UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

1,789 lines (1,788 loc) 50.6 kB
import { NodeViewWrapper as L, nodeViewProps as v, VueRenderer as R, VueNodeViewRenderer as $, EditorContent as G, BubbleMenu as Q, Editor as Z } from "../../node_modules/@tiptap/vue-3.js"; import { Node as ee, mergeAttributes as b, InputRule as te, nodePasteRule as D, 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 U 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 ve from "@tiptap/extension-font-family"; import { PluginKey as T, Plugin as Re } from "@tiptap/pm/state"; import $e from "@tiptap/suggestion"; import { emojiPattern as W } from "regex-combined-emojis"; import { resolveComponent as d, openBlock as l, createBlock as m, withCtx as u, createVNode as f, createElementBlock as _, withDirectives as Me, createElementVNode as w, Fragment as Ie, renderList as Oe, normalizeClass as z, withModifiers as Pe, resolveDynamicComponent as Be, vShow as Ae, createTextVNode as k, toDisplayString as p, markRaw as M, createCommentVNode as x, mergeProps as De } from "vue"; import { _ as g } from "../../_plugin-vue_export-helper-CHgC5LLL.js"; import X from "../emoji/emoji.js"; import { stringToUnicode as je, codeToEmojiData as H, emojiRegex as He, emojiShortCodeRegex as Ne } from "../../common/emoji/index.js"; import { emojisIndexed as Fe } from "@dialpad/dialtone-emojis"; import Ve from "../list-item/list-item.js"; import I from "../stack/stack.js"; import O from "tippy.js"; import { linkRegex as qe, getPhoneNumberRegex as Ke, returnFirstEl as F, warnIfUnmounted as Ue } 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_AUTOFOCUS_TYPES as ze, RICH_TEXT_EDITOR_OUTPUT_FORMATS as Xe, RICH_TEXT_EDITOR_SUPPORTED_LINK_PROTOCOLS as V } 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 Ze from "../button/button.js"; const et = { compatConfig: { MODE: 3 }, name: "EmojiComponent", components: { NodeViewWrapper: L, DtEmoji: X }, props: v }; function tt(e, t, o, n, r, i) { const s = d("dt-emoji"), a = d("node-view-wrapper"); return l(), m(a, { class: "d-d-inline-block d-va-bottom d-lh0" }, { default: u(() => [ f(s, { size: "500", code: e.node.attrs.code }, null, 8, ["code"]) ]), _: 1 }); } const nt = /* @__PURE__ */ g(et, [["render", tt]]), ot = { compatConfig: { MODE: 3 }, name: "SuggestionList", components: { DtListItem: Ve }, 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; } } } }, rt = { class: "d-popover__dialog d-suggestion-list__container" }, it = { ref: "suggestionList", class: "d-suggestion-list" }; function st(e, t, o, n, r, i) { const s = d("dt-list-item"); return l(), _("div", rt, [ Me(w("ul", it, [ (l(!0), _(Ie, null, Oe(o.items, (a, c) => (l(), m(s, { key: a.id, class: z([ "d-suggestion-list__item", { "d-list-item--highlighted": c === r.selectedIndex } ]), "navigation-type": "arrow-keys", onClick: (h) => i.selectItem(c), onKeydown: Pe(i.onKeyDown, ["prevent"]) }, { default: u(() => [ (l(), m(Be(o.itemComponent), { item: a }, null, 8, ["item"])) ]), _: 2 }, 1032, ["class", "onClick", "onKeydown"]))), 128)) ], 512), [ [Ae, o.items.length] ]) ]); } const P = /* @__PURE__ */ g(ot, [["render", st]]), at = { compatConfig: { MODE: 3 }, name: "EmojiSuggestion", components: { DtEmoji: X, DtStack: I }, props: { item: { type: Object, required: !0 } } }; function lt(e, t, o, n, r, i) { const s = d("dt-emoji"), a = d("dt-stack"); return l(), m(a, { direction: "row", gap: "400" }, { default: u(() => [ f(s, { size: "200", code: o.item.code }, null, 8, ["code"]), k(" " + p(o.item.code), 1) ]), _: 1 }); } const ct = /* @__PURE__ */ g(at, [["render", lt]]), B = { 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); } }; } }, dt = 20, ut = { 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, dt).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 R(P, { props: { itemComponent: M(ct), itemType: "emoji", ...n }, editor: n.editor }), n.clientRect && (t = O("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: [B] }), 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; } }; } }, mt = /(:\w+:)$/, ht = new RegExp(W + "$"), ft = (e) => { if (e && H(e[0])) return { text: e[2] || e[0] }; }, pt = (e) => [...e.matchAll(Ne)].filter((o) => H(o[0])).map((o) => ({ index: o.index, text: o[0], match: o })), gt = ee.create({ name: "emoji", addOptions() { return { HTMLAttributes: {} }; }, group: "inline", inline: !0, selectable: !1, atom: !0, addNodeView() { return $(nt); }, addAttributes() { return { code: { default: null } }; }, parseHTML() { return [ { tag: "emoji-component" } ]; }, renderText({ node: e }) { return je(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(mt) || e.match(ht); if (t) return ft(t); }, handler: ({ state: e, range: t, match: o, commands: n, chain: r, can: i }) => { const { tr: s } = e, a = t.from, c = t.to; s.replaceWith(a, c, this.type.create({ code: o[0] })); } }) ]; }, addPasteRules() { return [ D({ find: pt, type: this.type, getAttributes(e) { return { code: e[0] }; } }), D({ find: He, type: this.type, getAttributes(e) { return { code: e[0] }; } }) ]; }, addProseMirrorPlugins() { return [ $e({ char: ":", pluginKey: new T("emoji"), editor: this.editor, ...this.options.suggestion, ...ut }) ]; }, 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 _t(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 yt(e, t) { return !["#", "@"].includes(e.charAt(t.index)) && !["#", "@"].includes(e.charAt(t.index - 1)); } function wt(e) { const t = new RegExp( "(?:" + [ `[!?.,:;'"]`, "(?:&|&amp;)(?:lt|gt|quot|apos|raquo|laquo|rsaquo|lsaquo);)+$" ].join("|"), "g" ); return e.replace(t, ""); } function kt(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 = kt(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 xt(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 q = Ke(1, 15); function K(e, t, o, n, r, i) { if (!e) return; let s = o - t - 1; s = s < 0 ? 0 : s; const a = n - t, c = j( e, s, "left", q ), h = j( e, a, "right", q ), y = e.slice(c.from, h.to); _t(y, qe, yt).forEach((A) => { const C = wt(A[0]), S = t + c.from + A.index + 1, Y = S + C.length; r.addMark(S, Y, i.create()); }); } function bt(e) { let t = !1; return new Re({ 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 || K(a, 0, 0, a.length, s, e.type), t = !0; const c = oe( n.doc, [...o] ); return re(c).forEach(({ oldRange: y, newRange: E }) => { xt(E, r.doc, s, e.type), ie( r.doc, E, (C) => C.isTextblock ).forEach(({ node: C, pos: S }) => { K( C.textContent, S, y.from, E.to, s, e.type ); }); }), s; } }); } const Ct = { class: "d-link d-c-text d-d-inline-block d-wb-break-all", rel: "noopener noreferrer nofollow" }, Tt = se.create({ name: "CustomLink", renderHTML({ HTMLAttributes: e }) { return [ "a", b( this.options.HTMLAttributes, e, Ct ) ]; }, renderText({ node: e }) { return e.attrs.text; }, addProseMirrorPlugins() { return [ bt({ type: this.type }) ]; } }), Et = 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 }), St = U.extend({ parseHTML() { return [{ tag: "div" }]; }, renderHTML({ HTMLAttributes: e }) { return ["div", b(this.options.HTMLAttributes, e), 0]; } }), Lt = { compatConfig: { MODE: 3 }, name: "MentionComponent", components: { NodeViewWrapper: L, DtLink: J }, props: v, computed: { text() { return "@" + this.$props.node.attrs.name; } } }; function vt(e, t, o, n, r, i) { const s = d("dt-link"), a = d("node-view-wrapper"); return l(), m(a, { class: "d-d-inline-block" }, { default: u(() => [ f(s, { kind: "mention" }, { default: u(() => [ k(p(i.text), 1) ]), _: 1 }) ]), _: 1 }); } const Rt = /* @__PURE__ */ g(Lt, [["render", vt]]), $t = N.extend({ addNodeView() { return $(Rt); }, 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") } }), Mt = { compatConfig: { MODE: 3 }, name: "ChannelComponent", components: { NodeViewWrapper: L, DtLink: J }, props: v, computed: { text() { return "#" + this.$props.node.attrs.name; } } }; function It(e, t, o, n, r, i) { const s = d("dt-link"), a = d("node-view-wrapper"); return l(), m(a, { class: "d-d-inline-block" }, { default: u(() => [ f(s, { kind: "mention" }, { default: u(() => [ k(p(i.text), 1) ]), _: 1 }) ]), _: 1 }); } const Ot = /* @__PURE__ */ g(Mt, [["render", It]]), Pt = N.extend({ name: "channel", addNodeView() { return $(Ot); }, 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") } }), Bt = { compatConfig: { MODE: 3 }, name: "SlashCommandsComponent", components: { NodeViewWrapper: L }, props: v, emits: ["selected-command"], computed: { text() { return "/" + this.$props.node.attrs.command; } }, created() { this.$parent.$emit("selected-command", this.$props.node.attrs.command); } }; function At(e, t, o, n, r, i) { const s = d("node-view-wrapper"); return l(), m(s, { class: "d-d-inline-block" }, { default: u(() => [ k(p(i.text), 1) ]), _: 1 }); } const Dt = /* @__PURE__ */ g(Bt, [["render", At]]), jt = (e, t) => [...e.matchAll(t)].map((n) => { let r = n[2]; return r.endsWith(" ") || (r += " "), { index: n.index, text: r, match: n }; }), Ht = N.extend({ name: "slash-commands", group: "inline", inline: !0, addNodeView() { return $(Dt); }, 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 [ D({ find: (n) => jt(n, t), type: this.type, getAttributes(n) { return { command: n[0].trim() }; } }) ]; } }).configure({ suggestion: { char: "/", pluginKey: new T("slashCommandSuggestion") } }), Nt = { compatConfig: { MODE: 3 }, name: "MentionSuggestion", components: { DtAvatar: Je, DtStack: I }, 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; } } }, Ft = { class: "d-mention-suggestion__name" }, Vt = { key: 1, class: "d-mention-suggestion__divider" }, qt = { key: 2, class: "d-mention-suggestion__status" }; function Kt(e, t, o, n, r, i) { const s = d("dt-avatar"), a = d("dt-stack"); return l(), m(a, { direction: "row", class: "d-mention-suggestion__container", gap: "400" }, { default: u(() => [ f(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"]), f(a, { class: "d-mention-suggestion__details-container", gap: "100" }, { default: u(() => [ w("span", Ft, p(i.name), 1), i.showDetails ? (l(), m(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]]) }, p(i.presenceText), 3)) : x("", !0), i.status && i.presenceText ? (l(), _("div", Vt, " • ")) : x("", !0), i.status ? (l(), _("div", qt, p(i.status), 1)) : x("", !0) ]), _: 1 })) : x("", !0) ]), _: 1 }) ]), _: 1 }); } const Ut = /* @__PURE__ */ g(Nt, [["render", Kt]]), Wt = { // 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 R(P, { props: { itemComponent: M(Ut), itemType: "mention", ...n }, editor: n.editor }), n.clientRect && (t = O("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: [B] }), 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; } }; } }, zt = { compatConfig: { MODE: 3 }, name: "ChannelSuggestion", components: { DtStack: I, DtIconHash: Ye, DtIconLock: Ge }, props: { item: { type: Object, required: !0 } }, computed: { name() { return this.item.name; } } }; function Xt(e, t, o, n, r, i) { const s = d("dt-icon-hash"), a = d("dt-icon-lock"), c = d("dt-stack"); return l(), m(c, { direction: "row", gap: "400" }, { default: u(() => [ o.item.locked ? (l(), m(a, { key: 1, size: "300" })) : (l(), m(s, { key: 0, size: "300" })), w("span", null, p(i.name), 1) ]), _: 1 }); } const Jt = /* @__PURE__ */ g(zt, [["render", Xt]]), Yt = { // 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 R(P, { props: { itemComponent: M(Jt), itemType: "channel", ...n }, editor: n.editor }), n.clientRect && (t = O("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: [B] }), 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; } }; } }, Gt = { 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; } } }, Qt = { class: "d-body--md-compact" }, Zt = { key: 0 }, en = { class: "d-body--sm d-fc-tertiary" }; function tn(e, t, o, n, r, i) { return l(), _("div", null, [ w("div", Qt, [ w("span", null, "/" + p(i.command), 1), i.parametersExample ? (l(), _("span", Zt, p(i.parametersExample), 1)) : x("", !0) ]), w("div", en, p(i.description), 1) ]); } const nn = /* @__PURE__ */ g(Gt, [["render", tn]]), on = { // 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 R(P, { parent: void 0, props: { itemComponent: M(nn), itemType: "slash-command", ...n }, editor: n.editor }), n.clientRect && (t = O("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: [B] }), 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; } }; } }, rn = { compatConfig: { MODE: 3 }, name: "DtRichTextEditor", components: { EditorContent: G, BubbleMenu: Q, DtButton: Ze, DtStack: I }, 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" ? ze.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 Xe.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" ], 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" } }; }, computed: { attrs() { return { ...this.$attrs, onInput: () => { }, onFocus: () => { }, onBlur: () => { } }; }, // eslint-disable-next-line complexity extensions() { const e = [me, Ce, Ee, he]; e.push(this.useDivTags ? St : U), this.allowBlockquote && e.push(ce), this.allowBold && e.push(pe), 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 }).configure({ HTMLAttributes: { class: "d-link d-wb-break-all" }, openOnClick: !1, autolink: !0, protocols: V })), this.customLink && e.push(this.getExtension(Tt, this.customLink)), this.mentionSuggestion) { const n = { ...this.mentionSuggestion, ...Wt }; e.push($t.configure({ suggestion: n })); } if (this.channelSuggestion) { const n = { ...this.channelSuggestion, ...Yt }; e.push(Pt.configure({ suggestion: n })); } if (this.slashCommandSuggestion) { const n = { ...this.slashCommandSuggestion, ...on }; e.push(Ht.configure({ suggestion: n })); } return e.push(gt), 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(Et), (this.allowFontFamily || this.allowFontColor) && (e.push(Se), this.allowFontColor && e.push(Le), this.allowFontFamily && e.push(ve)), 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() { Ue(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 }, handlePaste: (e, t, o) => { const n = t.clipboardData || window.clipboardData, r = n.getData("text/plain"), i = n.getData("text/html"); return this.processPasteData(e, r, i); }, // 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, view: t, state: o, oldState: n, from: r, to: i }) { 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, c, h; 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 && ((h = (c = (a = s.marks) == null ? void 0 : a.at(0)) == null ? void 0 : c.type) == null ? void 0 : h.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 = V, r) { var a, c, h; if (!e) { this.removeLink(); return; } n.find((y) => y.test(e)) || (e = `${r}${e}`), this.editor.chain().focus().extendMarkRange("link").run(); const s = (h = (c = (a = this.editor) == null ? void 0 : a.view) == null ? void 0 : c.state) == null ? void 0 : h.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", () => { var e, t; if (this.preventTyping && ((t = (e = this.editor.view) == null ? void 0 : e.input) == null ? void 0 : t.lastKeyCode) !== 8) { this.editor.commands.setContent(this.modelValue, !1); return; } 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(); } } }, sn = { class: "d-popover__dialog" }; function an(e, t, o, n, r, i) { const s = d("dt-button"), a = d("dt-stack"), c = d("bubble-menu"), h = d("editor-content"); return l(), _("div", null, [ r.editor && o.link && !o.hideLinkBubbleMenu ? (l(), m(c, { key: 0, editor: r.editor, "should-show": i.bubbleMenuShouldShow, "tippy-options": r.tippyOptions, style: { visibility: "visible" } }, { default: u(() => [ w("div", sn, [ f(a, { direction: "row", class: "d-rich-text-editor-bubble-menu__button-stack", gap: "0" }, { default: u(() => [ f(s, { kind: "muted", importance: "clear", onClick: i.editLink }, { default: u(() => [ k(" Edit ") ]), _: 1 }, 8, ["onClick"]), f(s, { kind: "muted", importance: "clear", onClick: i.openLink }, { default: u(() => [ k(" Open link ") ]), _: 1 }, 8, ["onClick"]), f(s, { kind: "danger", importance: "clear", onClick: i.removeLink }, { default: u((