@tiptap/extension-table 2.5.0-beta.2 → 2.5.0-beta.3

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 (177) hide show
  1. package/dist/index.cjs +328 -328
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +327 -327
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.umd.js +328 -328
  6. package/dist/index.umd.js.map +1 -1
  7. package/dist/packages/core/src/CommandManager.d.ts +20 -0
  8. package/dist/packages/core/src/Editor.d.ts +161 -0
  9. package/dist/packages/core/src/EventEmitter.d.ts +11 -0
  10. package/dist/packages/core/src/Extension.d.ts +343 -0
  11. package/dist/packages/core/src/ExtensionManager.d.ts +55 -0
  12. package/dist/packages/core/src/InputRule.d.ts +42 -0
  13. package/dist/packages/core/src/Mark.d.ts +451 -0
  14. package/dist/packages/core/src/Node.d.ts +611 -0
  15. package/dist/packages/core/src/NodePos.d.ts +44 -0
  16. package/dist/packages/core/src/NodeView.d.ts +31 -0
  17. package/dist/packages/core/src/PasteRule.d.ts +50 -0
  18. package/dist/packages/core/src/Tracker.d.ts +11 -0
  19. package/dist/packages/core/src/commands/blur.d.ts +13 -0
  20. package/dist/packages/core/src/commands/clearContent.d.ts +14 -0
  21. package/dist/packages/core/src/commands/clearNodes.d.ts +13 -0
  22. package/dist/packages/core/src/commands/command.d.ts +18 -0
  23. package/dist/packages/core/src/commands/createParagraphNear.d.ts +13 -0
  24. package/dist/packages/core/src/commands/cut.d.ts +20 -0
  25. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +13 -0
  26. package/dist/packages/core/src/commands/deleteNode.d.ts +15 -0
  27. package/dist/packages/core/src/commands/deleteRange.d.ts +14 -0
  28. package/dist/packages/core/src/commands/deleteSelection.d.ts +13 -0
  29. package/dist/packages/core/src/commands/enter.d.ts +13 -0
  30. package/dist/packages/core/src/commands/exitCode.d.ts +13 -0
  31. package/dist/packages/core/src/commands/extendMarkRange.d.ts +25 -0
  32. package/dist/packages/core/src/commands/first.d.ts +14 -0
  33. package/dist/packages/core/src/commands/focus.d.ts +27 -0
  34. package/dist/packages/core/src/commands/forEach.d.ts +14 -0
  35. package/dist/packages/core/src/commands/index.d.ts +55 -0
  36. package/dist/packages/core/src/commands/insertContent.d.ts +34 -0
  37. package/dist/packages/core/src/commands/insertContentAt.d.ts +47 -0
  38. package/dist/packages/core/src/commands/join.d.ts +41 -0
  39. package/dist/packages/core/src/commands/joinItemBackward.d.ts +13 -0
  40. package/dist/packages/core/src/commands/joinItemForward.d.ts +13 -0
  41. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +12 -0
  42. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +12 -0
  43. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +14 -0
  44. package/dist/packages/core/src/commands/lift.d.ts +17 -0
  45. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +13 -0
  46. package/dist/packages/core/src/commands/liftListItem.d.ts +15 -0
  47. package/dist/packages/core/src/commands/newlineInCode.d.ts +13 -0
  48. package/dist/packages/core/src/commands/resetAttributes.d.ts +16 -0
  49. package/dist/packages/core/src/commands/scrollIntoView.d.ts +13 -0
  50. package/dist/packages/core/src/commands/selectAll.d.ts +13 -0
  51. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +13 -0
  52. package/dist/packages/core/src/commands/selectNodeForward.d.ts +13 -0
  53. package/dist/packages/core/src/commands/selectParentNode.d.ts +13 -0
  54. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +13 -0
  55. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +13 -0
  56. package/dist/packages/core/src/commands/setContent.d.ts +40 -0
  57. package/dist/packages/core/src/commands/setMark.d.ts +15 -0
  58. package/dist/packages/core/src/commands/setMeta.d.ts +15 -0
  59. package/dist/packages/core/src/commands/setNode.d.ts +16 -0
  60. package/dist/packages/core/src/commands/setNodeSelection.d.ts +14 -0
  61. package/dist/packages/core/src/commands/setTextSelection.d.ts +14 -0
  62. package/dist/packages/core/src/commands/sinkListItem.d.ts +15 -0
  63. package/dist/packages/core/src/commands/splitBlock.d.ts +17 -0
  64. package/dist/packages/core/src/commands/splitListItem.d.ts +15 -0
  65. package/dist/packages/core/src/commands/toggleList.d.ts +18 -0
  66. package/dist/packages/core/src/commands/toggleMark.d.ts +30 -0
  67. package/dist/packages/core/src/commands/toggleNode.d.ts +17 -0
  68. package/dist/packages/core/src/commands/toggleWrap.d.ts +16 -0
  69. package/dist/packages/core/src/commands/undoInputRule.d.ts +13 -0
  70. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +13 -0
  71. package/dist/packages/core/src/commands/unsetMark.d.ts +25 -0
  72. package/dist/packages/core/src/commands/updateAttributes.d.ts +24 -0
  73. package/dist/packages/core/src/commands/wrapIn.d.ts +16 -0
  74. package/dist/packages/core/src/commands/wrapInList.d.ts +16 -0
  75. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +5 -0
  76. package/dist/packages/core/src/extensions/commands.d.ts +3 -0
  77. package/dist/packages/core/src/extensions/editable.d.ts +2 -0
  78. package/dist/packages/core/src/extensions/focusEvents.d.ts +2 -0
  79. package/dist/packages/core/src/extensions/index.d.ts +6 -0
  80. package/dist/packages/core/src/extensions/keymap.d.ts +2 -0
  81. package/dist/packages/core/src/extensions/tabindex.d.ts +2 -0
  82. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +10 -0
  83. package/dist/packages/core/src/helpers/createChainableState.d.ts +10 -0
  84. package/dist/packages/core/src/helpers/createDocument.d.ts +12 -0
  85. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +15 -0
  86. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +7 -0
  87. package/dist/packages/core/src/helpers/findChildren.d.ts +9 -0
  88. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +10 -0
  89. package/dist/packages/core/src/helpers/findParentNode.d.ts +16 -0
  90. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +17 -0
  91. package/dist/packages/core/src/helpers/generateHTML.d.ts +8 -0
  92. package/dist/packages/core/src/helpers/generateJSON.d.ts +8 -0
  93. package/dist/packages/core/src/helpers/generateText.d.ts +12 -0
  94. package/dist/packages/core/src/helpers/getAttributes.d.ts +9 -0
  95. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +6 -0
  96. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +11 -0
  97. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +8 -0
  98. package/dist/packages/core/src/helpers/getExtensionField.d.ts +9 -0
  99. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +2 -0
  100. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +3 -0
  101. package/dist/packages/core/src/helpers/getMarkRange.d.ts +3 -0
  102. package/dist/packages/core/src/helpers/getMarkType.d.ts +2 -0
  103. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +3 -0
  104. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +11 -0
  105. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +3 -0
  106. package/dist/packages/core/src/helpers/getNodeType.d.ts +2 -0
  107. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +3 -0
  108. package/dist/packages/core/src/helpers/getSchema.d.ts +4 -0
  109. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +10 -0
  110. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +8 -0
  111. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +8 -0
  112. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +9 -0
  113. package/dist/packages/core/src/helpers/getText.d.ts +15 -0
  114. package/dist/packages/core/src/helpers/getTextBetween.d.ts +14 -0
  115. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +8 -0
  116. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +8 -0
  117. package/dist/packages/core/src/helpers/index.d.ts +50 -0
  118. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +9 -0
  119. package/dist/packages/core/src/helpers/isActive.d.ts +2 -0
  120. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +2 -0
  121. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +2 -0
  122. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +2 -0
  123. package/dist/packages/core/src/helpers/isList.d.ts +2 -0
  124. package/dist/packages/core/src/helpers/isMarkActive.d.ts +3 -0
  125. package/dist/packages/core/src/helpers/isNodeActive.d.ts +3 -0
  126. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +2 -0
  127. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +2 -0
  128. package/dist/packages/core/src/helpers/isTextSelection.d.ts +2 -0
  129. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +2 -0
  130. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +4 -0
  131. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +2 -0
  132. package/dist/packages/core/src/helpers/splitExtensions.d.ts +9 -0
  133. package/dist/packages/core/src/index.d.ts +24 -0
  134. package/dist/packages/core/src/inputRules/index.d.ts +5 -0
  135. package/dist/packages/core/src/inputRules/markInputRule.d.ts +13 -0
  136. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +23 -0
  137. package/dist/packages/core/src/inputRules/textInputRule.d.ts +10 -0
  138. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +15 -0
  139. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +28 -0
  140. package/dist/packages/core/src/pasteRules/index.d.ts +3 -0
  141. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +13 -0
  142. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +13 -0
  143. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +10 -0
  144. package/dist/packages/core/src/style.d.ts +1 -0
  145. package/dist/packages/core/src/types.d.ts +250 -0
  146. package/dist/packages/core/src/utilities/callOrReturn.d.ts +9 -0
  147. package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -0
  148. package/dist/packages/core/src/utilities/deleteProps.d.ts +6 -0
  149. package/dist/packages/core/src/utilities/elementFromString.d.ts +1 -0
  150. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -0
  151. package/dist/packages/core/src/utilities/findDuplicates.d.ts +1 -0
  152. package/dist/packages/core/src/utilities/fromString.d.ts +1 -0
  153. package/dist/packages/core/src/utilities/index.d.ts +20 -0
  154. package/dist/packages/core/src/utilities/isAndroid.d.ts +1 -0
  155. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +1 -0
  156. package/dist/packages/core/src/utilities/isFunction.d.ts +1 -0
  157. package/dist/packages/core/src/utilities/isMacOS.d.ts +1 -0
  158. package/dist/packages/core/src/utilities/isNumber.d.ts +1 -0
  159. package/dist/packages/core/src/utilities/isPlainObject.d.ts +1 -0
  160. package/dist/packages/core/src/utilities/isRegExp.d.ts +1 -0
  161. package/dist/packages/core/src/utilities/isString.d.ts +1 -0
  162. package/dist/packages/core/src/utilities/isiOS.d.ts +1 -0
  163. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +1 -0
  164. package/dist/packages/core/src/utilities/mergeDeep.d.ts +1 -0
  165. package/dist/packages/core/src/utilities/minMax.d.ts +1 -0
  166. package/dist/packages/core/src/utilities/objectIncludes.d.ts +8 -0
  167. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +8 -0
  168. package/dist/packages/extension-table/src/TableView.d.ts +17 -17
  169. package/dist/packages/extension-table/src/index.d.ts +5 -5
  170. package/dist/packages/extension-table/src/table.d.ts +194 -194
  171. package/dist/packages/extension-table/src/utilities/createCell.d.ts +2 -2
  172. package/dist/packages/extension-table/src/utilities/createColGroup.d.ts +19 -19
  173. package/dist/packages/extension-table/src/utilities/createTable.d.ts +2 -2
  174. package/dist/packages/extension-table/src/utilities/deleteTableWhenAllCellsSelected.d.ts +2 -2
  175. package/dist/packages/extension-table/src/utilities/getTableNodeTypes.d.ts +4 -4
  176. package/dist/packages/extension-table/src/utilities/isCellSelection.d.ts +2 -2
  177. package/package.json +3 -3
package/dist/index.umd.js CHANGED
@@ -4,353 +4,353 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-table"] = {}, global.core, global.state, global.tables));
5
5
  })(this, (function (exports, core, state, tables) { 'use strict';
6
6
 
7
- function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
8
- let totalWidth = 0;
9
- let fixedWidth = true;
10
- let nextDOM = colgroup.firstChild;
11
- const row = node.firstChild;
12
- for (let i = 0, col = 0; i < row.childCount; i += 1) {
13
- const { colspan, colwidth } = row.child(i).attrs;
14
- for (let j = 0; j < colspan; j += 1, col += 1) {
15
- const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
16
- const cssWidth = hasWidth ? `${hasWidth}px` : '';
17
- totalWidth += hasWidth || cellMinWidth;
18
- if (!hasWidth) {
19
- fixedWidth = false;
20
- }
21
- if (!nextDOM) {
22
- colgroup.appendChild(document.createElement('col')).style.width = cssWidth;
23
- }
24
- else {
25
- if (nextDOM.style.width !== cssWidth) {
26
- nextDOM.style.width = cssWidth;
27
- }
28
- nextDOM = nextDOM.nextSibling;
29
- }
30
- }
31
- }
32
- while (nextDOM) {
33
- const after = nextDOM.nextSibling;
34
- nextDOM.parentNode.removeChild(nextDOM);
35
- nextDOM = after;
36
- }
37
- if (fixedWidth) {
38
- table.style.width = `${totalWidth}px`;
39
- table.style.minWidth = '';
40
- }
41
- else {
42
- table.style.width = '';
43
- table.style.minWidth = `${totalWidth}px`;
44
- }
45
- }
46
- class TableView {
47
- constructor(node, cellMinWidth) {
48
- this.node = node;
49
- this.cellMinWidth = cellMinWidth;
50
- this.dom = document.createElement('div');
51
- this.dom.className = 'tableWrapper';
52
- this.table = this.dom.appendChild(document.createElement('table'));
53
- this.colgroup = this.table.appendChild(document.createElement('colgroup'));
54
- updateColumns(node, this.colgroup, this.table, cellMinWidth);
55
- this.contentDOM = this.table.appendChild(document.createElement('tbody'));
56
- }
57
- update(node) {
58
- if (node.type !== this.node.type) {
59
- return false;
60
- }
61
- this.node = node;
62
- updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
63
- return true;
64
- }
65
- ignoreMutation(mutation) {
66
- return (mutation.type === 'attributes'
67
- && (mutation.target === this.table || this.colgroup.contains(mutation.target)));
68
- }
7
+ function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
8
+ let totalWidth = 0;
9
+ let fixedWidth = true;
10
+ let nextDOM = colgroup.firstChild;
11
+ const row = node.firstChild;
12
+ for (let i = 0, col = 0; i < row.childCount; i += 1) {
13
+ const { colspan, colwidth } = row.child(i).attrs;
14
+ for (let j = 0; j < colspan; j += 1, col += 1) {
15
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
16
+ const cssWidth = hasWidth ? `${hasWidth}px` : '';
17
+ totalWidth += hasWidth || cellMinWidth;
18
+ if (!hasWidth) {
19
+ fixedWidth = false;
20
+ }
21
+ if (!nextDOM) {
22
+ colgroup.appendChild(document.createElement('col')).style.width = cssWidth;
23
+ }
24
+ else {
25
+ if (nextDOM.style.width !== cssWidth) {
26
+ nextDOM.style.width = cssWidth;
27
+ }
28
+ nextDOM = nextDOM.nextSibling;
29
+ }
30
+ }
31
+ }
32
+ while (nextDOM) {
33
+ const after = nextDOM.nextSibling;
34
+ nextDOM.parentNode.removeChild(nextDOM);
35
+ nextDOM = after;
36
+ }
37
+ if (fixedWidth) {
38
+ table.style.width = `${totalWidth}px`;
39
+ table.style.minWidth = '';
40
+ }
41
+ else {
42
+ table.style.width = '';
43
+ table.style.minWidth = `${totalWidth}px`;
44
+ }
45
+ }
46
+ class TableView {
47
+ constructor(node, cellMinWidth) {
48
+ this.node = node;
49
+ this.cellMinWidth = cellMinWidth;
50
+ this.dom = document.createElement('div');
51
+ this.dom.className = 'tableWrapper';
52
+ this.table = this.dom.appendChild(document.createElement('table'));
53
+ this.colgroup = this.table.appendChild(document.createElement('colgroup'));
54
+ updateColumns(node, this.colgroup, this.table, cellMinWidth);
55
+ this.contentDOM = this.table.appendChild(document.createElement('tbody'));
56
+ }
57
+ update(node) {
58
+ if (node.type !== this.node.type) {
59
+ return false;
60
+ }
61
+ this.node = node;
62
+ updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
63
+ return true;
64
+ }
65
+ ignoreMutation(mutation) {
66
+ return (mutation.type === 'attributes'
67
+ && (mutation.target === this.table || this.colgroup.contains(mutation.target)));
68
+ }
69
69
  }
70
70
 
71
- /**
72
- * Creates a colgroup element for a table node in ProseMirror.
73
- *
74
- * @param node - The ProseMirror node representing the table.
75
- * @param cellMinWidth - The minimum width of a cell in the table.
76
- * @param overrideCol - (Optional) The index of the column to override the width of.
77
- * @param overrideValue - (Optional) The width value to use for the overridden column.
78
- * @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.
79
- */
80
- function createColGroup(node, cellMinWidth, overrideCol, overrideValue) {
81
- let totalWidth = 0;
82
- let fixedWidth = true;
83
- const cols = [];
84
- const row = node.firstChild;
85
- if (!row) {
86
- return {};
87
- }
88
- for (let i = 0, col = 0; i < row.childCount; i += 1) {
89
- const { colspan, colwidth } = row.child(i).attrs;
90
- for (let j = 0; j < colspan; j += 1, col += 1) {
91
- const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
92
- const cssWidth = hasWidth ? `${hasWidth}px` : '';
93
- totalWidth += hasWidth || cellMinWidth;
94
- if (!hasWidth) {
95
- fixedWidth = false;
96
- }
97
- cols.push(['col', cssWidth ? { style: `width: ${cssWidth}` } : {}]);
98
- }
99
- }
100
- const tableWidth = fixedWidth ? `${totalWidth}px` : '';
101
- const tableMinWidth = fixedWidth ? '' : `${totalWidth}px`;
102
- const colgroup = ['colgroup', {}, ...cols];
103
- return { colgroup, tableWidth, tableMinWidth };
71
+ /**
72
+ * Creates a colgroup element for a table node in ProseMirror.
73
+ *
74
+ * @param node - The ProseMirror node representing the table.
75
+ * @param cellMinWidth - The minimum width of a cell in the table.
76
+ * @param overrideCol - (Optional) The index of the column to override the width of.
77
+ * @param overrideValue - (Optional) The width value to use for the overridden column.
78
+ * @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.
79
+ */
80
+ function createColGroup(node, cellMinWidth, overrideCol, overrideValue) {
81
+ let totalWidth = 0;
82
+ let fixedWidth = true;
83
+ const cols = [];
84
+ const row = node.firstChild;
85
+ if (!row) {
86
+ return {};
87
+ }
88
+ for (let i = 0, col = 0; i < row.childCount; i += 1) {
89
+ const { colspan, colwidth } = row.child(i).attrs;
90
+ for (let j = 0; j < colspan; j += 1, col += 1) {
91
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
92
+ const cssWidth = hasWidth ? `${hasWidth}px` : '';
93
+ totalWidth += hasWidth || cellMinWidth;
94
+ if (!hasWidth) {
95
+ fixedWidth = false;
96
+ }
97
+ cols.push(['col', cssWidth ? { style: `width: ${cssWidth}` } : {}]);
98
+ }
99
+ }
100
+ const tableWidth = fixedWidth ? `${totalWidth}px` : '';
101
+ const tableMinWidth = fixedWidth ? '' : `${totalWidth}px`;
102
+ const colgroup = ['colgroup', {}, ...cols];
103
+ return { colgroup, tableWidth, tableMinWidth };
104
104
  }
105
105
 
106
- function createCell(cellType, cellContent) {
107
- if (cellContent) {
108
- return cellType.createChecked(null, cellContent);
109
- }
110
- return cellType.createAndFill();
106
+ function createCell(cellType, cellContent) {
107
+ if (cellContent) {
108
+ return cellType.createChecked(null, cellContent);
109
+ }
110
+ return cellType.createAndFill();
111
111
  }
112
112
 
113
- function getTableNodeTypes(schema) {
114
- if (schema.cached.tableNodeTypes) {
115
- return schema.cached.tableNodeTypes;
116
- }
117
- const roles = {};
118
- Object.keys(schema.nodes).forEach(type => {
119
- const nodeType = schema.nodes[type];
120
- if (nodeType.spec.tableRole) {
121
- roles[nodeType.spec.tableRole] = nodeType;
122
- }
123
- });
124
- schema.cached.tableNodeTypes = roles;
125
- return roles;
113
+ function getTableNodeTypes(schema) {
114
+ if (schema.cached.tableNodeTypes) {
115
+ return schema.cached.tableNodeTypes;
116
+ }
117
+ const roles = {};
118
+ Object.keys(schema.nodes).forEach(type => {
119
+ const nodeType = schema.nodes[type];
120
+ if (nodeType.spec.tableRole) {
121
+ roles[nodeType.spec.tableRole] = nodeType;
122
+ }
123
+ });
124
+ schema.cached.tableNodeTypes = roles;
125
+ return roles;
126
126
  }
127
127
 
128
- function createTable(schema, rowsCount, colsCount, withHeaderRow, cellContent) {
129
- const types = getTableNodeTypes(schema);
130
- const headerCells = [];
131
- const cells = [];
132
- for (let index = 0; index < colsCount; index += 1) {
133
- const cell = createCell(types.cell, cellContent);
134
- if (cell) {
135
- cells.push(cell);
136
- }
137
- if (withHeaderRow) {
138
- const headerCell = createCell(types.header_cell, cellContent);
139
- if (headerCell) {
140
- headerCells.push(headerCell);
141
- }
142
- }
143
- }
144
- const rows = [];
145
- for (let index = 0; index < rowsCount; index += 1) {
146
- rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells));
147
- }
148
- return types.table.createChecked(null, rows);
128
+ function createTable(schema, rowsCount, colsCount, withHeaderRow, cellContent) {
129
+ const types = getTableNodeTypes(schema);
130
+ const headerCells = [];
131
+ const cells = [];
132
+ for (let index = 0; index < colsCount; index += 1) {
133
+ const cell = createCell(types.cell, cellContent);
134
+ if (cell) {
135
+ cells.push(cell);
136
+ }
137
+ if (withHeaderRow) {
138
+ const headerCell = createCell(types.header_cell, cellContent);
139
+ if (headerCell) {
140
+ headerCells.push(headerCell);
141
+ }
142
+ }
143
+ }
144
+ const rows = [];
145
+ for (let index = 0; index < rowsCount; index += 1) {
146
+ rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells));
147
+ }
148
+ return types.table.createChecked(null, rows);
149
149
  }
150
150
 
151
- function isCellSelection(value) {
152
- return value instanceof tables.CellSelection;
151
+ function isCellSelection(value) {
152
+ return value instanceof tables.CellSelection;
153
153
  }
154
154
 
155
- const deleteTableWhenAllCellsSelected = ({ editor }) => {
156
- const { selection } = editor.state;
157
- if (!isCellSelection(selection)) {
158
- return false;
159
- }
160
- let cellCount = 0;
161
- const table = core.findParentNodeClosestToPos(selection.ranges[0].$from, node => {
162
- return node.type.name === 'table';
163
- });
164
- table === null || table === void 0 ? void 0 : table.node.descendants(node => {
165
- if (node.type.name === 'table') {
166
- return false;
167
- }
168
- if (['tableCell', 'tableHeader'].includes(node.type.name)) {
169
- cellCount += 1;
170
- }
171
- });
172
- const allCellsSelected = cellCount === selection.ranges.length;
173
- if (!allCellsSelected) {
174
- return false;
175
- }
176
- editor.commands.deleteTable();
177
- return true;
155
+ const deleteTableWhenAllCellsSelected = ({ editor }) => {
156
+ const { selection } = editor.state;
157
+ if (!isCellSelection(selection)) {
158
+ return false;
159
+ }
160
+ let cellCount = 0;
161
+ const table = core.findParentNodeClosestToPos(selection.ranges[0].$from, node => {
162
+ return node.type.name === 'table';
163
+ });
164
+ table === null || table === void 0 ? void 0 : table.node.descendants(node => {
165
+ if (node.type.name === 'table') {
166
+ return false;
167
+ }
168
+ if (['tableCell', 'tableHeader'].includes(node.type.name)) {
169
+ cellCount += 1;
170
+ }
171
+ });
172
+ const allCellsSelected = cellCount === selection.ranges.length;
173
+ if (!allCellsSelected) {
174
+ return false;
175
+ }
176
+ editor.commands.deleteTable();
177
+ return true;
178
178
  };
179
179
 
180
- /**
181
- * This extension allows you to create tables.
182
- * @see https://www.tiptap.dev/api/nodes/table
183
- */
184
- const Table = core.Node.create({
185
- name: 'table',
186
- // @ts-ignore
187
- addOptions() {
188
- return {
189
- HTMLAttributes: {},
190
- resizable: false,
191
- handleWidth: 5,
192
- cellMinWidth: 25,
193
- // TODO: fix
194
- View: TableView,
195
- lastColumnResizable: true,
196
- allowTableNodeSelection: false,
197
- };
198
- },
199
- content: 'tableRow+',
200
- tableRole: 'table',
201
- isolating: true,
202
- group: 'block',
203
- parseHTML() {
204
- return [{ tag: 'table' }];
205
- },
206
- renderHTML({ node, HTMLAttributes }) {
207
- const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth);
208
- const table = [
209
- 'table',
210
- core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
211
- style: tableWidth
212
- ? `width: ${tableWidth}`
213
- : `minWidth: ${tableMinWidth}`,
214
- }),
215
- colgroup,
216
- ['tbody', 0],
217
- ];
218
- return table;
219
- },
220
- addCommands() {
221
- return {
222
- insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {
223
- const node = createTable(editor.schema, rows, cols, withHeaderRow);
224
- if (dispatch) {
225
- const offset = tr.selection.from + 1;
226
- tr.replaceSelectionWith(node)
227
- .scrollIntoView()
228
- .setSelection(state.TextSelection.near(tr.doc.resolve(offset)));
229
- }
230
- return true;
231
- },
232
- addColumnBefore: () => ({ state, dispatch }) => {
233
- return tables.addColumnBefore(state, dispatch);
234
- },
235
- addColumnAfter: () => ({ state, dispatch }) => {
236
- return tables.addColumnAfter(state, dispatch);
237
- },
238
- deleteColumn: () => ({ state, dispatch }) => {
239
- return tables.deleteColumn(state, dispatch);
240
- },
241
- addRowBefore: () => ({ state, dispatch }) => {
242
- return tables.addRowBefore(state, dispatch);
243
- },
244
- addRowAfter: () => ({ state, dispatch }) => {
245
- return tables.addRowAfter(state, dispatch);
246
- },
247
- deleteRow: () => ({ state, dispatch }) => {
248
- return tables.deleteRow(state, dispatch);
249
- },
250
- deleteTable: () => ({ state, dispatch }) => {
251
- return tables.deleteTable(state, dispatch);
252
- },
253
- mergeCells: () => ({ state, dispatch }) => {
254
- return tables.mergeCells(state, dispatch);
255
- },
256
- splitCell: () => ({ state, dispatch }) => {
257
- return tables.splitCell(state, dispatch);
258
- },
259
- toggleHeaderColumn: () => ({ state, dispatch }) => {
260
- return tables.toggleHeader('column')(state, dispatch);
261
- },
262
- toggleHeaderRow: () => ({ state, dispatch }) => {
263
- return tables.toggleHeader('row')(state, dispatch);
264
- },
265
- toggleHeaderCell: () => ({ state, dispatch }) => {
266
- return tables.toggleHeaderCell(state, dispatch);
267
- },
268
- mergeOrSplit: () => ({ state, dispatch }) => {
269
- if (tables.mergeCells(state, dispatch)) {
270
- return true;
271
- }
272
- return tables.splitCell(state, dispatch);
273
- },
274
- setCellAttribute: (name, value) => ({ state, dispatch }) => {
275
- return tables.setCellAttr(name, value)(state, dispatch);
276
- },
277
- goToNextCell: () => ({ state, dispatch }) => {
278
- return tables.goToNextCell(1)(state, dispatch);
279
- },
280
- goToPreviousCell: () => ({ state, dispatch }) => {
281
- return tables.goToNextCell(-1)(state, dispatch);
282
- },
283
- fixTables: () => ({ state, dispatch }) => {
284
- if (dispatch) {
285
- tables.fixTables(state);
286
- }
287
- return true;
288
- },
289
- setCellSelection: position => ({ tr, dispatch }) => {
290
- if (dispatch) {
291
- const selection = tables.CellSelection.create(tr.doc, position.anchorCell, position.headCell);
292
- // @ts-ignore
293
- tr.setSelection(selection);
294
- }
295
- return true;
296
- },
297
- };
298
- },
299
- addKeyboardShortcuts() {
300
- return {
301
- Tab: () => {
302
- if (this.editor.commands.goToNextCell()) {
303
- return true;
304
- }
305
- if (!this.editor.can().addRowAfter()) {
306
- return false;
307
- }
308
- return this.editor.chain().addRowAfter().goToNextCell().run();
309
- },
310
- 'Shift-Tab': () => this.editor.commands.goToPreviousCell(),
311
- Backspace: deleteTableWhenAllCellsSelected,
312
- 'Mod-Backspace': deleteTableWhenAllCellsSelected,
313
- Delete: deleteTableWhenAllCellsSelected,
314
- 'Mod-Delete': deleteTableWhenAllCellsSelected,
315
- };
316
- },
317
- addProseMirrorPlugins() {
318
- const isResizable = this.options.resizable && this.editor.isEditable;
319
- return [
320
- ...(isResizable
321
- ? [
322
- tables.columnResizing({
323
- handleWidth: this.options.handleWidth,
324
- cellMinWidth: this.options.cellMinWidth,
325
- // @ts-ignore (incorrect type)
326
- View: this.options.View,
327
- // TODO: PR for @types/prosemirror-tables
328
- // @ts-ignore (incorrect type)
329
- lastColumnResizable: this.options.lastColumnResizable,
330
- }),
331
- ]
332
- : []),
333
- tables.tableEditing({
334
- allowTableNodeSelection: this.options.allowTableNodeSelection,
335
- }),
336
- ];
337
- },
338
- extendNodeSchema(extension) {
339
- const context = {
340
- name: extension.name,
341
- options: extension.options,
342
- storage: extension.storage,
343
- };
344
- return {
345
- tableRole: core.callOrReturn(core.getExtensionField(extension, 'tableRole', context)),
346
- };
347
- },
180
+ /**
181
+ * This extension allows you to create tables.
182
+ * @see https://www.tiptap.dev/api/nodes/table
183
+ */
184
+ const Table = core.Node.create({
185
+ name: 'table',
186
+ // @ts-ignore
187
+ addOptions() {
188
+ return {
189
+ HTMLAttributes: {},
190
+ resizable: false,
191
+ handleWidth: 5,
192
+ cellMinWidth: 25,
193
+ // TODO: fix
194
+ View: TableView,
195
+ lastColumnResizable: true,
196
+ allowTableNodeSelection: false,
197
+ };
198
+ },
199
+ content: 'tableRow+',
200
+ tableRole: 'table',
201
+ isolating: true,
202
+ group: 'block',
203
+ parseHTML() {
204
+ return [{ tag: 'table' }];
205
+ },
206
+ renderHTML({ node, HTMLAttributes }) {
207
+ const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth);
208
+ const table = [
209
+ 'table',
210
+ core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
211
+ style: tableWidth
212
+ ? `width: ${tableWidth}`
213
+ : `minWidth: ${tableMinWidth}`,
214
+ }),
215
+ colgroup,
216
+ ['tbody', 0],
217
+ ];
218
+ return table;
219
+ },
220
+ addCommands() {
221
+ return {
222
+ insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {
223
+ const node = createTable(editor.schema, rows, cols, withHeaderRow);
224
+ if (dispatch) {
225
+ const offset = tr.selection.from + 1;
226
+ tr.replaceSelectionWith(node)
227
+ .scrollIntoView()
228
+ .setSelection(state.TextSelection.near(tr.doc.resolve(offset)));
229
+ }
230
+ return true;
231
+ },
232
+ addColumnBefore: () => ({ state, dispatch }) => {
233
+ return tables.addColumnBefore(state, dispatch);
234
+ },
235
+ addColumnAfter: () => ({ state, dispatch }) => {
236
+ return tables.addColumnAfter(state, dispatch);
237
+ },
238
+ deleteColumn: () => ({ state, dispatch }) => {
239
+ return tables.deleteColumn(state, dispatch);
240
+ },
241
+ addRowBefore: () => ({ state, dispatch }) => {
242
+ return tables.addRowBefore(state, dispatch);
243
+ },
244
+ addRowAfter: () => ({ state, dispatch }) => {
245
+ return tables.addRowAfter(state, dispatch);
246
+ },
247
+ deleteRow: () => ({ state, dispatch }) => {
248
+ return tables.deleteRow(state, dispatch);
249
+ },
250
+ deleteTable: () => ({ state, dispatch }) => {
251
+ return tables.deleteTable(state, dispatch);
252
+ },
253
+ mergeCells: () => ({ state, dispatch }) => {
254
+ return tables.mergeCells(state, dispatch);
255
+ },
256
+ splitCell: () => ({ state, dispatch }) => {
257
+ return tables.splitCell(state, dispatch);
258
+ },
259
+ toggleHeaderColumn: () => ({ state, dispatch }) => {
260
+ return tables.toggleHeader('column')(state, dispatch);
261
+ },
262
+ toggleHeaderRow: () => ({ state, dispatch }) => {
263
+ return tables.toggleHeader('row')(state, dispatch);
264
+ },
265
+ toggleHeaderCell: () => ({ state, dispatch }) => {
266
+ return tables.toggleHeaderCell(state, dispatch);
267
+ },
268
+ mergeOrSplit: () => ({ state, dispatch }) => {
269
+ if (tables.mergeCells(state, dispatch)) {
270
+ return true;
271
+ }
272
+ return tables.splitCell(state, dispatch);
273
+ },
274
+ setCellAttribute: (name, value) => ({ state, dispatch }) => {
275
+ return tables.setCellAttr(name, value)(state, dispatch);
276
+ },
277
+ goToNextCell: () => ({ state, dispatch }) => {
278
+ return tables.goToNextCell(1)(state, dispatch);
279
+ },
280
+ goToPreviousCell: () => ({ state, dispatch }) => {
281
+ return tables.goToNextCell(-1)(state, dispatch);
282
+ },
283
+ fixTables: () => ({ state, dispatch }) => {
284
+ if (dispatch) {
285
+ tables.fixTables(state);
286
+ }
287
+ return true;
288
+ },
289
+ setCellSelection: position => ({ tr, dispatch }) => {
290
+ if (dispatch) {
291
+ const selection = tables.CellSelection.create(tr.doc, position.anchorCell, position.headCell);
292
+ // @ts-ignore
293
+ tr.setSelection(selection);
294
+ }
295
+ return true;
296
+ },
297
+ };
298
+ },
299
+ addKeyboardShortcuts() {
300
+ return {
301
+ Tab: () => {
302
+ if (this.editor.commands.goToNextCell()) {
303
+ return true;
304
+ }
305
+ if (!this.editor.can().addRowAfter()) {
306
+ return false;
307
+ }
308
+ return this.editor.chain().addRowAfter().goToNextCell().run();
309
+ },
310
+ 'Shift-Tab': () => this.editor.commands.goToPreviousCell(),
311
+ Backspace: deleteTableWhenAllCellsSelected,
312
+ 'Mod-Backspace': deleteTableWhenAllCellsSelected,
313
+ Delete: deleteTableWhenAllCellsSelected,
314
+ 'Mod-Delete': deleteTableWhenAllCellsSelected,
315
+ };
316
+ },
317
+ addProseMirrorPlugins() {
318
+ const isResizable = this.options.resizable && this.editor.isEditable;
319
+ return [
320
+ ...(isResizable
321
+ ? [
322
+ tables.columnResizing({
323
+ handleWidth: this.options.handleWidth,
324
+ cellMinWidth: this.options.cellMinWidth,
325
+ // @ts-ignore (incorrect type)
326
+ View: this.options.View,
327
+ // TODO: PR for @types/prosemirror-tables
328
+ // @ts-ignore (incorrect type)
329
+ lastColumnResizable: this.options.lastColumnResizable,
330
+ }),
331
+ ]
332
+ : []),
333
+ tables.tableEditing({
334
+ allowTableNodeSelection: this.options.allowTableNodeSelection,
335
+ }),
336
+ ];
337
+ },
338
+ extendNodeSchema(extension) {
339
+ const context = {
340
+ name: extension.name,
341
+ options: extension.options,
342
+ storage: extension.storage,
343
+ };
344
+ return {
345
+ tableRole: core.callOrReturn(core.getExtensionField(extension, 'tableRole', context)),
346
+ };
347
+ },
348
348
  });
349
349
 
350
350
  exports.Table = Table;
351
351
  exports.createColGroup = createColGroup;
352
352
  exports.createTable = createTable;
353
- exports["default"] = Table;
353
+ exports.default = Table;
354
354
 
355
355
  Object.defineProperty(exports, '__esModule', { value: true });
356
356