@tiptap/extension-table 3.0.0-next.0 → 3.0.0-next.2

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