bridgerte 0.9.0

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.
@@ -0,0 +1,4515 @@
1
+ var Rn = Object.defineProperty;
2
+ var An = (e, t, n) => t in e ? Rn(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var Te = (e, t, n) => An(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { BRIDGE_CONTENT_CHANGE_DEBOUNCE_MS as Bn, isBridgeMessage as Dn, BRIDGE_HEIGHT_CHANGE_THROTTLE_MS as On, defaultBridgeEventTiming as Hn } from "./bridge.js";
5
+ import { B as _e, b as qt, a as Kt } from "./index-CuNKUHed.js";
6
+ import { DecoratorNode as Gt, $applyNodeReplacement as Ve, $getRoot as $, $isElementNode as Be, $createParagraphNode as W, TextNode as Q, $isParagraphNode as $n, $getSelection as A, $isRangeSelection as D, $insertNodes as U, FORMAT_ELEMENT_COMMAND as Fn, $createTextNode as je, FORMAT_TEXT_COMMAND as zn, REDO_COMMAND as Wn, UNDO_COMMAND as Un, OUTDENT_CONTENT_COMMAND as Vn, INDENT_CONTENT_COMMAND as jn, $getNodeByKey as ce, $setSelection as qn, SELECTION_CHANGE_COMMAND as Xt, COMMAND_PRIORITY_LOW as V, KEY_ESCAPE_COMMAND as Jt, KEY_ARROW_DOWN_COMMAND as Kn, KEY_ARROW_UP_COMMAND as Gn, KEY_ENTER_COMMAND as Xn, KEY_BACKSPACE_COMMAND as Jn, COMMAND_PRIORITY_HIGH as Le, KEY_DELETE_COMMAND as Yn, DELETE_CHARACTER_COMMAND as Qn, mergeRegister as Yt, $getNearestNodeFromDOMNode as Zn, CAN_UNDO_COMMAND as er, CAN_REDO_COMMAND as tr, createEditor as nr, CLEAR_HISTORY_COMMAND as rr } from "lexical";
7
+ import { $isHeadingNode as or, $isQuoteNode as ar, $createQuoteNode as sr, $createHeadingNode as ir, registerRichText as lr, HeadingNode as cr, QuoteNode as dr } from "@lexical/rich-text";
8
+ import { $isCodeNode as K, $createCodeNode as ur, getCodeLanguageOptions as mr, CodeNode as Qt, registerCodeHighlighting as gr, PrismTokenizer as pr, CodeHighlightNode as hr } from "@lexical/code";
9
+ import { $isListNode as fr, ListNode as Zt, INSERT_CHECK_LIST_COMMAND as br, INSERT_UNORDERED_LIST_COMMAND as yr, INSERT_ORDERED_LIST_COMMAND as vr, $isListItemNode as wr, registerList as Cr, registerCheckList as _r, ListItemNode as Er } from "@lexical/list";
10
+ import { $isTableSelection as en, $findTableNode as kr, $deleteTableColumnAtSelection as xr, $deleteTableRowAtSelection as Mr, $insertTableColumnAtSelection as Tr, $insertTableRowAtSelection as Lr, INSERT_TABLE_COMMAND as Sr, $findCellNode as Nr, TableNode as De, $isTableRowNode as Pr, $isTableCellNode as Ir, registerTablePlugin as Rr, TableRowNode as Ar, TableCellNode as Br, setScrollableTablesActive as Dr } from "@lexical/table";
11
+ import { $isLinkNode as we, $toggleLink as ot, formatUrl as Or, $createLinkNode as Hr, registerAutoLink as $r, createLinkMatcherWithRegExp as at, LinkNode as Fr, AutoLinkNode as zr } from "@lexical/link";
12
+ import { registerHistory as Wr, createEmptyHistoryState as Ur } from "@lexical/history";
13
+ import { $generateNodesFromDOM as tn, $generateHtmlFromNodes as Vr } from "@lexical/html";
14
+ import { isCommandStateForCommand as jr, defaultMenuSchema as ue, resolveToolbarMenu as Ee, codeBlockLanguagePanel as Oe, tableHeaderMenuItems as qr } from "./native-spec.js";
15
+ import { resolvePayloadPanelSchema as nn } from "./core.js";
16
+ import { $getSelectionStyleValueForProperty as Kr, $setBlocksType as Se, $patchStyleText as st, $trimTextContentFromAnchor as it } from "@lexical/selection";
17
+ import { $getNearestNodeOfType as Gr, $findMatchingParent as Xr, $insertNodeToNearestRoot as Jr } from "@lexical/utils";
18
+ import { autoUpdate as Yr, computePosition as Qr, platform as Zr, offset as eo, flip as to, shift as no } from "@floating-ui/dom";
19
+ const lt = "bridgerte-media", ct = (e, t) => `${e}:${t}`, ee = (e) => typeof e == "number" && Number.isFinite(e) && e > 0 ? Math.floor(e) : void 0, dt = (e) => typeof e == "number" && Number.isFinite(e) ? Math.min(Math.max(e, 0), 100) : void 0, ro = (e) => e === 20 || e === 50 || e === 100, ut = (e) => ro(e) ? e : void 0, mt = (e) => e === "center" || e === "right" ? e : void 0, Ne = (e, t, n) => {
20
+ n && e.setAttribute(t, n);
21
+ }, gt = (e, t, n) => {
22
+ n !== void 0 && e.setAttribute(t, String(n));
23
+ };
24
+ class re extends Gt {
25
+ constructor(n, r) {
26
+ super(r);
27
+ Te(this, "__payload");
28
+ this.__payload = {
29
+ ...n,
30
+ assetId: n.assetId ?? ct(n.mediaType, n.url),
31
+ width: ee(n.width),
32
+ height: ee(n.height),
33
+ duration: ee(n.duration),
34
+ progress: dt(n.progress),
35
+ displayWidthPercent: ut(n.displayWidthPercent),
36
+ align: mt(n.align)
37
+ }, this.__payload.displayWidthPercent === void 0 && delete this.__payload.displayWidthPercent, this.__payload.align === void 0 && delete this.__payload.align;
38
+ }
39
+ static getType() {
40
+ return lt;
41
+ }
42
+ static clone(n) {
43
+ return new re(n.__payload, n.__key);
44
+ }
45
+ createDOM(n) {
46
+ return this.createMediaElement();
47
+ }
48
+ updateDOM(n, r) {
49
+ if (n.__payload === this.__payload) return !1;
50
+ const o = this.createMediaElement();
51
+ return r.replaceWith(o), !0;
52
+ }
53
+ exportDOM(n) {
54
+ return { element: this.createMediaElement() };
55
+ }
56
+ static importDOM() {
57
+ return {
58
+ img: () => ({
59
+ conversion: oo,
60
+ priority: 1
61
+ }),
62
+ video: () => ({
63
+ conversion: ao,
64
+ priority: 1
65
+ })
66
+ };
67
+ }
68
+ static importJSON(n) {
69
+ return oe(n).updateFromJSON(n);
70
+ }
71
+ exportJSON() {
72
+ return {
73
+ ...super.exportJSON(),
74
+ ...this.__payload,
75
+ type: lt
76
+ };
77
+ }
78
+ getTextContent() {
79
+ return this.__payload.title ?? this.__payload.alt ?? this.__payload.url;
80
+ }
81
+ isInline() {
82
+ return !1;
83
+ }
84
+ getAsset() {
85
+ const n = this.__payload, r = {
86
+ id: n.assetId ?? ct(n.mediaType, n.url),
87
+ type: n.mediaType,
88
+ url: n.url,
89
+ status: n.status,
90
+ progress: n.progress,
91
+ poster: n.poster,
92
+ width: n.width,
93
+ height: n.height,
94
+ duration: n.duration,
95
+ mimeType: n.mimeType,
96
+ size: n.size,
97
+ errorMessage: n.errorMessage,
98
+ external: !0
99
+ };
100
+ return n.displayWidthPercent !== void 0 && (r.displayWidthPercent = n.displayWidthPercent), n.align !== void 0 && (r.align = n.align), r;
101
+ }
102
+ updatePayload(n) {
103
+ const r = this.getWritable();
104
+ r.__payload = {
105
+ ...r.__payload,
106
+ ...n,
107
+ width: ee(n.width ?? r.__payload.width),
108
+ height: ee(n.height ?? r.__payload.height),
109
+ duration: ee(n.duration ?? r.__payload.duration),
110
+ progress: dt(n.progress ?? r.__payload.progress),
111
+ displayWidthPercent: Object.prototype.hasOwnProperty.call(
112
+ n,
113
+ "displayWidthPercent"
114
+ ) ? ut(n.displayWidthPercent) : r.__payload.displayWidthPercent,
115
+ align: Object.prototype.hasOwnProperty.call(n, "align") ? mt(n.align) : r.__payload.align
116
+ }, r.__payload.displayWidthPercent === void 0 && delete r.__payload.displayWidthPercent, r.__payload.align === void 0 && delete r.__payload.align;
117
+ }
118
+ createMediaElement() {
119
+ const n = this.__payload, r = document.createElement("figure"), o = n.mediaType === "image" ? document.createElement("img") : document.createElement("video");
120
+ if (r.className = `bridgerte__media bridgerte__media--${n.mediaType}`, r.contentEditable = "false", r.dataset.assetId = n.assetId, r.dataset.mediaType = n.mediaType, r.dataset.status = n.status ?? "success", n.progress !== void 0 && (r.dataset.progress = String(n.progress)), n.align !== void 0 && (r.dataset.align = n.align), n.displayWidthPercent !== void 0 && (r.dataset.displayWidthPercent = String(n.displayWidthPercent), r.style.setProperty(
121
+ "--bridgerte-media-display-width",
122
+ `${n.displayWidthPercent}%`
123
+ )), o.className = "bridgerte__media-element", n.mediaType === "image" ? (o.setAttribute("src", n.url), o.setAttribute("loading", "lazy"), Ne(o, "alt", n.alt ?? n.title)) : (o.setAttribute("src", n.url), o.setAttribute("controls", "true"), o.setAttribute("preload", "metadata"), Ne(o, "poster", n.poster)), Ne(o, "title", n.title), gt(o, "width", n.width), gt(o, "height", n.height), r.append(o), n.status === "uploading" || n.status === "error") {
124
+ const a = document.createElement("figcaption");
125
+ a.className = "bridgerte__media-status", a.textContent = n.status === "error" ? n.errorMessage ?? "上传失败" : `上传中 ${n.progress ?? 0}%`, r.append(a);
126
+ }
127
+ return r;
128
+ }
129
+ }
130
+ const oo = (e) => {
131
+ const t = e instanceof HTMLImageElement ? e : null;
132
+ return {
133
+ node: t != null && t.src ? oe({
134
+ mediaType: "image",
135
+ url: t.src,
136
+ alt: t.alt,
137
+ title: t.title,
138
+ width: t.width,
139
+ height: t.height,
140
+ status: "success"
141
+ }) : null
142
+ };
143
+ }, ao = (e) => {
144
+ const t = e instanceof HTMLVideoElement ? e : null;
145
+ return {
146
+ node: t != null && t.src ? oe({
147
+ mediaType: "video",
148
+ url: t.src,
149
+ poster: t.poster,
150
+ title: t.title,
151
+ width: t.videoWidth || t.width,
152
+ height: t.videoHeight || t.height,
153
+ status: "success"
154
+ }) : null
155
+ };
156
+ }, oe = (e) => Ve(new re(e)), so = (e) => oe({
157
+ mediaType: "image",
158
+ url: e.url,
159
+ alt: e.alt,
160
+ title: e.title,
161
+ width: e.width,
162
+ height: e.height,
163
+ displayWidthPercent: e.displayWidthPercent,
164
+ align: e.align,
165
+ assetId: e.assetId,
166
+ status: "success"
167
+ }), io = (e) => oe({
168
+ mediaType: "video",
169
+ url: e.url,
170
+ poster: e.poster,
171
+ title: e.title,
172
+ width: e.width,
173
+ height: e.height,
174
+ displayWidthPercent: e.displayWidthPercent,
175
+ align: e.align,
176
+ assetId: e.assetId,
177
+ status: "success"
178
+ }), rn = (e) => e instanceof re, le = (e) => {
179
+ const t = (n) => {
180
+ if (rn(n) && n.getAsset().id === e) return n;
181
+ if (!Be(n)) return null;
182
+ for (const r of n.getChildren()) {
183
+ const o = t(r);
184
+ if (o) return o;
185
+ }
186
+ return null;
187
+ };
188
+ return t($());
189
+ }, on = {
190
+ root: {
191
+ type: "root",
192
+ version: 1,
193
+ children: []
194
+ }
195
+ };
196
+ function He(e = {}) {
197
+ return {
198
+ html: e.html ?? "",
199
+ json: e.json ?? on,
200
+ plainText: e.plainText ?? "",
201
+ assets: e.assets ?? [],
202
+ version: e.version ?? _e
203
+ };
204
+ }
205
+ const lo = (e) => e.toJSON(), co = (e) => {
206
+ var t;
207
+ return ((t = e.root.children) == null ? void 0 : t.length) === 0;
208
+ }, uo = (e) => e.read(() => {
209
+ const t = /* @__PURE__ */ new Map(), n = (r) => {
210
+ Be(r) && r.getChildren().forEach((o) => {
211
+ if (rn(o)) {
212
+ const a = o.getAsset();
213
+ t.set(a.id, a);
214
+ return;
215
+ }
216
+ Be(o) && n(o);
217
+ });
218
+ };
219
+ return n($()), [...t.values()];
220
+ }), an = (e, t) => {
221
+ const n = t.read(() => Vr(t)), r = e.read(() => $().getTextContent()), o = uo(e);
222
+ return {
223
+ html: n,
224
+ json: lo(e),
225
+ plainText: r,
226
+ assets: o,
227
+ version: _e
228
+ };
229
+ }, mo = (e, t) => {
230
+ const n = He(t);
231
+ return sn(e, n), an(e.getEditorState(), e);
232
+ }, sn = (e, t) => {
233
+ if (t.json !== on && !co(t.json)) {
234
+ const o = t.json;
235
+ e.setEditorState(e.parseEditorState(o));
236
+ return;
237
+ }
238
+ if (!t.html) {
239
+ e.update(
240
+ () => {
241
+ const o = $();
242
+ o.clear(), o.append(W());
243
+ },
244
+ { discrete: !0 }
245
+ );
246
+ return;
247
+ }
248
+ const r = new DOMParser().parseFromString(t.html, "text/html");
249
+ e.update(
250
+ () => {
251
+ const o = $(), a = tn(e, r);
252
+ o.clear(), o.append(...a);
253
+ },
254
+ { discrete: !0 }
255
+ );
256
+ };
257
+ class de extends Gt {
258
+ static getType() {
259
+ return "bridgerte-divider";
260
+ }
261
+ static clone(t) {
262
+ return new de(t.__key);
263
+ }
264
+ constructor(t) {
265
+ super(t);
266
+ }
267
+ createDOM(t) {
268
+ const n = document.createElement("hr");
269
+ return n.className = "bridgerte__divider", n;
270
+ }
271
+ updateDOM() {
272
+ return !1;
273
+ }
274
+ exportDOM(t) {
275
+ const n = document.createElement("hr");
276
+ return n.className = "bridgerte__divider", { element: n };
277
+ }
278
+ static importDOM() {
279
+ return {
280
+ hr: () => ({
281
+ conversion: go,
282
+ priority: 0
283
+ })
284
+ };
285
+ }
286
+ static importJSON(t) {
287
+ return qe().updateFromJSON(t);
288
+ }
289
+ exportJSON() {
290
+ return {
291
+ ...super.exportJSON(),
292
+ type: de.getType()
293
+ };
294
+ }
295
+ getTextContent() {
296
+ return `
297
+ `;
298
+ }
299
+ isInline() {
300
+ return !1;
301
+ }
302
+ }
303
+ const go = (e) => ({
304
+ node: qe()
305
+ }), qe = () => Ve(new de()), pt = "bridgerte-mention", Ke = "mention", ln = (e) => e.label.startsWith("@") ? e.label : `@${e.label}`, po = (e) => {
306
+ const t = document.createElement("span");
307
+ return t.className = "bridgerte__mention", t.dataset.type = Ke, t.dataset.id = e.id, t.dataset.value = e.value, t.contentEditable = "false", t.textContent = ln(e), e.description && (t.dataset.description = e.description), t;
308
+ };
309
+ class me extends Q {
310
+ constructor(n, r = ln(n), o) {
311
+ super(r, o);
312
+ Te(this, "__item");
313
+ this.__item = n;
314
+ }
315
+ static getType() {
316
+ return pt;
317
+ }
318
+ static clone(n) {
319
+ return new me(n.__item, n.__text, n.__key);
320
+ }
321
+ createDOM(n) {
322
+ const r = super.createDOM(n);
323
+ return r.className = "bridgerte__mention", r.dataset.type = Ke, r.dataset.id = this.__item.id, r.dataset.value = this.__item.value, r.contentEditable = "false", this.__item.description && (r.dataset.description = this.__item.description), r;
324
+ }
325
+ updateDOM(n, r, o) {
326
+ return super.updateDOM(n, r, o) ? !0 : (r.dataset.id = this.__item.id, r.dataset.value = this.__item.value, this.__item.description ? r.dataset.description = this.__item.description : delete r.dataset.description, !1);
327
+ }
328
+ exportDOM(n) {
329
+ return { element: po(this.__item) };
330
+ }
331
+ static importDOM() {
332
+ return {
333
+ span: () => ({
334
+ conversion: ho,
335
+ priority: 2
336
+ })
337
+ };
338
+ }
339
+ static importJSON(n) {
340
+ return Ge(n).updateFromJSON(n);
341
+ }
342
+ exportJSON() {
343
+ return {
344
+ ...super.exportJSON(),
345
+ ...this.__item,
346
+ type: pt
347
+ };
348
+ }
349
+ isTextEntity() {
350
+ return !0;
351
+ }
352
+ isToken() {
353
+ return !0;
354
+ }
355
+ getMentionItem() {
356
+ return this.__item;
357
+ }
358
+ }
359
+ const ho = (e) => {
360
+ var a;
361
+ const t = e instanceof HTMLElement ? e : null;
362
+ if (!t || t.dataset.type !== Ke)
363
+ return { node: null };
364
+ const n = ((a = t.textContent) == null ? void 0 : a.replace(/^@/, "")) || t.dataset.value || "", r = t.dataset.id || t.dataset.value || n, o = t.dataset.value || r;
365
+ return !n || !r || !o ? { node: null } : {
366
+ node: Ge({
367
+ id: r,
368
+ label: n,
369
+ value: o,
370
+ description: t.dataset.description
371
+ })
372
+ };
373
+ }, Ge = (e) => Ve(new me(e).setMode("token")), ht = (e) => e instanceof me, fo = "请输入内容", bo = () => {
374
+ const t = $().getChildren();
375
+ if (t.length === 0) return !0;
376
+ if (t.length > 1) return !1;
377
+ const n = t[0];
378
+ return $n(n) && n.getChildrenSize() === 0;
379
+ }, yo = ({
380
+ editor: e,
381
+ contentElement: t
382
+ }) => {
383
+ const n = e.getEditorState().read(bo);
384
+ t.dataset.empty = String(n);
385
+ }, vo = ({
386
+ editor: e,
387
+ contentElement: t,
388
+ isReadonly: n
389
+ }) => {
390
+ const r = (o) => {
391
+ n() || t.dataset.empty !== "true" || o.button === 0 && (o.preventDefault(), e.focus(() => {
392
+ e.update(() => {
393
+ $().selectStart();
394
+ });
395
+ }));
396
+ };
397
+ return t.addEventListener("pointerdown", r), () => {
398
+ t.removeEventListener("pointerdown", r);
399
+ };
400
+ }, Xe = {
401
+ // 居中对齐菜单使用,和 align 命令的 center value 对应。
402
+ "align-center": '<svg aria-hidden="true" class="lucide lucide-align-center" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M21 5H3" /> <path d="M17 12H7" /> <path d="M19 19H5" /> </svg>',
403
+ // 两端对齐菜单使用,保留段落排版语义,不和普通居中/左右对齐混用。
404
+ "align-justify": '<svg aria-hidden="true" class="lucide lucide-align-justify" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M3 5h18" /> <path d="M3 12h18" /> <path d="M3 19h18" /> </svg>',
405
+ // 左对齐菜单使用,是段落默认对齐方向的显式入口。
406
+ "align-left": '<svg aria-hidden="true" class="lucide lucide-align-left" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M21 5H3" /> <path d="M15 12H3" /> <path d="M17 19H3" /> </svg>',
407
+ // 右对齐菜单使用,和 align 命令的 right value 对应。
408
+ "align-right": '<svg aria-hidden="true" class="lucide lucide-align-right" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M21 5H3" /> <path d="M21 12H9" /> <path d="M21 19H7" /> </svg>',
409
+ // @ mention 插入入口使用,后续 mention 候选菜单仍复用同一语义 key。
410
+ "at-sign": '<svg aria-hidden="true" class="lucide lucide-at-sign" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <circle cx="12" cy="12" r="4" /> <path d="M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8" /> </svg>',
411
+ // 加粗菜单和 hoverbar 加粗按钮共用,表示 format.bold。
412
+ bold: '<svg aria-hidden="true" class="lucide lucide-bold" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8" /> </svg>',
413
+ // 字号菜单使用,表达大小写/字形敏感的文本尺寸设置。
414
+ "case-sensitive": '<svg aria-hidden="true" class="lucide lucide-case-sensitive" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16" /> <path d="M22 9v7" /> <path d="M3.304 13h6.392" /> <circle cx="18.5" cy="12.5" r="3.5" /> </svg>',
415
+ // 行内代码菜单和 hoverbar 行内代码按钮共用,表示 format.inlineCode。
416
+ code: '<svg aria-hidden="true" class="lucide lucide-code" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m16 18 6-6-6-6" /> <path d="m8 6-6 6 6 6" /> </svg>',
417
+ // 表格删除列入口使用,图形保持列方向,和 rows-minus 区分。
418
+ "columns-minus": '<svg aria-hidden="true" class="lucide lucide-between-vertical-end" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <rect width="7" height="13" x="3" y="3" rx="1" /> <path d="m9 22 3-3 3 3" /> <rect width="7" height="13" x="14" y="3" rx="1" /> </svg>',
419
+ // 表格插入列入口使用,图形保持列方向,和 rows-plus 区分。
420
+ "columns-plus": '<svg aria-hidden="true" class="lucide lucide-between-vertical-start" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <rect width="7" height="13" x="3" y="8" rx="1" /> <path d="m15 2-3 3-3-3" /> <rect width="7" height="13" x="14" y="8" rx="1" /> </svg>',
421
+ // 一级标题菜单使用,和 block.heading level 1 对应。
422
+ "heading-1": '<svg aria-hidden="true" class="lucide lucide-heading-1" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 12h8" /> <path d="M4 18V6" /> <path d="M12 18V6" /> <path d="m17 12 3-2v8" /> </svg>',
423
+ // 二级标题菜单使用,和 block.heading level 2 对应。
424
+ "heading-2": '<svg aria-hidden="true" class="lucide lucide-heading-2" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 12h8" /> <path d="M4 18V6" /> <path d="M12 18V6" /> <path d="M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1" /> </svg>',
425
+ // 三级标题菜单使用,和 block.heading level 3 对应。
426
+ "heading-3": '<svg aria-hidden="true" class="lucide lucide-heading-3" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 12h8" /> <path d="M4 18V6" /> <path d="M12 18V6" /> <path d="M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2" /> <path d="M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2" /> </svg>',
427
+ // 四级标题菜单使用,和 block.heading level 4 对应。
428
+ "heading-4": '<svg aria-hidden="true" class="lucide lucide-heading-4" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M12 18V6" /> <path d="M17 10v3a1 1 0 0 0 1 1h3" /> <path d="M21 10v8" /> <path d="M4 12h8" /> <path d="M4 18V6" /> </svg>',
429
+ // 五级标题菜单使用,和 block.heading level 5 对应。
430
+ "heading-5": '<svg aria-hidden="true" class="lucide lucide-heading-5" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 12h8" /> <path d="M4 18V6" /> <path d="M12 18V6" /> <path d="M17 13v-3h4" /> <path d="M17 17.7c.4.2.8.3 1.3.3 1.5 0 2.7-1.1 2.7-2.5S19.8 13 18.3 13H17" /> </svg>',
431
+ // 六级标题菜单使用,和 block.heading level 6 对应。
432
+ "heading-6": '<svg aria-hidden="true" class="lucide lucide-heading-6" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 12h8" /> <path d="M4 18V6" /> <path d="M12 18V6" /> <circle cx="19" cy="16" r="2" /> <path d="M20 10c-2 2-3 3.5-3 6" /> </svg>',
433
+ // 减少缩进菜单使用,和 indent.decrease 命令对应。
434
+ "indent-decrease": '<svg aria-hidden="true" class="lucide lucide-indent-decrease" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M21 5H11" /> <path d="M21 12H11" /> <path d="M21 19H11" /> <path d="m7 8-4 4 4 4" /> </svg>',
435
+ // 增加缩进菜单使用,和 indent.increase 命令对应。
436
+ "indent-increase": '<svg aria-hidden="true" class="lucide lucide-indent-increase" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M21 5H11" /> <path d="M21 12H11" /> <path d="M21 19H11" /> <path d="m3 8 4 4-4 4" /> </svg>',
437
+ // 斜体菜单和 hoverbar 斜体按钮共用,表示 format.italic。
438
+ italic: '<svg aria-hidden="true" class="lucide lucide-italic" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <line x1="19" x2="10" y1="4" y2="4" /> <line x1="14" x2="5" y1="20" y2="20" /> <line x1="15" x2="9" y1="4" y2="20" /> </svg>',
439
+ // 有序列表菜单使用,表示 list.ordered。
440
+ "list-ordered": '<svg aria-hidden="true" class="lucide lucide-list-ordered" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M11 5h10" /> <path d="M11 12h10" /> <path d="M11 19h10" /> <path d="M4 4h1v5" /> <path d="M4 9h2" /> <path d="M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02" /> </svg>',
441
+ // slash command 入口使用,表示打开候选命令列表。
442
+ "list-plus": '<svg aria-hidden="true" class="lucide lucide-list-plus" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M16 5H3" /> <path d="M11 12H3" /> <path d="M16 19H3" /> <path d="M18 9v6" /> <path d="M21 12h-6" /> </svg>',
443
+ // 待办列表菜单使用,表示 list.todo。
444
+ "list-todo": '<svg aria-hidden="true" class="lucide lucide-list-todo" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M13 5h8" /> <path d="M13 12h8" /> <path d="M13 19h8" /> <path d="m3 17 2 2 4-4" /> <rect x="3" y="4" width="6" height="6" rx="1" /> </svg>',
445
+ // 无序列表菜单使用,表示 list.unordered。
446
+ list: '<svg aria-hidden="true" class="lucide lucide-list" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M3 5h.01" /> <path d="M3 12h.01" /> <path d="M3 19h.01" /> <path d="M8 5h13" /> <path d="M8 12h13" /> <path d="M8 19h13" /> </svg>',
447
+ // 全屏切换菜单使用,表示 fullscreen.toggle。
448
+ maximize: '<svg aria-hidden="true" class="lucide lucide-maximize" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M8 3H5a2 2 0 0 0-2 2v3" /> <path d="M21 8V5a2 2 0 0 0-2-2h-3" /> <path d="M3 16v3a2 2 0 0 0 2 2h3" /> <path d="M16 21h3a2 2 0 0 0 2-2v-3" /> </svg>',
449
+ // 分割线菜单使用,表示 block.divider。
450
+ minus: '<svg aria-hidden="true" class="lucide lucide-minus" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M5 12h14" /> </svg>',
451
+ // 背景色菜单使用,表示 format.backgroundColor。
452
+ "paint-bucket": '<svg aria-hidden="true" class="lucide lucide-paint-bucket" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M11 7 6 2" /> <path d="M18.992 12H2.041" /> <path d="M21.145 18.38A3.34 3.34 0 0 1 20 16.5a3.3 3.3 0 0 1-1.145 1.88c-.575.46-.855 1.02-.855 1.595A2 2 0 0 0 20 22a2 2 0 0 0 2-2.025c0-.58-.285-1.13-.855-1.595" /> <path d="m8.5 4.5 2.148-2.148a1.205 1.205 0 0 1 1.704 0l7.296 7.296a1.205 1.205 0 0 1 0 1.704l-7.592 7.592a3.615 3.615 0 0 1-5.112 0l-3.888-3.888a3.615 3.615 0 0 1 0-5.112L5.67 7.33" /> </svg>',
453
+ // 文字颜色菜单使用,表示 format.color。
454
+ palette: '<svg aria-hidden="true" class="lucide lucide-palette" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z" /> <circle cx="13.5" cy="6.5" r=".5" fill="currentColor" /> <circle cx="17.5" cy="10.5" r=".5" fill="currentColor" /> <circle cx="6.5" cy="12.5" r=".5" fill="currentColor" /> <circle cx="8.5" cy="7.5" r=".5" fill="currentColor" /> </svg>',
455
+ // 正文段落菜单使用,表示 block.paragraph。
456
+ pilcrow: '<svg aria-hidden="true" class="lucide lucide-pilcrow" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M13 4v16" /> <path d="M17 4v16" /> <path d="M19 4H9.5a4.5 4.5 0 0 0 0 9H13" /> </svg>',
457
+ // 引用块菜单使用,表示 block.quote。
458
+ quote: '<svg aria-hidden="true" class="lucide lucide-quote" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M16 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" /> <path d="M5 3a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2 1 1 0 0 1 1 1v1a2 2 0 0 1-2 2 1 1 0 0 0-1 1v2a1 1 0 0 0 1 1 6 6 0 0 0 6-6V5a2 2 0 0 0-2-2z" /> </svg>',
459
+ // 重做菜单使用,表示 history.redo。
460
+ redo: '<svg aria-hidden="true" class="lucide lucide-redo" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M21 7v6h-6" /> <path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7" /> </svg>',
461
+ // 清除样式菜单和 hoverbar 清除样式按钮共用,表示 format.clear。
462
+ "remove-formatting": '<svg aria-hidden="true" class="lucide lucide-remove-formatting" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 7V4h16v3" /> <path d="M5 20h6" /> <path d="M13 4 8 20" /> <path d="m15 15 5 5" /> <path d="m20 15-5 5" /> </svg>',
463
+ // 表格删除行入口使用,图形保持行方向,和 columns-minus 区分。
464
+ "rows-minus": '<svg aria-hidden="true" class="lucide lucide-between-horizontal-end" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <rect width="13" height="7" x="3" y="3" rx="1" /> <path d="m22 15-3-3 3-3" /> <rect width="13" height="7" x="3" y="14" rx="1" /> </svg>',
465
+ // 表格插入行入口使用,图形保持行方向,和 columns-plus 区分。
466
+ "rows-plus": '<svg aria-hidden="true" class="lucide lucide-between-horizontal-start" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <rect width="13" height="7" x="8" y="3" rx="1" /> <path d="m2 9 3 3-3 3" /> <rect width="13" height="7" x="8" y="14" rx="1" /> </svg>',
467
+ // 代码块菜单使用,和行内代码的 code icon 区分为块级入口。
468
+ "square-code": '<svg aria-hidden="true" class="lucide lucide-square-code" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m10 9-3 3 3 3" /> <path d="m14 15 3-3-3-3" /> <rect x="3" y="3" width="18" height="18" rx="2" /> </svg>',
469
+ // 删除线菜单和 hoverbar 删除线按钮共用,表示 format.strike。
470
+ strikethrough: '<svg aria-hidden="true" class="lucide lucide-strikethrough" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M16 4H9a3 3 0 0 0-2.83 4" /> <path d="M14 12a4 4 0 0 1 0 8H6" /> <line x1="4" x2="20" y1="12" y2="12" /> </svg>',
471
+ // 下标菜单使用,表示 format.subscript。
472
+ subscript: '<svg aria-hidden="true" class="lucide lucide-subscript" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m4 5 8 8" /> <path d="m12 5-8 8" /> <path d="M20 19h-4c0-1.5.44-2 1.5-2.5S20 15.33 20 14c0-.47-.17-.93-.48-1.29a2.11 2.11 0 0 0-2.62-.44c-.42.24-.74.62-.9 1.07" /> </svg>',
473
+ // 上标菜单使用,表示 format.superscript。
474
+ superscript: '<svg aria-hidden="true" class="lucide lucide-superscript" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m4 19 8-8" /> <path d="m12 19-8-8" /> <path d="M20 12h-4c0-1.5.442-2 1.5-2.5S20 8.334 20 7.002c0-.472-.17-.93-.484-1.29a2.105 2.105 0 0 0-2.617-.436c-.42.239-.738.614-.899 1.06" /> </svg>',
475
+ // 删除整张表格入口使用,沿用 table 轮廓保持表格上下文语义。
476
+ "table-delete": '<svg aria-hidden="true" class="lucide lucide-table" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M12 3v18" /> <rect width="18" height="18" x="3" y="3" rx="2" /> <path d="M3 9h18" /> <path d="M3 15h18" /> </svg>',
477
+ // 插入表格菜单使用,表示 table.insert。
478
+ table: '<svg aria-hidden="true" class="lucide lucide-table" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M12 3v18" /> <rect width="18" height="18" x="3" y="3" rx="2" /> <path d="M3 9h18" /> <path d="M3 15h18" /> </svg>',
479
+ // 清空内容菜单使用,表示 content.clear,危险操作保持清理语义。
480
+ "trash-2": '<svg aria-hidden="true" class="lucide lucide-trash-2" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M10 11v6" /> <path d="M14 11v6" /> <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" /> <path d="M3 6h18" /> <path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" /> </svg>',
481
+ // 字体菜单使用,表示 format.fontFamily。
482
+ type: '<svg aria-hidden="true" class="lucide lucide-type" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M12 4v16" /> <path d="M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2" /> <path d="M9 20h6" /> </svg>',
483
+ // 下划线菜单和 hoverbar 下划线按钮共用,表示 format.underline。
484
+ underline: '<svg aria-hidden="true" class="lucide lucide-underline" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M6 4v6a6 6 0 0 0 12 0V4" /> <line x1="4" x2="20" y1="20" y2="20" /> </svg>',
485
+ // 撤销菜单使用,表示 history.undo。
486
+ undo: '<svg aria-hidden="true" class="lucide lucide-undo" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M3 7v6h6" /> <path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13" /> </svg>',
487
+ // 上传图片菜单使用,和 upload-video 分开,避免媒体类型在原生侧混淆。
488
+ "upload-image": '<svg aria-hidden="true" class="lucide lucide-image" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <rect width="18" height="18" x="3" y="3" rx="2" ry="2" /> <circle cx="9" cy="9" r="2" /> <path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21" /> </svg>',
489
+ // 上传视频菜单使用,和 upload-image 分开,避免媒体类型在原生侧混淆。
490
+ "upload-video": '<svg aria-hidden="true" class="lucide lucide-video" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5" /> <rect x="2" y="6" width="14" height="12" rx="2" /> </svg>',
491
+ // 行高菜单使用,表示 format.lineHeight。
492
+ "wrap-text": '<svg aria-hidden="true" class="lucide lucide-wrap-text" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="m16 16-3 3 3 3" /> <path d="M3 12h14.5a1 1 0 0 1 0 7H13" /> <path d="M3 19h6" /> <path d="M3 5h18" /> </svg>'
493
+ }, wo = (e) => {
494
+ const t = document.createElement("span");
495
+ return t.className = "bridgerte__menu-icon-text", t.textContent = e, t;
496
+ }, Je = (e, t, n) => {
497
+ if (t) {
498
+ e.innerHTML = t;
499
+ return;
500
+ }
501
+ e.append(wo(n));
502
+ }, z = (e, t = {}) => {
503
+ let n = null;
504
+ const r = (s) => {
505
+ const i = n ?? e;
506
+ if (!(!s && !n)) {
507
+ if (s) {
508
+ i.dataset.pressed = "true";
509
+ return;
510
+ }
511
+ delete i.dataset.pressed, n = null;
512
+ }
513
+ }, o = (s) => {
514
+ if (s.pointerType === "mouse") return;
515
+ const i = s.target;
516
+ n = i instanceof HTMLElement && t.targetSelector ? i.closest(t.targetSelector) : e, n && r(!0);
517
+ }, a = () => {
518
+ r(!1);
519
+ };
520
+ return e.addEventListener("pointerdown", o), e.addEventListener("pointerup", a), e.addEventListener("pointercancel", a), e.addEventListener("lostpointercapture", a), () => {
521
+ a(), e.removeEventListener("pointerdown", o), e.removeEventListener("pointerup", a), e.removeEventListener("pointercancel", a), e.removeEventListener("lostpointercapture", a);
522
+ };
523
+ }, ke = (e, t = {}) => e.map((n) => {
524
+ var a;
525
+ const r = (a = t.menuLabels) == null ? void 0 : a[n.id], o = n.payloadPanel ? nn(n.payloadPanel, t.payloadPanelConfig) : void 0;
526
+ return {
527
+ ...n,
528
+ ...r === void 0 ? {} : { label: r },
529
+ ...o === void 0 ? {} : { payloadPanel: o }
530
+ };
531
+ }), cn = (e, t) => {
532
+ const n = t.find((r) => r.command === e.command.type);
533
+ return (n == null ? void 0 : n.value) === void 0 ? void 0 : { value: String(n.value) };
534
+ }, dn = (e, t) => {
535
+ const n = t.find((o) => jr(e.command, o)), r = t.find((o) => o.command === e.command.type);
536
+ return {
537
+ active: (n == null ? void 0 : n.active) === !0,
538
+ disabled: e.payloadPanel ? (r == null ? void 0 : r.disabled) === !0 : (n == null ? void 0 : n.disabled) === !0 || (r == null ? void 0 : r.disabled) === !0
539
+ };
540
+ }, Co = 4, _o = 8, Eo = "button[data-bridgerte-toolbar-item-id]", ko = () => {
541
+ var e;
542
+ return typeof window < "u" && ((e = window.matchMedia) == null ? void 0 : e.call(window, "(hover: hover) and (pointer: fine)").matches) === !0;
543
+ }, ge = (e) => {
544
+ const t = e instanceof Element ? e.closest(Eo) : null;
545
+ return t instanceof HTMLButtonElement ? t : null;
546
+ }, ft = (e, t, n, r, o) => {
547
+ const a = dn(t, n), s = document.createElement("button"), i = r[t.icon] ?? Xe[t.icon];
548
+ s.type = "button", s.className = "bridgerte__toolbar-button", s.disabled = a.disabled, s.dataset.active = String(a.active), s.dataset.bridgerteToolbarItemId = t.id, s.setAttribute("aria-label", t.label), s.setAttribute("aria-pressed", String(a.active)), o && (s.dataset.tooltip = t.label), Je(s, i, t.label), e.append(s);
549
+ }, xo = (e, t, n, r, o) => {
550
+ e.textContent = "";
551
+ let a = "", s = null;
552
+ t.forEach((i) => {
553
+ if (i.type === "separator") {
554
+ a = "", s = null;
555
+ const m = document.createElement("span");
556
+ m.className = "bridgerte__toolbar-separator", m.dataset.separatorId = i.key, m.setAttribute("aria-hidden", "true"), e.append(m);
557
+ return;
558
+ }
559
+ const c = i.type === "button" ? i.item.group : i.key;
560
+ (!s || a !== c) && (a = c, s = document.createElement("div"), s.className = "bridgerte__toolbar-group", s.dataset.group = c, i.type === "group" && s.setAttribute("aria-label", i.title), e.append(s));
561
+ const l = s;
562
+ if (i.type === "button") {
563
+ ft(
564
+ l,
565
+ i.item,
566
+ n,
567
+ r,
568
+ o
569
+ );
570
+ return;
571
+ }
572
+ i.items.forEach((m) => {
573
+ ft(
574
+ l,
575
+ m,
576
+ n,
577
+ r,
578
+ o
579
+ );
580
+ });
581
+ });
582
+ };
583
+ function Mo(e, t) {
584
+ const n = t.placement ?? "top", r = ke(t.menuSchema ?? ue, {
585
+ menuLabels: t.menuLabels,
586
+ payloadPanelConfig: t.payloadPanelConfig
587
+ }), o = Ee(t.toolbarConfig, r), a = o.flatMap((u) => u.type === "button" ? [u.item] : u.type === "group" ? u.items : []), s = t.icons ?? {}, i = ko(), c = document.createElement("div"), l = e.closest(".bridgerte") ?? e;
588
+ let m = !1, C = null, _ = !1;
589
+ const x = z(e, {
590
+ targetSelector: "button[data-bridgerte-toolbar-item-id]"
591
+ }), h = () => {
592
+ l.append(c);
593
+ }, v = (u) => {
594
+ m || (xo(e, o, u, s, i), h());
595
+ }, S = () => {
596
+ m || v(t.editor.getCommandStates());
597
+ }, p = () => {
598
+ c.dataset.visible = "false", c.textContent = "";
599
+ }, w = (u) => {
600
+ const f = u.dataset.tooltip;
601
+ if (!i || !f || C) return;
602
+ const L = u.getBoundingClientRect();
603
+ c.textContent = f, c.dataset.visible = "true", c.style.left = `${L.left + L.width / 2}px`, c.style.top = `${L.top - _o}px`;
604
+ }, T = (u) => {
605
+ const f = ge(u.target);
606
+ f && w(f);
607
+ }, E = (u) => {
608
+ const f = u.relatedTarget, L = ge(u.target);
609
+ L && f instanceof Node && L.contains(f) || p();
610
+ }, P = () => {
611
+ C = null, delete e.dataset.dragging, document.removeEventListener("pointermove", I), document.removeEventListener("pointerup", k), document.removeEventListener("pointercancel", k);
612
+ }, I = (u) => {
613
+ if (!C) return;
614
+ const f = C.startClientX - u.clientX;
615
+ Math.abs(f) > Co && (C.hasDragged = !0, _ = !0, p()), e.scrollLeft = C.startScrollLeft + f;
616
+ }, k = (u) => {
617
+ const f = C;
618
+ P(), f && u.type !== "pointercancel" && f.pointerType !== "mouse" && !f.hasDragged && f.startButton && (g(f.startButton), _ = !0);
619
+ }, b = (u) => {
620
+ if (u.pointerType === "mouse" && u.button !== 0) return;
621
+ const f = ge(u.target);
622
+ u.preventDefault(), C = {
623
+ startClientX: u.clientX,
624
+ startScrollLeft: e.scrollLeft,
625
+ pointerType: u.pointerType,
626
+ hasDragged: !1,
627
+ startButton: f ?? void 0
628
+ }, e.dataset.dragging = "true", p(), document.addEventListener("pointermove", I), document.addEventListener("pointerup", k), document.addEventListener("pointercancel", k);
629
+ }, g = (u) => {
630
+ if (!(u instanceof HTMLButtonElement) || u.disabled) return;
631
+ const f = a.find((L) => L.id === u.dataset.bridgerteToolbarItemId);
632
+ if (f) {
633
+ if (t.editor.focus(), f.payloadPanel) {
634
+ const L = u.getBoundingClientRect();
635
+ t.editor.requestPayloadPanel({
636
+ menuId: f.id,
637
+ command: f.command,
638
+ panel: f.payloadPanel,
639
+ currentValues: cn(f, t.editor.getCommandStates()),
640
+ anchorRect: {
641
+ x: L.left,
642
+ y: L.top,
643
+ width: L.width,
644
+ height: L.height
645
+ }
646
+ });
647
+ return;
648
+ }
649
+ t.editor.executeCommand(f.command);
650
+ }
651
+ }, d = (u) => {
652
+ if (_) {
653
+ _ = !1, u.preventDefault(), u.stopPropagation();
654
+ return;
655
+ }
656
+ const f = ge(u.target);
657
+ f && g(f);
658
+ };
659
+ e.classList.add("bridgerte__toolbar"), c.className = "bridgerte__toolbar-tooltip", c.dataset.visible = "false", e.dataset.placement = n, e.setAttribute("role", "toolbar"), e.setAttribute(
660
+ "aria-label",
661
+ n === "bottom" ? "BridgeRTE tabbar" : "BridgeRTE toolbar"
662
+ ), e.addEventListener("pointerdown", b, !0), e.addEventListener("click", d), i && (e.addEventListener("mouseover", T), e.addEventListener("mouseout", E)), e.addEventListener("focusout", p), h();
663
+ const y = t.editor.subscribeCommandStateChange(v);
664
+ return {
665
+ update: S,
666
+ destroy() {
667
+ m || (m = !0, P(), y(), e.removeEventListener("pointerdown", b, !0), e.removeEventListener("click", d), i && (e.removeEventListener("mouseover", T), e.removeEventListener("mouseout", E)), x(), e.removeEventListener("focusout", p), c.remove(), e.classList.remove("bridgerte__toolbar"), delete e.dataset.placement, e.textContent = "", e.removeAttribute("role"), e.removeAttribute("aria-label"));
668
+ }
669
+ };
670
+ }
671
+ const To = [
672
+ { command: "format.bold", format: "bold" },
673
+ { command: "format.italic", format: "italic" },
674
+ { command: "format.underline", format: "underline" },
675
+ { command: "format.strike", format: "strikethrough" },
676
+ { command: "format.inlineCode", format: "code" },
677
+ { command: "format.superscript", format: "superscript" },
678
+ { command: "format.subscript", format: "subscript" }
679
+ ], Lo = [
680
+ { command: "format.color", property: "color" },
681
+ { command: "format.backgroundColor", property: "background-color" },
682
+ { command: "format.fontSize", property: "font-size" },
683
+ { command: "format.fontFamily", property: "font-family" },
684
+ { command: "format.lineHeight", property: "line-height" }
685
+ ], So = [
686
+ { command: "list.ordered", listType: "ordered" },
687
+ { command: "list.unordered", listType: "unordered" },
688
+ { command: "list.todo", listType: "todo" }
689
+ ], No = [
690
+ "media.pickImage",
691
+ "media.pickVideo"
692
+ ], un = () => {
693
+ const e = A();
694
+ if (!D(e)) return null;
695
+ const t = e.anchor.getNode();
696
+ return t.getKey() === "root" ? t : t.getTopLevelElementOrThrow();
697
+ }, Po = () => {
698
+ const e = un();
699
+ if (!e) return null;
700
+ if (or(e)) {
701
+ const t = Number(e.getTag().replace("h", ""));
702
+ return {
703
+ command: "block.heading",
704
+ value: Number.isNaN(t) ? void 0 : t
705
+ };
706
+ }
707
+ if (ar(e))
708
+ return {
709
+ command: "block.quote"
710
+ };
711
+ if (K(e)) {
712
+ const t = e.getLatest();
713
+ return {
714
+ command: "block.code",
715
+ value: K(t) ? t.getLanguage() ?? "" : ""
716
+ };
717
+ }
718
+ return {
719
+ command: "block.paragraph"
720
+ };
721
+ }, Io = () => {
722
+ const e = un();
723
+ if (!e || !("getFormatType" in e)) return;
724
+ const t = e.getFormatType();
725
+ return t === "" ? void 0 : t;
726
+ }, Ro = () => {
727
+ const e = A();
728
+ if (!D(e)) return null;
729
+ const t = e.anchor.getNode(), n = fr(t) ? t : Gr(t, Zt);
730
+ return n ? n.getListType() === "check" ? "todo" : n.getTag() === "ol" ? "ordered" : "unordered" : null;
731
+ }, Ao = (e) => {
732
+ const t = A();
733
+ if (!D(t)) return;
734
+ const n = Kr(t, e);
735
+ return n === "" ? void 0 : n;
736
+ }, Bo = () => {
737
+ const e = A();
738
+ if (!D(e)) return !1;
739
+ const t = e.anchor.getNode(), n = t.getParent();
740
+ return we(t) || we(n);
741
+ }, Do = (e) => {
742
+ const t = A(), n = D(t), r = Po(), o = Ro(), a = Io(), s = Bo(), i = e.readonly || !n, c = To.map((_) => ({
743
+ command: _.command,
744
+ active: n && t.hasFormat(_.format),
745
+ disabled: i
746
+ })), l = Lo.map((_) => {
747
+ const x = Ao(_.property);
748
+ return {
749
+ command: _.command,
750
+ active: x !== void 0,
751
+ disabled: i,
752
+ value: x
753
+ };
754
+ }), m = So.map((_) => ({
755
+ command: _.command,
756
+ active: o === _.listType,
757
+ disabled: i
758
+ })), C = No.map((_) => ({
759
+ command: _,
760
+ active: !1,
761
+ disabled: e.readonly || !e.canUploadMedia
762
+ }));
763
+ return [
764
+ ...c,
765
+ {
766
+ command: "format.clear",
767
+ active: !1,
768
+ disabled: i
769
+ },
770
+ ...l,
771
+ {
772
+ command: "block.heading",
773
+ active: (r == null ? void 0 : r.command) === "block.heading",
774
+ disabled: i,
775
+ value: (r == null ? void 0 : r.command) === "block.heading" ? r.value : void 0
776
+ },
777
+ {
778
+ command: "block.paragraph",
779
+ active: (r == null ? void 0 : r.command) === "block.paragraph",
780
+ disabled: i
781
+ },
782
+ {
783
+ command: "block.quote",
784
+ active: (r == null ? void 0 : r.command) === "block.quote",
785
+ disabled: i
786
+ },
787
+ {
788
+ command: "block.divider",
789
+ active: !1,
790
+ disabled: e.readonly
791
+ },
792
+ {
793
+ command: "block.code",
794
+ active: (r == null ? void 0 : r.command) === "block.code",
795
+ disabled: e.readonly,
796
+ value: (r == null ? void 0 : r.command) === "block.code" ? r.value : void 0
797
+ },
798
+ ...m,
799
+ {
800
+ command: "align",
801
+ active: a !== void 0,
802
+ disabled: i,
803
+ value: a
804
+ },
805
+ {
806
+ command: "link.set",
807
+ active: s,
808
+ disabled: i
809
+ },
810
+ {
811
+ command: "link.unset",
812
+ active: !1,
813
+ disabled: i || !s
814
+ },
815
+ {
816
+ command: "link.open",
817
+ active: !1,
818
+ disabled: e.readonly || !s
819
+ },
820
+ {
821
+ command: "indent.increase",
822
+ active: !1,
823
+ disabled: i
824
+ },
825
+ {
826
+ command: "indent.decrease",
827
+ active: !1,
828
+ disabled: i
829
+ },
830
+ {
831
+ command: "history.undo",
832
+ active: !1,
833
+ disabled: e.readonly || !e.canUndo
834
+ },
835
+ {
836
+ command: "history.redo",
837
+ active: !1,
838
+ disabled: e.readonly || !e.canRedo
839
+ },
840
+ {
841
+ command: "content.clear",
842
+ active: !1,
843
+ disabled: e.readonly
844
+ },
845
+ ...C,
846
+ {
847
+ command: "table.insert",
848
+ active: !1,
849
+ disabled: e.readonly
850
+ },
851
+ {
852
+ command: "fullscreen.toggle",
853
+ active: !1,
854
+ disabled: !1
855
+ }
856
+ ];
857
+ }, Oo = (e, t) => e.length === t.length && e.every((n, r) => {
858
+ const o = t[r];
859
+ return o !== void 0 && n.command === o.command && n.active === o.active && n.disabled === o.disabled && n.value === o.value;
860
+ }), j = (e, t, n, r) => {
861
+ var o;
862
+ try {
863
+ (o = e.onError) == null || o.call(e, { code: t, message: n, cause: r });
864
+ } catch (a) {
865
+ console.error("[BridgeRTE] onError callback failed.", a);
866
+ }
867
+ }, Ho = (e, t) => {
868
+ var n;
869
+ try {
870
+ (n = e.onChange) == null || n.call(e, t);
871
+ } catch (r) {
872
+ j(e, "callback.onChange", "onChange callback failed.", r);
873
+ }
874
+ }, $o = (e, t) => {
875
+ var n;
876
+ try {
877
+ (n = e.onContentChange) == null || n.call(e, t);
878
+ } catch (r) {
879
+ j(
880
+ e,
881
+ "callback.onContentChange",
882
+ "onContentChange callback failed.",
883
+ r
884
+ );
885
+ }
886
+ }, Fo = (e, t) => {
887
+ var n;
888
+ try {
889
+ (n = e.onCommandStateChange) == null || n.call(e, [...t]);
890
+ } catch (r) {
891
+ j(
892
+ e,
893
+ "callback.onCommandStateChange",
894
+ "onCommandStateChange callback failed.",
895
+ r
896
+ );
897
+ }
898
+ }, zo = (e) => {
899
+ var t;
900
+ try {
901
+ (t = e.onFocus) == null || t.call(e);
902
+ } catch (n) {
903
+ j(e, "callback.onFocus", "onFocus callback failed.", n);
904
+ }
905
+ }, Wo = (e) => {
906
+ var t;
907
+ try {
908
+ (t = e.onBlur) == null || t.call(e);
909
+ } catch (n) {
910
+ j(e, "callback.onBlur", "onBlur callback failed.", n);
911
+ }
912
+ }, Uo = (e, t) => {
913
+ var n;
914
+ try {
915
+ (n = e.onReady) == null || n.call(e, t);
916
+ } catch (r) {
917
+ j(e, "callback.onReady", "onReady callback failed.", r);
918
+ }
919
+ }, Vo = ({
920
+ lexicalEditor: e,
921
+ options: t,
922
+ isDestroyed: n,
923
+ canUploadMedia: r,
924
+ isReadonly: o
925
+ }) => {
926
+ let a = !1, s = !1, i = [];
927
+ const c = /* @__PURE__ */ new Set(), l = () => {
928
+ const C = [...i];
929
+ c.forEach((_) => {
930
+ try {
931
+ _(C);
932
+ } catch (x) {
933
+ j(
934
+ t,
935
+ "callback.commandStateSubscriber",
936
+ "Command state subscriber failed.",
937
+ x
938
+ );
939
+ }
940
+ });
941
+ }, m = (C = !0) => {
942
+ if (n()) return;
943
+ const _ = i;
944
+ e.getEditorState().read(() => {
945
+ i = Do({
946
+ canUndo: a,
947
+ canRedo: s,
948
+ readonly: o(),
949
+ canUploadMedia: r()
950
+ });
951
+ }), C && !Oo(_, i) && (Fo(t, i), l());
952
+ };
953
+ return {
954
+ refreshCommandStates: m,
955
+ getCommandStates() {
956
+ return m(!1), [...i];
957
+ },
958
+ subscribeCommandStateChange(C) {
959
+ return n() ? () => {
960
+ } : (c.add(C), C([...i]), () => {
961
+ c.delete(C);
962
+ });
963
+ },
964
+ setCanUndo(C) {
965
+ a = C, m();
966
+ },
967
+ setCanRedo(C) {
968
+ s = C, m();
969
+ },
970
+ setHistoryAvailability(C, _) {
971
+ a = C, s = _, m();
972
+ },
973
+ destroy() {
974
+ c.clear();
975
+ }
976
+ };
977
+ }, jo = (e) => `upload:${e}:${Date.now()}:${Math.random().toString(36).slice(2)}`, qo = (e) => typeof URL.createObjectURL == "function" ? URL.createObjectURL(e) : e.name, pe = (e) => {
978
+ typeof URL.revokeObjectURL == "function" && e.startsWith("blob:") && URL.revokeObjectURL(e);
979
+ }, bt = (e) => ({
980
+ name: e.name,
981
+ mimeType: e.type || void 0,
982
+ size: e.size,
983
+ data: e
984
+ }), Ko = (e) => typeof DOMException < "u" && e instanceof DOMException && e.name === "AbortError", Go = ({
985
+ container: e,
986
+ lexicalEditor: t,
987
+ options: n,
988
+ isDestroyed: r
989
+ }) => {
990
+ const o = /* @__PURE__ */ new Map();
991
+ let a = 0;
992
+ const s = (p, w) => {
993
+ t.update(() => {
994
+ var T;
995
+ (T = le(p)) == null || T.updatePayload(w);
996
+ });
997
+ }, i = (p) => {
998
+ let w = null;
999
+ return t.update(() => {
1000
+ const T = le(p);
1001
+ if (!T) return;
1002
+ const E = T.getAsset();
1003
+ w = {
1004
+ mediaType: E.type,
1005
+ url: E.url,
1006
+ assetId: E.id,
1007
+ status: E.status,
1008
+ progress: E.progress,
1009
+ poster: E.poster,
1010
+ width: E.width,
1011
+ height: E.height,
1012
+ duration: E.duration,
1013
+ mimeType: E.mimeType,
1014
+ size: E.size,
1015
+ displayWidthPercent: E.displayWidthPercent,
1016
+ align: E.align,
1017
+ errorMessage: E.errorMessage
1018
+ }, T.remove();
1019
+ }), w;
1020
+ }, c = (p, w) => {
1021
+ const T = o.get(p);
1022
+ return (T == null ? void 0 : T.runId) === w;
1023
+ }, l = (p) => {
1024
+ var w;
1025
+ (w = p.abortController) == null || w.abort();
1026
+ }, m = (p, w) => {
1027
+ const T = o.get(p);
1028
+ return T ? (l(T), pe(T.previewUrl), o.delete(p), !0) : !1;
1029
+ }, C = (p, w, T, E) => {
1030
+ t.update(
1031
+ () => {
1032
+ const P = oe({
1033
+ mediaType: p,
1034
+ url: E,
1035
+ assetId: T,
1036
+ status: "uploading",
1037
+ progress: 0,
1038
+ title: w.name,
1039
+ mimeType: w.type || void 0,
1040
+ size: w.size
1041
+ }), I = W();
1042
+ A() || $().selectEnd(), U([P, I]), I.selectStart();
1043
+ },
1044
+ { discrete: !0 }
1045
+ );
1046
+ }, _ = (p, w, T, E) => {
1047
+ s(w, {
1048
+ mediaType: p,
1049
+ url: E.url,
1050
+ poster: E.poster,
1051
+ width: E.width,
1052
+ height: E.height,
1053
+ duration: E.duration,
1054
+ mimeType: E.mimeType,
1055
+ size: E.size,
1056
+ status: "success",
1057
+ progress: 100,
1058
+ errorMessage: void 0
1059
+ }), pe(T);
1060
+ }, x = (p, w, T) => {
1061
+ var E;
1062
+ Ko(T) || (s(w, {
1063
+ mediaType: p,
1064
+ status: "error",
1065
+ errorMessage: "上传失败"
1066
+ }), (E = n.onUploadError) == null || E.call(n, {
1067
+ assetId: w,
1068
+ type: p,
1069
+ cause: T
1070
+ }));
1071
+ }, h = (p) => {
1072
+ const w = n.uploadAdapter;
1073
+ if (!w) return;
1074
+ const T = typeof AbortController == "function" ? new AbortController() : null, E = a + 1;
1075
+ a = E, p.runId = E, p.abortController = T, o.set(p.assetId, p);
1076
+ const P = {
1077
+ assetId: p.assetId,
1078
+ signal: T == null ? void 0 : T.signal,
1079
+ onProgress: (k) => {
1080
+ !c(p.assetId, E) || r() || s(p.assetId, {
1081
+ mediaType: p.type,
1082
+ status: "uploading",
1083
+ progress: k
1084
+ });
1085
+ }
1086
+ };
1087
+ let I;
1088
+ try {
1089
+ I = p.type === "image" ? w.uploadImage(bt(p.file), P) : w.uploadVideo(bt(p.file), P);
1090
+ } catch (k) {
1091
+ c(p.assetId, E) && x(p.type, p.assetId, k);
1092
+ return;
1093
+ }
1094
+ I.then((k) => {
1095
+ r() || !c(p.assetId, E) || (_(p.type, p.assetId, p.previewUrl, k), o.delete(p.assetId));
1096
+ }).catch((k) => {
1097
+ r() || !c(p.assetId, E) || x(p.type, p.assetId, k);
1098
+ });
1099
+ }, v = (p, w) => {
1100
+ if (!n.uploadAdapter) return;
1101
+ const T = jo(p), E = qo(w), P = {
1102
+ assetId: T,
1103
+ type: p,
1104
+ file: w,
1105
+ previewUrl: E,
1106
+ runId: 0,
1107
+ abortController: null
1108
+ };
1109
+ C(p, w, T, E), h(P);
1110
+ };
1111
+ return {
1112
+ pickMediaFile: (p) => {
1113
+ if (!n.uploadAdapter) return;
1114
+ const w = e.ownerDocument.createElement("input");
1115
+ w.type = "file", w.accept = p === "image" ? "image/*" : "video/*", w.style.display = "none", w.addEventListener("change", () => {
1116
+ var E;
1117
+ const T = (E = w.files) == null ? void 0 : E[0];
1118
+ w.remove(), T && v(p, T);
1119
+ }, { once: !0 }), e.append(w), w.click();
1120
+ },
1121
+ uploadMediaFile: v,
1122
+ removeMedia(p) {
1123
+ const w = i(p);
1124
+ !m(p) && (w != null && w.url.startsWith("blob:")) && pe(w.url);
1125
+ },
1126
+ retryMedia(p) {
1127
+ const w = o.get(p);
1128
+ !w || !n.uploadAdapter || (l(w), s(p, {
1129
+ mediaType: w.type,
1130
+ url: w.previewUrl,
1131
+ status: "uploading",
1132
+ progress: 0,
1133
+ errorMessage: void 0
1134
+ }), h(w));
1135
+ },
1136
+ destroy() {
1137
+ o.forEach((p) => {
1138
+ l(p), pe(p.previewUrl);
1139
+ }), o.clear();
1140
+ }
1141
+ };
1142
+ }, Xo = (e) => ur(e), Jo = {
1143
+ 1: "h1",
1144
+ 2: "h2",
1145
+ 3: "h3",
1146
+ 4: "h4",
1147
+ 5: "h5",
1148
+ 6: "h6"
1149
+ }, Yo = {
1150
+ code: "bridgerte__code-block",
1151
+ codeHighlight: {
1152
+ attr: "bridgerte__code-token bridgerte__code-token--attr",
1153
+ "attr-name": "bridgerte__code-token bridgerte__code-token--attr-name",
1154
+ "attr-value": "bridgerte__code-token bridgerte__code-token--attr-value",
1155
+ boolean: "bridgerte__code-token bridgerte__code-token--boolean",
1156
+ builtin: "bridgerte__code-token bridgerte__code-token--builtin",
1157
+ "class-name": "bridgerte__code-token bridgerte__code-token--class-name",
1158
+ comment: "bridgerte__code-token bridgerte__code-token--comment",
1159
+ constant: "bridgerte__code-token bridgerte__code-token--constant",
1160
+ deleted: "bridgerte__code-token bridgerte__code-token--deleted",
1161
+ function: "bridgerte__code-token bridgerte__code-token--function",
1162
+ inserted: "bridgerte__code-token bridgerte__code-token--inserted",
1163
+ keyword: "bridgerte__code-token bridgerte__code-token--keyword",
1164
+ namespace: "bridgerte__code-token bridgerte__code-token--namespace",
1165
+ number: "bridgerte__code-token bridgerte__code-token--number",
1166
+ operator: "bridgerte__code-token bridgerte__code-token--operator",
1167
+ prefix: "bridgerte__code-token bridgerte__code-token--prefix",
1168
+ property: "bridgerte__code-token bridgerte__code-token--property",
1169
+ punctuation: "bridgerte__code-token bridgerte__code-token--punctuation",
1170
+ regex: "bridgerte__code-token bridgerte__code-token--regex",
1171
+ selector: "bridgerte__code-token bridgerte__code-token--selector",
1172
+ string: "bridgerte__code-token bridgerte__code-token--string",
1173
+ tag: "bridgerte__code-token bridgerte__code-token--tag",
1174
+ unchanged: "bridgerte__code-token bridgerte__code-token--unchanged",
1175
+ url: "bridgerte__code-token bridgerte__code-token--url",
1176
+ variable: "bridgerte__code-token bridgerte__code-token--variable"
1177
+ },
1178
+ heading: {
1179
+ h1: "bridgerte__heading bridgerte__heading--h1",
1180
+ h2: "bridgerte__heading bridgerte__heading--h2",
1181
+ h3: "bridgerte__heading bridgerte__heading--h3",
1182
+ h4: "bridgerte__heading bridgerte__heading--h4",
1183
+ h5: "bridgerte__heading bridgerte__heading--h5",
1184
+ h6: "bridgerte__heading bridgerte__heading--h6"
1185
+ },
1186
+ list: {
1187
+ checklist: "bridgerte__list bridgerte__list--todo",
1188
+ ol: "bridgerte__list",
1189
+ ul: "bridgerte__list",
1190
+ listitem: "bridgerte__list-item",
1191
+ listitemChecked: "bridgerte__list-item bridgerte__list-item--checked",
1192
+ listitemUnchecked: "bridgerte__list-item bridgerte__list-item--unchecked"
1193
+ },
1194
+ paragraph: "bridgerte__paragraph",
1195
+ quote: "bridgerte__quote",
1196
+ root: "bridgerte__content-root",
1197
+ text: {
1198
+ bold: "bridgerte__text--bold",
1199
+ code: "bridgerte__code",
1200
+ italic: "bridgerte__text--italic",
1201
+ strikethrough: "bridgerte__text--strike",
1202
+ underline: "bridgerte__text--underline",
1203
+ underlineStrikethrough: "bridgerte__text--underline-strike"
1204
+ },
1205
+ table: "bridgerte__table",
1206
+ tableCell: "bridgerte__table-cell",
1207
+ tableCellHeader: "bridgerte__table-cell bridgerte__table-cell--header",
1208
+ tableRow: "bridgerte__table-row",
1209
+ tableScrollableWrapper: "bridgerte__table-wrapper"
1210
+ }, Qo = (e) => ({
1211
+ setBlockHeading: (l) => {
1212
+ e.update(() => {
1213
+ const m = A();
1214
+ D(m) && Se(m, () => ir(Jo[l]));
1215
+ });
1216
+ },
1217
+ setParagraphBlock: () => {
1218
+ e.update(() => {
1219
+ const l = A();
1220
+ D(l) && Se(l, () => W());
1221
+ });
1222
+ },
1223
+ setQuoteBlock: () => {
1224
+ e.update(() => {
1225
+ const l = A();
1226
+ D(l) && Se(l, () => sr());
1227
+ });
1228
+ },
1229
+ insertDividerBlock: () => {
1230
+ e.update(() => {
1231
+ const l = W();
1232
+ U([qe(), l]), l.selectStart();
1233
+ });
1234
+ },
1235
+ insertCodeBlock: (l) => {
1236
+ e.update(() => {
1237
+ const m = Xo(l), C = W();
1238
+ U([m, C]), m.selectEnd();
1239
+ });
1240
+ },
1241
+ setSelectedCodeBlockLanguage: (l) => {
1242
+ e.update(() => {
1243
+ const m = A();
1244
+ if (!D(m)) return;
1245
+ const C = m.anchor.getNode(), _ = C.getKey() === "root" ? C : C.getTopLevelElementOrThrow();
1246
+ K(_) && _.setLanguage(l);
1247
+ });
1248
+ },
1249
+ clearContent: () => {
1250
+ e.update(() => {
1251
+ const l = $();
1252
+ l.clear(), l.append(W());
1253
+ });
1254
+ },
1255
+ formatAlign: (l) => {
1256
+ e.dispatchCommand(Fn, l);
1257
+ }
1258
+ }), Zo = (e) => ({
1259
+ setLink: (o, a) => {
1260
+ e.update(() => {
1261
+ const s = A(), i = Or(o), c = (a == null ? void 0 : a.trim()) || o.trim();
1262
+ if (!(!D(s) || !o.trim())) {
1263
+ if (s.isCollapsed()) {
1264
+ const l = Hr(i, {
1265
+ rel: "noreferrer noopener",
1266
+ target: "_blank"
1267
+ });
1268
+ l.append(je(c)), U([l]);
1269
+ return;
1270
+ }
1271
+ ot(i, {
1272
+ rel: "noreferrer noopener",
1273
+ target: "_blank"
1274
+ });
1275
+ }
1276
+ });
1277
+ },
1278
+ unsetLink: () => {
1279
+ e.update(() => {
1280
+ ot(null);
1281
+ });
1282
+ },
1283
+ openSelectedLink: () => {
1284
+ if (typeof window > "u") return;
1285
+ const o = e.getEditorState().read(() => {
1286
+ const a = A();
1287
+ if (!D(a)) return null;
1288
+ const s = a.anchor.getNode(), i = we(s) ? s : Xr(s, we);
1289
+ return i ? {
1290
+ target: i.getTarget() ?? "_blank",
1291
+ url: i.sanitizeUrl(i.getURL())
1292
+ } : null;
1293
+ });
1294
+ o && window.open(o.url, o.target, "noopener,noreferrer");
1295
+ }
1296
+ }), ea = (e) => ({
1297
+ insertImage: (s) => {
1298
+ s.url.trim() && e.update(() => {
1299
+ const i = W();
1300
+ U([so(s), i]), i.selectStart();
1301
+ });
1302
+ },
1303
+ insertVideo: (s) => {
1304
+ s.url.trim() && e.update(() => {
1305
+ const i = W();
1306
+ U([io(s), i]), i.selectStart();
1307
+ });
1308
+ },
1309
+ resizeMedia: (s) => {
1310
+ e.update(() => {
1311
+ var i;
1312
+ (i = le(s.assetId)) == null || i.updatePayload({
1313
+ displayWidthPercent: s.widthPercent
1314
+ });
1315
+ });
1316
+ },
1317
+ resetMediaSize: (s) => {
1318
+ e.update(() => {
1319
+ var i;
1320
+ (i = le(s)) == null || i.updatePayload({
1321
+ displayWidthPercent: void 0
1322
+ });
1323
+ });
1324
+ },
1325
+ alignMedia: (s) => {
1326
+ e.update(() => {
1327
+ var i;
1328
+ (i = le(s.assetId)) == null || i.updatePayload({
1329
+ align: s.value === "left" ? void 0 : s.value
1330
+ });
1331
+ });
1332
+ }
1333
+ }), ta = (e) => ({
1334
+ insertMention: (n) => {
1335
+ e.update(() => {
1336
+ const r = A();
1337
+ D(r) && U([
1338
+ Ge(n),
1339
+ je(" ")
1340
+ ]);
1341
+ });
1342
+ }
1343
+ }), na = (e) => ({
1344
+ clearSelectionFormat: () => {
1345
+ e.update(() => {
1346
+ const r = A();
1347
+ D(r) && (r.setFormat(0), st(r, {
1348
+ color: null,
1349
+ "background-color": null,
1350
+ "font-size": null,
1351
+ "font-family": null,
1352
+ "line-height": null
1353
+ }));
1354
+ });
1355
+ },
1356
+ setSelectionStyle: (r, o) => {
1357
+ e.update(() => {
1358
+ const a = A();
1359
+ D(a) && st(a, {
1360
+ [r]: o === "" ? null : o
1361
+ });
1362
+ });
1363
+ }
1364
+ }), ra = 20, yt = (e, t) => Number.isFinite(e) && e > 0 ? Math.min(Math.floor(e), t) : 1, he = (e) => Number.isFinite(e) && (e ?? 0) > 0 ? Math.min(Math.floor(e ?? 1), ra) : 1, fe = () => {
1365
+ const e = A();
1366
+ return !D(e) && !en(e) ? !1 : Nr(e.anchor.getNode()) !== null;
1367
+ }, oa = (e) => ({
1368
+ insertTable: (i, c) => {
1369
+ const l = yt(i, qt), m = yt(c, Kt);
1370
+ e.dispatchCommand(Sr, {
1371
+ rows: String(l),
1372
+ columns: String(m),
1373
+ /*
1374
+ * BridgeRTE 默认表格更贴近文档编辑场景:首行作为表头,首列保持普通单元格。
1375
+ * 后续表格菜单补齐后,再把首行/首列表头切换做成显式行为。
1376
+ */
1377
+ includeHeaders: {
1378
+ rows: !0,
1379
+ columns: !1
1380
+ }
1381
+ });
1382
+ },
1383
+ insertTableRow: (i) => {
1384
+ e.update(() => {
1385
+ if (!fe()) return;
1386
+ const c = he(i.count);
1387
+ for (let l = 0; l < c; l += 1)
1388
+ Lr(i.direction !== "before");
1389
+ });
1390
+ },
1391
+ insertTableColumn: (i) => {
1392
+ e.update(() => {
1393
+ if (!fe()) return;
1394
+ const c = he(i.count);
1395
+ for (let l = 0; l < c; l += 1)
1396
+ Tr(i.direction !== "before");
1397
+ });
1398
+ },
1399
+ deleteTableRow: (i) => {
1400
+ e.update(() => {
1401
+ const c = he(i.count);
1402
+ for (let l = 0; l < c; l += 1) {
1403
+ if (!fe()) return;
1404
+ Mr();
1405
+ }
1406
+ });
1407
+ },
1408
+ deleteTableColumn: (i) => {
1409
+ e.update(() => {
1410
+ const c = he(i.count);
1411
+ for (let l = 0; l < c; l += 1) {
1412
+ if (!fe()) return;
1413
+ xr();
1414
+ }
1415
+ });
1416
+ },
1417
+ deleteTable: () => {
1418
+ e.update(() => {
1419
+ const i = A();
1420
+ if (!D(i) && !en(i)) return;
1421
+ const c = kr(i.anchor.getNode());
1422
+ if (!c) return;
1423
+ const l = W();
1424
+ c.insertAfter(l), c.remove(), l.selectStart();
1425
+ });
1426
+ }
1427
+ }), aa = (e) => {
1428
+ const t = oa(e);
1429
+ return {
1430
+ insertTable: (n) => {
1431
+ t.insertTable(n.rows, n.cols);
1432
+ },
1433
+ insertTableRow: (n) => {
1434
+ t.insertTableRow(n);
1435
+ },
1436
+ insertTableColumn: (n) => {
1437
+ t.insertTableColumn(n);
1438
+ },
1439
+ deleteTableRow: (n) => {
1440
+ t.deleteTableRow(n);
1441
+ },
1442
+ deleteTableColumn: (n) => {
1443
+ t.deleteTableColumn(n);
1444
+ },
1445
+ deleteTable: () => {
1446
+ t.deleteTable();
1447
+ }
1448
+ };
1449
+ }, sa = {
1450
+ "format.bold": "bold",
1451
+ "format.italic": "italic",
1452
+ "format.underline": "underline",
1453
+ "format.strike": "strikethrough",
1454
+ "format.inlineCode": "code",
1455
+ "format.superscript": "superscript",
1456
+ "format.subscript": "subscript"
1457
+ }, ia = {
1458
+ "list.ordered": vr,
1459
+ "list.unordered": yr,
1460
+ "list.todo": br
1461
+ }, la = {
1462
+ "indent.increase": jn,
1463
+ "indent.decrease": Vn,
1464
+ "history.undo": Un,
1465
+ "history.redo": Wn
1466
+ }, ca = {
1467
+ "format.color": "color",
1468
+ "format.backgroundColor": "background-color",
1469
+ "format.fontSize": "font-size",
1470
+ "format.fontFamily": "font-family",
1471
+ "format.lineHeight": "line-height"
1472
+ }, da = ({
1473
+ container: e,
1474
+ lexicalEditor: t,
1475
+ options: n,
1476
+ isDestroyed: r,
1477
+ isReadonly: o,
1478
+ reportError: a
1479
+ }) => {
1480
+ const s = Go({
1481
+ container: e,
1482
+ lexicalEditor: t,
1483
+ options: n,
1484
+ isDestroyed: r
1485
+ }), i = Qo(t), c = Zo(t), l = ea(t), m = ta(t), C = na(t), _ = aa(t), x = () => {
1486
+ var S, p;
1487
+ if (document.fullscreenElement) {
1488
+ (S = document.exitFullscreen) == null || S.call(document).catch((w) => {
1489
+ a(n, "fullscreen.exit", "Exit fullscreen failed.", w);
1490
+ });
1491
+ return;
1492
+ }
1493
+ (p = e.requestFullscreen) == null || p.call(e).catch((w) => {
1494
+ a(n, "fullscreen.enter", "Enter fullscreen failed.", w);
1495
+ });
1496
+ }, h = ((v) => {
1497
+ if (r() || o()) return;
1498
+ const S = sa[v.type];
1499
+ if (S) {
1500
+ t.dispatchCommand(zn, S);
1501
+ return;
1502
+ }
1503
+ const p = ia[v.type];
1504
+ if (p) {
1505
+ t.dispatchCommand(p, void 0);
1506
+ return;
1507
+ }
1508
+ const w = la[v.type];
1509
+ if (w) {
1510
+ t.dispatchCommand(w, void 0);
1511
+ return;
1512
+ }
1513
+ const T = ca[v.type];
1514
+ if (T && "value" in v) {
1515
+ C.setSelectionStyle(T, v.value);
1516
+ return;
1517
+ }
1518
+ switch (v.type) {
1519
+ case "format.clear":
1520
+ C.clearSelectionFormat();
1521
+ return;
1522
+ case "block.heading":
1523
+ i.setBlockHeading(v.level);
1524
+ return;
1525
+ case "block.paragraph":
1526
+ i.setParagraphBlock();
1527
+ return;
1528
+ case "block.quote":
1529
+ i.setQuoteBlock();
1530
+ return;
1531
+ case "block.divider":
1532
+ i.insertDividerBlock();
1533
+ return;
1534
+ case "block.code":
1535
+ i.insertCodeBlock(v.language);
1536
+ return;
1537
+ case "block.setCodeLanguage":
1538
+ i.setSelectedCodeBlockLanguage(v.language);
1539
+ return;
1540
+ case "align":
1541
+ i.formatAlign(v.value);
1542
+ return;
1543
+ case "link.set":
1544
+ c.setLink(v.href, v.text);
1545
+ return;
1546
+ case "link.unset":
1547
+ c.unsetLink();
1548
+ return;
1549
+ case "link.open":
1550
+ c.openSelectedLink();
1551
+ return;
1552
+ case "mention.insert":
1553
+ m.insertMention(v.item);
1554
+ return;
1555
+ case "content.clear":
1556
+ i.clearContent();
1557
+ return;
1558
+ case "table.insert":
1559
+ _.insertTable(v);
1560
+ return;
1561
+ case "table.insertRow":
1562
+ _.insertTableRow(v);
1563
+ return;
1564
+ case "table.insertColumn":
1565
+ _.insertTableColumn(v);
1566
+ return;
1567
+ case "table.deleteRow":
1568
+ _.deleteTableRow(v);
1569
+ return;
1570
+ case "table.deleteColumn":
1571
+ _.deleteTableColumn(v);
1572
+ return;
1573
+ case "table.delete":
1574
+ _.deleteTable();
1575
+ return;
1576
+ case "media.insertImage":
1577
+ l.insertImage(v);
1578
+ return;
1579
+ case "media.insertVideo":
1580
+ l.insertVideo(v);
1581
+ return;
1582
+ case "media.pickImage":
1583
+ s.pickMediaFile("image");
1584
+ return;
1585
+ case "media.pickVideo":
1586
+ s.pickMediaFile("video");
1587
+ return;
1588
+ case "media.retry":
1589
+ s.retryMedia(v.assetId);
1590
+ return;
1591
+ case "media.remove":
1592
+ s.removeMedia(v.assetId);
1593
+ return;
1594
+ case "media.resize":
1595
+ l.resizeMedia(v);
1596
+ return;
1597
+ case "media.align":
1598
+ l.alignMedia(v);
1599
+ return;
1600
+ case "media.resetSize":
1601
+ l.resetMediaSize(v.assetId);
1602
+ return;
1603
+ case "fullscreen.toggle":
1604
+ x();
1605
+ return;
1606
+ }
1607
+ });
1608
+ return h.uploadMediaFile = s.uploadMediaFile, h.destroy = () => {
1609
+ s.destroy();
1610
+ }, h;
1611
+ }, ua = 300, ma = "BridgeRTE", vt = ({
1612
+ editor: e,
1613
+ overflowLength: t
1614
+ }) => {
1615
+ if (t <= 0) return !1;
1616
+ const n = A();
1617
+ if (D(n))
1618
+ return it(e, n.anchor, t), !0;
1619
+ $().selectEnd();
1620
+ const r = A();
1621
+ return D(r) ? (it(e, r.anchor, t), !0) : !1;
1622
+ }, ga = ({
1623
+ lexicalEditor: e,
1624
+ options: t,
1625
+ isDestroyed: n,
1626
+ setContent: r,
1627
+ syncPlaceholder: o
1628
+ }) => {
1629
+ let a = 0, s = null;
1630
+ const i = () => {
1631
+ s && (clearTimeout(s), s = null);
1632
+ }, c = (p) => {
1633
+ if (n()) return;
1634
+ const w = an(e.getEditorState(), e);
1635
+ r(w), p && Ho(t, w);
1636
+ }, l = (p) => {
1637
+ const w = t.maxLength !== void 0 && t.maxLength >= 0 ? t.maxLength : void 0;
1638
+ return {
1639
+ dirty: !0,
1640
+ plainTextLength: p,
1641
+ version: _e,
1642
+ maxLength: w,
1643
+ isOverMaxLength: w === void 0 ? !1 : p > w
1644
+ };
1645
+ }, m = (p) => {
1646
+ $o(t, l(p));
1647
+ }, C = () => {
1648
+ t.onChange && (i(), s = setTimeout(() => {
1649
+ c(!0);
1650
+ }, Bn));
1651
+ }, _ = (p) => {
1652
+ if (a > 0) {
1653
+ a -= 1;
1654
+ return;
1655
+ }
1656
+ m(p), C();
1657
+ }, x = () => e.getEditorState().read(() => $().getTextContent().length), h = (p) => t.maxLength === void 0 || t.maxLength < 0 ? 0 : p - t.maxLength, v = (p) => p <= 0 ? !1 : (e.update(() => {
1658
+ vt({ editor: e, overflowLength: p });
1659
+ }, { discrete: !0 }), !0);
1660
+ return {
1661
+ clearContentChangeTimer: i,
1662
+ enforceCurrentMaxLength: () => {
1663
+ t.maxLength === void 0 || t.maxLength < 0 || e.update(() => {
1664
+ const p = $().getTextContent().length - (t.maxLength ?? 0);
1665
+ vt({ editor: e, overflowLength: p });
1666
+ }, { discrete: !0 });
1667
+ },
1668
+ syncContent: c,
1669
+ suppressNextChange() {
1670
+ a += 1;
1671
+ },
1672
+ syncAfterEditorUpdate() {
1673
+ const p = x();
1674
+ if (v(h(p))) {
1675
+ o();
1676
+ return;
1677
+ }
1678
+ o(), _(p);
1679
+ }
1680
+ };
1681
+ }, xe = "data-language", mn = "纯文本", pa = "language", ha = /* @__PURE__ */ new Set(["plain", "plaintext", "text", "txt"]), fa = [
1682
+ xe,
1683
+ "data-lang",
1684
+ "data-code-language",
1685
+ "data-highlight-language",
1686
+ "lang",
1687
+ "language"
1688
+ ], ba = /^[a-z][a-z0-9_+#.-]{0,31}$/i, ya = /^(?:language|lang)-([a-z][a-z0-9_+#.-]{0,31})$/i, va = /^brush:\s*([a-z][a-z0-9_+#.-]{0,31})$/i, wa = /* @__PURE__ */ new Map([
1689
+ ["js", "javascript"],
1690
+ ["jsx", "javascript"],
1691
+ ["py", "python"],
1692
+ ["rs", "rust"],
1693
+ ["ts", "typescript"],
1694
+ ["tsx", "typescript"]
1695
+ ]), Ca = (e) => e.type === "select", _a = (e) => e.find((t) => t.name === pa && Ca(t)), Y = (e) => {
1696
+ const t = e == null ? void 0 : e.trim().toLowerCase();
1697
+ return !t || !ba.test(t) ? null : wa.get(t) ?? t;
1698
+ }, Ea = (e) => {
1699
+ for (const t of fa) {
1700
+ const n = Y(e.getAttribute(t));
1701
+ if (n) return n;
1702
+ }
1703
+ return null;
1704
+ }, ka = (e) => {
1705
+ const [, t] = e.match(va) ?? [], n = Y(t);
1706
+ if (n) return n;
1707
+ for (const r of e.split(/\s+/)) {
1708
+ const [, o] = r.match(ya) ?? [], a = Y(o);
1709
+ if (a) return a;
1710
+ }
1711
+ return null;
1712
+ }, xa = () => {
1713
+ const e = mr().filter(([t]) => !ha.has(t)).map(([t, n]) => ({
1714
+ label: n,
1715
+ value: Y(t) ?? t
1716
+ }));
1717
+ return [
1718
+ { label: mn, value: "" },
1719
+ ...e
1720
+ ];
1721
+ }, wt = xa(), gn = (e = Oe) => {
1722
+ var t;
1723
+ return e === Oe ? wt : ((t = _a(e.fields)) == null ? void 0 : t.options) ?? wt;
1724
+ }, pn = (e, t) => {
1725
+ var n, r, o;
1726
+ return ((n = e.find((a) => a.value === t)) == null ? void 0 : n.label) ?? ((r = e.find((a) => Y(a.value) === Y(t))) == null ? void 0 : r.label) ?? ((o = e[0]) == null ? void 0 : o.label) ?? mn;
1727
+ };
1728
+ gn();
1729
+ const Ma = (e) => {
1730
+ [...e.querySelectorAll("pre,code")].forEach((t) => {
1731
+ const n = Ea(t) ?? ka(t.className), r = t.tagName === "PRE" ? t : t.closest("pre");
1732
+ r && n && r.setAttribute(xe, n);
1733
+ });
1734
+ }, Ta = (e) => {
1735
+ e.querySelectorAll("pre").forEach((t) => {
1736
+ [...t.children].forEach((r) => {
1737
+ r.tagName === "CODE" && r.replaceWith(...r.childNodes);
1738
+ });
1739
+ });
1740
+ }, La = (e, t) => {
1741
+ const n = [...t.querySelectorAll("pre[data-language]")];
1742
+ let r = 0;
1743
+ e.forEach((o) => {
1744
+ if (!K(o)) return;
1745
+ const a = n[r];
1746
+ if (r += 1, !a) return;
1747
+ const s = a.getAttribute(xe);
1748
+ s && !o.getLanguage() && o.setLanguage(s);
1749
+ });
1750
+ }, te = 12, Ct = 6, _t = (e, t, n) => Math.min(Math.max(e, t), Math.max(t, n)), Sa = () => {
1751
+ const e = window.visualViewport;
1752
+ return {
1753
+ left: (e == null ? void 0 : e.offsetLeft) ?? 0,
1754
+ top: (e == null ? void 0 : e.offsetTop) ?? 0,
1755
+ width: (e == null ? void 0 : e.width) ?? window.innerWidth,
1756
+ height: (e == null ? void 0 : e.height) ?? window.innerHeight
1757
+ };
1758
+ }, Na = (e) => {
1759
+ const t = e.style.visibility, n = e.style.pointerEvents, r = e.style.display;
1760
+ e.style.visibility = "hidden", e.style.pointerEvents = "none", e.style.display = "grid";
1761
+ const o = e.getBoundingClientRect();
1762
+ return e.style.visibility = t, e.style.pointerEvents = n, e.style.display = r, o;
1763
+ }, Pa = (e, t, n) => {
1764
+ const r = Na(e), o = Sa(), a = t.getBoundingClientRect(), s = a.left + te, i = a.top + te, c = n ? n.x : s, l = n ? n.y + n.height + Ct : i, m = n ? n.y - r.height - Ct : l, C = o.left + te, _ = o.top + te, x = o.left + o.width - r.width - te, h = o.top + o.height - r.height - te, v = l > h ? m : l;
1765
+ return {
1766
+ left: _t(c, C, x),
1767
+ top: _t(v, _, h),
1768
+ viewportHeight: o.height
1769
+ };
1770
+ }, hn = (e) => {
1771
+ var c, l;
1772
+ const t = document.createElement("div"), n = document.createElement("div"), r = document.createElement("div");
1773
+ let o;
1774
+ const a = () => {
1775
+ t.dataset.visible = "false", n.dataset.visible = "false", o = void 0;
1776
+ }, s = () => {
1777
+ const m = Pa(n, e.root, o);
1778
+ n.style.left = `${m.left}px`, n.style.top = `${m.top}px`, n.style.setProperty(
1779
+ "--bridgerte-dialog-visible-height",
1780
+ `${m.viewportHeight}px`
1781
+ );
1782
+ }, i = (m) => {
1783
+ o = m, m ? n.style.setProperty("--bridgerte-dialog-anchor-width", `${m.width}px`) : n.style.removeProperty("--bridgerte-dialog-anchor-width"), s(), t.dataset.visible = "true", n.dataset.visible = "true";
1784
+ };
1785
+ return t.className = "bridgerte__dialog-backdrop", t.dataset.visible = "false", n.className = `bridgerte__dialog ${e.className}`, n.dataset.visible = "false", r.className = "bridgerte__dialog-content", n.append(r), e.root.append(t, n), t.addEventListener("click", () => {
1786
+ var m;
1787
+ (m = e.onBackdropClick) == null || m.call(e), a();
1788
+ }), (c = window.visualViewport) == null || c.addEventListener("resize", s), (l = window.visualViewport) == null || l.addEventListener("scroll", s), window.addEventListener("resize", s), {
1789
+ element: n,
1790
+ content: r,
1791
+ open: i,
1792
+ close: a,
1793
+ destroy() {
1794
+ var m, C;
1795
+ a(), (m = window.visualViewport) == null || m.removeEventListener("resize", s), (C = window.visualViewport) == null || C.removeEventListener("scroll", s), window.removeEventListener("resize", s), t.remove(), n.remove();
1796
+ }
1797
+ };
1798
+ }, Ce = (e) => typeof requestAnimationFrame == "function" ? requestAnimationFrame(e) : window.setTimeout(e, 0), Ye = (e) => {
1799
+ if (typeof cancelAnimationFrame == "function") {
1800
+ cancelAnimationFrame(e);
1801
+ return;
1802
+ }
1803
+ window.clearTimeout(e);
1804
+ }, Et = "language", Ia = "bridgerte-code-block-language", kt = 8;
1805
+ let xt = 0;
1806
+ const Ra = () => (xt += 1, `${Ia}-${xt}`), Aa = (e, t, n) => {
1807
+ const r = e.querySelector(".bridgerte__code-block-control-label");
1808
+ e.dataset.language = n ?? "", r && (r.textContent = pn(t, n));
1809
+ }, Ba = (e, t) => {
1810
+ const n = document.createElement("button"), r = document.createElement("span"), o = document.createElement("span");
1811
+ return n.type = "button", n.className = "bridgerte__code-block-control", n.contentEditable = "false", n.dataset.language = t ?? "", n.setAttribute("aria-label", "选择代码块语言"), r.className = "bridgerte__code-block-control-label", r.textContent = pn(e, t), o.className = "bridgerte__code-block-control-arrow", n.append(r, o), n;
1812
+ }, Da = (e) => e.querySelector(".bridgerte__content") ?? e, Oa = (e) => {
1813
+ const t = document.createElement("div"), n = Da(e.root), r = nn(
1814
+ e.languagePanel ?? Oe,
1815
+ e.payloadPanelConfig
1816
+ ), o = gn(r);
1817
+ let a = null, s = null;
1818
+ const i = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), l = () => {
1819
+ a == null || a.close();
1820
+ }, m = (k, b) => {
1821
+ e.isReadonly() || e.editor.update(() => {
1822
+ const g = ce(k);
1823
+ K(g) && g.setLanguage(b);
1824
+ });
1825
+ }, C = (k, b) => {
1826
+ Ce(() => {
1827
+ m(k, b);
1828
+ });
1829
+ }, _ = (k, b, g) => {
1830
+ var d;
1831
+ return ((d = e.onRequest) == null ? void 0 : d.call(e, {
1832
+ id: Ra(),
1833
+ readonly: e.isReadonly(),
1834
+ menuId: "code-block-language",
1835
+ command: { type: "block.setCodeLanguage", language: g },
1836
+ panel: r,
1837
+ anchorRect: {
1838
+ x: b.left,
1839
+ y: b.top,
1840
+ width: b.width,
1841
+ height: b.height
1842
+ },
1843
+ currentValues: {
1844
+ [Et]: g
1845
+ },
1846
+ submit: (y) => {
1847
+ l(), C(k, y[Et] ?? "");
1848
+ },
1849
+ cancel: l
1850
+ })) === !0;
1851
+ }, x = (k, b) => {
1852
+ const g = e.root.getBoundingClientRect(), d = b.getBoundingClientRect(), y = d.bottom < g.top || d.top > g.bottom;
1853
+ k.hidden = y, k.style.transform = `translate(${d.left - g.left + kt}px, ${d.top - g.top + kt}px)`;
1854
+ }, h = (k) => {
1855
+ var f;
1856
+ const b = e.editor.getElementByKey(k);
1857
+ if (!b) {
1858
+ (f = i.get(k)) == null || f.remove(), i.delete(k);
1859
+ return;
1860
+ }
1861
+ b.dataset.lexicalKey = k;
1862
+ const g = b.getAttribute("data-language"), d = i.get(k);
1863
+ if (d) {
1864
+ Aa(d, o, g), x(d, b);
1865
+ return;
1866
+ }
1867
+ const y = Ba(o, g), u = z(y);
1868
+ y.dataset.lexicalKey = k, i.set(k, y), c.set(y, u), t.append(y), x(y, b);
1869
+ }, v = () => {
1870
+ s = null, i.forEach((k, b) => {
1871
+ h(b);
1872
+ });
1873
+ }, S = () => {
1874
+ s === null && (s = Ce(v));
1875
+ }, p = (k, b) => {
1876
+ const g = k.getBoundingClientRect(), d = k.dataset.language ?? "";
1877
+ if (_(b, g, d)) return;
1878
+ if (e.isReadonly()) {
1879
+ l();
1880
+ return;
1881
+ }
1882
+ a || (a = hn({
1883
+ root: e.root,
1884
+ className: "bridgerte__code-block-menu",
1885
+ onBackdropClick: l
1886
+ }));
1887
+ const y = document.createElement("div");
1888
+ a.content.replaceChildren(), a.element.style.minWidth = "180px", y.className = "bridgerte__code-block-menu-list", o.forEach((u) => {
1889
+ const f = document.createElement("button");
1890
+ f.type = "button", f.className = "bridgerte__code-block-menu-item", f.textContent = u.label, z(f), f.addEventListener("click", () => {
1891
+ l(), C(b, u.value);
1892
+ }), y.append(f);
1893
+ }), a.content.append(y), a.open({
1894
+ x: g.left,
1895
+ y: g.top,
1896
+ width: 180,
1897
+ height: g.height
1898
+ });
1899
+ };
1900
+ t.className = "bridgerte__code-block-controls-layer", e.root.append(t);
1901
+ const w = e.editor.registerMutationListener(
1902
+ Qt,
1903
+ (k) => {
1904
+ k.forEach((b, g) => {
1905
+ if (b === "destroyed") {
1906
+ const d = i.get(g);
1907
+ if (d) {
1908
+ const y = c.get(d);
1909
+ y == null || y(), c.delete(d), d.remove();
1910
+ }
1911
+ i.delete(g);
1912
+ return;
1913
+ }
1914
+ h(g);
1915
+ });
1916
+ }
1917
+ ), T = e.editor.registerUpdateListener(S), E = (k) => {
1918
+ const b = k.target;
1919
+ if (!(b instanceof HTMLElement)) return;
1920
+ const g = b.closest(".bridgerte__code-block-control");
1921
+ if (!(g instanceof HTMLElement)) return;
1922
+ const d = g.dataset.lexicalKey;
1923
+ d && (k.preventDefault(), k.stopPropagation(), p(g, d));
1924
+ }, P = (k) => {
1925
+ const b = k.target;
1926
+ b instanceof HTMLElement && b.closest(".bridgerte__code-block-control") && k.preventDefault();
1927
+ }, I = (k) => {
1928
+ const b = k.target;
1929
+ if (!(b instanceof HTMLElement)) return;
1930
+ if (!b.closest(".bridgerte__code-block")) {
1931
+ l();
1932
+ return;
1933
+ }
1934
+ const g = b.closest(".bridgerte__code-block");
1935
+ if (!g || g.textContent) return;
1936
+ const d = g.dataset.lexicalKey;
1937
+ d && (e.editor.update(() => {
1938
+ const y = ce(d);
1939
+ K(y) && y.selectEnd();
1940
+ }), e.editor.focus());
1941
+ };
1942
+ return t.addEventListener("pointerdown", P), t.addEventListener("click", E), n.addEventListener("pointerdown", I), n.addEventListener("scroll", S, { passive: !0 }), window.addEventListener("resize", S), {
1943
+ destroy() {
1944
+ w(), T(), s !== null && (Ye(s), s = null), t.removeEventListener("pointerdown", P), t.removeEventListener("click", E), n.removeEventListener("pointerdown", I), n.removeEventListener("scroll", S), window.removeEventListener("resize", S), i.forEach((k) => {
1945
+ var b;
1946
+ (b = c.get(k)) == null || b(), k.remove();
1947
+ }), i.clear(), c.clear(), t.remove(), a == null || a.destroy(), a = null;
1948
+ }
1949
+ };
1950
+ }, Qe = [
1951
+ "media-resize-20",
1952
+ "media-resize-50",
1953
+ "media-resize-100"
1954
+ ], Ha = [
1955
+ "media-align-left",
1956
+ "media-align-center",
1957
+ "media-align-right",
1958
+ "|",
1959
+ ...Qe,
1960
+ "|",
1961
+ "media-remove"
1962
+ ], $a = [
1963
+ "media-retry",
1964
+ "|",
1965
+ "media-remove"
1966
+ ], Fa = [
1967
+ {
1968
+ id: "media-align-left",
1969
+ command: { type: "media.align", assetId: "", value: "left" },
1970
+ label: "左",
1971
+ icon: "align-left",
1972
+ group: "media"
1973
+ },
1974
+ {
1975
+ id: "media-align-center",
1976
+ command: { type: "media.align", assetId: "", value: "center" },
1977
+ label: "中",
1978
+ icon: "align-center",
1979
+ group: "media"
1980
+ },
1981
+ {
1982
+ id: "media-align-right",
1983
+ command: { type: "media.align", assetId: "", value: "right" },
1984
+ label: "右",
1985
+ icon: "align-right",
1986
+ group: "media"
1987
+ },
1988
+ {
1989
+ id: "media-resize-20",
1990
+ command: { type: "media.resize", assetId: "", widthPercent: 20 },
1991
+ label: "20%",
1992
+ icon: "media-resize-20",
1993
+ group: "media"
1994
+ },
1995
+ {
1996
+ id: "media-resize-50",
1997
+ command: { type: "media.resize", assetId: "", widthPercent: 50 },
1998
+ label: "50%",
1999
+ icon: "media-resize-50",
2000
+ group: "media"
2001
+ },
2002
+ {
2003
+ id: "media-resize-100",
2004
+ command: { type: "media.resize", assetId: "", widthPercent: 100 },
2005
+ label: "100%",
2006
+ icon: "media-resize-100",
2007
+ group: "media"
2008
+ },
2009
+ {
2010
+ id: "media-retry",
2011
+ command: { type: "media.retry", assetId: "" },
2012
+ label: "重试",
2013
+ icon: "refresh-cw",
2014
+ group: "media"
2015
+ },
2016
+ {
2017
+ id: "media-remove",
2018
+ command: { type: "media.remove", assetId: "" },
2019
+ label: "删除",
2020
+ icon: "trash-2",
2021
+ group: "media"
2022
+ }
2023
+ ], za = (e) => Qe.includes(e), Wa = (e) => typeof e == "object" && Array.isArray(e.menuKeys), Ua = (e) => new Set(e.flatMap((t) => t === "|" ? [] : typeof t == "string" ? [t] : Wa(t) ? [t.key, ...t.menuKeys] : [])), Va = (e) => {
2024
+ const t = Ua(e), n = Qe.filter((r) => !t.has(r));
2025
+ return n.length === 0 ? e : [
2026
+ ...e,
2027
+ "|",
2028
+ ...n
2029
+ ];
2030
+ }, ja = (e) => {
2031
+ var r;
2032
+ const t = (e == null ? void 0 : e.toolbarKeys) ?? Ha;
2033
+ return {
2034
+ ...e,
2035
+ toolbarKeys: Va(t),
2036
+ excludeKeys: (r = e == null ? void 0 : e.excludeKeys) == null ? void 0 : r.filter((o) => !za(o))
2037
+ };
2038
+ }, qa = (e, t) => {
2039
+ switch (e.command.type) {
2040
+ case "media.retry":
2041
+ return { ...e.command, assetId: t };
2042
+ case "media.remove":
2043
+ return { ...e.command, assetId: t };
2044
+ case "media.resize":
2045
+ return { ...e.command, assetId: t };
2046
+ case "media.align":
2047
+ return { ...e.command, assetId: t };
2048
+ default:
2049
+ return null;
2050
+ }
2051
+ }, Ka = (e, t, n) => e.command.type === "media.resize" ? e.command.widthPercent === t : e.command.type === "media.align" && e.command.value === n, fn = (e, t = {}) => {
2052
+ const n = ke(Fa, {
2053
+ menuLabels: t.menuLabels
2054
+ }), r = e === "error" ? { toolbarKeys: $a } : ja(t.config);
2055
+ return Ee(r, n);
2056
+ }, ne = 8, ae = "bridgerte__media-controls-button", Ga = (e) => e.querySelector(".bridgerte__content") ?? e, Mt = (e) => e instanceof Element ? e.closest(".bridgerte__media") : null, Xa = (e, t = !1) => {
2057
+ const n = document.createElement("button");
2058
+ return n.type = "button", n.className = ae, n.textContent = e.label, n.dataset.menuItemId = e.id, n.dataset.action = e.id.replace(/^media-/, ""), t && (n.dataset.active = "true"), n.setAttribute("aria-label", e.label), n;
2059
+ }, bn = (e) => e.flatMap((t) => t.type === "button" ? [t.item] : t.type === "group" ? t.items : []), Ja = (e, t, n, r) => {
2060
+ if (t.type === "separator") {
2061
+ const a = document.createElement("span");
2062
+ a.className = "bridgerte__media-controls-separator", a.dataset.separatorId = t.key, a.setAttribute("aria-hidden", "true"), e.append(a);
2063
+ return;
2064
+ }
2065
+ (t.type === "button" ? [t.item] : t.items).forEach((a) => {
2066
+ e.append(Xa(
2067
+ a,
2068
+ Ka(a, n, r)
2069
+ ));
2070
+ });
2071
+ }, Ya = (e, t, n) => {
2072
+ const r = document.createElement("div"), o = e.dataset.status, a = Number(
2073
+ e.dataset.displayWidthPercent ?? t
2074
+ ), s = e.dataset.align ?? "left", i = fn(o, {
2075
+ config: n.mediaControlsConfig,
2076
+ menuLabels: n.menuLabels
2077
+ });
2078
+ return r.className = "bridgerte__media-controls", r.contentEditable = "false", r.setAttribute("aria-label", "媒体操作"), r.dataset.status = o ?? "success", r.dataset.displayWidthPercent = e.dataset.displayWidthPercent ?? "", r.dataset.align = e.dataset.align ?? "", r.dataset.menuItemIds = bn(i).map((c) => c.id).join("|"), i.forEach((c) => {
2079
+ Ja(r, c, a, s);
2080
+ }), r;
2081
+ }, Qa = (e) => {
2082
+ const t = document.createElement("div"), n = Ga(e.root), r = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
2083
+ let s = null, i = null, c = !1, l = null;
2084
+ const m = (d) => {
2085
+ var u;
2086
+ const y = r.get(d);
2087
+ y && ((u = o.get(y)) == null || u(), o.delete(y), y.remove(), r.delete(d), l === d && (l = null));
2088
+ }, C = (d, y) => y.dataset.status === "error" || l === d, _ = (d, y) => {
2089
+ const u = e.root.getBoundingClientRect(), f = y.getBoundingClientRect(), L = f.bottom < u.top || f.top > u.bottom, R = Math.max(
2090
+ ne,
2091
+ u.width - d.offsetWidth - ne
2092
+ ), H = Math.min(
2093
+ Math.max(f.left - u.left + ne, ne),
2094
+ R
2095
+ ), O = Math.max(
2096
+ ne,
2097
+ f.top - u.top - d.offsetHeight - ne
2098
+ );
2099
+ d.hidden = L, d.style.transform = `translate(${H}px, ${O}px)`;
2100
+ }, x = (d) => {
2101
+ const y = e.editor.getElementByKey(d);
2102
+ if (!y) {
2103
+ m(d);
2104
+ return;
2105
+ }
2106
+ y.dataset.lexicalKey = d, a.set(y, d);
2107
+ const u = r.get(d);
2108
+ if (!C(d, y)) {
2109
+ m(d);
2110
+ return;
2111
+ }
2112
+ if (u) {
2113
+ const R = y.dataset.status === "error", H = u.querySelector('[data-action="retry"]') !== null, O = y.dataset.displayWidthPercent ?? "", N = y.dataset.align ?? "";
2114
+ if (R === H && u.dataset.displayWidthPercent === O && u.dataset.align === N) {
2115
+ _(u, y);
2116
+ return;
2117
+ }
2118
+ m(d);
2119
+ }
2120
+ const f = Ya(y, e.defaultWidthPercent, e), L = z(f, {
2121
+ targetSelector: `.${ae}`
2122
+ });
2123
+ f.dataset.lexicalKey = d, f.dataset.assetId = y.dataset.assetId, r.set(d, f), o.set(f, L), t.append(f), _(f, y);
2124
+ }, h = () => {
2125
+ s = null, a.forEach((d, y) => {
2126
+ e.root.contains(y) || (a.delete(y), m(d));
2127
+ }), e.root.querySelectorAll(".bridgerte__media").forEach((d) => {
2128
+ const y = d.dataset.lexicalKey;
2129
+ y && (a.set(d, y), x(y));
2130
+ }), r.forEach((d, y) => {
2131
+ x(y);
2132
+ }), l !== null && x(l);
2133
+ }, v = () => {
2134
+ s === null && (s = Ce(h));
2135
+ }, S = (d, y) => {
2136
+ const u = y.dataset.assetId, f = bn(fn(y.dataset.status, {
2137
+ config: e.mediaControlsConfig,
2138
+ menuLabels: e.menuLabels
2139
+ })).find((R) => R.id === d.dataset.menuItemId);
2140
+ if (!u || !f) return;
2141
+ const L = qa(f, u);
2142
+ L && e.executeCommand(L);
2143
+ }, p = (d) => {
2144
+ if (!d) {
2145
+ const f = l;
2146
+ l = null, f !== null && x(f);
2147
+ return;
2148
+ }
2149
+ const y = d.dataset.lexicalKey ? d.dataset.lexicalKey : a.get(d) ?? null;
2150
+ if (!y || l === y) return;
2151
+ const u = l;
2152
+ l = y, u !== null && x(u), x(y);
2153
+ }, w = (d) => {
2154
+ const y = Mt(d.target);
2155
+ p(y);
2156
+ }, T = (d) => {
2157
+ p(Mt(d.target));
2158
+ }, E = (d) => {
2159
+ const y = d.target;
2160
+ if (!(y instanceof HTMLElement)) return;
2161
+ const u = y.closest(`.${ae}`);
2162
+ u && (d.preventDefault(), i = d.pointerType === "mouse" ? null : u);
2163
+ }, P = (d) => {
2164
+ if (d.pointerType === "mouse" || !i) return;
2165
+ const y = d.target, u = y instanceof HTMLElement ? y.closest(".bridgerte__media-controls") : null, f = y instanceof HTMLElement ? y.closest(`.${ae}`) : null;
2166
+ f === i && u && (d.preventDefault(), d.stopPropagation(), S(f, u), c = !0), i = null;
2167
+ }, I = () => {
2168
+ i = null;
2169
+ }, k = (d) => {
2170
+ if (c) {
2171
+ c = !1, d.preventDefault(), d.stopPropagation();
2172
+ return;
2173
+ }
2174
+ const y = d.target;
2175
+ if (!(y instanceof HTMLElement)) return;
2176
+ const u = y.closest(`.${ae}`), f = y.closest(".bridgerte__media-controls");
2177
+ !u || !f || (d.preventDefault(), d.stopPropagation(), S(u, f));
2178
+ };
2179
+ t.className = "bridgerte__media-controls-layer", e.root.append(t);
2180
+ const b = e.editor.registerMutationListener(
2181
+ re,
2182
+ (d) => {
2183
+ d.forEach((y, u) => {
2184
+ if (y === "destroyed") {
2185
+ m(u);
2186
+ return;
2187
+ }
2188
+ x(u);
2189
+ });
2190
+ }
2191
+ ), g = e.editor.registerUpdateListener(v);
2192
+ return t.addEventListener("pointerdown", E), t.addEventListener("pointerup", P), t.addEventListener("pointercancel", I), t.addEventListener("click", k), n.addEventListener("pointerdown", w), n.addEventListener("focusin", T), n.addEventListener("scroll", v, { passive: !0 }), window.addEventListener("resize", v), {
2193
+ destroy() {
2194
+ b(), g(), s !== null && (Ye(s), s = null), t.removeEventListener("pointerdown", E), t.removeEventListener("pointerup", P), t.removeEventListener("pointercancel", I), t.removeEventListener("click", k), n.removeEventListener("pointerdown", w), n.removeEventListener("focusin", T), n.removeEventListener("scroll", v), window.removeEventListener("resize", v), r.forEach((d) => {
2195
+ var y;
2196
+ (y = o.get(d)) == null || y(), d.remove();
2197
+ }), r.clear(), o.clear(), a.clear(), t.remove();
2198
+ }
2199
+ };
2200
+ }, Za = ["width", "height"], q = (e, t) => {
2201
+ var r;
2202
+ const n = (r = e[t]) == null ? void 0 : r.trim();
2203
+ return n || void 0;
2204
+ }, $e = (e, t) => {
2205
+ const n = Number.parseInt(e[t] ?? "", 10);
2206
+ return Number.isFinite(n) && n > 0 ? n : void 0;
2207
+ }, Tt = (e, t) => Za.reduce((n, r) => {
2208
+ const o = $e(t, r);
2209
+ return o === void 0 ? n : { ...n, [r]: o };
2210
+ }, e), es = (e, t) => {
2211
+ if (e.type === "format.color" || e.type === "format.backgroundColor" || e.type === "format.fontSize" || e.type === "format.fontFamily" || e.type === "format.lineHeight")
2212
+ return t.value !== void 0 ? { ...e, value: t.value } : e;
2213
+ if (e.type === "link.set") {
2214
+ const n = q(t, "href"), r = q(t, "text");
2215
+ return n ? { ...e, href: n, text: r } : null;
2216
+ }
2217
+ if (e.type === "block.code")
2218
+ return t.language ? { type: "block.code", language: t.language } : e;
2219
+ if (e.type === "block.setCodeLanguage")
2220
+ return t.language !== void 0 ? { ...e, language: t.language } : e;
2221
+ if (e.type === "table.insert") {
2222
+ const n = $e(t, "rows"), r = $e(t, "cols");
2223
+ return n && r ? { type: "table.insert", rows: n, cols: r } : null;
2224
+ }
2225
+ if (e.type === "media.insertImage") {
2226
+ const n = q(t, "url");
2227
+ return n ? Tt({
2228
+ ...e,
2229
+ url: n,
2230
+ alt: q(t, "alt"),
2231
+ title: q(t, "title")
2232
+ }, t) : null;
2233
+ }
2234
+ if (e.type === "media.insertVideo") {
2235
+ const n = q(t, "url");
2236
+ return n ? Tt({
2237
+ ...e,
2238
+ url: n,
2239
+ poster: q(t, "poster"),
2240
+ title: q(t, "title")
2241
+ }, t) : null;
2242
+ }
2243
+ return e;
2244
+ }, X = (e) => Math.min(Math.max(Math.round(e), 0), 255), Fe = ({ r: e, g: t, b: n }) => `#${[e, t, n].map((r) => X(r).toString(16).padStart(2, "0")).join("")}`, yn = (e) => {
2245
+ const n = e.trim().match(/^#([0-9a-f]{6})$/i);
2246
+ if (!n) return null;
2247
+ const r = n[1] ?? "";
2248
+ return {
2249
+ r: Number.parseInt(r.slice(0, 2), 16),
2250
+ g: Number.parseInt(r.slice(2, 4), 16),
2251
+ b: Number.parseInt(r.slice(4, 6), 16)
2252
+ };
2253
+ }, ts = (e) => {
2254
+ const t = e.trim().match(/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i);
2255
+ return t ? {
2256
+ r: X(Number(t[1])),
2257
+ g: X(Number(t[2])),
2258
+ b: X(Number(t[3]))
2259
+ } : null;
2260
+ }, ns = (e) => {
2261
+ const t = yn(e) ?? ts(e);
2262
+ return t ? Fe(t) : null;
2263
+ }, vn = (e) => Math.min(Math.max(e, 0), 1), rs = ({ r: e, g: t, b: n }) => {
2264
+ const r = X(e) / 255, o = X(t) / 255, a = X(n) / 255, s = Math.max(r, o, a), i = Math.min(r, o, a), c = s - i;
2265
+ let l = 0;
2266
+ return c !== 0 && (s === r ? l = 60 * ((o - a) / c % 6) : s === o ? l = 60 * ((a - r) / c + 2) : l = 60 * ((r - o) / c + 4)), {
2267
+ h: l < 0 ? l + 360 : l,
2268
+ s: s === 0 ? 0 : c / s,
2269
+ v: s
2270
+ };
2271
+ }, Lt = ({
2272
+ h: e,
2273
+ s: t,
2274
+ v: n
2275
+ }) => {
2276
+ const r = n * t, o = r * (1 - Math.abs(e / 60 % 2 - 1)), a = n - r;
2277
+ let s = 0, i = 0, c = 0;
2278
+ return e < 60 ? (s = r, i = o) : e < 120 ? (s = o, i = r) : e < 180 ? (i = r, c = o) : e < 240 ? (i = o, c = r) : e < 300 ? (s = o, c = r) : (s = r, c = o), {
2279
+ r: (s + a) * 255,
2280
+ g: (i + a) * 255,
2281
+ b: (c + a) * 255
2282
+ };
2283
+ }, os = ({ h: e, s: t }) => {
2284
+ const n = e * Math.PI / 180, r = vn(t) * 50;
2285
+ return {
2286
+ x: 50 + Math.cos(n) * r,
2287
+ y: 50 + Math.sin(n) * r
2288
+ };
2289
+ }, St = (e, t) => {
2290
+ const n = t.getBoundingClientRect(), r = n.left + n.width / 2, o = n.top + n.height / 2, a = e.clientX - r, s = e.clientY - o, i = Math.min(Math.sqrt(a * a + s * s), n.width / 2), c = Math.atan2(s, a) * 180 / Math.PI;
2291
+ return {
2292
+ h: c < 0 ? c + 360 : c,
2293
+ s: vn(i / (n.width / 2)),
2294
+ v: 1
2295
+ };
2296
+ }, as = [
2297
+ "#000000",
2298
+ "#ffffff"
2299
+ ], ss = (e) => {
2300
+ var t;
2301
+ return (t = e.options) != null && t.length ? e.options : as.map((n) => ({ label: n, value: n }));
2302
+ }, wn = () => {
2303
+ const e = document.createElement("section");
2304
+ return e.className = "bridgerte__payload-panel-field", e;
2305
+ }, is = (e, t, n) => {
2306
+ const r = wn(), o = document.createElement("div");
2307
+ return o.className = "bridgerte__payload-panel-option-list", e.options.forEach((a) => {
2308
+ const s = document.createElement("button");
2309
+ s.type = "button", s.className = "bridgerte__payload-panel-option", s.textContent = a.label, s.dataset.bridgertePayloadOption = a.value, s.dataset.active = t[e.name] === a.value ? "true" : "false", z(s), s.addEventListener("pointerdown", (i) => {
2310
+ i.preventDefault();
2311
+ }), s.addEventListener("click", () => {
2312
+ n({
2313
+ ...t,
2314
+ [e.name]: a.value
2315
+ });
2316
+ }), o.append(s);
2317
+ }), r.append(o), r;
2318
+ }, ls = (e, t, n) => {
2319
+ const r = wn(), o = document.createElement("div"), a = document.createElement("span"), s = document.createElement("div"), i = document.createElement("div");
2320
+ let c = { h: 0, s: 0, v: 1 }, l = null;
2321
+ const m = (x) => {
2322
+ const h = ns(x);
2323
+ if (!h) return;
2324
+ t[e.name] = h, i.style.background = h, c = rs(yn(h) ?? { r: 255, g: 255, b: 255 });
2325
+ const v = os(c);
2326
+ o.dataset.active = "true", i.dataset.empty = "false", a.style.left = `${v.x}%`, a.style.top = `${v.y}%`;
2327
+ }, C = () => {
2328
+ const x = t[e.name];
2329
+ x && n({
2330
+ ...t,
2331
+ [e.name]: x
2332
+ });
2333
+ };
2334
+ r.className = "bridgerte__payload-panel-field", o.className = "bridgerte__payload-panel-color-wheel", o.setAttribute("aria-label", `${e.label}选择区域`), a.className = "bridgerte__payload-panel-color-wheel-handle", s.className = "bridgerte__payload-panel-color-actions", i.className = "bridgerte__payload-panel-color-preview", i.dataset.empty = "true", o.append(a), ss(e).forEach((x) => {
2335
+ const h = document.createElement("button"), v = x.value;
2336
+ h.type = "button", h.className = "bridgerte__payload-panel-color-swatch", h.dataset.value = v, h.style.background = v, h.setAttribute("aria-label", `选择颜色 ${x.label}`), z(h), h.addEventListener("pointerdown", (S) => {
2337
+ S.preventDefault();
2338
+ }), h.addEventListener("click", () => {
2339
+ m(v), C();
2340
+ }), s.append(h);
2341
+ }), o.addEventListener("pointerdown", (x) => {
2342
+ l = x.pointerId, o.setPointerCapture(x.pointerId), c = St(x, o), m(Fe(Lt(c))), x.preventDefault();
2343
+ }), o.addEventListener("pointermove", (x) => {
2344
+ l === x.pointerId && (c = St(x, o), m(Fe(Lt(c))));
2345
+ }), o.addEventListener("pointerup", (x) => {
2346
+ l === x.pointerId && (l = null, o.releasePointerCapture(x.pointerId), C());
2347
+ }), o.addEventListener("pointercancel", (x) => {
2348
+ l === x.pointerId && (l = null, o.releasePointerCapture(x.pointerId));
2349
+ });
2350
+ const _ = t[e.name];
2351
+ return _ && m(_), r.append(o, i, s), r;
2352
+ }, cs = (e, t, n) => {
2353
+ const r = document.createElement("label"), o = document.createElement("input");
2354
+ return r.className = "bridgerte__payload-panel-text-field", r.textContent = e.label, o.type = e.name === "href" || e.name === "url" ? "url" : "text", o.className = "bridgerte__payload-panel-text-input", o.value = t[e.name] ?? "", o.placeholder = e.placeholder ?? "", o.spellcheck = !1, o.addEventListener("input", () => {
2355
+ t[e.name] = o.value;
2356
+ }), o.addEventListener("keydown", (a) => {
2357
+ a.key === "Enter" && (a.preventDefault(), n(t));
2358
+ }), r.append(o), r;
2359
+ }, ds = (e, t, n) => {
2360
+ const r = document.createElement("label"), o = document.createElement("input");
2361
+ return r.className = "bridgerte__payload-panel-text-field", r.textContent = e.label, o.type = "number", o.className = "bridgerte__payload-panel-text-input", o.value = t[e.name] ?? "", o.placeholder = e.placeholder ?? "", e.min !== void 0 && (o.min = String(e.min)), e.max !== void 0 && (o.max = String(e.max)), e.step !== void 0 && (o.step = String(e.step)), o.addEventListener("input", () => {
2362
+ t[e.name] = o.value;
2363
+ }), o.addEventListener("keydown", (a) => {
2364
+ a.key === "Enter" && (a.preventDefault(), n(t));
2365
+ }), r.append(o), r;
2366
+ }, us = ({
2367
+ field: e,
2368
+ values: t,
2369
+ onSubmit: n
2370
+ }) => e.type === "color" ? ls(e, t, n) : e.type === "text" ? cs(e, t, n) : e.type === "number" ? ds(e, t, n) : is(e, t, n), ms = (e) => {
2371
+ var t, n, r;
2372
+ return e.defaultValue ?? (e.type === "select" ? (t = e.options[0]) == null ? void 0 : t.value : void 0) ?? (e.type === "color" ? (r = (n = e.options) == null ? void 0 : n[0]) == null ? void 0 : r.value : void 0) ?? "";
2373
+ }, gs = (e, t) => (t == null ? void 0 : t[e.name]) ?? (e.type === "color" ? "" : ms(e)), Nt = (e) => e.some((t) => t.type === "text" || t.type === "number"), ps = (e) => {
2374
+ const t = e.querySelector(
2375
+ ".bridgerte__payload-panel-text-input"
2376
+ );
2377
+ queueMicrotask(() => {
2378
+ t == null || t.focus(), t == null || t.select();
2379
+ });
2380
+ }, hs = (e, t, n) => {
2381
+ const r = document.createElement("div"), o = document.createElement("span"), a = (n == null ? void 0 : n(e)) ?? null;
2382
+ if (r.className = "bridgerte__payload-panel-title", o.textContent = e.panel.title, r.append(o), a) {
2383
+ const s = document.createElement("button");
2384
+ s.type = "button", s.className = "bridgerte__payload-panel-clear", s.textContent = "清除", s.setAttribute("aria-label", `清除${e.panel.title}`), z(s), s.addEventListener("pointerdown", (i) => {
2385
+ i.preventDefault();
2386
+ }), s.addEventListener("click", () => {
2387
+ t(a);
2388
+ }), r.append(s);
2389
+ }
2390
+ return r;
2391
+ }, fs = (e) => (
2392
+ /*
2393
+ * 字体类面板只需要紧凑候选列表,颜色面板需要保留一点横向空间给圆盘和黑白按钮。
2394
+ * 输入型面板保留默认宽度;table-insert 会按 schema 网格列数单独计算。
2395
+ */
2396
+ e === "font-size" || e === "font-family" || e === "line-height" ? "180px" : "220px"
2397
+ ), bs = 3, ys = 3, vs = 10, Cn = 10, ws = 16, Cs = 2, _s = 24, Es = () => {
2398
+ var e;
2399
+ return typeof window < "u" && ((e = window.matchMedia) == null ? void 0 : e.call(window, "(hover: hover) and (pointer: fine)").matches) === !0;
2400
+ }, se = (e, t) => {
2401
+ const n = Number.parseInt(e ?? "", 10);
2402
+ return Number.isFinite(n) ? Math.min(Math.max(n, t.min), t.max) : t.defaultValue;
2403
+ }, ks = (e, t) => e.type === "number" && e.name === t, Pt = (e, t) => typeof e == "number" && Number.isFinite(e) && e > 0 ? Math.floor(e) : t, It = (e, t, n, r) => {
2404
+ const o = e.find((m) => ks(m, t)), a = Pt(o == null ? void 0 : o.min, 1), s = Pt(o == null ? void 0 : o.max, n), i = Math.max(a, s), c = Math.min(Math.max(r, a), i), l = se(o == null ? void 0 : o.defaultValue, {
2405
+ min: a,
2406
+ max: i,
2407
+ defaultValue: c
2408
+ });
2409
+ return {
2410
+ min: a,
2411
+ max: i,
2412
+ defaultValue: l
2413
+ };
2414
+ }, _n = (e) => ({
2415
+ rows: It(
2416
+ e,
2417
+ "rows",
2418
+ qt,
2419
+ bs
2420
+ ),
2421
+ cols: It(
2422
+ e,
2423
+ "cols",
2424
+ Kt,
2425
+ ys
2426
+ )
2427
+ }), xs = (e) => {
2428
+ const t = Math.min(e.cols.max, Cn);
2429
+ return `${t * ws + Math.max(t - 1, 0) * Cs + _s}px`;
2430
+ }, Ms = ({
2431
+ fields: e,
2432
+ values: t,
2433
+ onSubmit: n
2434
+ }) => {
2435
+ const r = _n(e), o = document.createElement("section"), a = document.createElement("div"), s = document.createElement("div"), i = [], c = Es(), l = Math.min(r.rows.max, vs), m = Math.min(r.cols.max, Cn), C = {
2436
+ ...r.rows,
2437
+ max: l,
2438
+ defaultValue: Math.min(r.rows.defaultValue, l)
2439
+ }, _ = {
2440
+ ...r.cols,
2441
+ max: m,
2442
+ defaultValue: Math.min(r.cols.defaultValue, m)
2443
+ };
2444
+ let x = se(
2445
+ t.rows,
2446
+ C
2447
+ ), h = se(
2448
+ t.cols,
2449
+ _
2450
+ ), v = null;
2451
+ const S = (k, b) => {
2452
+ x = k, h = b, t.rows = String(k), t.cols = String(b), s.textContent = `${k} x ${b}`, i.forEach((g) => {
2453
+ const d = Number.parseInt(g.dataset.rows ?? "0", 10), y = Number.parseInt(g.dataset.cols ?? "0", 10);
2454
+ g.dataset.active = String(d <= k && y <= b);
2455
+ });
2456
+ }, p = (k) => {
2457
+ var b;
2458
+ return ((b = document.elementFromPoint(k.clientX, k.clientY)) == null ? void 0 : b.closest(".bridgerte__payload-panel-table-cell")) ?? null;
2459
+ }, w = (k) => {
2460
+ if (!k) return;
2461
+ const b = se(
2462
+ k.dataset.rows,
2463
+ C
2464
+ ), g = se(
2465
+ k.dataset.cols,
2466
+ _
2467
+ );
2468
+ S(b, g);
2469
+ }, T = () => {
2470
+ n({
2471
+ ...t,
2472
+ rows: String(x),
2473
+ cols: String(h)
2474
+ });
2475
+ }, E = () => {
2476
+ v = null;
2477
+ }, P = () => {
2478
+ window.setTimeout(E, 0);
2479
+ }, I = (k, b) => {
2480
+ if (k.detail > 0 && v !== b) {
2481
+ k.preventDefault(), k.stopPropagation();
2482
+ return;
2483
+ }
2484
+ E(), w(b), T();
2485
+ };
2486
+ for (let k = 1; k <= l; k += 1)
2487
+ for (let b = 1; b <= m; b += 1) {
2488
+ const g = document.createElement("button");
2489
+ g.type = "button", g.className = "bridgerte__payload-panel-table-cell", g.dataset.rows = String(k), g.dataset.cols = String(b), g.setAttribute("aria-label", `插入 ${k} 行 ${b} 列表格`), z(g), g.addEventListener("pointerdown", (d) => {
2490
+ v = g, w(g), d.preventDefault();
2491
+ }), g.addEventListener("pointerup", P), g.addEventListener("pointercancel", E), g.addEventListener("click", (d) => {
2492
+ I(d, g);
2493
+ }), c && g.addEventListener("pointerenter", () => {
2494
+ w(g);
2495
+ }), i.push(g), a.append(g);
2496
+ }
2497
+ return o.className = "bridgerte__payload-panel-field", a.className = "bridgerte__payload-panel-table-grid", a.setAttribute("aria-label", "选择表格行列"), a.style.setProperty(
2498
+ "--bridgerte-payload-panel-table-cols",
2499
+ String(m)
2500
+ ), s.className = "bridgerte__payload-panel-table-status", s.setAttribute("aria-live", "polite"), a.addEventListener("pointermove", (k) => {
2501
+ c || w(p(k));
2502
+ }), S(x, h), o.append(a, s), o;
2503
+ }, Ts = "bridgerte-payload-panel";
2504
+ let Rt = 0;
2505
+ const Ls = () => (Rt += 1, `${Ts}-${Rt}`), be = (e) => e.panel.id === "table-insert", Ss = (e, t) => {
2506
+ const n = document.createElement("button");
2507
+ return n.type = "button", n.className = "bridgerte__payload-panel-submit", n.textContent = "应用", z(n), n.addEventListener("pointerdown", (r) => {
2508
+ r.preventDefault();
2509
+ }), n.addEventListener("click", () => {
2510
+ t(e);
2511
+ }), n;
2512
+ }, Ns = (e) => {
2513
+ let t = null, n = {};
2514
+ const r = hn({
2515
+ root: e.editorRoot,
2516
+ className: "bridgerte__payload-panel",
2517
+ onBackdropClick: () => {
2518
+ o();
2519
+ }
2520
+ });
2521
+ function o() {
2522
+ t = null, n = {}, r.close(), r.content.replaceChildren();
2523
+ }
2524
+ const a = (l) => {
2525
+ var C;
2526
+ if (!t || t.readonly || e.isReadonly()) return;
2527
+ const m = es(t.command, l);
2528
+ m && ((C = e.restoreEditorFocus) == null || C.call(e, () => {
2529
+ o(), e.isReadonly() || e.executeCommand(m);
2530
+ }));
2531
+ }, s = (l) => {
2532
+ var m;
2533
+ !t || t.readonly || e.isReadonly() || (m = e.restoreEditorFocus) == null || m.call(e, () => {
2534
+ o(), e.isReadonly() || e.executeCommand(l);
2535
+ });
2536
+ }, i = (l) => {
2537
+ n = l.panel.fields.reduce((C, _) => (C[_.name] = gs(_, l.currentValues), C), {});
2538
+ const m = be(l) ? xs(_n(l.panel.fields)) : fs(l.panel.id);
2539
+ r.element.style.width = `min(${m}, calc(100vw - 24px))`, r.content.append(hs(l, s, e.getClearCommand)), be(l) ? r.content.append(Ms({
2540
+ fields: l.panel.fields,
2541
+ values: n,
2542
+ onSubmit: a
2543
+ })) : l.panel.fields.forEach((C) => {
2544
+ r.content.append(us({
2545
+ field: C,
2546
+ values: n,
2547
+ onSubmit: a
2548
+ }));
2549
+ }), !be(l) && Nt(l.panel.fields) && r.content.append(Ss(n, a)), r.open(l.anchorRect), !be(l) && Nt(l.panel.fields) && ps(r.content);
2550
+ };
2551
+ return {
2552
+ open: (l) => {
2553
+ var _;
2554
+ o();
2555
+ const m = {
2556
+ ...l,
2557
+ id: Ls(),
2558
+ readonly: e.isReadonly(),
2559
+ submit: a,
2560
+ cancel: o
2561
+ };
2562
+ if (t = m, ((_ = e.onRequest) == null ? void 0 : _.call(e, m)) !== !0) {
2563
+ if (m.readonly) {
2564
+ o();
2565
+ return;
2566
+ }
2567
+ i(l);
2568
+ }
2569
+ },
2570
+ close: o,
2571
+ destroy() {
2572
+ o(), r.destroy();
2573
+ }
2574
+ };
2575
+ }, ie = "bridgerte__table-controls-button", Ps = [
2576
+ "table-insert-row-after",
2577
+ "table-delete-row",
2578
+ "table-insert-column-after",
2579
+ "table-delete-column",
2580
+ "table-delete"
2581
+ ], Is = () => {
2582
+ const e = new Map(ue.map((t) => [t.id, t]));
2583
+ return Ps.map((t) => qr.find((n) => n.id === t) ?? e.get(t)).filter((t) => t !== void 0);
2584
+ }, En = Is(), Rs = new Map(
2585
+ /*
2586
+ * Controls 按钮用 MenuItem.id 查完整 command,同类命令的不同 payload 不能用 command.type 合并。
2587
+ * 后续加入插入前/后、合并/拆分等表格菜单时,只要 id 稳定,就不会互相覆盖。
2588
+ */
2589
+ En.map((e) => [e.id, e])
2590
+ ), As = (e) => e.matches(".bridgerte__table") ? e : e.querySelector(".bridgerte__table") ?? e, Bs = (e, t) => e.classList.contains("bridgerte__table-wrapper") ? e : t.parentElement instanceof HTMLElement ? t.parentElement : t, Ds = (e) => e.querySelector(".bridgerte__content") ?? e, At = (e) => e instanceof Element ? e.closest(".bridgerte__table-wrapper") : null, Os = (e) => {
2591
+ const t = e.getFirstChild();
2592
+ if (!Pr(t)) return null;
2593
+ const n = t.getFirstChild();
2594
+ return Ir(n) ? n : null;
2595
+ }, Hs = (e) => {
2596
+ const t = document.createElement("button");
2597
+ return t.type = "button", t.className = ie, t.textContent = e.label, t.dataset.menuItemId = e.id, t.setAttribute("aria-label", e.label), t;
2598
+ }, $s = () => {
2599
+ const e = document.createElement("div");
2600
+ return e.className = "bridgerte__table-controls", e.contentEditable = "false", e.setAttribute("aria-label", "表格操作"), En.forEach((t) => {
2601
+ e.append(Hs(t));
2602
+ }), e;
2603
+ }, Fs = (e) => {
2604
+ const t = document.createElement("div"), n = Ds(e.root), r = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
2605
+ let s = null, i = null, c = !1, l = null;
2606
+ const m = (u, f) => {
2607
+ const L = e.root.getBoundingClientRect(), R = f.getBoundingClientRect(), H = R.bottom < L.top || R.top > L.bottom, O = Math.max(
2608
+ 8,
2609
+ L.width - u.offsetWidth - 8
2610
+ ), N = Math.min(
2611
+ Math.max(R.left - L.left + 8, 8),
2612
+ O
2613
+ ), M = Math.max(8, R.top - L.top - u.offsetHeight - 8);
2614
+ u.hidden = H, u.style.transform = `translate(${N}px, ${M}px)`;
2615
+ }, C = (u) => l === u, _ = (u) => {
2616
+ const f = e.editor.getElementByKey(u);
2617
+ if (!f) {
2618
+ x(u);
2619
+ return;
2620
+ }
2621
+ f.dataset.lexicalKey = u;
2622
+ const L = As(f), R = Bs(f, L);
2623
+ a.set(R, u);
2624
+ const H = r.get(u);
2625
+ if (!C(u)) {
2626
+ x(u);
2627
+ return;
2628
+ }
2629
+ if (H) {
2630
+ m(H, R);
2631
+ return;
2632
+ }
2633
+ const O = $s(), N = z(O, {
2634
+ targetSelector: `.${ie}`
2635
+ });
2636
+ O.dataset.lexicalKey = u, r.set(u, O), o.set(O, N), t.append(O), m(O, R);
2637
+ }, x = (u) => {
2638
+ var L;
2639
+ const f = r.get(u);
2640
+ f && ((L = o.get(f)) == null || L(), o.delete(f), f.remove(), r.delete(u), l === u && (l = null));
2641
+ }, h = () => {
2642
+ s = null, a.forEach((u, f) => {
2643
+ e.root.contains(f) || (a.delete(f), x(u));
2644
+ }), e.root.querySelectorAll(".bridgerte__table-wrapper").forEach((u) => {
2645
+ const f = u.dataset.lexicalKey;
2646
+ f && (a.set(u, f), _(f));
2647
+ }), r.forEach((u, f) => {
2648
+ _(f);
2649
+ }), l !== null && _(l);
2650
+ }, v = () => {
2651
+ s === null && (s = Ce(h));
2652
+ }, S = (u) => {
2653
+ e.editor.update(() => {
2654
+ var L;
2655
+ const f = ce(u);
2656
+ f instanceof De && ((L = Os(f)) == null || L.selectStart());
2657
+ }), e.editor.focus();
2658
+ }, p = (u, f) => {
2659
+ S(u), e.executeCommand(f);
2660
+ }, w = (u, f) => {
2661
+ const L = f.dataset.lexicalKey, R = u.dataset.menuItemId, H = R ? Rs.get(R) : void 0;
2662
+ !L || !H || p(L, H.command);
2663
+ }, T = (u) => {
2664
+ if (!u) {
2665
+ const R = l;
2666
+ l = null, R !== null && _(R);
2667
+ return;
2668
+ }
2669
+ const f = u.dataset.lexicalKey ? u.dataset.lexicalKey : a.get(u) ?? null;
2670
+ if (!f || l === f) return;
2671
+ const L = l;
2672
+ l = f, L !== null && _(L), _(f);
2673
+ }, E = (u) => {
2674
+ T(At(u.target));
2675
+ }, P = (u) => {
2676
+ T(At(u.target));
2677
+ }, I = (u) => {
2678
+ const f = u.target;
2679
+ if (!(f instanceof HTMLElement)) return;
2680
+ const L = f.closest(`.${ie}`);
2681
+ L && (u.preventDefault(), i = u.pointerType === "mouse" ? null : L);
2682
+ }, k = (u) => {
2683
+ if (u.pointerType === "mouse" || !i) return;
2684
+ const f = u.target, L = f instanceof HTMLElement ? f.closest(".bridgerte__table-controls") : null, R = f instanceof HTMLElement ? f.closest(`.${ie}`) : null;
2685
+ R === i && L && (u.preventDefault(), u.stopPropagation(), w(R, L), c = !0), i = null;
2686
+ }, b = () => {
2687
+ i = null;
2688
+ }, g = (u) => {
2689
+ if (c) {
2690
+ c = !1, u.preventDefault(), u.stopPropagation();
2691
+ return;
2692
+ }
2693
+ const f = u.target;
2694
+ if (!(f instanceof HTMLElement)) return;
2695
+ const L = f.closest(`.${ie}`), R = f.closest(".bridgerte__table-controls");
2696
+ !L || !R || (u.preventDefault(), u.stopPropagation(), w(L, R));
2697
+ }, d = e.editor.registerMutationListener(
2698
+ De,
2699
+ (u) => {
2700
+ u.forEach((f, L) => {
2701
+ if (f === "destroyed") {
2702
+ x(L);
2703
+ return;
2704
+ }
2705
+ _(L);
2706
+ });
2707
+ }
2708
+ ), y = e.editor.registerUpdateListener(v);
2709
+ return t.className = "bridgerte__table-controls-layer", e.root.append(t), t.addEventListener("pointerdown", I), t.addEventListener("pointerup", k), t.addEventListener("pointercancel", b), t.addEventListener("click", g), n.addEventListener("pointerdown", E), n.addEventListener("focusin", P), n.addEventListener("scroll", v, { passive: !0 }), window.addEventListener("resize", v), {
2710
+ destroy() {
2711
+ d(), y(), s !== null && (Ye(s), s = null), t.removeEventListener("pointerdown", I), t.removeEventListener("pointerup", k), t.removeEventListener("pointercancel", b), t.removeEventListener("click", g), n.removeEventListener("pointerdown", E), n.removeEventListener("focusin", P), n.removeEventListener("scroll", v), window.removeEventListener("resize", v), r.forEach((u) => {
2712
+ var f;
2713
+ (f = o.get(u)) == null || f(), u.remove();
2714
+ }), r.clear(), o.clear(), a.clear(), t.remove();
2715
+ }
2716
+ };
2717
+ }, zs = (e) => {
2718
+ const t = Ns({
2719
+ editorRoot: e.editorRoot,
2720
+ isReadonly: e.isReadonly,
2721
+ restoreEditorFocus: e.restoreEditorFocus,
2722
+ executeCommand: e.executeCommand,
2723
+ getClearCommand: e.getClearCommand,
2724
+ onRequest: e.onRequest
2725
+ }), n = Oa({
2726
+ editor: e.lexicalEditor,
2727
+ root: e.editorRoot,
2728
+ isReadonly: e.isReadonly,
2729
+ languagePanel: e.codeBlockLanguagePanel,
2730
+ payloadPanelConfig: e.payloadPanelConfig,
2731
+ onRequest: e.onRequest
2732
+ }), r = Fs({
2733
+ editor: e.lexicalEditor,
2734
+ root: e.editorRoot,
2735
+ executeCommand: e.executeCommand
2736
+ }), o = Qa({
2737
+ editor: e.lexicalEditor,
2738
+ root: e.editorRoot,
2739
+ defaultWidthPercent: e.defaultMediaWidthPercent,
2740
+ executeCommand: e.executeCommand,
2741
+ mediaControlsConfig: e.mediaControlsConfig,
2742
+ menuLabels: e.menuLabels
2743
+ });
2744
+ return {
2745
+ payloadPanelController: t,
2746
+ codeBlockController: n,
2747
+ tableHeaderController: r,
2748
+ mediaControlsController: o,
2749
+ destroy() {
2750
+ t.destroy(), n.destroy(), r.destroy(), o.destroy();
2751
+ }
2752
+ };
2753
+ }, Ws = (e, t) => {
2754
+ const n = document.createElement("div"), r = document.createElement("div"), o = document.createElement("div"), a = document.createElement("div");
2755
+ return e.classList.add("bridgerte"), e.textContent = "", n.className = "bridgerte__editor", a.className = "bridgerte__content", a.dataset.placeholder = t.placeholder, a.setAttribute("role", "textbox"), a.setAttribute("aria-multiline", "true"), r.append(a), t.shouldRenderToolbar && t.toolbarPlacement === "top" && n.append(o), n.append(r), t.shouldRenderToolbar && t.toolbarPlacement === "bottom" && n.append(o), e.append(n), {
2756
+ rootElement: n,
2757
+ editorElement: r,
2758
+ toolbarElement: o,
2759
+ contentElement: a
2760
+ };
2761
+ }, Us = ({
2762
+ editor: e
2763
+ }) => {
2764
+ let t = null;
2765
+ return {
2766
+ capture() {
2767
+ e.getEditorState().read(() => {
2768
+ var n;
2769
+ t = ((n = A()) == null ? void 0 : n.clone()) ?? null;
2770
+ });
2771
+ },
2772
+ restore() {
2773
+ t && e.update(() => {
2774
+ qn((t == null ? void 0 : t.clone()) ?? null);
2775
+ });
2776
+ },
2777
+ clear() {
2778
+ t = null;
2779
+ }
2780
+ };
2781
+ }, Vs = /((https?:\/\/|www\.)[^\s<>()]+[^\s<>().,;:!?])/i, js = /([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,})/i, qs = {
2782
+ changeHandlers: [],
2783
+ excludeParents: [],
2784
+ matchers: [
2785
+ at(Vs, (e) => e.startsWith("http://") || e.startsWith("https://") ? e : `https://${e}`),
2786
+ at(js, (e) => `mailto:${e}`)
2787
+ ]
2788
+ }, Ks = ({
2789
+ editor: e
2790
+ }) => $r(e, qs), Gs = [
2791
+ ".bridgerte__code-header",
2792
+ ".bridgerte__code-block-control",
2793
+ ".bridgerte__code-block-controls-layer",
2794
+ ".bridgerte__code-block-menu",
2795
+ ".bridgerte__table-controls-layer",
2796
+ ".bridgerte__table-controls",
2797
+ ".bridgerte__media-controls-layer",
2798
+ ".bridgerte__media-controls",
2799
+ ".bridgerte__dialog-backdrop",
2800
+ ".bridgerte__dialog",
2801
+ ".bridgerte__payload-panel"
2802
+ ].join(","), Xs = (e, t) => {
2803
+ const n = e.anchorNode, r = e.focusNode;
2804
+ return n !== null && r !== null && t.contains(n) && t.contains(r);
2805
+ }, Js = (e) => {
2806
+ e.querySelectorAll(Gs).forEach((t) => {
2807
+ t.remove();
2808
+ }), e.querySelectorAll('[contenteditable="false"]').forEach((t) => {
2809
+ t.classList.contains("bridgerte__media") || t.remove();
2810
+ });
2811
+ }, Ys = (e) => {
2812
+ const t = e.ownerDocument.getSelection();
2813
+ if (!t || t.rangeCount === 0 || !Xs(t, e))
2814
+ return null;
2815
+ const n = t.getRangeAt(0).cloneContents();
2816
+ Js(n);
2817
+ const r = e.ownerDocument.createElement("div");
2818
+ return r.append(n), {
2819
+ html: r.innerHTML,
2820
+ text: r.textContent ?? ""
2821
+ };
2822
+ }, Qs = ({
2823
+ target: e,
2824
+ isReadonly: t
2825
+ }) => {
2826
+ const n = (o) => {
2827
+ const a = Ys(e);
2828
+ !a || !o.clipboardData || (o.clipboardData.setData("text/html", a.html), o.clipboardData.setData("text/plain", a.text), o.preventDefault(), o.stopImmediatePropagation());
2829
+ }, r = (o) => {
2830
+ if (t()) {
2831
+ n(o);
2832
+ return;
2833
+ }
2834
+ n(o);
2835
+ };
2836
+ return e.addEventListener("copy", n, { capture: !0 }), e.addEventListener("cut", r, { capture: !0 }), () => {
2837
+ e.removeEventListener("copy", n, { capture: !0 }), e.removeEventListener("cut", r, { capture: !0 });
2838
+ };
2839
+ }, ye = 8, Zs = () => {
2840
+ const e = window.visualViewport;
2841
+ return {
2842
+ left: (e == null ? void 0 : e.offsetLeft) ?? 0,
2843
+ top: (e == null ? void 0 : e.offsetTop) ?? 0,
2844
+ width: (e == null ? void 0 : e.width) ?? window.innerWidth,
2845
+ height: (e == null ? void 0 : e.height) ?? window.innerHeight
2846
+ };
2847
+ }, Bt = (e, t, n) => Math.min(Math.max(e, t), Math.max(t, n));
2848
+ function kn(e, t, n = {}) {
2849
+ const r = n.placement ?? "bottom-start", o = n.offset ?? 8, a = n.shiftPadding ?? 8, s = n.strategy ?? "absolute";
2850
+ let i = null, c = !1;
2851
+ const l = () => {
2852
+ t.style.position = s, t.style.left = "0px", t.style.top = "0px", t.style.opacity = "0", t.style.pointerEvents = "none";
2853
+ }, m = (h, v) => {
2854
+ const S = Zs(), p = t.getBoundingClientRect(), w = S.left + ye, T = S.top + ye, E = S.left + S.width - p.width - ye, P = S.top + S.height - p.height - ye;
2855
+ t.style.left = `${Bt(h, w, E)}px`, t.style.top = `${Bt(v, T, P)}px`, t.style.opacity = "", t.style.pointerEvents = "";
2856
+ }, C = async () => {
2857
+ const h = await Qr(e, t, {
2858
+ placement: r,
2859
+ strategy: s,
2860
+ platform: Zr,
2861
+ middleware: [
2862
+ eo(o),
2863
+ to(),
2864
+ no({ padding: a })
2865
+ ]
2866
+ });
2867
+ m(h.x, h.y);
2868
+ }, _ = () => {
2869
+ i == null || i(), i = null;
2870
+ }, x = (h) => {
2871
+ if (c !== h) {
2872
+ if (c = h, _(), c) {
2873
+ l(), t.hidden = !1, i = Yr(e, t, C), C();
2874
+ return;
2875
+ }
2876
+ t.hidden = !0, t.style.opacity = "", t.style.pointerEvents = "";
2877
+ }
2878
+ };
2879
+ return l(), t.hidden = !0, {
2880
+ update: C,
2881
+ setOpen: x,
2882
+ destroy() {
2883
+ _(), t.hidden = !0;
2884
+ }
2885
+ };
2886
+ }
2887
+ const ze = () => {
2888
+ const e = window.getSelection(), t = e != null && e.rangeCount ? e.getRangeAt(0) : null, n = t == null ? void 0 : t.getBoundingClientRect();
2889
+ return !n || n.width === 0 && n.height === 0 ? null : n;
2890
+ }, ei = 160, ti = {
2891
+ toolbarKeys: [
2892
+ "bold",
2893
+ "italic",
2894
+ "underline",
2895
+ "strike",
2896
+ "inline-code",
2897
+ "clear-style",
2898
+ "|",
2899
+ "color",
2900
+ "background-color",
2901
+ "font-size",
2902
+ "font-family",
2903
+ "line-height"
2904
+ ]
2905
+ }, ni = () => {
2906
+ const e = A();
2907
+ return D(e) && !e.isCollapsed();
2908
+ }, Dt = (e, t) => e.target instanceof Node && t.contains(e.target), Ot = (e) => e instanceof Element ? e.closest(".bridgerte__hoverbar-button") : null, ri = (e) => e.flatMap((t) => t.type === "button" ? [t.item] : t.type === "group" ? t.items : []), oi = (e) => {
2909
+ const t = document.createElement("span");
2910
+ return t.className = "bridgerte__hoverbar-separator", t.dataset.separatorId = e.key, t.setAttribute("aria-hidden", "true"), t;
2911
+ }, ai = (e, t, n) => {
2912
+ const r = dn(e, t), o = document.createElement("button");
2913
+ return o.type = "button", o.className = "bridgerte__hoverbar-button", o.dataset.hoverbarItemId = e.id, o.dataset.active = String(r.active), o.disabled = r.disabled, o.setAttribute("aria-label", e.label), o.setAttribute("aria-pressed", String(r.active)), Je(o, n[e.icon] ?? Xe[e.icon], e.label), o;
2914
+ }, si = ({
2915
+ editorRoot: e,
2916
+ contentElement: t,
2917
+ editor: n,
2918
+ isReadonly: r,
2919
+ executeCommand: o,
2920
+ requestPayloadPanel: a,
2921
+ getCommandStates: s,
2922
+ menuSchema: i,
2923
+ hoverbarConfig: c,
2924
+ menuLabels: l,
2925
+ payloadPanelConfig: m,
2926
+ icons: C = {}
2927
+ }) => {
2928
+ const _ = ke(i ?? ue, {
2929
+ menuLabels: l,
2930
+ payloadPanelConfig: m
2931
+ }), x = Ee(c ?? ti, _), h = ri(x), v = document.createElement("span"), S = document.createElement("div");
2932
+ let p = null, w = !1, T = null;
2933
+ const E = z(S, {
2934
+ targetSelector: ".bridgerte__hoverbar-button"
2935
+ });
2936
+ v.className = "bridgerte__hoverbar-anchor", v.setAttribute("aria-hidden", "true"), S.className = "bridgerte__floating-menu bridgerte__hoverbar", S.setAttribute("role", "toolbar"), S.setAttribute("aria-label", "BridgeRTE hoverbar"), e.append(v, S), p = kn(v, S, {
2937
+ placement: "top",
2938
+ offset: 8,
2939
+ strategy: "fixed"
2940
+ });
2941
+ const P = () => {
2942
+ T && (window.clearTimeout(T), T = null);
2943
+ }, I = () => {
2944
+ P(), w = !1, S.replaceChildren(), S.dataset.visible = "false", p == null || p.setOpen(!1);
2945
+ }, k = () => {
2946
+ const N = ze(), M = t.getBoundingClientRect();
2947
+ v.style.left = `${(N == null ? void 0 : N.left) ?? M.left}px`, v.style.top = `${(N == null ? void 0 : N.top) ?? M.top}px`, v.style.width = `${(N == null ? void 0 : N.width) || 1}px`, v.style.height = `${(N == null ? void 0 : N.height) || 1}px`;
2948
+ }, b = () => {
2949
+ const N = s();
2950
+ S.replaceChildren(...x.flatMap((M) => M.type === "separator" ? [oi(M)] : (M.type === "button" ? [M.item] : M.items).map((F) => ai(F, N, C)))), k(), w = !0, S.dataset.visible = "true", p == null || p.setOpen(!0), p == null || p.update();
2951
+ }, g = () => r() ? !1 : n.getEditorState().read(ni), d = (N = !1) => {
2952
+ if (P(), !g()) {
2953
+ I();
2954
+ return;
2955
+ }
2956
+ if (N) {
2957
+ b();
2958
+ return;
2959
+ }
2960
+ w && I(), T = window.setTimeout(() => {
2961
+ T = null, g() && b();
2962
+ }, ei);
2963
+ }, y = (N) => {
2964
+ const M = h.find((B) => B.id === N.dataset.hoverbarItemId);
2965
+ if (!(!M || N.disabled)) {
2966
+ if (M.payloadPanel) {
2967
+ const B = N.getBoundingClientRect();
2968
+ a({
2969
+ menuId: M.id,
2970
+ command: M.command,
2971
+ panel: M.payloadPanel,
2972
+ currentValues: cn(M, s()),
2973
+ anchorRect: {
2974
+ x: B.left,
2975
+ y: B.top,
2976
+ width: B.width,
2977
+ height: B.height
2978
+ }
2979
+ }), d(!0);
2980
+ return;
2981
+ }
2982
+ o(M.command), d(!0);
2983
+ }
2984
+ }, u = (N) => {
2985
+ Ot(N.target) && N.preventDefault();
2986
+ }, f = (N) => {
2987
+ const M = Ot(N.target);
2988
+ M && (N.preventDefault(), y(M));
2989
+ }, L = (N) => {
2990
+ !w || Dt(N, S) || Dt(N, t) || I();
2991
+ }, R = n.registerCommand(
2992
+ Xt,
2993
+ () => (d(), !1),
2994
+ V
2995
+ ), H = n.registerUpdateListener(() => {
2996
+ d();
2997
+ }), O = n.registerCommand(
2998
+ Jt,
2999
+ (N) => w ? (N == null || N.preventDefault(), I(), !0) : !1,
3000
+ V
3001
+ );
3002
+ return S.addEventListener("pointerdown", u), S.addEventListener("click", f), document.addEventListener("pointerdown", L, !0), () => {
3003
+ P(), R(), H(), O(), S.removeEventListener("pointerdown", u), S.removeEventListener("click", f), document.removeEventListener("pointerdown", L, !0), E(), p == null || p.destroy(), v.remove(), S.remove();
3004
+ };
3005
+ }, ii = (e) => e.metaKey || e.ctrlKey, li = {
3006
+ b: { type: "format.bold" },
3007
+ i: { type: "format.italic" },
3008
+ u: { type: "format.underline" },
3009
+ "\\": { type: "format.clear" }
3010
+ }, ci = {
3011
+ x: { type: "format.strike" },
3012
+ l: { type: "align", value: "left" },
3013
+ e: { type: "align", value: "center" },
3014
+ r: { type: "align", value: "right" },
3015
+ j: { type: "align", value: "justify" }
3016
+ }, di = {
3017
+ 0: { type: "block.paragraph" },
3018
+ 1: { type: "block.heading", level: 1 },
3019
+ 2: { type: "block.heading", level: 2 },
3020
+ 3: { type: "block.heading", level: 3 },
3021
+ 4: { type: "block.heading", level: 4 },
3022
+ 5: { type: "block.heading", level: 5 },
3023
+ 6: { type: "block.heading", level: 6 }
3024
+ }, ui = (e) => {
3025
+ const t = e.key.toLowerCase(), n = e.code;
3026
+ if (!e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey || !ii(e)) return null;
3027
+ if (e.altKey) {
3028
+ if (e.shiftKey) return null;
3029
+ if (t === "c" || n === "KeyC") return { type: "block.code" };
3030
+ const r = n.startsWith("Digit") ? n.slice(5) : t;
3031
+ return di[r] ?? null;
3032
+ }
3033
+ return e.shiftKey ? t === "z" ? { type: "history.redo" } : t === "." || t === ">" || n === "Period" ? { type: "block.quote" } : t === "7" || t === "&" || n === "Digit7" ? { type: "list.ordered" } : t === "8" || t === "*" || n === "Digit8" ? { type: "list.unordered" } : t === "9" || t === "(" || n === "Digit9" ? { type: "list.todo" } : t === "-" || t === "_" || n === "Minus" ? { type: "block.divider" } : ci[t] ?? null : t === "z" ? { type: "history.undo" } : t === "y" && e.ctrlKey && !e.metaKey ? { type: "history.redo" } : t === "`" || t === "~" || n === "Backquote" ? { type: "format.inlineCode" } : li[t] ?? null;
3034
+ }, mi = ({
3035
+ target: e,
3036
+ isReadonly: t,
3037
+ executeCommand: n
3038
+ }) => {
3039
+ const r = (o) => {
3040
+ if (t()) return;
3041
+ const a = ui(o);
3042
+ a && (o.preventDefault(), n(a));
3043
+ };
3044
+ return e.addEventListener("keydown", r), () => {
3045
+ e.removeEventListener("keydown", r);
3046
+ };
3047
+ }, gi = (e, t) => {
3048
+ const n = t.offsetTop, r = n + t.offsetHeight, o = e.scrollTop, a = o + e.clientHeight;
3049
+ if (n < o) {
3050
+ e.scrollTop = n;
3051
+ return;
3052
+ }
3053
+ r > a && (e.scrollTop = r - e.clientHeight);
3054
+ }, Ze = (e, t) => {
3055
+ var n;
3056
+ if (e instanceof Text && t <= (((n = e.textContent) == null ? void 0 : n.length) ?? 0)) return e;
3057
+ for (const r of Array.from((e == null ? void 0 : e.childNodes) ?? [])) {
3058
+ const o = Ze(r, t);
3059
+ if (o) return o;
3060
+ }
3061
+ return null;
3062
+ }, xn = ({
3063
+ editorRoot: e,
3064
+ contentElement: t,
3065
+ editor: n,
3066
+ isReadonly: r,
3067
+ menu: o,
3068
+ anchor: a,
3069
+ itemSelector: s,
3070
+ getCurrentTrigger: i,
3071
+ getTriggerRect: c,
3072
+ resolveItems: l,
3073
+ renderItem: m,
3074
+ renderStatus: C,
3075
+ onStateChange: _,
3076
+ onSelect: x
3077
+ }) => {
3078
+ let h = null, v = 0;
3079
+ const S = z(o, {
3080
+ targetSelector: s
3081
+ }), p = kn(a, o, {
3082
+ placement: "bottom-start",
3083
+ offset: 2,
3084
+ strategy: "fixed"
3085
+ });
3086
+ e.append(a, o);
3087
+ const w = () => {
3088
+ const M = h ? c(h.trigger) ?? ze() : ze(), B = t.getBoundingClientRect();
3089
+ return M ?? B;
3090
+ }, T = () => {
3091
+ const M = w();
3092
+ a.style.left = `${M.left}px`, a.style.top = `${M.top}px`, a.style.height = `${M.height || 1}px`;
3093
+ }, E = (M = !0) => {
3094
+ h = null, o.dataset.visible = "false", M && o.replaceChildren(), p.setOpen(!1);
3095
+ }, P = () => {
3096
+ const M = o.querySelector(`${s}[data-active="true"]`);
3097
+ M && gi(o, M);
3098
+ }, I = (M, B) => {
3099
+ !h || h.requestId !== B.requestId || (E(), x(M, B.trigger));
3100
+ }, k = () => {
3101
+ if (!h) {
3102
+ E();
3103
+ return;
3104
+ }
3105
+ const M = h, B = w();
3106
+ if ((_ == null ? void 0 : _(M, {
3107
+ anchorRect: B,
3108
+ close: E,
3109
+ selectItem: (Z) => I(Z, M)
3110
+ })) === !0) {
3111
+ o.replaceChildren(), o.dataset.visible = "false", p.setOpen(!1);
3112
+ return;
3113
+ }
3114
+ if (M.status === "success")
3115
+ o.replaceChildren(
3116
+ ...M.items.map((Z, rt) => m(Z, rt, rt === M.activeIndex))
3117
+ );
3118
+ else {
3119
+ const Z = C == null ? void 0 : C(
3120
+ M.status,
3121
+ M.trigger.query,
3122
+ M.error
3123
+ );
3124
+ o.replaceChildren(...Z ? [Z] : []);
3125
+ }
3126
+ const G = o.children.length > 0;
3127
+ o.dataset.visible = String(G), T(), p.setOpen(G), P(), p.update();
3128
+ }, b = async (M, B) => {
3129
+ let F;
3130
+ try {
3131
+ F = await Promise.resolve(l(M));
3132
+ } catch (G) {
3133
+ (h == null ? void 0 : h.requestId) === B && (h = {
3134
+ ...h,
3135
+ items: [],
3136
+ activeIndex: 0,
3137
+ status: "error",
3138
+ error: G
3139
+ }, k());
3140
+ return;
3141
+ }
3142
+ !h || B !== h.requestId || (h = {
3143
+ ...h,
3144
+ items: F,
3145
+ activeIndex: Math.min(h.activeIndex, Math.max(F.length - 1, 0)),
3146
+ status: F.length > 0 ? "success" : "empty",
3147
+ error: void 0
3148
+ }, k());
3149
+ }, g = () => {
3150
+ if (r()) {
3151
+ E();
3152
+ return;
3153
+ }
3154
+ const M = n.getEditorState().read(i);
3155
+ if (!M) {
3156
+ E(!1);
3157
+ return;
3158
+ }
3159
+ v += 1, h = {
3160
+ trigger: M,
3161
+ items: [],
3162
+ activeIndex: 0,
3163
+ requestId: v,
3164
+ status: "loading",
3165
+ error: void 0
3166
+ }, k(), b(M.query, v);
3167
+ }, d = () => {
3168
+ if (!h || h.status !== "success") return !1;
3169
+ const M = h.items[h.activeIndex], B = h.trigger;
3170
+ return M ? (E(), x(M, B), !0) : !1;
3171
+ }, y = (M) => !h || h.status !== "success" || h.items.length === 0 ? !1 : (h = {
3172
+ ...h,
3173
+ activeIndex: (h.activeIndex + M + h.items.length) % h.items.length
3174
+ }, k(), !0), u = (M) => {
3175
+ const B = M.target, F = B instanceof HTMLElement ? B.closest(s) : null, G = F != null && F.dataset.index ? Number.parseInt(F.dataset.index, 10) : Number.NaN;
3176
+ !h || h.status !== "success" || Number.isNaN(G) || (h = { ...h, activeIndex: G }, M.preventDefault(), d());
3177
+ }, f = (M) => {
3178
+ const B = M.target;
3179
+ B instanceof HTMLElement && B.closest(s) && M.preventDefault();
3180
+ }, L = n.registerUpdateListener(() => {
3181
+ g();
3182
+ }), R = n.registerCommand(
3183
+ Kn,
3184
+ (M) => y(1) ? (M == null || M.preventDefault(), !0) : !1,
3185
+ V
3186
+ ), H = n.registerCommand(
3187
+ Gn,
3188
+ (M) => y(-1) ? (M == null || M.preventDefault(), !0) : !1,
3189
+ V
3190
+ ), O = n.registerCommand(
3191
+ Xn,
3192
+ (M) => d() ? (M == null || M.preventDefault(), !0) : !1,
3193
+ V
3194
+ ), N = n.registerCommand(
3195
+ Jt,
3196
+ (M) => h ? (M == null || M.preventDefault(), E(), !0) : !1,
3197
+ V
3198
+ );
3199
+ return o.addEventListener("click", u), o.addEventListener("pointerdown", f), {
3200
+ close: E,
3201
+ destroy() {
3202
+ L(), R(), H(), O(), N(), o.removeEventListener("click", u), o.removeEventListener("pointerdown", f), S(), p.destroy(), a.remove(), o.remove();
3203
+ }
3204
+ };
3205
+ }, pi = {
3206
+ labelField: "label",
3207
+ descriptionField: "description",
3208
+ avatarField: "avatar",
3209
+ iconField: "data.icon",
3210
+ showAvatar: !0,
3211
+ showIcon: !0,
3212
+ showDescription: !0,
3213
+ loadingText: "加载中",
3214
+ emptyText: "没有匹配的提及",
3215
+ errorText: "提及加载失败"
3216
+ }, hi = (e) => ({
3217
+ ...pi,
3218
+ ...e
3219
+ }), fi = (e, t) => {
3220
+ var o;
3221
+ const n = t.slice(5), r = (o = e.data) == null ? void 0 : o[n];
3222
+ return typeof r == "string" && r ? r : void 0;
3223
+ }, ve = (e, t) => {
3224
+ if (t.startsWith("data.")) return fi(e, t);
3225
+ const n = t === "id" ? e.id : t === "label" ? e.label : t === "value" ? e.value : t === "avatar" ? e.avatar : e.description;
3226
+ return typeof n == "string" && n ? n : void 0;
3227
+ }, bi = (e) => e.startsWith("@") ? e : `@${e}`, Mn = (e, t) => {
3228
+ const n = ve(e, t.labelField) ?? e.label ?? e.value ?? e.id, r = t.showDescription ? ve(e, t.descriptionField) ?? e.description : void 0, o = t.showAvatar ? ve(e, t.avatarField) ?? e.avatar : void 0, a = t.showIcon && !o ? ve(e, t.iconField) : void 0;
3229
+ return {
3230
+ item: e,
3231
+ label: bi(n),
3232
+ ...r ? { description: r } : {},
3233
+ ...o ? { avatar: o } : {},
3234
+ ...a ? { icon: a } : {}
3235
+ };
3236
+ }, yi = (e, t) => e.map((n) => Mn(n, t)), We = (e) => e instanceof Q && e.getTextContent().startsWith(" "), vi = (e) => {
3237
+ const n = e.getTextContent().slice(1);
3238
+ if (!n) {
3239
+ e.remove();
3240
+ return;
3241
+ }
3242
+ e.setTextContent(n);
3243
+ }, wi = (e, t) => {
3244
+ const n = e.getPreviousSibling(), r = e.getNextSibling(), o = We(r) ? r.getNextSibling() : r;
3245
+ if (We(r) && vi(r), e.remove(), t) {
3246
+ n == null || n.selectEnd();
3247
+ return;
3248
+ }
3249
+ o == null || o.selectStart();
3250
+ }, Ci = (e) => {
3251
+ const t = A();
3252
+ if (!D(t) || !t.isCollapsed()) return null;
3253
+ const n = t.anchor, r = n.getNode();
3254
+ if (ht(r)) return r;
3255
+ if (!(r instanceof Q)) return null;
3256
+ const o = r.getTextContentSize(), a = r.getPreviousSibling(), s = r.getNextSibling(), i = We(r) && n.offset === 1, c = e ? n.offset === 0 || i ? a : null : n.offset === o ? s : null;
3257
+ return ht(c) ? c : null;
3258
+ }, _i = (e, t, n) => {
3259
+ const r = (a) => {
3260
+ if (t()) return !1;
3261
+ const s = Ci(a);
3262
+ return s ? (wi(s, a), n(), !0) : !1;
3263
+ }, o = (a, s) => {
3264
+ const i = r(s);
3265
+ return i && a.preventDefault(), i;
3266
+ };
3267
+ return [
3268
+ e.registerCommand(
3269
+ Jn,
3270
+ (a) => o(a, !0),
3271
+ Le
3272
+ ),
3273
+ e.registerCommand(
3274
+ Yn,
3275
+ (a) => o(a, !1),
3276
+ Le
3277
+ ),
3278
+ e.registerCommand(
3279
+ Qn,
3280
+ (a) => r(a),
3281
+ Le
3282
+ )
3283
+ ];
3284
+ }, Ei = /(?:^|\s)@([\p{L}\p{N}_-]*)$/u, Ht = [
3285
+ { id: "bridgerte-team", label: "BridgeRTE Team", value: "bridgerte-team" },
3286
+ { id: "frontend", label: "Frontend", value: "frontend" },
3287
+ { id: "designer", label: "Designer", value: "designer" }
3288
+ ], ki = (e) => e.trim().toLowerCase(), xi = (e) => [e.label, e.value, e.description].filter(Boolean).join(" ").toLowerCase(), Mi = (e) => {
3289
+ const t = ki(e);
3290
+ return t ? Ht.filter((n) => xi(n).includes(t)) : Ht;
3291
+ }, Ti = () => {
3292
+ const e = A();
3293
+ if (!D(e) || !e.isCollapsed()) return null;
3294
+ const t = e.anchor, n = t.getNode();
3295
+ if (!(n instanceof Q)) return null;
3296
+ const o = n.getTextContent().slice(0, t.offset).match(Ei);
3297
+ if (!o) return null;
3298
+ const a = o[1] ?? "", s = o[0] ?? "", i = s.startsWith("@") ? 0 : 1, c = t.offset - s.length + i;
3299
+ return {
3300
+ query: a,
3301
+ nodeKey: n.getKey(),
3302
+ startOffset: c,
3303
+ endOffset: t.offset
3304
+ };
3305
+ }, Li = () => {
3306
+ const e = document.createElement("div");
3307
+ return e.className = "bridgerte__floating-menu bridgerte__mention-menu", e.dataset.visible = "false", e;
3308
+ }, Si = () => {
3309
+ const e = document.createElement("span");
3310
+ return e.className = "bridgerte__mention-anchor", e.setAttribute("aria-hidden", "true"), e;
3311
+ }, Ni = (e, t) => {
3312
+ var s;
3313
+ const n = e.getElementByKey(t.nodeKey), r = Ze(n, t.startOffset + 1);
3314
+ if (!(r instanceof Text)) return null;
3315
+ const o = document.createRange(), a = Math.min(t.startOffset + 1, ((s = r.textContent) == null ? void 0 : s.length) ?? 0);
3316
+ return a <= t.startOffset ? null : (o.setStart(r, t.startOffset), o.setEnd(r, a), o.getBoundingClientRect());
3317
+ }, Pi = (e, t, n) => {
3318
+ const r = document.createElement("button"), o = document.createElement("span");
3319
+ if (r.type = "button", r.className = "bridgerte__menu-item bridgerte__mention-item", r.dataset.mentionId = e.item.id, r.dataset.index = String(t), r.dataset.active = String(n), e.avatar) {
3320
+ const a = document.createElement("img");
3321
+ a.className = "bridgerte__mention-item-avatar", a.src = e.avatar, a.alt = "", a.setAttribute("aria-hidden", "true"), r.append(a);
3322
+ } else if (e.icon) {
3323
+ const a = document.createElement("span");
3324
+ a.className = "bridgerte__mention-item-icon", a.setAttribute("aria-hidden", "true"), a.textContent = e.icon, r.append(a);
3325
+ }
3326
+ if (o.className = "bridgerte__mention-item-title", o.textContent = e.label, r.append(o), e.description) {
3327
+ const a = document.createElement("span");
3328
+ a.className = "bridgerte__mention-item-description", a.textContent = e.description, r.append(a);
3329
+ }
3330
+ return r;
3331
+ }, Ii = (e, t) => {
3332
+ const n = document.createElement("div");
3333
+ return n.className = "bridgerte__mention-status", n.dataset.status = e, n.textContent = t, n;
3334
+ }, Ri = (e, t) => {
3335
+ switch (e) {
3336
+ case "loading":
3337
+ return t.loadingText;
3338
+ case "empty":
3339
+ return t.emptyText;
3340
+ case "error":
3341
+ return t.errorText;
3342
+ }
3343
+ }, Ai = (e) => e ? {
3344
+ x: e.x,
3345
+ y: e.y,
3346
+ width: e.width,
3347
+ height: e.height
3348
+ } : void 0, Bi = ({
3349
+ editorRoot: e,
3350
+ contentElement: t,
3351
+ editor: n,
3352
+ isReadonly: r,
3353
+ executeCommand: o,
3354
+ mentionProvider: a,
3355
+ mentionMenuConfig: s,
3356
+ onMentionMenuRequest: i
3357
+ }) => {
3358
+ const c = Li(), l = Si(), m = hi(s), C = (h, v) => {
3359
+ n.update(() => {
3360
+ const S = ce(v.nodeKey);
3361
+ S instanceof Q && (S.spliceText(v.startOffset, v.endOffset - v.startOffset, ""), S.select(v.startOffset, v.startOffset));
3362
+ }), o({ type: "mention.insert", item: h });
3363
+ }, _ = xn({
3364
+ editorRoot: e,
3365
+ contentElement: t,
3366
+ editor: n,
3367
+ isReadonly: r,
3368
+ menu: c,
3369
+ anchor: l,
3370
+ itemSelector: ".bridgerte__mention-item",
3371
+ getCurrentTrigger: Ti,
3372
+ getTriggerRect: (h) => Ni(n, h),
3373
+ resolveItems: async (h) => {
3374
+ const v = await Promise.resolve(
3375
+ a ? a(h) : Mi(h)
3376
+ );
3377
+ return yi(v, m);
3378
+ },
3379
+ renderItem: Pi,
3380
+ renderStatus: (h) => Ii(
3381
+ h,
3382
+ Ri(h, m)
3383
+ ),
3384
+ onStateChange: i ? (h, v) => i({
3385
+ id: `bridgerte-mention-menu-${h.requestId}`,
3386
+ query: h.trigger.query,
3387
+ status: h.status,
3388
+ items: h.items,
3389
+ config: m,
3390
+ readonly: r(),
3391
+ anchorRect: Ai(v.anchorRect),
3392
+ ...h.error ? { error: h.error } : {},
3393
+ submit: (S) => v.selectItem(
3394
+ Mn(S, m)
3395
+ ),
3396
+ cancel: v.close
3397
+ }) : void 0,
3398
+ onSelect: (h, v) => C(h.item, v)
3399
+ }), x = Yt(
3400
+ ..._i(n, r, () => _.close(!1))
3401
+ );
3402
+ return () => {
3403
+ x(), _.destroy();
3404
+ };
3405
+ }, Di = [
3406
+ "script",
3407
+ "style",
3408
+ "iframe",
3409
+ "object",
3410
+ "embed",
3411
+ "meta",
3412
+ "link",
3413
+ "xml",
3414
+ "svg",
3415
+ "math",
3416
+ "canvas",
3417
+ "form",
3418
+ "input",
3419
+ "button",
3420
+ "select",
3421
+ "textarea"
3422
+ ].join(","), Oi = [
3423
+ ".bridgerte__code-header",
3424
+ ".bridgerte__code-block-control",
3425
+ ".bridgerte__code-block-controls-layer",
3426
+ ".bridgerte__code-block-menu",
3427
+ ".bridgerte__table-controls-layer",
3428
+ ".bridgerte__table-controls",
3429
+ ".bridgerte__media-controls-layer",
3430
+ ".bridgerte__media-controls",
3431
+ ".bridgerte__dialog-backdrop",
3432
+ ".bridgerte__dialog",
3433
+ ".bridgerte__payload-panel",
3434
+ '[data-bridgerte-clipboard-ui="true"]'
3435
+ ].join(","), Hi = /* @__PURE__ */ new Set([
3436
+ "A",
3437
+ "B",
3438
+ "BLOCKQUOTE",
3439
+ "BR",
3440
+ "CODE",
3441
+ "DEL",
3442
+ "DIV",
3443
+ "EM",
3444
+ "H1",
3445
+ "H2",
3446
+ "H3",
3447
+ "H4",
3448
+ "H5",
3449
+ "H6",
3450
+ "FONT",
3451
+ "I",
3452
+ "LI",
3453
+ "OL",
3454
+ "P",
3455
+ "PRE",
3456
+ "S",
3457
+ "SPAN",
3458
+ "STRIKE",
3459
+ "STRONG",
3460
+ "SUB",
3461
+ "SUP",
3462
+ "TABLE",
3463
+ "TBODY",
3464
+ "TFOOT",
3465
+ "TD",
3466
+ "TH",
3467
+ "THEAD",
3468
+ "TR",
3469
+ "TT",
3470
+ "U",
3471
+ "UL"
3472
+ ]), $i = /* @__PURE__ */ new Set(["http:", "https:", "mailto:"]), Fi = "p,div,blockquote,pre,h1,h2,h3,h4,h5,h6,ul,ol,table", zi = "p,blockquote,pre,h1,h2,h3,h4,h5,h6,ul,ol,table", Wi = /* @__PURE__ */ new Set(["colspan", "rowspan"]), Ui = /* @__PURE__ */ new Set(["TD", "TH"]), Vi = /* @__PURE__ */ new Set(["M", "O", "V", "W"]), ji = /* @__PURE__ */ new Set(["SPAN"]), qi = /* @__PURE__ */ new Set(["color", "background-color"]), Ki = /^#([\da-f]{3}|[\da-f]{6}|[\da-f]{8})$/i, $t = /* @__PURE__ */ new Map([
3473
+ ["B", "strong"],
3474
+ ["DEL", "s"],
3475
+ ["I", "em"],
3476
+ ["STRIKE", "s"],
3477
+ ["TT", "code"]
3478
+ ]), Gi = (e) => {
3479
+ try {
3480
+ const t = new URL(e, window.location.href);
3481
+ return $i.has(t.protocol);
3482
+ } catch {
3483
+ return !1;
3484
+ }
3485
+ }, et = (e) => {
3486
+ e.replaceWith(...e.childNodes);
3487
+ }, tt = (e, t) => {
3488
+ const n = e.ownerDocument.createElement(t);
3489
+ return n.append(...e.childNodes), e.replaceWith(n), n;
3490
+ }, Xi = (e) => {
3491
+ const t = e.tagName.split(":")[0] ?? "";
3492
+ return e.tagName.includes(":") && Vi.has(t);
3493
+ }, Tn = (e) => {
3494
+ [...e.childNodes].forEach((t) => {
3495
+ if (t.nodeType === Node.COMMENT_NODE) {
3496
+ t.remove();
3497
+ return;
3498
+ }
3499
+ Tn(t);
3500
+ });
3501
+ }, Ln = (e) => {
3502
+ [...e.childNodes].forEach((t) => {
3503
+ if (t.nodeType === Node.TEXT_NODE) {
3504
+ const n = t.parentElement, r = !!(n != null && n.closest("pre,code,textarea")), o = (t.textContent ?? "").replace(/[\u200B-\u200D\uFEFF]/g, "").replace(/\u00A0/g, r ? " " : " ");
3505
+ if (r) {
3506
+ t.textContent = o;
3507
+ return;
3508
+ }
3509
+ let a = o.replace(/\s+/g, " ");
3510
+ t.previousSibling || (a = a.trimStart()), t.nextSibling || (a = a.trimEnd()), t.textContent = a;
3511
+ return;
3512
+ }
3513
+ Ln(t);
3514
+ });
3515
+ }, Ji = (e) => /^[1-9]\d*$/.test(e.trim()), nt = (e) => {
3516
+ const t = e.trim().toLowerCase(), [, n] = t.match(Ki) ?? [];
3517
+ return n ? n.length === 8 ? `#${n.slice(2)}` : t : null;
3518
+ }, Yi = (e, t) => {
3519
+ if (!ji.has(e)) return null;
3520
+ const n = t.split(";").flatMap((r) => {
3521
+ const [o, ...a] = r.split(":"), s = o == null ? void 0 : o.trim().toLowerCase(), i = nt(a.join(":"));
3522
+ return !s || !i || !qi.has(s) ? [] : [`${s}: ${i}`];
3523
+ });
3524
+ return n.length > 0 ? `${n.join("; ")};` : null;
3525
+ }, Qi = (e) => {
3526
+ if (Xi(e)) {
3527
+ e.remove();
3528
+ return;
3529
+ }
3530
+ if (!Hi.has(e.tagName)) {
3531
+ et(e);
3532
+ return;
3533
+ }
3534
+ [...e.attributes].forEach((t) => {
3535
+ const n = t.name.toLowerCase();
3536
+ if (n.startsWith("on")) {
3537
+ e.removeAttribute(t.name);
3538
+ return;
3539
+ }
3540
+ if (n === "style") {
3541
+ const r = Yi(e.tagName, t.value);
3542
+ if (r) {
3543
+ e.setAttribute(t.name, r);
3544
+ return;
3545
+ }
3546
+ e.removeAttribute(t.name);
3547
+ return;
3548
+ }
3549
+ if (e.tagName === "A" && n === "href") {
3550
+ if (Gi(t.value)) return;
3551
+ e.removeAttribute(t.name);
3552
+ return;
3553
+ }
3554
+ if (!(e.tagName === "A" && ["target", "rel", "title"].includes(n))) {
3555
+ if (e.tagName === "PRE" && n === xe) {
3556
+ const r = Y(t.value);
3557
+ if (r) {
3558
+ e.setAttribute(t.name, r);
3559
+ return;
3560
+ }
3561
+ e.removeAttribute(t.name);
3562
+ return;
3563
+ }
3564
+ if (e.tagName === "FONT" && n === "color") {
3565
+ if (nt(t.value)) return;
3566
+ e.removeAttribute(t.name);
3567
+ return;
3568
+ }
3569
+ Ui.has(e.tagName) && Wi.has(n) && Ji(t.value) || e.removeAttribute(t.name);
3570
+ }
3571
+ });
3572
+ }, Zi = (e) => {
3573
+ [...e.querySelectorAll("font")].forEach((t) => {
3574
+ const n = t.getAttribute("color"), r = n ? nt(n) : null, o = tt(t, "span");
3575
+ r && o.setAttribute("style", `color: ${r};`);
3576
+ });
3577
+ }, el = (e) => {
3578
+ [...e.querySelectorAll([...$t.keys()].join(","))].forEach((t) => {
3579
+ const n = $t.get(t.tagName);
3580
+ n && tt(t, n);
3581
+ });
3582
+ }, tl = (e) => {
3583
+ [...e.querySelectorAll("div")].reverse().forEach((t) => {
3584
+ if (t.querySelector(zi)) {
3585
+ et(t);
3586
+ return;
3587
+ }
3588
+ tt(t, "p");
3589
+ });
3590
+ }, nl = (e) => {
3591
+ [...e.querySelectorAll("span")].forEach((t) => {
3592
+ t.attributes.length === 0 && et(t);
3593
+ });
3594
+ }, rl = (e) => !["P", "DIV", "SPAN"].includes(e.tagName) || e.querySelector("br,table,ul,ol") ? !1 : !(e.textContent ?? "").trim(), Ft = (e) => {
3595
+ [...e.querySelectorAll("p,div,span")].reverse().forEach((t) => {
3596
+ rl(t) && t.remove();
3597
+ });
3598
+ }, ol = (e) => {
3599
+ var t;
3600
+ return e.nodeType === Node.TEXT_NODE ? !!((t = e.textContent) != null && t.trim()) : e.nodeType !== Node.ELEMENT_NODE ? !1 : !e.matches(Fi);
3601
+ }, al = (e) => {
3602
+ let t = [];
3603
+ const n = () => {
3604
+ if (t.length === 0) return;
3605
+ const r = e.ownerDocument.createElement("p"), o = t[0];
3606
+ o && (e.insertBefore(r, o), t.forEach((a) => {
3607
+ r.append(a);
3608
+ }), t = []);
3609
+ };
3610
+ [...e.childNodes].forEach((r) => {
3611
+ var o;
3612
+ if (r.nodeType === Node.TEXT_NODE && !((o = r.textContent) != null && o.trim())) {
3613
+ r.remove();
3614
+ return;
3615
+ }
3616
+ if (ol(r)) {
3617
+ t.push(r);
3618
+ return;
3619
+ }
3620
+ n();
3621
+ }), n();
3622
+ }, sl = (e) => {
3623
+ const t = document.createElement("template");
3624
+ t.innerHTML = e, t.content.querySelectorAll(Di).forEach((r) => {
3625
+ r.remove();
3626
+ }), t.content.querySelectorAll(Oi).forEach((r) => {
3627
+ r.remove();
3628
+ }), Tn(t.content), Ma(t.content), [...t.content.querySelectorAll("*")].forEach(Qi), Ln(t.content), Zi(t.content), el(t.content), tl(t.content), nl(t.content), Ft(t.content);
3629
+ const n = document.createElement("div");
3630
+ return n.append(t.content.cloneNode(!0)), al(n), Ft(n), n.innerHTML;
3631
+ }, il = /^https?:\/\/[^\s<>"']+\.[^\s<>"']+$/i, ll = /^www\.[^\s<>"']+\.[^\s<>"']+$/i, cl = new RegExp(
3632
+ `^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+(?:/[^\\s<>"']*)?$`,
3633
+ "i"
3634
+ ), dl = /^[^\s@]+@[^\s@]+\.[^\s@]+$/i, ul = (e) => e.type.startsWith("image/") ? "image" : e.type.startsWith("video/") ? "video" : null, Sn = (e) => e ? [...e].flatMap((t) => {
3635
+ const n = ul(t);
3636
+ return n ? [{ type: n, file: t }] : [];
3637
+ }) : [], Me = (e) => ({
3638
+ text: (e == null ? void 0 : e.getData("text/plain")) ?? "",
3639
+ html: (e == null ? void 0 : e.getData("text/html")) ?? "",
3640
+ files: e != null && e.files ? [...e.files] : []
3641
+ }), ml = (e) => ({
3642
+ name: e.name,
3643
+ mimeType: e.type || void 0,
3644
+ size: e.size,
3645
+ data: e
3646
+ }), gl = (e) => {
3647
+ const t = e.trim();
3648
+ return !t || /\s/.test(t) || t.includes("<") || t.includes(">") || /^[a-z][a-z0-9+.-]*:/i.test(t) && !/^https?:\/\//i.test(t) || dl.test(t) ? !1 : il.test(t) || ll.test(t) || cl.test(t);
3649
+ }, Nn = (e, {
3650
+ isReadonly: t,
3651
+ executeCommand: n
3652
+ }) => t() || !gl(e.text) ? !1 : (n({
3653
+ type: "link.set",
3654
+ href: e.text.trim()
3655
+ }), !0), Ue = (e, {
3656
+ isReadonly: t,
3657
+ canUploadMedia: n,
3658
+ uploadMediaFile: r
3659
+ }) => {
3660
+ if (t() || !n()) return !1;
3661
+ const o = Sn(e.files);
3662
+ return o.length === 0 ? !1 : (o.forEach(({ type: a, file: s }) => {
3663
+ r(a, s);
3664
+ }), !0);
3665
+ }, pl = (e, t) => {
3666
+ const r = new DOMParser().parseFromString(t, "text/html");
3667
+ Ta(r.body);
3668
+ const o = tn(e, r);
3669
+ return La(o, r.body), o;
3670
+ }, hl = (e, t) => {
3671
+ const n = pl(e, t);
3672
+ if (n.length === 0) return !1;
3673
+ if (A() || $().selectEnd(), n.some(K)) {
3674
+ n.forEach((o) => {
3675
+ Jr(o);
3676
+ });
3677
+ const r = n[n.length - 1];
3678
+ return r && K(r) && U([W()]), !0;
3679
+ }
3680
+ return U(n), !0;
3681
+ }, Pn = (e, {
3682
+ editor: t,
3683
+ isReadonly: n
3684
+ }) => {
3685
+ if (n()) return !1;
3686
+ if (!e.html.trim()) return fl(e, { editor: t, isReadonly: n });
3687
+ const r = sl(e.html);
3688
+ return r.trim() ? (t.update(() => {
3689
+ hl(t, r);
3690
+ }), !0) : !1;
3691
+ }, fl = (e, {
3692
+ editor: t,
3693
+ isReadonly: n
3694
+ }) => n() || e.html.trim() || !e.text ? !1 : (t.update(() => {
3695
+ A() || $().selectEnd(), U([je(e.text)]);
3696
+ }), !0), J = (e) => {
3697
+ e.preventDefault(), e.stopImmediatePropagation();
3698
+ }, bl = (e, t) => Ue(e, t) || Nn(e, t) || Pn(e, t), yl = (e) => {
3699
+ const t = (n) => {
3700
+ n.defaultPrevented || Nn(Me(n.clipboardData), e) && J(n);
3701
+ };
3702
+ return e.target.addEventListener("paste", t, { capture: !0 }), () => {
3703
+ e.target.removeEventListener("paste", t, { capture: !0 });
3704
+ };
3705
+ }, vl = (e) => {
3706
+ const t = (o) => {
3707
+ o.defaultPrevented || Ue(Me(o.clipboardData), e) && J(o);
3708
+ }, n = (o) => {
3709
+ var s;
3710
+ if (e.isReadonly() || !e.canUploadMedia()) return;
3711
+ const a = (s = o.dataTransfer) != null && s.files ? [...o.dataTransfer.files] : [];
3712
+ Sn(a).length !== 0 && (o.preventDefault(), o.dataTransfer && (o.dataTransfer.dropEffect = "copy"));
3713
+ }, r = (o) => {
3714
+ var s;
3715
+ const a = {
3716
+ files: (s = o.dataTransfer) != null && s.files ? [...o.dataTransfer.files] : []
3717
+ };
3718
+ Ue(a, e) && J(o);
3719
+ };
3720
+ return e.target.addEventListener("paste", t, { capture: !0 }), e.target.addEventListener("dragover", n), e.target.addEventListener("drop", r), () => {
3721
+ e.target.removeEventListener("paste", t, { capture: !0 }), e.target.removeEventListener("dragover", n), e.target.removeEventListener("drop", r);
3722
+ };
3723
+ }, wl = (e) => {
3724
+ const t = (n) => {
3725
+ n.defaultPrevented || !Pn(Me(n.clipboardData), e) || J(n);
3726
+ };
3727
+ return e.target.addEventListener("paste", t, { capture: !0 }), () => {
3728
+ e.target.removeEventListener("paste", t, { capture: !0 });
3729
+ };
3730
+ }, Cl = ({
3731
+ target: e,
3732
+ isReadonly: t,
3733
+ onPaste: n,
3734
+ canUploadMedia: r,
3735
+ uploadMediaFile: o,
3736
+ executeCommand: a,
3737
+ editor: s
3738
+ }) => {
3739
+ const i = (l, m) => bl({
3740
+ text: m.text ?? l.text,
3741
+ html: m.html ?? l.html,
3742
+ files: l.files
3743
+ }, {
3744
+ isReadonly: t,
3745
+ canUploadMedia: r,
3746
+ uploadMediaFile: o,
3747
+ executeCommand: a,
3748
+ editor: s
3749
+ }), c = (l) => {
3750
+ if (t() || !n) return;
3751
+ const m = Me(l.clipboardData), C = n({
3752
+ text: m.text,
3753
+ html: m.html,
3754
+ files: m.files.map(ml)
3755
+ });
3756
+ if (C instanceof Promise) {
3757
+ J(l), C.then((_) => {
3758
+ _ !== !0 && _ && i(m, _);
3759
+ });
3760
+ return;
3761
+ }
3762
+ if (C === !0) {
3763
+ J(l);
3764
+ return;
3765
+ }
3766
+ C && (J(l), i(m, C));
3767
+ };
3768
+ return e.addEventListener("paste", c, { capture: !0 }), () => {
3769
+ e.removeEventListener("paste", c, { capture: !0 });
3770
+ };
3771
+ }, _l = [
3772
+ "paragraph",
3773
+ "heading-1",
3774
+ "heading-2",
3775
+ "heading-3",
3776
+ "quote",
3777
+ "code-block",
3778
+ "ordered-list",
3779
+ "unordered-list",
3780
+ "todo-list",
3781
+ "divider",
3782
+ "upload-image",
3783
+ "upload-video",
3784
+ "table"
3785
+ ], El = {
3786
+ loadingText: "加载中",
3787
+ emptyText: "没有匹配的命令",
3788
+ errorText: "命令加载失败"
3789
+ }, kl = (e) => ({
3790
+ ...El,
3791
+ ...e
3792
+ }), xl = (e) => e.flatMap((t) => t.type === "button" ? [t.item] : t.type === "group" ? t.items : []), Ml = (e) => ({
3793
+ ...e,
3794
+ toolbarKeys: (e == null ? void 0 : e.toolbarKeys) ?? _l
3795
+ }), Tl = (e) => ({
3796
+ id: e.id,
3797
+ label: e.label,
3798
+ command: e.command,
3799
+ icon: e.icon,
3800
+ requiresPayload: e.requiresPayload,
3801
+ payloadPanel: e.payloadPanel,
3802
+ group: e.group,
3803
+ source: "schema"
3804
+ }), Ll = (e, t) => xl(Ee(
3805
+ Ml(t),
3806
+ e
3807
+ )).map(Tl), In = (e) => ({
3808
+ ...e,
3809
+ source: "provider"
3810
+ }), Sl = /(?:^|\s)\/([\p{L}\p{N}_-]*)$/u, Nl = (e) => e.trim().toLowerCase(), Pl = (e) => [e.label, e.id, e.description, e.group, ...e.keywords ?? []].filter(Boolean).join(" ").toLowerCase(), Il = (e, t) => {
3811
+ const n = Nl(t);
3812
+ return n ? e.filter((r) => Pl(r).includes(n)) : e;
3813
+ }, Rl = async (e, t) => (await Promise.resolve((t == null ? void 0 : t(e)) ?? [])).map(In), Al = (e) => "source" in e ? e : In(e), Bl = ({
3814
+ menuSchema: e,
3815
+ slashCommandConfig: t
3816
+ }) => e !== void 0 || t !== void 0, Dl = () => {
3817
+ const e = A();
3818
+ if (!D(e) || !e.isCollapsed()) return null;
3819
+ const t = e.anchor, n = t.getNode();
3820
+ if (!(n instanceof Q)) return null;
3821
+ const o = n.getTextContent().slice(0, t.offset).match(Sl);
3822
+ if (!o) return null;
3823
+ const a = o[1] ?? "", s = o[0] ?? "", i = s.startsWith("/") ? 0 : 1, c = t.offset - s.length + i;
3824
+ return {
3825
+ query: a,
3826
+ nodeKey: n.getKey(),
3827
+ startOffset: c,
3828
+ endOffset: t.offset
3829
+ };
3830
+ }, Ol = () => {
3831
+ const e = document.createElement("div");
3832
+ return e.className = "bridgerte__floating-menu bridgerte__slash-command-menu", e.dataset.visible = "false", e;
3833
+ }, Hl = () => {
3834
+ const e = document.createElement("span");
3835
+ return e.className = "bridgerte__slash-command-anchor", e.setAttribute("aria-hidden", "true"), e;
3836
+ }, zt = (e, t) => {
3837
+ var s;
3838
+ const n = e.getElementByKey(t.nodeKey), r = Ze(n, t.startOffset + 1);
3839
+ if (!(r instanceof Text)) return null;
3840
+ const o = document.createRange(), a = Math.min(t.startOffset + 1, ((s = r.textContent) == null ? void 0 : s.length) ?? 0);
3841
+ return a <= t.startOffset ? null : (o.setStart(r, t.startOffset), o.setEnd(r, a), o.getBoundingClientRect());
3842
+ }, $l = (e, t, n, r) => {
3843
+ const o = document.createElement("button"), a = document.createElement("span");
3844
+ if (o.type = "button", o.className = "bridgerte__menu-item bridgerte__slash-command-item", o.dataset.commandId = e.id, o.dataset.index = String(t), o.dataset.active = String(n), e.icon) {
3845
+ const s = document.createElement("span");
3846
+ s.className = "bridgerte__slash-command-item-icon", s.setAttribute("aria-hidden", "true"), Je(s, r[e.icon] ?? Xe[e.icon], e.label), o.append(s);
3847
+ }
3848
+ if (a.className = "bridgerte__slash-command-item-title", a.textContent = e.label, o.append(a), e.description) {
3849
+ const s = document.createElement("span");
3850
+ s.className = "bridgerte__slash-command-item-description", s.textContent = e.description, o.append(s);
3851
+ }
3852
+ return o;
3853
+ }, Fl = (e, t) => {
3854
+ const n = document.createElement("div");
3855
+ return n.className = "bridgerte__slash-command-status", n.dataset.status = e, n.textContent = t, n;
3856
+ }, zl = (e, t) => {
3857
+ switch (e) {
3858
+ case "loading":
3859
+ return t.loadingText;
3860
+ case "empty":
3861
+ return t.emptyText;
3862
+ case "error":
3863
+ return t.errorText;
3864
+ }
3865
+ }, Wt = (e) => e ? {
3866
+ x: e.x,
3867
+ y: e.y,
3868
+ width: e.width,
3869
+ height: e.height
3870
+ } : void 0, Wl = ({
3871
+ editorRoot: e,
3872
+ contentElement: t,
3873
+ editor: n,
3874
+ isReadonly: r,
3875
+ executeCommand: o,
3876
+ requestPayloadPanel: a,
3877
+ menuSchema: s,
3878
+ slashCommandConfig: i,
3879
+ icons: c = {},
3880
+ menuLabels: l,
3881
+ payloadPanelConfig: m,
3882
+ slashCommandMenuConfig: C,
3883
+ onSlashCommandMenuRequest: _,
3884
+ slashCommandProvider: x
3885
+ }) => {
3886
+ const h = Ol(), v = Hl(), S = kl(C), p = ke(s ?? ue, {
3887
+ menuLabels: l,
3888
+ payloadPanelConfig: m
3889
+ }), w = Ll(p, i), T = new Map(p.map((g) => [g.id, g])), E = Bl({
3890
+ menuSchema: s,
3891
+ slashCommandConfig: i
3892
+ }), P = (g) => {
3893
+ n.update(() => {
3894
+ const d = ce(g.nodeKey);
3895
+ d instanceof Q && (d.spliceText(g.startOffset, g.endOffset - g.startOffset, ""), d.select(g.startOffset, g.startOffset));
3896
+ });
3897
+ };
3898
+ return xn({
3899
+ editorRoot: e,
3900
+ contentElement: t,
3901
+ editor: n,
3902
+ isReadonly: r,
3903
+ menu: h,
3904
+ anchor: v,
3905
+ itemSelector: ".bridgerte__slash-command-item",
3906
+ getCurrentTrigger: Dl,
3907
+ getTriggerRect: (g) => zt(n, g),
3908
+ resolveItems: async (g) => {
3909
+ const d = E || !x ? Il(w, g) : [];
3910
+ try {
3911
+ const y = await Rl(g, x);
3912
+ return [...d, ...y];
3913
+ } catch (y) {
3914
+ if (d.length > 0) return d;
3915
+ throw y;
3916
+ }
3917
+ },
3918
+ renderItem: (g, d, y) => $l(
3919
+ g,
3920
+ d,
3921
+ y,
3922
+ c
3923
+ ),
3924
+ renderStatus: (g) => Fl(
3925
+ g,
3926
+ zl(g, S)
3927
+ ),
3928
+ onStateChange: _ ? (g, d) => _({
3929
+ id: `bridgerte-slash-command-menu-${g.requestId}`,
3930
+ query: g.trigger.query,
3931
+ status: g.status,
3932
+ items: g.items,
3933
+ config: S,
3934
+ readonly: r(),
3935
+ anchorRect: Wt(d.anchorRect),
3936
+ ...g.error ? { error: g.error } : {},
3937
+ submit: (y) => d.selectItem(Al(y)),
3938
+ cancel: d.close
3939
+ }) : void 0,
3940
+ onSelect: (g, d) => {
3941
+ P(d);
3942
+ const y = g.source === "schema" ? T.get(g.id) : void 0;
3943
+ if (y != null && y.payloadPanel) {
3944
+ const u = zt(n, d);
3945
+ a({
3946
+ menuId: y.id,
3947
+ command: y.command,
3948
+ panel: y.payloadPanel,
3949
+ anchorRect: Wt(u ?? void 0)
3950
+ });
3951
+ return;
3952
+ }
3953
+ o(g.command);
3954
+ }
3955
+ }).destroy;
3956
+ }, Ut = 32, Pe = (e) => {
3957
+ var t;
3958
+ return e instanceof HTMLElement && e.getAttribute("role") === "checkbox" && ((t = e.parentElement) == null ? void 0 : t.classList.contains("bridgerte__list--todo")) === !0;
3959
+ }, Ie = (e) => e instanceof HTMLElement ? e.closest('[role="checkbox"]') : null, Ul = (e) => Zn(e), Vt = (e) => e.button === 0, Re = (e, t) => {
3960
+ const n = t.getBoundingClientRect();
3961
+ return t.dir === "rtl" ? e.clientX >= n.right - Ut && e.clientX <= n.right : e.clientX >= n.left && e.clientX <= n.left + Ut;
3962
+ }, jt = (e) => {
3963
+ e.preventDefault(), e.stopPropagation(), e.stopImmediatePropagation();
3964
+ }, Vl = ({
3965
+ contentElement: e,
3966
+ editor: t,
3967
+ isReadonly: n
3968
+ }) => {
3969
+ let r = 0;
3970
+ const o = (c) => {
3971
+ if (n() || !Vt(c)) return;
3972
+ const l = Ie(c.target);
3973
+ !l || !Pe(l) || Re(c, l) && jt(c);
3974
+ }, a = (c, l) => {
3975
+ jt(c), t.update(() => {
3976
+ const m = Ul(l);
3977
+ wr(m) && m.toggleChecked();
3978
+ });
3979
+ }, s = (c) => {
3980
+ if (n() || !Vt(c) || Date.now() - r < 700) return;
3981
+ const l = Ie(c.target);
3982
+ !l || !Pe(l) || Re(c, l) && a(c, l);
3983
+ }, i = (c) => {
3984
+ if (n() || c.pointerType !== "touch") return;
3985
+ const l = Ie(c.target);
3986
+ !l || !Pe(l) || Re(c, l) && (r = Date.now(), a(c, l));
3987
+ };
3988
+ return e.addEventListener("pointerdown", o, !0), e.addEventListener("pointerup", i, !0), e.addEventListener("click", s, !0), () => {
3989
+ e.removeEventListener("pointerdown", o, !0), e.removeEventListener("pointerup", i, !0), e.removeEventListener("click", s, !0);
3990
+ };
3991
+ }, jl = {
3992
+ ...pr,
3993
+ defaultLanguage: null
3994
+ }, Ae = (e, t) => {
3995
+ var n;
3996
+ return ((n = e.floatingMenus) == null ? void 0 : n[t]) !== !1;
3997
+ }, ql = ({
3998
+ options: e,
3999
+ lexicalEditor: t,
4000
+ editorRoot: n,
4001
+ contentElement: r,
4002
+ historyState: o,
4003
+ isReadonly: a,
4004
+ executeCommand: s,
4005
+ requestPayloadPanel: i,
4006
+ uploadMediaFile: c,
4007
+ canUploadMedia: l,
4008
+ syncAfterEditorUpdate: m,
4009
+ refreshCommandStates: C,
4010
+ getCommandStates: _,
4011
+ setCanUndo: x,
4012
+ setCanRedo: h,
4013
+ enableKeyboardShortcuts: v
4014
+ }) => {
4015
+ const S = Ae(e, "mention"), p = Ae(e, "slash"), w = Ae(e, "hoverbar"), T = Yt(
4016
+ /*
4017
+ * 业务自定义 paste hook 最先看到原始剪贴板摘要;返回 undefined 时完全不拦截,
4018
+ * 继续走 BridgeRTE 内置媒体、URL 和 HTML 清洗链路。
4019
+ */
4020
+ Cl({
4021
+ target: r,
4022
+ isReadonly: a,
4023
+ onPaste: e.onPaste,
4024
+ canUploadMedia: l,
4025
+ uploadMediaFile: c,
4026
+ executeCommand: s,
4027
+ editor: t
4028
+ }),
4029
+ /*
4030
+ * 媒体文件粘贴/拖拽优先于 URL 粘贴快速路径;剪贴板里有文件时直接进入上传管线,
4031
+ * 没有文件再交给纯文本 URL 链接处理或 Lexical 默认粘贴。
4032
+ */
4033
+ vl({
4034
+ target: r,
4035
+ isReadonly: a,
4036
+ canUploadMedia: l,
4037
+ uploadMediaFile: c
4038
+ }),
4039
+ /*
4040
+ * URL 粘贴是 BridgeRTE 的高意图快捷路径,必须先于 Lexical 默认 paste 监听注册。
4041
+ * 否则 Lexical 会先把 URL 当普通文本插入,后续就失去“选区变链接”的语义。
4042
+ */
4043
+ yl({
4044
+ target: r,
4045
+ isReadonly: a,
4046
+ executeCommand: s
4047
+ }),
4048
+ /*
4049
+ * HTML 清洗放在媒体和纯文本 URL 之后、Lexical 默认 rich text paste 之前。
4050
+ * 这样外部网页/办公软件片段会先进入 BridgeRTE 白名单清洗,再转成 Lexical 节点。
4051
+ */
4052
+ wl({
4053
+ target: r,
4054
+ editor: t,
4055
+ isReadonly: a
4056
+ }),
4057
+ Qs({
4058
+ target: r,
4059
+ isReadonly: a
4060
+ }),
4061
+ lr(t),
4062
+ /*
4063
+ * 代码块高亮使用 Lexical 官方 Prism 管线。CodeNode 只保存语言和文本,真正的 token
4064
+ * 拆分、Tab/缩进处理和 data-highlight-language 都由这里注册;无语言时保持纯文本。
4065
+ */
4066
+ gr(t, jl),
4067
+ Wr(t, o, ua),
4068
+ Cr(t),
4069
+ _r(t),
4070
+ Vl({
4071
+ contentElement: r,
4072
+ editor: t,
4073
+ isReadonly: a
4074
+ }),
4075
+ S ? Bi({
4076
+ editorRoot: n,
4077
+ contentElement: r,
4078
+ editor: t,
4079
+ isReadonly: a,
4080
+ executeCommand: s,
4081
+ mentionProvider: e.mentionProvider,
4082
+ mentionMenuConfig: e.mentionMenuConfig,
4083
+ onMentionMenuRequest: e.onMentionMenuRequest
4084
+ }) : () => {
4085
+ },
4086
+ w ? si({
4087
+ editorRoot: n,
4088
+ contentElement: r,
4089
+ editor: t,
4090
+ isReadonly: a,
4091
+ executeCommand: s,
4092
+ requestPayloadPanel: i,
4093
+ getCommandStates: _,
4094
+ menuSchema: e.menuSchema,
4095
+ hoverbarConfig: e.hoverbarConfig,
4096
+ icons: e.icons,
4097
+ menuLabels: e.menuLabels,
4098
+ payloadPanelConfig: e.payloadPanelConfig
4099
+ }) : () => {
4100
+ },
4101
+ Rr(t),
4102
+ Ks({ editor: t }),
4103
+ p ? Wl({
4104
+ editorRoot: n,
4105
+ contentElement: r,
4106
+ editor: t,
4107
+ isReadonly: a,
4108
+ executeCommand: s,
4109
+ requestPayloadPanel: i,
4110
+ menuSchema: e.menuSchema,
4111
+ slashCommandConfig: e.slashCommandConfig,
4112
+ icons: e.icons,
4113
+ menuLabels: e.menuLabels,
4114
+ payloadPanelConfig: e.payloadPanelConfig,
4115
+ slashCommandMenuConfig: e.slashCommandMenuConfig,
4116
+ onSlashCommandMenuRequest: e.onSlashCommandMenuRequest,
4117
+ slashCommandProvider: e.slashCommandProvider
4118
+ }) : () => {
4119
+ },
4120
+ vo({
4121
+ editor: t,
4122
+ contentElement: r,
4123
+ isReadonly: a
4124
+ }),
4125
+ v ? mi({
4126
+ target: r,
4127
+ isReadonly: a,
4128
+ executeCommand: s
4129
+ }) : () => {
4130
+ },
4131
+ t.registerUpdateListener(() => {
4132
+ m(), C();
4133
+ }),
4134
+ t.registerCommand(
4135
+ Xt,
4136
+ () => (C(), !1),
4137
+ V
4138
+ ),
4139
+ t.registerCommand(
4140
+ er,
4141
+ (E) => (x(E), !1),
4142
+ V
4143
+ ),
4144
+ t.registerCommand(
4145
+ tr,
4146
+ (E) => (h(E), !1),
4147
+ V
4148
+ )
4149
+ );
4150
+ return {
4151
+ destroy() {
4152
+ T();
4153
+ }
4154
+ };
4155
+ };
4156
+ function Kl(e, t = {}) {
4157
+ const n = Ur(), r = t.toolbarMode ?? "top", o = t.mediaDefaultWidthPercent ?? 50, a = r === "top" || r === "bottom", s = r === "bottom" ? "bottom" : "top", {
4158
+ toolbarElement: i,
4159
+ contentElement: c
4160
+ } = Ws(e, {
4161
+ placeholder: t.placeholder ?? fo,
4162
+ shouldRenderToolbar: a,
4163
+ toolbarPlacement: s
4164
+ }), l = t.keyboardShortcuts === !0;
4165
+ let m = t.readonly ?? !1, C = !1, _ = null, x = He(t.value);
4166
+ const h = nr({
4167
+ namespace: ma,
4168
+ editable: !m,
4169
+ nodes: [
4170
+ cr,
4171
+ dr,
4172
+ Qt,
4173
+ hr,
4174
+ Zt,
4175
+ Er,
4176
+ De,
4177
+ Ar,
4178
+ Br,
4179
+ Fr,
4180
+ zr,
4181
+ de,
4182
+ re,
4183
+ me
4184
+ ],
4185
+ theme: Yo,
4186
+ onError: (L) => {
4187
+ j(t, "lexical.runtime", "Lexical runtime error.", L);
4188
+ }
4189
+ });
4190
+ Dr(h, !0);
4191
+ const v = () => C, S = () => m, p = () => {
4192
+ v() || yo({ editor: h, contentElement: c });
4193
+ }, w = Us({ editor: h }), T = ga({
4194
+ lexicalEditor: h,
4195
+ options: t,
4196
+ isDestroyed: v,
4197
+ setContent: (L) => {
4198
+ x = L;
4199
+ },
4200
+ syncPlaceholder: p
4201
+ }), E = Vo({
4202
+ lexicalEditor: h,
4203
+ options: t,
4204
+ isDestroyed: v,
4205
+ canUploadMedia: () => t.uploadAdapter !== void 0,
4206
+ isReadonly: S
4207
+ }), P = da({
4208
+ container: e,
4209
+ lexicalEditor: h,
4210
+ options: t,
4211
+ isDestroyed: v,
4212
+ isReadonly: S,
4213
+ reportError: j
4214
+ }), I = () => {
4215
+ c.contentEditable = String(!m), h.setEditable(!m);
4216
+ }, b = zs({
4217
+ editorRoot: e,
4218
+ lexicalEditor: h,
4219
+ isReadonly: S,
4220
+ restoreEditorFocus: (L) => {
4221
+ w.restore(), h.focus(L);
4222
+ },
4223
+ executeCommand: P,
4224
+ getClearCommand: (L) => {
4225
+ switch (L.command.type) {
4226
+ case "format.color":
4227
+ case "format.backgroundColor":
4228
+ case "format.fontSize":
4229
+ case "format.fontFamily":
4230
+ case "format.lineHeight":
4231
+ return { ...L.command, value: "" };
4232
+ default:
4233
+ return null;
4234
+ }
4235
+ },
4236
+ codeBlockLanguagePanel: t.codeBlockLanguagePanel,
4237
+ payloadPanelConfig: t.payloadPanelConfig,
4238
+ mediaControlsConfig: t.mediaControlsConfig,
4239
+ menuLabels: t.menuLabels,
4240
+ onRequest: t.onPayloadPanelRequest,
4241
+ defaultMediaWidthPercent: o
4242
+ }), g = () => zo(t), d = () => Wo(t), y = (L) => {
4243
+ v() || (w.capture(), b.payloadPanelController.open(L));
4244
+ };
4245
+ e.dataset.readonly = String(m), e.addEventListener("focusin", g), e.addEventListener("focusout", d), e.style.setProperty(
4246
+ "--bridgerte-media-display-width",
4247
+ `${o}%`
4248
+ );
4249
+ const u = ql({
4250
+ options: t,
4251
+ lexicalEditor: h,
4252
+ editorRoot: e,
4253
+ contentElement: c,
4254
+ historyState: n,
4255
+ isReadonly: S,
4256
+ executeCommand: P,
4257
+ requestPayloadPanel: y,
4258
+ uploadMediaFile: P.uploadMediaFile,
4259
+ canUploadMedia: () => t.uploadAdapter !== void 0,
4260
+ syncAfterEditorUpdate: T.syncAfterEditorUpdate,
4261
+ refreshCommandStates: E.refreshCommandStates,
4262
+ getCommandStates: E.getCommandStates,
4263
+ setCanUndo: E.setCanUndo,
4264
+ setCanRedo: E.setCanRedo,
4265
+ enableKeyboardShortcuts: l
4266
+ });
4267
+ h.setRootElement(c), T.suppressNextChange(), x = mo(h, t.value), I();
4268
+ const f = {
4269
+ getContent() {
4270
+ return v() || (T.clearContentChangeTimer(), T.syncContent(!1)), x;
4271
+ },
4272
+ setContent(L) {
4273
+ v() || (T.clearContentChangeTimer(), x = He(L), T.suppressNextChange(), sn(h, x), T.enforceCurrentMaxLength(), p(), h.dispatchCommand(rr, void 0), E.setHistoryAvailability(!1, !1), T.syncContent(!0));
4274
+ },
4275
+ executeCommand(L) {
4276
+ P(L);
4277
+ },
4278
+ requestPayloadPanel: y,
4279
+ getCommandStates: E.getCommandStates,
4280
+ subscribeCommandStateChange: E.subscribeCommandStateChange,
4281
+ setReadonly(L) {
4282
+ v() || (m = L, e.dataset.readonly = String(m), I(), E.refreshCommandStates());
4283
+ },
4284
+ focus() {
4285
+ v() || h.focus();
4286
+ },
4287
+ blur() {
4288
+ v() || c.blur();
4289
+ },
4290
+ destroy() {
4291
+ v() || (C = !0, T.clearContentChangeTimer(), _ == null || _.destroy(), _ = null, b.destroy(), P.destroy(), E.destroy(), w.clear(), u.destroy(), h.setRootElement(null), e.removeEventListener("focusin", g), e.removeEventListener("focusout", d), e.classList.remove("bridgerte"), e.textContent = "", delete e.dataset.readonly);
4292
+ }
4293
+ };
4294
+ return T.syncContent(!1), p(), E.refreshCommandStates(), a && (_ = Mo(i, {
4295
+ editor: f,
4296
+ menuSchema: t.menuSchema,
4297
+ placement: s,
4298
+ toolbarConfig: t.toolbarConfig,
4299
+ icons: t.icons,
4300
+ menuLabels: t.menuLabels,
4301
+ payloadPanelConfig: t.payloadPanelConfig
4302
+ })), Uo(t, f), f;
4303
+ }
4304
+ const Gl = (e) => !Dn(e) || !("id" in e) ? !1 : e.type === "editor.init" || e.type === "editor.executeCommand" || e.type === "editor.setContent" || e.type === "editor.setReadonly" || e.type === "editor.requestContent" || e.type === "editor.payloadPanelResolved" || e.type === "editor.payloadPanelCanceled" || e.type === "editor.uploadResolved" || e.type === "editor.uploadRejected", Xl = (e) => ({
4305
+ id: e,
4306
+ type: "editor.ready",
4307
+ payload: {
4308
+ menuSchema: ue,
4309
+ eventTiming: Hn,
4310
+ version: _e
4311
+ }
4312
+ }), Jl = (e) => `native-upload:${e}:${Date.now()}:${Math.random().toString(36).slice(2)}`, gc = ({
4313
+ container: e,
4314
+ transport: t
4315
+ }) => {
4316
+ var k;
4317
+ let n = null, r = !1, o = null, a = null, s = null, i = 0;
4318
+ const c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), m = (b) => {
4319
+ r || t.postMessage(b);
4320
+ }, C = () => {
4321
+ s && (clearTimeout(s), s = null);
4322
+ }, _ = () => {
4323
+ C(), s = setTimeout(() => {
4324
+ if (r) return;
4325
+ const b = Math.ceil(e.getBoundingClientRect().height);
4326
+ b !== i && (i = b, m({
4327
+ type: "editor.heightChange",
4328
+ payload: { height: b }
4329
+ }));
4330
+ }, On);
4331
+ }, x = (b) => {
4332
+ if (!n) return;
4333
+ const g = n.getContent();
4334
+ m({
4335
+ id: b,
4336
+ type: "editor.content",
4337
+ payload: g
4338
+ }), m({
4339
+ id: b,
4340
+ type: "editor.contentChange",
4341
+ payload: g
4342
+ });
4343
+ }, h = (b) => {
4344
+ const g = b.payload, d = c.get(g.assetId);
4345
+ if (d) {
4346
+ if (c.delete(g.assetId), d.source === "uploadAdapter") {
4347
+ d.resolve(g.result);
4348
+ return;
4349
+ }
4350
+ n == null || n.executeCommand({
4351
+ type: d.type === "image" ? "media.insertImage" : "media.insertVideo",
4352
+ url: g.result.url,
4353
+ poster: g.result.poster,
4354
+ width: g.result.width,
4355
+ height: g.result.height,
4356
+ displayWidthPercent: 50,
4357
+ assetId: g.assetId
4358
+ });
4359
+ }
4360
+ }, v = (b) => {
4361
+ const g = b.payload, d = c.get(g.assetId);
4362
+ if (d) {
4363
+ if (c.delete(g.assetId), d.source === "uploadAdapter") {
4364
+ d.reject(new Error(g.message));
4365
+ return;
4366
+ }
4367
+ m({
4368
+ id: b.id,
4369
+ type: "editor.error",
4370
+ payload: {
4371
+ code: "bridge.uploadRejected",
4372
+ message: g.message
4373
+ }
4374
+ });
4375
+ }
4376
+ }, S = (b, g) => new Promise((d, y) => {
4377
+ c.set(g, {
4378
+ type: b,
4379
+ assetId: g,
4380
+ source: "uploadAdapter",
4381
+ resolve: d,
4382
+ reject: y
4383
+ }), m({
4384
+ type: "editor.uploadRequest",
4385
+ payload: {
4386
+ assetId: g,
4387
+ type: b,
4388
+ accept: b === "image" ? "image/*" : "video/*"
4389
+ }
4390
+ });
4391
+ }), p = (b) => {
4392
+ const g = Jl(b);
4393
+ c.set(g, {
4394
+ type: b,
4395
+ assetId: g,
4396
+ source: "nativePicker"
4397
+ }), m({
4398
+ type: "editor.uploadRequest",
4399
+ payload: {
4400
+ assetId: g,
4401
+ type: b,
4402
+ accept: b === "image" ? "image/*" : "video/*"
4403
+ }
4404
+ });
4405
+ }, w = (b) => {
4406
+ const g = l.get(b.payload.requestId);
4407
+ g && (l.delete(b.payload.requestId), g.request.submit(b.payload.values));
4408
+ }, T = (b) => {
4409
+ const g = l.get(b.payload.requestId);
4410
+ g && (l.delete(b.payload.requestId), g.request.cancel());
4411
+ }, E = (b, g) => {
4412
+ n == null || n.destroy(), o == null || o(), c.clear(), l.clear(), n = Kl(e, {
4413
+ ...g,
4414
+ toolbarMode: "native",
4415
+ platform: "webview",
4416
+ uploadAdapter: {
4417
+ uploadImage(d, y) {
4418
+ return S("image", y.assetId);
4419
+ },
4420
+ uploadVideo(d, y) {
4421
+ return S("video", y.assetId);
4422
+ }
4423
+ },
4424
+ onContentChange: (d) => {
4425
+ m({
4426
+ type: "editor.contentChange",
4427
+ payload: d
4428
+ }), _();
4429
+ },
4430
+ onCommandStateChange: (d) => {
4431
+ m({
4432
+ type: "editor.commandStateChange",
4433
+ payload: d
4434
+ });
4435
+ },
4436
+ onPayloadPanelRequest: (d) => (l.set(d.id, { request: d }), m({
4437
+ type: "editor.payloadPanelRequest",
4438
+ payload: {
4439
+ menuId: d.menuId,
4440
+ command: d.command,
4441
+ panel: d.panel,
4442
+ anchorRect: d.anchorRect,
4443
+ currentValues: d.currentValues,
4444
+ id: d.id,
4445
+ readonly: d.readonly
4446
+ }
4447
+ }), !0),
4448
+ onError: (d) => {
4449
+ m({
4450
+ type: "editor.error",
4451
+ payload: d
4452
+ });
4453
+ }
4454
+ }), o = n.subscribeCommandStateChange((d) => {
4455
+ m({
4456
+ type: "editor.commandStateChange",
4457
+ payload: d
4458
+ });
4459
+ }), m(Xl(b)), _();
4460
+ }, P = (b) => {
4461
+ if (b.type === "media.pickImage") {
4462
+ p("image");
4463
+ return;
4464
+ }
4465
+ if (b.type === "media.pickVideo") {
4466
+ p("video");
4467
+ return;
4468
+ }
4469
+ n == null || n.executeCommand(b);
4470
+ }, I = (b) => {
4471
+ if (!(r || !Gl(b)))
4472
+ switch (b.type) {
4473
+ case "editor.init":
4474
+ E(b.id, b.payload);
4475
+ return;
4476
+ case "editor.executeCommand":
4477
+ P(b.payload);
4478
+ return;
4479
+ case "editor.setContent":
4480
+ n == null || n.setContent(b.payload);
4481
+ return;
4482
+ case "editor.setReadonly":
4483
+ n == null || n.setReadonly(b.payload.readonly);
4484
+ return;
4485
+ case "editor.requestContent":
4486
+ x(b.id);
4487
+ return;
4488
+ case "editor.payloadPanelResolved":
4489
+ w(b);
4490
+ return;
4491
+ case "editor.payloadPanelCanceled":
4492
+ T(b);
4493
+ return;
4494
+ case "editor.uploadResolved":
4495
+ h(b);
4496
+ return;
4497
+ case "editor.uploadRejected":
4498
+ v(b);
4499
+ return;
4500
+ }
4501
+ };
4502
+ return a = ((k = t.addMessageListener) == null ? void 0 : k.call(t, I)) ?? null, {
4503
+ receive: I,
4504
+ destroy() {
4505
+ r || (r = !0, C(), a == null || a(), o == null || o(), c.clear(), l.clear(), n == null || n.destroy(), n = null);
4506
+ }
4507
+ };
4508
+ };
4509
+ export {
4510
+ Kl as a,
4511
+ Mo as b,
4512
+ kn as c,
4513
+ gc as d
4514
+ };
4515
+ //# sourceMappingURL=index-C7IVE5Bd.js.map