@tiptap/vue-3 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +577 -455
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +228 -0
- package/dist/index.d.ts +228 -0
- package/dist/index.js +541 -443
- package/dist/index.js.map +1 -1
- package/dist/menus/index.cjs +692 -0
- package/dist/menus/index.cjs.map +1 -0
- package/dist/menus/index.d.cts +273 -0
- package/dist/menus/index.d.ts +273 -0
- package/dist/menus/index.js +684 -0
- package/dist/menus/index.js.map +1 -0
- package/package.json +28 -17
- package/src/Editor.ts +23 -17
- package/src/EditorContent.ts +14 -44
- package/src/VueMarkViewRenderer.ts +130 -0
- package/src/VueNodeViewRenderer.ts +99 -36
- package/src/VueRenderer.ts +27 -18
- package/src/index.ts +1 -2
- package/src/menus/BubbleMenu.ts +78 -0
- package/src/menus/FloatingMenu.ts +68 -0
- package/src/menus/index.ts +2 -0
- package/src/useEditor.ts +7 -1
- package/dist/index.umd.js +0 -495
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -161
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -343
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -451
- package/dist/packages/core/src/Node.d.ts +0 -611
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -255
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
- package/dist/packages/extension-bubble-menu/src/bubble-menu-plugin.d.ts +0 -76
- package/dist/packages/extension-bubble-menu/src/bubble-menu.d.ts +0 -15
- package/dist/packages/extension-bubble-menu/src/index.d.ts +0 -4
- package/dist/packages/extension-floating-menu/src/floating-menu-plugin.d.ts +0 -66
- package/dist/packages/extension-floating-menu/src/floating-menu.d.ts +0 -15
- package/dist/packages/extension-floating-menu/src/index.d.ts +0 -4
- package/dist/packages/vue-3/src/BubbleMenu.d.ts +0 -59
- package/dist/packages/vue-3/src/Editor.d.ts +0 -23
- package/dist/packages/vue-3/src/EditorContent.d.ts +0 -17
- package/dist/packages/vue-3/src/FloatingMenu.d.ts +0 -48
- package/dist/packages/vue-3/src/NodeViewContent.d.ts +0 -13
- package/dist/packages/vue-3/src/NodeViewWrapper.d.ts +0 -13
- package/dist/packages/vue-3/src/VueNodeViewRenderer.d.ts +0 -48
- package/dist/packages/vue-3/src/VueRenderer.d.ts +0 -36
- package/dist/packages/vue-3/src/index.d.ts +0 -10
- package/dist/packages/vue-3/src/useEditor.d.ts +0 -3
- package/src/BubbleMenu.ts +0 -71
- package/src/FloatingMenu.ts +0 -66
package/dist/index.js
CHANGED
|
@@ -1,478 +1,576 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export * from '@tiptap/core';
|
|
5
|
-
import { FloatingMenuPlugin } from '@tiptap/extension-floating-menu';
|
|
6
|
-
|
|
7
|
-
const BubbleMenu = defineComponent({
|
|
8
|
-
name: 'BubbleMenu',
|
|
9
|
-
props: {
|
|
10
|
-
pluginKey: {
|
|
11
|
-
type: [String, Object],
|
|
12
|
-
default: 'bubbleMenu',
|
|
13
|
-
},
|
|
14
|
-
editor: {
|
|
15
|
-
type: Object,
|
|
16
|
-
required: true,
|
|
17
|
-
},
|
|
18
|
-
updateDelay: {
|
|
19
|
-
type: Number,
|
|
20
|
-
default: undefined,
|
|
21
|
-
},
|
|
22
|
-
tippyOptions: {
|
|
23
|
-
type: Object,
|
|
24
|
-
default: () => ({}),
|
|
25
|
-
},
|
|
26
|
-
shouldShow: {
|
|
27
|
-
type: Function,
|
|
28
|
-
default: null,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
setup(props, { slots }) {
|
|
32
|
-
const root = ref(null);
|
|
33
|
-
onMounted(() => {
|
|
34
|
-
const { updateDelay, editor, pluginKey, shouldShow, tippyOptions, } = props;
|
|
35
|
-
editor.registerPlugin(BubbleMenuPlugin({
|
|
36
|
-
updateDelay,
|
|
37
|
-
editor,
|
|
38
|
-
element: root.value,
|
|
39
|
-
pluginKey,
|
|
40
|
-
shouldShow,
|
|
41
|
-
tippyOptions,
|
|
42
|
-
}));
|
|
43
|
-
});
|
|
44
|
-
onBeforeUnmount(() => {
|
|
45
|
-
const { pluginKey, editor } = props;
|
|
46
|
-
editor.unregisterPlugin(pluginKey);
|
|
47
|
-
});
|
|
48
|
-
return () => { var _a; return h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
|
|
1
|
+
// src/Editor.ts
|
|
2
|
+
import { Editor as CoreEditor } from "@tiptap/core";
|
|
3
|
+
import { customRef, markRaw } from "vue";
|
|
52
4
|
function useDebouncedRef(value) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
trigger();
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
class Editor extends Editor$1 {
|
|
73
|
-
constructor(options = {}) {
|
|
74
|
-
super(options);
|
|
75
|
-
this.contentComponent = null;
|
|
76
|
-
this.appContext = null;
|
|
77
|
-
this.reactiveState = useDebouncedRef(this.view.state);
|
|
78
|
-
this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage);
|
|
79
|
-
this.on('beforeTransaction', ({ nextState }) => {
|
|
80
|
-
this.reactiveState.value = nextState;
|
|
81
|
-
this.reactiveExtensionStorage.value = this.extensionStorage;
|
|
5
|
+
return customRef((track, trigger) => {
|
|
6
|
+
return {
|
|
7
|
+
get() {
|
|
8
|
+
track();
|
|
9
|
+
return value;
|
|
10
|
+
},
|
|
11
|
+
set(newValue) {
|
|
12
|
+
value = newValue;
|
|
13
|
+
requestAnimationFrame(() => {
|
|
14
|
+
requestAnimationFrame(() => {
|
|
15
|
+
trigger();
|
|
16
|
+
});
|
|
82
17
|
});
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
var Editor = class extends CoreEditor {
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
super(options);
|
|
25
|
+
this.contentComponent = null;
|
|
26
|
+
this.appContext = null;
|
|
27
|
+
this.reactiveState = useDebouncedRef(this.view.state);
|
|
28
|
+
this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage);
|
|
29
|
+
this.on("beforeTransaction", ({ nextState }) => {
|
|
30
|
+
this.reactiveState.value = nextState;
|
|
31
|
+
this.reactiveExtensionStorage.value = this.extensionStorage;
|
|
32
|
+
});
|
|
33
|
+
return markRaw(this);
|
|
34
|
+
}
|
|
35
|
+
get state() {
|
|
36
|
+
return this.reactiveState ? this.reactiveState.value : this.view.state;
|
|
37
|
+
}
|
|
38
|
+
get storage() {
|
|
39
|
+
return this.reactiveExtensionStorage ? this.reactiveExtensionStorage.value : super.storage;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Register a ProseMirror plugin.
|
|
43
|
+
*/
|
|
44
|
+
registerPlugin(plugin, handlePlugins) {
|
|
45
|
+
const nextState = super.registerPlugin(plugin, handlePlugins);
|
|
46
|
+
if (this.reactiveState) {
|
|
47
|
+
this.reactiveState.value = nextState;
|
|
97
48
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
49
|
+
return nextState;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Unregister a ProseMirror plugin.
|
|
53
|
+
*/
|
|
54
|
+
unregisterPlugin(nameOrPluginKey) {
|
|
55
|
+
const nextState = super.unregisterPlugin(nameOrPluginKey);
|
|
56
|
+
if (this.reactiveState && nextState) {
|
|
57
|
+
this.reactiveState.value = nextState;
|
|
104
58
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
name: 'EditorContent',
|
|
109
|
-
props: {
|
|
110
|
-
editor: {
|
|
111
|
-
default: null,
|
|
112
|
-
type: Object,
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
setup(props) {
|
|
116
|
-
const rootEl = ref();
|
|
117
|
-
const instance = getCurrentInstance();
|
|
118
|
-
watchEffect(() => {
|
|
119
|
-
const editor = props.editor;
|
|
120
|
-
if (editor && editor.options.element && rootEl.value) {
|
|
121
|
-
nextTick(() => {
|
|
122
|
-
if (!rootEl.value || !editor.options.element.firstChild) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const element = unref(rootEl.value);
|
|
126
|
-
rootEl.value.append(...editor.options.element.childNodes);
|
|
127
|
-
// @ts-ignore
|
|
128
|
-
editor.contentComponent = instance.ctx._;
|
|
129
|
-
if (instance) {
|
|
130
|
-
editor.appContext = {
|
|
131
|
-
...instance.appContext,
|
|
132
|
-
provides: {
|
|
133
|
-
// @ts-ignore
|
|
134
|
-
...instance.provides,
|
|
135
|
-
...instance.appContext.provides,
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
editor.setOptions({
|
|
140
|
-
element,
|
|
141
|
-
});
|
|
142
|
-
editor.createNodeViews();
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
onBeforeUnmount(() => {
|
|
147
|
-
const editor = props.editor;
|
|
148
|
-
if (!editor) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
// destroy nodeviews before vue removes dom element
|
|
152
|
-
if (!editor.isDestroyed) {
|
|
153
|
-
editor.view.setProps({
|
|
154
|
-
nodeViews: {},
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
editor.contentComponent = null;
|
|
158
|
-
editor.appContext = null;
|
|
159
|
-
if (!editor.options.element.firstChild) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const newElement = document.createElement('div');
|
|
163
|
-
newElement.append(...editor.options.element.childNodes);
|
|
164
|
-
editor.setOptions({
|
|
165
|
-
element: newElement,
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
return { rootEl };
|
|
169
|
-
},
|
|
170
|
-
render() {
|
|
171
|
-
return h('div', {
|
|
172
|
-
ref: (el) => { this.rootEl = el; },
|
|
173
|
-
});
|
|
174
|
-
},
|
|
175
|
-
});
|
|
59
|
+
return nextState;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
176
62
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
63
|
+
// src/EditorContent.ts
|
|
64
|
+
import { defineComponent, getCurrentInstance, h, nextTick, onBeforeUnmount, ref, unref, watchEffect } from "vue";
|
|
65
|
+
var EditorContent = defineComponent({
|
|
66
|
+
name: "EditorContent",
|
|
67
|
+
props: {
|
|
68
|
+
editor: {
|
|
69
|
+
default: null,
|
|
70
|
+
type: Object
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
setup(props) {
|
|
74
|
+
const rootEl = ref();
|
|
75
|
+
const instance = getCurrentInstance();
|
|
76
|
+
watchEffect(() => {
|
|
77
|
+
const editor = props.editor;
|
|
78
|
+
if (editor && editor.options.element && rootEl.value) {
|
|
79
|
+
nextTick(() => {
|
|
80
|
+
var _a;
|
|
81
|
+
if (!rootEl.value || !((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const element = unref(rootEl.value);
|
|
85
|
+
rootEl.value.append(...editor.options.element.childNodes);
|
|
86
|
+
editor.contentComponent = instance.ctx._;
|
|
87
|
+
if (instance) {
|
|
88
|
+
editor.appContext = {
|
|
89
|
+
...instance.appContext,
|
|
90
|
+
// Vue internally uses prototype chain to forward/shadow injects across the entire component chain
|
|
91
|
+
// so don't use object spread operator or 'Object.assign' and just set `provides` as is on editor's appContext
|
|
92
|
+
// @ts-expect-error forward instance's 'provides' into appContext
|
|
93
|
+
provides: instance.provides
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
editor.setOptions({
|
|
97
|
+
element
|
|
98
|
+
});
|
|
99
|
+
editor.createNodeViews();
|
|
214
100
|
});
|
|
215
|
-
|
|
216
|
-
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
onBeforeUnmount(() => {
|
|
104
|
+
const editor = props.editor;
|
|
105
|
+
if (!editor) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
editor.contentComponent = null;
|
|
109
|
+
editor.appContext = null;
|
|
110
|
+
});
|
|
111
|
+
return { rootEl };
|
|
112
|
+
},
|
|
113
|
+
render() {
|
|
114
|
+
return h("div", {
|
|
115
|
+
ref: (el) => {
|
|
116
|
+
this.rootEl = el;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
217
120
|
});
|
|
218
121
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
122
|
+
// src/NodeViewContent.ts
|
|
123
|
+
import { defineComponent as defineComponent2, h as h2 } from "vue";
|
|
124
|
+
var NodeViewContent = defineComponent2({
|
|
125
|
+
name: "NodeViewContent",
|
|
126
|
+
props: {
|
|
127
|
+
as: {
|
|
128
|
+
type: String,
|
|
129
|
+
default: "div"
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
render() {
|
|
133
|
+
return h2(this.as, {
|
|
134
|
+
style: {
|
|
135
|
+
whiteSpace: "pre-wrap"
|
|
136
|
+
},
|
|
137
|
+
"data-node-view-content": ""
|
|
138
|
+
});
|
|
139
|
+
}
|
|
235
140
|
});
|
|
236
141
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
142
|
+
// src/NodeViewWrapper.ts
|
|
143
|
+
import { defineComponent as defineComponent3, h as h3 } from "vue";
|
|
144
|
+
var NodeViewWrapper = defineComponent3({
|
|
145
|
+
name: "NodeViewWrapper",
|
|
146
|
+
props: {
|
|
147
|
+
as: {
|
|
148
|
+
type: String,
|
|
149
|
+
default: "div"
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
inject: ["onDragStart", "decorationClasses"],
|
|
153
|
+
render() {
|
|
154
|
+
var _a, _b;
|
|
155
|
+
return h3(
|
|
156
|
+
this.as,
|
|
157
|
+
{
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
class: this.decorationClasses,
|
|
160
|
+
style: {
|
|
161
|
+
whiteSpace: "normal"
|
|
243
162
|
},
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
style: {
|
|
252
|
-
whiteSpace: 'normal',
|
|
253
|
-
},
|
|
254
|
-
'data-node-view-wrapper': '',
|
|
255
|
-
// @ts-ignore (https://github.com/vuejs/vue-next/issues/3031)
|
|
256
|
-
onDragstart: this.onDragStart,
|
|
257
|
-
}, (_b = (_a = this.$slots).default) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
258
|
-
},
|
|
163
|
+
"data-node-view-wrapper": "",
|
|
164
|
+
// @ts-ignore (https://github.com/vuejs/vue-next/issues/3031)
|
|
165
|
+
onDragstart: this.onDragStart
|
|
166
|
+
},
|
|
167
|
+
(_b = (_a = this.$slots).default) == null ? void 0 : _b.call(_a)
|
|
168
|
+
);
|
|
169
|
+
}
|
|
259
170
|
});
|
|
260
171
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
172
|
+
// src/useEditor.ts
|
|
173
|
+
import { onBeforeUnmount as onBeforeUnmount2, onMounted, shallowRef } from "vue";
|
|
174
|
+
var useEditor = (options = {}) => {
|
|
175
|
+
const editor = shallowRef();
|
|
176
|
+
onMounted(() => {
|
|
177
|
+
editor.value = new Editor(options);
|
|
178
|
+
});
|
|
179
|
+
onBeforeUnmount2(() => {
|
|
180
|
+
var _a, _b, _c;
|
|
181
|
+
const nodes = (_a = editor.value) == null ? void 0 : _a.options.element;
|
|
182
|
+
const newEl = nodes == null ? void 0 : nodes.cloneNode(true);
|
|
183
|
+
(_b = nodes == null ? void 0 : nodes.parentNode) == null ? void 0 : _b.replaceChild(newEl, nodes);
|
|
184
|
+
(_c = editor.value) == null ? void 0 : _c.destroy();
|
|
185
|
+
});
|
|
186
|
+
return editor;
|
|
271
187
|
};
|
|
272
188
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
189
|
+
// src/VueMarkViewRenderer.ts
|
|
190
|
+
import { MarkView } from "@tiptap/core";
|
|
191
|
+
import { defineComponent as defineComponent4, h as h5, toRaw } from "vue";
|
|
192
|
+
|
|
193
|
+
// src/VueRenderer.ts
|
|
194
|
+
import { h as h4, markRaw as markRaw2, reactive, render } from "vue";
|
|
195
|
+
var VueRenderer = class {
|
|
196
|
+
constructor(component, { props = {}, editor }) {
|
|
197
|
+
this.editor = editor;
|
|
198
|
+
this.component = markRaw2(component);
|
|
199
|
+
this.el = document.createElement("div");
|
|
200
|
+
this.props = reactive(props);
|
|
201
|
+
this.renderedComponent = this.renderComponent();
|
|
202
|
+
}
|
|
203
|
+
get element() {
|
|
204
|
+
return this.renderedComponent.el;
|
|
205
|
+
}
|
|
206
|
+
get ref() {
|
|
207
|
+
var _a, _b, _c, _d;
|
|
208
|
+
if ((_b = (_a = this.renderedComponent.vNode) == null ? void 0 : _a.component) == null ? void 0 : _b.exposed) {
|
|
209
|
+
return this.renderedComponent.vNode.component.exposed;
|
|
284
210
|
}
|
|
285
|
-
|
|
286
|
-
|
|
211
|
+
return (_d = (_c = this.renderedComponent.vNode) == null ? void 0 : _c.component) == null ? void 0 : _d.proxy;
|
|
212
|
+
}
|
|
213
|
+
renderComponent() {
|
|
214
|
+
let vNode = h4(this.component, this.props);
|
|
215
|
+
if (this.editor.appContext) {
|
|
216
|
+
vNode.appContext = this.editor.appContext;
|
|
287
217
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (typeof document !== 'undefined' && this.el) {
|
|
291
|
-
render(vNode, this.el);
|
|
292
|
-
}
|
|
293
|
-
const destroy = () => {
|
|
294
|
-
if (this.el) {
|
|
295
|
-
render(null, this.el);
|
|
296
|
-
}
|
|
297
|
-
this.el = null;
|
|
298
|
-
vNode = null;
|
|
299
|
-
};
|
|
300
|
-
return { vNode, destroy, el: this.el ? this.el.firstElementChild : null };
|
|
218
|
+
if (typeof document !== "undefined" && this.el) {
|
|
219
|
+
render(vNode, this.el);
|
|
301
220
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
221
|
+
const destroy = () => {
|
|
222
|
+
if (this.el) {
|
|
223
|
+
render(null, this.el);
|
|
224
|
+
}
|
|
225
|
+
this.el = null;
|
|
226
|
+
vNode = null;
|
|
227
|
+
};
|
|
228
|
+
return { vNode, destroy, el: this.el ? this.el.firstElementChild : null };
|
|
229
|
+
}
|
|
230
|
+
updateProps(props = {}) {
|
|
231
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
232
|
+
this.props[key] = value;
|
|
233
|
+
});
|
|
234
|
+
this.renderComponent();
|
|
235
|
+
}
|
|
236
|
+
destroy() {
|
|
237
|
+
this.renderedComponent.destroy();
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// src/VueMarkViewRenderer.ts
|
|
242
|
+
var markViewProps = {
|
|
243
|
+
editor: {
|
|
244
|
+
type: Object,
|
|
245
|
+
required: true
|
|
246
|
+
},
|
|
247
|
+
mark: {
|
|
248
|
+
type: Object,
|
|
249
|
+
required: true
|
|
250
|
+
},
|
|
251
|
+
extension: {
|
|
252
|
+
type: Object,
|
|
253
|
+
required: true
|
|
254
|
+
},
|
|
255
|
+
inline: {
|
|
256
|
+
type: Boolean,
|
|
257
|
+
required: true
|
|
258
|
+
},
|
|
259
|
+
view: {
|
|
260
|
+
type: Object,
|
|
261
|
+
required: true
|
|
262
|
+
},
|
|
263
|
+
updateAttributes: {
|
|
264
|
+
type: Function,
|
|
265
|
+
required: true
|
|
266
|
+
},
|
|
267
|
+
HTMLAttributes: {
|
|
268
|
+
type: Object,
|
|
269
|
+
required: true
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
var MarkViewContent = defineComponent4({
|
|
273
|
+
name: "MarkViewContent",
|
|
274
|
+
props: {
|
|
275
|
+
as: {
|
|
276
|
+
type: String,
|
|
277
|
+
default: "span"
|
|
309
278
|
}
|
|
310
|
-
|
|
311
|
-
|
|
279
|
+
},
|
|
280
|
+
render() {
|
|
281
|
+
return h5(this.as, {
|
|
282
|
+
style: {
|
|
283
|
+
whiteSpace: "inherit"
|
|
284
|
+
},
|
|
285
|
+
"data-mark-view-content": ""
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
var VueMarkView = class extends MarkView {
|
|
290
|
+
constructor(component, props, options) {
|
|
291
|
+
super(component, props, options);
|
|
292
|
+
const componentProps = { ...props, updateAttributes: this.updateAttributes.bind(this) };
|
|
293
|
+
const extendedComponent = defineComponent4({
|
|
294
|
+
extends: { ...component },
|
|
295
|
+
props: Object.keys(componentProps),
|
|
296
|
+
template: this.component.template,
|
|
297
|
+
setup: (reactiveProps) => {
|
|
298
|
+
var _a;
|
|
299
|
+
return (_a = component.setup) == null ? void 0 : _a.call(component, reactiveProps, {
|
|
300
|
+
expose: () => void 0
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
// Add support for scoped styles
|
|
304
|
+
__scopeId: component.__scopeId,
|
|
305
|
+
__cssModules: component.__cssModules,
|
|
306
|
+
__name: component.__name,
|
|
307
|
+
__file: component.__file
|
|
308
|
+
});
|
|
309
|
+
this.renderer = new VueRenderer(extendedComponent, {
|
|
310
|
+
editor: this.editor,
|
|
311
|
+
props: componentProps
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
get dom() {
|
|
315
|
+
return this.renderer.element;
|
|
316
|
+
}
|
|
317
|
+
get contentDOM() {
|
|
318
|
+
return this.dom.querySelector("[data-mark-view-content]");
|
|
319
|
+
}
|
|
320
|
+
updateAttributes(attrs) {
|
|
321
|
+
const unproxiedMark = toRaw(this.mark);
|
|
322
|
+
super.updateAttributes(attrs, unproxiedMark);
|
|
323
|
+
}
|
|
324
|
+
destroy() {
|
|
325
|
+
this.renderer.destroy();
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
function VueMarkViewRenderer(component, options = {}) {
|
|
329
|
+
return (props) => {
|
|
330
|
+
if (!props.editor.contentComponent) {
|
|
331
|
+
return {};
|
|
312
332
|
}
|
|
333
|
+
return new VueMarkView(component, props, options);
|
|
334
|
+
};
|
|
313
335
|
}
|
|
314
336
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
337
|
+
// src/VueNodeViewRenderer.ts
|
|
338
|
+
import { NodeView } from "@tiptap/core";
|
|
339
|
+
import { defineComponent as defineComponent5, provide, ref as ref2 } from "vue";
|
|
340
|
+
var nodeViewProps = {
|
|
341
|
+
editor: {
|
|
342
|
+
type: Object,
|
|
343
|
+
required: true
|
|
344
|
+
},
|
|
345
|
+
node: {
|
|
346
|
+
type: Object,
|
|
347
|
+
required: true
|
|
348
|
+
},
|
|
349
|
+
decorations: {
|
|
350
|
+
type: Object,
|
|
351
|
+
required: true
|
|
352
|
+
},
|
|
353
|
+
selected: {
|
|
354
|
+
type: Boolean,
|
|
355
|
+
required: true
|
|
356
|
+
},
|
|
357
|
+
extension: {
|
|
358
|
+
type: Object,
|
|
359
|
+
required: true
|
|
360
|
+
},
|
|
361
|
+
getPos: {
|
|
362
|
+
type: Function,
|
|
363
|
+
required: true
|
|
364
|
+
},
|
|
365
|
+
updateAttributes: {
|
|
366
|
+
type: Function,
|
|
367
|
+
required: true
|
|
368
|
+
},
|
|
369
|
+
deleteNode: {
|
|
370
|
+
type: Function,
|
|
371
|
+
required: true
|
|
372
|
+
},
|
|
373
|
+
view: {
|
|
374
|
+
type: Object,
|
|
375
|
+
required: true
|
|
376
|
+
},
|
|
377
|
+
innerDecorations: {
|
|
378
|
+
type: Object,
|
|
379
|
+
required: true
|
|
380
|
+
},
|
|
381
|
+
HTMLAttributes: {
|
|
382
|
+
type: Object,
|
|
383
|
+
required: true
|
|
384
|
+
}
|
|
348
385
|
};
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
// @ts-ignore
|
|
377
|
-
// eslint-disable-next-line
|
|
378
|
-
__scopeId: this.component.__scopeId,
|
|
379
|
-
// add support for CSS Modules
|
|
380
|
-
// @ts-ignore
|
|
381
|
-
// eslint-disable-next-line
|
|
382
|
-
__cssModules: this.component.__cssModules,
|
|
383
|
-
// add support for vue devtools
|
|
384
|
-
// @ts-ignore
|
|
385
|
-
// eslint-disable-next-line
|
|
386
|
-
__name: this.component.__name,
|
|
387
|
-
// @ts-ignore
|
|
388
|
-
// eslint-disable-next-line
|
|
389
|
-
__file: this.component.__file,
|
|
390
|
-
});
|
|
391
|
-
this.renderer = new VueRenderer(extendedComponent, {
|
|
392
|
-
editor: this.editor,
|
|
393
|
-
props,
|
|
386
|
+
var VueNodeView = class extends NodeView {
|
|
387
|
+
mount() {
|
|
388
|
+
const props = {
|
|
389
|
+
editor: this.editor,
|
|
390
|
+
node: this.node,
|
|
391
|
+
decorations: this.decorations,
|
|
392
|
+
innerDecorations: this.innerDecorations,
|
|
393
|
+
view: this.view,
|
|
394
|
+
selected: false,
|
|
395
|
+
extension: this.extension,
|
|
396
|
+
HTMLAttributes: this.HTMLAttributes,
|
|
397
|
+
getPos: () => this.getPos(),
|
|
398
|
+
updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
|
|
399
|
+
deleteNode: () => this.deleteNode()
|
|
400
|
+
};
|
|
401
|
+
const onDragStart = this.onDragStart.bind(this);
|
|
402
|
+
this.decorationClasses = ref2(this.getDecorationClasses());
|
|
403
|
+
const extendedComponent = defineComponent5({
|
|
404
|
+
extends: { ...this.component },
|
|
405
|
+
props: Object.keys(props),
|
|
406
|
+
template: this.component.template,
|
|
407
|
+
setup: (reactiveProps) => {
|
|
408
|
+
var _a, _b;
|
|
409
|
+
provide("onDragStart", onDragStart);
|
|
410
|
+
provide("decorationClasses", this.decorationClasses);
|
|
411
|
+
return (_b = (_a = this.component).setup) == null ? void 0 : _b.call(_a, reactiveProps, {
|
|
412
|
+
expose: () => void 0
|
|
394
413
|
});
|
|
414
|
+
},
|
|
415
|
+
// add support for scoped styles
|
|
416
|
+
// @ts-ignore
|
|
417
|
+
// eslint-disable-next-line
|
|
418
|
+
__scopeId: this.component.__scopeId,
|
|
419
|
+
// add support for CSS Modules
|
|
420
|
+
// @ts-ignore
|
|
421
|
+
// eslint-disable-next-line
|
|
422
|
+
__cssModules: this.component.__cssModules,
|
|
423
|
+
// add support for vue devtools
|
|
424
|
+
// @ts-ignore
|
|
425
|
+
// eslint-disable-next-line
|
|
426
|
+
__name: this.component.__name,
|
|
427
|
+
// @ts-ignore
|
|
428
|
+
// eslint-disable-next-line
|
|
429
|
+
__file: this.component.__file
|
|
430
|
+
});
|
|
431
|
+
this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
|
|
432
|
+
this.editor.on("selectionUpdate", this.handleSelectionUpdate);
|
|
433
|
+
this.renderer = new VueRenderer(extendedComponent, {
|
|
434
|
+
editor: this.editor,
|
|
435
|
+
props
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Return the DOM element.
|
|
440
|
+
* This is the element that will be used to display the node view.
|
|
441
|
+
*/
|
|
442
|
+
get dom() {
|
|
443
|
+
if (!this.renderer.element || !this.renderer.element.hasAttribute("data-node-view-wrapper")) {
|
|
444
|
+
throw Error("Please use the NodeViewWrapper component for your node view.");
|
|
395
445
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
446
|
+
return this.renderer.element;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Return the content DOM element.
|
|
450
|
+
* This is the element that will be used to display the rich-text content of the node.
|
|
451
|
+
*/
|
|
452
|
+
get contentDOM() {
|
|
453
|
+
if (this.node.isLeaf) {
|
|
454
|
+
return null;
|
|
401
455
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
456
|
+
return this.dom.querySelector("[data-node-view-content]");
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* On editor selection update, check if the node is selected.
|
|
460
|
+
* If it is, call `selectNode`, otherwise call `deselectNode`.
|
|
461
|
+
*/
|
|
462
|
+
handleSelectionUpdate() {
|
|
463
|
+
const { from, to } = this.editor.state.selection;
|
|
464
|
+
const pos = this.getPos();
|
|
465
|
+
if (typeof pos !== "number") {
|
|
466
|
+
return;
|
|
408
467
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
return this.options.update({
|
|
420
|
-
oldNode,
|
|
421
|
-
oldDecorations,
|
|
422
|
-
newNode: node,
|
|
423
|
-
newDecorations: decorations,
|
|
424
|
-
updateProps: () => updateProps({ node, decorations }),
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
if (node.type !== this.node.type) {
|
|
428
|
-
return false;
|
|
429
|
-
}
|
|
430
|
-
if (node === this.node && this.decorations === decorations) {
|
|
431
|
-
return true;
|
|
432
|
-
}
|
|
433
|
-
this.node = node;
|
|
434
|
-
this.decorations = decorations;
|
|
435
|
-
updateProps({ node, decorations });
|
|
436
|
-
return true;
|
|
468
|
+
if (from <= pos && to >= pos + this.node.nodeSize) {
|
|
469
|
+
if (this.renderer.props.selected) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
this.selectNode();
|
|
473
|
+
} else {
|
|
474
|
+
if (!this.renderer.props.selected) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
this.deselectNode();
|
|
437
478
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* On update, update the React component.
|
|
482
|
+
* To prevent unnecessary updates, the `update` option can be used.
|
|
483
|
+
*/
|
|
484
|
+
update(node, decorations, innerDecorations) {
|
|
485
|
+
const rerenderComponent = (props) => {
|
|
486
|
+
this.decorationClasses.value = this.getDecorationClasses();
|
|
487
|
+
this.renderer.updateProps(props);
|
|
488
|
+
};
|
|
489
|
+
if (typeof this.options.update === "function") {
|
|
490
|
+
const oldNode = this.node;
|
|
491
|
+
const oldDecorations = this.decorations;
|
|
492
|
+
const oldInnerDecorations = this.innerDecorations;
|
|
493
|
+
this.node = node;
|
|
494
|
+
this.decorations = decorations;
|
|
495
|
+
this.innerDecorations = innerDecorations;
|
|
496
|
+
return this.options.update({
|
|
497
|
+
oldNode,
|
|
498
|
+
oldDecorations,
|
|
499
|
+
newNode: node,
|
|
500
|
+
newDecorations: decorations,
|
|
501
|
+
oldInnerDecorations,
|
|
502
|
+
innerDecorations,
|
|
503
|
+
updateProps: () => rerenderComponent({ node, decorations, innerDecorations })
|
|
504
|
+
});
|
|
445
505
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
selected: false,
|
|
449
|
-
});
|
|
450
|
-
if (this.renderer.element) {
|
|
451
|
-
this.renderer.element.classList.remove('ProseMirror-selectednode');
|
|
452
|
-
}
|
|
506
|
+
if (node.type !== this.node.type) {
|
|
507
|
+
return false;
|
|
453
508
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
// @ts-ignore
|
|
457
|
-
.map(item => item.type.attrs.class)
|
|
458
|
-
.flat()
|
|
459
|
-
.join(' '));
|
|
509
|
+
if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {
|
|
510
|
+
return true;
|
|
460
511
|
}
|
|
461
|
-
|
|
462
|
-
|
|
512
|
+
this.node = node;
|
|
513
|
+
this.decorations = decorations;
|
|
514
|
+
this.innerDecorations = innerDecorations;
|
|
515
|
+
rerenderComponent({ node, decorations, innerDecorations });
|
|
516
|
+
return true;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Select the node.
|
|
520
|
+
* Add the `selected` prop and the `ProseMirror-selectednode` class.
|
|
521
|
+
*/
|
|
522
|
+
selectNode() {
|
|
523
|
+
this.renderer.updateProps({
|
|
524
|
+
selected: true
|
|
525
|
+
});
|
|
526
|
+
if (this.renderer.element) {
|
|
527
|
+
this.renderer.element.classList.add("ProseMirror-selectednode");
|
|
463
528
|
}
|
|
464
|
-
}
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Deselect the node.
|
|
532
|
+
* Remove the `selected` prop and the `ProseMirror-selectednode` class.
|
|
533
|
+
*/
|
|
534
|
+
deselectNode() {
|
|
535
|
+
this.renderer.updateProps({
|
|
536
|
+
selected: false
|
|
537
|
+
});
|
|
538
|
+
if (this.renderer.element) {
|
|
539
|
+
this.renderer.element.classList.remove("ProseMirror-selectednode");
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
getDecorationClasses() {
|
|
543
|
+
return this.decorations.map((item) => item.type.attrs.class).flat().join(" ");
|
|
544
|
+
}
|
|
545
|
+
destroy() {
|
|
546
|
+
this.renderer.destroy();
|
|
547
|
+
this.editor.off("selectionUpdate", this.handleSelectionUpdate);
|
|
548
|
+
}
|
|
549
|
+
};
|
|
465
550
|
function VueNodeViewRenderer(component, options) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
return new VueNodeView(component, props, options);
|
|
474
|
-
};
|
|
551
|
+
return (props) => {
|
|
552
|
+
if (!props.editor.contentComponent) {
|
|
553
|
+
return {};
|
|
554
|
+
}
|
|
555
|
+
const normalizedComponent = typeof component === "function" && "__vccOpts" in component ? component.__vccOpts : component;
|
|
556
|
+
return new VueNodeView(normalizedComponent, props, options);
|
|
557
|
+
};
|
|
475
558
|
}
|
|
476
559
|
|
|
477
|
-
|
|
478
|
-
|
|
560
|
+
// src/index.ts
|
|
561
|
+
export * from "@tiptap/core";
|
|
562
|
+
export {
|
|
563
|
+
Editor,
|
|
564
|
+
EditorContent,
|
|
565
|
+
MarkViewContent,
|
|
566
|
+
NodeViewContent,
|
|
567
|
+
NodeViewWrapper,
|
|
568
|
+
VueMarkView,
|
|
569
|
+
VueMarkViewRenderer,
|
|
570
|
+
VueNodeViewRenderer,
|
|
571
|
+
VueRenderer,
|
|
572
|
+
markViewProps,
|
|
573
|
+
nodeViewProps,
|
|
574
|
+
useEditor
|
|
575
|
+
};
|
|
576
|
+
//# sourceMappingURL=index.js.map
|