@prosekit/core 0.8.0 → 0.8.1

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.
@@ -1,1620 +1,1636 @@
1
- import {
2
- Editor,
3
- EditorNotFoundError,
4
- Priority,
5
- ProseKitError,
6
- assert,
7
- createEditor,
8
- defineDefaultState,
9
- defineFacet,
10
- defineFacetPayload,
11
- elementFromJSON,
12
- elementFromNode,
13
- getMarkType,
14
- getNodeType,
15
- htmlFromJSON,
16
- htmlFromNode,
17
- isAllSelection,
18
- isElement,
19
- isFragment,
20
- isMark,
21
- isMarkAbsent,
22
- isMarkActive,
23
- isNodeActive,
24
- isNodeSelection,
25
- isNotNullish,
26
- isProseMirrorNode,
27
- isSelection,
28
- isSlice,
29
- isTextSelection,
30
- jsonFromHTML,
31
- jsonFromNode,
32
- jsonFromState,
33
- nodeFromElement,
34
- nodeFromHTML,
35
- nodeFromJSON,
36
- rootFacet,
37
- schemaFacet,
38
- stateFacet,
39
- stateFromJSON,
40
- toReversed,
41
- union
42
- } from "./chunk-B3WEP4DD.js";
43
-
44
- // src/commands/add-mark.ts
1
+ import { Editor, EditorNotFoundError, Priority, ProseKitError, assert, createEditor, defineDefaultState, defineFacet, defineFacetPayload, elementFromJSON, elementFromNode, getMarkType, getNodeType, htmlFromJSON, htmlFromNode, isAllSelection, isFragment, isMark, isMarkAbsent, isMarkActive, isNodeActive, isNodeSelection, isNotNullish, isProseMirrorNode, isSelection, isSlice, isTextSelection, jsonFromHTML, jsonFromNode, jsonFromState, nodeFromElement, nodeFromHTML, nodeFromJSON, rootFacet, schemaFacet, stateFacet, stateFromJSON, toReversed, union } from "./editor-BOiNwODb.js";
2
+ import { AllSelection, Plugin, PluginKey, ProseMirrorPlugin, TextSelection } from "@prosekit/pm/state";
3
+ import { ReplaceAroundStep, findWrapping, insertPoint } from "@prosekit/pm/transform";
4
+ import { baseKeymap, chainCommands, createParagraphNear, deleteSelection, joinTextblockBackward, lift, liftEmptyBlock, newlineInCode, selectNodeBackward, setBlockType as setBlockType$1, toggleMark as toggleMark$1 } from "@prosekit/pm/commands";
5
+ import { DOMSerializer, Fragment, ProseMirrorFragment, ProseMirrorNode, Slice } from "@prosekit/pm/model";
6
+ import { isElementLike } from "@ocavue/utils";
7
+ import OrderedMap from "orderedmap";
8
+ import mapValues from "just-map-values";
9
+ import clone from "just-clone";
10
+ import { history, redo, undo } from "@prosekit/pm/history";
11
+ import { keydownHandler } from "@prosekit/pm/keymap";
12
+ import { splitSplittableBlock } from "prosemirror-splittable";
13
+ import clsxLite from "clsx/lite";
14
+
15
+ //#region src/commands/add-mark.ts
16
+ /**
17
+ * Returns a command that adds the given mark with the given attributes.
18
+ *
19
+ * @public
20
+ */
45
21
  function addMark(options) {
46
- return (state, dispatch) => {
47
- const mark = getMarkType(state.schema, options.type).create(options.attrs);
48
- const from = options.from ?? state.selection.from;
49
- const to = options.to ?? state.selection.to;
50
- if (from > to) {
51
- return false;
52
- }
53
- dispatch?.(state.tr.addMark(from, to, mark));
54
- return true;
55
- };
56
- }
57
-
58
- // src/commands/expand-mark.ts
59
- import {
60
- TextSelection
61
- } from "@prosekit/pm/state";
22
+ return (state, dispatch) => {
23
+ const mark = getMarkType(state.schema, options.type).create(options.attrs);
24
+ const from = options.from ?? state.selection.from;
25
+ const to = options.to ?? state.selection.to;
26
+ if (from > to) return false;
27
+ dispatch?.(state.tr.addMark(from, to, mark));
28
+ return true;
29
+ };
30
+ }
31
+
32
+ //#endregion
33
+ //#region src/commands/expand-mark.ts
34
+ /**
35
+ * Expands the selection to include the entire mark at the current position.
36
+ *
37
+ * @public
38
+ */
62
39
  function expandMark(options) {
63
- return (state, dispatch) => {
64
- const markType = getMarkType(state.schema, options.type);
65
- const predicate = (mark) => mark.type === markType;
66
- const from = expandMarkBefore(state.selection.$from, predicate);
67
- const to = expandMarkAfter(state.selection.$to, predicate);
68
- if (from === state.selection.from && to === state.selection.to) {
69
- return false;
70
- }
71
- if (dispatch) {
72
- dispatch(state.tr.setSelection(TextSelection.create(state.doc, from, to)));
73
- }
74
- return true;
75
- };
40
+ return (state, dispatch) => {
41
+ const markType = getMarkType(state.schema, options.type);
42
+ const predicate = (mark) => mark.type === markType;
43
+ const from = expandMarkBefore(state.selection.$from, predicate);
44
+ const to = expandMarkAfter(state.selection.$to, predicate);
45
+ if (from === state.selection.from && to === state.selection.to) return false;
46
+ if (dispatch) dispatch(state.tr.setSelection(TextSelection.create(state.doc, from, to)));
47
+ return true;
48
+ };
76
49
  }
77
50
  function expandMarkBefore($pos, predicate) {
78
- const { parent } = $pos;
79
- if (!$pos.marks().some(predicate)) {
80
- return $pos.pos;
81
- }
82
- const index = $pos.index();
83
- let boundaryIndex = index;
84
- for (let i = index; i >= 0; i--) {
85
- const node = parent.child(i);
86
- if (node.marks.some(predicate)) {
87
- boundaryIndex = i;
88
- } else {
89
- break;
90
- }
91
- }
92
- return $pos.posAtIndex(boundaryIndex);
51
+ const { parent } = $pos;
52
+ if (!$pos.marks().some(predicate)) return $pos.pos;
53
+ const index = $pos.index();
54
+ let boundaryIndex = index;
55
+ for (let i = index; i >= 0; i--) {
56
+ const node = parent.child(i);
57
+ if (node.marks.some(predicate)) boundaryIndex = i;
58
+ else break;
59
+ }
60
+ return $pos.posAtIndex(boundaryIndex);
93
61
  }
94
62
  function expandMarkAfter($pos, predicate) {
95
- const { parent } = $pos;
96
- if (!$pos.marks().some(predicate)) {
97
- return $pos.pos;
98
- }
99
- const index = Math.max(0, $pos.indexAfter() - 1);
100
- const childCount = parent.childCount;
101
- let boundaryIndex = index;
102
- for (let i = index; i < childCount; i++) {
103
- const node = parent.child(i);
104
- if (node.marks.some(predicate)) {
105
- boundaryIndex = i;
106
- } else {
107
- break;
108
- }
109
- }
110
- return $pos.posAtIndex(boundaryIndex) + parent.child(boundaryIndex).nodeSize;
111
- }
112
-
113
- // src/commands/insert-default-block.ts
114
- import {
115
- TextSelection as TextSelection2
116
- } from "@prosekit/pm/state";
117
-
118
- // src/utils/default-block-at.ts
63
+ const { parent } = $pos;
64
+ if (!$pos.marks().some(predicate)) return $pos.pos;
65
+ const index = Math.max(0, $pos.indexAfter() - 1);
66
+ const childCount = parent.childCount;
67
+ let boundaryIndex = index;
68
+ for (let i = index; i < childCount; i++) {
69
+ const node = parent.child(i);
70
+ if (node.marks.some(predicate)) boundaryIndex = i;
71
+ else break;
72
+ }
73
+ return $pos.posAtIndex(boundaryIndex) + parent.child(boundaryIndex).nodeSize;
74
+ }
75
+
76
+ //#endregion
77
+ //#region src/utils/default-block-at.ts
78
+ /**
79
+ * @internal
80
+ */
119
81
  function defaultBlockAt(match) {
120
- for (let i = 0; i < match.edgeCount; i++) {
121
- const { type } = match.edge(i);
122
- if (type.isTextblock && !type.hasRequiredAttrs()) return type;
123
- }
124
- return null;
125
- }
126
-
127
- // src/commands/insert-default-block.ts
82
+ for (let i = 0; i < match.edgeCount; i++) {
83
+ const { type } = match.edge(i);
84
+ if (type.isTextblock && !type.hasRequiredAttrs()) return type;
85
+ }
86
+ return null;
87
+ }
88
+
89
+ //#endregion
90
+ //#region src/commands/insert-default-block.ts
91
+ /**
92
+ * Returns a command that inserts a default block after current selection or at
93
+ * the given position.
94
+ *
95
+ * @public
96
+ */
128
97
  function insertDefaultBlock(options) {
129
- return (state, dispatch) => {
130
- const $pos = options?.pos == null ? state.selection.$to : state.doc.resolve(options.pos);
131
- const depth = $pos.parent.isTextblock ? $pos.depth - 1 : $pos.depth;
132
- const parent = $pos.node(depth);
133
- const index = $pos.indexAfter(depth);
134
- const type = defaultBlockAt(parent.contentMatchAt(index));
135
- if (!type) return false;
136
- if (dispatch) {
137
- const pos = $pos.posAtIndex(index, depth);
138
- const node = type.createAndFill();
139
- if (!node) return false;
140
- const tr = state.tr.insert(pos, node);
141
- const selection = TextSelection2.findFrom(tr.doc.resolve(pos), 1);
142
- if (!selection) return false;
143
- tr.setSelection(selection);
144
- dispatch(tr.scrollIntoView());
145
- }
146
- return true;
147
- };
148
- }
149
-
150
- // src/commands/insert-node.ts
151
- import { insertPoint } from "@prosekit/pm/transform";
152
-
153
- // src/utils/set-selection-around.ts
154
- import {
155
- TextSelection as TextSelection3
156
- } from "@prosekit/pm/state";
98
+ return (state, dispatch) => {
99
+ const $pos = options?.pos == null ? state.selection.$to : state.doc.resolve(options.pos);
100
+ const depth = $pos.parent.isTextblock ? $pos.depth - 1 : $pos.depth;
101
+ const parent = $pos.node(depth);
102
+ const index = $pos.indexAfter(depth);
103
+ const type = defaultBlockAt(parent.contentMatchAt(index));
104
+ if (!type) return false;
105
+ if (dispatch) {
106
+ const pos = $pos.posAtIndex(index, depth);
107
+ const node = type.createAndFill();
108
+ if (!node) return false;
109
+ const tr = state.tr.insert(pos, node);
110
+ const selection = TextSelection.findFrom(tr.doc.resolve(pos), 1);
111
+ if (!selection) return false;
112
+ tr.setSelection(selection);
113
+ dispatch(tr.scrollIntoView());
114
+ }
115
+ return true;
116
+ };
117
+ }
118
+
119
+ //#endregion
120
+ //#region src/utils/set-selection-around.ts
157
121
  function setSelectionAround(tr, pos) {
158
- const docSize = tr.doc.content.size;
159
- const $pos = tr.doc.resolve(pos > docSize ? docSize : pos < 0 ? 0 : pos);
160
- const selection = TextSelection3.between($pos, $pos);
161
- tr.setSelection(selection);
162
- }
163
-
164
- // src/commands/insert-node.ts
122
+ const docSize = tr.doc.content.size;
123
+ const $pos = tr.doc.resolve(pos > docSize ? docSize : pos < 0 ? 0 : pos);
124
+ const selection = TextSelection.between($pos, $pos);
125
+ tr.setSelection(selection);
126
+ }
127
+
128
+ //#endregion
129
+ //#region src/commands/insert-node.ts
130
+ /**
131
+ * Returns a command that inserts the given node at the current selection or at
132
+ * the given position.
133
+ *
134
+ * @public
135
+ */
165
136
  function insertNode(options) {
166
- return (state, dispatch) => {
167
- const node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).createAndFill(options.attrs) : null;
168
- assert(node, "You must provide either a node or a type");
169
- const insertPos = insertPoint(
170
- state.doc,
171
- options.pos ?? state.selection.anchor,
172
- node.type
173
- );
174
- if (insertPos == null) return false;
175
- if (dispatch) {
176
- const tr = state.tr.insert(insertPos, node);
177
- setSelectionAround(tr, insertPos + node.nodeSize);
178
- dispatch(tr);
179
- }
180
- return true;
181
- };
182
- }
183
-
184
- // src/commands/remove-mark.ts
137
+ return (state, dispatch) => {
138
+ const node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).createAndFill(options.attrs) : null;
139
+ assert(node, "You must provide either a node or a type");
140
+ const insertPos = insertPoint(state.doc, options.pos ?? state.selection.anchor, node.type);
141
+ if (insertPos == null) return false;
142
+ if (dispatch) {
143
+ const tr = state.tr.insert(insertPos, node);
144
+ setSelectionAround(tr, insertPos + node.nodeSize);
145
+ dispatch(tr);
146
+ }
147
+ return true;
148
+ };
149
+ }
150
+
151
+ //#endregion
152
+ //#region src/commands/remove-mark.ts
153
+ /**
154
+ * Returns a command that removes the given mark.
155
+ *
156
+ * @public
157
+ */
185
158
  function removeMark(options) {
186
- return (state, dispatch) => {
187
- const markType = getMarkType(state.schema, options.type);
188
- const mark = options.attrs ? markType.create(options.attrs) : markType;
189
- const from = options.from ?? state.selection.from;
190
- const to = options.to ?? state.selection.to;
191
- if (from > to) {
192
- return false;
193
- }
194
- dispatch?.(state.tr.removeMark(from, to, mark));
195
- return true;
196
- };
197
- }
198
-
199
- // src/utils/find-parent-node.ts
159
+ return (state, dispatch) => {
160
+ const markType = getMarkType(state.schema, options.type);
161
+ const mark = options.attrs ? markType.create(options.attrs) : markType;
162
+ const from = options.from ?? state.selection.from;
163
+ const to = options.to ?? state.selection.to;
164
+ if (from > to) return false;
165
+ dispatch?.(state.tr.removeMark(from, to, mark));
166
+ return true;
167
+ };
168
+ }
169
+
170
+ //#endregion
171
+ //#region src/utils/find-parent-node.ts
172
+ /**
173
+ * Find the closest parent node that satisfies the predicate.
174
+ *
175
+ * @public
176
+ */
200
177
  function findParentNode(predicate, $pos) {
201
- for (let depth = $pos.depth; depth >= 0; depth -= 1) {
202
- const node = $pos.node(depth);
203
- if (predicate(node)) {
204
- const pos = depth === 0 ? 0 : $pos.before(depth);
205
- const start = $pos.start(depth);
206
- return { node, pos, start, depth };
207
- }
208
- }
209
- }
210
-
211
- // src/utils/find-parent-node-of-type.ts
178
+ for (let depth = $pos.depth; depth >= 0; depth -= 1) {
179
+ const node = $pos.node(depth);
180
+ if (predicate(node)) {
181
+ const pos = depth === 0 ? 0 : $pos.before(depth);
182
+ const start = $pos.start(depth);
183
+ return {
184
+ node,
185
+ pos,
186
+ start,
187
+ depth
188
+ };
189
+ }
190
+ }
191
+ }
192
+
193
+ //#endregion
194
+ //#region src/utils/find-parent-node-of-type.ts
195
+ /**
196
+ * Finds the closest parent node that matches the given node type.
197
+ *
198
+ * @public
199
+ */
212
200
  function findParentNodeOfType(type, $pos) {
213
- const nodeType = getNodeType($pos.doc.type.schema, type);
214
- return findParentNode((node) => node.type === nodeType, $pos);
201
+ const nodeType = getNodeType($pos.doc.type.schema, type);
202
+ return findParentNode((node) => node.type === nodeType, $pos);
215
203
  }
216
204
 
217
- // src/commands/remove-node.ts
205
+ //#endregion
206
+ //#region src/commands/remove-node.ts
207
+ /**
208
+ * Returns a command to remove the nearest ancestor node of a specific type from the current position.
209
+ *
210
+ * @public
211
+ */
218
212
  function removeNode(options) {
219
- return (state, dispatch) => {
220
- const $pos = typeof options.pos === "number" ? state.doc.resolve(options.pos) : state.selection.$anchor;
221
- const found = findParentNodeOfType(options.type, $pos);
222
- if (!found) return false;
223
- const { pos, node } = found;
224
- dispatch?.(state.tr.delete(pos, pos + node.nodeSize));
225
- return true;
226
- };
227
- }
228
-
229
- // src/utils/get-custom-selection.ts
230
- import {
231
- TextSelection as TextSelection4
232
- } from "@prosekit/pm/state";
213
+ return (state, dispatch) => {
214
+ const $pos = typeof options.pos === "number" ? state.doc.resolve(options.pos) : state.selection.$anchor;
215
+ const found = findParentNodeOfType(options.type, $pos);
216
+ if (!found) return false;
217
+ const { pos, node } = found;
218
+ dispatch?.(state.tr.delete(pos, pos + node.nodeSize));
219
+ return true;
220
+ };
221
+ }
222
+
223
+ //#endregion
224
+ //#region src/utils/get-custom-selection.ts
233
225
  function getCustomSelection(state, from, to) {
234
- const pos = from ?? to;
235
- if (pos != null) {
236
- const $from = state.doc.resolve(from ?? pos);
237
- const $to = state.doc.resolve(to ?? pos);
238
- return TextSelection4.between($from, $to);
239
- }
240
- return state.selection;
241
- }
242
-
243
- // src/commands/set-block-type.ts
226
+ const pos = from ?? to;
227
+ if (pos != null) {
228
+ const $from = state.doc.resolve(from ?? pos);
229
+ const $to = state.doc.resolve(to ?? pos);
230
+ return TextSelection.between($from, $to);
231
+ }
232
+ return state.selection;
233
+ }
234
+
235
+ //#endregion
236
+ //#region src/commands/set-block-type.ts
237
+ /**
238
+ * Returns a command that tries to set the selected textblocks to the given node
239
+ * type with the given attributes.
240
+ *
241
+ * @public
242
+ */
244
243
  function setBlockType(options) {
245
- return (state, dispatch) => {
246
- const nodeType = getNodeType(state.schema, options.type);
247
- const selection = getCustomSelection(state, options.from, options.to);
248
- const attrs = options.attrs;
249
- let applicable = false;
250
- for (let i = 0; i < selection.ranges.length && !applicable; i++) {
251
- const {
252
- $from: { pos: from },
253
- $to: { pos: to }
254
- } = selection.ranges[i];
255
- state.doc.nodesBetween(from, to, (node, pos) => {
256
- if (applicable) return false;
257
- if (!node.isTextblock || node.hasMarkup(nodeType, attrs)) return;
258
- if (node.type == nodeType) {
259
- applicable = true;
260
- } else {
261
- const $pos = state.doc.resolve(pos), index = $pos.index();
262
- applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType);
263
- }
264
- });
265
- }
266
- if (!applicable) return false;
267
- if (dispatch) {
268
- const tr = state.tr;
269
- for (const range of selection.ranges) {
270
- const {
271
- $from: { pos: from },
272
- $to: { pos: to }
273
- } = range;
274
- tr.setBlockType(from, to, nodeType, attrs);
275
- }
276
- dispatch(tr.scrollIntoView());
277
- }
278
- return true;
279
- };
280
- }
281
-
282
- // src/utils/get-node-types.ts
244
+ return (state, dispatch) => {
245
+ const nodeType = getNodeType(state.schema, options.type);
246
+ const selection = getCustomSelection(state, options.from, options.to);
247
+ const attrs = options.attrs;
248
+ let applicable = false;
249
+ for (let i = 0; i < selection.ranges.length && !applicable; i++) {
250
+ const { $from: { pos: from }, $to: { pos: to } } = selection.ranges[i];
251
+ state.doc.nodesBetween(from, to, (node, pos) => {
252
+ if (applicable) return false;
253
+ if (!node.isTextblock || node.hasMarkup(nodeType, attrs)) return;
254
+ if (node.type == nodeType) applicable = true;
255
+ else {
256
+ const $pos = state.doc.resolve(pos), index = $pos.index();
257
+ applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType);
258
+ }
259
+ });
260
+ }
261
+ if (!applicable) return false;
262
+ if (dispatch) {
263
+ const tr = state.tr;
264
+ for (const range of selection.ranges) {
265
+ const { $from: { pos: from }, $to: { pos: to } } = range;
266
+ tr.setBlockType(from, to, nodeType, attrs);
267
+ }
268
+ dispatch(tr.scrollIntoView());
269
+ }
270
+ return true;
271
+ };
272
+ }
273
+
274
+ //#endregion
275
+ //#region src/utils/get-node-types.ts
276
+ /**
277
+ * @internal
278
+ */
283
279
  function getNodeTypes(schema, types) {
284
- if (Array.isArray(types)) {
285
- return types.map((type) => getNodeType(schema, type));
286
- }
287
- return [getNodeType(schema, types)];
280
+ if (Array.isArray(types)) return types.map((type) => getNodeType(schema, type));
281
+ return [getNodeType(schema, types)];
288
282
  }
289
283
 
290
- // src/commands/set-node-attrs.ts
284
+ //#endregion
285
+ //#region src/commands/set-node-attrs.ts
286
+ /**
287
+ * Returns a command that set the attributes of the current node.
288
+ *
289
+ * @public
290
+ */
291
291
  function setNodeAttrs(options) {
292
- return (state, dispatch) => {
293
- const nodeTypes = getNodeTypes(state.schema, options.type);
294
- const from = options.pos ?? state.selection.from;
295
- const to = options.pos ?? state.selection.to;
296
- const positions = [];
297
- state.doc.nodesBetween(from, to, (node, pos) => {
298
- if (nodeTypes.includes(node.type)) {
299
- positions.push(pos);
300
- }
301
- if (!dispatch && positions.length > 0) {
302
- return false;
303
- }
304
- });
305
- if (positions.length === 0) {
306
- return false;
307
- }
308
- if (dispatch) {
309
- const { tr } = state;
310
- for (const pos of positions) {
311
- for (const [key, value] of Object.entries(options.attrs)) {
312
- tr.setNodeAttribute(pos, key, value);
313
- }
314
- }
315
- dispatch(tr);
316
- }
317
- return true;
318
- };
319
- }
320
-
321
- // src/commands/toggle-mark.ts
322
- import { toggleMark as baseToggleMark } from "@prosekit/pm/commands";
323
- function toggleMark({
324
- type,
325
- attrs,
326
- removeWhenPresent = false,
327
- enterInlineAtoms = true
328
- }) {
329
- return (state, dispatch, view) => {
330
- return baseToggleMark(getMarkType(state.schema, type), attrs, {
331
- removeWhenPresent,
332
- enterInlineAtoms
333
- })(state, dispatch, view);
334
- };
335
- }
336
-
337
- // src/commands/toggle-node.ts
338
- import { setBlockType as setBlockType2 } from "@prosekit/pm/commands";
292
+ return (state, dispatch) => {
293
+ const nodeTypes = getNodeTypes(state.schema, options.type);
294
+ const from = options.pos ?? state.selection.from;
295
+ const to = options.pos ?? state.selection.to;
296
+ const positions = [];
297
+ state.doc.nodesBetween(from, to, (node, pos) => {
298
+ if (nodeTypes.includes(node.type)) positions.push(pos);
299
+ if (!dispatch && positions.length > 0) return false;
300
+ });
301
+ if (positions.length === 0) return false;
302
+ if (dispatch) {
303
+ const { tr } = state;
304
+ for (const pos of positions) for (const [key, value] of Object.entries(options.attrs)) tr.setNodeAttribute(pos, key, value);
305
+ dispatch(tr);
306
+ }
307
+ return true;
308
+ };
309
+ }
310
+
311
+ //#endregion
312
+ //#region src/commands/toggle-mark.ts
313
+ /**
314
+ * Returns a command that toggles the given mark with the given attributes.
315
+ *
316
+ * @param options
317
+ *
318
+ * @public
319
+ */
320
+ function toggleMark({ type, attrs, removeWhenPresent = false, enterInlineAtoms = true }) {
321
+ return (state, dispatch, view) => {
322
+ return toggleMark$1(getMarkType(state.schema, type), attrs, {
323
+ removeWhenPresent,
324
+ enterInlineAtoms
325
+ })(state, dispatch, view);
326
+ };
327
+ }
328
+
329
+ //#endregion
330
+ //#region src/commands/toggle-node.ts
331
+ /**
332
+ * Returns a command that set the selected textblocks to the given node type
333
+ * with the given attributes.
334
+ *
335
+ * @param options
336
+ *
337
+ * @public
338
+ */
339
339
  function toggleNode({ type, attrs }) {
340
- return (state, dispatch, view) => {
341
- if (isNodeActive(state, type, attrs)) {
342
- const defaultType = state.schema.topNodeType.contentMatch.defaultType;
343
- if (!defaultType) {
344
- return false;
345
- }
346
- return setBlockType2(defaultType)(state, dispatch, view);
347
- } else {
348
- const nodeType = getNodeType(state.schema, type);
349
- return setBlockType2(nodeType, attrs)(state, dispatch, view);
350
- }
351
- };
352
- }
353
-
354
- // src/commands/toggle-wrap.ts
355
- import { lift } from "@prosekit/pm/commands";
356
-
357
- // src/commands/wrap.ts
358
- import { findWrapping } from "@prosekit/pm/transform";
340
+ return (state, dispatch, view) => {
341
+ if (isNodeActive(state, type, attrs)) {
342
+ const defaultType = state.schema.topNodeType.contentMatch.defaultType;
343
+ if (!defaultType) return false;
344
+ return setBlockType$1(defaultType)(state, dispatch, view);
345
+ } else {
346
+ const nodeType = getNodeType(state.schema, type);
347
+ return setBlockType$1(nodeType, attrs)(state, dispatch, view);
348
+ }
349
+ };
350
+ }
351
+
352
+ //#endregion
353
+ //#region src/commands/wrap.ts
354
+ /**
355
+ * Returns a command that wraps the selected textblock with the given node type.
356
+ *
357
+ * @param options
358
+ *
359
+ * @public
360
+ */
359
361
  function wrap(options) {
360
- return (state, dispatch) => {
361
- const { $from, $to } = state.selection;
362
- const range = $from.blockRange($to);
363
- if (!range) return false;
364
- const nodeType = getNodeType(state.schema, options.nodeType || options.type);
365
- const wrapping = findWrapping(range, nodeType, options.attrs);
366
- if (!wrapping) return false;
367
- dispatch?.(state.tr.wrap(range, wrapping));
368
- return true;
369
- };
370
- }
371
-
372
- // src/commands/toggle-wrap.ts
362
+ return (state, dispatch) => {
363
+ const { $from, $to } = state.selection;
364
+ const range = $from.blockRange($to);
365
+ if (!range) return false;
366
+ const nodeType = getNodeType(state.schema, options.nodeType || options.type);
367
+ const wrapping = findWrapping(range, nodeType, options.attrs);
368
+ if (!wrapping) return false;
369
+ dispatch?.(state.tr.wrap(range, wrapping));
370
+ return true;
371
+ };
372
+ }
373
+
374
+ //#endregion
375
+ //#region src/commands/toggle-wrap.ts
376
+ /**
377
+ * Toggle between wrapping an inactive node with the provided node type, and
378
+ * lifting it up into it's parent.
379
+ *
380
+ * @param options
381
+ *
382
+ * @public
383
+ */
373
384
  function toggleWrap(options) {
374
- const { type, attrs } = options;
375
- return (state, dispatch) => {
376
- if (isNodeActive(state, type, attrs)) {
377
- return lift(state, dispatch);
378
- }
379
- return wrap({ type, attrs })(state, dispatch);
380
- };
381
- }
382
-
383
- // src/commands/unset-block-type.ts
384
- import {
385
- Fragment,
386
- Slice
387
- } from "@prosekit/pm/model";
388
- import { ReplaceAroundStep } from "@prosekit/pm/transform";
385
+ const { type, attrs } = options;
386
+ return (state, dispatch) => {
387
+ if (isNodeActive(state, type, attrs)) return lift(state, dispatch);
388
+ return wrap({
389
+ type,
390
+ attrs
391
+ })(state, dispatch);
392
+ };
393
+ }
394
+
395
+ //#endregion
396
+ //#region src/commands/unset-block-type.ts
397
+ /**
398
+ * Returns a command that set the type of all textblocks between the given range
399
+ * to the default type (usually `paragraph`).
400
+ *
401
+ * @public
402
+ */
389
403
  function unsetBlockType(options) {
390
- return (state, dispatch) => {
391
- const from = options?.from ?? state.selection.from;
392
- const to = options?.to ?? state.selection.to;
393
- if (from > to) return false;
394
- const tr = state.tr;
395
- if (unsetTextBlockType(tr, from, to)) {
396
- dispatch?.(tr);
397
- return true;
398
- }
399
- return false;
400
- };
404
+ return (state, dispatch) => {
405
+ const from = options?.from ?? state.selection.from;
406
+ const to = options?.to ?? state.selection.to;
407
+ if (from > to) return false;
408
+ const tr = state.tr;
409
+ if (unsetTextBlockType(tr, from, to)) {
410
+ dispatch?.(tr);
411
+ return true;
412
+ }
413
+ return false;
414
+ };
401
415
  }
402
416
  function unsetTextBlockType(tr, from, to) {
403
- const mapFrom = tr.steps.length;
404
- tr.doc.nodesBetween(from, to, (node, pos, parent, index) => {
405
- if (!parent || !node.isTextblock) return true;
406
- const defaultType = parent.contentMatchAt(index).defaultType;
407
- if (defaultType && defaultType.isTextblock && node.type !== defaultType && defaultType.validContent(node.content)) {
408
- const mapping = tr.mapping.slice(mapFrom);
409
- const start = mapping.map(pos, 1);
410
- const end = mapping.map(pos + node.nodeSize, 1);
411
- const step = new ReplaceAroundStep(
412
- start,
413
- end,
414
- start + 1,
415
- end - 1,
416
- new Slice(Fragment.from(defaultType.create()), 0, 0),
417
- 1,
418
- true
419
- );
420
- tr.step(step);
421
- }
422
- return false;
423
- });
424
- return tr.steps.length > mapFrom;
425
- }
426
-
427
- // src/commands/unset-mark.ts
417
+ const mapFrom = tr.steps.length;
418
+ tr.doc.nodesBetween(from, to, (node, pos, parent, index) => {
419
+ if (!parent || !node.isTextblock) return true;
420
+ const defaultType = parent.contentMatchAt(index).defaultType;
421
+ if (defaultType && defaultType.isTextblock && node.type !== defaultType && defaultType.validContent(node.content)) {
422
+ const mapping = tr.mapping.slice(mapFrom);
423
+ const start = mapping.map(pos, 1);
424
+ const end = mapping.map(pos + node.nodeSize, 1);
425
+ const step = new ReplaceAroundStep(start, end, start + 1, end - 1, new Slice(Fragment.from(defaultType.create()), 0, 0), 1, true);
426
+ tr.step(step);
427
+ }
428
+ return false;
429
+ });
430
+ return tr.steps.length > mapFrom;
431
+ }
432
+
433
+ //#endregion
434
+ //#region src/commands/unset-mark.ts
435
+ /**
436
+ * Returns a command that removes all marks.
437
+ *
438
+ * @public
439
+ */
428
440
  function unsetMark(options) {
429
- return (state, dispatch) => {
430
- const from = options?.from ?? state.selection.from;
431
- const to = options?.to ?? state.selection.to;
432
- if (from > to) return false;
433
- dispatch?.(state.tr.removeMark(from, to));
434
- return true;
435
- };
436
- }
437
-
438
- // src/editor/with-priority.ts
441
+ return (state, dispatch) => {
442
+ const from = options?.from ?? state.selection.from;
443
+ const to = options?.to ?? state.selection.to;
444
+ if (from > to) return false;
445
+ dispatch?.(state.tr.removeMark(from, to));
446
+ return true;
447
+ };
448
+ }
449
+
450
+ //#endregion
451
+ //#region src/editor/with-priority.ts
452
+ /**
453
+ * Return an new extension with the given priority.
454
+ *
455
+ * @example
456
+ * ```ts
457
+ * import { Priority, withPriority } from 'prosekit/core'
458
+ *
459
+ * const extension = withPriority(defineMyExtension(), Priority.high)
460
+ * ```
461
+ *
462
+ * @public
463
+ */
439
464
  function withPriority(extension, priority) {
440
- const result = union(extension);
441
- result.priority = priority;
442
- return result;
443
- }
444
-
445
- // src/extensions/clipboard-serializer.ts
446
- import {
447
- DOMSerializer
448
- } from "@prosekit/pm/model";
449
- import {
450
- PluginKey,
451
- ProseMirrorPlugin
452
- } from "@prosekit/pm/state";
453
-
454
- // src/extensions/plugin.ts
455
- import {
456
- Plugin
457
- } from "@prosekit/pm/state";
465
+ const result = union(extension);
466
+ result.priority = priority;
467
+ return result;
468
+ }
469
+
470
+ //#endregion
471
+ //#region src/extensions/plugin.ts
472
+ /**
473
+ * Adds a ProseMirror plugin to the editor.
474
+ *
475
+ * @param plugin - The ProseMirror plugin to add, or an array of plugins, or a
476
+ * function that returns one or multiple plugins.
477
+ *
478
+ * @public
479
+ */
458
480
  function definePlugin(plugin) {
459
- if (plugin instanceof Plugin || Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin)) {
460
- return definePluginPayload(() => plugin);
461
- }
462
- if (typeof plugin === "function") {
463
- return definePluginPayload(plugin);
464
- }
465
- throw new TypeError("Invalid plugin");
481
+ if (plugin instanceof Plugin || Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin)) return definePluginPayload(() => plugin);
482
+ if (typeof plugin === "function") return definePluginPayload(plugin);
483
+ throw new TypeError("Invalid plugin");
466
484
  }
467
485
  function definePluginPayload(payload) {
468
- return defineFacetPayload(pluginFacet, [payload]);
469
- }
470
- var pluginFacet = defineFacet({
471
- reducer: (payloads) => {
472
- return ({ schema }) => {
473
- const plugins = [];
474
- for (const payload of payloads) {
475
- if (payload instanceof Plugin) {
476
- plugins.push(payload);
477
- } else if (Array.isArray(payload) && payload.every((p) => p instanceof Plugin)) {
478
- plugins.push(...payload);
479
- } else if (typeof payload === "function") {
480
- plugins.push(...[payload({ schema })].flat());
481
- } else {
482
- throw new ProseKitError("Invalid plugin");
483
- }
484
- }
485
- plugins.reverse();
486
- return { plugins };
487
- };
488
- },
489
- parent: stateFacet
486
+ return defineFacetPayload(pluginFacet, [payload]);
487
+ }
488
+ /**
489
+ * @internal
490
+ */
491
+ const pluginFacet = defineFacet({
492
+ reducer: (payloads) => {
493
+ return ({ schema }) => {
494
+ const plugins = [];
495
+ for (const payload of payloads) if (payload instanceof Plugin) plugins.push(payload);
496
+ else if (Array.isArray(payload) && payload.every((p) => p instanceof Plugin)) plugins.push(...payload);
497
+ else if (typeof payload === "function") plugins.push(...[payload({ schema })].flat());
498
+ else throw new ProseKitError("Invalid plugin");
499
+ plugins.reverse();
500
+ return { plugins };
501
+ };
502
+ },
503
+ parent: stateFacet
490
504
  });
491
505
 
492
- // src/extensions/clipboard-serializer.ts
506
+ //#endregion
507
+ //#region src/extensions/clipboard-serializer.ts
493
508
  function mergeWrappers(wrappers) {
494
- return (fn) => wrappers.filter(isNotNullish).reduce((fn2, wrapper) => wrapper(fn2), fn);
509
+ return (fn) => wrappers.filter(isNotNullish).reduce((fn$1, wrapper) => wrapper(fn$1), fn);
495
510
  }
496
511
  function wrapFunction(fn, wrapper) {
497
- return wrapper ? wrapper(fn) : fn;
512
+ return wrapper ? wrapper(fn) : fn;
498
513
  }
499
514
  var CustomDOMSerializer = class extends DOMSerializer {
500
- constructor(nodes, marks, serializeFragmentWrapper, serializeNodeWrapper) {
501
- super(nodes, marks);
502
- this.serializeFragmentWrapper = serializeFragmentWrapper;
503
- this.serializeNodeWrapper = serializeNodeWrapper;
504
- }
505
- serializeFragment(...args) {
506
- const fn = (...args2) => super.serializeFragment(...args2);
507
- return wrapFunction(fn, this.serializeFragmentWrapper)(...args);
508
- }
509
- serializeNode(...args) {
510
- const fn = (...args2) => super.serializeNode(...args2);
511
- return wrapFunction(fn, this.serializeNodeWrapper)(...args);
512
- }
515
+ constructor(nodes, marks, serializeFragmentWrapper, serializeNodeWrapper) {
516
+ super(nodes, marks);
517
+ this.serializeFragmentWrapper = serializeFragmentWrapper;
518
+ this.serializeNodeWrapper = serializeNodeWrapper;
519
+ }
520
+ serializeFragment(...args) {
521
+ const fn = (...args$1) => super.serializeFragment(...args$1);
522
+ return wrapFunction(fn, this.serializeFragmentWrapper)(...args);
523
+ }
524
+ serializeNode(...args) {
525
+ const fn = (...args$1) => super.serializeNode(...args$1);
526
+ return wrapFunction(fn, this.serializeNodeWrapper)(...args);
527
+ }
513
528
  };
514
529
  function createCustomDOMSerializer(schema, options) {
515
- const nodesFromSchema = (...args) => DOMSerializer.nodesFromSchema(...args);
516
- const marksFromSchema = (...args) => DOMSerializer.marksFromSchema(...args);
517
- const nodes = wrapFunction(nodesFromSchema, options.nodesFromSchemaWrapper)(schema);
518
- const marks = wrapFunction(marksFromSchema, options.marksFromSchemaWrapper)(schema);
519
- return new CustomDOMSerializer(nodes, marks, options.serializeFragmentWrapper, options.serializeNodeWrapper);
520
- }
521
- var clipboardSerializerFacet = defineFacet({
522
- reducer: (inputs) => {
523
- const options = {
524
- serializeFragmentWrapper: mergeWrappers(inputs.map((input) => input.serializeFragmentWrapper)),
525
- serializeNodeWrapper: mergeWrappers(inputs.map((input) => input.serializeNodeWrapper)),
526
- nodesFromSchemaWrapper: mergeWrappers(inputs.map((input) => input.nodesFromSchemaWrapper)),
527
- marksFromSchemaWrapper: mergeWrappers(inputs.map((input) => input.marksFromSchemaWrapper))
528
- };
529
- return ({ schema }) => {
530
- const clipboardSerializer = createCustomDOMSerializer(schema, options);
531
- return [
532
- new ProseMirrorPlugin({
533
- key: new PluginKey("prosekit-clipboard-serializer"),
534
- props: { clipboardSerializer }
535
- })
536
- ];
537
- };
538
- },
539
- singleton: true,
540
- parent: pluginFacet
530
+ const nodesFromSchema = (...args) => DOMSerializer.nodesFromSchema(...args);
531
+ const marksFromSchema = (...args) => DOMSerializer.marksFromSchema(...args);
532
+ const nodes = wrapFunction(nodesFromSchema, options.nodesFromSchemaWrapper)(schema);
533
+ const marks = wrapFunction(marksFromSchema, options.marksFromSchemaWrapper)(schema);
534
+ return new CustomDOMSerializer(nodes, marks, options.serializeFragmentWrapper, options.serializeNodeWrapper);
535
+ }
536
+ const clipboardSerializerFacet = defineFacet({
537
+ reducer: (inputs) => {
538
+ const options = {
539
+ serializeFragmentWrapper: mergeWrappers(inputs.map((input) => input.serializeFragmentWrapper)),
540
+ serializeNodeWrapper: mergeWrappers(inputs.map((input) => input.serializeNodeWrapper)),
541
+ nodesFromSchemaWrapper: mergeWrappers(inputs.map((input) => input.nodesFromSchemaWrapper)),
542
+ marksFromSchemaWrapper: mergeWrappers(inputs.map((input) => input.marksFromSchemaWrapper))
543
+ };
544
+ return ({ schema }) => {
545
+ const clipboardSerializer = createCustomDOMSerializer(schema, options);
546
+ return [new ProseMirrorPlugin({
547
+ key: new PluginKey("prosekit-clipboard-serializer"),
548
+ props: { clipboardSerializer }
549
+ })];
550
+ };
551
+ },
552
+ singleton: true,
553
+ parent: pluginFacet
541
554
  });
555
+ /**
556
+ * @internal
557
+ */
542
558
  function defineClipboardSerializer(options) {
543
- return defineFacetPayload(clipboardSerializerFacet, [options]);
559
+ return defineFacetPayload(clipboardSerializerFacet, [options]);
544
560
  }
545
561
 
546
- // src/commands/insert-text.ts
562
+ //#endregion
563
+ //#region src/commands/insert-text.ts
564
+ /**
565
+ * Returns a command that inserts the given text.
566
+ *
567
+ * @public
568
+ */
547
569
  function insertText({ text, from, to }) {
548
- return (state, dispatch) => {
549
- if (text) {
550
- dispatch?.(state.tr.insertText(text, from, to));
551
- }
552
- return true;
553
- };
554
- }
555
-
556
- // src/commands/select-all.ts
557
- import {
558
- AllSelection
559
- } from "@prosekit/pm/state";
570
+ return (state, dispatch) => {
571
+ if (text) dispatch?.(state.tr.insertText(text, from, to));
572
+ return true;
573
+ };
574
+ }
575
+
576
+ //#endregion
577
+ //#region src/commands/select-all.ts
578
+ /**
579
+ * Returns a command that selects the whole document.
580
+ *
581
+ * @public
582
+ */
560
583
  function selectAll() {
561
- return (state, dispatch) => {
562
- dispatch?.(state.tr.setSelection(new AllSelection(state.doc)));
563
- return true;
564
- };
565
- }
566
-
567
- // src/facets/command.ts
568
- var commandFacet = defineFacet({
569
- reducer: (inputs) => {
570
- const commands2 = Object.assign({}, ...inputs);
571
- return { commands: commands2 };
572
- },
573
- parent: rootFacet,
574
- singleton: true
584
+ return (state, dispatch) => {
585
+ dispatch?.(state.tr.setSelection(new AllSelection(state.doc)));
586
+ return true;
587
+ };
588
+ }
589
+
590
+ //#endregion
591
+ //#region src/facets/command.ts
592
+ const commandFacet = defineFacet({
593
+ reducer: (inputs) => {
594
+ const commands$1 = Object.assign({}, ...inputs);
595
+ return { commands: commands$1 };
596
+ },
597
+ parent: rootFacet,
598
+ singleton: true
575
599
  });
576
600
 
577
- // src/extensions/command.ts
578
- function defineCommands(commands2) {
579
- return defineFacetPayload(commandFacet, [commands2]);
601
+ //#endregion
602
+ //#region src/extensions/command.ts
603
+ function defineCommands(commands$1) {
604
+ return defineFacetPayload(commandFacet, [commands$1]);
580
605
  }
606
+ /**
607
+ * Add some base commands
608
+ *
609
+ * @public
610
+ */
581
611
  function defineBaseCommands() {
582
- return defineCommands({
583
- insertText,
584
- insertNode,
585
- removeNode,
586
- wrap,
587
- toggleWrap,
588
- setBlockType,
589
- setNodeAttrs,
590
- insertDefaultBlock,
591
- selectAll,
592
- addMark,
593
- removeMark,
594
- unsetBlockType,
595
- unsetMark
596
- });
597
- }
598
-
599
- // src/extensions/node-spec.ts
600
- import clone from "just-clone";
601
- import OrderedMap2 from "orderedmap";
602
-
603
- // src/facets/schema-spec.ts
604
- import OrderedMap from "orderedmap";
605
- var schemaSpecFacet = defineFacet({
606
- reducer: (specs) => {
607
- let nodes = OrderedMap.from({});
608
- let marks = OrderedMap.from({});
609
- let topNode = void 0;
610
- for (const spec of specs) {
611
- nodes = nodes.append(spec.nodes);
612
- marks = marks.append(spec.marks ?? {});
613
- topNode = topNode ?? spec.topNode;
614
- }
615
- return { nodes, marks, topNode };
616
- },
617
- parent: schemaFacet,
618
- singleton: true
612
+ return defineCommands({
613
+ insertText,
614
+ insertNode,
615
+ removeNode,
616
+ wrap,
617
+ toggleWrap,
618
+ setBlockType,
619
+ setNodeAttrs,
620
+ insertDefaultBlock,
621
+ selectAll,
622
+ addMark,
623
+ removeMark,
624
+ unsetBlockType,
625
+ unsetMark
626
+ });
627
+ }
628
+
629
+ //#endregion
630
+ //#region src/facets/schema-spec.ts
631
+ const schemaSpecFacet = defineFacet({
632
+ reducer: (specs) => {
633
+ let nodes = OrderedMap.from({});
634
+ let marks = OrderedMap.from({});
635
+ let topNode = void 0;
636
+ for (const spec of specs) {
637
+ nodes = nodes.append(spec.nodes);
638
+ marks = marks.append(spec.marks ?? {});
639
+ topNode = topNode ?? spec.topNode;
640
+ }
641
+ return {
642
+ nodes,
643
+ marks,
644
+ topNode
645
+ };
646
+ },
647
+ parent: schemaFacet,
648
+ singleton: true
619
649
  });
620
650
 
621
- // src/utils/array-grouping.ts
651
+ //#endregion
652
+ //#region src/utils/array-grouping.ts
622
653
  function groupBy(items, keySelector) {
623
- const result = {};
624
- for (const item of items) {
625
- const key = keySelector(item);
626
- const values = result[key] || (result[key] = []);
627
- values.push(item);
628
- }
629
- return result;
654
+ const result = {};
655
+ for (const item of items) {
656
+ const key = keySelector(item);
657
+ const values = result[key] ||= [];
658
+ values.push(item);
659
+ }
660
+ return result;
630
661
  }
631
662
  function groupEntries(entries) {
632
- const result = {};
633
- for (const [key, value] of entries) {
634
- const values = result[key] || (result[key] = []);
635
- values.push(value);
636
- }
637
- return result;
663
+ const result = {};
664
+ for (const [key, value] of entries) {
665
+ const values = result[key] ||= [];
666
+ values.push(value);
667
+ }
668
+ return result;
638
669
  }
639
670
 
640
- // src/utils/remove-undefined-values.ts
671
+ //#endregion
672
+ //#region src/utils/remove-undefined-values.ts
641
673
  function removeUndefinedValues(obj) {
642
- const result = {};
643
- for (const [key, value] of Object.entries(obj)) {
644
- if (value !== void 0) {
645
- result[key] = value;
646
- }
647
- }
648
- return result;
674
+ const result = {};
675
+ for (const [key, value] of Object.entries(obj)) if (value !== void 0) result[key] = value;
676
+ return result;
649
677
  }
650
678
 
651
- // src/utils/merge-objects.ts
679
+ //#endregion
680
+ //#region src/utils/merge-objects.ts
652
681
  function mergeObjects(...objects) {
653
- const filteredObjects = objects.filter(isNotNullish).map(removeUndefinedValues);
654
- return Object.assign({}, ...filteredObjects);
682
+ const filteredObjects = objects.filter(isNotNullish).map(removeUndefinedValues);
683
+ return Object.assign({}, ...filteredObjects);
655
684
  }
656
685
 
657
- // src/utils/merge-specs.ts
686
+ //#endregion
687
+ //#region src/utils/merge-specs.ts
658
688
  function mergeSpecs(a, b) {
659
- const attrs = {};
660
- const attrNames = /* @__PURE__ */ new Set([
661
- ...Object.keys(a.attrs ?? {}),
662
- ...Object.keys(b.attrs ?? {})
663
- ]);
664
- for (const name of attrNames) {
665
- const attrSpecA = a.attrs?.[name];
666
- const attrSpecB = b.attrs?.[name];
667
- const attrSpecMerged = mergeObjects(attrSpecA, attrSpecB);
668
- if (attrSpecMerged) {
669
- attrs[name] = attrSpecMerged;
670
- }
671
- }
672
- const parseDOM = [...a.parseDOM ?? [], ...b.parseDOM ?? []];
673
- return mergeObjects(a, b, { attrs, parseDOM });
674
- }
675
-
676
- // src/utils/output-spec.ts
689
+ const attrs = {};
690
+ const attrNames = new Set([...Object.keys(a.attrs ?? {}), ...Object.keys(b.attrs ?? {})]);
691
+ for (const name of attrNames) {
692
+ const attrSpecA = a.attrs?.[name];
693
+ const attrSpecB = b.attrs?.[name];
694
+ const attrSpecMerged = mergeObjects(attrSpecA, attrSpecB);
695
+ if (attrSpecMerged) attrs[name] = attrSpecMerged;
696
+ }
697
+ const parseDOM = [...a.parseDOM ?? [], ...b.parseDOM ?? []];
698
+ return mergeObjects(a, b, {
699
+ attrs,
700
+ parseDOM
701
+ });
702
+ }
703
+
704
+ //#endregion
705
+ //#region src/utils/output-spec.ts
677
706
  function wrapOutputSpecAttrs(toDOM, options) {
678
- return (node, ...args) => {
679
- const dom = toDOM(node, ...args);
680
- const pairs = options.map((option) => option.toDOM?.(node.attrs[option.attr])).filter(isNotNullish);
681
- return insertOutputSpecAttrs(dom, pairs);
682
- };
707
+ return (node, ...args) => {
708
+ const dom = toDOM(node, ...args);
709
+ const pairs = options.map((option) => option.toDOM?.(node.attrs[option.attr])).filter(isNotNullish);
710
+ return insertOutputSpecAttrs(dom, pairs);
711
+ };
683
712
  }
684
713
  function wrapTagParseRuleAttrs(rule, options) {
685
- const existingGetAttrs = rule.getAttrs;
686
- const existingAttrs = rule.attrs;
687
- return {
688
- ...rule,
689
- getAttrs: (dom) => {
690
- const baseAttrs = existingGetAttrs?.(dom) ?? existingAttrs ?? {};
691
- if (baseAttrs === false || !dom || !isElement(dom)) {
692
- return baseAttrs ?? null;
693
- }
694
- const insertedAttrs = {};
695
- for (const option of options) {
696
- if (option.parseDOM) {
697
- insertedAttrs[option.attr] = option.parseDOM(dom);
698
- }
699
- }
700
- return { ...baseAttrs, ...insertedAttrs };
701
- }
702
- };
714
+ const existingGetAttrs = rule.getAttrs;
715
+ const existingAttrs = rule.attrs;
716
+ return {
717
+ ...rule,
718
+ getAttrs: (dom) => {
719
+ const baseAttrs = existingGetAttrs?.(dom) ?? existingAttrs ?? {};
720
+ if (baseAttrs === false || !dom || !isElementLike(dom)) return baseAttrs ?? null;
721
+ const insertedAttrs = {};
722
+ for (const option of options) if (option.parseDOM) insertedAttrs[option.attr] = option.parseDOM(dom);
723
+ return {
724
+ ...baseAttrs,
725
+ ...insertedAttrs
726
+ };
727
+ }
728
+ };
703
729
  }
704
730
  function insertOutputSpecAttrs(dom, attrs) {
705
- if (!dom) {
706
- return dom;
707
- }
708
- if (Array.isArray(dom)) {
709
- const rest = dom.slice(1);
710
- let oldAttrs;
711
- if (rest.length > 0 && (rest[0] == null || typeof rest[0] === "object")) {
712
- oldAttrs = rest.shift();
713
- } else {
714
- oldAttrs = {};
715
- }
716
- const newAttrs = setObjectAttributes(oldAttrs, attrs);
717
- return [dom[0], newAttrs, ...rest];
718
- }
719
- if (isElement(dom)) {
720
- return setElementAttributes(dom, attrs);
721
- }
722
- if (typeof dom === "object" && "dom" in dom && isElement(dom.dom)) {
723
- return { ...dom, dom: setElementAttributes(dom.dom, attrs) };
724
- }
725
- return dom;
731
+ if (!dom) return dom;
732
+ if (Array.isArray(dom)) {
733
+ const rest = dom.slice(1);
734
+ let oldAttrs;
735
+ if (rest.length > 0 && (rest[0] == null || typeof rest[0] === "object")) oldAttrs = rest.shift();
736
+ else oldAttrs = {};
737
+ const newAttrs = setObjectAttributes(oldAttrs, attrs);
738
+ return [
739
+ dom[0],
740
+ newAttrs,
741
+ ...rest
742
+ ];
743
+ }
744
+ if (isElementLike(dom)) return setElementAttributes(dom, attrs);
745
+ if (typeof dom === "object" && "dom" in dom && isElementLike(dom.dom)) return {
746
+ ...dom,
747
+ dom: setElementAttributes(dom.dom, attrs)
748
+ };
749
+ return dom;
726
750
  }
727
751
  function setObjectAttributes(obj, attrs) {
728
- obj = { ...obj };
729
- for (const [key, value] of attrs) {
730
- const oldValue = obj[key];
731
- const newValue = key === "style" ? joinStyles(value, typeof oldValue === "string" ? oldValue : "") : value;
732
- obj[key] = newValue;
733
- }
734
- return obj;
752
+ obj = { ...obj };
753
+ for (const [key, value] of attrs) {
754
+ const oldValue = obj[key];
755
+ const newValue = key === "style" ? joinStyles(value, typeof oldValue === "string" ? oldValue : "") : value;
756
+ obj[key] = newValue;
757
+ }
758
+ return obj;
735
759
  }
736
760
  function setElementAttributes(element, attrs) {
737
- element = element.cloneNode(true);
738
- for (const [key, value] of attrs) {
739
- const oldValue = element.getAttribute(key);
740
- const newValue = key === "style" ? joinStyles(value, typeof oldValue === "string" ? oldValue : "") : value;
741
- element.setAttribute(key, newValue);
742
- }
743
- return element;
761
+ element = element.cloneNode(true);
762
+ for (const [key, value] of attrs) {
763
+ const oldValue = element.getAttribute(key);
764
+ const newValue = key === "style" ? joinStyles(value, typeof oldValue === "string" ? oldValue : "") : value;
765
+ element.setAttribute(key, newValue);
766
+ }
767
+ return element;
744
768
  }
745
769
  function joinStyles(...styles) {
746
- return styles.map((style) => style.trim().replace(/;$/, "")).filter(Boolean).join("; ");
770
+ return styles.map((style) => style.trim().replace(/;$/, "")).filter(Boolean).join("; ");
747
771
  }
748
772
 
749
- // src/extensions/node-spec.ts
773
+ //#endregion
774
+ //#region src/extensions/node-spec.ts
775
+ /**
776
+ * Defines a node type.
777
+ *
778
+ * @public
779
+ */
750
780
  function defineNodeSpec(options) {
751
- const payload = [options, void 0];
752
- return defineFacetPayload(nodeSpecFacet, [payload]);
753
- }
781
+ const payload = [options, void 0];
782
+ return defineFacetPayload(nodeSpecFacet, [payload]);
783
+ }
784
+ /**
785
+ * Defines an attribute for a node type.
786
+ *
787
+ * @public
788
+ */
754
789
  function defineNodeAttr(options) {
755
- const payload = [void 0, options];
756
- return defineFacetPayload(nodeSpecFacet, [payload]);
757
- }
758
- var nodeSpecFacet = defineFacet({
759
- reducer: (payloads) => {
760
- let specs = OrderedMap2.from({});
761
- let topNodeName = void 0;
762
- const specPayloads = payloads.map((input) => input[0]).filter(isNotNullish);
763
- const attrPayloads = payloads.map((input) => input[1]).filter(isNotNullish);
764
- for (const { name, topNode, ...spec } of specPayloads) {
765
- if (topNode) {
766
- topNodeName = name;
767
- }
768
- const prevSpec = specs.get(name);
769
- if (prevSpec) {
770
- specs = specs.update(name, mergeSpecs(prevSpec, spec));
771
- } else {
772
- specs = specs.addToStart(name, spec);
773
- }
774
- }
775
- const groupedAttrs = groupBy(attrPayloads, (payload) => payload.type);
776
- for (const [type, attrs] of Object.entries(groupedAttrs)) {
777
- if (!attrs) continue;
778
- const maybeSpec = specs.get(type);
779
- assert(maybeSpec, `Node type ${type} must be defined`);
780
- const spec = clone(maybeSpec);
781
- if (!spec.attrs) {
782
- spec.attrs = {};
783
- }
784
- for (const attr of attrs) {
785
- spec.attrs[attr.attr] = {
786
- default: attr.default,
787
- validate: attr.validate,
788
- splittable: attr.splittable
789
- };
790
- }
791
- if (spec.toDOM) {
792
- spec.toDOM = wrapOutputSpecAttrs(spec.toDOM, attrs);
793
- }
794
- if (spec.parseDOM) {
795
- spec.parseDOM = spec.parseDOM.map((rule) => wrapTagParseRuleAttrs(rule, attrs));
796
- }
797
- specs = specs.update(type, spec);
798
- }
799
- return { nodes: specs, topNode: topNodeName };
800
- },
801
- parent: schemaSpecFacet,
802
- singleton: true
790
+ const payload = [void 0, options];
791
+ return defineFacetPayload(nodeSpecFacet, [payload]);
792
+ }
793
+ const nodeSpecFacet = defineFacet({
794
+ reducer: (payloads) => {
795
+ let specs = OrderedMap.from({});
796
+ let topNodeName = void 0;
797
+ const specPayloads = payloads.map((input) => input[0]).filter(isNotNullish);
798
+ const attrPayloads = payloads.map((input) => input[1]).filter(isNotNullish);
799
+ for (const { name, topNode,...spec } of specPayloads) {
800
+ if (topNode) topNodeName = name;
801
+ const prevSpec = specs.get(name);
802
+ if (prevSpec) specs = specs.update(name, mergeSpecs(prevSpec, spec));
803
+ else specs = specs.addToStart(name, spec);
804
+ }
805
+ const groupedAttrs = groupBy(attrPayloads, (payload) => payload.type);
806
+ for (const [type, attrs] of Object.entries(groupedAttrs)) {
807
+ if (!attrs) continue;
808
+ const maybeSpec = specs.get(type);
809
+ assert(maybeSpec, `Node type ${type} must be defined`);
810
+ const spec = clone(maybeSpec);
811
+ if (!spec.attrs) spec.attrs = {};
812
+ for (const attr of attrs) spec.attrs[attr.attr] = {
813
+ default: attr.default,
814
+ validate: attr.validate,
815
+ splittable: attr.splittable
816
+ };
817
+ if (spec.toDOM) spec.toDOM = wrapOutputSpecAttrs(spec.toDOM, attrs);
818
+ if (spec.parseDOM) spec.parseDOM = spec.parseDOM.map((rule) => wrapTagParseRuleAttrs(rule, attrs));
819
+ specs = specs.update(type, spec);
820
+ }
821
+ return {
822
+ nodes: specs,
823
+ topNode: topNodeName
824
+ };
825
+ },
826
+ parent: schemaSpecFacet,
827
+ singleton: true
803
828
  });
804
829
 
805
- // src/extensions/doc.ts
830
+ //#endregion
831
+ //#region src/extensions/doc.ts
832
+ /**
833
+ * @public
834
+ *
835
+ * @deprecated Use the following import instead:
836
+ *
837
+ * ```ts
838
+ * import { defineDoc } from 'prosekit/extensions/doc'
839
+ * ```
840
+ */
806
841
  function defineDoc() {
807
- console.warn(
808
- '[prosekit] The `defineDoc` function from `prosekit/core` is deprecated. Use the following import instead: `import { defineDoc } from "prosekit/extensions/doc"`.'
809
- );
810
- return defineNodeSpec({
811
- name: "doc",
812
- content: "block+",
813
- topNode: true
814
- });
815
- }
816
-
817
- // src/extensions/events/plugin-view.ts
818
- import {
819
- PluginKey as PluginKey2,
820
- ProseMirrorPlugin as ProseMirrorPlugin2
821
- } from "@prosekit/pm/state";
842
+ console.warn("[prosekit] The `defineDoc` function from `prosekit/core` is deprecated. Use the following import instead: `import { defineDoc } from \"prosekit/extensions/doc\"`.");
843
+ return defineNodeSpec({
844
+ name: "doc",
845
+ content: "block+",
846
+ topNode: true
847
+ });
848
+ }
849
+
850
+ //#endregion
851
+ //#region src/extensions/events/plugin-view.ts
852
+ /**
853
+ * Registers a event handler that is called when the editor view is mounted.
854
+ *
855
+ * @public
856
+ */
822
857
  function defineMountHandler(handler) {
823
- return definePluginViewFacetPayload(["mount", handler]);
858
+ return definePluginViewFacetPayload(["mount", handler]);
824
859
  }
860
+ /**
861
+ * Registers a event handler that is called when the editor state is updated.
862
+ *
863
+ * @public
864
+ */
825
865
  function defineUpdateHandler(handler) {
826
- return definePluginViewFacetPayload(["update", handler]);
866
+ return definePluginViewFacetPayload(["update", handler]);
827
867
  }
868
+ /**
869
+ * Registers a event handler that is called when the editor view is unmounted.
870
+ *
871
+ * @public
872
+ */
828
873
  function defineUnmountHandler(handler) {
829
- return definePluginViewFacetPayload(["unmount", handler]);
874
+ return definePluginViewFacetPayload(["unmount", handler]);
830
875
  }
831
876
  function definePluginViewFacetPayload(input) {
832
- return defineFacetPayload(pluginViewFacet, [input]);
833
- }
834
- var pluginViewFacet = defineFacet({
835
- reduce: () => {
836
- let mountHandlers = [];
837
- let updateHandlers = [];
838
- let unmountHandlers = [];
839
- const plugin = new ProseMirrorPlugin2({
840
- key: pluginKey,
841
- view: (view) => {
842
- mountHandlers.forEach((fn) => fn(view));
843
- return {
844
- update: (view2, prevState) => {
845
- updateHandlers.forEach((fn) => fn(view2, prevState));
846
- },
847
- destroy: () => {
848
- unmountHandlers.forEach((fn) => fn());
849
- }
850
- };
851
- }
852
- });
853
- const register = (input) => {
854
- mountHandlers = [];
855
- updateHandlers = [];
856
- unmountHandlers = [];
857
- for (const args of input) {
858
- switch (args[0]) {
859
- case "mount":
860
- mountHandlers.push(args[1]);
861
- break;
862
- case "update":
863
- updateHandlers.push(args[1]);
864
- break;
865
- case "unmount":
866
- unmountHandlers.push(args[1]);
867
- break;
868
- }
869
- }
870
- };
871
- return function reducer(input) {
872
- register(input);
873
- return plugin;
874
- };
875
- },
876
- parent: pluginFacet,
877
- singleton: true
877
+ return defineFacetPayload(pluginViewFacet, [input]);
878
+ }
879
+ const pluginViewFacet = defineFacet({
880
+ reduce: () => {
881
+ let mountHandlers = [];
882
+ let updateHandlers = [];
883
+ let unmountHandlers = [];
884
+ const plugin = new ProseMirrorPlugin({
885
+ key: pluginKey,
886
+ view: (view) => {
887
+ mountHandlers.forEach((fn) => fn(view));
888
+ return {
889
+ update: (view$1, prevState) => {
890
+ updateHandlers.forEach((fn) => fn(view$1, prevState));
891
+ },
892
+ destroy: () => {
893
+ unmountHandlers.forEach((fn) => fn());
894
+ }
895
+ };
896
+ }
897
+ });
898
+ const register = (input) => {
899
+ mountHandlers = [];
900
+ updateHandlers = [];
901
+ unmountHandlers = [];
902
+ for (const args of input) switch (args[0]) {
903
+ case "mount":
904
+ mountHandlers.push(args[1]);
905
+ break;
906
+ case "update":
907
+ updateHandlers.push(args[1]);
908
+ break;
909
+ case "unmount":
910
+ unmountHandlers.push(args[1]);
911
+ break;
912
+ }
913
+ };
914
+ return function reducer(input) {
915
+ register(input);
916
+ return plugin;
917
+ };
918
+ },
919
+ parent: pluginFacet,
920
+ singleton: true
878
921
  });
879
- var pluginKey = new PluginKey2("prosekit-plugin-view-handler");
880
-
881
- // src/extensions/events/doc-change.ts
922
+ const pluginKey = new PluginKey("prosekit-plugin-view-handler");
923
+
924
+ //#endregion
925
+ //#region src/extensions/events/doc-change.ts
926
+ /**
927
+ * Registers a event handler that is called when the editor document is changed.
928
+ *
929
+ * @public
930
+ */
882
931
  function defineDocChangeHandler(handler) {
883
- return defineUpdateHandler((view, prevState) => {
884
- if (!view.state.doc.eq(prevState.doc)) {
885
- handler(view, prevState);
886
- }
887
- });
932
+ return defineUpdateHandler((view, prevState) => {
933
+ if (!view.state.doc.eq(prevState.doc)) handler(view, prevState);
934
+ });
888
935
  }
889
936
 
890
- // src/extensions/events/dom-event.ts
891
- import {
892
- PluginKey as PluginKey3,
893
- ProseMirrorPlugin as ProseMirrorPlugin3
894
- } from "@prosekit/pm/state";
895
-
896
- // src/utils/combine-event-handlers.ts
937
+ //#endregion
938
+ //#region src/utils/combine-event-handlers.ts
897
939
  function combineEventHandlers() {
898
- let handlers = [];
899
- function setHandlers(eventHandlers) {
900
- handlers = toReversed(eventHandlers);
901
- }
902
- function combinedEventHandler(...args) {
903
- for (const handler of handlers) {
904
- if (handler(...args)) {
905
- return true;
906
- }
907
- }
908
- return false;
909
- }
910
- return [setHandlers, combinedEventHandler];
911
- }
912
-
913
- // src/extensions/events/dom-event.ts
940
+ let handlers = [];
941
+ function setHandlers(eventHandlers) {
942
+ handlers = toReversed(eventHandlers);
943
+ }
944
+ function combinedEventHandler(...args) {
945
+ for (const handler of handlers) if (handler(...args)) return true;
946
+ return false;
947
+ }
948
+ return [setHandlers, combinedEventHandler];
949
+ }
950
+
951
+ //#endregion
952
+ //#region src/extensions/events/dom-event.ts
953
+ /**
954
+ * @internal
955
+ */
914
956
  function defineDomEventFacetPayload(...payloads) {
915
- return defineFacetPayload(
916
- domEventFacet,
917
- payloads
918
- );
957
+ return defineFacetPayload(domEventFacet, payloads);
919
958
  }
959
+ /**
960
+ * Register a new event handler for the given event type.
961
+ *
962
+ * @public
963
+ */
920
964
  function defineDOMEventHandler(event, handler) {
921
- return defineDomEventFacetPayload([
922
- event,
923
- handler
924
- ]);
925
- }
926
- var domEventFacet = defineFacet(
927
- {
928
- reduce: () => {
929
- const setHandlersMap = {};
930
- const combinedHandlerMap = {};
931
- let plugin;
932
- const update = (payloads) => {
933
- let hasNewEvent = false;
934
- for (const [event] of payloads) {
935
- if (!setHandlersMap[event]) {
936
- hasNewEvent = true;
937
- const [setHandlers, combinedHandler] = combineEventHandlers();
938
- setHandlersMap[event] = setHandlers;
939
- const e = (view, eventObject) => {
940
- return combinedHandler(view, eventObject);
941
- };
942
- combinedHandlerMap[event] = e;
943
- }
944
- }
945
- const map = groupEntries(payloads);
946
- for (const [event, setHandlers] of Object.entries(setHandlersMap)) {
947
- const handlers = map[event] ?? [];
948
- setHandlers(handlers);
949
- }
950
- if (hasNewEvent) {
951
- plugin = new ProseMirrorPlugin3({
952
- key: new PluginKey3("prosekit-dom-event-handler"),
953
- props: { handleDOMEvents: combinedHandlerMap }
954
- });
955
- }
956
- };
957
- return function reducer(inputs) {
958
- update(inputs);
959
- return plugin ?? [];
960
- };
961
- },
962
- parent: pluginFacet,
963
- singleton: true
964
- }
965
- );
966
-
967
- // src/extensions/events/editor-event.ts
968
- import {
969
- PluginKey as PluginKey4,
970
- ProseMirrorPlugin as ProseMirrorPlugin4
971
- } from "@prosekit/pm/state";
965
+ return defineDomEventFacetPayload([event, handler]);
966
+ }
967
+ /**
968
+ * @internal
969
+ */
970
+ const domEventFacet = defineFacet({
971
+ reduce: () => {
972
+ const setHandlersMap = {};
973
+ const combinedHandlerMap = {};
974
+ let plugin;
975
+ const update = (payloads) => {
976
+ let hasNewEvent = false;
977
+ for (const [event] of payloads) if (!setHandlersMap[event]) {
978
+ hasNewEvent = true;
979
+ const [setHandlers, combinedHandler] = combineEventHandlers();
980
+ setHandlersMap[event] = setHandlers;
981
+ const e = (view, eventObject) => {
982
+ return combinedHandler(view, eventObject);
983
+ };
984
+ combinedHandlerMap[event] = e;
985
+ }
986
+ const map = groupEntries(payloads);
987
+ for (const [event, setHandlers] of Object.entries(setHandlersMap)) {
988
+ const handlers = map[event] ?? [];
989
+ setHandlers(handlers);
990
+ }
991
+ if (hasNewEvent) plugin = new ProseMirrorPlugin({
992
+ key: new PluginKey("prosekit-dom-event-handler"),
993
+ props: { handleDOMEvents: combinedHandlerMap }
994
+ });
995
+ };
996
+ return function reducer(inputs) {
997
+ update(inputs);
998
+ return plugin ?? [];
999
+ };
1000
+ },
1001
+ parent: pluginFacet,
1002
+ singleton: true
1003
+ });
1004
+
1005
+ //#endregion
1006
+ //#region src/extensions/events/editor-event.ts
972
1007
  function defineEventFacetPayload(payload) {
973
- return defineFacetPayload(editorEventFacet, [payload]);
1008
+ return defineFacetPayload(editorEventFacet, [payload]);
974
1009
  }
1010
+ /**
1011
+ * @public
1012
+ *
1013
+ * See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleKeyDown}
1014
+ */
975
1015
  function defineKeyDownHandler(handler) {
976
- return defineEventFacetPayload(["keyDown", handler]);
1016
+ return defineEventFacetPayload(["keyDown", handler]);
977
1017
  }
1018
+ /**
1019
+ * @public
1020
+ *
1021
+ * See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleKeyPress}
1022
+ */
978
1023
  function defineKeyPressHandler(handler) {
979
- return defineEventFacetPayload(["keyPress", handler]);
1024
+ return defineEventFacetPayload(["keyPress", handler]);
980
1025
  }
1026
+ /**
1027
+ * @public
1028
+ *
1029
+ * See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleTextInput}
1030
+ */
981
1031
  function defineTextInputHandler(handler) {
982
- return defineEventFacetPayload(["textInput", handler]);
1032
+ return defineEventFacetPayload(["textInput", handler]);
983
1033
  }
1034
+ /**
1035
+ * @public
1036
+ *
1037
+ * See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleClickOn}
1038
+ */
984
1039
  function defineClickOnHandler(handler) {
985
- return defineEventFacetPayload(["clickOn", handler]);
1040
+ return defineEventFacetPayload(["clickOn", handler]);
986
1041
  }
1042
+ /**
1043
+ * @public
1044
+ *
1045
+ * See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleClick}
1046
+ */
987
1047
  function defineClickHandler(handler) {
988
- return defineEventFacetPayload(["click", handler]);
1048
+ return defineEventFacetPayload(["click", handler]);
989
1049
  }
1050
+ /**
1051
+ * @public
1052
+ *
1053
+ * See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleDoubleClickOn}
1054
+ */
990
1055
  function defineDoubleClickOnHandler(handler) {
991
- return defineEventFacetPayload(["doubleClickOn", handler]);
1056
+ return defineEventFacetPayload(["doubleClickOn", handler]);
992
1057
  }
1058
+ /**
1059
+ * @public
1060
+ *
1061
+ * See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleDoubleClick}
1062
+ */
993
1063
  function defineDoubleClickHandler(handler) {
994
- return defineEventFacetPayload(["doubleClick", handler]);
1064
+ return defineEventFacetPayload(["doubleClick", handler]);
995
1065
  }
1066
+ /**
1067
+ * @public
1068
+ *
1069
+ * See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleTripleClickOn}
1070
+ */
996
1071
  function defineTripleClickOnHandler(handler) {
997
- return defineEventFacetPayload(["tripleClickOn", handler]);
1072
+ return defineEventFacetPayload(["tripleClickOn", handler]);
998
1073
  }
1074
+ /**
1075
+ * @public
1076
+ *
1077
+ * See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleTripleClick}
1078
+ */
999
1079
  function defineTripleClickHandler(handler) {
1000
- return defineEventFacetPayload(["tripleClick", handler]);
1080
+ return defineEventFacetPayload(["tripleClick", handler]);
1001
1081
  }
1082
+ /**
1083
+ * @public
1084
+ *
1085
+ * See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handlePaste}
1086
+ */
1002
1087
  function definePasteHandler(handler) {
1003
- return defineEventFacetPayload(["paste", handler]);
1088
+ return defineEventFacetPayload(["paste", handler]);
1004
1089
  }
1090
+ /**
1091
+ * @public
1092
+ *
1093
+ * See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleDrop}
1094
+ */
1005
1095
  function defineDropHandler(handler) {
1006
- return defineEventFacetPayload(["drop", handler]);
1096
+ return defineEventFacetPayload(["drop", handler]);
1007
1097
  }
1098
+ /**
1099
+ * @public
1100
+ *
1101
+ * See {@link https://prosemirror.net/docs/ref/#view.EditorProps.handleScrollToSelection}
1102
+ */
1008
1103
  function defineScrollToSelectionHandler(handler) {
1009
- return defineEventFacetPayload(["scrollToSelection", handler]);
1010
- }
1011
- var editorEventFacet = defineFacet({
1012
- reduce: () => {
1013
- const [update, plugin] = setupEditorEventPlugin();
1014
- return (entries) => {
1015
- update(entries);
1016
- return plugin;
1017
- };
1018
- },
1019
- parent: pluginFacet,
1020
- singleton: true
1104
+ return defineEventFacetPayload(["scrollToSelection", handler]);
1105
+ }
1106
+ /**
1107
+ * @internal
1108
+ */
1109
+ const editorEventFacet = defineFacet({
1110
+ reduce: () => {
1111
+ const [update, plugin] = setupEditorEventPlugin();
1112
+ return (entries) => {
1113
+ update(entries);
1114
+ return plugin;
1115
+ };
1116
+ },
1117
+ parent: pluginFacet,
1118
+ singleton: true
1021
1119
  });
1022
1120
  function setupEditorEventPlugin() {
1023
- const [setKeyDownHandlers, handleKeyDown] = combineEventHandlers();
1024
- const [setKeyPressHandlers, handleKeyPress] = combineEventHandlers();
1025
- const [setTextInputHandlers, handleTextInput] = combineEventHandlers();
1026
- const [setClickOnHandlers, handleClickOn] = combineEventHandlers();
1027
- const [setClickHandlers, handleClick] = combineEventHandlers();
1028
- const [setDoubleClickOnHandlers, handleDoubleClickOn] = combineEventHandlers();
1029
- const [setDoubleClickHandlers, handleDoubleClick] = combineEventHandlers();
1030
- const [setTripleClickOnHandlers, handleTripleClickOn] = combineEventHandlers();
1031
- const [setTripleClickHandlers, handleTripleClick] = combineEventHandlers();
1032
- const [setPasteHandlers, handlePaste] = combineEventHandlers();
1033
- const [setDropHandlers, handleDrop] = combineEventHandlers();
1034
- const [setScrollToSelectionHandlers, handleScrollToSelection] = combineEventHandlers();
1035
- const update = (entries) => {
1036
- const map = groupEntries(entries);
1037
- setKeyDownHandlers(map.keyDown ?? []);
1038
- setKeyPressHandlers(map.keyPress ?? []);
1039
- setTextInputHandlers(map.textInput ?? []);
1040
- setClickOnHandlers(map.clickOn ?? []);
1041
- setClickHandlers(map.click ?? []);
1042
- setDoubleClickOnHandlers(map.doubleClickOn ?? []);
1043
- setDoubleClickHandlers(map.doubleClick ?? []);
1044
- setTripleClickOnHandlers(map.tripleClickOn ?? []);
1045
- setTripleClickHandlers(map.tripleClick ?? []);
1046
- setPasteHandlers(map.paste ?? []);
1047
- setDropHandlers(map.drop ?? []);
1048
- setScrollToSelectionHandlers(map.scrollToSelection ?? []);
1049
- };
1050
- const plugin = new ProseMirrorPlugin4({
1051
- key: new PluginKey4("prosekit-editor-event"),
1052
- props: {
1053
- handleKeyDown,
1054
- handleKeyPress,
1055
- handleTextInput,
1056
- handleClickOn,
1057
- handleClick,
1058
- handleDoubleClickOn,
1059
- handleDoubleClick,
1060
- handleTripleClickOn,
1061
- handleTripleClick,
1062
- handlePaste,
1063
- handleDrop,
1064
- handleScrollToSelection
1065
- }
1066
- });
1067
- return [update, plugin];
1068
- }
1069
-
1070
- // src/extensions/events/focus.ts
1121
+ const [setKeyDownHandlers, handleKeyDown] = combineEventHandlers();
1122
+ const [setKeyPressHandlers, handleKeyPress] = combineEventHandlers();
1123
+ const [setTextInputHandlers, handleTextInput] = combineEventHandlers();
1124
+ const [setClickOnHandlers, handleClickOn] = combineEventHandlers();
1125
+ const [setClickHandlers, handleClick] = combineEventHandlers();
1126
+ const [setDoubleClickOnHandlers, handleDoubleClickOn] = combineEventHandlers();
1127
+ const [setDoubleClickHandlers, handleDoubleClick] = combineEventHandlers();
1128
+ const [setTripleClickOnHandlers, handleTripleClickOn] = combineEventHandlers();
1129
+ const [setTripleClickHandlers, handleTripleClick] = combineEventHandlers();
1130
+ const [setPasteHandlers, handlePaste] = combineEventHandlers();
1131
+ const [setDropHandlers, handleDrop] = combineEventHandlers();
1132
+ const [setScrollToSelectionHandlers, handleScrollToSelection] = combineEventHandlers();
1133
+ const update = (entries) => {
1134
+ const map = groupEntries(entries);
1135
+ setKeyDownHandlers(map.keyDown ?? []);
1136
+ setKeyPressHandlers(map.keyPress ?? []);
1137
+ setTextInputHandlers(map.textInput ?? []);
1138
+ setClickOnHandlers(map.clickOn ?? []);
1139
+ setClickHandlers(map.click ?? []);
1140
+ setDoubleClickOnHandlers(map.doubleClickOn ?? []);
1141
+ setDoubleClickHandlers(map.doubleClick ?? []);
1142
+ setTripleClickOnHandlers(map.tripleClickOn ?? []);
1143
+ setTripleClickHandlers(map.tripleClick ?? []);
1144
+ setPasteHandlers(map.paste ?? []);
1145
+ setDropHandlers(map.drop ?? []);
1146
+ setScrollToSelectionHandlers(map.scrollToSelection ?? []);
1147
+ };
1148
+ const plugin = new ProseMirrorPlugin({
1149
+ key: new PluginKey("prosekit-editor-event"),
1150
+ props: {
1151
+ handleKeyDown,
1152
+ handleKeyPress,
1153
+ handleTextInput,
1154
+ handleClickOn,
1155
+ handleClick,
1156
+ handleDoubleClickOn,
1157
+ handleDoubleClick,
1158
+ handleTripleClickOn,
1159
+ handleTripleClick,
1160
+ handlePaste,
1161
+ handleDrop,
1162
+ handleScrollToSelection
1163
+ }
1164
+ });
1165
+ return [update, plugin];
1166
+ }
1167
+
1168
+ //#endregion
1169
+ //#region src/extensions/events/focus.ts
1170
+ /**
1171
+ * Registers a event handler that is called when the editor gains or loses focus.
1172
+ *
1173
+ * @public
1174
+ */
1071
1175
  function defineFocusChangeHandler(handler) {
1072
- const handleFocus = () => handler(true);
1073
- const handleBlur = () => handler(false);
1074
- return defineDomEventFacetPayload(
1075
- ["focus", handleFocus],
1076
- ["blur", handleBlur]
1077
- );
1078
- }
1079
-
1080
- // src/extensions/history.ts
1081
- import {
1082
- history,
1083
- redo,
1084
- undo
1085
- } from "@prosekit/pm/history";
1086
-
1087
- // src/utils/env.ts
1088
- var isApple = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
1089
-
1090
- // src/extensions/keymap.ts
1091
- import { chainCommands } from "@prosekit/pm/commands";
1092
- import { keydownHandler } from "@prosekit/pm/keymap";
1093
- import {
1094
- Plugin as Plugin2,
1095
- PluginKey as PluginKey5
1096
- } from "@prosekit/pm/state";
1097
- import mapValues from "just-map-values";
1098
- function defineKeymap(keymap2) {
1099
- return defineFacetPayload(keymapFacet, [keymap2]);
1100
- }
1101
- var keymapFacet = defineFacet({
1102
- reduce: () => {
1103
- let handler;
1104
- const handlerWrapper = (view, event) => {
1105
- if (handler) return handler(view, event);
1106
- return false;
1107
- };
1108
- const plugin = new Plugin2({
1109
- key: keymapPluginKey,
1110
- props: { handleKeyDown: handlerWrapper }
1111
- });
1112
- return (keymaps) => {
1113
- handler = keydownHandler(
1114
- mergeKeymaps(
1115
- // The keymap at the end have a higher priority.
1116
- toReversed(keymaps)
1117
- )
1118
- );
1119
- return plugin;
1120
- };
1121
- },
1122
- parent: pluginFacet,
1123
- singleton: true
1176
+ const handleFocus = () => handler(true);
1177
+ const handleBlur = () => handler(false);
1178
+ return defineDomEventFacetPayload(["focus", handleFocus], ["blur", handleBlur]);
1179
+ }
1180
+
1181
+ //#endregion
1182
+ //#region src/utils/env.ts
1183
+ /**
1184
+ * @private
1185
+ */
1186
+ const isApple = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
1187
+
1188
+ //#endregion
1189
+ //#region src/extensions/keymap.ts
1190
+ /**
1191
+ * @public
1192
+ */
1193
+ function defineKeymap(keymap$1) {
1194
+ return defineFacetPayload(keymapFacet, [keymap$1]);
1195
+ }
1196
+ /**
1197
+ * @internal
1198
+ */
1199
+ const keymapFacet = defineFacet({
1200
+ reduce: () => {
1201
+ let handler;
1202
+ const handlerWrapper = (view, event) => {
1203
+ if (handler) return handler(view, event);
1204
+ return false;
1205
+ };
1206
+ const plugin = new Plugin({
1207
+ key: keymapPluginKey,
1208
+ props: { handleKeyDown: handlerWrapper }
1209
+ });
1210
+ return (keymaps) => {
1211
+ handler = keydownHandler(mergeKeymaps(
1212
+ // The keymap at the end have a higher priority.
1213
+ toReversed(keymaps)
1214
+ ));
1215
+ return plugin;
1216
+ };
1217
+ },
1218
+ parent: pluginFacet,
1219
+ singleton: true
1124
1220
  });
1125
1221
  function mergeKeymaps(keymaps) {
1126
- const bindings = {};
1127
- for (const keymap2 of keymaps) {
1128
- for (const [key, command] of Object.entries(keymap2)) {
1129
- const commands2 = bindings[key] || (bindings[key] = []);
1130
- commands2.push(command);
1131
- }
1132
- }
1133
- return mapValues(bindings, mergeCommands);
1134
- }
1135
- function mergeCommands(commands2) {
1136
- return chainCommands(...commands2);
1137
- }
1138
- var keymapPluginKey = new PluginKey5("prosekit-keymap");
1139
-
1140
- // src/extensions/history.ts
1141
- var keymap = {
1142
- "Mod-z": undo,
1143
- "Shift-Mod-z": redo
1222
+ const bindings = {};
1223
+ for (const keymap$1 of keymaps) for (const [key, command] of Object.entries(keymap$1)) {
1224
+ const commands$1 = bindings[key] || (bindings[key] = []);
1225
+ commands$1.push(command);
1226
+ }
1227
+ return mapValues(bindings, mergeCommands);
1228
+ }
1229
+ function mergeCommands(commands$1) {
1230
+ return chainCommands(...commands$1);
1231
+ }
1232
+ const keymapPluginKey = new PluginKey("prosekit-keymap");
1233
+
1234
+ //#endregion
1235
+ //#region src/extensions/history.ts
1236
+ const keymap = {
1237
+ "Mod-z": undo,
1238
+ "Shift-Mod-z": redo
1144
1239
  };
1145
- if (!isApple) {
1146
- keymap["Mod-y"] = redo;
1147
- }
1148
- var commands = {
1149
- undo: () => undo,
1150
- redo: () => redo
1240
+ if (!isApple) keymap["Mod-y"] = redo;
1241
+ const commands = {
1242
+ undo: () => undo,
1243
+ redo: () => redo
1151
1244
  };
1152
- function defineHistory({
1153
- depth = 200,
1154
- newGroupDelay = 250
1155
- } = {}) {
1156
- return union(
1157
- definePlugin(history({ depth, newGroupDelay })),
1158
- defineKeymap(keymap),
1159
- defineCommands(commands)
1160
- );
1161
- }
1162
-
1163
- // src/extensions/keymap-base.ts
1164
- import {
1165
- baseKeymap,
1166
- chainCommands as chainCommands2,
1167
- createParagraphNear,
1168
- deleteSelection,
1169
- joinTextblockBackward,
1170
- liftEmptyBlock,
1171
- newlineInCode,
1172
- selectNodeBackward
1173
- } from "@prosekit/pm/commands";
1174
- import { splitSplittableBlock } from "prosemirror-splittable";
1175
- var customEnter = chainCommands2(
1176
- newlineInCode,
1177
- createParagraphNear,
1178
- liftEmptyBlock,
1179
- splitSplittableBlock
1180
- );
1181
- var customBackspace = chainCommands2(
1182
- deleteSelection,
1183
- joinTextblockBackward,
1184
- selectNodeBackward
1185
- );
1186
- var customBaseKeymap = {
1187
- ...baseKeymap,
1188
- Enter: customEnter,
1189
- Backspace: customBackspace
1245
+ /**
1246
+ * Add undo/redo history to the editor.
1247
+ *
1248
+ * @param options
1249
+ *
1250
+ * @public
1251
+ */
1252
+ function defineHistory({ depth = 200, newGroupDelay = 250 } = {}) {
1253
+ return union(definePlugin(history({
1254
+ depth,
1255
+ newGroupDelay
1256
+ })), defineKeymap(keymap), defineCommands(commands));
1257
+ }
1258
+
1259
+ //#endregion
1260
+ //#region src/extensions/keymap-base.ts
1261
+ const customEnter = chainCommands(newlineInCode, createParagraphNear, liftEmptyBlock, splitSplittableBlock);
1262
+ const customBackspace = chainCommands(deleteSelection, joinTextblockBackward, selectNodeBackward);
1263
+ const customBaseKeymap = {
1264
+ ...baseKeymap,
1265
+ Enter: customEnter,
1266
+ Backspace: customBackspace
1190
1267
  };
1268
+ /**
1269
+ * Defines some basic key bindings.
1270
+ *
1271
+ * @public
1272
+ */
1191
1273
  function defineBaseKeymap(options) {
1192
- const priority = options?.priority ?? 1 /* low */;
1193
- return withPriority(defineKeymap(customBaseKeymap), priority);
1274
+ const priority = options?.priority ?? Priority.low;
1275
+ return withPriority(defineKeymap(customBaseKeymap), priority);
1194
1276
  }
1195
1277
 
1196
- // src/extensions/mark-spec.ts
1197
- import clone2 from "just-clone";
1198
- import OrderedMap3 from "orderedmap";
1278
+ //#endregion
1279
+ //#region src/extensions/mark-spec.ts
1280
+ /**
1281
+ * @public
1282
+ */
1199
1283
  function defineMarkSpec(options) {
1200
- const payload = [options, void 0];
1201
- return defineFacetPayload(markSpecFacet, [payload]);
1284
+ const payload = [options, void 0];
1285
+ return defineFacetPayload(markSpecFacet, [payload]);
1202
1286
  }
1287
+ /**
1288
+ * @public
1289
+ */
1203
1290
  function defineMarkAttr(options) {
1204
- const payload = [void 0, options];
1205
- return defineFacetPayload(markSpecFacet, [payload]);
1206
- }
1207
- var markSpecFacet = defineFacet({
1208
- reducer: (payloads) => {
1209
- let specs = OrderedMap3.from({});
1210
- const specPayloads = payloads.map((input) => input[0]).filter(isNotNullish);
1211
- const attrPayloads = payloads.map((input) => input[1]).filter(isNotNullish);
1212
- for (const { name, ...spec } of specPayloads) {
1213
- const prevSpec = specs.get(name);
1214
- if (prevSpec) {
1215
- specs = specs.update(name, mergeSpecs(prevSpec, spec));
1216
- } else {
1217
- specs = specs.addToStart(name, spec);
1218
- }
1219
- }
1220
- const groupedAttrs = groupBy(attrPayloads, (payload) => payload.type);
1221
- for (const [type, attrs] of Object.entries(groupedAttrs)) {
1222
- if (!attrs) continue;
1223
- const maybeSpec = specs.get(type);
1224
- assert(maybeSpec, `Mark type ${type} must be defined`);
1225
- const spec = clone2(maybeSpec);
1226
- if (!spec.attrs) {
1227
- spec.attrs = {};
1228
- }
1229
- for (const attr of attrs) {
1230
- spec.attrs[attr.attr] = {
1231
- default: attr.default,
1232
- validate: attr.validate
1233
- };
1234
- }
1235
- if (spec.toDOM) {
1236
- spec.toDOM = wrapOutputSpecAttrs(spec.toDOM, attrs);
1237
- }
1238
- if (spec.parseDOM) {
1239
- spec.parseDOM = spec.parseDOM.map((rule) => wrapParseRuleAttrs(rule, attrs));
1240
- }
1241
- specs = specs.update(type, spec);
1242
- }
1243
- return { marks: specs, nodes: {} };
1244
- },
1245
- parent: schemaSpecFacet,
1246
- singleton: true
1291
+ const payload = [void 0, options];
1292
+ return defineFacetPayload(markSpecFacet, [payload]);
1293
+ }
1294
+ const markSpecFacet = defineFacet({
1295
+ reducer: (payloads) => {
1296
+ let specs = OrderedMap.from({});
1297
+ const specPayloads = payloads.map((input) => input[0]).filter(isNotNullish);
1298
+ const attrPayloads = payloads.map((input) => input[1]).filter(isNotNullish);
1299
+ for (const { name,...spec } of specPayloads) {
1300
+ const prevSpec = specs.get(name);
1301
+ if (prevSpec) specs = specs.update(name, mergeSpecs(prevSpec, spec));
1302
+ else specs = specs.addToStart(name, spec);
1303
+ }
1304
+ const groupedAttrs = groupBy(attrPayloads, (payload) => payload.type);
1305
+ for (const [type, attrs] of Object.entries(groupedAttrs)) {
1306
+ if (!attrs) continue;
1307
+ const maybeSpec = specs.get(type);
1308
+ assert(maybeSpec, `Mark type ${type} must be defined`);
1309
+ const spec = clone(maybeSpec);
1310
+ if (!spec.attrs) spec.attrs = {};
1311
+ for (const attr of attrs) spec.attrs[attr.attr] = {
1312
+ default: attr.default,
1313
+ validate: attr.validate
1314
+ };
1315
+ if (spec.toDOM) spec.toDOM = wrapOutputSpecAttrs(spec.toDOM, attrs);
1316
+ if (spec.parseDOM) spec.parseDOM = spec.parseDOM.map((rule) => wrapParseRuleAttrs(rule, attrs));
1317
+ specs = specs.update(type, spec);
1318
+ }
1319
+ return {
1320
+ marks: specs,
1321
+ nodes: {}
1322
+ };
1323
+ },
1324
+ parent: schemaSpecFacet,
1325
+ singleton: true
1247
1326
  });
1248
1327
  function wrapParseRuleAttrs(rule, attrs) {
1249
- if (rule.tag) {
1250
- return wrapTagParseRuleAttrs(rule, attrs);
1251
- }
1252
- return rule;
1328
+ if (rule.tag) return wrapTagParseRuleAttrs(rule, attrs);
1329
+ return rule;
1253
1330
  }
1254
1331
 
1255
- // src/extensions/mark-view.ts
1256
- import {
1257
- PluginKey as PluginKey6,
1258
- ProseMirrorPlugin as ProseMirrorPlugin5
1259
- } from "@prosekit/pm/state";
1332
+ //#endregion
1333
+ //#region src/extensions/mark-view.ts
1260
1334
  function defineMarkView(options) {
1261
- return defineFacetPayload(markViewFacet, [options]);
1262
- }
1263
- var markViewFacet = defineFacet({
1264
- reducer: (inputs) => {
1265
- const markViews = {};
1266
- for (const input of inputs) {
1267
- if (!markViews[input.name]) {
1268
- markViews[input.name] = input.constructor;
1269
- }
1270
- }
1271
- return () => [
1272
- new ProseMirrorPlugin5({
1273
- key: new PluginKey6("prosekit-mark-view"),
1274
- props: { markViews }
1275
- })
1276
- ];
1277
- },
1278
- parent: pluginFacet
1335
+ return defineFacetPayload(markViewFacet, [options]);
1336
+ }
1337
+ const markViewFacet = defineFacet({
1338
+ reducer: (inputs) => {
1339
+ const markViews = {};
1340
+ for (const input of inputs) if (!markViews[input.name]) markViews[input.name] = input.constructor;
1341
+ return () => [new ProseMirrorPlugin({
1342
+ key: new PluginKey("prosekit-mark-view"),
1343
+ props: { markViews }
1344
+ })];
1345
+ },
1346
+ parent: pluginFacet
1279
1347
  });
1280
1348
 
1281
- // src/extensions/mark-view-effect.ts
1282
- import {
1283
- PluginKey as PluginKey7,
1284
- ProseMirrorPlugin as ProseMirrorPlugin6
1285
- } from "@prosekit/pm/state";
1349
+ //#endregion
1350
+ //#region src/extensions/mark-view-effect.ts
1351
+ /**
1352
+ * @internal
1353
+ */
1286
1354
  function defineMarkViewFactory(options) {
1287
- const input = [options, null];
1288
- return defineFacetPayload(markViewFactoryFacet, [input]);
1355
+ const input = [options, null];
1356
+ return defineFacetPayload(markViewFactoryFacet, [input]);
1289
1357
  }
1358
+ /**
1359
+ * @internal
1360
+ */
1290
1361
  function defineMarkViewComponent(options) {
1291
- const input = [null, options];
1292
- return defineFacetPayload(markViewFactoryFacet, [input]);
1293
- }
1294
- var isServer = typeof window === "undefined";
1295
- var markViewFactoryFacet = defineFacet({
1296
- reducer: (inputs) => {
1297
- if (isServer) return [];
1298
- const markViews = {};
1299
- const factories = inputs.map((x) => x[0]).filter(isNotNullish);
1300
- const options = inputs.map((x) => x[1]).filter(isNotNullish);
1301
- for (const { group, name, args } of options) {
1302
- const factory = factories.find((factory2) => factory2.group === group);
1303
- if (!factory) continue;
1304
- markViews[name] = factory.factory(args);
1305
- }
1306
- return () => [
1307
- new ProseMirrorPlugin6({
1308
- key: new PluginKey7("prosekit-mark-view-effect"),
1309
- props: { markViews }
1310
- })
1311
- ];
1312
- },
1313
- parent: pluginFacet
1362
+ const input = [null, options];
1363
+ return defineFacetPayload(markViewFactoryFacet, [input]);
1364
+ }
1365
+ const isServer$1 = typeof window === "undefined";
1366
+ const markViewFactoryFacet = defineFacet({
1367
+ reducer: (inputs) => {
1368
+ if (isServer$1) return [];
1369
+ const markViews = {};
1370
+ const factories = inputs.map((x) => x[0]).filter(isNotNullish);
1371
+ const options = inputs.map((x) => x[1]).filter(isNotNullish);
1372
+ for (const { group, name, args } of options) {
1373
+ const factory = factories.find((factory$1) => factory$1.group === group);
1374
+ if (!factory) continue;
1375
+ markViews[name] = factory.factory(args);
1376
+ }
1377
+ return () => [new ProseMirrorPlugin({
1378
+ key: new PluginKey("prosekit-mark-view-effect"),
1379
+ props: { markViews }
1380
+ })];
1381
+ },
1382
+ parent: pluginFacet
1314
1383
  });
1315
1384
 
1316
- // src/extensions/node-view.ts
1317
- import {
1318
- PluginKey as PluginKey8,
1319
- ProseMirrorPlugin as ProseMirrorPlugin7
1320
- } from "@prosekit/pm/state";
1385
+ //#endregion
1386
+ //#region src/extensions/node-view.ts
1321
1387
  function defineNodeView(options) {
1322
- return defineFacetPayload(nodeViewFacet, [options]);
1323
- }
1324
- var nodeViewFacet = defineFacet({
1325
- reducer: (inputs) => {
1326
- const nodeViews = {};
1327
- for (const input of inputs) {
1328
- if (!nodeViews[input.name]) {
1329
- nodeViews[input.name] = input.constructor;
1330
- }
1331
- }
1332
- return () => [
1333
- new ProseMirrorPlugin7({
1334
- key: new PluginKey8("prosekit-node-view"),
1335
- props: { nodeViews }
1336
- })
1337
- ];
1338
- },
1339
- parent: pluginFacet
1388
+ return defineFacetPayload(nodeViewFacet, [options]);
1389
+ }
1390
+ const nodeViewFacet = defineFacet({
1391
+ reducer: (inputs) => {
1392
+ const nodeViews = {};
1393
+ for (const input of inputs) if (!nodeViews[input.name]) nodeViews[input.name] = input.constructor;
1394
+ return () => [new ProseMirrorPlugin({
1395
+ key: new PluginKey("prosekit-node-view"),
1396
+ props: { nodeViews }
1397
+ })];
1398
+ },
1399
+ parent: pluginFacet
1340
1400
  });
1341
1401
 
1342
- // src/extensions/node-view-effect.ts
1343
- import {
1344
- PluginKey as PluginKey9,
1345
- ProseMirrorPlugin as ProseMirrorPlugin8
1346
- } from "@prosekit/pm/state";
1402
+ //#endregion
1403
+ //#region src/extensions/node-view-effect.ts
1404
+ /**
1405
+ * @internal
1406
+ */
1347
1407
  function defineNodeViewFactory(options) {
1348
- const input = [options, null];
1349
- return defineFacetPayload(nodeViewFactoryFacet, [input]);
1408
+ const input = [options, null];
1409
+ return defineFacetPayload(nodeViewFactoryFacet, [input]);
1350
1410
  }
1411
+ /**
1412
+ * @internal
1413
+ */
1351
1414
  function defineNodeViewComponent(options) {
1352
- const input = [null, options];
1353
- return defineFacetPayload(nodeViewFactoryFacet, [input]);
1354
- }
1355
- var isServer2 = typeof window === "undefined";
1356
- var nodeViewFactoryFacet = defineFacet({
1357
- reducer: (inputs) => {
1358
- if (isServer2) return [];
1359
- const nodeViews = {};
1360
- const factories = inputs.map((x) => x[0]).filter(isNotNullish);
1361
- const options = inputs.map((x) => x[1]).filter(isNotNullish);
1362
- for (const { group, name, args } of options) {
1363
- const factory = factories.find((factory2) => factory2.group === group);
1364
- if (!factory) continue;
1365
- nodeViews[name] = factory.factory(args);
1366
- }
1367
- return () => [
1368
- new ProseMirrorPlugin8({
1369
- key: new PluginKey9("prosekit-node-view-effect"),
1370
- props: { nodeViews }
1371
- })
1372
- ];
1373
- },
1374
- parent: pluginFacet
1415
+ const input = [null, options];
1416
+ return defineFacetPayload(nodeViewFactoryFacet, [input]);
1417
+ }
1418
+ const isServer = typeof window === "undefined";
1419
+ const nodeViewFactoryFacet = defineFacet({
1420
+ reducer: (inputs) => {
1421
+ if (isServer) return [];
1422
+ const nodeViews = {};
1423
+ const factories = inputs.map((x) => x[0]).filter(isNotNullish);
1424
+ const options = inputs.map((x) => x[1]).filter(isNotNullish);
1425
+ for (const { group, name, args } of options) {
1426
+ const factory = factories.find((factory$1) => factory$1.group === group);
1427
+ if (!factory) continue;
1428
+ nodeViews[name] = factory.factory(args);
1429
+ }
1430
+ return () => [new ProseMirrorPlugin({
1431
+ key: new PluginKey("prosekit-node-view-effect"),
1432
+ props: { nodeViews }
1433
+ })];
1434
+ },
1435
+ parent: pluginFacet
1375
1436
  });
1376
1437
 
1377
- // src/extensions/paragraph.ts
1438
+ //#endregion
1439
+ //#region src/extensions/paragraph.ts
1440
+ /**
1441
+ * Defines a paragraph node spec.
1442
+ */
1378
1443
  function defineParagraphSpec() {
1379
- return defineNodeSpec({
1380
- name: "paragraph",
1381
- content: "inline*",
1382
- group: "block",
1383
- parseDOM: [{ tag: "p" }],
1384
- toDOM() {
1385
- return ["p", 0];
1386
- }
1387
- });
1388
- }
1444
+ return defineNodeSpec({
1445
+ name: "paragraph",
1446
+ content: "inline*",
1447
+ group: "block",
1448
+ parseDOM: [{ tag: "p" }],
1449
+ toDOM() {
1450
+ return ["p", 0];
1451
+ }
1452
+ });
1453
+ }
1454
+ /**
1455
+ * @public
1456
+ *
1457
+ * Defines a paragraph node spec as the highest priority, because it should be the default block node for most cases.
1458
+ *
1459
+ * @deprecated Use the following import instead:
1460
+ *
1461
+ * ```ts
1462
+ * import { defineParagraph } from 'prosekit/extensions/paragraph'
1463
+ * ```
1464
+ */
1389
1465
  function defineParagraph() {
1390
- console.warn(
1391
- '[prosekit] The `defineParagraph` function from `prosekit/core` is deprecated. Use the following import instead: `import { defineParagraph } from "prosekit/extensions/paragraph"`.'
1392
- );
1393
- return withPriority(defineParagraphSpec(), 4 /* highest */);
1394
- }
1395
-
1396
- // src/extensions/text.ts
1466
+ console.warn("[prosekit] The `defineParagraph` function from `prosekit/core` is deprecated. Use the following import instead: `import { defineParagraph } from \"prosekit/extensions/paragraph\"`.");
1467
+ return withPriority(defineParagraphSpec(), Priority.highest);
1468
+ }
1469
+
1470
+ //#endregion
1471
+ //#region src/extensions/text.ts
1472
+ /**
1473
+ * @public
1474
+ *
1475
+ * @deprecated Use the following import instead:
1476
+ *
1477
+ * ```ts
1478
+ * import { defineText } from 'prosekit/extensions/text'
1479
+ * ```
1480
+ */
1397
1481
  function defineText() {
1398
- console.warn(
1399
- '[prosekit] The `defineText` function from `prosekit/core` is deprecated. Use the following import instead: `import { defineText } from "prosekit/extensions/text"`.'
1400
- );
1401
- return defineNodeSpec({
1402
- name: "text",
1403
- group: "inline"
1404
- });
1482
+ console.warn("[prosekit] The `defineText` function from `prosekit/core` is deprecated. Use the following import instead: `import { defineText } from \"prosekit/extensions/text\"`.");
1483
+ return defineNodeSpec({
1484
+ name: "text",
1485
+ group: "inline"
1486
+ });
1405
1487
  }
1406
1488
 
1407
- // src/utils/cache.ts
1489
+ //#endregion
1490
+ //#region src/utils/cache.ts
1408
1491
  function cache(fn) {
1409
- let result = void 0;
1410
- return () => {
1411
- if (result === void 0) {
1412
- result = fn();
1413
- }
1414
- return result;
1415
- };
1416
- }
1417
-
1418
- // src/utils/can-use-regex-lookbehind.ts
1419
- var canUseRegexLookbehind = cache(() => {
1420
- try {
1421
- return "ab".replace(new RegExp("(?<=a)b", "g"), "c") === "ac";
1422
- } catch {
1423
- return false;
1424
- }
1492
+ let result = void 0;
1493
+ return () => {
1494
+ if (result === void 0) result = fn();
1495
+ return result;
1496
+ };
1497
+ }
1498
+
1499
+ //#endregion
1500
+ //#region src/utils/can-use-regex-lookbehind.ts
1501
+ const canUseRegexLookbehind = cache(() => {
1502
+ try {
1503
+ return "ab".replace(new RegExp("(?<=a)b", "g"), "c") === "ac";
1504
+ } catch {
1505
+ return false;
1506
+ }
1425
1507
  });
1426
1508
 
1427
- // src/utils/clsx.ts
1428
- import clsxLite from "clsx/lite";
1429
- var clsx = clsxLite;
1430
-
1431
- // src/utils/collect-children.ts
1509
+ //#endregion
1510
+ //#region src/utils/clsx.ts
1511
+ /**
1512
+ * A utility for constructing `className` strings conditionally.
1513
+ *
1514
+ * It is a re-export of [clsx/lite](https://www.npmjs.com/package/clsx) with stricter types.
1515
+ *
1516
+ * @public
1517
+ */
1518
+ const clsx = clsxLite;
1519
+
1520
+ //#endregion
1521
+ //#region src/utils/collect-children.ts
1522
+ /**
1523
+ * Collects all children of a node or a fragment, and returns them as an array.
1524
+ *
1525
+ * @public
1526
+ */
1432
1527
  function collectChildren(parent) {
1433
- const children = [];
1434
- for (let i = 0; i < parent.childCount; i++) {
1435
- children.push(parent.child(i));
1436
- }
1437
- return children;
1438
- }
1439
-
1440
- // src/utils/collect-nodes.ts
1441
- import {
1442
- ProseMirrorFragment,
1443
- ProseMirrorNode
1444
- } from "@prosekit/pm/model";
1528
+ const children = [];
1529
+ for (let i = 0; i < parent.childCount; i++) children.push(parent.child(i));
1530
+ return children;
1531
+ }
1532
+
1533
+ //#endregion
1534
+ //#region src/utils/collect-nodes.ts
1535
+ /**
1536
+ * Collects all nodes from a given content.
1537
+ *
1538
+ * @deprecated Use `collectChildren` instead.
1539
+ *
1540
+ * @public
1541
+ */
1445
1542
  function collectNodes(content) {
1446
- if (Array.isArray(content)) {
1447
- return content.flatMap(collectNodes);
1448
- }
1449
- if (content instanceof ProseMirrorNode) {
1450
- return [content];
1451
- }
1452
- if (content instanceof ProseMirrorFragment) {
1453
- const nodes = [];
1454
- for (let i = 0; i < content.childCount; i++) {
1455
- nodes.push(content.child(i));
1456
- }
1457
- return nodes;
1458
- }
1459
- throw new ProseKitError(`Invalid node content: ${typeof content}`);
1460
- }
1461
-
1462
- // src/utils/contains-inline-node.ts
1543
+ if (Array.isArray(content)) return content.flatMap(collectNodes);
1544
+ if (content instanceof ProseMirrorNode) return [content];
1545
+ if (content instanceof ProseMirrorFragment) {
1546
+ const nodes = [];
1547
+ for (let i = 0; i < content.childCount; i++) nodes.push(content.child(i));
1548
+ return nodes;
1549
+ }
1550
+ throw new ProseKitError(`Invalid node content: ${typeof content}`);
1551
+ }
1552
+
1553
+ //#endregion
1554
+ //#region src/utils/contains-inline-node.ts
1555
+ /**
1556
+ * @internal
1557
+ */
1463
1558
  function containsInlineNode(doc, from, to) {
1464
- let found = false;
1465
- doc.nodesBetween(from, to, (node) => {
1466
- if (found) return false;
1467
- if (node.isInline) found = true;
1468
- });
1469
- return found;
1470
- }
1471
-
1472
- // src/utils/get-id.ts
1473
- var id = 0;
1559
+ let found = false;
1560
+ doc.nodesBetween(from, to, (node) => {
1561
+ if (found) return false;
1562
+ if (node.isInline) found = true;
1563
+ });
1564
+ return found;
1565
+ }
1566
+
1567
+ //#endregion
1568
+ //#region src/utils/get-id.ts
1569
+ let id = 0;
1570
+ /**
1571
+ * Returns a unique id in the current process that can be used in various places.
1572
+ *
1573
+ * @internal
1574
+ */
1474
1575
  function getId() {
1475
- id = (id + 1) % Number.MAX_SAFE_INTEGER;
1476
- return `id:${id}`;
1576
+ id = (id + 1) % Number.MAX_SAFE_INTEGER;
1577
+ return `id:${id}`;
1477
1578
  }
1478
1579
 
1479
- // src/utils/is-at-block-start.ts
1580
+ //#endregion
1581
+ //#region src/utils/is-at-block-start.ts
1582
+ /**
1583
+ * Whether the selection is an empty text selection at the start of a block.
1584
+ *
1585
+ * @internal
1586
+ */
1480
1587
  function isAtBlockStart(state, view) {
1481
- const { $cursor } = state.selection;
1482
- if (!$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0)) {
1483
- return null;
1484
- }
1485
- return $cursor;
1588
+ const { $cursor } = state.selection;
1589
+ if (!$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0)) return null;
1590
+ return $cursor;
1486
1591
  }
1487
1592
 
1488
- // src/utils/is-in-code-block.ts
1593
+ //#endregion
1594
+ //#region src/utils/is-in-code-block.ts
1489
1595
  function isCodeBlockType(type) {
1490
- return !!(type.spec.code && type.isBlock);
1596
+ return !!(type.spec.code && type.isBlock);
1491
1597
  }
1598
+ /**
1599
+ * Check if the selection is in a code block.
1600
+ *
1601
+ * @internal
1602
+ */
1492
1603
  function isInCodeBlock(selection) {
1493
- return isCodeBlockType(selection.$from.parent.type) || isCodeBlockType(selection.$to.parent.type);
1604
+ return isCodeBlockType(selection.$from.parent.type) || isCodeBlockType(selection.$to.parent.type);
1494
1605
  }
1495
1606
 
1496
- // src/utils/maybe-run.ts
1607
+ //#endregion
1608
+ //#region src/utils/maybe-run.ts
1609
+ /**
1610
+ * @internal
1611
+ */
1497
1612
  function maybeRun(value, ...args) {
1498
- return typeof value === "function" ? value(...args) : value;
1613
+ return typeof value === "function" ? value(...args) : value;
1499
1614
  }
1500
1615
 
1501
- // src/utils/unicode.ts
1502
- var OBJECT_REPLACEMENT_CHARACTER = "\uFFFC";
1616
+ //#endregion
1617
+ //#region src/utils/unicode.ts
1618
+ /**
1619
+ * @internal
1620
+ */
1621
+ const OBJECT_REPLACEMENT_CHARACTER = "";
1503
1622
 
1504
- // src/utils/with-skip-code-block.ts
1623
+ //#endregion
1624
+ //#region src/utils/with-skip-code-block.ts
1625
+ /**
1626
+ * @internal
1627
+ */
1505
1628
  function withSkipCodeBlock(command) {
1506
- return (state, dispatch, view) => {
1507
- if (isInCodeBlock(state.selection)) {
1508
- return false;
1509
- }
1510
- return command(state, dispatch, view);
1511
- };
1512
- }
1513
- export {
1514
- Editor,
1515
- EditorNotFoundError,
1516
- OBJECT_REPLACEMENT_CHARACTER,
1517
- Priority,
1518
- ProseKitError,
1519
- getId as _getId,
1520
- addMark,
1521
- assert,
1522
- canUseRegexLookbehind,
1523
- clsx,
1524
- collectChildren,
1525
- collectNodes,
1526
- containsInlineNode,
1527
- createEditor,
1528
- defaultBlockAt,
1529
- defineBaseCommands,
1530
- defineBaseKeymap,
1531
- defineClickHandler,
1532
- defineClickOnHandler,
1533
- defineClipboardSerializer,
1534
- defineCommands,
1535
- defineDOMEventHandler,
1536
- defineDefaultState,
1537
- defineDoc,
1538
- defineDocChangeHandler,
1539
- defineDoubleClickHandler,
1540
- defineDoubleClickOnHandler,
1541
- defineDropHandler,
1542
- defineFacet,
1543
- defineFacetPayload,
1544
- defineFocusChangeHandler,
1545
- defineHistory,
1546
- defineKeyDownHandler,
1547
- defineKeyPressHandler,
1548
- defineKeymap,
1549
- defineMarkAttr,
1550
- defineMarkSpec,
1551
- defineMarkView,
1552
- defineMarkViewComponent,
1553
- defineMarkViewFactory,
1554
- defineMountHandler,
1555
- defineNodeAttr,
1556
- defineNodeSpec,
1557
- defineNodeView,
1558
- defineNodeViewComponent,
1559
- defineNodeViewFactory,
1560
- defineParagraph,
1561
- definePasteHandler,
1562
- definePlugin,
1563
- defineScrollToSelectionHandler,
1564
- defineText,
1565
- defineTextInputHandler,
1566
- defineTripleClickHandler,
1567
- defineTripleClickOnHandler,
1568
- defineUnmountHandler,
1569
- defineUpdateHandler,
1570
- editorEventFacet,
1571
- elementFromJSON,
1572
- elementFromNode,
1573
- expandMark,
1574
- findParentNode,
1575
- findParentNodeOfType,
1576
- getMarkType,
1577
- getNodeType,
1578
- htmlFromJSON,
1579
- htmlFromNode,
1580
- insertDefaultBlock,
1581
- insertNode,
1582
- isAllSelection,
1583
- isApple,
1584
- isAtBlockStart,
1585
- isElement,
1586
- isFragment,
1587
- isInCodeBlock,
1588
- isMark,
1589
- isMarkAbsent,
1590
- isMarkActive,
1591
- isNodeSelection,
1592
- isProseMirrorNode,
1593
- isSelection,
1594
- isSlice,
1595
- isTextSelection,
1596
- jsonFromHTML,
1597
- jsonFromNode,
1598
- jsonFromState,
1599
- keymapFacet,
1600
- maybeRun,
1601
- nodeFromElement,
1602
- nodeFromHTML,
1603
- nodeFromJSON,
1604
- pluginFacet,
1605
- removeMark,
1606
- removeNode,
1607
- setBlockType,
1608
- setNodeAttrs,
1609
- setSelectionAround,
1610
- stateFromJSON,
1611
- toggleMark,
1612
- toggleNode,
1613
- toggleWrap,
1614
- union,
1615
- unsetBlockType,
1616
- unsetMark,
1617
- withPriority,
1618
- withSkipCodeBlock,
1619
- wrap
1620
- };
1629
+ return (state, dispatch, view) => {
1630
+ if (isInCodeBlock(state.selection)) return false;
1631
+ return command(state, dispatch, view);
1632
+ };
1633
+ }
1634
+
1635
+ //#endregion
1636
+ export { Editor, EditorNotFoundError, OBJECT_REPLACEMENT_CHARACTER, Priority, ProseKitError, getId as _getId, addMark, assert, canUseRegexLookbehind, clsx, collectChildren, collectNodes, containsInlineNode, createEditor, defaultBlockAt, defineBaseCommands, defineBaseKeymap, defineClickHandler, defineClickOnHandler, defineClipboardSerializer, defineCommands, defineDOMEventHandler, defineDefaultState, defineDoc, defineDocChangeHandler, defineDoubleClickHandler, defineDoubleClickOnHandler, defineDropHandler, defineFacet, defineFacetPayload, defineFocusChangeHandler, defineHistory, defineKeyDownHandler, defineKeyPressHandler, defineKeymap, defineMarkAttr, defineMarkSpec, defineMarkView, defineMarkViewComponent, defineMarkViewFactory, defineMountHandler, defineNodeAttr, defineNodeSpec, defineNodeView, defineNodeViewComponent, defineNodeViewFactory, defineParagraph, definePasteHandler, definePlugin, defineScrollToSelectionHandler, defineText, defineTextInputHandler, defineTripleClickHandler, defineTripleClickOnHandler, defineUnmountHandler, defineUpdateHandler, editorEventFacet, elementFromJSON, elementFromNode, expandMark, findParentNode, findParentNodeOfType, getMarkType, getNodeType, htmlFromJSON, htmlFromNode, insertDefaultBlock, insertNode, isAllSelection, isApple, isAtBlockStart, isFragment, isInCodeBlock, isMark, isMarkAbsent, isMarkActive, isNodeSelection, isProseMirrorNode, isSelection, isSlice, isTextSelection, jsonFromHTML, jsonFromNode, jsonFromState, keymapFacet, maybeRun, nodeFromElement, nodeFromHTML, nodeFromJSON, pluginFacet, removeMark, removeNode, setBlockType, setNodeAttrs, setSelectionAround, stateFromJSON, toggleMark, toggleNode, toggleWrap, union, unsetBlockType, unsetMark, withPriority, withSkipCodeBlock, wrap };