@almadar/ui 2.1.2 → 2.1.4

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.
@@ -1,5 +1,5 @@
1
1
  import { apiClient } from './chunk-XSEDIUM6.js';
2
- import { SelectionContext, entityDataKeys, useEntityList } from './chunk-PE2H3NAW.js';
2
+ import { SelectionContext, entityDataKeys, useEntityList } from './chunk-JLEMVREZ.js';
3
3
  import { useEventBus } from './chunk-YXZM3WCF.js';
4
4
  import { subscribe, getSnapshot, clearEntities, removeEntity, updateSingleton, updateEntity, spawnEntity, getSingleton, getAllEntities, getByType, getEntity } from './chunk-N7MVUW4R.js';
5
5
  import { useCallback, useState, useEffect, useMemo, useContext, useSyncExternalStore } from 'react';
@@ -1,5 +1,5 @@
1
1
  import { useEventBus } from './chunk-YXZM3WCF.js';
2
- import React, { createContext, useContext, useState, useMemo, useCallback, useEffect } from 'react';
2
+ import React2, { createContext, useContext, useState, useMemo, useCallback, useEffect } from 'react';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
 
5
5
  var I18nContext = createContext({
@@ -90,12 +90,99 @@ function parseQueryBinding(binding) {
90
90
  field: parts.length > 1 ? parts.slice(1).join(".") : void 0
91
91
  };
92
92
  }
93
+ var SelectionContext = createContext(null);
94
+ var defaultCompareEntities = (a, b) => {
95
+ if (a === b) return true;
96
+ if (!a || !b) return false;
97
+ if (typeof a === "object" && typeof b === "object") {
98
+ const aId = a.id;
99
+ const bId = b.id;
100
+ return aId !== void 0 && aId === bId;
101
+ }
102
+ return false;
103
+ };
104
+ function SelectionProvider({
105
+ children,
106
+ debug = false,
107
+ compareEntities = defaultCompareEntities
108
+ }) {
109
+ const eventBus = useEventBus();
110
+ const [selected, setSelectedState] = useState(null);
111
+ const setSelected = useCallback(
112
+ (entity) => {
113
+ setSelectedState(entity);
114
+ if (debug) {
115
+ console.log("[SelectionProvider] Selection set:", entity);
116
+ }
117
+ },
118
+ [debug]
119
+ );
120
+ const clearSelection = useCallback(() => {
121
+ setSelectedState(null);
122
+ if (debug) {
123
+ console.log("[SelectionProvider] Selection cleared");
124
+ }
125
+ }, [debug]);
126
+ const isSelected = useCallback(
127
+ (entity) => {
128
+ return compareEntities(selected, entity);
129
+ },
130
+ [selected, compareEntities]
131
+ );
132
+ useEffect(() => {
133
+ const handleSelect = (event) => {
134
+ const row = event.payload?.row;
135
+ if (row) {
136
+ setSelected(row);
137
+ if (debug) {
138
+ console.log(`[SelectionProvider] ${event.type} received:`, row);
139
+ }
140
+ }
141
+ };
142
+ const handleDeselect = (event) => {
143
+ clearSelection();
144
+ if (debug) {
145
+ console.log(`[SelectionProvider] ${event.type} received - clearing selection`);
146
+ }
147
+ };
148
+ const unsubView = eventBus.on("UI:VIEW", handleSelect);
149
+ const unsubSelect = eventBus.on("UI:SELECT", handleSelect);
150
+ const unsubClose = eventBus.on("UI:CLOSE", handleDeselect);
151
+ const unsubDeselect = eventBus.on("UI:DESELECT", handleDeselect);
152
+ const unsubCancel = eventBus.on("UI:CANCEL", handleDeselect);
153
+ return () => {
154
+ unsubView();
155
+ unsubSelect();
156
+ unsubClose();
157
+ unsubDeselect();
158
+ unsubCancel();
159
+ };
160
+ }, [eventBus, setSelected, clearSelection, debug]);
161
+ const contextValue = {
162
+ selected,
163
+ setSelected,
164
+ clearSelection,
165
+ isSelected
166
+ };
167
+ return /* @__PURE__ */ jsx(SelectionContext.Provider, { value: contextValue, children });
168
+ }
169
+ function useSelection() {
170
+ const context = useContext(SelectionContext);
171
+ if (!context) {
172
+ throw new Error("useSelection must be used within a SelectionProvider");
173
+ }
174
+ return context;
175
+ }
176
+ function useSelectionOptional() {
177
+ const context = useContext(SelectionContext);
178
+ return context;
179
+ }
93
180
  var EntityDataContext = createContext(null);
94
181
  function EntityDataProvider({
95
182
  adapter,
96
183
  children
97
184
  }) {
98
- return React.createElement(
185
+ return React2.createElement(
99
186
  EntityDataContext.Provider,
100
187
  { value: adapter },
101
188
  children
@@ -292,92 +379,5 @@ function useEntitySuspense(entity, id) {
292
379
  return { data: null, refetch: () => {
293
380
  } };
294
381
  }
295
- var SelectionContext = createContext(null);
296
- var defaultCompareEntities = (a, b) => {
297
- if (a === b) return true;
298
- if (!a || !b) return false;
299
- if (typeof a === "object" && typeof b === "object") {
300
- const aId = a.id;
301
- const bId = b.id;
302
- return aId !== void 0 && aId === bId;
303
- }
304
- return false;
305
- };
306
- function SelectionProvider({
307
- children,
308
- debug = false,
309
- compareEntities = defaultCompareEntities
310
- }) {
311
- const eventBus = useEventBus();
312
- const [selected, setSelectedState] = useState(null);
313
- const setSelected = useCallback(
314
- (entity) => {
315
- setSelectedState(entity);
316
- if (debug) {
317
- console.log("[SelectionProvider] Selection set:", entity);
318
- }
319
- },
320
- [debug]
321
- );
322
- const clearSelection = useCallback(() => {
323
- setSelectedState(null);
324
- if (debug) {
325
- console.log("[SelectionProvider] Selection cleared");
326
- }
327
- }, [debug]);
328
- const isSelected = useCallback(
329
- (entity) => {
330
- return compareEntities(selected, entity);
331
- },
332
- [selected, compareEntities]
333
- );
334
- useEffect(() => {
335
- const handleSelect = (event) => {
336
- const row = event.payload?.row;
337
- if (row) {
338
- setSelected(row);
339
- if (debug) {
340
- console.log(`[SelectionProvider] ${event.type} received:`, row);
341
- }
342
- }
343
- };
344
- const handleDeselect = (event) => {
345
- clearSelection();
346
- if (debug) {
347
- console.log(`[SelectionProvider] ${event.type} received - clearing selection`);
348
- }
349
- };
350
- const unsubView = eventBus.on("UI:VIEW", handleSelect);
351
- const unsubSelect = eventBus.on("UI:SELECT", handleSelect);
352
- const unsubClose = eventBus.on("UI:CLOSE", handleDeselect);
353
- const unsubDeselect = eventBus.on("UI:DESELECT", handleDeselect);
354
- const unsubCancel = eventBus.on("UI:CANCEL", handleDeselect);
355
- return () => {
356
- unsubView();
357
- unsubSelect();
358
- unsubClose();
359
- unsubDeselect();
360
- unsubCancel();
361
- };
362
- }, [eventBus, setSelected, clearSelection, debug]);
363
- const contextValue = {
364
- selected,
365
- setSelected,
366
- clearSelection,
367
- isSelected
368
- };
369
- return /* @__PURE__ */ jsx(SelectionContext.Provider, { value: contextValue, children });
370
- }
371
- function useSelection() {
372
- const context = useContext(SelectionContext);
373
- if (!context) {
374
- throw new Error("useSelection must be used within a SelectionProvider");
375
- }
376
- return context;
377
- }
378
- function useSelectionOptional() {
379
- const context = useContext(SelectionContext);
380
- return context;
381
- }
382
382
 
383
383
  export { EntityDataProvider, I18nProvider, SelectionContext, SelectionProvider, createTranslate, entityDataKeys, parseQueryBinding, useEntity, useEntityDataAdapter, useEntityDetail, useEntityList, useEntityListSuspense, useEntitySuspense, useQuerySingleton, useSelection, useSelectionOptional, useTranslate };
@@ -1,7 +1,7 @@
1
1
  import { useTheme, useUISlots } from './chunk-BTXQJGFB.js';
2
- import { useTranslate, useQuerySingleton, useEntityList } from './chunk-PE2H3NAW.js';
3
- import { useEventBus } from './chunk-YXZM3WCF.js';
4
2
  import { cn, debugGroup, debug, debugGroupEnd, getNestedValue, isDebugEnabled } from './chunk-KKCVDUK7.js';
3
+ import { useTranslate, useQuerySingleton } from './chunk-JLEMVREZ.js';
4
+ import { useEventBus } from './chunk-YXZM3WCF.js';
5
5
  import { __publicField } from './chunk-PKBMQBKP.js';
6
6
  import * as React41 from 'react';
7
7
  import React41__default, { useCallback, useRef, useState, useLayoutEffect, useEffect, createContext, useMemo, useContext, Suspense } from 'react';
@@ -6442,7 +6442,6 @@ function normalizeColumns(columns) {
6442
6442
  function DataTable({
6443
6443
  fields,
6444
6444
  columns,
6445
- data,
6446
6445
  entity,
6447
6446
  itemActions,
6448
6447
  isLoading = false,
@@ -6476,8 +6475,8 @@ function DataTable({
6476
6475
  const resolvedEmptyDescription = emptyDescription ?? t("table.empty.description");
6477
6476
  const resolvedSearchPlaceholder = searchPlaceholder ?? t("common.search");
6478
6477
  const items = useMemo(
6479
- () => Array.isArray(data) ? data : [],
6480
- [data]
6478
+ () => Array.isArray(entity) ? entity : [],
6479
+ [entity]
6481
6480
  );
6482
6481
  const currentPage = page ?? 1;
6483
6482
  const currentPageSize = pageSize ?? 20;
@@ -6494,13 +6493,12 @@ function DataTable({
6494
6493
  /\{\{id\}\}/g,
6495
6494
  String(row.id)
6496
6495
  );
6497
- eventBus.emit("UI:NAVIGATE", { url, row, entity });
6496
+ eventBus.emit("UI:NAVIGATE", { url, row });
6498
6497
  return;
6499
6498
  }
6500
6499
  if (action.event) {
6501
6500
  eventBus.emit(`UI:${action.event}`, {
6502
- row,
6503
- entity
6501
+ row
6504
6502
  });
6505
6503
  }
6506
6504
  }
@@ -6519,10 +6517,10 @@ function DataTable({
6519
6517
  eventBus.emit("UI:NAVIGATE", { url, row, entity });
6520
6518
  return;
6521
6519
  }
6522
- eventBus.emit("UI:VIEW", { row, entity });
6520
+ eventBus.emit("UI:VIEW", { row });
6523
6521
  }
6524
6522
  },
6525
- [viewAction, eventBus, entity]
6523
+ [viewAction, eventBus]
6526
6524
  );
6527
6525
  const isRowClickable = !!viewAction;
6528
6526
  const effectiveColumns = fields ?? columns ?? [];
@@ -6535,61 +6533,54 @@ function DataTable({
6535
6533
  const handleSelectAll = useCallback(() => {
6536
6534
  if (allSelected) {
6537
6535
  eventBus.emit(`UI:${EntityDisplayEvents.DESELECT}`, {
6538
- ids: [],
6539
- entity
6536
+ ids: []
6540
6537
  });
6541
6538
  } else {
6542
6539
  eventBus.emit(`UI:${EntityDisplayEvents.SELECT}`, {
6543
- ids: items.map((row) => row.id),
6544
- entity
6540
+ ids: items.map((row) => row.id)
6545
6541
  });
6546
6542
  }
6547
- }, [allSelected, items, eventBus, entity]);
6543
+ }, [allSelected, items, eventBus]);
6548
6544
  const handleSelectRow = useCallback(
6549
6545
  (id) => {
6550
6546
  if (selectedIds.includes(id)) {
6551
6547
  eventBus.emit(`UI:${EntityDisplayEvents.DESELECT}`, {
6552
- ids: selectedIds.filter((i) => i !== id),
6553
- entity
6548
+ ids: selectedIds.filter((i) => i !== id)
6554
6549
  });
6555
6550
  } else {
6556
6551
  eventBus.emit(`UI:${EntityDisplayEvents.SELECT}`, {
6557
- ids: [...selectedIds, id],
6558
- entity
6552
+ ids: [...selectedIds, id]
6559
6553
  });
6560
6554
  }
6561
6555
  },
6562
- [selectedIds, eventBus, entity]
6556
+ [selectedIds, eventBus]
6563
6557
  );
6564
6558
  const handleSort = useCallback(
6565
6559
  (key) => {
6566
6560
  const newDirection = sortBy === key && sortDirection === "asc" ? "desc" : "asc";
6567
6561
  eventBus.emit(`UI:${EntityDisplayEvents.SORT}`, {
6568
6562
  field: key,
6569
- direction: newDirection,
6570
- entity
6563
+ direction: newDirection
6571
6564
  });
6572
6565
  },
6573
- [sortBy, sortDirection, eventBus, entity]
6566
+ [sortBy, sortDirection, eventBus]
6574
6567
  );
6575
6568
  const handleSearch = useCallback(
6576
6569
  (value) => {
6577
6570
  eventBus.emit(`UI:${EntityDisplayEvents.SEARCH}`, {
6578
- query: value,
6579
- entity
6571
+ query: value
6580
6572
  });
6581
6573
  },
6582
- [eventBus, entity]
6574
+ [eventBus]
6583
6575
  );
6584
6576
  const handlePageChange = useCallback(
6585
6577
  (newPage) => {
6586
6578
  eventBus.emit(`UI:${EntityDisplayEvents.PAGINATE}`, {
6587
6579
  page: newPage,
6588
- pageSize: currentPageSize,
6589
- entity
6580
+ pageSize: currentPageSize
6590
6581
  });
6591
6582
  },
6592
- [eventBus, currentPageSize, entity]
6583
+ [eventBus, currentPageSize]
6593
6584
  );
6594
6585
  const selectedRows = useMemo(
6595
6586
  () => items.filter((row) => selectedIds.includes(row.id)),
@@ -6857,7 +6848,6 @@ var StatCard = ({
6857
6848
  // Schema-based props
6858
6849
  entity,
6859
6850
  metrics,
6860
- data: externalData,
6861
6851
  isLoading: externalLoading,
6862
6852
  error: externalError
6863
6853
  }) => {
@@ -6866,19 +6856,14 @@ var StatCard = ({
6866
6856
  const { t } = useTranslate();
6867
6857
  const handleActionClick = React41__default.useCallback(() => {
6868
6858
  if (action?.event) {
6869
- eventBus.emit(`UI:${action.event}`, { entity });
6859
+ eventBus.emit(`UI:${action.event}`, {});
6870
6860
  }
6871
6861
  if (action?.onClick) {
6872
6862
  action.onClick();
6873
6863
  }
6874
- }, [action, eventBus, entity]);
6875
- const shouldAutoFetch = !!entity && !externalData && !!metrics;
6876
- const { data: fetchedData, isLoading: fetchLoading } = useEntityList(
6877
- shouldAutoFetch ? entity : void 0,
6878
- { skip: !shouldAutoFetch }
6879
- );
6880
- const data = externalData ?? fetchedData ?? [];
6881
- const isLoading = externalLoading ?? (shouldAutoFetch ? fetchLoading : false);
6864
+ }, [action, eventBus]);
6865
+ const data = Array.isArray(entity) ? entity : entity ? [entity] : [];
6866
+ const isLoading = externalLoading ?? false;
6882
6867
  const error = externalError;
6883
6868
  const computeMetricValue = React41__default.useCallback(
6884
6869
  (metric, items) => {
@@ -6927,6 +6912,13 @@ var StatCard = ({
6927
6912
  format: metric.format
6928
6913
  }));
6929
6914
  }, [metrics, data, computeMetricValue]);
6915
+ const calculatedTrend = React41__default.useMemo(() => {
6916
+ if (manualTrend !== void 0) return manualTrend;
6917
+ if (previousValue === void 0 || currentValue === void 0)
6918
+ return void 0;
6919
+ if (previousValue === 0) return currentValue > 0 ? 100 : 0;
6920
+ return (currentValue - previousValue) / previousValue * 100;
6921
+ }, [manualTrend, previousValue, currentValue]);
6930
6922
  if (schemaStats && schemaStats.length > 1) {
6931
6923
  if (isLoading) {
6932
6924
  return /* @__PURE__ */ jsx(
@@ -6953,16 +6945,9 @@ var StatCard = ({
6953
6945
  }
6954
6946
  );
6955
6947
  }
6956
- const label = schemaStats?.[0]?.label || labelToUse || entity || "Stat";
6948
+ const label = schemaStats?.[0]?.label || labelToUse || "Stat";
6957
6949
  const normalizedPropValue = Array.isArray(propValue) ? propValue[0] ?? propValue.length : propValue;
6958
6950
  const value = schemaStats?.[0]?.value ?? normalizedPropValue ?? 0;
6959
- const calculatedTrend = useMemo4(() => {
6960
- if (manualTrend !== void 0) return manualTrend;
6961
- if (previousValue === void 0 || currentValue === void 0)
6962
- return void 0;
6963
- if (previousValue === 0) return currentValue > 0 ? 100 : 0;
6964
- return (currentValue - previousValue) / previousValue * 100;
6965
- }, [manualTrend, previousValue, currentValue]);
6966
6951
  const trendDirection = manualDirection || (calculatedTrend === void 0 || calculatedTrend === 0 ? "neutral" : calculatedTrend > 0 ? "up" : "down");
6967
6952
  const isPositive = invertTrend ? trendDirection === "down" : trendDirection === "up";
6968
6953
  const TrendIcon = trendDirection === "up" ? TrendingUp : trendDirection === "down" ? TrendingDown : Minus;
@@ -7024,9 +7009,6 @@ var StatCard = ({
7024
7009
  ] });
7025
7010
  };
7026
7011
  StatCard.displayName = "StatCard";
7027
- function useMemo4(factory, deps) {
7028
- return React41__default.useMemo(factory, deps);
7029
- }
7030
7012
  var PageHeader = ({
7031
7013
  title,
7032
7014
  subtitle,
@@ -7221,7 +7203,6 @@ var DetailPanel = ({
7221
7203
  entity,
7222
7204
  fields: propFields,
7223
7205
  fieldNames,
7224
- data: externalData,
7225
7206
  initialData,
7226
7207
  isLoading = false,
7227
7208
  error
@@ -7240,22 +7221,23 @@ var DetailPanel = ({
7240
7221
  /\{\{(\w+)\}\}/g,
7241
7222
  (_, key) => String(data2?.[key] ?? "")
7242
7223
  );
7243
- eventBus.emit("UI:NAVIGATE", { url, row: data2, entity });
7224
+ eventBus.emit("UI:NAVIGATE", { url, row: data2 });
7244
7225
  return;
7245
7226
  }
7246
7227
  if (action.event) {
7247
- eventBus.emit(`UI:${action.event}`, { row: data2, entity });
7228
+ eventBus.emit(`UI:${action.event}`, { row: data2 });
7248
7229
  }
7249
7230
  if (action.onClick) {
7250
7231
  action.onClick();
7251
7232
  }
7252
7233
  },
7253
- [eventBus, entity]
7234
+ [eventBus]
7254
7235
  );
7255
7236
  const handleClose = useCallback(() => {
7256
7237
  eventBus.emit("UI:CLOSE", {});
7257
7238
  }, [eventBus]);
7258
- const data = externalData ?? initialData;
7239
+ const entityRecord = Array.isArray(entity) ? entity[0] : entity;
7240
+ const data = entityRecord ?? initialData;
7259
7241
  let title = propTitle;
7260
7242
  let sections = propSections ? [...propSections] : void 0;
7261
7243
  const normalizedData = data && typeof data === "object" && !Array.isArray(data) ? data : void 0;
@@ -7368,7 +7350,7 @@ var DetailPanel = ({
7368
7350
  return /* @__PURE__ */ jsx(
7369
7351
  LoadingState,
7370
7352
  {
7371
- message: `Loading ${entity || "details"}...`,
7353
+ message: "Loading details...",
7372
7354
  className
7373
7355
  }
7374
7356
  );
@@ -7389,7 +7371,7 @@ var DetailPanel = ({
7389
7371
  EmptyState,
7390
7372
  {
7391
7373
  title: "Not Found",
7392
- description: `The requested ${entity || "item"} could not be found.`,
7374
+ description: "The requested item could not be found.",
7393
7375
  className
7394
7376
  }
7395
7377
  );
@@ -7399,7 +7381,7 @@ var DetailPanel = ({
7399
7381
  /* @__PURE__ */ jsxs(HStack, { justify: "between", align: "start", children: [
7400
7382
  /* @__PURE__ */ jsxs(VStack, { gap: "sm", flex: true, className: "min-w-0", children: [
7401
7383
  avatar,
7402
- /* @__PURE__ */ jsx(Typography, { variant: "h2", weight: "bold", children: title || entity || "Details" }),
7384
+ /* @__PURE__ */ jsx(Typography, { variant: "h2", weight: "bold", children: title || "Details" }),
7403
7385
  subtitle && /* @__PURE__ */ jsx(Typography, { variant: "body", color: "secondary", children: subtitle }),
7404
7386
  normalizedData && effectiveFieldNames && /* @__PURE__ */ jsx(HStack, { gap: "xs", wrap: true, children: effectiveFieldNames.filter(
7405
7387
  (f) => f.toLowerCase().includes("status") || f.toLowerCase().includes("priority")
@@ -7608,6 +7590,23 @@ var Form = ({
7608
7590
  const resolvedSubmitLabel = submitLabel ?? t("common.save");
7609
7591
  const resolvedCancelLabel = cancelLabel ?? t("common.cancel");
7610
7592
  const normalizedInitialData = initialData ?? {};
7593
+ const entityName = typeof entity === "string" ? entity : entity?.name;
7594
+ const entityDerivedFields = React41__default.useMemo(() => {
7595
+ if (fields && fields.length > 0) return void 0;
7596
+ if (!entity || typeof entity === "string") return void 0;
7597
+ return entity.fields.map(
7598
+ (f) => ({
7599
+ name: f.name,
7600
+ type: f.type,
7601
+ required: f.required,
7602
+ defaultValue: f.default,
7603
+ values: f.values,
7604
+ min: f.min,
7605
+ max: f.max,
7606
+ relation: f.relation ? { entity: f.relation.entity } : void 0
7607
+ })
7608
+ );
7609
+ }, [entity, fields]);
7611
7610
  const conditionalFields = typeof conditionalFieldsRaw === "boolean" ? {} : conditionalFieldsRaw;
7612
7611
  const hiddenCalculations = typeof hiddenCalculationsRaw === "boolean" ? [] : hiddenCalculationsRaw;
7613
7612
  const violationTriggers = typeof violationTriggersRaw === "boolean" ? [] : violationTriggersRaw;
@@ -7723,9 +7722,9 @@ var Form = ({
7723
7722
  };
7724
7723
  const handleSubmit = (e) => {
7725
7724
  e.preventDefault();
7726
- eventBus.emit(`UI:${submitEvent}`, { data: formData, entity });
7725
+ eventBus.emit(`UI:${submitEvent}`, { data: formData });
7727
7726
  if (onSubmit) {
7728
- eventBus.emit(`UI:${onSubmit}`, { data: formData, entity });
7727
+ eventBus.emit(`UI:${onSubmit}`, { data: formData });
7729
7728
  }
7730
7729
  };
7731
7730
  const handleCancel = () => {
@@ -7755,25 +7754,26 @@ var Form = ({
7755
7754
  },
7756
7755
  [formData, isFieldVisible, relationsData, relationsLoading, isLoading]
7757
7756
  );
7757
+ const effectiveFields = entityDerivedFields ?? fields;
7758
7758
  const normalizedFields = React41__default.useMemo(() => {
7759
- if (!fields || fields.length === 0) return [];
7760
- return fields.map((field) => {
7759
+ if (!effectiveFields || effectiveFields.length === 0) return [];
7760
+ return effectiveFields.map((field) => {
7761
7761
  if (typeof field === "string") {
7762
7762
  return { name: field, type: "string" };
7763
7763
  }
7764
7764
  return field;
7765
7765
  });
7766
- }, [fields]);
7766
+ }, [effectiveFields]);
7767
7767
  const schemaFields = React41__default.useMemo(() => {
7768
7768
  if (normalizedFields.length === 0) return null;
7769
7769
  if (isDebugEnabled()) {
7770
- debugGroup(`Form: ${entity || "unknown"}`);
7770
+ debugGroup(`Form: ${entityName || "unknown"}`);
7771
7771
  debug(`Fields count: ${normalizedFields.length}`);
7772
7772
  debug("Conditional fields:", Object.keys(conditionalFields));
7773
7773
  debugGroupEnd();
7774
7774
  }
7775
7775
  return normalizedFields.map(renderField).filter(Boolean);
7776
- }, [normalizedFields, renderField, entity, conditionalFields]);
7776
+ }, [normalizedFields, renderField, entityName, conditionalFields]);
7777
7777
  const sectionElements = React41__default.useMemo(() => {
7778
7778
  if (!sections || sections.length === 0) return null;
7779
7779
  return sections.map((section) => {
@@ -8049,7 +8049,6 @@ var CardGrid = ({
8049
8049
  children,
8050
8050
  // EntityDisplayProps
8051
8051
  entity,
8052
- data: externalData,
8053
8052
  isLoading = false,
8054
8053
  error = null,
8055
8054
  page,
@@ -8065,40 +8064,30 @@ var CardGrid = ({
8065
8064
  const eventBus = useEventBus();
8066
8065
  const effectiveFieldNames = normalizeFields(fields).length > 0 ? normalizeFields(fields) : fieldNames ?? normalizeFields(columns);
8067
8066
  const gridTemplateColumns = `repeat(auto-fit, minmax(min(${minCardWidth}px, 100%), 1fr))`;
8068
- const normalizedData = Array.isArray(externalData) ? externalData : externalData ? [externalData] : [];
8067
+ const normalizedData = Array.isArray(entity) ? entity : entity ? [entity] : [];
8069
8068
  const resolvedPage = page ?? 1;
8070
8069
  const resolvedTotalPages = totalCount && pageSize ? Math.ceil(totalCount / pageSize) : 1;
8071
8070
  const handlePageChange = (newPage) => {
8072
8071
  eventBus.emit("UI:PAGINATE", { page: newPage, pageSize });
8073
8072
  };
8074
8073
  const handleCardClick = (itemData) => {
8075
- eventBus.emit("UI:VIEW", { row: itemData, entity });
8074
+ eventBus.emit("UI:VIEW", { row: itemData });
8076
8075
  };
8077
8076
  const renderContent = () => {
8078
8077
  if (children) {
8079
8078
  return children;
8080
8079
  }
8081
8080
  if (isLoading) {
8082
- return /* @__PURE__ */ jsx(Box, { className: "col-span-full text-center py-8 text-[var(--color-muted-foreground)]", children: /* @__PURE__ */ jsxs(Typography, { variant: "body", color: "secondary", children: [
8083
- "Loading ",
8084
- entity || "items",
8085
- "..."
8086
- ] }) });
8081
+ return /* @__PURE__ */ jsx(Box, { className: "col-span-full text-center py-8 text-[var(--color-muted-foreground)]", children: /* @__PURE__ */ jsx(Typography, { variant: "body", color: "secondary", children: "Loading items..." }) });
8087
8082
  }
8088
8083
  if (error) {
8089
8084
  return /* @__PURE__ */ jsx(Box, { className: "col-span-full text-center py-8 text-[var(--color-error)]", children: /* @__PURE__ */ jsxs(Typography, { variant: "body", color: "error", children: [
8090
- "Error loading ",
8091
- entity || "items",
8092
- ": ",
8085
+ "Error loading items: ",
8093
8086
  error.message
8094
8087
  ] }) });
8095
8088
  }
8096
8089
  if (normalizedData.length === 0) {
8097
- return /* @__PURE__ */ jsx(Box, { className: "col-span-full text-center py-8 text-[var(--color-muted-foreground)]", children: /* @__PURE__ */ jsxs(Typography, { variant: "body", color: "secondary", children: [
8098
- "No ",
8099
- entity || "items",
8100
- " found"
8101
- ] }) });
8090
+ return /* @__PURE__ */ jsx(Box, { className: "col-span-full text-center py-8 text-[var(--color-muted-foreground)]", children: /* @__PURE__ */ jsx(Typography, { variant: "body", color: "secondary", children: "No items found" }) });
8102
8091
  }
8103
8092
  return normalizedData.map((item, index) => {
8104
8093
  const itemData = item;
@@ -8111,11 +8100,11 @@ var CardGrid = ({
8111
8100
  const value = getNestedValue(itemData, field);
8112
8101
  return value !== void 0 && value !== null ? String(value) : "";
8113
8102
  });
8114
- eventBus.emit("UI:NAVIGATE", { url, row: itemData, entity });
8103
+ eventBus.emit("UI:NAVIGATE", { url, row: itemData });
8115
8104
  return;
8116
8105
  }
8117
8106
  if (action.event) {
8118
- eventBus.emit(`UI:${action.event}`, { row: itemData, entity });
8107
+ eventBus.emit(`UI:${action.event}`, { row: itemData });
8119
8108
  }
8120
8109
  if (action.onClick) {
8121
8110
  action.onClick(itemData);
@@ -8195,32 +8184,25 @@ function MasterDetail({
8195
8184
  masterFields = [],
8196
8185
  detailFields: _detailFields,
8197
8186
  // Captured but not used here - detail handled separately
8198
- data: externalData,
8199
8187
  loading: externalLoading,
8200
8188
  isLoading: externalIsLoading,
8201
8189
  error: externalError,
8202
8190
  className,
8203
8191
  ...rest
8204
8192
  }) {
8205
- const shouldAutoFetch = !!entity && !externalData;
8206
- const { data: fetchedData, isLoading: fetchLoading, error: fetchError } = useEntityList(
8207
- shouldAutoFetch ? entity : void 0,
8208
- { skip: !shouldAutoFetch }
8209
- );
8210
- const data = externalData ?? fetchedData;
8211
- const loading = externalLoading ?? (shouldAutoFetch ? fetchLoading : false);
8212
- const isLoading = externalIsLoading ?? (shouldAutoFetch ? fetchLoading : false);
8213
- const error = externalError ?? (shouldAutoFetch ? fetchError : null);
8193
+ const loading = externalLoading ?? false;
8194
+ const isLoading = externalIsLoading ?? false;
8195
+ const error = externalError ?? null;
8214
8196
  return /* @__PURE__ */ jsx(
8215
8197
  DataTable,
8216
8198
  {
8217
8199
  columns: masterFields,
8218
- data,
8200
+ entity,
8219
8201
  isLoading: loading || isLoading,
8220
8202
  error,
8221
8203
  className,
8222
- emptyTitle: `No ${entity || "items"} found`,
8223
- emptyDescription: `Create your first ${entity?.toLowerCase() || "item"} to get started.`,
8204
+ emptyTitle: "No items found",
8205
+ emptyDescription: "Create your first item to get started.",
8224
8206
  ...rest
8225
8207
  }
8226
8208
  );