@kerebron/extension-tables 0.4.27 → 0.4.28
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/assets/tables.css +85 -0
- package/esm/ExtensionTables.d.ts +10 -0
- package/esm/ExtensionTables.d.ts.map +1 -0
- package/esm/ExtensionTables.js +14 -0
- package/esm/NodeTable.d.ts +19 -0
- package/esm/NodeTable.d.ts.map +1 -0
- package/esm/NodeTable.js +83 -0
- package/esm/NodeTableCell.d.ts +11 -0
- package/esm/NodeTableCell.d.ts.map +1 -0
- package/esm/NodeTableCell.js +53 -0
- package/esm/NodeTableHeader.d.ts +8 -0
- package/esm/NodeTableHeader.d.ts.map +1 -0
- package/esm/NodeTableHeader.js +43 -0
- package/esm/NodeTableRow.d.ts +11 -0
- package/esm/NodeTableRow.d.ts.map +1 -0
- package/esm/NodeTableRow.js +23 -0
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/package.json +3 -0
- package/esm/utilities/CellSelection.d.ts +53 -0
- package/esm/utilities/CellSelection.d.ts.map +1 -0
- package/esm/utilities/CellSelection.js +364 -0
- package/esm/utilities/TableMap.d.ts +92 -0
- package/esm/utilities/TableMap.d.ts.map +1 -0
- package/esm/utilities/TableMap.js +319 -0
- package/esm/utilities/TableView.d.ts +21 -0
- package/esm/utilities/TableView.d.ts.map +1 -0
- package/esm/utilities/TableView.js +80 -0
- package/esm/utilities/columnResizing.d.ts +50 -0
- package/esm/utilities/columnResizing.d.ts.map +1 -0
- package/esm/utilities/columnResizing.js +299 -0
- package/esm/utilities/commands.d.ts +164 -0
- package/esm/utilities/commands.d.ts.map +1 -0
- package/esm/utilities/commands.js +702 -0
- package/esm/utilities/copypaste.d.ts +35 -0
- package/esm/utilities/copypaste.d.ts.map +1 -0
- package/esm/utilities/copypaste.js +283 -0
- package/esm/utilities/createCell.d.ts +3 -0
- package/esm/utilities/createCell.d.ts.map +1 -0
- package/esm/utilities/createCell.js +6 -0
- package/esm/utilities/createTable.d.ts +3 -0
- package/esm/utilities/createTable.d.ts.map +1 -0
- package/esm/utilities/createTable.js +31 -0
- package/esm/utilities/fixTables.d.ts +20 -0
- package/esm/utilities/fixTables.d.ts.map +1 -0
- package/esm/utilities/fixTables.js +146 -0
- package/esm/utilities/getTableNodeTypes.d.ts +5 -0
- package/esm/utilities/getTableNodeTypes.d.ts.map +1 -0
- package/esm/utilities/getTableNodeTypes.js +14 -0
- package/esm/utilities/input.d.ts +21 -0
- package/esm/utilities/input.d.ts.map +1 -0
- package/esm/utilities/input.js +241 -0
- package/esm/utilities/tableEditing.d.ts +23 -0
- package/esm/utilities/tableEditing.d.ts.map +1 -0
- package/esm/utilities/tableEditing.js +63 -0
- package/esm/utilities/tableNodeTypes.d.ts +14 -0
- package/esm/utilities/tableNodeTypes.d.ts.map +1 -0
- package/esm/utilities/tableNodeTypes.js +16 -0
- package/esm/utilities/util.d.ts +73 -0
- package/esm/utilities/util.d.ts.map +1 -0
- package/esm/utilities/util.js +155 -0
- package/package.json +2 -3
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
.kb-editor .tableWrapper {
|
|
2
|
+
overflow-x: auto;
|
|
3
|
+
}
|
|
4
|
+
.kb-editor table {
|
|
5
|
+
border-collapse: collapse;
|
|
6
|
+
table-layout: fixed;
|
|
7
|
+
width: 100%;
|
|
8
|
+
overflow: hidden;
|
|
9
|
+
}
|
|
10
|
+
.kb-editor td,
|
|
11
|
+
.kb-editor th {
|
|
12
|
+
vertical-align: top;
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
position: relative;
|
|
15
|
+
border: 1px solid var(--kb-color-border);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.kb-editor td:not([data-colwidth]):not(.column-resize-dragging),
|
|
19
|
+
.kb-editor th:not([data-colwidth]):not(.column-resize-dragging) {
|
|
20
|
+
/* if there's no explicit width set and the column is not being resized, set a default width */
|
|
21
|
+
min-width: var(--default-cell-min-width);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.kb-editor .column-resize-handle {
|
|
25
|
+
position: absolute;
|
|
26
|
+
right: -2px;
|
|
27
|
+
top: 0;
|
|
28
|
+
bottom: 0;
|
|
29
|
+
width: 4px;
|
|
30
|
+
z-index: 20;
|
|
31
|
+
background-color: #adf;
|
|
32
|
+
pointer-events: none;
|
|
33
|
+
}
|
|
34
|
+
.kb-editor.resize-cursor {
|
|
35
|
+
cursor: ew-resize;
|
|
36
|
+
cursor: col-resize;
|
|
37
|
+
}
|
|
38
|
+
/* Give selected cells a blue overlay */
|
|
39
|
+
.kb-editor .selectedCell:after {
|
|
40
|
+
z-index: 2;
|
|
41
|
+
position: absolute;
|
|
42
|
+
content: '';
|
|
43
|
+
left: 0;
|
|
44
|
+
right: 0;
|
|
45
|
+
top: 0;
|
|
46
|
+
bottom: 0;
|
|
47
|
+
background: rgba(200, 200, 255, 0.4);
|
|
48
|
+
pointer-events: none;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Touch-optimized table editing */
|
|
52
|
+
@media (max-width: 767px) {
|
|
53
|
+
.kb-editor table {
|
|
54
|
+
font-size: var(--kb-text-sm);
|
|
55
|
+
border-collapse: collapse;
|
|
56
|
+
width: 100%;
|
|
57
|
+
overflow-x: auto;
|
|
58
|
+
display: block;
|
|
59
|
+
white-space: nowrap;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.kb-editor th,
|
|
63
|
+
.kb-editor td {
|
|
64
|
+
min-width: 120px;
|
|
65
|
+
padding: var(--kb-space-md);
|
|
66
|
+
border: 1px solid var(--kb-color-border);
|
|
67
|
+
vertical-align: top;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* Hide complex table controls on mobile */
|
|
71
|
+
.tableWrapper .column-resize-handle {
|
|
72
|
+
display: none !important;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.kb-editor .tableWrapper {
|
|
76
|
+
overflow-x: auto;
|
|
77
|
+
-webkit-overflow-scrolling: touch;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* Table selection visual feedback */
|
|
81
|
+
.kb-editor .selectedCell {
|
|
82
|
+
background: rgba(var(--kb-color-primary-rgb), 0.1);
|
|
83
|
+
border: 2px solid var(--kb-color-primary);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Extension } from '@kerebron/editor';
|
|
2
|
+
import { NodeTable } from './NodeTable.js';
|
|
3
|
+
import { NodeTableRow } from './NodeTableRow.js';
|
|
4
|
+
import { NodeTableHeader } from './NodeTableHeader.js';
|
|
5
|
+
import { NodeTableCell } from './NodeTableCell.js';
|
|
6
|
+
export declare class ExtensionTables extends Extension {
|
|
7
|
+
name: string;
|
|
8
|
+
requires: (NodeTable | NodeTableRow | NodeTableHeader | NodeTableCell)[];
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ExtensionTables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionTables.d.ts","sourceRoot":"","sources":["../src/ExtensionTables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,qBAAa,eAAgB,SAAQ,SAAS;IAC5C,IAAI,SAAsB;IAC1B,QAAQ,iEAKN;CACH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Extension } from '@kerebron/editor';
|
|
2
|
+
import { NodeTable } from './NodeTable.js';
|
|
3
|
+
import { NodeTableRow } from './NodeTableRow.js';
|
|
4
|
+
import { NodeTableHeader } from './NodeTableHeader.js';
|
|
5
|
+
import { NodeTableCell } from './NodeTableCell.js';
|
|
6
|
+
export class ExtensionTables extends Extension {
|
|
7
|
+
name = 'extension-tables';
|
|
8
|
+
requires = [
|
|
9
|
+
new NodeTable(),
|
|
10
|
+
new NodeTableHeader(),
|
|
11
|
+
new NodeTableRow(),
|
|
12
|
+
new NodeTableCell(),
|
|
13
|
+
];
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NodeSpec, NodeType } from 'prosemirror-model';
|
|
2
|
+
import { type CoreEditor, Node } from '@kerebron/editor';
|
|
3
|
+
import { type CommandFactories, type CommandShortcuts } from '@kerebron/editor/commands';
|
|
4
|
+
import { Plugin } from 'prosemirror-state';
|
|
5
|
+
export declare class NodeTable extends Node {
|
|
6
|
+
name: string;
|
|
7
|
+
requires: string[];
|
|
8
|
+
attributes: {
|
|
9
|
+
class: {
|
|
10
|
+
default: string;
|
|
11
|
+
fromDom(element: HTMLElement): any;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
getNodeSpec(): NodeSpec;
|
|
15
|
+
getCommandFactories(editor: CoreEditor, type: NodeType): Partial<CommandFactories>;
|
|
16
|
+
getKeyboardShortcuts(): Partial<CommandShortcuts>;
|
|
17
|
+
getProseMirrorPlugins(): Plugin[];
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=NodeTable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeTable.d.ts","sourceRoot":"","sources":["../src/NodeTable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,EAAE,KAAK,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,2BAA2B,CAAC;AA4BnC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,qBAAa,SAAU,SAAQ,IAAI;IACxB,IAAI,SAAW;IACxB,QAAQ,WAAW;IAEV,UAAU;;;6BAGE,WAAW;;MAM9B;IAEO,WAAW,IAAI,QAAQ;IAgBvB,mBAAmB,CAC1B,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,gBAAgB,CAAC;IAsDnB,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAKjD,qBAAqB,IAAI,MAAM,EAAE;CAM3C"}
|
package/esm/NodeTable.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { TextSelection } from 'prosemirror-state';
|
|
2
|
+
import { Node } from '@kerebron/editor';
|
|
3
|
+
import { getHtmlAttributes, setHtmlAttributes, } from '@kerebron/editor/utilities';
|
|
4
|
+
import { createTable } from './utilities/createTable.js';
|
|
5
|
+
import { CellSelection } from './utilities/CellSelection.js';
|
|
6
|
+
import { columnResizing } from './utilities/columnResizing.js';
|
|
7
|
+
import { tableEditing } from './utilities/tableEditing.js';
|
|
8
|
+
import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, deleteColumn, deleteRow, deleteTable, goToNextCell, mergeCells, setCellAttr, splitCell, toggleHeader, toggleHeaderCell, toggleHeaderColumn, toggleHeaderRow, } from './utilities/commands.js';
|
|
9
|
+
export class NodeTable extends Node {
|
|
10
|
+
name = 'table';
|
|
11
|
+
requires = ['doc'];
|
|
12
|
+
attributes = {
|
|
13
|
+
class: {
|
|
14
|
+
default: 'table',
|
|
15
|
+
fromDom(element) {
|
|
16
|
+
return element.hasAttribute('class')
|
|
17
|
+
? element.getAttribute('class')
|
|
18
|
+
: undefined;
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
getNodeSpec() {
|
|
23
|
+
return {
|
|
24
|
+
content: 'table_row+',
|
|
25
|
+
tableRole: 'table',
|
|
26
|
+
isolating: true,
|
|
27
|
+
group: 'block',
|
|
28
|
+
parseDOM: [{
|
|
29
|
+
tag: 'table',
|
|
30
|
+
getAttrs: (element) => setHtmlAttributes(this, element),
|
|
31
|
+
}],
|
|
32
|
+
toDOM: (node) => ['table', getHtmlAttributes(this, node), ['tbody', 0]],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
getCommandFactories(editor, type) {
|
|
36
|
+
const commands = {
|
|
37
|
+
addColumnAfter: () => (state, dispatch) => addColumnAfter(state, dispatch),
|
|
38
|
+
addColumnBefore: () => (state, dispatch) => addColumnBefore(state, dispatch),
|
|
39
|
+
addRowAfter: () => (state, dispatch) => addRowAfter(state, dispatch),
|
|
40
|
+
addRowBefore: () => (state, dispatch) => addRowBefore(state, dispatch),
|
|
41
|
+
deleteColumn: () => (state, dispatch) => deleteColumn(state, dispatch),
|
|
42
|
+
deleteRow: () => (state, dispatch) => deleteRow(state, dispatch),
|
|
43
|
+
deleteTable: () => (state, dispatch) => deleteTable(state, dispatch),
|
|
44
|
+
goToNextCell: (direction) => goToNextCell(direction),
|
|
45
|
+
mergeCells: () => (state, dispatch) => mergeCells(state, dispatch),
|
|
46
|
+
setCellAttr: (...args) => setCellAttr(...args),
|
|
47
|
+
splitCell: () => (state, dispatch) => splitCell(state, dispatch),
|
|
48
|
+
toggleHeader: (...args) => toggleHeader(...args),
|
|
49
|
+
toggleHeaderCell: () => (state, dispatch) => toggleHeaderCell(state, dispatch),
|
|
50
|
+
toggleHeaderRow: () => (state, dispatch) => toggleHeaderRow(state, dispatch),
|
|
51
|
+
toggleHeaderColumn: () => (state, dispatch) => toggleHeaderColumn(state, dispatch),
|
|
52
|
+
insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => (state, dispatch) => {
|
|
53
|
+
const tr = state.tr;
|
|
54
|
+
const node = createTable(editor.schema, rows, cols, withHeaderRow);
|
|
55
|
+
if (dispatch) {
|
|
56
|
+
const offset = tr.selection.from + 1;
|
|
57
|
+
tr.replaceSelectionWith(node)
|
|
58
|
+
.scrollIntoView()
|
|
59
|
+
.setSelection(TextSelection.near(tr.doc.resolve(offset)));
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
},
|
|
63
|
+
setCellSelection: (position) => (state, dispatch) => {
|
|
64
|
+
if (dispatch) {
|
|
65
|
+
const selection = CellSelection.create(state.doc, position.anchorCell, position.headCell);
|
|
66
|
+
state.tr.setSelection(selection);
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
return commands;
|
|
72
|
+
}
|
|
73
|
+
getKeyboardShortcuts() {
|
|
74
|
+
const keys = {};
|
|
75
|
+
return keys;
|
|
76
|
+
}
|
|
77
|
+
getProseMirrorPlugins() {
|
|
78
|
+
return [
|
|
79
|
+
columnResizing(),
|
|
80
|
+
tableEditing(),
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NodeSpec, NodeType } from 'prosemirror-model';
|
|
2
|
+
import { type CoreEditor, Node } from '@kerebron/editor';
|
|
3
|
+
import { type CommandFactories, type CommandShortcuts } from '@kerebron/editor/commands';
|
|
4
|
+
export declare class NodeTableCell extends Node {
|
|
5
|
+
name: string;
|
|
6
|
+
requires: string[];
|
|
7
|
+
getNodeSpec(): NodeSpec;
|
|
8
|
+
getCommandFactories(editor: CoreEditor, type: NodeType): Partial<CommandFactories>;
|
|
9
|
+
getKeyboardShortcuts(): Partial<CommandShortcuts>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=NodeTableCell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeTableCell.d.ts","sourceRoot":"","sources":["../src/NodeTableCell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAAE,KAAK,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,2BAA2B,CAAC;AA4BnC,qBAAa,aAAc,SAAQ,IAAI;IAC5B,IAAI,SAAgB;IAC7B,QAAQ,WAAiB;IAEhB,WAAW,IAAI,QAAQ;IAmBvB,mBAAmB,CAC1B,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,gBAAgB,CAAC;IAKnB,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAI3D"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Node } from '@kerebron/editor';
|
|
2
|
+
function getCellAttrs(dom) {
|
|
3
|
+
if (typeof dom === 'string') {
|
|
4
|
+
return {};
|
|
5
|
+
}
|
|
6
|
+
const widthAttr = dom.getAttribute('data-colwidth');
|
|
7
|
+
const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr)
|
|
8
|
+
? widthAttr.split(',').map((s) => Number(s))
|
|
9
|
+
: null;
|
|
10
|
+
const colspan = Number(dom.getAttribute('colspan') || 1);
|
|
11
|
+
return {
|
|
12
|
+
colspan,
|
|
13
|
+
rowspan: Number(dom.getAttribute('rowspan') || 1),
|
|
14
|
+
colwidth: widths && widths.length == colspan ? widths : null,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function setCellAttrs(node) {
|
|
18
|
+
return {
|
|
19
|
+
colspan: (node.attrs.colspan != 1) ? node.attrs.colspan : undefined,
|
|
20
|
+
rowspan: (node.attrs.rowspan != 1) ? node.attrs.rowspan : undefined,
|
|
21
|
+
'data-colwidth': node.attrs.colwidth?.join(','),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export class NodeTableCell extends Node {
|
|
25
|
+
name = 'table_cell';
|
|
26
|
+
requires = ['table_row'];
|
|
27
|
+
getNodeSpec() {
|
|
28
|
+
return {
|
|
29
|
+
content: 'block+',
|
|
30
|
+
attrs: {
|
|
31
|
+
colspan: { default: 1 },
|
|
32
|
+
rowspan: { default: 1 },
|
|
33
|
+
colwidth: { default: null },
|
|
34
|
+
},
|
|
35
|
+
tableRole: 'cell',
|
|
36
|
+
isolating: true,
|
|
37
|
+
parseDOM: [
|
|
38
|
+
{ tag: 'td', getAttrs: (dom) => getCellAttrs(dom) },
|
|
39
|
+
],
|
|
40
|
+
toDOM(node) {
|
|
41
|
+
return ['td', setCellAttrs(node), 0];
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
getCommandFactories(editor, type) {
|
|
46
|
+
const commands = {};
|
|
47
|
+
return commands;
|
|
48
|
+
}
|
|
49
|
+
getKeyboardShortcuts() {
|
|
50
|
+
const keys = {};
|
|
51
|
+
return keys;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeTableHeader.d.ts","sourceRoot":"","sources":["../src/NodeTableHeader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AA2BxC,qBAAa,eAAgB,SAAQ,IAAI;IAC9B,IAAI,SAAkB;IAC/B,QAAQ,WAAa;IAEZ,WAAW,IAAI,QAAQ;CAgBjC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Node } from '@kerebron/editor';
|
|
2
|
+
function getCellAttrs(dom) {
|
|
3
|
+
if (typeof dom === 'string') {
|
|
4
|
+
return {};
|
|
5
|
+
}
|
|
6
|
+
const widthAttr = dom.getAttribute('data-colwidth');
|
|
7
|
+
const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr)
|
|
8
|
+
? widthAttr.split(',').map((s) => Number(s))
|
|
9
|
+
: null;
|
|
10
|
+
const colspan = Number(dom.getAttribute('colspan') || 1);
|
|
11
|
+
return {
|
|
12
|
+
colspan,
|
|
13
|
+
rowspan: Number(dom.getAttribute('rowspan') || 1),
|
|
14
|
+
colwidth: widths && widths.length == colspan ? widths : null,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function setCellAttrs(node) {
|
|
18
|
+
return {
|
|
19
|
+
colspan: (node.attrs.colspan != 1) ? node.attrs.colspan : undefined,
|
|
20
|
+
rowspan: (node.attrs.rowspan != 1) ? node.attrs.rowspan : undefined,
|
|
21
|
+
'data-colwidth': node.attrs.colwidth?.join(','),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export class NodeTableHeader extends Node {
|
|
25
|
+
name = 'table_header';
|
|
26
|
+
requires = ['table'];
|
|
27
|
+
getNodeSpec() {
|
|
28
|
+
return {
|
|
29
|
+
content: 'block+',
|
|
30
|
+
attrs: {
|
|
31
|
+
colspan: { default: 1 },
|
|
32
|
+
rowspan: { default: 1 },
|
|
33
|
+
colwidth: { default: null },
|
|
34
|
+
},
|
|
35
|
+
tableRole: 'header_cell',
|
|
36
|
+
isolating: true,
|
|
37
|
+
parseDOM: [
|
|
38
|
+
{ tag: 'th', getAttrs: (dom) => getCellAttrs(dom) },
|
|
39
|
+
],
|
|
40
|
+
toDOM: (node) => ['th', setCellAttrs(node), 0],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NodeSpec, NodeType } from 'prosemirror-model';
|
|
2
|
+
import { type CoreEditor, Node } from '@kerebron/editor';
|
|
3
|
+
import { type CommandFactories, type CommandShortcuts } from '@kerebron/editor/commands';
|
|
4
|
+
export declare class NodeTableRow extends Node {
|
|
5
|
+
name: string;
|
|
6
|
+
requires: string[];
|
|
7
|
+
getNodeSpec(): NodeSpec;
|
|
8
|
+
getCommandFactories(editor: CoreEditor, type: NodeType): Partial<CommandFactories>;
|
|
9
|
+
getKeyboardShortcuts(): Partial<CommandShortcuts>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=NodeTableRow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeTableRow.d.ts","sourceRoot":"","sources":["../src/NodeTableRow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,KAAK,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,2BAA2B,CAAC;AAMnC,qBAAa,YAAa,SAAQ,IAAI;IAC3B,IAAI,SAAe;IAC5B,QAAQ,WAAa;IAEZ,WAAW,IAAI,QAAQ;IAWvB,mBAAmB,CAC1B,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,QAAQ,GACb,OAAO,CAAC,gBAAgB,CAAC;IAMnB,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAI3D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Node } from '@kerebron/editor';
|
|
2
|
+
export class NodeTableRow extends Node {
|
|
3
|
+
name = 'table_row';
|
|
4
|
+
requires = ['table'];
|
|
5
|
+
getNodeSpec() {
|
|
6
|
+
return {
|
|
7
|
+
content: '(table_cell | table_header)*',
|
|
8
|
+
tableRole: 'row',
|
|
9
|
+
parseDOM: [{ tag: 'tr' }],
|
|
10
|
+
toDOM() {
|
|
11
|
+
return ['tr', 0];
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
getCommandFactories(editor, type) {
|
|
16
|
+
const commands = {};
|
|
17
|
+
return commands;
|
|
18
|
+
}
|
|
19
|
+
getKeyboardShortcuts() {
|
|
20
|
+
const keys = {};
|
|
21
|
+
return keys;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,gCAA2C,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const dntGlobals = {};
|
|
2
|
+
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
3
|
+
function createMergeProxy(baseObj, extObj) {
|
|
4
|
+
return new Proxy(baseObj, {
|
|
5
|
+
get(_target, prop, _receiver) {
|
|
6
|
+
if (prop in extObj) {
|
|
7
|
+
return extObj[prop];
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return baseObj[prop];
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
set(_target, prop, value) {
|
|
14
|
+
if (prop in extObj) {
|
|
15
|
+
delete extObj[prop];
|
|
16
|
+
}
|
|
17
|
+
baseObj[prop] = value;
|
|
18
|
+
return true;
|
|
19
|
+
},
|
|
20
|
+
deleteProperty(_target, prop) {
|
|
21
|
+
let success = false;
|
|
22
|
+
if (prop in extObj) {
|
|
23
|
+
delete extObj[prop];
|
|
24
|
+
success = true;
|
|
25
|
+
}
|
|
26
|
+
if (prop in baseObj) {
|
|
27
|
+
delete baseObj[prop];
|
|
28
|
+
success = true;
|
|
29
|
+
}
|
|
30
|
+
return success;
|
|
31
|
+
},
|
|
32
|
+
ownKeys(_target) {
|
|
33
|
+
const baseKeys = Reflect.ownKeys(baseObj);
|
|
34
|
+
const extKeys = Reflect.ownKeys(extObj);
|
|
35
|
+
const extKeysSet = new Set(extKeys);
|
|
36
|
+
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
37
|
+
},
|
|
38
|
+
defineProperty(_target, prop, desc) {
|
|
39
|
+
if (prop in extObj) {
|
|
40
|
+
delete extObj[prop];
|
|
41
|
+
}
|
|
42
|
+
Reflect.defineProperty(baseObj, prop, desc);
|
|
43
|
+
return true;
|
|
44
|
+
},
|
|
45
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
46
|
+
if (prop in extObj) {
|
|
47
|
+
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
has(_target, prop) {
|
|
54
|
+
return prop in extObj || prop in baseObj;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
package/esm/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Node, ResolvedPos, Slice } from 'prosemirror-model';
|
|
2
|
+
import { EditorState, Selection, Transaction } from 'prosemirror-state';
|
|
3
|
+
import { DecorationSource } from 'prosemirror-view';
|
|
4
|
+
import { Mappable } from 'prosemirror-transform';
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface CellSelectionJSON {
|
|
9
|
+
type: string;
|
|
10
|
+
anchor: number;
|
|
11
|
+
head: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A [`Selection`](http://prosemirror.net/docs/ref/#state.Selection)
|
|
15
|
+
* subclass that represents a cell selection spanning part of a table.
|
|
16
|
+
* With the plugin enabled, these will be created when the user
|
|
17
|
+
* selects across cells, and will be drawn by giving selected cells a
|
|
18
|
+
* `selectedCell` CSS class.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare class CellSelection extends Selection {
|
|
23
|
+
$anchorCell: ResolvedPos;
|
|
24
|
+
$headCell: ResolvedPos;
|
|
25
|
+
constructor($anchorCell: ResolvedPos, $headCell?: ResolvedPos);
|
|
26
|
+
map(doc: Node, mapping: Mappable): CellSelection | Selection;
|
|
27
|
+
content(): Slice;
|
|
28
|
+
replace(tr: Transaction, content?: Slice): void;
|
|
29
|
+
replaceWith(tr: Transaction, node: Node): void;
|
|
30
|
+
forEachCell(f: (node: Node, pos: number) => void): void;
|
|
31
|
+
isColSelection(): boolean;
|
|
32
|
+
static colSelection($anchorCell: ResolvedPos, $headCell?: ResolvedPos): CellSelection;
|
|
33
|
+
isRowSelection(): boolean;
|
|
34
|
+
eq(other: unknown): boolean;
|
|
35
|
+
static rowSelection($anchorCell: ResolvedPos, $headCell?: ResolvedPos): CellSelection;
|
|
36
|
+
toJSON(): CellSelectionJSON;
|
|
37
|
+
static fromJSON(doc: Node, json: CellSelectionJSON): CellSelection;
|
|
38
|
+
static create(doc: Node, anchorCell: number, headCell?: number): CellSelection;
|
|
39
|
+
getBookmark(): CellBookmark;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare class CellBookmark {
|
|
45
|
+
anchor: number;
|
|
46
|
+
head: number;
|
|
47
|
+
constructor(anchor: number, head: number);
|
|
48
|
+
map(mapping: Mappable): CellBookmark;
|
|
49
|
+
resolve(doc: Node): CellSelection | Selection;
|
|
50
|
+
}
|
|
51
|
+
export declare function drawCellSelection(state: EditorState): DecorationSource | null;
|
|
52
|
+
export declare function normalizeSelection(state: EditorState, tr: Transaction | undefined, allowTableNodeSelection: boolean): Transaction | undefined;
|
|
53
|
+
//# sourceMappingURL=CellSelection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CellSelection.d.ts","sourceRoot":"","sources":["../../src/utilities/CellSelection.ts"],"names":[],"mappings":"AAKA,OAAO,EAAY,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EACL,WAAW,EAEX,SAAS,EAGT,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAA6B,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIjD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;GAQG;AACH,qBAAa,aAAc,SAAQ,SAAS;IAGnC,WAAW,EAAE,WAAW,CAAC;IAIzB,SAAS,EAAE,WAAW,CAAC;gBAMlB,WAAW,EAAE,WAAW,EAAE,SAAS,GAAE,WAAyB;IAgCnE,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,GAAG,aAAa,GAAG,SAAS;IAoBnD,OAAO,IAAI,KAAK;IA6EhB,OAAO,CAAC,EAAE,EAAE,WAAW,EAAE,OAAO,GAAE,KAAmB,GAAG,IAAI;IAmB5D,WAAW,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI;IAIvD,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAkBvD,cAAc,IAAI,OAAO;WAelB,YAAY,CACxB,WAAW,EAAE,WAAW,EACxB,SAAS,GAAE,WAAyB,GACnC,aAAa;IAmCT,cAAc,IAAI,OAAO;IAczB,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;WAUpB,YAAY,CACxB,WAAW,EAAE,WAAW,EACxB,SAAS,GAAE,WAAyB,GACnC,aAAa;IAiCT,MAAM,IAAI,iBAAiB;WAQlB,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,iBAAiB,GAAG,aAAa;IAI3E,MAAM,CAAC,MAAM,CACX,GAAG,EAAE,IAAI,EACT,UAAU,EAAE,MAAM,EAClB,QAAQ,GAAE,MAAmB,GAC5B,aAAa;IAIP,WAAW,IAAI,YAAY;CAGrC;AAMD;;GAEG;AACH,qBAAa,YAAY;IAEd,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,MAAM;gBADZ,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM;IAGrB,GAAG,CAAC,OAAO,EAAE,QAAQ,GAAG,YAAY;IAIpC,OAAO,CAAC,GAAG,EAAE,IAAI,GAAG,aAAa,GAAG,SAAS;CAa9C;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,gBAAgB,GAAG,IAAI,CAS7E;AAgDD,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,WAAW,EAClB,EAAE,EAAE,WAAW,GAAG,SAAS,EAC3B,uBAAuB,EAAE,OAAO,GAC/B,WAAW,GAAG,SAAS,CAwBzB"}
|