@prosekit/extensions 0.7.21 → 0.7.22
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.
@@ -1319,7 +1319,14 @@ export declare function findCellPos(doc: ProseMirrorNode, pos: number): Resolved
|
|
1319
1319
|
*/
|
1320
1320
|
export declare function findCellRange(selection: Selection_2, anchorHit?: number, headHit?: number): [ResolvedPos, ResolvedPos] | undefined;
|
1321
1321
|
|
1322
|
-
|
1322
|
+
/**
|
1323
|
+
* Find the closest table node.
|
1324
|
+
*
|
1325
|
+
* @internal
|
1326
|
+
*/
|
1327
|
+
declare function findTable($pos: ResolvedPos): FindParentNodeResult | undefined;
|
1328
|
+
export { findTable }
|
1329
|
+
export { findTable as findTable_alias_1 }
|
1323
1330
|
|
1324
1331
|
export { GapCursor }
|
1325
1332
|
|
@@ -1785,12 +1792,19 @@ export declare interface PlaceholderOptions {
|
|
1785
1792
|
placeholder: string | ((state: EditorState) => string);
|
1786
1793
|
/**
|
1787
1794
|
* By default, the placeholder text will be shown whenever the current text
|
1788
|
-
* cursor is in an empty text node
|
1789
|
-
*
|
1795
|
+
* cursor is in an empty text node and it's not inside a code block or a
|
1796
|
+
* table node.
|
1797
|
+
*
|
1798
|
+
* If you only want to show the placeholder when the whole doc is empty, you
|
1799
|
+
* can set this option to 'doc'.
|
1800
|
+
*
|
1801
|
+
* You can also pass a function that receives the current editor state and
|
1802
|
+
* returns a boolean value to determine whether the placeholder should be
|
1803
|
+
* shown.
|
1790
1804
|
*
|
1791
1805
|
* @default 'block'
|
1792
1806
|
*/
|
1793
|
-
strategy?: 'doc' | 'block';
|
1807
|
+
strategy?: 'doc' | 'block' | ((state: EditorState) => boolean);
|
1794
1808
|
}
|
1795
1809
|
|
1796
1810
|
export declare const pluginKey: PluginKey<PredictionPluginState>;
|
@@ -0,0 +1,295 @@
|
|
1
|
+
// src/table/table.ts
|
2
|
+
import { union } from "@prosekit/core";
|
3
|
+
|
4
|
+
// src/table/table-commands.ts
|
5
|
+
import {
|
6
|
+
defaultBlockAt,
|
7
|
+
defineCommands,
|
8
|
+
getNodeType,
|
9
|
+
insertNode
|
10
|
+
} from "@prosekit/core";
|
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
|
61
|
+
function createEmptyTable(schema, row, col, header) {
|
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
|
+
}
|
82
|
+
}
|
83
|
+
function repeat(node, length) {
|
84
|
+
return Array(length).fill(node);
|
85
|
+
}
|
86
|
+
function insertTable(options) {
|
87
|
+
return (state, dispatch, view) => {
|
88
|
+
const { row, col, header } = options;
|
89
|
+
const table = createEmptyTable(state.schema, row, col, header);
|
90
|
+
return insertNode({ node: table })(state, dispatch, view);
|
91
|
+
};
|
92
|
+
}
|
93
|
+
var exitTable = (state, dispatch) => {
|
94
|
+
const { $head, $anchor } = state.selection;
|
95
|
+
if (!$head.sameParent($anchor)) {
|
96
|
+
return false;
|
97
|
+
}
|
98
|
+
let tableStart = -1;
|
99
|
+
let tableDepth = -1;
|
100
|
+
for (let depth = $head.depth; depth >= 0; depth--) {
|
101
|
+
const node2 = $head.node(depth);
|
102
|
+
if (node2.type.spec.tableRole === "table") {
|
103
|
+
tableStart = $head.before(depth);
|
104
|
+
tableDepth = depth;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
if (tableStart < 0 || tableDepth <= 0) {
|
108
|
+
return false;
|
109
|
+
}
|
110
|
+
const above = $head.node(tableDepth - 1);
|
111
|
+
const after = $head.indexAfter(tableDepth - 1);
|
112
|
+
const type = defaultBlockAt(above.contentMatchAt(after));
|
113
|
+
const node = type == null ? void 0 : type.createAndFill();
|
114
|
+
if (!type || !node || !above.canReplaceWith(after, after, type)) {
|
115
|
+
return false;
|
116
|
+
}
|
117
|
+
if (dispatch) {
|
118
|
+
const pos = $head.after(tableDepth);
|
119
|
+
const tr = state.tr.replaceWith(pos, pos, node);
|
120
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1));
|
121
|
+
dispatch(tr.scrollIntoView());
|
122
|
+
}
|
123
|
+
return true;
|
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
|
+
}
|
196
|
+
function defineTableCommands() {
|
197
|
+
return defineCommands({
|
198
|
+
insertTable,
|
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
|
214
|
+
});
|
215
|
+
}
|
216
|
+
|
217
|
+
// src/table/table-plugins.ts
|
218
|
+
import { definePlugin } from "@prosekit/core";
|
219
|
+
import { tableEditing, columnResizing } from "prosemirror-tables";
|
220
|
+
function defineTablePlugins() {
|
221
|
+
return definePlugin([tableEditing(), columnResizing()]);
|
222
|
+
}
|
223
|
+
|
224
|
+
// src/table/table-spec.ts
|
225
|
+
import { defineNodeSpec } from "@prosekit/core";
|
226
|
+
import { tableNodes } from "prosemirror-tables";
|
227
|
+
var cellContent = "block+";
|
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
|
+
});
|
238
|
+
function defineTableSpec() {
|
239
|
+
return defineNodeSpec({
|
240
|
+
...specs["table"],
|
241
|
+
content: "tableRow+",
|
242
|
+
name: "table"
|
243
|
+
});
|
244
|
+
}
|
245
|
+
function defineTableRowSpec() {
|
246
|
+
return defineNodeSpec({
|
247
|
+
...specs["table_row"],
|
248
|
+
content: "(tableCell | tableHeaderCell)*",
|
249
|
+
name: "tableRow"
|
250
|
+
});
|
251
|
+
}
|
252
|
+
function defineTableCellSpec() {
|
253
|
+
return defineNodeSpec({
|
254
|
+
...specs["table_cell"],
|
255
|
+
name: "tableCell",
|
256
|
+
attrs: cellAttrs
|
257
|
+
});
|
258
|
+
}
|
259
|
+
function defineTableHeaderCellSpec() {
|
260
|
+
return defineNodeSpec({
|
261
|
+
...specs["table_header"],
|
262
|
+
name: "tableHeaderCell",
|
263
|
+
attrs: cellAttrs
|
264
|
+
});
|
265
|
+
}
|
266
|
+
|
267
|
+
// src/table/table.ts
|
268
|
+
function defineTable() {
|
269
|
+
return union(
|
270
|
+
defineTableSpec(),
|
271
|
+
defineTableRowSpec(),
|
272
|
+
defineTableCellSpec(),
|
273
|
+
defineTableHeaderCellSpec(),
|
274
|
+
defineTablePlugins(),
|
275
|
+
defineTableCommands()
|
276
|
+
);
|
277
|
+
}
|
278
|
+
|
279
|
+
export {
|
280
|
+
isCellSelection,
|
281
|
+
findTable,
|
282
|
+
insertTable,
|
283
|
+
exitTable,
|
284
|
+
selectTableColumn,
|
285
|
+
selectTableRow,
|
286
|
+
selectTableCell,
|
287
|
+
selectTable,
|
288
|
+
defineTableCommands,
|
289
|
+
defineTablePlugins,
|
290
|
+
defineTableSpec,
|
291
|
+
defineTableRowSpec,
|
292
|
+
defineTableCellSpec,
|
293
|
+
defineTableHeaderCellSpec,
|
294
|
+
defineTable
|
295
|
+
};
|
@@ -1,3 +1,7 @@
|
|
1
|
+
import {
|
2
|
+
findTable
|
3
|
+
} from "./chunk-HHZL6V6B.js";
|
4
|
+
|
1
5
|
// src/placeholder/index.ts
|
2
6
|
import { definePlugin, isInCodeBlock, maybeRun } from "@prosekit/core";
|
3
7
|
import { Plugin, PluginKey } from "@prosekit/pm/state";
|
@@ -13,10 +17,8 @@ function createPlaceholderPlugin({
|
|
13
17
|
key: new PluginKey("prosekit-placeholder"),
|
14
18
|
props: {
|
15
19
|
decorations: (state) => {
|
16
|
-
|
17
|
-
|
18
|
-
}
|
19
|
-
if (isInCodeBlock(state.selection)) {
|
20
|
+
const strategyFn = typeof strategy === "function" ? strategy : strategy === "doc" ? docStrategy : defaultStrategy;
|
21
|
+
if (!strategyFn(state)) {
|
20
22
|
return null;
|
21
23
|
}
|
22
24
|
const placeholderText = maybeRun(placeholder, state);
|
@@ -29,11 +31,18 @@ function createPlaceholderPlugin({
|
|
29
31
|
}
|
30
32
|
});
|
31
33
|
}
|
34
|
+
function defaultStrategy(state) {
|
35
|
+
return !isInCodeBlock(state.selection) && !findTable(state.selection.$from);
|
36
|
+
}
|
37
|
+
function docStrategy(state) {
|
38
|
+
return isDocEmpty(state.doc) && defaultStrategy(state);
|
39
|
+
}
|
32
40
|
function isDocEmpty(doc) {
|
33
41
|
var _a;
|
34
42
|
return doc.childCount <= 1 && !((_a = doc.firstChild) == null ? void 0 : _a.content.size);
|
35
43
|
}
|
36
44
|
function createPlaceholderDecoration(state, placeholderText) {
|
45
|
+
if (!placeholderText) return null;
|
37
46
|
const { selection } = state;
|
38
47
|
if (!selection.empty) return null;
|
39
48
|
const $pos = selection.$anchor;
|
@@ -23,3 +23,4 @@ export { TableHeaderCellSpecExtension } from './_tsup-dts-rollup.js';
|
|
23
23
|
export { TableRowSpecExtension } from './_tsup-dts-rollup.js';
|
24
24
|
export { TableSpecExtension } from './_tsup-dts-rollup.js';
|
25
25
|
export { isCellSelection } from './_tsup-dts-rollup.js';
|
26
|
+
export { findTable } from './_tsup-dts-rollup.js';
|
@@ -1,280 +1,20 @@
|
|
1
|
-
// src/table/table.ts
|
2
|
-
import { union } from "@prosekit/core";
|
3
|
-
|
4
|
-
// src/table/table-commands.ts
|
5
1
|
import {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
61
|
-
function createEmptyTable(schema, row, col, header) {
|
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
|
-
}
|
82
|
-
}
|
83
|
-
function repeat(node, length) {
|
84
|
-
return Array(length).fill(node);
|
85
|
-
}
|
86
|
-
function insertTable(options) {
|
87
|
-
return (state, dispatch, view) => {
|
88
|
-
const { row, col, header } = options;
|
89
|
-
const table = createEmptyTable(state.schema, row, col, header);
|
90
|
-
return insertNode({ node: table })(state, dispatch, view);
|
91
|
-
};
|
92
|
-
}
|
93
|
-
var exitTable = (state, dispatch) => {
|
94
|
-
const { $head, $anchor } = state.selection;
|
95
|
-
if (!$head.sameParent($anchor)) {
|
96
|
-
return false;
|
97
|
-
}
|
98
|
-
let tableStart = -1;
|
99
|
-
let tableDepth = -1;
|
100
|
-
for (let depth = $head.depth; depth >= 0; depth--) {
|
101
|
-
const node2 = $head.node(depth);
|
102
|
-
if (node2.type.spec.tableRole === "table") {
|
103
|
-
tableStart = $head.before(depth);
|
104
|
-
tableDepth = depth;
|
105
|
-
}
|
106
|
-
}
|
107
|
-
if (tableStart < 0 || tableDepth <= 0) {
|
108
|
-
return false;
|
109
|
-
}
|
110
|
-
const above = $head.node(tableDepth - 1);
|
111
|
-
const after = $head.indexAfter(tableDepth - 1);
|
112
|
-
const type = defaultBlockAt(above.contentMatchAt(after));
|
113
|
-
const node = type == null ? void 0 : type.createAndFill();
|
114
|
-
if (!type || !node || !above.canReplaceWith(after, after, type)) {
|
115
|
-
return false;
|
116
|
-
}
|
117
|
-
if (dispatch) {
|
118
|
-
const pos = $head.after(tableDepth);
|
119
|
-
const tr = state.tr.replaceWith(pos, pos, node);
|
120
|
-
tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1));
|
121
|
-
dispatch(tr.scrollIntoView());
|
122
|
-
}
|
123
|
-
return true;
|
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
|
-
}
|
196
|
-
function defineTableCommands() {
|
197
|
-
return defineCommands({
|
198
|
-
insertTable,
|
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
|
214
|
-
});
|
215
|
-
}
|
216
|
-
|
217
|
-
// src/table/table-plugins.ts
|
218
|
-
import { definePlugin } from "@prosekit/core";
|
219
|
-
import { tableEditing, columnResizing } from "prosemirror-tables";
|
220
|
-
function defineTablePlugins() {
|
221
|
-
return definePlugin([tableEditing(), columnResizing()]);
|
222
|
-
}
|
223
|
-
|
224
|
-
// src/table/table-spec.ts
|
225
|
-
import { defineNodeSpec } from "@prosekit/core";
|
226
|
-
import { tableNodes } from "prosemirror-tables";
|
227
|
-
var cellContent = "block+";
|
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
|
-
});
|
238
|
-
function defineTableSpec() {
|
239
|
-
return defineNodeSpec({
|
240
|
-
...specs["table"],
|
241
|
-
content: "tableRow+",
|
242
|
-
name: "table"
|
243
|
-
});
|
244
|
-
}
|
245
|
-
function defineTableRowSpec() {
|
246
|
-
return defineNodeSpec({
|
247
|
-
...specs["table_row"],
|
248
|
-
content: "(tableCell | tableHeaderCell)*",
|
249
|
-
name: "tableRow"
|
250
|
-
});
|
251
|
-
}
|
252
|
-
function defineTableCellSpec() {
|
253
|
-
return defineNodeSpec({
|
254
|
-
...specs["table_cell"],
|
255
|
-
name: "tableCell",
|
256
|
-
attrs: cellAttrs
|
257
|
-
});
|
258
|
-
}
|
259
|
-
function defineTableHeaderCellSpec() {
|
260
|
-
return defineNodeSpec({
|
261
|
-
...specs["table_header"],
|
262
|
-
name: "tableHeaderCell",
|
263
|
-
attrs: cellAttrs
|
264
|
-
});
|
265
|
-
}
|
266
|
-
|
267
|
-
// src/table/table.ts
|
268
|
-
function defineTable() {
|
269
|
-
return union(
|
270
|
-
defineTableSpec(),
|
271
|
-
defineTableRowSpec(),
|
272
|
-
defineTableCellSpec(),
|
273
|
-
defineTableHeaderCellSpec(),
|
274
|
-
defineTablePlugins(),
|
275
|
-
defineTableCommands()
|
276
|
-
);
|
277
|
-
}
|
2
|
+
defineTable,
|
3
|
+
defineTableCellSpec,
|
4
|
+
defineTableCommands,
|
5
|
+
defineTableHeaderCellSpec,
|
6
|
+
defineTablePlugins,
|
7
|
+
defineTableRowSpec,
|
8
|
+
defineTableSpec,
|
9
|
+
exitTable,
|
10
|
+
findTable,
|
11
|
+
insertTable,
|
12
|
+
isCellSelection,
|
13
|
+
selectTable,
|
14
|
+
selectTableCell,
|
15
|
+
selectTableColumn,
|
16
|
+
selectTableRow
|
17
|
+
} from "./chunk-HHZL6V6B.js";
|
278
18
|
export {
|
279
19
|
defineTable,
|
280
20
|
defineTableCellSpec,
|
@@ -284,6 +24,7 @@ export {
|
|
284
24
|
defineTableRowSpec,
|
285
25
|
defineTableSpec,
|
286
26
|
exitTable,
|
27
|
+
findTable,
|
287
28
|
insertTable,
|
288
29
|
isCellSelection,
|
289
30
|
selectTable,
|
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.22",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -218,10 +218,10 @@
|
|
218
218
|
"prosemirror-gapcursor": "^1.3.2",
|
219
219
|
"prosemirror-highlight": "^0.9.0",
|
220
220
|
"prosemirror-search": "^1.0.0",
|
221
|
-
"prosemirror-tables": "^1.6.
|
222
|
-
"shiki": "^1.
|
223
|
-
"@prosekit/core": "^0.7.
|
224
|
-
"@prosekit/pm": "^0.1.
|
221
|
+
"prosemirror-tables": "^1.6.1",
|
222
|
+
"shiki": "^1.24.0",
|
223
|
+
"@prosekit/core": "^0.7.13",
|
224
|
+
"@prosekit/pm": "^0.1.9"
|
225
225
|
},
|
226
226
|
"peerDependencies": {
|
227
227
|
"loro-crdt": ">= 0.16.7",
|
@@ -244,15 +244,15 @@
|
|
244
244
|
}
|
245
245
|
},
|
246
246
|
"devDependencies": {
|
247
|
-
"@vitest/browser": "^2.1.
|
247
|
+
"@vitest/browser": "^2.1.6",
|
248
248
|
"just-pick": "^4.2.0",
|
249
|
-
"loro-crdt": "^1.
|
250
|
-
"loro-prosemirror": "^0.
|
249
|
+
"loro-crdt": "^1.1.4",
|
250
|
+
"loro-prosemirror": "^0.2.0",
|
251
251
|
"tsup": "^8.3.5",
|
252
252
|
"type-fest": "^4.26.1",
|
253
253
|
"typescript": "^5.6.3",
|
254
|
-
"vitest": "^2.1.
|
255
|
-
"y-prosemirror": "^1.2.
|
254
|
+
"vitest": "^2.1.6",
|
255
|
+
"y-prosemirror": "^1.2.13",
|
256
256
|
"y-protocols": "^1.0.6",
|
257
257
|
"yjs": "^13.6.20",
|
258
258
|
"@prosekit/dev": "0.0.0"
|