@kerebron/extension-tables 0.4.8 → 0.4.10
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/esm/ExtensionTables.js +7 -20
- package/esm/NodeTable.js +12 -30
- package/esm/NodeTableCell.js +2 -15
- package/esm/NodeTableHeader.js +2 -15
- package/esm/NodeTableRow.js +2 -15
- package/esm/utilities/CellSelection.js +10 -28
- package/esm/utilities/TableMap.js +8 -24
- package/esm/utilities/TableView.js +8 -36
- package/esm/utilities/columnResizing.js +4 -12
- package/package.json +5 -2
package/esm/ExtensionTables.js
CHANGED
|
@@ -4,24 +4,11 @@ import { NodeTableRow } from './NodeTableRow.js';
|
|
|
4
4
|
import { NodeTableHeader } from './NodeTableHeader.js';
|
|
5
5
|
import { NodeTableCell } from './NodeTableCell.js';
|
|
6
6
|
export class ExtensionTables extends Extension {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(this, "requires", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: [
|
|
20
|
-
new NodeTable(),
|
|
21
|
-
new NodeTableHeader(),
|
|
22
|
-
new NodeTableRow(),
|
|
23
|
-
new NodeTableCell(),
|
|
24
|
-
]
|
|
25
|
-
});
|
|
26
|
-
}
|
|
7
|
+
name = 'extension-tables';
|
|
8
|
+
requires = [
|
|
9
|
+
new NodeTable(),
|
|
10
|
+
new NodeTableHeader(),
|
|
11
|
+
new NodeTableRow(),
|
|
12
|
+
new NodeTableCell(),
|
|
13
|
+
];
|
|
27
14
|
}
|
package/esm/NodeTable.js
CHANGED
|
@@ -7,36 +7,18 @@ import { columnResizing } from './utilities/columnResizing.js';
|
|
|
7
7
|
import { tableEditing } from './utilities/tableEditing.js';
|
|
8
8
|
import { addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, deleteColumn, deleteRow, deleteTable, goToNextCell, mergeCells, setCellAttr, splitCell, toggleHeader, toggleHeaderCell, toggleHeaderColumn, toggleHeaderRow, } from './utilities/commands.js';
|
|
9
9
|
export class NodeTable extends Node {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
value: ['doc']
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(this, "attributes", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: {
|
|
29
|
-
class: {
|
|
30
|
-
default: 'table',
|
|
31
|
-
fromDom(element) {
|
|
32
|
-
return element.hasAttribute('class')
|
|
33
|
-
? element.getAttribute('class')
|
|
34
|
-
: undefined;
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
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
|
+
};
|
|
40
22
|
getNodeSpec() {
|
|
41
23
|
return {
|
|
42
24
|
content: 'table_row+',
|
package/esm/NodeTableCell.js
CHANGED
|
@@ -22,21 +22,8 @@ function setCellAttrs(node) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
export class NodeTableCell extends Node {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Object.defineProperty(this, "name", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: 'table_cell'
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(this, "requires", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true,
|
|
37
|
-
value: ['table_row']
|
|
38
|
-
});
|
|
39
|
-
}
|
|
25
|
+
name = 'table_cell';
|
|
26
|
+
requires = ['table_row'];
|
|
40
27
|
getNodeSpec() {
|
|
41
28
|
return {
|
|
42
29
|
content: 'block+',
|
package/esm/NodeTableHeader.js
CHANGED
|
@@ -22,21 +22,8 @@ function setCellAttrs(node) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
export class NodeTableHeader extends Node {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Object.defineProperty(this, "name", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: 'table_header'
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(this, "requires", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true,
|
|
37
|
-
value: ['table']
|
|
38
|
-
});
|
|
39
|
-
}
|
|
25
|
+
name = 'table_header';
|
|
26
|
+
requires = ['table'];
|
|
40
27
|
getNodeSpec() {
|
|
41
28
|
return {
|
|
42
29
|
content: 'block+',
|
package/esm/NodeTableRow.js
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
import { Node } from '@kerebron/editor';
|
|
2
2
|
export class NodeTableRow extends Node {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(this, "name", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
configurable: true,
|
|
8
|
-
writable: true,
|
|
9
|
-
value: 'table_row'
|
|
10
|
-
});
|
|
11
|
-
Object.defineProperty(this, "requires", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: ['table']
|
|
16
|
-
});
|
|
17
|
-
}
|
|
3
|
+
name = 'table_row';
|
|
4
|
+
requires = ['table'];
|
|
18
5
|
getNodeSpec() {
|
|
19
6
|
return {
|
|
20
7
|
content: '(table_cell | table_header)*',
|
|
@@ -17,6 +17,12 @@ import { inSameTable, pointsAtCell, removeColSpan } from './util.js';
|
|
|
17
17
|
* @public
|
|
18
18
|
*/
|
|
19
19
|
export class CellSelection extends Selection {
|
|
20
|
+
// A resolved position pointing _in front of_ the anchor cell (the one
|
|
21
|
+
// that doesn't move when extending the selection).
|
|
22
|
+
$anchorCell;
|
|
23
|
+
// A resolved position pointing in front of the head cell (the one
|
|
24
|
+
// moves when extending the selection).
|
|
25
|
+
$headCell;
|
|
20
26
|
// A table selection is identified by its anchor and head cells. The
|
|
21
27
|
// positions given to this constructor should point _before_ two
|
|
22
28
|
// cells in the same table. They may be the same, to select a single
|
|
@@ -42,22 +48,6 @@ export class CellSelection extends Selection {
|
|
|
42
48
|
return new SelectionRange(doc.resolve(from), doc.resolve(from + cell.content.size));
|
|
43
49
|
});
|
|
44
50
|
super(ranges[0].$from, ranges[0].$to, ranges);
|
|
45
|
-
// A resolved position pointing _in front of_ the anchor cell (the one
|
|
46
|
-
// that doesn't move when extending the selection).
|
|
47
|
-
Object.defineProperty(this, "$anchorCell", {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
configurable: true,
|
|
50
|
-
writable: true,
|
|
51
|
-
value: void 0
|
|
52
|
-
});
|
|
53
|
-
// A resolved position pointing in front of the head cell (the one
|
|
54
|
-
// moves when extending the selection).
|
|
55
|
-
Object.defineProperty(this, "$headCell", {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true,
|
|
58
|
-
writable: true,
|
|
59
|
-
value: void 0
|
|
60
|
-
});
|
|
61
51
|
this.$anchorCell = $anchorCell;
|
|
62
52
|
this.$headCell = $headCell;
|
|
63
53
|
}
|
|
@@ -273,19 +263,11 @@ Selection.jsonID('cell', CellSelection);
|
|
|
273
263
|
* @public
|
|
274
264
|
*/
|
|
275
265
|
export class CellBookmark {
|
|
266
|
+
anchor;
|
|
267
|
+
head;
|
|
276
268
|
constructor(anchor, head) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
configurable: true,
|
|
280
|
-
writable: true,
|
|
281
|
-
value: anchor
|
|
282
|
-
});
|
|
283
|
-
Object.defineProperty(this, "head", {
|
|
284
|
-
enumerable: true,
|
|
285
|
-
configurable: true,
|
|
286
|
-
writable: true,
|
|
287
|
-
value: head
|
|
288
|
-
});
|
|
269
|
+
this.anchor = anchor;
|
|
270
|
+
this.head = head;
|
|
289
271
|
}
|
|
290
272
|
map(mapping) {
|
|
291
273
|
return new CellBookmark(mapping.map(this.anchor), mapping.map(this.head));
|
|
@@ -37,6 +37,10 @@ else {
|
|
|
37
37
|
* @public
|
|
38
38
|
*/
|
|
39
39
|
export class TableMap {
|
|
40
|
+
width;
|
|
41
|
+
height;
|
|
42
|
+
map;
|
|
43
|
+
problems;
|
|
40
44
|
constructor(
|
|
41
45
|
/**
|
|
42
46
|
* The number of columns
|
|
@@ -56,30 +60,10 @@ export class TableMap {
|
|
|
56
60
|
* shape) for the table, used by the table normalizer.
|
|
57
61
|
*/
|
|
58
62
|
problems) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
value: width
|
|
64
|
-
});
|
|
65
|
-
Object.defineProperty(this, "height", {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
configurable: true,
|
|
68
|
-
writable: true,
|
|
69
|
-
value: height
|
|
70
|
-
});
|
|
71
|
-
Object.defineProperty(this, "map", {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
configurable: true,
|
|
74
|
-
writable: true,
|
|
75
|
-
value: map
|
|
76
|
-
});
|
|
77
|
-
Object.defineProperty(this, "problems", {
|
|
78
|
-
enumerable: true,
|
|
79
|
-
configurable: true,
|
|
80
|
-
writable: true,
|
|
81
|
-
value: problems
|
|
82
|
-
});
|
|
63
|
+
this.width = width;
|
|
64
|
+
this.height = height;
|
|
65
|
+
this.map = map;
|
|
66
|
+
this.problems = problems;
|
|
83
67
|
}
|
|
84
68
|
// Find the dimensions of the cell at the given position.
|
|
85
69
|
findCell(pos) {
|
|
@@ -2,43 +2,15 @@
|
|
|
2
2
|
* @public
|
|
3
3
|
*/
|
|
4
4
|
export class TableView {
|
|
5
|
+
node;
|
|
6
|
+
defaultCellMinWidth;
|
|
7
|
+
dom;
|
|
8
|
+
table;
|
|
9
|
+
colgroup;
|
|
10
|
+
contentDOM;
|
|
5
11
|
constructor(node, defaultCellMinWidth) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
configurable: true,
|
|
9
|
-
writable: true,
|
|
10
|
-
value: node
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(this, "defaultCellMinWidth", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: defaultCellMinWidth
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(this, "dom", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: void 0
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(this, "table", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: void 0
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(this, "colgroup", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: void 0
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(this, "contentDOM", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true,
|
|
40
|
-
value: void 0
|
|
41
|
-
});
|
|
12
|
+
this.node = node;
|
|
13
|
+
this.defaultCellMinWidth = defaultCellMinWidth;
|
|
42
14
|
this.dom = document.createElement('div');
|
|
43
15
|
this.dom.className = 'tableWrapper';
|
|
44
16
|
this.table = this.dom.appendChild(document.createElement('table'));
|
|
@@ -63,19 +63,11 @@ export function columnResizing({ handleWidth = 5, cellMinWidth = 25, defaultCell
|
|
|
63
63
|
* @public
|
|
64
64
|
*/
|
|
65
65
|
export class ResizeState {
|
|
66
|
+
activeHandle;
|
|
67
|
+
dragging;
|
|
66
68
|
constructor(activeHandle, dragging) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
configurable: true,
|
|
70
|
-
writable: true,
|
|
71
|
-
value: activeHandle
|
|
72
|
-
});
|
|
73
|
-
Object.defineProperty(this, "dragging", {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
configurable: true,
|
|
76
|
-
writable: true,
|
|
77
|
-
value: dragging
|
|
78
|
-
});
|
|
69
|
+
this.activeHandle = activeHandle;
|
|
70
|
+
this.dragging = dragging;
|
|
79
71
|
}
|
|
80
72
|
apply(tr) {
|
|
81
73
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kerebron/extension-tables",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"module": "./esm/ExtensionTables.js",
|
|
6
6
|
"exports": {
|
|
@@ -18,11 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"./NodeTableCell": {
|
|
20
20
|
"import": "./esm/NodeTableCell.js"
|
|
21
|
+
},
|
|
22
|
+
"./assets/*.css": {
|
|
23
|
+
"import": "./assets/*.css"
|
|
21
24
|
}
|
|
22
25
|
},
|
|
23
26
|
"scripts": {},
|
|
24
27
|
"dependencies": {
|
|
25
|
-
"@kerebron/editor": "0.4.
|
|
28
|
+
"@kerebron/editor": "0.4.10",
|
|
26
29
|
"prosemirror-model": "1.25.3",
|
|
27
30
|
"prosemirror-state": "1.4.3",
|
|
28
31
|
"prosemirror-transform": "1.10.4",
|