You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
23 KiB
1 line
23 KiB
3 years ago
|
{"version":3,"file":"tiptap-extension-table.cjs","sources":["../src/TableView.ts","../src/utilities/createCell.ts","../src/utilities/getTableNodeTypes.ts","../src/utilities/createTable.ts","../src/utilities/isCellSelection.ts","../src/utilities/deleteTableWhenAllCellsSelected.ts","../src/table.ts"],"sourcesContent":["// @ts-nocheck\nimport { Node as ProseMirrorNode } from 'prosemirror-model'\nimport { NodeView } from 'prosemirror-view'\n\nexport function updateColumns(node: ProseMirrorNode, colgroup: Element, table: Element, cellMinWidth: number, overrideCol?: number, overrideValue?: any) {\n let totalWidth = 0\n let fixedWidth = true\n let nextDOM = colgroup.firstChild\n const row = node.firstChild\n\n for (let i = 0, col = 0; i < row.childCount; i += 1) {\n const { colspan, colwidth } = row.child(i).attrs\n\n for (let j = 0; j < colspan; j += 1, col += 1) {\n const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j]\n const cssWidth = hasWidth ? `${hasWidth}px` : ''\n\n totalWidth += hasWidth || cellMinWidth\n\n if (!hasWidth) {\n fixedWidth = false\n }\n\n if (!nextDOM) {\n colgroup.appendChild(document.createElement('col')).style.width = cssWidth\n } else {\n if (nextDOM.style.width !== cssWidth) {\n nextDOM.style.width = cssWidth\n }\n\n nextDOM = nextDOM.nextSibling\n }\n }\n }\n\n while (nextDOM) {\n const after = nextDOM.nextSibling\n\n nextDOM.parentNode.removeChild(nextDOM)\n nextDOM = after\n }\n\n if (fixedWidth) {\n table.style.width = `${totalWidth}px`\n table.style.minWidth = ''\n } else {\n table.style.width = ''\n table.style.minWidth = `${totalWidth}px`\n }\n}\n\nexport class TableView implements NodeView {\n\n node: ProseMirrorNode\n\n cellMinWidth: number\n\n dom: Element\n\n table: Element\n\n colgroup: Element\n\n contentDOM: Element\n\n constructor(node: ProseMirrorNode, cellMinWidth: number) {\n this.node = node\n this.cellMinWidth = cellMinWidth\n this.dom = document.createElement('div')\n this.dom.className = 'tableWrapper'\n this.table = this.dom.appendChild(document.createElement('table'))\n this.colgroup = this.table.appendChild(document.createElement('colgroup'))\n updateColumns(node, this.colgroup, this.table, cellMinWidth)\n this.contentDOM = this.table.appendChild(document.createElement('tbody'))\n }\n\n update(node: ProseMirrorNode) {\n if (node.type !== this.node.type) {\n return false\n }\n\n this.node = node\n updateColumns(node, this.colgroup, this.table, this.cellMinWidth)\n\n return true\n }\n\n ignoreMutation(mutation: MutationRecord | { type: 'selection'; target: Element }) {\n return mutation.type === 'attributes' && (mutation.target === this.table || this.colgroup.contains(mutation.target))\n }\n}\n","import { Fragment, Node as ProsemirrorNode, NodeType } from 'prosemirror-model'\n\nexport function createCell(cellType: NodeType, cellContent?: Fragment | ProsemirrorNode | Array<ProsemirrorNode>): ProsemirrorNode | null | undefined {\n if (cellContent) {\n return cellType.createChecked(null, cellContent)\n }\n\n return cellType.createAndFill()\n}\n","import { NodeType, Schema } from 'prosemirror-model'\n\nexport function getTableNodeTypes(schema: Schema): { [key: string]: NodeType } {\n if (schema.cached.tableNodeTypes) {\n return schema.cached.tableNodeTypes\n }\n\n const roles: { [key: string]: NodeType } = {}\n\n Object.keys(schema.nodes).forEach(type => {\n const nodeType = schema.nodes[type]\n\n if (nodeType.spec.tableRole) {\n roles[nodeType.spec.tableRole] = nodeType\n }\n })\n\n schema.cached.tableNodeTypes = roles\n\n return roles\n}\n","import { Fragment, Node as ProsemirrorNode, Schema } from 'prosemirror-model'\n\nimport { createCell } from './createCell'\nimport { getTableNodeTypes } from './getTableNodeTypes'\n\nexport function createTable(schema: Schema, rowsCount: number, colsCount: number, withHeaderRow: boolean, cellContent?: Frag
|