@commentkit/comment-kit 1.6.0 → 2.0.1

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 (137) hide show
  1. package/CHANGELOG.md +298 -590
  2. package/README.md +421 -145
  3. package/SECURITY.md +47 -46
  4. package/dist/node/THIRD_PARTY_NOTICES.txt +56 -0
  5. package/dist/node/browser.js +17 -0
  6. package/dist/node/cli/api.js +226 -0
  7. package/dist/node/cli/bin.js +18 -0
  8. package/dist/node/cli/credentials.js +268 -0
  9. package/dist/node/cli/doctor.js +789 -0
  10. package/dist/node/cli/format.js +54 -0
  11. package/dist/node/cli/init.js +686 -0
  12. package/dist/node/cli/main.js +537 -0
  13. package/dist/node/cli/mcp.js +295 -0
  14. package/dist/node/cli/open.js +20 -0
  15. package/dist/node/plugins/astro-B5y1Gtbf.js +31 -0
  16. package/dist/node/plugins/astro.js +26 -0
  17. package/dist/node/plugins/git-BIXLbL3f.js +92 -0
  18. package/dist/node/plugins/jsx-Bg4BdSph.js +7958 -0
  19. package/dist/node/plugins/next.js +48 -0
  20. package/dist/node/plugins/options-THop1K92.js +71 -0
  21. package/dist/node/plugins/transform-CKiAuSbk.js +1155 -0
  22. package/dist/node/plugins/vite-BdAYUW10.js +74 -0
  23. package/dist/node/plugins/vite.js +1 -0
  24. package/dist/node/plugins/webpack-R2U2DLlY.js +35 -0
  25. package/dist/node/plugins/webpack-loader.cjs +21 -0
  26. package/dist/node/plugins/webpack-loader.js +18 -0
  27. package/dist/node/plugins/webpack.js +1 -0
  28. package/dist/node/shared/dashboard-places.js +33 -0
  29. package/dist/node/shared/endpoint.js +26 -0
  30. package/dist/node/shared/format.js +63 -0
  31. package/dist/node/types/astro.d.ts +11 -0
  32. package/dist/node/types/next.d.ts +34 -0
  33. package/dist/node/types/options.d.ts +59 -0
  34. package/dist/node/types/vite.d.ts +11 -0
  35. package/dist/node/types/webpack-loader.d.ts +22 -0
  36. package/dist/node/types/webpack.d.ts +27 -0
  37. package/dist/npm/THIRD_PARTY_NOTICES.txt +6 -6
  38. package/dist/npm/chunks/AgentSend-DOy3jhyF.js +68 -0
  39. package/dist/npm/chunks/Checklist-CW_SwMpS.js +282 -0
  40. package/dist/npm/chunks/Composer-Bveq5QrK.js +727 -0
  41. package/dist/npm/chunks/Guest-7hcN765o.js +270 -0
  42. package/dist/npm/chunks/MarkupEditor-6bJGpWGO.js +345 -0
  43. package/dist/npm/chunks/Panel-ChPUB68C.js +1211 -0
  44. package/dist/npm/chunks/Settings-CB5eEKnf.js +231 -0
  45. package/dist/npm/chunks/Shortcuts-eAyjJ89P.js +62 -0
  46. package/dist/npm/chunks/StyleEditor-CZTdAA5c.js +46 -0
  47. package/dist/npm/chunks/StylePanel-B4pHQUL9.js +199 -0
  48. package/dist/npm/chunks/TaskFields-C8BX0Sgg.js +289 -0
  49. package/dist/npm/chunks/ThreadCard-B1EsX3PR.js +1160 -0
  50. package/dist/npm/chunks/Viewer-DY6zb90M.js +114 -0
  51. package/dist/npm/chunks/{agent-BDMQtOzH.js → agent-MTQHr9ei.js} +9 -9
  52. package/dist/npm/chunks/{anchor-BsradQhn.js → anchor-BsQNVkHj.js} +108 -85
  53. package/dist/npm/chunks/{ar-8tPch6W4.js → ar-L5cQ-NPe.js} +71 -19
  54. package/dist/npm/chunks/card-bits-CTdrkYn8.js +53 -0
  55. package/dist/npm/chunks/{client-EFTWxHbJ.js → client-7eVxvg5j.js} +282 -290
  56. package/dist/npm/chunks/confetti-BIs5s14P.js +49 -0
  57. package/dist/npm/chunks/context-BuMl7A07.js +48 -0
  58. package/dist/npm/chunks/context-Cf6khm7A.js +20 -0
  59. package/dist/npm/chunks/{de-C63897uD.js → de-D0C-v6tP.js} +62 -18
  60. package/dist/npm/chunks/dialog-DvdIkCW0.js +3 -0
  61. package/dist/npm/chunks/dpop-0A76OPa9.js +96 -0
  62. package/dist/npm/chunks/drafts-B0ctr1g9.js +21 -0
  63. package/dist/npm/chunks/{es-CI2bSpvB.js → es-Bw4Dj9tN.js} +62 -18
  64. package/dist/npm/chunks/extension-DFVOvciD.js +62 -0
  65. package/dist/npm/chunks/{extension-BST6LH1q.js → extension-SmoH5AA4.js} +20 -12
  66. package/dist/npm/chunks/files-4lV9YQIX.js +114 -0
  67. package/dist/npm/chunks/{fr-rsVe-Lqk.js → fr-TkuQaIAa.js} +120 -76
  68. package/dist/npm/chunks/{hi-cvwbSaWP.js → hi-DXSH2U8d.js} +63 -19
  69. package/dist/npm/chunks/{i18n-C4v0M-6z.js → i18n-aVSu9TcJ.js} +136 -92
  70. package/dist/npm/chunks/identify-BGYh2dVo.js +106 -0
  71. package/dist/npm/chunks/{it-C8tnV0BF.js → it-CiWA_bch.js} +81 -37
  72. package/dist/npm/chunks/{ja-BWxDfC2f.js → ja-C-QmR3yz.js} +60 -16
  73. package/dist/npm/chunks/late-words-80_VWt8S.js +14 -0
  74. package/dist/npm/chunks/live-BExWHzQ7.js +85 -0
  75. package/dist/npm/chunks/locale-D8Q4Q2Nt.js +26 -0
  76. package/dist/npm/chunks/{nl-DNQ6eCht.js → nl-CEmZRqjX.js} +63 -19
  77. package/dist/npm/chunks/page-key-HSY3Lze5.js +62 -0
  78. package/dist/npm/chunks/{pick-CLyOdjnD.js → pick-B3sR7jtS.js} +45 -44
  79. package/dist/npm/chunks/pkce-CfZhiNBi.js +8 -0
  80. package/dist/npm/chunks/placement-BF_HOUDD.js +74 -0
  81. package/dist/npm/chunks/privacy-BWUGlHw5.js +57 -0
  82. package/dist/npm/chunks/{pt-BR-CkG7vpU2.js → pt-BR-b-a8sxO8.js} +62 -18
  83. package/dist/npm/chunks/{realtime-DIo-Wth4.js → realtime-C79zF50C.js} +14 -12
  84. package/dist/npm/chunks/report-DaVuoRYS.js +44 -0
  85. package/dist/npm/chunks/show-BoN8AC-F.js +97 -0
  86. package/dist/npm/chunks/signin-BOWr_WCo.js +75 -0
  87. package/dist/npm/chunks/{source-CS7C6wJA.js → source-mk3rGBBQ.js} +1 -1
  88. package/dist/npm/chunks/src-C8rZFyL_.js +215 -0
  89. package/dist/npm/chunks/start-CV4j78_q.js +1894 -0
  90. package/dist/npm/chunks/states-b9Bv3Ci7.js +3 -0
  91. package/dist/npm/chunks/upload-B2mkgMeJ.js +42 -0
  92. package/dist/npm/chunks/uploads-8AxyRq7g.js +1147 -0
  93. package/dist/npm/chunks/wrap-DW6EFbVQ.js +69 -0
  94. package/dist/npm/chunks/{zh-CN-BKuZOLBE.js → zh-CN-JTscW8u8.js} +61 -17
  95. package/dist/npm/element.js +58 -21
  96. package/dist/npm/headless.js +7 -3
  97. package/dist/npm/index.js +3 -3
  98. package/dist/npm/react.js +18 -11
  99. package/dist/npm/svelte.js +28 -12
  100. package/dist/npm/types/adapters/react.d.ts +4 -1
  101. package/dist/npm/types/adapters/svelte.d.ts +4 -1
  102. package/dist/npm/types/adapters/vue.d.ts +35 -2
  103. package/dist/npm/types/anchor/index.d.ts +19 -0
  104. package/dist/npm/types/capture/privacy.d.ts +14 -0
  105. package/dist/npm/types/core/api.d.ts +20 -1
  106. package/dist/npm/types/core/auth.d.ts +40 -21
  107. package/dist/npm/types/core/client.d.ts +60 -4
  108. package/dist/npm/types/core/page-key.d.ts +42 -0
  109. package/dist/npm/types/core/types.d.ts +87 -4
  110. package/dist/npm/types/element.d.ts +17 -7
  111. package/dist/npm/types/headless.d.ts +2 -1
  112. package/dist/npm/types/index.d.ts +16 -6
  113. package/dist/npm/vue.js +44 -9
  114. package/package.json +90 -14
  115. package/dist/npm/chunks/AgentSend-2JPDseOo.js +0 -63
  116. package/dist/npm/chunks/Checklist-BpDXQebo.js +0 -257
  117. package/dist/npm/chunks/Composer-CAyj-c8e.js +0 -677
  118. package/dist/npm/chunks/Guest-ZdFmTcXI.js +0 -187
  119. package/dist/npm/chunks/MarkupEditor-BFplZwFy.js +0 -332
  120. package/dist/npm/chunks/Panel-BhZ4XRDR.js +0 -861
  121. package/dist/npm/chunks/Settings-SPG9EHUZ.js +0 -204
  122. package/dist/npm/chunks/Shortcuts-C28HVDw6.js +0 -58
  123. package/dist/npm/chunks/StyleEditor-ByZMtq10.js +0 -43
  124. package/dist/npm/chunks/StylePanel-Iwhce2tE.js +0 -197
  125. package/dist/npm/chunks/TaskFields-BsP_fVJg.js +0 -273
  126. package/dist/npm/chunks/ThreadCard-BzVZdDCb.js +0 -1030
  127. package/dist/npm/chunks/Viewer-CqtGrdD8.js +0 -108
  128. package/dist/npm/chunks/card-bits-Bna-g3Py.js +0 -124
  129. package/dist/npm/chunks/confetti-DTKpwF3O.js +0 -40
  130. package/dist/npm/chunks/drafts-akdBsOd0.js +0 -50
  131. package/dist/npm/chunks/extension-D-V3utTm.js +0 -53
  132. package/dist/npm/chunks/live-BCpJVBeN.js +0 -33
  133. package/dist/npm/chunks/report-BBrT3r89.js +0 -27
  134. package/dist/npm/chunks/src-C4FsVoUp.js +0 -148
  135. package/dist/npm/chunks/start-i9M-r3aH.js +0 -1800
  136. package/dist/npm/chunks/upload-DSv7EyBD.js +0 -41
  137. package/dist/npm/chunks/uploads-I01kdqQF.js +0 -1103
@@ -1,1103 +0,0 @@
1
- import { p as e } from "./client-EFTWxHbJ.js";
2
- import { d as t, f as n, l as r, m as i, s as a, u as o } from "./i18n-C4v0M-6z.js";
3
- import { a as s } from "./card-bits-Bna-g3Py.js";
4
- import { d as c, f as l, l as u, m as d, n as f, p } from "./start-i9M-r3aH.js";
5
- // src/ui/editing.ts
6
- function m(e) {
7
- if (!(e.metaKey || e.ctrlKey) || e.altKey) return null;
8
- let t = e.key.toLowerCase();
9
- return e.shiftKey ? t === "x" ? "strike" : null : t === "b" ? "bold" : t === "i" ? "italic" : t === "e" ? "code" : null;
10
- }
11
- function h(e) {
12
- let t = e.replace(/\r\n/g, "\n").split("\n").filter((e) => e.trim());
13
- return t.length < 2 || e.includes("```") ? !1 : t.filter((e) => /[{};]\s*$|^\s*[<}\])]|=>|^\s*(import|export|const|let|var|function|return|if|for|def|class)\b|^\s{2,}\S|^\t/.test(e)).length / t.length >= .5;
14
- }
15
- // src/ui/richtext.ts
16
- var g = {
17
- bold: 1,
18
- italic: 2,
19
- strike: 4,
20
- code: 8
21
- }, _ = [
22
- "bold",
23
- "strike",
24
- "italic",
25
- "code"
26
- ], v = {
27
- bold: "strong",
28
- italic: "em",
29
- strike: "s",
30
- code: "code"
31
- }, y = {
32
- STRONG: 1,
33
- B: 1,
34
- EM: 2,
35
- I: 2,
36
- S: 4,
37
- STRIKE: 4,
38
- DEL: 4,
39
- CODE: 8
40
- }, ee = /^(DIV|P|LI|UL|OL|BLOCKQUOTE|H[1-6])$/, b = 0, x = () => ++b, S = (e, t = 0, n = 0) => e.split("").map((e) => ({
41
- c: e,
42
- m: t,
43
- p: n
44
- })), te = RegExp(`${d}|${p}|(?:^|[\\s(\\[])@[\\p{L}\\p{N}._-]+`, "gu");
45
- function C(e, t, n) {
46
- let r = 0;
47
- for (let i of e.matchAll(te)) {
48
- let a = i[0], o = i.index ?? 0;
49
- /^[\s(\[]/.test(a) && /[_@]/.test(a[1] ?? "") && (o += 1, a = a.slice(1)), o > r && n.push(...S(e.slice(r, o), t)), a.startsWith("**") ? C(a.slice(2, -2), t | g.bold, n) : a.startsWith("~~") ? C(a.slice(2, -2), t | g.strike, n) : a.startsWith("`") ? n.push(...S(a.slice(1, -1), t | g.code)) : a.startsWith("*") || a.startsWith("_") ? C(a.slice(1, -1), t | g.italic, n) : n.push(...S(a, t)), r = o + a.length;
50
- }
51
- r < e.length && n.push(...S(e.slice(r), t));
52
- }
53
- function ne(e, t) {
54
- e.split("\n").forEach((e, n) => {
55
- n && t.push({
56
- c: "\n",
57
- m: 0,
58
- p: 0
59
- }), C(e, 0, t);
60
- });
61
- }
62
- function re(e) {
63
- let t = {
64
- chars: [],
65
- langs: /* @__PURE__ */ new Map()
66
- }, n = 0, r = !1;
67
- for (let i of e.matchAll(c)) {
68
- let a = i.index ?? 0, o = e.slice(n, a).replace(/\n$/, "");
69
- r && (o = o.replace(/^\n/, "")), ne(o, t.chars);
70
- let s = x();
71
- t.langs.set(s, i[1] ?? ""), t.chars.push(...S(i[2].replace(/^\n|\n$/g, ""), 0, s)), n = a + i[0].length, r = !0;
72
- }
73
- let i = e.slice(n);
74
- return r && (i = i.replace(/^\n/, "")), ne(i, t.chars), t;
75
- }
76
- function w(e) {
77
- let t = [];
78
- for (let n of e) {
79
- let e = t[t.length - 1];
80
- e && e.p === n.p ? e.chars.push(n) : t.push({
81
- p: n.p,
82
- chars: [n]
83
- });
84
- }
85
- return t;
86
- }
87
- function T(e) {
88
- let t = [];
89
- for (let n of e) {
90
- let e = t[t.length - 1];
91
- e && e.m === n.m ? e.text += n.c : t.push({
92
- text: n.c,
93
- m: n.m
94
- });
95
- }
96
- return t;
97
- }
98
- function E(e, t) {
99
- let n = [];
100
- for (let r of e) {
101
- let e = (r.m & t) !== 0, i = n[n.length - 1];
102
- i && i.on === e ? i.runs.push(r) : n.push({
103
- on: e,
104
- runs: [r]
105
- });
106
- }
107
- return n;
108
- }
109
- function D(e, t = 0, n = !1) {
110
- if (t === _.length) return e.map((e) => e.text).join("");
111
- let r = _[t], i = "";
112
- for (let a of E(e, g[r])) {
113
- let e = D(a.runs, t + 1, n || a.on && r === "bold");
114
- if (!a.on) {
115
- i += e;
116
- continue;
117
- }
118
- let [, o, s, c] = /^(\s*)([\s\S]*?)(\s*)$/.exec(e);
119
- if (!s) {
120
- i += e;
121
- continue;
122
- }
123
- let l = r === "italic" ? n || s.includes("*") ? "_" : "*" : r === "bold" ? "**" : r === "strike" ? "~~" : "`";
124
- i += o + l + s + l + c;
125
- }
126
- return i;
127
- }
128
- function O(e) {
129
- return w(e.chars).map((t) => {
130
- let n = t.chars.map((e) => e.c).join("");
131
- return t.p ? "```" + (e.langs.get(t.p) ?? "") + "\n" + n + "\n```" : n.split("\n").reduce((e, n) => (e.out.push(D(T(t.chars.slice(e.at, e.at + n.length)))), e.at += n.length + 1, e), {
132
- out: [],
133
- at: 0
134
- }).out.join("\n");
135
- }).join("\n");
136
- }
137
- function ie(e, t, n, r) {
138
- if (n === _.length) {
139
- r.appendChild(e.createTextNode(t.map((e) => e.text).join("")));
140
- return;
141
- }
142
- let i = _[n];
143
- for (let a of E(t, g[i])) ie(e, a.runs, n + 1, a.on ? r.appendChild(e.createElement(v[i])) : r);
144
- }
145
- function ae(e, t) {
146
- let n = t.createDocumentFragment(), r = w(e.chars);
147
- for (let i of r) {
148
- if (i.p) {
149
- let r = n.appendChild(t.createElement("pre"));
150
- r.className = "ck-pre", r.setAttribute("data-block", String(i.p));
151
- let a = e.langs.get(i.p);
152
- a && r.setAttribute("data-lang", a);
153
- let o = i.chars.map((e) => e.c).join("");
154
- r.appendChild(t.createTextNode(o.endsWith("\n") ? o + "\n" : o));
155
- continue;
156
- }
157
- let r = 0;
158
- i.chars.map((e) => e.c).join("").split("\n").forEach((e, a) => {
159
- a && n.appendChild(t.createElement("br")), ie(t, T(i.chars.slice(r, r + e.length)), 0, n), r += e.length + 1;
160
- });
161
- }
162
- let i = r[r.length - 1];
163
- i && (i.p || i.chars[i.chars.length - 1].c === "\n") && n.appendChild(t.createElement("br"));
164
- let a = t.createTreeWalker(n, 4), o = [];
165
- for (; a.nextNode();) a.currentNode.data || o.push(a.currentNode);
166
- for (let e of o) e.parentNode.removeChild(e);
167
- return n;
168
- }
169
- function k(e) {
170
- if (e.nodeType === 3) return e.data.length > 0;
171
- if (e.nodeType !== 1) return !1;
172
- let t = e.tagName;
173
- return t === "BR" || t === "PRE" || t === "IMG" || [...e.childNodes].some(k);
174
- }
175
- function oe(e, t) {
176
- for (let n = e; n && n !== t && !(n.nodeType === 1 && ee.test(n.tagName)); n = n.parentNode) for (let e = n.nextSibling; e; e = e.nextSibling) if (k(e)) return !1;
177
- return !0;
178
- }
179
- function A(e) {
180
- let t = y[e.tagName] ?? 0, n = e.style;
181
- return n && ((n.fontWeight === "bold" || Number(n.fontWeight) >= 600) && (t |= g.bold), n.fontStyle === "italic" && (t |= g.italic), /line-through/.test(n.textDecoration || n.textDecorationLine || "") && (t |= g.strike)), t;
182
- }
183
- function j(e, t = []) {
184
- let n = {
185
- chars: [],
186
- langs: /* @__PURE__ */ new Map(),
187
- stops: [],
188
- points: t.map(() => -1)
189
- }, r = !1, i = 0, a = (e, r, i) => {
190
- t.forEach(([t, a], o) => {
191
- n.points[o] < 0 && t === e && a === r && (n.points[o] = i);
192
- });
193
- }, o = () => {
194
- if (!r) return;
195
- r = !1;
196
- let e = n.chars[n.chars.length - 1];
197
- e && !i && !e.p && n.chars.push({
198
- c: "\n",
199
- m: 0,
200
- p: 0
201
- });
202
- }, s = (c, l) => {
203
- let u = c.childNodes;
204
- for (let d = 0; d < u.length; d++) {
205
- a(c, d, n.chars.length);
206
- let f = u[d];
207
- if (f.nodeType === 3) {
208
- let r = f.data;
209
- if (!r) continue;
210
- o(), i && r.endsWith("\n") && !M(f, e) && (r = r.slice(0, -1)), t.forEach(([e, t], i) => {
211
- n.points[i] < 0 && e === f && (n.points[i] = n.chars.length + Math.min(t, r.length));
212
- }), n.stops.push({
213
- node: f,
214
- start: n.chars.length,
215
- end: n.chars.length + r.length
216
- }), n.chars.push(...S(r.replace(/ /g, " "), i ? 0 : l, i));
217
- continue;
218
- }
219
- if (f.nodeType !== 1) continue;
220
- let p = f;
221
- if (p.tagName === "BR") {
222
- if (oe(p, e)) continue;
223
- o(), n.stops.push({
224
- node: p,
225
- start: n.chars.length,
226
- end: n.chars.length + 1
227
- }), n.chars.push({
228
- c: "\n",
229
- m: 0,
230
- p: i
231
- });
232
- } else if (p.tagName === "PRE" && !i) r = !1, i = Number(p.getAttribute("data-block")) || x(), n.langs.has(i) && (i = x()), n.langs.set(i, p.getAttribute("data-lang") ?? ""), s(p, 0), i = 0;
233
- else if (ee.test(p.tagName) && !i) {
234
- let e = n.chars[n.chars.length - 1];
235
- r ? o() : e && e.c !== "\n" && !e.p && n.chars.push({
236
- c: "\n",
237
- m: 0,
238
- p: 0
239
- }), s(p, l), r = !0;
240
- } else s(p, i ? 0 : l | A(p));
241
- }
242
- a(c, u.length, n.chars.length);
243
- };
244
- return s(e, 0), n;
245
- }
246
- function M(e, t) {
247
- for (let n = e; n && n !== t && (n.nodeType !== 1 || n.tagName !== "PRE"); n = n.parentNode) for (let e = n.nextSibling; e; e = e.nextSibling) if (k(e)) return !0;
248
- return !1;
249
- }
250
- function se(e, t, n = "before") {
251
- let { stops: r } = j(e), i = (e) => !!e.parentElement?.closest("pre"), a = r.filter((e) => e.node.nodeType === 3 && e.start <= t && t <= e.end && (n === "before" || t < e.end || !i(e.node))), o = n === "before" ? a[0] : a[a.length - 1];
252
- if (o) return [o.node, t - o.start];
253
- let s = r.find((e) => e.node.nodeType === 1 && e.end === t);
254
- if (s) return F(s.node);
255
- let c = r.find((e) => e.start >= t && e.end > t);
256
- if (c) return P(c.node);
257
- let l = e.lastChild;
258
- return l && l.nodeName === "BR" ? P(l) : [e, e.childNodes.length];
259
- }
260
- var N = (e) => Array.prototype.indexOf.call(e.parentNode.childNodes, e), P = (e) => [e.parentNode, N(e)], F = (e) => [e.parentNode, N(e) + 1];
261
- function ce(e, t, n) {
262
- let r = e.chars.slice(t, n).filter((e) => e.c !== "\n");
263
- if (t === n) {
264
- let n = e.chars[t - 1];
265
- return n && n.c !== "\n" ? n.p ? g.code : n.m : 0;
266
- }
267
- return r.length ? r.reduce((e, t) => e & (t.p ? g.code : t.m), 15) : 0;
268
- }
269
- function le(e, t, n, r) {
270
- let i = g[r], a = (ce(e, t, n) & i) === 0;
271
- return {
272
- langs: e.langs,
273
- chars: e.chars.map((e, r) => r < t || r >= n || e.p || e.c === "\n" ? e : {
274
- ...e,
275
- m: a ? e.m | i : e.m & ~i
276
- })
277
- };
278
- }
279
- function I(e, t, n, r, i) {
280
- let a = new Map(e.langs);
281
- return i && a.set(i[0], i[1]), {
282
- langs: a,
283
- chars: [
284
- ...e.chars.slice(0, t),
285
- ...r,
286
- ...e.chars.slice(n)
287
- ]
288
- };
289
- }
290
- function ue(e, t) {
291
- let n = t;
292
- for (; n > 0 && e.chars[n - 1].c !== "\n" && !e.chars[n - 1].p;) n--;
293
- return e.chars.slice(n, t).map((e) => e.c).join("");
294
- }
295
- var L = /[\p{L}\p{N}_]/u, R = [
296
- ["**", g.bold],
297
- ["~~", g.strike],
298
- ["`", g.code],
299
- ["*", g.italic],
300
- ["_", g.italic]
301
- ];
302
- function de(e, t) {
303
- let n = e.chars, r = n[t - 1];
304
- if (!r || r.p || r.m & g.code) return null;
305
- let i = n[t];
306
- if (i && !i.p && L.test(i.c)) return null;
307
- let a = t - 1;
308
- for (; a > 0 && n[a - 1].c !== "\n" && !n[a - 1].p;) a--;
309
- let o = n.slice(a, t).map((e) => e.c).join("");
310
- for (let [i, s] of R) {
311
- let c = i.length, l = o.length - c;
312
- if (!o.endsWith(i) || o[l - 1] === i[0]) continue;
313
- let u = o.lastIndexOf(i, l - c - 1);
314
- if (u < 0) continue;
315
- let d = o[u - 1];
316
- if (d !== void 0 && (L.test(d) || d === i[0]) || o[u + c] === i[0]) continue;
317
- let f = o.slice(u + c, l);
318
- if (!f || /^\s|\s$/.test(f) || /:\/\/|^www\./.test(o.slice(0, u).split(/\s/).pop())) continue;
319
- let p = a + u, m = a + l, h = [...n.slice(p, p + c), ...n.slice(m, t)], _ = n.slice(p + c, m);
320
- if (h.some((e) => e.m & g.code) || s === g.code && _.some((e) => e.m & g.code)) continue;
321
- let v = [
322
- ...n.slice(0, p),
323
- ..._.map((e) => ({
324
- ...e,
325
- m: e.m | s
326
- })),
327
- ...n.slice(t)
328
- ];
329
- return {
330
- doc: {
331
- langs: e.langs,
332
- chars: v
333
- },
334
- caret: m - c,
335
- m: r.m
336
- };
337
- }
338
- return null;
339
- }
340
- function fe(e) {
341
- let t = e.getRootNode(), n = e.ownerDocument.getSelection(), r = [], i = t.getSelection;
342
- t !== e.ownerDocument && typeof i == "function" && r.push(() => {
343
- let e = i.call(t);
344
- return e?.rangeCount ? e.getRangeAt(0) : null;
345
- });
346
- let a = n?.getComposedRanges;
347
- t !== e.ownerDocument && n && typeof a == "function" && (r.push(() => a.call(n, { shadowRoots: [t] })[0]), r.push(() => a.call(n, t)[0])), r.push(() => n?.rangeCount ? n.getRangeAt(0) : null);
348
- for (let t of r) {
349
- let n;
350
- try {
351
- n = t();
352
- } catch {
353
- continue;
354
- }
355
- if (n && e.contains(n.startContainer) && e.contains(n.endContainer)) return {
356
- start: [n.startContainer, n.startOffset],
357
- end: [n.endContainer, n.endOffset]
358
- };
359
- }
360
- return null;
361
- }
362
- function pe(e, t, n = t) {
363
- let r = e.getRootNode(), i = (r !== e.ownerDocument && typeof r.getSelection == "function" ? r.getSelection() : null) ?? e.ownerDocument.getSelection();
364
- if (i) try {
365
- i.setBaseAndExtent(t[0], t[1], n[0], n[1]);
366
- } catch {}
367
- }
368
- function me(e, t) {
369
- let n = 0;
370
- for (let r = e; r && r !== t; r = r.parentNode) if (r.nodeType === 1) {
371
- if (r.tagName === "PRE") return g.code;
372
- n |= A(r);
373
- }
374
- return n;
375
- }
376
- function he(e, t) {
377
- for (let n = e; n && n !== t; n = n.parentNode) if (n.nodeType === 1 && n.tagName === "PRE") return Number(n.getAttribute("data-block")) || 0;
378
- return 0;
379
- }
380
- var ge = class {
381
- constructor() {
382
- this.stack = [], this.at = -1, this.open = null, this.time = 0, this.space = !1;
383
- }
384
- reset(e) {
385
- this.stack = [e], this.at = 0, this.open = null;
386
- }
387
- record(e, t, n, r = Date.now()) {
388
- let i = t === "insert" && this.space && !!n && !/^\s/.test(n);
389
- t !== "step" && this.open === t && r - this.time < 500 && !i && this.at >= 0 ? this.stack[this.at] = e : (this.stack.splice(this.at + 1), this.stack.push(e), this.stack.length > 101 && this.stack.shift(), this.at = this.stack.length - 1), this.open = t === "step" ? null : t, this.time = r, this.space = !!n && /\s$/.test(n);
390
- }
391
- select(e, t) {
392
- let n = this.stack[this.at];
393
- !n || n.start === e && n.end === t || (this.stack[this.at] = {
394
- ...n,
395
- start: e,
396
- end: t
397
- }, this.open = null);
398
- }
399
- undo() {
400
- return this.at <= 0 ? null : (this.open = null, this.stack[--this.at]);
401
- }
402
- redo() {
403
- return this.at >= this.stack.length - 1 ? null : (this.open = null, this.stack[++this.at]);
404
- }
405
- }, z = ".ck-textarea{resize:none;field-sizing:content;border-radius:var(--ck-radius-md);border:1px solid var(--ck-border);background:var(--ck-bg);outline:none;width:100%;min-height:68px;max-height:220px;padding:8px 11px;line-height:1.5;transition:border-color .12s,box-shadow .12s;display:block}.ck-textarea:focus{border-color:var(--ck-accent);box-shadow:0 0 0 3px color-mix(in srgb, var(--ck-accent) 18%, transparent);outline:none}.ck-textarea[aria-invalid=true]{border-color:var(--ck-danger)}.ck-editor{overscroll-behavior:contain;white-space:pre-wrap;overflow-wrap:anywhere;cursor:text;text-align:start;-webkit-user-select:text;user-select:text;overflow-y:auto}.ck-editor:empty:before{content:attr(data-placeholder);color:var(--ck-text-muted);opacity:.8;pointer-events:none}.ck-editor[aria-disabled=true]{color:var(--ck-text-muted);cursor:default}.ck-editor strong{font-weight:600}.ck-editor em{font-style:italic}.ck-editor s{color:var(--ck-text-muted)}.ck-editor code{font-family:var(--ck-mono);background:var(--ck-bg-muted);box-shadow:0 0 0 1px var(--ck-hairline);border-radius:5px;padding:1px 5px;font-size:12px}.ck-editor .ck-pre{font-family:var(--ck-mono);white-space:pre-wrap;margin:4px 0;padding:8px 10px;font-size:12px;line-height:1.55}.ck-format [aria-pressed=true]{background:var(--ck-bg-hover);color:var(--ck-text)}.ck-shot{border-radius:var(--ck-radius-md);background:var(--ck-bg-muted);margin-top:10px;position:relative;overflow:hidden}.ck-shot img,.ck-shot canvas{outline:1px solid var(--ck-img-outline);outline-offset:-1px;border-radius:inherit;width:100%;height:auto;display:block}.ck-msg .ck-shot img{object-fit:cover;object-position:top;max-height:150px}.ck-composer .ck-shot{height:140px}.ck-composer .ck-shot img{object-fit:cover;height:100%}.ck-shot-wait{place-items:center;font-size:12px;display:grid}.ck-shot-tools{flex-wrap:wrap;gap:4px;margin-top:8px;display:flex}.ck-composer .ck-shot-tools{margin:0;position:absolute;top:auto;bottom:8px;left:8px;right:8px}.ck-composer .ck-shot-tools .ck-chip{box-shadow:var(--ck-shadow-sm)}.ck-files{flex-wrap:wrap;gap:6px;margin-top:8px;display:flex}.ck-file{background:var(--ck-bg-muted);border-radius:6px;padding:4px 8px;font-size:12px}.ck-suggest{background:var(--ck-bg);max-height:180px;box-shadow:var(--ck-shadow);z-index:3;animation:ck-pop .12s var(--ck-ease);border-radius:12px;padding:4px;position:absolute;bottom:56px;left:14px;right:14px;overflow:auto}.ck-suggest button{border-radius:var(--ck-radius-sm);text-align:start;background:0 0;border:0;align-items:center;gap:8px;width:100%;padding:6px 8px;display:flex}.ck-suggest button[aria-selected=true]{background:var(--ck-bg-hover)}.ck-guest{gap:10px;margin-top:12px;display:grid}.ck-guest-privacy{margin:0;font-size:12px;line-height:1.45}.ck-guest-privacy a{color:inherit;text-underline-offset:2px;text-decoration:underline}.ck-error{color:var(--ck-danger);font-size:12px;font-weight:500}@media (pointer:coarse){.ck-textarea{font-size:16px}}@media (hover:hover){.ck-textarea:hover{border-color:color-mix(in srgb, var(--ck-text-muted) 45%, var(--ck-border))}.ck-suggest button:hover{background:var(--ck-bg-hover)}}.ck-suggest{overscroll-behavior:contain;border:1px solid #0000}.ck-compose{position:relative}.ck-format{gap:2px;margin-top:4px;display:flex}.ck-uploads{flex-wrap:wrap;gap:6px;margin:8px 0 0;padding:0;list-style:none;display:flex}.ck-upload{border-radius:var(--ck-radius-sm);background:var(--ck-bg-muted);max-width:100%;box-shadow:0 0 0 1px var(--ck-hairline);align-items:center;display:flex;position:relative;overflow:hidden}.ck-upload[data-image]{width:56px;height:56px}.ck-upload-thumb{cursor:zoom-in;background:0 0;border:0;width:100%;height:100%;padding:0}.ck-upload-thumb img{object-fit:cover;width:100%;height:100%;display:block}.ck-upload-name{text-overflow:ellipsis;white-space:nowrap;min-width:0;max-width:200px;color:var(--ck-text);align-items:center;gap:5px;padding:6px 28px 6px 9px;font-size:12.5px;display:inline-flex;overflow:hidden}.ck-upload[data-state=uploading] .ck-upload-thumb img{opacity:.6}.ck-upload-bar{left:6px;right:6px;background:#12131626;border-radius:2px;height:3px;position:absolute;bottom:5px;overflow:hidden}.ck-upload-bar>span{background:var(--ck-accent);height:100%;transition:width .16s linear;display:block}.ck-upload[data-state=failed]{box-shadow:0 0 0 1px color-mix(in srgb, var(--ck-danger) 55%, transparent)}.ck-upload-retry{background:var(--ck-danger);color:#fff;border:0;justify-content:center;align-items:center;gap:3px;height:20px;padding:0;font-size:10.5px;font-weight:700;display:flex;position:absolute;top:auto;bottom:0;left:0;right:0}.ck-upload:not([data-image]) .ck-upload-retry{border-radius:6px;height:auto;margin-inline-end:26px;padding:2px 6px;position:static}.ck-upload-remove{top:3px;color:#fff;background:#12131699;border:0;border-radius:50%;place-items:center;width:18px;height:18px;padding:0;display:grid;position:absolute}.ck-upload-remove:not(:-webkit-any(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi))){right:3px}.ck-upload-remove:not(:is(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi))){right:3px}.ck-upload-remove:-webkit-any(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi)){left:3px}.ck-upload-remove:is(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi)){left:3px}.ck-upload:not([data-image]) .ck-upload-remove{color:var(--ck-text-muted);background:0 0;top:50%;translate:0 -50%}@media (pointer:coarse){.ck-upload-remove{top:1px;width:26px;height:26px}.ck-upload-remove:not(:-webkit-any(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi))){right:1px}.ck-upload-remove:not(:is(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi))){right:1px}.ck-upload-remove:-webkit-any(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi)){left:1px}.ck-upload-remove:is(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi)){left:1px}}.ck-extra-add{gap:8px;margin-top:6px;display:flex}.ck-draft-list{gap:4px;margin-top:8px;display:grid}.ck-draft-item{align-items:center;gap:8px;font-size:13px;display:flex}.ck-draft-item bdi{overflow-wrap:anywhere;flex:1;min-width:0}.ck-draft-item .ck-ghost,.ck-checklist li .ck-ghost{flex:none;place-items:center;width:24px;height:24px;min-height:0;padding:0;display:grid}.ck-draft-box{width:13px;height:13px;box-shadow:inset 0 0 0 1.5px var(--ck-border);border-radius:3px;flex:none}.ck-pending-pin{z-index:var(--ck-z);pointer-events:none;filter:drop-shadow(0 0 .6px #fff)drop-shadow(0 3px 6px #12131647);width:30px;height:34px;animation:ck-pin-drop .26s var(--ck-ease);transform-origin:49% 97%;position:fixed;transform:translate(-49%,-97%)}.ck-pending-region{z-index:var(--ck-z);pointer-events:none;border-radius:6px;position:fixed}.ck-pending-pin svg{width:100%;height:100%;position:absolute;top:0;bottom:0;left:0;right:0;overflow:visible}.ck-pending-pin path{fill:var(--ck-accent);stroke:#121316;stroke-width:3px;stroke-linejoin:round}.ck-composer{animation:ck-pop .2s var(--ck-ease) 80ms backwards}.ck-style-list .ck-draft-item code,.ck-style-card li code{overflow-wrap:anywhere;flex:1;min-width:0;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px}.ck-style-card{border-radius:var(--ck-radius-sm);background:var(--ck-bg-muted);margin-top:8px;padding:8px 10px}.ck-style-card-head{color:var(--ck-text-muted);justify-content:space-between;align-items:center;gap:8px;font-size:12px;font-weight:600;display:flex}.ck-style-card ul{gap:3px;margin:6px 0 0;padding:0;list-style:none;display:grid}";
406
- // src/ui/MentionBox.tsx
407
- f(z);
408
- var B = /* @__PURE__ */ new WeakMap();
409
- function _e(e) {
410
- let t = B.get(e);
411
- return t || B.set(e, t = e.people().catch(() => [])), t;
412
- }
413
- var ve = [
414
- {
415
- mark: "bold",
416
- icon: "bold",
417
- label: "formatBold",
418
- keys: "Meta+B"
419
- },
420
- {
421
- mark: "italic",
422
- icon: "italic",
423
- label: "formatItalic",
424
- keys: "Meta+I"
425
- },
426
- {
427
- mark: "strike",
428
- icon: "strike",
429
- label: "formatStrike",
430
- keys: "Meta+Shift+X"
431
- },
432
- {
433
- mark: "code",
434
- icon: "code",
435
- label: "formatCode",
436
- keys: "Meta+E"
437
- }
438
- ], V = 1e4, ye = /(^|\s)@([\p{L}\p{N}._-]{0,30})$/u, be = {
439
- formatBold: "bold",
440
- formatItalic: "italic",
441
- formatStrikeThrough: "strike"
442
- };
443
- function H({ client: e, value: s, onChange: c, onMentions: d, onSubmit: f, placeholder: p, autofocus: _, disabled: v, canMention: y, above: ee }) {
444
- let b = n(null), [te, C] = i([]), [ne, w] = i(null), [T, E] = i(0), [D, ie] = i(/* @__PURE__ */ new Map()), [k] = i(() => typeof matchMedia == "function" && matchMedia("(pointer: coarse)").matches), [oe, A] = i(0), M = n({
445
- chars: [],
446
- langs: /* @__PURE__ */ new Map()
447
- }), N = n(null), P = n(!1), F = n(null), L = n(new ge()).current, R = n(null), z = ne === null ? [] : te.filter((e) => e.name.toLowerCase().includes(ne.toLowerCase())).slice(0, 8), B = (e, t = D) => [...t.entries()].filter(([t]) => e.includes(`@${t}`)).map(([, e]) => e), H = () => {
448
- let e = b.current, t = e && fe(e);
449
- if (!e || !t) return null;
450
- let n = j(e, [t.start, t.end]);
451
- M.current = n;
452
- let [r, i] = n.points;
453
- return {
454
- start: Math.min(r, i),
455
- end: Math.max(r, i),
456
- node: t.start[0],
457
- read: n
458
- };
459
- }, U = () => {
460
- let e = b.current, t = H();
461
- e && t && (F.current && (F.current.at !== t.start || t.start !== t.end) && (F.current = null), !P.current && !R.current && L.select(t.start, t.end), A(t.start === t.end ? F.current?.m ?? me(t.node, e) : ce(t.read, t.start, t.end)));
462
- }, W = (e, t) => {
463
- N.current = e, c(e);
464
- let n = t === null ? null : ye.exec(ue(M.current, t));
465
- w(y && n ? n[2] ?? "" : null), E(0), d(B(e));
466
- }, G = (e, t, n = t, r = "before") => {
467
- let i = b.current;
468
- i && (M.current = e, i.replaceChildren(ae(e, i.ownerDocument)), t !== void 0 && (i.focus({ preventScroll: !0 }), pe(i, se(i, t, r), se(i, n, r))));
469
- }, K = (e, t, n = t, r = "before", i = "step", a) => {
470
- let o = O(e);
471
- o.length > V || (G(e, t, n, r), L.record({
472
- doc: e,
473
- start: t,
474
- end: n
475
- }, i, a), W(o, t), U());
476
- }, q = (e) => {
477
- e && !P.current && (F.current = null, G(e.doc, e.start, e.end), W(O(e.doc), e.end), U());
478
- }, J = () => q(L.undo()), Y = () => q(L.redo()), X = () => {
479
- let e = H();
480
- if (!e || e.start !== e.end) return;
481
- let t = de(e.read, e.start);
482
- t && (K(t.doc, t.caret), F.current = {
483
- at: t.caret,
484
- m: t.m
485
- }, A(t.m));
486
- }, we = () => {
487
- let e = R.current;
488
- if (!e || P.current) return;
489
- R.current = null;
490
- let t = H();
491
- if (!t) return;
492
- let n = e.data ?? "", r = (e) => e.chars.map((e) => e.c).join(""), i = r(t.read), a = r(e.before), o = a.slice(0, e.start), s = a.slice(e.end), c = a.slice(e.start, e.end), l = t.read, u = -1;
493
- if (n && i.length >= o.length + s.length && i.startsWith(o) && i.endsWith(s)) {
494
- let e = i.slice(o.length, i.length - s.length);
495
- u = o.length, c && e === c + n ? l = I(l, u, u + c.length, []) : c && e === n + c ? l = I(l, u + n.length, u + n.length + c.length, []) : e !== n && (u = -1);
496
- }
497
- let d = e.pending;
498
- u >= 0 && d && (l = {
499
- langs: l.langs,
500
- chars: l.chars.map((e, t) => t >= u && t < u + n.length && !e.p && e.c !== "\n" ? {
501
- ...e,
502
- m: d.m
503
- } : e)
504
- }), l === t.read ? (L.record({
505
- doc: l,
506
- start: t.start,
507
- end: t.end
508
- }, "insert", n), U()) : K(l, u + n.length), /[*_~`]$/.test(n) && X();
509
- };
510
- t(() => {
511
- let e = b.current;
512
- if (!e || s === N.current || P.current) return;
513
- N.current = s;
514
- let t = e.getRootNode().activeElement === e, n = re(s);
515
- G(n, t ? n.chars.length : void 0), L.reset({
516
- doc: n,
517
- start: n.chars.length,
518
- end: n.chars.length
519
- });
520
- }, [s]), o(() => {
521
- let e = b.current;
522
- _ && e && (e.focus(), pe(e, se(e, M.current.chars.length)));
523
- }, [_]), o(() => {
524
- y && _e(e).then(C);
525
- }, [e, y]);
526
- let Te = (e, t, n = !1, r = H(), i = "step") => {
527
- let a = b.current;
528
- if (!a || !r) return;
529
- let o = he(r.node, a), s = V - (N.current ?? "").length + (r.end - r.start);
530
- if (s <= 0) return;
531
- if (e = e.replace(/\r\n?/g, "\n").slice(0, s), n && !o) {
532
- let t = x(), n = e.replace(/\n+$/, "");
533
- return K(I(r.read, r.start, r.end, S(n, 0, t), [t, ""]), r.start + n.length, void 0, "after");
534
- }
535
- let c = t ?? (o ? 0 : me(r.node, a));
536
- K(I(r.read, r.start, r.end, S(e, o ? 0 : c, o)), r.start + e.length, void 0, "before", i, e), e === "\n" && c && !o && (F.current = {
537
- at: r.start + 1,
538
- m: c
539
- });
540
- }, Z = (e) => {
541
- let t = H();
542
- if (!t || e.id === null) return;
543
- let n = /@[\p{L}\p{N}._-]*$/u.exec(ue(t.read, t.start)), r = t.start - (n?.[0].length ?? 0), i = /^\d+$/.test(e.id) ? new Map(D).set(e.name, Number(e.id)) : D;
544
- ie(i);
545
- let a = `@${e.name} `, o = I(t.read, r, t.end, S(a, t.read.chars[r]?.m ?? 0)), s = O(o);
546
- s.length > V || (G(o, r + a.length), L.record({
547
- doc: o,
548
- start: r + a.length,
549
- end: r + a.length
550
- }, "step"), N.current = s, w(null), c(s), d(B(s, i)));
551
- }, Q = (e) => {
552
- let t = b.current;
553
- if (!t || v) return;
554
- let n = H();
555
- if (n) {
556
- if (n.start === n.end) {
557
- let r = F.current?.at === n.start ? F.current.m : me(n.node, t);
558
- if (he(n.node, t)) return;
559
- F.current = {
560
- at: n.start,
561
- m: r ^ g[e]
562
- }, A(F.current.m);
563
- } else K(le(n.read, n.start, n.end, e), n.start, n.end);
564
- }
565
- }, $ = n({
566
- insert: Te,
567
- format: Q,
568
- refresh: U,
569
- where: H,
570
- undo: J,
571
- redo: Y,
572
- convert: X,
573
- composed: we
574
- });
575
- return $.current = {
576
- insert: Te,
577
- format: Q,
578
- refresh: U,
579
- where: H,
580
- undo: J,
581
- redo: Y,
582
- convert: X,
583
- composed: we
584
- }, o(() => {
585
- let e = b.current;
586
- if (!e) return;
587
- let t = e.ownerDocument, n = (t) => {
588
- let n = t.inputType;
589
- if (n === "historyUndo" || n === "historyRedo") t.preventDefault(), n === "historyUndo" ? $.current.undo() : $.current.redo();
590
- else if (n.startsWith("format") || /^insert(Un)?orderedList$|^insertHorizontalRule$|^insertLink$/.test(n)) {
591
- t.preventDefault();
592
- let e = be[n];
593
- e && $.current.format(e);
594
- } else {
595
- if (n.startsWith("delete") && !P.current) {
596
- let n = fe(e);
597
- if (n && !Ce(n)) {
598
- t.preventDefault(), $.current.insert("");
599
- return;
600
- }
601
- }
602
- if (n === "insertParagraph" || n === "insertLineBreak") t.preventDefault(), $.current.insert("\n");
603
- else if (n === "insertFromPaste" || n === "insertFromDrop" || n === "insertFromYank") {
604
- t.preventDefault();
605
- let n = t.dataTransfer?.getData("text/plain") ?? t.data ?? "", r = t.getTargetRanges?.()[0];
606
- if (!n) return;
607
- if (r && e.contains(r.startContainer)) {
608
- let t = j(e, [[r.startContainer, r.startOffset], [r.endContainer, r.endOffset]]), [i, a] = t.points;
609
- $.current.insert(n, void 0, h(n), {
610
- start: Math.min(i, a),
611
- end: Math.max(i, a),
612
- node: r.startContainer,
613
- read: t
614
- });
615
- } else $.current.insert(n, void 0, h(n));
616
- } else if (n === "insertText" || n === "insertReplacementText") {
617
- let r = t.data ?? t.dataTransfer?.getData("text/plain") ?? "", i = fe(e), a = O(M.current).length;
618
- if (r && a + r.length > V && (!i || i.start[0] === i.end[0] && i.start[1] === i.end[1])) {
619
- t.preventDefault();
620
- return;
621
- }
622
- if (r && i && !P.current && !Ce(i)) {
623
- t.preventDefault(), F.current = null, $.current.insert(r), n === "insertText" && $.current.convert();
624
- return;
625
- }
626
- let o = F.current;
627
- n === "insertText" && o && r && !P.current && (t.preventDefault(), F.current = null, $.current.insert(r, o.m, !1, void 0, "insert"), $.current.convert());
628
- }
629
- }
630
- }, r = () => {
631
- let e = $.current.where(), t = F.current, n = R.current;
632
- n?.data !== void 0 && e && e.start === e.end && e.start === n.start + n.data.length ? R.current = {
633
- ...n,
634
- data: void 0,
635
- carried: n.data
636
- } : (n?.data !== void 0 && $.current.composed(), R.current = e ? {
637
- start: e.start,
638
- end: e.end,
639
- before: e.read,
640
- pending: t && e.start === e.end && t.at === e.start ? t : null
641
- } : null), P.current = !0, F.current = null;
642
- }, i = (e) => {
643
- P.current = !1, R.current && (R.current.data = (R.current.carried ?? "") + (e.data ?? "")), setTimeout(() => $.current.composed(), 0);
644
- }, a = () => {
645
- e.getRootNode().activeElement === e && $.current.refresh();
646
- };
647
- return e.addEventListener("beforeinput", n), e.addEventListener("compositionstart", r), e.addEventListener("compositionend", i), t.addEventListener("selectionchange", a), () => {
648
- e.removeEventListener("beforeinput", n), e.removeEventListener("compositionstart", r), e.removeEventListener("compositionend", i), t.removeEventListener("selectionchange", a);
649
- };
650
- }, []), /* @__PURE__ */ r("div", {
651
- class: "ck-compose",
652
- children: [
653
- ee,
654
- /* @__PURE__ */ r("div", {
655
- ref: b,
656
- class: "ck-textarea ck-editor",
657
- contenteditable: v ? "false" : "true",
658
- role: "textbox",
659
- "aria-multiline": "true",
660
- dir: s ? "auto" : void 0,
661
- "data-placeholder": p,
662
- "aria-placeholder": p,
663
- "aria-label": p,
664
- "aria-disabled": v ? "true" : void 0,
665
- tabIndex: v ? -1 : 0,
666
- spellcheck: !0,
667
- "aria-autocomplete": "list",
668
- "aria-controls": z.length ? "ck-suggest" : void 0,
669
- "aria-activedescendant": z.length ? `ck-opt-${T}` : void 0,
670
- "aria-keyshortcuts": k ? void 0 : "Enter",
671
- onInput: (e) => {
672
- let t = b.current;
673
- if (!t) return;
674
- let n = H(), r = n?.read ?? j(t);
675
- M.current = r;
676
- let i = O(r), a = Se(e.inputType), o = r;
677
- if (i.length > V && !P.current ? (i = i.slice(0, V), o = re(i), G(o, o.chars.length), a = "step") : !i && t.firstChild && !P.current && t.replaceChildren(), W(i, n ? n.start : null), R.current && !P.current) return we();
678
- if (!P.current) {
679
- let t = a === "step" ? o.chars.length : n?.end ?? 0;
680
- L.record({
681
- doc: o,
682
- start: a === "step" ? t : n?.start ?? 0,
683
- end: t
684
- }, a, e.data);
685
- }
686
- U(), !P.current && e.inputType === "insertText" && X();
687
- },
688
- onPaste: (e) => {
689
- if (e.clipboardData?.files.length) return;
690
- e.preventDefault();
691
- let t = e.clipboardData?.getData("text/plain") ?? "";
692
- t && Te(t, void 0, h(t));
693
- },
694
- onKeyDown: (e) => {
695
- if ((e.key !== "Escape" || z.length) && e.stopPropagation(), z.length && [
696
- "ArrowDown",
697
- "ArrowUp",
698
- "Enter",
699
- "Tab",
700
- "Escape"
701
- ].includes(e.key)) {
702
- e.preventDefault(), e.key === "ArrowDown" ? E((e) => (e + 1) % z.length) : e.key === "ArrowUp" ? E((e) => (e - 1 + z.length) % z.length) : e.key === "Escape" ? w(null) : Z(z[T]);
703
- return;
704
- }
705
- let t = e.key.toLowerCase();
706
- if ((e.metaKey || e.ctrlKey) && !e.altKey && !e.isComposing && (t === "z" || t === "y" && e.ctrlKey && !e.metaKey && !xe())) return e.preventDefault(), t === "z" && !e.shiftKey ? J() : Y();
707
- let n = m(e);
708
- if (n) return e.preventDefault(), Q(n);
709
- e.key !== "Enter" || e.shiftKey || e.isComposing || e.keyCode === 229 || k && !e.metaKey && !e.ctrlKey || (e.preventDefault(), f());
710
- }
711
- }),
712
- z.length ? /* @__PURE__ */ r("div", {
713
- class: "ck-suggest",
714
- id: "ck-suggest",
715
- role: "listbox",
716
- "aria-label": a("mentionList"),
717
- children: z.map((e, t) => /* @__PURE__ */ r("button", {
718
- type: "button",
719
- role: "option",
720
- id: `ck-opt-${t}`,
721
- "aria-selected": t === T,
722
- onMouseDown: (t) => {
723
- t.preventDefault(), Z(e);
724
- },
725
- children: [/* @__PURE__ */ r(u, { person: e }), /* @__PURE__ */ r("bdi", { children: e.name })]
726
- }))
727
- }) : null,
728
- /* @__PURE__ */ r("div", {
729
- class: "ck-format",
730
- role: "toolbar",
731
- "aria-label": a("formatting"),
732
- children: ve.map((e) => /* @__PURE__ */ r("button", {
733
- type: "button",
734
- class: "ck-ghost ck-ghost-sm",
735
- "aria-label": a(e.label),
736
- title: `${a(e.label)} (${e.keys.replace("Meta", xe() ? "⌘" : "Ctrl").replace(/\+/g, " ")})`,
737
- "aria-keyshortcuts": e.keys,
738
- "aria-pressed": (oe & g[e.mark]) !== 0,
739
- disabled: v,
740
- onMouseDown: (e) => e.preventDefault(),
741
- onClick: () => Q(e.mark),
742
- children: /* @__PURE__ */ r(l, {
743
- name: e.icon,
744
- size: 14
745
- })
746
- }))
747
- })
748
- ]
749
- });
750
- }
751
- function xe() {
752
- return typeof navigator < "u" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
753
- }
754
- function Se(e) {
755
- return !e || e.startsWith("insertText") || e.startsWith("insertComposition") || e === "insertFromComposition" ? "insert" : e.startsWith("delete") ? "delete" : "step";
756
- }
757
- function Ce(e) {
758
- return e.start[0] === e.end[0] && e.start[1] === e.end[1];
759
- }
760
- // src/ui/style-edit.ts
761
- var U = [
762
- {
763
- property: "font-size",
764
- kind: "length"
765
- },
766
- {
767
- property: "font-weight",
768
- kind: "number"
769
- },
770
- {
771
- property: "line-height",
772
- kind: "length"
773
- },
774
- {
775
- property: "letter-spacing",
776
- kind: "length"
777
- },
778
- {
779
- property: "text-align",
780
- kind: "choice",
781
- options: [
782
- "start",
783
- "left",
784
- "center",
785
- "right",
786
- "end",
787
- "justify"
788
- ]
789
- },
790
- {
791
- property: "color",
792
- kind: "color"
793
- },
794
- {
795
- property: "background-color",
796
- kind: "color"
797
- },
798
- {
799
- property: "border-color",
800
- kind: "color"
801
- },
802
- {
803
- property: "border-width",
804
- kind: "length"
805
- },
806
- {
807
- property: "border-style",
808
- kind: "choice",
809
- options: [
810
- "none",
811
- "solid",
812
- "dashed",
813
- "dotted",
814
- "double"
815
- ]
816
- },
817
- {
818
- property: "border-radius",
819
- kind: "length"
820
- },
821
- {
822
- property: "opacity",
823
- kind: "number"
824
- },
825
- {
826
- property: "margin",
827
- kind: "box"
828
- },
829
- {
830
- property: "padding",
831
- kind: "box"
832
- },
833
- {
834
- property: "width",
835
- kind: "length"
836
- },
837
- {
838
- property: "height",
839
- kind: "length"
840
- },
841
- {
842
- property: "gap",
843
- kind: "length"
844
- },
845
- {
846
- property: "display",
847
- kind: "choice",
848
- options: [
849
- "block",
850
- "inline",
851
- "inline-block",
852
- "flex",
853
- "inline-flex",
854
- "grid",
855
- "none"
856
- ]
857
- }
858
- ], W = new Set(U.map((e) => e.property)), G = /* @__PURE__ */ new Set([
859
- "rgb",
860
- "rgba",
861
- "hsl",
862
- "hsla",
863
- "hwb",
864
- "lab",
865
- "lch",
866
- "oklab",
867
- "oklch",
868
- "color",
869
- "color-mix",
870
- "calc",
871
- "min",
872
- "max",
873
- "clamp",
874
- "var"
875
- ]);
876
- function K(e) {
877
- if (e.length > 120 || !/^[A-Za-z0-9#.%,()/*+ -]*$/.test(e) || /javascript|expression|import/i.test(e)) return !1;
878
- let t = [...e.matchAll(/([A-Za-z-]+)\s*\(/g)].map((e) => e[1].toLowerCase()), n = e.split("(").length - 1;
879
- return t.every((e) => G.has(e)) && n === t.length && n === e.split(")").length - 1;
880
- }
881
- function q(e) {
882
- return typeof e == "string" && W.has(e);
883
- }
884
- function J(e) {
885
- if (!Array.isArray(e)) return [];
886
- let t = /* @__PURE__ */ new Set(), n = [];
887
- for (let r of e) {
888
- if (!r || !q(r.property) || t.has(r.property)) continue;
889
- let e = typeof r.to == "string" && r.to.trim() ? r.to.trim() : null, i = typeof r.from == "string" && r.from.trim() ? r.from.trim() : null;
890
- if (!(e !== null && !K(e) || i !== null && !K(i)) && (t.add(r.property), n.push({
891
- property: r.property,
892
- from: i,
893
- to: e
894
- }), n.length >= 20)) break;
895
- }
896
- return n;
897
- }
898
- function Y(e) {
899
- let t = getComputedStyle(e), n = {};
900
- for (let { property: e } of U) {
901
- let r = X(t, e).trim();
902
- n[e] = K(r) ? r : "";
903
- }
904
- return n;
905
- }
906
- function X(e, t) {
907
- let n = e.getPropertyValue(t);
908
- if (n || ![
909
- "margin",
910
- "padding",
911
- "border-width",
912
- "border-color",
913
- "border-style",
914
- "border-radius"
915
- ].includes(t)) return n;
916
- let r = t === "border-radius" ? [
917
- "top-left",
918
- "top-right",
919
- "bottom-right",
920
- "bottom-left"
921
- ].map((t) => e.getPropertyValue(`border-${t}-radius`)) : [
922
- "top",
923
- "right",
924
- "bottom",
925
- "left"
926
- ].map((n) => e.getPropertyValue(t.startsWith("border-") ? `border-${n}-${t.slice(7)}` : `${t}-${n}`)), [i, a, o, s] = r;
927
- return r.some((e) => !e) ? "" : i === a && a === o && o === s ? i : i === o && a === s ? `${i} ${a}` : a === s ? `${i} ${a} ${o}` : r.join(" ");
928
- }
929
- function we(e) {
930
- return `${e.property} ${e.from || a("styleNotSet")} → ${e.to ?? a("styleRemoved")}`;
931
- }
932
- var Te = class {
933
- constructor(e) {
934
- this.element = e, this.saved = /* @__PURE__ */ new Map(), this.hadStyle = e.hasAttribute("style");
935
- }
936
- apply(e) {
937
- let t = new Map(e.filter((e) => q(e.property) && (e.to === null || K(e.to))).map((e) => [e.property, e.to]));
938
- for (let e of [...this.saved.keys()]) t.has(e) || this.restore(e);
939
- let n = this.element.style;
940
- for (let [e, r] of t) this.saved.has(e) || this.saved.set(e, [e, ...Q[e] ?? []].map((e) => ({
941
- name: e,
942
- value: n.getPropertyValue(e),
943
- priority: n.getPropertyPriority(e)
944
- }))), n.setProperty(e, r ?? "unset", "important");
945
- this.saved.size || this.cleanUp();
946
- }
947
- revert() {
948
- for (let e of [...this.saved.keys()]) this.restore(e);
949
- this.cleanUp();
950
- }
951
- restore(e) {
952
- let t = this.saved.get(e);
953
- this.saved.delete(e);
954
- let n = this.element.style;
955
- for (let { name: e } of [...t].reverse()) n.removeProperty(e);
956
- let r = t[0];
957
- if (r.value) n.setProperty(r.name, r.value, r.priority);
958
- else for (let { name: e, value: r, priority: i } of t.slice(1)) r && n.setProperty(e, r, i);
959
- }
960
- cleanUp() {
961
- !this.hadStyle && this.element.getAttribute("style") === "" && this.element.removeAttribute("style");
962
- }
963
- }, Z = (e) => [
964
- "top",
965
- "right",
966
- "bottom",
967
- "left"
968
- ].map((t) => e.replace("*", t)), Q = {
969
- margin: Z("margin-*"),
970
- padding: Z("padding-*"),
971
- "border-width": Z("border-*-width"),
972
- "border-color": Z("border-*-color"),
973
- "border-style": Z("border-*-style"),
974
- "border-radius": [
975
- "top-left",
976
- "top-right",
977
- "bottom-right",
978
- "bottom-left"
979
- ].map((e) => `border-${e}-radius`),
980
- gap: ["row-gap", "column-gap"]
981
- };
982
- // src/ui/uploads.tsx
983
- f(z);
984
- function $(t, r) {
985
- let [a, c] = i([]), l = n(/* @__PURE__ */ new Map()), u = n(/* @__PURE__ */ new Map()), d = n(/* @__PURE__ */ new Map()), f = n(a);
986
- f.current = a;
987
- let p = (e, t) => c((n) => n.map((n) => n.key === e ? {
988
- ...n,
989
- ...t
990
- } : n)), m = (n) => {
991
- d.current.delete(n.key);
992
- let r = new AbortController();
993
- l.current.set(n.key, r), p(n.key, {
994
- state: "uploading",
995
- progress: 0
996
- });
997
- let i = t.upload(n.file, n.file.name, "file", {
998
- signal: r.signal,
999
- onProgress: (e) => p(n.key, { progress: e })
1000
- }).then((e) => {
1001
- d.current.set(n.key, e.id), p(n.key, {
1002
- state: "done",
1003
- progress: 1,
1004
- attachmentId: e.id
1005
- });
1006
- }).catch((t) => {
1007
- t instanceof e && t.code === "upload_cancelled" || (d.current.set(n.key, "failed"), p(n.key, { state: "failed" }));
1008
- }).finally(() => l.current.delete(n.key));
1009
- u.current.set(n.key, i);
1010
- };
1011
- return o(() => () => {
1012
- l.current.forEach((e) => e.abort()), f.current.forEach((e) => e.preview && URL.revokeObjectURL(e.preview));
1013
- }, []), {
1014
- items: a,
1015
- add: (e) => {
1016
- let n = f.current.map((e) => e.file), i = s(n, e, t.state.get().config?.limits.max_upload_bytes ?? 10485760), a = i.files.filter((e) => !n.includes(e)).map((e) => ({
1017
- key: crypto.randomUUID(),
1018
- file: e,
1019
- preview: e.type.startsWith("image/") ? URL.createObjectURL(e) : null,
1020
- progress: 0,
1021
- state: "uploading",
1022
- attachmentId: null
1023
- }));
1024
- c((e) => [...e, ...a]), a.forEach(m), i.problem && r(i.problem);
1025
- },
1026
- remove: (e) => {
1027
- l.current.get(e.key)?.abort(), e.preview && URL.revokeObjectURL(e.preview), c((t) => t.filter((t) => t.key !== e.key));
1028
- },
1029
- retry: m,
1030
- clear: () => {
1031
- d.current.clear(), f.current.forEach((e) => e.preview && URL.revokeObjectURL(e.preview)), c([]);
1032
- },
1033
- ready: async () => {
1034
- let e = f.current.map((e) => e.key);
1035
- await Promise.all(e.map((e) => u.current.get(e)));
1036
- let t = e.map((e) => d.current.get(e));
1037
- return {
1038
- ids: t.filter((e) => !!e && e !== "failed"),
1039
- missing: t.some((e) => e !== void 0 && e === "failed")
1040
- };
1041
- },
1042
- busy: a.some((e) => e.state === "uploading")
1043
- };
1044
- }
1045
- function Ee({ items: e, onRemove: t, onRetry: n, onOpen: i }) {
1046
- if (!e.length) return null;
1047
- let o = e.filter((e) => e.preview);
1048
- return /* @__PURE__ */ r("ul", {
1049
- class: "ck-uploads",
1050
- "aria-label": a("attachments"),
1051
- children: e.map((e) => /* @__PURE__ */ r("li", {
1052
- class: "ck-upload",
1053
- "data-state": e.state,
1054
- "data-image": e.preview ? "true" : void 0,
1055
- children: [
1056
- e.preview ? /* @__PURE__ */ r("button", {
1057
- class: "ck-upload-thumb",
1058
- "aria-label": a("openImage", { name: e.file.name }),
1059
- onClick: () => i?.(o.indexOf(e)),
1060
- children: /* @__PURE__ */ r("img", {
1061
- src: e.preview,
1062
- alt: ""
1063
- })
1064
- }) : /* @__PURE__ */ r("span", {
1065
- class: "ck-upload-name",
1066
- children: [/* @__PURE__ */ r(l, {
1067
- name: "paperclip",
1068
- size: 13
1069
- }), /* @__PURE__ */ r("bdi", { children: e.file.name })]
1070
- }),
1071
- e.state === "uploading" ? /* @__PURE__ */ r("span", {
1072
- class: "ck-upload-bar",
1073
- role: "progressbar",
1074
- "aria-label": a("uploading", { name: e.file.name }),
1075
- "aria-valuemin": 0,
1076
- "aria-valuemax": 100,
1077
- "aria-valuenow": Math.round(e.progress * 100),
1078
- children: /* @__PURE__ */ r("span", { style: { width: `${Math.round(e.progress * 100)}%` } })
1079
- }) : null,
1080
- e.state === "failed" ? /* @__PURE__ */ r("button", {
1081
- class: "ck-upload-retry",
1082
- "aria-label": a("retryUpload", { name: e.file.name }),
1083
- title: a("uploadFailedShort"),
1084
- onClick: () => n(e),
1085
- children: [/* @__PURE__ */ r(l, {
1086
- name: "alert",
1087
- size: 13
1088
- }), a("retry")]
1089
- }) : null,
1090
- /* @__PURE__ */ r("button", {
1091
- class: "ck-upload-remove",
1092
- "aria-label": a("removeFile", { name: e.file.name }),
1093
- onClick: () => t(e),
1094
- children: /* @__PURE__ */ r(l, {
1095
- name: "close",
1096
- size: 12
1097
- })
1098
- })
1099
- ]
1100
- }))
1101
- });
1102
- }
1103
- export { J as a, we as c, z as d, Te as i, H as l, $ as n, Y as o, U as r, K as s, Ee as t, _e as u };