@prosekit/core 0.7.2 → 0.7.3

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.
@@ -35,7 +35,7 @@ import {
35
35
  stateFromJSON,
36
36
  toReversed,
37
37
  union
38
- } from "./chunk-YWQGKV6X.js";
38
+ } from "./chunk-UDQXAK7F.js";
39
39
 
40
40
  // src/commands/add-mark.ts
41
41
  import "@prosekit/pm/model";
@@ -43,8 +43,14 @@ import "@prosekit/pm/state";
43
43
  function addMark(options) {
44
44
  return (state, dispatch) => {
45
45
  var _a, _b;
46
- let mark = getMarkType(state.schema, options.type).create(options.attrs), from = (_a = options.from) != null ? _a : state.selection.from, to = (_b = options.to) != null ? _b : state.selection.to;
47
- return from > to ? !1 : (dispatch == null || dispatch(state.tr.addMark(from, to, mark)), !0);
46
+ const mark = getMarkType(state.schema, options.type).create(options.attrs);
47
+ const from = (_a = options.from) != null ? _a : state.selection.from;
48
+ const to = (_b = options.to) != null ? _b : state.selection.to;
49
+ if (from > to) {
50
+ return false;
51
+ }
52
+ dispatch == null ? void 0 : dispatch(state.tr.addMark(from, to, mark));
53
+ return true;
48
54
  };
49
55
  }
50
56
 
@@ -52,26 +58,52 @@ function addMark(options) {
52
58
  import { TextSelection } from "@prosekit/pm/state";
53
59
  function expandMark(options) {
54
60
  return (state, dispatch) => {
55
- let markType = getMarkType(state.schema, options.type), predicate = (mark) => mark.type === markType, from = expandMarkBefore(state.selection.$from, predicate), to = expandMarkAfter(state.selection.$to, predicate);
56
- return from === state.selection.from && to === state.selection.to ? !1 : (dispatch && dispatch(state.tr.setSelection(TextSelection.create(state.doc, from, to))), !0);
61
+ const markType = getMarkType(state.schema, options.type);
62
+ const predicate = (mark) => mark.type === markType;
63
+ const from = expandMarkBefore(state.selection.$from, predicate);
64
+ const to = expandMarkAfter(state.selection.$to, predicate);
65
+ if (from === state.selection.from && to === state.selection.to) {
66
+ return false;
67
+ }
68
+ if (dispatch) {
69
+ dispatch(state.tr.setSelection(TextSelection.create(state.doc, from, to)));
70
+ }
71
+ return true;
57
72
  };
58
73
  }
59
74
  function expandMarkBefore($pos, predicate) {
60
- let { parent } = $pos;
61
- if (!$pos.marks().some(predicate))
75
+ const { parent } = $pos;
76
+ if (!$pos.marks().some(predicate)) {
62
77
  return $pos.pos;
63
- let index = $pos.index(), boundaryIndex = index;
64
- for (let i = index; i >= 0 && parent.child(i).marks.some(predicate); i--)
65
- boundaryIndex = i;
78
+ }
79
+ const index = $pos.index();
80
+ let boundaryIndex = index;
81
+ for (let i = index; i >= 0; i--) {
82
+ const node = parent.child(i);
83
+ if (node.marks.some(predicate)) {
84
+ boundaryIndex = i;
85
+ } else {
86
+ break;
87
+ }
88
+ }
66
89
  return $pos.posAtIndex(boundaryIndex);
67
90
  }
68
91
  function expandMarkAfter($pos, predicate) {
69
- let { parent } = $pos;
70
- if (!$pos.marks().some(predicate))
92
+ const { parent } = $pos;
93
+ if (!$pos.marks().some(predicate)) {
71
94
  return $pos.pos;
72
- let index = Math.max(0, $pos.indexAfter() - 1), childCount = parent.childCount, boundaryIndex = index;
73
- for (let i = index; i < childCount && parent.child(i).marks.some(predicate); i++)
74
- boundaryIndex = i;
95
+ }
96
+ const index = Math.max(0, $pos.indexAfter() - 1);
97
+ const childCount = parent.childCount;
98
+ let boundaryIndex = index;
99
+ for (let i = index; i < childCount; i++) {
100
+ const node = parent.child(i);
101
+ if (node.marks.some(predicate)) {
102
+ boundaryIndex = i;
103
+ } else {
104
+ break;
105
+ }
106
+ }
75
107
  return $pos.posAtIndex(boundaryIndex) + parent.child(boundaryIndex).nodeSize;
76
108
  }
77
109
 
@@ -82,7 +114,9 @@ import { insertPoint } from "@prosekit/pm/transform";
82
114
  // src/utils/set-selection-around.ts
83
115
  import { TextSelection as TextSelection2 } from "@prosekit/pm/state";
84
116
  function setSelectionAround(tr, pos) {
85
- let docSize = tr.doc.content.size, $pos = tr.doc.resolve(pos > docSize ? docSize : pos < 0 ? 0 : pos), selection = TextSelection2.between($pos, $pos);
117
+ const docSize = tr.doc.content.size;
118
+ const $pos = tr.doc.resolve(pos > docSize ? docSize : pos < 0 ? 0 : pos);
119
+ const selection = TextSelection2.between($pos, $pos);
86
120
  tr.setSelection(selection);
87
121
  }
88
122
 
@@ -90,19 +124,20 @@ function setSelectionAround(tr, pos) {
90
124
  function insertNode(options) {
91
125
  return (state, dispatch) => {
92
126
  var _a;
93
- let node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).createAndFill(options.attrs) : null;
127
+ const node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).createAndFill(options.attrs) : null;
94
128
  assert(node, "You must provide either a node or a type");
95
- let insertPos = insertPoint(
129
+ const insertPos = insertPoint(
96
130
  state.doc,
97
131
  (_a = options.pos) != null ? _a : state.selection.anchor,
98
132
  node.type
99
133
  );
100
- if (insertPos == null) return !1;
134
+ if (insertPos == null) return false;
101
135
  if (dispatch) {
102
- let tr = state.tr.insert(insertPos, node);
103
- setSelectionAround(tr, insertPos + node.nodeSize), dispatch(tr);
136
+ const tr = state.tr.insert(insertPos, node);
137
+ setSelectionAround(tr, insertPos + node.nodeSize);
138
+ dispatch(tr);
104
139
  }
105
- return !0;
140
+ return true;
106
141
  };
107
142
  }
108
143
 
@@ -112,21 +147,31 @@ import "@prosekit/pm/state";
112
147
  function removeMark(options) {
113
148
  return (state, dispatch) => {
114
149
  var _a, _b;
115
- let markType = getMarkType(state.schema, options.type), mark = options.attrs ? markType.create(options.attrs) : markType, from = (_a = options.from) != null ? _a : state.selection.from, to = (_b = options.to) != null ? _b : state.selection.to;
116
- return from > to ? !1 : (dispatch == null || dispatch(state.tr.removeMark(from, to, mark)), !0);
150
+ const markType = getMarkType(state.schema, options.type);
151
+ const mark = options.attrs ? markType.create(options.attrs) : markType;
152
+ const from = (_a = options.from) != null ? _a : state.selection.from;
153
+ const to = (_b = options.to) != null ? _b : state.selection.to;
154
+ if (from > to) {
155
+ return false;
156
+ }
157
+ dispatch == null ? void 0 : dispatch(state.tr.removeMark(from, to, mark));
158
+ return true;
117
159
  };
118
160
  }
119
161
 
120
162
  // src/utils/find-parent-node.ts
121
163
  function findParentNode(nodeType, $pos) {
122
- for (let depth = $pos.depth; depth > 0; depth -= 1)
123
- if ($pos.node(depth).type === nodeType) {
124
- let from = $pos.before(depth), to = $pos.after(depth);
164
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
165
+ const node = $pos.node(depth);
166
+ if (node.type === nodeType) {
167
+ const from = $pos.before(depth);
168
+ const to = $pos.after(depth);
125
169
  return {
126
170
  from,
127
171
  to
128
172
  };
129
173
  }
174
+ }
130
175
  return {
131
176
  from: null,
132
177
  to: null
@@ -136,8 +181,14 @@ function findParentNode(nodeType, $pos) {
136
181
  // src/commands/remove-node.ts
137
182
  function removeNode(options) {
138
183
  return (state, dispatch) => {
139
- let nodeType = getNodeType(state.schema, options.type), $pos = typeof options.pos == "number" ? state.doc.resolve(options.pos) : state.selection.$anchor, { from, to } = findParentNode(nodeType, $pos);
140
- return from == null || to == null || from > to ? !1 : (dispatch == null || dispatch(state.tr.delete(from, to)), !0);
184
+ const nodeType = getNodeType(state.schema, options.type);
185
+ const $pos = typeof options.pos === "number" ? state.doc.resolve(options.pos) : state.selection.$anchor;
186
+ const { from, to } = findParentNode(nodeType, $pos);
187
+ if (from == null || to == null || from > to) {
188
+ return false;
189
+ }
190
+ dispatch == null ? void 0 : dispatch(state.tr.delete(from, to));
191
+ return true;
141
192
  };
142
193
  }
143
194
 
@@ -147,9 +198,10 @@ import "@prosekit/pm/state";
147
198
  // src/utils/get-custom-selection.ts
148
199
  import { TextSelection as TextSelection3 } from "@prosekit/pm/state";
149
200
  function getCustomSelection(state, from, to) {
150
- let pos = from != null ? from : to;
201
+ const pos = from != null ? from : to;
151
202
  if (pos != null) {
152
- let $from = state.doc.resolve(from != null ? from : pos), $to = state.doc.resolve(to != null ? to : pos);
203
+ const $from = state.doc.resolve(from != null ? from : pos);
204
+ const $to = state.doc.resolve(to != null ? to : pos);
153
205
  return TextSelection3.between($from, $to);
154
206
  }
155
207
  return state.selection;
@@ -158,28 +210,31 @@ function getCustomSelection(state, from, to) {
158
210
  // src/commands/set-block-type.ts
159
211
  function setBlockType(options) {
160
212
  return (state, dispatch) => {
161
- let nodeType = getNodeType(state.schema, options.type), selection = getCustomSelection(state, options.from, options.to), attrs = options.attrs, applicable = !1;
213
+ const nodeType = getNodeType(state.schema, options.type);
214
+ const selection = getCustomSelection(state, options.from, options.to);
215
+ const attrs = options.attrs;
216
+ let applicable = false;
162
217
  for (let i = 0; i < selection.ranges.length && !applicable; i++) {
163
- let {
218
+ const {
164
219
  $from: { pos: from },
165
220
  $to: { pos: to }
166
221
  } = selection.ranges[i];
167
222
  state.doc.nodesBetween(from, to, (node, pos) => {
168
- if (applicable) return !1;
169
- if (!(!node.isTextblock || node.hasMarkup(nodeType, attrs)))
170
- if (node.type == nodeType)
171
- applicable = !0;
172
- else {
173
- let $pos = state.doc.resolve(pos), index = $pos.index();
174
- applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType);
175
- }
223
+ if (applicable) return false;
224
+ if (!node.isTextblock || node.hasMarkup(nodeType, attrs)) return;
225
+ if (node.type == nodeType) {
226
+ applicable = true;
227
+ } else {
228
+ const $pos = state.doc.resolve(pos), index = $pos.index();
229
+ applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType);
230
+ }
176
231
  });
177
232
  }
178
- if (!applicable) return !1;
233
+ if (!applicable) return false;
179
234
  if (dispatch) {
180
- let tr = state.tr;
181
- for (let range of selection.ranges) {
182
- let {
235
+ const tr = state.tr;
236
+ for (const range of selection.ranges) {
237
+ const {
183
238
  $from: { pos: from },
184
239
  $to: { pos: to }
185
240
  } = range;
@@ -187,34 +242,48 @@ function setBlockType(options) {
187
242
  }
188
243
  dispatch(tr.scrollIntoView());
189
244
  }
190
- return !0;
245
+ return true;
191
246
  };
192
247
  }
193
248
 
194
249
  // src/utils/get-node-types.ts
195
250
  import "@prosekit/pm/model";
196
251
  function getNodeTypes(schema, types) {
197
- return Array.isArray(types) ? types.map((type) => getNodeType(schema, type)) : [getNodeType(schema, types)];
252
+ if (Array.isArray(types)) {
253
+ return types.map((type) => getNodeType(schema, type));
254
+ }
255
+ return [getNodeType(schema, types)];
198
256
  }
199
257
 
200
258
  // src/commands/set-node-attrs.ts
201
259
  function setNodeAttrs(options) {
202
260
  return (state, dispatch) => {
203
261
  var _a, _b;
204
- let nodeTypes = getNodeTypes(state.schema, options.type), from = (_a = options.pos) != null ? _a : state.selection.from, to = (_b = options.pos) != null ? _b : state.selection.to, positions = [];
205
- if (state.doc.nodesBetween(from, to, (node, pos) => {
206
- if (nodeTypes.includes(node.type) && positions.push(pos), !dispatch && positions.length > 0)
207
- return !1;
208
- }), positions.length === 0)
209
- return !1;
262
+ const nodeTypes = getNodeTypes(state.schema, options.type);
263
+ const from = (_a = options.pos) != null ? _a : state.selection.from;
264
+ const to = (_b = options.pos) != null ? _b : state.selection.to;
265
+ const positions = [];
266
+ state.doc.nodesBetween(from, to, (node, pos) => {
267
+ if (nodeTypes.includes(node.type)) {
268
+ positions.push(pos);
269
+ }
270
+ if (!dispatch && positions.length > 0) {
271
+ return false;
272
+ }
273
+ });
274
+ if (positions.length === 0) {
275
+ return false;
276
+ }
210
277
  if (dispatch) {
211
- let { tr } = state;
212
- for (let pos of positions)
213
- for (let [key, value] of Object.entries(options.attrs))
278
+ const { tr } = state;
279
+ for (const pos of positions) {
280
+ for (const [key, value] of Object.entries(options.attrs)) {
214
281
  tr.setNodeAttribute(pos, key, value);
282
+ }
283
+ }
215
284
  dispatch(tr);
216
285
  }
217
- return !0;
286
+ return true;
218
287
  };
219
288
  }
220
289
 
@@ -222,56 +291,76 @@ function setNodeAttrs(options) {
222
291
  import "@prosekit/pm/model";
223
292
  import "@prosekit/pm/state";
224
293
  function markApplies(doc, ranges, type) {
225
- for (let { $from, $to } of ranges) {
226
- let can = $from.depth == 0 ? doc.inlineContent && doc.type.allowsMarkType(type) : !1;
227
- if (doc.nodesBetween($from.pos, $to.pos, (node) => {
228
- if (can) return !1;
294
+ for (const { $from, $to } of ranges) {
295
+ let can = $from.depth == 0 ? doc.inlineContent && doc.type.allowsMarkType(type) : false;
296
+ doc.nodesBetween($from.pos, $to.pos, (node) => {
297
+ if (can) return false;
229
298
  can = node.inlineContent && node.type.allowsMarkType(type);
230
- }), can) return !0;
299
+ });
300
+ if (can) return true;
231
301
  }
232
- return !1;
302
+ return false;
233
303
  }
234
304
  function baseToggleMark(markType, attrs = null, options) {
235
- let removeWhenPresent = (options && options.removeWhenPresent) !== !1;
305
+ const removeWhenPresent = (options && options.removeWhenPresent) !== false;
236
306
  return function(state, dispatch) {
237
- let { empty, $cursor, ranges } = state.selection;
307
+ const { empty, $cursor, ranges } = state.selection;
238
308
  if (empty && !$cursor || !markApplies(state.doc, ranges, markType))
239
- return !1;
240
- if (dispatch)
241
- if ($cursor)
242
- markType.isInSet(state.storedMarks || $cursor.marks()) ? dispatch(state.tr.removeStoredMark(markType)) : dispatch(state.tr.addStoredMark(markType.create(attrs)));
243
- else {
244
- let add, tr = state.tr;
245
- removeWhenPresent ? add = !ranges.some(
246
- (r) => state.doc.rangeHasMark(r.$from.pos, r.$to.pos, markType)
247
- ) : add = !ranges.every((r) => {
248
- let missing = !1;
249
- return tr.doc.nodesBetween(r.$from.pos, r.$to.pos, (node, pos, parent) => {
250
- if (missing) return !1;
251
- missing = !markType.isInSet(node.marks) && !!parent && parent.type.allowsMarkType(markType) && !(node.isText && /^\s*$/.test(
252
- node.textBetween(
253
- Math.max(0, r.$from.pos - pos),
254
- Math.min(node.nodeSize, r.$to.pos - pos)
255
- )
256
- ));
257
- }), !missing;
258
- });
259
- for (let { $from, $to } of ranges)
260
- if (!add)
309
+ return false;
310
+ if (dispatch) {
311
+ if ($cursor) {
312
+ if (markType.isInSet(state.storedMarks || $cursor.marks()))
313
+ dispatch(state.tr.removeStoredMark(markType));
314
+ else dispatch(state.tr.addStoredMark(markType.create(attrs)));
315
+ } else {
316
+ let add;
317
+ const tr = state.tr;
318
+ if (removeWhenPresent) {
319
+ add = !ranges.some(
320
+ (r) => state.doc.rangeHasMark(r.$from.pos, r.$to.pos, markType)
321
+ );
322
+ } else {
323
+ add = !ranges.every((r) => {
324
+ let missing = false;
325
+ tr.doc.nodesBetween(r.$from.pos, r.$to.pos, (node, pos, parent) => {
326
+ if (missing) return false;
327
+ missing = !markType.isInSet(node.marks) && !!parent && parent.type.allowsMarkType(markType) && !(node.isText && /^\s*$/.test(
328
+ node.textBetween(
329
+ Math.max(0, r.$from.pos - pos),
330
+ Math.min(node.nodeSize, r.$to.pos - pos)
331
+ )
332
+ ));
333
+ });
334
+ return !missing;
335
+ });
336
+ }
337
+ for (const { $from, $to } of ranges) {
338
+ if (!add) {
261
339
  tr.removeMark($from.pos, $to.pos, markType);
262
- else {
263
- let from = $from.pos, to = $to.pos, start = $from.nodeAfter, end = $to.nodeBefore, spaceStart = start && start.isText ? /^\s*/.exec(start.text)[0].length : 0, spaceEnd = end && end.isText ? /\s*$/.exec(end.text)[0].length : 0;
264
- from + spaceStart < to && (from += spaceStart, to -= spaceEnd), tr.addMark(from, to, markType.create(attrs));
340
+ } else {
341
+ let from = $from.pos, to = $to.pos;
342
+ const start = $from.nodeAfter, end = $to.nodeBefore;
343
+ const spaceStart = start && start.isText ? /^\s*/.exec(start.text)[0].length : 0;
344
+ const spaceEnd = end && end.isText ? /\s*$/.exec(end.text)[0].length : 0;
345
+ if (from + spaceStart < to) {
346
+ from += spaceStart;
347
+ to -= spaceEnd;
348
+ }
349
+ tr.addMark(from, to, markType.create(attrs));
265
350
  }
351
+ }
266
352
  dispatch(tr.scrollIntoView());
267
353
  }
268
- return !0;
354
+ }
355
+ return true;
269
356
  };
270
357
  }
271
358
  function toggleMark({ type, attrs }) {
272
- return (state, dispatch, view) => baseToggleMark(getMarkType(state.schema, type), attrs, {
273
- removeWhenPresent: !1
274
- })(state, dispatch, view);
359
+ return (state, dispatch, view) => {
360
+ return baseToggleMark(getMarkType(state.schema, type), attrs, {
361
+ removeWhenPresent: false
362
+ })(state, dispatch, view);
363
+ };
275
364
  }
276
365
 
277
366
  // src/commands/toggle-node.ts
@@ -281,10 +370,13 @@ import "@prosekit/pm/state";
281
370
  function toggleNode({ type, attrs }) {
282
371
  return (state, dispatch, view) => {
283
372
  if (isNodeActive(state, type, attrs)) {
284
- let defaultType = state.schema.topNodeType.contentMatch.defaultType;
285
- return defaultType ? setBlockType2(defaultType)(state, dispatch, view) : !1;
373
+ const defaultType = state.schema.topNodeType.contentMatch.defaultType;
374
+ if (!defaultType) {
375
+ return false;
376
+ }
377
+ return setBlockType2(defaultType)(state, dispatch, view);
286
378
  } else {
287
- let nodeType = getNodeType(state.schema, type);
379
+ const nodeType = getNodeType(state.schema, type);
288
380
  return setBlockType2(nodeType, attrs)(state, dispatch, view);
289
381
  }
290
382
  };
@@ -297,31 +389,40 @@ import { ReplaceAroundStep } from "@prosekit/pm/transform";
297
389
  function unsetBlockType(options) {
298
390
  return (state, dispatch) => {
299
391
  var _a, _b;
300
- let from = (_a = options == null ? void 0 : options.from) != null ? _a : state.selection.from, to = (_b = options == null ? void 0 : options.to) != null ? _b : state.selection.to;
301
- if (from > to) return !1;
302
- let tr = state.tr;
303
- return unsetTextBlockType(tr, from, to) ? (dispatch == null || dispatch(tr), !0) : !1;
392
+ const from = (_a = options == null ? void 0 : options.from) != null ? _a : state.selection.from;
393
+ const to = (_b = options == null ? void 0 : options.to) != null ? _b : state.selection.to;
394
+ if (from > to) return false;
395
+ const tr = state.tr;
396
+ if (unsetTextBlockType(tr, from, to)) {
397
+ dispatch == null ? void 0 : dispatch(tr);
398
+ return true;
399
+ }
400
+ return false;
304
401
  };
305
402
  }
306
403
  function unsetTextBlockType(tr, from, to) {
307
- let mapFrom = tr.steps.length;
308
- return tr.doc.nodesBetween(from, to, (node, pos, parent, index) => {
309
- if (!parent || !node.isTextblock) return !0;
310
- let defaultType = parent.contentMatchAt(index).defaultType;
404
+ const mapFrom = tr.steps.length;
405
+ tr.doc.nodesBetween(from, to, (node, pos, parent, index) => {
406
+ if (!parent || !node.isTextblock) return true;
407
+ const defaultType = parent.contentMatchAt(index).defaultType;
311
408
  if (defaultType && defaultType.isTextblock && node.type !== defaultType && defaultType.validContent(node.content)) {
312
- let mapping = tr.mapping.slice(mapFrom), start = mapping.map(pos, 1), end = mapping.map(pos + node.nodeSize, 1), step = new ReplaceAroundStep(
409
+ const mapping = tr.mapping.slice(mapFrom);
410
+ const start = mapping.map(pos, 1);
411
+ const end = mapping.map(pos + node.nodeSize, 1);
412
+ const step = new ReplaceAroundStep(
313
413
  start,
314
414
  end,
315
415
  start + 1,
316
416
  end - 1,
317
417
  new Slice(Fragment.from(defaultType.create()), 0, 0),
318
418
  1,
319
- !0
419
+ true
320
420
  );
321
421
  tr.step(step);
322
422
  }
323
- return !1;
324
- }), tr.steps.length > mapFrom;
423
+ return false;
424
+ });
425
+ return tr.steps.length > mapFrom;
325
426
  }
326
427
 
327
428
  // src/commands/unset-mark.ts
@@ -329,8 +430,11 @@ import "@prosekit/pm/state";
329
430
  function unsetMark(options) {
330
431
  return (state, dispatch) => {
331
432
  var _a, _b;
332
- let from = (_a = options == null ? void 0 : options.from) != null ? _a : state.selection.from, to = (_b = options == null ? void 0 : options.to) != null ? _b : state.selection.to;
333
- return from > to ? !1 : (dispatch == null || dispatch(state.tr.removeMark(from, to)), !0);
433
+ const from = (_a = options == null ? void 0 : options.from) != null ? _a : state.selection.from;
434
+ const to = (_b = options == null ? void 0 : options.to) != null ? _b : state.selection.to;
435
+ if (from > to) return false;
436
+ dispatch == null ? void 0 : dispatch(state.tr.removeMark(from, to));
437
+ return true;
334
438
  };
335
439
  }
336
440
 
@@ -340,17 +444,21 @@ import "@prosekit/pm/state";
340
444
  import { findWrapping } from "@prosekit/pm/transform";
341
445
  function wrap({ nodeType, attrs }) {
342
446
  return (state, dispatch) => {
343
- let { $from, $to } = state.selection, range = $from.blockRange($to);
344
- if (!range) return !1;
345
- let wrapping = findWrapping(range, nodeType, attrs);
346
- return wrapping ? (dispatch == null || dispatch(state.tr.wrap(range, wrapping)), !0) : !1;
447
+ const { $from, $to } = state.selection;
448
+ const range = $from.blockRange($to);
449
+ if (!range) return false;
450
+ const wrapping = findWrapping(range, nodeType, attrs);
451
+ if (!wrapping) return false;
452
+ dispatch == null ? void 0 : dispatch(state.tr.wrap(range, wrapping));
453
+ return true;
347
454
  };
348
455
  }
349
456
 
350
457
  // src/editor/with-priority.ts
351
458
  function withPriority(extension, priority) {
352
- let result = union(extension);
353
- return result.priority = priority, result;
459
+ const result = union(extension);
460
+ result.priority = priority;
461
+ return result;
354
462
  }
355
463
 
356
464
  // src/commands/insert-text.ts
@@ -359,25 +467,36 @@ function insertText({
359
467
  from,
360
468
  to
361
469
  }) {
362
- return (state, dispatch) => (text && (dispatch == null || dispatch(state.tr.insertText(text, from, to))), !0);
470
+ return (state, dispatch) => {
471
+ if (text) {
472
+ dispatch == null ? void 0 : dispatch(state.tr.insertText(text, from, to));
473
+ }
474
+ return true;
475
+ };
363
476
  }
364
477
 
365
478
  // src/commands/select-all.ts
366
479
  import { AllSelection } from "@prosekit/pm/state";
367
480
  function selectAll() {
368
- return (state, dispatch) => (dispatch == null || dispatch(state.tr.setSelection(new AllSelection(state.doc))), !0);
481
+ return (state, dispatch) => {
482
+ dispatch == null ? void 0 : dispatch(state.tr.setSelection(new AllSelection(state.doc)));
483
+ return true;
484
+ };
369
485
  }
370
486
 
371
487
  // src/facets/command.ts
372
488
  var commandFacet = defineFacet({
373
- reducer: (inputs) => ({ commands: Object.assign({}, ...inputs) }),
489
+ reducer: (inputs) => {
490
+ const commands2 = Object.assign({}, ...inputs);
491
+ return { commands: commands2 };
492
+ },
374
493
  parent: rootFacet,
375
- singleton: !0
494
+ singleton: true
376
495
  });
377
496
 
378
497
  // src/extensions/command.ts
379
- function defineCommands(commands) {
380
- return defineFacetPayload(commandFacet, [commands]);
498
+ function defineCommands(commands2) {
499
+ return defineFacetPayload(commandFacet, [commands2]);
381
500
  }
382
501
  function defineBaseCommands() {
383
502
  return defineCommands({
@@ -404,34 +523,49 @@ import OrderedMap from "orderedmap";
404
523
  var schemaSpecFacet = defineFacet({
405
524
  reducer: (specs) => {
406
525
  var _a;
407
- let nodes = OrderedMap.from({}), marks = OrderedMap.from({}), topNode;
408
- for (let spec of specs)
409
- nodes = nodes.append(spec.nodes), marks = marks.append((_a = spec.marks) != null ? _a : {}), topNode = topNode != null ? topNode : spec.topNode;
526
+ let nodes = OrderedMap.from({});
527
+ let marks = OrderedMap.from({});
528
+ let topNode = void 0;
529
+ for (const spec of specs) {
530
+ nodes = nodes.append(spec.nodes);
531
+ marks = marks.append((_a = spec.marks) != null ? _a : {});
532
+ topNode = topNode != null ? topNode : spec.topNode;
533
+ }
410
534
  return { nodes, marks, topNode };
411
535
  },
412
536
  parent: schemaFacet,
413
- singleton: !0
537
+ singleton: true
414
538
  });
415
539
 
416
540
  // src/utils/is-element.ts
417
- var hasElement = typeof Element != "undefined";
541
+ var hasElement = typeof Element !== "undefined";
418
542
  function isElement(value) {
419
543
  return hasElement && value instanceof Element;
420
544
  }
421
545
 
422
546
  // src/extensions/node-spec.ts
423
547
  function defineNodeSpec(options) {
424
- return defineFacetPayload(nodeSpecFacet, [[options, void 0]]);
548
+ const payload = [options, void 0];
549
+ return defineFacetPayload(nodeSpecFacet, [payload]);
425
550
  }
426
551
  function defineNodeAttr(options) {
427
- return defineFacetPayload(nodeSpecFacet, [[void 0, options]]);
552
+ const payload = [void 0, options];
553
+ return defineFacetPayload(nodeSpecFacet, [payload]);
428
554
  }
429
555
  var nodeSpecFacet = defineFacet({
430
556
  reducer: (payloads) => {
431
- let nodes = OrderedMap2.from({}), topNodeName, specPayloads = payloads.map((input) => input[0]).filter(isNotNull), attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
432
- for (let { name, topNode, ...spec } of specPayloads)
433
- assert(!nodes.get(name), `Node type ${name} can only be defined once`), topNode && (topNodeName = name), nodes = nodes.addToStart(name, spec);
434
- for (let {
557
+ let nodes = OrderedMap2.from({});
558
+ let topNodeName = void 0;
559
+ const specPayloads = payloads.map((input) => input[0]).filter(isNotNull);
560
+ const attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
561
+ for (const { name, topNode, ...spec } of specPayloads) {
562
+ assert(!nodes.get(name), `Node type ${name} can only be defined once`);
563
+ if (topNode) {
564
+ topNodeName = name;
565
+ }
566
+ nodes = nodes.addToStart(name, spec);
567
+ }
568
+ for (const {
435
569
  type,
436
570
  attr,
437
571
  default: defaultValue,
@@ -439,57 +573,87 @@ var nodeSpecFacet = defineFacet({
439
573
  toDOM,
440
574
  parseDOM
441
575
  } of attrPayloads) {
442
- let spec = nodes.get(type);
443
- if (assert(spec, `Node type ${type} must be defined`), spec.attrs || (spec.attrs = {}), spec.attrs[attr] = {
576
+ const spec = nodes.get(type);
577
+ assert(spec, `Node type ${type} must be defined`);
578
+ if (!spec.attrs) {
579
+ spec.attrs = {};
580
+ }
581
+ spec.attrs[attr] = {
444
582
  default: defaultValue,
445
583
  splittable
446
- }, toDOM && spec.toDOM) {
447
- let existingToDom = spec.toDOM;
584
+ };
585
+ if (toDOM && spec.toDOM) {
586
+ const existingToDom = spec.toDOM;
448
587
  spec.toDOM = (node) => {
449
- let dom = existingToDom(node);
450
- if (!dom)
588
+ const dom = existingToDom(node);
589
+ if (!dom) {
451
590
  return dom;
452
- let attrDOM = toDOM(node.attrs[attr]);
453
- if (!attrDOM)
591
+ }
592
+ const attrDOM = toDOM(node.attrs[attr]);
593
+ if (!attrDOM) {
454
594
  return dom;
455
- let [key, value] = attrDOM;
456
- return key ? Array.isArray(dom) ? typeof dom[1] == "object" ? [
457
- dom[0],
458
- setObjectAttribute(
459
- dom[1],
460
- key,
461
- value
462
- ),
463
- ...dom.slice(2)
464
- ] : [dom[0], { [key]: value }, ...dom.slice(1)] : (isElement(dom) ? setElementAttribute(dom, key, value) : typeof dom == "object" && "dom" in dom && isElement(dom.dom) && setElementAttribute(dom.dom, key, value), dom) : dom;
595
+ }
596
+ const [key, value] = attrDOM;
597
+ if (!key) {
598
+ return dom;
599
+ }
600
+ if (Array.isArray(dom)) {
601
+ if (typeof dom[1] === "object") {
602
+ return [
603
+ dom[0],
604
+ setObjectAttribute(
605
+ dom[1],
606
+ key,
607
+ value
608
+ ),
609
+ ...dom.slice(2)
610
+ ];
611
+ } else {
612
+ return [dom[0], { [key]: value }, ...dom.slice(1)];
613
+ }
614
+ } else if (isElement(dom)) {
615
+ setElementAttribute(dom, key, value);
616
+ } else if (typeof dom === "object" && "dom" in dom && isElement(dom.dom)) {
617
+ setElementAttribute(dom.dom, key, value);
618
+ }
619
+ return dom;
465
620
  };
466
621
  }
467
- if (parseDOM && spec.parseDOM)
468
- for (let rule of spec.parseDOM) {
469
- let existingGetAttrs = rule.getAttrs, existingAttrs = rule.attrs;
622
+ if (parseDOM && spec.parseDOM) {
623
+ for (const rule of spec.parseDOM) {
624
+ const existingGetAttrs = rule.getAttrs;
625
+ const existingAttrs = rule.attrs;
470
626
  rule.getAttrs = (dom) => {
471
627
  var _a;
472
- let attrs = (_a = existingGetAttrs == null ? void 0 : existingGetAttrs(dom)) != null ? _a : existingAttrs;
473
- if (attrs === !1 || !dom || !isElement(dom))
628
+ const attrs = (_a = existingGetAttrs == null ? void 0 : existingGetAttrs(dom)) != null ? _a : existingAttrs;
629
+ if (attrs === false || !dom || !isElement(dom)) {
474
630
  return attrs != null ? attrs : null;
475
- let value = parseDOM(dom);
631
+ }
632
+ const value = parseDOM(dom);
476
633
  return {
477
634
  ...attrs,
478
635
  [attr]: value
479
636
  };
480
637
  };
481
638
  }
639
+ }
482
640
  }
483
641
  return { nodes, topNode: topNodeName };
484
642
  },
485
643
  parent: schemaSpecFacet,
486
- singleton: !0
644
+ singleton: true
487
645
  });
488
646
  function setObjectAttribute(obj, key, value) {
489
- return key === "style" && (value = `${value}${obj.style || ""}`), { ...obj, [key]: value };
647
+ if (key === "style") {
648
+ value = `${value}${obj.style || ""}`;
649
+ }
650
+ return { ...obj, [key]: value };
490
651
  }
491
652
  function setElementAttribute(element, key, value) {
492
- key === "style" && (value = `${value}${element.getAttribute("style") || ""}`), element.setAttribute(key, value);
653
+ if (key === "style") {
654
+ value = `${value}${element.getAttribute("style") || ""}`;
655
+ }
656
+ element.setAttribute(key, value);
493
657
  }
494
658
 
495
659
  // src/extensions/doc.ts
@@ -497,7 +661,7 @@ function defineDoc() {
497
661
  return defineNodeSpec({
498
662
  name: "doc",
499
663
  content: "block+",
500
- topNode: !0
664
+ topNode: true
501
665
  });
502
666
  }
503
667
 
@@ -508,27 +672,35 @@ import { PluginKey, ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm
508
672
  import "@prosekit/pm/model";
509
673
  import { Plugin } from "@prosekit/pm/state";
510
674
  function definePlugin(plugin) {
511
- if (plugin instanceof Plugin)
675
+ if (plugin instanceof Plugin) {
512
676
  return defineFacetPayload(pluginFacet, [() => [plugin]]);
513
- if (Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin))
677
+ }
678
+ if (Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin)) {
514
679
  return defineFacetPayload(pluginFacet, [() => plugin]);
515
- if (typeof plugin == "function")
680
+ }
681
+ if (typeof plugin === "function") {
516
682
  return defineFacetPayload(pluginFacet, [plugin]);
683
+ }
517
684
  throw new TypeError("Invalid plugin");
518
685
  }
519
686
  var pluginFacet = defineFacet({
520
- reducer: (payloads) => ({ schema }) => {
521
- let plugins = [];
522
- for (let payload of payloads)
523
- if (payload instanceof Plugin)
524
- plugins.push(payload);
525
- else if (Array.isArray(payload) && payload.every((p) => p instanceof Plugin))
526
- plugins.push(...payload);
527
- else if (typeof payload == "function")
528
- plugins.push(...[payload({ schema })].flat());
529
- else
530
- throw new ProseKitError("Invalid plugin");
531
- return plugins.reverse(), { plugins };
687
+ reducer: (payloads) => {
688
+ return ({ schema }) => {
689
+ const plugins = [];
690
+ for (const payload of payloads) {
691
+ if (payload instanceof Plugin) {
692
+ plugins.push(payload);
693
+ } else if (Array.isArray(payload) && payload.every((p) => p instanceof Plugin)) {
694
+ plugins.push(...payload);
695
+ } else if (typeof payload === "function") {
696
+ plugins.push(...[payload({ schema })].flat());
697
+ } else {
698
+ throw new ProseKitError("Invalid plugin");
699
+ }
700
+ }
701
+ plugins.reverse();
702
+ return { plugins };
703
+ };
532
704
  },
533
705
  parent: stateFacet
534
706
  });
@@ -545,19 +717,28 @@ function defineUnmountHandler(handler) {
545
717
  }
546
718
  var pluginViewFacet = defineFacet({
547
719
  reduce: () => {
548
- let mountHandlers = [], updateHandlers = [], unmountHandlers = [], plugin = new ProseMirrorPlugin2({
720
+ let mountHandlers = [];
721
+ let updateHandlers = [];
722
+ let unmountHandlers = [];
723
+ const plugin = new ProseMirrorPlugin2({
549
724
  key: pluginKey,
550
- view: (view) => (mountHandlers.forEach((fn) => fn(view)), {
551
- update: (view2, prevState) => {
552
- updateHandlers.forEach((fn) => fn(view2, prevState));
553
- },
554
- destroy: () => {
555
- unmountHandlers.forEach((fn) => fn());
556
- }
557
- })
558
- }), register = (input) => {
559
- mountHandlers = [], updateHandlers = [], unmountHandlers = [];
560
- for (let args of input)
725
+ view: (view) => {
726
+ mountHandlers.forEach((fn) => fn(view));
727
+ return {
728
+ update: (view2, prevState) => {
729
+ updateHandlers.forEach((fn) => fn(view2, prevState));
730
+ },
731
+ destroy: () => {
732
+ unmountHandlers.forEach((fn) => fn());
733
+ }
734
+ };
735
+ }
736
+ });
737
+ const register = (input) => {
738
+ mountHandlers = [];
739
+ updateHandlers = [];
740
+ unmountHandlers = [];
741
+ for (const args of input) {
561
742
  switch (args[0]) {
562
743
  case "mount":
563
744
  mountHandlers.push(args[1]);
@@ -569,19 +750,24 @@ var pluginViewFacet = defineFacet({
569
750
  unmountHandlers.push(args[1]);
570
751
  break;
571
752
  }
753
+ }
572
754
  };
573
- return function(input) {
574
- return register(input), plugin;
755
+ return function reducer(input) {
756
+ register(input);
757
+ return plugin;
575
758
  };
576
759
  },
577
760
  parent: pluginFacet,
578
- singleton: !0
579
- }), pluginKey = new PluginKey("prosekit-plugin-view-handler");
761
+ singleton: true
762
+ });
763
+ var pluginKey = new PluginKey("prosekit-plugin-view-handler");
580
764
 
581
765
  // src/extensions/events/doc-change.ts
582
766
  function defineDocChangeHandler(handler) {
583
767
  return defineUpdateHandler((view, prevState) => {
584
- view.state.doc.eq(prevState.doc) || handler(view, prevState);
768
+ if (!view.state.doc.eq(prevState.doc)) {
769
+ handler(view, prevState);
770
+ }
585
771
  });
586
772
  }
587
773
 
@@ -595,20 +781,26 @@ function combineEventHandlers() {
595
781
  _handlers = toReversed(handlers);
596
782
  }
597
783
  function combinedEventHandler(...args) {
598
- for (let handler of _handlers)
599
- if (handler(...args))
600
- return !0;
601
- return !1;
784
+ for (const handler of _handlers) {
785
+ if (handler(...args)) {
786
+ return true;
787
+ }
788
+ }
789
+ return false;
602
790
  }
603
791
  return [setHandlers, combinedEventHandler];
604
792
  }
605
793
 
606
794
  // src/utils/group-entries.ts
607
795
  function groupEntries(entries) {
608
- let map = {};
609
- for (let [key, value] of entries) {
610
- let values = map[key];
611
- values ? values.push(value) : map[key] = [value];
796
+ const map = {};
797
+ for (const [key, value] of entries) {
798
+ const values = map[key];
799
+ if (!values) {
800
+ map[key] = [value];
801
+ } else {
802
+ values.push(value);
803
+ }
612
804
  }
613
805
  return map;
614
806
  }
@@ -621,33 +813,42 @@ function defineDOMEventHandler(event, handler) {
621
813
  }
622
814
  var domEventFacet = defineFacet({
623
815
  reduce: () => {
624
- let setHandlersMap = {}, combinedHandlerMap = {}, plugin, update = (payloads) => {
816
+ const setHandlersMap = {};
817
+ const combinedHandlerMap = {};
818
+ let plugin;
819
+ const update = (payloads) => {
625
820
  var _a;
626
- let hasNewEvent = !1;
627
- for (let [event] of payloads)
821
+ let hasNewEvent = false;
822
+ for (const [event] of payloads) {
628
823
  if (!setHandlersMap[event]) {
629
- hasNewEvent = !0;
630
- let [setHandlers, combinedHandler] = combineEventHandlers();
824
+ hasNewEvent = true;
825
+ const [setHandlers, combinedHandler] = combineEventHandlers();
631
826
  setHandlersMap[event] = setHandlers;
632
- let e = (view, eventObject) => combinedHandler(view, eventObject);
827
+ const e = (view, eventObject) => {
828
+ return combinedHandler(view, eventObject);
829
+ };
633
830
  combinedHandlerMap[event] = e;
634
831
  }
635
- let map = groupEntries(payloads);
636
- for (let [event, setHandlers] of Object.entries(setHandlersMap)) {
637
- let handlers = (_a = map[event]) != null ? _a : [];
832
+ }
833
+ const map = groupEntries(payloads);
834
+ for (const [event, setHandlers] of Object.entries(setHandlersMap)) {
835
+ const handlers = (_a = map[event]) != null ? _a : [];
638
836
  setHandlers(handlers);
639
837
  }
640
- hasNewEvent && (plugin = new ProseMirrorPlugin3({
641
- key: new PluginKey2("prosekit-dom-event-handler"),
642
- props: { handleDOMEvents: combinedHandlerMap }
643
- }));
838
+ if (hasNewEvent) {
839
+ plugin = new ProseMirrorPlugin3({
840
+ key: new PluginKey2("prosekit-dom-event-handler"),
841
+ props: { handleDOMEvents: combinedHandlerMap }
842
+ });
843
+ }
644
844
  };
645
- return function(inputs) {
646
- return update(inputs), plugin != null ? plugin : [];
845
+ return function reducer(inputs) {
846
+ update(inputs);
847
+ return plugin != null ? plugin : [];
647
848
  };
648
849
  },
649
850
  parent: pluginFacet,
650
- singleton: !0
851
+ singleton: true
651
852
  });
652
853
 
653
854
  // src/extensions/events/editor-event.ts
@@ -690,18 +891,45 @@ function defineScrollToSelectionHandler(handler) {
690
891
  }
691
892
  var editorEventFacet = defineFacet({
692
893
  reduce: () => {
693
- let [update, plugin] = setupEditorEventPlugin();
694
- return (entries) => (update(entries), plugin);
894
+ const [update, plugin] = setupEditorEventPlugin();
895
+ return (entries) => {
896
+ update(entries);
897
+ return plugin;
898
+ };
695
899
  },
696
900
  parent: pluginFacet,
697
- singleton: !0
901
+ singleton: true
698
902
  });
699
903
  function setupEditorEventPlugin() {
700
- let [setKeyDownHandlers, handleKeyDown] = combineEventHandlers(), [setKeyPressHandlers, handleKeyPress] = combineEventHandlers(), [setTextInputHandlers, handleTextInput] = combineEventHandlers(), [setClickOnHandlers, handleClickOn] = combineEventHandlers(), [setClickHandlers, handleClick] = combineEventHandlers(), [setDoubleClickOnHandlers, handleDoubleClickOn] = combineEventHandlers(), [setDoubleClickHandlers, handleDoubleClick] = combineEventHandlers(), [setTripleClickOnHandlers, handleTripleClickOn] = combineEventHandlers(), [setTripleClickHandlers, handleTripleClick] = combineEventHandlers(), [setPasteHandlers, handlePaste] = combineEventHandlers(), [setDropHandlers, handleDrop] = combineEventHandlers(), [setScrollToSelectionHandlers, handleScrollToSelection] = combineEventHandlers(), update = (entries) => {
904
+ const [setKeyDownHandlers, handleKeyDown] = combineEventHandlers();
905
+ const [setKeyPressHandlers, handleKeyPress] = combineEventHandlers();
906
+ const [setTextInputHandlers, handleTextInput] = combineEventHandlers();
907
+ const [setClickOnHandlers, handleClickOn] = combineEventHandlers();
908
+ const [setClickHandlers, handleClick] = combineEventHandlers();
909
+ const [setDoubleClickOnHandlers, handleDoubleClickOn] = combineEventHandlers();
910
+ const [setDoubleClickHandlers, handleDoubleClick] = combineEventHandlers();
911
+ const [setTripleClickOnHandlers, handleTripleClickOn] = combineEventHandlers();
912
+ const [setTripleClickHandlers, handleTripleClick] = combineEventHandlers();
913
+ const [setPasteHandlers, handlePaste] = combineEventHandlers();
914
+ const [setDropHandlers, handleDrop] = combineEventHandlers();
915
+ const [setScrollToSelectionHandlers, handleScrollToSelection] = combineEventHandlers();
916
+ const update = (entries) => {
701
917
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
702
- let map = groupEntries(entries);
703
- setKeyDownHandlers((_a = map.keyDown) != null ? _a : []), setKeyPressHandlers((_b = map.keyPress) != null ? _b : []), setTextInputHandlers((_c = map.textInput) != null ? _c : []), setClickOnHandlers((_d = map.clickOn) != null ? _d : []), setClickHandlers((_e = map.click) != null ? _e : []), setDoubleClickOnHandlers((_f = map.doubleClickOn) != null ? _f : []), setDoubleClickHandlers((_g = map.doubleClick) != null ? _g : []), setTripleClickOnHandlers((_h = map.tripleClickOn) != null ? _h : []), setTripleClickHandlers((_i = map.tripleClick) != null ? _i : []), setPasteHandlers((_j = map.paste) != null ? _j : []), setDropHandlers((_k = map.drop) != null ? _k : []), setScrollToSelectionHandlers((_l = map.scrollToSelection) != null ? _l : []);
704
- }, plugin = new ProseMirrorPlugin4({
918
+ const map = groupEntries(entries);
919
+ setKeyDownHandlers((_a = map.keyDown) != null ? _a : []);
920
+ setKeyPressHandlers((_b = map.keyPress) != null ? _b : []);
921
+ setTextInputHandlers((_c = map.textInput) != null ? _c : []);
922
+ setClickOnHandlers((_d = map.clickOn) != null ? _d : []);
923
+ setClickHandlers((_e = map.click) != null ? _e : []);
924
+ setDoubleClickOnHandlers((_f = map.doubleClickOn) != null ? _f : []);
925
+ setDoubleClickHandlers((_g = map.doubleClick) != null ? _g : []);
926
+ setTripleClickOnHandlers((_h = map.tripleClickOn) != null ? _h : []);
927
+ setTripleClickHandlers((_i = map.tripleClick) != null ? _i : []);
928
+ setPasteHandlers((_j = map.paste) != null ? _j : []);
929
+ setDropHandlers((_k = map.drop) != null ? _k : []);
930
+ setScrollToSelectionHandlers((_l = map.scrollToSelection) != null ? _l : []);
931
+ };
932
+ const plugin = new ProseMirrorPlugin4({
705
933
  key: new PluginKey3("prosekit-editor-event"),
706
934
  props: {
707
935
  handleKeyDown,
@@ -723,9 +951,11 @@ function setupEditorEventPlugin() {
723
951
 
724
952
  // src/extensions/events/focus.ts
725
953
  function defineFocusChangeHandler(handler) {
954
+ const handleFocus = () => handler(true);
955
+ const handleBlur = () => handler(false);
726
956
  return defineFacetPayload(domEventFacet, [
727
- ["focus", () => handler(!0)],
728
- ["blur", () => handler(!1)]
957
+ ["focus", handleFocus],
958
+ ["blur", handleBlur]
729
959
  ]);
730
960
  }
731
961
 
@@ -733,58 +963,76 @@ function defineFocusChangeHandler(handler) {
733
963
  import { history, redo, undo } from "@prosekit/pm/history";
734
964
 
735
965
  // src/utils/env.ts
736
- var isApple = typeof navigator != "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : !1;
966
+ var isApple = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
737
967
 
738
968
  // src/extensions/keymap.ts
739
969
  import { chainCommands } from "@prosekit/pm/commands";
740
970
  import { keydownHandler } from "@prosekit/pm/keymap";
741
971
  import { Plugin as Plugin2, PluginKey as PluginKey4 } from "@prosekit/pm/state";
742
- function defineKeymap(keymap) {
743
- return defineFacetPayload(keymapFacet, [keymap]);
972
+ function defineKeymap(keymap2) {
973
+ return defineFacetPayload(keymapFacet, [keymap2]);
744
974
  }
745
975
  var keymapFacet = defineFacet({
746
976
  reduce: () => {
747
- let handler, handlerWrapper = (view, event) => handler ? handler(view, event) : !1, plugin = new Plugin2({
977
+ let handler;
978
+ const handlerWrapper = (view, event) => {
979
+ if (handler) return handler(view, event);
980
+ return false;
981
+ };
982
+ const plugin = new Plugin2({
748
983
  key: keymapPluginKey,
749
984
  props: { handleKeyDown: handlerWrapper }
750
985
  });
751
- return (keymaps) => (handler = keydownHandler(
752
- mergeKeymaps(
753
- // The keymap at the end have a higher priority.
754
- toReversed(keymaps)
755
- )
756
- ), plugin);
986
+ return (keymaps) => {
987
+ handler = keydownHandler(
988
+ mergeKeymaps(
989
+ // The keymap at the end have a higher priority.
990
+ toReversed(keymaps)
991
+ )
992
+ );
993
+ return plugin;
994
+ };
757
995
  },
758
996
  parent: pluginFacet,
759
- singleton: !0
997
+ singleton: true
760
998
  });
761
999
  function mergeKeymaps(keymaps) {
762
- let bindings = {};
763
- for (let keymap of keymaps)
764
- for (let [key, command] of Object.entries(keymap))
765
- (bindings[key] || (bindings[key] = [])).push(command);
1000
+ const bindings = {};
1001
+ for (const keymap2 of keymaps) {
1002
+ for (const [key, command] of Object.entries(keymap2)) {
1003
+ const commands2 = bindings[key] || (bindings[key] = []);
1004
+ commands2.push(command);
1005
+ }
1006
+ }
766
1007
  return Object.fromEntries(
767
- Object.entries(bindings).map(([key, commands]) => [
1008
+ Object.entries(bindings).map(([key, commands2]) => [
768
1009
  key,
769
- chainCommands(...commands)
1010
+ chainCommands(...commands2)
770
1011
  ])
771
1012
  );
772
1013
  }
773
1014
  var keymapPluginKey = new PluginKey4("prosekit-keymap");
774
1015
 
775
1016
  // src/extensions/history.ts
776
- function defineHistory() {
777
- let keymap = {
778
- "Mod-z": undo,
779
- "Shift-Mod-z": redo
780
- };
781
- return isApple || (keymap["Mod-y"] = redo), union([
782
- definePlugin(history()),
1017
+ var keymap = {
1018
+ "Mod-z": undo,
1019
+ "Shift-Mod-z": redo
1020
+ };
1021
+ if (!isApple) {
1022
+ keymap["Mod-y"] = redo;
1023
+ }
1024
+ var commands = {
1025
+ undo: () => undo,
1026
+ redo: () => redo
1027
+ };
1028
+ function defineHistory({
1029
+ depth = 200,
1030
+ newGroupDelay = 250
1031
+ } = {}) {
1032
+ return union([
1033
+ definePlugin(history({ depth, newGroupDelay })),
783
1034
  defineKeymap(keymap),
784
- defineCommands({
785
- undo: () => undo,
786
- redo: () => redo
787
- })
1035
+ defineCommands(commands)
788
1036
  ]);
789
1037
  }
790
1038
 
@@ -805,81 +1053,112 @@ var customEnter = chainCommands2(
805
1053
  createParagraphNear,
806
1054
  liftEmptyBlock,
807
1055
  splitSplittableBlock
808
- ), customBackspace = chainCommands2(
1056
+ );
1057
+ var customBackspace = chainCommands2(
809
1058
  deleteSelection,
810
1059
  joinTextblockBackward,
811
1060
  selectNodeBackward
812
- ), customBaseKeymap = {
1061
+ );
1062
+ var customBaseKeymap = {
813
1063
  ...baseKeymap,
814
1064
  Enter: customEnter,
815
1065
  Backspace: customBackspace
816
1066
  };
817
1067
  function defineBaseKeymap(options) {
818
1068
  var _a;
819
- let priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */;
1069
+ const priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */;
820
1070
  return withPriority(defineKeymap(customBaseKeymap), priority);
821
1071
  }
822
1072
 
823
1073
  // src/extensions/mark-spec.ts
824
1074
  function defineMarkSpec(options) {
825
- return defineFacetPayload(markSpecFacet, [[options, void 0]]);
1075
+ const payload = [options, void 0];
1076
+ return defineFacetPayload(markSpecFacet, [payload]);
826
1077
  }
827
1078
  function defineMarkAttr(options) {
828
- return defineFacetPayload(markSpecFacet, [[void 0, options]]);
1079
+ const payload = [void 0, options];
1080
+ return defineFacetPayload(markSpecFacet, [payload]);
829
1081
  }
830
1082
  var markSpecFacet = defineFacet({
831
1083
  reducer: (payloads) => {
832
- let marks = {}, specPayloads = payloads.map((input) => input[0]).filter(isNotNull), attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
833
- for (let { name, ...spec } of specPayloads) {
834
- if (marks[name])
1084
+ const marks = {};
1085
+ const specPayloads = payloads.map((input) => input[0]).filter(isNotNull);
1086
+ const attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
1087
+ for (const { name, ...spec } of specPayloads) {
1088
+ if (marks[name]) {
835
1089
  throw new ProseKitError(`Mark type ${name} has already been defined`);
1090
+ }
836
1091
  marks[name] = spec;
837
1092
  }
838
- for (let {
1093
+ for (const {
839
1094
  type,
840
1095
  attr,
841
1096
  default: defaultValue,
842
1097
  toDOM,
843
1098
  parseDOM
844
1099
  } of attrPayloads) {
845
- let spec = marks[type];
846
- if (!spec)
1100
+ const spec = marks[type];
1101
+ if (!spec) {
847
1102
  throw new ProseKitError(
848
1103
  `Mark type ${type} must be defined before defining attributes`
849
1104
  );
850
- if (spec.attrs || (spec.attrs = {}), spec.attrs[attr] = { default: defaultValue }, toDOM && spec.toDOM) {
851
- let existingToDom = spec.toDOM;
1105
+ }
1106
+ if (!spec.attrs) {
1107
+ spec.attrs = {};
1108
+ }
1109
+ spec.attrs[attr] = { default: defaultValue };
1110
+ if (toDOM && spec.toDOM) {
1111
+ const existingToDom = spec.toDOM;
852
1112
  spec.toDOM = (mark, inline) => {
853
- let dom = existingToDom(mark, inline);
854
- if (!dom)
1113
+ const dom = existingToDom(mark, inline);
1114
+ if (!dom) {
855
1115
  return dom;
856
- let attrDOM = toDOM(mark.attrs[attr]);
857
- if (!attrDOM)
1116
+ }
1117
+ const attrDOM = toDOM(mark.attrs[attr]);
1118
+ if (!attrDOM) {
1119
+ return dom;
1120
+ }
1121
+ const [key, value] = attrDOM;
1122
+ if (!key) {
858
1123
  return dom;
859
- let [key, value] = attrDOM;
860
- return key ? Array.isArray(dom) ? typeof dom[1] == "object" ? [dom[0], { ...dom[1], [key]: value }, ...dom.slice(2)] : [dom[0], { [key]: value }, ...dom.slice(1)] : (isElement(dom) ? dom.setAttribute(key, value) : typeof dom == "object" && "dom" in dom && isElement(dom.dom) && dom.dom.setAttribute(key, value), dom) : dom;
1124
+ }
1125
+ if (Array.isArray(dom)) {
1126
+ if (typeof dom[1] === "object") {
1127
+ return [dom[0], { ...dom[1], [key]: value }, ...dom.slice(2)];
1128
+ } else {
1129
+ return [dom[0], { [key]: value }, ...dom.slice(1)];
1130
+ }
1131
+ } else if (isElement(dom)) {
1132
+ dom.setAttribute(key, value);
1133
+ } else if (typeof dom === "object" && "dom" in dom && isElement(dom.dom)) {
1134
+ dom.dom.setAttribute(key, value);
1135
+ }
1136
+ return dom;
861
1137
  };
862
1138
  }
863
- if (parseDOM && spec.parseDOM)
864
- for (let rule of spec.parseDOM) {
865
- let existingGetAttrs = rule.getAttrs, existingAttrs = rule.attrs;
1139
+ if (parseDOM && spec.parseDOM) {
1140
+ for (const rule of spec.parseDOM) {
1141
+ const existingGetAttrs = rule.getAttrs;
1142
+ const existingAttrs = rule.attrs;
866
1143
  rule.getAttrs = (dom) => {
867
1144
  var _a;
868
- let attrs = (_a = existingGetAttrs == null ? void 0 : existingGetAttrs(dom)) != null ? _a : existingAttrs;
869
- if (attrs === !1 || !dom || !isElement(dom))
1145
+ const attrs = (_a = existingGetAttrs == null ? void 0 : existingGetAttrs(dom)) != null ? _a : existingAttrs;
1146
+ if (attrs === false || !dom || !isElement(dom)) {
870
1147
  return attrs != null ? attrs : null;
871
- let value = parseDOM(dom);
1148
+ }
1149
+ const value = parseDOM(dom);
872
1150
  return {
873
1151
  ...attrs,
874
1152
  [attr]: value
875
1153
  };
876
1154
  };
877
1155
  }
1156
+ }
878
1157
  }
879
1158
  return { marks, nodes: {} };
880
1159
  },
881
1160
  parent: schemaSpecFacet,
882
- singleton: !0
1161
+ singleton: true
883
1162
  });
884
1163
 
885
1164
  // src/extensions/node-view.ts
@@ -890,9 +1169,12 @@ function defineNodeView(options) {
890
1169
  }
891
1170
  var nodeViewFacet = defineFacet({
892
1171
  reducer: (inputs) => {
893
- let nodeViews = {};
894
- for (let input of inputs)
895
- nodeViews[input.name] || (nodeViews[input.name] = input.constructor);
1172
+ const nodeViews = {};
1173
+ for (const input of inputs) {
1174
+ if (!nodeViews[input.name]) {
1175
+ nodeViews[input.name] = input.constructor;
1176
+ }
1177
+ }
896
1178
  return () => [
897
1179
  new ProseMirrorPlugin5({
898
1180
  key: new PluginKey5("prosekit-node-view"),
@@ -907,17 +1189,24 @@ var nodeViewFacet = defineFacet({
907
1189
  import { PluginKey as PluginKey6, ProseMirrorPlugin as ProseMirrorPlugin6 } from "@prosekit/pm/state";
908
1190
  import "@prosekit/pm/view";
909
1191
  function defineNodeViewFactory(options) {
910
- return defineFacetPayload(nodeViewFactoryFacet, [[options, null]]);
1192
+ const input = [options, null];
1193
+ return defineFacetPayload(nodeViewFactoryFacet, [input]);
911
1194
  }
912
1195
  function defineNodeViewComponent(options) {
913
- return defineFacetPayload(nodeViewFactoryFacet, [[null, options]]);
1196
+ const input = [null, options];
1197
+ return defineFacetPayload(nodeViewFactoryFacet, [input]);
914
1198
  }
1199
+ var isServer = typeof window === "undefined";
915
1200
  var nodeViewFactoryFacet = defineFacet({
916
1201
  reducer: (inputs) => {
917
- let nodeViews = {}, factories = inputs.map((x) => x[0]).filter(isNotNull), options = inputs.map((x) => x[1]).filter(isNotNull);
918
- for (let { group, name, args } of options) {
919
- let factory = factories.find((factory2) => factory2.group === group);
920
- factory && (nodeViews[name] = factory.factory(args));
1202
+ if (isServer) return [];
1203
+ const nodeViews = {};
1204
+ const factories = inputs.map((x) => x[0]).filter(isNotNull);
1205
+ const options = inputs.map((x) => x[1]).filter(isNotNull);
1206
+ for (const { group, name, args } of options) {
1207
+ const factory = factories.find((factory2) => factory2.group === group);
1208
+ if (!factory) continue;
1209
+ nodeViews[name] = factory.factory(args);
921
1210
  }
922
1211
  return () => [
923
1212
  new ProseMirrorPlugin6({
@@ -955,8 +1244,13 @@ function defineText() {
955
1244
 
956
1245
  // src/utils/cache.ts
957
1246
  function cache(fn) {
958
- let result;
959
- return () => (result === void 0 && (result = fn()), result);
1247
+ let result = void 0;
1248
+ return () => {
1249
+ if (result === void 0) {
1250
+ result = fn();
1251
+ }
1252
+ return result;
1253
+ };
960
1254
  }
961
1255
 
962
1256
  // src/utils/can-use-regex-lookbehind.ts
@@ -964,7 +1258,7 @@ var canUseRegexLookbehind = cache(() => {
964
1258
  try {
965
1259
  return "ab".replace(new RegExp("(?<=a)b", "g"), "c") === "ac";
966
1260
  } catch (error) {
967
- return !1;
1261
+ return false;
968
1262
  }
969
1263
  });
970
1264
 
@@ -975,14 +1269,17 @@ var clsx = clsxLite;
975
1269
  // src/utils/collect-nodes.ts
976
1270
  import { ProseMirrorFragment, ProseMirrorNode as ProseMirrorNode2 } from "@prosekit/pm/model";
977
1271
  function collectNodes(content) {
978
- if (Array.isArray(content))
1272
+ if (Array.isArray(content)) {
979
1273
  return content.flatMap(collectNodes);
980
- if (content instanceof ProseMirrorNode2)
1274
+ }
1275
+ if (content instanceof ProseMirrorNode2) {
981
1276
  return [content];
1277
+ }
982
1278
  if (content instanceof ProseMirrorFragment) {
983
- let nodes = [];
984
- for (let i = 0; i < content.childCount; i++)
1279
+ const nodes = [];
1280
+ for (let i = 0; i < content.childCount; i++) {
985
1281
  nodes.push(content.child(i));
1282
+ }
986
1283
  return nodes;
987
1284
  }
988
1285
  throw new ProseKitError(`Invalid node content: ${typeof content}`);
@@ -991,7 +1288,7 @@ function collectNodes(content) {
991
1288
  // src/utils/default-block-at.ts
992
1289
  function defaultBlockAt(match) {
993
1290
  for (let i = 0; i < match.edgeCount; i++) {
994
- let { type } = match.edge(i);
1291
+ const { type } = match.edge(i);
995
1292
  if (type.isTextblock && !type.hasRequiredAttrs()) return type;
996
1293
  }
997
1294
  return null;
@@ -1000,13 +1297,16 @@ function defaultBlockAt(match) {
1000
1297
  // src/utils/get-id.ts
1001
1298
  var id = 0;
1002
1299
  function getId() {
1003
- return id = (id + 1) % Number.MAX_SAFE_INTEGER, `id:${id}`;
1300
+ id = (id + 1) % Number.MAX_SAFE_INTEGER;
1301
+ return `id:${id}`;
1004
1302
  }
1005
1303
 
1006
1304
  // src/utils/is-at-block-start.ts
1007
1305
  function isAtBlockStart(state, view) {
1008
- let { $cursor } = state.selection;
1009
- return !$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0) ? null : $cursor;
1306
+ const { $cursor } = state.selection;
1307
+ if (!$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0))
1308
+ return null;
1309
+ return $cursor;
1010
1310
  }
1011
1311
 
1012
1312
  // src/utils/is-in-code-block.ts
@@ -1019,7 +1319,7 @@ function isInCodeBlock(selection) {
1019
1319
 
1020
1320
  // src/utils/maybe-run.ts
1021
1321
  function maybeRun(value, ...args) {
1022
- return typeof value == "function" ? value(...args) : value;
1322
+ return typeof value === "function" ? value(...args) : value;
1023
1323
  }
1024
1324
 
1025
1325
  // src/utils/unicode.ts
@@ -1027,7 +1327,12 @@ var OBJECT_REPLACEMENT_CHARACTER = "\uFFFC";
1027
1327
 
1028
1328
  // src/utils/with-skip-code-block.ts
1029
1329
  function withSkipCodeBlock(command) {
1030
- return (state, dispatch, view) => isInCodeBlock(state.selection) ? !1 : command(state, dispatch, view);
1330
+ return (state, dispatch, view) => {
1331
+ if (isInCodeBlock(state.selection)) {
1332
+ return false;
1333
+ }
1334
+ return command(state, dispatch, view);
1335
+ };
1031
1336
  }
1032
1337
  export {
1033
1338
  Editor,