@prosekit/core 0.6.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_tsup-dts-rollup.d.ts +290 -45
- package/dist/chunk-YWQGKV6X.js +863 -0
- package/dist/prosekit-core-test.d.ts +2 -0
- package/dist/prosekit-core-test.js +101 -0
- package/dist/prosekit-core.d.ts +7 -0
- package/dist/prosekit-core.js +79 -823
- package/package.json +12 -4
package/dist/prosekit-core.js
CHANGED
@@ -1,38 +1,45 @@
|
|
1
|
+
import {
|
2
|
+
Editor,
|
3
|
+
EditorNotFoundError,
|
4
|
+
Priority,
|
5
|
+
ProseKitError,
|
6
|
+
assert,
|
7
|
+
createEditor,
|
8
|
+
defineDefaultState,
|
9
|
+
defineFacet,
|
10
|
+
defineFacetPayload,
|
11
|
+
elementFromJSON,
|
12
|
+
elementFromNode,
|
13
|
+
getMarkType,
|
14
|
+
getNodeType,
|
15
|
+
htmlFromJSON,
|
16
|
+
htmlFromNode,
|
17
|
+
isAllSelection,
|
18
|
+
isMark,
|
19
|
+
isMarkAbsent,
|
20
|
+
isMarkActive,
|
21
|
+
isNodeActive,
|
22
|
+
isNodeSelection,
|
23
|
+
isNotNull,
|
24
|
+
isProseMirrorNode,
|
25
|
+
isTextSelection,
|
26
|
+
jsonFromHTML,
|
27
|
+
jsonFromNode,
|
28
|
+
jsonFromState,
|
29
|
+
nodeFromElement,
|
30
|
+
nodeFromHTML,
|
31
|
+
nodeFromJSON,
|
32
|
+
rootFacet,
|
33
|
+
schemaFacet,
|
34
|
+
stateFacet,
|
35
|
+
stateFromJSON,
|
36
|
+
toReversed,
|
37
|
+
union
|
38
|
+
} from "./chunk-YWQGKV6X.js";
|
39
|
+
|
1
40
|
// src/commands/add-mark.ts
|
2
41
|
import "@prosekit/pm/model";
|
3
42
|
import "@prosekit/pm/state";
|
4
|
-
|
5
|
-
// src/utils/get-mark-type.ts
|
6
|
-
import "@prosekit/pm/model";
|
7
|
-
|
8
|
-
// src/error.ts
|
9
|
-
var ProseKitError = class extends Error {
|
10
|
-
}, EditorNotFoundError = class extends ProseKitError {
|
11
|
-
constructor() {
|
12
|
-
super(
|
13
|
-
"Unable to find editor. Pass it as an argument or call this function inside a ProseKit component."
|
14
|
-
);
|
15
|
-
}
|
16
|
-
}, DOMDocumentNotFoundError = class extends ProseKitError {
|
17
|
-
constructor() {
|
18
|
-
super(
|
19
|
-
"Unable to find browser Document. When not in the browser environment, you need to pass a DOM Document."
|
20
|
-
);
|
21
|
-
}
|
22
|
-
};
|
23
|
-
|
24
|
-
// src/utils/get-mark-type.ts
|
25
|
-
function getMarkType(schema, type) {
|
26
|
-
if (typeof type == "string") {
|
27
|
-
let markType = schema.marks[type];
|
28
|
-
if (!markType)
|
29
|
-
throw new ProseKitError(`Cannot find mark type "${type}"`);
|
30
|
-
return markType;
|
31
|
-
}
|
32
|
-
return type;
|
33
|
-
}
|
34
|
-
|
35
|
-
// src/commands/add-mark.ts
|
36
43
|
function addMark(options) {
|
37
44
|
return (state, dispatch) => {
|
38
45
|
var _a, _b;
|
@@ -72,24 +79,6 @@ function expandMarkAfter($pos, predicate) {
|
|
72
79
|
import "@prosekit/pm/state";
|
73
80
|
import { insertPoint } from "@prosekit/pm/transform";
|
74
81
|
|
75
|
-
// src/utils/assert.ts
|
76
|
-
function assert(condition, message = "Assertion failed") {
|
77
|
-
if (!condition)
|
78
|
-
throw new ProseKitError(message);
|
79
|
-
}
|
80
|
-
|
81
|
-
// src/utils/get-node-type.ts
|
82
|
-
import "@prosekit/pm/model";
|
83
|
-
function getNodeType(schema, type) {
|
84
|
-
if (typeof type == "string") {
|
85
|
-
let nodeType = schema.nodes[type];
|
86
|
-
if (!nodeType)
|
87
|
-
throw new ProseKitError(`Cannot find ProseMirror node type "${type}"`);
|
88
|
-
return nodeType;
|
89
|
-
}
|
90
|
-
return type;
|
91
|
-
}
|
92
|
-
|
93
82
|
// src/utils/set-selection-around.ts
|
94
83
|
import { TextSelection as TextSelection2 } from "@prosekit/pm/state";
|
95
84
|
function setSelectionAround(tr, pos) {
|
@@ -292,28 +281,6 @@ function toggleMark({
|
|
292
281
|
import { setBlockType as setBlockType2 } from "@prosekit/pm/commands";
|
293
282
|
import "@prosekit/pm/model";
|
294
283
|
import "@prosekit/pm/state";
|
295
|
-
|
296
|
-
// src/utils/attrs-match.ts
|
297
|
-
function attrsMatch(nodeOrMark, attrs) {
|
298
|
-
let currentAttrs = nodeOrMark.attrs;
|
299
|
-
for (let [key, value] of Object.entries(attrs))
|
300
|
-
if (currentAttrs[key] !== value)
|
301
|
-
return !1;
|
302
|
-
return !0;
|
303
|
-
}
|
304
|
-
|
305
|
-
// src/utils/is-node-active.ts
|
306
|
-
function isNodeActive(state, type, attrs) {
|
307
|
-
let $pos = state.selection.$from, nodeType = getNodeType(state.schema, type);
|
308
|
-
for (let depth = $pos.depth; depth >= 0; depth--) {
|
309
|
-
let node = $pos.node(depth);
|
310
|
-
if (node.type === nodeType && (!attrs || attrsMatch(node, attrs)))
|
311
|
-
return !0;
|
312
|
-
}
|
313
|
-
return !1;
|
314
|
-
}
|
315
|
-
|
316
|
-
// src/commands/toggle-node.ts
|
317
284
|
function toggleNode({
|
318
285
|
type,
|
319
286
|
attrs
|
@@ -329,730 +296,6 @@ function toggleNode({
|
|
329
296
|
};
|
330
297
|
}
|
331
298
|
|
332
|
-
// src/editor/editor.ts
|
333
|
-
import "@prosekit/pm/model";
|
334
|
-
import { EditorState as EditorState2 } from "@prosekit/pm/state";
|
335
|
-
import { EditorView } from "@prosekit/pm/view";
|
336
|
-
|
337
|
-
// src/extensions/default-state.ts
|
338
|
-
import { Selection } from "@prosekit/pm/state";
|
339
|
-
|
340
|
-
// src/types/priority.ts
|
341
|
-
var Priority = /* @__PURE__ */ ((Priority2) => (Priority2[Priority2.lowest = 0] = "lowest", Priority2[Priority2.low = 1] = "low", Priority2[Priority2.default = 2] = "default", Priority2[Priority2.high = 3] = "high", Priority2[Priority2.highest = 4] = "highest", Priority2))(Priority || {});
|
342
|
-
|
343
|
-
// src/facets/base-extension.ts
|
344
|
-
import "@prosekit/pm/model";
|
345
|
-
|
346
|
-
// src/utils/array.ts
|
347
|
-
function uniqPush(prev, next) {
|
348
|
-
let result = [...prev];
|
349
|
-
for (let item of next)
|
350
|
-
result.includes(item) || result.push(item);
|
351
|
-
return result;
|
352
|
-
}
|
353
|
-
function arraySubstract(a, b) {
|
354
|
-
return a.filter((x) => !b.includes(x));
|
355
|
-
}
|
356
|
-
function toReversed(arr) {
|
357
|
-
var _a, _b;
|
358
|
-
return (_b = (_a = arr.toReversed) == null ? void 0 : _a.call(arr)) != null ? _b : [...arr].reverse();
|
359
|
-
}
|
360
|
-
|
361
|
-
// src/utils/is-not-null.ts
|
362
|
-
function isNotNull(value) {
|
363
|
-
return value != null;
|
364
|
-
}
|
365
|
-
|
366
|
-
// src/facets/facet-node.ts
|
367
|
-
function zip5(a, b, mapper) {
|
368
|
-
return [
|
369
|
-
mapper(a[0], b[0]),
|
370
|
-
mapper(a[1], b[1]),
|
371
|
-
mapper(a[2], b[2]),
|
372
|
-
mapper(a[3], b[3]),
|
373
|
-
mapper(a[4], b[4])
|
374
|
-
];
|
375
|
-
}
|
376
|
-
function unionInput(a, b) {
|
377
|
-
return !a && !b ? null : uniqPush(a != null ? a : [], b != null ? b : []);
|
378
|
-
}
|
379
|
-
function subtractInput(a, b) {
|
380
|
-
return a ? b ? arraySubstract(a, b) : [...a] : null;
|
381
|
-
}
|
382
|
-
function unionChildren(a, b) {
|
383
|
-
let merged = new Map(a);
|
384
|
-
for (let [key, valueB] of b.entries()) {
|
385
|
-
let valueA = a.get(key);
|
386
|
-
merged.set(key, valueA ? unionFacetNode(valueA, valueB) : valueB);
|
387
|
-
}
|
388
|
-
return merged;
|
389
|
-
}
|
390
|
-
function subtractChildren(a, b) {
|
391
|
-
let merged = new Map(a);
|
392
|
-
for (let [key, valueB] of b.entries()) {
|
393
|
-
let valueA = a.get(key);
|
394
|
-
valueA && merged.set(key, subtractFacetNode(valueA, valueB));
|
395
|
-
}
|
396
|
-
return merged;
|
397
|
-
}
|
398
|
-
function unionFacetNode(a, b) {
|
399
|
-
return assert(a.facet === b.facet), new FacetNode(
|
400
|
-
a.facet,
|
401
|
-
zip5(a.inputs, b.inputs, unionInput),
|
402
|
-
unionChildren(a.children, b.children),
|
403
|
-
a.reducers
|
404
|
-
);
|
405
|
-
}
|
406
|
-
function subtractFacetNode(a, b) {
|
407
|
-
return assert(a.facet === b.facet), new FacetNode(
|
408
|
-
a.facet,
|
409
|
-
zip5(a.inputs, b.inputs, subtractInput),
|
410
|
-
subtractChildren(a.children, b.children),
|
411
|
-
a.reducers
|
412
|
-
);
|
413
|
-
}
|
414
|
-
var FacetNode = class {
|
415
|
-
constructor(facet, inputs = [null, null, null, null, null], children = /* @__PURE__ */ new Map(), reducers = [
|
416
|
-
null,
|
417
|
-
null,
|
418
|
-
null,
|
419
|
-
null,
|
420
|
-
null
|
421
|
-
]) {
|
422
|
-
this.facet = facet;
|
423
|
-
this.inputs = inputs;
|
424
|
-
this.children = children;
|
425
|
-
this.reducers = reducers;
|
426
|
-
this.output = null;
|
427
|
-
}
|
428
|
-
calcOutput() {
|
429
|
-
var _a, _b, _c;
|
430
|
-
let inputs = [null, null, null, null, null], output = [null, null, null, null, null];
|
431
|
-
for (let pri = 0; pri < 5; pri++) {
|
432
|
-
let input = this.inputs[pri];
|
433
|
-
input && (inputs[pri] = [...input]);
|
434
|
-
}
|
435
|
-
for (let child of this.children.values()) {
|
436
|
-
let childOutput = child.getOutput();
|
437
|
-
for (let pri = 0; pri < 5; pri++)
|
438
|
-
childOutput[pri] && (inputs[pri] || (inputs[pri] = [])).push(childOutput[pri]);
|
439
|
-
}
|
440
|
-
if (this.facet.singleton) {
|
441
|
-
let reducer = (_a = this.reducers)[_b = 2 /* default */] || (_a[_b] = this.facet.reducer), input = inputs.filter(isNotNull).flat();
|
442
|
-
output[2 /* default */] = reducer(input);
|
443
|
-
} else
|
444
|
-
for (let pri = 0; pri < 5; pri++) {
|
445
|
-
let input = inputs[pri];
|
446
|
-
if (input) {
|
447
|
-
let reducer = (_c = this.reducers)[pri] || (_c[pri] = this.facet.reducer);
|
448
|
-
output[pri] = reducer(input);
|
449
|
-
}
|
450
|
-
}
|
451
|
-
return output;
|
452
|
-
}
|
453
|
-
getOutput() {
|
454
|
-
return this.output || (this.output = this.calcOutput()), this.output;
|
455
|
-
}
|
456
|
-
getSingletonOutput() {
|
457
|
-
return assert(this.facet.singleton), this.getOutput()[2 /* default */];
|
458
|
-
}
|
459
|
-
getRootOutput() {
|
460
|
-
assert(this.isRoot());
|
461
|
-
let output = this.getSingletonOutput();
|
462
|
-
return assert(output), output;
|
463
|
-
}
|
464
|
-
isRoot() {
|
465
|
-
return !this.facet.parent;
|
466
|
-
}
|
467
|
-
};
|
468
|
-
|
469
|
-
// src/facets/schema.ts
|
470
|
-
import { Schema as Schema4 } from "@prosekit/pm/model";
|
471
|
-
|
472
|
-
// src/facets/facet.ts
|
473
|
-
var facetCount = 0, Facet = class {
|
474
|
-
/**
|
475
|
-
* @internal
|
476
|
-
*/
|
477
|
-
constructor(parent, singleton, _reducer, _reduce) {
|
478
|
-
this._reducer = _reducer;
|
479
|
-
this._reduce = _reduce;
|
480
|
-
/**
|
481
|
-
* @internal
|
482
|
-
*/
|
483
|
-
this.index = facetCount++;
|
484
|
-
assert((_reduce || _reducer) && !(_reduce && _reducer)), this.parent = parent, this.singleton = singleton, this.path = parent ? [...parent.path, this.index] : [];
|
485
|
-
}
|
486
|
-
get reducer() {
|
487
|
-
var _a, _b;
|
488
|
-
return (_b = this._reducer) != null ? _b : (_a = this._reduce) == null ? void 0 : _a.call(this);
|
489
|
-
}
|
490
|
-
};
|
491
|
-
function defineFacet(options) {
|
492
|
-
var _a;
|
493
|
-
return new Facet(
|
494
|
-
options.parent,
|
495
|
-
(_a = options.singleton) != null ? _a : !1,
|
496
|
-
options.reducer,
|
497
|
-
options.reduce
|
498
|
-
);
|
499
|
-
}
|
500
|
-
|
501
|
-
// src/facets/root.ts
|
502
|
-
function rootReducer(inputs) {
|
503
|
-
var _a;
|
504
|
-
let schema, commands, stateFunc, view;
|
505
|
-
for (let input of inputs)
|
506
|
-
schema = input.schema || schema, commands = input.commands || commands, stateFunc = input.state || stateFunc, view = input.view || view;
|
507
|
-
let state = schema && ((_a = stateFunc == null ? void 0 : stateFunc({ schema })) != null ? _a : { schema });
|
508
|
-
return { schema, state, commands, view };
|
509
|
-
}
|
510
|
-
var rootFacet = new Facet(
|
511
|
-
null,
|
512
|
-
!0,
|
513
|
-
rootReducer
|
514
|
-
);
|
515
|
-
|
516
|
-
// src/facets/schema.ts
|
517
|
-
var schemaFacet = defineFacet({
|
518
|
-
reducer: (specs) => {
|
519
|
-
assert(specs.length <= 1);
|
520
|
-
let spec = specs[0];
|
521
|
-
return { schema: spec ? new Schema4(spec) : null };
|
522
|
-
},
|
523
|
-
parent: rootFacet,
|
524
|
-
singleton: !0
|
525
|
-
});
|
526
|
-
|
527
|
-
// src/facets/base-extension.ts
|
528
|
-
var BaseExtension = class {
|
529
|
-
constructor() {
|
530
|
-
this.extension = [];
|
531
|
-
this.trees = [null, null, null, null, null];
|
532
|
-
}
|
533
|
-
/**
|
534
|
-
* @internal
|
535
|
-
*/
|
536
|
-
getTree(priority) {
|
537
|
-
var _a, _b;
|
538
|
-
let pri = (_a = priority != null ? priority : this.priority) != null ? _a : 2 /* default */;
|
539
|
-
return (_b = this.trees)[pri] || (_b[pri] = this.createTree(pri));
|
540
|
-
}
|
541
|
-
/**
|
542
|
-
* @internal
|
543
|
-
*/
|
544
|
-
findFacetOutput(facet) {
|
545
|
-
var _a;
|
546
|
-
let node = this.getTree();
|
547
|
-
for (let index of facet.path)
|
548
|
-
node = node == null ? void 0 : node.children.get(index);
|
549
|
-
return (_a = node == null ? void 0 : node.getOutput()) != null ? _a : null;
|
550
|
-
}
|
551
|
-
get schema() {
|
552
|
-
var _a, _b;
|
553
|
-
let output = this.findFacetOutput(schemaFacet);
|
554
|
-
return (_b = (_a = output == null ? void 0 : output.find(Boolean)) == null ? void 0 : _a.schema) != null ? _b : null;
|
555
|
-
}
|
556
|
-
};
|
557
|
-
|
558
|
-
// src/facets/facet-extension.ts
|
559
|
-
var FacetExtensionImpl = class extends BaseExtension {
|
560
|
-
/**
|
561
|
-
* @internal
|
562
|
-
*/
|
563
|
-
constructor(facet, payloads) {
|
564
|
-
super();
|
565
|
-
this.facet = facet;
|
566
|
-
this.payloads = payloads;
|
567
|
-
}
|
568
|
-
/**
|
569
|
-
* @internal
|
570
|
-
*/
|
571
|
-
createTree(priority) {
|
572
|
-
var _a;
|
573
|
-
let pri = (_a = this.priority) != null ? _a : priority, inputs = [null, null, null, null, null];
|
574
|
-
inputs[pri] = [...this.payloads];
|
575
|
-
let node = new FacetNode(this.facet, inputs);
|
576
|
-
for (; node.facet.parent; ) {
|
577
|
-
let children = /* @__PURE__ */ new Map([[node.facet.index, node]]);
|
578
|
-
node = new FacetNode(node.facet.parent, void 0, children);
|
579
|
-
}
|
580
|
-
return node;
|
581
|
-
}
|
582
|
-
};
|
583
|
-
function defineFacetPayload(facet, payloads) {
|
584
|
-
return new FacetExtensionImpl(facet, payloads);
|
585
|
-
}
|
586
|
-
|
587
|
-
// src/facets/state.ts
|
588
|
-
var stateFacet = defineFacet({
|
589
|
-
reduce: () => {
|
590
|
-
let callbacks = [], state = (ctx) => {
|
591
|
-
var _a, _b, _c, _d, _e, _f;
|
592
|
-
let configs = callbacks.map((cb) => cb(ctx)), config = {
|
593
|
-
schema: ctx.schema,
|
594
|
-
storedMarks: [],
|
595
|
-
plugins: []
|
596
|
-
};
|
597
|
-
for (let c of configs)
|
598
|
-
config.schema = (_a = config.schema) != null ? _a : c.schema, config.doc = (_b = config.doc) != null ? _b : c.doc, config.selection = (_c = config.selection) != null ? _c : c.selection, config.storedMarks = [...config.storedMarks, ...(_d = c.storedMarks) != null ? _d : []], config.plugins = uniqPush((_e = config.plugins) != null ? _e : [], (_f = c.plugins) != null ? _f : []);
|
599
|
-
return assert(
|
600
|
-
config.doc || config.schema,
|
601
|
-
"Can't create state without a schema nor a document"
|
602
|
-
), config.doc && (config.schema = void 0), config;
|
603
|
-
};
|
604
|
-
return function(inputs) {
|
605
|
-
return callbacks = inputs, { state };
|
606
|
-
};
|
607
|
-
},
|
608
|
-
singleton: !0,
|
609
|
-
parent: rootFacet
|
610
|
-
});
|
611
|
-
|
612
|
-
// src/utils/parse.ts
|
613
|
-
import { DOMParser, DOMSerializer } from "@prosekit/pm/model";
|
614
|
-
import { EditorState } from "@prosekit/pm/state";
|
615
|
-
|
616
|
-
// src/utils/get-dom-api.ts
|
617
|
-
function findGlobalBrowserDocument() {
|
618
|
-
if (typeof document != "undefined")
|
619
|
-
return document;
|
620
|
-
if (typeof globalThis != "undefined" && globalThis.document)
|
621
|
-
return globalThis.document;
|
622
|
-
}
|
623
|
-
function findGlobalBrowserWindow() {
|
624
|
-
if (typeof window != "undefined")
|
625
|
-
return window;
|
626
|
-
if (typeof globalThis != "undefined" && globalThis.window)
|
627
|
-
return globalThis.window;
|
628
|
-
}
|
629
|
-
function findBrowserDocument(options) {
|
630
|
-
var _a, _b, _c;
|
631
|
-
return (_c = (_a = options == null ? void 0 : options.document) != null ? _a : findGlobalBrowserDocument()) != null ? _c : (_b = findGlobalBrowserWindow()) == null ? void 0 : _b.document;
|
632
|
-
}
|
633
|
-
function findBrowserWindow(options) {
|
634
|
-
var _a, _b, _c, _d;
|
635
|
-
return (_d = (_b = (_a = options == null ? void 0 : options.document) == null ? void 0 : _a.defaultView) != null ? _b : findGlobalBrowserWindow()) != null ? _d : (_c = findBrowserDocument(options)) == null ? void 0 : _c.defaultView;
|
636
|
-
}
|
637
|
-
function getBrowserDocument(options) {
|
638
|
-
let doc = findBrowserDocument(options);
|
639
|
-
if (doc) return doc;
|
640
|
-
throw new DOMDocumentNotFoundError();
|
641
|
-
}
|
642
|
-
function getBrowserWindow(options) {
|
643
|
-
let win = findBrowserWindow(options);
|
644
|
-
if (win) return win;
|
645
|
-
throw new DOMDocumentNotFoundError();
|
646
|
-
}
|
647
|
-
|
648
|
-
// src/utils/parse.ts
|
649
|
-
function jsonFromState(state) {
|
650
|
-
return state.toJSON();
|
651
|
-
}
|
652
|
-
function stateFromJSON(json, options) {
|
653
|
-
return EditorState.fromJSON({ schema: options.schema }, json);
|
654
|
-
}
|
655
|
-
function jsonFromNode(node) {
|
656
|
-
return node.toJSON();
|
657
|
-
}
|
658
|
-
function nodeFromJSON(json, options) {
|
659
|
-
return options.schema.nodeFromJSON(json);
|
660
|
-
}
|
661
|
-
function nodeFromElement(element, options) {
|
662
|
-
let Parser = options.DOMParser || DOMParser, schema = options.schema;
|
663
|
-
return Parser.fromSchema(schema).parse(element);
|
664
|
-
}
|
665
|
-
function elementFromNode(node, options) {
|
666
|
-
let Serializer = (options == null ? void 0 : options.DOMSerializer) || DOMSerializer, document2 = getBrowserDocument(options), schema = node.type.schema, serializer = Serializer.fromSchema(schema);
|
667
|
-
return schema.topNodeType !== node.type ? serializer.serializeNode(node, { document: document2 }) : serializer.serializeFragment(
|
668
|
-
node.content,
|
669
|
-
{ document: document2 },
|
670
|
-
document2.createElement("div")
|
671
|
-
);
|
672
|
-
}
|
673
|
-
function elementFromHTML(html, options) {
|
674
|
-
let win = getBrowserWindow(options);
|
675
|
-
return new win.DOMParser().parseFromString(`<body><div>${html}</div></body>`, "text/html").body.firstElementChild;
|
676
|
-
}
|
677
|
-
function htmlFromElement(element) {
|
678
|
-
return element.outerHTML;
|
679
|
-
}
|
680
|
-
function nodeFromHTML(html, options) {
|
681
|
-
return nodeFromElement(elementFromHTML(html, options), options);
|
682
|
-
}
|
683
|
-
function htmlFromNode(node, options) {
|
684
|
-
return elementFromNode(node, options).outerHTML;
|
685
|
-
}
|
686
|
-
function jsonFromElement(element, options) {
|
687
|
-
return jsonFromNode(nodeFromElement(element, options));
|
688
|
-
}
|
689
|
-
function elementFromJSON(json, options) {
|
690
|
-
return elementFromNode(nodeFromJSON(json, options), options);
|
691
|
-
}
|
692
|
-
function jsonFromHTML(html, options) {
|
693
|
-
return jsonFromElement(elementFromHTML(html, options), options);
|
694
|
-
}
|
695
|
-
function htmlFromJSON(json, options) {
|
696
|
-
return htmlFromElement(elementFromJSON(json, options));
|
697
|
-
}
|
698
|
-
|
699
|
-
// src/extensions/default-state.ts
|
700
|
-
function defineDefaultState({
|
701
|
-
defaultDoc,
|
702
|
-
defaultHTML,
|
703
|
-
defaultSelection
|
704
|
-
}) {
|
705
|
-
if (defaultHTML && defaultDoc)
|
706
|
-
throw new ProseKitError(
|
707
|
-
"Only one of defaultHTML and defaultDoc can be provided"
|
708
|
-
);
|
709
|
-
return defineFacetPayload(stateFacet, [
|
710
|
-
({ schema }) => {
|
711
|
-
let config = {};
|
712
|
-
return defaultHTML && (typeof defaultHTML == "string" ? defaultDoc = jsonFromHTML(defaultHTML, { schema }) : defaultDoc = jsonFromElement(defaultHTML, { schema })), defaultDoc && (config.doc = schema.nodeFromJSON(defaultDoc), defaultSelection && (config.selection = Selection.fromJSON(config.doc, defaultSelection))), config;
|
713
|
-
}
|
714
|
-
]);
|
715
|
-
}
|
716
|
-
|
717
|
-
// src/utils/deep-equals.ts
|
718
|
-
import OrderedMap from "orderedmap";
|
719
|
-
function deepEquals(a, b) {
|
720
|
-
if (a === b)
|
721
|
-
return !0;
|
722
|
-
if (!a || !b)
|
723
|
-
return !1;
|
724
|
-
if (Array.isArray(a) && Array.isArray(b))
|
725
|
-
return a.length === b.length && a.every((x, i) => deepEquals(x, b[i]));
|
726
|
-
if (a instanceof OrderedMap && b instanceof OrderedMap)
|
727
|
-
return a.size === b.size && deepEquals(a.toObject(), b.toObject());
|
728
|
-
if (typeof a == "object" && typeof b == "object") {
|
729
|
-
let aKeys = Object.keys(a), bKeys = Object.keys(b);
|
730
|
-
return aKeys.length === bKeys.length && aKeys.every((key) => deepEquals(a[key], b[key]));
|
731
|
-
}
|
732
|
-
return !1;
|
733
|
-
}
|
734
|
-
|
735
|
-
// src/editor/builder.ts
|
736
|
-
import "@prosekit/pm/model";
|
737
|
-
|
738
|
-
// src/utils/is-mark-absent.ts
|
739
|
-
function isMarkAbsent(node, from, to, markType, attrs) {
|
740
|
-
let mark = attrs ? markType.create(attrs) : markType, missing = !1;
|
741
|
-
return node.nodesBetween(from, to, (node2, pos, parent) => {
|
742
|
-
if (missing) return !1;
|
743
|
-
missing = !mark.isInSet(node2.marks) && !!parent && parent.type.allowsMarkType(markType);
|
744
|
-
}), missing;
|
745
|
-
}
|
746
|
-
|
747
|
-
// src/utils/is-mark-active.ts
|
748
|
-
function isMarkActive(state, type, attrs) {
|
749
|
-
let { from, $from, to, empty } = state.selection, markType = getMarkType(state.schema, type);
|
750
|
-
return empty ? !!(attrs ? markType.create(attrs) : markType).isInSet(state.storedMarks || $from.marks()) : !isMarkAbsent(state.doc, from, to, markType, attrs);
|
751
|
-
}
|
752
|
-
|
753
|
-
// src/utils/type-assertion.ts
|
754
|
-
import { Mark, ProseMirrorNode as ProseMirrorNode2 } from "@prosekit/pm/model";
|
755
|
-
import {
|
756
|
-
AllSelection,
|
757
|
-
NodeSelection,
|
758
|
-
TextSelection as TextSelection5
|
759
|
-
} from "@prosekit/pm/state";
|
760
|
-
function isProseMirrorNode(node) {
|
761
|
-
return node instanceof ProseMirrorNode2;
|
762
|
-
}
|
763
|
-
function isMark(mark) {
|
764
|
-
return mark instanceof Mark;
|
765
|
-
}
|
766
|
-
function isTextSelection(sel) {
|
767
|
-
return sel instanceof TextSelection5;
|
768
|
-
}
|
769
|
-
function isNodeSelection(sel) {
|
770
|
-
return sel instanceof NodeSelection;
|
771
|
-
}
|
772
|
-
function isAllSelection(sel) {
|
773
|
-
return sel instanceof AllSelection;
|
774
|
-
}
|
775
|
-
|
776
|
-
// src/editor/builder.ts
|
777
|
-
function createNodeBuilder(getState, type) {
|
778
|
-
let builder = (...args) => buildNode(type, args);
|
779
|
-
return builder.isActive = (attrs) => {
|
780
|
-
let state = getState();
|
781
|
-
return state ? isNodeActive(state, type, attrs) : !1;
|
782
|
-
}, builder;
|
783
|
-
}
|
784
|
-
function createMarkBuilder(getState, type) {
|
785
|
-
let builder = (...args) => buildMark(type, args);
|
786
|
-
return builder.isActive = (attrs) => {
|
787
|
-
let state = getState();
|
788
|
-
return state ? isMarkActive(state, type, attrs) : !1;
|
789
|
-
}, builder;
|
790
|
-
}
|
791
|
-
function buildMark(type, args) {
|
792
|
-
let [attrs, children] = normalizeArgs(args);
|
793
|
-
return flattenChildren(type.schema, children, type.create(attrs));
|
794
|
-
}
|
795
|
-
function buildNode(type, args) {
|
796
|
-
let [attrs, children] = normalizeArgs(args), node = type.createAndFill(attrs, flattenChildren(type.schema, children));
|
797
|
-
if (!node)
|
798
|
-
throw new ProseKitError(`Couldn't create node ${type.name}`);
|
799
|
-
return node;
|
800
|
-
}
|
801
|
-
function flattenChildren(schema, children, mark) {
|
802
|
-
let nodes = [];
|
803
|
-
for (let child of children)
|
804
|
-
if (typeof child == "string")
|
805
|
-
child && nodes.push(schema.text(child, mark ? [mark] : null));
|
806
|
-
else if (Array.isArray(child))
|
807
|
-
nodes.push(...flattenChildren(schema, child, mark));
|
808
|
-
else if (isProseMirrorNode(child))
|
809
|
-
nodes.push(mark ? child.mark(mark.addToSet(child.marks)) : child);
|
810
|
-
else
|
811
|
-
throw new ProseKitError(`Invalid node child: ${typeof child}`);
|
812
|
-
return nodes;
|
813
|
-
}
|
814
|
-
function normalizeArgs(args) {
|
815
|
-
let [attrs, ...children] = args;
|
816
|
-
return isNodeChild(attrs) ? (children.unshift(attrs), [null, children]) : typeof attrs == "object" ? [attrs, children] : [null, children];
|
817
|
-
}
|
818
|
-
function isNodeChild(value) {
|
819
|
-
return value ? typeof value == "string" || Array.isArray(value) || isProseMirrorNode(value) : !1;
|
820
|
-
}
|
821
|
-
|
822
|
-
// src/facets/union-extension.ts
|
823
|
-
var UnionExtensionImpl = class extends BaseExtension {
|
824
|
-
/**
|
825
|
-
* @internal
|
826
|
-
*/
|
827
|
-
constructor(extension = []) {
|
828
|
-
super();
|
829
|
-
this.extension = extension;
|
830
|
-
}
|
831
|
-
/**
|
832
|
-
* @internal
|
833
|
-
*/
|
834
|
-
createTree(priority) {
|
835
|
-
var _a;
|
836
|
-
let pri = (_a = this.priority) != null ? _a : priority, extensions = [...this.extension];
|
837
|
-
extensions.sort((a, b) => {
|
838
|
-
var _a2, _b;
|
839
|
-
return ((_a2 = a.priority) != null ? _a2 : pri) - ((_b = b.priority) != null ? _b : pri);
|
840
|
-
});
|
841
|
-
let children = extensions.map((ext) => ext.getTree(pri));
|
842
|
-
assert(children.length > 0);
|
843
|
-
let node = children[0];
|
844
|
-
for (let i = 1; i < children.length; i++)
|
845
|
-
node = unionFacetNode(node, children[i]);
|
846
|
-
return node;
|
847
|
-
}
|
848
|
-
};
|
849
|
-
|
850
|
-
// src/editor/union.ts
|
851
|
-
function union(extension) {
|
852
|
-
let array = Array.isArray(extension) ? extension : [extension];
|
853
|
-
return assert(array.length > 0, "At least one extension is required"), new UnionExtensionImpl(
|
854
|
-
array
|
855
|
-
);
|
856
|
-
}
|
857
|
-
|
858
|
-
// src/editor/editor.ts
|
859
|
-
function createEditor(options) {
|
860
|
-
let { defaultDoc, defaultHTML, defaultSelection } = options, extension = options.extension;
|
861
|
-
return (defaultDoc || defaultHTML) && (extension = union([
|
862
|
-
extension,
|
863
|
-
defineDefaultState({
|
864
|
-
defaultDoc,
|
865
|
-
defaultHTML,
|
866
|
-
defaultSelection
|
867
|
-
})
|
868
|
-
])), Editor.create(new EditorInstance(extension));
|
869
|
-
}
|
870
|
-
var EditorInstance = class {
|
871
|
-
constructor(extension) {
|
872
|
-
this.view = null;
|
873
|
-
this.commandAppliers = {};
|
874
|
-
this.mount = this.mount.bind(this), this.unmount = this.unmount.bind(this), this.tree = extension.getTree();
|
875
|
-
let payload = this.tree.getRootOutput(), schema = payload.schema, stateConfig = payload.state;
|
876
|
-
assert(schema && stateConfig, "Schema must be defined");
|
877
|
-
let state = EditorState2.create(stateConfig);
|
878
|
-
if (this.cachedState = state, payload.commands)
|
879
|
-
for (let [name, commandCreator] of Object.entries(payload.commands))
|
880
|
-
this.defineCommand(name, commandCreator);
|
881
|
-
this.directEditorProps = { state, ...payload.view }, this.schema = this.directEditorProps.state.schema;
|
882
|
-
let getState = () => this.getState();
|
883
|
-
this.nodeBuilders = Object.fromEntries(
|
884
|
-
Object.values(this.schema.nodes).map((type) => [
|
885
|
-
type.name,
|
886
|
-
createNodeBuilder(getState, type)
|
887
|
-
])
|
888
|
-
), this.markBuilders = Object.fromEntries(
|
889
|
-
Object.values(this.schema.marks).map((type) => [
|
890
|
-
type.name,
|
891
|
-
createMarkBuilder(getState, type)
|
892
|
-
])
|
893
|
-
);
|
894
|
-
}
|
895
|
-
getState() {
|
896
|
-
return this.view && (this.cachedState = this.view.state), this.cachedState;
|
897
|
-
}
|
898
|
-
updateExtension(extension, add) {
|
899
|
-
var _a, _b, _c, _d;
|
900
|
-
let view = this.view;
|
901
|
-
if (!view || view.isDestroyed)
|
902
|
-
return;
|
903
|
-
let tree = extension.getTree(), payload = tree.getRootOutput();
|
904
|
-
if (payload != null && payload.schema)
|
905
|
-
throw new ProseKitError("Schema cannot be changed");
|
906
|
-
if (payload != null && payload.view)
|
907
|
-
throw new ProseKitError("View cannot be changed");
|
908
|
-
let oldPayload = this.tree.getRootOutput(), oldPlugins = [...(_b = (_a = view.state) == null ? void 0 : _a.plugins) != null ? _b : []];
|
909
|
-
this.tree = add ? unionFacetNode(this.tree, tree) : subtractFacetNode(this.tree, tree);
|
910
|
-
let newPayload = this.tree.getRootOutput(), newPlugins = [...(_d = (_c = newPayload == null ? void 0 : newPayload.state) == null ? void 0 : _c.plugins) != null ? _d : []];
|
911
|
-
if (!deepEquals(oldPlugins, newPlugins)) {
|
912
|
-
let state = view.state.reconfigure({ plugins: newPlugins });
|
913
|
-
view.updateState(state);
|
914
|
-
}
|
915
|
-
if (newPayload != null && newPayload.commands && !deepEquals(oldPayload == null ? void 0 : oldPayload.commands, newPayload == null ? void 0 : newPayload.commands)) {
|
916
|
-
let commands = newPayload.commands, names = Object.keys(commands);
|
917
|
-
for (let name of names)
|
918
|
-
this.defineCommand(name, commands[name]);
|
919
|
-
}
|
920
|
-
}
|
921
|
-
mount(place) {
|
922
|
-
if (this.view)
|
923
|
-
throw new ProseKitError("Editor is already mounted");
|
924
|
-
if (!place)
|
925
|
-
throw new ProseKitError("Can't mount editor without a place");
|
926
|
-
this.view = new EditorView({ mount: place }, this.directEditorProps);
|
927
|
-
}
|
928
|
-
unmount() {
|
929
|
-
if (!this.view)
|
930
|
-
throw new ProseKitError("Editor is not mounted yet");
|
931
|
-
this.view.destroy(), this.view = null;
|
932
|
-
}
|
933
|
-
get mounted() {
|
934
|
-
return !!this.view && !this.view.isDestroyed;
|
935
|
-
}
|
936
|
-
get assertView() {
|
937
|
-
if (!this.view)
|
938
|
-
throw new ProseKitError("Editor is not mounted");
|
939
|
-
return this.view;
|
940
|
-
}
|
941
|
-
definePlugins(plugins) {
|
942
|
-
let view = this.assertView, state = view.state, newPlugins = [...plugins, ...state.plugins], newState = state.reconfigure({ plugins: newPlugins });
|
943
|
-
view.setProps({ state: newState });
|
944
|
-
}
|
945
|
-
removePlugins(plugins) {
|
946
|
-
let view = this.view;
|
947
|
-
if (!view) return;
|
948
|
-
let state = view.state, newPlugins = state.plugins.filter((p) => !plugins.includes(p)), newState = state.reconfigure({ plugins: newPlugins });
|
949
|
-
view.setProps({ state: newState });
|
950
|
-
}
|
951
|
-
defineCommand(name, commandCreator) {
|
952
|
-
let applier = (...args) => {
|
953
|
-
let view = this.view;
|
954
|
-
return assert(view, `Cannot call command "${name}" before the editor is mounted`), commandCreator(...args)(view.state, view.dispatch.bind(view), view);
|
955
|
-
};
|
956
|
-
applier.canApply = (...args) => {
|
957
|
-
let view = this.view;
|
958
|
-
return view ? commandCreator(...args)(view.state, void 0, view) : !1;
|
959
|
-
}, this.commandAppliers[name] = applier;
|
960
|
-
}
|
961
|
-
removeCommand(name) {
|
962
|
-
delete this.commandAppliers[name];
|
963
|
-
}
|
964
|
-
}, Editor = class _Editor {
|
965
|
-
constructor(instance) {
|
966
|
-
this.afterMounted = [];
|
967
|
-
this.instance = instance, this.mount = this.mount.bind(this), this.unmount = this.unmount.bind(this), this.use = this.use.bind(this);
|
968
|
-
}
|
969
|
-
/**
|
970
|
-
* @internal
|
971
|
-
*/
|
972
|
-
static create(instance) {
|
973
|
-
if (!(instance instanceof EditorInstance))
|
974
|
-
throw new TypeError("Invalid EditorInstance");
|
975
|
-
return new _Editor(instance);
|
976
|
-
}
|
977
|
-
/**
|
978
|
-
* Whether the editor is mounted.
|
979
|
-
*/
|
980
|
-
get mounted() {
|
981
|
-
return this.instance.mounted;
|
982
|
-
}
|
983
|
-
/**
|
984
|
-
* The editor view.
|
985
|
-
*/
|
986
|
-
get view() {
|
987
|
-
return this.instance.assertView;
|
988
|
-
}
|
989
|
-
/**
|
990
|
-
* The editor schema.
|
991
|
-
*/
|
992
|
-
get schema() {
|
993
|
-
return this.instance.schema;
|
994
|
-
}
|
995
|
-
get commands() {
|
996
|
-
return this.instance.commandAppliers;
|
997
|
-
}
|
998
|
-
/**
|
999
|
-
* Whether the editor is focused.
|
1000
|
-
*/
|
1001
|
-
get focused() {
|
1002
|
-
var _a, _b;
|
1003
|
-
return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b : !1;
|
1004
|
-
}
|
1005
|
-
/**
|
1006
|
-
* Mount the editor to the given HTML element.
|
1007
|
-
* Pass `null` or `undefined` to unmount the editor.
|
1008
|
-
*/
|
1009
|
-
mount(place) {
|
1010
|
-
if (!place)
|
1011
|
-
return this.unmount();
|
1012
|
-
this.instance.mount(place), this.afterMounted.forEach((callback) => callback());
|
1013
|
-
}
|
1014
|
-
/**
|
1015
|
-
* Unmount the editor. This is equivalent to `mount(null)`.
|
1016
|
-
*/
|
1017
|
-
unmount() {
|
1018
|
-
this.mounted && this.instance.unmount();
|
1019
|
-
}
|
1020
|
-
/**
|
1021
|
-
* Focus the editor.
|
1022
|
-
*/
|
1023
|
-
focus() {
|
1024
|
-
var _a;
|
1025
|
-
(_a = this.instance.view) == null || _a.focus();
|
1026
|
-
}
|
1027
|
-
/**
|
1028
|
-
* Blur the editor.
|
1029
|
-
*/
|
1030
|
-
blur() {
|
1031
|
-
var _a;
|
1032
|
-
(_a = this.instance.view) == null || _a.dom.blur();
|
1033
|
-
}
|
1034
|
-
use(extension) {
|
1035
|
-
if (!this.mounted) {
|
1036
|
-
let lazyRemove = null, lazyCreate = () => {
|
1037
|
-
lazyRemove = this.use(extension);
|
1038
|
-
};
|
1039
|
-
return this.afterMounted.push(lazyCreate), () => {
|
1040
|
-
lazyRemove == null || lazyRemove();
|
1041
|
-
};
|
1042
|
-
}
|
1043
|
-
return this.instance.updateExtension(extension, !0), () => this.instance.updateExtension(extension, !1);
|
1044
|
-
}
|
1045
|
-
get state() {
|
1046
|
-
return this.instance.getState();
|
1047
|
-
}
|
1048
|
-
get nodes() {
|
1049
|
-
return this.instance.nodeBuilders;
|
1050
|
-
}
|
1051
|
-
get marks() {
|
1052
|
-
return this.instance.markBuilders;
|
1053
|
-
}
|
1054
|
-
};
|
1055
|
-
|
1056
299
|
// src/editor/with-priority.ts
|
1057
300
|
function withPriority(extension, priority) {
|
1058
301
|
let result = union(extension);
|
@@ -1069,9 +312,9 @@ function insertText({
|
|
1069
312
|
}
|
1070
313
|
|
1071
314
|
// src/commands/select-all.ts
|
1072
|
-
import { AllSelection
|
315
|
+
import { AllSelection } from "@prosekit/pm/state";
|
1073
316
|
function selectAll() {
|
1074
|
-
return (state, dispatch) => (dispatch == null || dispatch(state.tr.setSelection(new
|
317
|
+
return (state, dispatch) => (dispatch == null || dispatch(state.tr.setSelection(new AllSelection(state.doc))), !0);
|
1075
318
|
}
|
1076
319
|
|
1077
320
|
// src/commands/wrap.ts
|
@@ -1116,15 +359,15 @@ function defineBaseCommands() {
|
|
1116
359
|
}
|
1117
360
|
|
1118
361
|
// src/extensions/node-spec.ts
|
1119
|
-
import
|
362
|
+
import OrderedMap2 from "orderedmap";
|
1120
363
|
|
1121
364
|
// src/facets/schema-spec.ts
|
1122
365
|
import "@prosekit/pm/model";
|
1123
|
-
import
|
366
|
+
import OrderedMap from "orderedmap";
|
1124
367
|
var schemaSpecFacet = defineFacet({
|
1125
368
|
reducer: (specs) => {
|
1126
369
|
var _a;
|
1127
|
-
let nodes =
|
370
|
+
let nodes = OrderedMap.from({}), marks = OrderedMap.from({}), topNode;
|
1128
371
|
for (let spec of specs)
|
1129
372
|
nodes = nodes.append(spec.nodes), marks = marks.append((_a = spec.marks) != null ? _a : {}), topNode = topNode != null ? topNode : spec.topNode;
|
1130
373
|
return { nodes, marks, topNode };
|
@@ -1148,7 +391,7 @@ function defineNodeAttr(options) {
|
|
1148
391
|
}
|
1149
392
|
var nodeSpecFacet = defineFacet({
|
1150
393
|
reducer: (payloads) => {
|
1151
|
-
let nodes =
|
394
|
+
let nodes = OrderedMap2.from({}), topNodeName, specPayloads = payloads.map((input) => input[0]).filter(isNotNull), attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
|
1152
395
|
for (let { name, topNode, ...spec } of specPayloads)
|
1153
396
|
assert(!nodes.get(name), `Node type ${name} can only be defined once`), topNode && (topNodeName = name), nodes = nodes.addToStart(name, spec);
|
1154
397
|
for (let {
|
@@ -1226,11 +469,11 @@ import { PluginKey, ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm
|
|
1226
469
|
|
1227
470
|
// src/extensions/plugin.ts
|
1228
471
|
import "@prosekit/pm/model";
|
1229
|
-
import { Plugin
|
472
|
+
import { Plugin } from "@prosekit/pm/state";
|
1230
473
|
function definePlugin(plugin) {
|
1231
|
-
if (plugin instanceof
|
474
|
+
if (plugin instanceof Plugin)
|
1232
475
|
return defineFacetPayload(pluginFacet, [() => [plugin]]);
|
1233
|
-
if (Array.isArray(plugin) && plugin.every((p) => p instanceof
|
476
|
+
if (Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin))
|
1234
477
|
return defineFacetPayload(pluginFacet, [() => plugin]);
|
1235
478
|
if (typeof plugin == "function")
|
1236
479
|
return defineFacetPayload(pluginFacet, [plugin]);
|
@@ -1240,9 +483,9 @@ var pluginFacet = defineFacet({
|
|
1240
483
|
reducer: (payloads) => ({ schema }) => {
|
1241
484
|
let plugins = [];
|
1242
485
|
for (let payload of payloads)
|
1243
|
-
if (payload instanceof
|
486
|
+
if (payload instanceof Plugin)
|
1244
487
|
plugins.push(payload);
|
1245
|
-
else if (Array.isArray(payload) && payload.every((p) => p instanceof
|
488
|
+
else if (Array.isArray(payload) && payload.every((p) => p instanceof Plugin))
|
1246
489
|
plugins.push(...payload);
|
1247
490
|
else if (typeof payload == "function")
|
1248
491
|
plugins.push(...[payload({ schema })].flat());
|
@@ -1341,7 +584,7 @@ function defineDOMEventHandler(event, handler) {
|
|
1341
584
|
}
|
1342
585
|
var domEventFacet = defineFacet({
|
1343
586
|
reduce: () => {
|
1344
|
-
let setHandlersMap = {}, combinedHandlerMap = {}, plugin
|
587
|
+
let setHandlersMap = {}, combinedHandlerMap = {}, plugin, update = (payloads) => {
|
1345
588
|
var _a;
|
1346
589
|
let hasNewEvent = !1;
|
1347
590
|
for (let [event] of payloads)
|
@@ -1464,7 +707,7 @@ import {
|
|
1464
707
|
newlineInCode
|
1465
708
|
} from "@prosekit/pm/commands";
|
1466
709
|
import { keydownHandler } from "@prosekit/pm/keymap";
|
1467
|
-
import { Plugin as
|
710
|
+
import { Plugin as Plugin2, PluginKey as PluginKey4 } from "@prosekit/pm/state";
|
1468
711
|
import { splitSplittableBlock } from "prosemirror-splittable";
|
1469
712
|
var customBaseKeymap = {
|
1470
713
|
...baseKeymap,
|
@@ -1485,7 +728,7 @@ function defineBaseKeymap(options) {
|
|
1485
728
|
}
|
1486
729
|
var keymapFacet = defineFacet({
|
1487
730
|
reduce: () => {
|
1488
|
-
let handler
|
731
|
+
let handler, handlerWrapper = (view, event) => handler ? handler(view, event) : !1, plugin = new Plugin2({
|
1489
732
|
key: keymapPluginKey,
|
1490
733
|
props: { handleKeyDown: handlerWrapper }
|
1491
734
|
});
|
@@ -1616,22 +859,17 @@ var nodeViewFacet = defineFacet({
|
|
1616
859
|
import { PluginKey as PluginKey6, ProseMirrorPlugin as ProseMirrorPlugin6 } from "@prosekit/pm/state";
|
1617
860
|
import "@prosekit/pm/view";
|
1618
861
|
function defineNodeViewFactory(options) {
|
1619
|
-
return defineFacetPayload(nodeViewFactoryFacet, [options]);
|
862
|
+
return defineFacetPayload(nodeViewFactoryFacet, [[options, null]]);
|
863
|
+
}
|
864
|
+
function defineNodeViewComponent(options) {
|
865
|
+
return defineFacetPayload(nodeViewFactoryFacet, [[null, options]]);
|
1620
866
|
}
|
1621
867
|
var nodeViewFactoryFacet = defineFacet({
|
1622
868
|
reducer: (inputs) => {
|
1623
|
-
let nodeViews = {},
|
1624
|
-
for (let
|
1625
|
-
let
|
1626
|
-
|
1627
|
-
name: input.name,
|
1628
|
-
args: input.args
|
1629
|
-
}));
|
1630
|
-
}
|
1631
|
-
for (let [group, factory] of Object.entries(factories)) {
|
1632
|
-
let groupOptions = options[group] || [];
|
1633
|
-
for (let { name, args } of groupOptions)
|
1634
|
-
nodeViews[name] = factory(args);
|
869
|
+
let nodeViews = {}, factories = inputs.map((x) => x[0]).filter(isNotNull), options = inputs.map((x) => x[1]).filter(isNotNull);
|
870
|
+
for (let { group, name, args } of options) {
|
871
|
+
let factory = factories.find((factory2) => factory2.group === group);
|
872
|
+
factory && (nodeViews[name] = factory.factory(args));
|
1635
873
|
}
|
1636
874
|
return () => [
|
1637
875
|
new ProseMirrorPlugin6({
|
@@ -1686,6 +924,22 @@ var canUseRegexLookbehind = cache(() => {
|
|
1686
924
|
import clsxLite from "clsx/lite";
|
1687
925
|
var clsx = clsxLite;
|
1688
926
|
|
927
|
+
// src/utils/collect-nodes.ts
|
928
|
+
import { ProseMirrorFragment, ProseMirrorNode as ProseMirrorNode2 } from "@prosekit/pm/model";
|
929
|
+
function collectNodes(content) {
|
930
|
+
if (Array.isArray(content))
|
931
|
+
return content.flatMap(collectNodes);
|
932
|
+
if (content instanceof ProseMirrorNode2)
|
933
|
+
return [content];
|
934
|
+
if (content instanceof ProseMirrorFragment) {
|
935
|
+
let nodes = [];
|
936
|
+
for (let i = 0; i < content.childCount; i++)
|
937
|
+
nodes.push(content.child(i));
|
938
|
+
return nodes;
|
939
|
+
}
|
940
|
+
throw new ProseKitError(`Invalid node content: ${typeof content}`);
|
941
|
+
}
|
942
|
+
|
1689
943
|
// src/utils/default-block-at.ts
|
1690
944
|
function defaultBlockAt(match) {
|
1691
945
|
for (let i = 0; i < match.edgeCount; i++) {
|
@@ -1732,6 +986,7 @@ export {
|
|
1732
986
|
assert,
|
1733
987
|
canUseRegexLookbehind,
|
1734
988
|
clsx,
|
989
|
+
collectNodes,
|
1735
990
|
createEditor,
|
1736
991
|
defaultBlockAt,
|
1737
992
|
defineBaseCommands,
|
@@ -1759,6 +1014,7 @@ export {
|
|
1759
1014
|
defineNodeAttr,
|
1760
1015
|
defineNodeSpec,
|
1761
1016
|
defineNodeView,
|
1017
|
+
defineNodeViewComponent,
|
1762
1018
|
defineNodeViewFactory,
|
1763
1019
|
defineParagraph,
|
1764
1020
|
definePasteHandler,
|