@umriss-ui/dashboard 0.45.0 → 0.47.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/dashboard.js CHANGED
@@ -1,40 +1,40 @@
1
1
  "use client";
2
2
  import "./dashboard.css";
3
- import { Component as ve, useState as J, useRef as N, useLayoutEffect as de, useMemo as oe, Children as Se, isValidElement as ce, useEffect as te, Suspense as Ce, useSyncExternalStore as le, createElement as ke } from "react";
4
- import { useWording as ae, FormField as Ne, Input as He, Button as L, Text as K, GripGlyph as ue, Heading as Oe, Card as Ee, Skeleton as Re, Drawer as qe, ModalHeader as Te, ModalBody as De, Popover as Ae, announce as $, Menu as Ie, MenuItem as U, MenuSeparator as se } from "@umriss-ui/core";
5
- import { jsx as a, jsxs as R, Fragment as re } from "react/jsx-runtime";
6
- const Le = (s, e) => (i) => {
7
- const d = i.widgets.findIndex((n) => n.id === s), v = Math.max(0, Math.min(i.widgets.length - 1, e));
8
- if (d < 0 || d === v) return i;
9
- const y = [...i.widgets];
10
- return y.splice(v, 0, ...y.splice(d, 1)), { ...i, widgets: y };
11
- }, $e = (s, e) => (i) => i.widgets.some((d) => d.id === s && d.size !== e) ? { ...i, widgets: i.widgets.map((d) => d.id === s ? { ...d, size: e } : d) } : i, Fe = (s) => (e) => e.widgets.some((i) => i.id === s) ? { ...e, widgets: e.widgets.filter((i) => i.id !== s) } : e, Be = (s, e) => {
12
- let i = 1;
13
- for (; s.widgets.some((d) => d.id === `${e}-${i}`); ) i++;
14
- return `${e}-${i}`;
15
- }, Pe = (s) => (e) => ({ ...e, widgets: [...e.widgets, s] }), Ue = (s, e) => (i) => ({ ...i, widgets: i.widgets.map((d) => d.id === s ? { ...d, options: e } : d) }), Ve = "_root_2b0q1_17", We = "_bar_2b0q1_34", je = "_mode_2b0q1_43", Ge = "_head_2b0q1_58", Ye = "_editingHead_2b0q1_77", Xe = "_grip_2b0q1_85", Je = "_title_2b0q1_90", Ke = "_size_2b0q1_102", Qe = "_item_2b0q1_110", Ze = "_placeholder_2b0q1_120", et = "_grid_2b0q1_126", tt = "_headingRow_2b0q1_143", nt = "_headingHead_2b0q1_73", st = "_heading_2b0q1_73", rt = "_body_2b0q1_173", ot = "_options_2b0q1_201", at = "_catalogue_2b0q1_206", it = "_entry_2b0q1_214", dt = "_footprint_2b0q1_221", ct = "_entryText_2b0q1_233", z = {
16
- root: Ve,
17
- bar: We,
18
- mode: je,
19
- head: Ge,
20
- editingHead: Ye,
21
- grip: Xe,
22
- title: Je,
23
- size: Ke,
24
- item: Qe,
25
- placeholder: Ze,
26
- grid: et,
27
- headingRow: tt,
28
- headingHead: nt,
29
- heading: st,
30
- body: rt,
31
- options: ot,
32
- catalogue: at,
33
- entry: it,
34
- footprint: dt,
35
- entryText: ct
3
+ import { Component as He, useState as J, useRef as q, useLayoutEffect as ue, useMemo as ie, Children as Ee, isValidElement as he, useEffect as re, Suspense as Re, useSyncExternalStore as fe, createElement as qe } from "react";
4
+ import { useWording as de, FormField as Le, Input as Te, Button as B, Text as Q, GripGlyph as pe, Heading as De, Card as Ae, Skeleton as Ie, Drawer as $e, ModalHeader as Fe, ModalBody as Pe, Popover as Be, announce as U, Menu as je, MenuItem as j, MenuSeparator as te } from "@umriss-ui/core";
5
+ import { jsx as r, jsxs as R, Fragment as ne } from "react/jsx-runtime";
6
+ const ze = (t, e) => t.widgets.some((o) => o.id === e && o.locked !== !0), Ue = (t, e) => (o) => {
7
+ const i = o.widgets.findIndex((a) => a.id === t), S = Math.max(0, Math.min(o.widgets.length - 1, e));
8
+ if (i < 0 || i === S) return o;
9
+ const w = [...o.widgets];
10
+ return w.splice(S, 0, ...w.splice(i, 1)), { ...o, widgets: w };
11
+ }, Ve = (t, e) => (o) => o.widgets.some((i) => i.id === t && i.locked !== !0 && i.size !== e) ? { ...o, widgets: o.widgets.map((i) => i.id === t ? { ...i, size: e } : i) } : o, We = (t) => (e) => ze(e, t) ? { ...e, widgets: e.widgets.filter((o) => o.id !== t) } : e, Ge = (t, e) => {
12
+ let o = 1;
13
+ for (; t.widgets.some((i) => i.id === `${e}-${o}`); ) o++;
14
+ return `${e}-${o}`;
15
+ }, Ye = (t) => (e) => ({ ...e, widgets: [...e.widgets, t] }), Xe = (t, e) => (o) => ze(o, t) ? { ...o, widgets: o.widgets.map((i) => i.id === t ? { ...i, options: e } : i) } : o, Je = "_root_2b0q1_17", Ke = "_bar_2b0q1_34", Qe = "_mode_2b0q1_43", Ze = "_head_2b0q1_58", et = "_editingHead_2b0q1_77", tt = "_grip_2b0q1_85", nt = "_title_2b0q1_90", st = "_size_2b0q1_102", rt = "_item_2b0q1_110", ot = "_placeholder_2b0q1_120", at = "_grid_2b0q1_126", it = "_headingRow_2b0q1_143", dt = "_headingHead_2b0q1_73", ct = "_heading_2b0q1_73", lt = "_body_2b0q1_173", ut = "_options_2b0q1_201", ht = "_catalogue_2b0q1_206", ft = "_entry_2b0q1_214", pt = "_footprint_2b0q1_221", gt = "_entryText_2b0q1_233", _ = {
16
+ root: Je,
17
+ bar: Ke,
18
+ mode: Qe,
19
+ head: Ze,
20
+ editingHead: et,
21
+ grip: tt,
22
+ title: nt,
23
+ size: st,
24
+ item: rt,
25
+ placeholder: ot,
26
+ grid: at,
27
+ headingRow: it,
28
+ headingHead: dt,
29
+ heading: ct,
30
+ body: lt,
31
+ options: ut,
32
+ catalogue: ht,
33
+ entry: ft,
34
+ footprint: pt,
35
+ entryText: gt
36
36
  };
37
- class lt extends ve {
37
+ class bt extends He {
38
38
  state = { failed: !1 };
39
39
  static getDerivedStateFromError() {
40
40
  return { failed: !0 };
@@ -46,403 +46,409 @@ class lt extends ve {
46
46
  return this.state.failed ? this.props.fallback : this.props.children;
47
47
  }
48
48
  }
49
- const me = (s) => typeof s == "object" && s !== null && !Array.isArray(s), he = (s) => me(s) && Array.isArray(s.widgets), ie = (s) => s.widgets.filter((e) => me(e) && typeof e.id == "string" && typeof e.type == "string"), ut = (s) => ({ ...s, widgets: ie(s) }), ht = (s, e) => {
50
- const i = new Set(e.widgets.map((d) => d.id));
51
- return ie(s).filter((d) => !i.has(d.id));
52
- };
53
- function we(s, e) {
54
- const i = /* @__PURE__ */ new Set();
49
+ const ce = (t) => typeof t == "object" && t !== null && !Array.isArray(t), ge = (t) => ce(t) && Array.isArray(t.widgets), le = (t) => t.widgets.filter((e) => ce(e) && typeof e.id == "string" && typeof e.type == "string"), mt = (t) => ({ ...t, widgets: le(t) }), wt = (t, e) => {
50
+ const o = new Set(e.widgets.map((i) => i.id));
51
+ return le(t).filter((i) => !o.has(i.id));
52
+ }, be = (t) => ce(t) && [Object.prototype, null].includes(Object.getPrototypeOf(t)), yt = (t, e) => be(e) ? be(t) ? { ...e, ...t } : e : t === void 0 ? e : t;
53
+ function xe(t, e) {
54
+ const o = /* @__PURE__ */ new Set();
55
55
  return {
56
- ...s,
57
- widgets: ie(s).flatMap((d) => {
58
- const v = e.get(d.type);
59
- return !v || i.has(d.id) ? [] : (i.add(d.id), [v.sizes[d.size] ? d : { ...d, size: v.start }]);
56
+ ...t,
57
+ widgets: le(t).flatMap((i) => {
58
+ const S = e.get(i.type);
59
+ return !S || o.has(i.id) ? [] : (o.add(i.id), [{ ...i, size: S.sizes[i.size] ? i.size : S.start, options: yt(i.options, S.defaultOptions) }]);
60
60
  })
61
61
  };
62
62
  }
63
- function ye(s, e) {
64
- const i = /* @__PURE__ */ new Set(), d = (y, n, h, c) => {
65
- for (let l = y; l < y + c; l++) for (let b = n; b < n + h; b++) if (i.has(l * e + b)) return !1;
63
+ function Me(t, e) {
64
+ const o = /* @__PURE__ */ new Set(), i = (w, a, s, u) => {
65
+ for (let c = w; c < w + u; c++) for (let z = a; z < a + s; z++) if (o.has(c * e + z)) return !1;
66
66
  return !0;
67
67
  };
68
- let v = 0;
69
- return s.map((y) => {
70
- const n = Math.min(y.columns, e);
71
- for (let h = v; ; h++) {
72
- const c = Math.floor(h / e), l = h % e;
73
- if (!(l + n > e || !d(c, l, n, y.rows))) {
74
- for (let b = c; b < c + y.rows; b++) for (let p = l; p < l + n; p++) i.add(b * e + p);
75
- return v = h, { column: l, row: c, columns: n, rows: y.rows };
68
+ let S = 0;
69
+ return t.map((w) => {
70
+ const a = Math.min(w.columns, e);
71
+ for (let s = S; ; s++) {
72
+ const u = Math.floor(s / e), c = s % e;
73
+ if (!(c + a > e || !i(u, c, a, w.rows))) {
74
+ for (let z = u; z < u + w.rows; z++) for (let b = c; b < c + a; b++) o.add(z * e + b);
75
+ return S = s, { column: c, row: u, columns: a, rows: w.rows };
76
76
  }
77
77
  }
78
78
  });
79
79
  }
80
- function ft(s, e, i, d, v, { cell: y, unit: n, gap: h }) {
81
- let c = i, l = 1 / 0;
82
- for (let b = 0; b < s.length; b++) {
83
- const p = [...s];
84
- p.splice(b, 0, ...p.splice(i, 1));
85
- const H = ye(p, e)[b], O = (H.column * (y + h) - d) ** 2 + (H.row * (n + h) - v) ** 2;
86
- O < l && (l = O, c = b);
80
+ function _t(t, e, o, i, S, { cell: w, unit: a, gap: s }) {
81
+ let u = o, c = 1 / 0;
82
+ for (let z = 0; z < t.length; z++) {
83
+ const b = [...t];
84
+ b.splice(z, 0, ...b.splice(o, 1));
85
+ const v = Me(b, e)[z], V = (v.column * (w + s) - i) ** 2 + (v.row * (a + s) - S) ** 2;
86
+ V < c && (c = V, u = z);
87
87
  }
88
- return c;
88
+ return u;
89
89
  }
90
- const pt = { 3: "¼", 4: "⅓", 6: "½", 8: "⅔", 9: "¾" }, gt = ({ columns: s }) => s >= 12 ? "" : pt[s] ?? `${s}/12`;
91
- function bt({ grid: s, cards: e, shown: i, drop: d, cancelled: v }) {
92
- const [y, n] = J(null), h = N(null), c = N({}), l = N(/* @__PURE__ */ new Map()), b = N(null), p = N({ update: () => {
90
+ const zt = { 3: "¼", 4: "⅓", 6: "½", 8: "⅔", 9: "¾" }, xt = ({ columns: t }) => t >= 12 ? "" : zt[t] ?? `${t}/12`;
91
+ function Mt({ grid: t, cards: e, shown: o, drop: i, cancelled: S }) {
92
+ const [w, a] = J(null), s = q(null), u = q({}), c = q(/* @__PURE__ */ new Map()), z = q(null), b = q({ update: () => {
93
93
  }, finish: () => {
94
- } }), H = () => {
95
- const r = h.current, o = r && e.get(r.id);
96
- if (!r || !b.current || !o) return;
97
- const u = b.current.getBoundingClientRect();
98
- o.style.transform = `translate(${r.x - r.dx - u.left}px, ${r.y - r.dy - u.top}px)`;
94
+ } }), v = () => {
95
+ const d = s.current, l = d && e.get(d.id);
96
+ if (!d || !z.current || !l) return;
97
+ const m = z.current.getBoundingClientRect();
98
+ l.style.transform = `translate(${d.x - d.dx - m.left}px, ${d.y - d.dy - m.top}px)`;
99
99
  };
100
- de(() => {
101
- const r = /* @__PURE__ */ new Map(), o = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
102
- for (const [u, m] of e) {
103
- const S = l.current.get(u);
104
- r.set(u, [m.offsetLeft, m.offsetTop]), y && !o && S && u !== y.id && (S[0] !== m.offsetLeft || S[1] !== m.offsetTop) && m.animate([{ transform: `translate(${S[0] - m.offsetLeft}px, ${S[1] - m.offsetTop}px)` }, { transform: "none" }], { duration: 150, easing: "ease-out" });
100
+ ue(() => {
101
+ const d = /* @__PURE__ */ new Map(), l = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
102
+ for (const [m, h] of e) {
103
+ const p = c.current.get(m);
104
+ d.set(m, [h.offsetLeft, h.offsetTop]), w && !l && p && m !== w.id && (p[0] !== h.offsetLeft || p[1] !== h.offsetTop) && h.animate([{ transform: `translate(${p[0] - h.offsetLeft}px, ${p[1] - h.offsetTop}px)` }, { transform: "none" }], { duration: 150, easing: "ease-out" });
105
105
  }
106
- l.current = r, y && H();
106
+ c.current = d, w && v();
107
107
  });
108
- const O = () => {
109
- const r = h.current, o = s.current, u = r && e.get(r.id);
110
- if (!r || !o || !u) return;
111
- const m = getComputedStyle(o), S = parseFloat(m.columnGap), B = m.gridTemplateColumns.split(" ").length, q = o.getBoundingClientRect(), T = i[r.from].span, G = { cell: (q.width - (B - 1) * S) / B, gap: S, unit: (u.offsetHeight - (T.rows - 1) * S) / T.rows }, I = ft(i.map((W) => W.span), B, r.from, r.x - r.dx - q.left, r.y - r.dy - q.top, G);
112
- if (I === r.target) return H();
113
- r.target = I, n({ id: r.id, target: I });
114
- }, j = (r) => {
115
- const o = h.current;
116
- if (h.current = null, window.clearInterval(c.current.timer), c.current.escape && document.removeEventListener("keydown", c.current.escape), o && e.get(o.id)?.style.removeProperty("transform"), n(null), !!o?.started) {
117
- if (!r) return v(i[o.from].title);
118
- d(o.id, i[o.target].id);
108
+ const V = () => {
109
+ const d = s.current, l = t.current, m = d && e.get(d.id);
110
+ if (!d || !l || !m) return;
111
+ const h = getComputedStyle(l), p = parseFloat(h.columnGap), H = h.gridTemplateColumns.split(" ").length, E = l.getBoundingClientRect(), G = o[d.from].span, Y = { cell: (E.width - (H - 1) * p) / H, gap: p, unit: (m.offsetHeight - (G.rows - 1) * p) / G.rows }, D = _t(o.map(($) => $.span), H, d.from, d.x - d.dx - E.left, d.y - d.dy - E.top, Y);
112
+ if (D === d.target) return v();
113
+ d.target = D, a({ id: d.id, target: D });
114
+ }, K = (d) => {
115
+ const l = s.current;
116
+ if (s.current = null, window.clearInterval(u.current.timer), u.current.escape && document.removeEventListener("keydown", u.current.escape), l && e.get(l.id)?.style.removeProperty("transform"), a(null), !!l?.started) {
117
+ if (!d) return S(o[l.from].title);
118
+ i(l.id, o[l.target].id);
119
119
  }
120
120
  };
121
- de(() => {
122
- p.current = { update: O, finish: j };
121
+ ue(() => {
122
+ b.current = { update: V, finish: K };
123
123
  });
124
- const V = (r, o) => (u) => {
125
- const m = u.target;
126
- if (u.button > 0 || m.closest("button") || !u.currentTarget.contains(m)) return;
127
- const S = e.get(r).getBoundingClientRect();
128
- h.current = { id: r, from: o, x0: u.clientX, y0: u.clientY, x: u.clientX, y: u.clientY, dx: u.clientX - S.left, dy: u.clientY - S.top, started: !1, target: o }, u.currentTarget.setPointerCapture(u.pointerId);
129
- }, F = (r) => {
130
- const o = h.current;
131
- if (o) {
132
- if (o.x = r.clientX, o.y = r.clientY, !o.started) {
133
- if (Math.hypot(o.x - o.x0, o.y - o.y0) <= 4) return;
134
- o.started = !0, n({ id: o.id, target: o.from }), c.current.escape = (u) => u.key === "Escape" && p.current.finish(!1), document.addEventListener("keydown", c.current.escape), c.current.timer = window.setInterval(() => {
135
- const m = h.current?.y ?? window.innerHeight / 2, S = Math.ceil((64 - Math.min(m, window.innerHeight - m)) / 4);
136
- S <= 0 || (window.scrollBy(0, m < window.innerHeight / 2 ? -S : S), p.current.update());
124
+ const W = (d, l) => (m) => {
125
+ const h = m.target;
126
+ if (m.button > 0 || h.closest("button") || !m.currentTarget.contains(h)) return;
127
+ const p = e.get(d).getBoundingClientRect();
128
+ s.current = { id: d, from: l, x0: m.clientX, y0: m.clientY, x: m.clientX, y: m.clientY, dx: m.clientX - p.left, dy: m.clientY - p.top, started: !1, target: l }, m.currentTarget.setPointerCapture(m.pointerId);
129
+ }, A = (d) => {
130
+ const l = s.current;
131
+ if (l) {
132
+ if (l.x = d.clientX, l.y = d.clientY, !l.started) {
133
+ if (Math.hypot(l.x - l.x0, l.y - l.y0) <= 4) return;
134
+ l.started = !0, a({ id: l.id, target: l.from }), u.current.escape = (m) => m.key === "Escape" && b.current.finish(!1), document.addEventListener("keydown", u.current.escape), u.current.timer = window.setInterval(() => {
135
+ const h = s.current?.y ?? window.innerHeight / 2, p = Math.ceil((64 - Math.min(h, window.innerHeight - h)) / 4);
136
+ p <= 0 || (window.scrollBy(0, h < window.innerHeight / 2 ? -p : p), b.current.update());
137
137
  }, 16);
138
138
  }
139
- p.current.update();
139
+ b.current.update();
140
140
  }
141
141
  };
142
142
  return {
143
- drag: y,
143
+ drag: w,
144
144
  /** To go on the placeholder. */
145
- placeholder: b,
145
+ placeholder: z,
146
146
  /** The pointer handlers of a widget's head. */
147
- handlers: (r, o) => ({
148
- onPointerDown: V(r, o),
149
- onPointerMove: F,
150
- onPointerUp: () => p.current.finish(!0),
151
- onPointerCancel: () => p.current.finish(!1)
147
+ handlers: (d, l) => ({
148
+ onPointerDown: W(d, l),
149
+ onPointerMove: A,
150
+ onPointerUp: () => b.current.finish(!0),
151
+ onPointerCancel: () => b.current.finish(!1)
152
152
  })
153
153
  };
154
154
  }
155
- function _e(s) {
155
+ function Se(t) {
156
156
  return null;
157
157
  }
158
- function mt() {
158
+ function St() {
159
159
  return null;
160
160
  }
161
- const wt = "heading", Q = (s, e) => s.title?.(e) ?? s.label;
162
- function yt({ options: s, change: e }) {
163
- const i = ae();
164
- return /* @__PURE__ */ a(Ne, { label: i.dashboardHeadingField, children: /* @__PURE__ */ a(He, { value: s.text, onChange: (d) => e({ text: d.target.value }) }) });
161
+ const vt = "heading", Z = (t, e) => t.title?.(e) ?? t.label;
162
+ function Ct({ options: t, change: e }) {
163
+ const o = de();
164
+ return /* @__PURE__ */ r(Le, { label: o.dashboardHeadingField, children: /* @__PURE__ */ r(Te, { value: t.text, onChange: (i) => e({ text: i.target.value }) }) });
165
165
  }
166
- function _t(s) {
166
+ function kt(t) {
167
167
  return {
168
- name: wt,
169
- label: s.dashboardHeadingLabel,
170
- sentence: s.dashboardHeadingSentence,
168
+ name: vt,
169
+ label: t.dashboardHeadingLabel,
170
+ sentence: t.dashboardHeadingSentence,
171
171
  sizes: { full: { columns: 12, rows: 1 } },
172
172
  start: "full",
173
- defaultOptions: { text: s.dashboardHeadingText },
174
- title: (e) => e.text || s.dashboardHeadingLabel,
175
- form: yt,
173
+ defaultOptions: { text: t.dashboardHeadingText },
174
+ title: (e) => e.text || t.dashboardHeadingLabel,
175
+ form: Ct,
176
176
  children: () => null
177
177
  };
178
178
  }
179
- const Z = (...s) => s.filter(Boolean).join(" "), fe = 12;
180
- function xt({ render: s, ...e }) {
181
- return s(e);
179
+ const ee = (...t) => t.filter(Boolean).join(" "), me = 12;
180
+ function Nt({ render: t, ...e }) {
181
+ return t(e);
182
182
  }
183
- const pe = (s, e) => ({ "--_dashboard-column": s.column + 1, "--_dashboard-row": s.row + 1, "--_dashboard-columns": s.columns, "--_dashboard-rows": s.rows, "--_dashboard-order": e }), ge = (s) => s.columns * s.rows;
184
- function zt({ title: s, editing: e, children: i }) {
185
- const d = N(null), [v, y] = J(!1);
186
- te(() => {
187
- const h = d.current;
188
- if (!h) return;
189
- const c = () => y(h.scrollHeight > h.clientHeight || h.scrollWidth > h.clientWidth), l = new ResizeObserver(c), b = () => {
190
- l.disconnect(), l.observe(h);
191
- for (const H of h.children) l.observe(H);
192
- c();
193
- }, p = new MutationObserver(b);
194
- return p.observe(h, { childList: !0 }), b(), () => {
195
- l.disconnect(), p.disconnect();
183
+ const we = (t, e) => ({ "--_dashboard-column": t.column + 1, "--_dashboard-row": t.row + 1, "--_dashboard-columns": t.columns, "--_dashboard-rows": t.rows, "--_dashboard-order": e }), ye = (t) => t.columns * t.rows;
184
+ function Ot({ title: t, editing: e, children: o }) {
185
+ const i = q(null), [S, w] = J(!1);
186
+ re(() => {
187
+ const s = i.current;
188
+ if (!s) return;
189
+ const u = () => w(s.scrollHeight > s.clientHeight || s.scrollWidth > s.clientWidth), c = new ResizeObserver(u), z = () => {
190
+ c.disconnect(), c.observe(s);
191
+ for (const v of s.children) c.observe(v);
192
+ u();
193
+ }, b = new MutationObserver(z);
194
+ return b.observe(s, { childList: !0 }), z(), () => {
195
+ c.disconnect(), b.disconnect();
196
196
  };
197
197
  }, []);
198
- const n = v && !e;
199
- return /* @__PURE__ */ a("div", { ref: d, className: z.body, inert: e, ...n ? { role: "group", tabIndex: 0, "aria-label": s } : {}, children: i });
198
+ const a = S && !e;
199
+ return /* @__PURE__ */ r("div", { ref: i, className: _.body, inert: e, ...a ? { role: "group", tabIndex: 0, "aria-label": t } : {}, children: o });
200
200
  }
201
- const ee = (s, e) => (i) => {
202
- i ? s.set(e, i) : s.delete(e);
201
+ const se = (t, e) => (o) => {
202
+ o ? t.set(e, o) : t.delete(e);
203
203
  };
204
- function Mt({ view: s, editor: e, className: i, children: d, catalogue: v, ...y }) {
205
- const n = ae(), h = oe(() => _t(n), [n]), c = /* @__PURE__ */ new Map();
206
- for (const t of Se.toArray(d))
207
- ce(t) && t.type === _e ? c.set(t.props.name, t.props) : ce(t) && t.type === mt && c.set(h.name, h);
208
- const { register: l } = e;
209
- te(() => l(c));
210
- const b = we(s, c), p = b.widgets.flatMap((t) => {
211
- const f = c.get(t.type), x = f?.sizes[t.size];
212
- return f && x ? [{ widget: t, type: f, span: x }] : [];
213
- }), H = N(null), [O] = J(() => /* @__PURE__ */ new Map()), [j] = J(() => /* @__PURE__ */ new Map()), [V] = J(() => /* @__PURE__ */ new Map()), F = N(null), { editing: r } = e, o = b.widgets.length, u = (t, f, x) => {
214
- const C = b.widgets.findIndex((A) => A.id === t), M = Math.max(0, Math.min(o - 1, x));
215
- C !== M && (e.step(Le(t, M)), $(n.dashboardMoved(f, C + 1, M + 1, o)));
216
- }, { drag: m, placeholder: S, handlers: B } = bt({
217
- grid: H,
218
- cards: O,
219
- shown: p.map(({ widget: t, type: f, span: x }) => ({ id: t.id, span: x, title: Q(f, t.options) })),
220
- drop: (t, f) => {
221
- const x = p.find((C) => C.widget.id === t);
222
- u(t, Q(x.type, x.widget.options), b.widgets.findIndex((C) => C.id === f));
204
+ function Ht({ view: t, editor: e, className: o, children: i, catalogue: S, headingLevel: w = 2, ...a }) {
205
+ const s = de(), u = ie(() => kt(s), [s]), c = /* @__PURE__ */ new Map();
206
+ for (const n of Ee.toArray(i))
207
+ he(n) && n.type === Se ? c.set(n.props.name, n.props) : he(n) && n.type === St && c.set(u.name, u);
208
+ const { register: z } = e;
209
+ re(() => z(c));
210
+ const b = xe(t, c), v = b.widgets.flatMap((n) => {
211
+ const f = c.get(n.type), x = f?.sizes[n.size];
212
+ return f && x ? [{ widget: n, type: f, span: x }] : [];
213
+ }), K = `h${Math.min(6, w + (v.some(({ type: n }) => n === u) ? 1 : 0))}`, W = q(null), [A] = J(() => /* @__PURE__ */ new Map()), [d] = J(() => /* @__PURE__ */ new Map()), [l] = J(() => /* @__PURE__ */ new Map()), m = q(null), { editing: h } = e, p = b.widgets.length, H = (n, f, x) => {
214
+ const k = b.widgets.findIndex((N) => N.id === n), C = Math.max(0, Math.min(p - 1, x));
215
+ k !== C && (e.step(Ue(n, C)), U(s.dashboardMoved(f, k + 1, C + 1, p)));
216
+ }, { drag: E, placeholder: G, handlers: Y } = Mt({
217
+ grid: W,
218
+ cards: A,
219
+ shown: v.map(({ widget: n, type: f, span: x }) => ({ id: n.id, span: x, title: Z(f, n.options) })),
220
+ drop: (n, f) => {
221
+ const x = v.find((k) => k.widget.id === n);
222
+ H(n, Z(x.type, x.widget.options), b.widgets.findIndex((k) => k.id === f));
223
223
  },
224
- cancelled: (t) => $(n.dashboardDragCancelled(t))
225
- }), q = m ? p.findIndex((t) => t.widget.id === m.id) : -1, T = p.map((t, f) => f);
226
- q >= 0 && T.splice(m.target, 0, ...T.splice(q, 1));
227
- const G = ye(T.map((t) => p[t].span), fe), I = p.map((t, f) => G[T.indexOf(f)]), [W, w] = J(null), g = N(null), _ = N(null);
228
- te(() => {
229
- _.current && (O.get(_.current)?.scrollIntoView?.({ block: "nearest" }), _.current = null);
224
+ cancelled: (n) => U(s.dashboardDragCancelled(n))
225
+ }), D = E ? v.findIndex((n) => n.widget.id === E.id) : -1, $ = v.map((n, f) => f);
226
+ D >= 0 && $.splice(E.target, 0, ...$.splice(D, 1));
227
+ const y = Me($.map((n) => v[n].span), me), g = v.map((n, f) => y[$.indexOf(f)]), [M, O] = J(null), F = q(null), P = q(null);
228
+ re(() => {
229
+ P.current && (A.get(P.current)?.scrollIntoView?.({ block: "nearest" }), P.current = null);
230
230
  });
231
- const k = N(!1);
232
- te(() => {
233
- k.current !== !1 && ((k.current === null ? F.current : j.get(k.current))?.focus(), k.current = !1);
231
+ const L = q(!1);
232
+ re(() => {
233
+ L.current !== !1 && ((L.current === null ? m.current : d.get(L.current))?.focus(), L.current = !1);
234
234
  });
235
- const P = [...c.values()].filter((t) => !v || v.includes(t.name)), Y = (t) => {
236
- const f = { id: Be(b, t.name), type: t.name, size: t.start, options: t.defaultOptions };
237
- _.current = f.id, e.step(Pe(f)), $(n.dashboardAdded(Q(t, f.options), o + 1, o + 1));
238
- }, D = W ? c.get(b.widgets.find((t) => t.id === W)?.type ?? "") : void 0, ne = b.widgets.find((t) => t.id === W), xe = (t, f, x, C) => r ? {
239
- ref: ee(j, t.id),
240
- className: Z(z.head, z.editingHead),
241
- ...B(t.id, x),
235
+ const ve = [...c.values()].filter((n) => !S || S.includes(n.name)), Ce = (n) => {
236
+ const f = { id: Ge(b, n.name), type: n.name, size: n.start, options: n.defaultOptions };
237
+ P.current = f.id, e.step(Ye(f)), U(s.dashboardAdded(Z(n, f.options), p + 1, p + 1));
238
+ }, oe = M ? c.get(b.widgets.find((n) => n.id === M)?.type ?? "") : void 0, ae = b.widgets.find((n) => n.id === M), ke = (n, f, x, k, C) => h ? {
239
+ ref: se(d, n.id),
240
+ className: ee(_.head, _.editingHead),
241
+ ...Y(n.id, x),
242
242
  role: "group",
243
243
  tabIndex: 0,
244
- "aria-label": n.dashboardHead(f, C + 1, o),
245
- onKeyDown: (M) => {
246
- if (M.target !== M.currentTarget) return;
247
- const A = { ArrowLeft: C - 1, ArrowUp: C - 1, ArrowRight: C + 1, ArrowDown: C + 1, Home: 0, End: o - 1 }[M.key];
248
- A !== void 0 && (M.preventDefault(), u(t.id, f, A));
244
+ "aria-label": (C ? s.dashboardHeadLocked : s.dashboardHead)(f, k + 1, p),
245
+ onKeyDown: (N) => {
246
+ if (N.target !== N.currentTarget) return;
247
+ const I = { ArrowLeft: k - 1, ArrowUp: k - 1, ArrowRight: k + 1, ArrowDown: k + 1, Home: 0, End: p - 1 }[N.key];
248
+ I !== void 0 && (N.preventDefault(), H(n.id, f, I));
249
249
  }
250
- } : { className: z.head }, ze = (t, f, x, C, M) => {
251
- const A = Object.entries(f.sizes).sort(([, E], [, X]) => ge(E) - ge(X));
250
+ } : { className: _.head }, Ne = (n, f, x, k, C, N) => {
251
+ const I = Object.entries(f.sizes).sort(([, T], [, X]) => ye(T) - ye(X));
252
252
  return /* @__PURE__ */ R(
253
- Ie,
253
+ je,
254
254
  {
255
255
  align: "end",
256
- trigger: /* @__PURE__ */ a(L, { ref: ee(V, t.id), size: "sm", variant: "ghost", "aria-label": n.dashboardMenu(x), children: /* @__PURE__ */ a("svg", { viewBox: "0 0 10 10", width: "10", height: "10", "aria-hidden": "true", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", children: /* @__PURE__ */ a("path", { d: "M1.5 5h.01M5 5h.01M8.5 5h.01" }) }) }),
256
+ trigger: /* @__PURE__ */ r(B, { ref: se(l, n.id), size: "sm", variant: "ghost", "aria-label": s.dashboardMenu(x), children: /* @__PURE__ */ r("svg", { viewBox: "0 0 10 10", width: "10", height: "10", "aria-hidden": "true", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round", children: /* @__PURE__ */ r("path", { d: "M1.5 5h.01M5 5h.01M8.5 5h.01" }) }) }),
257
257
  children: [
258
- /* @__PURE__ */ a(U, { disabled: !0, children: n.dashboardPlace(M + 1, o) }),
259
- /* @__PURE__ */ a(U, { disabled: M === 0, onSelect: () => u(t.id, x, 0), children: n.dashboardMoveStart }),
260
- /* @__PURE__ */ a(U, { disabled: M === 0, onSelect: () => u(t.id, x, M - 1), children: n.dashboardMoveEarlier }),
261
- /* @__PURE__ */ a(U, { disabled: M === o - 1, onSelect: () => u(t.id, x, M + 1), children: n.dashboardMoveLater }),
262
- /* @__PURE__ */ a(U, { disabled: M === o - 1, onSelect: () => u(t.id, x, o - 1), children: n.dashboardMoveEnd }),
263
- A.length > 1 && /* @__PURE__ */ R(re, { children: [
264
- /* @__PURE__ */ a(se, {}),
265
- A.map(([E, X]) => /* @__PURE__ */ a(
266
- U,
258
+ /* @__PURE__ */ r(j, { disabled: !0, children: s.dashboardPlace(C + 1, p) }),
259
+ /* @__PURE__ */ r(j, { disabled: C === 0, onSelect: () => H(n.id, x, 0), children: s.dashboardMoveStart }),
260
+ /* @__PURE__ */ r(j, { disabled: C === 0, onSelect: () => H(n.id, x, C - 1), children: s.dashboardMoveEarlier }),
261
+ /* @__PURE__ */ r(j, { disabled: C === p - 1, onSelect: () => H(n.id, x, C + 1), children: s.dashboardMoveLater }),
262
+ /* @__PURE__ */ r(j, { disabled: C === p - 1, onSelect: () => H(n.id, x, p - 1), children: s.dashboardMoveEnd }),
263
+ N && /* @__PURE__ */ R(ne, { children: [
264
+ /* @__PURE__ */ r(te, {}),
265
+ /* @__PURE__ */ r(j, { disabled: !0, children: s.dashboardLockedLine })
266
+ ] }),
267
+ !N && I.length > 1 && /* @__PURE__ */ R(ne, { children: [
268
+ /* @__PURE__ */ r(te, {}),
269
+ I.map(([T, X]) => /* @__PURE__ */ r(
270
+ j,
267
271
  {
268
- "aria-current": E === t.size || void 0,
272
+ "aria-current": T === n.size || void 0,
269
273
  onSelect: () => {
270
- e.step($e(t.id, E)), $(n.dashboardResized(x, n.dashboardSizes[E]));
274
+ e.step(Ve(n.id, T)), U(s.dashboardResized(x, s.dashboardSizes[T]));
271
275
  },
272
- children: n.dashboardSizeEntry(n.dashboardSizes[E], gt(X), E === t.size)
276
+ children: s.dashboardSizeEntry(s.dashboardSizes[T], xt(X), T === n.size)
273
277
  },
274
- E
278
+ T
275
279
  ))
276
280
  ] }),
277
- f.form && /* @__PURE__ */ R(re, { children: [
278
- /* @__PURE__ */ a(se, {}),
279
- /* @__PURE__ */ a(
280
- U,
281
+ !N && f.form && /* @__PURE__ */ R(ne, { children: [
282
+ /* @__PURE__ */ r(te, {}),
283
+ /* @__PURE__ */ r(
284
+ j,
281
285
  {
282
286
  onSelect: () => {
283
- g.current = V.get(t.id) ?? null, w(t.id);
287
+ F.current = l.get(n.id) ?? null, O(n.id);
284
288
  },
285
- children: n.dashboardOptions
289
+ children: s.dashboardOptions
286
290
  }
287
291
  )
288
292
  ] }),
289
- /* @__PURE__ */ a(se, {}),
290
- /* @__PURE__ */ a(
291
- U,
293
+ !N && /* @__PURE__ */ r(te, {}),
294
+ !N && /* @__PURE__ */ r(
295
+ j,
292
296
  {
293
297
  tone: "danger",
294
298
  onSelect: () => {
295
- k.current = (p[C + 1] ?? p[C - 1])?.widget.id ?? null, e.step(Fe(t.id)), $(n.dashboardRemoved(x));
299
+ L.current = (v[k + 1] ?? v[k - 1])?.widget.id ?? null, e.step(We(n.id)), U(s.dashboardRemoved(x));
296
300
  },
297
- children: n.dashboardRemove
301
+ children: s.dashboardRemove
298
302
  }
299
303
  )
300
304
  ]
301
305
  }
302
306
  );
303
307
  };
304
- return /* @__PURE__ */ R("div", { role: "group", className: Z(z.root, i), "data-editing": r || void 0, ...y, children: [
305
- e.allowed && /* @__PURE__ */ a("div", { className: z.bar, children: r ? /* @__PURE__ */ R(re, { children: [
306
- /* @__PURE__ */ a("span", { className: z.mode, children: n.dashboardEditing }),
307
- /* @__PURE__ */ a(L, { size: "sm", disabled: !e.canUndo, onClick: e.undo, children: n.dashboardUndo }),
308
- /* @__PURE__ */ a(L, { size: "sm", disabled: !e.canRedo, onClick: e.redo, children: n.dashboardRedo }),
309
- /* @__PURE__ */ a(L, { size: "sm", disabled: !e.canReset, onClick: e.reset, children: n.dashboardReset }),
310
- /* @__PURE__ */ a(L, { ref: F, size: "sm", onClick: () => e.setCatalogue(!0), children: n.dashboardAddWidget }),
311
- /* @__PURE__ */ a(L, { size: "sm", onClick: e.cancel, children: n.dashboardCancel }),
312
- /* @__PURE__ */ a(L, { size: "sm", variant: "primary", onClick: e.done, children: n.dashboardDone })
313
- ] }) : /* @__PURE__ */ a(L, { size: "sm", onClick: e.edit, children: n.dashboardEdit }) }),
314
- r && o === 0 && /* @__PURE__ */ a(K, { children: n.dashboardEmptyEditing }),
315
- !r && o === 0 && /* @__PURE__ */ a(K, { children: n.dashboardEmpty }),
316
- /* @__PURE__ */ R("div", { className: z.grid, ref: H, children: [
317
- p.map(({ widget: t, type: f }, x) => {
318
- const C = pe(I[x], T.indexOf(x)), M = Q(f, t.options), A = b.widgets.findIndex((Me) => Me.id === t.id), E = xe(t, M, x, A), X = r && ze(t, f, M, x, A);
319
- return f === h ? /* @__PURE__ */ a("div", { ref: ee(O, t.id), className: Z(z.item, z.headingRow), style: C, "data-widget": t.id, "data-editing": r || void 0, "data-dragging": m?.id === t.id || void 0, children: /* @__PURE__ */ R("div", { ...E, className: Z(E.className, z.headingHead), children: [
320
- r && /* @__PURE__ */ a(ue, { className: z.grip }),
321
- /* @__PURE__ */ a(Oe, { level: 2, size: "lg", className: z.heading, children: t.options.text }),
308
+ return /* @__PURE__ */ R("div", { role: "group", className: ee(_.root, o), "data-editing": h || void 0, ...a, children: [
309
+ e.allowed && /* @__PURE__ */ r("div", { className: _.bar, children: h ? /* @__PURE__ */ R(ne, { children: [
310
+ /* @__PURE__ */ r("span", { className: _.mode, children: s.dashboardEditing }),
311
+ /* @__PURE__ */ r(B, { size: "sm", disabled: !e.canUndo, onClick: e.undo, children: s.dashboardUndo }),
312
+ /* @__PURE__ */ r(B, { size: "sm", disabled: !e.canRedo, onClick: e.redo, children: s.dashboardRedo }),
313
+ /* @__PURE__ */ r(B, { size: "sm", disabled: !e.canReset, onClick: e.reset, children: s.dashboardReset }),
314
+ /* @__PURE__ */ r(B, { ref: m, size: "sm", onClick: () => e.setCatalogue(!0), children: s.dashboardAddWidget }),
315
+ /* @__PURE__ */ r(B, { size: "sm", onClick: e.cancel, children: s.dashboardCancel }),
316
+ /* @__PURE__ */ r(B, { size: "sm", variant: "primary", onClick: e.done, children: s.dashboardDone })
317
+ ] }) : /* @__PURE__ */ r(B, { size: "sm", onClick: e.edit, children: s.dashboardEdit }) }),
318
+ h && p === 0 && /* @__PURE__ */ r(Q, { children: s.dashboardEmptyEditing }),
319
+ !h && p === 0 && /* @__PURE__ */ r(Q, { children: s.dashboardEmpty }),
320
+ /* @__PURE__ */ R("div", { className: _.grid, ref: W, children: [
321
+ v.map(({ widget: n, type: f }, x) => {
322
+ const k = we(g[x], $.indexOf(x)), C = Z(f, n.options), N = b.widgets.findIndex((Oe) => Oe.id === n.id), I = n.locked === !0, T = ke(n, C, x, N, I), X = h && Ne(n, f, C, x, N, I);
323
+ return f === u ? /* @__PURE__ */ r("div", { ref: se(A, n.id), className: ee(_.item, _.headingRow), style: k, "data-widget": n.id, "data-editing": h || void 0, "data-dragging": E?.id === n.id || void 0, children: /* @__PURE__ */ R("div", { ...T, className: ee(T.className, _.headingHead), children: [
324
+ h && /* @__PURE__ */ r(pe, { className: _.grip }),
325
+ /* @__PURE__ */ r(De, { level: w, size: "lg", className: _.heading, children: n.options.text }),
326
+ h && I && /* @__PURE__ */ r("span", { className: _.size, children: s.dashboardLocked }),
322
327
  X
323
- ] }) }, t.id) : /* @__PURE__ */ R(Ee, { ref: ee(O, t.id), className: z.item, style: C, "data-widget": t.id, "data-editing": r || void 0, "data-dragging": m?.id === t.id || void 0, "aria-label": M, children: [
324
- /* @__PURE__ */ R("div", { ...E, children: [
325
- r && /* @__PURE__ */ a(ue, { className: z.grip }),
326
- /* @__PURE__ */ a("h2", { className: z.title, children: M }),
327
- r && /* @__PURE__ */ a("span", { className: z.size, children: n.dashboardSizes[t.size] }),
328
+ ] }) }, n.id) : /* @__PURE__ */ R(Ae, { ref: se(A, n.id), className: _.item, style: k, "data-widget": n.id, "data-editing": h || void 0, "data-dragging": E?.id === n.id || void 0, "aria-label": C, children: [
329
+ /* @__PURE__ */ R("div", { ...T, children: [
330
+ h && /* @__PURE__ */ r(pe, { className: _.grip }),
331
+ /* @__PURE__ */ r(K, { className: _.title, children: C }),
332
+ h && /* @__PURE__ */ r("span", { className: _.size, children: s.dashboardSizes[n.size] }),
333
+ h && I && /* @__PURE__ */ r("span", { className: _.size, children: s.dashboardLocked }),
328
334
  X
329
335
  ] }),
330
- /* @__PURE__ */ a(zt, { title: M, editing: r, children: /* @__PURE__ */ a(lt, { size: t.size, options: t.options, fallback: /* @__PURE__ */ a(K, { tone: "secondary", children: n.dashboardFailed }), children: /* @__PURE__ */ a(Ce, { fallback: /* @__PURE__ */ a(Re, { width: "100%", height: "100%" }), children: /* @__PURE__ */ a(xt, { render: f.children, size: t.size, options: t.options }) }) }) })
331
- ] }, t.id);
336
+ /* @__PURE__ */ r(Ot, { title: C, editing: h, children: /* @__PURE__ */ r(bt, { size: n.size, options: n.options, fallback: /* @__PURE__ */ r(Q, { tone: "secondary", children: s.dashboardFailed }), children: /* @__PURE__ */ r(Re, { fallback: /* @__PURE__ */ r(Ie, { width: "100%", height: "100%" }), children: /* @__PURE__ */ r(Nt, { render: f.children, size: n.size, options: n.options }) }) }) })
337
+ ] }, n.id);
332
338
  }),
333
- q >= 0 && /* @__PURE__ */ a("div", { ref: S, "aria-hidden": "true", "data-placeholder": !0, className: Z(z.item, z.placeholder), style: pe(I[q], m.target) })
339
+ D >= 0 && /* @__PURE__ */ r("div", { ref: G, "aria-hidden": "true", "data-placeholder": !0, className: ee(_.item, _.placeholder), style: we(g[D], E.target) })
334
340
  ] }),
335
- /* @__PURE__ */ R(qe, { open: e.catalogue, onClose: () => e.setCatalogue(!1), children: [
336
- /* @__PURE__ */ a(Te, { title: n.dashboardCatalogue, description: n.dashboardCatalogueSentence }),
337
- /* @__PURE__ */ a(De, { children: /* @__PURE__ */ a("ul", { className: z.catalogue, children: P.map((t) => {
338
- const f = t.sizes[t.start];
339
- return /* @__PURE__ */ R("li", { className: z.entry, children: [
340
- /* @__PURE__ */ a("div", { className: z.footprint, role: "img", "aria-label": n.dashboardFootprint(f.columns, f.rows), children: /* @__PURE__ */ a("span", { style: { width: `${f.columns / fe * 100}%`, height: `${Math.min(1, f.rows / 4) * 100}%` } }) }),
341
- /* @__PURE__ */ R("div", { className: z.entryText, children: [
342
- /* @__PURE__ */ a(K, { as: "strong", weight: "semibold", children: t.label }),
343
- /* @__PURE__ */ a(K, { as: "span", size: "sm", tone: "secondary", children: t.sentence })
341
+ /* @__PURE__ */ R($e, { open: e.catalogue, onClose: () => e.setCatalogue(!1), children: [
342
+ /* @__PURE__ */ r(Fe, { title: s.dashboardCatalogue, description: s.dashboardCatalogueSentence }),
343
+ /* @__PURE__ */ r(Pe, { children: /* @__PURE__ */ r("ul", { className: _.catalogue, children: ve.map((n) => {
344
+ const f = n.sizes[n.start];
345
+ return /* @__PURE__ */ R("li", { className: _.entry, children: [
346
+ /* @__PURE__ */ r("div", { className: _.footprint, role: "img", "aria-label": s.dashboardFootprint(f.columns, f.rows), children: /* @__PURE__ */ r("span", { style: { width: `${f.columns / me * 100}%`, height: `${Math.min(1, f.rows / 4) * 100}%` } }) }),
347
+ /* @__PURE__ */ R("div", { className: _.entryText, children: [
348
+ /* @__PURE__ */ r(Q, { as: "strong", weight: "semibold", children: n.label }),
349
+ /* @__PURE__ */ r(Q, { as: "span", size: "sm", tone: "secondary", children: n.sentence })
344
350
  ] }),
345
- /* @__PURE__ */ a(L, { size: "sm", "aria-label": n.dashboardAddType(t.label), onClick: () => Y(t), children: n.dashboardAdd })
346
- ] }, t.name);
351
+ /* @__PURE__ */ r(B, { size: "sm", "aria-label": s.dashboardAddType(n.label), onClick: () => Ce(n), children: s.dashboardAdd })
352
+ ] }, n.name);
347
353
  }) }) })
348
354
  ] }),
349
- D?.form && ne && /* @__PURE__ */ a(Ae, { open: !0, anchorRef: g, align: "end", onOpenChange: () => w(null), role: "dialog", "aria-label": n.dashboardOptions, children: /* @__PURE__ */ a("div", { className: z.options, children: D.form({
350
- options: ne.options,
351
- change: (t) => {
352
- e.step(Ue(ne.id, t)), $(n.dashboardOptionsChanged(Q(D, t)));
355
+ oe?.form && ae && /* @__PURE__ */ r(Be, { open: !0, anchorRef: F, align: "end", onOpenChange: () => O(null), role: "dialog", "aria-label": s.dashboardOptions, children: /* @__PURE__ */ r("div", { className: _.options, children: oe.form({
356
+ options: ae.options,
357
+ change: (n) => {
358
+ e.step(Xe(ae.id, n)), U(s.dashboardOptionsChanged(Z(oe, n)));
353
359
  }
354
360
  }) }) })
355
361
  ] });
356
362
  }
357
- const be = (s, e) => JSON.stringify(s) === JSON.stringify(e);
358
- function kt({ defaultView: s, initialView: e, allowEdit: i = !0, onViewChange: d, onDraftChange: v }) {
359
- const y = N(null);
360
- y.current ??= { state: { view: he(e) ? e : s, draft: null, known: 0 }, listeners: /* @__PURE__ */ new Set(), types: /* @__PURE__ */ new Map(), signature: "" };
361
- const n = y.current, h = ae(), c = N({ defaultView: s, allowEdit: i, onViewChange: d, onDraftChange: v, wording: h });
362
- c.current = { defaultView: s, allowEdit: i, onViewChange: d, onDraftChange: v, wording: h };
363
- const l = oe(() => {
364
- const V = (w) => (n.listeners.add(w), () => void n.listeners.delete(w)), F = () => n.state, r = (w) => {
365
- n.state = w, n.listeners.forEach((g) => g());
366
- }, o = (w) => n.types.size ? we(w, n.types) : ut(w), u = () => {
367
- !c.current.allowEdit || n.state.draft || (r({ ...n.state, draft: { steps: [o(n.state.view)], at: 0 } }), c.current.onDraftChange?.(!0));
368
- }, m = (w) => {
369
- const { view: g, draft: _ } = n.state;
370
- if (!_) return;
371
- const k = _.steps[_.at], P = w && !be(k, o(g)), Y = { ...k, widgets: [...k.widgets, ...ht(g, _.steps[0])] };
372
- r({ ...n.state, view: P ? Y : g, draft: null, catalogue: !1 }), c.current.onDraftChange?.(!1);
373
- const { wording: D } = c.current;
374
- $(w ? P ? D.dashboardKept : D.dashboardLeft : D.dashboardCancelled), P && c.current.onViewChange?.(Y);
375
- }, S = (w) => {
376
- n.state.draft && r({ ...n.state, catalogue: w });
377
- }, B = (w) => {
378
- const { draft: g } = n.state;
363
+ const _e = (t, e) => JSON.stringify(t) === JSON.stringify(e);
364
+ function Lt({ defaultView: t, initialView: e, allowEdit: o = !0, onViewChange: i, onDraftChange: S }) {
365
+ const w = q(null);
366
+ w.current ??= { state: { view: ge(e) ? e : t, draft: null, known: 0 }, listeners: /* @__PURE__ */ new Set(), types: /* @__PURE__ */ new Map(), signature: "" };
367
+ const a = w.current, s = de(), u = q({ defaultView: t, allowEdit: o, onViewChange: i, onDraftChange: S, wording: s });
368
+ u.current = { defaultView: t, allowEdit: o, onViewChange: i, onDraftChange: S, wording: s };
369
+ const c = ie(() => {
370
+ const W = (y) => (a.listeners.add(y), () => void a.listeners.delete(y)), A = () => a.state, d = (y) => {
371
+ a.state = y, a.listeners.forEach((g) => g());
372
+ }, l = (y) => a.types.size ? xe(y, a.types) : mt(y), m = () => {
373
+ !u.current.allowEdit || a.state.draft || (d({ ...a.state, draft: { steps: [l(a.state.view)], at: 0 } }), u.current.onDraftChange?.(!0));
374
+ }, h = (y) => {
375
+ const { view: g, draft: M } = a.state;
376
+ if (!M) return;
377
+ const O = M.steps[M.at], F = y && !_e(O, l(g)), P = { ...O, widgets: [...O.widgets, ...wt(g, M.steps[0])] };
378
+ d({ ...a.state, view: F ? P : g, draft: null, catalogue: !1 }), u.current.onDraftChange?.(!1);
379
+ const { wording: L } = u.current;
380
+ U(y ? F ? L.dashboardKept : L.dashboardLeft : L.dashboardCancelled), F && u.current.onViewChange?.(P);
381
+ }, p = (y) => {
382
+ a.state.draft && d({ ...a.state, catalogue: y });
383
+ }, H = (y) => {
384
+ const { draft: g } = a.state;
379
385
  if (!g) return;
380
- const _ = g.steps[g.at], k = w(_);
381
- k !== _ && r({ ...n.state, draft: { steps: [...g.steps.slice(0, g.at + 1), k], at: g.at + 1 } });
382
- }, q = (w, g) => {
383
- const { draft: _ } = n.state;
384
- _?.steps[_.at + w] && (r({ ...n.state, draft: { ..._, at: _.at + w } }), $(g));
385
- }, T = () => q(-1, c.current.wording.dashboardUndone), G = () => q(1, c.current.wording.dashboardRedone), I = () => {
386
- n.state.draft && (B(() => o(c.current.defaultView)), $(c.current.wording.dashboardResetDone));
387
- }, W = (w, g, _) => ({
388
- allowed: w,
386
+ const M = g.steps[g.at], O = y(M);
387
+ O !== M && d({ ...a.state, draft: { steps: [...g.steps.slice(0, g.at + 1), O], at: g.at + 1 } });
388
+ }, E = (y, g) => {
389
+ const { draft: M } = a.state;
390
+ M?.steps[M.at + y] && (d({ ...a.state, draft: { ...M, at: M.at + y } }), U(g));
391
+ }, G = () => E(-1, u.current.wording.dashboardUndone), Y = () => E(1, u.current.wording.dashboardRedone), D = () => {
392
+ a.state.draft && (H(() => l(u.current.defaultView)), U(u.current.wording.dashboardResetDone));
393
+ }, $ = (y, g, M) => ({
394
+ allowed: y,
389
395
  editing: g !== null,
390
- edit: u,
391
- done: () => m(!0),
392
- cancel: () => m(!1),
393
- catalogue: _,
394
- setCatalogue: S,
395
- register: (k) => {
396
- n.types = k;
397
- const P = [...k].map(([Y, D]) => `${Y}:${D.start}:${JSON.stringify(D.sizes)}`).join("|");
398
- P !== n.signature && (n.signature = P, r({ ...n.state, known: n.state.known + 1 }));
396
+ edit: m,
397
+ done: () => h(!0),
398
+ cancel: () => h(!1),
399
+ catalogue: M,
400
+ setCatalogue: p,
401
+ register: (O) => {
402
+ a.types = O;
403
+ const F = [...O].map(([P, L]) => `${P}:${L.start}:${JSON.stringify(L.sizes)}`).join("|");
404
+ F !== a.signature && (a.signature = F, d({ ...a.state, known: a.state.known + 1 }));
399
405
  },
400
- step: B,
401
- undo: T,
402
- redo: G,
403
- reset: I,
406
+ step: H,
407
+ undo: G,
408
+ redo: Y,
409
+ reset: D,
404
410
  canUndo: !!g && g.at > 0,
405
411
  canRedo: !!g && g.at < g.steps.length - 1,
406
- canReset: !!g && !be(g.steps[g.at], o(c.current.defaultView))
412
+ canReset: !!g && !_e(g.steps[g.at], l(u.current.defaultView))
407
413
  });
408
414
  return {
409
- get: F,
410
- subscribe: V,
411
- edit: u,
412
- done: () => m(!0),
413
- cancel: () => m(!1),
414
- undo: T,
415
- redo: G,
416
- reset: I,
417
- catalogue: () => S(!0),
418
- read: o,
419
- setView: (w) => {
420
- const g = he(w) ? w : c.current.defaultView;
421
- r({ ...n.state, view: g, draft: n.state.draft ? { steps: [o(g)], at: 0 } : null });
415
+ get: A,
416
+ subscribe: W,
417
+ edit: m,
418
+ done: () => h(!0),
419
+ cancel: () => h(!1),
420
+ undo: G,
421
+ redo: Y,
422
+ reset: D,
423
+ catalogue: () => p(!0),
424
+ read: l,
425
+ setView: (y) => {
426
+ const g = ge(y) ? y : u.current.defaultView;
427
+ d({ ...a.state, view: g, draft: a.state.draft ? { steps: [l(g)], at: 0 } : null });
422
428
  },
423
- Dashboard: (w) => {
424
- const { view: g, draft: _, catalogue: k } = le(V, F, F);
425
- return ke(Mt, { ...w, view: _ ? _.steps[_.at] : g, editor: W(c.current.allowEdit, _, !!k) });
429
+ Dashboard: (y) => {
430
+ const { view: g, draft: M, catalogue: O } = fe(W, A, A);
431
+ return qe(Ht, { ...y, view: M ? M.steps[M.at] : g, editor: $(u.current.allowEdit, M, !!O) });
426
432
  }
427
433
  };
428
- }, [n]), { view: b, draft: p, known: H } = le(l.subscribe, l.get, l.get), O = p ? p.steps[p.at] : b, j = oe(() => l.read(O), [l, O, H]);
434
+ }, [a]), { view: z, draft: b, known: v } = fe(c.subscribe, c.get, c.get), V = b ? b.steps[b.at] : z, K = ie(() => c.read(V), [c, V, v]);
429
435
  return {
430
- Dashboard: l.Dashboard,
431
- WidgetType: _e,
432
- view: j,
433
- setView: l.setView,
434
- editing: p !== null,
435
- edit: l.edit,
436
- done: l.done,
437
- cancel: l.cancel,
438
- catalogue: l.catalogue,
439
- undo: l.undo,
440
- redo: l.redo,
441
- reset: l.reset
436
+ Dashboard: c.Dashboard,
437
+ WidgetType: Se,
438
+ view: K,
439
+ setView: c.setView,
440
+ editing: b !== null,
441
+ edit: c.edit,
442
+ done: c.done,
443
+ cancel: c.cancel,
444
+ catalogue: c.catalogue,
445
+ undo: c.undo,
446
+ redo: c.redo,
447
+ reset: c.reset
442
448
  };
443
449
  }
444
450
  export {
445
- mt as HeadingType,
446
- _e as WidgetType,
447
- kt as useDashboard
451
+ St as HeadingType,
452
+ Se as WidgetType,
453
+ Lt as useDashboard
448
454
  };