@doist/typist 10.0.0-next.1 → 10.0.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/CHANGELOG.md +12 -0
- package/dist/components/typist-editor.d.ts +126 -123
- package/dist/components/typist-editor.d.ts.map +1 -1
- package/dist/components/typist-editor.helper.d.ts +8 -11
- package/dist/components/typist-editor.helper.d.ts.map +1 -1
- package/dist/components/typist-editor.helper.js +21 -19
- package/dist/components/typist-editor.helper.js.map +1 -0
- package/dist/components/typist-editor.js +133 -135
- package/dist/components/typist-editor.js.map +1 -0
- package/dist/constants/common.js +9 -5
- package/dist/constants/common.js.map +1 -0
- package/dist/constants/extension-priorities.d.ts +3 -1
- package/dist/constants/extension-priorities.d.ts.map +1 -1
- package/dist/constants/extension-priorities.js +34 -30
- package/dist/constants/extension-priorities.js.map +1 -0
- package/dist/constants/regular-expressions.js +14 -10
- package/dist/constants/regular-expressions.js.map +1 -0
- package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.d.ts +12 -9
- package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.d.ts.map +1 -1
- package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.js +16 -19
- package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.js.map +1 -0
- package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.d.ts +12 -9
- package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.d.ts.map +1 -1
- package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.js +25 -28
- package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.js.map +1 -0
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.d.ts +24 -22
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.d.ts.map +1 -1
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.js +34 -36
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.js.map +1 -0
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.d.ts +23 -20
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.d.ts.map +1 -1
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.js +15 -8
- package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.js.map +1 -0
- package/dist/extensions/core/extra-editor-commands/extra-editor-commands.js +22 -18
- package/dist/extensions/core/extra-editor-commands/extra-editor-commands.js.map +1 -0
- package/dist/extensions/core/view-event-handlers.d.ts +14 -13
- package/dist/extensions/core/view-event-handlers.d.ts.map +1 -1
- package/dist/extensions/core/view-event-handlers.js +33 -31
- package/dist/extensions/core/view-event-handlers.js.map +1 -0
- package/dist/extensions/plain-text/paste-multiline-text.js +45 -59
- package/dist/extensions/plain-text/paste-multiline-text.js.map +1 -0
- package/dist/extensions/plain-text/plain-text-document.d.ts +7 -7
- package/dist/extensions/plain-text/plain-text-document.d.ts.map +1 -1
- package/dist/extensions/plain-text/plain-text-document.js +14 -13
- package/dist/extensions/plain-text/plain-text-document.js.map +1 -0
- package/dist/extensions/plain-text/plain-text-kit.d.ts +35 -33
- package/dist/extensions/plain-text/plain-text-kit.d.ts.map +1 -1
- package/dist/extensions/plain-text/plain-text-kit.js +33 -48
- package/dist/extensions/plain-text/plain-text-kit.js.map +1 -0
- package/dist/extensions/plain-text/plain-text-paragraph.d.ts +2 -9
- package/dist/extensions/plain-text/plain-text-paragraph.js +11 -11
- package/dist/extensions/plain-text/plain-text-paragraph.js.map +1 -0
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.js +37 -81
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.js.map +1 -0
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.js +32 -42
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.js.map +1 -0
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.js +24 -37
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.js.map +1 -0
- package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.js +21 -13
- package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.js.map +1 -0
- package/dist/extensions/rich-text/bold-and-italics.js +42 -40
- package/dist/extensions/rich-text/bold-and-italics.js.map +1 -0
- package/dist/extensions/rich-text/curvenote-codemark.js +16 -14
- package/dist/extensions/rich-text/curvenote-codemark.js.map +1 -0
- package/dist/extensions/rich-text/paste-emojis.js +20 -22
- package/dist/extensions/rich-text/paste-emojis.js.map +1 -0
- package/dist/extensions/rich-text/paste-markdown.js +46 -86
- package/dist/extensions/rich-text/paste-markdown.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-bullet-list.d.ts +10 -9
- package/dist/extensions/rich-text/rich-text-bullet-list.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-bullet-list.js +42 -56
- package/dist/extensions/rich-text/rich-text-bullet-list.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-code.js +34 -34
- package/dist/extensions/rich-text/rich-text-code.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-document.d.ts +7 -7
- package/dist/extensions/rich-text/rich-text-document.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-document.js +14 -13
- package/dist/extensions/rich-text/rich-text-document.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-heading.d.ts +5 -4
- package/dist/extensions/rich-text/rich-text-heading.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-heading.js +25 -25
- package/dist/extensions/rich-text/rich-text-heading.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-image.d.ts +53 -52
- package/dist/extensions/rich-text/rich-text-image.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-image.js +88 -105
- package/dist/extensions/rich-text/rich-text-image.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-kit.d.ts +127 -125
- package/dist/extensions/rich-text/rich-text-kit.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-kit.js +73 -135
- package/dist/extensions/rich-text/rich-text-kit.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-link.d.ts +5 -4
- package/dist/extensions/rich-text/rich-text-link.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-link.js +82 -90
- package/dist/extensions/rich-text/rich-text-link.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-ordered-list.d.ts +10 -9
- package/dist/extensions/rich-text/rich-text-ordered-list.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-ordered-list.js +42 -56
- package/dist/extensions/rich-text/rich-text-ordered-list.js.map +1 -0
- package/dist/extensions/rich-text/rich-text-strikethrough.d.ts +5 -4
- package/dist/extensions/rich-text/rich-text-strikethrough.d.ts.map +1 -1
- package/dist/extensions/rich-text/rich-text-strikethrough.js +10 -10
- package/dist/extensions/rich-text/rich-text-strikethrough.js.map +1 -0
- package/dist/extensions/shared/copy-markdown-source.js +22 -31
- package/dist/extensions/shared/copy-markdown-source.js.map +1 -0
- package/dist/extensions/shared/paste-html-table-as-string.js +47 -60
- package/dist/extensions/shared/paste-html-table-as-string.js.map +1 -0
- package/dist/extensions/shared/paste-singleline-text.js +31 -39
- package/dist/extensions/shared/paste-singleline-text.js.map +1 -0
- package/dist/factories/create-suggestion-extension.d.ts +74 -74
- package/dist/factories/create-suggestion-extension.d.ts.map +1 -1
- package/dist/factories/create-suggestion-extension.js +139 -161
- package/dist/factories/create-suggestion-extension.js.map +1 -0
- package/dist/helpers/dom.js +9 -5
- package/dist/helpers/dom.js.map +1 -0
- package/dist/helpers/schema.d.ts +5 -3
- package/dist/helpers/schema.d.ts.map +1 -1
- package/dist/helpers/schema.js +25 -21
- package/dist/helpers/schema.js.map +1 -0
- package/dist/helpers/serializer.js +24 -28
- package/dist/helpers/serializer.js.map +1 -0
- package/dist/helpers/unified.js +24 -17
- package/dist/helpers/unified.js.map +1 -0
- package/dist/hooks/use-editor.js +50 -53
- package/dist/hooks/use-editor.js.map +1 -0
- package/dist/index.d.ts +25 -31
- package/dist/index.js +24 -24
- package/dist/serializers/html/html.d.ts +12 -10
- package/dist/serializers/html/html.d.ts.map +1 -1
- package/dist/serializers/html/html.js +67 -127
- package/dist/serializers/html/html.js.map +1 -0
- package/dist/serializers/html/plugins/rehype-code-block.js +17 -17
- package/dist/serializers/html/plugins/rehype-code-block.js.map +1 -0
- package/dist/serializers/html/plugins/rehype-image.js +20 -30
- package/dist/serializers/html/plugins/rehype-image.js.map +1 -0
- package/dist/serializers/html/plugins/rehype-suggestions.js +31 -32
- package/dist/serializers/html/plugins/rehype-suggestions.js.map +1 -0
- package/dist/serializers/html/plugins/rehype-task-list.js +31 -32
- package/dist/serializers/html/plugins/rehype-task-list.js.map +1 -0
- package/dist/serializers/html/plugins/remark-autolink-literal.d.ts +4 -1
- package/dist/serializers/html/plugins/remark-autolink-literal.d.ts.map +1 -1
- package/dist/serializers/html/plugins/remark-autolink-literal.js +25 -21
- package/dist/serializers/html/plugins/remark-autolink-literal.js.map +1 -0
- package/dist/serializers/html/plugins/remark-disable-constructs.js +21 -41
- package/dist/serializers/html/plugins/remark-disable-constructs.js.map +1 -0
- package/dist/serializers/html/plugins/remark-strikethrough.d.ts +5 -2
- package/dist/serializers/html/plugins/remark-strikethrough.d.ts.map +1 -1
- package/dist/serializers/html/plugins/remark-strikethrough.js +25 -21
- package/dist/serializers/html/plugins/remark-strikethrough.js.map +1 -0
- package/dist/serializers/markdown/markdown.d.ts +13 -12
- package/dist/serializers/markdown/markdown.d.ts.map +1 -1
- package/dist/serializers/markdown/markdown.js +78 -154
- package/dist/serializers/markdown/markdown.js.map +1 -0
- package/dist/serializers/markdown/plugins/image.js +27 -24
- package/dist/serializers/markdown/plugins/image.js.map +1 -0
- package/dist/serializers/markdown/plugins/list-item.js +32 -37
- package/dist/serializers/markdown/plugins/list-item.js.map +1 -0
- package/dist/serializers/markdown/plugins/paragraph.js +19 -19
- package/dist/serializers/markdown/plugins/paragraph.js.map +1 -0
- package/dist/serializers/markdown/plugins/strikethrough.js +23 -19
- package/dist/serializers/markdown/plugins/strikethrough.js.map +1 -0
- package/dist/serializers/markdown/plugins/suggestion.js +21 -19
- package/dist/serializers/markdown/plugins/suggestion.js.map +1 -0
- package/dist/serializers/markdown/plugins/task-item.js +31 -35
- package/dist/serializers/markdown/plugins/task-item.js.map +1 -0
- package/dist/utilities/can-insert-node-at.d.ts +12 -5
- package/dist/utilities/can-insert-node-at.d.ts.map +1 -1
- package/dist/utilities/can-insert-node-at.js +10 -8
- package/dist/utilities/can-insert-node-at.js.map +1 -0
- package/dist/utilities/can-insert-suggestion.d.ts +11 -5
- package/dist/utilities/can-insert-suggestion.d.ts.map +1 -1
- package/dist/utilities/can-insert-suggestion.js +15 -12
- package/dist/utilities/can-insert-suggestion.js.map +1 -0
- package/package.json +4 -3
- package/dist/constants/common.d.ts +0 -10
- package/dist/constants/common.d.ts.map +0 -1
- package/dist/constants/regular-expressions.d.ts +0 -18
- package/dist/constants/regular-expressions.d.ts.map +0 -1
- package/dist/extensions/core/extra-editor-commands/extra-editor-commands.d.ts +0 -9
- package/dist/extensions/core/extra-editor-commands/extra-editor-commands.d.ts.map +0 -1
- package/dist/extensions/plain-text/paste-multiline-text.d.ts +0 -10
- package/dist/extensions/plain-text/paste-multiline-text.d.ts.map +0 -1
- package/dist/extensions/plain-text/plain-text-paragraph.d.ts.map +0 -1
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.d.ts +0 -9
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.d.ts.map +0 -1
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.d.ts +0 -9
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.d.ts.map +0 -1
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.d.ts +0 -9
- package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.d.ts.map +0 -1
- package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.d.ts +0 -8
- package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.d.ts.map +0 -1
- package/dist/extensions/rich-text/bold-and-italics.d.ts +0 -8
- package/dist/extensions/rich-text/bold-and-italics.d.ts.map +0 -1
- package/dist/extensions/rich-text/curvenote-codemark.d.ts +0 -11
- package/dist/extensions/rich-text/curvenote-codemark.d.ts.map +0 -1
- package/dist/extensions/rich-text/paste-emojis.d.ts +0 -9
- package/dist/extensions/rich-text/paste-emojis.d.ts.map +0 -1
- package/dist/extensions/rich-text/paste-markdown.d.ts +0 -11
- package/dist/extensions/rich-text/paste-markdown.d.ts.map +0 -1
- package/dist/extensions/rich-text/rich-text-code.d.ts +0 -17
- package/dist/extensions/rich-text/rich-text-code.d.ts.map +0 -1
- package/dist/extensions/shared/copy-markdown-source.d.ts +0 -20
- package/dist/extensions/shared/copy-markdown-source.d.ts.map +0 -1
- package/dist/extensions/shared/paste-html-table-as-string.d.ts +0 -20
- package/dist/extensions/shared/paste-html-table-as-string.d.ts.map +0 -1
- package/dist/extensions/shared/paste-singleline-text.d.ts +0 -10
- package/dist/extensions/shared/paste-singleline-text.d.ts.map +0 -1
- package/dist/helpers/dom.d.ts +0 -8
- package/dist/helpers/dom.d.ts.map +0 -1
- package/dist/helpers/serializer.d.ts +0 -21
- package/dist/helpers/serializer.d.ts.map +0 -1
- package/dist/helpers/unified.d.ts +0 -21
- package/dist/helpers/unified.d.ts.map +0 -1
- package/dist/hooks/use-editor.d.ts +0 -19
- package/dist/hooks/use-editor.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/serializers/html/plugins/rehype-code-block.d.ts +0 -10
- package/dist/serializers/html/plugins/rehype-code-block.d.ts.map +0 -1
- package/dist/serializers/html/plugins/rehype-image.d.ts +0 -11
- package/dist/serializers/html/plugins/rehype-image.d.ts.map +0 -1
- package/dist/serializers/html/plugins/rehype-suggestions.d.ts +0 -10
- package/dist/serializers/html/plugins/rehype-suggestions.d.ts.map +0 -1
- package/dist/serializers/html/plugins/rehype-task-list.d.ts +0 -7
- package/dist/serializers/html/plugins/rehype-task-list.d.ts.map +0 -1
- package/dist/serializers/html/plugins/remark-disable-constructs.d.ts +0 -11
- package/dist/serializers/html/plugins/remark-disable-constructs.d.ts.map +0 -1
- package/dist/serializers/markdown/plugins/image.d.ts +0 -12
- package/dist/serializers/markdown/plugins/image.d.ts.map +0 -1
- package/dist/serializers/markdown/plugins/list-item.d.ts +0 -14
- package/dist/serializers/markdown/plugins/list-item.d.ts.map +0 -1
- package/dist/serializers/markdown/plugins/paragraph.d.ts +0 -13
- package/dist/serializers/markdown/plugins/paragraph.d.ts.map +0 -1
- package/dist/serializers/markdown/plugins/strikethrough.d.ts +0 -13
- package/dist/serializers/markdown/plugins/strikethrough.d.ts.map +0 -1
- package/dist/serializers/markdown/plugins/suggestion.d.ts +0 -11
- package/dist/serializers/markdown/plugins/suggestion.d.ts.map +0 -1
- package/dist/serializers/markdown/plugins/task-item.d.ts +0 -14
- package/dist/serializers/markdown/plugins/task-item.d.ts.map +0 -1
|
@@ -1,66 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Plugin, PluginKey } from
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import { REGEX_LINE_BREAKS } from "../../constants/regular-expressions.js";
|
|
2
|
+
import { ClipboardDataType } from "../../constants/common.js";
|
|
3
|
+
import { Extension } from "@tiptap/core";
|
|
4
|
+
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
5
|
+
import { Fragment, Slice } from "@tiptap/pm/model";
|
|
6
|
+
//#region src/extensions/plain-text/paste-multiline-text.ts
|
|
7
7
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
* Handles a text input or paste event, and replaces all found line breaks with paragraph nodes.
|
|
9
|
+
*
|
|
10
|
+
* @param view The current editor view to process.
|
|
11
|
+
* @param text The multiline text input to parse.
|
|
12
|
+
*/
|
|
13
13
|
function handleTextInputOrPaste(view, text) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (textLine.length === 0) {
|
|
25
|
-
return schema.nodes.paragraph.create();
|
|
26
|
-
}
|
|
27
|
-
return schema.nodes.paragraph.create(null, schema.text(textLine));
|
|
28
|
-
});
|
|
29
|
-
// Inserts the new paragraph nodes at the current cursor position
|
|
30
|
-
// (takes into account if a selection needs to be replaced)
|
|
31
|
-
view.dispatch(tr.replaceSelection(Slice.maxOpen(Fragment.fromArray(paragraphNodes))).scrollIntoView());
|
|
32
|
-
// Suppress the default handling behaviour
|
|
33
|
-
return true;
|
|
14
|
+
const { schema } = view.state;
|
|
15
|
+
const { tr } = view.state;
|
|
16
|
+
const textLines = text.split(REGEX_LINE_BREAKS);
|
|
17
|
+
if (textLines.length === 1) return false;
|
|
18
|
+
const paragraphNodes = textLines.map((textLine) => {
|
|
19
|
+
if (textLine.length === 0) return schema.nodes.paragraph.create();
|
|
20
|
+
return schema.nodes.paragraph.create(null, schema.text(textLine));
|
|
21
|
+
});
|
|
22
|
+
view.dispatch(tr.replaceSelection(Slice.maxOpen(Fragment.fromArray(paragraphNodes))).scrollIntoView());
|
|
23
|
+
return true;
|
|
34
24
|
}
|
|
35
25
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
* The `MultilineDocumentPaste` extension preserves paragraphs (including empty ones) when
|
|
27
|
+
* copying-and-pasting text into the editor, or when inputting multiline text with some sort of
|
|
28
|
+
* automatic text insertion shortcut. This custom extension is required for a plain-text editor
|
|
29
|
+
* configured with `multiline: true`, so that multiline clipboard text is pasted correctly.
|
|
30
|
+
*/
|
|
41
31
|
const PasteMultilineText = Extension.create({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
return handleTextInputOrPaste(view, clipboardText);
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
}),
|
|
63
|
-
];
|
|
64
|
-
},
|
|
32
|
+
name: "pasteMultilineText",
|
|
33
|
+
addProseMirrorPlugins() {
|
|
34
|
+
return [new Plugin({
|
|
35
|
+
key: new PluginKey("pasteMultilineText"),
|
|
36
|
+
props: {
|
|
37
|
+
handleTextInput(view, _, __, inputText) {
|
|
38
|
+
return handleTextInputOrPaste(view, inputText);
|
|
39
|
+
},
|
|
40
|
+
handlePaste(view, event) {
|
|
41
|
+
const clipboardText = event.clipboardData?.getData(ClipboardDataType.Text).trim();
|
|
42
|
+
if (!clipboardText) return false;
|
|
43
|
+
return handleTextInputOrPaste(view, clipboardText);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
})];
|
|
47
|
+
}
|
|
65
48
|
});
|
|
49
|
+
//#endregion
|
|
66
50
|
export { PasteMultilineText };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=paste-multiline-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paste-multiline-text.js","names":[],"sources":["../../../src/extensions/plain-text/paste-multiline-text.ts"],"sourcesContent":["/* eslint-disable no-console */\n\nimport { Extension } from '@tiptap/core'\nimport { Fragment, Slice } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { ClipboardDataType } from '../../constants/common'\nimport { REGEX_LINE_BREAKS } from '../../constants/regular-expressions'\n\nimport type { Schema } from '@tiptap/pm/model'\nimport type { EditorView } from '@tiptap/pm/view'\n\n/**\n * Handles a text input or paste event, and replaces all found line breaks with paragraph nodes.\n *\n * @param view The current editor view to process.\n * @param text The multiline text input to parse.\n */\nfunction handleTextInputOrPaste(view: EditorView, text: string): boolean {\n const { schema } = view.state as { schema: Schema }\n const { tr } = view.state\n\n const textLines = text.split(REGEX_LINE_BREAKS)\n\n // Do not handle the event without a multiline input\n // (i.e. when the user is only typing)\n if (textLines.length === 1) {\n return false\n }\n\n // Build an array of paragraphs nodes (including empty ones)\n const paragraphNodes = textLines.map((textLine) => {\n if (textLine.length === 0) {\n return schema.nodes.paragraph.create()\n }\n\n return schema.nodes.paragraph.create(null, schema.text(textLine))\n })\n\n // Inserts the new paragraph nodes at the current cursor position\n // (takes into account if a selection needs to be replaced)\n view.dispatch(\n tr.replaceSelection(Slice.maxOpen(Fragment.fromArray(paragraphNodes))).scrollIntoView(),\n )\n\n // Suppress the default handling behaviour\n return true\n}\n\n/**\n * The `MultilineDocumentPaste` extension preserves paragraphs (including empty ones) when\n * copying-and-pasting text into the editor, or when inputting multiline text with some sort of\n * automatic text insertion shortcut. This custom extension is required for a plain-text editor\n * configured with `multiline: true`, so that multiline clipboard text is pasted correctly.\n */\nconst PasteMultilineText = Extension.create({\n name: 'pasteMultilineText',\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('pasteMultilineText'),\n props: {\n handleTextInput(view: EditorView, _, __, inputText) {\n return handleTextInputOrPaste(view, inputText)\n },\n handlePaste(view: EditorView, event) {\n const clipboardText = event.clipboardData\n ?.getData(ClipboardDataType.Text)\n .trim()\n\n // Do not handle the event if the clipboard doesn't contain text\n if (!clipboardText) {\n return false\n }\n\n return handleTextInputOrPaste(view, clipboardText)\n },\n },\n }),\n ]\n },\n})\n\nexport { PasteMultilineText }\n"],"mappings":";;;;;;;;;;;;AAkBA,SAAS,uBAAuB,MAAkB,MAAuB;CACrE,MAAM,EAAE,WAAW,KAAK;CACxB,MAAM,EAAE,OAAO,KAAK;CAEpB,MAAM,YAAY,KAAK,MAAM,kBAAkB;AAI/C,KAAI,UAAU,WAAW,EACrB,QAAO;CAIX,MAAM,iBAAiB,UAAU,KAAK,aAAa;AAC/C,MAAI,SAAS,WAAW,EACpB,QAAO,OAAO,MAAM,UAAU,QAAQ;AAG1C,SAAO,OAAO,MAAM,UAAU,OAAO,MAAM,OAAO,KAAK,SAAS,CAAC;GACnE;AAIF,MAAK,SACD,GAAG,iBAAiB,MAAM,QAAQ,SAAS,UAAU,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAC1F;AAGD,QAAO;;;;;;;;AASX,MAAM,qBAAqB,UAAU,OAAO;CACxC,MAAM;CACN,wBAAwB;AACpB,SAAO,CACH,IAAI,OAAO;GACP,KAAK,IAAI,UAAU,qBAAqB;GACxC,OAAO;IACH,gBAAgB,MAAkB,GAAG,IAAI,WAAW;AAChD,YAAO,uBAAuB,MAAM,UAAU;;IAElD,YAAY,MAAkB,OAAO;KACjC,MAAM,gBAAgB,MAAM,eACtB,QAAQ,kBAAkB,KAAK,CAChC,MAAM;AAGX,SAAI,CAAC,cACD,QAAO;AAGX,YAAO,uBAAuB,MAAM,cAAc;;IAEzD;GACJ,CAAC,CACL;;CAER,CAAC"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
//#region src/extensions/plain-text/plain-text-document.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* The options available to customize the `PlainTextDocument` extension.
|
|
3
4
|
*/
|
|
4
5
|
type PlainTextDocumentOptions = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Indicates whether the document accepts multiple lines of input or only a single line.
|
|
8
|
+
*/
|
|
9
|
+
multiline: boolean;
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
12
|
* Custom extension that extends the built-in `Document` extension to define a schema for multiline
|
|
12
13
|
* or singleline plain-text documents (as opposed to the multiple block nodes by default).
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
export type { PlainTextDocumentOptions };
|
|
15
|
+
//#endregion
|
|
16
|
+
export { type PlainTextDocumentOptions };
|
|
17
17
|
//# sourceMappingURL=plain-text-document.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plain-text-document.d.ts","
|
|
1
|
+
{"version":3,"file":"plain-text-document.d.ts","names":[],"sources":["../../../src/extensions/plain-text/plain-text-document.ts"],"mappings":";;;;KAKK,wBAAA;EAAwB;;;EAIzB,SAAA;AAAA"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { Document } from
|
|
1
|
+
import { Document } from "@tiptap/extension-document";
|
|
2
|
+
//#region src/extensions/plain-text/plain-text-document.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
* Custom extension that extends the built-in `Document` extension to define a schema for multiline
|
|
5
|
+
* or singleline plain-text documents (as opposed to the multiple block nodes by default).
|
|
6
|
+
*/
|
|
6
7
|
const PlainTextDocument = Document.extend({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// ref: https://tiptap.dev/api/schema#content
|
|
14
|
-
return `paragraph${this.options.multiline ? '+' : ''}`;
|
|
15
|
-
},
|
|
8
|
+
addOptions() {
|
|
9
|
+
return { multiline: true };
|
|
10
|
+
},
|
|
11
|
+
content() {
|
|
12
|
+
return `paragraph${this.options.multiline ? "+" : ""}`;
|
|
13
|
+
}
|
|
16
14
|
});
|
|
15
|
+
//#endregion
|
|
17
16
|
export { PlainTextDocument };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=plain-text-document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plain-text-document.js","names":[],"sources":["../../../src/extensions/plain-text/plain-text-document.ts"],"sourcesContent":["import { Document } from '@tiptap/extension-document'\n\n/**\n * The options available to customize the `PlainTextDocument` extension.\n */\ntype PlainTextDocumentOptions = {\n /**\n * Indicates whether the document accepts multiple lines of input or only a single line.\n */\n multiline: boolean\n}\n\n/**\n * Custom extension that extends the built-in `Document` extension to define a schema for multiline\n * or singleline plain-text documents (as opposed to the multiple block nodes by default).\n */\nconst PlainTextDocument = Document.extend<PlainTextDocumentOptions>({\n addOptions() {\n return {\n multiline: true,\n }\n },\n content() {\n // ref: https://tiptap.dev/api/schema#content\n return `paragraph${this.options.multiline ? '+' : ''}`\n },\n})\n\nexport { PlainTextDocument }\n\nexport type { PlainTextDocumentOptions }\n"],"mappings":";;;;;;AAgBA,MAAM,oBAAoB,SAAS,OAAiC;CAChE,aAAa;AACT,SAAO,EACH,WAAW,MACd;;CAEL,UAAU;AAEN,SAAO,YAAY,KAAK,QAAQ,YAAY,MAAM;;CAEzD,CAAC"}
|
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { PlainTextDocumentOptions } from "./plain-text-document.js";
|
|
2
|
+
import { ParagraphOptions } from "./plain-text-paragraph.js";
|
|
3
|
+
import { Extension } from "@tiptap/core";
|
|
4
|
+
import { HistoryOptions } from "@tiptap/extension-history";
|
|
5
|
+
|
|
6
|
+
//#region src/extensions/plain-text/plain-text-kit.d.ts
|
|
5
7
|
/**
|
|
6
8
|
* The options available to customize the `PlainTextKit` extension.
|
|
7
9
|
*/
|
|
8
10
|
type PlainTextKitOptions = {
|
|
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
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Set options for the `Document` extension, or `false` to disable.
|
|
13
|
+
*/
|
|
14
|
+
document: Partial<PlainTextDocumentOptions> | false;
|
|
15
|
+
/**
|
|
16
|
+
* Set options for the `History` extension, or `false` to disable.
|
|
17
|
+
*/
|
|
18
|
+
history: Partial<HistoryOptions> | false;
|
|
19
|
+
/**
|
|
20
|
+
* Set options for the `Paragraph` extension, or `false` to disable.
|
|
21
|
+
*/
|
|
22
|
+
paragraph: Partial<ParagraphOptions> | false;
|
|
23
|
+
/**
|
|
24
|
+
* Set to `false` to disable the `PasteHTMLTableAsString` extension.
|
|
25
|
+
*/
|
|
26
|
+
pasteHTMLTableAsString: false;
|
|
27
|
+
/**
|
|
28
|
+
* Set to `false` to disable the `Text` extension.
|
|
29
|
+
*/
|
|
30
|
+
text: false;
|
|
31
|
+
/**
|
|
32
|
+
* Set to `false` to disable the `Typography` extension.
|
|
33
|
+
*/
|
|
34
|
+
typography: false;
|
|
35
|
+
/**
|
|
36
|
+
* Set to `false` to disable the `SmartMarkdownTyping` extension.
|
|
37
|
+
*/
|
|
38
|
+
smartMarkdownTyping: false;
|
|
37
39
|
};
|
|
38
40
|
/**
|
|
39
41
|
* The `PlainTextKit` extension is a collection of the minimal required extensions to have a basic
|
|
@@ -41,6 +43,6 @@ type PlainTextKitOptions = {
|
|
|
41
43
|
* implementation, allowing almost every extension to be customized or disabled.
|
|
42
44
|
*/
|
|
43
45
|
declare const PlainTextKit: Extension<PlainTextKitOptions, any>;
|
|
46
|
+
//#endregion
|
|
44
47
|
export { PlainTextKit };
|
|
45
|
-
export type { PlainTextKitOptions };
|
|
46
48
|
//# sourceMappingURL=plain-text-kit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plain-text-kit.d.ts","
|
|
1
|
+
{"version":3,"file":"plain-text-kit.d.ts","names":[],"sources":["../../../src/extensions/plain-text/plain-text-kit.ts"],"mappings":";;;;;;;;AAgBuE;KAKlE,mBAAA;;;;EAID,QAAA,EAAU,OAAA,CAAQ,wBAAA;EAKT;;;EAAT,OAAA,EAAS,OAAA,CAAQ,cAAA;EAKC;;;EAAlB,SAAA,EAAW,OAAA,CAAQ,gBAAA;EALnB;;;EAUA,sBAAA;EALW;;;EAUX,IAAA;EAKA;;;EAAA,UAAA;EAaE;;;EARF,mBAAA;AAAA;;;;;;cAQE,YAAA,EAAY,SAAA,CAAA,mBAAA"}
|
|
@@ -1,52 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
1
|
+
import { CopyMarkdownSource } from "../shared/copy-markdown-source.js";
|
|
2
|
+
import { PasteHTMLTableAsString } from "../shared/paste-html-table-as-string.js";
|
|
3
|
+
import { PasteSinglelineText } from "../shared/paste-singleline-text.js";
|
|
4
|
+
import { SmartMarkdownTyping } from "./smart-markdown-typing/smart-markdown-typing.js";
|
|
5
|
+
import { PasteMultilineText } from "./paste-multiline-text.js";
|
|
6
|
+
import { PlainTextDocument } from "./plain-text-document.js";
|
|
7
|
+
import { PlainTextParagraph } from "./plain-text-paragraph.js";
|
|
8
|
+
import { Extension } from "@tiptap/core";
|
|
9
|
+
import { History } from "@tiptap/extension-history";
|
|
10
|
+
import { Text } from "@tiptap/extension-text";
|
|
11
|
+
import { Typography } from "@tiptap/extension-typography";
|
|
12
|
+
//#region src/extensions/plain-text/plain-text-kit.ts
|
|
12
13
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
* The `PlainTextKit` extension is a collection of the minimal required extensions to have a basic
|
|
15
|
+
* plain-text editor working. This extension is based on the official `StarterKit` extension
|
|
16
|
+
* implementation, allowing almost every extension to be customized or disabled.
|
|
17
|
+
*/
|
|
17
18
|
const PlainTextKit = Extension.create({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (this.options.history !== false) {
|
|
35
|
-
extensions.push(History.configure(this.options?.history));
|
|
36
|
-
}
|
|
37
|
-
if (this.options.paragraph !== false) {
|
|
38
|
-
extensions.push(PlainTextParagraph.configure(this.options?.paragraph));
|
|
39
|
-
}
|
|
40
|
-
if (this.options.text !== false) {
|
|
41
|
-
extensions.push(Text);
|
|
42
|
-
}
|
|
43
|
-
if (this.options.typography !== false) {
|
|
44
|
-
extensions.push(Typography);
|
|
45
|
-
}
|
|
46
|
-
if (this.options.smartMarkdownTyping !== false) {
|
|
47
|
-
extensions.push(SmartMarkdownTyping);
|
|
48
|
-
}
|
|
49
|
-
return extensions;
|
|
50
|
-
},
|
|
19
|
+
name: "plainTextKit",
|
|
20
|
+
addExtensions() {
|
|
21
|
+
const extensions = [];
|
|
22
|
+
if (this.options.document !== false) {
|
|
23
|
+
extensions.push(PlainTextDocument.configure(this.options?.document), CopyMarkdownSource, this.options?.document?.multiline === false ? PasteSinglelineText : PasteMultilineText);
|
|
24
|
+
if (this.options?.pasteHTMLTableAsString !== false) extensions.push(PasteHTMLTableAsString);
|
|
25
|
+
}
|
|
26
|
+
if (this.options.history !== false) extensions.push(History.configure(this.options?.history));
|
|
27
|
+
if (this.options.paragraph !== false) extensions.push(PlainTextParagraph.configure(this.options?.paragraph));
|
|
28
|
+
if (this.options.text !== false) extensions.push(Text);
|
|
29
|
+
if (this.options.typography !== false) extensions.push(Typography);
|
|
30
|
+
if (this.options.smartMarkdownTyping !== false) extensions.push(SmartMarkdownTyping);
|
|
31
|
+
return extensions;
|
|
32
|
+
}
|
|
51
33
|
});
|
|
34
|
+
//#endregion
|
|
52
35
|
export { PlainTextKit };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=plain-text-kit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plain-text-kit.js","names":[],"sources":["../../../src/extensions/plain-text/plain-text-kit.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { History, HistoryOptions } from '@tiptap/extension-history'\nimport { Text } from '@tiptap/extension-text'\nimport { Typography } from '@tiptap/extension-typography'\n\nimport { CopyMarkdownSource } from '../shared/copy-markdown-source'\nimport { PasteHTMLTableAsString } from '../shared/paste-html-table-as-string'\nimport { PasteSinglelineText } from '../shared/paste-singleline-text'\n\nimport { SmartMarkdownTyping } from './smart-markdown-typing/smart-markdown-typing'\nimport { PasteMultilineText } from './paste-multiline-text'\nimport { PlainTextDocument } from './plain-text-document'\nimport { PlainTextParagraph } from './plain-text-paragraph'\n\nimport type { Extensions } from '@tiptap/core'\nimport type { PlainTextDocumentOptions } from './plain-text-document'\nimport type { PlainTextParagraphOptions } from './plain-text-paragraph'\n\n/**\n * The options available to customize the `PlainTextKit` extension.\n */\ntype PlainTextKitOptions = {\n /**\n * Set options for the `Document` extension, or `false` to disable.\n */\n document: Partial<PlainTextDocumentOptions> | false\n\n /**\n * Set options for the `History` extension, or `false` to disable.\n */\n history: Partial<HistoryOptions> | false\n\n /**\n * Set options for the `Paragraph` extension, or `false` to disable.\n */\n paragraph: Partial<PlainTextParagraphOptions> | false\n\n /**\n * Set to `false` to disable the `PasteHTMLTableAsString` extension.\n */\n pasteHTMLTableAsString: false\n\n /**\n * Set to `false` to disable the `Text` extension.\n */\n text: false\n\n /**\n * Set to `false` to disable the `Typography` extension.\n */\n typography: false\n\n /**\n * Set to `false` to disable the `SmartMarkdownTyping` extension.\n */\n smartMarkdownTyping: false\n}\n\n/**\n * The `PlainTextKit` extension is a collection of the minimal required extensions to have a basic\n * plain-text editor working. This extension is based on the official `StarterKit` extension\n * implementation, allowing almost every extension to be customized or disabled.\n */\nconst PlainTextKit = Extension.create<PlainTextKitOptions>({\n name: 'plainTextKit',\n addExtensions() {\n const extensions: Extensions = []\n\n if (this.options.document !== false) {\n extensions.push(\n PlainTextDocument.configure(this.options?.document),\n\n // Supports copying the underlying Markdown source to the clipboard\n CopyMarkdownSource,\n\n // Supports pasting plain-text into both a singleline and multiline editor\n this.options?.document?.multiline === false\n ? PasteSinglelineText\n : PasteMultilineText,\n )\n\n if (this.options?.pasteHTMLTableAsString !== false) {\n // Supports pasting tables (from spreadsheets and websites) into the editor\n extensions.push(PasteHTMLTableAsString)\n }\n }\n\n if (this.options.history !== false) {\n extensions.push(History.configure(this.options?.history))\n }\n\n if (this.options.paragraph !== false) {\n extensions.push(PlainTextParagraph.configure(this.options?.paragraph))\n }\n\n if (this.options.text !== false) {\n extensions.push(Text)\n }\n\n if (this.options.typography !== false) {\n extensions.push(Typography)\n }\n\n if (this.options.smartMarkdownTyping !== false) {\n extensions.push(SmartMarkdownTyping)\n }\n\n return extensions\n },\n})\n\nexport { PlainTextKit }\n\nexport type { PlainTextKitOptions }\n"],"mappings":";;;;;;;;;;;;;;;;;AA+DA,MAAM,eAAe,UAAU,OAA4B;CACvD,MAAM;CACN,gBAAgB;EACZ,MAAM,aAAyB,EAAE;AAEjC,MAAI,KAAK,QAAQ,aAAa,OAAO;AACjC,cAAW,KACP,kBAAkB,UAAU,KAAK,SAAS,SAAS,EAGnD,oBAGA,KAAK,SAAS,UAAU,cAAc,QAChC,sBACA,mBACT;AAED,OAAI,KAAK,SAAS,2BAA2B,MAEzC,YAAW,KAAK,uBAAuB;;AAI/C,MAAI,KAAK,QAAQ,YAAY,MACzB,YAAW,KAAK,QAAQ,UAAU,KAAK,SAAS,QAAQ,CAAC;AAG7D,MAAI,KAAK,QAAQ,cAAc,MAC3B,YAAW,KAAK,mBAAmB,UAAU,KAAK,SAAS,UAAU,CAAC;AAG1E,MAAI,KAAK,QAAQ,SAAS,MACtB,YAAW,KAAK,KAAK;AAGzB,MAAI,KAAK,QAAQ,eAAe,MAC5B,YAAW,KAAK,WAAW;AAG/B,MAAI,KAAK,QAAQ,wBAAwB,MACrC,YAAW,KAAK,oBAAoB;AAGxC,SAAO;;CAEd,CAAC"}
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import { ParagraphOptions } from
|
|
2
|
-
|
|
3
|
-
* Custom extension that extends the built-in `Paragraph` extension to add an additional keyboard
|
|
4
|
-
* shortcut to insert a newline (needed to behave more closely to the `<textarea>` component).
|
|
5
|
-
*/
|
|
6
|
-
declare const PlainTextParagraph: import("@tiptap/core").Node<ParagraphOptions, any>;
|
|
7
|
-
export { PlainTextParagraph };
|
|
8
|
-
export type { ParagraphOptions as PlainTextParagraphOptions };
|
|
9
|
-
//# sourceMappingURL=plain-text-paragraph.d.ts.map
|
|
1
|
+
import { ParagraphOptions as ParagraphOptions$1 } from "@tiptap/extension-paragraph";
|
|
2
|
+
export { ParagraphOptions$1 as ParagraphOptions };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Paragraph } from
|
|
1
|
+
import { Paragraph } from "@tiptap/extension-paragraph";
|
|
2
|
+
//#region src/extensions/plain-text/plain-text-paragraph.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const PlainTextParagraph = Paragraph.extend({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
},
|
|
12
|
-
});
|
|
4
|
+
* Custom extension that extends the built-in `Paragraph` extension to add an additional keyboard
|
|
5
|
+
* shortcut to insert a newline (needed to behave more closely to the `<textarea>` component).
|
|
6
|
+
*/
|
|
7
|
+
const PlainTextParagraph = Paragraph.extend({ addKeyboardShortcuts() {
|
|
8
|
+
return { "Shift-Enter": () => this.editor.commands.enter() };
|
|
9
|
+
} });
|
|
10
|
+
//#endregion
|
|
13
11
|
export { PlainTextParagraph };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=plain-text-paragraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plain-text-paragraph.js","names":[],"sources":["../../../src/extensions/plain-text/plain-text-paragraph.ts"],"sourcesContent":["import { Paragraph, ParagraphOptions } from '@tiptap/extension-paragraph'\n\n/**\n * Custom extension that extends the built-in `Paragraph` extension to add an additional keyboard\n * shortcut to insert a newline (needed to behave more closely to the `<textarea>` component).\n */\nconst PlainTextParagraph = Paragraph.extend<ParagraphOptions>({\n addKeyboardShortcuts() {\n return {\n 'Shift-Enter': () => this.editor.commands.enter(),\n }\n },\n})\n\nexport { PlainTextParagraph }\n\nexport type { ParagraphOptions as PlainTextParagraphOptions }\n"],"mappings":";;;;;;AAMA,MAAM,qBAAqB,UAAU,OAAyB,EAC1D,uBAAuB;AACnB,QAAO,EACH,qBAAqB,KAAK,OAAO,SAAS,OAAO,EACpD;GAER,CAAC"}
|
|
@@ -1,89 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isMultilineDocument } from "../../../../helpers/schema.js";
|
|
2
|
+
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
3
|
+
//#region src/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const ALLOWED_KEYS = [
|
|
5
|
+
* A list of the allowed keys that might trigger smart typing.
|
|
6
|
+
*/
|
|
7
|
+
const ALLOWED_KEYS = ["Enter", "Tab"];
|
|
7
8
|
/**
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
* The standard and task list item regex for smart typing triggers.
|
|
10
|
+
*/
|
|
10
11
|
const REGEX_LIST_ITEM = /^( *(?:(?:\*|-)(?: \[[ x]\])?|\d+\.) )[^\n]*$/i;
|
|
11
12
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const INDENT_SPACES =
|
|
13
|
+
* A string with the minimum required spaces to properly indent list items.
|
|
14
|
+
*/
|
|
15
|
+
const INDENT_SPACES = " ";
|
|
15
16
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
* This plugin provides a more plesant typing experience for both standard and task lists, adding
|
|
18
|
+
* the list marker automatically when pressing the `Enter` key, and it also supports list items
|
|
19
|
+
* indentation with the `Tab` and `Shift+Tab` keys, forward and backward, respectively.
|
|
20
|
+
*/
|
|
20
21
|
const smartLists = new Plugin({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (event.key === 'Enter') {
|
|
41
|
-
// If the whole match is different from the first group match, the list item is not
|
|
42
|
-
// empty, and a new list marker is inserted; If they are equal, the list item is
|
|
43
|
-
// empty, and the list marker is deleted
|
|
44
|
-
if (match[0] !== match[1]) {
|
|
45
|
-
// Attempt to parse the first group match as an ordered list item marker
|
|
46
|
-
const orderedListItemMarkerIndex = parseInt(match[1], 10);
|
|
47
|
-
// Increment the ordered list item marker by 1 if it's a number, otherwise
|
|
48
|
-
// use the first group match as the list item marker
|
|
49
|
-
const nextListItemMarker = orderedListItemMarkerIndex
|
|
50
|
-
? `${orderedListItemMarkerIndex + 1}. `
|
|
51
|
-
: // Make sure the next task item marker is unchecked
|
|
52
|
-
match[1].replace(/\[x\]/i, '[ ]');
|
|
53
|
-
view.dispatch(tr
|
|
54
|
-
.replaceSelectionWith(schema.node('paragraph', {}, schema.text(nextListItemMarker)))
|
|
55
|
-
.scrollIntoView());
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
view.dispatch(tr.delete(selection.from - match[1].length, selection.to));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// Indent the list item with `Tab` or `Shift+Tab`?
|
|
62
|
-
else if (event.key === 'Tab') {
|
|
63
|
-
// If the whole match is different from the first group match, the text cursor is
|
|
64
|
-
// not at the beginning of the list item (i.e., `* |<Text>`, where the pipe is), and
|
|
65
|
-
// the event is not handled (for now this restriction is disabled)
|
|
66
|
-
// if (match[0] !== match[1]) {
|
|
67
|
-
// return false
|
|
68
|
-
// }
|
|
69
|
-
// Indent the list item forward or backward?
|
|
70
|
-
if (!event.shiftKey) {
|
|
71
|
-
// Indent the list item forward
|
|
72
|
-
view.dispatch(tr
|
|
73
|
-
.insertText(INDENT_SPACES, selection.from - match[0].length)
|
|
74
|
-
.scrollIntoView());
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
// Indent the list item backward if the whole match starts with a whitespace,
|
|
78
|
-
// otherwise do nothing as the list item is already at the start of the line
|
|
79
|
-
if (match[0].startsWith(INDENT_SPACES)) {
|
|
80
|
-
view.dispatch(tr.delete(selection.from - match[0].length, selection.to - match[0].length + INDENT_SPACES.length));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
// Suppress the default handling behaviour
|
|
85
|
-
return true;
|
|
86
|
-
},
|
|
87
|
-
},
|
|
22
|
+
key: new PluginKey("smartLists"),
|
|
23
|
+
props: { handleKeyDown(view, event) {
|
|
24
|
+
const { schema } = view.state;
|
|
25
|
+
const { selection, tr } = view.state;
|
|
26
|
+
if (!isMultilineDocument(schema)) return false;
|
|
27
|
+
if (!ALLOWED_KEYS.includes(event.key)) return false;
|
|
28
|
+
const match = selection.$from.nodeBefore?.text?.match(REGEX_LIST_ITEM);
|
|
29
|
+
if (!match) return false;
|
|
30
|
+
if (event.key === "Enter") if (match[0] !== match[1]) {
|
|
31
|
+
const orderedListItemMarkerIndex = parseInt(match[1], 10);
|
|
32
|
+
const nextListItemMarker = orderedListItemMarkerIndex ? `${orderedListItemMarkerIndex + 1}. ` : match[1].replace(/\[x\]/i, "[ ]");
|
|
33
|
+
view.dispatch(tr.replaceSelectionWith(schema.node("paragraph", {}, schema.text(nextListItemMarker))).scrollIntoView());
|
|
34
|
+
} else view.dispatch(tr.delete(selection.from - match[1].length, selection.to));
|
|
35
|
+
else if (event.key === "Tab") {
|
|
36
|
+
if (!event.shiftKey) view.dispatch(tr.insertText(INDENT_SPACES, selection.from - match[0].length).scrollIntoView());
|
|
37
|
+
else if (match[0].startsWith(INDENT_SPACES)) view.dispatch(tr.delete(selection.from - match[0].length, selection.to - match[0].length + 4));
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
} }
|
|
88
41
|
});
|
|
42
|
+
//#endregion
|
|
89
43
|
export { smartLists };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=smart-lists.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-lists.js","names":[],"sources":["../../../../../src/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.ts"],"sourcesContent":["import { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { isMultilineDocument } from '../../../../helpers/schema'\n\nimport type { Schema } from '@tiptap/pm/model'\nimport type { EditorView } from '@tiptap/pm/view'\n\n/**\n * A list of the allowed keys that might trigger smart typing.\n */\nconst ALLOWED_KEYS = ['Enter', 'Tab']\n\n/**\n * The standard and task list item regex for smart typing triggers.\n */\nconst REGEX_LIST_ITEM = /^( *(?:(?:\\*|-)(?: \\[[ x]\\])?|\\d+\\.) )[^\\n]*$/i\n\n/**\n * A string with the minimum required spaces to properly indent list items.\n */\nconst INDENT_SPACES = ' '\n\n/**\n * This plugin provides a more plesant typing experience for both standard and task lists, adding\n * the list marker automatically when pressing the `Enter` key, and it also supports list items\n * indentation with the `Tab` and `Shift+Tab` keys, forward and backward, respectively.\n */\nconst smartLists = new Plugin({\n key: new PluginKey('smartLists'),\n props: {\n handleKeyDown(view: EditorView, event) {\n const { schema } = view.state as { schema: Schema }\n const { selection, tr } = view.state\n\n // Do not handle the event if not in a multiline document\n if (!isMultilineDocument(schema)) {\n return false\n }\n\n // Do not handle the event if allowed keys were not pressed\n if (!ALLOWED_KEYS.includes(event.key)) {\n return false\n }\n\n const match = selection.$from.nodeBefore?.text?.match(REGEX_LIST_ITEM)\n\n // Do not handle the event if a list/task item was not found\n if (!match) {\n return false\n }\n\n // Insert a new list marker with `Enter`?\n if (event.key === 'Enter') {\n // If the whole match is different from the first group match, the list item is not\n // empty, and a new list marker is inserted; If they are equal, the list item is\n // empty, and the list marker is deleted\n if (match[0] !== match[1]) {\n // Attempt to parse the first group match as an ordered list item marker\n const orderedListItemMarkerIndex = parseInt(match[1], 10)\n\n // Increment the ordered list item marker by 1 if it's a number, otherwise\n // use the first group match as the list item marker\n const nextListItemMarker = orderedListItemMarkerIndex\n ? `${orderedListItemMarkerIndex + 1}. `\n : // Make sure the next task item marker is unchecked\n match[1].replace(/\\[x\\]/i, '[ ]')\n\n view.dispatch(\n tr\n .replaceSelectionWith(\n schema.node('paragraph', {}, schema.text(nextListItemMarker)),\n )\n .scrollIntoView(),\n )\n } else {\n view.dispatch(tr.delete(selection.from - match[1].length, selection.to))\n }\n }\n // Indent the list item with `Tab` or `Shift+Tab`?\n else if (event.key === 'Tab') {\n // If the whole match is different from the first group match, the text cursor is\n // not at the beginning of the list item (i.e., `* |<Text>`, where the pipe is), and\n // the event is not handled (for now this restriction is disabled)\n // if (match[0] !== match[1]) {\n // return false\n // }\n\n // Indent the list item forward or backward?\n if (!event.shiftKey) {\n // Indent the list item forward\n view.dispatch(\n tr\n .insertText(INDENT_SPACES, selection.from - match[0].length)\n .scrollIntoView(),\n )\n } else {\n // Indent the list item backward if the whole match starts with a whitespace,\n // otherwise do nothing as the list item is already at the start of the line\n if (match[0].startsWith(INDENT_SPACES)) {\n view.dispatch(\n tr.delete(\n selection.from - match[0].length,\n selection.to - match[0].length + INDENT_SPACES.length,\n ),\n )\n }\n }\n }\n\n // Suppress the default handling behaviour\n return true\n },\n },\n})\n\nexport { smartLists }\n"],"mappings":";;;;;;AAUA,MAAM,eAAe,CAAC,SAAS,MAAM;;;;AAKrC,MAAM,kBAAkB;;;;AAKxB,MAAM,gBAAgB;;;;;;AAOtB,MAAM,aAAa,IAAI,OAAO;CAC1B,KAAK,IAAI,UAAU,aAAa;CAChC,OAAO,EACH,cAAc,MAAkB,OAAO;EACnC,MAAM,EAAE,WAAW,KAAK;EACxB,MAAM,EAAE,WAAW,OAAO,KAAK;AAG/B,MAAI,CAAC,oBAAoB,OAAO,CAC5B,QAAO;AAIX,MAAI,CAAC,aAAa,SAAS,MAAM,IAAI,CACjC,QAAO;EAGX,MAAM,QAAQ,UAAU,MAAM,YAAY,MAAM,MAAM,gBAAgB;AAGtE,MAAI,CAAC,MACD,QAAO;AAIX,MAAI,MAAM,QAAQ,QAId,KAAI,MAAM,OAAO,MAAM,IAAI;GAEvB,MAAM,6BAA6B,SAAS,MAAM,IAAI,GAAG;GAIzD,MAAM,qBAAqB,6BACrB,GAAG,6BAA6B,EAAE,MAElC,MAAM,GAAG,QAAQ,UAAU,MAAM;AAEvC,QAAK,SACD,GACK,qBACG,OAAO,KAAK,aAAa,EAAE,EAAE,OAAO,KAAK,mBAAmB,CAAC,CAChE,CACA,gBAAgB,CACxB;QAED,MAAK,SAAS,GAAG,OAAO,UAAU,OAAO,MAAM,GAAG,QAAQ,UAAU,GAAG,CAAC;WAIvE,MAAM,QAAQ;OASf,CAAC,MAAM,SAEP,MAAK,SACD,GACK,WAAW,eAAe,UAAU,OAAO,MAAM,GAAG,OAAO,CAC3D,gBAAgB,CACxB;YAIG,MAAM,GAAG,WAAW,cAAc,CAClC,MAAK,SACD,GAAG,OACC,UAAU,OAAO,MAAM,GAAG,QAC1B,UAAU,KAAK,MAAM,GAAG,SAAS,EACpC,CACJ;;AAMb,SAAO;IAEd;CACJ,CAAC"}
|