@doist/typist 9.0.3 → 10.0.0-next.2
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/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 +26 -13
- 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,32 +1,29 @@
|
|
|
1
|
-
import { isActive, isTextSelection } from
|
|
2
|
-
import { TextSelection } from
|
|
3
|
-
import { clamp } from
|
|
1
|
+
import { isActive, isTextSelection } from "@tiptap/core";
|
|
2
|
+
import { TextSelection } from "@tiptap/pm/state";
|
|
3
|
+
import { clamp } from "lodash-es";
|
|
4
|
+
//#region src/extensions/core/extra-editor-commands/commands/extend-word-range.ts
|
|
4
5
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
* Extends the text selection to the current word.
|
|
7
|
+
*
|
|
8
|
+
* The solution for this function was inspired by the official `extendMarkRange` and
|
|
9
|
+
* `setTextSelection` commands.
|
|
10
|
+
*/
|
|
10
11
|
function extendWordRange() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const textAfter = $head.nodeAfter?.text?.match(/^[^\s]+/)?.[0] || '';
|
|
25
|
-
const minPos = TextSelection.atStart(doc).from;
|
|
26
|
-
const maxPos = TextSelection.atEnd(doc).to;
|
|
27
|
-
tr.setSelection(TextSelection.create(doc, clamp(selection.head - textBefore.length, minPos, maxPos), clamp(selection.head + textAfter.length, minPos, maxPos)));
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
30
|
-
};
|
|
12
|
+
return ({ state, tr, dispatch }) => {
|
|
13
|
+
const { doc, selection } = tr;
|
|
14
|
+
const { $head } = selection;
|
|
15
|
+
if (!isTextSelection(selection) || isActive(state, "code") || isActive(state, "codeBlock")) return false;
|
|
16
|
+
if (dispatch) {
|
|
17
|
+
const textBefore = $head.nodeBefore?.text?.match(/[^\s]+$/)?.[0] || "";
|
|
18
|
+
const textAfter = $head.nodeAfter?.text?.match(/^[^\s]+/)?.[0] || "";
|
|
19
|
+
const minPos = TextSelection.atStart(doc).from;
|
|
20
|
+
const maxPos = TextSelection.atEnd(doc).to;
|
|
21
|
+
tr.setSelection(TextSelection.create(doc, clamp(selection.head - textBefore.length, minPos, maxPos), clamp(selection.head + textAfter.length, minPos, maxPos)));
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
31
25
|
}
|
|
26
|
+
//#endregion
|
|
32
27
|
export { extendWordRange };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=extend-word-range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extend-word-range.js","names":[],"sources":["../../../../../src/extensions/core/extra-editor-commands/commands/extend-word-range.ts"],"sourcesContent":["import { isActive, isTextSelection, RawCommands } from '@tiptap/core'\nimport { TextSelection } from '@tiptap/pm/state'\nimport { clamp } from 'lodash-es'\n\n/**\n * Augment the official `@tiptap/core` module with extra commands so that the compiler knows about\n * them. For this to work externally, a wildcard export needs to be added to the root `index.ts`.\n */\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n extendWordRange: {\n /**\n * Extends the text selection to the current word.\n */\n extendWordRange: () => ReturnType\n }\n }\n}\n\n/**\n * Extends the text selection to the current word.\n *\n * The solution for this function was inspired by the official `extendMarkRange` and\n * `setTextSelection` commands.\n */\nfunction extendWordRange(): ReturnType<RawCommands['extendWordRange']> {\n return ({ state, tr, dispatch }) => {\n const { doc, selection } = tr\n const { $head } = selection\n\n // Do nothing if cursor position is not valid for a text selection\n if (\n !isTextSelection(selection) ||\n isActive(state, 'code') ||\n isActive(state, 'codeBlock')\n ) {\n return false\n }\n\n // Check if the transaction should be dispatched\n // ref: https://tiptap.dev/api/commands#dry-run-for-commands\n if (dispatch) {\n const textBefore = $head.nodeBefore?.text?.match(/[^\\s]+$/)?.[0] || ''\n const textAfter = $head.nodeAfter?.text?.match(/^[^\\s]+/)?.[0] || ''\n\n const minPos = TextSelection.atStart(doc).from\n const maxPos = TextSelection.atEnd(doc).to\n\n tr.setSelection(\n TextSelection.create(\n doc,\n clamp(selection.head - textBefore.length, minPos, maxPos),\n clamp(selection.head + textAfter.length, minPos, maxPos),\n ),\n )\n }\n\n return true\n }\n}\n\nexport { extendWordRange }\n"],"mappings":";;;;;;;;;;AAyBA,SAAS,kBAA8D;AACnE,SAAQ,EAAE,OAAO,IAAI,eAAe;EAChC,MAAM,EAAE,KAAK,cAAc;EAC3B,MAAM,EAAE,UAAU;AAGlB,MACI,CAAC,gBAAgB,UAAU,IAC3B,SAAS,OAAO,OAAO,IACvB,SAAS,OAAO,YAAY,CAE5B,QAAO;AAKX,MAAI,UAAU;GACV,MAAM,aAAa,MAAM,YAAY,MAAM,MAAM,UAAU,GAAG,MAAM;GACpE,MAAM,YAAY,MAAM,WAAW,MAAM,MAAM,UAAU,GAAG,MAAM;GAElE,MAAM,SAAS,cAAc,QAAQ,IAAI,CAAC;GAC1C,MAAM,SAAS,cAAc,MAAM,IAAI,CAAC;AAExC,MAAG,aACC,cAAc,OACV,KACA,MAAM,UAAU,OAAO,WAAW,QAAQ,QAAQ,OAAO,EACzD,MAAM,UAAU,OAAO,UAAU,QAAQ,QAAQ,OAAO,CAC3D,CACJ;;AAGL,SAAO"}
|
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import { RawCommands } from
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { Range, RawCommands } from "@tiptap/core";
|
|
2
|
+
import { ParseOptions } from "@tiptap/pm/model";
|
|
3
|
+
|
|
4
|
+
//#region src/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.d.ts
|
|
4
5
|
/**
|
|
5
6
|
* Augment the official `@tiptap/core` module with extra commands so that the compiler knows about
|
|
6
7
|
* them. For this to work externally, a wildcard export needs to be added to the root `index.ts`.
|
|
7
8
|
*/
|
|
8
9
|
declare module '@tiptap/core' {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
interface Commands<ReturnType> {
|
|
11
|
+
insertMarkdownContentAt: {
|
|
12
|
+
/**
|
|
13
|
+
* Inserts the provided Markdown content as HTML into the editor at a specific position.
|
|
14
|
+
*
|
|
15
|
+
* @param position The position or range the Markdown will be inserted in.
|
|
16
|
+
* @param markdown The Markdown content to parse and insert as HTML.
|
|
17
|
+
* @param options An optional object with the following parameters:
|
|
18
|
+
* @param options.parseOptions The parse options to use when the HTML content is parsed by ProseMirror.
|
|
19
|
+
* @param options.updateSelection Whether the selection should move to the newly inserted content.
|
|
20
|
+
*/
|
|
21
|
+
insertMarkdownContentAt: (position: number | Range, markdown: string, options?: {
|
|
22
|
+
parseOptions?: ParseOptions;
|
|
23
|
+
updateSelection?: boolean;
|
|
24
|
+
}) => ReturnType;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* Inserts the provided Markdown content as HTML into the editor at a specific position.
|
|
@@ -31,8 +32,9 @@ declare module '@tiptap/core' {
|
|
|
31
32
|
* and how Tiptap inserts content with the `insertContentAt` command.
|
|
32
33
|
*/
|
|
33
34
|
declare function insertMarkdownContentAt(position: number | Range, markdown: string, options?: {
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
parseOptions?: ParseOptions;
|
|
36
|
+
updateSelection?: boolean;
|
|
36
37
|
}): ReturnType<RawCommands['insertMarkdownContentAt']>;
|
|
38
|
+
//#endregion
|
|
37
39
|
export { insertMarkdownContentAt };
|
|
38
40
|
//# sourceMappingURL=insert-markdown-content-at.d.ts.map
|
package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert-markdown-content-at.d.ts","
|
|
1
|
+
{"version":3,"file":"insert-markdown-content-at.d.ts","names":[],"sources":["../../../../../src/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.ts"],"mappings":";;;;;AAOoD;;;;YAOtC,QAAA;IACN,uBAAA;MAiBmB;;;;;;;;;MAPf,uBAAA,GACI,QAAA,WAAmB,KAAA,EACnB,QAAA,UACA,OAAA;QACI,YAAA,GAAe,YAAA;QACf,eAAA;MAAA,MAEH,UAAA;IAAA;EAAA;AAAA;;AAAU;;;;;iBAWlB,uBAAA,CACL,QAAA,WAAmB,KAAA,EACnB,QAAA,UACA,OAAA;EACI,YAAA,GAAe,YAAA;EACf,eAAA;AAAA,IAEL,UAAA,CAAW,WAAA"}
|
|
@@ -1,40 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { parseHtmlToElement } from "../../../../helpers/dom.js";
|
|
2
|
+
import { getHTMLSerializerInstance } from "../../../../serializers/html/html.js";
|
|
3
|
+
import { selectionToInsertionEnd } from "@tiptap/core";
|
|
4
|
+
import { DOMParser } from "@tiptap/pm/model";
|
|
5
|
+
//#region src/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.ts
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
* Inserts the provided Markdown content as HTML into the editor at a specific position.
|
|
8
|
+
*
|
|
9
|
+
* The solution for this function was inspired by how ProseMirror pastes content from the clipboard,
|
|
10
|
+
* and how Tiptap inserts content with the `insertContentAt` command.
|
|
11
|
+
*/
|
|
11
12
|
function insertMarkdownContentAt(position, markdown, options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (options.updateSelection) {
|
|
34
|
-
selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return true;
|
|
38
|
-
};
|
|
13
|
+
return ({ editor, tr, dispatch }) => {
|
|
14
|
+
if (dispatch) {
|
|
15
|
+
options = {
|
|
16
|
+
parseOptions: {},
|
|
17
|
+
updateSelection: true,
|
|
18
|
+
...options
|
|
19
|
+
};
|
|
20
|
+
const { from, to } = typeof position === "number" ? {
|
|
21
|
+
from: position,
|
|
22
|
+
to: position
|
|
23
|
+
} : {
|
|
24
|
+
from: position.from,
|
|
25
|
+
to: position.to
|
|
26
|
+
};
|
|
27
|
+
const htmlContent = getHTMLSerializerInstance(editor.schema).serialize(markdown);
|
|
28
|
+
const content = DOMParser.fromSchema(editor.schema).parseSlice(parseHtmlToElement(htmlContent), options.parseOptions);
|
|
29
|
+
tr.replaceRange(from, to, content);
|
|
30
|
+
if (options.updateSelection) selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
39
34
|
}
|
|
35
|
+
//#endregion
|
|
40
36
|
export { insertMarkdownContentAt };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=insert-markdown-content-at.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insert-markdown-content-at.js","names":[],"sources":["../../../../../src/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.ts"],"sourcesContent":["import { RawCommands, selectionToInsertionEnd } from '@tiptap/core'\nimport { DOMParser } from '@tiptap/pm/model'\n\nimport { parseHtmlToElement } from '../../../../helpers/dom'\nimport { getHTMLSerializerInstance } from '../../../../serializers/html/html'\n\nimport type { Range } from '@tiptap/core'\nimport type { ParseOptions } from '@tiptap/pm/model'\n\n/**\n * Augment the official `@tiptap/core` module with extra commands so that the compiler knows about\n * them. For this to work externally, a wildcard export needs to be added to the root `index.ts`.\n */\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n insertMarkdownContentAt: {\n /**\n * Inserts the provided Markdown content as HTML into the editor at a specific position.\n *\n * @param position The position or range the Markdown will be inserted in.\n * @param markdown The Markdown content to parse and insert as HTML.\n * @param options An optional object with the following parameters:\n * @param options.parseOptions The parse options to use when the HTML content is parsed by ProseMirror.\n * @param options.updateSelection Whether the selection should move to the newly inserted content.\n */\n insertMarkdownContentAt: (\n position: number | Range,\n markdown: string,\n options?: {\n parseOptions?: ParseOptions\n updateSelection?: boolean\n },\n ) => ReturnType\n }\n }\n}\n\n/**\n * Inserts the provided Markdown content as HTML into the editor at a specific position.\n *\n * The solution for this function was inspired by how ProseMirror pastes content from the clipboard,\n * and how Tiptap inserts content with the `insertContentAt` command.\n */\nfunction insertMarkdownContentAt(\n position: number | Range,\n markdown: string,\n options?: {\n parseOptions?: ParseOptions\n updateSelection?: boolean\n },\n): ReturnType<RawCommands['insertMarkdownContentAt']> {\n return ({ editor, tr, dispatch }) => {\n // Check if the transaction should be dispatched\n // ref: https://tiptap.dev/api/commands#dry-run-for-commands\n if (dispatch) {\n // Default values for command options must be set here\n // (they do not work if set in the function signature)\n options = {\n parseOptions: {},\n updateSelection: true,\n ...options,\n }\n\n // Get the start and end positions from the provided position\n const { from, to } =\n typeof position === 'number'\n ? { from: position, to: position }\n : { from: position.from, to: position.to }\n\n // Parse the Markdown to HTML and then then into ProseMirror nodes\n const htmlContent = getHTMLSerializerInstance(editor.schema).serialize(markdown)\n const content = DOMParser.fromSchema(editor.schema).parseSlice(\n parseHtmlToElement(htmlContent),\n options.parseOptions,\n )\n\n // Inserts the content into the editor while preserving the current selection\n tr.replaceRange(from, to, content)\n\n // Set the text cursor to the end of the inserted content\n if (options.updateSelection) {\n selectionToInsertionEnd(tr, tr.steps.length - 1, -1)\n }\n }\n\n return true\n }\n}\n\nexport { insertMarkdownContentAt }\n"],"mappings":";;;;;;;;;;;AA2CA,SAAS,wBACL,UACA,UACA,SAIkD;AAClD,SAAQ,EAAE,QAAQ,IAAI,eAAe;AAGjC,MAAI,UAAU;AAGV,aAAU;IACN,cAAc,EAAE;IAChB,iBAAiB;IACjB,GAAG;IACN;GAGD,MAAM,EAAE,MAAM,OACV,OAAO,aAAa,WACd;IAAE,MAAM;IAAU,IAAI;IAAU,GAChC;IAAE,MAAM,SAAS;IAAM,IAAI,SAAS;IAAI;GAGlD,MAAM,cAAc,0BAA0B,OAAO,OAAO,CAAC,UAAU,SAAS;GAChF,MAAM,UAAU,UAAU,WAAW,OAAO,OAAO,CAAC,WAChD,mBAAmB,YAAY,EAC/B,QAAQ,aACX;AAGD,MAAG,aAAa,MAAM,IAAI,QAAQ;AAGlC,OAAI,QAAQ,gBACR,yBAAwB,IAAI,GAAG,MAAM,SAAS,GAAG,GAAG;;AAI5D,SAAO"}
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import { RawCommands } from
|
|
2
|
-
import
|
|
1
|
+
import { RawCommands } from "@tiptap/core";
|
|
2
|
+
import { ParseOptions } from "@tiptap/pm/model";
|
|
3
|
+
|
|
4
|
+
//#region src/extensions/core/extra-editor-commands/commands/insert-markdown-content.d.ts
|
|
3
5
|
/**
|
|
4
6
|
* Augment the official `@tiptap/core` module with extra commands so that the compiler knows about
|
|
5
7
|
* them. For this to work externally, a wildcard export needs to be added to the root `index.ts`.
|
|
6
8
|
*/
|
|
7
9
|
declare module '@tiptap/core' {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
interface Commands<ReturnType> {
|
|
11
|
+
insertMarkdownContent: {
|
|
12
|
+
/**
|
|
13
|
+
* Inserts the provided Markdown as HTML into the editor at the current position.
|
|
14
|
+
*
|
|
15
|
+
* @param markdown The Markdown content to parse and insert as HTML.
|
|
16
|
+
* @param options An optional object with the following parameters:
|
|
17
|
+
* @param options.parseOptions The parse options to use when the HTML content is parsed by ProseMirror.
|
|
18
|
+
* @param options.updateSelection Whether the selection should move to the newly inserted content.
|
|
19
|
+
*/
|
|
20
|
+
insertMarkdownContent: (markdown: string, options?: {
|
|
21
|
+
parseOptions?: ParseOptions;
|
|
22
|
+
updateSelection?: boolean;
|
|
23
|
+
}) => ReturnType;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
26
28
|
* Inserts the provided Markdown as HTML into the editor at the current position.
|
|
@@ -29,8 +31,9 @@ declare module '@tiptap/core' {
|
|
|
29
31
|
* `insertContent` command.
|
|
30
32
|
*/
|
|
31
33
|
declare function insertMarkdownContent(markdown: string, options?: {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
parseOptions?: ParseOptions;
|
|
35
|
+
updateSelection?: boolean;
|
|
34
36
|
}): ReturnType<RawCommands['insertMarkdownContent']>;
|
|
37
|
+
//#endregion
|
|
35
38
|
export { insertMarkdownContent };
|
|
36
39
|
//# sourceMappingURL=insert-markdown-content.d.ts.map
|
package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert-markdown-content.d.ts","
|
|
1
|
+
{"version":3,"file":"insert-markdown-content.d.ts","names":[],"sources":["../../../../../src/extensions/core/extra-editor-commands/commands/insert-markdown-content.ts"],"mappings":";;;;;;AAEoD;;;YAOtC,QAAA;IACN,qBAAA;MADe;;;;;;;;MAUX,qBAAA,GACI,QAAA,UACA,OAAA;QACI,YAAA,GAAe,YAAA;QACf,eAAA;MAAA,MAEH,UAAA;IAAA;EAAA;AAAA;;;;;;;iBAWR,qBAAA,CACL,QAAA,UACA,OAAA;EACI,YAAA,GAAe,YAAA;EACf,eAAA;AAAA,IAEL,UAAA,CAAW,WAAA"}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
//#region src/extensions/core/extra-editor-commands/commands/insert-markdown-content.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
* Inserts the provided Markdown as HTML into the editor at the current position.
|
|
4
|
+
*
|
|
5
|
+
* The solution for this function was inspired by how Tiptap inserts content with the
|
|
6
|
+
* `insertContent` command.
|
|
7
|
+
*/
|
|
7
8
|
function insertMarkdownContent(markdown, options) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
return ({ commands, tr }) => {
|
|
10
|
+
return commands.insertMarkdownContentAt({
|
|
11
|
+
from: tr.selection.from,
|
|
12
|
+
to: tr.selection.to
|
|
13
|
+
}, markdown, options);
|
|
14
|
+
};
|
|
11
15
|
}
|
|
16
|
+
//#endregion
|
|
12
17
|
export { insertMarkdownContent };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=insert-markdown-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insert-markdown-content.js","names":[],"sources":["../../../../../src/extensions/core/extra-editor-commands/commands/insert-markdown-content.ts"],"sourcesContent":["import { RawCommands } from '@tiptap/core'\n\nimport type { ParseOptions } from '@tiptap/pm/model'\n\n/**\n * Augment the official `@tiptap/core` module with extra commands so that the compiler knows about\n * them. For this to work externally, a wildcard export needs to be added to the root `index.ts`.\n */\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n insertMarkdownContent: {\n /**\n * Inserts the provided Markdown as HTML into the editor at the current position.\n *\n * @param markdown The Markdown content to parse and insert as HTML.\n * @param options An optional object with the following parameters:\n * @param options.parseOptions The parse options to use when the HTML content is parsed by ProseMirror.\n * @param options.updateSelection Whether the selection should move to the newly inserted content.\n */\n insertMarkdownContent: (\n markdown: string,\n options?: {\n parseOptions?: ParseOptions\n updateSelection?: boolean\n },\n ) => ReturnType\n }\n }\n}\n\n/**\n * Inserts the provided Markdown as HTML into the editor at the current position.\n *\n * The solution for this function was inspired by how Tiptap inserts content with the\n * `insertContent` command.\n */\nfunction insertMarkdownContent(\n markdown: string,\n options?: {\n parseOptions?: ParseOptions\n updateSelection?: boolean\n },\n): ReturnType<RawCommands['insertMarkdownContent']> {\n return ({ commands, tr }) => {\n return commands.insertMarkdownContentAt(\n { from: tr.selection.from, to: tr.selection.to },\n markdown,\n options,\n )\n }\n}\n\nexport { insertMarkdownContent }\n"],"mappings":";;;;;;;AAoCA,SAAS,sBACL,UACA,SAIgD;AAChD,SAAQ,EAAE,UAAU,SAAS;AACzB,SAAO,SAAS,wBACZ;GAAE,MAAM,GAAG,UAAU;GAAM,IAAI,GAAG,UAAU;GAAI,EAChD,UACA,QACH"}
|
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { createParagraphEnd } from "./commands/create-paragraph-end.js";
|
|
2
|
+
import { extendWordRange } from "./commands/extend-word-range.js";
|
|
3
|
+
import { insertMarkdownContent } from "./commands/insert-markdown-content.js";
|
|
4
|
+
import { insertMarkdownContentAt } from "./commands/insert-markdown-content-at.js";
|
|
5
|
+
import { Extension } from "@tiptap/core";
|
|
6
|
+
//#region src/extensions/core/extra-editor-commands/extra-editor-commands.ts
|
|
6
7
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
* The `ExtraEditorCommands` extension is a collection of editor commands that provide additional
|
|
9
|
+
* helper commands not available with the built-in commands. This extension was built similarly to
|
|
10
|
+
* the official `Commands` extension.
|
|
11
|
+
*/
|
|
11
12
|
const ExtraEditorCommands = Extension.create({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
name: "extraEditorCommands",
|
|
14
|
+
addCommands() {
|
|
15
|
+
return {
|
|
16
|
+
createParagraphEnd,
|
|
17
|
+
extendWordRange,
|
|
18
|
+
insertMarkdownContent,
|
|
19
|
+
insertMarkdownContentAt
|
|
20
|
+
};
|
|
21
|
+
}
|
|
21
22
|
});
|
|
23
|
+
//#endregion
|
|
22
24
|
export { ExtraEditorCommands };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=extra-editor-commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extra-editor-commands.js","names":[],"sources":["../../../../src/extensions/core/extra-editor-commands/extra-editor-commands.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nimport { createParagraphEnd } from './commands/create-paragraph-end'\nimport { extendWordRange } from './commands/extend-word-range'\nimport { insertMarkdownContent } from './commands/insert-markdown-content'\nimport { insertMarkdownContentAt } from './commands/insert-markdown-content-at'\n\n/**\n * The `ExtraEditorCommands` extension is a collection of editor commands that provide additional\n * helper commands not available with the built-in commands. This extension was built similarly to\n * the official `Commands` extension.\n */\nconst ExtraEditorCommands = Extension.create({\n name: 'extraEditorCommands',\n addCommands() {\n return {\n createParagraphEnd,\n extendWordRange,\n insertMarkdownContent,\n insertMarkdownContentAt,\n }\n },\n})\n\nexport { ExtraEditorCommands }\n"],"mappings":";;;;;;;;;;;AAYA,MAAM,sBAAsB,UAAU,OAAO;CACzC,MAAM;CACN,cAAc;AACV,SAAO;GACH;GACA;GACA;GACA;GACH;;CAER,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Extension } from
|
|
2
|
-
import
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
|
+
import { EditorView } from "@tiptap/pm/view";
|
|
3
|
+
|
|
4
|
+
//#region src/extensions/core/view-event-handlers.d.ts
|
|
3
5
|
/**
|
|
4
6
|
* The options available to customize the `ViewEventHandlers` extension.
|
|
5
7
|
*
|
|
@@ -7,14 +9,14 @@ import type { EditorView } from '@tiptap/pm/view';
|
|
|
7
9
|
* [`prosemirror-view`](https://prosemirror.net/docs/ref/#view.Props), and add them below.
|
|
8
10
|
*/
|
|
9
11
|
type ViewEventHandlersOptions = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Called when the editor is clicked, after `handleClickOn` handlers have been called.
|
|
14
|
+
*/
|
|
15
|
+
onClick?: (event: MouseEvent, view: EditorView, pos: number) => boolean | void;
|
|
16
|
+
/**
|
|
17
|
+
* Called when the editor receives a `keydown` event.
|
|
18
|
+
*/
|
|
19
|
+
onKeyDown?: (event: KeyboardEvent, view: EditorView) => boolean | void;
|
|
18
20
|
};
|
|
19
21
|
/**
|
|
20
22
|
* The `ViewEventHandlers` extension allows handling of various ProseMirror view events.
|
|
@@ -27,7 +29,6 @@ type ViewEventHandlersOptions = {
|
|
|
27
29
|
* These event handlers should be used sparingly, please consider if a reusable extension would be
|
|
28
30
|
* more appropriate for your use case.
|
|
29
31
|
*/
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
export type { ViewEventHandlersOptions };
|
|
32
|
+
//#endregion
|
|
33
|
+
export { type ViewEventHandlersOptions };
|
|
33
34
|
//# sourceMappingURL=view-event-handlers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-event-handlers.d.ts","
|
|
1
|
+
{"version":3,"file":"view-event-handlers.d.ts","names":[],"sources":["../../../src/extensions/core/view-event-handlers.ts"],"mappings":";;;;;;AAKiD;;;;KAQ5C,wBAAA;EASmB;;;EALpB,OAAA,IAAW,KAAA,EAAO,UAAA,EAAY,IAAA,EAAM,UAAA,EAAY,GAAA;EAAhD;;;EAKA,SAAA,IAAa,KAAA,EAAO,aAAA,EAAe,IAAA,EAAM,UAAA;AAAA"}
|
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import "../../constants/extension-priorities.js";
|
|
2
|
+
import { Extension } from "@tiptap/core";
|
|
3
|
+
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
4
|
+
//#region src/extensions/core/view-event-handlers.ts
|
|
4
5
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
* The `ViewEventHandlers` extension allows handling of various ProseMirror view events.
|
|
7
|
+
*
|
|
8
|
+
* The various event-handling functions may all return `true` to indicate that they handled the
|
|
9
|
+
* given event. The view will then take care to call `preventDefault` on the event, except with
|
|
10
|
+
* `handleDOMEvents`, where the handler itself is responsible for that. Return `false` or
|
|
11
|
+
* `undefined` for the default event handler to be called.
|
|
12
|
+
*
|
|
13
|
+
* These event handlers should be used sparingly, please consider if a reusable extension would be
|
|
14
|
+
* more appropriate for your use case.
|
|
15
|
+
*/
|
|
15
16
|
const ViewEventHandlers = Extension.create({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
];
|
|
33
|
-
},
|
|
17
|
+
name: "viewEventHandlers",
|
|
18
|
+
priority: 105,
|
|
19
|
+
addProseMirrorPlugins() {
|
|
20
|
+
const { options } = this;
|
|
21
|
+
return [new Plugin({
|
|
22
|
+
key: new PluginKey("viewEventHandlers"),
|
|
23
|
+
props: {
|
|
24
|
+
handleClick(view, pos, event) {
|
|
25
|
+
return options.onClick?.(event, view, pos) || false;
|
|
26
|
+
},
|
|
27
|
+
handleKeyDown(view, event) {
|
|
28
|
+
return options.onKeyDown?.(event, view) || false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
})];
|
|
32
|
+
}
|
|
34
33
|
});
|
|
34
|
+
//#endregion
|
|
35
35
|
export { ViewEventHandlers };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=view-event-handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-event-handlers.js","names":[],"sources":["../../../src/extensions/core/view-event-handlers.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nimport { VIEW_EVENT_HANDLERS_PRIORITY } from '../../constants/extension-priorities'\n\nimport type { EditorView } from '@tiptap/pm/view'\n\n/**\n * The options available to customize the `ViewEventHandlers` extension.\n *\n * If more view handlers are needed, please look into the available event handlers in\n * [`prosemirror-view`](https://prosemirror.net/docs/ref/#view.Props), and add them below.\n */\ntype ViewEventHandlersOptions = {\n /**\n * Called when the editor is clicked, after `handleClickOn` handlers have been called.\n */\n onClick?: (event: MouseEvent, view: EditorView, pos: number) => boolean | void\n\n /**\n * Called when the editor receives a `keydown` event.\n */\n onKeyDown?: (event: KeyboardEvent, view: EditorView) => boolean | void\n}\n\n/**\n * The `ViewEventHandlers` extension allows handling of various ProseMirror view events.\n *\n * The various event-handling functions may all return `true` to indicate that they handled the\n * given event. The view will then take care to call `preventDefault` on the event, except with\n * `handleDOMEvents`, where the handler itself is responsible for that. Return `false` or\n * `undefined` for the default event handler to be called.\n *\n * These event handlers should be used sparingly, please consider if a reusable extension would be\n * more appropriate for your use case.\n */\nconst ViewEventHandlers = Extension.create<ViewEventHandlersOptions>({\n name: 'viewEventHandlers',\n priority: VIEW_EVENT_HANDLERS_PRIORITY,\n addProseMirrorPlugins() {\n const { options } = this\n\n return [\n new Plugin({\n key: new PluginKey('viewEventHandlers'),\n props: {\n handleClick(view, pos, event) {\n return options.onClick?.(event, view, pos) || false\n },\n handleKeyDown(view, event) {\n return options.onKeyDown?.(event, view) || false\n },\n },\n }),\n ]\n },\n})\n\nexport { ViewEventHandlers }\n\nexport type { ViewEventHandlersOptions }\n"],"mappings":";;;;;;;;;;;;;;;AAoCA,MAAM,oBAAoB,UAAU,OAAiC;CACjE,MAAM;CACN,UAAA;CACA,wBAAwB;EACpB,MAAM,EAAE,YAAY;AAEpB,SAAO,CACH,IAAI,OAAO;GACP,KAAK,IAAI,UAAU,oBAAoB;GACvC,OAAO;IACH,YAAY,MAAM,KAAK,OAAO;AAC1B,YAAO,QAAQ,UAAU,OAAO,MAAM,IAAI,IAAI;;IAElD,cAAc,MAAM,OAAO;AACvB,YAAO,QAAQ,YAAY,OAAO,KAAK,IAAI;;IAElD;GACJ,CAAC,CACL;;CAER,CAAC"}
|