@mekari/pixel3-rich-text-editor 0.1.2 → 0.1.3-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-25RKPG44.mjs → chunk-47IOAHWN.mjs} +4 -2
- package/dist/{chunk-7BEXEMOE.mjs → chunk-6O4HSL2C.mjs} +4 -0
- package/dist/chunk-76GEEOAG.mjs +189 -0
- package/dist/{chunk-MKTM47RO.mjs → chunk-AIWY3FHJ.mjs} +1 -1
- package/dist/chunk-BWRU2WZN.mjs +202 -0
- package/dist/{chunk-ZO6THAT6.mjs → chunk-COZ45QUD.mjs} +1 -1
- package/dist/chunk-ENKUUZPM.mjs +124 -0
- package/dist/{chunk-Q7QLZISF.mjs → chunk-IFRJVX2K.mjs} +29 -1
- package/dist/{chunk-YE6FEVD4.mjs → chunk-UD5PDCGC.mjs} +18 -9
- package/dist/{chunk-YIEQVTEO.mjs → chunk-X2CB42A3.mjs} +1 -1
- package/dist/{chunk-5S2LSGJV.mjs → chunk-Y6UPQ6EU.mjs} +1 -1
- package/dist/{chunk-UBJOZ2IA.mjs → chunk-YWVVMJGP.mjs} +1 -1
- package/dist/{chunk-XNM3YX37.mjs → chunk-ZYSEHV5N.mjs} +13 -3
- package/dist/editor-toolbar.d.mts +2 -1
- package/dist/editor-toolbar.d.ts +2 -1
- package/dist/editor-toolbar.js +366 -16
- package/dist/editor-toolbar.mjs +10 -8
- package/dist/extensions/align-extension.js +27 -0
- package/dist/extensions/align-extension.mjs +2 -2
- package/dist/extensions/color-extension.js +27 -0
- package/dist/extensions/color-extension.mjs +2 -2
- package/dist/extensions/heading-extension.js +27 -0
- package/dist/extensions/heading-extension.mjs +2 -2
- package/dist/extensions/icons.d.mts +2 -1
- package/dist/extensions/icons.d.ts +2 -1
- package/dist/extensions/icons.js +31 -2
- package/dist/extensions/icons.mjs +5 -3
- package/dist/extensions/index.d.mts +6 -0
- package/dist/extensions/index.d.ts +6 -0
- package/dist/extensions/index.js +347 -2
- package/dist/extensions/index.mjs +18 -10
- package/dist/extensions/link-extension.js +27 -0
- package/dist/extensions/link-extension.mjs +2 -2
- package/dist/extensions/single-extension.d.mts +1 -1
- package/dist/extensions/single-extension.d.ts +1 -1
- package/dist/extensions/single-extension.js +28 -0
- package/dist/extensions/single-extension.mjs +2 -2
- package/dist/extensions/variable-extension.d.mts +19 -0
- package/dist/extensions/variable-extension.d.ts +19 -0
- package/dist/extensions/variable-extension.js +158 -0
- package/dist/extensions/variable-extension.mjs +7 -0
- package/dist/extensions/variable-list-extension.d.mts +33 -0
- package/dist/extensions/variable-list-extension.d.ts +33 -0
- package/dist/extensions/variable-list-extension.js +210 -0
- package/dist/extensions/variable-list-extension.mjs +7 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +596 -57
- package/dist/index.mjs +14 -11
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/modules/rich-text-editor.props.d.mts +5 -1
- package/dist/modules/rich-text-editor.props.d.ts +5 -1
- package/dist/modules/rich-text-editor.props.js +4 -0
- package/dist/modules/rich-text-editor.props.mjs +1 -1
- package/dist/modules/rich-text-editor.types.d.mts +10 -3
- package/dist/modules/rich-text-editor.types.d.ts +10 -3
- package/dist/rich-text-editor.d.mts +10 -1
- package/dist/rich-text-editor.d.ts +10 -1
- package/dist/rich-text-editor.js +596 -57
- package/dist/rich-text-editor.mjs +14 -11
- package/dist/rte-style-provider.mjs +2 -2
- package/dist/rte-variable-suggestion.d.mts +11 -0
- package/dist/rte-variable-suggestion.d.ts +11 -0
- package/dist/rte-variable-suggestion.js +405 -0
- package/dist/rte-variable-suggestion.mjs +10 -0
- package/package.json +7 -7
- /package/dist/{chunk-VYCDVS5I.mjs → chunk-HIHIKPNN.mjs} +0 -0
|
@@ -13,8 +13,9 @@ import {
|
|
|
13
13
|
RedoIcon,
|
|
14
14
|
StrikeIcon,
|
|
15
15
|
UnderlineIcon,
|
|
16
|
-
UndoIcon
|
|
17
|
-
|
|
16
|
+
UndoIcon,
|
|
17
|
+
VariableIcon
|
|
18
|
+
} from "./chunk-IFRJVX2K.mjs";
|
|
18
19
|
|
|
19
20
|
// src/extensions/single-extension.tsx
|
|
20
21
|
import { withDirectives as _withDirectives, resolveDirective as _resolveDirective, createVNode as _createVNode } from "vue";
|
|
@@ -56,6 +57,7 @@ var SingleExtention = defineComponent({
|
|
|
56
57
|
file: _createVNode(FileIcon, null, null),
|
|
57
58
|
audio: _createVNode(AudioIcon, null, null),
|
|
58
59
|
mention: _createVNode(MentionIcon, null, null),
|
|
60
|
+
variable: _createVNode(VariableIcon, null, null),
|
|
59
61
|
location: _createVNode(LocationIcon, null, null)
|
|
60
62
|
};
|
|
61
63
|
return () => _withDirectives(_createVNode("button", {
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-QZ7VFGWC.mjs";
|
|
4
|
+
|
|
5
|
+
// src/extensions/variable-list-extension.tsx
|
|
6
|
+
import { Fragment as _Fragment, createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
|
|
7
|
+
import { defineComponent, nextTick, ref, watch, computed } from "vue";
|
|
8
|
+
import { css } from "@mekari/pixel3-styled-system/css";
|
|
9
|
+
import { MpPopover, MpPopoverContent, MpPopoverList, MpPopoverListItem } from "@mekari/pixel3-popover";
|
|
10
|
+
import { MpText } from "@mekari/pixel3-text";
|
|
11
|
+
var VariableList = defineComponent({
|
|
12
|
+
name: "VariableList",
|
|
13
|
+
props: {
|
|
14
|
+
items: {
|
|
15
|
+
type: Array,
|
|
16
|
+
default: () => []
|
|
17
|
+
},
|
|
18
|
+
command: {
|
|
19
|
+
type: Function,
|
|
20
|
+
required: true
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
setup(props, {
|
|
24
|
+
expose
|
|
25
|
+
}) {
|
|
26
|
+
const selectedIndex = ref(0);
|
|
27
|
+
const listRef = ref(null);
|
|
28
|
+
const groupedItems = computed(() => {
|
|
29
|
+
const groups = {};
|
|
30
|
+
props.items.forEach((item) => {
|
|
31
|
+
const category = item.category || "OTHER";
|
|
32
|
+
if (!groups[category]) {
|
|
33
|
+
groups[category] = [];
|
|
34
|
+
}
|
|
35
|
+
groups[category].push(item);
|
|
36
|
+
});
|
|
37
|
+
return Object.entries(groups).map(([category, items]) => ({
|
|
38
|
+
category,
|
|
39
|
+
items
|
|
40
|
+
}));
|
|
41
|
+
});
|
|
42
|
+
const scrollToFocusedItem = /* @__PURE__ */ __name(() => {
|
|
43
|
+
nextTick(() => {
|
|
44
|
+
if (!listRef.value)
|
|
45
|
+
return;
|
|
46
|
+
const targetItem = listRef.value.querySelector('[data-active="true"], [data-highlight]');
|
|
47
|
+
if (targetItem) {
|
|
48
|
+
targetItem.scrollIntoView({
|
|
49
|
+
block: "nearest"
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}, "scrollToFocusedItem");
|
|
54
|
+
watch(() => props.items, () => {
|
|
55
|
+
selectedIndex.value = 0;
|
|
56
|
+
});
|
|
57
|
+
const onSelect = /* @__PURE__ */ __name((index) => {
|
|
58
|
+
const item = props.items[index];
|
|
59
|
+
if (item) {
|
|
60
|
+
props.command({
|
|
61
|
+
...item,
|
|
62
|
+
label: item.id
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}, "onSelect");
|
|
66
|
+
const onKeyDown = /* @__PURE__ */ __name(({
|
|
67
|
+
event
|
|
68
|
+
}) => {
|
|
69
|
+
if (!props.items.length) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
if (event.key === "ArrowUp") {
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
const total = props.items.length;
|
|
75
|
+
selectedIndex.value = (selectedIndex.value + total - 1) % total;
|
|
76
|
+
scrollToFocusedItem();
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
if (event.key === "ArrowDown") {
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
selectedIndex.value = (selectedIndex.value + 1) % props.items.length;
|
|
82
|
+
scrollToFocusedItem();
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
if (event.key === "Enter") {
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
onSelect(selectedIndex.value);
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}, "onKeyDown");
|
|
92
|
+
expose({
|
|
93
|
+
onKeyDown
|
|
94
|
+
});
|
|
95
|
+
return () => _createVNode(MpPopover, {
|
|
96
|
+
"id": "popover-rte-variable-list",
|
|
97
|
+
"is-manual": true,
|
|
98
|
+
"is-default-open": true,
|
|
99
|
+
"is-open": true
|
|
100
|
+
}, {
|
|
101
|
+
default: () => [_createVNode(MpPopoverContent, {
|
|
102
|
+
"class": css({
|
|
103
|
+
width: "280px",
|
|
104
|
+
maxHeight: "284px",
|
|
105
|
+
overflowY: "auto"
|
|
106
|
+
})
|
|
107
|
+
}, {
|
|
108
|
+
default: () => [_createVNode(MpPopoverList, {
|
|
109
|
+
"ref": (element) => {
|
|
110
|
+
var _a;
|
|
111
|
+
if (!element) {
|
|
112
|
+
listRef.value = null;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
listRef.value = (_a = element.$el) != null ? _a : element;
|
|
116
|
+
},
|
|
117
|
+
"data-pixel-rte": true
|
|
118
|
+
}, {
|
|
119
|
+
default: () => [!props.items.length && _createVNode(MpText, {
|
|
120
|
+
"color": "text.secondary",
|
|
121
|
+
"class": css({
|
|
122
|
+
px: "3",
|
|
123
|
+
py: "2"
|
|
124
|
+
})
|
|
125
|
+
}, {
|
|
126
|
+
default: () => [_createTextVNode("No result")]
|
|
127
|
+
}), groupedItems.value.map((group) => {
|
|
128
|
+
return _createVNode(_Fragment, null, [_createVNode(MpText, {
|
|
129
|
+
"size": "label-small",
|
|
130
|
+
"color": "text.secondary",
|
|
131
|
+
"class": css({
|
|
132
|
+
px: "3",
|
|
133
|
+
py: "2",
|
|
134
|
+
textTransform: "uppercase",
|
|
135
|
+
textAlign: "left",
|
|
136
|
+
letterSpacing: "0.05em",
|
|
137
|
+
display: "block",
|
|
138
|
+
width: "full"
|
|
139
|
+
})
|
|
140
|
+
}, {
|
|
141
|
+
default: () => [group.category]
|
|
142
|
+
}), group.items.map((item) => {
|
|
143
|
+
const itemIndex = props.items.indexOf(item);
|
|
144
|
+
return _createVNode(MpPopoverListItem, {
|
|
145
|
+
"key": `${item.id}-${itemIndex}`,
|
|
146
|
+
"onMousedown": (event) => event.preventDefault(),
|
|
147
|
+
"onMouseenter": () => {
|
|
148
|
+
selectedIndex.value = itemIndex;
|
|
149
|
+
},
|
|
150
|
+
"onClick": () => {
|
|
151
|
+
onSelect(itemIndex);
|
|
152
|
+
}
|
|
153
|
+
}, {
|
|
154
|
+
default: () => [_createVNode("div", {
|
|
155
|
+
"class": css({
|
|
156
|
+
display: "flex",
|
|
157
|
+
flexDirection: "column",
|
|
158
|
+
alignItems: "flex-start",
|
|
159
|
+
minWidth: "0",
|
|
160
|
+
width: "full",
|
|
161
|
+
gap: "0.5"
|
|
162
|
+
})
|
|
163
|
+
}, [_createVNode(MpText, {
|
|
164
|
+
"size": "label",
|
|
165
|
+
"is-truncated": true
|
|
166
|
+
}, {
|
|
167
|
+
default: () => [item.name || "Unknown"]
|
|
168
|
+
}), _createVNode(MpText, {
|
|
169
|
+
"size": "label-small",
|
|
170
|
+
"color": "text.secondary",
|
|
171
|
+
"is-truncated": true,
|
|
172
|
+
"class": css({
|
|
173
|
+
fontFamily: "mono"
|
|
174
|
+
})
|
|
175
|
+
}, {
|
|
176
|
+
default: () => [`{${item.id}}`]
|
|
177
|
+
})])]
|
|
178
|
+
});
|
|
179
|
+
})]);
|
|
180
|
+
})]
|
|
181
|
+
})]
|
|
182
|
+
})]
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
export {
|
|
188
|
+
VariableList
|
|
189
|
+
};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VariableList
|
|
3
|
+
} from "./chunk-76GEEOAG.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__name
|
|
6
|
+
} from "./chunk-QZ7VFGWC.mjs";
|
|
7
|
+
|
|
8
|
+
// src/rte-variable-suggestion.ts
|
|
9
|
+
import { VueRenderer } from "@tiptap/vue-3";
|
|
10
|
+
import { createPopper } from "@popperjs/core";
|
|
11
|
+
import { PluginKey } from "@tiptap/pm/state";
|
|
12
|
+
var VariablePluginKey = new PluginKey("variable");
|
|
13
|
+
var MAX_SUGGESTION_ITEMS = 50;
|
|
14
|
+
var getFilteredSuggestionItems = /* @__PURE__ */ __name((items, query) => {
|
|
15
|
+
const normalizedQuery = query.trim().toLowerCase();
|
|
16
|
+
return items.filter((item) => {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
if (!normalizedQuery) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
const id = item.id.toLowerCase();
|
|
22
|
+
const name = ((_a = item.name) != null ? _a : "").toLowerCase();
|
|
23
|
+
const category = ((_b = item.category) != null ? _b : "").toLowerCase();
|
|
24
|
+
return id.includes(normalizedQuery) || name.includes(normalizedQuery) || category.includes(normalizedQuery);
|
|
25
|
+
}).slice(0, MAX_SUGGESTION_ITEMS);
|
|
26
|
+
}, "getFilteredSuggestionItems");
|
|
27
|
+
var createVariableSuggestion = /* @__PURE__ */ __name((getSuggestionItems = () => []) => {
|
|
28
|
+
return {
|
|
29
|
+
char: "{",
|
|
30
|
+
pluginKey: VariablePluginKey,
|
|
31
|
+
command: ({
|
|
32
|
+
editor,
|
|
33
|
+
range,
|
|
34
|
+
props
|
|
35
|
+
}) => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const nodeAfter = editor.view.state.selection.$to.nodeAfter;
|
|
38
|
+
const overrideSpace = (_a = nodeAfter == null ? void 0 : nodeAfter.text) == null ? void 0 : _a.startsWith(" ");
|
|
39
|
+
if (overrideSpace) {
|
|
40
|
+
range.to += 1;
|
|
41
|
+
}
|
|
42
|
+
editor.chain().focus().insertContentAt(range, [{
|
|
43
|
+
type: "variable",
|
|
44
|
+
attrs: props
|
|
45
|
+
}, {
|
|
46
|
+
type: "text",
|
|
47
|
+
text: " "
|
|
48
|
+
}]).run();
|
|
49
|
+
(_b = window.getSelection()) == null ? void 0 : _b.collapseToEnd();
|
|
50
|
+
},
|
|
51
|
+
allow: ({
|
|
52
|
+
state,
|
|
53
|
+
range
|
|
54
|
+
}) => {
|
|
55
|
+
const $from = state.doc.resolve(range.from);
|
|
56
|
+
const type = state.schema.nodes["variable"];
|
|
57
|
+
const allow = !!$from.parent.type.contentMatch.matchType(type);
|
|
58
|
+
return allow;
|
|
59
|
+
},
|
|
60
|
+
items: ({
|
|
61
|
+
query
|
|
62
|
+
}) => {
|
|
63
|
+
return getFilteredSuggestionItems(getSuggestionItems(), query);
|
|
64
|
+
},
|
|
65
|
+
render: () => {
|
|
66
|
+
let component = null;
|
|
67
|
+
let popperInstance = null;
|
|
68
|
+
let popoverWrapper = null;
|
|
69
|
+
let clientRectProvider;
|
|
70
|
+
let editorElement = null;
|
|
71
|
+
let removeOutsideListeners = null;
|
|
72
|
+
const destroyVariablePopover = /* @__PURE__ */ __name(() => {
|
|
73
|
+
removeOutsideListeners == null ? void 0 : removeOutsideListeners();
|
|
74
|
+
removeOutsideListeners = null;
|
|
75
|
+
popperInstance == null ? void 0 : popperInstance.destroy();
|
|
76
|
+
popperInstance = null;
|
|
77
|
+
popoverWrapper == null ? void 0 : popoverWrapper.remove();
|
|
78
|
+
popoverWrapper = null;
|
|
79
|
+
component == null ? void 0 : component.destroy();
|
|
80
|
+
component = null;
|
|
81
|
+
}, "destroyVariablePopover");
|
|
82
|
+
const isWithinVariableContext = /* @__PURE__ */ __name((target) => {
|
|
83
|
+
if (!(target instanceof Node)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return Boolean((editorElement == null ? void 0 : editorElement.contains(target)) || (popoverWrapper == null ? void 0 : popoverWrapper.contains(target)));
|
|
87
|
+
}, "isWithinVariableContext");
|
|
88
|
+
const setupOutsideListeners = /* @__PURE__ */ __name(() => {
|
|
89
|
+
if (!editorElement || removeOutsideListeners) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const handleDocumentFocusIn = /* @__PURE__ */ __name((event) => {
|
|
93
|
+
if (!isWithinVariableContext(event.target)) {
|
|
94
|
+
destroyVariablePopover();
|
|
95
|
+
}
|
|
96
|
+
}, "handleDocumentFocusIn");
|
|
97
|
+
const handleDocumentPointerDown = /* @__PURE__ */ __name((event) => {
|
|
98
|
+
if (!isWithinVariableContext(event.target)) {
|
|
99
|
+
destroyVariablePopover();
|
|
100
|
+
}
|
|
101
|
+
}, "handleDocumentPointerDown");
|
|
102
|
+
const handleEditorFocusOut = /* @__PURE__ */ __name((event) => {
|
|
103
|
+
if (!isWithinVariableContext(event.relatedTarget)) {
|
|
104
|
+
destroyVariablePopover();
|
|
105
|
+
}
|
|
106
|
+
}, "handleEditorFocusOut");
|
|
107
|
+
document.addEventListener("focusin", handleDocumentFocusIn);
|
|
108
|
+
document.addEventListener("mousedown", handleDocumentPointerDown, true);
|
|
109
|
+
document.addEventListener("touchstart", handleDocumentPointerDown, true);
|
|
110
|
+
editorElement.addEventListener("focusout", handleEditorFocusOut);
|
|
111
|
+
removeOutsideListeners = /* @__PURE__ */ __name(() => {
|
|
112
|
+
document.removeEventListener("focusin", handleDocumentFocusIn);
|
|
113
|
+
document.removeEventListener("mousedown", handleDocumentPointerDown, true);
|
|
114
|
+
document.removeEventListener("touchstart", handleDocumentPointerDown, true);
|
|
115
|
+
editorElement == null ? void 0 : editorElement.removeEventListener("focusout", handleEditorFocusOut);
|
|
116
|
+
}, "removeOutsideListeners");
|
|
117
|
+
}, "setupOutsideListeners");
|
|
118
|
+
const getVirtualElement = /* @__PURE__ */ __name(() => {
|
|
119
|
+
if (!clientRectProvider) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
getBoundingClientRect: () => {
|
|
124
|
+
var _a;
|
|
125
|
+
return (_a = clientRectProvider == null ? void 0 : clientRectProvider()) != null ? _a : new DOMRect();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}, "getVirtualElement");
|
|
129
|
+
const updatePopoverPosition = /* @__PURE__ */ __name(() => {
|
|
130
|
+
const virtualElement = getVirtualElement();
|
|
131
|
+
if (!virtualElement || !popoverWrapper) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!popperInstance) {
|
|
135
|
+
popperInstance = createPopper(virtualElement, popoverWrapper, {
|
|
136
|
+
placement: "bottom-start",
|
|
137
|
+
modifiers: [{
|
|
138
|
+
name: "offset",
|
|
139
|
+
options: {
|
|
140
|
+
offset: [0, 8]
|
|
141
|
+
}
|
|
142
|
+
}, {
|
|
143
|
+
name: "flip",
|
|
144
|
+
options: {
|
|
145
|
+
fallbackPlacements: ["top-start"]
|
|
146
|
+
}
|
|
147
|
+
}]
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
popperInstance.update();
|
|
152
|
+
}, "updatePopoverPosition");
|
|
153
|
+
return {
|
|
154
|
+
onStart: (props) => {
|
|
155
|
+
clientRectProvider = props.clientRect;
|
|
156
|
+
editorElement = props.editor.view.dom;
|
|
157
|
+
component = new VueRenderer(VariableList, {
|
|
158
|
+
editor: props.editor,
|
|
159
|
+
props: {
|
|
160
|
+
items: props.items,
|
|
161
|
+
command: props.command
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
popoverWrapper = document.createElement("div");
|
|
165
|
+
popoverWrapper.style.position = "absolute";
|
|
166
|
+
popoverWrapper.style.zIndex = "var(--mp-z-index-popover)";
|
|
167
|
+
if (component.element) {
|
|
168
|
+
popoverWrapper.append(component.element);
|
|
169
|
+
}
|
|
170
|
+
document.body.append(popoverWrapper);
|
|
171
|
+
setupOutsideListeners();
|
|
172
|
+
updatePopoverPosition();
|
|
173
|
+
},
|
|
174
|
+
onUpdate: (props) => {
|
|
175
|
+
clientRectProvider = props.clientRect;
|
|
176
|
+
component == null ? void 0 : component.updateProps({
|
|
177
|
+
items: props.items,
|
|
178
|
+
command: props.command
|
|
179
|
+
});
|
|
180
|
+
updatePopoverPosition();
|
|
181
|
+
},
|
|
182
|
+
onKeyDown: (props) => {
|
|
183
|
+
var _a, _b;
|
|
184
|
+
if (props.event.key === "Escape") {
|
|
185
|
+
destroyVariablePopover();
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
return (_b = (_a = component == null ? void 0 : component.ref) == null ? void 0 : _a.onKeyDown(props)) != null ? _b : false;
|
|
189
|
+
},
|
|
190
|
+
onExit: () => {
|
|
191
|
+
destroyVariablePopover();
|
|
192
|
+
editorElement = null;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}, "createVariableSuggestion");
|
|
198
|
+
|
|
199
|
+
export {
|
|
200
|
+
VariablePluginKey,
|
|
201
|
+
createVariableSuggestion
|
|
202
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// src/extensions/variable-extension.ts
|
|
2
|
+
import { Node, mergeAttributes } from "@tiptap/core";
|
|
3
|
+
import Suggestion from "@tiptap/suggestion";
|
|
4
|
+
var Variable = Node.create({
|
|
5
|
+
name: "variable",
|
|
6
|
+
addOptions() {
|
|
7
|
+
return {
|
|
8
|
+
HTMLAttributes: {},
|
|
9
|
+
renderLabel({
|
|
10
|
+
node
|
|
11
|
+
}) {
|
|
12
|
+
var _a;
|
|
13
|
+
return `{${(_a = node.attrs.label) != null ? _a : node.attrs.id}}`;
|
|
14
|
+
},
|
|
15
|
+
suggestion: {}
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
group: "inline",
|
|
19
|
+
inline: true,
|
|
20
|
+
selectable: false,
|
|
21
|
+
atom: true,
|
|
22
|
+
addAttributes() {
|
|
23
|
+
return {
|
|
24
|
+
id: {
|
|
25
|
+
default: null,
|
|
26
|
+
parseHTML: (element) => element.getAttribute("data-id"),
|
|
27
|
+
renderHTML: (attributes) => {
|
|
28
|
+
if (!attributes.id) {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
"data-id": attributes.id
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
label: {
|
|
37
|
+
default: null,
|
|
38
|
+
parseHTML: (element) => element.getAttribute("data-label"),
|
|
39
|
+
renderHTML: (attributes) => {
|
|
40
|
+
if (!attributes.label) {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
"data-label": attributes.label
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
category: {
|
|
49
|
+
default: null,
|
|
50
|
+
parseHTML: (element) => element.getAttribute("data-category"),
|
|
51
|
+
renderHTML: (attributes) => {
|
|
52
|
+
if (!attributes.category) {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
"data-category": attributes.category
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
parseHTML() {
|
|
63
|
+
return [{
|
|
64
|
+
tag: `span[data-type="${this.name}"]`
|
|
65
|
+
}];
|
|
66
|
+
},
|
|
67
|
+
renderHTML({
|
|
68
|
+
node,
|
|
69
|
+
HTMLAttributes
|
|
70
|
+
}) {
|
|
71
|
+
return ["span", mergeAttributes({
|
|
72
|
+
"data-type": this.name
|
|
73
|
+
}, this.options.HTMLAttributes, HTMLAttributes), this.options.renderLabel({
|
|
74
|
+
options: this.options,
|
|
75
|
+
node
|
|
76
|
+
})];
|
|
77
|
+
},
|
|
78
|
+
renderText({
|
|
79
|
+
node
|
|
80
|
+
}) {
|
|
81
|
+
return this.options.renderLabel({
|
|
82
|
+
options: this.options,
|
|
83
|
+
node
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
addKeyboardShortcuts() {
|
|
87
|
+
return {
|
|
88
|
+
Backspace: () => this.editor.commands.command(({
|
|
89
|
+
tr,
|
|
90
|
+
state
|
|
91
|
+
}) => {
|
|
92
|
+
let isVariable = false;
|
|
93
|
+
const {
|
|
94
|
+
selection
|
|
95
|
+
} = state;
|
|
96
|
+
const {
|
|
97
|
+
empty,
|
|
98
|
+
anchor
|
|
99
|
+
} = selection;
|
|
100
|
+
if (!empty) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
|
|
104
|
+
if (node.type.name === this.name) {
|
|
105
|
+
isVariable = true;
|
|
106
|
+
tr.insertText(this.options.suggestion.char || "", pos, pos + node.nodeSize);
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return isVariable;
|
|
111
|
+
})
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
addProseMirrorPlugins() {
|
|
115
|
+
return [Suggestion({
|
|
116
|
+
editor: this.editor,
|
|
117
|
+
...this.options.suggestion
|
|
118
|
+
})];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
export {
|
|
123
|
+
Variable
|
|
124
|
+
};
|
|
@@ -407,6 +407,33 @@ var LocationIcon = defineComponent({
|
|
|
407
407
|
}, null)]);
|
|
408
408
|
}
|
|
409
409
|
});
|
|
410
|
+
var VariableIcon = defineComponent({
|
|
411
|
+
name: "VariableIcon",
|
|
412
|
+
setup() {
|
|
413
|
+
return () => _createVNode("svg", {
|
|
414
|
+
"class": "mp-icon mp-icon--size_sm",
|
|
415
|
+
"data-pixel-component": "MpIcon",
|
|
416
|
+
"data-icon-name": "text-editor-inline-code",
|
|
417
|
+
"viewBox": "0 0 24 24",
|
|
418
|
+
"role": "presentation",
|
|
419
|
+
"fill": "none",
|
|
420
|
+
"focusable": "false",
|
|
421
|
+
"style": "--mp-icon-color: var(--mp-colors-icon-default);"
|
|
422
|
+
}, [_createVNode("path", {
|
|
423
|
+
"d": "M15 6L21 12L15 18",
|
|
424
|
+
"stroke": "currentcolor",
|
|
425
|
+
"stroke-width": "1.5",
|
|
426
|
+
"stroke-linecap": "round",
|
|
427
|
+
"stroke-linejoin": "round"
|
|
428
|
+
}, null), _createVNode("path", {
|
|
429
|
+
"d": "M9 6L3 12L9 18",
|
|
430
|
+
"stroke": "currentcolor",
|
|
431
|
+
"stroke-width": "1.5",
|
|
432
|
+
"stroke-linecap": "round",
|
|
433
|
+
"stroke-linejoin": "round"
|
|
434
|
+
}, null)]);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
410
437
|
|
|
411
438
|
export {
|
|
412
439
|
BoldIcon,
|
|
@@ -431,5 +458,6 @@ export {
|
|
|
431
458
|
FileIcon,
|
|
432
459
|
AudioIcon,
|
|
433
460
|
MentionIcon,
|
|
434
|
-
LocationIcon
|
|
461
|
+
LocationIcon,
|
|
462
|
+
VariableIcon
|
|
435
463
|
};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HeadingExtention
|
|
3
|
+
} from "./chunk-X2CB42A3.mjs";
|
|
1
4
|
import {
|
|
2
5
|
LinkExtension
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-COZ45QUD.mjs";
|
|
4
7
|
import {
|
|
5
8
|
SingleExtention
|
|
6
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-47IOAHWN.mjs";
|
|
7
10
|
import {
|
|
8
11
|
AlignExtention
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-YWVVMJGP.mjs";
|
|
10
13
|
import {
|
|
11
14
|
ColorExtension
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import {
|
|
14
|
-
HeadingExtention
|
|
15
|
-
} from "./chunk-YIEQVTEO.mjs";
|
|
15
|
+
} from "./chunk-Y6UPQ6EU.mjs";
|
|
16
16
|
import {
|
|
17
17
|
__name
|
|
18
18
|
} from "./chunk-QZ7VFGWC.mjs";
|
|
@@ -25,7 +25,7 @@ import { MpDivider } from "@mekari/pixel3-divider";
|
|
|
25
25
|
import { MpScrollbar } from "@mekari/pixel3-scrollbar";
|
|
26
26
|
var EditorToolbar = defineComponent({
|
|
27
27
|
name: "EditorToolbar",
|
|
28
|
-
emits: ["clickImage", "clickFile", "clickAudio", "clickMention", "clickLocation"],
|
|
28
|
+
emits: ["clickImage", "clickFile", "clickAudio", "clickMention", "clickVariable", "clickLocation"],
|
|
29
29
|
props: {
|
|
30
30
|
editor: {
|
|
31
31
|
type: Object
|
|
@@ -48,7 +48,7 @@ var EditorToolbar = defineComponent({
|
|
|
48
48
|
}, {
|
|
49
49
|
emit
|
|
50
50
|
}) {
|
|
51
|
-
const items = ["heading", "bold", "italic", "underline", "strike", "blockquote", "bulletList", "orderedList", "textColor", "fillColor", "textLink", "align", "undo", "redo", "clear", "image", "file", "audio", "mention", "location"];
|
|
51
|
+
const items = ["heading", "bold", "italic", "underline", "strike", "blockquote", "bulletList", "orderedList", "textColor", "fillColor", "textLink", "align", "undo", "redo", "clear", "image", "file", "audio", "mention", "variable", "location"];
|
|
52
52
|
const itemOptions = {
|
|
53
53
|
heading: {
|
|
54
54
|
tooltipLabel: "Text style",
|
|
@@ -133,6 +133,15 @@ var EditorToolbar = defineComponent({
|
|
|
133
133
|
emit("clickMention");
|
|
134
134
|
}
|
|
135
135
|
},
|
|
136
|
+
variable: {
|
|
137
|
+
tooltipLabel: "Insert variable",
|
|
138
|
+
editor,
|
|
139
|
+
onClick: () => {
|
|
140
|
+
;
|
|
141
|
+
(editor == null ? void 0 : editor.chain()).focus().insertContent("{").run();
|
|
142
|
+
emit("clickVariable");
|
|
143
|
+
}
|
|
144
|
+
},
|
|
136
145
|
location: {
|
|
137
146
|
tooltipLabel: "Add location",
|
|
138
147
|
onClick: () => emit("clickLocation")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CaretIcon
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IFRJVX2K.mjs";
|
|
4
4
|
|
|
5
5
|
// src/extensions/heading-extension.tsx
|
|
6
6
|
import { withDirectives as _withDirectives, resolveDirective as _resolveDirective, createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
|