@dou-ui/editor 0.1.0-alpha.2 → 0.1.0-alpha.21

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 (168) hide show
  1. package/dist/code/code-editor-block.js.map +1 -1
  2. package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js +1 -0
  3. package/dist/code/code-editor-block.vue_vue_type_script_setup_true_lang.js.map +1 -1
  4. package/dist/collaboration/binding.js +371 -57
  5. package/dist/collaboration/binding.js.map +1 -1
  6. package/dist/collaboration/cursors.js +42 -10
  7. package/dist/collaboration/cursors.js.map +1 -1
  8. package/dist/collaboration/index.js +61 -11
  9. package/dist/collaboration/index.js.map +1 -1
  10. package/dist/collaboration/inline-diff.js +138 -0
  11. package/dist/collaboration/inline-diff.js.map +1 -0
  12. package/dist/collaboration/merged-props.js +152 -0
  13. package/dist/collaboration/merged-props.js.map +1 -0
  14. package/dist/collaboration/order.js +41 -1
  15. package/dist/collaboration/order.js.map +1 -1
  16. package/dist/collaboration/table.js +64 -25
  17. package/dist/collaboration/table.js.map +1 -1
  18. package/dist/collaboration/text.js +213 -1
  19. package/dist/collaboration/text.js.map +1 -1
  20. package/dist/components/block-handle.js.map +1 -1
  21. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js +125 -17
  22. package/dist/components/block-handle.vue_vue_type_script_setup_true_lang.js.map +1 -1
  23. package/dist/components/bubble-toolbar.js.map +1 -1
  24. package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js +2 -1
  25. package/dist/components/bubble-toolbar.vue_vue_type_script_setup_true_lang.js.map +1 -1
  26. package/dist/components/comment-card.js.map +1 -1
  27. package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js +2 -1
  28. package/dist/components/comment-card.vue_vue_type_script_setup_true_lang.js.map +1 -1
  29. package/dist/components/slash-choices.js +6 -0
  30. package/dist/components/slash-choices.js.map +1 -0
  31. package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js +56 -0
  32. package/dist/components/slash-choices.vue_vue_type_script_setup_true_lang.js.map +1 -0
  33. package/dist/components/slash-menu.js.map +1 -1
  34. package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js +185 -20
  35. package/dist/components/slash-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  36. package/dist/core/block-selection.js +32 -4
  37. package/dist/core/block-selection.js.map +1 -1
  38. package/dist/core/blocks.js +21 -3
  39. package/dist/core/blocks.js.map +1 -1
  40. package/dist/core/commands.js +125 -13
  41. package/dist/core/commands.js.map +1 -1
  42. package/dist/core/comments.js +85 -3
  43. package/dist/core/comments.js.map +1 -1
  44. package/dist/core/convert.js +3 -3
  45. package/dist/core/convert.js.map +1 -1
  46. package/dist/core/editor.js +2 -1
  47. package/dist/core/editor.js.map +1 -1
  48. package/dist/core/extension.js +6 -2
  49. package/dist/core/extension.js.map +1 -1
  50. package/dist/core/model.js +10 -3
  51. package/dist/core/model.js.map +1 -1
  52. package/dist/core/plugins.js +108 -5
  53. package/dist/core/plugins.js.map +1 -1
  54. package/dist/core/prepare.js +12 -5
  55. package/dist/core/prepare.js.map +1 -1
  56. package/dist/core/schema.js.map +1 -1
  57. package/dist/core/transaction.js +19 -4
  58. package/dist/core/transaction.js.map +1 -1
  59. package/dist/define-block.js +8 -4
  60. package/dist/define-block.js.map +1 -1
  61. package/dist/document.js +59 -4
  62. package/dist/document.js.map +1 -1
  63. package/dist/dom.js +112 -13
  64. package/dist/dom.js.map +1 -1
  65. package/dist/editor.js.map +1 -1
  66. package/dist/editor.vue_vue_type_script_setup_true_lang.js +3 -3
  67. package/dist/editor.vue_vue_type_script_setup_true_lang.js.map +1 -1
  68. package/dist/editor2.js.map +1 -1
  69. package/dist/extensions/align/align-menu.js.map +1 -1
  70. package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js +4 -6
  71. package/dist/extensions/align/align-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  72. package/dist/extensions/callout/html.js +5 -4
  73. package/dist/extensions/callout/html.js.map +1 -1
  74. package/dist/extensions/colors/color-menu.js.map +1 -1
  75. package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js +6 -8
  76. package/dist/extensions/colors/color-menu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  77. package/dist/extensions/columns/column-picker.js +6 -0
  78. package/dist/extensions/columns/column-picker.js.map +1 -0
  79. package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js +57 -0
  80. package/dist/extensions/columns/column-picker.vue_vue_type_script_setup_true_lang.js.map +1 -0
  81. package/dist/extensions/columns/columns-controls.js +6 -0
  82. package/dist/extensions/columns/columns-controls.js.map +1 -0
  83. package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js +341 -0
  84. package/dist/extensions/columns/columns-controls.vue_vue_type_script_setup_true_lang.js.map +1 -0
  85. package/dist/extensions/columns/html.js +34 -0
  86. package/dist/extensions/columns/html.js.map +1 -0
  87. package/dist/extensions/columns/index.js +57 -0
  88. package/dist/extensions/columns/index.js.map +1 -0
  89. package/dist/extensions/columns/keys.js +53 -0
  90. package/dist/extensions/columns/keys.js.map +1 -0
  91. package/dist/extensions/columns/plugin.js +213 -0
  92. package/dist/extensions/columns/plugin.js.map +1 -0
  93. package/dist/extensions/columns/schema.js +58 -0
  94. package/dist/extensions/columns/schema.js.map +1 -0
  95. package/dist/extensions/columns/select-columns.js +6 -0
  96. package/dist/extensions/columns/select-columns.js.map +1 -0
  97. package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js +71 -0
  98. package/dist/extensions/columns/select-columns.vue_vue_type_script_setup_true_lang.js.map +1 -0
  99. package/dist/extensions/editor-kit.js +3 -1
  100. package/dist/extensions/editor-kit.js.map +1 -1
  101. package/dist/extensions/list-html.js +1 -1
  102. package/dist/extensions/list-html.js.map +1 -1
  103. package/dist/extensions/table/plugin.js +33 -1
  104. package/dist/extensions/table/plugin.js.map +1 -1
  105. package/dist/extensions/table/table-controls.js.map +1 -1
  106. package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js +1 -1
  107. package/dist/extensions/table/table-controls.vue_vue_type_script_setup_true_lang.js.map +1 -1
  108. package/dist/extensions/table/view.js +25 -1
  109. package/dist/extensions/table/view.js.map +1 -1
  110. package/dist/flow/board-block.js +6 -0
  111. package/dist/flow/board-block.js.map +1 -0
  112. package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js +659 -0
  113. package/dist/flow/board-block.vue_vue_type_script_setup_true_lang.js.map +1 -0
  114. package/dist/flow/board.js +221 -0
  115. package/dist/flow/board.js.map +1 -0
  116. package/dist/flow/index.js +173 -0
  117. package/dist/flow/index.js.map +1 -0
  118. package/dist/index.js +3 -2
  119. package/dist/index.js.map +1 -1
  120. package/dist/locale.js +78 -6
  121. package/dist/locale.js.map +1 -1
  122. package/dist/markdown/index.js +2 -2
  123. package/dist/markdown/index.js.map +1 -1
  124. package/dist/style.css +1 -1
  125. package/dist/style.js +2 -1
  126. package/dist/types/collaboration/binding.d.ts +12 -0
  127. package/dist/types/collaboration/cursors.d.ts +29 -1
  128. package/dist/types/collaboration/index.d.ts +53 -6
  129. package/dist/types/collaboration/inline-diff.d.ts +9 -0
  130. package/dist/types/collaboration/merged-props.d.ts +20 -0
  131. package/dist/types/collaboration/order.d.ts +5 -0
  132. package/dist/types/collaboration/table.d.ts +5 -1
  133. package/dist/types/collaboration/text.d.ts +20 -0
  134. package/dist/types/components/slash-choices.vue.d.ts +18 -0
  135. package/dist/types/core/blocks.d.ts +10 -0
  136. package/dist/types/core/commands.d.ts +17 -2
  137. package/dist/types/core/comments.d.ts +39 -3
  138. package/dist/types/core/convert.d.ts +10 -2
  139. package/dist/types/core/extension.d.ts +58 -4
  140. package/dist/types/core/model.d.ts +6 -1
  141. package/dist/types/core/plugins.d.ts +9 -0
  142. package/dist/types/core/prepare.d.ts +16 -2
  143. package/dist/types/core/schema.d.ts +1 -1
  144. package/dist/types/core/transaction.d.ts +6 -0
  145. package/dist/types/define-block.d.ts +16 -4
  146. package/dist/types/document.d.ts +5 -2
  147. package/dist/types/dom.d.ts +43 -4
  148. package/dist/types/editor.d.ts +9 -1
  149. package/dist/types/editor.vue.d.ts +24 -0
  150. package/dist/types/extensions/columns/column-picker.vue.d.ts +10 -0
  151. package/dist/types/extensions/columns/columns-controls.vue.d.ts +3 -0
  152. package/dist/types/extensions/columns/html.d.ts +10 -0
  153. package/dist/types/extensions/columns/index.d.ts +9 -0
  154. package/dist/types/extensions/columns/keys.d.ts +6 -0
  155. package/dist/types/extensions/columns/plugin.d.ts +28 -0
  156. package/dist/types/extensions/columns/schema.d.ts +17 -0
  157. package/dist/types/extensions/columns/select-columns.vue.d.ts +13 -0
  158. package/dist/types/extensions/editor-kit.d.ts +4 -1
  159. package/dist/types/extensions/table/view.d.ts +8 -1
  160. package/dist/types/flow/board-block.vue.d.ts +16 -0
  161. package/dist/types/flow/board.d.ts +53 -0
  162. package/dist/types/flow/index.d.ts +65 -0
  163. package/dist/types/index.d.ts +29 -4
  164. package/dist/types/locale.d.ts +34 -0
  165. package/dist/types/markdown/index.d.ts +8 -1
  166. package/dist/use-comments.js +2 -2
  167. package/dist/use-comments.js.map +1 -1
  168. package/package.json +14 -5
@@ -0,0 +1,213 @@
1
+ import { blockAround, blocksIn, layoutOf, siblingRangeBetween } from "../../core/blocks.js";
2
+ import { getBlockSelection, selectBlocks } from "../../core/block-selection.js";
3
+ import { changesBlockStructure, isRemote } from "../../core/plugins.js";
4
+ import { Plugin, PluginKey, Selection, TextSelection } from "prosemirror-state";
5
+ import { Decoration, DecorationSet } from "prosemirror-view";
6
+ import { AttrStep } from "prosemirror-transform";
7
+ // src/extensions/columns/plugin.ts
8
+ var descends = (node) => node.type.name === "block" || node.type.name === "blockGroup";
9
+ /** Remove the block at `pos`, or its group when it is the only block there (a group may not be empty). */
10
+ function removeBlock(tr, pos) {
11
+ const $pos = tr.doc.resolve(pos);
12
+ const node = tr.doc.nodeAt(pos);
13
+ if ($pos.parent.type.name === "blockGroup" && $pos.parent.childCount === 1) tr.delete($pos.before(), $pos.after());
14
+ else tr.delete(pos, pos + node.nodeSize);
15
+ }
16
+ /** Put the block at `pos` in place of its children. */
17
+ function unwrap(tr, pos, block) {
18
+ const group = block.childCount > 1 ? block.child(1) : null;
19
+ if (group) tr.replaceWith(pos, pos + block.nodeSize, group.content);
20
+ else removeBlock(tr, pos);
21
+ }
22
+ /**
23
+ * Find the first thing wrong with the columns of `tr.doc` and fix it.
24
+ * Fixes only move and remove blocks, never add any: two editors fixing
25
+ * the same remote change both end up with the same document.
26
+ */
27
+ function fixOne(tr) {
28
+ const doc = tr.doc;
29
+ const first = tr.steps.length;
30
+ const map = (pos) => tr.mapping.slice(first).map(pos);
31
+ let fixed = false;
32
+ doc.descendants((node, pos) => {
33
+ if (fixed) return false;
34
+ if (node.type.name !== "block") return descends(node);
35
+ const layout = layoutOf(node);
36
+ if (!layout) return true;
37
+ const $pos = doc.resolve(pos);
38
+ const owner = $pos.depth > 0 ? $pos.node($pos.depth - 1) : null;
39
+ const group = node.childCount > 1 ? node.child(1) : null;
40
+ if (layout === "column") {
41
+ if (layoutOf(owner) !== "row") unwrap(tr, pos, node);
42
+ else if (!group) removeBlock(tr, pos);
43
+ else return true;
44
+ fixed = true;
45
+ return false;
46
+ }
47
+ for (let depth = $pos.depth; depth > 0; depth--) {
48
+ if (layoutOf($pos.node(depth)) !== "column") continue;
49
+ unwrap(tr, pos, node);
50
+ fixed = true;
51
+ return false;
52
+ }
53
+ if (!group) {
54
+ removeBlock(tr, pos);
55
+ fixed = true;
56
+ return false;
57
+ }
58
+ const columns = [];
59
+ const strays = [];
60
+ const start = pos + 1 + node.firstChild.nodeSize + 1;
61
+ group.forEach((child, offset) => {
62
+ const entry = {
63
+ node: child,
64
+ pos: start + offset
65
+ };
66
+ if (layoutOf(child) === "column") columns.push(entry);
67
+ else strays.push(entry);
68
+ });
69
+ const stray = strays[0];
70
+ if (!columns.length || columns.length === 1 && !stray) {
71
+ const only = columns[0];
72
+ if (only) unwrap(tr, only.pos, only.node);
73
+ unwrap(tr, map(pos), tr.doc.nodeAt(map(pos)));
74
+ fixed = true;
75
+ return false;
76
+ }
77
+ if (stray) {
78
+ const before = columns.filter((column) => column.pos < stray.pos).at(-1);
79
+ const target = before ?? columns[0];
80
+ const at = before ? target.pos + target.node.nodeSize - 2 : target.pos + 1 + target.node.firstChild.nodeSize + 1;
81
+ tr.delete(stray.pos, stray.pos + stray.node.nodeSize);
82
+ tr.insert(map(at), stray.node);
83
+ fixed = true;
84
+ return false;
85
+ }
86
+ return true;
87
+ });
88
+ if (fixed && tr.doc.childCount === 0) {
89
+ const schema = tr.doc.type.schema;
90
+ tr.insert(0, schema.nodes.block.create(null, schema.nodes.paragraph.create()));
91
+ }
92
+ return fixed;
93
+ }
94
+ /** Each column's width, as a style on its block, and its name for screen readers. */
95
+ function widths(doc, preview, label) {
96
+ const decorations = [];
97
+ doc.descendants((node, pos) => {
98
+ if (node.type.name !== "block") return descends(node);
99
+ if (layoutOf(node) !== "row") return true;
100
+ const group = node.childCount > 1 ? node.child(1) : null;
101
+ let at = pos + 1 + node.firstChild.nodeSize + 1;
102
+ group?.forEach((column, _offset, index) => {
103
+ const shown = preview?.find((entry) => entry.pos === at);
104
+ const width = shown ? shown.width : column.firstChild.attrs.width;
105
+ if (width && width !== 1) decorations.push(Decoration.node(at, at + column.nodeSize, { style: `--dou-editor-column-width: ${width}` }));
106
+ const inner = at + 1 + column.firstChild.nodeSize;
107
+ if (column.childCount > 1) decorations.push(Decoration.node(inner, inner + column.child(1).nodeSize, { "aria-label": label(index + 1, group.childCount) }));
108
+ at += column.nodeSize;
109
+ });
110
+ return true;
111
+ });
112
+ return DecorationSet.create(doc, decorations);
113
+ }
114
+ var columnsKey = new PluginKey("dou-editor-columns");
115
+ /** Show `preview` widths without changing the document, or stop showing them (`null`). */
116
+ function previewColumns(tr, preview) {
117
+ return tr.setMeta(columnsKey, { preview }).setMeta("addToHistory", false);
118
+ }
119
+ /** Lay the columns out again, e.g. after the locale changed their names. */
120
+ var refreshColumns = (tr) => tr.setMeta(columnsKey, {}).setMeta("addToHistory", false);
121
+ /** The column around a position: the position before its block, or -1 outside columns. */
122
+ function columnAt(state, pos) {
123
+ const $pos = state.doc.resolve(pos);
124
+ for (let depth = $pos.depth; depth > 0; depth--) if (layoutOf($pos.node(depth)) === "column") return $pos.before(depth);
125
+ return -1;
126
+ }
127
+ /**
128
+ * A text selection from one column into another, or between a column and
129
+ * the blocks around the set: the whole blocks instead, so deleting it or
130
+ * typing over it never joins text across columns.
131
+ */
132
+ function selectAcross(state) {
133
+ const { selection } = state;
134
+ if (!(selection instanceof TextSelection) || selection.empty || getBlockSelection(state)) return null;
135
+ const { $from, $to } = selection;
136
+ const doc = state.doc;
137
+ let from = selection.from;
138
+ let to = selection.to;
139
+ if ($to.parentOffset === 0 && $to.parent.isTextblock) {
140
+ const block = blockAround($to);
141
+ const before = block && Selection.findFrom(doc.resolve(block.pos), -1, true);
142
+ if (before && before.from > from) to = before.from;
143
+ }
144
+ if ($from.parentOffset === $from.parent.content.size && $from.parent.isTextblock) {
145
+ const block = blockAround($from);
146
+ const after = block && Selection.findFrom(doc.resolve(block.contentPos + block.content.nodeSize), 1, true);
147
+ if (after && after.from < to) from = after.from;
148
+ }
149
+ if (columnAt(state, from) === columnAt(state, to)) return null;
150
+ const range = siblingRangeBetween(doc, from, to);
151
+ if (!range) return null;
152
+ const blocks = blocksIn(range);
153
+ const [first, last] = [blocks[0].node.attrs.id, blocks.at(-1).node.attrs.id];
154
+ const backwards = selection.head < selection.anchor;
155
+ let result = null;
156
+ selectBlocks(backwards ? last : first, backwards ? first : last)(state, (tr) => {
157
+ result = tr;
158
+ });
159
+ return result;
160
+ }
161
+ /**
162
+ * Keeps columns well formed after every change, also one from another
163
+ * collaborator (the fix is the same everywhere): columns only in a set of
164
+ * columns, at least one block in each, at least two in a set, no set of
165
+ * columns in a column. Lays each column's width on it, and turns a text
166
+ * selection across columns into a selection of the whole blocks.
167
+ */
168
+ function columnsPlugin(label) {
169
+ return new Plugin({
170
+ key: columnsKey,
171
+ state: {
172
+ init: (_config, state) => ({
173
+ decorations: widths(state.doc, null, label),
174
+ preview: null
175
+ }),
176
+ apply: (tr, value, _old, state) => {
177
+ const meta = tr.getMeta(columnsKey);
178
+ let preview = value.preview;
179
+ if (meta?.preview !== void 0) preview = meta.preview;
180
+ else if (preview && tr.docChanged) preview = preview.map((entry) => ({
181
+ ...entry,
182
+ pos: tr.mapping.map(entry.pos)
183
+ }));
184
+ if (meta || tr.docChanged && (changesBlockStructure(tr) || tr.steps.some((step) => step instanceof AttrStep))) return {
185
+ decorations: widths(state.doc, preview, label),
186
+ preview
187
+ };
188
+ if (!tr.docChanged) return value;
189
+ return {
190
+ decorations: value.decorations.map(tr.mapping, tr.doc),
191
+ preview
192
+ };
193
+ }
194
+ },
195
+ appendTransaction(trs, _old, state) {
196
+ if (trs.some((tr) => changesBlockStructure(tr))) {
197
+ const tr = state.tr;
198
+ for (let round = 0; round < 64 && fixOne(tr); round++);
199
+ if (tr.docChanged) {
200
+ if (trs.every(isRemote)) tr.setMeta("addToHistory", false);
201
+ return tr;
202
+ }
203
+ }
204
+ return trs.some((tr) => tr.selectionSet) ? selectAcross(state) : null;
205
+ },
206
+ props: { decorations(state) {
207
+ return this.getState(state)?.decorations;
208
+ } }
209
+ });
210
+ }
211
+ export { columnsKey, columnsPlugin, previewColumns, refreshColumns };
212
+
213
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","names":[],"sources":["../../../src/extensions/columns/plugin.ts"],"sourcesContent":["import type { Node as PMNode } from 'prosemirror-model'\nimport {\n Plugin,\n PluginKey,\n Selection,\n TextSelection,\n type EditorState,\n type Transaction,\n} from 'prosemirror-state'\nimport { AttrStep } from 'prosemirror-transform'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { getBlockSelection, selectBlocks } from '../../core/block-selection'\nimport { blockAround, blocksIn, layoutOf, siblingRangeBetween } from '../../core/blocks'\nimport { changesBlockStructure, isRemote } from '../../core/plugins'\n\nconst descends = (node: PMNode) => node.type.name === 'block' || node.type.name === 'blockGroup'\n\n/** Remove the block at `pos`, or its group when it is the only block there (a group may not be empty). */\nfunction removeBlock(tr: Transaction, pos: number) {\n const $pos = tr.doc.resolve(pos)\n const node = tr.doc.nodeAt(pos)!\n if ($pos.parent.type.name === 'blockGroup' && $pos.parent.childCount === 1)\n tr.delete($pos.before(), $pos.after())\n else tr.delete(pos, pos + node.nodeSize)\n}\n\n/** Put the block at `pos` in place of its children. */\nfunction unwrap(tr: Transaction, pos: number, block: PMNode) {\n const group = block.childCount > 1 ? block.child(1) : null\n if (group) tr.replaceWith(pos, pos + block.nodeSize, group.content)\n else removeBlock(tr, pos)\n}\n\n/**\n * Find the first thing wrong with the columns of `tr.doc` and fix it.\n * Fixes only move and remove blocks, never add any: two editors fixing\n * the same remote change both end up with the same document.\n */\nfunction fixOne(tr: Transaction): boolean {\n const doc = tr.doc\n // positions in `doc`, mapped through this round's steps only\n const first = tr.steps.length\n const map = (pos: number) => tr.mapping.slice(first).map(pos)\n let fixed = false\n doc.descendants((node, pos) => {\n if (fixed) return false\n if (node.type.name !== 'block') return descends(node)\n const layout = layoutOf(node)\n if (!layout) return true\n const $pos = doc.resolve(pos)\n const owner = $pos.depth > 0 ? $pos.node($pos.depth - 1) : null\n const group = node.childCount > 1 ? node.child(1) : null\n if (layout === 'column') {\n // a column outside a set of columns: its blocks take its place\n if (layoutOf(owner) !== 'row') unwrap(tr, pos, node)\n // an empty column goes away\n else if (!group) removeBlock(tr, pos)\n else return true\n fixed = true\n return false\n }\n // a set of columns inside a column: columns don't nest, its columns take its place\n for (let depth = $pos.depth; depth > 0; depth--) {\n if (layoutOf($pos.node(depth)) !== 'column') continue\n unwrap(tr, pos, node)\n fixed = true\n return false\n }\n if (!group) {\n removeBlock(tr, pos)\n fixed = true\n return false\n }\n const columns: { node: PMNode; pos: number }[] = []\n const strays: { node: PMNode; pos: number }[] = []\n const start = pos + 1 + node.firstChild!.nodeSize + 1\n group.forEach((child, offset) => {\n const entry = { node: child, pos: start + offset }\n if (layoutOf(child) === 'column') columns.push(entry)\n else strays.push(entry)\n })\n const stray = strays[0]\n if (!columns.length || (columns.length === 1 && !stray)) {\n // one column (or none) is no set of columns: its blocks take its place\n const only = columns[0]\n if (only) unwrap(tr, only.pos, only.node)\n unwrap(tr, map(pos), tr.doc.nodeAt(map(pos))!)\n fixed = true\n return false\n }\n if (stray) {\n // a block between columns joins the column before it, or the first one\n const before = columns.filter((column) => column.pos < stray.pos).at(-1)\n const target = before ?? columns[0]!\n const at = before\n ? target.pos + target.node.nodeSize - 2\n : target.pos + 1 + target.node.firstChild!.nodeSize + 1\n tr.delete(stray.pos, stray.pos + stray.node.nodeSize)\n tr.insert(map(at), stray.node)\n fixed = true\n return false\n }\n return true\n })\n if (fixed && tr.doc.childCount === 0) {\n const schema = tr.doc.type.schema\n tr.insert(0, schema.nodes.block!.create(null, schema.nodes.paragraph!.create()))\n }\n return fixed\n}\n\n/** A column's width while its bar is dragged: shown, not yet in the document. */\nexport interface ColumnPreview {\n /** The position before the column's block. */\n pos: number\n width: number\n}\n\ninterface ColumnsState {\n decorations: DecorationSet\n preview: ColumnPreview[] | null\n}\n\n/** Each column's width, as a style on its block, and its name for screen readers. */\nfunction widths(doc: PMNode, preview: ColumnPreview[] | null, label: ColumnLabel): DecorationSet {\n const decorations: Decoration[] = []\n doc.descendants((node, pos) => {\n if (node.type.name !== 'block') return descends(node)\n if (layoutOf(node) !== 'row') return true\n const group = node.childCount > 1 ? node.child(1) : null\n let at = pos + 1 + node.firstChild!.nodeSize + 1\n group?.forEach((column, _offset, index) => {\n const shown = preview?.find((entry) => entry.pos === at)\n const width = shown ? shown.width : (column.firstChild!.attrs.width as number | null)\n if (width && width !== 1)\n decorations.push(\n Decoration.node(at, at + column.nodeSize, {\n style: `--dou-editor-column-width: ${width}`,\n }),\n )\n // the column's blocks, named after its place\n const inner = at + 1 + column.firstChild!.nodeSize\n if (column.childCount > 1)\n decorations.push(\n Decoration.node(inner, inner + column.child(1).nodeSize, {\n 'aria-label': label(index + 1, group.childCount),\n }),\n )\n at += column.nodeSize\n })\n return true\n })\n return DecorationSet.create(doc, decorations)\n}\n\n/** The name of a column: its place among the columns of its set. */\nexport type ColumnLabel = (index: number, count: number) => string\n\nexport const columnsKey = new PluginKey<ColumnsState>('dou-editor-columns')\n\n/** Show `preview` widths without changing the document, or stop showing them (`null`). */\nexport function previewColumns(tr: Transaction, preview: ColumnPreview[] | null): Transaction {\n return tr.setMeta(columnsKey, { preview }).setMeta('addToHistory', false)\n}\n\n/** Lay the columns out again, e.g. after the locale changed their names. */\nexport const refreshColumns = (tr: Transaction) =>\n tr.setMeta(columnsKey, {}).setMeta('addToHistory', false)\n\n/** The column around a position: the position before its block, or -1 outside columns. */\nfunction columnAt(state: EditorState, pos: number): number {\n const $pos = state.doc.resolve(pos)\n for (let depth = $pos.depth; depth > 0; depth--)\n if (layoutOf($pos.node(depth)) === 'column') return $pos.before(depth)\n return -1\n}\n\n/**\n * A text selection from one column into another, or between a column and\n * the blocks around the set: the whole blocks instead, so deleting it or\n * typing over it never joins text across columns.\n */\nfunction selectAcross(state: EditorState): Transaction | null {\n const { selection } = state\n if (!(selection instanceof TextSelection) || selection.empty || getBlockSelection(state))\n return null\n // an end at the very start of the next block (or the very end of the one\n // before) is where the browser puts a selection that stops at a line\n // break: that block isn't selected\n const { $from, $to } = selection\n const doc = state.doc\n let from = selection.from\n let to = selection.to\n if ($to.parentOffset === 0 && $to.parent.isTextblock) {\n const block = blockAround($to)\n const before = block && Selection.findFrom(doc.resolve(block.pos), -1, true)\n if (before && before.from > from) to = before.from\n }\n if ($from.parentOffset === $from.parent.content.size && $from.parent.isTextblock) {\n const block = blockAround($from)\n const after =\n block && Selection.findFrom(doc.resolve(block.contentPos + block.content.nodeSize), 1, true)\n if (after && after.from < to) from = after.from\n }\n if (columnAt(state, from) === columnAt(state, to)) return null\n const range = siblingRangeBetween(doc, from, to)\n if (!range) return null\n const blocks = blocksIn(range)\n const [first, last] = [blocks[0]!.node.attrs.id, blocks.at(-1)!.node.attrs.id] as string[]\n const backwards = selection.head < selection.anchor\n let result: Transaction | null = null\n selectBlocks(backwards ? last! : first!, backwards ? first! : last!)(state, (tr) => {\n result = tr\n })\n return result\n}\n\n/**\n * Keeps columns well formed after every change, also one from another\n * collaborator (the fix is the same everywhere): columns only in a set of\n * columns, at least one block in each, at least two in a set, no set of\n * columns in a column. Lays each column's width on it, and turns a text\n * selection across columns into a selection of the whole blocks.\n */\nexport function columnsPlugin(label: ColumnLabel): Plugin<ColumnsState> {\n return new Plugin<ColumnsState>({\n key: columnsKey,\n state: {\n init: (_config, state) => ({ decorations: widths(state.doc, null, label), preview: null }),\n apply: (tr, value, _old, state) => {\n const meta = tr.getMeta(columnsKey) as { preview?: ColumnPreview[] | null } | undefined\n let preview = value.preview\n if (meta?.preview !== undefined) preview = meta.preview\n else if (preview && tr.docChanged)\n preview = preview.map((entry) => ({ ...entry, pos: tr.mapping.map(entry.pos) }))\n if (\n meta ||\n (tr.docChanged &&\n (changesBlockStructure(tr) || tr.steps.some((step) => step instanceof AttrStep)))\n )\n return { decorations: widths(state.doc, preview, label), preview }\n if (!tr.docChanged) return value\n return { decorations: value.decorations.map(tr.mapping, tr.doc), preview }\n },\n },\n appendTransaction(trs, _old, state) {\n if (trs.some((tr) => changesBlockStructure(tr))) {\n const tr = state.tr\n for (let round = 0; round < 64 && fixOne(tr); round++);\n if (tr.docChanged) {\n if (trs.every(isRemote)) tr.setMeta('addToHistory', false)\n return tr\n }\n }\n return trs.some((tr) => tr.selectionSet) ? selectAcross(state) : null\n },\n props: {\n decorations(state) {\n return this.getState(state)?.decorations\n },\n },\n })\n}\n"],"mappings":";;;;;;;AAeA,IAAM,YAAY,SAAiB,KAAK,KAAK,SAAS,WAAW,KAAK,KAAK,SAAS;;AAGpF,S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Aa,KAAK,IAAI;EACnE;EACA,OAAO,EACL,YAAY,OAAO;GACjB,OAAO,KAAK,SAAS,KAAK,CAAC,EAAE;EAC/B,EACF;CACF,CAAC;AACH"}
@@ -0,0 +1,58 @@
1
+ /** A column's width: a positive weight, rounded; anything else is the default (1). */
2
+ function widthOf(value) {
3
+ const width = Number(value);
4
+ if (value === null || value === void 0 || !Number.isFinite(width) || width <= 0) return null;
5
+ return Math.min(100, Math.max(.01, Math.round(width * 1e3) / 1e3));
6
+ }
7
+ var countOf = (props) => {
8
+ const count = Math.round(Number(props.count));
9
+ return Number.isFinite(count) ? Math.min(5, Math.max(2, count)) : 2;
10
+ };
11
+ /**
12
+ * A set of columns. Its content node holds no text and isn't shown; its
13
+ * children are `column` blocks, laid out side by side.
14
+ */
15
+ var columnsSpec = {
16
+ atom: true,
17
+ selectable: false,
18
+ layout: "row",
19
+ maxColumns: 5,
20
+ /** New columns, `props.count` of them (2 by default), each with an empty paragraph. */
21
+ template: (props) => Array.from({ length: countOf(props) }, () => ({
22
+ type: "column",
23
+ children: [{ type: "paragraph" }]
24
+ })),
25
+ parseDOM: [{ tag: "div[data-content-type=\"columns\"]" }],
26
+ toDOM: () => ["div", {
27
+ class: "dou-editor__content dou-editor__content--columns",
28
+ "data-content-type": "columns"
29
+ }]
30
+ };
31
+ /**
32
+ * One column: its children are the blocks shown in it. `props.width` is
33
+ * its share of the row, a weight against the other columns' (1 when left
34
+ * out), so two people resizing different columns at once both keep theirs.
35
+ */
36
+ var columnSpec = {
37
+ atom: true,
38
+ selectable: false,
39
+ layout: "column",
40
+ attrs: { width: { default: null } },
41
+ optionalProps: ["width"],
42
+ normalizeProps: (attrs) => "width" in attrs ? {
43
+ ...attrs,
44
+ width: widthOf(attrs.width)
45
+ } : attrs,
46
+ parseDOM: [{
47
+ tag: "div[data-content-type=\"column\"]",
48
+ getAttrs: (dom) => ({ width: widthOf(dom.dataset.width) })
49
+ }],
50
+ toDOM: (node) => ["div", {
51
+ class: "dou-editor__content dou-editor__content--column",
52
+ "data-content-type": "column",
53
+ ...node.attrs.width ? { "data-width": String(node.attrs.width) } : {}
54
+ }]
55
+ };
56
+ export { columnSpec, columnsSpec, widthOf };
57
+
58
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","names":[],"sources":["../../../src/extensions/columns/schema.ts"],"sourcesContent":["import type { NodeSpec } from 'prosemirror-model'\nimport type { BlockProps, PartialBlock } from '../../core/model'\n\n/** The most columns a set can have, from the picker or by dropping blocks beside them. */\nexport const MAX_COLUMNS = 5\nexport const MIN_COLUMNS = 2\n\n/** A column's width: a positive weight, rounded; anything else is the default (1). */\nexport function widthOf(value: unknown): number | null {\n const width = Number(value)\n if (value === null || value === undefined || !Number.isFinite(width) || width <= 0) return null\n return Math.min(100, Math.max(0.01, Math.round(width * 1000) / 1000))\n}\n\nconst countOf = (props: BlockProps) => {\n const count = Math.round(Number(props.count))\n return Number.isFinite(count) ? Math.min(MAX_COLUMNS, Math.max(MIN_COLUMNS, count)) : MIN_COLUMNS\n}\n\n/**\n * A set of columns. Its content node holds no text and isn't shown; its\n * children are `column` blocks, laid out side by side.\n */\nexport const columnsSpec: NodeSpec = {\n atom: true,\n selectable: false,\n layout: 'row',\n maxColumns: MAX_COLUMNS,\n /** New columns, `props.count` of them (2 by default), each with an empty paragraph. */\n template: (props: BlockProps): PartialBlock[] =>\n Array.from({ length: countOf(props) }, () => ({\n type: 'column',\n children: [{ type: 'paragraph' }],\n })),\n parseDOM: [{ tag: 'div[data-content-type=\"columns\"]' }],\n toDOM: () => [\n 'div',\n { class: 'dou-editor__content dou-editor__content--columns', 'data-content-type': 'columns' },\n ],\n}\n\n/**\n * One column: its children are the blocks shown in it. `props.width` is\n * its share of the row, a weight against the other columns' (1 when left\n * out), so two people resizing different columns at once both keep theirs.\n */\nexport const columnSpec: NodeSpec = {\n atom: true,\n selectable: false,\n layout: 'column',\n attrs: { width: { default: null } },\n optionalProps: ['width'],\n normalizeProps: (attrs: { width?: unknown }) =>\n 'width' in attrs ? { ...attrs, width: widthOf(attrs.width) } : attrs,\n parseDOM: [\n {\n tag: 'div[data-content-type=\"column\"]',\n getAttrs: (dom) => ({ width: widthOf((dom as HTMLElement).dataset.width) }),\n },\n ],\n toDOM: (node) => [\n 'div',\n {\n class: 'dou-editor__content dou-editor__content--column',\n 'data-content-type': 'column',\n ...(node.attrs.width ? { 'data-width': String(node.attrs.width) } : {}),\n },\n ],\n}\n"],"mappings":";AAQA,SAAgB,QAAQ,OAA+B;CACrD,MAAM,QAAQ,OAAO,KAAK;CAC1B,IAAI,UAAU,QAAQ,UAAU,KAAA,KAAa,CAAC,OAAO,SAAS,KAAK,KAAK,SAAS,GAAG,OAAO;CAC3F,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,KAAM,KAAK,MAAM,QAAQ,GAAI,IAAI,GAAI,CAAC;AACtE;AAEA,IAAM,WAAW,UAAsB;CACrC,MAAM,QAAQ,KAAK,MAAM,OAAO,MAAM,KAAK,CAAC;CAC5C,OAAO,OAAO,SAAS,KAAK,IAAI,KAAK,IAAA,GAAiB,KAAK,IAAA,GAAiB,KAAK,CAAC,IAAA;AACpF;;;;;AAMA,IAAa,cAAwB;CACnC,MAAM;CACN,YAAY;CACZ,QAAQ;CACR,YAAA;;CAEA,WAAW,UACT,MAAM,KAAK,EAAE,QAAQ,QAAQ,KAAK,EAAE,UAAU;EAC5C,MAAM;EACN,UAAU,CAAC,EAAE,MAAM,YAAY,CAAC;CAClC,EAAE;CACJ,UAAU,CAAC,EAAE,KAAK,qCAAmC,CAAC;CACtD,aAAa,CACX,OACA;EAAE,OAAO;EAAoD,qBAAqB;CAAU,CAC9F;AACF;;;;;;AAOA,IAAa,aAAuB;CAClC,MAAM;CACN,YAAY;CACZ,QAAQ;CACR,OAAO,EAAE,OAAO,EAAE,SAAS,KAAK,EAAE;CAClC,eAAe,CAAC,OAAO;CACvB,iBAAiB,UACf,WAAW,QAAQ;EAAE,GAAG;EAAO,OAAO,QAAQ,MAAM,KAAK;CAAE,IAAI;CACjE,UAAU,CACR;EACE,KAAK;EACL,WAAW,SAAS,EAAE,OAAO,QAAS,IAAoB,QAAQ,KAAK,EAAE;CAC3E,CACF;CACA,QAAQ,SAAS,CACf,OACA;EACE,OAAO;EACP,qBAAqB;EACrB,GAAI,KAAK,MAAM,QAAQ,EAAE,cAAc,OAAO,KAAK,MAAM,KAAK,EAAE,IAAI,CAAC;CACvE,CACF;AACF"}
@@ -0,0 +1,6 @@
1
+ import select_columns_vue_vue_type_script_setup_true_lang_default from "./select-columns.vue_vue_type_script_setup_true_lang.js";
2
+ // src/extensions/columns/select-columns.vue
3
+ var select_columns_default = select_columns_vue_vue_type_script_setup_true_lang_default;
4
+ export { select_columns_default as default };
5
+
6
+ //# sourceMappingURL=select-columns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-columns.js","names":["_sfc_main"],"sources":["../../../src/extensions/columns/select-columns.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { DistributeHorizontalIcon, LayoutColumnsIcon } from '@dou-ui/icons'\nimport { DouDropdownItem } from 'dou-ui'\nimport { computed } from 'vue'\nimport { selectBlocks } from '../../core/block-selection'\nimport { findBlockById, layoutOf, parentBlock } from '../../core/blocks'\nimport type { Block } from '../../core/model'\nimport { useEditor } from '../../editor'\n\n/**\n * In the block menu of a block inside columns: select the whole set of\n * columns, to move, copy or remove it with the handle or the keyboard;\n * and, when the columns differ in width, make them even (where the bar\n * between them can't be dragged, e.g. on a touch screen).\n */\nconst props = defineProps<{ block: Block }>()\nconst { view, state, messages } = useEditor()\n\n/** The set of columns around the block, if any. */\nconst row = computed(() => {\n const doc = state.value?.doc\n if (!doc) return null\n for (let info = findBlockById(doc, props.block.id); info; info = parentBlock(doc, info))\n if (layoutOf(info.node) === 'row') return info\n return null\n})\n\n/** Where the content of each column with a width of its own is. */\nconst uneven = computed(() => {\n const info = row.value\n if (!info?.group) return []\n const list: number[] = []\n let pos = info.contentPos + info.content.nodeSize + 1\n info.group.forEach((column) => {\n if (column.firstChild!.attrs.width != null) list.push(pos + 1)\n pos += column.nodeSize\n })\n return list\n})\n\nfunction select() {\n const current = view.value\n if (!current || !row.value) return\n selectBlocks(row.value.node.attrs.id as string)(current.state, current.dispatch)\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction even() {\n const current = view.value\n if (!current || !uneven.value.length) return\n const tr = current.state.tr\n for (const pos of uneven.value) tr.setNodeAttribute(pos, 'width', null)\n current.dispatch(tr)\n requestAnimationFrame(() => view.value?.focus())\n}\n</script>\n\n<template>\n <template v-if=\"row\">\n <DouDropdownItem @click=\"select\">\n <template #prefix><LayoutColumnsIcon /></template>\n {{ messages.columns.select }}\n </DouDropdownItem>\n <DouDropdownItem v-if=\"uneven.length\" @click=\"even\">\n <template #prefix><DistributeHorizontalIcon /></template>\n {{ messages.columns.even }}\n </DouDropdownItem>\n </template>\n</template>\n"],"mappings":""}
@@ -0,0 +1,71 @@
1
+ import { findBlockById, layoutOf, parentBlock } from "../../core/blocks.js";
2
+ import { selectBlocks } from "../../core/block-selection.js";
3
+ import { useEditor } from "../../editor.js";
4
+ import { DouDropdownItem } from "dou-ui";
5
+ import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createTextVNode, createVNode, defineComponent, openBlock, toDisplayString, unref, withCtx } from "vue";
6
+ import { DistributeHorizontalIcon, LayoutColumnsIcon } from "@dou-ui/icons";
7
+ // src/extensions/columns/select-columns.vue?vue&type=script&setup=true&lang.ts
8
+ /**
9
+ * In the block menu of a block inside columns: select the whole set of
10
+ * columns, to move, copy or remove it with the handle or the keyboard;
11
+ * and, when the columns differ in width, make them even (where the bar
12
+ * between them can't be dragged, e.g. on a touch screen).
13
+ */
14
+ var select_columns_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
15
+ __name: "select-columns",
16
+ props: { block: {} },
17
+ setup(__props) {
18
+ const props = __props;
19
+ const { view, state, messages } = useEditor();
20
+ /** The set of columns around the block, if any. */
21
+ const row = computed(() => {
22
+ const doc = state.value?.doc;
23
+ if (!doc) return null;
24
+ for (let info = findBlockById(doc, props.block.id); info; info = parentBlock(doc, info)) if (layoutOf(info.node) === "row") return info;
25
+ return null;
26
+ });
27
+ /** Where the content of each column with a width of its own is. */
28
+ const uneven = computed(() => {
29
+ const info = row.value;
30
+ if (!info?.group) return [];
31
+ const list = [];
32
+ let pos = info.contentPos + info.content.nodeSize + 1;
33
+ info.group.forEach((column) => {
34
+ if (column.firstChild.attrs.width != null) list.push(pos + 1);
35
+ pos += column.nodeSize;
36
+ });
37
+ return list;
38
+ });
39
+ function select() {
40
+ const current = view.value;
41
+ if (!current || !row.value) return;
42
+ selectBlocks(row.value.node.attrs.id)(current.state, current.dispatch);
43
+ requestAnimationFrame(() => view.value?.focus());
44
+ }
45
+ function even() {
46
+ const current = view.value;
47
+ if (!current || !uneven.value.length) return;
48
+ const tr = current.state.tr;
49
+ for (const pos of uneven.value) tr.setNodeAttribute(pos, "width", null);
50
+ current.dispatch(tr);
51
+ requestAnimationFrame(() => view.value?.focus());
52
+ }
53
+ return (_ctx, _cache) => {
54
+ return row.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [createVNode(unref(DouDropdownItem), { onClick: select }, {
55
+ prefix: withCtx(() => [createVNode(unref(LayoutColumnsIcon))]),
56
+ default: withCtx(() => [createTextVNode(" " + toDisplayString(unref(messages).columns.select), 1)]),
57
+ _: 1
58
+ }), uneven.value.length ? (openBlock(), createBlock(unref(DouDropdownItem), {
59
+ key: 0,
60
+ onClick: even
61
+ }, {
62
+ prefix: withCtx(() => [createVNode(unref(DistributeHorizontalIcon))]),
63
+ default: withCtx(() => [createTextVNode(" " + toDisplayString(unref(messages).columns.even), 1)]),
64
+ _: 1
65
+ })) : createCommentVNode("", true)], 64)) : createCommentVNode("", true);
66
+ };
67
+ }
68
+ });
69
+ export { select_columns_vue_vue_type_script_setup_true_lang_default as default };
70
+
71
+ //# sourceMappingURL=select-columns.vue_vue_type_script_setup_true_lang.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-columns.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_Fragment","_createVNode","_unref","_withCtx","_createTextVNode","_toDisplayString","_createBlock","_createCommentVNode"],"sources":["../../../src/extensions/columns/select-columns.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { DistributeHorizontalIcon, LayoutColumnsIcon } from '@dou-ui/icons'\nimport { DouDropdownItem } from 'dou-ui'\nimport { computed } from 'vue'\nimport { selectBlocks } from '../../core/block-selection'\nimport { findBlockById, layoutOf, parentBlock } from '../../core/blocks'\nimport type { Block } from '../../core/model'\nimport { useEditor } from '../../editor'\n\n/**\n * In the block menu of a block inside columns: select the whole set of\n * columns, to move, copy or remove it with the handle or the keyboard;\n * and, when the columns differ in width, make them even (where the bar\n * between them can't be dragged, e.g. on a touch screen).\n */\nconst props = defineProps<{ block: Block }>()\nconst { view, state, messages } = useEditor()\n\n/** The set of columns around the block, if any. */\nconst row = computed(() => {\n const doc = state.value?.doc\n if (!doc) return null\n for (let info = findBlockById(doc, props.block.id); info; info = parentBlock(doc, info))\n if (layoutOf(info.node) === 'row') return info\n return null\n})\n\n/** Where the content of each column with a width of its own is. */\nconst uneven = computed(() => {\n const info = row.value\n if (!info?.group) return []\n const list: number[] = []\n let pos = info.contentPos + info.content.nodeSize + 1\n info.group.forEach((column) => {\n if (column.firstChild!.attrs.width != null) list.push(pos + 1)\n pos += column.nodeSize\n })\n return list\n})\n\nfunction select() {\n const current = view.value\n if (!current || !row.value) return\n selectBlocks(row.value.node.attrs.id as string)(current.state, current.dispatch)\n requestAnimationFrame(() => view.value?.focus())\n}\n\nfunction even() {\n const current = view.value\n if (!current || !uneven.value.length) return\n const tr = current.state.tr\n for (const pos of uneven.value) tr.setNodeAttribute(pos, 'width', null)\n current.dispatch(tr)\n requestAnimationFrame(() => view.value?.focus())\n}\n</script>\n\n<template>\n <template v-if=\"row\">\n <DouDropdownItem @click=\"select\">\n <template #prefix><LayoutColumnsIcon /></template>\n {{ messages.columns.select }}\n </DouDropdownItem>\n <DouDropdownItem v-if=\"uneven.length\" @click=\"even\">\n <template #prefix><DistributeHorizontalIcon /></template>\n {{ messages.columns.even }}\n </DouDropdownItem>\n </template>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;EAeA,MAAM,QAAQ;EACd,MAAM,EAAE,MAAM,OAAO,aAAa,UAAU;;EAG5C,MAAM,MAAM,eAAe;GACzB,MAAM,MAAM,MAAM,OAAO;GACzB,IAAI,CAAC,KAAK,OAAO;GACjB,KAAK,IAAI,OAAO,cAAc,KAAK,MAAM,MAAM,EAAE,GAAG,MAAM,OAAO,YAAY,KAAK,IAAI,GACpF,IAAI,SAAS,KAAK,IAAI,MAAM,OAAO,OAAO;GAC5C,OAAO;EACT,CAAC;;EAGD,MAAM,SAAS,eAAe;GAC5B,MAAM,OAAO,IAAI;GACjB,IAAI,CAAC,MAAM,OAAO,OAAO,CAAC;GAC1B,MAAM,OAAiB,CAAC;GACxB,IAAI,MAAM,KAAK,aAAa,KAAK,QAAQ,WAAW;GACpD,KAAK,MAAM,SAAS,WAAW;IAC7B,IAAI,OAAO,WAAY,MAAM,SAAS,MAAM,KAAK,KAAK,MAAM,CAAC;IAC7D,OAAO,OAAO;GAChB,CAAC;GACD,OAAO;EACT,CAAC;EAED,SAAS,SAAS;GAChB,MAAM,UAAU,KAAK;GACrB,IAAI,CAAC,WAAW,CAAC,IAAI,OAAO;GAC5B,aAAa,IAAI,MAAM,KAAK,MAAM,EAAY,CAAC,CAAC,QAAQ,OAAO,QAAQ,QAAQ;GAC/E,4BAA4B,KAAK,OAAO,MAAM,CAAC;EACjD;EAEA,SAAS,OAAO;GACd,MAAM,UAAU,KAAK;GACrB,IAAI,CAAC,WAAW,CAAC,OAAO,MAAM,QAAQ;GACtC,MAAM,KAAK,QAAQ,MAAM;GACzB,KAAK,MAAM,OAAO,OAAO,OAAO,GAAG,iBAAiB,KAAK,SAAS,IAAI;GACtE,QAAQ,SAAS,EAAE;GACnB,4BAA4B,KAAK,OAAO,MAAM,CAAC;EACjD;;GAIkB,OAAA,IAAA,SAAhBA,UAAA,GAAAC,mBASWC,UAAA,EAAA,KAAA,EAAA,GAAA,CARTC,YAGkBC,MAAA,eAAA,GAAA,EAHA,SAAO,OAAM,GAAA;IAClB,QAAMC,cAAsB,CAArBF,YAAqBC,MAAA,iBAAA,CAAA,C;IAAW,SAAAC,cAClD,CADkDC,gBAAA,MAClDC,gBAAGH,MAAA,QAAA,CAAQ,CAAC,QAAQ,MAAM,GAAA,CAAA,C;;G,IAEL,OAAA,MAAO,UAA9BJ,UAAA,GAAAQ,YAGkBJ,MAAA,eAAA,GAAA;;IAHqB,SAAO;;IACjC,QAAMC,cAA6B,CAA5BF,YAA4BC,MAAA,wBAAA,CAAA,C;IAAW,SAAAC,cACzD,CADyDC,gBAAA,MACzDC,gBAAGH,MAAA,QAAA,CAAQ,CAAC,QAAQ,IAAI,GAAA,CAAA,C"}
@@ -3,6 +3,7 @@ import { align } from "./align/index.js";
3
3
  import { callout } from "./callout/index.js";
4
4
  import { colors } from "./colors/index.js";
5
5
  import { codeBlock } from "./code-block/index.js";
6
+ import { columns } from "./columns/index.js";
6
7
  import { formatting, link } from "./formatting.js";
7
8
  import { lists } from "./lists.js";
8
9
  import { table } from "./table/index.js";
@@ -23,6 +24,7 @@ function editorKit(options = {}) {
23
24
  toggle,
24
25
  callout,
25
26
  table,
27
+ columns,
26
28
  formatting,
27
29
  link,
28
30
  colors,
@@ -30,6 +32,6 @@ function editorKit(options = {}) {
30
32
  };
31
33
  return [paragraph, ...Object.entries(parts).filter(([name]) => options[name] !== false).map(([, extension]) => extension)];
32
34
  }
33
- export { align, callout, codeBlock, colors, divider, editorKit, formatting, heading, link, lists, paragraph, quote, table, toggle };
35
+ export { align, callout, codeBlock, colors, columns, divider, editorKit, formatting, heading, link, lists, paragraph, quote, table, toggle };
34
36
 
35
37
  //# sourceMappingURL=editor-kit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"editor-kit.js","names":[],"sources":["../../src/extensions/editor-kit.ts"],"sourcesContent":["import type { EditorExtension } from '../core/extension'\nimport { divider, heading, paragraph, quote } from './blocks'\nimport { align } from './align'\nimport { callout } from './callout'\nimport { colors } from './colors'\nimport { codeBlock, type CodeBlockOptions } from './code-block'\nimport { formatting, link } from './formatting'\nimport { lists } from './lists'\nimport { table } from './table'\nimport { toggle } from './toggle'\n\nexport interface EditorKitOptions {\n heading?: boolean\n lists?: boolean\n quote?: boolean\n /**\n * Options for the code block, e.g. its highlighter, or `false` to leave\n * it out. Another code block extension takes its place, e.g.\n * `codeEditorBlock()` from `@dou-ui/editor/code`.\n */\n codeBlock?: boolean | CodeBlockOptions | EditorExtension\n divider?: boolean\n toggle?: boolean\n callout?: boolean\n table?: boolean\n formatting?: boolean\n link?: boolean\n /** Text and background colors. */\n colors?: boolean\n /** Aligning paragraphs, headings and quotes. */\n align?: boolean\n}\n\n/**\n * The built-in blocks and formatting. Pass `false` for any part to leave\n * it out, e.g. `editorKit({ codeBlock: false })`.\n */\nexport function editorKit(options: EditorKitOptions = {}): EditorExtension[] {\n const code = options.codeBlock\n const parts = {\n heading,\n lists,\n quote,\n codeBlock:\n typeof code === 'object' && 'name' in code\n ? code\n : codeBlock(typeof code === 'object' ? code : {}),\n divider,\n toggle,\n callout,\n table,\n formatting,\n link,\n colors,\n align,\n }\n return [\n paragraph,\n ...Object.entries(parts)\n .filter(([name]) => options[name as keyof EditorKitOptions] !== false)\n .map(([, extension]) => extension),\n ]\n}\n\nexport {\n align,\n callout,\n colors,\n codeBlock,\n divider,\n formatting,\n heading,\n link,\n lists,\n paragraph,\n quote,\n table,\n toggle,\n}\n"],"mappings":";;;;;;;;;;;;;;AAqCA,SAAgB,UAAU,UAA4B,CAAC,GAAsB;CAC3E,MAAM,OAAO,QAAQ;CACrB,MAAM,QAAQ;EACZ;EACA;EACA;EACA,WACE,OAAO,SAAS,YAAY,UAAU,OAClC,OACA,UAAU,OAAO,SAAS,WAAW,OAAO,CAAC,CAAC;EACpD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,OAAO,CACL,WACA,GAAG,OAAO,QAAQ,KAAK,CAAC,CACrB,QAAQ,CAAC,UAAU,QAAQ,UAAoC,KAAK,CAAC,CACrE,KAAK,GAAG,eAAe,SAAS,CACrC;AACF"}
1
+ {"version":3,"file":"editor-kit.js","names":[],"sources":["../../src/extensions/editor-kit.ts"],"sourcesContent":["import type { EditorExtension } from '../core/extension'\nimport { divider, heading, paragraph, quote } from './blocks'\nimport { align } from './align'\nimport { callout } from './callout'\nimport { colors } from './colors'\nimport { codeBlock, type CodeBlockOptions } from './code-block'\nimport { columns } from './columns'\nimport { formatting, link } from './formatting'\nimport { lists } from './lists'\nimport { table } from './table'\nimport { toggle } from './toggle'\n\nexport interface EditorKitOptions {\n heading?: boolean\n lists?: boolean\n quote?: boolean\n /**\n * Options for the code block, e.g. its highlighter, or `false` to leave\n * it out. Another code block extension takes its place, e.g.\n * `codeEditorBlock()` from `@dou-ui/editor/code`.\n */\n codeBlock?: boolean | CodeBlockOptions | EditorExtension\n divider?: boolean\n toggle?: boolean\n callout?: boolean\n table?: boolean\n /** Blocks side by side in columns. */\n columns?: boolean\n formatting?: boolean\n link?: boolean\n /** Text and background colors. */\n colors?: boolean\n /** Aligning paragraphs, headings and quotes. */\n align?: boolean\n}\n\n/**\n * The built-in blocks and formatting. Pass `false` for any part to leave\n * it out, e.g. `editorKit({ codeBlock: false })`.\n */\nexport function editorKit(options: EditorKitOptions = {}): EditorExtension[] {\n const code = options.codeBlock\n const parts = {\n heading,\n lists,\n quote,\n codeBlock:\n typeof code === 'object' && 'name' in code\n ? code\n : codeBlock(typeof code === 'object' ? code : {}),\n divider,\n toggle,\n callout,\n table,\n columns,\n formatting,\n link,\n colors,\n align,\n }\n return [\n paragraph,\n ...Object.entries(parts)\n .filter(([name]) => options[name as keyof EditorKitOptions] !== false)\n .map(([, extension]) => extension),\n ]\n}\n\nexport {\n align,\n callout,\n colors,\n codeBlock,\n columns,\n divider,\n formatting,\n heading,\n link,\n lists,\n paragraph,\n quote,\n table,\n toggle,\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwCA,SAAgB,UAAU,UAA4B,CAAC,GAAsB;CAC3E,MAAM,OAAO,QAAQ;CACrB,MAAM,QAAQ;EACZ;EACA;EACA;EACA,WACE,OAAO,SAAS,YAAY,UAAU,OAClC,OACA,UAAU,OAAO,SAAS,WAAW,OAAO,CAAC,CAAC;EACpD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,OAAO,CACL,WACA,GAAG,OAAO,QAAQ,KAAK,CAAC,CACrB,QAAQ,CAAC,UAAU,QAAQ,UAAoC,KAAK,CAAC,CACrE,KAAK,GAAG,eAAe,SAAS,CACrC;AACF"}
@@ -42,7 +42,7 @@ function convertList(list) {
42
42
  return blocks;
43
43
  }
44
44
  function firstText(item) {
45
- const walker = item.ownerDocument.createTreeWalker(item, NodeFilter.SHOW_TEXT);
45
+ const walker = item.ownerDocument.createTreeWalker(item, 4);
46
46
  for (let node = walker.nextNode(); node; node = walker.nextNode()) if (node.textContent?.trim()) return node;
47
47
  return null;
48
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"list-html.js","names":[],"sources":["../../src/extensions/list-html.ts"],"sourcesContent":["import { indentLines, type BlockOutputContext } from '../core/output'\nimport { blockElement, splitContainer } from '../core/prepare'\n\nconst TASK = /^\\s*\\[( |x|X)\\]\\s/\n\n/**\n * Lists from other apps nest a list inside an item (`<li>text<ul>…</ul></li>`),\n * but a list item here is a block of text with child blocks. Rewrite them\n * into blocks before parsing, so nesting survives. Task lists\n * (`<li><input type=\"checkbox\">`, or `[ ]` / `[x]` before the text as\n * Markdown writes them) become to-do items.\n */\nexport function prepareLists(root: HTMLElement) {\n const outer = Array.from(root.querySelectorAll('ul, ol')).filter(\n (list) => !list.parentElement?.closest('ul, ol'),\n )\n for (const list of outer) list.replaceWith(...convertList(list))\n}\n\nfunction convertList(list: Element): HTMLElement[] {\n const doc = list.ownerDocument\n const numbered = list.tagName === 'OL'\n const blocks: HTMLElement[] = []\n for (const item of Array.from(list.children)) {\n if (item.tagName !== 'LI') continue\n let type = numbered ? 'numberedItem' : 'bulletItem'\n const data: Record<string, string> = {}\n const checkbox = item.querySelector(\n ':scope > input[type=\"checkbox\"], :scope > p > input[type=\"checkbox\"]',\n )\n if (checkbox) {\n type = 'checkItem'\n data.checked = String(\n (checkbox as HTMLInputElement).checked || checkbox.hasAttribute('checked'),\n )\n checkbox.remove()\n } else {\n const text = firstText(item)\n const match = text && TASK.exec(text.data)\n if (text && match) {\n type = 'checkItem'\n data.checked = String(match[1] !== ' ')\n text.data = text.data.slice(match[0].length)\n }\n }\n // the first paragraph is the item's text; what follows becomes its children\n for (const nested of Array.from(item.children))\n if (nested.tagName === 'UL' || nested.tagName === 'OL')\n nested.replaceWith(...convertList(nested))\n const { content, children } = splitContainer(item)\n blocks.push(blockElement(doc, type, content, children, data))\n }\n return blocks\n}\n\nfunction firstText(item: Element): Text | null {\n const walker = item.ownerDocument.createTreeWalker(item, NodeFilter.SHOW_TEXT)\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (node.textContent?.trim()) return node as Text\n }\n return null\n}\n\n/** A list item in Markdown: the marker, the text, and the children indented under it. */\nexport function listItemMarkdown(marker: string, { content, children }: BlockOutputContext) {\n // a checkbox marker indents its children like the bullet in front of it\n const width = marker.startsWith('- [') ? 2 : marker.length\n const item = indentLines(content, marker, ' '.repeat(width))\n if (!children) return item\n // a nested list follows right after; other blocks need a blank line, or they join the text\n const gap = /^([-*+]|\\d+[.)])( |$)/.test(children) ? '\\n' : '\\n\\n'\n return `${item}${gap}${indentLines(children, ' '.repeat(width))}`\n}\n"],"mappings":";;;AAGA,IAAM,OAAO;;;;;;;;AASb,SAAgB,aAAa,MAAmB;CAC9C,MAAM,QAAQ,MAAM,KAAK,KAAK,iBAAiB,QAA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,OAAO;CAEvC,OAAO;AACT;;AAGA,SAAgB,iBAAiB,QAAgB,EAAE,SAAS,YAAgC;CAE1F,MAAM,QAAQ,OAAO,WAAW,KAAK,IAAI,IAAI,OAAO;CACpD,MAAM,OAAO,YAAY,SAAS,QAAQ,IAAI,OAAO,KAAK,CAAC;CAC3D,IAAI,CAAC,UAAU,OAAO;CAGtB,OAAO,GAAG,OADE,wBAAwB,KAAK,QAAQ,IAAI,OAAO,SACrC,YAAY,UAAU,IAAI,OAAO,KAAK,CAAC;AAChE"}
1
+ {"version":3,"file":"list-html.js","names":[],"sources":["../../src/extensions/list-html.ts"],"sourcesContent":["import { indentLines, type BlockOutputContext } from '../core/output'\nimport { blockElement, splitContainer } from '../core/prepare'\n\nconst TASK = /^\\s*\\[( |x|X)\\]\\s/\n\n/**\n * Lists from other apps nest a list inside an item (`<li>text<ul>…</ul></li>`),\n * but a list item here is a block of text with child blocks. Rewrite them\n * into blocks before parsing, so nesting survives. Task lists\n * (`<li><input type=\"checkbox\">`, or `[ ]` / `[x]` before the text as\n * Markdown writes them) become to-do items.\n */\nexport function prepareLists(root: HTMLElement) {\n const outer = Array.from(root.querySelectorAll('ul, ol')).filter(\n (list) => !list.parentElement?.closest('ul, ol'),\n )\n for (const list of outer) list.replaceWith(...convertList(list))\n}\n\nfunction convertList(list: Element): HTMLElement[] {\n const doc = list.ownerDocument\n const numbered = list.tagName === 'OL'\n const blocks: HTMLElement[] = []\n for (const item of Array.from(list.children)) {\n if (item.tagName !== 'LI') continue\n let type = numbered ? 'numberedItem' : 'bulletItem'\n const data: Record<string, string> = {}\n const checkbox = item.querySelector(\n ':scope > input[type=\"checkbox\"], :scope > p > input[type=\"checkbox\"]',\n )\n if (checkbox) {\n type = 'checkItem'\n data.checked = String(\n (checkbox as HTMLInputElement).checked || checkbox.hasAttribute('checked'),\n )\n checkbox.remove()\n } else {\n const text = firstText(item)\n const match = text && TASK.exec(text.data)\n if (text && match) {\n type = 'checkItem'\n data.checked = String(match[1] !== ' ')\n text.data = text.data.slice(match[0].length)\n }\n }\n // the first paragraph is the item's text; what follows becomes its children\n for (const nested of Array.from(item.children))\n if (nested.tagName === 'UL' || nested.tagName === 'OL')\n nested.replaceWith(...convertList(nested))\n const { content, children } = splitContainer(item)\n blocks.push(blockElement(doc, type, content, children, data))\n }\n return blocks\n}\n\nfunction firstText(item: Element): Text | null {\n // NodeFilter.SHOW_TEXT, as a number: the DOM may come from a library, without globals\n const walker = item.ownerDocument.createTreeWalker(item, 4)\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (node.textContent?.trim()) return node as Text\n }\n return null\n}\n\n/** A list item in Markdown: the marker, the text, and the children indented under it. */\nexport function listItemMarkdown(marker: string, { content, children }: BlockOutputContext) {\n // a checkbox marker indents its children like the bullet in front of it\n const width = marker.startsWith('- [') ? 2 : marker.length\n const item = indentLines(content, marker, ' '.repeat(width))\n if (!children) return item\n // a nested list follows right after; other blocks need a blank line, or they join the text\n const gap = /^([-*+]|\\d+[.)])( |$)/.test(children) ? '\\n' : '\\n\\n'\n return `${item}${gap}${indentLines(children, ' '.repeat(width))}`\n}\n"],"mappings":";;;AAGA,IAAM,OAAO;;;;;;;;AASb,SAAgB,aAAa,MAAmB;CAC9C,MAAM,QAAQ,MAAM,KAAK,KAAK,iBAAiB,QAAQ,CAAC,CAAC,CAAC,QACvD,SAAS,CAAC,KAAK,eAAe,QAAQ,QAAQ,CACjD;CACA,KAAK,MAAM,QAAQ,OAAO,KAAK,YAAY,GAAG,YAAY,IAAI,CAAC;AACjE;AAEA,SAAS,YAAY,MAA8B;CACjD,MAAM,MAAM,KAAK;CACjB,MAAM,WAAW,KAAK,YAAY;CAClC,MAAM,SAAwB,CAAC;CAC/B,KAAK,MAAM,QAAQ,MAAM,KAAK,KAAK,QAAQ,GAAG;EAC5C,IAAI,KAAK,YAAY,MAAM;EAC3B,IAAI,OAAO,WAAW,iBAAiB;EACvC,MAAM,OAA+B,CAAC;EACtC,MAAM,WAAW,KAAK,c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the text column (the surface's padding, from a reading
64
+ * width), in px on the mount, for top-level tables to reach into. Read from
65
+ * the padding the surface already has, so any way of writing the reading
66
+ * width works; kept up to date as the mount or the column changes size.
67
+ */
68
+ var Margins = class {
69
+ view;
70
+ observer = null;
71
+ mount;
72
+ constructor(view) {
73
+ this.view = view;
74
+ const mount = view.dom.parentElement;
75
+ this.mount = mount?.classList.contains("dou-editor__mount") ? mount : null;
76
+ if (!this.mount || typeof ResizeObserver === "undefined") return;
77
+ this.observer = new ResizeObserver(() => this.measure());
78
+ this.observer.observe(this.mount);
79
+ this.observer.observe(view.dom);
80
+ }
81
+ measure() {
82
+ const mount = this.mount;
83
+ if (!mount) return;
84
+ const style = getComputedStyle(this.view.dom);
85
+ for (const [name, value] of [["--dou-editor-margin-start", style.paddingInlineStart], ["--dou-editor-margin-end", style.paddingInlineEnd]]) if (mount.style.getPropertyValue(name) !== value) mount.style.setProperty(name, value);
86
+ }
87
+ destroy() {
88
+ this.observer?.disconnect();
89
+ this.mount?.style.removeProperty("--dou-editor-margin-start");
90
+ this.mount?.style.removeProperty("--dou-editor-margin-end");
91
+ }
92
+ };
62
93
  var tableKey = new PluginKey("dou-editor-table");
63
94
  function tablePlugin() {
64
95
  return new Plugin({
@@ -73,7 +104,8 @@ function tablePlugin() {
73
104
  normalize(state.doc, tr);
74
105
  return tr.docChanged ? tr : null;
75
106
  },
76
- props: { decorations: (state) => tableKey.getState(state) }
107
+ props: { decorations: (state) => tableKey.getState(state) },
108
+ view: (view) => new Margins(view)
77
109
  });
78
110
  }
79
111
  export { tableKey, tablePlugin };
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","names":[],"sources":["../../../src/extensions/table/plugin.ts"],"sourcesContent":["import type { Node as PMNode } from 'prosemirror-model'\nimport { Plugin, PluginKey, type Transaction } from 'prosemirror-state'\nimport { TableMap } from 'prosemirror-tables'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { createId } from '../../core/model'\nimport { fitColumns, isHeaderAt } from './schema'\n\n/** Tables only sit in blocks; text and other content need no visit. */\nconst descends = (node: PMNode) => node.type.name === 'block' || node.type.name === 'blockGroup'\n\nconst sameColumns = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b)\n\n/**\n * Keep every table well formed after each change: a unique id on every\n * row, one column record per column, and header cells exactly where the\n * table's `headerRow` / `headerColumn` say.\n */\nfunction normalize(doc: PMNode, tr: Transaction) {\n const rowIds = new Set<string>()\n doc.descendants((node, pos) => {\n if (node.type.spec.tableRole !== 'table') return descends(node)\n const map = TableMap.get(node)\n const columns = fitColumns(node.attrs.columns, map.width)\n if (!sameColumns(columns, node.attrs.columns)) tr.setNodeAttribute(pos, 'columns', columns)\n const start = pos + 1\n node.forEach((row, offset) => {\n const id = row.attrs.id as string | null\n if (!id || rowIds.has(id)) tr.setNodeAttribute(start + offset, 'id', createId())\n else rowIds.add(id)\n })\n const seen = new Set<number>()\n for (const cellPos of map.map) {\n if (seen.has(cellPos)) continue\n seen.add(cellPos)\n const rect = map.findCell(cellPos)\n const cell = node.nodeAt(cellPos)!\n const header = isHeaderAt(node.attrs, rect.top, rect.left)\n const type = header ? node.type.schema.nodes.tableHeader! : node.type.schema.nodes.tableCell!\n if (cell.type !== type) tr.setNodeMarkup(start + cellPos, type, cell.attrs)\n }\n return false\n })\n}\n\n/** Text alignment per column, laid on the cells. */\nfunction alignments(doc: PMNode): DecorationSet {\n const decorations: Decoration[] = []\n doc.descendants((node, pos) => {\n if (node.type.spec.tableRole !== 'table') return descends(node)\n const columns = node.attrs.columns as { align?: string }[]\n if (!columns.some((column) => column.align)) return false\n const map = TableMap.get(node)\n const seen = new Set<number>()\n for (const cellPos of map.map) {\n if (seen.has(cellPos)) continue\n seen.add(cellPos)\n const align = columns[map.findCell(cellPos).left]?.align\n if (!align) continue\n const cell = node.nodeAt(cellPos)!\n const from = pos + 1 + cellPos\n decorations.push(\n Decoration.node(from, from + cell.nodeSize, { style: `text-align: ${align}` }),\n )\n }\n return false\n })\n return DecorationSet.create(doc, decorations)\n}\n\nexport const tableKey = new PluginKey<DecorationSet>('dou-editor-table')\n\nexport function tablePlugin(): Plugin<DecorationSet> {\n return new Plugin<DecorationSet>({\n key: tableKey,\n state: {\n init: (_config, state) => alignments(state.doc),\n apply: (tr, value, _old, state) => (tr.docChanged ? alignments(state.doc) : value),\n },\n appendTransaction(trs, _old, state) {\n if (!trs.some((tr) => tr.docChanged)) return null\n const tr = state.tr\n normalize(state.doc, tr)\n return tr.docChanged ? tr : null\n },\n props: {\n decorations: (state) => tableKey.getState(state),\n },\n })\n}\n"],"mappings":";;;;;;;AAQA,IAAM,YAAY,SAAiB,KAAK,KAAK,SAAS,WAAW,KAAK,KAAK,SAAS;AAEpF,IAAM,eAAe,GAAY,MAAe,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC;;;;;;AAOtF,SAAS,UAAU,KAAa,IAAiB;CAC/C,MAAM,yBAAS,IAAI,IAAY;CAC/B,IAAI,aAAa,MAAM,QAAQ;EAC7B,IAAI,KAAK,KAAK,KAAK,cAAc,SAAS,OAAO,SAAS,IAAI;EAC9D,MAAM,MAAM,SAAS,IAAI,IAAI;EAC7B,MAAM,UAAU,WAAW,KAAK,MAAM,SAAS,IAAI,KAAK;EACxD,IAAI,CAAC,YAAY,SAAS,KAAK,MAAM,OAAO,GAAG,GAAG,iBAAiB,KAAK,WAAW,OAAO;EAC1F,MAAM,QAAQ,MAAM;EACpB,KAAK,SAAS,KAAK,WAAW;GAC5B,MAAM,KAAK,IAAI,MAAM;GACrB,IAAI,CAAC,MAAM,OAAO,IAAI,EAAE,GAAG,GAAG,iBAAiB,QAAQ,QAAQ,MAAM,SAAS,CAAC;QAC1E,OAAO,IAAI,EAAE;EACpB,CAAC;EACD,MAAM,uBAAO,IAAI,IAAY;EAC7B,KAAK,MAAM,WAAW,IAAI,KAAK;GAC7B,IAAI,KAAK,IAAI,OAAO,GAAG;GACvB,KAAK,IAAI,OAAO;GAChB,MAAM,OAAO,IAAI,SAA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ACA,kBAAkB,KAAK,MAAM,OAAO;GAClC,IAAI,CAAC,IAAI,MAAM,OAAO,GAAG,UAAU,GAAG,OAAO;GAC7C,MAAM,KAAK,MAAM;GACjB,UAAU,MAAM,KAAK,EAAE;GACvB,OAAO,GAAG,aAAa,KAAK;EAC9B;EACA,OAAO,EACL,cAAc,UAAU,SAAS,SAAS,KAAK,EACjD;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"plugin.js","names":[],"sources":["../../../src/extensions/table/plugin.ts"],"sourcesContent":["import type { Node as PMNode } from 'prosemirror-model'\nimport { Plugin, PluginKey, type Transaction } from 'prosemirror-state'\nimport { TableMap } from 'prosemirror-tables'\nimport { Decoration, DecorationSet, type EditorView } from 'prosemirror-view'\nimport { createId } from '../../core/model'\nimport { fitColumns, isHeaderAt } from './schema'\n\n/** Tables only sit in blocks; text and other content need no visit. */\nconst descends = (node: PMNode) => node.type.name === 'block' || node.type.name === 'blockGroup'\n\nconst sameColumns = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b)\n\n/**\n * Keep every table well formed after each change: a unique id on every\n * row, one column record per column, and header cells exactly where the\n * table's `headerRow` / `headerColumn` say.\n */\nfunction normalize(doc: PMNode, tr: Transaction) {\n const rowIds = new Set<string>()\n doc.descendants((node, pos) => {\n if (node.type.spec.tableRole !== 'table') return descends(node)\n const map = TableMap.get(node)\n const columns = fitColumns(node.attrs.columns, map.width)\n if (!sameColumns(columns, node.attrs.columns)) tr.setNodeAttribute(pos, 'columns', columns)\n const start = pos + 1\n node.forEach((row, offset) => {\n const id = row.attrs.id as string | null\n if (!id || rowIds.has(id)) tr.setNodeAttribute(start + offset, 'id', createId())\n else rowIds.add(id)\n })\n const seen = new Set<number>()\n for (const cellPos of map.map) {\n if (seen.has(cellPos)) continue\n seen.add(cellPos)\n const rect = map.findCell(cellPos)\n const cell = node.nodeAt(cellPos)!\n const header = isHeaderAt(node.attrs, rect.top, rect.left)\n const type = header ? node.type.schema.nodes.tableHeader! : node.type.schema.nodes.tableCell!\n if (cell.type !== type) tr.setNodeMarkup(start + cellPos, type, cell.attrs)\n }\n return false\n })\n}\n\n/** Text alignment per column, laid on the cells. */\nfunction alignments(doc: PMNode): DecorationSet {\n const decorations: Decoration[] = []\n doc.descendants((node, pos) => {\n if (node.type.spec.tableRole !== 'table') return descends(node)\n const columns = node.attrs.columns as { align?: string }[]\n if (!columns.some((column) => column.align)) return false\n const map = TableMap.get(node)\n const seen = new Set<number>()\n for (const cellPos of map.map) {\n if (seen.has(cellPos)) continue\n seen.add(cellPos)\n const align = columns[map.findCell(cellPos).left]?.align\n if (!align) continue\n const cell = node.nodeAt(cellPos)!\n const from = pos + 1 + cellPos\n decorations.push(\n Decoration.node(from, from + cell.nodeSize, { style: `text-align: ${align}` }),\n )\n }\n return false\n })\n return DecorationSet.create(doc, decorations)\n}\n\n/**\n * The margins beside the text column (the surface's padding, from a reading\n * width), in px on the mount, for top-level tables to reach into. Read from\n * the padding the surface already has, so any way of writing the reading\n * width works; kept up to date as the mount or the column changes size.\n */\nclass Margins {\n private readonly observer: ResizeObserver | null = null\n private readonly mount: HTMLElement | null\n\n constructor(private readonly view: EditorView) {\n const mount = view.dom.parentElement\n this.mount = mount?.classList.contains('dou-editor__mount') ? mount : null\n if (!this.mount || typeof ResizeObserver === 'undefined') return\n this.observer = new ResizeObserver(() => this.measure())\n // the mount's width, and the column's (the padding changes with the reading width)\n this.observer.observe(this.mount)\n this.observer.observe(view.dom)\n }\n\n private measure() {\n const mount = this.mount\n if (!mount) return\n const style = getComputedStyle(this.view.dom)\n for (const [name, value] of [\n ['--dou-editor-margin-start', style.paddingInlineStart],\n ['--dou-editor-margin-end', style.paddingInlineEnd],\n ] as const) {\n if (mount.style.getPropertyValue(name) !== value) mount.style.setProperty(name, value)\n }\n }\n\n destroy() {\n this.observer?.disconnect()\n this.mount?.style.removeProperty('--dou-editor-margin-start')\n this.mount?.style.removeProperty('--dou-editor-margin-end')\n }\n}\n\nexport const tableKey = new PluginKey<DecorationSet>('dou-editor-table')\n\nexport function tablePlugin(): Plugin<DecorationSet> {\n return new Plugin<DecorationSet>({\n key: tableKey,\n state: {\n init: (_config, state) => alignments(state.doc),\n apply: (tr, value, _old, state) => (tr.docChanged ? alignments(state.doc) : value),\n },\n appendTransaction(trs, _old, state) {\n if (!trs.some((tr) => tr.docChanged)) return null\n const tr = state.tr\n normalize(state.doc, tr)\n return tr.docChanged ? tr : null\n },\n props: {\n decorations: (state) => tableKey.getState(state),\n },\n view: (view) => new Margins(view),\n })\n}\n"],"mappings":";;;;;;;AAQA,IAAM,YAAY,SAAiB,KAAK,KAAK,SAAS,WAAW,KAAK,KAAK,SAAS;AAEpF,IAAM,eAAe,GAAY,MAAe,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC;;;;;;AAOtF,SAAS,UAAU,KAAa,IAAiB;CAC/C,MAAM,yBAAS,IAAI,IAAY;CAC/B,IAAI,aAAa,MAAM,QAAQ;EAC7B,IAAI,KAAK,KAAK,KAAK,cAAc,SAAS,OAAO,SAAS,IAAI;EAC9D,MAAM,MAAM,SAAS,IAAI,IAAI;EAC7B,MAAM,UAAU,WAAW,KAAK,MAAM,SAAS,IAAI,KAAK;EACxD,IAAI,CAAC,YAAY,SAAS,KAAK,MAAM,OAAO,GAAG,GAAG,iBAAiB,KAAK,WAAW,OAAO;EAC1F,MAAM,QAAQ,MAAM;EACpB,KAAK,SAAS,KAAK,WAAW;GAC5B,MAAM,KAAK,IAAI,MAAM;GACrB,IAAI,CAAC,MAAM,OAAO,IAAI,EAAE,GAAG,GAAG,iBAAiB,QAAQ,QAAQ,MAAM,SAAS,CAAC;QAC1E,OAAO,IAAI,EAAE;EACpB,CAAC;EACD,MAAM,uBAAO,IAAI,IAAY;EAC7B,KAAK,MAAM,WAAW,IAAI,KAAK;GAC7B,IAAI,KAAK,IAAI,OAAO,GAAG;GACvB,KAAK,IAAI,OAAO;GAChB,MAAM,OAAO,IAAI,SAAS,OAAO;GACjC,MAAM,OAAO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