@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
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import dynamicIconImports from 'lucide-react/dynamicIconImports'
|
|
3
|
+
import { parseIconSpec } from '../icon-spec'
|
|
4
|
+
import { FONT_AWESOME_ALIASES } from '../icon-aliases'
|
|
5
|
+
|
|
6
|
+
const lucide = (name: string) => ({ kind: 'lucide', name })
|
|
7
|
+
|
|
8
|
+
describe('parseIconSpec', () => {
|
|
9
|
+
it.each([
|
|
10
|
+
['CreditCard', 'CreditCard'],
|
|
11
|
+
['credit-card', 'CreditCard'],
|
|
12
|
+
['credit_card', 'CreditCard'],
|
|
13
|
+
['CreditCardIcon', 'CreditCard'],
|
|
14
|
+
['Building2', 'Building2'],
|
|
15
|
+
['building-2', 'Building2'],
|
|
16
|
+
[' brain ', 'Brain'],
|
|
17
|
+
])('Lucide %s', (input, name) => {
|
|
18
|
+
expect(parseIconSpec(input)).toEqual(lucide(name))
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it.each([
|
|
22
|
+
// The real ones stored by doctores.lat
|
|
23
|
+
['fas fa-brain', 'Brain'],
|
|
24
|
+
['fas fa-female', 'Venus'],
|
|
25
|
+
['fas fa-bone', 'Bone'],
|
|
26
|
+
['fas fa-eye', 'Eye'],
|
|
27
|
+
['fas fa-allergies', 'Flower2'],
|
|
28
|
+
['fas fa-baby', 'Baby'],
|
|
29
|
+
['fas fa-user-md', 'Stethoscope'],
|
|
30
|
+
['fas fa-tooth', 'Toothbrush'],
|
|
31
|
+
// Other FA spellings
|
|
32
|
+
['fa-solid fa-brain', 'Brain'],
|
|
33
|
+
['far fa-heart', 'Heart'],
|
|
34
|
+
['fa fa-user-md', 'Stethoscope'],
|
|
35
|
+
['fa-brain', 'Brain'],
|
|
36
|
+
['fa-solid fa-heart-pulse', 'HeartPulse'],
|
|
37
|
+
['fas fa-heartbeat fa-2x fa-fw', 'HeartPulse'],
|
|
38
|
+
['fa-regular fa-calendar-check', 'CalendarCheck'],
|
|
39
|
+
['fal fa-map-marker-alt', 'MapPin'],
|
|
40
|
+
])('FontAwesome %s', (input, name) => {
|
|
41
|
+
expect(parseIconSpec(input)).toEqual(lucide(name))
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it.each([
|
|
45
|
+
['mdi mdi-home', 'Home'],
|
|
46
|
+
['mdi-home', 'Home'],
|
|
47
|
+
['bi bi-house', 'House'],
|
|
48
|
+
['ti ti-home', 'Home'],
|
|
49
|
+
['ri-home-line', 'Home'],
|
|
50
|
+
['mdi:home', 'Home'],
|
|
51
|
+
['lucide:brain', 'Brain'],
|
|
52
|
+
['material-icons home', 'Home'],
|
|
53
|
+
])('otras librerías %s', (input, name) => {
|
|
54
|
+
expect(parseIconSpec(input)).toEqual(lucide(name))
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it.each(['🩺', '👨⚕️', '🇲🇽', '👍🏽', '1️⃣', '❤️'])('emoji %s', (value) => {
|
|
58
|
+
expect(parseIconSpec(value)).toEqual({ kind: 'emoji', value })
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('dos emojis o emoji con texto no son un emoji', () => {
|
|
62
|
+
expect(parseIconSpec('🩺🩺').kind).toBe('unknown')
|
|
63
|
+
expect(parseIconSpec('🩺 hola').kind).toBe('unknown')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it.each([
|
|
67
|
+
'https://cdn.example.com/a.png',
|
|
68
|
+
'http://example.com/icon',
|
|
69
|
+
'/uploads/a.png',
|
|
70
|
+
'./a.png',
|
|
71
|
+
'../a.svg',
|
|
72
|
+
'uploads/a.webp',
|
|
73
|
+
'data:image/png;base64,iVBORw0KGgo=',
|
|
74
|
+
'data:image/svg+xml;base64,PHN2Zy8+',
|
|
75
|
+
'data:image/jpeg;base64,/9j/4AAQ',
|
|
76
|
+
])('imagen válida %s', (src) => {
|
|
77
|
+
expect(parseIconSpec(src)).toEqual({ kind: 'image', src })
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it.each([
|
|
81
|
+
['letras', 'a'.repeat(100_000)],
|
|
82
|
+
['fa- encadenado', 'fa-a'.repeat(25_000)],
|
|
83
|
+
['estilo repetido', 'fas '.repeat(25_000)],
|
|
84
|
+
['ruta larga', '/' + 'a'.repeat(100_000)],
|
|
85
|
+
['data:image enorme', 'data:image/png;base64,' + 'A'.repeat(100_000)],
|
|
86
|
+
['emoji ZWJ repetido', '👨\u200d⚕️'.repeat(10_000)],
|
|
87
|
+
])('entrada de 100k caracteres (%s) responde rápido y sin romper', (_n, raw) => {
|
|
88
|
+
const t0 = Date.now()
|
|
89
|
+
expect(() => parseIconSpec(raw)).not.toThrow()
|
|
90
|
+
expect(Date.now() - t0).toBeLessThan(500) // sin backtracking catastrófico
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it.each([
|
|
94
|
+
'javascript:alert(1)',
|
|
95
|
+
'JavaScript:alert(1)',
|
|
96
|
+
'vbscript:x',
|
|
97
|
+
'data:text/html;base64,PHNjcmlwdD4=',
|
|
98
|
+
'data:image/svg+xml;base64,AAA" onerror="x',
|
|
99
|
+
'data:application/javascript,alert(1)',
|
|
100
|
+
'file:///etc/passwd',
|
|
101
|
+
'//evil.example.com/x.png',
|
|
102
|
+
'<svg onload=alert(1)></svg>',
|
|
103
|
+
'blob:https://x/y',
|
|
104
|
+
'https://x.com/a b.png',
|
|
105
|
+
])('inválido o peligroso %s -> unknown', (raw) => {
|
|
106
|
+
expect(parseIconSpec(raw).kind).toBe('unknown')
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it.each(['', ' ', 'no es un icono', 'fas fa-no-existe-xyz', 'fa-solid', 'Icon', 'texto.largo'])(
|
|
110
|
+
'unknown %j',
|
|
111
|
+
(raw) => {
|
|
112
|
+
expect(parseIconSpec(raw).kind).toBe('unknown')
|
|
113
|
+
},
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
it('valores no string', () => {
|
|
117
|
+
expect(parseIconSpec(null)).toEqual({ kind: 'unknown', raw: '' })
|
|
118
|
+
expect(parseIconSpec(undefined)).toEqual({ kind: 'unknown', raw: '' })
|
|
119
|
+
expect(parseIconSpec(42)).toEqual({ kind: 'unknown', raw: '42' })
|
|
120
|
+
expect(parseIconSpec({})).toMatchObject({ kind: 'unknown' })
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('es determinista', () => {
|
|
124
|
+
expect(parseIconSpec('fas fa-brain')).toEqual(parseIconSpec('fas fa-brain'))
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
describe('FONT_AWESOME_ALIASES', () => {
|
|
129
|
+
it('tiene una tabla amplia', () => {
|
|
130
|
+
expect(Object.keys(FONT_AWESOME_ALIASES).length).toBeGreaterThan(150)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('todo alias apunta a un glifo Lucide real', () => {
|
|
134
|
+
const keys = new Set(Object.keys(dynamicIconImports))
|
|
135
|
+
const bad = Object.entries(FONT_AWESOME_ALIASES).filter(([, v]) => !keys.has(v))
|
|
136
|
+
expect(bad).toEqual([])
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('cada alias resuelve a lucide vía parseIconSpec', () => {
|
|
140
|
+
for (const name of Object.keys(FONT_AWESOME_ALIASES)) {
|
|
141
|
+
expect(parseIconSpec(`fas fa-${name}`).kind, name).toBe('lucide')
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('cubre los iconos médicos usados por doctores.lat', () => {
|
|
146
|
+
const names = [
|
|
147
|
+
'brain', 'bone', 'eye', 'heart', 'heartbeat', 'stethoscope', 'user-md', 'user-nurse', 'tooth',
|
|
148
|
+
'baby', 'female', 'male', 'venus-mars', 'allergies', 'lungs', 'x-ray', 'pills', 'syringe',
|
|
149
|
+
'hospital', 'ambulance', 'procedures', 'dna', 'microscope', 'notes-medical', 'file-medical',
|
|
150
|
+
'vial', 'thermometer', 'wheelchair', 'diagnoses', 'head-side-virus', 'child', 'clinic-medical',
|
|
151
|
+
'hospital-alt', 'user-doctor', 'map-marker-alt', 'shield-heart', 'hand-sparkles',
|
|
152
|
+
]
|
|
153
|
+
for (const n of names) expect(parseIconSpec(`fas fa-${n}`).kind, n).toBe('lucide')
|
|
154
|
+
})
|
|
155
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ColumnFilterConfig } from './dynamic-columns-shim'
|
|
2
|
+
|
|
3
|
+
interface FilterFieldColumn {
|
|
4
|
+
key?: string
|
|
5
|
+
filterField?: string
|
|
6
|
+
/** snake_case spelling emitted by some kernels. */
|
|
7
|
+
filter_field?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Honors `ColumnDefinition.filterField`: a display column (e.g.
|
|
12
|
+
* `institution_type.name`) filters by its persisted field (`institution_type_id`).
|
|
13
|
+
* The header filter keeps living on the display column, but its `filterKey` —
|
|
14
|
+
* and therefore the `f_*` param sent to the backend — becomes the filterField.
|
|
15
|
+
* When the filterField has its own option source (static options, searchEndpoint
|
|
16
|
+
* 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
|
|
17
|
+
* (which may be names, not FK ids) while its selection is read from the
|
|
18
|
+
* filterField key. Columns without
|
|
19
|
+
* `filterField` (or equal to their key) are returned untouched.
|
|
20
|
+
*/
|
|
21
|
+
export function applyColumnFilterFields(
|
|
22
|
+
columns: readonly FilterFieldColumn[] | undefined,
|
|
23
|
+
configs: Map<string, ColumnFilterConfig>,
|
|
24
|
+
dynamicFilters: Record<string, string[]> = {},
|
|
25
|
+
): Map<string, ColumnFilterConfig> {
|
|
26
|
+
if (!columns?.length) return configs
|
|
27
|
+
|
|
28
|
+
let resolved: Map<string, ColumnFilterConfig> | null = null
|
|
29
|
+
for (const column of columns) {
|
|
30
|
+
if (!column.key) continue
|
|
31
|
+
const filterField = column.filterField || column.filter_field
|
|
32
|
+
if (!filterField || filterField === column.key) continue
|
|
33
|
+
|
|
34
|
+
const displayConfig = configs.get(column.key)
|
|
35
|
+
if (!displayConfig) continue
|
|
36
|
+
|
|
37
|
+
const fieldConfig = configs.get(filterField)
|
|
38
|
+
const fieldHasOwnOptions = Boolean(
|
|
39
|
+
fieldConfig &&
|
|
40
|
+
(fieldConfig.options.length > 0 ||
|
|
41
|
+
fieldConfig.searchEndpoint ||
|
|
42
|
+
fieldConfig.loadOptions),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
resolved ??= new Map(configs)
|
|
46
|
+
resolved.set(column.key, {
|
|
47
|
+
...displayConfig,
|
|
48
|
+
...(fieldConfig && fieldHasOwnOptions
|
|
49
|
+
? {
|
|
50
|
+
filterType: fieldConfig.filterType,
|
|
51
|
+
options: fieldConfig.options,
|
|
52
|
+
loading: fieldConfig.loading,
|
|
53
|
+
searchEndpoint: fieldConfig.searchEndpoint,
|
|
54
|
+
loadOptions: fieldConfig.loadOptions,
|
|
55
|
+
}
|
|
56
|
+
: {}),
|
|
57
|
+
filterKey: filterField,
|
|
58
|
+
// Sin config propia del campo, la selección vive bajo la key del filterField.
|
|
59
|
+
selectedValues: fieldConfig
|
|
60
|
+
? (fieldConfig.selectedValues ?? displayConfig.selectedValues)
|
|
61
|
+
: (dynamicFilters[filterField] ?? []),
|
|
62
|
+
onFilterChange: fieldConfig?.onFilterChange ?? displayConfig.onFilterChange,
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
return resolved ?? configs
|
|
66
|
+
}
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
SelectTrigger,
|
|
35
35
|
SelectValue,
|
|
36
36
|
Switch,
|
|
37
|
+
Checkbox,
|
|
37
38
|
Skeleton,
|
|
38
39
|
Badge,
|
|
39
40
|
Popover,
|
|
@@ -54,6 +55,7 @@ import { toastServerError, extractFieldErrors, localizeFieldIssue, localizeField
|
|
|
54
55
|
import { DynamicSelectField, OptionLead, OptionThumb } from '../dynamic-select-field'
|
|
55
56
|
import { RecordPicker } from '../record-picker'
|
|
56
57
|
import { DynamicMultiSelectField } from '../dynamic-multi-select-field'
|
|
58
|
+
import { UploadField } from '../upload-field'
|
|
57
59
|
import { DynamicRelations } from '../dynamic-relations'
|
|
58
60
|
import { AuditInfo, readAuditMeta } from '../audit-info'
|
|
59
61
|
import type { AuditMeta } from '../types'
|
|
@@ -69,7 +71,7 @@ import { FieldCell } from '../field-grid'
|
|
|
69
71
|
import { isNilUuid, normalizeNilUuid } from '../nil-uuid'
|
|
70
72
|
import { normalizeRefFieldsForSubmit } from './normalize-submit'
|
|
71
73
|
import { validateValues, bagHasErrors, exemptUnchangedRuleIssues } from '../validator'
|
|
72
|
-
import { DynamicIcon, isLucideIconName } from '../dynamic-icon'
|
|
74
|
+
import { DynamicIcon, Icon, isLucideIconName } from '../dynamic-icon'
|
|
73
75
|
import { IconPickerField } from '../icon-picker-field'
|
|
74
76
|
import { humanizeToken, localizeFieldLabel } from '../dynamic-columns-helpers'
|
|
75
77
|
import { formatDateCell } from '../dynamic-columns'
|
|
@@ -85,6 +87,7 @@ import { generateBadgeStyles } from '@asteby/metacore-ui/lib'
|
|
|
85
87
|
import { CollectionCell, type ItemField } from '../collection-cell'
|
|
86
88
|
import type { ActionFieldDef, RelationMeta } from '../types'
|
|
87
89
|
import { ImageUrlContext, identityImageUrl, type GetImageUrl } from '../image-url-context'
|
|
90
|
+
import { getFieldWidget, useFieldWidgetRegistryVersion } from '../field-widget-registry'
|
|
88
91
|
import { TimeZoneContext, CurrencyContext } from '../org-runtime-context'
|
|
89
92
|
|
|
90
93
|
// Re-export the resolver type so `index.ts`'s
|
|
@@ -108,7 +111,8 @@ export interface FieldOption {
|
|
|
108
111
|
export interface FieldDef {
|
|
109
112
|
key: string
|
|
110
113
|
label: string
|
|
111
|
-
type: 'text' | 'textarea' | 'select' | 'search' | 'number' | 'date' | 'email' | 'url' | 'boolean' | 'image'
|
|
114
|
+
type: 'text' | 'textarea' | 'select' | 'search' | 'number' | 'date' | 'email' | 'url' | 'boolean' | 'image'
|
|
115
|
+
| 'password' | 'phone' | 'tel' | 'checkbox' | 'time' | 'hidden' | 'multiselect' | 'file' | string
|
|
112
116
|
required?: boolean
|
|
113
117
|
options?: FieldOption[]
|
|
114
118
|
defaultValue?: any
|
|
@@ -393,6 +397,9 @@ export function isLineItemsField(field: FieldDef, value: any): boolean {
|
|
|
393
397
|
// inline-table branch just because its current value is an array
|
|
394
398
|
// (including the [] default on a freshly-created record).
|
|
395
399
|
if ((field as ActionFieldDef).multiple) return false
|
|
400
|
+
// `multiselect` stores a plain array of ids/values (editable picker), not a
|
|
401
|
+
// structured line-items document.
|
|
402
|
+
if (field.type === 'multiselect') return false
|
|
396
403
|
if (fieldItemFields(field)?.length) return true
|
|
397
404
|
if (Array.isArray(value)) return true
|
|
398
405
|
return (
|
|
@@ -475,7 +482,11 @@ function formatDisplayValue(rawValue: any, field: FieldDef): string {
|
|
|
475
482
|
if (value === null || value === undefined || value === '') return '—'
|
|
476
483
|
const objLabel = objectLabel(value)
|
|
477
484
|
if (objLabel !== undefined) return objLabel
|
|
478
|
-
if (field.type === 'boolean' || typeof value === 'boolean') return value ? 'Sí' : 'No'
|
|
485
|
+
if (field.type === 'boolean' || field.type === 'checkbox' || typeof value === 'boolean') return value ? 'Sí' : 'No'
|
|
486
|
+
if (isPasswordField(field)) return '••••••••'
|
|
487
|
+
if (field.type === 'multiselect' && Array.isArray(value)) {
|
|
488
|
+
return value.map(v => field.options?.find(o => o.value === String(v))?.label ?? String(v)).join(', ')
|
|
489
|
+
}
|
|
479
490
|
|
|
480
491
|
if (field.type === 'select' && field.options?.length) {
|
|
481
492
|
const match = field.options.find(o => o.value === String(value))
|
|
@@ -564,7 +575,7 @@ export function filterVisibleFields(
|
|
|
564
575
|
): FieldDef[] {
|
|
565
576
|
const values = formValues && attributeClasses ? { ...formValues, [ATTRIBUTE_CLASSES_KEY]: attributeClasses } : formValues
|
|
566
577
|
return (fields ?? []).filter(f => {
|
|
567
|
-
if (f.hidden) return false
|
|
578
|
+
if (f.hidden || f.type === 'hidden') return false
|
|
568
579
|
if (mode === 'create' && f.readonly) return false
|
|
569
580
|
if (values && !evaluateVisibleWhen(getVisibleWhen(f), values)) return false
|
|
570
581
|
return true
|
|
@@ -579,6 +590,11 @@ export function filterVisibleFields(
|
|
|
579
590
|
// visible fields — hidden fields are dropped from BOTH the render/required-gate
|
|
580
591
|
// AND the submitted values. Keys with no matching declared field, or whose
|
|
581
592
|
// field carries no `visible_when`, always pass through (retrocompat).
|
|
593
|
+
// NOTE: a `type:'hidden'` field is never in the visible set, so with a
|
|
594
|
+
// `visible_when` it is ALWAYS stripped (even when the predicate is true);
|
|
595
|
+
// without `visible_when` it passes through with its default. Pinned by tests.
|
|
596
|
+
// TODO(deuda): hay dos resolvers de campos (EditField de este diálogo y
|
|
597
|
+
// resolveWidget de dynamic-form); converger en uno solo.
|
|
582
598
|
export function stripHiddenFieldValues(
|
|
583
599
|
values: Record<string, any>,
|
|
584
600
|
fields: FieldDef[] | undefined,
|
|
@@ -595,6 +611,36 @@ export function stripHiddenFieldValues(
|
|
|
595
611
|
return out
|
|
596
612
|
}
|
|
597
613
|
|
|
614
|
+
/** `password` fields are write-only: never prefilled, never shown, and an empty value is not submitted. */
|
|
615
|
+
const isPasswordField = (f: FieldDef | undefined): boolean => f?.type === 'password'
|
|
616
|
+
|
|
617
|
+
// dropEmptyPasswords removes empty `password` fields from a submit payload:
|
|
618
|
+
// on edit an empty password means "keep the current one" (the record never
|
|
619
|
+
// carries it, so the input starts blank); on create an optional empty password
|
|
620
|
+
// must not send "" to the server either.
|
|
621
|
+
export function dropEmptyPasswords(
|
|
622
|
+
values: Record<string, any>,
|
|
623
|
+
fields: FieldDef[] | undefined,
|
|
624
|
+
): Record<string, any> {
|
|
625
|
+
const out = { ...values }
|
|
626
|
+
for (const f of fields ?? []) {
|
|
627
|
+
if (isPasswordField(f) && (out[f.key] === '' || out[f.key] == null)) delete out[f.key]
|
|
628
|
+
}
|
|
629
|
+
return out
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// requiredGateFields leaves out, on edit, the password fields left empty: an
|
|
633
|
+
// empty password on edit means "keep the current one" (it is not submitted), so
|
|
634
|
+
// a `required` password must not block saving. On create it stays required.
|
|
635
|
+
function requiredGateFields(
|
|
636
|
+
fields: FieldDef[],
|
|
637
|
+
mode: 'view' | 'edit' | 'create',
|
|
638
|
+
values: Record<string, any>,
|
|
639
|
+
): FieldDef[] {
|
|
640
|
+
if (mode !== 'edit') return fields
|
|
641
|
+
return fields.filter(f => !(isPasswordField(f) && (values[f.key] === '' || values[f.key] == null)))
|
|
642
|
+
}
|
|
643
|
+
|
|
598
644
|
function applyEnsureFields(meta: ModalMetadata | null | undefined, ensureFields?: FieldDef[]): ModalMetadata | null {
|
|
599
645
|
if (!meta) return meta ?? null
|
|
600
646
|
if (!ensureFields?.length) return meta
|
|
@@ -697,7 +743,9 @@ export function DynamicRecordDialog({
|
|
|
697
743
|
const seedForm = (meta: ModalMetadata, rec: any) => {
|
|
698
744
|
const initial: Record<string, any> = {}
|
|
699
745
|
for (const field of meta.fields ?? []) {
|
|
700
|
-
initial[field.key] =
|
|
746
|
+
initial[field.key] = isPasswordField(field)
|
|
747
|
+
? ''
|
|
748
|
+
: resolvePath(rec, field.key) ?? field.defaultValue ?? ''
|
|
701
749
|
}
|
|
702
750
|
setFormValues(initial)
|
|
703
751
|
}
|
|
@@ -840,6 +888,7 @@ export function DynamicRecordDialog({
|
|
|
840
888
|
setFormValues(prev => {
|
|
841
889
|
const next = { ...prev }
|
|
842
890
|
for (const field of modalMeta?.fields ?? []) {
|
|
891
|
+
if (isPasswordField(field)) continue
|
|
843
892
|
const v = resolvePath(rec, field.key)
|
|
844
893
|
if (v !== undefined) next[field.key] = v
|
|
845
894
|
}
|
|
@@ -897,7 +946,7 @@ export function DynamicRecordDialog({
|
|
|
897
946
|
// Laravel-style: collect every issue from the shared validator
|
|
898
947
|
// (required + rule strings / min/max / email…) on visible fields only.
|
|
899
948
|
const visible = filterVisibleFields(modalMeta.fields, mode, formValues, attributeClasses)
|
|
900
|
-
let bag = validateValues(visible as ActionFieldDef[], formValues)
|
|
949
|
+
let bag = validateValues(requiredGateFields(visible, mode, formValues) as ActionFieldDef[], formValues)
|
|
901
950
|
// Edit: a legacy value re-sent unchanged is not re-judged by a rule
|
|
902
951
|
// added after it was written (same grandfathering as the kernel).
|
|
903
952
|
if (mode === 'edit' && record) {
|
|
@@ -941,7 +990,10 @@ export function DynamicRecordDialog({
|
|
|
941
990
|
|
|
942
991
|
// Empty reference pickers → null (not "" / nil-UUID) so nullable FK
|
|
943
992
|
// columns accept them instead of raising a 23503 FK violation.
|
|
944
|
-
let payload =
|
|
993
|
+
let payload = dropEmptyPasswords(
|
|
994
|
+
normalizeRefFieldsForSubmit(submittedValues, modalMeta.fields),
|
|
995
|
+
modalMeta.fields,
|
|
996
|
+
)
|
|
945
997
|
|
|
946
998
|
if (
|
|
947
999
|
isCreate &&
|
|
@@ -1081,7 +1133,7 @@ export function DynamicRecordDialog({
|
|
|
1081
1133
|
const goNextStep = () => {
|
|
1082
1134
|
const step = groups[clampedStep]
|
|
1083
1135
|
const stepFields = step?.fields ?? []
|
|
1084
|
-
const bag = validateValues(stepFields as ActionFieldDef[], formValues)
|
|
1136
|
+
const bag = validateValues(requiredGateFields(stepFields, mode, formValues) as ActionFieldDef[], formValues)
|
|
1085
1137
|
if (bagHasErrors(bag)) {
|
|
1086
1138
|
const labels: Record<string, string> = {}
|
|
1087
1139
|
for (const f of stepFields) labels[f.key] = localizeFieldLabel(f.label, t)
|
|
@@ -1346,7 +1398,7 @@ function FieldRow({ field, record, value, mode, onChange, error, locked }: Field
|
|
|
1346
1398
|
) : isEditReadonly ? (
|
|
1347
1399
|
<ReadonlyEditField field={field} value={value} />
|
|
1348
1400
|
) : (
|
|
1349
|
-
<EditField field={field} value={value} onChange={onChange} record={record} invalid={!!error} />
|
|
1401
|
+
<EditField field={field} value={value} onChange={onChange} record={record} invalid={!!error} error={error} />
|
|
1350
1402
|
)}
|
|
1351
1403
|
|
|
1352
1404
|
{error && mode !== 'view' && (
|
|
@@ -1361,8 +1413,15 @@ function FieldRow({ field, record, value, mode, onChange, error, locked }: Field
|
|
|
1361
1413
|
// edits. Booleans render as a disabled switch to match their editable
|
|
1362
1414
|
// counterpart; everything else renders the formatted display value in a disabled
|
|
1363
1415
|
// text input.
|
|
1416
|
+
const noopChange = () => {}
|
|
1417
|
+
|
|
1364
1418
|
export function ReadonlyEditField({ field, value }: { field: FieldDef; value: any }) {
|
|
1365
|
-
|
|
1419
|
+
useFieldWidgetRegistryVersion()
|
|
1420
|
+
const HostWidget = getFieldWidget(field.widget)
|
|
1421
|
+
if (HostWidget) {
|
|
1422
|
+
return <HostWidget field={field as unknown as ActionFieldDef} value={value} onChange={noopChange} disabled />
|
|
1423
|
+
}
|
|
1424
|
+
if (field.type === 'boolean' || field.type === 'checkbox' || typeof value === 'boolean') {
|
|
1366
1425
|
return (
|
|
1367
1426
|
<div className="flex items-center gap-2 py-1">
|
|
1368
1427
|
<Switch checked={!!value} disabled />
|
|
@@ -1580,7 +1639,7 @@ export function ViewValue({
|
|
|
1580
1639
|
return <p className="text-sm py-1">{inlineLabel}</p>
|
|
1581
1640
|
}
|
|
1582
1641
|
|
|
1583
|
-
if (field.type === 'boolean' || typeof value === 'boolean') {
|
|
1642
|
+
if (field.type === 'boolean' || field.type === 'checkbox' || typeof value === 'boolean') {
|
|
1584
1643
|
return (
|
|
1585
1644
|
<div className="flex items-center gap-2 py-1">
|
|
1586
1645
|
<Switch checked={!!value} disabled />
|
|
@@ -1631,6 +1690,22 @@ export function ViewValue({
|
|
|
1631
1690
|
)
|
|
1632
1691
|
}
|
|
1633
1692
|
|
|
1693
|
+
// Explicit `type: 'icon'`: any stored icon format via the universal resolver.
|
|
1694
|
+
if (renderAs === 'icon') {
|
|
1695
|
+
const empty = <p className="text-sm py-1 text-muted-foreground">-</p>
|
|
1696
|
+
if (!value) return empty
|
|
1697
|
+
return (
|
|
1698
|
+
<div className="py-1">
|
|
1699
|
+
<Icon
|
|
1700
|
+
name={value}
|
|
1701
|
+
className="h-6 w-6"
|
|
1702
|
+
fallback={empty}
|
|
1703
|
+
resolveImageSrc={(src) => (/^(?:data:|https?:)/i.test(src) ? src : getImageUrl(src))}
|
|
1704
|
+
/>
|
|
1705
|
+
</div>
|
|
1706
|
+
)
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1634
1709
|
if (field.type === 'image' || renderAs === 'image') {
|
|
1635
1710
|
if (isLucideIconName(value)) {
|
|
1636
1711
|
return <IconNameViewValue name={value} />
|
|
@@ -1989,7 +2064,7 @@ function JsonObjectViewValue({ value }: { value: Record<string, unknown> }) {
|
|
|
1989
2064
|
)
|
|
1990
2065
|
}
|
|
1991
2066
|
|
|
1992
|
-
export function EditField({ field, value, onChange, record, invalid }: {
|
|
2067
|
+
export function EditField({ field, value, onChange, record, invalid, error }: {
|
|
1993
2068
|
field: FieldDef
|
|
1994
2069
|
value: any
|
|
1995
2070
|
onChange: (val: any) => void
|
|
@@ -1997,6 +2072,8 @@ export function EditField({ field, value, onChange, record, invalid }: {
|
|
|
1997
2072
|
record?: any
|
|
1998
2073
|
/** When true, paint the control with a destructive border (Laravel-style). */
|
|
1999
2074
|
invalid?: boolean
|
|
2075
|
+
/** Validation message, forwarded to a host-registered field widget. */
|
|
2076
|
+
error?: string
|
|
2000
2077
|
}) {
|
|
2001
2078
|
const invalidCls = invalid
|
|
2002
2079
|
? 'border-destructive ring-1 ring-destructive/30 focus-visible:ring-destructive aria-invalid:border-destructive'
|
|
@@ -2006,6 +2083,22 @@ export function EditField({ field, value, onChange, record, invalid }: {
|
|
|
2006
2083
|
const editFieldImageUrl = useContext(ImageUrlContext)
|
|
2007
2084
|
const dialogModel = useContext(RecordDialogModelContext)
|
|
2008
2085
|
|
|
2086
|
+
// Host-registered widget (`widget: "<name>"`) wins over every built-in and
|
|
2087
|
+
// type-based branch. Unregistered names fall through untouched.
|
|
2088
|
+
useFieldWidgetRegistryVersion()
|
|
2089
|
+
const HostWidget = getFieldWidget(field.widget)
|
|
2090
|
+
if (HostWidget) {
|
|
2091
|
+
return (
|
|
2092
|
+
<HostWidget
|
|
2093
|
+
field={field as unknown as ActionFieldDef}
|
|
2094
|
+
value={value}
|
|
2095
|
+
onChange={onChange}
|
|
2096
|
+
error={error}
|
|
2097
|
+
record={record}
|
|
2098
|
+
/>
|
|
2099
|
+
)
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2009
2102
|
// Jsonb line-items columns (e.g. Transfer.items) are action-built documents:
|
|
2010
2103
|
// editing the array field-by-field is out of scope. Render them READ-ONLY
|
|
2011
2104
|
// with the same inline table the detail view uses — a localized, ref-resolved
|
|
@@ -2044,6 +2137,38 @@ export function EditField({ field, value, onChange, record, invalid }: {
|
|
|
2044
2137
|
)
|
|
2045
2138
|
}
|
|
2046
2139
|
|
|
2140
|
+
// Checkbox: boolean like `boolean`, rendered as a checkbox with its label.
|
|
2141
|
+
if (field.type === 'checkbox') {
|
|
2142
|
+
return (
|
|
2143
|
+
<div className="flex items-center gap-2 py-1">
|
|
2144
|
+
<Checkbox
|
|
2145
|
+
checked={value === true || value === 'true'}
|
|
2146
|
+
onCheckedChange={(c: boolean | 'indeterminate') => onChange(c === true)}
|
|
2147
|
+
aria-invalid={invalid || undefined}
|
|
2148
|
+
/>
|
|
2149
|
+
</div>
|
|
2150
|
+
)
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
// Multiselect: array of ids/values. A `ref`/`searchEndpoint` resolves options
|
|
2154
|
+
// remotely (same contract as `multiple`); otherwise the static `options`.
|
|
2155
|
+
if (field.type === 'multiselect') {
|
|
2156
|
+
return (
|
|
2157
|
+
<DynamicMultiSelectField
|
|
2158
|
+
field={field as ActionFieldDef}
|
|
2159
|
+
value={value}
|
|
2160
|
+
onChange={onChange}
|
|
2161
|
+
staticOptions={field.options}
|
|
2162
|
+
/>
|
|
2163
|
+
)
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
// File: generic uploader (POST to the host upload endpoint, stores the
|
|
2167
|
+
// returned url/path). `image` / `widget: 'upload'` keep the image dropzone.
|
|
2168
|
+
if (field.type === 'file') {
|
|
2169
|
+
return <UploadField field={field as ActionFieldDef} value={value} onChange={onChange} />
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2047
2172
|
if (field.type === 'textarea') {
|
|
2048
2173
|
return (
|
|
2049
2174
|
<Textarea
|
|
@@ -2221,7 +2346,13 @@ export function EditField({ field, value, onChange, record, invalid }: {
|
|
|
2221
2346
|
? 'number'
|
|
2222
2347
|
: field.type === 'email'
|
|
2223
2348
|
? 'email'
|
|
2224
|
-
: '
|
|
2349
|
+
: field.type === 'password'
|
|
2350
|
+
? 'password'
|
|
2351
|
+
: field.type === 'phone' || field.type === 'tel'
|
|
2352
|
+
? 'tel'
|
|
2353
|
+
: field.type === 'time'
|
|
2354
|
+
? 'time'
|
|
2355
|
+
: 'text'
|
|
2225
2356
|
|
|
2226
2357
|
return <ScannableRecordInput field={field} value={value} onChange={onChange} inputType={inputType} invalid={invalid} className={invalidCls} />
|
|
2227
2358
|
}
|
|
@@ -2270,6 +2401,7 @@ function ScannableRecordInput({
|
|
|
2270
2401
|
)
|
|
2271
2402
|
}
|
|
2272
2403
|
placeholder={field.placeholder}
|
|
2404
|
+
autoComplete={inputType === 'password' ? 'new-password' : undefined}
|
|
2273
2405
|
aria-invalid={invalid || undefined}
|
|
2274
2406
|
className={className}
|
|
2275
2407
|
/>
|
package/src/dynamic-columns.tsx
CHANGED
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
} from './display-value'
|
|
50
50
|
import { MediaValue } from './rich-url'
|
|
51
51
|
import { OptionsContext } from './options-context'
|
|
52
|
-
import { DynamicIcon, isLucideIconName } from './dynamic-icon'
|
|
52
|
+
import { DynamicIcon, Icon, isLucideIconName } from './dynamic-icon'
|
|
53
53
|
import { CollectionCell } from './collection-cell'
|
|
54
54
|
import { isNilUuid, normalizeNilUuid } from './nil-uuid'
|
|
55
55
|
import { useOptionsResolver } from './use-options-resolver'
|
|
@@ -1482,6 +1482,27 @@ export function makeDefaultGetDynamicColumns(
|
|
|
1482
1482
|
return <ImageCell value={imageSrc} getImageUrl={getImageUrl} />
|
|
1483
1483
|
}
|
|
1484
1484
|
|
|
1485
|
+
case 'icon': {
|
|
1486
|
+
// Explicit `type: 'icon'` only: any stored icon format
|
|
1487
|
+
// (Lucide, FontAwesome classes, emoji, image URL).
|
|
1488
|
+
// Uninterpretable values show the dash, never raw text.
|
|
1489
|
+
if (!value) return <EmptyCell />
|
|
1490
|
+
return (
|
|
1491
|
+
<Icon
|
|
1492
|
+
name={value}
|
|
1493
|
+
className="h-5 w-5 text-foreground/80"
|
|
1494
|
+
fallback={<EmptyCell />}
|
|
1495
|
+
resolveImageSrc={(src) =>
|
|
1496
|
+
/^(?:data:|https?:)/i.test(src)
|
|
1497
|
+
? src
|
|
1498
|
+
: getImageUrl(
|
|
1499
|
+
resolveImageSrc(col, src, apiBaseUrl, normalizeImagePath),
|
|
1500
|
+
)
|
|
1501
|
+
}
|
|
1502
|
+
/>
|
|
1503
|
+
)
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1485
1506
|
case 'image_stack': {
|
|
1486
1507
|
// Defensive: normally handled above before the
|
|
1487
1508
|
// switch; kept so a late `type: image_stack` without
|
package/src/dynamic-form.tsx
CHANGED
|
@@ -39,6 +39,7 @@ import { DynamicDateField } from './dynamic-date-field'
|
|
|
39
39
|
import { UploadField } from './upload-field'
|
|
40
40
|
import { IconPickerField } from './icon-picker-field'
|
|
41
41
|
import { ColorPickerField } from './color-picker-field'
|
|
42
|
+
import { getFieldWidget, useFieldWidgetRegistryVersion } from './field-widget-registry'
|
|
42
43
|
|
|
43
44
|
export { buildZodSchema, resolveWidget }
|
|
44
45
|
export { DynamicLineItems } from './dynamic-line-items'
|
|
@@ -388,6 +389,7 @@ function FieldRow({ field, value, onChange, values, error, initialValues }: Fiel
|
|
|
388
389
|
initialValues={initialValues}
|
|
389
390
|
values={values}
|
|
390
391
|
effectiveOptions={effectiveOptions}
|
|
392
|
+
error={error}
|
|
391
393
|
/>
|
|
392
394
|
{error && <span className="text-red-500 text-sm" role="alert">{error}</span>}
|
|
393
395
|
</div>
|
|
@@ -426,8 +428,17 @@ function FieldRenderer({
|
|
|
426
428
|
value,
|
|
427
429
|
onChange,
|
|
428
430
|
initialValues,
|
|
431
|
+
values,
|
|
429
432
|
effectiveOptions,
|
|
430
|
-
|
|
433
|
+
error,
|
|
434
|
+
}: FieldRendererProps & { effectiveOptions?: import('./types').OptionDef[]; error?: string }) {
|
|
435
|
+
// Host-registered widget (`widget: "<name>"`) wins over every built-in and
|
|
436
|
+
// type-based branch. Unregistered names fall through untouched.
|
|
437
|
+
useFieldWidgetRegistryVersion()
|
|
438
|
+
const HostWidget = getFieldWidget(field.widget)
|
|
439
|
+
if (HostWidget) {
|
|
440
|
+
return <HostWidget field={field} value={value} onChange={onChange} error={error} record={values} />
|
|
441
|
+
}
|
|
431
442
|
// Repeatable line-items group → render the row grid. Its value is an array
|
|
432
443
|
// of row objects rather than a scalar.
|
|
433
444
|
if (isLineItemsField(field)) {
|