@prosekit/core 0.0.12 → 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.
@@ -49,8 +49,6 @@ declare interface AddMarkOptions {
49
49
  export { AddMarkOptions }
50
50
  export { AddMarkOptions as AddMarkOptions_alias_1 }
51
51
 
52
- export declare type AnySlot = Slot<any, any>;
53
-
54
52
  export declare function applyAction(operator: Action): Command;
55
53
 
56
54
  /**
@@ -78,9 +76,13 @@ export declare interface CommandCreators {
78
76
  [name: string]: CommandCreator;
79
77
  }
80
78
 
81
- export declare const commandSlot: Facet<CommandSlotInput, CommandSlotInput>;
79
+ export declare const commandFacet: Facet<CommandCreators, CommandCreators>;
80
+
81
+ export declare type CommandPayload = CommandCreators;
82
+
83
+ export declare type Converters = ConverterTuple[];
82
84
 
83
- export declare type CommandSlotInput = Record<string, CommandCreator<any>>;
85
+ declare type ConverterTuple = Tuple5<FacetConverter | undefined>;
84
86
 
85
87
  /** @public */
86
88
  declare function createEditor<E extends Extension>({ extension, defaultDoc, defaultSelection, }: EditorOptions<E>): Editor<E>;
@@ -169,7 +171,7 @@ export { defineDoc as defineDoc_alias_1 }
169
171
  */
170
172
  declare function defineEventHandler(options: {
171
173
  update?: VoidFunction;
172
- }): FacetExtension<VoidFunction, PluginFacetInput>;
174
+ }): FacetExtension<VoidFunction, PluginPayload>;
173
175
  export { defineEventHandler }
174
176
  export { defineEventHandler as defineEventHandler_alias_1 }
175
177
 
@@ -221,6 +223,10 @@ declare function defineNodeView(options: NodeViewOptions): Extension;
221
223
  export { defineNodeView }
222
224
  export { defineNodeView as defineNodeView_alias_1 }
223
225
 
226
+ declare function defineNodeViewEffect(options: NodeViewEffectOptions): Extension;
227
+ export { defineNodeViewEffect }
228
+ export { defineNodeViewEffect as defineNodeViewEffect_alias_1 }
229
+
224
230
  /** @public */
225
231
  declare function defineParagraph(): Extension< {
226
232
  NODES: "paragraph";
@@ -377,40 +383,45 @@ declare class Facet<Input, Output> {
377
383
  /** @internal */
378
384
  readonly index: number;
379
385
  /** @internal */
380
- readonly slot: () => Slot<Input, Output>;
386
+ readonly converter: () => FacetConverter<Input, Output>;
381
387
  /** @internal */
382
388
  readonly next: Facet<Output, any> | null;
383
- /** @internal */
384
- readonly single: boolean;
385
389
  private constructor();
386
- static define<Input, Output>({ slot, combine, next, single, }: FacetOptions<Input, Output>): Facet<Input, Output>;
390
+ static define<Input, Output>({ converter: converter, convert: convert, next, }: FacetOptions<Input, Output>): Facet<Input, Output>;
387
391
  /** @internal */
388
- static defineSlot<Input>(options: Omit<FacetOptions<Input, Input>, 'next'>): Facet<Input, Input>;
389
- extension(inputs: Input[]): FacetExtension<Input, Output>;
392
+ static defineRootFacet<Input>(options: Omit<FacetOptions<Input, Input>, 'next'>): Facet<Input, Input>;
393
+ extension(payloads: Input[]): FacetExtension<Input, Output>;
390
394
  }
391
395
  export { Facet }
392
396
  export { Facet as Facet_alias_1 }
393
397
 
398
+ /** @public */
399
+ export declare interface FacetConverter<Input = any, Output = any> {
400
+ create: (inputs: Input[]) => Output;
401
+ update: (inputs: Input[]) => Output | null;
402
+ }
403
+
394
404
  /** @public */
395
405
  declare class FacetExtension<Input, Output> {
396
406
  readonly facet: Facet<Input, Output>;
397
- readonly inputs: Input[];
407
+ readonly payloads: Input[];
398
408
  extension: Extension;
399
- constructor(facet: Facet<Input, Output>, inputs: Input[]);
409
+ constructor(facet: Facet<Input, Output>, payloads: Input[]);
400
410
  }
401
411
  export { FacetExtension }
402
412
  export { FacetExtension as FacetExtension_alias_1 }
403
413
 
404
414
  /** @public */
405
415
  declare interface FacetOptions<Input, Output> {
406
- combine?: (inputs: Input[]) => Output;
407
- slot?: () => Slot<Input, Output>;
416
+ convert?: (payloads: Input[]) => Output;
417
+ converter?: () => FacetConverter<Input, Output>;
408
418
  next: Facet<Output, any>;
409
- single?: boolean;
410
419
  }
411
420
  export { FacetOptions }
412
421
  export { FacetOptions as FacetOptions_alias_1 }
413
422
 
423
+ export declare function getFacetCount(): number;
424
+
414
425
  /** @internal */
415
426
  declare function getMarkType(schema: Schema, type: string | MarkType): MarkType;
416
427
  export { getMarkType }
@@ -421,12 +432,6 @@ declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
421
432
  export { getNodeType }
422
433
  export { getNodeType as getNodeType_alias_1 }
423
434
 
424
- declare type Input = unknown;
425
-
426
- export declare type Inputs = InputTuple[];
427
-
428
- declare type InputTuple = [Input[], Input[], Input[], Input[], Input[]];
429
-
430
435
  export declare function insertNode({ node, pos, }: {
431
436
  node: ProseMirrorNode;
432
437
  pos?: number;
@@ -499,6 +504,18 @@ declare interface NodeSpecOptions<NodeName extends string = string> extends Node
499
504
  export { NodeSpecOptions }
500
505
  export { NodeSpecOptions as NodeSpecOptions_alias_1 }
501
506
 
507
+ declare type NodeViewEffectOptions = {
508
+ group: string;
509
+ name: string;
510
+ args: unknown;
511
+ } | {
512
+ group: string;
513
+ name?: undefined;
514
+ factory: (args: unknown) => NodeViewConstructor;
515
+ };
516
+ export { NodeViewEffectOptions }
517
+ export { NodeViewEffectOptions as NodeViewEffectOptions_alias_1 }
518
+
502
519
  declare interface NodeViewOptions {
503
520
  name: string;
504
521
  constructor: NodeViewConstructor;
@@ -508,17 +525,23 @@ export { NodeViewOptions as NodeViewOptions_alias_1 }
508
525
 
509
526
  export declare function objectEqual<T>(a: T, b: T): boolean;
510
527
 
528
+ declare type Payload = unknown;
529
+
530
+ export declare type Payloads = PayloadTuple[];
531
+
532
+ declare type PayloadTuple = Tuple5<Payload[]>;
533
+
511
534
  /** @internal */
512
- declare const pluginFacet: Facet<PluginFacetInput, StateConfigCallback>;
535
+ declare const pluginFacet: Facet<PluginPayload, StatePayload>;
513
536
  export { pluginFacet }
514
537
  export { pluginFacet as pluginFacet_alias_1 }
515
538
 
516
539
  /** @internal */
517
- declare type PluginFacetInput = (context: {
540
+ declare type PluginPayload = (context: {
518
541
  schema: Schema;
519
542
  }) => Plugin_2[];
520
- export { PluginFacetInput }
521
- export { PluginFacetInput as PluginFacetInput_alias_1 }
543
+ export { PluginPayload }
544
+ export { PluginPayload as PluginPayload_alias_1 }
522
545
 
523
546
  /**
524
547
  * @public
@@ -541,7 +564,9 @@ declare class ProseKitError extends Error {
541
564
  export { ProseKitError }
542
565
  export { ProseKitError as ProseKitError_alias_1 }
543
566
 
544
- export declare const schemaSlot: Facet<SchemaSpec<any, any>, SchemaSpec<any, any>>;
567
+ export declare const schemaFacet: Facet<SchemaPayload, SchemaPayload>;
568
+
569
+ export declare type SchemaPayload = SchemaSpec;
545
570
 
546
571
  /**
547
572
  * A JSON representation of the prosemirror selection.
@@ -574,35 +599,7 @@ declare type SimplifyUnion<T> = Simplify<UnionToIntersection<T>>;
574
599
  export { SimplifyUnion }
575
600
  export { SimplifyUnion as SimplifyUnion_alias_1 }
576
601
 
577
- export declare interface Slot<Input, Output> {
578
- create: (inputs: Input[]) => Output;
579
- update: (inputs: Input[]) => Output | null;
580
- }
581
-
582
- export declare type Slots = SlotTuple[];
583
-
584
- declare type SlotTuple = [
585
- AnySlot | undefined,
586
- AnySlot | undefined,
587
- AnySlot | undefined,
588
- AnySlot | undefined,
589
- AnySlot | undefined
590
- ];
591
-
592
- /**
593
- * Use topological sort algorithm to sort facets.
594
- */
595
- export declare function sortFacets(unsorted: readonly Facet<any, any>[]): Facet<any, any>[];
596
-
597
- declare type StateConfigCallback = (ctx: StateConfigContext) => EditorStateConfig;
598
- export { StateConfigCallback }
599
- export { StateConfigCallback as StateConfigCallback_alias_1 }
600
-
601
- declare interface StateConfigContext {
602
- schema: Schema;
603
- }
604
- export { StateConfigContext }
605
- export { StateConfigContext as StateConfigContext_alias_1 }
602
+ export declare const stateFacet: Facet<StatePayload, StatePayload>;
606
603
 
607
604
  /**
608
605
  * A JSON representation of the prosemirror state.
@@ -622,7 +619,9 @@ declare interface StateJson {
622
619
  export { StateJson }
623
620
  export { StateJson as StateJson_alias_1 }
624
621
 
625
- export declare const stateSlot: Facet<StateConfigCallback, StateConfigCallback>;
622
+ export declare type StatePayload = (ctx: {
623
+ schema: Schema;
624
+ }) => EditorStateConfig;
626
625
 
627
626
  export declare type ToCommandApplier<T extends CommandArgs> = {
628
627
  [K in keyof T]: CommandApplier<T[K]>;
@@ -658,6 +657,8 @@ declare interface ToggleNodeOptions {
658
657
  export { ToggleNodeOptions }
659
658
  export { ToggleNodeOptions as ToggleNodeOptions_alias_1 }
660
659
 
660
+ declare type Tuple5<T> = [T, T, T, T, T];
661
+
661
662
  declare function union<E extends Extension | Extension[]>(extension: E): SimplifyExtension<E>;
662
663
  export { union }
663
664
  export { union as union_alias_1 }
@@ -666,18 +667,16 @@ export declare function uniqPush<T>(prev: readonly T[], next: readonly T[]): T[]
666
667
 
667
668
  export declare function uniqRemove<T>(prev: T[], next: T[]): T[];
668
669
 
669
- export declare function updateExtension(prevInputs: Inputs, prevSlots: Slots, extension: Extension, mode: 'add' | 'remove'): {
670
- schemaInput: SchemaSpec<any, any> | null;
671
- stateInput: StateConfigCallback | null;
672
- viewInput: ViewProps | null;
673
- commandInput: CommandSlotInput | null;
670
+ export declare function updateExtension(prevInputs: Payloads, prevConverters: Converters, extension: Extension, mode: 'add' | 'remove'): {
671
+ schemaInput: SchemaPayload | null;
672
+ stateInput: StatePayload | null;
673
+ viewInput: ViewPayload | null;
674
+ commandInput: CommandCreators | null;
674
675
  };
675
676
 
676
- declare type ViewProps = Omit<DirectEditorProps, 'state'>;
677
- export { ViewProps }
678
- export { ViewProps as ViewProps_alias_1 }
677
+ export declare const viewFacet: Facet<ViewPayload, ViewPayload>;
679
678
 
680
- export declare const viewSlot: Facet<ViewProps, ViewProps>;
679
+ export declare type ViewPayload = Omit<DirectEditorProps, 'state'>;
681
680
 
682
681
  export declare function voidFunction(): void;
683
682
 
@@ -30,10 +30,12 @@ export { defineNodeSpec } from './_tsup-dts-rollup';
30
30
  export { NodeSpecOptions } from './_tsup-dts-rollup';
31
31
  export { defineNodeView } from './_tsup-dts-rollup';
32
32
  export { NodeViewOptions } from './_tsup-dts-rollup';
33
+ export { defineNodeViewEffect } from './_tsup-dts-rollup';
34
+ export { NodeViewEffectOptions } from './_tsup-dts-rollup';
33
35
  export { defineParagraph } from './_tsup-dts-rollup';
34
36
  export { definePlugin } from './_tsup-dts-rollup';
35
37
  export { pluginFacet } from './_tsup-dts-rollup';
36
- export { PluginFacetInput } from './_tsup-dts-rollup';
38
+ export { PluginPayload } from './_tsup-dts-rollup';
37
39
  export { defineText } from './_tsup-dts-rollup';
38
40
  export { CommandArgs } from './_tsup-dts-rollup';
39
41
  export { Extension } from './_tsup-dts-rollup';
@@ -50,6 +52,3 @@ export { Priority } from './_tsup-dts-rollup';
50
52
  export { SimplifyUnion } from './_tsup-dts-rollup';
51
53
  export { getMarkType } from './_tsup-dts-rollup';
52
54
  export { getNodeType } from './_tsup-dts-rollup';
53
- export { StateConfigContext } from './_tsup-dts-rollup';
54
- export { StateConfigCallback } from './_tsup-dts-rollup';
55
- export { ViewProps } from './_tsup-dts-rollup';
@@ -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/editor/facet.ts
162
- var nextIndex = 0;
158
+ // src/facets/facet.ts
159
+ var facetCount = 0;
160
+ function getFacetCount() {
161
+ return facetCount;
162
+ }
163
163
  var Facet = class _Facet {
164
- constructor(slot, next, single) {
164
+ constructor(converter, next) {
165
165
  /** @internal */
166
- this.index = nextIndex++;
167
- this.slot = slot;
166
+ this.index = facetCount++;
167
+ this.converter = converter;
168
168
  this.next = next;
169
- this.single = single;
170
169
  }
171
170
  static define({
172
- slot,
173
- combine,
174
- next,
175
- single
171
+ converter,
172
+ convert,
173
+ next
176
174
  }) {
177
- const slotFn = slot ? slot : combine ? () => ({
178
- create: combine,
179
- update: combine
175
+ const converterFunction = converter ? converter : convert ? () => ({
176
+ create: convert,
177
+ update: convert
180
178
  }) : null;
181
- if (!slotFn) {
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(slotFn, next, single != null ? single : false);
182
+ return new _Facet(converterFunction, next);
187
183
  }
188
184
  /** @internal */
189
- static defineSlot(options) {
185
+ static defineRootFacet(options) {
190
186
  return _Facet.define(options);
191
187
  }
192
- extension(inputs) {
193
- return new FacetExtension(this, inputs);
188
+ extension(payloads) {
189
+ return new FacetExtension(this, payloads);
194
190
  }
195
191
  };
196
192
  var FacetExtension = class {
197
- constructor(facet, inputs) {
193
+ constructor(facet, payloads) {
198
194
  this.facet = facet;
199
- this.inputs = inputs;
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/editor/slots.ts
254
- var schemaSlot = Facet.defineSlot({
255
- combine: (specs) => {
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
231
  function defineDefaultState(options) {
310
- return stateSlot.extension([
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 inputs = [];
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
- inputs[facet.index] = [[], [], [], [], []];
436
+ payloads[facet.index] = [[], [], [], [], []];
484
437
  }
485
- const facetInputs = ext.inputs;
486
- inputs[facet.index][pri].push(...facetInputs);
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, inputs];
455
+ return [facets, payloads];
503
456
  }
504
- function updateExtension(prevInputs, prevSlots, extension, mode) {
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 (const facet of sortFacets(facets)) {
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
- prevInputs[facet.index],
517
- inputs[facet.index]
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 slotTuple = prevSlots[facet.index] || (prevSlots[facet.index] = [
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 prevSlot = slotTuple[pri];
536
- const slot = prevSlot || facet.slot();
537
- prevSlots[facet.index][pri] = slot;
538
- const output = prevSlot ? slot.update(inputArray) : slot.create(inputArray);
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 slotTuple = prevSlots[facet.index] || (prevSlots[facet.index] = [
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 prevSlot = slotTuple[2 /* default */];
563
- const slot = prevSlot || facet.slot();
564
- prevSlots[facet.index][2 /* default */] = slot;
565
- const output = prevSlot ? slot.update(inputArray) : slot.create(inputArray);
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
- const outputTuple = [[], [], [output], [], []];
570
- if (facet.next) {
571
- inputs[facet.next.index] = modifyInputTuple(
572
- inputs[facet.next.index],
573
- outputTuple
574
- );
575
- continue;
576
- } else {
577
- switch (facet) {
578
- case schemaSlot:
579
- schemaInput = output;
580
- break;
581
- case stateSlot:
582
- stateInput = output;
583
- break;
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
  }
@@ -625,11 +575,11 @@ var EditorInstance = class {
625
575
  constructor(extension) {
626
576
  this.view = null;
627
577
  this.commandAppliers = {};
628
- this.inputs = [];
629
- this.slots = [];
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.inputs, this.slots, extension, "add");
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
  }
@@ -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.inputs, this.slots, extension, mode);
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
  }
@@ -703,8 +653,9 @@ 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) {
@@ -829,7 +780,7 @@ import "@prosekit/pm/model";
829
780
  import { AllSelection } from "@prosekit/pm/state";
830
781
  import { findWrapping, insertPoint } from "@prosekit/pm/transform";
831
782
  function defineCommands(commands) {
832
- return commandSlot.extension([commands]);
783
+ return commandFacet.extension([commands]);
833
784
  }
834
785
  function defineBaseCommands() {
835
786
  return defineCommands({
@@ -904,7 +855,7 @@ function defineNodeSpec(options) {
904
855
  return nodeSpecFacet.extension([options]);
905
856
  }
906
857
  var nodeSpecFacet = Facet.define({
907
- combine: (options) => {
858
+ convert: (options) => {
908
859
  const nodes = {};
909
860
  let topNodeName = void 0;
910
861
  for (const { name, topNode, ...spec } of options) {
@@ -918,7 +869,7 @@ var nodeSpecFacet = Facet.define({
918
869
  }
919
870
  return { nodes, topNode: topNodeName };
920
871
  },
921
- next: schemaSlot
872
+ next: schemaFacet
922
873
  });
923
874
 
924
875
  // src/extensions/doc.ts
@@ -952,13 +903,13 @@ function definePlugin(plugin) {
952
903
  throw new TypeError("Invalid plugin");
953
904
  }
954
905
  var pluginFacet = Facet.define({
955
- combine: (callbacks) => {
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: stateSlot
912
+ next: stateFacet
962
913
  });
963
914
 
964
915
  // src/extensions/event-handler.ts
@@ -968,7 +919,7 @@ function defineEventHandler(options) {
968
919
  return eventFacet.extension([updateHandler]);
969
920
  }
970
921
  var eventFacet = Facet.define({
971
- slot: () => {
922
+ converter: () => {
972
923
  let updateHandlers = [];
973
924
  const plugin = new ProseMirrorPlugin({
974
925
  key: pluginKey,
@@ -993,8 +944,7 @@ var eventFacet = Facet.define({
993
944
  }
994
945
  };
995
946
  },
996
- next: pluginFacet,
997
- single: true
947
+ next: pluginFacet
998
948
  });
999
949
  var pluginKey = new PluginKey("prosekit-event-handler");
1000
950
 
@@ -1015,7 +965,7 @@ function defineBaseKeymap() {
1015
965
  return defineKeymap(baseKeymap);
1016
966
  }
1017
967
  var keymapFacet = Facet.define({
1018
- slot: () => {
968
+ converter: () => {
1019
969
  let handler = null;
1020
970
  const handlerWrapper = (view, event) => {
1021
971
  if (handler)
@@ -1038,8 +988,7 @@ var keymapFacet = Facet.define({
1038
988
  }
1039
989
  };
1040
990
  },
1041
- next: pluginFacet,
1042
- single: true
991
+ next: pluginFacet
1043
992
  });
1044
993
  function mergeKeymaps(keymaps) {
1045
994
  const bindings = {};
@@ -1085,7 +1034,7 @@ function defineInputRule(rules) {
1085
1034
  return inputRuleFacet.extension([rules]);
1086
1035
  }
1087
1036
  var inputRuleFacet = Facet.define({
1088
- combine: (inputs) => {
1037
+ convert: (inputs) => {
1089
1038
  return (context) => {
1090
1039
  const rules = inputs.flatMap((callback) => callback(context));
1091
1040
  return [inputRules({ rules })];
@@ -1099,7 +1048,7 @@ function defineMarkSpec(options) {
1099
1048
  return markSpecFacet.extension([options]);
1100
1049
  }
1101
1050
  var markSpecFacet = Facet.define({
1102
- combine: (options) => {
1051
+ convert: (options) => {
1103
1052
  const marks = {};
1104
1053
  for (const { name, ...spec } of options) {
1105
1054
  if (marks[name]) {
@@ -1109,24 +1058,58 @@ var markSpecFacet = Facet.define({
1109
1058
  }
1110
1059
  return { marks, nodes: {} };
1111
1060
  },
1112
- next: schemaSlot
1061
+ next: schemaFacet
1113
1062
  });
1114
1063
 
1115
1064
  // src/extensions/node-view.ts
1116
- import { Plugin as Plugin5 } from "@prosekit/pm/state";
1065
+ import { ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm/state";
1117
1066
  import "@prosekit/pm/view";
1118
1067
  function defineNodeView(options) {
1119
1068
  return nodeViewFacet.extension([options]);
1120
1069
  }
1121
1070
  var nodeViewFacet = Facet.define({
1122
- combine: (inputs) => {
1071
+ convert: (inputs) => {
1123
1072
  const nodeViews = {};
1124
1073
  for (const input of inputs) {
1125
1074
  if (!nodeViews[input.name]) {
1126
1075
  nodeViews[input.name] = input.constructor;
1127
1076
  }
1128
1077
  }
1129
- return () => [new Plugin5({ props: { nodeViews } })];
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 } })] : [];
1130
1113
  },
1131
1114
  next: pluginFacet
1132
1115
  });
@@ -1171,6 +1154,7 @@ export {
1171
1154
  defineMarkSpec,
1172
1155
  defineNodeSpec,
1173
1156
  defineNodeView,
1157
+ defineNodeViewEffect,
1174
1158
  defineParagraph,
1175
1159
  definePlugin,
1176
1160
  defineText,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/core",
3
3
  "type": "module",
4
- "version": "0.0.12",
4
+ "version": "0.0.13",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -40,7 +40,7 @@
40
40
  "dependencies": {
41
41
  "@prosekit/pm": "^0.0.6",
42
42
  "orderedmap": "^2.1.1",
43
- "type-fest": "^4.4.0"
43
+ "type-fest": "^4.5.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@prosekit/dev": "*",
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ export { addMark, type AddMarkOptions } from './commands/add-mark'
2
2
  export { toggleMark, type ToggleMarkOptions } from './commands/toggle-mark'
3
3
  export { toggleNode, type ToggleNodeOptions } from './commands/toggle-node'
4
4
  export { Editor, createEditor, type EditorOptions } from './editor/editor'
5
- export { Facet, FacetExtension, type FacetOptions } from './editor/facet'
5
+ export { Facet, FacetExtension, type FacetOptions } from './facets/facet'
6
6
  export { union } from './editor/type-utils'
7
7
  export { withPriority } from './editor/with-priority'
8
8
  export { ProseKitError } from './error'
@@ -23,15 +23,18 @@ export {
23
23
  export { defineMarkSpec, type MarkSpecOptions } from './extensions/mark-spec'
24
24
  export { defineNodeSpec, type NodeSpecOptions } from './extensions/node-spec'
25
25
  export { defineNodeView, type NodeViewOptions } from './extensions/node-view'
26
+ export {
27
+ defineNodeViewEffect,
28
+ type NodeViewEffectOptions,
29
+ } from './extensions/node-view-effect'
26
30
  export { defineParagraph } from './extensions/paragraph'
27
31
  export {
28
32
  definePlugin,
29
33
  pluginFacet,
30
- type PluginFacetInput,
34
+ type PluginPayload,
31
35
  } from './extensions/plugin'
32
36
  export { defineText } from './extensions/text'
33
37
  export { type CommandArgs as CommandArgs } from './types/command'
34
- export * from './types/editor'
35
38
  export {
36
39
  type Extension,
37
40
  type ExtractCommandAppliers,