@prosekit/extensions 0.8.0 → 0.9.1

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.
Files changed (100) hide show
  1. package/dist/commit/style.css +1 -1
  2. package/dist/commit/style.js +0 -0
  3. package/dist/enter-rule-RdhEA900.js +96 -0
  4. package/dist/gap-cursor/style.css +6 -3
  5. package/dist/gap-cursor/style.js +0 -0
  6. package/dist/input-rule-Gji4N7Oe.js +93 -0
  7. package/dist/list/style.css +7 -7
  8. package/dist/list/style.js +0 -0
  9. package/dist/loro/style.css +13 -9
  10. package/dist/loro/style.js +0 -0
  11. package/dist/mark-rule-wEOcDt6i.js +160 -0
  12. package/dist/placeholder/style.css +3 -3
  13. package/dist/placeholder/style.js +0 -0
  14. package/dist/prosekit-extensions-autocomplete.d.ts +33 -3
  15. package/dist/prosekit-extensions-autocomplete.js +126 -174
  16. package/dist/prosekit-extensions-blockquote.d.ts +48 -8
  17. package/dist/prosekit-extensions-blockquote.js +64 -78
  18. package/dist/prosekit-extensions-bold.d.ts +54 -8
  19. package/dist/prosekit-extensions-bold.js +61 -73
  20. package/dist/prosekit-extensions-code-block.d.ts +159 -20
  21. package/dist/prosekit-extensions-code-block.js +201 -184
  22. package/dist/prosekit-extensions-code.d.ts +54 -8
  23. package/dist/prosekit-extensions-code.js +44 -56
  24. package/dist/prosekit-extensions-commit.d.ts +52 -4
  25. package/dist/prosekit-extensions-commit.js +140 -183
  26. package/dist/prosekit-extensions-doc.d.ts +19 -2
  27. package/dist/prosekit-extensions-doc.js +14 -12
  28. package/dist/prosekit-extensions-drop-cursor.d.ts +35 -3
  29. package/dist/prosekit-extensions-drop-cursor.js +14 -8
  30. package/dist/prosekit-extensions-enter-rule.d.ts +105 -5
  31. package/dist/prosekit-extensions-enter-rule.js +3 -8
  32. package/dist/prosekit-extensions-file.d.ts +129 -8
  33. package/dist/prosekit-extensions-file.js +124 -132
  34. package/dist/prosekit-extensions-gap-cursor.d.ts +26 -2
  35. package/dist/prosekit-extensions-gap-cursor.js +21 -9
  36. package/dist/prosekit-extensions-hard-break.d.ts +53 -0
  37. package/dist/prosekit-extensions-hard-break.js +58 -0
  38. package/dist/prosekit-extensions-heading.d.ts +63 -9
  39. package/dist/prosekit-extensions-heading.js +121 -95
  40. package/dist/prosekit-extensions-horizontal-rule.d.ts +38 -8
  41. package/dist/prosekit-extensions-horizontal-rule.js +53 -71
  42. package/dist/prosekit-extensions-image.d.ts +50 -7
  43. package/dist/prosekit-extensions-image.js +71 -62
  44. package/dist/prosekit-extensions-input-rule.d.ts +129 -6
  45. package/dist/prosekit-extensions-input-rule.js +3 -14
  46. package/dist/prosekit-extensions-italic.d.ts +54 -8
  47. package/dist/prosekit-extensions-italic.js +51 -63
  48. package/dist/prosekit-extensions-link.d.ts +62 -10
  49. package/dist/prosekit-extensions-link.js +95 -100
  50. package/dist/prosekit-extensions-list.d.ts +104 -17
  51. package/dist/prosekit-extensions-list.js +115 -158
  52. package/dist/prosekit-extensions-loro.d.ts +69 -11
  53. package/dist/prosekit-extensions-loro.js +49 -77
  54. package/dist/prosekit-extensions-mark-rule.d.ts +37 -2
  55. package/dist/prosekit-extensions-mark-rule.js +3 -6
  56. package/dist/prosekit-extensions-mention.d.ts +39 -4
  57. package/dist/prosekit-extensions-mention.js +52 -50
  58. package/dist/prosekit-extensions-mod-click-prevention.d.ts +17 -2
  59. package/dist/prosekit-extensions-mod-click-prevention.js +20 -16
  60. package/dist/prosekit-extensions-paragraph.d.ts +60 -7
  61. package/dist/prosekit-extensions-paragraph.js +46 -45
  62. package/dist/prosekit-extensions-placeholder.d.ts +33 -2
  63. package/dist/prosekit-extensions-placeholder.js +39 -56
  64. package/dist/prosekit-extensions-readonly.d.ts +10 -1
  65. package/dist/prosekit-extensions-readonly.js +13 -14
  66. package/dist/prosekit-extensions-search.d.ts +74 -3
  67. package/dist/prosekit-extensions-search.js +48 -47
  68. package/dist/prosekit-extensions-strike.d.ts +47 -8
  69. package/dist/prosekit-extensions-strike.js +44 -49
  70. package/dist/prosekit-extensions-table.d.ts +231 -26
  71. package/dist/prosekit-extensions-table.js +3 -34
  72. package/dist/prosekit-extensions-text-align.d.ts +71 -8
  73. package/dist/prosekit-extensions-text-align.js +63 -44
  74. package/dist/prosekit-extensions-text.d.ts +19 -2
  75. package/dist/prosekit-extensions-text.js +13 -11
  76. package/dist/prosekit-extensions-underline.d.ts +43 -7
  77. package/dist/prosekit-extensions-underline.js +33 -37
  78. package/dist/prosekit-extensions-virtual-selection.d.ts +21 -2
  79. package/dist/prosekit-extensions-virtual-selection.js +49 -52
  80. package/dist/prosekit-extensions-yjs.d.ts +90 -14
  81. package/dist/prosekit-extensions-yjs.js +88 -131
  82. package/dist/prosekit-extensions.d.ts +1 -1
  83. package/dist/search/style.css +4 -3
  84. package/dist/search/style.js +0 -0
  85. package/dist/shiki-highlighter-chunk-CZGvZlhf.d.ts +18 -0
  86. package/dist/shiki-highlighter-chunk.d.ts +2 -0
  87. package/dist/shiki-highlighter-chunk.js +32 -39
  88. package/dist/table/style.css +10 -13
  89. package/dist/table/style.js +0 -0
  90. package/dist/table-DnVliJ6E.js +287 -0
  91. package/dist/virtual-selection/style.css +2 -2
  92. package/dist/virtual-selection/style.js +0 -0
  93. package/dist/yjs/style.css +9 -8
  94. package/dist/yjs/style.js +0 -0
  95. package/package.json +81 -54
  96. package/dist/_tsup-dts-rollup.d.ts +0 -2459
  97. package/dist/chunk-6UYLCVBX.js +0 -185
  98. package/dist/chunk-D54VSLLS.js +0 -105
  99. package/dist/chunk-I2UMHK3L.js +0 -99
  100. package/dist/chunk-QVFEYPQ6.js +0 -306
@@ -1,2 +1,37 @@
1
- export { defineMarkRule } from './_tsup-dts-rollup.js';
2
- export { MarkRuleOptions } from './_tsup-dts-rollup.js';
1
+ import { PlainExtension } from "@prosekit/core";
2
+ import { Attrs, MarkType } from "@prosekit/pm/model";
3
+
4
+ //#region src/mark-rule/types.d.ts
5
+
6
+ /**
7
+ * The options for {@link defineMarkRule}.
8
+ *
9
+ * @public
10
+ */
11
+ interface MarkRuleOptions {
12
+ /**
13
+ * The regular expression to match against. It must has a `g` flag to match
14
+ * all instances of the mark.
15
+ */
16
+ regex: RegExp;
17
+ /**
18
+ * The mark type to apply to the matched text.
19
+ */
20
+ type: string | MarkType;
21
+ /**
22
+ * Attributes to set on the mark. If a function is provided, it will be called
23
+ * with the matched result from the regular expression.
24
+ *
25
+ * @default null
26
+ */
27
+ attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
28
+ }
29
+ //#endregion
30
+ //#region src/mark-rule/mark-rule.d.ts
31
+ /**
32
+ * A mark rule is something that can automatically apply marks to text if it
33
+ * matches a certain pattern, and remove them if it doesn't match anymore.
34
+ */
35
+ declare function defineMarkRule(options: MarkRuleOptions): PlainExtension;
36
+ //#endregion
37
+ export { MarkRuleOptions, defineMarkRule };
@@ -1,6 +1,3 @@
1
- import {
2
- defineMarkRule
3
- } from "./chunk-6UYLCVBX.js";
4
- export {
5
- defineMarkRule
6
- };
1
+ import { defineMarkRule } from "./mark-rule-wEOcDt6i.js";
2
+
3
+ export { defineMarkRule };
@@ -1,4 +1,39 @@
1
- export { defineMentionSpec } from './_tsup-dts-rollup.js';
2
- export { defineMentionCommands } from './_tsup-dts-rollup.js';
3
- export { defineMention } from './_tsup-dts-rollup.js';
4
- export { MentionAttrs } from './_tsup-dts-rollup.js';
1
+ import { Extension, Union } from "@prosekit/core";
2
+
3
+ //#region src/mention/index.d.ts
4
+ interface MentionAttrs {
5
+ id: string;
6
+ value: string;
7
+ kind: string;
8
+ }
9
+ /**
10
+ * @internal
11
+ */
12
+ type MentionSpecExtension = Extension<{
13
+ Nodes: {
14
+ mention: MentionAttrs;
15
+ };
16
+ }>;
17
+ /**
18
+ * @public
19
+ */
20
+ declare function defineMentionSpec(): MentionSpecExtension;
21
+ /**
22
+ * @internal
23
+ */
24
+ type MentionCommandsExtension = Extension<{
25
+ Commands: {
26
+ insertMention: [attrs: MentionAttrs];
27
+ };
28
+ }>;
29
+ declare function defineMentionCommands(): MentionCommandsExtension;
30
+ /**
31
+ * @internal
32
+ */
33
+ type MentionExtension = Union<[MentionSpecExtension, MentionCommandsExtension]>;
34
+ /**
35
+ * @public
36
+ */
37
+ declare function defineMention(): MentionExtension;
38
+ //#endregion
39
+ export { MentionAttrs, MentionCommandsExtension, MentionExtension, MentionSpecExtension, defineMention, defineMentionCommands, defineMentionSpec };
@@ -1,56 +1,58 @@
1
- // src/mention/index.ts
2
- import {
3
- defineCommands,
4
- defineNodeSpec,
5
- insertNode,
6
- union
7
- } from "@prosekit/core";
1
+ import { defineCommands, defineNodeSpec, insertNode, union } from "@prosekit/core";
2
+
3
+ //#region src/mention/index.ts
4
+ /**
5
+ * @public
6
+ */
8
7
  function defineMentionSpec() {
9
- return defineNodeSpec({
10
- name: "mention",
11
- atom: true,
12
- group: "inline",
13
- attrs: {
14
- id: {},
15
- value: {},
16
- kind: { default: "" }
17
- },
18
- inline: true,
19
- leafText: (node) => node.attrs.value.toString(),
20
- parseDOM: [
21
- {
22
- tag: `span[data-mention]`,
23
- getAttrs: (dom) => ({
24
- id: dom.getAttribute("data-id") || "",
25
- kind: dom.getAttribute("data-mention") || "",
26
- value: dom.textContent || ""
27
- })
28
- }
29
- ],
30
- toDOM(node) {
31
- return [
32
- "span",
33
- {
34
- "data-id": node.attrs.id.toString(),
35
- "data-mention": node.attrs.kind.toString()
36
- },
37
- node.attrs.value.toString()
38
- ];
39
- }
40
- });
8
+ return defineNodeSpec({
9
+ name: "mention",
10
+ atom: true,
11
+ group: "inline",
12
+ attrs: {
13
+ id: { validate: "string" },
14
+ value: { validate: "string" },
15
+ kind: {
16
+ default: "",
17
+ validate: "string"
18
+ }
19
+ },
20
+ inline: true,
21
+ leafText: (node) => node.attrs.value.toString(),
22
+ parseDOM: [{
23
+ tag: `span[data-mention]`,
24
+ getAttrs: (dom) => ({
25
+ id: dom.getAttribute("data-id") || "",
26
+ kind: dom.getAttribute("data-mention") || "",
27
+ value: dom.textContent || ""
28
+ })
29
+ }],
30
+ toDOM(node) {
31
+ return [
32
+ "span",
33
+ {
34
+ "data-id": node.attrs.id.toString(),
35
+ "data-mention": node.attrs.kind.toString()
36
+ },
37
+ node.attrs.value.toString()
38
+ ];
39
+ }
40
+ });
41
41
  }
42
42
  function defineMentionCommands() {
43
- return defineCommands({
44
- insertMention: (attrs) => {
45
- return insertNode({ type: "mention", attrs });
46
- }
47
- });
43
+ return defineCommands({ insertMention: (attrs) => {
44
+ return insertNode({
45
+ type: "mention",
46
+ attrs
47
+ });
48
+ } });
48
49
  }
50
+ /**
51
+ * @public
52
+ */
49
53
  function defineMention() {
50
- return union(defineMentionSpec(), defineMentionCommands());
54
+ return union(defineMentionSpec(), defineMentionCommands());
51
55
  }
52
- export {
53
- defineMention,
54
- defineMentionCommands,
55
- defineMentionSpec
56
- };
56
+
57
+ //#endregion
58
+ export { defineMention, defineMentionCommands, defineMentionSpec };
@@ -1,2 +1,17 @@
1
- export { defineModClickPrevention } from './_tsup-dts-rollup.js';
2
- export { ModClickPreventionExtension } from './_tsup-dts-rollup.js';
1
+ import { PlainExtension } from "@prosekit/core";
2
+
3
+ //#region src/mod-click-prevention/index.d.ts
4
+
5
+ /**
6
+ * @internal
7
+ */
8
+ type ModClickPreventionExtension = PlainExtension;
9
+ /**
10
+ * By default, clicking a node while holding the mod key will select the node. This
11
+ * extension disables that behavior.
12
+ *
13
+ * @public
14
+ */
15
+ declare function defineModClickPrevention(): ModClickPreventionExtension;
16
+ //#endregion
17
+ export { ModClickPreventionExtension, defineModClickPrevention };
@@ -1,20 +1,24 @@
1
- // src/mod-click-prevention/index.ts
2
- import {
3
- definePlugin,
4
- isApple
5
- } from "@prosekit/core";
6
- import {
7
- Plugin,
8
- PluginKey
9
- } from "@prosekit/pm/state";
1
+ import { definePlugin, isApple } from "@prosekit/core";
2
+ import { Plugin, PluginKey } from "@prosekit/pm/state";
3
+
4
+ //#region src/mod-click-prevention/index.ts
5
+ /**
6
+ * By default, clicking a node while holding the mod key will select the node. This
7
+ * extension disables that behavior.
8
+ *
9
+ * @public
10
+ */
10
11
  function defineModClickPrevention() {
11
- return definePlugin(new Plugin({ key, props: { handleClick } }));
12
+ return definePlugin(new Plugin({
13
+ key,
14
+ props: { handleClick }
15
+ }));
12
16
  }
13
- var key = new PluginKey("prosekit-mod-click-prevention");
17
+ const key = new PluginKey("prosekit-mod-click-prevention");
14
18
  function handleClick(_view, _pos, event) {
15
- return !!event[selectNodeModifier];
19
+ return !!event[selectNodeModifier];
16
20
  }
17
- var selectNodeModifier = isApple ? "metaKey" : "ctrlKey";
18
- export {
19
- defineModClickPrevention
20
- };
21
+ const selectNodeModifier = isApple ? "metaKey" : "ctrlKey";
22
+
23
+ //#endregion
24
+ export { defineModClickPrevention };
@@ -1,7 +1,60 @@
1
- export { defineParagraph } from './_tsup-dts-rollup.js';
2
- export { ParagraphExtension } from './_tsup-dts-rollup.js';
3
- export { defineParagraphCommands } from './_tsup-dts-rollup.js';
4
- export { ParagraphCommandsExtension } from './_tsup-dts-rollup.js';
5
- export { defineParagraphKeymap } from './_tsup-dts-rollup.js';
6
- export { defineParagraphSpec } from './_tsup-dts-rollup.js';
7
- export { ParagraphSpecExtension } from './_tsup-dts-rollup.js';
1
+ import { Extension, PlainExtension, Union } from "@prosekit/core";
2
+ import { Command } from "@prosekit/pm/state";
3
+ import { Attrs } from "@prosekit/pm/model";
4
+
5
+ //#region src/paragraph/paragraph-commands.d.ts
6
+ /**
7
+ * @internal
8
+ */
9
+ type ParagraphCommandsExtension = Extension<{
10
+ Commands: {
11
+ setParagraph: [];
12
+ };
13
+ }>;
14
+ /**
15
+ * @internal
16
+ */
17
+
18
+ /**
19
+ * @internal
20
+ */
21
+ declare function defineParagraphCommands(): ParagraphCommandsExtension;
22
+ //#endregion
23
+ //#region src/paragraph/paragraph-spec.d.ts
24
+ /**
25
+ * @internal
26
+ */
27
+ type ParagraphSpecExtension = Extension<{
28
+ Nodes: {
29
+ paragraph: Attrs;
30
+ };
31
+ }>;
32
+ /**
33
+ * @internal
34
+ *
35
+ * Defines a paragraph node spec.
36
+ */
37
+ declare function defineParagraphSpec(): ParagraphSpecExtension;
38
+ //#endregion
39
+ //#region src/paragraph/paragraph.d.ts
40
+ /**
41
+ * @internal
42
+ */
43
+ type ParagraphExtension = Union<[ParagraphSpecExtension, ParagraphCommandsExtension]>;
44
+ /**
45
+ * @public
46
+ *
47
+ * Defines a paragraph node.
48
+ *
49
+ * The paragraph node spec has the highest priority, because it should be the
50
+ * default block node for most cases.
51
+ */
52
+ declare function defineParagraph(): ParagraphExtension;
53
+ //#endregion
54
+ //#region src/paragraph/paragraph-keymap.d.ts
55
+ /**
56
+ * @internal
57
+ */
58
+ declare function defineParagraphKeymap(): PlainExtension;
59
+ //#endregion
60
+ export { ParagraphCommandsExtension, ParagraphExtension, ParagraphSpecExtension, defineParagraph, defineParagraphCommands, defineParagraphKeymap, defineParagraphSpec };
@@ -1,59 +1,60 @@
1
- // src/paragraph/paragraph.ts
2
- import {
3
- Priority,
4
- union,
5
- withPriority
6
- } from "@prosekit/core";
1
+ import { Priority, defineCommands, defineKeymap, defineNodeSpec, setBlockType, union, withPriority } from "@prosekit/core";
7
2
 
8
- // src/paragraph/paragraph-commands.ts
9
- import {
10
- defineCommands,
11
- setBlockType
12
- } from "@prosekit/core";
3
+ //#region src/paragraph/paragraph-commands.ts
4
+ /**
5
+ * @internal
6
+ */
13
7
  function setParagraph() {
14
- return setBlockType({ type: "paragraph" });
8
+ return setBlockType({ type: "paragraph" });
15
9
  }
10
+ /**
11
+ * @internal
12
+ */
16
13
  function defineParagraphCommands() {
17
- return defineCommands({ setParagraph });
14
+ return defineCommands({ setParagraph });
18
15
  }
19
16
 
20
- // src/paragraph/paragraph-keymap.ts
21
- import {
22
- defineKeymap
23
- } from "@prosekit/core";
17
+ //#endregion
18
+ //#region src/paragraph/paragraph-keymap.ts
19
+ /**
20
+ * @internal
21
+ */
24
22
  function defineParagraphKeymap() {
25
- return defineKeymap({
26
- "mod-alt-0": setParagraph()
27
- });
23
+ return defineKeymap({ "mod-alt-0": setParagraph() });
28
24
  }
29
25
 
30
- // src/paragraph/paragraph-spec.ts
31
- import {
32
- defineNodeSpec
33
- } from "@prosekit/core";
26
+ //#endregion
27
+ //#region src/paragraph/paragraph-spec.ts
28
+ /**
29
+ * @internal
30
+ *
31
+ * Defines a paragraph node spec.
32
+ */
34
33
  function defineParagraphSpec() {
35
- return defineNodeSpec({
36
- name: "paragraph",
37
- content: "inline*",
38
- group: "block",
39
- parseDOM: [{ tag: "p" }],
40
- toDOM() {
41
- return ["p", 0];
42
- }
43
- });
34
+ return defineNodeSpec({
35
+ name: "paragraph",
36
+ content: "inline*",
37
+ group: "block",
38
+ parseDOM: [{ tag: "p" }],
39
+ toDOM() {
40
+ return ["p", 0];
41
+ }
42
+ });
44
43
  }
45
44
 
46
- // src/paragraph/paragraph.ts
45
+ //#endregion
46
+ //#region src/paragraph/paragraph.ts
47
+ /**
48
+ * @public
49
+ *
50
+ * Defines a paragraph node.
51
+ *
52
+ * The paragraph node spec has the highest priority, because it should be the
53
+ * default block node for most cases.
54
+ */
47
55
  function defineParagraph() {
48
- return union(
49
- withPriority(defineParagraphSpec(), Priority.highest),
50
- defineParagraphCommands(),
51
- defineParagraphKeymap()
52
- );
56
+ return union(withPriority(defineParagraphSpec(), Priority.highest), defineParagraphCommands(), defineParagraphKeymap());
53
57
  }
54
- export {
55
- defineParagraph,
56
- defineParagraphCommands,
57
- defineParagraphKeymap,
58
- defineParagraphSpec
59
- };
58
+
59
+ //#endregion
60
+ export { defineParagraph, defineParagraphCommands, defineParagraphKeymap, defineParagraphSpec };
@@ -1,2 +1,33 @@
1
- export { definePlaceholder } from './_tsup-dts-rollup.js';
2
- export { PlaceholderOptions } from './_tsup-dts-rollup.js';
1
+ import { PlainExtension } from "@prosekit/core";
2
+ import { EditorState } from "@prosekit/pm/state";
3
+
4
+ //#region src/placeholder/index.d.ts
5
+ interface PlaceholderOptions {
6
+ /**
7
+ * The placeholder to use. It can be a static string or a function that
8
+ * receives the current editor state and returns a string.
9
+ */
10
+ placeholder: string | ((state: EditorState) => string);
11
+ /**
12
+ * By default, the placeholder text will be shown whenever the current text
13
+ * cursor is in an empty text node and it's not inside a code block or a
14
+ * table node.
15
+ *
16
+ * If you only want to show the placeholder when the whole doc is empty, you
17
+ * can set this option to 'doc'.
18
+ *
19
+ * You can also pass a function that receives the current editor state and
20
+ * returns a boolean value to determine whether the placeholder should be
21
+ * shown.
22
+ *
23
+ * @default 'block'
24
+ */
25
+ strategy?: "doc" | "block" | ((state: EditorState) => boolean);
26
+ }
27
+ /**
28
+ * Add a placeholder text to the editor when the current block or document is
29
+ * empty.
30
+ */
31
+ declare function definePlaceholder(options: PlaceholderOptions): PlainExtension;
32
+ //#endregion
33
+ export { PlaceholderOptions, definePlaceholder };
@@ -1,68 +1,51 @@
1
- import {
2
- findTable
3
- } from "./chunk-QVFEYPQ6.js";
1
+ import { findTable } from "./table-DnVliJ6E.js";
2
+ import { definePlugin, isInCodeBlock, maybeRun } from "@prosekit/core";
3
+ import { Plugin, PluginKey } from "@prosekit/pm/state";
4
+ import { Decoration, DecorationSet } from "@prosekit/pm/view";
4
5
 
5
- // src/placeholder/index.ts
6
- import {
7
- definePlugin,
8
- isInCodeBlock,
9
- maybeRun
10
- } from "@prosekit/core";
11
- import {
12
- Plugin,
13
- PluginKey
14
- } from "@prosekit/pm/state";
15
- import {
16
- Decoration,
17
- DecorationSet
18
- } from "@prosekit/pm/view";
6
+ //#region src/placeholder/index.ts
7
+ /**
8
+ * Add a placeholder text to the editor when the current block or document is
9
+ * empty.
10
+ */
19
11
  function definePlaceholder(options) {
20
- return definePlugin(createPlaceholderPlugin(options));
12
+ return definePlugin(createPlaceholderPlugin(options));
21
13
  }
22
- function createPlaceholderPlugin({
23
- placeholder,
24
- strategy = "block"
25
- }) {
26
- return new Plugin({
27
- key: new PluginKey("prosekit-placeholder"),
28
- props: {
29
- decorations: (state) => {
30
- const strategyFn = typeof strategy === "function" ? strategy : strategy === "doc" ? docStrategy : defaultStrategy;
31
- if (!strategyFn(state)) {
32
- return null;
33
- }
34
- const placeholderText = maybeRun(placeholder, state);
35
- const deco = createPlaceholderDecoration(state, placeholderText);
36
- if (!deco) {
37
- return null;
38
- }
39
- return DecorationSet.create(state.doc, [deco]);
40
- }
41
- }
42
- });
14
+ function createPlaceholderPlugin({ placeholder, strategy = "block" }) {
15
+ return new Plugin({
16
+ key: new PluginKey("prosekit-placeholder"),
17
+ props: { decorations: (state) => {
18
+ const strategyFn = typeof strategy === "function" ? strategy : strategy === "doc" ? docStrategy : defaultStrategy;
19
+ if (!strategyFn(state)) return null;
20
+ const placeholderText = maybeRun(placeholder, state);
21
+ const deco = createPlaceholderDecoration(state, placeholderText);
22
+ if (!deco) return null;
23
+ return DecorationSet.create(state.doc, [deco]);
24
+ } }
25
+ });
43
26
  }
44
27
  function defaultStrategy(state) {
45
- return !isInCodeBlock(state.selection) && !findTable(state.selection.$from);
28
+ return !isInCodeBlock(state.selection) && !findTable(state.selection.$from);
46
29
  }
47
30
  function docStrategy(state) {
48
- return isDocEmpty(state.doc) && defaultStrategy(state);
31
+ return isDocEmpty(state.doc) && defaultStrategy(state);
49
32
  }
50
33
  function isDocEmpty(doc) {
51
- return doc.childCount <= 1 && !doc.firstChild?.content.size;
34
+ return doc.childCount <= 1 && !doc.firstChild?.content.size;
52
35
  }
53
36
  function createPlaceholderDecoration(state, placeholderText) {
54
- if (!placeholderText) return null;
55
- const { selection } = state;
56
- if (!selection.empty) return null;
57
- const $pos = selection.$anchor;
58
- const node = $pos.parent;
59
- if (node.content.size > 0) return null;
60
- const before = $pos.before();
61
- return Decoration.node(before, before + node.nodeSize, {
62
- "class": "prosekit-placeholder",
63
- "data-placeholder": placeholderText
64
- });
37
+ if (!placeholderText) return null;
38
+ const { selection } = state;
39
+ if (!selection.empty) return null;
40
+ const $pos = selection.$anchor;
41
+ const node = $pos.parent;
42
+ if (node.content.size > 0) return null;
43
+ const before = $pos.before();
44
+ return Decoration.node(before, before + node.nodeSize, {
45
+ "class": "prosekit-placeholder",
46
+ "data-placeholder": placeholderText
47
+ });
65
48
  }
66
- export {
67
- definePlaceholder
68
- };
49
+
50
+ //#endregion
51
+ export { definePlaceholder };
@@ -1 +1,10 @@
1
- export { defineReadonly } from './_tsup-dts-rollup.js';
1
+ import { PlainExtension } from "@prosekit/core";
2
+
3
+ //#region src/readonly/index.d.ts
4
+
5
+ /**
6
+ * Make the editor read-only.
7
+ */
8
+ declare function defineReadonly(): PlainExtension;
9
+ //#endregion
10
+ export { defineReadonly };
@@ -1,18 +1,17 @@
1
- // src/readonly/index.ts
2
1
  import { definePlugin } from "@prosekit/core";
3
- import {
4
- PluginKey,
5
- ProseMirrorPlugin
6
- } from "@prosekit/pm/state";
2
+ import { PluginKey, ProseMirrorPlugin } from "@prosekit/pm/state";
3
+
4
+ //#region src/readonly/index.ts
5
+ /**
6
+ * Make the editor read-only.
7
+ */
7
8
  function defineReadonly() {
8
- return definePlugin(plugin);
9
+ return definePlugin(plugin);
9
10
  }
10
- var plugin = new ProseMirrorPlugin({
11
- key: new PluginKey("prosekey-readonly"),
12
- props: {
13
- editable: () => false
14
- }
11
+ const plugin = new ProseMirrorPlugin({
12
+ key: new PluginKey("prosekey-readonly"),
13
+ props: { editable: () => false }
15
14
  });
16
- export {
17
- defineReadonly
18
- };
15
+
16
+ //#endregion
17
+ export { defineReadonly };