diff --git a/.prettierrc b/.prettierrc index 3dc0fa3..02af236 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,5 @@ { - "printWidth": 150, + "printWidth": 80, "tabWidth": 2, "useTabs": false, "semi": false, diff --git a/src/Kernel/BlockSelection.ts b/src/Kernel/BlockSelection.ts new file mode 100644 index 0000000..0240b17 --- /dev/null +++ b/src/Kernel/BlockSelection.ts @@ -0,0 +1,61 @@ +import { EventManager } from './EventManager' +import { Block } from '@BlockHub/Block/Block' + +export type BlkSlctnType = Block + +export type SelectionEventType = 'select' | 'unselect' | 'update' + +export class BlockSelection { + private _selectedBlocks: Array = [] + + get blocks(): BlkSlctnType[] { + return this._selectedBlocks + } + + events = { + update: new EventManager(), + } + + isSelected(block: BlkSlctnType): boolean { + return this._selectedBlocks.findIndex((b) => b === block) !== -1 + } + + add(block: BlkSlctnType) { + this._selectedBlocks.push(block) + this.events.update.emit('update') + } + + remove(block: BlkSlctnType) { + this._selectedBlocks.splice(this._selectedBlocks.indexOf(block), 1) + this.events.update.emit('update') + } + + replace(blocks: BlkSlctnType[]) { + this._selectedBlocks = blocks + this.events.update.emit('update') + } + + clear() { + this._selectedBlocks = [] + this.events.update.emit('update') + } + + toggle(block: BlkSlctnType) { + if (this.isSelected(block)) { + this.remove(block) + } else { + this.add(block) + } + } + + batchToggle(blocks: BlkSlctnType[]) { + blocks.forEach((block) => { + this.toggle(block) + }) + } + + focus(block: BlkSlctnType) { + this.clear() + this.add(block) + } +} diff --git a/src/Kernel/index.ts b/src/Kernel/index.ts index 9c121c5..c8b0e63 100644 --- a/src/Kernel/index.ts +++ b/src/Kernel/index.ts @@ -3,6 +3,7 @@ import { HistoryManager } from './HistoryManager' import { Slide } from './Slide' import { TableBlock } from '@BlockHub/TableBlock/TableBlock' import { PictureBlock } from '@BlockHub/PictureBlock/PictureBlock' +import { BlockSelection } from './BlockSelection' import { EventManager } from './EventManager' import { TextAtom } from './Store/TextStore' @@ -16,7 +17,13 @@ interface RichTextStateChange { export const kernel = { currentIndex: 0, - slides: [new Slide([new TextBoxBlock(100, 50), new TableBlock(400, 300, 4, 3), new PictureBlock(100, 300)])], + slides: [ + new Slide([ + new TextBoxBlock(100, 50), + new TableBlock(400, 300, 4, 3), + new PictureBlock(100, 300), + ]), + ], richTextObserver: new EventManager(), @@ -26,3 +33,5 @@ export const kernel = { } export const history = new HistoryManager() + +export const selectionBlk = new BlockSelection() diff --git a/src/UserInterface/Slide/Slide.vue b/src/UserInterface/Slide/Slide.vue index a3a1f51..6cadd05 100644 --- a/src/UserInterface/Slide/Slide.vue +++ b/src/UserInterface/Slide/Slide.vue @@ -1,12 +1,42 @@ diff --git a/src/UserInterface/Slide/SlideContainer.vue b/src/UserInterface/Slide/SlideContainer.vue index b53c338..89f35aa 100644 --- a/src/UserInterface/Slide/SlideContainer.vue +++ b/src/UserInterface/Slide/SlideContainer.vue @@ -1,9 +1,112 @@ diff --git a/src/UserInterface/ToolBar/ToolBar.vue b/src/UserInterface/ToolBar/ToolBar.vue index 82b2200..29318df 100644 --- a/src/UserInterface/ToolBar/ToolBar.vue +++ b/src/UserInterface/ToolBar/ToolBar.vue @@ -1,11 +1,10 @@ diff --git a/src/style.css b/src/style.css index a9819d5..3ac14d7 100644 --- a/src/style.css +++ b/src/style.css @@ -4,11 +4,17 @@ :root { /* font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; */ - font-family: 'Segoe UI', 'Segoe UI Web (West European)', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', sans-serif; + font-family: 'Segoe UI', 'Segoe UI Web (West European)', 'Segoe UI', + -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', sans-serif; } body { margin: 0; + -moz-user-select: none; /*火狐*/ + -webkit-user-select: none; /*webkit浏览器*/ + -ms-user-select: none; /*IE10*/ + -khtml-user-select: none; /*早期浏览器*/ + user-select: none; } svg {