reactjs-tiptap-editor
Version:
A modern WYSIWYG rich text editor based on tiptap and shadcn ui for React
1,049 lines (1,048 loc) • 39.3 kB
JavaScript
import { M as ve, c as Ne, m as Ft, P as Nt, a as Yt, q as Ie, r as He, s as we, u as xe, v as Me, x as De, T as Ue } from "./index-CXIIg9Sq.js";
import { jsxs as je, jsx as F } from "react/jsx-runtime";
import { useState as Be } from "react";
import { P as ze, m as We, A as Fe, k as Ke, n as Ge, R as Qe } from "./RichTextEditor-iSPxjLdO.js";
const _e = "aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2ntley5rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6logistics9properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3ncaster6d0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2psy3ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0america6xi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2", $e = "ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2", B = (t, n) => {
for (const e in n)
t[e] = n[e];
return t;
}, Kt = "numeric", Gt = "ascii", Qt = "alpha", Q = "asciinumeric", G = "alphanumeric", _t = "domain", pe = "emoji", qe = "scheme", Je = "slashscheme", Dt = "whitespace";
function Ve(t, n) {
return t in n || (n[t] = []), n[t];
}
function D(t, n, e) {
n[Kt] && (n[Q] = !0, n[G] = !0), n[Gt] && (n[Q] = !0, n[Qt] = !0), n[Q] && (n[G] = !0), n[Qt] && (n[G] = !0), n[G] && (n[_t] = !0), n[pe] && (n[_t] = !0);
for (const o in n) {
const s = Ve(o, e);
s.indexOf(t) < 0 && s.push(t);
}
}
function Ye(t, n) {
const e = {};
for (const o in n)
n[o].indexOf(t) >= 0 && (e[o] = !0);
return e;
}
function y(t = null) {
this.j = {}, this.jr = [], this.jd = null, this.t = t;
}
y.groups = {};
y.prototype = {
accepts() {
return !!this.t;
},
/**
* Follow an existing transition from the given input to the next state.
* Does not mutate.
* @param {string} input character or token type to transition on
* @returns {?State<T>} the next state, if any
*/
go(t) {
const n = this, e = n.j[t];
if (e)
return e;
for (let o = 0; o < n.jr.length; o++) {
const s = n.jr[o][0], i = n.jr[o][1];
if (i && s.test(t))
return i;
}
return n.jd;
},
/**
* Whether the state has a transition for the given input. Set the second
* argument to true to only look for an exact match (and not a default or
* regular-expression-based transition)
* @param {string} input
* @param {boolean} exactOnly
*/
has(t, n = !1) {
return n ? t in this.j : !!this.go(t);
},
/**
* Short for "transition all"; create a transition from the array of items
* in the given list to the same final resulting state.
* @param {string | string[]} inputs Group of inputs to transition on
* @param {Transition<T> | State<T>} [next] Transition options
* @param {Flags} [flags] Collections flags to add token to
* @param {Collections<T>} [groups] Master list of token groups
*/
ta(t, n, e, o) {
for (let s = 0; s < t.length; s++)
this.tt(t[s], n, e, o);
},
/**
* Short for "take regexp transition"; defines a transition for this state
* when it encounters a token which matches the given regular expression
* @param {RegExp} regexp Regular expression transition (populate first)
* @param {T | State<T>} [next] Transition options
* @param {Flags} [flags] Collections flags to add token to
* @param {Collections<T>} [groups] Master list of token groups
* @returns {State<T>} taken after the given input
*/
tr(t, n, e, o) {
o = o || y.groups;
let s;
return n && n.j ? s = n : (s = new y(n), e && o && D(n, e, o)), this.jr.push([t, s]), s;
},
/**
* Short for "take transitions", will take as many sequential transitions as
* the length of the given input and returns the
* resulting final state.
* @param {string | string[]} input
* @param {T | State<T>} [next] Transition options
* @param {Flags} [flags] Collections flags to add token to
* @param {Collections<T>} [groups] Master list of token groups
* @returns {State<T>} taken after the given input
*/
ts(t, n, e, o) {
let s = this;
const i = t.length;
if (!i)
return s;
for (let a = 0; a < i - 1; a++)
s = s.tt(t[a]);
return s.tt(t[i - 1], n, e, o);
},
/**
* Short for "take transition", this is a method for building/working with
* state machines.
*
* If a state already exists for the given input, returns it.
*
* If a token is specified, that state will emit that token when reached by
* the linkify engine.
*
* If no state exists, it will be initialized with some default transitions
* that resemble existing default transitions.
*
* If a state is given for the second argument, that state will be
* transitioned to on the given input regardless of what that input
* previously did.
*
* Specify a token group flags to define groups that this token belongs to.
* The token will be added to corresponding entires in the given groups
* object.
*
* @param {string} input character, token type to transition on
* @param {T | State<T>} [next] Transition options
* @param {Flags} [flags] Collections flags to add token to
* @param {Collections<T>} [groups] Master list of groups
* @returns {State<T>} taken after the given input
*/
tt(t, n, e, o) {
o = o || y.groups;
const s = this;
if (n && n.j)
return s.j[t] = n, n;
const i = n;
let a, l = s.go(t);
if (l ? (a = new y(), B(a.j, l.j), a.jr.push.apply(a.jr, l.jr), a.jd = l.jd, a.t = l.t) : a = new y(), i) {
if (o)
if (a.t && typeof a.t == "string") {
const h = B(Ye(a.t, o), e);
D(i, h, o);
} else e && D(i, e, o);
a.t = i;
}
return s.j[t] = a, a;
}
};
const u = (t, n, e, o, s) => t.ta(n, e, o, s), A = (t, n, e, o, s) => t.tr(n, e, o, s), ue = (t, n, e, o, s) => t.ts(n, e, o, s), r = (t, n, e, o, s) => t.tt(n, e, o, s), I = "WORD", $t = "UWORD", Ae = "ASCIINUMERICAL", ke = "ALPHANUMERICAL", Y = "LOCALHOST", qt = "TLD", Jt = "UTLD", ot = "SCHEME", j = "SLASH_SCHEME", Xt = "NUM", Vt = "WS", Zt = "NL", _ = "OPENBRACE", $ = "CLOSEBRACE", st = "OPENBRACKET", it = "CLOSEBRACKET", rt = "OPENPAREN", at = "CLOSEPAREN", lt = "OPENANGLEBRACKET", ct = "CLOSEANGLEBRACKET", ut = "FULLWIDTHLEFTPAREN", dt = "FULLWIDTHRIGHTPAREN", ht = "LEFTCORNERBRACKET", ft = "RIGHTCORNERBRACKET", mt = "LEFTWHITECORNERBRACKET", gt = "RIGHTWHITECORNERBRACKET", Et = "FULLWIDTHLESSTHAN", pt = "FULLWIDTHGREATERTHAN", At = "AMPERSAND", te = "APOSTROPHE", kt = "ASTERISK", w = "AT", Lt = "BACKSLASH", Tt = "BACKTICK", Ct = "CARET", x = "COLON", ee = "COMMA", yt = "DOLLAR", S = "DOT", Rt = "EQUALS", ne = "EXCLAMATION", O = "HYPHEN", q = "PERCENT", bt = "PIPE", Ot = "PLUS", St = "POUND", J = "QUERY", oe = "QUOTE", Le = "FULLWIDTHMIDDLEDOT", se = "SEMI", P = "SLASH", V = "TILDE", Pt = "UNDERSCORE", Te = "EMOJI", vt = "SYM";
var Ce = /* @__PURE__ */ Object.freeze({
__proto__: null,
WORD: I,
UWORD: $t,
ASCIINUMERICAL: Ae,
ALPHANUMERICAL: ke,
LOCALHOST: Y,
TLD: qt,
UTLD: Jt,
SCHEME: ot,
SLASH_SCHEME: j,
NUM: Xt,
WS: Vt,
NL: Zt,
OPENBRACE: _,
CLOSEBRACE: $,
OPENBRACKET: st,
CLOSEBRACKET: it,
OPENPAREN: rt,
CLOSEPAREN: at,
OPENANGLEBRACKET: lt,
CLOSEANGLEBRACKET: ct,
FULLWIDTHLEFTPAREN: ut,
FULLWIDTHRIGHTPAREN: dt,
LEFTCORNERBRACKET: ht,
RIGHTCORNERBRACKET: ft,
LEFTWHITECORNERBRACKET: mt,
RIGHTWHITECORNERBRACKET: gt,
FULLWIDTHLESSTHAN: Et,
FULLWIDTHGREATERTHAN: pt,
AMPERSAND: At,
APOSTROPHE: te,
ASTERISK: kt,
AT: w,
BACKSLASH: Lt,
BACKTICK: Tt,
CARET: Ct,
COLON: x,
COMMA: ee,
DOLLAR: yt,
DOT: S,
EQUALS: Rt,
EXCLAMATION: ne,
HYPHEN: O,
PERCENT: q,
PIPE: bt,
PLUS: Ot,
POUND: St,
QUERY: J,
QUOTE: oe,
FULLWIDTHMIDDLEDOT: Le,
SEMI: se,
SLASH: P,
TILDE: V,
UNDERSCORE: Pt,
EMOJI: Te,
SYM: vt
});
const v = /[a-z]/, K = new RegExp("\\p{L}", "u"), Ut = new RegExp("\\p{Emoji}", "u"), N = /\d/, jt = /\s/, de = "\r", Bt = `
`, Xe = "️", Ze = "", zt = "";
let tt = null, et = null;
function tn(t = []) {
const n = {};
y.groups = n;
const e = new y();
tt == null && (tt = he(_e)), et == null && (et = he($e)), r(e, "'", te), r(e, "{", _), r(e, "}", $), r(e, "[", st), r(e, "]", it), r(e, "(", rt), r(e, ")", at), r(e, "<", lt), r(e, ">", ct), r(e, "(", ut), r(e, ")", dt), r(e, "「", ht), r(e, "」", ft), r(e, "『", mt), r(e, "』", gt), r(e, "<", Et), r(e, ">", pt), r(e, "&", At), r(e, "*", kt), r(e, "@", w), r(e, "`", Tt), r(e, "^", Ct), r(e, ":", x), r(e, ",", ee), r(e, "$", yt), r(e, ".", S), r(e, "=", Rt), r(e, "!", ne), r(e, "-", O), r(e, "%", q), r(e, "|", bt), r(e, "+", Ot), r(e, "#", St), r(e, "?", J), r(e, '"', oe), r(e, "/", P), r(e, ";", se), r(e, "~", V), r(e, "_", Pt), r(e, "\\", Lt), r(e, "・", Le);
const o = A(e, N, Xt, {
[Kt]: !0
});
A(o, N, o);
const s = A(o, v, Ae, {
[Q]: !0
}), i = A(o, K, ke, {
[G]: !0
}), a = A(e, v, I, {
[Gt]: !0
});
A(a, N, s), A(a, v, a), A(s, N, s), A(s, v, s);
const l = A(e, K, $t, {
[Qt]: !0
});
A(l, v), A(l, N, i), A(l, K, l), A(i, N, i), A(i, v), A(i, K, i);
const h = r(e, Bt, Zt, {
[Dt]: !0
}), c = r(e, de, Vt, {
[Dt]: !0
}), f = A(e, jt, Vt, {
[Dt]: !0
});
r(e, zt, f), r(c, Bt, h), r(c, zt, f), A(c, jt, f), r(f, de), r(f, Bt), A(f, jt, f), r(f, zt, f);
const d = A(e, Ut, Te, {
[pe]: !0
});
r(d, "#"), A(d, Ut, d), r(d, Xe, d);
const g = r(d, Ze);
r(g, "#"), A(g, Ut, d);
const p = [[v, a], [N, s]], R = [[v, null], [K, l], [N, i]];
for (let k = 0; k < tt.length; k++)
H(e, tt[k], qt, I, p);
for (let k = 0; k < et.length; k++)
H(e, et[k], Jt, $t, R);
D(qt, {
tld: !0,
ascii: !0
}, n), D(Jt, {
utld: !0,
alpha: !0
}, n), H(e, "file", ot, I, p), H(e, "mailto", ot, I, p), H(e, "http", j, I, p), H(e, "https", j, I, p), H(e, "ftp", j, I, p), H(e, "ftps", j, I, p), D(ot, {
scheme: !0,
ascii: !0
}, n), D(j, {
slashscheme: !0,
ascii: !0
}, n), t = t.sort((k, T) => k[0] > T[0] ? 1 : -1);
for (let k = 0; k < t.length; k++) {
const T = t[k][0], L = t[k][1] ? {
[qe]: !0
} : {
[Je]: !0
};
T.indexOf("-") >= 0 ? L[_t] = !0 : v.test(T) ? N.test(T) ? L[Q] = !0 : L[Gt] = !0 : L[Kt] = !0, ue(e, T, T, L);
}
return ue(e, "localhost", Y, {
ascii: !0
}), e.jd = new y(vt), {
start: e,
tokens: B({
groups: n
}, Ce)
};
}
function ye(t, n) {
const e = en(n.replace(/[A-Z]/g, (l) => l.toLowerCase())), o = e.length, s = [];
let i = 0, a = 0;
for (; a < o; ) {
let l = t, h = null, c = 0, f = null, d = -1, g = -1;
for (; a < o && (h = l.go(e[a])); )
l = h, l.accepts() ? (d = 0, g = 0, f = l) : d >= 0 && (d += e[a].length, g++), c += e[a].length, i += e[a].length, a++;
i -= d, a -= g, c -= d, s.push({
t: f.t,
// token type/name
v: n.slice(i - c, i),
// string value
s: i - c,
// start index
e: i
// end index (excluding)
});
}
return s;
}
function en(t) {
const n = [], e = t.length;
let o = 0;
for (; o < e; ) {
let s = t.charCodeAt(o), i, a = s < 55296 || s > 56319 || o + 1 === e || (i = t.charCodeAt(o + 1)) < 56320 || i > 57343 ? t[o] : t.slice(o, o + 2);
n.push(a), o += a.length;
}
return n;
}
function H(t, n, e, o, s) {
let i;
const a = n.length;
for (let l = 0; l < a - 1; l++) {
const h = n[l];
t.j[h] ? i = t.j[h] : (i = new y(o), i.jr = s.slice(), t.j[h] = i), t = i;
}
return i = new y(e), i.jr = s.slice(), t.j[n[a - 1]] = i, i;
}
function he(t) {
const n = [], e = [];
let o = 0, s = "0123456789";
for (; o < t.length; ) {
let i = 0;
for (; s.indexOf(t[o + i]) >= 0; )
i++;
if (i > 0) {
n.push(e.join(""));
for (let a = parseInt(t.substring(o, o + i), 10); a > 0; a--)
e.pop();
o += i;
} else
e.push(t[o]), o++;
}
return n;
}
const X = {
defaultProtocol: "http",
events: null,
format: fe,
formatHref: fe,
nl2br: !1,
tagName: "a",
target: null,
rel: null,
validate: !0,
truncate: 1 / 0,
className: null,
attributes: null,
ignoreTags: [],
render: null
};
function ie(t, n = null) {
let e = B({}, X);
t && (e = B(e, t instanceof ie ? t.o : t));
const o = e.ignoreTags, s = [];
for (let i = 0; i < o.length; i++)
s.push(o[i].toUpperCase());
this.o = e, n && (this.defaultRender = n), this.ignoreTags = s;
}
ie.prototype = {
o: X,
/**
* @type string[]
*/
ignoreTags: [],
/**
* @param {IntermediateRepresentation} ir
* @returns {any}
*/
defaultRender(t) {
return t;
},
/**
* Returns true or false based on whether a token should be displayed as a
* link based on the user options.
* @param {MultiToken} token
* @returns {boolean}
*/
check(t) {
return this.get("validate", t.toString(), t);
},
// Private methods
/**
* Resolve an option's value based on the value of the option and the given
* params. If operator and token are specified and the target option is
* callable, automatically calls the function with the given argument.
* @template {keyof Opts} K
* @param {K} key Name of option to use
* @param {string} [operator] will be passed to the target option if it's a
* function. If not specified, RAW function value gets returned
* @param {MultiToken} [token] The token from linkify.tokenize
* @returns {Opts[K] | any}
*/
get(t, n, e) {
const o = n != null;
let s = this.o[t];
return s && (typeof s == "object" ? (s = e.t in s ? s[e.t] : X[t], typeof s == "function" && o && (s = s(n, e))) : typeof s == "function" && o && (s = s(n, e.t, e)), s);
},
/**
* @template {keyof Opts} L
* @param {L} key Name of options object to use
* @param {string} [operator]
* @param {MultiToken} [token]
* @returns {Opts[L] | any}
*/
getObj(t, n, e) {
let o = this.o[t];
return typeof o == "function" && n != null && (o = o(n, e.t, e)), o;
},
/**
* Convert the given token to a rendered element that may be added to the
* calling-interface's DOM
* @param {MultiToken} token Token to render to an HTML element
* @returns {any} Render result; e.g., HTML string, DOM element, React
* Component, etc.
*/
render(t) {
const n = t.render(this);
return (this.get("render", null, t) || this.defaultRender)(n, t.t, t);
}
};
function fe(t) {
return t;
}
function Re(t, n) {
this.t = "token", this.v = t, this.tk = n;
}
Re.prototype = {
isLink: !1,
/**
* Return the string this token represents.
* @return {string}
*/
toString() {
return this.v;
},
/**
* What should the value for this token be in the `href` HTML attribute?
* Returns the `.toString` value by default.
* @param {string} [scheme]
* @return {string}
*/
toHref(t) {
return this.toString();
},
/**
* @param {Options} options Formatting options
* @returns {string}
*/
toFormattedString(t) {
const n = this.toString(), e = t.get("truncate", n, this), o = t.get("format", n, this);
return e && o.length > e ? o.substring(0, e) + "…" : o;
},
/**
*
* @param {Options} options
* @returns {string}
*/
toFormattedHref(t) {
return t.get("formatHref", this.toHref(t.get("defaultProtocol")), this);
},
/**
* The start index of this token in the original input string
* @returns {number}
*/
startIndex() {
return this.tk[0].s;
},
/**
* The end index of this token in the original input string (up to this
* index but not including it)
* @returns {number}
*/
endIndex() {
return this.tk[this.tk.length - 1].e;
},
/**
Returns an object of relevant values for this token, which includes keys
* type - Kind of token ('url', 'email', etc.)
* value - Original text
* href - The value that should be added to the anchor tag's href
attribute
@method toObject
@param {string} [protocol] `'http'` by default
*/
toObject(t = X.defaultProtocol) {
return {
type: this.t,
value: this.toString(),
isLink: this.isLink,
href: this.toHref(t),
start: this.startIndex(),
end: this.endIndex()
};
},
/**
*
* @param {Options} options Formatting option
*/
toFormattedObject(t) {
return {
type: this.t,
value: this.toFormattedString(t),
isLink: this.isLink,
href: this.toFormattedHref(t),
start: this.startIndex(),
end: this.endIndex()
};
},
/**
* Whether this token should be rendered as a link according to the given options
* @param {Options} options
* @returns {boolean}
*/
validate(t) {
return t.get("validate", this.toString(), this);
},
/**
* Return an object that represents how this link should be rendered.
* @param {Options} options Formattinng options
*/
render(t) {
const n = this, e = this.toHref(t.get("defaultProtocol")), o = t.get("formatHref", e, this), s = t.get("tagName", e, n), i = this.toFormattedString(t), a = {}, l = t.get("className", e, n), h = t.get("target", e, n), c = t.get("rel", e, n), f = t.getObj("attributes", e, n), d = t.getObj("events", e, n);
return a.href = o, l && (a.class = l), h && (a.target = h), c && (a.rel = c), f && B(a, f), {
tagName: s,
attributes: a,
content: i,
eventListeners: d
};
}
};
function It(t, n) {
class e extends Re {
constructor(s, i) {
super(s, i), this.t = t;
}
}
for (const o in n)
e.prototype[o] = n[o];
return e.t = t, e;
}
const me = It("email", {
isLink: !0,
toHref() {
return "mailto:" + this.toString();
}
}), ge = It("text"), nn = It("nl"), nt = It("url", {
isLink: !0,
/**
Lowercases relevant parts of the domain and adds the protocol if
required. Note that this will not escape unsafe HTML characters in the
URL.
@param {string} [scheme] default scheme (e.g., 'https')
@return {string} the full href
*/
toHref(t = X.defaultProtocol) {
return this.hasProtocol() ? this.v : `${t}://${this.v}`;
},
/**
* Check whether this URL token has a protocol
* @return {boolean}
*/
hasProtocol() {
const t = this.tk;
return t.length >= 2 && t[0].t !== Y && t[1].t === x;
}
}), b = (t) => new y(t);
function on({
groups: t
}) {
const n = t.domain.concat([At, kt, w, Lt, Tt, Ct, yt, Rt, O, Xt, q, bt, Ot, St, P, vt, V, Pt]), e = [x, ee, S, ne, q, J, oe, se, lt, ct, _, $, it, st, rt, at, ut, dt, ht, ft, mt, gt, Et, pt], o = [At, te, kt, Lt, Tt, Ct, yt, Rt, O, _, $, q, bt, Ot, St, J, P, vt, V, Pt], s = b(), i = r(s, V);
u(i, o, i), u(i, t.domain, i);
const a = b(), l = b(), h = b();
u(s, t.domain, a), u(s, t.scheme, l), u(s, t.slashscheme, h), u(a, o, i), u(a, t.domain, a);
const c = r(a, w);
r(i, w, c), r(l, w, c), r(h, w, c);
const f = r(i, S);
u(f, o, i), u(f, t.domain, i);
const d = b();
u(c, t.domain, d), u(d, t.domain, d);
const g = r(d, S);
u(g, t.domain, d);
const p = b(me);
u(g, t.tld, p), u(g, t.utld, p), r(c, Y, p);
const R = r(d, O);
r(R, O, R), u(R, t.domain, d), u(p, t.domain, d), r(p, S, g), r(p, O, R);
const k = r(p, x);
u(k, t.numeric, me);
const T = r(a, O), m = r(a, S);
r(T, O, T), u(T, t.domain, a), u(m, o, i), u(m, t.domain, a);
const L = b(nt);
u(m, t.tld, L), u(m, t.utld, L), u(L, t.domain, a), u(L, o, i), r(L, S, m), r(L, O, T), r(L, w, c);
const Oe = r(L, x), ae = b(nt);
u(Oe, t.numeric, ae);
const C = b(nt), z = b();
u(C, n, C), u(C, e, z), u(z, n, C), u(z, e, z), r(L, P, C), r(ae, P, C);
const Ht = r(l, x), Se = r(h, x), Pe = r(Se, P), wt = r(Pe, P);
u(l, t.domain, a), r(l, S, m), r(l, O, T), u(h, t.domain, a), r(h, S, m), r(h, O, T), u(Ht, t.domain, C), r(Ht, P, C), r(Ht, J, C), u(wt, t.domain, C), u(wt, n, C), r(wt, P, C);
const le = [
[_, $],
// {}
[st, it],
// []
[rt, at],
// ()
[lt, ct],
// <>
[ut, dt],
// ()
[ht, ft],
// 「」
[mt, gt],
// 『』
[Et, pt]
// <>
];
for (let xt = 0; xt < le.length; xt++) {
const [ce, Mt] = le[xt], Z = r(C, ce);
r(z, ce, Z), r(Z, Mt, C);
const U = b(nt);
u(Z, n, U);
const W = b();
u(Z, e), u(U, n, U), u(U, e, W), u(W, n, U), u(W, e, W), r(U, Mt, C), r(W, Mt, C);
}
return r(s, Y, L), r(s, Zt, nn), {
start: s,
tokens: Ce
};
}
function sn(t, n, e) {
let o = e.length, s = 0, i = [], a = [];
for (; s < o; ) {
let l = t, h = null, c = null, f = 0, d = null, g = -1;
for (; s < o && !(h = l.go(e[s].t)); )
a.push(e[s++]);
for (; s < o && (c = h || l.go(e[s].t)); )
h = null, l = c, l.accepts() ? (g = 0, d = l) : g >= 0 && g++, s++, f++;
if (g < 0)
s -= f, s < o && (a.push(e[s]), s++);
else {
a.length > 0 && (i.push(Wt(ge, n, a)), a = []), s -= g, f -= g;
const p = d.t, R = e.slice(s - f, s);
i.push(Wt(p, n, R));
}
}
return a.length > 0 && i.push(Wt(ge, n, a)), i;
}
function Wt(t, n, e) {
const o = e[0].s, s = e[e.length - 1].e, i = n.slice(o, s);
return new t(i, e);
}
const rn = typeof console < "u" && console && console.warn || (() => {
}), an = "until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.", E = {
scanner: null,
parser: null,
tokenQueue: [],
pluginQueue: [],
customSchemes: [],
initialized: !1
};
function ln() {
return y.groups = {}, E.scanner = null, E.parser = null, E.tokenQueue = [], E.pluginQueue = [], E.customSchemes = [], E.initialized = !1, E;
}
function Ee(t, n = !1) {
if (E.initialized && rn(`linkifyjs: already initialized - will not register custom scheme "${t}" ${an}`), !/^[0-9a-z]+(-[0-9a-z]+)*$/.test(t))
throw new Error(`linkifyjs: incorrect scheme format.
1. Must only contain digits, lowercase ASCII letters or "-"
2. Cannot start or end with "-"
3. "-" cannot repeat`);
E.customSchemes.push([t, n]);
}
function cn() {
E.scanner = tn(E.customSchemes);
for (let t = 0; t < E.tokenQueue.length; t++)
E.tokenQueue[t][1]({
scanner: E.scanner
});
E.parser = on(E.scanner.tokens);
for (let t = 0; t < E.pluginQueue.length; t++)
E.pluginQueue[t][1]({
scanner: E.scanner,
parser: E.parser
});
return E.initialized = !0, E;
}
function re(t) {
return E.initialized || cn(), sn(E.parser.start, t, ye(E.scanner.start, t));
}
re.scan = ye;
function be(t, n = null, e = null) {
if (n && typeof n == "object") {
if (e)
throw Error(`linkifyjs: Invalid link type ${n}; must be a string`);
e = n, n = null;
}
const o = new ie(e), s = re(t), i = [];
for (let a = 0; a < s.length; a++) {
const l = s[a];
l.isLink && (!n || l.t === n) && o.check(l) && i.push(l.toFormattedObject(o));
}
return i;
}
function un(t) {
return t.length === 1 ? t[0].isLink : t.length === 3 && t[1].isLink ? ["()", "[]"].includes(t[0].value + t[2].value) : !1;
}
function dn(t) {
return new Nt({
key: new Yt("autolink"),
appendTransaction: (n, e, o) => {
const s = n.some((c) => c.docChanged) && !e.doc.eq(o.doc), i = n.some((c) => c.getMeta("preventAutolink"));
if (!s || i)
return;
const { tr: a } = o, l = Ie(e.doc, [...n]);
if (He(l).forEach(({ newRange: c }) => {
const f = we(o.doc, c, (p) => p.isTextblock);
let d, g;
if (f.length > 1 ? (d = f[0], g = o.doc.textBetween(d.pos, d.pos + d.node.nodeSize, void 0, " ")) : f.length && o.doc.textBetween(c.from, c.to, " ", " ").endsWith(" ") && (d = f[0], g = o.doc.textBetween(d.pos, c.to, void 0, " ")), d && g) {
const p = g.split(" ").filter((m) => m !== "");
if (p.length <= 0)
return !1;
const R = p[p.length - 1], k = d.pos + g.lastIndexOf(R);
if (!R)
return !1;
const T = re(R).map((m) => m.toObject(t.defaultProtocol));
if (!un(T))
return !1;
T.filter((m) => m.isLink).map((m) => ({
...m,
from: k + m.start + 1,
to: k + m.end + 1
})).filter((m) => o.schema.marks.code ? !o.doc.rangeHasMark(m.from, m.to, o.schema.marks.code) : !0).filter((m) => t.validate(m.value)).filter((m) => t.shouldAutoLink(m.value)).forEach((m) => {
xe(m.from, m.to, o.doc).some((L) => L.mark.type === t.type) || a.addMark(m.from, m.to, t.type.create({
href: m.href
}));
});
}
}), !!a.steps.length)
return a;
}
});
}
function hn(t) {
return new Nt({
key: new Yt("handleClickLink"),
props: {
handleClick: (n, e, o) => {
var s, i;
if (o.button !== 0 || !n.editable)
return !1;
let a = o.target;
const l = [];
for (; a.nodeName !== "DIV"; )
l.push(a), a = a.parentNode;
if (!l.find((g) => g.nodeName === "A"))
return !1;
const h = Me(n.state, t.type.name), c = o.target, f = (s = c == null ? void 0 : c.href) !== null && s !== void 0 ? s : h.href, d = (i = c == null ? void 0 : c.target) !== null && i !== void 0 ? i : h.target;
return c && f ? (window.open(f, d), !0) : !1;
}
}
});
}
function fn(t) {
return new Nt({
key: new Yt("handlePasteLink"),
props: {
handlePaste: (n, e, o) => {
const { state: s } = n, { selection: i } = s, { empty: a } = i;
if (a)
return !1;
let l = "";
o.content.forEach((c) => {
l += c.textContent;
});
const h = be(l, { defaultProtocol: t.defaultProtocol }).find((c) => c.isLink && c.value === l);
return !l || !h ? !1 : t.editor.commands.setMark(t.type, {
href: h.href
});
}
}
});
}
const mn = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g;
function M(t, n) {
const e = [
"http",
"https",
"ftp",
"ftps",
"mailto",
"tel",
"callto",
"sms",
"cid",
"xmpp"
];
return n && n.forEach((o) => {
const s = typeof o == "string" ? o : o.scheme;
s && e.push(s);
}), !t || t.replace(mn, "").match(new RegExp(
// eslint-disable-next-line no-useless-escape
`^(?:(?:${e.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,
"i"
));
}
const gn = ve.create({
name: "link",
priority: 1e3,
keepOnSplit: !1,
exitable: !0,
onCreate() {
this.options.validate && !this.options.shouldAutoLink && (this.options.shouldAutoLink = this.options.validate, console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")), this.options.protocols.forEach((t) => {
if (typeof t == "string") {
Ee(t);
return;
}
Ee(t.scheme, t.optionalSlashes);
});
},
onDestroy() {
ln();
},
inclusive() {
return this.options.autolink;
},
addOptions() {
return {
openOnClick: !0,
linkOnPaste: !0,
autolink: !0,
protocols: [],
defaultProtocol: "http",
HTMLAttributes: {
target: "_blank",
rel: "noopener noreferrer nofollow",
class: null
},
isAllowedUri: (t, n) => !!M(t, n.protocols),
validate: (t) => !!t,
shouldAutoLink: (t) => !!t
};
},
addAttributes() {
return {
href: {
default: null,
parseHTML(t) {
return t.getAttribute("href");
}
},
target: {
default: this.options.HTMLAttributes.target
},
rel: {
default: this.options.HTMLAttributes.rel
},
class: {
default: this.options.HTMLAttributes.class
}
};
},
parseHTML() {
return [
{
tag: "a[href]",
getAttrs: (t) => {
const n = t.getAttribute("href");
return !n || !this.options.isAllowedUri(n, {
defaultValidate: (e) => !!M(e, this.options.protocols),
protocols: this.options.protocols,
defaultProtocol: this.options.defaultProtocol
}) ? !1 : null;
}
}
];
},
renderHTML({ HTMLAttributes: t }) {
return this.options.isAllowedUri(t.href, {
defaultValidate: (n) => !!M(n, this.options.protocols),
protocols: this.options.protocols,
defaultProtocol: this.options.defaultProtocol
}) ? ["a", Ft(this.options.HTMLAttributes, t), 0] : [
"a",
Ft(this.options.HTMLAttributes, { ...t, href: "" }),
0
];
},
addCommands() {
return {
setLink: (t) => ({ chain: n }) => {
const { href: e } = t;
return this.options.isAllowedUri(e, {
defaultValidate: (o) => !!M(o, this.options.protocols),
protocols: this.options.protocols,
defaultProtocol: this.options.defaultProtocol
}) ? n().setMark(this.name, t).setMeta("preventAutolink", !0).run() : !1;
},
toggleLink: (t) => ({ chain: n }) => {
const { href: e } = t;
return this.options.isAllowedUri(e, {
defaultValidate: (o) => !!M(o, this.options.protocols),
protocols: this.options.protocols,
defaultProtocol: this.options.defaultProtocol
}) ? n().toggleMark(this.name, t, { extendEmptyMarkRange: !0 }).setMeta("preventAutolink", !0).run() : !1;
},
unsetLink: () => ({ chain: t }) => t().unsetMark(this.name, { extendEmptyMarkRange: !0 }).setMeta("preventAutolink", !0).run()
};
},
addPasteRules() {
return [
Ne({
find: (t) => {
const n = [];
if (t) {
const { protocols: e, defaultProtocol: o } = this.options, s = be(t).filter((i) => i.isLink && this.options.isAllowedUri(i.value, {
defaultValidate: (a) => !!M(a, e),
protocols: e,
defaultProtocol: o
}));
s.length && s.forEach((i) => n.push({
text: i.value,
data: {
href: i.href
},
index: i.start
}));
}
return n;
},
type: this.type,
getAttributes: (t) => {
var n;
return {
href: (n = t.data) === null || n === void 0 ? void 0 : n.href
};
}
})
];
},
addProseMirrorPlugins() {
const t = [], { protocols: n, defaultProtocol: e } = this.options;
return this.options.autolink && t.push(dn({
type: this.type,
defaultProtocol: this.options.defaultProtocol,
validate: (o) => this.options.isAllowedUri(o, {
defaultValidate: (s) => !!M(s, n),
protocols: n,
defaultProtocol: e
}),
shouldAutoLink: this.options.shouldAutoLink
})), this.options.openOnClick === !0 && t.push(hn({
type: this.type
})), this.options.linkOnPaste && t.push(fn({
editor: this.editor,
defaultProtocol: this.options.defaultProtocol,
type: this.type
})), t;
}
});
function En(t) {
const [n, e] = Be(!1);
function o(s, i, a) {
t.action && (t.action({ link: s, text: i, openInNewTab: a }), e(!1));
}
return /* @__PURE__ */ je(ze, { modal: !0, open: n, onOpenChange: e, children: [
/* @__PURE__ */ F(We, { disabled: t == null ? void 0 : t.disabled, asChild: !0, children: /* @__PURE__ */ F(
Fe,
{
tooltip: t == null ? void 0 : t.tooltip,
isActive: t == null ? void 0 : t.isActive,
disabled: t == null ? void 0 : t.disabled,
children: /* @__PURE__ */ F(Ke, { name: t == null ? void 0 : t.icon })
}
) }),
/* @__PURE__ */ F(Ge, { hideWhenDetached: !0, className: "richtext-w-full", align: "start", side: "bottom", children: /* @__PURE__ */ F(Qe, { editor: t.editor, onSetLink: o }) })
] });
}
const Tn = /* @__PURE__ */ gn.extend({
inclusive: !1,
parseHTML() {
return [
{
tag: 'a[href]:not([data-type="button"]):not([href *= "javascript:" i])'
}
];
},
renderHTML({ HTMLAttributes: t }) {
return [
"a",
Ft(this.options.HTMLAttributes, t, {
class: "link"
}),
0
];
},
addOptions() {
var t;
return {
...(t = this.parent) == null ? void 0 : t.call(this),
openOnClick: !0,
button: ({ editor: n, t: e }) => ({
component: En,
componentProps: {
editor: n,
action: (o) => {
const { link: s, text: i, openInNewTab: a } = o;
n.chain().extendMarkRange("link").insertContent({
type: "text",
text: i,
marks: [
{
type: "link",
attrs: {
href: s,
target: a ? "_blank" : ""
}
}
]
}).setLink({ href: s }).focus().run();
},
id: "linkk",
isActive: () => n.isActive("link") || !1,
disabled: !n.can().setLink({ href: "" }),
icon: "Link",
tooltip: e("editor.link.tooltip")
}
})
};
},
addProseMirrorPlugins() {
return [
new Nt({
props: {
handleClick: (t, n) => {
const { schema: e, doc: o, tr: s } = t.state, i = De(o.resolve(n), e.marks.link);
if (!i)
return !1;
const a = o.resolve(i.from), l = o.resolve(i.to), h = s.setSelection(new Ue(a, l));
t.dispatch(h);
}
}
})
];
}
});
export {
Tn as Link
};