@inf-monkeys-tech/monkeys-design 0.4.30 → 0.4.32

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.js CHANGED
@@ -4548,7 +4548,7 @@ var require_lodash = __commonJS({
4548
4548
  function valuesIn(object) {
4549
4549
  return object == null ? [] : baseValues(object, keysIn(object));
4550
4550
  }
4551
- function clamp3(number, lower, upper) {
4551
+ function clamp4(number, lower, upper) {
4552
4552
  if (upper === undefined2) {
4553
4553
  upper = lower;
4554
4554
  lower = undefined2;
@@ -5225,7 +5225,7 @@ var require_lodash = __commonJS({
5225
5225
  lodash.camelCase = camelCase;
5226
5226
  lodash.capitalize = capitalize;
5227
5227
  lodash.ceil = ceil;
5228
- lodash.clamp = clamp3;
5228
+ lodash.clamp = clamp4;
5229
5229
  lodash.clone = clone;
5230
5230
  lodash.cloneDeep = cloneDeep;
5231
5231
  lodash.cloneDeepWith = cloneDeepWith;
@@ -19996,6 +19996,2817 @@ function AppLayout({ header, sidebar, children, flush = false, className }) {
19996
19996
  ] })
19997
19997
  ] });
19998
19998
  }
19999
+ function ClampIcon({ expanded }) {
20000
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { "aria-hidden": "true", viewBox: "0 0 20 20", className: "h-4 w-4", fill: "none", children: [
20001
+ /* @__PURE__ */ jsxRuntime.jsx(
20002
+ "path",
20003
+ {
20004
+ d: "M4 4.5h12M4 15.5h12M7.5 7.5 5 10l2.5 2.5M12.5 7.5 15 10l-2.5 2.5",
20005
+ stroke: "currentColor",
20006
+ strokeWidth: "1.6",
20007
+ strokeLinecap: "round",
20008
+ strokeLinejoin: "round",
20009
+ className: expanded ? "" : "hidden"
20010
+ }
20011
+ ),
20012
+ /* @__PURE__ */ jsxRuntime.jsx(
20013
+ "path",
20014
+ {
20015
+ d: "M4 4.5h12M4 15.5h12M5 7.5 7.5 10 5 12.5M15 7.5 12.5 10l2.5 2.5",
20016
+ stroke: "currentColor",
20017
+ strokeWidth: "1.6",
20018
+ strokeLinecap: "round",
20019
+ strokeLinejoin: "round",
20020
+ className: expanded ? "hidden" : ""
20021
+ }
20022
+ )
20023
+ ] });
20024
+ }
20025
+ function ResizeGripIcon() {
20026
+ return /* @__PURE__ */ jsxRuntime.jsx(
20027
+ "span",
20028
+ {
20029
+ "aria-hidden": "true",
20030
+ className: "pointer-events-none absolute right-1/2 top-3 bottom-3 w-px translate-x-1/2 rounded-full bg-border/65 opacity-0 transition-opacity group-hover/resize:opacity-100"
20031
+ }
20032
+ );
20033
+ }
20034
+ function getItemTitle(item) {
20035
+ if (item.title) return item.title;
20036
+ return typeof item.label === "string" ? item.label : void 0;
20037
+ }
20038
+ function clampWidth2(width, minWidth, maxWidth) {
20039
+ return Math.min(Math.max(width, minWidth), maxWidth);
20040
+ }
20041
+ function assignRef(ref, node) {
20042
+ if (typeof ref === "function") {
20043
+ ref(node);
20044
+ } else if (ref) {
20045
+ ref.current = node;
20046
+ }
20047
+ }
20048
+ function readStoredLayout(storageKey, options) {
20049
+ const fallback = {
20050
+ collapsed: options.defaultCollapsed,
20051
+ width: clampWidth2(options.defaultWidth, options.minWidth, options.maxWidth)
20052
+ };
20053
+ if (typeof window === "undefined" || !storageKey) return fallback;
20054
+ try {
20055
+ const rawValue = window.localStorage.getItem(storageKey);
20056
+ if (!rawValue) return fallback;
20057
+ const parsedValue = JSON.parse(rawValue);
20058
+ return {
20059
+ collapsed: typeof parsedValue.collapsed === "boolean" ? parsedValue.collapsed : fallback.collapsed,
20060
+ width: typeof parsedValue.width === "number" && Number.isFinite(parsedValue.width) ? clampWidth2(parsedValue.width, options.minWidth, options.maxWidth) : fallback.width
20061
+ };
20062
+ } catch {
20063
+ return fallback;
20064
+ }
20065
+ }
20066
+ var WorkbenchResizableSidebar = React.forwardRef(
20067
+ function WorkbenchResizableSidebar2({
20068
+ title,
20069
+ items,
20070
+ activeItemId,
20071
+ itemAs,
20072
+ collapsed,
20073
+ defaultCollapsed = false,
20074
+ onCollapsedChange,
20075
+ width,
20076
+ onWidthChange,
20077
+ defaultWidth = 220,
20078
+ minWidth = 180,
20079
+ maxWidth = 420,
20080
+ collapsedWidth = 60,
20081
+ collapseThreshold = 140,
20082
+ storageKey,
20083
+ resizable = true,
20084
+ collapsible = true,
20085
+ collapseLabel = "Collapse sidebar",
20086
+ expandLabel = "Expand sidebar",
20087
+ resizeLabel = "Resize sidebar",
20088
+ desktopClassName = "hidden md:flex",
20089
+ mobileClassName = "flex md:hidden",
20090
+ className,
20091
+ classNames,
20092
+ style
20093
+ }, ref) {
20094
+ const initialLayoutRef = React.useRef(null);
20095
+ if (!initialLayoutRef.current) {
20096
+ initialLayoutRef.current = readStoredLayout(storageKey, {
20097
+ defaultCollapsed,
20098
+ defaultWidth,
20099
+ minWidth,
20100
+ maxWidth
20101
+ });
20102
+ }
20103
+ const sidebarRef = React.useRef(null);
20104
+ const [internalCollapsed, setInternalCollapsed] = React.useState(initialLayoutRef.current.collapsed);
20105
+ const [internalWidth, setInternalWidth] = React.useState(initialLayoutRef.current.width);
20106
+ const [isResizing, setIsResizing] = React.useState(false);
20107
+ const resolvedCollapsed = collapsed ?? internalCollapsed;
20108
+ const resolvedWidth = width ?? internalWidth;
20109
+ const isCollapsedControlled = collapsed !== void 0;
20110
+ const isWidthControlled = width !== void 0;
20111
+ const setSidebarRef = (node) => {
20112
+ sidebarRef.current = node;
20113
+ assignRef(ref, node);
20114
+ };
20115
+ const updateCollapsed = (nextCollapsed) => {
20116
+ if (!collapsible && nextCollapsed) return;
20117
+ if (!isCollapsedControlled) {
20118
+ setInternalCollapsed(nextCollapsed);
20119
+ }
20120
+ onCollapsedChange?.(nextCollapsed);
20121
+ };
20122
+ const updateWidth = (nextWidth) => {
20123
+ const clampedWidth = clampWidth2(nextWidth, minWidth, maxWidth);
20124
+ if (!isWidthControlled) {
20125
+ setInternalWidth(clampedWidth);
20126
+ }
20127
+ onWidthChange?.(clampedWidth);
20128
+ };
20129
+ const startResize = (event) => {
20130
+ if (!resizable) return;
20131
+ event.preventDefault();
20132
+ setIsResizing(true);
20133
+ };
20134
+ const handleResizeKeyDown = (event) => {
20135
+ if (!resizable) return;
20136
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
20137
+ event.preventDefault();
20138
+ if (event.key === "ArrowLeft") {
20139
+ const nextWidth = resolvedWidth - 24;
20140
+ if (nextWidth < collapseThreshold && collapsible) {
20141
+ updateCollapsed(true);
20142
+ return;
20143
+ }
20144
+ updateWidth(nextWidth);
20145
+ } else {
20146
+ if (resolvedCollapsed) {
20147
+ updateCollapsed(false);
20148
+ updateWidth(Math.max(resolvedWidth, minWidth));
20149
+ return;
20150
+ }
20151
+ updateWidth(resolvedWidth + 24);
20152
+ }
20153
+ };
20154
+ React.useEffect(() => {
20155
+ if (typeof window === "undefined" || !storageKey) return;
20156
+ window.localStorage.setItem(storageKey, JSON.stringify({
20157
+ collapsed: resolvedCollapsed,
20158
+ width: clampWidth2(resolvedWidth, minWidth, maxWidth)
20159
+ }));
20160
+ }, [maxWidth, minWidth, resolvedCollapsed, resolvedWidth, storageKey]);
20161
+ React.useEffect(() => {
20162
+ if (!isResizing) return void 0;
20163
+ const handlePointerMove = (event) => {
20164
+ const sidebarNode = sidebarRef.current;
20165
+ if (!sidebarNode) return;
20166
+ const nextWidth = event.clientX - sidebarNode.getBoundingClientRect().left;
20167
+ if (nextWidth < collapseThreshold && collapsible) {
20168
+ updateCollapsed(true);
20169
+ return;
20170
+ }
20171
+ updateCollapsed(false);
20172
+ updateWidth(nextWidth);
20173
+ };
20174
+ const handlePointerUp = () => setIsResizing(false);
20175
+ window.addEventListener("pointermove", handlePointerMove);
20176
+ window.addEventListener("pointerup", handlePointerUp);
20177
+ document.body.style.cursor = "col-resize";
20178
+ document.body.style.userSelect = "none";
20179
+ return () => {
20180
+ window.removeEventListener("pointermove", handlePointerMove);
20181
+ window.removeEventListener("pointerup", handlePointerUp);
20182
+ document.body.style.cursor = "";
20183
+ document.body.style.userSelect = "";
20184
+ };
20185
+ }, [collapseThreshold, collapsible, isResizing, maxWidth, minWidth, resolvedWidth, resolvedCollapsed]);
20186
+ const renderItem = (item, mobile = false) => {
20187
+ const active = item.active ?? item.id === activeItemId;
20188
+ const ItemComponent = itemAs ?? (item.href ? "a" : "button");
20189
+ const itemTitle = getItemTitle(item);
20190
+ const itemProps = {
20191
+ ...item.to ? { to: item.to } : {},
20192
+ ...item.href ? { href: item.href } : {},
20193
+ ...ItemComponent === "button" ? { type: "button" } : {},
20194
+ title: itemTitle,
20195
+ "aria-current": active ? "page" : void 0,
20196
+ "aria-disabled": item.disabled || void 0,
20197
+ tabIndex: item.disabled ? -1 : void 0,
20198
+ onClick: (event) => {
20199
+ if (item.disabled) {
20200
+ event.preventDefault();
20201
+ return;
20202
+ }
20203
+ item.onClick?.(event);
20204
+ }
20205
+ };
20206
+ return /* @__PURE__ */ jsxRuntime.jsxs(
20207
+ ItemComponent,
20208
+ {
20209
+ ...itemProps,
20210
+ "data-active": active ? "true" : "false",
20211
+ className: cn(
20212
+ mobile ? "inline-flex h-9 shrink-0 items-center gap-2 rounded-lg border px-3 text-xs font-medium transition-colors" : "relative flex h-9 w-full items-center justify-between gap-2 overflow-hidden rounded-md border px-2 text-left text-[12px] shadow-none transition-colors",
20213
+ mobile ? active ? "border-primary/40 bg-primary/12 text-foreground" : "border-border/60 bg-card/60 text-muted-foreground hover:bg-card/80 hover:text-foreground" : active ? "border-primary/40 bg-primary/12 text-foreground shadow-sm" : "border-border/60 bg-card/60 text-foreground hover:border-primary/20 hover:bg-card/80",
20214
+ !mobile && resolvedCollapsed && "justify-center px-0",
20215
+ item.disabled && "pointer-events-none opacity-50",
20216
+ mobile ? classNames?.mobileItem : classNames?.item,
20217
+ item.className
20218
+ ),
20219
+ children: [
20220
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("inline-flex h-4 w-4 shrink-0 items-center justify-center [&_svg]:h-3.5 [&_svg]:w-3.5", classNames?.itemIcon), children: item.icon }),
20221
+ mobile || !resolvedCollapsed ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("min-w-0 flex-1 truncate", classNames?.itemLabel), children: item.label }) : null,
20222
+ !mobile && !resolvedCollapsed && item.endContent ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0", children: item.endContent }) : null
20223
+ ]
20224
+ },
20225
+ item.id
20226
+ );
20227
+ };
20228
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
20229
+ /* @__PURE__ */ jsxRuntime.jsxs(
20230
+ "aside",
20231
+ {
20232
+ ref: setSidebarRef,
20233
+ "data-workbench-resizable-sidebar": true,
20234
+ "data-collapsed": resolvedCollapsed ? "true" : "false",
20235
+ className: cn(
20236
+ "relative z-20 h-full min-h-0 flex-shrink-0 flex-col rounded-xl border border-border/70 bg-card p-3 text-card-foreground shadow-sm",
20237
+ "transition-[width,opacity] duration-300",
20238
+ resolvedCollapsed && "items-center",
20239
+ desktopClassName,
20240
+ classNames?.root,
20241
+ className
20242
+ ),
20243
+ style: {
20244
+ width: resolvedCollapsed ? collapsedWidth : resolvedWidth,
20245
+ transition: isResizing ? "none" : void 0,
20246
+ ...style
20247
+ },
20248
+ children: [
20249
+ resizable ? /* @__PURE__ */ jsxRuntime.jsx(
20250
+ "button",
20251
+ {
20252
+ type: "button",
20253
+ "aria-label": resizeLabel,
20254
+ title: resizeLabel,
20255
+ className: cn("group/resize absolute -right-1.5 bottom-0 top-0 z-50 w-3 cursor-col-resize bg-transparent outline-none focus-visible:ring-2 focus-visible:ring-primary/30", classNames?.resizeHandle),
20256
+ onPointerDown: startResize,
20257
+ onKeyDown: handleResizeKeyDown,
20258
+ children: /* @__PURE__ */ jsxRuntime.jsx(ResizeGripIcon, {})
20259
+ }
20260
+ ) : null,
20261
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full w-full min-w-0 flex-col overflow-visible", children: [
20262
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("mb-3 flex min-w-0 items-center gap-2", resolvedCollapsed ? "justify-center px-0" : "justify-between px-2", classNames?.header), children: [
20263
+ !resolvedCollapsed && title ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("min-w-0 truncate text-[11px] font-medium uppercase text-muted-foreground", classNames?.title), children: title }) : null,
20264
+ collapsible ? /* @__PURE__ */ jsxRuntime.jsx(
20265
+ "button",
20266
+ {
20267
+ type: "button",
20268
+ className: cn("inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30", classNames?.collapseButton),
20269
+ "aria-label": resolvedCollapsed ? expandLabel : collapseLabel,
20270
+ title: resolvedCollapsed ? expandLabel : collapseLabel,
20271
+ onClick: () => updateCollapsed(!resolvedCollapsed),
20272
+ children: /* @__PURE__ */ jsxRuntime.jsx(ClampIcon, { expanded: !resolvedCollapsed })
20273
+ }
20274
+ ) : null
20275
+ ] }),
20276
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("min-h-0 flex-1 space-y-2 overflow-y-auto", resolvedCollapsed && "flex w-full flex-col items-center", classNames?.list), children: items.map((item) => renderItem(item)) })
20277
+ ] })
20278
+ ]
20279
+ }
20280
+ ),
20281
+ /* @__PURE__ */ jsxRuntime.jsx("nav", { className: cn("gap-2 overflow-x-auto pb-1", mobileClassName, classNames?.mobileNav), "aria-label": typeof title === "string" ? title : void 0, children: items.map((item) => renderItem(item, true)) })
20282
+ ] });
20283
+ }
20284
+ );
20285
+ function shouldRenderBodyWrapper(props) {
20286
+ return Boolean(
20287
+ props.header || props.footer || props.bodyAs || props.bodyClassName || props.bodyProps || props.classNames?.body
20288
+ );
20289
+ }
20290
+ var WorkbenchContentPane = React.forwardRef(
20291
+ function WorkbenchContentPane2({
20292
+ as: Component = "section",
20293
+ bodyAs: BodyComponent = "div",
20294
+ header,
20295
+ footer,
20296
+ children,
20297
+ className,
20298
+ headerClassName,
20299
+ bodyClassName,
20300
+ footerClassName,
20301
+ bodyProps,
20302
+ classNames,
20303
+ style,
20304
+ ...props
20305
+ }, ref) {
20306
+ const renderBodyWrapper = shouldRenderBodyWrapper({
20307
+ header,
20308
+ footer,
20309
+ bodyAs: BodyComponent === "div" ? void 0 : BodyComponent,
20310
+ bodyClassName,
20311
+ bodyProps,
20312
+ classNames
20313
+ });
20314
+ const { className: bodyPropsClassName, ...restBodyProps } = bodyProps ?? {};
20315
+ return /* @__PURE__ */ jsxRuntime.jsxs(
20316
+ Component,
20317
+ {
20318
+ ref,
20319
+ "data-workbench-content-pane": true,
20320
+ className: cn(
20321
+ "workbench-surface-subtle flex h-full min-w-0 flex-1 flex-col overflow-hidden rounded-xl border border-border/50 transition-all duration-300 dark:border-border/40",
20322
+ classNames?.root,
20323
+ className
20324
+ ),
20325
+ style,
20326
+ ...props,
20327
+ children: [
20328
+ header ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("shrink-0 border-b border-border/40 px-4 py-3 dark:border-border/30", classNames?.header, headerClassName), children: header }) : null,
20329
+ renderBodyWrapper ? /* @__PURE__ */ jsxRuntime.jsx(
20330
+ BodyComponent,
20331
+ {
20332
+ className: cn("min-h-0 flex-1 overflow-hidden", classNames?.body, bodyClassName, bodyPropsClassName),
20333
+ ...restBodyProps,
20334
+ children
20335
+ }
20336
+ ) : children,
20337
+ footer ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("shrink-0 border-t border-border/40 px-4 py-3 dark:border-border/30", classNames?.footer, footerClassName), children: footer }) : null
20338
+ ]
20339
+ }
20340
+ );
20341
+ }
20342
+ );
20343
+ var defaultLabels = {
20344
+ settingsButton: "Gallery settings",
20345
+ title: "Gallery settings",
20346
+ visibleColumns: "Visible fields",
20347
+ coverField: "Cover field",
20348
+ autoDetect: "Auto",
20349
+ cardDensity: "Card density",
20350
+ cardColumns: "Cards per row",
20351
+ detailColumns: "Detail columns",
20352
+ fieldVisibility: "Field visibility",
20353
+ fieldLimit: "Field limit",
20354
+ fieldLimitHint: "Uses current field order",
20355
+ layout: "Gallery layout",
20356
+ compact: "Compact",
20357
+ comfortable: "Standard",
20358
+ detailed: "Detailed",
20359
+ autoColumns: "Auto",
20360
+ columns: (count) => `${count}`,
20361
+ bentoColumns: (count) => `${count}`,
20362
+ topLimit: "First fields",
20363
+ allFields: "All fields",
20364
+ adaptiveGrid: "Grid",
20365
+ masonry: "Masonry"
20366
+ };
20367
+ function normalizeColumnKey(column) {
20368
+ return String(column?.key || "");
20369
+ }
20370
+ function getDefaultColumnLabel(column) {
20371
+ return column.label ?? column.key;
20372
+ }
20373
+ function getDefaultVisibleColumnKeys(columns) {
20374
+ return columns.filter((column) => normalizeColumnKey(column) && column.hidden !== true).map((column) => normalizeColumnKey(column));
20375
+ }
20376
+ function getResolvedVisibleColumnKeys({
20377
+ columns,
20378
+ visibleColumnKeys,
20379
+ allowEmptyVisibleColumns
20380
+ }) {
20381
+ const validKeys = new Set(columns.map(normalizeColumnKey).filter(Boolean));
20382
+ const controlledKeys = Array.isArray(visibleColumnKeys) ? visibleColumnKeys.filter((key) => validKeys.has(String(key))) : null;
20383
+ if (controlledKeys && (controlledKeys.length || allowEmptyVisibleColumns)) {
20384
+ return controlledKeys;
20385
+ }
20386
+ return getDefaultVisibleColumnKeys(columns);
20387
+ }
20388
+ function getDefaultDensityOptions(labels) {
20389
+ return [
20390
+ { value: "compact", label: labels.compact },
20391
+ { value: "comfortable", label: labels.comfortable },
20392
+ { value: "detailed", label: labels.detailed }
20393
+ ];
20394
+ }
20395
+ function getDefaultGridColumnOptions(labels) {
20396
+ return [
20397
+ { value: "auto", label: labels.autoColumns },
20398
+ { value: 1, label: labels.columns(1) },
20399
+ { value: 2, label: labels.columns(2) },
20400
+ { value: 3, label: labels.columns(3) },
20401
+ { value: 4, label: labels.columns(4) }
20402
+ ];
20403
+ }
20404
+ function getDefaultBentoColumnOptions(labels) {
20405
+ return [
20406
+ { value: 1, label: labels.bentoColumns(1) },
20407
+ { value: 2, label: labels.bentoColumns(2) },
20408
+ { value: 3, label: labels.bentoColumns(3) }
20409
+ ];
20410
+ }
20411
+ function getDefaultDetailVisibilityOptions(labels) {
20412
+ return [
20413
+ { value: "limit", label: labels.topLimit },
20414
+ { value: "all", label: labels.allFields }
20415
+ ];
20416
+ }
20417
+ function getDefaultLayoutOptions(labels) {
20418
+ return [
20419
+ { value: "fixed", label: labels.adaptiveGrid },
20420
+ { value: "masonry", label: labels.masonry }
20421
+ ];
20422
+ }
20423
+ function normalizeOptionValue(value) {
20424
+ return String(value);
20425
+ }
20426
+ function getOptionValue(options, rawValue, fallbackValue) {
20427
+ const valueText = String(rawValue ?? fallbackValue);
20428
+ return options.some((option) => String(option.value) === valueText) ? valueText : String(fallbackValue);
20429
+ }
20430
+ function parseNumberOption(value) {
20431
+ const parsed = Number.parseInt(value, 10);
20432
+ return Number.isFinite(parsed) ? parsed : 1;
20433
+ }
20434
+ var compactSegmentedClassNames = {
20435
+ root: "flex w-full flex-wrap",
20436
+ item: "min-w-[58px] flex-1 px-2 text-[11px]",
20437
+ label: "text-[11px]"
20438
+ };
20439
+ function WorkbenchGallerySettingsPanel({
20440
+ columns = [],
20441
+ galleryFieldOptions,
20442
+ value,
20443
+ onValueChange,
20444
+ labels,
20445
+ densityOptions,
20446
+ gridColumnOptions,
20447
+ bentoColumnOptions,
20448
+ detailVisibilityOptions,
20449
+ layoutOptions,
20450
+ getColumnLabel = getDefaultColumnLabel,
20451
+ getColumnDescription,
20452
+ showColumnVisibility = true,
20453
+ showGalleryControls = true,
20454
+ showLayoutControl = true,
20455
+ showGridColumns = true,
20456
+ showDetailColumns = true,
20457
+ allowEmptyVisibleColumns = false,
20458
+ className,
20459
+ classNames
20460
+ }) {
20461
+ const resolvedLabels = { ...defaultLabels, ...labels };
20462
+ const resolvedValue = value || {};
20463
+ const resolvedColumns = columns.filter((column) => normalizeColumnKey(column));
20464
+ const resolvedVisibleColumnKeys = getResolvedVisibleColumnKeys({
20465
+ columns: resolvedColumns,
20466
+ visibleColumnKeys: resolvedValue.visibleColumnKeys,
20467
+ allowEmptyVisibleColumns
20468
+ });
20469
+ const visibleColumnKeySet = new Set(resolvedVisibleColumnKeys);
20470
+ const resolvedGalleryFieldOptions = (galleryFieldOptions || resolvedColumns).filter((column) => normalizeColumnKey(column));
20471
+ const resolvedDensityOptions = densityOptions || getDefaultDensityOptions(resolvedLabels);
20472
+ const resolvedGridColumnOptions = gridColumnOptions || getDefaultGridColumnOptions(resolvedLabels);
20473
+ const resolvedBentoColumnOptions = bentoColumnOptions || getDefaultBentoColumnOptions(resolvedLabels);
20474
+ const resolvedDetailVisibilityOptions = detailVisibilityOptions || getDefaultDetailVisibilityOptions(resolvedLabels);
20475
+ const resolvedLayoutOptions = layoutOptions || getDefaultLayoutOptions(resolvedLabels);
20476
+ const canUpdate = typeof onValueChange === "function";
20477
+ const updateValue = (patch) => {
20478
+ onValueChange?.({ ...resolvedValue, ...patch }, patch);
20479
+ };
20480
+ const toggleColumn = (columnKey) => {
20481
+ if (!canUpdate) return;
20482
+ const nextVisibleSet = new Set(resolvedVisibleColumnKeys);
20483
+ if (nextVisibleSet.has(columnKey)) {
20484
+ nextVisibleSet.delete(columnKey);
20485
+ } else {
20486
+ nextVisibleSet.add(columnKey);
20487
+ }
20488
+ let nextVisibleColumnKeys = resolvedColumns.map(normalizeColumnKey).filter((key) => nextVisibleSet.has(key));
20489
+ if (!nextVisibleColumnKeys.length && !allowEmptyVisibleColumns) {
20490
+ nextVisibleColumnKeys = [columnKey];
20491
+ }
20492
+ updateValue({ visibleColumnKeys: nextVisibleColumnKeys });
20493
+ };
20494
+ const shouldRenderColumnVisibility = showColumnVisibility && resolvedColumns.length > 0;
20495
+ const shouldRenderGalleryControls = showGalleryControls;
20496
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("space-y-3 text-foreground", classNames?.root, className), children: [
20497
+ shouldRenderColumnVisibility ? /* @__PURE__ */ jsxRuntime.jsxs("section", { className: cn("space-y-2", classNames?.section), children: [
20498
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("text-[10px] font-medium uppercase tracking-wide text-muted-foreground", classNames?.sectionHeader), children: resolvedLabels.visibleColumns }),
20499
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("max-h-[220px] space-y-1 overflow-y-auto pr-1", classNames?.columnList), children: resolvedColumns.map((column) => {
20500
+ const columnKey = normalizeColumnKey(column);
20501
+ return /* @__PURE__ */ jsxRuntime.jsx(
20502
+ BaseCheckbox,
20503
+ {
20504
+ checked: visibleColumnKeySet.has(columnKey),
20505
+ disabled: !canUpdate,
20506
+ label: getColumnLabel(column),
20507
+ description: getColumnDescription?.(column),
20508
+ onChange: () => toggleColumn(columnKey),
20509
+ className: cn("flex w-full rounded-lg px-2 py-1.5 hover:bg-muted/50", classNames?.columnItem)
20510
+ },
20511
+ `workbench-gallery-column-${columnKey}`
20512
+ );
20513
+ }) })
20514
+ ] }) : null,
20515
+ shouldRenderGalleryControls ? /* @__PURE__ */ jsxRuntime.jsxs("section", { className: cn("space-y-3 border-t border-border/60 pt-3", classNames?.section), children: [
20516
+ /* @__PURE__ */ jsxRuntime.jsx(
20517
+ BaseField,
20518
+ {
20519
+ label: resolvedLabels.coverField,
20520
+ classNames: {
20521
+ label: "text-[10px] uppercase tracking-wide text-muted-foreground"
20522
+ },
20523
+ children: /* @__PURE__ */ jsxRuntime.jsx(
20524
+ BaseSelect,
20525
+ {
20526
+ value: String(resolvedValue.galleryFieldKey || "auto"),
20527
+ options: [
20528
+ { value: "auto", label: resolvedLabels.autoDetect },
20529
+ ...resolvedGalleryFieldOptions.map((column) => ({
20530
+ value: normalizeColumnKey(column),
20531
+ label: getColumnLabel(column)
20532
+ }))
20533
+ ],
20534
+ disabled: !canUpdate,
20535
+ onChange: (event) => updateValue({ galleryFieldKey: event.currentTarget.value || "auto" }),
20536
+ className: classNames?.control
20537
+ }
20538
+ )
20539
+ }
20540
+ ),
20541
+ /* @__PURE__ */ jsxRuntime.jsx(
20542
+ BaseField,
20543
+ {
20544
+ label: resolvedLabels.cardDensity,
20545
+ classNames: {
20546
+ label: "text-[10px] uppercase tracking-wide text-muted-foreground"
20547
+ },
20548
+ children: /* @__PURE__ */ jsxRuntime.jsx(
20549
+ BaseSegmentedControl,
20550
+ {
20551
+ value: getOptionValue(resolvedDensityOptions, resolvedValue.galleryDensity, "comfortable"),
20552
+ options: resolvedDensityOptions.map((option) => ({
20553
+ value: normalizeOptionValue(option.value),
20554
+ label: option.label,
20555
+ disabled: option.disabled
20556
+ })),
20557
+ onValueChange: (nextValue) => updateValue({ galleryDensity: nextValue }),
20558
+ className: cn("w-full", classNames?.control),
20559
+ classNames: compactSegmentedClassNames
20560
+ }
20561
+ )
20562
+ }
20563
+ ),
20564
+ showGridColumns ? /* @__PURE__ */ jsxRuntime.jsx(
20565
+ BaseField,
20566
+ {
20567
+ label: resolvedLabels.cardColumns,
20568
+ classNames: {
20569
+ label: "text-[10px] uppercase tracking-wide text-muted-foreground"
20570
+ },
20571
+ children: /* @__PURE__ */ jsxRuntime.jsx(
20572
+ BaseSegmentedControl,
20573
+ {
20574
+ value: getOptionValue(resolvedGridColumnOptions, resolvedValue.galleryGridColumns, "auto"),
20575
+ options: resolvedGridColumnOptions.map((option) => ({
20576
+ value: normalizeOptionValue(option.value),
20577
+ label: option.label,
20578
+ disabled: option.disabled
20579
+ })),
20580
+ onValueChange: (nextValue) => updateValue({
20581
+ galleryGridColumns: nextValue === "auto" ? "auto" : parseNumberOption(nextValue)
20582
+ }),
20583
+ className: cn("w-full", classNames?.control),
20584
+ classNames: compactSegmentedClassNames
20585
+ }
20586
+ )
20587
+ }
20588
+ ) : null,
20589
+ showDetailColumns ? /* @__PURE__ */ jsxRuntime.jsx(
20590
+ BaseField,
20591
+ {
20592
+ label: resolvedLabels.detailColumns,
20593
+ classNames: {
20594
+ label: "text-[10px] uppercase tracking-wide text-muted-foreground"
20595
+ },
20596
+ children: /* @__PURE__ */ jsxRuntime.jsx(
20597
+ BaseSegmentedControl,
20598
+ {
20599
+ value: getOptionValue(resolvedBentoColumnOptions, resolvedValue.galleryBentoColumns, 2),
20600
+ options: resolvedBentoColumnOptions.map((option) => ({
20601
+ value: normalizeOptionValue(option.value),
20602
+ label: option.label,
20603
+ disabled: option.disabled
20604
+ })),
20605
+ onValueChange: (nextValue) => updateValue({ galleryBentoColumns: parseNumberOption(nextValue) }),
20606
+ className: cn("w-full", classNames?.control),
20607
+ classNames: compactSegmentedClassNames
20608
+ }
20609
+ )
20610
+ }
20611
+ ) : null,
20612
+ /* @__PURE__ */ jsxRuntime.jsx(
20613
+ BaseField,
20614
+ {
20615
+ label: resolvedLabels.fieldVisibility,
20616
+ classNames: {
20617
+ label: "text-[10px] uppercase tracking-wide text-muted-foreground"
20618
+ },
20619
+ children: /* @__PURE__ */ jsxRuntime.jsx(
20620
+ BaseSegmentedControl,
20621
+ {
20622
+ value: getOptionValue(resolvedDetailVisibilityOptions, resolvedValue.galleryDetailVisibility, "limit"),
20623
+ options: resolvedDetailVisibilityOptions.map((option) => ({
20624
+ value: normalizeOptionValue(option.value),
20625
+ label: option.label,
20626
+ disabled: option.disabled
20627
+ })),
20628
+ onValueChange: (nextValue) => updateValue({ galleryDetailVisibility: nextValue }),
20629
+ className: cn("w-full", classNames?.control),
20630
+ classNames: compactSegmentedClassNames
20631
+ }
20632
+ )
20633
+ }
20634
+ ),
20635
+ resolvedValue.galleryDetailVisibility !== "all" ? /* @__PURE__ */ jsxRuntime.jsx(
20636
+ BaseField,
20637
+ {
20638
+ label: resolvedLabels.fieldLimit,
20639
+ description: resolvedLabels.fieldLimitHint,
20640
+ classNames: {
20641
+ label: "text-[10px] uppercase tracking-wide text-muted-foreground",
20642
+ description: "text-[10px]"
20643
+ },
20644
+ children: /* @__PURE__ */ jsxRuntime.jsx(
20645
+ BaseInput,
20646
+ {
20647
+ type: "number",
20648
+ min: 1,
20649
+ step: 1,
20650
+ value: String(resolvedValue.galleryDetailLimit || 4),
20651
+ disabled: !canUpdate,
20652
+ onChange: (event) => updateValue({ galleryDetailLimit: event.currentTarget.value }),
20653
+ className: classNames?.control
20654
+ }
20655
+ )
20656
+ }
20657
+ ) : null,
20658
+ showLayoutControl ? /* @__PURE__ */ jsxRuntime.jsx(
20659
+ BaseField,
20660
+ {
20661
+ label: resolvedLabels.layout,
20662
+ classNames: {
20663
+ label: "text-[10px] uppercase tracking-wide text-muted-foreground"
20664
+ },
20665
+ children: /* @__PURE__ */ jsxRuntime.jsx(
20666
+ BaseSegmentedControl,
20667
+ {
20668
+ value: getOptionValue(resolvedLayoutOptions, resolvedValue.galleryLayout, "fixed"),
20669
+ options: resolvedLayoutOptions.map((option) => ({
20670
+ value: normalizeOptionValue(option.value),
20671
+ label: option.label,
20672
+ disabled: option.disabled
20673
+ })),
20674
+ onValueChange: (nextValue) => updateValue({ galleryLayout: nextValue }),
20675
+ className: cn("w-full", classNames?.control),
20676
+ classNames: compactSegmentedClassNames
20677
+ }
20678
+ )
20679
+ }
20680
+ ) : null
20681
+ ] }) : null
20682
+ ] });
20683
+ }
20684
+ function WorkbenchGallerySettingsButton({
20685
+ open,
20686
+ defaultOpen = false,
20687
+ onOpenChange,
20688
+ triggerIcon,
20689
+ triggerLabel,
20690
+ triggerTitle,
20691
+ align = "end",
20692
+ popoverWidth = 320,
20693
+ panelHeader,
20694
+ panelBefore,
20695
+ panelAfter,
20696
+ panelClassName,
20697
+ buttonClassName,
20698
+ popoverClassName,
20699
+ buttonClassNames,
20700
+ labels,
20701
+ className,
20702
+ classNames,
20703
+ ...panelProps
20704
+ }) {
20705
+ const resolvedLabels = { ...defaultLabels, ...labels };
20706
+ const rootRef = React.useRef(null);
20707
+ const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);
20708
+ const [popoverStyle, setPopoverStyle] = React.useState({});
20709
+ const isControlled = open !== void 0;
20710
+ const isOpen = isControlled ? Boolean(open) : uncontrolledOpen;
20711
+ const setOpen = (nextOpen) => {
20712
+ if (!isControlled) {
20713
+ setUncontrolledOpen(nextOpen);
20714
+ }
20715
+ onOpenChange?.(nextOpen);
20716
+ };
20717
+ React.useLayoutEffect(() => {
20718
+ if (!isOpen) return void 0;
20719
+ const updatePopoverPosition = () => {
20720
+ const triggerRect = rootRef.current?.getBoundingClientRect();
20721
+ if (!triggerRect || typeof window === "undefined") return;
20722
+ const viewportPadding = 12;
20723
+ const availableWidth = Math.max(window.innerWidth - viewportPadding * 2, 0);
20724
+ const resolvedWidth = Math.min(popoverWidth, availableWidth || popoverWidth);
20725
+ const preferredLeft = align === "start" ? triggerRect.left : triggerRect.right - resolvedWidth;
20726
+ const left = Math.min(
20727
+ Math.max(preferredLeft, viewportPadding),
20728
+ Math.max(window.innerWidth - resolvedWidth - viewportPadding, viewportPadding)
20729
+ );
20730
+ const top = Math.min(
20731
+ triggerRect.bottom + 8,
20732
+ Math.max(window.innerHeight - 80, viewportPadding)
20733
+ );
20734
+ setPopoverStyle({
20735
+ left,
20736
+ top,
20737
+ width: resolvedWidth,
20738
+ maxHeight: `calc(100vh - ${Math.round(top + viewportPadding)}px)`
20739
+ });
20740
+ };
20741
+ const handlePointerDown = (event) => {
20742
+ if (!rootRef.current?.contains(event.target)) {
20743
+ setOpen(false);
20744
+ }
20745
+ };
20746
+ const handleKeyDown = (event) => {
20747
+ if (event.key === "Escape") setOpen(false);
20748
+ };
20749
+ updatePopoverPosition();
20750
+ window.addEventListener("resize", updatePopoverPosition);
20751
+ window.addEventListener("scroll", updatePopoverPosition, true);
20752
+ window.addEventListener("pointerdown", handlePointerDown);
20753
+ window.addEventListener("keydown", handleKeyDown);
20754
+ return () => {
20755
+ window.removeEventListener("resize", updatePopoverPosition);
20756
+ window.removeEventListener("scroll", updatePopoverPosition, true);
20757
+ window.removeEventListener("pointerdown", handlePointerDown);
20758
+ window.removeEventListener("keydown", handleKeyDown);
20759
+ };
20760
+ }, [align, isOpen, popoverWidth]);
20761
+ const resolvedTriggerLabel = triggerLabel ?? resolvedLabels.settingsButton;
20762
+ const resolvedPanelHeader = panelHeader ?? resolvedLabels.title;
20763
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: rootRef, className: cn("relative inline-flex", buttonClassNames?.root, className), children: [
20764
+ /* @__PURE__ */ jsxRuntime.jsx(
20765
+ BaseButton,
20766
+ {
20767
+ icon: triggerIcon,
20768
+ label: resolvedTriggerLabel,
20769
+ title: triggerTitle || (typeof resolvedTriggerLabel === "string" ? resolvedTriggerLabel : void 0),
20770
+ iconOnly: Boolean(triggerIcon),
20771
+ active: isOpen,
20772
+ tone: "muted",
20773
+ "aria-haspopup": "dialog",
20774
+ "aria-expanded": isOpen,
20775
+ className: cn(buttonClassNames?.trigger, buttonClassName),
20776
+ onClick: () => setOpen(!isOpen)
20777
+ }
20778
+ ),
20779
+ isOpen ? /* @__PURE__ */ jsxRuntime.jsxs(
20780
+ "div",
20781
+ {
20782
+ role: "dialog",
20783
+ "aria-label": typeof resolvedPanelHeader === "string" ? resolvedPanelHeader : void 0,
20784
+ className: cn(
20785
+ "fixed z-50 overflow-y-auto rounded-xl border border-border bg-card p-3 text-foreground shadow-lg",
20786
+ align === "start" ? "origin-top-left" : "origin-top-right",
20787
+ buttonClassNames?.popover,
20788
+ popoverClassName
20789
+ ),
20790
+ style: popoverStyle,
20791
+ children: [
20792
+ resolvedPanelHeader ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("mb-3 text-[11px] font-medium text-foreground", buttonClassNames?.header), children: resolvedPanelHeader }) : null,
20793
+ panelBefore,
20794
+ /* @__PURE__ */ jsxRuntime.jsx(
20795
+ WorkbenchGallerySettingsPanel,
20796
+ {
20797
+ ...panelProps,
20798
+ labels: resolvedLabels,
20799
+ className: cn(buttonClassNames?.panel, panelClassName),
20800
+ classNames
20801
+ }
20802
+ ),
20803
+ panelAfter
20804
+ ]
20805
+ }
20806
+ ) : null
20807
+ ] });
20808
+ }
20809
+ function TableViewIcon() {
20810
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", className: "h-3.5 w-3.5", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
20811
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "3", y: "4", width: "18", height: "16", rx: "2" }),
20812
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 10h18M9 4v16" })
20813
+ ] });
20814
+ }
20815
+ function GalleryViewIcon() {
20816
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", className: "h-3.5 w-3.5", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
20817
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "3", y: "3", width: "7", height: "7", rx: "1.5" }),
20818
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "14", y: "3", width: "7", height: "7", rx: "1.5" }),
20819
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "3", y: "14", width: "7", height: "7", rx: "1.5" }),
20820
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { x: "14", y: "14", width: "7", height: "7", rx: "1.5" })
20821
+ ] });
20822
+ }
20823
+ function SettingsIcon() {
20824
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", className: "h-3.5 w-3.5", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
20825
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M20 7h-9M7 7H4M14 17H4M20 17h-3" }),
20826
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "9", cy: "7", r: "2" }),
20827
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "16", cy: "17", r: "2" })
20828
+ ] });
20829
+ }
20830
+ function ChevronDownIcon3({ open }) {
20831
+ return /* @__PURE__ */ jsxRuntime.jsx(
20832
+ "svg",
20833
+ {
20834
+ "aria-hidden": "true",
20835
+ viewBox: "0 0 24 24",
20836
+ className: cn("h-3 w-3 opacity-55 transition-transform", open && "rotate-180"),
20837
+ fill: "none",
20838
+ stroke: "currentColor",
20839
+ strokeWidth: "2",
20840
+ children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m6 9 6 6 6-6" })
20841
+ }
20842
+ );
20843
+ }
20844
+ var defaultViewModeOptions = [
20845
+ { value: "list", label: "Table view", icon: /* @__PURE__ */ jsxRuntime.jsx(TableViewIcon, {}) },
20846
+ { value: "gallery", label: "Gallery view", icon: /* @__PURE__ */ jsxRuntime.jsx(GalleryViewIcon, {}) }
20847
+ ];
20848
+ function getViewModeOptionIcon(option) {
20849
+ if (option.icon !== void 0) return option.icon;
20850
+ if (option.value === "list" || option.value === "table") return /* @__PURE__ */ jsxRuntime.jsx(TableViewIcon, {});
20851
+ if (option.value === "gallery") return /* @__PURE__ */ jsxRuntime.jsx(GalleryViewIcon, {});
20852
+ return null;
20853
+ }
20854
+ function getSettingsTriggerLabel(settings) {
20855
+ return settings.triggerLabel ?? settings.labels?.settingsButton ?? "Settings";
20856
+ }
20857
+ function WorkbenchContentToolbarViewModeControl({
20858
+ value,
20859
+ options,
20860
+ onValueChange,
20861
+ classNames
20862
+ }) {
20863
+ const rootRef = React.useRef(null);
20864
+ const [open, setOpen] = React.useState(false);
20865
+ const activeOption = options.find((option) => option.value === value) || options.find((option) => !option.disabled) || options[0];
20866
+ const activeIcon = activeOption ? getViewModeOptionIcon(activeOption) : null;
20867
+ React.useEffect(() => {
20868
+ if (!open) return void 0;
20869
+ const handlePointerDown = (event) => {
20870
+ if (!rootRef.current?.contains(event.target)) {
20871
+ setOpen(false);
20872
+ }
20873
+ };
20874
+ const handleKeyDown = (event) => {
20875
+ if (event.key === "Escape") setOpen(false);
20876
+ };
20877
+ window.addEventListener("pointerdown", handlePointerDown);
20878
+ window.addEventListener("keydown", handleKeyDown);
20879
+ return () => {
20880
+ window.removeEventListener("pointerdown", handlePointerDown);
20881
+ window.removeEventListener("keydown", handleKeyDown);
20882
+ };
20883
+ }, [open]);
20884
+ if (!activeOption) return null;
20885
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: rootRef, className: cn("relative inline-flex", classNames?.viewModeRoot), children: [
20886
+ /* @__PURE__ */ jsxRuntime.jsxs(
20887
+ "button",
20888
+ {
20889
+ type: "button",
20890
+ "aria-haspopup": "listbox",
20891
+ "aria-expanded": open,
20892
+ className: cn(
20893
+ "inline-flex h-7 min-w-0 items-center justify-center gap-1.5 rounded-md border border-border/70 bg-card px-2 text-xs font-medium text-foreground shadow-none transition-colors hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/25",
20894
+ classNames?.viewModeTrigger
20895
+ ),
20896
+ onClick: () => setOpen((current) => !current),
20897
+ children: [
20898
+ activeIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center text-muted-foreground", children: activeIcon }) : null,
20899
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "min-w-0 truncate", children: activeOption.label }),
20900
+ /* @__PURE__ */ jsxRuntime.jsx(ChevronDownIcon3, { open })
20901
+ ]
20902
+ }
20903
+ ),
20904
+ open ? /* @__PURE__ */ jsxRuntime.jsx(
20905
+ "div",
20906
+ {
20907
+ role: "listbox",
20908
+ className: cn(
20909
+ "absolute left-0 top-full z-50 mt-2 min-w-[160px] overflow-hidden rounded-xl border border-border/60 bg-card/95 p-1.5 text-xs text-foreground shadow-lg backdrop-blur-xl",
20910
+ classNames?.viewModeMenu
20911
+ ),
20912
+ children: options.map((option) => {
20913
+ const selected = option.value === activeOption.value;
20914
+ const optionIcon = getViewModeOptionIcon(option);
20915
+ return /* @__PURE__ */ jsxRuntime.jsxs(
20916
+ "button",
20917
+ {
20918
+ type: "button",
20919
+ role: "option",
20920
+ "aria-selected": selected,
20921
+ disabled: option.disabled,
20922
+ className: cn(
20923
+ "flex min-h-8 w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/55 hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",
20924
+ selected && "bg-muted/60 text-foreground",
20925
+ classNames?.viewModeItem
20926
+ ),
20927
+ onClick: () => {
20928
+ if (option.disabled) return;
20929
+ onValueChange?.(option.value, option);
20930
+ setOpen(false);
20931
+ },
20932
+ children: [
20933
+ optionIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center", children: optionIcon }) : null,
20934
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "min-w-0 truncate", children: option.label })
20935
+ ]
20936
+ },
20937
+ option.value
20938
+ );
20939
+ })
20940
+ }
20941
+ ) : null
20942
+ ] });
20943
+ }
20944
+ var WorkbenchContentToolbar = React.forwardRef(
20945
+ function WorkbenchContentToolbar2({
20946
+ as: Component = "div",
20947
+ children,
20948
+ end,
20949
+ viewMode,
20950
+ viewModeOptions,
20951
+ onViewModeChange,
20952
+ gallerySettings,
20953
+ gallerySettingsPlacement = "start",
20954
+ className,
20955
+ startClassName,
20956
+ endClassName,
20957
+ classNames,
20958
+ ...props
20959
+ }, ref) {
20960
+ const resolvedViewModeOptions = viewModeOptions || (viewMode ? defaultViewModeOptions : []);
20961
+ const resolvedGallerySettings = gallerySettings && typeof gallerySettings === "object" ? gallerySettings : null;
20962
+ const shouldRenderViewMode = Boolean(resolvedViewModeOptions.length);
20963
+ const shouldRenderSettings = Boolean(resolvedGallerySettings);
20964
+ const shouldRenderSettingsInStart = shouldRenderSettings && gallerySettingsPlacement !== "end";
20965
+ const shouldRenderSettingsInEnd = shouldRenderSettings && gallerySettingsPlacement === "end";
20966
+ const shouldRenderStart = shouldRenderViewMode || shouldRenderSettingsInStart || Boolean(children);
20967
+ const shouldRenderEnd = Boolean(end) || shouldRenderSettingsInEnd;
20968
+ return /* @__PURE__ */ jsxRuntime.jsxs(
20969
+ Component,
20970
+ {
20971
+ ref,
20972
+ "data-workbench-content-toolbar": true,
20973
+ className: cn(
20974
+ "flex min-h-[46px] shrink-0 flex-col gap-2 border-b border-border/60 px-4 py-2 md:flex-row md:items-center md:justify-between",
20975
+ classNames?.root,
20976
+ className
20977
+ ),
20978
+ ...props,
20979
+ children: [
20980
+ shouldRenderStart ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-wrap items-center gap-2", classNames?.start, startClassName), children: [
20981
+ shouldRenderViewMode ? /* @__PURE__ */ jsxRuntime.jsx(
20982
+ WorkbenchContentToolbarViewModeControl,
20983
+ {
20984
+ value: viewMode,
20985
+ options: resolvedViewModeOptions,
20986
+ onValueChange: onViewModeChange,
20987
+ classNames
20988
+ }
20989
+ ) : null,
20990
+ shouldRenderSettingsInStart && resolvedGallerySettings ? /* @__PURE__ */ jsxRuntime.jsx(
20991
+ WorkbenchGallerySettingsButton,
20992
+ {
20993
+ align: "end",
20994
+ triggerIcon: /* @__PURE__ */ jsxRuntime.jsx(SettingsIcon, {}),
20995
+ triggerLabel: getSettingsTriggerLabel(resolvedGallerySettings),
20996
+ ...resolvedGallerySettings,
20997
+ buttonClassName: cn(
20998
+ "!h-7 !w-7 !min-h-0 !rounded-md !p-0 text-xs",
20999
+ classNames?.settings,
21000
+ resolvedGallerySettings.buttonClassName
21001
+ )
21002
+ }
21003
+ ) : null,
21004
+ children
21005
+ ] }) : null,
21006
+ shouldRenderEnd ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex shrink-0 items-center gap-2", classNames?.end, endClassName), children: [
21007
+ end,
21008
+ shouldRenderSettingsInEnd && resolvedGallerySettings ? /* @__PURE__ */ jsxRuntime.jsx(
21009
+ WorkbenchGallerySettingsButton,
21010
+ {
21011
+ align: "end",
21012
+ triggerIcon: /* @__PURE__ */ jsxRuntime.jsx(SettingsIcon, {}),
21013
+ triggerLabel: getSettingsTriggerLabel(resolvedGallerySettings),
21014
+ ...resolvedGallerySettings,
21015
+ buttonClassName: cn(
21016
+ "!h-7 !w-7 !min-h-0 !rounded-md !p-0 text-xs",
21017
+ classNames?.settings,
21018
+ resolvedGallerySettings.buttonClassName
21019
+ )
21020
+ }
21021
+ ) : null
21022
+ ] }) : null
21023
+ ]
21024
+ }
21025
+ );
21026
+ }
21027
+ );
21028
+ function shouldRenderBodyWrapper2(props) {
21029
+ return Boolean(
21030
+ props.header || props.footer || props.bodyAs || props.bodyClassName || props.bodyProps || props.classNames?.body
21031
+ );
21032
+ }
21033
+ function hasRenderableChildren(children) {
21034
+ if (children === null || children === void 0 || typeof children === "boolean") return false;
21035
+ if (typeof children === "string") return children.trim().length > 0;
21036
+ if (Array.isArray(children)) return children.some(hasRenderableChildren);
21037
+ const childList = React.Children.toArray(children);
21038
+ if (!childList.length) return false;
21039
+ return childList.some((child) => typeof child === "string" ? child.trim().length > 0 : true);
21040
+ }
21041
+ function resolveWidthStyle(open, width) {
21042
+ if (width === void 0) return {};
21043
+ if (open === void 0) return { width };
21044
+ return {
21045
+ width: open ? width : 0,
21046
+ opacity: open ? 1 : 0
21047
+ };
21048
+ }
21049
+ function getFallbackFieldLabel(field) {
21050
+ return field.label ?? field.key;
21051
+ }
21052
+ function getObjectDisplayValue(value) {
21053
+ const displayKeys = ["text", "label", "title", "display", "value", "recordId"];
21054
+ for (const key of displayKeys) {
21055
+ if (!Object.prototype.hasOwnProperty.call(value, key)) continue;
21056
+ const displayValue = value[key];
21057
+ if (displayValue !== null && displayValue !== void 0 && displayValue !== "") {
21058
+ return displayValue;
21059
+ }
21060
+ }
21061
+ return void 0;
21062
+ }
21063
+ function isEmptyDetailValue(value) {
21064
+ return value === null || value === void 0 || value === "";
21065
+ }
21066
+ function isPlainDisplayValue(value) {
21067
+ return ["string", "number", "boolean"].includes(typeof value);
21068
+ }
21069
+ function getMediaDisplayData(value) {
21070
+ if (!value) return null;
21071
+ if (typeof value === "string") {
21072
+ const isDataImage = value.startsWith("data:image/");
21073
+ const isImageUrl = /\.(avif|gif|jpe?g|png|svg|webp)(\?.*)?$/i.test(value);
21074
+ return isDataImage || isImageUrl ? { src: value } : null;
21075
+ }
21076
+ if (typeof value !== "object" || React.isValidElement(value)) return null;
21077
+ const media = value;
21078
+ const src = media.src || media.url || media.thumbnail || media.preview || media.image;
21079
+ return src ? {
21080
+ src: String(src),
21081
+ alt: media.alt || media.label || media.title || "",
21082
+ caption: media.caption || media.description || media.label || media.title
21083
+ } : null;
21084
+ }
21085
+ function shouldRenderAsMedia(field, value) {
21086
+ const renderType = String(field?.renderType || "").toLowerCase();
21087
+ return ["image", "media", "preview", "thumbnail"].includes(renderType) || Boolean(getMediaDisplayData(value));
21088
+ }
21089
+ function renderMaybeFieldIcon(icon, className) {
21090
+ if (!icon) {
21091
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: cn("relative inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center", className), children: [
21092
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "absolute inset-0 rounded-full border border-primary/25 bg-primary/10" }),
21093
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "h-1.5 w-1.5 rounded-full bg-primary" })
21094
+ ] });
21095
+ }
21096
+ if (typeof icon === "string" || typeof icon === "number") {
21097
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("inline-flex h-3.5 min-w-3.5 shrink-0 items-center justify-center rounded-sm text-[10px] font-semibold text-primary", className), children: icon });
21098
+ }
21099
+ if (typeof icon === "boolean") return null;
21100
+ if (React.isValidElement(icon)) return icon;
21101
+ const IconComponent = icon;
21102
+ return /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { className: cn("h-3.5 w-3.5 shrink-0 text-primary", className) });
21103
+ }
21104
+ function renderDetailFieldLabel(label, field, classNames) {
21105
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: cn("inline-flex min-w-0 items-center gap-1.5 text-[11px] font-semibold text-foreground", classNames?.fieldLabel), children: [
21106
+ renderMaybeFieldIcon(field.labelIcon || field.icon, classNames?.fieldLabelIcon),
21107
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "min-w-0 truncate", children: label })
21108
+ ] });
21109
+ }
21110
+ function WorkbenchDetailSidebarMediaValue({
21111
+ media,
21112
+ classNames
21113
+ }) {
21114
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("grid gap-2", classNames?.mediaValue), children: [
21115
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-md border border-border/55 bg-muted/20 dark:border-border/45 dark:bg-muted/10", children: /* @__PURE__ */ jsxRuntime.jsx(
21116
+ "img",
21117
+ {
21118
+ src: media.src,
21119
+ alt: String(media.alt || ""),
21120
+ className: cn("block aspect-[16/9] w-full object-cover", classNames?.mediaImage)
21121
+ }
21122
+ ) }),
21123
+ media.caption ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("truncate text-[11px] leading-4 text-muted-foreground", classNames?.mediaCaption), children: media.caption }) : null
21124
+ ] });
21125
+ }
21126
+ function getDefaultDetailDisplayValue(value, emptyValue, field, classNames) {
21127
+ if (isEmptyDetailValue(value)) return emptyValue;
21128
+ if (React.isValidElement(value)) return value;
21129
+ if (shouldRenderAsMedia(field, value)) {
21130
+ const media = getMediaDisplayData(value);
21131
+ if (media) return /* @__PURE__ */ jsxRuntime.jsx(WorkbenchDetailSidebarMediaValue, { media, classNames });
21132
+ }
21133
+ if (Array.isArray(value)) {
21134
+ const parts = value.map((item) => getDefaultDetailDisplayValue(item, "", void 0, classNames)).filter((item) => !isEmptyDetailValue(item));
21135
+ if (!parts.length) return emptyValue;
21136
+ if (parts.every(isPlainDisplayValue)) return parts.map(String).join(" \xB7 ");
21137
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "inline-flex flex-wrap items-center gap-1", children: parts.map((part, index) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex items-center gap-1", children: [
21138
+ index > 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "\xB7" }) : null,
21139
+ isPlainDisplayValue(part) ? String(part) : part
21140
+ ] }, index)) });
21141
+ }
21142
+ if (typeof value === "object") {
21143
+ const displayValue = getObjectDisplayValue(value);
21144
+ return displayValue === void 0 ? emptyValue : getDefaultDetailDisplayValue(displayValue, emptyValue, field, classNames);
21145
+ }
21146
+ return String(value);
21147
+ }
21148
+ function getDefaultFieldValue(field, record) {
21149
+ if (Object.prototype.hasOwnProperty.call(field, "value")) {
21150
+ return typeof field.value === "function" ? field.value(record, field) : field.value;
21151
+ }
21152
+ return record ? record?.[field.key] : void 0;
21153
+ }
21154
+ function shouldHideField(field, record) {
21155
+ return typeof field.hidden === "function" ? field.hidden(field, record) : Boolean(field.hidden);
21156
+ }
21157
+ function shouldHideSection(section, record) {
21158
+ return typeof section.hidden === "function" ? section.hidden(section, record) : Boolean(section.hidden);
21159
+ }
21160
+ function WorkbenchDetailSidebarAutoContent({
21161
+ record,
21162
+ fields,
21163
+ sections,
21164
+ fieldColumns = 1,
21165
+ emptyValue = "\u2014",
21166
+ emptyState,
21167
+ getFieldValue,
21168
+ renderFieldValue,
21169
+ formatFieldValue,
21170
+ formatFieldLabel,
21171
+ classNames
21172
+ }) {
21173
+ const resolvedSections = sections?.length ? sections : fields?.length ? [{ fields, columns: fieldColumns }] : [];
21174
+ const visibleSections = resolvedSections.filter((section) => !shouldHideSection(section, record));
21175
+ if (!visibleSections.length) {
21176
+ return emptyState ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("rounded-lg border border-dashed border-border/60 px-3 py-6 text-center text-xs text-muted-foreground", classNames?.emptyState), children: emptyState }) : null;
21177
+ }
21178
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("space-y-3", classNames?.autoBody), children: visibleSections.map((section, sectionIndex) => {
21179
+ const visibleFields = (section.fields || []).filter((field) => !shouldHideField(field, record));
21180
+ const sectionKey = section.id || `section-${sectionIndex}`;
21181
+ if (!visibleFields.length && !section.emptyState) return null;
21182
+ const items = visibleFields.map((field, fieldIndex) => {
21183
+ const context = {
21184
+ field,
21185
+ fieldIndex,
21186
+ section,
21187
+ sectionIndex,
21188
+ record
21189
+ };
21190
+ const rawValue = getFieldValue ? getFieldValue(field, record, context) : getDefaultFieldValue(field, record);
21191
+ const value = renderFieldValue ? renderFieldValue(field, record, context) : formatFieldValue ? formatFieldValue(rawValue, context) : getDefaultDetailDisplayValue(rawValue, field.emptyValue ?? emptyValue, field, classNames);
21192
+ const fieldLabel = formatFieldLabel ? formatFieldLabel(getFallbackFieldLabel(field), context) : getFallbackFieldLabel(field);
21193
+ return {
21194
+ term: renderDetailFieldLabel(fieldLabel, field, classNames),
21195
+ value
21196
+ };
21197
+ });
21198
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: cn("min-w-0 space-y-3", classNames?.section), children: [
21199
+ section.title || section.description ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("min-w-0 space-y-1.5", classNames?.sectionHeader), children: [
21200
+ section.title ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("inline-flex max-w-full items-center gap-2 rounded-md border border-primary/20 bg-primary/5 px-2.5 py-1.5 text-xs font-medium text-primary dark:border-primary/25 dark:bg-primary/10", classNames?.sectionTitle), children: section.title }) : null,
21201
+ section.description ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("text-[11px] leading-5 text-muted-foreground", classNames?.sectionDescription), children: section.description }) : null
21202
+ ] }) : null,
21203
+ items.length ? /* @__PURE__ */ jsxRuntime.jsx(
21204
+ BaseDescriptionList,
21205
+ {
21206
+ items,
21207
+ columns: section.columns || fieldColumns,
21208
+ className: cn("gap-3", classNames?.descriptionList),
21209
+ classNames: {
21210
+ item: cn("!border-0 !bg-transparent !p-0 !shadow-none !gap-1.5", classNames?.descriptionListItem),
21211
+ term: cn("!normal-case !tracking-normal !text-foreground", classNames?.descriptionListTerm),
21212
+ value: cn(
21213
+ "min-h-10 rounded-md border border-border/55 bg-muted/25 px-3 py-2 text-xs leading-5 text-foreground shadow-[inset_0_1px_0_hsl(var(--background)/0.8)] dark:border-border/45 dark:bg-white/[0.035]",
21214
+ classNames?.fieldValue,
21215
+ classNames?.descriptionListValue
21216
+ )
21217
+ }
21218
+ }
21219
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("py-3 text-center text-xs text-muted-foreground", classNames?.emptyState), children: section.emptyState })
21220
+ ] }, sectionKey);
21221
+ }) });
21222
+ }
21223
+ var WorkbenchDetailSidebar = React.forwardRef(
21224
+ function WorkbenchDetailSidebar2({
21225
+ as: Component = "aside",
21226
+ bodyAs: BodyComponent = "div",
21227
+ open,
21228
+ width,
21229
+ header,
21230
+ footer,
21231
+ resizeHandle,
21232
+ children,
21233
+ record,
21234
+ fields,
21235
+ sections,
21236
+ fieldColumns,
21237
+ emptyValue,
21238
+ emptyState,
21239
+ getFieldValue,
21240
+ renderFieldValue,
21241
+ formatFieldValue,
21242
+ formatFieldLabel,
21243
+ className,
21244
+ headerClassName,
21245
+ bodyClassName,
21246
+ footerClassName,
21247
+ resizeHandleClassName,
21248
+ bodyProps,
21249
+ classNames,
21250
+ style,
21251
+ ...props
21252
+ }, ref) {
21253
+ const autoContent = hasRenderableChildren(children) ? children : /* @__PURE__ */ jsxRuntime.jsx(
21254
+ WorkbenchDetailSidebarAutoContent,
21255
+ {
21256
+ record,
21257
+ fields,
21258
+ sections,
21259
+ fieldColumns,
21260
+ emptyValue,
21261
+ emptyState,
21262
+ getFieldValue,
21263
+ renderFieldValue,
21264
+ formatFieldValue,
21265
+ formatFieldLabel,
21266
+ classNames
21267
+ }
21268
+ );
21269
+ const renderBodyWrapper = shouldRenderBodyWrapper2({
21270
+ header,
21271
+ footer,
21272
+ bodyAs: BodyComponent === "div" ? void 0 : BodyComponent,
21273
+ bodyClassName,
21274
+ bodyProps,
21275
+ classNames
21276
+ });
21277
+ const { className: bodyPropsClassName, ...restBodyProps } = bodyProps ?? {};
21278
+ return /* @__PURE__ */ jsxRuntime.jsxs(
21279
+ Component,
21280
+ {
21281
+ ref,
21282
+ "data-workbench-detail-sidebar": true,
21283
+ "data-open": open === void 0 ? void 0 : open ? "true" : "false",
21284
+ className: cn(
21285
+ "workbench-surface-subtle relative flex flex-shrink-0 flex-col self-stretch overflow-hidden rounded-lg border border-border/50 transition-all duration-300 dark:border-border/40",
21286
+ open === false && "pointer-events-none",
21287
+ classNames?.root,
21288
+ className
21289
+ ),
21290
+ style: {
21291
+ ...resolveWidthStyle(open, width),
21292
+ ...style
21293
+ },
21294
+ ...props,
21295
+ children: [
21296
+ resizeHandle ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(classNames?.resizeHandle, resizeHandleClassName), children: resizeHandle }) : null,
21297
+ header ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("shrink-0 border-b border-border/40 px-4 py-3 dark:border-border/30", classNames?.header, headerClassName), children: header }) : null,
21298
+ renderBodyWrapper ? /* @__PURE__ */ jsxRuntime.jsx(
21299
+ BodyComponent,
21300
+ {
21301
+ className: cn("min-h-0 flex-1 overflow-y-auto", classNames?.body, bodyClassName, bodyPropsClassName),
21302
+ ...restBodyProps,
21303
+ children: autoContent
21304
+ }
21305
+ ) : autoContent,
21306
+ footer ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("shrink-0 border-t border-border/40 px-4 py-3 dark:border-border/30", classNames?.footer, footerClassName), children: footer }) : null
21307
+ ]
21308
+ }
21309
+ );
21310
+ }
21311
+ );
21312
+ function isWorkbenchIconComponent(icon) {
21313
+ if (typeof icon === "function") return true;
21314
+ return typeof icon === "object" && icon !== null && !React.isValidElement(icon) && "$$typeof" in icon;
21315
+ }
21316
+ function renderWorkbenchIcon(icon, className) {
21317
+ if (!icon) return null;
21318
+ if (React.isValidElement(icon)) return icon;
21319
+ if (isWorkbenchIconComponent(icon)) {
21320
+ const Icon = icon;
21321
+ return /* @__PURE__ */ jsxRuntime.jsx(Icon, { className });
21322
+ }
21323
+ return icon;
21324
+ }
21325
+ function getWorkbenchIconComponent(icon) {
21326
+ if (!icon || !isWorkbenchIconComponent(icon)) return null;
21327
+ return icon;
21328
+ }
21329
+ function toCssSize2(value) {
21330
+ if (value === void 0) return void 0;
21331
+ return typeof value === "number" ? `${value}px` : value;
21332
+ }
21333
+ function defaultFormatLabel(value) {
21334
+ if (value === void 0 || value === null || value === false) return null;
21335
+ return value;
21336
+ }
21337
+ function toTitle(value) {
21338
+ if (typeof value === "string" || typeof value === "number") return String(value);
21339
+ return void 0;
21340
+ }
21341
+ function defaultGetRowKey(row, rowIndex) {
21342
+ return row?.id ?? row?.key ?? row?.linkKey ?? rowIndex;
21343
+ }
21344
+ function defaultGetRowSelectionKey(row) {
21345
+ return row?.linkKey ?? row?.id ?? row?.key;
21346
+ }
21347
+ function getOrderedColumns(columns, columnOrder) {
21348
+ if (!columnOrder?.length) return columns;
21349
+ const columnMap = new Map(columns.map((column) => [column.key, column]));
21350
+ const orderedColumns = columnOrder.map((columnKey) => columnMap.get(columnKey)).filter(Boolean);
21351
+ const orderedKeySet = new Set(orderedColumns.map((column) => column.key));
21352
+ const remainingColumns = columns.filter((column) => !orderedKeySet.has(column.key));
21353
+ return [...orderedColumns, ...remainingColumns];
21354
+ }
21355
+ function normalizeColumnOrder(columnKeys, columnOrder) {
21356
+ const validColumnKeys = new Set(columnKeys);
21357
+ const orderedKeys = (columnOrder || []).filter((columnKey) => validColumnKeys.has(columnKey));
21358
+ const orderedKeySet = new Set(orderedKeys);
21359
+ const remainingKeys = columnKeys.filter((columnKey) => !orderedKeySet.has(columnKey));
21360
+ return [...orderedKeys, ...remainingKeys];
21361
+ }
21362
+ function WorkbenchTableHeaderHelper({
21363
+ helperText,
21364
+ className
21365
+ }) {
21366
+ if (!hasRenderableNode(helperText)) return null;
21367
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: cn("group relative inline-flex items-center", className), children: [
21368
+ /* @__PURE__ */ jsxRuntime.jsx(
21369
+ "button",
21370
+ {
21371
+ type: "button",
21372
+ title: toTitle(helperText),
21373
+ "aria-label": toTitle(helperText) || "Field help",
21374
+ className: "inline-flex h-4 w-4 items-center justify-center rounded-full border border-border/60 bg-background text-[10px] font-semibold normal-case tracking-normal text-muted-foreground shadow-sm transition-colors hover:border-primary/40 hover:text-primary focus-visible:border-primary/40 focus-visible:text-primary focus-visible:outline-none",
21375
+ onClick: (event) => event.stopPropagation(),
21376
+ children: "?"
21377
+ }
21378
+ ),
21379
+ /* @__PURE__ */ jsxRuntime.jsx(
21380
+ "span",
21381
+ {
21382
+ role: "tooltip",
21383
+ className: "pointer-events-none absolute left-1/2 top-full z-40 mt-2 hidden w-72 -translate-x-1/2 whitespace-pre-line rounded-lg border border-border/60 bg-card px-3 py-2 text-[11px] font-normal normal-case leading-5 tracking-normal text-foreground shadow-sm backdrop-blur-sm group-hover:block group-focus-within:block",
21384
+ children: helperText
21385
+ }
21386
+ )
21387
+ ] });
21388
+ }
21389
+ function WorkbenchTableView({
21390
+ rows = [],
21391
+ columns = [],
21392
+ onRowClick,
21393
+ selectedRowKey,
21394
+ selectedLinkKey,
21395
+ activePrimaryColumn,
21396
+ activeTablePrimaryColumn,
21397
+ renderedRowCount,
21398
+ totalRowCount,
21399
+ tableMinWidth,
21400
+ minWidth,
21401
+ bodyMaxHeight = "min(58vh, 38rem)",
21402
+ stickyFirstColumn = true,
21403
+ appearance,
21404
+ columnOrder,
21405
+ columnSizes,
21406
+ columnDragEnabled,
21407
+ columnResizeEnabled,
21408
+ className,
21409
+ tableClassName,
21410
+ rowClassName,
21411
+ classNames,
21412
+ style,
21413
+ renderCell,
21414
+ renderFieldValue,
21415
+ renderColumnHeader,
21416
+ onColumnOrderChange,
21417
+ onColumnSizeChange,
21418
+ onSort,
21419
+ formatLabel = defaultFormatLabel,
21420
+ getColumnDataType,
21421
+ getColumnIcon,
21422
+ getColumnTypeIcon,
21423
+ getRowKey = defaultGetRowKey,
21424
+ getRowSelectionKey = defaultGetRowSelectionKey,
21425
+ isActionColumn,
21426
+ isActionField,
21427
+ isRowDisabled,
21428
+ isWorkbenchPlaceholderRow,
21429
+ emptyState = "-",
21430
+ hiddenRowsMessage
21431
+ }) {
21432
+ const columnKeySignature = columns.map((column) => column.key).join("");
21433
+ const defaultColumnOrder = React.useMemo(() => columnKeySignature ? columnKeySignature.split("") : [], [columnKeySignature]);
21434
+ const [internalColumnOrder, setInternalColumnOrder] = React.useState(defaultColumnOrder);
21435
+ const [internalColumnSizes, setInternalColumnSizes] = React.useState({});
21436
+ React.useEffect(() => {
21437
+ setInternalColumnOrder((current) => normalizeColumnOrder(defaultColumnOrder, current));
21438
+ }, [defaultColumnOrder]);
21439
+ const resolvedColumnOrder = columnOrder ? normalizeColumnOrder(defaultColumnOrder, columnOrder) : internalColumnOrder;
21440
+ const resolvedColumnSizes = columnSizes ?? internalColumnSizes;
21441
+ const handleColumnOrderChange = React.useCallback((nextOrder, detail) => {
21442
+ const normalizedOrder = normalizeColumnOrder(defaultColumnOrder, nextOrder);
21443
+ if (!columnOrder) {
21444
+ setInternalColumnOrder(normalizedOrder);
21445
+ }
21446
+ onColumnOrderChange?.(normalizedOrder, detail);
21447
+ }, [columnOrder, defaultColumnOrder, onColumnOrderChange]);
21448
+ const handleColumnSizeChange = React.useCallback((columnId, width, detail) => {
21449
+ if (!columnSizes) {
21450
+ setInternalColumnSizes((current) => ({
21451
+ ...current,
21452
+ [columnId]: width
21453
+ }));
21454
+ }
21455
+ onColumnSizeChange?.(columnId, width, detail);
21456
+ }, [columnSizes, onColumnSizeChange]);
21457
+ const resolvedSelectedKey = selectedRowKey ?? selectedLinkKey;
21458
+ const resolvedActivePrimaryColumn = activePrimaryColumn ?? activeTablePrimaryColumn;
21459
+ const orderedColumns = getOrderedColumns(columns, resolvedColumnOrder);
21460
+ const hiddenRowCount = Math.max(0, Number(totalRowCount || rows.length) - Number(renderedRowCount || rows.length));
21461
+ const resolvedMinWidth = tableMinWidth ?? minWidth ?? Math.max(760, Math.min(orderedColumns.length * 112, 1440));
21462
+ const renderValue = renderCell ?? renderFieldValue ?? ((column, row) => row?.[column.key]);
21463
+ const isAction = isActionColumn ?? isActionField ?? (() => false);
21464
+ const isDisabled = isRowDisabled ?? isWorkbenchPlaceholderRow ?? (() => false);
21465
+ const resolveColumnIcon = getColumnIcon ?? getColumnTypeIcon;
21466
+ const footer = hiddenRowCount > 0 && hiddenRowsMessage ? typeof hiddenRowsMessage === "function" ? hiddenRowsMessage(hiddenRowCount, renderedRowCount || rows.length, totalRowCount || rows.length) : hiddenRowsMessage : null;
21467
+ return /* @__PURE__ */ jsxRuntime.jsxs(
21468
+ BaseTableContainer,
21469
+ {
21470
+ appearance,
21471
+ className: cn("w-full overflow-hidden rounded-lg border border-border/40 bg-muted/15 dark:border-border/35 dark:bg-muted/10", classNames?.root, className),
21472
+ style,
21473
+ children: [
21474
+ /* @__PURE__ */ jsxRuntime.jsx(
21475
+ "div",
21476
+ {
21477
+ className: cn("w-full overflow-auto", classNames?.scrollArea),
21478
+ style: { maxHeight: toCssSize2(bodyMaxHeight) },
21479
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
21480
+ BaseTable,
21481
+ {
21482
+ appearance,
21483
+ columnOrder: resolvedColumnOrder,
21484
+ columnSizes: resolvedColumnSizes,
21485
+ columnDragEnabled,
21486
+ columnResizeEnabled,
21487
+ onColumnOrderChange: handleColumnOrderChange,
21488
+ onColumnSizeChange: handleColumnSizeChange,
21489
+ className: cn("w-full table-auto text-left text-xs", classNames?.table, tableClassName),
21490
+ style: { minWidth: resolvedMinWidth },
21491
+ children: [
21492
+ /* @__PURE__ */ jsxRuntime.jsx(BaseTableHeader, { appearance, className: cn("text-[10px] font-mono uppercase tracking-wide text-muted-foreground", classNames?.header), children: /* @__PURE__ */ jsxRuntime.jsx(BaseTableRow, { className: cn("hover:bg-transparent", classNames?.headerRow), children: orderedColumns.map((column, columnIndex) => {
21493
+ const columnType = column.renderType || column.type || getColumnDataType?.(column.key, rows, column);
21494
+ const columnIcon = renderWorkbenchIcon(
21495
+ resolveColumnIcon?.(columnType, column),
21496
+ "h-3.5 w-3.5 shrink-0 text-primary"
21497
+ );
21498
+ const previousColumn = orderedColumns[columnIndex - 1];
21499
+ const followsRecordIcon = previousColumn?.renderType === "icon" && column.key === resolvedActivePrimaryColumn?.key;
21500
+ const headerContent = renderColumnHeader ? renderColumnHeader(column, { column, columnIndex, columns: orderedColumns, rows, columnType }) : formatLabel(column.label, { column });
21501
+ const headerTrailing = !renderColumnHeader && (hasRenderableNode(column.trailing) || hasRenderableNode(column.helperText)) ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex items-center gap-1.5", children: [
21502
+ hasRenderableNode(column.trailing) ? formatLabel(column.trailing, { column }) : null,
21503
+ /* @__PURE__ */ jsxRuntime.jsx(WorkbenchTableHeaderHelper, { helperText: formatLabel(column.helperText, { column }), className: classNames?.helper })
21504
+ ] }) : void 0;
21505
+ const sortable = Boolean(column.sortable);
21506
+ const handleSort = sortable && onSort ? () => onSort(column.key, column) : void 0;
21507
+ return /* @__PURE__ */ jsxRuntime.jsx(
21508
+ BaseTableHead,
21509
+ {
21510
+ appearance,
21511
+ columnId: column.key,
21512
+ align: column.align,
21513
+ icon: renderColumnHeader ? void 0 : columnIcon,
21514
+ label: headerContent,
21515
+ description: renderColumnHeader ? void 0 : formatLabel(column.description, { column }),
21516
+ meta: renderColumnHeader ? void 0 : formatLabel(column.meta, { column }),
21517
+ actions: renderColumnHeader ? void 0 : column.actions,
21518
+ trailing: headerTrailing,
21519
+ sortable,
21520
+ sortDirection: column.sortDirection,
21521
+ sortLabel: column.sortLabel,
21522
+ onSort: handleSort,
21523
+ draggable: column.draggable,
21524
+ dragLabel: column.dragLabel,
21525
+ resizable: column.resizable,
21526
+ resizeLabel: column.resizeLabel,
21527
+ width: column.width,
21528
+ minWidth: typeof column.minWidth === "number" ? column.minWidth : void 0,
21529
+ maxWidth: typeof column.maxWidth === "number" ? column.maxWidth : void 0,
21530
+ className: cn(
21531
+ "sticky top-0 z-20 h-auto whitespace-nowrap bg-card/95 px-4 py-3 font-medium backdrop-blur-sm supports-[backdrop-filter]:bg-card/90",
21532
+ stickyFirstColumn && columnIndex === 0 && "left-0 z-30 shadow-[1px_0_0_0_hsl(var(--border)/0.35)]",
21533
+ column.compactHeaderClassName,
21534
+ column.headerClassName,
21535
+ column.renderType === "icon" && "pl-3 pr-1",
21536
+ followsRecordIcon && "pl-2",
21537
+ classNames?.headerCell
21538
+ ),
21539
+ style: {
21540
+ minWidth: typeof column.minWidth === "string" ? column.minWidth : void 0,
21541
+ maxWidth: typeof column.maxWidth === "string" ? column.maxWidth : void 0
21542
+ }
21543
+ },
21544
+ column.key
21545
+ );
21546
+ }) }) }),
21547
+ /* @__PURE__ */ jsxRuntime.jsx(BaseTableBody, { appearance, className: cn("divide-y divide-border/35 dark:divide-border/30", classNames?.body), children: rows.length ? rows.map((row, rowIndex) => {
21548
+ const key = getRowKey(row, rowIndex);
21549
+ const disabled = isDisabled(row, rowIndex);
21550
+ const selectionKey = getRowSelectionKey(row, rowIndex);
21551
+ const selected = Boolean(resolvedSelectedKey && String(selectionKey) === String(resolvedSelectedKey));
21552
+ const resolvedRowClassName = typeof rowClassName === "function" ? rowClassName(row, rowIndex) : rowClassName;
21553
+ return /* @__PURE__ */ jsxRuntime.jsx(
21554
+ BaseTableRow,
21555
+ {
21556
+ appearance,
21557
+ interactive: Boolean(onRowClick) && !disabled,
21558
+ selected,
21559
+ disabled,
21560
+ onClick: () => {
21561
+ if (!disabled) {
21562
+ onRowClick?.(row, rowIndex);
21563
+ }
21564
+ },
21565
+ className: cn(
21566
+ onRowClick && !disabled ? "cursor-pointer" : "cursor-default",
21567
+ selected ? "bg-primary/10 hover:bg-primary/15" : disabled ? "" : "hover:bg-muted/25 dark:hover:bg-muted/15",
21568
+ classNames?.row,
21569
+ resolvedRowClassName
21570
+ ),
21571
+ children: orderedColumns.map((column, columnIndex) => {
21572
+ const shouldWrap = isAction(column) || column.wrap === true;
21573
+ const previousColumn = orderedColumns[columnIndex - 1];
21574
+ const followsRecordIcon = previousColumn?.renderType === "icon" && column.key === resolvedActivePrimaryColumn?.key;
21575
+ return /* @__PURE__ */ jsxRuntime.jsx(
21576
+ BaseTableCell,
21577
+ {
21578
+ appearance,
21579
+ align: column.align,
21580
+ className: cn(
21581
+ shouldWrap ? "align-top whitespace-normal" : "whitespace-nowrap",
21582
+ "px-4 py-3 text-muted-foreground",
21583
+ stickyFirstColumn && columnIndex === 0 && "sticky left-0 z-10 bg-card/95 text-foreground shadow-[1px_0_0_0_hsl(var(--border)/0.3)]",
21584
+ column.compactCellClassName,
21585
+ column.cellClassName,
21586
+ column.renderType === "icon" && "pl-3 pr-1",
21587
+ followsRecordIcon && "pl-2",
21588
+ classNames?.cell
21589
+ ),
21590
+ children: renderValue(column, row, {
21591
+ row,
21592
+ rowIndex,
21593
+ column,
21594
+ columnIndex,
21595
+ compact: true,
21596
+ surface: "list"
21597
+ })
21598
+ },
21599
+ `${key}-${column.key}`
21600
+ );
21601
+ })
21602
+ },
21603
+ key
21604
+ );
21605
+ }) : /* @__PURE__ */ jsxRuntime.jsx(
21606
+ BaseTableEmpty,
21607
+ {
21608
+ appearance,
21609
+ colSpan: Math.max(orderedColumns.length, 1),
21610
+ classNames: { cell: "px-4 py-10 text-center text-sm text-muted-foreground" },
21611
+ children: emptyState
21612
+ }
21613
+ ) })
21614
+ ]
21615
+ }
21616
+ )
21617
+ }
21618
+ ),
21619
+ footer ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("border-t border-border/40 px-4 py-2 text-[11px] text-muted-foreground dark:border-border/30", classNames?.footer), children: footer }) : null
21620
+ ]
21621
+ }
21622
+ );
21623
+ }
21624
+ var imageExtPattern = /\.(png|jpe?g|webp|gif|svg|bmp|avif)$/i;
21625
+ var audioExtPattern = /\.(wav|mp3|ogg|m4a|flac|aac)$/i;
21626
+ var isLikelyUrl = (value) => /^https?:\/\//i.test(String(value || ""));
21627
+ var getColumnRenderKind = (column) => String(column?.renderType || column?.type || "").toLowerCase();
21628
+ var isImageLikeValue = (value) => String(value || "").startsWith("data:image/") || imageExtPattern.test(String(value || ""));
21629
+ var isAudioLikeValue = (value) => String(value || "").startsWith("data:audio/") || audioExtPattern.test(String(value || ""));
21630
+ var escapeSvgText = (value) => String(value || "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
21631
+ var getDefaultGalleryFieldValue = (column, row) => {
21632
+ if (!column) return null;
21633
+ return row?.[column.key] ?? null;
21634
+ };
21635
+ var getDefaultGalleryDisplayText = (value) => {
21636
+ if (value === null || value === void 0 || value === "") return "\u2014";
21637
+ if (Array.isArray(value)) {
21638
+ const parts = value.map((item) => {
21639
+ if (typeof item === "string") return item;
21640
+ if (!item || typeof item !== "object") return "";
21641
+ const objectItem = item;
21642
+ return objectItem.text || objectItem.label || objectItem.title || objectItem.display || objectItem.value || objectItem.recordId || "";
21643
+ }).filter(Boolean);
21644
+ return parts.join(" \xB7 ") || "\u2014";
21645
+ }
21646
+ if (typeof value === "object") {
21647
+ const objectValue = value;
21648
+ return String(objectValue.text || objectValue.label || objectValue.title || objectValue.display || objectValue.value || "\u2014");
21649
+ }
21650
+ return String(value);
21651
+ };
21652
+ var isDefaultGalleryImageField = (column = { key: "" }, value) => getColumnRenderKind(column) === "image" || isImageLikeValue(value);
21653
+ var isDefaultGalleryAudioField = (column = { key: "" }, value) => getColumnRenderKind(column) === "audio" || isAudioLikeValue(value);
21654
+ var getDefaultGalleryImagePreviewSrc = (value, rowId, columnLabel) => {
21655
+ if (isLikelyUrl(value) || String(value || "").startsWith("data:image/")) return String(value);
21656
+ const title = escapeSvgText(value || columnLabel || rowId || "");
21657
+ const titleText = title ? `<text x='68' y='450' fill='white' font-family='Inter, Arial' font-size='52' font-weight='700'>${title}</text>` : "";
21658
+ const svg = `<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 960 540'><defs><linearGradient id='g' x1='0' y1='0' x2='1' y2='1'><stop offset='0%' stop-color='#0f172a'/><stop offset='55%' stop-color='#1d4ed8'/><stop offset='100%' stop-color='#14b8a6'/></linearGradient></defs><rect width='960' height='540' fill='url(#g)'/><g opacity='0.28'><circle cx='780' cy='130' r='150' fill='#67e8f9'/><circle cx='180' cy='430' r='170' fill='#a78bfa'/></g>${titleText}</svg>`;
21659
+ return `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`;
21660
+ };
21661
+ var isDefaultGalleryMediaColumn = (column, row, {
21662
+ getFieldValue = getDefaultGalleryFieldValue,
21663
+ shouldEnhanceMultimodal = true,
21664
+ isImageField = isDefaultGalleryImageField,
21665
+ isAudioField = isDefaultGalleryAudioField
21666
+ } = {}) => {
21667
+ if (!column || !shouldEnhanceMultimodal) return false;
21668
+ const value = getFieldValue(column, row);
21669
+ return isImageField(column, value) || isAudioField(column, value);
21670
+ };
21671
+ var isDefaultGalleryTitleCandidate = (column, row, { isMediaColumn = () => false } = {}) => {
21672
+ if (!column || column.renderType === "icon") return false;
21673
+ return !isMediaColumn(column, row);
21674
+ };
21675
+ var isDefaultGallerySummaryCandidate = (column, row, { isMediaColumn = () => false } = {}) => {
21676
+ if (!column || column.renderType === "icon") return false;
21677
+ return !isMediaColumn(column, row);
21678
+ };
21679
+ var renderDefaultGalleryFieldValue = (column, row, {
21680
+ compact = false,
21681
+ getFieldValue = getDefaultGalleryFieldValue,
21682
+ getDisplayText = getDefaultGalleryDisplayText
21683
+ } = {}) => {
21684
+ const value = getFieldValue(column, row);
21685
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("leading-relaxed", compact && column?.wrap === true && "line-clamp-2 block"), children: getDisplayText(value) });
21686
+ };
21687
+ var getDefaultGalleryDetailLimit = (density) => {
21688
+ if (density === "compact") return 2;
21689
+ if (density === "detailed") return 6;
21690
+ return 4;
21691
+ };
21692
+ var getNormalizedGalleryBentoColumns = (columns, density) => {
21693
+ if (columns === 1 || columns === 2 || columns === 3) return Number(columns);
21694
+ return density === "detailed" ? 1 : 2;
21695
+ };
21696
+ var getNormalizedGalleryDetailLimit = ({
21697
+ density,
21698
+ visibility,
21699
+ limit
21700
+ }) => {
21701
+ if (visibility === "all") return Number.POSITIVE_INFINITY;
21702
+ const parsedLimit = Number.parseInt(String(limit), 10);
21703
+ if (Number.isFinite(parsedLimit) && parsedLimit > 0) return parsedLimit;
21704
+ return getDefaultGalleryDetailLimit(density);
21705
+ };
21706
+ var getGalleryCardPaddingClassName = (density) => {
21707
+ if (density === "compact") return "p-3";
21708
+ if (density === "detailed") return "p-4";
21709
+ return "p-3.5";
21710
+ };
21711
+ var getGalleryPreviewClassName = (density, isMasonry) => {
21712
+ if (isMasonry) return "h-auto w-full object-cover";
21713
+ if (density === "compact") return "h-32 w-full object-cover";
21714
+ if (density === "detailed") return "h-48 w-full object-cover";
21715
+ return "h-40 w-full object-cover";
21716
+ };
21717
+ var getGalleryDetailGridClassName = (columns) => {
21718
+ if (columns === 1) return "grid-cols-1";
21719
+ if (columns === 3) return "grid-cols-1 sm:grid-cols-2 2xl:grid-cols-3";
21720
+ return "grid-cols-1 sm:grid-cols-2";
21721
+ };
21722
+ function getIconComponent(icon) {
21723
+ return getWorkbenchIconComponent(icon);
21724
+ }
21725
+ function defaultFormatLabel2(value) {
21726
+ return value;
21727
+ }
21728
+ function getLabelText(value) {
21729
+ if (typeof value === "string" || typeof value === "number") return String(value);
21730
+ return "";
21731
+ }
21732
+ function WorkbenchGalleryCard({
21733
+ row,
21734
+ columns,
21735
+ onClick = () => {
21736
+ },
21737
+ isSelected = false,
21738
+ isMasonry = false,
21739
+ galleryFieldKey = "auto",
21740
+ galleryDensity = "comfortable",
21741
+ galleryBentoColumns,
21742
+ galleryDetailVisibility = "limit",
21743
+ galleryDetailLimit,
21744
+ shouldEnhanceMultimodal = true,
21745
+ getFieldValue,
21746
+ isMediaColumn,
21747
+ isTitleCandidate,
21748
+ isSummaryCandidate,
21749
+ getDisplayText,
21750
+ renderFieldValue,
21751
+ getImagePreviewSrc,
21752
+ isImageField,
21753
+ isAudioField,
21754
+ AudioPlayerComponent,
21755
+ cardVariant = "default",
21756
+ renderPreview,
21757
+ renderMeta,
21758
+ renderLeadingVisual,
21759
+ resolveRecordVisual,
21760
+ hiddenDetailFieldKeys = [],
21761
+ labels,
21762
+ formatLabel = defaultFormatLabel2,
21763
+ className
21764
+ }) {
21765
+ const resolvedGetFieldValue = getFieldValue || getDefaultGalleryFieldValue;
21766
+ const resolvedGetDisplayText = getDisplayText || getDefaultGalleryDisplayText;
21767
+ const resolvedIsImageField = isImageField || isDefaultGalleryImageField;
21768
+ const resolvedIsAudioField = isAudioField || isDefaultGalleryAudioField;
21769
+ const resolvedGetImagePreviewSrc = getImagePreviewSrc || getDefaultGalleryImagePreviewSrc;
21770
+ const resolvedIsMediaColumn = isMediaColumn || ((column, candidateRow) => isDefaultGalleryMediaColumn(column, candidateRow, {
21771
+ getFieldValue: resolvedGetFieldValue,
21772
+ shouldEnhanceMultimodal,
21773
+ isImageField: resolvedIsImageField,
21774
+ isAudioField: resolvedIsAudioField
21775
+ }));
21776
+ const resolvedIsTitleCandidate = isTitleCandidate || ((column, candidateRow) => isDefaultGalleryTitleCandidate(column, candidateRow, { isMediaColumn: resolvedIsMediaColumn }));
21777
+ const resolvedIsSummaryCandidate = isSummaryCandidate || ((column, candidateRow) => isDefaultGallerySummaryCandidate(column, candidateRow, { isMediaColumn: resolvedIsMediaColumn }));
21778
+ const resolvedRenderFieldValue = renderFieldValue || ((column, candidateRow, { compact } = {}) => renderDefaultGalleryFieldValue(column, candidateRow, {
21779
+ compact,
21780
+ getFieldValue: resolvedGetFieldValue,
21781
+ getDisplayText: resolvedGetDisplayText
21782
+ }));
21783
+ const isPreviewOnly = cardVariant === "preview-only";
21784
+ const isImageOnly = cardVariant === "image-only";
21785
+ const isChromaticBento = cardVariant === "chromatic-bento";
21786
+ const selectedGalleryColumn = galleryFieldKey !== "auto" ? columns.find((column) => column.key === galleryFieldKey && resolvedIsMediaColumn(column, row)) : null;
21787
+ const mediaColumn = selectedGalleryColumn || (shouldEnhanceMultimodal ? columns.find((column) => resolvedIsMediaColumn(column, row)) : null);
21788
+ const iconColumn = columns.find((column) => column.renderType === "icon");
21789
+ const iconVisual = iconColumn && resolveRecordVisual ? resolveRecordVisual(row[iconColumn.key], row, iconColumn) : null;
21790
+ const IconComponent = getIconComponent(iconVisual?.Icon || iconVisual?.icon);
21791
+ const mediaValue = mediaColumn ? resolvedGetFieldValue(mediaColumn, row) : null;
21792
+ const isImageMedia = mediaColumn ? resolvedIsImageField(mediaColumn, mediaValue) : false;
21793
+ const isAudioMedia = mediaColumn ? resolvedIsAudioField(mediaColumn, mediaValue) : false;
21794
+ const contentColumns = columns.filter((column) => column.key !== mediaColumn?.key && column.renderType !== "icon");
21795
+ const titleCandidates = contentColumns.filter((column) => {
21796
+ if (!column || resolvedIsMediaColumn(column, row) || !resolvedIsTitleCandidate(column, row)) return false;
21797
+ const value = resolvedGetFieldValue(column, row);
21798
+ return !(value === null || value === void 0 || value === "");
21799
+ });
21800
+ const titleColumn = titleCandidates[0] || null;
21801
+ const titleText = titleColumn ? resolvedGetDisplayText(resolvedGetFieldValue(titleColumn, row)) : resolvedGetDisplayText(row.linkKey || row.id);
21802
+ const summaryColumn = contentColumns.find((column) => {
21803
+ if (!column || column.key === titleColumn?.key || resolvedIsMediaColumn(column, row) || !resolvedIsSummaryCandidate(column, row)) return false;
21804
+ const summaryText2 = String(resolvedGetDisplayText(resolvedGetFieldValue(column, row)));
21805
+ return summaryText2 !== "\u2014" && summaryText2.length > 12;
21806
+ }) || contentColumns.find((column) => {
21807
+ if (!column || column.key === titleColumn?.key || resolvedIsMediaColumn(column, row) || !resolvedIsSummaryCandidate(column, row)) return false;
21808
+ const fallbackText = String(resolvedGetDisplayText(resolvedGetFieldValue(column, row)));
21809
+ return fallbackText !== "\u2014";
21810
+ }) || null;
21811
+ const summaryText = summaryColumn ? resolvedGetDisplayText(resolvedGetFieldValue(summaryColumn, row)) : "";
21812
+ const hiddenDetailKeySet = new Set(hiddenDetailFieldKeys);
21813
+ const detailColumns = contentColumns.filter((column) => column.key !== titleColumn?.key && column.key !== summaryColumn?.key && !hiddenDetailKeySet.has(column.key));
21814
+ const resolvedDetailLimit = getNormalizedGalleryDetailLimit({
21815
+ density: galleryDensity,
21816
+ visibility: galleryDetailVisibility,
21817
+ limit: galleryDetailLimit
21818
+ });
21819
+ const visibleDetailColumns = Number.isFinite(resolvedDetailLimit) ? detailColumns.slice(0, resolvedDetailLimit) : detailColumns;
21820
+ const isDetailedCard = galleryDensity === "detailed";
21821
+ const resolvedBentoColumns = getNormalizedGalleryBentoColumns(galleryBentoColumns, galleryDensity);
21822
+ const cardPaddingClassName = getGalleryCardPaddingClassName(galleryDensity);
21823
+ const detailGridClassName = getGalleryDetailGridClassName(resolvedBentoColumns);
21824
+ const previewClassName = isImageOnly ? "block h-auto w-full transition-transform duration-500 group-hover:scale-[1.02]" : getGalleryPreviewClassName(galleryDensity, isMasonry);
21825
+ const customPreview = typeof renderPreview === "function" ? renderPreview({
21826
+ row,
21827
+ mediaColumn,
21828
+ mediaValue,
21829
+ isImageMedia,
21830
+ isAudioMedia,
21831
+ iconVisual,
21832
+ IconComponent,
21833
+ previewClassName
21834
+ }) : null;
21835
+ const metaContent = typeof renderMeta === "function" ? renderMeta({
21836
+ row,
21837
+ contentColumns,
21838
+ detailColumns,
21839
+ titleColumn,
21840
+ summaryColumn,
21841
+ getDisplayText: resolvedGetDisplayText,
21842
+ getFieldValue: resolvedGetFieldValue
21843
+ }) : null;
21844
+ const customLeadingVisual = typeof renderLeadingVisual === "function" ? renderLeadingVisual({
21845
+ row,
21846
+ contentColumns,
21847
+ detailColumns,
21848
+ titleColumn,
21849
+ summaryColumn,
21850
+ iconVisual,
21851
+ getDisplayText: resolvedGetDisplayText,
21852
+ getFieldValue: resolvedGetFieldValue
21853
+ }) : null;
21854
+ const defaultLeadingVisual = !customLeadingVisual && iconVisual ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex h-9 w-9 items-center justify-center rounded-lg border", iconVisual.chipClassName || "border-primary/20 bg-primary/10 text-primary"), children: renderWorkbenchIcon(iconVisual.Icon || iconVisual.icon, cn("h-4 w-4", iconVisual.iconClassName || "text-primary")) }) : null;
21855
+ const leadingVisual = customLeadingVisual || defaultLeadingVisual;
21856
+ const defaultMetaClassName = isChromaticBento ? "shrink-0 rounded-full border border-border/40 bg-muted/25 px-2.5 py-1 text-[10px] text-muted-foreground transition-all duration-300 group-hover:border-primary/30 group-hover:bg-primary/10 group-hover:text-primary dark:border-border/35 dark:bg-muted/15" : "shrink-0 rounded-md border border-border/40 bg-muted/25 px-2 py-1 text-[10px] text-muted-foreground dark:border-border/35 dark:bg-muted/15";
21857
+ const detailCellClassName = isChromaticBento ? "rounded-xl border border-border/35 bg-muted/20 px-3 py-2.5 transition-all duration-300 group-hover:border-primary/25 group-hover:bg-primary/5 dark:border-border/30 dark:bg-muted/10" : "rounded-lg border border-border/35 bg-muted/20 px-2.5 py-2 dark:border-border/30 dark:bg-muted/10";
21858
+ const detailLabelClassName = isChromaticBento ? "text-[10px] uppercase tracking-[0.14em] text-muted-foreground transition-colors duration-300 group-hover:text-foreground" : "text-[10px] uppercase tracking-[0.12em] text-muted-foreground";
21859
+ const detailValueClassName = isChromaticBento ? "mt-1.5 text-[11px] text-muted-foreground transition-colors duration-300 group-hover:text-foreground [&_*]:max-w-full [&_pre]:text-[11px] [&_pre]:leading-relaxed" : "mt-1.5 text-[11px] text-foreground [&_*]:max-w-full [&_pre]:text-[11px] [&_pre]:leading-relaxed";
21860
+ const fieldCountLabel = labels?.fieldCount?.(contentColumns.length);
21861
+ const coverOnlyHint = labels?.coverOnlyHint;
21862
+ return /* @__PURE__ */ jsxRuntime.jsxs(
21863
+ "button",
21864
+ {
21865
+ type: "button",
21866
+ onClick,
21867
+ "aria-label": getLabelText(titleText),
21868
+ className: cn(
21869
+ "group relative w-full text-left transition-all duration-300",
21870
+ isImageOnly ? "overflow-hidden rounded-xl bg-transparent p-0 shadow-none" : isPreviewOnly ? "overflow-hidden rounded-3xl bg-transparent p-0" : cn("overflow-hidden rounded-xl border", isChromaticBento && "rounded-3xl shadow-none"),
21871
+ !isPreviewOnly && !isImageOnly && cardPaddingClassName,
21872
+ !isPreviewOnly && !isImageOnly && (isSelected ? isChromaticBento ? "border-primary/35 bg-background/85 ring-1 ring-primary/20" : "border-primary/40 bg-primary/10 ring-1 ring-primary/30" : isChromaticBento ? "workbench-surface-card hover:-translate-y-1 hover:border-primary/20" : "workbench-surface-card hover:border-primary/30"),
21873
+ isPreviewOnly && isSelected && "ring-1 ring-primary/30",
21874
+ isImageOnly && (isSelected ? "ring-1 ring-primary/30" : "hover:-translate-y-0.5"),
21875
+ isMasonry ? "block h-full w-full min-w-0" : "h-full min-w-0",
21876
+ className
21877
+ ),
21878
+ children: [
21879
+ isChromaticBento ? /* @__PURE__ */ jsxRuntime.jsx(
21880
+ "div",
21881
+ {
21882
+ "aria-hidden": "true",
21883
+ className: cn(
21884
+ "pointer-events-none absolute inset-0 bg-[radial-gradient(circle_at_top_right,rgba(34,211,238,0.18),transparent_40%),radial-gradient(circle_at_bottom_left,rgba(16,185,129,0.12),transparent_45%)] opacity-0 transition-opacity duration-300",
21885
+ isSelected ? "opacity-100" : "group-hover:opacity-100"
21886
+ )
21887
+ }
21888
+ ) : null,
21889
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative z-[1]", children: [
21890
+ customPreview ?? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
21891
+ isImageMedia && mediaColumn ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(
21892
+ "overflow-hidden bg-card/50",
21893
+ isImageOnly ? "rounded-xl bg-transparent" : isPreviewOnly ? "rounded-3xl" : "mb-3 rounded-lg border border-border/70"
21894
+ ), children: /* @__PURE__ */ jsxRuntime.jsx(
21895
+ "img",
21896
+ {
21897
+ src: resolvedGetImagePreviewSrc(mediaValue, row.id, mediaColumn.label),
21898
+ alt: String(mediaValue || mediaColumn.label || ""),
21899
+ className: previewClassName,
21900
+ loading: "lazy",
21901
+ referrerPolicy: "no-referrer",
21902
+ onError: (event) => {
21903
+ event.currentTarget.onerror = null;
21904
+ event.currentTarget.src = resolvedGetImagePreviewSrc("", row.id, mediaColumn.label);
21905
+ }
21906
+ }
21907
+ ) }) : null,
21908
+ !isImageMedia && iconVisual && isPreviewOnly ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(
21909
+ "flex items-center justify-center",
21910
+ isPreviewOnly ? cn("rounded-3xl border py-10", iconVisual.chipClassName || "border-primary/20 bg-primary/5") : "mb-3 h-24 rounded-lg border border-border/60 bg-primary/5"
21911
+ ), children: renderWorkbenchIcon(iconVisual.Icon || iconVisual.icon, cn("h-10 w-10", iconVisual.iconClassName || "text-primary")) }) : null,
21912
+ isAudioMedia && AudioPlayerComponent ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(!isPreviewOnly && "mb-3"), children: /* @__PURE__ */ jsxRuntime.jsx(AudioPlayerComponent, { filename: String(mediaValue) }) }) : null
21913
+ ] }),
21914
+ !isPreviewOnly && !isImageOnly ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
21915
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start gap-3", children: [
21916
+ leadingVisual ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shrink-0", children: leadingVisual }) : null,
21917
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 flex-1 items-start justify-between gap-3", children: [
21918
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
21919
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(
21920
+ "flex items-center gap-2 text-sm font-semibold",
21921
+ isChromaticBento ? "text-muted-foreground transition-colors duration-300 group-hover:text-foreground" : "text-foreground"
21922
+ ), children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: titleText }) }),
21923
+ summaryText && summaryText !== titleText ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(
21924
+ "mt-1 text-[11px] leading-5 text-muted-foreground",
21925
+ isDetailedCard ? "line-clamp-4" : "line-clamp-2",
21926
+ isChromaticBento && "transition-colors duration-300 group-hover:text-foreground"
21927
+ ), children: summaryText }) : null
21928
+ ] }),
21929
+ metaContent ?? (hasRenderableNode(fieldCountLabel) ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: defaultMetaClassName, children: fieldCountLabel }) : null)
21930
+ ] })
21931
+ ] }),
21932
+ visibleDetailColumns.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("mt-3 grid grid-flow-row gap-2", detailGridClassName), children: visibleDetailColumns.map((column) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: detailCellClassName, children: [
21933
+ column.label ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: detailLabelClassName, children: formatLabel(column.label, { column }) }) : null,
21934
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(detailValueClassName, !column.label && "mt-0"), children: resolvedRenderFieldValue(column, row, { compact: galleryDensity !== "detailed", surface: "gallery" }) })
21935
+ ] }, `${row.id || row.linkKey}-${column.key}`)) }) : null,
21936
+ !summaryText && visibleDetailColumns.length === 0 && hasRenderableNode(coverOnlyHint) ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(
21937
+ "mt-3 text-[11px] text-muted-foreground",
21938
+ isChromaticBento && "transition-colors duration-300 group-hover:text-foreground"
21939
+ ), children: coverOnlyHint }) : null
21940
+ ] }) : null
21941
+ ] })
21942
+ ]
21943
+ }
21944
+ );
21945
+ }
21946
+ var DEFAULT_MASONRY_GAP_PX = 12;
21947
+ var DEFAULT_MASONRY_ROW_HEIGHT_PX = 8;
21948
+ var DEFAULT_MASONRY_COLUMN_WIDTH_PX = 280;
21949
+ var DEFAULT_MASONRY_ITEM_HEIGHT_PX = 240;
21950
+ function clamp3(value, min5, max5) {
21951
+ return Math.min(Math.max(value, min5), max5);
21952
+ }
21953
+ function getRootFontSize(node) {
21954
+ if (typeof window === "undefined") return 16;
21955
+ const target = node || document.documentElement;
21956
+ const parsed = Number.parseFloat(window.getComputedStyle(target).fontSize);
21957
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : 16;
21958
+ }
21959
+ function resolveLengthToPixels(value, fallback, node) {
21960
+ if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
21961
+ if (typeof value !== "string") return fallback;
21962
+ const normalized = value.trim().toLowerCase();
21963
+ if (!normalized) return fallback;
21964
+ if (/^\d+(\.\d+)?$/.test(normalized)) {
21965
+ const parsed = Number.parseFloat(normalized);
21966
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
21967
+ }
21968
+ if (normalized.endsWith("px")) {
21969
+ const parsed = Number.parseFloat(normalized);
21970
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
21971
+ }
21972
+ if (normalized.endsWith("rem")) {
21973
+ const parsed = Number.parseFloat(normalized);
21974
+ if (!Number.isFinite(parsed) || parsed <= 0) return fallback;
21975
+ return parsed * getRootFontSize(node);
21976
+ }
21977
+ return fallback;
21978
+ }
21979
+ function areMeasurementMapsEqual(prev, next) {
21980
+ const prevKeys = Object.keys(prev);
21981
+ const nextKeys = Object.keys(next);
21982
+ if (prevKeys.length !== nextKeys.length) return false;
21983
+ for (const key of nextKeys) {
21984
+ if (prev[key] !== next[key]) return false;
21985
+ }
21986
+ return true;
21987
+ }
21988
+ function getMasonryColumnCount({
21989
+ containerWidth,
21990
+ itemCount,
21991
+ targetColumnWidth,
21992
+ gap
21993
+ }) {
21994
+ if (!containerWidth) return 1;
21995
+ const safeItemCount = Math.max(itemCount, 1);
21996
+ const maxCandidate = Math.max(
21997
+ 1,
21998
+ Math.min(
21999
+ safeItemCount,
22000
+ Math.ceil((containerWidth + gap) / (Math.max(targetColumnWidth * 0.58, 1) + gap))
22001
+ )
22002
+ );
22003
+ let bestCount = 1;
22004
+ let bestScore = Number.POSITIVE_INFINITY;
22005
+ for (let candidateCount = 1; candidateCount <= maxCandidate; candidateCount += 1) {
22006
+ const actualColumnWidth = (containerWidth - gap * Math.max(candidateCount - 1, 0)) / candidateCount;
22007
+ if (!Number.isFinite(actualColumnWidth) || actualColumnWidth <= 0) continue;
22008
+ const underflowPenalty = Math.max(0, targetColumnWidth * 0.78 - actualColumnWidth);
22009
+ const overflowPenalty = Math.max(0, actualColumnWidth - targetColumnWidth * 1.35);
22010
+ const candidateScore = Math.abs(actualColumnWidth - targetColumnWidth) + underflowPenalty * 3 + overflowPenalty * 2;
22011
+ if (candidateScore < bestScore) {
22012
+ bestScore = candidateScore;
22013
+ bestCount = candidateCount;
22014
+ }
22015
+ }
22016
+ return bestCount;
22017
+ }
22018
+ function getItemColumnSpan({
22019
+ size,
22020
+ columnWidth,
22021
+ columnCount,
22022
+ gap
22023
+ }) {
22024
+ if (Number.isFinite(size?.columnSpan) && Number(size?.columnSpan) > 0) {
22025
+ return clamp3(Math.round(Number(size?.columnSpan)), 1, columnCount);
22026
+ }
22027
+ const itemWidth = resolveLengthToPixels(size?.width, columnWidth, null);
22028
+ return clamp3(Math.ceil((itemWidth + gap) / (columnWidth + gap)), 1, columnCount);
22029
+ }
22030
+ function getItemRowSpan({
22031
+ size,
22032
+ measuredHeight,
22033
+ rowHeight,
22034
+ gap
22035
+ }) {
22036
+ if (Number.isFinite(size?.rowSpan) && Number(size?.rowSpan) > 0) {
22037
+ return Math.max(1, Math.round(Number(size?.rowSpan)));
22038
+ }
22039
+ const itemHeight = Number.isFinite(measuredHeight) && Number(measuredHeight) > 0 ? Number(measuredHeight) : resolveLengthToPixels(size?.height, DEFAULT_MASONRY_ITEM_HEIGHT_PX, null);
22040
+ return Math.max(1, Math.ceil((itemHeight + gap) / (rowHeight + gap)));
22041
+ }
22042
+ function getResolvedItemHeight({
22043
+ size,
22044
+ measuredHeight
22045
+ }) {
22046
+ return Number.isFinite(measuredHeight) && Number(measuredHeight) > 0 ? Number(measuredHeight) : resolveLengthToPixels(size?.height, DEFAULT_MASONRY_ITEM_HEIGHT_PX, null);
22047
+ }
22048
+ function WorkbenchMasonryLayout({
22049
+ items = [],
22050
+ renderItem,
22051
+ getItemKey = (item, index) => item?.id ?? item?.key ?? index,
22052
+ getItemSize,
22053
+ columnWidth = DEFAULT_MASONRY_COLUMN_WIDTH_PX,
22054
+ gap = DEFAULT_MASONRY_GAP_PX,
22055
+ rowHeight = DEFAULT_MASONRY_ROW_HEIGHT_PX,
22056
+ placementStrategy = "shelf",
22057
+ className
22058
+ }) {
22059
+ const containerRef = React.useRef(null);
22060
+ const itemNodesRef = React.useRef(/* @__PURE__ */ new Map());
22061
+ const itemObserverRef = React.useRef(null);
22062
+ const [containerWidth, setContainerWidth] = React.useState(0);
22063
+ const [measuredHeights, setMeasuredHeights] = React.useState({});
22064
+ const itemKeys = React.useMemo(
22065
+ () => items.map((item, index) => String(getItemKey(item, index))),
22066
+ [getItemKey, items]
22067
+ );
22068
+ const itemKeysSignature = itemKeys.join("|");
22069
+ React.useEffect(() => {
22070
+ const node = containerRef.current;
22071
+ if (!node) return void 0;
22072
+ const updateWidth = () => {
22073
+ const nextWidth = Math.round(node.getBoundingClientRect().width);
22074
+ setContainerWidth((prevWidth) => prevWidth === nextWidth ? prevWidth : nextWidth);
22075
+ };
22076
+ updateWidth();
22077
+ if (typeof ResizeObserver === "function") {
22078
+ const observer = new ResizeObserver(() => updateWidth());
22079
+ observer.observe(node);
22080
+ return () => observer.disconnect();
22081
+ }
22082
+ window.addEventListener("resize", updateWidth);
22083
+ return () => window.removeEventListener("resize", updateWidth);
22084
+ }, []);
22085
+ React.useEffect(() => {
22086
+ setMeasuredHeights((prev) => {
22087
+ const next = Object.fromEntries(
22088
+ Object.entries(prev).filter(([key]) => itemKeys.includes(key))
22089
+ );
22090
+ return areMeasurementMapsEqual(prev, next) ? prev : next;
22091
+ });
22092
+ }, [itemKeys, itemKeysSignature]);
22093
+ const resolvedTargetColumnWidth = resolveLengthToPixels(
22094
+ columnWidth,
22095
+ DEFAULT_MASONRY_COLUMN_WIDTH_PX,
22096
+ containerRef.current
22097
+ );
22098
+ const isDensePlacement = placementStrategy === "dense";
22099
+ const columnCount = getMasonryColumnCount({
22100
+ containerWidth,
22101
+ itemCount: items.length,
22102
+ targetColumnWidth: resolvedTargetColumnWidth,
22103
+ gap
22104
+ });
22105
+ const resolvedColumnWidth = containerWidth > 0 ? (containerWidth - gap * Math.max(columnCount - 1, 0)) / columnCount : resolvedTargetColumnWidth;
22106
+ const layoutItems = React.useMemo(() => items.map((item, index) => {
22107
+ const key = itemKeys[index];
22108
+ const size = typeof getItemSize === "function" ? getItemSize(item, {
22109
+ columnCount,
22110
+ columnWidth: resolvedColumnWidth,
22111
+ containerWidth,
22112
+ gap,
22113
+ placementStrategy,
22114
+ rowHeight
22115
+ }) || {} : {};
22116
+ return {
22117
+ key,
22118
+ item,
22119
+ size,
22120
+ columnSpan: getItemColumnSpan({
22121
+ size,
22122
+ columnWidth: resolvedColumnWidth,
22123
+ columnCount,
22124
+ gap
22125
+ }),
22126
+ rowSpan: getItemRowSpan({
22127
+ size,
22128
+ measuredHeight: measuredHeights[key],
22129
+ rowHeight,
22130
+ gap
22131
+ })
22132
+ };
22133
+ }), [
22134
+ columnCount,
22135
+ containerWidth,
22136
+ gap,
22137
+ getItemSize,
22138
+ itemKeys,
22139
+ items,
22140
+ measuredHeights,
22141
+ placementStrategy,
22142
+ resolvedColumnWidth,
22143
+ rowHeight
22144
+ ]);
22145
+ React.useLayoutEffect(() => {
22146
+ const nextMeasurements = {};
22147
+ itemNodesRef.current.forEach((node, key) => {
22148
+ const nextHeight = Math.ceil(node.getBoundingClientRect().height);
22149
+ if (Number.isFinite(nextHeight) && nextHeight > 0) {
22150
+ nextMeasurements[key] = nextHeight;
22151
+ }
22152
+ });
22153
+ setMeasuredHeights((prev) => {
22154
+ if (!Object.keys(nextMeasurements).length) return prev;
22155
+ const merged = { ...prev, ...nextMeasurements };
22156
+ return areMeasurementMapsEqual(prev, merged) ? prev : merged;
22157
+ });
22158
+ }, [columnCount, isDensePlacement, itemKeysSignature, resolvedColumnWidth]);
22159
+ React.useEffect(() => {
22160
+ if (typeof ResizeObserver !== "function") return void 0;
22161
+ const observer = new ResizeObserver((entries) => {
22162
+ setMeasuredHeights((prev) => {
22163
+ const next = { ...prev };
22164
+ let didChange = false;
22165
+ for (const entry of entries) {
22166
+ const key = entry.target.dataset.masonryKey;
22167
+ if (!key) continue;
22168
+ const nextHeight = Math.ceil(entry.contentRect.height);
22169
+ if (!Number.isFinite(nextHeight) || nextHeight <= 0 || next[key] === nextHeight) continue;
22170
+ next[key] = nextHeight;
22171
+ didChange = true;
22172
+ }
22173
+ return didChange ? next : prev;
22174
+ });
22175
+ });
22176
+ itemObserverRef.current = observer;
22177
+ itemNodesRef.current.forEach((node) => observer.observe(node));
22178
+ return () => {
22179
+ observer.disconnect();
22180
+ itemObserverRef.current = null;
22181
+ };
22182
+ }, [isDensePlacement, itemKeysSignature]);
22183
+ const registerItemNode = (key, node) => {
22184
+ const currentNodes = itemNodesRef.current;
22185
+ const previousNode = currentNodes.get(key);
22186
+ if (previousNode && previousNode !== node && itemObserverRef.current) {
22187
+ itemObserverRef.current.unobserve(previousNode);
22188
+ }
22189
+ if (!node) {
22190
+ currentNodes.delete(key);
22191
+ return;
22192
+ }
22193
+ node.dataset.masonryKey = key;
22194
+ currentNodes.set(key, node);
22195
+ if (itemObserverRef.current) {
22196
+ itemObserverRef.current.observe(node);
22197
+ }
22198
+ };
22199
+ if (!isDensePlacement) {
22200
+ const orderedLayout = (() => {
22201
+ const columnBottoms = Array.from({ length: columnCount }, () => 0);
22202
+ let nextColumnIndex = 0;
22203
+ let maxBottom = 0;
22204
+ const positionedItems = layoutItems.map(({ key, item, columnSpan, rowSpan, size }) => {
22205
+ const resolvedSpan = clamp3(columnSpan, 1, columnCount);
22206
+ let startColumn = nextColumnIndex;
22207
+ if (startColumn + resolvedSpan > columnCount) {
22208
+ startColumn = 0;
22209
+ }
22210
+ startColumn = Math.min(startColumn, columnCount - resolvedSpan);
22211
+ const itemWidth = resolvedColumnWidth * resolvedSpan + gap * Math.max(resolvedSpan - 1, 0);
22212
+ const itemHeight = getResolvedItemHeight({
22213
+ size,
22214
+ measuredHeight: measuredHeights[key]
22215
+ });
22216
+ const top = Math.max(...columnBottoms.slice(startColumn, startColumn + resolvedSpan));
22217
+ const left = startColumn * (resolvedColumnWidth + gap);
22218
+ const bottom = top + itemHeight;
22219
+ for (let columnIndex = startColumn; columnIndex < startColumn + resolvedSpan; columnIndex += 1) {
22220
+ columnBottoms[columnIndex] = bottom + gap;
22221
+ }
22222
+ maxBottom = Math.max(maxBottom, bottom);
22223
+ nextColumnIndex = startColumn + resolvedSpan;
22224
+ if (nextColumnIndex >= columnCount) {
22225
+ nextColumnIndex = 0;
22226
+ }
22227
+ return {
22228
+ key,
22229
+ item,
22230
+ columnSpan: resolvedSpan,
22231
+ itemHeight,
22232
+ itemWidth,
22233
+ left,
22234
+ rowSpan,
22235
+ size,
22236
+ top
22237
+ };
22238
+ });
22239
+ return {
22240
+ containerHeight: Math.max(0, maxBottom),
22241
+ positionedItems
22242
+ };
22243
+ })();
22244
+ return /* @__PURE__ */ jsxRuntime.jsx(
22245
+ "div",
22246
+ {
22247
+ ref: containerRef,
22248
+ className: cn("relative w-full", className),
22249
+ style: { height: `${orderedLayout.containerHeight}px` },
22250
+ children: orderedLayout.positionedItems.map(({ key, item, columnSpan, rowSpan, size, itemWidth, left, top }) => {
22251
+ const unresolvedSingleColumnWidth = containerWidth <= 0 && columnCount === 1;
22252
+ const itemWidthValue = unresolvedSingleColumnWidth ? "100%" : `${itemWidth}px`;
22253
+ return /* @__PURE__ */ jsxRuntime.jsx(
22254
+ "div",
22255
+ {
22256
+ className: "absolute min-w-0",
22257
+ style: {
22258
+ left: unresolvedSingleColumnWidth ? 0 : `${left}px`,
22259
+ top: `${top}px`,
22260
+ width: itemWidthValue,
22261
+ maxWidth: itemWidthValue
22262
+ },
22263
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: (node) => registerItemNode(key, node), className: "min-w-0", children: renderItem(item, {
22264
+ columnCount,
22265
+ columnSpan,
22266
+ columnWidth: resolvedColumnWidth,
22267
+ containerWidth,
22268
+ gap,
22269
+ itemWidth,
22270
+ placementStrategy,
22271
+ rowSpan,
22272
+ rowHeight,
22273
+ size
22274
+ }) })
22275
+ },
22276
+ key
22277
+ );
22278
+ })
22279
+ }
22280
+ );
22281
+ }
22282
+ return /* @__PURE__ */ jsxRuntime.jsx(
22283
+ "div",
22284
+ {
22285
+ ref: containerRef,
22286
+ className: cn("grid w-full items-start", className),
22287
+ style: {
22288
+ gap: `${gap}px`,
22289
+ gridAutoFlow: "row dense",
22290
+ gridAutoRows: `${rowHeight}px`,
22291
+ gridTemplateColumns: `repeat(${columnCount}, minmax(0, 1fr))`
22292
+ },
22293
+ children: layoutItems.map(({ key, item, columnSpan, rowSpan, size }) => /* @__PURE__ */ jsxRuntime.jsx(
22294
+ "div",
22295
+ {
22296
+ className: "min-w-0",
22297
+ style: {
22298
+ gridColumn: `span ${columnSpan}`,
22299
+ gridRow: `span ${rowSpan}`
22300
+ },
22301
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: (node) => registerItemNode(key, node), className: "h-full", children: renderItem(item, {
22302
+ columnCount,
22303
+ columnSpan,
22304
+ columnWidth: resolvedColumnWidth,
22305
+ containerWidth,
22306
+ gap,
22307
+ placementStrategy,
22308
+ rowSpan,
22309
+ rowHeight,
22310
+ size
22311
+ }) })
22312
+ },
22313
+ key
22314
+ ))
22315
+ }
22316
+ );
22317
+ }
22318
+ var GALLERY_GRID_GAP_PX = 12;
22319
+ function getNormalizedGalleryGridCardWidth(cardWidth) {
22320
+ if (typeof cardWidth === "number" && Number.isFinite(cardWidth) && cardWidth > 0) {
22321
+ return `${cardWidth}px`;
22322
+ }
22323
+ if (typeof cardWidth === "string" && cardWidth.trim()) {
22324
+ return cardWidth.trim();
22325
+ }
22326
+ return void 0;
22327
+ }
22328
+ function getDefaultGalleryDetailLimit2(density) {
22329
+ if (density === "compact") return 2;
22330
+ if (density === "detailed") return 6;
22331
+ return 4;
22332
+ }
22333
+ function getNormalizedGalleryBentoColumns2(columns, density) {
22334
+ if (columns === 1 || columns === 2 || columns === 3) return Number(columns);
22335
+ return density === "detailed" ? 1 : 2;
22336
+ }
22337
+ function getNormalizedGalleryDetailLimit2({
22338
+ density,
22339
+ visibility,
22340
+ limit
22341
+ }) {
22342
+ if (visibility === "all") return Number.POSITIVE_INFINITY;
22343
+ const parsedLimit = Number.parseInt(String(limit), 10);
22344
+ if (Number.isFinite(parsedLimit) && parsedLimit > 0) return parsedLimit;
22345
+ return getDefaultGalleryDetailLimit2(density);
22346
+ }
22347
+ function getGalleryCardWidthMetrics(density) {
22348
+ if (density === "compact") return { min: 220, ideal: 244, max: 268 };
22349
+ if (density === "detailed") return { min: 320, ideal: 372, max: 420 };
22350
+ return { min: 260, ideal: 304, max: 348 };
22351
+ }
22352
+ function getGalleryCardWidthForColumnCount({
22353
+ containerWidth,
22354
+ columnCount,
22355
+ gap
22356
+ }) {
22357
+ if (!containerWidth || !columnCount) return 0;
22358
+ return (containerWidth - gap * Math.max(columnCount - 1, 0)) / columnCount;
22359
+ }
22360
+ function getNormalizedGalleryGridColumns(columns) {
22361
+ if (columns === void 0 || columns === null || columns === "" || columns === "auto") {
22362
+ return void 0;
22363
+ }
22364
+ const parsedColumns = Number.parseInt(String(columns), 10);
22365
+ if (!Number.isFinite(parsedColumns) || parsedColumns <= 0) return void 0;
22366
+ return Math.max(1, Math.min(parsedColumns, 8));
22367
+ }
22368
+ function getGalleryGridColumnCount({
22369
+ containerWidth,
22370
+ rowCount,
22371
+ minCardWidth,
22372
+ idealCardWidth,
22373
+ maxCardWidth,
22374
+ gap
22375
+ }) {
22376
+ if (!containerWidth) return 1;
22377
+ const safeRowCount = Math.max(rowCount, 1);
22378
+ const lowerBound = Math.max(1, Math.ceil((containerWidth + gap) / (maxCardWidth + gap)));
22379
+ const upperBound = Math.max(1, Math.floor((containerWidth + gap) / (minCardWidth + gap)));
22380
+ const idealCount = Math.max(1, Math.round((containerWidth + gap) / (idealCardWidth + gap)));
22381
+ const phantomPenalty = Math.round((idealCardWidth - minCardWidth) / 2) + gap;
22382
+ const maxCandidate = Math.max(1, lowerBound, upperBound + 1, idealCount + 1);
22383
+ let bestCount = 1;
22384
+ let bestScore = Number.POSITIVE_INFINITY;
22385
+ for (let candidateCount = 1; candidateCount <= maxCandidate; candidateCount += 1) {
22386
+ const cardWidth = getGalleryCardWidthForColumnCount({ containerWidth, columnCount: candidateCount, gap });
22387
+ const overflowPenalty = Math.max(0, cardWidth - maxCardWidth);
22388
+ const underflowPenalty = Math.max(0, minCardWidth - cardWidth);
22389
+ const idealPenalty = Math.abs(cardWidth - idealCardWidth);
22390
+ const phantomColumns = Math.max(0, candidateCount - safeRowCount);
22391
+ const candidateScore = overflowPenalty * 3 + underflowPenalty * 2 + idealPenalty + phantomColumns * phantomPenalty;
22392
+ if (candidateScore < bestScore) {
22393
+ bestScore = candidateScore;
22394
+ bestCount = candidateCount;
22395
+ }
22396
+ }
22397
+ return bestCount;
22398
+ }
22399
+ function getGalleryGridLayoutStyle({
22400
+ isRailLayout,
22401
+ railCardWidth,
22402
+ fixedCardWidth,
22403
+ fixedColumnCount,
22404
+ containerWidth,
22405
+ rowCount,
22406
+ minCardWidth,
22407
+ idealCardWidth,
22408
+ maxCardWidth
22409
+ }) {
22410
+ if (isRailLayout) {
22411
+ return { gridAutoColumns: `${railCardWidth}px` };
22412
+ }
22413
+ if (fixedColumnCount) {
22414
+ const responsiveColumnCount = containerWidth ? Math.max(1, Math.min(
22415
+ fixedColumnCount,
22416
+ Math.floor((containerWidth + GALLERY_GRID_GAP_PX) / (minCardWidth + GALLERY_GRID_GAP_PX)) || 1
22417
+ )) : fixedColumnCount;
22418
+ return {
22419
+ gridTemplateColumns: `repeat(${responsiveColumnCount}, minmax(0, 1fr))`,
22420
+ justifyContent: "start",
22421
+ alignContent: "start"
22422
+ };
22423
+ }
22424
+ if (fixedCardWidth) {
22425
+ return {
22426
+ gridTemplateColumns: `repeat(auto-fit, minmax(min(100%, ${fixedCardWidth}), ${fixedCardWidth}))`,
22427
+ justifyContent: "start",
22428
+ alignContent: "start"
22429
+ };
22430
+ }
22431
+ if (!containerWidth) {
22432
+ return {
22433
+ gridTemplateColumns: `repeat(auto-fit, minmax(min(100%, ${minCardWidth}px), min(100%, ${maxCardWidth}px)))`,
22434
+ justifyContent: "start",
22435
+ alignContent: "start"
22436
+ };
22437
+ }
22438
+ const columnCount = getGalleryGridColumnCount({
22439
+ containerWidth,
22440
+ rowCount,
22441
+ minCardWidth,
22442
+ idealCardWidth,
22443
+ maxCardWidth,
22444
+ gap: GALLERY_GRID_GAP_PX
22445
+ });
22446
+ return {
22447
+ gridTemplateColumns: `repeat(${columnCount}, minmax(0, 1fr))`,
22448
+ justifyContent: "start",
22449
+ alignContent: "start"
22450
+ };
22451
+ }
22452
+ function getGalleryTextLength(value) {
22453
+ if (value === null || value === void 0) return 0;
22454
+ const text = String(value).trim();
22455
+ return text && text !== "\u2014" ? text.length : 0;
22456
+ }
22457
+ function getGalleryFieldText({
22458
+ column,
22459
+ row,
22460
+ getFieldValue,
22461
+ getDisplayText
22462
+ }) {
22463
+ if (!column) return "";
22464
+ const rawValue = getFieldValue(column, row);
22465
+ if (rawValue === null || rawValue === void 0 || rawValue === "") return "";
22466
+ const textValue = getDisplayText(rawValue);
22467
+ return textValue === "\u2014" ? "" : String(textValue);
22468
+ }
22469
+ function estimateLineCount({
22470
+ text,
22471
+ charsPerLine,
22472
+ maxLines
22473
+ }) {
22474
+ const textLength = getGalleryTextLength(text);
22475
+ if (!textLength) return 0;
22476
+ return Math.max(1, Math.min(maxLines, Math.ceil(textLength / charsPerLine)));
22477
+ }
22478
+ function estimateGalleryDetailCellHeight({
22479
+ text,
22480
+ density,
22481
+ bentoColumns
22482
+ }) {
22483
+ const baseHeight = density === "detailed" ? 54 : density === "compact" ? 44 : 48;
22484
+ const charsPerLine = bentoColumns === 1 ? density === "detailed" ? 32 : 26 : density === "detailed" ? 18 : 15;
22485
+ const maxLines = density === "detailed" ? 3 : 2;
22486
+ const lineCount = estimateLineCount({ text, charsPerLine, maxLines });
22487
+ if (!lineCount) return baseHeight;
22488
+ return baseHeight + Math.max(0, lineCount - 1) * 16;
22489
+ }
22490
+ function estimateGalleryDetailGridHeight({
22491
+ columns,
22492
+ density,
22493
+ bentoColumns
22494
+ }) {
22495
+ if (!columns.length) return 0;
22496
+ const cellHeights = columns.map((column) => estimateGalleryDetailCellHeight({
22497
+ text: column.text,
22498
+ density,
22499
+ bentoColumns
22500
+ }));
22501
+ if (bentoColumns === 1) {
22502
+ return 12 + cellHeights.reduce((sum, height) => sum + height, 0) + Math.max(0, columns.length - 1) * 8;
22503
+ }
22504
+ let totalHeight = 12;
22505
+ for (let index = 0; index < cellHeights.length; index += bentoColumns) {
22506
+ const rowHeights = cellHeights.slice(index, index + bentoColumns);
22507
+ totalHeight += Math.max(...rowHeights);
22508
+ if (index + bentoColumns < cellHeights.length) totalHeight += 8;
22509
+ }
22510
+ return totalHeight;
22511
+ }
22512
+ function getDefaultGalleryMasonryItemSize({
22513
+ row,
22514
+ columns,
22515
+ galleryFieldKey,
22516
+ galleryDensity,
22517
+ galleryBentoColumns,
22518
+ galleryDetailVisibility,
22519
+ galleryDetailLimit,
22520
+ getFieldValue,
22521
+ isMediaColumn,
22522
+ isTitleCandidate,
22523
+ isSummaryCandidate,
22524
+ getDisplayText,
22525
+ isImageField,
22526
+ isAudioField,
22527
+ cardVariant,
22528
+ renderPreview,
22529
+ renderLeadingVisual,
22530
+ hiddenDetailFieldKeys,
22531
+ layout,
22532
+ resolveRecordVisual
22533
+ }) {
22534
+ const iconColumn = columns.find((column) => column.renderType === "icon");
22535
+ const iconVisual = iconColumn && resolveRecordVisual ? resolveRecordVisual(row?.[iconColumn.key], row, iconColumn) : null;
22536
+ const selectedGalleryColumn = galleryFieldKey !== "auto" ? columns.find((column) => column.key === galleryFieldKey && isMediaColumn(column, row)) : null;
22537
+ const mediaColumn = selectedGalleryColumn || columns.find((column) => isMediaColumn(column, row)) || null;
22538
+ const mediaValue = mediaColumn ? getFieldValue(mediaColumn, row) : null;
22539
+ const isImageMedia = mediaColumn ? isImageField(mediaColumn, mediaValue) : false;
22540
+ const isAudioMedia = mediaColumn ? isAudioField(mediaColumn, mediaValue) : false;
22541
+ const hasDefaultLeadingVisual = Boolean(iconVisual);
22542
+ const hasLeadingVisual = Boolean(renderLeadingVisual) || hasDefaultLeadingVisual;
22543
+ const contentColumns = columns.filter((column) => column.key !== mediaColumn?.key && column.renderType !== "icon");
22544
+ const titleCandidates = contentColumns.filter((column) => {
22545
+ if (!column || isMediaColumn(column, row) || !isTitleCandidate(column, row)) return false;
22546
+ const value = getFieldValue(column, row);
22547
+ return !(value === null || value === void 0 || value === "");
22548
+ });
22549
+ const titleColumn = titleCandidates[0] || null;
22550
+ const titleText = titleColumn ? getGalleryFieldText({ column: titleColumn, row, getFieldValue, getDisplayText }) : String(getDisplayText(row?.linkKey || row?.id || ""));
22551
+ const summaryColumn = contentColumns.find((column) => {
22552
+ if (!column || column.key === titleColumn?.key || isMediaColumn(column, row) || !isSummaryCandidate(column, row)) return false;
22553
+ const summaryText2 = getGalleryFieldText({ column, row, getFieldValue, getDisplayText });
22554
+ return summaryText2.length > 12;
22555
+ }) || contentColumns.find((column) => {
22556
+ if (!column || column.key === titleColumn?.key || isMediaColumn(column, row) || !isSummaryCandidate(column, row)) return false;
22557
+ return getGalleryTextLength(getGalleryFieldText({ column, row, getFieldValue, getDisplayText })) > 0;
22558
+ }) || null;
22559
+ const summaryText = summaryColumn ? getGalleryFieldText({ column: summaryColumn, row, getFieldValue, getDisplayText }) : "";
22560
+ const hiddenDetailKeySet = new Set(hiddenDetailFieldKeys);
22561
+ const detailColumns = contentColumns.filter((column) => column.key !== titleColumn?.key && column.key !== summaryColumn?.key && !hiddenDetailKeySet.has(column.key)).map((column) => ({
22562
+ column,
22563
+ text: getGalleryFieldText({ column, row, getFieldValue, getDisplayText })
22564
+ }));
22565
+ const resolvedDetailLimit = getNormalizedGalleryDetailLimit2({
22566
+ density: galleryDensity,
22567
+ visibility: galleryDetailVisibility,
22568
+ limit: galleryDetailLimit
22569
+ });
22570
+ const visibleDetailColumns = Number.isFinite(resolvedDetailLimit) ? detailColumns.slice(0, resolvedDetailLimit) : detailColumns;
22571
+ const hiddenDetailCount = Math.max(detailColumns.length - visibleDetailColumns.length, 0);
22572
+ const resolvedBentoColumns = getNormalizedGalleryBentoColumns2(galleryBentoColumns, galleryDensity);
22573
+ const resolvedColumnWidth = layout?.columnWidth || getGalleryCardWidthMetrics(galleryDensity).ideal;
22574
+ if (cardVariant === "image-only") {
22575
+ return {
22576
+ width: resolvedColumnWidth,
22577
+ height: Math.round(resolvedColumnWidth * 1.25)
22578
+ };
22579
+ }
22580
+ if (cardVariant === "preview-only") {
22581
+ return {
22582
+ width: resolvedColumnWidth,
22583
+ height: Math.round(resolvedColumnWidth * 0.82)
22584
+ };
22585
+ }
22586
+ let estimatedHeight = galleryDensity === "detailed" ? 84 : galleryDensity === "compact" ? 64 : 72;
22587
+ if (typeof renderPreview === "function") {
22588
+ estimatedHeight += galleryDensity === "detailed" ? 188 : galleryDensity === "compact" ? 140 : 164;
22589
+ } else if (isImageMedia) {
22590
+ estimatedHeight += Math.round(resolvedColumnWidth * (galleryDensity === "detailed" ? 0.72 : 0.62)) + 12;
22591
+ } else if (isAudioMedia) {
22592
+ estimatedHeight += 92;
22593
+ }
22594
+ const titleLines = estimateLineCount({
22595
+ text: titleText,
22596
+ charsPerLine: galleryDensity === "detailed" ? 26 : 24,
22597
+ maxLines: 2
22598
+ }) || 1;
22599
+ const summaryLines = estimateLineCount({
22600
+ text: summaryText,
22601
+ charsPerLine: hasLeadingVisual ? 22 : galleryDensity === "detailed" ? 30 : 26,
22602
+ maxLines: galleryDensity === "detailed" ? 4 : 2
22603
+ });
22604
+ const textHeaderHeight = 26 + titleLines * 18 + (summaryLines > 0 ? summaryLines * 16 + 4 : 0);
22605
+ estimatedHeight += Math.max(hasLeadingVisual ? 56 : 0, textHeaderHeight);
22606
+ estimatedHeight += estimateGalleryDetailGridHeight({
22607
+ columns: visibleDetailColumns,
22608
+ density: galleryDensity,
22609
+ bentoColumns: resolvedBentoColumns
22610
+ });
22611
+ if (hiddenDetailCount > 0) estimatedHeight += 18;
22612
+ if (!summaryText && visibleDetailColumns.length === 0) estimatedHeight += 24;
22613
+ return {
22614
+ width: resolvedColumnWidth,
22615
+ height: estimatedHeight
22616
+ };
22617
+ }
22618
+ function WorkbenchGalleryView({
22619
+ rows = [],
22620
+ columns = [],
22621
+ onRowClick = () => {
22622
+ },
22623
+ selectedLinkKey,
22624
+ selectedRowKey,
22625
+ className,
22626
+ isMasonry = false,
22627
+ galleryLayoutMode = "auto",
22628
+ galleryRailCardWidth,
22629
+ galleryGridColumns,
22630
+ galleryGridCardWidth,
22631
+ galleryMasonryColumnWidth,
22632
+ masonryPlacementStrategy = "shelf",
22633
+ galleryFieldKey = "auto",
22634
+ galleryDensity = "comfortable",
22635
+ galleryBentoColumns = 2,
22636
+ galleryDetailVisibility = "limit",
22637
+ galleryDetailLimit,
22638
+ shouldEnhanceMultimodal = true,
22639
+ getFieldValue,
22640
+ isMediaColumn,
22641
+ isTitleCandidate,
22642
+ isSummaryCandidate,
22643
+ getDisplayText,
22644
+ renderFieldValue,
22645
+ getImagePreviewSrc,
22646
+ isImageField,
22647
+ isAudioField,
22648
+ AudioPlayerComponent,
22649
+ cardVariant = "default",
22650
+ renderPreview,
22651
+ renderMeta,
22652
+ renderLeadingVisual,
22653
+ resolveRecordVisual,
22654
+ hiddenDetailFieldKeys = [],
22655
+ labels,
22656
+ formatLabel,
22657
+ getMasonryItemSize
22658
+ }) {
22659
+ const containerRef = React.useRef(null);
22660
+ const [containerWidth, setContainerWidth] = React.useState(0);
22661
+ const { min: resolvedMinCardWidth, ideal: resolvedIdealCardWidth, max: resolvedMaxCardWidth } = getGalleryCardWidthMetrics(galleryDensity);
22662
+ const resolvedRailCardWidth = galleryRailCardWidth || resolvedMinCardWidth;
22663
+ const resolvedGridColumnCount = getNormalizedGalleryGridColumns(galleryGridColumns);
22664
+ const resolvedGridCardWidth = getNormalizedGalleryGridCardWidth(galleryGridCardWidth);
22665
+ const resolvedMasonryColumnWidth = galleryMasonryColumnWidth || resolvedMinCardWidth;
22666
+ const isRailLayout = galleryLayoutMode === "rail";
22667
+ const resolvedGetFieldValue = getFieldValue || getDefaultGalleryFieldValue;
22668
+ const resolvedGetDisplayText = getDisplayText || getDefaultGalleryDisplayText;
22669
+ const resolvedIsImageField = isImageField || isDefaultGalleryImageField;
22670
+ const resolvedIsAudioField = isAudioField || isDefaultGalleryAudioField;
22671
+ const resolvedIsMediaColumn = isMediaColumn || ((column, row) => isDefaultGalleryMediaColumn(column, row, {
22672
+ getFieldValue: resolvedGetFieldValue,
22673
+ shouldEnhanceMultimodal,
22674
+ isImageField: resolvedIsImageField,
22675
+ isAudioField: resolvedIsAudioField
22676
+ }));
22677
+ const resolvedIsTitleCandidate = isTitleCandidate || ((column, row) => isDefaultGalleryTitleCandidate(column, row, { isMediaColumn: resolvedIsMediaColumn }));
22678
+ const resolvedIsSummaryCandidate = isSummaryCandidate || ((column, row) => isDefaultGallerySummaryCandidate(column, row, { isMediaColumn: resolvedIsMediaColumn }));
22679
+ const resolvedRenderFieldValue = renderFieldValue || ((column, row, { compact } = {}) => /* @__PURE__ */ jsxRuntime.jsx("span", { children: resolvedGetDisplayText(resolvedGetFieldValue(column, row)) }));
22680
+ React.useEffect(() => {
22681
+ if (isMasonry || isRailLayout || resolvedGridCardWidth) return void 0;
22682
+ const node = containerRef.current;
22683
+ if (!node) return void 0;
22684
+ const updateWidth = () => {
22685
+ const nextWidth = Math.round(node.getBoundingClientRect().width);
22686
+ setContainerWidth((prevWidth) => prevWidth === nextWidth ? prevWidth : nextWidth);
22687
+ };
22688
+ updateWidth();
22689
+ if (typeof ResizeObserver === "function") {
22690
+ const observer = new ResizeObserver(() => updateWidth());
22691
+ observer.observe(node);
22692
+ return () => observer.disconnect();
22693
+ }
22694
+ window.addEventListener("resize", updateWidth);
22695
+ return () => window.removeEventListener("resize", updateWidth);
22696
+ }, [isMasonry, isRailLayout, resolvedGridCardWidth]);
22697
+ const layoutStyle = React.useMemo(() => getGalleryGridLayoutStyle({
22698
+ isRailLayout,
22699
+ railCardWidth: resolvedRailCardWidth,
22700
+ fixedCardWidth: resolvedGridCardWidth,
22701
+ fixedColumnCount: resolvedGridColumnCount,
22702
+ containerWidth,
22703
+ rowCount: rows.length,
22704
+ minCardWidth: resolvedMinCardWidth,
22705
+ idealCardWidth: resolvedIdealCardWidth,
22706
+ maxCardWidth: resolvedMaxCardWidth
22707
+ }), [
22708
+ containerWidth,
22709
+ isRailLayout,
22710
+ resolvedGridCardWidth,
22711
+ resolvedGridColumnCount,
22712
+ resolvedIdealCardWidth,
22713
+ resolvedMaxCardWidth,
22714
+ resolvedMinCardWidth,
22715
+ resolvedRailCardWidth,
22716
+ rows.length
22717
+ ]);
22718
+ const renderGalleryCard = (row, rowIndex) => /* @__PURE__ */ jsxRuntime.jsx(
22719
+ WorkbenchGalleryCard,
22720
+ {
22721
+ row,
22722
+ columns,
22723
+ onClick: () => onRowClick(row, rowIndex),
22724
+ isSelected: String(row?.linkKey || row?.id || "") === String(selectedRowKey || selectedLinkKey || ""),
22725
+ isMasonry,
22726
+ galleryFieldKey,
22727
+ galleryDensity,
22728
+ galleryBentoColumns,
22729
+ galleryDetailVisibility,
22730
+ galleryDetailLimit,
22731
+ shouldEnhanceMultimodal,
22732
+ getFieldValue: resolvedGetFieldValue,
22733
+ isMediaColumn: resolvedIsMediaColumn,
22734
+ isTitleCandidate: resolvedIsTitleCandidate,
22735
+ isSummaryCandidate: resolvedIsSummaryCandidate,
22736
+ getDisplayText: resolvedGetDisplayText,
22737
+ renderFieldValue: resolvedRenderFieldValue,
22738
+ getImagePreviewSrc,
22739
+ isImageField: resolvedIsImageField,
22740
+ isAudioField: resolvedIsAudioField,
22741
+ AudioPlayerComponent,
22742
+ cardVariant,
22743
+ renderPreview,
22744
+ renderMeta,
22745
+ renderLeadingVisual,
22746
+ resolveRecordVisual,
22747
+ hiddenDetailFieldKeys,
22748
+ labels,
22749
+ formatLabel
22750
+ },
22751
+ row?.id || row?.linkKey || rowIndex
22752
+ );
22753
+ if (isMasonry) {
22754
+ return /* @__PURE__ */ jsxRuntime.jsx(
22755
+ WorkbenchMasonryLayout,
22756
+ {
22757
+ items: rows,
22758
+ className,
22759
+ gap: GALLERY_GRID_GAP_PX,
22760
+ columnWidth: resolvedMasonryColumnWidth,
22761
+ placementStrategy: masonryPlacementStrategy,
22762
+ getItemKey: (row, rowIndex) => row?.id || row?.linkKey || rowIndex,
22763
+ getItemSize: (row, layout) => {
22764
+ const defaultSize = getDefaultGalleryMasonryItemSize({
22765
+ row,
22766
+ columns,
22767
+ galleryFieldKey,
22768
+ galleryDensity,
22769
+ galleryBentoColumns,
22770
+ galleryDetailVisibility,
22771
+ galleryDetailLimit,
22772
+ getFieldValue: resolvedGetFieldValue,
22773
+ isMediaColumn: resolvedIsMediaColumn,
22774
+ isTitleCandidate: resolvedIsTitleCandidate,
22775
+ isSummaryCandidate: resolvedIsSummaryCandidate,
22776
+ getDisplayText: resolvedGetDisplayText,
22777
+ isImageField: resolvedIsImageField,
22778
+ isAudioField: resolvedIsAudioField,
22779
+ cardVariant,
22780
+ renderPreview,
22781
+ renderLeadingVisual,
22782
+ hiddenDetailFieldKeys,
22783
+ layout,
22784
+ resolveRecordVisual
22785
+ });
22786
+ if (typeof getMasonryItemSize !== "function") return defaultSize;
22787
+ const customSize = getMasonryItemSize(row, { ...layout, defaultSize }) || {};
22788
+ return {
22789
+ ...defaultSize,
22790
+ ...customSize
22791
+ };
22792
+ },
22793
+ renderItem: (row) => renderGalleryCard(row, rows.indexOf(row))
22794
+ }
22795
+ );
22796
+ }
22797
+ return /* @__PURE__ */ jsxRuntime.jsx(
22798
+ "div",
22799
+ {
22800
+ ref: containerRef,
22801
+ className: cn(
22802
+ isRailLayout ? "grid grid-flow-col items-center gap-3" : "grid items-start gap-3",
22803
+ className
22804
+ ),
22805
+ style: layoutStyle,
22806
+ children: rows.map((row, rowIndex) => renderGalleryCard(row, rowIndex))
22807
+ }
22808
+ );
22809
+ }
19999
22810
  function cn4(...inputs) {
20000
22811
  return inputs.filter(Boolean).join(" ");
20001
22812
  }
@@ -20392,6 +23203,16 @@ exports.NavButton = NavButton;
20392
23203
  exports.OAuthButton = OAuthButton;
20393
23204
  exports.OIDCButton = OIDCButton;
20394
23205
  exports.PendingApproval = PendingApproval;
23206
+ exports.WorkbenchContentPane = WorkbenchContentPane;
23207
+ exports.WorkbenchContentToolbar = WorkbenchContentToolbar;
23208
+ exports.WorkbenchDetailSidebar = WorkbenchDetailSidebar;
23209
+ exports.WorkbenchGalleryCard = WorkbenchGalleryCard;
23210
+ exports.WorkbenchGallerySettingsButton = WorkbenchGallerySettingsButton;
23211
+ exports.WorkbenchGallerySettingsPanel = WorkbenchGallerySettingsPanel;
23212
+ exports.WorkbenchGalleryView = WorkbenchGalleryView;
23213
+ exports.WorkbenchMasonryLayout = WorkbenchMasonryLayout;
23214
+ exports.WorkbenchResizableSidebar = WorkbenchResizableSidebar;
23215
+ exports.WorkbenchTableView = WorkbenchTableView;
20395
23216
  exports.applyMonkeysTheme = applyMonkeysTheme;
20396
23217
  exports.calculateHue = calculateHue;
20397
23218
  exports.calculateLightness = calculateLightness;