@takesix/react 0.0.0-stage → 0.2.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.
package/dist/index.js ADDED
@@ -0,0 +1,1286 @@
1
+ import { Fragment as e, useCallback as t, useEffect as n, useId as r, useLayoutEffect as i, useMemo as a, useRef as o, useState as s } from "react";
2
+ import { DEFAULT_SIZE as c, MAX_BLOCKS_PER_LEVEL as l, SIZES as u, addBlock as d, addLink as f, buildIndex as p, canAddBlock as m, getLevel as h, groupBlocks as g, moveBlock as _, removeBlock as ee, updateBlock as v, visibleLinks as te } from "@takesix/core";
3
+ import { Fragment as y, jsx as b, jsxs as x } from "react/jsx-runtime";
4
+ // src/icons.tsx
5
+ function ne({ size: e = 20 }) {
6
+ return /* @__PURE__ */ x("svg", {
7
+ width: e,
8
+ height: e,
9
+ viewBox: "0 0 24 24",
10
+ fill: "none",
11
+ stroke: "currentColor",
12
+ strokeWidth: "1.5",
13
+ strokeLinecap: "round",
14
+ children: [/* @__PURE__ */ b("line", {
15
+ x1: "12",
16
+ y1: "5",
17
+ x2: "12",
18
+ y2: "19"
19
+ }), /* @__PURE__ */ b("line", {
20
+ x1: "5",
21
+ y1: "12",
22
+ x2: "19",
23
+ y2: "12"
24
+ })]
25
+ });
26
+ }
27
+ function S() {
28
+ return /* @__PURE__ */ x("svg", {
29
+ width: "12",
30
+ height: "12",
31
+ viewBox: "0 0 24 24",
32
+ fill: "none",
33
+ stroke: "currentColor",
34
+ strokeWidth: "2.5",
35
+ strokeLinecap: "round",
36
+ children: [/* @__PURE__ */ b("line", {
37
+ x1: "18",
38
+ y1: "6",
39
+ x2: "6",
40
+ y2: "18"
41
+ }), /* @__PURE__ */ b("line", {
42
+ x1: "6",
43
+ y1: "6",
44
+ x2: "18",
45
+ y2: "18"
46
+ })]
47
+ });
48
+ }
49
+ function C() {
50
+ return /* @__PURE__ */ x("svg", {
51
+ width: "12",
52
+ height: "12",
53
+ viewBox: "0 0 24 24",
54
+ fill: "none",
55
+ stroke: "currentColor",
56
+ strokeWidth: "2.5",
57
+ strokeLinecap: "round",
58
+ strokeLinejoin: "round",
59
+ children: [/* @__PURE__ */ b("line", {
60
+ x1: "5",
61
+ y1: "12",
62
+ x2: "19",
63
+ y2: "12"
64
+ }), /* @__PURE__ */ b("polyline", { points: "12 5 19 12 12 19" })]
65
+ });
66
+ }
67
+ function re() {
68
+ return /* @__PURE__ */ x("svg", {
69
+ width: "12",
70
+ height: "12",
71
+ viewBox: "0 0 24 24",
72
+ fill: "none",
73
+ stroke: "currentColor",
74
+ strokeWidth: "2.2",
75
+ strokeLinecap: "round",
76
+ children: [
77
+ /* @__PURE__ */ b("line", {
78
+ x1: "5",
79
+ y1: "6",
80
+ x2: "19",
81
+ y2: "6"
82
+ }),
83
+ /* @__PURE__ */ b("line", {
84
+ x1: "5",
85
+ y1: "12",
86
+ x2: "19",
87
+ y2: "12"
88
+ }),
89
+ /* @__PURE__ */ b("line", {
90
+ x1: "5",
91
+ y1: "18",
92
+ x2: "13",
93
+ y2: "18"
94
+ })
95
+ ]
96
+ });
97
+ }
98
+ var w = {
99
+ card: "_card_21d5p_1",
100
+ deleteBtn: "_deleteBtn_21d5p_13",
101
+ sizeBtn: "_sizeBtn_21d5p_38",
102
+ resizeHandle: "_resizeHandle_21d5p_63",
103
+ cardResizing: "_cardResizing_21d5p_74",
104
+ detailsBtn: "_detailsBtn_21d5p_82",
105
+ cardEditing: "_cardEditing_21d5p_102",
106
+ detailsBtnFilled: "_detailsBtnFilled_21d5p_106",
107
+ connectBtn: "_connectBtn_21d5p_115",
108
+ connectBtnActive: "_connectBtnActive_21d5p_140",
109
+ cardConnectingSource: "_cardConnectingSource_21d5p_151",
110
+ cardConnectable: "_cardConnectable_21d5p_156",
111
+ cardConnected: "_cardConnected_21d5p_165",
112
+ connectOverlay: "_connectOverlay_21d5p_171",
113
+ cardUnlinkable: "_cardUnlinkable_21d5p_183",
114
+ inside: "_inside_21d5p_189",
115
+ selectOverlay: "_selectOverlay_21d5p_196",
116
+ selectMark: "_selectMark_21d5p_201",
117
+ cardSelected: "_cardSelected_21d5p_217",
118
+ connectOverlayConnected: "_connectOverlayConnected_21d5p_227",
119
+ header: "_header_21d5p_237",
120
+ cardWithDetails: "_cardWithDetails_21d5p_241",
121
+ addInside: "_addInside_21d5p_245",
122
+ dragHandle: "_dragHandle_21d5p_257",
123
+ cardDragged: "_cardDragged_21d5p_283",
124
+ cardZoomable: "_cardZoomable_21d5p_293",
125
+ title: "_title_21d5p_298",
126
+ description: "_description_21d5p_299",
127
+ icon: "_icon_21d5p_315",
128
+ headerText: "_headerText_21d5p_322",
129
+ cardWide: "_cardWide_21d5p_349",
130
+ editable: "_editable_21d5p_365"
131
+ }, T = {
132
+ S: 2,
133
+ M: 3,
134
+ L: 4,
135
+ F: 6
136
+ }, E = {
137
+ S: "⅓",
138
+ M: "½",
139
+ L: "⅔",
140
+ F: "1"
141
+ }, D = {
142
+ S: "a third",
143
+ M: "half",
144
+ L: "two thirds",
145
+ F: "full width"
146
+ };
147
+ function O(e) {
148
+ return u.reduce((t, n) => Math.abs(T[n] - e) < Math.abs(T[t] - e) ? n : t);
149
+ }
150
+ function ie({ block: e, editing: t, onRename: r, onDescribe: i, onDelete: a, onAddChild: l, onDrillIn: d, connectingFrom: f, canLinkTo: p, isConnected: m, onStartConnect: h, onConnectTarget: g, onRegisterEl: _, isDragged: ee, dropPosition: v, onDragStartBlock: te, onDragOverBlock: y, onDragEndBlock: T, onShowDetails: ie, selectable: k, selected: A, onToggleSelect: j, onResize: M }) {
151
+ let [N, P] = s(null), F = N ?? e.size ?? c, I = !!e.details?.trim(), ae = e.children?.length ?? 0, L = ae > 0, R = o(null), [z, B] = s(!1);
152
+ n(() => {
153
+ if (!z) return;
154
+ let e = () => B(!1);
155
+ return window.addEventListener("pointerup", e), () => window.removeEventListener("pointerup", e);
156
+ }, [z]);
157
+ let V = F === "F" ? "y" : "x", H = f === e.id, U = f !== null && f !== e.id && p, W = f !== null && f !== e.id && !p, G = o(_);
158
+ G.current = _, n(() => (G.current(e.id, R.current), () => {
159
+ G.current(e.id, null);
160
+ }), [e.id]);
161
+ function K() {
162
+ let e = R.current.getBoundingClientRect();
163
+ return {
164
+ left: e.left,
165
+ top: e.top,
166
+ width: e.width,
167
+ height: e.height
168
+ };
169
+ }
170
+ function oe(t) {
171
+ if (!L || !R.current || t.target.closest("[data-text], [data-drag-handle], [data-resize-handle]")) return;
172
+ let n = window.getSelection();
173
+ n && !n.isCollapsed && R.current.contains(n.anchorNode) || d(e, K());
174
+ }
175
+ let q = w.card;
176
+ return L && !U && !k && (q += ` ${w.cardZoomable}`), A && (q += ` ${w.cardSelected}`), F === "F" && (q += ` ${w.cardWide}`), N && (q += ` ${w.cardResizing}`), t ? q += ` ${w.cardEditing}` : I && (q += ` ${w.cardWithDetails}`), ee && (q += ` ${w.cardDragged}`), H ? q += ` ${w.cardConnectingSource}` : U && m ? q += ` ${w.cardConnected}` : U ? q += ` ${w.cardConnectable}` : W && (q += ` ${w.cardUnlinkable}`), /* @__PURE__ */ x("div", {
177
+ className: q,
178
+ ref: R,
179
+ "data-block-id": e.id,
180
+ "data-size": F,
181
+ "data-drop": v ?? void 0,
182
+ "data-axis": V,
183
+ onClick: oe,
184
+ draggable: t && z,
185
+ onDragStart: (t) => {
186
+ z ? (t.dataTransfer.effectAllowed = "move", t.dataTransfer.setData("text/plain", e.id), te(e.id)) : t.preventDefault();
187
+ },
188
+ onDragOver: (n) => {
189
+ if (!t) return;
190
+ let r = n.currentTarget.getBoundingClientRect(), i = V === "y" ? r.top + r.height / 2 : r.left + r.width / 2;
191
+ y(e.id, (V === "y" ? n.clientY : n.clientX) < i ? "before" : "after");
192
+ },
193
+ onDragEnd: () => {
194
+ B(!1), T();
195
+ },
196
+ children: [
197
+ t && /* @__PURE__ */ b("div", {
198
+ className: w.resizeHandle,
199
+ "data-resize-handle": !0,
200
+ title: "Drag to resize",
201
+ "aria-hidden": "true",
202
+ onPointerDown: (t) => {
203
+ t.preventDefault(), t.stopPropagation(), t.currentTarget.setPointerCapture?.(t.pointerId), P(e.size ?? c);
204
+ },
205
+ onPointerMove: (e) => {
206
+ if (!N || !R.current) return;
207
+ let t = R.current.parentElement;
208
+ if (!t) return;
209
+ let n = parseFloat(getComputedStyle(t).columnGap) || 0, r = (t.getBoundingClientRect().width - 5 * n) / 6, i = O((e.clientX - R.current.getBoundingClientRect().left + n) / (r + n));
210
+ i !== N && P(i);
211
+ },
212
+ onPointerUp: () => {
213
+ N && N !== (e.size ?? c) && M(e.id, N), P(null);
214
+ },
215
+ onPointerCancel: () => P(null)
216
+ }),
217
+ t && /* @__PURE__ */ b("div", {
218
+ className: w.dragHandle,
219
+ "data-drag-handle": !0,
220
+ title: "Drag to reorder",
221
+ "aria-hidden": "true",
222
+ onPointerDown: () => B(!0)
223
+ }),
224
+ k && /* @__PURE__ */ b("button", {
225
+ className: `${w.connectOverlay} ${w.selectOverlay}`,
226
+ onClick: (t) => {
227
+ t.stopPropagation(), j(e.id);
228
+ },
229
+ "aria-label": `Select ${e.title}`,
230
+ "aria-pressed": A,
231
+ children: /* @__PURE__ */ b("span", {
232
+ className: w.selectMark,
233
+ "aria-hidden": "true",
234
+ children: A ? "✓" : ""
235
+ })
236
+ }),
237
+ U && /* @__PURE__ */ b("button", {
238
+ className: `${w.connectOverlay} ${m ? w.connectOverlayConnected : ""}`,
239
+ onClick: (t) => {
240
+ t.stopPropagation(), g(e.id);
241
+ },
242
+ "aria-label": m ? `Disconnect from ${e.title}` : `Connect to ${e.title}`
243
+ }),
244
+ (t || I) && /* @__PURE__ */ b("button", {
245
+ className: `${w.detailsBtn} ${I ? w.detailsBtnFilled : ""}`,
246
+ onClick: (t) => {
247
+ t.stopPropagation(), ie(e.id);
248
+ },
249
+ "aria-label": `Details of ${e.title}`,
250
+ title: I ? "Details" : "Add details",
251
+ children: /* @__PURE__ */ b(re, {})
252
+ }),
253
+ t && /* @__PURE__ */ b("button", {
254
+ className: w.sizeBtn,
255
+ onClick: (t) => {
256
+ t.stopPropagation(), M(e.id, u[(u.indexOf(F) + 1) % u.length]);
257
+ },
258
+ "aria-label": `Size of ${e.title}: ${D[F]}`,
259
+ title: "Size: click to change, or drag the right edge",
260
+ children: E[F]
261
+ }),
262
+ t && /* @__PURE__ */ b("button", {
263
+ className: w.deleteBtn,
264
+ onClick: (t) => {
265
+ t.stopPropagation(), a(e.id);
266
+ },
267
+ "aria-label": `Delete ${e.title}`,
268
+ children: /* @__PURE__ */ b(S, {})
269
+ }),
270
+ t && /* @__PURE__ */ b("button", {
271
+ className: `${w.connectBtn} ${H ? w.connectBtnActive : ""}`,
272
+ onClick: (t) => {
273
+ t.stopPropagation(), h(e.id);
274
+ },
275
+ "aria-label": H ? "Cancel connection" : `Connect from ${e.title}`,
276
+ title: H ? "Cancel" : "Connect to another block",
277
+ children: /* @__PURE__ */ b(C, {})
278
+ }),
279
+ /* @__PURE__ */ x("div", {
280
+ className: w.header,
281
+ children: [e.icon && /* @__PURE__ */ b("span", {
282
+ className: w.icon,
283
+ children: e.icon
284
+ }), /* @__PURE__ */ x("div", {
285
+ className: w.headerText,
286
+ children: [/* @__PURE__ */ b("h2", {
287
+ className: `${w.title} ${t ? w.editable : ""}`,
288
+ "data-text": !0,
289
+ contentEditable: t || void 0,
290
+ suppressContentEditableWarning: !0,
291
+ onKeyDown: t ? (e) => {
292
+ e.key === "Enter" && (e.preventDefault(), e.currentTarget.blur());
293
+ } : void 0,
294
+ onBlur: t ? (t) => r(e.id, t.currentTarget.textContent ?? "") : void 0,
295
+ children: e.title
296
+ }, `title-${t}`), (e.description || t) && /* @__PURE__ */ b("p", {
297
+ className: `${w.description} ${t ? w.editable : ""}`,
298
+ "data-text": !0,
299
+ contentEditable: t || void 0,
300
+ suppressContentEditableWarning: !0,
301
+ "data-placeholder": "Description",
302
+ onBlur: t ? (t) => i(e.id, t.currentTarget.textContent ?? "") : void 0,
303
+ children: e.description
304
+ }, `desc-${t}`)]
305
+ })]
306
+ }),
307
+ L && /* @__PURE__ */ x("button", {
308
+ className: w.inside,
309
+ "aria-label": `Zoom into ${e.title}`,
310
+ children: [ae, " more inside"]
311
+ }),
312
+ !L && t && /* @__PURE__ */ x("button", {
313
+ className: `${w.inside} ${w.addInside}`,
314
+ onClick: (t) => {
315
+ t.stopPropagation(), R.current && l(e, K());
316
+ },
317
+ "aria-label": `Add child to ${e.title}`,
318
+ children: [/* @__PURE__ */ b(ne, { size: 11 }), " add inside"]
319
+ })
320
+ ]
321
+ });
322
+ }
323
+ // src/geometry.ts
324
+ var k = 2;
325
+ function A(e, t, n, r) {
326
+ return e === "right" && t === "left" ? r.x - n.x : e === "left" && t === "right" ? n.x - r.x : e === "bottom" && t === "top" ? r.y - n.y : e === "top" && t === "bottom" ? n.y - r.y : null;
327
+ }
328
+ function j(e, t, n) {
329
+ switch (t) {
330
+ case "right": return {
331
+ x: e.x + n,
332
+ y: e.y
333
+ };
334
+ case "left": return {
335
+ x: e.x - n,
336
+ y: e.y
337
+ };
338
+ case "bottom": return {
339
+ x: e.x,
340
+ y: e.y + n
341
+ };
342
+ case "top": return {
343
+ x: e.x,
344
+ y: e.y - n
345
+ };
346
+ }
347
+ }
348
+ function M(e, t, n) {
349
+ if (t <= 1) return 0;
350
+ let r = Math.min(16, n * .6 / t);
351
+ return (e - (t - 1) / 2) * r;
352
+ }
353
+ function N(e, t, n) {
354
+ let r = (e.left + e.right) / 2, i = (e.top + e.bottom) / 2, a = (t.left + t.right) / 2, o = (t.top + t.bottom) / 2, s = a - r, c = o - i;
355
+ if (Math.abs(c) < Math.min(e.height, t.height) * .5) {
356
+ let r = s >= 0;
357
+ return n.some((n) => {
358
+ let a = (n.left + n.right) / 2, o = r ? a > e.right - 4 && a < t.left + 4 : a < e.left + 4 && a > t.right - 4, s = Math.abs((n.top + n.bottom) / 2 - i) < (e.height + n.height) * .4;
359
+ return o && s;
360
+ }) ? {
361
+ exitEdge: "bottom",
362
+ entryEdge: "bottom"
363
+ } : {
364
+ exitEdge: r ? "right" : "left",
365
+ entryEdge: r ? "left" : "right"
366
+ };
367
+ }
368
+ let l = c > 0;
369
+ return {
370
+ exitEdge: l ? "bottom" : "top",
371
+ entryEdge: l ? "top" : "bottom"
372
+ };
373
+ }
374
+ function P(e, t, n, r, i) {
375
+ let a = (e.left + e.right) / 2, o = (e.top + e.bottom) / 2;
376
+ switch (t) {
377
+ case "right": return {
378
+ x: e.right - i.x,
379
+ y: o - i.y + M(n, r, e.height)
380
+ };
381
+ case "left": return {
382
+ x: e.left - i.x,
383
+ y: o - i.y + M(n, r, e.height)
384
+ };
385
+ case "bottom": return {
386
+ x: a - i.x + M(n, r, e.width),
387
+ y: e.bottom - i.y
388
+ };
389
+ case "top": return {
390
+ x: a - i.x + M(n, r, e.width),
391
+ y: e.top - i.y
392
+ };
393
+ }
394
+ }
395
+ function F(e, t, n, r, i, a, o) {
396
+ if (r === "bottom" && i === "bottom") {
397
+ let e = Math.max(a.y, o.y) + 32;
398
+ return [{
399
+ x: a.x,
400
+ y: e
401
+ }, {
402
+ x: o.x,
403
+ y: e
404
+ }];
405
+ }
406
+ if (r === "right" || r === "left") {
407
+ let n = (t.left + t.right) / 2, i = (e.left + e.right) / 2, s = r === "right" ? 1 : -1, c = Math.min(Math.abs(n - i) * .4, 80);
408
+ return [{
409
+ x: a.x + s * c,
410
+ y: a.y
411
+ }, {
412
+ x: o.x - s * c,
413
+ y: o.y
414
+ }];
415
+ }
416
+ let s = (a.y + o.y) / 2;
417
+ return [{
418
+ x: a.x,
419
+ y: s
420
+ }, {
421
+ x: o.x,
422
+ y: s
423
+ }];
424
+ }
425
+ function I(e, t, n, r) {
426
+ return {
427
+ x: (e.x + 3 * t.x + 3 * n.x + r.x) / 8,
428
+ y: (e.y + 3 * t.y + 3 * n.y + r.y) / 8
429
+ };
430
+ }
431
+ function ae(e, t, n) {
432
+ let r = {
433
+ x: n.left,
434
+ y: n.top
435
+ }, i = [];
436
+ for (let n of e) {
437
+ let { fromId: e, toId: r } = n, a = t.get(e), o = t.get(r);
438
+ if (!a || !o) continue;
439
+ let s = [];
440
+ for (let [n, i] of t) n !== e && n !== r && s.push(i);
441
+ i.push({
442
+ ...n,
443
+ fromRect: a,
444
+ toRect: o,
445
+ ...N(a, o, s)
446
+ });
447
+ }
448
+ let a = /* @__PURE__ */ new Map(), o = (e, t, n) => {
449
+ let r = a.get(e);
450
+ r || a.set(e, r = []), r.push({
451
+ ci: t,
452
+ role: n
453
+ });
454
+ };
455
+ return i.forEach((e, t) => {
456
+ o(`${e.fromId}-${e.exitEdge}`, t, "exit"), o(`${e.toId}-${e.entryEdge}`, t, "entry");
457
+ }), i.map((e, t) => {
458
+ let n = a.get(`${e.fromId}-${e.exitEdge}`), i = a.get(`${e.toId}-${e.entryEdge}`), o = n.findIndex((e) => e.ci === t && e.role === "exit"), s = i.findIndex((e) => e.ci === t && e.role === "entry"), c = P(e.fromRect, e.exitEdge, o, n.length, r), l = P(e.toRect, e.entryEdge, s, i.length, r), u = e.headAtStart ? 14 : 0, d = e.headAtEnd ? 14 : 0, f = A(e.exitEdge, e.entryEdge, c, l);
459
+ if (f !== null && u + d > f - k) {
460
+ let e = Math.max(0, f - k) / (u + d);
461
+ u *= e, d *= e;
462
+ }
463
+ let p = j(c, e.exitEdge, u), m = j(l, e.entryEdge, d), [h, g] = F(e.fromRect, e.toRect, r, e.exitEdge, e.entryEdge, p, m);
464
+ return {
465
+ key: e.key,
466
+ d: `M ${p.x} ${p.y} C ${h.x} ${h.y}, ${g.x} ${g.y}, ${m.x} ${m.y}`,
467
+ mid: I(p, h, g, m),
468
+ vertical: e.exitEdge === "top" && e.entryEdge === "bottom" || e.exitEdge === "bottom" && e.entryEdge === "top"
469
+ };
470
+ });
471
+ }
472
+ var L = {
473
+ popover: "_popover_1b6n3_1",
474
+ close: "_close_1b6n3_19",
475
+ row: "_row_1b6n3_39",
476
+ ends: "_ends_1b6n3_45",
477
+ endsArrow: "_endsArrow_1b6n3_51",
478
+ label: "_label_1b6n3_55",
479
+ actions: "_actions_1b6n3_71",
480
+ directions: "_directions_1b6n3_78",
481
+ btn: "_btn_1b6n3_83",
482
+ btnActive: "_btnActive_1b6n3_105",
483
+ danger: "_danger_1b6n3_112"
484
+ }, R = [
485
+ {
486
+ value: "forward",
487
+ symbol: "→",
488
+ label: "One way"
489
+ },
490
+ {
491
+ value: "both",
492
+ symbol: "↔",
493
+ label: "Both ways"
494
+ },
495
+ {
496
+ value: "none",
497
+ symbol: "—",
498
+ label: "No direction"
499
+ }
500
+ ];
501
+ function z({ links: e, x: t, y: r, titleOf: i, onUpdate: a, onRemove: s, onClose: c }) {
502
+ let l = o(null);
503
+ return n(() => {
504
+ function e(e) {
505
+ l.current && !l.current.contains(e.target) && c();
506
+ }
507
+ function t(e) {
508
+ e.key === "Escape" && c();
509
+ }
510
+ return document.addEventListener("pointerdown", e), window.addEventListener("keydown", t), () => {
511
+ document.removeEventListener("pointerdown", e), window.removeEventListener("keydown", t);
512
+ };
513
+ }, [c]), /* @__PURE__ */ x("div", {
514
+ ref: l,
515
+ className: L.popover,
516
+ style: {
517
+ left: t,
518
+ top: r
519
+ },
520
+ role: "dialog",
521
+ "aria-label": e.length === 1 ? "Link" : `${e.length} links`,
522
+ onClick: (e) => e.stopPropagation(),
523
+ children: [/* @__PURE__ */ b("button", {
524
+ className: L.close,
525
+ onClick: c,
526
+ "aria-label": "Close",
527
+ children: /* @__PURE__ */ b(S, {})
528
+ }), e.map((e, t) => /* @__PURE__ */ b(B, {
529
+ link: e,
530
+ titleOf: i,
531
+ onUpdate: (t) => a(e, t),
532
+ onRemove: () => s(e)
533
+ }, e.id ?? t))]
534
+ });
535
+ }
536
+ function B({ link: e, titleOf: t, onUpdate: r, onRemove: i }) {
537
+ let [a, o] = s(e.label ?? "");
538
+ n(() => o(e.label ?? ""), [e.label]);
539
+ let c = e.direction ?? "forward";
540
+ function l() {
541
+ let t = a.trim();
542
+ t !== (e.label ?? "") && r({ label: t || void 0 });
543
+ }
544
+ return /* @__PURE__ */ x("div", {
545
+ className: L.row,
546
+ children: [
547
+ /* @__PURE__ */ x("div", {
548
+ className: L.ends,
549
+ children: [
550
+ t(e.from),
551
+ " ",
552
+ /* @__PURE__ */ b("span", {
553
+ className: L.endsArrow,
554
+ children: R.find((e) => e.value === c).symbol
555
+ }),
556
+ " ",
557
+ t(e.to)
558
+ ]
559
+ }),
560
+ /* @__PURE__ */ b("input", {
561
+ className: L.label,
562
+ value: a,
563
+ placeholder: "Label",
564
+ "aria-label": "Label",
565
+ onChange: (e) => o(e.target.value),
566
+ onBlur: l,
567
+ onKeyDown: (e) => {
568
+ e.key === "Enter" && (e.preventDefault(), l());
569
+ }
570
+ }),
571
+ /* @__PURE__ */ x("div", {
572
+ className: L.actions,
573
+ children: [
574
+ /* @__PURE__ */ b("div", {
575
+ className: L.directions,
576
+ role: "group",
577
+ "aria-label": "Direction",
578
+ children: R.map((e) => /* @__PURE__ */ b("button", {
579
+ className: `${L.btn} ${c === e.value ? L.btnActive : ""}`,
580
+ "aria-pressed": c === e.value,
581
+ "aria-label": e.label,
582
+ title: e.label,
583
+ onClick: () => r({ direction: e.value === "forward" ? void 0 : e.value }),
584
+ children: e.symbol
585
+ }, e.value))
586
+ }),
587
+ /* @__PURE__ */ b("button", {
588
+ className: L.btn,
589
+ onClick: () => r({
590
+ from: e.to,
591
+ to: e.from
592
+ }),
593
+ "aria-label": "Reverse",
594
+ title: "Reverse",
595
+ disabled: c !== "forward",
596
+ children: "⇄"
597
+ }),
598
+ /* @__PURE__ */ b("button", {
599
+ className: `${L.btn} ${L.danger}`,
600
+ onClick: i,
601
+ "aria-label": "Delete link",
602
+ title: "Delete link",
603
+ children: "Delete"
604
+ })
605
+ ]
606
+ })
607
+ ]
608
+ });
609
+ }
610
+ // src/markdown.tsx
611
+ var V = /^(https?:\/\/|mailto:)/i;
612
+ function H(e) {
613
+ let t = e.replace(/\r\n?/g, "\n").split("\n"), n = [], r = 0;
614
+ for (; r < t.length;) {
615
+ let e = t[r];
616
+ if (e.trim() === "") {
617
+ r++;
618
+ continue;
619
+ }
620
+ if (e.startsWith("```")) {
621
+ let e = [];
622
+ for (r++; r < t.length && !t[r].startsWith("```");) e.push(t[r++]);
623
+ r++, n.push({
624
+ kind: "code",
625
+ text: e.join("\n")
626
+ });
627
+ continue;
628
+ }
629
+ let i = /^(#{1,3})\s+(.*)$/.exec(e);
630
+ if (i) {
631
+ n.push({
632
+ kind: "heading",
633
+ level: i[1].length,
634
+ text: i[2]
635
+ }), r++;
636
+ continue;
637
+ }
638
+ let a = /^\s*([-*]|\d+\.)\s+/, o = a.exec(e);
639
+ if (o) {
640
+ let e = /\d/.test(o[1]), i = [];
641
+ for (; r < t.length && a.test(t[r]);) i.push(t[r++].replace(a, ""));
642
+ n.push({
643
+ kind: "list",
644
+ ordered: e,
645
+ items: i
646
+ });
647
+ continue;
648
+ }
649
+ let s = [];
650
+ for (; r < t.length && t[r].trim() !== "" && !t[r].startsWith("```") && !/^#{1,3}\s/.test(t[r]) && !a.test(t[r]);) s.push(t[r++]);
651
+ n.push({
652
+ kind: "paragraph",
653
+ text: s.join("\n")
654
+ });
655
+ }
656
+ return n;
657
+ }
658
+ var U = /`([^`]+)`|\*\*([^*]+)\*\*|\*([^*]+)\*|\[([^\]]+)\]\(([^)\s]+)\)|\n/g;
659
+ function W(t) {
660
+ let n = [], r = 0, i = 0;
661
+ for (let a of t.matchAll(U)) {
662
+ a.index > r && n.push(t.slice(r, a.index));
663
+ let [o, s, c, l, u, d] = a;
664
+ s === void 0 ? c === void 0 ? l === void 0 ? u === void 0 ? o === "\n" && n.push(/* @__PURE__ */ b("br", {}, i++)) : n.push(V.test(d) ? /* @__PURE__ */ b("a", {
665
+ href: d,
666
+ target: "_blank",
667
+ rel: "noopener noreferrer",
668
+ children: W(u)
669
+ }, i++) : /* @__PURE__ */ b(e, { children: W(u) }, i++)) : n.push(/* @__PURE__ */ b("em", { children: W(l) }, i++)) : n.push(/* @__PURE__ */ b("strong", { children: W(c) }, i++)) : n.push(/* @__PURE__ */ b("code", { children: s }, i++)), r = a.index + o.length;
670
+ }
671
+ return r < t.length && n.push(t.slice(r)), n;
672
+ }
673
+ function G({ source: e, className: t }) {
674
+ return /* @__PURE__ */ b("div", {
675
+ className: t,
676
+ children: H(e).map((e, t) => {
677
+ switch (e.kind) {
678
+ case "heading": {
679
+ let n = [
680
+ "h3",
681
+ "h4",
682
+ "h5"
683
+ ][e.level - 1];
684
+ return /* @__PURE__ */ b(n, { children: W(e.text) }, t);
685
+ }
686
+ case "paragraph": return /* @__PURE__ */ b("p", { children: W(e.text) }, t);
687
+ case "list": {
688
+ let n = e.ordered ? "ol" : "ul";
689
+ return /* @__PURE__ */ b(n, { children: e.items.map((e, t) => /* @__PURE__ */ b("li", { children: W(e) }, t)) }, t);
690
+ }
691
+ case "code": return /* @__PURE__ */ b("pre", { children: /* @__PURE__ */ b("code", { children: e.text }) }, t);
692
+ }
693
+ })
694
+ });
695
+ }
696
+ var K = {
697
+ panel: "_panel_24xow_1",
698
+ slideIn: "_slideIn_24xow_1",
699
+ close: "_close_24xow_24",
700
+ head: "_head_24xow_44",
701
+ icon: "_icon_24xow_52",
702
+ title: "_title_24xow_57",
703
+ description: "_description_24xow_63",
704
+ editor: "_editor_24xow_70",
705
+ body: "_body_24xow_88",
706
+ empty: "_empty_24xow_124"
707
+ };
708
+ // src/DetailsPanel.tsx
709
+ function oe({ block: e, editing: t, onChange: r, onClose: i }) {
710
+ let [a, o] = s(e.details ?? "");
711
+ n(() => o(e.details ?? ""), [e.id, e.details]), n(() => {
712
+ function e(e) {
713
+ e.key === "Escape" && !(e.target instanceof HTMLTextAreaElement) && i();
714
+ }
715
+ return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
716
+ }, [i]);
717
+ function c() {
718
+ a !== (e.details ?? "") && r(a);
719
+ }
720
+ return /* @__PURE__ */ x("aside", {
721
+ className: K.panel,
722
+ "aria-label": `Details: ${e.title}`,
723
+ children: [
724
+ /* @__PURE__ */ b("button", {
725
+ className: K.close,
726
+ onClick: i,
727
+ "aria-label": "Close details",
728
+ children: /* @__PURE__ */ b(S, {})
729
+ }),
730
+ /* @__PURE__ */ x("div", {
731
+ className: K.head,
732
+ children: [e.icon && /* @__PURE__ */ b("span", {
733
+ className: K.icon,
734
+ children: e.icon
735
+ }), /* @__PURE__ */ x("div", { children: [/* @__PURE__ */ b("h2", {
736
+ className: K.title,
737
+ children: e.title
738
+ }), e.description && /* @__PURE__ */ b("p", {
739
+ className: K.description,
740
+ children: e.description
741
+ })] })]
742
+ }),
743
+ t ? /* @__PURE__ */ x(y, { children: [/* @__PURE__ */ b("textarea", {
744
+ className: K.editor,
745
+ value: a,
746
+ placeholder: "Details in Markdown: **bold**, *italic*, `code`, lists, [links](https://…)",
747
+ "aria-label": "Details (Markdown)",
748
+ onChange: (e) => o(e.target.value),
749
+ onBlur: c
750
+ }), a.trim() && /* @__PURE__ */ b(G, {
751
+ source: a,
752
+ className: K.body
753
+ })] }) : e.details?.trim() ? /* @__PURE__ */ b(G, {
754
+ source: e.details,
755
+ className: K.body
756
+ }) : /* @__PURE__ */ b("p", {
757
+ className: K.empty,
758
+ children: "No details"
759
+ })
760
+ ]
761
+ });
762
+ }
763
+ var q = {
764
+ viewer: "_viewer_1knu3_1",
765
+ breadcrumb: "_breadcrumb_1knu3_10",
766
+ crumbItem: "_crumbItem_1knu3_20",
767
+ crumbSep: "_crumbSep_1knu3_26",
768
+ crumb: "_crumb_1knu3_20",
769
+ crumbActive: "_crumbActive_1knu3_51",
770
+ backdrop: "_backdrop_1knu3_54",
771
+ slide: "_slide_1knu3_62",
772
+ slideCard: "_slideCard_1knu3_73",
773
+ slideHeader: "_slideHeader_1knu3_83",
774
+ headerDetailsBtn: "_headerDetailsBtn_1knu3_91",
775
+ slideHeaderTop: "_slideHeaderTop_1knu3_112",
776
+ slideIcon: "_slideIcon_1knu3_116",
777
+ slideHeaderText: "_slideHeaderText_1knu3_123",
778
+ slideTitle: "_slideTitle_1knu3_128",
779
+ slideDescription: "_slideDescription_1knu3_136",
780
+ gridArea: "_gridArea_1knu3_144",
781
+ arrowSvg: "_arrowSvg_1knu3_153",
782
+ arrow: "_arrow_1knu3_153",
783
+ arrowSvgEditing: "_arrowSvgEditing_1knu3_171",
784
+ arrowHit: "_arrowHit_1knu3_171",
785
+ arrowLabel: "_arrowLabel_1knu3_184",
786
+ arrowLabelOpen: "_arrowLabelOpen_1knu3_189",
787
+ arrowIndirect: "_arrowIndirect_1knu3_193",
788
+ arrowHead: "_arrowHead_1knu3_197",
789
+ empty: "_empty_1knu3_211",
790
+ gridAreaNested: "_gridAreaNested_1knu3_218",
791
+ grid: "_grid_1knu3_144",
792
+ levelTools: "_levelTools_1knu3_243",
793
+ groupBtn: "_groupBtn_1knu3_249",
794
+ groupBtnActive: "_groupBtnActive_1knu3_266",
795
+ fullHint: "_fullHint_1knu3_273",
796
+ addBlock: "_addBlock_1knu3_280",
797
+ linkBar: "_linkBar_1knu3_301",
798
+ linkBarCancel: "_linkBarCancel_1knu3_319"
799
+ };
800
+ // src/Viewer.tsx
801
+ function se(e) {
802
+ let t = [...new Set(e.links.map((e) => e.label).filter((e) => !!e))];
803
+ return e.links.length > 2 ? `${e.links.length} links` : t.length ? t.join(", ") : void 0;
804
+ }
805
+ function J(e) {
806
+ return [e.from, e.to].sort().join("|");
807
+ }
808
+ function ce(e) {
809
+ return {
810
+ left: e.left,
811
+ top: e.top,
812
+ right: e.right,
813
+ bottom: e.bottom,
814
+ width: e.width,
815
+ height: e.height
816
+ };
817
+ }
818
+ function le({ document: e, editing: c, actions: u }) {
819
+ let d = o(null), f = o(null), m = o(!1), g = o(!1), _ = o(/* @__PURE__ */ new Map()), ee = o(null), v = r(), [y, S] = s(null), [C, w] = s(null), [T, E] = s(null), [D, O] = s(null), k = t(() => O(null), []), [A, j] = s(null), M = t(() => j(null), []), [N, P] = s(null), [F, I] = s([]), [L, R] = s([]), [B, V] = s(0), [H, U] = s(0), [W, G] = s(0), K = a(() => p(e), [e]), le = A ? K.get(A)?.block : void 0, Y = a(() => {
820
+ let e = L.findIndex((e) => !K.has(e.id));
821
+ return e === -1 ? L : L.slice(0, e);
822
+ }, [L, K]);
823
+ n(() => {
824
+ Y !== L && R(Y);
825
+ }, [Y, L]);
826
+ let X = Y.length ? Y[Y.length - 1].id : null, Z = X === null ? void 0 : K.get(X)?.block, Q = a(() => h(e, X, K).slice(0, l), [
827
+ e,
828
+ X,
829
+ K
830
+ ]), $ = a(() => te(e, X, K), [
831
+ e,
832
+ X,
833
+ K
834
+ ]), ue = X !== null, de = c && Q.length < l;
835
+ i(() => {
836
+ let e = d.current;
837
+ if (!e) return;
838
+ if (m.current) {
839
+ m.current = !1, e.style.transition = "none", e.style.transform = "", e.style.transformOrigin = "", e.getBoundingClientRect(), e.style.transition = "";
840
+ return;
841
+ }
842
+ let t = f.current;
843
+ if (f.current = null, !t) return;
844
+ let n = e.getBoundingClientRect();
845
+ if (!n.width || !n.height) return;
846
+ let r = t.width / n.width, i = t.height / n.height, a = t.left + t.width / 2 - (n.left + n.width / 2), o = t.top + t.height / 2 - (n.top + n.height / 2);
847
+ e.style.transition = "none", e.style.transformOrigin = "center center", e.style.transform = `translate(${a}px, ${o}px) scale(${r}, ${i})`, e.getBoundingClientRect(), requestAnimationFrame(() => {
848
+ e.style.transition = "transform 0.5s cubic-bezier(0.22, 1, 0.36, 1)", e.style.transform = "", e.addEventListener("transitionend", () => {
849
+ e.style.transition = "", e.style.transformOrigin = "", G((e) => e + 1);
850
+ }, { once: !0 });
851
+ });
852
+ }, [B]), n(() => {
853
+ c || (S(null), O(null), E(null));
854
+ }, [c]), n(() => E(null), [X]), n(() => {
855
+ D && !$.some((e) => J(e) === D) && O(null);
856
+ }, [$, D]), n(() => {
857
+ function e(e) {
858
+ e.key === "Escape" && (S(null), E(null));
859
+ }
860
+ return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
861
+ }, []), n(() => {
862
+ let e = d.current, t = !(!e || e.style.transform === "" && e.style.transition === "");
863
+ function n() {
864
+ let e = ee.current;
865
+ if (!e || !$.length) {
866
+ I([]);
867
+ return;
868
+ }
869
+ let t = /* @__PURE__ */ new Map();
870
+ for (let [e, n] of _.current) t.set(e, ce(n.getBoundingClientRect()));
871
+ I(ae($.map((e) => ({
872
+ key: e.key,
873
+ fromId: e.from,
874
+ toId: e.to,
875
+ headAtStart: e.direction === "both",
876
+ headAtEnd: e.direction !== "none"
877
+ })), t, ce(e.getBoundingClientRect())));
878
+ }
879
+ if (t) {
880
+ I([]);
881
+ let e = setTimeout(n, 1500);
882
+ return () => clearTimeout(e);
883
+ }
884
+ n();
885
+ }, [
886
+ Q,
887
+ $,
888
+ B,
889
+ c,
890
+ H,
891
+ W
892
+ ]);
893
+ let fe = o(null);
894
+ n(() => {
895
+ let e = ee.current;
896
+ if (!e || typeof ResizeObserver > "u") return;
897
+ let t = new ResizeObserver(() => U((e) => e + 1));
898
+ fe.current = t, t.observe(e);
899
+ for (let e of _.current.values()) t.observe(e);
900
+ return () => {
901
+ t.disconnect(), fe.current = null;
902
+ };
903
+ }, []);
904
+ let pe = t((e, t) => {
905
+ let n = _.current.get(e);
906
+ n && fe.current?.unobserve(n), t ? (_.current.set(e, t), fe.current?.observe(t)) : _.current.delete(e);
907
+ }, []), me = a(() => {
908
+ let e = new Map($.map((e) => [e.key, e]));
909
+ return F.flatMap((t) => {
910
+ let n = e.get(t.key);
911
+ return n ? [{
912
+ ...t,
913
+ link: n,
914
+ label: se(n)
915
+ }] : [];
916
+ });
917
+ }, [F, $]), he = t((e) => {
918
+ if (!y || e === y) return !1;
919
+ let t = K.get(y), n = K.get(e);
920
+ return !t || !n ? !1 : !t.path.includes(e) && !n.path.includes(y);
921
+ }, [y, K]), ge = y ? K.get(y)?.block : void 0, _e = a(() => y ? new Set((e.links ?? []).filter((e) => e.from === y).map((e) => e.to)) : /* @__PURE__ */ new Set(), [e.links, y]);
922
+ function ve(e, t) {
923
+ f.current = t, R((n) => [...n, {
924
+ id: e.id,
925
+ cardRect: t
926
+ }]), V((e) => e + 1);
927
+ }
928
+ function ye(e, t) {
929
+ u.add(e.id), ve(e, t);
930
+ }
931
+ function be(e) {
932
+ if (e >= Y.length) return;
933
+ let t = Y[Y.length - 1]?.cardRect, n = d.current;
934
+ if (t && n) {
935
+ let r = n.getBoundingClientRect(), i = t.width / r.width, a = t.height / r.height, o = t.left + t.width / 2 - (r.left + r.width / 2), s = t.top + t.height / 2 - (r.top + r.height / 2);
936
+ n.style.transition = "transform 0.35s cubic-bezier(0.4, 0, 0.8, 0)", n.style.transformOrigin = "center center", n.style.transform = `translate(${o}px, ${s}px) scale(${i}, ${a})`, g.current = !0, setTimeout(() => {
937
+ g.current = !1, m.current = !0, R((t) => t.slice(0, e)), V((e) => e + 1);
938
+ }, 370);
939
+ } else R((t) => t.slice(0, e)), V((e) => e + 1);
940
+ }
941
+ function xe() {
942
+ w(null), P(null);
943
+ }
944
+ function Se() {
945
+ if (C && N && N.id !== C) {
946
+ let e = Q.map((e) => e.id).filter((e) => e !== C).indexOf(N.id) + +(N.position === "after");
947
+ e !== Q.findIndex((e) => e.id === C) && u.move(C, X, e);
948
+ }
949
+ xe();
950
+ }
951
+ let Ce = c ? {
952
+ onDragOver: (e) => {
953
+ C && e.preventDefault();
954
+ },
955
+ onDrop: (e) => {
956
+ e.preventDefault(), Se();
957
+ }
958
+ } : {};
959
+ function we(e) {
960
+ y && (u.toggleLink(y, e), S(null));
961
+ }
962
+ let Te = [{ label: e.title }, ...Y.map((e) => ({ label: K.get(e.id)?.block.title ?? "" }))], Ee = (e) => /* @__PURE__ */ b(ie, {
963
+ block: e,
964
+ editing: c,
965
+ onRename: u.rename,
966
+ onDescribe: u.describe,
967
+ onDelete: u.remove,
968
+ onAddChild: ye,
969
+ onDrillIn: ve,
970
+ connectingFrom: y,
971
+ canLinkTo: he(e.id),
972
+ isConnected: _e.has(e.id),
973
+ onStartConnect: (e) => S(e === y ? null : e),
974
+ onConnectTarget: we,
975
+ onRegisterEl: pe,
976
+ isDragged: C === e.id,
977
+ dropPosition: C && N?.id === e.id && N.id !== C ? N.position : null,
978
+ onDragStartBlock: w,
979
+ onDragOverBlock: (e, t) => {
980
+ C && (N?.id !== e || N.position !== t) && P({
981
+ id: e,
982
+ position: t
983
+ });
984
+ },
985
+ onDragEndBlock: xe,
986
+ onShowDetails: j,
987
+ selectable: T !== null,
988
+ selected: T?.includes(e.id) ?? !1,
989
+ onToggleSelect: (e) => E((t) => t && (t.includes(e) ? t.filter((t) => t !== e) : [...t, e])),
990
+ onResize: u.setSize
991
+ }, e.id), De = () => /* @__PURE__ */ b("button", {
992
+ className: q.addBlock,
993
+ onClick: () => u.add(X),
994
+ "aria-label": "Add block",
995
+ children: /* @__PURE__ */ b(ne, {})
996
+ });
997
+ return /* @__PURE__ */ x("div", {
998
+ className: q.viewer,
999
+ children: [
1000
+ ue && /* @__PURE__ */ b("nav", {
1001
+ className: q.breadcrumb,
1002
+ "aria-label": "Breadcrumb",
1003
+ onClick: (e) => {
1004
+ e.target.closest("button") || g.current || be(Y.length - 1);
1005
+ },
1006
+ children: Te.map((e, t) => /* @__PURE__ */ x("span", {
1007
+ className: q.crumbItem,
1008
+ children: [t > 0 && /* @__PURE__ */ b("span", {
1009
+ className: q.crumbSep,
1010
+ children: "/"
1011
+ }), /* @__PURE__ */ b("button", {
1012
+ className: `${q.crumb} ${t === Te.length - 1 ? q.crumbActive : ""}`,
1013
+ onClick: () => be(t),
1014
+ disabled: t === Te.length - 1,
1015
+ "aria-current": t === Te.length - 1 ? "location" : void 0,
1016
+ children: e.label
1017
+ })]
1018
+ }, t))
1019
+ }),
1020
+ T && /* @__PURE__ */ x("div", {
1021
+ className: q.linkBar,
1022
+ role: "status",
1023
+ children: [
1024
+ /* @__PURE__ */ x("span", { children: [
1025
+ "Select blocks to group: ",
1026
+ /* @__PURE__ */ b("strong", { children: T.length }),
1027
+ " selected"
1028
+ ] }),
1029
+ /* @__PURE__ */ b("button", {
1030
+ className: q.linkBarCancel,
1031
+ disabled: T.length < 2,
1032
+ onClick: () => {
1033
+ u.group(T), E(null);
1034
+ },
1035
+ children: "Group"
1036
+ }),
1037
+ /* @__PURE__ */ b("button", {
1038
+ className: q.linkBarCancel,
1039
+ onClick: () => E(null),
1040
+ children: "Cancel"
1041
+ })
1042
+ ]
1043
+ }),
1044
+ ge && /* @__PURE__ */ x("div", {
1045
+ className: q.linkBar,
1046
+ role: "status",
1047
+ children: [/* @__PURE__ */ x("span", { children: [
1048
+ "Linking from ",
1049
+ /* @__PURE__ */ b("strong", { children: ge.title }),
1050
+ ": click a block on any level"
1051
+ ] }), /* @__PURE__ */ b("button", {
1052
+ className: q.linkBarCancel,
1053
+ onClick: () => S(null),
1054
+ children: "Cancel"
1055
+ })]
1056
+ }),
1057
+ ue && /* @__PURE__ */ b("div", {
1058
+ className: q.backdrop,
1059
+ onClick: () => {
1060
+ g.current || be(Y.length - 1);
1061
+ },
1062
+ "aria-hidden": "true"
1063
+ }),
1064
+ /* @__PURE__ */ x("div", {
1065
+ ref: d,
1066
+ className: `${q.slide} ${ue ? q.slideCard : ""}`,
1067
+ children: [(() => {
1068
+ let t = Z ?? {
1069
+ title: e.title,
1070
+ description: e.description,
1071
+ icon: void 0
1072
+ };
1073
+ return /* @__PURE__ */ x("div", {
1074
+ className: `${q.slideHeader} ${Z ? "" : q.slideHeaderTop}`,
1075
+ children: [
1076
+ t.icon && /* @__PURE__ */ b("span", {
1077
+ className: q.slideIcon,
1078
+ children: t.icon
1079
+ }),
1080
+ /* @__PURE__ */ x("div", {
1081
+ className: q.slideHeaderText,
1082
+ children: [/* @__PURE__ */ b("h1", {
1083
+ className: q.slideTitle,
1084
+ children: t.title
1085
+ }), t.description && /* @__PURE__ */ b("p", {
1086
+ className: q.slideDescription,
1087
+ children: t.description
1088
+ })]
1089
+ }),
1090
+ Z && (c || Z.details?.trim()) && /* @__PURE__ */ x("button", {
1091
+ className: q.headerDetailsBtn,
1092
+ onClick: () => j(Z.id),
1093
+ "aria-label": `Details of ${Z.title}`,
1094
+ children: [
1095
+ /* @__PURE__ */ b(re, {}),
1096
+ " ",
1097
+ Z.details?.trim() ? "Details" : "Add details"
1098
+ ]
1099
+ })
1100
+ ]
1101
+ });
1102
+ })(), /* @__PURE__ */ x("div", {
1103
+ ref: ee,
1104
+ className: `${q.gridArea} ${ue ? q.gridAreaNested : ""}`,
1105
+ children: [
1106
+ c && Q.length >= 2 && /* @__PURE__ */ x("div", {
1107
+ className: q.levelTools,
1108
+ role: "group",
1109
+ "aria-label": "Level tools",
1110
+ children: [/* @__PURE__ */ b("button", {
1111
+ className: `${q.groupBtn} ${T ? q.groupBtnActive : ""}`,
1112
+ onClick: () => {
1113
+ S(null), E((e) => e ? null : []);
1114
+ },
1115
+ "aria-pressed": T !== null,
1116
+ children: "Group blocks"
1117
+ }), Q.length >= l && !T && /* @__PURE__ */ x("span", {
1118
+ className: q.fullHint,
1119
+ children: [
1120
+ Q.length,
1121
+ " of ",
1122
+ l,
1123
+ ": group blocks to add more"
1124
+ ]
1125
+ })]
1126
+ }),
1127
+ /* @__PURE__ */ x("div", {
1128
+ className: q.grid,
1129
+ ...Ce,
1130
+ children: [Q.map((e) => Ee(e)), de && De()]
1131
+ }),
1132
+ Q.length === 0 && !c && /* @__PURE__ */ b("p", {
1133
+ className: q.empty,
1134
+ children: "Nothing here yet"
1135
+ }),
1136
+ me.length > 0 && /* @__PURE__ */ x("svg", {
1137
+ className: `${q.arrowSvg} ${c ? q.arrowSvgEditing : ""}`,
1138
+ "aria-hidden": !c || void 0,
1139
+ children: [/* @__PURE__ */ b("defs", { children: /* @__PURE__ */ b("marker", {
1140
+ id: v,
1141
+ markerWidth: 10,
1142
+ markerHeight: "8",
1143
+ refX: "0",
1144
+ refY: "4",
1145
+ orient: "auto-start-reverse",
1146
+ markerUnits: "userSpaceOnUse",
1147
+ children: /* @__PURE__ */ b("path", {
1148
+ d: "M 0 0 L 10 4 L 0 8 Z",
1149
+ className: q.arrowHead
1150
+ })
1151
+ }) }), me.map((e) => /* @__PURE__ */ x("g", {
1152
+ "data-link": e.key,
1153
+ children: [
1154
+ c && /* @__PURE__ */ b("path", {
1155
+ d: e.d,
1156
+ className: q.arrowHit,
1157
+ role: "button",
1158
+ "aria-label": `Edit link ${K.get(e.link.from)?.block.title ?? e.link.from} – ${K.get(e.link.to)?.block.title ?? e.link.to}`,
1159
+ onClick: (t) => {
1160
+ t.stopPropagation(), O(J(e.link));
1161
+ }
1162
+ }),
1163
+ /* @__PURE__ */ b("path", {
1164
+ d: e.d,
1165
+ className: `${q.arrow} ${e.link.direct ? "" : q.arrowIndirect}`,
1166
+ markerEnd: e.link.direction === "none" ? void 0 : `url(#${v})`,
1167
+ markerStart: e.link.direction === "both" ? `url(#${v})` : void 0
1168
+ }),
1169
+ e.label && /* @__PURE__ */ b("text", {
1170
+ x: e.vertical ? e.mid.x + 8 : e.mid.x,
1171
+ y: e.mid.y,
1172
+ className: `${q.arrowLabel} ${D === J(e.link) ? q.arrowLabelOpen : ""}`,
1173
+ onClick: c ? (t) => {
1174
+ t.stopPropagation(), O(J(e.link));
1175
+ } : void 0,
1176
+ textAnchor: e.vertical ? "start" : "middle",
1177
+ dominantBaseline: "middle",
1178
+ children: e.label
1179
+ })
1180
+ ]
1181
+ }, e.key))]
1182
+ }),
1183
+ (() => {
1184
+ let e = c && me.find((e) => J(e.link) === D);
1185
+ return e ? /* @__PURE__ */ b(z, {
1186
+ links: e.link.links,
1187
+ x: e.mid.x,
1188
+ y: e.mid.y,
1189
+ titleOf: (e) => K.get(e)?.block.title ?? e,
1190
+ onUpdate: u.updateLink,
1191
+ onRemove: u.removeLink,
1192
+ onClose: k
1193
+ }) : null;
1194
+ })()
1195
+ ]
1196
+ })]
1197
+ }),
1198
+ le && /* @__PURE__ */ b(oe, {
1199
+ block: le,
1200
+ editing: c,
1201
+ onChange: (e) => u.setDetails(le.id, e),
1202
+ onClose: M
1203
+ })
1204
+ ]
1205
+ });
1206
+ }
1207
+ var Y = { takeSix: "_takeSix_b98wp_4" }, X = {
1208
+ title: "New block",
1209
+ description: "Description"
1210
+ };
1211
+ function Z({ document: e, onChange: t, editing: n = !1, theme: r = "auto", className: i }) {
1212
+ let o = t !== void 0 && n, s = a(() => {
1213
+ let n = (n) => {
1214
+ n !== e && t?.(n);
1215
+ };
1216
+ return {
1217
+ rename(t, r) {
1218
+ let i = r.trim();
1219
+ i && n(v(e, t, { title: i }));
1220
+ },
1221
+ describe(t, r) {
1222
+ n(v(e, t, { description: r.trim() || void 0 }));
1223
+ },
1224
+ remove(t) {
1225
+ n(ee(e, t));
1226
+ },
1227
+ add(t) {
1228
+ m(e, t) && n(d(e, t, X).document);
1229
+ },
1230
+ setSize(t, r) {
1231
+ n(v(e, t, { size: r === c ? void 0 : r }));
1232
+ },
1233
+ move(t, r, i) {
1234
+ n(_(e, t, r, { index: i }));
1235
+ },
1236
+ group(t) {
1237
+ n(g(e, t, {
1238
+ title: "New group",
1239
+ description: `${t.length} blocks`
1240
+ }).document);
1241
+ },
1242
+ setDetails(t, r) {
1243
+ n(v(e, t, { details: r.trim() ? r : void 0 }));
1244
+ },
1245
+ updateLink(t, r) {
1246
+ let i = { ...t };
1247
+ for (let [e, t] of Object.entries(r)) t === void 0 ? delete i[e] : i[e] = t;
1248
+ n({
1249
+ ...e,
1250
+ links: (e.links ?? []).map((e) => e === t ? i : e)
1251
+ });
1252
+ },
1253
+ removeLink(t) {
1254
+ let r = (e.links ?? []).filter((e) => e !== t), { links: i, ...a } = e;
1255
+ n(r.length ? {
1256
+ ...e,
1257
+ links: r
1258
+ } : a);
1259
+ },
1260
+ toggleLink(t, r) {
1261
+ let i = e.links ?? [], a = i.filter((e) => e.from !== t || e.to !== r);
1262
+ if (a.length === i.length) n(f(e, {
1263
+ from: t,
1264
+ to: r
1265
+ }).document);
1266
+ else {
1267
+ let { links: t, ...r } = e;
1268
+ n(a.length ? {
1269
+ ...e,
1270
+ links: a
1271
+ } : r);
1272
+ }
1273
+ }
1274
+ };
1275
+ }, [e, t]);
1276
+ return /* @__PURE__ */ b("div", {
1277
+ className: `${Y.takeSix} ${i ?? ""}`,
1278
+ "data-theme": r,
1279
+ children: /* @__PURE__ */ b(le, {
1280
+ document: e,
1281
+ editing: o,
1282
+ actions: s
1283
+ })
1284
+ });
1285
+ }
1286
+ export { Z as TakeSix };