@tiptap/extension-table 3.0.0 → 3.0.2-beta.0
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/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/cell/index.cjs +68 -0
- package/dist/cell/index.cjs.map +1 -0
- package/dist/cell/index.d.cts +33 -0
- package/dist/cell/index.d.ts +33 -0
- package/dist/cell/index.js +41 -0
- package/dist/cell/index.js.map +1 -0
- package/dist/header/index.cjs +68 -0
- package/dist/header/index.cjs.map +1 -0
- package/dist/header/index.d.cts +33 -0
- package/dist/header/index.d.ts +33 -0
- package/dist/header/index.js +41 -0
- package/dist/header/index.js.map +1 -0
- package/dist/index.cjs +480 -321
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +305 -0
- package/dist/index.d.ts +305 -0
- package/dist/index.js +465 -316
- package/dist/index.js.map +1 -1
- package/dist/kit/index.cjs +497 -0
- package/dist/kit/index.cjs.map +1 -0
- package/dist/kit/index.d.cts +252 -0
- package/dist/kit/index.d.ts +252 -0
- package/dist/kit/index.js +490 -0
- package/dist/kit/index.js.map +1 -0
- package/dist/row/index.cjs +49 -0
- package/dist/row/index.cjs.map +1 -0
- package/dist/row/index.d.cts +33 -0
- package/dist/row/index.d.ts +33 -0
- package/dist/row/index.js +22 -0
- package/dist/row/index.js.map +1 -0
- package/dist/table/index.cjs +384 -0
- package/dist/table/index.cjs.map +1 -0
- package/dist/{packages/extension-table/src/table.d.ts → table/index.d.cts} +45 -19
- package/dist/table/index.d.ts +220 -0
- package/dist/table/index.js +373 -0
- package/dist/table/index.js.map +1 -0
- package/package.json +53 -11
- package/src/cell/index.ts +1 -0
- package/src/cell/table-cell.ts +60 -0
- package/src/header/index.ts +1 -0
- package/src/header/table-header.ts +60 -0
- package/src/index.ts +6 -7
- package/src/kit/index.ts +64 -0
- package/src/row/index.ts +1 -0
- package/src/row/table-row.ts +38 -0
- package/src/table/TableView.ts +108 -0
- package/src/table/index.ts +3 -0
- package/src/{table.ts → table/table.ts} +56 -64
- package/src/table/utilities/colStyle.ts +9 -0
- package/src/{utilities → table/utilities}/createCell.ts +1 -1
- package/src/{utilities → table/utilities}/createColGroup.ts +24 -6
- package/src/{utilities → table/utilities}/createTable.ts +1 -1
- package/src/{utilities → table/utilities}/deleteTableWhenAllCellsSelected.ts +2 -1
- package/src/{utilities → table/utilities}/getTableNodeTypes.ts +1 -1
- package/src/types.ts +19 -0
- package/dist/index.umd.js +0 -358
- 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 -161
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -343
- 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 -451
- package/dist/packages/core/src/Node.d.ts +0 -611
- 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 -15
- 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 -15
- 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 -2
- 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 -13
- 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 -255
- 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/src/TableView.ts +0 -100
- /package/src/{utilities → table/utilities}/isCellSelection.ts +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-table",
|
|
3
3
|
"description": "table extension for tiptap",
|
|
4
|
-
"version": "3.0.0",
|
|
4
|
+
"version": "3.0.2-beta.0",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -15,26 +15,68 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types":
|
|
18
|
+
"types": {
|
|
19
|
+
"import": "./dist/index.d.ts",
|
|
20
|
+
"require": "./dist/index.d.cts"
|
|
21
|
+
},
|
|
19
22
|
"import": "./dist/index.js",
|
|
20
23
|
"require": "./dist/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./table": {
|
|
26
|
+
"types": {
|
|
27
|
+
"import": "./dist/table/index.d.ts",
|
|
28
|
+
"require": "./dist/table/index.d.cts"
|
|
29
|
+
},
|
|
30
|
+
"import": "./dist/table/index.js",
|
|
31
|
+
"require": "./dist/table/index.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./cell": {
|
|
34
|
+
"types": {
|
|
35
|
+
"import": "./dist/cell/index.d.ts",
|
|
36
|
+
"require": "./dist/cell/index.d.cts"
|
|
37
|
+
},
|
|
38
|
+
"import": "./dist/cell/index.js",
|
|
39
|
+
"require": "./dist/cell/index.cjs"
|
|
40
|
+
},
|
|
41
|
+
"./header": {
|
|
42
|
+
"types": {
|
|
43
|
+
"import": "./dist/header/index.d.ts",
|
|
44
|
+
"require": "./dist/header/index.d.cts"
|
|
45
|
+
},
|
|
46
|
+
"import": "./dist/header/index.js",
|
|
47
|
+
"require": "./dist/header/index.cjs"
|
|
48
|
+
},
|
|
49
|
+
"./kit": {
|
|
50
|
+
"types": {
|
|
51
|
+
"import": "./dist/kit/index.d.ts",
|
|
52
|
+
"require": "./dist/kit/index.d.cts"
|
|
53
|
+
},
|
|
54
|
+
"import": "./dist/kit/index.js",
|
|
55
|
+
"require": "./dist/kit/index.cjs"
|
|
56
|
+
},
|
|
57
|
+
"./row": {
|
|
58
|
+
"types": {
|
|
59
|
+
"import": "./dist/row/index.d.ts",
|
|
60
|
+
"require": "./dist/row/index.d.cts"
|
|
61
|
+
},
|
|
62
|
+
"import": "./dist/row/index.js",
|
|
63
|
+
"require": "./dist/row/index.cjs"
|
|
21
64
|
}
|
|
22
65
|
},
|
|
23
66
|
"main": "dist/index.cjs",
|
|
24
67
|
"module": "dist/index.js",
|
|
25
|
-
"
|
|
26
|
-
"types": "dist/packages/extension-table/src/index.d.ts",
|
|
68
|
+
"types": "dist/index.d.ts",
|
|
27
69
|
"files": [
|
|
28
70
|
"src",
|
|
29
71
|
"dist"
|
|
30
72
|
],
|
|
31
73
|
"devDependencies": {
|
|
32
|
-
"@tiptap/core": "^3.0.0",
|
|
33
|
-
"@tiptap/pm": "^3.0.0"
|
|
74
|
+
"@tiptap/core": "^3.0.2-beta.0",
|
|
75
|
+
"@tiptap/pm": "^3.0.2-beta.0"
|
|
34
76
|
},
|
|
35
77
|
"peerDependencies": {
|
|
36
|
-
"@tiptap/core": "^3.0.0",
|
|
37
|
-
"@tiptap/pm": "^3.0.0"
|
|
78
|
+
"@tiptap/core": "^3.0.2-beta.0",
|
|
79
|
+
"@tiptap/pm": "^3.0.2-beta.0"
|
|
38
80
|
},
|
|
39
81
|
"repository": {
|
|
40
82
|
"type": "git",
|
|
@@ -42,7 +84,7 @@
|
|
|
42
84
|
"directory": "packages/extension-table"
|
|
43
85
|
},
|
|
44
86
|
"scripts": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
87
|
+
"build": "tsup",
|
|
88
|
+
"lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
|
|
47
89
|
}
|
|
48
|
-
}
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './table-cell.js'
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import '../types.js'
|
|
2
|
+
|
|
3
|
+
import { mergeAttributes, Node } from '@tiptap/core'
|
|
4
|
+
|
|
5
|
+
export interface TableCellOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The HTML attributes for a table cell node.
|
|
8
|
+
* @default {}
|
|
9
|
+
* @example { class: 'foo' }
|
|
10
|
+
*/
|
|
11
|
+
HTMLAttributes: Record<string, any>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This extension allows you to create table cells.
|
|
16
|
+
* @see https://www.tiptap.dev/api/nodes/table-cell
|
|
17
|
+
*/
|
|
18
|
+
export const TableCell = Node.create<TableCellOptions>({
|
|
19
|
+
name: 'tableCell',
|
|
20
|
+
|
|
21
|
+
addOptions() {
|
|
22
|
+
return {
|
|
23
|
+
HTMLAttributes: {},
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
content: 'block+',
|
|
28
|
+
|
|
29
|
+
addAttributes() {
|
|
30
|
+
return {
|
|
31
|
+
colspan: {
|
|
32
|
+
default: 1,
|
|
33
|
+
},
|
|
34
|
+
rowspan: {
|
|
35
|
+
default: 1,
|
|
36
|
+
},
|
|
37
|
+
colwidth: {
|
|
38
|
+
default: null,
|
|
39
|
+
parseHTML: element => {
|
|
40
|
+
const colwidth = element.getAttribute('colwidth')
|
|
41
|
+
const value = colwidth ? colwidth.split(',').map(width => parseInt(width, 10)) : null
|
|
42
|
+
|
|
43
|
+
return value
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
tableRole: 'cell',
|
|
50
|
+
|
|
51
|
+
isolating: true,
|
|
52
|
+
|
|
53
|
+
parseHTML() {
|
|
54
|
+
return [{ tag: 'td' }]
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
renderHTML({ HTMLAttributes }) {
|
|
58
|
+
return ['td', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
|
59
|
+
},
|
|
60
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './table-header.js'
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import '../types.js'
|
|
2
|
+
|
|
3
|
+
import { mergeAttributes, Node } from '@tiptap/core'
|
|
4
|
+
|
|
5
|
+
export interface TableHeaderOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The HTML attributes for a table header node.
|
|
8
|
+
* @default {}
|
|
9
|
+
* @example { class: 'foo' }
|
|
10
|
+
*/
|
|
11
|
+
HTMLAttributes: Record<string, any>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This extension allows you to create table headers.
|
|
16
|
+
* @see https://www.tiptap.dev/api/nodes/table-header
|
|
17
|
+
*/
|
|
18
|
+
export const TableHeader = Node.create<TableHeaderOptions>({
|
|
19
|
+
name: 'tableHeader',
|
|
20
|
+
|
|
21
|
+
addOptions() {
|
|
22
|
+
return {
|
|
23
|
+
HTMLAttributes: {},
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
content: 'block+',
|
|
28
|
+
|
|
29
|
+
addAttributes() {
|
|
30
|
+
return {
|
|
31
|
+
colspan: {
|
|
32
|
+
default: 1,
|
|
33
|
+
},
|
|
34
|
+
rowspan: {
|
|
35
|
+
default: 1,
|
|
36
|
+
},
|
|
37
|
+
colwidth: {
|
|
38
|
+
default: null,
|
|
39
|
+
parseHTML: element => {
|
|
40
|
+
const colwidth = element.getAttribute('colwidth')
|
|
41
|
+
const value = colwidth ? colwidth.split(',').map(width => parseInt(width, 10)) : null
|
|
42
|
+
|
|
43
|
+
return value
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
tableRole: 'header_cell',
|
|
50
|
+
|
|
51
|
+
isolating: true,
|
|
52
|
+
|
|
53
|
+
parseHTML() {
|
|
54
|
+
return [{ tag: 'th' }]
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
renderHTML({ HTMLAttributes }) {
|
|
58
|
+
return ['th', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
|
59
|
+
},
|
|
60
|
+
})
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
|
|
7
|
-
export default Table
|
|
1
|
+
export * from './cell/index.js'
|
|
2
|
+
export * from './header/index.js'
|
|
3
|
+
export * from './kit/index.js'
|
|
4
|
+
export * from './row/index.js'
|
|
5
|
+
export * from './table/index.js'
|
|
6
|
+
export * from './table/TableView.js'
|
package/src/kit/index.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core'
|
|
2
|
+
|
|
3
|
+
import type { TableCellOptions } from '../cell/index.js'
|
|
4
|
+
import { TableCell } from '../cell/index.js'
|
|
5
|
+
import type { TableHeaderOptions } from '../header/index.js'
|
|
6
|
+
import { TableHeader } from '../header/index.js'
|
|
7
|
+
import type { TableRowOptions } from '../row/index.js'
|
|
8
|
+
import { TableRow } from '../row/index.js'
|
|
9
|
+
import type { TableOptions } from '../table/index.js'
|
|
10
|
+
import { Table } from '../table/index.js'
|
|
11
|
+
|
|
12
|
+
export interface TableKitOptions {
|
|
13
|
+
/**
|
|
14
|
+
* If set to false, the table extension will not be registered
|
|
15
|
+
* @example table: false
|
|
16
|
+
*/
|
|
17
|
+
table: Partial<TableOptions> | false
|
|
18
|
+
/**
|
|
19
|
+
* If set to false, the table extension will not be registered
|
|
20
|
+
* @example tableCell: false
|
|
21
|
+
*/
|
|
22
|
+
tableCell: Partial<TableCellOptions> | false
|
|
23
|
+
/**
|
|
24
|
+
* If set to false, the table extension will not be registered
|
|
25
|
+
* @example tableHeader: false
|
|
26
|
+
*/
|
|
27
|
+
tableHeader: Partial<TableHeaderOptions> | false
|
|
28
|
+
/**
|
|
29
|
+
* If set to false, the table extension will not be registered
|
|
30
|
+
* @example tableRow: false
|
|
31
|
+
*/
|
|
32
|
+
tableRow: Partial<TableRowOptions> | false
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The table kit is a collection of table editor extensions.
|
|
37
|
+
*
|
|
38
|
+
* It’s a good starting point for building your own table in Tiptap.
|
|
39
|
+
*/
|
|
40
|
+
export const TableKit = Extension.create<TableKitOptions>({
|
|
41
|
+
name: 'tableKit',
|
|
42
|
+
|
|
43
|
+
addExtensions() {
|
|
44
|
+
const extensions = []
|
|
45
|
+
|
|
46
|
+
if (this.options.table !== false) {
|
|
47
|
+
extensions.push(Table.configure(this.options.table))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (this.options.tableCell !== false) {
|
|
51
|
+
extensions.push(TableCell.configure(this.options.tableCell))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (this.options.tableHeader !== false) {
|
|
55
|
+
extensions.push(TableHeader.configure(this.options.tableHeader))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (this.options.tableRow !== false) {
|
|
59
|
+
extensions.push(TableRow.configure(this.options.tableRow))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return extensions
|
|
63
|
+
},
|
|
64
|
+
})
|
package/src/row/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './table-row.js'
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import '../types.js'
|
|
2
|
+
|
|
3
|
+
import { mergeAttributes, Node } from '@tiptap/core'
|
|
4
|
+
|
|
5
|
+
export interface TableRowOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The HTML attributes for a table row node.
|
|
8
|
+
* @default {}
|
|
9
|
+
* @example { class: 'foo' }
|
|
10
|
+
*/
|
|
11
|
+
HTMLAttributes: Record<string, any>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This extension allows you to create table rows.
|
|
16
|
+
* @see https://www.tiptap.dev/api/nodes/table-row
|
|
17
|
+
*/
|
|
18
|
+
export const TableRow = Node.create<TableRowOptions>({
|
|
19
|
+
name: 'tableRow',
|
|
20
|
+
|
|
21
|
+
addOptions() {
|
|
22
|
+
return {
|
|
23
|
+
HTMLAttributes: {},
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
content: '(tableCell | tableHeader)*',
|
|
28
|
+
|
|
29
|
+
tableRole: 'row',
|
|
30
|
+
|
|
31
|
+
parseHTML() {
|
|
32
|
+
return [{ tag: 'tr' }]
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
renderHTML({ HTMLAttributes }) {
|
|
36
|
+
return ['tr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
|
37
|
+
},
|
|
38
|
+
})
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
|
+
import type { NodeView, ViewMutationRecord } from '@tiptap/pm/view'
|
|
3
|
+
|
|
4
|
+
import { getColStyleDeclaration } from './utilities/colStyle.js'
|
|
5
|
+
|
|
6
|
+
export function updateColumns(
|
|
7
|
+
node: ProseMirrorNode,
|
|
8
|
+
colgroup: HTMLTableColElement, // <colgroup> has the same prototype as <col>
|
|
9
|
+
table: HTMLTableElement,
|
|
10
|
+
cellMinWidth: number,
|
|
11
|
+
overrideCol?: number,
|
|
12
|
+
overrideValue?: number,
|
|
13
|
+
) {
|
|
14
|
+
let totalWidth = 0
|
|
15
|
+
let fixedWidth = true
|
|
16
|
+
let nextDOM = colgroup.firstChild
|
|
17
|
+
const row = node.firstChild
|
|
18
|
+
|
|
19
|
+
if (row !== null) {
|
|
20
|
+
for (let i = 0, col = 0; i < row.childCount; i += 1) {
|
|
21
|
+
const { colspan, colwidth } = row.child(i).attrs
|
|
22
|
+
|
|
23
|
+
for (let j = 0; j < colspan; j += 1, col += 1) {
|
|
24
|
+
const hasWidth = overrideCol === col ? overrideValue : ((colwidth && colwidth[j]) as number | undefined)
|
|
25
|
+
const cssWidth = hasWidth ? `${hasWidth}px` : ''
|
|
26
|
+
|
|
27
|
+
totalWidth += hasWidth || cellMinWidth
|
|
28
|
+
|
|
29
|
+
if (!hasWidth) {
|
|
30
|
+
fixedWidth = false
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!nextDOM) {
|
|
34
|
+
const colElement = document.createElement('col')
|
|
35
|
+
|
|
36
|
+
const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth)
|
|
37
|
+
|
|
38
|
+
colElement.style.setProperty(propertyKey, propertyValue)
|
|
39
|
+
|
|
40
|
+
colgroup.appendChild(colElement)
|
|
41
|
+
} else {
|
|
42
|
+
if ((nextDOM as HTMLTableColElement).style.width !== cssWidth) {
|
|
43
|
+
const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth)
|
|
44
|
+
|
|
45
|
+
;(nextDOM as HTMLTableColElement).style.setProperty(propertyKey, propertyValue)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
nextDOM = nextDOM.nextSibling
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
while (nextDOM) {
|
|
55
|
+
const after = nextDOM.nextSibling
|
|
56
|
+
|
|
57
|
+
nextDOM.parentNode?.removeChild(nextDOM)
|
|
58
|
+
nextDOM = after
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (fixedWidth) {
|
|
62
|
+
table.style.width = `${totalWidth}px`
|
|
63
|
+
table.style.minWidth = ''
|
|
64
|
+
} else {
|
|
65
|
+
table.style.width = ''
|
|
66
|
+
table.style.minWidth = `${totalWidth}px`
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export class TableView implements NodeView {
|
|
71
|
+
node: ProseMirrorNode
|
|
72
|
+
|
|
73
|
+
cellMinWidth: number
|
|
74
|
+
|
|
75
|
+
dom: HTMLDivElement
|
|
76
|
+
|
|
77
|
+
table: HTMLTableElement
|
|
78
|
+
|
|
79
|
+
colgroup: HTMLTableColElement
|
|
80
|
+
|
|
81
|
+
contentDOM: HTMLTableSectionElement
|
|
82
|
+
|
|
83
|
+
constructor(node: ProseMirrorNode, cellMinWidth: number) {
|
|
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
|
+
|
|
94
|
+
update(node: ProseMirrorNode) {
|
|
95
|
+
if (node.type !== this.node.type) {
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
this.node = node
|
|
100
|
+
updateColumns(node, this.colgroup, this.table, this.cellMinWidth)
|
|
101
|
+
|
|
102
|
+
return true
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
ignoreMutation(mutation: ViewMutationRecord) {
|
|
106
|
+
return mutation.type === 'attributes' && (mutation.target === this.table || this.colgroup.contains(mutation.target))
|
|
107
|
+
}
|
|
108
|
+
}
|