@youcan/celeste 0.6.30 → 0.6.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/celeste.css +483 -264
  2. package/dist/cjs/alert.js +2 -2
  3. package/dist/cjs/chunks/index.js +229 -2
  4. package/dist/cjs/chunks/index2.js +1457 -0
  5. package/dist/cjs/chunks/index3.js +16457 -0
  6. package/dist/cjs/chunks/sonner.js +1154 -0
  7. package/dist/cjs/config.js +136 -0
  8. package/dist/cjs/extra-settings.js +155 -0
  9. package/dist/cjs/index.js +75 -0
  10. package/dist/cjs/label.js +2 -2
  11. package/dist/cjs/link-bubble.js +228 -0
  12. package/dist/cjs/link-button.js +2 -2
  13. package/dist/cjs/rich-editor.js +4996 -0
  14. package/dist/cjs/select-icon.js +2 -2
  15. package/dist/cjs/sonner-alert.js +41 -0
  16. package/dist/cjs/sonner.js +3 -0
  17. package/dist/cjs/text-input-affix.js +2 -2
  18. package/dist/cjs/types.js +1 -0
  19. package/dist/components/index.d.ts +2 -0
  20. package/dist/components/rich-editor/config.d.ts +33 -0
  21. package/dist/components/rich-editor/extra-settings.d.ts +6 -0
  22. package/dist/components/rich-editor/index.d.ts +2 -0
  23. package/dist/components/rich-editor/link-bubble.d.ts +11 -0
  24. package/dist/components/rich-editor/rich-editor.d.ts +55 -0
  25. package/dist/components/rich-editor/types.d.ts +19 -0
  26. package/dist/components/sonner/index.d.ts +4 -0
  27. package/dist/components/sonner/sonner-alert.d.ts +13 -0
  28. package/dist/components/sonner/sonner.d.ts +5 -0
  29. package/dist/es/alert.js +2 -2
  30. package/dist/es/checkbox-label.js +1 -1
  31. package/dist/es/chunks/index.js +277 -50
  32. package/dist/es/chunks/index2.js +1457 -0
  33. package/dist/es/chunks/index3.js +16458 -0
  34. package/dist/es/chunks/sonner.js +1155 -0
  35. package/dist/es/combobox-group.js +1 -1
  36. package/dist/es/combobox-input.js +1 -1
  37. package/dist/es/combobox-item.js +1 -1
  38. package/dist/es/combobox-list.js +1 -1
  39. package/dist/es/combobox-root.js +1 -1
  40. package/dist/es/combobox-separator.js +1 -1
  41. package/dist/es/combobox-trigger.js +1 -1
  42. package/dist/es/command-group.js +1 -1
  43. package/dist/es/command-input.js +1 -1
  44. package/dist/es/command-item.js +1 -1
  45. package/dist/es/command-list.js +1 -1
  46. package/dist/es/command-root.js +1 -1
  47. package/dist/es/command-separator.js +1 -1
  48. package/dist/es/config.js +136 -0
  49. package/dist/es/dropdown-menu-group.js +1 -1
  50. package/dist/es/dropdown-menu-item.js +1 -1
  51. package/dist/es/dropdown-menu-label.js +1 -1
  52. package/dist/es/dropdown-menu-separator.js +1 -1
  53. package/dist/es/dropdown-menu-trigger.js +1 -1
  54. package/dist/es/dropdown-menu.js +1 -1
  55. package/dist/es/dropdown.js +1 -1
  56. package/dist/es/extra-settings.js +156 -0
  57. package/dist/es/index.js +94 -19
  58. package/dist/es/label.js +3 -3
  59. package/dist/es/link-bubble.js +229 -0
  60. package/dist/es/link-button.js +2 -2
  61. package/dist/es/modal-content.js +1 -1
  62. package/dist/es/modal-header.js +1 -1
  63. package/dist/es/popover-content.js +1 -1
  64. package/dist/es/popover-trigger.js +1 -1
  65. package/dist/es/rich-editor.js +4997 -0
  66. package/dist/es/scroll-bar.js +1 -1
  67. package/dist/es/segmented-control-item.js +1 -1
  68. package/dist/es/segmented-control.js +1 -1
  69. package/dist/es/select-content.js +1 -1
  70. package/dist/es/select-icon.js +2 -2
  71. package/dist/es/select-item.js +1 -1
  72. package/dist/es/select-trigger.js +1 -1
  73. package/dist/es/select-value.js +1 -1
  74. package/dist/es/sonner-alert.js +42 -0
  75. package/dist/es/sonner.js +4 -0
  76. package/dist/es/tab-menu-content.js +1 -1
  77. package/dist/es/tab-menu-item.js +1 -1
  78. package/dist/es/tab-menu-list.js +1 -1
  79. package/dist/es/tab-menu.js +1 -1
  80. package/dist/es/text-input-affix.js +2 -2
  81. package/dist/es/tooltip.js +1 -1
  82. package/dist/es/types.js +1 -0
  83. package/dist/index.d.ts +1 -0
  84. package/dist/utils/index.d.ts +3 -0
  85. package/dist/utils/sonner.d.ts +19 -0
  86. package/package.json +15 -4
  87. package/src/components/index.ts +2 -0
  88. package/src/components/rich-editor/config.ts +150 -0
  89. package/src/components/rich-editor/extra-settings.vue +151 -0
  90. package/src/components/rich-editor/index.ts +2 -0
  91. package/src/components/rich-editor/link-bubble.vue +288 -0
  92. package/src/components/rich-editor/rich-editor.vue +428 -0
  93. package/src/components/rich-editor/stories/rich-editor.stories.ts +87 -0
  94. package/src/components/rich-editor/types.ts +21 -0
  95. package/src/components/sonner/index.ts +5 -0
  96. package/src/components/sonner/sonner-alert.vue +54 -0
  97. package/src/components/sonner/sonner.vue +13 -0
  98. package/src/components/sonner/stories/sonner.stories.ts +194 -0
  99. package/src/index.ts +1 -0
  100. package/src/utils/index.ts +3 -0
  101. package/src/utils/sonner.ts +72 -0
@@ -0,0 +1,4997 @@
1
+ import { markRaw, defineComponent, ref, getCurrentInstance, watchEffect, nextTick, unref, onBeforeUnmount, h as h$1, customRef, computed, watch, onMounted, openBlock, createElementBlock, createElementVNode, Fragment as Fragment$1, renderList, createBlock, withCtx, createVNode, normalizeClass, normalizeStyle, toDisplayString, createCommentVNode } from "vue";
2
+ import CompactButton from "./compact-button.js";
3
+ import SelectContent from "./select-content.js";
4
+ import SelectIcon from "./select-icon.js";
5
+ import SelectItem from "./select-item.js";
6
+ import SelectTrigger from "./select-trigger.js";
7
+ import SelectValue from "./select-value.js";
8
+ import { _ as _sfc_main$1 } from "./chunks/select.js";
9
+ import Tooltip from "./tooltip.js";
10
+ import { M as Mark, m as mergeAttributes, e as markPasteRule, c as Plugin, P as PluginKey, f as combineTransactionSteps, h as getChangedRanges, j as findChildrenInRange, l as getMarksBetween, n as getAttributes, E as Extension, o as dropPoint, S as Selection, k as keydownHandler, N as NodeSelection, F as Fragment, b as Slice, T as TextSelection, D as DecorationSet, q as Decoration, r as Mapping, s as callOrReturn, t as getExtensionField, u as isNodeEmpty, v as isNodeSelection, w as Node3, x as wrappingInputRule, y as markInputRule, z as textblockTypeInputRule, A as canInsertNode, B as nodeInputRule, C as getNodeType, G as getNodeAtPosition, H as isNodeActive, I as isAtStartOfNode, J as isAtEndOfNode, K as Editor$1 } from "./chunks/index3.js";
11
+ import { fullToolbar, onActionClick, selectedOption } from "./config.js";
12
+ import ExtraSettings from "./extra-settings.js";
13
+ import LinkBubble from "./link-bubble.js";
14
+ import { _ as _export_sfc } from "./chunks/_plugin-vue_export-helper.js";
15
+ const encodedTlds = "aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0america6xi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2";
16
+ const encodedUtlds = "ελ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";
17
+ const assign = (target, properties) => {
18
+ for (const key in properties) {
19
+ target[key] = properties[key];
20
+ }
21
+ return target;
22
+ };
23
+ const numeric = "numeric";
24
+ const ascii = "ascii";
25
+ const alpha = "alpha";
26
+ const asciinumeric = "asciinumeric";
27
+ const alphanumeric = "alphanumeric";
28
+ const domain = "domain";
29
+ const emoji = "emoji";
30
+ const scheme = "scheme";
31
+ const slashscheme = "slashscheme";
32
+ const whitespace = "whitespace";
33
+ function registerGroup(name, groups) {
34
+ if (!(name in groups)) {
35
+ groups[name] = [];
36
+ }
37
+ return groups[name];
38
+ }
39
+ function addToGroups(t, flags, groups) {
40
+ if (flags[numeric]) {
41
+ flags[asciinumeric] = true;
42
+ flags[alphanumeric] = true;
43
+ }
44
+ if (flags[ascii]) {
45
+ flags[asciinumeric] = true;
46
+ flags[alpha] = true;
47
+ }
48
+ if (flags[asciinumeric]) {
49
+ flags[alphanumeric] = true;
50
+ }
51
+ if (flags[alpha]) {
52
+ flags[alphanumeric] = true;
53
+ }
54
+ if (flags[alphanumeric]) {
55
+ flags[domain] = true;
56
+ }
57
+ if (flags[emoji]) {
58
+ flags[domain] = true;
59
+ }
60
+ for (const k in flags) {
61
+ const group = registerGroup(k, groups);
62
+ if (group.indexOf(t) < 0) {
63
+ group.push(t);
64
+ }
65
+ }
66
+ }
67
+ function flagsForToken(t, groups) {
68
+ const result = {};
69
+ for (const c in groups) {
70
+ if (groups[c].indexOf(t) >= 0) {
71
+ result[c] = true;
72
+ }
73
+ }
74
+ return result;
75
+ }
76
+ function State(token = null) {
77
+ this.j = {};
78
+ this.jr = [];
79
+ this.jd = null;
80
+ this.t = token;
81
+ }
82
+ State.groups = {};
83
+ State.prototype = {
84
+ accepts() {
85
+ return !!this.t;
86
+ },
87
+ /**
88
+ * Follow an existing transition from the given input to the next state.
89
+ * Does not mutate.
90
+ * @param {string} input character or token type to transition on
91
+ * @returns {?State<T>} the next state, if any
92
+ */
93
+ go(input) {
94
+ const state = this;
95
+ const nextState = state.j[input];
96
+ if (nextState) {
97
+ return nextState;
98
+ }
99
+ for (let i = 0; i < state.jr.length; i++) {
100
+ const regex = state.jr[i][0];
101
+ const nextState2 = state.jr[i][1];
102
+ if (nextState2 && regex.test(input)) {
103
+ return nextState2;
104
+ }
105
+ }
106
+ return state.jd;
107
+ },
108
+ /**
109
+ * Whether the state has a transition for the given input. Set the second
110
+ * argument to true to only look for an exact match (and not a default or
111
+ * regular-expression-based transition)
112
+ * @param {string} input
113
+ * @param {boolean} exactOnly
114
+ */
115
+ has(input, exactOnly = false) {
116
+ return exactOnly ? input in this.j : !!this.go(input);
117
+ },
118
+ /**
119
+ * Short for "transition all"; create a transition from the array of items
120
+ * in the given list to the same final resulting state.
121
+ * @param {string | string[]} inputs Group of inputs to transition on
122
+ * @param {Transition<T> | State<T>} [next] Transition options
123
+ * @param {Flags} [flags] Collections flags to add token to
124
+ * @param {Collections<T>} [groups] Master list of token groups
125
+ */
126
+ ta(inputs, next, flags, groups) {
127
+ for (let i = 0; i < inputs.length; i++) {
128
+ this.tt(inputs[i], next, flags, groups);
129
+ }
130
+ },
131
+ /**
132
+ * Short for "take regexp transition"; defines a transition for this state
133
+ * when it encounters a token which matches the given regular expression
134
+ * @param {RegExp} regexp Regular expression transition (populate first)
135
+ * @param {T | State<T>} [next] Transition options
136
+ * @param {Flags} [flags] Collections flags to add token to
137
+ * @param {Collections<T>} [groups] Master list of token groups
138
+ * @returns {State<T>} taken after the given input
139
+ */
140
+ tr(regexp, next, flags, groups) {
141
+ groups = groups || State.groups;
142
+ let nextState;
143
+ if (next && next.j) {
144
+ nextState = next;
145
+ } else {
146
+ nextState = new State(next);
147
+ if (flags && groups) {
148
+ addToGroups(next, flags, groups);
149
+ }
150
+ }
151
+ this.jr.push([regexp, nextState]);
152
+ return nextState;
153
+ },
154
+ /**
155
+ * Short for "take transitions", will take as many sequential transitions as
156
+ * the length of the given input and returns the
157
+ * resulting final state.
158
+ * @param {string | string[]} input
159
+ * @param {T | State<T>} [next] Transition options
160
+ * @param {Flags} [flags] Collections flags to add token to
161
+ * @param {Collections<T>} [groups] Master list of token groups
162
+ * @returns {State<T>} taken after the given input
163
+ */
164
+ ts(input, next, flags, groups) {
165
+ let state = this;
166
+ const len = input.length;
167
+ if (!len) {
168
+ return state;
169
+ }
170
+ for (let i = 0; i < len - 1; i++) {
171
+ state = state.tt(input[i]);
172
+ }
173
+ return state.tt(input[len - 1], next, flags, groups);
174
+ },
175
+ /**
176
+ * Short for "take transition", this is a method for building/working with
177
+ * state machines.
178
+ *
179
+ * If a state already exists for the given input, returns it.
180
+ *
181
+ * If a token is specified, that state will emit that token when reached by
182
+ * the linkify engine.
183
+ *
184
+ * If no state exists, it will be initialized with some default transitions
185
+ * that resemble existing default transitions.
186
+ *
187
+ * If a state is given for the second argument, that state will be
188
+ * transitioned to on the given input regardless of what that input
189
+ * previously did.
190
+ *
191
+ * Specify a token group flags to define groups that this token belongs to.
192
+ * The token will be added to corresponding entires in the given groups
193
+ * object.
194
+ *
195
+ * @param {string} input character, token type to transition on
196
+ * @param {T | State<T>} [next] Transition options
197
+ * @param {Flags} [flags] Collections flags to add token to
198
+ * @param {Collections<T>} [groups] Master list of groups
199
+ * @returns {State<T>} taken after the given input
200
+ */
201
+ tt(input, next, flags, groups) {
202
+ groups = groups || State.groups;
203
+ const state = this;
204
+ if (next && next.j) {
205
+ state.j[input] = next;
206
+ return next;
207
+ }
208
+ const t = next;
209
+ let nextState, templateState = state.go(input);
210
+ if (templateState) {
211
+ nextState = new State();
212
+ assign(nextState.j, templateState.j);
213
+ nextState.jr.push.apply(nextState.jr, templateState.jr);
214
+ nextState.jd = templateState.jd;
215
+ nextState.t = templateState.t;
216
+ } else {
217
+ nextState = new State();
218
+ }
219
+ if (t) {
220
+ if (groups) {
221
+ if (nextState.t && typeof nextState.t === "string") {
222
+ const allFlags = assign(flagsForToken(nextState.t, groups), flags);
223
+ addToGroups(t, allFlags, groups);
224
+ } else if (flags) {
225
+ addToGroups(t, flags, groups);
226
+ }
227
+ }
228
+ nextState.t = t;
229
+ }
230
+ state.j[input] = nextState;
231
+ return nextState;
232
+ }
233
+ };
234
+ const ta = (state, input, next, flags, groups) => state.ta(input, next, flags, groups);
235
+ const tr = (state, regexp, next, flags, groups) => state.tr(regexp, next, flags, groups);
236
+ const ts = (state, input, next, flags, groups) => state.ts(input, next, flags, groups);
237
+ const tt = (state, input, next, flags, groups) => state.tt(input, next, flags, groups);
238
+ const WORD = "WORD";
239
+ const UWORD = "UWORD";
240
+ const ASCIINUMERICAL = "ASCIINUMERICAL";
241
+ const ALPHANUMERICAL = "ALPHANUMERICAL";
242
+ const LOCALHOST = "LOCALHOST";
243
+ const TLD = "TLD";
244
+ const UTLD = "UTLD";
245
+ const SCHEME = "SCHEME";
246
+ const SLASH_SCHEME = "SLASH_SCHEME";
247
+ const NUM = "NUM";
248
+ const WS = "WS";
249
+ const NL = "NL";
250
+ const OPENBRACE = "OPENBRACE";
251
+ const CLOSEBRACE = "CLOSEBRACE";
252
+ const OPENBRACKET = "OPENBRACKET";
253
+ const CLOSEBRACKET = "CLOSEBRACKET";
254
+ const OPENPAREN = "OPENPAREN";
255
+ const CLOSEPAREN = "CLOSEPAREN";
256
+ const OPENANGLEBRACKET = "OPENANGLEBRACKET";
257
+ const CLOSEANGLEBRACKET = "CLOSEANGLEBRACKET";
258
+ const FULLWIDTHLEFTPAREN = "FULLWIDTHLEFTPAREN";
259
+ const FULLWIDTHRIGHTPAREN = "FULLWIDTHRIGHTPAREN";
260
+ const LEFTCORNERBRACKET = "LEFTCORNERBRACKET";
261
+ const RIGHTCORNERBRACKET = "RIGHTCORNERBRACKET";
262
+ const LEFTWHITECORNERBRACKET = "LEFTWHITECORNERBRACKET";
263
+ const RIGHTWHITECORNERBRACKET = "RIGHTWHITECORNERBRACKET";
264
+ const FULLWIDTHLESSTHAN = "FULLWIDTHLESSTHAN";
265
+ const FULLWIDTHGREATERTHAN = "FULLWIDTHGREATERTHAN";
266
+ const AMPERSAND = "AMPERSAND";
267
+ const APOSTROPHE = "APOSTROPHE";
268
+ const ASTERISK = "ASTERISK";
269
+ const AT = "AT";
270
+ const BACKSLASH = "BACKSLASH";
271
+ const BACKTICK = "BACKTICK";
272
+ const CARET = "CARET";
273
+ const COLON = "COLON";
274
+ const COMMA = "COMMA";
275
+ const DOLLAR = "DOLLAR";
276
+ const DOT = "DOT";
277
+ const EQUALS = "EQUALS";
278
+ const EXCLAMATION = "EXCLAMATION";
279
+ const HYPHEN = "HYPHEN";
280
+ const PERCENT = "PERCENT";
281
+ const PIPE = "PIPE";
282
+ const PLUS = "PLUS";
283
+ const POUND = "POUND";
284
+ const QUERY = "QUERY";
285
+ const QUOTE = "QUOTE";
286
+ const FULLWIDTHMIDDLEDOT = "FULLWIDTHMIDDLEDOT";
287
+ const SEMI = "SEMI";
288
+ const SLASH = "SLASH";
289
+ const TILDE = "TILDE";
290
+ const UNDERSCORE = "UNDERSCORE";
291
+ const EMOJI$1 = "EMOJI";
292
+ const SYM = "SYM";
293
+ var tk = /* @__PURE__ */ Object.freeze({
294
+ __proto__: null,
295
+ ALPHANUMERICAL,
296
+ AMPERSAND,
297
+ APOSTROPHE,
298
+ ASCIINUMERICAL,
299
+ ASTERISK,
300
+ AT,
301
+ BACKSLASH,
302
+ BACKTICK,
303
+ CARET,
304
+ CLOSEANGLEBRACKET,
305
+ CLOSEBRACE,
306
+ CLOSEBRACKET,
307
+ CLOSEPAREN,
308
+ COLON,
309
+ COMMA,
310
+ DOLLAR,
311
+ DOT,
312
+ EMOJI: EMOJI$1,
313
+ EQUALS,
314
+ EXCLAMATION,
315
+ FULLWIDTHGREATERTHAN,
316
+ FULLWIDTHLEFTPAREN,
317
+ FULLWIDTHLESSTHAN,
318
+ FULLWIDTHMIDDLEDOT,
319
+ FULLWIDTHRIGHTPAREN,
320
+ HYPHEN,
321
+ LEFTCORNERBRACKET,
322
+ LEFTWHITECORNERBRACKET,
323
+ LOCALHOST,
324
+ NL,
325
+ NUM,
326
+ OPENANGLEBRACKET,
327
+ OPENBRACE,
328
+ OPENBRACKET,
329
+ OPENPAREN,
330
+ PERCENT,
331
+ PIPE,
332
+ PLUS,
333
+ POUND,
334
+ QUERY,
335
+ QUOTE,
336
+ RIGHTCORNERBRACKET,
337
+ RIGHTWHITECORNERBRACKET,
338
+ SCHEME,
339
+ SEMI,
340
+ SLASH,
341
+ SLASH_SCHEME,
342
+ SYM,
343
+ TILDE,
344
+ TLD,
345
+ UNDERSCORE,
346
+ UTLD,
347
+ UWORD,
348
+ WORD,
349
+ WS
350
+ });
351
+ const ASCII_LETTER = /[a-z]/;
352
+ const LETTER = new RegExp("\\p{L}", "u");
353
+ const EMOJI = new RegExp("\\p{Emoji}", "u");
354
+ const DIGIT = /\d/;
355
+ const SPACE = /\s/;
356
+ const CR = "\r";
357
+ const LF = "\n";
358
+ const EMOJI_VARIATION = "️";
359
+ const EMOJI_JOINER = "‍";
360
+ const OBJECT_REPLACEMENT = "";
361
+ let tlds = null, utlds = null;
362
+ function init$2(customSchemes = []) {
363
+ const groups = {};
364
+ State.groups = groups;
365
+ const Start = new State();
366
+ if (tlds == null) {
367
+ tlds = decodeTlds(encodedTlds);
368
+ }
369
+ if (utlds == null) {
370
+ utlds = decodeTlds(encodedUtlds);
371
+ }
372
+ tt(Start, "'", APOSTROPHE);
373
+ tt(Start, "{", OPENBRACE);
374
+ tt(Start, "}", CLOSEBRACE);
375
+ tt(Start, "[", OPENBRACKET);
376
+ tt(Start, "]", CLOSEBRACKET);
377
+ tt(Start, "(", OPENPAREN);
378
+ tt(Start, ")", CLOSEPAREN);
379
+ tt(Start, "<", OPENANGLEBRACKET);
380
+ tt(Start, ">", CLOSEANGLEBRACKET);
381
+ tt(Start, "(", FULLWIDTHLEFTPAREN);
382
+ tt(Start, ")", FULLWIDTHRIGHTPAREN);
383
+ tt(Start, "「", LEFTCORNERBRACKET);
384
+ tt(Start, "」", RIGHTCORNERBRACKET);
385
+ tt(Start, "『", LEFTWHITECORNERBRACKET);
386
+ tt(Start, "』", RIGHTWHITECORNERBRACKET);
387
+ tt(Start, "<", FULLWIDTHLESSTHAN);
388
+ tt(Start, ">", FULLWIDTHGREATERTHAN);
389
+ tt(Start, "&", AMPERSAND);
390
+ tt(Start, "*", ASTERISK);
391
+ tt(Start, "@", AT);
392
+ tt(Start, "`", BACKTICK);
393
+ tt(Start, "^", CARET);
394
+ tt(Start, ":", COLON);
395
+ tt(Start, ",", COMMA);
396
+ tt(Start, "$", DOLLAR);
397
+ tt(Start, ".", DOT);
398
+ tt(Start, "=", EQUALS);
399
+ tt(Start, "!", EXCLAMATION);
400
+ tt(Start, "-", HYPHEN);
401
+ tt(Start, "%", PERCENT);
402
+ tt(Start, "|", PIPE);
403
+ tt(Start, "+", PLUS);
404
+ tt(Start, "#", POUND);
405
+ tt(Start, "?", QUERY);
406
+ tt(Start, '"', QUOTE);
407
+ tt(Start, "/", SLASH);
408
+ tt(Start, ";", SEMI);
409
+ tt(Start, "~", TILDE);
410
+ tt(Start, "_", UNDERSCORE);
411
+ tt(Start, "\\", BACKSLASH);
412
+ tt(Start, "・", FULLWIDTHMIDDLEDOT);
413
+ const Num = tr(Start, DIGIT, NUM, {
414
+ [numeric]: true
415
+ });
416
+ tr(Num, DIGIT, Num);
417
+ const Asciinumeric = tr(Num, ASCII_LETTER, ASCIINUMERICAL, {
418
+ [asciinumeric]: true
419
+ });
420
+ const Alphanumeric = tr(Num, LETTER, ALPHANUMERICAL, {
421
+ [alphanumeric]: true
422
+ });
423
+ const Word = tr(Start, ASCII_LETTER, WORD, {
424
+ [ascii]: true
425
+ });
426
+ tr(Word, DIGIT, Asciinumeric);
427
+ tr(Word, ASCII_LETTER, Word);
428
+ tr(Asciinumeric, DIGIT, Asciinumeric);
429
+ tr(Asciinumeric, ASCII_LETTER, Asciinumeric);
430
+ const UWord = tr(Start, LETTER, UWORD, {
431
+ [alpha]: true
432
+ });
433
+ tr(UWord, ASCII_LETTER);
434
+ tr(UWord, DIGIT, Alphanumeric);
435
+ tr(UWord, LETTER, UWord);
436
+ tr(Alphanumeric, DIGIT, Alphanumeric);
437
+ tr(Alphanumeric, ASCII_LETTER);
438
+ tr(Alphanumeric, LETTER, Alphanumeric);
439
+ const Nl2 = tt(Start, LF, NL, {
440
+ [whitespace]: true
441
+ });
442
+ const Cr = tt(Start, CR, WS, {
443
+ [whitespace]: true
444
+ });
445
+ const Ws = tr(Start, SPACE, WS, {
446
+ [whitespace]: true
447
+ });
448
+ tt(Start, OBJECT_REPLACEMENT, Ws);
449
+ tt(Cr, LF, Nl2);
450
+ tt(Cr, OBJECT_REPLACEMENT, Ws);
451
+ tr(Cr, SPACE, Ws);
452
+ tt(Ws, CR);
453
+ tt(Ws, LF);
454
+ tr(Ws, SPACE, Ws);
455
+ tt(Ws, OBJECT_REPLACEMENT, Ws);
456
+ const Emoji = tr(Start, EMOJI, EMOJI$1, {
457
+ [emoji]: true
458
+ });
459
+ tt(Emoji, "#");
460
+ tr(Emoji, EMOJI, Emoji);
461
+ tt(Emoji, EMOJI_VARIATION, Emoji);
462
+ const EmojiJoiner = tt(Emoji, EMOJI_JOINER);
463
+ tt(EmojiJoiner, "#");
464
+ tr(EmojiJoiner, EMOJI, Emoji);
465
+ const wordjr = [[ASCII_LETTER, Word], [DIGIT, Asciinumeric]];
466
+ const uwordjr = [[ASCII_LETTER, null], [LETTER, UWord], [DIGIT, Alphanumeric]];
467
+ for (let i = 0; i < tlds.length; i++) {
468
+ fastts(Start, tlds[i], TLD, WORD, wordjr);
469
+ }
470
+ for (let i = 0; i < utlds.length; i++) {
471
+ fastts(Start, utlds[i], UTLD, UWORD, uwordjr);
472
+ }
473
+ addToGroups(TLD, {
474
+ tld: true,
475
+ ascii: true
476
+ }, groups);
477
+ addToGroups(UTLD, {
478
+ utld: true,
479
+ alpha: true
480
+ }, groups);
481
+ fastts(Start, "file", SCHEME, WORD, wordjr);
482
+ fastts(Start, "mailto", SCHEME, WORD, wordjr);
483
+ fastts(Start, "http", SLASH_SCHEME, WORD, wordjr);
484
+ fastts(Start, "https", SLASH_SCHEME, WORD, wordjr);
485
+ fastts(Start, "ftp", SLASH_SCHEME, WORD, wordjr);
486
+ fastts(Start, "ftps", SLASH_SCHEME, WORD, wordjr);
487
+ addToGroups(SCHEME, {
488
+ scheme: true,
489
+ ascii: true
490
+ }, groups);
491
+ addToGroups(SLASH_SCHEME, {
492
+ slashscheme: true,
493
+ ascii: true
494
+ }, groups);
495
+ customSchemes = customSchemes.sort((a, b) => a[0] > b[0] ? 1 : -1);
496
+ for (let i = 0; i < customSchemes.length; i++) {
497
+ const sch = customSchemes[i][0];
498
+ const optionalSlashSlash = customSchemes[i][1];
499
+ const flags = optionalSlashSlash ? {
500
+ [scheme]: true
501
+ } : {
502
+ [slashscheme]: true
503
+ };
504
+ if (sch.indexOf("-") >= 0) {
505
+ flags[domain] = true;
506
+ } else if (!ASCII_LETTER.test(sch)) {
507
+ flags[numeric] = true;
508
+ } else if (DIGIT.test(sch)) {
509
+ flags[asciinumeric] = true;
510
+ } else {
511
+ flags[ascii] = true;
512
+ }
513
+ ts(Start, sch, sch, flags);
514
+ }
515
+ ts(Start, "localhost", LOCALHOST, {
516
+ ascii: true
517
+ });
518
+ Start.jd = new State(SYM);
519
+ return {
520
+ start: Start,
521
+ tokens: assign({
522
+ groups
523
+ }, tk)
524
+ };
525
+ }
526
+ function run$1(start, str) {
527
+ const iterable = stringToArray(str.replace(/[A-Z]/g, (c) => c.toLowerCase()));
528
+ const charCount = iterable.length;
529
+ const tokens = [];
530
+ let cursor = 0;
531
+ let charCursor = 0;
532
+ while (charCursor < charCount) {
533
+ let state = start;
534
+ let nextState = null;
535
+ let tokenLength = 0;
536
+ let latestAccepting = null;
537
+ let sinceAccepts = -1;
538
+ let charsSinceAccepts = -1;
539
+ while (charCursor < charCount && (nextState = state.go(iterable[charCursor]))) {
540
+ state = nextState;
541
+ if (state.accepts()) {
542
+ sinceAccepts = 0;
543
+ charsSinceAccepts = 0;
544
+ latestAccepting = state;
545
+ } else if (sinceAccepts >= 0) {
546
+ sinceAccepts += iterable[charCursor].length;
547
+ charsSinceAccepts++;
548
+ }
549
+ tokenLength += iterable[charCursor].length;
550
+ cursor += iterable[charCursor].length;
551
+ charCursor++;
552
+ }
553
+ cursor -= sinceAccepts;
554
+ charCursor -= charsSinceAccepts;
555
+ tokenLength -= sinceAccepts;
556
+ tokens.push({
557
+ t: latestAccepting.t,
558
+ // token type/name
559
+ v: str.slice(cursor - tokenLength, cursor),
560
+ // string value
561
+ s: cursor - tokenLength,
562
+ // start index
563
+ e: cursor
564
+ // end index (excluding)
565
+ });
566
+ }
567
+ return tokens;
568
+ }
569
+ function stringToArray(str) {
570
+ const result = [];
571
+ const len = str.length;
572
+ let index = 0;
573
+ while (index < len) {
574
+ let first = str.charCodeAt(index);
575
+ let second;
576
+ let char = first < 55296 || first > 56319 || index + 1 === len || (second = str.charCodeAt(index + 1)) < 56320 || second > 57343 ? str[index] : str.slice(index, index + 2);
577
+ result.push(char);
578
+ index += char.length;
579
+ }
580
+ return result;
581
+ }
582
+ function fastts(state, input, t, defaultt, jr) {
583
+ let next;
584
+ const len = input.length;
585
+ for (let i = 0; i < len - 1; i++) {
586
+ const char = input[i];
587
+ if (state.j[char]) {
588
+ next = state.j[char];
589
+ } else {
590
+ next = new State(defaultt);
591
+ next.jr = jr.slice();
592
+ state.j[char] = next;
593
+ }
594
+ state = next;
595
+ }
596
+ next = new State(t);
597
+ next.jr = jr.slice();
598
+ state.j[input[len - 1]] = next;
599
+ return next;
600
+ }
601
+ function decodeTlds(encoded) {
602
+ const words = [];
603
+ const stack = [];
604
+ let i = 0;
605
+ let digits = "0123456789";
606
+ while (i < encoded.length) {
607
+ let popDigitCount = 0;
608
+ while (digits.indexOf(encoded[i + popDigitCount]) >= 0) {
609
+ popDigitCount++;
610
+ }
611
+ if (popDigitCount > 0) {
612
+ words.push(stack.join(""));
613
+ for (let popCount = parseInt(encoded.substring(i, i + popDigitCount), 10); popCount > 0; popCount--) {
614
+ stack.pop();
615
+ }
616
+ i += popDigitCount;
617
+ } else {
618
+ stack.push(encoded[i]);
619
+ i++;
620
+ }
621
+ }
622
+ return words;
623
+ }
624
+ const defaults = {
625
+ defaultProtocol: "http",
626
+ events: null,
627
+ format: noop,
628
+ formatHref: noop,
629
+ nl2br: false,
630
+ tagName: "a",
631
+ target: null,
632
+ rel: null,
633
+ validate: true,
634
+ truncate: Infinity,
635
+ className: null,
636
+ attributes: null,
637
+ ignoreTags: [],
638
+ render: null
639
+ };
640
+ function Options(opts, defaultRender = null) {
641
+ let o = assign({}, defaults);
642
+ if (opts) {
643
+ o = assign(o, opts instanceof Options ? opts.o : opts);
644
+ }
645
+ const ignoredTags = o.ignoreTags;
646
+ const uppercaseIgnoredTags = [];
647
+ for (let i = 0; i < ignoredTags.length; i++) {
648
+ uppercaseIgnoredTags.push(ignoredTags[i].toUpperCase());
649
+ }
650
+ this.o = o;
651
+ if (defaultRender) {
652
+ this.defaultRender = defaultRender;
653
+ }
654
+ this.ignoreTags = uppercaseIgnoredTags;
655
+ }
656
+ Options.prototype = {
657
+ o: defaults,
658
+ /**
659
+ * @type string[]
660
+ */
661
+ ignoreTags: [],
662
+ /**
663
+ * @param {IntermediateRepresentation} ir
664
+ * @returns {any}
665
+ */
666
+ defaultRender(ir) {
667
+ return ir;
668
+ },
669
+ /**
670
+ * Returns true or false based on whether a token should be displayed as a
671
+ * link based on the user options.
672
+ * @param {MultiToken} token
673
+ * @returns {boolean}
674
+ */
675
+ check(token) {
676
+ return this.get("validate", token.toString(), token);
677
+ },
678
+ // Private methods
679
+ /**
680
+ * Resolve an option's value based on the value of the option and the given
681
+ * params. If operator and token are specified and the target option is
682
+ * callable, automatically calls the function with the given argument.
683
+ * @template {keyof Opts} K
684
+ * @param {K} key Name of option to use
685
+ * @param {string} [operator] will be passed to the target option if it's a
686
+ * function. If not specified, RAW function value gets returned
687
+ * @param {MultiToken} [token] The token from linkify.tokenize
688
+ * @returns {Opts[K] | any}
689
+ */
690
+ get(key, operator, token) {
691
+ const isCallable = operator != null;
692
+ let option = this.o[key];
693
+ if (!option) {
694
+ return option;
695
+ }
696
+ if (typeof option === "object") {
697
+ option = token.t in option ? option[token.t] : defaults[key];
698
+ if (typeof option === "function" && isCallable) {
699
+ option = option(operator, token);
700
+ }
701
+ } else if (typeof option === "function" && isCallable) {
702
+ option = option(operator, token.t, token);
703
+ }
704
+ return option;
705
+ },
706
+ /**
707
+ * @template {keyof Opts} L
708
+ * @param {L} key Name of options object to use
709
+ * @param {string} [operator]
710
+ * @param {MultiToken} [token]
711
+ * @returns {Opts[L] | any}
712
+ */
713
+ getObj(key, operator, token) {
714
+ let obj = this.o[key];
715
+ if (typeof obj === "function" && operator != null) {
716
+ obj = obj(operator, token.t, token);
717
+ }
718
+ return obj;
719
+ },
720
+ /**
721
+ * Convert the given token to a rendered element that may be added to the
722
+ * calling-interface's DOM
723
+ * @param {MultiToken} token Token to render to an HTML element
724
+ * @returns {any} Render result; e.g., HTML string, DOM element, React
725
+ * Component, etc.
726
+ */
727
+ render(token) {
728
+ const ir = token.render(this);
729
+ const renderFn = this.get("render", null, token) || this.defaultRender;
730
+ return renderFn(ir, token.t, token);
731
+ }
732
+ };
733
+ function noop(val) {
734
+ return val;
735
+ }
736
+ function MultiToken(value, tokens) {
737
+ this.t = "token";
738
+ this.v = value;
739
+ this.tk = tokens;
740
+ }
741
+ MultiToken.prototype = {
742
+ isLink: false,
743
+ /**
744
+ * Return the string this token represents.
745
+ * @return {string}
746
+ */
747
+ toString() {
748
+ return this.v;
749
+ },
750
+ /**
751
+ * What should the value for this token be in the `href` HTML attribute?
752
+ * Returns the `.toString` value by default.
753
+ * @param {string} [scheme]
754
+ * @return {string}
755
+ */
756
+ toHref(scheme2) {
757
+ return this.toString();
758
+ },
759
+ /**
760
+ * @param {Options} options Formatting options
761
+ * @returns {string}
762
+ */
763
+ toFormattedString(options) {
764
+ const val = this.toString();
765
+ const truncate = options.get("truncate", val, this);
766
+ const formatted = options.get("format", val, this);
767
+ return truncate && formatted.length > truncate ? formatted.substring(0, truncate) + "…" : formatted;
768
+ },
769
+ /**
770
+ *
771
+ * @param {Options} options
772
+ * @returns {string}
773
+ */
774
+ toFormattedHref(options) {
775
+ return options.get("formatHref", this.toHref(options.get("defaultProtocol")), this);
776
+ },
777
+ /**
778
+ * The start index of this token in the original input string
779
+ * @returns {number}
780
+ */
781
+ startIndex() {
782
+ return this.tk[0].s;
783
+ },
784
+ /**
785
+ * The end index of this token in the original input string (up to this
786
+ * index but not including it)
787
+ * @returns {number}
788
+ */
789
+ endIndex() {
790
+ return this.tk[this.tk.length - 1].e;
791
+ },
792
+ /**
793
+ Returns an object of relevant values for this token, which includes keys
794
+ * type - Kind of token ('url', 'email', etc.)
795
+ * value - Original text
796
+ * href - The value that should be added to the anchor tag's href
797
+ attribute
798
+ @method toObject
799
+ @param {string} [protocol] `'http'` by default
800
+ */
801
+ toObject(protocol = defaults.defaultProtocol) {
802
+ return {
803
+ type: this.t,
804
+ value: this.toString(),
805
+ isLink: this.isLink,
806
+ href: this.toHref(protocol),
807
+ start: this.startIndex(),
808
+ end: this.endIndex()
809
+ };
810
+ },
811
+ /**
812
+ *
813
+ * @param {Options} options Formatting option
814
+ */
815
+ toFormattedObject(options) {
816
+ return {
817
+ type: this.t,
818
+ value: this.toFormattedString(options),
819
+ isLink: this.isLink,
820
+ href: this.toFormattedHref(options),
821
+ start: this.startIndex(),
822
+ end: this.endIndex()
823
+ };
824
+ },
825
+ /**
826
+ * Whether this token should be rendered as a link according to the given options
827
+ * @param {Options} options
828
+ * @returns {boolean}
829
+ */
830
+ validate(options) {
831
+ return options.get("validate", this.toString(), this);
832
+ },
833
+ /**
834
+ * Return an object that represents how this link should be rendered.
835
+ * @param {Options} options Formattinng options
836
+ */
837
+ render(options) {
838
+ const token = this;
839
+ const href = this.toHref(options.get("defaultProtocol"));
840
+ const formattedHref = options.get("formatHref", href, this);
841
+ const tagName = options.get("tagName", href, token);
842
+ const content = this.toFormattedString(options);
843
+ const attributes = {};
844
+ const className = options.get("className", href, token);
845
+ const target = options.get("target", href, token);
846
+ const rel = options.get("rel", href, token);
847
+ const attrs = options.getObj("attributes", href, token);
848
+ const eventListeners = options.getObj("events", href, token);
849
+ attributes.href = formattedHref;
850
+ if (className) {
851
+ attributes.class = className;
852
+ }
853
+ if (target) {
854
+ attributes.target = target;
855
+ }
856
+ if (rel) {
857
+ attributes.rel = rel;
858
+ }
859
+ if (attrs) {
860
+ assign(attributes, attrs);
861
+ }
862
+ return {
863
+ tagName,
864
+ attributes,
865
+ content,
866
+ eventListeners
867
+ };
868
+ }
869
+ };
870
+ function createTokenClass(type, props) {
871
+ class Token extends MultiToken {
872
+ constructor(value, tokens) {
873
+ super(value, tokens);
874
+ this.t = type;
875
+ }
876
+ }
877
+ for (const p in props) {
878
+ Token.prototype[p] = props[p];
879
+ }
880
+ Token.t = type;
881
+ return Token;
882
+ }
883
+ const Email = createTokenClass("email", {
884
+ isLink: true,
885
+ toHref() {
886
+ return "mailto:" + this.toString();
887
+ }
888
+ });
889
+ const Text$1 = createTokenClass("text");
890
+ const Nl = createTokenClass("nl");
891
+ const Url = createTokenClass("url", {
892
+ isLink: true,
893
+ /**
894
+ Lowercases relevant parts of the domain and adds the protocol if
895
+ required. Note that this will not escape unsafe HTML characters in the
896
+ URL.
897
+ @param {string} [scheme] default scheme (e.g., 'https')
898
+ @return {string} the full href
899
+ */
900
+ toHref(scheme2 = defaults.defaultProtocol) {
901
+ return this.hasProtocol() ? this.v : `${scheme2}://${this.v}`;
902
+ },
903
+ /**
904
+ * Check whether this URL token has a protocol
905
+ * @return {boolean}
906
+ */
907
+ hasProtocol() {
908
+ const tokens = this.tk;
909
+ return tokens.length >= 2 && tokens[0].t !== LOCALHOST && tokens[1].t === COLON;
910
+ }
911
+ });
912
+ const makeState = (arg) => new State(arg);
913
+ function init$1({
914
+ groups
915
+ }) {
916
+ const qsAccepting = groups.domain.concat([AMPERSAND, ASTERISK, AT, BACKSLASH, BACKTICK, CARET, DOLLAR, EQUALS, HYPHEN, NUM, PERCENT, PIPE, PLUS, POUND, SLASH, SYM, TILDE, UNDERSCORE]);
917
+ const qsNonAccepting = [APOSTROPHE, COLON, COMMA, DOT, EXCLAMATION, PERCENT, QUERY, QUOTE, SEMI, OPENANGLEBRACKET, CLOSEANGLEBRACKET, OPENBRACE, CLOSEBRACE, CLOSEBRACKET, OPENBRACKET, OPENPAREN, CLOSEPAREN, FULLWIDTHLEFTPAREN, FULLWIDTHRIGHTPAREN, LEFTCORNERBRACKET, RIGHTCORNERBRACKET, LEFTWHITECORNERBRACKET, RIGHTWHITECORNERBRACKET, FULLWIDTHLESSTHAN, FULLWIDTHGREATERTHAN];
918
+ const localpartAccepting = [AMPERSAND, APOSTROPHE, ASTERISK, BACKSLASH, BACKTICK, CARET, DOLLAR, EQUALS, HYPHEN, OPENBRACE, CLOSEBRACE, PERCENT, PIPE, PLUS, POUND, QUERY, SLASH, SYM, TILDE, UNDERSCORE];
919
+ const Start = makeState();
920
+ const Localpart = tt(Start, TILDE);
921
+ ta(Localpart, localpartAccepting, Localpart);
922
+ ta(Localpart, groups.domain, Localpart);
923
+ const Domain = makeState(), Scheme = makeState(), SlashScheme = makeState();
924
+ ta(Start, groups.domain, Domain);
925
+ ta(Start, groups.scheme, Scheme);
926
+ ta(Start, groups.slashscheme, SlashScheme);
927
+ ta(Domain, localpartAccepting, Localpart);
928
+ ta(Domain, groups.domain, Domain);
929
+ const LocalpartAt = tt(Domain, AT);
930
+ tt(Localpart, AT, LocalpartAt);
931
+ tt(Scheme, AT, LocalpartAt);
932
+ tt(SlashScheme, AT, LocalpartAt);
933
+ const LocalpartDot = tt(Localpart, DOT);
934
+ ta(LocalpartDot, localpartAccepting, Localpart);
935
+ ta(LocalpartDot, groups.domain, Localpart);
936
+ const EmailDomain = makeState();
937
+ ta(LocalpartAt, groups.domain, EmailDomain);
938
+ ta(EmailDomain, groups.domain, EmailDomain);
939
+ const EmailDomainDot = tt(EmailDomain, DOT);
940
+ ta(EmailDomainDot, groups.domain, EmailDomain);
941
+ const Email$1 = makeState(Email);
942
+ ta(EmailDomainDot, groups.tld, Email$1);
943
+ ta(EmailDomainDot, groups.utld, Email$1);
944
+ tt(LocalpartAt, LOCALHOST, Email$1);
945
+ const EmailDomainHyphen = tt(EmailDomain, HYPHEN);
946
+ tt(EmailDomainHyphen, HYPHEN, EmailDomainHyphen);
947
+ ta(EmailDomainHyphen, groups.domain, EmailDomain);
948
+ ta(Email$1, groups.domain, EmailDomain);
949
+ tt(Email$1, DOT, EmailDomainDot);
950
+ tt(Email$1, HYPHEN, EmailDomainHyphen);
951
+ const EmailColon = tt(Email$1, COLON);
952
+ ta(EmailColon, groups.numeric, Email);
953
+ const DomainHyphen = tt(Domain, HYPHEN);
954
+ const DomainDot = tt(Domain, DOT);
955
+ tt(DomainHyphen, HYPHEN, DomainHyphen);
956
+ ta(DomainHyphen, groups.domain, Domain);
957
+ ta(DomainDot, localpartAccepting, Localpart);
958
+ ta(DomainDot, groups.domain, Domain);
959
+ const DomainDotTld = makeState(Url);
960
+ ta(DomainDot, groups.tld, DomainDotTld);
961
+ ta(DomainDot, groups.utld, DomainDotTld);
962
+ ta(DomainDotTld, groups.domain, Domain);
963
+ ta(DomainDotTld, localpartAccepting, Localpart);
964
+ tt(DomainDotTld, DOT, DomainDot);
965
+ tt(DomainDotTld, HYPHEN, DomainHyphen);
966
+ tt(DomainDotTld, AT, LocalpartAt);
967
+ const DomainDotTldColon = tt(DomainDotTld, COLON);
968
+ const DomainDotTldColonPort = makeState(Url);
969
+ ta(DomainDotTldColon, groups.numeric, DomainDotTldColonPort);
970
+ const Url$1 = makeState(Url);
971
+ const UrlNonaccept = makeState();
972
+ ta(Url$1, qsAccepting, Url$1);
973
+ ta(Url$1, qsNonAccepting, UrlNonaccept);
974
+ ta(UrlNonaccept, qsAccepting, Url$1);
975
+ ta(UrlNonaccept, qsNonAccepting, UrlNonaccept);
976
+ tt(DomainDotTld, SLASH, Url$1);
977
+ tt(DomainDotTldColonPort, SLASH, Url$1);
978
+ const SchemeColon = tt(Scheme, COLON);
979
+ const SlashSchemeColon = tt(SlashScheme, COLON);
980
+ const SlashSchemeColonSlash = tt(SlashSchemeColon, SLASH);
981
+ const UriPrefix = tt(SlashSchemeColonSlash, SLASH);
982
+ ta(Scheme, groups.domain, Domain);
983
+ tt(Scheme, DOT, DomainDot);
984
+ tt(Scheme, HYPHEN, DomainHyphen);
985
+ ta(SlashScheme, groups.domain, Domain);
986
+ tt(SlashScheme, DOT, DomainDot);
987
+ tt(SlashScheme, HYPHEN, DomainHyphen);
988
+ ta(SchemeColon, groups.domain, Url$1);
989
+ tt(SchemeColon, SLASH, Url$1);
990
+ tt(SchemeColon, QUERY, Url$1);
991
+ ta(UriPrefix, groups.domain, Url$1);
992
+ ta(UriPrefix, qsAccepting, Url$1);
993
+ tt(UriPrefix, SLASH, Url$1);
994
+ const bracketPairs = [
995
+ [OPENBRACE, CLOSEBRACE],
996
+ // {}
997
+ [OPENBRACKET, CLOSEBRACKET],
998
+ // []
999
+ [OPENPAREN, CLOSEPAREN],
1000
+ // ()
1001
+ [OPENANGLEBRACKET, CLOSEANGLEBRACKET],
1002
+ // <>
1003
+ [FULLWIDTHLEFTPAREN, FULLWIDTHRIGHTPAREN],
1004
+ // ()
1005
+ [LEFTCORNERBRACKET, RIGHTCORNERBRACKET],
1006
+ // 「」
1007
+ [LEFTWHITECORNERBRACKET, RIGHTWHITECORNERBRACKET],
1008
+ // 『』
1009
+ [FULLWIDTHLESSTHAN, FULLWIDTHGREATERTHAN]
1010
+ // <>
1011
+ ];
1012
+ for (let i = 0; i < bracketPairs.length; i++) {
1013
+ const [OPEN, CLOSE] = bracketPairs[i];
1014
+ const UrlOpen = tt(Url$1, OPEN);
1015
+ tt(UrlNonaccept, OPEN, UrlOpen);
1016
+ tt(UrlOpen, CLOSE, Url$1);
1017
+ const UrlOpenQ = makeState(Url);
1018
+ ta(UrlOpen, qsAccepting, UrlOpenQ);
1019
+ const UrlOpenSyms = makeState();
1020
+ ta(UrlOpen, qsNonAccepting);
1021
+ ta(UrlOpenQ, qsAccepting, UrlOpenQ);
1022
+ ta(UrlOpenQ, qsNonAccepting, UrlOpenSyms);
1023
+ ta(UrlOpenSyms, qsAccepting, UrlOpenQ);
1024
+ ta(UrlOpenSyms, qsNonAccepting, UrlOpenSyms);
1025
+ tt(UrlOpenQ, CLOSE, Url$1);
1026
+ tt(UrlOpenSyms, CLOSE, Url$1);
1027
+ }
1028
+ tt(Start, LOCALHOST, DomainDotTld);
1029
+ tt(Start, NL, Nl);
1030
+ return {
1031
+ start: Start,
1032
+ tokens: tk
1033
+ };
1034
+ }
1035
+ function run(start, input, tokens) {
1036
+ let len = tokens.length;
1037
+ let cursor = 0;
1038
+ let multis = [];
1039
+ let textTokens = [];
1040
+ while (cursor < len) {
1041
+ let state = start;
1042
+ let secondState = null;
1043
+ let nextState = null;
1044
+ let multiLength = 0;
1045
+ let latestAccepting = null;
1046
+ let sinceAccepts = -1;
1047
+ while (cursor < len && !(secondState = state.go(tokens[cursor].t))) {
1048
+ textTokens.push(tokens[cursor++]);
1049
+ }
1050
+ while (cursor < len && (nextState = secondState || state.go(tokens[cursor].t))) {
1051
+ secondState = null;
1052
+ state = nextState;
1053
+ if (state.accepts()) {
1054
+ sinceAccepts = 0;
1055
+ latestAccepting = state;
1056
+ } else if (sinceAccepts >= 0) {
1057
+ sinceAccepts++;
1058
+ }
1059
+ cursor++;
1060
+ multiLength++;
1061
+ }
1062
+ if (sinceAccepts < 0) {
1063
+ cursor -= multiLength;
1064
+ if (cursor < len) {
1065
+ textTokens.push(tokens[cursor]);
1066
+ cursor++;
1067
+ }
1068
+ } else {
1069
+ if (textTokens.length > 0) {
1070
+ multis.push(initMultiToken(Text$1, input, textTokens));
1071
+ textTokens = [];
1072
+ }
1073
+ cursor -= sinceAccepts;
1074
+ multiLength -= sinceAccepts;
1075
+ const Multi = latestAccepting.t;
1076
+ const subtokens = tokens.slice(cursor - multiLength, cursor);
1077
+ multis.push(initMultiToken(Multi, input, subtokens));
1078
+ }
1079
+ }
1080
+ if (textTokens.length > 0) {
1081
+ multis.push(initMultiToken(Text$1, input, textTokens));
1082
+ }
1083
+ return multis;
1084
+ }
1085
+ function initMultiToken(Multi, input, tokens) {
1086
+ const startIdx = tokens[0].s;
1087
+ const endIdx = tokens[tokens.length - 1].e;
1088
+ const value = input.slice(startIdx, endIdx);
1089
+ return new Multi(value, tokens);
1090
+ }
1091
+ const warn = typeof console !== "undefined" && console && console.warn || (() => {
1092
+ });
1093
+ const warnAdvice = "until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.";
1094
+ const INIT = {
1095
+ scanner: null,
1096
+ parser: null,
1097
+ tokenQueue: [],
1098
+ pluginQueue: [],
1099
+ customSchemes: [],
1100
+ initialized: false
1101
+ };
1102
+ function reset() {
1103
+ State.groups = {};
1104
+ INIT.scanner = null;
1105
+ INIT.parser = null;
1106
+ INIT.tokenQueue = [];
1107
+ INIT.pluginQueue = [];
1108
+ INIT.customSchemes = [];
1109
+ INIT.initialized = false;
1110
+ return INIT;
1111
+ }
1112
+ function registerCustomProtocol(scheme2, optionalSlashSlash = false) {
1113
+ if (INIT.initialized) {
1114
+ warn(`linkifyjs: already initialized - will not register custom scheme "${scheme2}" ${warnAdvice}`);
1115
+ }
1116
+ if (!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(scheme2)) {
1117
+ throw new Error(`linkifyjs: incorrect scheme format.
1118
+ 1. Must only contain digits, lowercase ASCII letters or "-"
1119
+ 2. Cannot start or end with "-"
1120
+ 3. "-" cannot repeat`);
1121
+ }
1122
+ INIT.customSchemes.push([scheme2, optionalSlashSlash]);
1123
+ }
1124
+ function init() {
1125
+ INIT.scanner = init$2(INIT.customSchemes);
1126
+ for (let i = 0; i < INIT.tokenQueue.length; i++) {
1127
+ INIT.tokenQueue[i][1]({
1128
+ scanner: INIT.scanner
1129
+ });
1130
+ }
1131
+ INIT.parser = init$1(INIT.scanner.tokens);
1132
+ for (let i = 0; i < INIT.pluginQueue.length; i++) {
1133
+ INIT.pluginQueue[i][1]({
1134
+ scanner: INIT.scanner,
1135
+ parser: INIT.parser
1136
+ });
1137
+ }
1138
+ INIT.initialized = true;
1139
+ return INIT;
1140
+ }
1141
+ function tokenize(str) {
1142
+ if (!INIT.initialized) {
1143
+ init();
1144
+ }
1145
+ return run(INIT.parser.start, str, run$1(INIT.scanner.start, str));
1146
+ }
1147
+ tokenize.scan = run$1;
1148
+ function find(str, type = null, opts = null) {
1149
+ if (type && typeof type === "object") {
1150
+ if (opts) {
1151
+ throw Error(`linkifyjs: Invalid link type ${type}; must be a string`);
1152
+ }
1153
+ opts = type;
1154
+ type = null;
1155
+ }
1156
+ const options = new Options(opts);
1157
+ const tokens = tokenize(str);
1158
+ const filtered = [];
1159
+ for (let i = 0; i < tokens.length; i++) {
1160
+ const token = tokens[i];
1161
+ if (token.isLink && (!type || token.t === type) && options.check(token)) {
1162
+ filtered.push(token.toFormattedObject(options));
1163
+ }
1164
+ }
1165
+ return filtered;
1166
+ }
1167
+ var UNICODE_WHITESPACE_PATTERN = "[\0-   ᠎ -\u2029  ]";
1168
+ var UNICODE_WHITESPACE_REGEX = new RegExp(UNICODE_WHITESPACE_PATTERN);
1169
+ var UNICODE_WHITESPACE_REGEX_END = new RegExp(`${UNICODE_WHITESPACE_PATTERN}$`);
1170
+ var UNICODE_WHITESPACE_REGEX_GLOBAL = new RegExp(UNICODE_WHITESPACE_PATTERN, "g");
1171
+ function isValidLinkStructure(tokens) {
1172
+ if (tokens.length === 1) {
1173
+ return tokens[0].isLink;
1174
+ }
1175
+ if (tokens.length === 3 && tokens[1].isLink) {
1176
+ return ["()", "[]"].includes(tokens[0].value + tokens[2].value);
1177
+ }
1178
+ return false;
1179
+ }
1180
+ function autolink(options) {
1181
+ return new Plugin({
1182
+ key: new PluginKey("autolink"),
1183
+ appendTransaction: (transactions, oldState, newState) => {
1184
+ const docChanges = transactions.some((transaction) => transaction.docChanged) && !oldState.doc.eq(newState.doc);
1185
+ const preventAutolink = transactions.some((transaction) => transaction.getMeta("preventAutolink"));
1186
+ if (!docChanges || preventAutolink) {
1187
+ return;
1188
+ }
1189
+ const { tr: tr2 } = newState;
1190
+ const transform = combineTransactionSteps(oldState.doc, [...transactions]);
1191
+ const changes = getChangedRanges(transform);
1192
+ changes.forEach(({ newRange }) => {
1193
+ const nodesInChangedRanges = findChildrenInRange(newState.doc, newRange, (node) => node.isTextblock);
1194
+ let textBlock;
1195
+ let textBeforeWhitespace;
1196
+ if (nodesInChangedRanges.length > 1) {
1197
+ textBlock = nodesInChangedRanges[0];
1198
+ textBeforeWhitespace = newState.doc.textBetween(
1199
+ textBlock.pos,
1200
+ textBlock.pos + textBlock.node.nodeSize,
1201
+ void 0,
1202
+ " "
1203
+ );
1204
+ } else if (nodesInChangedRanges.length) {
1205
+ const endText = newState.doc.textBetween(newRange.from, newRange.to, " ", " ");
1206
+ if (!UNICODE_WHITESPACE_REGEX_END.test(endText)) {
1207
+ return;
1208
+ }
1209
+ textBlock = nodesInChangedRanges[0];
1210
+ textBeforeWhitespace = newState.doc.textBetween(textBlock.pos, newRange.to, void 0, " ");
1211
+ }
1212
+ if (textBlock && textBeforeWhitespace) {
1213
+ const wordsBeforeWhitespace = textBeforeWhitespace.split(UNICODE_WHITESPACE_REGEX).filter(Boolean);
1214
+ if (wordsBeforeWhitespace.length <= 0) {
1215
+ return false;
1216
+ }
1217
+ const lastWordBeforeSpace = wordsBeforeWhitespace[wordsBeforeWhitespace.length - 1];
1218
+ const lastWordAndBlockOffset = textBlock.pos + textBeforeWhitespace.lastIndexOf(lastWordBeforeSpace);
1219
+ if (!lastWordBeforeSpace) {
1220
+ return false;
1221
+ }
1222
+ const linksBeforeSpace = tokenize(lastWordBeforeSpace).map((t) => t.toObject(options.defaultProtocol));
1223
+ if (!isValidLinkStructure(linksBeforeSpace)) {
1224
+ return false;
1225
+ }
1226
+ linksBeforeSpace.filter((link) => link.isLink).map((link) => ({
1227
+ ...link,
1228
+ from: lastWordAndBlockOffset + link.start + 1,
1229
+ to: lastWordAndBlockOffset + link.end + 1
1230
+ })).filter((link) => {
1231
+ if (!newState.schema.marks.code) {
1232
+ return true;
1233
+ }
1234
+ return !newState.doc.rangeHasMark(link.from, link.to, newState.schema.marks.code);
1235
+ }).filter((link) => options.validate(link.value)).filter((link) => options.shouldAutoLink(link.value)).forEach((link) => {
1236
+ if (getMarksBetween(link.from, link.to, newState.doc).some((item) => item.mark.type === options.type)) {
1237
+ return;
1238
+ }
1239
+ tr2.addMark(
1240
+ link.from,
1241
+ link.to,
1242
+ options.type.create({
1243
+ href: link.href
1244
+ })
1245
+ );
1246
+ });
1247
+ }
1248
+ });
1249
+ if (!tr2.steps.length) {
1250
+ return;
1251
+ }
1252
+ return tr2;
1253
+ }
1254
+ });
1255
+ }
1256
+ function clickHandler(options) {
1257
+ return new Plugin({
1258
+ key: new PluginKey("handleClickLink"),
1259
+ props: {
1260
+ handleClick: (view, pos, event) => {
1261
+ var _a, _b;
1262
+ if (event.button !== 0) {
1263
+ return false;
1264
+ }
1265
+ if (!view.editable) {
1266
+ return false;
1267
+ }
1268
+ let link = null;
1269
+ if (event.target instanceof HTMLAnchorElement) {
1270
+ link = event.target;
1271
+ } else {
1272
+ let a = event.target;
1273
+ const els = [];
1274
+ while (a.nodeName !== "DIV") {
1275
+ els.push(a);
1276
+ a = a.parentNode;
1277
+ }
1278
+ link = els.find((value) => value.nodeName === "A");
1279
+ }
1280
+ if (!link) {
1281
+ return false;
1282
+ }
1283
+ const attrs = getAttributes(view.state, options.type.name);
1284
+ const href = (_a = link == null ? void 0 : link.href) != null ? _a : attrs.href;
1285
+ const target = (_b = link == null ? void 0 : link.target) != null ? _b : attrs.target;
1286
+ if (options.enableClickSelection) {
1287
+ options.editor.commands.extendMarkRange(options.type.name);
1288
+ }
1289
+ if (link && href) {
1290
+ window.open(href, target);
1291
+ return true;
1292
+ }
1293
+ return false;
1294
+ }
1295
+ }
1296
+ });
1297
+ }
1298
+ function pasteHandler(options) {
1299
+ return new Plugin({
1300
+ key: new PluginKey("handlePasteLink"),
1301
+ props: {
1302
+ handlePaste: (view, event, slice2) => {
1303
+ const { state } = view;
1304
+ const { selection } = state;
1305
+ const { empty } = selection;
1306
+ if (empty) {
1307
+ return false;
1308
+ }
1309
+ let textContent = "";
1310
+ slice2.content.forEach((node) => {
1311
+ textContent += node.textContent;
1312
+ });
1313
+ const link = find(textContent, { defaultProtocol: options.defaultProtocol }).find(
1314
+ (item) => item.isLink && item.value === textContent
1315
+ );
1316
+ if (!textContent || !link) {
1317
+ return false;
1318
+ }
1319
+ return options.editor.commands.setMark(options.type, {
1320
+ href: link.href
1321
+ });
1322
+ }
1323
+ }
1324
+ });
1325
+ }
1326
+ function isAllowedUri(uri, protocols) {
1327
+ const allowedProtocols = ["http", "https", "ftp", "ftps", "mailto", "tel", "callto", "sms", "cid", "xmpp"];
1328
+ if (protocols) {
1329
+ protocols.forEach((protocol) => {
1330
+ const nextProtocol = typeof protocol === "string" ? protocol : protocol.scheme;
1331
+ if (nextProtocol) {
1332
+ allowedProtocols.push(nextProtocol);
1333
+ }
1334
+ });
1335
+ }
1336
+ return !uri || uri.replace(UNICODE_WHITESPACE_REGEX_GLOBAL, "").match(
1337
+ new RegExp(
1338
+ // eslint-disable-next-line no-useless-escape
1339
+ `^(?:(?:${allowedProtocols.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,
1340
+ "i"
1341
+ )
1342
+ );
1343
+ }
1344
+ var Link = Mark.create({
1345
+ name: "link",
1346
+ priority: 1e3,
1347
+ keepOnSplit: false,
1348
+ exitable: true,
1349
+ onCreate() {
1350
+ if (this.options.validate && !this.options.shouldAutoLink) {
1351
+ this.options.shouldAutoLink = this.options.validate;
1352
+ console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.");
1353
+ }
1354
+ this.options.protocols.forEach((protocol) => {
1355
+ if (typeof protocol === "string") {
1356
+ registerCustomProtocol(protocol);
1357
+ return;
1358
+ }
1359
+ registerCustomProtocol(protocol.scheme, protocol.optionalSlashes);
1360
+ });
1361
+ },
1362
+ onDestroy() {
1363
+ reset();
1364
+ },
1365
+ inclusive() {
1366
+ return this.options.autolink;
1367
+ },
1368
+ addOptions() {
1369
+ return {
1370
+ openOnClick: true,
1371
+ enableClickSelection: false,
1372
+ linkOnPaste: true,
1373
+ autolink: true,
1374
+ protocols: [],
1375
+ defaultProtocol: "http",
1376
+ HTMLAttributes: {
1377
+ target: "_blank",
1378
+ rel: "noopener noreferrer nofollow",
1379
+ class: null
1380
+ },
1381
+ isAllowedUri: (url, ctx) => !!isAllowedUri(url, ctx.protocols),
1382
+ validate: (url) => !!url,
1383
+ shouldAutoLink: (url) => !!url
1384
+ };
1385
+ },
1386
+ addAttributes() {
1387
+ return {
1388
+ href: {
1389
+ default: null,
1390
+ parseHTML(element) {
1391
+ return element.getAttribute("href");
1392
+ }
1393
+ },
1394
+ target: {
1395
+ default: this.options.HTMLAttributes.target
1396
+ },
1397
+ rel: {
1398
+ default: this.options.HTMLAttributes.rel
1399
+ },
1400
+ class: {
1401
+ default: this.options.HTMLAttributes.class
1402
+ }
1403
+ };
1404
+ },
1405
+ parseHTML() {
1406
+ return [
1407
+ {
1408
+ tag: "a[href]",
1409
+ getAttrs: (dom) => {
1410
+ const href = dom.getAttribute("href");
1411
+ if (!href || !this.options.isAllowedUri(href, {
1412
+ defaultValidate: (url) => !!isAllowedUri(url, this.options.protocols),
1413
+ protocols: this.options.protocols,
1414
+ defaultProtocol: this.options.defaultProtocol
1415
+ })) {
1416
+ return false;
1417
+ }
1418
+ return null;
1419
+ }
1420
+ }
1421
+ ];
1422
+ },
1423
+ renderHTML({ HTMLAttributes }) {
1424
+ if (!this.options.isAllowedUri(HTMLAttributes.href, {
1425
+ defaultValidate: (href) => !!isAllowedUri(href, this.options.protocols),
1426
+ protocols: this.options.protocols,
1427
+ defaultProtocol: this.options.defaultProtocol
1428
+ })) {
1429
+ return ["a", mergeAttributes(this.options.HTMLAttributes, { ...HTMLAttributes, href: "" }), 0];
1430
+ }
1431
+ return ["a", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
1432
+ },
1433
+ addCommands() {
1434
+ return {
1435
+ setLink: (attributes) => ({ chain }) => {
1436
+ const { href } = attributes;
1437
+ if (!this.options.isAllowedUri(href, {
1438
+ defaultValidate: (url) => !!isAllowedUri(url, this.options.protocols),
1439
+ protocols: this.options.protocols,
1440
+ defaultProtocol: this.options.defaultProtocol
1441
+ })) {
1442
+ return false;
1443
+ }
1444
+ return chain().setMark(this.name, attributes).setMeta("preventAutolink", true).run();
1445
+ },
1446
+ toggleLink: (attributes) => ({ chain }) => {
1447
+ const { href } = attributes || {};
1448
+ if (href && !this.options.isAllowedUri(href, {
1449
+ defaultValidate: (url) => !!isAllowedUri(url, this.options.protocols),
1450
+ protocols: this.options.protocols,
1451
+ defaultProtocol: this.options.defaultProtocol
1452
+ })) {
1453
+ return false;
1454
+ }
1455
+ return chain().toggleMark(this.name, attributes, { extendEmptyMarkRange: true }).setMeta("preventAutolink", true).run();
1456
+ },
1457
+ unsetLink: () => ({ chain }) => {
1458
+ return chain().unsetMark(this.name, { extendEmptyMarkRange: true }).setMeta("preventAutolink", true).run();
1459
+ }
1460
+ };
1461
+ },
1462
+ addPasteRules() {
1463
+ return [
1464
+ markPasteRule({
1465
+ find: (text) => {
1466
+ const foundLinks = [];
1467
+ if (text) {
1468
+ const { protocols, defaultProtocol } = this.options;
1469
+ const links = find(text).filter(
1470
+ (item) => item.isLink && this.options.isAllowedUri(item.value, {
1471
+ defaultValidate: (href) => !!isAllowedUri(href, protocols),
1472
+ protocols,
1473
+ defaultProtocol
1474
+ })
1475
+ );
1476
+ if (links.length) {
1477
+ links.forEach(
1478
+ (link) => foundLinks.push({
1479
+ text: link.value,
1480
+ data: {
1481
+ href: link.href
1482
+ },
1483
+ index: link.start
1484
+ })
1485
+ );
1486
+ }
1487
+ }
1488
+ return foundLinks;
1489
+ },
1490
+ type: this.type,
1491
+ getAttributes: (match) => {
1492
+ var _a;
1493
+ return {
1494
+ href: (_a = match.data) == null ? void 0 : _a.href
1495
+ };
1496
+ }
1497
+ })
1498
+ ];
1499
+ },
1500
+ addProseMirrorPlugins() {
1501
+ const plugins = [];
1502
+ const { protocols, defaultProtocol } = this.options;
1503
+ if (this.options.autolink) {
1504
+ plugins.push(
1505
+ autolink({
1506
+ type: this.type,
1507
+ defaultProtocol: this.options.defaultProtocol,
1508
+ validate: (url) => this.options.isAllowedUri(url, {
1509
+ defaultValidate: (href) => !!isAllowedUri(href, protocols),
1510
+ protocols,
1511
+ defaultProtocol
1512
+ }),
1513
+ shouldAutoLink: this.options.shouldAutoLink
1514
+ })
1515
+ );
1516
+ }
1517
+ if (this.options.openOnClick === true) {
1518
+ plugins.push(
1519
+ clickHandler({
1520
+ type: this.type,
1521
+ editor: this.editor,
1522
+ enableClickSelection: this.options.enableClickSelection
1523
+ })
1524
+ );
1525
+ }
1526
+ if (this.options.linkOnPaste) {
1527
+ plugins.push(
1528
+ pasteHandler({
1529
+ editor: this.editor,
1530
+ defaultProtocol: this.options.defaultProtocol,
1531
+ type: this.type
1532
+ })
1533
+ );
1534
+ }
1535
+ return plugins;
1536
+ }
1537
+ });
1538
+ var index_default$2 = Link;
1539
+ var TextAlign = Extension.create({
1540
+ name: "textAlign",
1541
+ addOptions() {
1542
+ return {
1543
+ types: [],
1544
+ alignments: ["left", "center", "right", "justify"],
1545
+ defaultAlignment: null
1546
+ };
1547
+ },
1548
+ addGlobalAttributes() {
1549
+ return [
1550
+ {
1551
+ types: this.options.types,
1552
+ attributes: {
1553
+ textAlign: {
1554
+ default: this.options.defaultAlignment,
1555
+ parseHTML: (element) => {
1556
+ const alignment = element.style.textAlign;
1557
+ return this.options.alignments.includes(alignment) ? alignment : this.options.defaultAlignment;
1558
+ },
1559
+ renderHTML: (attributes) => {
1560
+ if (!attributes.textAlign) {
1561
+ return {};
1562
+ }
1563
+ return { style: `text-align: ${attributes.textAlign}` };
1564
+ }
1565
+ }
1566
+ }
1567
+ }
1568
+ ];
1569
+ },
1570
+ addCommands() {
1571
+ return {
1572
+ setTextAlign: (alignment) => ({ commands }) => {
1573
+ if (!this.options.alignments.includes(alignment)) {
1574
+ return false;
1575
+ }
1576
+ return this.options.types.map((type) => commands.updateAttributes(type, { textAlign: alignment })).every((response) => response);
1577
+ },
1578
+ unsetTextAlign: () => ({ commands }) => {
1579
+ return this.options.types.map((type) => commands.resetAttributes(type, "textAlign")).every((response) => response);
1580
+ },
1581
+ toggleTextAlign: (alignment) => ({ editor, commands }) => {
1582
+ if (!this.options.alignments.includes(alignment)) {
1583
+ return false;
1584
+ }
1585
+ if (editor.isActive({ textAlign: alignment })) {
1586
+ return commands.unsetTextAlign();
1587
+ }
1588
+ return commands.setTextAlign(alignment);
1589
+ }
1590
+ };
1591
+ },
1592
+ addKeyboardShortcuts() {
1593
+ return {
1594
+ "Mod-Shift-l": () => this.editor.commands.setTextAlign("left"),
1595
+ "Mod-Shift-e": () => this.editor.commands.setTextAlign("center"),
1596
+ "Mod-Shift-r": () => this.editor.commands.setTextAlign("right"),
1597
+ "Mod-Shift-j": () => this.editor.commands.setTextAlign("justify")
1598
+ };
1599
+ }
1600
+ });
1601
+ var index_default$1 = TextAlign;
1602
+ var mergeNestedSpanStyles = (element) => {
1603
+ if (!element.children.length) {
1604
+ return;
1605
+ }
1606
+ const childSpans = element.querySelectorAll("span");
1607
+ if (!childSpans) {
1608
+ return;
1609
+ }
1610
+ childSpans.forEach((childSpan) => {
1611
+ var _a, _b;
1612
+ const childStyle = childSpan.getAttribute("style");
1613
+ const closestParentSpanStyleOfChild = (_b = (_a = childSpan.parentElement) == null ? void 0 : _a.closest("span")) == null ? void 0 : _b.getAttribute("style");
1614
+ childSpan.setAttribute("style", `${closestParentSpanStyleOfChild};${childStyle}`);
1615
+ });
1616
+ };
1617
+ var TextStyle = Mark.create({
1618
+ name: "textStyle",
1619
+ priority: 101,
1620
+ addOptions() {
1621
+ return {
1622
+ HTMLAttributes: {},
1623
+ mergeNestedSpanStyles: true
1624
+ };
1625
+ },
1626
+ parseHTML() {
1627
+ return [
1628
+ {
1629
+ tag: "span",
1630
+ consuming: false,
1631
+ getAttrs: (element) => {
1632
+ const hasStyles = element.hasAttribute("style");
1633
+ if (!hasStyles) {
1634
+ return false;
1635
+ }
1636
+ if (this.options.mergeNestedSpanStyles) {
1637
+ mergeNestedSpanStyles(element);
1638
+ }
1639
+ return {};
1640
+ }
1641
+ }
1642
+ ];
1643
+ },
1644
+ renderHTML({ HTMLAttributes }) {
1645
+ return ["span", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
1646
+ },
1647
+ addCommands() {
1648
+ return {
1649
+ toggleTextStyle: (attributes) => ({ commands }) => {
1650
+ return commands.toggleMark(this.name, attributes);
1651
+ },
1652
+ removeEmptyTextStyle: () => ({ tr: tr2 }) => {
1653
+ const { selection } = tr2;
1654
+ tr2.doc.nodesBetween(selection.from, selection.to, (node, pos) => {
1655
+ if (node.isTextblock) {
1656
+ return true;
1657
+ }
1658
+ if (!node.marks.filter((mark) => mark.type === this.type).some((mark) => Object.values(mark.attrs).some((value) => !!value))) {
1659
+ tr2.removeMark(pos, pos + node.nodeSize, this.type);
1660
+ }
1661
+ });
1662
+ return true;
1663
+ }
1664
+ };
1665
+ }
1666
+ });
1667
+ var BackgroundColor = Extension.create({
1668
+ name: "backgroundColor",
1669
+ addOptions() {
1670
+ return {
1671
+ types: ["textStyle"]
1672
+ };
1673
+ },
1674
+ addGlobalAttributes() {
1675
+ return [
1676
+ {
1677
+ types: this.options.types,
1678
+ attributes: {
1679
+ backgroundColor: {
1680
+ default: null,
1681
+ parseHTML: (element) => {
1682
+ var _a;
1683
+ return (_a = element.style.backgroundColor) == null ? void 0 : _a.replace(/['"]+/g, "");
1684
+ },
1685
+ renderHTML: (attributes) => {
1686
+ if (!attributes.backgroundColor) {
1687
+ return {};
1688
+ }
1689
+ return {
1690
+ style: `background-color: ${attributes.backgroundColor}`
1691
+ };
1692
+ }
1693
+ }
1694
+ }
1695
+ }
1696
+ ];
1697
+ },
1698
+ addCommands() {
1699
+ return {
1700
+ setBackgroundColor: (backgroundColor) => ({ chain }) => {
1701
+ return chain().setMark("textStyle", { backgroundColor }).run();
1702
+ },
1703
+ unsetBackgroundColor: () => ({ chain }) => {
1704
+ return chain().setMark("textStyle", { backgroundColor: null }).removeEmptyTextStyle().run();
1705
+ }
1706
+ };
1707
+ }
1708
+ });
1709
+ var Color = Extension.create({
1710
+ name: "color",
1711
+ addOptions() {
1712
+ return {
1713
+ types: ["textStyle"]
1714
+ };
1715
+ },
1716
+ addGlobalAttributes() {
1717
+ return [
1718
+ {
1719
+ types: this.options.types,
1720
+ attributes: {
1721
+ color: {
1722
+ default: null,
1723
+ parseHTML: (element) => {
1724
+ var _a;
1725
+ return (_a = element.style.color) == null ? void 0 : _a.replace(/['"]+/g, "");
1726
+ },
1727
+ renderHTML: (attributes) => {
1728
+ if (!attributes.color) {
1729
+ return {};
1730
+ }
1731
+ return {
1732
+ style: `color: ${attributes.color}`
1733
+ };
1734
+ }
1735
+ }
1736
+ }
1737
+ }
1738
+ ];
1739
+ },
1740
+ addCommands() {
1741
+ return {
1742
+ setColor: (color) => ({ chain }) => {
1743
+ return chain().setMark("textStyle", { color }).run();
1744
+ },
1745
+ unsetColor: () => ({ chain }) => {
1746
+ return chain().setMark("textStyle", { color: null }).removeEmptyTextStyle().run();
1747
+ }
1748
+ };
1749
+ }
1750
+ });
1751
+ var FontFamily = Extension.create({
1752
+ name: "fontFamily",
1753
+ addOptions() {
1754
+ return {
1755
+ types: ["textStyle"]
1756
+ };
1757
+ },
1758
+ addGlobalAttributes() {
1759
+ return [
1760
+ {
1761
+ types: this.options.types,
1762
+ attributes: {
1763
+ fontFamily: {
1764
+ default: null,
1765
+ parseHTML: (element) => element.style.fontFamily,
1766
+ renderHTML: (attributes) => {
1767
+ if (!attributes.fontFamily) {
1768
+ return {};
1769
+ }
1770
+ return {
1771
+ style: `font-family: ${attributes.fontFamily}`
1772
+ };
1773
+ }
1774
+ }
1775
+ }
1776
+ }
1777
+ ];
1778
+ },
1779
+ addCommands() {
1780
+ return {
1781
+ setFontFamily: (fontFamily) => ({ chain }) => {
1782
+ return chain().setMark("textStyle", { fontFamily }).run();
1783
+ },
1784
+ unsetFontFamily: () => ({ chain }) => {
1785
+ return chain().setMark("textStyle", { fontFamily: null }).removeEmptyTextStyle().run();
1786
+ }
1787
+ };
1788
+ }
1789
+ });
1790
+ var FontSize = Extension.create({
1791
+ name: "fontSize",
1792
+ addOptions() {
1793
+ return {
1794
+ types: ["textStyle"]
1795
+ };
1796
+ },
1797
+ addGlobalAttributes() {
1798
+ return [
1799
+ {
1800
+ types: this.options.types,
1801
+ attributes: {
1802
+ fontSize: {
1803
+ default: null,
1804
+ parseHTML: (element) => element.style.fontSize,
1805
+ renderHTML: (attributes) => {
1806
+ if (!attributes.fontSize) {
1807
+ return {};
1808
+ }
1809
+ return {
1810
+ style: `font-size: ${attributes.fontSize}`
1811
+ };
1812
+ }
1813
+ }
1814
+ }
1815
+ }
1816
+ ];
1817
+ },
1818
+ addCommands() {
1819
+ return {
1820
+ setFontSize: (fontSize) => ({ chain }) => {
1821
+ return chain().setMark("textStyle", { fontSize }).run();
1822
+ },
1823
+ unsetFontSize: () => ({ chain }) => {
1824
+ return chain().setMark("textStyle", { fontSize: null }).removeEmptyTextStyle().run();
1825
+ }
1826
+ };
1827
+ }
1828
+ });
1829
+ var LineHeight = Extension.create({
1830
+ name: "lineHeight",
1831
+ addOptions() {
1832
+ return {
1833
+ types: ["textStyle"]
1834
+ };
1835
+ },
1836
+ addGlobalAttributes() {
1837
+ return [
1838
+ {
1839
+ types: this.options.types,
1840
+ attributes: {
1841
+ lineHeight: {
1842
+ default: null,
1843
+ parseHTML: (element) => element.style.lineHeight,
1844
+ renderHTML: (attributes) => {
1845
+ if (!attributes.lineHeight) {
1846
+ return {};
1847
+ }
1848
+ return {
1849
+ style: `line-height: ${attributes.lineHeight}`
1850
+ };
1851
+ }
1852
+ }
1853
+ }
1854
+ }
1855
+ ];
1856
+ },
1857
+ addCommands() {
1858
+ return {
1859
+ setLineHeight: (lineHeight) => ({ chain }) => {
1860
+ return chain().setMark("textStyle", { lineHeight }).run();
1861
+ },
1862
+ unsetLineHeight: () => ({ chain }) => {
1863
+ return chain().setMark("textStyle", { lineHeight: null }).removeEmptyTextStyle().run();
1864
+ }
1865
+ };
1866
+ }
1867
+ });
1868
+ var TextStyleKit = Extension.create({
1869
+ name: "textStyleKit",
1870
+ addExtensions() {
1871
+ const extensions = [];
1872
+ if (this.options.backgroundColor !== false) {
1873
+ extensions.push(BackgroundColor.configure(this.options.backgroundColor));
1874
+ }
1875
+ if (this.options.color !== false) {
1876
+ extensions.push(Color.configure(this.options.color));
1877
+ }
1878
+ if (this.options.fontFamily !== false) {
1879
+ extensions.push(FontFamily.configure(this.options.fontFamily));
1880
+ }
1881
+ if (this.options.fontSize !== false) {
1882
+ extensions.push(FontSize.configure(this.options.fontSize));
1883
+ }
1884
+ if (this.options.lineHeight !== false) {
1885
+ extensions.push(LineHeight.configure(this.options.lineHeight));
1886
+ }
1887
+ if (this.options.textStyle !== false) {
1888
+ extensions.push(TextStyle.configure(this.options.textStyle));
1889
+ }
1890
+ return extensions;
1891
+ }
1892
+ });
1893
+ function dropCursor(options = {}) {
1894
+ return new Plugin({
1895
+ view(editorView) {
1896
+ return new DropCursorView(editorView, options);
1897
+ }
1898
+ });
1899
+ }
1900
+ class DropCursorView {
1901
+ constructor(editorView, options) {
1902
+ var _a;
1903
+ this.editorView = editorView;
1904
+ this.cursorPos = null;
1905
+ this.element = null;
1906
+ this.timeout = -1;
1907
+ this.width = (_a = options.width) !== null && _a !== void 0 ? _a : 1;
1908
+ this.color = options.color === false ? void 0 : options.color || "black";
1909
+ this.class = options.class;
1910
+ this.handlers = ["dragover", "dragend", "drop", "dragleave"].map((name) => {
1911
+ let handler = (e) => {
1912
+ this[name](e);
1913
+ };
1914
+ editorView.dom.addEventListener(name, handler);
1915
+ return { name, handler };
1916
+ });
1917
+ }
1918
+ destroy() {
1919
+ this.handlers.forEach(({ name, handler }) => this.editorView.dom.removeEventListener(name, handler));
1920
+ }
1921
+ update(editorView, prevState) {
1922
+ if (this.cursorPos != null && prevState.doc != editorView.state.doc) {
1923
+ if (this.cursorPos > editorView.state.doc.content.size)
1924
+ this.setCursor(null);
1925
+ else
1926
+ this.updateOverlay();
1927
+ }
1928
+ }
1929
+ setCursor(pos) {
1930
+ if (pos == this.cursorPos)
1931
+ return;
1932
+ this.cursorPos = pos;
1933
+ if (pos == null) {
1934
+ this.element.parentNode.removeChild(this.element);
1935
+ this.element = null;
1936
+ } else {
1937
+ this.updateOverlay();
1938
+ }
1939
+ }
1940
+ updateOverlay() {
1941
+ let $pos = this.editorView.state.doc.resolve(this.cursorPos);
1942
+ let isBlock = !$pos.parent.inlineContent, rect;
1943
+ let editorDOM = this.editorView.dom, editorRect = editorDOM.getBoundingClientRect();
1944
+ let scaleX = editorRect.width / editorDOM.offsetWidth, scaleY = editorRect.height / editorDOM.offsetHeight;
1945
+ if (isBlock) {
1946
+ let before = $pos.nodeBefore, after = $pos.nodeAfter;
1947
+ if (before || after) {
1948
+ let node = this.editorView.nodeDOM(this.cursorPos - (before ? before.nodeSize : 0));
1949
+ if (node) {
1950
+ let nodeRect = node.getBoundingClientRect();
1951
+ let top = before ? nodeRect.bottom : nodeRect.top;
1952
+ if (before && after)
1953
+ top = (top + this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top) / 2;
1954
+ let halfWidth = this.width / 2 * scaleY;
1955
+ rect = { left: nodeRect.left, right: nodeRect.right, top: top - halfWidth, bottom: top + halfWidth };
1956
+ }
1957
+ }
1958
+ }
1959
+ if (!rect) {
1960
+ let coords = this.editorView.coordsAtPos(this.cursorPos);
1961
+ let halfWidth = this.width / 2 * scaleX;
1962
+ rect = { left: coords.left - halfWidth, right: coords.left + halfWidth, top: coords.top, bottom: coords.bottom };
1963
+ }
1964
+ let parent = this.editorView.dom.offsetParent;
1965
+ if (!this.element) {
1966
+ this.element = parent.appendChild(document.createElement("div"));
1967
+ if (this.class)
1968
+ this.element.className = this.class;
1969
+ this.element.style.cssText = "position: absolute; z-index: 50; pointer-events: none;";
1970
+ if (this.color) {
1971
+ this.element.style.backgroundColor = this.color;
1972
+ }
1973
+ }
1974
+ this.element.classList.toggle("prosemirror-dropcursor-block", isBlock);
1975
+ this.element.classList.toggle("prosemirror-dropcursor-inline", !isBlock);
1976
+ let parentLeft, parentTop;
1977
+ if (!parent || parent == document.body && getComputedStyle(parent).position == "static") {
1978
+ parentLeft = -pageXOffset;
1979
+ parentTop = -pageYOffset;
1980
+ } else {
1981
+ let rect2 = parent.getBoundingClientRect();
1982
+ let parentScaleX = rect2.width / parent.offsetWidth, parentScaleY = rect2.height / parent.offsetHeight;
1983
+ parentLeft = rect2.left - parent.scrollLeft * parentScaleX;
1984
+ parentTop = rect2.top - parent.scrollTop * parentScaleY;
1985
+ }
1986
+ this.element.style.left = (rect.left - parentLeft) / scaleX + "px";
1987
+ this.element.style.top = (rect.top - parentTop) / scaleY + "px";
1988
+ this.element.style.width = (rect.right - rect.left) / scaleX + "px";
1989
+ this.element.style.height = (rect.bottom - rect.top) / scaleY + "px";
1990
+ }
1991
+ scheduleRemoval(timeout) {
1992
+ clearTimeout(this.timeout);
1993
+ this.timeout = setTimeout(() => this.setCursor(null), timeout);
1994
+ }
1995
+ dragover(event) {
1996
+ if (!this.editorView.editable)
1997
+ return;
1998
+ let pos = this.editorView.posAtCoords({ left: event.clientX, top: event.clientY });
1999
+ let node = pos && pos.inside >= 0 && this.editorView.state.doc.nodeAt(pos.inside);
2000
+ let disableDropCursor = node && node.type.spec.disableDropCursor;
2001
+ let disabled = typeof disableDropCursor == "function" ? disableDropCursor(this.editorView, pos, event) : disableDropCursor;
2002
+ if (pos && !disabled) {
2003
+ let target = pos.pos;
2004
+ if (this.editorView.dragging && this.editorView.dragging.slice) {
2005
+ let point = dropPoint(this.editorView.state.doc, target, this.editorView.dragging.slice);
2006
+ if (point != null)
2007
+ target = point;
2008
+ }
2009
+ this.setCursor(target);
2010
+ this.scheduleRemoval(5e3);
2011
+ }
2012
+ }
2013
+ dragend() {
2014
+ this.scheduleRemoval(20);
2015
+ }
2016
+ drop() {
2017
+ this.scheduleRemoval(20);
2018
+ }
2019
+ dragleave(event) {
2020
+ if (!this.editorView.dom.contains(event.relatedTarget))
2021
+ this.setCursor(null);
2022
+ }
2023
+ }
2024
+ class GapCursor extends Selection {
2025
+ /**
2026
+ Create a gap cursor.
2027
+ */
2028
+ constructor($pos) {
2029
+ super($pos, $pos);
2030
+ }
2031
+ map(doc, mapping) {
2032
+ let $pos = doc.resolve(mapping.map(this.head));
2033
+ return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos);
2034
+ }
2035
+ content() {
2036
+ return Slice.empty;
2037
+ }
2038
+ eq(other) {
2039
+ return other instanceof GapCursor && other.head == this.head;
2040
+ }
2041
+ toJSON() {
2042
+ return { type: "gapcursor", pos: this.head };
2043
+ }
2044
+ /**
2045
+ @internal
2046
+ */
2047
+ static fromJSON(doc, json) {
2048
+ if (typeof json.pos != "number")
2049
+ throw new RangeError("Invalid input for GapCursor.fromJSON");
2050
+ return new GapCursor(doc.resolve(json.pos));
2051
+ }
2052
+ /**
2053
+ @internal
2054
+ */
2055
+ getBookmark() {
2056
+ return new GapBookmark(this.anchor);
2057
+ }
2058
+ /**
2059
+ @internal
2060
+ */
2061
+ static valid($pos) {
2062
+ let parent = $pos.parent;
2063
+ if (parent.isTextblock || !closedBefore($pos) || !closedAfter($pos))
2064
+ return false;
2065
+ let override = parent.type.spec.allowGapCursor;
2066
+ if (override != null)
2067
+ return override;
2068
+ let deflt = parent.contentMatchAt($pos.index()).defaultType;
2069
+ return deflt && deflt.isTextblock;
2070
+ }
2071
+ /**
2072
+ @internal
2073
+ */
2074
+ static findGapCursorFrom($pos, dir, mustMove = false) {
2075
+ search: for (; ; ) {
2076
+ if (!mustMove && GapCursor.valid($pos))
2077
+ return $pos;
2078
+ let pos = $pos.pos, next = null;
2079
+ for (let d = $pos.depth; ; d--) {
2080
+ let parent = $pos.node(d);
2081
+ if (dir > 0 ? $pos.indexAfter(d) < parent.childCount : $pos.index(d) > 0) {
2082
+ next = parent.child(dir > 0 ? $pos.indexAfter(d) : $pos.index(d) - 1);
2083
+ break;
2084
+ } else if (d == 0) {
2085
+ return null;
2086
+ }
2087
+ pos += dir;
2088
+ let $cur = $pos.doc.resolve(pos);
2089
+ if (GapCursor.valid($cur))
2090
+ return $cur;
2091
+ }
2092
+ for (; ; ) {
2093
+ let inside = dir > 0 ? next.firstChild : next.lastChild;
2094
+ if (!inside) {
2095
+ if (next.isAtom && !next.isText && !NodeSelection.isSelectable(next)) {
2096
+ $pos = $pos.doc.resolve(pos + next.nodeSize * dir);
2097
+ mustMove = false;
2098
+ continue search;
2099
+ }
2100
+ break;
2101
+ }
2102
+ next = inside;
2103
+ pos += dir;
2104
+ let $cur = $pos.doc.resolve(pos);
2105
+ if (GapCursor.valid($cur))
2106
+ return $cur;
2107
+ }
2108
+ return null;
2109
+ }
2110
+ }
2111
+ }
2112
+ GapCursor.prototype.visible = false;
2113
+ GapCursor.findFrom = GapCursor.findGapCursorFrom;
2114
+ Selection.jsonID("gapcursor", GapCursor);
2115
+ class GapBookmark {
2116
+ constructor(pos) {
2117
+ this.pos = pos;
2118
+ }
2119
+ map(mapping) {
2120
+ return new GapBookmark(mapping.map(this.pos));
2121
+ }
2122
+ resolve(doc) {
2123
+ let $pos = doc.resolve(this.pos);
2124
+ return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos);
2125
+ }
2126
+ }
2127
+ function closedBefore($pos) {
2128
+ for (let d = $pos.depth; d >= 0; d--) {
2129
+ let index = $pos.index(d), parent = $pos.node(d);
2130
+ if (index == 0) {
2131
+ if (parent.type.spec.isolating)
2132
+ return true;
2133
+ continue;
2134
+ }
2135
+ for (let before = parent.child(index - 1); ; before = before.lastChild) {
2136
+ if (before.childCount == 0 && !before.inlineContent || before.isAtom || before.type.spec.isolating)
2137
+ return true;
2138
+ if (before.inlineContent)
2139
+ return false;
2140
+ }
2141
+ }
2142
+ return true;
2143
+ }
2144
+ function closedAfter($pos) {
2145
+ for (let d = $pos.depth; d >= 0; d--) {
2146
+ let index = $pos.indexAfter(d), parent = $pos.node(d);
2147
+ if (index == parent.childCount) {
2148
+ if (parent.type.spec.isolating)
2149
+ return true;
2150
+ continue;
2151
+ }
2152
+ for (let after = parent.child(index); ; after = after.firstChild) {
2153
+ if (after.childCount == 0 && !after.inlineContent || after.isAtom || after.type.spec.isolating)
2154
+ return true;
2155
+ if (after.inlineContent)
2156
+ return false;
2157
+ }
2158
+ }
2159
+ return true;
2160
+ }
2161
+ function gapCursor() {
2162
+ return new Plugin({
2163
+ props: {
2164
+ decorations: drawGapCursor,
2165
+ createSelectionBetween(_view, $anchor, $head) {
2166
+ return $anchor.pos == $head.pos && GapCursor.valid($head) ? new GapCursor($head) : null;
2167
+ },
2168
+ handleClick,
2169
+ handleKeyDown,
2170
+ handleDOMEvents: { beforeinput }
2171
+ }
2172
+ });
2173
+ }
2174
+ const handleKeyDown = keydownHandler({
2175
+ "ArrowLeft": arrow("horiz", -1),
2176
+ "ArrowRight": arrow("horiz", 1),
2177
+ "ArrowUp": arrow("vert", -1),
2178
+ "ArrowDown": arrow("vert", 1)
2179
+ });
2180
+ function arrow(axis, dir) {
2181
+ const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left";
2182
+ return function(state, dispatch, view) {
2183
+ let sel = state.selection;
2184
+ let $start = dir > 0 ? sel.$to : sel.$from, mustMove = sel.empty;
2185
+ if (sel instanceof TextSelection) {
2186
+ if (!view.endOfTextblock(dirStr) || $start.depth == 0)
2187
+ return false;
2188
+ mustMove = false;
2189
+ $start = state.doc.resolve(dir > 0 ? $start.after() : $start.before());
2190
+ }
2191
+ let $found = GapCursor.findGapCursorFrom($start, dir, mustMove);
2192
+ if (!$found)
2193
+ return false;
2194
+ if (dispatch)
2195
+ dispatch(state.tr.setSelection(new GapCursor($found)));
2196
+ return true;
2197
+ };
2198
+ }
2199
+ function handleClick(view, pos, event) {
2200
+ if (!view || !view.editable)
2201
+ return false;
2202
+ let $pos = view.state.doc.resolve(pos);
2203
+ if (!GapCursor.valid($pos))
2204
+ return false;
2205
+ let clickPos = view.posAtCoords({ left: event.clientX, top: event.clientY });
2206
+ if (clickPos && clickPos.inside > -1 && NodeSelection.isSelectable(view.state.doc.nodeAt(clickPos.inside)))
2207
+ return false;
2208
+ view.dispatch(view.state.tr.setSelection(new GapCursor($pos)));
2209
+ return true;
2210
+ }
2211
+ function beforeinput(view, event) {
2212
+ if (event.inputType != "insertCompositionText" || !(view.state.selection instanceof GapCursor))
2213
+ return false;
2214
+ let { $from } = view.state.selection;
2215
+ let insert = $from.parent.contentMatchAt($from.index()).findWrapping(view.state.schema.nodes.text);
2216
+ if (!insert)
2217
+ return false;
2218
+ let frag = Fragment.empty;
2219
+ for (let i = insert.length - 1; i >= 0; i--)
2220
+ frag = Fragment.from(insert[i].createAndFill(null, frag));
2221
+ let tr2 = view.state.tr.replace($from.pos, $from.pos, new Slice(frag, 0, 0));
2222
+ tr2.setSelection(TextSelection.near(tr2.doc.resolve($from.pos + 1)));
2223
+ view.dispatch(tr2);
2224
+ return false;
2225
+ }
2226
+ function drawGapCursor(state) {
2227
+ if (!(state.selection instanceof GapCursor))
2228
+ return null;
2229
+ let node = document.createElement("div");
2230
+ node.className = "ProseMirror-gapcursor";
2231
+ return DecorationSet.create(state.doc, [Decoration.widget(state.selection.head, node, { key: "gapcursor" })]);
2232
+ }
2233
+ var GOOD_LEAF_SIZE = 200;
2234
+ var RopeSequence = function RopeSequence2() {
2235
+ };
2236
+ RopeSequence.prototype.append = function append(other) {
2237
+ if (!other.length) {
2238
+ return this;
2239
+ }
2240
+ other = RopeSequence.from(other);
2241
+ return !this.length && other || other.length < GOOD_LEAF_SIZE && this.leafAppend(other) || this.length < GOOD_LEAF_SIZE && other.leafPrepend(this) || this.appendInner(other);
2242
+ };
2243
+ RopeSequence.prototype.prepend = function prepend(other) {
2244
+ if (!other.length) {
2245
+ return this;
2246
+ }
2247
+ return RopeSequence.from(other).append(this);
2248
+ };
2249
+ RopeSequence.prototype.appendInner = function appendInner(other) {
2250
+ return new Append(this, other);
2251
+ };
2252
+ RopeSequence.prototype.slice = function slice(from2, to) {
2253
+ if (from2 === void 0) from2 = 0;
2254
+ if (to === void 0) to = this.length;
2255
+ if (from2 >= to) {
2256
+ return RopeSequence.empty;
2257
+ }
2258
+ return this.sliceInner(Math.max(0, from2), Math.min(this.length, to));
2259
+ };
2260
+ RopeSequence.prototype.get = function get(i) {
2261
+ if (i < 0 || i >= this.length) {
2262
+ return void 0;
2263
+ }
2264
+ return this.getInner(i);
2265
+ };
2266
+ RopeSequence.prototype.forEach = function forEach(f, from2, to) {
2267
+ if (from2 === void 0) from2 = 0;
2268
+ if (to === void 0) to = this.length;
2269
+ if (from2 <= to) {
2270
+ this.forEachInner(f, from2, to, 0);
2271
+ } else {
2272
+ this.forEachInvertedInner(f, from2, to, 0);
2273
+ }
2274
+ };
2275
+ RopeSequence.prototype.map = function map(f, from2, to) {
2276
+ if (from2 === void 0) from2 = 0;
2277
+ if (to === void 0) to = this.length;
2278
+ var result = [];
2279
+ this.forEach(function(elt, i) {
2280
+ return result.push(f(elt, i));
2281
+ }, from2, to);
2282
+ return result;
2283
+ };
2284
+ RopeSequence.from = function from(values) {
2285
+ if (values instanceof RopeSequence) {
2286
+ return values;
2287
+ }
2288
+ return values && values.length ? new Leaf(values) : RopeSequence.empty;
2289
+ };
2290
+ var Leaf = /* @__PURE__ */ function(RopeSequence3) {
2291
+ function Leaf2(values) {
2292
+ RopeSequence3.call(this);
2293
+ this.values = values;
2294
+ }
2295
+ Leaf2.__proto__ = RopeSequence3;
2296
+ Leaf2.prototype = Object.create(RopeSequence3.prototype);
2297
+ Leaf2.prototype.constructor = Leaf2;
2298
+ var prototypeAccessors = { length: { configurable: true }, depth: { configurable: true } };
2299
+ Leaf2.prototype.flatten = function flatten() {
2300
+ return this.values;
2301
+ };
2302
+ Leaf2.prototype.sliceInner = function sliceInner(from2, to) {
2303
+ if (from2 == 0 && to == this.length) {
2304
+ return this;
2305
+ }
2306
+ return new Leaf2(this.values.slice(from2, to));
2307
+ };
2308
+ Leaf2.prototype.getInner = function getInner(i) {
2309
+ return this.values[i];
2310
+ };
2311
+ Leaf2.prototype.forEachInner = function forEachInner(f, from2, to, start) {
2312
+ for (var i = from2; i < to; i++) {
2313
+ if (f(this.values[i], start + i) === false) {
2314
+ return false;
2315
+ }
2316
+ }
2317
+ };
2318
+ Leaf2.prototype.forEachInvertedInner = function forEachInvertedInner(f, from2, to, start) {
2319
+ for (var i = from2 - 1; i >= to; i--) {
2320
+ if (f(this.values[i], start + i) === false) {
2321
+ return false;
2322
+ }
2323
+ }
2324
+ };
2325
+ Leaf2.prototype.leafAppend = function leafAppend(other) {
2326
+ if (this.length + other.length <= GOOD_LEAF_SIZE) {
2327
+ return new Leaf2(this.values.concat(other.flatten()));
2328
+ }
2329
+ };
2330
+ Leaf2.prototype.leafPrepend = function leafPrepend(other) {
2331
+ if (this.length + other.length <= GOOD_LEAF_SIZE) {
2332
+ return new Leaf2(other.flatten().concat(this.values));
2333
+ }
2334
+ };
2335
+ prototypeAccessors.length.get = function() {
2336
+ return this.values.length;
2337
+ };
2338
+ prototypeAccessors.depth.get = function() {
2339
+ return 0;
2340
+ };
2341
+ Object.defineProperties(Leaf2.prototype, prototypeAccessors);
2342
+ return Leaf2;
2343
+ }(RopeSequence);
2344
+ RopeSequence.empty = new Leaf([]);
2345
+ var Append = /* @__PURE__ */ function(RopeSequence3) {
2346
+ function Append2(left, right) {
2347
+ RopeSequence3.call(this);
2348
+ this.left = left;
2349
+ this.right = right;
2350
+ this.length = left.length + right.length;
2351
+ this.depth = Math.max(left.depth, right.depth) + 1;
2352
+ }
2353
+ Append2.__proto__ = RopeSequence3;
2354
+ Append2.prototype = Object.create(RopeSequence3.prototype);
2355
+ Append2.prototype.constructor = Append2;
2356
+ Append2.prototype.flatten = function flatten() {
2357
+ return this.left.flatten().concat(this.right.flatten());
2358
+ };
2359
+ Append2.prototype.getInner = function getInner(i) {
2360
+ return i < this.left.length ? this.left.get(i) : this.right.get(i - this.left.length);
2361
+ };
2362
+ Append2.prototype.forEachInner = function forEachInner(f, from2, to, start) {
2363
+ var leftLen = this.left.length;
2364
+ if (from2 < leftLen && this.left.forEachInner(f, from2, Math.min(to, leftLen), start) === false) {
2365
+ return false;
2366
+ }
2367
+ if (to > leftLen && this.right.forEachInner(f, Math.max(from2 - leftLen, 0), Math.min(this.length, to) - leftLen, start + leftLen) === false) {
2368
+ return false;
2369
+ }
2370
+ };
2371
+ Append2.prototype.forEachInvertedInner = function forEachInvertedInner(f, from2, to, start) {
2372
+ var leftLen = this.left.length;
2373
+ if (from2 > leftLen && this.right.forEachInvertedInner(f, from2 - leftLen, Math.max(to, leftLen) - leftLen, start + leftLen) === false) {
2374
+ return false;
2375
+ }
2376
+ if (to < leftLen && this.left.forEachInvertedInner(f, Math.min(from2, leftLen), to, start) === false) {
2377
+ return false;
2378
+ }
2379
+ };
2380
+ Append2.prototype.sliceInner = function sliceInner(from2, to) {
2381
+ if (from2 == 0 && to == this.length) {
2382
+ return this;
2383
+ }
2384
+ var leftLen = this.left.length;
2385
+ if (to <= leftLen) {
2386
+ return this.left.slice(from2, to);
2387
+ }
2388
+ if (from2 >= leftLen) {
2389
+ return this.right.slice(from2 - leftLen, to - leftLen);
2390
+ }
2391
+ return this.left.slice(from2, leftLen).append(this.right.slice(0, to - leftLen));
2392
+ };
2393
+ Append2.prototype.leafAppend = function leafAppend(other) {
2394
+ var inner = this.right.leafAppend(other);
2395
+ if (inner) {
2396
+ return new Append2(this.left, inner);
2397
+ }
2398
+ };
2399
+ Append2.prototype.leafPrepend = function leafPrepend(other) {
2400
+ var inner = this.left.leafPrepend(other);
2401
+ if (inner) {
2402
+ return new Append2(inner, this.right);
2403
+ }
2404
+ };
2405
+ Append2.prototype.appendInner = function appendInner2(other) {
2406
+ if (this.left.depth >= Math.max(this.right.depth, other.depth) + 1) {
2407
+ return new Append2(this.left, new Append2(this.right, other));
2408
+ }
2409
+ return new Append2(this, other);
2410
+ };
2411
+ return Append2;
2412
+ }(RopeSequence);
2413
+ const max_empty_items = 500;
2414
+ class Branch {
2415
+ constructor(items, eventCount) {
2416
+ this.items = items;
2417
+ this.eventCount = eventCount;
2418
+ }
2419
+ // Pop the latest event off the branch's history and apply it
2420
+ // to a document transform.
2421
+ popEvent(state, preserveItems) {
2422
+ if (this.eventCount == 0)
2423
+ return null;
2424
+ let end = this.items.length;
2425
+ for (; ; end--) {
2426
+ let next = this.items.get(end - 1);
2427
+ if (next.selection) {
2428
+ --end;
2429
+ break;
2430
+ }
2431
+ }
2432
+ let remap, mapFrom;
2433
+ if (preserveItems) {
2434
+ remap = this.remapping(end, this.items.length);
2435
+ mapFrom = remap.maps.length;
2436
+ }
2437
+ let transform = state.tr;
2438
+ let selection, remaining;
2439
+ let addAfter = [], addBefore = [];
2440
+ this.items.forEach((item, i) => {
2441
+ if (!item.step) {
2442
+ if (!remap) {
2443
+ remap = this.remapping(end, i + 1);
2444
+ mapFrom = remap.maps.length;
2445
+ }
2446
+ mapFrom--;
2447
+ addBefore.push(item);
2448
+ return;
2449
+ }
2450
+ if (remap) {
2451
+ addBefore.push(new Item(item.map));
2452
+ let step = item.step.map(remap.slice(mapFrom)), map2;
2453
+ if (step && transform.maybeStep(step).doc) {
2454
+ map2 = transform.mapping.maps[transform.mapping.maps.length - 1];
2455
+ addAfter.push(new Item(map2, void 0, void 0, addAfter.length + addBefore.length));
2456
+ }
2457
+ mapFrom--;
2458
+ if (map2)
2459
+ remap.appendMap(map2, mapFrom);
2460
+ } else {
2461
+ transform.maybeStep(item.step);
2462
+ }
2463
+ if (item.selection) {
2464
+ selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection;
2465
+ remaining = new Branch(this.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), this.eventCount - 1);
2466
+ return false;
2467
+ }
2468
+ }, this.items.length, 0);
2469
+ return { remaining, transform, selection };
2470
+ }
2471
+ // Create a new branch with the given transform added.
2472
+ addTransform(transform, selection, histOptions, preserveItems) {
2473
+ let newItems = [], eventCount = this.eventCount;
2474
+ let oldItems = this.items, lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null;
2475
+ for (let i = 0; i < transform.steps.length; i++) {
2476
+ let step = transform.steps[i].invert(transform.docs[i]);
2477
+ let item = new Item(transform.mapping.maps[i], step, selection), merged;
2478
+ if (merged = lastItem && lastItem.merge(item)) {
2479
+ item = merged;
2480
+ if (i)
2481
+ newItems.pop();
2482
+ else
2483
+ oldItems = oldItems.slice(0, oldItems.length - 1);
2484
+ }
2485
+ newItems.push(item);
2486
+ if (selection) {
2487
+ eventCount++;
2488
+ selection = void 0;
2489
+ }
2490
+ if (!preserveItems)
2491
+ lastItem = item;
2492
+ }
2493
+ let overflow = eventCount - histOptions.depth;
2494
+ if (overflow > DEPTH_OVERFLOW) {
2495
+ oldItems = cutOffEvents(oldItems, overflow);
2496
+ eventCount -= overflow;
2497
+ }
2498
+ return new Branch(oldItems.append(newItems), eventCount);
2499
+ }
2500
+ remapping(from2, to) {
2501
+ let maps = new Mapping();
2502
+ this.items.forEach((item, i) => {
2503
+ let mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from2 ? maps.maps.length - item.mirrorOffset : void 0;
2504
+ maps.appendMap(item.map, mirrorPos);
2505
+ }, from2, to);
2506
+ return maps;
2507
+ }
2508
+ addMaps(array) {
2509
+ if (this.eventCount == 0)
2510
+ return this;
2511
+ return new Branch(this.items.append(array.map((map2) => new Item(map2))), this.eventCount);
2512
+ }
2513
+ // When the collab module receives remote changes, the history has
2514
+ // to know about those, so that it can adjust the steps that were
2515
+ // rebased on top of the remote changes, and include the position
2516
+ // maps for the remote changes in its array of items.
2517
+ rebased(rebasedTransform, rebasedCount) {
2518
+ if (!this.eventCount)
2519
+ return this;
2520
+ let rebasedItems = [], start = Math.max(0, this.items.length - rebasedCount);
2521
+ let mapping = rebasedTransform.mapping;
2522
+ let newUntil = rebasedTransform.steps.length;
2523
+ let eventCount = this.eventCount;
2524
+ this.items.forEach((item) => {
2525
+ if (item.selection)
2526
+ eventCount--;
2527
+ }, start);
2528
+ let iRebased = rebasedCount;
2529
+ this.items.forEach((item) => {
2530
+ let pos = mapping.getMirror(--iRebased);
2531
+ if (pos == null)
2532
+ return;
2533
+ newUntil = Math.min(newUntil, pos);
2534
+ let map2 = mapping.maps[pos];
2535
+ if (item.step) {
2536
+ let step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]);
2537
+ let selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos));
2538
+ if (selection)
2539
+ eventCount++;
2540
+ rebasedItems.push(new Item(map2, step, selection));
2541
+ } else {
2542
+ rebasedItems.push(new Item(map2));
2543
+ }
2544
+ }, start);
2545
+ let newMaps = [];
2546
+ for (let i = rebasedCount; i < newUntil; i++)
2547
+ newMaps.push(new Item(mapping.maps[i]));
2548
+ let items = this.items.slice(0, start).append(newMaps).append(rebasedItems);
2549
+ let branch = new Branch(items, eventCount);
2550
+ if (branch.emptyItemCount() > max_empty_items)
2551
+ branch = branch.compress(this.items.length - rebasedItems.length);
2552
+ return branch;
2553
+ }
2554
+ emptyItemCount() {
2555
+ let count = 0;
2556
+ this.items.forEach((item) => {
2557
+ if (!item.step)
2558
+ count++;
2559
+ });
2560
+ return count;
2561
+ }
2562
+ // Compressing a branch means rewriting it to push the air (map-only
2563
+ // items) out. During collaboration, these naturally accumulate
2564
+ // because each remote change adds one. The `upto` argument is used
2565
+ // to ensure that only the items below a given level are compressed,
2566
+ // because `rebased` relies on a clean, untouched set of items in
2567
+ // order to associate old items with rebased steps.
2568
+ compress(upto = this.items.length) {
2569
+ let remap = this.remapping(0, upto), mapFrom = remap.maps.length;
2570
+ let items = [], events = 0;
2571
+ this.items.forEach((item, i) => {
2572
+ if (i >= upto) {
2573
+ items.push(item);
2574
+ if (item.selection)
2575
+ events++;
2576
+ } else if (item.step) {
2577
+ let step = item.step.map(remap.slice(mapFrom)), map2 = step && step.getMap();
2578
+ mapFrom--;
2579
+ if (map2)
2580
+ remap.appendMap(map2, mapFrom);
2581
+ if (step) {
2582
+ let selection = item.selection && item.selection.map(remap.slice(mapFrom));
2583
+ if (selection)
2584
+ events++;
2585
+ let newItem = new Item(map2.invert(), step, selection), merged, last = items.length - 1;
2586
+ if (merged = items.length && items[last].merge(newItem))
2587
+ items[last] = merged;
2588
+ else
2589
+ items.push(newItem);
2590
+ }
2591
+ } else if (item.map) {
2592
+ mapFrom--;
2593
+ }
2594
+ }, this.items.length, 0);
2595
+ return new Branch(RopeSequence.from(items.reverse()), events);
2596
+ }
2597
+ }
2598
+ Branch.empty = new Branch(RopeSequence.empty, 0);
2599
+ function cutOffEvents(items, n) {
2600
+ let cutPoint;
2601
+ items.forEach((item, i) => {
2602
+ if (item.selection && n-- == 0) {
2603
+ cutPoint = i;
2604
+ return false;
2605
+ }
2606
+ });
2607
+ return items.slice(cutPoint);
2608
+ }
2609
+ class Item {
2610
+ constructor(map2, step, selection, mirrorOffset) {
2611
+ this.map = map2;
2612
+ this.step = step;
2613
+ this.selection = selection;
2614
+ this.mirrorOffset = mirrorOffset;
2615
+ }
2616
+ merge(other) {
2617
+ if (this.step && other.step && !other.selection) {
2618
+ let step = other.step.merge(this.step);
2619
+ if (step)
2620
+ return new Item(step.getMap().invert(), step, this.selection);
2621
+ }
2622
+ }
2623
+ }
2624
+ class HistoryState {
2625
+ constructor(done, undone, prevRanges, prevTime, prevComposition) {
2626
+ this.done = done;
2627
+ this.undone = undone;
2628
+ this.prevRanges = prevRanges;
2629
+ this.prevTime = prevTime;
2630
+ this.prevComposition = prevComposition;
2631
+ }
2632
+ }
2633
+ const DEPTH_OVERFLOW = 20;
2634
+ function applyTransaction(history2, state, tr2, options) {
2635
+ let historyTr = tr2.getMeta(historyKey), rebased;
2636
+ if (historyTr)
2637
+ return historyTr.historyState;
2638
+ if (tr2.getMeta(closeHistoryKey))
2639
+ history2 = new HistoryState(history2.done, history2.undone, null, 0, -1);
2640
+ let appended = tr2.getMeta("appendedTransaction");
2641
+ if (tr2.steps.length == 0) {
2642
+ return history2;
2643
+ } else if (appended && appended.getMeta(historyKey)) {
2644
+ if (appended.getMeta(historyKey).redo)
2645
+ return new HistoryState(history2.done.addTransform(tr2, void 0, options, mustPreserveItems(state)), history2.undone, rangesFor(tr2.mapping.maps), history2.prevTime, history2.prevComposition);
2646
+ else
2647
+ return new HistoryState(history2.done, history2.undone.addTransform(tr2, void 0, options, mustPreserveItems(state)), null, history2.prevTime, history2.prevComposition);
2648
+ } else if (tr2.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) {
2649
+ let composition = tr2.getMeta("composition");
2650
+ let newGroup = history2.prevTime == 0 || !appended && history2.prevComposition != composition && (history2.prevTime < (tr2.time || 0) - options.newGroupDelay || !isAdjacentTo(tr2, history2.prevRanges));
2651
+ let prevRanges = appended ? mapRanges(history2.prevRanges, tr2.mapping) : rangesFor(tr2.mapping.maps);
2652
+ return new HistoryState(history2.done.addTransform(tr2, newGroup ? state.selection.getBookmark() : void 0, options, mustPreserveItems(state)), Branch.empty, prevRanges, tr2.time, composition == null ? history2.prevComposition : composition);
2653
+ } else if (rebased = tr2.getMeta("rebased")) {
2654
+ return new HistoryState(history2.done.rebased(tr2, rebased), history2.undone.rebased(tr2, rebased), mapRanges(history2.prevRanges, tr2.mapping), history2.prevTime, history2.prevComposition);
2655
+ } else {
2656
+ return new HistoryState(history2.done.addMaps(tr2.mapping.maps), history2.undone.addMaps(tr2.mapping.maps), mapRanges(history2.prevRanges, tr2.mapping), history2.prevTime, history2.prevComposition);
2657
+ }
2658
+ }
2659
+ function isAdjacentTo(transform, prevRanges) {
2660
+ if (!prevRanges)
2661
+ return false;
2662
+ if (!transform.docChanged)
2663
+ return true;
2664
+ let adjacent = false;
2665
+ transform.mapping.maps[0].forEach((start, end) => {
2666
+ for (let i = 0; i < prevRanges.length; i += 2)
2667
+ if (start <= prevRanges[i + 1] && end >= prevRanges[i])
2668
+ adjacent = true;
2669
+ });
2670
+ return adjacent;
2671
+ }
2672
+ function rangesFor(maps) {
2673
+ let result = [];
2674
+ for (let i = maps.length - 1; i >= 0 && result.length == 0; i--)
2675
+ maps[i].forEach((_from, _to, from2, to) => result.push(from2, to));
2676
+ return result;
2677
+ }
2678
+ function mapRanges(ranges, mapping) {
2679
+ if (!ranges)
2680
+ return null;
2681
+ let result = [];
2682
+ for (let i = 0; i < ranges.length; i += 2) {
2683
+ let from2 = mapping.map(ranges[i], 1), to = mapping.map(ranges[i + 1], -1);
2684
+ if (from2 <= to)
2685
+ result.push(from2, to);
2686
+ }
2687
+ return result;
2688
+ }
2689
+ function histTransaction(history2, state, redo2) {
2690
+ let preserveItems = mustPreserveItems(state);
2691
+ let histOptions = historyKey.get(state).spec.config;
2692
+ let pop = (redo2 ? history2.undone : history2.done).popEvent(state, preserveItems);
2693
+ if (!pop)
2694
+ return null;
2695
+ let selection = pop.selection.resolve(pop.transform.doc);
2696
+ let added = (redo2 ? history2.done : history2.undone).addTransform(pop.transform, state.selection.getBookmark(), histOptions, preserveItems);
2697
+ let newHist = new HistoryState(redo2 ? added : pop.remaining, redo2 ? pop.remaining : added, null, 0, -1);
2698
+ return pop.transform.setSelection(selection).setMeta(historyKey, { redo: redo2, historyState: newHist });
2699
+ }
2700
+ let cachedPreserveItems = false, cachedPreserveItemsPlugins = null;
2701
+ function mustPreserveItems(state) {
2702
+ let plugins = state.plugins;
2703
+ if (cachedPreserveItemsPlugins != plugins) {
2704
+ cachedPreserveItems = false;
2705
+ cachedPreserveItemsPlugins = plugins;
2706
+ for (let i = 0; i < plugins.length; i++)
2707
+ if (plugins[i].spec.historyPreserveItems) {
2708
+ cachedPreserveItems = true;
2709
+ break;
2710
+ }
2711
+ }
2712
+ return cachedPreserveItems;
2713
+ }
2714
+ const historyKey = new PluginKey("history");
2715
+ const closeHistoryKey = new PluginKey("closeHistory");
2716
+ function history(config = {}) {
2717
+ config = {
2718
+ depth: config.depth || 100,
2719
+ newGroupDelay: config.newGroupDelay || 500
2720
+ };
2721
+ return new Plugin({
2722
+ key: historyKey,
2723
+ state: {
2724
+ init() {
2725
+ return new HistoryState(Branch.empty, Branch.empty, null, 0, -1);
2726
+ },
2727
+ apply(tr2, hist, state) {
2728
+ return applyTransaction(hist, state, tr2, config);
2729
+ }
2730
+ },
2731
+ config,
2732
+ props: {
2733
+ handleDOMEvents: {
2734
+ beforeinput(view, e) {
2735
+ let inputType = e.inputType;
2736
+ let command = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null;
2737
+ if (!command)
2738
+ return false;
2739
+ e.preventDefault();
2740
+ return command(view.state, view.dispatch);
2741
+ }
2742
+ }
2743
+ }
2744
+ });
2745
+ }
2746
+ function buildCommand(redo2, scroll) {
2747
+ return (state, dispatch) => {
2748
+ let hist = historyKey.getState(state);
2749
+ if (!hist || (redo2 ? hist.undone : hist.done).eventCount == 0)
2750
+ return false;
2751
+ if (dispatch) {
2752
+ let tr2 = histTransaction(hist, state, redo2);
2753
+ if (tr2)
2754
+ dispatch(scroll ? tr2.scrollIntoView() : tr2);
2755
+ }
2756
+ return true;
2757
+ };
2758
+ }
2759
+ const undo = buildCommand(false, true);
2760
+ const redo = buildCommand(true, true);
2761
+ var CharacterCount = Extension.create({
2762
+ name: "characterCount",
2763
+ addOptions() {
2764
+ return {
2765
+ limit: null,
2766
+ mode: "textSize",
2767
+ textCounter: (text) => text.length,
2768
+ wordCounter: (text) => text.split(" ").filter((word) => word !== "").length
2769
+ };
2770
+ },
2771
+ addStorage() {
2772
+ return {
2773
+ characters: () => 0,
2774
+ words: () => 0
2775
+ };
2776
+ },
2777
+ onBeforeCreate() {
2778
+ this.storage.characters = (options) => {
2779
+ const node = (options == null ? void 0 : options.node) || this.editor.state.doc;
2780
+ const mode = (options == null ? void 0 : options.mode) || this.options.mode;
2781
+ if (mode === "textSize") {
2782
+ const text = node.textBetween(0, node.content.size, void 0, " ");
2783
+ return this.options.textCounter(text);
2784
+ }
2785
+ return node.nodeSize;
2786
+ };
2787
+ this.storage.words = (options) => {
2788
+ const node = (options == null ? void 0 : options.node) || this.editor.state.doc;
2789
+ const text = node.textBetween(0, node.content.size, " ", " ");
2790
+ return this.options.wordCounter(text);
2791
+ };
2792
+ },
2793
+ addProseMirrorPlugins() {
2794
+ let initialEvaluationDone = false;
2795
+ return [
2796
+ new Plugin({
2797
+ key: new PluginKey("characterCount"),
2798
+ appendTransaction: (transactions, oldState, newState) => {
2799
+ if (initialEvaluationDone) {
2800
+ return;
2801
+ }
2802
+ const limit = this.options.limit;
2803
+ if (limit === null || limit === void 0 || limit === 0) {
2804
+ initialEvaluationDone = true;
2805
+ return;
2806
+ }
2807
+ const initialContentSize = this.storage.characters({ node: newState.doc });
2808
+ if (initialContentSize > limit) {
2809
+ const over = initialContentSize - limit;
2810
+ const from2 = 0;
2811
+ const to = over;
2812
+ console.warn(
2813
+ `[CharacterCount] Initial content exceeded limit of ${limit} characters. Content was automatically trimmed.`
2814
+ );
2815
+ const tr2 = newState.tr.deleteRange(from2, to);
2816
+ initialEvaluationDone = true;
2817
+ return tr2;
2818
+ }
2819
+ initialEvaluationDone = true;
2820
+ },
2821
+ filterTransaction: (transaction, state) => {
2822
+ const limit = this.options.limit;
2823
+ if (!transaction.docChanged || limit === 0 || limit === null || limit === void 0) {
2824
+ return true;
2825
+ }
2826
+ const oldSize = this.storage.characters({ node: state.doc });
2827
+ const newSize = this.storage.characters({ node: transaction.doc });
2828
+ if (newSize <= limit) {
2829
+ return true;
2830
+ }
2831
+ if (oldSize > limit && newSize > limit && newSize <= oldSize) {
2832
+ return true;
2833
+ }
2834
+ if (oldSize > limit && newSize > limit && newSize > oldSize) {
2835
+ return false;
2836
+ }
2837
+ const isPaste = transaction.getMeta("paste");
2838
+ if (!isPaste) {
2839
+ return false;
2840
+ }
2841
+ const pos = transaction.selection.$head.pos;
2842
+ const over = newSize - limit;
2843
+ const from2 = pos - over;
2844
+ const to = pos;
2845
+ transaction.deleteRange(from2, to);
2846
+ const updatedSize = this.storage.characters({ node: transaction.doc });
2847
+ if (updatedSize > limit) {
2848
+ return false;
2849
+ }
2850
+ return true;
2851
+ }
2852
+ })
2853
+ ];
2854
+ }
2855
+ });
2856
+ var Dropcursor = Extension.create({
2857
+ name: "dropCursor",
2858
+ addOptions() {
2859
+ return {
2860
+ color: "currentColor",
2861
+ width: 1,
2862
+ class: void 0
2863
+ };
2864
+ },
2865
+ addProseMirrorPlugins() {
2866
+ return [dropCursor(this.options)];
2867
+ }
2868
+ });
2869
+ Extension.create({
2870
+ name: "focus",
2871
+ addOptions() {
2872
+ return {
2873
+ className: "has-focus",
2874
+ mode: "all"
2875
+ };
2876
+ },
2877
+ addProseMirrorPlugins() {
2878
+ return [
2879
+ new Plugin({
2880
+ key: new PluginKey("focus"),
2881
+ props: {
2882
+ decorations: ({ doc, selection }) => {
2883
+ const { isEditable, isFocused } = this.editor;
2884
+ const { anchor } = selection;
2885
+ const decorations = [];
2886
+ if (!isEditable || !isFocused) {
2887
+ return DecorationSet.create(doc, []);
2888
+ }
2889
+ let maxLevels = 0;
2890
+ if (this.options.mode === "deepest") {
2891
+ doc.descendants((node, pos) => {
2892
+ if (node.isText) {
2893
+ return;
2894
+ }
2895
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
2896
+ if (!isCurrent) {
2897
+ return false;
2898
+ }
2899
+ maxLevels += 1;
2900
+ });
2901
+ }
2902
+ let currentLevel = 0;
2903
+ doc.descendants((node, pos) => {
2904
+ if (node.isText) {
2905
+ return false;
2906
+ }
2907
+ const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
2908
+ if (!isCurrent) {
2909
+ return false;
2910
+ }
2911
+ currentLevel += 1;
2912
+ const outOfScope = this.options.mode === "deepest" && maxLevels - currentLevel > 0 || this.options.mode === "shallowest" && currentLevel > 1;
2913
+ if (outOfScope) {
2914
+ return this.options.mode === "deepest";
2915
+ }
2916
+ decorations.push(
2917
+ Decoration.node(pos, pos + node.nodeSize, {
2918
+ class: this.options.className
2919
+ })
2920
+ );
2921
+ });
2922
+ return DecorationSet.create(doc, decorations);
2923
+ }
2924
+ }
2925
+ })
2926
+ ];
2927
+ }
2928
+ });
2929
+ var Gapcursor = Extension.create({
2930
+ name: "gapCursor",
2931
+ addProseMirrorPlugins() {
2932
+ return [gapCursor()];
2933
+ },
2934
+ extendNodeSchema(extension) {
2935
+ var _a;
2936
+ const context = {
2937
+ name: extension.name,
2938
+ options: extension.options,
2939
+ storage: extension.storage
2940
+ };
2941
+ return {
2942
+ allowGapCursor: (_a = callOrReturn(getExtensionField(extension, "allowGapCursor", context))) != null ? _a : null
2943
+ };
2944
+ }
2945
+ });
2946
+ var Placeholder = Extension.create({
2947
+ name: "placeholder",
2948
+ addOptions() {
2949
+ return {
2950
+ emptyEditorClass: "is-editor-empty",
2951
+ emptyNodeClass: "is-empty",
2952
+ placeholder: "Write something …",
2953
+ showOnlyWhenEditable: true,
2954
+ showOnlyCurrent: true,
2955
+ includeChildren: false
2956
+ };
2957
+ },
2958
+ addProseMirrorPlugins() {
2959
+ return [
2960
+ new Plugin({
2961
+ key: new PluginKey("placeholder"),
2962
+ props: {
2963
+ decorations: ({ doc, selection }) => {
2964
+ const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
2965
+ const { anchor } = selection;
2966
+ const decorations = [];
2967
+ if (!active) {
2968
+ return null;
2969
+ }
2970
+ const isEmptyDoc = this.editor.isEmpty;
2971
+ doc.descendants((node, pos) => {
2972
+ const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
2973
+ const isEmpty = !node.isLeaf && isNodeEmpty(node);
2974
+ if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
2975
+ const classes = [this.options.emptyNodeClass];
2976
+ if (isEmptyDoc) {
2977
+ classes.push(this.options.emptyEditorClass);
2978
+ }
2979
+ const decoration = Decoration.node(pos, pos + node.nodeSize, {
2980
+ class: classes.join(" "),
2981
+ "data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
2982
+ editor: this.editor,
2983
+ node,
2984
+ pos,
2985
+ hasAnchor
2986
+ }) : this.options.placeholder
2987
+ });
2988
+ decorations.push(decoration);
2989
+ }
2990
+ return this.options.includeChildren;
2991
+ });
2992
+ return DecorationSet.create(doc, decorations);
2993
+ }
2994
+ }
2995
+ })
2996
+ ];
2997
+ }
2998
+ });
2999
+ Extension.create({
3000
+ name: "selection",
3001
+ addOptions() {
3002
+ return {
3003
+ className: "selection"
3004
+ };
3005
+ },
3006
+ addProseMirrorPlugins() {
3007
+ const { editor, options } = this;
3008
+ return [
3009
+ new Plugin({
3010
+ key: new PluginKey("selection"),
3011
+ props: {
3012
+ decorations(state) {
3013
+ if (state.selection.empty || editor.isFocused || !editor.isEditable || isNodeSelection(state.selection) || editor.view.dragging) {
3014
+ return null;
3015
+ }
3016
+ return DecorationSet.create(state.doc, [
3017
+ Decoration.inline(state.selection.from, state.selection.to, {
3018
+ class: options.className
3019
+ })
3020
+ ]);
3021
+ }
3022
+ }
3023
+ })
3024
+ ];
3025
+ }
3026
+ });
3027
+ function nodeEqualsType({ types, node }) {
3028
+ return node && Array.isArray(types) && types.includes(node.type) || (node == null ? void 0 : node.type) === types;
3029
+ }
3030
+ var TrailingNode = Extension.create({
3031
+ name: "trailingNode",
3032
+ addOptions() {
3033
+ return {
3034
+ node: "paragraph",
3035
+ notAfter: []
3036
+ };
3037
+ },
3038
+ addProseMirrorPlugins() {
3039
+ const plugin = new PluginKey(this.name);
3040
+ const disabledNodes = Object.entries(this.editor.schema.nodes).map(([, value]) => value).filter((node) => (this.options.notAfter || []).concat(this.options.node).includes(node.name));
3041
+ return [
3042
+ new Plugin({
3043
+ key: plugin,
3044
+ appendTransaction: (_, __, state) => {
3045
+ const { doc, tr: tr2, schema } = state;
3046
+ const shouldInsertNodeAtEnd = plugin.getState(state);
3047
+ const endPosition = doc.content.size;
3048
+ const type = schema.nodes[this.options.node];
3049
+ if (!shouldInsertNodeAtEnd) {
3050
+ return;
3051
+ }
3052
+ return tr2.insert(endPosition, type.create());
3053
+ },
3054
+ state: {
3055
+ init: (_, state) => {
3056
+ const lastNode = state.tr.doc.lastChild;
3057
+ return !nodeEqualsType({ node: lastNode, types: disabledNodes });
3058
+ },
3059
+ apply: (tr2, value) => {
3060
+ if (!tr2.docChanged) {
3061
+ return value;
3062
+ }
3063
+ const lastNode = tr2.doc.lastChild;
3064
+ return !nodeEqualsType({ node: lastNode, types: disabledNodes });
3065
+ }
3066
+ }
3067
+ })
3068
+ ];
3069
+ }
3070
+ });
3071
+ var UndoRedo = Extension.create({
3072
+ name: "undoRedo",
3073
+ addOptions() {
3074
+ return {
3075
+ depth: 100,
3076
+ newGroupDelay: 500
3077
+ };
3078
+ },
3079
+ addCommands() {
3080
+ return {
3081
+ undo: () => ({ state, dispatch }) => {
3082
+ return undo(state, dispatch);
3083
+ },
3084
+ redo: () => ({ state, dispatch }) => {
3085
+ return redo(state, dispatch);
3086
+ }
3087
+ };
3088
+ },
3089
+ addProseMirrorPlugins() {
3090
+ return [history(this.options)];
3091
+ },
3092
+ addKeyboardShortcuts() {
3093
+ return {
3094
+ "Mod-z": () => this.editor.commands.undo(),
3095
+ "Shift-Mod-z": () => this.editor.commands.redo(),
3096
+ "Mod-y": () => this.editor.commands.redo(),
3097
+ // Russian keyboard layouts
3098
+ "Mod-я": () => this.editor.commands.undo(),
3099
+ "Shift-Mod-я": () => this.editor.commands.redo()
3100
+ };
3101
+ }
3102
+ });
3103
+ var h = (tag, attributes) => {
3104
+ if (tag === "slot") {
3105
+ return 0;
3106
+ }
3107
+ if (tag instanceof Function) {
3108
+ return tag(attributes);
3109
+ }
3110
+ const { children, ...rest } = attributes != null ? attributes : {};
3111
+ if (tag === "svg") {
3112
+ throw new Error("SVG elements are not supported in the JSX syntax, use the array syntax instead");
3113
+ }
3114
+ return [tag, rest, children];
3115
+ };
3116
+ var inputRegex$3 = /^\s*>\s$/;
3117
+ var Blockquote = Node3.create({
3118
+ name: "blockquote",
3119
+ addOptions() {
3120
+ return {
3121
+ HTMLAttributes: {}
3122
+ };
3123
+ },
3124
+ content: "block+",
3125
+ group: "block",
3126
+ defining: true,
3127
+ parseHTML() {
3128
+ return [{ tag: "blockquote" }];
3129
+ },
3130
+ renderHTML({ HTMLAttributes }) {
3131
+ return /* @__PURE__ */ h("blockquote", { ...mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), children: /* @__PURE__ */ h("slot", {}) });
3132
+ },
3133
+ addCommands() {
3134
+ return {
3135
+ setBlockquote: () => ({ commands }) => {
3136
+ return commands.wrapIn(this.name);
3137
+ },
3138
+ toggleBlockquote: () => ({ commands }) => {
3139
+ return commands.toggleWrap(this.name);
3140
+ },
3141
+ unsetBlockquote: () => ({ commands }) => {
3142
+ return commands.lift(this.name);
3143
+ }
3144
+ };
3145
+ },
3146
+ addKeyboardShortcuts() {
3147
+ return {
3148
+ "Mod-Shift-b": () => this.editor.commands.toggleBlockquote()
3149
+ };
3150
+ },
3151
+ addInputRules() {
3152
+ return [
3153
+ wrappingInputRule({
3154
+ find: inputRegex$3,
3155
+ type: this.type
3156
+ })
3157
+ ];
3158
+ }
3159
+ });
3160
+ var starInputRegex$1 = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/;
3161
+ var starPasteRegex$1 = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g;
3162
+ var underscoreInputRegex$1 = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/;
3163
+ var underscorePasteRegex$1 = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g;
3164
+ var Bold = Mark.create({
3165
+ name: "bold",
3166
+ addOptions() {
3167
+ return {
3168
+ HTMLAttributes: {}
3169
+ };
3170
+ },
3171
+ parseHTML() {
3172
+ return [
3173
+ {
3174
+ tag: "strong"
3175
+ },
3176
+ {
3177
+ tag: "b",
3178
+ getAttrs: (node) => node.style.fontWeight !== "normal" && null
3179
+ },
3180
+ {
3181
+ style: "font-weight=400",
3182
+ clearMark: (mark) => mark.type.name === this.name
3183
+ },
3184
+ {
3185
+ style: "font-weight",
3186
+ getAttrs: (value) => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null
3187
+ }
3188
+ ];
3189
+ },
3190
+ renderHTML({ HTMLAttributes }) {
3191
+ return /* @__PURE__ */ h("strong", { ...mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), children: /* @__PURE__ */ h("slot", {}) });
3192
+ },
3193
+ addCommands() {
3194
+ return {
3195
+ setBold: () => ({ commands }) => {
3196
+ return commands.setMark(this.name);
3197
+ },
3198
+ toggleBold: () => ({ commands }) => {
3199
+ return commands.toggleMark(this.name);
3200
+ },
3201
+ unsetBold: () => ({ commands }) => {
3202
+ return commands.unsetMark(this.name);
3203
+ }
3204
+ };
3205
+ },
3206
+ addKeyboardShortcuts() {
3207
+ return {
3208
+ "Mod-b": () => this.editor.commands.toggleBold(),
3209
+ "Mod-B": () => this.editor.commands.toggleBold()
3210
+ };
3211
+ },
3212
+ addInputRules() {
3213
+ return [
3214
+ markInputRule({
3215
+ find: starInputRegex$1,
3216
+ type: this.type
3217
+ }),
3218
+ markInputRule({
3219
+ find: underscoreInputRegex$1,
3220
+ type: this.type
3221
+ })
3222
+ ];
3223
+ },
3224
+ addPasteRules() {
3225
+ return [
3226
+ markPasteRule({
3227
+ find: starPasteRegex$1,
3228
+ type: this.type
3229
+ }),
3230
+ markPasteRule({
3231
+ find: underscorePasteRegex$1,
3232
+ type: this.type
3233
+ })
3234
+ ];
3235
+ }
3236
+ });
3237
+ var inputRegex$2 = /(^|[^`])`([^`]+)`(?!`)/;
3238
+ var pasteRegex$1 = /(^|[^`])`([^`]+)`(?!`)/g;
3239
+ var Code = Mark.create({
3240
+ name: "code",
3241
+ addOptions() {
3242
+ return {
3243
+ HTMLAttributes: {}
3244
+ };
3245
+ },
3246
+ excludes: "_",
3247
+ code: true,
3248
+ exitable: true,
3249
+ parseHTML() {
3250
+ return [{ tag: "code" }];
3251
+ },
3252
+ renderHTML({ HTMLAttributes }) {
3253
+ return ["code", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
3254
+ },
3255
+ addCommands() {
3256
+ return {
3257
+ setCode: () => ({ commands }) => {
3258
+ return commands.setMark(this.name);
3259
+ },
3260
+ toggleCode: () => ({ commands }) => {
3261
+ return commands.toggleMark(this.name);
3262
+ },
3263
+ unsetCode: () => ({ commands }) => {
3264
+ return commands.unsetMark(this.name);
3265
+ }
3266
+ };
3267
+ },
3268
+ addKeyboardShortcuts() {
3269
+ return {
3270
+ "Mod-e": () => this.editor.commands.toggleCode()
3271
+ };
3272
+ },
3273
+ addInputRules() {
3274
+ return [
3275
+ markInputRule({
3276
+ find: inputRegex$2,
3277
+ type: this.type
3278
+ })
3279
+ ];
3280
+ },
3281
+ addPasteRules() {
3282
+ return [
3283
+ markPasteRule({
3284
+ find: pasteRegex$1,
3285
+ type: this.type
3286
+ })
3287
+ ];
3288
+ }
3289
+ });
3290
+ var backtickInputRegex = /^```([a-z]+)?[\s\n]$/;
3291
+ var tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/;
3292
+ var CodeBlock = Node3.create({
3293
+ name: "codeBlock",
3294
+ addOptions() {
3295
+ return {
3296
+ languageClassPrefix: "language-",
3297
+ exitOnTripleEnter: true,
3298
+ exitOnArrowDown: true,
3299
+ defaultLanguage: null,
3300
+ HTMLAttributes: {}
3301
+ };
3302
+ },
3303
+ content: "text*",
3304
+ marks: "",
3305
+ group: "block",
3306
+ code: true,
3307
+ defining: true,
3308
+ addAttributes() {
3309
+ return {
3310
+ language: {
3311
+ default: this.options.defaultLanguage,
3312
+ parseHTML: (element) => {
3313
+ var _a;
3314
+ const { languageClassPrefix } = this.options;
3315
+ const classNames = [...((_a = element.firstElementChild) == null ? void 0 : _a.classList) || []];
3316
+ const languages = classNames.filter((className) => className.startsWith(languageClassPrefix)).map((className) => className.replace(languageClassPrefix, ""));
3317
+ const language = languages[0];
3318
+ if (!language) {
3319
+ return null;
3320
+ }
3321
+ return language;
3322
+ },
3323
+ rendered: false
3324
+ }
3325
+ };
3326
+ },
3327
+ parseHTML() {
3328
+ return [
3329
+ {
3330
+ tag: "pre",
3331
+ preserveWhitespace: "full"
3332
+ }
3333
+ ];
3334
+ },
3335
+ renderHTML({ node, HTMLAttributes }) {
3336
+ return [
3337
+ "pre",
3338
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
3339
+ [
3340
+ "code",
3341
+ {
3342
+ class: node.attrs.language ? this.options.languageClassPrefix + node.attrs.language : null
3343
+ },
3344
+ 0
3345
+ ]
3346
+ ];
3347
+ },
3348
+ addCommands() {
3349
+ return {
3350
+ setCodeBlock: (attributes) => ({ commands }) => {
3351
+ return commands.setNode(this.name, attributes);
3352
+ },
3353
+ toggleCodeBlock: (attributes) => ({ commands }) => {
3354
+ return commands.toggleNode(this.name, "paragraph", attributes);
3355
+ }
3356
+ };
3357
+ },
3358
+ addKeyboardShortcuts() {
3359
+ return {
3360
+ "Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(),
3361
+ // remove code block when at start of document or code block is empty
3362
+ Backspace: () => {
3363
+ const { empty, $anchor } = this.editor.state.selection;
3364
+ const isAtStart = $anchor.pos === 1;
3365
+ if (!empty || $anchor.parent.type.name !== this.name) {
3366
+ return false;
3367
+ }
3368
+ if (isAtStart || !$anchor.parent.textContent.length) {
3369
+ return this.editor.commands.clearNodes();
3370
+ }
3371
+ return false;
3372
+ },
3373
+ // exit node on triple enter
3374
+ Enter: ({ editor }) => {
3375
+ if (!this.options.exitOnTripleEnter) {
3376
+ return false;
3377
+ }
3378
+ const { state } = editor;
3379
+ const { selection } = state;
3380
+ const { $from, empty } = selection;
3381
+ if (!empty || $from.parent.type !== this.type) {
3382
+ return false;
3383
+ }
3384
+ const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
3385
+ const endsWithDoubleNewline = $from.parent.textContent.endsWith("\n\n");
3386
+ if (!isAtEnd || !endsWithDoubleNewline) {
3387
+ return false;
3388
+ }
3389
+ return editor.chain().command(({ tr: tr2 }) => {
3390
+ tr2.delete($from.pos - 2, $from.pos);
3391
+ return true;
3392
+ }).exitCode().run();
3393
+ },
3394
+ // exit node on arrow down
3395
+ ArrowDown: ({ editor }) => {
3396
+ if (!this.options.exitOnArrowDown) {
3397
+ return false;
3398
+ }
3399
+ const { state } = editor;
3400
+ const { selection, doc } = state;
3401
+ const { $from, empty } = selection;
3402
+ if (!empty || $from.parent.type !== this.type) {
3403
+ return false;
3404
+ }
3405
+ const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;
3406
+ if (!isAtEnd) {
3407
+ return false;
3408
+ }
3409
+ const after = $from.after();
3410
+ if (after === void 0) {
3411
+ return false;
3412
+ }
3413
+ const nodeAfter = doc.nodeAt(after);
3414
+ if (nodeAfter) {
3415
+ return editor.commands.command(({ tr: tr2 }) => {
3416
+ tr2.setSelection(Selection.near(doc.resolve(after)));
3417
+ return true;
3418
+ });
3419
+ }
3420
+ return editor.commands.exitCode();
3421
+ }
3422
+ };
3423
+ },
3424
+ addInputRules() {
3425
+ return [
3426
+ textblockTypeInputRule({
3427
+ find: backtickInputRegex,
3428
+ type: this.type,
3429
+ getAttributes: (match) => ({
3430
+ language: match[1]
3431
+ })
3432
+ }),
3433
+ textblockTypeInputRule({
3434
+ find: tildeInputRegex,
3435
+ type: this.type,
3436
+ getAttributes: (match) => ({
3437
+ language: match[1]
3438
+ })
3439
+ })
3440
+ ];
3441
+ },
3442
+ addProseMirrorPlugins() {
3443
+ return [
3444
+ // this plugin creates a code block for pasted content from VS Code
3445
+ // we can also detect the copied code language
3446
+ new Plugin({
3447
+ key: new PluginKey("codeBlockVSCodeHandler"),
3448
+ props: {
3449
+ handlePaste: (view, event) => {
3450
+ if (!event.clipboardData) {
3451
+ return false;
3452
+ }
3453
+ if (this.editor.isActive(this.type.name)) {
3454
+ return false;
3455
+ }
3456
+ const text = event.clipboardData.getData("text/plain");
3457
+ const vscode = event.clipboardData.getData("vscode-editor-data");
3458
+ const vscodeData = vscode ? JSON.parse(vscode) : void 0;
3459
+ const language = vscodeData == null ? void 0 : vscodeData.mode;
3460
+ if (!text || !language) {
3461
+ return false;
3462
+ }
3463
+ const { tr: tr2, schema } = view.state;
3464
+ const textNode = schema.text(text.replace(/\r\n?/g, "\n"));
3465
+ tr2.replaceSelectionWith(this.type.create({ language }, textNode));
3466
+ if (tr2.selection.$from.parent.type !== this.type) {
3467
+ tr2.setSelection(TextSelection.near(tr2.doc.resolve(Math.max(0, tr2.selection.from - 2))));
3468
+ }
3469
+ tr2.setMeta("paste", true);
3470
+ view.dispatch(tr2);
3471
+ return true;
3472
+ }
3473
+ }
3474
+ })
3475
+ ];
3476
+ }
3477
+ });
3478
+ var Document = Node3.create({
3479
+ name: "doc",
3480
+ topNode: true,
3481
+ content: "block+"
3482
+ });
3483
+ var HardBreak = Node3.create({
3484
+ name: "hardBreak",
3485
+ addOptions() {
3486
+ return {
3487
+ keepMarks: true,
3488
+ HTMLAttributes: {}
3489
+ };
3490
+ },
3491
+ inline: true,
3492
+ group: "inline",
3493
+ selectable: false,
3494
+ linebreakReplacement: true,
3495
+ parseHTML() {
3496
+ return [{ tag: "br" }];
3497
+ },
3498
+ renderHTML({ HTMLAttributes }) {
3499
+ return ["br", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)];
3500
+ },
3501
+ renderText() {
3502
+ return "\n";
3503
+ },
3504
+ addCommands() {
3505
+ return {
3506
+ setHardBreak: () => ({ commands, chain, state, editor }) => {
3507
+ return commands.first([
3508
+ () => commands.exitCode(),
3509
+ () => commands.command(() => {
3510
+ const { selection, storedMarks } = state;
3511
+ if (selection.$from.parent.type.spec.isolating) {
3512
+ return false;
3513
+ }
3514
+ const { keepMarks } = this.options;
3515
+ const { splittableMarks } = editor.extensionManager;
3516
+ const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
3517
+ return chain().insertContent({ type: this.name }).command(({ tr: tr2, dispatch }) => {
3518
+ if (dispatch && marks && keepMarks) {
3519
+ const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name));
3520
+ tr2.ensureMarks(filteredMarks);
3521
+ }
3522
+ return true;
3523
+ }).run();
3524
+ })
3525
+ ]);
3526
+ }
3527
+ };
3528
+ },
3529
+ addKeyboardShortcuts() {
3530
+ return {
3531
+ "Mod-Enter": () => this.editor.commands.setHardBreak(),
3532
+ "Shift-Enter": () => this.editor.commands.setHardBreak()
3533
+ };
3534
+ }
3535
+ });
3536
+ var Heading = Node3.create({
3537
+ name: "heading",
3538
+ addOptions() {
3539
+ return {
3540
+ levels: [1, 2, 3, 4, 5, 6],
3541
+ HTMLAttributes: {}
3542
+ };
3543
+ },
3544
+ content: "inline*",
3545
+ group: "block",
3546
+ defining: true,
3547
+ addAttributes() {
3548
+ return {
3549
+ level: {
3550
+ default: 1,
3551
+ rendered: false
3552
+ }
3553
+ };
3554
+ },
3555
+ parseHTML() {
3556
+ return this.options.levels.map((level) => ({
3557
+ tag: `h${level}`,
3558
+ attrs: { level }
3559
+ }));
3560
+ },
3561
+ renderHTML({ node, HTMLAttributes }) {
3562
+ const hasLevel = this.options.levels.includes(node.attrs.level);
3563
+ const level = hasLevel ? node.attrs.level : this.options.levels[0];
3564
+ return [`h${level}`, mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
3565
+ },
3566
+ addCommands() {
3567
+ return {
3568
+ setHeading: (attributes) => ({ commands }) => {
3569
+ if (!this.options.levels.includes(attributes.level)) {
3570
+ return false;
3571
+ }
3572
+ return commands.setNode(this.name, attributes);
3573
+ },
3574
+ toggleHeading: (attributes) => ({ commands }) => {
3575
+ if (!this.options.levels.includes(attributes.level)) {
3576
+ return false;
3577
+ }
3578
+ return commands.toggleNode(this.name, "paragraph", attributes);
3579
+ }
3580
+ };
3581
+ },
3582
+ addKeyboardShortcuts() {
3583
+ return this.options.levels.reduce(
3584
+ (items, level) => ({
3585
+ ...items,
3586
+ ...{
3587
+ [`Mod-Alt-${level}`]: () => this.editor.commands.toggleHeading({ level })
3588
+ }
3589
+ }),
3590
+ {}
3591
+ );
3592
+ },
3593
+ addInputRules() {
3594
+ return this.options.levels.map((level) => {
3595
+ return textblockTypeInputRule({
3596
+ find: new RegExp(`^(#{${Math.min(...this.options.levels)},${level}})\\s$`),
3597
+ type: this.type,
3598
+ getAttributes: {
3599
+ level
3600
+ }
3601
+ });
3602
+ });
3603
+ }
3604
+ });
3605
+ var HorizontalRule = Node3.create({
3606
+ name: "horizontalRule",
3607
+ addOptions() {
3608
+ return {
3609
+ HTMLAttributes: {}
3610
+ };
3611
+ },
3612
+ group: "block",
3613
+ parseHTML() {
3614
+ return [{ tag: "hr" }];
3615
+ },
3616
+ renderHTML({ HTMLAttributes }) {
3617
+ return ["hr", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)];
3618
+ },
3619
+ addCommands() {
3620
+ return {
3621
+ setHorizontalRule: () => ({ chain, state }) => {
3622
+ if (!canInsertNode(state, state.schema.nodes[this.name])) {
3623
+ return false;
3624
+ }
3625
+ const { selection } = state;
3626
+ const { $to: $originTo } = selection;
3627
+ const currentChain = chain();
3628
+ if (isNodeSelection(selection)) {
3629
+ currentChain.insertContentAt($originTo.pos, {
3630
+ type: this.name
3631
+ });
3632
+ } else {
3633
+ currentChain.insertContent({ type: this.name });
3634
+ }
3635
+ return currentChain.command(({ tr: tr2, dispatch }) => {
3636
+ var _a;
3637
+ if (dispatch) {
3638
+ const { $to } = tr2.selection;
3639
+ const posAfter = $to.end();
3640
+ if ($to.nodeAfter) {
3641
+ if ($to.nodeAfter.isTextblock) {
3642
+ tr2.setSelection(TextSelection.create(tr2.doc, $to.pos + 1));
3643
+ } else if ($to.nodeAfter.isBlock) {
3644
+ tr2.setSelection(NodeSelection.create(tr2.doc, $to.pos));
3645
+ } else {
3646
+ tr2.setSelection(TextSelection.create(tr2.doc, $to.pos));
3647
+ }
3648
+ } else {
3649
+ const node = (_a = $to.parent.type.contentMatch.defaultType) == null ? void 0 : _a.create();
3650
+ if (node) {
3651
+ tr2.insert(posAfter, node);
3652
+ tr2.setSelection(TextSelection.create(tr2.doc, posAfter + 1));
3653
+ }
3654
+ }
3655
+ tr2.scrollIntoView();
3656
+ }
3657
+ return true;
3658
+ }).run();
3659
+ }
3660
+ };
3661
+ },
3662
+ addInputRules() {
3663
+ return [
3664
+ nodeInputRule({
3665
+ find: /^(?:---|—-|___\s|\*\*\*\s)$/,
3666
+ type: this.type
3667
+ })
3668
+ ];
3669
+ }
3670
+ });
3671
+ var starInputRegex = /(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/;
3672
+ var starPasteRegex = /(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g;
3673
+ var underscoreInputRegex = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/;
3674
+ var underscorePasteRegex = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g;
3675
+ var Italic = Mark.create({
3676
+ name: "italic",
3677
+ addOptions() {
3678
+ return {
3679
+ HTMLAttributes: {}
3680
+ };
3681
+ },
3682
+ parseHTML() {
3683
+ return [
3684
+ {
3685
+ tag: "em"
3686
+ },
3687
+ {
3688
+ tag: "i",
3689
+ getAttrs: (node) => node.style.fontStyle !== "normal" && null
3690
+ },
3691
+ {
3692
+ style: "font-style=normal",
3693
+ clearMark: (mark) => mark.type.name === this.name
3694
+ },
3695
+ {
3696
+ style: "font-style=italic"
3697
+ }
3698
+ ];
3699
+ },
3700
+ renderHTML({ HTMLAttributes }) {
3701
+ return ["em", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
3702
+ },
3703
+ addCommands() {
3704
+ return {
3705
+ setItalic: () => ({ commands }) => {
3706
+ return commands.setMark(this.name);
3707
+ },
3708
+ toggleItalic: () => ({ commands }) => {
3709
+ return commands.toggleMark(this.name);
3710
+ },
3711
+ unsetItalic: () => ({ commands }) => {
3712
+ return commands.unsetMark(this.name);
3713
+ }
3714
+ };
3715
+ },
3716
+ addKeyboardShortcuts() {
3717
+ return {
3718
+ "Mod-i": () => this.editor.commands.toggleItalic(),
3719
+ "Mod-I": () => this.editor.commands.toggleItalic()
3720
+ };
3721
+ },
3722
+ addInputRules() {
3723
+ return [
3724
+ markInputRule({
3725
+ find: starInputRegex,
3726
+ type: this.type
3727
+ }),
3728
+ markInputRule({
3729
+ find: underscoreInputRegex,
3730
+ type: this.type
3731
+ })
3732
+ ];
3733
+ },
3734
+ addPasteRules() {
3735
+ return [
3736
+ markPasteRule({
3737
+ find: starPasteRegex,
3738
+ type: this.type
3739
+ }),
3740
+ markPasteRule({
3741
+ find: underscorePasteRegex,
3742
+ type: this.type
3743
+ })
3744
+ ];
3745
+ }
3746
+ });
3747
+ var __defProp = Object.defineProperty;
3748
+ var __export = (target, all) => {
3749
+ for (var name in all)
3750
+ __defProp(target, name, { get: all[name], enumerable: true });
3751
+ };
3752
+ var ListItemName = "listItem";
3753
+ var TextStyleName = "textStyle";
3754
+ var bulletListInputRegex = /^\s*([-+*])\s$/;
3755
+ var BulletList = Node3.create({
3756
+ name: "bulletList",
3757
+ addOptions() {
3758
+ return {
3759
+ itemTypeName: "listItem",
3760
+ HTMLAttributes: {},
3761
+ keepMarks: false,
3762
+ keepAttributes: false
3763
+ };
3764
+ },
3765
+ group: "block list",
3766
+ content() {
3767
+ return `${this.options.itemTypeName}+`;
3768
+ },
3769
+ parseHTML() {
3770
+ return [{ tag: "ul" }];
3771
+ },
3772
+ renderHTML({ HTMLAttributes }) {
3773
+ return ["ul", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
3774
+ },
3775
+ addCommands() {
3776
+ return {
3777
+ toggleBulletList: () => ({ commands, chain }) => {
3778
+ if (this.options.keepAttributes) {
3779
+ return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
3780
+ }
3781
+ return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
3782
+ }
3783
+ };
3784
+ },
3785
+ addKeyboardShortcuts() {
3786
+ return {
3787
+ "Mod-Shift-8": () => this.editor.commands.toggleBulletList()
3788
+ };
3789
+ },
3790
+ addInputRules() {
3791
+ let inputRule = wrappingInputRule({
3792
+ find: bulletListInputRegex,
3793
+ type: this.type
3794
+ });
3795
+ if (this.options.keepMarks || this.options.keepAttributes) {
3796
+ inputRule = wrappingInputRule({
3797
+ find: bulletListInputRegex,
3798
+ type: this.type,
3799
+ keepMarks: this.options.keepMarks,
3800
+ keepAttributes: this.options.keepAttributes,
3801
+ getAttributes: () => {
3802
+ return this.editor.getAttributes(TextStyleName);
3803
+ },
3804
+ editor: this.editor
3805
+ });
3806
+ }
3807
+ return [inputRule];
3808
+ }
3809
+ });
3810
+ var ListItem = Node3.create({
3811
+ name: "listItem",
3812
+ addOptions() {
3813
+ return {
3814
+ HTMLAttributes: {},
3815
+ bulletListTypeName: "bulletList",
3816
+ orderedListTypeName: "orderedList"
3817
+ };
3818
+ },
3819
+ content: "paragraph block*",
3820
+ defining: true,
3821
+ parseHTML() {
3822
+ return [
3823
+ {
3824
+ tag: "li"
3825
+ }
3826
+ ];
3827
+ },
3828
+ renderHTML({ HTMLAttributes }) {
3829
+ return ["li", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
3830
+ },
3831
+ addKeyboardShortcuts() {
3832
+ return {
3833
+ Enter: () => this.editor.commands.splitListItem(this.name),
3834
+ Tab: () => this.editor.commands.sinkListItem(this.name),
3835
+ "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
3836
+ };
3837
+ }
3838
+ });
3839
+ var listHelpers_exports = {};
3840
+ __export(listHelpers_exports, {
3841
+ findListItemPos: () => findListItemPos,
3842
+ getNextListDepth: () => getNextListDepth,
3843
+ handleBackspace: () => handleBackspace,
3844
+ handleDelete: () => handleDelete,
3845
+ hasListBefore: () => hasListBefore,
3846
+ hasListItemAfter: () => hasListItemAfter,
3847
+ hasListItemBefore: () => hasListItemBefore,
3848
+ listItemHasSubList: () => listItemHasSubList,
3849
+ nextListIsDeeper: () => nextListIsDeeper,
3850
+ nextListIsHigher: () => nextListIsHigher
3851
+ });
3852
+ var findListItemPos = (typeOrName, state) => {
3853
+ const { $from } = state.selection;
3854
+ const nodeType = getNodeType(typeOrName, state.schema);
3855
+ let currentNode = null;
3856
+ let currentDepth = $from.depth;
3857
+ let currentPos = $from.pos;
3858
+ let targetDepth = null;
3859
+ while (currentDepth > 0 && targetDepth === null) {
3860
+ currentNode = $from.node(currentDepth);
3861
+ if (currentNode.type === nodeType) {
3862
+ targetDepth = currentDepth;
3863
+ } else {
3864
+ currentDepth -= 1;
3865
+ currentPos -= 1;
3866
+ }
3867
+ }
3868
+ if (targetDepth === null) {
3869
+ return null;
3870
+ }
3871
+ return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
3872
+ };
3873
+ var getNextListDepth = (typeOrName, state) => {
3874
+ const listItemPos = findListItemPos(typeOrName, state);
3875
+ if (!listItemPos) {
3876
+ return false;
3877
+ }
3878
+ const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4);
3879
+ return depth;
3880
+ };
3881
+ var hasListBefore = (editorState, name, parentListTypes) => {
3882
+ const { $anchor } = editorState.selection;
3883
+ const previousNodePos = Math.max(0, $anchor.pos - 2);
3884
+ const previousNode = editorState.doc.resolve(previousNodePos).node();
3885
+ if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
3886
+ return false;
3887
+ }
3888
+ return true;
3889
+ };
3890
+ var hasListItemBefore = (typeOrName, state) => {
3891
+ var _a;
3892
+ const { $anchor } = state.selection;
3893
+ const $targetPos = state.doc.resolve($anchor.pos - 2);
3894
+ if ($targetPos.index() === 0) {
3895
+ return false;
3896
+ }
3897
+ if (((_a = $targetPos.nodeBefore) == null ? void 0 : _a.type.name) !== typeOrName) {
3898
+ return false;
3899
+ }
3900
+ return true;
3901
+ };
3902
+ var listItemHasSubList = (typeOrName, state, node) => {
3903
+ if (!node) {
3904
+ return false;
3905
+ }
3906
+ const nodeType = getNodeType(typeOrName, state.schema);
3907
+ let hasSubList = false;
3908
+ node.descendants((child) => {
3909
+ if (child.type === nodeType) {
3910
+ hasSubList = true;
3911
+ }
3912
+ });
3913
+ return hasSubList;
3914
+ };
3915
+ var handleBackspace = (editor, name, parentListTypes) => {
3916
+ if (editor.commands.undoInputRule()) {
3917
+ return true;
3918
+ }
3919
+ if (editor.state.selection.from !== editor.state.selection.to) {
3920
+ return false;
3921
+ }
3922
+ if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
3923
+ const { $anchor } = editor.state.selection;
3924
+ const $listPos = editor.state.doc.resolve($anchor.before() - 1);
3925
+ const listDescendants = [];
3926
+ $listPos.node().descendants((node, pos) => {
3927
+ if (node.type.name === name) {
3928
+ listDescendants.push({ node, pos });
3929
+ }
3930
+ });
3931
+ const lastItem = listDescendants.at(-1);
3932
+ if (!lastItem) {
3933
+ return false;
3934
+ }
3935
+ const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
3936
+ return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
3937
+ }
3938
+ if (!isNodeActive(editor.state, name)) {
3939
+ return false;
3940
+ }
3941
+ if (!isAtStartOfNode(editor.state)) {
3942
+ return false;
3943
+ }
3944
+ const listItemPos = findListItemPos(name, editor.state);
3945
+ if (!listItemPos) {
3946
+ return false;
3947
+ }
3948
+ const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
3949
+ const prevNode = $prev.node(listItemPos.depth);
3950
+ const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
3951
+ if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
3952
+ return editor.commands.joinItemBackward();
3953
+ }
3954
+ return editor.chain().liftListItem(name).run();
3955
+ };
3956
+ var nextListIsDeeper = (typeOrName, state) => {
3957
+ const listDepth = getNextListDepth(typeOrName, state);
3958
+ const listItemPos = findListItemPos(typeOrName, state);
3959
+ if (!listItemPos || !listDepth) {
3960
+ return false;
3961
+ }
3962
+ if (listDepth > listItemPos.depth) {
3963
+ return true;
3964
+ }
3965
+ return false;
3966
+ };
3967
+ var nextListIsHigher = (typeOrName, state) => {
3968
+ const listDepth = getNextListDepth(typeOrName, state);
3969
+ const listItemPos = findListItemPos(typeOrName, state);
3970
+ if (!listItemPos || !listDepth) {
3971
+ return false;
3972
+ }
3973
+ if (listDepth < listItemPos.depth) {
3974
+ return true;
3975
+ }
3976
+ return false;
3977
+ };
3978
+ var handleDelete = (editor, name) => {
3979
+ if (!isNodeActive(editor.state, name)) {
3980
+ return false;
3981
+ }
3982
+ if (!isAtEndOfNode(editor.state, name)) {
3983
+ return false;
3984
+ }
3985
+ const { selection } = editor.state;
3986
+ const { $from, $to } = selection;
3987
+ if (!selection.empty && $from.sameParent($to)) {
3988
+ return false;
3989
+ }
3990
+ if (nextListIsDeeper(name, editor.state)) {
3991
+ return editor.chain().focus(editor.state.selection.from + 4).lift(name).joinBackward().run();
3992
+ }
3993
+ if (nextListIsHigher(name, editor.state)) {
3994
+ return editor.chain().joinForward().joinBackward().run();
3995
+ }
3996
+ return editor.commands.joinItemForward();
3997
+ };
3998
+ var hasListItemAfter = (typeOrName, state) => {
3999
+ var _a;
4000
+ const { $anchor } = state.selection;
4001
+ const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2);
4002
+ if ($targetPos.index() === $targetPos.parent.childCount - 1) {
4003
+ return false;
4004
+ }
4005
+ if (((_a = $targetPos.nodeAfter) == null ? void 0 : _a.type.name) !== typeOrName) {
4006
+ return false;
4007
+ }
4008
+ return true;
4009
+ };
4010
+ var ListKeymap = Extension.create({
4011
+ name: "listKeymap",
4012
+ addOptions() {
4013
+ return {
4014
+ listTypes: [
4015
+ {
4016
+ itemName: "listItem",
4017
+ wrapperNames: ["bulletList", "orderedList"]
4018
+ },
4019
+ {
4020
+ itemName: "taskItem",
4021
+ wrapperNames: ["taskList"]
4022
+ }
4023
+ ]
4024
+ };
4025
+ },
4026
+ addKeyboardShortcuts() {
4027
+ return {
4028
+ Delete: ({ editor }) => {
4029
+ let handled = false;
4030
+ this.options.listTypes.forEach(({ itemName }) => {
4031
+ if (editor.state.schema.nodes[itemName] === void 0) {
4032
+ return;
4033
+ }
4034
+ if (handleDelete(editor, itemName)) {
4035
+ handled = true;
4036
+ }
4037
+ });
4038
+ return handled;
4039
+ },
4040
+ "Mod-Delete": ({ editor }) => {
4041
+ let handled = false;
4042
+ this.options.listTypes.forEach(({ itemName }) => {
4043
+ if (editor.state.schema.nodes[itemName] === void 0) {
4044
+ return;
4045
+ }
4046
+ if (handleDelete(editor, itemName)) {
4047
+ handled = true;
4048
+ }
4049
+ });
4050
+ return handled;
4051
+ },
4052
+ Backspace: ({ editor }) => {
4053
+ let handled = false;
4054
+ this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
4055
+ if (editor.state.schema.nodes[itemName] === void 0) {
4056
+ return;
4057
+ }
4058
+ if (handleBackspace(editor, itemName, wrapperNames)) {
4059
+ handled = true;
4060
+ }
4061
+ });
4062
+ return handled;
4063
+ },
4064
+ "Mod-Backspace": ({ editor }) => {
4065
+ let handled = false;
4066
+ this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
4067
+ if (editor.state.schema.nodes[itemName] === void 0) {
4068
+ return;
4069
+ }
4070
+ if (handleBackspace(editor, itemName, wrapperNames)) {
4071
+ handled = true;
4072
+ }
4073
+ });
4074
+ return handled;
4075
+ }
4076
+ };
4077
+ }
4078
+ });
4079
+ var ListItemName2 = "listItem";
4080
+ var TextStyleName2 = "textStyle";
4081
+ var orderedListInputRegex = /^(\d+)\.\s$/;
4082
+ var OrderedList = Node3.create({
4083
+ name: "orderedList",
4084
+ addOptions() {
4085
+ return {
4086
+ itemTypeName: "listItem",
4087
+ HTMLAttributes: {},
4088
+ keepMarks: false,
4089
+ keepAttributes: false
4090
+ };
4091
+ },
4092
+ group: "block list",
4093
+ content() {
4094
+ return `${this.options.itemTypeName}+`;
4095
+ },
4096
+ addAttributes() {
4097
+ return {
4098
+ start: {
4099
+ default: 1,
4100
+ parseHTML: (element) => {
4101
+ return element.hasAttribute("start") ? parseInt(element.getAttribute("start") || "", 10) : 1;
4102
+ }
4103
+ },
4104
+ type: {
4105
+ default: null,
4106
+ parseHTML: (element) => element.getAttribute("type")
4107
+ }
4108
+ };
4109
+ },
4110
+ parseHTML() {
4111
+ return [
4112
+ {
4113
+ tag: "ol"
4114
+ }
4115
+ ];
4116
+ },
4117
+ renderHTML({ HTMLAttributes }) {
4118
+ const { start, ...attributesWithoutStart } = HTMLAttributes;
4119
+ return start === 1 ? ["ol", mergeAttributes(this.options.HTMLAttributes, attributesWithoutStart), 0] : ["ol", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
4120
+ },
4121
+ addCommands() {
4122
+ return {
4123
+ toggleOrderedList: () => ({ commands, chain }) => {
4124
+ if (this.options.keepAttributes) {
4125
+ return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName2, this.editor.getAttributes(TextStyleName2)).run();
4126
+ }
4127
+ return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
4128
+ }
4129
+ };
4130
+ },
4131
+ addKeyboardShortcuts() {
4132
+ return {
4133
+ "Mod-Shift-7": () => this.editor.commands.toggleOrderedList()
4134
+ };
4135
+ },
4136
+ addInputRules() {
4137
+ let inputRule = wrappingInputRule({
4138
+ find: orderedListInputRegex,
4139
+ type: this.type,
4140
+ getAttributes: (match) => ({ start: +match[1] }),
4141
+ joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1]
4142
+ });
4143
+ if (this.options.keepMarks || this.options.keepAttributes) {
4144
+ inputRule = wrappingInputRule({
4145
+ find: orderedListInputRegex,
4146
+ type: this.type,
4147
+ keepMarks: this.options.keepMarks,
4148
+ keepAttributes: this.options.keepAttributes,
4149
+ getAttributes: (match) => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName2) }),
4150
+ joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],
4151
+ editor: this.editor
4152
+ });
4153
+ }
4154
+ return [inputRule];
4155
+ }
4156
+ });
4157
+ var inputRegex$1 = /^\s*(\[([( |x])?\])\s$/;
4158
+ var TaskItem = Node3.create({
4159
+ name: "taskItem",
4160
+ addOptions() {
4161
+ return {
4162
+ nested: false,
4163
+ HTMLAttributes: {},
4164
+ taskListTypeName: "taskList",
4165
+ a11y: void 0
4166
+ };
4167
+ },
4168
+ content() {
4169
+ return this.options.nested ? "paragraph block*" : "paragraph+";
4170
+ },
4171
+ defining: true,
4172
+ addAttributes() {
4173
+ return {
4174
+ checked: {
4175
+ default: false,
4176
+ keepOnSplit: false,
4177
+ parseHTML: (element) => {
4178
+ const dataChecked = element.getAttribute("data-checked");
4179
+ return dataChecked === "" || dataChecked === "true";
4180
+ },
4181
+ renderHTML: (attributes) => ({
4182
+ "data-checked": attributes.checked
4183
+ })
4184
+ }
4185
+ };
4186
+ },
4187
+ parseHTML() {
4188
+ return [
4189
+ {
4190
+ tag: `li[data-type="${this.name}"]`,
4191
+ priority: 51
4192
+ }
4193
+ ];
4194
+ },
4195
+ renderHTML({ node, HTMLAttributes }) {
4196
+ return [
4197
+ "li",
4198
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
4199
+ "data-type": this.name
4200
+ }),
4201
+ [
4202
+ "label",
4203
+ [
4204
+ "input",
4205
+ {
4206
+ type: "checkbox",
4207
+ checked: node.attrs.checked ? "checked" : null
4208
+ }
4209
+ ],
4210
+ ["span"]
4211
+ ],
4212
+ ["div", 0]
4213
+ ];
4214
+ },
4215
+ addKeyboardShortcuts() {
4216
+ const shortcuts = {
4217
+ Enter: () => this.editor.commands.splitListItem(this.name),
4218
+ "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
4219
+ };
4220
+ if (!this.options.nested) {
4221
+ return shortcuts;
4222
+ }
4223
+ return {
4224
+ ...shortcuts,
4225
+ Tab: () => this.editor.commands.sinkListItem(this.name)
4226
+ };
4227
+ },
4228
+ addNodeView() {
4229
+ return ({ node, HTMLAttributes, getPos, editor }) => {
4230
+ const listItem = document.createElement("li");
4231
+ const checkboxWrapper = document.createElement("label");
4232
+ const checkboxStyler = document.createElement("span");
4233
+ const checkbox = document.createElement("input");
4234
+ const content = document.createElement("div");
4235
+ const updateA11Y = () => {
4236
+ var _a, _b;
4237
+ checkbox.ariaLabel = ((_b = (_a = this.options.a11y) == null ? void 0 : _a.checkboxLabel) == null ? void 0 : _b.call(_a, node, checkbox.checked)) || `Task item checkbox for ${node.textContent || "empty task item"}`;
4238
+ };
4239
+ updateA11Y();
4240
+ checkboxWrapper.contentEditable = "false";
4241
+ checkbox.type = "checkbox";
4242
+ checkbox.addEventListener("mousedown", (event) => event.preventDefault());
4243
+ checkbox.addEventListener("change", (event) => {
4244
+ if (!editor.isEditable && !this.options.onReadOnlyChecked) {
4245
+ checkbox.checked = !checkbox.checked;
4246
+ return;
4247
+ }
4248
+ const { checked } = event.target;
4249
+ if (editor.isEditable && typeof getPos === "function") {
4250
+ editor.chain().focus(void 0, { scrollIntoView: false }).command(({ tr: tr2 }) => {
4251
+ const position = getPos();
4252
+ if (typeof position !== "number") {
4253
+ return false;
4254
+ }
4255
+ const currentNode = tr2.doc.nodeAt(position);
4256
+ tr2.setNodeMarkup(position, void 0, {
4257
+ ...currentNode == null ? void 0 : currentNode.attrs,
4258
+ checked
4259
+ });
4260
+ return true;
4261
+ }).run();
4262
+ }
4263
+ if (!editor.isEditable && this.options.onReadOnlyChecked) {
4264
+ if (!this.options.onReadOnlyChecked(node, checked)) {
4265
+ checkbox.checked = !checkbox.checked;
4266
+ }
4267
+ }
4268
+ });
4269
+ Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
4270
+ listItem.setAttribute(key, value);
4271
+ });
4272
+ listItem.dataset.checked = node.attrs.checked;
4273
+ checkbox.checked = node.attrs.checked;
4274
+ checkboxWrapper.append(checkbox, checkboxStyler);
4275
+ listItem.append(checkboxWrapper, content);
4276
+ Object.entries(HTMLAttributes).forEach(([key, value]) => {
4277
+ listItem.setAttribute(key, value);
4278
+ });
4279
+ return {
4280
+ dom: listItem,
4281
+ contentDOM: content,
4282
+ update: (updatedNode) => {
4283
+ if (updatedNode.type !== this.type) {
4284
+ return false;
4285
+ }
4286
+ listItem.dataset.checked = updatedNode.attrs.checked;
4287
+ checkbox.checked = updatedNode.attrs.checked;
4288
+ updateA11Y();
4289
+ return true;
4290
+ }
4291
+ };
4292
+ };
4293
+ },
4294
+ addInputRules() {
4295
+ return [
4296
+ wrappingInputRule({
4297
+ find: inputRegex$1,
4298
+ type: this.type,
4299
+ getAttributes: (match) => ({
4300
+ checked: match[match.length - 1] === "x"
4301
+ })
4302
+ })
4303
+ ];
4304
+ }
4305
+ });
4306
+ var TaskList = Node3.create({
4307
+ name: "taskList",
4308
+ addOptions() {
4309
+ return {
4310
+ itemTypeName: "taskItem",
4311
+ HTMLAttributes: {}
4312
+ };
4313
+ },
4314
+ group: "block list",
4315
+ content() {
4316
+ return `${this.options.itemTypeName}+`;
4317
+ },
4318
+ parseHTML() {
4319
+ return [
4320
+ {
4321
+ tag: `ul[data-type="${this.name}"]`,
4322
+ priority: 51
4323
+ }
4324
+ ];
4325
+ },
4326
+ renderHTML({ HTMLAttributes }) {
4327
+ return ["ul", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { "data-type": this.name }), 0];
4328
+ },
4329
+ addCommands() {
4330
+ return {
4331
+ toggleTaskList: () => ({ commands }) => {
4332
+ return commands.toggleList(this.name, this.options.itemTypeName);
4333
+ }
4334
+ };
4335
+ },
4336
+ addKeyboardShortcuts() {
4337
+ return {
4338
+ "Mod-Shift-9": () => this.editor.commands.toggleTaskList()
4339
+ };
4340
+ }
4341
+ });
4342
+ Extension.create({
4343
+ name: "listKit",
4344
+ addExtensions() {
4345
+ const extensions = [];
4346
+ if (this.options.bulletList !== false) {
4347
+ extensions.push(BulletList.configure(this.options.bulletList));
4348
+ }
4349
+ if (this.options.listItem !== false) {
4350
+ extensions.push(ListItem.configure(this.options.listItem));
4351
+ }
4352
+ if (this.options.listKeymap !== false) {
4353
+ extensions.push(ListKeymap.configure(this.options.listKeymap));
4354
+ }
4355
+ if (this.options.orderedList !== false) {
4356
+ extensions.push(OrderedList.configure(this.options.orderedList));
4357
+ }
4358
+ if (this.options.taskItem !== false) {
4359
+ extensions.push(TaskItem.configure(this.options.taskItem));
4360
+ }
4361
+ if (this.options.taskList !== false) {
4362
+ extensions.push(TaskList.configure(this.options.taskList));
4363
+ }
4364
+ return extensions;
4365
+ }
4366
+ });
4367
+ var Paragraph = Node3.create({
4368
+ name: "paragraph",
4369
+ priority: 1e3,
4370
+ addOptions() {
4371
+ return {
4372
+ HTMLAttributes: {}
4373
+ };
4374
+ },
4375
+ group: "block",
4376
+ content: "inline*",
4377
+ parseHTML() {
4378
+ return [{ tag: "p" }];
4379
+ },
4380
+ renderHTML({ HTMLAttributes }) {
4381
+ return ["p", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
4382
+ },
4383
+ addCommands() {
4384
+ return {
4385
+ setParagraph: () => ({ commands }) => {
4386
+ return commands.setNode(this.name);
4387
+ }
4388
+ };
4389
+ },
4390
+ addKeyboardShortcuts() {
4391
+ return {
4392
+ "Mod-Alt-0": () => this.editor.commands.setParagraph()
4393
+ };
4394
+ }
4395
+ });
4396
+ var inputRegex = /(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/;
4397
+ var pasteRegex = /(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g;
4398
+ var Strike = Mark.create({
4399
+ name: "strike",
4400
+ addOptions() {
4401
+ return {
4402
+ HTMLAttributes: {}
4403
+ };
4404
+ },
4405
+ parseHTML() {
4406
+ return [
4407
+ {
4408
+ tag: "s"
4409
+ },
4410
+ {
4411
+ tag: "del"
4412
+ },
4413
+ {
4414
+ tag: "strike"
4415
+ },
4416
+ {
4417
+ style: "text-decoration",
4418
+ consuming: false,
4419
+ getAttrs: (style) => style.includes("line-through") ? {} : false
4420
+ }
4421
+ ];
4422
+ },
4423
+ renderHTML({ HTMLAttributes }) {
4424
+ return ["s", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
4425
+ },
4426
+ addCommands() {
4427
+ return {
4428
+ setStrike: () => ({ commands }) => {
4429
+ return commands.setMark(this.name);
4430
+ },
4431
+ toggleStrike: () => ({ commands }) => {
4432
+ return commands.toggleMark(this.name);
4433
+ },
4434
+ unsetStrike: () => ({ commands }) => {
4435
+ return commands.unsetMark(this.name);
4436
+ }
4437
+ };
4438
+ },
4439
+ addKeyboardShortcuts() {
4440
+ return {
4441
+ "Mod-Shift-s": () => this.editor.commands.toggleStrike()
4442
+ };
4443
+ },
4444
+ addInputRules() {
4445
+ return [
4446
+ markInputRule({
4447
+ find: inputRegex,
4448
+ type: this.type
4449
+ })
4450
+ ];
4451
+ },
4452
+ addPasteRules() {
4453
+ return [
4454
+ markPasteRule({
4455
+ find: pasteRegex,
4456
+ type: this.type
4457
+ })
4458
+ ];
4459
+ }
4460
+ });
4461
+ var Text = Node3.create({
4462
+ name: "text",
4463
+ group: "inline"
4464
+ });
4465
+ var Underline = Mark.create({
4466
+ name: "underline",
4467
+ addOptions() {
4468
+ return {
4469
+ HTMLAttributes: {}
4470
+ };
4471
+ },
4472
+ parseHTML() {
4473
+ return [
4474
+ {
4475
+ tag: "u"
4476
+ },
4477
+ {
4478
+ style: "text-decoration",
4479
+ consuming: false,
4480
+ getAttrs: (style) => style.includes("underline") ? {} : false
4481
+ }
4482
+ ];
4483
+ },
4484
+ renderHTML({ HTMLAttributes }) {
4485
+ return ["u", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
4486
+ },
4487
+ addCommands() {
4488
+ return {
4489
+ setUnderline: () => ({ commands }) => {
4490
+ return commands.setMark(this.name);
4491
+ },
4492
+ toggleUnderline: () => ({ commands }) => {
4493
+ return commands.toggleMark(this.name);
4494
+ },
4495
+ unsetUnderline: () => ({ commands }) => {
4496
+ return commands.unsetMark(this.name);
4497
+ }
4498
+ };
4499
+ },
4500
+ addKeyboardShortcuts() {
4501
+ return {
4502
+ "Mod-u": () => this.editor.commands.toggleUnderline(),
4503
+ "Mod-U": () => this.editor.commands.toggleUnderline()
4504
+ };
4505
+ }
4506
+ });
4507
+ var StarterKit = Extension.create({
4508
+ name: "starterKit",
4509
+ addExtensions() {
4510
+ var _a, _b, _c, _d;
4511
+ const extensions = [];
4512
+ if (this.options.bold !== false) {
4513
+ extensions.push(Bold.configure(this.options.bold));
4514
+ }
4515
+ if (this.options.blockquote !== false) {
4516
+ extensions.push(Blockquote.configure(this.options.blockquote));
4517
+ }
4518
+ if (this.options.bulletList !== false) {
4519
+ extensions.push(BulletList.configure(this.options.bulletList));
4520
+ }
4521
+ if (this.options.code !== false) {
4522
+ extensions.push(Code.configure(this.options.code));
4523
+ }
4524
+ if (this.options.codeBlock !== false) {
4525
+ extensions.push(CodeBlock.configure(this.options.codeBlock));
4526
+ }
4527
+ if (this.options.document !== false) {
4528
+ extensions.push(Document.configure(this.options.document));
4529
+ }
4530
+ if (this.options.dropcursor !== false) {
4531
+ extensions.push(Dropcursor.configure(this.options.dropcursor));
4532
+ }
4533
+ if (this.options.gapcursor !== false) {
4534
+ extensions.push(Gapcursor.configure(this.options.gapcursor));
4535
+ }
4536
+ if (this.options.hardBreak !== false) {
4537
+ extensions.push(HardBreak.configure(this.options.hardBreak));
4538
+ }
4539
+ if (this.options.heading !== false) {
4540
+ extensions.push(Heading.configure(this.options.heading));
4541
+ }
4542
+ if (this.options.undoRedo !== false) {
4543
+ extensions.push(UndoRedo.configure(this.options.undoRedo));
4544
+ }
4545
+ if (this.options.horizontalRule !== false) {
4546
+ extensions.push(HorizontalRule.configure(this.options.horizontalRule));
4547
+ }
4548
+ if (this.options.italic !== false) {
4549
+ extensions.push(Italic.configure(this.options.italic));
4550
+ }
4551
+ if (this.options.listItem !== false) {
4552
+ extensions.push(ListItem.configure(this.options.listItem));
4553
+ }
4554
+ if (this.options.listKeymap !== false) {
4555
+ extensions.push(ListKeymap.configure((_a = this.options) == null ? void 0 : _a.listKeymap));
4556
+ }
4557
+ if (this.options.link !== false) {
4558
+ extensions.push(Link.configure((_b = this.options) == null ? void 0 : _b.link));
4559
+ }
4560
+ if (this.options.orderedList !== false) {
4561
+ extensions.push(OrderedList.configure(this.options.orderedList));
4562
+ }
4563
+ if (this.options.paragraph !== false) {
4564
+ extensions.push(Paragraph.configure(this.options.paragraph));
4565
+ }
4566
+ if (this.options.strike !== false) {
4567
+ extensions.push(Strike.configure(this.options.strike));
4568
+ }
4569
+ if (this.options.text !== false) {
4570
+ extensions.push(Text.configure(this.options.text));
4571
+ }
4572
+ if (this.options.underline !== false) {
4573
+ extensions.push(Underline.configure((_c = this.options) == null ? void 0 : _c.underline));
4574
+ }
4575
+ if (this.options.trailingNode !== false) {
4576
+ extensions.push(TrailingNode.configure((_d = this.options) == null ? void 0 : _d.trailingNode));
4577
+ }
4578
+ return extensions;
4579
+ }
4580
+ });
4581
+ var index_default = StarterKit;
4582
+ function useDebouncedRef(value) {
4583
+ return customRef((track, trigger) => {
4584
+ return {
4585
+ get() {
4586
+ track();
4587
+ return value;
4588
+ },
4589
+ set(newValue) {
4590
+ value = newValue;
4591
+ requestAnimationFrame(() => {
4592
+ requestAnimationFrame(() => {
4593
+ trigger();
4594
+ });
4595
+ });
4596
+ }
4597
+ };
4598
+ });
4599
+ }
4600
+ var Editor = class extends Editor$1 {
4601
+ constructor(options = {}) {
4602
+ super(options);
4603
+ this.contentComponent = null;
4604
+ this.appContext = null;
4605
+ this.reactiveState = useDebouncedRef(this.view.state);
4606
+ this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage);
4607
+ this.on("beforeTransaction", ({ nextState }) => {
4608
+ this.reactiveState.value = nextState;
4609
+ this.reactiveExtensionStorage.value = this.extensionStorage;
4610
+ });
4611
+ return markRaw(this);
4612
+ }
4613
+ get state() {
4614
+ return this.reactiveState ? this.reactiveState.value : this.view.state;
4615
+ }
4616
+ get storage() {
4617
+ return this.reactiveExtensionStorage ? this.reactiveExtensionStorage.value : super.storage;
4618
+ }
4619
+ /**
4620
+ * Register a ProseMirror plugin.
4621
+ */
4622
+ registerPlugin(plugin, handlePlugins) {
4623
+ const nextState = super.registerPlugin(plugin, handlePlugins);
4624
+ if (this.reactiveState) {
4625
+ this.reactiveState.value = nextState;
4626
+ }
4627
+ return nextState;
4628
+ }
4629
+ /**
4630
+ * Unregister a ProseMirror plugin.
4631
+ */
4632
+ unregisterPlugin(nameOrPluginKey) {
4633
+ const nextState = super.unregisterPlugin(nameOrPluginKey);
4634
+ if (this.reactiveState && nextState) {
4635
+ this.reactiveState.value = nextState;
4636
+ }
4637
+ return nextState;
4638
+ }
4639
+ };
4640
+ var EditorContent = defineComponent({
4641
+ name: "EditorContent",
4642
+ props: {
4643
+ editor: {
4644
+ default: null,
4645
+ type: Object
4646
+ }
4647
+ },
4648
+ setup(props) {
4649
+ const rootEl = ref();
4650
+ const instance = getCurrentInstance();
4651
+ watchEffect(() => {
4652
+ const editor = props.editor;
4653
+ if (editor && editor.options.element && rootEl.value) {
4654
+ nextTick(() => {
4655
+ var _a;
4656
+ if (!rootEl.value || !((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
4657
+ return;
4658
+ }
4659
+ const element = unref(rootEl.value);
4660
+ rootEl.value.append(...editor.options.element.childNodes);
4661
+ editor.contentComponent = instance.ctx._;
4662
+ if (instance) {
4663
+ editor.appContext = {
4664
+ ...instance.appContext,
4665
+ // Vue internally uses prototype chain to forward/shadow injects across the entire component chain
4666
+ // so don't use object spread operator or 'Object.assign' and just set `provides` as is on editor's appContext
4667
+ // @ts-expect-error forward instance's 'provides' into appContext
4668
+ provides: instance.provides
4669
+ };
4670
+ }
4671
+ editor.setOptions({
4672
+ element
4673
+ });
4674
+ editor.createNodeViews();
4675
+ });
4676
+ }
4677
+ });
4678
+ onBeforeUnmount(() => {
4679
+ const editor = props.editor;
4680
+ if (!editor) {
4681
+ return;
4682
+ }
4683
+ editor.contentComponent = null;
4684
+ editor.appContext = null;
4685
+ });
4686
+ return { rootEl };
4687
+ },
4688
+ render() {
4689
+ return h$1("div", {
4690
+ ref: (el) => {
4691
+ this.rootEl = el;
4692
+ }
4693
+ });
4694
+ }
4695
+ });
4696
+ defineComponent({
4697
+ name: "NodeViewContent",
4698
+ props: {
4699
+ as: {
4700
+ type: String,
4701
+ default: "div"
4702
+ }
4703
+ },
4704
+ render() {
4705
+ return h$1(this.as, {
4706
+ style: {
4707
+ whiteSpace: "pre-wrap"
4708
+ },
4709
+ "data-node-view-content": ""
4710
+ });
4711
+ }
4712
+ });
4713
+ defineComponent({
4714
+ name: "NodeViewWrapper",
4715
+ props: {
4716
+ as: {
4717
+ type: String,
4718
+ default: "div"
4719
+ }
4720
+ },
4721
+ inject: ["onDragStart", "decorationClasses"],
4722
+ render() {
4723
+ var _a, _b;
4724
+ return h$1(
4725
+ this.as,
4726
+ {
4727
+ // @ts-ignore
4728
+ class: this.decorationClasses,
4729
+ style: {
4730
+ whiteSpace: "normal"
4731
+ },
4732
+ "data-node-view-wrapper": "",
4733
+ // @ts-ignore (https://github.com/vuejs/vue-next/issues/3031)
4734
+ onDragstart: this.onDragStart
4735
+ },
4736
+ (_b = (_a = this.$slots).default) == null ? void 0 : _b.call(_a)
4737
+ );
4738
+ }
4739
+ });
4740
+ defineComponent({
4741
+ name: "MarkViewContent",
4742
+ props: {
4743
+ as: {
4744
+ type: String,
4745
+ default: "span"
4746
+ }
4747
+ },
4748
+ render() {
4749
+ return h$1(this.as, {
4750
+ style: {
4751
+ whiteSpace: "inherit"
4752
+ },
4753
+ "data-mark-view-content": ""
4754
+ });
4755
+ }
4756
+ });
4757
+ const _hoisted_1 = {
4758
+ key: 0,
4759
+ class: "celeste-rich-editor"
4760
+ };
4761
+ const _hoisted_2 = { class: "toolbar" };
4762
+ const _hoisted_3 = { class: "select-menu-wrapper" };
4763
+ const _hoisted_4 = { key: 2 };
4764
+ const _hoisted_5 = {
4765
+ key: 2,
4766
+ class: "divider"
4767
+ };
4768
+ const _hoisted_6 = {
4769
+ key: 0,
4770
+ class: "extra-settings-wrapper"
4771
+ };
4772
+ const _hoisted_7 = { class: "text-field" };
4773
+ const _sfc_main = /* @__PURE__ */ defineComponent({
4774
+ __name: "rich-editor",
4775
+ props: {
4776
+ modelValue: {
4777
+ type: String,
4778
+ default: ""
4779
+ },
4780
+ placeholder: {
4781
+ type: String,
4782
+ default: ""
4783
+ },
4784
+ customToolbar: {
4785
+ type: Array,
4786
+ default: () => []
4787
+ },
4788
+ maxLimit: {
4789
+ type: Number,
4790
+ default: null
4791
+ },
4792
+ showExtraSettings: {
4793
+ type: Boolean,
4794
+ default: true
4795
+ }
4796
+ },
4797
+ emits: ["update:modelValue"],
4798
+ setup(__props, { emit: __emit }) {
4799
+ const props = __props;
4800
+ const emit = __emit;
4801
+ const filteredToolbar = computed(() => {
4802
+ const customToolbar = props.customToolbar;
4803
+ if (!customToolbar || customToolbar.length === 0) {
4804
+ return fullToolbar.value;
4805
+ }
4806
+ const toolbarMap = new Map(
4807
+ fullToolbar.value.filter((item) => item.type !== "divider" && "slug" in item).map((item) => [item.slug, item])
4808
+ );
4809
+ return customToolbar.map((key) => {
4810
+ if (key === "divider") {
4811
+ return { type: "divider" };
4812
+ }
4813
+ return toolbarMap.get(key);
4814
+ }).filter((item) => Boolean(item));
4815
+ });
4816
+ const editor = ref();
4817
+ const showSetLinkFromToolbar = ref(false);
4818
+ function openLinkBubbleFromToolbar() {
4819
+ showSetLinkFromToolbar.value = true;
4820
+ }
4821
+ const charactersCount = computed(() => {
4822
+ var _a;
4823
+ return ((_a = editor.value) == null ? void 0 : _a.storage.characterCount.characters()) || 0;
4824
+ });
4825
+ const limitWarning = computed(() => {
4826
+ const isCloseToMaxCharacter = charactersCount.value >= props.maxLimit - 20;
4827
+ const isMaxCharacter = charactersCount.value === props.maxLimit;
4828
+ if (isCloseToMaxCharacter && !isMaxCharacter) {
4829
+ return "warning";
4830
+ }
4831
+ if (isMaxCharacter) {
4832
+ return "danger";
4833
+ }
4834
+ return "";
4835
+ });
4836
+ watch(() => props.modelValue, (value) => {
4837
+ var _a, _b;
4838
+ if (((_a = editor.value) == null ? void 0 : _a.getHTML()) === value) {
4839
+ return;
4840
+ }
4841
+ (_b = editor.value) == null ? void 0 : _b.commands.setContent(value);
4842
+ });
4843
+ onMounted(() => {
4844
+ editor.value = new Editor({
4845
+ content: props.modelValue,
4846
+ extensions: [
4847
+ index_default.configure({
4848
+ link: false
4849
+ }),
4850
+ Placeholder.configure({
4851
+ placeholder: props.placeholder,
4852
+ emptyEditorClass: "is-editor-empty"
4853
+ }),
4854
+ TextStyleKit.configure({
4855
+ color: {
4856
+ types: ["textStyle"]
4857
+ },
4858
+ fontSize: {
4859
+ types: ["textStyle"]
4860
+ }
4861
+ }),
4862
+ index_default$1.configure({
4863
+ types: ["heading", "paragraph"]
4864
+ }),
4865
+ index_default$2.configure({
4866
+ openOnClick: false,
4867
+ autolink: false,
4868
+ HTMLAttributes: {
4869
+ class: "celeste-rich-editor-link",
4870
+ rel: null
4871
+ }
4872
+ }),
4873
+ CharacterCount.configure({
4874
+ limit: props.maxLimit
4875
+ })
4876
+ ],
4877
+ onUpdate: () => {
4878
+ var _a;
4879
+ emit("update:modelValue", ((_a = editor.value) == null ? void 0 : _a.getHTML()) || "");
4880
+ }
4881
+ });
4882
+ });
4883
+ onBeforeUnmount(() => {
4884
+ var _a;
4885
+ (_a = editor.value) == null ? void 0 : _a.destroy();
4886
+ });
4887
+ return (_ctx, _cache) => {
4888
+ return editor.value ? (openBlock(), createElementBlock("div", _hoisted_1, [
4889
+ createElementVNode("div", _hoisted_2, [
4890
+ (openBlock(true), createElementBlock(Fragment$1, null, renderList(filteredToolbar.value, (item, parentIndex) => {
4891
+ return openBlock(), createElementBlock(Fragment$1, { key: parentIndex }, [
4892
+ item.type !== "divider" && !item.children ? (openBlock(), createBlock(Tooltip, {
4893
+ key: 0,
4894
+ title: item.name,
4895
+ variant: "dark"
4896
+ }, {
4897
+ default: withCtx(() => [
4898
+ createVNode(CompactButton, {
4899
+ icon: `${item.icon}`,
4900
+ variant: "ghost",
4901
+ class: normalizeClass({ active: typeof item.active === "string" && editor.value.isActive(item.active) }),
4902
+ onClick: ($event) => unref(onActionClick)(editor.value, item.slug, null, openLinkBubbleFromToolbar)
4903
+ }, null, 8, ["icon", "class", "onClick"])
4904
+ ]),
4905
+ _: 2
4906
+ }, 1032, ["title"])) : item.type !== "divider" && item.children ? (openBlock(), createBlock(Tooltip, {
4907
+ key: 1,
4908
+ title: item.name,
4909
+ variant: "dark"
4910
+ }, {
4911
+ default: withCtx(() => [
4912
+ createElementVNode("div", _hoisted_3, [
4913
+ createVNode(_sfc_main$1, {
4914
+ "model-value": unref(selectedOption)(editor.value, item.children),
4915
+ "onUpdate:modelValue": ($event) => unref(onActionClick)(editor.value, item.slug, $event)
4916
+ }, {
4917
+ default: withCtx(() => [
4918
+ createVNode(SelectTrigger, { variant: "inline" }, {
4919
+ default: withCtx(() => [
4920
+ createVNode(SelectValue)
4921
+ ]),
4922
+ _: 1
4923
+ }),
4924
+ createVNode(SelectContent, {
4925
+ align: "end",
4926
+ width: "fit"
4927
+ }, {
4928
+ default: withCtx(() => [
4929
+ (openBlock(true), createElementBlock(Fragment$1, null, renderList(item.children, (child, childIndex) => {
4930
+ return openBlock(), createBlock(SelectItem, {
4931
+ key: childIndex,
4932
+ value: child.option
4933
+ }, {
4934
+ default: withCtx(() => [
4935
+ item.slug === "color" ? (openBlock(), createElementBlock(Fragment$1, { key: 0 }, [
4936
+ createVNode(SelectIcon, null, {
4937
+ default: withCtx(() => [
4938
+ createElementVNode("i", {
4939
+ class: normalizeClass(child.icon),
4940
+ style: normalizeStyle({ background: child.option })
4941
+ }, null, 6)
4942
+ ]),
4943
+ _: 2
4944
+ }, 1024),
4945
+ createElementVNode("span", null, toDisplayString(child.name), 1)
4946
+ ], 64)) : item.slug === "align" ? (openBlock(), createBlock(SelectIcon, { key: 1 }, {
4947
+ default: withCtx(() => [
4948
+ createElementVNode("i", {
4949
+ class: normalizeClass(child.icon)
4950
+ }, null, 2)
4951
+ ]),
4952
+ _: 2
4953
+ }, 1024)) : (openBlock(), createElementBlock("span", _hoisted_4, toDisplayString(child.name), 1))
4954
+ ]),
4955
+ _: 2
4956
+ }, 1032, ["value"]);
4957
+ }), 128))
4958
+ ]),
4959
+ _: 2
4960
+ }, 1024)
4961
+ ]),
4962
+ _: 2
4963
+ }, 1032, ["model-value", "onUpdate:modelValue"])
4964
+ ])
4965
+ ]),
4966
+ _: 2
4967
+ }, 1032, ["title"])) : (openBlock(), createElementBlock("div", _hoisted_5))
4968
+ ], 64);
4969
+ }), 128)),
4970
+ __props.showExtraSettings ? (openBlock(), createElementBlock("div", _hoisted_6, [
4971
+ _cache[1] || (_cache[1] = createElementVNode("div", { class: "divider" }, null, -1)),
4972
+ createVNode(ExtraSettings, { editor: editor.value }, null, 8, ["editor"])
4973
+ ])) : createCommentVNode("", true)
4974
+ ]),
4975
+ createElementVNode("div", _hoisted_7, [
4976
+ createVNode(unref(EditorContent), { editor: editor.value }, null, 8, ["editor"])
4977
+ ]),
4978
+ __props.maxLimit ? (openBlock(), createElementBlock("div", {
4979
+ key: 0,
4980
+ class: normalizeClass(["characters-count", {
4981
+ warning: limitWarning.value === "warning",
4982
+ danger: limitWarning.value === "danger"
4983
+ }])
4984
+ }, toDisplayString(charactersCount.value) + "/" + toDisplayString(__props.maxLimit), 3)) : createCommentVNode("", true),
4985
+ createVNode(LinkBubble, {
4986
+ editor: editor.value,
4987
+ "show-set-link-from-toolbar": showSetLinkFromToolbar.value,
4988
+ onSetLinkClosed: _cache[0] || (_cache[0] = ($event) => showSetLinkFromToolbar.value = false)
4989
+ }, null, 8, ["editor", "show-set-link-from-toolbar"])
4990
+ ])) : createCommentVNode("", true);
4991
+ };
4992
+ }
4993
+ });
4994
+ const richEditor = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-dbc85b1a"]]);
4995
+ export {
4996
+ richEditor as default
4997
+ };