reifyui 0.7.3 → 0.8.1
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/README.md +66 -0
- package/dist/chart.cjs +170 -0
- package/dist/chart.cjs.map +1 -0
- package/dist/chart.d.ts +57 -0
- package/dist/chart.js +138 -0
- package/dist/chart.js.map +1 -0
- package/dist/index.cjs +315 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +89 -0
- package/dist/index.js +315 -9
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
- package/src/chart/Chart.jsx +90 -0
- package/src/chart/index.d.ts +57 -0
- package/src/chart/index.js +10 -0
- package/src/chart/tokens.js +52 -0
- package/src/chart/useChartTokens.js +33 -0
- package/src/components/FilePreview.jsx +24 -16
- package/src/components/Panel.jsx +82 -0
- package/src/grid/PanelGrid.jsx +232 -0
- package/src/grid/layout.js +122 -0
- package/src/index.d.ts +89 -0
- package/src/index.js +8 -0
- package/styles/chat.css +19 -2
- package/styles/panels.css +162 -0
- package/styles/themes/dark.css +16 -0
- package/styles/themes/light.css +17 -0
package/dist/index.d.ts
CHANGED
|
@@ -575,3 +575,92 @@ export interface SheetExportOptions {
|
|
|
575
575
|
}
|
|
576
576
|
export function sheetToDelimited(sheet: Sheet, delimiter?: string, options?: SheetExportOptions): string;
|
|
577
577
|
export function sheetToAoA(sheet: Sheet, options?: SheetExportOptions): unknown[][];
|
|
578
|
+
|
|
579
|
+
// ── boards: panels and the grid they sit in ──────────────────────────────────
|
|
580
|
+
export interface PanelProps {
|
|
581
|
+
title?: ReactNode;
|
|
582
|
+
/** Heading level, so a board fits YOUR document outline. Default 'h3'. */
|
|
583
|
+
titleAs?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'div';
|
|
584
|
+
/** Quiet second line under the title — when it last refreshed, what it counts. */
|
|
585
|
+
meta?: ReactNode;
|
|
586
|
+
/** Controls in the header, after the title. A press on one never drags the panel. */
|
|
587
|
+
actions?: ReactNode;
|
|
588
|
+
footer?: ReactNode;
|
|
589
|
+
|
|
590
|
+
/** No content yet: the body becomes a placeholder of the same size, so a board of four
|
|
591
|
+
* requests does not reflow four times as they land. */
|
|
592
|
+
loading?: boolean;
|
|
593
|
+
/** The name a screen reader is given while loading. Default 'Loading'. */
|
|
594
|
+
loadingLabel?: string;
|
|
595
|
+
/** Content is up and being refreshed: the header shows it and the body stays readable. */
|
|
596
|
+
busy?: boolean;
|
|
597
|
+
busyLabel?: string;
|
|
598
|
+
|
|
599
|
+
/** What went wrong, verbatim — shown monospace, selectable and scrollable, because the error
|
|
600
|
+
* is the thing that lets someone fix what produced it. Wins over `children`, loses to
|
|
601
|
+
* `loading` (a retry in flight should not still show the failure it is retrying). */
|
|
602
|
+
error?: ReactNode;
|
|
603
|
+
/** The line above the message. Default 'This panel could not load'. */
|
|
604
|
+
errorTitle?: ReactNode;
|
|
605
|
+
/** Extra context under the message, folded away — e.g. the statement that failed. */
|
|
606
|
+
errorDetail?: ReactNode;
|
|
607
|
+
detailLabel?: ReactNode;
|
|
608
|
+
/** Absent → no retry control is drawn, rather than one that does nothing. */
|
|
609
|
+
onRetry?: () => void;
|
|
610
|
+
retryLabel?: ReactNode;
|
|
611
|
+
|
|
612
|
+
className?: string;
|
|
613
|
+
classNames?: { root?: string; head?: string; body?: string };
|
|
614
|
+
children?: ReactNode;
|
|
615
|
+
}
|
|
616
|
+
/** The frame around one thing on a board. Fills the cell it is given: put it in a box with a
|
|
617
|
+
* height. Its header carries `.uic-panel-head`, which is what PanelGrid drags by. */
|
|
618
|
+
export const Panel: ComponentType<PanelProps>;
|
|
619
|
+
|
|
620
|
+
/** One panel's cell. x/w are COLUMNS and y/h are ROWS — never pixels. */
|
|
621
|
+
export interface PanelLayoutItem {
|
|
622
|
+
/** Matches the child's React `key`. */
|
|
623
|
+
i: string;
|
|
624
|
+
x: number;
|
|
625
|
+
y: number;
|
|
626
|
+
w: number;
|
|
627
|
+
h: number;
|
|
628
|
+
minW?: number;
|
|
629
|
+
minH?: number;
|
|
630
|
+
maxW?: number;
|
|
631
|
+
maxH?: number;
|
|
632
|
+
/** Neither moves nor resizes, and other panels flow around it. */
|
|
633
|
+
static?: boolean;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export interface PanelGridProps {
|
|
637
|
+
layout: PanelLayoutItem[];
|
|
638
|
+
/** One element per layout entry, matched by `key`. A child with no entry is not rendered. */
|
|
639
|
+
children?: ReactNode;
|
|
640
|
+
cols?: number;
|
|
641
|
+
/** px per row. Default 40. */
|
|
642
|
+
rowHeight?: number;
|
|
643
|
+
/** px between cells. Default 12. */
|
|
644
|
+
gap?: number;
|
|
645
|
+
/** Default false: nothing drags, nothing resizes, and no handle is drawn. */
|
|
646
|
+
editable?: boolean;
|
|
647
|
+
/** Selector a press must land inside to start a move. Default '.uic-panel-head' — Panel's own
|
|
648
|
+
* header. Point it at your own element and give that element `touch-action: none`. */
|
|
649
|
+
dragHandle?: string;
|
|
650
|
+
/** Below this container width the grid becomes ONE column in layout order and stops being
|
|
651
|
+
* arrangeable. Default 640. */
|
|
652
|
+
stackAt?: number;
|
|
653
|
+
/** The resize handle's accessible name. Name the panel in it. */
|
|
654
|
+
resizeLabel?: (id: string) => string;
|
|
655
|
+
/** Fires ONCE per interaction, on release — not per pixel. The layout stays yours: nothing
|
|
656
|
+
* moves until you apply what this hands you. */
|
|
657
|
+
onLayoutChange?: (layout: PanelLayoutItem[]) => void;
|
|
658
|
+
className?: string;
|
|
659
|
+
}
|
|
660
|
+
/** A grid of panels you can drag and resize, whose read-only mode is the default. Gravity is up
|
|
661
|
+
* and always on: the panel you drop keeps the cell you dropped it in, the rest flow around it. */
|
|
662
|
+
export const PanelGrid: ComponentType<PanelGridProps>;
|
|
663
|
+
|
|
664
|
+
/** Gravity applied to a layout you built yourself. Add a panel with `y: Infinity` to put it at
|
|
665
|
+
* the bottom, then pass the array through this to turn that into a real row. */
|
|
666
|
+
export function packLayout(layout: PanelLayoutItem[], cols?: number): PanelLayoutItem[];
|
package/dist/index.js
CHANGED
|
@@ -3084,6 +3084,7 @@ function FilePreview({
|
|
|
3084
3084
|
fetchFile,
|
|
3085
3085
|
officePdfUrl,
|
|
3086
3086
|
renderMarkdown,
|
|
3087
|
+
parseWorkbook,
|
|
3087
3088
|
onDownload,
|
|
3088
3089
|
title
|
|
3089
3090
|
}) {
|
|
@@ -3114,15 +3115,12 @@ function FilePreview({
|
|
|
3114
3115
|
return;
|
|
3115
3116
|
}
|
|
3116
3117
|
if (kind === "sheet") {
|
|
3118
|
+
if (!parseWorkbook) {
|
|
3119
|
+
setSt({ kind: "binary", error: "This format has no inline preview here \u2014 download it to open it." });
|
|
3120
|
+
return;
|
|
3121
|
+
}
|
|
3117
3122
|
try {
|
|
3118
|
-
const
|
|
3119
|
-
const XLSX = await import("xlsx");
|
|
3120
|
-
const wb = XLSX.read(buf, { type: "array" });
|
|
3121
|
-
const sheets = wb.SheetNames.map((n) => {
|
|
3122
|
-
const ws = wb.Sheets[n] || {};
|
|
3123
|
-
const filled = Boolean(ws["!ref"]);
|
|
3124
|
-
return { name: n, filled, rows: filled ? XLSX.utils.sheet_to_json(ws, { header: 1, raw: false }) : [] };
|
|
3125
|
-
});
|
|
3123
|
+
const sheets = await parseWorkbook(await res.arrayBuffer());
|
|
3126
3124
|
const first = sheets.findIndex((s) => s.filled);
|
|
3127
3125
|
if (alive) {
|
|
3128
3126
|
setTab(first < 0 ? 0 : first);
|
|
@@ -3153,7 +3151,7 @@ function FilePreview({
|
|
|
3153
3151
|
alive = false;
|
|
3154
3152
|
if (obj) URL.revokeObjectURL(obj);
|
|
3155
3153
|
};
|
|
3156
|
-
}, [url, name, fetchFile, officePdfUrl]);
|
|
3154
|
+
}, [url, name, fetchFile, officePdfUrl, parseWorkbook]);
|
|
3157
3155
|
const download = () => onDownload ? onDownload(url, name) : defaultDownload(url, name);
|
|
3158
3156
|
return /* @__PURE__ */ jsxs14("aside", { className: "uic-fp", "aria-label": title || `Preview of ${name}`, children: [
|
|
3159
3157
|
/* @__PURE__ */ jsxs14("header", { className: "uic-fp-head", children: [
|
|
@@ -3569,6 +3567,311 @@ function useTypewriter(phrases, { active = true } = {}) {
|
|
|
3569
3567
|
}, [active]);
|
|
3570
3568
|
return text;
|
|
3571
3569
|
}
|
|
3570
|
+
|
|
3571
|
+
// src/components/Panel.jsx
|
|
3572
|
+
import { jsx as jsx23, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
3573
|
+
function Panel(props) {
|
|
3574
|
+
const {
|
|
3575
|
+
title,
|
|
3576
|
+
titleAs: Heading = "h3",
|
|
3577
|
+
meta,
|
|
3578
|
+
actions,
|
|
3579
|
+
footer,
|
|
3580
|
+
loading = false,
|
|
3581
|
+
loadingLabel = "Loading",
|
|
3582
|
+
busy = false,
|
|
3583
|
+
busyLabel = "Refreshing",
|
|
3584
|
+
error = null,
|
|
3585
|
+
errorTitle = "This panel could not load",
|
|
3586
|
+
errorDetail = null,
|
|
3587
|
+
detailLabel = "Details",
|
|
3588
|
+
onRetry,
|
|
3589
|
+
retryLabel = "Try again",
|
|
3590
|
+
className = "",
|
|
3591
|
+
classNames = {},
|
|
3592
|
+
children
|
|
3593
|
+
} = props;
|
|
3594
|
+
const body = loading ? /* @__PURE__ */ jsxs20("div", { className: "uic-panel-load", children: [
|
|
3595
|
+
/* @__PURE__ */ jsx23("span", { className: "uic-panel-load-bar" }),
|
|
3596
|
+
/* @__PURE__ */ jsx23("span", { className: "uic-panel-load-bar" }),
|
|
3597
|
+
/* @__PURE__ */ jsx23("span", { className: "uic-panel-load-bar" }),
|
|
3598
|
+
/* @__PURE__ */ jsx23("span", { className: "uic-sr", children: loadingLabel })
|
|
3599
|
+
] }) : error ? /* @__PURE__ */ jsxs20("div", { className: "uic-panel-fail", children: [
|
|
3600
|
+
/* @__PURE__ */ jsx23("p", { className: "uic-panel-fail-t", children: errorTitle }),
|
|
3601
|
+
/* @__PURE__ */ jsx23("pre", { className: "uic-panel-fail-m", children: error }),
|
|
3602
|
+
errorDetail ? /* @__PURE__ */ jsxs20("details", { className: "uic-panel-fail-d", children: [
|
|
3603
|
+
/* @__PURE__ */ jsx23("summary", { children: detailLabel }),
|
|
3604
|
+
/* @__PURE__ */ jsx23("div", { className: "uic-panel-fail-dd", children: errorDetail })
|
|
3605
|
+
] }) : null,
|
|
3606
|
+
onRetry ? /* @__PURE__ */ jsx23("div", { className: "uic-panel-fail-act", children: /* @__PURE__ */ jsx23(Button, { size: "sm", onClick: onRetry, children: retryLabel }) }) : null
|
|
3607
|
+
] }) : children;
|
|
3608
|
+
return /* @__PURE__ */ jsxs20(
|
|
3609
|
+
"section",
|
|
3610
|
+
{
|
|
3611
|
+
className: ["uic-panel", className, classNames.root || ""].filter(Boolean).join(" "),
|
|
3612
|
+
"aria-busy": loading || busy || void 0,
|
|
3613
|
+
children: [
|
|
3614
|
+
/* @__PURE__ */ jsxs20("header", { className: ["uic-panel-head", classNames.head || ""].filter(Boolean).join(" "), children: [
|
|
3615
|
+
/* @__PURE__ */ jsxs20("div", { className: "uic-panel-titles", children: [
|
|
3616
|
+
title ? /* @__PURE__ */ jsx23(Heading, { className: "uic-panel-title", children: title }) : null,
|
|
3617
|
+
meta ? /* @__PURE__ */ jsx23("p", { className: "uic-panel-meta", children: meta }) : null
|
|
3618
|
+
] }),
|
|
3619
|
+
actions ? /* @__PURE__ */ jsx23("div", { className: "uic-panel-acts", children: actions }) : null
|
|
3620
|
+
] }),
|
|
3621
|
+
busy ? /* @__PURE__ */ jsx23("div", { className: "uic-panel-busy", role: "status", "aria-label": busyLabel }) : null,
|
|
3622
|
+
/* @__PURE__ */ jsx23("div", { className: ["uic-panel-body", classNames.body || ""].filter(Boolean).join(" "), children: body }),
|
|
3623
|
+
footer ? /* @__PURE__ */ jsx23("footer", { className: "uic-panel-foot", children: footer }) : null
|
|
3624
|
+
]
|
|
3625
|
+
}
|
|
3626
|
+
);
|
|
3627
|
+
}
|
|
3628
|
+
|
|
3629
|
+
// src/grid/PanelGrid.jsx
|
|
3630
|
+
import React14, { useCallback as useCallback8, useEffect as useEffect15, useLayoutEffect, useMemo as useMemo3, useRef as useRef11, useState as useState14 } from "react";
|
|
3631
|
+
|
|
3632
|
+
// src/grid/layout.js
|
|
3633
|
+
function sortLayout(layout) {
|
|
3634
|
+
return [...layout].sort((a, b) => a.y - b.y || a.x - b.x);
|
|
3635
|
+
}
|
|
3636
|
+
function overlaps(a, b) {
|
|
3637
|
+
return a.i !== b.i && a.x < b.x + b.w && a.x + a.w > b.x && a.y < b.y + b.h && a.y + a.h > b.y;
|
|
3638
|
+
}
|
|
3639
|
+
function firstOverlap(placed, item) {
|
|
3640
|
+
for (const p of placed) if (overlaps(p, item)) return p;
|
|
3641
|
+
return null;
|
|
3642
|
+
}
|
|
3643
|
+
function clampItem(item, cols) {
|
|
3644
|
+
const minW = Math.max(1, item.minW || 1);
|
|
3645
|
+
const minH = Math.max(1, item.minH || 1);
|
|
3646
|
+
const w = Math.min(Math.max(item.w ?? minW, minW), Math.min(item.maxW || cols, cols));
|
|
3647
|
+
const h = Math.max(Math.min(item.h ?? minH, item.maxH || Infinity), minH);
|
|
3648
|
+
const x = Math.min(Math.max(item.x ?? 0, 0), cols - w);
|
|
3649
|
+
return { ...item, x, y: Math.max(0, item.y ?? 0), w, h };
|
|
3650
|
+
}
|
|
3651
|
+
function compact(layout, cols, pinned) {
|
|
3652
|
+
const sorted = layout.map((it) => clampItem(it, cols)).sort((a, b) => a.y - b.y || Number(b.i === pinned) - Number(a.i === pinned) || a.x - b.x);
|
|
3653
|
+
const statics = sorted.filter((it) => it.static);
|
|
3654
|
+
const rest = sorted.filter((it) => !it.static);
|
|
3655
|
+
const placed = [...statics];
|
|
3656
|
+
for (const item of rest) {
|
|
3657
|
+
let y = item.y;
|
|
3658
|
+
while (y > 0 && !firstOverlap(placed, { ...item, y: y - 1 })) y--;
|
|
3659
|
+
let hit;
|
|
3660
|
+
while (hit = firstOverlap(placed, { ...item, y })) y = hit.y + hit.h;
|
|
3661
|
+
placed.push({ ...item, y });
|
|
3662
|
+
}
|
|
3663
|
+
const byId = new Map(placed.map((it) => [it.i, it]));
|
|
3664
|
+
return layout.map((it) => byId.get(it.i) || it);
|
|
3665
|
+
}
|
|
3666
|
+
function moveItem(layout, id, x, y, cols) {
|
|
3667
|
+
const next = layout.map((it) => it.i === id && !it.static ? clampItem({ ...it, x, y: Math.max(0, y) }, cols) : it);
|
|
3668
|
+
return compact(next, cols, id);
|
|
3669
|
+
}
|
|
3670
|
+
function nudgeItem(layout, id, dx, dy, cols) {
|
|
3671
|
+
const item = layout.find((it) => it.i === id);
|
|
3672
|
+
if (!item || item.static) return layout;
|
|
3673
|
+
if (dx) return moveItem(layout, id, item.x + dx, item.y, cols);
|
|
3674
|
+
const sameCols = layout.filter((o) => o.i !== id && o.x < item.x + item.w && o.x + o.w > item.x);
|
|
3675
|
+
if (dy < 0) {
|
|
3676
|
+
const above = sameCols.filter((o) => o.y + o.h <= item.y);
|
|
3677
|
+
if (!above.length) return layout;
|
|
3678
|
+
const near2 = above.reduce((a, b) => a.y + a.h > b.y + b.h ? a : b);
|
|
3679
|
+
return moveItem(layout, id, item.x, near2.y, cols);
|
|
3680
|
+
}
|
|
3681
|
+
const below = sameCols.filter((o) => o.y >= item.y + item.h);
|
|
3682
|
+
if (!below.length) return layout;
|
|
3683
|
+
const near = below.reduce((a, b) => a.y < b.y ? a : b);
|
|
3684
|
+
return moveItem(layout, id, item.x, near.y + near.h, cols);
|
|
3685
|
+
}
|
|
3686
|
+
function resizeItem(layout, id, w, h, cols) {
|
|
3687
|
+
const next = layout.map((it) => it.i === id && !it.static ? clampItem({ ...it, w, h }, cols) : it);
|
|
3688
|
+
return compact(next, cols, id);
|
|
3689
|
+
}
|
|
3690
|
+
function layoutRows(layout) {
|
|
3691
|
+
return layout.reduce((n, it) => Math.max(n, (it.y || 0) + (it.h || 1)), 0);
|
|
3692
|
+
}
|
|
3693
|
+
function sameLayout(a, b) {
|
|
3694
|
+
if (a.length !== b.length) return false;
|
|
3695
|
+
const byId = new Map(b.map((it) => [it.i, it]));
|
|
3696
|
+
return a.every((it) => {
|
|
3697
|
+
const o = byId.get(it.i);
|
|
3698
|
+
return o && o.x === it.x && o.y === it.y && o.w === it.w && o.h === it.h;
|
|
3699
|
+
});
|
|
3700
|
+
}
|
|
3701
|
+
|
|
3702
|
+
// src/grid/PanelGrid.jsx
|
|
3703
|
+
import { jsx as jsx24, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
3704
|
+
function useMeasuredWidth() {
|
|
3705
|
+
const ref = useRef11(null);
|
|
3706
|
+
const [width, setWidth] = useState14(0);
|
|
3707
|
+
useLayoutEffect(() => {
|
|
3708
|
+
const el = ref.current;
|
|
3709
|
+
if (!el) return void 0;
|
|
3710
|
+
const measure = () => setWidth(el.clientWidth);
|
|
3711
|
+
measure();
|
|
3712
|
+
const ro = new ResizeObserver(measure);
|
|
3713
|
+
ro.observe(el);
|
|
3714
|
+
return () => ro.disconnect();
|
|
3715
|
+
}, []);
|
|
3716
|
+
return [ref, width];
|
|
3717
|
+
}
|
|
3718
|
+
var NO_DRAG = "button, a, input, select, textarea, [data-uic-nodrag]";
|
|
3719
|
+
function PanelGrid(props) {
|
|
3720
|
+
const {
|
|
3721
|
+
layout = [],
|
|
3722
|
+
children,
|
|
3723
|
+
cols = 12,
|
|
3724
|
+
rowHeight = 40,
|
|
3725
|
+
gap = 12,
|
|
3726
|
+
editable = false,
|
|
3727
|
+
dragHandle = ".uic-panel-head",
|
|
3728
|
+
stackAt = 640,
|
|
3729
|
+
onLayoutChange,
|
|
3730
|
+
resizeLabel,
|
|
3731
|
+
className = ""
|
|
3732
|
+
} = props;
|
|
3733
|
+
const [wrapRef, width] = useMeasuredWidth();
|
|
3734
|
+
const [drag, setDrag] = useState14(null);
|
|
3735
|
+
const dragRef = useRef11(null);
|
|
3736
|
+
const swallowClick = useRef11(false);
|
|
3737
|
+
const stacked = width > 0 && width < stackAt;
|
|
3738
|
+
const arrangeable = editable && !stacked;
|
|
3739
|
+
const live = drag ? drag.preview : layout;
|
|
3740
|
+
const colW = width > 0 ? (width - gap * (cols - 1)) / cols : 0;
|
|
3741
|
+
const cellW = colW + gap;
|
|
3742
|
+
const cellH = rowHeight + gap;
|
|
3743
|
+
const rowsToPx = (h) => h * rowHeight + (h - 1) * gap;
|
|
3744
|
+
const stack2 = useMemo3(() => {
|
|
3745
|
+
if (!stacked) return null;
|
|
3746
|
+
const tops = /* @__PURE__ */ new Map();
|
|
3747
|
+
let y = 0;
|
|
3748
|
+
for (const it of sortLayout(live)) {
|
|
3749
|
+
tops.set(it.i, y);
|
|
3750
|
+
y += rowsToPx(it.h || 1) + gap;
|
|
3751
|
+
}
|
|
3752
|
+
return { tops, height: Math.max(0, y - gap) };
|
|
3753
|
+
}, [stacked, live, rowHeight, gap]);
|
|
3754
|
+
const rows = layoutRows(live);
|
|
3755
|
+
const height = stacked ? stack2.height : rows ? rowsToPx(rows) : 0;
|
|
3756
|
+
const commit = useCallback8((next) => {
|
|
3757
|
+
if (onLayoutChange && !sameLayout(next, layout)) onLayoutChange(next);
|
|
3758
|
+
}, [onLayoutChange, layout]);
|
|
3759
|
+
const detach = useRef11(null);
|
|
3760
|
+
useEffect15(() => () => detach.current?.(), []);
|
|
3761
|
+
const start = (id, mode) => (e) => {
|
|
3762
|
+
if (!arrangeable || e.button !== 0) return;
|
|
3763
|
+
const item = layout.find((it) => it.i === id);
|
|
3764
|
+
if (!item || item.static) return;
|
|
3765
|
+
if (mode === "move" && (!e.target.closest(dragHandle) || e.target.closest(NO_DRAG))) return;
|
|
3766
|
+
e.preventDefault();
|
|
3767
|
+
detach.current?.();
|
|
3768
|
+
const begin = { id, mode, origin: item, px: e.clientX, py: e.clientY, dx: 0, dy: 0, preview: layout };
|
|
3769
|
+
dragRef.current = begin;
|
|
3770
|
+
setDrag(begin);
|
|
3771
|
+
const onMove = (ev) => {
|
|
3772
|
+
const d = dragRef.current;
|
|
3773
|
+
if (!d) return;
|
|
3774
|
+
const dx = ev.clientX - d.px;
|
|
3775
|
+
const dy = ev.clientY - d.py;
|
|
3776
|
+
if (Math.abs(dx) > 3 || Math.abs(dy) > 3) swallowClick.current = true;
|
|
3777
|
+
const cx = Math.round(dx / cellW);
|
|
3778
|
+
const cy = Math.round(dy / cellH);
|
|
3779
|
+
const preview = d.mode === "move" ? moveItem(layout, d.id, d.origin.x + cx, d.origin.y + cy, cols) : resizeItem(layout, d.id, d.origin.w + cx, d.origin.h + cy, cols);
|
|
3780
|
+
dragRef.current = { ...d, dx, dy, preview };
|
|
3781
|
+
setDrag(dragRef.current);
|
|
3782
|
+
};
|
|
3783
|
+
const end = (commitIt) => () => {
|
|
3784
|
+
const d = dragRef.current;
|
|
3785
|
+
dragRef.current = null;
|
|
3786
|
+
off();
|
|
3787
|
+
setDrag(null);
|
|
3788
|
+
if (d && commitIt) commit(d.preview);
|
|
3789
|
+
};
|
|
3790
|
+
const onUp = end(true);
|
|
3791
|
+
const onKey2 = (ev) => {
|
|
3792
|
+
if (ev.key === "Escape") end(false)();
|
|
3793
|
+
};
|
|
3794
|
+
function off() {
|
|
3795
|
+
detach.current = null;
|
|
3796
|
+
window.removeEventListener("pointermove", onMove);
|
|
3797
|
+
window.removeEventListener("pointerup", onUp);
|
|
3798
|
+
window.removeEventListener("pointercancel", onUp);
|
|
3799
|
+
window.removeEventListener("keydown", onKey2);
|
|
3800
|
+
}
|
|
3801
|
+
detach.current = off;
|
|
3802
|
+
window.addEventListener("pointermove", onMove);
|
|
3803
|
+
window.addEventListener("pointerup", onUp);
|
|
3804
|
+
window.addEventListener("pointercancel", onUp);
|
|
3805
|
+
window.addEventListener("keydown", onKey2);
|
|
3806
|
+
};
|
|
3807
|
+
const onClickCapture = (e) => {
|
|
3808
|
+
if (!swallowClick.current) return;
|
|
3809
|
+
swallowClick.current = false;
|
|
3810
|
+
e.stopPropagation();
|
|
3811
|
+
e.preventDefault();
|
|
3812
|
+
};
|
|
3813
|
+
const onHandleKey = (id) => (e) => {
|
|
3814
|
+
const step = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }[e.key];
|
|
3815
|
+
if (!step) return;
|
|
3816
|
+
const item = layout.find((it) => it.i === id);
|
|
3817
|
+
if (!item) return;
|
|
3818
|
+
e.preventDefault();
|
|
3819
|
+
commit(e.shiftKey ? nudgeItem(layout, id, step[0], step[1], cols) : resizeItem(layout, id, item.w + step[0], item.h + step[1], cols));
|
|
3820
|
+
};
|
|
3821
|
+
const boxOf = (it) => stacked ? { left: 0, top: stack2.tops.get(it.i), width, height: rowsToPx(it.h || 1) } : { left: it.x * cellW, top: it.y * cellH, width: it.w * colW + (it.w - 1) * gap, height: rowsToPx(it.h) };
|
|
3822
|
+
const byId = new Map(live.map((it) => [it.i, it]));
|
|
3823
|
+
const ghost = drag && drag.mode === "move" && byId.has(drag.id) ? boxOf(byId.get(drag.id)) : null;
|
|
3824
|
+
const cls = ["uic-pg", arrangeable ? "is-editable" : "", stacked ? "is-stacked" : "", className].filter(Boolean).join(" ");
|
|
3825
|
+
return /* @__PURE__ */ jsxs21(
|
|
3826
|
+
"div",
|
|
3827
|
+
{
|
|
3828
|
+
ref: wrapRef,
|
|
3829
|
+
className: cls,
|
|
3830
|
+
style: { height },
|
|
3831
|
+
onClickCapture,
|
|
3832
|
+
onPointerDownCapture: () => {
|
|
3833
|
+
swallowClick.current = false;
|
|
3834
|
+
},
|
|
3835
|
+
children: [
|
|
3836
|
+
ghost ? /* @__PURE__ */ jsx24("div", { className: "uic-pg-ghost", "aria-hidden": "true", style: ghost }) : null,
|
|
3837
|
+
width > 0 && React14.Children.map(children, (child) => {
|
|
3838
|
+
if (!React14.isValidElement(child) || child.key == null) return null;
|
|
3839
|
+
const id = String(child.key).replace(/^\.\$/, "");
|
|
3840
|
+
const it = byId.get(id);
|
|
3841
|
+
if (!it) return null;
|
|
3842
|
+
const moving = drag && drag.id === id;
|
|
3843
|
+
const offset = moving && drag.mode === "move" ? { transform: `translate(${drag.dx}px, ${drag.dy}px)` } : null;
|
|
3844
|
+
return /* @__PURE__ */ jsxs21(
|
|
3845
|
+
"div",
|
|
3846
|
+
{
|
|
3847
|
+
className: "uic-pg-item" + (moving ? " is-moving" : ""),
|
|
3848
|
+
style: { ...boxOf(it), ...offset },
|
|
3849
|
+
onPointerDown: arrangeable ? start(id, "move") : void 0,
|
|
3850
|
+
children: [
|
|
3851
|
+
child,
|
|
3852
|
+
arrangeable && !it.static ? /* @__PURE__ */ jsx24(
|
|
3853
|
+
"button",
|
|
3854
|
+
{
|
|
3855
|
+
type: "button",
|
|
3856
|
+
className: "uic-pg-handle",
|
|
3857
|
+
"aria-label": resizeLabel ? resizeLabel(id) : "Resize panel. Arrow keys resize it; shift with arrow keys moves it past its neighbours.",
|
|
3858
|
+
onPointerDown: start(id, "resize"),
|
|
3859
|
+
onKeyDown: onHandleKey(id),
|
|
3860
|
+
children: /* @__PURE__ */ jsx24("svg", { width: "10", height: "10", viewBox: "0 0 10 10", "aria-hidden": "true", children: /* @__PURE__ */ jsx24("path", { d: "M9 1v8H1", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" }) })
|
|
3861
|
+
}
|
|
3862
|
+
) : null
|
|
3863
|
+
]
|
|
3864
|
+
}
|
|
3865
|
+
);
|
|
3866
|
+
})
|
|
3867
|
+
]
|
|
3868
|
+
}
|
|
3869
|
+
);
|
|
3870
|
+
}
|
|
3871
|
+
function packLayout(layout, cols = 12) {
|
|
3872
|
+
const bottom = layoutRows(layout.filter((it) => Number.isFinite(it.y)));
|
|
3873
|
+
return compact(layout.map((it) => Number.isFinite(it.y) ? it : { ...it, y: bottom }), cols);
|
|
3874
|
+
}
|
|
3572
3875
|
export {
|
|
3573
3876
|
AssistantTurn,
|
|
3574
3877
|
AuthForm,
|
|
@@ -3613,6 +3916,8 @@ export {
|
|
|
3613
3916
|
Input,
|
|
3614
3917
|
Modal,
|
|
3615
3918
|
PaneResizer,
|
|
3919
|
+
Panel,
|
|
3920
|
+
PanelGrid,
|
|
3616
3921
|
Popover,
|
|
3617
3922
|
SESSION_EVENT,
|
|
3618
3923
|
SearchField,
|
|
@@ -3645,6 +3950,7 @@ export {
|
|
|
3645
3950
|
isAuthed,
|
|
3646
3951
|
login,
|
|
3647
3952
|
logout,
|
|
3953
|
+
packLayout,
|
|
3648
3954
|
parseArgs,
|
|
3649
3955
|
prettyJson,
|
|
3650
3956
|
pumpResponsesStream,
|