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