@dou-ui/editor 0.1.0-alpha.16 → 0.1.0-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collaboration/binding.js +39 -49
- package/dist/collaboration/binding.js.map +1 -1
- package/dist/collaboration/inline-diff.js +138 -0
- package/dist/collaboration/inline-diff.js.map +1 -0
- package/dist/collaboration/merged-props.js +10 -10
- package/dist/collaboration/merged-props.js.map +1 -1
- package/dist/collaboration/order.js +41 -1
- package/dist/collaboration/order.js.map +1 -1
- package/dist/collaboration/table.js +64 -25
- package/dist/collaboration/table.js.map +1 -1
- package/dist/collaboration/text.js +213 -1
- package/dist/collaboration/text.js.map +1 -1
- package/dist/core/comments.js +85 -3
- package/dist/core/comments.js.map +1 -1
- package/dist/define-block.js +6 -3
- package/dist/define-block.js.map +1 -1
- package/dist/editor.js.map +1 -1
- package/dist/flow/board-block.js.map +1 -1
- package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js +70 -9
- package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/flow/board.js +124 -5
- package/dist/flow/board.js.map +1 -1
- package/dist/flow/index.js +5 -2
- package/dist/flow/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/collaboration/inline-diff.d.ts +9 -0
- package/dist/types/collaboration/order.d.ts +5 -0
- package/dist/types/collaboration/table.d.ts +5 -1
- package/dist/types/collaboration/text.d.ts +20 -0
- package/dist/types/core/comments.d.ts +39 -3
- package/dist/types/define-block.d.ts +16 -4
- package/dist/types/editor.d.ts +9 -1
- package/dist/types/flow/board.d.ts +15 -2
- package/dist/types/flow/index.d.ts +8 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/use-comments.js +2 -2
- package/dist/use-comments.js.map +1 -1
- package/package.json +7 -7
package/dist/editor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.js","names":[],"sources":["../src/editor.ts"],"sourcesContent":["import type { EditorState, Command, Plugin } from 'prosemirror-state'\nimport type { EditorView } from 'prosemirror-view'\nimport type { CommentAction, CommentAuthor, CommentThread } from 'dou-ui'\nimport {\n inject,\n onBeforeUnmount,\n provide,\n shallowReactive,\n shallowRef,\n type ComputedRef,\n type InjectionKey,\n type ShallowRef,\n} from 'vue'\nimport type { CommentAnchor, CommentRange } from './core/comments'\nimport type { EditorExtension, ResolvedEditorExtensions } from './core/extension'\nimport type { BlockChanges } from './core/changes'\nimport type { Block, EditorDocument, PartialBlock } from './core/model'\nimport type { EditorSearchQuery } from './core/search'\nimport type {\n BlockEdge,\n BlockPatch,\n BlockPlacement,\n EditorTransaction,\n EditorTransactionMeta,\n} from './core/transaction'\nimport type { EditorMessages, EditorMessagesOverride } from './locale'\n\nexport interface EditorProps {\n /**\n * The document, bound with `v-model`. With collaboration the shared\n * document is the source of truth: leave `v-model` out and read changes\n * from the `change` event.\n */\n modelValue?: EditorDocument<PartialBlock>\n /**\n * Blocks, marks, shortcuts and menu entries. Defaults to `[editorKit()]`;\n * read once, when the editor mounts.\n */\n extensions?: (EditorExtension | EditorExtension[])[]\n /** Show the document without editing it. Links stay clickable. */\n readonly?: boolean\n /** The built-in find panel (`Ctrl/⌘+F`). Off, the keys are left to the browser. On by default. */\n searchable?: boolean\n /** The hint in the empty block under the cursor. */\n placeholder?: string\n /** Replace any of the built-in texts. */\n messages?: EditorMessagesOverride\n /** The accessible name of the editing area. */\n ariaLabel?: string\n /** Focus the editor once it is mounted. */\n autofocus?: boolean\n /**\n * Extra ProseMirror plugins, e.g. for collaboration. They run before\n * the built-in ones, so their keys win.\n */\n plugins?: Plugin[]\n /** Leave out the built-in undo history (collaboration brings its own). */\n history?: boolean\n /** Undo and redo commands to replace the built-in ones. */\n undo?: Command\n redo?: Command\n /**\n * The comment threads, bound with `v-model:comments`. The text a thread\n * is about carries its id in the document; leave this out to turn\n * comments off.\n */\n comments?: CommentThread[]\n /** Who is commenting. Without it comments can be read but not written. */\n author?: CommentAuthor\n /** The id of the thread shown beside its text, bound with `v-model:activeComment`. */\n activeComment?: string | null\n /** Whether threads can be started and answered; also while `readonly`. Defaults to `true`. */\n commentable?: boolean\n /**\n * An older version of the document, e.g. one the app saved. The editor\n * then shows the document read-only, with what changed since marked:\n * blocks added and removed, and in each changed block the text added\n * and removed. Blocks are matched by `id`; a block without one shows as\n * removed.\n */\n compare?: EditorDocument<PartialBlock> | null\n /**\n * The block with the cursor and the selected blocks, bound with\n * `v-model:selection`. Setting it puts the cursor at the end of `block`,\n * or selects `blocks` when there are several siblings, without focusing.\n */\n selection?: EditorSelection\n}\n\n/**\n * Who made a change: `'external'` for a new `v-model` value or\n * `setBlocks`, `'remote'` for a collaborator's, `'restore'` for `restore`,\n * `'undo'` and `'redo'`, or\n * the `origin` given to `transact`. Typing and the editor's own commands\n * leave it out.\n */\nexport type EditorOrigin = 'external' | 'remote' | 'restore' | 'undo' | 'redo' | (string & {})\n\n/** What a change to the document did, as the `transaction` event hands it over. */\nexport interface EditorTransactionResult {\n /** The document after the change, as `update:modelValue` gets it next. */\n blocks: Block[]\n /** The blocks the change touched, by id. */\n changes: BlockChanges\n meta: {\n origin?: EditorOrigin\n /** Whether undo can take the change back: not for others' changes, nor for undo and redo themselves. */\n history: boolean\n }\n}\n\n/** Where the selection is, by block. */\nexport interface EditorSelection {\n /** The innermost block at the cursor (the moving end of a selection); `null` while none is. */\n block: string | null\n /**\n * The blocks the selection covers: the selected blocks, or the blocks a\n * text selection runs across, at the level they share.\n */\n blocks: string[]\n}\n\nexport interface EditorEmits {\n 'update:modelValue': [document: EditorDocument]\n /** The document changed: typing, formatting, moving blocks. */\n change: [document: EditorDocument]\n /** Every change to the document, with what it touched; `update:modelValue` follows. */\n transaction: [result: EditorTransactionResult]\n /** The cursor moved to another block, or other blocks were selected. */\n 'update:selection': [selection: EditorSelection]\n /** Before a link opens (Ctrl / ⌘ + click, or a click while read-only); `preventDefault()` keeps it from opening in a new tab. */\n linkOpen: [event: EditorLinkOpenEvent]\n focus: [event: FocusEvent]\n blur: [event: FocusEvent]\n 'update:comments': [threads: CommentThread[]]\n 'update:activeComment': [id: string | null]\n /** A change to the comments made here: to send to a server, notify people, keep a log. */\n commentAction: [action: CommentAction]\n}\n\n/**\n * Before a link is followed. `preventDefault()` stops the editor from\n * opening it in a new tab, e.g. to use the app's router or ask first.\n */\nexport interface EditorLinkOpenEvent {\n /** The address as the text's `link` holds it. */\n link: string\n /** The id of the block the link is in. */\n block: string\n defaultPrevented: boolean\n preventDefault: () => void\n}\n\nexport interface EditorExpose {\n /** The ProseMirror view, once mounted. */\n readonly view: EditorView | null\n focus: () => void\n blur: () => void\n /** The current document. */\n getBlocks: () => Block[]\n /** Replace the document. The change does not go into the undo history. */\n setBlocks: (blocks: PartialBlock[]) => void\n /** The current document as HTML, written by the extensions (see `blocksToHTML`). */\n getHTML: () => string\n /** Replace the document with HTML, read like pasted HTML. */\n setHTML: (html: string) => void\n /** Run a ProseMirror command, e.g. one of the exported ones. */\n run: (command: Command) => boolean\n /**\n * Opens the find panel (`Ctrl/⌘+F`), with a query put in; with `replace`\n * in it, the replace box opens too. `false` when `searchable` is off or\n * the editor is not mounted.\n */\n openSearch: (query?: Partial<EditorSearchQuery>) => boolean\n /** Closes the find panel; `false` when it was not open. */\n closeSearch: () => boolean\n /**\n * Make changes by blocks and ids, applied together as one undo step.\n * Returns what happened, or `null` when nothing changed. Works while\n * read-only too.\n */\n transact: (\n fn: (tr: EditorTransaction) => void,\n meta?: EditorTransactionMeta,\n ) => EditorTransactionResult | null\n /** One block, or `null` when there is none with that id. */\n getBlock: (id: string) => Block | null\n /**\n * Insert blocks, by default after the block with the cursor. Returns the\n * new blocks' ids (an id already in use is replaced). One undo step.\n */\n insertBlocks: (blocks: PartialBlock[], placement?: BlockPlacement) => string[]\n /** Change a block's type, props (merged), content or children. One undo step. */\n updateBlock: (id: string, patch: BlockPatch) => boolean\n /** Remove blocks with their children. One undo step. */\n removeBlocks: (ids: string[]) => boolean\n /** Move blocks, in the order given, before, after or into another block. One undo step. */\n moveBlocks: (ids: string[], placement: BlockPlacement) => boolean\n /** Focus the editor with the cursor at the start or end (the default) of a block, scrolled into view. */\n focusBlock: (id: string, edge?: BlockEdge) => boolean\n /** The selection by block, as `v-model:selection` has it. */\n getSelection: () => EditorSelection\n undo: () => boolean\n redo: () => boolean\n readonly canUndo: boolean\n readonly canRedo: boolean\n /**\n * Start a thread on the selected text and open the box for its first\n * comment; with the cursor on commented text, open that thread to reply.\n */\n comment: () => boolean\n /** Where each thread is anchored; `null` for a thread whose text was deleted. */\n getCommentAnchors: () => Record<string, CommentAnchor | null>\n /**\n * Replace the document with `doc`, e.g. an older version, as one\n * change undo takes back. With collaboration only the blocks that differ\n * are written, and everyone sees it. The `transaction` event has origin\n * `'restore'`. Like the other methods it works while `readonly`; it is\n * the one change allowed while comparing. Returns `false` when nothing\n * differs.\n */\n restore: (doc: EditorDocument<PartialBlock>) => boolean\n /** With `compare`: scroll to the next change after the one last shown; `false` when there is none. */\n nextChange: () => boolean\n /** With `compare`: scroll to the change before the one last shown. */\n previousChange: () => boolean\n}\n\n/** The comments, as the parts around the editing area see them. */\nexport interface EditorComments {\n /** Comments are on: there are threads to show. */\n enabled: ComputedRef<boolean>\n /** Threads can be started and answered. */\n writable: ComputedRef<boolean>\n threads: ComputedRef<readonly CommentThread[]>\n author: ComputedRef<CommentAuthor | undefined>\n /** The thread shown beside its text. */\n active: ComputedRef<string | null>\n /** The text a new thread is being started on. */\n pending: ShallowRef<CommentRange | null>\n /** Goes up when the open thread's reply box should take focus. */\n focusRequest: ShallowRef<number>\n /** The selected text, also in a read-only editor; `null` when there is none. */\n selection: () => CommentRange | null\n /** Start a thread on the selected text, or open the one the cursor is in. */\n start: () => boolean\n apply: (action: CommentAction) => void\n open: (id: string | null) => void\n /** Close the card, dropping a thread not yet started. */\n close: () => void\n}\n\n/** What the parts around the editing area (menus, handle, toolbar) share. */\nexport interface EditorContext {\n view: ShallowRef<EditorView | null>\n /** Updated on every transaction, so computeds follow the selection too. */\n state: ShallowRef<EditorState | null>\n focused: ShallowRef<boolean>\n /** Blocks are being dragged by the handle. */\n dragging: ShallowRef<boolean>\n editable: ComputedRef<boolean>\n messages: ComputedRef<EditorMessages>\n /** What the extensions contribute: schema, menu entries, toolbar toggles. */\n kit: ResolvedEditorExtensions\n /** The element the overlays are positioned against. */\n root: ShallowRef<HTMLElement | null>\n comments: EditorComments\n}\n\nexport const editorKey: InjectionKey<EditorContext> = Symbol('DouEditor')\n\nconst toolbarMenusKey: InjectionKey<Set<ShallowRef<boolean>>> = Symbol('DouEditorToolbarMenus')\n\n/** For the formatting toolbar: the open state of the menus in it. */\nexport function provideToolbarMenus(): Set<ShallowRef<boolean>> {\n const menus = shallowReactive(new Set<ShallowRef<boolean>>())\n provide(toolbarMenusKey, menus)\n return menus\n}\n\n/**\n * The open state for a menu in the formatting toolbar (an extension's\n * `toolbar` component), to bind with `v-model:open`: the toolbar stays\n * while the menu is open, though the focus has left the editor.\n */\nexport function useToolbarMenu(): ShallowRef<boolean> {\n const open = shallowRef(false)\n const menus = inject(toolbarMenusKey, null)\n if (menus) {\n menus.add(open)\n onBeforeUnmount(() => menus.delete(open))\n }\n return open\n}\n\n/** The editor around a block component, for its messages, state and view. */\nexport function useEditor(): EditorContext {\n const context = inject(editorKey, null)\n if (!context) throw new Error('[@dou-ui/editor] useEditor() must be called inside <DouEditor>')\n return context\n}\n"],"mappings":";;AA6QA,IAAa,YAAyC,OAAO,WAAW;AAExE,IAAM,kBAA0D,OAAO,uBAAuB;;AAG9F,SAAgB,sBAAgD;CAC9D,MAAM,QAAQ,gCAAgB,IAAI,IAAyB,CAAC;CAC5D,QAAQ,iBAAiB,KAAK;CAC9B,OAAO;AACT;;;;;;AAOA,SAAgB,iBAAsC;CACpD,MAAM,OAAO,WAAW,KAAK;CAC7B,MAAM,QAAQ,OAAO,iBAAiB,IAAI;CAC1C,IAAI,OAAO;EACT,MAAM,IAAI,IAAI;EACd,sBAAsB,MAAM,OAAO,IAAI,CAAC;CAC1C;CACA,OAAO;AACT;;AAGA,SAAgB,YAA2B;CACzC,MAAM,UAAU,OAAO,WAAW,IAAI;CACtC,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,gEAAgE;CAC9F,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"editor.js","names":[],"sources":["../src/editor.ts"],"sourcesContent":["import type { EditorState, Command, Plugin } from 'prosemirror-state'\nimport type { EditorView } from 'prosemirror-view'\nimport type { CommentAction, CommentAuthor, CommentThread } from 'dou-ui'\nimport {\n inject,\n onBeforeUnmount,\n provide,\n shallowReactive,\n shallowRef,\n type ComputedRef,\n type InjectionKey,\n type ShallowRef,\n} from 'vue'\nimport type { CommentAnchor, CommentRange } from './core/comments'\nimport type { EditorExtension, ResolvedEditorExtensions } from './core/extension'\nimport type { BlockChanges } from './core/changes'\nimport type { Block, EditorDocument, PartialBlock } from './core/model'\nimport type { EditorSearchQuery } from './core/search'\nimport type {\n BlockEdge,\n BlockPatch,\n BlockPlacement,\n EditorTransaction,\n EditorTransactionMeta,\n} from './core/transaction'\nimport type { EditorMessages, EditorMessagesOverride } from './locale'\n\nexport interface EditorProps {\n /**\n * The document, bound with `v-model`. With collaboration the shared\n * document is the source of truth: leave `v-model` out and read changes\n * from the `change` event.\n */\n modelValue?: EditorDocument<PartialBlock>\n /**\n * Blocks, marks, shortcuts and menu entries. Defaults to `[editorKit()]`;\n * read once, when the editor mounts.\n */\n extensions?: (EditorExtension | EditorExtension[])[]\n /** Show the document without editing it. Links stay clickable. */\n readonly?: boolean\n /** The built-in find panel (`Ctrl/⌘+F`). Off, the keys are left to the browser. On by default. */\n searchable?: boolean\n /** The hint in the empty block under the cursor. */\n placeholder?: string\n /** Replace any of the built-in texts. */\n messages?: EditorMessagesOverride\n /** The accessible name of the editing area. */\n ariaLabel?: string\n /** Focus the editor once it is mounted. */\n autofocus?: boolean\n /**\n * Extra ProseMirror plugins, e.g. for collaboration. They run before\n * the built-in ones, so their keys win.\n */\n plugins?: Plugin[]\n /** Leave out the built-in undo history (collaboration brings its own). */\n history?: boolean\n /** Undo and redo commands to replace the built-in ones. */\n undo?: Command\n redo?: Command\n /**\n * The comment threads, bound with `v-model:comments`. The text a thread\n * is about carries its id in the document; leave this out to turn\n * comments off.\n */\n comments?: CommentThread[]\n /** Who is commenting. Without it comments can be read but not written. */\n author?: CommentAuthor\n /** The id of the thread shown beside its text, bound with `v-model:activeComment`. */\n activeComment?: string | null\n /** Whether threads can be started and answered; also while `readonly`. Defaults to `true`. */\n commentable?: boolean\n /**\n * An older version of the document, e.g. one the app saved. The editor\n * then shows the document read-only, with what changed since marked:\n * blocks added and removed, and in each changed block the text added\n * and removed. Blocks are matched by `id`; a block without one shows as\n * removed.\n */\n compare?: EditorDocument<PartialBlock> | null\n /**\n * The block with the cursor and the selected blocks, bound with\n * `v-model:selection`. Setting it puts the cursor at the end of `block`,\n * or selects `blocks` when there are several siblings, without focusing.\n */\n selection?: EditorSelection\n}\n\n/**\n * Who made a change: `'external'` for a new `v-model` value or\n * `setBlocks`, `'remote'` for a collaborator's, `'restore'` for `restore`,\n * `'undo'` and `'redo'`, or\n * the `origin` given to `transact`. Typing and the editor's own commands\n * leave it out.\n */\nexport type EditorOrigin = 'external' | 'remote' | 'restore' | 'undo' | 'redo' | (string & {})\n\n/** What a change to the document did, as the `transaction` event hands it over. */\nexport interface EditorTransactionResult {\n /** The document after the change, as `update:modelValue` gets it next. */\n blocks: Block[]\n /** The blocks the change touched, by id. */\n changes: BlockChanges\n meta: {\n origin?: EditorOrigin\n /** Whether undo can take the change back: not for others' changes, nor for undo and redo themselves. */\n history: boolean\n }\n}\n\n/** Where the selection is, by block. */\nexport interface EditorSelection {\n /** The innermost block at the cursor (the moving end of a selection); `null` while none is. */\n block: string | null\n /**\n * The blocks the selection covers: the selected blocks, or the blocks a\n * text selection runs across, at the level they share.\n */\n blocks: string[]\n}\n\nexport interface EditorEmits {\n 'update:modelValue': [document: EditorDocument]\n /** The document changed: typing, formatting, moving blocks. */\n change: [document: EditorDocument]\n /** Every change to the document, with what it touched; `update:modelValue` follows. */\n transaction: [result: EditorTransactionResult]\n /** The cursor moved to another block, or other blocks were selected. */\n 'update:selection': [selection: EditorSelection]\n /** Before a link opens (Ctrl / ⌘ + click, or a click while read-only); `preventDefault()` keeps it from opening in a new tab. */\n linkOpen: [event: EditorLinkOpenEvent]\n focus: [event: FocusEvent]\n blur: [event: FocusEvent]\n 'update:comments': [threads: CommentThread[]]\n 'update:activeComment': [id: string | null]\n /** A change to the comments made here: to send to a server, notify people, keep a log. */\n commentAction: [action: CommentAction]\n}\n\n/**\n * Before a link is followed. `preventDefault()` stops the editor from\n * opening it in a new tab, e.g. to use the app's router or ask first.\n */\nexport interface EditorLinkOpenEvent {\n /** The address as the text's `link` holds it. */\n link: string\n /** The id of the block the link is in. */\n block: string\n defaultPrevented: boolean\n preventDefault: () => void\n}\n\nexport interface EditorExpose {\n /** The ProseMirror view, once mounted. */\n readonly view: EditorView | null\n focus: () => void\n blur: () => void\n /** The current document. */\n getBlocks: () => Block[]\n /** Replace the document. The change does not go into the undo history. */\n setBlocks: (blocks: PartialBlock[]) => void\n /** The current document as HTML, written by the extensions (see `blocksToHTML`). */\n getHTML: () => string\n /** Replace the document with HTML, read like pasted HTML. */\n setHTML: (html: string) => void\n /** Run a ProseMirror command, e.g. one of the exported ones. */\n run: (command: Command) => boolean\n /**\n * Opens the find panel (`Ctrl/⌘+F`), with a query put in; with `replace`\n * in it, the replace box opens too. `false` when `searchable` is off or\n * the editor is not mounted.\n */\n openSearch: (query?: Partial<EditorSearchQuery>) => boolean\n /** Closes the find panel; `false` when it was not open. */\n closeSearch: () => boolean\n /**\n * Make changes by blocks and ids, applied together as one undo step.\n * Returns what happened, or `null` when nothing changed. Works while\n * read-only too.\n */\n transact: (\n fn: (tr: EditorTransaction) => void,\n meta?: EditorTransactionMeta,\n ) => EditorTransactionResult | null\n /** One block, or `null` when there is none with that id. */\n getBlock: (id: string) => Block | null\n /**\n * Insert blocks, by default after the block with the cursor. Returns the\n * new blocks' ids (an id already in use is replaced). One undo step.\n */\n insertBlocks: (blocks: PartialBlock[], placement?: BlockPlacement) => string[]\n /** Change a block's type, props (merged), content or children. One undo step. */\n updateBlock: (id: string, patch: BlockPatch) => boolean\n /** Remove blocks with their children. One undo step. */\n removeBlocks: (ids: string[]) => boolean\n /** Move blocks, in the order given, before, after or into another block. One undo step. */\n moveBlocks: (ids: string[], placement: BlockPlacement) => boolean\n /** Focus the editor with the cursor at the start or end (the default) of a block, scrolled into view. */\n focusBlock: (id: string, edge?: BlockEdge) => boolean\n /** The selection by block, as `v-model:selection` has it. */\n getSelection: () => EditorSelection\n undo: () => boolean\n redo: () => boolean\n readonly canUndo: boolean\n readonly canRedo: boolean\n /**\n * Start a thread on the selected text and open the box for its first\n * comment; with the cursor on commented text, open that thread to reply.\n */\n comment: () => boolean\n /** Where each thread is anchored; `null` for a thread whose text was deleted. */\n getCommentAnchors: () => Record<string, CommentAnchor | null>\n /**\n * Replace the document with `doc`, e.g. an older version, as one\n * change undo takes back. With collaboration only the blocks that differ\n * are written, and everyone sees it. The `transaction` event has origin\n * `'restore'`. Like the other methods it works while `readonly`; it is\n * the one change allowed while comparing. Returns `false` when nothing\n * differs.\n */\n restore: (doc: EditorDocument<PartialBlock>) => boolean\n /** With `compare`: scroll to the next change after the one last shown; `false` when there is none. */\n nextChange: () => boolean\n /** With `compare`: scroll to the change before the one last shown. */\n previousChange: () => boolean\n}\n\n/** The comments, as the parts around the editing area see them. */\nexport interface EditorComments {\n /** Comments are on: there are threads to show. */\n enabled: ComputedRef<boolean>\n /** Threads can be started and answered. */\n writable: ComputedRef<boolean>\n threads: ComputedRef<readonly CommentThread[]>\n author: ComputedRef<CommentAuthor | undefined>\n /** The thread shown beside its text. */\n active: ComputedRef<string | null>\n /** The text a new thread is being started on. */\n pending: ShallowRef<CommentRange | null>\n /** Goes up when the open thread's reply box should take focus. */\n focusRequest: ShallowRef<number>\n /** The selected text, also in a read-only editor; `null` when there is none. */\n selection: () => CommentRange | null\n /** Start a thread on the selected text, or open the one the cursor is in. */\n start: () => boolean\n /**\n * Make a change to the threads. A new thread goes on the text being\n * commented on; with `anchored`, its block already put it inside (see\n * `BlockCommentsSpec`). A removed thread is taken off its text or block.\n */\n apply: (action: CommentAction, options?: { anchored?: boolean }) => void\n /** Open a thread: beside its text, or inside its block, which watches `active`. */\n open: (id: string | null) => void\n /** Close the card, dropping a thread not yet started. */\n close: () => void\n}\n\n/** What the parts around the editing area (menus, handle, toolbar) share. */\nexport interface EditorContext {\n view: ShallowRef<EditorView | null>\n /** Updated on every transaction, so computeds follow the selection too. */\n state: ShallowRef<EditorState | null>\n focused: ShallowRef<boolean>\n /** Blocks are being dragged by the handle. */\n dragging: ShallowRef<boolean>\n editable: ComputedRef<boolean>\n messages: ComputedRef<EditorMessages>\n /** What the extensions contribute: schema, menu entries, toolbar toggles. */\n kit: ResolvedEditorExtensions\n /** The element the overlays are positioned against. */\n root: ShallowRef<HTMLElement | null>\n comments: EditorComments\n}\n\nexport const editorKey: InjectionKey<EditorContext> = Symbol('DouEditor')\n\nconst toolbarMenusKey: InjectionKey<Set<ShallowRef<boolean>>> = Symbol('DouEditorToolbarMenus')\n\n/** For the formatting toolbar: the open state of the menus in it. */\nexport function provideToolbarMenus(): Set<ShallowRef<boolean>> {\n const menus = shallowReactive(new Set<ShallowRef<boolean>>())\n provide(toolbarMenusKey, menus)\n return menus\n}\n\n/**\n * The open state for a menu in the formatting toolbar (an extension's\n * `toolbar` component), to bind with `v-model:open`: the toolbar stays\n * while the menu is open, though the focus has left the editor.\n */\nexport function useToolbarMenu(): ShallowRef<boolean> {\n const open = shallowRef(false)\n const menus = inject(toolbarMenusKey, null)\n if (menus) {\n menus.add(open)\n onBeforeUnmount(() => menus.delete(open))\n }\n return open\n}\n\n/** The editor around a block component, for its messages, state and view. */\nexport function useEditor(): EditorContext {\n const context = inject(editorKey, null)\n if (!context) throw new Error('[@dou-ui/editor] useEditor() must be called inside <DouEditor>')\n return context\n}\n"],"mappings":";;AAmRA,IAAa,YAAyC,OAAO,WAAW;AAExE,IAAM,kBAA0D,OAAO,uBAAuB;;AAG9F,SAAgB,sBAAgD;CAC9D,MAAM,QAAQ,gCAAgB,IAAI,IAAyB,CAAC;CAC5D,QAAQ,iBAAiB,KAAK;CAC9B,OAAO;AACT;;;;;;AAOA,SAAgB,iBAAsC;CACpD,MAAM,OAAO,WAAW,KAAK;CAC7B,MAAM,QAAQ,OAAO,iBAAiB,IAAI;CAC1C,IAAI,OAAO;EACT,MAAM,IAAI,IAAI;EACd,sBAAsB,MAAM,OAAO,IAAI,CAAC;CAC1C;CACA,OAAO;AACT;;AAGA,SAAgB,YAA2B;CACzC,MAAM,UAAU,OAAO,WAAW,IAAI;CACtC,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,gEAAgE;CAC9F,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board-block.js","names":["_sfc_main"],"sources":["../../src/flow/board-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n defaultNode,\n defineNodeType,\n DouFlowControls,\n DouFlowEditor,\n defineFlowExtension,\n type NodeTypeSpec,\n type FlowDocument,\n type FlowExtension,\n type FlowHistoryHandler,\n type FlowNode,\n type FlowTransaction,\n} from '@dou-ui/flow'\nimport { EyeIcon, PencilIcon, PlusIcon, SquareIcon } from '@dou-ui/icons'\nimport { DouButton, DouCommand, DouDialog, DouPopover, type CommandItem } from 'dou-ui'\nimport { NodeSelection } from 'prosemirror-state'\nimport {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { findBlockById } from '../core/blocks'\nimport { historyCommands } from '../core/editor'\nimport { labelOf } from '../core/extension'\nimport type { BlockProps } from '../core/model'\nimport { joinStepKey, ownStepKey } from '../core/transaction'\nimport { useEditor } from '../editor'\nimport {\n BOARD_HEIGHT,\n BOARD_OPEN_EVENT,\n boardOf,\n clampHeight,\n onlyBoardChanged,\n type BoardBlockSettings,\n} from './board'\n\n/** The board with the groups this reader folded or unfolded. */\nfunction withFolded(board: FlowDocument, folded: Map<string, boolean>): FlowDocument {\n if (!folded.size) return board\n const nodes = board.nodes.map((node) => {\n if (!folded.has(node.id)) return node\n const { collapsed: _, ...data } = node.data ?? {}\n return { ...node, data: folded.get(node.id) ? { ...data, collapsed: true } : data }\n })\n return { ...board, nodes }\n}\n\nconst props = defineProps<{\n block: { id: string; type: string; props: BlockProps }\n updateProps: (props: BlockProps) => void\n selected: boolean\n editable: boolean\n settings: BoardBlockSettings\n}>()\n\nconst { view, messages } = useEditor()\nconst text = computed(() => messages.value.board)\nconst label = computed(() => labelOf(props.settings.label, messages.value))\nconst stored = computed(() => boardOf(props.block.props.board))\n/*\n * Whether a group is folded is each reader's own view, as with toggles: it\n * stays out of the document (what it holds there is kept), and is shown\n * from here.\n */\nconst folded = shallowRef(new Map<string, boolean>())\nconst board = computed(() => withFolded(stored.value, folded.value))\nconst empty = computed(() => !board.value.nodes.length)\n\n/* the fullscreen editor */\nconst open = shallowRef(false)\nwatch(open, (value) => {\n if (!value) shown.value = board.value\n})\n\nconst root = useTemplateRef<HTMLElement>('root')\nconst canvas = useTemplateRef<HTMLElement>('canvas')\nconst preview = useTemplateRef<InstanceType<typeof DouFlowEditor>>('preview')\n\n/* the height, followed live while the bar is dragged */\nconst dragged = shallowRef<number | null>(null)\nconst height = computed(\n () => dragged.value ?? clampHeight(Number(props.block.props.height) || props.settings.height),\n)\n\n/* the preview is drawn once the block comes near the screen */\nconst seen = shallowRef(typeof IntersectionObserver === 'undefined')\nlet observer: IntersectionObserver | null = null\nlet resized: ResizeObserver | null = null\nlet frame = 0\n/** Fits the preview to its box again, once the nodes have been laid out. */\nfunction refit() {\n cancelAnimationFrame(frame)\n frame = requestAnimationFrame(() => preview.value?.fit())\n}\nonMounted(() => {\n const element = root.value!\n element.addEventListener(BOARD_OPEN_EVENT, openEditor)\n if (!seen.value) {\n observer = new IntersectionObserver(\n (entries) => {\n if (!entries.some((entry) => entry.isIntersecting)) return\n seen.value = true\n observer?.disconnect()\n observer = null\n },\n { rootMargin: '200px' },\n )\n observer.observe(element)\n }\n if (typeof ResizeObserver !== 'undefined') {\n let width = element.clientWidth\n resized = new ResizeObserver(() => {\n if (element.clientWidth === width) return\n width = element.clientWidth\n refit()\n })\n resized.observe(element)\n }\n})\nonBeforeUnmount(() => {\n settle()\n root.value?.removeEventListener(BOARD_OPEN_EVENT, openEditor)\n observer?.disconnect()\n resized?.disconnect()\n cancelAnimationFrame(frame)\n})\n/* what the preview shows: held while the fullscreen editor covers it, so it isn't redrawn each frame */\nconst shown = shallowRef(board.value)\nwatch(board, (value) => {\n if (!open.value) shown.value = value\n})\nwatch(shown, () => void nextTick(refit))\nwatch(height, () => void nextTick(refit))\n\nfunction openEditor() {\n if (!props.editable && empty.value) return\n steps.undo = 0\n steps.redo = 0\n pending = null\n open.value = true\n}\n\nconst contentPos = () => {\n const state = view.value?.state\n return state ? (findBlockById(state.doc, props.block.id)?.contentPos ?? null) : null\n}\n\n/** The keys go to the canvas from the start: a tool's letter, `Esc` letting go of a selection. */\nfunction onOpened() {\n canvas.value?.querySelector<HTMLElement>('.dou-flow-editor')?.focus({ preventScroll: true })\n}\n\n/** Back in the document: the block selected, the editor focused. */\nfunction onClosed() {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n if (props.editable)\n editor.dispatch(editor.state.tr.setSelection(NodeSelection.create(editor.state.doc, pos)))\n editor.focus()\n}\n\n/*\n * Changes on the board go into the document as they are made, so `v-model`,\n * collaboration and the other blocks see them, and into the editor's undo\n * history: undo in the fullscreen editor is the document's, one step per\n * change on the board. The frames of a drag (or nudges with the arrow keys,\n * or typing in one node) join the step of the first one; only the fields\n * they change are written, so what others change meanwhile stays theirs. A\n * cancelled drag takes its step back.\n */\nconst GROUP_WINDOW = 1000\n/** A drag going on: its group, and when its last frame came. */\nlet pending: { group: string; time: number } | null = null\n/** The steps taken on the board since it was opened, and those undone. */\nconst steps = { undo: 0, redo: 0 }\n\n/** The board as the document keeps it: groups folded as they are there; and what this reader folded. */\nfunction toDocument(next: FlowDocument): FlowDocument {\n const before = new Map(stored.value.nodes.map((node) => [node.id, node]))\n let changed: Map<string, boolean> | null = null\n const nodes = next.nodes.map((node) => {\n const mine = !!node.data?.collapsed\n const theirs = before.get(node.id)?.data?.collapsed\n if (mine === !!theirs) {\n if (folded.value.has(node.id)) (changed ??= new Map(folded.value)).delete(node.id)\n return node\n }\n if (folded.value.get(node.id) !== mine) (changed ??= new Map(folded.value)).set(node.id, mine)\n const { collapsed: _, ...data } = node.data ?? {}\n if (theirs !== undefined) return { ...node, data: { ...data, collapsed: theirs } }\n // a node with no data before has none after\n if (Object.keys(data).length || before.get(node.id)?.data) return { ...node, data }\n const { data: __, ...rest } = node\n return rest as FlowNode\n })\n if (changed) folded.value = changed\n warnDataImages(next, before)\n return { ...next, nodes }\n}\n\nlet warned = false\n/** Pictures kept in the document as data URLs make it large: say so once, while developing. */\nfunction warnDataImages(next: FlowDocument, before: Map<string, FlowNode>) {\n if (warned || process.env.NODE_ENV === 'production') return\n const added = next.nodes.find(\n (node) =>\n typeof node.data?.src === 'string' &&\n node.data.src.startsWith('data:') &&\n before.get(node.id)?.data?.src !== node.data.src,\n )\n if (!added) return\n warned = true\n console.warn(\n `[@dou-ui/editor] a picture on the \"${props.block.type}\" block is kept in the document as a data URL; pass \\`upload\\` to whiteboardBlock() to keep only its address`,\n )\n}\n\nconst currentBoard = () => {\n const pos = contentPos()\n return pos === null ? null : (view.value?.state.doc.nodeAt(pos)?.attrs.board ?? null)\n}\n\n/** Writes the board as one undo step of its own. */\nfunction record(next: unknown) {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n editor.dispatch(editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta(ownStepKey, true))\n steps.undo++\n steps.redo = 0\n}\n\n/** Writes the board into the undo step before, the drag's. */\nfunction join(next: unknown) {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n const tr = editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta(joinStepKey, true)\n // for the built-in history: part of the step before, however long after\n editor.dispatch(tr.setMeta('appendedTransaction', editor.state.tr))\n}\n\n/** Ends the drag going on: the next change is a step of its own. */\nfunction settle() {\n pending = null\n}\n\nfunction forward(tr: FlowTransaction) {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null || !props.editable) return\n const group = tr.meta.group\n const next = toDocument(tr.doc)\n // only folded or unfolded: nothing for the document\n if (JSON.stringify(next) === JSON.stringify(currentBoard())) return\n const now = Date.now()\n if (pending && (pending.group !== group || now - pending.time >= GROUP_WINDOW)) {\n // a cancelled drag putting the board back: part of its step\n if (tr.meta.history === false) return join(next)\n settle()\n }\n if (tr.meta.history === false) {\n editor.dispatch(\n editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta('addToHistory', false),\n )\n return\n }\n if (!group) return record(next)\n if (pending) {\n pending.time = now\n return join(next)\n }\n pending = { group, time: now }\n record(next)\n}\n\n/** Undo or redo in the document; refused when it would change something besides this board. */\nfunction travel(kind: 'undo' | 'redo') {\n settle()\n const editor = view.value\n if (!editor || !steps[kind]) return false\n const before = editor.state.doc\n const commands = historyCommands(editor.state)\n if (!commands[kind](editor.state, editor.dispatch, editor)) return false\n if (!onlyBoardChanged(before, editor.state.doc, props.block.id)) {\n // the board's own steps are used up: put back what was taken\n historyCommands(editor.state)[kind === 'undo' ? 'redo' : 'undo'](\n editor.state,\n editor.dispatch,\n editor,\n )\n steps[kind] = 0\n return false\n }\n steps[kind]--\n steps[kind === 'undo' ? 'redo' : 'undo']++\n return true\n}\n\n/** A cancelled drag: the board is back where it started, and its step is taken back. */\nfunction drop(group: string) {\n if (pending?.group !== group) return\n pending = null\n const editor = view.value\n if (!editor || !steps.undo) return\n if (historyCommands(editor.state).undo(editor.state, editor.dispatch, editor)) steps.undo--\n}\n\nconst history: FlowHistoryHandler = {\n undo: () => travel('undo'),\n redo: () => travel('redo'),\n canUndo: () => steps.undo > 0,\n canRedo: () => steps.redo > 0 && !pending,\n drop,\n close: settle,\n}\nconst bridge: FlowExtension = defineFlowExtension({\n name: 'editor-board-history',\n history: () => history,\n})\nconst extensions = [...props.settings.extensions, bridge]\n\n/*\n * Adding nodes: the types the extensions offer (`palette`), from a button\n * at the top left. When none is offered (`flowKit()` alone), a node of its\n * own with an input and an output, so what is added can be connected right\n * away.\n */\nconst offered = [\n ...props.settings.extensions.flat(),\n { nodeTypes: props.settings.editorProps.nodeTypes ?? [] },\n].some((extension) => extension.nodeTypes?.some((spec) => spec.palette))\nconst nodeTypes = computed(() => {\n const given = (props.settings.editorProps.nodeTypes ?? []) as NodeTypeSpec[]\n if (offered || !props.settings.fallbackNode) return given\n const name = text.value.node\n const step = defineNodeType({\n ...defaultNode,\n defaults: () => ({ label: name, inputs: [{ id: 'in' }], outputs: [{ id: 'out' }] }),\n palette: { label: name, icon: SquareIcon },\n }) as unknown as NodeTypeSpec\n return [step, ...given]\n})\nconst full = useTemplateRef<InstanceType<typeof DouFlowEditor>>('full')\nconst palette = computed(() => (props.editable ? (full.value?.paletteTypes ?? []) : []))\n/* several types: the same searchable list as when an edge is dropped on the canvas */\nconst adding = shallowRef(false)\nconst query = shallowRef('')\nconst addTrigger = useTemplateRef<InstanceType<typeof DouButton>>('addTrigger')\nconst command = useTemplateRef<InstanceType<typeof DouCommand>>('command')\nconst items = computed<CommandItem[]>(() =>\n palette.value.map((spec) => ({\n value: spec.type,\n label: spec.palette!.label,\n group: spec.palette!.group,\n description: spec.palette!.description,\n keywords: spec.palette!.keywords,\n icon: spec.palette!.icon,\n })),\n)\nwatch(adding, (value) => {\n if (!value) return\n query.value = ''\n // a phone's keyboard would cover the list: search only with a mouse\n if (!matchMedia('(pointer: coarse)').matches) void nextTick(() => command.value?.focus())\n})\n\nfunction addNode(type: string) {\n adding.value = false\n full.value?.insertNode(type)\n}\nfunction dragNode(type: string, event: PointerEvent) {\n if (event.button !== 0) return\n full.value?.startInsertDrag(type, event)\n // the list goes once the node is dropped, or the drag ends otherwise\n window.addEventListener(\n 'pointerup',\n () => {\n if (!adding.value) return\n adding.value = false\n // a drag let go of (or cancelled) off the canvas: back to the button\n void nextTick(() => {\n // the list may not be hidden yet: focus still in its search field\n const active = document.activeElement\n const list = command.value?.$el as HTMLElement | undefined\n if (!active || active === document.body || list?.contains(active))\n (addTrigger.value?.$el as HTMLElement | undefined)?.focus({ preventScroll: true })\n })\n },\n { once: true },\n )\n}\n\n/** A label cut into the letters the search matched and the rest. */\nfunction parts(name: string, indices: number[]) {\n const hit = new Set(indices)\n const out: { text: string; match: boolean }[] = []\n for (let i = 0; i < name.length; i++) {\n const match = hit.has(i)\n const last = out[out.length - 1]\n if (last && last.match === match) last.text += name[i]\n else out.push({ text: name[i]!, match })\n }\n return out\n}\n\n/* changing the height: drag the bar under the block, or the arrow keys on it */\nfunction onResizeStart(event: PointerEvent) {\n if (event.button !== 0) return\n event.preventDefault()\n const bar = event.currentTarget as HTMLElement\n bar.setPointerCapture(event.pointerId)\n const startY = event.clientY\n const start = height.value\n const move = (e: PointerEvent) => (dragged.value = clampHeight(start + e.clientY - startY))\n const finish = (commit: boolean) => {\n bar.removeEventListener('pointermove', move)\n bar.removeEventListener('pointerup', up)\n bar.removeEventListener('pointercancel', cancel)\n window.removeEventListener('keydown', escape, true)\n const value = dragged.value\n dragged.value = null\n if (commit && value !== null && value !== start) props.updateProps({ height: value })\n }\n const up = () => finish(true)\n const cancel = () => finish(false)\n const escape = (e: KeyboardEvent) => {\n if (e.key !== 'Escape') return\n e.preventDefault()\n e.stopPropagation()\n finish(false)\n }\n bar.addEventListener('pointermove', move)\n bar.addEventListener('pointerup', up)\n bar.addEventListener('pointercancel', cancel)\n window.addEventListener('keydown', escape, true)\n}\n\nfunction onResizeKey(event: KeyboardEvent) {\n const by = { ArrowUp: -BOARD_HEIGHT.step, ArrowDown: BOARD_HEIGHT.step }[event.key]\n if (by) {\n event.preventDefault()\n props.updateProps({ height: clampHeight(height.value + by) })\n } else if (event.key === 'Escape') {\n event.preventDefault()\n onClosed()\n }\n}\n\nfunction resetHeight() {\n props.updateProps({ height: props.settings.height })\n}\n</script>\n\n<template>\n <div\n ref=\"root\"\n class=\"dou-editor-board\"\n :class=\"{ 'is-selected': selected, 'is-empty': empty }\"\n :style=\"{ height: `${height}px` }\"\n @dblclick=\"openEditor\"\n >\n <div v-if=\"!empty\" class=\"dou-editor-board__preview\" role=\"img\" :aria-label=\"label\">\n <DouFlowEditor\n class=\"dou-editor-board__canvas\"\n inert\n v-if=\"seen\"\n ref=\"preview\"\n :model-value=\"shown\"\n v-bind=\"settings.editorProps\"\n :extensions=\"settings.extensions\"\n :node-types=\"nodeTypes\"\n readonly\n fit-view\n :fit-min-zoom=\"0.05\"\n :simple-zoom=\"0\"\n :min-zoom=\"0.05\"\n :max-zoom=\"1\"\n :bordered=\"false\"\n :searchable=\"false\"\n :commentable=\"false\"\n :pan-on-scroll=\"false\"\n />\n </div>\n <div v-else class=\"dou-editor-board__empty\">\n <span class=\"dou-editor-board__empty-text\">{{ text.empty }}</span>\n <DouButton v-if=\"editable\" size=\"sm\" variant=\"outline\" @click=\"openEditor\">\n <template #leading><PencilIcon /></template>\n {{ text.start }}\n </DouButton>\n </div>\n\n <div v-if=\"!empty\" class=\"dou-editor-board__actions\">\n <DouButton size=\"sm\" variant=\"outline\" class=\"dou-editor-board__open\" @click=\"openEditor\">\n <template #leading><PencilIcon v-if=\"editable\" /><EyeIcon v-else /></template>\n {{ editable ? text.edit : text.view }}\n </DouButton>\n </div>\n\n <div\n v-if=\"editable\"\n class=\"dou-editor-board__resize\"\n role=\"separator\"\n aria-orientation=\"horizontal\"\n tabindex=\"0\"\n :aria-label=\"text.resize\"\n :aria-valuemin=\"BOARD_HEIGHT.min\"\n :aria-valuemax=\"BOARD_HEIGHT.max\"\n :aria-valuenow=\"height\"\n data-editor-control\n @pointerdown=\"onResizeStart\"\n @keydown=\"onResizeKey\"\n @dblclick.stop=\"resetHeight\"\n />\n\n <DouDialog\n v-model:open=\"open\"\n :title=\"label\"\n fullscreen\n destroy-on-close\n @opened=\"onOpened\"\n @close=\"settle\"\n @closed=\"onClosed\"\n >\n <div ref=\"canvas\" class=\"dou-editor-board__editor\" data-editor-control>\n <DouFlowEditor\n ref=\"full\"\n :model-value=\"board\"\n v-bind=\"settings.editorProps\"\n :extensions=\"extensions\"\n :node-types=\"nodeTypes\"\n :readonly=\"!editable\"\n fit-view\n :fit-min-zoom=\"0.1\"\n :simple-zoom=\"0.1\"\n :commentable=\"false\"\n :aria-label=\"label\"\n @transaction=\"forward\"\n >\n <DouFlowControls />\n <div v-if=\"palette.length\" class=\"dou-editor-board__add\">\n <DouButton\n v-if=\"palette.length === 1\"\n size=\"sm\"\n variant=\"outline\"\n @pointerdown=\"dragNode(palette[0]!.type, $event)\"\n @click=\"addNode(palette[0]!.type)\"\n >\n <template #leading><PlusIcon /></template>\n {{ text.addNode }}\n </DouButton>\n <DouPopover v-else v-model:open=\"adding\" placement=\"bottom-start\">\n <DouButton ref=\"addTrigger\" size=\"sm\" variant=\"outline\">\n <template #leading><PlusIcon /></template>\n {{ text.addNode }}\n </DouButton>\n <template #content>\n <DouCommand\n ref=\"command\"\n v-model:query=\"query\"\n class=\"dou-editor-board__types\"\n :items=\"items\"\n :placeholder=\"text.searchNodes\"\n :aria-label=\"text.addNode\"\n :empty-text=\"text.noNodes\"\n :max-height=\"280\"\n @select=\"addNode(String($event.value))\"\n >\n <template #item=\"{ item, indices }\">\n <span\n class=\"dou-editor-board__type\"\n @pointerdown=\"dragNode(String(item.value), $event)\"\n >\n <span class=\"dou-editor-board__type-icon\">\n <component :is=\"item.icon\" v-if=\"item.icon\" />\n </span>\n <span class=\"dou-command__label\">\n <template v-for=\"(part, at) in parts(item.label, indices)\" :key=\"at\">\n <mark v-if=\"part.match\" class=\"dou-command__match\">{{ part.text }}</mark>\n <template v-else>{{ part.text }}</template>\n </template>\n </span>\n <span v-if=\"item.description\" class=\"dou-command__description\">\n {{ item.description }}\n </span>\n </span>\n </template>\n </DouCommand>\n </template>\n </DouPopover>\n </div>\n <p v-if=\"palette.length && !board.nodes.length\" class=\"dou-editor-board__hint\">\n {{ text.emptyFlow }}\n </p>\n </DouFlowEditor>\n </div>\n </DouDialog>\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"board-block.js","names":["_sfc_main"],"sources":["../../src/flow/board-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n defaultNode,\n defineNodeType,\n DouFlowControls,\n DouFlowEditor,\n defineFlowExtension,\n type NodeTypeSpec,\n type FlowDocument,\n type FlowExtension,\n type FlowHistoryHandler,\n type FlowNode,\n type FlowTransaction,\n} from '@dou-ui/flow'\nimport type { CommentAction, CommentThread } from 'dou-ui'\nimport { EyeIcon, PencilIcon, PlusIcon, SquareIcon } from '@dou-ui/icons'\nimport { DouButton, DouCommand, DouDialog, DouPopover, type CommandItem } from 'dou-ui'\nimport { NodeSelection } from 'prosemirror-state'\nimport {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { findBlockById } from '../core/blocks'\nimport { historyCommands } from '../core/editor'\nimport { labelOf } from '../core/extension'\nimport type { BlockProps } from '../core/model'\nimport { joinStepKey, ownStepKey } from '../core/transaction'\nimport { useEditor } from '../editor'\nimport {\n BOARD_HEIGHT,\n BOARD_OPEN_EVENT,\n boardComments,\n boardOf,\n clampHeight,\n onlyBoardChanged,\n type BoardBlockSettings,\n} from './board'\n\n/** The board with the groups this reader folded or unfolded. */\nfunction withFolded(board: FlowDocument, folded: Map<string, boolean>): FlowDocument {\n if (!folded.size) return board\n const nodes = board.nodes.map((node) => {\n if (!folded.has(node.id)) return node\n const { collapsed: _, ...data } = node.data ?? {}\n return { ...node, data: folded.get(node.id) ? { ...data, collapsed: true } : data }\n })\n return { ...board, nodes }\n}\n\nconst props = defineProps<{\n block: { id: string; type: string; props: BlockProps }\n updateProps: (props: BlockProps) => void\n selected: boolean\n editable: boolean\n settings: BoardBlockSettings\n}>()\n\nconst { view, messages, comments } = useEditor()\nconst text = computed(() => messages.value.board)\nconst label = computed(() => labelOf(props.settings.label, messages.value))\nconst stored = computed(() => boardOf(props.block.props.board))\n/*\n * Whether a group is folded is each reader's own view, as with toggles: it\n * stays out of the document (what it holds there is kept), and is shown\n * from here.\n */\nconst folded = shallowRef(new Map<string, boolean>())\nconst board = computed(() => withFolded(stored.value, folded.value))\nconst empty = computed(() => !board.value.nodes.length)\n\n/* the fullscreen editor */\nconst open = shallowRef(false)\n/** The fullscreen editor is in place (its dialog done opening). */\nconst opened = shallowRef(false)\nwatch(open, (value) => {\n if (!value) shown.value = board.value\n})\n\n/*\n * Comment threads on the nodes and edges: the document's threads, author\n * and open thread, shown by the flow editors. The ids are kept on the nodes\n * and edges (see `boardComments`); a thread opened from outside, e.g. a\n * list of the document's comments, opens the fullscreen editor at it.\n */\nconst flowComments = computed(() =>\n props.settings.commentable && comments.enabled.value\n ? (comments.threads.value as CommentThread[])\n : undefined,\n)\nconst threadsHere = computed(\n () =>\n new Set(\n props.settings.commentable ? Object.keys(boardComments.anchors(props.block.props)) : [],\n ),\n)\nconst here = (id: string | null): id is string => !!id && threadsHere.value.has(id)\n/** The open thread, when it is on this board and the fullscreen editor shows it. */\nconst boardActive = computed(() =>\n opened.value && here(comments.active.value) ? comments.active.value : null,\n)\nwatch(\n () => comments.active.value,\n (id) => {\n if (here(id) && !open.value) openEditor()\n },\n)\n/*\n * The preview can't be pressed (it is inert and lets the pointer through to\n * the block), but its comment markers look like buttons: a click or tap on\n * one opens the board at its thread.\n */\nconst markerCursor = shallowRef(false)\nfunction markerAt(event: MouseEvent): string | null {\n if (!flowComments.value) return null\n const markers = root.value?.querySelectorAll<HTMLElement>(\n '.dou-editor-board__preview [data-thread]',\n )\n for (const marker of markers ?? []) {\n const box = marker.getBoundingClientRect()\n if (\n event.clientX >= box.left &&\n event.clientX <= box.right &&\n event.clientY >= box.top &&\n event.clientY <= box.bottom\n )\n return marker.dataset.thread ?? null\n }\n return null\n}\nfunction onPreviewClick(event: MouseEvent) {\n const id = markerAt(event)\n if (id) comments.open(id)\n}\nfunction onPreviewMove(event: PointerEvent) {\n if (event.pointerType === 'mouse') markerCursor.value = !!markerAt(event)\n}\n\nfunction onActive(id: string | null) {\n if (id !== boardActive.value) comments.open(id)\n}\nfunction onCommentAction(action: CommentAction) {\n comments.apply(action, { anchored: true })\n}\nfunction onClose() {\n settle()\n opened.value = false\n if (here(comments.active.value)) comments.open(null)\n}\n\nconst root = useTemplateRef<HTMLElement>('root')\nconst canvas = useTemplateRef<HTMLElement>('canvas')\nconst preview = useTemplateRef<InstanceType<typeof DouFlowEditor>>('preview')\n\n/* the height, followed live while the bar is dragged */\nconst dragged = shallowRef<number | null>(null)\nconst height = computed(\n () => dragged.value ?? clampHeight(Number(props.block.props.height) || props.settings.height),\n)\n\n/* the preview is drawn once the block comes near the screen */\nconst seen = shallowRef(typeof IntersectionObserver === 'undefined')\nlet observer: IntersectionObserver | null = null\nlet resized: ResizeObserver | null = null\nlet frame = 0\n/** Fits the preview to its box again, once the nodes have been laid out. */\nfunction refit() {\n cancelAnimationFrame(frame)\n frame = requestAnimationFrame(() => preview.value?.fit())\n}\nonMounted(() => {\n const element = root.value!\n element.addEventListener(BOARD_OPEN_EVENT, openEditor)\n if (!seen.value) {\n observer = new IntersectionObserver(\n (entries) => {\n if (!entries.some((entry) => entry.isIntersecting)) return\n seen.value = true\n observer?.disconnect()\n observer = null\n },\n { rootMargin: '200px' },\n )\n observer.observe(element)\n }\n if (typeof ResizeObserver !== 'undefined') {\n let width = element.clientWidth\n resized = new ResizeObserver(() => {\n if (element.clientWidth === width) return\n width = element.clientWidth\n refit()\n })\n resized.observe(element)\n }\n})\nonBeforeUnmount(() => {\n settle()\n root.value?.removeEventListener(BOARD_OPEN_EVENT, openEditor)\n observer?.disconnect()\n resized?.disconnect()\n cancelAnimationFrame(frame)\n})\n/* what the preview shows: held while the fullscreen editor covers it, so it isn't redrawn each frame */\nconst shown = shallowRef(board.value)\nwatch(board, (value) => {\n if (!open.value) shown.value = value\n})\nwatch(shown, () => void nextTick(refit))\nwatch(height, () => void nextTick(refit))\n\nfunction openEditor() {\n if (!props.editable && empty.value) return\n steps.undo = 0\n steps.redo = 0\n pending = null\n open.value = true\n}\n\nconst contentPos = () => {\n const state = view.value?.state\n return state ? (findBlockById(state.doc, props.block.id)?.contentPos ?? null) : null\n}\n\n/** The keys go to the canvas from the start: a tool's letter, `Esc` letting go of a selection. */\nfunction onOpened() {\n opened.value = true\n canvas.value?.querySelector<HTMLElement>('.dou-flow-editor')?.focus({ preventScroll: true })\n}\n\n/** Back in the document: the block selected, the editor focused. */\nfunction onClosed() {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n if (props.editable)\n editor.dispatch(editor.state.tr.setSelection(NodeSelection.create(editor.state.doc, pos)))\n editor.focus()\n}\n\n/*\n * Changes on the board go into the document as they are made, so `v-model`,\n * collaboration and the other blocks see them, and into the editor's undo\n * history: undo in the fullscreen editor is the document's, one step per\n * change on the board. The frames of a drag (or nudges with the arrow keys,\n * or typing in one node) join the step of the first one; only the fields\n * they change are written, so what others change meanwhile stays theirs. A\n * cancelled drag takes its step back.\n */\nconst GROUP_WINDOW = 1000\n/** A drag going on: its group, and when its last frame came. */\nlet pending: { group: string; time: number } | null = null\n/** The steps taken on the board since it was opened, and those undone. */\nconst steps = { undo: 0, redo: 0 }\n\n/** The board as the document keeps it: groups folded as they are there; and what this reader folded. */\nfunction toDocument(next: FlowDocument): FlowDocument {\n const before = new Map(stored.value.nodes.map((node) => [node.id, node]))\n let changed: Map<string, boolean> | null = null\n const nodes = next.nodes.map((node) => {\n const mine = !!node.data?.collapsed\n const theirs = before.get(node.id)?.data?.collapsed\n if (mine === !!theirs) {\n if (folded.value.has(node.id)) (changed ??= new Map(folded.value)).delete(node.id)\n return node\n }\n if (folded.value.get(node.id) !== mine) (changed ??= new Map(folded.value)).set(node.id, mine)\n const { collapsed: _, ...data } = node.data ?? {}\n if (theirs !== undefined) return { ...node, data: { ...data, collapsed: theirs } }\n // a node with no data before has none after\n if (Object.keys(data).length || before.get(node.id)?.data) return { ...node, data }\n const { data: __, ...rest } = node\n return rest as FlowNode\n })\n if (changed) folded.value = changed\n warnDataImages(next, before)\n return { ...next, nodes }\n}\n\nlet warned = false\n/** Pictures kept in the document as data URLs make it large: say so once, while developing. */\nfunction warnDataImages(next: FlowDocument, before: Map<string, FlowNode>) {\n if (warned || process.env.NODE_ENV === 'production') return\n const added = next.nodes.find(\n (node) =>\n typeof node.data?.src === 'string' &&\n node.data.src.startsWith('data:') &&\n before.get(node.id)?.data?.src !== node.data.src,\n )\n if (!added) return\n warned = true\n console.warn(\n `[@dou-ui/editor] a picture on the \"${props.block.type}\" block is kept in the document as a data URL; pass \\`upload\\` to whiteboardBlock() to keep only its address`,\n )\n}\n\nconst currentBoard = () => {\n const pos = contentPos()\n return pos === null ? null : (view.value?.state.doc.nodeAt(pos)?.attrs.board ?? null)\n}\n\n/** Writes the board as one undo step of its own. */\nfunction record(next: unknown) {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n editor.dispatch(editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta(ownStepKey, true))\n steps.undo++\n steps.redo = 0\n}\n\n/** Writes the board into the undo step before, the drag's. */\nfunction join(next: unknown) {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n const tr = editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta(joinStepKey, true)\n // for the built-in history: part of the step before, however long after\n editor.dispatch(tr.setMeta('appendedTransaction', editor.state.tr))\n}\n\n/** Ends the drag going on: the next change is a step of its own. */\nfunction settle() {\n pending = null\n}\n\nfunction forward(tr: FlowTransaction) {\n const editor = view.value\n const pos = contentPos()\n // a thread put on or taken off a node is written in a read-only document too, as on text\n const comment = tr.meta.origin === 'comment'\n if (!editor || pos === null || (!props.editable && !comment)) return\n const group = tr.meta.group\n const next = toDocument(tr.doc)\n // only folded or unfolded: nothing for the document\n if (JSON.stringify(next) === JSON.stringify(currentBoard())) return\n // not a step of the undo history, nor part of a drag going on\n if (comment) {\n editor.dispatch(\n editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta('addToHistory', false),\n )\n return\n }\n const now = Date.now()\n if (pending && (pending.group !== group || now - pending.time >= GROUP_WINDOW)) {\n // a cancelled drag putting the board back: part of its step\n if (tr.meta.history === false) return join(next)\n settle()\n }\n if (tr.meta.history === false) {\n editor.dispatch(\n editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta('addToHistory', false),\n )\n return\n }\n if (!group) return record(next)\n if (pending) {\n pending.time = now\n return join(next)\n }\n pending = { group, time: now }\n record(next)\n}\n\n/** Undo or redo in the document; refused when it would change something besides this board. */\nfunction travel(kind: 'undo' | 'redo') {\n settle()\n const editor = view.value\n if (!editor || !steps[kind]) return false\n const before = editor.state.doc\n const commands = historyCommands(editor.state)\n if (!commands[kind](editor.state, editor.dispatch, editor)) return false\n if (!onlyBoardChanged(before, editor.state.doc, props.block.id)) {\n // the board's own steps are used up: put back what was taken\n historyCommands(editor.state)[kind === 'undo' ? 'redo' : 'undo'](\n editor.state,\n editor.dispatch,\n editor,\n )\n steps[kind] = 0\n return false\n }\n steps[kind]--\n steps[kind === 'undo' ? 'redo' : 'undo']++\n return true\n}\n\n/** A cancelled drag: the board is back where it started, and its step is taken back. */\nfunction drop(group: string) {\n if (pending?.group !== group) return\n pending = null\n const editor = view.value\n if (!editor || !steps.undo) return\n if (historyCommands(editor.state).undo(editor.state, editor.dispatch, editor)) steps.undo--\n}\n\nconst history: FlowHistoryHandler = {\n undo: () => travel('undo'),\n redo: () => travel('redo'),\n canUndo: () => steps.undo > 0,\n canRedo: () => steps.redo > 0 && !pending,\n drop,\n close: settle,\n}\nconst bridge: FlowExtension = defineFlowExtension({\n name: 'editor-board-history',\n history: () => history,\n})\nconst extensions = [...props.settings.extensions, bridge]\n\n/*\n * Adding nodes: the types the extensions offer (`palette`), from a button\n * at the top left. When none is offered (`flowKit()` alone), a node of its\n * own with an input and an output, so what is added can be connected right\n * away.\n */\nconst offered = [\n ...props.settings.extensions.flat(),\n { nodeTypes: props.settings.editorProps.nodeTypes ?? [] },\n].some((extension) => extension.nodeTypes?.some((spec) => spec.palette))\nconst nodeTypes = computed(() => {\n const given = (props.settings.editorProps.nodeTypes ?? []) as NodeTypeSpec[]\n if (offered || !props.settings.fallbackNode) return given\n const name = text.value.node\n const step = defineNodeType({\n ...defaultNode,\n defaults: () => ({ label: name, inputs: [{ id: 'in' }], outputs: [{ id: 'out' }] }),\n palette: { label: name, icon: SquareIcon },\n }) as unknown as NodeTypeSpec\n return [step, ...given]\n})\nconst full = useTemplateRef<InstanceType<typeof DouFlowEditor>>('full')\nconst palette = computed(() => (props.editable ? (full.value?.paletteTypes ?? []) : []))\n/* several types: the same searchable list as when an edge is dropped on the canvas */\nconst adding = shallowRef(false)\nconst query = shallowRef('')\nconst addTrigger = useTemplateRef<InstanceType<typeof DouButton>>('addTrigger')\nconst command = useTemplateRef<InstanceType<typeof DouCommand>>('command')\nconst items = computed<CommandItem[]>(() =>\n palette.value.map((spec) => ({\n value: spec.type,\n label: spec.palette!.label,\n group: spec.palette!.group,\n description: spec.palette!.description,\n keywords: spec.palette!.keywords,\n icon: spec.palette!.icon,\n })),\n)\nwatch(adding, (value) => {\n if (!value) return\n query.value = ''\n // a phone's keyboard would cover the list: search only with a mouse\n if (!matchMedia('(pointer: coarse)').matches) void nextTick(() => command.value?.focus())\n})\n\nfunction addNode(type: string) {\n adding.value = false\n full.value?.insertNode(type)\n}\nfunction dragNode(type: string, event: PointerEvent) {\n if (event.button !== 0) return\n full.value?.startInsertDrag(type, event)\n // the list goes once the node is dropped, or the drag ends otherwise\n window.addEventListener(\n 'pointerup',\n () => {\n if (!adding.value) return\n adding.value = false\n // a drag let go of (or cancelled) off the canvas: back to the button\n void nextTick(() => {\n // the list may not be hidden yet: focus still in its search field\n const active = document.activeElement\n const list = command.value?.$el as HTMLElement | undefined\n if (!active || active === document.body || list?.contains(active))\n (addTrigger.value?.$el as HTMLElement | undefined)?.focus({ preventScroll: true })\n })\n },\n { once: true },\n )\n}\n\n/** A label cut into the letters the search matched and the rest. */\nfunction parts(name: string, indices: number[]) {\n const hit = new Set(indices)\n const out: { text: string; match: boolean }[] = []\n for (let i = 0; i < name.length; i++) {\n const match = hit.has(i)\n const last = out[out.length - 1]\n if (last && last.match === match) last.text += name[i]\n else out.push({ text: name[i]!, match })\n }\n return out\n}\n\n/* changing the height: drag the bar under the block, or the arrow keys on it */\nfunction onResizeStart(event: PointerEvent) {\n if (event.button !== 0) return\n event.preventDefault()\n const bar = event.currentTarget as HTMLElement\n bar.setPointerCapture(event.pointerId)\n const startY = event.clientY\n const start = height.value\n const move = (e: PointerEvent) => (dragged.value = clampHeight(start + e.clientY - startY))\n const finish = (commit: boolean) => {\n bar.removeEventListener('pointermove', move)\n bar.removeEventListener('pointerup', up)\n bar.removeEventListener('pointercancel', cancel)\n window.removeEventListener('keydown', escape, true)\n const value = dragged.value\n dragged.value = null\n if (commit && value !== null && value !== start) props.updateProps({ height: value })\n }\n const up = () => finish(true)\n const cancel = () => finish(false)\n const escape = (e: KeyboardEvent) => {\n if (e.key !== 'Escape') return\n e.preventDefault()\n e.stopPropagation()\n finish(false)\n }\n bar.addEventListener('pointermove', move)\n bar.addEventListener('pointerup', up)\n bar.addEventListener('pointercancel', cancel)\n window.addEventListener('keydown', escape, true)\n}\n\nfunction onResizeKey(event: KeyboardEvent) {\n const by = { ArrowUp: -BOARD_HEIGHT.step, ArrowDown: BOARD_HEIGHT.step }[event.key]\n if (by) {\n event.preventDefault()\n props.updateProps({ height: clampHeight(height.value + by) })\n } else if (event.key === 'Escape') {\n event.preventDefault()\n onClosed()\n }\n}\n\nfunction resetHeight() {\n props.updateProps({ height: props.settings.height })\n}\n</script>\n\n<template>\n <div\n ref=\"root\"\n class=\"dou-editor-board\"\n :class=\"{ 'is-selected': selected, 'is-empty': empty }\"\n :style=\"{ height: `${height}px`, cursor: markerCursor ? 'pointer' : undefined }\"\n @dblclick=\"openEditor\"\n @click=\"onPreviewClick\"\n @pointermove=\"onPreviewMove\"\n @pointerleave=\"markerCursor = false\"\n >\n <div v-if=\"!empty\" class=\"dou-editor-board__preview\" role=\"img\" :aria-label=\"label\">\n <DouFlowEditor\n class=\"dou-editor-board__canvas\"\n inert\n v-if=\"seen\"\n ref=\"preview\"\n :model-value=\"shown\"\n v-bind=\"settings.editorProps\"\n :extensions=\"settings.extensions\"\n :node-types=\"nodeTypes\"\n readonly\n fit-view\n :fit-min-zoom=\"0.05\"\n :simple-zoom=\"0\"\n :min-zoom=\"0.05\"\n :max-zoom=\"1\"\n :bordered=\"false\"\n :searchable=\"false\"\n :comments=\"flowComments\"\n :commentable=\"false\"\n :pan-on-scroll=\"false\"\n />\n </div>\n <div v-else class=\"dou-editor-board__empty\">\n <span class=\"dou-editor-board__empty-text\">{{ text.empty }}</span>\n <DouButton v-if=\"editable\" size=\"sm\" variant=\"outline\" @click=\"openEditor\">\n <template #leading><PencilIcon /></template>\n {{ text.start }}\n </DouButton>\n </div>\n\n <div v-if=\"!empty\" class=\"dou-editor-board__actions\">\n <DouButton size=\"sm\" variant=\"outline\" class=\"dou-editor-board__open\" @click=\"openEditor\">\n <template #leading><PencilIcon v-if=\"editable\" /><EyeIcon v-else /></template>\n {{ editable ? text.edit : text.view }}\n </DouButton>\n </div>\n\n <div\n v-if=\"editable\"\n class=\"dou-editor-board__resize\"\n role=\"separator\"\n aria-orientation=\"horizontal\"\n tabindex=\"0\"\n :aria-label=\"text.resize\"\n :aria-valuemin=\"BOARD_HEIGHT.min\"\n :aria-valuemax=\"BOARD_HEIGHT.max\"\n :aria-valuenow=\"height\"\n data-editor-control\n @pointerdown=\"onResizeStart\"\n @keydown=\"onResizeKey\"\n @dblclick.stop=\"resetHeight\"\n />\n\n <DouDialog\n v-model:open=\"open\"\n :title=\"label\"\n fullscreen\n destroy-on-close\n @opened=\"onOpened\"\n @close=\"onClose\"\n @closed=\"onClosed\"\n >\n <div ref=\"canvas\" class=\"dou-editor-board__editor\" data-editor-control>\n <DouFlowEditor\n ref=\"full\"\n :model-value=\"board\"\n v-bind=\"settings.editorProps\"\n :extensions=\"extensions\"\n :node-types=\"nodeTypes\"\n :readonly=\"!editable\"\n fit-view\n :fit-min-zoom=\"0.1\"\n :simple-zoom=\"0.1\"\n :comments=\"flowComments\"\n :author=\"comments.author.value\"\n :commentable=\"comments.writable.value\"\n :active-comment=\"boardActive\"\n :aria-label=\"label\"\n @transaction=\"forward\"\n @update:active-comment=\"onActive\"\n @comment-action=\"onCommentAction\"\n >\n <DouFlowControls />\n <div v-if=\"palette.length\" class=\"dou-editor-board__add\">\n <DouButton\n v-if=\"palette.length === 1\"\n size=\"sm\"\n variant=\"outline\"\n @pointerdown=\"dragNode(palette[0]!.type, $event)\"\n @click=\"addNode(palette[0]!.type)\"\n >\n <template #leading><PlusIcon /></template>\n {{ text.addNode }}\n </DouButton>\n <DouPopover v-else v-model:open=\"adding\" placement=\"bottom-start\">\n <DouButton ref=\"addTrigger\" size=\"sm\" variant=\"outline\">\n <template #leading><PlusIcon /></template>\n {{ text.addNode }}\n </DouButton>\n <template #content>\n <DouCommand\n ref=\"command\"\n v-model:query=\"query\"\n class=\"dou-editor-board__types\"\n :items=\"items\"\n :placeholder=\"text.searchNodes\"\n :aria-label=\"text.addNode\"\n :empty-text=\"text.noNodes\"\n :max-height=\"280\"\n @select=\"addNode(String($event.value))\"\n >\n <template #item=\"{ item, indices }\">\n <span\n class=\"dou-editor-board__type\"\n @pointerdown=\"dragNode(String(item.value), $event)\"\n >\n <span class=\"dou-editor-board__type-icon\">\n <component :is=\"item.icon\" v-if=\"item.icon\" />\n </span>\n <span class=\"dou-command__label\">\n <template v-for=\"(part, at) in parts(item.label, indices)\" :key=\"at\">\n <mark v-if=\"part.match\" class=\"dou-command__match\">{{ part.text }}</mark>\n <template v-else>{{ part.text }}</template>\n </template>\n </span>\n <span v-if=\"item.description\" class=\"dou-command__description\">\n {{ item.description }}\n </span>\n </span>\n </template>\n </DouCommand>\n </template>\n </DouPopover>\n </div>\n <p v-if=\"palette.length && !board.nodes.length\" class=\"dou-editor-board__hint\">\n {{ text.emptyFlow }}\n </p>\n </DouFlowEditor>\n </div>\n </DouDialog>\n </div>\n</template>\n"],"mappings":""}
|
|
@@ -3,7 +3,7 @@ import { findBlockById } from "../core/blocks.js";
|
|
|
3
3
|
import { useEditor } from "../editor.js";
|
|
4
4
|
import { historyCommands } from "../core/editor.js";
|
|
5
5
|
import { joinStepKey, ownStepKey } from "../core/transaction.js";
|
|
6
|
-
import { BOARD_HEIGHT, BOARD_OPEN_EVENT, boardOf, clampHeight, onlyBoardChanged } from "./board.js";
|
|
6
|
+
import { BOARD_HEIGHT, BOARD_OPEN_EVENT, boardComments, boardOf, clampHeight, onlyBoardChanged } from "./board.js";
|
|
7
7
|
import { DouButton, DouCommand, DouDialog, DouPopover } from "dou-ui";
|
|
8
8
|
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, mergeProps, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, openBlock, renderList, resolveDynamicComponent, shallowRef, toDisplayString, unref, useTemplateRef, watch, withCtx, withModifiers } from "vue";
|
|
9
9
|
import { NodeSelection } from "prosemirror-state";
|
|
@@ -77,7 +77,7 @@ var board_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
const props = __props;
|
|
80
|
-
const { view, messages } = useEditor();
|
|
80
|
+
const { view, messages, comments } = useEditor();
|
|
81
81
|
const text = computed(() => messages.value.board);
|
|
82
82
|
const label = computed(() => labelOf(props.settings.label, messages.value));
|
|
83
83
|
const stored = computed(() => boardOf(props.block.props.board));
|
|
@@ -85,9 +85,47 @@ var board_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
85
85
|
const board = computed(() => withFolded(stored.value, folded.value));
|
|
86
86
|
const empty = computed(() => !board.value.nodes.length);
|
|
87
87
|
const open = shallowRef(false);
|
|
88
|
+
/** The fullscreen editor is in place (its dialog done opening). */
|
|
89
|
+
const opened = shallowRef(false);
|
|
88
90
|
watch(open, (value) => {
|
|
89
91
|
if (!value) shown.value = board.value;
|
|
90
92
|
});
|
|
93
|
+
const flowComments = computed(() => props.settings.commentable && comments.enabled.value ? comments.threads.value : void 0);
|
|
94
|
+
const threadsHere = computed(() => new Set(props.settings.commentable ? Object.keys(boardComments.anchors(props.block.props)) : []));
|
|
95
|
+
const here = (id) => !!id && threadsHere.value.has(id);
|
|
96
|
+
/** The open thread, when it is on this board and the fullscreen editor shows it. */
|
|
97
|
+
const boardActive = computed(() => opened.value && here(comments.active.value) ? comments.active.value : null);
|
|
98
|
+
watch(() => comments.active.value, (id) => {
|
|
99
|
+
if (here(id) && !open.value) openEditor();
|
|
100
|
+
});
|
|
101
|
+
const markerCursor = shallowRef(false);
|
|
102
|
+
function markerAt(event) {
|
|
103
|
+
if (!flowComments.value) return null;
|
|
104
|
+
const markers = root.value?.querySelectorAll(".dou-editor-board__preview [data-thread]");
|
|
105
|
+
for (const marker of markers ?? []) {
|
|
106
|
+
const box = marker.getBoundingClientRect();
|
|
107
|
+
if (event.clientX >= box.left && event.clientX <= box.right && event.clientY >= box.top && event.clientY <= box.bottom) return marker.dataset.thread ?? null;
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
function onPreviewClick(event) {
|
|
112
|
+
const id = markerAt(event);
|
|
113
|
+
if (id) comments.open(id);
|
|
114
|
+
}
|
|
115
|
+
function onPreviewMove(event) {
|
|
116
|
+
if (event.pointerType === "mouse") markerCursor.value = !!markerAt(event);
|
|
117
|
+
}
|
|
118
|
+
function onActive(id) {
|
|
119
|
+
if (id !== boardActive.value) comments.open(id);
|
|
120
|
+
}
|
|
121
|
+
function onCommentAction(action) {
|
|
122
|
+
comments.apply(action, { anchored: true });
|
|
123
|
+
}
|
|
124
|
+
function onClose() {
|
|
125
|
+
settle();
|
|
126
|
+
opened.value = false;
|
|
127
|
+
if (here(comments.active.value)) comments.open(null);
|
|
128
|
+
}
|
|
91
129
|
const root = useTemplateRef("root");
|
|
92
130
|
const canvas = useTemplateRef("canvas");
|
|
93
131
|
const preview = useTemplateRef("preview");
|
|
@@ -150,6 +188,7 @@ var board_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
150
188
|
};
|
|
151
189
|
/** The keys go to the canvas from the start: a tool's letter, `Esc` letting go of a selection. */
|
|
152
190
|
function onOpened() {
|
|
191
|
+
opened.value = true;
|
|
153
192
|
canvas.value?.querySelector(".dou-flow-editor")?.focus({ preventScroll: true });
|
|
154
193
|
}
|
|
155
194
|
/** Back in the document: the block selected, the editor focused. */
|
|
@@ -236,10 +275,15 @@ var board_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
236
275
|
function forward(tr) {
|
|
237
276
|
const editor = view.value;
|
|
238
277
|
const pos = contentPos();
|
|
239
|
-
|
|
278
|
+
const comment = tr.meta.origin === "comment";
|
|
279
|
+
if (!editor || pos === null || !props.editable && !comment) return;
|
|
240
280
|
const group = tr.meta.group;
|
|
241
281
|
const next = toDocument(tr.doc);
|
|
242
282
|
if (JSON.stringify(next) === JSON.stringify(currentBoard())) return;
|
|
283
|
+
if (comment) {
|
|
284
|
+
editor.dispatch(editor.state.tr.setNodeAttribute(pos, "board", next).setMeta("addToHistory", false));
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
243
287
|
const now = Date.now();
|
|
244
288
|
if (pending && (pending.group !== group || now - pending.time >= GROUP_WINDOW)) {
|
|
245
289
|
if (tr.meta.history === false) return join(next);
|
|
@@ -420,8 +464,14 @@ var board_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
420
464
|
"is-selected": __props.selected,
|
|
421
465
|
"is-empty": empty.value
|
|
422
466
|
}]),
|
|
423
|
-
style: normalizeStyle({
|
|
424
|
-
|
|
467
|
+
style: normalizeStyle({
|
|
468
|
+
height: `${height.value}px`,
|
|
469
|
+
cursor: markerCursor.value ? "pointer" : void 0
|
|
470
|
+
}),
|
|
471
|
+
onDblclick: openEditor,
|
|
472
|
+
onClick: onPreviewClick,
|
|
473
|
+
onPointermove: onPreviewMove,
|
|
474
|
+
onPointerleave: _cache[6] || (_cache[6] = ($event) => markerCursor.value = false)
|
|
425
475
|
}, [
|
|
426
476
|
!empty.value ? (openBlock(), createElementBlock("div", {
|
|
427
477
|
key: 0,
|
|
@@ -446,12 +496,14 @@ var board_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
446
496
|
"max-zoom": 1,
|
|
447
497
|
bordered: false,
|
|
448
498
|
searchable: false,
|
|
499
|
+
comments: flowComments.value,
|
|
449
500
|
commentable: false,
|
|
450
501
|
"pan-on-scroll": false
|
|
451
502
|
}), null, 16, [
|
|
452
503
|
"model-value",
|
|
453
504
|
"extensions",
|
|
454
|
-
"node-types"
|
|
505
|
+
"node-types",
|
|
506
|
+
"comments"
|
|
455
507
|
])) : createCommentVNode("", true)], 8, _hoisted_1)) : (openBlock(), createElementBlock("div", _hoisted_2, [createElementVNode("span", _hoisted_3, toDisplayString(text.value.empty), 1), __props.editable ? (openBlock(), createBlock(unref(DouButton), {
|
|
456
508
|
key: 0,
|
|
457
509
|
size: "sm",
|
|
@@ -494,7 +546,7 @@ var board_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
494
546
|
fullscreen: "",
|
|
495
547
|
"destroy-on-close": "",
|
|
496
548
|
onOpened,
|
|
497
|
-
onClose
|
|
549
|
+
onClose,
|
|
498
550
|
onClosed
|
|
499
551
|
}, {
|
|
500
552
|
default: withCtx(() => [createElementVNode("div", {
|
|
@@ -513,9 +565,14 @@ var board_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
513
565
|
"fit-view": "",
|
|
514
566
|
"fit-min-zoom": .1,
|
|
515
567
|
"simple-zoom": .1,
|
|
516
|
-
|
|
568
|
+
comments: flowComments.value,
|
|
569
|
+
author: unref(comments).author.value,
|
|
570
|
+
commentable: unref(comments).writable.value,
|
|
571
|
+
"active-comment": boardActive.value,
|
|
517
572
|
"aria-label": label.value,
|
|
518
|
-
onTransaction: forward
|
|
573
|
+
onTransaction: forward,
|
|
574
|
+
"onUpdate:activeComment": onActive,
|
|
575
|
+
onCommentAction
|
|
519
576
|
}), {
|
|
520
577
|
default: withCtx(() => [
|
|
521
578
|
createVNode(unref(DouFlowControls)),
|
|
@@ -585,6 +642,10 @@ var board_block_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
585
642
|
"model-value",
|
|
586
643
|
"node-types",
|
|
587
644
|
"readonly",
|
|
645
|
+
"comments",
|
|
646
|
+
"author",
|
|
647
|
+
"commentable",
|
|
648
|
+
"active-comment",
|
|
588
649
|
"aria-label"
|
|
589
650
|
])], 512)]),
|
|
590
651
|
_: 1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board-block.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_normalizeStyle","_createBlock","_unref","_mergeProps","_createCommentVNode","_createElementVNode","_toDisplayString","_withCtx","_createVNode","_createTextVNode","_withModifiers","_resolveDynamicComponent","_Fragment","_renderList"],"sources":["../../src/flow/board-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n defaultNode,\n defineNodeType,\n DouFlowControls,\n DouFlowEditor,\n defineFlowExtension,\n type NodeTypeSpec,\n type FlowDocument,\n type FlowExtension,\n type FlowHistoryHandler,\n type FlowNode,\n type FlowTransaction,\n} from '@dou-ui/flow'\nimport { EyeIcon, PencilIcon, PlusIcon, SquareIcon } from '@dou-ui/icons'\nimport { DouButton, DouCommand, DouDialog, DouPopover, type CommandItem } from 'dou-ui'\nimport { NodeSelection } from 'prosemirror-state'\nimport {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { findBlockById } from '../core/blocks'\nimport { historyCommands } from '../core/editor'\nimport { labelOf } from '../core/extension'\nimport type { BlockProps } from '../core/model'\nimport { joinStepKey, ownStepKey } from '../core/transaction'\nimport { useEditor } from '../editor'\nimport {\n BOARD_HEIGHT,\n BOARD_OPEN_EVENT,\n boardOf,\n clampHeight,\n onlyBoardChanged,\n type BoardBlockSettings,\n} from './board'\n\n/** The board with the groups this reader folded or unfolded. */\nfunction withFolded(board: FlowDocument, folded: Map<string, boolean>): FlowDocument {\n if (!folded.size) return board\n const nodes = board.nodes.map((node) => {\n if (!folded.has(node.id)) return node\n const { collapsed: _, ...data } = node.data ?? {}\n return { ...node, data: folded.get(node.id) ? { ...data, collapsed: true } : data }\n })\n return { ...board, nodes }\n}\n\nconst props = defineProps<{\n block: { id: string; type: string; props: BlockProps }\n updateProps: (props: BlockProps) => void\n selected: boolean\n editable: boolean\n settings: BoardBlockSettings\n}>()\n\nconst { view, messages } = useEditor()\nconst text = computed(() => messages.value.board)\nconst label = computed(() => labelOf(props.settings.label, messages.value))\nconst stored = computed(() => boardOf(props.block.props.board))\n/*\n * Whether a group is folded is each reader's own view, as with toggles: it\n * stays out of the document (what it holds there is kept), and is shown\n * from here.\n */\nconst folded = shallowRef(new Map<string, boolean>())\nconst board = computed(() => withFolded(stored.value, folded.value))\nconst empty = computed(() => !board.value.nodes.length)\n\n/* the fullscreen editor */\nconst open = shallowRef(false)\nwatch(open, (value) => {\n if (!value) shown.value = board.value\n})\n\nconst root = useTemplateRef<HTMLElement>('root')\nconst canvas = useTemplateRef<HTMLElement>('canvas')\nconst preview = useTemplateRef<InstanceType<typeof DouFlowEditor>>('preview')\n\n/* the height, followed live while the bar is dragged */\nconst dragged = shallowRef<number | null>(null)\nconst height = computed(\n () => dragged.value ?? clampHeight(Number(props.block.props.height) || props.settings.height),\n)\n\n/* the preview is drawn once the block comes near the screen */\nconst seen = shallowRef(typeof IntersectionObserver === 'undefined')\nlet observer: IntersectionObserver | null = null\nlet resized: ResizeObserver | null = null\nlet frame = 0\n/** Fits the preview to its box again, once the nodes have been laid out. */\nfunction refit() {\n cancelAnimationFrame(frame)\n frame = requestAnimationFrame(() => preview.value?.fit())\n}\nonMounted(() => {\n const element = root.value!\n element.addEventListener(BOARD_OPEN_EVENT, openEditor)\n if (!seen.value) {\n observer = new IntersectionObserver(\n (entries) => {\n if (!entries.some((entry) => entry.isIntersecting)) return\n seen.value = true\n observer?.disconnect()\n observer = null\n },\n { rootMargin: '200px' },\n )\n observer.observe(element)\n }\n if (typeof ResizeObserver !== 'undefined') {\n let width = element.clientWidth\n resized = new ResizeObserver(() => {\n if (element.clientWidth === width) return\n width = element.clientWidth\n refit()\n })\n resized.observe(element)\n }\n})\nonBeforeUnmount(() => {\n settle()\n root.value?.removeEventListener(BOARD_OPEN_EVENT, openEditor)\n observer?.disconnect()\n resized?.disconnect()\n cancelAnimationFrame(frame)\n})\n/* what the preview shows: held while the fullscreen editor covers it, so it isn't redrawn each frame */\nconst shown = shallowRef(board.value)\nwatch(board, (value) => {\n if (!open.value) shown.value = value\n})\nwatch(shown, () => void nextTick(refit))\nwatch(height, () => void nextTick(refit))\n\nfunction openEditor() {\n if (!props.editable && empty.value) return\n steps.undo = 0\n steps.redo = 0\n pending = null\n open.value = true\n}\n\nconst contentPos = () => {\n const state = view.value?.state\n return state ? (findBlockById(state.doc, props.block.id)?.contentPos ?? null) : null\n}\n\n/** The keys go to the canvas from the start: a tool's letter, `Esc` letting go of a selection. */\nfunction onOpened() {\n canvas.value?.querySelector<HTMLElement>('.dou-flow-editor')?.focus({ preventScroll: true })\n}\n\n/** Back in the document: the block selected, the editor focused. */\nfunction onClosed() {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n if (props.editable)\n editor.dispatch(editor.state.tr.setSelection(NodeSelection.create(editor.state.doc, pos)))\n editor.focus()\n}\n\n/*\n * Changes on the board go into the document as they are made, so `v-model`,\n * collaboration and the other blocks see them, and into the editor's undo\n * history: undo in the fullscreen editor is the document's, one step per\n * change on the board. The frames of a drag (or nudges with the arrow keys,\n * or typing in one node) join the step of the first one; only the fields\n * they change are written, so what others change meanwhile stays theirs. A\n * cancelled drag takes its step back.\n */\nconst GROUP_WINDOW = 1000\n/** A drag going on: its group, and when its last frame came. */\nlet pending: { group: string; time: number } | null = null\n/** The steps taken on the board since it was opened, and those undone. */\nconst steps = { undo: 0, redo: 0 }\n\n/** The board as the document keeps it: groups folded as they are there; and what this reader folded. */\nfunction toDocument(next: FlowDocument): FlowDocument {\n const before = new Map(stored.value.nodes.map((node) => [node.id, node]))\n let changed: Map<string, boolean> | null = null\n const nodes = next.nodes.map((node) => {\n const mine = !!node.data?.collapsed\n const theirs = before.get(node.id)?.data?.collapsed\n if (mine === !!theirs) {\n if (folded.value.has(node.id)) (changed ??= new Map(folded.value)).delete(node.id)\n return node\n }\n if (folded.value.get(node.id) !== mine) (changed ??= new Map(folded.value)).set(node.id, mine)\n const { collapsed: _, ...data } = node.data ?? {}\n if (theirs !== undefined) return { ...node, data: { ...data, collapsed: theirs } }\n // a node with no data before has none after\n if (Object.keys(data).length || before.get(node.id)?.data) return { ...node, data }\n const { data: __, ...rest } = node\n return rest as FlowNode\n })\n if (changed) folded.value = changed\n warnDataImages(next, before)\n return { ...next, nodes }\n}\n\nlet warned = false\n/** Pictures kept in the document as data URLs make it large: say so once, while developing. */\nfunction warnDataImages(next: FlowDocument, before: Map<string, FlowNode>) {\n if (warned || process.env.NODE_ENV === 'production') return\n const added = next.nodes.find(\n (node) =>\n typeof node.data?.src === 'string' &&\n node.data.src.startsWith('data:') &&\n before.get(node.id)?.data?.src !== node.data.src,\n )\n if (!added) return\n warned = true\n console.warn(\n `[@dou-ui/editor] a picture on the \"${props.block.type}\" block is kept in the document as a data URL; pass \\`upload\\` to whiteboardBlock() to keep only its address`,\n )\n}\n\nconst currentBoard = () => {\n const pos = contentPos()\n return pos === null ? null : (view.value?.state.doc.nodeAt(pos)?.attrs.board ?? null)\n}\n\n/** Writes the board as one undo step of its own. */\nfunction record(next: unknown) {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n editor.dispatch(editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta(ownStepKey, true))\n steps.undo++\n steps.redo = 0\n}\n\n/** Writes the board into the undo step before, the drag's. */\nfunction join(next: unknown) {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n const tr = editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta(joinStepKey, true)\n // for the built-in history: part of the step before, however long after\n editor.dispatch(tr.setMeta('appendedTransaction', editor.state.tr))\n}\n\n/** Ends the drag going on: the next change is a step of its own. */\nfunction settle() {\n pending = null\n}\n\nfunction forward(tr: FlowTransaction) {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null || !props.editable) return\n const group = tr.meta.group\n const next = toDocument(tr.doc)\n // only folded or unfolded: nothing for the document\n if (JSON.stringify(next) === JSON.stringify(currentBoard())) return\n const now = Date.now()\n if (pending && (pending.group !== group || now - pending.time >= GROUP_WINDOW)) {\n // a cancelled drag putting the board back: part of its step\n if (tr.meta.history === false) return join(next)\n settle()\n }\n if (tr.meta.history === false) {\n editor.dispatch(\n editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta('addToHistory', false),\n )\n return\n }\n if (!group) return record(next)\n if (pending) {\n pending.time = now\n return join(next)\n }\n pending = { group, time: now }\n record(next)\n}\n\n/** Undo or redo in the document; refused when it would change something besides this board. */\nfunction travel(kind: 'undo' | 'redo') {\n settle()\n const editor = view.value\n if (!editor || !steps[kind]) return false\n const before = editor.state.doc\n const commands = historyCommands(editor.state)\n if (!commands[kind](editor.state, editor.dispatch, editor)) return false\n if (!onlyBoardChanged(before, editor.state.doc, props.block.id)) {\n // the board's own steps are used up: put back what was taken\n historyCommands(editor.state)[kind === 'undo' ? 'redo' : 'undo'](\n editor.state,\n editor.dispatch,\n editor,\n )\n steps[kind] = 0\n return false\n }\n steps[kind]--\n steps[kind === 'undo' ? 'redo' : 'undo']++\n return true\n}\n\n/** A cancelled drag: the board is back where it started, and its step is taken back. */\nfunction drop(group: string) {\n if (pending?.group !== group) return\n pending = null\n const editor = view.value\n if (!editor || !steps.undo) return\n if (historyCommands(editor.state).undo(editor.state, editor.dispatch, editor)) steps.undo--\n}\n\nconst history: FlowHistoryHandler = {\n undo: () => travel('undo'),\n redo: () => travel('redo'),\n canUndo: () => steps.undo > 0,\n canRedo: () => steps.redo > 0 && !pending,\n drop,\n close: settle,\n}\nconst bridge: FlowExtension = defineFlowExtension({\n name: 'editor-board-history',\n history: () => history,\n})\nconst extensions = [...props.settings.extensions, bridge]\n\n/*\n * Adding nodes: the types the extensions offer (`palette`), from a button\n * at the top left. When none is offered (`flowKit()` alone), a node of its\n * own with an input and an output, so what is added can be connected right\n * away.\n */\nconst offered = [\n ...props.settings.extensions.flat(),\n { nodeTypes: props.settings.editorProps.nodeTypes ?? [] },\n].some((extension) => extension.nodeTypes?.some((spec) => spec.palette))\nconst nodeTypes = computed(() => {\n const given = (props.settings.editorProps.nodeTypes ?? []) as NodeTypeSpec[]\n if (offered || !props.settings.fallbackNode) return given\n const name = text.value.node\n const step = defineNodeType({\n ...defaultNode,\n defaults: () => ({ label: name, inputs: [{ id: 'in' }], outputs: [{ id: 'out' }] }),\n palette: { label: name, icon: SquareIcon },\n }) as unknown as NodeTypeSpec\n return [step, ...given]\n})\nconst full = useTemplateRef<InstanceType<typeof DouFlowEditor>>('full')\nconst palette = computed(() => (props.editable ? (full.value?.paletteTypes ?? []) : []))\n/* several types: the same searchable list as when an edge is dropped on the canvas */\nconst adding = shallowRef(false)\nconst query = shallowRef('')\nconst addTrigger = useTemplateRef<InstanceType<typeof DouButton>>('addTrigger')\nconst command = useTemplateRef<InstanceType<typeof DouCommand>>('command')\nconst items = computed<CommandItem[]>(() =>\n palette.value.map((spec) => ({\n value: spec.type,\n label: spec.palette!.label,\n group: spec.palette!.group,\n description: spec.palette!.description,\n keywords: spec.palette!.keywords,\n icon: spec.palette!.icon,\n })),\n)\nwatch(adding, (value) => {\n if (!value) return\n query.value = ''\n // a phone's keyboard would cover the list: search only with a mouse\n if (!matchMedia('(pointer: coarse)').matches) void nextTick(() => command.value?.focus())\n})\n\nfunction addNode(type: string) {\n adding.value = false\n full.value?.insertNode(type)\n}\nfunction dragNode(type: string, event: PointerEvent) {\n if (event.button !== 0) return\n full.value?.startInsertDrag(type, event)\n // the list goes once the node is dropped, or the drag ends otherwise\n window.addEventListener(\n 'pointerup',\n () => {\n if (!adding.value) return\n adding.value = false\n // a drag let go of (or cancelled) off the canvas: back to the button\n void nextTick(() => {\n // the list may not be hidden yet: focus still in its search field\n const active = document.activeElement\n const list = command.value?.$el as HTMLElement | undefined\n if (!active || active === document.body || list?.contains(active))\n (addTrigger.value?.$el as HTMLElement | undefined)?.focus({ preventScroll: true })\n })\n },\n { once: true },\n )\n}\n\n/** A label cut into the letters the search matched and the rest. */\nfunction parts(name: string, indices: number[]) {\n const hit = new Set(indices)\n const out: { text: string; match: boolean }[] = []\n for (let i = 0; i < name.length; i++) {\n const match = hit.has(i)\n const last = out[out.length - 1]\n if (last && last.match === match) last.text += name[i]\n else out.push({ text: name[i]!, match })\n }\n return out\n}\n\n/* changing the height: drag the bar under the block, or the arrow keys on it */\nfunction onResizeStart(event: PointerEvent) {\n if (event.button !== 0) return\n event.preventDefault()\n const bar = event.currentTarget as HTMLElement\n bar.setPointerCapture(event.pointerId)\n const startY = event.clientY\n const start = height.value\n const move = (e: PointerEvent) => (dragged.value = clampHeight(start + e.clientY - startY))\n const finish = (commit: boolean) => {\n bar.removeEventListener('pointermove', move)\n bar.removeEventListener('pointerup', up)\n bar.removeEventListener('pointercancel', cancel)\n window.removeEventListener('keydown', escape, true)\n const value = dragged.value\n dragged.value = null\n if (commit && value !== null && value !== start) props.updateProps({ height: value })\n }\n const up = () => finish(true)\n const cancel = () => finish(false)\n const escape = (e: KeyboardEvent) => {\n if (e.key !== 'Escape') return\n e.preventDefault()\n e.stopPropagation()\n finish(false)\n }\n bar.addEventListener('pointermove', move)\n bar.addEventListener('pointerup', up)\n bar.addEventListener('pointercancel', cancel)\n window.addEventListener('keydown', escape, true)\n}\n\nfunction onResizeKey(event: KeyboardEvent) {\n const by = { ArrowUp: -BOARD_HEIGHT.step, ArrowDown: BOARD_HEIGHT.step }[event.key]\n if (by) {\n event.preventDefault()\n props.updateProps({ height: clampHeight(height.value + by) })\n } else if (event.key === 'Escape') {\n event.preventDefault()\n onClosed()\n }\n}\n\nfunction resetHeight() {\n props.updateProps({ height: props.settings.height })\n}\n</script>\n\n<template>\n <div\n ref=\"root\"\n class=\"dou-editor-board\"\n :class=\"{ 'is-selected': selected, 'is-empty': empty }\"\n :style=\"{ height: `${height}px` }\"\n @dblclick=\"openEditor\"\n >\n <div v-if=\"!empty\" class=\"dou-editor-board__preview\" role=\"img\" :aria-label=\"label\">\n <DouFlowEditor\n class=\"dou-editor-board__canvas\"\n inert\n v-if=\"seen\"\n ref=\"preview\"\n :model-value=\"shown\"\n v-bind=\"settings.editorProps\"\n :extensions=\"settings.extensions\"\n :node-types=\"nodeTypes\"\n readonly\n fit-view\n :fit-min-zoom=\"0.05\"\n :simple-zoom=\"0\"\n :min-zoom=\"0.05\"\n :max-zoom=\"1\"\n :bordered=\"false\"\n :searchable=\"false\"\n :commentable=\"false\"\n :pan-on-scroll=\"false\"\n />\n </div>\n <div v-else class=\"dou-editor-board__empty\">\n <span class=\"dou-editor-board__empty-text\">{{ text.empty }}</span>\n <DouButton v-if=\"editable\" size=\"sm\" variant=\"outline\" @click=\"openEditor\">\n <template #leading><PencilIcon /></template>\n {{ text.start }}\n </DouButton>\n </div>\n\n <div v-if=\"!empty\" class=\"dou-editor-board__actions\">\n <DouButton size=\"sm\" variant=\"outline\" class=\"dou-editor-board__open\" @click=\"openEditor\">\n <template #leading><PencilIcon v-if=\"editable\" /><EyeIcon v-else /></template>\n {{ editable ? text.edit : text.view }}\n </DouButton>\n </div>\n\n <div\n v-if=\"editable\"\n class=\"dou-editor-board__resize\"\n role=\"separator\"\n aria-orientation=\"horizontal\"\n tabindex=\"0\"\n :aria-label=\"text.resize\"\n :aria-valuemin=\"BOARD_HEIGHT.min\"\n :aria-valuemax=\"BOARD_HEIGHT.max\"\n :aria-valuenow=\"height\"\n data-editor-control\n @pointerdown=\"onResizeStart\"\n @keydown=\"onResizeKey\"\n @dblclick.stop=\"resetHeight\"\n />\n\n <DouDialog\n v-model:open=\"open\"\n :title=\"label\"\n fullscreen\n destroy-on-close\n @opened=\"onOpened\"\n @close=\"settle\"\n @closed=\"onClosed\"\n >\n <div ref=\"canvas\" class=\"dou-editor-board__editor\" data-editor-control>\n <DouFlowEditor\n ref=\"full\"\n :model-value=\"board\"\n v-bind=\"settings.editorProps\"\n :extensions=\"extensions\"\n :node-types=\"nodeTypes\"\n :readonly=\"!editable\"\n fit-view\n :fit-min-zoom=\"0.1\"\n :simple-zoom=\"0.1\"\n :commentable=\"false\"\n :aria-label=\"label\"\n @transaction=\"forward\"\n >\n <DouFlowControls />\n <div v-if=\"palette.length\" class=\"dou-editor-board__add\">\n <DouButton\n v-if=\"palette.length === 1\"\n size=\"sm\"\n variant=\"outline\"\n @pointerdown=\"dragNode(palette[0]!.type, $event)\"\n @click=\"addNode(palette[0]!.type)\"\n >\n <template #leading><PlusIcon /></template>\n {{ text.addNode }}\n </DouButton>\n <DouPopover v-else v-model:open=\"adding\" placement=\"bottom-start\">\n <DouButton ref=\"addTrigger\" size=\"sm\" variant=\"outline\">\n <template #leading><PlusIcon /></template>\n {{ text.addNode }}\n </DouButton>\n <template #content>\n <DouCommand\n ref=\"command\"\n v-model:query=\"query\"\n class=\"dou-editor-board__types\"\n :items=\"items\"\n :placeholder=\"text.searchNodes\"\n :aria-label=\"text.addNode\"\n :empty-text=\"text.noNodes\"\n :max-height=\"280\"\n @select=\"addNode(String($event.value))\"\n >\n <template #item=\"{ item, indices }\">\n <span\n class=\"dou-editor-board__type\"\n @pointerdown=\"dragNode(String(item.value), $event)\"\n >\n <span class=\"dou-editor-board__type-icon\">\n <component :is=\"item.icon\" v-if=\"item.icon\" />\n </span>\n <span class=\"dou-command__label\">\n <template v-for=\"(part, at) in parts(item.label, indices)\" :key=\"at\">\n <mark v-if=\"part.match\" class=\"dou-command__match\">{{ part.text }}</mark>\n <template v-else>{{ part.text }}</template>\n </template>\n </span>\n <span v-if=\"item.description\" class=\"dou-command__description\">\n {{ item.description }}\n </span>\n </span>\n </template>\n </DouCommand>\n </template>\n </DouPopover>\n </div>\n <p v-if=\"palette.length && !board.nodes.length\" class=\"dou-editor-board__hint\">\n {{ text.emptyFlow }}\n </p>\n </DouFlowEditor>\n </div>\n </DouDialog>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgLA,IAAM,eAAe;;;;;;;;;;;;EAtIrB,SAAS,WAAW,OAAqB,QAA4C;GACnF,IAAI,CAAC,OAAO,MAAM,OAAO;GACzB,MAAM,QAAQ,MAAM,MAAM,KAAK,SAAS;IACtC,IAAI,CAAC,OAAO,IAAI,KAAK,EAAE,GAAG,OAAO;IACjC,MAAM,EAAE,WAAW,GAAG,GAAG,SAAS,KAAK,QAAQ,CAAC;IAChD,OAAO;KAAE,GAAG;KAAM,MAAM,OAAO,IAAI,KAAK,EAAE,IAAI;MAAE,GAAG;MAAM,WAAW;KAAK,IAAI;IAAK;GACpF,CAAC;GACD,OAAO;IAAE,GAAG;IAAO;GAAM;EAC3B;EAEA,MAAM,QAAQ;EAQd,MAAM,EAAE,MAAM,aAAa,UAAU;EACrC,MAAM,OAAO,eAAe,SAAS,MAAM,KAAK;EAChD,MAAM,QAAQ,eAAe,QAAQ,MAAM,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AAK,SAAQ;;SACjC,SAAOK,cAAa,CAAZC,YAAYN,MAAA,QAAA,CAAA,C;SAAW,SAAAK,cAC1C,CAD0CE,gBAAA,MAC1CH,gBAAG,KAAA,MAAK,OAAO,GAAA,CAAA,C;;;;;OAqCZ,QAAA,MAAQ,UAAM,CAAK,MAAA,MAAM,MAAM,UAAxCT,UAAA,GAAAC,mBAEI,KAFJ,aAEIQ,gBADC,KAAA,MAAK,SAAS,GAAA,CAAA,K"}
|
|
1
|
+
{"version":3,"file":"board-block.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_normalizeClass","_normalizeStyle","_createBlock","_unref","_mergeProps","_createCommentVNode","_createElementVNode","_toDisplayString","_withCtx","_createVNode","_createTextVNode","_withModifiers","_resolveDynamicComponent","_Fragment","_renderList"],"sources":["../../src/flow/board-block.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n defaultNode,\n defineNodeType,\n DouFlowControls,\n DouFlowEditor,\n defineFlowExtension,\n type NodeTypeSpec,\n type FlowDocument,\n type FlowExtension,\n type FlowHistoryHandler,\n type FlowNode,\n type FlowTransaction,\n} from '@dou-ui/flow'\nimport type { CommentAction, CommentThread } from 'dou-ui'\nimport { EyeIcon, PencilIcon, PlusIcon, SquareIcon } from '@dou-ui/icons'\nimport { DouButton, DouCommand, DouDialog, DouPopover, type CommandItem } from 'dou-ui'\nimport { NodeSelection } from 'prosemirror-state'\nimport {\n computed,\n nextTick,\n onBeforeUnmount,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\nimport { findBlockById } from '../core/blocks'\nimport { historyCommands } from '../core/editor'\nimport { labelOf } from '../core/extension'\nimport type { BlockProps } from '../core/model'\nimport { joinStepKey, ownStepKey } from '../core/transaction'\nimport { useEditor } from '../editor'\nimport {\n BOARD_HEIGHT,\n BOARD_OPEN_EVENT,\n boardComments,\n boardOf,\n clampHeight,\n onlyBoardChanged,\n type BoardBlockSettings,\n} from './board'\n\n/** The board with the groups this reader folded or unfolded. */\nfunction withFolded(board: FlowDocument, folded: Map<string, boolean>): FlowDocument {\n if (!folded.size) return board\n const nodes = board.nodes.map((node) => {\n if (!folded.has(node.id)) return node\n const { collapsed: _, ...data } = node.data ?? {}\n return { ...node, data: folded.get(node.id) ? { ...data, collapsed: true } : data }\n })\n return { ...board, nodes }\n}\n\nconst props = defineProps<{\n block: { id: string; type: string; props: BlockProps }\n updateProps: (props: BlockProps) => void\n selected: boolean\n editable: boolean\n settings: BoardBlockSettings\n}>()\n\nconst { view, messages, comments } = useEditor()\nconst text = computed(() => messages.value.board)\nconst label = computed(() => labelOf(props.settings.label, messages.value))\nconst stored = computed(() => boardOf(props.block.props.board))\n/*\n * Whether a group is folded is each reader's own view, as with toggles: it\n * stays out of the document (what it holds there is kept), and is shown\n * from here.\n */\nconst folded = shallowRef(new Map<string, boolean>())\nconst board = computed(() => withFolded(stored.value, folded.value))\nconst empty = computed(() => !board.value.nodes.length)\n\n/* the fullscreen editor */\nconst open = shallowRef(false)\n/** The fullscreen editor is in place (its dialog done opening). */\nconst opened = shallowRef(false)\nwatch(open, (value) => {\n if (!value) shown.value = board.value\n})\n\n/*\n * Comment threads on the nodes and edges: the document's threads, author\n * and open thread, shown by the flow editors. The ids are kept on the nodes\n * and edges (see `boardComments`); a thread opened from outside, e.g. a\n * list of the document's comments, opens the fullscreen editor at it.\n */\nconst flowComments = computed(() =>\n props.settings.commentable && comments.enabled.value\n ? (comments.threads.value as CommentThread[])\n : undefined,\n)\nconst threadsHere = computed(\n () =>\n new Set(\n props.settings.commentable ? Object.keys(boardComments.anchors(props.block.props)) : [],\n ),\n)\nconst here = (id: string | null): id is string => !!id && threadsHere.value.has(id)\n/** The open thread, when it is on this board and the fullscreen editor shows it. */\nconst boardActive = computed(() =>\n opened.value && here(comments.active.value) ? comments.active.value : null,\n)\nwatch(\n () => comments.active.value,\n (id) => {\n if (here(id) && !open.value) openEditor()\n },\n)\n/*\n * The preview can't be pressed (it is inert and lets the pointer through to\n * the block), but its comment markers look like buttons: a click or tap on\n * one opens the board at its thread.\n */\nconst markerCursor = shallowRef(false)\nfunction markerAt(event: MouseEvent): string | null {\n if (!flowComments.value) return null\n const markers = root.value?.querySelectorAll<HTMLElement>(\n '.dou-editor-board__preview [data-thread]',\n )\n for (const marker of markers ?? []) {\n const box = marker.getBoundingClientRect()\n if (\n event.clientX >= box.left &&\n event.clientX <= box.right &&\n event.clientY >= box.top &&\n event.clientY <= box.bottom\n )\n return marker.dataset.thread ?? null\n }\n return null\n}\nfunction onPreviewClick(event: MouseEvent) {\n const id = markerAt(event)\n if (id) comments.open(id)\n}\nfunction onPreviewMove(event: PointerEvent) {\n if (event.pointerType === 'mouse') markerCursor.value = !!markerAt(event)\n}\n\nfunction onActive(id: string | null) {\n if (id !== boardActive.value) comments.open(id)\n}\nfunction onCommentAction(action: CommentAction) {\n comments.apply(action, { anchored: true })\n}\nfunction onClose() {\n settle()\n opened.value = false\n if (here(comments.active.value)) comments.open(null)\n}\n\nconst root = useTemplateRef<HTMLElement>('root')\nconst canvas = useTemplateRef<HTMLElement>('canvas')\nconst preview = useTemplateRef<InstanceType<typeof DouFlowEditor>>('preview')\n\n/* the height, followed live while the bar is dragged */\nconst dragged = shallowRef<number | null>(null)\nconst height = computed(\n () => dragged.value ?? clampHeight(Number(props.block.props.height) || props.settings.height),\n)\n\n/* the preview is drawn once the block comes near the screen */\nconst seen = shallowRef(typeof IntersectionObserver === 'undefined')\nlet observer: IntersectionObserver | null = null\nlet resized: ResizeObserver | null = null\nlet frame = 0\n/** Fits the preview to its box again, once the nodes have been laid out. */\nfunction refit() {\n cancelAnimationFrame(frame)\n frame = requestAnimationFrame(() => preview.value?.fit())\n}\nonMounted(() => {\n const element = root.value!\n element.addEventListener(BOARD_OPEN_EVENT, openEditor)\n if (!seen.value) {\n observer = new IntersectionObserver(\n (entries) => {\n if (!entries.some((entry) => entry.isIntersecting)) return\n seen.value = true\n observer?.disconnect()\n observer = null\n },\n { rootMargin: '200px' },\n )\n observer.observe(element)\n }\n if (typeof ResizeObserver !== 'undefined') {\n let width = element.clientWidth\n resized = new ResizeObserver(() => {\n if (element.clientWidth === width) return\n width = element.clientWidth\n refit()\n })\n resized.observe(element)\n }\n})\nonBeforeUnmount(() => {\n settle()\n root.value?.removeEventListener(BOARD_OPEN_EVENT, openEditor)\n observer?.disconnect()\n resized?.disconnect()\n cancelAnimationFrame(frame)\n})\n/* what the preview shows: held while the fullscreen editor covers it, so it isn't redrawn each frame */\nconst shown = shallowRef(board.value)\nwatch(board, (value) => {\n if (!open.value) shown.value = value\n})\nwatch(shown, () => void nextTick(refit))\nwatch(height, () => void nextTick(refit))\n\nfunction openEditor() {\n if (!props.editable && empty.value) return\n steps.undo = 0\n steps.redo = 0\n pending = null\n open.value = true\n}\n\nconst contentPos = () => {\n const state = view.value?.state\n return state ? (findBlockById(state.doc, props.block.id)?.contentPos ?? null) : null\n}\n\n/** The keys go to the canvas from the start: a tool's letter, `Esc` letting go of a selection. */\nfunction onOpened() {\n opened.value = true\n canvas.value?.querySelector<HTMLElement>('.dou-flow-editor')?.focus({ preventScroll: true })\n}\n\n/** Back in the document: the block selected, the editor focused. */\nfunction onClosed() {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n if (props.editable)\n editor.dispatch(editor.state.tr.setSelection(NodeSelection.create(editor.state.doc, pos)))\n editor.focus()\n}\n\n/*\n * Changes on the board go into the document as they are made, so `v-model`,\n * collaboration and the other blocks see them, and into the editor's undo\n * history: undo in the fullscreen editor is the document's, one step per\n * change on the board. The frames of a drag (or nudges with the arrow keys,\n * or typing in one node) join the step of the first one; only the fields\n * they change are written, so what others change meanwhile stays theirs. A\n * cancelled drag takes its step back.\n */\nconst GROUP_WINDOW = 1000\n/** A drag going on: its group, and when its last frame came. */\nlet pending: { group: string; time: number } | null = null\n/** The steps taken on the board since it was opened, and those undone. */\nconst steps = { undo: 0, redo: 0 }\n\n/** The board as the document keeps it: groups folded as they are there; and what this reader folded. */\nfunction toDocument(next: FlowDocument): FlowDocument {\n const before = new Map(stored.value.nodes.map((node) => [node.id, node]))\n let changed: Map<string, boolean> | null = null\n const nodes = next.nodes.map((node) => {\n const mine = !!node.data?.collapsed\n const theirs = before.get(node.id)?.data?.collapsed\n if (mine === !!theirs) {\n if (folded.value.has(node.id)) (changed ??= new Map(folded.value)).delete(node.id)\n return node\n }\n if (folded.value.get(node.id) !== mine) (changed ??= new Map(folded.value)).set(node.id, mine)\n const { collapsed: _, ...data } = node.data ?? {}\n if (theirs !== undefined) return { ...node, data: { ...data, collapsed: theirs } }\n // a node with no data before has none after\n if (Object.keys(data).length || before.get(node.id)?.data) return { ...node, data }\n const { data: __, ...rest } = node\n return rest as FlowNode\n })\n if (changed) folded.value = changed\n warnDataImages(next, before)\n return { ...next, nodes }\n}\n\nlet warned = false\n/** Pictures kept in the document as data URLs make it large: say so once, while developing. */\nfunction warnDataImages(next: FlowDocument, before: Map<string, FlowNode>) {\n if (warned || process.env.NODE_ENV === 'production') return\n const added = next.nodes.find(\n (node) =>\n typeof node.data?.src === 'string' &&\n node.data.src.startsWith('data:') &&\n before.get(node.id)?.data?.src !== node.data.src,\n )\n if (!added) return\n warned = true\n console.warn(\n `[@dou-ui/editor] a picture on the \"${props.block.type}\" block is kept in the document as a data URL; pass \\`upload\\` to whiteboardBlock() to keep only its address`,\n )\n}\n\nconst currentBoard = () => {\n const pos = contentPos()\n return pos === null ? null : (view.value?.state.doc.nodeAt(pos)?.attrs.board ?? null)\n}\n\n/** Writes the board as one undo step of its own. */\nfunction record(next: unknown) {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n editor.dispatch(editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta(ownStepKey, true))\n steps.undo++\n steps.redo = 0\n}\n\n/** Writes the board into the undo step before, the drag's. */\nfunction join(next: unknown) {\n const editor = view.value\n const pos = contentPos()\n if (!editor || pos === null) return\n const tr = editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta(joinStepKey, true)\n // for the built-in history: part of the step before, however long after\n editor.dispatch(tr.setMeta('appendedTransaction', editor.state.tr))\n}\n\n/** Ends the drag going on: the next change is a step of its own. */\nfunction settle() {\n pending = null\n}\n\nfunction forward(tr: FlowTransaction) {\n const editor = view.value\n const pos = contentPos()\n // a thread put on or taken off a node is written in a read-only document too, as on text\n const comment = tr.meta.origin === 'comment'\n if (!editor || pos === null || (!props.editable && !comment)) return\n const group = tr.meta.group\n const next = toDocument(tr.doc)\n // only folded or unfolded: nothing for the document\n if (JSON.stringify(next) === JSON.stringify(currentBoard())) return\n // not a step of the undo history, nor part of a drag going on\n if (comment) {\n editor.dispatch(\n editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta('addToHistory', false),\n )\n return\n }\n const now = Date.now()\n if (pending && (pending.group !== group || now - pending.time >= GROUP_WINDOW)) {\n // a cancelled drag putting the board back: part of its step\n if (tr.meta.history === false) return join(next)\n settle()\n }\n if (tr.meta.history === false) {\n editor.dispatch(\n editor.state.tr.setNodeAttribute(pos, 'board', next).setMeta('addToHistory', false),\n )\n return\n }\n if (!group) return record(next)\n if (pending) {\n pending.time = now\n return join(next)\n }\n pending = { group, time: now }\n record(next)\n}\n\n/** Undo or redo in the document; refused when it would change something besides this board. */\nfunction travel(kind: 'undo' | 'redo') {\n settle()\n const editor = view.value\n if (!editor || !steps[kind]) return false\n const before = editor.state.doc\n const commands = historyCommands(editor.state)\n if (!commands[kind](editor.state, editor.dispatch, editor)) return false\n if (!onlyBoardChanged(before, editor.state.doc, props.block.id)) {\n // the board's own steps are used up: put back what was taken\n historyCommands(editor.state)[kind === 'undo' ? 'redo' : 'undo'](\n editor.state,\n editor.dispatch,\n editor,\n )\n steps[kind] = 0\n return false\n }\n steps[kind]--\n steps[kind === 'undo' ? 'redo' : 'undo']++\n return true\n}\n\n/** A cancelled drag: the board is back where it started, and its step is taken back. */\nfunction drop(group: string) {\n if (pending?.group !== group) return\n pending = null\n const editor = view.value\n if (!editor || !steps.undo) return\n if (historyCommands(editor.state).undo(editor.state, editor.dispatch, editor)) steps.undo--\n}\n\nconst history: FlowHistoryHandler = {\n undo: () => travel('undo'),\n redo: () => travel('redo'),\n canUndo: () => steps.undo > 0,\n canRedo: () => steps.redo > 0 && !pending,\n drop,\n close: settle,\n}\nconst bridge: FlowExtension = defineFlowExtension({\n name: 'editor-board-history',\n history: () => history,\n})\nconst extensions = [...props.settings.extensions, bridge]\n\n/*\n * Adding nodes: the types the extensions offer (`palette`), from a button\n * at the top left. When none is offered (`flowKit()` alone), a node of its\n * own with an input and an output, so what is added can be connected right\n * away.\n */\nconst offered = [\n ...props.settings.extensions.flat(),\n { nodeTypes: props.settings.editorProps.nodeTypes ?? [] },\n].some((extension) => extension.nodeTypes?.some((spec) => spec.palette))\nconst nodeTypes = computed(() => {\n const given = (props.settings.editorProps.nodeTypes ?? []) as NodeTypeSpec[]\n if (offered || !props.settings.fallbackNode) return given\n const name = text.value.node\n const step = defineNodeType({\n ...defaultNode,\n defaults: () => ({ label: name, inputs: [{ id: 'in' }], outputs: [{ id: 'out' }] }),\n palette: { label: name, icon: SquareIcon },\n }) as unknown as NodeTypeSpec\n return [step, ...given]\n})\nconst full = useTemplateRef<InstanceType<typeof DouFlowEditor>>('full')\nconst palette = computed(() => (props.editable ? (full.value?.paletteTypes ?? []) : []))\n/* several types: the same searchable list as when an edge is dropped on the canvas */\nconst adding = shallowRef(false)\nconst query = shallowRef('')\nconst addTrigger = useTemplateRef<InstanceType<typeof DouButton>>('addTrigger')\nconst command = useTemplateRef<InstanceType<typeof DouCommand>>('command')\nconst items = computed<CommandItem[]>(() =>\n palette.value.map((spec) => ({\n value: spec.type,\n label: spec.palette!.label,\n group: spec.palette!.group,\n description: spec.palette!.description,\n keywords: spec.palette!.keywords,\n icon: spec.palette!.icon,\n })),\n)\nwatch(adding, (value) => {\n if (!value) return\n query.value = ''\n // a phone's keyboard would cover the list: search only with a mouse\n if (!matchMedia('(pointer: coarse)').matches) void nextTick(() => command.value?.focus())\n})\n\nfunction addNode(type: string) {\n adding.value = false\n full.value?.insertNode(type)\n}\nfunction dragNode(type: string, event: PointerEvent) {\n if (event.button !== 0) return\n full.value?.startInsertDrag(type, event)\n // the list goes once the node is dropped, or the drag ends otherwise\n window.addEventListener(\n 'pointerup',\n () => {\n if (!adding.value) return\n adding.value = false\n // a drag let go of (or cancelled) off the canvas: back to the button\n void nextTick(() => {\n // the list may not be hidden yet: focus still in its search field\n const active = document.activeElement\n const list = command.value?.$el as HTMLElement | undefined\n if (!active || active === document.body || list?.contains(active))\n (addTrigger.value?.$el as HTMLElement | undefined)?.focus({ preventScroll: true })\n })\n },\n { once: true },\n )\n}\n\n/** A label cut into the letters the search matched and the rest. */\nfunction parts(name: string, indices: number[]) {\n const hit = new Set(indices)\n const out: { text: string; match: boolean }[] = []\n for (let i = 0; i < name.length; i++) {\n const match = hit.has(i)\n const last = out[out.length - 1]\n if (last && last.match === match) last.text += name[i]\n else out.push({ text: name[i]!, match })\n }\n return out\n}\n\n/* changing the height: drag the bar under the block, or the arrow keys on it */\nfunction onResizeStart(event: PointerEvent) {\n if (event.button !== 0) return\n event.preventDefault()\n const bar = event.currentTarget as HTMLElement\n bar.setPointerCapture(event.pointerId)\n const startY = event.clientY\n const start = height.value\n const move = (e: PointerEvent) => (dragged.value = clampHeight(start + e.clientY - startY))\n const finish = (commit: boolean) => {\n bar.removeEventListener('pointermove', move)\n bar.removeEventListener('pointerup', up)\n bar.removeEventListener('pointercancel', cancel)\n window.removeEventListener('keydown', escape, true)\n const value = dragged.value\n dragged.value = null\n if (commit && value !== null && value !== start) props.updateProps({ height: value })\n }\n const up = () => finish(true)\n const cancel = () => finish(false)\n const escape = (e: KeyboardEvent) => {\n if (e.key !== 'Escape') return\n e.preventDefault()\n e.stopPropagation()\n finish(false)\n }\n bar.addEventListener('pointermove', move)\n bar.addEventListener('pointerup', up)\n bar.addEventListener('pointercancel', cancel)\n window.addEventListener('keydown', escape, true)\n}\n\nfunction onResizeKey(event: KeyboardEvent) {\n const by = { ArrowUp: -BOARD_HEIGHT.step, ArrowDown: BOARD_HEIGHT.step }[event.key]\n if (by) {\n event.preventDefault()\n props.updateProps({ height: clampHeight(height.value + by) })\n } else if (event.key === 'Escape') {\n event.preventDefault()\n onClosed()\n }\n}\n\nfunction resetHeight() {\n props.updateProps({ height: props.settings.height })\n}\n</script>\n\n<template>\n <div\n ref=\"root\"\n class=\"dou-editor-board\"\n :class=\"{ 'is-selected': selected, 'is-empty': empty }\"\n :style=\"{ height: `${height}px`, cursor: markerCursor ? 'pointer' : undefined }\"\n @dblclick=\"openEditor\"\n @click=\"onPreviewClick\"\n @pointermove=\"onPreviewMove\"\n @pointerleave=\"markerCursor = false\"\n >\n <div v-if=\"!empty\" class=\"dou-editor-board__preview\" role=\"img\" :aria-label=\"label\">\n <DouFlowEditor\n class=\"dou-editor-board__canvas\"\n inert\n v-if=\"seen\"\n ref=\"preview\"\n :model-value=\"shown\"\n v-bind=\"settings.editorProps\"\n :extensions=\"settings.extensions\"\n :node-types=\"nodeTypes\"\n readonly\n fit-view\n :fit-min-zoom=\"0.05\"\n :simple-zoom=\"0\"\n :min-zoom=\"0.05\"\n :max-zoom=\"1\"\n :bordered=\"false\"\n :searchable=\"false\"\n :comments=\"flowComments\"\n :commentable=\"false\"\n :pan-on-scroll=\"false\"\n />\n </div>\n <div v-else class=\"dou-editor-board__empty\">\n <span class=\"dou-editor-board__empty-text\">{{ text.empty }}</span>\n <DouButton v-if=\"editable\" size=\"sm\" variant=\"outline\" @click=\"openEditor\">\n <template #leading><PencilIcon /></template>\n {{ text.start }}\n </DouButton>\n </div>\n\n <div v-if=\"!empty\" class=\"dou-editor-board__actions\">\n <DouButton size=\"sm\" variant=\"outline\" class=\"dou-editor-board__open\" @click=\"openEditor\">\n <template #leading><PencilIcon v-if=\"editable\" /><EyeIcon v-else /></template>\n {{ editable ? text.edit : text.view }}\n </DouButton>\n </div>\n\n <div\n v-if=\"editable\"\n class=\"dou-editor-board__resize\"\n role=\"separator\"\n aria-orientation=\"horizontal\"\n tabindex=\"0\"\n :aria-label=\"text.resize\"\n :aria-valuemin=\"BOARD_HEIGHT.min\"\n :aria-valuemax=\"BOARD_HEIGHT.max\"\n :aria-valuenow=\"height\"\n data-editor-control\n @pointerdown=\"onResizeStart\"\n @keydown=\"onResizeKey\"\n @dblclick.stop=\"resetHeight\"\n />\n\n <DouDialog\n v-model:open=\"open\"\n :title=\"label\"\n fullscreen\n destroy-on-close\n @opened=\"onOpened\"\n @close=\"onClose\"\n @closed=\"onClosed\"\n >\n <div ref=\"canvas\" class=\"dou-editor-board__editor\" data-editor-control>\n <DouFlowEditor\n ref=\"full\"\n :model-value=\"board\"\n v-bind=\"settings.editorProps\"\n :extensions=\"extensions\"\n :node-types=\"nodeTypes\"\n :readonly=\"!editable\"\n fit-view\n :fit-min-zoom=\"0.1\"\n :simple-zoom=\"0.1\"\n :comments=\"flowComments\"\n :author=\"comments.author.value\"\n :commentable=\"comments.writable.value\"\n :active-comment=\"boardActive\"\n :aria-label=\"label\"\n @transaction=\"forward\"\n @update:active-comment=\"onActive\"\n @comment-action=\"onCommentAction\"\n >\n <DouFlowControls />\n <div v-if=\"palette.length\" class=\"dou-editor-board__add\">\n <DouButton\n v-if=\"palette.length === 1\"\n size=\"sm\"\n variant=\"outline\"\n @pointerdown=\"dragNode(palette[0]!.type, $event)\"\n @click=\"addNode(palette[0]!.type)\"\n >\n <template #leading><PlusIcon /></template>\n {{ text.addNode }}\n </DouButton>\n <DouPopover v-else v-model:open=\"adding\" placement=\"bottom-start\">\n <DouButton ref=\"addTrigger\" size=\"sm\" variant=\"outline\">\n <template #leading><PlusIcon /></template>\n {{ text.addNode }}\n </DouButton>\n <template #content>\n <DouCommand\n ref=\"command\"\n v-model:query=\"query\"\n class=\"dou-editor-board__types\"\n :items=\"items\"\n :placeholder=\"text.searchNodes\"\n :aria-label=\"text.addNode\"\n :empty-text=\"text.noNodes\"\n :max-height=\"280\"\n @select=\"addNode(String($event.value))\"\n >\n <template #item=\"{ item, indices }\">\n <span\n class=\"dou-editor-board__type\"\n @pointerdown=\"dragNode(String(item.value), $event)\"\n >\n <span class=\"dou-editor-board__type-icon\">\n <component :is=\"item.icon\" v-if=\"item.icon\" />\n </span>\n <span class=\"dou-command__label\">\n <template v-for=\"(part, at) in parts(item.label, indices)\" :key=\"at\">\n <mark v-if=\"part.match\" class=\"dou-command__match\">{{ part.text }}</mark>\n <template v-else>{{ part.text }}</template>\n </template>\n </span>\n <span v-if=\"item.description\" class=\"dou-command__description\">\n {{ item.description }}\n </span>\n </span>\n </template>\n </DouCommand>\n </template>\n </DouPopover>\n </div>\n <p v-if=\"palette.length && !board.nodes.length\" class=\"dou-editor-board__hint\">\n {{ text.emptyFlow }}\n </p>\n </DouFlowEditor>\n </div>\n </DouDialog>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4PA,IAAM,eAAe;;;;;;;;;;;;EAhNrB,SAAS,WAAW,OAAqB,QAA4C;GACnF,IAAI,CAAC,OAAO,MAAM,OAAO;GACzB,MAAM,QAAQ,MAAM,MAAM,KAAK,SAAS;IACtC,IAAI,CAAC,OAAO,IAAI,KAAK,EAAE,GAAG,OAAO;IACjC,MAAM,EAAE,WAAW,GAAG,GAAG,SAAS,KAAK,QAAQ,CAAC;IAChD,OAAO;KAAE,GAAG;KAAM,MAAM,OAAO,IAAI,KAAK,EAAE,IAAI;MAAE,GAAG;MAAM,WAAW;KAAK,IAAI;IAAK;GACpF,CAAC;GACD,OAAO;IAAE,GAAG;IAAO;GAAM;EAC3B;EAEA,MAAM,QAAQ;EAQd,MAAM,EAAE,MAAM,UAAU,aAAa,UAAU;EAC/C,MAAM,OAAO,eAAe,SAAS,MAAM,KAAK;EAChD,MAAM,QAAQ,eAAe,QAAQ,MAAM,SAAS,OAAO,SAAS,KAAK,CAAC;EAC1E,MAAM,SAAS,eAAe,QAAQ,MAAM,MAAM,MAAM,KAAK,CAAC;E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