@prosekit/core 0.7.13 → 0.7.15
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 +141 -23
- package/dist/{chunk-LAFNHJDR.js → chunk-B3WEP4DD.js} +97 -82
- package/dist/prosekit-core-test.js +3 -3
- package/dist/prosekit-core.d.ts +12 -3
- package/dist/prosekit-core.js +281 -137
- package/package.json +7 -7
package/dist/prosekit-core.js
CHANGED
@@ -39,25 +39,26 @@ import {
|
|
39
39
|
stateFromJSON,
|
40
40
|
toReversed,
|
41
41
|
union
|
42
|
-
} from "./chunk-
|
42
|
+
} from "./chunk-B3WEP4DD.js";
|
43
43
|
|
44
44
|
// src/commands/add-mark.ts
|
45
45
|
function addMark(options) {
|
46
46
|
return (state, dispatch) => {
|
47
|
-
var _a, _b;
|
48
47
|
const mark = getMarkType(state.schema, options.type).create(options.attrs);
|
49
|
-
const from =
|
50
|
-
const to =
|
48
|
+
const from = options.from ?? state.selection.from;
|
49
|
+
const to = options.to ?? state.selection.to;
|
51
50
|
if (from > to) {
|
52
51
|
return false;
|
53
52
|
}
|
54
|
-
dispatch
|
53
|
+
dispatch?.(state.tr.addMark(from, to, mark));
|
55
54
|
return true;
|
56
55
|
};
|
57
56
|
}
|
58
57
|
|
59
58
|
// src/commands/expand-mark.ts
|
60
|
-
import {
|
59
|
+
import {
|
60
|
+
TextSelection
|
61
|
+
} from "@prosekit/pm/state";
|
61
62
|
function expandMark(options) {
|
62
63
|
return (state, dispatch) => {
|
63
64
|
const markType = getMarkType(state.schema, options.type);
|
@@ -110,7 +111,9 @@ function expandMarkAfter($pos, predicate) {
|
|
110
111
|
}
|
111
112
|
|
112
113
|
// src/commands/insert-default-block.ts
|
113
|
-
import {
|
114
|
+
import {
|
115
|
+
TextSelection as TextSelection2
|
116
|
+
} from "@prosekit/pm/state";
|
114
117
|
|
115
118
|
// src/utils/default-block-at.ts
|
116
119
|
function defaultBlockAt(match) {
|
@@ -124,7 +127,7 @@ function defaultBlockAt(match) {
|
|
124
127
|
// src/commands/insert-default-block.ts
|
125
128
|
function insertDefaultBlock(options) {
|
126
129
|
return (state, dispatch) => {
|
127
|
-
const $pos =
|
130
|
+
const $pos = options?.pos == null ? state.selection.$to : state.doc.resolve(options.pos);
|
128
131
|
const depth = $pos.parent.isTextblock ? $pos.depth - 1 : $pos.depth;
|
129
132
|
const parent = $pos.node(depth);
|
130
133
|
const index = $pos.indexAfter(depth);
|
@@ -148,7 +151,9 @@ function insertDefaultBlock(options) {
|
|
148
151
|
import { insertPoint } from "@prosekit/pm/transform";
|
149
152
|
|
150
153
|
// src/utils/set-selection-around.ts
|
151
|
-
import {
|
154
|
+
import {
|
155
|
+
TextSelection as TextSelection3
|
156
|
+
} from "@prosekit/pm/state";
|
152
157
|
function setSelectionAround(tr, pos) {
|
153
158
|
const docSize = tr.doc.content.size;
|
154
159
|
const $pos = tr.doc.resolve(pos > docSize ? docSize : pos < 0 ? 0 : pos);
|
@@ -159,12 +164,11 @@ function setSelectionAround(tr, pos) {
|
|
159
164
|
// src/commands/insert-node.ts
|
160
165
|
function insertNode(options) {
|
161
166
|
return (state, dispatch) => {
|
162
|
-
var _a;
|
163
167
|
const node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).createAndFill(options.attrs) : null;
|
164
168
|
assert(node, "You must provide either a node or a type");
|
165
169
|
const insertPos = insertPoint(
|
166
170
|
state.doc,
|
167
|
-
|
171
|
+
options.pos ?? state.selection.anchor,
|
168
172
|
node.type
|
169
173
|
);
|
170
174
|
if (insertPos == null) return false;
|
@@ -180,15 +184,14 @@ function insertNode(options) {
|
|
180
184
|
// src/commands/remove-mark.ts
|
181
185
|
function removeMark(options) {
|
182
186
|
return (state, dispatch) => {
|
183
|
-
var _a, _b;
|
184
187
|
const markType = getMarkType(state.schema, options.type);
|
185
188
|
const mark = options.attrs ? markType.create(options.attrs) : markType;
|
186
|
-
const from =
|
187
|
-
const to =
|
189
|
+
const from = options.from ?? state.selection.from;
|
190
|
+
const to = options.to ?? state.selection.to;
|
188
191
|
if (from > to) {
|
189
192
|
return false;
|
190
193
|
}
|
191
|
-
dispatch
|
194
|
+
dispatch?.(state.tr.removeMark(from, to, mark));
|
192
195
|
return true;
|
193
196
|
};
|
194
197
|
}
|
@@ -218,7 +221,7 @@ function removeNode(options) {
|
|
218
221
|
const found = findParentNodeOfType(options.type, $pos);
|
219
222
|
if (!found) return false;
|
220
223
|
const { pos, node } = found;
|
221
|
-
dispatch
|
224
|
+
dispatch?.(state.tr.delete(pos, pos + node.nodeSize));
|
222
225
|
return true;
|
223
226
|
};
|
224
227
|
}
|
@@ -228,10 +231,10 @@ import {
|
|
228
231
|
TextSelection as TextSelection4
|
229
232
|
} from "@prosekit/pm/state";
|
230
233
|
function getCustomSelection(state, from, to) {
|
231
|
-
const pos = from
|
234
|
+
const pos = from ?? to;
|
232
235
|
if (pos != null) {
|
233
|
-
const $from = state.doc.resolve(from
|
234
|
-
const $to = state.doc.resolve(to
|
236
|
+
const $from = state.doc.resolve(from ?? pos);
|
237
|
+
const $to = state.doc.resolve(to ?? pos);
|
235
238
|
return TextSelection4.between($from, $to);
|
236
239
|
}
|
237
240
|
return state.selection;
|
@@ -287,10 +290,9 @@ function getNodeTypes(schema, types) {
|
|
287
290
|
// src/commands/set-node-attrs.ts
|
288
291
|
function setNodeAttrs(options) {
|
289
292
|
return (state, dispatch) => {
|
290
|
-
var _a, _b;
|
291
293
|
const nodeTypes = getNodeTypes(state.schema, options.type);
|
292
|
-
const from =
|
293
|
-
const to =
|
294
|
+
const from = options.pos ?? state.selection.from;
|
295
|
+
const to = options.pos ?? state.selection.to;
|
294
296
|
const positions = [];
|
295
297
|
state.doc.nodesBetween(from, to, (node, pos) => {
|
296
298
|
if (nodeTypes.includes(node.type)) {
|
@@ -362,7 +364,7 @@ function wrap(options) {
|
|
362
364
|
const nodeType = getNodeType(state.schema, options.nodeType || options.type);
|
363
365
|
const wrapping = findWrapping(range, nodeType, options.attrs);
|
364
366
|
if (!wrapping) return false;
|
365
|
-
dispatch
|
367
|
+
dispatch?.(state.tr.wrap(range, wrapping));
|
366
368
|
return true;
|
367
369
|
};
|
368
370
|
}
|
@@ -379,17 +381,19 @@ function toggleWrap(options) {
|
|
379
381
|
}
|
380
382
|
|
381
383
|
// src/commands/unset-block-type.ts
|
382
|
-
import {
|
384
|
+
import {
|
385
|
+
Fragment,
|
386
|
+
Slice
|
387
|
+
} from "@prosekit/pm/model";
|
383
388
|
import { ReplaceAroundStep } from "@prosekit/pm/transform";
|
384
389
|
function unsetBlockType(options) {
|
385
390
|
return (state, dispatch) => {
|
386
|
-
|
387
|
-
const
|
388
|
-
const to = (_b = options == null ? void 0 : options.to) != null ? _b : state.selection.to;
|
391
|
+
const from = options?.from ?? state.selection.from;
|
392
|
+
const to = options?.to ?? state.selection.to;
|
389
393
|
if (from > to) return false;
|
390
394
|
const tr = state.tr;
|
391
395
|
if (unsetTextBlockType(tr, from, to)) {
|
392
|
-
dispatch
|
396
|
+
dispatch?.(tr);
|
393
397
|
return true;
|
394
398
|
}
|
395
399
|
return false;
|
@@ -423,11 +427,10 @@ function unsetTextBlockType(tr, from, to) {
|
|
423
427
|
// src/commands/unset-mark.ts
|
424
428
|
function unsetMark(options) {
|
425
429
|
return (state, dispatch) => {
|
426
|
-
|
427
|
-
const
|
428
|
-
const to = (_b = options == null ? void 0 : options.to) != null ? _b : state.selection.to;
|
430
|
+
const from = options?.from ?? state.selection.from;
|
431
|
+
const to = options?.to ?? state.selection.to;
|
429
432
|
if (from > to) return false;
|
430
|
-
dispatch
|
433
|
+
dispatch?.(state.tr.removeMark(from, to));
|
431
434
|
return true;
|
432
435
|
};
|
433
436
|
}
|
@@ -439,21 +442,124 @@ function withPriority(extension, priority) {
|
|
439
442
|
return result;
|
440
443
|
}
|
441
444
|
|
445
|
+
// src/extensions/clipboard-serializer.ts
|
446
|
+
import {
|
447
|
+
DOMSerializer
|
448
|
+
} from "@prosekit/pm/model";
|
449
|
+
import {
|
450
|
+
PluginKey,
|
451
|
+
ProseMirrorPlugin
|
452
|
+
} from "@prosekit/pm/state";
|
453
|
+
|
454
|
+
// src/extensions/plugin.ts
|
455
|
+
import {
|
456
|
+
Plugin
|
457
|
+
} from "@prosekit/pm/state";
|
458
|
+
function definePlugin(plugin) {
|
459
|
+
if (plugin instanceof Plugin || Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin)) {
|
460
|
+
return definePluginPayload(() => plugin);
|
461
|
+
}
|
462
|
+
if (typeof plugin === "function") {
|
463
|
+
return definePluginPayload(plugin);
|
464
|
+
}
|
465
|
+
throw new TypeError("Invalid plugin");
|
466
|
+
}
|
467
|
+
function definePluginPayload(payload) {
|
468
|
+
return defineFacetPayload(pluginFacet, [payload]);
|
469
|
+
}
|
470
|
+
var pluginFacet = defineFacet({
|
471
|
+
reducer: (payloads) => {
|
472
|
+
return ({ schema }) => {
|
473
|
+
const plugins = [];
|
474
|
+
for (const payload of payloads) {
|
475
|
+
if (payload instanceof Plugin) {
|
476
|
+
plugins.push(payload);
|
477
|
+
} else if (Array.isArray(payload) && payload.every((p) => p instanceof Plugin)) {
|
478
|
+
plugins.push(...payload);
|
479
|
+
} else if (typeof payload === "function") {
|
480
|
+
plugins.push(...[payload({ schema })].flat());
|
481
|
+
} else {
|
482
|
+
throw new ProseKitError("Invalid plugin");
|
483
|
+
}
|
484
|
+
}
|
485
|
+
plugins.reverse();
|
486
|
+
return { plugins };
|
487
|
+
};
|
488
|
+
},
|
489
|
+
parent: stateFacet
|
490
|
+
});
|
491
|
+
|
492
|
+
// src/extensions/clipboard-serializer.ts
|
493
|
+
function mergeWrappers(wrappers) {
|
494
|
+
return (fn) => wrappers.filter(isNotNullish).reduce((fn2, wrapper) => wrapper(fn2), fn);
|
495
|
+
}
|
496
|
+
function wrapFunction(fn, wrapper) {
|
497
|
+
return wrapper ? wrapper(fn) : fn;
|
498
|
+
}
|
499
|
+
var CustomDOMSerializer = class extends DOMSerializer {
|
500
|
+
constructor(nodes, marks, serializeFragmentWrapper, serializeNodeWrapper) {
|
501
|
+
super(nodes, marks);
|
502
|
+
this.serializeFragmentWrapper = serializeFragmentWrapper;
|
503
|
+
this.serializeNodeWrapper = serializeNodeWrapper;
|
504
|
+
}
|
505
|
+
serializeFragment(...args) {
|
506
|
+
const fn = (...args2) => super.serializeFragment(...args2);
|
507
|
+
return wrapFunction(fn, this.serializeFragmentWrapper)(...args);
|
508
|
+
}
|
509
|
+
serializeNode(...args) {
|
510
|
+
const fn = (...args2) => super.serializeNode(...args2);
|
511
|
+
return wrapFunction(fn, this.serializeNodeWrapper)(...args);
|
512
|
+
}
|
513
|
+
};
|
514
|
+
function createCustomDOMSerializer(schema, options) {
|
515
|
+
const nodesFromSchema = (...args) => DOMSerializer.nodesFromSchema(...args);
|
516
|
+
const marksFromSchema = (...args) => DOMSerializer.marksFromSchema(...args);
|
517
|
+
const nodes = wrapFunction(nodesFromSchema, options.nodesFromSchemaWrapper)(schema);
|
518
|
+
const marks = wrapFunction(marksFromSchema, options.marksFromSchemaWrapper)(schema);
|
519
|
+
return new CustomDOMSerializer(nodes, marks, options.serializeFragmentWrapper, options.serializeNodeWrapper);
|
520
|
+
}
|
521
|
+
var clipboardSerializerFacet = defineFacet({
|
522
|
+
reducer: (inputs) => {
|
523
|
+
const options = {
|
524
|
+
serializeFragmentWrapper: mergeWrappers(inputs.map((input) => input.serializeFragmentWrapper)),
|
525
|
+
serializeNodeWrapper: mergeWrappers(inputs.map((input) => input.serializeNodeWrapper)),
|
526
|
+
nodesFromSchemaWrapper: mergeWrappers(inputs.map((input) => input.nodesFromSchemaWrapper)),
|
527
|
+
marksFromSchemaWrapper: mergeWrappers(inputs.map((input) => input.marksFromSchemaWrapper))
|
528
|
+
};
|
529
|
+
return ({ schema }) => {
|
530
|
+
const clipboardSerializer = createCustomDOMSerializer(schema, options);
|
531
|
+
return [
|
532
|
+
new ProseMirrorPlugin({
|
533
|
+
key: new PluginKey("prosekit-clipboard-serializer"),
|
534
|
+
props: { clipboardSerializer }
|
535
|
+
})
|
536
|
+
];
|
537
|
+
};
|
538
|
+
},
|
539
|
+
singleton: true,
|
540
|
+
parent: pluginFacet
|
541
|
+
});
|
542
|
+
function defineClipboardSerializer(options) {
|
543
|
+
return defineFacetPayload(clipboardSerializerFacet, [options]);
|
544
|
+
}
|
545
|
+
|
442
546
|
// src/commands/insert-text.ts
|
443
547
|
function insertText({ text, from, to }) {
|
444
548
|
return (state, dispatch) => {
|
445
549
|
if (text) {
|
446
|
-
dispatch
|
550
|
+
dispatch?.(state.tr.insertText(text, from, to));
|
447
551
|
}
|
448
552
|
return true;
|
449
553
|
};
|
450
554
|
}
|
451
555
|
|
452
556
|
// src/commands/select-all.ts
|
453
|
-
import {
|
557
|
+
import {
|
558
|
+
AllSelection
|
559
|
+
} from "@prosekit/pm/state";
|
454
560
|
function selectAll() {
|
455
561
|
return (state, dispatch) => {
|
456
|
-
dispatch
|
562
|
+
dispatch?.(state.tr.setSelection(new AllSelection(state.doc)));
|
457
563
|
return true;
|
458
564
|
};
|
459
565
|
}
|
@@ -498,14 +604,13 @@ import OrderedMap2 from "orderedmap";
|
|
498
604
|
import OrderedMap from "orderedmap";
|
499
605
|
var schemaSpecFacet = defineFacet({
|
500
606
|
reducer: (specs) => {
|
501
|
-
var _a;
|
502
607
|
let nodes = OrderedMap.from({});
|
503
608
|
let marks = OrderedMap.from({});
|
504
609
|
let topNode = void 0;
|
505
610
|
for (const spec of specs) {
|
506
611
|
nodes = nodes.append(spec.nodes);
|
507
|
-
marks = marks.append(
|
508
|
-
topNode = topNode
|
612
|
+
marks = marks.append(spec.marks ?? {});
|
613
|
+
topNode = topNode ?? spec.topNode;
|
509
614
|
}
|
510
615
|
return { nodes, marks, topNode };
|
511
616
|
},
|
@@ -551,21 +656,20 @@ function mergeObjects(...objects) {
|
|
551
656
|
|
552
657
|
// src/utils/merge-specs.ts
|
553
658
|
function mergeSpecs(a, b) {
|
554
|
-
var _a, _b, _c, _d, _e, _f;
|
555
659
|
const attrs = {};
|
556
660
|
const attrNames = /* @__PURE__ */ new Set([
|
557
|
-
...Object.keys(
|
558
|
-
...Object.keys(
|
661
|
+
...Object.keys(a.attrs ?? {}),
|
662
|
+
...Object.keys(b.attrs ?? {})
|
559
663
|
]);
|
560
664
|
for (const name of attrNames) {
|
561
|
-
const attrSpecA =
|
562
|
-
const attrSpecB =
|
665
|
+
const attrSpecA = a.attrs?.[name];
|
666
|
+
const attrSpecB = b.attrs?.[name];
|
563
667
|
const attrSpecMerged = mergeObjects(attrSpecA, attrSpecB);
|
564
668
|
if (attrSpecMerged) {
|
565
669
|
attrs[name] = attrSpecMerged;
|
566
670
|
}
|
567
671
|
}
|
568
|
-
const parseDOM = [...
|
672
|
+
const parseDOM = [...a.parseDOM ?? [], ...b.parseDOM ?? []];
|
569
673
|
return mergeObjects(a, b, { attrs, parseDOM });
|
570
674
|
}
|
571
675
|
|
@@ -573,10 +677,7 @@ function mergeSpecs(a, b) {
|
|
573
677
|
function wrapOutputSpecAttrs(toDOM, options) {
|
574
678
|
return (node, ...args) => {
|
575
679
|
const dom = toDOM(node, ...args);
|
576
|
-
const pairs = options.map((option) =>
|
577
|
-
var _a;
|
578
|
-
return (_a = option.toDOM) == null ? void 0 : _a.call(option, node.attrs[option.attr]);
|
579
|
-
}).filter(isNotNullish);
|
680
|
+
const pairs = options.map((option) => option.toDOM?.(node.attrs[option.attr])).filter(isNotNullish);
|
580
681
|
return insertOutputSpecAttrs(dom, pairs);
|
581
682
|
};
|
582
683
|
}
|
@@ -586,10 +687,9 @@ function wrapTagParseRuleAttrs(rule, options) {
|
|
586
687
|
return {
|
587
688
|
...rule,
|
588
689
|
getAttrs: (dom) => {
|
589
|
-
|
590
|
-
const baseAttrs = (_b = (_a = existingGetAttrs == null ? void 0 : existingGetAttrs(dom)) != null ? _a : existingAttrs) != null ? _b : {};
|
690
|
+
const baseAttrs = existingGetAttrs?.(dom) ?? existingAttrs ?? {};
|
591
691
|
if (baseAttrs === false || !dom || !isElement(dom)) {
|
592
|
-
return baseAttrs
|
692
|
+
return baseAttrs ?? null;
|
593
693
|
}
|
594
694
|
const insertedAttrs = {};
|
595
695
|
for (const option of options) {
|
@@ -692,9 +792,7 @@ var nodeSpecFacet = defineFacet({
|
|
692
792
|
spec.toDOM = wrapOutputSpecAttrs(spec.toDOM, attrs);
|
693
793
|
}
|
694
794
|
if (spec.parseDOM) {
|
695
|
-
spec.parseDOM = spec.parseDOM.map(
|
696
|
-
(rule) => wrapTagParseRuleAttrs(rule, attrs)
|
697
|
-
);
|
795
|
+
spec.parseDOM = spec.parseDOM.map((rule) => wrapTagParseRuleAttrs(rule, attrs));
|
698
796
|
}
|
699
797
|
specs = specs.update(type, spec);
|
700
798
|
}
|
@@ -715,47 +813,9 @@ function defineDoc() {
|
|
715
813
|
|
716
814
|
// src/extensions/events/plugin-view.ts
|
717
815
|
import {
|
718
|
-
PluginKey,
|
719
|
-
ProseMirrorPlugin
|
816
|
+
PluginKey as PluginKey2,
|
817
|
+
ProseMirrorPlugin as ProseMirrorPlugin2
|
720
818
|
} from "@prosekit/pm/state";
|
721
|
-
|
722
|
-
// src/extensions/plugin.ts
|
723
|
-
import { Plugin } from "@prosekit/pm/state";
|
724
|
-
function definePlugin(plugin) {
|
725
|
-
if (plugin instanceof Plugin || Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin)) {
|
726
|
-
return definePluginPayload(() => plugin);
|
727
|
-
}
|
728
|
-
if (typeof plugin === "function") {
|
729
|
-
return definePluginPayload(plugin);
|
730
|
-
}
|
731
|
-
throw new TypeError("Invalid plugin");
|
732
|
-
}
|
733
|
-
function definePluginPayload(payload) {
|
734
|
-
return defineFacetPayload(pluginFacet, [payload]);
|
735
|
-
}
|
736
|
-
var pluginFacet = defineFacet({
|
737
|
-
reducer: (payloads) => {
|
738
|
-
return ({ schema }) => {
|
739
|
-
const plugins = [];
|
740
|
-
for (const payload of payloads) {
|
741
|
-
if (payload instanceof Plugin) {
|
742
|
-
plugins.push(payload);
|
743
|
-
} else if (Array.isArray(payload) && payload.every((p) => p instanceof Plugin)) {
|
744
|
-
plugins.push(...payload);
|
745
|
-
} else if (typeof payload === "function") {
|
746
|
-
plugins.push(...[payload({ schema })].flat());
|
747
|
-
} else {
|
748
|
-
throw new ProseKitError("Invalid plugin");
|
749
|
-
}
|
750
|
-
}
|
751
|
-
plugins.reverse();
|
752
|
-
return { plugins };
|
753
|
-
};
|
754
|
-
},
|
755
|
-
parent: stateFacet
|
756
|
-
});
|
757
|
-
|
758
|
-
// src/extensions/events/plugin-view.ts
|
759
819
|
function defineMountHandler(handler) {
|
760
820
|
return definePluginViewFacetPayload(["mount", handler]);
|
761
821
|
}
|
@@ -773,7 +833,7 @@ var pluginViewFacet = defineFacet({
|
|
773
833
|
let mountHandlers = [];
|
774
834
|
let updateHandlers = [];
|
775
835
|
let unmountHandlers = [];
|
776
|
-
const plugin = new
|
836
|
+
const plugin = new ProseMirrorPlugin2({
|
777
837
|
key: pluginKey,
|
778
838
|
view: (view) => {
|
779
839
|
mountHandlers.forEach((fn) => fn(view));
|
@@ -813,7 +873,7 @@ var pluginViewFacet = defineFacet({
|
|
813
873
|
parent: pluginFacet,
|
814
874
|
singleton: true
|
815
875
|
});
|
816
|
-
var pluginKey = new
|
876
|
+
var pluginKey = new PluginKey2("prosekit-plugin-view-handler");
|
817
877
|
|
818
878
|
// src/extensions/events/doc-change.ts
|
819
879
|
function defineDocChangeHandler(handler) {
|
@@ -825,7 +885,10 @@ function defineDocChangeHandler(handler) {
|
|
825
885
|
}
|
826
886
|
|
827
887
|
// src/extensions/events/dom-event.ts
|
828
|
-
import {
|
888
|
+
import {
|
889
|
+
PluginKey as PluginKey3,
|
890
|
+
ProseMirrorPlugin as ProseMirrorPlugin3
|
891
|
+
} from "@prosekit/pm/state";
|
829
892
|
|
830
893
|
// src/utils/combine-event-handlers.ts
|
831
894
|
function combineEventHandlers() {
|
@@ -864,7 +927,6 @@ var domEventFacet = defineFacet(
|
|
864
927
|
const combinedHandlerMap = {};
|
865
928
|
let plugin;
|
866
929
|
const update = (payloads) => {
|
867
|
-
var _a;
|
868
930
|
let hasNewEvent = false;
|
869
931
|
for (const [event] of payloads) {
|
870
932
|
if (!setHandlersMap[event]) {
|
@@ -879,19 +941,19 @@ var domEventFacet = defineFacet(
|
|
879
941
|
}
|
880
942
|
const map = groupEntries(payloads);
|
881
943
|
for (const [event, setHandlers] of Object.entries(setHandlersMap)) {
|
882
|
-
const handlers =
|
944
|
+
const handlers = map[event] ?? [];
|
883
945
|
setHandlers(handlers);
|
884
946
|
}
|
885
947
|
if (hasNewEvent) {
|
886
|
-
plugin = new
|
887
|
-
key: new
|
948
|
+
plugin = new ProseMirrorPlugin3({
|
949
|
+
key: new PluginKey3("prosekit-dom-event-handler"),
|
888
950
|
props: { handleDOMEvents: combinedHandlerMap }
|
889
951
|
});
|
890
952
|
}
|
891
953
|
};
|
892
954
|
return function reducer(inputs) {
|
893
955
|
update(inputs);
|
894
|
-
return plugin
|
956
|
+
return plugin ?? [];
|
895
957
|
};
|
896
958
|
},
|
897
959
|
parent: pluginFacet,
|
@@ -900,7 +962,10 @@ var domEventFacet = defineFacet(
|
|
900
962
|
);
|
901
963
|
|
902
964
|
// src/extensions/events/editor-event.ts
|
903
|
-
import {
|
965
|
+
import {
|
966
|
+
PluginKey as PluginKey4,
|
967
|
+
ProseMirrorPlugin as ProseMirrorPlugin4
|
968
|
+
} from "@prosekit/pm/state";
|
904
969
|
function defineEventFacetPayload(payload) {
|
905
970
|
return defineFacetPayload(editorEventFacet, [payload]);
|
906
971
|
}
|
@@ -965,23 +1030,22 @@ function setupEditorEventPlugin() {
|
|
965
1030
|
const [setDropHandlers, handleDrop] = combineEventHandlers();
|
966
1031
|
const [setScrollToSelectionHandlers, handleScrollToSelection] = combineEventHandlers();
|
967
1032
|
const update = (entries) => {
|
968
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
969
1033
|
const map = groupEntries(entries);
|
970
|
-
setKeyDownHandlers(
|
971
|
-
setKeyPressHandlers(
|
972
|
-
setTextInputHandlers(
|
973
|
-
setClickOnHandlers(
|
974
|
-
setClickHandlers(
|
975
|
-
setDoubleClickOnHandlers(
|
976
|
-
setDoubleClickHandlers(
|
977
|
-
setTripleClickOnHandlers(
|
978
|
-
setTripleClickHandlers(
|
979
|
-
setPasteHandlers(
|
980
|
-
setDropHandlers(
|
981
|
-
setScrollToSelectionHandlers(
|
1034
|
+
setKeyDownHandlers(map.keyDown ?? []);
|
1035
|
+
setKeyPressHandlers(map.keyPress ?? []);
|
1036
|
+
setTextInputHandlers(map.textInput ?? []);
|
1037
|
+
setClickOnHandlers(map.clickOn ?? []);
|
1038
|
+
setClickHandlers(map.click ?? []);
|
1039
|
+
setDoubleClickOnHandlers(map.doubleClickOn ?? []);
|
1040
|
+
setDoubleClickHandlers(map.doubleClick ?? []);
|
1041
|
+
setTripleClickOnHandlers(map.tripleClickOn ?? []);
|
1042
|
+
setTripleClickHandlers(map.tripleClick ?? []);
|
1043
|
+
setPasteHandlers(map.paste ?? []);
|
1044
|
+
setDropHandlers(map.drop ?? []);
|
1045
|
+
setScrollToSelectionHandlers(map.scrollToSelection ?? []);
|
982
1046
|
};
|
983
|
-
const plugin = new
|
984
|
-
key: new
|
1047
|
+
const plugin = new ProseMirrorPlugin4({
|
1048
|
+
key: new PluginKey4("prosekit-editor-event"),
|
985
1049
|
props: {
|
986
1050
|
handleKeyDown,
|
987
1051
|
handleKeyPress,
|
@@ -1011,7 +1075,11 @@ function defineFocusChangeHandler(handler) {
|
|
1011
1075
|
}
|
1012
1076
|
|
1013
1077
|
// src/extensions/history.ts
|
1014
|
-
import {
|
1078
|
+
import {
|
1079
|
+
history,
|
1080
|
+
redo,
|
1081
|
+
undo
|
1082
|
+
} from "@prosekit/pm/history";
|
1015
1083
|
|
1016
1084
|
// src/utils/env.ts
|
1017
1085
|
var isApple = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
|
@@ -1019,7 +1087,10 @@ var isApple = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navig
|
|
1019
1087
|
// src/extensions/keymap.ts
|
1020
1088
|
import { chainCommands } from "@prosekit/pm/commands";
|
1021
1089
|
import { keydownHandler } from "@prosekit/pm/keymap";
|
1022
|
-
import {
|
1090
|
+
import {
|
1091
|
+
Plugin as Plugin2,
|
1092
|
+
PluginKey as PluginKey5
|
1093
|
+
} from "@prosekit/pm/state";
|
1023
1094
|
import mapValues from "just-map-values";
|
1024
1095
|
function defineKeymap(keymap2) {
|
1025
1096
|
return defineFacetPayload(keymapFacet, [keymap2]);
|
@@ -1061,7 +1132,7 @@ function mergeKeymaps(keymaps) {
|
|
1061
1132
|
function mergeCommands(commands2) {
|
1062
1133
|
return chainCommands(...commands2);
|
1063
1134
|
}
|
1064
|
-
var keymapPluginKey = new
|
1135
|
+
var keymapPluginKey = new PluginKey5("prosekit-keymap");
|
1065
1136
|
|
1066
1137
|
// src/extensions/history.ts
|
1067
1138
|
var keymap = {
|
@@ -1115,8 +1186,7 @@ var customBaseKeymap = {
|
|
1115
1186
|
Backspace: customBackspace
|
1116
1187
|
};
|
1117
1188
|
function defineBaseKeymap(options) {
|
1118
|
-
|
1119
|
-
const priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */;
|
1189
|
+
const priority = options?.priority ?? 1 /* low */;
|
1120
1190
|
return withPriority(defineKeymap(customBaseKeymap), priority);
|
1121
1191
|
}
|
1122
1192
|
|
@@ -1163,9 +1233,7 @@ var markSpecFacet = defineFacet({
|
|
1163
1233
|
spec.toDOM = wrapOutputSpecAttrs(spec.toDOM, attrs);
|
1164
1234
|
}
|
1165
1235
|
if (spec.parseDOM) {
|
1166
|
-
spec.parseDOM = spec.parseDOM.map(
|
1167
|
-
(rule) => wrapParseRuleAttrs(rule, attrs)
|
1168
|
-
);
|
1236
|
+
spec.parseDOM = spec.parseDOM.map((rule) => wrapParseRuleAttrs(rule, attrs));
|
1169
1237
|
}
|
1170
1238
|
specs = specs.update(type, spec);
|
1171
1239
|
}
|
@@ -1181,8 +1249,72 @@ function wrapParseRuleAttrs(rule, attrs) {
|
|
1181
1249
|
return rule;
|
1182
1250
|
}
|
1183
1251
|
|
1252
|
+
// src/extensions/mark-view.ts
|
1253
|
+
import {
|
1254
|
+
PluginKey as PluginKey6,
|
1255
|
+
ProseMirrorPlugin as ProseMirrorPlugin5
|
1256
|
+
} from "@prosekit/pm/state";
|
1257
|
+
function defineMarkView(options) {
|
1258
|
+
return defineFacetPayload(markViewFacet, [options]);
|
1259
|
+
}
|
1260
|
+
var markViewFacet = defineFacet({
|
1261
|
+
reducer: (inputs) => {
|
1262
|
+
const markViews = {};
|
1263
|
+
for (const input of inputs) {
|
1264
|
+
if (!markViews[input.name]) {
|
1265
|
+
markViews[input.name] = input.constructor;
|
1266
|
+
}
|
1267
|
+
}
|
1268
|
+
return () => [
|
1269
|
+
new ProseMirrorPlugin5({
|
1270
|
+
key: new PluginKey6("prosekit-mark-view"),
|
1271
|
+
props: { markViews }
|
1272
|
+
})
|
1273
|
+
];
|
1274
|
+
},
|
1275
|
+
parent: pluginFacet
|
1276
|
+
});
|
1277
|
+
|
1278
|
+
// src/extensions/mark-view-effect.ts
|
1279
|
+
import {
|
1280
|
+
PluginKey as PluginKey7,
|
1281
|
+
ProseMirrorPlugin as ProseMirrorPlugin6
|
1282
|
+
} from "@prosekit/pm/state";
|
1283
|
+
function defineMarkViewFactory(options) {
|
1284
|
+
const input = [options, null];
|
1285
|
+
return defineFacetPayload(markViewFactoryFacet, [input]);
|
1286
|
+
}
|
1287
|
+
function defineMarkViewComponent(options) {
|
1288
|
+
const input = [null, options];
|
1289
|
+
return defineFacetPayload(markViewFactoryFacet, [input]);
|
1290
|
+
}
|
1291
|
+
var isServer = typeof window === "undefined";
|
1292
|
+
var markViewFactoryFacet = defineFacet({
|
1293
|
+
reducer: (inputs) => {
|
1294
|
+
if (isServer) return [];
|
1295
|
+
const markViews = {};
|
1296
|
+
const factories = inputs.map((x) => x[0]).filter(isNotNullish);
|
1297
|
+
const options = inputs.map((x) => x[1]).filter(isNotNullish);
|
1298
|
+
for (const { group, name, args } of options) {
|
1299
|
+
const factory = factories.find((factory2) => factory2.group === group);
|
1300
|
+
if (!factory) continue;
|
1301
|
+
markViews[name] = factory.factory(args);
|
1302
|
+
}
|
1303
|
+
return () => [
|
1304
|
+
new ProseMirrorPlugin6({
|
1305
|
+
key: new PluginKey7("prosekit-mark-view-effect"),
|
1306
|
+
props: { markViews }
|
1307
|
+
})
|
1308
|
+
];
|
1309
|
+
},
|
1310
|
+
parent: pluginFacet
|
1311
|
+
});
|
1312
|
+
|
1184
1313
|
// src/extensions/node-view.ts
|
1185
|
-
import {
|
1314
|
+
import {
|
1315
|
+
PluginKey as PluginKey8,
|
1316
|
+
ProseMirrorPlugin as ProseMirrorPlugin7
|
1317
|
+
} from "@prosekit/pm/state";
|
1186
1318
|
function defineNodeView(options) {
|
1187
1319
|
return defineFacetPayload(nodeViewFacet, [options]);
|
1188
1320
|
}
|
@@ -1195,8 +1327,8 @@ var nodeViewFacet = defineFacet({
|
|
1195
1327
|
}
|
1196
1328
|
}
|
1197
1329
|
return () => [
|
1198
|
-
new
|
1199
|
-
key: new
|
1330
|
+
new ProseMirrorPlugin7({
|
1331
|
+
key: new PluginKey8("prosekit-node-view"),
|
1200
1332
|
props: { nodeViews }
|
1201
1333
|
})
|
1202
1334
|
];
|
@@ -1205,7 +1337,10 @@ var nodeViewFacet = defineFacet({
|
|
1205
1337
|
});
|
1206
1338
|
|
1207
1339
|
// src/extensions/node-view-effect.ts
|
1208
|
-
import {
|
1340
|
+
import {
|
1341
|
+
PluginKey as PluginKey9,
|
1342
|
+
ProseMirrorPlugin as ProseMirrorPlugin8
|
1343
|
+
} from "@prosekit/pm/state";
|
1209
1344
|
function defineNodeViewFactory(options) {
|
1210
1345
|
const input = [options, null];
|
1211
1346
|
return defineFacetPayload(nodeViewFactoryFacet, [input]);
|
@@ -1214,10 +1349,10 @@ function defineNodeViewComponent(options) {
|
|
1214
1349
|
const input = [null, options];
|
1215
1350
|
return defineFacetPayload(nodeViewFactoryFacet, [input]);
|
1216
1351
|
}
|
1217
|
-
var
|
1352
|
+
var isServer2 = typeof window === "undefined";
|
1218
1353
|
var nodeViewFactoryFacet = defineFacet({
|
1219
1354
|
reducer: (inputs) => {
|
1220
|
-
if (
|
1355
|
+
if (isServer2) return [];
|
1221
1356
|
const nodeViews = {};
|
1222
1357
|
const factories = inputs.map((x) => x[0]).filter(isNotNullish);
|
1223
1358
|
const options = inputs.map((x) => x[1]).filter(isNotNullish);
|
@@ -1227,8 +1362,8 @@ var nodeViewFactoryFacet = defineFacet({
|
|
1227
1362
|
nodeViews[name] = factory.factory(args);
|
1228
1363
|
}
|
1229
1364
|
return () => [
|
1230
|
-
new
|
1231
|
-
key: new
|
1365
|
+
new ProseMirrorPlugin8({
|
1366
|
+
key: new PluginKey9("prosekit-node-view-effect"),
|
1232
1367
|
props: { nodeViews }
|
1233
1368
|
})
|
1234
1369
|
];
|
@@ -1275,7 +1410,7 @@ function cache(fn) {
|
|
1275
1410
|
var canUseRegexLookbehind = cache(() => {
|
1276
1411
|
try {
|
1277
1412
|
return "ab".replace(new RegExp("(?<=a)b", "g"), "c") === "ac";
|
1278
|
-
} catch
|
1413
|
+
} catch {
|
1279
1414
|
return false;
|
1280
1415
|
}
|
1281
1416
|
});
|
@@ -1294,7 +1429,10 @@ function collectChildren(parent) {
|
|
1294
1429
|
}
|
1295
1430
|
|
1296
1431
|
// src/utils/collect-nodes.ts
|
1297
|
-
import {
|
1432
|
+
import {
|
1433
|
+
ProseMirrorFragment,
|
1434
|
+
ProseMirrorNode
|
1435
|
+
} from "@prosekit/pm/model";
|
1298
1436
|
function collectNodes(content) {
|
1299
1437
|
if (Array.isArray(content)) {
|
1300
1438
|
return content.flatMap(collectNodes);
|
@@ -1332,8 +1470,9 @@ function getId() {
|
|
1332
1470
|
// src/utils/is-at-block-start.ts
|
1333
1471
|
function isAtBlockStart(state, view) {
|
1334
1472
|
const { $cursor } = state.selection;
|
1335
|
-
if (!$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0))
|
1473
|
+
if (!$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0)) {
|
1336
1474
|
return null;
|
1475
|
+
}
|
1337
1476
|
return $cursor;
|
1338
1477
|
}
|
1339
1478
|
|
@@ -1382,6 +1521,7 @@ export {
|
|
1382
1521
|
defineBaseKeymap,
|
1383
1522
|
defineClickHandler,
|
1384
1523
|
defineClickOnHandler,
|
1524
|
+
defineClipboardSerializer,
|
1385
1525
|
defineCommands,
|
1386
1526
|
defineDOMEventHandler,
|
1387
1527
|
defineDefaultState,
|
@@ -1399,6 +1539,9 @@ export {
|
|
1399
1539
|
defineKeymap,
|
1400
1540
|
defineMarkAttr,
|
1401
1541
|
defineMarkSpec,
|
1542
|
+
defineMarkView,
|
1543
|
+
defineMarkViewComponent,
|
1544
|
+
defineMarkViewFactory,
|
1402
1545
|
defineMountHandler,
|
1403
1546
|
defineNodeAttr,
|
1404
1547
|
defineNodeSpec,
|
@@ -1430,6 +1573,7 @@ export {
|
|
1430
1573
|
isAllSelection,
|
1431
1574
|
isApple,
|
1432
1575
|
isAtBlockStart,
|
1576
|
+
isElement,
|
1433
1577
|
isFragment,
|
1434
1578
|
isInCodeBlock,
|
1435
1579
|
isMark,
|