@prosekit/extensions 0.0.0-next-20240724172520 → 0.0.0-next-20240901092634

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.
Files changed (39) hide show
  1. package/dist/_tsup-dts-rollup.d.ts +520 -129
  2. package/dist/{chunk-GPSAJOJA.js → chunk-GITDYNLT.js} +0 -3
  3. package/dist/{chunk-LVMTQOWG.js → chunk-LAQZC3ZM.js} +12 -14
  4. package/dist/{chunk-OJCMRVEY.js → chunk-RE23OQPF.js} +2 -2
  5. package/dist/loro/style.css +30 -0
  6. package/dist/prosekit-extensions-autocomplete.js +3 -2
  7. package/dist/prosekit-extensions-blockquote.js +2 -2
  8. package/dist/prosekit-extensions-bold.js +3 -3
  9. package/dist/prosekit-extensions-code-block.d.ts +4 -0
  10. package/dist/prosekit-extensions-code-block.js +20 -46
  11. package/dist/prosekit-extensions-code.js +3 -3
  12. package/dist/prosekit-extensions-commit.js +9 -6
  13. package/dist/prosekit-extensions-enter-rule.js +1 -1
  14. package/dist/prosekit-extensions-gap-cursor.d.ts +1 -0
  15. package/dist/prosekit-extensions-heading.d.ts +1 -1
  16. package/dist/prosekit-extensions-heading.js +3 -3
  17. package/dist/prosekit-extensions-image.js +1 -1
  18. package/dist/prosekit-extensions-input-rule.js +1 -1
  19. package/dist/prosekit-extensions-italic.js +3 -3
  20. package/dist/prosekit-extensions-link.js +5 -5
  21. package/dist/prosekit-extensions-list.js +3 -3
  22. package/dist/prosekit-extensions-loro.d.ts +11 -0
  23. package/dist/prosekit-extensions-loro.js +79 -0
  24. package/dist/prosekit-extensions-mark-rule.js +1 -1
  25. package/dist/prosekit-extensions-mention.js +1 -1
  26. package/dist/prosekit-extensions-placeholder.js +0 -1
  27. package/dist/prosekit-extensions-strike.js +3 -3
  28. package/dist/prosekit-extensions-table.d.ts +15 -3
  29. package/dist/prosekit-extensions-table.js +191 -90
  30. package/dist/prosekit-extensions-text-align.d.ts +3 -1
  31. package/dist/prosekit-extensions-text-align.js +2 -2
  32. package/dist/prosekit-extensions-underline.js +2 -2
  33. package/dist/prosekit-extensions-yjs.d.ts +14 -0
  34. package/dist/prosekit-extensions-yjs.js +143 -0
  35. package/dist/shiki-highlighter-chunk-C5VVQ2TD.js +50 -0
  36. package/dist/table/style.css +6 -1
  37. package/dist/yjs/style.css +31 -0
  38. package/package.json +58 -10
  39. package/dist/shiki-import-UFUFVKJ2.js +0 -5
@@ -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 { defineTableHeaderCellSpec } from './_tsup-dts-rollup';
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/index.ts
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 table = getNodeType(schema, "table");
14
- const tableRow = getNodeType(schema, "tableRow");
15
- const tableCell = getNodeType(schema, "tableCell");
16
- const tableHeaderCell = getNodeType(schema, "tableHeaderCell");
17
- const createHeaderRow = () => {
18
- return tableRow.createAndFill(
19
- null,
20
- Array.from({ length: col }, () => tableHeaderCell.createAndFill())
21
- );
22
- };
23
- const createBodyRow = () => {
24
- return tableRow.createAndFill(
25
- null,
26
- Array.from({ length: col }, () => tableCell.createAndFill())
27
- );
28
- };
29
- const rows = [
30
- ...Array.from({ length: header ? 1 : 0 }, createHeaderRow),
31
- ...Array.from({ length: header ? row - 1 : row }, createBodyRow)
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 insertTable({ row, col, header }) {
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,100 +223,57 @@ 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
- function getCellAttrs(dom) {
91
- if (typeof dom === "string") {
92
- return {};
93
- }
94
- const widthAttr = dom.getAttribute("data-colwidth");
95
- const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr) ? widthAttr.split(",").map((s) => Number(s)) : null;
96
- const colspan = Number(dom.getAttribute("colspan") || 1);
97
- return {
98
- colspan,
99
- rowspan: Number(dom.getAttribute("rowspan") || 1),
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
- name: "table",
120
- tableRole: "table",
240
+ ...specs["table"],
121
241
  content: "tableRow+",
122
- isolating: true,
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
- name: "tableRow",
133
- tableRole: "row",
247
+ ...specs["table_row"],
134
248
  content: "(tableCell | tableHeaderCell)*",
135
- parseDOM: [{ tag: "tr" }],
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
- tableRole: "cell",
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
- tableRole: "header_cell",
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/index.ts
267
+ // src/table/table.ts
174
268
  function defineTable() {
175
- return union([
269
+ return union(
176
270
  defineTableSpec(),
177
271
  defineTableRowSpec(),
178
272
  defineTableCellSpec(),
179
273
  defineTableHeaderCellSpec(),
180
274
  defineTablePlugins(),
181
275
  defineTableCommands()
182
- ]);
276
+ );
183
277
  }
184
278
  export {
185
279
  defineTable,
@@ -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
  };
@@ -3,4 +3,6 @@ export { defineTextAlignCommands } from './_tsup-dts-rollup';
3
3
  export { defineTextAlignKeymap } from './_tsup-dts-rollup';
4
4
  export { defineTextAlign } from './_tsup-dts-rollup';
5
5
  export { TextAlignOptions } from './_tsup-dts-rollup';
6
- export { TextAlignCommandTyping } from './_tsup-dts-rollup';
6
+ export { TextAlignAttrsExtension } from './_tsup-dts-rollup';
7
+ export { TextAlignCommandsExtension } from './_tsup-dts-rollup';
8
+ export { TextAlignExtension } from './_tsup-dts-rollup';
@@ -41,11 +41,11 @@ function defineTextAlignKeymap(types) {
41
41
  });
42
42
  }
43
43
  function defineTextAlign(options) {
44
- return union([
44
+ return union(
45
45
  defineTextAlignAttrs(options.types, options.default || "left"),
46
46
  defineTextAlignKeymap(options.types),
47
47
  defineTextAlignCommands(options.types)
48
- ]);
48
+ );
49
49
  }
50
50
  export {
51
51
  defineTextAlign,
@@ -31,11 +31,11 @@ function defineUnderlineKeymap() {
31
31
  });
32
32
  }
33
33
  function defineUnderline() {
34
- return union([
34
+ return union(
35
35
  defineUnderlineSpec(),
36
36
  defineUnderlineCommands(),
37
37
  defineUnderlineKeymap()
38
- ]);
38
+ );
39
39
  }
40
40
  export {
41
41
  defineUnderline,
@@ -0,0 +1,14 @@
1
+ export { defineYjs } from './_tsup-dts-rollup';
2
+ export { YjsOptions } from './_tsup-dts-rollup';
3
+ export { YjsExtension } from './_tsup-dts-rollup';
4
+ export { defineYjsCommands_alias_1 as defineYjsCommands } from './_tsup-dts-rollup';
5
+ export { defineYjsCursorPlugin_alias_1 as defineYjsCursorPlugin } from './_tsup-dts-rollup';
6
+ export { defineYjsKeymap } from './_tsup-dts-rollup';
7
+ export { defineYjsSyncPlugin } from './_tsup-dts-rollup';
8
+ export { defineYjsUndoPlugin } from './_tsup-dts-rollup';
9
+ export { YjsCursorOptions_alias_1 as YjsCursorOptions } from './_tsup-dts-rollup';
10
+ export { YjsCursorPluginOptions_alias_1 as YjsCursorPluginOptions } from './_tsup-dts-rollup';
11
+ export { YjsSyncOptions } from './_tsup-dts-rollup';
12
+ export { YjsSyncPluginOptions } from './_tsup-dts-rollup';
13
+ export { YjsUndoOptions } from './_tsup-dts-rollup';
14
+ export { YjsUndoPluginOptions } from './_tsup-dts-rollup';
@@ -0,0 +1,143 @@
1
+ // src/yjs/index.ts
2
+ import {
3
+ Priority,
4
+ union,
5
+ withPriority
6
+ } from "@prosekit/core";
7
+
8
+ // src/yjs/commands.ts
9
+ import { defineCommands } from "@prosekit/core";
10
+
11
+ // src/yjs/undo-plugin.ts
12
+ import { definePlugin } from "@prosekit/core";
13
+ import {
14
+ yUndoPluginKey,
15
+ yUndoPlugin as originalYUndoPlugin,
16
+ undo as yUndo,
17
+ redo as yRedo
18
+ } from "y-prosemirror";
19
+ function fixYUndoPlugin(yUndoPluginInstance) {
20
+ const originalUndoPluginView = yUndoPluginInstance.spec.view;
21
+ yUndoPluginInstance.spec.view = (view) => {
22
+ const { undoManager } = yUndoPluginKey.getState(view.state);
23
+ if (undoManager.restore) {
24
+ undoManager.restore();
25
+ undoManager.restore = () => {
26
+ };
27
+ }
28
+ const viewRet = originalUndoPluginView ? originalUndoPluginView(view) : void 0;
29
+ return {
30
+ destroy: () => {
31
+ const hasUndoManSelf = undoManager.trackedOrigins.has(undoManager);
32
+ const observers = undoManager._observers;
33
+ undoManager.restore = () => {
34
+ if (hasUndoManSelf) {
35
+ undoManager.trackedOrigins.add(undoManager);
36
+ }
37
+ undoManager.doc.on(
38
+ "afterTransaction",
39
+ undoManager.afterTransactionHandler
40
+ );
41
+ undoManager._observers = observers;
42
+ };
43
+ if (viewRet == null ? void 0 : viewRet.destroy) {
44
+ viewRet.destroy();
45
+ }
46
+ }
47
+ };
48
+ };
49
+ }
50
+ function yUndoPlugin(options) {
51
+ const yUndoPluginInstance = originalYUndoPlugin(options);
52
+ fixYUndoPlugin(yUndoPluginInstance);
53
+ return yUndoPluginInstance;
54
+ }
55
+ var undo = (state, dispatch) => {
56
+ const { undoManager } = yUndoPluginKey.getState(state);
57
+ if (undoManager.undoStack.length === 0) {
58
+ return false;
59
+ }
60
+ if (!dispatch) {
61
+ return true;
62
+ }
63
+ return yUndo(state);
64
+ };
65
+ var redo = (state, dispatch) => {
66
+ const { undoManager } = yUndoPluginKey.getState(state);
67
+ if (undoManager.redoStack.length === 0) {
68
+ return false;
69
+ }
70
+ if (!dispatch) {
71
+ return true;
72
+ }
73
+ return yRedo(state);
74
+ };
75
+ function defineYjsUndoPlugin(options) {
76
+ return definePlugin(yUndoPlugin(options));
77
+ }
78
+
79
+ // src/yjs/commands.ts
80
+ var commands = {
81
+ undo: () => undo,
82
+ redo: () => redo
83
+ };
84
+ function defineYjsCommands() {
85
+ return defineCommands(commands);
86
+ }
87
+
88
+ // src/yjs/cursor-plugin.ts
89
+ import { definePlugin as definePlugin2 } from "@prosekit/core";
90
+ import { yCursorPlugin } from "y-prosemirror";
91
+ function defineYjsCursorPlugin(options) {
92
+ const { awareness, ...rest } = options;
93
+ return definePlugin2(yCursorPlugin(awareness, rest));
94
+ }
95
+
96
+ // src/yjs/keymap.ts
97
+ import {
98
+ defineKeymap,
99
+ isApple
100
+ } from "@prosekit/core";
101
+ var keymap = {
102
+ "Mod-z": undo,
103
+ "Shift-Mod-z": redo
104
+ };
105
+ if (!isApple) {
106
+ keymap["Mod-y"] = redo;
107
+ }
108
+ function defineYjsKeymap() {
109
+ return defineKeymap(keymap);
110
+ }
111
+
112
+ // src/yjs/sync-plugin.ts
113
+ import { definePlugin as definePlugin3 } from "@prosekit/core";
114
+ import { ySyncPlugin } from "y-prosemirror";
115
+ function defineYjsSyncPlugin(options) {
116
+ const { fragment, ...rest } = options;
117
+ return definePlugin3(ySyncPlugin(fragment, rest));
118
+ }
119
+
120
+ // src/yjs/index.ts
121
+ function defineYjs(options) {
122
+ var _a;
123
+ const { doc, awareness, sync, undo: undo2, cursor } = options;
124
+ const fragment = (_a = options.fragment) != null ? _a : doc.getXmlFragment("prosemirror");
125
+ return withPriority(
126
+ union([
127
+ defineYjsKeymap(),
128
+ defineYjsCommands(),
129
+ defineYjsCursorPlugin({ ...cursor, awareness }),
130
+ defineYjsUndoPlugin({ ...undo2 }),
131
+ defineYjsSyncPlugin({ ...sync, fragment })
132
+ ]),
133
+ Priority.high
134
+ );
135
+ }
136
+ export {
137
+ defineYjs,
138
+ defineYjsCommands,
139
+ defineYjsCursorPlugin,
140
+ defineYjsKeymap,
141
+ defineYjsSyncPlugin,
142
+ defineYjsUndoPlugin
143
+ };
@@ -0,0 +1,50 @@
1
+ // src/code-block/shiki-highlighter-chunk.ts
2
+ import {
3
+ createHighlighter,
4
+ createJavaScriptRegexEngine
5
+ } from "shiki/bundle/full";
6
+ var highlighter;
7
+ var loadedLangs = /* @__PURE__ */ new Set();
8
+ var loadedThemes = /* @__PURE__ */ new Set();
9
+ async function createAndCacheHighlighter({
10
+ ...options
11
+ }) {
12
+ if (!highlighter) {
13
+ if (!options.engine) {
14
+ const engine = createJavaScriptRegexEngine();
15
+ options.engine = engine;
16
+ }
17
+ highlighter = await createHighlighter(options);
18
+ }
19
+ }
20
+ async function loadLanguages(langs) {
21
+ for (const lang of langs) {
22
+ if (!highlighter) break;
23
+ await highlighter.loadLanguage(lang);
24
+ loadedLangs.add(lang);
25
+ }
26
+ }
27
+ async function loadThemes(themes) {
28
+ for (const theme of themes) {
29
+ if (!highlighter) break;
30
+ await highlighter.loadTheme(theme);
31
+ loadedThemes.add(theme);
32
+ }
33
+ }
34
+ function createOrGetHighlighter(options) {
35
+ if (!highlighter) {
36
+ return { promise: createAndCacheHighlighter(options) };
37
+ }
38
+ const langs = options.langs.filter((lang) => !loadedLangs.has(lang));
39
+ if (langs.length > 0) {
40
+ return { promise: loadLanguages(langs) };
41
+ }
42
+ const themes = options.themes.filter((theme) => !loadedThemes.has(theme));
43
+ if (themes.length > 0) {
44
+ return { promise: loadThemes(themes) };
45
+ }
46
+ return { highlighter };
47
+ }
48
+ export {
49
+ createOrGetHighlighter
50
+ };
@@ -30,5 +30,10 @@
30
30
  cursor: col-resize;
31
31
  }
32
32
  .ProseMirror .selectedCell {
33
- background-color: Highlight;
33
+ --color:
34
+ 210,
35
+ 100%,
36
+ 56%;
37
+ background-color: hsla(var(--color), 20%);
38
+ border: 1px double hsl(var(--color));
34
39
  }
@@ -0,0 +1,31 @@
1
+ /* src/yjs/style.css */
2
+ .ProseMirror .ProseMirror-yjs-cursor {
3
+ position: absolute;
4
+ border-left: black;
5
+ border-left-style: solid;
6
+ border-left-width: 2px;
7
+ border-color: orange;
8
+ height: 1em;
9
+ word-break: normal;
10
+ pointer-events: none;
11
+ }
12
+ .ProseMirror .ProseMirror-yjs-cursor > div {
13
+ position: relative;
14
+ top: -1.05em;
15
+ font-size: 13px;
16
+ background-color: rgb(250, 129, 0);
17
+ font-family: serif;
18
+ font-style: normal;
19
+ font-weight: normal;
20
+ line-height: normal;
21
+ -webkit-user-select: none;
22
+ -moz-user-select: none;
23
+ -ms-user-select: none;
24
+ user-select: none;
25
+ color: white;
26
+ padding-left: 2px;
27
+ padding-right: 2px;
28
+ }
29
+ .ProseMirror > .ProseMirror-yjs-cursor:first-child {
30
+ margin-top: 16px;
31
+ }