@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.cjs CHANGED
@@ -1,353 +1,394 @@
1
- 'use strict';
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
19
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Table: () => Table,
24
+ createColGroup: () => createColGroup,
25
+ createTable: () => createTable,
26
+ default: () => src_default
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
4
29
 
5
- var core = require('@tiptap/core');
6
- var state = require('@tiptap/pm/state');
7
- var tables = require('@tiptap/pm/tables');
30
+ // src/table.ts
31
+ var import_core2 = require("@tiptap/core");
32
+ var import_state = require("@tiptap/pm/state");
33
+ var import_tables2 = require("@tiptap/pm/tables");
34
+
35
+ // src/utilities/colStyle.ts
36
+ function getColStyleDeclaration(minWidth, width) {
37
+ if (width) {
38
+ return ["width", `${Math.max(width, minWidth)}px`];
39
+ }
40
+ return ["min-width", `${minWidth}px`];
41
+ }
8
42
 
43
+ // src/TableView.ts
9
44
  function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) {
10
- let totalWidth = 0;
11
- let fixedWidth = true;
12
- let nextDOM = colgroup.firstChild;
13
- const row = node.firstChild;
45
+ var _a;
46
+ let totalWidth = 0;
47
+ let fixedWidth = true;
48
+ let nextDOM = colgroup.firstChild;
49
+ const row = node.firstChild;
50
+ if (row !== null) {
14
51
  for (let i = 0, col = 0; i < row.childCount; i += 1) {
15
- const { colspan, colwidth } = row.child(i).attrs;
16
- for (let j = 0; j < colspan; j += 1, col += 1) {
17
- const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
18
- const cssWidth = hasWidth ? `${hasWidth}px` : '';
19
- totalWidth += hasWidth || cellMinWidth;
20
- if (!hasWidth) {
21
- fixedWidth = false;
22
- }
23
- if (!nextDOM) {
24
- colgroup.appendChild(document.createElement('col')).style.width = cssWidth;
25
- }
26
- else {
27
- if (nextDOM.style.width !== cssWidth) {
28
- nextDOM.style.width = cssWidth;
29
- }
30
- nextDOM = nextDOM.nextSibling;
31
- }
52
+ const { colspan, colwidth } = row.child(i).attrs;
53
+ for (let j = 0; j < colspan; j += 1, col += 1) {
54
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
55
+ const cssWidth = hasWidth ? `${hasWidth}px` : "";
56
+ totalWidth += hasWidth || cellMinWidth;
57
+ if (!hasWidth) {
58
+ fixedWidth = false;
32
59
  }
33
- }
34
- while (nextDOM) {
35
- const after = nextDOM.nextSibling;
36
- nextDOM.parentNode.removeChild(nextDOM);
37
- nextDOM = after;
38
- }
39
- if (fixedWidth) {
40
- table.style.width = `${totalWidth}px`;
41
- table.style.minWidth = '';
42
- }
43
- else {
44
- table.style.width = '';
45
- table.style.minWidth = `${totalWidth}px`;
46
- }
47
- }
48
- class TableView {
49
- constructor(node, cellMinWidth) {
50
- this.node = node;
51
- this.cellMinWidth = cellMinWidth;
52
- this.dom = document.createElement('div');
53
- this.dom.className = 'tableWrapper';
54
- this.table = this.dom.appendChild(document.createElement('table'));
55
- this.colgroup = this.table.appendChild(document.createElement('colgroup'));
56
- updateColumns(node, this.colgroup, this.table, cellMinWidth);
57
- this.contentDOM = this.table.appendChild(document.createElement('tbody'));
58
- }
59
- update(node) {
60
- if (node.type !== this.node.type) {
61
- return false;
60
+ if (!nextDOM) {
61
+ const colElement = document.createElement("col");
62
+ const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
63
+ colElement.style.setProperty(propertyKey, propertyValue);
64
+ colgroup.appendChild(colElement);
65
+ } else {
66
+ if (nextDOM.style.width !== cssWidth) {
67
+ const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth);
68
+ nextDOM.style.setProperty(propertyKey, propertyValue);
69
+ }
70
+ nextDOM = nextDOM.nextSibling;
62
71
  }
63
- this.node = node;
64
- updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
65
- return true;
66
- }
67
- ignoreMutation(mutation) {
68
- return (mutation.type === 'attributes'
69
- && (mutation.target === this.table || this.colgroup.contains(mutation.target)));
72
+ }
70
73
  }
74
+ }
75
+ while (nextDOM) {
76
+ const after = nextDOM.nextSibling;
77
+ (_a = nextDOM.parentNode) == null ? void 0 : _a.removeChild(nextDOM);
78
+ nextDOM = after;
79
+ }
80
+ if (fixedWidth) {
81
+ table.style.width = `${totalWidth}px`;
82
+ table.style.minWidth = "";
83
+ } else {
84
+ table.style.width = "";
85
+ table.style.minWidth = `${totalWidth}px`;
86
+ }
71
87
  }
88
+ var TableView = class {
89
+ constructor(node, cellMinWidth) {
90
+ this.node = node;
91
+ this.cellMinWidth = cellMinWidth;
92
+ this.dom = document.createElement("div");
93
+ this.dom.className = "tableWrapper";
94
+ this.table = this.dom.appendChild(document.createElement("table"));
95
+ this.colgroup = this.table.appendChild(document.createElement("colgroup"));
96
+ updateColumns(node, this.colgroup, this.table, cellMinWidth);
97
+ this.contentDOM = this.table.appendChild(document.createElement("tbody"));
98
+ }
99
+ update(node) {
100
+ if (node.type !== this.node.type) {
101
+ return false;
102
+ }
103
+ this.node = node;
104
+ updateColumns(node, this.colgroup, this.table, this.cellMinWidth);
105
+ return true;
106
+ }
107
+ ignoreMutation(mutation) {
108
+ return mutation.type === "attributes" && (mutation.target === this.table || this.colgroup.contains(mutation.target));
109
+ }
110
+ };
72
111
 
73
- /**
74
- * Creates a colgroup element for a table node in ProseMirror.
75
- *
76
- * @param node - The ProseMirror node representing the table.
77
- * @param cellMinWidth - The minimum width of a cell in the table.
78
- * @param overrideCol - (Optional) The index of the column to override the width of.
79
- * @param overrideValue - (Optional) The width value to use for the overridden column.
80
- * @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.
81
- */
112
+ // src/utilities/createColGroup.ts
82
113
  function createColGroup(node, cellMinWidth, overrideCol, overrideValue) {
83
- let totalWidth = 0;
84
- let fixedWidth = true;
85
- const cols = [];
86
- const row = node.firstChild;
87
- if (!row) {
88
- return {};
89
- }
90
- for (let i = 0, col = 0; i < row.childCount; i += 1) {
91
- const { colspan, colwidth } = row.child(i).attrs;
92
- for (let j = 0; j < colspan; j += 1, col += 1) {
93
- const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
94
- const cssWidth = hasWidth ? `${hasWidth}px` : '';
95
- totalWidth += hasWidth || cellMinWidth;
96
- if (!hasWidth) {
97
- fixedWidth = false;
98
- }
99
- cols.push(['col', cssWidth ? { style: `width: ${cssWidth}` } : {}]);
100
- }
114
+ let totalWidth = 0;
115
+ let fixedWidth = true;
116
+ const cols = [];
117
+ const row = node.firstChild;
118
+ if (!row) {
119
+ return {};
120
+ }
121
+ for (let i = 0, col = 0; i < row.childCount; i += 1) {
122
+ const { colspan, colwidth } = row.child(i).attrs;
123
+ for (let j = 0; j < colspan; j += 1, col += 1) {
124
+ const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j];
125
+ totalWidth += hasWidth || cellMinWidth;
126
+ if (!hasWidth) {
127
+ fixedWidth = false;
128
+ }
129
+ const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth);
130
+ cols.push([
131
+ "col",
132
+ { style: `${property}: ${value}` }
133
+ ]);
101
134
  }
102
- const tableWidth = fixedWidth ? `${totalWidth}px` : '';
103
- const tableMinWidth = fixedWidth ? '' : `${totalWidth}px`;
104
- const colgroup = ['colgroup', {}, ...cols];
105
- return { colgroup, tableWidth, tableMinWidth };
135
+ }
136
+ const tableWidth = fixedWidth ? `${totalWidth}px` : "";
137
+ const tableMinWidth = fixedWidth ? "" : `${totalWidth}px`;
138
+ const colgroup = ["colgroup", {}, ...cols];
139
+ return { colgroup, tableWidth, tableMinWidth };
106
140
  }
107
141
 
142
+ // src/utilities/createCell.ts
108
143
  function createCell(cellType, cellContent) {
109
- if (cellContent) {
110
- return cellType.createChecked(null, cellContent);
111
- }
112
- return cellType.createAndFill();
144
+ if (cellContent) {
145
+ return cellType.createChecked(null, cellContent);
146
+ }
147
+ return cellType.createAndFill();
113
148
  }
114
149
 
150
+ // src/utilities/getTableNodeTypes.ts
115
151
  function getTableNodeTypes(schema) {
116
- if (schema.cached.tableNodeTypes) {
117
- return schema.cached.tableNodeTypes;
152
+ if (schema.cached.tableNodeTypes) {
153
+ return schema.cached.tableNodeTypes;
154
+ }
155
+ const roles = {};
156
+ Object.keys(schema.nodes).forEach((type) => {
157
+ const nodeType = schema.nodes[type];
158
+ if (nodeType.spec.tableRole) {
159
+ roles[nodeType.spec.tableRole] = nodeType;
118
160
  }
119
- const roles = {};
120
- Object.keys(schema.nodes).forEach(type => {
121
- const nodeType = schema.nodes[type];
122
- if (nodeType.spec.tableRole) {
123
- roles[nodeType.spec.tableRole] = nodeType;
124
- }
125
- });
126
- schema.cached.tableNodeTypes = roles;
127
- return roles;
161
+ });
162
+ schema.cached.tableNodeTypes = roles;
163
+ return roles;
128
164
  }
129
165
 
166
+ // src/utilities/createTable.ts
130
167
  function createTable(schema, rowsCount, colsCount, withHeaderRow, cellContent) {
131
- const types = getTableNodeTypes(schema);
132
- const headerCells = [];
133
- const cells = [];
134
- for (let index = 0; index < colsCount; index += 1) {
135
- const cell = createCell(types.cell, cellContent);
136
- if (cell) {
137
- cells.push(cell);
138
- }
139
- if (withHeaderRow) {
140
- const headerCell = createCell(types.header_cell, cellContent);
141
- if (headerCell) {
142
- headerCells.push(headerCell);
143
- }
144
- }
168
+ const types = getTableNodeTypes(schema);
169
+ const headerCells = [];
170
+ const cells = [];
171
+ for (let index = 0; index < colsCount; index += 1) {
172
+ const cell = createCell(types.cell, cellContent);
173
+ if (cell) {
174
+ cells.push(cell);
145
175
  }
146
- const rows = [];
147
- for (let index = 0; index < rowsCount; index += 1) {
148
- rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells));
176
+ if (withHeaderRow) {
177
+ const headerCell = createCell(types.header_cell, cellContent);
178
+ if (headerCell) {
179
+ headerCells.push(headerCell);
180
+ }
149
181
  }
150
- return types.table.createChecked(null, rows);
182
+ }
183
+ const rows = [];
184
+ for (let index = 0; index < rowsCount; index += 1) {
185
+ rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells));
186
+ }
187
+ return types.table.createChecked(null, rows);
151
188
  }
152
189
 
190
+ // src/utilities/deleteTableWhenAllCellsSelected.ts
191
+ var import_core = require("@tiptap/core");
192
+
193
+ // src/utilities/isCellSelection.ts
194
+ var import_tables = require("@tiptap/pm/tables");
153
195
  function isCellSelection(value) {
154
- return value instanceof tables.CellSelection;
196
+ return value instanceof import_tables.CellSelection;
155
197
  }
156
198
 
157
- const deleteTableWhenAllCellsSelected = ({ editor }) => {
158
- const { selection } = editor.state;
159
- if (!isCellSelection(selection)) {
160
- return false;
199
+ // src/utilities/deleteTableWhenAllCellsSelected.ts
200
+ var deleteTableWhenAllCellsSelected = ({ editor }) => {
201
+ const { selection } = editor.state;
202
+ if (!isCellSelection(selection)) {
203
+ return false;
204
+ }
205
+ let cellCount = 0;
206
+ const table = (0, import_core.findParentNodeClosestToPos)(selection.ranges[0].$from, (node) => {
207
+ return node.type.name === "table";
208
+ });
209
+ table == null ? void 0 : table.node.descendants((node) => {
210
+ if (node.type.name === "table") {
211
+ return false;
161
212
  }
162
- let cellCount = 0;
163
- const table = core.findParentNodeClosestToPos(selection.ranges[0].$from, node => {
164
- return node.type.name === 'table';
165
- });
166
- table === null || table === void 0 ? void 0 : table.node.descendants(node => {
167
- if (node.type.name === 'table') {
168
- return false;
169
- }
170
- if (['tableCell', 'tableHeader'].includes(node.type.name)) {
171
- cellCount += 1;
172
- }
173
- });
174
- const allCellsSelected = cellCount === selection.ranges.length;
175
- if (!allCellsSelected) {
176
- return false;
213
+ if (["tableCell", "tableHeader"].includes(node.type.name)) {
214
+ cellCount += 1;
177
215
  }
178
- editor.commands.deleteTable();
179
- return true;
216
+ });
217
+ const allCellsSelected = cellCount === selection.ranges.length;
218
+ if (!allCellsSelected) {
219
+ return false;
220
+ }
221
+ editor.commands.deleteTable();
222
+ return true;
180
223
  };
181
224
 
182
- /**
183
- * This extension allows you to create tables.
184
- * @see https://www.tiptap.dev/api/nodes/table
185
- */
186
- const Table = core.Node.create({
187
- name: 'table',
188
- // @ts-ignore
189
- addOptions() {
190
- return {
191
- HTMLAttributes: {},
192
- resizable: false,
193
- handleWidth: 5,
194
- cellMinWidth: 25,
195
- // TODO: fix
196
- View: TableView,
197
- lastColumnResizable: true,
198
- allowTableNodeSelection: false,
199
- };
200
- },
201
- content: 'tableRow+',
202
- tableRole: 'table',
203
- isolating: true,
204
- group: 'block',
205
- parseHTML() {
206
- return [{ tag: 'table' }];
207
- },
208
- renderHTML({ node, HTMLAttributes }) {
209
- const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth);
210
- const table = [
211
- 'table',
212
- core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
213
- style: tableWidth
214
- ? `width: ${tableWidth}`
215
- : `min-width: ${tableMinWidth}`,
216
- }),
217
- colgroup,
218
- ['tbody', 0],
219
- ];
220
- return table;
221
- },
222
- addCommands() {
223
- return {
224
- insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {
225
- const node = createTable(editor.schema, rows, cols, withHeaderRow);
226
- if (dispatch) {
227
- const offset = tr.selection.from + 1;
228
- tr.replaceSelectionWith(node)
229
- .scrollIntoView()
230
- .setSelection(state.TextSelection.near(tr.doc.resolve(offset)));
231
- }
232
- return true;
233
- },
234
- addColumnBefore: () => ({ state, dispatch }) => {
235
- return tables.addColumnBefore(state, dispatch);
236
- },
237
- addColumnAfter: () => ({ state, dispatch }) => {
238
- return tables.addColumnAfter(state, dispatch);
239
- },
240
- deleteColumn: () => ({ state, dispatch }) => {
241
- return tables.deleteColumn(state, dispatch);
242
- },
243
- addRowBefore: () => ({ state, dispatch }) => {
244
- return tables.addRowBefore(state, dispatch);
245
- },
246
- addRowAfter: () => ({ state, dispatch }) => {
247
- return tables.addRowAfter(state, dispatch);
248
- },
249
- deleteRow: () => ({ state, dispatch }) => {
250
- return tables.deleteRow(state, dispatch);
251
- },
252
- deleteTable: () => ({ state, dispatch }) => {
253
- return tables.deleteTable(state, dispatch);
254
- },
255
- mergeCells: () => ({ state, dispatch }) => {
256
- return tables.mergeCells(state, dispatch);
257
- },
258
- splitCell: () => ({ state, dispatch }) => {
259
- return tables.splitCell(state, dispatch);
260
- },
261
- toggleHeaderColumn: () => ({ state, dispatch }) => {
262
- return tables.toggleHeader('column')(state, dispatch);
263
- },
264
- toggleHeaderRow: () => ({ state, dispatch }) => {
265
- return tables.toggleHeader('row')(state, dispatch);
266
- },
267
- toggleHeaderCell: () => ({ state, dispatch }) => {
268
- return tables.toggleHeaderCell(state, dispatch);
269
- },
270
- mergeOrSplit: () => ({ state, dispatch }) => {
271
- if (tables.mergeCells(state, dispatch)) {
272
- return true;
273
- }
274
- return tables.splitCell(state, dispatch);
275
- },
276
- setCellAttribute: (name, value) => ({ state, dispatch }) => {
277
- return tables.setCellAttr(name, value)(state, dispatch);
278
- },
279
- goToNextCell: () => ({ state, dispatch }) => {
280
- return tables.goToNextCell(1)(state, dispatch);
281
- },
282
- goToPreviousCell: () => ({ state, dispatch }) => {
283
- return tables.goToNextCell(-1)(state, dispatch);
284
- },
285
- fixTables: () => ({ state, dispatch }) => {
286
- if (dispatch) {
287
- tables.fixTables(state);
288
- }
289
- return true;
290
- },
291
- setCellSelection: position => ({ tr, dispatch }) => {
292
- if (dispatch) {
293
- const selection = tables.CellSelection.create(tr.doc, position.anchorCell, position.headCell);
294
- // @ts-ignore
295
- tr.setSelection(selection);
296
- }
297
- return true;
298
- },
299
- };
300
- },
301
- addKeyboardShortcuts() {
302
- return {
303
- Tab: () => {
304
- if (this.editor.commands.goToNextCell()) {
305
- return true;
306
- }
307
- if (!this.editor.can().addRowAfter()) {
308
- return false;
309
- }
310
- return this.editor.chain().addRowAfter().goToNextCell().run();
311
- },
312
- 'Shift-Tab': () => this.editor.commands.goToPreviousCell(),
313
- Backspace: deleteTableWhenAllCellsSelected,
314
- 'Mod-Backspace': deleteTableWhenAllCellsSelected,
315
- Delete: deleteTableWhenAllCellsSelected,
316
- 'Mod-Delete': deleteTableWhenAllCellsSelected,
317
- };
318
- },
319
- addProseMirrorPlugins() {
320
- const isResizable = this.options.resizable && this.editor.isEditable;
321
- return [
322
- ...(isResizable
323
- ? [
324
- tables.columnResizing({
325
- handleWidth: this.options.handleWidth,
326
- cellMinWidth: this.options.cellMinWidth,
327
- View: this.options.View,
328
- lastColumnResizable: this.options.lastColumnResizable,
329
- }),
330
- ]
331
- : []),
332
- tables.tableEditing({
333
- allowTableNodeSelection: this.options.allowTableNodeSelection,
334
- }),
335
- ];
336
- },
337
- extendNodeSchema(extension) {
338
- const context = {
339
- name: extension.name,
340
- options: extension.options,
341
- storage: extension.storage,
342
- };
343
- return {
344
- tableRole: core.callOrReturn(core.getExtensionField(extension, 'tableRole', context)),
345
- };
346
- },
225
+ // src/table.ts
226
+ var Table = import_core2.Node.create({
227
+ name: "table",
228
+ // @ts-ignore
229
+ addOptions() {
230
+ return {
231
+ HTMLAttributes: {},
232
+ resizable: false,
233
+ handleWidth: 5,
234
+ cellMinWidth: 25,
235
+ // TODO: fix
236
+ View: TableView,
237
+ lastColumnResizable: true,
238
+ allowTableNodeSelection: false
239
+ };
240
+ },
241
+ content: "tableRow+",
242
+ tableRole: "table",
243
+ isolating: true,
244
+ group: "block",
245
+ parseHTML() {
246
+ return [{ tag: "table" }];
247
+ },
248
+ renderHTML({ node, HTMLAttributes }) {
249
+ const { colgroup, tableWidth, tableMinWidth } = createColGroup(
250
+ node,
251
+ this.options.cellMinWidth
252
+ );
253
+ const table = [
254
+ "table",
255
+ (0, import_core2.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {
256
+ style: tableWidth ? `width: ${tableWidth}` : `min-width: ${tableMinWidth}`
257
+ }),
258
+ colgroup,
259
+ ["tbody", 0]
260
+ ];
261
+ return table;
262
+ },
263
+ addCommands() {
264
+ return {
265
+ insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => {
266
+ const node = createTable(editor.schema, rows, cols, withHeaderRow);
267
+ if (dispatch) {
268
+ const offset = tr.selection.from + 1;
269
+ tr.replaceSelectionWith(node).scrollIntoView().setSelection(import_state.TextSelection.near(tr.doc.resolve(offset)));
270
+ }
271
+ return true;
272
+ },
273
+ addColumnBefore: () => ({ state, dispatch }) => {
274
+ return (0, import_tables2.addColumnBefore)(state, dispatch);
275
+ },
276
+ addColumnAfter: () => ({ state, dispatch }) => {
277
+ return (0, import_tables2.addColumnAfter)(state, dispatch);
278
+ },
279
+ deleteColumn: () => ({ state, dispatch }) => {
280
+ return (0, import_tables2.deleteColumn)(state, dispatch);
281
+ },
282
+ addRowBefore: () => ({ state, dispatch }) => {
283
+ return (0, import_tables2.addRowBefore)(state, dispatch);
284
+ },
285
+ addRowAfter: () => ({ state, dispatch }) => {
286
+ return (0, import_tables2.addRowAfter)(state, dispatch);
287
+ },
288
+ deleteRow: () => ({ state, dispatch }) => {
289
+ return (0, import_tables2.deleteRow)(state, dispatch);
290
+ },
291
+ deleteTable: () => ({ state, dispatch }) => {
292
+ return (0, import_tables2.deleteTable)(state, dispatch);
293
+ },
294
+ mergeCells: () => ({ state, dispatch }) => {
295
+ return (0, import_tables2.mergeCells)(state, dispatch);
296
+ },
297
+ splitCell: () => ({ state, dispatch }) => {
298
+ return (0, import_tables2.splitCell)(state, dispatch);
299
+ },
300
+ toggleHeaderColumn: () => ({ state, dispatch }) => {
301
+ return (0, import_tables2.toggleHeader)("column")(state, dispatch);
302
+ },
303
+ toggleHeaderRow: () => ({ state, dispatch }) => {
304
+ return (0, import_tables2.toggleHeader)("row")(state, dispatch);
305
+ },
306
+ toggleHeaderCell: () => ({ state, dispatch }) => {
307
+ return (0, import_tables2.toggleHeaderCell)(state, dispatch);
308
+ },
309
+ mergeOrSplit: () => ({ state, dispatch }) => {
310
+ if ((0, import_tables2.mergeCells)(state, dispatch)) {
311
+ return true;
312
+ }
313
+ return (0, import_tables2.splitCell)(state, dispatch);
314
+ },
315
+ setCellAttribute: (name, value) => ({ state, dispatch }) => {
316
+ return (0, import_tables2.setCellAttr)(name, value)(state, dispatch);
317
+ },
318
+ goToNextCell: () => ({ state, dispatch }) => {
319
+ return (0, import_tables2.goToNextCell)(1)(state, dispatch);
320
+ },
321
+ goToPreviousCell: () => ({ state, dispatch }) => {
322
+ return (0, import_tables2.goToNextCell)(-1)(state, dispatch);
323
+ },
324
+ fixTables: () => ({ state, dispatch }) => {
325
+ if (dispatch) {
326
+ (0, import_tables2.fixTables)(state);
327
+ }
328
+ return true;
329
+ },
330
+ setCellSelection: (position) => ({ tr, dispatch }) => {
331
+ if (dispatch) {
332
+ const selection = import_tables2.CellSelection.create(tr.doc, position.anchorCell, position.headCell);
333
+ tr.setSelection(selection);
334
+ }
335
+ return true;
336
+ }
337
+ };
338
+ },
339
+ addKeyboardShortcuts() {
340
+ return {
341
+ Tab: () => {
342
+ if (this.editor.commands.goToNextCell()) {
343
+ return true;
344
+ }
345
+ if (!this.editor.can().addRowAfter()) {
346
+ return false;
347
+ }
348
+ return this.editor.chain().addRowAfter().goToNextCell().run();
349
+ },
350
+ "Shift-Tab": () => this.editor.commands.goToPreviousCell(),
351
+ Backspace: deleteTableWhenAllCellsSelected,
352
+ "Mod-Backspace": deleteTableWhenAllCellsSelected,
353
+ Delete: deleteTableWhenAllCellsSelected,
354
+ "Mod-Delete": deleteTableWhenAllCellsSelected
355
+ };
356
+ },
357
+ addProseMirrorPlugins() {
358
+ const isResizable = this.options.resizable && this.editor.isEditable;
359
+ return [
360
+ ...isResizable ? [
361
+ (0, import_tables2.columnResizing)({
362
+ handleWidth: this.options.handleWidth,
363
+ cellMinWidth: this.options.cellMinWidth,
364
+ defaultCellMinWidth: this.options.cellMinWidth,
365
+ View: this.options.View,
366
+ lastColumnResizable: this.options.lastColumnResizable
367
+ })
368
+ ] : [],
369
+ (0, import_tables2.tableEditing)({
370
+ allowTableNodeSelection: this.options.allowTableNodeSelection
371
+ })
372
+ ];
373
+ },
374
+ extendNodeSchema(extension) {
375
+ const context = {
376
+ name: extension.name,
377
+ options: extension.options,
378
+ storage: extension.storage
379
+ };
380
+ return {
381
+ tableRole: (0, import_core2.callOrReturn)((0, import_core2.getExtensionField)(extension, "tableRole", context))
382
+ };
383
+ }
347
384
  });
348
385
 
349
- exports.Table = Table;
350
- exports.createColGroup = createColGroup;
351
- exports.createTable = createTable;
352
- exports.default = Table;
353
- //# sourceMappingURL=index.cjs.map
386
+ // src/index.ts
387
+ var src_default = Table;
388
+ // Annotate the CommonJS export names for ESM import in node:
389
+ 0 && (module.exports = {
390
+ Table,
391
+ createColGroup,
392
+ createTable
393
+ });
394
+ //# sourceMappingURL=index.cjs.map