@prosekit/extensions 0.7.12 → 0.7.14
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.
@@ -8,6 +8,7 @@ import { bundledLanguagesInfo } from 'shiki';
|
|
8
8
|
import { BundledTheme } from 'shiki';
|
9
9
|
import { BundledThemeInfo } from 'shiki';
|
10
10
|
import { bundledThemesInfo } from 'shiki';
|
11
|
+
import { CellSelection } from 'prosemirror-tables';
|
11
12
|
import { Command } from '@prosekit/pm/state';
|
12
13
|
import { CursorAwareness } from 'loro-prosemirror';
|
13
14
|
import type { DecorationAttrs } from '@prosekit/pm/view';
|
@@ -19,6 +20,7 @@ import { Extension } from '@prosekit/core';
|
|
19
20
|
import { ExtensionTyping } from '@prosekit/core';
|
20
21
|
import { ExtractMarkActions } from '@prosekit/core';
|
21
22
|
import { ExtractNodeActions } from '@prosekit/core';
|
23
|
+
import { FindParentNodeResult } from '@prosekit/core';
|
22
24
|
import { GapCursor } from 'prosemirror-gapcursor';
|
23
25
|
import { getSingletonHighlighter } from 'shiki/bundle/full';
|
24
26
|
import type { Highlighter } from 'shiki';
|
@@ -44,6 +46,7 @@ import { PlainExtension } from '@prosekit/core';
|
|
44
46
|
import { Plugin as Plugin_2 } from '@prosekit/pm/state';
|
45
47
|
import { PluginKey } from '@prosekit/pm/state';
|
46
48
|
import { ProseMirrorNode } from '@prosekit/pm/model';
|
49
|
+
import type { ResolvedPos } from '@prosekit/pm/model';
|
47
50
|
import type { Selection as Selection_2 } from '@prosekit/pm/state';
|
48
51
|
import { SimplifyDeeper } from '@prosekit/core';
|
49
52
|
import type { SpecialLanguage } from 'shiki';
|
@@ -811,7 +814,9 @@ export declare function defineStrikeSpec(): StrikeSpecExtension;
|
|
811
814
|
/**
|
812
815
|
* @public
|
813
816
|
*/
|
814
|
-
|
817
|
+
declare function defineTable(): TableExtension;
|
818
|
+
export { defineTable }
|
819
|
+
export { defineTable as defineTable_alias_1 }
|
815
820
|
|
816
821
|
/**
|
817
822
|
* @internal
|
@@ -1086,7 +1091,27 @@ export declare type EnterRuleOptions = {
|
|
1086
1091
|
*
|
1087
1092
|
* @public
|
1088
1093
|
*/
|
1089
|
-
|
1094
|
+
declare const exitTable: Command;
|
1095
|
+
export { exitTable }
|
1096
|
+
export { exitTable as exitTable_alias_1 }
|
1097
|
+
|
1098
|
+
/**
|
1099
|
+
* Try to find a resolved pos of a cell by using the given pos as a hit point.
|
1100
|
+
*
|
1101
|
+
* @internal
|
1102
|
+
*/
|
1103
|
+
export declare function findCellPos(doc: ProseMirrorNode, pos: number): ResolvedPos | undefined;
|
1104
|
+
|
1105
|
+
/**
|
1106
|
+
* Try to find the anchor and head cell in the same table by using the given
|
1107
|
+
* anchor and head as hit points, or fallback to the selection's anchor and
|
1108
|
+
* head.
|
1109
|
+
*
|
1110
|
+
* @internal
|
1111
|
+
*/
|
1112
|
+
export declare function findCellRange(selection: Selection_2, anchorHit?: number, headHit?: number): [ResolvedPos, ResolvedPos] | undefined;
|
1113
|
+
|
1114
|
+
export declare function findTable($pos: ResolvedPos): FindParentNodeResult | undefined;
|
1090
1115
|
|
1091
1116
|
export { GapCursor }
|
1092
1117
|
|
@@ -1196,22 +1221,39 @@ export declare type ImageSpecExtension = Extension<{
|
|
1196
1221
|
|
1197
1222
|
export { IndentListOptions }
|
1198
1223
|
|
1224
|
+
export declare function inputText(input: string): Promise<void>;
|
1225
|
+
|
1199
1226
|
/**
|
1200
1227
|
* Insert a table node with the given number of rows and columns, and optionally
|
1201
1228
|
* a header row.
|
1202
1229
|
*
|
1230
|
+
* @param options
|
1231
|
+
*
|
1203
1232
|
* @public
|
1204
1233
|
*/
|
1205
|
-
|
1234
|
+
declare function insertTable(options: InsertTableOptions): Command;
|
1235
|
+
export { insertTable }
|
1236
|
+
export { insertTable as insertTable_alias_1 }
|
1206
1237
|
|
1207
1238
|
/**
|
1208
1239
|
* @public
|
1209
1240
|
*/
|
1210
|
-
|
1241
|
+
declare interface InsertTableOptions {
|
1211
1242
|
row: number;
|
1212
1243
|
col: number;
|
1213
1244
|
header: boolean;
|
1214
1245
|
}
|
1246
|
+
export { InsertTableOptions }
|
1247
|
+
export { InsertTableOptions as InsertTableOptions_alias_1 }
|
1248
|
+
|
1249
|
+
/**
|
1250
|
+
* Checks if the given object is a `CellSelection` instance.
|
1251
|
+
*
|
1252
|
+
* @public
|
1253
|
+
*/
|
1254
|
+
declare function isCellSelection(value: unknown): value is CellSelection;
|
1255
|
+
export { isCellSelection }
|
1256
|
+
export { isCellSelection as isCellSelection_alias_1 }
|
1215
1257
|
|
1216
1258
|
/**
|
1217
1259
|
* @internal
|
@@ -1551,6 +1593,96 @@ export declare interface SearchQueryOptions {
|
|
1551
1593
|
wholeWord?: boolean;
|
1552
1594
|
}
|
1553
1595
|
|
1596
|
+
/**
|
1597
|
+
* @public
|
1598
|
+
*/
|
1599
|
+
declare function selectTable(options?: SelectTableOptions): Command;
|
1600
|
+
export { selectTable }
|
1601
|
+
export { selectTable as selectTable_alias_1 }
|
1602
|
+
|
1603
|
+
/**
|
1604
|
+
* @public
|
1605
|
+
*/
|
1606
|
+
declare function selectTableCell(options?: SelectTableCellOptions): Command;
|
1607
|
+
export { selectTableCell }
|
1608
|
+
export { selectTableCell as selectTableCell_alias_1 }
|
1609
|
+
|
1610
|
+
/**
|
1611
|
+
* @public
|
1612
|
+
*/
|
1613
|
+
declare interface SelectTableCellOptions {
|
1614
|
+
/**
|
1615
|
+
* A hit position of the table cell to select from. By default, the selection
|
1616
|
+
* anchor will be used.
|
1617
|
+
*/
|
1618
|
+
pos?: number;
|
1619
|
+
}
|
1620
|
+
export { SelectTableCellOptions }
|
1621
|
+
export { SelectTableCellOptions as SelectTableCellOptions_alias_1 }
|
1622
|
+
|
1623
|
+
/**
|
1624
|
+
* @public
|
1625
|
+
*/
|
1626
|
+
declare function selectTableColumn(options?: SelectTableColumnOptions): Command;
|
1627
|
+
export { selectTableColumn }
|
1628
|
+
export { selectTableColumn as selectTableColumn_alias_1 }
|
1629
|
+
|
1630
|
+
/**
|
1631
|
+
* @public
|
1632
|
+
*/
|
1633
|
+
declare interface SelectTableColumnOptions {
|
1634
|
+
/**
|
1635
|
+
* A hit position of the table cell to select from. By default, the selection
|
1636
|
+
* anchor will be used.
|
1637
|
+
*/
|
1638
|
+
anchor?: number;
|
1639
|
+
/**
|
1640
|
+
* A hit position of the table cell to select to. By default, the selection
|
1641
|
+
* head will be used.
|
1642
|
+
*/
|
1643
|
+
head?: number;
|
1644
|
+
}
|
1645
|
+
export { SelectTableColumnOptions }
|
1646
|
+
export { SelectTableColumnOptions as SelectTableColumnOptions_alias_1 }
|
1647
|
+
|
1648
|
+
/**
|
1649
|
+
* @public
|
1650
|
+
*/
|
1651
|
+
declare interface SelectTableOptions {
|
1652
|
+
/**
|
1653
|
+
* A hit position of the table to select from. By default, the selection
|
1654
|
+
* anchor will be used.
|
1655
|
+
*/
|
1656
|
+
pos?: number;
|
1657
|
+
}
|
1658
|
+
export { SelectTableOptions }
|
1659
|
+
export { SelectTableOptions as SelectTableOptions_alias_1 }
|
1660
|
+
|
1661
|
+
/**
|
1662
|
+
* @public
|
1663
|
+
*/
|
1664
|
+
declare function selectTableRow(options?: SelectTableRowOptions): Command;
|
1665
|
+
export { selectTableRow }
|
1666
|
+
export { selectTableRow as selectTableRow_alias_1 }
|
1667
|
+
|
1668
|
+
/**
|
1669
|
+
* @public
|
1670
|
+
*/
|
1671
|
+
declare interface SelectTableRowOptions {
|
1672
|
+
/**
|
1673
|
+
* A hit position of the table cell to select from. By default, the selection
|
1674
|
+
* anchor will be used.
|
1675
|
+
*/
|
1676
|
+
anchor?: number;
|
1677
|
+
/**
|
1678
|
+
* A hit position of the table cell to select to. By default, the selection
|
1679
|
+
* head will be used.
|
1680
|
+
*/
|
1681
|
+
head?: number;
|
1682
|
+
}
|
1683
|
+
export { SelectTableRowOptions }
|
1684
|
+
export { SelectTableRowOptions as SelectTableRowOptions_alias_1 }
|
1685
|
+
|
1554
1686
|
/**
|
1555
1687
|
* @internal
|
1556
1688
|
*/
|
@@ -1702,6 +1834,20 @@ declare type TableCommandsExtension = Extension<{
|
|
1702
1834
|
Commands: {
|
1703
1835
|
insertTable: [InsertTableOptions];
|
1704
1836
|
exitTable: [];
|
1837
|
+
selectTable: [options?: SelectTableOptions];
|
1838
|
+
selectTableCell: [options?: SelectTableCellOptions];
|
1839
|
+
selectTableColumn: [options?: SelectTableColumnOptions];
|
1840
|
+
selectTableRow: [options?: SelectTableRowOptions];
|
1841
|
+
addTableColumnBefore: [];
|
1842
|
+
addTableColumnAfter: [];
|
1843
|
+
addTableRowAbove: [];
|
1844
|
+
addTableRowBelow: [];
|
1845
|
+
deleteTable: [];
|
1846
|
+
deleteTableColumn: [];
|
1847
|
+
deleteTableRow: [];
|
1848
|
+
deleteCellSelection: [];
|
1849
|
+
mergeTableCells: [];
|
1850
|
+
splitTableCell: [];
|
1705
1851
|
};
|
1706
1852
|
}>;
|
1707
1853
|
export { TableCommandsExtension }
|
@@ -1710,13 +1856,15 @@ export { TableCommandsExtension as TableCommandsExtension_alias_1 }
|
|
1710
1856
|
/**
|
1711
1857
|
* @internal
|
1712
1858
|
*/
|
1713
|
-
|
1859
|
+
declare type TableExtension = Union<[
|
1714
1860
|
TableSpecExtension,
|
1715
1861
|
TableRowSpecExtension,
|
1716
1862
|
TableCellSpecExtension,
|
1717
1863
|
TableHeaderCellSpecExtension,
|
1718
1864
|
TableCommandsExtension
|
1719
1865
|
]>;
|
1866
|
+
export { TableExtension }
|
1867
|
+
export { TableExtension as TableExtension_alias_1 }
|
1720
1868
|
|
1721
1869
|
/**
|
1722
1870
|
* @internal
|
@@ -1,13 +1,25 @@
|
|
1
1
|
export { defineTable } from './_tsup-dts-rollup';
|
2
2
|
export { TableExtension } from './_tsup-dts-rollup';
|
3
|
-
export { defineTableCellSpec } from './_tsup-dts-rollup';
|
4
3
|
export { defineTableCommands } from './_tsup-dts-rollup';
|
5
|
-
export {
|
4
|
+
export { exitTable } from './_tsup-dts-rollup';
|
5
|
+
export { insertTable } from './_tsup-dts-rollup';
|
6
|
+
export { selectTable } from './_tsup-dts-rollup';
|
7
|
+
export { selectTableCell } from './_tsup-dts-rollup';
|
8
|
+
export { selectTableColumn } from './_tsup-dts-rollup';
|
9
|
+
export { selectTableRow } from './_tsup-dts-rollup';
|
10
|
+
export { InsertTableOptions } from './_tsup-dts-rollup';
|
11
|
+
export { SelectTableCellOptions } from './_tsup-dts-rollup';
|
12
|
+
export { SelectTableColumnOptions } from './_tsup-dts-rollup';
|
13
|
+
export { SelectTableOptions } from './_tsup-dts-rollup';
|
14
|
+
export { SelectTableRowOptions } from './_tsup-dts-rollup';
|
15
|
+
export { TableCommandsExtension } from './_tsup-dts-rollup';
|
6
16
|
export { defineTablePlugins } from './_tsup-dts-rollup';
|
17
|
+
export { defineTableCellSpec } from './_tsup-dts-rollup';
|
18
|
+
export { defineTableHeaderCellSpec } from './_tsup-dts-rollup';
|
7
19
|
export { defineTableRowSpec } from './_tsup-dts-rollup';
|
8
20
|
export { defineTableSpec } from './_tsup-dts-rollup';
|
9
21
|
export { TableCellSpecExtension } from './_tsup-dts-rollup';
|
10
|
-
export { TableCommandsExtension } from './_tsup-dts-rollup';
|
11
22
|
export { TableHeaderCellSpecExtension } from './_tsup-dts-rollup';
|
12
23
|
export { TableRowSpecExtension } from './_tsup-dts-rollup';
|
13
24
|
export { TableSpecExtension } from './_tsup-dts-rollup';
|
25
|
+
export { isCellSelection } from './_tsup-dts-rollup';
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// src/table/
|
1
|
+
// src/table/table.ts
|
2
2
|
import { union } from "@prosekit/core";
|
3
3
|
|
4
4
|
// src/table/table-commands.ts
|
@@ -9,31 +9,83 @@ import {
|
|
9
9
|
insertNode
|
10
10
|
} from "@prosekit/core";
|
11
11
|
import { TextSelection } from "@prosekit/pm/state";
|
12
|
+
import {
|
13
|
+
addColumnAfter,
|
14
|
+
addColumnBefore,
|
15
|
+
addRowAfter,
|
16
|
+
addRowBefore,
|
17
|
+
CellSelection as CellSelection2,
|
18
|
+
deleteCellSelection,
|
19
|
+
deleteColumn,
|
20
|
+
deleteRow,
|
21
|
+
deleteTable,
|
22
|
+
mergeCells,
|
23
|
+
splitCell,
|
24
|
+
TableMap
|
25
|
+
} from "prosemirror-tables";
|
26
|
+
|
27
|
+
// src/table/table-utils.ts
|
28
|
+
import { findParentNode } from "@prosekit/core";
|
29
|
+
import {
|
30
|
+
cellAround,
|
31
|
+
cellNear,
|
32
|
+
CellSelection,
|
33
|
+
inSameTable
|
34
|
+
} from "prosemirror-tables";
|
35
|
+
function isCellSelection(value) {
|
36
|
+
return value instanceof CellSelection;
|
37
|
+
}
|
38
|
+
function findTable($pos) {
|
39
|
+
return findParentNode((node) => node.type.spec.tableRole === "table", $pos);
|
40
|
+
}
|
41
|
+
function findCellRange(selection, anchorHit, headHit) {
|
42
|
+
var _a, _b;
|
43
|
+
if (anchorHit == null && headHit == null && isCellSelection(selection)) {
|
44
|
+
return [selection.$anchorCell, selection.$headCell];
|
45
|
+
}
|
46
|
+
const anchor = (_a = anchorHit != null ? anchorHit : headHit) != null ? _a : selection.anchor;
|
47
|
+
const head = (_b = headHit != null ? headHit : anchorHit) != null ? _b : selection.head;
|
48
|
+
const doc = selection.$head.doc;
|
49
|
+
const $anchorCell = findCellPos(doc, anchor);
|
50
|
+
const $headCell = findCellPos(doc, head);
|
51
|
+
if ($anchorCell && $headCell && inSameTable($anchorCell, $headCell)) {
|
52
|
+
return [$anchorCell, $headCell];
|
53
|
+
}
|
54
|
+
}
|
55
|
+
function findCellPos(doc, pos) {
|
56
|
+
const $pos = doc.resolve(pos);
|
57
|
+
return cellAround($pos) || cellNear($pos);
|
58
|
+
}
|
59
|
+
|
60
|
+
// src/table/table-commands.ts
|
12
61
|
function createEmptyTable(schema, row, col, header) {
|
13
|
-
const
|
14
|
-
const
|
15
|
-
const
|
16
|
-
const
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
);
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
);
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
return table.createAndFill(null, rows);
|
62
|
+
const tableType = getNodeType(schema, "table");
|
63
|
+
const tableRowType = getNodeType(schema, "tableRow");
|
64
|
+
const tableCellType = getNodeType(schema, "tableCell");
|
65
|
+
const tableHeaderCellType = getNodeType(schema, "tableHeaderCell");
|
66
|
+
if (header) {
|
67
|
+
const headerCell = tableHeaderCellType.createAndFill();
|
68
|
+
const headerCells = repeat(headerCell, col);
|
69
|
+
const headerRow = tableRowType.createAndFill(null, headerCells);
|
70
|
+
const bodyCell = tableCellType.createAndFill();
|
71
|
+
const bodyCells = repeat(bodyCell, col);
|
72
|
+
const bodyRow = tableRowType.createAndFill(null, bodyCells);
|
73
|
+
const bodyRows = repeat(bodyRow, row - 1);
|
74
|
+
return tableType.createAndFill(null, [headerRow, ...bodyRows]);
|
75
|
+
} else {
|
76
|
+
const bodyCell = tableCellType.createAndFill();
|
77
|
+
const bodyCells = repeat(bodyCell, col);
|
78
|
+
const bodyRow = tableRowType.createAndFill(null, bodyCells);
|
79
|
+
const bodyRows = repeat(bodyRow, row);
|
80
|
+
return tableType.createAndFill(null, bodyRows);
|
81
|
+
}
|
34
82
|
}
|
35
|
-
function
|
83
|
+
function repeat(node, length) {
|
84
|
+
return Array(length).fill(node);
|
85
|
+
}
|
86
|
+
function insertTable(options) {
|
36
87
|
return (state, dispatch, view) => {
|
88
|
+
const { row, col, header } = options;
|
37
89
|
const table = createEmptyTable(state.schema, row, col, header);
|
38
90
|
return insertNode({ node: table })(state, dispatch, view);
|
39
91
|
};
|
@@ -70,10 +122,95 @@ var exitTable = (state, dispatch) => {
|
|
70
122
|
}
|
71
123
|
return true;
|
72
124
|
};
|
125
|
+
function selectTableColumn(options) {
|
126
|
+
return (state, dispatch) => {
|
127
|
+
const range = findCellRange(state.selection, options == null ? void 0 : options.anchor, options == null ? void 0 : options.head);
|
128
|
+
if (!range) {
|
129
|
+
return false;
|
130
|
+
}
|
131
|
+
if (dispatch) {
|
132
|
+
const [$anchorCell, $headCell] = range;
|
133
|
+
const selection = CellSelection2.colSelection($anchorCell, $headCell);
|
134
|
+
dispatch(state.tr.setSelection(selection));
|
135
|
+
}
|
136
|
+
return true;
|
137
|
+
};
|
138
|
+
}
|
139
|
+
function selectTableRow(options) {
|
140
|
+
return (state, dispatch) => {
|
141
|
+
const range = findCellRange(state.selection, options == null ? void 0 : options.anchor, options == null ? void 0 : options.head);
|
142
|
+
if (!range) {
|
143
|
+
return false;
|
144
|
+
}
|
145
|
+
if (dispatch) {
|
146
|
+
const [$anchorCell, $headCell] = range;
|
147
|
+
const selection = CellSelection2.rowSelection($anchorCell, $headCell);
|
148
|
+
dispatch(state.tr.setSelection(selection));
|
149
|
+
}
|
150
|
+
return true;
|
151
|
+
};
|
152
|
+
}
|
153
|
+
function selectTableCell(options) {
|
154
|
+
return (state, dispatch) => {
|
155
|
+
var _a;
|
156
|
+
const $cellPos = findCellPos(
|
157
|
+
state.doc,
|
158
|
+
(_a = options == null ? void 0 : options.pos) != null ? _a : state.selection.anchor
|
159
|
+
);
|
160
|
+
if (!$cellPos) {
|
161
|
+
return false;
|
162
|
+
}
|
163
|
+
if (dispatch) {
|
164
|
+
const selection = new CellSelection2($cellPos);
|
165
|
+
dispatch(state.tr.setSelection(selection));
|
166
|
+
}
|
167
|
+
return true;
|
168
|
+
};
|
169
|
+
}
|
170
|
+
function selectTable(options) {
|
171
|
+
return (state, dispatch) => {
|
172
|
+
const $pos = (options == null ? void 0 : options.pos) ? state.doc.resolve(options.pos) : state.selection.$anchor;
|
173
|
+
const table = findTable($pos);
|
174
|
+
if (!table) {
|
175
|
+
return false;
|
176
|
+
}
|
177
|
+
const map = TableMap.get(table.node);
|
178
|
+
if (map.map.length === 0) {
|
179
|
+
return false;
|
180
|
+
}
|
181
|
+
if (dispatch) {
|
182
|
+
let tr = state.tr;
|
183
|
+
const firstCellPosInTable = map.map[0];
|
184
|
+
const lastCellPosInTable = map.map[map.map.length - 1];
|
185
|
+
const firstCellPos = table.pos + firstCellPosInTable + 1;
|
186
|
+
const lastCellPos = table.pos + lastCellPosInTable + 1;
|
187
|
+
const $firstCellPos = tr.doc.resolve(firstCellPos);
|
188
|
+
const $lastCellPos = tr.doc.resolve(lastCellPos);
|
189
|
+
const selection = new CellSelection2($firstCellPos, $lastCellPos);
|
190
|
+
tr = tr.setSelection(selection);
|
191
|
+
dispatch == null ? void 0 : dispatch(tr);
|
192
|
+
}
|
193
|
+
return true;
|
194
|
+
};
|
195
|
+
}
|
73
196
|
function defineTableCommands() {
|
74
197
|
return defineCommands({
|
75
198
|
insertTable,
|
76
|
-
exitTable: () => exitTable
|
199
|
+
exitTable: () => exitTable,
|
200
|
+
selectTable,
|
201
|
+
selectTableCell,
|
202
|
+
selectTableColumn,
|
203
|
+
selectTableRow,
|
204
|
+
addTableColumnBefore: () => addColumnBefore,
|
205
|
+
addTableColumnAfter: () => addColumnAfter,
|
206
|
+
addTableRowAbove: () => addRowBefore,
|
207
|
+
addTableRowBelow: () => addRowAfter,
|
208
|
+
deleteTable: () => deleteTable,
|
209
|
+
deleteTableColumn: () => deleteColumn,
|
210
|
+
deleteTableRow: () => deleteRow,
|
211
|
+
deleteCellSelection: () => deleteCellSelection,
|
212
|
+
mergeTableCells: () => mergeCells,
|
213
|
+
splitTableCell: () => splitCell
|
77
214
|
});
|
78
215
|
}
|
79
216
|
|
@@ -86,91 +223,48 @@ function defineTablePlugins() {
|
|
86
223
|
|
87
224
|
// src/table/table-spec.ts
|
88
225
|
import { defineNodeSpec } from "@prosekit/core";
|
226
|
+
import { tableNodes } from "prosemirror-tables";
|
89
227
|
var cellContent = "block+";
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
colwidth: widths && widths.length == colspan ? widths : null
|
101
|
-
};
|
102
|
-
}
|
103
|
-
function setCellAttrs(node) {
|
104
|
-
const pmAttrs = node.attrs;
|
105
|
-
const domAttrs = {};
|
106
|
-
if (pmAttrs.colspan !== 1) {
|
107
|
-
domAttrs.colspan = pmAttrs.colspan;
|
108
|
-
}
|
109
|
-
if (pmAttrs.rowspan !== 1) {
|
110
|
-
domAttrs.rowspan = pmAttrs.rowspan;
|
111
|
-
}
|
112
|
-
if (pmAttrs.colwidth) {
|
113
|
-
domAttrs["data-colwidth"] = pmAttrs.colwidth.join(",");
|
114
|
-
}
|
115
|
-
return domAttrs;
|
116
|
-
}
|
228
|
+
var cellAttrs = {
|
229
|
+
colspan: { default: 1 },
|
230
|
+
rowspan: { default: 1 },
|
231
|
+
colwidth: { default: null }
|
232
|
+
};
|
233
|
+
var specs = tableNodes({
|
234
|
+
tableGroup: "block",
|
235
|
+
cellContent,
|
236
|
+
cellAttributes: {}
|
237
|
+
});
|
117
238
|
function defineTableSpec() {
|
118
239
|
return defineNodeSpec({
|
119
|
-
|
120
|
-
tableRole: "table",
|
240
|
+
...specs["table"],
|
121
241
|
content: "tableRow+",
|
122
|
-
|
123
|
-
group: "block",
|
124
|
-
parseDOM: [{ tag: "table" }],
|
125
|
-
toDOM() {
|
126
|
-
return ["table", ["tbody", 0]];
|
127
|
-
}
|
242
|
+
name: "table"
|
128
243
|
});
|
129
244
|
}
|
130
245
|
function defineTableRowSpec() {
|
131
246
|
return defineNodeSpec({
|
132
|
-
|
133
|
-
tableRole: "row",
|
247
|
+
...specs["table_row"],
|
134
248
|
content: "(tableCell | tableHeaderCell)*",
|
135
|
-
|
136
|
-
toDOM() {
|
137
|
-
return ["tr", 0];
|
138
|
-
}
|
249
|
+
name: "tableRow"
|
139
250
|
});
|
140
251
|
}
|
141
|
-
var cellAttrs = {
|
142
|
-
colspan: { default: 1 },
|
143
|
-
rowspan: { default: 1 },
|
144
|
-
colwidth: { default: null }
|
145
|
-
};
|
146
252
|
function defineTableCellSpec() {
|
147
253
|
return defineNodeSpec({
|
254
|
+
...specs["table_cell"],
|
148
255
|
name: "tableCell",
|
149
|
-
|
150
|
-
content: cellContent,
|
151
|
-
attrs: cellAttrs,
|
152
|
-
isolating: true,
|
153
|
-
parseDOM: [{ tag: "td", getAttrs: (dom) => getCellAttrs(dom) }],
|
154
|
-
toDOM(node) {
|
155
|
-
return ["td", setCellAttrs(node), 0];
|
156
|
-
}
|
256
|
+
attrs: cellAttrs
|
157
257
|
});
|
158
258
|
}
|
159
259
|
function defineTableHeaderCellSpec() {
|
160
260
|
return defineNodeSpec({
|
261
|
+
...specs["table_header"],
|
161
262
|
name: "tableHeaderCell",
|
162
|
-
|
163
|
-
content: cellContent,
|
164
|
-
attrs: cellAttrs,
|
165
|
-
isolating: true,
|
166
|
-
parseDOM: [{ tag: "th", getAttrs: (dom) => getCellAttrs(dom) }],
|
167
|
-
toDOM(node) {
|
168
|
-
return ["th", setCellAttrs(node), 0];
|
169
|
-
}
|
263
|
+
attrs: cellAttrs
|
170
264
|
});
|
171
265
|
}
|
172
266
|
|
173
|
-
// src/table/
|
267
|
+
// src/table/table.ts
|
174
268
|
function defineTable() {
|
175
269
|
return union(
|
176
270
|
defineTableSpec(),
|
@@ -188,5 +282,12 @@ export {
|
|
188
282
|
defineTableHeaderCellSpec,
|
189
283
|
defineTablePlugins,
|
190
284
|
defineTableRowSpec,
|
191
|
-
defineTableSpec
|
285
|
+
defineTableSpec,
|
286
|
+
exitTable,
|
287
|
+
insertTable,
|
288
|
+
isCellSelection,
|
289
|
+
selectTable,
|
290
|
+
selectTableCell,
|
291
|
+
selectTableColumn,
|
292
|
+
selectTableRow
|
192
293
|
};
|
package/dist/table/style.css
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/extensions",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.7.
|
4
|
+
"version": "0.7.14",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -208,9 +208,9 @@
|
|
208
208
|
"prosemirror-gapcursor": "^1.3.2",
|
209
209
|
"prosemirror-highlight": "^0.8.0",
|
210
210
|
"prosemirror-search": "^1.0.0",
|
211
|
-
"prosemirror-tables": "^1.
|
211
|
+
"prosemirror-tables": "^1.5.0",
|
212
212
|
"shiki": "^1.14.1",
|
213
|
-
"@prosekit/core": "^0.7.
|
213
|
+
"@prosekit/core": "^0.7.10",
|
214
214
|
"@prosekit/pm": "^0.1.8"
|
215
215
|
},
|
216
216
|
"peerDependencies": {
|
@@ -235,6 +235,7 @@
|
|
235
235
|
},
|
236
236
|
"devDependencies": {
|
237
237
|
"@vitest/browser": "^2.0.5",
|
238
|
+
"just-pick": "^4.2.0",
|
238
239
|
"loro-crdt": "^0.16.7",
|
239
240
|
"loro-prosemirror": "^0.0.7",
|
240
241
|
"tsup": "^8.2.4",
|