@prosekit/extensions 0.0.4 → 0.0.6

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.
@@ -33,12 +33,12 @@ function setTrMeta(tr, meta) {
33
33
  return tr.setMeta(pluginKey, meta);
34
34
  }
35
35
  var pluginKey = new PluginKey(
36
- "prosemirror-prediction"
36
+ "prosekit-autocomplete"
37
37
  );
38
38
 
39
39
  // src/autocomplete/plugin.ts
40
40
  function createAutocompletePlugin({
41
- rules
41
+ getRules
42
42
  }) {
43
43
  return new Plugin({
44
44
  key: pluginKey,
@@ -55,7 +55,7 @@ function createAutocompletePlugin({
55
55
  if (meta) {
56
56
  return meta;
57
57
  }
58
- const nextValue = calcPluginState(newState, rules);
58
+ const nextValue = calcPluginState(newState, getRules());
59
59
  if (nextValue.active && prevValue.ignore != null && ((_a = nextValue.matching) == null ? void 0 : _a.from) === prevValue.ignore) {
60
60
  return prevValue;
61
61
  }
@@ -167,8 +167,20 @@ function addAutocomplete(rule) {
167
167
  return autocompleteFacet.extension([rule]);
168
168
  }
169
169
  var autocompleteFacet = Facet.define({
170
- combine: (rules) => {
171
- return () => [createAutocompletePlugin({ rules })];
170
+ slot: () => {
171
+ let localRules = [];
172
+ const getRules = () => localRules;
173
+ return {
174
+ create: (rules) => {
175
+ localRules = rules;
176
+ const plugin = createAutocompletePlugin({ getRules });
177
+ return () => [plugin];
178
+ },
179
+ update: (rules) => {
180
+ localRules = rules;
181
+ return null;
182
+ }
183
+ };
172
184
  },
173
185
  next: pluginFacet
174
186
  });
@@ -6,10 +6,11 @@ interface HeadingAttrs {
6
6
  declare function addHeadingSpec(): _prosekit_core.Extension<{
7
7
  NODES: "heading";
8
8
  }>;
9
+ declare function addHeadingKeymap(): _prosekit_core.Extension<_prosekit_core.ExtensionTyping<string, string, _prosekit_core.CommandArgs>>;
9
10
  declare function addHeadingInputRule(): _prosekit_core.Extension<_prosekit_core.ExtensionTyping<string, string, _prosekit_core.CommandArgs>>;
10
11
  /** @public */
11
12
  declare function addHeading(): _prosekit_core.Extension<{
12
13
  NODES: "heading";
13
14
  }>;
14
15
 
15
- export { HeadingAttrs, addHeading, addHeadingInputRule, addHeadingSpec };
16
+ export { HeadingAttrs, addHeading, addHeadingInputRule, addHeadingKeymap, addHeadingSpec };
@@ -1,9 +1,11 @@
1
1
  // src/heading/index.ts
2
2
  import {
3
3
  addInputRule,
4
+ addKeymap,
4
5
  addNodeSpec,
5
6
  defineExtension,
6
- getNodeType
7
+ getNodeType,
8
+ toggleNode
7
9
  } from "@prosekit/core";
8
10
  import { textblockTypeInputRule } from "@prosekit/pm/inputrules";
9
11
  function addHeadingSpec() {
@@ -28,6 +30,16 @@ function addHeadingSpec() {
28
30
  }
29
31
  });
30
32
  }
33
+ function addHeadingKeymap() {
34
+ return addKeymap({
35
+ "mod-1": toggleNode({ type: "heading", attrs: { level: 1 } }),
36
+ "mod-2": toggleNode({ type: "heading", attrs: { level: 2 } }),
37
+ "mod-3": toggleNode({ type: "heading", attrs: { level: 3 } }),
38
+ "mod-4": toggleNode({ type: "heading", attrs: { level: 4 } }),
39
+ "mod-5": toggleNode({ type: "heading", attrs: { level: 5 } }),
40
+ "mod-6": toggleNode({ type: "heading", attrs: { level: 6 } })
41
+ });
42
+ }
31
43
  function addHeadingInputRule() {
32
44
  return addInputRule(({ schema }) => {
33
45
  const nodeSpec = getNodeType(schema, "heading");
@@ -44,10 +56,15 @@ function addHeadingInputRule() {
44
56
  });
45
57
  }
46
58
  function addHeading() {
47
- return defineExtension([addHeadingSpec(), addHeadingInputRule()]);
59
+ return defineExtension([
60
+ addHeadingSpec(),
61
+ addHeadingInputRule(),
62
+ addHeadingKeymap()
63
+ ]);
48
64
  }
49
65
  export {
50
66
  addHeading,
51
67
  addHeadingInputRule,
68
+ addHeadingKeymap,
52
69
  addHeadingSpec
53
70
  };
@@ -0,0 +1,21 @@
1
+ import * as _prosekit_core from '@prosekit/core';
2
+
3
+ interface MentionAttrs {
4
+ id: string;
5
+ kind: string;
6
+ value: string;
7
+ }
8
+ /**
9
+ * @public
10
+ */
11
+ declare function addMentionSpec(): _prosekit_core.Extension<{
12
+ NODES: "mention";
13
+ }>;
14
+ /**
15
+ * @public
16
+ */
17
+ declare function addMention(): _prosekit_core.Extension<{
18
+ NODES: "mention";
19
+ }>;
20
+
21
+ export { MentionAttrs, addMention, addMentionSpec };
@@ -0,0 +1,45 @@
1
+ // src/mention/index.ts
2
+ import { addNodeSpec, defineExtension } from "@prosekit/core";
3
+ function addMentionSpec() {
4
+ return addNodeSpec({
5
+ name: "mention",
6
+ spec: {
7
+ atom: true,
8
+ group: "inline",
9
+ attrs: {
10
+ id: {},
11
+ value: {},
12
+ kind: { default: "" }
13
+ },
14
+ inline: true,
15
+ leafText: (node) => node.attrs.value.toString(),
16
+ parseDOM: [
17
+ {
18
+ tag: `span[data-mention]`,
19
+ getAttrs: (dom) => ({
20
+ id: dom.getAttribute("data-id") || "",
21
+ kind: dom.getAttribute("data-mention") || "",
22
+ value: dom.textContent || ""
23
+ })
24
+ }
25
+ ],
26
+ toDOM(node) {
27
+ return [
28
+ "span",
29
+ {
30
+ "data-id": node.attrs.id.toString(),
31
+ "data-mention": node.attrs.kind.toString()
32
+ },
33
+ node.attrs.value.toString()
34
+ ];
35
+ }
36
+ }
37
+ });
38
+ }
39
+ function addMention() {
40
+ return defineExtension([addMentionSpec()]);
41
+ }
42
+ export {
43
+ addMention,
44
+ addMentionSpec
45
+ };
@@ -1,7 +1,7 @@
1
1
  // src/placeholder/index.ts
2
2
  import { addPlugin } from "@prosekit/core";
3
3
  import "@prosekit/pm/model";
4
- import { Plugin } from "@prosekit/pm/state";
4
+ import { Plugin, PluginKey } from "@prosekit/pm/state";
5
5
  import { Decoration, DecorationSet } from "@prosekit/pm/view";
6
6
  function addPlaceholder(options) {
7
7
  return addPlugin({
@@ -10,6 +10,7 @@ function addPlaceholder(options) {
10
10
  }
11
11
  function createPlaceholderPlugin(options) {
12
12
  return new Plugin({
13
+ key: placeholderPluginKey,
13
14
  props: {
14
15
  decorations: (state) => {
15
16
  if (options.strategy === "doc" && !isDocEmpty(state.doc)) {
@@ -25,6 +26,7 @@ function createPlaceholderPlugin(options) {
25
26
  }
26
27
  });
27
28
  }
29
+ var placeholderPluginKey = new PluginKey("prosekit-placeholder");
28
30
  function isDocEmpty(doc) {
29
31
  var _a;
30
32
  return doc.childCount <= 1 && !((_a = doc.firstChild) == null ? void 0 : _a.content.size);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/extensions",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -68,6 +68,11 @@
68
68
  "./list/style.css": {
69
69
  "default": "./dist/list/style.css"
70
70
  },
71
+ "./mention": {
72
+ "types": "./dist/prosekit-extensions-mention.d.ts",
73
+ "import": "./dist/prosekit-extensions-mention.js",
74
+ "default": "./dist/prosekit-extensions-mention.js"
75
+ },
71
76
  "./placeholder": {
72
77
  "types": "./dist/prosekit-extensions-placeholder.d.ts",
73
78
  "import": "./dist/prosekit-extensions-placeholder.js",
@@ -86,7 +91,7 @@
86
91
  "dist"
87
92
  ],
88
93
  "dependencies": {
89
- "@prosekit/core": "^0.0.4",
94
+ "@prosekit/core": "^0.0.6",
90
95
  "@prosekit/pm": "^0.0.3",
91
96
  "prosemirror-flat-list": "^0.3.15"
92
97
  },
@@ -127,6 +132,9 @@
127
132
  "list": [
128
133
  "./dist/prosekit-extensions-list.d.ts"
129
134
  ],
135
+ "mention": [
136
+ "./dist/prosekit-extensions-mention.d.ts"
137
+ ],
130
138
  "placeholder": [
131
139
  "./dist/prosekit-extensions-placeholder.d.ts"
132
140
  ],