@prosekit/extensions 0.4.6 → 0.5.0

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.
@@ -531,6 +531,14 @@ export declare function defineMentionSpec(): Extension< {
531
531
  NODES: "mention";
532
532
  }>;
533
533
 
534
+ /**
535
+ * By default, clicking a node while holding the mod key will select the node. This
536
+ * extension disables that behavior.
537
+ *
538
+ * @public
539
+ */
540
+ export declare function defineModClickPrevention(): Extension;
541
+
534
542
  /**
535
543
  * Add a placeholder text to the editor when the current block or document is
536
544
  * empty.
@@ -630,6 +638,32 @@ NODES: "table";
630
638
  export { defineTableSpec }
631
639
  export { defineTableSpec as defineTableSpec_alias_1 }
632
640
 
641
+ /**
642
+ * Adds a `textAlign` attribute to the specified nodes. This will be rendered as
643
+ * a CSS `text-align` style.
644
+ *
645
+ * @public
646
+ */
647
+ export declare function defineTextAlign(options: TextAlignOptions): Extension<{
648
+ COMMAND_ARGS: {
649
+ setTextAlign: [value: string | null];
650
+ };
651
+ }>;
652
+
653
+ /**
654
+ * @internal
655
+ */
656
+ export declare function defineTextAlignCommands(types: string[]): Extension<{
657
+ COMMAND_ARGS: {
658
+ setTextAlign: [value: string | null];
659
+ };
660
+ }>;
661
+
662
+ /**
663
+ * @internal
664
+ */
665
+ export declare function defineTextAlignKeymap(types: string[]): Extension<ExtensionTyping<string, string, CommandArgs>>;
666
+
633
667
  /**
634
668
  * Defines an enter rule that replaces the matched text with a block node.
635
669
  *
@@ -846,6 +880,11 @@ export declare function insertTable({ row, col, header, }: {
846
880
  header: boolean;
847
881
  }): Command;
848
882
 
883
+ /**
884
+ * @deprecated Use `isApple` from `@prosekit/core`
885
+ */
886
+ export declare const isApple: boolean;
887
+
849
888
  export declare const LINK_ENTER_RE: RegExp;
850
889
 
851
890
  export declare const LINK_INPUT_RE: RegExp;
@@ -954,8 +993,33 @@ export declare interface PredictionPluginState {
954
993
  } | null;
955
994
  }
956
995
 
996
+ /**
997
+ * @internal
998
+ */
999
+ export declare function setTextAlign({ types, value, }: {
1000
+ types: string[];
1001
+ value: string | null;
1002
+ }): Command;
1003
+
957
1004
  export declare function setTrMeta(tr: Transaction, meta: PredictionPluginState): Transaction;
958
1005
 
1006
+ export declare interface TextAlignOptions {
1007
+ /**
1008
+ * The names of node to add the attribute to.
1009
+ *
1010
+ * @example
1011
+ *
1012
+ * ["paragraph", "heading"]
1013
+ */
1014
+ types: string[];
1015
+ /**
1016
+ * The default value for the attribute.
1017
+ *
1018
+ * @default "left"
1019
+ */
1020
+ default?: string;
1021
+ }
1022
+
959
1023
  /**
960
1024
  * Options for {@link defineTextBlockEnterRule}.
961
1025
  *
@@ -1,7 +1,8 @@
1
1
  // src/enter-rule/index.ts
2
2
  import {
3
- Facet,
4
3
  OBJECT_REPLACEMENT_CHARACTER,
4
+ defineFacet,
5
+ defineFacetPayload,
5
6
  getNodeType,
6
7
  isTextSelection,
7
8
  maybeRun,
@@ -9,7 +10,8 @@ import {
9
10
  } from "@prosekit/core";
10
11
  import { keydownHandler } from "@prosekit/pm/keymap";
11
12
  import {
12
- ProseMirrorPlugin
13
+ ProseMirrorPlugin,
14
+ PluginKey
13
15
  } from "@prosekit/pm/state";
14
16
  function defineEnterRule({
15
17
  regex,
@@ -17,7 +19,7 @@ function defineEnterRule({
17
19
  stop = false
18
20
  }) {
19
21
  const rule = new EnterRule(regex, handler, stop);
20
- return enterRule.extension([rule]);
22
+ return defineFacetPayload(enterRule, [rule]);
21
23
  }
22
24
  function defineTextBlockEnterRule({
23
25
  regex,
@@ -46,8 +48,8 @@ var EnterRule = class {
46
48
  this.stop = stop;
47
49
  }
48
50
  };
49
- var enterRule = Facet.define({
50
- converter: () => {
51
+ var enterRule = defineFacet({
52
+ reduce: () => {
51
53
  let rules = [];
52
54
  const command = (state, dispatch, view) => {
53
55
  if (!view)
@@ -55,20 +57,16 @@ var enterRule = Facet.define({
55
57
  return execRules(view, rules, dispatch);
56
58
  };
57
59
  const handler = keydownHandler({ Enter: command });
58
- const plugin = new ProseMirrorPlugin({ props: { handleKeyDown: handler } });
59
- const pluginFunc = () => [plugin];
60
- return {
61
- create: (inputs) => {
62
- rules = inputs;
63
- return pluginFunc;
64
- },
65
- update: (inputs) => {
66
- rules = inputs;
67
- return null;
68
- }
60
+ const plugin = new ProseMirrorPlugin({
61
+ key: new PluginKey("prosekit-enter-rule"),
62
+ props: { handleKeyDown: handler }
63
+ });
64
+ return function reducer(inputs) {
65
+ rules = inputs;
66
+ return plugin;
69
67
  };
70
68
  },
71
- next: pluginFacet
69
+ parent: pluginFacet
72
70
  });
73
71
  function execRules(view, rules, dispatch) {
74
72
  if (view.composing)
@@ -1,6 +1,7 @@
1
1
  // src/input-rule/index.ts
2
2
  import {
3
- Facet,
3
+ defineFacet,
4
+ defineFacetPayload,
4
5
  getMarkType,
5
6
  getNodeType,
6
7
  isMarkAbsent,
@@ -16,7 +17,7 @@ import {
16
17
  import "@prosekit/pm/model";
17
18
  import "@prosekit/pm/state";
18
19
  function defineInputRule(rule) {
19
- return inputRuleFacet.extension([() => rule]);
20
+ return defineFacetPayload(inputRuleFacet, [() => rule]);
20
21
  }
21
22
  function createMarkInputRule({
22
23
  regex,
@@ -61,7 +62,7 @@ function defineTextBlockInputRule({
61
62
  type,
62
63
  attrs
63
64
  }) {
64
- return inputRuleFacet.extension([
65
+ return defineFacetPayload(inputRuleFacet, [
65
66
  ({ schema }) => {
66
67
  const nodeType = getNodeType(schema, type);
67
68
  return textblockTypeInputRule(regex, nodeType, attrs);
@@ -74,21 +75,21 @@ function defineWrappingInputRule({
74
75
  attrs,
75
76
  join
76
77
  }) {
77
- return inputRuleFacet.extension([
78
+ return defineFacetPayload(inputRuleFacet, [
78
79
  ({ schema }) => {
79
80
  const nodeType = getNodeType(schema, type);
80
81
  return wrappingInputRule(regex, nodeType, attrs, join);
81
82
  }
82
83
  ]);
83
84
  }
84
- var inputRuleFacet = Facet.define({
85
- convert: (inputs) => {
85
+ var inputRuleFacet = defineFacet({
86
+ reducer: (inputs) => {
86
87
  return (context) => {
87
88
  const rules = inputs.flatMap((callback) => callback(context));
88
89
  return [inputRules({ rules })];
89
90
  };
90
91
  },
91
- next: pluginFacet
92
+ parent: pluginFacet
92
93
  });
93
94
 
94
95
  export {
@@ -1,6 +1,13 @@
1
1
  // src/mark-rule/extension.ts
2
- import { Facet, pluginFacet } from "@prosekit/core";
3
- import { ProseMirrorPlugin } from "@prosekit/pm/state";
2
+ import {
3
+ defineFacet,
4
+ defineFacetPayload,
5
+ pluginFacet
6
+ } from "@prosekit/core";
7
+ import {
8
+ PluginKey,
9
+ ProseMirrorPlugin
10
+ } from "@prosekit/pm/state";
4
11
 
5
12
  // src/mark-rule/apply.ts
6
13
  import {
@@ -158,29 +165,23 @@ function applyMarkRules(rules, transactions, oldState, newState) {
158
165
 
159
166
  // src/mark-rule/extension.ts
160
167
  function defineMarkRule(options) {
161
- return markRuleFacet.extension([options]);
168
+ return defineFacetPayload(markRuleFacet, [options]);
162
169
  }
163
- var markRuleFacet = Facet.define({
164
- converter: () => {
170
+ var markRuleFacet = defineFacet({
171
+ reduce: () => {
165
172
  let rules = [];
166
173
  const plugin = new ProseMirrorPlugin({
174
+ key: new PluginKey("prosekit-mark-rule"),
167
175
  appendTransaction: (transactions, oldState, newState) => {
168
176
  return applyMarkRules(rules, transactions, oldState, newState);
169
177
  }
170
178
  });
171
- const pluginFunc = () => [plugin];
172
- return {
173
- create: (inputs) => {
174
- rules = inputs;
175
- return pluginFunc;
176
- },
177
- update: (inputs) => {
178
- rules = inputs;
179
- return null;
180
- }
179
+ return function reducer(input) {
180
+ rules = input;
181
+ return plugin;
181
182
  };
182
183
  },
183
- next: pluginFacet
184
+ parent: pluginFacet
184
185
  });
185
186
 
186
187
  export {
@@ -1,6 +1,7 @@
1
1
  // src/autocomplete/index.ts
2
2
  import {
3
- Facet,
3
+ defineFacet,
4
+ defineFacetPayload,
4
5
  pluginFacet
5
6
  } from "@prosekit/core";
6
7
 
@@ -170,25 +171,20 @@ var AutocompleteRule = class {
170
171
 
171
172
  // src/autocomplete/index.ts
172
173
  function defineAutocomplete(rule) {
173
- return autocompleteFacet.extension([rule]);
174
+ return defineFacetPayload(autocompleteFacet, [rule]);
174
175
  }
175
- var autocompleteFacet = Facet.define({
176
- converter: () => {
177
- let localRules = [];
178
- const getRules = () => localRules;
179
- return {
180
- create: (rules) => {
181
- localRules = rules;
182
- const plugin = createAutocompletePlugin({ getRules });
183
- return () => [plugin];
184
- },
185
- update: (rules) => {
186
- localRules = rules;
187
- return null;
188
- }
176
+ var autocompleteFacet = defineFacet({
177
+ reduce: () => {
178
+ let rules = [];
179
+ const getRules = () => rules;
180
+ const plugin = createAutocompletePlugin({ getRules });
181
+ return function reducer(inputs) {
182
+ rules = inputs;
183
+ return plugin;
189
184
  };
190
185
  },
191
- next: pluginFacet
186
+ parent: pluginFacet,
187
+ singleton: true
192
188
  });
193
189
  export {
194
190
  AutocompleteRule,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineWrappingInputRule
3
- } from "./chunk-CJ3SOSL6.js";
3
+ } from "./chunk-LVMTQOWG.js";
4
4
 
5
5
  // src/blockquote/index.ts
6
6
  import { defineNodeSpec, union } from "@prosekit/core";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineMarkInputRule
3
- } from "./chunk-CJ3SOSL6.js";
3
+ } from "./chunk-LVMTQOWG.js";
4
4
 
5
5
  // src/bold/index.ts
6
6
  import {
@@ -1,9 +1,9 @@
1
- import {
2
- defineTextBlockEnterRule
3
- } from "./chunk-HLBUHIMJ.js";
4
1
  import {
5
2
  defineTextBlockInputRule
6
- } from "./chunk-CJ3SOSL6.js";
3
+ } from "./chunk-LVMTQOWG.js";
4
+ import {
5
+ defineTextBlockEnterRule
6
+ } from "./chunk-DZAKXWWF.js";
7
7
 
8
8
  // src/code-block/code-block.ts
9
9
  import { union } from "@prosekit/core";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineMarkInputRule
3
- } from "./chunk-CJ3SOSL6.js";
3
+ } from "./chunk-LVMTQOWG.js";
4
4
 
5
5
  // src/code/index.ts
6
6
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  defineEnterRule,
3
3
  defineTextBlockEnterRule
4
- } from "./chunk-HLBUHIMJ.js";
4
+ } from "./chunk-DZAKXWWF.js";
5
5
  export {
6
6
  defineEnterRule,
7
7
  defineTextBlockEnterRule
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineTextBlockInputRule
3
- } from "./chunk-CJ3SOSL6.js";
3
+ } from "./chunk-LVMTQOWG.js";
4
4
 
5
5
  // src/heading/index.ts
6
6
  import {
@@ -4,7 +4,7 @@ import {
4
4
  defineMarkInputRule,
5
5
  defineTextBlockInputRule,
6
6
  defineWrappingInputRule
7
- } from "./chunk-CJ3SOSL6.js";
7
+ } from "./chunk-LVMTQOWG.js";
8
8
  export {
9
9
  createMarkInputRule,
10
10
  defineInputRule,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineMarkInputRule
3
- } from "./chunk-CJ3SOSL6.js";
3
+ } from "./chunk-LVMTQOWG.js";
4
4
 
5
5
  // src/italic/index.ts
6
6
  import {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  defineMarkRule
3
- } from "./chunk-7G7COECS.js";
4
- import {
5
- defineEnterRule
6
- } from "./chunk-HLBUHIMJ.js";
3
+ } from "./chunk-ZOBSD7ZH.js";
7
4
  import {
8
5
  defineInputRule
9
- } from "./chunk-CJ3SOSL6.js";
6
+ } from "./chunk-LVMTQOWG.js";
7
+ import {
8
+ defineEnterRule
9
+ } from "./chunk-DZAKXWWF.js";
10
10
 
11
11
  // src/link/index.ts
12
12
  import {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineInputRule
3
- } from "./chunk-CJ3SOSL6.js";
3
+ } from "./chunk-LVMTQOWG.js";
4
4
 
5
5
  // src/list/index.ts
6
6
  import {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineMarkRule
3
- } from "./chunk-7G7COECS.js";
3
+ } from "./chunk-ZOBSD7ZH.js";
4
4
  export {
5
5
  defineMarkRule
6
6
  };
@@ -0,0 +1 @@
1
+ export { defineModClickPrevention } from './_tsup-dts-rollup';
@@ -0,0 +1,19 @@
1
+ // src/mod-click-prevention/index.ts
2
+ import { definePlugin } from "@prosekit/core";
3
+ import { Plugin, PluginKey } from "@prosekit/pm/state";
4
+
5
+ // src/mod-click-prevention/env.ts
6
+ var isApple = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navigator.platform) : false;
7
+
8
+ // src/mod-click-prevention/index.ts
9
+ function defineModClickPrevention() {
10
+ return definePlugin(new Plugin({ key, props: { handleClick } }));
11
+ }
12
+ var key = new PluginKey("prosekit-mod-click-prevention");
13
+ function handleClick(_view, _pos, event) {
14
+ return !!event[selectNodeModifier];
15
+ }
16
+ var selectNodeModifier = isApple ? "metaKey" : "ctrlKey";
17
+ export {
18
+ defineModClickPrevention
19
+ };
@@ -4,9 +4,8 @@ import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
4
4
  function defineReadonly() {
5
5
  return definePlugin(plugin);
6
6
  }
7
- var key = new PluginKey("readonly");
8
7
  var plugin = new ProseMirrorPlugin({
9
- key,
8
+ key: new PluginKey("prosekey-readonly"),
10
9
  props: {
11
10
  editable: () => false
12
11
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defineMarkInputRule
3
- } from "./chunk-CJ3SOSL6.js";
3
+ } from "./chunk-LVMTQOWG.js";
4
4
 
5
5
  // src/strike/index.ts
6
6
  import {
@@ -0,0 +1,5 @@
1
+ export { setTextAlign } from './_tsup-dts-rollup';
2
+ export { defineTextAlignCommands } from './_tsup-dts-rollup';
3
+ export { defineTextAlignKeymap } from './_tsup-dts-rollup';
4
+ export { defineTextAlign } from './_tsup-dts-rollup';
5
+ export { TextAlignOptions } from './_tsup-dts-rollup';
@@ -0,0 +1,55 @@
1
+ // src/text-align/index.ts
2
+ import {
3
+ defineCommands,
4
+ defineKeymap,
5
+ defineNodeAttr,
6
+ setNodeAttrs,
7
+ union
8
+ } from "@prosekit/core";
9
+ function defineTextAlignAttr(type, defaultValue) {
10
+ return defineNodeAttr({
11
+ type,
12
+ attr: "textAlign",
13
+ default: defaultValue,
14
+ splittable: true,
15
+ toDOM: (value) => value ? ["style", `text-align:${value};`] : null,
16
+ parseDOM: (node) => {
17
+ return node.style.getPropertyValue("text-align") || null;
18
+ }
19
+ });
20
+ }
21
+ function defineTextAlignAttrs(types, defaultValue) {
22
+ return union(types.map((type) => defineTextAlignAttr(type, defaultValue)));
23
+ }
24
+ function setTextAlign({
25
+ types,
26
+ value
27
+ }) {
28
+ return setNodeAttrs({ type: types, attrs: { textAlign: value } });
29
+ }
30
+ function defineTextAlignCommands(types) {
31
+ return defineCommands({
32
+ setTextAlign: (value) => setTextAlign({ types, value })
33
+ });
34
+ }
35
+ function defineTextAlignKeymap(types) {
36
+ return defineKeymap({
37
+ "mod-shift-l": setTextAlign({ types, value: "left" }),
38
+ "mod-shift-e": setTextAlign({ types, value: "center" }),
39
+ "mod-shift-r": setTextAlign({ types, value: "right" }),
40
+ "mod-shift-j": setTextAlign({ types, value: "justify" })
41
+ });
42
+ }
43
+ function defineTextAlign(options) {
44
+ return union([
45
+ defineTextAlignAttrs(options.types, options.default || "left"),
46
+ defineTextAlignKeymap(options.types),
47
+ defineTextAlignCommands(options.types)
48
+ ]);
49
+ }
50
+ export {
51
+ defineTextAlign,
52
+ defineTextAlignCommands,
53
+ defineTextAlignKeymap,
54
+ setTextAlign
55
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/extensions",
3
3
  "type": "module",
4
- "version": "0.4.6",
4
+ "version": "0.5.0",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -30,11 +30,6 @@
30
30
  "import": "./dist/prosekit-extensions.js",
31
31
  "default": "./dist/prosekit-extensions.js"
32
32
  },
33
- "./mark-rule": {
34
- "types": "./dist/prosekit-extensions-mark-rule.d.ts",
35
- "import": "./dist/prosekit-extensions-mark-rule.js",
36
- "default": "./dist/prosekit-extensions-mark-rule.js"
37
- },
38
33
  "./autocomplete": {
39
34
  "types": "./dist/prosekit-extensions-autocomplete.d.ts",
40
35
  "import": "./dist/prosekit-extensions-autocomplete.js",
@@ -103,11 +98,21 @@
103
98
  "./list/style.css": {
104
99
  "default": "./dist/list/style.css"
105
100
  },
101
+ "./mark-rule": {
102
+ "types": "./dist/prosekit-extensions-mark-rule.d.ts",
103
+ "import": "./dist/prosekit-extensions-mark-rule.js",
104
+ "default": "./dist/prosekit-extensions-mark-rule.js"
105
+ },
106
106
  "./mention": {
107
107
  "types": "./dist/prosekit-extensions-mention.d.ts",
108
108
  "import": "./dist/prosekit-extensions-mention.js",
109
109
  "default": "./dist/prosekit-extensions-mention.js"
110
110
  },
111
+ "./mod-click-prevention": {
112
+ "types": "./dist/prosekit-extensions-mod-click-prevention.d.ts",
113
+ "import": "./dist/prosekit-extensions-mod-click-prevention.js",
114
+ "default": "./dist/prosekit-extensions-mod-click-prevention.js"
115
+ },
111
116
  "./placeholder": {
112
117
  "types": "./dist/prosekit-extensions-placeholder.d.ts",
113
118
  "import": "./dist/prosekit-extensions-placeholder.js",
@@ -134,6 +139,11 @@
134
139
  "./table/style.css": {
135
140
  "default": "./dist/table/style.css"
136
141
  },
142
+ "./text-align": {
143
+ "types": "./dist/prosekit-extensions-text-align.d.ts",
144
+ "import": "./dist/prosekit-extensions-text-align.js",
145
+ "default": "./dist/prosekit-extensions-text-align.js"
146
+ },
137
147
  "./underline": {
138
148
  "types": "./dist/prosekit-extensions-underline.d.ts",
139
149
  "import": "./dist/prosekit-extensions-underline.js",
@@ -152,19 +162,19 @@
152
162
  "dist"
153
163
  ],
154
164
  "dependencies": {
155
- "@prosekit/core": "^0.4.2",
156
- "@prosekit/pm": "^0.1.2",
165
+ "@prosekit/core": "^0.5.0",
166
+ "@prosekit/pm": "^0.1.3",
157
167
  "prosemirror-dropcursor": "^1.8.1",
158
168
  "prosemirror-flat-list": "^0.5.0",
159
169
  "prosemirror-highlight": "^0.5.0",
160
170
  "prosemirror-tables": "^1.3.7",
161
- "shiki": "^1.3.0"
171
+ "shiki": "^1.4.0"
162
172
  },
163
173
  "devDependencies": {
164
174
  "@prosekit/dev": "*",
165
175
  "tsup": "^8.0.2",
166
176
  "typescript": "^5.4.5",
167
- "vitest": "^1.5.2"
177
+ "vitest": "^1.6.0"
168
178
  },
169
179
  "scripts": {
170
180
  "build:tsup": "tsup",
@@ -176,9 +186,6 @@
176
186
  ".": [
177
187
  "./dist/prosekit-extensions.d.ts"
178
188
  ],
179
- "mark-rule": [
180
- "./dist/prosekit-extensions-mark-rule.d.ts"
181
- ],
182
189
  "autocomplete": [
183
190
  "./dist/prosekit-extensions-autocomplete.d.ts"
184
191
  ],
@@ -218,9 +225,15 @@
218
225
  "list": [
219
226
  "./dist/prosekit-extensions-list.d.ts"
220
227
  ],
228
+ "mark-rule": [
229
+ "./dist/prosekit-extensions-mark-rule.d.ts"
230
+ ],
221
231
  "mention": [
222
232
  "./dist/prosekit-extensions-mention.d.ts"
223
233
  ],
234
+ "mod-click-prevention": [
235
+ "./dist/prosekit-extensions-mod-click-prevention.d.ts"
236
+ ],
224
237
  "placeholder": [
225
238
  "./dist/prosekit-extensions-placeholder.d.ts"
226
239
  ],
@@ -233,6 +246,9 @@
233
246
  "table": [
234
247
  "./dist/prosekit-extensions-table.d.ts"
235
248
  ],
249
+ "text-align": [
250
+ "./dist/prosekit-extensions-text-align.d.ts"
251
+ ],
236
252
  "underline": [
237
253
  "./dist/prosekit-extensions-underline.d.ts"
238
254
  ],