@prosekit/core 0.7.6 → 0.7.8
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 +325 -95
- package/dist/{chunk-MOSGJZHV.js → chunk-UKHJHMFE.js} +250 -170
- package/dist/prosekit-core-test.js +13 -19
- package/dist/prosekit-core.d.ts +7 -0
- package/dist/prosekit-core.js +249 -257
- package/package.json +5 -3
@@ -59,6 +59,42 @@ var Priority = /* @__PURE__ */ ((Priority2) => {
|
|
59
59
|
return Priority2;
|
60
60
|
})(Priority || {});
|
61
61
|
|
62
|
+
// src/utils/type-assertion.ts
|
63
|
+
import { Fragment, Mark, ProseMirrorNode, Slice } from "@prosekit/pm/model";
|
64
|
+
import {
|
65
|
+
AllSelection,
|
66
|
+
NodeSelection,
|
67
|
+
Selection,
|
68
|
+
TextSelection
|
69
|
+
} from "@prosekit/pm/state";
|
70
|
+
function isProseMirrorNode(node) {
|
71
|
+
return node instanceof ProseMirrorNode;
|
72
|
+
}
|
73
|
+
function isMark(mark) {
|
74
|
+
return mark instanceof Mark;
|
75
|
+
}
|
76
|
+
function isFragment(fragment) {
|
77
|
+
return fragment instanceof Fragment;
|
78
|
+
}
|
79
|
+
function isSlice(slice) {
|
80
|
+
return slice instanceof Slice;
|
81
|
+
}
|
82
|
+
function isSelection(sel) {
|
83
|
+
return sel instanceof Selection;
|
84
|
+
}
|
85
|
+
function isTextSelection(sel) {
|
86
|
+
return sel instanceof TextSelection;
|
87
|
+
}
|
88
|
+
function isNodeSelection(sel) {
|
89
|
+
return sel instanceof NodeSelection;
|
90
|
+
}
|
91
|
+
function isAllSelection(sel) {
|
92
|
+
return sel instanceof AllSelection;
|
93
|
+
}
|
94
|
+
function isNotNullish(value) {
|
95
|
+
return value != null;
|
96
|
+
}
|
97
|
+
|
62
98
|
// src/facets/facet.ts
|
63
99
|
var facetCount = 0;
|
64
100
|
var Facet = class {
|
@@ -113,11 +149,6 @@ function toReversed(arr) {
|
|
113
149
|
return (_b = (_a = arr.toReversed) == null ? void 0 : _a.call(arr)) != null ? _b : [...arr].reverse();
|
114
150
|
}
|
115
151
|
|
116
|
-
// src/utils/is-not-null.ts
|
117
|
-
function isNotNull(value) {
|
118
|
-
return value != null;
|
119
|
-
}
|
120
|
-
|
121
152
|
// src/facets/facet-node.ts
|
122
153
|
function zip5(a, b, mapper) {
|
123
154
|
return [
|
@@ -208,7 +239,7 @@ var FacetNode = class {
|
|
208
239
|
}
|
209
240
|
if (this.facet.singleton) {
|
210
241
|
const reducer = (_a = this.reducers)[_b = 2 /* default */] || (_a[_b] = this.facet.reducer);
|
211
|
-
const input = inputs.filter(
|
242
|
+
const input = inputs.filter(isNotNullish).flat();
|
212
243
|
output[2 /* default */] = reducer(input);
|
213
244
|
} else {
|
214
245
|
for (let pri = 0; pri < 5; pri++) {
|
@@ -441,7 +472,7 @@ function htmlFromJSON(json, options) {
|
|
441
472
|
}
|
442
473
|
|
443
474
|
// src/extensions/default-state.ts
|
444
|
-
import { Selection } from "@prosekit/pm/state";
|
475
|
+
import { Selection as Selection3 } from "@prosekit/pm/state";
|
445
476
|
|
446
477
|
// src/facets/state.ts
|
447
478
|
var stateFacet = defineFacet({
|
@@ -480,31 +511,78 @@ var stateFacet = defineFacet({
|
|
480
511
|
parent: rootFacet
|
481
512
|
});
|
482
513
|
|
514
|
+
// src/utils/editor-content.ts
|
515
|
+
import { Selection as Selection2 } from "@prosekit/pm/state";
|
516
|
+
|
517
|
+
// src/utils/is-object.ts
|
518
|
+
function isObject(v) {
|
519
|
+
return typeof v === "object" && v != null;
|
520
|
+
}
|
521
|
+
|
522
|
+
// src/utils/is-element.ts
|
523
|
+
var ELEMENT_NODE = 1;
|
524
|
+
function isElement(el) {
|
525
|
+
return isObject(el) && el.nodeType === ELEMENT_NODE && typeof el.nodeName === "string";
|
526
|
+
}
|
527
|
+
|
528
|
+
// src/utils/editor-content.ts
|
529
|
+
function getEditorContentJSON(schema, content) {
|
530
|
+
if (typeof content === "string") {
|
531
|
+
return jsonFromHTML(content, { schema });
|
532
|
+
} else if (isElement(content)) {
|
533
|
+
return jsonFromElement(content, { schema });
|
534
|
+
} else {
|
535
|
+
return content;
|
536
|
+
}
|
537
|
+
}
|
538
|
+
function getEditorContentNode(schema, content) {
|
539
|
+
if (isProseMirrorNode(content)) {
|
540
|
+
return content;
|
541
|
+
}
|
542
|
+
return schema.nodeFromJSON(getEditorContentJSON(schema, content));
|
543
|
+
}
|
544
|
+
function getEditorContentDoc(schema, content) {
|
545
|
+
const doc = getEditorContentNode(schema, content);
|
546
|
+
assert(
|
547
|
+
doc.type.schema === schema,
|
548
|
+
"Document schema does not match editor schema"
|
549
|
+
);
|
550
|
+
assert(
|
551
|
+
doc.type === schema.topNodeType,
|
552
|
+
`Document type does not match editor top node type. Expected ${schema.topNodeType.name}, got ${doc.type.name}`
|
553
|
+
);
|
554
|
+
return doc;
|
555
|
+
}
|
556
|
+
function getEditorSelection(doc, selection) {
|
557
|
+
if (isSelection(selection)) {
|
558
|
+
assert(selection.$head.doc === doc, "Selection and doc do not match");
|
559
|
+
return selection;
|
560
|
+
}
|
561
|
+
if (selection === "start") {
|
562
|
+
return Selection2.atStart(doc);
|
563
|
+
}
|
564
|
+
if (selection === "end") {
|
565
|
+
return Selection2.atEnd(doc);
|
566
|
+
}
|
567
|
+
return Selection2.fromJSON(doc, selection);
|
568
|
+
}
|
569
|
+
|
483
570
|
// src/extensions/default-state.ts
|
484
571
|
function defineDefaultState({
|
572
|
+
defaultSelection,
|
573
|
+
defaultContent,
|
485
574
|
defaultDoc,
|
486
|
-
defaultHTML
|
487
|
-
defaultSelection
|
575
|
+
defaultHTML
|
488
576
|
}) {
|
489
|
-
|
490
|
-
throw new ProseKitError(
|
491
|
-
"Only one of defaultHTML and defaultDoc can be provided"
|
492
|
-
);
|
493
|
-
}
|
577
|
+
const defaultDocContent = defaultContent || defaultDoc || defaultHTML;
|
494
578
|
return defineFacetPayload(stateFacet, [
|
495
579
|
({ schema }) => {
|
496
580
|
const config = {};
|
497
|
-
if (
|
498
|
-
|
499
|
-
|
500
|
-
} else {
|
501
|
-
defaultDoc = jsonFromElement(defaultHTML, { schema });
|
502
|
-
}
|
503
|
-
}
|
504
|
-
if (defaultDoc) {
|
505
|
-
config.doc = schema.nodeFromJSON(defaultDoc);
|
581
|
+
if (defaultDocContent) {
|
582
|
+
const json = getEditorContentJSON(schema, defaultDocContent);
|
583
|
+
config.doc = schema.nodeFromJSON(json);
|
506
584
|
if (defaultSelection) {
|
507
|
-
config.selection =
|
585
|
+
config.selection = Selection3.fromJSON(config.doc, defaultSelection);
|
508
586
|
}
|
509
587
|
}
|
510
588
|
return config;
|
@@ -556,29 +634,6 @@ function isMarkActive(state, type, attrs) {
|
|
556
634
|
}
|
557
635
|
}
|
558
636
|
|
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
637
|
// src/facets/union-extension.ts
|
583
638
|
var UnionExtensionImpl = class extends BaseExtension {
|
584
639
|
/**
|
@@ -646,6 +701,7 @@ function deepEquals(a, b) {
|
|
646
701
|
|
647
702
|
// src/editor/action.ts
|
648
703
|
import "@prosekit/pm/model";
|
704
|
+
import mapValues from "just-map-values";
|
649
705
|
|
650
706
|
// src/utils/attrs-match.ts
|
651
707
|
function attrsMatch(nodeOrMark, attrs) {
|
@@ -673,28 +729,32 @@ function isNodeActive(state, type, attrs) {
|
|
673
729
|
|
674
730
|
// src/editor/action.ts
|
675
731
|
function createNodeActions(schema, getState, createNode = defaultCreateNode) {
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
732
|
+
return mapValues(
|
733
|
+
schema.nodes,
|
734
|
+
(type) => createNodeAction(type, getState, createNode)
|
735
|
+
);
|
736
|
+
}
|
737
|
+
function createNodeAction(type, getState, createNode) {
|
738
|
+
const action = (...args) => buildNode(type, args, createNode);
|
739
|
+
action.isActive = (attrs) => {
|
740
|
+
const state = getState();
|
741
|
+
return state ? isNodeActive(state, type, attrs) : false;
|
742
|
+
};
|
743
|
+
return action;
|
686
744
|
}
|
687
745
|
function createMarkActions(schema, getState, applyMark = defaultApplyMark) {
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
746
|
+
return mapValues(
|
747
|
+
schema.marks,
|
748
|
+
(type) => createMarkAction(type, getState, applyMark)
|
749
|
+
);
|
750
|
+
}
|
751
|
+
function createMarkAction(type, getState, applyMark) {
|
752
|
+
const action = (...args) => buildMark(type, args, applyMark);
|
753
|
+
action.isActive = (attrs) => {
|
754
|
+
const state = getState();
|
755
|
+
return state ? isMarkActive(state, type, attrs) : false;
|
756
|
+
};
|
757
|
+
return action;
|
698
758
|
}
|
699
759
|
function buildMark(type, args, applyMark) {
|
700
760
|
const [attrs, children] = normalizeArgs(args);
|
@@ -702,7 +762,7 @@ function buildMark(type, args, applyMark) {
|
|
702
762
|
return applyMark(mark, flattenChildren(type.schema, children));
|
703
763
|
}
|
704
764
|
var defaultApplyMark = (mark, children) => {
|
705
|
-
return children.map((
|
765
|
+
return children.map((node) => node.mark(mark.addToSet(node.marks)));
|
706
766
|
};
|
707
767
|
function buildNode(type, args, createNode) {
|
708
768
|
const [attrs, children] = normalizeArgs(args);
|
@@ -750,27 +810,24 @@ function isNodeChild(value) {
|
|
750
810
|
|
751
811
|
// src/editor/editor.ts
|
752
812
|
function setupEditorExtension(options) {
|
753
|
-
|
754
|
-
if (defaultDoc || defaultHTML) {
|
813
|
+
if (options.defaultContent || options.defaultDoc || options.defaultHTML) {
|
755
814
|
return union([
|
756
815
|
options.extension,
|
757
|
-
defineDefaultState(
|
758
|
-
defaultDoc,
|
759
|
-
defaultHTML,
|
760
|
-
defaultSelection
|
761
|
-
})
|
816
|
+
defineDefaultState(options)
|
762
817
|
]);
|
763
818
|
}
|
764
819
|
return options.extension;
|
765
820
|
}
|
766
821
|
function createEditor(options) {
|
767
822
|
const extension = setupEditorExtension(options);
|
768
|
-
|
823
|
+
const instance = new EditorInstance(extension);
|
824
|
+
return new Editor(instance);
|
769
825
|
}
|
770
826
|
var EditorInstance = class {
|
771
827
|
constructor(extension) {
|
772
828
|
this.view = null;
|
773
829
|
this.commands = {};
|
830
|
+
this.afterMounted = [];
|
774
831
|
this.getState = () => {
|
775
832
|
var _a;
|
776
833
|
return ((_a = this.view) == null ? void 0 : _a.state) || this.directEditorProps.state;
|
@@ -798,6 +855,21 @@ var EditorInstance = class {
|
|
798
855
|
this.directEditorProps.state = state;
|
799
856
|
}
|
800
857
|
}
|
858
|
+
setContent(content, selection) {
|
859
|
+
const doc = getEditorContentDoc(this.schema, content);
|
860
|
+
doc.check();
|
861
|
+
const sel = getEditorSelection(doc, selection || "start");
|
862
|
+
const oldState = this.getState();
|
863
|
+
if (doc.eq(oldState.doc) && (!selection || sel.eq(oldState.selection))) {
|
864
|
+
return;
|
865
|
+
}
|
866
|
+
const newState = EditorState2.create({
|
867
|
+
doc,
|
868
|
+
selection: sel,
|
869
|
+
plugins: oldState.plugins
|
870
|
+
});
|
871
|
+
this.updateState(newState);
|
872
|
+
}
|
801
873
|
updateExtension(extension, add) {
|
802
874
|
var _a, _b, _c, _d;
|
803
875
|
const view = this.view;
|
@@ -829,19 +901,33 @@ var EditorInstance = class {
|
|
829
901
|
}
|
830
902
|
}
|
831
903
|
}
|
904
|
+
use(extension) {
|
905
|
+
if (!this.mounted) {
|
906
|
+
let canceled = false;
|
907
|
+
let lazyRemove = null;
|
908
|
+
const lazyCreate = () => {
|
909
|
+
if (!canceled) {
|
910
|
+
lazyRemove = this.use(extension);
|
911
|
+
}
|
912
|
+
};
|
913
|
+
this.afterMounted.push(lazyCreate);
|
914
|
+
return () => {
|
915
|
+
canceled = true;
|
916
|
+
lazyRemove == null ? void 0 : lazyRemove();
|
917
|
+
};
|
918
|
+
}
|
919
|
+
this.updateExtension(extension, true);
|
920
|
+
return () => this.updateExtension(extension, false);
|
921
|
+
}
|
832
922
|
mount(place) {
|
833
923
|
if (this.view) {
|
834
924
|
throw new ProseKitError("Editor is already mounted");
|
835
925
|
}
|
836
|
-
if (!place) {
|
837
|
-
throw new ProseKitError("Can't mount editor without a place");
|
838
|
-
}
|
839
926
|
this.view = new EditorView({ mount: place }, this.directEditorProps);
|
927
|
+
this.afterMounted.forEach((callback) => callback());
|
840
928
|
}
|
841
929
|
unmount() {
|
842
|
-
if (!this.view)
|
843
|
-
throw new ProseKitError("Editor is not mounted yet");
|
844
|
-
}
|
930
|
+
if (!this.view) return;
|
845
931
|
this.directEditorProps.state = this.view.state;
|
846
932
|
this.view.destroy();
|
847
933
|
this.view = null;
|
@@ -891,25 +977,81 @@ var EditorInstance = class {
|
|
891
977
|
delete this.commands[name];
|
892
978
|
}
|
893
979
|
};
|
894
|
-
var Editor = class
|
980
|
+
var Editor = class {
|
895
981
|
/**
|
896
982
|
* @internal
|
897
983
|
*/
|
898
984
|
constructor(instance) {
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
this.
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
985
|
+
/**
|
986
|
+
* Mount the editor to the given HTML element.
|
987
|
+
* Pass `null` or `undefined` to unmount the editor.
|
988
|
+
*/
|
989
|
+
this.mount = (place) => {
|
990
|
+
if (place) {
|
991
|
+
this.instance.mount(place);
|
992
|
+
} else {
|
993
|
+
this.instance.unmount();
|
994
|
+
}
|
995
|
+
};
|
996
|
+
/**
|
997
|
+
* Unmount the editor. This is equivalent to `mount(null)`.
|
998
|
+
*/
|
999
|
+
this.unmount = () => {
|
1000
|
+
this.instance.unmount();
|
1001
|
+
};
|
1002
|
+
/**
|
1003
|
+
* Focus the editor.
|
1004
|
+
*/
|
1005
|
+
this.focus = () => {
|
1006
|
+
var _a;
|
1007
|
+
(_a = this.instance.view) == null ? void 0 : _a.focus();
|
1008
|
+
};
|
1009
|
+
/**
|
1010
|
+
* Blur the editor.
|
1011
|
+
*/
|
1012
|
+
this.blur = () => {
|
1013
|
+
var _a;
|
1014
|
+
(_a = this.instance.view) == null ? void 0 : _a.dom.blur();
|
1015
|
+
};
|
1016
|
+
/**
|
1017
|
+
* Register an extension to the editor. Return a function to unregister the
|
1018
|
+
* extension.
|
1019
|
+
*/
|
1020
|
+
this.use = (extension) => {
|
1021
|
+
return this.instance.use(extension);
|
1022
|
+
};
|
1023
|
+
/**
|
1024
|
+
* Update the editor's state.
|
1025
|
+
*
|
1026
|
+
* @remarks
|
1027
|
+
*
|
1028
|
+
* This is an advanced method. Use it only if you have a specific reason to
|
1029
|
+
* directly manipulate the editor's state.
|
1030
|
+
*/
|
1031
|
+
this.updateState = (state) => {
|
1032
|
+
this.instance.updateState(state);
|
1033
|
+
};
|
1034
|
+
/**
|
1035
|
+
* Update the editor's document and selection.
|
1036
|
+
*
|
1037
|
+
* @param content - The new document to set. It can be one of the following:
|
1038
|
+
* - A ProseMirror node instance
|
1039
|
+
* - A ProseMirror node JSON object
|
1040
|
+
* - An HTML string
|
1041
|
+
* - An HTML element instance
|
1042
|
+
* @param selection - Optional. Specifies the new selection. It can be one of the following:
|
1043
|
+
* - A ProseMirror selection instance
|
1044
|
+
* - A ProseMirror selection JSON object
|
1045
|
+
* - The string "start" (to set selection at the beginning, default value)
|
1046
|
+
* - The string "end" (to set selection at the end)
|
1047
|
+
*/
|
1048
|
+
this.setContent = (content, selection) => {
|
1049
|
+
return this.instance.setContent(content, selection);
|
1050
|
+
};
|
909
1051
|
if (!(instance instanceof EditorInstance)) {
|
910
1052
|
throw new TypeError("Invalid EditorInstance");
|
911
1053
|
}
|
912
|
-
|
1054
|
+
this.instance = instance;
|
913
1055
|
}
|
914
1056
|
/**
|
915
1057
|
* Whether the editor is mounted.
|
@@ -929,68 +1071,6 @@ var Editor = class _Editor {
|
|
929
1071
|
get schema() {
|
930
1072
|
return this.instance.schema;
|
931
1073
|
}
|
932
|
-
/**
|
933
|
-
* Whether the editor is focused.
|
934
|
-
*/
|
935
|
-
get focused() {
|
936
|
-
var _a, _b;
|
937
|
-
return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b : false;
|
938
|
-
}
|
939
|
-
/**
|
940
|
-
* Mount the editor to the given HTML element.
|
941
|
-
* Pass `null` or `undefined` to unmount the editor.
|
942
|
-
*/
|
943
|
-
mount(place) {
|
944
|
-
if (!place) {
|
945
|
-
return this.unmount();
|
946
|
-
}
|
947
|
-
this.instance.mount(place);
|
948
|
-
this.afterMounted.forEach((callback) => callback());
|
949
|
-
}
|
950
|
-
/**
|
951
|
-
* Unmount the editor. This is equivalent to `mount(null)`.
|
952
|
-
*/
|
953
|
-
unmount() {
|
954
|
-
if (this.mounted) {
|
955
|
-
this.instance.unmount();
|
956
|
-
}
|
957
|
-
}
|
958
|
-
/**
|
959
|
-
* Focus the editor.
|
960
|
-
*/
|
961
|
-
focus() {
|
962
|
-
var _a;
|
963
|
-
(_a = this.instance.view) == null ? void 0 : _a.focus();
|
964
|
-
}
|
965
|
-
/**
|
966
|
-
* Blur the editor.
|
967
|
-
*/
|
968
|
-
blur() {
|
969
|
-
var _a;
|
970
|
-
(_a = this.instance.view) == null ? void 0 : _a.dom.blur();
|
971
|
-
}
|
972
|
-
/**
|
973
|
-
* Register an extension to the editor. Return a function to unregister the
|
974
|
-
* extension.
|
975
|
-
*/
|
976
|
-
use(extension) {
|
977
|
-
if (!this.mounted) {
|
978
|
-
let canceled = false;
|
979
|
-
let lazyRemove = null;
|
980
|
-
const lazyCreate = () => {
|
981
|
-
if (!canceled) {
|
982
|
-
lazyRemove = this.use(extension);
|
983
|
-
}
|
984
|
-
};
|
985
|
-
this.afterMounted.push(lazyCreate);
|
986
|
-
return () => {
|
987
|
-
canceled = true;
|
988
|
-
lazyRemove == null ? void 0 : lazyRemove();
|
989
|
-
};
|
990
|
-
}
|
991
|
-
this.instance.updateExtension(extension, true);
|
992
|
-
return () => this.instance.updateExtension(extension, false);
|
993
|
-
}
|
994
1074
|
/**
|
995
1075
|
* The editor's current state.
|
996
1076
|
*/
|
@@ -998,15 +1078,11 @@ var Editor = class _Editor {
|
|
998
1078
|
return this.instance.getState();
|
999
1079
|
}
|
1000
1080
|
/**
|
1001
|
-
*
|
1002
|
-
*
|
1003
|
-
* @remarks
|
1004
|
-
*
|
1005
|
-
* This is an advanced method. Use it only if you have a specific reason to
|
1006
|
-
* directly manipulate the editor's state.
|
1081
|
+
* Whether the editor is focused.
|
1007
1082
|
*/
|
1008
|
-
|
1009
|
-
|
1083
|
+
get focused() {
|
1084
|
+
var _a, _b;
|
1085
|
+
return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b : false;
|
1010
1086
|
}
|
1011
1087
|
/**
|
1012
1088
|
* All {@link CommandAction}s defined by the editor.
|
@@ -1037,12 +1113,21 @@ export {
|
|
1037
1113
|
isNodeActive,
|
1038
1114
|
Priority,
|
1039
1115
|
toReversed,
|
1040
|
-
|
1116
|
+
isProseMirrorNode,
|
1117
|
+
isMark,
|
1118
|
+
isFragment,
|
1119
|
+
isSlice,
|
1120
|
+
isSelection,
|
1121
|
+
isTextSelection,
|
1122
|
+
isNodeSelection,
|
1123
|
+
isAllSelection,
|
1124
|
+
isNotNullish,
|
1041
1125
|
defineFacet,
|
1042
1126
|
rootFacet,
|
1043
1127
|
schemaFacet,
|
1044
1128
|
defineFacetPayload,
|
1045
1129
|
stateFacet,
|
1130
|
+
isElement,
|
1046
1131
|
jsonFromState,
|
1047
1132
|
stateFromJSON,
|
1048
1133
|
jsonFromNode,
|
@@ -1057,11 +1142,6 @@ export {
|
|
1057
1142
|
defineDefaultState,
|
1058
1143
|
isMarkAbsent,
|
1059
1144
|
isMarkActive,
|
1060
|
-
isProseMirrorNode,
|
1061
|
-
isMark,
|
1062
|
-
isTextSelection,
|
1063
|
-
isNodeSelection,
|
1064
|
-
isAllSelection,
|
1065
1145
|
createNodeActions,
|
1066
1146
|
createMarkActions,
|
1067
1147
|
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-UKHJHMFE.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
@@ -142,11 +142,15 @@ export { SimplifyUnion } from './_tsup-dts-rollup';
|
|
142
142
|
export { assert } from './_tsup-dts-rollup';
|
143
143
|
export { canUseRegexLookbehind } from './_tsup-dts-rollup';
|
144
144
|
export { clsx } from './_tsup-dts-rollup';
|
145
|
+
export { collectChildren } from './_tsup-dts-rollup';
|
145
146
|
export { collectNodes } from './_tsup-dts-rollup';
|
146
147
|
export { NodeContent } from './_tsup-dts-rollup';
|
147
148
|
export { containsInlineNode } from './_tsup-dts-rollup';
|
148
149
|
export { defaultBlockAt } from './_tsup-dts-rollup';
|
149
150
|
export { isApple } from './_tsup-dts-rollup';
|
151
|
+
export { findParentNode } from './_tsup-dts-rollup';
|
152
|
+
export { FindParentNodeResult } from './_tsup-dts-rollup';
|
153
|
+
export { findParentNodeOfType } from './_tsup-dts-rollup';
|
150
154
|
export { _getId } from './_tsup-dts-rollup';
|
151
155
|
export { getMarkType } from './_tsup-dts-rollup';
|
152
156
|
export { getNodeType } from './_tsup-dts-rollup';
|
@@ -171,9 +175,12 @@ export { DOMParserOptions } from './_tsup-dts-rollup';
|
|
171
175
|
export { DOMSerializerOptions } from './_tsup-dts-rollup';
|
172
176
|
export { JSONParserOptions } from './_tsup-dts-rollup';
|
173
177
|
export { isAllSelection } from './_tsup-dts-rollup';
|
178
|
+
export { isFragment } from './_tsup-dts-rollup';
|
174
179
|
export { isMark } from './_tsup-dts-rollup';
|
175
180
|
export { isNodeSelection } from './_tsup-dts-rollup';
|
176
181
|
export { isProseMirrorNode } from './_tsup-dts-rollup';
|
182
|
+
export { isSelection } from './_tsup-dts-rollup';
|
183
|
+
export { isSlice } from './_tsup-dts-rollup';
|
177
184
|
export { isTextSelection } from './_tsup-dts-rollup';
|
178
185
|
export { withSkipCodeBlock } from './_tsup-dts-rollup';
|
179
186
|
export { OBJECT_REPLACEMENT_CHARACTER } from './_tsup-dts-rollup';
|