@prosekit/extensions 0.9.2 → 0.9.3

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.
@@ -2,32 +2,93 @@ import { Extension } from "@prosekit/core";
2
2
  import { EditorState } from "@prosekit/pm/state";
3
3
 
4
4
  //#region src/autocomplete/autocomplete-rule.d.ts
5
- type MatchHandler = (options: {
5
+ /**
6
+ * Options for the {@link MatchHandler} callback.
7
+ */
8
+ interface MatchHandlerOptions {
9
+ /**
10
+ * The editor state.
11
+ */
6
12
  state: EditorState;
13
+ /**
14
+ * The result of `RegExp.exec`.
15
+ */
7
16
  match: RegExpExecArray;
17
+ /**
18
+ * The start position of the matched text.
19
+ */
8
20
  from: number;
21
+ /**
22
+ * The end position of the matched text.
23
+ */
9
24
  to: number;
25
+ /**
26
+ * Call this function to ignore the match. You probably want to call this
27
+ * function when the user presses the `Escape` key.
28
+ */
10
29
  ignoreMatch: () => void;
30
+ /**
31
+ * Call this function to delete the matched text. For example, in a slash
32
+ * menu, you might want to delete the matched text first then do something
33
+ * else when the user presses the `Enter` key.
34
+ */
11
35
  deleteMatch: () => void;
12
- }) => void;
36
+ }
37
+ /**
38
+ * A callback that is called when the rule starts to match, and also on
39
+ * subsequent updates while the rule continues to match.
40
+ */
41
+ type MatchHandler = (options: MatchHandlerOptions) => void;
42
+ /**
43
+ * Options for creating an {@link AutocompleteRule}
44
+ */
45
+ interface AutocompleteRuleOptions {
46
+ /**
47
+ * The regular expression to match against the text before the cursor. The
48
+ * last match before the cursor is used.
49
+ *
50
+ * For a slash menu, you might use `/\/(|\S.*)$/u`.
51
+ * For a mention, you might use `/@\w*$/`
52
+ */
53
+ regex: RegExp;
54
+ /**
55
+ * A callback that is called when the rule starts to match, and also on
56
+ * subsequent updates while the rule continues to match.
57
+ */
58
+ onEnter: MatchHandler;
59
+ /**
60
+ * A callback that is called when the rule stops matching.
61
+ */
62
+ onLeave?: VoidFunction;
63
+ /**
64
+ * A predicate to determine if the rule can be applied in the current editor
65
+ * state. If not provided, it defaults to only allowing matches in empty
66
+ * selections that are not inside a code block or code mark.
67
+ */
68
+ canMatch?: (options: {
69
+ state: EditorState;
70
+ }) => boolean;
71
+ }
72
+ /**
73
+ * An autocomplete rule that can be used to create an autocomplete extension.
74
+ *
75
+ * @public
76
+ */
13
77
  declare class AutocompleteRule {
78
+ /** @internal */
14
79
  readonly regex: RegExp;
80
+ /** @internal */
15
81
  readonly onMatch: MatchHandler;
82
+ /** @internal */
16
83
  readonly onLeave?: VoidFunction;
84
+ /** @internal */
17
85
  readonly canMatch: (options: {
18
86
  state: EditorState;
19
87
  }) => boolean;
20
- constructor(options: {
21
- regex: RegExp;
22
- onEnter: MatchHandler;
23
- onLeave?: VoidFunction;
24
- canMatch?: (options: {
25
- state: EditorState;
26
- }) => boolean;
27
- });
88
+ constructor(options: AutocompleteRuleOptions);
28
89
  }
29
90
  //#endregion
30
91
  //#region src/autocomplete/autocomplete.d.ts
31
92
  declare function defineAutocomplete(rule: AutocompleteRule): Extension;
32
93
  //#endregion
33
- export { AutocompleteRule, MatchHandler, defineAutocomplete };
94
+ export { AutocompleteRule, AutocompleteRuleOptions, MatchHandler, MatchHandlerOptions, defineAutocomplete };
@@ -130,10 +130,19 @@ const autocompleteFacet = defineFacet({
130
130
 
131
131
  //#endregion
132
132
  //#region src/autocomplete/autocomplete-rule.ts
133
+ /**
134
+ * An autocomplete rule that can be used to create an autocomplete extension.
135
+ *
136
+ * @public
137
+ */
133
138
  var AutocompleteRule = class {
139
+ /** @internal */
134
140
  regex;
141
+ /** @internal */
135
142
  onMatch;
143
+ /** @internal */
136
144
  onLeave;
145
+ /** @internal */
137
146
  canMatch;
138
147
  constructor(options) {
139
148
  this.regex = options.regex;
@@ -6,8 +6,10 @@ import { Attrs, NodeType } from "@prosekit/pm/model";
6
6
 
7
7
  /**
8
8
  * @public
9
+ *
10
+ * Options for {@link EnterRuleHandler}.
9
11
  */
10
- type EnterRuleHandler = (options: {
12
+ interface EnterRuleHandlerOptions {
11
13
  /**
12
14
  * The current editor state.
13
15
  */
@@ -24,7 +26,11 @@ type EnterRuleHandler = (options: {
24
26
  * The matched result from the regular expression.
25
27
  */
26
28
  match: RegExpExecArray;
27
- }) => Transaction | null;
29
+ }
30
+ /**
31
+ * @public
32
+ */
33
+ type EnterRuleHandler = (options: EnterRuleHandlerOptions) => Transaction | null;
28
34
  /**
29
35
  * Options for {@link defineEnterRule}.
30
36
  *
@@ -51,7 +57,7 @@ type EnterRuleOptions = {
51
57
  *
52
58
  * @public
53
59
  */
54
- type TextBlockEnterRuleOptions = {
60
+ interface TextBlockEnterRuleOptions {
55
61
  /**
56
62
  * The regular expression to match against. It should end with `$`.
57
63
  */
@@ -71,7 +77,7 @@ type TextBlockEnterRuleOptions = {
71
77
  * @default true
72
78
  */
73
79
  stop?: boolean;
74
- };
80
+ }
75
81
  /**
76
82
  * Defines an enter rule. An enter rule applies when the text directly in front of
77
83
  * the cursor matches `regex` and user presses Enter. The `regex` should end
@@ -102,4 +108,4 @@ declare function defineTextBlockEnterRule({
102
108
  stop
103
109
  }: TextBlockEnterRuleOptions): PlainExtension;
104
110
  //#endregion
105
- export { EnterRuleHandler, EnterRuleOptions, TextBlockEnterRuleOptions, defineEnterRule, defineTextBlockEnterRule };
111
+ export { EnterRuleHandler, EnterRuleHandlerOptions, EnterRuleOptions, TextBlockEnterRuleOptions, defineEnterRule, defineTextBlockEnterRule };
@@ -7,6 +7,8 @@ import { Extension, PlainExtension, Union } from "@prosekit/core";
7
7
  */
8
8
  interface LinkAttrs {
9
9
  href: string;
10
+ target?: string | null;
11
+ rel?: string | null;
10
12
  }
11
13
  /**
12
14
  * @internal
@@ -26,18 +26,36 @@ function defineLinkSpec() {
26
26
  return defineMarkSpec({
27
27
  name: "link",
28
28
  inclusive: false,
29
- attrs: { href: { validate: "string" } },
29
+ attrs: {
30
+ href: { validate: "string" },
31
+ target: {
32
+ default: null,
33
+ validate: "string|null"
34
+ },
35
+ rel: {
36
+ default: null,
37
+ validate: "string|null"
38
+ }
39
+ },
30
40
  parseDOM: [{
31
41
  tag: "a[href]",
32
42
  getAttrs: (dom) => {
33
- return { href: dom.getAttribute("href") || "" };
43
+ return {
44
+ href: dom.getAttribute("href") || "",
45
+ target: dom.getAttribute("target") || null,
46
+ rel: dom.getAttribute("rel") || null
47
+ };
34
48
  }
35
49
  }],
36
50
  toDOM(node) {
37
- const { href } = node.attrs;
51
+ const { href, target, rel } = node.attrs;
38
52
  return [
39
53
  "a",
40
- { href },
54
+ {
55
+ href,
56
+ target,
57
+ rel
58
+ },
41
59
  0
42
60
  ];
43
61
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/extensions",
3
3
  "type": "module",
4
- "version": "0.9.2",
4
+ "version": "0.9.3",
5
5
  "private": false,
6
6
  "description": "A collection of common extensions for ProseKit",
7
7
  "author": {
@@ -207,8 +207,8 @@
207
207
  "prosemirror-search": "^1.1.0",
208
208
  "prosemirror-tables": "^1.7.1",
209
209
  "shiki": "^3.6.0",
210
- "@prosekit/pm": "^0.1.11",
211
- "@prosekit/core": "^0.8.2"
210
+ "@prosekit/core": "^0.8.2",
211
+ "@prosekit/pm": "^0.1.11"
212
212
  },
213
213
  "peerDependencies": {
214
214
  "loro-crdt": ">= 0.16.7",