@entifix/react-controls 0.23.6 → 0.23.7
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/README.md +16 -0
- package/dist/i18n/catalog/en.d.ts.map +1 -1
- package/dist/i18n/catalog/en.js +2 -1
- package/dist/i18n/catalog/en.js.map +1 -1
- package/dist/i18n/catalog/es.d.ts +1 -0
- package/dist/i18n/catalog/es.d.ts.map +1 -1
- package/dist/i18n/catalog/es.js +2 -1
- package/dist/i18n/catalog/es.js.map +1 -1
- package/dist/i18n/catalog/index.d.ts +2 -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/primitives.d.ts +1 -0
- package/dist/primitives.d.ts.map +1 -1
- package/dist/primitives.js +1 -0
- package/dist/primitives.js.map +1 -1
- package/dist/ui/atoms/cell-value/cell-value.d.ts +2 -1
- package/dist/ui/atoms/cell-value/cell-value.d.ts.map +1 -1
- package/dist/ui/atoms/cell-value/cell-value.js +31 -5
- package/dist/ui/atoms/cell-value/cell-value.js.map +1 -1
- package/dist/ui/atoms/field-control/field-control.d.ts +2 -1
- package/dist/ui/atoms/field-control/field-control.d.ts.map +1 -1
- package/dist/ui/atoms/field-control/field-control.js +19 -0
- package/dist/ui/atoms/field-control/field-control.js.map +1 -1
- package/dist/ui/atoms/money/money-input.d.ts +4 -0
- package/dist/ui/atoms/money/money-input.d.ts.map +1 -1
- package/dist/ui/atoms/money/money-input.js +10 -13
- package/dist/ui/atoms/money/money-input.js.map +1 -1
- package/dist/ui/atoms/number-input/quantity-input.d.ts +19 -4
- package/dist/ui/atoms/number-input/quantity-input.d.ts.map +1 -1
- package/dist/ui/atoms/number-input/quantity-input.js +13 -5
- package/dist/ui/atoms/number-input/quantity-input.js.map +1 -1
- package/dist/ui/atoms/number-input/scaled-quantity-input.d.ts +16 -0
- package/dist/ui/atoms/number-input/scaled-quantity-input.d.ts.map +1 -0
- package/dist/ui/atoms/number-input/scaled-quantity-input.js +135 -0
- package/dist/ui/atoms/number-input/scaled-quantity-input.js.map +1 -0
- package/dist/ui/atoms/number-input/step-button.d.ts +3 -0
- package/dist/ui/atoms/number-input/step-button.d.ts.map +1 -0
- package/dist/ui/atoms/number-input/step-button.js +3 -0
- package/dist/ui/atoms/number-input/step-button.js.map +1 -0
- package/dist/ui/atoms/number-input/unparsed.d.ts +10 -0
- package/dist/ui/atoms/number-input/unparsed.d.ts.map +1 -0
- package/dist/ui/atoms/number-input/unparsed.js +10 -0
- package/dist/ui/atoms/number-input/unparsed.js.map +1 -0
- package/dist/ui/atoms/scaled/index.d.ts +5 -0
- package/dist/ui/atoms/scaled/index.d.ts.map +1 -0
- package/dist/ui/atoms/scaled/index.js +6 -0
- package/dist/ui/atoms/scaled/index.js.map +1 -0
- package/dist/ui/atoms/scaled/scaled-input.d.ts +24 -0
- package/dist/ui/atoms/scaled/scaled-input.d.ts.map +1 -0
- package/dist/ui/atoms/scaled/scaled-input.js +98 -0
- package/dist/ui/atoms/scaled/scaled-input.js.map +1 -0
- package/dist/ui/atoms/scaled/scaled-math.d.ts +13 -0
- package/dist/ui/atoms/scaled/scaled-math.d.ts.map +1 -0
- package/dist/ui/atoms/scaled/scaled-math.js +17 -0
- package/dist/ui/atoms/scaled/scaled-math.js.map +1 -0
- package/dist/ui/atoms/scaled/scaled-value.d.ts +14 -0
- package/dist/ui/atoms/scaled/scaled-value.d.ts.map +1 -0
- package/dist/ui/atoms/scaled/scaled-value.js +14 -0
- package/dist/ui/atoms/scaled/scaled-value.js.map +1 -0
- package/dist/ui/atoms/scaled/use-unit-label.d.ts +4 -0
- package/dist/ui/atoms/scaled/use-unit-label.d.ts.map +1 -0
- package/dist/ui/atoms/scaled/use-unit-label.js +11 -0
- package/dist/ui/atoms/scaled/use-unit-label.js.map +1 -0
- package/dist/ui/organisms/entity-detail-grid/entity-detail-grid.d.ts.map +1 -1
- package/dist/ui/organisms/entity-detail-grid/entity-detail-grid.js +1 -1
- package/dist/ui/organisms/entity-detail-grid/entity-detail-grid.js.map +1 -1
- package/dist/ui/organisms/entity-table/entity-table-slots.d.ts +6 -1
- 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/use-entity-table-columns.d.ts.map +1 -1
- package/dist/ui/organisms/entity-table/use-entity-table-columns.js +2 -0
- package/dist/ui/organisms/entity-table/use-entity-table-columns.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ui/organisms/entity-table/use-entity-table-columns.ts"],"sourcesContent":["'use client';\n\nimport {\n describeEntityColumns,\n type Entity,\n type EntityConstructor,\n} from '@entifix/core';\nimport { useMemo } from 'react';\n\nimport { useLocalizedDescriptors } from '../../../i18n/index.js';\nimport { useUiPreference } from '../../../preferences/index.js';\nimport type { ColumnPersonalization } from '../../molecules/column-settings/index.js';\nimport type { EntityTableColumn } from './entity-table.types.js';\nimport type { EntityColumnProps } from './entity-table-slots.js';\n\nconst EMPTY_PERSONALIZATION: ColumnPersonalization = {};\nconst NONE_WITHHELD: readonly string[] = [];\n\n/**\n * Applies `<EntityColumn>` overrides on top of the metadata descriptors, and\n * appends a virtual column for any slot naming a member the entity does not\n * have (a computed column).\n */\nfunction mergeSlots<TEntity extends Entity>(\n descriptors: Array<EntityTableColumn<TEntity>>,\n slotColumns: Array<EntityColumnProps<TEntity>>,\n): Array<EntityTableColumn<TEntity>> {\n const merged = descriptors.map(descriptor => {\n const slot = slotColumns.find(entry => entry.field === descriptor.name);\n if (!slot) return descriptor;\n const { field: _field, ...overrides } = slot;\n return {\n ...descriptor,\n ...Object.fromEntries(\n Object.entries(overrides).filter(([, value]) => value !== undefined),\n ),\n } as EntityTableColumn<TEntity>;\n });\n\n const virtual = slotColumns\n .filter(slot => !descriptors.some(entry => entry.name === slot.field))\n .map<EntityTableColumn<TEntity>>((slot, index) => ({\n name: slot.field,\n key: slot.field,\n label: slot.label ?? slot.field,\n type: slot.type ?? 'string',\n sortable: slot.sortable ?? false,\n filterable: slot.filterable ?? false,\n order: slot.order ?? descriptors.length + index,\n readonly: false,\n required: false,\n linkLabelProperty: 'name',\n linkSearchProperty: 'name',\n linkSerialization: 'id',\n // A slot-only column has no accessor, so there is nothing for a copy to\n // reset — the value is computed from members that are cloned themselves.\n resetOnClone: false,\n ...(slot.minWidth === undefined ? {} : { minWidth: slot.minWidth }),\n ...(slot.money === undefined ? {} : { money: slot.money }),\n header: slot.header,\n render: slot.render,\n virtual: true,\n }));\n\n return [...merged, ...virtual].sort(\n (left, right) => left.order - right.order,\n );\n}\n\n/**\n * Reorders columns per the stored personalization. Names the user never saw\n * (added to the entity after the layout was saved) keep their default position\n * at the end instead of vanishing, and stale names in the stored order are\n * dropped — so a saved layout degrades rather than breaks.\n */\nfunction applyOrder<TEntity extends Entity>(\n columns: Array<EntityTableColumn<TEntity>>,\n order: string[] | undefined,\n): Array<EntityTableColumn<TEntity>> {\n if (!order || order.length === 0) return columns;\n\n const ranked = order\n .map(name => columns.find(column => column.name === name))\n .filter((column): column is EntityTableColumn<TEntity> => !!column);\n const remaining = columns.filter(column => !order.includes(column.name));\n\n return [...ranked, ...remaining];\n}\n\n/**\n * Drops the columns the host withholds from this reader. Not a hidden column\n * the reader can bring back: it is gone from the settings, the filters, the\n * sort choices and the cards. A name that is no column throws, because a\n * withheld column that is still on screen is the failure nobody would notice.\n */\nfunction withhold<TEntity extends Entity>(\n columns: Array<EntityTableColumn<TEntity>>,\n withheld: readonly string[],\n): Array<EntityTableColumn<TEntity>> {\n for (const name of withheld) {\n if (!columns.some(column => column.name === name)) {\n throw new Error(\n `EntityTable was asked to hide \"${name}\", which is not one of its columns. ` +\n 'Name a member the entity declares, or a column a slot adds.',\n );\n }\n }\n return columns.filter(column => !withheld.includes(column.name));\n}\n\n/**\n * Whether a column is the record's own key — the entity's `id`, not a\n * reference to another record's.\n */\nfunction isOwnKey<TEntity extends Entity>(\n column: EntityTableColumn<TEntity>,\n): boolean {\n return column.type === 'id' && column.references === undefined;\n}\n\n/**\n * The whole column pipeline as a pure function — metadata descriptors, then\n * slot overrides, then what the host withholds and the record's own key\n * (unless `showKey`), then the user's stored layout.\n * Kept separate from the hook so the resolution rules can be reasoned about\n * (and tested) without React.\n */\nexport function resolveEntityTableColumns<TEntity extends Entity>(\n described: Array<EntityTableColumn<TEntity>>,\n slotColumns: Array<EntityColumnProps<TEntity>>,\n personalization: ColumnPersonalization,\n withheld: readonly string[] = NONE_WITHHELD,\n showKey = false,\n): {\n columns: Array<EntityTableColumn<TEntity>>;\n visibleColumns: Array<EntityTableColumn<TEntity>>;\n hidden: string[];\n} {\n const kept = withhold(mergeSlots(described, slotColumns), withheld);\n const columns = applyOrder(\n showKey ? kept : kept.filter(column => !isOwnKey(column)),\n personalization.order,\n );\n const hidden = personalization.hidden ?? [];\n\n return {\n columns,\n visibleColumns: columns.filter(column => !hidden.includes(column.name)),\n hidden,\n };\n}\n\nexport interface UseEntityTableColumnsResult<TEntity extends Entity> {\n /** Every column, in the user's order — what the settings popover lists. */\n columns: Array<EntityTableColumn<TEntity>>;\n /** The subset actually rendered. */\n visibleColumns: Array<EntityTableColumn<TEntity>>;\n hidden: string[];\n personalization: ColumnPersonalization;\n setPersonalization: (next: ColumnPersonalization) => void;\n}\n\n/**\n * Resolves the columns a table renders: entity metadata, then slot overrides,\n * then the user's persisted layout.\n */\nexport function useEntityTableColumns<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n slotColumns: Array<EntityColumnProps<TEntity>>,\n sample: TEntity | undefined,\n preferenceKey: string,\n withheld: readonly string[] = NONE_WITHHELD,\n showKey = false,\n): UseEntityTableColumnsResult<TEntity> {\n const { value: personalization, setValue: setPersonalization } =\n useUiPreference<ColumnPersonalization>(\n preferenceKey,\n EMPTY_PERSONALIZATION,\n );\n\n const metadata = useMemo(\n () =>\n describeEntityColumns(entityConstructor, sample).filter(\n descriptor => descriptor.presentation !== 'none',\n ) as Array<EntityTableColumn<TEntity>>,\n [entityConstructor, sample],\n );\n\n // Before slots merge, so an `<EntityColumn label>` override still wins over\n // the entity's own translated label.\n const described = useLocalizedDescriptors(metadata);\n\n // Not memoized: `slotColumns` is rebuilt from `children` on every render, so\n // any dependency list would miss every time. The work is a few array passes\n // over a handful of columns — cheaper than the comparison would be.\n const { columns, visibleColumns, hidden } = resolveEntityTableColumns(\n described,\n slotColumns,\n personalization,\n withheld,\n showKey,\n );\n\n return {\n columns,\n visibleColumns,\n hidden,\n personalization,\n setPersonalization,\n };\n}\n"],"names":["describeEntityColumns","useMemo","useLocalizedDescriptors","useUiPreference","EMPTY_PERSONALIZATION","NONE_WITHHELD","mergeSlots","descriptors","slotColumns","merged","map","descriptor","slot","find","entry","field","name","_field","overrides","Object","fromEntries","entries","filter","value","undefined","virtual","some","index","key","label","type","sortable","filterable","order","length","readonly","required","linkLabelProperty","linkSearchProperty","linkSerialization","resetOnClone","minWidth","money","header","render","sort","left","right","applyOrder","columns","ranked","column","remaining","includes","withhold","withheld","Error","isOwnKey","references","resolveEntityTableColumns","described","personalization","showKey","kept","hidden","visibleColumns","useEntityTableColumns","entityConstructor","sample","preferenceKey","setValue","setPersonalization","metadata","presentation"],"mappings":"AAAA;;;AAEA,SACEA,qBAAqB,QAGhB,gBAAgB;AACvB,SAASC,OAAO,QAAQ,QAAQ;AAEhC,SAASC,uBAAuB,QAAQ,yBAAyB;AACjE,SAASC,eAAe,QAAQ,gCAAgC;AAKhE,MAAMC,wBAA+C,CAAC;AACtD,MAAMC,gBAAmC,EAAE;AAE3C;;;;CAIC,GACD,SAASC,WACPC,WAA8C,EAC9CC,WAA8C;IAE9C,MAAMC,SAASF,YAAYG,GAAG,CAACC,CAAAA;QAC7B,MAAMC,OAAOJ,YAAYK,IAAI,CAACC,CAAAA,QAASA,MAAMC,KAAK,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AC6B,CAAAA,SAAU,CAACM,SAASN,UACjDU,gBAAgB5B,KAAK;IAEvB,MAAM+B,UAASH,0BAAAA,gBAAgBG,MAAM,YAAtBH,0BAA0B,EAAE;IAE3C,OAAO;QACLZ;QACAgB,gBAAgBhB,QAAQ3B,MAAM,CAAC6B,CAAAA,SAAU,CAACa,OAAOX,QAAQ,CAACF,OAAOnC,IAAI;QACrEgD;IACF;AACF;AAYA;;;CAGC,GACD,OAAO,SAASE,sBACdC,iBAA6C,EAC7C3D,WAA8C,EAC9C4D,MAA2B,EAC3BC,aAAqB,EACrBd,WAA8BlD,aAAa,EAC3CyD,UAAU,KAAK;IAEf,MAAM,EAAEvC,OAAOsC,eAAe,EAAES,UAAUC,kBAAkB,EAAE,GAC5DpE,gBACEkE,eACAjE;IAGJ,MAAMoE,WAAWvE,QACf,IACED,sBAAsBmE,mBAAmBC,QAAQ9C,MAAM,CACrDX,CAAAA,aAAcA,WAAW8D,YAAY,KAAK,SAE9C;QAACN;QAAmBC;KAAO;IAG7B,4EAA4E;IAC5E,qCAAqC;IACrC,MAAMR,YAAY1D,wBAAwBsE;IAE1C,6EAA6E;IAC7E,4EAA4E;IAC5E,oEAAoE;IACpE,MAAM,EAAEvB,OAAO,EAAEgB,cAAc,EAAED,MAAM,EAAE,GAAGL,0BAC1CC,WACApD,aACAqD,iBACAN,UACAO;IAGF,OAAO;QACLb;QACAgB;QACAD;QACAH;QACAU;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/organisms/entity-table/use-entity-table-columns.ts"],"sourcesContent":["'use client';\n\nimport {\n describeEntityColumns,\n type Entity,\n type EntityConstructor,\n} from '@entifix/core';\nimport { useMemo } from 'react';\n\nimport { useLocalizedDescriptors } from '../../../i18n/index.js';\nimport { useUiPreference } from '../../../preferences/index.js';\nimport type { ColumnPersonalization } from '../../molecules/column-settings/index.js';\nimport type { EntityTableColumn } from './entity-table.types.js';\nimport type { EntityColumnProps } from './entity-table-slots.js';\n\nconst EMPTY_PERSONALIZATION: ColumnPersonalization = {};\nconst NONE_WITHHELD: readonly string[] = [];\n\n/**\n * Applies `<EntityColumn>` overrides on top of the metadata descriptors, and\n * appends a virtual column for any slot naming a member the entity does not\n * have (a computed column).\n */\nfunction mergeSlots<TEntity extends Entity>(\n descriptors: Array<EntityTableColumn<TEntity>>,\n slotColumns: Array<EntityColumnProps<TEntity>>,\n): Array<EntityTableColumn<TEntity>> {\n const merged = descriptors.map(descriptor => {\n const slot = slotColumns.find(entry => entry.field === descriptor.name);\n if (!slot) return descriptor;\n const { field: _field, ...overrides } = slot;\n return {\n ...descriptor,\n ...Object.fromEntries(\n Object.entries(overrides).filter(([, value]) => value !== undefined),\n ),\n } as EntityTableColumn<TEntity>;\n });\n\n const virtual = slotColumns\n .filter(slot => !descriptors.some(entry => entry.name === slot.field))\n .map<EntityTableColumn<TEntity>>((slot, index) => ({\n name: slot.field,\n key: slot.field,\n label: slot.label ?? slot.field,\n type: slot.type ?? 'string',\n sortable: slot.sortable ?? false,\n filterable: slot.filterable ?? false,\n order: slot.order ?? descriptors.length + index,\n readonly: false,\n required: false,\n linkLabelProperty: 'name',\n linkSearchProperty: 'name',\n linkSerialization: 'id',\n // A slot-only column has no accessor, so there is nothing for a copy to\n // reset — the value is computed from members that are cloned themselves.\n resetOnClone: false,\n ...(slot.minWidth === undefined ? {} : { minWidth: slot.minWidth }),\n ...(slot.money === undefined ? {} : { money: slot.money }),\n ...(slot.scaled === undefined ? {} : { scaled: slot.scaled }),\n header: slot.header,\n render: slot.render,\n virtual: true,\n }));\n\n return [...merged, ...virtual].sort(\n (left, right) => left.order - right.order,\n );\n}\n\n/**\n * Reorders columns per the stored personalization. Names the user never saw\n * (added to the entity after the layout was saved) keep their default position\n * at the end instead of vanishing, and stale names in the stored order are\n * dropped — so a saved layout degrades rather than breaks.\n */\nfunction applyOrder<TEntity extends Entity>(\n columns: Array<EntityTableColumn<TEntity>>,\n order: string[] | undefined,\n): Array<EntityTableColumn<TEntity>> {\n if (!order || order.length === 0) return columns;\n\n const ranked = order\n .map(name => columns.find(column => column.name === name))\n .filter((column): column is EntityTableColumn<TEntity> => !!column);\n const remaining = columns.filter(column => !order.includes(column.name));\n\n return [...ranked, ...remaining];\n}\n\n/**\n * Drops the columns the host withholds from this reader. Not a hidden column\n * the reader can bring back: it is gone from the settings, the filters, the\n * sort choices and the cards. A name that is no column throws, because a\n * withheld column that is still on screen is the failure nobody would notice.\n */\nfunction withhold<TEntity extends Entity>(\n columns: Array<EntityTableColumn<TEntity>>,\n withheld: readonly string[],\n): Array<EntityTableColumn<TEntity>> {\n for (const name of withheld) {\n if (!columns.some(column => column.name === name)) {\n throw new Error(\n `EntityTable was asked to hide \"${name}\", which is not one of its columns. ` +\n 'Name a member the entity declares, or a column a slot adds.',\n );\n }\n }\n return columns.filter(column => !withheld.includes(column.name));\n}\n\n/**\n * Whether a column is the record's own key — the entity's `id`, not a\n * reference to another record's.\n */\nfunction isOwnKey<TEntity extends Entity>(\n column: EntityTableColumn<TEntity>,\n): boolean {\n return column.type === 'id' && column.references === undefined;\n}\n\n/**\n * The whole column pipeline as a pure function — metadata descriptors, then\n * slot overrides, then what the host withholds and the record's own key\n * (unless `showKey`), then the user's stored layout.\n * Kept separate from the hook so the resolution rules can be reasoned about\n * (and tested) without React.\n */\nexport function resolveEntityTableColumns<TEntity extends Entity>(\n described: Array<EntityTableColumn<TEntity>>,\n slotColumns: Array<EntityColumnProps<TEntity>>,\n personalization: ColumnPersonalization,\n withheld: readonly string[] = NONE_WITHHELD,\n showKey = false,\n): {\n columns: Array<EntityTableColumn<TEntity>>;\n visibleColumns: Array<EntityTableColumn<TEntity>>;\n hidden: string[];\n} {\n const kept = withhold(mergeSlots(described, slotColumns), withheld);\n const columns = applyOrder(\n showKey ? kept : kept.filter(column => !isOwnKey(column)),\n personalization.order,\n );\n const hidden = personalization.hidden ?? [];\n\n return {\n columns,\n visibleColumns: columns.filter(column => !hidden.includes(column.name)),\n hidden,\n };\n}\n\nexport interface UseEntityTableColumnsResult<TEntity extends Entity> {\n /** Every column, in the user's order — what the settings popover lists. */\n columns: Array<EntityTableColumn<TEntity>>;\n /** The subset actually rendered. */\n visibleColumns: Array<EntityTableColumn<TEntity>>;\n hidden: string[];\n personalization: ColumnPersonalization;\n setPersonalization: (next: ColumnPersonalization) => void;\n}\n\n/**\n * Resolves the columns a table renders: entity metadata, then slot overrides,\n * then the user's persisted layout.\n */\nexport function useEntityTableColumns<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n slotColumns: Array<EntityColumnProps<TEntity>>,\n sample: TEntity | undefined,\n preferenceKey: string,\n withheld: readonly string[] = NONE_WITHHELD,\n showKey = false,\n): UseEntityTableColumnsResult<TEntity> {\n const { value: personalization, setValue: setPersonalization } =\n useUiPreference<ColumnPersonalization>(\n preferenceKey,\n EMPTY_PERSONALIZATION,\n );\n\n const metadata = useMemo(\n () =>\n describeEntityColumns(entityConstructor, sample).filter(\n descriptor => descriptor.presentation !== 'none',\n ) as Array<EntityTableColumn<TEntity>>,\n [entityConstructor, sample],\n );\n\n // Before slots merge, so an `<EntityColumn label>` override still wins over\n // the entity's own translated label.\n const described = useLocalizedDescriptors(metadata);\n\n // Not memoized: `slotColumns` is rebuilt from `children` on every render, so\n // any dependency list would miss every time. The work is a few array passes\n // over a handful of columns — cheaper than the comparison would be.\n const { columns, visibleColumns, hidden } = resolveEntityTableColumns(\n described,\n slotColumns,\n personalization,\n withheld,\n showKey,\n );\n\n return {\n columns,\n visibleColumns,\n hidden,\n personalization,\n setPersonalization,\n };\n}\n"],"names":["describeEntityColumns","useMemo","useLocalizedDescriptors","useUiPreference","EMPTY_PERSONALIZATION","NONE_WITHHELD","mergeSlots","descriptors","slotColumns","merged","map","descriptor","slot","find","entry","field","name","_field","overrides","Object","fromEntries","entries","filter","value","undefined","virtual","some","index","key","label","type","sortable","filterable","order","length","readonly","required","linkLabelProperty","linkSearchProperty","linkSerialization","resetOnClone","minWidth","money","scaled","header","render","sort","left","right","applyOrder","columns","ranked","column","remaining","includes","withhold","withheld","Error","isOwnKey","references","resolveEntityTableColumns","described","personalization","showKey","kept","hidden","visibleColumns","useEntityTableColumns","entityConstructor","sample","preferenceKey","setValue","setPersonalization","metadata","presentation"],"mappings":"AAAA;;;AAEA,SACEA,qBAAqB,QAGhB,gBAAgB;AACvB,SAASC,OAAO,QAAQ,QAAQ;AAEhC,SAASC,uBAAuB,QAAQ,yBAAyB;AACjE,SAASC,eAAe,QAAQ,gCAAgC;AAKhE,MAAMC,wBAA+C,CAAC;AACtD,MAAMC,gBAAmC,EAAE;AAE3C;;;;CAIC,GACD,SAASC,WACPC,WAA8C,EAC9CC,WAA8C;IAE9C,MAAMC,SAASF,YAAYG,GAAG,CAACC,CAAAA;QAC7B,MAAMC,OAAOJ,YAAYK,IAAI,CAACC,CAAAA,QAASA,MAAMC,KAAK,KAAKJ,WAAWK,IAAI;QACtE,IAAI,CAACJ,MAAM,OAAOD;QAClB,MAAM,EAAEI,OAAOE,MAAM,EAAgB,GAAGL,MAAdM,6CAAcN;;;QACxC,OAAO,aACFD,YACAQ,OAAOC,WAAW,CACnBD,OAAOE,OAAO,CAACH,WAAWI,MAAM,CAAC,CAAC,GAAGC,MAAM,GAAKA,UAAUC;IAGhE;IAEA,MAAMC,UAAUjB,YACbc,MAAM,CAACV,CAAAA,OAAQ,CAACL,YAAYmB,IAAI,CAACZ,CAAAA,QAASA,MAAME,IAAI,KAAKJ,KAAKG,KAAK,GACnEL,GAAG,CAA6B,CAACE,MAAMe;YAG/Bf,aACDA,YACIA,gBACEA,kBACLA;eAP0C;YACjDI,MAAMJ,KAAKG,KAAK;YAChBa,KAAKhB,KAAKG,KAAK;YACfc,KAAK,GAAEjB,cAAAA,KAAKiB,KAAK,YAAVjB,cAAcA,KAAKG,KAAK;YAC/Be,IAAI,GAAElB,aAAAA,KAAKkB,IAAI,YAATlB,aAAa;YACnBmB,QAAQ,GAAEnB,iBAAAA,KAAKmB,QAAQ,YAAbnB,iBA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C;QAACN;QAAmBC;KAAO;IAG7B,4EAA4E;IAC5E,qCAAqC;IACrC,MAAMR,YAAY3D,wBAAwBuE;IAE1C,6EAA6E;IAC7E,4EAA4E;IAC5E,oEAAoE;IACpE,MAAM,EAAEvB,OAAO,EAAEgB,cAAc,EAAED,MAAM,EAAE,GAAGL,0BAC1CC,WACArD,aACAsD,iBACAN,UACAO;IAGF,OAAO;QACLb;QACAgB;QACAD;QACAH;QACAU;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entifix/react-controls",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.7",
|
|
4
4
|
"description": "Entity-agnostic React UI — table, form, filters, wizard, command palette — rendered from entity metadata, plus layout primitives.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@headlessui/react": "^2.2.10",
|
|
20
20
|
"class-variance-authority": "^0.7.1",
|
|
21
21
|
"idb": "^8.0.4",
|
|
22
|
-
"@entifix/core": "0.23.
|
|
22
|
+
"@entifix/core": "0.23.7"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
"./package.json": "./package.json",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"react": "19.3.1",
|
|
56
56
|
"react-i18next": "18.0.1",
|
|
57
57
|
"storybook": "^10.6.6",
|
|
58
|
-
"@entifix/i18n": "0.23.
|
|
59
|
-
"@entifix/style": "0.23.
|
|
58
|
+
"@entifix/i18n": "0.23.7",
|
|
59
|
+
"@entifix/style": "0.23.7"
|
|
60
60
|
},
|
|
61
61
|
"nx": {
|
|
62
62
|
"tags": [
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"i18next": ">=26 <28",
|
|
112
112
|
"react": ">=19 <20",
|
|
113
113
|
"react-i18next": ">=17 <19",
|
|
114
|
-
"@entifix/i18n": "0.23.
|
|
114
|
+
"@entifix/i18n": "0.23.7"
|
|
115
115
|
},
|
|
116
116
|
"peerDependenciesMeta": {
|
|
117
117
|
"@entifix/i18n": {
|