@mekari/pixel3-rich-text-editor 0.1.2-dev.0 → 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
package/dist/index.js
CHANGED
|
@@ -37,8 +37,8 @@ __export(src_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(src_exports);
|
|
38
38
|
|
|
39
39
|
// src/rich-text-editor.tsx
|
|
40
|
-
var
|
|
41
|
-
var
|
|
40
|
+
var import_vue22 = require("vue");
|
|
41
|
+
var import_vue23 = require("vue");
|
|
42
42
|
var import_pixel3_utils4 = require("@mekari/pixel3-utils");
|
|
43
43
|
|
|
44
44
|
// src/modules/rich-text-editor.props.ts
|
|
@@ -75,6 +75,10 @@ var richTextEditorProps = {
|
|
|
75
75
|
type: Array,
|
|
76
76
|
default: () => []
|
|
77
77
|
},
|
|
78
|
+
variables: {
|
|
79
|
+
type: Array,
|
|
80
|
+
default: () => []
|
|
81
|
+
},
|
|
78
82
|
validateLink: {
|
|
79
83
|
type: Function
|
|
80
84
|
},
|
|
@@ -166,7 +170,7 @@ var useRTEStyleProvider = /* @__PURE__ */ __name((props) => {
|
|
|
166
170
|
}, "useRTEStyleProvider");
|
|
167
171
|
|
|
168
172
|
// src/rich-text-editor.tsx
|
|
169
|
-
var
|
|
173
|
+
var import_vue_33 = require("@tiptap/vue-3");
|
|
170
174
|
var import_starter_kit = __toESM(require("@tiptap/starter-kit"));
|
|
171
175
|
var import_extension_underline = __toESM(require("@tiptap/extension-underline"));
|
|
172
176
|
var import_extension_text_align = __toESM(require("@tiptap/extension-text-align"));
|
|
@@ -181,9 +185,9 @@ var import_tokens = require("@mekari/pixel3-styled-system/tokens");
|
|
|
181
185
|
var import_pixel3_form_control = require("@mekari/pixel3-form-control");
|
|
182
186
|
|
|
183
187
|
// src/editor-toolbar.tsx
|
|
184
|
-
var
|
|
185
|
-
var
|
|
186
|
-
var
|
|
188
|
+
var import_vue16 = require("vue");
|
|
189
|
+
var import_vue17 = require("vue");
|
|
190
|
+
var import_css6 = require("@mekari/pixel3-styled-system/css");
|
|
187
191
|
var import_pixel3_divider = require("@mekari/pixel3-divider");
|
|
188
192
|
var import_pixel3_scrollbar = require("@mekari/pixel3-scrollbar");
|
|
189
193
|
|
|
@@ -603,6 +607,33 @@ var LocationIcon = (0, import_vue3.defineComponent)({
|
|
|
603
607
|
}, null)]);
|
|
604
608
|
}
|
|
605
609
|
});
|
|
610
|
+
var VariableIcon = (0, import_vue3.defineComponent)({
|
|
611
|
+
name: "VariableIcon",
|
|
612
|
+
setup() {
|
|
613
|
+
return () => (0, import_vue2.createVNode)("svg", {
|
|
614
|
+
"class": "mp-icon mp-icon--size_sm",
|
|
615
|
+
"data-pixel-component": "MpIcon",
|
|
616
|
+
"data-icon-name": "text-editor-inline-code",
|
|
617
|
+
"viewBox": "0 0 24 24",
|
|
618
|
+
"role": "presentation",
|
|
619
|
+
"fill": "none",
|
|
620
|
+
"focusable": "false",
|
|
621
|
+
"style": "--mp-icon-color: var(--mp-colors-icon-default);"
|
|
622
|
+
}, [(0, import_vue2.createVNode)("path", {
|
|
623
|
+
"d": "M15 6L21 12L15 18",
|
|
624
|
+
"stroke": "currentcolor",
|
|
625
|
+
"stroke-width": "1.5",
|
|
626
|
+
"stroke-linecap": "round",
|
|
627
|
+
"stroke-linejoin": "round"
|
|
628
|
+
}, null), (0, import_vue2.createVNode)("path", {
|
|
629
|
+
"d": "M9 6L3 12L9 18",
|
|
630
|
+
"stroke": "currentcolor",
|
|
631
|
+
"stroke-width": "1.5",
|
|
632
|
+
"stroke-linecap": "round",
|
|
633
|
+
"stroke-linejoin": "round"
|
|
634
|
+
}, null)]);
|
|
635
|
+
}
|
|
636
|
+
});
|
|
606
637
|
|
|
607
638
|
// src/extensions/heading-extension.tsx
|
|
608
639
|
var HeadingExtention = (0, import_vue5.defineComponent)({
|
|
@@ -867,6 +898,7 @@ var SingleExtention = (0, import_vue9.defineComponent)({
|
|
|
867
898
|
file: (0, import_vue8.createVNode)(FileIcon, null, null),
|
|
868
899
|
audio: (0, import_vue8.createVNode)(AudioIcon, null, null),
|
|
869
900
|
mention: (0, import_vue8.createVNode)(MentionIcon, null, null),
|
|
901
|
+
variable: (0, import_vue8.createVNode)(VariableIcon, null, null),
|
|
870
902
|
location: (0, import_vue8.createVNode)(LocationIcon, null, null)
|
|
871
903
|
};
|
|
872
904
|
return () => (0, import_vue8.withDirectives)((0, import_vue8.createVNode)("button", {
|
|
@@ -1193,10 +1225,313 @@ var LinkExtension = (0, import_vue13.defineComponent)({
|
|
|
1193
1225
|
}
|
|
1194
1226
|
});
|
|
1195
1227
|
|
|
1228
|
+
// src/extensions/variable-extension.ts
|
|
1229
|
+
var import_core2 = require("@tiptap/core");
|
|
1230
|
+
var import_suggestion = __toESM(require("@tiptap/suggestion"));
|
|
1231
|
+
var Variable = import_core2.Node.create({
|
|
1232
|
+
name: "variable",
|
|
1233
|
+
addOptions() {
|
|
1234
|
+
return {
|
|
1235
|
+
HTMLAttributes: {},
|
|
1236
|
+
renderLabel({
|
|
1237
|
+
node
|
|
1238
|
+
}) {
|
|
1239
|
+
var _a;
|
|
1240
|
+
return `{${(_a = node.attrs.label) != null ? _a : node.attrs.id}}`;
|
|
1241
|
+
},
|
|
1242
|
+
suggestion: {}
|
|
1243
|
+
};
|
|
1244
|
+
},
|
|
1245
|
+
group: "inline",
|
|
1246
|
+
inline: true,
|
|
1247
|
+
selectable: false,
|
|
1248
|
+
atom: true,
|
|
1249
|
+
addAttributes() {
|
|
1250
|
+
return {
|
|
1251
|
+
id: {
|
|
1252
|
+
default: null,
|
|
1253
|
+
parseHTML: (element) => element.getAttribute("data-id"),
|
|
1254
|
+
renderHTML: (attributes) => {
|
|
1255
|
+
if (!attributes.id) {
|
|
1256
|
+
return {};
|
|
1257
|
+
}
|
|
1258
|
+
return {
|
|
1259
|
+
"data-id": attributes.id
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
},
|
|
1263
|
+
label: {
|
|
1264
|
+
default: null,
|
|
1265
|
+
parseHTML: (element) => element.getAttribute("data-label"),
|
|
1266
|
+
renderHTML: (attributes) => {
|
|
1267
|
+
if (!attributes.label) {
|
|
1268
|
+
return {};
|
|
1269
|
+
}
|
|
1270
|
+
return {
|
|
1271
|
+
"data-label": attributes.label
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
},
|
|
1275
|
+
category: {
|
|
1276
|
+
default: null,
|
|
1277
|
+
parseHTML: (element) => element.getAttribute("data-category"),
|
|
1278
|
+
renderHTML: (attributes) => {
|
|
1279
|
+
if (!attributes.category) {
|
|
1280
|
+
return {};
|
|
1281
|
+
}
|
|
1282
|
+
return {
|
|
1283
|
+
"data-category": attributes.category
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
},
|
|
1289
|
+
parseHTML() {
|
|
1290
|
+
return [{
|
|
1291
|
+
tag: `span[data-type="${this.name}"]`
|
|
1292
|
+
}];
|
|
1293
|
+
},
|
|
1294
|
+
renderHTML({
|
|
1295
|
+
node,
|
|
1296
|
+
HTMLAttributes
|
|
1297
|
+
}) {
|
|
1298
|
+
return ["span", (0, import_core2.mergeAttributes)({
|
|
1299
|
+
"data-type": this.name
|
|
1300
|
+
}, this.options.HTMLAttributes, HTMLAttributes), this.options.renderLabel({
|
|
1301
|
+
options: this.options,
|
|
1302
|
+
node
|
|
1303
|
+
})];
|
|
1304
|
+
},
|
|
1305
|
+
renderText({
|
|
1306
|
+
node
|
|
1307
|
+
}) {
|
|
1308
|
+
return this.options.renderLabel({
|
|
1309
|
+
options: this.options,
|
|
1310
|
+
node
|
|
1311
|
+
});
|
|
1312
|
+
},
|
|
1313
|
+
addKeyboardShortcuts() {
|
|
1314
|
+
return {
|
|
1315
|
+
Backspace: () => this.editor.commands.command(({
|
|
1316
|
+
tr,
|
|
1317
|
+
state
|
|
1318
|
+
}) => {
|
|
1319
|
+
let isVariable = false;
|
|
1320
|
+
const {
|
|
1321
|
+
selection
|
|
1322
|
+
} = state;
|
|
1323
|
+
const {
|
|
1324
|
+
empty,
|
|
1325
|
+
anchor
|
|
1326
|
+
} = selection;
|
|
1327
|
+
if (!empty) {
|
|
1328
|
+
return false;
|
|
1329
|
+
}
|
|
1330
|
+
state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
|
|
1331
|
+
if (node.type.name === this.name) {
|
|
1332
|
+
isVariable = true;
|
|
1333
|
+
tr.insertText(this.options.suggestion.char || "", pos, pos + node.nodeSize);
|
|
1334
|
+
return false;
|
|
1335
|
+
}
|
|
1336
|
+
});
|
|
1337
|
+
return isVariable;
|
|
1338
|
+
})
|
|
1339
|
+
};
|
|
1340
|
+
},
|
|
1341
|
+
addProseMirrorPlugins() {
|
|
1342
|
+
return [(0, import_suggestion.default)({
|
|
1343
|
+
editor: this.editor,
|
|
1344
|
+
...this.options.suggestion
|
|
1345
|
+
})];
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
|
|
1349
|
+
// src/extensions/variable-list-extension.tsx
|
|
1350
|
+
var import_vue14 = require("vue");
|
|
1351
|
+
var import_vue15 = require("vue");
|
|
1352
|
+
var import_css5 = require("@mekari/pixel3-styled-system/css");
|
|
1353
|
+
var import_pixel3_popover3 = require("@mekari/pixel3-popover");
|
|
1354
|
+
var import_pixel3_text2 = require("@mekari/pixel3-text");
|
|
1355
|
+
var VariableList = (0, import_vue15.defineComponent)({
|
|
1356
|
+
name: "VariableList",
|
|
1357
|
+
props: {
|
|
1358
|
+
items: {
|
|
1359
|
+
type: Array,
|
|
1360
|
+
default: () => []
|
|
1361
|
+
},
|
|
1362
|
+
command: {
|
|
1363
|
+
type: Function,
|
|
1364
|
+
required: true
|
|
1365
|
+
}
|
|
1366
|
+
},
|
|
1367
|
+
setup(props, {
|
|
1368
|
+
expose
|
|
1369
|
+
}) {
|
|
1370
|
+
const selectedIndex = (0, import_vue15.ref)(0);
|
|
1371
|
+
const listRef = (0, import_vue15.ref)(null);
|
|
1372
|
+
const groupedItems = (0, import_vue15.computed)(() => {
|
|
1373
|
+
const groups = {};
|
|
1374
|
+
props.items.forEach((item) => {
|
|
1375
|
+
const category = item.category || "OTHER";
|
|
1376
|
+
if (!groups[category]) {
|
|
1377
|
+
groups[category] = [];
|
|
1378
|
+
}
|
|
1379
|
+
groups[category].push(item);
|
|
1380
|
+
});
|
|
1381
|
+
return Object.entries(groups).map(([category, items]) => ({
|
|
1382
|
+
category,
|
|
1383
|
+
items
|
|
1384
|
+
}));
|
|
1385
|
+
});
|
|
1386
|
+
const scrollToFocusedItem = /* @__PURE__ */ __name(() => {
|
|
1387
|
+
(0, import_vue15.nextTick)(() => {
|
|
1388
|
+
if (!listRef.value)
|
|
1389
|
+
return;
|
|
1390
|
+
const targetItem = listRef.value.querySelector('[data-active="true"], [data-highlight]');
|
|
1391
|
+
if (targetItem) {
|
|
1392
|
+
targetItem.scrollIntoView({
|
|
1393
|
+
block: "nearest"
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
}, "scrollToFocusedItem");
|
|
1398
|
+
(0, import_vue15.watch)(() => props.items, () => {
|
|
1399
|
+
selectedIndex.value = 0;
|
|
1400
|
+
});
|
|
1401
|
+
const onSelect = /* @__PURE__ */ __name((index) => {
|
|
1402
|
+
const item = props.items[index];
|
|
1403
|
+
if (item) {
|
|
1404
|
+
props.command({
|
|
1405
|
+
...item,
|
|
1406
|
+
label: item.id
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
}, "onSelect");
|
|
1410
|
+
const onKeyDown = /* @__PURE__ */ __name(({
|
|
1411
|
+
event
|
|
1412
|
+
}) => {
|
|
1413
|
+
if (!props.items.length) {
|
|
1414
|
+
return false;
|
|
1415
|
+
}
|
|
1416
|
+
if (event.key === "ArrowUp") {
|
|
1417
|
+
event.preventDefault();
|
|
1418
|
+
const total = props.items.length;
|
|
1419
|
+
selectedIndex.value = (selectedIndex.value + total - 1) % total;
|
|
1420
|
+
scrollToFocusedItem();
|
|
1421
|
+
return true;
|
|
1422
|
+
}
|
|
1423
|
+
if (event.key === "ArrowDown") {
|
|
1424
|
+
event.preventDefault();
|
|
1425
|
+
selectedIndex.value = (selectedIndex.value + 1) % props.items.length;
|
|
1426
|
+
scrollToFocusedItem();
|
|
1427
|
+
return true;
|
|
1428
|
+
}
|
|
1429
|
+
if (event.key === "Enter") {
|
|
1430
|
+
event.preventDefault();
|
|
1431
|
+
onSelect(selectedIndex.value);
|
|
1432
|
+
return true;
|
|
1433
|
+
}
|
|
1434
|
+
return false;
|
|
1435
|
+
}, "onKeyDown");
|
|
1436
|
+
expose({
|
|
1437
|
+
onKeyDown
|
|
1438
|
+
});
|
|
1439
|
+
return () => (0, import_vue14.createVNode)(import_pixel3_popover3.MpPopover, {
|
|
1440
|
+
"id": "popover-rte-variable-list",
|
|
1441
|
+
"is-manual": true,
|
|
1442
|
+
"is-default-open": true,
|
|
1443
|
+
"is-open": true
|
|
1444
|
+
}, {
|
|
1445
|
+
default: () => [(0, import_vue14.createVNode)(import_pixel3_popover3.MpPopoverContent, {
|
|
1446
|
+
"class": (0, import_css5.css)({
|
|
1447
|
+
width: "280px",
|
|
1448
|
+
maxHeight: "284px",
|
|
1449
|
+
overflowY: "auto"
|
|
1450
|
+
})
|
|
1451
|
+
}, {
|
|
1452
|
+
default: () => [(0, import_vue14.createVNode)(import_pixel3_popover3.MpPopoverList, {
|
|
1453
|
+
"ref": (element) => {
|
|
1454
|
+
var _a;
|
|
1455
|
+
if (!element) {
|
|
1456
|
+
listRef.value = null;
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
listRef.value = (_a = element.$el) != null ? _a : element;
|
|
1460
|
+
},
|
|
1461
|
+
"data-pixel-rte": true
|
|
1462
|
+
}, {
|
|
1463
|
+
default: () => [!props.items.length && (0, import_vue14.createVNode)(import_pixel3_text2.MpText, {
|
|
1464
|
+
"color": "text.secondary",
|
|
1465
|
+
"class": (0, import_css5.css)({
|
|
1466
|
+
px: "3",
|
|
1467
|
+
py: "2"
|
|
1468
|
+
})
|
|
1469
|
+
}, {
|
|
1470
|
+
default: () => [(0, import_vue14.createTextVNode)("No result")]
|
|
1471
|
+
}), groupedItems.value.map((group) => {
|
|
1472
|
+
return (0, import_vue14.createVNode)(import_vue14.Fragment, null, [(0, import_vue14.createVNode)(import_pixel3_text2.MpText, {
|
|
1473
|
+
"size": "label-small",
|
|
1474
|
+
"color": "text.secondary",
|
|
1475
|
+
"class": (0, import_css5.css)({
|
|
1476
|
+
px: "3",
|
|
1477
|
+
py: "2",
|
|
1478
|
+
textTransform: "uppercase",
|
|
1479
|
+
textAlign: "left",
|
|
1480
|
+
letterSpacing: "0.05em",
|
|
1481
|
+
display: "block",
|
|
1482
|
+
width: "full"
|
|
1483
|
+
})
|
|
1484
|
+
}, {
|
|
1485
|
+
default: () => [group.category]
|
|
1486
|
+
}), group.items.map((item) => {
|
|
1487
|
+
const itemIndex = props.items.indexOf(item);
|
|
1488
|
+
return (0, import_vue14.createVNode)(import_pixel3_popover3.MpPopoverListItem, {
|
|
1489
|
+
"key": `${item.id}-${itemIndex}`,
|
|
1490
|
+
"onMousedown": (event) => event.preventDefault(),
|
|
1491
|
+
"onMouseenter": () => {
|
|
1492
|
+
selectedIndex.value = itemIndex;
|
|
1493
|
+
},
|
|
1494
|
+
"onClick": () => {
|
|
1495
|
+
onSelect(itemIndex);
|
|
1496
|
+
}
|
|
1497
|
+
}, {
|
|
1498
|
+
default: () => [(0, import_vue14.createVNode)("div", {
|
|
1499
|
+
"class": (0, import_css5.css)({
|
|
1500
|
+
display: "flex",
|
|
1501
|
+
flexDirection: "column",
|
|
1502
|
+
alignItems: "flex-start",
|
|
1503
|
+
minWidth: "0",
|
|
1504
|
+
width: "full",
|
|
1505
|
+
gap: "0.5"
|
|
1506
|
+
})
|
|
1507
|
+
}, [(0, import_vue14.createVNode)(import_pixel3_text2.MpText, {
|
|
1508
|
+
"size": "label",
|
|
1509
|
+
"is-truncated": true
|
|
1510
|
+
}, {
|
|
1511
|
+
default: () => [item.name || "Unknown"]
|
|
1512
|
+
}), (0, import_vue14.createVNode)(import_pixel3_text2.MpText, {
|
|
1513
|
+
"size": "label-small",
|
|
1514
|
+
"color": "text.secondary",
|
|
1515
|
+
"is-truncated": true,
|
|
1516
|
+
"class": (0, import_css5.css)({
|
|
1517
|
+
fontFamily: "mono"
|
|
1518
|
+
})
|
|
1519
|
+
}, {
|
|
1520
|
+
default: () => [`{${item.id}}`]
|
|
1521
|
+
})])]
|
|
1522
|
+
});
|
|
1523
|
+
})]);
|
|
1524
|
+
})]
|
|
1525
|
+
})]
|
|
1526
|
+
})]
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
});
|
|
1530
|
+
|
|
1196
1531
|
// src/editor-toolbar.tsx
|
|
1197
|
-
var EditorToolbar = (0,
|
|
1532
|
+
var EditorToolbar = (0, import_vue17.defineComponent)({
|
|
1198
1533
|
name: "EditorToolbar",
|
|
1199
|
-
emits: ["clickImage", "clickFile", "clickAudio", "clickMention", "clickLocation"],
|
|
1534
|
+
emits: ["clickImage", "clickFile", "clickAudio", "clickMention", "clickVariable", "clickLocation"],
|
|
1200
1535
|
props: {
|
|
1201
1536
|
editor: {
|
|
1202
1537
|
type: Object
|
|
@@ -1219,7 +1554,7 @@ var EditorToolbar = (0, import_vue15.defineComponent)({
|
|
|
1219
1554
|
}, {
|
|
1220
1555
|
emit
|
|
1221
1556
|
}) {
|
|
1222
|
-
const items = ["heading", "bold", "italic", "underline", "strike", "blockquote", "bulletList", "orderedList", "textColor", "fillColor", "textLink", "align", "undo", "redo", "clear", "image", "file", "audio", "mention", "location"];
|
|
1557
|
+
const items = ["heading", "bold", "italic", "underline", "strike", "blockquote", "bulletList", "orderedList", "textColor", "fillColor", "textLink", "align", "undo", "redo", "clear", "image", "file", "audio", "mention", "variable", "location"];
|
|
1223
1558
|
const itemOptions = {
|
|
1224
1559
|
heading: {
|
|
1225
1560
|
tooltipLabel: "Text style",
|
|
@@ -1304,6 +1639,15 @@ var EditorToolbar = (0, import_vue15.defineComponent)({
|
|
|
1304
1639
|
emit("clickMention");
|
|
1305
1640
|
}
|
|
1306
1641
|
},
|
|
1642
|
+
variable: {
|
|
1643
|
+
tooltipLabel: "Insert variable",
|
|
1644
|
+
editor,
|
|
1645
|
+
onClick: () => {
|
|
1646
|
+
;
|
|
1647
|
+
(editor == null ? void 0 : editor.chain()).focus().insertContent("{").run();
|
|
1648
|
+
emit("clickVariable");
|
|
1649
|
+
}
|
|
1650
|
+
},
|
|
1307
1651
|
location: {
|
|
1308
1652
|
tooltipLabel: "Add location",
|
|
1309
1653
|
onClick: () => emit("clickLocation")
|
|
@@ -1334,31 +1678,31 @@ var EditorToolbar = (0, import_vue15.defineComponent)({
|
|
|
1334
1678
|
const tooltipLabel = tooltip || resolvedOptions.tooltipLabel;
|
|
1335
1679
|
switch (resolvedItem) {
|
|
1336
1680
|
case "heading":
|
|
1337
|
-
return (0,
|
|
1681
|
+
return (0, import_vue16.createVNode)(HeadingExtention, {
|
|
1338
1682
|
"tooltipLabel": tooltipLabel,
|
|
1339
1683
|
"editor": editor
|
|
1340
1684
|
}, null);
|
|
1341
1685
|
case "align":
|
|
1342
|
-
return (0,
|
|
1686
|
+
return (0, import_vue16.createVNode)(AlignExtention, {
|
|
1343
1687
|
"tooltipLabel": tooltipLabel,
|
|
1344
1688
|
"editor": editor
|
|
1345
1689
|
}, null);
|
|
1346
1690
|
case "textColor":
|
|
1347
1691
|
case "fillColor":
|
|
1348
|
-
return (0,
|
|
1692
|
+
return (0, import_vue16.createVNode)(ColorExtension, {
|
|
1349
1693
|
"tooltipLabel": tooltipLabel,
|
|
1350
1694
|
"editor": editor,
|
|
1351
1695
|
"type": resolvedOptions.type
|
|
1352
1696
|
}, null);
|
|
1353
1697
|
case "textLink":
|
|
1354
|
-
return (0,
|
|
1698
|
+
return (0, import_vue16.createVNode)(LinkExtension, {
|
|
1355
1699
|
"tooltipLabel": tooltipLabel,
|
|
1356
1700
|
"editor": editor,
|
|
1357
1701
|
"validateLink": validateLink,
|
|
1358
1702
|
"transformLink": transformLink
|
|
1359
1703
|
}, null);
|
|
1360
1704
|
default:
|
|
1361
|
-
return (0,
|
|
1705
|
+
return (0, import_vue16.createVNode)(SingleExtention, {
|
|
1362
1706
|
"name": resolvedItem,
|
|
1363
1707
|
"tooltipLabel": tooltipLabel,
|
|
1364
1708
|
"onClick": resolvedOptions.onClick,
|
|
@@ -1366,7 +1710,7 @@ var EditorToolbar = (0, import_vue15.defineComponent)({
|
|
|
1366
1710
|
}, null);
|
|
1367
1711
|
}
|
|
1368
1712
|
}, "renderExtension");
|
|
1369
|
-
return () => (0,
|
|
1713
|
+
return () => (0, import_vue16.createVNode)(import_pixel3_scrollbar.MpScrollbar, {
|
|
1370
1714
|
"options": {
|
|
1371
1715
|
overflow: {
|
|
1372
1716
|
y: "hide",
|
|
@@ -1374,18 +1718,18 @@ var EditorToolbar = (0, import_vue15.defineComponent)({
|
|
|
1374
1718
|
}
|
|
1375
1719
|
}
|
|
1376
1720
|
}, {
|
|
1377
|
-
default: () => [(0,
|
|
1378
|
-
"class": (0,
|
|
1721
|
+
default: () => [(0, import_vue16.createVNode)("div", {
|
|
1722
|
+
"class": (0, import_css6.css)({
|
|
1379
1723
|
display: "flex",
|
|
1380
1724
|
alignItems: "stretch",
|
|
1381
1725
|
gap: "1"
|
|
1382
1726
|
})
|
|
1383
|
-
}, [options == null ? void 0 : options.map((option, index) => (0,
|
|
1727
|
+
}, [options == null ? void 0 : options.map((option, index) => (0, import_vue16.createVNode)(import_vue16.Fragment, null, [option.map((item) => {
|
|
1384
1728
|
const resolvedItem = typeof item === "string" ? item : item.value;
|
|
1385
1729
|
if (items.includes(resolvedItem)) {
|
|
1386
1730
|
return renderExtension(item);
|
|
1387
1731
|
}
|
|
1388
|
-
}), index !== (options == null ? void 0 : options.length) - 1 && (0,
|
|
1732
|
+
}), index !== (options == null ? void 0 : options.length) - 1 && (0, import_vue16.createVNode)(import_pixel3_divider.MpDivider, {
|
|
1389
1733
|
"id": "divider-toolbar",
|
|
1390
1734
|
"orientation": "vertical"
|
|
1391
1735
|
}, null)]))])]
|
|
@@ -1394,9 +1738,9 @@ var EditorToolbar = (0, import_vue15.defineComponent)({
|
|
|
1394
1738
|
});
|
|
1395
1739
|
|
|
1396
1740
|
// src/rte-style-provider.tsx
|
|
1397
|
-
var
|
|
1398
|
-
var
|
|
1399
|
-
var MpRTEStyleProvider = (0,
|
|
1741
|
+
var import_vue18 = require("vue");
|
|
1742
|
+
var import_vue19 = require("vue");
|
|
1743
|
+
var MpRTEStyleProvider = (0, import_vue19.defineComponent)({
|
|
1400
1744
|
name: "MpRTEStyleProvider",
|
|
1401
1745
|
props: RTEStyleProviderProps,
|
|
1402
1746
|
setup(props, {
|
|
@@ -1405,27 +1749,27 @@ var MpRTEStyleProvider = (0, import_vue17.defineComponent)({
|
|
|
1405
1749
|
const api = useRTEStyleProvider(props);
|
|
1406
1750
|
return () => {
|
|
1407
1751
|
var _a;
|
|
1408
|
-
return (0,
|
|
1752
|
+
return (0, import_vue18.createVNode)("div", api.value.rootProps, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
|
|
1409
1753
|
};
|
|
1410
1754
|
}
|
|
1411
1755
|
});
|
|
1412
1756
|
|
|
1413
1757
|
// src/rte-suggestion.ts
|
|
1414
1758
|
var import_vue_3 = require("@tiptap/vue-3");
|
|
1415
|
-
var
|
|
1759
|
+
var import_core3 = require("@popperjs/core");
|
|
1416
1760
|
|
|
1417
1761
|
// src/extensions/mention-list-extension.tsx
|
|
1418
|
-
var
|
|
1419
|
-
var
|
|
1420
|
-
var
|
|
1762
|
+
var import_vue20 = require("vue");
|
|
1763
|
+
var import_vue21 = require("vue");
|
|
1764
|
+
var import_css7 = require("@mekari/pixel3-styled-system/css");
|
|
1421
1765
|
var import_pixel3_avatar = require("@mekari/pixel3-avatar");
|
|
1422
|
-
var
|
|
1423
|
-
var
|
|
1766
|
+
var import_pixel3_popover4 = require("@mekari/pixel3-popover");
|
|
1767
|
+
var import_pixel3_text3 = require("@mekari/pixel3-text");
|
|
1424
1768
|
var avatarVariantColors = ["violet", "lime", "amber", "sky", "pink", "teal", "rose", "stone"];
|
|
1425
1769
|
var getAvatarVariantColor = /* @__PURE__ */ __name((index) => {
|
|
1426
1770
|
return avatarVariantColors[index % avatarVariantColors.length];
|
|
1427
1771
|
}, "getAvatarVariantColor");
|
|
1428
|
-
var MentionList = (0,
|
|
1772
|
+
var MentionList = (0, import_vue21.defineComponent)({
|
|
1429
1773
|
name: "MentionList",
|
|
1430
1774
|
props: {
|
|
1431
1775
|
items: {
|
|
@@ -1440,10 +1784,10 @@ var MentionList = (0, import_vue19.defineComponent)({
|
|
|
1440
1784
|
setup(props, {
|
|
1441
1785
|
expose
|
|
1442
1786
|
}) {
|
|
1443
|
-
const selectedIndex = (0,
|
|
1444
|
-
const listRef = (0,
|
|
1787
|
+
const selectedIndex = (0, import_vue21.ref)(0);
|
|
1788
|
+
const listRef = (0, import_vue21.ref)(null);
|
|
1445
1789
|
const scrollToFocusedItem = /* @__PURE__ */ __name(() => {
|
|
1446
|
-
(0,
|
|
1790
|
+
(0, import_vue21.nextTick)(() => {
|
|
1447
1791
|
if (!listRef.value)
|
|
1448
1792
|
return;
|
|
1449
1793
|
const targetItem = listRef.value.querySelector('[data-active="true"], [data-highlight]');
|
|
@@ -1454,7 +1798,7 @@ var MentionList = (0, import_vue19.defineComponent)({
|
|
|
1454
1798
|
}
|
|
1455
1799
|
});
|
|
1456
1800
|
}, "scrollToFocusedItem");
|
|
1457
|
-
(0,
|
|
1801
|
+
(0, import_vue21.watch)(() => props.items, () => {
|
|
1458
1802
|
selectedIndex.value = 0;
|
|
1459
1803
|
});
|
|
1460
1804
|
const onSelect = /* @__PURE__ */ __name((index) => {
|
|
@@ -1495,20 +1839,20 @@ var MentionList = (0, import_vue19.defineComponent)({
|
|
|
1495
1839
|
expose({
|
|
1496
1840
|
onKeyDown
|
|
1497
1841
|
});
|
|
1498
|
-
return () => (0,
|
|
1842
|
+
return () => (0, import_vue20.createVNode)(import_pixel3_popover4.MpPopover, {
|
|
1499
1843
|
"id": "popover-rte-mention-list",
|
|
1500
1844
|
"is-manual": true,
|
|
1501
1845
|
"is-default-open": true,
|
|
1502
1846
|
"is-open": true
|
|
1503
1847
|
}, {
|
|
1504
|
-
default: () => [(0,
|
|
1505
|
-
"class": (0,
|
|
1848
|
+
default: () => [(0, import_vue20.createVNode)(import_pixel3_popover4.MpPopoverContent, {
|
|
1849
|
+
"class": (0, import_css7.css)({
|
|
1506
1850
|
width: "280px",
|
|
1507
1851
|
maxHeight: "284px",
|
|
1508
1852
|
overflowY: "auto"
|
|
1509
1853
|
})
|
|
1510
1854
|
}, {
|
|
1511
|
-
default: () => [(0,
|
|
1855
|
+
default: () => [(0, import_vue20.createVNode)(import_pixel3_popover4.MpPopoverList, {
|
|
1512
1856
|
"ref": (element) => {
|
|
1513
1857
|
var _a;
|
|
1514
1858
|
if (!element) {
|
|
@@ -1519,16 +1863,16 @@ var MentionList = (0, import_vue19.defineComponent)({
|
|
|
1519
1863
|
},
|
|
1520
1864
|
"data-pixel-rte": true
|
|
1521
1865
|
}, {
|
|
1522
|
-
default: () => [!props.items.length && (0,
|
|
1866
|
+
default: () => [!props.items.length && (0, import_vue20.createVNode)(import_pixel3_text3.MpText, {
|
|
1523
1867
|
"color": "text.secondary",
|
|
1524
|
-
"class": (0,
|
|
1868
|
+
"class": (0, import_css7.css)({
|
|
1525
1869
|
px: "3",
|
|
1526
1870
|
py: "2"
|
|
1527
1871
|
})
|
|
1528
1872
|
}, {
|
|
1529
|
-
default: () => [(0,
|
|
1873
|
+
default: () => [(0, import_vue20.createTextVNode)("No result")]
|
|
1530
1874
|
}), props.items.map((item, index) => {
|
|
1531
|
-
return (0,
|
|
1875
|
+
return (0, import_vue20.createVNode)(import_pixel3_popover4.MpPopoverListItem, {
|
|
1532
1876
|
"key": `${item.id}-${index}`,
|
|
1533
1877
|
"is-active": selectedIndex.value === index,
|
|
1534
1878
|
"onMousedown": (event) => event.preventDefault(),
|
|
@@ -1539,33 +1883,33 @@ var MentionList = (0, import_vue19.defineComponent)({
|
|
|
1539
1883
|
onSelect(index);
|
|
1540
1884
|
}
|
|
1541
1885
|
}, {
|
|
1542
|
-
default: () => [(0,
|
|
1543
|
-
"class": (0,
|
|
1886
|
+
default: () => [(0, import_vue20.createVNode)("div", {
|
|
1887
|
+
"class": (0, import_css7.css)({
|
|
1544
1888
|
display: "flex",
|
|
1545
1889
|
alignItems: "center",
|
|
1546
1890
|
gap: "2",
|
|
1547
1891
|
width: "full",
|
|
1548
1892
|
minWidth: "0"
|
|
1549
1893
|
})
|
|
1550
|
-
}, [item.avatar && (0,
|
|
1894
|
+
}, [item.avatar && (0, import_vue20.createVNode)(import_pixel3_avatar.MpAvatar, {
|
|
1551
1895
|
"id": `avatar-rte-mention-${index}`,
|
|
1552
1896
|
"name": item.avatar,
|
|
1553
1897
|
"size": "lg",
|
|
1554
1898
|
"variant-color": getAvatarVariantColor(index)
|
|
1555
|
-
}, null), (0,
|
|
1556
|
-
"class": (0,
|
|
1899
|
+
}, null), (0, import_vue20.createVNode)("div", {
|
|
1900
|
+
"class": (0, import_css7.css)({
|
|
1557
1901
|
display: "flex",
|
|
1558
1902
|
flexDirection: "column",
|
|
1559
1903
|
alignItems: "flex-start",
|
|
1560
1904
|
minWidth: "0",
|
|
1561
1905
|
flex: "1 1 0%"
|
|
1562
1906
|
})
|
|
1563
|
-
}, [(0,
|
|
1907
|
+
}, [(0, import_vue20.createVNode)(import_pixel3_text3.MpText, {
|
|
1564
1908
|
"size": "label",
|
|
1565
1909
|
"is-truncated": true
|
|
1566
1910
|
}, {
|
|
1567
1911
|
default: () => [item.name || "Unknown"]
|
|
1568
|
-
}), item.description && (0,
|
|
1912
|
+
}), item.description && (0, import_vue20.createVNode)(import_pixel3_text3.MpText, {
|
|
1569
1913
|
"size": "label-small",
|
|
1570
1914
|
"color": "text.secondary",
|
|
1571
1915
|
"is-truncated": true
|
|
@@ -1672,7 +2016,7 @@ var createMentionSuggestion = /* @__PURE__ */ __name((getSuggestionItems = () =>
|
|
|
1672
2016
|
return;
|
|
1673
2017
|
}
|
|
1674
2018
|
if (!popperInstance) {
|
|
1675
|
-
popperInstance = (0,
|
|
2019
|
+
popperInstance = (0, import_core3.createPopper)(virtualElement, popoverWrapper, {
|
|
1676
2020
|
placement: "bottom-start",
|
|
1677
2021
|
modifiers: [{
|
|
1678
2022
|
name: "offset",
|
|
@@ -1736,8 +2080,199 @@ var createMentionSuggestion = /* @__PURE__ */ __name((getSuggestionItems = () =>
|
|
|
1736
2080
|
};
|
|
1737
2081
|
}, "createMentionSuggestion");
|
|
1738
2082
|
|
|
2083
|
+
// src/rte-variable-suggestion.ts
|
|
2084
|
+
var import_vue_32 = require("@tiptap/vue-3");
|
|
2085
|
+
var import_core4 = require("@popperjs/core");
|
|
2086
|
+
var import_state = require("@tiptap/pm/state");
|
|
2087
|
+
var VariablePluginKey = new import_state.PluginKey("variable");
|
|
2088
|
+
var MAX_SUGGESTION_ITEMS2 = 50;
|
|
2089
|
+
var getFilteredSuggestionItems2 = /* @__PURE__ */ __name((items, query) => {
|
|
2090
|
+
const normalizedQuery = query.trim().toLowerCase();
|
|
2091
|
+
return items.filter((item) => {
|
|
2092
|
+
var _a, _b;
|
|
2093
|
+
if (!normalizedQuery) {
|
|
2094
|
+
return true;
|
|
2095
|
+
}
|
|
2096
|
+
const id = item.id.toLowerCase();
|
|
2097
|
+
const name = ((_a = item.name) != null ? _a : "").toLowerCase();
|
|
2098
|
+
const category = ((_b = item.category) != null ? _b : "").toLowerCase();
|
|
2099
|
+
return id.includes(normalizedQuery) || name.includes(normalizedQuery) || category.includes(normalizedQuery);
|
|
2100
|
+
}).slice(0, MAX_SUGGESTION_ITEMS2);
|
|
2101
|
+
}, "getFilteredSuggestionItems");
|
|
2102
|
+
var createVariableSuggestion = /* @__PURE__ */ __name((getSuggestionItems = () => []) => {
|
|
2103
|
+
return {
|
|
2104
|
+
char: "{",
|
|
2105
|
+
pluginKey: VariablePluginKey,
|
|
2106
|
+
command: ({
|
|
2107
|
+
editor,
|
|
2108
|
+
range,
|
|
2109
|
+
props
|
|
2110
|
+
}) => {
|
|
2111
|
+
var _a, _b;
|
|
2112
|
+
const nodeAfter = editor.view.state.selection.$to.nodeAfter;
|
|
2113
|
+
const overrideSpace = (_a = nodeAfter == null ? void 0 : nodeAfter.text) == null ? void 0 : _a.startsWith(" ");
|
|
2114
|
+
if (overrideSpace) {
|
|
2115
|
+
range.to += 1;
|
|
2116
|
+
}
|
|
2117
|
+
editor.chain().focus().insertContentAt(range, [{
|
|
2118
|
+
type: "variable",
|
|
2119
|
+
attrs: props
|
|
2120
|
+
}, {
|
|
2121
|
+
type: "text",
|
|
2122
|
+
text: " "
|
|
2123
|
+
}]).run();
|
|
2124
|
+
(_b = window.getSelection()) == null ? void 0 : _b.collapseToEnd();
|
|
2125
|
+
},
|
|
2126
|
+
allow: ({
|
|
2127
|
+
state,
|
|
2128
|
+
range
|
|
2129
|
+
}) => {
|
|
2130
|
+
const $from = state.doc.resolve(range.from);
|
|
2131
|
+
const type = state.schema.nodes["variable"];
|
|
2132
|
+
const allow = !!$from.parent.type.contentMatch.matchType(type);
|
|
2133
|
+
return allow;
|
|
2134
|
+
},
|
|
2135
|
+
items: ({
|
|
2136
|
+
query
|
|
2137
|
+
}) => {
|
|
2138
|
+
return getFilteredSuggestionItems2(getSuggestionItems(), query);
|
|
2139
|
+
},
|
|
2140
|
+
render: () => {
|
|
2141
|
+
let component = null;
|
|
2142
|
+
let popperInstance = null;
|
|
2143
|
+
let popoverWrapper = null;
|
|
2144
|
+
let clientRectProvider;
|
|
2145
|
+
let editorElement = null;
|
|
2146
|
+
let removeOutsideListeners = null;
|
|
2147
|
+
const destroyVariablePopover = /* @__PURE__ */ __name(() => {
|
|
2148
|
+
removeOutsideListeners == null ? void 0 : removeOutsideListeners();
|
|
2149
|
+
removeOutsideListeners = null;
|
|
2150
|
+
popperInstance == null ? void 0 : popperInstance.destroy();
|
|
2151
|
+
popperInstance = null;
|
|
2152
|
+
popoverWrapper == null ? void 0 : popoverWrapper.remove();
|
|
2153
|
+
popoverWrapper = null;
|
|
2154
|
+
component == null ? void 0 : component.destroy();
|
|
2155
|
+
component = null;
|
|
2156
|
+
}, "destroyVariablePopover");
|
|
2157
|
+
const isWithinVariableContext = /* @__PURE__ */ __name((target) => {
|
|
2158
|
+
if (!(target instanceof Node)) {
|
|
2159
|
+
return false;
|
|
2160
|
+
}
|
|
2161
|
+
return Boolean((editorElement == null ? void 0 : editorElement.contains(target)) || (popoverWrapper == null ? void 0 : popoverWrapper.contains(target)));
|
|
2162
|
+
}, "isWithinVariableContext");
|
|
2163
|
+
const setupOutsideListeners = /* @__PURE__ */ __name(() => {
|
|
2164
|
+
if (!editorElement || removeOutsideListeners) {
|
|
2165
|
+
return;
|
|
2166
|
+
}
|
|
2167
|
+
const handleDocumentFocusIn = /* @__PURE__ */ __name((event) => {
|
|
2168
|
+
if (!isWithinVariableContext(event.target)) {
|
|
2169
|
+
destroyVariablePopover();
|
|
2170
|
+
}
|
|
2171
|
+
}, "handleDocumentFocusIn");
|
|
2172
|
+
const handleDocumentPointerDown = /* @__PURE__ */ __name((event) => {
|
|
2173
|
+
if (!isWithinVariableContext(event.target)) {
|
|
2174
|
+
destroyVariablePopover();
|
|
2175
|
+
}
|
|
2176
|
+
}, "handleDocumentPointerDown");
|
|
2177
|
+
const handleEditorFocusOut = /* @__PURE__ */ __name((event) => {
|
|
2178
|
+
if (!isWithinVariableContext(event.relatedTarget)) {
|
|
2179
|
+
destroyVariablePopover();
|
|
2180
|
+
}
|
|
2181
|
+
}, "handleEditorFocusOut");
|
|
2182
|
+
document.addEventListener("focusin", handleDocumentFocusIn);
|
|
2183
|
+
document.addEventListener("mousedown", handleDocumentPointerDown, true);
|
|
2184
|
+
document.addEventListener("touchstart", handleDocumentPointerDown, true);
|
|
2185
|
+
editorElement.addEventListener("focusout", handleEditorFocusOut);
|
|
2186
|
+
removeOutsideListeners = /* @__PURE__ */ __name(() => {
|
|
2187
|
+
document.removeEventListener("focusin", handleDocumentFocusIn);
|
|
2188
|
+
document.removeEventListener("mousedown", handleDocumentPointerDown, true);
|
|
2189
|
+
document.removeEventListener("touchstart", handleDocumentPointerDown, true);
|
|
2190
|
+
editorElement == null ? void 0 : editorElement.removeEventListener("focusout", handleEditorFocusOut);
|
|
2191
|
+
}, "removeOutsideListeners");
|
|
2192
|
+
}, "setupOutsideListeners");
|
|
2193
|
+
const getVirtualElement = /* @__PURE__ */ __name(() => {
|
|
2194
|
+
if (!clientRectProvider) {
|
|
2195
|
+
return null;
|
|
2196
|
+
}
|
|
2197
|
+
return {
|
|
2198
|
+
getBoundingClientRect: () => {
|
|
2199
|
+
var _a;
|
|
2200
|
+
return (_a = clientRectProvider == null ? void 0 : clientRectProvider()) != null ? _a : new DOMRect();
|
|
2201
|
+
}
|
|
2202
|
+
};
|
|
2203
|
+
}, "getVirtualElement");
|
|
2204
|
+
const updatePopoverPosition = /* @__PURE__ */ __name(() => {
|
|
2205
|
+
const virtualElement = getVirtualElement();
|
|
2206
|
+
if (!virtualElement || !popoverWrapper) {
|
|
2207
|
+
return;
|
|
2208
|
+
}
|
|
2209
|
+
if (!popperInstance) {
|
|
2210
|
+
popperInstance = (0, import_core4.createPopper)(virtualElement, popoverWrapper, {
|
|
2211
|
+
placement: "bottom-start",
|
|
2212
|
+
modifiers: [{
|
|
2213
|
+
name: "offset",
|
|
2214
|
+
options: {
|
|
2215
|
+
offset: [0, 8]
|
|
2216
|
+
}
|
|
2217
|
+
}, {
|
|
2218
|
+
name: "flip",
|
|
2219
|
+
options: {
|
|
2220
|
+
fallbackPlacements: ["top-start"]
|
|
2221
|
+
}
|
|
2222
|
+
}]
|
|
2223
|
+
});
|
|
2224
|
+
return;
|
|
2225
|
+
}
|
|
2226
|
+
popperInstance.update();
|
|
2227
|
+
}, "updatePopoverPosition");
|
|
2228
|
+
return {
|
|
2229
|
+
onStart: (props) => {
|
|
2230
|
+
clientRectProvider = props.clientRect;
|
|
2231
|
+
editorElement = props.editor.view.dom;
|
|
2232
|
+
component = new import_vue_32.VueRenderer(VariableList, {
|
|
2233
|
+
editor: props.editor,
|
|
2234
|
+
props: {
|
|
2235
|
+
items: props.items,
|
|
2236
|
+
command: props.command
|
|
2237
|
+
}
|
|
2238
|
+
});
|
|
2239
|
+
popoverWrapper = document.createElement("div");
|
|
2240
|
+
popoverWrapper.style.position = "absolute";
|
|
2241
|
+
popoverWrapper.style.zIndex = "var(--mp-z-index-popover)";
|
|
2242
|
+
if (component.element) {
|
|
2243
|
+
popoverWrapper.append(component.element);
|
|
2244
|
+
}
|
|
2245
|
+
document.body.append(popoverWrapper);
|
|
2246
|
+
setupOutsideListeners();
|
|
2247
|
+
updatePopoverPosition();
|
|
2248
|
+
},
|
|
2249
|
+
onUpdate: (props) => {
|
|
2250
|
+
clientRectProvider = props.clientRect;
|
|
2251
|
+
component == null ? void 0 : component.updateProps({
|
|
2252
|
+
items: props.items,
|
|
2253
|
+
command: props.command
|
|
2254
|
+
});
|
|
2255
|
+
updatePopoverPosition();
|
|
2256
|
+
},
|
|
2257
|
+
onKeyDown: (props) => {
|
|
2258
|
+
var _a, _b;
|
|
2259
|
+
if (props.event.key === "Escape") {
|
|
2260
|
+
destroyVariablePopover();
|
|
2261
|
+
return true;
|
|
2262
|
+
}
|
|
2263
|
+
return (_b = (_a = component == null ? void 0 : component.ref) == null ? void 0 : _a.onKeyDown(props)) != null ? _b : false;
|
|
2264
|
+
},
|
|
2265
|
+
onExit: () => {
|
|
2266
|
+
destroyVariablePopover();
|
|
2267
|
+
editorElement = null;
|
|
2268
|
+
}
|
|
2269
|
+
};
|
|
2270
|
+
}
|
|
2271
|
+
};
|
|
2272
|
+
}, "createVariableSuggestion");
|
|
2273
|
+
|
|
1739
2274
|
// src/rich-text-editor.tsx
|
|
1740
|
-
var MpRichTextEditor = (0,
|
|
2275
|
+
var MpRichTextEditor = (0, import_vue23.defineComponent)({
|
|
1741
2276
|
name: "MpRichTextEditor",
|
|
1742
2277
|
props: richTextEditorProps,
|
|
1743
2278
|
emits: richTextEditorEmits,
|
|
@@ -1746,11 +2281,11 @@ var MpRichTextEditor = (0, import_vue21.defineComponent)({
|
|
|
1746
2281
|
}) {
|
|
1747
2282
|
const formControlProp = (0, import_pixel3_form_control.useFormControlContext)();
|
|
1748
2283
|
const api = useRichTextEditor(props);
|
|
1749
|
-
const isFocused = (0,
|
|
2284
|
+
const isFocused = (0, import_vue23.ref)(false);
|
|
1750
2285
|
const {
|
|
1751
2286
|
isNextTheme
|
|
1752
2287
|
} = (0, import_pixel3_utils4.usePixelTheme)();
|
|
1753
|
-
const editor = new
|
|
2288
|
+
const editor = new import_vue_33.Editor({
|
|
1754
2289
|
content: api.value.value,
|
|
1755
2290
|
editable: (formControlProp == null ? void 0 : formControlProp.value.isDisabled) === void 0 ? !api.value.isDisabled : !(formControlProp == null ? void 0 : formControlProp.value.isDisabled),
|
|
1756
2291
|
editorProps: {
|
|
@@ -1791,6 +2326,9 @@ var MpRichTextEditor = (0, import_vue21.defineComponent)({
|
|
|
1791
2326
|
}),
|
|
1792
2327
|
...props.suggestions && props.suggestions.length > 0 ? [import_extension_mention.default.configure({
|
|
1793
2328
|
suggestion: createMentionSuggestion(() => props.suggestions || [])
|
|
2329
|
+
})] : [],
|
|
2330
|
+
...props.variables && props.variables.length > 0 ? [Variable.configure({
|
|
2331
|
+
suggestion: createVariableSuggestion(() => props.variables || [])
|
|
1794
2332
|
})] : []
|
|
1795
2333
|
],
|
|
1796
2334
|
onFocus({
|
|
@@ -1821,25 +2359,26 @@ var MpRichTextEditor = (0, import_vue21.defineComponent)({
|
|
|
1821
2359
|
onClickFile: () => onClickToolbar("file"),
|
|
1822
2360
|
onClickAudio: () => onClickToolbar("audio"),
|
|
1823
2361
|
onClickMention: () => onClickToolbar("mention"),
|
|
2362
|
+
onClickVariable: () => onClickToolbar("variable"),
|
|
1824
2363
|
onClickLocation: () => onClickToolbar("location")
|
|
1825
2364
|
};
|
|
1826
2365
|
return () => {
|
|
1827
|
-
return (0,
|
|
2366
|
+
return (0, import_vue22.createVNode)("div", (0, import_vue22.mergeProps)(api.value.rootProps, {
|
|
1828
2367
|
"style": {
|
|
1829
2368
|
"--mp-rich-text-editor--border-color-hover": (formControlProp == null ? void 0 : formControlProp.value.isInvalid) || api.value.isInvalid ? isNextTheme.value ? import_tokens.token.var("colors.border.danger") : import_tokens.token.var("colors.red.400") : isFocused.value ? isNextTheme.value ? import_tokens.token.var("colors.border.focused") : import_tokens.token.var("colors.blue.400") : isNextTheme.value ? import_tokens.token.var("colors.border.form") : import_tokens.token.var("colors.gray.400"),
|
|
1830
2369
|
"--mp-rich-text-editor--border-color": (formControlProp == null ? void 0 : formControlProp.value.isInvalid) || api.value.isInvalid ? isNextTheme.value ? import_tokens.token.var("colors.border.danger") : import_tokens.token.var("colors.red.400") : isFocused.value ? isNextTheme.value ? import_tokens.token.var("colors.border.focused") : import_tokens.token.var("colors.blue.400") : isNextTheme.value ? import_tokens.token.var("colors.border.form") : import_tokens.token.var("colors.gray.100"),
|
|
1831
2370
|
"--mp-rich-text-editor--box-shadow": isFocused.value ? isNextTheme.value ? import_tokens.token.var("shadows.focus") : import_tokens.token.var("shadows.outer") : void 0,
|
|
1832
2371
|
"--mp-rich-text-editor--background-color": (formControlProp == null ? void 0 : formControlProp.value.isDisabled) || api.value.isDisabled ? isNextTheme.value ? import_tokens.token.var("colors.background.disabled") : import_tokens.token.var("colors.gray.50") : isNextTheme.value ? import_tokens.token.var("colors.background.neutral") : import_tokens.token.var("colors.white")
|
|
1833
2372
|
}
|
|
1834
|
-
}), [(0,
|
|
2373
|
+
}), [(0, import_vue22.createVNode)(EditorToolbar, (0, import_vue22.mergeProps)({
|
|
1835
2374
|
"editor": editor,
|
|
1836
2375
|
"options": api.value.options,
|
|
1837
2376
|
"validateLink": props.validateLink,
|
|
1838
2377
|
"transformLink": props.transformLink
|
|
1839
|
-
}, api.value.toolbarProps, toolbarActionHandlers), null), (0,
|
|
2378
|
+
}, api.value.toolbarProps, toolbarActionHandlers), null), (0, import_vue22.createVNode)(MpRTEStyleProvider, {
|
|
1840
2379
|
"id": `${api.value.id}-style-provider`
|
|
1841
2380
|
}, {
|
|
1842
|
-
default: () => [(0,
|
|
2381
|
+
default: () => [(0, import_vue22.createVNode)(import_vue_33.EditorContent, (0, import_vue22.mergeProps)({
|
|
1843
2382
|
"editor": editor
|
|
1844
2383
|
}, api.value.areaProps), null)]
|
|
1845
2384
|
})]);
|