@prosekit/core 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_tsup-dts-rollup.d.ts +212 -81
- package/dist/prosekit-core.d.ts +8 -1
- package/dist/prosekit-core.js +766 -506
- package/package.json +4 -4
package/dist/prosekit-core.js
CHANGED
@@ -107,6 +107,13 @@ function expandMarkAfter($pos, predicate) {
|
|
107
107
|
import "@prosekit/pm/state";
|
108
108
|
import { insertPoint } from "@prosekit/pm/transform";
|
109
109
|
|
110
|
+
// src/utils/assert.ts
|
111
|
+
function assert(condition, message = "Assertion failed") {
|
112
|
+
if (!condition) {
|
113
|
+
throw new ProseKitError(message);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
110
117
|
// src/utils/get-node-type.ts
|
111
118
|
import "@prosekit/pm/model";
|
112
119
|
function getNodeType(schema, type) {
|
@@ -133,10 +140,8 @@ function setSelectionAround(tr, pos) {
|
|
133
140
|
function insertNode(options) {
|
134
141
|
return (state, dispatch) => {
|
135
142
|
var _a;
|
136
|
-
const node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).
|
137
|
-
|
138
|
-
throw new ProseKitError("You must provide either a node or a type");
|
139
|
-
}
|
143
|
+
const node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).createAndFill(options.attrs) : null;
|
144
|
+
assert(node, "You must provide either a node or a type");
|
140
145
|
const insertPos = insertPoint(
|
141
146
|
state.doc,
|
142
147
|
(_a = options.pos) != null ? _a : state.selection.to,
|
@@ -228,20 +233,38 @@ function setBlockType(options) {
|
|
228
233
|
};
|
229
234
|
}
|
230
235
|
|
236
|
+
// src/utils/get-node-types.ts
|
237
|
+
import "@prosekit/pm/model";
|
238
|
+
function getNodeTypes(schema, types) {
|
239
|
+
if (Array.isArray(types)) {
|
240
|
+
return types.map((type) => getNodeType(schema, type));
|
241
|
+
}
|
242
|
+
return [getNodeType(schema, types)];
|
243
|
+
}
|
244
|
+
|
231
245
|
// src/commands/set-node-attrs.ts
|
232
246
|
function setNodeAttrs(options) {
|
233
247
|
return (state, dispatch) => {
|
234
|
-
var _a;
|
235
|
-
const
|
236
|
-
const
|
237
|
-
const
|
238
|
-
|
248
|
+
var _a, _b;
|
249
|
+
const nodeTypes = getNodeTypes(state.schema, options.type);
|
250
|
+
const from = (_a = options.pos) != null ? _a : state.selection.from;
|
251
|
+
const to = (_b = options.pos) != null ? _b : state.selection.to;
|
252
|
+
const positions = [];
|
253
|
+
state.doc.nodesBetween(from, to, (node, pos) => {
|
254
|
+
if (nodeTypes.includes(node.type)) {
|
255
|
+
positions.push(pos);
|
256
|
+
}
|
257
|
+
if (!dispatch && positions.length > 0) {
|
258
|
+
return false;
|
259
|
+
}
|
260
|
+
});
|
261
|
+
if (positions.length === 0) {
|
239
262
|
return false;
|
240
263
|
}
|
241
264
|
if (dispatch) {
|
242
265
|
const { tr } = state;
|
243
|
-
for (const
|
244
|
-
|
266
|
+
for (const pos of positions) {
|
267
|
+
for (const [key, value] of Object.entries(options.attrs)) {
|
245
268
|
tr.setNodeAttribute(pos, key, value);
|
246
269
|
}
|
247
270
|
}
|
@@ -252,19 +275,85 @@ function setNodeAttrs(options) {
|
|
252
275
|
}
|
253
276
|
|
254
277
|
// src/commands/toggle-mark.ts
|
255
|
-
import { toggleMark as baseToggleMark } from "@prosekit/pm/commands";
|
256
278
|
import "@prosekit/pm/model";
|
257
279
|
import "@prosekit/pm/state";
|
280
|
+
function markApplies(doc, ranges, type) {
|
281
|
+
for (const { $from, $to } of ranges) {
|
282
|
+
let can = $from.depth == 0 ? doc.inlineContent && doc.type.allowsMarkType(type) : false;
|
283
|
+
doc.nodesBetween($from.pos, $to.pos, (node) => {
|
284
|
+
if (can)
|
285
|
+
return false;
|
286
|
+
can = node.inlineContent && node.type.allowsMarkType(type);
|
287
|
+
});
|
288
|
+
if (can)
|
289
|
+
return true;
|
290
|
+
}
|
291
|
+
return false;
|
292
|
+
}
|
293
|
+
function baseToggleMark(markType, attrs = null, options) {
|
294
|
+
const removeWhenPresent = (options && options.removeWhenPresent) !== false;
|
295
|
+
return function(state, dispatch) {
|
296
|
+
const { empty, $cursor, ranges } = state.selection;
|
297
|
+
if (empty && !$cursor || !markApplies(state.doc, ranges, markType))
|
298
|
+
return false;
|
299
|
+
if (dispatch) {
|
300
|
+
if ($cursor) {
|
301
|
+
if (markType.isInSet(state.storedMarks || $cursor.marks()))
|
302
|
+
dispatch(state.tr.removeStoredMark(markType));
|
303
|
+
else
|
304
|
+
dispatch(state.tr.addStoredMark(markType.create(attrs)));
|
305
|
+
} else {
|
306
|
+
let add;
|
307
|
+
const tr = state.tr;
|
308
|
+
if (removeWhenPresent) {
|
309
|
+
add = !ranges.some(
|
310
|
+
(r) => state.doc.rangeHasMark(r.$from.pos, r.$to.pos, markType)
|
311
|
+
);
|
312
|
+
} else {
|
313
|
+
add = !ranges.every((r) => {
|
314
|
+
let missing = false;
|
315
|
+
tr.doc.nodesBetween(r.$from.pos, r.$to.pos, (node, pos, parent) => {
|
316
|
+
if (missing)
|
317
|
+
return false;
|
318
|
+
missing = !markType.isInSet(node.marks) && !!parent && parent.type.allowsMarkType(markType) && !(node.isText && /^\s*$/.test(
|
319
|
+
node.textBetween(
|
320
|
+
Math.max(0, r.$from.pos - pos),
|
321
|
+
Math.min(node.nodeSize, r.$to.pos - pos)
|
322
|
+
)
|
323
|
+
));
|
324
|
+
});
|
325
|
+
return !missing;
|
326
|
+
});
|
327
|
+
}
|
328
|
+
for (const { $from, $to } of ranges) {
|
329
|
+
if (!add) {
|
330
|
+
tr.removeMark($from.pos, $to.pos, markType);
|
331
|
+
} else {
|
332
|
+
let from = $from.pos, to = $to.pos;
|
333
|
+
const start = $from.nodeAfter, end = $to.nodeBefore;
|
334
|
+
const spaceStart = start && start.isText ? /^\s*/.exec(start.text)[0].length : 0;
|
335
|
+
const spaceEnd = end && end.isText ? /\s*$/.exec(end.text)[0].length : 0;
|
336
|
+
if (from + spaceStart < to) {
|
337
|
+
from += spaceStart;
|
338
|
+
to -= spaceEnd;
|
339
|
+
}
|
340
|
+
tr.addMark(from, to, markType.create(attrs));
|
341
|
+
}
|
342
|
+
}
|
343
|
+
dispatch(tr.scrollIntoView());
|
344
|
+
}
|
345
|
+
}
|
346
|
+
return true;
|
347
|
+
};
|
348
|
+
}
|
258
349
|
function toggleMark({
|
259
350
|
type,
|
260
351
|
attrs
|
261
352
|
}) {
|
262
353
|
return (state, dispatch, view) => {
|
263
|
-
return baseToggleMark(getMarkType(state.schema, type), attrs
|
264
|
-
|
265
|
-
|
266
|
-
view
|
267
|
-
);
|
354
|
+
return baseToggleMark(getMarkType(state.schema, type), attrs, {
|
355
|
+
removeWhenPresent: false
|
356
|
+
})(state, dispatch, view);
|
268
357
|
};
|
269
358
|
}
|
270
359
|
|
@@ -317,14 +406,27 @@ function toggleNode({
|
|
317
406
|
}
|
318
407
|
|
319
408
|
// src/editor/editor.ts
|
320
|
-
import
|
409
|
+
import "@prosekit/pm/model";
|
321
410
|
import { EditorState as EditorState2 } from "@prosekit/pm/state";
|
322
411
|
import { EditorView } from "@prosekit/pm/view";
|
323
412
|
|
324
413
|
// src/extensions/default-state.ts
|
325
414
|
import { Selection } from "@prosekit/pm/state";
|
326
415
|
|
327
|
-
// src/
|
416
|
+
// src/types/priority.ts
|
417
|
+
var Priority = /* @__PURE__ */ ((Priority2) => {
|
418
|
+
Priority2[Priority2["lowest"] = 0] = "lowest";
|
419
|
+
Priority2[Priority2["low"] = 1] = "low";
|
420
|
+
Priority2[Priority2["default"] = 2] = "default";
|
421
|
+
Priority2[Priority2["high"] = 3] = "high";
|
422
|
+
Priority2[Priority2["highest"] = 4] = "highest";
|
423
|
+
return Priority2;
|
424
|
+
})(Priority || {});
|
425
|
+
|
426
|
+
// src/facets/base-extension.ts
|
427
|
+
import "@prosekit/pm/model";
|
428
|
+
|
429
|
+
// src/utils/array.ts
|
328
430
|
function uniqPush(prev, next) {
|
329
431
|
const result = [...prev];
|
330
432
|
for (const item of next) {
|
@@ -334,84 +436,268 @@ function uniqPush(prev, next) {
|
|
334
436
|
}
|
335
437
|
return result;
|
336
438
|
}
|
337
|
-
function
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
}
|
344
|
-
}
|
345
|
-
return result;
|
439
|
+
function arraySubstract(a, b) {
|
440
|
+
return a.filter((x) => !b.includes(x));
|
441
|
+
}
|
442
|
+
function toReversed(arr) {
|
443
|
+
var _a, _b;
|
444
|
+
return (_b = (_a = arr.toReversed) == null ? void 0 : _a.call(arr)) != null ? _b : [...arr].reverse();
|
346
445
|
}
|
347
446
|
|
348
|
-
// src/facets/
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
447
|
+
// src/facets/facet-node.ts
|
448
|
+
function zip5(a, b, mapper) {
|
449
|
+
return [
|
450
|
+
mapper(a[0], b[0]),
|
451
|
+
mapper(a[1], b[1]),
|
452
|
+
mapper(a[2], b[2]),
|
453
|
+
mapper(a[3], b[3]),
|
454
|
+
mapper(a[4], b[4])
|
455
|
+
];
|
456
|
+
}
|
457
|
+
function unionInput(a, b) {
|
458
|
+
if (!a && !b)
|
459
|
+
return null;
|
460
|
+
return uniqPush(a != null ? a : [], b != null ? b : []);
|
461
|
+
}
|
462
|
+
function subtractInput(a, b) {
|
463
|
+
if (!a)
|
464
|
+
return null;
|
465
|
+
if (!b)
|
466
|
+
return [];
|
467
|
+
return arraySubstract(a, b);
|
468
|
+
}
|
469
|
+
function unionChildren(a, b) {
|
470
|
+
const merged = new Map(a);
|
471
|
+
for (const [key, valueB] of b.entries()) {
|
472
|
+
const valueA = a.get(key);
|
473
|
+
merged.set(key, valueA ? unionFacetNode(valueA, valueB) : valueB);
|
474
|
+
}
|
475
|
+
return merged;
|
476
|
+
}
|
477
|
+
function subtractChildren(a, b) {
|
478
|
+
const merged = new Map(a);
|
479
|
+
for (const [key, valueB] of b.entries()) {
|
480
|
+
const valueA = a.get(key);
|
481
|
+
merged.set(key, valueA ? subtractFacetNode(valueA, valueB) : valueB);
|
482
|
+
}
|
483
|
+
return merged;
|
484
|
+
}
|
485
|
+
function unionFacetNode(a, b) {
|
486
|
+
assert(a.facet === b.facet);
|
487
|
+
return new FacetNode(
|
488
|
+
a.facet,
|
489
|
+
zip5(a.inputs, b.inputs, unionInput),
|
490
|
+
unionChildren(a.children, b.children)
|
491
|
+
);
|
492
|
+
}
|
493
|
+
function subtractFacetNode(a, b) {
|
494
|
+
assert(a.facet === b.facet);
|
495
|
+
return new FacetNode(
|
496
|
+
a.facet,
|
497
|
+
zip5(a.inputs, b.inputs, subtractInput),
|
498
|
+
subtractChildren(a.children, b.children)
|
499
|
+
);
|
500
|
+
}
|
501
|
+
var FacetNode = class {
|
502
|
+
constructor(facet, inputs = [null, null, null, null, null], children = /* @__PURE__ */ new Map()) {
|
503
|
+
this.facet = facet;
|
504
|
+
this.inputs = inputs;
|
505
|
+
this.children = children;
|
506
|
+
this.reducers = [null, null, null, null, null];
|
507
|
+
this.output = null;
|
508
|
+
}
|
509
|
+
calcOutput() {
|
510
|
+
var _a, _b, _c;
|
511
|
+
const inputs = [null, null, null, null, null];
|
512
|
+
const output = [null, null, null, null, null];
|
513
|
+
for (let pri = 0; pri < 5; pri++) {
|
514
|
+
const input = this.inputs[pri];
|
515
|
+
if (input) {
|
516
|
+
inputs[pri] = [...input];
|
517
|
+
}
|
518
|
+
}
|
519
|
+
for (const child of this.children.values()) {
|
520
|
+
const childOutput = child.getOutput();
|
521
|
+
for (let pri = 0; pri < 5; pri++) {
|
522
|
+
if (childOutput[pri]) {
|
523
|
+
const input = inputs[pri] || (inputs[pri] = []);
|
524
|
+
input.push(childOutput[pri]);
|
525
|
+
}
|
526
|
+
}
|
527
|
+
}
|
528
|
+
if (this.facet.singleton) {
|
529
|
+
const reducer = (_a = this.reducers)[_b = 2 /* default */] || (_a[_b] = this.facet.reducer);
|
530
|
+
const input = inputs.filter(Boolean).flat();
|
531
|
+
output[2 /* default */] = reducer(input);
|
532
|
+
} else {
|
533
|
+
for (let pri = 0; pri < 5; pri++) {
|
534
|
+
const input = inputs[pri];
|
535
|
+
if (input) {
|
536
|
+
const reducer = (_c = this.reducers)[pri] || (_c[pri] = this.facet.reducer);
|
537
|
+
output[pri] = reducer(input);
|
538
|
+
}
|
539
|
+
}
|
540
|
+
}
|
541
|
+
return output;
|
542
|
+
}
|
543
|
+
getOutput() {
|
544
|
+
if (!this.output) {
|
545
|
+
this.output = this.calcOutput();
|
546
|
+
}
|
547
|
+
return this.output;
|
548
|
+
}
|
549
|
+
getSingletonOutput() {
|
550
|
+
assert(this.facet.singleton);
|
551
|
+
return this.getOutput()[2 /* default */];
|
552
|
+
}
|
553
|
+
getRootOutput() {
|
554
|
+
assert(this.isRoot());
|
555
|
+
const output = this.getSingletonOutput();
|
556
|
+
assert(output);
|
557
|
+
return output;
|
558
|
+
}
|
559
|
+
isRoot() {
|
560
|
+
return !this.facet.parent;
|
353
561
|
}
|
354
562
|
};
|
355
563
|
|
564
|
+
// src/facets/schema.ts
|
565
|
+
import { Schema as Schema4 } from "@prosekit/pm/model";
|
566
|
+
|
356
567
|
// src/facets/facet.ts
|
357
568
|
var facetCount = 0;
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
constructor(
|
569
|
+
var Facet = class {
|
570
|
+
/**
|
571
|
+
* @internal
|
572
|
+
*/
|
573
|
+
constructor(parent, singleton, _reducer, _reduce) {
|
574
|
+
this._reducer = _reducer;
|
575
|
+
this._reduce = _reduce;
|
363
576
|
/**
|
364
577
|
* @internal
|
365
578
|
*/
|
366
579
|
this.index = facetCount++;
|
367
|
-
|
368
|
-
|
369
|
-
*/
|
370
|
-
this.isSchema = false;
|
371
|
-
this.converter = converter;
|
372
|
-
this.next = next;
|
580
|
+
assert((_reduce || _reducer) && !(_reduce && _reducer));
|
581
|
+
this.parent = parent;
|
373
582
|
this.singleton = singleton;
|
583
|
+
this.path = parent ? [...parent.path, this.index] : [];
|
374
584
|
}
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
585
|
+
get reducer() {
|
586
|
+
var _a, _b;
|
587
|
+
return (_b = this._reducer) != null ? _b : (_a = this._reduce) == null ? void 0 : _a.call(this);
|
588
|
+
}
|
589
|
+
};
|
590
|
+
function defineFacet(options) {
|
591
|
+
var _a;
|
592
|
+
return new Facet(
|
593
|
+
options.parent,
|
594
|
+
(_a = options.singleton) != null ? _a : false,
|
595
|
+
options.reducer,
|
596
|
+
options.reduce
|
597
|
+
);
|
598
|
+
}
|
599
|
+
|
600
|
+
// src/facets/root.ts
|
601
|
+
function rootReducer(inputs) {
|
602
|
+
var _a;
|
603
|
+
let schema;
|
604
|
+
let commands;
|
605
|
+
let stateFunc;
|
606
|
+
let view;
|
607
|
+
for (const input of inputs) {
|
608
|
+
schema = input.schema || schema;
|
609
|
+
commands = input.commands || commands;
|
610
|
+
stateFunc = input.state || stateFunc;
|
611
|
+
view = input.view || view;
|
612
|
+
}
|
613
|
+
const state = schema && ((_a = stateFunc == null ? void 0 : stateFunc({ schema })) != null ? _a : { schema });
|
614
|
+
return { schema, state, commands, view };
|
615
|
+
}
|
616
|
+
var rootFacet = new Facet(
|
617
|
+
null,
|
618
|
+
true,
|
619
|
+
rootReducer
|
620
|
+
);
|
621
|
+
|
622
|
+
// src/facets/schema.ts
|
623
|
+
var schemaFacet = defineFacet({
|
624
|
+
reducer: (specs) => {
|
625
|
+
assert(specs.length <= 1);
|
626
|
+
const spec = specs[0];
|
627
|
+
const schema = spec ? new Schema4(spec) : null;
|
628
|
+
return { schema };
|
629
|
+
},
|
630
|
+
parent: rootFacet,
|
631
|
+
singleton: true
|
632
|
+
});
|
633
|
+
|
634
|
+
// src/facets/base-extension.ts
|
635
|
+
var BaseExtension = class {
|
636
|
+
constructor() {
|
637
|
+
this.extension = [];
|
638
|
+
this.trees = [null, null, null, null, null];
|
389
639
|
}
|
390
640
|
/**
|
391
641
|
* @internal
|
392
642
|
*/
|
393
|
-
|
394
|
-
|
643
|
+
getTree(priority) {
|
644
|
+
var _a, _b;
|
645
|
+
const pri = (_a = priority != null ? priority : this.priority) != null ? _a : 2 /* default */;
|
646
|
+
return (_b = this.trees)[pri] || (_b[pri] = this.createTree(pri));
|
395
647
|
}
|
396
|
-
|
397
|
-
|
648
|
+
/**
|
649
|
+
* @internal
|
650
|
+
*/
|
651
|
+
findFacetOutput(facet) {
|
652
|
+
var _a;
|
653
|
+
let node = this.getTree();
|
654
|
+
for (const index of facet.path) {
|
655
|
+
node = node == null ? void 0 : node.children.get(index);
|
656
|
+
}
|
657
|
+
return (_a = node == null ? void 0 : node.getOutput()) != null ? _a : null;
|
658
|
+
}
|
659
|
+
get schema() {
|
660
|
+
var _a, _b;
|
661
|
+
const output = this.findFacetOutput(schemaFacet);
|
662
|
+
return (_b = (_a = output == null ? void 0 : output.find(Boolean)) == null ? void 0 : _a.schema) != null ? _b : null;
|
398
663
|
}
|
399
664
|
};
|
665
|
+
|
666
|
+
// src/facets/facet-extension.ts
|
400
667
|
var FacetExtensionImpl = class extends BaseExtension {
|
668
|
+
/**
|
669
|
+
* @internal
|
670
|
+
*/
|
401
671
|
constructor(facet, payloads) {
|
402
|
-
var _a;
|
403
672
|
super();
|
404
673
|
this.facet = facet;
|
405
674
|
this.payloads = payloads;
|
406
|
-
|
407
|
-
|
675
|
+
}
|
676
|
+
/**
|
677
|
+
* @internal
|
678
|
+
*/
|
679
|
+
createTree(priority) {
|
680
|
+
var _a;
|
681
|
+
const pri = (_a = this.priority) != null ? _a : priority;
|
682
|
+
const inputs = [null, null, null, null, null];
|
683
|
+
inputs[pri] = [...this.payloads];
|
684
|
+
let node = new FacetNode(this.facet, inputs);
|
685
|
+
while (node.facet.parent) {
|
686
|
+
const children = /* @__PURE__ */ new Map([[node.facet.index, node]]);
|
687
|
+
node = new FacetNode(node.facet.parent, void 0, children);
|
688
|
+
}
|
689
|
+
return node;
|
408
690
|
}
|
409
691
|
};
|
692
|
+
function defineFacetPayload(facet, payloads) {
|
693
|
+
return new FacetExtensionImpl(facet, payloads);
|
694
|
+
}
|
410
695
|
|
411
696
|
// src/facets/state.ts
|
412
|
-
var stateFacet =
|
413
|
-
|
414
|
-
|
697
|
+
var stateFacet = defineFacet({
|
698
|
+
reduce: () => {
|
699
|
+
let callbacks = [];
|
700
|
+
const state = (ctx) => {
|
415
701
|
var _a, _b, _c, _d, _e, _f;
|
416
702
|
const configs = callbacks.map((cb) => cb(ctx));
|
417
703
|
const config = {
|
@@ -426,17 +712,22 @@ var stateFacet = Facet.defineRootFacet({
|
|
426
712
|
config.storedMarks = [...config.storedMarks, ...(_d = c.storedMarks) != null ? _d : []];
|
427
713
|
config.plugins = uniqPush((_e = config.plugins) != null ? _e : [], (_f = c.plugins) != null ? _f : []);
|
428
714
|
}
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
}
|
715
|
+
assert(
|
716
|
+
config.doc || config.schema,
|
717
|
+
"Can't create state without a schema nor a document"
|
718
|
+
);
|
434
719
|
if (config.doc) {
|
435
720
|
config.schema = void 0;
|
436
721
|
}
|
437
722
|
return config;
|
438
723
|
};
|
439
|
-
|
724
|
+
return function reducer(inputs) {
|
725
|
+
callbacks = inputs;
|
726
|
+
return { state };
|
727
|
+
};
|
728
|
+
},
|
729
|
+
singleton: true,
|
730
|
+
parent: rootFacet
|
440
731
|
});
|
441
732
|
|
442
733
|
// src/utils/parse.ts
|
@@ -552,7 +843,7 @@ function defineDefaultState({
|
|
552
843
|
"Only one of defaultHTML and defaultDoc can be provided"
|
553
844
|
);
|
554
845
|
}
|
555
|
-
return stateFacet
|
846
|
+
return defineFacetPayload(stateFacet, [
|
556
847
|
({ schema }) => {
|
557
848
|
const config = {};
|
558
849
|
if (defaultHTML) {
|
@@ -573,225 +864,44 @@ function defineDefaultState({
|
|
573
864
|
]);
|
574
865
|
}
|
575
866
|
|
576
|
-
// src/
|
577
|
-
var Priority = /* @__PURE__ */ ((Priority2) => {
|
578
|
-
Priority2[Priority2["lowest"] = 4] = "lowest";
|
579
|
-
Priority2[Priority2["low"] = 3] = "low";
|
580
|
-
Priority2[Priority2["default"] = 2] = "default";
|
581
|
-
Priority2[Priority2["high"] = 1] = "high";
|
582
|
-
Priority2[Priority2["highest"] = 0] = "highest";
|
583
|
-
return Priority2;
|
584
|
-
})(Priority || {});
|
585
|
-
|
586
|
-
// src/facets/command.ts
|
587
|
-
var commandFacet = Facet.defineRootFacet({
|
588
|
-
convert: (inputs) => {
|
589
|
-
return Object.assign({}, ...inputs);
|
590
|
-
}
|
591
|
-
});
|
592
|
-
|
593
|
-
// src/facets/schema.ts
|
867
|
+
// src/utils/deep-equals.ts
|
594
868
|
import OrderedMap from "orderedmap";
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
let nodes = OrderedMap.from({});
|
599
|
-
let marks = OrderedMap.from({});
|
600
|
-
let topNode = void 0;
|
601
|
-
for (const spec of specs) {
|
602
|
-
nodes = nodes.append(spec.nodes);
|
603
|
-
marks = marks.append((_a = spec.marks) != null ? _a : {});
|
604
|
-
topNode = topNode != null ? topNode : spec.topNode;
|
605
|
-
}
|
606
|
-
return { nodes, marks, topNode };
|
869
|
+
function deepEquals(a, b) {
|
870
|
+
if (a === b) {
|
871
|
+
return true;
|
607
872
|
}
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
// src/facets/view.ts
|
612
|
-
var viewFacet = Facet.defineRootFacet({
|
613
|
-
convert: (props) => {
|
614
|
-
return Object.assign({}, ...props);
|
873
|
+
if (!a || !b) {
|
874
|
+
return false;
|
615
875
|
}
|
616
|
-
|
617
|
-
|
618
|
-
// src/facets/flatten.ts
|
619
|
-
function flattenInputTuple(inputTuple) {
|
620
|
-
return [
|
621
|
-
...inputTuple[0],
|
622
|
-
...inputTuple[1],
|
623
|
-
...inputTuple[2],
|
624
|
-
...inputTuple[3],
|
625
|
-
...inputTuple[4]
|
626
|
-
];
|
627
|
-
}
|
628
|
-
function mergeInputTuple(tupleA, tupleB) {
|
629
|
-
if (!tupleA)
|
630
|
-
return tupleB;
|
631
|
-
if (!tupleB)
|
632
|
-
return tupleA;
|
633
|
-
const [a0, a1, a2, a3, a4] = tupleA;
|
634
|
-
const [b0, b1, b2, b3, b4] = tupleB;
|
635
|
-
return [
|
636
|
-
uniqPush(a0, b0),
|
637
|
-
uniqPush(a1, b1),
|
638
|
-
uniqPush(a2, b2),
|
639
|
-
uniqPush(a3, b3),
|
640
|
-
uniqPush(a4, b4)
|
641
|
-
];
|
642
|
-
}
|
643
|
-
function removeInputTuple(tupleA, tupleB) {
|
644
|
-
if (!tupleA)
|
645
|
-
return [[], [], [], [], []];
|
646
|
-
if (!tupleB)
|
647
|
-
return tupleA;
|
648
|
-
const [a0, a1, a2, a3, a4] = tupleA;
|
649
|
-
const [b0, b1, b2, b3, b4] = tupleB;
|
650
|
-
return [
|
651
|
-
uniqRemove(a0, b0),
|
652
|
-
uniqRemove(a1, b1),
|
653
|
-
uniqRemove(a2, b2),
|
654
|
-
uniqRemove(a3, b3),
|
655
|
-
uniqRemove(a4, b4)
|
656
|
-
];
|
657
|
-
}
|
658
|
-
function extractFacets(root) {
|
659
|
-
var _a;
|
660
|
-
const extensions = [root];
|
661
|
-
const priorities = [2 /* default */];
|
662
|
-
const facets = [];
|
663
|
-
const payloads = [];
|
664
|
-
while (extensions.length > 0) {
|
665
|
-
const ext = extensions.pop();
|
666
|
-
const pri = priorities.pop();
|
667
|
-
if (ext instanceof FacetExtensionImpl) {
|
668
|
-
const facet = ext.facet;
|
669
|
-
if (!facets[facet.index]) {
|
670
|
-
facets[facet.index] = facet;
|
671
|
-
payloads[facet.index] = [[], [], [], [], []];
|
672
|
-
}
|
673
|
-
const facetPayloads = ext.payloads;
|
674
|
-
payloads[facet.index][pri].push(...facetPayloads);
|
675
|
-
} else if (ext.extension) {
|
676
|
-
const p = (_a = ext.priority) != null ? _a : pri;
|
677
|
-
if (Array.isArray(ext.extension)) {
|
678
|
-
for (const e of ext.extension) {
|
679
|
-
extensions.push(e);
|
680
|
-
priorities.push(p);
|
681
|
-
}
|
682
|
-
} else {
|
683
|
-
extensions.push(ext.extension);
|
684
|
-
priorities.push(p);
|
685
|
-
}
|
686
|
-
} else {
|
687
|
-
throw new ProseKitError("Invalid extension");
|
688
|
-
}
|
876
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
877
|
+
return a.length === b.length && a.every((x, i) => deepEquals(x, b[i]));
|
689
878
|
}
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
let stateInput = null;
|
698
|
-
let viewInput = null;
|
699
|
-
let commandInput = null;
|
700
|
-
for (let index = getFacetCount(); index >= 0; index--) {
|
701
|
-
const facet = facets[index];
|
702
|
-
if (!facet) {
|
703
|
-
continue;
|
704
|
-
}
|
705
|
-
const nextFacet = facet.next;
|
706
|
-
if (nextFacet) {
|
707
|
-
facets[_a = nextFacet.index] || (facets[_a] = nextFacet);
|
708
|
-
}
|
709
|
-
if (!inputs[facet.index]) {
|
710
|
-
continue;
|
711
|
-
}
|
712
|
-
const inputTuple = modifyInputTuple(prevInputs[index], inputs[index]);
|
713
|
-
prevInputs[index] = inputTuple;
|
714
|
-
if (facet.next && !facet.singleton) {
|
715
|
-
let hasOutput = false;
|
716
|
-
const outputTuple = [[], [], [], [], []];
|
717
|
-
for (let pri = 0; pri < 5; pri++) {
|
718
|
-
const inputArray = inputTuple[pri];
|
719
|
-
if (inputArray.length === 0) {
|
720
|
-
continue;
|
721
|
-
}
|
722
|
-
const converterTuple = prevConverters[index] || (prevConverters[index] = [
|
723
|
-
void 0,
|
724
|
-
void 0,
|
725
|
-
void 0,
|
726
|
-
void 0,
|
727
|
-
void 0
|
728
|
-
]);
|
729
|
-
const prevConverter = converterTuple[pri];
|
730
|
-
const converter = prevConverter || facet.converter();
|
731
|
-
prevConverters[index][pri] = converter;
|
732
|
-
const output = prevConverter ? converter.update(inputArray) : converter.create(inputArray);
|
733
|
-
if (!output) {
|
734
|
-
continue;
|
735
|
-
}
|
736
|
-
hasOutput = true;
|
737
|
-
outputTuple[pri].push(output);
|
738
|
-
}
|
739
|
-
if (!hasOutput) {
|
740
|
-
continue;
|
741
|
-
}
|
742
|
-
inputs[facet.next.index] = modifyInputTuple(
|
743
|
-
inputs[facet.next.index],
|
744
|
-
outputTuple
|
745
|
-
);
|
746
|
-
continue;
|
747
|
-
} else {
|
748
|
-
const inputArray = flattenInputTuple(inputTuple);
|
749
|
-
prevConverters[index] || (prevConverters[index] = [
|
750
|
-
void 0,
|
751
|
-
void 0,
|
752
|
-
void 0,
|
753
|
-
void 0,
|
754
|
-
void 0
|
755
|
-
]);
|
756
|
-
const prevConverter = prevConverters[index][2 /* default */];
|
757
|
-
const converter = prevConverter || facet.converter();
|
758
|
-
prevConverters[index][2 /* default */] = converter;
|
759
|
-
const output = prevConverter ? converter.update(inputArray) : converter.create(inputArray);
|
760
|
-
if (!output) {
|
761
|
-
continue;
|
762
|
-
}
|
763
|
-
if (facet.next) {
|
764
|
-
const outputTuple = [[], [], [output], [], []];
|
765
|
-
inputs[facet.next.index] = modifyInputTuple(
|
766
|
-
inputs[facet.next.index],
|
767
|
-
outputTuple
|
768
|
-
);
|
769
|
-
} else {
|
770
|
-
switch (facet) {
|
771
|
-
case schemaFacet:
|
772
|
-
schemaInput = output;
|
773
|
-
break;
|
774
|
-
case stateFacet:
|
775
|
-
stateInput = output;
|
776
|
-
break;
|
777
|
-
case viewFacet:
|
778
|
-
viewInput = output;
|
779
|
-
break;
|
780
|
-
case commandFacet:
|
781
|
-
commandInput = output;
|
782
|
-
break;
|
783
|
-
default:
|
784
|
-
throw new ProseKitError("Invalid root facet");
|
785
|
-
}
|
786
|
-
}
|
787
|
-
}
|
879
|
+
if (a instanceof OrderedMap && b instanceof OrderedMap) {
|
880
|
+
return a.size === b.size && deepEquals(a.toObject(), b.toObject());
|
881
|
+
}
|
882
|
+
if (typeof a === "object" && typeof b === "object") {
|
883
|
+
const aKeys = Object.keys(a);
|
884
|
+
const bKeys = Object.keys(b);
|
885
|
+
return aKeys.length === bKeys.length && aKeys.every((key) => deepEquals(a[key], b[key]));
|
788
886
|
}
|
789
|
-
return
|
887
|
+
return false;
|
790
888
|
}
|
791
889
|
|
792
890
|
// src/editor/builder.ts
|
793
891
|
import "@prosekit/pm/model";
|
794
892
|
|
893
|
+
// src/utils/is-mark-absent.ts
|
894
|
+
function isMarkAbsent(node, from, to, markType, attrs) {
|
895
|
+
const mark = attrs ? markType.create(attrs) : markType;
|
896
|
+
let missing = false;
|
897
|
+
node.nodesBetween(from, to, (node2, pos, parent) => {
|
898
|
+
if (missing)
|
899
|
+
return false;
|
900
|
+
missing = !mark.isInSet(node2.marks) && !!parent && parent.type.allowsMarkType(markType);
|
901
|
+
});
|
902
|
+
return missing;
|
903
|
+
}
|
904
|
+
|
795
905
|
// src/utils/is-mark-active.ts
|
796
906
|
function isMarkActive(state, type, attrs) {
|
797
907
|
const { from, $from, to, empty } = state.selection;
|
@@ -800,26 +910,25 @@ function isMarkActive(state, type, attrs) {
|
|
800
910
|
const mark = attrs ? markType.create(attrs) : markType;
|
801
911
|
return !!mark.isInSet(state.storedMarks || $from.marks());
|
802
912
|
} else {
|
803
|
-
|
804
|
-
return state.doc.rangeHasMark(from, to, markOrType);
|
913
|
+
return !isMarkAbsent(state.doc, from, to, markType, attrs);
|
805
914
|
}
|
806
915
|
}
|
807
916
|
|
808
917
|
// src/utils/type-assertion.ts
|
809
|
-
import { Mark, ProseMirrorNode } from "@prosekit/pm/model";
|
918
|
+
import { Mark, ProseMirrorNode as ProseMirrorNode2 } from "@prosekit/pm/model";
|
810
919
|
import {
|
811
920
|
AllSelection,
|
812
921
|
NodeSelection,
|
813
|
-
TextSelection as
|
922
|
+
TextSelection as TextSelection5
|
814
923
|
} from "@prosekit/pm/state";
|
815
924
|
function isProseMirrorNode(node) {
|
816
|
-
return node instanceof
|
925
|
+
return node instanceof ProseMirrorNode2;
|
817
926
|
}
|
818
927
|
function isMark(mark) {
|
819
928
|
return mark instanceof Mark;
|
820
929
|
}
|
821
930
|
function isTextSelection(sel) {
|
822
|
-
return sel instanceof
|
931
|
+
return sel instanceof TextSelection5;
|
823
932
|
}
|
824
933
|
function isNodeSelection(sel) {
|
825
934
|
return sel instanceof NodeSelection;
|
@@ -893,43 +1002,27 @@ function isNodeChild(value) {
|
|
893
1002
|
}
|
894
1003
|
|
895
1004
|
// src/facets/union-extension.ts
|
896
|
-
import { Schema as Schema5 } from "@prosekit/pm/model";
|
897
1005
|
var UnionExtensionImpl = class extends BaseExtension {
|
1006
|
+
/**
|
1007
|
+
* @internal
|
1008
|
+
*/
|
898
1009
|
constructor(extension = []) {
|
899
1010
|
super();
|
900
1011
|
this.extension = extension;
|
901
|
-
this._schema = void 0;
|
902
|
-
this.hasSchemaCount = 0;
|
903
|
-
for (const e of extension) {
|
904
|
-
if (e instanceof BaseExtension) {
|
905
|
-
this.hasSchemaCount += e.hasSchema ? 1 : 0;
|
906
|
-
} else {
|
907
|
-
throw new ProseKitError("Invalid extension");
|
908
|
-
}
|
909
|
-
}
|
910
|
-
}
|
911
|
-
get hasSchema() {
|
912
|
-
return this.hasSchemaCount > 0;
|
913
1012
|
}
|
914
|
-
|
1013
|
+
/**
|
1014
|
+
* @internal
|
1015
|
+
*/
|
1016
|
+
createTree(priority) {
|
915
1017
|
var _a;
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
const schema = (_a = this.extension.find((e) => e.hasSchema)) == null ? void 0 : _a.schema;
|
925
|
-
if (schema) {
|
926
|
-
this._schema = schema;
|
927
|
-
return this._schema;
|
928
|
-
}
|
929
|
-
}
|
930
|
-
const { schemaInput } = updateExtension([], [], this, "add");
|
931
|
-
this._schema = schemaInput ? new Schema5(schemaInput) : null;
|
932
|
-
return this._schema;
|
1018
|
+
const pri = (_a = this.priority) != null ? _a : priority;
|
1019
|
+
const extensions = [...this.extension];
|
1020
|
+
extensions.sort((a, b) => {
|
1021
|
+
var _a2, _b;
|
1022
|
+
return ((_a2 = a.priority) != null ? _a2 : pri) - ((_b = b.priority) != null ? _b : pri);
|
1023
|
+
});
|
1024
|
+
const children = extensions.map((ext) => ext.getTree(pri));
|
1025
|
+
return children.reduce(unionFacetNode, new FacetNode(rootFacet));
|
933
1026
|
}
|
934
1027
|
};
|
935
1028
|
|
@@ -961,24 +1054,21 @@ var EditorInstance = class {
|
|
961
1054
|
constructor(extension) {
|
962
1055
|
this.view = null;
|
963
1056
|
this.commandAppliers = {};
|
964
|
-
this.payloads = [];
|
965
|
-
this.converters = [];
|
966
1057
|
this.mount = this.mount.bind(this);
|
967
1058
|
this.unmount = this.unmount.bind(this);
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
const stateConfig = stateInput ? stateInput({ schema }) : { schema };
|
1059
|
+
this.tree = extension.getTree();
|
1060
|
+
const payload = this.tree.getRootOutput();
|
1061
|
+
const schema = payload.schema;
|
1062
|
+
const stateConfig = payload.state;
|
1063
|
+
assert(schema && stateConfig, "Schema must be defined");
|
974
1064
|
const state = EditorState2.create(stateConfig);
|
975
1065
|
this.cachedState = state;
|
976
|
-
if (
|
977
|
-
for (const [name, commandCreator] of Object.entries(
|
1066
|
+
if (payload.commands) {
|
1067
|
+
for (const [name, commandCreator] of Object.entries(payload.commands)) {
|
978
1068
|
this.defineCommand(name, commandCreator);
|
979
1069
|
}
|
980
1070
|
}
|
981
|
-
this.directEditorProps = { state, ...
|
1071
|
+
this.directEditorProps = { state, ...payload.view };
|
982
1072
|
this.schema = this.directEditorProps.state.schema;
|
983
1073
|
const getState = () => this.getState();
|
984
1074
|
this.nodeBuilders = Object.fromEntries(
|
@@ -1000,29 +1090,31 @@ var EditorInstance = class {
|
|
1000
1090
|
}
|
1001
1091
|
return this.cachedState;
|
1002
1092
|
}
|
1003
|
-
updateExtension(extension,
|
1004
|
-
var _a;
|
1005
|
-
const
|
1006
|
-
|
1093
|
+
updateExtension(extension, add) {
|
1094
|
+
var _a, _b, _c, _d, _e;
|
1095
|
+
const tree = extension.getTree();
|
1096
|
+
const payload = tree.getRootOutput();
|
1097
|
+
if (payload == null ? void 0 : payload.schema) {
|
1007
1098
|
throw new ProseKitError("Schema cannot be changed");
|
1008
1099
|
}
|
1009
|
-
if (
|
1100
|
+
if (payload == null ? void 0 : payload.view) {
|
1010
1101
|
throw new ProseKitError("View cannot be changed");
|
1011
1102
|
}
|
1012
|
-
const
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
const state = this.view.state.reconfigure({ plugins });
|
1103
|
+
const oldPayload = this.tree.getRootOutput();
|
1104
|
+
const oldPlugins = [...(_c = (_b = (_a = this.view) == null ? void 0 : _a.state) == null ? void 0 : _b.plugins) != null ? _c : []];
|
1105
|
+
this.tree = add ? unionFacetNode(this.tree, tree) : subtractFacetNode(this.tree, tree);
|
1106
|
+
const newPayload = this.tree.getRootOutput();
|
1107
|
+
const newPlugins = [...(_e = (_d = newPayload == null ? void 0 : newPayload.state) == null ? void 0 : _d.plugins) != null ? _e : []];
|
1108
|
+
if (!deepEquals(oldPlugins, newPlugins)) {
|
1109
|
+
assert(this.view, "EditorInstance.view is not defined");
|
1110
|
+
const state = this.view.state.reconfigure({ plugins: newPlugins });
|
1020
1111
|
this.view.updateState(state);
|
1021
1112
|
}
|
1022
|
-
if (
|
1023
|
-
const
|
1113
|
+
if ((newPayload == null ? void 0 : newPayload.commands) && !deepEquals(oldPayload == null ? void 0 : oldPayload.commands, newPayload == null ? void 0 : newPayload.commands)) {
|
1114
|
+
const commands = newPayload.commands;
|
1115
|
+
const names = Object.keys(commands);
|
1024
1116
|
for (const name of names) {
|
1025
|
-
this.defineCommand(name,
|
1117
|
+
this.defineCommand(name, commands[name]);
|
1026
1118
|
}
|
1027
1119
|
}
|
1028
1120
|
}
|
@@ -1176,8 +1268,8 @@ var Editor = class _Editor {
|
|
1176
1268
|
lazyRemove == null ? void 0 : lazyRemove();
|
1177
1269
|
};
|
1178
1270
|
}
|
1179
|
-
this.instance.updateExtension(extension,
|
1180
|
-
return () => this.instance.updateExtension(extension,
|
1271
|
+
this.instance.updateExtension(extension, true);
|
1272
|
+
return () => this.instance.updateExtension(extension, false);
|
1181
1273
|
}
|
1182
1274
|
get state() {
|
1183
1275
|
return this.instance.getState();
|
@@ -1241,9 +1333,19 @@ function wrap({
|
|
1241
1333
|
};
|
1242
1334
|
}
|
1243
1335
|
|
1336
|
+
// src/facets/command.ts
|
1337
|
+
var commandFacet = defineFacet({
|
1338
|
+
reducer: (inputs) => {
|
1339
|
+
const commands = Object.assign({}, ...inputs);
|
1340
|
+
return { commands };
|
1341
|
+
},
|
1342
|
+
parent: rootFacet,
|
1343
|
+
singleton: true
|
1344
|
+
});
|
1345
|
+
|
1244
1346
|
// src/extensions/command.ts
|
1245
1347
|
function defineCommands(commands) {
|
1246
|
-
return commandFacet
|
1348
|
+
return defineFacetPayload(commandFacet, [commands]);
|
1247
1349
|
}
|
1248
1350
|
function defineBaseCommands() {
|
1249
1351
|
return defineCommands({
|
@@ -1258,6 +1360,29 @@ function defineBaseCommands() {
|
|
1258
1360
|
});
|
1259
1361
|
}
|
1260
1362
|
|
1363
|
+
// src/extensions/node-spec.ts
|
1364
|
+
import OrderedMap3 from "orderedmap";
|
1365
|
+
|
1366
|
+
// src/facets/schema-spec.ts
|
1367
|
+
import "@prosekit/pm/model";
|
1368
|
+
import OrderedMap2 from "orderedmap";
|
1369
|
+
var schemaSpecFacet = defineFacet({
|
1370
|
+
reducer: (specs) => {
|
1371
|
+
var _a;
|
1372
|
+
let nodes = OrderedMap2.from({});
|
1373
|
+
let marks = OrderedMap2.from({});
|
1374
|
+
let topNode = void 0;
|
1375
|
+
for (const spec of specs) {
|
1376
|
+
nodes = nodes.append(spec.nodes);
|
1377
|
+
marks = marks.append((_a = spec.marks) != null ? _a : {});
|
1378
|
+
topNode = topNode != null ? topNode : spec.topNode;
|
1379
|
+
}
|
1380
|
+
return { nodes, marks, topNode };
|
1381
|
+
},
|
1382
|
+
parent: schemaFacet,
|
1383
|
+
singleton: true
|
1384
|
+
});
|
1385
|
+
|
1261
1386
|
// src/utils/is-element.ts
|
1262
1387
|
var hasElement = typeof Element !== "undefined";
|
1263
1388
|
function isElement(value) {
|
@@ -1272,44 +1397,39 @@ function isNotNull(value) {
|
|
1272
1397
|
// src/extensions/node-spec.ts
|
1273
1398
|
function defineNodeSpec(options) {
|
1274
1399
|
const payload = [options, void 0];
|
1275
|
-
return nodeSpecFacet
|
1400
|
+
return defineFacetPayload(nodeSpecFacet, [payload]);
|
1276
1401
|
}
|
1277
1402
|
function defineNodeAttr(options) {
|
1278
1403
|
const payload = [void 0, options];
|
1279
|
-
return nodeSpecFacet
|
1404
|
+
return defineFacetPayload(nodeSpecFacet, [payload]);
|
1280
1405
|
}
|
1281
|
-
var nodeSpecFacet =
|
1282
|
-
|
1283
|
-
|
1406
|
+
var nodeSpecFacet = defineFacet({
|
1407
|
+
reducer: (payloads) => {
|
1408
|
+
let nodes = OrderedMap3.from({});
|
1284
1409
|
let topNodeName = void 0;
|
1285
1410
|
const specPayloads = payloads.map((input) => input[0]).filter(isNotNull);
|
1286
1411
|
const attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
|
1287
1412
|
for (const { name, topNode, ...spec } of specPayloads) {
|
1288
|
-
|
1289
|
-
throw new ProseKitError(`Node type ${name} has already been defined`);
|
1290
|
-
}
|
1413
|
+
assert(!nodes.get(name), `Node type ${name} can only be defined once`);
|
1291
1414
|
if (topNode) {
|
1292
1415
|
topNodeName = name;
|
1293
1416
|
}
|
1294
|
-
nodes
|
1417
|
+
nodes = nodes.addToStart(name, spec);
|
1295
1418
|
}
|
1296
1419
|
for (const {
|
1297
1420
|
type,
|
1298
1421
|
attr,
|
1299
1422
|
default: defaultValue,
|
1423
|
+
splittable,
|
1300
1424
|
toDOM,
|
1301
1425
|
parseDOM
|
1302
1426
|
} of attrPayloads) {
|
1303
|
-
const spec = nodes
|
1304
|
-
|
1305
|
-
throw new ProseKitError(
|
1306
|
-
`Node type ${type} must be defined before defining attributes`
|
1307
|
-
);
|
1308
|
-
}
|
1427
|
+
const spec = nodes.get(type);
|
1428
|
+
assert(spec, `Node type ${type} must be defined`);
|
1309
1429
|
if (!spec.attrs) {
|
1310
1430
|
spec.attrs = {};
|
1311
1431
|
}
|
1312
|
-
spec.attrs[attr] = { default: defaultValue };
|
1432
|
+
spec.attrs[attr] = { default: defaultValue, splittable };
|
1313
1433
|
if (toDOM && spec.toDOM) {
|
1314
1434
|
const existingToDom = spec.toDOM;
|
1315
1435
|
spec.toDOM = (node) => {
|
@@ -1327,14 +1447,22 @@ var nodeSpecFacet = Facet.define({
|
|
1327
1447
|
}
|
1328
1448
|
if (Array.isArray(dom)) {
|
1329
1449
|
if (typeof dom[1] === "object") {
|
1330
|
-
return [
|
1450
|
+
return [
|
1451
|
+
dom[0],
|
1452
|
+
setObjectAttribute(
|
1453
|
+
dom[1],
|
1454
|
+
key,
|
1455
|
+
value
|
1456
|
+
),
|
1457
|
+
...dom.slice(2)
|
1458
|
+
];
|
1331
1459
|
} else {
|
1332
1460
|
return [dom[0], { [key]: value }, ...dom.slice(1)];
|
1333
1461
|
}
|
1334
1462
|
} else if (isElement(dom)) {
|
1335
|
-
dom
|
1463
|
+
setElementAttribute(dom, key, value);
|
1336
1464
|
} else if (typeof dom === "object" && "dom" in dom && isElement(dom.dom)) {
|
1337
|
-
dom.dom
|
1465
|
+
setElementAttribute(dom.dom, key, value);
|
1338
1466
|
}
|
1339
1467
|
return dom;
|
1340
1468
|
};
|
@@ -1360,9 +1488,21 @@ var nodeSpecFacet = Facet.define({
|
|
1360
1488
|
}
|
1361
1489
|
return { nodes, topNode: topNodeName };
|
1362
1490
|
},
|
1363
|
-
|
1491
|
+
parent: schemaSpecFacet,
|
1364
1492
|
singleton: true
|
1365
1493
|
});
|
1494
|
+
function setObjectAttribute(obj, key, value) {
|
1495
|
+
if (key === "style") {
|
1496
|
+
value = `${value}${obj.style || ""}`;
|
1497
|
+
}
|
1498
|
+
return { ...obj, [key]: value };
|
1499
|
+
}
|
1500
|
+
function setElementAttribute(element, key, value) {
|
1501
|
+
if (key === "style") {
|
1502
|
+
value = `${value}${element.getAttribute("style") || ""}`;
|
1503
|
+
}
|
1504
|
+
element.setAttribute(key, value);
|
1505
|
+
}
|
1366
1506
|
|
1367
1507
|
// src/extensions/doc.ts
|
1368
1508
|
function defineDoc() {
|
@@ -1374,60 +1514,61 @@ function defineDoc() {
|
|
1374
1514
|
}
|
1375
1515
|
|
1376
1516
|
// src/extensions/events/plugin-view.ts
|
1377
|
-
import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
|
1517
|
+
import { PluginKey, ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm/state";
|
1378
1518
|
|
1379
1519
|
// src/extensions/plugin.ts
|
1380
1520
|
import "@prosekit/pm/model";
|
1381
1521
|
import { Plugin as Plugin2 } from "@prosekit/pm/state";
|
1382
1522
|
function definePlugin(plugin) {
|
1383
1523
|
if (plugin instanceof Plugin2) {
|
1384
|
-
return pluginFacet
|
1524
|
+
return defineFacetPayload(pluginFacet, [() => [plugin]]);
|
1385
1525
|
}
|
1386
1526
|
if (Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin2)) {
|
1387
|
-
return pluginFacet
|
1527
|
+
return defineFacetPayload(pluginFacet, [() => plugin]);
|
1388
1528
|
}
|
1389
1529
|
if (typeof plugin === "function") {
|
1390
|
-
return pluginFacet
|
1530
|
+
return defineFacetPayload(pluginFacet, [plugin]);
|
1391
1531
|
}
|
1392
1532
|
throw new TypeError("Invalid plugin");
|
1393
1533
|
}
|
1394
|
-
var pluginFacet =
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
const
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
return output;
|
1534
|
+
var pluginFacet = defineFacet({
|
1535
|
+
reducer: (payloads) => {
|
1536
|
+
return ({ schema }) => {
|
1537
|
+
const plugins = [];
|
1538
|
+
for (const payload of payloads) {
|
1539
|
+
if (payload instanceof Plugin2) {
|
1540
|
+
plugins.push(payload);
|
1541
|
+
} else if (Array.isArray(payload) && payload.every((p) => p instanceof Plugin2)) {
|
1542
|
+
plugins.push(...payload);
|
1543
|
+
} else if (typeof payload === "function") {
|
1544
|
+
plugins.push(...[payload({ schema })].flat());
|
1545
|
+
} else {
|
1546
|
+
throw new ProseKitError("Invalid plugin");
|
1547
|
+
}
|
1409
1548
|
}
|
1549
|
+
plugins.reverse();
|
1550
|
+
return { plugins };
|
1410
1551
|
};
|
1411
1552
|
},
|
1412
|
-
|
1553
|
+
parent: stateFacet
|
1413
1554
|
});
|
1414
1555
|
|
1415
1556
|
// src/extensions/events/plugin-view.ts
|
1416
1557
|
function defineMountHandler(handler) {
|
1417
|
-
return pluginViewFacet
|
1558
|
+
return defineFacetPayload(pluginViewFacet, [["mount", handler]]);
|
1418
1559
|
}
|
1419
1560
|
function defineUpdateHandler(handler) {
|
1420
|
-
return pluginViewFacet
|
1561
|
+
return defineFacetPayload(pluginViewFacet, [["update", handler]]);
|
1421
1562
|
}
|
1422
1563
|
function defineUnmountHandler(handler) {
|
1423
|
-
return pluginViewFacet
|
1564
|
+
return defineFacetPayload(pluginViewFacet, [["unmount", handler]]);
|
1424
1565
|
}
|
1425
|
-
var pluginViewFacet =
|
1426
|
-
|
1566
|
+
var pluginViewFacet = defineFacet({
|
1567
|
+
reduce: () => {
|
1427
1568
|
let mountHandlers = [];
|
1428
1569
|
let updateHandlers = [];
|
1429
1570
|
let unmountHandlers = [];
|
1430
|
-
const plugin = new
|
1571
|
+
const plugin = new ProseMirrorPlugin2({
|
1431
1572
|
key: pluginKey,
|
1432
1573
|
view: (view) => {
|
1433
1574
|
mountHandlers.forEach((fn) => fn(view));
|
@@ -1441,7 +1582,6 @@ var pluginViewFacet = Facet.define({
|
|
1441
1582
|
};
|
1442
1583
|
}
|
1443
1584
|
});
|
1444
|
-
const pluginFunc = () => [plugin];
|
1445
1585
|
const register = (input) => {
|
1446
1586
|
mountHandlers = [];
|
1447
1587
|
updateHandlers = [];
|
@@ -1460,18 +1600,12 @@ var pluginViewFacet = Facet.define({
|
|
1460
1600
|
}
|
1461
1601
|
}
|
1462
1602
|
};
|
1463
|
-
return {
|
1464
|
-
|
1465
|
-
|
1466
|
-
return pluginFunc;
|
1467
|
-
},
|
1468
|
-
update: (input) => {
|
1469
|
-
register(input);
|
1470
|
-
return null;
|
1471
|
-
}
|
1603
|
+
return function reducer(input) {
|
1604
|
+
register(input);
|
1605
|
+
return plugin;
|
1472
1606
|
};
|
1473
1607
|
},
|
1474
|
-
|
1608
|
+
parent: pluginFacet,
|
1475
1609
|
singleton: true
|
1476
1610
|
});
|
1477
1611
|
var pluginKey = new PluginKey("prosekit-plugin-view-handler");
|
@@ -1486,13 +1620,13 @@ function defineDocChangeHandler(handler) {
|
|
1486
1620
|
}
|
1487
1621
|
|
1488
1622
|
// src/extensions/events/dom-event.ts
|
1489
|
-
import { PluginKey as PluginKey2, ProseMirrorPlugin as
|
1623
|
+
import { PluginKey as PluginKey2, ProseMirrorPlugin as ProseMirrorPlugin3 } from "@prosekit/pm/state";
|
1490
1624
|
|
1491
1625
|
// src/utils/combine-event-handlers.ts
|
1492
1626
|
function combineEventHandlers() {
|
1493
1627
|
let _handlers = [];
|
1494
1628
|
function setHandlers(handlers) {
|
1495
|
-
_handlers = handlers;
|
1629
|
+
_handlers = toReversed(handlers);
|
1496
1630
|
}
|
1497
1631
|
function combinedEventHandler(...args) {
|
1498
1632
|
for (const handler of _handlers) {
|
@@ -1521,106 +1655,97 @@ function groupEntries(entries) {
|
|
1521
1655
|
|
1522
1656
|
// src/extensions/events/dom-event.ts
|
1523
1657
|
function defineDOMEventHandler(event, handler) {
|
1524
|
-
return domEventFacet
|
1658
|
+
return defineFacetPayload(domEventFacet, [
|
1525
1659
|
[event, handler]
|
1526
1660
|
]);
|
1527
1661
|
}
|
1528
|
-
var domEventFacet =
|
1529
|
-
|
1662
|
+
var domEventFacet = defineFacet({
|
1663
|
+
reduce: () => {
|
1530
1664
|
const setHandlersMap = {};
|
1531
1665
|
const combinedHandlerMap = {};
|
1666
|
+
let plugin = null;
|
1532
1667
|
const update = (payloads) => {
|
1668
|
+
var _a;
|
1533
1669
|
let hasNewEvent = false;
|
1534
1670
|
for (const [event] of payloads) {
|
1535
1671
|
if (!setHandlersMap[event]) {
|
1536
1672
|
hasNewEvent = true;
|
1537
1673
|
const [setHandlers, combinedHandler] = combineEventHandlers();
|
1538
1674
|
setHandlersMap[event] = setHandlers;
|
1539
|
-
|
1675
|
+
const e = (view, eventObject) => {
|
1676
|
+
return combinedHandler(view, eventObject);
|
1677
|
+
};
|
1678
|
+
combinedHandlerMap[event] = e;
|
1540
1679
|
}
|
1541
1680
|
}
|
1542
1681
|
const map = groupEntries(payloads);
|
1543
|
-
for (const [event,
|
1544
|
-
const
|
1545
|
-
setHandlers(handlers
|
1682
|
+
for (const [event, setHandlers] of Object.entries(setHandlersMap)) {
|
1683
|
+
const handlers = (_a = map[event]) != null ? _a : [];
|
1684
|
+
setHandlers(handlers);
|
1546
1685
|
}
|
1547
1686
|
if (hasNewEvent) {
|
1548
|
-
|
1687
|
+
plugin = new ProseMirrorPlugin3({
|
1549
1688
|
key: new PluginKey2("prosekit-dom-event-handler"),
|
1550
1689
|
props: { handleDOMEvents: combinedHandlerMap }
|
1551
1690
|
});
|
1552
|
-
} else {
|
1553
|
-
return null;
|
1554
1691
|
}
|
1555
1692
|
};
|
1556
|
-
return {
|
1557
|
-
|
1558
|
-
|
1559
|
-
return plugin ? () => plugin : () => [];
|
1560
|
-
},
|
1561
|
-
update: (payloads) => {
|
1562
|
-
const plugin = update(payloads);
|
1563
|
-
return plugin ? () => plugin : null;
|
1564
|
-
}
|
1693
|
+
return function reducer(inputs) {
|
1694
|
+
update(inputs);
|
1695
|
+
return plugin != null ? plugin : [];
|
1565
1696
|
};
|
1566
1697
|
},
|
1567
|
-
|
1698
|
+
parent: pluginFacet,
|
1568
1699
|
singleton: true
|
1569
1700
|
});
|
1570
1701
|
|
1571
1702
|
// src/extensions/events/editor-event.ts
|
1572
|
-
import { PluginKey as PluginKey3, ProseMirrorPlugin as
|
1703
|
+
import { PluginKey as PluginKey3, ProseMirrorPlugin as ProseMirrorPlugin4 } from "@prosekit/pm/state";
|
1573
1704
|
function defineKeyDownHandler(handler) {
|
1574
|
-
return editorEventFacet
|
1705
|
+
return defineFacetPayload(editorEventFacet, [["keyDown", handler]]);
|
1575
1706
|
}
|
1576
1707
|
function defineKeyPressHandler(handler) {
|
1577
|
-
return editorEventFacet
|
1708
|
+
return defineFacetPayload(editorEventFacet, [["keyPress", handler]]);
|
1578
1709
|
}
|
1579
1710
|
function defineTextInputHandler(handler) {
|
1580
|
-
return editorEventFacet
|
1711
|
+
return defineFacetPayload(editorEventFacet, [["textInput", handler]]);
|
1581
1712
|
}
|
1582
1713
|
function defineClickOnHandler(handler) {
|
1583
|
-
return editorEventFacet
|
1714
|
+
return defineFacetPayload(editorEventFacet, [["clickOn", handler]]);
|
1584
1715
|
}
|
1585
1716
|
function defineClickHandler(handler) {
|
1586
|
-
return editorEventFacet
|
1717
|
+
return defineFacetPayload(editorEventFacet, [["click", handler]]);
|
1587
1718
|
}
|
1588
1719
|
function defineDoubleClickOnHandler(handler) {
|
1589
|
-
return editorEventFacet
|
1720
|
+
return defineFacetPayload(editorEventFacet, [["doubleClickOn", handler]]);
|
1590
1721
|
}
|
1591
1722
|
function defineDoubleClickHandler(handler) {
|
1592
|
-
return editorEventFacet
|
1723
|
+
return defineFacetPayload(editorEventFacet, [["doubleClick", handler]]);
|
1593
1724
|
}
|
1594
1725
|
function defineTripleClickOnHandler(handler) {
|
1595
|
-
return editorEventFacet
|
1726
|
+
return defineFacetPayload(editorEventFacet, [["tripleClickOn", handler]]);
|
1596
1727
|
}
|
1597
1728
|
function defineTripleClickHandler(handler) {
|
1598
|
-
return editorEventFacet
|
1729
|
+
return defineFacetPayload(editorEventFacet, [["tripleClick", handler]]);
|
1599
1730
|
}
|
1600
1731
|
function definePasteHandler(handler) {
|
1601
|
-
return editorEventFacet
|
1732
|
+
return defineFacetPayload(editorEventFacet, [["paste", handler]]);
|
1602
1733
|
}
|
1603
1734
|
function defineDropHandler(handler) {
|
1604
|
-
return editorEventFacet
|
1735
|
+
return defineFacetPayload(editorEventFacet, [["drop", handler]]);
|
1605
1736
|
}
|
1606
1737
|
function defineScrollToSelectionHandler(handler) {
|
1607
|
-
return editorEventFacet
|
1738
|
+
return defineFacetPayload(editorEventFacet, [["scrollToSelection", handler]]);
|
1608
1739
|
}
|
1609
|
-
var editorEventFacet =
|
1610
|
-
|
1740
|
+
var editorEventFacet = defineFacet({
|
1741
|
+
reduce: () => {
|
1611
1742
|
const [update, plugin] = setupEditorEventPlugin();
|
1612
|
-
return {
|
1613
|
-
|
1614
|
-
|
1615
|
-
return () => plugin;
|
1616
|
-
},
|
1617
|
-
update: (entries) => {
|
1618
|
-
update(entries);
|
1619
|
-
return null;
|
1620
|
-
}
|
1743
|
+
return (entries) => {
|
1744
|
+
update(entries);
|
1745
|
+
return plugin;
|
1621
1746
|
};
|
1622
1747
|
},
|
1623
|
-
|
1748
|
+
parent: pluginFacet,
|
1624
1749
|
singleton: true
|
1625
1750
|
});
|
1626
1751
|
function setupEditorEventPlugin() {
|
@@ -1652,8 +1777,8 @@ function setupEditorEventPlugin() {
|
|
1652
1777
|
setDropHandlers((_k = map.drop) != null ? _k : []);
|
1653
1778
|
setScrollToSelectionHandlers((_l = map.scrollToSelection) != null ? _l : []);
|
1654
1779
|
};
|
1655
|
-
const plugin = new
|
1656
|
-
key: new PluginKey3("prosekit-editor-
|
1780
|
+
const plugin = new ProseMirrorPlugin4({
|
1781
|
+
key: new PluginKey3("prosekit-editor-event"),
|
1657
1782
|
props: {
|
1658
1783
|
handleKeyDown,
|
1659
1784
|
handleKeyPress,
|
@@ -1676,7 +1801,7 @@ function setupEditorEventPlugin() {
|
|
1676
1801
|
function defineFocusChangeHandler(handler) {
|
1677
1802
|
const handleFocus = () => handler(true);
|
1678
1803
|
const handleBlur = () => handler(false);
|
1679
|
-
return domEventFacet
|
1804
|
+
return defineFacetPayload(domEventFacet, [
|
1680
1805
|
["focus", handleFocus],
|
1681
1806
|
["blur", handleBlur]
|
1682
1807
|
]);
|
@@ -1686,22 +1811,127 @@ function defineFocusChangeHandler(handler) {
|
|
1686
1811
|
import { history, redo, undo } from "@prosekit/pm/history";
|
1687
1812
|
|
1688
1813
|
// src/utils/env.ts
|
1689
|
-
var
|
1814
|
+
var isApple = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
|
1690
1815
|
|
1691
1816
|
// src/extensions/keymap.ts
|
1692
|
-
import {
|
1817
|
+
import {
|
1818
|
+
baseKeymap,
|
1819
|
+
chainCommands,
|
1820
|
+
createParagraphNear,
|
1821
|
+
liftEmptyBlock,
|
1822
|
+
newlineInCode
|
1823
|
+
} from "@prosekit/pm/commands";
|
1693
1824
|
import { keydownHandler } from "@prosekit/pm/keymap";
|
1694
1825
|
import { Plugin as Plugin3, PluginKey as PluginKey4 } from "@prosekit/pm/state";
|
1826
|
+
|
1827
|
+
// src/commands/split-block-as.ts
|
1828
|
+
import {
|
1829
|
+
AllSelection as AllSelection3,
|
1830
|
+
NodeSelection as NodeSelection2,
|
1831
|
+
TextSelection as TextSelection6
|
1832
|
+
} from "@prosekit/pm/state";
|
1833
|
+
import { canSplit } from "@prosekit/pm/transform";
|
1834
|
+
|
1835
|
+
// src/utils/default-block-at.ts
|
1836
|
+
function defaultBlockAt(match) {
|
1837
|
+
for (let i = 0; i < match.edgeCount; i++) {
|
1838
|
+
const { type } = match.edge(i);
|
1839
|
+
if (type.isTextblock && !type.hasRequiredAttrs())
|
1840
|
+
return type;
|
1841
|
+
}
|
1842
|
+
return null;
|
1843
|
+
}
|
1844
|
+
|
1845
|
+
// src/commands/split-block-as.ts
|
1846
|
+
function splitBlockAs(splitNode) {
|
1847
|
+
return (state, dispatch) => {
|
1848
|
+
const { $from, $to } = state.selection;
|
1849
|
+
if (state.selection instanceof NodeSelection2 && state.selection.node.isBlock) {
|
1850
|
+
if (!$from.parentOffset || !canSplit(state.doc, $from.pos))
|
1851
|
+
return false;
|
1852
|
+
if (dispatch)
|
1853
|
+
dispatch(state.tr.split($from.pos).scrollIntoView());
|
1854
|
+
return true;
|
1855
|
+
}
|
1856
|
+
if (!$from.parent.isBlock)
|
1857
|
+
return false;
|
1858
|
+
if (dispatch) {
|
1859
|
+
const atEnd = $to.parentOffset == $to.parent.content.size;
|
1860
|
+
const tr = state.tr;
|
1861
|
+
if (state.selection instanceof TextSelection6 || state.selection instanceof AllSelection3)
|
1862
|
+
tr.deleteSelection();
|
1863
|
+
const deflt = $from.depth == 0 ? null : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)));
|
1864
|
+
const splitType = splitNode && splitNode($from.parent, deflt, atEnd);
|
1865
|
+
let types = splitType ? [splitType] : atEnd && deflt ? [{ type: deflt }] : void 0;
|
1866
|
+
let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types);
|
1867
|
+
if (!types && !can && canSplit(
|
1868
|
+
tr.doc,
|
1869
|
+
tr.mapping.map($from.pos),
|
1870
|
+
1,
|
1871
|
+
deflt ? [{ type: deflt }] : void 0
|
1872
|
+
)) {
|
1873
|
+
if (deflt)
|
1874
|
+
types = [{ type: deflt }];
|
1875
|
+
can = true;
|
1876
|
+
}
|
1877
|
+
if (can) {
|
1878
|
+
tr.split(tr.mapping.map($from.pos), 1, types);
|
1879
|
+
if (!atEnd && !$from.parentOffset && $from.parent.type != deflt) {
|
1880
|
+
const first = tr.mapping.map($from.before()), $first = tr.doc.resolve(first);
|
1881
|
+
if (deflt && $from.node(-1).canReplaceWith($first.index(), $first.index() + 1, deflt))
|
1882
|
+
tr.setNodeMarkup(tr.mapping.map($from.before()), deflt);
|
1883
|
+
}
|
1884
|
+
}
|
1885
|
+
dispatch(tr.scrollIntoView());
|
1886
|
+
}
|
1887
|
+
return true;
|
1888
|
+
};
|
1889
|
+
}
|
1890
|
+
|
1891
|
+
// src/commands/split-block-enter.ts
|
1892
|
+
var splitBlockEnter = splitBlockAs((node, deflt, atEnd) => {
|
1893
|
+
if (atEnd && deflt) {
|
1894
|
+
const attrs = pickSplittableAttrs(node, deflt);
|
1895
|
+
if (attrs) {
|
1896
|
+
return { type: deflt, attrs };
|
1897
|
+
}
|
1898
|
+
}
|
1899
|
+
return null;
|
1900
|
+
});
|
1901
|
+
function pickSplittableAttrs(node, type) {
|
1902
|
+
var _a;
|
1903
|
+
const attrs = {};
|
1904
|
+
let found = false;
|
1905
|
+
for (const [attr, value] of Object.entries(node.attrs)) {
|
1906
|
+
const spec = (_a = type.spec.attrs) == null ? void 0 : _a[attr];
|
1907
|
+
if (spec && spec.default !== value && spec.splittable === true) {
|
1908
|
+
attrs[attr] = value;
|
1909
|
+
found = true;
|
1910
|
+
}
|
1911
|
+
}
|
1912
|
+
return found ? attrs : null;
|
1913
|
+
}
|
1914
|
+
|
1915
|
+
// src/extensions/keymap.ts
|
1916
|
+
var customBaseKeymap = {
|
1917
|
+
...baseKeymap,
|
1918
|
+
Enter: chainCommands(
|
1919
|
+
newlineInCode,
|
1920
|
+
createParagraphNear,
|
1921
|
+
liftEmptyBlock,
|
1922
|
+
splitBlockEnter
|
1923
|
+
)
|
1924
|
+
};
|
1695
1925
|
function defineKeymap(keymap) {
|
1696
|
-
return keymapFacet
|
1926
|
+
return defineFacetPayload(keymapFacet, [keymap]);
|
1697
1927
|
}
|
1698
1928
|
function defineBaseKeymap(options) {
|
1699
1929
|
var _a;
|
1700
|
-
const priority = (_a = options == null ? void 0 : options.priority) != null ? _a :
|
1701
|
-
return withPriority(defineKeymap(
|
1930
|
+
const priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */;
|
1931
|
+
return withPriority(defineKeymap(customBaseKeymap), priority);
|
1702
1932
|
}
|
1703
|
-
var keymapFacet =
|
1704
|
-
|
1933
|
+
var keymapFacet = defineFacet({
|
1934
|
+
reduce: () => {
|
1705
1935
|
let handler = null;
|
1706
1936
|
const handlerWrapper = (view, event) => {
|
1707
1937
|
if (handler)
|
@@ -1712,19 +1942,17 @@ var keymapFacet = Facet.define({
|
|
1712
1942
|
key: keymapPluginKey,
|
1713
1943
|
props: { handleKeyDown: handlerWrapper }
|
1714
1944
|
});
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
return null;
|
1724
|
-
}
|
1945
|
+
return (keymaps) => {
|
1946
|
+
handler = keydownHandler(
|
1947
|
+
mergeKeymaps(
|
1948
|
+
// The keymap at the end have a higher priority.
|
1949
|
+
toReversed(keymaps)
|
1950
|
+
)
|
1951
|
+
);
|
1952
|
+
return plugin;
|
1725
1953
|
};
|
1726
1954
|
},
|
1727
|
-
|
1955
|
+
parent: pluginFacet,
|
1728
1956
|
singleton: true
|
1729
1957
|
});
|
1730
1958
|
function mergeKeymaps(keymaps) {
|
@@ -1750,7 +1978,7 @@ function defineHistory() {
|
|
1750
1978
|
"Mod-z": undo,
|
1751
1979
|
"Shift-Mod-z": redo
|
1752
1980
|
};
|
1753
|
-
if (!
|
1981
|
+
if (!isApple) {
|
1754
1982
|
keymap["Mod-y"] = redo;
|
1755
1983
|
}
|
1756
1984
|
return union([
|
@@ -1766,14 +1994,14 @@ function defineHistory() {
|
|
1766
1994
|
// src/extensions/mark-spec.ts
|
1767
1995
|
function defineMarkSpec(options) {
|
1768
1996
|
const payload = [options, void 0];
|
1769
|
-
return markSpecFacet
|
1997
|
+
return defineFacetPayload(markSpecFacet, [payload]);
|
1770
1998
|
}
|
1771
1999
|
function defineMarkAttr(options) {
|
1772
2000
|
const payload = [void 0, options];
|
1773
|
-
return markSpecFacet
|
2001
|
+
return defineFacetPayload(markSpecFacet, [payload]);
|
1774
2002
|
}
|
1775
|
-
var markSpecFacet =
|
1776
|
-
|
2003
|
+
var markSpecFacet = defineFacet({
|
2004
|
+
reducer: (payloads) => {
|
1777
2005
|
const marks = {};
|
1778
2006
|
const specPayloads = payloads.map((input) => input[0]).filter(isNotNull);
|
1779
2007
|
const attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
|
@@ -1850,37 +2078,42 @@ var markSpecFacet = Facet.define({
|
|
1850
2078
|
}
|
1851
2079
|
return { marks, nodes: {} };
|
1852
2080
|
},
|
1853
|
-
|
2081
|
+
parent: schemaSpecFacet,
|
1854
2082
|
singleton: true
|
1855
2083
|
});
|
1856
2084
|
|
1857
2085
|
// src/extensions/node-view.ts
|
1858
|
-
import { ProseMirrorPlugin as
|
2086
|
+
import { PluginKey as PluginKey5, ProseMirrorPlugin as ProseMirrorPlugin5 } from "@prosekit/pm/state";
|
1859
2087
|
import "@prosekit/pm/view";
|
1860
2088
|
function defineNodeView(options) {
|
1861
|
-
return nodeViewFacet
|
2089
|
+
return defineFacetPayload(nodeViewFacet, [options]);
|
1862
2090
|
}
|
1863
|
-
var nodeViewFacet =
|
1864
|
-
|
2091
|
+
var nodeViewFacet = defineFacet({
|
2092
|
+
reducer: (inputs) => {
|
1865
2093
|
const nodeViews = {};
|
1866
2094
|
for (const input of inputs) {
|
1867
2095
|
if (!nodeViews[input.name]) {
|
1868
2096
|
nodeViews[input.name] = input.constructor;
|
1869
2097
|
}
|
1870
2098
|
}
|
1871
|
-
return () => [
|
2099
|
+
return () => [
|
2100
|
+
new ProseMirrorPlugin5({
|
2101
|
+
key: new PluginKey5("prosekit-node-view"),
|
2102
|
+
props: { nodeViews }
|
2103
|
+
})
|
2104
|
+
];
|
1872
2105
|
},
|
1873
|
-
|
2106
|
+
parent: pluginFacet
|
1874
2107
|
});
|
1875
2108
|
|
1876
2109
|
// src/extensions/node-view-effect.ts
|
1877
|
-
import { ProseMirrorPlugin as
|
2110
|
+
import { PluginKey as PluginKey6, ProseMirrorPlugin as ProseMirrorPlugin6 } from "@prosekit/pm/state";
|
1878
2111
|
import "@prosekit/pm/view";
|
1879
2112
|
function defineNodeViewFactory(options) {
|
1880
|
-
return nodeViewFactoryFacet
|
2113
|
+
return defineFacetPayload(nodeViewFactoryFacet, [options]);
|
1881
2114
|
}
|
1882
|
-
var nodeViewFactoryFacet =
|
1883
|
-
|
2115
|
+
var nodeViewFactoryFacet = defineFacet({
|
2116
|
+
reducer: (inputs) => {
|
1884
2117
|
const nodeViews = {};
|
1885
2118
|
const options = {};
|
1886
2119
|
const factories = {};
|
@@ -1902,9 +2135,14 @@ var nodeViewFactoryFacet = Facet.define({
|
|
1902
2135
|
nodeViews[name] = factory(args);
|
1903
2136
|
}
|
1904
2137
|
}
|
1905
|
-
return () => [
|
2138
|
+
return () => [
|
2139
|
+
new ProseMirrorPlugin6({
|
2140
|
+
key: new PluginKey6("prosekit-node-view-effect"),
|
2141
|
+
props: { nodeViews }
|
2142
|
+
})
|
2143
|
+
];
|
1906
2144
|
},
|
1907
|
-
|
2145
|
+
parent: pluginFacet
|
1908
2146
|
});
|
1909
2147
|
|
1910
2148
|
// src/extensions/paragraph.ts
|
@@ -1920,7 +2158,7 @@ function defineParagraphSpec() {
|
|
1920
2158
|
});
|
1921
2159
|
}
|
1922
2160
|
function defineParagraph() {
|
1923
|
-
return withPriority(defineParagraphSpec(),
|
2161
|
+
return withPriority(defineParagraphSpec(), 4 /* highest */);
|
1924
2162
|
}
|
1925
2163
|
|
1926
2164
|
// src/extensions/text.ts
|
@@ -1931,20 +2169,30 @@ function defineText() {
|
|
1931
2169
|
});
|
1932
2170
|
}
|
1933
2171
|
|
2172
|
+
// src/utils/cache.ts
|
2173
|
+
function cache(fn) {
|
2174
|
+
let result = void 0;
|
2175
|
+
return () => {
|
2176
|
+
if (result === void 0) {
|
2177
|
+
result = fn();
|
2178
|
+
}
|
2179
|
+
return result;
|
2180
|
+
};
|
2181
|
+
}
|
2182
|
+
|
2183
|
+
// src/utils/can-use-regex-lookbehind.ts
|
2184
|
+
var canUseRegexLookbehind = cache(() => {
|
2185
|
+
try {
|
2186
|
+
return "ab".replace(new RegExp("(?<=a)b", "g"), "c") === "ac";
|
2187
|
+
} catch (error) {
|
2188
|
+
return false;
|
2189
|
+
}
|
2190
|
+
});
|
2191
|
+
|
1934
2192
|
// src/utils/clsx.ts
|
1935
2193
|
import clsxLite from "clsx/lite";
|
1936
2194
|
var clsx = clsxLite;
|
1937
2195
|
|
1938
|
-
// src/utils/default-block-at.ts
|
1939
|
-
function defaultBlockAt(match) {
|
1940
|
-
for (let i = 0; i < match.edgeCount; i++) {
|
1941
|
-
const { type } = match.edge(i);
|
1942
|
-
if (type.isTextblock && !type.hasRequiredAttrs())
|
1943
|
-
return type;
|
1944
|
-
}
|
1945
|
-
return null;
|
1946
|
-
}
|
1947
|
-
|
1948
2196
|
// src/utils/get-id.ts
|
1949
2197
|
var id = 0;
|
1950
2198
|
function getId() {
|
@@ -1960,6 +2208,11 @@ function isInCodeBlock(selection) {
|
|
1960
2208
|
return isCodeBlockType(selection.$from.parent.type) || isCodeBlockType(selection.$to.parent.type);
|
1961
2209
|
}
|
1962
2210
|
|
2211
|
+
// src/utils/maybe-run.ts
|
2212
|
+
function maybeRun(value, ...args) {
|
2213
|
+
return typeof value === "function" ? value(...args) : value;
|
2214
|
+
}
|
2215
|
+
|
1963
2216
|
// src/utils/unicode.ts
|
1964
2217
|
var OBJECT_REPLACEMENT_CHARACTER = "\uFFFC";
|
1965
2218
|
|
@@ -1975,12 +2228,13 @@ function withSkipCodeBlock(command) {
|
|
1975
2228
|
export {
|
1976
2229
|
Editor,
|
1977
2230
|
EditorNotFoundError,
|
1978
|
-
Facet,
|
1979
2231
|
OBJECT_REPLACEMENT_CHARACTER,
|
1980
2232
|
Priority,
|
1981
2233
|
ProseKitError,
|
1982
2234
|
getId as _getId,
|
1983
2235
|
addMark,
|
2236
|
+
assert,
|
2237
|
+
canUseRegexLookbehind,
|
1984
2238
|
clsx,
|
1985
2239
|
createEditor,
|
1986
2240
|
defaultBlockAt,
|
@@ -1996,6 +2250,8 @@ export {
|
|
1996
2250
|
defineDoubleClickHandler,
|
1997
2251
|
defineDoubleClickOnHandler,
|
1998
2252
|
defineDropHandler,
|
2253
|
+
defineFacet,
|
2254
|
+
defineFacetPayload,
|
1999
2255
|
defineFocusChangeHandler,
|
2000
2256
|
defineHistory,
|
2001
2257
|
defineKeyDownHandler,
|
@@ -2027,8 +2283,11 @@ export {
|
|
2027
2283
|
htmlFromNode,
|
2028
2284
|
insertNode,
|
2029
2285
|
isAllSelection,
|
2286
|
+
isApple,
|
2030
2287
|
isInCodeBlock,
|
2031
2288
|
isMark,
|
2289
|
+
isMarkAbsent,
|
2290
|
+
isMarkActive,
|
2032
2291
|
isNodeSelection,
|
2033
2292
|
isProseMirrorNode,
|
2034
2293
|
isTextSelection,
|
@@ -2036,6 +2295,7 @@ export {
|
|
2036
2295
|
jsonFromNode,
|
2037
2296
|
jsonFromState,
|
2038
2297
|
keymapFacet,
|
2298
|
+
maybeRun,
|
2039
2299
|
nodeFromElement,
|
2040
2300
|
nodeFromHTML,
|
2041
2301
|
nodeFromJSON,
|