@asteby/metacore-runtime-react 53.13.0 → 53.14.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 (69) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/action-modal-dispatcher.d.ts +1 -1
  3. package/dist/action-modal-dispatcher.d.ts.map +1 -1
  4. package/dist/action-modal-dispatcher.js +31 -6
  5. package/dist/bulk-image-dialog.d.ts +0 -13
  6. package/dist/bulk-image-dialog.d.ts.map +1 -1
  7. package/dist/bulk-image-dialog.js +9 -280
  8. package/dist/bulk-image-import.d.ts +2 -24
  9. package/dist/bulk-image-import.d.ts.map +1 -1
  10. package/dist/bulk-image-import.js +11 -30
  11. package/dist/bulk-image-target.d.ts +25 -0
  12. package/dist/bulk-image-target.d.ts.map +1 -0
  13. package/dist/bulk-image-target.js +30 -0
  14. package/dist/bulk-image-wizard.d.ts +15 -0
  15. package/dist/bulk-image-wizard.d.ts.map +1 -0
  16. package/dist/bulk-image-wizard.js +282 -0
  17. package/dist/dialogs/dynamic-record.d.ts +8 -1
  18. package/dist/dialogs/dynamic-record.d.ts.map +1 -1
  19. package/dist/dialogs/dynamic-record.js +34 -4
  20. package/dist/dynamic-columns.d.ts.map +1 -1
  21. package/dist/dynamic-columns.js +4 -0
  22. package/dist/dynamic-form-schema.d.ts.map +1 -1
  23. package/dist/dynamic-form-schema.js +5 -1
  24. package/dist/dynamic-form.d.ts.map +1 -1
  25. package/dist/dynamic-form.js +28 -3
  26. package/dist/dynamic-kanban.d.ts.map +1 -1
  27. package/dist/dynamic-kanban.js +33 -1
  28. package/dist/dynamic-line-items.d.ts.map +1 -1
  29. package/dist/dynamic-line-items.js +9 -1
  30. package/dist/dynamic-table.d.ts.map +1 -1
  31. package/dist/dynamic-table.js +7 -0
  32. package/dist/field-grid.d.ts +3 -1
  33. package/dist/field-grid.d.ts.map +1 -1
  34. package/dist/field-grid.js +2 -2
  35. package/dist/index.d.ts +3 -2
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +1 -2
  38. package/dist/nullable-boolean.d.ts +48 -0
  39. package/dist/nullable-boolean.d.ts.map +1 -0
  40. package/dist/nullable-boolean.js +80 -0
  41. package/dist/tri-state-boolean-impl.d.ts +24 -0
  42. package/dist/tri-state-boolean-impl.d.ts.map +1 -0
  43. package/dist/tri-state-boolean-impl.js +35 -0
  44. package/dist/tri-state-boolean.d.ts +15 -0
  45. package/dist/tri-state-boolean.d.ts.map +1 -0
  46. package/dist/tri-state-boolean.js +24 -0
  47. package/dist/use-dynamic-filters.d.ts.map +1 -1
  48. package/dist/use-dynamic-filters.js +10 -0
  49. package/package.json +3 -3
  50. package/src/__tests__/bulk-image-dialog.test.tsx +3 -3
  51. package/src/__tests__/nullable-boolean.test.tsx +458 -0
  52. package/src/action-modal-dispatcher.tsx +32 -6
  53. package/src/bulk-image-dialog.tsx +21 -496
  54. package/src/bulk-image-import.ts +2 -51
  55. package/src/bulk-image-target.ts +55 -0
  56. package/src/bulk-image-wizard.tsx +494 -0
  57. package/src/dialogs/dynamic-record.tsx +53 -5
  58. package/src/dynamic-columns.tsx +3 -0
  59. package/src/dynamic-form-schema.ts +4 -1
  60. package/src/dynamic-form.tsx +31 -2
  61. package/src/dynamic-kanban.tsx +6 -1
  62. package/src/dynamic-line-items.tsx +9 -1
  63. package/src/dynamic-table.tsx +5 -0
  64. package/src/field-grid.tsx +4 -0
  65. package/src/index.ts +2 -8
  66. package/src/nullable-boolean.ts +96 -0
  67. package/src/tri-state-boolean-impl.tsx +71 -0
  68. package/src/tri-state-boolean.tsx +39 -0
  69. package/src/use-dynamic-filters.ts +8 -0
@@ -15,7 +15,7 @@
15
15
  // The host injects its axios-like client via <ApiProvider>; we no longer
16
16
  // depend on a bundler alias to `@/lib/api`.
17
17
  import { emitRecordMutationSettled } from './record-mutation-events'
18
- import { Suspense, useState, useCallback, useEffect, useMemo, useRef, useSyncExternalStore } from 'react'
18
+ import { Suspense, useState, useCallback, useEffect, useId, useMemo, useRef, useSyncExternalStore } from 'react'
19
19
  import { useTranslation } from 'react-i18next'
20
20
  import {
21
21
  Dialog,
@@ -96,6 +96,8 @@ import { federatedModalComponent, resolveFederatedModal } from './primitives/con
96
96
  import { installedPredicate, useContributionsVersion } from './primitives/use-contributions'
97
97
  import { isTodayToken, todayInZone } from './calendar-date'
98
98
  import { useTimeZone } from './org-runtime-context'
99
+ import { isNullableBooleanField, omitUntouchedNullBooleans, usesTriState } from './nullable-boolean'
100
+ import { TriStateBooleanField } from './tri-state-boolean'
99
101
 
100
102
  export type { ActionMetadata, ActionModalProps }
101
103
 
@@ -1088,6 +1090,8 @@ export function focusFirstInvalid(root: HTMLElement | null): HTMLElement | null
1088
1090
 
1089
1091
  function GenericActionModal({ open, onOpenChange, action, model, record, endpoint, onSuccess }: ActionModalProps) {
1090
1092
  const { t, i18n } = useTranslation()
1093
+ // Prefijo único por instancia para los ids de las etiquetas (aria-labelledby).
1094
+ const formUid = useId()
1091
1095
  // Addon-contributed labels (action + fields) are i18n keys whose locale
1092
1096
  // bundle loads asynchronously; translate at render so they don't render raw.
1093
1097
  // defaultValue keeps an already-localized string unchanged.
@@ -1285,7 +1289,10 @@ function GenericActionModal({ open, onOpenChange, action, model, record, endpoin
1285
1289
  setFormError(undefined)
1286
1290
  setExecuting(true)
1287
1291
  try {
1288
- let payload: Record<string, any> = { ...formData }
1292
+ // Un booleano NULL del registro que nadie tocó no viaja.
1293
+ let payload: Record<string, any> = record
1294
+ ? omitUntouchedNullBooleans({ ...formData }, action.fields, (k) => readRecordPath(record, k))
1295
+ : { ...formData }
1289
1296
  // Create-placement actions (and any create with no record) may need a
1290
1297
  // host branch stamp when the sidebar is on "Todas". Skip when the
1291
1298
  // form already collected branch_id, or the host has no gate.
@@ -1405,7 +1412,7 @@ function GenericActionModal({ open, onOpenChange, action, model, record, endpoin
1405
1412
  resolveWidget(field) === 'richtext'
1406
1413
  return (
1407
1414
  <FieldCell key={field.key} fullWidth={fullWidth}>
1408
- <FieldLabel htmlFor={field.key} required={field.required}>
1415
+ <FieldLabel id={`${formUid}${field.key}-label`} htmlFor={field.key} required={field.required}>
1409
1416
  {tl(field.label)}
1410
1417
  </FieldLabel>
1411
1418
  {renderField(
@@ -1415,6 +1422,7 @@ function GenericActionModal({ open, onOpenChange, action, model, record, endpoin
1415
1422
  formData,
1416
1423
  record,
1417
1424
  fieldErrors,
1425
+ `${formUid}${field.key}-label`,
1418
1426
  )}
1419
1427
  {fieldErrors[field.key] && (
1420
1428
  <p id={`${field.key}-error`} className="text-destructive text-xs mt-1" data-field-error={field.key}>
@@ -1506,6 +1514,13 @@ export function buildFieldDefaults(
1506
1514
  defaults[field.key] = fromRecord
1507
1515
  continue
1508
1516
  }
1517
+ // Booleano opcional en NULL en el registro: se siembra null («Sin
1518
+ // definir»), no el default ni `false`. Si el usuario no lo toca, la
1519
+ // llave no viaja (omitUntouchedNullBooleans) y el NULL se conserva.
1520
+ if (record && isNullableBooleanField(field) && readRecordPath(record, field.key) === null) {
1521
+ defaults[field.key] = null
1522
+ continue
1523
+ }
1509
1524
  defaults[field.key] = resolveFieldDefault(field, ctx) ?? (field.type === 'boolean' ? false : '')
1510
1525
  }
1511
1526
  return defaults
@@ -1533,6 +1548,7 @@ function wizardStepErrors(
1533
1548
  // single-page action form — no widget is duplicated.
1534
1549
  function WizardActionModal({ open, onOpenChange, action, model, record, endpoint, onSuccess }: ActionModalProps) {
1535
1550
  const { t, i18n } = useTranslation()
1551
+ const formUid = useId()
1536
1552
  const tl = (s: string) => t(s, { defaultValue: s })
1537
1553
  const api = useApi()
1538
1554
  const reasonPrompt = useReasonPrompt()
@@ -1611,7 +1627,12 @@ function WizardActionModal({ open, onOpenChange, action, model, record, endpoint
1611
1627
  const res = await reasonPrompt.run({
1612
1628
  title: tl(action.label),
1613
1629
  description: t('actions.reason_desc', { defaultValue: 'Esta acción pide el motivo. Queda en la bitácora del documento.' }),
1614
- request: (reason) => api.post(url, withApproval(reason ? { ...formData, reason } : formData, auth)),
1630
+ request: (reason) => {
1631
+ const data = record
1632
+ ? omitUntouchedNullBooleans(formData, steps.flatMap((s) => s.fields ?? []), (k) => readRecordPath(record, k))
1633
+ : formData
1634
+ return api.post(url, withApproval(reason ? { ...data, reason } : data, auth))
1635
+ },
1615
1636
  })
1616
1637
  if (!res) return
1617
1638
  const allFields = steps.flatMap(s => s.fields ?? [])
@@ -1697,10 +1718,10 @@ function WizardActionModal({ open, onOpenChange, action, model, record, endpoint
1697
1718
  resolveWidget(field) === 'richtext'
1698
1719
  return (
1699
1720
  <FieldCell key={field.key} fullWidth={fullWidth}>
1700
- <FieldLabel htmlFor={field.key} required={field.required}>
1721
+ <FieldLabel id={`${formUid}${field.key}-label`} htmlFor={field.key} required={field.required}>
1701
1722
  {tl(field.label)}
1702
1723
  </FieldLabel>
1703
- {renderField(field, formData[field.key], (v: any) => updateField(field.key, v), formData, record)}
1724
+ {renderField(field, formData[field.key], (v: any) => updateField(field.key, v), formData, record, undefined, `${formUid}${field.key}-label`)}
1704
1725
  </FieldCell>
1705
1726
  )
1706
1727
  })}
@@ -1804,6 +1825,8 @@ export function renderField(
1804
1825
  formValues?: Record<string, any>,
1805
1826
  record?: Record<string, any>,
1806
1827
  fieldErrors?: Record<string, string>,
1828
+ // id único de la etiqueta visible: el control de tres estados la referencia.
1829
+ labelId?: string,
1807
1830
  ) {
1808
1831
  // Repeatable line-items group → row grid (value is an array of row objects).
1809
1832
  // The header form values flow in so a cell can depend on a header field.
@@ -1871,6 +1894,9 @@ export function renderField(
1871
1894
  )
1872
1895
  }
1873
1896
  case 'switch':
1897
+ if (usesTriState(field, record ? readRecordPath(record, field.key) : undefined)) {
1898
+ return <TriStateBooleanField id={field.key} value={value} onChange={onChange} label={field.label} labelledBy={labelId} invalid={invalid} />
1899
+ }
1874
1900
  return <Switch id={field.key} checked={!!value} onCheckedChange={onChange} />
1875
1901
  case 'number':
1876
1902
  return <Input id={field.key} type="number" value={value ?? ''} onChange={(e: React.ChangeEvent<HTMLInputElement>) => {