@editora/plugins 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -0
  3. package/dist/approval-workflow.cjs.js +447 -0
  4. package/dist/approval-workflow.esm.js +1070 -0
  5. package/dist/blocks-library.cjs.js +442 -0
  6. package/dist/blocks-library.esm.js +1317 -0
  7. package/dist/citations.cjs.js +548 -0
  8. package/dist/citations.esm.js +1457 -0
  9. package/dist/conditional-content.cjs.js +626 -0
  10. package/dist/conditional-content.esm.js +1360 -0
  11. package/dist/content-rules.cjs.js +408 -0
  12. package/dist/content-rules.esm.js +1093 -0
  13. package/dist/data-binding.cjs.js +321 -0
  14. package/dist/data-binding.esm.js +913 -0
  15. package/dist/doc-schema.cjs.js +398 -0
  16. package/dist/doc-schema.esm.js +1310 -0
  17. package/dist/enterprise.cjs.js +1 -0
  18. package/dist/enterprise.esm.js +56 -0
  19. package/dist/index.cjs.js +1 -1
  20. package/dist/index.esm.js +109 -81
  21. package/dist/mentions.cjs.js +105 -0
  22. package/dist/mentions.esm.js +726 -0
  23. package/dist/page-break.cjs.js +2 -2
  24. package/dist/page-break.esm.js +32 -32
  25. package/dist/pii-redaction.cjs.js +436 -0
  26. package/dist/pii-redaction.esm.js +1377 -0
  27. package/dist/preview.cjs.js +3 -3
  28. package/dist/preview.esm.js +29 -29
  29. package/dist/slash-commands.cjs.js +90 -0
  30. package/dist/slash-commands.esm.js +752 -0
  31. package/dist/smart-paste.cjs.js +398 -0
  32. package/dist/smart-paste.esm.js +1388 -0
  33. package/dist/track-changes.cjs.js +77 -0
  34. package/dist/track-changes.esm.js +755 -0
  35. package/dist/translation-workflow.cjs.js +626 -0
  36. package/dist/translation-workflow.esm.js +1718 -0
  37. package/dist/version-diff.cjs.js +362 -0
  38. package/dist/version-diff.esm.js +768 -0
  39. package/index.d.ts +798 -0
  40. package/package.json +104 -5
@@ -0,0 +1,913 @@
1
+ const A = ".rte-content, .editora-content", C = '.rte-data-binding[data-binding="true"]', it = "rte-data-binding-styles", g = "rte-data-binding-dialog-overlay", f = ':is([data-theme="dark"], .dark, .editora-theme-dark, .rte-theme-dark)', pt = {
2
+ dialogTitleInsert: "Insert Data Binding",
3
+ dialogTitleEdit: "Edit Data Binding",
4
+ keyLabel: "Data Key",
5
+ keyPlaceholder: "user.firstName",
6
+ fallbackLabel: "Fallback Text",
7
+ fallbackPlaceholder: "Guest",
8
+ formatLabel: "Format",
9
+ currencyLabel: "Currency",
10
+ currencyPlaceholder: "USD",
11
+ saveText: "Save",
12
+ cancelText: "Cancel",
13
+ previewOnText: "Preview On",
14
+ previewOffText: "Preview Off",
15
+ tokenAriaPrefix: "Data binding token"
16
+ }, x = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new WeakMap(), G = /* @__PURE__ */ new WeakMap();
17
+ let R = null, h = null, U = 0, P = null, O = null, M = null, z = null;
18
+ function yt(t) {
19
+ return {
20
+ ...pt,
21
+ ...t || {}
22
+ };
23
+ }
24
+ function ot(t = {}) {
25
+ const n = (t.locale || (typeof navigator < "u" ? navigator.language : "en-US")).trim() || "en-US";
26
+ return {
27
+ data: t.data,
28
+ getData: t.getData,
29
+ api: t.api,
30
+ cacheTtlMs: Math.max(0, Number(t.cacheTtlMs ?? 3e4)),
31
+ labels: yt(t.labels),
32
+ defaultFormat: t.defaultFormat || "text",
33
+ defaultFallback: t.defaultFallback || "",
34
+ locale: n,
35
+ numberFormatOptions: t.numberFormatOptions || {},
36
+ dateFormatOptions: t.dateFormatOptions || { year: "numeric", month: "short", day: "2-digit" }
37
+ };
38
+ }
39
+ function y(t) {
40
+ return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
41
+ }
42
+ function dt(t) {
43
+ return t ? t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement : null;
44
+ }
45
+ function j(t) {
46
+ return t.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || t;
47
+ }
48
+ function q(t) {
49
+ return t ? (t.getAttribute("data-theme") || t.getAttribute("theme") || "").toLowerCase() === "dark" ? !0 : t.classList.contains("dark") || t.classList.contains("editora-theme-dark") || t.classList.contains("rte-theme-dark") : !1;
50
+ }
51
+ function ht(t) {
52
+ const n = j(t);
53
+ if (q(n)) return !0;
54
+ const a = n.closest("[data-theme], [theme], .dark, .editora-theme-dark, .rte-theme-dark");
55
+ return q(a) ? !0 : q(document.documentElement) || q(document.body);
56
+ }
57
+ function D(t, n = !0) {
58
+ if (t?.contentElement instanceof HTMLElement) return t.contentElement;
59
+ if (t?.editorElement instanceof HTMLElement) {
60
+ const e = t.editorElement;
61
+ if (e.matches(A)) return e;
62
+ const i = e.querySelector(A);
63
+ if (i instanceof HTMLElement) return i;
64
+ }
65
+ const a = window.getSelection();
66
+ if (a && a.rangeCount > 0) {
67
+ const e = a.getRangeAt(0).startContainer, o = dt(e)?.closest(A);
68
+ if (o) return o;
69
+ }
70
+ const r = document.activeElement;
71
+ if (r) {
72
+ if (r.matches(A)) return r;
73
+ const e = r.closest(A);
74
+ if (e) return e;
75
+ }
76
+ return h && h.isConnected ? h : n ? document.querySelector(A) : null;
77
+ }
78
+ function K(t) {
79
+ return t.getAttribute("contenteditable") === "false" || t.getAttribute("data-readonly") === "true";
80
+ }
81
+ function lt(t) {
82
+ const n = window.getSelection();
83
+ if (!n || n.rangeCount === 0) return null;
84
+ const a = n.getRangeAt(0);
85
+ return t.contains(a.commonAncestorContainer) ? a.cloneRange() : null;
86
+ }
87
+ function st(t, n) {
88
+ const a = window.getSelection();
89
+ a && (a.removeAllRanges(), a.addRange(n), t.focus({ preventScroll: !0 }));
90
+ }
91
+ function kt(t, n) {
92
+ const a = (n || "").trim();
93
+ if (a)
94
+ return a.split(".").filter(Boolean).reduce((r, e) => {
95
+ if (!(r == null || typeof r != "object"))
96
+ return r[e];
97
+ }, t);
98
+ }
99
+ function xt() {
100
+ if (typeof document > "u" || document.getElementById(it)) return;
101
+ const t = document.createElement("style");
102
+ t.id = it, t.textContent = `
103
+ .rte-data-binding {
104
+ display: inline-flex;
105
+ align-items: center;
106
+ max-width: 100%;
107
+ gap: 5px;
108
+ padding: 2px 8px 2px 7px;
109
+ border-radius: 999px;
110
+ border: 1px dashed #8b5cf6;
111
+ background: linear-gradient(180deg, #f9f7ff 0%, #f1edff 100%);
112
+ color: #4c1d95;
113
+ font-size: 0.88em;
114
+ font-weight: 600;
115
+ line-height: 1.3;
116
+ vertical-align: baseline;
117
+ white-space: nowrap;
118
+ overflow: hidden;
119
+ text-overflow: ellipsis;
120
+ user-select: all;
121
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
122
+ cursor: pointer;
123
+ }
124
+
125
+ .rte-data-binding::before {
126
+ content: '{}';
127
+ display: inline-flex;
128
+ align-items: center;
129
+ justify-content: center;
130
+ min-width: 14px;
131
+ height: 14px;
132
+ border-radius: 999px;
133
+ background: rgba(139, 92, 246, 0.16);
134
+ color: #5b21b6;
135
+ font-size: 10px;
136
+ font-weight: 700;
137
+ line-height: 1;
138
+ letter-spacing: -0.2px;
139
+ flex: 0 0 auto;
140
+ }
141
+
142
+ .rte-data-binding.rte-data-binding-preview {
143
+ border-style: solid;
144
+ background: #ecfdf5;
145
+ border-color: #34d399;
146
+ color: #065f46;
147
+ user-select: text;
148
+ }
149
+
150
+ .rte-data-binding.rte-data-binding-preview::before {
151
+ content: '=';
152
+ background: rgba(16, 185, 129, 0.15);
153
+ color: #047857;
154
+ letter-spacing: 0;
155
+ }
156
+
157
+ .rte-data-binding.rte-data-binding-missing {
158
+ border-style: dashed;
159
+ border-color: #f87171;
160
+ background: #fef2f2;
161
+ color: #991b1b;
162
+ }
163
+
164
+ .rte-data-binding-dialog-overlay {
165
+ position: fixed;
166
+ inset: 0;
167
+ z-index: 2147483646;
168
+ background: rgba(15, 23, 42, 0.54);
169
+ display: flex;
170
+ align-items: center;
171
+ justify-content: center;
172
+ padding: 20px;
173
+ }
174
+
175
+ .rte-data-binding-dialog {
176
+ width: min(560px, 96vw);
177
+ max-height: min(86vh, 720px);
178
+ border: 1px solid #dbe3ec;
179
+ border-radius: 8px;
180
+ background: #ffffff;
181
+ box-shadow: 0 24px 50px rgba(15, 23, 42, 0.26);
182
+ display: flex;
183
+ flex-direction: column;
184
+ overflow: hidden;
185
+ }
186
+
187
+ .rte-data-binding-header,
188
+ .rte-data-binding-footer {
189
+ display: flex;
190
+ align-items: center;
191
+ justify-content: space-between;
192
+ gap: 10px;
193
+ padding: 12px 14px;
194
+ background: #f8fafc;
195
+ border-bottom: 1px solid #e2e8f0;
196
+ }
197
+
198
+ .rte-data-binding-footer {
199
+ justify-content: flex-end;
200
+ border-bottom: 0;
201
+ border-top: 1px solid #e2e8f0;
202
+ }
203
+
204
+ .rte-data-binding-title {
205
+ margin: 0;
206
+ font-size: 16px;
207
+ font-weight: 700;
208
+ color: #0f172a;
209
+ }
210
+
211
+ .rte-data-binding-body {
212
+ padding: 14px;
213
+ overflow: auto;
214
+ display: grid;
215
+ gap: 12px;
216
+ grid-template-columns: 1fr;
217
+ }
218
+
219
+ .rte-data-binding-field {
220
+ display: grid;
221
+ gap: 6px;
222
+ }
223
+
224
+ .rte-data-binding-field label {
225
+ font-size: 12px;
226
+ font-weight: 600;
227
+ color: #334155;
228
+ }
229
+
230
+ .rte-data-binding-field input,
231
+ .rte-data-binding-field select {
232
+ width: 100%;
233
+ min-height: 36px;
234
+ border: 1px solid #cbd5e1;
235
+ border-radius: 6px;
236
+ padding: 8px 10px;
237
+ font-size: 13px;
238
+ line-height: 1.4;
239
+ color: #0f172a;
240
+ background: #ffffff;
241
+ box-sizing: border-box;
242
+ }
243
+
244
+ .rte-data-binding-help {
245
+ margin: 0;
246
+ font-size: 12px;
247
+ color: #64748b;
248
+ }
249
+
250
+ .rte-data-binding-btn {
251
+ border: 1px solid #cbd5e1;
252
+ border-radius: 6px;
253
+ min-height: 34px;
254
+ padding: 6px 12px;
255
+ background: #ffffff;
256
+ color: #0f172a;
257
+ font-size: 13px;
258
+ cursor: pointer;
259
+ }
260
+
261
+ .rte-data-binding-btn-primary {
262
+ background: #2563eb;
263
+ border-color: #2563eb;
264
+ color: #ffffff;
265
+ }
266
+
267
+ .rte-data-binding-btn-primary:hover {
268
+ background: #1d4ed8;
269
+ }
270
+
271
+ .rte-toolbar-group-items.data-binding,
272
+ .editora-toolbar-group-items.data-binding {
273
+ display: flex;
274
+ border: 1px solid #cbd5e1;
275
+ border-radius: 6px;
276
+ overflow: hidden;
277
+ background: #ffffff;
278
+ }
279
+
280
+ .rte-toolbar-group-items.data-binding .rte-toolbar-item,
281
+ .editora-toolbar-group-items.data-binding .editora-toolbar-item {
282
+ display: flex;
283
+ }
284
+
285
+ .rte-toolbar-group-items.data-binding .rte-toolbar-button,
286
+ .editora-toolbar-group-items.data-binding .editora-toolbar-button {
287
+ border: 0;
288
+ border-radius: 0;
289
+ border-right: 1px solid #cbd5e1;
290
+ }
291
+
292
+ .rte-toolbar-group-items.data-binding .rte-toolbar-item:last-child .rte-toolbar-button,
293
+ .editora-toolbar-group-items.data-binding .editora-toolbar-item:last-child .editora-toolbar-button {
294
+ border-right: 0;
295
+ }
296
+
297
+ .rte-data-binding-btn:focus-visible,
298
+ .rte-data-binding-field input:focus-visible,
299
+ .rte-data-binding-field select:focus-visible {
300
+ outline: none;
301
+ border-color: #3b82f6;
302
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
303
+ }
304
+
305
+ ${f} .rte-data-binding,
306
+ .${g}.rte-data-binding-theme-dark .rte-data-binding {
307
+ background: linear-gradient(180deg, #3b0764 0%, #2e1065 100%);
308
+ border-color: #a78bfa;
309
+ color: #ede9fe;
310
+ }
311
+
312
+ ${f} .rte-data-binding::before,
313
+ .${g}.rte-data-binding-theme-dark .rte-data-binding::before {
314
+ background: rgba(167, 139, 250, 0.22);
315
+ color: #ddd6fe;
316
+ }
317
+
318
+ ${f} .rte-data-binding.rte-data-binding-preview,
319
+ .${g}.rte-data-binding-theme-dark .rte-data-binding.rte-data-binding-preview {
320
+ background: #064e3b;
321
+ border-color: #10b981;
322
+ color: #d1fae5;
323
+ }
324
+
325
+ ${f} .rte-data-binding.rte-data-binding-missing,
326
+ .${g}.rte-data-binding-theme-dark .rte-data-binding.rte-data-binding-missing {
327
+ background: #7f1d1d;
328
+ border-color: #ef4444;
329
+ color: #fee2e2;
330
+ }
331
+
332
+ ${f} .rte-toolbar-group-items.data-binding,
333
+ ${f} .editora-toolbar-group-items.data-binding {
334
+ display: flex;
335
+ border: 1px solid #566275;
336
+ border-radius: 6px;
337
+ overflow: hidden;
338
+ }
339
+
340
+ ${f} .rte-toolbar-group-items.data-binding .rte-toolbar-button,
341
+ ${f} .editora-toolbar-group-items.data-binding .editora-toolbar-button {
342
+ border-right-color: #566275;
343
+ }
344
+
345
+ ${f} .rte-data-binding-dialog,
346
+ .${g}.rte-data-binding-theme-dark .rte-data-binding-dialog {
347
+ background: #1f2937;
348
+ border-color: #334155;
349
+ }
350
+
351
+ ${f} .rte-data-binding-header,
352
+ ${f} .rte-data-binding-footer,
353
+ .${g}.rte-data-binding-theme-dark .rte-data-binding-header,
354
+ .${g}.rte-data-binding-theme-dark .rte-data-binding-footer {
355
+ background: #111827;
356
+ border-color: #334155;
357
+ }
358
+
359
+ ${f} .rte-data-binding-title,
360
+ ${f} .rte-data-binding-field label,
361
+ .${g}.rte-data-binding-theme-dark .rte-data-binding-title,
362
+ .${g}.rte-data-binding-theme-dark .rte-data-binding-field label {
363
+ color: #e2e8f0;
364
+ }
365
+
366
+ ${f} .rte-data-binding-help,
367
+ .${g}.rte-data-binding-theme-dark .rte-data-binding-help {
368
+ color: #94a3b8;
369
+ }
370
+
371
+ ${f} .rte-data-binding-field input,
372
+ ${f} .rte-data-binding-field select,
373
+ ${f} .rte-data-binding-btn,
374
+ .${g}.rte-data-binding-theme-dark .rte-data-binding-field input,
375
+ .${g}.rte-data-binding-theme-dark .rte-data-binding-field select,
376
+ .${g}.rte-data-binding-theme-dark .rte-data-binding-btn {
377
+ background: #0f172a;
378
+ border-color: #475569;
379
+ color: #e2e8f0;
380
+ }
381
+
382
+ ${f} .rte-data-binding-btn-primary,
383
+ .${g}.rte-data-binding-theme-dark .rte-data-binding-btn-primary {
384
+ background: #2563eb;
385
+ border-color: #2563eb;
386
+ color: #ffffff;
387
+ }
388
+ `, document.head.appendChild(t);
389
+ }
390
+ function J(t) {
391
+ t.dispatchEvent(new Event("input", { bubbles: !0 }));
392
+ }
393
+ function Y(t, n) {
394
+ if (n === t.innerHTML) return;
395
+ const a = window.execEditorCommand || window.executeEditorCommand;
396
+ if (typeof a == "function")
397
+ try {
398
+ a("recordDomTransaction", t, n, t.innerHTML);
399
+ } catch {
400
+ }
401
+ }
402
+ function H(t, n) {
403
+ return {
404
+ key: String(t.key || "").trim(),
405
+ fallback: String(t.fallback ?? n.defaultFallback ?? ""),
406
+ format: t.format || n.defaultFormat || "text",
407
+ currency: String(t.currency || "USD").trim().toUpperCase() || "USD"
408
+ };
409
+ }
410
+ function ct(t) {
411
+ return `{{${t.key}}}`;
412
+ }
413
+ function ut(t, n) {
414
+ const a = document.createElement("span");
415
+ return a.className = "rte-data-binding", a.setAttribute("data-binding", "true"), a.setAttribute("data-binding-key", t.key), a.setAttribute("data-binding-fallback", t.fallback || ""), a.setAttribute("data-binding-format", t.format || "text"), a.setAttribute("data-binding-currency", t.currency || "USD"), a.setAttribute("contenteditable", "false"), a.setAttribute("spellcheck", "false"), a.setAttribute("draggable", "false"), a.setAttribute("tabindex", "0"), a.setAttribute("role", "button"), a.setAttribute("aria-label", `${n.tokenAriaPrefix}: ${t.key}. Press Enter to edit.`), a.textContent = ct(t), a;
416
+ }
417
+ function Z(t, n) {
418
+ return H(
419
+ {
420
+ key: t.getAttribute("data-binding-key") || "",
421
+ fallback: t.getAttribute("data-binding-fallback") || n.defaultFallback,
422
+ format: t.getAttribute("data-binding-format") || n.defaultFormat,
423
+ currency: t.getAttribute("data-binding-currency") || "USD"
424
+ },
425
+ n
426
+ );
427
+ }
428
+ function X(t, n, a) {
429
+ t.classList.add("rte-data-binding"), t.setAttribute("data-binding", "true"), t.setAttribute("data-binding-key", n.key), t.setAttribute("data-binding-fallback", n.fallback || ""), t.setAttribute("data-binding-format", n.format || "text"), t.setAttribute("data-binding-currency", n.currency || "USD"), t.setAttribute("contenteditable", "false"), t.setAttribute("spellcheck", "false"), t.setAttribute("draggable", "false"), t.setAttribute("tabindex", "0"), t.setAttribute("role", "button"), t.setAttribute("aria-label", `${a.tokenAriaPrefix}: ${n.key}. Press Enter to edit.`);
430
+ }
431
+ function V(t, n) {
432
+ const a = Array.from(t.querySelectorAll(C));
433
+ return a.forEach((r) => {
434
+ const e = Z(r, n);
435
+ X(r, e, n.labels);
436
+ }), a;
437
+ }
438
+ function Q(t) {
439
+ const n = window.getSelection();
440
+ if (n && n.rangeCount > 0) {
441
+ const e = n.getRangeAt(0).startContainer, o = dt(e)?.closest(C);
442
+ if (o && t.contains(o)) return o;
443
+ }
444
+ const r = document.activeElement?.closest(C);
445
+ return r && t.contains(r) ? r : null;
446
+ }
447
+ function ft() {
448
+ R && (R.cleanup(), R = null);
449
+ }
450
+ function tt(t, n, a) {
451
+ const r = j(t);
452
+ Array.from(r.querySelectorAll('[data-command="toggleDataBindingPreview"]')).forEach((i) => {
453
+ if (i.setAttribute("data-active", n ? "true" : "false"), i.classList.toggle("active", n), i.setAttribute("aria-pressed", n ? "true" : "false"), a) {
454
+ const o = n ? a.labels.previewOnText : a.labels.previewOffText;
455
+ i.setAttribute("title", o), i.setAttribute("aria-label", o);
456
+ }
457
+ });
458
+ }
459
+ function vt(t, n, a) {
460
+ const r = n.format || "text";
461
+ if (t == null) return n.fallback || "";
462
+ if (r === "json") {
463
+ if (typeof t == "string") return t;
464
+ try {
465
+ return JSON.stringify(t);
466
+ } catch {
467
+ return String(t);
468
+ }
469
+ }
470
+ if (r === "date") {
471
+ const e = t instanceof Date ? t : new Date(String(t));
472
+ if (Number.isNaN(e.getTime())) return String(t);
473
+ try {
474
+ return new Intl.DateTimeFormat(a.locale, a.dateFormatOptions).format(e);
475
+ } catch {
476
+ return e.toISOString();
477
+ }
478
+ }
479
+ if (r === "number" || r === "currency") {
480
+ const e = typeof t == "number" ? t : Number(t);
481
+ if (!Number.isFinite(e)) return String(t);
482
+ const i = { ...a.numberFormatOptions };
483
+ if (r === "currency") {
484
+ const o = (n.currency || "USD").toUpperCase();
485
+ Object.assign(i, { style: "currency", currency: o });
486
+ }
487
+ try {
488
+ return new Intl.NumberFormat(a.locale, i).format(e);
489
+ } catch {
490
+ return String(e);
491
+ }
492
+ }
493
+ return String(t);
494
+ }
495
+ function T(t, n, a, r) {
496
+ const e = Z(t, n), i = e.key;
497
+ if (t.classList.remove("rte-data-binding-preview", "rte-data-binding-missing"), !a) {
498
+ t.textContent = ct(e), t.setAttribute("aria-label", `${n.labels.tokenAriaPrefix}: ${i}. Press Enter to edit.`);
499
+ return;
500
+ }
501
+ const o = kt(r, i), l = o == null, d = l ? e.fallback || "" : vt(o, e, n);
502
+ t.textContent = d || e.fallback || "", t.classList.add("rte-data-binding-preview"), l && !(e.fallback || "").trim() && t.classList.add("rte-data-binding-missing"), t.setAttribute("aria-label", `${n.labels.tokenAriaPrefix}: ${i} = ${t.textContent || ""}. Press Enter to edit.`);
503
+ }
504
+ function v(t) {
505
+ return typeof t == "object" && t !== null && !Array.isArray(t);
506
+ }
507
+ function wt(t, n) {
508
+ return n ? n.split(".").filter(Boolean).reduce((a, r) => {
509
+ if (!(!v(a) && !Array.isArray(a)))
510
+ return a[r];
511
+ }, t) : t;
512
+ }
513
+ function Et(t, n, a) {
514
+ const r = n.api, e = j(t), i = { editor: t, editorRoot: e, signal: a };
515
+ if (r.buildRequest) {
516
+ const p = r.buildRequest(i);
517
+ return { url: p.url, init: { ...p.init || {}, signal: a } };
518
+ }
519
+ const o = (r.method || "GET").toUpperCase(), l = typeof r.headers == "function" ? r.headers(i) : r.headers || {}, d = typeof r.params == "function" ? r.params(i) : r.params, c = new URL(r.url, window.location.origin);
520
+ d && Object.entries(d).forEach(([p, m]) => {
521
+ m != null && c.searchParams.set(p, String(m));
522
+ });
523
+ const u = {
524
+ method: o,
525
+ headers: { ...l },
526
+ credentials: r.credentials,
527
+ mode: r.mode,
528
+ cache: r.cache,
529
+ signal: a
530
+ };
531
+ if (o !== "GET" && o !== "HEAD") {
532
+ const p = typeof r.body == "function" ? r.body(i) : r.body;
533
+ if (p != null)
534
+ if (v(p)) {
535
+ u.body = JSON.stringify(p);
536
+ const m = u.headers;
537
+ !m["Content-Type"] && !m["content-type"] && (m["Content-Type"] = "application/json");
538
+ } else
539
+ u.body = p;
540
+ }
541
+ return { url: c.toString(), init: u };
542
+ }
543
+ async function Dt(t, n) {
544
+ const a = n.api;
545
+ if (!a) return {};
546
+ const r = new AbortController(), e = j(t), i = { editor: t, editorRoot: e, signal: r.signal }, o = Math.max(0, Number(a.timeoutMs ?? 1e4));
547
+ let l = null;
548
+ o > 0 && (l = window.setTimeout(() => r.abort(), o));
549
+ try {
550
+ const { url: d, init: c } = Et(t, n, r.signal), u = await fetch(d, { ...c, signal: r.signal });
551
+ if (!u.ok)
552
+ throw new Error(`Data binding API request failed: ${u.status}`);
553
+ const m = (a.responseType || "json") === "text" ? await u.text() : await u.json();
554
+ if (a.transformResponse) {
555
+ const B = a.transformResponse(m, i);
556
+ return v(B) ? B : {};
557
+ }
558
+ const $ = wt(m, a.responsePath);
559
+ return v($) ? $ : v(m) ? m : { value: $ };
560
+ } catch (d) {
561
+ return d?.name !== "AbortError" && a.onError?.(d, i), {};
562
+ } finally {
563
+ l !== null && window.clearTimeout(l);
564
+ }
565
+ }
566
+ async function I(t, n) {
567
+ const a = W.get(t);
568
+ if (a) return a;
569
+ const r = N.get(t), e = Date.now();
570
+ if (r && e - r.timestamp <= n.cacheTtlMs)
571
+ return r.data;
572
+ const i = G.get(t);
573
+ if (i) return i;
574
+ const o = (async () => {
575
+ try {
576
+ if (typeof n.getData == "function") {
577
+ const d = await Promise.resolve(n.getData({ editor: t, editorRoot: j(t) }));
578
+ if (v(d)) return d;
579
+ }
580
+ if (n.api) {
581
+ const d = await Dt(t, n);
582
+ if (v(d)) return d;
583
+ }
584
+ if (typeof n.data == "function") {
585
+ const d = await Promise.resolve(n.data());
586
+ if (v(d)) return d;
587
+ }
588
+ return v(n.data) ? n.data : {};
589
+ } finally {
590
+ G.delete(t);
591
+ }
592
+ })();
593
+ G.set(t, o);
594
+ const l = await o;
595
+ return N.set(t, { timestamp: e, data: l }), l;
596
+ }
597
+ async function _(t, n, a) {
598
+ const r = V(t, n);
599
+ if (x.set(t, a), tt(t, a, n), !a) {
600
+ r.forEach((i) => T(i, n, !1));
601
+ return;
602
+ }
603
+ const e = await I(t, n);
604
+ r.forEach((i) => T(i, n, !0, e));
605
+ }
606
+ function bt(t, n) {
607
+ let a = lt(t);
608
+ a || (a = document.createRange(), a.selectNodeContents(t), a.collapse(!1)), a.collapsed || a.deleteContents(), a.insertNode(n);
609
+ const r = document.createTextNode(" ");
610
+ n.after(r);
611
+ const e = document.createRange();
612
+ e.setStart(r, 1), e.collapse(!0), st(t, e), t.normalize();
613
+ }
614
+ function At(t) {
615
+ const n = t.metaKey || t.ctrlKey, a = t.key.toLowerCase(), r = n && t.altKey && t.shiftKey && a === "d", e = !t.metaKey && !t.ctrlKey && !t.altKey && !t.shiftKey && a === "f7";
616
+ return r || e;
617
+ }
618
+ function St(t) {
619
+ const n = t.metaKey || t.ctrlKey, a = t.key.toLowerCase(), r = n && t.altKey && t.shiftKey && a === "b", e = !t.metaKey && !t.ctrlKey && !t.altKey && !t.shiftKey && a === "f8";
620
+ return r || e;
621
+ }
622
+ function S(t, n, a, r, e) {
623
+ ft();
624
+ const i = a === "insert" ? lt(t) : null, o = n.labels, l = e ? Z(e, n) : H(r || {}, n), d = document.createElement("div");
625
+ d.className = g, ht(t) && d.classList.add("rte-data-binding-theme-dark");
626
+ const c = document.createElement("section");
627
+ c.className = "rte-data-binding-dialog", c.setAttribute("role", "dialog"), c.setAttribute("aria-modal", "true"), c.setAttribute("aria-labelledby", "rte-data-binding-dialog-title"), c.innerHTML = `
628
+ <header class="rte-data-binding-header">
629
+ <h2 id="rte-data-binding-dialog-title" class="rte-data-binding-title">${y(
630
+ a === "edit" ? o.dialogTitleEdit : o.dialogTitleInsert
631
+ )}</h2>
632
+ <button type="button" class="rte-data-binding-btn" data-action="cancel" aria-label="${y(o.cancelText)}">✕</button>
633
+ </header>
634
+ <div class="rte-data-binding-body">
635
+ <div class="rte-data-binding-field">
636
+ <label for="rte-data-binding-key">${y(o.keyLabel)}</label>
637
+ <input id="rte-data-binding-key" class="rte-data-binding-key" type="text" value="${y(l.key)}" placeholder="${y(
638
+ o.keyPlaceholder
639
+ )}" />
640
+ </div>
641
+ <div class="rte-data-binding-field">
642
+ <label for="rte-data-binding-fallback">${y(o.fallbackLabel)}</label>
643
+ <input id="rte-data-binding-fallback" class="rte-data-binding-fallback" type="text" value="${y(
644
+ l.fallback || ""
645
+ )}" placeholder="${y(o.fallbackPlaceholder)}" />
646
+ </div>
647
+ <div class="rte-data-binding-field">
648
+ <label for="rte-data-binding-format">${y(o.formatLabel)}</label>
649
+ <select id="rte-data-binding-format" class="rte-data-binding-format">
650
+ <option value="text" ${l.format === "text" ? "selected" : ""}>Text</option>
651
+ <option value="number" ${l.format === "number" ? "selected" : ""}>Number</option>
652
+ <option value="currency" ${l.format === "currency" ? "selected" : ""}>Currency</option>
653
+ <option value="date" ${l.format === "date" ? "selected" : ""}>Date</option>
654
+ <option value="json" ${l.format === "json" ? "selected" : ""}>JSON</option>
655
+ </select>
656
+ </div>
657
+ <div class="rte-data-binding-field">
658
+ <label for="rte-data-binding-currency">${y(o.currencyLabel)}</label>
659
+ <input id="rte-data-binding-currency" class="rte-data-binding-currency" type="text" maxlength="3" value="${y(
660
+ l.currency || "USD"
661
+ )}" placeholder="${y(o.currencyPlaceholder)}" />
662
+ </div>
663
+ <p class="rte-data-binding-help">Use dot paths like <code>user.name</code> or <code>order.total</code>.</p>
664
+ </div>
665
+ <footer class="rte-data-binding-footer">
666
+ <button type="button" class="rte-data-binding-btn" data-action="cancel">${y(o.cancelText)}</button>
667
+ <button type="button" class="rte-data-binding-btn rte-data-binding-btn-primary" data-action="save">${y(o.saveText)}</button>
668
+ </footer>
669
+ `, d.appendChild(c), document.body.appendChild(d);
670
+ const u = c.querySelector(".rte-data-binding-key"), p = c.querySelector(".rte-data-binding-fallback"), m = c.querySelector(".rte-data-binding-format"), $ = c.querySelector(".rte-data-binding-currency"), B = () => {
671
+ const s = m?.value === "currency", k = $?.closest(".rte-data-binding-field");
672
+ k && (k.style.display = s ? "grid" : "none");
673
+ };
674
+ B(), m?.addEventListener("change", B);
675
+ const L = () => {
676
+ d.removeEventListener("click", nt), d.removeEventListener("keydown", rt, !0), document.removeEventListener("keydown", et, !0), d.parentNode && d.parentNode.removeChild(d), R = null, t.focus({ preventScroll: !0 });
677
+ }, et = (s) => {
678
+ s.key === "Escape" && (s.preventDefault(), s.stopPropagation(), L());
679
+ }, nt = (s) => {
680
+ s.target === d && L();
681
+ }, gt = (s) => {
682
+ if (s.key !== "Tab") return;
683
+ const k = Array.from(
684
+ c.querySelectorAll('button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])')
685
+ );
686
+ if (k.length === 0) return;
687
+ const w = k[0], E = k[k.length - 1], F = document.activeElement;
688
+ if (s.shiftKey && F === w) {
689
+ s.preventDefault(), E.focus();
690
+ return;
691
+ }
692
+ !s.shiftKey && F === E && (s.preventDefault(), w.focus());
693
+ }, at = async () => {
694
+ const s = (u?.value || "").trim();
695
+ if (!s) {
696
+ u?.focus();
697
+ return;
698
+ }
699
+ const k = H(
700
+ {
701
+ key: s,
702
+ fallback: (p?.value || "").trim(),
703
+ format: m?.value || n.defaultFormat,
704
+ currency: ($?.value || "USD").trim().toUpperCase()
705
+ },
706
+ n
707
+ ), w = t.innerHTML;
708
+ if (e) {
709
+ X(e, k, o);
710
+ const E = x.get(t) === !0, F = E ? await I(t, n) : void 0;
711
+ T(e, n, E, F);
712
+ } else {
713
+ if (i)
714
+ try {
715
+ st(t, i);
716
+ } catch {
717
+ }
718
+ const E = ut(k, o);
719
+ if (bt(t, E), x.get(t) === !0) {
720
+ const mt = await I(t, n);
721
+ T(E, n, !0, mt);
722
+ }
723
+ }
724
+ J(t), Y(t, w), L();
725
+ }, rt = (s) => {
726
+ if (s.key === "Escape") {
727
+ s.preventDefault(), L();
728
+ return;
729
+ }
730
+ gt(s), s.key === "Enter" && !s.shiftKey && s.target instanceof HTMLInputElement && (s.preventDefault(), at());
731
+ };
732
+ c.addEventListener("click", (s) => {
733
+ const w = s.target?.getAttribute("data-action");
734
+ if (w) {
735
+ if (w === "cancel") {
736
+ L();
737
+ return;
738
+ }
739
+ w === "save" && at();
740
+ }
741
+ }), d.addEventListener("click", nt), d.addEventListener("keydown", rt, !0), document.addEventListener("keydown", et, !0), R = { cleanup: L }, u?.focus();
742
+ }
743
+ function Tt(t) {
744
+ z = t, O || (O = (n) => {
745
+ const r = n.target?.closest(A);
746
+ if (!r) return;
747
+ h = r, b.has(r) || b.set(r, t);
748
+ const e = b.get(r) || t;
749
+ V(r, e);
750
+ const i = x.get(r) === !0;
751
+ tt(r, i, e), i || Array.from(r.querySelectorAll(C)).forEach((l) => T(l, e, !1));
752
+ }, document.addEventListener("focusin", O, !0)), P || (P = (n) => {
753
+ if (document.querySelector(`.${g}`)) return;
754
+ const a = n.target;
755
+ if (a?.closest("input, textarea, select")) return;
756
+ const r = D(void 0, !1);
757
+ if (!r || K(r)) return;
758
+ const e = b.get(r) || z || t, i = a?.closest(C);
759
+ if (i && (n.key === "Enter" || n.key === " ")) {
760
+ n.preventDefault(), n.stopPropagation(), h = r, S(r, e, "edit", void 0, i);
761
+ return;
762
+ }
763
+ if (At(n)) {
764
+ n.preventDefault(), n.stopPropagation();
765
+ const o = Q(r);
766
+ o ? S(r, e, "edit", void 0, o) : S(r, e, "insert");
767
+ return;
768
+ }
769
+ if (St(n)) {
770
+ n.preventDefault(), n.stopPropagation();
771
+ const o = x.get(r) !== !0;
772
+ _(r, e, o);
773
+ }
774
+ }, document.addEventListener("keydown", P, !0)), M || (M = (n) => {
775
+ if (document.querySelector(`.${g}`) || n.defaultPrevented || n.button !== 0 || n.metaKey || n.ctrlKey || n.altKey || n.shiftKey) return;
776
+ const r = n.target?.closest(C);
777
+ if (!r) return;
778
+ const e = r.closest(A);
779
+ if (!e || K(e)) return;
780
+ const i = b.get(e) || z || t;
781
+ b.set(e, i), h = e, n.preventDefault(), n.stopPropagation(), r.focus({ preventScroll: !0 }), S(e, i, "edit", void 0, r);
782
+ }, document.addEventListener("click", M, !0));
783
+ }
784
+ function $t() {
785
+ O && (document.removeEventListener("focusin", O, !0), O = null), P && (document.removeEventListener("keydown", P, !0), P = null), M && (document.removeEventListener("click", M, !0), M = null), z = null, h = null;
786
+ }
787
+ const Lt = (t = {}) => {
788
+ const n = ot(t);
789
+ return xt(), {
790
+ name: "dataBinding",
791
+ toolbar: [
792
+ {
793
+ id: "dataBindingTools",
794
+ label: "Data Binding",
795
+ type: "group",
796
+ command: "openDataBindingDialog",
797
+ items: [
798
+ {
799
+ id: "dataBinding",
800
+ label: "Data Binding",
801
+ command: "openDataBindingDialog",
802
+ icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M7 4a3 3 0 0 0-3 3v3h2V7a1 1 0 0 1 1-1h3V4H7Zm10 0h-3v2h3a1 1 0 0 1 1 1v3h2V7a3 3 0 0 0-3-3ZM4 14v3a3 3 0 0 0 3 3h3v-2H7a1 1 0 0 1-1-1v-3H4Zm14 0v3a1 1 0 0 1-1 1h-3v2h3a3 3 0 0 0 3-3v-3h-2ZM8.5 12a1.5 1.5 0 1 1 0-3h7a1.5 1.5 0 0 1 0 3h-7Zm0 4a1.5 1.5 0 1 1 0-3h4a1.5 1.5 0 0 1 0 3h-4Z" fill="currentColor"></path></svg>'
803
+ },
804
+ {
805
+ id: "dataBindingPreview",
806
+ label: "Data Preview",
807
+ command: "toggleDataBindingPreview",
808
+ icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" focusable="false" aria-hidden="true"><path d="M12 3c-4.4 0-8 1.3-8 3v12c0 1.7 3.6 3 8 3s8-1.3 8-3V6c0-1.7-3.6-3-8-3Zm0 2c3.9 0 6 .9 6 1s-2.1 1-6 1-6-.9-6-1 2.1-1 6-1Zm0 4c3 0 5.6-.5 7-1.3V11c0 .9-2.7 2-7 2s-7-1.1-7-2V7.7C6.4 8.5 9 9 12 9Zm0 6c-4.3 0-7-1.1-7-2v3c0 .9 2.7 2 7 2s7-1.1 7-2v-3c0 .9-2.7 2-7 2Z" fill="currentColor"></path><path d="M16.5 9.4a1 1 0 0 1 1.4 0l1.1 1.1 1.8-1.8a1 1 0 1 1 1.4 1.4l-2.5 2.5a1 1 0 0 1-1.4 0l-1.8-1.8a1 1 0 0 1 0-1.4Z" fill="currentColor"></path></svg>'
809
+ }
810
+ ]
811
+ }
812
+ ],
813
+ commands: {
814
+ openDataBindingDialog: (a, r) => {
815
+ const e = D(r);
816
+ if (!e || K(e)) return !1;
817
+ h = e;
818
+ const i = b.get(e) || n;
819
+ b.set(e, i), V(e, i);
820
+ const o = a?.target;
821
+ if (o === "insert")
822
+ return S(e, i, "insert", a), !0;
823
+ const l = Q(e);
824
+ return o === "edit" || l ? !l && o === "edit" ? !1 : (S(e, i, "edit", a, l || void 0), !0) : (S(e, i, "insert", a), !0);
825
+ },
826
+ insertDataBindingToken: async (a, r) => {
827
+ const e = D(r);
828
+ if (!e || K(e)) return !1;
829
+ h = e;
830
+ const i = b.get(e) || n;
831
+ b.set(e, i);
832
+ const o = H(a || {}, i);
833
+ if (!o.key) return !1;
834
+ const l = e.innerHTML, d = ut(o, i.labels);
835
+ if (bt(e, d), x.get(e) === !0) {
836
+ const u = await I(e, i);
837
+ T(d, i, !0, u);
838
+ }
839
+ return J(e), Y(e, l), !0;
840
+ },
841
+ editDataBindingToken: async (a, r) => {
842
+ const e = D(r);
843
+ if (!e || K(e)) return !1;
844
+ h = e;
845
+ const i = b.get(e) || n;
846
+ b.set(e, i);
847
+ const o = Q(e);
848
+ if (!o) return !1;
849
+ const l = Z(o, i), d = H({ ...l, ...a || {} }, i);
850
+ if (!d.key) return !1;
851
+ const c = e.innerHTML;
852
+ X(o, d, i.labels);
853
+ const u = x.get(e) === !0, p = u ? await I(e, i) : void 0;
854
+ return T(o, i, u, p), J(e), Y(e, c), !0;
855
+ },
856
+ toggleDataBindingPreview: async (a, r) => {
857
+ const e = D(r);
858
+ if (!e) return !1;
859
+ h = e;
860
+ const i = b.get(e) || n;
861
+ b.set(e, i);
862
+ const o = typeof a == "boolean" ? a : x.get(e) !== !0;
863
+ return await _(e, i, o), !0;
864
+ },
865
+ setDataBindingData: async (a, r) => {
866
+ const e = D(r);
867
+ if (!e) return !1;
868
+ if (h = e, a && typeof a == "object" ? (W.set(e, a), N.set(e, { timestamp: Date.now(), data: a })) : (W.delete(e), N.delete(e)), x.get(e) === !0) {
869
+ const i = b.get(e) || n;
870
+ await _(e, i, !0);
871
+ }
872
+ return !0;
873
+ },
874
+ refreshDataBindings: async (a, r) => {
875
+ const e = D(r);
876
+ if (!e) return !1;
877
+ h = e, N.delete(e);
878
+ const i = b.get(e) || n;
879
+ b.set(e, i);
880
+ const o = x.get(e) === !0;
881
+ return await _(e, i, o), !0;
882
+ }
883
+ },
884
+ keymap: {
885
+ "Mod-Alt-Shift-d": "openDataBindingDialog",
886
+ "Mod-Alt-Shift-D": "openDataBindingDialog",
887
+ "Mod-Alt-Shift-b": "toggleDataBindingPreview",
888
+ "Mod-Alt-Shift-B": "toggleDataBindingPreview",
889
+ F7: "openDataBindingDialog",
890
+ F8: "toggleDataBindingPreview"
891
+ },
892
+ init: function(r) {
893
+ U += 1;
894
+ const e = this && typeof this.__pluginConfig == "object" ? ot({ ...n, ...this.__pluginConfig }) : n;
895
+ Tt(e);
896
+ const i = D(
897
+ r && r.editorElement ? { editorElement: r.editorElement } : void 0,
898
+ !1
899
+ );
900
+ if (i) {
901
+ h = i, b.set(i, e), V(i, e);
902
+ const o = x.get(i) === !0;
903
+ tt(i, o, e);
904
+ }
905
+ },
906
+ destroy: () => {
907
+ U = Math.max(0, U - 1), U === 0 && (ft(), $t());
908
+ }
909
+ };
910
+ };
911
+ export {
912
+ Lt as DataBindingPlugin
913
+ };