@ecsplico/editor 4.0.0 → 4.2.0
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/CHANGELOG.md +18 -0
- package/dist/code/CodeSurface.vue.d.ts +3 -3
- package/dist/document/DocumentSurface.vue.d.ts +3 -3
- package/dist/features/image-studio/components/ImageStudioDialog.js +149 -86
- package/dist/features/image-studio/components/ImageStudioDialog.js.map +1 -1
- package/dist/features/image-studio/components/ImageStudioDialog.vue.d.ts +4 -0
- package/dist/features/image-studio/components/ImageStudioLibraryPanel.js +186 -0
- package/dist/features/image-studio/components/ImageStudioLibraryPanel.js.map +1 -0
- package/dist/features/image-studio/components/ImageStudioLibraryTile.js +134 -0
- package/dist/features/image-studio/components/ImageStudioLibraryTile.js.map +1 -0
- package/dist/features/image-studio/index.d.ts +3 -2
- package/dist/features/image-studio/index.js +2 -2
- package/dist/features/image-studio/library.d.ts +35 -0
- package/dist/features/image-studio/react/ImageStudioDialog.js +45 -4
- package/dist/features/image-studio/react/ImageStudioDialog.js.map +1 -1
- package/dist/features/image-studio/react/ImageStudioLibraryPanel.js +141 -0
- package/dist/features/image-studio/react/ImageStudioLibraryPanel.js.map +1 -0
- package/dist/features/image-studio/react/ImageStudioLibraryTile.js +105 -0
- package/dist/features/image-studio/react/ImageStudioLibraryTile.js.map +1 -0
- package/dist/features/image-studio/react/store.d.ts +5 -0
- package/dist/features/image-studio/react/store.js.map +1 -1
- package/dist/features/image-studio/react.d.ts +3 -2
- package/dist/features/image-studio/react.js +2 -2
- package/dist/features/image-studio/react.js.map +1 -1
- package/dist/features/image-studio/state.d.ts +5 -0
- package/dist/features/image-studio/state.js +9 -1
- package/dist/features/image-studio/state.js.map +1 -1
- package/dist/features/image-studio/store.d.ts +5 -0
- package/dist/features/image-studio/vue.d.ts +3 -2
- package/dist/features/image-studio/vue.js +2 -2
- package/dist/features/image-studio/vue.js.map +1 -1
- package/dist/features/media/index.js +1 -1
- package/dist/features/media/react/AudioRecorderModal.js +1 -1
- package/dist/features/media/react.js +1 -1
- package/dist/i18n/de/image-studio.js +9 -0
- package/dist/i18n/de/image-studio.js.map +1 -1
- package/dist/i18n/de.d.ts +9 -0
- package/dist/i18n/en/image-studio.js +9 -0
- package/dist/i18n/en/image-studio.js.map +1 -1
- package/dist/integrations/composite-ai/transfer-transforms.js +1 -1
- package/dist/markdown/MarkdownSurface.vue.d.ts +5 -5
- package/dist/nuxt/module.d.ts +18 -0
- package/dist/presets/compose.js +1 -1
- package/dist/react/compose.js +1 -1
- package/dist/tree/react/use-tree-view.d.ts +3 -1
- package/dist/tree/react/use-tree-view.js +3 -1
- package/dist/tree/react/use-tree-view.js.map +1 -1
- package/dist/tree/tree-host.js +1 -1
- package/dist/tree/tree-model.js +12 -10
- package/dist/tree/tree-model.js.map +1 -1
- package/dist/tree/tree-view-model.d.ts +5 -0
- package/dist/tree/tree-view-model.js +1 -0
- package/dist/tree/tree-view-model.js.map +1 -1
- package/dist/tree/tree-view.d.ts +4 -2
- package/dist/tree/tree-view.js +4 -2
- package/dist/tree/tree-view.js.map +1 -1
- package/dist/vue/AdvancedEditor.vue.d.ts +4 -4
- package/dist/vue/SimpleEditor.vue.d.ts +4 -4
- package/dist/vue/components/EditorSurface.vue.d.ts +4 -4
- package/dist/vue/compose.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-model.js","names":[],"sources":["../../src/tree/tree-model.ts"],"sourcesContent":["import type { BlockTransfer } from '../core/block-transfer'\nimport { createStore, type ReadonlyStore } from '../core/store'\nimport { acceptsChild, type Basket, basketById, type BlockType } from '../features/composites'\nimport type { Translate } from '../i18n'\nimport { type DropEnv, dropVerdict, type DropVerdict } from './drop-rules'\nimport { remapFolderPath } from './folder-paths'\nimport type { DocumentStore } from './store'\nimport {\n ancestorKeys,\n collectFolderPaths,\n creatableBelow,\n type DragPayload,\n dragPayloadOf,\n EMPTY_OUTLINE,\n filterKinds,\n folderNamesIn,\n isDraggable,\n joinPath,\n type Outline,\n parentPath,\n type TreeItem,\n VIRTUAL_ROOT,\n} from './tree-items'\nimport { deriveTree, filterQuery, type TreeRow, type TreeView } from './tree-rows'\nimport type { NodeFilters, TreeViewModel } from './tree-view-model'\nimport type { DocumentSummary, TreeFolder } from './types'\n\n// One framework-free model per `DocumentTree`, rendered by the Vue and the React component alike. It owns what the\n// tree remembers (open rows, kind filters, the title filter, the selection, a drag, a folder being renamed or created)\n// and checks all of it against the tree after every change of the store, the outline or the view state, so a key of\n// something that moved or vanished never lingers. It never calls the store or the editor to change something: it emits\n// `TreeCommand`s to the `execute` it was given and follows their result.\n\n/** What the model asks its host to do; the host reports whether it happened. */\nexport type TreeCommand\n = | { type: 'openDocument', id: string }\n | { type: 'createDocument', folder: string }\n | { type: 'moveDocument', id: string, folder: string }\n | { type: 'removeDocument', id: string, folder: string }\n | { type: 'createFolder', path: string }\n | { type: 'moveFolder', from: string, to: string }\n | { type: 'removeFolder', path: string }\n /** Moves the block into the Typed block `targetId` (`null` = the end of the document). */\n | { type: 'moveBlock', id: string, targetId: string | null }\n | { type: 'revealBlock', id: string | null, pos: number }\n /** Adds an Folder block to the Typed block `targetId` (`null` = the end of the document). */\n | { type: 'createFolderBlock', targetId: string | null }\n /** Lets the user pick files and imports them into the Typed block `targetId` (`null` = the end of the document); `false` when none were imported. */\n | { type: 'importFiles', targetId: string | null }\n | { type: 'warn', title: string, description: string }\n /** Inserts a Typed block dragged in from another surface or tree at the end of the Typed block `targetId` (`null` = the end of the document); `menu`: offer the transforms at `x`, `y` first. */\n | { type: 'transferBlock', payload: BlockTransfer, targetId: string | null, menu: boolean, x: number, y: number }\n /** Puts the editor into focus mode on the Typed block `id` (`null` = leaves focus mode); sent after the tree's own focus changed. */\n | { type: 'focusBlock', id: string | null }\n /** The Typed block `id` absorbs the Typed block that follows it (`mergeCompositeWithNext`); `false` when the editor refuses. */\n | { type: 'mergeBlock', id: string }\n\n/** Runs a command and resolves whether it happened. Never rejects: the host reports its own failures. */\nexport type TreeExecutor = (command: TreeCommand) => boolean | Promise<boolean>\n\n/** What the model needs from the open document's editor. */\nexport interface TreeEditor {\n kinds: readonly BlockType[]\n /** The baskets a Typed block can be put into (colour dots on the rows). */\n baskets: readonly Basket[]\n /** The outline in `structure`: Typed blocks in `'structured'` structure, else the headings. Empty once the editor is gone. */\n outline: (structure: string) => Outline\n /** Whether a block may move into a Typed block, judged on the live document. */\n moveVerdict: NonNullable<DropEnv['moveVerdict']>\n /** Whether the editor takes blocks from outside: it has the transfer feature's drop target and its `transferBlock` command. */\n canTransfer: () => boolean\n /** The block id of the Typed block the editor is focused on (focus mode), `null` without focus. The model mirrors it into the tree. */\n focusedId: () => string | null\n /** Whether the Typed block `id` can absorb the Typed block that follows it, judged on the live document. */\n canMerge: (id: string) => boolean\n /** `listener` runs after the document or the editor's focus changed; returns the unsubscribe function. */\n onChange: (listener: () => void) => () => void\n}\n\n/** What the surrounding app decides: the open editor and the `blocks.structure` / `blocks.treeRoot` settings. */\nexport interface TreeContext {\n editor: TreeEditor | undefined\n structure: string\n treeRoot: string\n}\n\nexport interface TreeModelOptions {\n /** Words the menus, the drop refusals and the label of an untitled open document; the framework layer passes the context's `t`. */\n t: Translate\n store: DocumentStore\n /** The view state shared by the trees of one app: open store items and kind filters (persisted). */\n view: TreeViewModel\n execute: TreeExecutor\n context: TreeContext\n /** The folder new documents and folders go to; default the root. */\n selectedFolder?: string\n /** How long the outline waits for the document to settle before it is read again; default 150 ms. */\n outlineDebounceMs?: number\n}\n\n/** A drag in progress. */\nexport interface TreeDrag {\n source: DragPayload\n /** Key of the dragged row (`''` for a `foreign-block`, which has no row here) */\n sourceKey: string\n /** Key of the row under the pointer */\n hover: string | null\n /** What dropping on `hover` would do; `null` without a `hover` */\n verdict: DropVerdict | null\n}\n\n/** A folder being renamed. */\nexport interface TreeRename {\n /** Key of the folder's row */\n key: string\n path: string\n /** Its name when renaming started */\n base: string\n draft: string\n error: string | null\n}\n\n/** A folder being named. */\nexport interface TreeCreateFolder {\n /** Folder path the folder is created in */\n parent: string\n draft: string\n error: string | null\n}\n\n/** Everything a renderer needs. Fields below `view` are what the derived `view` was computed from and what `rowOf` reads. */\nexport interface TreeState {\n /** The loaded folder tree: `undefined` = not loaded yet, `null` = loading failed. */\n tree: TreeFolder | null | undefined\n documents: readonly DocumentSummary[]\n activeId: string | undefined\n /** The open document is the root (virtual mode) instead of the store's folders. */\n virtual: boolean\n structure: string\n kinds: readonly BlockType[]\n /** The open editor's baskets (colours of the row dots). */\n baskets: readonly Basket[]\n hasEditor: boolean\n outline: Outline\n nodeFilters: NodeFilters\n /** The basket ids the tree shows (`[]` = all). */\n basketFilter: readonly string[]\n /** Key of the focused row: the tree lists only its children. `null` = no focus. */\n focusKey: string | null\n expanded: readonly string[]\n collapsedOutline: readonly string[]\n /** What the title filter input holds. */\n filterText: string\n filterOverrides: Readonly<Record<string, boolean>>\n /** The folder new documents, folders and host imports go to. */\n selectedFolder: string\n /** Virtual mode: block ID of the selected Typed block that takes Typed blocks; `null` = the document itself. */\n virtualTarget: string | null\n drag: TreeDrag | null\n renaming: TreeRename | null\n creatingFolder: TreeCreateFolder | null\n /** Key of the row whose deletion is running. */\n removing: string | null\n view: TreeView\n /** The unfiltered items from the top down to the focused one (the breadcrumb); empty without a focus. Derived with `view`. */\n focusPath: readonly TreeItem[]\n}\n\n/** One row of a row's menu. */\nexport interface TreeMenuEntry {\n label: string\n icon: string\n run: () => void\n}\n\n/** How a renderer draws one row. */\nexport interface TreeRowState extends TreeRow {\n /** The row's document is the open one. */\n active: boolean\n /** The row is the selected folder, or (virtual mode) the selected Typed block. */\n selected: boolean\n /** What dropping the drag on this row would do, while the pointer is over it. */\n drop: DropVerdict | null\n renaming: TreeRename | null\n removing: boolean\n /** The kinds the row's kind filter can hide below it, and the ones it hides. */\n filterKinds: readonly BlockType[]\n hiddenKinds: readonly string[]\n /** The row offers a kind filter. */\n showFilter: boolean\n}\n\nexport interface TreeModel {\n readonly state: ReadonlyStore<TreeState>\n /** The open editor or a setting changed. */\n setContext: (context: TreeContext) => void\n /** The host selected another folder (it controls the value). */\n setSelectedFolder: (path: string) => void\n\n // --- what is open, filtered, typed\n /** Opens or closes a row; while the title filter is set the choice is discarded when it is cleared. */\n setOpen: (key: string, open: boolean) => void\n toggle: (key: string) => void\n /** Opens the rows (also during a title filter); closed rows are left alone otherwise. */\n expand: (keys: readonly string[]) => void\n /** Filters the rows by title (case-insensitive substring); `''` clears it and restores the opened rows from before. */\n setFilterText: (text: string) => void\n setKindHidden: (key: string, kind: string, hidden: boolean) => void\n clearFilter: (key: string) => void\n clearAllFilters: () => void\n /** Shows (`shown`) or stops showing the Typed blocks of the basket; no basket shown = no filter. */\n setBasketShown: (id: string, shown: boolean) => void\n clearBasketFilter: () => void\n /** Focuses a Typed block row: the tree lists only its children and the editor hides everything else. */\n focus: (key: string) => void\n /** Leaves focus mode (tree and editor). */\n defocus: () => void\n /** Whether the Typed block row can be merged with the Typed block after it (it has a block ID and the editor accepts the merge). */\n canMerge: (item: TreeItem) => boolean\n /** Merges the Typed block row with the Typed block after it: the row keeps its title, id and meta and takes over the other one's body and nested Typed blocks. */\n merge: (item: TreeItem) => void\n\n // --- rows\n /** A row was chosen (click, Enter). */\n select: (item: TreeItem) => void\n /** `select`, and a folder or the root toggles. */\n activate: (item: TreeItem) => void\n addMenu: (item: TreeItem) => TreeMenuEntry[][]\n remove: (item: TreeItem) => Promise<void>\n\n // --- drag and drop\n isDraggable: (item: TreeItem) => boolean\n /** Starts dragging `item`; returns what the drag carries, `null` when `item` cannot be dragged. */\n dragStart: (item: TreeItem) => DragPayload | null\n /** The pointer is over `item`; returns the verdict (`null` without a drag). Only an `ok` one is a drop target. */\n dragOver: (item: TreeItem) => DropVerdict | null\n /** The pointer left `item` for good (not into one of its parts). */\n dragLeave: (item: TreeItem) => void\n dragEnd: () => void\n drop: (item: TreeItem) => Promise<void>\n /**\n * A Typed block from another surface or tree (`BLOCK_MIME`) is over `item`; returns the verdict, `null` while this\n * tree's own drag is running. Only an `ok` one is a drop target.\n */\n foreignDragOver: (item: TreeItem) => DropVerdict | null\n /** Drops the foreign Typed block `payload` on `item`: inserts a copy at the end of that Typed block (`menu`: offers the transforms at `x`, `y` instead). */\n dropForeign: (item: TreeItem, payload: BlockTransfer, menu: boolean, x: number, y: number) => Promise<void>\n\n // --- renaming and creating folders\n startRename: (item: TreeItem) => void\n setRenameDraft: (text: string) => void\n cancelRename: () => void\n commitRename: () => Promise<void>\n /** The rename field lost focus: commit, or give up with a warning when the name is invalid. */\n blurRename: () => Promise<void>\n startCreateFolder: (parent: string) => void\n setFolderDraft: (text: string) => void\n cancelCreateFolder: () => void\n commitCreateFolder: () => Promise<void>\n\n dispose: () => void\n}\n\nconst NO_DOCUMENTS: readonly DocumentSummary[] = []\nconst NO_KINDS: readonly BlockType[] = []\nconst NO_BASKETS: readonly Basket[] = []\nconst NO_FILTERS: Readonly<Record<string, boolean>> = {}\nconst UNSET = Symbol('unset')\n\nconst isOutlineKey = (key: string) => key.startsWith('outline:')\n\n/** The state `core` holds: everything of `TreeState` but what is derived from the view. */\ntype TreeCore = Omit<TreeState, 'view' | 'focusPath'>\n\nconst withView = (c: TreeCore, view: TreeView): TreeState => ({ ...c, view, focusPath: view.focusPath })\n\nfunction sameVerdict(a: DropVerdict | null, b: DropVerdict | null): boolean {\n if (a === b) return true\n if (!a || !b) return false\n return a.ok ? b.ok : !b.ok && a.reason === b.reason\n}\n\n/** A row's state in `state` (`item` is one of `state.view.items`). */\nexport function rowOf(state: TreeState, item: TreeItem, t: Translate): TreeRowState {\n const hidden = state.nodeFilters[item.key] ?? []\n const kinds = filterKinds(item, { structure: state.structure, activeId: state.activeId, kinds: state.kinds, t })\n const virtualTarget = state.virtual && (item.key === VIRTUAL_ROOT ? state.virtualTarget === null : !!item.blockId && item.blockId === state.virtualTarget)\n return {\n ...state.view.rows.get(item.key)!,\n active: item.id !== undefined && item.id === state.activeId,\n selected: (item.type !== 'document' && item.path === state.selectedFolder) || virtualTarget,\n drop: state.drag?.hover === item.key ? state.drag.verdict : null,\n renaming: state.renaming?.key === item.key ? state.renaming : null,\n removing: state.removing === item.key,\n filterKinds: kinds,\n hiddenKinds: hidden,\n showFilter: kinds.length > 0 && (item.type === 'root' || item.type === 'folder' || !!item.children?.length || hidden.length > 0),\n }\n}\n\n/** A tree model over `options.store`; call `dispose` when its tree goes away. */\nexport function createTreeModel(options: TreeModelOptions): TreeModel {\n const { store, view: shared, execute, t } = options\n const debounceMs = options.outlineDebounceMs ?? 150\n\n let editor = options.context.editor\n let structure = options.context.structure\n let treeRoot = options.context.treeRoot\n let unwatchEditor = editor?.onChange(onEditorChange)\n /** The focus the editor last showed that the tree took over (or already had); a change of the editor's focus is told apart from the tree's own by comparing against it. */\n let seenFocus: string | null = null\n let outlineTimer: ReturnType<typeof setTimeout> | undefined\n /** A folder move the host is running: until it is done, a selected folder at the old path follows to the new one. */\n let pendingMove: { from: string, to: string } | undefined\n let disposed = false\n\n const isVirtual = () => treeRoot === 'file' && structure === 'structured' && !!editor\n\n let core: TreeCore = {\n tree: store.tree.get(),\n documents: store.documents.get() ?? NO_DOCUMENTS,\n activeId: store.activeId.get(),\n virtual: isVirtual(),\n structure,\n kinds: editor?.kinds ?? NO_KINDS,\n baskets: editor?.baskets ?? NO_BASKETS,\n hasEditor: !!editor,\n outline: editor ? editor.outline(structure) : EMPTY_OUTLINE,\n nodeFilters: shared.nodeFilters.get(),\n basketFilter: shared.basketFilter.get(),\n focusKey: null,\n expanded: shared.expanded.get(),\n collapsedOutline: [],\n filterText: '',\n filterOverrides: NO_FILTERS,\n selectedFolder: options.selectedFolder ?? '',\n virtualTarget: null,\n drag: null,\n renaming: null,\n creatingFolder: null,\n removing: null,\n }\n let lastView: { deps: readonly unknown[], view: TreeView } | undefined\n let lastTree: TreeFolder | null | undefined | typeof UNSET = UNSET\n let folderPaths = new Set<string>()\n let lastActiveFolder: string | undefined | typeof UNSET = UNSET\n let lastActiveId: string | undefined | typeof UNSET = UNSET\n\n const dropEnv = (): DropEnv => ({ virtual: core.virtual, moveVerdict: editor?.moveVerdict, canTransfer: editor?.canTransfer() ?? false, t })\n\n function viewOf(c: TreeCore): TreeView {\n const deps = [c.tree, c.documents, c.activeId, c.virtual, c.outline, c.kinds, c.nodeFilters, c.basketFilter, c.baskets, c.focusKey, c.expanded, c.collapsedOutline, c.filterText, c.filterOverrides]\n if (lastView && deps.every((dep, i) => Object.is(dep, lastView!.deps[i]))) return lastView.view\n // A basket the open editor does not offer cannot be unchecked in the filter menu, so it never filters.\n const basketFilter = c.basketFilter.filter(id => basketById(c.baskets, id) !== undefined)\n const view = deriveTree({ ...c, basketFilter, t, select: selectItem })\n lastView = { deps, view }\n return view\n }\n\n const renameError = (draft: string, path: string, base: string, tree: TreeFolder | null | undefined) =>\n draft.trim() === base ? null : store.validateName(draft, folderNamesIn(tree, parentPath(path), path))\n const folderError = (draft: string, parent: string, tree: TreeFolder | null | undefined) =>\n draft.trim() ? store.validateName(draft, folderNamesIn(tree, parent)) : null\n\n /** Measures everything the tree remembers against the current tree: what is gone is dropped, what depends on the tree is recomputed. */\n function reconcile(c: TreeCore, view: TreeView): TreeCore {\n let next = c\n if (c.tree !== lastTree) {\n lastTree = c.tree\n folderPaths = new Set<string>()\n if (c.tree) collectFolderPaths(c.tree, folderPaths)\n if (c.tree && !folderPaths.has(next.selectedFolder)) {\n const followed = pendingMove ? remapFolderPath(next.selectedFolder, pendingMove.from, pendingMove.to) : ''\n next = { ...next, selectedFolder: folderPaths.has(followed) ? followed : '' }\n }\n }\n if (next.virtualTarget !== null && (!next.virtual || !view.keys.has(`outline:${next.virtualTarget}`))) next = { ...next, virtualTarget: null }\n if (next.focusKey !== null && !view.keys.has(next.focusKey)) next = { ...next, focusKey: null }\n if (next.renaming) {\n const r = next.renaming\n if (!view.keys.has(r.key)) next = { ...next, renaming: null }\n else {\n const error = renameError(r.draft, r.path, r.base, next.tree)\n if (error !== r.error) next = { ...next, renaming: { ...r, error } }\n }\n }\n if (next.creatingFolder) {\n const f = next.creatingFolder\n if (next.tree && !folderPaths.has(f.parent)) next = { ...next, creatingFolder: null }\n else {\n const error = folderError(f.draft, f.parent, next.tree)\n if (error !== f.error) next = { ...next, creatingFolder: { ...f, error } }\n }\n }\n if (next.drag) {\n const d = next.drag\n if ((d.source.type !== 'foreign-block' && !view.keys.has(d.sourceKey)) || (d.hover !== null && !view.keys.has(d.hover))) next = { ...next, drag: null }\n else if (d.hover !== null) {\n const target = view.rows.get(d.hover)?.item\n const verdict = target ? dropVerdict(d.source, target, dropEnv()) : d.verdict\n if (!sameVerdict(verdict, d.verdict)) next = { ...next, drag: { ...d, verdict } }\n }\n }\n return next\n }\n\n const state = createStore<TreeState>(withView(core, viewOf(core)))\n\n function publish(c: TreeCore) {\n if (disposed) return\n const view = viewOf(c)\n core = reconcile(c, view)\n const next = withView(core, view)\n const current = state.get()\n if ((Object.keys(next) as (keyof TreeState)[]).every(key => Object.is(next[key], current[key]))) return\n state.set(next)\n }\n\n const patch = (changes: Partial<TreeCore>) => publish({ ...core, ...changes })\n\n // --- sources ---------------------------------------------------------------------------------------------------\n\n /** Reads the store and the shared view state; what opening a document shows is opened. */\n function sync() {\n if (disposed) return\n const documents = store.documents.get() ?? NO_DOCUMENTS\n const activeId = store.activeId.get()\n publish({ ...core, tree: store.tree.get(), documents, activeId, nodeFilters: shared.nodeFilters.get(), basketFilter: shared.basketFilter.get(), expanded: shared.expanded.get() })\n // Opening a document (also by URL, or after a move) shows it: its folders open and its folder becomes the selected one.\n const activeFolder = documents.find(d => d.id === activeId)?.folder\n if (activeFolder !== lastActiveFolder) {\n lastActiveFolder = activeFolder\n expand(ancestorKeys(activeFolder ?? ''))\n if (activeFolder !== undefined) setSelectedFolder(activeFolder)\n }\n if (activeId !== lastActiveId) {\n lastActiveId = activeId\n if (activeId) expand([`doc:${activeId}`])\n }\n }\n\n const unsubscribe = [\n store.tree.subscribe(sync),\n store.documents.subscribe(sync),\n store.activeId.subscribe(sync),\n shared.nodeFilters.subscribe(sync),\n shared.basketFilter.subscribe(sync),\n shared.expanded.subscribe(sync),\n ]\n\n function readOutline() {\n patch({ outline: editor ? editor.outline(structure) : EMPTY_OUTLINE })\n mirrorFocus()\n }\n\n /**\n * The editor's focus mode changed on its own (the focus chip, a block's „Fokussieren“, the focused Typed block vanished):\n * the tree follows without a command. A Typed block the outline does not know yet is retried after the next outline read.\n */\n function mirrorFocus() {\n const id = editor?.focusedId() ?? null\n if (id === seenFocus) return\n if (id === null) {\n seenFocus = null\n if (core.focusKey !== null) patch({ focusKey: null })\n return\n }\n const key = `outline:${id}`\n if (core.focusKey !== key) {\n const item = state.get().view.index.get(key)?.item\n if (item?.type !== 'typedBlock') return\n patch({ focusKey: key })\n }\n seenFocus = id\n }\n\n // The outline is read when the document changed and has been quiet for a moment; a drag in progress is checked at once, and so is the editor's focus.\n function onEditorChange() {\n clearTimeout(outlineTimer)\n outlineTimer = setTimeout(readOutline, debounceMs)\n if (core.drag) publish(core)\n mirrorFocus()\n }\n\n function setContext(context: TreeContext) {\n if (context.editor === editor && context.structure === structure && context.treeRoot === treeRoot) return\n const editorChanged = context.editor !== editor\n const wasVirtual = core.virtual\n editor = context.editor\n structure = context.structure\n treeRoot = context.treeRoot\n clearTimeout(outlineTimer)\n if (editorChanged) {\n seenFocus = null\n unwatchEditor?.()\n unwatchEditor = editor?.onChange(onEditorChange)\n }\n patch({\n virtual: isVirtual(),\n structure,\n kinds: editor?.kinds ?? NO_KINDS,\n baskets: editor?.baskets ?? NO_BASKETS,\n ...(editorChanged ? { focusKey: null } : {}),\n hasEditor: !!editor,\n outline: editor ? editor.outline(structure) : EMPTY_OUTLINE,\n })\n if (core.virtual && !wasVirtual) expand([VIRTUAL_ROOT])\n mirrorFocus()\n }\n\n // --- open, filtered, typed -------------------------------------------------------------------------------------\n\n const filtering = () => filterQuery(core.filterText) !== ''\n\n function setOpen(key: string, open: boolean) {\n if (filtering()) patch({ filterOverrides: { ...core.filterOverrides, [key]: open } })\n else if (isOutlineKey(key)) patch({ collapsedOutline: open ? core.collapsedOutline.filter(k => k !== key) : [...core.collapsedOutline.filter(k => k !== key), key] })\n else if (open) shared.expand([key])\n else shared.expanded.set(shared.expanded.get().filter(k => k !== key))\n }\n\n function expand(keys: readonly string[]) {\n const outlineKeys = keys.filter(isOutlineKey)\n const { filterOverrides } = core\n const overridden = keys.some(key => key in filterOverrides)\n if (overridden || outlineKeys.some(key => core.collapsedOutline.includes(key))) {\n patch({\n collapsedOutline: core.collapsedOutline.filter(key => !outlineKeys.includes(key)),\n filterOverrides: overridden ? Object.fromEntries(Object.entries(filterOverrides).filter(([key]) => !keys.includes(key))) : filterOverrides,\n })\n }\n shared.expand(keys.filter(key => !isOutlineKey(key)))\n }\n\n function setFilterText(text: string) {\n patch({ filterText: text, filterOverrides: filterQuery(text) ? core.filterOverrides : NO_FILTERS })\n }\n\n // --- focus -----------------------------------------------------------------------------------------------------\n\n /** Only a Typed block the editor can address (it has a block ID) can be focused. */\n function focus(key: string) {\n const item = state.get().view.index.get(key)?.item\n if (item?.type !== 'typedBlock' || !item.blockId) return\n patch({ focusKey: key })\n void execute({ type: 'focusBlock', id: item.blockId })\n }\n\n function defocus() {\n if (core.focusKey === null) return\n patch({ focusKey: null })\n void execute({ type: 'focusBlock', id: null })\n }\n\n // --- merge -----------------------------------------------------------------------------------------------------\n\n const canMerge = (item: TreeItem) => item.type === 'typedBlock' && !!item.blockId && !!editor?.canMerge(item.blockId)\n\n function merge(item: TreeItem) {\n if (canMerge(item)) void execute({ type: 'mergeBlock', id: item.blockId! })\n }\n\n // --- selection -------------------------------------------------------------------------------------------------\n\n function setSelectedFolder(path: string) {\n patch({ selectedFolder: path })\n }\n\n function selectItem(item: TreeItem) {\n if (core.renaming?.key === item.key) return\n if (item.key === VIRTUAL_ROOT) return patch({ virtualTarget: null })\n if (item.type === 'document') {\n setSelectedFolder(item.folder ?? '')\n void execute({ type: 'openDocument', id: item.id! })\n }\n else if (item.type === 'typedBlock' || item.type === 'heading') {\n void execute({ type: 'revealBlock', id: item.blockId ?? null, pos: item.pos! })\n const takesTypedBlocks = !!item.kind && core.kinds.some(kind => acceptsChild(core.kinds, item.kind!, kind.id))\n if (core.virtual && item.blockId && takesTypedBlocks) patch({ virtualTarget: item.blockId })\n }\n else {\n setSelectedFolder(item.path ?? '')\n }\n }\n\n function toggle(key: string) {\n setOpen(key, !state.get().view.rows.get(key)?.open)\n }\n\n /** A folder moved from `from` to `to`: its open/selected state follows it. */\n function followFolderMove(from: string, to: string) {\n shared.followFolderMove(from, to)\n patch({\n selectedFolder: remapFolderPath(core.selectedFolder, from, to),\n filterOverrides: Object.fromEntries(Object.entries(core.filterOverrides).map(([key, open]) => [key.startsWith('folder:') ? `folder:${remapFolderPath(key.slice(7), from, to)}` : key, open])),\n })\n expand(ancestorKeys(parentPath(to)))\n }\n\n async function moveFolder(from: string, to: string) {\n pendingMove = { from, to }\n const moved = await execute({ type: 'moveFolder', from, to })\n pendingMove = undefined\n if (moved) followFolderMove(from, to)\n }\n\n // --- drag and drop ---------------------------------------------------------------------------------------------\n\n function dragStart(item: TreeItem) {\n if (core.renaming?.key === item.key || !isDraggable(item, core.virtual)) return null\n const source = dragPayloadOf(item)\n patch({ drag: { source, sourceKey: item.key, hover: null, verdict: null } })\n return source\n }\n\n function dragOver(item: TreeItem) {\n const drag = core.drag\n if (!drag) return null\n const verdict = dropVerdict(drag.source, item, dropEnv())\n if (drag.hover !== item.key || !sameVerdict(drag.verdict, verdict)) patch({ drag: { ...drag, hover: item.key, verdict } })\n return verdict\n }\n\n function foreignDragOver(item: TreeItem) {\n const drag = core.drag\n if (drag && drag.source.type !== 'foreign-block') return null\n const source: DragPayload = { type: 'foreign-block' }\n const verdict = dropVerdict(source, item, dropEnv())\n if (!drag || drag.hover !== item.key || !sameVerdict(drag.verdict, verdict)) patch({ drag: { source, sourceKey: '', hover: item.key, verdict } })\n return verdict\n }\n\n async function dropForeign(item: TreeItem, payload: BlockTransfer, menu: boolean, x: number, y: number) {\n // This tree's own drag (a row also writes the block payload) is a move, not a transfer.\n if (core.drag && core.drag.source.type !== 'foreign-block') return\n patch({ drag: null })\n if (!dropVerdict({ type: 'foreign-block' }, item, dropEnv()).ok) return\n const targetId = item.key === VIRTUAL_ROOT ? null : item.blockId!\n // A throwing executor (the contract says it never does) must not leave the drop handler with an unhandled rejection.\n let done = false\n try {\n done = await execute({ type: 'transferBlock', payload, targetId, menu, x, y })\n }\n catch {\n return\n }\n if (done && targetId && !menu) expand([`outline:${targetId}`])\n }\n\n async function drop(item: TreeItem) {\n const drag = core.drag\n patch({ drag: null })\n if (!drag || !dropVerdict(drag.source, item, dropEnv()).ok) return\n const { source } = drag\n if (source.type === 'typedBlock') {\n const targetId = item.key === VIRTUAL_ROOT ? null : item.blockId!\n if (await execute({ type: 'moveBlock', id: source.blockId, targetId }) && targetId) expand([`outline:${targetId}`])\n return\n }\n // A foreign Typed block is dropped through `dropForeign`, which reads its payload; it is no move of this tree.\n if (source.type === 'foreign-block') return\n const targetPath = item.path!\n if (source.type === 'document') {\n if (await execute({ type: 'moveDocument', id: source.id!, folder: targetPath })) expand(ancestorKeys(targetPath))\n return\n }\n await moveFolder(source.path, joinPath(targetPath, source.path.slice(source.path.lastIndexOf('/') + 1)))\n }\n\n // --- renaming, creating ----------------------------------------------------------------------------------------\n\n function startRename(item: TreeItem) {\n if (item.type !== 'folder') return\n patch({ renaming: { key: item.key, path: item.path!, base: item.label, draft: item.label, error: null } })\n }\n\n async function commitRename() {\n const r = core.renaming\n // An invalid name keeps the field open with its inline error.\n if (!r || r.error) return\n const name = r.draft.trim()\n patch({ renaming: null })\n if (name !== r.base) await moveFolder(r.path, joinPath(parentPath(r.path), name))\n }\n\n async function blurRename() {\n const r = core.renaming\n if (!r) return\n if (r.error) {\n void execute({ type: 'warn', title: t('tree.folder.renameFailed'), description: r.error })\n patch({ renaming: null })\n return\n }\n await commitRename()\n }\n\n function startCreateFolder(parent: string) {\n patch({ selectedFolder: parent, creatingFolder: { parent, draft: '', error: null } })\n }\n\n async function commitCreateFolder() {\n const f = core.creatingFolder\n if (!f) return\n if (!f.draft.trim()) return patch({ creatingFolder: null })\n if (f.error) return\n patch({ creatingFolder: null })\n if (await execute({ type: 'createFolder', path: joinPath(f.parent, f.draft.trim()) })) expand(ancestorKeys(f.parent))\n }\n\n // --- menus, deleting -------------------------------------------------------------------------------------------\n\n async function createDocumentIn(folder: string) {\n setSelectedFolder(folder)\n if (await execute({ type: 'createDocument', folder })) expand(ancestorKeys(folder))\n }\n\n /** Runs `command` for the Typed block of `item` (the file itself when it has none) and shows the result. */\n async function inComposite(item: TreeItem, command: TreeCommand) {\n if (await execute(command)) expand([item.blockId ? `outline:${item.blockId}` : item.key])\n }\n\n /**\n * What can be created below `item`: folders of the store take documents and sub-folders, the open file (as the root or\n * as a document row) and its Typed blocks take what their Block type accepts. Other rows take nothing. Folders also list\n * „Umbenennen“ here: renaming a document happens in the editor's title field.\n */\n function addMenu(item: TreeItem): TreeMenuEntry[][] {\n const groups: TreeMenuEntry[][] = []\n if (item.key !== VIRTUAL_ROOT && (item.type === 'root' || item.type === 'folder')) {\n const path = item.path!\n groups.push([\n { label: t('tree.menu.newDocument'), icon: 'i-lucide-file-plus', run: () => void createDocumentIn(path) },\n { label: item.type === 'root' ? t('tree.menu.newFolder') : t('tree.menu.newSubfolder'), icon: 'i-lucide-folder-plus', run: () => startCreateFolder(path) },\n ])\n }\n else {\n const can = creatableBelow(item, { structure: core.structure, hasEditor: core.hasEditor, activeId: core.activeId, kinds: core.kinds })\n const targetId = item.blockId ?? null\n const entries: TreeMenuEntry[] = []\n if (can.folder) entries.push({ label: t('tree.menu.newCompositeFolder'), icon: 'i-lucide-folder-plus', run: () => void inComposite(item, { type: 'createFolderBlock', targetId }) })\n if (can.files) entries.push({ label: t('tree.menu.importFile'), icon: 'i-lucide-file-up', run: () => void inComposite(item, { type: 'importFiles', targetId }) })\n if (entries.length) groups.push(entries)\n }\n if (item.type === 'folder') groups.push([{ label: t('tree.menu.rename'), icon: 'i-lucide-pencil', run: () => startRename(item) }])\n return groups\n }\n\n async function remove(item: TreeItem) {\n patch({ removing: item.key })\n try {\n await execute(item.type === 'document' ? { type: 'removeDocument', id: item.id!, folder: item.folder ?? '' } : { type: 'removeFolder', path: item.path! })\n }\n finally {\n patch({ removing: null })\n }\n }\n\n sync()\n mirrorFocus()\n\n return {\n state,\n setContext,\n setSelectedFolder,\n setOpen,\n toggle,\n expand,\n setFilterText,\n setKindHidden: (key, kind, hidden) => shared.setKindHidden(key, kind, hidden),\n clearFilter: key => shared.clearFilter(key),\n clearAllFilters: () => shared.clearAllFilters(),\n setBasketShown: (id, shown) => shared.setBasketShown(id, shown),\n clearBasketFilter: () => shared.clearBasketFilter(),\n focus,\n defocus,\n canMerge,\n merge,\n select: selectItem,\n activate(item) {\n selectItem(item)\n if (item.type === 'root' || item.type === 'folder') toggle(item.key)\n },\n addMenu,\n remove,\n isDraggable: item => core.renaming?.key !== item.key && isDraggable(item, core.virtual),\n dragStart,\n dragOver,\n dragLeave(item) {\n // A foreign drag only exists while it is over this tree (no `dragend` reaches here), so leaving a row ends it; the next row's `foreignDragOver` starts it again.\n if (core.drag?.source.type === 'foreign-block') patch({ drag: null })\n else if (core.drag?.hover === item.key) patch({ drag: { ...core.drag, hover: null, verdict: null } })\n },\n dragEnd: () => patch({ drag: null }),\n drop,\n foreignDragOver,\n dropForeign,\n startRename,\n setRenameDraft(text) {\n const r = core.renaming\n if (r) patch({ renaming: { ...r, draft: text, error: renameError(text, r.path, r.base, core.tree) } })\n },\n cancelRename: () => patch({ renaming: null }),\n commitRename,\n blurRename,\n startCreateFolder,\n setFolderDraft(text) {\n const f = core.creatingFolder\n if (f) patch({ creatingFolder: { ...f, draft: text, error: folderError(text, f.parent, core.tree) } })\n },\n cancelCreateFolder: () => patch({ creatingFolder: null }),\n commitCreateFolder,\n dispose() {\n disposed = true\n clearTimeout(outlineTimer)\n unwatchE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AK,MAAM,OAAO,SAAS,iBAAiB,MAAM,EAAE,MAAM,KAAK,CAAC;QAC/D,IAAI,KAAK,MAAM,UAAU,KAAK,KAAK,MAAM,EAAE,MAAM;IAAE,GAAG,KAAK;IAAM,OAAO;IAAM,SAAS;GAAK,EAAE,CAAC;EACtG;EACA,eAAe,MAAM,EAAE,MAAM,KAAK,CAAC;EACnC;EACA;EACA;EACA;EACA,eAAe,MAAM;GACnB,MAAM,IAAI,KAAK;GACf,IAAI,GAAG,MAAM,EAAE,UAAU;IAAE,GAAG;IAAG,OAAO;IAAM,OAAO,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI;GAAE,EAAE,CAAC;EACvG;EACA,oBAAoB,MAAM,EAAE,UAAU,KAAK,CAAC;EAC5C;EACA;EACA;EACA,eAAe,MAAM;GACnB,MAAM,IAAI,KAAK;GACf,IAAI,GAAG,MAAM,EAAE,gBAAgB;IAAE,GAAG;IAAG,OAAO;IAAM,OAAO,YAAY,MAAM,EAAE,QAAQ,KAAK,IAAI;GAAE,EAAE,CAAC;EACvG;EACA,0BAA0B,MAAM,EAAE,gBAAgB,KAAK,CAAC;EACxD;EACA,UAAU;GACR,WAAW;GACX,aAAa,YAAY;GACzB,gBAAgB;GAChB,KAAK,MAAM,QAAQ,aAAa,KAAK;EACvC;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"tree-model.js","names":[],"sources":["../../src/tree/tree-model.ts"],"sourcesContent":["import type { BlockTransfer } from '../core/block-transfer'\nimport { createStore, type ReadonlyStore } from '../core/store'\nimport { acceptsChild, type Basket, basketById, type BlockType } from '../features/composites'\nimport type { Translate } from '../i18n'\nimport { type DropEnv, dropVerdict, type DropVerdict } from './drop-rules'\nimport { remapFolderPath } from './folder-paths'\nimport type { DocumentStore } from './store'\nimport {\n ancestorKeys,\n collectFolderPaths,\n creatableBelow,\n type DragPayload,\n dragPayloadOf,\n EMPTY_OUTLINE,\n filterKinds,\n folderNamesIn,\n isDraggable,\n joinPath,\n type Outline,\n parentPath,\n type TreeItem,\n VIRTUAL_ROOT,\n} from './tree-items'\nimport { deriveTree, filterQuery, type TreeRow, type TreeView } from './tree-rows'\nimport type { NodeFilters, TreeViewModel } from './tree-view-model'\nimport type { DocumentSummary, TreeFolder } from './types'\n\n// One framework-free model per `DocumentTree`, rendered by the Vue and the React component alike. It owns what the\n// tree remembers (open rows, kind filters, the title filter, the selection, a drag, a folder being renamed or created)\n// and checks all of it against the tree after every change of the store, the outline or the view state, so a key of\n// something that moved or vanished never lingers. It never calls the store or the editor to change something: it emits\n// `TreeCommand`s to the `execute` it was given and follows their result.\n\n/** What the model asks its host to do; the host reports whether it happened. */\nexport type TreeCommand\n = | { type: 'openDocument', id: string }\n | { type: 'createDocument', folder: string }\n | { type: 'moveDocument', id: string, folder: string }\n | { type: 'removeDocument', id: string, folder: string }\n | { type: 'createFolder', path: string }\n | { type: 'moveFolder', from: string, to: string }\n | { type: 'removeFolder', path: string }\n /** Moves the block into the Typed block `targetId` (`null` = the end of the document). */\n | { type: 'moveBlock', id: string, targetId: string | null }\n | { type: 'revealBlock', id: string | null, pos: number }\n /** Adds an Folder block to the Typed block `targetId` (`null` = the end of the document). */\n | { type: 'createFolderBlock', targetId: string | null }\n /** Lets the user pick files and imports them into the Typed block `targetId` (`null` = the end of the document); `false` when none were imported. */\n | { type: 'importFiles', targetId: string | null }\n | { type: 'warn', title: string, description: string }\n /** Inserts a Typed block dragged in from another surface or tree at the end of the Typed block `targetId` (`null` = the end of the document); `menu`: offer the transforms at `x`, `y` first. */\n | { type: 'transferBlock', payload: BlockTransfer, targetId: string | null, menu: boolean, x: number, y: number }\n /** Puts the editor into focus mode on the Typed block `id` (`null` = leaves focus mode); sent after the tree's own focus changed. */\n | { type: 'focusBlock', id: string | null }\n /** The Typed block `id` absorbs the Typed block that follows it (`mergeCompositeWithNext`); `false` when the editor refuses. */\n | { type: 'mergeBlock', id: string }\n\n/** Runs a command and resolves whether it happened. Never rejects: the host reports its own failures. */\nexport type TreeExecutor = (command: TreeCommand) => boolean | Promise<boolean>\n\n/** What the model needs from the open document's editor. */\nexport interface TreeEditor {\n kinds: readonly BlockType[]\n /** The baskets a Typed block can be put into (colour dots on the rows). */\n baskets: readonly Basket[]\n /** The outline in `structure`: Typed blocks in `'structured'` structure, else the headings. Empty once the editor is gone. */\n outline: (structure: string) => Outline\n /** Whether a block may move into a Typed block, judged on the live document. */\n moveVerdict: NonNullable<DropEnv['moveVerdict']>\n /** Whether the editor takes blocks from outside: it has the transfer feature's drop target and its `transferBlock` command. */\n canTransfer: () => boolean\n /** The block id of the Typed block the editor is focused on (focus mode), `null` without focus. The model mirrors it into the tree. */\n focusedId: () => string | null\n /** Whether the Typed block `id` can absorb the Typed block that follows it, judged on the live document. */\n canMerge: (id: string) => boolean\n /** `listener` runs after the document or the editor's focus changed; returns the unsubscribe function. */\n onChange: (listener: () => void) => () => void\n}\n\n/** What the surrounding app decides: the open editor and the `blocks.structure` / `blocks.treeRoot` settings. */\nexport interface TreeContext {\n editor: TreeEditor | undefined\n structure: string\n treeRoot: string\n}\n\nexport interface TreeModelOptions {\n /** Words the menus, the drop refusals and the label of an untitled open document; the framework layer passes the context's `t`. */\n t: Translate\n store: DocumentStore\n /** The view state shared by the trees of one app: open store items and kind filters (persisted). */\n view: TreeViewModel\n execute: TreeExecutor\n context: TreeContext\n /** The folder new documents and folders go to; default the root. */\n selectedFolder?: string\n /** How long the outline waits for the document to settle before it is read again; default 150 ms. */\n outlineDebounceMs?: number\n}\n\n/** A drag in progress. */\nexport interface TreeDrag {\n source: DragPayload\n /** Key of the dragged row (`''` for a `foreign-block`, which has no row here) */\n sourceKey: string\n /** Key of the row under the pointer */\n hover: string | null\n /** What dropping on `hover` would do; `null` without a `hover` */\n verdict: DropVerdict | null\n}\n\n/** A folder being renamed. */\nexport interface TreeRename {\n /** Key of the folder's row */\n key: string\n path: string\n /** Its name when renaming started */\n base: string\n draft: string\n error: string | null\n}\n\n/** A folder being named. */\nexport interface TreeCreateFolder {\n /** Folder path the folder is created in */\n parent: string\n draft: string\n error: string | null\n}\n\n/** Everything a renderer needs. Fields below `view` are what the derived `view` was computed from and what `rowOf` reads. */\nexport interface TreeState {\n /** The loaded folder tree: `undefined` = not loaded yet, `null` = loading failed. */\n tree: TreeFolder | null | undefined\n documents: readonly DocumentSummary[]\n activeId: string | undefined\n /** The open document is the root (virtual mode) instead of the store's folders. */\n virtual: boolean\n structure: string\n kinds: readonly BlockType[]\n /** The open editor's baskets (colours of the row dots). */\n baskets: readonly Basket[]\n hasEditor: boolean\n outline: Outline\n nodeFilters: NodeFilters\n /** The basket ids the tree shows (`[]` = all). */\n basketFilter: readonly string[]\n /** Key of the focused row: the tree lists only its children. `null` = no focus. */\n focusKey: string | null\n expanded: readonly string[]\n collapsedOutline: readonly string[]\n /** What the title filter input holds. */\n filterText: string\n filterOverrides: Readonly<Record<string, boolean>>\n /** The folder new documents, folders and host imports go to. */\n selectedFolder: string\n /** Virtual mode: block ID of the selected Typed block that takes Typed blocks; `null` = the document itself. */\n virtualTarget: string | null\n drag: TreeDrag | null\n renaming: TreeRename | null\n creatingFolder: TreeCreateFolder | null\n /** Key of the row whose deletion is running. */\n removing: string | null\n view: TreeView\n /** The unfiltered items from the top down to the focused one (the breadcrumb); empty without a focus. Derived with `view`. */\n focusPath: readonly TreeItem[]\n}\n\n/** One row of a row's menu. */\nexport interface TreeMenuEntry {\n label: string\n icon: string\n run: () => void\n}\n\n/** How a renderer draws one row. */\nexport interface TreeRowState extends TreeRow {\n /** The row's document is the open one. */\n active: boolean\n /** The row is the selected folder, or (virtual mode) the selected Typed block. */\n selected: boolean\n /** What dropping the drag on this row would do, while the pointer is over it. */\n drop: DropVerdict | null\n renaming: TreeRename | null\n removing: boolean\n /** The kinds the row's kind filter can hide below it, and the ones it hides. */\n filterKinds: readonly BlockType[]\n hiddenKinds: readonly string[]\n /** The row offers a kind filter. */\n showFilter: boolean\n}\n\nexport interface TreeModel {\n readonly state: ReadonlyStore<TreeState>\n /** The open editor or a setting changed. */\n setContext: (context: TreeContext) => void\n /** The host selected another folder (it controls the value). */\n setSelectedFolder: (path: string) => void\n\n // --- what is open, filtered, typed\n /** Opens or closes a row; while the title filter is set the choice is discarded when it is cleared. */\n setOpen: (key: string, open: boolean) => void\n toggle: (key: string) => void\n /** Opens the rows (also during a title filter); closed rows are left alone otherwise. */\n expand: (keys: readonly string[]) => void\n /** Filters the rows by title (case-insensitive substring); `''` clears it and restores the opened rows from before. */\n setFilterText: (text: string) => void\n setKindHidden: (key: string, kind: string, hidden: boolean) => void\n clearFilter: (key: string) => void\n clearAllFilters: () => void\n /** Shows (`shown`) or stops showing the Typed blocks of the basket; no basket shown = no filter. */\n setBasketShown: (id: string, shown: boolean) => void\n clearBasketFilter: () => void\n /** Focuses a Typed block row: the tree lists only its children and the editor hides everything else. */\n focus: (key: string) => void\n /** Leaves focus mode (tree and editor). */\n defocus: () => void\n /** Whether the Typed block row can be merged with the Typed block after it (it has a block ID and the editor accepts the merge). */\n canMerge: (item: TreeItem) => boolean\n /** Merges the Typed block row with the Typed block after it: the row keeps its title, id and meta and takes over the other one's body and nested Typed blocks. */\n merge: (item: TreeItem) => void\n\n // --- rows\n /** A row was chosen (click, Enter). */\n select: (item: TreeItem) => void\n /** `select`, and a folder or the root toggles. */\n activate: (item: TreeItem) => void\n addMenu: (item: TreeItem) => TreeMenuEntry[][]\n remove: (item: TreeItem) => Promise<void>\n\n // --- drag and drop\n isDraggable: (item: TreeItem) => boolean\n /** Starts dragging `item`; returns what the drag carries, `null` when `item` cannot be dragged. */\n dragStart: (item: TreeItem) => DragPayload | null\n /** The pointer is over `item`; returns the verdict (`null` without a drag). Only an `ok` one is a drop target. */\n dragOver: (item: TreeItem) => DropVerdict | null\n /** The pointer left `item` for good (not into one of its parts). */\n dragLeave: (item: TreeItem) => void\n dragEnd: () => void\n drop: (item: TreeItem) => Promise<void>\n /**\n * A Typed block from another surface or tree (`BLOCK_MIME`) is over `item`; returns the verdict, `null` while this\n * tree's own drag is running. Only an `ok` one is a drop target.\n */\n foreignDragOver: (item: TreeItem) => DropVerdict | null\n /** Drops the foreign Typed block `payload` on `item`: inserts a copy at the end of that Typed block (`menu`: offers the transforms at `x`, `y` instead). */\n dropForeign: (item: TreeItem, payload: BlockTransfer, menu: boolean, x: number, y: number) => Promise<void>\n\n // --- renaming and creating folders\n startRename: (item: TreeItem) => void\n setRenameDraft: (text: string) => void\n cancelRename: () => void\n commitRename: () => Promise<void>\n /** The rename field lost focus: commit, or give up with a warning when the name is invalid. */\n blurRename: () => Promise<void>\n startCreateFolder: (parent: string) => void\n setFolderDraft: (text: string) => void\n cancelCreateFolder: () => void\n commitCreateFolder: () => Promise<void>\n\n dispose: () => void\n}\n\nconst NO_DOCUMENTS: readonly DocumentSummary[] = []\nconst NO_KINDS: readonly BlockType[] = []\nconst NO_BASKETS: readonly Basket[] = []\nconst NO_FILTERS: Readonly<Record<string, boolean>> = {}\nconst UNSET = Symbol('unset')\n\nconst isOutlineKey = (key: string) => key.startsWith('outline:')\n\n/** The state `core` holds: everything of `TreeState` but what is derived from the view. */\ntype TreeCore = Omit<TreeState, 'view' | 'focusPath'>\n\nconst withView = (c: TreeCore, view: TreeView): TreeState => ({ ...c, view, focusPath: view.focusPath })\n\nfunction sameVerdict(a: DropVerdict | null, b: DropVerdict | null): boolean {\n if (a === b) return true\n if (!a || !b) return false\n return a.ok ? b.ok : !b.ok && a.reason === b.reason\n}\n\n/** A row's state in `state` (`item` is one of `state.view.items`). */\nexport function rowOf(state: TreeState, item: TreeItem, t: Translate): TreeRowState {\n const hidden = state.nodeFilters[item.key] ?? []\n const kinds = filterKinds(item, { structure: state.structure, activeId: state.activeId, kinds: state.kinds, t })\n const virtualTarget = state.virtual && (item.key === VIRTUAL_ROOT ? state.virtualTarget === null : !!item.blockId && item.blockId === state.virtualTarget)\n return {\n ...state.view.rows.get(item.key)!,\n active: item.id !== undefined && item.id === state.activeId,\n selected: (item.type !== 'document' && item.path === state.selectedFolder) || virtualTarget,\n drop: state.drag?.hover === item.key ? state.drag.verdict : null,\n renaming: state.renaming?.key === item.key ? state.renaming : null,\n removing: state.removing === item.key,\n filterKinds: kinds,\n hiddenKinds: hidden,\n showFilter: kinds.length > 0 && (item.type === 'root' || item.type === 'folder' || !!item.children?.length || hidden.length > 0),\n }\n}\n\n/** A tree model over `options.store`; call `dispose` when its tree goes away. */\nexport function createTreeModel(options: TreeModelOptions): TreeModel {\n const { store, view: shared, execute, t } = options\n const debounceMs = options.outlineDebounceMs ?? 150\n\n let editor = options.context.editor\n let structure = options.context.structure\n let treeRoot = options.context.treeRoot\n let unwatchEditor = editor?.onChange(onEditorChange)\n /** The focus the editor last showed that the tree took over (or already had); a change of the editor's focus is told apart from the tree's own by comparing against it. */\n let seenFocus: string | null = null\n let outlineTimer: ReturnType<typeof setTimeout> | undefined\n /** A folder move the host is running: until it is done, a selected folder at the old path follows to the new one. */\n let pendingMove: { from: string, to: string } | undefined\n let disposed = false\n\n const isVirtual = () => treeRoot === 'file' && structure === 'structured' && !!editor\n\n let core: TreeCore = {\n tree: store.tree.get(),\n documents: store.documents.get() ?? NO_DOCUMENTS,\n activeId: store.activeId.get(),\n virtual: isVirtual(),\n structure,\n kinds: editor?.kinds ?? NO_KINDS,\n baskets: editor?.baskets ?? NO_BASKETS,\n hasEditor: !!editor,\n outline: editor ? editor.outline(structure) : EMPTY_OUTLINE,\n nodeFilters: shared.nodeFilters.get(),\n basketFilter: shared.basketFilter.get(),\n focusKey: null,\n expanded: shared.expanded.get(),\n collapsedOutline: shared.collapsedOutline.get(),\n filterText: '',\n filterOverrides: NO_FILTERS,\n selectedFolder: options.selectedFolder ?? '',\n virtualTarget: null,\n drag: null,\n renaming: null,\n creatingFolder: null,\n removing: null,\n }\n let lastView: { deps: readonly unknown[], view: TreeView } | undefined\n let lastTree: TreeFolder | null | undefined | typeof UNSET = UNSET\n let folderPaths = new Set<string>()\n let lastActiveFolder: string | undefined | typeof UNSET = UNSET\n let lastActiveId: string | undefined | typeof UNSET = UNSET\n\n const dropEnv = (): DropEnv => ({ virtual: core.virtual, moveVerdict: editor?.moveVerdict, canTransfer: editor?.canTransfer() ?? false, t })\n\n function viewOf(c: TreeCore): TreeView {\n const deps = [c.tree, c.documents, c.activeId, c.virtual, c.outline, c.kinds, c.nodeFilters, c.basketFilter, c.baskets, c.focusKey, c.expanded, c.collapsedOutline, c.filterText, c.filterOverrides]\n if (lastView && deps.every((dep, i) => Object.is(dep, lastView!.deps[i]))) return lastView.view\n // A basket the open editor does not offer cannot be unchecked in the filter menu, so it never filters.\n const basketFilter = c.basketFilter.filter(id => basketById(c.baskets, id) !== undefined)\n const view = deriveTree({ ...c, basketFilter, t, select: selectItem })\n lastView = { deps, view }\n return view\n }\n\n const renameError = (draft: string, path: string, base: string, tree: TreeFolder | null | undefined) =>\n draft.trim() === base ? null : store.validateName(draft, folderNamesIn(tree, parentPath(path), path))\n const folderError = (draft: string, parent: string, tree: TreeFolder | null | undefined) =>\n draft.trim() ? store.validateName(draft, folderNamesIn(tree, parent)) : null\n\n /** Measures everything the tree remembers against the current tree: what is gone is dropped, what depends on the tree is recomputed. */\n function reconcile(c: TreeCore, view: TreeView): TreeCore {\n let next = c\n if (c.tree !== lastTree) {\n lastTree = c.tree\n folderPaths = new Set<string>()\n if (c.tree) collectFolderPaths(c.tree, folderPaths)\n if (c.tree && !folderPaths.has(next.selectedFolder)) {\n const followed = pendingMove ? remapFolderPath(next.selectedFolder, pendingMove.from, pendingMove.to) : ''\n next = { ...next, selectedFolder: folderPaths.has(followed) ? followed : '' }\n }\n }\n if (next.virtualTarget !== null && (!next.virtual || !view.keys.has(`outline:${next.virtualTarget}`))) next = { ...next, virtualTarget: null }\n if (next.focusKey !== null && !view.keys.has(next.focusKey)) next = { ...next, focusKey: null }\n if (next.renaming) {\n const r = next.renaming\n if (!view.keys.has(r.key)) next = { ...next, renaming: null }\n else {\n const error = renameError(r.draft, r.path, r.base, next.tree)\n if (error !== r.error) next = { ...next, renaming: { ...r, error } }\n }\n }\n if (next.creatingFolder) {\n const f = next.creatingFolder\n if (next.tree && !folderPaths.has(f.parent)) next = { ...next, creatingFolder: null }\n else {\n const error = folderError(f.draft, f.parent, next.tree)\n if (error !== f.error) next = { ...next, creatingFolder: { ...f, error } }\n }\n }\n if (next.drag) {\n const d = next.drag\n if ((d.source.type !== 'foreign-block' && !view.keys.has(d.sourceKey)) || (d.hover !== null && !view.keys.has(d.hover))) next = { ...next, drag: null }\n else if (d.hover !== null) {\n const target = view.rows.get(d.hover)?.item\n const verdict = target ? dropVerdict(d.source, target, dropEnv()) : d.verdict\n if (!sameVerdict(verdict, d.verdict)) next = { ...next, drag: { ...d, verdict } }\n }\n }\n return next\n }\n\n const state = createStore<TreeState>(withView(core, viewOf(core)))\n\n function publish(c: TreeCore) {\n if (disposed) return\n const view = viewOf(c)\n core = reconcile(c, view)\n const next = withView(core, view)\n const current = state.get()\n if ((Object.keys(next) as (keyof TreeState)[]).every(key => Object.is(next[key], current[key]))) return\n state.set(next)\n }\n\n const patch = (changes: Partial<TreeCore>) => publish({ ...core, ...changes })\n\n // --- sources ---------------------------------------------------------------------------------------------------\n\n /** Reads the store and the shared view state; what opening a document shows is opened. */\n function sync() {\n if (disposed) return\n const documents = store.documents.get() ?? NO_DOCUMENTS\n const activeId = store.activeId.get()\n publish({ ...core, tree: store.tree.get(), documents, activeId, nodeFilters: shared.nodeFilters.get(), basketFilter: shared.basketFilter.get(), expanded: shared.expanded.get(), collapsedOutline: shared.collapsedOutline.get() })\n // Opening a document (also by URL, or after a move) shows it: its folders open and its folder becomes the selected one.\n const activeFolder = documents.find(d => d.id === activeId)?.folder\n if (activeFolder !== lastActiveFolder) {\n lastActiveFolder = activeFolder\n expand(ancestorKeys(activeFolder ?? ''))\n if (activeFolder !== undefined) setSelectedFolder(activeFolder)\n }\n if (activeId !== lastActiveId) {\n lastActiveId = activeId\n if (activeId) expand([`doc:${activeId}`])\n }\n }\n\n const unsubscribe = [\n store.tree.subscribe(sync),\n store.documents.subscribe(sync),\n store.activeId.subscribe(sync),\n shared.nodeFilters.subscribe(sync),\n shared.basketFilter.subscribe(sync),\n shared.expanded.subscribe(sync),\n shared.collapsedOutline.subscribe(sync),\n ]\n\n function readOutline() {\n patch({ outline: editor ? editor.outline(structure) : EMPTY_OUTLINE })\n mirrorFocus()\n }\n\n /**\n * The editor's focus mode changed on its own (the focus chip, a block's „Fokussieren“, the focused Typed block vanished):\n * the tree follows without a command. A Typed block the outline does not know yet is retried after the next outline read.\n */\n function mirrorFocus() {\n const id = editor?.focusedId() ?? null\n if (id === seenFocus) return\n if (id === null) {\n seenFocus = null\n if (core.focusKey !== null) patch({ focusKey: null })\n return\n }\n const key = `outline:${id}`\n if (core.focusKey !== key) {\n const item = state.get().view.index.get(key)?.item\n if (item?.type !== 'typedBlock') return\n patch({ focusKey: key })\n }\n seenFocus = id\n }\n\n // The outline is read when the document changed and has been quiet for a moment; a drag in progress is checked at once, and so is the editor's focus.\n function onEditorChange() {\n clearTimeout(outlineTimer)\n outlineTimer = setTimeout(readOutline, debounceMs)\n if (core.drag) publish(core)\n mirrorFocus()\n }\n\n function setContext(context: TreeContext) {\n if (context.editor === editor && context.structure === structure && context.treeRoot === treeRoot) return\n const editorChanged = context.editor !== editor\n const wasVirtual = core.virtual\n editor = context.editor\n structure = context.structure\n treeRoot = context.treeRoot\n clearTimeout(outlineTimer)\n if (editorChanged) {\n seenFocus = null\n unwatchEditor?.()\n unwatchEditor = editor?.onChange(onEditorChange)\n }\n patch({\n virtual: isVirtual(),\n structure,\n kinds: editor?.kinds ?? NO_KINDS,\n baskets: editor?.baskets ?? NO_BASKETS,\n ...(editorChanged ? { focusKey: null } : {}),\n hasEditor: !!editor,\n outline: editor ? editor.outline(structure) : EMPTY_OUTLINE,\n })\n if (core.virtual && !wasVirtual) expand([VIRTUAL_ROOT])\n mirrorFocus()\n }\n\n // --- open, filtered, typed -------------------------------------------------------------------------------------\n\n const filtering = () => filterQuery(core.filterText) !== ''\n\n function setOpen(key: string, open: boolean) {\n if (filtering()) patch({ filterOverrides: { ...core.filterOverrides, [key]: open } })\n else if (isOutlineKey(key)) {\n const rest = shared.collapsedOutline.get().filter(k => k !== key)\n shared.collapsedOutline.set(open ? rest : [...rest, key])\n }\n else if (open) shared.expand([key])\n else shared.expanded.set(shared.expanded.get().filter(k => k !== key))\n }\n\n function expand(keys: readonly string[]) {\n const outlineKeys = keys.filter(isOutlineKey)\n const { filterOverrides } = core\n if (keys.some(key => key in filterOverrides)) patch({ filterOverrides: Object.fromEntries(Object.entries(filterOverrides).filter(([key]) => !keys.includes(key))) })\n const collapsed = shared.collapsedOutline.get()\n if (outlineKeys.some(key => collapsed.includes(key))) shared.collapsedOutline.set(collapsed.filter(key => !outlineKeys.includes(key)))\n shared.expand(keys.filter(key => !isOutlineKey(key)))\n }\n\n function setFilterText(text: string) {\n patch({ filterText: text, filterOverrides: filterQuery(text) ? core.filterOverrides : NO_FILTERS })\n }\n\n // --- focus -----------------------------------------------------------------------------------------------------\n\n /** Only a Typed block the editor can address (it has a block ID) can be focused. */\n function focus(key: string) {\n const item = state.get().view.index.get(key)?.item\n if (item?.type !== 'typedBlock' || !item.blockId) return\n patch({ focusKey: key })\n void execute({ type: 'focusBlock', id: item.blockId })\n }\n\n function defocus() {\n if (core.focusKey === null) return\n patch({ focusKey: null })\n void execute({ type: 'focusBlock', id: null })\n }\n\n // --- merge -----------------------------------------------------------------------------------------------------\n\n const canMerge = (item: TreeItem) => item.type === 'typedBlock' && !!item.blockId && !!editor?.canMerge(item.blockId)\n\n function merge(item: TreeItem) {\n if (canMerge(item)) void execute({ type: 'mergeBlock', id: item.blockId! })\n }\n\n // --- selection -------------------------------------------------------------------------------------------------\n\n function setSelectedFolder(path: string) {\n patch({ selectedFolder: path })\n }\n\n function selectItem(item: TreeItem) {\n if (core.renaming?.key === item.key) return\n if (item.key === VIRTUAL_ROOT) return patch({ virtualTarget: null })\n if (item.type === 'document') {\n setSelectedFolder(item.folder ?? '')\n void execute({ type: 'openDocument', id: item.id! })\n }\n else if (item.type === 'typedBlock' || item.type === 'heading') {\n void execute({ type: 'revealBlock', id: item.blockId ?? null, pos: item.pos! })\n const takesTypedBlocks = !!item.kind && core.kinds.some(kind => acceptsChild(core.kinds, item.kind!, kind.id))\n if (core.virtual && item.blockId && takesTypedBlocks) patch({ virtualTarget: item.blockId })\n }\n else {\n setSelectedFolder(item.path ?? '')\n }\n }\n\n function toggle(key: string) {\n setOpen(key, !state.get().view.rows.get(key)?.open)\n }\n\n /** A folder moved from `from` to `to`: its open/selected state follows it. */\n function followFolderMove(from: string, to: string) {\n shared.followFolderMove(from, to)\n patch({\n selectedFolder: remapFolderPath(core.selectedFolder, from, to),\n filterOverrides: Object.fromEntries(Object.entries(core.filterOverrides).map(([key, open]) => [key.startsWith('folder:') ? `folder:${remapFolderPath(key.slice(7), from, to)}` : key, open])),\n })\n expand(ancestorKeys(parentPath(to)))\n }\n\n async function moveFolder(from: string, to: string) {\n pendingMove = { from, to }\n const moved = await execute({ type: 'moveFolder', from, to })\n pendingMove = undefined\n if (moved) followFolderMove(from, to)\n }\n\n // --- drag and drop ---------------------------------------------------------------------------------------------\n\n function dragStart(item: TreeItem) {\n if (core.renaming?.key === item.key || !isDraggable(item, core.virtual)) return null\n const source = dragPayloadOf(item)\n patch({ drag: { source, sourceKey: item.key, hover: null, verdict: null } })\n return source\n }\n\n function dragOver(item: TreeItem) {\n const drag = core.drag\n if (!drag) return null\n const verdict = dropVerdict(drag.source, item, dropEnv())\n if (drag.hover !== item.key || !sameVerdict(drag.verdict, verdict)) patch({ drag: { ...drag, hover: item.key, verdict } })\n return verdict\n }\n\n function foreignDragOver(item: TreeItem) {\n const drag = core.drag\n if (drag && drag.source.type !== 'foreign-block') return null\n const source: DragPayload = { type: 'foreign-block' }\n const verdict = dropVerdict(source, item, dropEnv())\n if (!drag || drag.hover !== item.key || !sameVerdict(drag.verdict, verdict)) patch({ drag: { source, sourceKey: '', hover: item.key, verdict } })\n return verdict\n }\n\n async function dropForeign(item: TreeItem, payload: BlockTransfer, menu: boolean, x: number, y: number) {\n // This tree's own drag (a row also writes the block payload) is a move, not a transfer.\n if (core.drag && core.drag.source.type !== 'foreign-block') return\n patch({ drag: null })\n if (!dropVerdict({ type: 'foreign-block' }, item, dropEnv()).ok) return\n const targetId = item.key === VIRTUAL_ROOT ? null : item.blockId!\n // A throwing executor (the contract says it never does) must not leave the drop handler with an unhandled rejection.\n let done = false\n try {\n done = await execute({ type: 'transferBlock', payload, targetId, menu, x, y })\n }\n catch {\n return\n }\n if (done && targetId && !menu) expand([`outline:${targetId}`])\n }\n\n async function drop(item: TreeItem) {\n const drag = core.drag\n patch({ drag: null })\n if (!drag || !dropVerdict(drag.source, item, dropEnv()).ok) return\n const { source } = drag\n if (source.type === 'typedBlock') {\n const targetId = item.key === VIRTUAL_ROOT ? null : item.blockId!\n if (await execute({ type: 'moveBlock', id: source.blockId, targetId }) && targetId) expand([`outline:${targetId}`])\n return\n }\n // A foreign Typed block is dropped through `dropForeign`, which reads its payload; it is no move of this tree.\n if (source.type === 'foreign-block') return\n const targetPath = item.path!\n if (source.type === 'document') {\n if (await execute({ type: 'moveDocument', id: source.id!, folder: targetPath })) expand(ancestorKeys(targetPath))\n return\n }\n await moveFolder(source.path, joinPath(targetPath, source.path.slice(source.path.lastIndexOf('/') + 1)))\n }\n\n // --- renaming, creating ----------------------------------------------------------------------------------------\n\n function startRename(item: TreeItem) {\n if (item.type !== 'folder') return\n patch({ renaming: { key: item.key, path: item.path!, base: item.label, draft: item.label, error: null } })\n }\n\n async function commitRename() {\n const r = core.renaming\n // An invalid name keeps the field open with its inline error.\n if (!r || r.error) return\n const name = r.draft.trim()\n patch({ renaming: null })\n if (name !== r.base) await moveFolder(r.path, joinPath(parentPath(r.path), name))\n }\n\n async function blurRename() {\n const r = core.renaming\n if (!r) return\n if (r.error) {\n void execute({ type: 'warn', title: t('tree.folder.renameFailed'), description: r.error })\n patch({ renaming: null })\n return\n }\n await commitRename()\n }\n\n function startCreateFolder(parent: string) {\n patch({ selectedFolder: parent, creatingFolder: { parent, draft: '', error: null } })\n }\n\n async function commitCreateFolder() {\n const f = core.creatingFolder\n if (!f) return\n if (!f.draft.trim()) return patch({ creatingFolder: null })\n if (f.error) return\n patch({ creatingFolder: null })\n if (await execute({ type: 'createFolder', path: joinPath(f.parent, f.draft.trim()) })) expand(ancestorKeys(f.parent))\n }\n\n // --- menus, deleting -------------------------------------------------------------------------------------------\n\n async function createDocumentIn(folder: string) {\n setSelectedFolder(folder)\n if (await execute({ type: 'createDocument', folder })) expand(ancestorKeys(folder))\n }\n\n /** Runs `command` for the Typed block of `item` (the file itself when it has none) and shows the result. */\n async function inComposite(item: TreeItem, command: TreeCommand) {\n if (await execute(command)) expand([item.blockId ? `outline:${item.blockId}` : item.key])\n }\n\n /**\n * What can be created below `item`: folders of the store take documents and sub-folders, the open file (as the root or\n * as a document row) and its Typed blocks take what their Block type accepts. Other rows take nothing. Folders also list\n * „Umbenennen“ here: renaming a document happens in the editor's title field.\n */\n function addMenu(item: TreeItem): TreeMenuEntry[][] {\n const groups: TreeMenuEntry[][] = []\n if (item.key !== VIRTUAL_ROOT && (item.type === 'root' || item.type === 'folder')) {\n const path = item.path!\n groups.push([\n { label: t('tree.menu.newDocument'), icon: 'i-lucide-file-plus', run: () => void createDocumentIn(path) },\n { label: item.type === 'root' ? t('tree.menu.newFolder') : t('tree.menu.newSubfolder'), icon: 'i-lucide-folder-plus', run: () => startCreateFolder(path) },\n ])\n }\n else {\n const can = creatableBelow(item, { structure: core.structure, hasEditor: core.hasEditor, activeId: core.activeId, kinds: core.kinds })\n const targetId = item.blockId ?? null\n const entries: TreeMenuEntry[] = []\n if (can.folder) entries.push({ label: t('tree.menu.newCompositeFolder'), icon: 'i-lucide-folder-plus', run: () => void inComposite(item, { type: 'createFolderBlock', targetId }) })\n if (can.files) entries.push({ label: t('tree.menu.importFile'), icon: 'i-lucide-file-up', run: () => void inComposite(item, { type: 'importFiles', targetId }) })\n if (entries.length) groups.push(entries)\n }\n if (item.type === 'folder') groups.push([{ label: t('tree.menu.rename'), icon: 'i-lucide-pencil', run: () => startRename(item) }])\n return groups\n }\n\n async function remove(item: TreeItem) {\n patch({ removing: item.key })\n try {\n await execute(item.type === 'document' ? { type: 'removeDocument', id: item.id!, folder: item.folder ?? '' } : { type: 'removeFolder', path: item.path! })\n }\n finally {\n patch({ removing: null })\n }\n }\n\n sync()\n mirrorFocus()\n\n return {\n state,\n setContext,\n setSelectedFolder,\n setOpen,\n toggle,\n expand,\n setFilterText,\n setKindHidden: (key, kind, hidden) => shared.setKindHidden(key, kind, hidden),\n clearFilter: key => shared.clearFilter(key),\n clearAllFilters: () => shared.clearAllFilters(),\n setBasketShown: (id, shown) => shared.setBasketShown(id, shown),\n clearBasketFilter: () => shared.clearBasketFilter(),\n focus,\n defocus,\n canMerge,\n merge,\n select: selectItem,\n activate(item) {\n selectItem(item)\n if (item.type === 'root' || item.type === 'folder') toggle(item.key)\n },\n addMenu,\n remove,\n isDraggable: item => core.renaming?.key !== item.key && isDraggable(item, core.virtual),\n dragStart,\n dragOver,\n dragLeave(item) {\n // A foreign drag only exists while it is over this tree (no `dragend` reaches here), so leaving a row ends it; the next row's `foreignDragOver` starts it again.\n if (core.drag?.source.type === 'foreign-block') patch({ drag: null })\n else if (core.drag?.hover === item.key) patch({ drag: { ...core.drag, hover: null, verdict: null } })\n },\n dragEnd: () => patch({ drag: null }),\n drop,\n foreignDragOver,\n dropForeign,\n startRename,\n setRenameDraft(text) {\n const r = core.renaming\n if (r) patch({ renaming: { ...r, draft: text, error: renameError(text, r.path, r.base, core.tree) } })\n },\n cancelRename: () => patch({ renaming: null }),\n commitRename,\n blurRename,\n startCreateFolder,\n setFolderDraft(text) {\n const f = core.creatingFolder\n if (f) patch({ creatingFolder: { ...f, draft: text, error: folderError(text, f.parent, core.tree) } })\n },\n cancelCreateFolder: () => patch({ creatingFolder: null }),\n commitCreateFolder,\n dispose() {\n disposed = true\n cl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ACA;EACA;EACA,cAAa,SAAQ,KAAK,UAAU,QAAQ,KAAK,OAAO,YAAY,MAAM,KAAK,OAAO;EACtF;EACA;EACA,UAAU,MAAM;GAEd,IAAI,KAAK,MAAM,OAAO,SAAS,iBAAiB,MAAM,EAAE,MAAM,KAAK,CAAC;QAC/D,IAAI,KAAK,MAAM,UAAU,KAAK,KAAK,MAAM,EAAE,MAAM;IAAE,GAAG,KAAK;IAAM,OAAO;IAAM,SAAS;GAAK,EAAE,CAAC;EACtG;EACA,eAAe,MAAM,EAAE,MAAM,KAAK,CAAC;EACnC;EACA;EACA;EACA;EACA,eAAe,MAAM;GACnB,MAAM,IAAI,KAAK;GACf,IAAI,GAAG,MAAM,EAAE,UAAU;IAAE,GAAG;IAAG,OAAO;IAAM,OAAO,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI;GAAE,EAAE,CAAC;EACvG;EACA,oBAAoB,MAAM,EAAE,UAAU,KAAK,CAAC;EAC5C;EACA;EACA;EACA,eAAe,MAAM;GACnB,MAAM,IAAI,KAAK;GACf,IAAI,GAAG,MAAM,EAAE,gBAAgB;IAAE,GAAG;IAAG,OAAO;IAAM,OAAO,YAAY,MAAM,EAAE,QAAQ,KAAK,IAAI;GAAE,EAAE,CAAC;EACvG;EACA,0BAA0B,MAAM,EAAE,gBAAgB,KAAK,CAAC;EACxD;EACA,UAAU;GACR,WAAW;GACX,aAAa,YAAY;GACzB,gBAAgB;GAChB,KAAK,MAAM,QAAQ,aAAa,KAAK;EACvC;CACF;AACF"}
|
|
@@ -11,6 +11,11 @@ export interface TreeViewModel {
|
|
|
11
11
|
basketFilter: Store<string[]>;
|
|
12
12
|
/** Keys of the open tree items; lasts for the session. Replace, never mutate. */
|
|
13
13
|
expanded: Store<string[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Keys of the closed outline rows (`outline:<block id>`): outline rows are open unless listed here. Lasts for the
|
|
16
|
+
* session; a host may set it, e.g. to show a document with its top Typed blocks closed. Replace, never mutate.
|
|
17
|
+
*/
|
|
18
|
+
collapsedOutline: Store<string[]>;
|
|
14
19
|
/** Opens the items (already open ones are left alone). */
|
|
15
20
|
expand(keys: readonly string[]): void;
|
|
16
21
|
/** Hides (`hidden`) or shows `kind` below the item. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-view-model.js","names":[],"sources":["../../src/tree/tree-view-model.ts"],"sourcesContent":["import type { EditorContext } from '../core/context'\nimport { createStore, type Store } from '../core/store'\nimport { FOLDER_KEY_PREFIX, folderKey, remapFolderPath } from './folder-paths'\n\nconst NODE_FILTERS_KEY = 'tip-tree:node-filters'\nconst BASKET_FILTER_KEY = 'tip-tree:basket-filter'\n\n/** Hidden kind ids per tree item key. */\nexport type NodeFilters = Record<string, string[]>\n\nfunction readStored<T>(key: string, fallback: T, isValid: (value: unknown) => value is T): T {\n try {\n const raw = localStorage.getItem(key)\n if (raw !== null) {\n const value: unknown = JSON.parse(raw)\n if (isValid(value)) return value\n }\n } catch { /* unavailable or corrupt storage: use the default */ }\n return fallback\n}\n\nfunction writeStored(key: string, value: unknown) {\n try {\n localStorage.setItem(key, JSON.stringify(value))\n } catch { /* storage full or blocked: the setting then lasts for this session only */ }\n}\n\nconst isNodeFilters = (value: unknown): value is NodeFilters =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n && Object.values(value).every(kinds => Array.isArray(kinds) && kinds.every(kind => typeof kind === 'string'))\n\nconst isStringList = (value: unknown): value is string[] => Array.isArray(value) && value.every(item => typeof item === 'string')\n\n/** The view state of the file browser; see `createTreeView`. */\nexport interface TreeViewModel {\n /** The kinds hidden below each tree item, by item key. Persists in localStorage. Replace, never mutate. */\n nodeFilters: Store<NodeFilters>\n /** The basket ids whose Typed blocks the tree shows; `[]` = all of them. Persists in localStorage. Replace, never mutate. */\n basketFilter: Store<string[]>\n /** Keys of the open tree items; lasts for the session. Replace, never mutate. */\n expanded: Store<string[]>\n /** Opens the items (already open ones are left alone). */\n expand(keys: readonly string[]): void\n /** Hides (`hidden`) or shows `kind` below the item. */\n setKindHidden(key: string, kind: string, hidden: boolean): void\n clearFilter(key: string): void\n clearAllFilters(): void\n /** Shows (`shown`) or stops showing the Typed blocks of the basket. */\n setBasketShown(id: string, shown: boolean): void\n clearBasketFilter(): void\n /** Follows a folder moved from `from` to `to`: open folder items of it and below it get the new path. */\n followFolderMove(from: string, to: string): void\n}\n\n/**\n * A view model of its own: `nodeFilters` is read from localStorage once and written back on every change (a model that\n * is dropped takes its subscription with it, there is nothing to dispose).\n */\nexport function createTreeView(): TreeViewModel {\n const nodeFilters = createStore<NodeFilters>('window' in globalThis ? readStored<NodeFilters>(NODE_FILTERS_KEY, {}, isNodeFilters) : {})\n nodeFilters.subscribe(value => writeStored(NODE_FILTERS_KEY, value))\n const basketFilter = createStore<string[]>('window' in globalThis ? readStored<string[]>(BASKET_FILTER_KEY, [], isStringList) : [])\n basketFilter.subscribe(value => writeStored(BASKET_FILTER_KEY, value))\n const expanded = createStore<string[]>([])\n return {\n nodeFilters,\n basketFilter,\n expanded,\n expand(keys) {\n const current = expanded.get()\n const missing = keys.filter(key => !current.includes(key))\n if (missing.length) expanded.set([...current, ...missing])\n },\n setKindHidden(key, kind, hidden) {\n const filters = nodeFilters.get()\n const rest = (filters[key] ?? []).filter(id => id !== kind)\n const { [key]: _previous, ...others } = filters\n nodeFilters.set(rest.length || hidden ? { ...others, [key]: hidden ? [...rest, kind] : rest } : others)\n },\n clearFilter(key) {\n const { [key]: _previous, ...others } = nodeFilters.get()\n nodeFilters.set(others)\n },\n setBasketShown(id, shown) {\n const current = basketFilter.get()\n if (current.includes(id) === shown) return\n basketFilter.set(shown ? [...current, id] : current.filter(other => other !== id))\n },\n clearBasketFilter() {\n if (basketFilter.get().length) basketFilter.set([])\n },\n clearAllFilters() {\n nodeFilters.set({})\n },\n followFolderMove(from, to) {\n expanded.set(expanded.get().map(key => (key.startsWith(FOLDER_KEY_PREFIX) ? folderKey(remapFolderPath(key.slice(FOLDER_KEY_PREFIX.length), from, to)) : key)))\n },\n }\n}\n\nconst views = new WeakMap<EditorContext, TreeViewModel>()\n\n/** The view model shared by every tree of one editor context (one app): created on first use, then cached. */\nexport function treeView(ctx: EditorContext): TreeViewModel {\n let view = views.get(ctx)\n if (!view) {\n view = createTreeView()\n views.set(ctx, view)\n }\n return view\n}\n"],"mappings":";;;AAIA,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAK1B,SAAS,WAAc,KAAa,UAAa,SAA4C;CAC3F,IAAI;EACF,MAAM,MAAM,aAAa,QAAQ,GAAG;EACpC,IAAI,QAAQ,MAAM;GAChB,MAAM,QAAiB,KAAK,MAAM,GAAG;GACrC,IAAI,QAAQ,KAAK,GAAG,OAAO;EAC7B;CACF,QAAQ,CAAwD;CAChE,OAAO;AACT;AAEA,SAAS,YAAY,KAAa,OAAgB;CAChD,IAAI;EACF,aAAa,QAAQ,KAAK,KAAK,UAAU,KAAK,CAAC;CACjD,QAAQ,CAA8E;AACxF;AAEA,MAAM,iBAAiB,UACrB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,KAChE,OAAO,OAAO,KAAK,CAAC,CAAC,OAAM,UAAS,MAAM,QAAQ,KAAK,KAAK,MAAM,OAAM,SAAQ,OAAO,SAAS,QAAQ,CAAC;AAE9G,MAAM,gBAAgB,UAAsC,MAAM,QAAQ,KAAK,KAAK,MAAM,OAAM,SAAQ,OAAO,SAAS,QAAQ;;;;;
|
|
1
|
+
{"version":3,"file":"tree-view-model.js","names":[],"sources":["../../src/tree/tree-view-model.ts"],"sourcesContent":["import type { EditorContext } from '../core/context'\nimport { createStore, type Store } from '../core/store'\nimport { FOLDER_KEY_PREFIX, folderKey, remapFolderPath } from './folder-paths'\n\nconst NODE_FILTERS_KEY = 'tip-tree:node-filters'\nconst BASKET_FILTER_KEY = 'tip-tree:basket-filter'\n\n/** Hidden kind ids per tree item key. */\nexport type NodeFilters = Record<string, string[]>\n\nfunction readStored<T>(key: string, fallback: T, isValid: (value: unknown) => value is T): T {\n try {\n const raw = localStorage.getItem(key)\n if (raw !== null) {\n const value: unknown = JSON.parse(raw)\n if (isValid(value)) return value\n }\n } catch { /* unavailable or corrupt storage: use the default */ }\n return fallback\n}\n\nfunction writeStored(key: string, value: unknown) {\n try {\n localStorage.setItem(key, JSON.stringify(value))\n } catch { /* storage full or blocked: the setting then lasts for this session only */ }\n}\n\nconst isNodeFilters = (value: unknown): value is NodeFilters =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n && Object.values(value).every(kinds => Array.isArray(kinds) && kinds.every(kind => typeof kind === 'string'))\n\nconst isStringList = (value: unknown): value is string[] => Array.isArray(value) && value.every(item => typeof item === 'string')\n\n/** The view state of the file browser; see `createTreeView`. */\nexport interface TreeViewModel {\n /** The kinds hidden below each tree item, by item key. Persists in localStorage. Replace, never mutate. */\n nodeFilters: Store<NodeFilters>\n /** The basket ids whose Typed blocks the tree shows; `[]` = all of them. Persists in localStorage. Replace, never mutate. */\n basketFilter: Store<string[]>\n /** Keys of the open tree items; lasts for the session. Replace, never mutate. */\n expanded: Store<string[]>\n /**\n * Keys of the closed outline rows (`outline:<block id>`): outline rows are open unless listed here. Lasts for the\n * session; a host may set it, e.g. to show a document with its top Typed blocks closed. Replace, never mutate.\n */\n collapsedOutline: Store<string[]>\n /** Opens the items (already open ones are left alone). */\n expand(keys: readonly string[]): void\n /** Hides (`hidden`) or shows `kind` below the item. */\n setKindHidden(key: string, kind: string, hidden: boolean): void\n clearFilter(key: string): void\n clearAllFilters(): void\n /** Shows (`shown`) or stops showing the Typed blocks of the basket. */\n setBasketShown(id: string, shown: boolean): void\n clearBasketFilter(): void\n /** Follows a folder moved from `from` to `to`: open folder items of it and below it get the new path. */\n followFolderMove(from: string, to: string): void\n}\n\n/**\n * A view model of its own: `nodeFilters` is read from localStorage once and written back on every change (a model that\n * is dropped takes its subscription with it, there is nothing to dispose).\n */\nexport function createTreeView(): TreeViewModel {\n const nodeFilters = createStore<NodeFilters>('window' in globalThis ? readStored<NodeFilters>(NODE_FILTERS_KEY, {}, isNodeFilters) : {})\n nodeFilters.subscribe(value => writeStored(NODE_FILTERS_KEY, value))\n const basketFilter = createStore<string[]>('window' in globalThis ? readStored<string[]>(BASKET_FILTER_KEY, [], isStringList) : [])\n basketFilter.subscribe(value => writeStored(BASKET_FILTER_KEY, value))\n const expanded = createStore<string[]>([])\n return {\n nodeFilters,\n basketFilter,\n expanded,\n collapsedOutline: createStore<string[]>([]),\n expand(keys) {\n const current = expanded.get()\n const missing = keys.filter(key => !current.includes(key))\n if (missing.length) expanded.set([...current, ...missing])\n },\n setKindHidden(key, kind, hidden) {\n const filters = nodeFilters.get()\n const rest = (filters[key] ?? []).filter(id => id !== kind)\n const { [key]: _previous, ...others } = filters\n nodeFilters.set(rest.length || hidden ? { ...others, [key]: hidden ? [...rest, kind] : rest } : others)\n },\n clearFilter(key) {\n const { [key]: _previous, ...others } = nodeFilters.get()\n nodeFilters.set(others)\n },\n setBasketShown(id, shown) {\n const current = basketFilter.get()\n if (current.includes(id) === shown) return\n basketFilter.set(shown ? [...current, id] : current.filter(other => other !== id))\n },\n clearBasketFilter() {\n if (basketFilter.get().length) basketFilter.set([])\n },\n clearAllFilters() {\n nodeFilters.set({})\n },\n followFolderMove(from, to) {\n expanded.set(expanded.get().map(key => (key.startsWith(FOLDER_KEY_PREFIX) ? folderKey(remapFolderPath(key.slice(FOLDER_KEY_PREFIX.length), from, to)) : key)))\n },\n }\n}\n\nconst views = new WeakMap<EditorContext, TreeViewModel>()\n\n/** The view model shared by every tree of one editor context (one app): created on first use, then cached. */\nexport function treeView(ctx: EditorContext): TreeViewModel {\n let view = views.get(ctx)\n if (!view) {\n view = createTreeView()\n views.set(ctx, view)\n }\n return view\n}\n"],"mappings":";;;AAIA,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAK1B,SAAS,WAAc,KAAa,UAAa,SAA4C;CAC3F,IAAI;EACF,MAAM,MAAM,aAAa,QAAQ,G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AM,QAAQ,QAAQ,QAAQ,CAAC,EAAA,CAAG,QAAO,OAAM,OAAO,IAAI;GAC1D,MAAM,GAAG,MAAM,WAAW,GAAG,WAAW;GACxC,YAAY,IAAI,KAAK,UAAU,SAAS;IAAE,GAAG;KAAS,MAAM,SAAS,CAAC,GAAG,MAAM,IAAI,IAAI;GAAK,IAAI,MAAM;EACxG;EACA,YAAY,KAAK;GACf,MAAM,GAAG,MAAM,WAAW,GAAG,WAAW,YAAY,IAAI;GACxD,YAAY,IAAI,MAAM;EACxB;EACA,eAAe,IAAI,OAAO;GACxB,MAAM,UAAU,aAAa,IAAI;GACjC,IAAI,QAAQ,SAAS,EAAE,MAAM,OAAO;GACpC,aAAa,IAAI,QAAQ,CAAC,GAAG,SAAS,EAAE,IAAI,QAAQ,QAAO,UAAS,UAAU,EAAE,CAAC;EACnF;EACA,oBAAoB;GAClB,IAAI,aAAa,IAAI,CAAC,CAAC,QAAQ,aAAa,IAAI,CAAC,CAAC;EACpD;EACA,kBAAkB;GAChB,YAAY,IAAI,CAAC,CAAC;EACpB;EACA,iBAAiB,MAAM,IAAI;GACzB,SAAS,IAAI,SAAS,IAAI,CAAC,CAAC,KAAI,QAAQ,IAAI,WAAA,SAA4B,IAAI,UAAU,gBAAgB,IAAI,MAAM,kBAAkB,MAAM,GAAG,MAAM,EAAE,CAAC,IAAI,GAAI,CAAC;EAC/J;CACF;AACF;AAEA,MAAM,wBAAQ,IAAI,QAAsC;;AAGxD,SAAgB,SAAS,KAAmC;CAC1D,IAAI,OAAO,MAAM,IAAI,GAAG;CACxB,IAAI,CAAC,MAAM;EACT,OAAO,eAAe;EACtB,MAAM,IAAI,KAAK,IAAI;CACrB;CACA,OAAO;AACT"}
|
package/dist/tree/tree-view.d.ts
CHANGED
|
@@ -3,12 +3,14 @@ import { Ref } from "vue";
|
|
|
3
3
|
//#region src/tree/tree-view.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* The Vue view of the file browser's `TreeViewModel` (shared by every tree of one Vue app): `nodeFilters` (the kinds
|
|
6
|
-
* hidden below each tree item, by item key) persists in localStorage, `expanded` (tree item keys)
|
|
7
|
-
* session;
|
|
6
|
+
* hidden below each tree item, by item key) persists in localStorage, `expanded` (tree item keys) and
|
|
7
|
+
* `collapsedOutline` (the closed outline rows, `outline:<block id>`) last for the session; the refs are replaced, not
|
|
8
|
+
* mutated. Call this from `setup()`.
|
|
8
9
|
*/
|
|
9
10
|
export declare function useTreeView(): {
|
|
10
11
|
nodeFilters: Ref<NodeFilters>;
|
|
11
12
|
expanded: Ref<string[]>;
|
|
13
|
+
collapsedOutline: Ref<string[]>;
|
|
12
14
|
model: TreeViewModel;
|
|
13
15
|
};
|
|
14
16
|
//#endregion
|
package/dist/tree/tree-view.js
CHANGED
|
@@ -4,14 +4,16 @@ import { useWritableStoreRef } from "../vue/store-ref.js";
|
|
|
4
4
|
//#region src/tree/tree-view.ts
|
|
5
5
|
/**
|
|
6
6
|
* The Vue view of the file browser's `TreeViewModel` (shared by every tree of one Vue app): `nodeFilters` (the kinds
|
|
7
|
-
* hidden below each tree item, by item key) persists in localStorage, `expanded` (tree item keys)
|
|
8
|
-
* session;
|
|
7
|
+
* hidden below each tree item, by item key) persists in localStorage, `expanded` (tree item keys) and
|
|
8
|
+
* `collapsedOutline` (the closed outline rows, `outline:<block id>`) last for the session; the refs are replaced, not
|
|
9
|
+
* mutated. Call this from `setup()`.
|
|
9
10
|
*/
|
|
10
11
|
function useTreeView() {
|
|
11
12
|
const model = treeView(useEditorContext());
|
|
12
13
|
return {
|
|
13
14
|
nodeFilters: useWritableStoreRef(model.nodeFilters),
|
|
14
15
|
expanded: useWritableStoreRef(model.expanded),
|
|
16
|
+
collapsedOutline: useWritableStoreRef(model.collapsedOutline),
|
|
15
17
|
model
|
|
16
18
|
};
|
|
17
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-view.js","names":[],"sources":["../../src/tree/tree-view.ts"],"sourcesContent":["import type { Ref } from 'vue'\nimport { useEditorContext } from '../vue/context'\nimport { useWritableStoreRef } from '../vue/store-ref'\nimport { type NodeFilters, treeView, type TreeViewModel } from './tree-view-model'\n\n/**\n * The Vue view of the file browser's `TreeViewModel` (shared by every tree of one Vue app): `nodeFilters` (the kinds\n * hidden below each tree item, by item key) persists in localStorage, `expanded` (tree item keys)
|
|
1
|
+
{"version":3,"file":"tree-view.js","names":[],"sources":["../../src/tree/tree-view.ts"],"sourcesContent":["import type { Ref } from 'vue'\nimport { useEditorContext } from '../vue/context'\nimport { useWritableStoreRef } from '../vue/store-ref'\nimport { type NodeFilters, treeView, type TreeViewModel } from './tree-view-model'\n\n/**\n * The Vue view of the file browser's `TreeViewModel` (shared by every tree of one Vue app): `nodeFilters` (the kinds\n * hidden below each tree item, by item key) persists in localStorage, `expanded` (tree item keys) and\n * `collapsedOutline` (the closed outline rows, `outline:<block id>`) last for the session; the refs are replaced, not\n * mutated. Call this from `setup()`.\n */\nexport function useTreeView(): { nodeFilters: Ref<NodeFilters>, expanded: Ref<string[]>, collapsedOutline: Ref<string[]>, model: TreeViewModel } {\n const model = treeView(useEditorContext())\n return {\n nodeFilters: useWritableStoreRef(model.nodeFilters),\n expanded: useWritableStoreRef(model.expanded),\n collapsedOutline: useWritableStoreRef(model.collapsedOutline),\n model,\n }\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,cAAiI;CAC/I,MAAM,QAAQ,SAAS,iBAAiB,CAAC;CACzC,OAAO;EACL,aAAa,oBAAoB,MAAM,WAAW;EAClD,UAAU,oBAAoB,MAAM,QAAQ;EAC5C,kBAAkB,oBAAoB,MAAM,gBAAgB;EAC5D;CACF;AACF"}
|
|
@@ -71,19 +71,19 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {
|
|
|
71
71
|
editor: import("vue").ComputedRef<Editor | undefined>;
|
|
72
72
|
preset: ComposedEditor<Component>;
|
|
73
73
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
74
|
+
"update:modelValue": (content: JSONContent) => any;
|
|
75
|
+
ready: (editor: Editor) => any;
|
|
74
76
|
settingsOpen: (tab?: string | undefined) => any;
|
|
75
77
|
"update:sidebarOpen": (value: boolean) => any;
|
|
76
78
|
"update:commentsOpen": (value: boolean) => any;
|
|
77
|
-
"update:modelValue": (content: JSONContent) => any;
|
|
78
|
-
ready: (editor: Editor) => any;
|
|
79
79
|
metadataCreate: (list: string, item: MetadataItem) => any;
|
|
80
80
|
contentError: (error: Error) => any;
|
|
81
81
|
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
82
|
+
"onUpdate:modelValue"?: ((content: JSONContent) => any) | undefined;
|
|
83
|
+
onReady?: ((editor: Editor) => any) | undefined;
|
|
82
84
|
onSettingsOpen?: ((tab?: string | undefined) => any) | undefined;
|
|
83
85
|
"onUpdate:sidebarOpen"?: ((value: boolean) => any) | undefined;
|
|
84
86
|
"onUpdate:commentsOpen"?: ((value: boolean) => any) | undefined;
|
|
85
|
-
"onUpdate:modelValue"?: ((content: JSONContent) => any) | undefined;
|
|
86
|
-
onReady?: ((editor: Editor) => any) | undefined;
|
|
87
87
|
onMetadataCreate?: ((list: string, item: MetadataItem) => any) | undefined;
|
|
88
88
|
onContentError?: ((error: Error) => any) | undefined;
|
|
89
89
|
}>, {
|
|
@@ -41,19 +41,19 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {
|
|
|
41
41
|
editor: import("vue").ComputedRef<Editor | undefined>;
|
|
42
42
|
preset: EditorPreset<Component>;
|
|
43
43
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
44
|
+
"update:modelValue": (content: JSONContent) => any;
|
|
45
|
+
ready: (editor: Editor) => any;
|
|
44
46
|
settingsOpen: (tab?: string | undefined) => any;
|
|
45
47
|
"update:sidebarOpen": (value: boolean) => any;
|
|
46
48
|
"update:commentsOpen": (value: boolean) => any;
|
|
47
|
-
"update:modelValue": (content: JSONContent) => any;
|
|
48
|
-
ready: (editor: Editor) => any;
|
|
49
49
|
metadataCreate: (list: string, item: MetadataItem) => any;
|
|
50
50
|
contentError: (error: Error) => any;
|
|
51
51
|
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
52
|
+
"onUpdate:modelValue"?: ((content: JSONContent) => any) | undefined;
|
|
53
|
+
onReady?: ((editor: Editor) => any) | undefined;
|
|
52
54
|
onSettingsOpen?: ((tab?: string | undefined) => any) | undefined;
|
|
53
55
|
"onUpdate:sidebarOpen"?: ((value: boolean) => any) | undefined;
|
|
54
56
|
"onUpdate:commentsOpen"?: ((value: boolean) => any) | undefined;
|
|
55
|
-
"onUpdate:modelValue"?: ((content: JSONContent) => any) | undefined;
|
|
56
|
-
onReady?: ((editor: Editor) => any) | undefined;
|
|
57
57
|
onMetadataCreate?: ((list: string, item: MetadataItem) => any) | undefined;
|
|
58
58
|
onContentError?: ((error: Error) => any) | undefined;
|
|
59
59
|
}>, {
|
|
@@ -43,19 +43,19 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {
|
|
|
43
43
|
settingsOpen: import("vue").Ref<boolean, boolean>;
|
|
44
44
|
settingsTab: import("vue").Ref<string | undefined, string | undefined>;
|
|
45
45
|
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
46
|
+
"update:modelValue": (content: JSONContent) => any;
|
|
47
|
+
ready: (editor: Editor) => any;
|
|
46
48
|
settingsOpen: (tab?: string | undefined) => any;
|
|
47
49
|
"update:sidebarOpen": (value: boolean) => any;
|
|
48
50
|
"update:commentsOpen": (value: boolean) => any;
|
|
49
|
-
"update:modelValue": (content: JSONContent) => any;
|
|
50
|
-
ready: (editor: Editor) => any;
|
|
51
51
|
metadataCreate: (list: string, item: MetadataItem) => any;
|
|
52
52
|
contentError: (error: Error) => any;
|
|
53
53
|
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
54
|
+
"onUpdate:modelValue"?: ((content: JSONContent) => any) | undefined;
|
|
55
|
+
onReady?: ((editor: Editor) => any) | undefined;
|
|
54
56
|
onSettingsOpen?: ((tab?: string | undefined) => any) | undefined;
|
|
55
57
|
"onUpdate:sidebarOpen"?: ((value: boolean) => any) | undefined;
|
|
56
58
|
"onUpdate:commentsOpen"?: ((value: boolean) => any) | undefined;
|
|
57
|
-
"onUpdate:modelValue"?: ((content: JSONContent) => any) | undefined;
|
|
58
|
-
onReady?: ((editor: Editor) => any) | undefined;
|
|
59
59
|
onMetadataCreate?: ((list: string, item: MetadataItem) => any) | undefined;
|
|
60
60
|
onContentError?: ((error: Error) => any) | undefined;
|
|
61
61
|
}>, {
|
package/dist/vue/compose.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { coreUiFeature } from "../core/core-feature.js";
|
|
2
|
+
import { composeEditor as composeEditor$1 } from "../presets/compose.js";
|
|
2
3
|
import { bulletsTransform, summaryTransform } from "../integrations/composite-ai/transfer-transforms.js";
|
|
3
4
|
import { compositeAiFeature } from "../integrations/composite-ai/index.js";
|
|
4
5
|
import { transcriptAiFeature } from "../integrations/transcript-ai/index.js";
|
|
5
|
-
import { composeEditor as composeEditor$1 } from "../presets/compose.js";
|
|
6
6
|
import { mediaFeature } from "../features/media/vue.js";
|
|
7
7
|
import _sfc_main from "./components/EditorCommandPalette.js";
|
|
8
8
|
import { aiFeature } from "../features/ai/vue.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecsplico/editor",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vue and React editor library on TipTap v3 (Vue: Nuxt UI; React: shadcn/ui): framework-free features with Vue and React bindings, simple and advanced presets, tree-shakeable entries. Built ESM with type declarations.",
|
|
6
6
|
"license": "MIT",
|