@prosekit/extensions 0.7.24 → 0.9.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.
- package/dist/commit/style.css +2 -1
- package/dist/commit/style.js +0 -0
- package/dist/enter-rule-RdhEA900.js +96 -0
- package/dist/gap-cursor/style.css +8 -5
- package/dist/gap-cursor/style.js +0 -0
- package/dist/input-rule-Gji4N7Oe.js +93 -0
- package/dist/list/style.css +7 -7
- package/dist/list/style.js +0 -0
- package/dist/loro/style.css +21 -17
- package/dist/loro/style.js +0 -0
- package/dist/mark-rule-wEOcDt6i.js +160 -0
- package/dist/placeholder/style.css +5 -5
- package/dist/placeholder/style.js +0 -0
- package/dist/prosekit-extensions-autocomplete.d.ts +33 -3
- package/dist/prosekit-extensions-autocomplete.js +122 -174
- package/dist/prosekit-extensions-blockquote.d.ts +51 -8
- package/dist/prosekit-extensions-blockquote.js +64 -78
- package/dist/prosekit-extensions-bold.d.ts +61 -8
- package/dist/prosekit-extensions-bold.js +61 -73
- package/dist/prosekit-extensions-code-block.d.ts +172 -20
- package/dist/prosekit-extensions-code-block.js +201 -184
- package/dist/prosekit-extensions-code.d.ts +61 -8
- package/dist/prosekit-extensions-code.js +44 -55
- package/dist/prosekit-extensions-commit.d.ts +53 -4
- package/dist/prosekit-extensions-commit.js +142 -183
- package/dist/prosekit-extensions-doc.d.ts +22 -0
- package/dist/prosekit-extensions-doc.js +16 -0
- package/dist/prosekit-extensions-drop-cursor.d.ts +34 -3
- package/dist/prosekit-extensions-drop-cursor.js +14 -8
- package/dist/prosekit-extensions-enter-rule.d.ts +106 -5
- package/dist/prosekit-extensions-enter-rule.js +3 -8
- package/dist/prosekit-extensions-file.d.ts +126 -8
- package/dist/prosekit-extensions-file.js +111 -132
- package/dist/prosekit-extensions-gap-cursor.d.ts +29 -2
- package/dist/prosekit-extensions-gap-cursor.js +21 -9
- package/dist/prosekit-extensions-hard-break.d.ts +58 -0
- package/dist/prosekit-extensions-hard-break.js +58 -0
- package/dist/prosekit-extensions-heading.d.ts +69 -9
- package/dist/prosekit-extensions-heading.js +121 -95
- package/dist/prosekit-extensions-horizontal-rule.d.ts +41 -8
- package/dist/prosekit-extensions-horizontal-rule.js +53 -71
- package/dist/prosekit-extensions-image.d.ts +53 -7
- package/dist/prosekit-extensions-image.js +71 -62
- package/dist/prosekit-extensions-input-rule.d.ts +134 -6
- package/dist/prosekit-extensions-input-rule.js +3 -14
- package/dist/prosekit-extensions-italic.d.ts +61 -8
- package/dist/prosekit-extensions-italic.js +51 -63
- package/dist/prosekit-extensions-link.d.ts +65 -10
- package/dist/prosekit-extensions-link.js +95 -100
- package/dist/prosekit-extensions-list.d.ts +114 -17
- package/dist/prosekit-extensions-list.js +115 -158
- package/dist/prosekit-extensions-loro.d.ts +78 -11
- package/dist/prosekit-extensions-loro.js +49 -77
- package/dist/prosekit-extensions-mark-rule.d.ts +41 -2
- package/dist/prosekit-extensions-mark-rule.js +3 -6
- package/dist/prosekit-extensions-mention.d.ts +40 -4
- package/dist/prosekit-extensions-mention.js +52 -50
- package/dist/prosekit-extensions-mod-click-prevention.d.ts +20 -2
- package/dist/prosekit-extensions-mod-click-prevention.js +20 -16
- package/dist/prosekit-extensions-paragraph.d.ts +65 -0
- package/dist/prosekit-extensions-paragraph.js +60 -0
- package/dist/prosekit-extensions-placeholder.d.ts +32 -2
- package/dist/prosekit-extensions-placeholder.js +39 -56
- package/dist/prosekit-extensions-readonly.d.ts +13 -1
- package/dist/prosekit-extensions-readonly.js +13 -14
- package/dist/prosekit-extensions-search.d.ts +77 -3
- package/dist/prosekit-extensions-search.js +48 -47
- package/dist/prosekit-extensions-strike.d.ts +50 -8
- package/dist/prosekit-extensions-strike.js +44 -49
- package/dist/prosekit-extensions-table.d.ts +237 -26
- package/dist/prosekit-extensions-table.js +3 -34
- package/dist/prosekit-extensions-text-align.d.ts +72 -8
- package/dist/prosekit-extensions-text-align.js +63 -44
- package/dist/prosekit-extensions-text.d.ts +22 -0
- package/dist/prosekit-extensions-text.js +15 -0
- package/dist/prosekit-extensions-underline.d.ts +46 -7
- package/dist/prosekit-extensions-underline.js +33 -37
- package/dist/prosekit-extensions-virtual-selection.d.ts +24 -2
- package/dist/prosekit-extensions-virtual-selection.js +49 -52
- package/dist/prosekit-extensions-yjs.d.ts +99 -14
- package/dist/prosekit-extensions-yjs.js +88 -131
- package/dist/prosekit-extensions.d.ts +1 -1
- package/dist/search/style.css +5 -5
- package/dist/search/style.js +0 -0
- package/dist/shiki-highlighter-chunk-Cd3WeOKL.d.ts +19 -0
- package/dist/shiki-highlighter-chunk.d.ts +2 -0
- package/dist/shiki-highlighter-chunk.js +34 -43
- package/dist/table/style.css +18 -17
- package/dist/table/style.js +0 -0
- package/dist/table-DnVliJ6E.js +287 -0
- package/dist/virtual-selection/style.css +2 -2
- package/dist/virtual-selection/style.js +0 -0
- package/dist/yjs/style.css +15 -17
- package/dist/yjs/style.js +0 -0
- package/package.json +103 -52
- package/dist/_tsup-dts-rollup.d.ts +0 -2500
- package/dist/chunk-6UYLCVBX.js +0 -185
- package/dist/chunk-BV3SHIMW.js +0 -98
- package/dist/chunk-D54VSLLS.js +0 -105
- package/dist/chunk-HFAZX2J3.js +0 -306
@@ -1,2 +1,41 @@
|
|
1
|
-
|
2
|
-
|
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
|
+
* The options for {@link defineMarkRule}.
|
7
|
+
*
|
8
|
+
* @public
|
9
|
+
*/
|
10
|
+
/**
|
11
|
+
* The options for {@link defineMarkRule}.
|
12
|
+
*
|
13
|
+
* @public
|
14
|
+
*/
|
15
|
+
interface MarkRuleOptions {
|
16
|
+
/**
|
17
|
+
* The regular expression to match against. It must has a `g` flag to match
|
18
|
+
* all instances of the mark.
|
19
|
+
*/
|
20
|
+
regex: RegExp;
|
21
|
+
/**
|
22
|
+
* The mark type to apply to the matched text.
|
23
|
+
*/
|
24
|
+
type: string | MarkType;
|
25
|
+
/**
|
26
|
+
* Attributes to set on the mark. If a function is provided, it will be called
|
27
|
+
* with the matched result from the regular expression.
|
28
|
+
*
|
29
|
+
* @default null
|
30
|
+
*/
|
31
|
+
attrs?: Attrs | null | ((match: RegExpMatchArray) => Attrs | null);
|
32
|
+
} //#endregion
|
33
|
+
//#region src/mark-rule/mark-rule.d.ts
|
34
|
+
/**
|
35
|
+
* A mark rule is something that can automatically apply marks to text if it
|
36
|
+
* matches a certain pattern, and remove them if it doesn't match anymore.
|
37
|
+
*/
|
38
|
+
declare function defineMarkRule(options: MarkRuleOptions): PlainExtension;
|
39
|
+
|
40
|
+
//#endregion
|
41
|
+
export { MarkRuleOptions, defineMarkRule };
|
@@ -1,4 +1,40 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
+
|
39
|
+
//#endregion
|
40
|
+
export { MentionAttrs, MentionCommandsExtension, MentionExtension, MentionSpecExtension, defineMention, defineMentionCommands, defineMentionSpec };
|
@@ -1,56 +1,58 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
54
|
+
return union(defineMentionSpec(), defineMentionCommands());
|
51
55
|
}
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
defineMentionSpec
|
56
|
-
};
|
56
|
+
|
57
|
+
//#endregion
|
58
|
+
export { defineMention, defineMentionCommands, defineMentionSpec };
|
@@ -1,2 +1,20 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { PlainExtension } from "@prosekit/core";
|
2
|
+
|
3
|
+
//#region src/mod-click-prevention/index.d.ts
|
4
|
+
/**
|
5
|
+
* @internal
|
6
|
+
*/
|
7
|
+
/**
|
8
|
+
* @internal
|
9
|
+
*/
|
10
|
+
type ModClickPreventionExtension = PlainExtension;
|
11
|
+
/**
|
12
|
+
* By default, clicking a node while holding the mod key will select the node. This
|
13
|
+
* extension disables that behavior.
|
14
|
+
*
|
15
|
+
* @public
|
16
|
+
*/
|
17
|
+
declare function defineModClickPrevention(): ModClickPreventionExtension;
|
18
|
+
|
19
|
+
//#endregion
|
20
|
+
export { ModClickPreventionExtension, defineModClickPrevention };
|
@@ -1,20 +1,24 @@
|
|
1
|
-
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
12
|
+
return definePlugin(new Plugin({
|
13
|
+
key,
|
14
|
+
props: { handleClick }
|
15
|
+
}));
|
12
16
|
}
|
13
|
-
|
17
|
+
const key = new PluginKey("prosekit-mod-click-prevention");
|
14
18
|
function handleClick(_view, _pos, event) {
|
15
|
-
|
19
|
+
return !!event[selectNodeModifier];
|
16
20
|
}
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
};
|
21
|
+
const selectNodeModifier = isApple ? "metaKey" : "ctrlKey";
|
22
|
+
|
23
|
+
//#endregion
|
24
|
+
export { defineModClickPrevention };
|
@@ -0,0 +1,65 @@
|
|
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
|
+
/**
|
10
|
+
* @internal
|
11
|
+
*/
|
12
|
+
type ParagraphCommandsExtension = Extension<{
|
13
|
+
Commands: {
|
14
|
+
setParagraph: [];
|
15
|
+
};
|
16
|
+
}>;
|
17
|
+
/**
|
18
|
+
* @internal
|
19
|
+
*/
|
20
|
+
|
21
|
+
/**
|
22
|
+
* @internal
|
23
|
+
*/
|
24
|
+
declare function defineParagraphCommands(): ParagraphCommandsExtension; //#endregion
|
25
|
+
//#region src/paragraph/paragraph-spec.d.ts
|
26
|
+
/**
|
27
|
+
* @internal
|
28
|
+
*/
|
29
|
+
type ParagraphSpecExtension = Extension<{
|
30
|
+
Nodes: {
|
31
|
+
paragraph: Attrs;
|
32
|
+
};
|
33
|
+
}>;
|
34
|
+
/**
|
35
|
+
* @internal
|
36
|
+
*
|
37
|
+
* Defines a paragraph node spec.
|
38
|
+
*/
|
39
|
+
declare function defineParagraphSpec(): ParagraphSpecExtension;
|
40
|
+
|
41
|
+
//#endregion
|
42
|
+
//#region src/paragraph/paragraph.d.ts
|
43
|
+
/**
|
44
|
+
* @internal
|
45
|
+
*/
|
46
|
+
type ParagraphExtension = Union<[ParagraphSpecExtension, ParagraphCommandsExtension]>;
|
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
|
+
*/
|
55
|
+
declare function defineParagraph(): ParagraphExtension;
|
56
|
+
|
57
|
+
//#endregion
|
58
|
+
//#region src/paragraph/paragraph-keymap.d.ts
|
59
|
+
/**
|
60
|
+
* @internal
|
61
|
+
*/
|
62
|
+
declare function defineParagraphKeymap(): PlainExtension;
|
63
|
+
|
64
|
+
//#endregion
|
65
|
+
export { ParagraphCommandsExtension, ParagraphExtension, ParagraphSpecExtension, defineParagraph, defineParagraphCommands, defineParagraphKeymap, defineParagraphSpec };
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { Priority, defineCommands, defineKeymap, defineNodeSpec, setBlockType, union, withPriority } from "@prosekit/core";
|
2
|
+
|
3
|
+
//#region src/paragraph/paragraph-commands.ts
|
4
|
+
/**
|
5
|
+
* @internal
|
6
|
+
*/
|
7
|
+
function setParagraph() {
|
8
|
+
return setBlockType({ type: "paragraph" });
|
9
|
+
}
|
10
|
+
/**
|
11
|
+
* @internal
|
12
|
+
*/
|
13
|
+
function defineParagraphCommands() {
|
14
|
+
return defineCommands({ setParagraph });
|
15
|
+
}
|
16
|
+
|
17
|
+
//#endregion
|
18
|
+
//#region src/paragraph/paragraph-keymap.ts
|
19
|
+
/**
|
20
|
+
* @internal
|
21
|
+
*/
|
22
|
+
function defineParagraphKeymap() {
|
23
|
+
return defineKeymap({ "mod-alt-0": setParagraph() });
|
24
|
+
}
|
25
|
+
|
26
|
+
//#endregion
|
27
|
+
//#region src/paragraph/paragraph-spec.ts
|
28
|
+
/**
|
29
|
+
* @internal
|
30
|
+
*
|
31
|
+
* Defines a paragraph node spec.
|
32
|
+
*/
|
33
|
+
function defineParagraphSpec() {
|
34
|
+
return defineNodeSpec({
|
35
|
+
name: "paragraph",
|
36
|
+
content: "inline*",
|
37
|
+
group: "block",
|
38
|
+
parseDOM: [{ tag: "p" }],
|
39
|
+
toDOM() {
|
40
|
+
return ["p", 0];
|
41
|
+
}
|
42
|
+
});
|
43
|
+
}
|
44
|
+
|
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
|
+
*/
|
55
|
+
function defineParagraph() {
|
56
|
+
return union(withPriority(defineParagraphSpec(), Priority.highest), defineParagraphCommands(), defineParagraphKeymap());
|
57
|
+
}
|
58
|
+
|
59
|
+
//#endregion
|
60
|
+
export { defineParagraph, defineParagraphCommands, defineParagraphKeymap, defineParagraphSpec };
|
@@ -1,2 +1,32 @@
|
|
1
|
-
|
2
|
-
|
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; //#endregion
|
32
|
+
export { PlaceholderOptions, definePlaceholder };
|
@@ -1,68 +1,51 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
} from "
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
12
|
+
return definePlugin(createPlaceholderPlugin(options));
|
21
13
|
}
|
22
|
-
function createPlaceholderPlugin({
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
28
|
+
return !isInCodeBlock(state.selection) && !findTable(state.selection.$from);
|
46
29
|
}
|
47
30
|
function docStrategy(state) {
|
48
|
-
|
31
|
+
return isDocEmpty(state.doc) && defaultStrategy(state);
|
49
32
|
}
|
50
33
|
function isDocEmpty(doc) {
|
51
|
-
|
34
|
+
return doc.childCount <= 1 && !doc.firstChild?.content.size;
|
52
35
|
}
|
53
36
|
function createPlaceholderDecoration(state, placeholderText) {
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
67
|
-
|
68
|
-
};
|
49
|
+
|
50
|
+
//#endregion
|
51
|
+
export { definePlaceholder };
|
@@ -1 +1,13 @@
|
|
1
|
-
|
1
|
+
import { PlainExtension } from "@prosekit/core";
|
2
|
+
|
3
|
+
//#region src/readonly/index.d.ts
|
4
|
+
/**
|
5
|
+
* Make the editor read-only.
|
6
|
+
*/
|
7
|
+
/**
|
8
|
+
* Make the editor read-only.
|
9
|
+
*/
|
10
|
+
declare function defineReadonly(): PlainExtension;
|
11
|
+
|
12
|
+
//#endregion
|
13
|
+
export { defineReadonly };
|
@@ -1,18 +1,17 @@
|
|
1
|
-
// src/readonly/index.ts
|
2
1
|
import { definePlugin } from "@prosekit/core";
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
9
|
+
return definePlugin(plugin);
|
9
10
|
}
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
editable: () => false
|
14
|
-
}
|
11
|
+
const plugin = new ProseMirrorPlugin({
|
12
|
+
key: new PluginKey("prosekey-readonly"),
|
13
|
+
props: { editable: () => false }
|
15
14
|
});
|
16
|
-
|
17
|
-
|
18
|
-
};
|
15
|
+
|
16
|
+
//#endregion
|
17
|
+
export { defineReadonly };
|
@@ -1,3 +1,77 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
import { Extension, PlainExtension } from "@prosekit/core";
|
2
|
+
|
3
|
+
//#region src/search/index.d.ts
|
4
|
+
/**
|
5
|
+
* Options for {@link defineSearchQuery}
|
6
|
+
*
|
7
|
+
* @public
|
8
|
+
*/
|
9
|
+
/**
|
10
|
+
* Options for {@link defineSearchQuery}
|
11
|
+
*
|
12
|
+
* @public
|
13
|
+
*/
|
14
|
+
interface SearchQueryOptions {
|
15
|
+
/**
|
16
|
+
* The search string (or regular expression).
|
17
|
+
*/
|
18
|
+
search: string;
|
19
|
+
/**
|
20
|
+
* The replace text.
|
21
|
+
*/
|
22
|
+
replace?: string;
|
23
|
+
/**
|
24
|
+
* Indicates whether the search is case-sensitive
|
25
|
+
*
|
26
|
+
* @default false
|
27
|
+
*/
|
28
|
+
caseSensitive?: boolean;
|
29
|
+
/**
|
30
|
+
* By default, string search will replace `\n`, `\r`, and `\t` in the query
|
31
|
+
* with newline, return, and tab characters. When this is set to true, that
|
32
|
+
* behavior is disabled.
|
33
|
+
*
|
34
|
+
* @default false
|
35
|
+
*/
|
36
|
+
literal?: boolean;
|
37
|
+
/**
|
38
|
+
* When true, the search string is interpreted as a regular expression.
|
39
|
+
*
|
40
|
+
* @default false
|
41
|
+
*/
|
42
|
+
regexp?: boolean;
|
43
|
+
/**
|
44
|
+
* Enable whole-word matching.
|
45
|
+
*
|
46
|
+
* @default false
|
47
|
+
*/
|
48
|
+
wholeWord?: boolean;
|
49
|
+
}
|
50
|
+
/**
|
51
|
+
* Defines an extension that stores a current search query and replace string.
|
52
|
+
*
|
53
|
+
* @public
|
54
|
+
*/
|
55
|
+
declare function defineSearchQuery(options: SearchQueryOptions): PlainExtension;
|
56
|
+
/**
|
57
|
+
* @internal
|
58
|
+
*/
|
59
|
+
type SearchCommandsExtension = Extension<{
|
60
|
+
Commands: {
|
61
|
+
findNext: [];
|
62
|
+
findPrev: [];
|
63
|
+
findNextNoWrap: [];
|
64
|
+
findPrevNoWrap: [];
|
65
|
+
replaceNext: [];
|
66
|
+
replaceNextNoWrap: [];
|
67
|
+
replaceCurrent: [];
|
68
|
+
replaceAll: [];
|
69
|
+
};
|
70
|
+
}>;
|
71
|
+
/**
|
72
|
+
* Defines commands for search and replace.
|
73
|
+
*
|
74
|
+
* @public
|
75
|
+
*/
|
76
|
+
declare function defineSearchCommands(): SearchCommandsExtension; //#endregion
|
77
|
+
export { SearchCommandsExtension, SearchQueryOptions, defineSearchCommands, defineSearchQuery };
|