@graphysdk/react-renderer 1.9.0-beta.1795707432298 → 1.9.0-beta.1795773309240

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.
@@ -1,974 +0,0 @@
1
- import { Bt as ve, Dr as se, Hn as E, Ht as ee, J as P, Pr as Qe, Qt as C, Rn as Te, Rt as et, Tn as tt, Tr as nt, Vt as W, Z as rt, _ as ot, at, ct as ce, ft as it, h as lt, n as te, nt as st, ot as ct, pt as G, rn as dt, st as ut, tt as pt } from "./history-chords-DsyzK0E1.js";
2
- import { H as ft, _t as be, a as ht, b as mt, c as ye, d as g, f as m, h as gt, ht as K, i as vt, l as Tt, m as bt, mt as yt, o as B, ot as ke, p as kt, pt as St, r as xt, s as Se, t as At, u as Ct, w as Ft } from "./start-arrow-button-CqFgBJ0s.js";
3
- import { AUTO_COLOR as de, SetContentCaptionCommand as Et, SetContentSubtitleCommand as Nt, SetContentTitleCommand as Pt, SetStyleRuleCommand as Lt, TEXT_ANNOTATION_FADE_ALPHA as Ot, UpdateAnnotationCommand as xe, alignUnitFractions as It, findStyleRule as Mt, readStyleCoord as zt, resolveTextAnnotationStyle as wt, toPaintColor as ue } from "@graphysdk/viz-engine";
4
- import { useCallback as Dt, useEffect as A, useLayoutEffect as Ae, useMemo as z, useRef as U, useState as q } from "react";
5
- import { Fragment as Ce, jsx as t, jsxs as p } from "react/jsx-runtime";
6
- import { autoUpdate as _t, flip as Rt, offset as Ht, shift as Bt, useFloating as Ut } from "@floating-ui/react-dom";
7
- import { Tooltip as I } from "@base-ui/react/tooltip";
8
- import { Popover as M } from "@base-ui/react/popover";
9
- import { Menu as v } from "@base-ui/react/menu";
10
- import { Toolbar as X } from "@base-ui/react/toolbar";
11
- import { EditorContent as Fe, useEditor as $t, useEditorState as w } from "@tiptap/react";
12
- import { Extension as Ee } from "@tiptap/core";
13
- import { Bold as jt } from "@tiptap/extension-bold";
14
- import { Document as $ } from "@tiptap/extension-document";
15
- import { HardBreak as Wt } from "@tiptap/extension-hard-break";
16
- import { Heading as Gt } from "@tiptap/extension-heading";
17
- import { Italic as Kt } from "@tiptap/extension-italic";
18
- import { Link as Xt } from "@tiptap/extension-link";
19
- import { Text as Vt } from "@tiptap/extension-text";
20
- import { TextAlign as Jt } from "@tiptap/extension-text-align";
21
- import { Color as Zt, FontFamily as Ne, TextStyle as Yt } from "@tiptap/extension-text-style";
22
- import { Underline as qt } from "@tiptap/extension-underline";
23
- import { Placeholder as ne, UndoRedo as Qt } from "@tiptap/extensions";
24
- import { Paragraph as Pe } from "@tiptap/extension-paragraph";
25
- import { Toggle as en } from "@base-ui/react/toggle";
26
- import './rich-text-editor-module.css';var Le = (e) => /* @__PURE__ */ t(P, {
27
- ...e,
28
- children: /* @__PURE__ */ p("g", {
29
- stroke: "currentColor",
30
- strokeWidth: 2,
31
- strokeLinecap: "round",
32
- strokeLinejoin: "round",
33
- children: [
34
- /* @__PURE__ */ t("path", { d: "M21 5H3" }),
35
- /* @__PURE__ */ t("path", { d: "M17 12H7" }),
36
- /* @__PURE__ */ t("path", { d: "M19 19H5" })
37
- ]
38
- })
39
- }), Oe = (e) => /* @__PURE__ */ t(P, {
40
- ...e,
41
- children: /* @__PURE__ */ p("g", {
42
- stroke: "currentColor",
43
- strokeWidth: 2,
44
- strokeLinecap: "round",
45
- strokeLinejoin: "round",
46
- children: [
47
- /* @__PURE__ */ t("path", { d: "M21 5H3" }),
48
- /* @__PURE__ */ t("path", { d: "M21 12H9" }),
49
- /* @__PURE__ */ t("path", { d: "M21 19H7" })
50
- ]
51
- })
52
- }), Ie = (e) => /* @__PURE__ */ t(P, {
53
- ...e,
54
- children: /* @__PURE__ */ p("g", {
55
- stroke: "currentColor",
56
- strokeWidth: 2,
57
- strokeLinecap: "round",
58
- strokeLinejoin: "round",
59
- children: [
60
- /* @__PURE__ */ t("path", { d: "M21 5H3" }),
61
- /* @__PURE__ */ t("path", { d: "M15 12H3" }),
62
- /* @__PURE__ */ t("path", { d: "M17 19H3" })
63
- ]
64
- })
65
- }), tn = ({ textColor: e, ...n }) => /* @__PURE__ */ p(P, {
66
- ...n,
67
- children: [/* @__PURE__ */ p("g", {
68
- stroke: "currentColor",
69
- strokeWidth: 2,
70
- strokeLinecap: "round",
71
- children: [/* @__PURE__ */ t("path", { d: "M6 4h12" }), /* @__PURE__ */ t("path", { d: "M12 4v12" })]
72
- }), /* @__PURE__ */ t("path", {
73
- d: "M5 20h14",
74
- stroke: e ?? "currentColor",
75
- strokeWidth: 3,
76
- strokeLinecap: "round"
77
- })]
78
- });
79
- var Me = [
80
- {
81
- id: "modern",
82
- key: "graph.annotations.textToolbar.font.modern"
83
- },
84
- {
85
- id: "fresh",
86
- key: "graph.annotations.textToolbar.font.fresh"
87
- },
88
- {
89
- id: "timeless",
90
- key: "graph.annotations.textToolbar.font.timeless"
91
- },
92
- {
93
- id: "technical",
94
- key: "graph.annotations.textToolbar.font.technical"
95
- },
96
- {
97
- id: "fineliner",
98
- key: "graph.annotations.textToolbar.font.fineliner"
99
- },
100
- {
101
- id: "handwritten",
102
- key: "graph.annotations.textToolbar.font.handwritten"
103
- }
104
- ].map(({ id: e, key: n }) => ({
105
- id: e,
106
- key: n,
107
- fontFamily: et[e] ?? e
108
- })), nn = (e) => Me.find((n) => n.id === (e ?? "modern")) ?? null;
109
- var ze = [
110
- {
111
- size: 12,
112
- key: "graph.annotations.textToolbar.fontSize.small"
113
- },
114
- {
115
- size: 15,
116
- key: "graph.annotations.textToolbar.fontSize.medium"
117
- },
118
- {
119
- size: 18,
120
- key: "graph.annotations.textToolbar.fontSize.large"
121
- },
122
- {
123
- size: 24,
124
- key: "graph.annotations.textToolbar.fontSize.extraLarge"
125
- },
126
- {
127
- size: 30,
128
- key: "graph.annotations.textToolbar.fontSize.huge"
129
- }
130
- ], rn = (e) => ze.find((n) => n.size === (e ?? 15)) ?? null, on = (e) => `${e}px`, an = [
131
- {
132
- alignment: "left",
133
- Icon: Ie
134
- },
135
- {
136
- alignment: "center",
137
- Icon: Le
138
- },
139
- {
140
- alignment: "right",
141
- Icon: Oe
142
- }
143
- ], kr = ({ annotation: e, textBox: n, panelRect: r, frameWidth: c, frameHeight: o, frameElement: l }) => {
144
- const a = C(), { commands: s } = Qe(), d = Ft(r), f = se((i) => i.spec.styles.overrides), k = se((i) => zt(i.spec)), h = G(), y = Ct(), u = mt(), T = wt(nt(), e.id), F = Tt(e.content), S = it((i) => i.caret?.editor ?? null), L = w({
145
- editor: S,
146
- selector: () => ye(S)
147
- }), D = w({
148
- editor: S,
149
- selector: () => Se(S)
150
- }), _ = nn(F.font ?? D), V = rn(F.fontSize ?? L), We = lt(T), Ge = F.color ?? We, ae = z(() => ({
151
- target: "annotation",
152
- kind: "text",
153
- annotation: e.id
154
- }), [e.id]), ie = (i, b) => {
155
- const x = Mt(f, { select: ae }, k)?.declarations ?? {};
156
- s.dispatch(new Lt({
157
- list: "overrides",
158
- rule: {
159
- select: ae,
160
- declarations: {
161
- ...x,
162
- ...i
163
- }
164
- }
165
- }), b);
166
- }, J = (i, b) => {
167
- s.dispatch(new xe({
168
- kind: "text",
169
- id: e.id,
170
- patch: i
171
- }), b);
172
- }, O = () => h.getState().caret?.editor?.getJSON() ?? e.content, Z = (i, b) => {
173
- const x = O(), H = h.getState().caret?.editor ?? null;
174
- if (H !== null && !B(x)) {
175
- H.chain().focus().setMark(xt, i).run();
176
- return;
177
- }
178
- J({ content: ht(x, i) }, b);
179
- }, Ke = () => {
180
- d(e.id), l.focus({ preventScroll: !0 });
181
- }, Xe = (i) => ie(ln(i), { transient: !0 }), Ve = (i) => ie({ fillAlpha: i }, { transient: !0 }), R = T.fill !== ke, Je = (i) => Z({ color: i === de ? void 0 : i }, { transient: !0 }), Ze = (i) => () => {
182
- B(O()) || le({ font: i }), Z({ font: i }), y.close();
183
- }, Ye = (i) => () => {
184
- B(O()) || le({ fontSize: i }), Z({ fontSize: i }), y.close();
185
- }, le = (i) => {
186
- const b = (n.x + It(e.align).x * n.width) / r.width, x = u({
187
- annotationId: e.id,
188
- anchorX: b,
189
- align: e.align,
190
- panelWidth: r.width,
191
- minWidth: e.width,
192
- pickedFontSize: i.fontSize ?? L,
193
- pickedFont: i.font ?? D
194
- });
195
- x > e.width && J({ width: x });
196
- }, qe = (i) => {
197
- const b = h.getState().caret?.editor ?? null;
198
- if (b === null || B(O())) {
199
- J({ content: vt(O(), i) });
200
- return;
201
- }
202
- const x = b.state.storedMarks;
203
- b.chain().focus().setTextAlign(i).command(({ tr: H }) => (H.setStoredMarks(x), !0)).run();
204
- };
205
- return /* @__PURE__ */ p(g.Root, {
206
- anchorBox: n,
207
- panelRect: r,
208
- frameWidth: c,
209
- frameHeight: o,
210
- label: a("graph.annotations.textToolbar.label"),
211
- testId: "text-toolbar",
212
- children: [
213
- /* @__PURE__ */ t(g.ColorPicker, {
214
- color: ue(T.fill),
215
- label: a("graph.annotations.textToolbar.background"),
216
- hasTransparentOption: !0,
217
- onChange: Xe,
218
- opacity: R ? T.fillAlpha : void 0,
219
- onOpacityChange: R ? Ve : void 0,
220
- ...y.bind("background"),
221
- children: /* @__PURE__ */ t(g.Swatch, {
222
- color: R ? ue(T.fill) : bt,
223
- opacity: R ? T.fillAlpha : void 0
224
- })
225
- }),
226
- /* @__PURE__ */ t(g.ColorPicker, {
227
- color: F.color ?? de,
228
- label: a("graph.annotations.textToolbar.color"),
229
- hasAutomaticOption: !0,
230
- onChange: Je,
231
- ...y.bind("color"),
232
- children: /* @__PURE__ */ t(tn, {
233
- size: "sm",
234
- textColor: Ge,
235
- title: ""
236
- })
237
- }),
238
- /* @__PURE__ */ t(g.Dropdown, {
239
- label: a("graph.annotations.textToolbar.font.ariaLabel"),
240
- trigger: /* @__PURE__ */ t("span", {
241
- style: { fontFamily: _?.fontFamily },
242
- children: "Aa"
243
- }),
244
- ...y.bind("font"),
245
- children: Me.map((i) => /* @__PURE__ */ t(g.MenuItem, {
246
- selected: i.id === _?.id,
247
- onClick: Ze(i.id),
248
- children: /* @__PURE__ */ t("span", {
249
- style: { fontFamily: i.fontFamily },
250
- children: a(i.key)
251
- })
252
- }, i.id))
253
- }),
254
- /* @__PURE__ */ t(g.Dropdown, {
255
- label: a("graph.annotations.textToolbar.fontSize.ariaLabel"),
256
- trigger: V === null ? "" : a(V.key),
257
- ...y.bind("fontSize"),
258
- children: ze.map((i) => /* @__PURE__ */ t(g.MenuItem, {
259
- selected: i.size === V?.size,
260
- onClick: Ye(i.size),
261
- children: /* @__PURE__ */ t("span", {
262
- style: { fontSize: on(i.size) },
263
- children: a(i.key)
264
- })
265
- }, i.size))
266
- }),
267
- /* @__PURE__ */ t(g.Separator, {}),
268
- /* @__PURE__ */ t(sn, {
269
- current: F.alignment ?? "center",
270
- onPick: qe
271
- }),
272
- /* @__PURE__ */ t(g.Separator, {}),
273
- /* @__PURE__ */ t(At, { annotationId: e.id }),
274
- /* @__PURE__ */ t(g.IconButton, {
275
- label: a("graph.annotations.textToolbar.remove"),
276
- onClick: Ke,
277
- children: /* @__PURE__ */ t(gt, {
278
- size: "sm",
279
- title: ""
280
- })
281
- })
282
- ]
283
- });
284
- }, ln = (e) => e === "transparent" ? { fill: ke } : {
285
- fill: e,
286
- fillAlpha: kt(e) ? Ot : 1
287
- }, sn = ({ current: e, onPick: n }) => {
288
- const r = C(), c = (o) => () => n(o);
289
- return /* @__PURE__ */ t(Ce, { children: an.map((o) => /* @__PURE__ */ t(g.ToggleButton, {
290
- label: r(`graph.annotations.textToolbar.align.${o.alignment}`),
291
- pressed: o.alignment === e,
292
- onClick: c(o.alignment),
293
- children: /* @__PURE__ */ t(o.Icon, {
294
- size: "sm",
295
- title: ""
296
- })
297
- }, o.alignment)) });
298
- }, cn = "data-variant", we = Pe.extend({ addAttributes() {
299
- return { variant: {
300
- default: null,
301
- parseHTML: (e) => e.getAttribute("data-variant") ?? null,
302
- renderHTML: (e) => e.variant ? { [cn]: e.variant } : {}
303
- } };
304
- } }), dn = Ee.create({
305
- name: "preventBackspaceAcrossTitleBoundary",
306
- addOptions() {
307
- return { showTitle: !0 };
308
- },
309
- addKeyboardShortcuts() {
310
- return { Backspace: ({ editor: e }) => {
311
- if (!this.options.showTitle) return !1;
312
- const { selection: n } = e.state;
313
- if (!n.empty) return !1;
314
- const { $from: r } = n;
315
- return r.depth !== 1 || r.parentOffset !== 0 ? !1 : r.index(0) === 1;
316
- } };
317
- }
318
- }), re = () => [
319
- Vt,
320
- Qt,
321
- Gt.configure({ levels: [
322
- 1,
323
- 2,
324
- 3
325
- ] }),
326
- jt,
327
- Kt,
328
- qt,
329
- Jt.configure({ types: ["heading", "paragraph"] }),
330
- Xt.configure({
331
- openOnClick: !1,
332
- autolink: !0
333
- }),
334
- Yt,
335
- Zt,
336
- Wt
337
- ], un = ({ titlePlaceholder: e, subtitlePlaceholder: n, showTitle: r, showSubtitle: c }) => [
338
- fn({
339
- showTitle: r,
340
- showSubtitle: c
341
- }),
342
- we,
343
- ...re(),
344
- Ne,
345
- dn.configure({ showTitle: r }),
346
- ne.configure({
347
- showOnlyCurrent: !1,
348
- placeholder: ({ pos: o, editor: l }) => {
349
- if (r && o === 0) return e;
350
- const a = r ? l.state.doc.firstChild?.nodeSize ?? -1 : 0;
351
- return c && o === a ? n : "";
352
- }
353
- })
354
- ], pn = ({ placeholder: e }) => [
355
- $,
356
- we,
357
- ...re(),
358
- Ne,
359
- ne.configure({
360
- showOnlyCurrent: !1,
361
- placeholder: ({ pos: n }) => n === 0 ? e : ""
362
- })
363
- ], fn = ({ showTitle: e, showSubtitle: n }) => e && n ? $.extend({ content: "block{2,}" }) : $, De = (e, n) => {
364
- if (n === null) return;
365
- let r = null;
366
- try {
367
- r = e.view.posAtCoords({
368
- left: n.x,
369
- top: n.y
370
- });
371
- } catch {
372
- r = null;
373
- }
374
- e.commands.focus(r === null ? "end" : r.pos, { scrollIntoView: !1 });
375
- }, hn = "'Noto Serif', Georgia, 'Times New Roman', serif, 'Apple Color Emoji', 'NotoColorEmoji'", mn = `'Aeonik', 'Aeonik Fallback', ${Te}`, gn = "'PT Mono', 'Courier New', monospace, 'Apple Color Emoji', 'NotoColorEmoji'", vn = "'Intruding Cat', cursive, 'Apple Color Emoji', 'NotoColorEmoji'", Q = [
376
- {
377
- id: "modern",
378
- label: "Modern",
379
- preview: "Aa",
380
- fontFamily: Te
381
- },
382
- {
383
- id: "fresh",
384
- label: "Fresh",
385
- preview: "Aa",
386
- fontFamily: mn
387
- },
388
- {
389
- id: "timeless",
390
- label: "Timeless",
391
- preview: "Aa",
392
- fontFamily: hn
393
- },
394
- {
395
- id: "technical",
396
- label: "Technical",
397
- preview: "00",
398
- fontFamily: gn
399
- },
400
- {
401
- id: "fineliner",
402
- label: "Fineliner",
403
- preview: "Aa",
404
- fontFamily: vn
405
- }
406
- ], Tn = (e) => e ? Q.find((n) => n.fontFamily === e) ?? null : null, _e = "_70l3rt0", Re = "_70l3rt1", He = "_70l3rt3", Be = "_70l3rt4", Ue = "_70l3rt5", bn = ({ editor: e, currentFontFamily: n, open: r, onOpenChange: c }) => {
407
- const o = C(), l = Tn(n) ?? Q[0], a = (s) => {
408
- e.chain().focus().setFontFamily(s.fontFamily).run();
409
- };
410
- return /* @__PURE__ */ p(v.Root, {
411
- open: r,
412
- onOpenChange: c,
413
- children: [/* @__PURE__ */ p(v.Trigger, {
414
- render: /* @__PURE__ */ t(X.Button, {}),
415
- "aria-label": o("graph.toolbar.font.ariaLabel"),
416
- className: _e,
417
- onMouseDown: (s) => s.preventDefault(),
418
- children: [/* @__PURE__ */ t("span", {
419
- className: Re,
420
- style: { fontFamily: l?.fontFamily },
421
- children: l?.preview
422
- }), /* @__PURE__ */ t(be, { size: "sm" })]
423
- }), /* @__PURE__ */ t(v.Portal, {
424
- container: W(),
425
- className: K,
426
- children: /* @__PURE__ */ t(ee, { children: /* @__PURE__ */ t(v.Positioner, {
427
- side: "bottom",
428
- align: "start",
429
- sideOffset: 6,
430
- className: He,
431
- children: /* @__PURE__ */ t(v.Popup, {
432
- className: Be,
433
- onMouseDown: (s) => s.preventDefault(),
434
- children: Q.map((s) => /* @__PURE__ */ t(v.Item, {
435
- className: Ue,
436
- "data-selected": s.id === l?.id,
437
- onClick: () => a(s),
438
- children: /* @__PURE__ */ t("span", {
439
- style: { fontFamily: s.fontFamily },
440
- children: s.label
441
- })
442
- }, s.id))
443
- })
444
- }) })
445
- })]
446
- });
447
- }, $e = {
448
- id: "text",
449
- translationKey: "graph.toolbar.heading.text",
450
- previewFont: E.fontTextEditorBody
451
- }, pe = [
452
- {
453
- id: "caption",
454
- translationKey: "graph.toolbar.heading.caption",
455
- previewFont: E.fontTextEditorH6
456
- },
457
- $e,
458
- {
459
- id: "h3",
460
- translationKey: "graph.toolbar.heading.heading3",
461
- previewFont: E.fontTextEditorH3
462
- },
463
- {
464
- id: "h2",
465
- translationKey: "graph.toolbar.heading.heading2",
466
- previewFont: E.fontTextEditorH2
467
- },
468
- {
469
- id: "h1",
470
- translationKey: "graph.toolbar.heading.heading1",
471
- previewFont: E.fontTextEditorH1
472
- }
473
- ], yn = ({ editor: e, activeStyle: n, open: r, onOpenChange: c }) => {
474
- const o = C(), l = pe.find((a) => a.id === n) ?? $e;
475
- return /* @__PURE__ */ p(v.Root, {
476
- open: r,
477
- onOpenChange: c,
478
- children: [/* @__PURE__ */ p(v.Trigger, {
479
- render: /* @__PURE__ */ t(X.Button, {}),
480
- "aria-label": o("graph.toolbar.heading.ariaLabel"),
481
- className: _e,
482
- onMouseDown: (a) => a.preventDefault(),
483
- children: [/* @__PURE__ */ t("span", {
484
- className: Re,
485
- children: o(l.translationKey)
486
- }), /* @__PURE__ */ t(be, { size: "sm" })]
487
- }), /* @__PURE__ */ t(v.Portal, {
488
- container: W(),
489
- className: K,
490
- children: /* @__PURE__ */ t(ee, { children: /* @__PURE__ */ t(v.Positioner, {
491
- side: "bottom",
492
- align: "start",
493
- sideOffset: 6,
494
- className: He,
495
- children: /* @__PURE__ */ t(v.Popup, {
496
- className: Be,
497
- onMouseDown: (a) => a.preventDefault(),
498
- children: pe.map((a) => /* @__PURE__ */ t(v.Item, {
499
- className: Ue,
500
- "data-selected": a.id === l.id,
501
- onClick: () => kn(e, a.id),
502
- children: /* @__PURE__ */ t(Sn, {
503
- font: a.previewFont,
504
- children: o(a.translationKey)
505
- })
506
- }, a.id))
507
- })
508
- }) })
509
- })]
510
- });
511
- }, kn = (e, n) => {
512
- switch (n) {
513
- case "caption":
514
- e.chain().focus().setNode("paragraph", { variant: "caption" }).run();
515
- return;
516
- case "text":
517
- e.chain().focus().setNode("paragraph", { variant: null }).run();
518
- return;
519
- case "h1":
520
- e.chain().focus().setHeading({ level: 1 }).run();
521
- return;
522
- case "h2":
523
- e.chain().focus().setHeading({ level: 2 }).run();
524
- return;
525
- case "h3":
526
- e.chain().focus().setHeading({ level: 3 }).run();
527
- }
528
- }, Sn = ({ font: e, children: n }) => /* @__PURE__ */ t("span", {
529
- style: {
530
- font: e,
531
- margin: 0
532
- },
533
- children: n
534
- }), xn = (e) => /* @__PURE__ */ t(P, {
535
- ...e,
536
- children: /* @__PURE__ */ p("g", {
537
- stroke: "currentColor",
538
- strokeWidth: 2,
539
- strokeLinecap: "round",
540
- strokeLinejoin: "round",
541
- children: [/* @__PURE__ */ t("path", { d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" }), /* @__PURE__ */ t("path", { d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" })]
542
- })
543
- }), An = (e) => /* @__PURE__ */ t(P, {
544
- ...e,
545
- children: /* @__PURE__ */ p("g", {
546
- stroke: "currentColor",
547
- strokeWidth: 2,
548
- strokeLinecap: "round",
549
- strokeLinejoin: "round",
550
- children: [/* @__PURE__ */ t("path", { d: "M18 6 6 18" }), /* @__PURE__ */ t("path", { d: "m6 6 12 12" })]
551
- })
552
- }), Cn = (e) => !e.content || e.content.length === 0 ? !0 : e.content.every((n) => !n.content || n.content.length === 0), Fn = (e) => {
553
- const { $from: n } = e.state.selection, r = n.parent.textContent, c = n.parentOffset, o = n.start();
554
- let l = c;
555
- for (; l > 0 && fe(r[l - 1]); ) l -= 1;
556
- let a = c;
557
- for (; a < r.length && fe(r[a]); ) a += 1;
558
- return {
559
- from: o + l,
560
- to: o + a
561
- };
562
- }, fe = (e) => e !== void 0 && /\S/.test(e), En = "fop13s0", Nn = "fop13s1", Pn = "fop13s2", Ln = "fop13s3", he = "fop13s4", On = ({ editor: e, currentUrl: n, active: r, open: c, onOpenChange: o }) => {
563
- const l = C(), [a, s] = q(""), d = U(null);
564
- A(() => {
565
- c && s(n ?? "");
566
- }, [c, n]);
567
- const f = () => {
568
- In(e, a), o(!1);
569
- }, k = () => {
570
- s(""), o(!1);
571
- }, h = (u) => {
572
- s(u.target.value);
573
- }, y = (u) => {
574
- u.key === "Enter" && (u.preventDefault(), f());
575
- };
576
- return /* @__PURE__ */ p(M.Root, {
577
- open: c,
578
- onOpenChange: o,
579
- children: [/* @__PURE__ */ t(M.Trigger, {
580
- render: /* @__PURE__ */ t(X.Button, {}),
581
- "aria-label": l("graph.toolbar.formatting.link"),
582
- "data-active": r,
583
- className: En,
584
- onMouseDown: (u) => u.preventDefault(),
585
- children: /* @__PURE__ */ t(xn, {})
586
- }), /* @__PURE__ */ t(M.Portal, {
587
- container: W(),
588
- className: K,
589
- children: /* @__PURE__ */ t(ee, { children: /* @__PURE__ */ t(M.Positioner, {
590
- sideOffset: 6,
591
- align: "end",
592
- className: Nn,
593
- children: /* @__PURE__ */ p(M.Popup, {
594
- className: Pn,
595
- initialFocus: d,
596
- onMouseDown: (u) => u.preventDefault(),
597
- children: [
598
- /* @__PURE__ */ t("input", {
599
- ref: d,
600
- type: "url",
601
- value: a,
602
- placeholder: l("graph.toolbar.link.placeholder"),
603
- "aria-label": l("graph.toolbar.link.urlLabel"),
604
- className: Ln,
605
- onMouseDown: (u) => u.stopPropagation(),
606
- onChange: h,
607
- onKeyDown: y
608
- }),
609
- /* @__PURE__ */ t("button", {
610
- type: "button",
611
- "aria-label": l("common.cancel"),
612
- className: he,
613
- onClick: k,
614
- children: /* @__PURE__ */ t(An, {})
615
- }),
616
- /* @__PURE__ */ t("button", {
617
- type: "button",
618
- "aria-label": l("graph.toolbar.link.apply"),
619
- className: he,
620
- onClick: f,
621
- children: /* @__PURE__ */ t(ft, {})
622
- })
623
- ]
624
- })
625
- }) })
626
- })]
627
- });
628
- }, In = (e, n) => {
629
- const r = n.trim(), { selection: c } = e.state;
630
- if (!r) {
631
- e.chain().focus().extendMarkRange("link").unsetLink().run();
632
- return;
633
- }
634
- if (!c.empty) {
635
- e.chain().focus().setLink({ href: r }).run();
636
- return;
637
- }
638
- if (e.isActive("link")) {
639
- e.chain().focus().extendMarkRange("link").setLink({ href: r }).run();
640
- return;
641
- }
642
- const o = Fn(e);
643
- e.chain().focus().setTextSelection(o).setLink({ href: r }).run();
644
- }, Mn = "_1d66w570", zn = "_1d66w571", N = ({ label: e, active: n, onToggle: r, children: c }) => {
645
- const o = (l) => l.preventDefault();
646
- return /* @__PURE__ */ p(I.Root, { children: [/* @__PURE__ */ t(I.Trigger, {
647
- render: /* @__PURE__ */ t(en, {
648
- render: /* @__PURE__ */ t(X.Button, {}),
649
- pressed: n,
650
- onPressedChange: () => r()
651
- }),
652
- "aria-label": e,
653
- className: Mn,
654
- onMouseDown: o,
655
- children: c
656
- }), /* @__PURE__ */ t(I.Portal, {
657
- container: W(),
658
- className: K,
659
- children: /* @__PURE__ */ t(yt, { children: /* @__PURE__ */ t(I.Positioner, {
660
- sideOffset: 6,
661
- className: zn,
662
- children: /* @__PURE__ */ t(I.Popup, {
663
- className: St,
664
- children: e
665
- })
666
- }) })
667
- })] });
668
- }, wn = ({ editor: e, activeAlignment: n = "left" }) => {
669
- const r = C();
670
- return /* @__PURE__ */ p(Ce, { children: [
671
- /* @__PURE__ */ t(N, {
672
- label: r("graph.toolbar.textAlign.left"),
673
- active: n === "left",
674
- onToggle: () => e.chain().focus().setTextAlign("left").run(),
675
- children: /* @__PURE__ */ t(Ie, {})
676
- }),
677
- /* @__PURE__ */ t(N, {
678
- label: r("graph.toolbar.textAlign.center"),
679
- active: n === "center",
680
- onToggle: () => e.chain().focus().setTextAlign("center").run(),
681
- children: /* @__PURE__ */ t(Le, {})
682
- }),
683
- /* @__PURE__ */ t(N, {
684
- label: r("graph.toolbar.textAlign.right"),
685
- active: n === "right",
686
- onToggle: () => e.chain().focus().setTextAlign("right").run(),
687
- children: /* @__PURE__ */ t(Oe, {})
688
- })
689
- ] });
690
- }, Dn = "_1u34vl40", _n = ({ editor: e }) => ({
691
- bold: e?.isActive("bold") ?? !1,
692
- italic: e?.isActive("italic") ?? !1,
693
- underlined: e?.isActive("underline") ?? !1,
694
- linked: e?.isActive("link") ?? !1,
695
- linkUrl: e?.getAttributes("link").href ?? null,
696
- color: e?.getAttributes("textStyle").color ?? null,
697
- fontFamily: e?.getAttributes("textStyle").fontFamily ?? null,
698
- fontSize: Rn(e),
699
- textAlign: Hn(e)
700
- }), Rn = (e) => e ? e.isActive("heading", { level: 1 }) ? "h1" : e.isActive("heading", { level: 2 }) ? "h2" : e.isActive("heading", { level: 3 }) ? "h3" : e.isActive("paragraph", { variant: "caption" }) ? "caption" : "text" : "text", Hn = (e) => e ? e.isActive({ textAlign: "center" }) ? "center" : e.isActive({ textAlign: "right" }) ? "right" : "left" : "left", Bn = 8, Un = 8, $n = ({ editor: e }) => {
701
- const n = C(), [r, c] = q(!1), [o, l] = q(null), a = o !== null, s = (u) => (T) => {
702
- l(T ? u : null);
703
- }, { refs: d, floatingStyles: f } = Ut({
704
- placement: "top-start",
705
- strategy: "fixed",
706
- middleware: [
707
- Ht(Bn),
708
- Rt(),
709
- Bt({ padding: Un })
710
- ],
711
- whileElementsMounted: _t
712
- }), k = U(null), h = w({
713
- editor: e,
714
- selector: _n
715
- }), y = Dt((u) => {
716
- k.current = u, d.setFloating(u);
717
- }, [d]);
718
- return A(() => {
719
- e && d.setReference(e.view.dom);
720
- }, [e, d]), A(() => {
721
- if (!e) return;
722
- const u = () => c(!0), T = ({ event: F }) => {
723
- const { relatedTarget: S, currentTarget: L } = F, D = S instanceof Node && k.current?.contains(S), _ = S instanceof Node && L instanceof Node && L.contains(S);
724
- !D && !_ && c(!1);
725
- };
726
- return e.on("focus", u), e.on("blur", T), () => {
727
- e.off("focus", u), e.off("blur", T);
728
- };
729
- }, [e]), !e || !r && !a ? null : /* @__PURE__ */ t(m.Portal, { children: /* @__PURE__ */ p(m.Root, {
730
- ref: y,
731
- className: Dn,
732
- style: f,
733
- children: [
734
- /* @__PURE__ */ p(m.Group, { children: [/* @__PURE__ */ t(m.ColorPicker, {
735
- color: h?.color ?? null,
736
- onChange: (u) => e.chain().setColor(u).run(),
737
- open: o === "color",
738
- onOpenChange: s("color")
739
- }), /* @__PURE__ */ t(bn, {
740
- editor: e,
741
- currentFontFamily: h?.fontFamily ?? null,
742
- open: o === "fontFamily",
743
- onOpenChange: s("fontFamily")
744
- })] }),
745
- /* @__PURE__ */ t(m.Separator, {}),
746
- /* @__PURE__ */ t(m.Group, { children: /* @__PURE__ */ t(yn, {
747
- editor: e,
748
- activeStyle: h?.fontSize ?? "text",
749
- open: o === "fontSize",
750
- onOpenChange: s("fontSize")
751
- }) }),
752
- /* @__PURE__ */ t(m.Separator, {}),
753
- /* @__PURE__ */ p(m.Group, { children: [
754
- /* @__PURE__ */ t(N, {
755
- label: n("graph.toolbar.formatting.bold"),
756
- active: h?.bold ?? !1,
757
- onToggle: () => e.chain().focus().toggleBold().run(),
758
- children: /* @__PURE__ */ t("strong", { children: "B" })
759
- }),
760
- /* @__PURE__ */ t(N, {
761
- label: n("graph.toolbar.formatting.italic"),
762
- active: h?.italic ?? !1,
763
- onToggle: () => e.chain().focus().toggleItalic().run(),
764
- children: /* @__PURE__ */ t("em", { children: "I" })
765
- }),
766
- /* @__PURE__ */ t(N, {
767
- label: n("graph.toolbar.formatting.underline"),
768
- active: h?.underlined ?? !1,
769
- onToggle: () => e.chain().focus().toggleUnderline().run(),
770
- children: /* @__PURE__ */ t("u", { children: "U" })
771
- })
772
- ] }),
773
- /* @__PURE__ */ t(m.Separator, {}),
774
- /* @__PURE__ */ t(m.Group, { children: /* @__PURE__ */ t(wn, {
775
- editor: e,
776
- activeAlignment: h?.textAlign
777
- }) }),
778
- /* @__PURE__ */ t(m.Separator, {}),
779
- /* @__PURE__ */ t(m.Group, { children: /* @__PURE__ */ t(On, {
780
- editor: e,
781
- currentUrl: h?.linkUrl ?? null,
782
- active: h?.linked ?? !1,
783
- open: o === "link",
784
- onOpenChange: s("link")
785
- }) })
786
- ]
787
- }) });
788
- }, jn = "_1uy50v30", je = ({ editor: e, ariaLabel: n }) => /* @__PURE__ */ p("div", {
789
- className: jn,
790
- children: [/* @__PURE__ */ t($n, { editor: e }), /* @__PURE__ */ t(Fe, {
791
- editor: e,
792
- "aria-label": n
793
- })]
794
- }), Wn = 200, oe = ({ content: e, extensions: n, editable: r, onUpdate: c, updateDebounceMs: o = Wn }) => {
795
- const l = U(me(e)), a = U(l.current), s = dt((f) => {
796
- a.current = f, c?.(f);
797
- }, o), d = $t({
798
- extensions: n,
799
- content: l.current,
800
- editable: r,
801
- immediatelyRender: !1,
802
- onUpdate: ({ editor: f }) => {
803
- const k = f.getJSON();
804
- if (Y(a.current, k)) return s.cancel();
805
- s.run(k);
806
- }
807
- });
808
- return A(() => {
809
- d?.setEditable(r);
810
- }, [d, r]), A(() => {
811
- if (!d) return;
812
- const f = me(e);
813
- Y(a.current, f) || (a.current = f, !Y(d.getJSON(), f) && (s.cancel(), Gn(d, f)));
814
- }, [
815
- d,
816
- e,
817
- s
818
- ]), A(() => () => s.flush(), [s]), d;
819
- }, me = (e) => e === null ? {
820
- type: "doc",
821
- content: []
822
- } : typeof e == "string" ? {
823
- type: "doc",
824
- content: [{
825
- type: "paragraph",
826
- content: e ? [{
827
- type: "text",
828
- text: e
829
- }] : []
830
- }]
831
- } : e, Gn = (e, n) => {
832
- const { from: r, to: c } = e.state.selection;
833
- e.commands.setContent(n, { emitUpdate: !1 });
834
- const o = e.state.doc.content.size;
835
- e.commands.setTextSelection({
836
- from: Math.min(r, o),
837
- to: Math.min(c, o)
838
- });
839
- }, Y = (e, n) => JSON.stringify(j(e)) === JSON.stringify(j(n)), j = (e) => Array.isArray(e) ? e.map(j) : e === null || typeof e != "object" ? e : Object.fromEntries(Object.entries(e).map(([n, r]) => [n, j(r)]).filter(([, n]) => !Kn(n)).sort(([n], [r]) => String(n).localeCompare(String(r)))), Kn = (e) => e == null || typeof e == "object" && Object.keys(e).length === 0, Sr = ({ caption: e, captionStyle: n }) => {
840
- const { dispatch: r } = te(), c = G(), o = oe({
841
- content: e,
842
- extensions: z(() => pn({ placeholder: ut }), []),
843
- editable: !0,
844
- onUpdate: (l) => {
845
- const a = Cn(l) ? null : l;
846
- r(new Et({ caption: a }));
847
- }
848
- });
849
- return Ae(() => {
850
- o !== null && De(o, c.getState().takePendingTextCaret("caption"));
851
- }, [o, c]), /* @__PURE__ */ t("div", {
852
- "data-testid": "caption-editor",
853
- style: tt(n),
854
- children: o === null ? /* @__PURE__ */ t(pt, { caption: e }) : /* @__PURE__ */ t(je, {
855
- editor: o,
856
- ariaLabel: "Chart caption"
857
- })
858
- });
859
- }, Xn = (e) => [
860
- $,
861
- Pe,
862
- ...re(),
863
- Vn,
864
- ne.configure({
865
- showOnlyCurrent: !1,
866
- placeholder: ({ pos: n }) => n === 0 ? e : ""
867
- })
868
- ], xr = ({ annotation: e }) => {
869
- const n = C(), { dispatch: r } = te(), c = G(), o = z(() => Xn(n("graph.annotations.text.placeholder")), [n]), l = oe({
870
- content: e.content,
871
- extensions: o,
872
- editable: !0,
873
- onUpdate: (d) => {
874
- r(new xe({
875
- kind: "text",
876
- id: e.id,
877
- patch: { content: d }
878
- }));
879
- }
880
- });
881
- A(() => {
882
- const { setCaretEditor: d } = c.getState();
883
- return d(l), () => d(null);
884
- }, [l, c]), A(() => {
885
- l?.commands.focus("end", { scrollIntoView: !1 });
886
- }, [l]);
887
- const a = w({
888
- editor: l,
889
- selector: ({ editor: d }) => ye(d)
890
- }), s = w({
891
- editor: l,
892
- selector: ({ editor: d }) => Se(d)
893
- });
894
- return /* @__PURE__ */ t(Fe, {
895
- "aria-label": n("graph.annotations.text.editLabel"),
896
- className: ot,
897
- editor: l,
898
- style: {
899
- ...a === null ? {} : { fontSize: `calc(${a}px * ${E.textScale})` },
900
- ...s === null ? {} : { fontFamily: ve(s) }
901
- },
902
- "data-testid": "text-annotation-editor"
903
- });
904
- }, ge = (e) => {
905
- const n = ve(e);
906
- return n === void 0 ? {} : { style: `font-family: ${n}` };
907
- }, Vn = Ee.create({
908
- name: "annotationTextStyleAttributes",
909
- addGlobalAttributes() {
910
- return [{
911
- types: ["textStyle"],
912
- attributes: {
913
- fontFamily: {
914
- default: null,
915
- renderHTML: (e) => ge(e.fontFamily)
916
- },
917
- font: {
918
- default: null,
919
- renderHTML: (e) => ge(e.font)
920
- },
921
- fontSize: {
922
- default: null,
923
- renderHTML: (e) => typeof e.fontSize == "number" && Number.isFinite(e.fontSize) ? { style: `font-size: calc(${e.fontSize}px * ${E.textScale})` } : {}
924
- }
925
- }
926
- }];
927
- }
928
- }), Ar = ({ title: e, showTitle: n, showSubtitle: r, subtitle: c }) => {
929
- const { dispatch: o } = te(), l = G(), a = z(() => un({
930
- titlePlaceholder: ce,
931
- subtitlePlaceholder: ce,
932
- showTitle: n,
933
- showSubtitle: r
934
- }), [n, r]), s = oe({
935
- content: z(() => at({
936
- title: e,
937
- showTitle: n,
938
- subtitle: c,
939
- showSubtitle: r
940
- }), [
941
- e,
942
- n,
943
- c,
944
- r
945
- ]),
946
- extensions: a,
947
- editable: !0,
948
- onUpdate: (d) => {
949
- const f = ct(d, n);
950
- n && o(new Pt({ title: f.title })), r && o(new Nt({ subtitle: f.subtitle }));
951
- }
952
- });
953
- return Ae(() => {
954
- s !== null && De(s, l.getState().takePendingTextCaret("header"));
955
- }, [s, l]), /* @__PURE__ */ t("div", {
956
- className: rt,
957
- "data-testid": "title-editor",
958
- children: s === null ? /* @__PURE__ */ t(st, {
959
- title: e,
960
- showTitle: n,
961
- showSubtitle: r,
962
- subtitle: c
963
- }) : /* @__PURE__ */ t(je, {
964
- editor: s,
965
- ariaLabel: "Chart title and subtitle"
966
- })
967
- });
968
- };
969
- export {
970
- Sr as CaptionEditor,
971
- xr as TextAnnotationEditor,
972
- kr as TextToolbar,
973
- Ar as TitleEditor
974
- };