@object-ui/fields 4.0.7 → 4.0.9

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,11 @@
1
1
  import { default as React } from 'react';
2
2
  import { FieldMetadata } from '../../types/src';
3
+ /**
4
+ * Heuristic: detect strings that look like opaque foreign-key IDs (e.g. nanoid
5
+ * or BSON ObjectId). Used so we don't display random gibberish to users when
6
+ * a lookup wasn't expanded.
7
+ */
8
+ export declare function isLikelyOpaqueId(v: unknown): boolean;
3
9
  /**
4
10
  * Cell renderer props
5
11
  */
@@ -25,6 +31,12 @@ export declare function formatCurrency(value: number, currency?: string): string
25
31
  * E.g., $150,000 → $150K, $1,200,000 → $1.2M
26
32
  */
27
33
  export declare function formatCompactCurrency(value: number, currency?: string): string;
34
+ /**
35
+ * Format a plain number with thousands separators, no currency symbol.
36
+ * Used as a safe fallback when a currency-typed field has no `currency`
37
+ * configured — we'd rather render `1,234.50` than silently assume USD.
38
+ */
39
+ export declare function formatNumber(value: number, decimals?: number): string;
28
40
  /**
29
41
  * Format percent value
30
42
  * Handles both decimal (0.8 = 80%) and whole number (80 = 80%) inputs.
@@ -43,15 +55,15 @@ export declare function humanizeLabel(value: string): string;
43
55
  /**
44
56
  * Format date as relative time (e.g., "2 days ago", "Today", "Overdue 3d")
45
57
  */
46
- export declare function formatRelativeDate(value: string | Date): string;
58
+ export declare function formatRelativeDate(value: string | Date | number): string;
47
59
  /**
48
60
  * Format date value
49
61
  */
50
- export declare function formatDate(value: string | Date, style?: string): string;
62
+ export declare function formatDate(value: string | Date | number, style?: string): string;
51
63
  /**
52
64
  * Format datetime value
53
65
  */
54
- export declare function formatDateTime(value: string | Date): string;
66
+ export declare function formatDateTime(value: string | Date | number): string;
55
67
  /**
56
68
  * Text field cell renderer
57
69
  */
@@ -82,8 +94,35 @@ export declare function DateCellRenderer({ value, field }: CellRendererProps): R
82
94
  * DateTime field cell renderer (Airtable-style with date and time visually separated)
83
95
  */
84
96
  export declare function DateTimeCellRenderer({ value }: CellRendererProps): React.ReactElement;
97
+ export declare function getBadgeColorClasses(color?: string, val?: unknown): string;
98
+ /**
99
+ * Resolve a semantic color name (e.g. "red", "green") for a value, suitable
100
+ * for callers that need a raw color token rather than CSS classes (for
101
+ * example, the Gantt renderer paints bars via inline styles).
102
+ *
103
+ * Resolution order: explicit option color → semantic value mapping →
104
+ * deterministic hash fallback. Returns `undefined` only when no value is
105
+ * supplied so the caller can fall back to its own default.
106
+ */
107
+ export declare function getSemanticColorName(color?: string, val?: unknown): string | undefined;
85
108
  /**
86
- * Select field cell renderer (with badges)
109
+ * Map a semantic color name to its Tailwind -500 hex value. Used by
110
+ * inline-style consumers (Gantt bars). Falls back to the supplied default
111
+ * (or the platform default blue) when the name is unrecognized.
112
+ */
113
+ export declare function getSemanticHex(name?: string, fallback?: string): string;
114
+ /**
115
+ * Select field cell renderer.
116
+ *
117
+ * Two visual styles, controlled by `field.appearance` (renderer-level option,
118
+ * not part of the `@objectstack/spec` field schema):
119
+ * - `'badge'` (default for spec compatibility): soft-pill colored badge.
120
+ * - `'dot'`: a small colored dot followed by the option label. Used by
121
+ * dense list/grid contexts to keep the table visually quiet — repeated
122
+ * filled badges across many rows create heavy visual noise.
123
+ *
124
+ * Metadata always wins: callers can pass `appearance: 'badge'` on the field
125
+ * descriptor to force the legacy badge in any context.
87
126
  */
88
127
  export declare function SelectCellRenderer({ value, field }: CellRendererProps): React.ReactElement;
89
128
  /**
@@ -107,7 +146,14 @@ export declare function FileCellRenderer({ value, field }: CellRendererProps): R
107
146
  */
108
147
  export declare function ImageCellRenderer({ value }: CellRendererProps): React.ReactElement;
109
148
  /**
110
- * Lookup/Master-Detail field cell renderer
149
+ * Lookup/Master-Detail field cell renderer.
150
+ *
151
+ * Display order:
152
+ * 1. Embedded record object (`{ id, name, ... }` from `$expand`) → use its name
153
+ * 2. Static `field.options[]` (e.g. when the lookup is a closed enum) → look up label
154
+ * 3. Fetch-on-demand: when the value is a primitive ID and `field.reference_to`
155
+ * is known, resolve via dataSource and show the related record's display name.
156
+ * Falls back to a muted placeholder while pending and on failure.
111
157
  */
112
158
  export declare function LookupCellRenderer({ value, field }: CellRendererProps): React.ReactElement;
113
159
  /**
@@ -124,6 +170,16 @@ export declare function UserCellRenderer({ value }: CellRendererProps): React.Re
124
170
  * @param renderer React component to render the field
125
171
  */
126
172
  export declare function registerFieldRenderer(type: string, renderer: React.FC<CellRendererProps>): void;
173
+ /**
174
+ * Resolve the canonical cell-renderer key for a field. Accepts either a
175
+ * raw type string (back-compat) or a field-metadata object so that
176
+ * format hints (`format: 'phone'` etc.) can promote a plain `text`
177
+ * field to its richer renderer counterpart.
178
+ */
179
+ export declare function resolveCellRendererType(fieldOrType: string | {
180
+ type?: string;
181
+ format?: string;
182
+ } | null | undefined): string;
127
183
  /**
128
184
  * Get the appropriate cell renderer for a field type
129
185
  */
@@ -91,6 +91,14 @@ export interface RecordPickerDialogProps {
91
91
  columns?: Array<string | LookupColumnDef>;
92
92
  /** Primary display field (default: 'name') */
93
93
  displayField?: string;
94
+ /**
95
+ * Optional `titleFormat` template (e.g. `"{full_name}"` or
96
+ * `"{case_number} - {subject}"`). When set and the displayField column is
97
+ * auto-inferred, the column renders via the template instead of reading
98
+ * a possibly-missing field. Mirrors how DetailView/ObjectCalendar resolve
99
+ * record titles.
100
+ */
101
+ titleFormat?: string | null;
94
102
  /** Record id field (default: 'id') */
95
103
  idField?: string;
96
104
  /** Page size (default: 10) */
@@ -163,4 +171,4 @@ export interface RecordPickerDialogProps {
163
171
  * states, and single/multi-select. Responsive: mobile-friendly width
164
172
  * via Tailwind breakpoints.
165
173
  */
166
- export declare function RecordPickerDialog({ open, onOpenChange, title, multiple, dataSource, objectName, columns: columnsProp, displayField, idField, pageSize, value, onSelect, onSelectRecords, lookupFilters, cellRenderer, filterColumns, renderFilterBar, renderGrid, }: RecordPickerDialogProps): import("react/jsx-runtime").JSX.Element;
174
+ export declare function RecordPickerDialog({ open, onOpenChange, title, multiple, dataSource, objectName, columns: columnsProp, displayField, titleFormat, idField, pageSize, value, onSelect, onSelectRecords, lookupFilters, cellRenderer, filterColumns, renderFilterBar, renderGrid, }: RecordPickerDialogProps): import("react/jsx-runtime").JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@object-ui/fields",
3
- "version": "4.0.7",
3
+ "version": "4.0.9",
4
4
  "description": "Field renderers and registry for Object UI",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,13 +26,13 @@
26
26
  "dependencies": {
27
27
  "clsx": "^2.1.1",
28
28
  "lucide-react": "^1.14.0",
29
- "tailwind-merge": "^3.5.0",
30
- "@object-ui/components": "4.0.7",
31
- "@object-ui/core": "4.0.7",
32
- "@object-ui/i18n": "4.0.7",
33
- "@object-ui/providers": "4.0.7",
34
- "@object-ui/react": "4.0.7",
35
- "@object-ui/types": "4.0.7"
29
+ "tailwind-merge": "^3.6.0",
30
+ "@object-ui/components": "4.0.9",
31
+ "@object-ui/core": "4.0.9",
32
+ "@object-ui/i18n": "4.0.9",
33
+ "@object-ui/providers": "4.0.9",
34
+ "@object-ui/react": "4.0.9",
35
+ "@object-ui/types": "4.0.9"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "react": "^18.0.0 || ^19.0.0",
@@ -43,7 +43,7 @@
43
43
  "@types/react-dom": "19.2.3",
44
44
  "@vitejs/plugin-react": "^6.0.1",
45
45
  "typescript": "^6.0.3",
46
- "vite": "^8.0.10",
46
+ "vite": "^8.0.12",
47
47
  "vite-plugin-dts": "^5.0.0"
48
48
  },
49
49
  "publishConfig": {