@prosekit/core 0.7.5 → 0.7.7
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 +266 -174
- package/dist/{chunk-M267LRMB.js → chunk-MDJ2B4IL.js} +238 -170
- package/dist/prosekit-core-test.js +13 -19
- package/dist/prosekit-core.d.ts +9 -0
- package/dist/prosekit-core.js +38 -45
- package/package.json +5 -4
@@ -440,8 +440,35 @@ function htmlFromJSON(json, options) {
|
|
440
440
|
return htmlFromElement(elementFromJSON(json, options));
|
441
441
|
}
|
442
442
|
|
443
|
+
// src/utils/type-assertion.ts
|
444
|
+
import { Mark, ProseMirrorNode } from "@prosekit/pm/model";
|
445
|
+
import {
|
446
|
+
AllSelection,
|
447
|
+
NodeSelection,
|
448
|
+
TextSelection,
|
449
|
+
Selection
|
450
|
+
} from "@prosekit/pm/state";
|
451
|
+
function isProseMirrorNode(node) {
|
452
|
+
return node instanceof ProseMirrorNode;
|
453
|
+
}
|
454
|
+
function isMark(mark) {
|
455
|
+
return mark instanceof Mark;
|
456
|
+
}
|
457
|
+
function isSelection(sel) {
|
458
|
+
return sel instanceof Selection;
|
459
|
+
}
|
460
|
+
function isTextSelection(sel) {
|
461
|
+
return sel instanceof TextSelection;
|
462
|
+
}
|
463
|
+
function isNodeSelection(sel) {
|
464
|
+
return sel instanceof NodeSelection;
|
465
|
+
}
|
466
|
+
function isAllSelection(sel) {
|
467
|
+
return sel instanceof AllSelection;
|
468
|
+
}
|
469
|
+
|
443
470
|
// src/extensions/default-state.ts
|
444
|
-
import { Selection } from "@prosekit/pm/state";
|
471
|
+
import { Selection as Selection3 } from "@prosekit/pm/state";
|
445
472
|
|
446
473
|
// src/facets/state.ts
|
447
474
|
var stateFacet = defineFacet({
|
@@ -480,31 +507,74 @@ var stateFacet = defineFacet({
|
|
480
507
|
parent: rootFacet
|
481
508
|
});
|
482
509
|
|
483
|
-
// src/
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
510
|
+
// src/utils/editor-content.ts
|
511
|
+
import { Selection as Selection2 } from "@prosekit/pm/state";
|
512
|
+
|
513
|
+
// src/utils/is-object.ts
|
514
|
+
function isObject(v) {
|
515
|
+
return typeof v === "object" && v != null;
|
516
|
+
}
|
517
|
+
|
518
|
+
// src/utils/is-element.ts
|
519
|
+
var ELEMENT_NODE = 1;
|
520
|
+
function isElement(el) {
|
521
|
+
return isObject(el) && el.nodeType === ELEMENT_NODE && typeof el.nodeName === "string";
|
522
|
+
}
|
523
|
+
|
524
|
+
// src/utils/editor-content.ts
|
525
|
+
function getEditorContentJSON(schema, content) {
|
526
|
+
if (typeof content === "string") {
|
527
|
+
return jsonFromHTML(content, { schema });
|
528
|
+
} else if (isElement(content)) {
|
529
|
+
return jsonFromElement(content, { schema });
|
530
|
+
} else {
|
531
|
+
return content;
|
532
|
+
}
|
533
|
+
}
|
534
|
+
function getEditorContentNode(schema, content) {
|
535
|
+
if (isProseMirrorNode(content)) {
|
536
|
+
return content;
|
537
|
+
}
|
538
|
+
return schema.nodeFromJSON(getEditorContentJSON(schema, content));
|
539
|
+
}
|
540
|
+
function getEditorContentDoc(schema, content) {
|
541
|
+
const doc = getEditorContentNode(schema, content);
|
542
|
+
assert(
|
543
|
+
doc.type.schema === schema,
|
544
|
+
"Document schema does not match editor schema"
|
545
|
+
);
|
546
|
+
assert(
|
547
|
+
doc.type === schema.topNodeType,
|
548
|
+
`Document type does not match editor top node type. Expected ${schema.topNodeType.name}, got ${doc.type.name}`
|
549
|
+
);
|
550
|
+
return doc;
|
551
|
+
}
|
552
|
+
function getEditorSelection(doc, selection) {
|
553
|
+
if (isSelection(selection)) {
|
554
|
+
assert(selection.$head.doc === doc, "Selection and doc do not match");
|
555
|
+
return selection;
|
556
|
+
}
|
557
|
+
if (selection === "start") {
|
558
|
+
return Selection2.atStart(doc);
|
493
559
|
}
|
560
|
+
if (selection === "end") {
|
561
|
+
return Selection2.atEnd(doc);
|
562
|
+
}
|
563
|
+
return Selection2.fromJSON(doc, selection);
|
564
|
+
}
|
565
|
+
|
566
|
+
// src/extensions/default-state.ts
|
567
|
+
function defineDefaultState(options) {
|
568
|
+
const { defaultSelection, defaultContent, defaultDoc, defaultHTML } = options;
|
569
|
+
const defaultDocContent = defaultContent || defaultDoc || defaultHTML;
|
494
570
|
return defineFacetPayload(stateFacet, [
|
495
571
|
({ schema }) => {
|
496
572
|
const config = {};
|
497
|
-
if (
|
498
|
-
|
499
|
-
|
500
|
-
} else {
|
501
|
-
defaultDoc = jsonFromElement(defaultHTML, { schema });
|
502
|
-
}
|
503
|
-
}
|
504
|
-
if (defaultDoc) {
|
505
|
-
config.doc = schema.nodeFromJSON(defaultDoc);
|
573
|
+
if (defaultDocContent) {
|
574
|
+
const json = getEditorContentJSON(schema, defaultDocContent);
|
575
|
+
config.doc = schema.nodeFromJSON(json);
|
506
576
|
if (defaultSelection) {
|
507
|
-
config.selection =
|
577
|
+
config.selection = Selection3.fromJSON(config.doc, defaultSelection);
|
508
578
|
}
|
509
579
|
}
|
510
580
|
return config;
|
@@ -556,29 +626,6 @@ function isMarkActive(state, type, attrs) {
|
|
556
626
|
}
|
557
627
|
}
|
558
628
|
|
559
|
-
// src/utils/type-assertion.ts
|
560
|
-
import { Mark, ProseMirrorNode } from "@prosekit/pm/model";
|
561
|
-
import {
|
562
|
-
AllSelection,
|
563
|
-
NodeSelection,
|
564
|
-
TextSelection
|
565
|
-
} from "@prosekit/pm/state";
|
566
|
-
function isProseMirrorNode(node) {
|
567
|
-
return node instanceof ProseMirrorNode;
|
568
|
-
}
|
569
|
-
function isMark(mark) {
|
570
|
-
return mark instanceof Mark;
|
571
|
-
}
|
572
|
-
function isTextSelection(sel) {
|
573
|
-
return sel instanceof TextSelection;
|
574
|
-
}
|
575
|
-
function isNodeSelection(sel) {
|
576
|
-
return sel instanceof NodeSelection;
|
577
|
-
}
|
578
|
-
function isAllSelection(sel) {
|
579
|
-
return sel instanceof AllSelection;
|
580
|
-
}
|
581
|
-
|
582
629
|
// src/facets/union-extension.ts
|
583
630
|
var UnionExtensionImpl = class extends BaseExtension {
|
584
631
|
/**
|
@@ -610,12 +657,10 @@ var UnionExtensionImpl = class extends BaseExtension {
|
|
610
657
|
};
|
611
658
|
|
612
659
|
// src/editor/union.ts
|
613
|
-
function union(
|
614
|
-
const
|
615
|
-
assert(
|
616
|
-
return new UnionExtensionImpl(
|
617
|
-
array
|
618
|
-
);
|
660
|
+
function union(...exts) {
|
661
|
+
const extensions = exts.flat();
|
662
|
+
assert(extensions.length > 0, "At least one extension is required");
|
663
|
+
return new UnionExtensionImpl(extensions);
|
619
664
|
}
|
620
665
|
|
621
666
|
// src/editor/editor.ts
|
@@ -648,6 +693,7 @@ function deepEquals(a, b) {
|
|
648
693
|
|
649
694
|
// src/editor/action.ts
|
650
695
|
import "@prosekit/pm/model";
|
696
|
+
import mapValues from "just-map-values";
|
651
697
|
|
652
698
|
// src/utils/attrs-match.ts
|
653
699
|
function attrsMatch(nodeOrMark, attrs) {
|
@@ -675,28 +721,32 @@ function isNodeActive(state, type, attrs) {
|
|
675
721
|
|
676
722
|
// src/editor/action.ts
|
677
723
|
function createNodeActions(schema, getState, createNode = defaultCreateNode) {
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
724
|
+
return mapValues(
|
725
|
+
schema.nodes,
|
726
|
+
(type) => createNodeAction(type, getState, createNode)
|
727
|
+
);
|
728
|
+
}
|
729
|
+
function createNodeAction(type, getState, createNode) {
|
730
|
+
const action = (...args) => buildNode(type, args, createNode);
|
731
|
+
action.isActive = (attrs) => {
|
732
|
+
const state = getState();
|
733
|
+
return state ? isNodeActive(state, type, attrs) : false;
|
734
|
+
};
|
735
|
+
return action;
|
688
736
|
}
|
689
737
|
function createMarkActions(schema, getState, applyMark = defaultApplyMark) {
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
738
|
+
return mapValues(
|
739
|
+
schema.marks,
|
740
|
+
(type) => createMarkAction(type, getState, applyMark)
|
741
|
+
);
|
742
|
+
}
|
743
|
+
function createMarkAction(type, getState, applyMark) {
|
744
|
+
const action = (...args) => buildMark(type, args, applyMark);
|
745
|
+
action.isActive = (attrs) => {
|
746
|
+
const state = getState();
|
747
|
+
return state ? isMarkActive(state, type, attrs) : false;
|
748
|
+
};
|
749
|
+
return action;
|
700
750
|
}
|
701
751
|
function buildMark(type, args, applyMark) {
|
702
752
|
const [attrs, children] = normalizeArgs(args);
|
@@ -704,7 +754,7 @@ function buildMark(type, args, applyMark) {
|
|
704
754
|
return applyMark(mark, flattenChildren(type.schema, children));
|
705
755
|
}
|
706
756
|
var defaultApplyMark = (mark, children) => {
|
707
|
-
return children.map((
|
757
|
+
return children.map((node) => node.mark(mark.addToSet(node.marks)));
|
708
758
|
};
|
709
759
|
function buildNode(type, args, createNode) {
|
710
760
|
const [attrs, children] = normalizeArgs(args);
|
@@ -752,27 +802,24 @@ function isNodeChild(value) {
|
|
752
802
|
|
753
803
|
// src/editor/editor.ts
|
754
804
|
function setupEditorExtension(options) {
|
755
|
-
|
756
|
-
if (defaultDoc || defaultHTML) {
|
805
|
+
if (options.defaultContent || options.defaultDoc || options.defaultHTML) {
|
757
806
|
return union([
|
758
807
|
options.extension,
|
759
|
-
defineDefaultState(
|
760
|
-
defaultDoc,
|
761
|
-
defaultHTML,
|
762
|
-
defaultSelection
|
763
|
-
})
|
808
|
+
defineDefaultState(options)
|
764
809
|
]);
|
765
810
|
}
|
766
811
|
return options.extension;
|
767
812
|
}
|
768
813
|
function createEditor(options) {
|
769
814
|
const extension = setupEditorExtension(options);
|
770
|
-
|
815
|
+
const instance = new EditorInstance(extension);
|
816
|
+
return new Editor(instance);
|
771
817
|
}
|
772
818
|
var EditorInstance = class {
|
773
819
|
constructor(extension) {
|
774
820
|
this.view = null;
|
775
821
|
this.commands = {};
|
822
|
+
this.afterMounted = [];
|
776
823
|
this.getState = () => {
|
777
824
|
var _a;
|
778
825
|
return ((_a = this.view) == null ? void 0 : _a.state) || this.directEditorProps.state;
|
@@ -800,6 +847,21 @@ var EditorInstance = class {
|
|
800
847
|
this.directEditorProps.state = state;
|
801
848
|
}
|
802
849
|
}
|
850
|
+
setContent(content, selection) {
|
851
|
+
const doc = getEditorContentDoc(this.schema, content);
|
852
|
+
doc.check();
|
853
|
+
const sel = getEditorSelection(doc, selection || "start");
|
854
|
+
const oldState = this.getState();
|
855
|
+
if (doc.eq(oldState.doc) && (!selection || sel.eq(oldState.selection))) {
|
856
|
+
return;
|
857
|
+
}
|
858
|
+
const newState = EditorState2.create({
|
859
|
+
doc,
|
860
|
+
selection: sel,
|
861
|
+
plugins: oldState.plugins
|
862
|
+
});
|
863
|
+
this.updateState(newState);
|
864
|
+
}
|
803
865
|
updateExtension(extension, add) {
|
804
866
|
var _a, _b, _c, _d;
|
805
867
|
const view = this.view;
|
@@ -831,19 +893,33 @@ var EditorInstance = class {
|
|
831
893
|
}
|
832
894
|
}
|
833
895
|
}
|
896
|
+
use(extension) {
|
897
|
+
if (!this.mounted) {
|
898
|
+
let canceled = false;
|
899
|
+
let lazyRemove = null;
|
900
|
+
const lazyCreate = () => {
|
901
|
+
if (!canceled) {
|
902
|
+
lazyRemove = this.use(extension);
|
903
|
+
}
|
904
|
+
};
|
905
|
+
this.afterMounted.push(lazyCreate);
|
906
|
+
return () => {
|
907
|
+
canceled = true;
|
908
|
+
lazyRemove == null ? void 0 : lazyRemove();
|
909
|
+
};
|
910
|
+
}
|
911
|
+
this.updateExtension(extension, true);
|
912
|
+
return () => this.updateExtension(extension, false);
|
913
|
+
}
|
834
914
|
mount(place) {
|
835
915
|
if (this.view) {
|
836
916
|
throw new ProseKitError("Editor is already mounted");
|
837
917
|
}
|
838
|
-
if (!place) {
|
839
|
-
throw new ProseKitError("Can't mount editor without a place");
|
840
|
-
}
|
841
918
|
this.view = new EditorView({ mount: place }, this.directEditorProps);
|
919
|
+
this.afterMounted.forEach((callback) => callback());
|
842
920
|
}
|
843
921
|
unmount() {
|
844
|
-
if (!this.view)
|
845
|
-
throw new ProseKitError("Editor is not mounted yet");
|
846
|
-
}
|
922
|
+
if (!this.view) return;
|
847
923
|
this.directEditorProps.state = this.view.state;
|
848
924
|
this.view.destroy();
|
849
925
|
this.view = null;
|
@@ -893,25 +969,81 @@ var EditorInstance = class {
|
|
893
969
|
delete this.commands[name];
|
894
970
|
}
|
895
971
|
};
|
896
|
-
var Editor = class
|
972
|
+
var Editor = class {
|
897
973
|
/**
|
898
974
|
* @internal
|
899
975
|
*/
|
900
976
|
constructor(instance) {
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
this.
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
977
|
+
/**
|
978
|
+
* Mount the editor to the given HTML element.
|
979
|
+
* Pass `null` or `undefined` to unmount the editor.
|
980
|
+
*/
|
981
|
+
this.mount = (place) => {
|
982
|
+
if (place) {
|
983
|
+
this.instance.mount(place);
|
984
|
+
} else {
|
985
|
+
this.instance.unmount();
|
986
|
+
}
|
987
|
+
};
|
988
|
+
/**
|
989
|
+
* Unmount the editor. This is equivalent to `mount(null)`.
|
990
|
+
*/
|
991
|
+
this.unmount = () => {
|
992
|
+
this.instance.unmount();
|
993
|
+
};
|
994
|
+
/**
|
995
|
+
* Focus the editor.
|
996
|
+
*/
|
997
|
+
this.focus = () => {
|
998
|
+
var _a;
|
999
|
+
(_a = this.instance.view) == null ? void 0 : _a.focus();
|
1000
|
+
};
|
1001
|
+
/**
|
1002
|
+
* Blur the editor.
|
1003
|
+
*/
|
1004
|
+
this.blur = () => {
|
1005
|
+
var _a;
|
1006
|
+
(_a = this.instance.view) == null ? void 0 : _a.dom.blur();
|
1007
|
+
};
|
1008
|
+
/**
|
1009
|
+
* Register an extension to the editor. Return a function to unregister the
|
1010
|
+
* extension.
|
1011
|
+
*/
|
1012
|
+
this.use = (extension) => {
|
1013
|
+
return this.instance.use(extension);
|
1014
|
+
};
|
1015
|
+
/**
|
1016
|
+
* Update the editor's state.
|
1017
|
+
*
|
1018
|
+
* @remarks
|
1019
|
+
*
|
1020
|
+
* This is an advanced method. Use it only if you have a specific reason to
|
1021
|
+
* directly manipulate the editor's state.
|
1022
|
+
*/
|
1023
|
+
this.updateState = (state) => {
|
1024
|
+
this.instance.updateState(state);
|
1025
|
+
};
|
1026
|
+
/**
|
1027
|
+
* Update the editor's document and selection.
|
1028
|
+
*
|
1029
|
+
* @param content - The new document to set. It can be one of the following:
|
1030
|
+
* - A ProseMirror node instance
|
1031
|
+
* - A ProseMirror node JSON object
|
1032
|
+
* - An HTML string
|
1033
|
+
* - An HTML element instance
|
1034
|
+
* @param selection - Optional. Specifies the new selection. It can be one of the following:
|
1035
|
+
* - A ProseMirror selection instance
|
1036
|
+
* - A ProseMirror selection JSON object
|
1037
|
+
* - The string "start" (to set selection at the beginning, default value)
|
1038
|
+
* - The string "end" (to set selection at the end)
|
1039
|
+
*/
|
1040
|
+
this.setContent = (content, selection) => {
|
1041
|
+
return this.instance.setContent(content, selection);
|
1042
|
+
};
|
911
1043
|
if (!(instance instanceof EditorInstance)) {
|
912
1044
|
throw new TypeError("Invalid EditorInstance");
|
913
1045
|
}
|
914
|
-
|
1046
|
+
this.instance = instance;
|
915
1047
|
}
|
916
1048
|
/**
|
917
1049
|
* Whether the editor is mounted.
|
@@ -931,68 +1063,6 @@ var Editor = class _Editor {
|
|
931
1063
|
get schema() {
|
932
1064
|
return this.instance.schema;
|
933
1065
|
}
|
934
|
-
/**
|
935
|
-
* Whether the editor is focused.
|
936
|
-
*/
|
937
|
-
get focused() {
|
938
|
-
var _a, _b;
|
939
|
-
return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b : false;
|
940
|
-
}
|
941
|
-
/**
|
942
|
-
* Mount the editor to the given HTML element.
|
943
|
-
* Pass `null` or `undefined` to unmount the editor.
|
944
|
-
*/
|
945
|
-
mount(place) {
|
946
|
-
if (!place) {
|
947
|
-
return this.unmount();
|
948
|
-
}
|
949
|
-
this.instance.mount(place);
|
950
|
-
this.afterMounted.forEach((callback) => callback());
|
951
|
-
}
|
952
|
-
/**
|
953
|
-
* Unmount the editor. This is equivalent to `mount(null)`.
|
954
|
-
*/
|
955
|
-
unmount() {
|
956
|
-
if (this.mounted) {
|
957
|
-
this.instance.unmount();
|
958
|
-
}
|
959
|
-
}
|
960
|
-
/**
|
961
|
-
* Focus the editor.
|
962
|
-
*/
|
963
|
-
focus() {
|
964
|
-
var _a;
|
965
|
-
(_a = this.instance.view) == null ? void 0 : _a.focus();
|
966
|
-
}
|
967
|
-
/**
|
968
|
-
* Blur the editor.
|
969
|
-
*/
|
970
|
-
blur() {
|
971
|
-
var _a;
|
972
|
-
(_a = this.instance.view) == null ? void 0 : _a.dom.blur();
|
973
|
-
}
|
974
|
-
/**
|
975
|
-
* Register an extension to the editor. Return a function to unregister the
|
976
|
-
* extension.
|
977
|
-
*/
|
978
|
-
use(extension) {
|
979
|
-
if (!this.mounted) {
|
980
|
-
let canceled = false;
|
981
|
-
let lazyRemove = null;
|
982
|
-
const lazyCreate = () => {
|
983
|
-
if (!canceled) {
|
984
|
-
lazyRemove = this.use(extension);
|
985
|
-
}
|
986
|
-
};
|
987
|
-
this.afterMounted.push(lazyCreate);
|
988
|
-
return () => {
|
989
|
-
canceled = true;
|
990
|
-
lazyRemove == null ? void 0 : lazyRemove();
|
991
|
-
};
|
992
|
-
}
|
993
|
-
this.instance.updateExtension(extension, true);
|
994
|
-
return () => this.instance.updateExtension(extension, false);
|
995
|
-
}
|
996
1066
|
/**
|
997
1067
|
* The editor's current state.
|
998
1068
|
*/
|
@@ -1000,15 +1070,11 @@ var Editor = class _Editor {
|
|
1000
1070
|
return this.instance.getState();
|
1001
1071
|
}
|
1002
1072
|
/**
|
1003
|
-
*
|
1004
|
-
*
|
1005
|
-
* @remarks
|
1006
|
-
*
|
1007
|
-
* This is an advanced method. Use it only if you have a specific reason to
|
1008
|
-
* directly manipulate the editor's state.
|
1073
|
+
* Whether the editor is focused.
|
1009
1074
|
*/
|
1010
|
-
|
1011
|
-
|
1075
|
+
get focused() {
|
1076
|
+
var _a, _b;
|
1077
|
+
return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b : false;
|
1012
1078
|
}
|
1013
1079
|
/**
|
1014
1080
|
* All {@link CommandAction}s defined by the editor.
|
@@ -1045,6 +1111,7 @@ export {
|
|
1045
1111
|
schemaFacet,
|
1046
1112
|
defineFacetPayload,
|
1047
1113
|
stateFacet,
|
1114
|
+
isElement,
|
1048
1115
|
jsonFromState,
|
1049
1116
|
stateFromJSON,
|
1050
1117
|
jsonFromNode,
|
@@ -1056,14 +1123,15 @@ export {
|
|
1056
1123
|
elementFromJSON,
|
1057
1124
|
jsonFromHTML,
|
1058
1125
|
htmlFromJSON,
|
1059
|
-
defineDefaultState,
|
1060
|
-
isMarkAbsent,
|
1061
|
-
isMarkActive,
|
1062
1126
|
isProseMirrorNode,
|
1063
1127
|
isMark,
|
1128
|
+
isSelection,
|
1064
1129
|
isTextSelection,
|
1065
1130
|
isNodeSelection,
|
1066
1131
|
isAllSelection,
|
1132
|
+
defineDefaultState,
|
1133
|
+
isMarkAbsent,
|
1134
|
+
isMarkActive,
|
1067
1135
|
createNodeActions,
|
1068
1136
|
createMarkActions,
|
1069
1137
|
union,
|
@@ -4,11 +4,12 @@ import {
|
|
4
4
|
assert,
|
5
5
|
createMarkActions,
|
6
6
|
createNodeActions,
|
7
|
+
isProseMirrorNode,
|
7
8
|
setupEditorExtension
|
8
|
-
} from "./chunk-
|
9
|
+
} from "./chunk-MDJ2B4IL.js";
|
9
10
|
|
10
11
|
// src/test/test-editor.ts
|
11
|
-
import {
|
12
|
+
import { NodeSelection, TextSelection } from "@prosekit/pm/state";
|
12
13
|
|
13
14
|
// src/test/test-builder.ts
|
14
15
|
var createNodeForTest = (type, attrs, children) => {
|
@@ -53,7 +54,7 @@ var createNodeForTest = (type, attrs, children) => {
|
|
53
54
|
};
|
54
55
|
var applyMarkForTest = (mark, children) => {
|
55
56
|
return children.map((node) => {
|
56
|
-
const newNode = node.mark(
|
57
|
+
const newNode = node.mark(mark.addToSet(node.marks));
|
57
58
|
newNode.tags = node.tags;
|
58
59
|
return newNode;
|
59
60
|
});
|
@@ -85,6 +86,12 @@ var TestEditorInstance = class extends EditorInstance {
|
|
85
86
|
this.nodes = createNodeActions(this.schema, this.getState, createNodeForTest);
|
86
87
|
this.marks = createMarkActions(this.schema, this.getState, applyMarkForTest);
|
87
88
|
}
|
89
|
+
setContent(content, selection) {
|
90
|
+
return super.setContent(
|
91
|
+
content,
|
92
|
+
isProseMirrorNode(content) && !selection ? getSelection(content) : selection
|
93
|
+
);
|
94
|
+
}
|
88
95
|
};
|
89
96
|
var TestEditor = class extends Editor {
|
90
97
|
constructor(instance) {
|
@@ -104,21 +111,7 @@ var TestEditor = class extends Editor {
|
|
104
111
|
* ```
|
105
112
|
*/
|
106
113
|
set(doc) {
|
107
|
-
|
108
|
-
doc.type.schema === this.schema,
|
109
|
-
"Document schema does not match editor schema"
|
110
|
-
);
|
111
|
-
assert(
|
112
|
-
doc.type === this.schema.topNodeType,
|
113
|
-
"Document type does not match editor top node type"
|
114
|
-
);
|
115
|
-
const selection = getSelection(doc);
|
116
|
-
const state = EditorState.create({
|
117
|
-
doc,
|
118
|
-
selection,
|
119
|
-
plugins: this.state.plugins
|
120
|
-
});
|
121
|
-
this.updateState(state);
|
114
|
+
return this.setContent(doc);
|
122
115
|
}
|
123
116
|
dispatchEvent(event) {
|
124
117
|
this.view.dispatchEvent(event);
|
@@ -126,7 +119,8 @@ var TestEditor = class extends Editor {
|
|
126
119
|
};
|
127
120
|
function createTestEditor(options) {
|
128
121
|
const extension = setupEditorExtension(options);
|
129
|
-
|
122
|
+
const instance = new TestEditorInstance(extension);
|
123
|
+
return new TestEditor(instance);
|
130
124
|
}
|
131
125
|
export {
|
132
126
|
createTestEditor
|
package/dist/prosekit-core.d.ts
CHANGED
@@ -36,9 +36,11 @@ export { EditorNotFoundError_alias_1 as EditorNotFoundError } from './_tsup-dts-
|
|
36
36
|
export { ProseKitError_alias_1 as ProseKitError } from './_tsup-dts-rollup';
|
37
37
|
export { defineBaseCommands } from './_tsup-dts-rollup';
|
38
38
|
export { defineCommands } from './_tsup-dts-rollup';
|
39
|
+
export { BaseCommandsExtension } from './_tsup-dts-rollup';
|
39
40
|
export { defineDefaultState } from './_tsup-dts-rollup';
|
40
41
|
export { DefaultStateOptions } from './_tsup-dts-rollup';
|
41
42
|
export { defineDoc } from './_tsup-dts-rollup';
|
43
|
+
export { DocExtension } from './_tsup-dts-rollup';
|
42
44
|
export { defineDocChangeHandler } from './_tsup-dts-rollup';
|
43
45
|
export { DocChangeHandler } from './_tsup-dts-rollup';
|
44
46
|
export { defineDOMEventHandler } from './_tsup-dts-rollup';
|
@@ -76,12 +78,14 @@ export { MountHandler } from './_tsup-dts-rollup';
|
|
76
78
|
export { UnmountHandler } from './_tsup-dts-rollup';
|
77
79
|
export { UpdateHandler } from './_tsup-dts-rollup';
|
78
80
|
export { defineHistory } from './_tsup-dts-rollup';
|
81
|
+
export { HistoryExtension } from './_tsup-dts-rollup';
|
79
82
|
export { HistoryOptions } from './_tsup-dts-rollup';
|
80
83
|
export { defineKeymap } from './_tsup-dts-rollup';
|
81
84
|
export { keymapFacet } from './_tsup-dts-rollup';
|
82
85
|
export { Keymap } from './_tsup-dts-rollup';
|
83
86
|
export { KeymapPayload } from './_tsup-dts-rollup';
|
84
87
|
export { defineBaseKeymap } from './_tsup-dts-rollup';
|
88
|
+
export { BaseKeymapExtension } from './_tsup-dts-rollup';
|
85
89
|
export { defineMarkAttr } from './_tsup-dts-rollup';
|
86
90
|
export { defineMarkSpec } from './_tsup-dts-rollup';
|
87
91
|
export { MarkAttrOptions } from './_tsup-dts-rollup';
|
@@ -97,10 +101,12 @@ export { defineNodeViewFactory } from './_tsup-dts-rollup';
|
|
97
101
|
export { NodeViewComponentOptions } from './_tsup-dts-rollup';
|
98
102
|
export { NodeViewFactoryOptions } from './_tsup-dts-rollup';
|
99
103
|
export { defineParagraph } from './_tsup-dts-rollup';
|
104
|
+
export { ParagraphExtension } from './_tsup-dts-rollup';
|
100
105
|
export { definePlugin } from './_tsup-dts-rollup';
|
101
106
|
export { pluginFacet } from './_tsup-dts-rollup';
|
102
107
|
export { PluginPayload } from './_tsup-dts-rollup';
|
103
108
|
export { defineText } from './_tsup-dts-rollup';
|
109
|
+
export { TextExtension } from './_tsup-dts-rollup';
|
104
110
|
export { defineFacet } from './_tsup-dts-rollup';
|
105
111
|
export { Facet } from './_tsup-dts-rollup';
|
106
112
|
export { defineFacetPayload } from './_tsup-dts-rollup';
|
@@ -116,6 +122,8 @@ export { ExtractMarkActions } from './_tsup-dts-rollup';
|
|
116
122
|
export { ExtractMarks } from './_tsup-dts-rollup';
|
117
123
|
export { ExtractNodeActions } from './_tsup-dts-rollup';
|
118
124
|
export { ExtractNodes } from './_tsup-dts-rollup';
|
125
|
+
export { PlainExtension } from './_tsup-dts-rollup';
|
126
|
+
export { Union } from './_tsup-dts-rollup';
|
119
127
|
export { UnionExtension } from './_tsup-dts-rollup';
|
120
128
|
export { CommandAction } from './_tsup-dts-rollup';
|
121
129
|
export { CommandTyping } from './_tsup-dts-rollup';
|
@@ -166,6 +174,7 @@ export { isAllSelection } from './_tsup-dts-rollup';
|
|
166
174
|
export { isMark } from './_tsup-dts-rollup';
|
167
175
|
export { isNodeSelection } from './_tsup-dts-rollup';
|
168
176
|
export { isProseMirrorNode } from './_tsup-dts-rollup';
|
177
|
+
export { isSelection } from './_tsup-dts-rollup';
|
169
178
|
export { isTextSelection } from './_tsup-dts-rollup';
|
170
179
|
export { withSkipCodeBlock } from './_tsup-dts-rollup';
|
171
180
|
export { OBJECT_REPLACEMENT_CHARACTER } from './_tsup-dts-rollup';
|