@dialpad/dialtone
Version:
Dialpad's Dialtone design system monorepo
1,798 lines (1,796 loc) • 51.6 kB
JavaScript
import { nodeViewProps as L, NodeViewWrapper as R, VueRenderer as v, VueNodeViewRenderer as I, BubbleMenu as G, EditorContent as Q, Editor as Z } from "../../node_modules/@tiptap/vue-3.js";
import { Node as ee, nodePasteRule as P, InputRule as te, mergeAttributes as b, getMarksBetween as ne, combineTransactionSteps as oe, getChangedRanges as re, findChildrenInRange as ie, Mark as se, nodeInputRule as ae, Extension as le } from "@tiptap/core";
import ce from "@tiptap/extension-blockquote";
import de from "@tiptap/extension-code-block";
import ue from "@tiptap/extension-code";
import me from "@tiptap/extension-document";
import he from "@tiptap/extension-hard-break";
import q from "@tiptap/extension-paragraph";
import fe from "@tiptap/extension-placeholder";
import pe from "@tiptap/extension-bold";
import ge from "@tiptap/extension-bullet-list";
import _e from "@tiptap/extension-italic";
import ye from "@tiptap/extension-link";
import we from "@tiptap/extension-list-item";
import ke from "@tiptap/extension-ordered-list";
import xe from "@tiptap/extension-strike";
import be from "@tiptap/extension-underline";
import Ce from "@tiptap/extension-text";
import Te from "@tiptap/extension-text-align";
import Ee from "@tiptap/extension-history";
import Se from "@tiptap/extension-text-style";
import Le from "@tiptap/extension-color";
import Re from "@tiptap/extension-font-family";
import { PluginKey as T, Plugin as ve } from "@tiptap/pm/state";
import Ie from "@tiptap/suggestion";
import { emojiPattern as W } from "regex-combined-emojis";
import { resolveComponent as c, createBlock as h, openBlock as l, withCtx as u, createVNode as p, createElementBlock as _, withDirectives as Oe, createElementVNode as w, Fragment as Be, renderList as Me, withModifiers as $e, normalizeClass as z, resolveDynamicComponent as Ae, vShow as De, createTextVNode as k, toDisplayString as m, markRaw as O, createCommentVNode as x, mergeProps as Pe } from "vue";
import { _ as g } from "../../_plugin-vue_export-helper-CHgC5LLL.js";
import X from "../emoji/emoji.js";
import { emojiRegex as je, stringToUnicode as He, codeToEmojiData as H, emojiShortCodeRegex as Ne } from "../../common/emoji/index.js";
import { emojisIndexed as Fe } from "@dialpad/dialtone-emojis";
import Ke from "../list-item/list-item.js";
import B from "../stack/stack.js";
import M from "tippy.js";
import { getPhoneNumberRegex as Ve, linkRegex as Ue, warnIfUnmounted as qe, returnFirstEl as F } from "../../common/utils/index.js";
import We from "@tiptap/extension-image";
import N from "@tiptap/extension-mention";
import J from "../link/link.js";
import { RICH_TEXT_EDITOR_SUPPORTED_LINK_PROTOCOLS as K, RICH_TEXT_EDITOR_OUTPUT_FORMATS as ze, RICH_TEXT_EDITOR_AUTOFOCUS_TYPES as Xe } from "./rich-text-editor-constants.js";
import Je from "../avatar/avatar.js";
import Ye from "@dialpad/dialtone-icons/vue3/hash";
import Ge from "@dialpad/dialtone-icons/vue3/lock";
import Qe from "deep-equal";
import { DialtoneLocalization as Ze } from "../../localization/index.js";
import et from "../button/button.js";
const tt = {
compatConfig: { MODE: 3 },
name: "EmojiComponent",
components: {
NodeViewWrapper: R,
DtEmoji: X
},
props: L
};
function nt(e, t, o, n, r, i) {
const s = c("dt-emoji"), a = c("node-view-wrapper");
return l(), h(a, { class: "d-d-inline-block d-va-bottom d-lh0" }, {
default: u(() => [
p(s, {
size: "500",
code: e.node.attrs.code
}, null, 8, ["code"])
]),
_: 1
});
}
const ot = /* @__PURE__ */ g(tt, [["render", nt]]), rt = {
compatConfig: { MODE: 3 },
name: "SuggestionList",
components: {
DtListItem: Ke
},
props: {
items: {
type: Array,
required: !0
},
command: {
type: Function,
required: !0
},
itemComponent: {
type: Object,
required: !0
},
itemType: {
type: String,
required: !0
}
},
data() {
return {
selectedIndex: 0
};
},
watch: {
items() {
this.selectedIndex = 0;
}
},
methods: {
onKeyDown({ event: e }) {
return e.key === "ArrowUp" ? (this.upHandler(), !0) : e.key === "ArrowDown" ? (this.downHandler(), !0) : e.key === "Enter" || e.key === "Tab" ? (this.selectHandler(), !0) : !1;
},
upHandler() {
this.selectedIndex = (this.selectedIndex + this.items.length - 1) % this.items.length, this.scrollActiveElementIntoView();
},
downHandler() {
this.selectedIndex = (this.selectedIndex + 1) % this.items.length, this.scrollActiveElementIntoView();
},
async scrollActiveElementIntoView() {
await this.$nextTick();
const e = this.$refs.suggestionList.querySelector(".d-list-item--highlighted");
e && e.scrollIntoView({
behaviour: "smooth",
block: "center"
});
},
selectHandler() {
this.selectItem(this.selectedIndex);
},
selectItem(e) {
const t = this.items[e];
switch (this.itemType) {
case "emoji":
this.command(t);
return;
case "mention":
this.command({ name: t.name, id: t.id, avatarSrc: t.avatarSrc });
break;
case "channel":
this.command({ name: t.name, id: t.id });
break;
case "slash-command":
this.command({ command: t.command });
break;
}
}
}
}, it = { class: "d-popover__dialog d-suggestion-list__container" }, st = {
ref: "suggestionList",
class: "d-suggestion-list"
};
function at(e, t, o, n, r, i) {
const s = c("dt-list-item");
return l(), _("div", it, [
Oe(w("ul", st, [
(l(!0), _(Be, null, Me(o.items, (a, d) => (l(), h(s, {
key: a.id,
class: z([
"d-suggestion-list__item",
{ "d-list-item--highlighted": d === r.selectedIndex }
]),
"navigation-type": "arrow-keys",
onClick: (f) => i.selectItem(d),
onKeydown: $e(i.onKeyDown, ["prevent"])
}, {
default: u(() => [
(l(), h(Ae(o.itemComponent), { item: a }, null, 8, ["item"]))
]),
_: 2
}, 1032, ["class", "onClick", "onKeydown"]))), 128))
], 512), [
[De, o.items.length]
])
]);
}
const $ = /* @__PURE__ */ g(rt, [["render", at]]), lt = {
compatConfig: { MODE: 3 },
name: "EmojiSuggestion",
components: {
DtEmoji: X,
DtStack: B
},
props: {
item: {
type: Object,
required: !0
}
}
};
function ct(e, t, o, n, r, i) {
const s = c("dt-emoji"), a = c("dt-stack");
return l(), h(a, {
direction: "row",
gap: "400"
}, {
default: u(() => [
p(s, {
size: "200",
code: o.item.code
}, null, 8, ["code"]),
k(" " + m(o.item.code), 1)
]),
_: 1
});
}
const dt = /* @__PURE__ */ g(lt, [["render", ct]]), A = {
name: "hideOnEsc",
defaultValue: !0,
fn({ hide: e }) {
function t(o) {
o.keyCode === 27 && e();
}
return {
onShow() {
document.addEventListener("keydown", t);
},
onHide() {
document.removeEventListener("keydown", t);
}
};
}
}, ut = 20, mt = {
items: ({ query: e }) => {
if (e.length < 2)
return [];
const t = Object.values(Fe);
return e = e.toLowerCase(), t.filter(
(n) => [
n.name,
n.shortname.replaceAll(":", ""),
...n.keywords
].some((r) => r.startsWith(e))
).splice(0, ut).map((n) => ({ code: n.shortname }));
},
command: ({ editor: e, range: t, props: o }) => {
var i, s;
const n = e.view.state.selection.$to.nodeAfter;
((i = n == null ? void 0 : n.text) == null ? void 0 : i.startsWith(" ")) && (t.to += 1), e.chain().focus().insertContentAt(t, [
{
type: "emoji",
attrs: o
}
]).run(), (s = window.getSelection()) == null || s.collapseToEnd();
},
render: () => {
let e, t, o = !1;
return {
onStart: (n) => {
e = new v($, {
props: {
itemComponent: O(dt),
itemType: "emoji",
...n
},
editor: n.editor
}), n.clientRect && (t = M("body", {
getReferenceClientRect: n.clientRect,
appendTo: () => document.body,
content: e.element,
showOnCreate: !1,
onShow: () => {
o = !0;
},
onHidden: () => {
o = !1;
},
interactive: !0,
trigger: "manual",
placement: "top-start",
zIndex: 650,
plugins: [A]
}), n.items.length > 0 && (t == null || t[0].show()));
},
onUpdate(n) {
e == null || e.updateProps(n), n.items.length > 0 ? t == null || t[0].show() : t == null || t[0].hide(), t == null || t[0].setProps({
getReferenceClientRect: n.clientRect
});
},
onKeyDown(n) {
var r;
if (o)
return (r = e == null ? void 0 : e.ref) == null ? void 0 : r.onKeyDown(n);
},
onExit() {
t == null || t[0].destroy(), t = null, e == null || e.destroy(), e = null;
}
};
}
}, ht = /(:\w+:)$/, ft = new RegExp(W + "$"), pt = (e) => {
if (e && H(e[0]))
return { text: e[2] || e[0] };
}, gt = (e) => [...e.matchAll(Ne)].filter((o) => H(o[0])).map((o) => ({
index: o.index,
text: o[0],
match: o
})), _t = ee.create({
name: "emoji",
addOptions() {
return {
HTMLAttributes: {}
};
},
group: "inline",
inline: !0,
selectable: !1,
atom: !0,
addNodeView() {
return I(ot);
},
addAttributes() {
return {
code: {
default: null
}
};
},
parseHTML() {
return [
{
tag: "emoji-component"
}
];
},
renderText({ node: e }) {
return He(H(e.attrs.code).unicode_output);
},
renderHTML({ HTMLAttributes: e }) {
return ["emoji-component", b(this.options.HTMLAttributes, e)];
},
addInputRules() {
return [
new te({
find: (e) => {
const t = e.match(ht) || e.match(ft);
if (t)
return pt(t);
},
handler: ({ state: e, range: t, match: o }) => {
const { tr: n } = e, r = t.from, i = t.to;
n.replaceWith(r, i, this.type.create({ code: o[0] }));
}
})
];
},
addPasteRules() {
return [
P({
find: gt,
type: this.type,
getAttributes(e) {
return {
code: e[0]
};
}
}),
P({
find: je,
type: this.type,
getAttributes(e) {
return {
code: e[0]
};
}
})
];
},
addProseMirrorPlugins() {
return [
Ie({
char: ":",
pluginKey: new T("emoji"),
editor: this.editor,
...this.options.suggestion,
...mt
})
];
},
addKeyboardShortcuts() {
return {
Backspace: () => this.editor.commands.command(({ tr: e, state: t }) => {
let o = !1;
const { selection: n } = t, { empty: r, anchor: i } = n;
return r ? (t.doc.nodesBetween(i - 1, i, (s, a) => {
if (s.type.name === this.name)
return o = !0, e.insertText("", a, a + s.nodeSize), !1;
}), o) : !1;
})
};
}
});
function yt(e, t, o = () => !0) {
const n = [];
t.lastIndex = 0;
let r;
for (; r = t.exec(e); )
o(e, r) && n.push(r);
return n;
}
function wt(e, t) {
return !["#", "@"].includes(e.charAt(t.index)) && !["#", "@"].includes(e.charAt(t.index - 1));
}
function kt(e) {
const t = new RegExp(
"(?:" + [
`[!?.,:;'"]`,
"(?:&|&)(?:lt|gt|quot|apos|raquo|laquo|rsaquo|lsaquo);)+$"
].join("|"),
"g"
);
return e.replace(t, "");
}
function xt(e, t) {
const o = e.slice(0, t + 1).search(/\S+\s*$/), n = e.slice(t).search(/\s/);
if (n < 0) {
const r = e.slice(o);
return {
text: r,
from: o,
to: o + r.length
};
}
return {
text: e.slice(o, n + t),
from: o,
to: n + t
};
}
function j(e, t, o, n) {
const r = xt(e, t);
if (n.lastIndex = 0, !n.test(r.text))
return r;
const i = o === "left" ? r.from - 1 : r.to + 1;
return i <= 0 || i >= e.length || i === t ? r : j(e, i, o, n);
}
function bt(e, t, o, n) {
const r = Math.max(e.from - 1, 0), i = Math.min(e.to + 1, t.content.size), s = ne(r, i, t);
for (const a of s)
a.mark.type === n && o.removeMark(a.from, a.to, n);
}
const V = Ve(1, 15);
function U(e, t, o, n, r, i) {
if (!e)
return;
let s = o - t - 1;
s = s < 0 ? 0 : s;
const a = n - t, d = j(
e,
s,
"left",
V
), f = j(
e,
a,
"right",
V
), y = e.slice(d.from, f.to);
yt(y, Ue, wt).forEach((D) => {
const C = kt(D[0]), S = t + d.from + D.index + 1, Y = S + C.length;
r.addMark(S, Y, i.create());
});
}
function Ct(e) {
let t = !1;
return new ve({
key: new T("autolink"),
appendTransaction: (o, n, r) => {
const i = o.some((y) => y.docChanged) && !n.doc.eq(r.doc);
if (t && !i)
return;
const { tr: s } = r, { textContent: a } = r.doc;
t || U(a, 0, 0, a.length, s, e.type), t = !0;
const d = oe(
n.doc,
[...o]
);
return re(d).forEach(({ oldRange: y, newRange: E }) => {
bt(E, r.doc, s, e.type), ie(
r.doc,
E,
(C) => C.isTextblock
).forEach(({ node: C, pos: S }) => {
U(
C.textContent,
S,
y.from,
E.to,
s,
e.type
);
});
}), s;
}
});
}
const Tt = {
class: "d-link d-c-text d-d-inline-block d-wb-break-all",
rel: "noopener noreferrer nofollow"
}, Et = se.create({
name: "CustomLink",
renderHTML({ HTMLAttributes: e }) {
return [
"a",
b(
this.options.HTMLAttributes,
e,
Tt
)
];
},
renderText({ node: e }) {
return e.attrs.text;
},
addProseMirrorPlugins() {
return [
Ct({ type: this.type })
];
}
}), St = We.extend({
name: "ConfigurableImage",
addAttributes() {
return {
src: {
default: ""
},
alt: {
default: void 0
},
title: {
default: void 0
},
width: {
default: void 0
},
height: {
default: void 0
},
style: {
default: void 0
}
};
}
}).configure({ inline: !0, allowBase64: !0 }), Lt = q.extend({
parseHTML() {
return [{ tag: "div" }];
},
renderHTML({ HTMLAttributes: e }) {
return ["div", b(this.options.HTMLAttributes, e), 0];
}
}), Rt = {
compatConfig: { MODE: 3 },
name: "MentionComponent",
components: {
NodeViewWrapper: R,
DtLink: J
},
props: L,
computed: {
text() {
return "@" + this.$props.node.attrs.name;
}
}
};
function vt(e, t, o, n, r, i) {
const s = c("dt-link"), a = c("node-view-wrapper");
return l(), h(a, { class: "d-d-inline-block" }, {
default: u(() => [
p(s, { kind: "mention" }, {
default: u(() => [
k(m(i.text), 1)
]),
_: 1
})
]),
_: 1
});
}
const It = /* @__PURE__ */ g(Rt, [["render", vt]]), Ot = N.extend({
addNodeView() {
return I(It);
},
parseHTML() {
return [
{
tag: "mention-component"
}
];
},
addAttributes() {
return {
name: {
default: ""
},
avatarSrc: {
default: ""
},
id: {
default: ""
}
};
},
renderText({ node: e }) {
return `@${e.attrs.id}`;
},
renderHTML({ HTMLAttributes: e }) {
return ["mention-component", b(this.options.HTMLAttributes, e)];
}
}).configure({
suggestion: {
char: "@",
pluginKey: new T("mentionSuggestion")
}
}), Bt = {
compatConfig: { MODE: 3 },
name: "ChannelComponent",
components: {
NodeViewWrapper: R,
DtLink: J
},
props: L,
computed: {
text() {
return "#" + this.$props.node.attrs.name;
}
}
};
function Mt(e, t, o, n, r, i) {
const s = c("dt-link"), a = c("node-view-wrapper");
return l(), h(a, { class: "d-d-inline-block" }, {
default: u(() => [
p(s, { kind: "mention" }, {
default: u(() => [
k(m(i.text), 1)
]),
_: 1
})
]),
_: 1
});
}
const $t = /* @__PURE__ */ g(Bt, [["render", Mt]]), At = N.extend({
name: "channel",
addNodeView() {
return I($t);
},
parseHTML() {
return [
{
tag: "channel-component"
}
];
},
addAttributes() {
return {
name: {
default: ""
},
id: {
default: ""
},
locked: {
default: !1
}
};
},
renderText({ node: e }) {
return `#${e.attrs.id}`;
},
renderHTML({ HTMLAttributes: e }) {
return ["channel-component", b(this.options.HTMLAttributes, e)];
}
}).configure({
suggestion: {
char: "#",
pluginKey: new T("channelSuggestion")
}
}), Dt = {
compatConfig: { MODE: 3 },
name: "SlashCommandsComponent",
components: {
NodeViewWrapper: R
},
props: {
...L
},
emits: ["selected-command"],
computed: {
text() {
return "/" + this.$props.node.attrs.command;
}
},
created() {
var o, n, r;
const e = this.$props.node.attrs.command;
this.$emit("selected-command", e);
const t = (r = (n = (o = this.editor) == null ? void 0 : o.storage) == null ? void 0 : n["slash-commands"]) == null ? void 0 : r.onSelectedCommand;
t && typeof t == "function" && t(e);
}
};
function Pt(e, t, o, n, r, i) {
const s = c("node-view-wrapper");
return l(), h(s, { class: "d-d-inline-block" }, {
default: u(() => [
k(m(i.text), 1)
]),
_: 1
});
}
const jt = /* @__PURE__ */ g(Dt, [["render", Pt]]), Ht = (e, t) => [...e.matchAll(t)].map((n) => {
let r = n[2];
return r.endsWith(" ") || (r += " "), {
index: n.index,
text: r,
match: n
};
}), Nt = N.extend({
name: "slash-commands",
group: "inline",
inline: !0,
addOptions() {
var e;
return {
...(e = this.parent) == null ? void 0 : e.call(this),
onSelectedCommand: null
};
},
addStorage() {
return {
onSelectedCommand: this.options.onSelectedCommand
};
},
addNodeView() {
return I(jt);
},
parseHTML() {
return [
{
tag: "command-component"
}
];
},
addAttributes() {
return {
command: {
default: ""
},
parametersExample: {
default: ""
},
description: {
default: ""
}
};
},
renderText({ node: e }) {
return `/${e.attrs.command}`;
},
renderHTML({ HTMLAttributes: e }) {
return ["command-component", b(this.options.HTMLAttributes, e)];
},
addInputRules() {
var o;
const e = (o = this.options.suggestion) == null ? void 0 : o.items({ query: "" }).map((n) => n.command), t = new RegExp(`^((?:\\/)(${e.join("|")})) $`);
return [
ae({
find: t,
type: this.type,
getAttributes(n) {
return { command: n[2] };
}
})
];
},
addPasteRules() {
var o;
const e = (o = this.options.suggestion) == null ? void 0 : o.items({ query: "" }).map((n) => n.command), t = new RegExp(`^((?:\\/)(${e.join("|")})) ?$`, "g");
return [
P({
find: (n) => Ht(n, t),
type: this.type,
getAttributes(n) {
return { command: n[0].trim() };
}
})
];
}
}).configure({
suggestion: {
char: "/",
pluginKey: new T("slashCommandSuggestion")
}
}), Ft = {
compatConfig: { MODE: 3 },
name: "MentionSuggestion",
components: {
DtAvatar: Je,
DtStack: B
},
props: {
item: {
type: Object,
required: !0
}
},
computed: {
name() {
return this.item.name;
},
avatarSrc() {
return this.item.avatarSrc;
},
presence() {
return this.item.presence;
},
status() {
return this.item.status;
},
presenceText() {
return this.item.presenceText;
},
presenceFontColorClass() {
return {
active: "d-recipe-contact-row--active",
busy: "d-recipe-contact-row--busy",
away: "d-recipe-contact-row--away",
offline: "d-recipe-contact-row--busy"
}[this.presence];
},
showDetails() {
return this.item.showDetails;
}
}
}, Kt = { class: "d-mention-suggestion__name" }, Vt = {
key: 1,
class: "d-mention-suggestion__divider"
}, Ut = {
key: 2,
class: "d-mention-suggestion__status"
};
function qt(e, t, o, n, r, i) {
const s = c("dt-avatar"), a = c("dt-stack");
return l(), h(a, {
direction: "row",
class: "d-mention-suggestion__container",
gap: "400"
}, {
default: u(() => [
p(s, {
"full-name": i.name,
"image-src": i.avatarSrc,
"image-alt": i.name,
"show-presence": i.showDetails,
presence: i.presence,
size: "sm"
}, null, 8, ["full-name", "image-src", "image-alt", "show-presence", "presence"]),
p(a, {
class: "d-mention-suggestion__details-container",
gap: "100"
}, {
default: u(() => [
w("span", Kt, m(i.name), 1),
i.showDetails ? (l(), h(a, {
key: 0,
direction: "row",
gap: "300",
class: "d-label--sm-plain"
}, {
default: u(() => [
i.presenceText ? (l(), _("span", {
key: 0,
class: z(["d-mention-suggestion__presence", [i.presenceFontColorClass]])
}, m(i.presenceText), 3)) : x("", !0),
i.status && i.presenceText ? (l(), _("div", Vt, " • ")) : x("", !0),
i.status ? (l(), _("div", Ut, m(i.status), 1)) : x("", !0)
]),
_: 1
})) : x("", !0)
]),
_: 1
})
]),
_: 1
});
}
const Wt = /* @__PURE__ */ g(Ft, [["render", qt]]), zt = {
// This function comes from the user and passed to the editor directly.
// This will also activate the mention plugin on the editor
// items: ({ query }) => { return [] },
allowSpaces: !0,
render: () => {
let e, t, o = !1;
return {
onStart: (n) => {
e = new v($, {
props: {
itemComponent: O(Wt),
itemType: "mention",
...n
},
editor: n.editor
}), n.clientRect && (t = M("body", {
getReferenceClientRect: n.clientRect,
appendTo: () => document.body,
content: e.element,
showOnCreate: !1,
onShow: () => {
o = !0;
},
onHidden: () => {
o = !1;
},
interactive: !0,
trigger: "manual",
placement: "top-start",
zIndex: 650,
plugins: [A]
}), n.items.length > 0 && (t == null || t[0].show()));
},
onUpdate(n) {
e == null || e.updateProps(n), n.items.length > 0 ? t == null || t[0].show() : t == null || t[0].hide(), n.clientRect && (t == null || t[0].setProps({
getReferenceClientRect: n.clientRect
}));
},
onKeyDown(n) {
var r;
if (o)
return (r = e == null ? void 0 : e.ref) == null ? void 0 : r.onKeyDown(n);
},
onExit() {
t == null || t[0].destroy(), t = null, e == null || e.destroy(), e = null;
}
};
}
}, Xt = {
compatConfig: { MODE: 3 },
name: "ChannelSuggestion",
components: {
DtStack: B,
DtIconHash: Ye,
DtIconLock: Ge
},
props: {
item: {
type: Object,
required: !0
}
},
computed: {
name() {
return this.item.name;
}
}
};
function Jt(e, t, o, n, r, i) {
const s = c("dt-icon-hash"), a = c("dt-icon-lock"), d = c("dt-stack");
return l(), h(d, {
direction: "row",
gap: "400"
}, {
default: u(() => [
o.item.locked ? (l(), h(a, {
key: 1,
size: "300"
})) : (l(), h(s, {
key: 0,
size: "300"
})),
w("span", null, m(i.name), 1)
]),
_: 1
});
}
const Yt = /* @__PURE__ */ g(Xt, [["render", Jt]]), Gt = {
// This function comes from the user and passed to the editor directly.
// This will also activate the mention plugin on the editor
// items: ({ query }) => { return [] },
allowSpaces: !0,
render: () => {
let e, t, o = !1;
return {
onStart: (n) => {
e = new v($, {
props: {
itemComponent: O(Yt),
itemType: "channel",
...n
},
editor: n.editor
}), n.clientRect && (t = M("body", {
getReferenceClientRect: n.clientRect,
appendTo: () => document.body,
content: e.element,
showOnCreate: !1,
onShow: () => {
o = !0;
},
onHidden: () => {
o = !1;
},
interactive: !0,
trigger: "manual",
placement: "top-start",
zIndex: 650,
plugins: [A]
}), n.items.length > 0 && (t == null || t[0].show()));
},
onUpdate(n) {
e == null || e.updateProps(n), n.items.length > 0 ? t == null || t[0].show() : t == null || t[0].hide(), n.clientRect && (t == null || t[0].setProps({
getReferenceClientRect: n.clientRect
}));
},
onKeyDown(n) {
var r;
if (o)
return (r = e == null ? void 0 : e.ref) == null ? void 0 : r.onKeyDown(n);
},
onExit() {
t == null || t[0].destroy(), t = null, e == null || e.destroy(), e = null;
}
};
}
}, Qt = {
compatConfig: { MODE: 3 },
name: "SlashCommandSuggestion",
props: {
item: {
type: Object,
required: !0
}
},
computed: {
command() {
return this.item.command;
},
description() {
return this.item.description;
},
parametersExample() {
return this.item.parametersExample;
}
}
}, Zt = { class: "d-body--md-compact" }, en = { key: 0 }, tn = { class: "d-body--sm d-fc-tertiary" };
function nn(e, t, o, n, r, i) {
return l(), _("div", null, [
w("div", Zt, [
w("span", null, "/" + m(i.command), 1),
i.parametersExample ? (l(), _("span", en, m(i.parametersExample), 1)) : x("", !0)
]),
w("div", tn, m(i.description), 1)
]);
}
const on = /* @__PURE__ */ g(Qt, [["render", nn]]), rn = {
// This function comes from the user and passed to the editor directly.
// This will also activate the mention plugin on the editor
// items: ({ query }) => { return [] },
allowSpaces: !0,
startOfLine: !0,
render: () => {
let e, t, o = !1;
return {
onStart: (n) => {
e = new v($, {
parent: void 0,
props: {
itemComponent: O(on),
itemType: "slash-command",
...n
},
editor: n.editor
}), n.clientRect && (t = M("body", {
getReferenceClientRect: n.clientRect,
appendTo: () => document.body,
content: e.element,
showOnCreate: !1,
onShow: () => {
o = !0;
},
onHidden: () => {
o = !1;
},
interactive: !0,
trigger: "manual",
placement: "top-start",
zIndex: 650,
plugins: [A]
}), n.items.length > 0 && (t == null || t[0].show()));
},
onUpdate(n) {
e == null || e.updateProps(n), n.items.length > 0 ? t == null || t[0].show() : t == null || t[0].hide(), n.clientRect && (t == null || t[0].setProps({
getReferenceClientRect: n.clientRect
}));
},
onKeyDown(n) {
var r;
if (o)
return (r = e == null ? void 0 : e.ref) == null ? void 0 : r.onKeyDown(n);
},
onExit() {
t == null || t[0].destroy(), t = null, e == null || e.destroy(), e = null;
}
};
}
}, sn = {
compatConfig: { MODE: 3 },
name: "DtRichTextEditor",
components: {
EditorContent: Q,
BubbleMenu: G,
DtButton: et,
DtStack: B
},
props: {
/**
* Value of the input. The object format should match TipTap's JSON
* document structure: https://tiptap.dev/guide/output#option-1-json
*/
modelValue: {
type: [Object, String],
default: ""
},
/**
* Whether the input is editable
*/
editable: {
type: Boolean,
default: !0
},
/**
* Prevents the user from typing any further. Deleting text will still work.
*/
preventTyping: {
type: Boolean,
default: !1
},
/**
* When this option is false the editor will only ever paste plain text, no rich text formatting will be applied,
* and any HTML will be rendered as text.
*/
pasteRichText: {
type: Boolean,
default: !0
},
/**
* Whether the input allows for line breaks to be introduced in the text by pressing enter. If this is disabled,
* line breaks can still be entered by pressing shift+enter.
*/
allowLineBreaks: {
type: Boolean,
default: !1
},
/**
* Descriptive label for the input element
*/
inputAriaLabel: {
type: String,
required: !0
},
/**
* Additional class name for the input element. Only accepts a String value
* because this is passed to the editor via options. For multiple classes,
* join them into one string, e.g. "d-p8 d-hmx96"
*/
inputClass: {
type: String,
default: ""
},
/**
* Whether the input should receive focus after the component has been
* mounted. Either one of `start`, `end`, `all` or a Boolean or a Number.
* - `start` Sets the focus to the beginning of the input
* - `end` Sets the focus to the end of the input
* - `all` Selects the whole contents of the input
* - `Number` Sets the focus to a specific position in the input
* - `true` Defaults to `start`
* - `false` Disables autofocus
* @values true, false, start, end, all, number
*/
autoFocus: {
type: [Boolean, String, Number],
default: !1,
validator(e) {
return typeof e == "string" ? Xe.includes(e) : !0;
}
},
/**
* The output format that the editor uses when emitting the "@input" event.
* One of `text`, `json`, `html`. See https://tiptap.dev/guide/output for
* examples.
* @values text, json, html
*/
outputFormat: {
type: String,
default: "html",
validator(e) {
return ze.includes(e);
}
},
/**
* Placeholder text
*/
placeholder: {
type: String,
default: ""
},
/**
* Enables the TipTap Link extension and optionally passes configurations to it
*
* It is not recommended to use this and the custom link extension at the same time.
*/
link: {
type: [Boolean, Object],
default: !1
},
/**
* Enables the Custom Link extension and optionally passes configurations to it
*
* It is not recommended to use this and the built in TipTap link extension at the same time.
*
* The custom link does some additional things on top of the built in TipTap link
* extension such as styling phone numbers and IP adresses as links, and allows you
* to linkify text without having to type a space after the link. Currently it is missing some
* functionality such as editing links and will likely require more work to be fully usable,
* so it is recommended to use the built in TipTap link for now.
*/
customLink: {
type: [Boolean, Object],
default: !1
},
/**
* suggestion object containing the items query function.
* The valid keys passed into this object can be found here: https://tiptap.dev/api/utilities/suggestion
*
* The only required key is the items function which is used to query the contacts for suggestion.
* items({ query }) => { return [ContactObject]; }
* ContactObject format:
* { name: string, avatarSrc: string, id: string }
*
* When null, it does not add the plugin.
*/
mentionSuggestion: {
type: Object,
default: null
},
/**
* suggestion object containing the items query function.
* The valid keys passed into this object can be found here: https://tiptap.dev/api/utilities/suggestion
*
* The only required key is the items function which is used to query the channels for suggestion.
* items({ query }) => { return [ChannelObject]; }
* ChannelObject format:
* { name: string, id: string, locked: boolean }
*
* When null, it does not add the plugin. Setting locked to true will display a lock rather than hash.
*/
channelSuggestion: {
type: Object,
default: null
},
/**
* suggestion object containing the items query function.
* The valid keys passed into this object can be found here: https://tiptap.dev/api/utilities/suggestion
*
* The only required key is the items function which is used to query the slash commands for suggestion.
* items({ query }) => { return [SlashCommandObject]; }
* SlashCommandObject format:
* { command: string, description: string, parametersExample?: string }
* The "parametersExample" parameter is optional, and describes an example
* of the parameters that command can take.
*
* When null, it does not add the plugin.
* Note that slash commands only work when they are the first word in the input.
*/
slashCommandSuggestion: {
type: Object,
default: null
},
/**
* Whether the input allows for block quote.
*/
allowBlockquote: {
type: Boolean,
default: !0
},
/**
* Whether the input allows for bold to be introduced in the text.
*/
allowBold: {
type: Boolean,
default: !0
},
/**
* Whether the input allows for bullet list to be introduced in the text.
*/
allowBulletList: {
type: Boolean,
default: !0
},
/**
* Whether the input allows for italic to be introduced in the text.
*/
allowItalic: {
type: Boolean,
default: !0
},
/**
* Whether the input allows for strike to be introduced in the text.
*/
allowStrike: {
type: Boolean,
default: !0
},
/**
* Whether the input allows for underline to be introduced in the text.
*/
allowUnderline: {
type: Boolean,
default: !0
},
/**
* Whether the input allows inline code (wrapped in backticks).
*/
allowCode: {
type: Boolean,
default: !0
},
/**
* Whether the input allows codeblock to be introduced in the text.
*/
allowCodeblock: {
type: Boolean,
default: !0
},
/**
* Whether the input allows inline images to be rendered.
*/
allowInlineImages: {
type: Boolean,
default: !1
},
/**
* Whether the input allows color to be introduced in the text.
*/
allowFontColor: {
type: Boolean,
default: !1
},
/**
* Whether the input allows different font-families to be introduced in the text.
*/
allowFontFamily: {
type: Boolean,
default: !1
},
/**
* Additional TipTap extensions to be added to the editor.
*/
additionalExtensions: {
type: Array,
default: () => []
},
/**
* Manually hide the link bubble menu. The link bubble menu is shown when a link is selected via the cursor.
* There are some cases when you may want the link to remain selected but hide the bubble menu such as when You
* are showing a custom link editor popup.
*/
hideLinkBubbleMenu: {
type: Boolean,
default: !1
},
/**
* Show text in HTML div tags instead of paragraph tags
*/
useDivTags: {
type: Boolean,
default: !1
}
},
emits: [
/**
* Editor input event
* @event input
* @type {String|JSON}
*/
"input",
/**
* Input event always in JSON format.
* @event input
* @type {JSON}
*/
"json-input",
/**
* Input event always in HTML format.
* @event input
* @type {HTML}
*/
"html-input",
/**
* Input event always in text format.
* @event input
* @type {String}
*/
"text-input",
/**
* Event to sync the value with the parent
* @event update:value
* @type {String|JSON}
*/
"update:modelValue",
/**
* Editor blur event
* @event blur
* @type {FocusEvent}
*/
"blur",
/**
* Editor focus event
* @event focus
* @type {FocusEvent}
*/
"focus",
/**
* Enter was pressed. Note that shift enter must be pressed to line break the input.
* @event enter
* @type {String}
*/
"enter",
/**
* "Edit link" button was clicked. Fires an event for the consuming component to handle the editing of the link.
* event contains the link object with two properties href and text.
* @event edit-link
* @type {Object}
*/
"edit-link",
/**
* "Selected" event is fired when the user selects text in the editor. returns the currently selected text.
* If the selected text is partially a link, the full link text is returned.
* @event selected
* @type {String}
*/
"selected",
/**
* Event fired when a slash command is selected
* @event selected-command
* @type {String}
*/
"selected-command"
],
data() {
return {
editor: null,
tippyOptions: {
appendTo: () => {
var e;
return (e = F(this.$refs.editor.$el).getRootNode()) == null ? void 0 : e.querySelector("body");
},
placement: "top-start"
},
i18n: new Ze()
};
},
computed: {
attrs() {
return {
...this.$attrs,
onInput: () => {
},
onFocus: () => {
},
onBlur: () => {
}
};
},
// eslint-disable-next-line complexity
extensions() {
const e = [me, Ce, Ee, he];
e.push(this.useDivTags ? Lt : q), this.allowBold && e.push(pe), this.allowBlockquote && e.push(ce), this.allowBulletList && (e.push(ge), e.push(we.extend({
renderText({ node: n }) {
return n.textContent;
}
})), e.push(ke)), this.allowItalic && e.push(_e), this.allowStrike && e.push(xe), this.allowUnderline && e.push(be), this.placeholder && e.push(
fe.configure({ placeholder: this.placeholder })
);
const t = this, o = le.create({
addKeyboardShortcuts() {
return {
"Shift-Enter": ({ editor: n }) => t.allowLineBreaks ? !1 : (n.commands.first(({ commands: r }) => [
() => r.newlineInCode(),
() => t.allowBulletList && r.splitListItem("listItem"),
() => r.createParagraphNear(),
() => r.liftEmptyBlock(),
() => r.splitBlock()
]), !0),
Enter: () => t.allowLineBreaks ? !1 : (t.$emit("enter"), !0)
};
}
});
if (e.push(o), this.link && e.push(ye.extend({
inclusive: !1,
addKeyboardShortcuts() {
return {
"Mod-k": () => (t.$emit("edit-link"), !0)
};
}
}).configure({
HTMLAttributes: {
class: "d-link d-wb-break-all"
},
openOnClick: !1,
autolink: !0,
protocols: K
})), this.customLink && e.push(this.getExtension(Et, this.customLink)), this.mentionSuggestion) {
const n = { ...this.mentionSuggestion, ...zt };
e.push(Ot.configure({ suggestion: n }));
}
if (this.channelSuggestion) {
const n = { ...this.channelSuggestion, ...Gt };
e.push(At.configure({ suggestion: n }));
}
if (this.slashCommandSuggestion) {
const n = { ...this.slashCommandSuggestion, ...rn };
e.push(Nt.configure({
suggestion: n,
onSelectedCommand: (r) => {
this.$emit("selected-command", r);
}
}));
}
return e.push(_t), e.push(Te.configure({
types: ["paragraph"]
})), this.allowCode && e.push(ue), this.allowCodeblock && e.push(de.extend({
renderText({ node: n }) {
return `\`\`\`
${n.textContent}
\`\`\``;
}
}).configure({
HTMLAttributes: {
class: "d-rich-text-editor__code-block"
}
})), this.allowInlineImages && e.push(St), (this.allowFontFamily || this.allowFontColor) && (e.push(Se), this.allowFontColor && e.push(Le), this.allowFontFamily && e.push(Re)), this.additionalExtensions.length && e.push(...this.additionalExtensions), e;
},
inputAttrs() {
const e = {
"aria-label": this.inputAriaLabel,
"aria-multiline": !0,
role: "textbox"
};
return this.editable || (e["aria-readonly"] = !0), e;
}
},
/**
* Because the Editor instance is initialized when mounted it does not get
* updated props automatically, so the ones that can change after mount have
* to be hooked up to the Editor's own API.
*/
watch: {
editable(e) {
this.editor.setEditable(e), this.updateEditorAttributes({ "aria-readonly": !e });
},
inputClass(e) {
this.updateEditorAttributes({ class: e });
},
inputAriaLabel(e) {
this.updateEditorAttributes({ "aria-label": e });
},
extensions() {
this.destroyEditor(), this.createEditor();
},
modelValue(e) {
this.processValue(e);
}
},
created() {
this.createEditor();
},
beforeUnmount() {
this.destroyEditor();
},
mounted() {
qe(F(this.$el), this.$options.name), this.processValue(this.modelValue, !1);
},
methods: {
createEditor() {
this.editor = new Z({
autofocus: this.autoFocus,
content: this.modelValue,
editable: this.editable,
extensions: this.extensions,
parseOptions: {
preserveWhitespace: "full"
},
editorProps: {
attributes: {
...this.inputAttrs,
class: this.inputClass
},
handleKeyDown: (e, t) => {
if (!this.preventTyping) return !1;
const o = ["Backspace"];
return !this.allowLineBreaks && !t.shiftKey && o.push("Enter"), !o.includes(t.key);
},
handlePaste: (e, t) => {
const o = t.clipboardData || window.clipboardData, n = o.getData("text/plain"), r = o.getData("text/html");
return this.processPasteData(e, n, r);
},
// Moves the <br /> tags inside the previous closing tag to avoid
// Prosemirror wrapping them within another </p> tag.
transformPastedHTML(e) {
return e.replace(/(<\/\w+>)((<br \/>)+)/g, "$2$3$1");
}
}
}), this.addEditorListeners();
},
bubbleMenuShouldShow({ editor: e }) {
return e.isActive("link");
},
/**
* If the selection contains a link, return the existing link text.
* Otherwise, use just the selected text.
* @param editor the editor instance.
*/
getSelectedLinkText(e) {
var a, d, f;
const { view: t, state: o } = e, { from: n, to: r } = t.state.selection, i = o.doc.textBetween(n, r, ""), s = this.editor.state.doc.nodeAt(n);
return s && ((f = (d = (a = s.marks) == null ? void 0 : a.at(0)) == null ? void 0 : d.type) == null ? void 0 : f.name) === "link" ? s.textContent : i;
},
editLink() {
const e = this.getSelectedLinkText(this.editor), t = {
href: this.editor.getAttributes("link").href,
text: e
};
this.$emit("edit-link", t);
},
removeLink() {
var e, t, o, n;
(n = (o = (t = (e = this.editor) == null ? void 0 : e.chain()) == null ? void 0 : t.focus()) == null ? void 0 : o.unsetLink()) == null || n.run();
},
openLink() {
var t, o;
(o = (t = this.editor) == null ? void 0 : t.chain()) == null || o.focus();
const e = this.editor.getAttributes("link").href;
window.open(e, "_blank");
},
// eslint-disable-next-line complexity
setLink(e, t, o, n = K, r) {
var a, d, f;
if (!e) {
this.removeLink();
return;
}
n.find((y) => y.test(e)) || (e = `${r}${e}`), this.editor.chain().focus().extendMarkRange("link").run();
const s = (f = (d = (a = this.editor) == null ? void 0 : a.view) == null ? void 0 : d.state) == null ? void 0 : f.selection;
this.editor.chain().focus().insertContent(t).setTextSelection({ from: s.from, to: s.from + t.length }).setLink({ href: e, class: o.class }).run();
},
// eslint-disable-next-line complexity
processValue(e, t = !0) {
const o = this.getOutput();
if (!(t && Qe(e, o))) {
if (typeof e == "string" && this.outputFormat === "text") {
const n = new RegExp(`(${W})`, "g");
e = e == null ? void 0 : e.replace(n, '<emoji-component code="$1"></emoji-component>');
}
this.editor.commands.setContent(e, !1, { preserveWhitespace: "full" });
}
},
destroyEditor() {
this.editor.destroy();
},
insertPlainTextWithHardBreaks(e, t) {
const { tr: o } = e.state, { from: n, to: r } = e.state.selection;
o.deleteRange(n, r);
const i = t.split(/\r?\n/);
let s = n;
for (let a = 0; a < i.length; a++)
a > 0 && (o.insert(s, e.state.schema.nodes.hardBreak.create()), s++), o.insertText(i[a], s), s += i[a].length;
e.dispatch(o);
},
shouldPreserveLineBreaks(e, t) {
return this.pasteRichText ? !t && e && this.hasBlankLines(e) : !!e;
},
processPasteData(e, t, o) {
if (this.shouldPreserveLineBreaks(t, o))
return this.insertPlainTextWithHardBreaks(e, t), !0;
if (this.shouldHandlePreformattedHTML(o)) {
const n = this.extractPreformattedText(o);
if (n && n.includes(`
`))
return this.insertPlainTextWithHardBreaks(e, n), !0;
}
return !1;
},
shouldHandlePreformattedHTML(e) {
return this.pasteRichText && e && this.containsPreformattedContent(e);
},
containsPreformattedContent(e) {
const t = document.createElement("div");
t.innerHTML = e;
const o = t.querySelectorAll("*");
for (const n of o)
if (this.hasPreWhitespace(n) && this.hasLineBreaks(n))
return !0;
return !1;
},
hasPreWhitespace(e) {
const t = e.getAttribute("style") || "", o = e.style.whiteSpace || "", n = o === "pre" || o === "pre-wrap", r = t.includes("white-space: pre");
return n || r;
},
hasLineBreaks(e) {
return e.textContent && e.textContent.includes(`
`);
},
hasBlankLines(e) {
return e.includes(`
`) || /\n\s*\n/.test(e);
},
extractPreformattedText(e) {
const t = document.createElement("div");
return t.innerHTML = e, this.walkAndExtractText(t);
},
walkAndExtractText(e) {
let t = "";
if (e.nodeType === Node.TEXT_NODE)
t += e.textContent;
else if (e.nodeType === Node.ELEMENT_NODE)
if (this.hasPreWhitespace(e))
t += e.textContent;
else
for (const o of e.childNodes)
t += this.walkAndExtractText(o);
return t;
},
triggerInputChangeEvents() {
const e = this.getOutput();
this.$emit("input", e), this.$emit("update:modelValue", e);
const t = this.editor.getJSON();
this.$emit("json-input", t);
const o = this.editor.getHTML();
this.$emit("html-input", o);
const n = this.editor.getText({ blockSeparator: `
` });
this.$emit("text-input", n);
},
/**
* The Editor exposes event hooks that we have to map our emits into. See
* https://tiptap.dev/api/events for all events.
*/
addEditorListeners() {
this.editor.on("create", () => {
this.triggerInputChangeEvents();
}), this.editor.on("update", () => {
this.triggerInputChangeEvents();
}), this.editor.on("selectionUpdate", ({ editor: e }) => {
this.$emit("selected", this.getSelectedLinkText(e));
}), this.editor.on("focus", ({ event: e }) => {
this.$emit("focus", e);
}), this.editor.on("blur", ({ event: e }) => {
this.$emit("blur", e);
});
},
getOutput() {
switch (this.outputFormat) {
case "json":
return this.editor.getJSON();
case "html":
return this.editor.getHTML();
case "text":
default:
return this.editor.getText({ blockSeparator: `
` });
}
},
getExtension(e, t) {
var o;
return typeof t == "boolean" ? e : (o = e.configure) == null ? void 0 : o.call(e, t);
},
updateEditorAttributes(e) {
this.editor.setOptions({
editorProps: {
attributes: {
...this.inputAttrs,
class: this.inputClass,
...e
}
}
});
},
focusEditor() {
this.editor.commands.focus();
}
}
}, an = { class: "d-popover__dialog" };
function ln(e, t, o, n, r, i) {
const s = c("dt-button"), a = c("dt-stack"), d = c("bubble-menu"), f = c("editor-content");
return l(), _("div", null, [
r.editor && o.link && !o.hideLinkBubbleMenu ? (l(), h(d, {
key: 0,
editor: r.editor,
"should-show": i.bubbleMenuShouldShow,
"tippy-options": r.tippyOptions,
style: { visibility: "visible" }
}, {
default: u(() => [
w("div", an, [
p(a, {
direction: "row",