@asteby/metacore-runtime-react 49.10.0 → 49.12.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/CHANGELOG.md +26 -0
- package/README.md +40 -0
- package/dist/column-filter-field.d.ts +21 -0
- package/dist/column-filter-field.d.ts.map +1 -0
- package/dist/column-filter-field.js +51 -0
- package/dist/dialogs/dynamic-record.d.ts +5 -2
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +96 -14
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +11 -1
- package/dist/dynamic-form.d.ts.map +1 -1
- package/dist/dynamic-form.js +10 -2
- package/dist/dynamic-icon.d.ts +16 -1
- package/dist/dynamic-icon.d.ts.map +1 -1
- package/dist/dynamic-icon.js +36 -5
- package/dist/dynamic-multi-select-field.d.ts +13 -1
- package/dist/dynamic-multi-select-field.d.ts.map +1 -1
- package/dist/dynamic-multi-select-field.js +19 -4
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +2 -1
- package/dist/field-widget-registry.d.ts +35 -0
- package/dist/field-widget-registry.d.ts.map +1 -0
- package/dist/field-widget-registry.js +66 -0
- package/dist/icon-aliases.d.ts +2 -0
- package/dist/icon-aliases.d.ts.map +1 -0
- package/dist/icon-aliases.js +594 -0
- package/dist/icon-resolvers.d.ts +13 -0
- package/dist/icon-resolvers.d.ts.map +1 -0
- package/dist/icon-resolvers.js +36 -0
- package/dist/icon-spec.d.ts +17 -0
- package/dist/icon-spec.d.ts.map +1 -0
- package/dist/icon-spec.js +165 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/column-filter-field.test.ts +105 -0
- package/src/__tests__/dynamic-record-field-types.test.tsx +221 -0
- package/src/__tests__/field-widget-registry.test.tsx +165 -0
- package/src/__tests__/icon-component.test.tsx +145 -0
- package/src/__tests__/icon-spec.test.ts +155 -0
- package/src/column-filter-field.ts +66 -0
- package/src/dialogs/dynamic-record.tsx +145 -13
- package/src/dynamic-columns.tsx +22 -1
- package/src/dynamic-form.tsx +12 -1
- package/src/dynamic-icon.tsx +68 -3
- package/src/dynamic-multi-select-field.tsx +29 -4
- package/src/dynamic-table.tsx +2 -1
- package/src/field-widget-registry.tsx +98 -0
- package/src/icon-aliases.ts +602 -0
- package/src/icon-resolvers.ts +59 -0
- package/src/icon-spec.ts +169 -0
- package/src/index.ts +12 -0
- package/src/types.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @asteby/metacore-runtime-react
|
|
2
2
|
|
|
3
|
+
## 49.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3136af6: Resolutor universal de íconos: `parseIconSpec` (Lucide en 4 formas, clases FontAwesome 5/6 vía tabla de alias propia, otras fuentes/Iconify, emoji, imágenes seguras), `registerIconResolver` para que el host enchufe FontAwesome/Iconify/sprites, componente `Icon` y columna `type: 'icon'` en tabla y detalle. `DynamicIcon` conserva su firma y ahora interpreta también esos formatos; los nombres Lucide resuelven igual que antes.
|
|
8
|
+
|
|
9
|
+
## 49.11.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 85042b0: `DynamicTable` ahora respeta `ColumnDefinition.filterField` (y `filter_field`) en el filtro de cabecera: una columna de display de relación (p. ej. `institution_type.name`) filtra por su campo persistido (`institution_type_id`) y adopta las opciones de ese campo cuando las tiene. Aditivo: sin `filterField`, o igual a la key, el comportamiento no cambia.
|
|
14
|
+
|
|
15
|
+
Cambio de contrato a notar: en hosts cuya metadata declare `filterField`, el parámetro `f_*` enviado al backend pasa de la key de la columna a la FK (`f_institution_type_id`), que es lo buscado. Los hosts que lo parcheaban localmente (p. ej. `applyMetadataFilterFields`) pueden borrar el parche.
|
|
16
|
+
|
|
17
|
+
Matiz: si la columna con `filterField` no tiene una config propia de opciones para ese campo, conserva sus opciones de display, que pueden ser nombres y no IDs (posible discrepancia valor/FK frente al `f_*` enviado). En ese caso la selección se lee de la clave del `filterField` en los filtros dinámicos, no de la del display. El `f_*` enviado siempre pasa a ser la FK.
|
|
18
|
+
|
|
19
|
+
- 2d51625: Registro de widgets de campo: `registerFieldWidget(name, component)` (devuelve disposer), `getFieldWidget`, `listFieldWidgets`, `clearFieldWidgets`, el hook `useFieldWidgetRegistryVersion` y los tipos `FieldWidgetProps` (`field`, `value`, `onChange`, `disabled`, `error`, `record`) y `FieldWidgetComponent`. `DynamicForm` y `DynamicRecordDialog` consultan el registro con el `widget` servido por el kernel (`FieldDef.Widget`) antes del render por `type`, de modo que un host enchufa mapas, horarios u otros editores propios. Un nombre sin registrar deja el comportamiento actual intacto.
|
|
20
|
+
|
|
21
|
+
Atención: un widget registrado tiene prioridad sobre los widgets built-in del SDK con el mismo nombre (`upload`, `icon`, `dynamic_select`); registrar uno con ese nombre reemplaza el render del SDK para esos campos.
|
|
22
|
+
|
|
23
|
+
`FieldWidgetProps.record` son los valores vivos del form en `DynamicForm` (también en modo crear) y el registro cargado/en edición en el diálogo.
|
|
24
|
+
|
|
25
|
+
- 28c5db8: DynamicRecordDialog: el renderer cubre los tipos `password` (nunca se prellena ni se muestra; vacío = no se envía), `phone`/`tel`, `checkbox`, `time`, `hidden` (no se renderiza, sí va en el payload con su default), `multiselect` (ref/searchEndpoint o `options` estáticas vía `staticOptions` en DynamicMultiSelectField) y `file` (UploadField). Los tipos existentes no cambian.
|
|
26
|
+
|
|
27
|
+
Al editar, un `password` vacío ya no entra al gate de `required` (vacío = no cambiar), tanto al guardar como en "Siguiente" del wizard; al crear sigue siendo obligatorio. Comportamiento fijado con test: un campo `hidden` con `visible_when` siempre se omite del payload (no se evalúa el predicado), y un `hidden` sin `visible_when` viaja con su default. Deuda conocida: hay dos resolvers de campos (`EditField` del diálogo y `resolveWidget` de dynamic-form).
|
|
28
|
+
|
|
3
29
|
## 49.10.0
|
|
4
30
|
|
|
5
31
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -35,6 +35,46 @@ Peers: `react`, `react-dom`, `react-i18next`, `i18next`, `@tanstack/react-router
|
|
|
35
35
|
| `isLicenseOperable` / `isLicenseBlocking` / `isPresetEntitled` / `isTrialExpired` | Helpers puros sobre `LicenseState`, espejo de `State.Operable()/Blocking()` del backend. |
|
|
36
36
|
| `<RealtimeProvider client={…} />` / `useRealtime()` / `useRealtimeInvalidate()` / `useRealtimeStatus()` / `useRealtimeTick()` | Reacción en vivo a `DATA_EVENT` del host (ver [Realtime](#realtime)). |
|
|
37
37
|
|
|
38
|
+
## Íconos
|
|
39
|
+
|
|
40
|
+
`<Icon name={value} />` (y `DynamicIcon`, que conserva su firma `{ name, className }`)
|
|
41
|
+
interpreta cualquier valor de ícono que un backend haya guardado. La clasificación
|
|
42
|
+
es `parseIconSpec(value)`, una función pura que devuelve
|
|
43
|
+
`{ kind: 'lucide', name } | { kind: 'emoji', value } | { kind: 'image', src } | { kind: 'unknown', raw }`.
|
|
44
|
+
|
|
45
|
+
| Formato | Ejemplos | Resultado |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| Lucide | `Brain`, `credit-card`, `credit_card`, `BrainIcon` | glifo Lucide |
|
|
48
|
+
| FontAwesome 5/6 | `fas fa-brain`, `fa-solid fa-brain`, `far fa-heart`, `fa fa-user-md`, `fa-brain` | glifo Lucide vía tabla `FONT_AWESOME_ALIASES` + prueba del nombre en Lucide |
|
|
49
|
+
| Otras fuentes | `mdi mdi-home`, `bi bi-house`, `ti ti-home`, `ri-home-line`, `mdi:home`, `material-icons home` | solo normalización contra Lucide (sin tabla) |
|
|
50
|
+
| Emoji | `🩺`, `👨⚕️`, `🇲🇽` | un solo grafema emoji (`Intl.Segmenter` si existe) |
|
|
51
|
+
| Imagen | `https://…`, `/ruta.png`, `./a.svg`, `uploads/a.png`, `data:image/(png\|jpeg\|webp\|gif\|svg+xml)` | `<img alt="" loading="lazy">`, se oculta si falla |
|
|
52
|
+
| Otro | `javascript:…`, `data:text/html`, SVG inline, texto libre | `unknown`: no se pinta texto crudo (null o la prop `fallback`) |
|
|
53
|
+
|
|
54
|
+
Lucide no incluye logos de marca (github, twitter…): las marcas (`fab fa-github`) quedan
|
|
55
|
+
`unknown` salvo que el host registre un resolutor.
|
|
56
|
+
|
|
57
|
+
**Orden de resolución:** (1) resolutores del host, el registrado más recientemente primero;
|
|
58
|
+
el primero que devuelve algo distinto de `null` gana; (2) el parser integrado.
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { registerIconResolver } from '@asteby/metacore-runtime-react'
|
|
62
|
+
|
|
63
|
+
// Al arrancar el host. Devuelve un IconSpec (reusa los renderers del SDK),
|
|
64
|
+
// un ReactNode (se pinta tal cual) o null para ceder.
|
|
65
|
+
const dispose = registerIconResolver((spec) =>
|
|
66
|
+
spec.startsWith('sprite:') ? <svg><use href={`/sprite.svg#${spec.slice(7)}`} /></svg> : null,
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Columnas:** `type: 'icon'` en la metadata de una columna pinta el valor con el resolutor
|
|
71
|
+
(tabla y detalle). Es opt-in: una columna de texto llamada `icon` no cambia. Un valor que
|
|
72
|
+
no se entiende muestra `-`.
|
|
73
|
+
|
|
74
|
+
`DynamicIcon` (menús, botones de acción) no pinta imágenes, solo glifos/emoji/nodos del host; para imágenes usa `<Icon>` o una columna `type: 'icon'`.
|
|
75
|
+
|
|
76
|
+
**Accesibilidad:** los íconos son decorativos (`aria-hidden`) salvo que se pase `label`.
|
|
77
|
+
|
|
38
78
|
## Realtime
|
|
39
79
|
|
|
40
80
|
El host expone un `RealtimeAPI` (`@asteby/metacore-sdk`) — en ops viaja como
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ColumnFilterConfig } from './dynamic-columns-shim';
|
|
2
|
+
interface FilterFieldColumn {
|
|
3
|
+
key?: string;
|
|
4
|
+
filterField?: string;
|
|
5
|
+
/** snake_case spelling emitted by some kernels. */
|
|
6
|
+
filter_field?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Honors `ColumnDefinition.filterField`: a display column (e.g.
|
|
10
|
+
* `institution_type.name`) filters by its persisted field (`institution_type_id`).
|
|
11
|
+
* The header filter keeps living on the display column, but its `filterKey` —
|
|
12
|
+
* and therefore the `f_*` param sent to the backend — becomes the filterField.
|
|
13
|
+
* When the filterField has its own option source (static options, searchEndpoint
|
|
14
|
+
* or loader) the column adopts it, so options are the FK values. A column whose filterField has no config of its own keeps its display options
|
|
15
|
+
* (which may be names, not FK ids) while its selection is read from the
|
|
16
|
+
* filterField key. Columns without
|
|
17
|
+
* `filterField` (or equal to their key) are returned untouched.
|
|
18
|
+
*/
|
|
19
|
+
export declare function applyColumnFilterFields(columns: readonly FilterFieldColumn[] | undefined, configs: Map<string, ColumnFilterConfig>, dynamicFilters?: Record<string, string[]>): Map<string, ColumnFilterConfig>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=column-filter-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"column-filter-field.d.ts","sourceRoot":"","sources":["../src/column-filter-field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAEhE,UAAU,iBAAiB;IACvB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACnC,OAAO,EAAE,SAAS,iBAAiB,EAAE,GAAG,SAAS,EACjD,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EACxC,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAM,GAC9C,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAyCjC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Honors `ColumnDefinition.filterField`: a display column (e.g.
|
|
3
|
+
* `institution_type.name`) filters by its persisted field (`institution_type_id`).
|
|
4
|
+
* The header filter keeps living on the display column, but its `filterKey` —
|
|
5
|
+
* and therefore the `f_*` param sent to the backend — becomes the filterField.
|
|
6
|
+
* When the filterField has its own option source (static options, searchEndpoint
|
|
7
|
+
* or loader) the column adopts it, so options are the FK values. A column whose filterField has no config of its own keeps its display options
|
|
8
|
+
* (which may be names, not FK ids) while its selection is read from the
|
|
9
|
+
* filterField key. Columns without
|
|
10
|
+
* `filterField` (or equal to their key) are returned untouched.
|
|
11
|
+
*/
|
|
12
|
+
export function applyColumnFilterFields(columns, configs, dynamicFilters = {}) {
|
|
13
|
+
if (!columns?.length)
|
|
14
|
+
return configs;
|
|
15
|
+
let resolved = null;
|
|
16
|
+
for (const column of columns) {
|
|
17
|
+
if (!column.key)
|
|
18
|
+
continue;
|
|
19
|
+
const filterField = column.filterField || column.filter_field;
|
|
20
|
+
if (!filterField || filterField === column.key)
|
|
21
|
+
continue;
|
|
22
|
+
const displayConfig = configs.get(column.key);
|
|
23
|
+
if (!displayConfig)
|
|
24
|
+
continue;
|
|
25
|
+
const fieldConfig = configs.get(filterField);
|
|
26
|
+
const fieldHasOwnOptions = Boolean(fieldConfig &&
|
|
27
|
+
(fieldConfig.options.length > 0 ||
|
|
28
|
+
fieldConfig.searchEndpoint ||
|
|
29
|
+
fieldConfig.loadOptions));
|
|
30
|
+
resolved ??= new Map(configs);
|
|
31
|
+
resolved.set(column.key, {
|
|
32
|
+
...displayConfig,
|
|
33
|
+
...(fieldConfig && fieldHasOwnOptions
|
|
34
|
+
? {
|
|
35
|
+
filterType: fieldConfig.filterType,
|
|
36
|
+
options: fieldConfig.options,
|
|
37
|
+
loading: fieldConfig.loading,
|
|
38
|
+
searchEndpoint: fieldConfig.searchEndpoint,
|
|
39
|
+
loadOptions: fieldConfig.loadOptions,
|
|
40
|
+
}
|
|
41
|
+
: {}),
|
|
42
|
+
filterKey: filterField,
|
|
43
|
+
// Sin config propia del campo, la selección vive bajo la key del filterField.
|
|
44
|
+
selectedValues: fieldConfig
|
|
45
|
+
? (fieldConfig.selectedValues ?? displayConfig.selectedValues)
|
|
46
|
+
: (dynamicFilters[filterField] ?? []),
|
|
47
|
+
onFilterChange: fieldConfig?.onFilterChange ?? displayConfig.onFilterChange,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return resolved ?? configs;
|
|
51
|
+
}
|
|
@@ -20,7 +20,7 @@ export interface FieldOption {
|
|
|
20
20
|
export interface FieldDef {
|
|
21
21
|
key: string;
|
|
22
22
|
label: string;
|
|
23
|
-
type: 'text' | 'textarea' | 'select' | 'search' | 'number' | 'date' | 'email' | 'url' | 'boolean' | 'image' | string;
|
|
23
|
+
type: 'text' | 'textarea' | 'select' | 'search' | 'number' | 'date' | 'email' | 'url' | 'boolean' | 'image' | 'password' | 'phone' | 'tel' | 'checkbox' | 'time' | 'hidden' | 'multiselect' | 'file' | string;
|
|
24
24
|
required?: boolean;
|
|
25
25
|
options?: FieldOption[];
|
|
26
26
|
defaultValue?: any;
|
|
@@ -204,6 +204,7 @@ export declare function fkSeedOption(field: FieldDef, value: any, record: any):
|
|
|
204
204
|
export declare function isMoneyField(field: FieldDef, value: any): boolean;
|
|
205
205
|
export declare function filterVisibleFields(fields: FieldDef[] | undefined, mode: 'view' | 'edit' | 'create', formValues?: Record<string, any>, attributeClasses?: string[]): FieldDef[];
|
|
206
206
|
export declare function stripHiddenFieldValues(values: Record<string, any>, fields: FieldDef[] | undefined, mode: 'view' | 'edit' | 'create', attributeClasses?: string[]): Record<string, any>;
|
|
207
|
+
export declare function dropEmptyPasswords(values: Record<string, any>, fields: FieldDef[] | undefined): Record<string, any>;
|
|
207
208
|
export declare function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf, ensureFields, mode, model, recordId, endpoint, onSaved, onCreate, onUpdate, defaults, lockedFields, schema, onDelete, onEdit, onOpenFullPage, initialRecord, getImageUrl, timeZone, currency, onChange, }: DynamicRecordDialogProps): import("react").JSX.Element;
|
|
208
209
|
export declare function ReadonlyEditField({ field, value }: {
|
|
209
210
|
field: FieldDef;
|
|
@@ -220,7 +221,7 @@ export declare function ViewValue({ field, value: rawValue, record, getImageUrl:
|
|
|
220
221
|
/** Optional override; when omitted falls back to the nearest provider. */
|
|
221
222
|
currency?: string;
|
|
222
223
|
}): import("react").JSX.Element;
|
|
223
|
-
export declare function EditField({ field, value, onChange, record, invalid }: {
|
|
224
|
+
export declare function EditField({ field, value, onChange, record, invalid, error }: {
|
|
224
225
|
field: FieldDef;
|
|
225
226
|
value: any;
|
|
226
227
|
onChange: (val: any) => void;
|
|
@@ -228,5 +229,7 @@ export declare function EditField({ field, value, onChange, record, invalid }: {
|
|
|
228
229
|
record?: any;
|
|
229
230
|
/** When true, paint the control with a destructive border (Laravel-style). */
|
|
230
231
|
invalid?: boolean;
|
|
232
|
+
/** Validation message, forwarded to a host-registered field widget. */
|
|
233
|
+
error?: string;
|
|
231
234
|
}): import("react").JSX.Element;
|
|
232
235
|
//# sourceMappingURL=dynamic-record.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-record.d.ts","sourceRoot":"","sources":["../../src/dialogs/dynamic-record.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"dynamic-record.d.ts","sourceRoot":"","sources":["../../src/dialogs/dynamic-record.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AA+C1C,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAGjF,OAA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gB,SAAS,CAAC,EACtB,KAAK,EACL,KAAK,EAAE,QAAQ,EACf,MAAM,EACN,WAAW,EAAE,eAAe,EAC5B,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,YAAY,GACzB,EAAE;IACC,KAAK,EAAE,QAAQ,CAAA;IACf,KAAK,EAAE,GAAG,CAAA;IACV,MAAM,EAAE,GAAG,CAAA;IACX,mFAAmF;IACnF,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB,+BA6TA;AAwLD,wBAAgB,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;IAC1E,KAAK,EAAE,QAAQ,CAAA;IACf,KAAK,EAAE,GAAG,CAAA;IACV,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;IAC5B,iFAAiF;IACjF,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,8EAA8E;IAC9E,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB,+BAyRA"}
|
|
@@ -16,7 +16,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
16
16
|
/** Model key of the open create/edit dialog — used to hide "+" on self-FK pickers
|
|
17
17
|
* (e.g. Customer.parent_id) so they don't nest another "Crear Cliente" modal. */
|
|
18
18
|
const RecordDialogModelContext = createContext(undefined);
|
|
19
|
-
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, Button, Input, Textarea, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch, Skeleton, Badge, Popover, PopoverContent, PopoverTrigger, Calendar, } from '@asteby/metacore-ui/primitives';
|
|
19
|
+
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, Button, Input, Textarea, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Switch, Checkbox, Skeleton, Badge, Popover, PopoverContent, PopoverTrigger, Calendar, } from '@asteby/metacore-ui/primitives';
|
|
20
20
|
import { cn } from '@asteby/metacore-ui/lib';
|
|
21
21
|
import { toast } from 'sonner';
|
|
22
22
|
import { format, parseISO } from 'date-fns';
|
|
@@ -30,6 +30,7 @@ import { toastServerError, extractFieldErrors, localizeFieldIssue, localizeField
|
|
|
30
30
|
import { DynamicSelectField, OptionLead, OptionThumb } from '../dynamic-select-field';
|
|
31
31
|
import { RecordPicker } from '../record-picker';
|
|
32
32
|
import { DynamicMultiSelectField } from '../dynamic-multi-select-field';
|
|
33
|
+
import { UploadField } from '../upload-field';
|
|
33
34
|
import { DynamicRelations } from '../dynamic-relations';
|
|
34
35
|
import { AuditInfo, readAuditMeta } from '../audit-info';
|
|
35
36
|
import { useOptionsResolver } from '../use-options-resolver';
|
|
@@ -43,7 +44,7 @@ import { FieldCell } from '../field-grid';
|
|
|
43
44
|
import { isNilUuid, normalizeNilUuid } from '../nil-uuid';
|
|
44
45
|
import { normalizeRefFieldsForSubmit } from './normalize-submit';
|
|
45
46
|
import { validateValues, bagHasErrors, exemptUnchangedRuleIssues } from '../validator';
|
|
46
|
-
import { DynamicIcon, isLucideIconName } from '../dynamic-icon';
|
|
47
|
+
import { DynamicIcon, Icon, isLucideIconName } from '../dynamic-icon';
|
|
47
48
|
import { IconPickerField } from '../icon-picker-field';
|
|
48
49
|
import { humanizeToken, localizeFieldLabel } from '../dynamic-columns-helpers';
|
|
49
50
|
import { formatDateCell } from '../dynamic-columns';
|
|
@@ -52,6 +53,7 @@ import { MediaValue, RichText } from '../rich-url';
|
|
|
52
53
|
import { generateBadgeStyles } from '@asteby/metacore-ui/lib';
|
|
53
54
|
import { CollectionCell } from '../collection-cell';
|
|
54
55
|
import { ImageUrlContext, identityImageUrl } from '../image-url-context';
|
|
56
|
+
import { getFieldWidget, useFieldWidgetRegistryVersion } from '../field-widget-registry';
|
|
55
57
|
import { TimeZoneContext, CurrencyContext } from '../org-runtime-context';
|
|
56
58
|
// localizedModelName resolves the (possibly addon-i18n) model name: prefer the
|
|
57
59
|
// translated titleKey, fall back to the backend-provided raw title.
|
|
@@ -129,6 +131,10 @@ export function isLineItemsField(field, value) {
|
|
|
129
131
|
// (including the [] default on a freshly-created record).
|
|
130
132
|
if (field.multiple)
|
|
131
133
|
return false;
|
|
134
|
+
// `multiselect` stores a plain array of ids/values (editable picker), not a
|
|
135
|
+
// structured line-items document.
|
|
136
|
+
if (field.type === 'multiselect')
|
|
137
|
+
return false;
|
|
132
138
|
if (fieldItemFields(field)?.length)
|
|
133
139
|
return true;
|
|
134
140
|
if (Array.isArray(value))
|
|
@@ -209,8 +215,13 @@ function formatDisplayValue(rawValue, field) {
|
|
|
209
215
|
const objLabel = objectLabel(value);
|
|
210
216
|
if (objLabel !== undefined)
|
|
211
217
|
return objLabel;
|
|
212
|
-
if (field.type === 'boolean' || typeof value === 'boolean')
|
|
218
|
+
if (field.type === 'boolean' || field.type === 'checkbox' || typeof value === 'boolean')
|
|
213
219
|
return value ? 'Sí' : 'No';
|
|
220
|
+
if (isPasswordField(field))
|
|
221
|
+
return '••••••••';
|
|
222
|
+
if (field.type === 'multiselect' && Array.isArray(value)) {
|
|
223
|
+
return value.map(v => field.options?.find(o => o.value === String(v))?.label ?? String(v)).join(', ');
|
|
224
|
+
}
|
|
214
225
|
if (field.type === 'select' && field.options?.length) {
|
|
215
226
|
const match = field.options.find(o => o.value === String(value));
|
|
216
227
|
// Matched option label wins (localized); humanize the raw token only
|
|
@@ -289,7 +300,7 @@ export function isMoneyField(field, value) {
|
|
|
289
300
|
export function filterVisibleFields(fields, mode, formValues, attributeClasses) {
|
|
290
301
|
const values = formValues && attributeClasses ? { ...formValues, [ATTRIBUTE_CLASSES_KEY]: attributeClasses } : formValues;
|
|
291
302
|
return (fields ?? []).filter(f => {
|
|
292
|
-
if (f.hidden)
|
|
303
|
+
if (f.hidden || f.type === 'hidden')
|
|
293
304
|
return false;
|
|
294
305
|
if (mode === 'create' && f.readonly)
|
|
295
306
|
return false;
|
|
@@ -306,6 +317,11 @@ export function filterVisibleFields(fields, mode, formValues, attributeClasses)
|
|
|
306
317
|
// visible fields — hidden fields are dropped from BOTH the render/required-gate
|
|
307
318
|
// AND the submitted values. Keys with no matching declared field, or whose
|
|
308
319
|
// field carries no `visible_when`, always pass through (retrocompat).
|
|
320
|
+
// NOTE: a `type:'hidden'` field is never in the visible set, so with a
|
|
321
|
+
// `visible_when` it is ALWAYS stripped (even when the predicate is true);
|
|
322
|
+
// without `visible_when` it passes through with its default. Pinned by tests.
|
|
323
|
+
// TODO(deuda): hay dos resolvers de campos (EditField de este diálogo y
|
|
324
|
+
// resolveWidget de dynamic-form); converger en uno solo.
|
|
309
325
|
export function stripHiddenFieldValues(values, fields, mode, attributeClasses) {
|
|
310
326
|
const visibleKeys = new Set(filterVisibleFields(fields, mode, values, attributeClasses).map(f => f.key));
|
|
311
327
|
const out = {};
|
|
@@ -317,6 +333,28 @@ export function stripHiddenFieldValues(values, fields, mode, attributeClasses) {
|
|
|
317
333
|
}
|
|
318
334
|
return out;
|
|
319
335
|
}
|
|
336
|
+
/** `password` fields are write-only: never prefilled, never shown, and an empty value is not submitted. */
|
|
337
|
+
const isPasswordField = (f) => f?.type === 'password';
|
|
338
|
+
// dropEmptyPasswords removes empty `password` fields from a submit payload:
|
|
339
|
+
// on edit an empty password means "keep the current one" (the record never
|
|
340
|
+
// carries it, so the input starts blank); on create an optional empty password
|
|
341
|
+
// must not send "" to the server either.
|
|
342
|
+
export function dropEmptyPasswords(values, fields) {
|
|
343
|
+
const out = { ...values };
|
|
344
|
+
for (const f of fields ?? []) {
|
|
345
|
+
if (isPasswordField(f) && (out[f.key] === '' || out[f.key] == null))
|
|
346
|
+
delete out[f.key];
|
|
347
|
+
}
|
|
348
|
+
return out;
|
|
349
|
+
}
|
|
350
|
+
// requiredGateFields leaves out, on edit, the password fields left empty: an
|
|
351
|
+
// empty password on edit means "keep the current one" (it is not submitted), so
|
|
352
|
+
// a `required` password must not block saving. On create it stays required.
|
|
353
|
+
function requiredGateFields(fields, mode, values) {
|
|
354
|
+
if (mode !== 'edit')
|
|
355
|
+
return fields;
|
|
356
|
+
return fields.filter(f => !(isPasswordField(f) && (values[f.key] === '' || values[f.key] == null)));
|
|
357
|
+
}
|
|
320
358
|
function applyEnsureFields(meta, ensureFields) {
|
|
321
359
|
if (!meta)
|
|
322
360
|
return meta ?? null;
|
|
@@ -387,7 +425,9 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
387
425
|
const seedForm = (meta, rec) => {
|
|
388
426
|
const initial = {};
|
|
389
427
|
for (const field of meta.fields ?? []) {
|
|
390
|
-
initial[field.key] =
|
|
428
|
+
initial[field.key] = isPasswordField(field)
|
|
429
|
+
? ''
|
|
430
|
+
: resolvePath(rec, field.key) ?? field.defaultValue ?? '';
|
|
391
431
|
}
|
|
392
432
|
setFormValues(initial);
|
|
393
433
|
};
|
|
@@ -526,6 +566,8 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
526
566
|
setFormValues(prev => {
|
|
527
567
|
const next = { ...prev };
|
|
528
568
|
for (const field of modalMeta?.fields ?? []) {
|
|
569
|
+
if (isPasswordField(field))
|
|
570
|
+
continue;
|
|
529
571
|
const v = resolvePath(rec, field.key);
|
|
530
572
|
if (v !== undefined)
|
|
531
573
|
next[field.key] = v;
|
|
@@ -578,7 +620,7 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
578
620
|
// Laravel-style: collect every issue from the shared validator
|
|
579
621
|
// (required + rule strings / min/max / email…) on visible fields only.
|
|
580
622
|
const visible = filterVisibleFields(modalMeta.fields, mode, formValues, attributeClasses);
|
|
581
|
-
let bag = validateValues(visible, formValues);
|
|
623
|
+
let bag = validateValues(requiredGateFields(visible, mode, formValues), formValues);
|
|
582
624
|
// Edit: a legacy value re-sent unchanged is not re-judged by a rule
|
|
583
625
|
// added after it was written (same grandfathering as the kernel).
|
|
584
626
|
if (mode === 'edit' && record) {
|
|
@@ -618,7 +660,7 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
618
660
|
const submittedValues = stripHiddenFieldValues(formValues, modalMeta.fields, mode, attributeClasses);
|
|
619
661
|
// Empty reference pickers → null (not "" / nil-UUID) so nullable FK
|
|
620
662
|
// columns accept them instead of raising a 23503 FK violation.
|
|
621
|
-
let payload = normalizeRefFieldsForSubmit(submittedValues, modalMeta.fields);
|
|
663
|
+
let payload = dropEmptyPasswords(normalizeRefFieldsForSubmit(submittedValues, modalMeta.fields), modalMeta.fields);
|
|
622
664
|
if (isCreate &&
|
|
623
665
|
branchGate &&
|
|
624
666
|
(payload.branch_id == null || payload.branch_id === '')) {
|
|
@@ -739,7 +781,7 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
739
781
|
const goNextStep = () => {
|
|
740
782
|
const step = groups[clampedStep];
|
|
741
783
|
const stepFields = step?.fields ?? [];
|
|
742
|
-
const bag = validateValues(stepFields, formValues);
|
|
784
|
+
const bag = validateValues(requiredGateFields(stepFields, mode, formValues), formValues);
|
|
743
785
|
if (bagHasErrors(bag)) {
|
|
744
786
|
const labels = {};
|
|
745
787
|
for (const f of stepFields)
|
|
@@ -770,15 +812,21 @@ function FieldRow({ field, record, value, mode, onChange, error, locked }) {
|
|
|
770
812
|
// CREATE for a caller-specified field (see `lockedFields`).
|
|
771
813
|
const isEditReadonly = (mode === 'edit' && !!field.readonly) || !!locked;
|
|
772
814
|
const { t } = useTranslation();
|
|
773
|
-
return (_jsxs("div", { className: "flex flex-col gap-1.5", "data-aby-field": field.key, children: [_jsxs(Label, { className: "text-sm font-medium text-foreground/80", children: [localizeFieldLabel(field.label, t), field.required && mode !== 'view' && !isEditReadonly && (_jsx("span", { className: "text-destructive ml-0.5", children: "*" }))] }), mode === 'view' ? (_jsx(ViewValue, { field: field, value: value, record: record })) : isEditReadonly ? (_jsx(ReadonlyEditField, { field: field, value: value })) : (_jsx(EditField, { field: field, value: value, onChange: onChange, record: record, invalid: !!error })), error && mode !== 'view' && (_jsx("p", { className: "text-destructive text-xs mt-1", children: error }))] }));
|
|
815
|
+
return (_jsxs("div", { className: "flex flex-col gap-1.5", "data-aby-field": field.key, children: [_jsxs(Label, { className: "text-sm font-medium text-foreground/80", children: [localizeFieldLabel(field.label, t), field.required && mode !== 'view' && !isEditReadonly && (_jsx("span", { className: "text-destructive ml-0.5", children: "*" }))] }), mode === 'view' ? (_jsx(ViewValue, { field: field, value: value, record: record })) : isEditReadonly ? (_jsx(ReadonlyEditField, { field: field, value: value })) : (_jsx(EditField, { field: field, value: value, onChange: onChange, record: record, invalid: !!error, error: error })), error && mode !== 'view' && (_jsx("p", { className: "text-destructive text-xs mt-1", children: error }))] }));
|
|
774
816
|
}
|
|
775
817
|
// ReadonlyEditField — the edit-mode rendering of a `readonly` (system-generated)
|
|
776
818
|
// field: a disabled, muted input that shows the current value without allowing
|
|
777
819
|
// edits. Booleans render as a disabled switch to match their editable
|
|
778
820
|
// counterpart; everything else renders the formatted display value in a disabled
|
|
779
821
|
// text input.
|
|
822
|
+
const noopChange = () => { };
|
|
780
823
|
export function ReadonlyEditField({ field, value }) {
|
|
781
|
-
|
|
824
|
+
useFieldWidgetRegistryVersion();
|
|
825
|
+
const HostWidget = getFieldWidget(field.widget);
|
|
826
|
+
if (HostWidget) {
|
|
827
|
+
return _jsx(HostWidget, { field: field, value: value, onChange: noopChange, disabled: true });
|
|
828
|
+
}
|
|
829
|
+
if (field.type === 'boolean' || field.type === 'checkbox' || typeof value === 'boolean') {
|
|
782
830
|
return (_jsxs("div", { className: "flex items-center gap-2 py-1", children: [_jsx(Switch, { checked: !!value, disabled: true }), _jsx("span", { className: "text-sm text-muted-foreground", children: value ? 'Sí' : 'No' })] }));
|
|
783
831
|
}
|
|
784
832
|
const fieldRef = getFieldRef(field);
|
|
@@ -914,7 +962,7 @@ export function ViewValue({ field, value: rawValue, record, getImageUrl: getImag
|
|
|
914
962
|
if (inlineLabel !== undefined) {
|
|
915
963
|
return _jsx("p", { className: "text-sm py-1", children: inlineLabel });
|
|
916
964
|
}
|
|
917
|
-
if (field.type === 'boolean' || typeof value === 'boolean') {
|
|
965
|
+
if (field.type === 'boolean' || field.type === 'checkbox' || typeof value === 'boolean') {
|
|
918
966
|
return (_jsxs("div", { className: "flex items-center gap-2 py-1", children: [_jsx(Switch, { checked: !!value, disabled: true }), _jsx("span", { className: "text-sm text-muted-foreground", children: value ? 'Sí' : 'No' })] }));
|
|
919
967
|
}
|
|
920
968
|
if (field.type === 'color') {
|
|
@@ -937,6 +985,13 @@ export function ViewValue({ field, value: rawValue, record, getImageUrl: getImag
|
|
|
937
985
|
}
|
|
938
986
|
return value || caption ? (_jsx("div", { className: "py-1", children: _jsx(ImageStack, { src: value ? String(value) : undefined, label: caption, getImageUrl: getImageUrl, size: "lg" }) })) : (_jsx("p", { className: "text-sm py-1 text-muted-foreground", children: "Sin imagen" }));
|
|
939
987
|
}
|
|
988
|
+
// Explicit `type: 'icon'`: any stored icon format via the universal resolver.
|
|
989
|
+
if (renderAs === 'icon') {
|
|
990
|
+
const empty = _jsx("p", { className: "text-sm py-1 text-muted-foreground", children: "-" });
|
|
991
|
+
if (!value)
|
|
992
|
+
return empty;
|
|
993
|
+
return (_jsx("div", { className: "py-1", children: _jsx(Icon, { name: value, className: "h-6 w-6", fallback: empty, resolveImageSrc: (src) => (/^(?:data:|https?:)/i.test(src) ? src : getImageUrl(src)) }) }));
|
|
994
|
+
}
|
|
940
995
|
if (field.type === 'image' || renderAs === 'image') {
|
|
941
996
|
if (isLucideIconName(value)) {
|
|
942
997
|
return _jsx(IconNameViewValue, { name: value });
|
|
@@ -1135,13 +1190,20 @@ function JsonObjectViewValue({ value }) {
|
|
|
1135
1190
|
return (_jsxs("div", { className: "min-w-0", children: [_jsx("dt", { className: "text-[11px] font-medium uppercase tracking-wide text-muted-foreground", children: label }), _jsx("dd", { className: "mt-0.5 break-words text-foreground", children: isNest ? (_jsx("pre", { className: "max-h-48 overflow-auto rounded-md bg-muted/40 p-2 text-[11px] leading-relaxed whitespace-pre-wrap", children: JSON.stringify(raw, null, 2) })) : raw === null || raw === '' ? (_jsx("span", { className: "text-muted-foreground", children: "\u2014" })) : (String(raw)) })] }, key));
|
|
1136
1191
|
}) }));
|
|
1137
1192
|
}
|
|
1138
|
-
export function EditField({ field, value, onChange, record, invalid }) {
|
|
1193
|
+
export function EditField({ field, value, onChange, record, invalid, error }) {
|
|
1139
1194
|
const invalidCls = invalid
|
|
1140
1195
|
? 'border-destructive ring-1 ring-destructive/30 focus-visible:ring-destructive aria-invalid:border-destructive'
|
|
1141
1196
|
: undefined;
|
|
1142
1197
|
const { t, i18n } = useTranslation();
|
|
1143
1198
|
const editFieldImageUrl = useContext(ImageUrlContext);
|
|
1144
1199
|
const dialogModel = useContext(RecordDialogModelContext);
|
|
1200
|
+
// Host-registered widget (`widget: "<name>"`) wins over every built-in and
|
|
1201
|
+
// type-based branch. Unregistered names fall through untouched.
|
|
1202
|
+
useFieldWidgetRegistryVersion();
|
|
1203
|
+
const HostWidget = getFieldWidget(field.widget);
|
|
1204
|
+
if (HostWidget) {
|
|
1205
|
+
return (_jsx(HostWidget, { field: field, value: value, onChange: onChange, error: error, record: record }));
|
|
1206
|
+
}
|
|
1145
1207
|
// Jsonb line-items columns (e.g. Transfer.items) are action-built documents:
|
|
1146
1208
|
// editing the array field-by-field is out of scope. Render them READ-ONLY
|
|
1147
1209
|
// with the same inline table the detail view uses — a localized, ref-resolved
|
|
@@ -1152,6 +1214,20 @@ export function EditField({ field, value, onChange, record, invalid }) {
|
|
|
1152
1214
|
if (field.type === 'boolean') {
|
|
1153
1215
|
return (_jsxs("div", { className: "flex items-center gap-2 py-1", children: [_jsx(Switch, { checked: !!value, onCheckedChange: onChange }), _jsx("span", { className: "text-sm text-muted-foreground", children: value ? 'Sí' : 'No' })] }));
|
|
1154
1216
|
}
|
|
1217
|
+
// Checkbox: boolean like `boolean`, rendered as a checkbox with its label.
|
|
1218
|
+
if (field.type === 'checkbox') {
|
|
1219
|
+
return (_jsx("div", { className: "flex items-center gap-2 py-1", children: _jsx(Checkbox, { checked: value === true || value === 'true', onCheckedChange: (c) => onChange(c === true), "aria-invalid": invalid || undefined }) }));
|
|
1220
|
+
}
|
|
1221
|
+
// Multiselect: array of ids/values. A `ref`/`searchEndpoint` resolves options
|
|
1222
|
+
// remotely (same contract as `multiple`); otherwise the static `options`.
|
|
1223
|
+
if (field.type === 'multiselect') {
|
|
1224
|
+
return (_jsx(DynamicMultiSelectField, { field: field, value: value, onChange: onChange, staticOptions: field.options }));
|
|
1225
|
+
}
|
|
1226
|
+
// File: generic uploader (POST to the host upload endpoint, stores the
|
|
1227
|
+
// returned url/path). `image` / `widget: 'upload'` keep the image dropzone.
|
|
1228
|
+
if (field.type === 'file') {
|
|
1229
|
+
return _jsx(UploadField, { field: field, value: value, onChange: onChange });
|
|
1230
|
+
}
|
|
1155
1231
|
if (field.type === 'textarea') {
|
|
1156
1232
|
return (_jsx(Textarea, { value: value ?? '', onChange: (e) => onChange(e.target.value), placeholder: field.placeholder, rows: 4, "aria-invalid": invalid || undefined, className: invalidCls }));
|
|
1157
1233
|
}
|
|
@@ -1234,7 +1310,13 @@ export function EditField({ field, value, onChange, record, invalid }) {
|
|
|
1234
1310
|
? 'number'
|
|
1235
1311
|
: field.type === 'email'
|
|
1236
1312
|
? 'email'
|
|
1237
|
-
: '
|
|
1313
|
+
: field.type === 'password'
|
|
1314
|
+
? 'password'
|
|
1315
|
+
: field.type === 'phone' || field.type === 'tel'
|
|
1316
|
+
? 'tel'
|
|
1317
|
+
: field.type === 'time'
|
|
1318
|
+
? 'time'
|
|
1319
|
+
: 'text';
|
|
1238
1320
|
return _jsx(ScannableRecordInput, { field: field, value: value, onChange: onChange, inputType: inputType, invalid: invalid, className: invalidCls });
|
|
1239
1321
|
}
|
|
1240
1322
|
/**
|
|
@@ -1255,7 +1337,7 @@ function ScannableRecordInput({ field, value, onChange, inputType, invalid, clas
|
|
|
1255
1337
|
// muestra un mensaje amable cuando el navegador no tiene cámara.
|
|
1256
1338
|
const scanEnabled = !!(field.scan ??
|
|
1257
1339
|
field.scannable);
|
|
1258
|
-
const input = (_jsx(Input, { type: inputType, value: value ?? '', onChange: (e) => onChange(inputType === 'number' ? (e.target.value === '' ? '' : Number(e.target.value)) : e.target.value), placeholder: field.placeholder, "aria-invalid": invalid || undefined, className: className }));
|
|
1340
|
+
const input = (_jsx(Input, { type: inputType, value: value ?? '', onChange: (e) => onChange(inputType === 'number' ? (e.target.value === '' ? '' : Number(e.target.value)) : e.target.value), placeholder: field.placeholder, autoComplete: inputType === 'password' ? 'new-password' : undefined, "aria-invalid": invalid || undefined, className: className }));
|
|
1259
1341
|
if (!scanEnabled)
|
|
1260
1342
|
return input;
|
|
1261
1343
|
return (_jsxs("div", { className: "flex w-full min-w-0 items-center gap-1.5", children: [_jsx("div", { className: "min-w-0 flex-1", children: input }), _jsx(Button, { type: "button", variant: "outline", size: "icon", className: "size-9 shrink-0", onClick: () => setScanOpen(true), title: "Escanear con la c\u00E1mara", "aria-label": "Escanear c\u00F3digo de barras con la c\u00E1mara", children: _jsx(ScanLine, { className: "size-4" }) }), _jsx(BarcodeScanner, { open: scanOpen, onClose: () => setScanOpen(false), onDetected: (code) => onChange(code),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-columns.d.ts","sourceRoot":"","sources":["../src/dynamic-columns.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,UAAU,CAAA;AAwC9C,OAAO,KAAK,EAAiB,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE9D,OAAO,KAAK,EAER,iBAAi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ClB,CAgCA,CAAA;AAED,wBAAgB,4BAA4B,CACxC,OAAO,GAAE,qBAA0B,GACpC,iBAAiB,CAisBnB;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,iBACL,CAAA"}
|
package/dist/dynamic-columns.js
CHANGED
|
@@ -26,7 +26,7 @@ import { objectLabel } from './dynamic-relation-helpers';
|
|
|
26
26
|
import { OptionBadge, RelationThumbnail, ImageStack, statusColorFor, useIsDarkTheme, } from './display-value';
|
|
27
27
|
import { MediaValue } from './rich-url';
|
|
28
28
|
import { OptionsContext } from './options-context';
|
|
29
|
-
import { DynamicIcon, isLucideIconName } from './dynamic-icon';
|
|
29
|
+
import { DynamicIcon, Icon, isLucideIconName } from './dynamic-icon';
|
|
30
30
|
import { CollectionCell } from './collection-cell';
|
|
31
31
|
import { isNilUuid, normalizeNilUuid } from './nil-uuid';
|
|
32
32
|
import { useOptionsResolver } from './use-options-resolver';
|
|
@@ -996,6 +996,16 @@ export function makeDefaultGetDynamicColumns(helpers = {}) {
|
|
|
996
996
|
: imageValue;
|
|
997
997
|
return _jsx(ImageCell, { value: imageSrc, getImageUrl: getImageUrl });
|
|
998
998
|
}
|
|
999
|
+
case 'icon': {
|
|
1000
|
+
// Explicit `type: 'icon'` only: any stored icon format
|
|
1001
|
+
// (Lucide, FontAwesome classes, emoji, image URL).
|
|
1002
|
+
// Uninterpretable values show the dash, never raw text.
|
|
1003
|
+
if (!value)
|
|
1004
|
+
return _jsx(EmptyCell, {});
|
|
1005
|
+
return (_jsx(Icon, { name: value, className: "h-5 w-5 text-foreground/80", fallback: _jsx(EmptyCell, {}), resolveImageSrc: (src) => /^(?:data:|https?:)/i.test(src)
|
|
1006
|
+
? src
|
|
1007
|
+
: getImageUrl(resolveImageSrc(col, src, apiBaseUrl, normalizeImagePath)) }));
|
|
1008
|
+
}
|
|
999
1009
|
case 'image_stack': {
|
|
1000
1010
|
// Defensive: normally handled above before the
|
|
1001
1011
|
// switch; kept so a late `type: image_stack` without
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-form.d.ts","sourceRoot":"","sources":["../src/dynamic-form.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAwB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAA;AAerE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,EACH,cAAc,EACd,aAAa,EAOhB,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"dynamic-form.d.ts","sourceRoot":"","sources":["../src/dynamic-form.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAwB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAA;AAerE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,EACH,cAAc,EACd,aAAa,EAOhB,MAAM,uBAAuB,CAAA;AAc9B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAEzF,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACnC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/D,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CAC3B;AAsBD,wBAAgB,WAAW,CAAC,EACxB,MAAM,EACN,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,WAAuB,EACvB,WAAwB,EACxB,QAAgB,EAChB,UAAU,EACV,cAAsB,GACzB,EAAE,gBAAgB,+BAiOlB;AAsQD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,EAC1B,YAAY,EAAE,SAAS,OAAO,EAAE,GACjC,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAMrB"}
|
package/dist/dynamic-form.js
CHANGED
|
@@ -19,6 +19,7 @@ import { DynamicDateField } from './dynamic-date-field';
|
|
|
19
19
|
import { UploadField } from './upload-field';
|
|
20
20
|
import { IconPickerField } from './icon-picker-field';
|
|
21
21
|
import { ColorPickerField } from './color-picker-field';
|
|
22
|
+
import { getFieldWidget, useFieldWidgetRegistryVersion } from './field-widget-registry';
|
|
22
23
|
export { buildZodSchema, resolveWidget };
|
|
23
24
|
export { DynamicLineItems } from './dynamic-line-items';
|
|
24
25
|
export { DynamicSelectField } from './dynamic-select-field';
|
|
@@ -209,7 +210,7 @@ function FieldRow({ field, value, onChange, values, error, initialValues }) {
|
|
|
209
210
|
const fullWidth = isLineItemsField(field) ||
|
|
210
211
|
resolveWidget(field) === 'textarea' ||
|
|
211
212
|
resolveWidget(field) === 'richtext';
|
|
212
|
-
return (_jsxs("div", { className: 'grid gap-2 ' + (fullWidth ? 'sm:col-span-2' : ''), children: [_jsxs(Label, { htmlFor: field.key, children: [field.label, field.required && _jsx("span", { className: "text-red-500 ml-1", children: "*" })] }), _jsx(FieldRenderer, { field: field, value: value, onChange: onChange, initialValues: initialValues, values: values, effectiveOptions: effectiveOptions }), error && _jsx("span", { className: "text-red-500 text-sm", role: "alert", children: error })] }));
|
|
213
|
+
return (_jsxs("div", { className: 'grid gap-2 ' + (fullWidth ? 'sm:col-span-2' : ''), children: [_jsxs(Label, { htmlFor: field.key, children: [field.label, field.required && _jsx("span", { className: "text-red-500 ml-1", children: "*" })] }), _jsx(FieldRenderer, { field: field, value: value, onChange: onChange, initialValues: initialValues, values: values, effectiveOptions: effectiveOptions, error: error }), error && _jsx("span", { className: "text-red-500 text-sm", role: "alert", children: error })] }));
|
|
213
214
|
}
|
|
214
215
|
// seedOptionFromSibling builds a pre-resolved option for an FK field from the
|
|
215
216
|
// resolved sibling the backend served on the initial record (e.g. a line item's
|
|
@@ -236,7 +237,14 @@ function seedOptionFromSibling(field, value, initialValues) {
|
|
|
236
237
|
icon: sib.icon,
|
|
237
238
|
};
|
|
238
239
|
}
|
|
239
|
-
function FieldRenderer({ field, value, onChange, initialValues, effectiveOptions, }) {
|
|
240
|
+
function FieldRenderer({ field, value, onChange, initialValues, values, effectiveOptions, error, }) {
|
|
241
|
+
// Host-registered widget (`widget: "<name>"`) wins over every built-in and
|
|
242
|
+
// type-based branch. Unregistered names fall through untouched.
|
|
243
|
+
useFieldWidgetRegistryVersion();
|
|
244
|
+
const HostWidget = getFieldWidget(field.widget);
|
|
245
|
+
if (HostWidget) {
|
|
246
|
+
return _jsx(HostWidget, { field: field, value: value, onChange: onChange, error: error, record: values });
|
|
247
|
+
}
|
|
240
248
|
// Repeatable line-items group → render the row grid. Its value is an array
|
|
241
249
|
// of row objects rather than a scalar.
|
|
242
250
|
if (isLineItemsField(field)) {
|
package/dist/dynamic-icon.d.ts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
1
2
|
export interface DynamicIconProps {
|
|
2
3
|
name: string;
|
|
3
4
|
className?: string;
|
|
4
5
|
}
|
|
5
|
-
export
|
|
6
|
+
export interface IconProps {
|
|
7
|
+
/** Any icon value: Lucide name, FontAwesome classes, emoji, image URL... */
|
|
8
|
+
name: unknown;
|
|
9
|
+
className?: string;
|
|
10
|
+
/** Accessible name. Without it the icon is decorative (aria-hidden). */
|
|
11
|
+
label?: string;
|
|
12
|
+
/** Drawn when the value cannot be interpreted. Default: nothing. */
|
|
13
|
+
fallback?: ReactNode;
|
|
14
|
+
/** Maps an image `src` before it reaches <img> (e.g. host `getImageUrl`). */
|
|
15
|
+
resolveImageSrc?: (src: string) => string;
|
|
16
|
+
/** Render image sources (default true). DynamicIcon turns it off. */
|
|
17
|
+
images?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function Icon({ name, className, label, fallback, resolveImageSrc, images }: IconProps): import("react").JSX.Element;
|
|
20
|
+
export declare function DynamicIcon({ name, className }: DynamicIconProps): import("react").JSX.Element;
|
|
6
21
|
export declare function resolveLucideIconName(value: unknown): string | null;
|
|
7
22
|
export declare function isLucideIconName(value: unknown): value is string;
|
|
8
23
|
/** PascalCase names of every lucide glyph, for the icon picker grid. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-icon.d.ts","sourceRoot":"","sources":["../src/dynamic-icon.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dynamic-icon.d.ts","sourceRoot":"","sources":["../src/dynamic-icon.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAKhD,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,SAAS;IACtB,4EAA4E;IAC5E,IAAI,EAAE,OAAO,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,oEAAoE;IACpE,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,6EAA6E;IAC7E,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;IACzC,qEAAqE;IACrE,MAAM,CAAC,EAAE,OAAO,CAAA;CACnB;AA8CD,wBAAgB,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAe,EAAE,eAAe,EAAE,MAAa,EAAE,EAAE,SAAS,+BA0B1G;AAMD,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,gBAAgB,+BAEhE;AAMD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CASnE;AASD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEhE;AAED,wEAAwE;AACxE,wBAAgB,eAAe,IAAI,MAAM,EAAE,CAE1C"}
|