@prosekit/core 0.0.0-next-20231120040948 → 0.0.0-next-20240421132240
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 +747 -49
- package/dist/prosekit-core.d.ts +62 -5
- package/dist/prosekit-core.js +787 -184
- package/package.json +7 -9
- package/dist/style.css +0 -55
- package/src/index.ts +0 -71
package/dist/prosekit-core.js
CHANGED
@@ -8,6 +8,20 @@ import "@prosekit/pm/model";
|
|
8
8
|
// src/error.ts
|
9
9
|
var ProseKitError = class extends Error {
|
10
10
|
};
|
11
|
+
var EditorNotFoundError = class extends ProseKitError {
|
12
|
+
constructor() {
|
13
|
+
super(
|
14
|
+
"Unable to find editor. Pass it as an argument or call this function inside a ProseKit component."
|
15
|
+
);
|
16
|
+
}
|
17
|
+
};
|
18
|
+
var DOMDocumentNotFoundError = class extends ProseKitError {
|
19
|
+
constructor() {
|
20
|
+
super(
|
21
|
+
"Unable to find browser Document. When not in the browser environment, you need to pass a DOM Document."
|
22
|
+
);
|
23
|
+
}
|
24
|
+
};
|
11
25
|
|
12
26
|
// src/utils/get-mark-type.ts
|
13
27
|
function getMarkType(schema, type) {
|
@@ -36,8 +50,61 @@ function addMark(options) {
|
|
36
50
|
};
|
37
51
|
}
|
38
52
|
|
39
|
-
// src/commands/
|
53
|
+
// src/commands/expand-mark.ts
|
40
54
|
import { TextSelection } from "@prosekit/pm/state";
|
55
|
+
function expandMark(options) {
|
56
|
+
return (state, dispatch) => {
|
57
|
+
const markType = getMarkType(state.schema, options.type);
|
58
|
+
const predicate = (mark) => mark.type === markType;
|
59
|
+
const from = expandMarkBefore(state.selection.$from, predicate);
|
60
|
+
const to = expandMarkAfter(state.selection.$to, predicate);
|
61
|
+
if (from === state.selection.from && to === state.selection.to) {
|
62
|
+
return false;
|
63
|
+
}
|
64
|
+
if (dispatch) {
|
65
|
+
dispatch(state.tr.setSelection(TextSelection.create(state.doc, from, to)));
|
66
|
+
}
|
67
|
+
return true;
|
68
|
+
};
|
69
|
+
}
|
70
|
+
function expandMarkBefore($pos, predicate) {
|
71
|
+
const { parent } = $pos;
|
72
|
+
if (!$pos.marks().some(predicate)) {
|
73
|
+
return $pos.pos;
|
74
|
+
}
|
75
|
+
const index = $pos.index();
|
76
|
+
let boundaryIndex = index;
|
77
|
+
for (let i = index; i >= 0; i--) {
|
78
|
+
const node = parent.child(i);
|
79
|
+
if (node.marks.some(predicate)) {
|
80
|
+
boundaryIndex = i;
|
81
|
+
} else {
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
return $pos.posAtIndex(boundaryIndex);
|
86
|
+
}
|
87
|
+
function expandMarkAfter($pos, predicate) {
|
88
|
+
const { parent } = $pos;
|
89
|
+
if (!$pos.marks().some(predicate)) {
|
90
|
+
return $pos.pos;
|
91
|
+
}
|
92
|
+
const index = Math.max(0, $pos.indexAfter() - 1);
|
93
|
+
const childCount = parent.childCount;
|
94
|
+
let boundaryIndex = index;
|
95
|
+
for (let i = index; i < childCount; i++) {
|
96
|
+
const node = parent.child(i);
|
97
|
+
if (node.marks.some(predicate)) {
|
98
|
+
boundaryIndex = i;
|
99
|
+
} else {
|
100
|
+
break;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
return $pos.posAtIndex(boundaryIndex) + parent.child(boundaryIndex).nodeSize;
|
104
|
+
}
|
105
|
+
|
106
|
+
// src/commands/insert-node.ts
|
107
|
+
import "@prosekit/pm/state";
|
41
108
|
import { insertPoint } from "@prosekit/pm/transform";
|
42
109
|
|
43
110
|
// src/utils/get-node-type.ts
|
@@ -53,6 +120,15 @@ function getNodeType(schema, type) {
|
|
53
120
|
return type;
|
54
121
|
}
|
55
122
|
|
123
|
+
// src/utils/set-selection-around.ts
|
124
|
+
import { TextSelection as TextSelection2 } from "@prosekit/pm/state";
|
125
|
+
function setSelectionAround(tr, pos) {
|
126
|
+
const docSize = tr.doc.content.size;
|
127
|
+
const $pos = tr.doc.resolve(pos > docSize ? docSize : pos < 0 ? 0 : pos);
|
128
|
+
const selection = TextSelection2.between($pos, $pos);
|
129
|
+
tr.setSelection(selection);
|
130
|
+
}
|
131
|
+
|
56
132
|
// src/commands/insert-node.ts
|
57
133
|
function insertNode(options) {
|
58
134
|
return (state, dispatch) => {
|
@@ -70,7 +146,7 @@ function insertNode(options) {
|
|
70
146
|
return false;
|
71
147
|
if (dispatch) {
|
72
148
|
const tr = state.tr.insert(insertPos, node);
|
73
|
-
|
149
|
+
setSelectionAround(tr, insertPos + node.nodeSize);
|
74
150
|
dispatch(tr);
|
75
151
|
}
|
76
152
|
return true;
|
@@ -99,13 +175,13 @@ function removeMark(options) {
|
|
99
175
|
import "@prosekit/pm/state";
|
100
176
|
|
101
177
|
// src/utils/get-custom-selection.ts
|
102
|
-
import { TextSelection as
|
178
|
+
import { TextSelection as TextSelection3 } from "@prosekit/pm/state";
|
103
179
|
function getCustomSelection(state, from, to) {
|
104
180
|
const pos = from != null ? from : to;
|
105
181
|
if (pos != null) {
|
106
182
|
const $from = state.doc.resolve(from != null ? from : pos);
|
107
183
|
const $to = state.doc.resolve(to != null ? to : pos);
|
108
|
-
return
|
184
|
+
return TextSelection3.between($from, $to);
|
109
185
|
}
|
110
186
|
return state.selection;
|
111
187
|
}
|
@@ -152,6 +228,29 @@ function setBlockType(options) {
|
|
152
228
|
};
|
153
229
|
}
|
154
230
|
|
231
|
+
// src/commands/set-node-attrs.ts
|
232
|
+
function setNodeAttrs(options) {
|
233
|
+
return (state, dispatch) => {
|
234
|
+
var _a;
|
235
|
+
const nodeType = getNodeType(state.schema, options.type);
|
236
|
+
const pos = (_a = options.pos) != null ? _a : state.selection.$from.before();
|
237
|
+
const node = state.doc.nodeAt(pos);
|
238
|
+
if (!node || node.type !== nodeType) {
|
239
|
+
return false;
|
240
|
+
}
|
241
|
+
if (dispatch) {
|
242
|
+
const { tr } = state;
|
243
|
+
for (const [key, value] of Object.entries(options.attrs)) {
|
244
|
+
if (value !== void 0) {
|
245
|
+
tr.setNodeAttribute(pos, key, value);
|
246
|
+
}
|
247
|
+
}
|
248
|
+
dispatch(tr);
|
249
|
+
}
|
250
|
+
return true;
|
251
|
+
};
|
252
|
+
}
|
253
|
+
|
155
254
|
// src/commands/toggle-mark.ts
|
156
255
|
import { toggleMark as baseToggleMark } from "@prosekit/pm/commands";
|
157
256
|
import "@prosekit/pm/model";
|
@@ -341,11 +440,11 @@ var stateFacet = Facet.defineRootFacet({
|
|
341
440
|
});
|
342
441
|
|
343
442
|
// src/utils/parse.ts
|
344
|
-
import { DOMParser } from "@prosekit/pm/model";
|
443
|
+
import { DOMParser, DOMSerializer } from "@prosekit/pm/model";
|
345
444
|
import { EditorState } from "@prosekit/pm/state";
|
346
445
|
|
347
446
|
// src/utils/get-dom-api.ts
|
348
|
-
function
|
447
|
+
function findGlobalBrowserDocument() {
|
349
448
|
if (typeof document !== "undefined") {
|
350
449
|
return document;
|
351
450
|
}
|
@@ -353,7 +452,7 @@ function getGlobalBrowserDocument() {
|
|
353
452
|
return globalThis.document;
|
354
453
|
}
|
355
454
|
}
|
356
|
-
function
|
455
|
+
function findGlobalBrowserWindow() {
|
357
456
|
if (typeof window !== "undefined") {
|
358
457
|
return window;
|
359
458
|
}
|
@@ -361,49 +460,85 @@ function getGlobalBrowserWindow() {
|
|
361
460
|
return globalThis.window;
|
362
461
|
}
|
363
462
|
}
|
364
|
-
function
|
365
|
-
var _a;
|
366
|
-
|
367
|
-
|
463
|
+
function findBrowserDocument(options) {
|
464
|
+
var _a, _b, _c;
|
465
|
+
return (_c = (_a = options == null ? void 0 : options.document) != null ? _a : findGlobalBrowserDocument()) != null ? _c : (_b = findGlobalBrowserWindow()) == null ? void 0 : _b.document;
|
466
|
+
}
|
467
|
+
function findBrowserWindow(options) {
|
468
|
+
var _a, _b, _c, _d;
|
469
|
+
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;
|
470
|
+
}
|
471
|
+
function getBrowserDocument(options) {
|
472
|
+
const doc = findBrowserDocument(options);
|
473
|
+
if (doc)
|
474
|
+
return doc;
|
475
|
+
throw new DOMDocumentNotFoundError();
|
476
|
+
}
|
477
|
+
function getBrowserWindow(options) {
|
478
|
+
const win = findBrowserWindow(options);
|
479
|
+
if (win)
|
368
480
|
return win;
|
369
|
-
|
370
|
-
return (_a = getGlobalBrowserDocument()) == null ? void 0 : _a.defaultView;
|
481
|
+
throw new DOMDocumentNotFoundError();
|
371
482
|
}
|
372
483
|
|
373
484
|
// src/utils/parse.ts
|
374
|
-
function
|
375
|
-
return
|
376
|
-
}
|
377
|
-
function jsonFromElement(element, schema) {
|
378
|
-
return jsonFromNode(nodeFromElement(element, schema));
|
485
|
+
function jsonFromState(state) {
|
486
|
+
return state.toJSON();
|
379
487
|
}
|
380
|
-
function
|
381
|
-
return
|
488
|
+
function stateFromJSON(json, options) {
|
489
|
+
return EditorState.fromJSON({ schema: options.schema }, json);
|
382
490
|
}
|
383
|
-
function
|
384
|
-
return
|
491
|
+
function jsonFromNode(node) {
|
492
|
+
return node.toJSON();
|
385
493
|
}
|
386
|
-
function
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
494
|
+
function nodeFromJSON(json, options) {
|
495
|
+
return options.schema.nodeFromJSON(json);
|
496
|
+
}
|
497
|
+
function nodeFromElement(element, options) {
|
498
|
+
const Parser = options.DOMParser || DOMParser;
|
499
|
+
const schema = options.schema;
|
500
|
+
return Parser.fromSchema(schema).parse(element);
|
501
|
+
}
|
502
|
+
function elementFromNode(node, options) {
|
503
|
+
const Serializer = (options == null ? void 0 : options.DOMSerializer) || DOMSerializer;
|
504
|
+
const document2 = getBrowserDocument(options);
|
505
|
+
const schema = node.type.schema;
|
506
|
+
const serializer = Serializer.fromSchema(schema);
|
507
|
+
if (schema.topNodeType !== node.type) {
|
508
|
+
return serializer.serializeNode(node, { document: document2 });
|
509
|
+
} else {
|
510
|
+
return serializer.serializeFragment(
|
511
|
+
node.content,
|
512
|
+
{ document: document2 },
|
513
|
+
document2.createElement("div")
|
391
514
|
);
|
392
515
|
}
|
516
|
+
}
|
517
|
+
function elementFromHTML(html, options) {
|
518
|
+
const win = getBrowserWindow(options);
|
393
519
|
const parser = new win.DOMParser();
|
394
|
-
return parser.parseFromString(`<body>${html}</body>`, "text/html").body;
|
520
|
+
return parser.parseFromString(`<body><div>${html}</div></body>`, "text/html").body.firstElementChild;
|
395
521
|
}
|
396
|
-
function
|
397
|
-
return
|
522
|
+
function htmlFromElement(element) {
|
523
|
+
return element.outerHTML;
|
398
524
|
}
|
399
|
-
function
|
400
|
-
return
|
525
|
+
function nodeFromHTML(html, options) {
|
526
|
+
return nodeFromElement(elementFromHTML(html, options), options);
|
527
|
+
}
|
528
|
+
function htmlFromNode(node, options) {
|
529
|
+
return elementFromNode(node, options).outerHTML;
|
530
|
+
}
|
531
|
+
function jsonFromElement(element, options) {
|
532
|
+
return jsonFromNode(nodeFromElement(element, options));
|
401
533
|
}
|
402
|
-
function
|
403
|
-
return
|
534
|
+
function elementFromJSON(json, options) {
|
535
|
+
return elementFromNode(nodeFromJSON(json, options), options);
|
404
536
|
}
|
405
|
-
function
|
406
|
-
return
|
537
|
+
function jsonFromHTML(html, options) {
|
538
|
+
return jsonFromElement(elementFromHTML(html, options), options);
|
539
|
+
}
|
540
|
+
function htmlFromJSON(json, options) {
|
541
|
+
return htmlFromElement(elementFromJSON(json, options));
|
407
542
|
}
|
408
543
|
|
409
544
|
// src/extensions/default-state.ts
|
@@ -422,9 +557,9 @@ function defineDefaultState({
|
|
422
557
|
const config = {};
|
423
558
|
if (defaultHTML) {
|
424
559
|
if (typeof defaultHTML === "string") {
|
425
|
-
defaultDoc = jsonFromHTML(defaultHTML, schema);
|
560
|
+
defaultDoc = jsonFromHTML(defaultHTML, { schema });
|
426
561
|
} else {
|
427
|
-
defaultDoc = jsonFromElement(defaultHTML, schema);
|
562
|
+
defaultDoc = jsonFromElement(defaultHTML, { schema });
|
428
563
|
}
|
429
564
|
}
|
430
565
|
if (defaultDoc) {
|
@@ -654,12 +789,28 @@ function updateExtension(prevInputs, prevConverters, extension, mode) {
|
|
654
789
|
return { schemaInput, stateInput, viewInput, commandInput };
|
655
790
|
}
|
656
791
|
|
792
|
+
// src/editor/builder.ts
|
793
|
+
import "@prosekit/pm/model";
|
794
|
+
|
795
|
+
// src/utils/is-mark-active.ts
|
796
|
+
function isMarkActive(state, type, attrs) {
|
797
|
+
const { from, $from, to, empty } = state.selection;
|
798
|
+
const markType = getMarkType(state.schema, type);
|
799
|
+
if (empty) {
|
800
|
+
const mark = attrs ? markType.create(attrs) : markType;
|
801
|
+
return !!mark.isInSet(state.storedMarks || $from.marks());
|
802
|
+
} else {
|
803
|
+
const markOrType = attrs ? markType.create(attrs) : markType;
|
804
|
+
return state.doc.rangeHasMark(from, to, markOrType);
|
805
|
+
}
|
806
|
+
}
|
807
|
+
|
657
808
|
// src/utils/type-assertion.ts
|
658
809
|
import { Mark, ProseMirrorNode } from "@prosekit/pm/model";
|
659
810
|
import {
|
660
811
|
AllSelection,
|
661
812
|
NodeSelection,
|
662
|
-
TextSelection as
|
813
|
+
TextSelection as TextSelection4
|
663
814
|
} from "@prosekit/pm/state";
|
664
815
|
function isProseMirrorNode(node) {
|
665
816
|
return node instanceof ProseMirrorNode;
|
@@ -668,7 +819,7 @@ function isMark(mark) {
|
|
668
819
|
return mark instanceof Mark;
|
669
820
|
}
|
670
821
|
function isTextSelection(sel) {
|
671
|
-
return sel instanceof
|
822
|
+
return sel instanceof TextSelection4;
|
672
823
|
}
|
673
824
|
function isNodeSelection(sel) {
|
674
825
|
return sel instanceof NodeSelection;
|
@@ -677,30 +828,7 @@ function isAllSelection(sel) {
|
|
677
828
|
return sel instanceof AllSelection;
|
678
829
|
}
|
679
830
|
|
680
|
-
// src/utils/is-mark-active.ts
|
681
|
-
function isMarkActive(state, type, attrs) {
|
682
|
-
const markType = getMarkType(state.schema, type);
|
683
|
-
const mark = attrs ? markType.create(attrs) : markType;
|
684
|
-
const { from, $from, to, empty } = state.selection;
|
685
|
-
if (empty) {
|
686
|
-
return hasMark(state.storedMarks || $from.marks(), mark);
|
687
|
-
} else {
|
688
|
-
return state.doc.rangeHasMark(from, to, mark);
|
689
|
-
}
|
690
|
-
}
|
691
|
-
function hasMark(marks, mark) {
|
692
|
-
if (marks.length === 0) {
|
693
|
-
return false;
|
694
|
-
}
|
695
|
-
if (isMark(mark)) {
|
696
|
-
return marks.some((m) => m.eq(mark));
|
697
|
-
} else {
|
698
|
-
return marks.some((m) => m.type === mark);
|
699
|
-
}
|
700
|
-
}
|
701
|
-
|
702
831
|
// src/editor/builder.ts
|
703
|
-
import "@prosekit/pm/model";
|
704
832
|
function createNodeBuilder(getState, type) {
|
705
833
|
const builder = (...args) => buildNode(type, args);
|
706
834
|
builder.isActive = (attrs) => {
|
@@ -814,12 +942,9 @@ function union(extension) {
|
|
814
942
|
}
|
815
943
|
|
816
944
|
// src/editor/editor.ts
|
817
|
-
function createEditor({
|
818
|
-
|
819
|
-
|
820
|
-
defaultHTML,
|
821
|
-
defaultSelection
|
822
|
-
}) {
|
945
|
+
function createEditor(options) {
|
946
|
+
const { defaultDoc, defaultHTML, defaultSelection } = options;
|
947
|
+
let extension = options.extension;
|
823
948
|
if (defaultDoc || defaultHTML) {
|
824
949
|
extension = union([
|
825
950
|
extension,
|
@@ -847,6 +972,7 @@ var EditorInstance = class {
|
|
847
972
|
const schema = new Schema6(schemaInput);
|
848
973
|
const stateConfig = stateInput ? stateInput({ schema }) : { schema };
|
849
974
|
const state = EditorState2.create(stateConfig);
|
975
|
+
this.cachedState = state;
|
850
976
|
if (commandInput) {
|
851
977
|
for (const [name, commandCreator] of Object.entries(commandInput)) {
|
852
978
|
this.defineCommand(name, commandCreator);
|
@@ -854,10 +980,7 @@ var EditorInstance = class {
|
|
854
980
|
}
|
855
981
|
this.directEditorProps = { state, ...viewInput };
|
856
982
|
this.schema = this.directEditorProps.state.schema;
|
857
|
-
const getState = () =>
|
858
|
-
var _a;
|
859
|
-
return (_a = this.view) == null ? void 0 : _a.state;
|
860
|
-
};
|
983
|
+
const getState = () => this.getState();
|
861
984
|
this.nodeBuilders = Object.fromEntries(
|
862
985
|
Object.values(this.schema.nodes).map((type) => [
|
863
986
|
type.name,
|
@@ -871,6 +994,12 @@ var EditorInstance = class {
|
|
871
994
|
])
|
872
995
|
);
|
873
996
|
}
|
997
|
+
getState() {
|
998
|
+
if (this.view) {
|
999
|
+
this.cachedState = this.view.state;
|
1000
|
+
}
|
1001
|
+
return this.cachedState;
|
1002
|
+
}
|
874
1003
|
updateExtension(extension, mode) {
|
875
1004
|
var _a;
|
876
1005
|
const { schemaInput, stateInput, viewInput, commandInput } = updateExtension(this.payloads, this.converters, extension, mode);
|
@@ -975,18 +1104,38 @@ var Editor = class _Editor {
|
|
975
1104
|
}
|
976
1105
|
return new _Editor(instance);
|
977
1106
|
}
|
1107
|
+
/**
|
1108
|
+
* Whether the editor is mounted.
|
1109
|
+
*/
|
978
1110
|
get mounted() {
|
979
1111
|
return !!this.instance.view;
|
980
1112
|
}
|
1113
|
+
/**
|
1114
|
+
* The editor view.
|
1115
|
+
*/
|
981
1116
|
get view() {
|
982
1117
|
return this.instance.assertView;
|
983
1118
|
}
|
1119
|
+
/**
|
1120
|
+
* The editor schema.
|
1121
|
+
*/
|
984
1122
|
get schema() {
|
985
1123
|
return this.instance.schema;
|
986
1124
|
}
|
987
1125
|
get commands() {
|
988
1126
|
return this.instance.commandAppliers;
|
989
1127
|
}
|
1128
|
+
/**
|
1129
|
+
* Whether the editor is focused.
|
1130
|
+
*/
|
1131
|
+
get focused() {
|
1132
|
+
var _a, _b;
|
1133
|
+
return (_b = (_a = this.instance.view) == null ? void 0 : _a.hasFocus()) != null ? _b : false;
|
1134
|
+
}
|
1135
|
+
/**
|
1136
|
+
* Mount the editor to the given HTML element.
|
1137
|
+
* Pass `null` or `undefined` to unmount the editor.
|
1138
|
+
*/
|
990
1139
|
mount(place) {
|
991
1140
|
if (!place) {
|
992
1141
|
return this.unmount();
|
@@ -994,11 +1143,28 @@ var Editor = class _Editor {
|
|
994
1143
|
this.instance.mount(place);
|
995
1144
|
this.afterMounted.forEach((callback) => callback());
|
996
1145
|
}
|
1146
|
+
/**
|
1147
|
+
* Unmount the editor. This is equivalent to `mount(null)`.
|
1148
|
+
*/
|
997
1149
|
unmount() {
|
998
1150
|
if (this.mounted) {
|
999
1151
|
this.instance.unmount();
|
1000
1152
|
}
|
1001
1153
|
}
|
1154
|
+
/**
|
1155
|
+
* Focus the editor.
|
1156
|
+
*/
|
1157
|
+
focus() {
|
1158
|
+
var _a;
|
1159
|
+
(_a = this.instance.view) == null ? void 0 : _a.focus();
|
1160
|
+
}
|
1161
|
+
/**
|
1162
|
+
* Blur the editor.
|
1163
|
+
*/
|
1164
|
+
blur() {
|
1165
|
+
var _a;
|
1166
|
+
(_a = this.instance.view) == null ? void 0 : _a.dom.blur();
|
1167
|
+
}
|
1002
1168
|
use(extension) {
|
1003
1169
|
if (!this.mounted) {
|
1004
1170
|
let lazyRemove = null;
|
@@ -1013,17 +1179,8 @@ var Editor = class _Editor {
|
|
1013
1179
|
this.instance.updateExtension(extension, "add");
|
1014
1180
|
return () => this.instance.updateExtension(extension, "remove");
|
1015
1181
|
}
|
1016
|
-
|
1017
|
-
|
1018
|
-
*/
|
1019
|
-
isNodeActive(nodeType, attrs) {
|
1020
|
-
return isNodeActive(this.view.state, nodeType, attrs);
|
1021
|
-
}
|
1022
|
-
/**
|
1023
|
-
* @deprecated
|
1024
|
-
*/
|
1025
|
-
isMarkActive(markType, attrs) {
|
1026
|
-
return isMarkActive(this.view.state, markType, attrs);
|
1182
|
+
get state() {
|
1183
|
+
return this.instance.getState();
|
1027
1184
|
}
|
1028
1185
|
get nodes() {
|
1029
1186
|
return this.instance.nodeBuilders;
|
@@ -1094,32 +1251,117 @@ function defineBaseCommands() {
|
|
1094
1251
|
insertNode,
|
1095
1252
|
wrap,
|
1096
1253
|
setBlockType,
|
1254
|
+
setNodeAttrs,
|
1097
1255
|
selectAll,
|
1098
1256
|
addMark,
|
1099
1257
|
removeMark
|
1100
1258
|
});
|
1101
1259
|
}
|
1102
1260
|
|
1261
|
+
// src/utils/is-element.ts
|
1262
|
+
var hasElement = typeof Element !== "undefined";
|
1263
|
+
function isElement(value) {
|
1264
|
+
return hasElement && value instanceof Element;
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
// src/utils/is-not-null.ts
|
1268
|
+
function isNotNull(value) {
|
1269
|
+
return value != null;
|
1270
|
+
}
|
1271
|
+
|
1103
1272
|
// src/extensions/node-spec.ts
|
1104
1273
|
function defineNodeSpec(options) {
|
1105
|
-
|
1274
|
+
const payload = [options, void 0];
|
1275
|
+
return nodeSpecFacet.extension([payload]);
|
1276
|
+
}
|
1277
|
+
function defineNodeAttr(options) {
|
1278
|
+
const payload = [void 0, options];
|
1279
|
+
return nodeSpecFacet.extension([payload]);
|
1106
1280
|
}
|
1107
1281
|
var nodeSpecFacet = Facet.define({
|
1108
|
-
convert: (
|
1282
|
+
convert: (payloads) => {
|
1109
1283
|
const nodes = {};
|
1110
1284
|
let topNodeName = void 0;
|
1111
|
-
|
1285
|
+
const specPayloads = payloads.map((input) => input[0]).filter(isNotNull);
|
1286
|
+
const attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
|
1287
|
+
for (const { name, topNode, ...spec } of specPayloads) {
|
1112
1288
|
if (nodes[name]) {
|
1113
1289
|
throw new ProseKitError(`Node type ${name} has already been defined`);
|
1114
1290
|
}
|
1115
|
-
if (
|
1291
|
+
if (topNode) {
|
1116
1292
|
topNodeName = name;
|
1117
1293
|
}
|
1118
1294
|
nodes[name] = spec;
|
1119
1295
|
}
|
1296
|
+
for (const {
|
1297
|
+
type,
|
1298
|
+
attr,
|
1299
|
+
default: defaultValue,
|
1300
|
+
toDOM,
|
1301
|
+
parseDOM
|
1302
|
+
} of attrPayloads) {
|
1303
|
+
const spec = nodes[type];
|
1304
|
+
if (!spec) {
|
1305
|
+
throw new ProseKitError(
|
1306
|
+
`Node type ${type} must be defined before defining attributes`
|
1307
|
+
);
|
1308
|
+
}
|
1309
|
+
if (!spec.attrs) {
|
1310
|
+
spec.attrs = {};
|
1311
|
+
}
|
1312
|
+
spec.attrs[attr] = { default: defaultValue };
|
1313
|
+
if (toDOM && spec.toDOM) {
|
1314
|
+
const existingToDom = spec.toDOM;
|
1315
|
+
spec.toDOM = (node) => {
|
1316
|
+
const dom = existingToDom(node);
|
1317
|
+
if (!dom) {
|
1318
|
+
return dom;
|
1319
|
+
}
|
1320
|
+
const attrDOM = toDOM(node.attrs[attr]);
|
1321
|
+
if (!attrDOM) {
|
1322
|
+
return dom;
|
1323
|
+
}
|
1324
|
+
const [key, value] = attrDOM;
|
1325
|
+
if (!key) {
|
1326
|
+
return dom;
|
1327
|
+
}
|
1328
|
+
if (Array.isArray(dom)) {
|
1329
|
+
if (typeof dom[1] === "object") {
|
1330
|
+
return [dom[0], { ...dom[1], [key]: value }, ...dom.slice(2)];
|
1331
|
+
} else {
|
1332
|
+
return [dom[0], { [key]: value }, ...dom.slice(1)];
|
1333
|
+
}
|
1334
|
+
} else if (isElement(dom)) {
|
1335
|
+
dom.setAttribute(key, value);
|
1336
|
+
} else if (typeof dom === "object" && "dom" in dom && isElement(dom.dom)) {
|
1337
|
+
dom.dom.setAttribute(key, value);
|
1338
|
+
}
|
1339
|
+
return dom;
|
1340
|
+
};
|
1341
|
+
}
|
1342
|
+
if (parseDOM && spec.parseDOM) {
|
1343
|
+
for (const rule of spec.parseDOM) {
|
1344
|
+
const existingGetAttrs = rule.getAttrs;
|
1345
|
+
const existingAttrs = rule.attrs;
|
1346
|
+
rule.getAttrs = (dom) => {
|
1347
|
+
var _a;
|
1348
|
+
const attrs = (_a = existingGetAttrs == null ? void 0 : existingGetAttrs(dom)) != null ? _a : existingAttrs;
|
1349
|
+
if (attrs === false || !dom || !isElement(dom)) {
|
1350
|
+
return attrs != null ? attrs : null;
|
1351
|
+
}
|
1352
|
+
const value = parseDOM(dom);
|
1353
|
+
return {
|
1354
|
+
...attrs,
|
1355
|
+
[attr]: value
|
1356
|
+
};
|
1357
|
+
};
|
1358
|
+
}
|
1359
|
+
}
|
1360
|
+
}
|
1120
1361
|
return { nodes, topNode: topNodeName };
|
1121
1362
|
},
|
1122
|
-
next: schemaFacet
|
1363
|
+
next: schemaFacet,
|
1364
|
+
singleton: true
|
1123
1365
|
});
|
1124
1366
|
|
1125
1367
|
// src/extensions/doc.ts
|
@@ -1131,16 +1373,8 @@ function defineDoc() {
|
|
1131
1373
|
});
|
1132
1374
|
}
|
1133
1375
|
|
1134
|
-
// src/extensions/
|
1135
|
-
import {
|
1136
|
-
|
1137
|
-
// src/utils/env.ts
|
1138
|
-
var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
|
1139
|
-
|
1140
|
-
// src/extensions/keymap.ts
|
1141
|
-
import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
|
1142
|
-
import { keydownHandler } from "@prosekit/pm/keymap";
|
1143
|
-
import { Plugin as Plugin3, PluginKey } from "@prosekit/pm/state";
|
1376
|
+
// src/extensions/events/plugin-view.ts
|
1377
|
+
import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
|
1144
1378
|
|
1145
1379
|
// src/extensions/plugin.ts
|
1146
1380
|
import "@prosekit/pm/model";
|
@@ -1158,21 +1392,313 @@ function definePlugin(plugin) {
|
|
1158
1392
|
throw new TypeError("Invalid plugin");
|
1159
1393
|
}
|
1160
1394
|
var pluginFacet = Facet.define({
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1395
|
+
converter: () => {
|
1396
|
+
let inputs = [];
|
1397
|
+
const output = ({ schema }) => {
|
1398
|
+
const plugins = inputs.flatMap((func) => func({ schema }));
|
1164
1399
|
return { plugins };
|
1165
1400
|
};
|
1401
|
+
return {
|
1402
|
+
create: (payloads) => {
|
1403
|
+
inputs = payloads;
|
1404
|
+
return output;
|
1405
|
+
},
|
1406
|
+
update: (payloads) => {
|
1407
|
+
inputs = payloads;
|
1408
|
+
return output;
|
1409
|
+
}
|
1410
|
+
};
|
1166
1411
|
},
|
1167
1412
|
next: stateFacet
|
1168
1413
|
});
|
1169
1414
|
|
1415
|
+
// src/extensions/events/plugin-view.ts
|
1416
|
+
function defineMountHandler(handler) {
|
1417
|
+
return pluginViewFacet.extension([["mount", handler]]);
|
1418
|
+
}
|
1419
|
+
function defineUpdateHandler(handler) {
|
1420
|
+
return pluginViewFacet.extension([["update", handler]]);
|
1421
|
+
}
|
1422
|
+
function defineUnmountHandler(handler) {
|
1423
|
+
return pluginViewFacet.extension([["unmount", handler]]);
|
1424
|
+
}
|
1425
|
+
var pluginViewFacet = Facet.define({
|
1426
|
+
converter: () => {
|
1427
|
+
let mountHandlers = [];
|
1428
|
+
let updateHandlers = [];
|
1429
|
+
let unmountHandlers = [];
|
1430
|
+
const plugin = new ProseMirrorPlugin({
|
1431
|
+
key: pluginKey,
|
1432
|
+
view: (view) => {
|
1433
|
+
mountHandlers.forEach((fn) => fn(view));
|
1434
|
+
return {
|
1435
|
+
update: (view2, prevState) => {
|
1436
|
+
updateHandlers.forEach((fn) => fn(view2, prevState));
|
1437
|
+
},
|
1438
|
+
destroy: () => {
|
1439
|
+
unmountHandlers.forEach((fn) => fn());
|
1440
|
+
}
|
1441
|
+
};
|
1442
|
+
}
|
1443
|
+
});
|
1444
|
+
const pluginFunc = () => [plugin];
|
1445
|
+
const register = (input) => {
|
1446
|
+
mountHandlers = [];
|
1447
|
+
updateHandlers = [];
|
1448
|
+
unmountHandlers = [];
|
1449
|
+
for (const args of input) {
|
1450
|
+
switch (args[0]) {
|
1451
|
+
case "mount":
|
1452
|
+
mountHandlers.push(args[1]);
|
1453
|
+
break;
|
1454
|
+
case "update":
|
1455
|
+
updateHandlers.push(args[1]);
|
1456
|
+
break;
|
1457
|
+
case "unmount":
|
1458
|
+
unmountHandlers.push(args[1]);
|
1459
|
+
break;
|
1460
|
+
}
|
1461
|
+
}
|
1462
|
+
};
|
1463
|
+
return {
|
1464
|
+
create: (input) => {
|
1465
|
+
register(input);
|
1466
|
+
return pluginFunc;
|
1467
|
+
},
|
1468
|
+
update: (input) => {
|
1469
|
+
register(input);
|
1470
|
+
return null;
|
1471
|
+
}
|
1472
|
+
};
|
1473
|
+
},
|
1474
|
+
next: pluginFacet,
|
1475
|
+
singleton: true
|
1476
|
+
});
|
1477
|
+
var pluginKey = new PluginKey("prosekit-plugin-view-handler");
|
1478
|
+
|
1479
|
+
// src/extensions/events/doc-change.ts
|
1480
|
+
function defineDocChangeHandler(handler) {
|
1481
|
+
return defineUpdateHandler((view, prevState) => {
|
1482
|
+
if (!view.state.doc.eq(prevState.doc)) {
|
1483
|
+
handler(view, prevState);
|
1484
|
+
}
|
1485
|
+
});
|
1486
|
+
}
|
1487
|
+
|
1488
|
+
// src/extensions/events/dom-event.ts
|
1489
|
+
import { PluginKey as PluginKey2, ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm/state";
|
1490
|
+
|
1491
|
+
// src/utils/combine-event-handlers.ts
|
1492
|
+
function combineEventHandlers() {
|
1493
|
+
let _handlers = [];
|
1494
|
+
function setHandlers(handlers) {
|
1495
|
+
_handlers = handlers;
|
1496
|
+
}
|
1497
|
+
function combinedEventHandler(...args) {
|
1498
|
+
for (const handler of _handlers) {
|
1499
|
+
if (handler(...args)) {
|
1500
|
+
return true;
|
1501
|
+
}
|
1502
|
+
}
|
1503
|
+
return false;
|
1504
|
+
}
|
1505
|
+
return [setHandlers, combinedEventHandler];
|
1506
|
+
}
|
1507
|
+
|
1508
|
+
// src/utils/group-entries.ts
|
1509
|
+
function groupEntries(entries) {
|
1510
|
+
const map = {};
|
1511
|
+
for (const [key, value] of entries) {
|
1512
|
+
const values = map[key];
|
1513
|
+
if (!values) {
|
1514
|
+
map[key] = [value];
|
1515
|
+
} else {
|
1516
|
+
values.push(value);
|
1517
|
+
}
|
1518
|
+
}
|
1519
|
+
return map;
|
1520
|
+
}
|
1521
|
+
|
1522
|
+
// src/extensions/events/dom-event.ts
|
1523
|
+
function defineDOMEventHandler(event, handler) {
|
1524
|
+
return domEventFacet.extension([
|
1525
|
+
[event, handler]
|
1526
|
+
]);
|
1527
|
+
}
|
1528
|
+
var domEventFacet = Facet.define({
|
1529
|
+
converter: () => {
|
1530
|
+
const setHandlersMap = {};
|
1531
|
+
const combinedHandlerMap = {};
|
1532
|
+
const update = (payloads) => {
|
1533
|
+
let hasNewEvent = false;
|
1534
|
+
for (const [event] of payloads) {
|
1535
|
+
if (!setHandlersMap[event]) {
|
1536
|
+
hasNewEvent = true;
|
1537
|
+
const [setHandlers, combinedHandler] = combineEventHandlers();
|
1538
|
+
setHandlersMap[event] = setHandlers;
|
1539
|
+
combinedHandlerMap[event] = combinedHandler;
|
1540
|
+
}
|
1541
|
+
}
|
1542
|
+
const map = groupEntries(payloads);
|
1543
|
+
for (const [event, handlers] of Object.entries(map)) {
|
1544
|
+
const setHandlers = setHandlersMap[event];
|
1545
|
+
setHandlers(handlers != null ? handlers : []);
|
1546
|
+
}
|
1547
|
+
if (hasNewEvent) {
|
1548
|
+
return new ProseMirrorPlugin2({
|
1549
|
+
key: new PluginKey2("prosekit-dom-event-handler"),
|
1550
|
+
props: { handleDOMEvents: combinedHandlerMap }
|
1551
|
+
});
|
1552
|
+
} else {
|
1553
|
+
return null;
|
1554
|
+
}
|
1555
|
+
};
|
1556
|
+
return {
|
1557
|
+
create: (payloads) => {
|
1558
|
+
const plugin = update(payloads);
|
1559
|
+
return plugin ? () => plugin : () => [];
|
1560
|
+
},
|
1561
|
+
update: (payloads) => {
|
1562
|
+
const plugin = update(payloads);
|
1563
|
+
return plugin ? () => plugin : null;
|
1564
|
+
}
|
1565
|
+
};
|
1566
|
+
},
|
1567
|
+
next: pluginFacet,
|
1568
|
+
singleton: true
|
1569
|
+
});
|
1570
|
+
|
1571
|
+
// src/extensions/events/editor-event.ts
|
1572
|
+
import { PluginKey as PluginKey3, ProseMirrorPlugin as ProseMirrorPlugin3 } from "@prosekit/pm/state";
|
1573
|
+
function defineKeyDownHandler(handler) {
|
1574
|
+
return editorEventFacet.extension([["keyDown", handler]]);
|
1575
|
+
}
|
1576
|
+
function defineKeyPressHandler(handler) {
|
1577
|
+
return editorEventFacet.extension([["keyPress", handler]]);
|
1578
|
+
}
|
1579
|
+
function defineTextInputHandler(handler) {
|
1580
|
+
return editorEventFacet.extension([["textInput", handler]]);
|
1581
|
+
}
|
1582
|
+
function defineClickOnHandler(handler) {
|
1583
|
+
return editorEventFacet.extension([["clickOn", handler]]);
|
1584
|
+
}
|
1585
|
+
function defineClickHandler(handler) {
|
1586
|
+
return editorEventFacet.extension([["click", handler]]);
|
1587
|
+
}
|
1588
|
+
function defineDoubleClickOnHandler(handler) {
|
1589
|
+
return editorEventFacet.extension([["doubleClickOn", handler]]);
|
1590
|
+
}
|
1591
|
+
function defineDoubleClickHandler(handler) {
|
1592
|
+
return editorEventFacet.extension([["doubleClick", handler]]);
|
1593
|
+
}
|
1594
|
+
function defineTripleClickOnHandler(handler) {
|
1595
|
+
return editorEventFacet.extension([["tripleClickOn", handler]]);
|
1596
|
+
}
|
1597
|
+
function defineTripleClickHandler(handler) {
|
1598
|
+
return editorEventFacet.extension([["tripleClick", handler]]);
|
1599
|
+
}
|
1600
|
+
function definePasteHandler(handler) {
|
1601
|
+
return editorEventFacet.extension([["paste", handler]]);
|
1602
|
+
}
|
1603
|
+
function defineDropHandler(handler) {
|
1604
|
+
return editorEventFacet.extension([["drop", handler]]);
|
1605
|
+
}
|
1606
|
+
function defineScrollToSelectionHandler(handler) {
|
1607
|
+
return editorEventFacet.extension([["scrollToSelection", handler]]);
|
1608
|
+
}
|
1609
|
+
var editorEventFacet = Facet.define({
|
1610
|
+
converter: () => {
|
1611
|
+
const [update, plugin] = setupEditorEventPlugin();
|
1612
|
+
return {
|
1613
|
+
create: (entries) => {
|
1614
|
+
update(entries);
|
1615
|
+
return () => plugin;
|
1616
|
+
},
|
1617
|
+
update: (entries) => {
|
1618
|
+
update(entries);
|
1619
|
+
return null;
|
1620
|
+
}
|
1621
|
+
};
|
1622
|
+
},
|
1623
|
+
next: pluginFacet,
|
1624
|
+
singleton: true
|
1625
|
+
});
|
1626
|
+
function setupEditorEventPlugin() {
|
1627
|
+
const [setKeyDownHandlers, handleKeyDown] = combineEventHandlers();
|
1628
|
+
const [setKeyPressHandlers, handleKeyPress] = combineEventHandlers();
|
1629
|
+
const [setTextInputHandlers, handleTextInput] = combineEventHandlers();
|
1630
|
+
const [setClickOnHandlers, handleClickOn] = combineEventHandlers();
|
1631
|
+
const [setClickHandlers, handleClick] = combineEventHandlers();
|
1632
|
+
const [setDoubleClickOnHandlers, handleDoubleClickOn] = combineEventHandlers();
|
1633
|
+
const [setDoubleClickHandlers, handleDoubleClick] = combineEventHandlers();
|
1634
|
+
const [setTripleClickOnHandlers, handleTripleClickOn] = combineEventHandlers();
|
1635
|
+
const [setTripleClickHandlers, handleTripleClick] = combineEventHandlers();
|
1636
|
+
const [setPasteHandlers, handlePaste] = combineEventHandlers();
|
1637
|
+
const [setDropHandlers, handleDrop] = combineEventHandlers();
|
1638
|
+
const [setScrollToSelectionHandlers, handleScrollToSelection] = combineEventHandlers();
|
1639
|
+
const update = (entries) => {
|
1640
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
1641
|
+
const map = groupEntries(entries);
|
1642
|
+
setKeyDownHandlers((_a = map.keyDown) != null ? _a : []);
|
1643
|
+
setKeyPressHandlers((_b = map.keyPress) != null ? _b : []);
|
1644
|
+
setTextInputHandlers((_c = map.textInput) != null ? _c : []);
|
1645
|
+
setClickOnHandlers((_d = map.clickOn) != null ? _d : []);
|
1646
|
+
setClickHandlers((_e = map.click) != null ? _e : []);
|
1647
|
+
setDoubleClickOnHandlers((_f = map.doubleClickOn) != null ? _f : []);
|
1648
|
+
setDoubleClickHandlers((_g = map.doubleClick) != null ? _g : []);
|
1649
|
+
setTripleClickOnHandlers((_h = map.tripleClickOn) != null ? _h : []);
|
1650
|
+
setTripleClickHandlers((_i = map.tripleClick) != null ? _i : []);
|
1651
|
+
setPasteHandlers((_j = map.paste) != null ? _j : []);
|
1652
|
+
setDropHandlers((_k = map.drop) != null ? _k : []);
|
1653
|
+
setScrollToSelectionHandlers((_l = map.scrollToSelection) != null ? _l : []);
|
1654
|
+
};
|
1655
|
+
const plugin = new ProseMirrorPlugin3({
|
1656
|
+
key: new PluginKey3("prosekit-editor-handler"),
|
1657
|
+
props: {
|
1658
|
+
handleKeyDown,
|
1659
|
+
handleKeyPress,
|
1660
|
+
handleTextInput,
|
1661
|
+
handleClickOn,
|
1662
|
+
handleClick,
|
1663
|
+
handleDoubleClickOn,
|
1664
|
+
handleDoubleClick,
|
1665
|
+
handleTripleClickOn,
|
1666
|
+
handleTripleClick,
|
1667
|
+
handlePaste,
|
1668
|
+
handleDrop,
|
1669
|
+
handleScrollToSelection
|
1670
|
+
}
|
1671
|
+
});
|
1672
|
+
return [update, plugin];
|
1673
|
+
}
|
1674
|
+
|
1675
|
+
// src/extensions/events/focus.ts
|
1676
|
+
function defineFocusChangeHandler(handler) {
|
1677
|
+
const handleFocus = () => handler(true);
|
1678
|
+
const handleBlur = () => handler(false);
|
1679
|
+
return domEventFacet.extension([
|
1680
|
+
["focus", handleFocus],
|
1681
|
+
["blur", handleBlur]
|
1682
|
+
]);
|
1683
|
+
}
|
1684
|
+
|
1685
|
+
// src/extensions/history.ts
|
1686
|
+
import { history, redo, undo } from "@prosekit/pm/history";
|
1687
|
+
|
1688
|
+
// src/utils/env.ts
|
1689
|
+
var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
|
1690
|
+
|
1170
1691
|
// src/extensions/keymap.ts
|
1692
|
+
import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
|
1693
|
+
import { keydownHandler } from "@prosekit/pm/keymap";
|
1694
|
+
import { Plugin as Plugin3, PluginKey as PluginKey4 } from "@prosekit/pm/state";
|
1171
1695
|
function defineKeymap(keymap) {
|
1172
1696
|
return keymapFacet.extension([keymap]);
|
1173
1697
|
}
|
1174
|
-
function defineBaseKeymap() {
|
1175
|
-
|
1698
|
+
function defineBaseKeymap(options) {
|
1699
|
+
var _a;
|
1700
|
+
const priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 3 /* low */;
|
1701
|
+
return withPriority(defineKeymap(baseKeymap), priority);
|
1176
1702
|
}
|
1177
1703
|
var keymapFacet = Facet.define({
|
1178
1704
|
converter: () => {
|
@@ -1216,7 +1742,7 @@ function mergeKeymaps(keymaps) {
|
|
1216
1742
|
])
|
1217
1743
|
);
|
1218
1744
|
}
|
1219
|
-
var keymapPluginKey = new
|
1745
|
+
var keymapPluginKey = new PluginKey4("prosekit-keymap");
|
1220
1746
|
|
1221
1747
|
// src/extensions/history.ts
|
1222
1748
|
function defineHistory() {
|
@@ -1237,52 +1763,99 @@ function defineHistory() {
|
|
1237
1763
|
]);
|
1238
1764
|
}
|
1239
1765
|
|
1240
|
-
// src/extensions/input-rules.ts
|
1241
|
-
import { InputRule, inputRules } from "@prosekit/pm/inputrules";
|
1242
|
-
import "@prosekit/pm/model";
|
1243
|
-
import "@prosekit/pm/state";
|
1244
|
-
function defineInputRule(rule) {
|
1245
|
-
if (rule instanceof InputRule) {
|
1246
|
-
return inputRuleFacet.extension([() => rule]);
|
1247
|
-
}
|
1248
|
-
if (Array.isArray(rule) && rule.every((r) => r instanceof InputRule)) {
|
1249
|
-
return inputRuleFacet.extension([() => rule]);
|
1250
|
-
}
|
1251
|
-
if (typeof rule === "function") {
|
1252
|
-
return inputRuleFacet.extension([rule]);
|
1253
|
-
}
|
1254
|
-
throw new TypeError("Invalid input rule");
|
1255
|
-
}
|
1256
|
-
var inputRuleFacet = Facet.define({
|
1257
|
-
convert: (inputs) => {
|
1258
|
-
return (context) => {
|
1259
|
-
const rules = inputs.flatMap((callback) => callback(context));
|
1260
|
-
return [inputRules({ rules })];
|
1261
|
-
};
|
1262
|
-
},
|
1263
|
-
next: pluginFacet
|
1264
|
-
});
|
1265
|
-
|
1266
1766
|
// src/extensions/mark-spec.ts
|
1267
1767
|
function defineMarkSpec(options) {
|
1268
|
-
|
1768
|
+
const payload = [options, void 0];
|
1769
|
+
return markSpecFacet.extension([payload]);
|
1770
|
+
}
|
1771
|
+
function defineMarkAttr(options) {
|
1772
|
+
const payload = [void 0, options];
|
1773
|
+
return markSpecFacet.extension([payload]);
|
1269
1774
|
}
|
1270
1775
|
var markSpecFacet = Facet.define({
|
1271
|
-
convert: (
|
1776
|
+
convert: (payloads) => {
|
1272
1777
|
const marks = {};
|
1273
|
-
|
1778
|
+
const specPayloads = payloads.map((input) => input[0]).filter(isNotNull);
|
1779
|
+
const attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
|
1780
|
+
for (const { name, ...spec } of specPayloads) {
|
1274
1781
|
if (marks[name]) {
|
1275
1782
|
throw new ProseKitError(`Mark type ${name} has already been defined`);
|
1276
1783
|
}
|
1277
1784
|
marks[name] = spec;
|
1278
1785
|
}
|
1786
|
+
for (const {
|
1787
|
+
type,
|
1788
|
+
attr,
|
1789
|
+
default: defaultValue,
|
1790
|
+
toDOM,
|
1791
|
+
parseDOM
|
1792
|
+
} of attrPayloads) {
|
1793
|
+
const spec = marks[type];
|
1794
|
+
if (!spec) {
|
1795
|
+
throw new ProseKitError(
|
1796
|
+
`Mark type ${type} must be defined before defining attributes`
|
1797
|
+
);
|
1798
|
+
}
|
1799
|
+
if (!spec.attrs) {
|
1800
|
+
spec.attrs = {};
|
1801
|
+
}
|
1802
|
+
spec.attrs[attr] = { default: defaultValue };
|
1803
|
+
if (toDOM && spec.toDOM) {
|
1804
|
+
const existingToDom = spec.toDOM;
|
1805
|
+
spec.toDOM = (mark, inline) => {
|
1806
|
+
const dom = existingToDom(mark, inline);
|
1807
|
+
if (!dom) {
|
1808
|
+
return dom;
|
1809
|
+
}
|
1810
|
+
const attrDOM = toDOM(mark.attrs[attr]);
|
1811
|
+
if (!attrDOM) {
|
1812
|
+
return dom;
|
1813
|
+
}
|
1814
|
+
const [key, value] = attrDOM;
|
1815
|
+
if (!key) {
|
1816
|
+
return dom;
|
1817
|
+
}
|
1818
|
+
if (Array.isArray(dom)) {
|
1819
|
+
if (typeof dom[1] === "object") {
|
1820
|
+
return [dom[0], { ...dom[1], [key]: value }, ...dom.slice(2)];
|
1821
|
+
} else {
|
1822
|
+
return [dom[0], { [key]: value }, ...dom.slice(1)];
|
1823
|
+
}
|
1824
|
+
} else if (isElement(dom)) {
|
1825
|
+
dom.setAttribute(key, value);
|
1826
|
+
} else if (typeof dom === "object" && "dom" in dom && isElement(dom.dom)) {
|
1827
|
+
dom.dom.setAttribute(key, value);
|
1828
|
+
}
|
1829
|
+
return dom;
|
1830
|
+
};
|
1831
|
+
}
|
1832
|
+
if (parseDOM && spec.parseDOM) {
|
1833
|
+
for (const rule of spec.parseDOM) {
|
1834
|
+
const existingGetAttrs = rule.getAttrs;
|
1835
|
+
const existingAttrs = rule.attrs;
|
1836
|
+
rule.getAttrs = (dom) => {
|
1837
|
+
var _a;
|
1838
|
+
const attrs = (_a = existingGetAttrs == null ? void 0 : existingGetAttrs(dom)) != null ? _a : existingAttrs;
|
1839
|
+
if (attrs === false || !dom || !isElement(dom)) {
|
1840
|
+
return attrs != null ? attrs : null;
|
1841
|
+
}
|
1842
|
+
const value = parseDOM(dom);
|
1843
|
+
return {
|
1844
|
+
...attrs,
|
1845
|
+
[attr]: value
|
1846
|
+
};
|
1847
|
+
};
|
1848
|
+
}
|
1849
|
+
}
|
1850
|
+
}
|
1279
1851
|
return { marks, nodes: {} };
|
1280
1852
|
},
|
1281
|
-
next: schemaFacet
|
1853
|
+
next: schemaFacet,
|
1854
|
+
singleton: true
|
1282
1855
|
});
|
1283
1856
|
|
1284
1857
|
// src/extensions/node-view.ts
|
1285
|
-
import { ProseMirrorPlugin } from "@prosekit/pm/state";
|
1858
|
+
import { ProseMirrorPlugin as ProseMirrorPlugin4 } from "@prosekit/pm/state";
|
1286
1859
|
import "@prosekit/pm/view";
|
1287
1860
|
function defineNodeView(options) {
|
1288
1861
|
return nodeViewFacet.extension([options]);
|
@@ -1295,18 +1868,18 @@ var nodeViewFacet = Facet.define({
|
|
1295
1868
|
nodeViews[input.name] = input.constructor;
|
1296
1869
|
}
|
1297
1870
|
}
|
1298
|
-
return () => [new
|
1871
|
+
return () => [new ProseMirrorPlugin4({ props: { nodeViews } })];
|
1299
1872
|
},
|
1300
1873
|
next: pluginFacet
|
1301
1874
|
});
|
1302
1875
|
|
1303
1876
|
// src/extensions/node-view-effect.ts
|
1304
|
-
import { ProseMirrorPlugin as
|
1877
|
+
import { ProseMirrorPlugin as ProseMirrorPlugin5 } from "@prosekit/pm/state";
|
1305
1878
|
import "@prosekit/pm/view";
|
1306
|
-
function
|
1307
|
-
return
|
1879
|
+
function defineNodeViewFactory(options) {
|
1880
|
+
return nodeViewFactoryFacet.extension([options]);
|
1308
1881
|
}
|
1309
|
-
var
|
1882
|
+
var nodeViewFactoryFacet = Facet.define({
|
1310
1883
|
convert: (inputs) => {
|
1311
1884
|
const nodeViews = {};
|
1312
1885
|
const options = {};
|
@@ -1329,7 +1902,7 @@ var nodeViewEffectFacet = Facet.define({
|
|
1329
1902
|
nodeViews[name] = factory(args);
|
1330
1903
|
}
|
1331
1904
|
}
|
1332
|
-
return () =>
|
1905
|
+
return () => [new ProseMirrorPlugin5({ props: { nodeViews } })];
|
1333
1906
|
},
|
1334
1907
|
next: pluginFacet
|
1335
1908
|
});
|
@@ -1358,92 +1931,122 @@ function defineText() {
|
|
1358
1931
|
});
|
1359
1932
|
}
|
1360
1933
|
|
1361
|
-
// src/
|
1362
|
-
import
|
1934
|
+
// src/utils/clsx.ts
|
1935
|
+
import clsxLite from "clsx/lite";
|
1936
|
+
var clsx = clsxLite;
|
1363
1937
|
|
1364
|
-
// src/utils/
|
1365
|
-
function
|
1366
|
-
|
1938
|
+
// src/utils/default-block-at.ts
|
1939
|
+
function defaultBlockAt(match) {
|
1940
|
+
for (let i = 0; i < match.edgeCount; i++) {
|
1941
|
+
const { type } = match.edge(i);
|
1942
|
+
if (type.isTextblock && !type.hasRequiredAttrs())
|
1943
|
+
return type;
|
1944
|
+
}
|
1945
|
+
return null;
|
1367
1946
|
}
|
1368
1947
|
|
1369
|
-
// src/
|
1370
|
-
|
1371
|
-
|
1948
|
+
// src/utils/get-id.ts
|
1949
|
+
var id = 0;
|
1950
|
+
function getId() {
|
1951
|
+
id = (id + 1) % Number.MAX_SAFE_INTEGER;
|
1952
|
+
return `id:${id}`;
|
1953
|
+
}
|
1954
|
+
|
1955
|
+
// src/utils/is-in-code-block.ts
|
1956
|
+
function isCodeBlockType(type) {
|
1957
|
+
return type.spec.code && type.isBlock;
|
1958
|
+
}
|
1959
|
+
function isInCodeBlock(selection) {
|
1960
|
+
return isCodeBlockType(selection.$from.parent.type) || isCodeBlockType(selection.$to.parent.type);
|
1961
|
+
}
|
1962
|
+
|
1963
|
+
// src/utils/unicode.ts
|
1964
|
+
var OBJECT_REPLACEMENT_CHARACTER = "\uFFFC";
|
1965
|
+
|
1966
|
+
// src/utils/with-skip-code-block.ts
|
1967
|
+
function withSkipCodeBlock(command) {
|
1968
|
+
return (state, dispatch, view) => {
|
1969
|
+
if (isInCodeBlock(state.selection)) {
|
1970
|
+
return false;
|
1971
|
+
}
|
1972
|
+
return command(state, dispatch, view);
|
1973
|
+
};
|
1372
1974
|
}
|
1373
|
-
var updateHandlerFacet = Facet.define({
|
1374
|
-
converter: () => {
|
1375
|
-
let updateHandlers = [];
|
1376
|
-
const plugin = new ProseMirrorPlugin3({
|
1377
|
-
key: pluginKey,
|
1378
|
-
view: (view) => {
|
1379
|
-
updateHandlers.forEach((fn) => fn({ view }));
|
1380
|
-
return {
|
1381
|
-
update: (view2, prevState) => {
|
1382
|
-
updateHandlers.forEach((fn) => fn({ view: view2, prevState }));
|
1383
|
-
}
|
1384
|
-
};
|
1385
|
-
}
|
1386
|
-
});
|
1387
|
-
const pluginFunc = () => [plugin];
|
1388
|
-
return {
|
1389
|
-
create: (handlers) => {
|
1390
|
-
updateHandlers = handlers.filter(isNotNull);
|
1391
|
-
return pluginFunc;
|
1392
|
-
},
|
1393
|
-
update: (handlers) => {
|
1394
|
-
updateHandlers = handlers.filter(isNotNull);
|
1395
|
-
return null;
|
1396
|
-
}
|
1397
|
-
};
|
1398
|
-
},
|
1399
|
-
next: pluginFacet,
|
1400
|
-
singleton: true
|
1401
|
-
});
|
1402
|
-
var pluginKey = new PluginKey2("prosekit-event-handler");
|
1403
1975
|
export {
|
1404
1976
|
Editor,
|
1977
|
+
EditorNotFoundError,
|
1405
1978
|
Facet,
|
1979
|
+
OBJECT_REPLACEMENT_CHARACTER,
|
1406
1980
|
Priority,
|
1407
1981
|
ProseKitError,
|
1982
|
+
getId as _getId,
|
1408
1983
|
addMark,
|
1984
|
+
clsx,
|
1409
1985
|
createEditor,
|
1986
|
+
defaultBlockAt,
|
1410
1987
|
defineBaseCommands,
|
1411
1988
|
defineBaseKeymap,
|
1989
|
+
defineClickHandler,
|
1990
|
+
defineClickOnHandler,
|
1412
1991
|
defineCommands,
|
1992
|
+
defineDOMEventHandler,
|
1413
1993
|
defineDefaultState,
|
1414
1994
|
defineDoc,
|
1995
|
+
defineDocChangeHandler,
|
1996
|
+
defineDoubleClickHandler,
|
1997
|
+
defineDoubleClickOnHandler,
|
1998
|
+
defineDropHandler,
|
1999
|
+
defineFocusChangeHandler,
|
1415
2000
|
defineHistory,
|
1416
|
-
|
2001
|
+
defineKeyDownHandler,
|
2002
|
+
defineKeyPressHandler,
|
1417
2003
|
defineKeymap,
|
2004
|
+
defineMarkAttr,
|
1418
2005
|
defineMarkSpec,
|
2006
|
+
defineMountHandler,
|
2007
|
+
defineNodeAttr,
|
1419
2008
|
defineNodeSpec,
|
1420
2009
|
defineNodeView,
|
1421
|
-
|
2010
|
+
defineNodeViewFactory,
|
1422
2011
|
defineParagraph,
|
2012
|
+
definePasteHandler,
|
1423
2013
|
definePlugin,
|
2014
|
+
defineScrollToSelectionHandler,
|
1424
2015
|
defineText,
|
2016
|
+
defineTextInputHandler,
|
2017
|
+
defineTripleClickHandler,
|
2018
|
+
defineTripleClickOnHandler,
|
2019
|
+
defineUnmountHandler,
|
1425
2020
|
defineUpdateHandler,
|
2021
|
+
elementFromJSON,
|
2022
|
+
elementFromNode,
|
2023
|
+
expandMark,
|
1426
2024
|
getMarkType,
|
1427
2025
|
getNodeType,
|
2026
|
+
htmlFromJSON,
|
2027
|
+
htmlFromNode,
|
1428
2028
|
insertNode,
|
1429
2029
|
isAllSelection,
|
2030
|
+
isInCodeBlock,
|
1430
2031
|
isMark,
|
1431
2032
|
isNodeSelection,
|
1432
2033
|
isProseMirrorNode,
|
1433
2034
|
isTextSelection,
|
1434
|
-
jsonFromElement,
|
1435
2035
|
jsonFromHTML,
|
1436
2036
|
jsonFromNode,
|
1437
2037
|
jsonFromState,
|
2038
|
+
keymapFacet,
|
1438
2039
|
nodeFromElement,
|
1439
2040
|
nodeFromHTML,
|
1440
2041
|
nodeFromJSON,
|
1441
2042
|
pluginFacet,
|
1442
2043
|
removeMark,
|
1443
2044
|
setBlockType,
|
2045
|
+
setNodeAttrs,
|
1444
2046
|
stateFromJSON,
|
1445
2047
|
toggleMark,
|
1446
2048
|
toggleNode,
|
1447
2049
|
union,
|
1448
|
-
withPriority
|
2050
|
+
withPriority,
|
2051
|
+
withSkipCodeBlock
|
1449
2052
|
};
|