@prosekit/extensions 0.7.24 → 0.9.0
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/dist/commit/style.css +2 -1
- package/dist/commit/style.js +0 -0
- package/dist/enter-rule-RdhEA900.js +96 -0
- package/dist/gap-cursor/style.css +8 -5
- package/dist/gap-cursor/style.js +0 -0
- package/dist/input-rule-Gji4N7Oe.js +93 -0
- package/dist/list/style.css +7 -7
- package/dist/list/style.js +0 -0
- package/dist/loro/style.css +21 -17
- package/dist/loro/style.js +0 -0
- package/dist/mark-rule-wEOcDt6i.js +160 -0
- package/dist/placeholder/style.css +5 -5
- package/dist/placeholder/style.js +0 -0
- package/dist/prosekit-extensions-autocomplete.d.ts +33 -3
- package/dist/prosekit-extensions-autocomplete.js +122 -174
- package/dist/prosekit-extensions-blockquote.d.ts +51 -8
- package/dist/prosekit-extensions-blockquote.js +64 -78
- package/dist/prosekit-extensions-bold.d.ts +61 -8
- package/dist/prosekit-extensions-bold.js +61 -73
- package/dist/prosekit-extensions-code-block.d.ts +172 -20
- package/dist/prosekit-extensions-code-block.js +201 -184
- package/dist/prosekit-extensions-code.d.ts +61 -8
- package/dist/prosekit-extensions-code.js +44 -55
- package/dist/prosekit-extensions-commit.d.ts +53 -4
- package/dist/prosekit-extensions-commit.js +142 -183
- package/dist/prosekit-extensions-doc.d.ts +22 -0
- package/dist/prosekit-extensions-doc.js +16 -0
- package/dist/prosekit-extensions-drop-cursor.d.ts +34 -3
- package/dist/prosekit-extensions-drop-cursor.js +14 -8
- package/dist/prosekit-extensions-enter-rule.d.ts +106 -5
- package/dist/prosekit-extensions-enter-rule.js +3 -8
- package/dist/prosekit-extensions-file.d.ts +126 -8
- package/dist/prosekit-extensions-file.js +111 -132
- package/dist/prosekit-extensions-gap-cursor.d.ts +29 -2
- package/dist/prosekit-extensions-gap-cursor.js +21 -9
- package/dist/prosekit-extensions-hard-break.d.ts +58 -0
- package/dist/prosekit-extensions-hard-break.js +58 -0
- package/dist/prosekit-extensions-heading.d.ts +69 -9
- package/dist/prosekit-extensions-heading.js +121 -95
- package/dist/prosekit-extensions-horizontal-rule.d.ts +41 -8
- package/dist/prosekit-extensions-horizontal-rule.js +53 -71
- package/dist/prosekit-extensions-image.d.ts +53 -7
- package/dist/prosekit-extensions-image.js +71 -62
- package/dist/prosekit-extensions-input-rule.d.ts +134 -6
- package/dist/prosekit-extensions-input-rule.js +3 -14
- package/dist/prosekit-extensions-italic.d.ts +61 -8
- package/dist/prosekit-extensions-italic.js +51 -63
- package/dist/prosekit-extensions-link.d.ts +65 -10
- package/dist/prosekit-extensions-link.js +95 -100
- package/dist/prosekit-extensions-list.d.ts +114 -17
- package/dist/prosekit-extensions-list.js +115 -158
- package/dist/prosekit-extensions-loro.d.ts +78 -11
- package/dist/prosekit-extensions-loro.js +49 -77
- package/dist/prosekit-extensions-mark-rule.d.ts +41 -2
- package/dist/prosekit-extensions-mark-rule.js +3 -6
- package/dist/prosekit-extensions-mention.d.ts +40 -4
- package/dist/prosekit-extensions-mention.js +52 -50
- package/dist/prosekit-extensions-mod-click-prevention.d.ts +20 -2
- package/dist/prosekit-extensions-mod-click-prevention.js +20 -16
- package/dist/prosekit-extensions-paragraph.d.ts +65 -0
- package/dist/prosekit-extensions-paragraph.js +60 -0
- package/dist/prosekit-extensions-placeholder.d.ts +32 -2
- package/dist/prosekit-extensions-placeholder.js +39 -56
- package/dist/prosekit-extensions-readonly.d.ts +13 -1
- package/dist/prosekit-extensions-readonly.js +13 -14
- package/dist/prosekit-extensions-search.d.ts +77 -3
- package/dist/prosekit-extensions-search.js +48 -47
- package/dist/prosekit-extensions-strike.d.ts +50 -8
- package/dist/prosekit-extensions-strike.js +44 -49
- package/dist/prosekit-extensions-table.d.ts +237 -26
- package/dist/prosekit-extensions-table.js +3 -34
- package/dist/prosekit-extensions-text-align.d.ts +72 -8
- package/dist/prosekit-extensions-text-align.js +63 -44
- package/dist/prosekit-extensions-text.d.ts +22 -0
- package/dist/prosekit-extensions-text.js +15 -0
- package/dist/prosekit-extensions-underline.d.ts +46 -7
- package/dist/prosekit-extensions-underline.js +33 -37
- package/dist/prosekit-extensions-virtual-selection.d.ts +24 -2
- package/dist/prosekit-extensions-virtual-selection.js +49 -52
- package/dist/prosekit-extensions-yjs.d.ts +99 -14
- package/dist/prosekit-extensions-yjs.js +88 -131
- package/dist/prosekit-extensions.d.ts +1 -1
- package/dist/search/style.css +5 -5
- package/dist/search/style.js +0 -0
- package/dist/shiki-highlighter-chunk-Cd3WeOKL.d.ts +19 -0
- package/dist/shiki-highlighter-chunk.d.ts +2 -0
- package/dist/shiki-highlighter-chunk.js +34 -43
- package/dist/table/style.css +18 -17
- package/dist/table/style.js +0 -0
- package/dist/table-DnVliJ6E.js +287 -0
- package/dist/virtual-selection/style.css +2 -2
- package/dist/virtual-selection/style.js +0 -0
- package/dist/yjs/style.css +15 -17
- package/dist/yjs/style.js +0 -0
- package/package.json +103 -52
- package/dist/_tsup-dts-rollup.d.ts +0 -2500
- package/dist/chunk-6UYLCVBX.js +0 -185
- package/dist/chunk-BV3SHIMW.js +0 -98
- package/dist/chunk-D54VSLLS.js +0 -105
- package/dist/chunk-HFAZX2J3.js +0 -306
@@ -0,0 +1,287 @@
|
|
1
|
+
import { defaultBlockAt, defineCommands, defineNodeSpec, definePlugin, findParentNode, getNodeType, insertNode, union } from "@prosekit/core";
|
2
|
+
import { TextSelection } from "@prosekit/pm/state";
|
3
|
+
import { CellSelection, TableMap, addColumnAfter, addColumnBefore, addRowAfter, addRowBefore, cellAround, cellNear, columnResizing, deleteCellSelection, deleteColumn, deleteRow, deleteTable, inSameTable, mergeCells, splitCell, tableEditing, tableNodes } from "prosemirror-tables";
|
4
|
+
|
5
|
+
//#region src/table/table-utils.ts
|
6
|
+
/**
|
7
|
+
* Checks if the given object is a `CellSelection` instance.
|
8
|
+
*
|
9
|
+
* @public
|
10
|
+
*/
|
11
|
+
function isCellSelection(value) {
|
12
|
+
return value instanceof CellSelection;
|
13
|
+
}
|
14
|
+
/**
|
15
|
+
* Find the closest table node.
|
16
|
+
*
|
17
|
+
* @internal
|
18
|
+
*/
|
19
|
+
function findTable($pos) {
|
20
|
+
return findParentNode((node) => node.type.spec.tableRole === "table", $pos);
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* Try to find the anchor and head cell in the same table by using the given
|
24
|
+
* anchor and head as hit points, or fallback to the selection's anchor and
|
25
|
+
* head.
|
26
|
+
*
|
27
|
+
* @internal
|
28
|
+
*/
|
29
|
+
function findCellRange(selection, anchorHit, headHit) {
|
30
|
+
if (anchorHit == null && headHit == null && isCellSelection(selection)) return [selection.$anchorCell, selection.$headCell];
|
31
|
+
const anchor = anchorHit ?? headHit ?? selection.anchor;
|
32
|
+
const head = headHit ?? anchorHit ?? selection.head;
|
33
|
+
const doc = selection.$head.doc;
|
34
|
+
const $anchorCell = findCellPos(doc, anchor);
|
35
|
+
const $headCell = findCellPos(doc, head);
|
36
|
+
if ($anchorCell && $headCell && inSameTable($anchorCell, $headCell)) return [$anchorCell, $headCell];
|
37
|
+
}
|
38
|
+
/**
|
39
|
+
* Try to find a resolved pos of a cell by using the given pos as a hit point.
|
40
|
+
*
|
41
|
+
* @internal
|
42
|
+
*/
|
43
|
+
function findCellPos(doc, pos) {
|
44
|
+
const $pos = doc.resolve(pos);
|
45
|
+
return cellAround($pos) || cellNear($pos);
|
46
|
+
}
|
47
|
+
|
48
|
+
//#endregion
|
49
|
+
//#region src/table/table-commands.ts
|
50
|
+
function createEmptyTable(schema, row, col, header) {
|
51
|
+
const tableType = getNodeType(schema, "table");
|
52
|
+
const tableRowType = getNodeType(schema, "tableRow");
|
53
|
+
const tableCellType = getNodeType(schema, "tableCell");
|
54
|
+
const tableHeaderCellType = getNodeType(schema, "tableHeaderCell");
|
55
|
+
if (header) {
|
56
|
+
const headerCell = tableHeaderCellType.createAndFill();
|
57
|
+
const headerCells = repeat(headerCell, col);
|
58
|
+
const headerRow = tableRowType.createAndFill(null, headerCells);
|
59
|
+
const bodyCell = tableCellType.createAndFill();
|
60
|
+
const bodyCells = repeat(bodyCell, col);
|
61
|
+
const bodyRow = tableRowType.createAndFill(null, bodyCells);
|
62
|
+
const bodyRows = repeat(bodyRow, row - 1);
|
63
|
+
return tableType.createAndFill(null, [headerRow, ...bodyRows]);
|
64
|
+
} else {
|
65
|
+
const bodyCell = tableCellType.createAndFill();
|
66
|
+
const bodyCells = repeat(bodyCell, col);
|
67
|
+
const bodyRow = tableRowType.createAndFill(null, bodyCells);
|
68
|
+
const bodyRows = repeat(bodyRow, row);
|
69
|
+
return tableType.createAndFill(null, bodyRows);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
function repeat(node, length) {
|
73
|
+
return Array(length).fill(node);
|
74
|
+
}
|
75
|
+
/**
|
76
|
+
* Insert a table node with the given number of rows and columns, and optionally
|
77
|
+
* a header row.
|
78
|
+
*
|
79
|
+
* @param options
|
80
|
+
*
|
81
|
+
* @public
|
82
|
+
*/
|
83
|
+
function insertTable(options) {
|
84
|
+
return (state, dispatch, view) => {
|
85
|
+
const { row, col, header = false } = options;
|
86
|
+
const table = createEmptyTable(state.schema, row, col, header);
|
87
|
+
return insertNode({ node: table })(state, dispatch, view);
|
88
|
+
};
|
89
|
+
}
|
90
|
+
/**
|
91
|
+
* When the selection is in a table node, create a default block after the table
|
92
|
+
* table, and move the cursor there.
|
93
|
+
*
|
94
|
+
* @public
|
95
|
+
*/
|
96
|
+
const exitTable = (state, dispatch) => {
|
97
|
+
const { $head, $anchor } = state.selection;
|
98
|
+
if (!$head.sameParent($anchor)) return false;
|
99
|
+
let tableStart = -1;
|
100
|
+
let tableDepth = -1;
|
101
|
+
for (let depth = $head.depth; depth >= 0; depth--) {
|
102
|
+
const node$1 = $head.node(depth);
|
103
|
+
if (node$1.type.spec.tableRole === "table") {
|
104
|
+
tableStart = $head.before(depth);
|
105
|
+
tableDepth = depth;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
if (tableStart < 0 || tableDepth <= 0) return false;
|
109
|
+
const above = $head.node(tableDepth - 1);
|
110
|
+
const after = $head.indexAfter(tableDepth - 1);
|
111
|
+
const type = defaultBlockAt(above.contentMatchAt(after));
|
112
|
+
const node = type?.createAndFill();
|
113
|
+
if (!type || !node || !above.canReplaceWith(after, after, type)) return false;
|
114
|
+
if (dispatch) {
|
115
|
+
const pos = $head.after(tableDepth);
|
116
|
+
const tr = state.tr.replaceWith(pos, pos, node);
|
117
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(pos), 1));
|
118
|
+
dispatch(tr.scrollIntoView());
|
119
|
+
}
|
120
|
+
return true;
|
121
|
+
};
|
122
|
+
/**
|
123
|
+
* @public
|
124
|
+
*/
|
125
|
+
function selectTableColumn(options) {
|
126
|
+
return (state, dispatch) => {
|
127
|
+
const range = findCellRange(state.selection, options?.anchor, options?.head);
|
128
|
+
if (!range) return false;
|
129
|
+
if (dispatch) {
|
130
|
+
const [$anchorCell, $headCell] = range;
|
131
|
+
const selection = CellSelection.colSelection($anchorCell, $headCell);
|
132
|
+
dispatch(state.tr.setSelection(selection));
|
133
|
+
}
|
134
|
+
return true;
|
135
|
+
};
|
136
|
+
}
|
137
|
+
/**
|
138
|
+
* @public
|
139
|
+
*/
|
140
|
+
function selectTableRow(options) {
|
141
|
+
return (state, dispatch) => {
|
142
|
+
const range = findCellRange(state.selection, options?.anchor, options?.head);
|
143
|
+
if (!range) return false;
|
144
|
+
if (dispatch) {
|
145
|
+
const [$anchorCell, $headCell] = range;
|
146
|
+
const selection = CellSelection.rowSelection($anchorCell, $headCell);
|
147
|
+
dispatch(state.tr.setSelection(selection));
|
148
|
+
}
|
149
|
+
return true;
|
150
|
+
};
|
151
|
+
}
|
152
|
+
/**
|
153
|
+
* @public
|
154
|
+
*/
|
155
|
+
function selectTableCell(options) {
|
156
|
+
return (state, dispatch) => {
|
157
|
+
const $cellPos = findCellPos(state.doc, options?.pos ?? state.selection.anchor);
|
158
|
+
if (!$cellPos) return false;
|
159
|
+
if (dispatch) {
|
160
|
+
const selection = new CellSelection($cellPos);
|
161
|
+
dispatch(state.tr.setSelection(selection));
|
162
|
+
}
|
163
|
+
return true;
|
164
|
+
};
|
165
|
+
}
|
166
|
+
/**
|
167
|
+
* @public
|
168
|
+
*/
|
169
|
+
function selectTable(options) {
|
170
|
+
return (state, dispatch) => {
|
171
|
+
const $pos = options?.pos ? state.doc.resolve(options.pos) : state.selection.$anchor;
|
172
|
+
const table = findTable($pos);
|
173
|
+
if (!table) return false;
|
174
|
+
const map = TableMap.get(table.node);
|
175
|
+
if (map.map.length === 0) return false;
|
176
|
+
if (dispatch) {
|
177
|
+
let tr = state.tr;
|
178
|
+
const firstCellPosInTable = map.map[0];
|
179
|
+
const lastCellPosInTable = map.map[map.map.length - 1];
|
180
|
+
const firstCellPos = table.pos + firstCellPosInTable + 1;
|
181
|
+
const lastCellPos = table.pos + lastCellPosInTable + 1;
|
182
|
+
const $firstCellPos = tr.doc.resolve(firstCellPos);
|
183
|
+
const $lastCellPos = tr.doc.resolve(lastCellPos);
|
184
|
+
const selection = new CellSelection($firstCellPos, $lastCellPos);
|
185
|
+
tr = tr.setSelection(selection);
|
186
|
+
dispatch?.(tr);
|
187
|
+
}
|
188
|
+
return true;
|
189
|
+
};
|
190
|
+
}
|
191
|
+
/**
|
192
|
+
* Adds commands for working with `table` nodes.
|
193
|
+
*
|
194
|
+
* @public
|
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
|
+
//#endregion
|
218
|
+
//#region src/table/table-plugins.ts
|
219
|
+
/**
|
220
|
+
* @public
|
221
|
+
*/
|
222
|
+
function defineTablePlugins() {
|
223
|
+
return definePlugin([tableEditing(), columnResizing()]);
|
224
|
+
}
|
225
|
+
|
226
|
+
//#endregion
|
227
|
+
//#region src/table/table-spec.ts
|
228
|
+
const cellContent = "block+";
|
229
|
+
const cellAttrs = {
|
230
|
+
colspan: { default: 1 },
|
231
|
+
rowspan: { default: 1 },
|
232
|
+
colwidth: { default: null }
|
233
|
+
};
|
234
|
+
const specs = tableNodes({
|
235
|
+
tableGroup: "block",
|
236
|
+
cellContent,
|
237
|
+
cellAttributes: {}
|
238
|
+
});
|
239
|
+
/**
|
240
|
+
* @internal
|
241
|
+
*/
|
242
|
+
function defineTableSpec() {
|
243
|
+
return defineNodeSpec({
|
244
|
+
...specs["table"],
|
245
|
+
content: "tableRow+",
|
246
|
+
name: "table"
|
247
|
+
});
|
248
|
+
}
|
249
|
+
/**
|
250
|
+
* @internal
|
251
|
+
*/
|
252
|
+
function defineTableRowSpec() {
|
253
|
+
return defineNodeSpec({
|
254
|
+
...specs["table_row"],
|
255
|
+
content: "(tableCell | tableHeaderCell)*",
|
256
|
+
name: "tableRow"
|
257
|
+
});
|
258
|
+
}
|
259
|
+
/**
|
260
|
+
* @internal
|
261
|
+
*/
|
262
|
+
function defineTableCellSpec() {
|
263
|
+
return defineNodeSpec({
|
264
|
+
...specs["table_cell"],
|
265
|
+
name: "tableCell",
|
266
|
+
attrs: cellAttrs
|
267
|
+
});
|
268
|
+
}
|
269
|
+
function defineTableHeaderCellSpec() {
|
270
|
+
return defineNodeSpec({
|
271
|
+
...specs["table_header"],
|
272
|
+
name: "tableHeaderCell",
|
273
|
+
attrs: cellAttrs
|
274
|
+
});
|
275
|
+
}
|
276
|
+
|
277
|
+
//#endregion
|
278
|
+
//#region src/table/table.ts
|
279
|
+
/**
|
280
|
+
* @public
|
281
|
+
*/
|
282
|
+
function defineTable() {
|
283
|
+
return union(defineTableSpec(), defineTableRowSpec(), defineTableCellSpec(), defineTableHeaderCellSpec(), defineTablePlugins(), defineTableCommands());
|
284
|
+
}
|
285
|
+
|
286
|
+
//#endregion
|
287
|
+
export { defineTable, defineTableCellSpec, defineTableCommands, defineTableHeaderCellSpec, defineTablePlugins, defineTableRowSpec, defineTableSpec, exitTable, findTable, insertTable, isCellSelection, selectTable, selectTableCell, selectTableColumn, selectTableRow };
|
File without changes
|
package/dist/yjs/style.css
CHANGED
@@ -1,31 +1,29 @@
|
|
1
|
-
/* src/yjs/style.css */
|
2
1
|
.ProseMirror .ProseMirror-yjs-cursor {
|
3
|
-
|
4
|
-
|
2
|
+
word-break: normal;
|
3
|
+
pointer-events: none;
|
4
|
+
border-color: orange;
|
5
5
|
border-left-style: solid;
|
6
6
|
border-left-width: 2px;
|
7
|
-
border-color: orange;
|
8
7
|
height: 1em;
|
9
|
-
|
10
|
-
pointer-events: none;
|
8
|
+
position: absolute;
|
11
9
|
}
|
10
|
+
|
12
11
|
.ProseMirror .ProseMirror-yjs-cursor > div {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
color: #fff;
|
13
|
+
user-select: none;
|
14
|
+
background-color: #fa8100;
|
15
|
+
padding-left: 2px;
|
16
|
+
padding-right: 2px;
|
17
17
|
font-family: serif;
|
18
|
+
font-size: 13px;
|
18
19
|
font-style: normal;
|
19
20
|
font-weight: normal;
|
20
21
|
line-height: normal;
|
21
|
-
|
22
|
-
|
23
|
-
-ms-user-select: none;
|
24
|
-
user-select: none;
|
25
|
-
color: white;
|
26
|
-
padding-left: 2px;
|
27
|
-
padding-right: 2px;
|
22
|
+
position: relative;
|
23
|
+
top: -1.05em;
|
28
24
|
}
|
25
|
+
|
29
26
|
.ProseMirror > .ProseMirror-yjs-cursor:first-child {
|
30
27
|
margin-top: 16px;
|
31
28
|
}
|
29
|
+
|
File without changes
|