@dou-ui/editor 0.1.0-alpha.17 → 0.1.0-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collaboration/binding.js +39 -49
- package/dist/collaboration/binding.js.map +1 -1
- package/dist/collaboration/inline-diff.js +138 -0
- package/dist/collaboration/inline-diff.js.map +1 -0
- package/dist/collaboration/merged-props.js +10 -10
- package/dist/collaboration/merged-props.js.map +1 -1
- package/dist/collaboration/order.js +41 -1
- package/dist/collaboration/order.js.map +1 -1
- package/dist/collaboration/table.js +64 -25
- package/dist/collaboration/table.js.map +1 -1
- package/dist/collaboration/text.js +213 -1
- package/dist/collaboration/text.js.map +1 -1
- package/dist/core/comments.js +85 -3
- package/dist/core/comments.js.map +1 -1
- package/dist/define-block.js +6 -3
- package/dist/define-block.js.map +1 -1
- package/dist/editor.js.map +1 -1
- package/dist/flow/board-block.js.map +1 -1
- package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js +70 -9
- package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/flow/board.js +124 -5
- package/dist/flow/board.js.map +1 -1
- package/dist/flow/index.js +5 -2
- package/dist/flow/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/collaboration/inline-diff.d.ts +9 -0
- package/dist/types/collaboration/order.d.ts +5 -0
- package/dist/types/collaboration/table.d.ts +5 -1
- package/dist/types/collaboration/text.d.ts +20 -0
- package/dist/types/core/comments.d.ts +39 -3
- package/dist/types/define-block.d.ts +16 -4
- package/dist/types/editor.d.ts +9 -1
- package/dist/types/flow/board.d.ts +15 -2
- package/dist/types/flow/index.d.ts +8 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/use-comments.js +2 -2
- package/dist/use-comments.js.map +1 -1
- package/package.json +7 -7
package/dist/flow/board.js
CHANGED
|
@@ -9,24 +9,31 @@ var BOARD_HEIGHT = {
|
|
|
9
9
|
};
|
|
10
10
|
/** The items of a list that are objects. */
|
|
11
11
|
var objects = (list) => Array.isArray(list) ? list.filter((item) => item && typeof item === "object" && !Array.isArray(item)) : [];
|
|
12
|
+
var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
13
|
+
/** Edges need two readable endpoints that refer to nodes in this board. */
|
|
14
|
+
function edgesOf(value, nodes) {
|
|
15
|
+
const ids = new Set(nodes.map((node) => node.id).filter((id) => typeof id === "string"));
|
|
16
|
+
const endpoint = (end) => isObject(end) && typeof end.node === "string" && ids.has(end.node) && (end.port === void 0 || typeof end.port === "string");
|
|
17
|
+
return objects(value).filter((edge) => typeof edge.id === "string" && !!edge.id && endpoint(edge.source) && endpoint(edge.target));
|
|
18
|
+
}
|
|
12
19
|
/**
|
|
13
20
|
* A block's `board` prop as a flow document; one that is missing or not
|
|
14
21
|
* shaped like one is read as an empty flow (nodes and edges that aren't
|
|
15
|
-
* objects are left out).
|
|
22
|
+
* objects, and edges without valid endpoints, are left out).
|
|
16
23
|
*/
|
|
17
24
|
function boardOf(value) {
|
|
18
25
|
const source = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
26
|
+
const nodes = objects(source.nodes);
|
|
19
27
|
return {
|
|
20
28
|
...source,
|
|
21
29
|
version: 1,
|
|
22
|
-
nodes
|
|
23
|
-
edges:
|
|
30
|
+
nodes,
|
|
31
|
+
edges: edgesOf(source.edges, nodes)
|
|
24
32
|
};
|
|
25
33
|
}
|
|
26
34
|
var clampHeight = (height) => Math.round(Math.min(BOARD_HEIGHT.max, Math.max(BOARD_HEIGHT.min, height)));
|
|
27
35
|
/** A block's `height` prop in px: the default when it isn't a positive number. */
|
|
28
36
|
var heightOf = (value, fallback) => typeof value === "number" && value > 0 ? clampHeight(value) : fallback;
|
|
29
|
-
var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
30
37
|
/** What `checkDocument` reports of a block's props: a board or height it would read differently. */
|
|
31
38
|
function checkBoardProps(props) {
|
|
32
39
|
const problems = [];
|
|
@@ -47,6 +54,10 @@ function checkBoardProps(props) {
|
|
|
47
54
|
prop: `board.${list}`,
|
|
48
55
|
message: `Some ${list} are not objects; they would be left out`
|
|
49
56
|
});
|
|
57
|
+
else if (list === "edges" && edgesOf(items, objects(board.nodes)).length !== items.length) problems.push({
|
|
58
|
+
prop: "board.edges",
|
|
59
|
+
message: "Some edges have no id, invalid endpoints, or refer to missing nodes; they would be left out"
|
|
60
|
+
});
|
|
50
61
|
}
|
|
51
62
|
}
|
|
52
63
|
if (height != null && !(typeof height === "number" && height > 0)) problems.push({
|
|
@@ -97,6 +108,114 @@ function onlyBoardChanged(a, b, id) {
|
|
|
97
108
|
if (before.node.childCount !== after.node.childCount) return false;
|
|
98
109
|
return before.node.childCount < 2 || before.node.child(1).eq(after.node.child(1));
|
|
99
110
|
}
|
|
100
|
-
|
|
111
|
+
var threadIds = (item) => Array.isArray(item.comments) ? item.comments.filter((id) => typeof id === "string") : [];
|
|
112
|
+
/** What a node shows: its label, or a whiteboard shape's text. */
|
|
113
|
+
var textOf = (data) => {
|
|
114
|
+
const text = data?.label ?? data?.text;
|
|
115
|
+
return typeof text === "string" ? text : "";
|
|
116
|
+
};
|
|
117
|
+
var pinOf = (node, id) => {
|
|
118
|
+
const pins = node.commentPins;
|
|
119
|
+
const at = isObject(pins) && Object.hasOwn(pins, id) ? pins[id] : null;
|
|
120
|
+
return isObject(at) && typeof at.x === "number" && typeof at.y === "number" ? {
|
|
121
|
+
x: at.x,
|
|
122
|
+
y: at.y
|
|
123
|
+
} : null;
|
|
124
|
+
};
|
|
125
|
+
/** `comments` (and `commentPins`) of a node or edge with only the ids `keep` says yes to. */
|
|
126
|
+
function keepOn(item, keep) {
|
|
127
|
+
const ids = threadIds(item);
|
|
128
|
+
const kept = ids.filter(keep);
|
|
129
|
+
const pins = "commentPins" in item && isObject(item.commentPins) ? item.commentPins : null;
|
|
130
|
+
const keptPins = pins ? Object.fromEntries(Object.entries(pins).filter(([id]) => keep(id))) : null;
|
|
131
|
+
if (kept.length === ids.length && (!pins || Object.keys(keptPins).length === Object.keys(pins).length)) return item;
|
|
132
|
+
const { comments: _, commentPins: __, ...rest } = item;
|
|
133
|
+
const next = { ...rest };
|
|
134
|
+
if (kept.length) next.comments = kept;
|
|
135
|
+
if (keptPins && Object.keys(keptPins).length) next.commentPins = keptPins;
|
|
136
|
+
return next;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* How a board block keeps comment threads: on its nodes and edges, in their
|
|
140
|
+
* `comments` (and `commentPins`), as a `DouFlowEditor` does.
|
|
141
|
+
*/
|
|
142
|
+
var boardComments = {
|
|
143
|
+
anchors(props) {
|
|
144
|
+
const board = boardOf(props.board);
|
|
145
|
+
const anchors = {};
|
|
146
|
+
for (const node of board.nodes) {
|
|
147
|
+
let number = 0;
|
|
148
|
+
for (const id of threadIds(node)) {
|
|
149
|
+
const at = pinOf(node, id);
|
|
150
|
+
anchors[id] = {
|
|
151
|
+
text: textOf(node.data),
|
|
152
|
+
target: at ? {
|
|
153
|
+
node: node.id,
|
|
154
|
+
at,
|
|
155
|
+
number: ++number
|
|
156
|
+
} : { node: node.id }
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
for (const edge of board.edges) for (const id of threadIds(edge)) anchors[id] ??= {
|
|
161
|
+
text: edge.label ?? "",
|
|
162
|
+
target: { edge: edge.id }
|
|
163
|
+
};
|
|
164
|
+
return anchors;
|
|
165
|
+
},
|
|
166
|
+
place(props, id, target) {
|
|
167
|
+
const board = boardOf(props.board);
|
|
168
|
+
const add = (ids) => [...ids.filter((other) => other !== id), id];
|
|
169
|
+
if ("node" in target) {
|
|
170
|
+
if (!board.nodes.some((node) => node.id === target.node)) return null;
|
|
171
|
+
const nodes = board.nodes.map((node) => {
|
|
172
|
+
if (node.id !== target.node) return node;
|
|
173
|
+
const next = {
|
|
174
|
+
...node,
|
|
175
|
+
comments: add(threadIds(node))
|
|
176
|
+
};
|
|
177
|
+
if (target.at) next.commentPins = {
|
|
178
|
+
...isObject(node.commentPins) ? node.commentPins : {},
|
|
179
|
+
[id]: target.at
|
|
180
|
+
};
|
|
181
|
+
return next;
|
|
182
|
+
});
|
|
183
|
+
return {
|
|
184
|
+
...props,
|
|
185
|
+
board: {
|
|
186
|
+
...board,
|
|
187
|
+
nodes
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
if (!board.edges.some((edge) => edge.id === target.edge)) return null;
|
|
192
|
+
const edges = board.edges.map((edge) => edge.id === target.edge ? {
|
|
193
|
+
...edge,
|
|
194
|
+
comments: add(threadIds(edge))
|
|
195
|
+
} : edge);
|
|
196
|
+
return {
|
|
197
|
+
...props,
|
|
198
|
+
board: {
|
|
199
|
+
...board,
|
|
200
|
+
edges
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
strip(props, keep) {
|
|
205
|
+
if (props.board == null) return props;
|
|
206
|
+
const board = boardOf(props.board);
|
|
207
|
+
const nodes = board.nodes.map((node) => keepOn(node, keep));
|
|
208
|
+
const edges = board.edges.map((edge) => keepOn(edge, keep));
|
|
209
|
+
return nodes.every((node, i) => node === board.nodes[i]) && edges.every((edge, i) => edge === board.edges[i]) ? props : {
|
|
210
|
+
...props,
|
|
211
|
+
board: {
|
|
212
|
+
...board,
|
|
213
|
+
nodes,
|
|
214
|
+
edges
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
export { BOARD_HEIGHT, BOARD_OPEN_EVENT, boardComments, boardOf, checkBoardProps, clampHeight, heightOf, onlyBoardChanged };
|
|
101
220
|
|
|
102
221
|
//# sourceMappingURL=board.js.map
|
package/dist/flow/board.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board.js","names":[],"sources":["../../src/flow/board.ts"],"sourcesContent":["import type { FlowDocument, FlowExtension } from '@dou-ui/flow'\nimport type { Node as PMNode } from 'prosemirror-model'\nimport type { Label } from '../core/extension'\nimport type { FlowBlockEditorProps } from './index'\n\n/** Sent to a block's element to open its fullscreen editor (`Enter` on the selected block). */\nexport const BOARD_OPEN_EVENT = 'dou-editor-board-open'\n\n/** Heights a block may have in the document, in px. */\nexport const BOARD_HEIGHT = { min: 160, max: 1200, step: 40 }\n\nexport interface BoardBlockSettings {\n label: Label\n extensions: (FlowExtension | FlowExtension[])[]\n editorProps: FlowBlockEditorProps\n height: number\n /** When the extensions offer no node to add, offer one with ports (not on a whiteboard, which has its tools). */\n fallbackNode: boolean\n}\n\n/** The items of a list that are objects. */\nconst objects = <T>(list: unknown) =>\n Array.isArray(list)\n ? (list.filter((item) => item && typeof item === 'object' && !Array.isArray(item)) as T[])\n : []\n\n/**\n * A block's `board` prop as a flow document; one that is missing or not\n * shaped like one is read as an empty flow (nodes and edges that aren't\n * objects are left out).\n */\nexport function boardOf(value: unknown): FlowDocument {\n const source =\n value && typeof value === 'object' && !Array.isArray(value)\n ? (value as Partial<FlowDocument>)\n : {}\n return {\n ...source,\n version: 1,\n nodes: objects(source.nodes),\n edges: objects(source.edges),\n } as FlowDocument\n}\n\nexport const clampHeight = (height: number) =>\n Math.round(Math.min(BOARD_HEIGHT.max, Math.max(BOARD_HEIGHT.min, height)))\n\n/** A block's `height` prop in px: the default when it isn't a positive number. */\nexport const heightOf = (value: unknown, fallback: number) =>\n typeof value === 'number' && value > 0 ? clampHeight(value) : fallback\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n !!value && typeof value === 'object' && !Array.isArray(value)\n\n/** What `checkDocument` reports of a block's props: a board or height it would read differently. */\nexport function checkBoardProps(props: Record<string, unknown>) {\n const problems: { prop: string; message: string }[] = []\n const { board, height } = props\n if (board != null) {\n if (!isObject(board))\n problems.push({\n prop: 'board',\n message: 'The board is not a flow document; it would be shown empty',\n })\n else\n for (const list of ['nodes', 'edges'] as const) {\n const items = board[list]\n if (items === undefined) continue\n if (!Array.isArray(items))\n problems.push({\n prop: `board.${list}`,\n message: `\"${list}\" is not a list; it would be read as empty`,\n })\n else if (items.some((item) => !isObject(item)))\n problems.push({\n prop: `board.${list}`,\n message: `Some ${list} are not objects; they would be left out`,\n })\n }\n }\n if (height != null && !(typeof height === 'number' && height > 0))\n problems.push({\n prop: 'height',\n message: `The height ${JSON.stringify(height)} is not a positive number; the default would be used`,\n })\n else if (typeof height === 'number' && (height < BOARD_HEIGHT.min || height > BOARD_HEIGHT.max))\n problems.push({\n prop: 'height',\n message: `The height ${height} is outside ${BOARD_HEIGHT.min}–${BOARD_HEIGHT.max}; it would be clamped`,\n })\n return problems\n}\n\ninterface Found {\n pos: number\n node: PMNode\n}\n\nconst endOf = (at: Found) => at.pos + at.node.nodeSize\n/** A content node's attributes besides the board. */\nconst restOf = (node: PMNode) => JSON.stringify({ ...node.attrs, board: null })\n\n/**\n * Whether `a` and `b` differ only in the `board` prop of the block `id`:\n * an undo taken from the fullscreen editor must not change anything the\n * person can't see there.\n */\nexport function onlyBoardChanged(a: PMNode, b: PMNode, id: string): boolean {\n const find = (doc: PMNode) => {\n let found: Found | null = null\n doc.descendants((node, pos) => {\n if (found) return false\n if (node.type.name === 'block' && node.attrs.id === id) {\n found = { pos, node }\n return false\n }\n return true\n })\n return found as Found | null\n }\n const before = find(a)\n const after = find(b)\n if (!before || !after) return false\n if (!a.slice(0, before.pos).eq(b.slice(0, after.pos))) return false\n if (!a.slice(endOf(before)).eq(b.slice(endOf(after)))) return false\n const [x, y] = [before.node.firstChild!, after.node.firstChild!]\n if (x.type !== y.type) return false\n if (restOf(x) !== restOf(y)) return false\n // the children of the block, if any\n if (before.node.childCount !== after.node.childCount) return false\n return before.node.childCount < 2 || before.node.child(1).eq(after.node.child(1))\n}\n"],"mappings":";;AAMA,IAAa,mBAAmB;;AAGhC,IAAa,eAAe;CAAE,KAAK;CAAK,KAAK;CAAM,MAAM;AAAG;;AAY5D,IAAM,WAAc,SAClB,MAAM,QAAQ,IAAI,IACb,KAAK,QAAQ,SAAS,QAAQ,OAAO,S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CAAC,CAAC,GAAG,MAAM,KAAK,MAAM,CAAC,CAAC;AAClF"}
|
|
1
|
+
{"version":3,"file":"board.js","names":[],"sources":["../../src/flow/board.ts"],"sourcesContent":["import type {\n FlowCommentAnchor,\n FlowDocument,\n FlowEdge,\n FlowExtension,\n FlowNode,\n} from '@dou-ui/flow'\nimport type { Node as PMNode } from 'prosemirror-model'\nimport type { BlockCommentAnchor, BlockCommentsSpec } from '../core/comments'\nimport type { Label } from '../core/extension'\nimport type { FlowBlockEditorProps } from './index'\n\n/** Sent to a block's element to open its fullscreen editor (`Enter` on the selected block). */\nexport const BOARD_OPEN_EVENT = 'dou-editor-board-open'\n\n/** Heights a block may have in the document, in px. */\nexport const BOARD_HEIGHT = { min: 160, max: 1200, step: 40 }\n\nexport interface BoardBlockSettings {\n label: Label\n extensions: (FlowExtension | FlowExtension[])[]\n editorProps: FlowBlockEditorProps\n height: number\n /** When the extensions offer no node to add, offer one with ports (not on a whiteboard, which has its tools). */\n fallbackNode: boolean\n /** Threads can be started and shown on the nodes and edges, with the document's comments. */\n commentable: boolean\n}\n\n/** The items of a list that are objects. */\nconst objects = <T>(list: unknown) =>\n Array.isArray(list)\n ? (list.filter((item) => item && typeof item === 'object' && !Array.isArray(item)) as T[])\n : []\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n !!value && typeof value === 'object' && !Array.isArray(value)\n\n/** Edges need two readable endpoints that refer to nodes in this board. */\nfunction edgesOf(value: unknown, nodes: FlowNode[]): FlowEdge[] {\n const ids = new Set(nodes.map((node) => node.id).filter((id) => typeof id === 'string'))\n const endpoint = (end: unknown) =>\n isObject(end) &&\n typeof end.node === 'string' &&\n ids.has(end.node) &&\n (end.port === undefined || typeof end.port === 'string')\n return objects<FlowEdge>(value).filter(\n (edge) =>\n typeof edge.id === 'string' && !!edge.id && endpoint(edge.source) && endpoint(edge.target),\n )\n}\n\n/**\n * A block's `board` prop as a flow document; one that is missing or not\n * shaped like one is read as an empty flow (nodes and edges that aren't\n * objects, and edges without valid endpoints, are left out).\n */\nexport function boardOf(value: unknown): FlowDocument {\n const source =\n value && typeof value === 'object' && !Array.isArray(value)\n ? (value as Partial<FlowDocument>)\n : {}\n const nodes = objects<FlowNode>(source.nodes)\n return {\n ...source,\n version: 1,\n nodes,\n edges: edgesOf(source.edges, nodes),\n } as FlowDocument\n}\n\nexport const clampHeight = (height: number) =>\n Math.round(Math.min(BOARD_HEIGHT.max, Math.max(BOARD_HEIGHT.min, height)))\n\n/** A block's `height` prop in px: the default when it isn't a positive number. */\nexport const heightOf = (value: unknown, fallback: number) =>\n typeof value === 'number' && value > 0 ? clampHeight(value) : fallback\n\n/** What `checkDocument` reports of a block's props: a board or height it would read differently. */\nexport function checkBoardProps(props: Record<string, unknown>) {\n const problems: { prop: string; message: string }[] = []\n const { board, height } = props\n if (board != null) {\n if (!isObject(board))\n problems.push({\n prop: 'board',\n message: 'The board is not a flow document; it would be shown empty',\n })\n else\n for (const list of ['nodes', 'edges'] as const) {\n const items = board[list]\n if (items === undefined) continue\n if (!Array.isArray(items))\n problems.push({\n prop: `board.${list}`,\n message: `\"${list}\" is not a list; it would be read as empty`,\n })\n else if (items.some((item) => !isObject(item)))\n problems.push({\n prop: `board.${list}`,\n message: `Some ${list} are not objects; they would be left out`,\n })\n else if (\n list === 'edges' &&\n edgesOf(items, objects<FlowNode>(board.nodes)).length !== items.length\n )\n problems.push({\n prop: 'board.edges',\n message:\n 'Some edges have no id, invalid endpoints, or refer to missing nodes; they would be left out',\n })\n }\n }\n if (height != null && !(typeof height === 'number' && height > 0))\n problems.push({\n prop: 'height',\n message: `The height ${JSON.stringify(height)} is not a positive number; the default would be used`,\n })\n else if (typeof height === 'number' && (height < BOARD_HEIGHT.min || height > BOARD_HEIGHT.max))\n problems.push({\n prop: 'height',\n message: `The height ${height} is outside ${BOARD_HEIGHT.min}–${BOARD_HEIGHT.max}; it would be clamped`,\n })\n return problems\n}\n\ninterface Found {\n pos: number\n node: PMNode\n}\n\nconst endOf = (at: Found) => at.pos + at.node.nodeSize\n/** A content node's attributes besides the board. */\nconst restOf = (node: PMNode) => JSON.stringify({ ...node.attrs, board: null })\n\n/**\n * Whether `a` and `b` differ only in the `board` prop of the block `id`:\n * an undo taken from the fullscreen editor must not change anything the\n * person can't see there.\n */\nexport function onlyBoardChanged(a: PMNode, b: PMNode, id: string): boolean {\n const find = (doc: PMNode) => {\n let found: Found | null = null\n doc.descendants((node, pos) => {\n if (found) return false\n if (node.type.name === 'block' && node.attrs.id === id) {\n found = { pos, node }\n return false\n }\n return true\n })\n return found as Found | null\n }\n const before = find(a)\n const after = find(b)\n if (!before || !after) return false\n if (!a.slice(0, before.pos).eq(b.slice(0, after.pos))) return false\n if (!a.slice(endOf(before)).eq(b.slice(endOf(after)))) return false\n const [x, y] = [before.node.firstChild!, after.node.firstChild!]\n if (x.type !== y.type) return false\n if (restOf(x) !== restOf(y)) return false\n // the children of the block, if any\n if (before.node.childCount !== after.node.childCount) return false\n return before.node.childCount < 2 || before.node.child(1).eq(after.node.child(1))\n}\n\n/**\n * Where a thread is on a board, as the flow editor's `getCommentAnchors`\n * gives it: a node, maybe a point on it with its number there, or an edge.\n */\nexport type BoardCommentTarget = FlowCommentAnchor\n\nconst threadIds = (item: { comments?: unknown }): string[] =>\n Array.isArray(item.comments) ? item.comments.filter((id) => typeof id === 'string') : []\n\n/** What a node shows: its label, or a whiteboard shape's text. */\nconst textOf = (data: Record<string, unknown> | undefined) => {\n const text = data?.label ?? data?.text\n return typeof text === 'string' ? text : ''\n}\n\nconst pinOf = (node: FlowNode, id: string) => {\n const pins = node.commentPins\n const at = isObject(pins) && Object.hasOwn(pins, id) ? pins[id] : null\n return isObject(at) && typeof at.x === 'number' && typeof at.y === 'number'\n ? { x: at.x, y: at.y }\n : null\n}\n\n/** `comments` (and `commentPins`) of a node or edge with only the ids `keep` says yes to. */\nfunction keepOn<T extends FlowNode | FlowEdge>(item: T, keep: (id: string) => boolean): T {\n const ids = threadIds(item)\n const kept = ids.filter(keep)\n const pins = 'commentPins' in item && isObject(item.commentPins) ? item.commentPins : null\n const keptPins = pins ? Object.fromEntries(Object.entries(pins).filter(([id]) => keep(id))) : null\n if (\n kept.length === ids.length &&\n (!pins || Object.keys(keptPins!).length === Object.keys(pins).length)\n )\n return item\n const { comments: _, commentPins: __, ...rest } = item as FlowNode\n const next = { ...rest } as T\n if (kept.length) next.comments = kept\n if (keptPins && Object.keys(keptPins).length) (next as FlowNode).commentPins = keptPins\n return next\n}\n\n/**\n * How a board block keeps comment threads: on its nodes and edges, in their\n * `comments` (and `commentPins`), as a `DouFlowEditor` does.\n */\nexport const boardComments: BlockCommentsSpec<BoardCommentTarget> = {\n anchors(props) {\n const board = boardOf(props.board)\n const anchors: Record<string, BlockCommentAnchor<BoardCommentTarget>> = {}\n for (const node of board.nodes) {\n // pins are numbered on the node in the order they were made, from 1\n let number = 0\n for (const id of threadIds(node)) {\n const at = pinOf(node, id)\n anchors[id] = {\n text: textOf(node.data),\n target: at ? { node: node.id, at, number: ++number } : { node: node.id },\n }\n }\n }\n for (const edge of board.edges)\n for (const id of threadIds(edge))\n anchors[id] ??= { text: edge.label ?? '', target: { edge: edge.id } }\n return anchors\n },\n place(props, id, target) {\n const board = boardOf(props.board)\n const add = (ids: string[]) => [...ids.filter((other) => other !== id), id]\n if ('node' in target) {\n if (!board.nodes.some((node) => node.id === target.node)) return null\n const nodes = board.nodes.map((node) => {\n if (node.id !== target.node) return node\n const next: FlowNode = { ...node, comments: add(threadIds(node)) }\n if (target.at)\n next.commentPins = {\n ...(isObject(node.commentPins) ? node.commentPins : {}),\n [id]: target.at,\n }\n return next\n })\n return { ...props, board: { ...board, nodes } }\n }\n if (!board.edges.some((edge) => edge.id === target.edge)) return null\n const edges = board.edges.map((edge) =>\n edge.id === target.edge ? { ...edge, comments: add(threadIds(edge)) } : edge,\n )\n return { ...props, board: { ...board, edges } }\n },\n strip(props, keep) {\n if (props.board == null) return props\n const board = boardOf(props.board)\n const nodes = board.nodes.map((node) => keepOn(node, keep))\n const edges = board.edges.map((edge) => keepOn(edge, keep))\n const same =\n nodes.every((node, i) => node === board.nodes[i]) &&\n edges.every((edge, i) => edge === board.edges[i])\n return same ? props : { ...props, board: { ...board, nodes, edges } }\n },\n}\n"],"mappings":";;AAaA,IAAa,mBAAmB;;AAGhC,IAAa,eAAe;CAAE,KAAK;CAAK,KAAK;CAAM,MAAM;AAAG;;AAc5D,IAAM,WAAc,SAClB,MAAM,QAAQ,IAAI,IACb,KAAK,QAAQ,SAAS,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,QAAQ,IAAI,CAAC,IAC/E,CAAC;AAEP,IAAM,YAAY,UAChB,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;;AAG9D,SAAS,QAAQ,OAAgB,OAA+B;CAC9D,MAAM,MAAM,IAAI,IAAI,MAAM,KAAK,SAAS,KAAK,EAAE,CAAC,CAAC,QAAQ,OAAO,OAAO,OAAO,QAAQ,CAAC;CACvF,MAAM,YAAY,QAChB,SAAS,GAAG,KACZ,OAAO,IAAI,SAAS,YACpB,IAAI,IAAI,IAAI,IAAI,MACf,IAAI,SAAS,KAAA,KAAa,OAAO,IAAI,SAAS;CACjD,OAAO,QAAkB,KAAK,CAAC,CAAC,QAC7B,SACC,OAAO,KAAK,OAAO,YAAY,CAAC,CAAC,KAAK,MAAM,SAAS,KAAK,MAAM,KAAK,SAAS,KAAK,MAAM,CAC7F;AACF;;;;;;AAOA,SAAgB,QAAQ,OAA8B;CACpD,MAAM,SACJ,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IACrD,QACD,CAAC;CACP,MAAM,QAAQ,QAAkB,OAAO,KAAK;CAC5C,OAAO;EACL,GAAG;EACH,SAAS;EACT;EACA,OAAO,QAAQ,OAAO,OAAO,KAAK;CACpC;AACF;AAEA,IAAa,eAAe,WAC1B,KAAK,MAAM,KAAK,IAAI,aAAa,KAAK,KAAK,IAAI,aAAa,KA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AAM,KAAK,SAAS,OAAO,MAAM,IAAI,CAAC;EAC1D,MAAM,QAAQ,MAAM,MAAM,KAAK,SAAS,OAAO,MAAM,IAAI,CAAC;EAI1D,OAFE,MAAM,OAAO,MAAM,MAAM,SAAS,MAAM,MAAM,EAAE,KAChD,MAAM,OAAO,MAAM,MAAM,SAAS,MAAM,MAAM,EAAE,IACpC,QAAQ;GAAE,GAAG;GAAO,OAAO;IAAE,GAAG;IAAO;IAAO;GAAM;EAAE;CACtE;AACF"}
|
package/dist/flow/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { editorLocales } from "../locale.js";
|
|
|
2
2
|
import { labelOf } from "../core/extension.js";
|
|
3
3
|
import { escapeHTML } from "../core/output.js";
|
|
4
4
|
import { defineBlock } from "../define-block.js";
|
|
5
|
-
import { BOARD_OPEN_EVENT, boardOf, checkBoardProps, clampHeight, heightOf } from "./board.js";
|
|
5
|
+
import { BOARD_OPEN_EVENT, boardComments, boardOf, checkBoardProps, clampHeight, heightOf } from "./board.js";
|
|
6
6
|
import board_block_default from "./board-block.js";
|
|
7
7
|
import { defineComponent, h } from "vue";
|
|
8
8
|
import { NodeSelection } from "prosemirror-state";
|
|
@@ -61,7 +61,8 @@ function boardBlock(options, fallbackNode) {
|
|
|
61
61
|
extensions: options.extensions ?? [flowKit()],
|
|
62
62
|
editorProps: options.editorProps ?? {},
|
|
63
63
|
height: options.height ?? 360,
|
|
64
|
-
fallbackNode
|
|
64
|
+
fallbackNode,
|
|
65
|
+
commentable: options.commentable !== false
|
|
65
66
|
};
|
|
66
67
|
const View = defineComponent({
|
|
67
68
|
name: "DouEditorFlowBlockView",
|
|
@@ -82,6 +83,7 @@ function boardBlock(options, fallbackNode) {
|
|
|
82
83
|
},
|
|
83
84
|
content: "none",
|
|
84
85
|
component: View,
|
|
86
|
+
comments: settings.commentable ? boardComments : void 0,
|
|
85
87
|
menu: options.menu === false ? void 0 : {
|
|
86
88
|
icon: WorkflowIcon,
|
|
87
89
|
...menu,
|
|
@@ -148,6 +150,7 @@ function whiteboardBlock(options = {}) {
|
|
|
148
150
|
})],
|
|
149
151
|
editorProps: options.editorProps,
|
|
150
152
|
height: options.height,
|
|
153
|
+
commentable: options.commentable,
|
|
151
154
|
html: options.html,
|
|
152
155
|
menu: options.menu === false ? false : {
|
|
153
156
|
icon: ShapesIcon,
|
package/dist/flow/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["BoardBlock"],"sources":["../../src/flow/index.ts"],"sourcesContent":["import { flowKit, type FlowDocument, type FlowEditorProps, type FlowExtension } from '@dou-ui/flow'\nimport { whiteboardKit, type WhiteboardKitOptions } from '@dou-ui/flow/whiteboard'\nimport { ShapesIcon, WorkflowIcon } from '@dou-ui/icons'\nimport { NodeSelection, type Command } from 'prosemirror-state'\nimport { defineComponent, h } from 'vue'\nimport { labelOf, type BlockOption, type EditorExtension, type Label } from '../core/extension'\nimport { escapeHTML } from '../core/output'\nimport { defineBlock } from '../define-block'\nimport { editorLocales } from '../locale'\nimport BoardBlock from './board-block.vue'\nimport {\n boardOf,\n BOARD_OPEN_EVENT,\n checkBoardProps,\n clampHeight,\n heightOf,\n type BoardBlockSettings,\n} from './board'\n\nexport { boardOf } from './board'\n\n/** The props of the fullscreen editor that a flow block may set. */\nexport type FlowBlockEditorProps = Omit<\n FlowEditorProps,\n 'extensions' | 'readonly' | 'fitView' | 'comments' | 'author' | 'activeComment' | 'commentable'\n>\n\nexport interface FlowBlockOptions {\n /** The block type, e.g. `approvalFlow`; unique among the editor's blocks. */\n type: string\n /** What the flow is made of, as the editor's `extensions`. `[flowKit()]` by default. */\n extensions?: (FlowExtension | FlowExtension[])[]\n /** More props for the flow editors, e.g. `nodeTypes`, `portTypes` or `direction`. */\n editorProps?: FlowBlockEditorProps\n /** The block's name: the title of the fullscreen editor, and of its slash menu entry. */\n label: Label\n /** The slash menu entry, or `false` to leave it out (blocks then come from code or pasting). */\n menu?: (Omit<BlockOption, 'key' | 'type' | 'label'> & { key?: string; label?: Label }) | false\n /** The height of a new block in the document, in px. Defaults to `360`. */\n height?: number\n /**\n * How a block is written in `blocksToHTML`, e.g. an `<img>` of a picture\n * of it the app keeps. By default a `<figure>` with its name, which\n * pasting reads back as the block.\n */\n html?: (board: FlowDocument, block: { id: string; props: Record<string, unknown> }) => string\n}\n\nconst fence = (type: string) => `dou-${type}`\n\nfunction attrsOf(dom: HTMLElement, height: number) {\n let board: unknown = null\n try {\n board = JSON.parse(dom.getAttribute('data-prop-board') ?? 'null')\n } catch {\n // a board that can't be read is an empty one\n }\n // `320`, or written by hand `320px`\n const stored = Number.parseFloat(dom.getAttribute('data-prop-height') ?? '')\n return { board: board ? boardOf(board) : null, height: stored > 0 ? clampHeight(stored) : height }\n}\n\n/** Turns ```dou-<type> fences from Markdown back into blocks. */\nfunction readFences(root: HTMLElement, type: string) {\n for (const code of root.querySelectorAll<HTMLElement>(`pre > code.language-${fence(type)}`)) {\n let written: unknown\n try {\n written = JSON.parse(code.textContent ?? '')\n } catch {\n continue\n }\n // `{ height, board }`, or the board alone\n const wrapped = !!written && typeof written === 'object' && 'board' in written\n const { board, height } = (wrapped ? written : { board: written }) as {\n board: unknown\n height?: unknown\n }\n const element = root.ownerDocument.createElement('div')\n element.dataset.contentType = type\n element.setAttribute('data-prop-board', JSON.stringify(boardOf(board)))\n if (typeof height === 'number') element.setAttribute('data-prop-height', String(height))\n code.parentElement!.replaceWith(element)\n }\n}\n\n/**\n * A block that holds a flow, drawn with `@dou-ui/flow`: the document shows\n * it whole, and it is edited in a fullscreen editor (double-click, the\n * “Edit” button, or `Enter` while the block is selected). The flow is the\n * block's `board` prop; collaboration merges it node by node.\n *\n * ```ts\n * extensions: [editorKit(), flowBlock({ type: 'approvalFlow', label: '审批流程', extensions: [flowKit(), approval()] })]\n * ```\n *\n * Needs `@dou-ui/flow` and its styles. For a whiteboard, `whiteboardBlock()`.\n */\nexport function flowBlock(options: FlowBlockOptions): EditorExtension {\n return boardBlock(options, true)\n}\n\nfunction boardBlock(options: FlowBlockOptions, fallbackNode: boolean): EditorExtension {\n const { type } = options\n const settings: BoardBlockSettings = {\n label: options.label,\n extensions: options.extensions ?? [flowKit()],\n editorProps: options.editorProps ?? {},\n height: options.height ?? 360,\n fallbackNode,\n }\n const View = defineComponent({\n name: 'DouEditorFlowBlockView',\n inheritAttrs: false,\n setup(_props, { attrs }) {\n return () => h(BoardBlock, { ...attrs, settings } as never)\n },\n })\n const menu = options.menu === false ? undefined : options.menu\n const block = defineBlock({\n type,\n props: { board: null, height: settings.height },\n content: 'none',\n component: View,\n menu:\n options.menu === false\n ? undefined\n : { icon: WorkflowIcon, ...menu, label: menu?.label ?? options.label },\n spec: {\n mergeProps: { board: { lists: ['nodes', 'edges'], objects: ['data'] } },\n // for `checkDocument`: what the block would read differently\n checkProps: checkBoardProps,\n // what is copied, and what `blocksToHTML` writes\n parseDOM: [`div[data-content-type=\"${type}\"]`, `figure[data-content-type=\"${type}\"]`].map(\n (tag) => ({\n tag,\n // before the figures of images, whatever the app's HTML puts inside\n priority: 70,\n getAttrs: (dom: HTMLElement) => attrsOf(dom, settings.height),\n }),\n ),\n },\n })\n /** `Enter` on the selected block opens it. */\n const open: Command = (state, dispatch, view) => {\n const { selection } = state\n if (!(selection instanceof NodeSelection) || selection.node.type.name !== type) return false\n if (dispatch && view) {\n const dom = view.nodeDOM(selection.from) as HTMLElement | null\n dom?.querySelector('.dou-editor-board')?.dispatchEvent(new CustomEvent(BOARD_OPEN_EVENT))\n }\n return true\n }\n return {\n ...block,\n name: `flow:${type}`,\n keymap: () => ({ enter: open }),\n prepareHTML: (root) => readFences(root, type),\n output: {\n blocks: {\n [type]: {\n html: (node, { children }) => {\n const board = boardOf(node.props.board)\n // written outside an editor: in Chinese, as the other output\n const inside = options.html\n ? options.html(board, node)\n : `<figcaption>${escapeHTML(labelOf(options.label, editorLocales['zh-CN']!))}</figcaption>`\n // the board stays on the figure, so pasting it reads back the block\n return `<figure data-content-type=\"${escapeHTML(type)}\" data-prop-board=\"${escapeHTML(JSON.stringify(board))}\" data-prop-height=\"${heightOf(node.props.height, settings.height)}\">${inside}</figure>${children}`\n },\n markdown: (node, { children }) => {\n const value = {\n height: heightOf(node.props.height, settings.height),\n board: boardOf(node.props.board),\n }\n const written = `\\`\\`\\`${fence(type)}\\n${JSON.stringify(value)}\\n\\`\\`\\``\n return children ? `${written}\\n\\n${children}` : written\n },\n },\n },\n },\n }\n}\n\nexport interface WhiteboardBlockOptions\n extends\n Pick<WhiteboardKitOptions, 'upload' | 'onUploadError'>,\n Pick<FlowBlockOptions, 'height' | 'html' | 'editorProps'> {\n /** The slash menu entry, or `false` to leave it out. */\n menu?: FlowBlockOptions['menu']\n}\n\n/**\n * A whiteboard block: shapes, sticky notes, text, pen strokes, images and\n * connectors, drawn in a fullscreen editor. Pass the `upload` of `image()`\n * so pictures on the board are uploaded too, not kept in the document.\n *\n * ```ts\n * extensions: [editorKit(), whiteboardBlock({ upload })]\n * ```\n */\nexport function whiteboardBlock(options: WhiteboardBlockOptions = {}): EditorExtension {\n return boardBlock(\n {\n type: 'whiteboard',\n label: (m) => m.types.whiteboard,\n extensions: [\n flowKit(),\n whiteboardKit({ upload: options.upload, onUploadError: options.onUploadError }),\n ],\n editorProps: options.editorProps,\n height: options.height,\n html: options.html,\n menu:\n options.menu === false\n ? false\n : {\n icon: ShapesIcon,\n hint: (m) => m.hints.whiteboard,\n keywords: [\n 'whiteboard',\n 'board',\n 'draw',\n 'flowchart',\n 'baiban',\n 'huatu',\n 'liuchengtu',\n ],\n ...options.menu,\n },\n },\n false,\n )\n}\n"],"mappings":";;;;;;;;;;;;AAgDA,IAAM,SAAS,SAAiB,OAAO;AAEvC,SAAS,QAAQ,KAAkB,QAAgB;CACjD,IAAI,QAAiB;CACrB,IAAI;EACF,QAAQ,KAAK,MAAM,IAAI,aAAa,iBAAiB,KAAK,MAAM;CAClE,QAAQ,CAER;CAEA,MAAM,SAAS,OAAO,WAAW,IAAI,aAAa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C,MAAM,QAAQ;KACZ,QAAQ,SAAS,KAAK,MAAM,QAAQ,SAAS,MAAM;KACnD,OAAO,QAAQ,KAAK,MAAM,KAAK;IACjC;IACA,MAAM,UAAU,SAAS,MAAM,IAAI,EAAE,IAAI,KAAK,UAAU,KAAK,EAAE;IAC/D,OAAO,WAAW,GAAG,QAAQ,MAAM,aAAa;GAClD;EACF,EACF,EACF;CACF;AACF;;;;;;;;;;AAmBA,SAAgB,gBAAgB,UAAkC,CAAC,GAAoB;CACrF,OAAO,WACL;EACE,MAAM;EACN,QAAQ,MAAM,EAAE,MAAM;EACtB,YAAY,CACV,QAAQ,GACR,cAAc;GAAE,QAAQ,QAAQ;GAAQ,eAAe,QAAQ;EAAc,CAAC,CAChF;EACA,aAAa,QAAQ;EACrB,QAAQ,QAAQ;EAChB,MAAM,QAAQ;EACd,MACE,QAAQ,SAAS,QACb,QACA;GACE,MAAM;GACN,OAAO,MAAM,EAAE,MAAM;GACrB,UAAU;IACR;IACA;IACA;IACA;IACA;IACA;IACA;GACF;GACA,GAAG,QAAQ;EACb;CACR,GACA,KACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["BoardBlock"],"sources":["../../src/flow/index.ts"],"sourcesContent":["import { flowKit, type FlowDocument, type FlowEditorProps, type FlowExtension } from '@dou-ui/flow'\nimport { whiteboardKit, type WhiteboardKitOptions } from '@dou-ui/flow/whiteboard'\nimport { ShapesIcon, WorkflowIcon } from '@dou-ui/icons'\nimport { NodeSelection, type Command } from 'prosemirror-state'\nimport { defineComponent, h } from 'vue'\nimport { labelOf, type BlockOption, type EditorExtension, type Label } from '../core/extension'\nimport { escapeHTML } from '../core/output'\nimport { defineBlock } from '../define-block'\nimport { editorLocales } from '../locale'\nimport BoardBlock from './board-block.vue'\nimport {\n boardComments,\n boardOf,\n BOARD_OPEN_EVENT,\n checkBoardProps,\n clampHeight,\n heightOf,\n type BoardBlockSettings,\n} from './board'\n\nexport { boardOf, type BoardCommentTarget } from './board'\n\n/** The props of the fullscreen editor that a flow block may set. */\nexport type FlowBlockEditorProps = Omit<\n FlowEditorProps,\n 'extensions' | 'readonly' | 'fitView' | 'comments' | 'author' | 'activeComment' | 'commentable'\n>\n\nexport interface FlowBlockOptions {\n /** The block type, e.g. `approvalFlow`; unique among the editor's blocks. */\n type: string\n /** What the flow is made of, as the editor's `extensions`. `[flowKit()]` by default. */\n extensions?: (FlowExtension | FlowExtension[])[]\n /** More props for the flow editors, e.g. `nodeTypes`, `portTypes` or `direction`. */\n editorProps?: FlowBlockEditorProps\n /** The block's name: the title of the fullscreen editor, and of its slash menu entry. */\n label: Label\n /** The slash menu entry, or `false` to leave it out (blocks then come from code or pasting). */\n menu?: (Omit<BlockOption, 'key' | 'type' | 'label'> & { key?: string; label?: Label }) | false\n /** The height of a new block in the document, in px. Defaults to `360`. */\n height?: number\n /**\n * Comment threads on the nodes and edges, with the document's\n * `v-model:comments`, `author` and `commentable`. Defaults to `true`;\n * `false` leaves them out of this block type.\n */\n commentable?: boolean\n /**\n * How a block is written in `blocksToHTML`, e.g. an `<img>` of a picture\n * of it the app keeps. By default a `<figure>` with its name, which\n * pasting reads back as the block.\n */\n html?: (board: FlowDocument, block: { id: string; props: Record<string, unknown> }) => string\n}\n\nconst fence = (type: string) => `dou-${type}`\n\nfunction attrsOf(dom: HTMLElement, height: number) {\n let board: unknown = null\n try {\n board = JSON.parse(dom.getAttribute('data-prop-board') ?? 'null')\n } catch {\n // a board that can't be read is an empty one\n }\n // `320`, or written by hand `320px`\n const stored = Number.parseFloat(dom.getAttribute('data-prop-height') ?? '')\n return { board: board ? boardOf(board) : null, height: stored > 0 ? clampHeight(stored) : height }\n}\n\n/** Turns ```dou-<type> fences from Markdown back into blocks. */\nfunction readFences(root: HTMLElement, type: string) {\n for (const code of root.querySelectorAll<HTMLElement>(`pre > code.language-${fence(type)}`)) {\n let written: unknown\n try {\n written = JSON.parse(code.textContent ?? '')\n } catch {\n continue\n }\n // `{ height, board }`, or the board alone\n const wrapped = !!written && typeof written === 'object' && 'board' in written\n const { board, height } = (wrapped ? written : { board: written }) as {\n board: unknown\n height?: unknown\n }\n const element = root.ownerDocument.createElement('div')\n element.dataset.contentType = type\n element.setAttribute('data-prop-board', JSON.stringify(boardOf(board)))\n if (typeof height === 'number') element.setAttribute('data-prop-height', String(height))\n code.parentElement!.replaceWith(element)\n }\n}\n\n/**\n * A block that holds a flow, drawn with `@dou-ui/flow`: the document shows\n * it whole, and it is edited in a fullscreen editor (double-click, the\n * “Edit” button, or `Enter` while the block is selected). The flow is the\n * block's `board` prop; collaboration merges it node by node.\n *\n * ```ts\n * extensions: [editorKit(), flowBlock({ type: 'approvalFlow', label: '审批流程', extensions: [flowKit(), approval()] })]\n * ```\n *\n * Needs `@dou-ui/flow` and its styles. For a whiteboard, `whiteboardBlock()`.\n */\nexport function flowBlock(options: FlowBlockOptions): EditorExtension {\n return boardBlock(options, true)\n}\n\nfunction boardBlock(options: FlowBlockOptions, fallbackNode: boolean): EditorExtension {\n const { type } = options\n const settings: BoardBlockSettings = {\n label: options.label,\n extensions: options.extensions ?? [flowKit()],\n editorProps: options.editorProps ?? {},\n height: options.height ?? 360,\n fallbackNode,\n commentable: options.commentable !== false,\n }\n const View = defineComponent({\n name: 'DouEditorFlowBlockView',\n inheritAttrs: false,\n setup(_props, { attrs }) {\n return () => h(BoardBlock, { ...attrs, settings } as never)\n },\n })\n const menu = options.menu === false ? undefined : options.menu\n const block = defineBlock({\n type,\n props: { board: null, height: settings.height },\n content: 'none',\n component: View,\n // threads on the nodes and edges, kept in the board\n comments: settings.commentable ? boardComments : undefined,\n menu:\n options.menu === false\n ? undefined\n : { icon: WorkflowIcon, ...menu, label: menu?.label ?? options.label },\n spec: {\n mergeProps: { board: { lists: ['nodes', 'edges'], objects: ['data'] } },\n // for `checkDocument`: what the block would read differently\n checkProps: checkBoardProps,\n // what is copied, and what `blocksToHTML` writes\n parseDOM: [`div[data-content-type=\"${type}\"]`, `figure[data-content-type=\"${type}\"]`].map(\n (tag) => ({\n tag,\n // before the figures of images, whatever the app's HTML puts inside\n priority: 70,\n getAttrs: (dom: HTMLElement) => attrsOf(dom, settings.height),\n }),\n ),\n },\n })\n /** `Enter` on the selected block opens it. */\n const open: Command = (state, dispatch, view) => {\n const { selection } = state\n if (!(selection instanceof NodeSelection) || selection.node.type.name !== type) return false\n if (dispatch && view) {\n const dom = view.nodeDOM(selection.from) as HTMLElement | null\n dom?.querySelector('.dou-editor-board')?.dispatchEvent(new CustomEvent(BOARD_OPEN_EVENT))\n }\n return true\n }\n return {\n ...block,\n name: `flow:${type}`,\n keymap: () => ({ enter: open }),\n prepareHTML: (root) => readFences(root, type),\n output: {\n blocks: {\n [type]: {\n html: (node, { children }) => {\n const board = boardOf(node.props.board)\n // written outside an editor: in Chinese, as the other output\n const inside = options.html\n ? options.html(board, node)\n : `<figcaption>${escapeHTML(labelOf(options.label, editorLocales['zh-CN']!))}</figcaption>`\n // the board stays on the figure, so pasting it reads back the block\n return `<figure data-content-type=\"${escapeHTML(type)}\" data-prop-board=\"${escapeHTML(JSON.stringify(board))}\" data-prop-height=\"${heightOf(node.props.height, settings.height)}\">${inside}</figure>${children}`\n },\n markdown: (node, { children }) => {\n const value = {\n height: heightOf(node.props.height, settings.height),\n board: boardOf(node.props.board),\n }\n const written = `\\`\\`\\`${fence(type)}\\n${JSON.stringify(value)}\\n\\`\\`\\``\n return children ? `${written}\\n\\n${children}` : written\n },\n },\n },\n },\n }\n}\n\nexport interface WhiteboardBlockOptions\n extends\n Pick<WhiteboardKitOptions, 'upload' | 'onUploadError'>,\n Pick<FlowBlockOptions, 'height' | 'html' | 'editorProps' | 'commentable'> {\n /** The slash menu entry, or `false` to leave it out. */\n menu?: FlowBlockOptions['menu']\n}\n\n/**\n * A whiteboard block: shapes, sticky notes, text, pen strokes, images and\n * connectors, drawn in a fullscreen editor. Pass the `upload` of `image()`\n * so pictures on the board are uploaded too, not kept in the document.\n *\n * ```ts\n * extensions: [editorKit(), whiteboardBlock({ upload })]\n * ```\n */\nexport function whiteboardBlock(options: WhiteboardBlockOptions = {}): EditorExtension {\n return boardBlock(\n {\n type: 'whiteboard',\n label: (m) => m.types.whiteboard,\n extensions: [\n flowKit(),\n whiteboardKit({ upload: options.upload, onUploadError: options.onUploadError }),\n ],\n editorProps: options.editorProps,\n height: options.height,\n commentable: options.commentable,\n html: options.html,\n menu:\n options.menu === false\n ? false\n : {\n icon: ShapesIcon,\n hint: (m) => m.hints.whiteboard,\n keywords: [\n 'whiteboard',\n 'board',\n 'draw',\n 'flowchart',\n 'baiban',\n 'huatu',\n 'liuchengtu',\n ],\n ...options.menu,\n },\n },\n false,\n )\n}\n"],"mappings":";;;;;;;;;;;;AAuDA,IAAM,SAAS,SAAiB,OAAO;AAEvC,SAAS,QAAQ,KAAkB,QAAgB;CACjD,IAAI,QAAiB;CACrB,IAAI;EACF,QAAQ,KAAK,MAAM,IAAI,aAAa,iBAAiB,KAAK,MAAM;CAClE,QAAQ,CAER;CAEA,MAAM,SAAS,OAAO,WAAW,IAAI,aAAa,kBAAkB,KAAK,EAAE;CAC3E,OAAO;EAAE,OAAO,QAAQ,QAAQ,KAAK,IAAI;EAAM,QAAQ,SAAS,IAAI,YAAY,MAAM,IAAI;CAAO;AACnG;;AAGA,SAAS,WAAW,MAAmB,MAAc;CACnD,KAAK,MAAM,QAAQ,KAAK,iBAA8B,uBAAuB,MAAM,IAAI,GAAG,GAAG;EAC3F,IAAI;EACJ,IAAI;GACF,UAAU,KAAK,MAAM,KAAK,eAAe,EAAE;EAC7C,QAAQ;GACN;EACF;EAGA,MAAM,EAAE,OAAO,WADC,CAAC,CAAC,WAAW,OAAO,YAAY,YAAY,WAAW,UAClC,UAAU,EAAE,OAAO,QAAQ;EAIhE,MAAM,UAAU,KAAK,cAAc,cAAc,KAAK;EACtD,QAAQ,QAAQ,cAAc;EAC9B,QAAQ,aAAa,mBAAmB,KAAK,UAAU,QAAQ,KAAK,CAAC,CAAC;EACtE,IAAI,OAAO,WAAW,UA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rB,MAAM,QAAQ;EACd,MACE,QAAQ,SAAS,QACb,QACA;GACE,MAAM;GACN,OAAO,MAAM,EAAE,MAAM;GACrB,UAAU;IACR;IACA;IACA;IACA;IACA;IACA;IACA;GACF;GACA,GAAG,QAAQ;EACb;CACR,GACA,KACF;AACF"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Editor"],"sources":["../src/index.ts"],"sourcesContent":["import { withInstall } from 'dou-ui'\nimport Editor from './editor.vue'\nimport type { EditorContent } from './define-block'\n\nexport const DouEditor = withInstall(Editor)\nexport default DouEditor\n\nexport { useEditor, useToolbarMenu } from './editor'\nexport type {\n EditorComments,\n EditorContext,\n EditorEmits,\n EditorExpose,\n EditorLinkOpenEvent,\n EditorProps,\n EditorOrigin,\n EditorSelection,\n EditorTransactionResult,\n} from './editor'\nexport { EditorTransaction } from './core/transaction'\nexport type {\n BlockEdge,\n BlockPatch,\n BlockPlacement,\n EditorTransactionMeta,\n} from './core/transaction'\nexport type { BlockChanges } from './core/changes'\nexport type {
|
|
1
|
+
{"version":3,"file":"index.js","names":["Editor"],"sources":["../src/index.ts"],"sourcesContent":["import { withInstall } from 'dou-ui'\nimport Editor from './editor.vue'\nimport type { EditorContent } from './define-block'\n\nexport const DouEditor = withInstall(Editor)\nexport default DouEditor\n\nexport { useEditor, useToolbarMenu } from './editor'\nexport type {\n EditorComments,\n EditorContext,\n EditorEmits,\n EditorExpose,\n EditorLinkOpenEvent,\n EditorProps,\n EditorOrigin,\n EditorSelection,\n EditorTransactionResult,\n} from './editor'\nexport { EditorTransaction } from './core/transaction'\nexport type {\n BlockEdge,\n BlockPatch,\n BlockPlacement,\n EditorTransactionMeta,\n} from './core/transaction'\nexport type { BlockChanges } from './core/changes'\nexport type {\n BlockCommentAnchor,\n BlockCommentsSpec,\n CommentAnchor,\n CommentRange,\n} from './core/comments'\nexport { editorLocales, useEditorMessages } from './locale'\nexport type { EditorMessages, EditorMessagesOverride } from './locale'\nexport { filterOptions } from './catalog'\nexport { defineEditorExtension, labelOf } from './core/extension'\nexport type {\n BlockOption,\n BlockOptionChoice,\n BlockOptionChoices,\n BlockOptionChoicesEmits,\n BlockOptionChoicesProps,\n CommentsProvider,\n EditorExtension,\n EditorExtensionContext,\n FormatOption,\n HistoryProvider,\n Label,\n MountComponent,\n ResolvedEditorExtensions,\n} from './core/extension'\nexport {\n align,\n callout,\n codeBlock,\n colors,\n columns,\n divider,\n formatting,\n heading,\n link,\n lists,\n paragraph,\n quote,\n editorKit,\n table,\n toggle,\n} from './extensions/editor-kit'\nexport type { CalloutTone } from './extensions/callout'\nexport { setHighlight, setTextColor, textColors } from './extensions/colors'\nexport type { TextColor } from './extensions/colors'\nexport { currentAlign, setAlign } from './extensions/align'\nexport { alignable } from './core/align'\nexport type { BlockAlign } from './core/align'\nexport { attachment, formatFileSize, isSafeFileSrc } from './extensions/attachment'\nexport type { AttachmentOptions } from './extensions/attachment'\nexport { embed, resolveEmbed } from './extensions/embed'\nexport type { EmbedOptions, EmbedResolver, EmbedTarget } from './extensions/embed'\nexport {\n alignColumns,\n clearCells,\n deleteColumns,\n deleteRows,\n insertColumn,\n insertRow,\n mergeCells,\n moveLines,\n moveLinesTo,\n splitMergedCell,\n toggleHeader,\n} from './extensions/table'\nexport type { TableAlign, TableColumn } from './extensions/table'\nexport type { EditorKitOptions } from './extensions/editor-kit'\nexport { componentMounter, defineBlock, EditorContent, vueNodeView } from './define-block'\nexport { historyCommands } from './core/editor'\nexport { defaultLanguages } from './extensions/code-block'\nexport type { CodeBlockOptions, CodeHighlighter, CodeLanguage } from './extensions/code-block'\nexport { image, isSafeImageSrc, readAsDataUrl } from './extensions/image'\nexport { mention } from './extensions/mention'\nexport type { MentionItem, MentionOptions } from './extensions/mention'\nexport type { FileUploader, ImageOptions } from './extensions/image'\nexport type { BlockViewProps, DefineBlockOptions } from './define-block'\nexport { atomInputRule, blockInputRule, markInputRule } from './core/input-rules'\nexport type {\n Block,\n BlockProps,\n BreakContent,\n EditorDocument,\n InlineContent,\n InlineNodeContent,\n PartialBlock,\n PartialTableCell,\n PartialTableRow,\n RowsSpec,\n TableCell,\n TableRow,\n TextContent,\n} from './core/model'\nexport { blocksToDoc, createId, docToBlocks } from './core/model'\nexport { diffBlocks, diffText, inlineText } from './core/diff'\nexport type { BlockVersionChange, BlocksDiff, TextPart } from './core/diff'\nexport { searchDoc } from './core/search'\nexport type { EditorMatch, EditorSearchQuery } from './core/search'\nexport { checkDocument, emptyDocument, migrateDocument } from './document'\nexport type { CheckDocumentOptions, DocumentProblem } from './document'\nexport type { BuiltinContentType, ContentType, MarkType } from './core/schema'\nexport { contentDOM, createSchema, isSafeHref, textBlock } from './core/schema'\nexport {\n duplicateBlocks,\n insertBlockAfter,\n liftBlocks,\n swapBlocks,\n moveRangeTo,\n setBlockType,\n sinkBlocks,\n} from './core/commands'\nexport { clearBlockSelection, getBlockSelection, selectBlocks } from './core/block-selection'\nexport { isRemote } from './core/plugins'\nexport { blocksToHTML, htmlToBlocks, type HTMLToBlocksOptions } from './core/convert'\nexport type { DOMParserLike } from './core/prepare'\nexport type { EditorExtensionList } from './core/convert'\nexport { escapeHTML, escapeMarkdown, indentLines } from './core/output'\nexport type {\n BlockOutput,\n BlockOutputContext,\n EditorExtensionOutput,\n InlineOutput,\n MarkdownBlockContext,\n MarkOutput,\n} from './core/output'\nexport { blockElement, splitContainer } from './core/prepare'\n\ndeclare module 'vue' {\n export interface GlobalComponents {\n DouEditor: typeof DouEditor\n DouEditorContent: typeof EditorContent\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAa,YAAY,YAAYA,cAAM"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** A changed range by index: `a[aFrom..aTo)` became `b[bFrom..bTo)`. */
|
|
2
|
+
type Change = [aFrom: number, aTo: number, bFrom: number, bTo: number];
|
|
3
|
+
export interface DiffBudget {
|
|
4
|
+
left: number;
|
|
5
|
+
}
|
|
6
|
+
export declare const createDiffBudget: () => DiffBudget;
|
|
7
|
+
/** The changes between two lists, items compared with `===`, with touching ones joined. */
|
|
8
|
+
export declare function diffLists(a: ArrayLike<unknown>, b: ArrayLike<unknown>, budget?: DiffBudget): Change[];
|
|
9
|
+
export {};
|
|
@@ -18,3 +18,8 @@ export declare function keptIndexes(keys: (string | null)[]): Set<number>;
|
|
|
18
18
|
* keys; the others get fresh keys between their kept neighbours.
|
|
19
19
|
*/
|
|
20
20
|
export declare function orderKeys(keys: (string | null)[]): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Keys only for items inserted or moved between base and written. Other
|
|
23
|
+
* surviving items retain the room's order, including its new items.
|
|
24
|
+
*/
|
|
25
|
+
export declare function changedOrderKeys(before: string[], after: string[], current: Map<string, string | null>, compareIds?: (a: string, b: string) => number): Map<string, string>;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import type { Node as PMNode, NodeType } from 'prosemirror-model';
|
|
2
2
|
import * as Y from 'yjs';
|
|
3
3
|
import { type BlockProps } from '../core/model';
|
|
4
|
+
import type { DiffBudget } from './inline-diff';
|
|
5
|
+
import { type TextUpdatePlan } from './text';
|
|
4
6
|
type YEntry = Y.Map<unknown>;
|
|
5
7
|
/** The table node a stored table stands for. */
|
|
6
8
|
export declare function readTable(yblock: YEntry, type: NodeType, props: BlockProps): PMNode;
|
|
9
|
+
/** Build all cell writes without changing the map, including any diff failures. */
|
|
10
|
+
export declare function prepareTableText(yblock: YEntry, before: PMNode | null, after: PMNode, plans: Map<Y.Text, TextUpdatePlan>, budget?: DiffBudget): void;
|
|
7
11
|
/**
|
|
8
12
|
* Write the table `after` into a stored table that holds `before` (`null`
|
|
9
13
|
* for a new one). Returns whether cells that became visible hold text the
|
|
10
14
|
* editor doesn't show yet, typed by someone else while they were merged away.
|
|
11
15
|
*/
|
|
12
|
-
export declare function writeTable(yblock: YEntry, before: PMNode | null, after: PMNode): boolean;
|
|
16
|
+
export declare function writeTable(yblock: YEntry, before: PMNode | null, after: PMNode, plans?: Map<Y.Text, TextUpdatePlan>): boolean;
|
|
13
17
|
/** Forget a stored table's rows, e.g. when the block stops being a table. */
|
|
14
18
|
export declare function clearTable(yblock: YEntry): void;
|
|
15
19
|
/** The cell a position in a table falls in, and the offset in its text. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Mark, type Node as PMNode, type Schema } from 'prosemirror-model';
|
|
2
2
|
import type * as Y from 'yjs';
|
|
3
|
+
import { type DiffBudget } from './inline-diff';
|
|
3
4
|
export type Attributes = Record<string, unknown>;
|
|
4
5
|
export declare function markAttributes(marks: readonly Mark[], schema: Schema): Attributes;
|
|
5
6
|
/** Write `content`'s inline nodes from `from` to `to` into `text` at `at`. */
|
|
@@ -7,3 +8,22 @@ export declare function insertInline(text: Y.Text, at: number, content: PMNode,
|
|
|
7
8
|
export declare function inlineFrom(text: Y.Text, schema: Schema, code: boolean): PMNode[];
|
|
8
9
|
/** Bring `text` from `before`'s inline content to `after`'s, changing only what differs. */
|
|
9
10
|
export declare function updateText(text: Y.Text, before: PMNode, after: PMNode): void;
|
|
11
|
+
/** Exact content changes, at UTF-16 offsets, never inside a surrogate pair. */
|
|
12
|
+
export declare function inlineChanges(before: PMNode, after: PMNode, budget?: DiffBudget): InlineChange[];
|
|
13
|
+
export type TextUpdatePlan = (text: Y.Text) => void;
|
|
14
|
+
type InlineChange = [number, number, number, number];
|
|
15
|
+
/**
|
|
16
|
+
* Apply base → written edits to the current inline content. Offsets are
|
|
17
|
+
* mapped through the room's edits first; overlapping replacements use
|
|
18
|
+
* written content, while edits elsewhere and their marks remain intact.
|
|
19
|
+
*/
|
|
20
|
+
export declare function prepareTextFromBase(base: PMNode, written: PMNode, current: PMNode, budget?: DiffBudget): TextUpdatePlan;
|
|
21
|
+
/** Used after a complete preflight, so no diff can fail after a map write. */
|
|
22
|
+
export declare function updateTextFromBase(text: Y.Text, base: PMNode, written: PMNode, current: PMNode): void;
|
|
23
|
+
/**
|
|
24
|
+
* `after` with the comment marks of `before` on all unchanged inline
|
|
25
|
+
* fragments, when `after` has none: a version read from Markdown, which
|
|
26
|
+
* doesn't carry them, leaves the threads where the text stays the same.
|
|
27
|
+
*/
|
|
28
|
+
export declare function keepInlineComments(before: PMNode, after: PMNode, budget?: DiffBudget): PMNode;
|
|
29
|
+
export {};
|
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
import { type Node as PMNode } from 'prosemirror-model';
|
|
2
2
|
import { Plugin, PluginKey, type EditorState } from 'prosemirror-state';
|
|
3
3
|
import { DecorationSet, type EditorView } from 'prosemirror-view';
|
|
4
|
+
import type { BlockProps } from './model';
|
|
5
|
+
/** Where a thread is inside a block: what to show for it, and the block's own description of the spot. */
|
|
6
|
+
export interface BlockCommentAnchor<Target = unknown> {
|
|
7
|
+
/** The text of what the thread is about, e.g. a node's label; `''` when it has none. */
|
|
8
|
+
text: string;
|
|
9
|
+
/** Where in the block, as the block describes it, e.g. `{ node: 'n1' }`. */
|
|
10
|
+
target: Target;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* How a block type keeps comment threads on what is inside it, in its
|
|
14
|
+
* props: the `comments` field of its spec. The block's component starts
|
|
15
|
+
* and shows those threads itself (see `useEditor().comments`); the editor
|
|
16
|
+
* lists them in `getCommentAnchors()`, leaves them out of pasted copies,
|
|
17
|
+
* and puts them back after undo and redo, which restore older props.
|
|
18
|
+
*/
|
|
19
|
+
export interface BlockCommentsSpec<Target = unknown> {
|
|
20
|
+
/** The threads in the block, by id. */
|
|
21
|
+
anchors: (props: BlockProps) => Record<string, BlockCommentAnchor<Target>>;
|
|
22
|
+
/** The props with thread `id` on `target`; `null` when that isn't in the block any more. */
|
|
23
|
+
place: (props: BlockProps, id: string, target: Target) => BlockProps | null;
|
|
24
|
+
/** The props with only the threads `keep` says yes to. */
|
|
25
|
+
strip: (props: BlockProps, keep: (id: string) => boolean) => BlockProps;
|
|
26
|
+
}
|
|
27
|
+
declare module 'prosemirror-model' {
|
|
28
|
+
interface NodeSpec {
|
|
29
|
+
/** Comment threads kept inside the block's props, see `BlockCommentsSpec`. */
|
|
30
|
+
comments?: BlockCommentsSpec<any>;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** The `comments` of a node's spec: a block type that keeps threads inside. */
|
|
34
|
+
export declare const blockCommentsOf: (node: PMNode) => BlockCommentsSpec | undefined;
|
|
4
35
|
/** A range of the document, as positions. */
|
|
5
36
|
export interface CommentRange {
|
|
6
37
|
from: number;
|
|
@@ -8,12 +39,17 @@ export interface CommentRange {
|
|
|
8
39
|
}
|
|
9
40
|
/** Where a thread is anchored: the block and the text it is about. */
|
|
10
41
|
export interface CommentAnchor {
|
|
11
|
-
/** The id of the (first) block holding the text. */
|
|
42
|
+
/** The id of the (first) block holding the text, or of the block the thread is inside. */
|
|
12
43
|
block: string;
|
|
13
|
-
/** The text the thread is about. */
|
|
44
|
+
/** The text the thread is about; inside a block, what the block shows for it (e.g. a node's label). */
|
|
14
45
|
text: string;
|
|
46
|
+
/** The text's first and last positions; inside a block, the block's. */
|
|
15
47
|
from: number;
|
|
16
48
|
to: number;
|
|
49
|
+
/** Inside a block: the block's type. */
|
|
50
|
+
type?: string;
|
|
51
|
+
/** Inside a block: where, as the block describes it (e.g. `{ node: 'n1' }` on a whiteboard). */
|
|
52
|
+
target?: unknown;
|
|
17
53
|
}
|
|
18
54
|
export interface CommentPluginState {
|
|
19
55
|
/** The text a thread is being started on, until its first comment is sent. */
|
|
@@ -38,7 +74,7 @@ export declare function commentAnchors(doc: PMNode): Map<string, CommentAnchor>;
|
|
|
38
74
|
export declare function commentRange(doc: PMNode, id: string): CommentRange | null;
|
|
39
75
|
/** Marks `range` as the text of a new thread. Not undone with the edits around it. */
|
|
40
76
|
export declare function anchorComment(view: EditorView, range: CommentRange, id: string): void;
|
|
41
|
-
/** Takes a removed thread's anchor off the text. */
|
|
77
|
+
/** Takes a removed thread's anchor off the text, or out of the block it is inside. */
|
|
42
78
|
export declare function unanchorComment(view: EditorView, id: string): void;
|
|
43
79
|
export declare function setPendingComment(view: EditorView, range: CommentRange | null): void;
|
|
44
80
|
export declare function commentPlugin(options: CommentPluginOptions): Plugin<CommentPluginState>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { NodeSpec } from 'prosemirror-model';
|
|
2
2
|
import type { NodeViewConstructor } from 'prosemirror-view';
|
|
3
3
|
import { type AppContext, type Component, type InjectionKey, type PropType } from 'vue';
|
|
4
|
+
import type { BlockCommentsSpec } from './core/comments';
|
|
4
5
|
import type { BlockOption, EditorExtension, Label, MountComponent } from './core/extension';
|
|
5
6
|
import type { BlockProps } from './core/model';
|
|
6
7
|
/** What a block's Vue component receives. */
|
|
@@ -11,13 +12,19 @@ export interface BlockViewProps {
|
|
|
11
12
|
type: string;
|
|
12
13
|
props: BlockProps;
|
|
13
14
|
};
|
|
14
|
-
/**
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Change props; the change goes into the document, the undo history and
|
|
17
|
+
* collaboration. `history: false` keeps it out of the undo history, e.g.
|
|
18
|
+
* for the id of a comment thread put inside the block.
|
|
19
|
+
*/
|
|
20
|
+
updateProps: (props: BlockProps, options?: {
|
|
21
|
+
history?: boolean;
|
|
22
|
+
}) => void;
|
|
16
23
|
/** The block is selected as a whole (a block without text was clicked). */
|
|
17
24
|
selected: boolean;
|
|
18
25
|
editable: boolean;
|
|
19
26
|
}
|
|
20
|
-
export interface DefineBlockOptions {
|
|
27
|
+
export interface DefineBlockOptions<Target = unknown> {
|
|
21
28
|
type: string;
|
|
22
29
|
/** The props and their defaults. They are stored in the document, as `Block.props`. */
|
|
23
30
|
props?: Record<string, unknown>;
|
|
@@ -27,6 +34,11 @@ export interface DefineBlockOptions {
|
|
|
27
34
|
component?: Component;
|
|
28
35
|
/** `Enter` at the end continues with the same type, like a list. */
|
|
29
36
|
continues?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Comment threads on what is inside the block, kept in its props: how
|
|
39
|
+
* to find, put back and strip them. See `BlockCommentsSpec`.
|
|
40
|
+
*/
|
|
41
|
+
comments?: BlockCommentsSpec<Target>;
|
|
30
42
|
/** Entries for the slash menu and the “turn into” menus; one is made from `menu` when given. */
|
|
31
43
|
menu?: Omit<BlockOption, 'key' | 'type'> & {
|
|
32
44
|
key?: string;
|
|
@@ -62,5 +74,5 @@ export declare function vueNodeView(component: Component, appContext: AppContext
|
|
|
62
74
|
* Declare a block type rendered by a Vue component (or by plain DOM), with
|
|
63
75
|
* its props stored in the document. Returns an extension for `extensions`.
|
|
64
76
|
*/
|
|
65
|
-
export declare function defineBlock(options: DefineBlockOptions): EditorExtension;
|
|
77
|
+
export declare function defineBlock<Target = unknown>(options: DefineBlockOptions<Target>): EditorExtension;
|
|
66
78
|
export type { Label };
|
package/dist/types/editor.d.ts
CHANGED
|
@@ -218,7 +218,15 @@ export interface EditorComments {
|
|
|
218
218
|
selection: () => CommentRange | null;
|
|
219
219
|
/** Start a thread on the selected text, or open the one the cursor is in. */
|
|
220
220
|
start: () => boolean;
|
|
221
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Make a change to the threads. A new thread goes on the text being
|
|
223
|
+
* commented on; with `anchored`, its block already put it inside (see
|
|
224
|
+
* `BlockCommentsSpec`). A removed thread is taken off its text or block.
|
|
225
|
+
*/
|
|
226
|
+
apply: (action: CommentAction, options?: {
|
|
227
|
+
anchored?: boolean;
|
|
228
|
+
}) => void;
|
|
229
|
+
/** Open a thread: beside its text, or inside its block, which watches `active`. */
|
|
222
230
|
open: (id: string | null) => void;
|
|
223
231
|
/** Close the card, dropping a thread not yet started. */
|
|
224
232
|
close: () => void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { FlowDocument, FlowExtension } from '@dou-ui/flow';
|
|
1
|
+
import type { FlowCommentAnchor, FlowDocument, FlowExtension } from '@dou-ui/flow';
|
|
2
2
|
import type { Node as PMNode } from 'prosemirror-model';
|
|
3
|
+
import type { BlockCommentsSpec } from '../core/comments';
|
|
3
4
|
import type { Label } from '../core/extension';
|
|
4
5
|
import type { FlowBlockEditorProps } from './index';
|
|
5
6
|
/** Sent to a block's element to open its fullscreen editor (`Enter` on the selected block). */
|
|
@@ -17,11 +18,13 @@ export interface BoardBlockSettings {
|
|
|
17
18
|
height: number;
|
|
18
19
|
/** When the extensions offer no node to add, offer one with ports (not on a whiteboard, which has its tools). */
|
|
19
20
|
fallbackNode: boolean;
|
|
21
|
+
/** Threads can be started and shown on the nodes and edges, with the document's comments. */
|
|
22
|
+
commentable: boolean;
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
22
25
|
* A block's `board` prop as a flow document; one that is missing or not
|
|
23
26
|
* shaped like one is read as an empty flow (nodes and edges that aren't
|
|
24
|
-
* objects are left out).
|
|
27
|
+
* objects, and edges without valid endpoints, are left out).
|
|
25
28
|
*/
|
|
26
29
|
export declare function boardOf(value: unknown): FlowDocument;
|
|
27
30
|
export declare const clampHeight: (height: number) => number;
|
|
@@ -38,3 +41,13 @@ export declare function checkBoardProps(props: Record<string, unknown>): {
|
|
|
38
41
|
* person can't see there.
|
|
39
42
|
*/
|
|
40
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>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type FlowDocument, type FlowEditorProps, type FlowExtension } from '@dou-ui/flow';
|
|
2
2
|
import { type WhiteboardKitOptions } from '@dou-ui/flow/whiteboard';
|
|
3
3
|
import { type BlockOption, type EditorExtension, type Label } from '../core/extension';
|
|
4
|
-
export { boardOf } from './board';
|
|
4
|
+
export { boardOf, type BoardCommentTarget } from './board';
|
|
5
5
|
/** The props of the fullscreen editor that a flow block may set. */
|
|
6
6
|
export type FlowBlockEditorProps = Omit<FlowEditorProps, 'extensions' | 'readonly' | 'fitView' | 'comments' | 'author' | 'activeComment' | 'commentable'>;
|
|
7
7
|
export interface FlowBlockOptions {
|
|
@@ -20,6 +20,12 @@ export interface FlowBlockOptions {
|
|
|
20
20
|
}) | false;
|
|
21
21
|
/** The height of a new block in the document, in px. Defaults to `360`. */
|
|
22
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;
|
|
23
29
|
/**
|
|
24
30
|
* How a block is written in `blocksToHTML`, e.g. an `<img>` of a picture
|
|
25
31
|
* of it the app keeps. By default a `<figure>` with its name, which
|
|
@@ -43,7 +49,7 @@ export interface FlowBlockOptions {
|
|
|
43
49
|
* Needs `@dou-ui/flow` and its styles. For a whiteboard, `whiteboardBlock()`.
|
|
44
50
|
*/
|
|
45
51
|
export declare function flowBlock(options: FlowBlockOptions): EditorExtension;
|
|
46
|
-
export interface WhiteboardBlockOptions extends Pick<WhiteboardKitOptions, 'upload' | 'onUploadError'>, Pick<FlowBlockOptions, 'height' | 'html' | 'editorProps'> {
|
|
52
|
+
export interface WhiteboardBlockOptions extends Pick<WhiteboardKitOptions, 'upload' | 'onUploadError'>, Pick<FlowBlockOptions, 'height' | 'html' | 'editorProps' | 'commentable'> {
|
|
47
53
|
/** The slash menu entry, or `false` to leave it out. */
|
|
48
54
|
menu?: FlowBlockOptions['menu'];
|
|
49
55
|
}
|