@prosekit/core 0.0.13 → 0.0.15

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.
@@ -1,8 +1,9 @@
1
1
  import { Attrs } from '@prosekit/pm/model';
2
+ import { Attrs as Attrs_2 } from 'prosemirror-model';
2
3
  import { Command } from '@prosekit/pm/state';
3
4
  import type { ConditionalExcept } from 'type-fest';
4
5
  import type { DirectEditorProps } from '@prosekit/pm/view';
5
- import type { EditorState } from '@prosekit/pm/state';
6
+ import { EditorState } from '@prosekit/pm/state';
6
7
  import type { EditorStateConfig } from '@prosekit/pm/state';
7
8
  import { EditorView } from '@prosekit/pm/view';
8
9
  import type { EmptyObject } from 'type-fest';
@@ -11,8 +12,10 @@ import type { IsEqual } from 'type-fest';
11
12
  import { Mark } from '@prosekit/pm/model';
12
13
  import type { MarkSpec } from '@prosekit/pm/model';
13
14
  import { MarkType } from '@prosekit/pm/model';
15
+ import { Node as Node_2 } from 'prosemirror-model';
14
16
  import type { NodeSpec } from '@prosekit/pm/model';
15
17
  import { NodeType } from '@prosekit/pm/model';
18
+ import { NodeType as NodeType_2 } from 'prosemirror-model';
16
19
  import { NodeViewConstructor } from '@prosekit/pm/view';
17
20
  import { Options } from 'tsup';
18
21
  import { Plugin as Plugin_2 } from '@prosekit/pm/state';
@@ -20,6 +23,7 @@ import { ProseMirrorFragment } from '@prosekit/pm/model';
20
23
  import { ProseMirrorNode } from '@prosekit/pm/model';
21
24
  import { Schema } from '@prosekit/pm/model';
22
25
  import type { SchemaSpec } from '@prosekit/pm/model';
26
+ import { Selection as Selection_2 } from 'prosemirror-state';
23
27
  import type { Simplify } from 'type-fest';
24
28
  import { Transaction } from '@prosekit/pm/state';
25
29
  import type { UnionToIntersection } from 'type-fest';
@@ -30,11 +34,7 @@ declare type Action = (options: {
30
34
  view?: EditorView;
31
35
  }) => boolean;
32
36
 
33
- declare function addMark(options: AddMarkOptions): Command;
34
- export { addMark }
35
- export { addMark as addMark_alias_1 }
36
-
37
- declare interface AddMarkOptions {
37
+ declare function addMark(options: {
38
38
  type: string | MarkType;
39
39
  attrs?: Attrs | null;
40
40
  /**
@@ -45,9 +45,9 @@ declare interface AddMarkOptions {
45
45
  * The end position of the mark. By default it will be the end position of current selection.
46
46
  */
47
47
  to?: number;
48
- }
49
- export { AddMarkOptions }
50
- export { AddMarkOptions as AddMarkOptions_alias_1 }
48
+ }): Command;
49
+ export { addMark }
50
+ export { addMark as addMark_alias_1 }
51
51
 
52
52
  export declare function applyAction(operator: Action): Command;
53
53
 
@@ -123,16 +123,16 @@ declare function defineBaseCommands(): Extension<{
123
123
  to?: number | undefined;
124
124
  }];
125
125
  insertNode: [{
126
- node: ProseMirrorNode;
126
+ node: Node_2;
127
127
  pos?: number | undefined;
128
128
  }];
129
129
  wrap: [{
130
- nodeType: NodeType;
131
- attrs?: Attrs | null | undefined;
130
+ nodeType: NodeType_2;
131
+ attrs?: Attrs_2 | null | undefined;
132
132
  }];
133
- setBlockType: [{
134
- nodeType: NodeType;
135
- attrs?: Attrs | null | undefined;
133
+ setBlockType: [options: {
134
+ type: string | NodeType_2;
135
+ attrs?: Attrs_2 | null | undefined;
136
136
  from?: number | undefined;
137
137
  to?: number | undefined;
138
138
  }];
@@ -386,8 +386,10 @@ declare class Facet<Input, Output> {
386
386
  readonly converter: () => FacetConverter<Input, Output>;
387
387
  /** @internal */
388
388
  readonly next: Facet<Output, any> | null;
389
+ /** @internal */
390
+ readonly singleton: boolean;
389
391
  private constructor();
390
- static define<Input, Output>({ converter: converter, convert: convert, next, }: FacetOptions<Input, Output>): Facet<Input, Output>;
392
+ static define<Input, Output>({ converter: converter, convert: convert, next, singleton, }: FacetOptions<Input, Output>): Facet<Input, Output>;
391
393
  /** @internal */
392
394
  static defineRootFacet<Input>(options: Omit<FacetOptions<Input, Input>, 'next'>): Facet<Input, Input>;
393
395
  extension(payloads: Input[]): FacetExtension<Input, Output>;
@@ -416,10 +418,13 @@ declare interface FacetOptions<Input, Output> {
416
418
  convert?: (payloads: Input[]) => Output;
417
419
  converter?: () => FacetConverter<Input, Output>;
418
420
  next: Facet<Output, any>;
421
+ singleton?: boolean;
419
422
  }
420
423
  export { FacetOptions }
421
424
  export { FacetOptions as FacetOptions_alias_1 }
422
425
 
426
+ export declare function getCustomSelection(state: EditorState, from?: number | null, to?: number | null): Selection_2;
427
+
423
428
  export declare function getFacetCount(): number;
424
429
 
425
430
  /** @internal */
@@ -432,11 +437,30 @@ declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
432
437
  export { getNodeType }
433
438
  export { getNodeType as getNodeType_alias_1 }
434
439
 
435
- export declare function insertNode({ node, pos, }: {
440
+ declare function insertNode(options: {
441
+ node: ProseMirrorNode;
442
+ pos?: number;
443
+ }): Command;
444
+
445
+ declare function insertNode(options: {
446
+ attrs?: Attrs;
447
+ type: string;
448
+ pos?: number;
449
+ }): Command;
450
+ export { insertNode }
451
+ export { insertNode as insertNode_alias_1 }
452
+
453
+ export declare function insertNode_alias_2({ node, pos, }: {
436
454
  node: ProseMirrorNode;
437
455
  pos?: number;
438
456
  }): Action;
439
457
 
458
+ export declare function insertText({ text, from, to, }: {
459
+ text: string;
460
+ from?: number;
461
+ to?: number;
462
+ }): Command;
463
+
440
464
  export declare const isMac: boolean;
441
465
 
442
466
  export declare function isMark(mark: unknown): mark is Mark;
@@ -568,6 +592,8 @@ export declare const schemaFacet: Facet<SchemaPayload, SchemaPayload>;
568
592
 
569
593
  export declare type SchemaPayload = SchemaSpec;
570
594
 
595
+ export declare function selectAll(): Command;
596
+
571
597
  /**
572
598
  * A JSON representation of the prosemirror selection.
573
599
  *
@@ -581,6 +607,19 @@ declare interface SelectionJson {
581
607
  export { SelectionJson }
582
608
  export { SelectionJson as SelectionJson_alias_1 }
583
609
 
610
+ /**
611
+ * Returns a command that tries to set the selected textblocks to the given node
612
+ * type with the given attributes.
613
+ */
614
+ declare function setBlockType(options: {
615
+ type: NodeType | string;
616
+ attrs?: Attrs | null;
617
+ from?: number;
618
+ to?: number;
619
+ }): Command;
620
+ export { setBlockType }
621
+ export { setBlockType as setBlockType_alias_1 }
622
+
584
623
  /**
585
624
  * @internal
586
625
  */
@@ -635,28 +674,20 @@ export declare type ToCommandCreators<T extends CommandArgs> = {
635
674
  [K in keyof T]: CommandCreator<T[K]>;
636
675
  };
637
676
 
638
- declare function toggleMark(options: ToggleMarkOptions): Command;
677
+ declare function toggleMark({ type, attrs, }: {
678
+ type: string | MarkType;
679
+ attrs?: Attrs | null;
680
+ }): Command;
639
681
  export { toggleMark }
640
682
  export { toggleMark as toggleMark_alias_1 }
641
683
 
642
- declare interface ToggleMarkOptions {
643
- type: string | MarkType;
684
+ declare function toggleNode({ type, attrs, }: {
685
+ type: string | NodeType;
644
686
  attrs?: Attrs | null;
645
- }
646
- export { ToggleMarkOptions }
647
- export { ToggleMarkOptions as ToggleMarkOptions_alias_1 }
648
-
649
- declare function toggleNode(options: ToggleNodeOptions): Command;
687
+ }): Command;
650
688
  export { toggleNode }
651
689
  export { toggleNode as toggleNode_alias_1 }
652
690
 
653
- declare interface ToggleNodeOptions {
654
- type: string | NodeType;
655
- attrs?: Attrs | null;
656
- }
657
- export { ToggleNodeOptions }
658
- export { ToggleNodeOptions as ToggleNodeOptions_alias_1 }
659
-
660
691
  declare type Tuple5<T> = [T, T, T, T, T];
661
692
 
662
693
  declare function union<E extends Extension | Extension[]>(extension: E): SimplifyExtension<E>;
@@ -685,4 +716,9 @@ declare function withPriority<T extends Extension>(extension: T, priority: Prior
685
716
  export { withPriority }
686
717
  export { withPriority as withPriority_alias_1 }
687
718
 
719
+ export declare function wrap({ nodeType, attrs, }: {
720
+ nodeType: NodeType;
721
+ attrs?: Attrs | null;
722
+ }): Command;
723
+
688
724
  export { }
@@ -1,15 +1,11 @@
1
1
  export { addMark } from './_tsup-dts-rollup';
2
- export { AddMarkOptions } from './_tsup-dts-rollup';
2
+ export { insertNode } from './_tsup-dts-rollup';
3
+ export { setBlockType } from './_tsup-dts-rollup';
3
4
  export { toggleMark } from './_tsup-dts-rollup';
4
- export { ToggleMarkOptions } from './_tsup-dts-rollup';
5
5
  export { toggleNode } from './_tsup-dts-rollup';
6
- export { ToggleNodeOptions } from './_tsup-dts-rollup';
7
6
  export { Editor } from './_tsup-dts-rollup';
8
7
  export { createEditor } from './_tsup-dts-rollup';
9
8
  export { EditorOptions } from './_tsup-dts-rollup';
10
- export { Facet } from './_tsup-dts-rollup';
11
- export { FacetExtension } from './_tsup-dts-rollup';
12
- export { FacetOptions } from './_tsup-dts-rollup';
13
9
  export { union } from './_tsup-dts-rollup';
14
10
  export { withPriority } from './_tsup-dts-rollup';
15
11
  export { ProseKitError_alias_1 as ProseKitError } from './_tsup-dts-rollup';
@@ -37,6 +33,9 @@ export { definePlugin } from './_tsup-dts-rollup';
37
33
  export { pluginFacet } from './_tsup-dts-rollup';
38
34
  export { PluginPayload } from './_tsup-dts-rollup';
39
35
  export { defineText } from './_tsup-dts-rollup';
36
+ export { Facet } from './_tsup-dts-rollup';
37
+ export { FacetExtension } from './_tsup-dts-rollup';
38
+ export { FacetOptions } from './_tsup-dts-rollup';
40
39
  export { CommandArgs } from './_tsup-dts-rollup';
41
40
  export { Extension } from './_tsup-dts-rollup';
42
41
  export { ExtractCommandAppliers } from './_tsup-dts-rollup';
@@ -36,23 +36,8 @@ function addMark(options) {
36
36
  };
37
37
  }
38
38
 
39
- // src/commands/toggle-mark.ts
40
- import { toggleMark as baseToggleMark } from "@prosekit/pm/commands";
41
- import "@prosekit/pm/model";
42
- import "@prosekit/pm/state";
43
- function toggleMark(options) {
44
- return (state, dispatch, view) => {
45
- return baseToggleMark(
46
- getMarkType(state.schema, options.type),
47
- options.attrs
48
- )(state, dispatch, view);
49
- };
50
- }
51
-
52
- // src/commands/toggle-node.ts
53
- import { setBlockType } from "@prosekit/pm/commands";
54
- import "@prosekit/pm/model";
55
- import "@prosekit/pm/state";
39
+ // src/commands/insert-node.ts
40
+ import { insertPoint } from "@prosekit/pm/transform";
56
41
 
57
42
  // src/utils/get-node-type.ts
58
43
  import "@prosekit/pm/model";
@@ -67,6 +52,108 @@ function getNodeType(schema, type) {
67
52
  return type;
68
53
  }
69
54
 
55
+ // src/commands/insert-node.ts
56
+ function insertNode(options) {
57
+ return (state, dispatch) => {
58
+ var _a;
59
+ const node = options.node ? options.node : options.type ? getNodeType(state.schema, options.type).createChecked(options.attrs) : null;
60
+ if (!node) {
61
+ throw new ProseKitError("You must provide either a node or a type");
62
+ }
63
+ const insertPos = insertPoint(
64
+ state.doc,
65
+ (_a = options.pos) != null ? _a : state.selection.to,
66
+ node.type
67
+ );
68
+ if (insertPos == null)
69
+ return false;
70
+ if (dispatch) {
71
+ const tr = state.tr.insert(insertPos, node);
72
+ dispatch(tr);
73
+ }
74
+ return true;
75
+ };
76
+ }
77
+
78
+ // src/commands/set-block-type.ts
79
+ import "@prosekit/pm/state";
80
+
81
+ // src/utils/get-custom-selection.ts
82
+ import { TextSelection } from "@prosekit/pm/state";
83
+ function getCustomSelection(state, from, to) {
84
+ const pos = from != null ? from : to;
85
+ if (pos != null) {
86
+ const $from = state.doc.resolve(from != null ? from : pos);
87
+ const $to = state.doc.resolve(to != null ? to : pos);
88
+ return TextSelection.between($from, $to);
89
+ }
90
+ return state.selection;
91
+ }
92
+
93
+ // src/commands/set-block-type.ts
94
+ function setBlockType(options) {
95
+ return (state, dispatch) => {
96
+ const nodeType = getNodeType(state.schema, options.type);
97
+ const selection = getCustomSelection(state, options.from, options.to);
98
+ const attrs = options.attrs;
99
+ let applicable = false;
100
+ for (let i = 0; i < selection.ranges.length && !applicable; i++) {
101
+ const {
102
+ $from: { pos: from },
103
+ $to: { pos: to }
104
+ } = selection.ranges[i];
105
+ state.doc.nodesBetween(from, to, (node, pos) => {
106
+ if (applicable)
107
+ return false;
108
+ if (!node.isTextblock || node.hasMarkup(nodeType, attrs))
109
+ return;
110
+ if (node.type == nodeType) {
111
+ applicable = true;
112
+ } else {
113
+ const $pos = state.doc.resolve(pos), index = $pos.index();
114
+ applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType);
115
+ }
116
+ });
117
+ }
118
+ if (!applicable)
119
+ return false;
120
+ if (dispatch) {
121
+ const tr = state.tr;
122
+ for (const range of selection.ranges) {
123
+ const {
124
+ $from: { pos: from },
125
+ $to: { pos: to }
126
+ } = range;
127
+ tr.setBlockType(from, to, nodeType, attrs);
128
+ }
129
+ dispatch(tr.scrollIntoView());
130
+ }
131
+ return true;
132
+ };
133
+ }
134
+
135
+ // src/commands/toggle-mark.ts
136
+ import { toggleMark as baseToggleMark } from "@prosekit/pm/commands";
137
+ import "@prosekit/pm/model";
138
+ import "@prosekit/pm/state";
139
+ function toggleMark({
140
+ type,
141
+ attrs
142
+ }) {
143
+ return (state, dispatch, view) => {
144
+ return baseToggleMark(getMarkType(state.schema, type), attrs)(
145
+ state,
146
+ dispatch,
147
+ view
148
+ );
149
+ };
150
+ }
151
+
152
+ // src/commands/toggle-node.ts
153
+ import { setBlockType as setBlockType2 } from "@prosekit/pm/commands";
154
+ import "@prosekit/pm/model";
155
+ import "@prosekit/pm/state";
156
+
70
157
  // src/utils/object-euqal.ts
71
158
  function objectEqual(a, b) {
72
159
  if (a === b) {
@@ -111,17 +198,20 @@ function isNodeActive(state, type, attrs) {
111
198
  }
112
199
 
113
200
  // src/commands/toggle-node.ts
114
- function toggleNode(options) {
201
+ function toggleNode({
202
+ type,
203
+ attrs
204
+ }) {
115
205
  return (state, dispatch, view) => {
116
- if (isNodeActive(state, options.type, options.attrs)) {
206
+ if (isNodeActive(state, type, attrs)) {
117
207
  const defaultType = state.schema.topNodeType.contentMatch.defaultType;
118
208
  if (!defaultType) {
119
209
  return false;
120
210
  }
121
- return setBlockType(defaultType)(state, dispatch, view);
211
+ return setBlockType2(defaultType)(state, dispatch, view);
122
212
  } else {
123
- const nodeType = getNodeType(state.schema, options.type);
124
- return setBlockType(nodeType, options.attrs)(state, dispatch, view);
213
+ const nodeType = getNodeType(state.schema, type);
214
+ return setBlockType2(nodeType, attrs)(state, dispatch, view);
125
215
  }
126
216
  };
127
217
  }
@@ -161,16 +251,18 @@ function getFacetCount() {
161
251
  return facetCount;
162
252
  }
163
253
  var Facet = class _Facet {
164
- constructor(converter, next) {
254
+ constructor(converter, next, singleton) {
165
255
  /** @internal */
166
256
  this.index = facetCount++;
167
257
  this.converter = converter;
168
258
  this.next = next;
259
+ this.singleton = singleton;
169
260
  }
170
261
  static define({
171
262
  converter,
172
263
  convert,
173
- next
264
+ next,
265
+ singleton
174
266
  }) {
175
267
  const converterFunction = converter ? converter : convert ? () => ({
176
268
  create: convert,
@@ -179,7 +271,7 @@ var Facet = class _Facet {
179
271
  if (!converterFunction) {
180
272
  throw new ProseKitError("Facet must have either 'convert' or 'converter'");
181
273
  }
182
- return new _Facet(converterFunction, next);
274
+ return new _Facet(converterFunction, next, singleton != null ? singleton : false);
183
275
  }
184
276
  /** @internal */
185
277
  static defineRootFacet(options) {
@@ -476,7 +568,7 @@ function updateExtension(prevInputs, prevConverters, extension, mode) {
476
568
  }
477
569
  const inputTuple = modifyInputTuple(prevInputs[index], inputs[index]);
478
570
  prevInputs[index] = inputTuple;
479
- if (facet.next) {
571
+ if (facet.next && !facet.singleton) {
480
572
  let hasOutput = false;
481
573
  const outputTuple = [[], [], [], [], []];
482
574
  for (let pri = 0; pri < 5; pri++) {
@@ -511,35 +603,43 @@ function updateExtension(prevInputs, prevConverters, extension, mode) {
511
603
  continue;
512
604
  } else {
513
605
  const inputArray = flattenInputTuple(inputTuple);
514
- const converterTuple = prevConverters[index] || (prevConverters[index] = [
606
+ prevConverters[index] || (prevConverters[index] = [
515
607
  void 0,
516
608
  void 0,
517
609
  void 0,
518
610
  void 0,
519
611
  void 0
520
612
  ]);
521
- const prevConverter = converterTuple[2 /* default */];
613
+ const prevConverter = prevConverters[index][2 /* default */];
522
614
  const converter = prevConverter || facet.converter();
523
615
  prevConverters[index][2 /* default */] = converter;
524
616
  const output = prevConverter ? converter.update(inputArray) : converter.create(inputArray);
525
617
  if (!output) {
526
618
  continue;
527
619
  }
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");
620
+ if (facet.next) {
621
+ const outputTuple = [[], [], [output], [], []];
622
+ inputs[facet.next.index] = modifyInputTuple(
623
+ inputs[facet.next.index],
624
+ outputTuple
625
+ );
626
+ } else {
627
+ switch (facet) {
628
+ case schemaFacet:
629
+ schemaInput = output;
630
+ break;
631
+ case stateFacet:
632
+ stateInput = output;
633
+ break;
634
+ case viewFacet:
635
+ viewInput = output;
636
+ break;
637
+ case commandFacet:
638
+ commandInput = output;
639
+ break;
640
+ default:
641
+ throw new ProseKitError("Invalid root facet");
642
+ }
543
643
  }
544
644
  }
545
645
  }
@@ -775,78 +875,81 @@ function withPriority(extension, priority) {
775
875
  return { extension, priority };
776
876
  }
777
877
 
778
- // src/extensions/command.ts
779
- import "@prosekit/pm/model";
878
+ // src/commands/insert-text.ts
879
+ function insertText({
880
+ text,
881
+ from,
882
+ to
883
+ }) {
884
+ return (state, dispatch) => {
885
+ if (text) {
886
+ dispatch == null ? void 0 : dispatch(state.tr.insertText(text, from, to));
887
+ }
888
+ return true;
889
+ };
890
+ }
891
+
892
+ // src/commands/select-all.ts
780
893
  import { AllSelection } from "@prosekit/pm/state";
781
- import { findWrapping, insertPoint } from "@prosekit/pm/transform";
894
+ function selectAll() {
895
+ return (state, dispatch) => {
896
+ dispatch == null ? void 0 : dispatch(state.tr.setSelection(new AllSelection(state.doc)));
897
+ return true;
898
+ };
899
+ }
900
+
901
+ // src/commands/wrap.ts
902
+ import "@prosekit/pm/model";
903
+ import "@prosekit/pm/state";
904
+ import { findWrapping } from "@prosekit/pm/transform";
905
+ function wrap({
906
+ nodeType,
907
+ attrs
908
+ }) {
909
+ return (state, dispatch) => {
910
+ const { $from, $to } = state.selection;
911
+ const range = $from.blockRange($to);
912
+ if (!range)
913
+ return false;
914
+ const wrapping = findWrapping(range, nodeType, attrs);
915
+ if (!wrapping)
916
+ return false;
917
+ dispatch == null ? void 0 : dispatch(state.tr.wrap(range, wrapping));
918
+ return true;
919
+ };
920
+ }
921
+
922
+ // src/extensions/actions.ts
923
+ import "@prosekit/pm/model";
924
+ import { Selection as Selection2 } from "@prosekit/pm/state";
925
+ import { insertPoint as insertPoint2 } from "@prosekit/pm/transform";
926
+ function insertNode2({
927
+ node,
928
+ pos
929
+ }) {
930
+ return ({ tr }) => {
931
+ const insertPos = insertPoint2(tr.doc, pos != null ? pos : tr.selection.to, node.type);
932
+ if (insertPos == null) {
933
+ return false;
934
+ }
935
+ tr.insert(insertPos, node);
936
+ const $pos = tr.doc.resolve(insertPos);
937
+ tr.setSelection(Selection2.near($pos));
938
+ return true;
939
+ };
940
+ }
941
+
942
+ // src/extensions/command.ts
782
943
  function defineCommands(commands) {
783
944
  return commandFacet.extension([commands]);
784
945
  }
785
946
  function defineBaseCommands() {
786
947
  return defineCommands({
787
- insertText: ({
788
- text,
789
- from,
790
- to
791
- }) => {
792
- return (state, dispatch) => {
793
- if (text) {
794
- dispatch == null ? void 0 : dispatch(state.tr.insertText(text, from, to));
795
- }
796
- return true;
797
- };
798
- },
799
- insertNode: ({ node, pos }) => {
800
- return (state, dispatch) => {
801
- const insertPos = insertPoint(
802
- state.doc,
803
- pos != null ? pos : state.selection.to,
804
- node.type
805
- );
806
- if (insertPos == null)
807
- return false;
808
- if (dispatch) {
809
- const tr = state.tr.insert(insertPos, node);
810
- dispatch(tr);
811
- }
812
- return true;
813
- };
814
- },
815
- wrap: ({
816
- nodeType,
817
- attrs
818
- }) => {
819
- return (state, dispatch) => {
820
- const { $from, $to } = state.selection;
821
- const range = $from.blockRange($to);
822
- if (!range)
823
- return false;
824
- const wrapping = findWrapping(range, nodeType, attrs);
825
- if (!wrapping)
826
- return false;
827
- dispatch == null ? void 0 : dispatch(state.tr.wrap(range, wrapping));
828
- return true;
829
- };
830
- },
831
- setBlockType: ({
832
- nodeType,
833
- attrs,
834
- from,
835
- to
836
- }) => {
837
- return (state, dispatch) => {
838
- from = from != null ? from : state.selection.from;
839
- to = from != null ? from : state.selection.from;
840
- dispatch == null ? void 0 : dispatch(state.tr.setBlockType(from, to, nodeType, attrs));
841
- return true;
842
- };
843
- },
844
- selectAll: () => {
845
- return (state, dispatch) => {
846
- dispatch == null ? void 0 : dispatch(state.tr.setSelection(new AllSelection(state.doc)));
847
- return true;
848
- };
849
- }
948
+ insertText,
949
+ insertNode: insertNode2,
950
+ wrap,
951
+ setBlockType,
952
+ selectAll
850
953
  });
851
954
  }
852
955
 
@@ -944,7 +1047,8 @@ var eventFacet = Facet.define({
944
1047
  }
945
1048
  };
946
1049
  },
947
- next: pluginFacet
1050
+ next: pluginFacet,
1051
+ singleton: true
948
1052
  });
949
1053
  var pluginKey = new PluginKey("prosekit-event-handler");
950
1054
 
@@ -988,7 +1092,8 @@ var keymapFacet = Facet.define({
988
1092
  }
989
1093
  };
990
1094
  },
991
- next: pluginFacet
1095
+ next: pluginFacet,
1096
+ singleton: true
992
1097
  });
993
1098
  function mergeKeymaps(keymaps) {
994
1099
  const bindings = {};
@@ -1160,7 +1265,9 @@ export {
1160
1265
  defineText,
1161
1266
  getMarkType,
1162
1267
  getNodeType,
1268
+ insertNode,
1163
1269
  pluginFacet,
1270
+ setBlockType,
1164
1271
  toggleMark,
1165
1272
  toggleNode,
1166
1273
  union,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/core",
3
3
  "type": "module",
4
- "version": "0.0.13",
4
+ "version": "0.0.15",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
package/src/index.ts CHANGED
@@ -1,8 +1,9 @@
1
- export { addMark, type AddMarkOptions } from './commands/add-mark'
2
- export { toggleMark, type ToggleMarkOptions } from './commands/toggle-mark'
3
- export { toggleNode, type ToggleNodeOptions } from './commands/toggle-node'
1
+ export { addMark } from './commands/add-mark'
2
+ export { insertNode } from './commands/insert-node'
3
+ export { setBlockType } from './commands/set-block-type'
4
+ export { toggleMark } from './commands/toggle-mark'
5
+ export { toggleNode } from './commands/toggle-node'
4
6
  export { Editor, createEditor, type EditorOptions } from './editor/editor'
5
- export { Facet, FacetExtension, type FacetOptions } from './facets/facet'
6
7
  export { union } from './editor/type-utils'
7
8
  export { withPriority } from './editor/with-priority'
8
9
  export { ProseKitError } from './error'
@@ -34,6 +35,7 @@ export {
34
35
  type PluginPayload,
35
36
  } from './extensions/plugin'
36
37
  export { defineText } from './extensions/text'
38
+ export { Facet, FacetExtension, type FacetOptions } from './facets/facet'
37
39
  export { type CommandArgs as CommandArgs } from './types/command'
38
40
  export {
39
41
  type Extension,