@prosekit/core 0.0.6 → 0.0.7

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.
@@ -16,6 +16,20 @@ interface ToggleNodeOptions {
16
16
  }
17
17
  declare function toggleNode(options: ToggleNodeOptions): Command;
18
18
 
19
+ interface AddMarkOptions {
20
+ type: string | MarkType;
21
+ attrs?: Attrs | null;
22
+ /**
23
+ * The start position of the mark. By default it will be the start position of current selection.
24
+ */
25
+ from?: number;
26
+ /**
27
+ * The end position of the mark. By default it will be the end position of current selection.
28
+ */
29
+ to?: number;
30
+ }
31
+ declare function addMark(options: AddMarkOptions): Command;
32
+
19
33
  type CommandDispatcher<Args extends any[] = any[]> = (...arg: Args) => boolean;
20
34
  type CommandCreator<Args extends any[] = any[]> = (...arg: Args) => Command;
21
35
  /** @internal */
@@ -217,7 +231,9 @@ declare function addDoc(): Extension<{
217
231
  NODES: "doc";
218
232
  }>;
219
233
 
220
- /** @public */
234
+ /**
235
+ * @public
236
+ */
221
237
  declare function addInputRule(rules: (context: {
222
238
  schema: Schema;
223
239
  }) => InputRule[]): Extension;
@@ -234,9 +250,8 @@ declare function addBaseKeymap(): Extension<ExtensionTyping<string, string, Comm
234
250
  /**
235
251
  * @public
236
252
  */
237
- interface MarkSpecOptions<M extends string = string> {
238
- name: M;
239
- spec: MarkSpec;
253
+ interface MarkSpecOptions<MarkName extends string = string> extends MarkSpec {
254
+ name: MarkName;
240
255
  }
241
256
  /**
242
257
  * @public
@@ -248,16 +263,15 @@ declare function addMarkSpec<Mark extends string>(options: MarkSpecOptions<Mark>
248
263
  /**
249
264
  * @public
250
265
  */
251
- interface NodeSpecOptions<N extends string = string> {
252
- name: N;
253
- spec: NodeSpec;
266
+ interface NodeSpecOptions<NodeName extends string = string> extends NodeSpec {
267
+ name: NodeName;
254
268
  topNode?: boolean;
255
269
  }
256
270
  /**
257
271
  * @public
258
272
  */
259
- declare function addNodeSpec<Node extends string>(options: NodeSpecOptions<Node>): Extension<{
260
- NODES: Node;
273
+ declare function addNodeSpec<NodeName extends string>(options: NodeSpecOptions<NodeName>): Extension<{
274
+ NODES: NodeName;
261
275
  }>;
262
276
 
263
277
  interface NodeViewOptions {
@@ -303,4 +317,4 @@ declare function getMarkType(schema: Schema, type: string | MarkType): MarkType;
303
317
  /** @internal */
304
318
  declare function getNodeType(schema: Schema, type: string | NodeType): NodeType;
305
319
 
306
- export { CommandArgs, Editor, EditorOptions, Extension, ExtensionTyping, ExtractCommandCreators, ExtractCommandDispatchers, ExtractMarks, ExtractNodes, Facet, FacetExtension, FacetOptions, Keymap, MarkSpecOptions, NodeSpecOptions, NodeViewOptions, PluginFacetInput, PluginOptions, Priority, ProseKitError, SimplifyExtension, SimplifyUnion, StateConfigCallback, StateConfigContext, ToggleMarkOptions, ToggleNodeOptions, ViewProps, addBaseCommands, addBaseKeymap, addCommands, addDoc, addInputRule, addKeymap, addMarkSpec, addNodeSpec, addNodeView, addParagraph, addPlugin, addText, createEditor, defineExtension, getMarkType, getNodeType, pluginFacet, toggleMark, toggleNode, withPriority };
320
+ export { AddMarkOptions, CommandArgs, Editor, EditorOptions, Extension, ExtensionTyping, ExtractCommandCreators, ExtractCommandDispatchers, ExtractMarks, ExtractNodes, Facet, FacetExtension, FacetOptions, Keymap, MarkSpecOptions, NodeSpecOptions, NodeViewOptions, PluginFacetInput, PluginOptions, Priority, ProseKitError, SimplifyExtension, SimplifyUnion, StateConfigCallback, StateConfigContext, ToggleMarkOptions, ToggleNodeOptions, ViewProps, addBaseCommands, addBaseKeymap, addCommands, addDoc, addInputRule, addKeymap, addMark, addMarkSpec, addNodeSpec, addNodeView, addParagraph, addPlugin, addText, createEditor, defineExtension, getMarkType, getNodeType, pluginFacet, toggleMark, toggleNode, withPriority };
@@ -109,6 +109,23 @@ function toggleNode(options) {
109
109
  };
110
110
  }
111
111
 
112
+ // src/commands/add-mark.ts
113
+ import "@prosekit/pm/model";
114
+ import "@prosekit/pm/state";
115
+ function addMark(options) {
116
+ return (state, dispatch) => {
117
+ var _a, _b;
118
+ const mark = getMarkType(state.schema, options.type).create(options.attrs);
119
+ const from = (_a = options.from) != null ? _a : state.selection.from;
120
+ const to = (_b = options.to) != null ? _b : state.selection.to;
121
+ if (from > to) {
122
+ return false;
123
+ }
124
+ dispatch == null ? void 0 : dispatch(state.tr.addMark(from, to, mark));
125
+ return true;
126
+ };
127
+ }
128
+
112
129
  // src/editor/editor.ts
113
130
  import { Schema as Schema3 } from "@prosekit/pm/model";
114
131
  import { EditorState } from "@prosekit/pm/state";
@@ -730,17 +747,17 @@ function addNodeSpec(options) {
730
747
  var nodeSpecFacet = Facet.define({
731
748
  combine: (options) => {
732
749
  const nodes = {};
733
- let topNode = void 0;
734
- for (const { name, spec, topNode: isTopNode } of options) {
750
+ let topNodeName = void 0;
751
+ for (const { name, topNode, ...spec } of options) {
735
752
  if (nodes[name]) {
736
753
  throw new Error(`Node type ${name} has already been defined`);
737
754
  }
738
- nodes[name] = spec;
739
- if (isTopNode && !topNode) {
740
- topNode = name;
755
+ if (topNodeName && !topNode) {
756
+ topNodeName = name;
741
757
  }
758
+ nodes[name] = spec;
742
759
  }
743
- return { nodes, topNode };
760
+ return { nodes, topNode: topNodeName };
744
761
  },
745
762
  next: schemaSlot
746
763
  });
@@ -749,9 +766,7 @@ var nodeSpecFacet = Facet.define({
749
766
  function addDoc() {
750
767
  return addNodeSpec({
751
768
  name: "doc",
752
- spec: {
753
- content: "block+"
754
- }
769
+ content: "block+"
755
770
  });
756
771
  }
757
772
 
@@ -857,7 +872,7 @@ function addMarkSpec(options) {
857
872
  var markSpecFacet = Facet.define({
858
873
  combine: (options) => {
859
874
  const marks = {};
860
- for (const { name, spec } of options) {
875
+ for (const { name, ...spec } of options) {
861
876
  if (marks[name]) {
862
877
  throw new Error(`Mark type ${name} has already been defined`);
863
878
  }
@@ -891,13 +906,11 @@ var nodeViewFacet = Facet.define({
891
906
  function addParagraph() {
892
907
  return addNodeSpec({
893
908
  name: "paragraph",
894
- spec: {
895
- content: "inline*",
896
- group: "block",
897
- parseDOM: [{ tag: "p" }],
898
- toDOM() {
899
- return ["p", 0];
900
- }
909
+ content: "inline*",
910
+ group: "block",
911
+ parseDOM: [{ tag: "p" }],
912
+ toDOM() {
913
+ return ["p", 0];
901
914
  }
902
915
  });
903
916
  }
@@ -906,9 +919,7 @@ function addParagraph() {
906
919
  function addText() {
907
920
  return addNodeSpec({
908
921
  name: "text",
909
- spec: {
910
- group: "inline"
911
- }
922
+ group: "inline"
912
923
  });
913
924
  }
914
925
  export {
@@ -923,6 +934,7 @@ export {
923
934
  addDoc,
924
935
  addInputRule,
925
936
  addKeymap,
937
+ addMark,
926
938
  addMarkSpec,
927
939
  addNodeSpec,
928
940
  addNodeView,
package/dist/style.css CHANGED
@@ -1,4 +1,4 @@
1
- /* ../../node_modules/.pnpm/prosemirror-view@1.31.6/node_modules/prosemirror-view/style/prosemirror.css */
1
+ /* ../../node_modules/.pnpm/prosemirror-view@1.31.7/node_modules/prosemirror-view/style/prosemirror.css */
2
2
  .ProseMirror {
3
3
  position: relative;
4
4
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/core",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -40,13 +40,13 @@
40
40
  "dependencies": {
41
41
  "@prosekit/pm": "^0.0.3",
42
42
  "orderedmap": "^2.1.1",
43
- "type-fest": "^4.0.0"
43
+ "type-fest": "^4.2.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@prosekit/dev": "*",
47
- "tsup": "^7.1.0",
47
+ "tsup": "^7.2.0",
48
48
  "typescript": "^5.1.6",
49
- "vitest": "^0.33.0"
49
+ "vitest": "^0.34.1"
50
50
  },
51
51
  "scripts": {
52
52
  "build:tsup": "tsup",
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { toggleMark, type ToggleMarkOptions } from './commands/toggle-mark'
2
2
  export { toggleNode, type ToggleNodeOptions } from './commands/toggle-node'
3
+ export { addMark, type AddMarkOptions } from './commands/add-mark'
3
4
  export { Editor, createEditor, type EditorOptions } from './editor/editor'
4
5
  export { Facet, FacetExtension, type FacetOptions } from './editor/facet'
5
6
  export { defineExtension } from './editor/type-utils'