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/dist/index.cjs CHANGED
@@ -72,6 +72,8 @@ __export(src_exports, {
72
72
  Input: () => Input,
73
73
  Modal: () => Modal,
74
74
  PaneResizer: () => PaneResizer,
75
+ Panel: () => Panel,
76
+ PanelGrid: () => PanelGrid,
75
77
  Popover: () => Popover,
76
78
  SESSION_EVENT: () => SESSION_EVENT,
77
79
  SearchField: () => SearchField,
@@ -104,6 +106,7 @@ __export(src_exports, {
104
106
  isAuthed: () => isAuthed,
105
107
  login: () => login,
106
108
  logout: () => logout,
109
+ packLayout: () => packLayout,
107
110
  parseArgs: () => parseArgs,
108
111
  prettyJson: () => prettyJson,
109
112
  pumpResponsesStream: () => pumpResponsesStream,
@@ -3312,6 +3315,7 @@ function FilePreview({
3312
3315
  fetchFile,
3313
3316
  officePdfUrl,
3314
3317
  renderMarkdown,
3318
+ parseWorkbook,
3315
3319
  onDownload,
3316
3320
  title
3317
3321
  }) {
@@ -3342,15 +3346,12 @@ function FilePreview({
3342
3346
  return;
3343
3347
  }
3344
3348
  if (kind === "sheet") {
3349
+ if (!parseWorkbook) {
3350
+ setSt({ kind: "binary", error: "This format has no inline preview here \u2014 download it to open it." });
3351
+ return;
3352
+ }
3345
3353
  try {
3346
- const buf = await res.arrayBuffer();
3347
- const XLSX = await import("xlsx");
3348
- const wb = XLSX.read(buf, { type: "array" });
3349
- const sheets = wb.SheetNames.map((n) => {
3350
- const ws = wb.Sheets[n] || {};
3351
- const filled = Boolean(ws["!ref"]);
3352
- return { name: n, filled, rows: filled ? XLSX.utils.sheet_to_json(ws, { header: 1, raw: false }) : [] };
3353
- });
3354
+ const sheets = await parseWorkbook(await res.arrayBuffer());
3354
3355
  const first = sheets.findIndex((s) => s.filled);
3355
3356
  if (alive) {
3356
3357
  setTab(first < 0 ? 0 : first);
@@ -3381,7 +3382,7 @@ function FilePreview({
3381
3382
  alive = false;
3382
3383
  if (obj) URL.revokeObjectURL(obj);
3383
3384
  };
3384
- }, [url, name, fetchFile, officePdfUrl]);
3385
+ }, [url, name, fetchFile, officePdfUrl, parseWorkbook]);
3385
3386
  const download = () => onDownload ? onDownload(url, name) : defaultDownload(url, name);
3386
3387
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("aside", { className: "uic-fp", "aria-label": title || `Preview of ${name}`, children: [
3387
3388
  /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("header", { className: "uic-fp-head", children: [
@@ -3797,4 +3798,309 @@ function useTypewriter(phrases, { active = true } = {}) {
3797
3798
  }, [active]);
3798
3799
  return text;
3799
3800
  }
3801
+
3802
+ // src/components/Panel.jsx
3803
+ var import_jsx_runtime23 = require("react/jsx-runtime");
3804
+ function Panel(props) {
3805
+ const {
3806
+ title,
3807
+ titleAs: Heading = "h3",
3808
+ meta,
3809
+ actions,
3810
+ footer,
3811
+ loading = false,
3812
+ loadingLabel = "Loading",
3813
+ busy = false,
3814
+ busyLabel = "Refreshing",
3815
+ error = null,
3816
+ errorTitle = "This panel could not load",
3817
+ errorDetail = null,
3818
+ detailLabel = "Details",
3819
+ onRetry,
3820
+ retryLabel = "Try again",
3821
+ className = "",
3822
+ classNames = {},
3823
+ children
3824
+ } = props;
3825
+ const body = loading ? /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "uic-panel-load", children: [
3826
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-panel-load-bar" }),
3827
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-panel-load-bar" }),
3828
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-panel-load-bar" }),
3829
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("span", { className: "uic-sr", children: loadingLabel })
3830
+ ] }) : error ? /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "uic-panel-fail", children: [
3831
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("p", { className: "uic-panel-fail-t", children: errorTitle }),
3832
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("pre", { className: "uic-panel-fail-m", children: error }),
3833
+ errorDetail ? /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("details", { className: "uic-panel-fail-d", children: [
3834
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("summary", { children: detailLabel }),
3835
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "uic-panel-fail-dd", children: errorDetail })
3836
+ ] }) : null,
3837
+ onRetry ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "uic-panel-fail-act", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Button, { size: "sm", onClick: onRetry, children: retryLabel }) }) : null
3838
+ ] }) : children;
3839
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
3840
+ "section",
3841
+ {
3842
+ className: ["uic-panel", className, classNames.root || ""].filter(Boolean).join(" "),
3843
+ "aria-busy": loading || busy || void 0,
3844
+ children: [
3845
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("header", { className: ["uic-panel-head", classNames.head || ""].filter(Boolean).join(" "), children: [
3846
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "uic-panel-titles", children: [
3847
+ title ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Heading, { className: "uic-panel-title", children: title }) : null,
3848
+ meta ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("p", { className: "uic-panel-meta", children: meta }) : null
3849
+ ] }),
3850
+ actions ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "uic-panel-acts", children: actions }) : null
3851
+ ] }),
3852
+ busy ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "uic-panel-busy", role: "status", "aria-label": busyLabel }) : null,
3853
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: ["uic-panel-body", classNames.body || ""].filter(Boolean).join(" "), children: body }),
3854
+ footer ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("footer", { className: "uic-panel-foot", children: footer }) : null
3855
+ ]
3856
+ }
3857
+ );
3858
+ }
3859
+
3860
+ // src/grid/PanelGrid.jsx
3861
+ var import_react25 = __toESM(require("react"), 1);
3862
+
3863
+ // src/grid/layout.js
3864
+ function sortLayout(layout) {
3865
+ return [...layout].sort((a, b) => a.y - b.y || a.x - b.x);
3866
+ }
3867
+ function overlaps(a, b) {
3868
+ 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;
3869
+ }
3870
+ function firstOverlap(placed, item) {
3871
+ for (const p of placed) if (overlaps(p, item)) return p;
3872
+ return null;
3873
+ }
3874
+ function clampItem(item, cols) {
3875
+ const minW = Math.max(1, item.minW || 1);
3876
+ const minH = Math.max(1, item.minH || 1);
3877
+ const w = Math.min(Math.max(item.w ?? minW, minW), Math.min(item.maxW || cols, cols));
3878
+ const h = Math.max(Math.min(item.h ?? minH, item.maxH || Infinity), minH);
3879
+ const x = Math.min(Math.max(item.x ?? 0, 0), cols - w);
3880
+ return { ...item, x, y: Math.max(0, item.y ?? 0), w, h };
3881
+ }
3882
+ function compact(layout, cols, pinned) {
3883
+ 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);
3884
+ const statics = sorted.filter((it) => it.static);
3885
+ const rest = sorted.filter((it) => !it.static);
3886
+ const placed = [...statics];
3887
+ for (const item of rest) {
3888
+ let y = item.y;
3889
+ while (y > 0 && !firstOverlap(placed, { ...item, y: y - 1 })) y--;
3890
+ let hit;
3891
+ while (hit = firstOverlap(placed, { ...item, y })) y = hit.y + hit.h;
3892
+ placed.push({ ...item, y });
3893
+ }
3894
+ const byId = new Map(placed.map((it) => [it.i, it]));
3895
+ return layout.map((it) => byId.get(it.i) || it);
3896
+ }
3897
+ function moveItem(layout, id, x, y, cols) {
3898
+ const next = layout.map((it) => it.i === id && !it.static ? clampItem({ ...it, x, y: Math.max(0, y) }, cols) : it);
3899
+ return compact(next, cols, id);
3900
+ }
3901
+ function nudgeItem(layout, id, dx, dy, cols) {
3902
+ const item = layout.find((it) => it.i === id);
3903
+ if (!item || item.static) return layout;
3904
+ if (dx) return moveItem(layout, id, item.x + dx, item.y, cols);
3905
+ const sameCols = layout.filter((o) => o.i !== id && o.x < item.x + item.w && o.x + o.w > item.x);
3906
+ if (dy < 0) {
3907
+ const above = sameCols.filter((o) => o.y + o.h <= item.y);
3908
+ if (!above.length) return layout;
3909
+ const near2 = above.reduce((a, b) => a.y + a.h > b.y + b.h ? a : b);
3910
+ return moveItem(layout, id, item.x, near2.y, cols);
3911
+ }
3912
+ const below = sameCols.filter((o) => o.y >= item.y + item.h);
3913
+ if (!below.length) return layout;
3914
+ const near = below.reduce((a, b) => a.y < b.y ? a : b);
3915
+ return moveItem(layout, id, item.x, near.y + near.h, cols);
3916
+ }
3917
+ function resizeItem(layout, id, w, h, cols) {
3918
+ const next = layout.map((it) => it.i === id && !it.static ? clampItem({ ...it, w, h }, cols) : it);
3919
+ return compact(next, cols, id);
3920
+ }
3921
+ function layoutRows(layout) {
3922
+ return layout.reduce((n, it) => Math.max(n, (it.y || 0) + (it.h || 1)), 0);
3923
+ }
3924
+ function sameLayout(a, b) {
3925
+ if (a.length !== b.length) return false;
3926
+ const byId = new Map(b.map((it) => [it.i, it]));
3927
+ return a.every((it) => {
3928
+ const o = byId.get(it.i);
3929
+ return o && o.x === it.x && o.y === it.y && o.w === it.w && o.h === it.h;
3930
+ });
3931
+ }
3932
+
3933
+ // src/grid/PanelGrid.jsx
3934
+ var import_jsx_runtime24 = require("react/jsx-runtime");
3935
+ function useMeasuredWidth() {
3936
+ const ref = (0, import_react25.useRef)(null);
3937
+ const [width, setWidth] = (0, import_react25.useState)(0);
3938
+ (0, import_react25.useLayoutEffect)(() => {
3939
+ const el = ref.current;
3940
+ if (!el) return void 0;
3941
+ const measure = () => setWidth(el.clientWidth);
3942
+ measure();
3943
+ const ro = new ResizeObserver(measure);
3944
+ ro.observe(el);
3945
+ return () => ro.disconnect();
3946
+ }, []);
3947
+ return [ref, width];
3948
+ }
3949
+ var NO_DRAG = "button, a, input, select, textarea, [data-uic-nodrag]";
3950
+ function PanelGrid(props) {
3951
+ const {
3952
+ layout = [],
3953
+ children,
3954
+ cols = 12,
3955
+ rowHeight = 40,
3956
+ gap = 12,
3957
+ editable = false,
3958
+ dragHandle = ".uic-panel-head",
3959
+ stackAt = 640,
3960
+ onLayoutChange,
3961
+ resizeLabel,
3962
+ className = ""
3963
+ } = props;
3964
+ const [wrapRef, width] = useMeasuredWidth();
3965
+ const [drag, setDrag] = (0, import_react25.useState)(null);
3966
+ const dragRef = (0, import_react25.useRef)(null);
3967
+ const swallowClick = (0, import_react25.useRef)(false);
3968
+ const stacked = width > 0 && width < stackAt;
3969
+ const arrangeable = editable && !stacked;
3970
+ const live = drag ? drag.preview : layout;
3971
+ const colW = width > 0 ? (width - gap * (cols - 1)) / cols : 0;
3972
+ const cellW = colW + gap;
3973
+ const cellH = rowHeight + gap;
3974
+ const rowsToPx = (h) => h * rowHeight + (h - 1) * gap;
3975
+ const stack2 = (0, import_react25.useMemo)(() => {
3976
+ if (!stacked) return null;
3977
+ const tops = /* @__PURE__ */ new Map();
3978
+ let y = 0;
3979
+ for (const it of sortLayout(live)) {
3980
+ tops.set(it.i, y);
3981
+ y += rowsToPx(it.h || 1) + gap;
3982
+ }
3983
+ return { tops, height: Math.max(0, y - gap) };
3984
+ }, [stacked, live, rowHeight, gap]);
3985
+ const rows = layoutRows(live);
3986
+ const height = stacked ? stack2.height : rows ? rowsToPx(rows) : 0;
3987
+ const commit = (0, import_react25.useCallback)((next) => {
3988
+ if (onLayoutChange && !sameLayout(next, layout)) onLayoutChange(next);
3989
+ }, [onLayoutChange, layout]);
3990
+ const detach = (0, import_react25.useRef)(null);
3991
+ (0, import_react25.useEffect)(() => () => detach.current?.(), []);
3992
+ const start = (id, mode) => (e) => {
3993
+ if (!arrangeable || e.button !== 0) return;
3994
+ const item = layout.find((it) => it.i === id);
3995
+ if (!item || item.static) return;
3996
+ if (mode === "move" && (!e.target.closest(dragHandle) || e.target.closest(NO_DRAG))) return;
3997
+ e.preventDefault();
3998
+ detach.current?.();
3999
+ const begin = { id, mode, origin: item, px: e.clientX, py: e.clientY, dx: 0, dy: 0, preview: layout };
4000
+ dragRef.current = begin;
4001
+ setDrag(begin);
4002
+ const onMove = (ev) => {
4003
+ const d = dragRef.current;
4004
+ if (!d) return;
4005
+ const dx = ev.clientX - d.px;
4006
+ const dy = ev.clientY - d.py;
4007
+ if (Math.abs(dx) > 3 || Math.abs(dy) > 3) swallowClick.current = true;
4008
+ const cx = Math.round(dx / cellW);
4009
+ const cy = Math.round(dy / cellH);
4010
+ 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);
4011
+ dragRef.current = { ...d, dx, dy, preview };
4012
+ setDrag(dragRef.current);
4013
+ };
4014
+ const end = (commitIt) => () => {
4015
+ const d = dragRef.current;
4016
+ dragRef.current = null;
4017
+ off();
4018
+ setDrag(null);
4019
+ if (d && commitIt) commit(d.preview);
4020
+ };
4021
+ const onUp = end(true);
4022
+ const onKey2 = (ev) => {
4023
+ if (ev.key === "Escape") end(false)();
4024
+ };
4025
+ function off() {
4026
+ detach.current = null;
4027
+ window.removeEventListener("pointermove", onMove);
4028
+ window.removeEventListener("pointerup", onUp);
4029
+ window.removeEventListener("pointercancel", onUp);
4030
+ window.removeEventListener("keydown", onKey2);
4031
+ }
4032
+ detach.current = off;
4033
+ window.addEventListener("pointermove", onMove);
4034
+ window.addEventListener("pointerup", onUp);
4035
+ window.addEventListener("pointercancel", onUp);
4036
+ window.addEventListener("keydown", onKey2);
4037
+ };
4038
+ const onClickCapture = (e) => {
4039
+ if (!swallowClick.current) return;
4040
+ swallowClick.current = false;
4041
+ e.stopPropagation();
4042
+ e.preventDefault();
4043
+ };
4044
+ const onHandleKey = (id) => (e) => {
4045
+ const step = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }[e.key];
4046
+ if (!step) return;
4047
+ const item = layout.find((it) => it.i === id);
4048
+ if (!item) return;
4049
+ e.preventDefault();
4050
+ commit(e.shiftKey ? nudgeItem(layout, id, step[0], step[1], cols) : resizeItem(layout, id, item.w + step[0], item.h + step[1], cols));
4051
+ };
4052
+ 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) };
4053
+ const byId = new Map(live.map((it) => [it.i, it]));
4054
+ const ghost = drag && drag.mode === "move" && byId.has(drag.id) ? boxOf(byId.get(drag.id)) : null;
4055
+ const cls = ["uic-pg", arrangeable ? "is-editable" : "", stacked ? "is-stacked" : "", className].filter(Boolean).join(" ");
4056
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
4057
+ "div",
4058
+ {
4059
+ ref: wrapRef,
4060
+ className: cls,
4061
+ style: { height },
4062
+ onClickCapture,
4063
+ onPointerDownCapture: () => {
4064
+ swallowClick.current = false;
4065
+ },
4066
+ children: [
4067
+ ghost ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: "uic-pg-ghost", "aria-hidden": "true", style: ghost }) : null,
4068
+ width > 0 && import_react25.default.Children.map(children, (child) => {
4069
+ if (!import_react25.default.isValidElement(child) || child.key == null) return null;
4070
+ const id = String(child.key).replace(/^\.\$/, "");
4071
+ const it = byId.get(id);
4072
+ if (!it) return null;
4073
+ const moving = drag && drag.id === id;
4074
+ const offset = moving && drag.mode === "move" ? { transform: `translate(${drag.dx}px, ${drag.dy}px)` } : null;
4075
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
4076
+ "div",
4077
+ {
4078
+ className: "uic-pg-item" + (moving ? " is-moving" : ""),
4079
+ style: { ...boxOf(it), ...offset },
4080
+ onPointerDown: arrangeable ? start(id, "move") : void 0,
4081
+ children: [
4082
+ child,
4083
+ arrangeable && !it.static ? /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
4084
+ "button",
4085
+ {
4086
+ type: "button",
4087
+ className: "uic-pg-handle",
4088
+ "aria-label": resizeLabel ? resizeLabel(id) : "Resize panel. Arrow keys resize it; shift with arrow keys moves it past its neighbours.",
4089
+ onPointerDown: start(id, "resize"),
4090
+ onKeyDown: onHandleKey(id),
4091
+ children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("svg", { width: "10", height: "10", viewBox: "0 0 10 10", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("path", { d: "M9 1v8H1", fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" }) })
4092
+ }
4093
+ ) : null
4094
+ ]
4095
+ }
4096
+ );
4097
+ })
4098
+ ]
4099
+ }
4100
+ );
4101
+ }
4102
+ function packLayout(layout, cols = 12) {
4103
+ const bottom = layoutRows(layout.filter((it) => Number.isFinite(it.y)));
4104
+ return compact(layout.map((it) => Number.isFinite(it.y) ? it : { ...it, y: bottom }), cols);
4105
+ }
3800
4106
  //# sourceMappingURL=index.cjs.map