@dou-ui/editor 0.1.0-alpha.3 → 0.1.0-alpha.30

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.
Files changed (159) hide show
  1. package/dist/collaboration/binding.js +371 -57
  2. package/dist/collaboration/binding.js.map +1 -1
  3. package/dist/collaboration/cursors.js +42 -10
  4. package/dist/collaboration/cursors.js.map +1 -1
  5. package/dist/collaboration/index.js +61 -11
  6. package/dist/collaboration/index.js.map +1 -1
  7. package/dist/collaboration/inline-diff.js +138 -0
  8. package/dist/collaboration/inline-diff.js.map +1 -0
  9. package/dist/collaboration/merged-props.js +152 -0
  10. package/dist/collaboration/merged-props.js.map +1 -0
  11. package/dist/collaboration/order.js +41 -1
  12. package/dist/collaboration/order.js.map +1 -1
  13. package/dist/collaboration/table.js +64 -25
  14. package/dist/collaboration/table.js.map +1 -1
  15. package/dist/collaboration/text.js +213 -1
  16. package/dist/collaboration/text.js.map +1 -1
  17. package/dist/components/block-handle.js.map +1 -1
  18. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +127 -17
  19. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
  20. package/dist/components/slash-choices.js +6 -0
  21. package/dist/components/slash-choices.js.map +1 -0
  22. package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js +56 -0
  23. package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js.map +1 -0
  24. package/dist/components/slash-menu.js.map +1 -1
  25. package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js +185 -20
  26. package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  27. package/dist/core/block-selection.js +32 -4
  28. package/dist/core/block-selection.js.map +1 -1
  29. package/dist/core/blocks.js +21 -3
  30. package/dist/core/blocks.js.map +1 -1
  31. package/dist/core/cjk.js +54 -0
  32. package/dist/core/cjk.js.map +1 -0
  33. package/dist/core/commands.js +125 -13
  34. package/dist/core/commands.js.map +1 -1
  35. package/dist/core/comments.js +85 -3
  36. package/dist/core/comments.js.map +1 -1
  37. package/dist/core/convert.js +3 -3
  38. package/dist/core/convert.js.map +1 -1
  39. package/dist/core/extension.js +6 -2
  40. package/dist/core/extension.js.map +1 -1
  41. package/dist/core/model.js +10 -3
  42. package/dist/core/model.js.map +1 -1
  43. package/dist/core/output.js +26 -10
  44. package/dist/core/output.js.map +1 -1
  45. package/dist/core/prepare.js +12 -5
  46. package/dist/core/prepare.js.map +1 -1
  47. package/dist/core/schema.js.map +1 -1
  48. package/dist/core/transaction.js +19 -4
  49. package/dist/core/transaction.js.map +1 -1
  50. package/dist/define-block.js +8 -4
  51. package/dist/define-block.js.map +1 -1
  52. package/dist/document.js +59 -4
  53. package/dist/document.js.map +1 -1
  54. package/dist/dom.js +109 -13
  55. package/dist/dom.js.map +1 -1
  56. package/dist/editor.js.map +1 -1
  57. package/dist/editor.vue_vue_type_script_setup_true_lang.js +6 -5
  58. package/dist/editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
  59. package/dist/editor2.js.map +1 -1
  60. package/dist/extensions/callout/html.js +5 -4
  61. package/dist/extensions/callout/html.js.map +1 -1
  62. package/dist/extensions/columns/column-picker.js +6 -0
  63. package/dist/extensions/columns/column-picker.js.map +1 -0
  64. package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js +57 -0
  65. package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js.map +1 -0
  66. package/dist/extensions/columns/columns-controls.js +6 -0
  67. package/dist/extensions/columns/columns-controls.js.map +1 -0
  68. package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js +341 -0
  69. package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js.map +1 -0
  70. package/dist/extensions/columns/html.js +34 -0
  71. package/dist/extensions/columns/html.js.map +1 -0
  72. package/dist/extensions/columns/index.js +57 -0
  73. package/dist/extensions/columns/index.js.map +1 -0
  74. package/dist/extensions/columns/keys.js +53 -0
  75. package/dist/extensions/columns/keys.js.map +1 -0
  76. package/dist/extensions/columns/plugin.js +213 -0
  77. package/dist/extensions/columns/plugin.js.map +1 -0
  78. package/dist/extensions/columns/schema.js +58 -0
  79. package/dist/extensions/columns/schema.js.map +1 -0
  80. package/dist/extensions/columns/select-columns.js +6 -0
  81. package/dist/extensions/columns/select-columns.js.map +1 -0
  82. package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js +71 -0
  83. package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js.map +1 -0
  84. package/dist/extensions/editor-kit.js +3 -1
  85. package/dist/extensions/editor-kit.js.map +1 -1
  86. package/dist/extensions/list-html.js +1 -1
  87. package/dist/extensions/list-html.js.map +1 -1
  88. package/dist/extensions/table/plugin.js +33 -1
  89. package/dist/extensions/table/plugin.js.map +1 -1
  90. package/dist/extensions/table/schema.js +5 -1
  91. package/dist/extensions/table/schema.js.map +1 -1
  92. package/dist/extensions/table/table-controls.js.map +1 -1
  93. package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js +80 -9
  94. package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js.map +1 -1
  95. package/dist/extensions/table/view.js +181 -3
  96. package/dist/extensions/table/view.js.map +1 -1
  97. package/dist/flow/board-block.js +6 -0
  98. package/dist/flow/board-block.js.map +1 -0
  99. package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js +659 -0
  100. package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js.map +1 -0
  101. package/dist/flow/board.js +221 -0
  102. package/dist/flow/board.js.map +1 -0
  103. package/dist/flow/index.js +173 -0
  104. package/dist/flow/index.js.map +1 -0
  105. package/dist/index.js +3 -2
  106. package/dist/index.js.map +1 -1
  107. package/dist/locale.js +78 -6
  108. package/dist/locale.js.map +1 -1
  109. package/dist/markdown/cjk-friendly.js +62 -0
  110. package/dist/markdown/cjk-friendly.js.map +1 -0
  111. package/dist/markdown/index.js +4 -3
  112. package/dist/markdown/index.js.map +1 -1
  113. package/dist/style.css +1 -1
  114. package/dist/style.js +2 -0
  115. package/dist/types/collaboration/binding.d.ts +12 -0
  116. package/dist/types/collaboration/cursors.d.ts +29 -1
  117. package/dist/types/collaboration/index.d.ts +53 -6
  118. package/dist/types/collaboration/inline-diff.d.ts +9 -0
  119. package/dist/types/collaboration/merged-props.d.ts +20 -0
  120. package/dist/types/collaboration/order.d.ts +5 -0
  121. package/dist/types/collaboration/table.d.ts +5 -1
  122. package/dist/types/collaboration/text.d.ts +20 -0
  123. package/dist/types/components/slash-choices.vue.d.ts +18 -0
  124. package/dist/types/core/blocks.d.ts +10 -0
  125. package/dist/types/core/cjk.d.ts +23 -0
  126. package/dist/types/core/commands.d.ts +17 -2
  127. package/dist/types/core/comments.d.ts +39 -3
  128. package/dist/types/core/convert.d.ts +10 -2
  129. package/dist/types/core/extension.d.ts +58 -4
  130. package/dist/types/core/model.d.ts +6 -1
  131. package/dist/types/core/prepare.d.ts +16 -2
  132. package/dist/types/core/schema.d.ts +1 -1
  133. package/dist/types/core/transaction.d.ts +6 -0
  134. package/dist/types/define-block.d.ts +16 -4
  135. package/dist/types/document.d.ts +5 -2
  136. package/dist/types/dom.d.ts +41 -4
  137. package/dist/types/editor.d.ts +15 -1
  138. package/dist/types/editor.vue.d.ts +24 -0
  139. package/dist/types/extensions/columns/column-picker.vue.d.ts +10 -0
  140. package/dist/types/extensions/columns/columns-controls.vue.d.ts +3 -0
  141. package/dist/types/extensions/columns/html.d.ts +10 -0
  142. package/dist/types/extensions/columns/index.d.ts +9 -0
  143. package/dist/types/extensions/columns/keys.d.ts +6 -0
  144. package/dist/types/extensions/columns/plugin.d.ts +28 -0
  145. package/dist/types/extensions/columns/schema.d.ts +17 -0
  146. package/dist/types/extensions/columns/select-columns.vue.d.ts +13 -0
  147. package/dist/types/extensions/editor-kit.d.ts +4 -1
  148. package/dist/types/extensions/table/view.d.ts +36 -2
  149. package/dist/types/flow/board-block.vue.d.ts +16 -0
  150. package/dist/types/flow/board.d.ts +53 -0
  151. package/dist/types/flow/index.d.ts +65 -0
  152. package/dist/types/index.d.ts +29 -4
  153. package/dist/types/locale.d.ts +34 -0
  154. package/dist/types/markdown/cjk-friendly.d.ts +6 -0
  155. package/dist/types/markdown/index.d.ts +11 -4
  156. package/dist/types/use-comments.d.ts +1 -0
  157. package/dist/use-comments.js +63 -9
  158. package/dist/use-comments.js.map +1 -1
  159. package/package.json +14 -5
@@ -0,0 +1,13 @@
1
+ import type { Block } from '../../core/model';
2
+ /**
3
+ * In the block menu of a block inside columns: select the whole set of
4
+ * columns, to move, copy or remove it with the handle or the keyboard;
5
+ * and, when the columns differ in width, make them even (where the bar
6
+ * between them can't be dragged, e.g. on a touch screen).
7
+ */
8
+ type __VLS_Props = {
9
+ block: Block;
10
+ };
11
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
12
+ declare const _default: typeof __VLS_export;
13
+ export default _default;
@@ -4,6 +4,7 @@ import { align } from './align';
4
4
  import { callout } from './callout';
5
5
  import { colors } from './colors';
6
6
  import { codeBlock, type CodeBlockOptions } from './code-block';
7
+ import { columns } from './columns';
7
8
  import { formatting, link } from './formatting';
8
9
  import { lists } from './lists';
9
10
  import { table } from './table';
@@ -22,6 +23,8 @@ export interface EditorKitOptions {
22
23
  toggle?: boolean;
23
24
  callout?: boolean;
24
25
  table?: boolean;
26
+ /** Blocks side by side in columns. */
27
+ columns?: boolean;
25
28
  formatting?: boolean;
26
29
  link?: boolean;
27
30
  /** Text and background colors. */
@@ -34,4 +37,4 @@ export interface EditorKitOptions {
34
37
  * it out, e.g. `editorKit({ codeBlock: false })`.
35
38
  */
36
39
  export declare function editorKit(options?: EditorKitOptions): EditorExtension[];
37
- export { align, callout, colors, codeBlock, divider, formatting, heading, link, lists, paragraph, quote, table, toggle, };
40
+ export { align, callout, colors, codeBlock, columns, divider, formatting, heading, link, lists, paragraph, quote, table, toggle, };
@@ -4,10 +4,44 @@ import type { NodeView, ViewMutationRecord } from 'prosemirror-view';
4
4
  /** The narrowest a column gets, without a width of its own and when resized. */
5
5
  export declare const CELL_MIN_WIDTH = 96;
6
6
  /**
7
- * A table in the editor: a scrolling frame (the block's content element)
8
- * around the table, with a `<colgroup>` that holds the column widths.
7
+ * A table in the editor: an outer frame (`this.dom`, the block's content
8
+ * element), an inner scrolling viewport around the table, and a lightweight
9
+ * custom horizontal scrollbar aligned to the text column's start edge.
10
+ *
11
+ * Keeping the viewport inside the frame lets top-level wide tables scroll into
12
+ * the left reading-width margin while the scrollbar starts flush with the
13
+ * text column, and prevents the edge-fade mask (`is-cut-start` / `is-cut-end`)
14
+ * from fading the ends of the scrollbar itself.
9
15
  */
10
16
  export declare class TableBlockView extends TableView implements NodeView {
17
+ readonly viewport: HTMLDivElement;
18
+ readonly bar: HTMLDivElement;
19
+ readonly thumb: HTMLDivElement;
20
+ private readonly observer;
21
+ private thumbSize;
22
+ private dragging;
23
+ private dragStartX;
24
+ private dragStartScroll;
25
+ private idleTimer;
26
+ private rafId;
27
+ private readonly onScroll;
28
+ private readonly onResize;
29
+ private readonly onBarMouseDown;
30
+ private readonly onTrackDown;
31
+ private readonly onThumbDown;
32
+ private readonly onThumbMove;
33
+ private readonly onThumbUp;
11
34
  constructor(node: PMNode);
35
+ private isRtl;
36
+ private scheduleSync;
37
+ /** Sync edge-fade classes and the custom scrollbar thumb geometry. */
38
+ private sync;
39
+ /** Which sides cut columns off: the table's edges against the viewport's, padding left out. */
40
+ private edges;
41
+ /** Size and position the custom scrollbar thumb along its track. */
42
+ private updateScrollbar;
43
+ update(node: PMNode): boolean;
44
+ stopEvent(event: Event): boolean;
12
45
  ignoreMutation(record: ViewMutationRecord): boolean;
46
+ destroy(): void;
13
47
  }
@@ -0,0 +1,16 @@
1
+ import type { BlockProps } from '../core/model';
2
+ import { type BoardBlockSettings } from './board';
3
+ type __VLS_Props = {
4
+ block: {
5
+ id: string;
6
+ type: string;
7
+ props: BlockProps;
8
+ };
9
+ updateProps: (props: BlockProps) => void;
10
+ selected: boolean;
11
+ editable: boolean;
12
+ settings: BoardBlockSettings;
13
+ };
14
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
15
+ declare const _default: typeof __VLS_export;
16
+ export default _default;
@@ -0,0 +1,53 @@
1
+ import type { FlowCommentAnchor, FlowDocument, FlowExtension } from '@dou-ui/flow';
2
+ import type { Node as PMNode } from 'prosemirror-model';
3
+ import type { BlockCommentsSpec } from '../core/comments';
4
+ import type { Label } from '../core/extension';
5
+ import type { FlowBlockEditorProps } from './index';
6
+ /** Sent to a block's element to open its fullscreen editor (`Enter` on the selected block). */
7
+ export declare const BOARD_OPEN_EVENT = "dou-editor-board-open";
8
+ /** Heights a block may have in the document, in px. */
9
+ export declare const BOARD_HEIGHT: {
10
+ min: number;
11
+ max: number;
12
+ step: number;
13
+ };
14
+ export interface BoardBlockSettings {
15
+ label: Label;
16
+ extensions: (FlowExtension | FlowExtension[])[];
17
+ editorProps: FlowBlockEditorProps;
18
+ height: number;
19
+ /** When the extensions offer no node to add, offer one with ports (not on a whiteboard, which has its tools). */
20
+ fallbackNode: boolean;
21
+ /** Threads can be started and shown on the nodes and edges, with the document's comments. */
22
+ commentable: boolean;
23
+ }
24
+ /**
25
+ * A block's `board` prop as a flow document; one that is missing or not
26
+ * shaped like one is read as an empty flow (nodes and edges that aren't
27
+ * objects, and edges without valid endpoints, are left out).
28
+ */
29
+ export declare function boardOf(value: unknown): FlowDocument;
30
+ export declare const clampHeight: (height: number) => number;
31
+ /** A block's `height` prop in px: the default when it isn't a positive number. */
32
+ export declare const heightOf: (value: unknown, fallback: number) => number;
33
+ /** What `checkDocument` reports of a block's props: a board or height it would read differently. */
34
+ export declare function checkBoardProps(props: Record<string, unknown>): {
35
+ prop: string;
36
+ message: string;
37
+ }[];
38
+ /**
39
+ * Whether `a` and `b` differ only in the `board` prop of the block `id`:
40
+ * an undo taken from the fullscreen editor must not change anything the
41
+ * person can't see there.
42
+ */
43
+ export declare function onlyBoardChanged(a: PMNode, b: PMNode, id: string): boolean;
44
+ /**
45
+ * Where a thread is on a board, as the flow editor's `getCommentAnchors`
46
+ * gives it: a node, maybe a point on it with its number there, or an edge.
47
+ */
48
+ export type BoardCommentTarget = FlowCommentAnchor;
49
+ /**
50
+ * How a board block keeps comment threads: on its nodes and edges, in their
51
+ * `comments` (and `commentPins`), as a `DouFlowEditor` does.
52
+ */
53
+ export declare const boardComments: BlockCommentsSpec<BoardCommentTarget>;
@@ -0,0 +1,65 @@
1
+ import { type FlowDocument, type FlowEditorProps, type FlowExtension } from '@dou-ui/flow';
2
+ import { type WhiteboardKitOptions } from '@dou-ui/flow/whiteboard';
3
+ import { type BlockOption, type EditorExtension, type Label } from '../core/extension';
4
+ export { boardOf, type BoardCommentTarget } from './board';
5
+ /** The props of the fullscreen editor that a flow block may set. */
6
+ export type FlowBlockEditorProps = Omit<FlowEditorProps, 'extensions' | 'readonly' | 'fitView' | 'comments' | 'author' | 'activeComment' | 'commentable'>;
7
+ export interface FlowBlockOptions {
8
+ /** The block type, e.g. `approvalFlow`; unique among the editor's blocks. */
9
+ type: string;
10
+ /** What the flow is made of, as the editor's `extensions`. `[flowKit()]` by default. */
11
+ extensions?: (FlowExtension | FlowExtension[])[];
12
+ /** More props for the flow editors, e.g. `nodeTypes`, `portTypes` or `direction`. */
13
+ editorProps?: FlowBlockEditorProps;
14
+ /** The block's name: the title of the fullscreen editor, and of its slash menu entry. */
15
+ label: Label;
16
+ /** The slash menu entry, or `false` to leave it out (blocks then come from code or pasting). */
17
+ menu?: (Omit<BlockOption, 'key' | 'type' | 'label'> & {
18
+ key?: string;
19
+ label?: Label;
20
+ }) | false;
21
+ /** The height of a new block in the document, in px. Defaults to `360`. */
22
+ height?: number;
23
+ /**
24
+ * Comment threads on the nodes and edges, with the document's
25
+ * `v-model:comments`, `author` and `commentable`. Defaults to `true`;
26
+ * `false` leaves them out of this block type.
27
+ */
28
+ commentable?: boolean;
29
+ /**
30
+ * How a block is written in `blocksToHTML`, e.g. an `<img>` of a picture
31
+ * of it the app keeps. By default a `<figure>` with its name, which
32
+ * pasting reads back as the block.
33
+ */
34
+ html?: (board: FlowDocument, block: {
35
+ id: string;
36
+ props: Record<string, unknown>;
37
+ }) => string;
38
+ }
39
+ /**
40
+ * A block that holds a flow, drawn with `@dou-ui/flow`: the document shows
41
+ * it whole, and it is edited in a fullscreen editor (double-click, the
42
+ * “Edit” button, or `Enter` while the block is selected). The flow is the
43
+ * block's `board` prop; collaboration merges it node by node.
44
+ *
45
+ * ```ts
46
+ * extensions: [editorKit(), flowBlock({ type: 'approvalFlow', label: '审批流程', extensions: [flowKit(), approval()] })]
47
+ * ```
48
+ *
49
+ * Needs `@dou-ui/flow` and its styles. For a whiteboard, `whiteboardBlock()`.
50
+ */
51
+ export declare function flowBlock(options: FlowBlockOptions): EditorExtension;
52
+ export interface WhiteboardBlockOptions extends Pick<WhiteboardKitOptions, 'upload' | 'onUploadError'>, Pick<FlowBlockOptions, 'height' | 'html' | 'editorProps' | 'commentable'> {
53
+ /** The slash menu entry, or `false` to leave it out. */
54
+ menu?: FlowBlockOptions['menu'];
55
+ }
56
+ /**
57
+ * A whiteboard block: shapes, sticky notes, text, pen strokes, images and
58
+ * connectors, drawn in a fullscreen editor. Pass the `upload` of `image()`
59
+ * so pictures on the board are uploaded too, not kept in the document.
60
+ *
61
+ * ```ts
62
+ * extensions: [editorKit(), whiteboardBlock({ upload })]
63
+ * ```
64
+ */
65
+ export declare function whiteboardBlock(options?: WhiteboardBlockOptions): EditorExtension;
@@ -48,8 +48,10 @@ export declare const DouEditor: import("dou-ui").WithInstall<import("vue").Defin
48
48
  toggle?: string | undefined;
49
49
  callout?: string | undefined;
50
50
  table?: string | undefined;
51
+ columns?: string | undefined;
51
52
  attachment?: string | undefined;
52
53
  embed?: string | undefined;
54
+ whiteboard?: string | undefined;
53
55
  } | undefined;
54
56
  hints?: {
55
57
  paragraph?: string | undefined;
@@ -66,8 +68,10 @@ export declare const DouEditor: import("dou-ui").WithInstall<import("vue").Defin
66
68
  toggle?: string | undefined;
67
69
  callout?: string | undefined;
68
70
  table?: string | undefined;
71
+ columns?: string | undefined;
69
72
  attachment?: string | undefined;
70
73
  embed?: string | undefined;
74
+ whiteboard?: string | undefined;
71
75
  } | undefined;
72
76
  image?: {
73
77
  empty?: string | undefined;
@@ -126,6 +130,14 @@ export declare const DouEditor: import("dou-ui").WithInstall<import("vue").Defin
126
130
  addRow?: string | undefined;
127
131
  addColumn?: string | undefined;
128
132
  } | undefined;
133
+ columns?: {
134
+ pick?: string | undefined;
135
+ count?: string | undefined;
136
+ select?: string | undefined;
137
+ resize?: string | undefined;
138
+ even?: string | undefined;
139
+ column?: string | undefined;
140
+ } | undefined;
129
141
  colors?: {
130
142
  label?: string | undefined;
131
143
  text?: string | undefined;
@@ -166,6 +178,18 @@ export declare const DouEditor: import("dou-ui").WithInstall<import("vue").Defin
166
178
  edit?: string | undefined;
167
179
  cancel?: string | undefined;
168
180
  } | undefined;
181
+ board?: {
182
+ empty?: string | undefined;
183
+ start?: string | undefined;
184
+ edit?: string | undefined;
185
+ view?: string | undefined;
186
+ resize?: string | undefined;
187
+ addNode?: string | undefined;
188
+ searchNodes?: string | undefined;
189
+ noNodes?: string | undefined;
190
+ node?: string | undefined;
191
+ emptyFlow?: string | undefined;
192
+ } | undefined;
169
193
  noResults?: string | undefined;
170
194
  addBlock?: string | undefined;
171
195
  dragHandle?: string | undefined;
@@ -210,13 +234,13 @@ export type { EditorComments, EditorContext, EditorEmits, EditorExpose, EditorLi
210
234
  export { EditorTransaction } from './core/transaction';
211
235
  export type { BlockEdge, BlockPatch, BlockPlacement, EditorTransactionMeta, } from './core/transaction';
212
236
  export type { BlockChanges } from './core/changes';
213
- export type { CommentAnchor, CommentRange } from './core/comments';
237
+ export type { BlockCommentAnchor, BlockCommentsSpec, CommentAnchor, CommentRange, } from './core/comments';
214
238
  export { editorLocales, useEditorMessages } from './locale';
215
239
  export type { EditorMessages, EditorMessagesOverride } from './locale';
216
240
  export { filterOptions } from './catalog';
217
241
  export { defineEditorExtension, labelOf } from './core/extension';
218
- export type { BlockOption, CommentsProvider, EditorExtension, EditorExtensionContext, FormatOption, HistoryProvider, Label, MountComponent, ResolvedEditorExtensions, } from './core/extension';
219
- export { align, callout, codeBlock, colors, divider, formatting, heading, link, lists, paragraph, quote, editorKit, table, toggle, } from './extensions/editor-kit';
242
+ export type { BlockOption, BlockOptionChoice, BlockOptionChoices, BlockOptionChoicesEmits, BlockOptionChoicesProps, CommentsProvider, EditorExtension, EditorExtensionContext, FormatOption, HistoryProvider, Label, MountComponent, ResolvedEditorExtensions, } from './core/extension';
243
+ export { align, callout, codeBlock, colors, columns, divider, formatting, heading, link, lists, paragraph, quote, editorKit, table, toggle, } from './extensions/editor-kit';
220
244
  export type { CalloutTone } from './extensions/callout';
221
245
  export { setHighlight, setTextColor, textColors } from './extensions/colors';
222
246
  export type { TextColor } from './extensions/colors';
@@ -253,7 +277,8 @@ export { contentDOM, createSchema, isSafeHref, textBlock } from './core/schema';
253
277
  export { duplicateBlocks, insertBlockAfter, liftBlocks, swapBlocks, moveRangeTo, setBlockType, sinkBlocks, } from './core/commands';
254
278
  export { clearBlockSelection, getBlockSelection, selectBlocks } from './core/block-selection';
255
279
  export { isRemote } from './core/plugins';
256
- export { blocksToHTML, htmlToBlocks } from './core/convert';
280
+ export { blocksToHTML, htmlToBlocks, type HTMLToBlocksOptions } from './core/convert';
281
+ export type { DOMParserLike } from './core/prepare';
257
282
  export type { EditorExtensionList } from './core/convert';
258
283
  export { escapeHTML, escapeMarkdown, indentLines } from './core/output';
259
284
  export type { BlockOutput, BlockOutputContext, EditorExtensionOutput, InlineOutput, MarkdownBlockContext, MarkOutput, } from './core/output';
@@ -19,8 +19,10 @@ export interface EditorMessages {
19
19
  toggle: string;
20
20
  callout: string;
21
21
  table: string;
22
+ columns: string;
22
23
  attachment: string;
23
24
  embed: string;
25
+ whiteboard: string;
24
26
  };
25
27
  /** Short descriptions in the slash menu. */
26
28
  hints: {
@@ -38,8 +40,10 @@ export interface EditorMessages {
38
40
  toggle: string;
39
41
  callout: string;
40
42
  table: string;
43
+ columns: string;
41
44
  attachment: string;
42
45
  embed: string;
46
+ whiteboard: string;
43
47
  };
44
48
  /** The image block. */
45
49
  image: {
@@ -103,6 +107,21 @@ export interface EditorMessages {
103
107
  addRow: string;
104
108
  addColumn: string;
105
109
  };
110
+ /** Columns: the picker in the slash menu, the block menu entry, the resize bar. */
111
+ columns: {
112
+ /** The title of the picker for the number of columns. */
113
+ pick: string;
114
+ /** A number of columns; `{count}` is replaced with it. */
115
+ count: string;
116
+ /** Selects the whole set of columns a block is in. */
117
+ select: string;
118
+ /** The bar between two columns. */
119
+ resize: string;
120
+ /** Makes every column of the set as wide as the others. */
121
+ even: string;
122
+ /** A column, for screen readers; `{index}` and `{count}` are replaced. */
123
+ column: string;
124
+ };
106
125
  /** The color menu of the formatting toolbar. */
107
126
  colors: {
108
127
  label: string;
@@ -148,6 +167,21 @@ export interface EditorMessages {
148
167
  edit: string;
149
168
  cancel: string;
150
169
  };
170
+ /** Blocks holding a whiteboard or a flow (`@dou-ui/editor/flow`). */
171
+ board: {
172
+ empty: string;
173
+ start: string;
174
+ edit: string;
175
+ view: string;
176
+ resize: string;
177
+ /** The button that adds a node to a flow, and the name of the node a flow block offers. */
178
+ addNode: string;
179
+ searchNodes: string;
180
+ noNodes: string;
181
+ node: string;
182
+ /** On an empty flow in the fullscreen editor. */
183
+ emptyFlow: string;
184
+ };
151
185
  noResults: string;
152
186
  addBlock: string;
153
187
  dragHandle: string;
@@ -0,0 +1,6 @@
1
+ import type MarkdownIt from 'markdown-it';
2
+ /**
3
+ * markdown-it plugin implementing the CommonMark CJK-friendly emphasis and
4
+ * GFM strikethrough delimiter flanking rules (`tats-u/markdown-cjk-friendly`).
5
+ */
6
+ export declare function cjkFriendly(md: MarkdownIt): void;
@@ -1,14 +1,21 @@
1
1
  import { type EditorExtensionList } from '../core/convert';
2
2
  import type { Block, PartialBlock } from '../core/model';
3
+ import { type DOMParserLike } from '../core/prepare';
4
+ export type { DOMParserLike };
3
5
  export interface MarkdownToBlocksOptions {
4
6
  /**
5
- * Turns Markdown into HTML. Defaults to markdown-it with HTML allowed
6
- * (the HTML is read like pasted HTML, so only what the extensions know
7
- * is kept); pass your own to add syntax.
7
+ * Turns Markdown into HTML. Defaults to markdown-it with HTML allowed and
8
+ * CJK-friendly emphasis/strikethrough rules (the HTML is read like pasted
9
+ * HTML, so only what the extensions know is kept); pass your own to add syntax.
8
10
  */
9
11
  render?: (markdown: string) => string;
12
+ /**
13
+ * Reads the HTML. Defaults to the global `DOMParser`; where there is none
14
+ * (Node, Bun), pass one from a DOM library such as happy-dom or linkedom.
15
+ */
16
+ domParser?: DOMParserLike;
10
17
  }
11
18
  /** Write blocks as Markdown (CommonMark with GitHub's extensions). Works without a browser. */
12
19
  export declare function blocksToMarkdown(blocks: PartialBlock[], extensions: EditorExtensionList): string;
13
- /** Read Markdown as blocks. Needs `DOMParser` (a browser, or a DOM library). */
20
+ /** Read Markdown as blocks. Needs a `DOMParser`: the browser's, or `options.domParser`. */
14
21
  export declare function markdownToBlocks(markdown: string, extensions: EditorExtensionList, options?: MarkdownToBlocksOptions): Block[];
@@ -13,5 +13,6 @@ export declare function useEditorComments(options: {
13
13
  comments: EditorComments;
14
14
  plugin: import("prosemirror-state").Plugin<import("./core/comments").CommentPluginState>;
15
15
  anchors: () => Record<string, CommentAnchor | null>;
16
+ scrollToComment: (id: string, scrollOptions?: ScrollIntoViewOptions) => boolean;
16
17
  };
17
18
  export {};
@@ -1,6 +1,7 @@
1
1
  import { anchorComment, commentAnchors, commentPlugin, commentsAt, setPendingComment, unanchorComment } from "./core/comments.js";
2
- import { applyCommentAction } from "dou-ui";
3
- import { computed, shallowRef, watch } from "vue";
2
+ import { toggleKey } from "./extensions/toggle/state.js";
3
+ import { applyCommentAction, useReducedMotion } from "dou-ui";
4
+ import { computed, nextTick, shallowRef, watch } from "vue";
4
5
  import { TextSelection } from "prosemirror-state";
5
6
  // src/use-comments.ts
6
7
  /** The selected text in a read-only editor, which keeps no selection of its own. */
@@ -34,9 +35,19 @@ function hasText(state, range) {
34
35
  function useEditorComments(options) {
35
36
  const { props, emit, view, provider } = options;
36
37
  const threads = computed(() => provider?.threads.value ?? props.comments ?? []);
38
+ let latestThreads = null;
39
+ watch(() => props.comments, () => {
40
+ latestThreads = null;
41
+ }, { flush: "sync" });
42
+ const currentThreads = () => {
43
+ const value = threads.value;
44
+ return latestThreads ?? value;
45
+ };
37
46
  const enabled = computed(() => !!provider || props.comments !== void 0);
38
47
  const writable = computed(() => enabled.value && !!props.author && props.commentable !== false);
39
48
  const known = computed(() => new Set(threads.value.map((thread) => thread.id)));
49
+ const currentKnown = () => latestThreads ? new Set(latestThreads.map((thread) => thread.id)) : known.value;
50
+ const reducedMotion = useReducedMotion();
40
51
  if (provider) watch(provider.threads, (value) => emit("update:comments", [...value]), { immediate: true });
41
52
  const innerActive = shallowRef(null);
42
53
  const active = computed(() => props.activeComment === void 0 ? innerActive.value : props.activeComment);
@@ -83,15 +94,20 @@ function useEditorComments(options) {
83
94
  if (current && pending.value) setPendingComment(current, null);
84
95
  open(null);
85
96
  }
86
- function apply(action) {
97
+ function apply(action, how = {}) {
87
98
  const current = view.value;
88
- if (action.type === "create") {
99
+ if (action.type === "create" && !how.anchored) {
89
100
  const range = pending.value;
90
101
  if (!current || !range) return;
91
102
  anchorComment(current, range, action.thread.id);
92
103
  } else if (current && action.type === "remove") unanchorComment(current, action.threadId);
93
104
  if (provider) provider.apply(action);
94
- else emit("update:comments", applyCommentAction(threads.value, action));
105
+ else {
106
+ const next = applyCommentAction(currentThreads(), action);
107
+ if (!latestThreads) nextTick(() => latestThreads = null);
108
+ latestThreads = next;
109
+ emit("update:comments", next);
110
+ }
95
111
  emit("commentAction", action);
96
112
  if (action.type === "create") {
97
113
  open(action.thread.id);
@@ -99,11 +115,11 @@ function useEditorComments(options) {
99
115
  } else if (action.type === "remove" || action.type === "resolve") open(null);
100
116
  }
101
117
  const isOpen = (id) => {
102
- const thread = threads.value.find((item) => item.id === id);
118
+ const thread = currentThreads().find((item) => item.id === id);
103
119
  return !!thread && !thread.resolved;
104
120
  };
105
121
  const plugin = commentPlugin({
106
- known: () => enabled.value ? known.value : null,
122
+ known: () => enabled.value ? currentKnown() : null,
107
123
  onClick: (ids) => {
108
124
  if (pending.value && view.value) setPendingComment(view.value, null);
109
125
  open(ids.find(isOpen) ?? null);
@@ -115,7 +131,44 @@ function useEditorComments(options) {
115
131
  });
116
132
  function anchors() {
117
133
  const found = view.value ? commentAnchors(view.value.state.doc) : /* @__PURE__ */ new Map();
118
- return Object.fromEntries(threads.value.map((thread) => [thread.id, found.get(thread.id) ?? null]));
134
+ return Object.fromEntries(currentThreads().map((thread) => [thread.id, found.get(thread.id) ?? null]));
135
+ }
136
+ function scrollToComment(id, scrollOptions) {
137
+ const current = view.value;
138
+ if (!current || !enabled.value) return false;
139
+ const anchor = anchors()[id];
140
+ if (!anchor) return false;
141
+ const toggleState = toggleKey.getState(current.state);
142
+ if (toggleState?.closed.size) {
143
+ const $pos = current.state.doc.resolve(anchor.from);
144
+ for (let depth = $pos.depth - 1; depth > 0; depth--) {
145
+ if ($pos.node(depth).type.name !== "blockGroup") continue;
146
+ const blockId = $pos.node(depth - 1).attrs.id;
147
+ if (blockId && toggleState.closed.has(blockId)) current.dispatch(current.state.tr.setMeta(toggleKey, blockId).setMeta("addToHistory", false));
148
+ }
149
+ }
150
+ let target = null;
151
+ if (!anchor.type) {
152
+ target = current.dom.querySelector(`[data-comment="${CSS.escape(id)}"]`);
153
+ if (!target) {
154
+ const at = current.domAtPos(anchor.from).node;
155
+ target = at instanceof HTMLElement ? at : at.parentElement;
156
+ }
157
+ }
158
+ if (!target && anchor.block) target = current.dom.querySelector(`[data-block-id="${CSS.escape(anchor.block)}"]`);
159
+ if (!target) {
160
+ const dom = current.nodeDOM(anchor.from);
161
+ if (dom instanceof HTMLElement) target = dom;
162
+ }
163
+ if (!target) return false;
164
+ const behavior = scrollOptions?.behavior === "smooth" && reducedMotion.value ? "auto" : scrollOptions?.behavior ?? (reducedMotion.value ? "auto" : "smooth");
165
+ target.scrollIntoView?.({
166
+ block: "center",
167
+ inline: "nearest",
168
+ ...scrollOptions,
169
+ behavior
170
+ });
171
+ return true;
119
172
  }
120
173
  return {
121
174
  comments: {
@@ -133,7 +186,8 @@ function useEditorComments(options) {
133
186
  close
134
187
  },
135
188
  plugin,
136
- anchors
189
+ anchors,
190
+ scrollToComment
137
191
  };
138
192
  }
139
193
  export { useEditorComments };
@@ -1 +1 @@
1
- {"version":3,"file":"use-comments.js","names":[],"sources":["../src/use-comments.ts"],"sourcesContent":["import { applyCommentAction, type CommentAction, type CommentThread } from 'dou-ui'\nimport { TextSelection, type EditorState } from 'prosemirror-state'\nimport type { EditorView } from 'prosemirror-view'\nimport { computed, shallowRef, watch, type ShallowRef } from 'vue'\nimport {\n anchorComment,\n commentAnchors,\n commentsAt,\n commentPlugin,\n setPendingComment,\n unanchorComment,\n type CommentAnchor,\n type CommentRange,\n} from './core/comments'\nimport type { CommentsProvider } from './core/extension'\nimport type { EditorComments, EditorEmits, EditorProps } from './editor'\n\ntype Emit = <K extends keyof EditorEmits>(event: K, ...args: EditorEmits[K]) => void\n\n/** The selected text in a read-only editor, which keeps no selection of its own. */\nfunction domSelection(view: EditorView): CommentRange | null {\n const selection = view.dom.ownerDocument.getSelection()\n if (!selection || selection.isCollapsed || !selection.rangeCount) return null\n const range = selection.getRangeAt(0)\n if (!view.dom.contains(range.startContainer) || !view.dom.contains(range.endContainer))\n return null\n try {\n const from = view.posAtDOM(range.startContainer, range.startOffset)\n const to = view.posAtDOM(range.endContainer, range.endOffset)\n return to > from ? { from, to } : null\n } catch {\n return null\n }\n}\n\n/** Whether a range holds text a thread can be about: not only a divider, not in code. */\nfunction hasText(state: EditorState, range: CommentRange) {\n let text = false\n state.doc.nodesBetween(range.from, range.to, (node) => {\n if (text) return false\n if (!node.isTextblock) return true\n text = !node.type.spec.code && node.content.size > 0\n return false\n })\n return text\n}\n\nexport function useEditorComments(options: {\n props: EditorProps\n emit: Emit\n view: ShallowRef<EditorView | null>\n provider: CommentsProvider | null\n}) {\n const { props, emit, view, provider } = options\n\n const threads = computed<readonly CommentThread[]>(\n () => provider?.threads.value ?? props.comments ?? [],\n )\n const enabled = computed(() => !!provider || props.comments !== undefined)\n const writable = computed(() => enabled.value && !!props.author && props.commentable !== false)\n const known = computed(() => new Set(threads.value.map((thread) => thread.id)))\n\n // the shared document's threads, mirrored to `v-model:comments`\n if (provider)\n watch(provider.threads, (value) => emit('update:comments', [...value]), { immediate: true })\n\n const innerActive = shallowRef<string | null>(null)\n const active = computed(() =>\n props.activeComment === undefined ? innerActive.value : props.activeComment,\n )\n function open(id: string | null) {\n if (id === active.value) return\n innerActive.value = id\n emit('update:activeComment', id)\n }\n\n const pending = shallowRef<CommentRange | null>(null)\n\n function selection(): CommentRange | null {\n const current = view.value\n if (!current) return null\n const range = current.editable\n ? current.state.selection instanceof TextSelection && !current.state.selection.empty\n ? { from: current.state.selection.from, to: current.state.selection.to }\n : null\n : domSelection(current)\n return range && hasText(current.state, range) ? range : null\n }\n\n const focusRequest = shallowRef(0)\n\n /** The open thread the cursor is in, innermost first. */\n function threadAtCursor(): string | null {\n const current = view.value\n if (!current) return null\n const ids = commentsAt(current.state, current.state.selection.from)\n return ids.find((id) => isOpen(id)) ?? null\n }\n\n function start(): boolean {\n const current = view.value\n if (!current || !enabled.value) return false\n const range = selection()\n if (!range) {\n // on commented text: open its thread, ready to reply\n const id = threadAtCursor()\n if (!id) return false\n open(id)\n focusRequest.value++\n return true\n }\n if (!writable.value) return false\n open(null)\n setPendingComment(current, range)\n return true\n }\n\n function close() {\n const current = view.value\n if (current && pending.value) setPendingComment(current, null)\n open(null)\n }\n\n function apply(action: CommentAction) {\n const current = view.value\n if (action.type === 'create') {\n const range = pending.value\n if (!current || !range) return\n anchorComment(current, range, action.thread.id)\n } else if (current && action.type === 'remove') unanchorComment(current, action.threadId)\n if (provider) provider.apply(action)\n else emit('update:comments', applyCommentAction(threads.value, action))\n emit('commentAction', action)\n if (action.type === 'create') {\n open(action.thread.id)\n focusRequest.value++\n } else if (action.type === 'remove' || action.type === 'resolve') open(null)\n }\n\n const isOpen = (id: string) => {\n const thread = threads.value.find((item) => item.id === id)\n return !!thread && !thread.resolved\n }\n\n const plugin = commentPlugin({\n known: () => (enabled.value ? known.value : null),\n onClick: (ids) => {\n if (pending.value && view.value) setPendingComment(view.value, null)\n open(ids.find(isOpen) ?? null)\n },\n // selecting other text (the formatting toolbar shows) closes an open thread\n onSelect: () => {\n if (!pending.value) open(null)\n },\n onPending: (range) => (pending.value = range),\n })\n\n function anchors(): Record<string, CommentAnchor | null> {\n const found = view.value ? commentAnchors(view.value.state.doc) : new Map()\n return Object.fromEntries(\n threads.value.map((thread) => [thread.id, found.get(thread.id) ?? null]),\n )\n }\n\n const comments: EditorComments = {\n enabled,\n writable,\n threads,\n author: computed(() => props.author),\n active,\n pending,\n focusRequest,\n selection,\n start,\n apply,\n open,\n close,\n }\n\n return { comments, plugin, anchors }\n}\n"],"mappings":";;;;;;AAoBA,SAAS,aAAa,MAAuC;CAC3D,MAAM,YAAY,KAAK,IAAI,cAAc,aAAa;CACtD,IAAI,CAAC,aAAa,UAAU,eAAe,CAAC,UAAU,YAAY,OAAO;CACzE,MAAM,QAAQ,UAAU,WAAW,CAAC;CACpC,IAAI,CAAC,KAAK,IAAI,SAAS,MAAM,cAAc,KAAK,C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,UAAU,gBAAgB,SAAS,OAAO,QAAQ;EACxF,IAAI,UAAU,SAAS,MAAM,MAAM;OAC9B,KAAK,mBAAmB,mBAAmB,QAAQ,OAAO,MAAM,CAAC;EACtE,KAAK,iBAAiB,MAAM;EAC5B,IAAI,OAAO,SAAS,UAAU;GAC5B,KAAK,OAAO,OAAO,EAAE;GACrB,aAAa;EACf,OAAO,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,WAAW,KAAK,IAAI;CAC7E;CAEA,MAAM,UAAU,OAAe;EAC7B,MAAM,SAAS,QAAQ,MAAM,MAAM,SAAS,KAAK,OAAO,EAAE;EAC1D,OAAO,CAAC,CAAC,UAAU,CAAC,OAAO;CAC7B;CAEA,MAAM,SAAS,cAAc;EAC3B,aAAc,QAAQ,QAAQ,MAAM,QAAQ;EAC5C,UAAU,QAAQ;GAChB,IAAI,QAAQ,SAAS,KAAK,OAAO,kBAAkB,KAAK,OAAO,IAAI;GACnE,KAAK,IAAI,KAAK,MAAM,KAAK,IAAI;EAC/B;EAEA,gBAAgB;GACd,IAAI,CAAC,QAAQ,OAAO,KAAK,IAAI;EAC/B;EACA,YAAY,UAAW,QAAQ,QAAQ;CACzC,CAAC;CAED,SAAS,UAAgD;EACvD,MAAM,QAAQ,KAAK,QAAQ,eAAe,KAAK,MAAM,MAAM,GAAG,oBAAI,IAAI,IAAI;EAC1E,OAAO,OAAO,YACZ,QAAQ,MAAM,KAAK,WAAW,CAAC,OAAO,IAAI,MAAM,IAAI,OAAO,EAAE,KAAK,IAAI,CAAC,CACzE;CACF;CAiBA,OAAO;EAAE,UAAA;GAdP;GACA;GACA;GACA,QAAQ,eAAe,MAAM,MAAM;GACnC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EAGO;EAAU;EAAQ;CAAQ;AACrC"}
1
+ {"version":3,"file":"use-comments.js","names":[],"sources":["../src/use-comments.ts"],"sourcesContent":["import {\n applyCommentAction,\n useReducedMotion,\n type CommentAction,\n type CommentThread,\n} from 'dou-ui'\nimport { TextSelection, type EditorState } from 'prosemirror-state'\nimport type { EditorView } from 'prosemirror-view'\nimport { computed, nextTick, shallowRef, watch, type ShallowRef } from 'vue'\nimport {\n anchorComment,\n commentAnchors,\n commentsAt,\n commentPlugin,\n setPendingComment,\n unanchorComment,\n type CommentAnchor,\n type CommentRange,\n} from './core/comments'\nimport type { CommentsProvider } from './core/extension'\nimport type { EditorComments, EditorEmits, EditorProps } from './editor'\nimport { toggleKey } from './extensions/toggle/state'\n\ntype Emit = <K extends keyof EditorEmits>(event: K, ...args: EditorEmits[K]) => void\n\n/** The selected text in a read-only editor, which keeps no selection of its own. */\nfunction domSelection(view: EditorView): CommentRange | null {\n const selection = view.dom.ownerDocument.getSelection()\n if (!selection || selection.isCollapsed || !selection.rangeCount) return null\n const range = selection.getRangeAt(0)\n if (!view.dom.contains(range.startContainer) || !view.dom.contains(range.endContainer))\n return null\n try {\n const from = view.posAtDOM(range.startContainer, range.startOffset)\n const to = view.posAtDOM(range.endContainer, range.endOffset)\n return to > from ? { from, to } : null\n } catch {\n return null\n }\n}\n\n/** Whether a range holds text a thread can be about: not only a divider, not in code. */\nfunction hasText(state: EditorState, range: CommentRange) {\n let text = false\n state.doc.nodesBetween(range.from, range.to, (node) => {\n if (text) return false\n if (!node.isTextblock) return true\n text = !node.type.spec.code && node.content.size > 0\n return false\n })\n return text\n}\n\nexport function useEditorComments(options: {\n props: EditorProps\n emit: Emit\n view: ShallowRef<EditorView | null>\n provider: CommentsProvider | null\n}) {\n const { props, emit, view, provider } = options\n\n const threads = computed<readonly CommentThread[]>(\n () => provider?.threads.value ?? props.comments ?? [],\n )\n /*\n * `v-model:comments` catches up after the parent renders, so reads in the\n * same tick (such as `getCommentAnchors()` inside `@comment-action`) see\n * the latest applied list immediately.\n */\n let latestThreads: readonly CommentThread[] | null = null\n watch(\n () => props.comments,\n () => {\n latestThreads = null\n },\n { flush: 'sync' },\n )\n const currentThreads = (): readonly CommentThread[] => {\n const value = threads.value\n return latestThreads ?? value\n }\n const enabled = computed(() => !!provider || props.comments !== undefined)\n const writable = computed(() => enabled.value && !!props.author && props.commentable !== false)\n const known = computed(() => new Set(threads.value.map((thread) => thread.id)))\n const currentKnown = () =>\n latestThreads ? new Set(latestThreads.map((thread) => thread.id)) : known.value\n const reducedMotion = useReducedMotion()\n\n // the shared document's threads, mirrored to `v-model:comments`\n if (provider)\n watch(provider.threads, (value) => emit('update:comments', [...value]), { immediate: true })\n\n const innerActive = shallowRef<string | null>(null)\n const active = computed(() =>\n props.activeComment === undefined ? innerActive.value : props.activeComment,\n )\n function open(id: string | null) {\n if (id === active.value) return\n innerActive.value = id\n emit('update:activeComment', id)\n }\n\n const pending = shallowRef<CommentRange | null>(null)\n\n function selection(): CommentRange | null {\n const current = view.value\n if (!current) return null\n const range = current.editable\n ? current.state.selection instanceof TextSelection && !current.state.selection.empty\n ? { from: current.state.selection.from, to: current.state.selection.to }\n : null\n : domSelection(current)\n return range && hasText(current.state, range) ? range : null\n }\n\n const focusRequest = shallowRef(0)\n\n /** The open thread the cursor is in, innermost first. */\n function threadAtCursor(): string | null {\n const current = view.value\n if (!current) return null\n const ids = commentsAt(current.state, current.state.selection.from)\n return ids.find((id) => isOpen(id)) ?? null\n }\n\n function start(): boolean {\n const current = view.value\n if (!current || !enabled.value) return false\n const range = selection()\n if (!range) {\n // on commented text: open its thread, ready to reply\n const id = threadAtCursor()\n if (!id) return false\n open(id)\n focusRequest.value++\n return true\n }\n if (!writable.value) return false\n open(null)\n setPendingComment(current, range)\n return true\n }\n\n function close() {\n const current = view.value\n if (current && pending.value) setPendingComment(current, null)\n open(null)\n }\n\n function apply(action: CommentAction, how: { anchored?: boolean } = {}) {\n const current = view.value\n if (action.type === 'create' && !how.anchored) {\n const range = pending.value\n if (!current || !range) return\n anchorComment(current, range, action.thread.id)\n } else if (current && action.type === 'remove') unanchorComment(current, action.threadId)\n if (provider) provider.apply(action)\n else {\n const next = applyCommentAction(currentThreads(), action)\n if (!latestThreads) void nextTick(() => (latestThreads = null))\n latestThreads = next\n emit('update:comments', next)\n }\n emit('commentAction', action)\n if (action.type === 'create') {\n open(action.thread.id)\n focusRequest.value++\n } else if (action.type === 'remove' || action.type === 'resolve') open(null)\n }\n\n const isOpen = (id: string) => {\n const thread = currentThreads().find((item) => item.id === id)\n return !!thread && !thread.resolved\n }\n\n const plugin = commentPlugin({\n known: () => (enabled.value ? currentKnown() : null),\n onClick: (ids) => {\n if (pending.value && view.value) setPendingComment(view.value, null)\n open(ids.find(isOpen) ?? null)\n },\n // selecting other text (the formatting toolbar shows) closes an open thread\n onSelect: () => {\n if (!pending.value) open(null)\n },\n onPending: (range) => (pending.value = range),\n })\n\n function anchors(): Record<string, CommentAnchor | null> {\n const found = view.value ? commentAnchors(view.value.state.doc) : new Map()\n return Object.fromEntries(\n currentThreads().map((thread) => [thread.id, found.get(thread.id) ?? null]),\n )\n }\n\n function scrollToComment(id: string, scrollOptions?: ScrollIntoViewOptions): boolean {\n const current = view.value\n if (!current || !enabled.value) return false\n const anchor = anchors()[id]\n if (!anchor) return false\n // open any collapsed toggle around the anchor so the element is laid out before scrolling\n const toggleState = toggleKey.getState(current.state)\n if (toggleState?.closed.size) {\n const $pos = current.state.doc.resolve(anchor.from)\n for (let depth = $pos.depth - 1; depth > 0; depth--) {\n if ($pos.node(depth).type.name !== 'blockGroup') continue\n const blockId = $pos.node(depth - 1).attrs.id as string | undefined\n if (blockId && toggleState.closed.has(blockId))\n current.dispatch(\n current.state.tr.setMeta(toggleKey, blockId).setMeta('addToHistory', false),\n )\n }\n }\n let target: HTMLElement | null = null\n if (!anchor.type) {\n target = current.dom.querySelector<HTMLElement>(`[data-comment=\"${CSS.escape(id)}\"]`)\n if (!target) {\n const at = current.domAtPos(anchor.from).node\n target = at instanceof HTMLElement ? at : at.parentElement\n }\n }\n if (!target && anchor.block)\n target = current.dom.querySelector<HTMLElement>(\n `[data-block-id=\"${CSS.escape(anchor.block)}\"]`,\n )\n if (!target) {\n const dom = current.nodeDOM(anchor.from)\n if (dom instanceof HTMLElement) target = dom\n }\n if (!target) return false\n const behavior =\n scrollOptions?.behavior === 'smooth' && reducedMotion.value\n ? 'auto'\n : (scrollOptions?.behavior ?? (reducedMotion.value ? 'auto' : 'smooth'))\n target.scrollIntoView?.({\n block: 'center',\n inline: 'nearest',\n ...scrollOptions,\n behavior,\n })\n return true\n }\n\n const comments: EditorComments = {\n enabled,\n writable,\n threads,\n author: computed(() => props.author),\n active,\n pending,\n focusRequest,\n selection,\n start,\n apply,\n open,\n close,\n }\n\n return { comments, plugin, anchors, scrollToComment }\n}\n"],"mappings":";;;;;;;AA0BA,SAAS,aAAa,MAAuC;CAC3D,MAAM,YAAY,KAAK,IAAI,cAAc,aAAa;CACtD,IAAI,CAAC,aAAa,UAAU,eAAe,CAAC,UAAU,YAAY,OAAO;CACzE,MAAM,QAAQ,UAAU,WAAW,CAAC;CACpC,IAAI,CAAC,KAAK,IAAI,SAAS,MAAM,cAAc,KAAK,CAAC,KAAK,IAAI,SAAS,MAAM,YAAY,GACnF,OAAO;CACT,IAAI;EACF,MAAM,OAAO,KAAK,SAAS,MAAM,gBAAgB,MAAM,WAAW;EAClE,MAAM,KAAK,KAAK,SAAS,MAAM,cAAc,MAAM,SAAS;EAC5D,OAAO,KAAK,OAAO;GAAE;GAAM;EAAG,IAAI;CACpC,QAAQ;EACN,OAAO;CACT;AACF;;AAGA,SAAS,QAAQ,OAAoB,OAAqB;CACxD,IAAI,OAAO;CACX,MAAM,IAAI,aAAa,MAAM,MAAM,MAAM,KAAK,SAAS;EACrD,IAAI,MAAM,OAAO;EACjB,IAAI,CAAC,KAAK,aAAa,OAAO;EAC9B,OAAO,CAAC,KAAK,KAAK,KAAK,QAAQ,KAAK,QAAQ,OAAO;EACnD,OAAO;CACT,CAAC;CACD,OAAO;AACT;AAEA,SAAgB,kBAAkB,SAK/B;CACD,MAAM,EAAE,OAAO,MAAM,MAAM,aAAa;CAExC,MAAM,UAAU,eACR,UAAU,QAAQ,SAAS,M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AC,CAAC,MAAM;IAC3C,IAAI,WAAW,YAAY,OAAO,IAAI,OAAO,GAC3C,QAAQ,SACN,QAAQ,MAAM,GAAG,QAAQ,WAAW,OAAO,CAAC,CAAC,QAAQ,gBAAgB,KAAK,CAC5E;GACJ;EACF;EACA,IAAI,SAA6B;EACjC,IAAI,CAAC,OAAO,MAAM;GAChB,SAAS,QAAQ,IAAI,cAA2B,kBAAkB,IAAI,OAAO,EAAE,EAAE,GAAG;GACpF,IAAI,CAAC,QAAQ;IACX,MAAM,KAAK,QAAQ,SAAS,OAAO,IAAI,CAAC,CAAC;IACzC,SAAS,cAAc,cAAc,KAAK,GAAG;GAC/C;EACF;EACA,IAAI,CAAC,UAAU,OAAO,OACpB,SAAS,QAAQ,IAAI,cACnB,mBAAmB,IAAI,OAAO,OAAO,KAAK,EAAE,GAC9C;EACF,IAAI,CAAC,QAAQ;GACX,MAAM,MAAM,QAAQ,QAAQ,OAAO,IAAI;GACvC,IAAI,eAAe,aAAa,SAAS;EAC3C;EACA,IAAI,CAAC,QAAQ,OAAO;EACpB,MAAM,WACJ,eAAe,aAAa,YAAY,cAAc,QAClD,SACC,eAAe,aAAa,cAAc,QAAQ,SAAS;EAClE,OAAO,iBAAiB;GACtB,OAAO;GACP,QAAQ;GACR,GAAG;GACH;EACF,CAAC;EACD,OAAO;CACT;CAiBA,OAAO;EAAE,UAAA;GAdP;GACA;GACA;GACA,QAAQ,eAAe,MAAM,MAAM;GACnC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EAGO;EAAU;EAAQ;EAAS;CAAgB;AACtD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dou-ui/editor",
3
- "version": "0.1.0-alpha.3",
3
+ "version": "0.1.0-alpha.30",
4
4
  "description": "DouUI 的块编辑器:基于 ProseMirror,文档由可拖动、可转换的块组成",
5
5
  "keywords": [
6
6
  "vue",
@@ -40,6 +40,10 @@
40
40
  "types": "./dist/types/code/index.d.ts",
41
41
  "import": "./dist/code/index.js"
42
42
  },
43
+ "./flow": {
44
+ "types": "./dist/types/flow/index.d.ts",
45
+ "import": "./dist/flow/index.js"
46
+ },
43
47
  "./markdown": {
44
48
  "types": "./dist/types/markdown/index.d.ts",
45
49
  "import": "./dist/markdown/index.js"
@@ -58,8 +62,9 @@
58
62
  "build": "vite build && vue-tsc -p tsconfig.build.json && bun scripts/build-style.ts"
59
63
  },
60
64
  "peerDependencies": {
61
- "@dou-ui/code": "0.1.0-alpha.3",
62
- "dou-ui": "0.1.0-alpha.3",
65
+ "@dou-ui/code": "0.1.0-alpha.30",
66
+ "@dou-ui/flow": "0.1.0-alpha.30",
67
+ "dou-ui": "0.1.0-alpha.30",
63
68
  "vue": "^3.5.0",
64
69
  "yjs": "^13.6.0",
65
70
  "markdown-it": "^14.0.0"
@@ -68,6 +73,9 @@
68
73
  "@dou-ui/code": {
69
74
  "optional": true
70
75
  },
76
+ "@dou-ui/flow": {
77
+ "optional": true
78
+ },
71
79
  "yjs": {
72
80
  "optional": true
73
81
  },
@@ -76,7 +84,7 @@
76
84
  }
77
85
  },
78
86
  "dependencies": {
79
- "@dou-ui/icons": "0.1.0-alpha.3",
87
+ "@dou-ui/icons": "0.1.0-alpha.30",
80
88
  "prosemirror-commands": "^1.7.2",
81
89
  "prosemirror-history": "^1.5.1",
82
90
  "prosemirror-inputrules": "^1.5.1",
@@ -91,7 +99,8 @@
91
99
  "access": "public"
92
100
  },
93
101
  "devDependencies": {
94
- "@dou-ui/code": "0.1.0-alpha.3",
102
+ "@dou-ui/code": "0.1.0-alpha.30",
103
+ "@dou-ui/flow": "0.1.0-alpha.30",
95
104
  "@types/markdown-it": "^14.1.2",
96
105
  "markdown-it": "^14.1.0",
97
106
  "y-protocols": "^1.0.7",