@entifix/react-controls 0.20.2 → 0.21.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/dist/i18n/catalog/en.d.ts.map +1 -1
- package/dist/i18n/catalog/en.js +3 -0
- package/dist/i18n/catalog/en.js.map +1 -1
- package/dist/i18n/catalog/es.d.ts +3 -0
- package/dist/i18n/catalog/es.d.ts.map +1 -1
- package/dist/i18n/catalog/es.js +3 -0
- package/dist/i18n/catalog/es.js.map +1 -1
- package/dist/i18n/catalog/index.d.ts +6 -0
- package/dist/i18n/catalog/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/ui/actions/action-surfaces.d.ts +13 -0
- package/dist/ui/actions/action-surfaces.d.ts.map +1 -1
- package/dist/ui/actions/action-surfaces.js +15 -0
- package/dist/ui/actions/action-surfaces.js.map +1 -1
- package/dist/ui/atoms/cell-value/cell-value.d.ts +6 -0
- package/dist/ui/atoms/cell-value/cell-value.d.ts.map +1 -1
- package/dist/ui/atoms/cell-value/cell-value.js +97 -14
- package/dist/ui/atoms/cell-value/cell-value.js.map +1 -1
- package/dist/ui/atoms/cell-value/index.d.ts +1 -0
- package/dist/ui/atoms/cell-value/index.d.ts.map +1 -1
- package/dist/ui/atoms/cell-value/index.js +1 -0
- package/dist/ui/atoms/cell-value/index.js.map +1 -1
- package/dist/ui/atoms/cell-value/use-record-label.d.ts +16 -0
- package/dist/ui/atoms/cell-value/use-record-label.d.ts.map +1 -0
- package/dist/ui/atoms/cell-value/use-record-label.js +55 -0
- package/dist/ui/atoms/cell-value/use-record-label.js.map +1 -0
- package/dist/ui/atoms/table/table.d.ts +4 -2
- package/dist/ui/atoms/table/table.d.ts.map +1 -1
- package/dist/ui/atoms/table/table.js +3 -1
- package/dist/ui/atoms/table/table.js.map +1 -1
- package/dist/ui/organisms/entity-form/entity-form.d.ts +1 -1
- package/dist/ui/organisms/entity-form/entity-form.d.ts.map +1 -1
- package/dist/ui/organisms/entity-form/entity-form.js +19 -10
- package/dist/ui/organisms/entity-form/entity-form.js.map +1 -1
- package/dist/ui/organisms/entity-form/entity-form.types.d.ts +0 -8
- package/dist/ui/organisms/entity-form/entity-form.types.d.ts.map +1 -1
- package/dist/ui/organisms/entity-form/entity-form.types.js.map +1 -1
- package/dist/ui/organisms/entity-table/card-roles.d.ts +10 -0
- package/dist/ui/organisms/entity-table/card-roles.d.ts.map +1 -0
- package/dist/ui/organisms/entity-table/card-roles.js +14 -0
- package/dist/ui/organisms/entity-table/card-roles.js.map +1 -0
- package/dist/ui/organisms/entity-table/entity-table-slots.d.ts +2 -0
- package/dist/ui/organisms/entity-table/entity-table-slots.d.ts.map +1 -1
- package/dist/ui/organisms/entity-table/entity-table-slots.js.map +1 -1
- package/dist/ui/organisms/entity-table/entity-table.d.ts.map +1 -1
- package/dist/ui/organisms/entity-table/entity-table.js +242 -173
- package/dist/ui/organisms/entity-table/entity-table.js.map +1 -1
- package/dist/ui/organisms/entity-table/pivot.d.ts +32 -5
- package/dist/ui/organisms/entity-table/pivot.d.ts.map +1 -1
- package/dist/ui/organisms/entity-table/pivot.js +42 -9
- package/dist/ui/organisms/entity-table/pivot.js.map +1 -1
- package/dist/ui/organisms/entity-table/use-entity-table-columns.d.ts.map +1 -1
- package/dist/ui/organisms/entity-table/use-entity-table-columns.js +6 -3
- package/dist/ui/organisms/entity-table/use-entity-table-columns.js.map +1 -1
- package/dist/ui/utils/reference-labels.d.ts +59 -0
- package/dist/ui/utils/reference-labels.d.ts.map +1 -0
- package/dist/ui/utils/reference-labels.js +49 -0
- package/dist/ui/utils/reference-labels.js.map +1 -0
- package/dist/ui/utils/use-focus-on-arrival.d.ts +11 -0
- package/dist/ui/utils/use-focus-on-arrival.d.ts.map +1 -1
- package/dist/ui/utils/use-focus-on-arrival.js +33 -1
- package/dist/ui/utils/use-focus-on-arrival.js.map +1 -1
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ui/atoms/cell-value/cell-value.tsx"],"sourcesContent":["'use client';\n\nimport type { Formatters, Locale } from '@entifix/core';\nimport {\n defaultLocale,\n type Entity,\n EntityCollectionLink,\n type EntityFieldDescriptor,\n EntityLink,\n isLocalizedText,\n localize,\n type MetaAccessorType,\n} from '@entifix/core';\n\nimport {\n useEnumLabel,\n useFormatters,\n useLocale,\n useT,\n} from '../../../i18n/index.js';\nimport { Money } from '../money/money.js';\nimport { currencyOf } from '../money/money-math.js';\nimport { Skeleton } from '../skeleton/index.js';\n\n/** Stand-in for an absent value, so an empty cell still reads as intentional. */\nconst EMPTY = '—';\n\n/**\n * A link reads as its target's label once the target is loaded (embedded or\n * resolved). Never as its id: a key is not a name, and showing one fails the\n * reader who came to see which record it is (#200).\n */\nfunction entityLabel(\n target: Entity | undefined,\n linkLabelProperty: string,\n locale: Locale,\n): string | undefined {\n const label = (target as Record<string, unknown> | undefined)?.[\n linkLabelProperty\n ];\n if (label == null) return undefined;\n // A target labelled by a localized member reads in the reader's locale.\n return isLocalizedText(label) ? localize(label, locale) : String(label);\n}\n\nfunction formatLink(\n link: EntityLink<Entity>,\n linkLabelProperty: string,\n locale: Locale,\n): string {\n return link.id == null\n ? EMPTY\n : (entityLabel(link.value, linkLabelProperty, locale) ?? EMPTY);\n}\n\nfunction formatCollectionLink(\n link: EntityCollectionLink<Entity>,\n linkLabelProperty: string,\n locale: Locale,\n): string {\n return (link.values ?? [])\n .map(target => entityLabel(target, linkLabelProperty, locale) ?? EMPTY)\n .join(', ');\n}\n\n/**\n * Everything locale-dependent, resolved once by the component and handed down.\n * The formatters carry an explicit locale, which is what keeps a date rendered\n * on the server byte-identical to the same date rendered in the browser.\n */\ninterface CellFormatting {\n readonly formatters: Formatters;\n readonly yes: string;\n readonly no: string;\n readonly enumLabel: (value: string) => string;\n readonly rowCount: (count: number) => string;\n readonly locale: Locale;\n}\n\nfunction formatByType(\n value: unknown,\n type: MetaAccessorType,\n linkLabelProperty: string,\n formatting: CellFormatting,\n): string {\n switch (type) {\n case 'date':\n return formatting.formatters.date(\n value instanceof Date ? value : String(value),\n );\n case 'number':\n return typeof value === 'number'\n ? formatting.formatters.number(value)\n : String(value);\n case 'boolean':\n return value ? formatting.yes : formatting.no;\n case 'enum':\n return formatting.enumLabel(String(value));\n case 'link':\n return value instanceof EntityLink\n ? formatLink(value, linkLabelProperty, formatting.locale)\n : String(value);\n case 'linkCollection':\n return value instanceof EntityCollectionLink\n ? formatCollectionLink(value, linkLabelProperty, formatting.locale)\n : String(value);\n case 'scalarCollection':\n // The same comma list the draft holds, spaced for reading. Not `String`:\n // an array's own `toString` joins on a bare comma, which reads as one\n // run-on token in a narrow column.\n return Array.isArray(value) ? value.join(', ') : String(value);\n case 'composition':\n // Owned rows have no useful one-line form — a receipt's lines are not a\n // sentence — and the master's own screen is where they are read and\n // edited. So the cell reports the count and stops.\n return Array.isArray(value)\n ? formatting.rowCount(value.length)\n : String(value);\n case 'localized':\n // The reader's locale, falling back to the host's default; a value\n // that is not a text per locale has no reading worth guessing at.\n return isLocalizedText(value)\n ? (localize(value, formatting.locale) ?? '')\n : '';\n default:\n return String(value);\n }\n}\n\n/**\n * Tabular figures, applied once, here — not on `--font-sans` and not per call\n * site. A column of numbers or dates must align on the digit; a paragraph must\n * not, because proportional figures are what prose is set in. The descriptor\n * already knows which is which, so the cell is the only place that has to.\n */\nconst NUMERIC_CLASS: Partial<Record<MetaAccessorType, string>> = {\n number: 'tabular-nums',\n date: 'tabular-nums',\n};\n\nexport interface CellValueProps {\n value: unknown;\n descriptor: EntityFieldDescriptor;\n /**\n * The record the value belongs to. A money member whose currency is another\n * member of the record (`money.currencyMember`) reads it from here.\n */\n record?: Readonly<Record<string, unknown>>;\n}\n\n/**\n * Renders one entity member according to its metadata type. Centralizing this\n * is what lets a table stay generic: a link, a date and a number all arrive as\n * \"the value of an accessor\", and only the descriptor decides how they read.\n */\nexport function CellValue({ value, descriptor, record }: CellValueProps) {\n const t = useT();\n const formatters = useFormatters();\n const enumLabel = useEnumLabel();\n const locale = useLocale();\n\n if (value === undefined || value === null || value === '') {\n return <span className=\"text-content-muted\">{EMPTY}</span>;\n }\n\n // An amount reads as money in the reader's locale, never as the stored\n // number. A draft holds it as a string, so a numeric string counts too. A\n // currency the record does not carry leaves it a plain number rather than\n // guessing one.\n if (descriptor.money !== undefined) {\n const amount = typeof value === 'number' ? value : Number(value);\n const currency = currencyOf(descriptor.money, record);\n if (currency !== undefined && Number.isFinite(amount)) {\n return (\n <Money\n amount={amount}\n currency={currency}\n unit={descriptor.money.unit}\n locale={locale}\n />\n );\n }\n }\n\n // A relation whose target has not arrived yet holds its place with a\n // skeleton — the id is all it has, and the id is not what it means.\n if (\n (value instanceof EntityLink &&\n value.id != null &&\n value.value === undefined) ||\n (value instanceof EntityCollectionLink &&\n value.ids.length > 0 &&\n value.values === undefined)\n ) {\n return <Skeleton shape=\"line\" className=\"w-16\" />;\n }\n\n const text = formatByType(\n value,\n descriptor.type,\n descriptor.linkLabelProperty,\n {\n formatters,\n yes: t('value.yes'),\n no: t('value.no'),\n enumLabel: raw => enumLabel(descriptor, raw),\n rowCount: count => t('value.rowCount', { count }),\n locale,\n },\n );\n\n if (text === '') {\n return <span className=\"text-content-muted\">{EMPTY}</span>;\n }\n\n // Text the reader's locale lacks falls back to the default locale's, and is\n // marked as that language, so it is read in its own voice (WCAG 3.1.2).\n if (\n descriptor.type === 'localized' &&\n isLocalizedText(value) &&\n (value[locale] ?? '') === ''\n ) {\n return <span lang={defaultLocale()}>{text}</span>;\n }\n\n return (\n <span className={NUMERIC_CLASS[descriptor.type] ?? undefined}>{text}</span>\n );\n}\n"],"names":["defaultLocale","EntityCollectionLink","EntityLink","isLocalizedText","localize","useEnumLabel","useFormatters","useLocale","useT","Money","currencyOf","Skeleton","EMPTY","entityLabel","target","linkLabelProperty","locale","label","undefined","String","formatLink","link","id","value","formatCollectionLink","values","map","join","formatByType","type","formatting","formatters","date","Date","number","yes","no","enumLabel","Array","isArray","rowCount","length","NUMERIC_CLASS","CellValue","descriptor","record","t","span","className","money","amount","Number","currency","isFinite","unit","ids","shape","text","raw","count","lang"],"mappings":"AAAA;;AAGA,SACEA,aAAa,EAEbC,oBAAoB,EAEpBC,UAAU,EACVC,eAAe,EACfC,QAAQ,QAEH,gBAAgB;AAEvB,SACEC,YAAY,EACZC,aAAa,EACbC,SAAS,EACTC,IAAI,QACC,yBAAyB;AAChC,SAASC,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,UAAU,QAAQ,yBAAyB;AACpD,SAASC,QAAQ,QAAQ,uBAAuB;AAEhD,+EAA+E,GAC/E,MAAMC,QAAQ;AAEd;;;;CAIC,GACD,SAASC,YACPC,MAA0B,EAC1BC,iBAAyB,EACzBC,MAAc;IAEd,MAAMC,QAASH,0BAAD,AAACA,MAAgD,CAC7DC,kBACD;IACD,IAAIE,SAAS,MAAM,OAAOC;IAC1B,wEAAwE;IACxE,OAAOf,gBAAgBc,SAASb,SAASa,OAAOD,UAAUG,OAAOF;AACnE;AAEA,SAASG,WACPC,IAAwB,EACxBN,iBAAyB,EACzBC,MAAc;QAITH;IAFL,OAAOQ,KAAKC,EAAE,IAAI,OACdV,SACCC,eAAAA,YAAYQ,KAAKE,KAAK,EAAER,mBAAmBC,mBAA3CH,eAAsDD;AAC7D;AAEA,SAASY,qBACPH,IAAkC,EAClCN,iBAAyB,EACzBC,MAAc;QAENK;IAAR,OAAO,EAACA,eAAAA,KAAKI,MAAM,YAAXJ,eAAe,EAAE,EACtBK,GAAG,CAACZ,CAAAA;YAAUD;gBAAAA,eAAAA,YAAYC,QAAQC,mBAAmBC,mBAAvCH,eAAkDD;OAChEe,IAAI,CAAC;AACV;AAgBA,SAASC,aACPL,KAAc,EACdM,IAAsB,EACtBd,iBAAyB,EACzBe,UAA0B;IAE1B,OAAQD;QACN,KAAK;YACH,OAAOC,WAAWC,UAAU,CAACC,IAAI,C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AEN,iCAAAA,aAAa,CAACE,WAAWf,IAAI,CAAC,YAA9Ba,iCAAkCxB;kBAAYuC;;AAEnE"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/cell-value/cell-value.tsx"],"sourcesContent":["'use client';\n\nimport type { Formatters, Locale } from '@entifix/core';\nimport {\n defaultLocale,\n type Entity,\n EntityCollectionLink,\n type EntityFieldDescriptor,\n EntityLink,\n isLocalizedText,\n localize,\n type MetaAccessorType,\n} from '@entifix/core';\nimport { useCallback } from 'react';\n\nimport {\n useEnumLabel,\n useFormatters,\n useLocale,\n useT,\n} from '../../../i18n/index.js';\nimport {\n useReferenceLabel,\n useUnresolvedReference,\n} from '../../utils/reference-labels.js';\nimport { Money } from '../money/money.js';\nimport { currencyOf } from '../money/money-math.js';\nimport { Skeleton } from '../skeleton/index.js';\n\n/** Stand-in for an absent value, so an empty cell still reads as intentional. */\nconst EMPTY = '—';\n\n/**\n * A link reads as its target's label once the target is loaded (embedded or\n * resolved). Never as its id: a key is not a name, and showing one fails the\n * reader who came to see which record it is (#200).\n */\nfunction entityLabel(\n target: Entity | undefined,\n linkLabelProperty: string,\n locale: Locale,\n): string | undefined {\n const label = (target as Record<string, unknown> | undefined)?.[\n linkLabelProperty\n ];\n if (label == null) return undefined;\n // A target labelled by a localized member reads in the reader's locale.\n return isLocalizedText(label) ? localize(label, locale) : String(label);\n}\n\nfunction formatLink(\n link: EntityLink<Entity>,\n linkLabelProperty: string,\n locale: Locale,\n): string {\n return link.id == null\n ? EMPTY\n : (entityLabel(link.value, linkLabelProperty, locale) ?? EMPTY);\n}\n\nfunction formatCollectionLink(\n link: EntityCollectionLink<Entity>,\n linkLabelProperty: string,\n locale: Locale,\n): string {\n return (link.values ?? [])\n .map(target => entityLabel(target, linkLabelProperty, locale) ?? EMPTY)\n .join(', ');\n}\n\n/**\n * Everything locale-dependent, resolved once by the component and handed down.\n * The formatters carry an explicit locale, which is what keeps a date rendered\n * on the server byte-identical to the same date rendered in the browser.\n */\ninterface CellFormatting {\n readonly formatters: Formatters;\n readonly yes: string;\n readonly no: string;\n readonly enumLabel: (value: string) => string;\n readonly rowCount: (count: number) => string;\n readonly locale: Locale;\n}\n\nfunction formatByType(\n value: unknown,\n type: MetaAccessorType,\n linkLabelProperty: string,\n formatting: CellFormatting,\n): string {\n switch (type) {\n case 'date':\n return formatting.formatters.date(\n value instanceof Date ? value : String(value),\n );\n case 'number':\n return typeof value === 'number'\n ? formatting.formatters.number(value)\n : String(value);\n case 'boolean':\n return value ? formatting.yes : formatting.no;\n case 'enum':\n return formatting.enumLabel(String(value));\n case 'link':\n return value instanceof EntityLink\n ? formatLink(value, linkLabelProperty, formatting.locale)\n : String(value);\n case 'linkCollection':\n return value instanceof EntityCollectionLink\n ? formatCollectionLink(value, linkLabelProperty, formatting.locale)\n : String(value);\n case 'scalarCollection':\n // The same comma list the draft holds, spaced for reading. Not `String`:\n // an array's own `toString` joins on a bare comma, which reads as one\n // run-on token in a narrow column.\n return Array.isArray(value) ? value.join(', ') : String(value);\n case 'composition':\n // Owned rows have no useful one-line form — a receipt's lines are not a\n // sentence — and the master's own screen is where they are read and\n // edited. So the cell reports the count and stops.\n return Array.isArray(value)\n ? formatting.rowCount(value.length)\n : String(value);\n case 'localized':\n // The reader's locale, falling back to the host's default; a value\n // that is not a text per locale has no reading worth guessing at.\n return isLocalizedText(value)\n ? (localize(value, formatting.locale) ?? '')\n : '';\n default:\n return String(value);\n }\n}\n\n/** The formatting {@link formatByType} reads, resolved for the reader. */\nfunction useCellFormatting(): (\n descriptor: EntityFieldDescriptor,\n) => CellFormatting {\n const t = useT();\n const formatters = useFormatters();\n const enumLabel = useEnumLabel();\n const locale = useLocale();\n return useCallback(\n descriptor => ({\n formatters,\n yes: t('value.yes'),\n no: t('value.no'),\n enumLabel: raw => enumLabel(descriptor, raw),\n rowCount: count => t('value.rowCount', { count }),\n locale,\n }),\n [enumLabel, formatters, locale, t],\n );\n}\n\n/**\n * A filled-in member's value as one line of text, exactly as its cell reads\n * it — for the places that need words rather than an element: a checkbox's\n * name, a confirm dialog's object, a toast.\n */\nexport function useValueText(): (\n value: unknown,\n descriptor: EntityFieldDescriptor,\n) => string {\n const formatting = useCellFormatting();\n return useCallback(\n (value, descriptor) =>\n formatByType(\n value,\n descriptor.type,\n descriptor.linkLabelProperty,\n formatting(descriptor),\n ),\n [formatting],\n );\n}\n\n/**\n * A reference reads as its target's name, in every state the read can be in\n * ([ADR 0030](../../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)):\n * a skeleton while it resolves (the noun and short id for a screen reader); the name; the entity's noun and the short id,\n * muted, when no record answered or the read failed — never an alert, since a\n * list that loaded has not failed because one name could not be read; and the\n * raw id, muted, when the host registered nothing to read it with.\n */\nfunction ReferenceValue({ entity, id }: { entity: string; id: string }) {\n const state = useReferenceLabel(entity, id);\n const unresolved = useUnresolvedReference();\n const locale = useLocale();\n switch (state.status) {\n case 'resolving':\n // The skeleton is hidden from assistive tech, so the noun and short id\n // stand in for it there: a record's title link is never nameless.\n return (\n <>\n <Skeleton shape=\"line\" className=\"w-16\" />\n <span className=\"sr-only\">{unresolved(entity, id)}</span>\n </>\n );\n case 'named': {\n const { label } = state;\n if (typeof label === 'string') return <span>{label}</span>;\n const text = localize(label, locale);\n return (label[locale] ?? '') === '' ? (\n <span lang={defaultLocale()}>{text}</span>\n ) : (\n <span>{text}</span>\n );\n }\n case 'unregistered':\n return <span className=\"text-content-muted\">{id}</span>;\n default:\n return (\n <span className=\"text-content-muted\">{unresolved(entity, id)}</span>\n );\n }\n}\n\n/**\n * Tabular figures, applied once, here — not on `--font-sans` and not per call\n * site. A column of numbers or dates must align on the digit; a paragraph must\n * not, because proportional figures are what prose is set in. The descriptor\n * already knows which is which, so the cell is the only place that has to.\n */\nconst NUMERIC_CLASS: Partial<Record<MetaAccessorType, string>> = {\n number: 'tabular-nums',\n date: 'tabular-nums',\n};\n\nexport interface CellValueProps {\n value: unknown;\n descriptor: EntityFieldDescriptor;\n /**\n * The record the value belongs to. A money member whose currency is another\n * member of the record (`money.currencyMember`) reads it from here.\n */\n record?: Readonly<Record<string, unknown>>;\n}\n\n/**\n * Renders one entity member according to its metadata type. Centralizing this\n * is what lets a table stay generic: a link, a date and a number all arrive as\n * \"the value of an accessor\", and only the descriptor decides how they read.\n */\nexport function CellValue({ value, descriptor, record }: CellValueProps) {\n const formatting = useCellFormatting();\n const locale = useLocale();\n\n if (value === undefined || value === null || value === '') {\n return <span className=\"text-content-muted\">{EMPTY}</span>;\n }\n\n // A key into another entity reads as that record's name, never as itself.\n if (descriptor.references !== undefined) {\n return (\n <ReferenceValue\n entity={descriptor.references.entity}\n id={String(value)}\n />\n );\n }\n\n // An amount reads as money in the reader's locale, never as the stored\n // number. A draft holds it as a string, so a numeric string counts too. A\n // currency the record does not carry leaves it a plain number rather than\n // guessing one.\n if (descriptor.money !== undefined) {\n const amount = typeof value === 'number' ? value : Number(value);\n const currency = currencyOf(descriptor.money, record);\n if (currency !== undefined && Number.isFinite(amount)) {\n return (\n <Money\n amount={amount}\n currency={currency}\n unit={descriptor.money.unit}\n locale={locale}\n />\n );\n }\n }\n\n // A relation whose target has not arrived yet holds its place with a\n // skeleton — the id is all it has, and the id is not what it means.\n if (\n (value instanceof EntityLink &&\n value.id != null &&\n value.value === undefined) ||\n (value instanceof EntityCollectionLink &&\n value.ids.length > 0 &&\n value.values === undefined)\n ) {\n return <Skeleton shape=\"line\" className=\"w-16\" />;\n }\n\n const text = formatByType(\n value,\n descriptor.type,\n descriptor.linkLabelProperty,\n formatting(descriptor),\n );\n\n if (text === '') {\n return <span className=\"text-content-muted\">{EMPTY}</span>;\n }\n\n // Text the reader's locale lacks falls back to the default locale's, and is\n // marked as that language, so it is read in its own voice (WCAG 3.1.2).\n if (\n descriptor.type === 'localized' &&\n isLocalizedText(value) &&\n (value[locale] ?? '') === ''\n ) {\n return <span lang={defaultLocale()}>{text}</span>;\n }\n\n return (\n <span className={NUMERIC_CLASS[descriptor.type] ?? undefined}>{text}</span>\n );\n}\n"],"names":["defaultLocale","EntityCollectionLink","EntityLink","isLocalizedText","localize","useCallback","useEnumLabel","useFormatters","useLocale","useT","useReferenceLabel","useUnresolvedReference","Money","currencyOf","Skeleton","EMPTY","entityLabel","target","linkLabelProperty","locale","label","undefined","String","formatLink","link","id","value","formatCollectionLink","values","map","join","formatByType","type","formatting","formatters","date","Date","number","yes","no","enumLabel","Array","isArray","rowCount","length","useCellFormatting","t","descriptor","raw","count","useValueText","ReferenceValue","entity","state","unresolved","status","shape","className","span","text","lang","NUMERIC_CLASS","CellValue","record","references","money","amount","Number","currency","isFinite","unit","ids"],"mappings":"AAAA;;AAGA,SACEA,aAAa,EAEbC,oBAAoB,EAEpBC,UAAU,EACVC,eAAe,EACfC,QAAQ,QAEH,gBAAgB;AACvB,SAASC,WAAW,QAAQ,QAAQ;AAEpC,SACEC,YAAY,EACZC,aAAa,EACbC,SAAS,EACTC,IAAI,QACC,yBAAyB;AAChC,SACEC,iBAAiB,EACjBC,sBAAsB,QACjB,kCAAkC;AACzC,SAASC,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,UAAU,QAAQ,yBAAyB;AACpD,SAASC,QAAQ,QAAQ,uBAAuB;AAEhD,+EAA+E,GAC/E,MAAMC,QAAQ;AAEd;;;;CAIC,GACD,SAASC,YACPC,MAA0B,EAC1BC,iBAAyB,EACzBC,MAAc;IAEd,MAAMC,QAASH,0BAAD,AAACA,MAAgD,CAC7DC,kBACD;IACD,IAAIE,SAAS,MAAM,OAAOC;IAC1B,wEAAwE;IACxE,OAAOlB,gBAAgBiB,SAAShB,SAASgB,OAAOD,UAAUG,OAAOF;AACnE;AAEA,SAASG,WACPC,IAAwB,EACxBN,iBAAyB,EACzBC,MAAc;QAITH;IAFL,OAAOQ,KAAKC,EAAE,IAAI,OACdV,SACCC,eAAAA,YAAYQ,KAAKE,KAAK,EAAER,mBAAmBC,mBAA3CH,eAAsDD;AAC7D;AAEA,SAASY,qBACPH,IAAkC,E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WAAU;;IAC1C;IAEA,MAAME,OAAO5B,aACXL,OACAqB,WAAWf,IAAI,EACfe,WAAW7B,iBAAiB,EAC5Be,WAAWc;IAGb,IAAIY,SAAS,IAAI;QACf,qBAAO,KAACD;YAAKD,WAAU;sBAAsB1C;;IAC/C;IAEA,4EAA4E;IAC5E,wEAAwE;IACxE,IACEgC,WAAWf,IAAI,KAAK,eACpB7B,gBAAgBuB,UAChB,EAACA,gBAAAA,KAAK,CAACP,OAAO,YAAbO,gBAAiB,QAAQ,IAC1B;QACA,qBAAO,KAACgC;YAAKE,MAAM5D;sBAAkB2D;;IACvC;IAEA,qBACE,KAACD;QAAKD,SAAS,GAAEI,iCAAAA,aAAa,CAACd,WAAWf,IAAI,CAAC,YAA9B6B,iCAAkCxC;kBAAYsC;;AAEnE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/cell-value/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/cell-value/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ui/atoms/cell-value/index.ts"],"sourcesContent":["export * from './cell-value.js';\n"],"names":[],"mappings":"AAAA,cAAc,kBAAkB"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/cell-value/index.ts"],"sourcesContent":["export * from './cell-value.js';\nexport * from './use-record-label.js';\n"],"names":[],"mappings":"AAAA,cAAc,kBAAkB;AAChC,cAAc,wBAAwB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ChildConstructor } from '@entifix/core';
|
|
2
|
+
/**
|
|
3
|
+
* What a record is called, in words — the one derivation every surface that
|
|
4
|
+
* names a record reads: a row's checkbox and title, a card's heading, a
|
|
5
|
+
* confirm dialog's object, the typed delete policy, a breadcrumb, a toast
|
|
6
|
+
* ([ADR 0030](../../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).
|
|
7
|
+
*
|
|
8
|
+
* Core's `recordLabel()` decides **which** member names the record; this puts
|
|
9
|
+
* it into the reader's language: a value as its cell reads it, a reference by
|
|
10
|
+
* its target's name (or the target's noun and short id until that is known),
|
|
11
|
+
* and otherwise the entity's own noun with the record's short id. Never a
|
|
12
|
+
* whole id, except a reference the host registered nothing to read — which is
|
|
13
|
+
* the developer's cue, not the reader's.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useRecordLabel(): (entityConstructor: ChildConstructor, record: object | undefined) => string;
|
|
16
|
+
//# sourceMappingURL=use-record-label.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-record-label.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/cell-value/use-record-label.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,eAAe,CAAC;AAUvB;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,IAAI,CAChC,iBAAiB,EAAE,gBAAgB,EACnC,MAAM,EAAE,MAAM,GAAG,SAAS,KACvB,MAAM,CAgCV"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
3
|
+
import { findMetaEntity, recordLabel } from '@entifix/core';
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
import { useEntityNoun, useT } from '../../../i18n/index.js';
|
|
6
|
+
import { useReferenceLabels, useUnresolvedReference } from '../../utils/reference-labels.js';
|
|
7
|
+
import { useValueText } from './cell-value.js';
|
|
8
|
+
/**
|
|
9
|
+
* What a record is called, in words — the one derivation every surface that
|
|
10
|
+
* names a record reads: a row's checkbox and title, a card's heading, a
|
|
11
|
+
* confirm dialog's object, the typed delete policy, a breadcrumb, a toast
|
|
12
|
+
* ([ADR 0030](../../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).
|
|
13
|
+
*
|
|
14
|
+
* Core's `recordLabel()` decides **which** member names the record; this puts
|
|
15
|
+
* it into the reader's language: a value as its cell reads it, a reference by
|
|
16
|
+
* its target's name (or the target's noun and short id until that is known),
|
|
17
|
+
* and otherwise the entity's own noun with the record's short id. Never a
|
|
18
|
+
* whole id, except a reference the host registered nothing to read — which is
|
|
19
|
+
* the developer's cue, not the reader's.
|
|
20
|
+
*/ export function useRecordLabel() {
|
|
21
|
+
const valueText = useValueText();
|
|
22
|
+
const lookup = useReferenceLabels();
|
|
23
|
+
const unresolved = useUnresolvedReference();
|
|
24
|
+
const t = useT();
|
|
25
|
+
const noun = useEntityNoun();
|
|
26
|
+
return useCallback((entityConstructor, record)=>{
|
|
27
|
+
var _findMetaEntity;
|
|
28
|
+
const label = recordLabel(entityConstructor, record);
|
|
29
|
+
if (label.kind === 'value') return valueText(label.value, label.member);
|
|
30
|
+
if (label.kind === 'reference') {
|
|
31
|
+
const state = lookup.label(label.entity, label.id);
|
|
32
|
+
if (state.status === 'named') {
|
|
33
|
+
return valueText(state.label, _extends({}, label.member, {
|
|
34
|
+
type: typeof state.label === 'string' ? 'string' : 'localized'
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return state.status === 'unregistered' ? label.id : unresolved(label.entity, label.id);
|
|
38
|
+
}
|
|
39
|
+
const entityNoun = noun((_findMetaEntity = findMetaEntity(entityConstructor)) != null ? _findMetaEntity : {
|
|
40
|
+
name: entityConstructor.name
|
|
41
|
+
});
|
|
42
|
+
return label.shortId === undefined ? entityNoun : t('reference.unresolved', {
|
|
43
|
+
noun: entityNoun,
|
|
44
|
+
id: label.shortId
|
|
45
|
+
});
|
|
46
|
+
}, [
|
|
47
|
+
lookup,
|
|
48
|
+
noun,
|
|
49
|
+
t,
|
|
50
|
+
unresolved,
|
|
51
|
+
valueText
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=use-record-label.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/cell-value/use-record-label.ts"],"sourcesContent":["'use client';\n\nimport {\n type ChildConstructor,\n findMetaEntity,\n recordLabel,\n} from '@entifix/core';\nimport { useCallback } from 'react';\n\nimport { useEntityNoun, useT } from '../../../i18n/index.js';\nimport {\n useReferenceLabels,\n useUnresolvedReference,\n} from '../../utils/reference-labels.js';\nimport { useValueText } from './cell-value.js';\n\n/**\n * What a record is called, in words — the one derivation every surface that\n * names a record reads: a row's checkbox and title, a card's heading, a\n * confirm dialog's object, the typed delete policy, a breadcrumb, a toast\n * ([ADR 0030](../../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).\n *\n * Core's `recordLabel()` decides **which** member names the record; this puts\n * it into the reader's language: a value as its cell reads it, a reference by\n * its target's name (or the target's noun and short id until that is known),\n * and otherwise the entity's own noun with the record's short id. Never a\n * whole id, except a reference the host registered nothing to read — which is\n * the developer's cue, not the reader's.\n */\nexport function useRecordLabel(): (\n entityConstructor: ChildConstructor,\n record: object | undefined,\n) => string {\n const valueText = useValueText();\n const lookup = useReferenceLabels();\n const unresolved = useUnresolvedReference();\n const t = useT();\n const noun = useEntityNoun();\n\n return useCallback(\n (entityConstructor, record) => {\n const label = recordLabel(entityConstructor, record);\n if (label.kind === 'value') return valueText(label.value, label.member);\n if (label.kind === 'reference') {\n const state = lookup.label(label.entity, label.id);\n if (state.status === 'named') {\n return valueText(state.label, {\n ...label.member,\n type: typeof state.label === 'string' ? 'string' : 'localized',\n });\n }\n return state.status === 'unregistered'\n ? label.id\n : unresolved(label.entity, label.id);\n }\n const entityNoun = noun(\n findMetaEntity(entityConstructor) ?? { name: entityConstructor.name },\n );\n return label.shortId === undefined\n ? entityNoun\n : t('reference.unresolved', { noun: entityNoun, id: label.shortId });\n },\n [lookup, noun, t, unresolved, valueText],\n );\n}\n"],"names":["findMetaEntity","recordLabel","useCallback","useEntityNoun","useT","useReferenceLabels","useUnresolvedReference","useValueText","useRecordLabel","valueText","lookup","unresolved","t","noun","entityConstructor","record","label","kind","value","member","state","entity","id","status","type","entityNoun","name","shortId","undefined"],"mappings":"AAAA;;AAEA,SAEEA,cAAc,EACdC,WAAW,QACN,gBAAgB;AACvB,SAASC,WAAW,QAAQ,QAAQ;AAEpC,SAASC,aAAa,EAAEC,IAAI,QAAQ,yBAAyB;AAC7D,SACEC,kBAAkB,EAClBC,sBAAsB,QACjB,kCAAkC;AACzC,SAASC,YAAY,QAAQ,kBAAkB;AAE/C;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC;IAId,MAAMC,YAAYF;IAClB,MAAMG,SAASL;IACf,MAAMM,aAAaL;IACnB,MAAMM,IAAIR;IACV,MAAMS,OAAOV;IAEb,OAAOD,YACL,CAACY,mBAAmBC;YAgBhBf;QAfF,MAAMgB,QAAQf,YAAYa,mBAAmBC;QAC7C,IAAIC,MAAMC,IAAI,KAAK,SAAS,OAAOR,UAAUO,MAAME,KAAK,EAAEF,MAAMG,MAAM;QACtE,IAAIH,MAAMC,IAAI,KAAK,aAAa;YAC9B,MAAMG,QAAQV,OAAOM,KAAK,CAACA,MAAMK,MAAM,EAAEL,MAAMM,EAAE;YACjD,IAAIF,MAAMG,MAAM,KAAK,SAAS;gBAC5B,OAAOd,UAAUW,MAAMJ,KAAK,EAAE,aACzBA,MAAMG,MAAM;oBACfK,MAAM,OAAOJ,MAAMJ,KAAK,KAAK,WAAW,WAAW;;YAEvD;YACA,OAAOI,MAAMG,MAAM,KAAK,iBACpBP,MAAMM,EAAE,GACRX,WAAWK,MAAMK,MAAM,EAAEL,MAAMM,EAAE;QACvC;QACA,MAAMG,aAAaZ,MACjBb,kBAAAA,eAAec,8BAAfd,kBAAqC;YAAE0B,MAAMZ,kBAAkBY,IAAI;QAAC;QAEtE,OAAOV,MAAMW,OAAO,KAAKC,YACrBH,aACAb,EAAE,wBAAwB;YAAEC,MAAMY;YAAYH,IAAIN,MAAMW,OAAO;QAAC;IACtE,GACA;QAACjB;QAAQG;QAAMD;QAAGD;QAAYF;KAAU;AAE5C"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { type ComponentPropsWithoutRef, type ReactNode } from 'react';
|
|
1
|
+
import { type ComponentPropsWithoutRef, type CSSProperties, type ReactNode } from 'react';
|
|
2
2
|
export interface TableProps extends ComponentPropsWithoutRef<'table'> {
|
|
3
3
|
/** Class names for the scroll container wrapping the `<table>`. */
|
|
4
4
|
containerClassName?: string;
|
|
5
|
+
/** Inline style on that container — the scroll padding a sticky column needs. */
|
|
6
|
+
containerStyle?: CSSProperties;
|
|
5
7
|
/**
|
|
6
8
|
* What the table holds — "Clientes, 12 resultados". It names the table and,
|
|
7
9
|
* once the table overflows its container, the scroll region too.
|
|
@@ -19,7 +21,7 @@ export interface TableProps extends ComponentPropsWithoutRef<'table'> {
|
|
|
19
21
|
* caption, so a keyboard can scroll it — and one that fits is neither, so it
|
|
20
22
|
* adds no tab stop that does nothing.
|
|
21
23
|
*/
|
|
22
|
-
export declare function Table({ className, containerClassName, caption, captionClassName, children, ...props }: TableProps): import("react").JSX.Element;
|
|
24
|
+
export declare function Table({ className, containerClassName, containerStyle, caption, captionClassName, children, ...props }: TableProps): import("react").JSX.Element;
|
|
23
25
|
export declare function TableHead({ className, ...props }: ComponentPropsWithoutRef<'thead'>): import("react").JSX.Element;
|
|
24
26
|
export declare function TableBody({ className, ...props }: ComponentPropsWithoutRef<'tbody'>): import("react").JSX.Element;
|
|
25
27
|
export declare function TableRow({ className, ...props }: ComponentPropsWithoutRef<'tr'>): import("react").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../src/ui/atoms/table/table.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,SAAS,EAM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,EACvB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,wBAAwB,CAAC,IAAI,CAAC,+BAUhC;AAED,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;AAUxD,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAChD,wBAAwB,CAAC,IAAI,CAAC,EAC9B,OAAO,CACR;IACC,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB;AAED,wBAAgB,eAAe,CAAC,EAC9B,KAAe,EACf,SAAS,EACT,GAAG,KAAK,EACT,EAAE,oBAAoB,+BAYtB;AAED,MAAM,WAAW,cAAe,SAAQ,IAAI,CAC1C,wBAAwB,CAAC,IAAI,CAAC,EAC9B,OAAO,CACR;IACC,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB;AAED,wBAAgB,SAAS,CAAC,EACxB,KAAe,EACf,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,+BAOhB;AAED,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,EAC9B,OAAO,EACP,SAAS,EACT,GAAG,KAAK,EACT,EAAE,wBAAwB,CAAC,IAAI,CAAC,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,+BAatD"}
|
|
@@ -32,9 +32,10 @@ import { cn } from '../../utils/cn.js';
|
|
|
32
32
|
* caption, so a keyboard can scroll it — and one that fits is neither, so it
|
|
33
33
|
* adds no tab stop that does nothing.
|
|
34
34
|
*/ export function Table(_0) {
|
|
35
|
-
let { className, containerClassName, caption, captionClassName = 'sr-only', children } = _0, props = _object_without_properties_loose(_0, [
|
|
35
|
+
let { className, containerClassName, containerStyle, caption, captionClassName = 'sr-only', children } = _0, props = _object_without_properties_loose(_0, [
|
|
36
36
|
"className",
|
|
37
37
|
"containerClassName",
|
|
38
|
+
"containerStyle",
|
|
38
39
|
"caption",
|
|
39
40
|
"captionClassName",
|
|
40
41
|
"children"
|
|
@@ -45,6 +46,7 @@ import { cn } from '../../utils/cn.js';
|
|
|
45
46
|
const named = caption !== undefined;
|
|
46
47
|
return /*#__PURE__*/ _jsx("div", _extends({
|
|
47
48
|
ref: container,
|
|
49
|
+
style: containerStyle,
|
|
48
50
|
"data-overflows": overflows || undefined
|
|
49
51
|
}, overflows && {
|
|
50
52
|
tabIndex: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ui/atoms/table/table.tsx"],"sourcesContent":["'use client';\n\nimport {\n type ComponentPropsWithoutRef,\n type ReactNode,\n type RefObject,\n useEffect,\n useId,\n useRef,\n useState,\n} from 'react';\n\nimport { cn } from '../../utils/cn.js';\n\nexport interface TableProps extends ComponentPropsWithoutRef<'table'> {\n /** Class names for the scroll container wrapping the `<table>`. */\n containerClassName?: string;\n /**\n * What the table holds — \"Clientes, 12 resultados\". It names the table and,\n * once the table overflows its container, the scroll region too.\n */\n caption?: ReactNode;\n /** Class names for the caption; screen-reader only unless overridden. */\n captionClassName?: string;\n}\n\n/**\n * Whether an element's content is larger than its box, on either axis —\n * measured again whenever the box or the content it holds resizes.\n */\nfunction useOverflows(ref: RefObject<HTMLElement | null>): boolean {\n const [overflows, setOverflows] = useState(false);\n useEffect(() => {\n const node = ref.current as HTMLElement;\n const measure = () =>\n setOverflows(\n node.scrollWidth > node.clientWidth ||\n node.scrollHeight > node.clientHeight,\n );\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n // The table grows with its rows while the container keeps its size.\n for (const child of Array.from(node.children)) observer.observe(child);\n return () => observer.disconnect();\n }, [ref]);\n return overflows;\n}\n\n/**\n * Styled table primitive — no entity knowledge, no data fetching. `EntityTable`\n * composes these; anything rendering non-entity tabular data can use them too.\n *\n * Wide tables scroll inside their own container rather than pushing the page\n * sideways. A container that scrolls is a **focusable region** named by the\n * caption, so a keyboard can scroll it — and one that fits is neither, so it\n * adds no tab stop that does nothing.\n */\nexport function Table({\n className,\n containerClassName,\n caption,\n captionClassName = 'sr-only',\n children,\n ...props\n}: TableProps) {\n const container = useRef<HTMLDivElement>(null);\n const captionId = useId();\n const overflows = useOverflows(container);\n const named = caption !== undefined;\n\n return (\n <div\n ref={container}\n data-overflows={overflows || undefined}\n {...(overflows && {\n tabIndex: 0,\n role: named ? 'region' : undefined,\n 'aria-labelledby': named ? captionId : undefined,\n })}\n className={cn(\n 'w-full overflow-auto rounded-xl border border-border bg-surface-elevated focus-ring',\n containerClassName,\n )}\n >\n <table\n className={cn(\n 'w-full border-collapse text-step-0 text-content',\n className,\n )}\n {...props}\n >\n {named && (\n <caption id={captionId} className={captionClassName}>\n {caption}\n </caption>\n )}\n {children}\n </table>\n </div>\n );\n}\n\nexport function TableHead({\n className,\n ...props\n}: ComponentPropsWithoutRef<'thead'>) {\n return (\n <thead\n // Sticky inside a container that scrolls: the column names stay in view\n // over a long page of rows. One layer above the rows, and no higher: a\n // row menu opened under it must still paint over it.\n className={cn(\n 'top-0 sticky z-1 border-b border-border bg-surface',\n className,\n )}\n {...props}\n />\n );\n}\n\nexport function TableBody({\n className,\n ...props\n}: ComponentPropsWithoutRef<'tbody'>) {\n return (\n <tbody className={cn('divide-y divide-border', className)} {...props} />\n );\n}\n\nexport function TableRow({\n className,\n ...props\n}: ComponentPropsWithoutRef<'tr'>) {\n return (\n <tr\n className={cn(\n 'transition-colors duration-200 ease-smooth hover:bg-surface',\n className,\n )}\n {...props}\n />\n );\n}\n\nexport type TableCellAlign = 'start' | 'center' | 'end';\n\nconst ALIGN_CLASS: Record<TableCellAlign, string> = {\n start: 'text-left',\n center: 'text-center',\n end: 'text-right',\n};\n\n// `align` shadows the deprecated HTML attribute, which allows a different set\n// of values — omit the native one rather than narrow it.\nexport interface TableHeaderCellProps extends Omit<\n ComponentPropsWithoutRef<'th'>,\n 'align'\n> {\n align?: TableCellAlign;\n}\n\nexport function TableHeaderCell({\n align = 'start',\n className,\n ...props\n}: TableHeaderCellProps) {\n return (\n <th\n scope=\"col\"\n className={cn(\n 'px-s py-2xs text-step-sm font-semibold whitespace-nowrap text-content-muted',\n ALIGN_CLASS[align],\n className,\n )}\n {...props}\n />\n );\n}\n\nexport interface TableCellProps extends Omit<\n ComponentPropsWithoutRef<'td'>,\n 'align'\n> {\n align?: TableCellAlign;\n}\n\nexport function TableCell({\n align = 'start',\n className,\n ...props\n}: TableCellProps) {\n return (\n <td\n className={cn('px-s py-2xs align-middle', ALIGN_CLASS[align], className)}\n {...props}\n />\n );\n}\n\n/** Full-width message row — empty results, an error, a loading state. */\nexport function TableMessageRow({\n colSpan,\n className,\n ...props\n}: ComponentPropsWithoutRef<'td'> & { colSpan: number }) {\n return (\n <tr>\n <td\n colSpan={colSpan}\n className={cn(\n 'px-s py-m text-center text-step-sm text-content-muted',\n className,\n )}\n {...props}\n />\n </tr>\n );\n}\n"],"names":["useEffect","useId","useRef","useState","cn","useOverflows","ref","overflows","setOverflows","node","current","measure","scrollWidth","clientWidth","scrollHeight","clientHeight","observer","ResizeObserver","observe","child","Array","from","children","disconnect","Table","className","containerClassName","caption","captionClassName","props","container","captionId","named","undefined","div","data-overflows","tabIndex","role","table","id","TableHead","thead","TableBody","tbody","TableRow","tr","ALIGN_CLASS","start","center","end","TableHeaderCell","align","th","scope","TableCell","td","TableMessageRow","colSpan"],"mappings":"AAAA;;;;AAEA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/atoms/table/table.tsx"],"sourcesContent":["'use client';\n\nimport {\n type ComponentPropsWithoutRef,\n type CSSProperties,\n type ReactNode,\n type RefObject,\n useEffect,\n useId,\n useRef,\n useState,\n} from 'react';\n\nimport { cn } from '../../utils/cn.js';\n\nexport interface TableProps extends ComponentPropsWithoutRef<'table'> {\n /** Class names for the scroll container wrapping the `<table>`. */\n containerClassName?: string;\n /** Inline style on that container — the scroll padding a sticky column needs. */\n containerStyle?: CSSProperties;\n /**\n * What the table holds — \"Clientes, 12 resultados\". It names the table and,\n * once the table overflows its container, the scroll region too.\n */\n caption?: ReactNode;\n /** Class names for the caption; screen-reader only unless overridden. */\n captionClassName?: string;\n}\n\n/**\n * Whether an element's content is larger than its box, on either axis —\n * measured again whenever the box or the content it holds resizes.\n */\nfunction useOverflows(ref: RefObject<HTMLElement | null>): boolean {\n const [overflows, setOverflows] = useState(false);\n useEffect(() => {\n const node = ref.current as HTMLElement;\n const measure = () =>\n setOverflows(\n node.scrollWidth > node.clientWidth ||\n node.scrollHeight > node.clientHeight,\n );\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(node);\n // The table grows with its rows while the container keeps its size.\n for (const child of Array.from(node.children)) observer.observe(child);\n return () => observer.disconnect();\n }, [ref]);\n return overflows;\n}\n\n/**\n * Styled table primitive — no entity knowledge, no data fetching. `EntityTable`\n * composes these; anything rendering non-entity tabular data can use them too.\n *\n * Wide tables scroll inside their own container rather than pushing the page\n * sideways. A container that scrolls is a **focusable region** named by the\n * caption, so a keyboard can scroll it — and one that fits is neither, so it\n * adds no tab stop that does nothing.\n */\nexport function Table({\n className,\n containerClassName,\n containerStyle,\n caption,\n captionClassName = 'sr-only',\n children,\n ...props\n}: TableProps) {\n const container = useRef<HTMLDivElement>(null);\n const captionId = useId();\n const overflows = useOverflows(container);\n const named = caption !== undefined;\n\n return (\n <div\n ref={container}\n style={containerStyle}\n data-overflows={overflows || undefined}\n {...(overflows && {\n tabIndex: 0,\n role: named ? 'region' : undefined,\n 'aria-labelledby': named ? captionId : undefined,\n })}\n className={cn(\n 'w-full overflow-auto rounded-xl border border-border bg-surface-elevated focus-ring',\n containerClassName,\n )}\n >\n <table\n className={cn(\n 'w-full border-collapse text-step-0 text-content',\n className,\n )}\n {...props}\n >\n {named && (\n <caption id={captionId} className={captionClassName}>\n {caption}\n </caption>\n )}\n {children}\n </table>\n </div>\n );\n}\n\nexport function TableHead({\n className,\n ...props\n}: ComponentPropsWithoutRef<'thead'>) {\n return (\n <thead\n // Sticky inside a container that scrolls: the column names stay in view\n // over a long page of rows. One layer above the rows, and no higher: a\n // row menu opened under it must still paint over it.\n className={cn(\n 'top-0 sticky z-1 border-b border-border bg-surface',\n className,\n )}\n {...props}\n />\n );\n}\n\nexport function TableBody({\n className,\n ...props\n}: ComponentPropsWithoutRef<'tbody'>) {\n return (\n <tbody className={cn('divide-y divide-border', className)} {...props} />\n );\n}\n\nexport function TableRow({\n className,\n ...props\n}: ComponentPropsWithoutRef<'tr'>) {\n return (\n <tr\n className={cn(\n 'transition-colors duration-200 ease-smooth hover:bg-surface',\n className,\n )}\n {...props}\n />\n );\n}\n\nexport type TableCellAlign = 'start' | 'center' | 'end';\n\nconst ALIGN_CLASS: Record<TableCellAlign, string> = {\n start: 'text-left',\n center: 'text-center',\n end: 'text-right',\n};\n\n// `align` shadows the deprecated HTML attribute, which allows a different set\n// of values — omit the native one rather than narrow it.\nexport interface TableHeaderCellProps extends Omit<\n ComponentPropsWithoutRef<'th'>,\n 'align'\n> {\n align?: TableCellAlign;\n}\n\nexport function TableHeaderCell({\n align = 'start',\n className,\n ...props\n}: TableHeaderCellProps) {\n return (\n <th\n scope=\"col\"\n className={cn(\n 'px-s py-2xs text-step-sm font-semibold whitespace-nowrap text-content-muted',\n ALIGN_CLASS[align],\n className,\n )}\n {...props}\n />\n );\n}\n\nexport interface TableCellProps extends Omit<\n ComponentPropsWithoutRef<'td'>,\n 'align'\n> {\n align?: TableCellAlign;\n}\n\nexport function TableCell({\n align = 'start',\n className,\n ...props\n}: TableCellProps) {\n return (\n <td\n className={cn('px-s py-2xs align-middle', ALIGN_CLASS[align], className)}\n {...props}\n />\n );\n}\n\n/** Full-width message row — empty results, an error, a loading state. */\nexport function TableMessageRow({\n colSpan,\n className,\n ...props\n}: ComponentPropsWithoutRef<'td'> & { colSpan: number }) {\n return (\n <tr>\n <td\n colSpan={colSpan}\n className={cn(\n 'px-s py-m text-center text-step-sm text-content-muted',\n className,\n )}\n {...props}\n />\n </tr>\n );\n}\n"],"names":["useEffect","useId","useRef","useState","cn","useOverflows","ref","overflows","setOverflows","node","current","measure","scrollWidth","clientWidth","scrollHeight","clientHeight","observer","ResizeObserver","observe","child","Array","from","children","disconnect","Table","className","containerClassName","containerStyle","caption","captionClassName","props","container","captionId","named","undefined","div","style","data-overflows","tabIndex","role","table","id","TableHead","thead","TableBody","tbody","TableRow","tr","ALIGN_CLASS","start","center","end","TableHeaderCell","align","th","scope","TableCell","td","TableMessageRow","colSpan"],"mappings":"AAAA;;;;AAEA,SAKEA,SAAS,EACTC,KAAK,EACLC,MAAM,EACNC,QAAQ,QACH,QAAQ;AAEf,SAASC,EAAE,QAAQ,oBAAoB;AAgBvC;;;CAGC,GACD,SAASC,aAAaC,GAAkC;IACtD,MAAM,CAACC,WAAWC,aAAa,GAAGL,SAAS;IAC3CH,UAAU;QACR,MAAMS,OAAOH,IAAII,OAAO;QACxB,MAAMC,UAAU,IACdH,aACEC,KAAKG,WAAW,GAAGH,KAAKI,WAAW,IACjCJ,KAAKK,YAAY,GAAGL,KAAKM,YAAY;QAE3CJ;QACA,MAAMK,WAAW,IAAIC,eAAeN;QACpCK,SAASE,OAAO,CAACT;QACjB,oEAAoE;QACpE,KAAK,MAAMU,SAASC,MAAMC,IAAI,CAACZ,KAAKa,QAAQ,EAAGN,SAASE,OAAO,CAACC;QAChE,OAAO,IAAMH,SAASO,UAAU;IAClC,GAAG;QAACjB;KAAI;IACR,OAAOC;AACT;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASiB,MAAM,EAQT;QARS,EACpBC,SAAS,EACTC,kBAAkB,EAClBC,cAAc,EACdC,OAAO,EACPC,mBAAmB,SAAS,EAC5BP,QAAQ,EAEG,OADRQ;;;;;;;;IAEH,MAAMC,YAAY7B,OAAuB;IACzC,MAAM8B,YAAY/B;IAClB,MAAMM,YAAYF,aAAa0B;IAC/B,MAAME,QAAQL,YAAYM;IAE1B,qBACE,KAACC;QACC7B,KAAKyB;QACLK,OAAOT;QACPU,kBAAgB9B,aAAa2B;OACxB3B,aAAa;QAChB+B,UAAU;QACVC,MAAMN,QAAQ,WAAWC;QACzB,mBAAmBD,QAAQD,YAAYE;IACzC;QACAT,WAAWrB,GACT,u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+1,4 @@
|
|
|
1
1
|
import { type Entity } from '@entifix/core';
|
|
2
2
|
import type { EntityFormProps } from './entity-form.types.js';
|
|
3
|
-
export declare function EntityForm<TEntity extends Entity>({ entityConstructor, entity, values, onFieldChange, linkSources, onLinkChange, mode: modeProp, defaultMode, onModeChange, errors, formError, onSubmit, onDelete, deletePolicy,
|
|
3
|
+
export declare function EntityForm<TEntity extends Entity>({ entityConstructor, entity, values, onFieldChange, linkSources, onLinkChange, mode: modeProp, defaultMode, onModeChange, errors, formError, onSubmit, onDelete, deletePolicy, embedded, isLoading, skeleton, isSaving, isPending, isDeleting, error, onRetry, backHref, renderLink, title, metadata, isMetadataLoading, onUseCase, onClone, children, }: EntityFormProps<TEntity>): import("react").JSX.Element;
|
|
4
4
|
//# sourceMappingURL=entity-form.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-form.d.ts","sourceRoot":"","sources":["../../../../src/ui/organisms/entity-form/entity-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,MAAM,EAWZ,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"entity-form.d.ts","sourceRoot":"","sources":["../../../../src/ui/organisms/entity-form/entity-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,MAAM,EAWZ,MAAM,eAAe,CAAC;AAsCvB,OAAO,KAAK,EAGV,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAqDhC,wBAAgB,UAAU,CAAC,OAAO,SAAS,MAAM,EAAE,EACjD,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,aAAa,EACb,WAAW,EACX,YAAY,EACZ,IAAI,EAAE,QAAQ,EACd,WAAW,EACX,YAAY,EACZ,MAAM,EACN,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,YAAwB,EACxB,QAAgB,EAChB,SAAiB,EACjB,QAAe,EACf,QAAgB,EAChB,SAAiB,EACjB,UAAkB,EAClB,KAAK,EACL,OAAO,EACP,QAAQ,EACR,UAAyB,EACzB,KAAK,EACL,QAAQ,EACR,iBAAyB,EACzB,SAAS,EACT,OAAO,EACP,QAAQ,GACT,EAAE,eAAe,CAAC,OAAO,CAAC,+BA6c1B"}
|
|
@@ -4,10 +4,10 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
4
4
|
import { cloneEntityDraft, describeEntityColumns, extractMetaEntity, readDraftString, readLocalizedDraft, readRowDrafts } from '@entifix/core';
|
|
5
5
|
import { useEffect, useId, useRef, useState } from 'react';
|
|
6
6
|
import { useEntityNoun, useLocalizedDescriptors, useT, useTranslateKey } from '../../../i18n/index.js';
|
|
7
|
-
import { renderAnchor, useCasesForSurface } from '../../actions/index.js';
|
|
7
|
+
import { availableUseCases, renderAnchor, useCasesForSurface } from '../../actions/index.js';
|
|
8
8
|
import { useVerbInvoker } from '../../actions/use-verb-invoker.js';
|
|
9
9
|
import { Button, button } from '../../atoms/button/index.js';
|
|
10
|
-
import { CellValue } from '../../atoms/cell-value/index.js';
|
|
10
|
+
import { CellValue, useRecordLabel } from '../../atoms/cell-value/index.js';
|
|
11
11
|
import { FieldControl } from '../../atoms/field-control/index.js';
|
|
12
12
|
import { LocalizedFieldControl } from '../../atoms/localized-field-control/index.js';
|
|
13
13
|
import { Skeleton } from '../../atoms/skeleton/index.js';
|
|
@@ -20,7 +20,7 @@ import { RegionState } from '../../molecules/region-state/index.js';
|
|
|
20
20
|
import { Stack } from '../../molecules/stack/index.js';
|
|
21
21
|
import { cn } from '../../utils/cn.js';
|
|
22
22
|
import { useLiveUpdates } from '../../utils/live-updates.js';
|
|
23
|
-
import { useFocusOnArrival } from '../../utils/use-focus-on-arrival.js';
|
|
23
|
+
import { useFocusOnArrival, useFocusOnLoss } from '../../utils/use-focus-on-arrival.js';
|
|
24
24
|
import { EntityDetailGrid } from '../entity-detail-grid/index.js';
|
|
25
25
|
import { readEntityFormFields } from './entity-form-slots.js';
|
|
26
26
|
import { resolveEntityFormFields } from './use-entity-form-fields.js';
|
|
@@ -66,7 +66,7 @@ import { resolveEntityFormFields } from './use-entity-form-fields.js';
|
|
|
66
66
|
*/ /** The key the built-in Delete runs under, which no declared verb can take. */ const DELETE_KEY = '$delete';
|
|
67
67
|
/** Save, from anywhere in the form — the caret in a field included. */ const SAVE_SHORTCUT = 'Mod+S';
|
|
68
68
|
/** The footer's declared primary, when it is not Save. */ const PRIMARY_SHORTCUT = 'Mod+Enter';
|
|
69
|
-
export function EntityForm({ entityConstructor, entity, values, onFieldChange, linkSources, onLinkChange, mode: modeProp, defaultMode, onModeChange, errors, formError, onSubmit, onDelete, deletePolicy = 'confirm',
|
|
69
|
+
export function EntityForm({ entityConstructor, entity, values, onFieldChange, linkSources, onLinkChange, mode: modeProp, defaultMode, onModeChange, errors, formError, onSubmit, onDelete, deletePolicy = 'confirm', embedded = false, isLoading = false, skeleton = true, isSaving = false, isPending = false, isDeleting = false, error, onRetry, backHref, renderLink = renderAnchor, title, metadata, isMetadataLoading = false, onUseCase, onClone, children }) {
|
|
70
70
|
const formId = useId();
|
|
71
71
|
const slots = readEntityFormFields(children);
|
|
72
72
|
// The *field* descriptors, which stay local and synchronous — a column is a
|
|
@@ -144,8 +144,16 @@ export function EntityForm({ entityConstructor, entity, values, onFieldChange, l
|
|
|
144
144
|
// hook count must stay fixed across renders.
|
|
145
145
|
const declaredHeaderUseCases = useCasesForSurface('form-header', metadata == null ? void 0 : metadata.useCases);
|
|
146
146
|
const declaredFooterUseCases = useCasesForSurface('form-footer', metadata == null ? void 0 : metadata.useCases);
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
// And only the verbs the record's state allows: a shipment awaiting dispatch
|
|
148
|
+
// offers Dispatch, not every move a shipment can ever make.
|
|
149
|
+
const headerUseCases = onUseCase ? availableUseCases(declaredHeaderUseCases, entity) : [];
|
|
150
|
+
const footerUseCases = onUseCase ? availableUseCases(declaredFooterUseCases, entity) : [];
|
|
151
|
+
// A verb that moved its record out of the states it applies to unmounts the
|
|
152
|
+
// button the reader just pressed; focus goes to the heading, not `<body>`.
|
|
153
|
+
useFocusOnLoss(()=>heading.current, [
|
|
154
|
+
...headerUseCases,
|
|
155
|
+
...footerUseCases
|
|
156
|
+
].map(({ key })=>key).join(' '));
|
|
149
157
|
// Every verb on the form, and its own Delete, goes through one invoker: a
|
|
150
158
|
// destructive verb asks, asks for the name, or runs and offers Undo, as it
|
|
151
159
|
// declared — `revoke-sessions` ends every session a user holds.
|
|
@@ -154,11 +162,12 @@ export function EntityForm({ entityConstructor, entity, values, onFieldChange, l
|
|
|
154
162
|
busy,
|
|
155
163
|
served: metadata == null ? void 0 : metadata.useCases
|
|
156
164
|
});
|
|
157
|
-
// What a confirmation names
|
|
158
|
-
//
|
|
165
|
+
// What a confirmation names — the object in "Delete {record}?" and the text
|
|
166
|
+
// the typed policy asks for — through the one derivation every surface
|
|
167
|
+
// shares: the entity's `labelMember`, resolved if it is a reference.
|
|
159
168
|
const metaEntity = extractMetaEntity(entityConstructor);
|
|
160
|
-
const
|
|
161
|
-
const recordLabel =
|
|
169
|
+
const nameOf = useRecordLabel();
|
|
170
|
+
const recordLabel = nameOf(entityConstructor, draft);
|
|
162
171
|
const invoke = (descriptor)=>verbs.invoke({
|
|
163
172
|
descriptor,
|
|
164
173
|
target: undefined,
|