@prosekit/core 0.7.2 → 0.7.4

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