@wordrhyme/auto-crud 1.12.2 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { i as positionActions, n as compareOrder, r as matchesPosition, t as actionPositionSchema } from "./position--p6kJnYA.js";
2
2
  import * as React from "react";
3
- import { Fragment, forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
3
+ import { Fragment, createContext, forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
4
4
  import { ArrowDownUp, BadgeCheck, CalendarIcon, Check, CheckCircle2, ChevronDown, ChevronLeft, ChevronRight, ChevronRightIcon, ChevronUp, ChevronsLeft, ChevronsRight, ChevronsUpDown, CommandIcon, Download, Ellipsis, EyeOff, FileDown, FileSpreadsheetIcon, GripVertical, ListFilter, ListFilterIcon, Loader2, PlusCircle, RefreshCw, Settings2, Text, Trash2, Upload, X, XCircle } from "lucide-react";
5
5
  import { flexRender, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
6
6
  import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, Badge, Button, Calendar, Checkbox, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, Input, Label, Popover, PopoverContent, PopoverTrigger, Select as Select$1, SelectContent, SelectItem, SelectTrigger, SelectValue, Separator, Slider, Switch, Table as Table$1, TableBody, TableCell, TableHead, TableHeader, TableRow, cn as cn$1 } from "@wordrhyme/shadcn";
@@ -11,8 +11,9 @@ import { customAlphabet } from "nanoid";
11
11
  import { ActionBar, ActionBarClose, ActionBarGroup, ActionBarItem, ActionBarSelection, ActionBarSeparator, Faceted, FacetedBadgeList, FacetedContent, FacetedEmpty, FacetedGroup, FacetedInput, FacetedItem, FacetedList, FacetedTrigger, MultiCombobox, Select, Select as Select$2, Sortable, SortableContent, SortableItem, SortableItemHandle, SortableOverlay } from "@wordrhyme/shadcn-ui";
12
12
  import { AlertDialog as AlertDialog$1, AlertDialogAction as AlertDialogAction$1, AlertDialogCancel as AlertDialogCancel$1, AlertDialogContent as AlertDialogContent$1, AlertDialogDescription as AlertDialogDescription$1, AlertDialogFooter as AlertDialogFooter$1, AlertDialogHeader as AlertDialogHeader$1, AlertDialogTitle as AlertDialogTitle$1, Button as Button$1, Calendar as Calendar$1, Dialog as Dialog$1, DialogContent as DialogContent$1, DialogDescription as DialogDescription$1, DialogHeader as DialogHeader$1, DialogTitle as DialogTitle$1, DropdownMenu as DropdownMenu$1, DropdownMenuContent as DropdownMenuContent$1, DropdownMenuItem as DropdownMenuItem$1, DropdownMenuSeparator, DropdownMenuTrigger as DropdownMenuTrigger$1, Popover as Popover$1, PopoverContent as PopoverContent$1, PopoverTrigger as PopoverTrigger$1, Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@wordrhyme/ui";
13
13
  import { z } from "zod";
14
- import { DatePicker, Form, JsonSchemaField, connect, mapProps } from "@wordrhyme/formily-shadcn";
14
+ import { DatePicker, Form, JsonSchemaField, connect, defaultComponentRegistry, mapProps } from "@wordrhyme/formily-shadcn";
15
15
  import { createForm } from "@formily/core";
16
+ import { mapReadPretty, useField, useFieldSchema } from "@formily/react";
16
17
  import { action, observable } from "@formily/reactive";
17
18
  import { toast } from "sonner";
18
19
  import { keepPreviousData } from "@tanstack/react-query";
@@ -5463,6 +5464,7 @@ function FormModal({ open, onOpenChange, title, description, children, variant =
5463
5464
  open,
5464
5465
  onOpenChange,
5465
5466
  children: /* @__PURE__ */ jsxs(SheetContent, {
5467
+ ...!description ? { "aria-describedby": void 0 } : {},
5466
5468
  side,
5467
5469
  className: cn("sm:max-w-lg flex flex-col p-0", className),
5468
5470
  children: [
@@ -5488,6 +5490,7 @@ function FormModal({ open, onOpenChange, title, description, children, variant =
5488
5490
  open,
5489
5491
  onOpenChange,
5490
5492
  children: /* @__PURE__ */ jsxs(DialogContent$1, {
5493
+ ...!description ? { "aria-describedby": void 0 } : {},
5491
5494
  className: cn("max-w-2xl sm:max-w-2xl flex flex-col max-h-[85vh] overflow-hidden p-0", className),
5492
5495
  children: [
5493
5496
  /* @__PURE__ */ jsxs(DialogHeader$1, {
@@ -5609,6 +5612,8 @@ function createFormSchema(schema, options) {
5609
5612
  const inferredByName = inferComponentByFieldName(key);
5610
5613
  const component = inferredByName?.component ?? fieldTypeToFormilyComponent[parsed.type];
5611
5614
  const inferredProps = inferredByName?.props ?? {};
5615
+ const componentProps = getComponentProps(parsed.type, parsed);
5616
+ if (parsed.type === "enum" && override?.enum) componentProps.options = override.enum;
5612
5617
  properties[key] = {
5613
5618
  type: mapToJsonSchemaType(parsed.type),
5614
5619
  title: humanize$1(key),
@@ -5617,7 +5622,7 @@ function createFormSchema(schema, options) {
5617
5622
  "x-decorator-props": decoratorProps,
5618
5623
  "x-component": component,
5619
5624
  "x-component-props": {
5620
- ...getComponentProps(parsed.type, parsed),
5625
+ ...componentProps,
5621
5626
  ...inferredProps
5622
5627
  },
5623
5628
  ...parsed.enumValues && { enum: parsed.enumValues.map((v) => ({
@@ -5651,6 +5656,51 @@ function createEditFormSchema(schema, options) {
5651
5656
  });
5652
5657
  }
5653
5658
 
5659
+ //#endregion
5660
+ //#region src/components/auto-crud/read-pretty-field.tsx
5661
+ const ReadPrettyBooleanLocale = createContext(zhCN.boolean);
5662
+ const ReadPrettyRenderers = createContext({});
5663
+ function ReadPrettyField({ options }) {
5664
+ const field = useField();
5665
+ const schema = useFieldSchema();
5666
+ const renderCustomValue = useContext(ReadPrettyRenderers)[field.path.toString()];
5667
+ return renderCustomValue ? renderCustomValue() : /* @__PURE__ */ jsx(ReadPrettyValue, {
5668
+ value: field.value,
5669
+ options: options?.length ? options : field.dataSource,
5670
+ date: schema["x-component"] === "DatePicker"
5671
+ });
5672
+ }
5673
+ function ReadPrettyValue({ value, options: choices, date }) {
5674
+ const booleanLocale = useContext(ReadPrettyBooleanLocale);
5675
+ useDateFormatterVersion();
5676
+ const renderValue = (item) => {
5677
+ if (item == null || item === "") return /* @__PURE__ */ jsx("span", {
5678
+ className: "text-muted-foreground",
5679
+ children: "-"
5680
+ });
5681
+ const option = choices?.find((choice) => String(choice.value) === String(item));
5682
+ if (option) return Array.isArray(value) ? /* @__PURE__ */ jsx(Badge, {
5683
+ variant: "secondary",
5684
+ className: "font-normal",
5685
+ children: option.label
5686
+ }) : option.label;
5687
+ if (typeof item === "boolean") return item ? booleanLocale.true : booleanLocale.false;
5688
+ if (item instanceof Date || date) return formatDate(item);
5689
+ if (typeof item === "object") return /* @__PURE__ */ jsx("pre", {
5690
+ className: "rounded-md bg-muted/50 p-3 text-sm whitespace-pre-wrap break-words",
5691
+ children: JSON.stringify(item, null, 2)
5692
+ });
5693
+ return String(item);
5694
+ };
5695
+ return /* @__PURE__ */ jsx("div", {
5696
+ className: "min-w-0 whitespace-pre-wrap break-words text-base leading-6 text-foreground",
5697
+ children: Array.isArray(value) ? value.length ? /* @__PURE__ */ jsx("div", {
5698
+ className: "flex flex-wrap gap-2",
5699
+ children: value.map((item, index$1) => /* @__PURE__ */ jsx("span", { children: renderValue(item) }, index$1))
5700
+ }) : renderValue(null) : renderValue(value)
5701
+ });
5702
+ }
5703
+
5654
5704
  //#endregion
5655
5705
  //#region src/lib/crud-reference-projection.ts
5656
5706
  function isRecord$1(value) {
@@ -5799,12 +5849,8 @@ function normalizeFieldOptions$1(options) {
5799
5849
  * 从统一字段配置生成 Formily overrides。
5800
5850
  * `legacyOverrides` 保持兼容旧 API,字段级 `form` 配置优先级最高。
5801
5851
  */
5802
- function buildFormOverrides(fields, legacyOverrides, denyFields) {
5852
+ function buildFormOverrides(fields, legacyOverrides, denyFields, mode = "edit") {
5803
5853
  const result = { ...legacyOverrides };
5804
- if (denyFields) for (const field of denyFields) result[field] = {
5805
- ...result[field],
5806
- "x-hidden": true
5807
- };
5808
5854
  if (fields) for (const [key, config] of Object.entries(fields)) {
5809
5855
  const fieldOptions = normalizeFieldOptions$1((config.form && typeof config.form === "object" ? config.form : void 0)?.enum) ?? normalizeFieldOptions$1(config.enum);
5810
5856
  const fieldDataSource = fieldOptions || !config.dataSource ? void 0 : normalizeDataSourceConfig(config.dataSource);
@@ -5812,10 +5858,6 @@ function buildFormOverrides(fields, legacyOverrides, denyFields) {
5812
5858
  ...result[key],
5813
5859
  title: config.label
5814
5860
  };
5815
- if (config.hidden) result[key] = {
5816
- ...result[key],
5817
- "x-hidden": true
5818
- };
5819
5861
  if (fieldOptions) result[key] = {
5820
5862
  ...result[key],
5821
5863
  enum: fieldOptions
@@ -5824,15 +5866,27 @@ function buildFormOverrides(fields, legacyOverrides, denyFields) {
5824
5866
  ...result[key],
5825
5867
  "x-data-source": config.dataSource
5826
5868
  };
5827
- if (config.form === false) result[key] = {
5869
+ if (config.form === false && mode !== "view") result[key] = {
5828
5870
  ...result[key],
5829
5871
  "x-hidden": true
5830
5872
  };
5831
- else if (config.form && typeof config.form === "object") result[key] = {
5873
+ else if (config.form && typeof config.form === "object") {
5874
+ const { "x-hidden": formHidden,...sharedFormConfig } = config.form;
5875
+ result[key] = {
5876
+ ...result[key],
5877
+ ...sharedFormConfig,
5878
+ ...mode !== "view" && formHidden !== void 0 ? { "x-hidden": formHidden } : {}
5879
+ };
5880
+ }
5881
+ if (config.hidden) result[key] = {
5832
5882
  ...result[key],
5833
- ...config.form
5883
+ "x-hidden": true
5834
5884
  };
5835
5885
  }
5886
+ for (const field of denyFields ?? []) result[field] = {
5887
+ ...result[field],
5888
+ "x-hidden": true
5889
+ };
5836
5890
  return result;
5837
5891
  }
5838
5892
 
@@ -5895,6 +5949,13 @@ const defaultFieldComponents = {
5895
5949
  decorator: "FormItem"
5896
5950
  }
5897
5951
  };
5952
+ const readPrettyFieldComponents = Object.fromEntries(Object.entries({
5953
+ ...defaultComponentRegistry,
5954
+ ...defaultFieldComponents
5955
+ }).filter(([, config]) => "decorator" in config).map(([name, config]) => [name, {
5956
+ ...config,
5957
+ component: connect(config.component, mapReadPretty(ReadPrettyField))
5958
+ }]));
5898
5959
  const AUTO_CRUD_DATA_SOURCE_SCOPE_KEY = "$autoCrudDataSource";
5899
5960
  const POPUP_SCROLL_LOAD_THRESHOLD$1 = 24;
5900
5961
  const dataSourceReactionStates = /* @__PURE__ */ new WeakMap();
@@ -5923,7 +5984,8 @@ function mergeReactions(existing, reaction) {
5923
5984
  if (Array.isArray(existing)) return existing.includes(reaction) ? existing : [...existing, reaction];
5924
5985
  return [existing, reaction];
5925
5986
  }
5926
- function applyDataSourceReactions(schema) {
5987
+ function applyDataSourceReactions(schema, readPretty = false) {
5988
+ if (readPretty) schema["x-pattern"] = "readPretty";
5927
5989
  const dataSourceConfig = getSchemaDataSourceConfig(schema);
5928
5990
  if (dataSourceConfig) {
5929
5991
  const reaction = `{{${AUTO_CRUD_DATA_SOURCE_SCOPE_KEY}(${JSON.stringify(dataSourceConfig)})}}`;
@@ -5931,12 +5993,12 @@ function applyDataSourceReactions(schema) {
5931
5993
  }
5932
5994
  const properties = schema.properties;
5933
5995
  if (properties && typeof properties === "object" && !Array.isArray(properties)) {
5934
- for (const property of Object.values(properties)) if (property && typeof property === "object" && !Array.isArray(property)) applyDataSourceReactions(property);
5996
+ for (const property of Object.values(properties)) if (property && typeof property === "object" && !Array.isArray(property)) applyDataSourceReactions(property, readPretty);
5935
5997
  }
5936
5998
  const items = schema.items;
5937
5999
  if (Array.isArray(items)) {
5938
- for (const item of items) if (item && typeof item === "object") applyDataSourceReactions(item);
5939
- } else if (items && typeof items === "object") applyDataSourceReactions(items);
6000
+ for (const item of items) if (item && typeof item === "object") applyDataSourceReactions(item, readPretty);
6001
+ } else if (items && typeof items === "object") applyDataSourceReactions(items, readPretty);
5940
6002
  }
5941
6003
  function getDataSourceReactionState(field) {
5942
6004
  const existing = dataSourceReactionStates.get(field);
@@ -5981,7 +6043,7 @@ function loadAutoCrudDataSource({ entry, field, registryVersion, search, sourceK
5981
6043
  });
5982
6044
  setAutoCrudDataSourceOptions(field, state.options);
5983
6045
  if (!append && state.loadKey === loadKey && state.registryVersion === registryVersion) return;
5984
- if (entry.reset && state.dependencyKey !== void 0 && state.dependencyKey !== dependencyKey) field.setValue(void 0);
6046
+ if (entry.reset && !field.readPretty && state.dependencyKey !== void 0 && state.dependencyKey !== dependencyKey) field.setValue(void 0);
5985
6047
  state.dependencyKey = dependencyKey;
5986
6048
  if (!append) {
5987
6049
  state.loadKey = loadKey;
@@ -6157,7 +6219,10 @@ function createAutoCrudDataSourceReaction(config, registryState) {
6157
6219
  };
6158
6220
  }
6159
6221
  function AutoFormInner({ schema: zodSchema, initialValues, onSubmit, fields, overrides, scope: scopeProp, mode = "create", loading = false, gridColumns = 1, labelAlign = "top", labelWidth, showSubmitButton = true }, ref) {
6160
- const form = useMemo(() => createForm({ initialValues }), [JSON.stringify(initialValues)]);
6222
+ const form = useMemo(() => createForm({
6223
+ initialValues,
6224
+ pattern: mode === "view" ? "readPretty" : "editable"
6225
+ }), [JSON.stringify(initialValues), mode]);
6161
6226
  const dataSourceRegistryState = useMemo(() => observable({ version: 0 }), []);
6162
6227
  const updateDataSourceRegistryState = useCallback(() => {
6163
6228
  action(() => {
@@ -6165,40 +6230,75 @@ function AutoFormInner({ schema: zodSchema, initialValues, onSubmit, fields, ove
6165
6230
  });
6166
6231
  }, [dataSourceRegistryState]);
6167
6232
  const dataSourceRegistryVersion = useRegistryVersion$1(dataSources.subscribe, updateDataSourceRegistryState);
6168
- const formOverrides = useMemo(() => buildFormOverrides(fields, overrides), [fields, overrides]);
6233
+ const formOverrides = useMemo(() => buildFormOverrides(fields, overrides, void 0, mode), [
6234
+ fields,
6235
+ overrides,
6236
+ mode
6237
+ ]);
6169
6238
  const formSchema = useMemo(() => {
6170
- const nextSchema = createEditFormSchema(zodSchema, {
6239
+ const nextSchema = (mode === "view" ? createFormSchema : createEditFormSchema)(zodSchema, {
6171
6240
  overrides: formOverrides,
6172
6241
  layout: "grid",
6173
6242
  gridColumns
6174
6243
  });
6175
- applyDataSourceReactions(nextSchema);
6244
+ const grid = typeof nextSchema.properties === "object" ? nextSchema.properties.layout : void 0;
6245
+ if (mode === "view" && grid && typeof grid === "object") {
6246
+ grid["x-component-props"] = {
6247
+ ...grid["x-component-props"],
6248
+ className: cn$1(grid["x-component-props"]?.className, "gap-x-10 gap-y-7 py-2")
6249
+ };
6250
+ const properties = typeof grid.properties === "object" ? grid.properties : {};
6251
+ for (const property of Object.values(properties)) {
6252
+ const decoratorProps = property["x-decorator-props"];
6253
+ const fullWidth = property.type === "object" || property.type === "array" || ["Textarea", "RichTextEditor"].includes(property["x-component"]);
6254
+ property["x-decorator-props"] = {
6255
+ colon: false,
6256
+ ...decoratorProps,
6257
+ className: cn$1(fullWidth && decoratorProps?.gridSpan == null && "col-span-full", decoratorProps?.className)
6258
+ };
6259
+ }
6260
+ }
6261
+ applyDataSourceReactions(nextSchema, mode === "view");
6176
6262
  return nextSchema;
6177
6263
  }, [
6178
6264
  zodSchema,
6179
6265
  formOverrides,
6180
6266
  gridColumns,
6181
- dataSourceRegistryVersion
6267
+ dataSourceRegistryVersion,
6268
+ mode
6182
6269
  ]);
6183
6270
  const formLayout = useMemo(() => {
6184
6271
  const inlineLabel = labelAlign === "left" || labelAlign === "right";
6185
- return {
6186
- labelPlacement: inlineLabel ? "start" : "top",
6187
- itemProps: inlineLabel ? { label: {
6188
- className: labelAlign === "right" ? "text-right" : void 0,
6189
- style: labelWidth != null ? { width: labelWidth } : void 0
6190
- } } : void 0
6191
- };
6192
- }, [labelAlign, labelWidth]);
6272
+ return { itemProps: {
6273
+ container: mode === "view" ? { className: "min-w-0 space-y-0 gap-2" } : void 0,
6274
+ label: {
6275
+ placement: inlineLabel ? "start" : "top",
6276
+ className: cn$1(mode === "view" && "mb-0 text-sm font-normal text-muted-foreground leading-5", labelAlign === "right" && "text-right"),
6277
+ style: inlineLabel && labelWidth != null ? { width: labelWidth } : void 0
6278
+ }
6279
+ } };
6280
+ }, [
6281
+ labelAlign,
6282
+ labelWidth,
6283
+ mode
6284
+ ]);
6193
6285
  const fieldComponents = useMemo(() => ({ fields: {
6194
6286
  ...defaultFieldComponents,
6287
+ ...mode === "view" ? {
6288
+ ...readPrettyFieldComponents,
6289
+ ObjectField: {
6290
+ component: ReadPrettyField,
6291
+ decorator: "FormItem"
6292
+ }
6293
+ } : {},
6195
6294
  ...components.all()
6196
- } }), [useRegistryVersion$1(components.subscribe)]);
6295
+ } }), [useRegistryVersion$1(components.subscribe), mode]);
6197
6296
  const scope = useMemo(() => ({
6198
6297
  ...scopeProp,
6199
6298
  [AUTO_CRUD_DATA_SOURCE_SCOPE_KEY]: (config) => createAutoCrudDataSourceReaction(config, dataSourceRegistryState)
6200
6299
  }), [dataSourceRegistryState, scopeProp]);
6201
6300
  const handleSubmit = async () => {
6301
+ if (mode === "view" || !onSubmit) return;
6202
6302
  await form.validate();
6203
6303
  if (form.valid) await onSubmit(form.values);
6204
6304
  };
@@ -6210,7 +6310,7 @@ function AutoFormInner({ schema: zodSchema, initialValues, onSubmit, fields, ove
6210
6310
  schema: formSchema,
6211
6311
  components: fieldComponents,
6212
6312
  scope
6213
- }), showSubmitButton && /* @__PURE__ */ jsx("div", {
6313
+ }), mode !== "view" && showSubmitButton && /* @__PURE__ */ jsx("div", {
6214
6314
  className: "flex justify-end gap-2 mt-6",
6215
6315
  children: /* @__PURE__ */ jsx(Button, {
6216
6316
  type: "button",
@@ -6226,7 +6326,7 @@ const AutoForm = forwardRef(AutoFormInner);
6226
6326
  //#endregion
6227
6327
  //#region src/components/auto-crud/crud-form-modal.tsx
6228
6328
  function CrudFormModal({ open, onOpenChange, mode, schema, initialValues, onSubmit, loading = false, variant = "dialog", overrides, scope, title, locale = zhCN.formModal, gridColumns, labelAlign, labelWidth, className }) {
6229
- const defaultTitle = mode === "create" ? locale.createTitle : locale.editTitle;
6329
+ const defaultTitle = mode === "create" ? locale.createTitle : mode === "edit" ? locale.editTitle : zhCN.viewModal.title;
6230
6330
  const formRef = useRef(null);
6231
6331
  const handleSubmit = async () => {
6232
6332
  await formRef.current?.submit();
@@ -6237,7 +6337,7 @@ function CrudFormModal({ open, onOpenChange, mode, schema, initialValues, onSubm
6237
6337
  title: title ?? defaultTitle,
6238
6338
  variant,
6239
6339
  className,
6240
- footer: /* @__PURE__ */ jsxs("div", {
6340
+ footer: mode !== "view" ? /* @__PURE__ */ jsxs("div", {
6241
6341
  className: "flex justify-end gap-2",
6242
6342
  children: [/* @__PURE__ */ jsx(Button, {
6243
6343
  type: "button",
@@ -6250,14 +6350,16 @@ function CrudFormModal({ open, onOpenChange, mode, schema, initialValues, onSubm
6250
6350
  disabled: loading,
6251
6351
  children: loading ? locale.submitting : mode === "create" ? locale.create : locale.save
6252
6352
  })]
6253
- }),
6353
+ }) : void 0,
6254
6354
  children: /* @__PURE__ */ jsx(AutoForm, {
6255
6355
  ref: formRef,
6256
6356
  schema,
6257
- mode,
6357
+ ...mode === "view" ? { mode } : {
6358
+ mode,
6359
+ onSubmit
6360
+ },
6258
6361
  initialValues,
6259
6362
  loading,
6260
- onSubmit,
6261
6363
  overrides,
6262
6364
  scope,
6263
6365
  gridColumns,
@@ -7637,7 +7739,7 @@ function ViewModal(props) {
7637
7739
  if (!props.open || !props.data) return null;
7638
7740
  return /* @__PURE__ */ jsx(ViewModalContent, { ...props });
7639
7741
  }
7640
- function ViewModalContent({ open, onOpenChange, variant, data, schema, fields: fieldConfig, dynamicOptions, denyFields, locale, tableOverrides, view }) {
7742
+ function ViewModalContent({ open, onOpenChange, variant, data, schema, fields: fieldConfig, dynamicOptions, denyFields, locale, tableOverrides, view, form }) {
7641
7743
  const excluded = React.useMemo(() => {
7642
7744
  const denied = new Set(denyFields ?? []);
7643
7745
  return Object.keys(schema.shape).filter((key) => {
@@ -7652,70 +7754,82 @@ function ViewModalContent({ open, onOpenChange, variant, data, schema, fields: f
7652
7754
  ]);
7653
7755
  const rows = React.useMemo(() => data ? [data] : [], [data]);
7654
7756
  const resolvedOptions = useDynamicResolveOptions(fieldConfig, rows, excluded);
7655
- const content = /* @__PURE__ */ jsx("dl", {
7656
- className: "grid gap-4 py-4",
7657
- children: useReactTable({
7658
- data: rows,
7659
- columns: React.useMemo(() => {
7660
- const overrides = {};
7661
- for (const [key, fieldSchema] of Object.entries(schema.shape).filter(([fieldKey]) => !excluded.includes(fieldKey))) {
7662
- const config = fieldConfig?.[key] ?? {};
7663
- const tableConfig = getTableConfig(config);
7664
- const listOverride = tableOverrides?.[key];
7665
- const options = getTableOptions(config) ?? resolvedOptions.optionsByField[key] ?? (tableConfig?.dataSource !== void 0 ? void 0 : dynamicOptions?.[key]);
7666
- overrides[key] = {
7667
- label: tableConfig?.label ?? config.label ?? listOverride?.label ?? humanize(key),
7668
- index: tableConfig?.index ?? listOverride?.index,
7669
- cell: ({ getValue, row }) => {
7670
- const value = getValue();
7671
- return config.format?.(value, {
7672
- row: row.original,
7673
- target: "display"
7674
- }) ?? renderFieldValue(value, parseZodField(fieldSchema).type, locale.boolean, options, tableConfig?.display ?? "auto", Infinity);
7675
- },
7676
- ...view?.presentation === "table" ? listOverride : void 0,
7677
- hidden: false,
7678
- ...view?.overrides?.[key]
7679
- };
7680
- }
7681
- return createTableSchema(schema, {
7682
- overrides,
7683
- exclude: excluded
7684
- });
7685
- }, [
7686
- schema,
7687
- excluded,
7688
- fieldConfig,
7689
- tableOverrides,
7690
- view,
7691
- resolvedOptions.optionsByField,
7692
- dynamicOptions,
7693
- locale.boolean
7694
- ]),
7695
- getCoreRowModel: getCoreRowModel()
7696
- }).getRowModel().rows[0]?.getAllCells().map((cell) => /* @__PURE__ */ jsxs("div", {
7697
- className: "grid grid-cols-3 items-start gap-4",
7698
- children: [/* @__PURE__ */ jsx("dt", {
7699
- className: "text-sm font-medium text-muted-foreground",
7700
- children: cell.column.columnDef.meta?.label ?? humanize(cell.column.id)
7701
- }), /* @__PURE__ */ jsx("dd", {
7702
- className: "col-span-2 min-w-0 whitespace-pre-wrap break-words text-sm",
7703
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
7704
- })]
7705
- }, cell.id))
7706
- });
7707
- if (variant === "sheet") return /* @__PURE__ */ jsx(Sheet, {
7708
- open,
7709
- onOpenChange,
7710
- children: /* @__PURE__ */ jsxs(SheetContent, { children: [/* @__PURE__ */ jsx(SheetHeader, { children: /* @__PURE__ */ jsx(SheetTitle, { children: locale.viewModal.title }) }), content] })
7757
+ const table = useReactTable({
7758
+ data: rows,
7759
+ columns: React.useMemo(() => {
7760
+ const overrides$1 = {};
7761
+ for (const [key, fieldSchema] of Object.entries(schema.shape).filter(([fieldKey]) => !excluded.includes(fieldKey))) {
7762
+ const config = fieldConfig?.[key] ?? {};
7763
+ const tableConfig = getTableConfig(config);
7764
+ const listOverride = tableOverrides?.[key];
7765
+ const options = getTableOptions(config) ?? resolvedOptions.optionsByField[key] ?? (tableConfig?.dataSource !== void 0 ? void 0 : dynamicOptions?.[key]);
7766
+ overrides$1[key] = {
7767
+ label: tableConfig?.label ?? config.label ?? listOverride?.label ?? humanize(key),
7768
+ index: tableConfig?.index ?? listOverride?.index,
7769
+ cell: ({ getValue, row }) => {
7770
+ const value = getValue();
7771
+ return config.format?.(value, {
7772
+ row: row.original,
7773
+ target: "display"
7774
+ }) ?? (tableConfig?.display && tableConfig.display !== "auto" || options?.some((option) => option.badgeTone) ? renderFieldValue(value, parseZodField(fieldSchema).type, locale.boolean, options, tableConfig?.display ?? "auto", Infinity) : /* @__PURE__ */ jsx(ReadPrettyValue, {
7775
+ value,
7776
+ options,
7777
+ date: parseZodField(fieldSchema).type === "date"
7778
+ }));
7779
+ },
7780
+ ...view?.presentation === "table" ? listOverride : void 0,
7781
+ hidden: false,
7782
+ ...view?.overrides?.[key]
7783
+ };
7784
+ }
7785
+ return createTableSchema(schema, {
7786
+ overrides: overrides$1,
7787
+ exclude: excluded
7788
+ });
7789
+ }, [
7790
+ schema,
7791
+ excluded,
7792
+ fieldConfig,
7793
+ tableOverrides,
7794
+ view,
7795
+ resolvedOptions.optionsByField,
7796
+ dynamicOptions,
7797
+ locale.boolean
7798
+ ]),
7799
+ getCoreRowModel: getCoreRowModel()
7711
7800
  });
7712
- return /* @__PURE__ */ jsx(Dialog$1, {
7713
- open,
7714
- onOpenChange,
7715
- children: /* @__PURE__ */ jsxs(DialogContent$1, {
7716
- "aria-describedby": void 0,
7717
- className: "max-w-2xl max-h-[80vh] overflow-y-auto",
7718
- children: [/* @__PURE__ */ jsx(DialogHeader$1, { children: /* @__PURE__ */ jsx(DialogTitle$1, { children: locale.viewModal.title }) }), content]
7801
+ const detailSchema = React.useMemo(() => schema.omit(Object.fromEntries(excluded.map((key) => [key, true]))), [schema, excluded]);
7802
+ const overrides = buildFormOverrides(fieldConfig, form?.overrides, denyFields, "view");
7803
+ const renderers = {};
7804
+ for (const [index$1, cell] of (table.getRowModel().rows[0]?.getAllCells() ?? []).entries()) {
7805
+ const key = cell.column.id;
7806
+ overrides[key] = {
7807
+ ...overrides[key],
7808
+ title: cell.column.columnDef.meta?.label ?? humanize(key),
7809
+ "x-index": index$1
7810
+ };
7811
+ renderers[key] = () => flexRender(cell.column.columnDef.cell, cell.getContext());
7812
+ delete overrides[key]["x-data-source"];
7813
+ }
7814
+ return /* @__PURE__ */ jsx(ReadPrettyBooleanLocale.Provider, {
7815
+ value: locale.boolean,
7816
+ children: /* @__PURE__ */ jsx(ReadPrettyRenderers.Provider, {
7817
+ value: renderers,
7818
+ children: /* @__PURE__ */ jsx(CrudFormModal, {
7819
+ open,
7820
+ onOpenChange,
7821
+ mode: "view",
7822
+ variant,
7823
+ schema: detailSchema,
7824
+ initialValues: data ?? void 0,
7825
+ overrides,
7826
+ scope: form?.scope,
7827
+ title: locale.viewModal.title,
7828
+ gridColumns: form?.columns,
7829
+ labelAlign: form?.labelAlign,
7830
+ labelWidth: form?.labelWidth,
7831
+ className: form?.className
7832
+ })
7719
7833
  })
7720
7834
  });
7721
7835
  }
@@ -8220,6 +8334,8 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
8220
8334
  scope: formConfig?.scope,
8221
8335
  locale: locale.formModal,
8222
8336
  gridColumns: formConfig?.columns,
8337
+ labelAlign: formConfig?.labelAlign,
8338
+ labelWidth: formConfig?.labelWidth,
8223
8339
  className: formConfig?.className
8224
8340
  }),
8225
8341
  /* @__PURE__ */ jsx(ViewModal, {
@@ -8233,7 +8349,8 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
8233
8349
  denyFields,
8234
8350
  locale,
8235
8351
  tableOverrides: detailTableOverrides,
8236
- view: viewConfig
8352
+ view: viewConfig,
8353
+ form: formConfig
8237
8354
  }),
8238
8355
  /* @__PURE__ */ jsx(AlertDialog$1, {
8239
8356
  open: resource.modal.deleteOpen,