@alfadocs/ui-kit-debug 1.60.0 → 1.61.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.
Files changed (116) hide show
  1. package/dist/_chunks/dashboard-grid-DRnhIlT-.js +1404 -0
  2. package/dist/_chunks/dashboard-grid-DRnhIlT-.js.map +1 -0
  3. package/dist/_chunks/{marketplace-app-shell-DK2pFMpf.js → marketplace-app-shell-p6hPgVwy.js} +2 -2
  4. package/dist/_chunks/{marketplace-app-shell-DK2pFMpf.js.map → marketplace-app-shell-p6hPgVwy.js.map} +1 -1
  5. package/dist/_chunks/{sidebar-DhePV1hE.js → sidebar-C9Zof0z1.js} +526 -518
  6. package/dist/_chunks/sidebar-C9Zof0z1.js.map +1 -0
  7. package/dist/agent-catalog.json +37 -2
  8. package/dist/agent-i18n/en.json +3 -1
  9. package/dist/components/dashboard-grid/dashboard-grid-engine.d.ts +16 -4
  10. package/dist/components/dashboard-grid/dashboard-grid-engine.d.ts.map +1 -1
  11. package/dist/components/dashboard-grid/dashboard-grid.agent.d.ts.map +1 -1
  12. package/dist/components/dashboard-grid/dashboard-grid.d.ts +42 -2
  13. package/dist/components/dashboard-grid/dashboard-grid.d.ts.map +1 -1
  14. package/dist/components/dashboard-grid/index.d.ts +1 -1
  15. package/dist/components/dashboard-grid/index.d.ts.map +1 -1
  16. package/dist/components/dashboard-grid/index.js +1 -1
  17. package/dist/components/sidebar/index.js +1 -1
  18. package/dist/components/sidebar/sidebar.d.ts +6 -0
  19. package/dist/components/sidebar/sidebar.d.ts.map +1 -1
  20. package/dist/i18n/locales/ar.d.ts +1 -0
  21. package/dist/i18n/locales/ar.d.ts.map +1 -1
  22. package/dist/i18n/locales/ar.js +1 -0
  23. package/dist/i18n/locales/ar.js.map +1 -1
  24. package/dist/i18n/locales/de.d.ts +1 -0
  25. package/dist/i18n/locales/de.d.ts.map +1 -1
  26. package/dist/i18n/locales/de.js +1 -0
  27. package/dist/i18n/locales/de.js.map +1 -1
  28. package/dist/i18n/locales/el.d.ts +1 -0
  29. package/dist/i18n/locales/el.d.ts.map +1 -1
  30. package/dist/i18n/locales/el.js +1 -0
  31. package/dist/i18n/locales/el.js.map +1 -1
  32. package/dist/i18n/locales/en.d.ts +1 -0
  33. package/dist/i18n/locales/en.d.ts.map +1 -1
  34. package/dist/i18n/locales/en.js +1 -0
  35. package/dist/i18n/locales/en.js.map +1 -1
  36. package/dist/i18n/locales/es.d.ts +1 -0
  37. package/dist/i18n/locales/es.d.ts.map +1 -1
  38. package/dist/i18n/locales/es.js +1 -0
  39. package/dist/i18n/locales/es.js.map +1 -1
  40. package/dist/i18n/locales/fr.d.ts +1 -0
  41. package/dist/i18n/locales/fr.d.ts.map +1 -1
  42. package/dist/i18n/locales/fr.js +1 -0
  43. package/dist/i18n/locales/fr.js.map +1 -1
  44. package/dist/i18n/locales/hi.d.ts +1 -0
  45. package/dist/i18n/locales/hi.d.ts.map +1 -1
  46. package/dist/i18n/locales/hi.js +1 -0
  47. package/dist/i18n/locales/hi.js.map +1 -1
  48. package/dist/i18n/locales/it.d.ts +1 -0
  49. package/dist/i18n/locales/it.d.ts.map +1 -1
  50. package/dist/i18n/locales/it.js +1 -0
  51. package/dist/i18n/locales/it.js.map +1 -1
  52. package/dist/i18n/locales/ja.d.ts +1 -0
  53. package/dist/i18n/locales/ja.d.ts.map +1 -1
  54. package/dist/i18n/locales/ja.js +1 -0
  55. package/dist/i18n/locales/ja.js.map +1 -1
  56. package/dist/i18n/locales/nl.d.ts +1 -0
  57. package/dist/i18n/locales/nl.d.ts.map +1 -1
  58. package/dist/i18n/locales/nl.js +1 -0
  59. package/dist/i18n/locales/nl.js.map +1 -1
  60. package/dist/i18n/locales/pl.d.ts +1 -0
  61. package/dist/i18n/locales/pl.d.ts.map +1 -1
  62. package/dist/i18n/locales/pl.js +1 -0
  63. package/dist/i18n/locales/pl.js.map +1 -1
  64. package/dist/i18n/locales/pt.d.ts +1 -0
  65. package/dist/i18n/locales/pt.d.ts.map +1 -1
  66. package/dist/i18n/locales/pt.js +1 -0
  67. package/dist/i18n/locales/pt.js.map +1 -1
  68. package/dist/i18n/locales/ro.d.ts +1 -0
  69. package/dist/i18n/locales/ro.d.ts.map +1 -1
  70. package/dist/i18n/locales/ro.js +1 -0
  71. package/dist/i18n/locales/ro.js.map +1 -1
  72. package/dist/i18n/locales/ru.d.ts +1 -0
  73. package/dist/i18n/locales/ru.d.ts.map +1 -1
  74. package/dist/i18n/locales/ru.js +1 -0
  75. package/dist/i18n/locales/ru.js.map +1 -1
  76. package/dist/i18n/locales/sq.d.ts +1 -0
  77. package/dist/i18n/locales/sq.d.ts.map +1 -1
  78. package/dist/i18n/locales/sq.js +1 -0
  79. package/dist/i18n/locales/sq.js.map +1 -1
  80. package/dist/i18n/locales/sv.d.ts +1 -0
  81. package/dist/i18n/locales/sv.d.ts.map +1 -1
  82. package/dist/i18n/locales/sv.js +1 -0
  83. package/dist/i18n/locales/sv.js.map +1 -1
  84. package/dist/i18n/locales/tr.d.ts +1 -0
  85. package/dist/i18n/locales/tr.d.ts.map +1 -1
  86. package/dist/i18n/locales/tr.js +1 -0
  87. package/dist/i18n/locales/tr.js.map +1 -1
  88. package/dist/i18n/locales/zh.d.ts +1 -0
  89. package/dist/i18n/locales/zh.d.ts.map +1 -1
  90. package/dist/i18n/locales/zh.js +1 -0
  91. package/dist/i18n/locales/zh.js.map +1 -1
  92. package/dist/index.js +3 -3
  93. package/dist/locales/ar.json +1 -0
  94. package/dist/locales/de.json +1 -0
  95. package/dist/locales/el.json +1 -0
  96. package/dist/locales/en.json +1 -0
  97. package/dist/locales/es.json +1 -0
  98. package/dist/locales/fr.json +1 -0
  99. package/dist/locales/hi.json +1 -0
  100. package/dist/locales/it.json +1 -0
  101. package/dist/locales/ja.json +1 -0
  102. package/dist/locales/nl.json +1 -0
  103. package/dist/locales/pl.json +1 -0
  104. package/dist/locales/pt.json +1 -0
  105. package/dist/locales/ro.json +1 -0
  106. package/dist/locales/ru.json +1 -0
  107. package/dist/locales/sq.json +1 -0
  108. package/dist/locales/sv.json +1 -0
  109. package/dist/locales/tr.json +1 -0
  110. package/dist/locales/zh.json +1 -0
  111. package/dist/patterns/marketplace-app-shell/index.js +1 -1
  112. package/dist/tokens.css +1 -1
  113. package/package.json +1 -1
  114. package/dist/_chunks/dashboard-grid-DeNEltwI.js +0 -933
  115. package/dist/_chunks/dashboard-grid-DeNEltwI.js.map +0 -1
  116. package/dist/_chunks/sidebar-DhePV1hE.js.map +0 -1
@@ -0,0 +1,1404 @@
1
+ import { jsxs as pe, jsx as R } from "react/jsx-runtime";
2
+ import { forwardRef as Nt, useRef as k, useState as B, useCallback as A, useMemo as se, useEffect as q, useImperativeHandle as Pt, useContext as Wt, Children as Dt, isValidElement as Ht, Fragment as zt, createContext as Xt, cloneElement as ct } from "react";
3
+ import { c as le } from "./index-D2ZczOXr.js";
4
+ import { useTranslation as wt } from "react-i18next";
5
+ import { I as Xe } from "./icon-button-dNE6ENLn.js";
6
+ import { D as Re } from "./dropdown-menu-D1we7oAY.js";
7
+ import { T as Ft } from "./tooltip-Cp-PLePW.js";
8
+ import { u as te } from "./use-isomorphic-layout-effect-BGfaCOP1.js";
9
+ import { u as Yt } from "./registry-DvAUVLHh.js";
10
+ import { P as Ot } from "./plus-DzMQ_c6b.js";
11
+ import { X as jt } from "./x-B5YnXwCz.js";
12
+ import { G as Vt } from "./grip-vertical-onSb1JXO.js";
13
+ import { E as $t } from "./ellipsis-dRo9ouSU.js";
14
+ import { c as Kt } from "./createLucideIcon-DhHxpK9K.js";
15
+ /**
16
+ * @license lucide-react v1.22.0 - ISC
17
+ *
18
+ * This source code is licensed under the ISC license.
19
+ * See the LICENSE file in the root directory of this source tree.
20
+ */
21
+ const Ut = [
22
+ ["path", { d: "M19 13v6h-6", key: "1hxl6d" }],
23
+ ["path", { d: "M5 11V5h6", key: "12e2xe" }],
24
+ ["path", { d: "m5 5 14 14", key: "11anup" }]
25
+ ], qt = Kt("move-diagonal-2", Ut), Bt = {
26
+ id: "dashboard-grid",
27
+ // The board's whole purpose is in-place rearrangement of its widgets.
28
+ // `scroll` is backed by reveal_widget (the catalogue's name heuristic
29
+ // cannot see that and warns).
30
+ capabilities: ["edit_inline", "scroll"],
31
+ state: {
32
+ layout: {
33
+ type: "{ id: string, x: number, y: number, w: number, h: number }[]",
34
+ descriptionKey: "ui.agent.dashboardGrid.state.layout",
35
+ description: "Current widget geometry in cell units — ids and rectangles only, no widget content.",
36
+ read: (r) => r.getGridState().layout
37
+ },
38
+ cols: {
39
+ type: "number",
40
+ descriptionKey: "ui.agent.dashboardGrid.state.cols",
41
+ description: "Logical column count of the board.",
42
+ read: (r) => r.getGridState().cols
43
+ },
44
+ editing: {
45
+ type: "boolean",
46
+ descriptionKey: "ui.agent.dashboardGrid.state.editing",
47
+ description: "Whether edit mode is on. Move/resize actions are refused while it is off — the host app owns the toggle.",
48
+ read: (r) => r.getGridState().editing
49
+ },
50
+ stacked: {
51
+ type: "boolean",
52
+ descriptionKey: "ui.agent.dashboardGrid.state.stacked",
53
+ description: "Whether the board is narrower than its stackBelow width and shows its widgets as one read-only column. Move/resize actions are unavailable while it is true, even in edit mode; the saved layout is unchanged.",
54
+ read: (r) => r.getGridState().stacked
55
+ },
56
+ selectedId: {
57
+ type: "string | null",
58
+ descriptionKey: "ui.agent.dashboardGrid.state.selectedId",
59
+ description: "The widget the host has marked (for example while its settings are open), or null. Set by the host, not by agents.",
60
+ read: (r) => r.getGridState().selectedId
61
+ }
62
+ },
63
+ actions: {
64
+ reveal_widget: {
65
+ // Scrolls the view and rings a widget for a moment; changes nothing.
66
+ safety: "read",
67
+ argsType: "id",
68
+ argsSchema: {
69
+ type: "object",
70
+ properties: {
71
+ id: { type: "string", description: "Widget id (see layout state)." }
72
+ },
73
+ required: ["id"]
74
+ },
75
+ returns: "Promise<boolean> (revealed)",
76
+ returnsSchema: {
77
+ type: "boolean",
78
+ description: "True once the widget is in view; false if it has not appeared within a second."
79
+ },
80
+ idempotent: !0,
81
+ errors: [
82
+ "Unknown or not yet rendered widget id: waits up to a second, then resolves false."
83
+ ],
84
+ descriptionKey: "ui.agent.dashboardGrid.actions.revealWidget",
85
+ description: "Scroll a widget into view (its scrolling ancestor and the window) and highlight it briefly. Works in view and edit mode, and for a widget added a moment ago. Does not move focus.",
86
+ invoke: (r, s) => r.revealWidget(s.id)
87
+ },
88
+ move_widget: {
89
+ // Rearranging the board mutates user configuration — a write,
90
+ // reversible by moving back.
91
+ safety: "write",
92
+ argsType: "id, x, y",
93
+ argsSchema: {
94
+ type: "object",
95
+ properties: {
96
+ id: { type: "string", description: "Widget id (see layout state)." },
97
+ x: {
98
+ type: "integer",
99
+ minimum: 0,
100
+ description: "0-based logical column."
101
+ },
102
+ y: { type: "integer", minimum: 0, description: "0-based row." }
103
+ },
104
+ required: ["id", "x", "y"]
105
+ },
106
+ returns: "boolean (accepted)",
107
+ returnsSchema: {
108
+ type: "boolean",
109
+ description: "True when applied; false when edit mode is off, the board is stacked, or the id is unknown."
110
+ },
111
+ idempotent: !0,
112
+ errors: [
113
+ "Unavailable while the board is stacked (state stacked is true): returns false and changes nothing.",
114
+ "Unavailable while edit mode is off: returns false.",
115
+ "Unknown widget id: returns false."
116
+ ],
117
+ descriptionKey: "ui.agent.dashboardGrid.actions.moveWidget",
118
+ description: "Move a widget to a cell. Out-of-bounds targets are clamped; colliding widgets are pushed down and the layout re-compacts. Refused while edit mode is off or the board is stacked.",
119
+ invoke: (r, s) => r.moveWidgetTo(s.id, s.x, s.y)
120
+ },
121
+ resize_widget: {
122
+ safety: "write",
123
+ argsType: "id, w, h",
124
+ argsSchema: {
125
+ type: "object",
126
+ properties: {
127
+ id: { type: "string", description: "Widget id (see layout state)." },
128
+ w: {
129
+ type: "integer",
130
+ minimum: 1,
131
+ description: "Column span (≥ 1)."
132
+ },
133
+ h: { type: "integer", minimum: 1, description: "Row span (≥ 1)." }
134
+ },
135
+ required: ["id", "w", "h"]
136
+ },
137
+ returns: "boolean (accepted)",
138
+ returnsSchema: {
139
+ type: "boolean",
140
+ description: "True when applied; false when edit mode is off, the board is stacked, or the id is unknown."
141
+ },
142
+ idempotent: !0,
143
+ errors: [
144
+ "Unavailable while the board is stacked (state stacked is true): returns false and changes nothing.",
145
+ "Unavailable while edit mode is off: returns false.",
146
+ "Unknown widget id: returns false."
147
+ ],
148
+ descriptionKey: "ui.agent.dashboardGrid.actions.resizeWidget",
149
+ description: "Resize a widget to a span. Clamped to the grid and the widget’s min/max; colliding widgets are pushed down. Refused while edit mode is off or the board is stacked.",
150
+ invoke: (r, s) => r.resizeWidgetTo(s.id, s.w, s.h)
151
+ }
152
+ },
153
+ domHooks: {
154
+ root: {
155
+ attr: "data-component",
156
+ value: "dashboard-grid",
157
+ description: 'Also carries data-stacked="true" while the board shows one read-only column.'
158
+ },
159
+ instanceId: {
160
+ attr: "data-component-id",
161
+ sourceProp: "id",
162
+ description: "Sourced from the id prop."
163
+ },
164
+ item: {
165
+ attr: "data-widget-id",
166
+ description: "Each widget wrapper carries its layout id."
167
+ }
168
+ }
169
+ };
170
+ function H(r, s) {
171
+ return r.x < s.x + s.w && s.x < r.x + r.w && r.y < s.y + s.h && s.y < r.y + r.h;
172
+ }
173
+ function Ie(r, s) {
174
+ const i = Math.max(1, r.minW ?? 1), l = Math.max(1, r.minH ?? 1), g = Math.min(s, r.maxW ?? s), N = r.maxH ?? Number.POSITIVE_INFINITY, m = Math.min(Math.max(r.w, i), g), a = Math.min(Math.max(r.h, l), N), L = Math.min(Math.max(0, r.x), s - m), w = Math.max(0, r.y);
175
+ return { ...r, x: L, y: w, w: m, h: a };
176
+ }
177
+ function lt(r, s) {
178
+ if (s.some((i) => H(i, r))) return !1;
179
+ for (let i = r.y; i < r.y + r.h; i += 1)
180
+ if (!s.some(
181
+ (g) => g.x >= r.x + r.w && i >= g.y && i < g.y + g.h
182
+ )) return !1;
183
+ return !0;
184
+ }
185
+ function ut(r, s, i) {
186
+ return Math.abs(r.y * i + r.x - (s.y * i + s.x));
187
+ }
188
+ function ie(r, s, i, l) {
189
+ const g = r.map((o) => Ie(o, s)), N = [...g].sort((o, h) => o.id === i ? -1 : h.id === i ? 1 : o.y - h.y || o.x - h.x), m = [], a = i ? g.find((o) => o.id === i) : void 0, L = /* @__PURE__ */ new Set();
190
+ for (const o of N) {
191
+ if (o.id !== i) {
192
+ if (a && H(a, o)) {
193
+ const h = { ...o, y: Math.max(0, a.y - o.h) };
194
+ !H(a, h) && !m.some((M) => M.id !== i && H(M, h)) && (o.y = h.y);
195
+ }
196
+ if (m.some((h) => H(h, o))) {
197
+ L.add(o.id);
198
+ const h = g.filter((y) => y.id !== o.id);
199
+ let M = o.y;
200
+ for (; m.some((y) => H(y, { ...o, y: M })); )
201
+ M += 1;
202
+ let _ = null;
203
+ for (let y = Math.max(0, o.y - o.h); y <= M; y += 1)
204
+ for (let S = 0; S <= s - o.w; S += 1) {
205
+ const D = { ...o, x: S, y };
206
+ (lt(D, h) || l !== void 0 && H(l, D) && !h.some((z) => H(z, D))) && (!_ || ut({ x: S, y }, o, s) < ut(_, o, s)) && (_ = { x: S, y });
207
+ }
208
+ if (_)
209
+ o.x = _.x, o.y = _.y;
210
+ else {
211
+ o.y = M;
212
+ const y = a !== void 0 && a.x < o.x && o.x < a.x + a.w, S = a ? a.x : o.x;
213
+ for (; y && o.x > S && !h.some((D) => H(D, { ...o, x: o.x - 1 })); )
214
+ o.x -= 1;
215
+ }
216
+ }
217
+ for (; m.some((h) => H(h, o)); )
218
+ o.y += 1;
219
+ for (; o.y > 0; ) {
220
+ const h = { ...o, y: o.y - 1 };
221
+ if (m.some((M) => H(M, h))) break;
222
+ o.y -= 1;
223
+ }
224
+ }
225
+ m.push(o);
226
+ }
227
+ const w = a ? [...m].sort((o, h) => o.y - h.y || o.x - h.x) : [];
228
+ for (const o of w) {
229
+ if (o.id === i || L.has(o.id)) continue;
230
+ const h = m.filter((_) => _.id !== o.id);
231
+ let M = null;
232
+ for (let _ = 0; _ < o.y && !M; _ += 1) {
233
+ const y = Array.from(
234
+ { length: 2 * o.w + 1 },
235
+ (S, D) => o.x - o.w + D
236
+ ).filter((S) => S >= 0 && S <= s - o.w).sort((S, D) => Math.abs(S - o.x) - Math.abs(D - o.x) || S - D);
237
+ for (const S of y)
238
+ if (lt({ ...o, x: S, y: _ }, h)) {
239
+ M = { x: S, y: _ };
240
+ break;
241
+ }
242
+ }
243
+ if (M)
244
+ for (o.x = M.x, o.y = M.y; o.y > 0; ) {
245
+ const _ = { ...o, y: o.y - 1 };
246
+ if (h.some((y) => H(y, _))) break;
247
+ o.y -= 1;
248
+ }
249
+ }
250
+ const T = new Map(m.map((o) => [o.id, o]));
251
+ return r.map((o) => T.get(o.id));
252
+ }
253
+ function Jt(r, s, i, l, g) {
254
+ const N = r.map(
255
+ (m) => m.id === s ? Ie({ ...m, x: i, y: l }, g) : m
256
+ );
257
+ return ie(
258
+ N,
259
+ g,
260
+ s,
261
+ r.find((m) => m.id === s)
262
+ );
263
+ }
264
+ function Qt(r, s, i, l, g) {
265
+ const N = r.map(
266
+ (m) => m.id === s ? (
267
+ // Resizing never moves the widget: the width clamps to the space
268
+ // between its position and the grid edge (clampRect would slide it).
269
+ // minW wins over the edge clamp so clampRect cannot re-raise w and
270
+ // slide x as a side effect.
271
+ Ie(
272
+ {
273
+ ...m,
274
+ w: Math.max(m.minW ?? 1, Math.min(i, g - m.x)),
275
+ h: l
276
+ },
277
+ g
278
+ )
279
+ ) : m
280
+ );
281
+ return ie(N, g, s);
282
+ }
283
+ function ft(r, s, i, l) {
284
+ const g = Math.min(Math.max(1, i), s), N = r.reduce((m, a) => Math.max(m, a.y + a.h), 0);
285
+ for (let m = 0; m <= N; m += 1)
286
+ for (let a = 0; a <= s - g; a += 1) {
287
+ const L = {
288
+ x: a,
289
+ y: m,
290
+ w: g,
291
+ h: l
292
+ };
293
+ if (!r.some((w) => H(w, L)))
294
+ return { x: a, y: m };
295
+ }
296
+ return { x: 0, y: N };
297
+ }
298
+ function yt(r) {
299
+ return r.reduce((s, i) => Math.max(s, i.y + i.h), 0);
300
+ }
301
+ const Zt = 24;
302
+ function mt(r, s, i) {
303
+ return s === void 0 || !Number.isFinite(s) || s <= 0 ? !1 : !Number.isFinite(r) || r <= 0 ? i : i ? r < s + Zt : r < s;
304
+ }
305
+ function er(r, s) {
306
+ const i = new Map(s.map((l) => [l.id, l]));
307
+ return r.map((l, g) => ({ id: l, index: g, entry: i.get(l) })).sort((l, g) => !l.entry || !g.entry ? l.entry ? -1 : g.entry ? 1 : l.index - g.index : l.entry.y - g.entry.y || l.entry.x - g.entry.x || l.index - g.index).map(({ id: l }) => l);
308
+ }
309
+ const tr = le(
310
+ [
311
+ "ds:grid ds:w-full",
312
+ // A stacking context: a grabbed widget's lift stays inside the board.
313
+ "ds:isolate",
314
+ "ds:gap-[var(--spacing-md)]",
315
+ // Edit-mode surface: tint the whole plane, draw faint cell lines, and
316
+ // reserve spare rows (--dg-min-block) so the AVAILABLE space reads at
317
+ // a glance instead of the board ending at the last occupied row.
318
+ "ds:data-[editing=true]:rounded-[var(--radius-lg)] ds:data-[editing=true]:bg-muted/10",
319
+ "ds:data-[editing=true]:[background-image:var(--dg-grid-lines)]",
320
+ "ds:data-[editing=true]:min-h-[var(--dg-min-block)]"
321
+ ].join(" "),
322
+ {
323
+ variants: {
324
+ // Stacked: one full-width column; each row takes its widget's block
325
+ // size. Focus can fall back to the board here (see the focus effect),
326
+ // so it gets the kit's focus ring.
327
+ stacked: {
328
+ false: [
329
+ "ds:[grid-template-columns:repeat(var(--dg-cols),minmax(0,1fr))]",
330
+ "ds:[grid-auto-rows:var(--dg-row)]"
331
+ ].join(" "),
332
+ true: [
333
+ "ds:grid-cols-1 ds:auto-rows-auto",
334
+ "ds:focus-visible:outline-[length:var(--focus-ring-width)] ds:focus-visible:outline-solid ds:focus-visible:outline-ring ds:focus-visible:outline-offset-[length:var(--focus-ring-offset)]"
335
+ ].join(" ")
336
+ }
337
+ },
338
+ defaultVariants: { stacked: !1 }
339
+ }
340
+ ), rr = le(
341
+ [
342
+ "ds:relative ds:min-h-0 ds:min-w-0 ds:overflow-hidden",
343
+ // Its own stacking context: a sticky or raised layer inside a widget
344
+ // can never paint over the page's chrome (a sticky toolbar, say).
345
+ "ds:isolate",
346
+ // Header actions fold into one menu below a set widget width.
347
+ "ds:@container/widget",
348
+ // Mirror of Card variant="elevated" so widgets read as kit cards.
349
+ "ds:rounded-[var(--radius-lg)] ds:bg-[var(--card)] ds:text-[var(--card-foreground)]",
350
+ "ds:[:where(&)]:border-[length:var(--surface-border-width,var(--border-width-sm))] ds:border-[color:var(--card-border)] ds:shadow-[var(--shadow-card)]",
351
+ // Grabbed feedback (keyboard or pointer drag in flight).
352
+ "ds:data-[grabbed=true]:ring-[length:var(--focus-ring-width)] ds:data-[grabbed=true]:ring-ring ds:data-[grabbed=true]:z-10",
353
+ // Selected (and briefly revealed): an inset edge in --primary, the
354
+ // kit's selected colour, so it reads apart from focus and from a grab.
355
+ "ds:data-[selected=true]:ring-[length:var(--border-width-md)] ds:data-[selected=true]:ring-inset ds:data-[selected=true]:ring-[color:var(--primary)]",
356
+ "ds:data-[revealed=true]:ring-[length:var(--border-width-md)] ds:data-[revealed=true]:ring-inset ds:data-[revealed=true]:ring-[color:var(--primary)]",
357
+ "ds:forced-colors:data-[selected=true]:outline-[length:var(--border-width-md)] ds:forced-colors:data-[selected=true]:outline-solid ds:forced-colors:data-[selected=true]:outline-[Highlight]",
358
+ // Only reachable when stacking removes the focused edit control: the
359
+ // widget then takes focus itself (tabindex -1, set at that moment).
360
+ "ds:focus-visible:outline-[length:var(--focus-ring-width)] ds:focus-visible:outline-solid ds:focus-visible:outline-ring ds:focus-visible:outline-offset-[length:var(--focus-ring-offset)]"
361
+ ].join(" "),
362
+ {
363
+ variants: {
364
+ stacked: {
365
+ false: [
366
+ "ds:[grid-column-start:var(--dg-x)] ds:[grid-column-end:span_var(--dg-w)]",
367
+ "ds:[grid-row-start:var(--dg-y)] ds:[grid-row-end:span_var(--dg-h)]"
368
+ ].join(" "),
369
+ true: "ds:col-span-full ds:row-auto"
370
+ },
371
+ stackedHeight: { grid: "", content: "" }
372
+ },
373
+ compoundVariants: [
374
+ { stacked: !1, class: "ds:flex ds:flex-col" },
375
+ // At least the block size the widget has in the grid (h rows plus the
376
+ // h - 1 gaps). A minimum, not a fixed size: at 200% zoom the widget
377
+ // grows instead of clipping its content (WCAG 1.4.4, 1.4.10).
378
+ {
379
+ stacked: !0,
380
+ stackedHeight: "grid",
381
+ class: [
382
+ "ds:flex ds:flex-col",
383
+ "ds:[min-block-size:calc(var(--dg-h)*var(--dg-row)_+_(var(--dg-h)_-_1)*var(--spacing-md))]"
384
+ ].join(" ")
385
+ },
386
+ // As tall as the content, or minStackedHeight. A grid, not a flex
387
+ // column, so the body row is a definite box a 100% chart can fill.
388
+ {
389
+ stacked: !0,
390
+ stackedHeight: "content",
391
+ class: [
392
+ "ds:grid ds:grid-cols-[minmax(0,1fr)] ds:grid-rows-[auto_1fr]",
393
+ "ds:[min-block-size:var(--dg-min-stacked)]"
394
+ ].join(" ")
395
+ }
396
+ ],
397
+ defaultVariants: { stacked: !1, stackedHeight: "grid" }
398
+ }
399
+ ), nr = le(
400
+ "ds:ps-[var(--spacing-md)] ds:pt-[var(--spacing-xs)]",
401
+ {
402
+ variants: {
403
+ // `box`: fill the widget's block size and clip to it. `content`: take
404
+ // the content's own height (the content-height stack), never a box.
405
+ fit: {
406
+ box: "ds:min-h-0 ds:flex-1 ds:overflow-hidden",
407
+ content: "ds:min-w-0"
408
+ },
409
+ // Editing: clear of the resize grip's whole hit area, a
410
+ // --min-target-size square in the corner. Block-end takes the full
411
+ // size, keeping the width narrow widgets need; inline-end the glyph.
412
+ editing: {
413
+ false: "ds:pe-[var(--spacing-md)] ds:pb-[var(--spacing-md)]",
414
+ true: [
415
+ "ds:pe-[calc(var(--spacing-lg)_+_var(--spacing-2xs))]",
416
+ "ds:pb-[var(--min-target-size)]"
417
+ ].join(" ")
418
+ }
419
+ },
420
+ defaultVariants: { fit: "box", editing: !1 }
421
+ }
422
+ ), sr = le(
423
+ [
424
+ "ds:absolute ds:bottom-[var(--spacing-2xs)] ds:end-[var(--spacing-2xs)]",
425
+ "ds:inline-flex ds:size-[var(--spacing-lg)] ds:items-center ds:justify-center",
426
+ "ds:rounded-[var(--radius-sm)] ds:text-[var(--muted-foreground)] ds:touch-none",
427
+ "ds:cursor-nwse-resize ds:rtl:cursor-nesw-resize",
428
+ "ds:hover:bg-muted/20 ds:hover:text-[var(--foreground)]",
429
+ "ds:aria-pressed:bg-muted/20 ds:aria-pressed:text-[var(--foreground)]",
430
+ "ds:[&_svg]:size-3.5 ds:rtl:[&_svg]:-scale-x-100",
431
+ "ds:before:absolute ds:before:content-['']",
432
+ "ds:before:bottom-[calc(-1*var(--spacing-2xs))] ds:before:end-[calc(-1*var(--spacing-2xs))]",
433
+ "ds:before:size-[var(--min-target-size)]",
434
+ "ds:focus-visible:outline-[length:var(--focus-ring-width)] ds:focus-visible:outline-solid ds:focus-visible:outline-ring ds:focus-visible:outline-offset-[length:var(--focus-ring-offset)]"
435
+ ].join(" ")
436
+ ), pt = le(
437
+ "ds:items-center ds:gap-[calc(var(--min-target-size)_-_var(--spacing-xl))]",
438
+ {
439
+ variants: {
440
+ when: {
441
+ always: "ds:flex",
442
+ wide: "ds:flex ds:@max-[300px]/widget:hidden",
443
+ narrow: "ds:hidden ds:@max-[300px]/widget:flex"
444
+ }
445
+ },
446
+ defaultVariants: { when: "always" }
447
+ }
448
+ ), Fe = "ds:bg-[var(--card)] ds:data-[component=icon-button]:sm:before:block", ir = le(
449
+ "ds:flex ds:items-center ds:gap-[var(--spacing-xs)] ds:ps-[var(--spacing-sm)] ds:pe-[var(--spacing-sm)] ds:pt-[var(--spacing-sm)]",
450
+ {
451
+ variants: {
452
+ editing: {
453
+ false: "",
454
+ true: "ds:cursor-grab ds:select-none ds:[-webkit-touch-callout:none]"
455
+ }
456
+ },
457
+ defaultVariants: { editing: !1 }
458
+ }
459
+ ), or = le(
460
+ [
461
+ "ds:m-0 ds:min-w-0 ds:flex-1 ds:truncate ds:text-sm ds:font-medium",
462
+ "ds:rounded-[var(--radius-sm)]",
463
+ "ds:focus-visible:outline-[length:var(--focus-ring-width)] ds:focus-visible:outline-solid ds:focus-visible:outline-ring ds:focus-visible:outline-offset-[length:var(--focus-ring-offset)]"
464
+ ].join(" ")
465
+ ), xt = Xt(
466
+ null
467
+ );
468
+ function gt(r) {
469
+ return r !== void 0 && Number.isFinite(r) && r >= 1 ? Math.floor(r) : void 0;
470
+ }
471
+ function Le(r, s) {
472
+ Dt.forEach(r, (i) => {
473
+ if (Ht(i)) {
474
+ if (i.type === zt) {
475
+ Le(
476
+ i.props.children,
477
+ s
478
+ );
479
+ return;
480
+ }
481
+ s(i);
482
+ }
483
+ });
484
+ }
485
+ function kt({
486
+ id: r,
487
+ title: s,
488
+ minStackedHeight: i,
489
+ actions: l,
490
+ actionsSlot: g,
491
+ children: N
492
+ }) {
493
+ var V, ue, oe;
494
+ const { t: m } = wt("ui"), a = Wt(xt), L = k(null), w = a == null ? void 0 : a.layoutById.get(r), [T, o] = B(null), [h, M] = B(!1), [_, y] = B(!1), [S, D] = B(!1);
495
+ if (q(() => {
496
+ if (!T) return;
497
+ const u = () => M(T.scrollWidth > T.clientWidth);
498
+ u();
499
+ const J = typeof document < "u" ? document.fonts : void 0;
500
+ J == null || J.addEventListener("loadingdone", u);
501
+ const $ = typeof ResizeObserver > "u" ? void 0 : new ResizeObserver(u);
502
+ return $ == null || $.observe(T), () => {
503
+ J == null || J.removeEventListener("loadingdone", u), $ == null || $.disconnect();
504
+ };
505
+ }, [T, s]), q(() => {
506
+ h || D(!1);
507
+ }, [h]), te(() => {
508
+ const u = L.current;
509
+ !u || !w || (u.style.setProperty("--dg-x", String(w.x + 1)), u.style.setProperty("--dg-y", String(w.y + 1)), u.style.setProperty("--dg-w", String(w.w)), u.style.setProperty("--dg-h", String(w.h)), u.style.setProperty(
510
+ "--dg-min-stacked",
511
+ i !== void 0 && Number.isFinite(i) && i > 0 ? `${i}px` : "auto"
512
+ ));
513
+ }, [w == null ? void 0 : w.x, w == null ? void 0 : w.y, w == null ? void 0 : w.w, w == null ? void 0 : w.h, w, i]), !a || !w) return null;
514
+ const G = ((V = a.grab) == null ? void 0 : V.id) === r, z = a.editing, I = [
515
+ ...l ?? [],
516
+ ...z && a.canRemove ? [
517
+ {
518
+ id: "__remove__",
519
+ label: m("dashboardGrid.remove", { title: s }),
520
+ icon: /* @__PURE__ */ R(jt, {}),
521
+ onSelect: () => a.requestRemove(r)
522
+ }
523
+ ] : []
524
+ ], E = I.length > 1, Ae = a.headingLevel ? `h${a.headingLevel}` : "span";
525
+ return /* @__PURE__ */ pe(
526
+ "div",
527
+ {
528
+ ref: L,
529
+ role: "listitem",
530
+ "aria-label": s,
531
+ "data-component": "dashboard-grid-widget",
532
+ "data-widget-id": r,
533
+ "data-grabbed": G || void 0,
534
+ "data-selected": a.selectedId === r || void 0,
535
+ "data-revealed": a.revealedId === r || void 0,
536
+ "aria-current": a.selectedId === r ? "true" : void 0,
537
+ className: rr({
538
+ stacked: a.stacked,
539
+ stackedHeight: a.stackedHeight
540
+ }),
541
+ children: [
542
+ /* @__PURE__ */ pe(
543
+ "div",
544
+ {
545
+ className: ir({ editing: z }),
546
+ onPointerDown: z ? (u) => a.startHeaderPress(r, u) : void 0,
547
+ children: [
548
+ z ? /* @__PURE__ */ R(
549
+ Xe,
550
+ {
551
+ size: "sm",
552
+ intent: "outline",
553
+ type: "button",
554
+ icon: /* @__PURE__ */ R(Vt, {}),
555
+ "aria-label": m("dashboardGrid.move", { title: s }),
556
+ "aria-pressed": G && ((ue = a.grab) == null ? void 0 : ue.kind) === "move",
557
+ className: `ds:cursor-grab ds:touch-none ${Fe}`,
558
+ onPointerDown: (u) => a.startPointerGrab("move", r, u),
559
+ onKeyDown: (u) => a.keyboardStep(u, r),
560
+ onClick: () => a.startKeyboardGrab("move", r)
561
+ }
562
+ ) : null,
563
+ /* @__PURE__ */ R(
564
+ Ft,
565
+ {
566
+ label: s,
567
+ open: h && S,
568
+ onOpenChange: (u) => D(u && h),
569
+ children: /* @__PURE__ */ R(
570
+ Ae,
571
+ {
572
+ ref: o,
573
+ tabIndex: h || _ ? 0 : void 0,
574
+ "data-dashboard-grid-title": "",
575
+ onFocus: () => y(!0),
576
+ onBlur: () => y(!1),
577
+ className: or(),
578
+ children: s
579
+ }
580
+ )
581
+ }
582
+ ),
583
+ g,
584
+ I.length > 0 ? /* @__PURE__ */ R(
585
+ "div",
586
+ {
587
+ className: pt({
588
+ when: E ? "wide" : "always"
589
+ }),
590
+ children: I.map((u) => /* @__PURE__ */ R(
591
+ Xe,
592
+ {
593
+ size: "sm",
594
+ intent: "outline",
595
+ type: "button",
596
+ icon: u.icon,
597
+ className: Fe,
598
+ "aria-label": u.label,
599
+ onClick: u.onSelect
600
+ },
601
+ u.id
602
+ ))
603
+ }
604
+ ) : null,
605
+ E ? /* @__PURE__ */ R("div", { className: pt({ when: "narrow" }), children: /* @__PURE__ */ pe(Re.Root, { modal: !1, children: [
606
+ /* @__PURE__ */ R(Re.Trigger, { asChild: !0, children: /* @__PURE__ */ R(
607
+ Xe,
608
+ {
609
+ size: "sm",
610
+ intent: "outline",
611
+ type: "button",
612
+ icon: /* @__PURE__ */ R($t, {}),
613
+ className: Fe,
614
+ "aria-label": m("dashboardGrid.moreActions", { title: s })
615
+ }
616
+ ) }),
617
+ /* @__PURE__ */ R(Re.Content, { align: "end", children: I.map((u) => /* @__PURE__ */ R(
618
+ Re.Item,
619
+ {
620
+ startIcon: u.icon,
621
+ onSelect: u.onSelect,
622
+ children: u.label
623
+ },
624
+ u.id
625
+ )) })
626
+ ] }) }) : null
627
+ ]
628
+ }
629
+ ),
630
+ /* @__PURE__ */ R(
631
+ "div",
632
+ {
633
+ className: nr({
634
+ fit: a.stacked && a.stackedHeight === "content" ? "content" : "box",
635
+ editing: z
636
+ }),
637
+ children: N
638
+ }
639
+ ),
640
+ z ? /* @__PURE__ */ R(
641
+ "button",
642
+ {
643
+ type: "button",
644
+ "aria-label": m("dashboardGrid.resize", { title: s }),
645
+ "aria-pressed": G && ((oe = a.grab) == null ? void 0 : oe.kind) === "resize",
646
+ className: sr(),
647
+ onPointerDown: (u) => a.startPointerGrab("resize", r, u),
648
+ onKeyDown: (u) => a.keyboardStep(u, r),
649
+ onClick: () => a.startKeyboardGrab("resize", r),
650
+ children: /* @__PURE__ */ R(qt, { "aria-hidden": "true" })
651
+ }
652
+ ) : null
653
+ ]
654
+ }
655
+ );
656
+ }
657
+ kt.displayName = "DashboardGrid.Widget";
658
+ const ht = 1e3, dr = 1600, ar = [
659
+ "button",
660
+ "a",
661
+ "input",
662
+ "select",
663
+ "textarea",
664
+ "label",
665
+ "summary",
666
+ '[contenteditable]:not([contenteditable="false"])',
667
+ '[role="button"]',
668
+ '[role="menuitem"]',
669
+ "[tabindex]:not([data-dashboard-grid-title])"
670
+ ].join(", "), vt = 4, cr = 400, lr = 8, Ye = 48, ur = 18;
671
+ function fr(r) {
672
+ const s = {
673
+ x: null,
674
+ y: null
675
+ }, i = (l) => l === "auto" || l === "scroll" || l === "overlay";
676
+ for (let l = r.parentElement; l && l !== document.body && l !== document.documentElement && !(s.x && s.y); l = l.parentElement) {
677
+ const g = window.getComputedStyle(l);
678
+ !s.y && i(g.overflowY) && l.scrollHeight > l.clientHeight && (s.y = l), !s.x && i(g.overflowX) && l.scrollWidth > l.clientWidth && (s.x = l);
679
+ }
680
+ return s;
681
+ }
682
+ function me(r, s, i, l, g, N, m = !0) {
683
+ const a = r.find((h) => h.id === i);
684
+ if (!a) return r;
685
+ const L = m ? yt(r) + 2 : Number.POSITIVE_INFINITY, w = s === "move" ? Jt(r, i, l, Math.min(g, L - a.h), N) : Qt(r, i, l, Math.min(g, L - a.y), N), T = w.find((h) => h.id === i);
686
+ return T !== void 0 && T.x === a.x && T.y === a.y && T.w === a.w && T.h === a.h ? r : w;
687
+ }
688
+ function bt(r) {
689
+ if (r >= Ye) return 0;
690
+ const s = (Ye - Math.max(0, r)) / Ye;
691
+ return Math.ceil(s * ur);
692
+ }
693
+ const Mt = Nt(
694
+ ({
695
+ "aria-label": r,
696
+ id: s,
697
+ cols: i = 12,
698
+ rowHeight: l = 96,
699
+ layout: g,
700
+ defaultLayout: N,
701
+ onLayoutChange: m,
702
+ editing: a = !1,
703
+ onRemoveWidget: L,
704
+ onRequestAdd: w,
705
+ stackBelow: T,
706
+ onStackedChange: o,
707
+ stackedHeight: h = "grid",
708
+ selectedId: M,
709
+ widgetHeadingLevel: _,
710
+ children: y,
711
+ className: S
712
+ }, D) => {
713
+ const { t: G } = wt("ui"), z = k(null), I = k(null), [E, Ae] = B(!1), V = k(!1);
714
+ V.current = E;
715
+ const ue = k(null), oe = A((e) => {
716
+ var d;
717
+ if (e === V.current) return;
718
+ const t = z.current, n = typeof document < "u" ? document.activeElement : null;
719
+ ue.current = t && n instanceof HTMLElement && t.contains(n) ? {
720
+ element: n,
721
+ widgetId: ((d = n.closest("[data-widget-id]")) == null ? void 0 : d.getAttribute("data-widget-id")) ?? null
722
+ } : null, V.current = e, Ae(e);
723
+ }, []);
724
+ te(() => {
725
+ const e = z.current;
726
+ if (!e) return;
727
+ if (T === void 0) {
728
+ oe(!1);
729
+ return;
730
+ }
731
+ if (oe(
732
+ mt(e.offsetWidth, T, V.current)
733
+ ), typeof ResizeObserver > "u") return;
734
+ const t = new ResizeObserver((n) => {
735
+ var c, v;
736
+ const d = n[n.length - 1];
737
+ if (!d) return;
738
+ const f = ((v = (c = d.borderBoxSize) == null ? void 0 : c[0]) == null ? void 0 : v.inlineSize) ?? d.contentRect.width;
739
+ oe(mt(f, T, V.current));
740
+ });
741
+ return t.observe(e), () => t.disconnect();
742
+ }, [T, oe]);
743
+ const u = a && !E, J = se(() => {
744
+ const e = [];
745
+ return Le(y, (t) => {
746
+ t.props.id && e.push(t.props.id);
747
+ }), e;
748
+ }, [y]), $ = se(() => {
749
+ const e = /* @__PURE__ */ new Map();
750
+ return Le(y, (t) => {
751
+ t.props.id && e.set(t.props.id, {
752
+ defaultW: t.props.defaultW ?? 4,
753
+ defaultH: t.props.defaultH ?? 2,
754
+ minW: gt(t.props.minW),
755
+ minH: gt(t.props.minH)
756
+ });
757
+ }), e;
758
+ }, [y]), [St, Gt] = B(() => N ?? []), ye = g ?? St, Oe = k(ye);
759
+ Oe.current = ye;
760
+ const xe = A(
761
+ (e) => e.map((t) => {
762
+ const n = Oe.current.find((v) => v.id === t.id), { minW: d, minH: f, ...c } = t;
763
+ return {
764
+ ...c,
765
+ ...(n == null ? void 0 : n.minW) !== void 0 ? { minW: n.minW } : {},
766
+ ...(n == null ? void 0 : n.minH) !== void 0 ? { minH: n.minH } : {}
767
+ };
768
+ }),
769
+ []
770
+ ), Q = A(
771
+ (e) => {
772
+ const t = xe(e);
773
+ g === void 0 && Gt(t), m == null || m(t);
774
+ },
775
+ [g, m, xe]
776
+ ), { resolved: W, autoPlaced: je } = se(() => {
777
+ const e = (f) => {
778
+ const c = $.get(f.id);
779
+ return Ie(
780
+ {
781
+ ...f,
782
+ ...(c == null ? void 0 : c.minW) !== void 0 ? { minW: Math.max(f.minW ?? 1, c.minW) } : {},
783
+ ...(c == null ? void 0 : c.minH) !== void 0 ? { minH: Math.max(f.minH ?? 1, c.minH) } : {}
784
+ },
785
+ i
786
+ );
787
+ }, t = ye.map(e), n = J.filter(
788
+ (f) => !t.some((c) => c.id === f)
789
+ );
790
+ if (n.length === 0)
791
+ return {
792
+ resolved: t.some(
793
+ (c, v) => t.some((x, p) => p > v && H(c, x))
794
+ ) ? ie(t, i) : t,
795
+ autoPlaced: !1
796
+ };
797
+ const d = [...t];
798
+ for (const f of n) {
799
+ const c = $.get(f) ?? { defaultW: 4, defaultH: 2 }, v = Math.min(Math.max(c.defaultW, c.minW ?? 1), i), x = Math.max(c.defaultH, c.minH ?? 1), p = ft(d, i, v, x);
800
+ d.push(e({ id: f, x: p.x, y: p.y, w: v, h: x }));
801
+ }
802
+ return { resolved: ie(d, i), autoPlaced: !0 };
803
+ }, [ye, J, $, i]), Ve = k("");
804
+ q(() => {
805
+ if (!je) return;
806
+ const e = W.map(
807
+ (t) => `${t.id}:${t.x},${t.y},${t.w},${t.h}`
808
+ ).join("|");
809
+ Ve.current !== e && (Ve.current = e, Q(W));
810
+ }, [je, W, Q]);
811
+ const [Et, Tt] = B(null), [de, $e] = B(null), [_t, ae] = B(""), Ne = k(null), j = k(null), ce = k(null), Pe = k(!1), ge = k(i);
812
+ ge.current = i;
813
+ const fe = k(W);
814
+ fe.current = W;
815
+ const re = A((e) => {
816
+ Ne.current = e, Tt(e);
817
+ }, []), ke = A(
818
+ (e, t, n) => {
819
+ const d = { kind: e, id: t, via: n };
820
+ j.current = { ...d, baseLayout: fe.current }, $e(d), re(fe.current);
821
+ },
822
+ [re]
823
+ ), he = Et ?? W, Ke = se(
824
+ () => new Map(he.map((e) => [e.id, e])),
825
+ [he]
826
+ ), Ue = A(
827
+ (e, t) => {
828
+ ae(
829
+ e === "move" ? G("dashboardGrid.movedTo", { col: t.x + 1, row: t.y + 1 }) : G("dashboardGrid.resizedTo", { cols: t.w, rows: t.h })
830
+ );
831
+ },
832
+ [G]
833
+ ), F = k(null), Y = A(
834
+ (e) => {
835
+ var v;
836
+ (v = F.current) == null || v.call(F), F.current = null;
837
+ const t = Ne.current, n = j.current;
838
+ if (j.current = null, ce.current = null, $e(null), re(null), !e || !t || !n) {
839
+ ae(G("dashboardGrid.cancelled"));
840
+ return;
841
+ }
842
+ const d = ie(t, ge.current), f = (x) => x.map((p) => `${p.id}:${p.x},${p.y},${p.w},${p.h}`).join("|");
843
+ if (f(d) === f(fe.current)) {
844
+ ae(G("dashboardGrid.cancelled"));
845
+ return;
846
+ }
847
+ Q(d);
848
+ const c = d.find((x) => x.id === n.id);
849
+ ae(
850
+ c ? G("dashboardGrid.droppedAt", {
851
+ col: c.x + 1,
852
+ row: c.y + 1
853
+ }) : G("dashboardGrid.cancelled")
854
+ );
855
+ },
856
+ [re, Q, G]
857
+ ), We = k(Y);
858
+ We.current = Y;
859
+ const qe = A(
860
+ (e, t) => {
861
+ if (!u) return;
862
+ if (Pe.current) {
863
+ Pe.current = !1;
864
+ return;
865
+ }
866
+ const n = j.current;
867
+ if ((n == null ? void 0 : n.via) !== "pointer") {
868
+ if (n && n.id === t && n.kind === e) {
869
+ Y(!0);
870
+ return;
871
+ }
872
+ ke(e, t, "keyboard"), ae(
873
+ G(e === "move" ? "dashboardGrid.grabbed" : "dashboardGrid.resizeGrabbed")
874
+ );
875
+ }
876
+ },
877
+ [u, ke, Y, G]
878
+ ), Be = A(
879
+ (e, t) => {
880
+ const n = j.current;
881
+ if (!n || n.id !== t || n.via !== "keyboard")
882
+ return;
883
+ if (e.key === "Escape") {
884
+ e.preventDefault(), Y(!1);
885
+ return;
886
+ }
887
+ if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)) return;
888
+ e.preventDefault();
889
+ const f = typeof window < "u" && I.current ? window.getComputedStyle(I.current).direction === "rtl" : !1, c = e.key === "ArrowRight" ? f ? -1 : 1 : e.key === "ArrowLeft" ? f ? 1 : -1 : 0, v = e.key === "ArrowDown" ? 1 : e.key === "ArrowUp" ? -1 : 0, p = (Ne.current ?? n.baseLayout).find((P) => P.id === t);
890
+ if (!p) return;
891
+ const b = n.kind === "move" ? me(
892
+ n.baseLayout,
893
+ "move",
894
+ t,
895
+ p.x + c,
896
+ p.y + v,
897
+ i
898
+ ) : me(
899
+ n.baseLayout,
900
+ "resize",
901
+ t,
902
+ p.w + c,
903
+ p.h + v,
904
+ i
905
+ );
906
+ re(b);
907
+ const C = b.find((P) => P.id === t);
908
+ C && Ue(n.kind, C);
909
+ },
910
+ [i, Y, re, Ue]
911
+ ), ve = A(() => {
912
+ const e = ce.current, t = j.current, n = I.current;
913
+ if (!e || !t || !n) return;
914
+ const d = n.getBoundingClientRect(), f = e.lastClientX - d.left - e.startGridX, c = e.lastClientY - d.top - e.startGridY, v = Math.round(f / e.colStride) * (e.isRtl ? -1 : 1), x = Math.round(c / e.rowStride), { origin: p } = e;
915
+ re(
916
+ e.kind === "move" ? me(
917
+ t.baseLayout,
918
+ "move",
919
+ e.id,
920
+ p.x + v,
921
+ p.y + x,
922
+ ge.current
923
+ ) : me(
924
+ t.baseLayout,
925
+ "resize",
926
+ e.id,
927
+ p.w + v,
928
+ p.h + x,
929
+ ge.current
930
+ )
931
+ );
932
+ }, [re]), Me = k(!1), Je = A(() => {
933
+ var x;
934
+ (x = F.current) == null || x.call(F);
935
+ const e = (p) => {
936
+ const b = ce.current;
937
+ !b || p.pointerId !== b.pointerId || (b.lastClientX = p.clientX, b.lastClientY = p.clientY, b.travelled || (b.travelled = Math.hypot(
938
+ p.clientX - b.pressX,
939
+ p.clientY - b.pressY
940
+ ) > vt), ve());
941
+ }, t = (p) => (b) => {
942
+ const C = ce.current;
943
+ !C || b.pointerId !== C.pointerId || (Pe.current = C.fromHandle, We.current(p));
944
+ }, n = t(!0), d = t(!1), f = () => ve();
945
+ let c = 0;
946
+ const v = () => {
947
+ c = requestAnimationFrame(v);
948
+ const p = ce.current;
949
+ if (!(p != null && p.travelled)) return;
950
+ const b = I.current;
951
+ if (!b) return;
952
+ const { lastClientX: C, lastClientY: P } = p, K = fr(b), Ce = (U, dt, ee) => {
953
+ const ze = ee ? window.innerHeight : window.innerWidth, O = U == null ? void 0 : U.getBoundingClientRect(), Lt = Math.max(
954
+ ee ? (O == null ? void 0 : O.top) ?? 0 : (O == null ? void 0 : O.left) ?? 0,
955
+ 0
956
+ ), It = Math.min(
957
+ ee ? (O == null ? void 0 : O.bottom) ?? ze : (O == null ? void 0 : O.right) ?? ze,
958
+ ze
959
+ ), we = bt(It - dt) - bt(dt - Lt);
960
+ if (we === 0) return;
961
+ const at = () => U ? ee ? U.scrollTop : U.scrollLeft : ee ? window.scrollY : window.scrollX, At = at();
962
+ U == null || U.scrollBy(ee ? 0 : we, ee ? we : 0), (!U || at() === At) && window.scrollBy(ee ? 0 : we, ee ? we : 0);
963
+ };
964
+ Ce(K.y, P, !0), Ce(K.x, C, !1);
965
+ };
966
+ c = requestAnimationFrame(v), window.addEventListener("pointermove", e), window.addEventListener("pointerup", n), window.addEventListener("pointercancel", d), window.addEventListener("scroll", f, {
967
+ capture: !0,
968
+ passive: !0
969
+ }), F.current = () => {
970
+ cancelAnimationFrame(c), Me.current = !1, window.removeEventListener("pointermove", e), window.removeEventListener("pointerup", n), window.removeEventListener("pointercancel", d), window.removeEventListener("scroll", f, { capture: !0 });
971
+ };
972
+ }, [ve]);
973
+ q(
974
+ () => () => {
975
+ var e;
976
+ (e = F.current) == null || e.call(F), F.current = null;
977
+ },
978
+ []
979
+ );
980
+ const Se = A(
981
+ (e, t, n, d, f) => {
982
+ var K;
983
+ const c = I.current, v = fe.current.find((Ce) => Ce.id === t);
984
+ if (!c || !v) return !1;
985
+ const x = c.getBoundingClientRect();
986
+ if (x.width <= 0) return !1;
987
+ const p = window.getComputedStyle(c), b = Number.parseFloat(p.columnGap) || 0, C = Number.parseFloat(p.rowGap) || 0, P = (x.width - b * (i - 1)) / i;
988
+ ce.current = {
989
+ kind: e,
990
+ id: t,
991
+ pointerId: n.pointerId,
992
+ startGridX: n.clientX - x.left,
993
+ startGridY: n.clientY - x.top,
994
+ lastClientX: n.clientX,
995
+ lastClientY: n.clientY,
996
+ origin: v,
997
+ colStride: P + b,
998
+ rowStride: l + C,
999
+ isRtl: p.direction === "rtl",
1000
+ fromHandle: f,
1001
+ pressX: n.clientX,
1002
+ pressY: n.clientY,
1003
+ travelled: !1
1004
+ };
1005
+ try {
1006
+ (K = d.setPointerCapture) == null || K.call(d, n.pointerId);
1007
+ } catch {
1008
+ }
1009
+ return ke(e, t, "pointer"), Je(), !0;
1010
+ },
1011
+ [i, l, ke, Je]
1012
+ ), Qe = A(
1013
+ (e, t, n) => {
1014
+ var d, f;
1015
+ u && (j.current || (n.preventDefault(), (f = (d = n.currentTarget).focus) == null || f.call(d), Se(e, t, n, n.currentTarget, !0)));
1016
+ },
1017
+ [u, Se]
1018
+ ), Z = k(null), ne = A(() => {
1019
+ const e = Z.current;
1020
+ Z.current = null, e && (e.holdTimer && clearTimeout(e.holdTimer), e.cleanup());
1021
+ }, []), Ze = A(
1022
+ (e, t) => {
1023
+ if (!u || j.current || Z.current || t.button !== 0 || !t.isPrimary) return;
1024
+ const n = t.target;
1025
+ if (!t.currentTarget.contains(n)) return;
1026
+ const d = n.closest(ar);
1027
+ if (d && t.currentTarget.contains(d)) return;
1028
+ const f = t.currentTarget, c = t.pointerType === "touch";
1029
+ c || t.preventDefault();
1030
+ const v = (b, C) => {
1031
+ const P = Z.current;
1032
+ if (ne(), !(!P || j.current) && Se(
1033
+ "move",
1034
+ P.id,
1035
+ {
1036
+ pointerId: P.pointerId,
1037
+ clientX: P.startClientX,
1038
+ clientY: P.startClientY
1039
+ },
1040
+ P.surface,
1041
+ !1
1042
+ )) {
1043
+ Me.current = c;
1044
+ const K = ce.current;
1045
+ K && (K.lastClientX = b, K.lastClientY = C, K.travelled = !c), ve();
1046
+ }
1047
+ }, x = (b) => {
1048
+ const C = Z.current;
1049
+ if (!C || b.pointerId !== C.pointerId) return;
1050
+ const P = Math.hypot(
1051
+ b.clientX - C.startClientX,
1052
+ b.clientY - C.startClientY
1053
+ );
1054
+ c ? P > lr && ne() : P > vt && v(b.clientX, b.clientY);
1055
+ }, p = (b) => {
1056
+ var C;
1057
+ b.pointerId === ((C = Z.current) == null ? void 0 : C.pointerId) && ne();
1058
+ };
1059
+ window.addEventListener("pointermove", x), window.addEventListener("pointerup", p), window.addEventListener("pointercancel", p), Z.current = {
1060
+ id: e,
1061
+ pointerId: t.pointerId,
1062
+ pointerType: t.pointerType,
1063
+ startClientX: t.clientX,
1064
+ startClientY: t.clientY,
1065
+ surface: f,
1066
+ holdTimer: c ? setTimeout(() => {
1067
+ const b = Z.current;
1068
+ b && v(b.startClientX, b.startClientY);
1069
+ }, cr) : null,
1070
+ cleanup: () => {
1071
+ window.removeEventListener("pointermove", x), window.removeEventListener("pointerup", p), window.removeEventListener("pointercancel", p);
1072
+ }
1073
+ };
1074
+ },
1075
+ [u, Se, ve, ne]
1076
+ );
1077
+ q(() => {
1078
+ u || (ne(), j.current && We.current(!1));
1079
+ }, [u, ne]), q(() => ne, [ne]), q(() => {
1080
+ const e = I.current;
1081
+ if (!u || !e) return;
1082
+ const t = (d) => {
1083
+ Me.current && d.cancelable && d.preventDefault();
1084
+ }, n = (d) => {
1085
+ (Z.current || Me.current) && d.preventDefault();
1086
+ };
1087
+ return e.addEventListener("touchmove", t, { passive: !1 }), e.addEventListener("contextmenu", n), () => {
1088
+ e.removeEventListener("touchmove", t), e.removeEventListener("contextmenu", n);
1089
+ };
1090
+ }, [u]), q(() => {
1091
+ if (!de) return;
1092
+ const e = (t) => {
1093
+ t.key === "Escape" && Y(!1);
1094
+ };
1095
+ return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
1096
+ }, [de, Y]), q(() => {
1097
+ if (!de || de.via !== "keyboard") return;
1098
+ const e = (n) => {
1099
+ var f;
1100
+ const d = n.relatedTarget;
1101
+ (!d || !((f = I.current) != null && f.contains(d))) && Y(!1);
1102
+ }, t = I.current;
1103
+ return t == null || t.addEventListener("focusout", e), () => t == null ? void 0 : t.removeEventListener("focusout", e);
1104
+ }, [de, Y]), te(() => {
1105
+ E && (j.current && Y(!1), a && ae(G("dashboardGrid.stackedReadOnly")));
1106
+ }, [E, a, Y, G]), te(() => {
1107
+ var f;
1108
+ const e = ue.current;
1109
+ ue.current = null;
1110
+ const t = z.current;
1111
+ if (!e || !t) return;
1112
+ const n = document.activeElement;
1113
+ if (n === e.element || n !== null && n !== document.body) return;
1114
+ if (t.contains(e.element)) {
1115
+ e.element.focus();
1116
+ return;
1117
+ }
1118
+ const d = e.widgetId ? Array.from(
1119
+ t.querySelectorAll("[data-widget-id]")
1120
+ ).find(
1121
+ (c) => c.getAttribute("data-widget-id") === e.widgetId
1122
+ ) : void 0;
1123
+ if (d) {
1124
+ d.setAttribute("tabindex", "-1"), d.focus();
1125
+ return;
1126
+ }
1127
+ (f = I.current) == null || f.focus();
1128
+ }, [E]);
1129
+ const Ge = k(o);
1130
+ Ge.current = o;
1131
+ const et = k(!1);
1132
+ te(() => {
1133
+ var e;
1134
+ et.current !== E && (et.current = E, (e = Ge.current) == null || e.call(Ge, E));
1135
+ }, [E]), te(() => {
1136
+ const e = I.current;
1137
+ e && (e.style.setProperty("--dg-cols", String(i)), e.style.setProperty("--dg-row", `${l}px`));
1138
+ }, [i, l]);
1139
+ const tt = yt(he);
1140
+ te(() => {
1141
+ const e = I.current;
1142
+ e && (e.style.setProperty(
1143
+ "--dg-grid-lines",
1144
+ `repeating-linear-gradient(to right, color-mix(in srgb, var(--border) 50%, transparent) 0 1px, transparent 1px calc((100% + var(--spacing-md)) / ${i})), repeating-linear-gradient(to bottom, color-mix(in srgb, var(--border) 50%, transparent) 0 1px, transparent 1px calc(${l}px + var(--spacing-md)))`
1145
+ ), e.style.setProperty(
1146
+ "--dg-min-block",
1147
+ `calc(${tt + 2} * (${l}px + var(--spacing-md)) - var(--spacing-md))`
1148
+ ));
1149
+ }, [i, l, tt]);
1150
+ const rt = k(null), De = u && !!w, Ee = se(
1151
+ () => De ? ft(he, i, 2, 2) : null,
1152
+ [De, he, i]
1153
+ );
1154
+ te(() => {
1155
+ const e = rt.current;
1156
+ !e || !Ee || (e.style.setProperty("--dg-x", String(Ee.x + 1)), e.style.setProperty("--dg-y", String(Ee.y + 1)), e.style.setProperty("--dg-w", "2"), e.style.setProperty("--dg-h", "2"));
1157
+ }, [Ee]);
1158
+ const nt = A(
1159
+ (e) => {
1160
+ Q(
1161
+ ie(
1162
+ fe.current.filter((t) => t.id !== e),
1163
+ ge.current
1164
+ )
1165
+ ), ae(G("dashboardGrid.removed")), L == null || L(e), requestAnimationFrame(() => {
1166
+ const t = I.current;
1167
+ if (!t) return;
1168
+ const n = t.querySelector("button");
1169
+ n ? n.focus() : t.focus();
1170
+ });
1171
+ },
1172
+ [Q, L, G]
1173
+ ), [st, it] = B(null), X = k(null), be = k(null), Te = k(0), _e = A(() => {
1174
+ var c;
1175
+ const e = X.current, t = I.current;
1176
+ if (!e || !t) return !1;
1177
+ const n = Array.from(
1178
+ t.querySelectorAll("[data-widget-id]")
1179
+ ).find((v) => v.getAttribute("data-widget-id") === e.id), d = n == null ? void 0 : n.getBoundingClientRect();
1180
+ if (!n || !d || d.height <= 0)
1181
+ return performance.now() > e.deadline && (X.current = null, e.resolve(!1)), !1;
1182
+ X.current = null;
1183
+ const f = ((c = window.matchMedia) == null ? void 0 : c.call(window, "(prefers-reduced-motion: reduce)").matches) || window.getComputedStyle(t).getPropertyValue("--animation-duration").trim() === "0ms";
1184
+ return n.scrollIntoView({
1185
+ block: "nearest",
1186
+ inline: "nearest",
1187
+ behavior: f ? "auto" : "smooth"
1188
+ }), it(e.id), be.current && clearTimeout(be.current), be.current = setTimeout(
1189
+ () => it(null),
1190
+ dr
1191
+ ), e.resolve(!0), !0;
1192
+ }, []), ot = A(
1193
+ (e) => new Promise((t) => {
1194
+ var c;
1195
+ (c = X.current) == null || c.resolve(!1), cancelAnimationFrame(Te.current);
1196
+ const n = setTimeout(() => {
1197
+ const v = X.current;
1198
+ (v == null ? void 0 : v.resolve) === d && !_e() && X.current === v && (X.current = null, d(!1));
1199
+ }, ht), d = (v) => {
1200
+ clearTimeout(n), t(v);
1201
+ };
1202
+ X.current = {
1203
+ id: e,
1204
+ deadline: performance.now() + ht,
1205
+ resolve: d
1206
+ };
1207
+ const f = () => {
1208
+ X.current && !_e() && X.current && (Te.current = requestAnimationFrame(f));
1209
+ };
1210
+ Te.current = requestAnimationFrame(f);
1211
+ }),
1212
+ [_e]
1213
+ );
1214
+ te(() => {
1215
+ X.current && _e();
1216
+ }), q(
1217
+ () => () => {
1218
+ var e;
1219
+ cancelAnimationFrame(Te.current), be.current && clearTimeout(be.current), (e = X.current) == null || e.resolve(!1), X.current = null;
1220
+ },
1221
+ []
1222
+ );
1223
+ const He = se(
1224
+ () => ({
1225
+ moveWidgetTo(e, t, n) {
1226
+ if (!u || V.current || !Number.isFinite(t) || !Number.isFinite(n) || !W.some((f) => f.id === e)) return !1;
1227
+ const d = me(
1228
+ W,
1229
+ "move",
1230
+ e,
1231
+ Math.round(t),
1232
+ Math.round(n),
1233
+ i,
1234
+ !1
1235
+ );
1236
+ return d !== W && Q(ie(d, i)), !0;
1237
+ },
1238
+ resizeWidgetTo(e, t, n) {
1239
+ if (!u || V.current || !Number.isFinite(t) || !Number.isFinite(n) || !W.some((f) => f.id === e)) return !1;
1240
+ const d = me(
1241
+ W,
1242
+ "resize",
1243
+ e,
1244
+ Math.round(t),
1245
+ Math.round(n),
1246
+ i,
1247
+ !1
1248
+ );
1249
+ return d !== W && Q(ie(d, i)), !0;
1250
+ },
1251
+ revealWidget: ot,
1252
+ getGridState() {
1253
+ return {
1254
+ cols: i,
1255
+ editing: a,
1256
+ stacked: E,
1257
+ layout: xe(W),
1258
+ selectedId: M ?? null
1259
+ };
1260
+ }
1261
+ }),
1262
+ [
1263
+ u,
1264
+ a,
1265
+ E,
1266
+ W,
1267
+ i,
1268
+ Q,
1269
+ xe,
1270
+ ot,
1271
+ M
1272
+ ]
1273
+ );
1274
+ Pt(D, () => He, [He]), Yt(Bt, He, s);
1275
+ const Ct = se(
1276
+ () => ({
1277
+ editing: u,
1278
+ stacked: E,
1279
+ stackedHeight: h,
1280
+ selectedId: M,
1281
+ revealedId: st,
1282
+ headingLevel: _,
1283
+ layoutById: Ke,
1284
+ grab: de,
1285
+ canRemove: !!L,
1286
+ requestRemove: nt,
1287
+ startKeyboardGrab: qe,
1288
+ keyboardStep: Be,
1289
+ startPointerGrab: Qe,
1290
+ startHeaderPress: Ze
1291
+ }),
1292
+ [
1293
+ u,
1294
+ E,
1295
+ h,
1296
+ M,
1297
+ st,
1298
+ _,
1299
+ Ke,
1300
+ de,
1301
+ L,
1302
+ nt,
1303
+ qe,
1304
+ Be,
1305
+ Qe,
1306
+ Ze
1307
+ ]
1308
+ ), Rt = se(() => {
1309
+ if (T === void 0) return y;
1310
+ const e = [], t = /* @__PURE__ */ new Map(), n = [];
1311
+ return Le(y, (d) => {
1312
+ const f = d.props.id;
1313
+ if (f && !t.has(f)) {
1314
+ const c = ct(d, {
1315
+ key: `widget:${f}:${d.key ?? ""}`
1316
+ });
1317
+ t.set(f, c), e.push(c);
1318
+ } else {
1319
+ const c = ct(d, {
1320
+ key: d.key === null ? `child:at:${n.length}` : `child:key:${d.key}`
1321
+ });
1322
+ n.push(c), e.push(c);
1323
+ }
1324
+ }), E ? [
1325
+ ...er([...t.keys()], W).map(
1326
+ (d) => t.get(d)
1327
+ ),
1328
+ ...n
1329
+ ] : e;
1330
+ }, [T, y, E, W]);
1331
+ return /* @__PURE__ */ pe(
1332
+ "div",
1333
+ {
1334
+ ref: z,
1335
+ "data-component": "dashboard-grid",
1336
+ "data-component-id": s,
1337
+ "data-editing": u || void 0,
1338
+ "data-stacked": E || void 0,
1339
+ className: `ds:block ds:w-full ${S ?? ""}`.trim(),
1340
+ children: [
1341
+ /* @__PURE__ */ R("div", { role: "status", "aria-live": "polite", className: "ds:sr-only", children: _t }),
1342
+ /* @__PURE__ */ pe(
1343
+ "div",
1344
+ {
1345
+ ref: I,
1346
+ role: "list",
1347
+ "aria-label": r,
1348
+ tabIndex: -1,
1349
+ "data-editing": u || void 0,
1350
+ "data-stacked": E || void 0,
1351
+ className: tr({ stacked: E }),
1352
+ children: [
1353
+ /* @__PURE__ */ R(xt.Provider, { value: Ct, children: Rt }),
1354
+ De ? (
1355
+ // role="list" allows only listitem children — the tile wrapper
1356
+ // carries the grid placement, the button fills it.
1357
+ /* @__PURE__ */ R(
1358
+ "div",
1359
+ {
1360
+ ref: rt,
1361
+ role: "listitem",
1362
+ className: [
1363
+ "ds:flex",
1364
+ "ds:[grid-column-start:var(--dg-x)] ds:[grid-column-end:span_var(--dg-w)]",
1365
+ "ds:[grid-row-start:var(--dg-y)] ds:[grid-row-end:span_var(--dg-h)]"
1366
+ ].join(" "),
1367
+ children: /* @__PURE__ */ pe(
1368
+ "button",
1369
+ {
1370
+ type: "button",
1371
+ onClick: w,
1372
+ className: [
1373
+ "ds:flex ds:flex-1 ds:items-center ds:justify-center ds:gap-[var(--spacing-xs)]",
1374
+ "ds:rounded-[var(--radius-lg)] ds:border ds:border-dashed ds:border-border",
1375
+ "ds:text-sm ds:text-muted-foreground ds:transition-colors",
1376
+ "ds:hover:bg-muted/10 ds:hover:text-foreground",
1377
+ "ds:focus-visible:outline-[length:var(--focus-ring-width)] ds:focus-visible:outline-solid ds:focus-visible:outline-ring"
1378
+ ].join(" "),
1379
+ children: [
1380
+ /* @__PURE__ */ R(Ot, { "aria-hidden": "true", className: "ds:size-4" }),
1381
+ G("dashboardGrid.add")
1382
+ ]
1383
+ }
1384
+ )
1385
+ }
1386
+ )
1387
+ ) : null
1388
+ ]
1389
+ }
1390
+ )
1391
+ ]
1392
+ }
1393
+ );
1394
+ }
1395
+ );
1396
+ Mt.displayName = "DashboardGrid";
1397
+ const Tr = Object.assign(Mt, {
1398
+ Widget: kt
1399
+ });
1400
+ export {
1401
+ Tr as D,
1402
+ Bt as d
1403
+ };
1404
+ //# sourceMappingURL=dashboard-grid-DRnhIlT-.js.map