@prosekit/core 0.0.11 → 0.0.13
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 +189 -190
- package/dist/prosekit-core.d.ts +19 -20
- package/dist/prosekit-core.js +205 -220
- package/dist/style.css +4 -1
- package/package.json +3 -3
- package/src/index.ts +24 -17
package/dist/prosekit-core.js
CHANGED
@@ -134,9 +134,6 @@ import { EditorView } from "@prosekit/pm/view";
|
|
134
134
|
// src/extensions/default-state.ts
|
135
135
|
import { Selection } from "@prosekit/pm/state";
|
136
136
|
|
137
|
-
// src/editor/slots.ts
|
138
|
-
import OrderedMap from "orderedmap";
|
139
|
-
|
140
137
|
// src/utils/uniq-array.ts
|
141
138
|
function uniqPush(prev, next) {
|
142
139
|
const result = [...prev];
|
@@ -158,115 +155,50 @@ function uniqRemove(prev, next) {
|
|
158
155
|
return result;
|
159
156
|
}
|
160
157
|
|
161
|
-
// src/
|
162
|
-
var
|
158
|
+
// src/facets/facet.ts
|
159
|
+
var facetCount = 0;
|
160
|
+
function getFacetCount() {
|
161
|
+
return facetCount;
|
162
|
+
}
|
163
163
|
var Facet = class _Facet {
|
164
|
-
constructor(
|
164
|
+
constructor(converter, next) {
|
165
165
|
/** @internal */
|
166
|
-
this.index =
|
167
|
-
this.
|
166
|
+
this.index = facetCount++;
|
167
|
+
this.converter = converter;
|
168
168
|
this.next = next;
|
169
|
-
this.single = single;
|
170
169
|
}
|
171
170
|
static define({
|
172
|
-
|
173
|
-
|
174
|
-
next
|
175
|
-
single
|
171
|
+
converter,
|
172
|
+
convert,
|
173
|
+
next
|
176
174
|
}) {
|
177
|
-
const
|
178
|
-
create:
|
179
|
-
update:
|
175
|
+
const converterFunction = converter ? converter : convert ? () => ({
|
176
|
+
create: convert,
|
177
|
+
update: convert
|
180
178
|
}) : null;
|
181
|
-
if (!
|
182
|
-
throw new ProseKitError(
|
183
|
-
"Facet must have either 'slot' or 'combine' option"
|
184
|
-
);
|
179
|
+
if (!converterFunction) {
|
180
|
+
throw new ProseKitError("Facet must have either 'convert' or 'converter'");
|
185
181
|
}
|
186
|
-
return new _Facet(
|
182
|
+
return new _Facet(converterFunction, next);
|
187
183
|
}
|
188
184
|
/** @internal */
|
189
|
-
static
|
185
|
+
static defineRootFacet(options) {
|
190
186
|
return _Facet.define(options);
|
191
187
|
}
|
192
|
-
extension(
|
193
|
-
return new FacetExtension(this,
|
188
|
+
extension(payloads) {
|
189
|
+
return new FacetExtension(this, payloads);
|
194
190
|
}
|
195
191
|
};
|
196
192
|
var FacetExtension = class {
|
197
|
-
constructor(facet,
|
193
|
+
constructor(facet, payloads) {
|
198
194
|
this.facet = facet;
|
199
|
-
this.
|
195
|
+
this.payloads = payloads;
|
200
196
|
}
|
201
197
|
};
|
202
|
-
function sortFacets(unsorted) {
|
203
|
-
var _a;
|
204
|
-
const facets = unsorted.filter((val) => val);
|
205
|
-
const facetMap = [];
|
206
|
-
const inbounds = [];
|
207
|
-
let facetCount = 0;
|
208
|
-
for (const facet of facets) {
|
209
|
-
const index = facet.index;
|
210
|
-
if (facetMap[index] != null) {
|
211
|
-
continue;
|
212
|
-
}
|
213
|
-
if (inbounds[index] == null) {
|
214
|
-
inbounds[index] = 0;
|
215
|
-
}
|
216
|
-
facetCount++;
|
217
|
-
facetMap[index] = facet;
|
218
|
-
if (facet.next) {
|
219
|
-
const nextIndex2 = facet.next.index;
|
220
|
-
if (inbounds[nextIndex2] == null) {
|
221
|
-
inbounds[nextIndex2] = 0;
|
222
|
-
}
|
223
|
-
inbounds[nextIndex2] += 1;
|
224
|
-
if (facetMap[nextIndex2] == null) {
|
225
|
-
facets.push(facet.next);
|
226
|
-
}
|
227
|
-
}
|
228
|
-
}
|
229
|
-
const sortedFacets = [];
|
230
|
-
const sortedIndexes = [];
|
231
|
-
inbounds.forEach((inbound, index) => {
|
232
|
-
if (inbound === 0) {
|
233
|
-
sortedIndexes.push(index);
|
234
|
-
}
|
235
|
-
});
|
236
|
-
for (const index of sortedIndexes) {
|
237
|
-
const facet = facetMap[index];
|
238
|
-
sortedFacets.push(facet);
|
239
|
-
const nextIndex2 = (_a = facet.next) == null ? void 0 : _a.index;
|
240
|
-
if (nextIndex2 == null)
|
241
|
-
continue;
|
242
|
-
inbounds[nextIndex2] -= 1;
|
243
|
-
if (inbounds[nextIndex2] === 0) {
|
244
|
-
sortedIndexes.push(nextIndex2);
|
245
|
-
}
|
246
|
-
}
|
247
|
-
if (facetCount !== sortedFacets.length) {
|
248
|
-
throw new ProseKitError(`Facet has circular dependency`);
|
249
|
-
}
|
250
|
-
return sortedFacets;
|
251
|
-
}
|
252
198
|
|
253
|
-
// src/
|
254
|
-
var
|
255
|
-
|
256
|
-
var _a;
|
257
|
-
let nodes = OrderedMap.from({});
|
258
|
-
let marks = OrderedMap.from({});
|
259
|
-
let topNode = void 0;
|
260
|
-
for (const spec of specs) {
|
261
|
-
nodes = nodes.append(spec.nodes);
|
262
|
-
marks = marks.append((_a = spec.marks) != null ? _a : {});
|
263
|
-
topNode = topNode != null ? topNode : spec.topNode;
|
264
|
-
}
|
265
|
-
return { nodes, marks, topNode };
|
266
|
-
}
|
267
|
-
});
|
268
|
-
var stateSlot = Facet.defineSlot({
|
269
|
-
combine: (callbacks) => {
|
199
|
+
// src/facets/state.ts
|
200
|
+
var stateFacet = Facet.defineRootFacet({
|
201
|
+
convert: (callbacks) => {
|
270
202
|
return (ctx) => {
|
271
203
|
var _a, _b, _c, _d, _e, _f;
|
272
204
|
const configs = callbacks.map((cb) => cb(ctx));
|
@@ -294,20 +226,10 @@ var stateSlot = Facet.defineSlot({
|
|
294
226
|
};
|
295
227
|
}
|
296
228
|
});
|
297
|
-
var viewSlot = Facet.defineSlot({
|
298
|
-
combine: (props) => {
|
299
|
-
return Object.assign({}, ...props);
|
300
|
-
}
|
301
|
-
});
|
302
|
-
var commandSlot = Facet.defineSlot({
|
303
|
-
combine: (inputs) => {
|
304
|
-
return Object.assign({}, ...inputs);
|
305
|
-
}
|
306
|
-
});
|
307
229
|
|
308
230
|
// src/extensions/default-state.ts
|
309
|
-
function
|
310
|
-
return
|
231
|
+
function defineDefaultState(options) {
|
232
|
+
return stateFacet.extension([
|
311
233
|
({ schema }) => {
|
312
234
|
const config = {};
|
313
235
|
if (options.doc) {
|
@@ -417,6 +339,37 @@ function isNodeChild(value) {
|
|
417
339
|
return typeof value === "string" || Array.isArray(value) || isProseMirrorNode(value);
|
418
340
|
}
|
419
341
|
|
342
|
+
// src/facets/command.ts
|
343
|
+
var commandFacet = Facet.defineRootFacet({
|
344
|
+
convert: (inputs) => {
|
345
|
+
return Object.assign({}, ...inputs);
|
346
|
+
}
|
347
|
+
});
|
348
|
+
|
349
|
+
// src/facets/schema.ts
|
350
|
+
import OrderedMap from "orderedmap";
|
351
|
+
var schemaFacet = Facet.defineRootFacet({
|
352
|
+
convert: (specs) => {
|
353
|
+
var _a;
|
354
|
+
let nodes = OrderedMap.from({});
|
355
|
+
let marks = OrderedMap.from({});
|
356
|
+
let topNode = void 0;
|
357
|
+
for (const spec of specs) {
|
358
|
+
nodes = nodes.append(spec.nodes);
|
359
|
+
marks = marks.append((_a = spec.marks) != null ? _a : {});
|
360
|
+
topNode = topNode != null ? topNode : spec.topNode;
|
361
|
+
}
|
362
|
+
return { nodes, marks, topNode };
|
363
|
+
}
|
364
|
+
});
|
365
|
+
|
366
|
+
// src/facets/view.ts
|
367
|
+
var viewFacet = Facet.defineRootFacet({
|
368
|
+
convert: (props) => {
|
369
|
+
return Object.assign({}, ...props);
|
370
|
+
}
|
371
|
+
});
|
372
|
+
|
420
373
|
// src/types/priority.ts
|
421
374
|
var Priority = /* @__PURE__ */ ((Priority2) => {
|
422
375
|
Priority2[Priority2["lowest"] = 4] = "lowest";
|
@@ -472,7 +425,7 @@ function extractFacets(root) {
|
|
472
425
|
const extensions = [root];
|
473
426
|
const priorities = [2 /* default */];
|
474
427
|
const facets = [];
|
475
|
-
const
|
428
|
+
const payloads = [];
|
476
429
|
while (extensions.length > 0) {
|
477
430
|
const ext = extensions.pop();
|
478
431
|
const pri = priorities.pop();
|
@@ -480,10 +433,10 @@ function extractFacets(root) {
|
|
480
433
|
const facet = ext.facet;
|
481
434
|
if (!facets[facet.index]) {
|
482
435
|
facets[facet.index] = facet;
|
483
|
-
|
436
|
+
payloads[facet.index] = [[], [], [], [], []];
|
484
437
|
}
|
485
|
-
const
|
486
|
-
|
438
|
+
const facetPayloads = ext.payloads;
|
439
|
+
payloads[facet.index][pri].push(...facetPayloads);
|
487
440
|
} else if (ext.extension) {
|
488
441
|
const p = (_a = ext.priority) != null ? _a : pri;
|
489
442
|
if (Array.isArray(ext.extension)) {
|
@@ -499,25 +452,31 @@ function extractFacets(root) {
|
|
499
452
|
throw new ProseKitError("Invalid extension");
|
500
453
|
}
|
501
454
|
}
|
502
|
-
return [facets,
|
455
|
+
return [facets, payloads];
|
503
456
|
}
|
504
|
-
function updateExtension(prevInputs,
|
457
|
+
function updateExtension(prevInputs, prevConverters, extension, mode) {
|
458
|
+
var _a;
|
505
459
|
const modifyInputTuple = mode === "add" ? mergeInputTuple : removeInputTuple;
|
506
460
|
const [facets, inputs] = extractFacets(extension);
|
507
461
|
let schemaInput = null;
|
508
462
|
let stateInput = null;
|
509
463
|
let viewInput = null;
|
510
464
|
let commandInput = null;
|
511
|
-
for (
|
465
|
+
for (let index = getFacetCount(); index >= 0; index--) {
|
466
|
+
const facet = facets[index];
|
467
|
+
if (!facet) {
|
468
|
+
continue;
|
469
|
+
}
|
470
|
+
const nextFacet = facet.next;
|
471
|
+
if (nextFacet) {
|
472
|
+
facets[_a = nextFacet.index] || (facets[_a] = nextFacet);
|
473
|
+
}
|
512
474
|
if (!inputs[facet.index]) {
|
513
475
|
continue;
|
514
476
|
}
|
515
|
-
const inputTuple = modifyInputTuple(
|
516
|
-
|
517
|
-
|
518
|
-
);
|
519
|
-
prevInputs[facet.index] = inputTuple;
|
520
|
-
if (facet.next && !facet.single) {
|
477
|
+
const inputTuple = modifyInputTuple(prevInputs[index], inputs[index]);
|
478
|
+
prevInputs[index] = inputTuple;
|
479
|
+
if (facet.next) {
|
521
480
|
let hasOutput = false;
|
522
481
|
const outputTuple = [[], [], [], [], []];
|
523
482
|
for (let pri = 0; pri < 5; pri++) {
|
@@ -525,17 +484,17 @@ function updateExtension(prevInputs, prevSlots, extension, mode) {
|
|
525
484
|
if (inputArray.length === 0) {
|
526
485
|
continue;
|
527
486
|
}
|
528
|
-
const
|
487
|
+
const converterTuple = prevConverters[index] || (prevConverters[index] = [
|
529
488
|
void 0,
|
530
489
|
void 0,
|
531
490
|
void 0,
|
532
491
|
void 0,
|
533
492
|
void 0
|
534
493
|
]);
|
535
|
-
const
|
536
|
-
const
|
537
|
-
|
538
|
-
const output =
|
494
|
+
const prevConverter = converterTuple[pri];
|
495
|
+
const converter = prevConverter || facet.converter();
|
496
|
+
prevConverters[index][pri] = converter;
|
497
|
+
const output = prevConverter ? converter.update(inputArray) : converter.create(inputArray);
|
539
498
|
if (!output) {
|
540
499
|
continue;
|
541
500
|
}
|
@@ -552,44 +511,35 @@ function updateExtension(prevInputs, prevSlots, extension, mode) {
|
|
552
511
|
continue;
|
553
512
|
} else {
|
554
513
|
const inputArray = flattenInputTuple(inputTuple);
|
555
|
-
const
|
514
|
+
const converterTuple = prevConverters[index] || (prevConverters[index] = [
|
556
515
|
void 0,
|
557
516
|
void 0,
|
558
517
|
void 0,
|
559
518
|
void 0,
|
560
519
|
void 0
|
561
520
|
]);
|
562
|
-
const
|
563
|
-
const
|
564
|
-
|
565
|
-
const output =
|
521
|
+
const prevConverter = converterTuple[2 /* default */];
|
522
|
+
const converter = prevConverter || facet.converter();
|
523
|
+
prevConverters[index][2 /* default */] = converter;
|
524
|
+
const output = prevConverter ? converter.update(inputArray) : converter.create(inputArray);
|
566
525
|
if (!output) {
|
567
526
|
continue;
|
568
527
|
}
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
case viewSlot:
|
585
|
-
viewInput = output;
|
586
|
-
break;
|
587
|
-
case commandSlot:
|
588
|
-
commandInput = output;
|
589
|
-
break;
|
590
|
-
default:
|
591
|
-
throw new ProseKitError("Invalid facet");
|
592
|
-
}
|
528
|
+
switch (facet) {
|
529
|
+
case schemaFacet:
|
530
|
+
schemaInput = output;
|
531
|
+
break;
|
532
|
+
case stateFacet:
|
533
|
+
stateInput = output;
|
534
|
+
break;
|
535
|
+
case viewFacet:
|
536
|
+
viewInput = output;
|
537
|
+
break;
|
538
|
+
case commandFacet:
|
539
|
+
commandInput = output;
|
540
|
+
break;
|
541
|
+
default:
|
542
|
+
throw new ProseKitError("Invalid root facet");
|
593
543
|
}
|
594
544
|
}
|
595
545
|
}
|
@@ -597,7 +547,7 @@ function updateExtension(prevInputs, prevSlots, extension, mode) {
|
|
597
547
|
}
|
598
548
|
|
599
549
|
// src/editor/type-utils.ts
|
600
|
-
function
|
550
|
+
function union(extension) {
|
601
551
|
if (extension && Array.isArray(extension)) {
|
602
552
|
return { extension };
|
603
553
|
}
|
@@ -611,9 +561,9 @@ function createEditor({
|
|
611
561
|
defaultSelection
|
612
562
|
}) {
|
613
563
|
if (defaultDoc) {
|
614
|
-
extension =
|
564
|
+
extension = union([
|
615
565
|
extension,
|
616
|
-
|
566
|
+
defineDefaultState({
|
617
567
|
doc: defaultDoc,
|
618
568
|
selection: defaultSelection
|
619
569
|
})
|
@@ -625,11 +575,11 @@ var EditorInstance = class {
|
|
625
575
|
constructor(extension) {
|
626
576
|
this.view = null;
|
627
577
|
this.commandAppliers = {};
|
628
|
-
this.
|
629
|
-
this.
|
578
|
+
this.payloads = [];
|
579
|
+
this.converters = [];
|
630
580
|
this.mount = this.mount.bind(this);
|
631
581
|
this.unmount = this.unmount.bind(this);
|
632
|
-
const { schemaInput, stateInput, viewInput, commandInput } = updateExtension(this.
|
582
|
+
const { schemaInput, stateInput, viewInput, commandInput } = updateExtension(this.payloads, this.converters, extension, "add");
|
633
583
|
if (!schemaInput) {
|
634
584
|
throw new ProseKitError("Schema must be defined");
|
635
585
|
}
|
@@ -638,7 +588,7 @@ var EditorInstance = class {
|
|
638
588
|
const state = EditorState.create(stateConfig);
|
639
589
|
if (commandInput) {
|
640
590
|
for (const [name, commandCreator] of Object.entries(commandInput)) {
|
641
|
-
this.
|
591
|
+
this.defineCommand(name, commandCreator);
|
642
592
|
}
|
643
593
|
}
|
644
594
|
this.directEditorProps = { state, ...viewInput };
|
@@ -662,7 +612,7 @@ var EditorInstance = class {
|
|
662
612
|
}
|
663
613
|
updateExtension(extension, mode) {
|
664
614
|
var _a;
|
665
|
-
const { schemaInput, stateInput, viewInput, commandInput } = updateExtension(this.
|
615
|
+
const { schemaInput, stateInput, viewInput, commandInput } = updateExtension(this.payloads, this.converters, extension, mode);
|
666
616
|
if (schemaInput) {
|
667
617
|
throw new ProseKitError("Schema cannot be changed");
|
668
618
|
}
|
@@ -682,7 +632,7 @@ var EditorInstance = class {
|
|
682
632
|
if (commandInput) {
|
683
633
|
const names = Object.keys(commandInput);
|
684
634
|
for (const name of names) {
|
685
|
-
this.
|
635
|
+
this.defineCommand(name, commandInput[name]);
|
686
636
|
}
|
687
637
|
}
|
688
638
|
}
|
@@ -703,11 +653,12 @@ var EditorInstance = class {
|
|
703
653
|
this.view = null;
|
704
654
|
}
|
705
655
|
get assertView() {
|
706
|
-
if (!this.view)
|
656
|
+
if (!this.view) {
|
707
657
|
throw new ProseKitError("Editor is not mounted");
|
658
|
+
}
|
708
659
|
return this.view;
|
709
660
|
}
|
710
|
-
|
661
|
+
definePlugins(plugins) {
|
711
662
|
const view = this.assertView;
|
712
663
|
const state = view.state;
|
713
664
|
const newPlugins = [...plugins, ...state.plugins];
|
@@ -723,7 +674,7 @@ var EditorInstance = class {
|
|
723
674
|
const newState = state.reconfigure({ plugins: newPlugins });
|
724
675
|
view.setProps({ state: newState });
|
725
676
|
}
|
726
|
-
|
677
|
+
defineCommand(name, commandCreator) {
|
727
678
|
const applier = (...args) => {
|
728
679
|
const view = this.view;
|
729
680
|
if (!view) {
|
@@ -828,11 +779,11 @@ function withPriority(extension, priority) {
|
|
828
779
|
import "@prosekit/pm/model";
|
829
780
|
import { AllSelection } from "@prosekit/pm/state";
|
830
781
|
import { findWrapping, insertPoint } from "@prosekit/pm/transform";
|
831
|
-
function
|
832
|
-
return
|
782
|
+
function defineCommands(commands) {
|
783
|
+
return commandFacet.extension([commands]);
|
833
784
|
}
|
834
|
-
function
|
835
|
-
return
|
785
|
+
function defineBaseCommands() {
|
786
|
+
return defineCommands({
|
836
787
|
insertText: ({
|
837
788
|
text,
|
838
789
|
from,
|
@@ -900,11 +851,11 @@ function addBaseCommands() {
|
|
900
851
|
}
|
901
852
|
|
902
853
|
// src/extensions/node-spec.ts
|
903
|
-
function
|
854
|
+
function defineNodeSpec(options) {
|
904
855
|
return nodeSpecFacet.extension([options]);
|
905
856
|
}
|
906
857
|
var nodeSpecFacet = Facet.define({
|
907
|
-
|
858
|
+
convert: (options) => {
|
908
859
|
const nodes = {};
|
909
860
|
let topNodeName = void 0;
|
910
861
|
for (const { name, topNode, ...spec } of options) {
|
@@ -918,12 +869,12 @@ var nodeSpecFacet = Facet.define({
|
|
918
869
|
}
|
919
870
|
return { nodes, topNode: topNodeName };
|
920
871
|
},
|
921
|
-
next:
|
872
|
+
next: schemaFacet
|
922
873
|
});
|
923
874
|
|
924
875
|
// src/extensions/doc.ts
|
925
|
-
function
|
926
|
-
return
|
876
|
+
function defineDoc() {
|
877
|
+
return defineNodeSpec({
|
927
878
|
name: "doc",
|
928
879
|
content: "block+"
|
929
880
|
});
|
@@ -939,7 +890,7 @@ function voidFunction() {
|
|
939
890
|
// src/extensions/plugin.ts
|
940
891
|
import "@prosekit/pm/model";
|
941
892
|
import { Plugin as Plugin2 } from "@prosekit/pm/state";
|
942
|
-
function
|
893
|
+
function definePlugin(plugin) {
|
943
894
|
if (plugin instanceof Plugin2) {
|
944
895
|
return pluginFacet.extension([() => [plugin]]);
|
945
896
|
}
|
@@ -952,27 +903,28 @@ function addPlugin(plugin) {
|
|
952
903
|
throw new TypeError("Invalid plugin");
|
953
904
|
}
|
954
905
|
var pluginFacet = Facet.define({
|
955
|
-
|
906
|
+
convert: (callbacks) => {
|
956
907
|
return ({ schema }) => {
|
957
908
|
const plugins = callbacks.flatMap((func) => func({ schema }));
|
958
909
|
return { plugins };
|
959
910
|
};
|
960
911
|
},
|
961
|
-
next:
|
912
|
+
next: stateFacet
|
962
913
|
});
|
963
914
|
|
964
915
|
// src/extensions/event-handler.ts
|
965
|
-
function
|
916
|
+
function defineEventHandler(options) {
|
966
917
|
var _a;
|
967
918
|
const updateHandler = (_a = options == null ? void 0 : options.update) != null ? _a : voidFunction;
|
968
919
|
return eventFacet.extension([updateHandler]);
|
969
920
|
}
|
970
921
|
var eventFacet = Facet.define({
|
971
|
-
|
922
|
+
converter: () => {
|
972
923
|
let updateHandlers = [];
|
973
924
|
const plugin = new ProseMirrorPlugin({
|
974
925
|
key: pluginKey,
|
975
926
|
view: () => {
|
927
|
+
updateHandlers.forEach((fn) => fn());
|
976
928
|
return {
|
977
929
|
update: (_view, _prevState) => {
|
978
930
|
updateHandlers.forEach((fn) => fn());
|
@@ -992,8 +944,7 @@ var eventFacet = Facet.define({
|
|
992
944
|
}
|
993
945
|
};
|
994
946
|
},
|
995
|
-
next: pluginFacet
|
996
|
-
single: true
|
947
|
+
next: pluginFacet
|
997
948
|
});
|
998
949
|
var pluginKey = new PluginKey("prosekit-event-handler");
|
999
950
|
|
@@ -1007,14 +958,14 @@ var isMac = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigat
|
|
1007
958
|
import { baseKeymap, chainCommands } from "@prosekit/pm/commands";
|
1008
959
|
import { keydownHandler } from "@prosekit/pm/keymap";
|
1009
960
|
import { Plugin as Plugin3, PluginKey as PluginKey2 } from "@prosekit/pm/state";
|
1010
|
-
function
|
961
|
+
function defineKeymap(keymap) {
|
1011
962
|
return keymapFacet.extension([keymap]);
|
1012
963
|
}
|
1013
|
-
function
|
1014
|
-
return
|
964
|
+
function defineBaseKeymap() {
|
965
|
+
return defineKeymap(baseKeymap);
|
1015
966
|
}
|
1016
967
|
var keymapFacet = Facet.define({
|
1017
|
-
|
968
|
+
converter: () => {
|
1018
969
|
let handler = null;
|
1019
970
|
const handlerWrapper = (view, event) => {
|
1020
971
|
if (handler)
|
@@ -1037,8 +988,7 @@ var keymapFacet = Facet.define({
|
|
1037
988
|
}
|
1038
989
|
};
|
1039
990
|
},
|
1040
|
-
next: pluginFacet
|
1041
|
-
single: true
|
991
|
+
next: pluginFacet
|
1042
992
|
});
|
1043
993
|
function mergeKeymaps(keymaps) {
|
1044
994
|
const bindings = {};
|
@@ -1058,7 +1008,7 @@ function mergeKeymaps(keymaps) {
|
|
1058
1008
|
var keymapPluginKey = new PluginKey2("prosekit-keymap");
|
1059
1009
|
|
1060
1010
|
// src/extensions/history.ts
|
1061
|
-
function
|
1011
|
+
function defineHistory() {
|
1062
1012
|
const keymap = {
|
1063
1013
|
"Mod-z": undo,
|
1064
1014
|
"Shift-Mod-z": redo
|
@@ -1066,10 +1016,10 @@ function addHistory() {
|
|
1066
1016
|
if (!isMac) {
|
1067
1017
|
keymap["Mod-y"] = redo;
|
1068
1018
|
}
|
1069
|
-
return
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1019
|
+
return union([
|
1020
|
+
definePlugin(history()),
|
1021
|
+
defineKeymap(keymap),
|
1022
|
+
defineCommands({
|
1073
1023
|
undo: () => undo,
|
1074
1024
|
redo: () => redo
|
1075
1025
|
})
|
@@ -1080,11 +1030,11 @@ function addHistory() {
|
|
1080
1030
|
import { inputRules } from "@prosekit/pm/inputrules";
|
1081
1031
|
import "@prosekit/pm/model";
|
1082
1032
|
import "@prosekit/pm/state";
|
1083
|
-
function
|
1033
|
+
function defineInputRule(rules) {
|
1084
1034
|
return inputRuleFacet.extension([rules]);
|
1085
1035
|
}
|
1086
1036
|
var inputRuleFacet = Facet.define({
|
1087
|
-
|
1037
|
+
convert: (inputs) => {
|
1088
1038
|
return (context) => {
|
1089
1039
|
const rules = inputs.flatMap((callback) => callback(context));
|
1090
1040
|
return [inputRules({ rules })];
|
@@ -1094,11 +1044,11 @@ var inputRuleFacet = Facet.define({
|
|
1094
1044
|
});
|
1095
1045
|
|
1096
1046
|
// src/extensions/mark-spec.ts
|
1097
|
-
function
|
1047
|
+
function defineMarkSpec(options) {
|
1098
1048
|
return markSpecFacet.extension([options]);
|
1099
1049
|
}
|
1100
1050
|
var markSpecFacet = Facet.define({
|
1101
|
-
|
1051
|
+
convert: (options) => {
|
1102
1052
|
const marks = {};
|
1103
1053
|
for (const { name, ...spec } of options) {
|
1104
1054
|
if (marks[name]) {
|
@@ -1108,31 +1058,65 @@ var markSpecFacet = Facet.define({
|
|
1108
1058
|
}
|
1109
1059
|
return { marks, nodes: {} };
|
1110
1060
|
},
|
1111
|
-
next:
|
1061
|
+
next: schemaFacet
|
1112
1062
|
});
|
1113
1063
|
|
1114
1064
|
// src/extensions/node-view.ts
|
1115
|
-
import {
|
1065
|
+
import { ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm/state";
|
1116
1066
|
import "@prosekit/pm/view";
|
1117
|
-
function
|
1067
|
+
function defineNodeView(options) {
|
1118
1068
|
return nodeViewFacet.extension([options]);
|
1119
1069
|
}
|
1120
1070
|
var nodeViewFacet = Facet.define({
|
1121
|
-
|
1071
|
+
convert: (inputs) => {
|
1122
1072
|
const nodeViews = {};
|
1123
1073
|
for (const input of inputs) {
|
1124
1074
|
if (!nodeViews[input.name]) {
|
1125
1075
|
nodeViews[input.name] = input.constructor;
|
1126
1076
|
}
|
1127
1077
|
}
|
1128
|
-
return () => [new
|
1078
|
+
return () => [new ProseMirrorPlugin2({ props: { nodeViews } })];
|
1079
|
+
},
|
1080
|
+
next: pluginFacet
|
1081
|
+
});
|
1082
|
+
|
1083
|
+
// src/extensions/node-view-effect.ts
|
1084
|
+
import { ProseMirrorPlugin as ProseMirrorPlugin3 } from "@prosekit/pm/state";
|
1085
|
+
import "@prosekit/pm/view";
|
1086
|
+
function defineNodeViewEffect(options) {
|
1087
|
+
return nodeViewEffectFacet.extension([options]);
|
1088
|
+
}
|
1089
|
+
var nodeViewEffectFacet = Facet.define({
|
1090
|
+
convert: (inputs) => {
|
1091
|
+
const nodeViews = {};
|
1092
|
+
const options = {};
|
1093
|
+
const factories = {};
|
1094
|
+
for (const input of inputs) {
|
1095
|
+
const group = input.group;
|
1096
|
+
if (input.name == null) {
|
1097
|
+
factories[group] = input.factory;
|
1098
|
+
} else {
|
1099
|
+
options[group] || (options[group] = []);
|
1100
|
+
options[group].push({
|
1101
|
+
name: input.name,
|
1102
|
+
args: input.args
|
1103
|
+
});
|
1104
|
+
}
|
1105
|
+
}
|
1106
|
+
for (const [group, factory] of Object.entries(factories)) {
|
1107
|
+
const groupOptions = options[group] || [];
|
1108
|
+
for (const { name, args } of groupOptions) {
|
1109
|
+
nodeViews[name] = factory(args);
|
1110
|
+
}
|
1111
|
+
}
|
1112
|
+
return () => Object.keys(nodeViews).length > 0 ? [new ProseMirrorPlugin3({ props: { nodeViews } })] : [];
|
1129
1113
|
},
|
1130
1114
|
next: pluginFacet
|
1131
1115
|
});
|
1132
1116
|
|
1133
1117
|
// src/extensions/paragraph.ts
|
1134
|
-
function
|
1135
|
-
return
|
1118
|
+
function defineParagraph() {
|
1119
|
+
return defineNodeSpec({
|
1136
1120
|
name: "paragraph",
|
1137
1121
|
content: "inline*",
|
1138
1122
|
group: "block",
|
@@ -1144,8 +1128,8 @@ function addParagraph() {
|
|
1144
1128
|
}
|
1145
1129
|
|
1146
1130
|
// src/extensions/text.ts
|
1147
|
-
function
|
1148
|
-
return
|
1131
|
+
function defineText() {
|
1132
|
+
return defineNodeSpec({
|
1149
1133
|
name: "text",
|
1150
1134
|
group: "inline"
|
1151
1135
|
});
|
@@ -1156,28 +1140,29 @@ export {
|
|
1156
1140
|
FacetExtension,
|
1157
1141
|
Priority,
|
1158
1142
|
ProseKitError,
|
1159
|
-
addBaseCommands,
|
1160
|
-
addBaseKeymap,
|
1161
|
-
addCommands,
|
1162
|
-
addDefaultState,
|
1163
|
-
addDoc,
|
1164
|
-
addEventHandler,
|
1165
|
-
addHistory,
|
1166
|
-
addInputRule,
|
1167
|
-
addKeymap,
|
1168
1143
|
addMark,
|
1169
|
-
addMarkSpec,
|
1170
|
-
addNodeSpec,
|
1171
|
-
addNodeView,
|
1172
|
-
addParagraph,
|
1173
|
-
addPlugin,
|
1174
|
-
addText,
|
1175
1144
|
createEditor,
|
1176
|
-
|
1145
|
+
defineBaseCommands,
|
1146
|
+
defineBaseKeymap,
|
1147
|
+
defineCommands,
|
1148
|
+
defineDefaultState,
|
1149
|
+
defineDoc,
|
1150
|
+
defineEventHandler,
|
1151
|
+
defineHistory,
|
1152
|
+
defineInputRule,
|
1153
|
+
defineKeymap,
|
1154
|
+
defineMarkSpec,
|
1155
|
+
defineNodeSpec,
|
1156
|
+
defineNodeView,
|
1157
|
+
defineNodeViewEffect,
|
1158
|
+
defineParagraph,
|
1159
|
+
definePlugin,
|
1160
|
+
defineText,
|
1177
1161
|
getMarkType,
|
1178
1162
|
getNodeType,
|
1179
1163
|
pluginFacet,
|
1180
1164
|
toggleMark,
|
1181
1165
|
toggleNode,
|
1166
|
+
union,
|
1182
1167
|
withPriority
|
1183
1168
|
};
|