File size: 6,776 Bytes
89ce340 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
import { customAlphabet } from 'nanoid'
import { defineStore } from 'pinia'
import { ToolbarStates } from '@/types/toolbar'
import type { CreatingElement, ShapeFormatPainter, TextFormatPainter } from '@/types/edit'
import type { DialogForExportTypes } from '@/types/export'
import { type TextAttrs, defaultRichTextAttrs } from '@/utils/prosemirror/utils'
import { useSlidesStore } from './slides'
export interface MainState {
activeElementIdList: string[]
handleElementId: string
activeGroupElementId: string
hiddenElementIdList: string[]
canvasPercentage: number
canvasScale: number
canvasDragged: boolean
thumbnailsFocus: boolean
editorAreaFocus: boolean
disableHotkeys: boolean
gridLineSize: number
showRuler: boolean
creatingElement: CreatingElement | null
creatingCustomShape: boolean
toolbarState: ToolbarStates
clipingImageElementId: string
isScaling: boolean
richTextAttrs: TextAttrs
selectedTableCells: string[]
selectedSlidesIndex: number[]
dialogForExport: DialogForExportTypes
databaseId: string
textFormatPainter: TextFormatPainter | null
shapeFormatPainter: ShapeFormatPainter | null
showSelectPanel: boolean
showSearchPanel: boolean
showNotesPanel: boolean
showMarkupPanel: boolean
showAIPPTDialog: boolean
}
const nanoid = customAlphabet('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')
export const databaseId = nanoid(10)
export const useMainStore = defineStore('main', {
state: (): MainState => ({
activeElementIdList: [], // 被选中的元素ID集合,包含 handleElementId
handleElementId: '', // 正在操作的元素ID
activeGroupElementId: '', // 组合元素成员中,被选中可独立操作的元素ID
hiddenElementIdList: [], // 被隐藏的元素ID集合
canvasPercentage: 90, // 画布可视区域百分比
canvasScale: 1, // 画布缩放比例(基于宽度{{slidesStore.viewportSize}}像素)
canvasDragged: false, // 画布被拖拽移动
thumbnailsFocus: false, // 左侧导航缩略图区域聚焦
editorAreaFocus: false, // 编辑区域聚焦
disableHotkeys: false, // 禁用快捷键
gridLineSize: 0, // 网格线尺寸(0表示不显示网格线)
showRuler: false, // 显示标尺
creatingElement: null, // 正在插入的元素信息,需要通过绘制插入的元素(文字、形状、线条)
creatingCustomShape: false, // 正在绘制任意多边形
toolbarState: ToolbarStates.SLIDE_DESIGN, // 右侧工具栏状态
clipingImageElementId: '', // 当前正在裁剪的图片ID
richTextAttrs: defaultRichTextAttrs, // 富文本状态
selectedTableCells: [], // 选中的表格单元格
isScaling: false, // 正在进行元素缩放
selectedSlidesIndex: [], // 当前被选中的页面索引集合
dialogForExport: '', // 导出面板
databaseId, // 标识当前应用的indexedDB数据库ID
textFormatPainter: null, // 文字格式刷
shapeFormatPainter: null, // 形状格式刷
showSelectPanel: false, // 打开选择面板
showSearchPanel: false, // 打开查找替换面板
showNotesPanel: false, // 打开批注面板
showMarkupPanel: false, // 打开类型标注面板
showAIPPTDialog: false, // 打开AIPPT创建窗口
}),
getters: {
activeElementList(state) {
const slidesStore = useSlidesStore()
const currentSlide = slidesStore.currentSlide
if (!currentSlide || !currentSlide.elements) return []
return currentSlide.elements.filter(element => state.activeElementIdList.includes(element.id))
},
handleElement(state) {
const slidesStore = useSlidesStore()
const currentSlide = slidesStore.currentSlide
if (!currentSlide || !currentSlide.elements) return null
return currentSlide.elements.find(element => state.handleElementId === element.id) || null
},
},
actions: {
setActiveElementIdList(activeElementIdList: string[]) {
if (activeElementIdList.length === 1) this.handleElementId = activeElementIdList[0]
else this.handleElementId = ''
this.activeElementIdList = activeElementIdList
},
setHandleElementId(handleElementId: string) {
this.handleElementId = handleElementId
},
setActiveGroupElementId(activeGroupElementId: string) {
this.activeGroupElementId = activeGroupElementId
},
setHiddenElementIdList(hiddenElementIdList: string[]) {
this.hiddenElementIdList = hiddenElementIdList
},
setCanvasPercentage(percentage: number) {
this.canvasPercentage = percentage
},
setCanvasScale(scale: number) {
this.canvasScale = scale
},
setCanvasDragged(isDragged: boolean) {
this.canvasDragged = isDragged
},
setThumbnailsFocus(isFocus: boolean) {
this.thumbnailsFocus = isFocus
},
setEditorareaFocus(isFocus: boolean) {
this.editorAreaFocus = isFocus
},
setDisableHotkeysState(disable: boolean) {
this.disableHotkeys = disable
},
setGridLineSize(size: number) {
this.gridLineSize = size
},
setRulerState(show: boolean) {
this.showRuler = show
},
setCreatingElement(element: CreatingElement | null) {
this.creatingElement = element
},
setCreatingCustomShapeState(state: boolean) {
this.creatingCustomShape = state
},
setToolbarState(toolbarState: ToolbarStates) {
this.toolbarState = toolbarState
},
setClipingImageElementId(elId: string) {
this.clipingImageElementId = elId
},
setRichtextAttrs(attrs: TextAttrs) {
this.richTextAttrs = attrs
},
setSelectedTableCells(cells: string[]) {
this.selectedTableCells = cells
},
setScalingState(isScaling: boolean) {
this.isScaling = isScaling
},
updateSelectedSlidesIndex(selectedSlidesIndex: number[]) {
this.selectedSlidesIndex = selectedSlidesIndex
},
setDialogForExport(type: DialogForExportTypes) {
this.dialogForExport = type
},
setTextFormatPainter(textFormatPainter: TextFormatPainter | null) {
this.textFormatPainter = textFormatPainter
},
setShapeFormatPainter(shapeFormatPainter: ShapeFormatPainter | null) {
this.shapeFormatPainter = shapeFormatPainter
},
setSelectPanelState(show: boolean) {
this.showSelectPanel = show
},
setSearchPanelState(show: boolean) {
this.showSearchPanel = show
},
setNotesPanelState(show: boolean) {
this.showNotesPanel = show
},
setMarkupPanelState(show: boolean) {
this.showMarkupPanel = show
},
setAIPPTDialogState(show: boolean) {
this.showAIPPTDialog = show
},
},
}) |