@tiptap/extension-table 3.0.0 → 3.0.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/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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
} from '@tiptap/core'
|
|
4
|
-
import { DOMOutputSpec } from '@tiptap/pm/model'
|
|
1
|
+
import '../types.js'
|
|
2
|
+
|
|
3
|
+
import { callOrReturn, getExtensionField, mergeAttributes, Node } from '@tiptap/core'
|
|
4
|
+
import type { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
5
5
|
import { TextSelection } from '@tiptap/pm/state'
|
|
6
6
|
import {
|
|
7
7
|
addColumnAfter,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
toggleHeader,
|
|
23
23
|
toggleHeaderCell,
|
|
24
24
|
} from '@tiptap/pm/tables'
|
|
25
|
-
import { NodeView } from '@tiptap/pm/view'
|
|
25
|
+
import type { EditorView, NodeView } from '@tiptap/pm/view'
|
|
26
26
|
|
|
27
27
|
import { TableView } from './TableView.js'
|
|
28
28
|
import { createColGroup } from './utilities/createColGroup.js'
|
|
@@ -62,7 +62,7 @@ export interface TableOptions {
|
|
|
62
62
|
* The node view to render the table.
|
|
63
63
|
* @default TableView
|
|
64
64
|
*/
|
|
65
|
-
View: NodeView
|
|
65
|
+
View: (new (node: ProseMirrorNode, cellMinWidth: number, view: EditorView) => NodeView) | null
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* Enables the resizing of the last column.
|
|
@@ -88,17 +88,13 @@ declare module '@tiptap/core' {
|
|
|
88
88
|
* @returns True if the command was successful, otherwise false
|
|
89
89
|
* @example editor.commands.insertTable({ rows: 3, cols: 3, withHeaderRow: true })
|
|
90
90
|
*/
|
|
91
|
-
insertTable: (options?: {
|
|
92
|
-
rows?: number
|
|
93
|
-
cols?: number
|
|
94
|
-
withHeaderRow?: boolean
|
|
95
|
-
}) => ReturnType
|
|
91
|
+
insertTable: (options?: { rows?: number; cols?: number; withHeaderRow?: boolean }) => ReturnType
|
|
96
92
|
|
|
97
93
|
/**
|
|
98
94
|
* Add a column before the current column
|
|
99
95
|
* @returns True if the command was successful, otherwise false
|
|
100
96
|
* @example editor.commands.addColumnBefore()
|
|
101
|
-
|
|
97
|
+
*/
|
|
102
98
|
addColumnBefore: () => ReturnType
|
|
103
99
|
|
|
104
100
|
/**
|
|
@@ -224,22 +220,6 @@ declare module '@tiptap/core' {
|
|
|
224
220
|
setCellSelection: (position: { anchorCell: number; headCell?: number }) => ReturnType
|
|
225
221
|
}
|
|
226
222
|
}
|
|
227
|
-
|
|
228
|
-
interface NodeConfig<Options, Storage> {
|
|
229
|
-
/**
|
|
230
|
-
* A string or function to determine the role of the table.
|
|
231
|
-
* @default 'table'
|
|
232
|
-
* @example () => 'table'
|
|
233
|
-
*/
|
|
234
|
-
tableRole?:
|
|
235
|
-
| string
|
|
236
|
-
| ((this: {
|
|
237
|
-
name: string
|
|
238
|
-
options: Options
|
|
239
|
-
storage: Storage
|
|
240
|
-
parent: ParentConfig<NodeConfig<Options>>['tableRole']
|
|
241
|
-
}) => string)
|
|
242
|
-
}
|
|
243
223
|
}
|
|
244
224
|
|
|
245
225
|
/**
|
|
@@ -276,17 +256,12 @@ export const Table = Node.create<TableOptions>({
|
|
|
276
256
|
},
|
|
277
257
|
|
|
278
258
|
renderHTML({ node, HTMLAttributes }) {
|
|
279
|
-
const { colgroup, tableWidth, tableMinWidth } = createColGroup(
|
|
280
|
-
node,
|
|
281
|
-
this.options.cellMinWidth,
|
|
282
|
-
)
|
|
259
|
+
const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth)
|
|
283
260
|
|
|
284
261
|
const table: DOMOutputSpec = [
|
|
285
262
|
'table',
|
|
286
263
|
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
|
|
287
|
-
style: tableWidth
|
|
288
|
-
? `width: ${tableWidth}`
|
|
289
|
-
: `minWidth: ${tableMinWidth}`,
|
|
264
|
+
style: tableWidth ? `width: ${tableWidth}` : `min-width: ${tableMinWidth}`,
|
|
290
265
|
}),
|
|
291
266
|
colgroup,
|
|
292
267
|
['tbody', 0],
|
|
@@ -298,7 +273,8 @@ export const Table = Node.create<TableOptions>({
|
|
|
298
273
|
addCommands() {
|
|
299
274
|
return {
|
|
300
275
|
insertTable:
|
|
301
|
-
({ rows = 3, cols = 3, withHeaderRow = true } = {}) =>
|
|
276
|
+
({ rows = 3, cols = 3, withHeaderRow = true } = {}) =>
|
|
277
|
+
({ tr, dispatch, editor }) => {
|
|
302
278
|
const node = createTable(editor.schema, rows, cols, withHeaderRow)
|
|
303
279
|
|
|
304
280
|
if (dispatch) {
|
|
@@ -312,55 +288,68 @@ export const Table = Node.create<TableOptions>({
|
|
|
312
288
|
return true
|
|
313
289
|
},
|
|
314
290
|
addColumnBefore:
|
|
315
|
-
() =>
|
|
291
|
+
() =>
|
|
292
|
+
({ state, dispatch }) => {
|
|
316
293
|
return addColumnBefore(state, dispatch)
|
|
317
294
|
},
|
|
318
295
|
addColumnAfter:
|
|
319
|
-
() =>
|
|
296
|
+
() =>
|
|
297
|
+
({ state, dispatch }) => {
|
|
320
298
|
return addColumnAfter(state, dispatch)
|
|
321
299
|
},
|
|
322
300
|
deleteColumn:
|
|
323
|
-
() =>
|
|
301
|
+
() =>
|
|
302
|
+
({ state, dispatch }) => {
|
|
324
303
|
return deleteColumn(state, dispatch)
|
|
325
304
|
},
|
|
326
305
|
addRowBefore:
|
|
327
|
-
() =>
|
|
306
|
+
() =>
|
|
307
|
+
({ state, dispatch }) => {
|
|
328
308
|
return addRowBefore(state, dispatch)
|
|
329
309
|
},
|
|
330
310
|
addRowAfter:
|
|
331
|
-
() =>
|
|
311
|
+
() =>
|
|
312
|
+
({ state, dispatch }) => {
|
|
332
313
|
return addRowAfter(state, dispatch)
|
|
333
314
|
},
|
|
334
315
|
deleteRow:
|
|
335
|
-
() =>
|
|
316
|
+
() =>
|
|
317
|
+
({ state, dispatch }) => {
|
|
336
318
|
return deleteRow(state, dispatch)
|
|
337
319
|
},
|
|
338
320
|
deleteTable:
|
|
339
|
-
() =>
|
|
321
|
+
() =>
|
|
322
|
+
({ state, dispatch }) => {
|
|
340
323
|
return deleteTable(state, dispatch)
|
|
341
324
|
},
|
|
342
325
|
mergeCells:
|
|
343
|
-
() =>
|
|
326
|
+
() =>
|
|
327
|
+
({ state, dispatch }) => {
|
|
344
328
|
return mergeCells(state, dispatch)
|
|
345
329
|
},
|
|
346
330
|
splitCell:
|
|
347
|
-
() =>
|
|
331
|
+
() =>
|
|
332
|
+
({ state, dispatch }) => {
|
|
348
333
|
return splitCell(state, dispatch)
|
|
349
334
|
},
|
|
350
335
|
toggleHeaderColumn:
|
|
351
|
-
() =>
|
|
336
|
+
() =>
|
|
337
|
+
({ state, dispatch }) => {
|
|
352
338
|
return toggleHeader('column')(state, dispatch)
|
|
353
339
|
},
|
|
354
340
|
toggleHeaderRow:
|
|
355
|
-
() =>
|
|
341
|
+
() =>
|
|
342
|
+
({ state, dispatch }) => {
|
|
356
343
|
return toggleHeader('row')(state, dispatch)
|
|
357
344
|
},
|
|
358
345
|
toggleHeaderCell:
|
|
359
|
-
() =>
|
|
346
|
+
() =>
|
|
347
|
+
({ state, dispatch }) => {
|
|
360
348
|
return toggleHeaderCell(state, dispatch)
|
|
361
349
|
},
|
|
362
350
|
mergeOrSplit:
|
|
363
|
-
() =>
|
|
351
|
+
() =>
|
|
352
|
+
({ state, dispatch }) => {
|
|
364
353
|
if (mergeCells(state, dispatch)) {
|
|
365
354
|
return true
|
|
366
355
|
}
|
|
@@ -368,19 +357,23 @@ export const Table = Node.create<TableOptions>({
|
|
|
368
357
|
return splitCell(state, dispatch)
|
|
369
358
|
},
|
|
370
359
|
setCellAttribute:
|
|
371
|
-
(name, value) =>
|
|
360
|
+
(name, value) =>
|
|
361
|
+
({ state, dispatch }) => {
|
|
372
362
|
return setCellAttr(name, value)(state, dispatch)
|
|
373
363
|
},
|
|
374
364
|
goToNextCell:
|
|
375
|
-
() =>
|
|
365
|
+
() =>
|
|
366
|
+
({ state, dispatch }) => {
|
|
376
367
|
return goToNextCell(1)(state, dispatch)
|
|
377
368
|
},
|
|
378
369
|
goToPreviousCell:
|
|
379
|
-
() =>
|
|
370
|
+
() =>
|
|
371
|
+
({ state, dispatch }) => {
|
|
380
372
|
return goToNextCell(-1)(state, dispatch)
|
|
381
373
|
},
|
|
382
374
|
fixTables:
|
|
383
|
-
() =>
|
|
375
|
+
() =>
|
|
376
|
+
({ state, dispatch }) => {
|
|
384
377
|
if (dispatch) {
|
|
385
378
|
fixTables(state)
|
|
386
379
|
}
|
|
@@ -388,7 +381,8 @@ export const Table = Node.create<TableOptions>({
|
|
|
388
381
|
return true
|
|
389
382
|
},
|
|
390
383
|
setCellSelection:
|
|
391
|
-
position =>
|
|
384
|
+
position =>
|
|
385
|
+
({ tr, dispatch }) => {
|
|
392
386
|
if (dispatch) {
|
|
393
387
|
const selection = CellSelection.create(tr.doc, position.anchorCell, position.headCell)
|
|
394
388
|
|
|
@@ -428,16 +422,14 @@ export const Table = Node.create<TableOptions>({
|
|
|
428
422
|
return [
|
|
429
423
|
...(isResizable
|
|
430
424
|
? [
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}),
|
|
440
|
-
]
|
|
425
|
+
columnResizing({
|
|
426
|
+
handleWidth: this.options.handleWidth,
|
|
427
|
+
cellMinWidth: this.options.cellMinWidth,
|
|
428
|
+
defaultCellMinWidth: this.options.cellMinWidth,
|
|
429
|
+
View: this.options.View,
|
|
430
|
+
lastColumnResizable: this.options.lastColumnResizable,
|
|
431
|
+
}),
|
|
432
|
+
]
|
|
441
433
|
: []),
|
|
442
434
|
tableEditing({
|
|
443
435
|
allowTableNodeSelection: this.options.allowTableNodeSelection,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function getColStyleDeclaration(minWidth: number, width: number | undefined): [string, string] {
|
|
2
|
+
if (width) {
|
|
3
|
+
// apply the stored width unless it is below the configured minimum cell width
|
|
4
|
+
return ['width', `${Math.max(width, minWidth)}px`]
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// set the minimum with on the column if it has no stored width
|
|
8
|
+
return ['min-width', `${minWidth}px`]
|
|
9
|
+
}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
1
|
+
import type { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
|
+
|
|
3
|
+
import { getColStyleDeclaration } from './colStyle.js'
|
|
4
|
+
|
|
5
|
+
export type ColGroup =
|
|
6
|
+
| {
|
|
7
|
+
colgroup: DOMOutputSpec
|
|
8
|
+
tableWidth: string
|
|
9
|
+
tableMinWidth: string
|
|
10
|
+
}
|
|
11
|
+
| Record<string, never>
|
|
2
12
|
|
|
3
13
|
/**
|
|
4
14
|
* Creates a colgroup element for a table node in ProseMirror.
|
|
@@ -9,12 +19,19 @@ import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
|
9
19
|
* @param overrideValue - (Optional) The width value to use for the overridden column.
|
|
10
20
|
* @returns An object containing the colgroup element, the total width of the table, and the minimum width of the table.
|
|
11
21
|
*/
|
|
22
|
+
export function createColGroup(node: ProseMirrorNode, cellMinWidth: number): ColGroup
|
|
23
|
+
export function createColGroup(
|
|
24
|
+
node: ProseMirrorNode,
|
|
25
|
+
cellMinWidth: number,
|
|
26
|
+
overrideCol: number,
|
|
27
|
+
overrideValue: number,
|
|
28
|
+
): ColGroup
|
|
12
29
|
export function createColGroup(
|
|
13
30
|
node: ProseMirrorNode,
|
|
14
31
|
cellMinWidth: number,
|
|
15
32
|
overrideCol?: number,
|
|
16
|
-
overrideValue?:
|
|
17
|
-
) {
|
|
33
|
+
overrideValue?: number,
|
|
34
|
+
): ColGroup {
|
|
18
35
|
let totalWidth = 0
|
|
19
36
|
let fixedWidth = true
|
|
20
37
|
const cols: DOMOutputSpec[] = []
|
|
@@ -28,8 +45,7 @@ export function createColGroup(
|
|
|
28
45
|
const { colspan, colwidth } = row.child(i).attrs
|
|
29
46
|
|
|
30
47
|
for (let j = 0; j < colspan; j += 1, col += 1) {
|
|
31
|
-
const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j]
|
|
32
|
-
const cssWidth = hasWidth ? `${hasWidth}px` : ''
|
|
48
|
+
const hasWidth = overrideCol === col ? overrideValue : colwidth && (colwidth[j] as number | undefined)
|
|
33
49
|
|
|
34
50
|
totalWidth += hasWidth || cellMinWidth
|
|
35
51
|
|
|
@@ -37,7 +53,9 @@ export function createColGroup(
|
|
|
37
53
|
fixedWidth = false
|
|
38
54
|
}
|
|
39
55
|
|
|
40
|
-
|
|
56
|
+
const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth)
|
|
57
|
+
|
|
58
|
+
cols.push(['col', { style: `${property}: ${value}` }])
|
|
41
59
|
}
|
|
42
60
|
}
|
|
43
61
|
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ParentConfig } from '@tiptap/core'
|
|
2
|
+
|
|
3
|
+
declare module '@tiptap/core' {
|
|
4
|
+
interface NodeConfig<Options, Storage> {
|
|
5
|
+
/**
|
|
6
|
+
* A string or function to determine the role of the table.
|
|
7
|
+
* @default 'table'
|
|
8
|
+
* @example () => 'table'
|
|
9
|
+
*/
|
|
10
|
+
tableRole?:
|
|
11
|
+
| string
|
|
12
|
+
| ((this: {
|
|
13
|
+
name: string
|
|
14
|
+
options: Options
|
|
15
|
+
storage: Storage
|
|
16
|
+
parent: ParentConfig<NodeConfig<Options>>['tableRole']
|
|
17
|
+
}) => string)
|
|
18
|
+
}
|
|
19
|
+
}
|