@asteby/metacore-runtime-react 53.27.0 → 53.29.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/business/customer-picker.d.ts +10 -1
  3. package/dist/business/customer-picker.d.ts.map +1 -1
  4. package/dist/business/customer-picker.js +7 -2
  5. package/dist/dialogs/create-record-dialog.d.ts +1 -1
  6. package/dist/dialogs/create-record-dialog.d.ts.map +1 -1
  7. package/dist/dialogs/create-record-dialog.js +2 -2
  8. package/dist/dialogs/dynamic-record.d.ts +19 -2
  9. package/dist/dialogs/dynamic-record.d.ts.map +1 -1
  10. package/dist/dialogs/dynamic-record.js +83 -25
  11. package/dist/dialogs/types.d.ts +6 -0
  12. package/dist/dialogs/types.d.ts.map +1 -1
  13. package/dist/dynamic-crud-page.d.ts.map +1 -1
  14. package/dist/dynamic-crud-page.js +3 -0
  15. package/dist/dynamic-form.d.ts.map +1 -1
  16. package/dist/dynamic-form.js +6 -5
  17. package/dist/field-widget-registry.d.ts +6 -0
  18. package/dist/field-widget-registry.d.ts.map +1 -1
  19. package/dist/index.d.ts +4 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +3 -1
  22. package/dist/loom/index.d.ts +9 -0
  23. package/dist/loom/index.d.ts.map +1 -0
  24. package/dist/loom/index.js +9 -0
  25. package/dist/loom/overlay.d.ts +74 -0
  26. package/dist/loom/overlay.d.ts.map +1 -0
  27. package/dist/loom/overlay.js +142 -0
  28. package/dist/loom/proposals.d.ts +26 -0
  29. package/dist/loom/proposals.d.ts.map +1 -0
  30. package/dist/loom/proposals.js +74 -0
  31. package/dist/loom/provider.d.ts +28 -0
  32. package/dist/loom/provider.d.ts.map +1 -0
  33. package/dist/loom/provider.js +31 -0
  34. package/dist/loom/resolve.d.ts +23 -0
  35. package/dist/loom/resolve.d.ts.map +1 -0
  36. package/dist/loom/resolve.js +138 -0
  37. package/dist/loom/seam.d.ts +28 -0
  38. package/dist/loom/seam.d.ts.map +1 -0
  39. package/dist/loom/seam.js +127 -0
  40. package/dist/loom/seams.d.ts +31 -0
  41. package/dist/loom/seams.d.ts.map +1 -0
  42. package/dist/loom/seams.js +21 -0
  43. package/dist/loom/store.d.ts +16 -0
  44. package/dist/loom/store.d.ts.map +1 -0
  45. package/dist/loom/store.js +72 -0
  46. package/dist/loom/types.d.ts +153 -0
  47. package/dist/loom/types.d.ts.map +1 -0
  48. package/dist/loom/types.js +1 -0
  49. package/dist/model-labels.d.ts +26 -0
  50. package/dist/model-labels.d.ts.map +1 -1
  51. package/dist/model-labels.js +22 -5
  52. package/dist/record-picker-dialog.d.ts +10 -1
  53. package/dist/record-picker-dialog.d.ts.map +1 -1
  54. package/dist/record-picker-dialog.js +18 -3
  55. package/dist/record-picker.d.ts +6 -0
  56. package/dist/record-picker.d.ts.map +1 -1
  57. package/dist/record-picker.js +4 -1
  58. package/dist/types.d.ts +10 -0
  59. package/dist/types.d.ts.map +1 -1
  60. package/package.json +6 -6
  61. package/src/__tests__/dynamic-record-seam.test.tsx +194 -0
  62. package/src/__tests__/dynamic-record-texts.test.tsx +22 -0
  63. package/src/__tests__/field-widget-set-values.test.tsx +65 -0
  64. package/src/__tests__/loom-overlay.test.ts +94 -0
  65. package/src/__tests__/loom-resolve.test.ts +108 -0
  66. package/src/__tests__/model-labels.test.tsx +41 -1
  67. package/src/__tests__/record-picker-open-on-focus.test.tsx +49 -0
  68. package/src/business/customer-picker.tsx +17 -0
  69. package/src/dialogs/create-record-dialog.tsx +6 -0
  70. package/src/dialogs/dynamic-record.tsx +131 -26
  71. package/src/dialogs/types.ts +6 -0
  72. package/src/dynamic-crud-page.tsx +3 -0
  73. package/src/dynamic-form.tsx +9 -2
  74. package/src/field-widget-registry.tsx +6 -0
  75. package/src/index.ts +4 -1
  76. package/src/loom/index.ts +36 -0
  77. package/src/loom/overlay.ts +196 -0
  78. package/src/loom/proposals.tsx +156 -0
  79. package/src/loom/provider.tsx +69 -0
  80. package/src/loom/resolve.ts +136 -0
  81. package/src/loom/seam.tsx +235 -0
  82. package/src/loom/seams.ts +42 -0
  83. package/src/loom/store.ts +81 -0
  84. package/src/loom/types.ts +167 -0
  85. package/src/model-labels.ts +45 -5
  86. package/src/record-picker-dialog.tsx +42 -1
  87. package/src/record-picker.tsx +10 -0
  88. package/src/types.ts +10 -0
@@ -10,6 +10,7 @@
10
10
  // the image-url resolver and the org IANA timezone — are passed as props so the
11
11
  // SDK stays transport- and host-agnostic.
12
12
  import { emitRecordMutation } from '../record-mutation-events'
13
+ import { modelVerbTitle, resolveModelNoun } from '../model-labels'
13
14
  import { createContext, lazy, Suspense, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from 'react'
14
15
  import { useTranslation } from 'react-i18next'
15
16
  import type { ModelSchema } from './types'
@@ -100,6 +101,9 @@ import { CollectionCell, type ItemField } from '../collection-cell'
100
101
  import type { ActionFieldDef, RelationMeta } from '../types'
101
102
  import { ImageUrlContext, identityImageUrl, type GetImageUrl } from '../image-url-context'
102
103
  import { getFieldWidget, useFieldWidgetRegistryVersion } from '../field-widget-registry'
104
+ import { Seam } from '../loom/seam'
105
+ import { ProposalReview, useProposalQueue } from '../loom/proposals'
106
+ import { RECORD_FORM_SECTION, recordDialogHeaderContract } from '../loom/seams'
103
107
  import { TimeZoneContext, CurrencyContext, useNumberLocale, useSystemActor } from '../org-runtime-context'
104
108
  import { AuthorshipCell, hasSpecialAuthorship, readProvenance } from '../provenance'
105
109
 
@@ -286,6 +290,9 @@ interface ModalMetadata {
286
290
  titleKey?: string
287
291
  createTitle?: string
288
292
  editTitle?: string
293
+ /** Backend-localized singular noun ("cliente"): feeds "Crear/Editar/Eliminar {noun}". Host i18n `models.<model>.singular` wins. */
294
+ singular_label?: string
295
+ singularLabel?: string
289
296
  /**
290
297
  * Optional per-model dialog texts. When present they replace the generic
291
298
  * description / submit label of the mode; absent → the built-in texts.
@@ -334,13 +341,17 @@ interface ModalMetadata {
334
341
  messages?: { created?: string; updated?: string; deleted?: string }
335
342
  }
336
343
 
337
- type TFn = (key: string) => string
344
+ type TFn = (key: string, opts?: Record<string, unknown>) => string
338
345
 
339
346
  // localizedModelName resolves the (possibly addon-i18n) model name: prefer the
340
347
  // translated titleKey, fall back to the backend-provided raw title.
341
- function localizedModelName(meta: ModalMetadata, t: TFn): string {
342
- if (meta.titleKey && t(meta.titleKey) !== meta.titleKey) return t(meta.titleKey)
343
- return meta.title || ''
348
+ function localizedModelName(meta: ModalMetadata, t: TFn, model = ''): string {
349
+ return resolveModelNoun(t, {
350
+ model,
351
+ singularLabel: meta.singular_label ?? meta.singularLabel,
352
+ titleKey: meta.titleKey,
353
+ title: meta.title,
354
+ })
344
355
  }
345
356
 
346
357
  export interface DynamicRecordDialogProps {
@@ -444,6 +455,16 @@ export interface DynamicRecordDialogProps {
444
455
  * own list/detail query so the parent row's totals refresh underneath.
445
456
  */
446
457
  onChange?: () => void
458
+ /**
459
+ * Intenciones que piden los injertos del seam `record.dialog.header` (Loom, RFC 0005):
460
+ * `record.select` `{ record }` y `record.edit` `{ id, patch }`. Devuelve true si la atendió.
461
+ */
462
+ onIntent?: (intent: string, payload: unknown) => boolean
463
+ /**
464
+ * Propuesta inicial (p. ej. la que trae una intención `record.edit`): se muestra como diff
465
+ * revisable sobre el registro cargado. Sólo pasan campos editables del formulario.
466
+ */
467
+ initialProposal?: { patch: Record<string, unknown>; reason?: string; labels?: Record<string, string>; apply?: 'review' | 'auto' }
447
468
  }
448
469
 
449
470
  function resolvePath(obj: any, path: string): any {
@@ -642,9 +663,9 @@ function modeTexts(
642
663
 
643
664
  const MODE_CONFIG = {
644
665
  create: {
645
- getTitle: (meta: ModalMetadata, t: TFn) => {
646
- const name = localizedModelName(meta, t)
647
- return name ? `Crear ${name}` : (meta.createTitle || meta.title || 'Nuevo registro')
666
+ getTitle: (meta: ModalMetadata, t: TFn, model = '') => {
667
+ const name = localizedModelName(meta, t, model)
668
+ return name ? modelVerbTitle(t, 'create', name, `Crear ${name}`) : (meta.createTitle || meta.title || 'Nuevo registro')
648
669
  },
649
670
  description: 'Completa los campos para crear un nuevo registro.',
650
671
  submitLabel: 'Crear',
@@ -652,9 +673,9 @@ const MODE_CONFIG = {
652
673
  cancelLabel: 'Cancelar',
653
674
  },
654
675
  edit: {
655
- getTitle: (meta: ModalMetadata, t: TFn) => {
656
- const name = localizedModelName(meta, t)
657
- return name ? `Editar ${name}` : (meta.editTitle || meta.title || 'Editar registro')
676
+ getTitle: (meta: ModalMetadata, t: TFn, model = '') => {
677
+ const name = localizedModelName(meta, t, model)
678
+ return name ? modelVerbTitle(t, 'edit', name, `Editar ${name}`) : (meta.editTitle || meta.title || 'Editar registro')
658
679
  },
659
680
  description: 'Modifica los campos y guarda los cambios.',
660
681
  submitLabel: 'Guardar cambios',
@@ -662,7 +683,7 @@ const MODE_CONFIG = {
662
683
  cancelLabel: 'Cancelar',
663
684
  },
664
685
  view: {
665
- getTitle: (meta: ModalMetadata, t: TFn) => localizedModelName(meta, t) || meta.title || 'Ver registro',
686
+ getTitle: (meta: ModalMetadata, t: TFn, model = '') => localizedModelName(meta, t, model) || meta.title || 'Ver registro',
666
687
  description: 'Información detallada del registro.',
667
688
  submitLabel: '',
668
689
  submittingLabel: '',
@@ -818,6 +839,8 @@ export function DynamicRecordDialog({
818
839
  timeZone,
819
840
  currency,
820
841
  onChange,
842
+ onIntent,
843
+ initialProposal,
821
844
  }: DynamicRecordDialogProps) {
822
845
  const api = useApi()
823
846
  const branchGate = useBranchCreateGate()
@@ -899,6 +922,54 @@ export function DynamicRecordDialog({
899
922
  (patch: Record<string, any>) => setFormValues(prev => ({ ...prev, ...patch })),
900
923
  [],
901
924
  )
925
+ // Loom: seam `record.dialog.header`. Los injertos proponen; el diálogo muestra el diff y aplica.
926
+ const proposals = useProposalQueue(formValues, applyPrefill)
927
+ const headerContract = useMemo(() => recordDialogHeaderContract(prefillAllowedKeys), [prefillAllowedKeys])
928
+ const sectionContract = useMemo(
929
+ () => recordDialogHeaderContract(prefillAllowedKeys, RECORD_FORM_SECTION),
930
+ [prefillAllowedKeys],
931
+ )
932
+ const headerLenses = useMemo(
933
+ () => ({
934
+ model,
935
+ mode: isCreate ? 'create' : 'edit',
936
+ recordId: recordId ?? undefined,
937
+ values: formValues,
938
+ fields: (modalMeta?.fields ?? []).map((f: any) => ({
939
+ key: String(f.key),
940
+ label: f.label ? localizeFieldLabel(f.label, t) : String(f.key),
941
+ type: f.type,
942
+ })),
943
+ }),
944
+ [model, isCreate, recordId, formValues, modalMeta, t],
945
+ )
946
+ const fieldLabelOf = useCallback(
947
+ (key: string) => headerLenses.fields.find(f => f.key === key)?.label ?? key,
948
+ [headerLenses],
949
+ )
950
+ // La propuesta inicial entra una vez, cuando el formulario ya tiene sus campos.
951
+ const seededProposal = useRef(false)
952
+ useEffect(() => {
953
+ if (!open) {
954
+ seededProposal.current = false
955
+ return
956
+ }
957
+ if (seededProposal.current || !initialProposal || loading || !modalMeta) return
958
+ seededProposal.current = true
959
+ const patch: Record<string, unknown> = {}
960
+ for (const [k, v] of Object.entries(initialProposal.patch)) if (prefillAllowedKeys.has(k)) patch[k] = v
961
+ if (!Object.keys(patch).length) return
962
+ proposals.push({
963
+ ...initialProposal,
964
+ patch,
965
+ id: 'host#initial',
966
+ graft: 'host.initial',
967
+ addon: 'host',
968
+ previous: {},
969
+ dropped: [],
970
+ })
971
+ // eslint-disable-next-line react-hooks/exhaustive-deps
972
+ }, [open, initialProposal, loading, modalMeta, prefillAllowedKeys])
902
973
  const config = MODE_CONFIG[mode]
903
974
 
904
975
  // ── Fetch metadata + record when dialog opens ──────────────────────────
@@ -1314,14 +1385,21 @@ export function DynamicRecordDialog({
1314
1385
  }
1315
1386
 
1316
1387
  const title = modalMeta
1317
- ? config.getTitle(modalMeta, t)
1388
+ ? config.getTitle(modalMeta, t, model)
1318
1389
  : mode === 'create'
1319
1390
  ? 'Nuevo registro'
1320
1391
  : mode === 'edit'
1321
1392
  ? 'Editar registro'
1322
1393
  : 'Ver registro'
1323
1394
 
1324
- const texts = modeTexts(modalMeta, mode, config)
1395
+ // Generic dialog texts go through the host's i18n (`dynamic.*`, es defaults) so an English host
1396
+ // gets English buttons without per-model metadata; per-model metadata texts still win.
1397
+ const texts = modeTexts(modalMeta, mode, {
1398
+ description: t(`dynamic.${mode}_description`, { defaultValue: config.description }),
1399
+ submitLabel: t(`dynamic.${mode}_submit`, { defaultValue: config.submitLabel }),
1400
+ })
1401
+ const submittingLabel = t(`dynamic.${mode}_submitting`, { defaultValue: config.submittingLabel })
1402
+ const cancelLabel = t(`dynamic.${mode}_cancel`, { defaultValue: config.cancelLabel })
1325
1403
 
1326
1404
  const visibleFields = filterVisibleFields(modalMeta?.fields, mode, formValues, attributeClasses)
1327
1405
 
@@ -1351,6 +1429,7 @@ export function DynamicRecordDialog({
1351
1429
  mode={mode}
1352
1430
  locked={isCreate && !!lockedFields?.includes(field.key)}
1353
1431
  error={fieldErrors[field.key]}
1432
+ setValues={patch => setFormValues((prev: Record<string, any>) => ({ ...prev, ...patch }))}
1354
1433
  onChange={val => {
1355
1434
  if (getDeriveFrom(field)) {
1356
1435
  if (val === '' || val == null) manualDerived.current.delete(field.key)
@@ -1433,6 +1512,16 @@ export function DynamicRecordDialog({
1433
1512
  onApply={applyPrefill}
1434
1513
  />
1435
1514
  )}
1515
+ {isEditable && (
1516
+ <Seam
1517
+ contract={headerContract}
1518
+ lenses={headerLenses}
1519
+ host={{ model, mode: isCreate ? 'create' : 'edit' }}
1520
+ onProposal={proposals.push}
1521
+ onIntent={onIntent ? (intent, payload) => onIntent(intent, payload) : undefined}
1522
+ />
1523
+ )}
1524
+ {isEditable && <ProposalReview queue={proposals} values={formValues} labelOf={fieldLabelOf} />}
1436
1525
  <form
1437
1526
  id={formId}
1438
1527
  // Stable Aby / guidance contract: unique id={formId}
@@ -1494,6 +1583,16 @@ export function DynamicRecordDialog({
1494
1583
  </div>
1495
1584
  )}
1496
1585
  </form>
1586
+ {isEditable && (
1587
+ <Seam
1588
+ contract={sectionContract}
1589
+ lenses={headerLenses}
1590
+ host={{ model, mode: isCreate ? 'create' : 'edit' }}
1591
+ onProposal={proposals.push}
1592
+ onIntent={onIntent ? (intent, payload) => onIntent(intent, payload) : undefined}
1593
+ className="mt-4 grid gap-3"
1594
+ />
1595
+ )}
1497
1596
 
1498
1597
 
1499
1598
  {/* Líneas del documento: SOLO las relaciones de
@@ -1580,11 +1679,11 @@ export function DynamicRecordDialog({
1580
1679
  on; the first step still shows Cancel. */}
1581
1680
  {isSteps && clampedStep > 0 ? (
1582
1681
  <Button variant="outline" onClick={goBackStep} disabled={saving || deleting}>
1583
- Anterior
1682
+ {t('dynamic.previous', { defaultValue: 'Anterior' })}
1584
1683
  </Button>
1585
1684
  ) : (
1586
1685
  <Button variant="outline" onClick={() => onOpenChange(false)} disabled={saving || deleting}>
1587
- {config.cancelLabel}
1686
+ {cancelLabel}
1588
1687
  </Button>
1589
1688
  )}
1590
1689
  {isView && onDelete && (
@@ -1594,12 +1693,12 @@ export function DynamicRecordDialog({
1594
1693
  disabled={deleting || loading}
1595
1694
  >
1596
1695
  {deleting && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
1597
- {deleting ? 'Eliminando...' : 'Eliminar'}
1696
+ {deleting ? t('dynamic.deleting', { defaultValue: 'Eliminando...' }) : t('dynamic.delete_confirm', { defaultValue: 'Eliminar' })}
1598
1697
  </Button>
1599
1698
  )}
1600
1699
  {isView && onEdit && (
1601
1700
  <Button onClick={onEdit} disabled={deleting || loading}>
1602
- Editar
1701
+ {t('dynamic.edit', { defaultValue: 'Editar' })}
1603
1702
  </Button>
1604
1703
  )}
1605
1704
  {/* Non-final wizard step → "Siguiente" validates the step
@@ -1607,7 +1706,7 @@ export function DynamicRecordDialog({
1607
1706
  every non-wizard form) keeps the real submit button. */}
1608
1707
  {isEditable && isSteps && !isLastStep && (
1609
1708
  <Button type="button" onClick={goNextStep} disabled={saving || loading}>
1610
- Siguiente
1709
+ {t('dynamic.next', { defaultValue: 'Siguiente' })}
1611
1710
  </Button>
1612
1711
  )}
1613
1712
  {isEditable && (!isSteps || isLastStep) && (
@@ -1617,7 +1716,7 @@ export function DynamicRecordDialog({
1617
1716
  disabled={saving || loading}
1618
1717
  >
1619
1718
  {saving && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
1620
- {saving ? config.submittingLabel : texts.submitLabel}
1719
+ {saving ? submittingLabel : texts.submitLabel}
1621
1720
  </Button>
1622
1721
  )}
1623
1722
  </div>
@@ -1647,6 +1746,8 @@ interface FieldRowProps {
1647
1746
  value: any
1648
1747
  mode: 'view' | 'edit' | 'create'
1649
1748
  onChange: (val: any) => void
1749
+ /** Patches several form values at once (forwarded to host field widgets). */
1750
+ setValues?: (patch: Record<string, any>) => void
1650
1751
  /** Localized validation error for this field, shown in red under the input. */
1651
1752
  error?: string
1652
1753
  /**
@@ -1658,7 +1759,7 @@ interface FieldRowProps {
1658
1759
  locked?: boolean
1659
1760
  }
1660
1761
 
1661
- function FieldRow({ field, record, value, mode, onChange, error, locked }: FieldRowProps) {
1762
+ function FieldRow({ field, record, value, mode, onChange, setValues, error, locked }: FieldRowProps) {
1662
1763
  // A `readonly` field is server/system-generated (e.g. the GitHub addon's
1663
1764
  // `number`/`github_url`, filled by the API after the outbound create). On
1664
1765
  // CREATE it is excluded from the form entirely (see `visibleFields`); on EDIT
@@ -1685,7 +1786,7 @@ function FieldRow({ field, record, value, mode, onChange, error, locked }: Field
1685
1786
  ) : isEditReadonly ? (
1686
1787
  <ReadonlyEditField field={field} value={value} />
1687
1788
  ) : (
1688
- <EditField field={field} value={value} onChange={onChange} record={record} invalid={!!error} error={error} labelId={labelId} />
1789
+ <EditField field={field} value={value} onChange={onChange} setValues={setValues} record={record} invalid={!!error} error={error} labelId={labelId} />
1689
1790
  )}
1690
1791
 
1691
1792
  {error && mode !== 'view' && (
@@ -2381,12 +2482,14 @@ function JsonObjectViewValue({ value }: { value: Record<string, unknown> }) {
2381
2482
  )
2382
2483
  }
2383
2484
 
2384
- export function EditField({ field, value, onChange, record, invalid, error, labelId }: {
2485
+ export function EditField({ field, value, onChange, setValues, record, invalid, error, labelId }: {
2385
2486
  field: FieldDef
2386
2487
  /** id de la etiqueta visible (FieldRow); el control de tres estados la referencia. */
2387
2488
  labelId?: string
2388
2489
  value: any
2389
2490
  onChange: (val: any) => void
2491
+ /** Patches several form values at once (forwarded to host field widgets). */
2492
+ setValues?: (patch: Record<string, any>) => void
2390
2493
  /** The full record being edited — supplies FK relation siblings + line-items. */
2391
2494
  record?: any
2392
2495
  /** When true, paint the control with a destructive border (Laravel-style). */
@@ -2413,6 +2516,7 @@ export function EditField({ field, value, onChange, record, invalid, error, labe
2413
2516
  field={field as unknown as ActionFieldDef}
2414
2517
  value={value}
2415
2518
  onChange={onChange}
2519
+ setValues={setValues}
2416
2520
  error={error}
2417
2521
  record={record}
2418
2522
  />
@@ -2616,7 +2720,7 @@ export function EditField({ field, value, onChange, record, invalid, error, labe
2616
2720
  return (
2617
2721
  <Select value={String(value ?? '')} onValueChange={onChange}>
2618
2722
  <SelectTrigger className={cn("w-full", invalidCls)} aria-invalid={invalid || undefined}>
2619
- <SelectValue placeholder="Seleccionar..." />
2723
+ <SelectValue placeholder={t('dynamic.select_placeholder', { defaultValue: 'Seleccionar...' })} />
2620
2724
  </SelectTrigger>
2621
2725
  <SelectContent>
2622
2726
  {field.options.map(opt => (
@@ -2674,7 +2778,7 @@ export function EditField({ field, value, onChange, record, invalid, error, labe
2674
2778
  <CalendarIcon className="mr-2 h-4 w-4" />
2675
2779
  {validDate
2676
2780
  ? format(validDate, 'PPP', { locale: es })
2677
- : "Seleccionar fecha"}
2781
+ : t('dynamic.select_date', { defaultValue: 'Seleccionar fecha' })}
2678
2782
  </Button>
2679
2783
  </PopoverTrigger>
2680
2784
  <PopoverContent className="w-auto p-0" align="start">
@@ -2901,6 +3005,7 @@ function extractArray(res: any): any[] {
2901
3005
  const searchCache = new Map<string, any[]>()
2902
3006
 
2903
3007
  function SearchField({ field, value, onChange }: { field: FieldDef; value: any; onChange: (val: any) => void }) {
3008
+ const { t } = useTranslation()
2904
3009
  const api = useApi()
2905
3010
  const [selectedLabel, setSelectedLabel] = useState('')
2906
3011
  const ep = field.searchEndpoint!
@@ -2947,14 +3052,14 @@ function SearchField({ field, value, onChange }: { field: FieldDef; value: any;
2947
3052
  selected={value ? { value, label: selectedLabel } : null}
2948
3053
  renderValue={() => (
2949
3054
  <span className={cn('min-w-0 flex-1 truncate', !selectedLabel && 'text-muted-foreground')}>
2950
- {selectedLabel || `Seleccionar ${what}...`}
3055
+ {selectedLabel || t('dynamic.select_what', { what, defaultValue: `Seleccionar ${what}...` })}
2951
3056
  </span>
2952
3057
  )}
2953
3058
  onSelect={(item) => {
2954
3059
  onChange(itemValue(item))
2955
3060
  setSelectedLabel(itemLabel(item))
2956
3061
  }}
2957
- searchPlaceholder={`Buscar ${what}...`}
3062
+ searchPlaceholder={t('dynamic.search_what', { what, defaultValue: `Buscar ${what}...` })}
2958
3063
  emptyText="Sin resultados."
2959
3064
  />
2960
3065
  )
@@ -113,6 +113,12 @@ export interface CreateRecordDialogProps extends RecordDialogProps {
113
113
  * Ignored outside create mode.
114
114
  */
115
115
  lockedFields?: string[]
116
+ /** Fields merged into the modal schema after load (see DynamicRecordDialog.ensureFields). */
117
+ ensureFields?: import('./dynamic-record').FieldDef[]
118
+ /** Intenciones del seam `record.dialog.header` (see DynamicRecordDialog.onIntent). */
119
+ onIntent?: (intent: string, payload: unknown) => boolean
120
+ /** Propuesta inicial mostrada como diff (see DynamicRecordDialog.initialProposal). */
121
+ initialProposal?: import('./dynamic-record').DynamicRecordDialogProps['initialProposal']
116
122
  /** Notification when a create or update succeeds. */
117
123
  onSaved?: () => void
118
124
  }
@@ -192,6 +192,9 @@ export function DynamicCRUDPage(props: DynamicCRUDPageProps) {
192
192
  model,
193
193
  title: metadata?.title,
194
194
  titleKey: metadata?.titleKey ?? metadata?.title_key,
195
+ singularLabel: metadata?.singular_label,
196
+ newLabelMeta: metadata?.new_label,
197
+ gender: metadata?.gender,
195
198
  titleOverride: titleOverride ?? ext?.title,
196
199
  newLabelOverride: newLabel ?? ext?.newLabel,
197
200
  newPrefix: strings.newPrefix,
@@ -241,6 +241,8 @@ export function DynamicForm({
241
241
  try { await onSubmit(data) } finally { setSubmitting(false) }
242
242
  }
243
243
 
244
+ const patchValues = (patch: Record<string, any>) => setValues((prev: Record<string, any>) => ({ ...prev, ...patch }))
245
+
244
246
  // Renders one group's fields into the responsive 2-column grid: scalar
245
247
  // header fields flow through it; line-items grids (and textareas) span full
246
248
  // width so the row table / memo gets room. Shared by every layout mode.
@@ -256,6 +258,7 @@ export function DynamicForm({
256
258
  error={errors[field.key]}
257
259
  initialValues={initialValues}
258
260
  onFieldMeta={onFieldMeta}
261
+ setValues={patchValues}
259
262
  />
260
263
  ))}
261
264
  </div>
@@ -376,6 +379,8 @@ interface FieldRendererProps {
376
379
  onFieldMeta?: (key: string, meta: { width?: number; height?: number }) => void
377
380
  /** id único (useId) de la etiqueta visible; el control de tres estados la referencia. */
378
381
  labelId?: string
382
+ /** Patches several form values at once (forwarded to host field widgets). */
383
+ setValues?: (patch: Record<string, any>) => void
379
384
  }
380
385
 
381
386
  interface FieldRowProps extends FieldRendererProps {
@@ -386,7 +391,7 @@ interface FieldRowProps extends FieldRendererProps {
386
391
  // component so a STATIC enum select whose options are all gated out by a sibling
387
392
  // value (`when`) can hide the ENTIRE row (label included) and run its reset
388
393
  // effect with valid hook ordering.
389
- function FieldRow({ field, value, onChange, values, error, initialValues, onFieldMeta }: FieldRowProps) {
394
+ function FieldRow({ field, value, onChange, values, error, initialValues, onFieldMeta, setValues }: FieldRowProps) {
390
395
  // Único por instancia: dos formularios montados con el mismo campo no chocan.
391
396
  const labelId = `${useId()}-label`
392
397
  const isStaticSelect =
@@ -427,6 +432,7 @@ function FieldRow({ field, value, onChange, values, error, initialValues, onFiel
427
432
  error={error}
428
433
  onFieldMeta={onFieldMeta}
429
434
  labelId={labelId}
435
+ setValues={setValues}
430
436
  />
431
437
  {error && <span className="text-red-500 text-sm" role="alert">{error}</span>}
432
438
  </div>
@@ -470,13 +476,14 @@ function FieldRenderer({
470
476
  error,
471
477
  onFieldMeta,
472
478
  labelId,
479
+ setValues,
473
480
  }: FieldRendererProps & { effectiveOptions?: import('./types').OptionDef[]; error?: string }) {
474
481
  // Host-registered widget (`widget: "<name>"`) wins over every built-in and
475
482
  // type-based branch. Unregistered names fall through untouched.
476
483
  useFieldWidgetRegistryVersion()
477
484
  const HostWidget = getFieldWidget(field.widget)
478
485
  if (HostWidget) {
479
- return <HostWidget field={field} value={value} onChange={onChange} error={error} record={values} />
486
+ return <HostWidget field={field} value={value} onChange={onChange} error={error} record={values} setValues={setValues} />
480
487
  }
481
488
  // Repeatable line-items group → render the row grid. Its value is an array
482
489
  // of row objects rather than a scalar.
@@ -37,6 +37,12 @@ export interface FieldWidgetProps {
37
37
  * record dialog (`EditField`) it is the loaded/edited record.
38
38
  */
39
39
  record?: Record<string, any>
40
+ /**
41
+ * Merge several sibling fields into the form at once. For widgets that fill
42
+ * the form from an external source (a scanned document, a lookup) instead of
43
+ * editing their own value. Absent where the host form cannot patch siblings.
44
+ */
45
+ setValues?: (patch: Record<string, any>) => void
40
46
  }
41
47
 
42
48
  export type FieldWidgetComponent = React.ComponentType<FieldWidgetProps>
package/src/index.ts CHANGED
@@ -344,6 +344,7 @@ export {
344
344
  } from './addon-layout-context'
345
345
  export * from './slot'
346
346
  export * from './slots'
347
+ export * from './loom'
347
348
  export * from './capability-gate'
348
349
  export {
349
350
  PermissionsProvider,
@@ -586,6 +587,8 @@ export { DynamicRecordDialog, ViewValue } from './dialogs/dynamic-record'
586
587
  export { normalizeRefFieldsForSubmit } from './dialogs/normalize-submit'
587
588
  export type { DynamicRecordDialogProps, FieldDef, FieldOption, GetImageUrl } from './dialogs/dynamic-record'
588
589
  export { CreateRecordDialog } from './dialogs/create-record-dialog'
590
+ export { useInfiniteScrollSentinel, dedupeById } from './use-infinite-scroll'
591
+ export type { UseInfiniteScrollOptions, InfiniteScrollRefs } from './use-infinite-scroll'
589
592
  export { EntitySelect } from './entity-select'
590
593
  export type { EntitySelectProps, EntitySelectOption } from './entity-select'
591
594
  // RecordPicker — the ONE "pick a related record" control (search, single /
@@ -912,5 +915,5 @@ export type { BatchLog as BulkImageBatchLog } from './bulk-image-import'
912
915
  export * from './attention'
913
916
  export * from './view-system'
914
917
 
915
- export { useModelLabels, resolveModelLabels, defaultSingular } from './model-labels'
918
+ export { useModelLabels, resolveModelLabels, resolveModelNoun, modelVerbTitle, defaultSingular } from './model-labels'
916
919
  export type { ModelLabels, ModelLabelInput, ModelLabelT } from './model-labels'
@@ -0,0 +1,36 @@
1
+ // Loom — sistema de contribuciones de UI (RFC 0005 del kernel).
2
+ export * from './types'
3
+ export {
4
+ registerGraft,
5
+ registerPart,
6
+ getPart,
7
+ listGrafts,
8
+ unregisterLoomByAddon,
9
+ clearLoom,
10
+ subscribeLoom,
11
+ loomVersion,
12
+ } from './store'
13
+ export { resolveSeam, attenuatePatch, matchesWrite, projectLenses, sensitiveClasses, redactMessage } from './resolve'
14
+ export { LoomProvider, useLoomConfig, type LoomProviderProps, type LoomConfig } from './provider'
15
+ export { Seam, SeamInspector, useSeam, type SeamProps, type SeamHostContext } from './seam'
16
+ export { useProposalQueue, ProposalReview, type ProposalQueue, type ProposalReviewProps } from './proposals'
17
+ export {
18
+ applyOverlays,
19
+ mergeConfig,
20
+ type PageBlock,
21
+ type BlockGraph,
22
+ type OverlayOp,
23
+ type OverlayScope,
24
+ type OverlayLayer,
25
+ type OverlayConflict,
26
+ type OverlayConflictReason,
27
+ type OverlayResult,
28
+ type BlockProvenance,
29
+ } from './overlay'
30
+ export {
31
+ RECORD_DIALOG_HEADER,
32
+ RECORD_FORM_SECTION,
33
+ recordDialogHeaderContract,
34
+ type RecordDialogHeaderLenses,
35
+ type RecordFormSeam,
36
+ } from './seams'