@momoi-labs/kiso-react 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export * from "./form-field.js";
20
20
  export * from "./form.js";
21
21
  export * from "./header.js";
22
22
  export * from "./input.js";
23
+ export * from "./password-input.js";
23
24
  export * from "./kv.js";
24
25
  export * from "./label.js";
25
26
  export * from "./link.js";
@@ -30,12 +31,15 @@ export * from "./pagination.js";
30
31
  export * from "./popover.js";
31
32
  export * from "./search.js";
32
33
  export * from "./select.js";
34
+ export * from "./detail-select.js";
35
+ export type { ChartStyle } from "./chart-style.js";
33
36
  export * from "./separator.js";
34
37
  export * from "./sidebar.js";
35
38
  export * from "./skeleton.js";
36
39
  export * from "./sparkline.js";
37
40
  export * from "./spinner.js";
38
41
  export * from "./split.js";
42
+ export * from "./pane-grid.js";
39
43
  export * from "./stat.js";
40
44
  export * from "./switch.js";
41
45
  export * from "./table.js";
@@ -60,3 +64,4 @@ export * from "./status-badge.js";
60
64
  export * from "./steps.js";
61
65
  export * from "./radio-group.js";
62
66
  export * from "./file-dropzone.js";
67
+ export * from "./diagram.js";
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ export * from "./form-field.js";
21
21
  export * from "./form.js";
22
22
  export * from "./header.js";
23
23
  export * from "./input.js";
24
+ export * from "./password-input.js";
24
25
  export * from "./kv.js";
25
26
  export * from "./label.js";
26
27
  export * from "./link.js";
@@ -31,12 +32,14 @@ export * from "./pagination.js";
31
32
  export * from "./popover.js";
32
33
  export * from "./search.js";
33
34
  export * from "./select.js";
35
+ export * from "./detail-select.js";
34
36
  export * from "./separator.js";
35
37
  export * from "./sidebar.js";
36
38
  export * from "./skeleton.js";
37
39
  export * from "./sparkline.js";
38
40
  export * from "./spinner.js";
39
41
  export * from "./split.js";
42
+ export * from "./pane-grid.js";
40
43
  export * from "./stat.js";
41
44
  export * from "./switch.js";
42
45
  export * from "./table.js";
@@ -61,3 +64,4 @@ export * from "./status-badge.js";
61
64
  export * from "./steps.js";
62
65
  export * from "./radio-group.js";
63
66
  export * from "./file-dropzone.js";
67
+ export * from "./diagram.js";
@@ -2,6 +2,7 @@ import * as React from "react";
2
2
  import { type VariantProps } from "class-variance-authority";
3
3
  type LogViewHandle = {
4
4
  scrollToBottom: (behavior?: ScrollBehavior) => void;
5
+ getScrollElement: () => HTMLDivElement | null;
5
6
  };
6
7
  declare function LogView({ className, children, follow, onFollowChange, ref, ...props }: Omit<React.ComponentProps<"div">, "ref"> & {
7
8
  follow?: boolean;
package/dist/log-view.js CHANGED
@@ -8,6 +8,9 @@ import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
8
8
  /* Within this much of the end counts as "at the bottom". A log that is being
9
9
  written to rarely lands on an exact scroll position. */
10
10
  const BOTTOM_THRESHOLD = 8;
11
+ function isAtBottom(el) {
12
+ return el.scrollHeight - el.scrollTop - el.clientHeight <= BOTTOM_THRESHOLD;
13
+ }
11
14
  /* The frame is `.logview` and the scroller is `.log-scroll` inside it, so the
12
15
  component owns the scroller and with it follow-tail: new lines pin the view
13
16
  to the end until the reader scrolls away, and returning to the end resumes.
@@ -15,6 +18,8 @@ const BOTTOM_THRESHOLD = 8;
15
18
  "Follow" switch — and read `onFollowChange` to keep it in step. */
16
19
  function LogView({ className, children, follow, onFollowChange, ref, ...props }) {
17
20
  const scroller = React.useRef(null);
21
+ /* The scroll height at the last pin, or null while not following. */
22
+ const pinned = React.useRef(null);
18
23
  const [atBottom, setAtBottom] = React.useState(true);
19
24
  const following = follow ?? atBottom;
20
25
  React.useImperativeHandle(ref, () => ({
@@ -23,16 +28,27 @@ function LogView({ className, children, follow, onFollowChange, ref, ...props })
23
28
  if (el)
24
29
  el.scrollTo({ top: el.scrollHeight, behavior });
25
30
  },
31
+ getScrollElement() {
32
+ return scroller.current;
33
+ },
26
34
  }), []);
27
- /* Before paint, so a new line never shows up above the fold first. */
35
+ /* Before paint, so a new line never shows up above the fold first. Skip the
36
+ pin when the height is unchanged and the view is still at the bottom: a
37
+ virtualized body re-renders its rows on every scroll, and pinning then
38
+ pulls back a reader who leaves the end in small steps. */
28
39
  useIsomorphicLayoutEffect(() => {
29
40
  const el = scroller.current;
30
- if (el && following)
31
- el.scrollTop = el.scrollHeight;
41
+ if (!el || !following) {
42
+ pinned.current = null;
43
+ return;
44
+ }
45
+ if (el.scrollHeight === pinned.current && isAtBottom(el))
46
+ return;
47
+ el.scrollTop = el.scrollHeight;
48
+ pinned.current = el.scrollHeight;
32
49
  }, [children, following]);
33
50
  return (_jsx("div", { "data-slot": "log-view", "data-follow": following, className: cn("logview", className), ...props, children: _jsx("div", { ref: scroller, "data-slot": "log-view-scroll", className: "log-scroll", onScroll: (event) => {
34
- const el = event.currentTarget;
35
- const bottom = el.scrollHeight - el.scrollTop - el.clientHeight <= BOTTOM_THRESHOLD;
51
+ const bottom = isAtBottom(event.currentTarget);
36
52
  setAtBottom(bottom);
37
53
  if (bottom !== following)
38
54
  onFollowChange?.(bottom);
@@ -0,0 +1,28 @@
1
+ import * as React from "react";
2
+ export type PaneGridLayout = {
3
+ rows: string[][];
4
+ sizes: Record<string, number>;
5
+ };
6
+ export type PaneGridOverflow = "wrap" | "scroll";
7
+ export type PaneGridProps = Omit<React.ComponentProps<"section">, "title"> & {
8
+ title?: React.ReactNode;
9
+ layout?: PaneGridLayout;
10
+ defaultLayout?: PaneGridLayout;
11
+ onLayoutChange?: (layout: PaneGridLayout) => void;
12
+ flow?: "rows" | "masonry";
13
+ overflow?: PaneGridOverflow;
14
+ fill?: boolean;
15
+ pack?: boolean;
16
+ scrollPages?: number;
17
+ debug?: boolean;
18
+ };
19
+ export declare function PaneGrid({ title, layout: controlled, defaultLayout, onLayoutChange, overflow, flow, fill, pack, scrollPages, debug, className, children, ...props }: PaneGridProps): React.JSX.Element;
20
+ export type GridPaneProps = Omit<React.ComponentProps<"article">, "title" | "id"> & {
21
+ id: string;
22
+ title: string;
23
+ min?: number;
24
+ size?: number;
25
+ newRow?: boolean;
26
+ actions?: React.ReactNode;
27
+ };
28
+ export declare function GridPane({ id, title, min: _min, size: _size, newRow: _newRow, actions, className, style, children, ...props }: GridPaneProps): React.JSX.Element;
@@ -0,0 +1,488 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { clsx as cn } from "clsx";
5
+ import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
6
+ const COLUMNS = 12;
7
+ /* A drag ends on release, on cancellation, or when capture is lost. */
8
+ const RELEASE = ["pointerup", "pointercancel", "lostpointercapture"];
9
+ /* DashboardGrid's breakpoints, measured on the grid's own width so a grid
10
+ beside a sidebar or panel gets the columns its space allows: above 1024px
11
+ twelve columns, above 640px six, then one. Unmeasured grids use twelve. */
12
+ const pickColumns = (width) => !width ? COLUMNS : width <= 640 ? 1 : width <= 1024 ? 6 : COLUMNS;
13
+ const PaneContext = React.createContext(null);
14
+ const clamp = (value, min, max) => Math.max(min, Math.min(max, value));
15
+ /* Every pane appears exactly once, with a size at or above its minimum.
16
+ Panes missing from the layout go to the end, or to a row of their own. */
17
+ function normalize(layout, specs) {
18
+ const known = new Map(specs.map((spec) => [spec.id, spec]));
19
+ const seen = new Set();
20
+ const rows = (layout?.rows ?? [])
21
+ .map((row) => row.filter((id) => known.has(id) && !seen.has(id) && seen.add(id)))
22
+ .filter((row) => row.length);
23
+ for (const spec of specs) {
24
+ if (seen.has(spec.id))
25
+ continue;
26
+ if (spec.newRow || !rows.length)
27
+ rows.push([spec.id]);
28
+ else
29
+ rows[rows.length - 1].push(spec.id);
30
+ }
31
+ const sizes = {};
32
+ for (const spec of specs) {
33
+ sizes[spec.id] = clamp(Math.round(layout?.sizes[spec.id] ?? spec.size), spec.min, COLUMNS);
34
+ }
35
+ return { rows, sizes };
36
+ }
37
+ function sameLayout(a, b) {
38
+ return (a.rows.length === b.rows.length &&
39
+ a.rows.every((row, index) => row.length === b.rows[index].length && row.every((id, at) => id === b.rows[index][at])) &&
40
+ Object.keys(a.sizes).length === Object.keys(b.sizes).length &&
41
+ Object.entries(a.sizes).every(([id, size]) => b.sizes[id] === size));
42
+ }
43
+ /* Lay a row's panes out on lines. In order by default, so the person's
44
+ arrangement holds; with `pack`, big panes first and small ones fill the
45
+ holes left behind. With `scroll`, one line however wide. `fill` hands a
46
+ line's leftover columns to its panes, for display only. */
47
+ function layRow(ids, specs, sizes, columns, options) {
48
+ const scale = (value) => clamp(Math.ceil((value * columns) / COLUMNS), 1, columns);
49
+ let items = ids.map((id) => ({ id, size: scale(sizes[id]), min: scale(specs.get(id).min), col: 1, span: 0 }));
50
+ if (options.pack && !options.scroll)
51
+ items = [...items].sort((a, b) => b.size - a.size);
52
+ const lines = [];
53
+ for (const item of items) {
54
+ let line = options.pack && !options.scroll ? lines.find((line) => line.used + item.size <= columns) : lines[lines.length - 1];
55
+ if (!line || (!options.scroll && line.used + item.size > columns)) {
56
+ line = { used: 0, free: 0, scroll: false, items: [] };
57
+ lines.push(line);
58
+ }
59
+ line.items.push(item);
60
+ line.used += item.size;
61
+ }
62
+ for (const line of lines) {
63
+ line.scroll = options.scroll && line.used > columns;
64
+ line.free = Math.max(0, columns - line.used);
65
+ const extra = line.items.map(() => 0);
66
+ if (options.fill && !line.scroll)
67
+ for (let left = line.free, at = 0; left > 0; left--, at++)
68
+ extra[at % extra.length]++;
69
+ let col = 1;
70
+ line.items.forEach((item, index) => {
71
+ item.col = col;
72
+ item.span = item.size + extra[index];
73
+ col += item.span;
74
+ });
75
+ }
76
+ return lines;
77
+ }
78
+ export function PaneGrid({ title, layout: controlled, defaultLayout, onLayoutChange, overflow = "wrap", flow = "rows", fill = false, pack = false, scrollPages = 2, debug = false, className, children, ...props }) {
79
+ const elements = new Map();
80
+ const specs = [];
81
+ for (const child of React.Children.toArray(children)) {
82
+ if (!React.isValidElement(child) || typeof child.props.id !== "string")
83
+ continue;
84
+ elements.set(child.props.id, child);
85
+ specs.push({ id: child.props.id, min: child.props.min ?? 1, size: child.props.size ?? 6, newRow: !!child.props.newRow });
86
+ }
87
+ const specMap = new Map(specs.map((spec) => [spec.id, spec]));
88
+ const [internal, setInternal] = React.useState(() => normalize(defaultLayout, specs));
89
+ const layout = normalize(controlled ?? internal, specs);
90
+ const update = (next) => {
91
+ if (sameLayout(next, layout))
92
+ return;
93
+ if (!controlled)
94
+ setInternal(next);
95
+ onLayoutChange?.(next);
96
+ };
97
+ const bodyRef = React.useRef(null);
98
+ const dropRef = React.useRef(null);
99
+ const [width, setWidth] = React.useState(0);
100
+ useIsomorphicLayoutEffect(() => {
101
+ const body = bodyRef.current;
102
+ if (!body || typeof ResizeObserver === "undefined")
103
+ return;
104
+ const measure = () => setWidth(body.clientWidth);
105
+ measure();
106
+ const observer = new ResizeObserver(measure);
107
+ observer.observe(body);
108
+ return () => observer.disconnect();
109
+ }, []);
110
+ const columns = pickColumns(width);
111
+ const compact = columns !== COLUMNS;
112
+ const stacked = columns === 1;
113
+ const scrolling = overflow === "scroll" && !stacked;
114
+ const masonry = flow === "masonry" && overflow === "wrap";
115
+ const scrollMax = columns * Math.max(1, scrollPages);
116
+ let gridRow = 0;
117
+ const rows = layout.rows.map((ids) => {
118
+ const lines = layRow(ids, specMap, layout.sizes, columns, { fill: fill && !masonry, pack, scroll: scrolling }).map((line) => ({ ...line, row: ++gridRow }));
119
+ return { ids, lines };
120
+ });
121
+ // Pixel tracks keep natural heights while sharing the same column grid.
122
+ // Observe direct children only: nested PaneGrids own their measurements.
123
+ useIsomorphicLayoutEffect(() => {
124
+ const body = bodyRef.current;
125
+ if (!body || !masonry)
126
+ return;
127
+ const panes = Array.from(body.children).filter((node) => node instanceof HTMLElement && node.hasAttribute("data-pane-id"));
128
+ const byId = new Map(panes.map(pane => [pane.dataset.paneId, pane]));
129
+ const measure = () => {
130
+ const gap = parseFloat(getComputedStyle(body).columnGap) || 0;
131
+ const heights = new Map(panes.map(pane => [pane.dataset.paneId, pane.getBoundingClientRect().height]));
132
+ let base = 0;
133
+ rows.forEach((row, index) => {
134
+ const bottoms = Array(columns).fill(base);
135
+ const items = row.lines.flatMap(line => line.items);
136
+ if (pack)
137
+ items.sort((a, b) => b.size - a.size);
138
+ for (const item of items) {
139
+ const pane = byId.get(item.id);
140
+ if (!pane)
141
+ continue;
142
+ let col = 0;
143
+ let top = Infinity;
144
+ for (let start = 0; start <= columns - item.span; start++) {
145
+ const candidate = Math.max(...bottoms.slice(start, start + item.span));
146
+ if (candidate < top) {
147
+ col = start;
148
+ top = candidate;
149
+ }
150
+ }
151
+ const height = Math.ceil(heights.get(item.id) ?? 0);
152
+ pane.style.setProperty("--masonry-r", String(Math.ceil(top) + 1));
153
+ pane.style.setProperty("--masonry-c", String(col + 1));
154
+ pane.style.setProperty("--masonry-h", String(Math.max(1, height)));
155
+ for (let at = col; at < col + item.span; at++)
156
+ bottoms[at] = top + height + gap;
157
+ }
158
+ const rule = body.querySelector(`:scope > [data-pane-row="${index}"]`);
159
+ rule?.style.setProperty("--masonry-r", String(Math.ceil(base) + 1));
160
+ base = Math.max(...bottoms);
161
+ });
162
+ };
163
+ measure();
164
+ if (typeof ResizeObserver === "undefined")
165
+ return;
166
+ let frame = 0;
167
+ const observer = new ResizeObserver(() => {
168
+ cancelAnimationFrame(frame);
169
+ frame = requestAnimationFrame(measure);
170
+ });
171
+ observer.observe(body);
172
+ panes.forEach(pane => observer.observe(pane));
173
+ return () => { observer.disconnect(); cancelAnimationFrame(frame); };
174
+ });
175
+ /* Handlers read the latest render through this ref, so a drag that spans
176
+ several renders never acts on a stale layout. */
177
+ const state = React.useRef({ layout, rows, columns, compact, stacked, scrolling, masonry, scrollMax, update });
178
+ state.current = { layout, rows, columns, compact, stacked, scrolling, masonry, scrollMax, update };
179
+ const specsRef = React.useRef(specMap);
180
+ specsRef.current = specMap;
181
+ const api = React.useMemo(() => {
182
+ const paneElement = (id) => bodyRef.current?.querySelector(`:scope > [data-pane-id="${CSS.escape(id)}"], :scope > .pane-grid-scroll > [data-pane-id="${CSS.escape(id)}"]`);
183
+ const lineOf = (id) => {
184
+ for (const row of state.current.rows)
185
+ for (const line of row.lines)
186
+ if (line.items.some((item) => item.id === id))
187
+ return line;
188
+ return undefined;
189
+ };
190
+ const gaps = () => {
191
+ const style = bodyRef.current ? getComputedStyle(bodyRef.current) : null;
192
+ return { x: parseFloat(style?.columnGap ?? "0") || 0, y: parseFloat((state.current.masonry ? style?.columnGap : style?.rowGap) ?? "0") || 0 };
193
+ };
194
+ const maxOf = (id) => {
195
+ const { layout, columns, scrolling, masonry, scrollMax } = state.current;
196
+ const line = lineOf(id);
197
+ const size = layout.sizes[id];
198
+ if (masonry)
199
+ return columns;
200
+ if (!line)
201
+ return size;
202
+ return scrolling ? Math.min(columns, size + scrollMax - line.used) : size + line.free;
203
+ };
204
+ const resize = (id, next) => {
205
+ const { layout, compact, update } = state.current;
206
+ if (compact)
207
+ return;
208
+ const spec = specsRef.current.get(id);
209
+ if (!spec)
210
+ return;
211
+ const size = clamp(Math.round(next), spec.min, maxOf(id));
212
+ if (size === layout.sizes[id])
213
+ return;
214
+ update({ rows: layout.rows, sizes: { ...layout.sizes, [id]: size } });
215
+ };
216
+ const startResize = (id, event) => {
217
+ const { layout, columns, compact } = state.current;
218
+ const body = bodyRef.current;
219
+ const pane = paneElement(id);
220
+ if (compact || !body || !pane)
221
+ return;
222
+ event.preventDefault();
223
+ const handle = event.currentTarget;
224
+ handle.setPointerCapture(event.pointerId);
225
+ const startX = event.clientX;
226
+ const startSize = layout.sizes[id];
227
+ const columnWidth = (body.clientWidth - gaps().x * (columns - 1)) / columns + gaps().x;
228
+ handle.classList.add("dragging");
229
+ pane.classList.add("resizing");
230
+ const move = (moved) => resize(id, startSize + Math.round((moved.clientX - startX) / columnWidth));
231
+ const stop = () => {
232
+ handle.classList.remove("dragging");
233
+ pane.classList.remove("resizing");
234
+ handle.removeEventListener("pointermove", move);
235
+ for (const type of RELEASE)
236
+ handle.removeEventListener(type, stop);
237
+ };
238
+ handle.addEventListener("pointermove", move);
239
+ for (const type of RELEASE)
240
+ handle.addEventListener(type, stop);
241
+ };
242
+ /* Where a dragged pane lands: before or after a pane on one of a row's
243
+ lines, in the whole gap above a row as a row of its own, or after the
244
+ last row. */
245
+ const hitTest = (x, y, self) => {
246
+ const { rows, stacked, masonry } = state.current;
247
+ const rect = (id) => paneElement(id)?.getBoundingClientRect();
248
+ for (const row of rows) {
249
+ const bands = row.lines.map((line) => {
250
+ const rects = line.items.map((item) => rect(item.id)).filter((box) => !!box);
251
+ return { line, top: Math.min(...rects.map((box) => box.top)), bottom: Math.max(...rects.map((box) => box.bottom)) };
252
+ });
253
+ if (!bands.length)
254
+ continue;
255
+ const top = Math.min(...bands.map(band => band.top));
256
+ const bottom = Math.max(...bands.map(band => band.bottom));
257
+ if (y < top)
258
+ return { ref: row.ids[0], where: "newrow-before" };
259
+ if (y > bottom)
260
+ continue;
261
+ if (masonry) {
262
+ const candidates = row.ids.filter(id => id !== self).flatMap(id => {
263
+ const box = rect(id);
264
+ if (!box)
265
+ return [];
266
+ const dx = Math.max(box.left - x, 0, x - box.right);
267
+ const dy = Math.max(box.top - y, 0, y - box.bottom);
268
+ return [{ id, box, distance: Math.hypot(dx, dy) }];
269
+ }).sort((a, b) => a.distance - b.distance);
270
+ const nearest = candidates[0];
271
+ if (!nearest)
272
+ return null;
273
+ const before = stacked ? y < nearest.box.top + nearest.box.height / 2 : x < nearest.box.left + nearest.box.width / 2;
274
+ return { ref: nearest.id, where: before ? "before" : "after" };
275
+ }
276
+ const band = bands.reduce((near, next) => Math.abs((next.top + next.bottom) / 2 - y) < Math.abs((near.top + near.bottom) / 2 - y) ? next : near);
277
+ const items = band.line.items.filter((item) => item.id !== self);
278
+ if (!items.length) {
279
+ const others = row.ids.filter((id) => id !== self);
280
+ return others.length ? { ref: others[others.length - 1], where: "after" } : null;
281
+ }
282
+ for (const item of items) {
283
+ const box = rect(item.id);
284
+ if (!box)
285
+ continue;
286
+ const before = stacked ? y < box.top + box.height / 2 : x < box.left + box.width / 2;
287
+ if (before)
288
+ return { ref: item.id, where: "before" };
289
+ }
290
+ return { ref: items[items.length - 1].id, where: "after" };
291
+ }
292
+ return { ref: null, where: "newrow-end" };
293
+ };
294
+ const paint = (target) => {
295
+ const drop = dropRef.current;
296
+ const body = bodyRef.current;
297
+ if (!drop || !body)
298
+ return;
299
+ if (!target) {
300
+ drop.hidden = true;
301
+ return;
302
+ }
303
+ const gap = gaps().y;
304
+ const box = body.getBoundingClientRect();
305
+ drop.hidden = false;
306
+ drop.dataset.invalid = String(!!target.invalid);
307
+ const ref = target.ref ? paneElement(target.ref)?.getBoundingClientRect() : null;
308
+ const across = (top) => {
309
+ drop.dataset.axis = "y";
310
+ Object.assign(drop.style, { left: "0px", width: `${box.width}px`, height: "", top: `${top}px` });
311
+ };
312
+ if (target.where === "newrow-end")
313
+ across(box.height + gap / 2);
314
+ else if (!ref)
315
+ drop.hidden = true;
316
+ else if (target.where === "newrow-before") {
317
+ const row = state.current.rows.find(row => row.ids.includes(target.ref));
318
+ const top = row ? Math.min(...row.ids.map(id => paneElement(id)?.getBoundingClientRect().top ?? ref.top)) : ref.top;
319
+ across(top - box.top - gap / 2 - 1.5);
320
+ }
321
+ else if (state.current.stacked)
322
+ across((target.where === "before" ? ref.top - gap / 2 : ref.bottom + gap / 2) - box.top - 1.5);
323
+ else {
324
+ drop.dataset.axis = "x";
325
+ const left = (target.where === "before" ? ref.left - gap / 2 : ref.right + gap / 2) - box.left - 1.5;
326
+ Object.assign(drop.style, { top: `${ref.top - box.top}px`, height: `${ref.height}px`, left: `${left}px`, width: "" });
327
+ }
328
+ };
329
+ const plan = (id, target) => {
330
+ const rows = state.current.layout.rows.map((row) => row.filter((other) => other !== id));
331
+ if (target.where === "before" || target.where === "after") {
332
+ const row = rows.find((row) => target.ref !== null && row.includes(target.ref));
333
+ if (!row)
334
+ return null;
335
+ row.splice(row.indexOf(target.ref) + (target.where === "after" ? 1 : 0), 0, id);
336
+ }
337
+ else if (target.where === "newrow-before") {
338
+ const at = rows.findIndex((row) => target.ref !== null && row.includes(target.ref));
339
+ if (at < 0)
340
+ return null;
341
+ rows.splice(at, 0, [id]);
342
+ }
343
+ else
344
+ rows.push([id]);
345
+ return rows.filter((row) => row.length);
346
+ };
347
+ const exceeds = (id, target) => {
348
+ const { layout, scrolling, scrollMax, columns } = state.current;
349
+ if (!scrolling || (target.where !== "before" && target.where !== "after"))
350
+ return false;
351
+ const row = layout.rows.find((row) => target.ref !== null && row.includes(target.ref));
352
+ if (!row)
353
+ return false;
354
+ const scale = (value) => clamp(Math.ceil((value * columns) / COLUMNS), 1, columns);
355
+ return row.filter((other) => other !== id).reduce((sum, other) => sum + scale(layout.sizes[other]), 0) + scale(layout.sizes[id]) > scrollMax;
356
+ };
357
+ const startMove = (id, event) => {
358
+ const pane = paneElement(id);
359
+ if (!pane)
360
+ return;
361
+ if (event.target.closest("button, a, input, select, textarea, [role='button']:not(.grid-pane-head)"))
362
+ return;
363
+ event.preventDefault();
364
+ const handle = event.currentTarget;
365
+ handle.setPointerCapture(event.pointerId);
366
+ const start = { x: event.clientX, y: event.clientY };
367
+ let active = false;
368
+ let target = null;
369
+ const move = (moved) => {
370
+ if (!active) {
371
+ if (Math.hypot(moved.clientX - start.x, moved.clientY - start.y) < 6)
372
+ return;
373
+ active = true;
374
+ pane.classList.add("dragging");
375
+ if (bodyRef.current)
376
+ bodyRef.current.dataset.dragging = "true";
377
+ }
378
+ target = hitTest(moved.clientX, moved.clientY, id);
379
+ if (target)
380
+ target.invalid = exceeds(id, target);
381
+ paint(target);
382
+ };
383
+ const stop = () => {
384
+ handle.removeEventListener("pointermove", move);
385
+ for (const type of RELEASE)
386
+ handle.removeEventListener(type, stop);
387
+ pane.classList.remove("dragging");
388
+ delete bodyRef.current?.dataset.dragging;
389
+ paint(null);
390
+ if (!active || !target || target.invalid)
391
+ return;
392
+ const rows = plan(id, target);
393
+ if (rows)
394
+ state.current.update({ rows, sizes: state.current.layout.sizes });
395
+ };
396
+ handle.addEventListener("pointermove", move);
397
+ for (const type of RELEASE)
398
+ handle.addEventListener(type, stop);
399
+ };
400
+ const moveBy = (id, direction) => {
401
+ const { layout, update } = state.current;
402
+ const order = layout.rows.flat();
403
+ const at = order.indexOf(id);
404
+ const to = at + direction;
405
+ if (at < 0 || to < 0 || to >= order.length)
406
+ return;
407
+ const other = order[to];
408
+ const rows = layout.rows.map((row) => row.map((entry) => (entry === id ? other : entry === other ? id : entry)));
409
+ update({ rows, sizes: layout.sizes });
410
+ };
411
+ /* A pane at the start of a row rejoins the row above; anywhere else it
412
+ starts a row of its own with the panes after it. */
413
+ const toggleRow = (id) => {
414
+ const { layout, update } = state.current;
415
+ const rows = layout.rows.map((row) => [...row]);
416
+ const at = rows.findIndex((row) => row.includes(id));
417
+ if (at < 0)
418
+ return;
419
+ const index = rows[at].indexOf(id);
420
+ if (index > 0)
421
+ rows.splice(at + 1, 0, rows[at].splice(index));
422
+ else if (at > 0)
423
+ rows[at - 1].push(...rows.splice(at, 1)[0]);
424
+ else
425
+ return;
426
+ update({ rows, sizes: layout.sizes });
427
+ };
428
+ return { resize, startResize, startMove, moveBy, toggleRow };
429
+ }, []);
430
+ const placements = new Map();
431
+ for (const row of rows) {
432
+ for (const line of row.lines) {
433
+ for (const item of line.items) {
434
+ const max = masonry ? columns : scrolling ? Math.min(columns, item.size + scrollMax - line.used) : item.size + line.free;
435
+ placements.set(item.id, { id: item.id, row: line.scroll ? 1 : line.row, col: item.col, span: item.span, size: item.size, min: item.min, max, compact, stacked, debug });
436
+ }
437
+ }
438
+ }
439
+ const renderPane = (id) => {
440
+ const element = elements.get(id);
441
+ const placement = placements.get(id);
442
+ if (!element || !placement)
443
+ return null;
444
+ return (_jsx(PaneContext.Provider, { value: { placement, api }, children: element }, id));
445
+ };
446
+ return (_jsxs("section", { "data-slot": "pane-grid", className: cn("pane-grid", className), ...props, children: [title != null && _jsx("h2", { "data-slot": "pane-grid-title", className: "pane-grid-title t-h2", children: title }), _jsxs("div", { ref: bodyRef, "data-slot": "pane-grid-body", className: "pane-grid-body", "data-columns": columns, "data-compact": compact ? "true" : undefined, "data-overflow": overflow, "data-flow": masonry ? "masonry" : "rows", "data-debug": debug ? "true" : undefined, style: { "--pane-cols": columns, "--pane-grid-width": `${width}px` }, children: [rows.flatMap((row, index) => [
447
+ (index > 0 || debug) && (_jsx("div", { className: "pane-grid-rule", "data-pane-row": index, "aria-hidden": "true", style: { "--r": row.lines[0].row }, children: debug && `row ${index + 1} · ${row.lines.map((line) => `${line.used}/${columns}${line.scroll ? " ⇆ scroll" : ""}`).join(" + ")}` }, `rule-${index}`)),
448
+ ...(masonry ? row.ids.map(renderPane) : row.lines.flatMap((line) => line.scroll
449
+ ? [
450
+ _jsx("div", { className: "pane-grid-scroll", style: { "--r": line.row, "--n": line.used }, children: line.items.map((item) => renderPane(item.id)) }, `scroll-${line.items[0].id}`),
451
+ ]
452
+ : [
453
+ ...line.items.map((item) => renderPane(item.id)),
454
+ debug && !masonry && line.free > 0 && !fill && (_jsxs("div", { className: "pane-grid-free", "aria-hidden": "true", style: { "--r": line.row, "--c": line.used + 1, "--s": line.free }, children: ["free ", line.free] }, `free-${line.row}`)),
455
+ ])),
456
+ ]), _jsx("div", { ref: dropRef, className: "pane-grid-drop", "aria-hidden": "true", hidden: true })] })] }));
457
+ }
458
+ export function GridPane({ id, title, min: _min, size: _size, newRow: _newRow, actions, className, style, children, ...props }) {
459
+ const context = React.useContext(PaneContext);
460
+ if (!context)
461
+ throw new Error("GridPane must be a child of PaneGrid.");
462
+ const { placement, api } = context;
463
+ return (_jsxs("article", { "data-slot": "grid-pane", "data-pane-id": id, className: cn("grid-pane card", className), style: { "--r": placement.row, "--c": placement.col, "--s": placement.span, ...style }, ...props, children: [_jsxs("div", { "data-slot": "grid-pane-head", className: "grid-pane-head", role: "button", tabIndex: 0, "aria-label": `Move ${title}`, onPointerDown: (event) => api.startMove(id, event), onKeyDown: (event) => {
464
+ if (event.target !== event.currentTarget)
465
+ return;
466
+ if (event.key === "ArrowLeft" || (placement.stacked && event.key === "ArrowUp"))
467
+ api.moveBy(id, -1);
468
+ else if (event.key === "ArrowRight" || (placement.stacked && event.key === "ArrowDown"))
469
+ api.moveBy(id, 1);
470
+ else if (event.key === "Enter" || event.key === " ")
471
+ api.toggleRow(id);
472
+ else
473
+ return;
474
+ event.preventDefault();
475
+ }, children: [_jsx("h3", { "data-slot": "grid-pane-title", className: "grid-pane-title t-h3", children: title }), placement.debug && _jsxs("span", { className: "grid-pane-meta", children: ["size=", placement.size, " \u00B7 min=", placement.min, " \u00B7 max=", placement.max] }), actions != null && _jsx("div", { "data-slot": "grid-pane-actions", className: "grid-pane-actions", children: actions })] }), _jsx("div", { "data-slot": "grid-pane-body", className: "grid-pane-body", children: children }), !placement.compact && (_jsx("div", { "data-slot": "grid-pane-resizer", className: "grid-pane-resizer", role: "separator", tabIndex: 0, "aria-orientation": "vertical", "aria-label": `Resize ${title}`, "aria-valuenow": placement.size, "aria-valuemin": placement.min, "aria-valuemax": placement.max, "aria-disabled": placement.min === placement.max || undefined, onPointerDown: (event) => api.startResize(id, event), onKeyDown: (event) => {
476
+ if (event.key === "ArrowRight")
477
+ api.resize(id, placement.size + 1);
478
+ else if (event.key === "ArrowLeft")
479
+ api.resize(id, placement.size - 1);
480
+ else if (event.key === "Home")
481
+ api.resize(id, placement.min);
482
+ else if (event.key === "End")
483
+ api.resize(id, placement.max);
484
+ else
485
+ return;
486
+ event.preventDefault();
487
+ } }))] }));
488
+ }
@@ -0,0 +1,15 @@
1
+ import { type ComponentProps } from "react";
2
+ import { Input } from "./input.js";
3
+ declare const defaultLabels: {
4
+ show: string;
5
+ hide: string;
6
+ showName: string;
7
+ hideName: string;
8
+ shown: string;
9
+ hidden: string;
10
+ };
11
+ export type PasswordInputProps = Omit<ComponentProps<typeof Input>, "type"> & {
12
+ labels?: Partial<typeof defaultLabels>;
13
+ };
14
+ export declare function PasswordInput({ labels, id: providedId, disabled, ...props }: PasswordInputProps): import("react").JSX.Element;
15
+ export {};