@economic/taco 2.28.0 → 2.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. package/dist/components/Icon/components/Phone.d.ts +3 -0
  2. package/dist/components/Icon/components/index.d.ts +1 -1
  3. package/dist/components/Input/Input.d.ts +1 -1
  4. package/dist/components/List/components/Item.d.ts +1 -1
  5. package/dist/components/Menu/components/Item.d.ts +1 -1
  6. package/dist/components/Menu/components/Link.d.ts +1 -1
  7. package/dist/components/Navigation2/components/Link.d.ts +1 -1
  8. package/dist/components/Select2/components/Option.d.ts +2 -2
  9. package/dist/components/Select2/components/Search.d.ts +1 -1
  10. package/dist/components/Tag/Tag.d.ts +1 -1
  11. package/dist/esm/index.css +10 -6
  12. package/dist/esm/packages/taco/src/components/Combobox/useCombobox.js +45 -43
  13. package/dist/esm/packages/taco/src/components/Combobox/useCombobox.js.map +1 -1
  14. package/dist/esm/packages/taco/src/components/Datepicker/useDatepicker.js +1 -1
  15. package/dist/esm/packages/taco/src/components/Datepicker/useDatepicker.js.map +1 -1
  16. package/dist/esm/packages/taco/src/components/Icon/components/Phone.js +17 -0
  17. package/dist/esm/packages/taco/src/components/Icon/components/Phone.js.map +1 -0
  18. package/dist/esm/packages/taco/src/components/Icon/components/index.js +2 -0
  19. package/dist/esm/packages/taco/src/components/Icon/components/index.js.map +1 -1
  20. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js +1 -1
  21. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js.map +1 -1
  22. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/util.js +9 -2
  23. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/util.js.map +1 -1
  24. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +4 -1
  25. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js.map +1 -1
  26. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Cell/BuiltIns/DisplayCell.js +3 -7
  27. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Cell/BuiltIns/DisplayCell.js.map +1 -1
  28. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js +1 -1
  29. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js.map +1 -1
  30. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.js +11 -9
  31. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.js.map +1 -1
  32. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +3 -3
  33. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
  34. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableStyleColumnFreezing.js +4 -2
  35. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableStyleColumnFreezing.js.map +1 -1
  36. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableStyleGrid.js +9 -8
  37. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableStyleGrid.js.map +1 -1
  38. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/columns.js +7 -1
  39. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/columns.js.map +1 -1
  40. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +15 -11
  41. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
  42. package/dist/esm/packages/taco/src/utils/date.js +3 -3
  43. package/dist/esm/packages/taco/src/utils/date.js.map +1 -1
  44. package/dist/index.css +10 -6
  45. package/dist/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.d.ts +1 -3
  46. package/dist/primitives/Table/useTableManager/util/columns.d.ts +1 -1
  47. package/dist/taco.cjs.development.js +128 -91
  48. package/dist/taco.cjs.development.js.map +1 -1
  49. package/dist/taco.cjs.production.min.js +1 -1
  50. package/dist/taco.cjs.production.min.js.map +1 -1
  51. package/dist/utils/date.d.ts +1 -1
  52. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"useTableEditing.js","sources":["../../../../../../../../src/components/Table3/features/useTableEditing.ts"],"sourcesContent":["import React from 'react';\nimport { Cell as ReactTableCell, Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { Table3EditingSaveHandler, Table3EditingValidatorFn } from '../types';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../utils/dom';\nimport { useGlobalKeyDown } from '../../../hooks/useGlobalKeyDown';\nimport { willRowMove } from '../util/editing';\nimport { TableRef } from '../../../primitives/Table/types';\n\nexport function useTableEditing<TType = unknown>(\n isEnabled = false,\n handleSave: Table3EditingSaveHandler<TType> | undefined,\n validator: Table3EditingValidatorFn<TType> | undefined\n) {\n // used to switch the table into editing mode\n const [isEditing, toggleEditing] = React.useState(false);\n\n // used to switch the editing between \"detailed\" mode\n const [isDetailedMode, toggleDetailedMode] = React.useState(false);\n\n // store the last focused cell, so that up/down arrow key navigation remains in the same column\n const [lastFocusedCellIndex, setLastFocusedCellIndex] = useLastFocusedCellIndex();\n\n // store pending changes for each row\n // changes are saved as soon as the active row changes, so in most cases this will only contain the active row's changes\n // but not always - if validation or server requests fail when saving, those rows remain until the failure is resolved\n const pendingChangesFns = usePendingChanges<TType>(isEnabled, handleSave, validator);\n\n // if focus leaves the table in any way, trigger a save\n const handleBlur = React.useCallback(\n (event: React.FocusEvent<HTMLTableElement>) => {\n if (\n event.relatedTarget !== event.currentTarget &&\n !isElementInsideOrTriggeredFromContainer(event.relatedTarget, event.currentTarget)\n ) {\n pendingChangesFns.saveChanges();\n }\n },\n [pendingChangesFns.saveChanges]\n );\n\n // TODO: using useGlobalKeyDown prevents trigger when focused on inputs, but it's more \"proper\"\n useGlobalKeyDown(isEnabled && isEditing ? { key: 's', meta: true, shift: false } : undefined, event => {\n event.preventDefault();\n pendingChangesFns.saveChanges();\n });\n\n return {\n isEnabled,\n isEditing,\n isDetailedMode,\n toggleDetailedMode: isEnabled ? toggleDetailedMode : () => undefined,\n toggleEditing: isEnabled ? toggleEditing : () => undefined,\n lastFocusedCellIndex,\n setLastFocusedCellIndex,\n ...pendingChangesFns,\n handleBlur: isEnabled && isEditing ? handleBlur : () => undefined,\n };\n}\n\ntype SaveState = 'pending' | 'complete';\ntype PendingChange<TType = unknown> = Partial<TType> & {\n _meta: {\n original: TType;\n moveReason: Record<string, 'search' | 'sorting' | 'filter'>;\n errors: {\n row: string;\n cells: Record<string, string>;\n hasShownErrorAlert: boolean;\n };\n status?: SaveState;\n };\n};\n\nfunction usePendingChanges<TType = unknown>(\n isEnabled: boolean,\n handleSave: Table3EditingSaveHandler<TType> | undefined,\n validator: Table3EditingValidatorFn<TType> | undefined\n) {\n const [pendingChanges, setPendingChanges] = React.useState<Record<string, PendingChange<TType>>>({});\n // we maintain save status as separate state because 'complete' needs to briefly show after pendingChanges are deleted\n const [saveStates, setSaveState] = React.useState<Record<string, SaveState>>({});\n\n function getCellValue<T extends TType>(cell: ReactTableCell<T, unknown>): unknown | undefined {\n return pendingChanges[cell.row.id]?.[cell.column.id];\n }\n\n function getCellError<T extends TType>(cell: ReactTableCell<T, unknown>): string | undefined {\n return pendingChanges[cell.row.id]?._meta.errors?.cells?.[cell.column.id];\n }\n\n const setCellValue = React.useCallback(function <T extends TType>(\n cell: ReactTableCell<T, unknown>,\n change: unknown,\n rowIndex: number\n ) {\n setPendingChanges(currentChanges => {\n const nextChanges = { ...currentChanges };\n const rowChanges = {\n ...currentChanges[cell.row.id],\n _meta: {\n ...currentChanges[cell.row.id]?._meta,\n original: cell.row.original,\n moveReason: {\n ...currentChanges[cell.row.id]?._meta.moveReason,\n },\n errors: {\n ...currentChanges[cell.row.id]?._meta.errors,\n },\n },\n } as PendingChange<T>;\n\n // update if the change is different to the original (saved) value,\n // otherwise remove any change - no point saving the same value\n if (change !== cell.row.original[cell.column.id]) {\n rowChanges[cell.column.id] = change;\n\n // determine if the row will move position based on this change, and save why it will move\n const reason = willRowMove(cell, change, rowIndex);\n\n if (reason) {\n rowChanges._meta.moveReason[cell.column.id] = reason;\n } else {\n delete rowChanges._meta.moveReason[cell.column.id];\n }\n } else {\n delete rowChanges[cell.column.id];\n }\n\n // set the changes for the row...\n // or delete if there are no changes left, so that we don't store changes with unchanged data\n if (Object.keys(rowChanges).filter(k => k !== '_meta').length) {\n nextChanges[cell.row.id] = rowChanges;\n } else {\n delete nextChanges[cell.row.id];\n }\n\n return nextChanges;\n });\n },\n []);\n\n async function validateCell<T extends TType>(cell: ReactTableCell<T, unknown>) {\n if (!validator || !isEnabled) {\n return;\n }\n\n const changeSet = getChangesetFromChanges(pendingChanges[cell.row.id]);\n\n // only validate if the cell being blurred actually has any changes\n if (cell.column.id in changeSet) {\n const errors = ((await validator(changeSet)) ?? {}) as Record<string, string>;\n\n setPendingChanges(currentChanges => {\n const nextChanges = { ...currentChanges };\n nextChanges[cell.row.id]._meta = {\n ...nextChanges[cell.row.id]._meta,\n errors: {\n ...nextChanges[cell.row.id]._meta.errors,\n cells: errors,\n hasShownErrorAlert:\n Object.keys(errors).length && !nextChanges[cell.row.id]._meta.errors.hasShownErrorAlert\n ? false\n : nextChanges[cell.row.id]._meta.errors.hasShownErrorAlert,\n },\n };\n return nextChanges;\n });\n }\n }\n\n function hasRowErrors(rowId: string) {\n if (!isEnabled) {\n return false;\n }\n\n return (\n !!pendingChanges[rowId]?._meta.errors?.row || !!Object.keys(pendingChanges[rowId]?._meta.errors?.cells ?? {}).length\n );\n }\n\n function hasRowErrorsSeen(rowId: string) {\n if (!isEnabled) {\n return false;\n }\n\n return hasRowErrors(rowId) && !!pendingChanges[rowId]._meta.errors?.hasShownErrorAlert;\n }\n\n function setRowErrorsSeen(rowId: string) {\n if (pendingChanges[rowId]._meta.errors?.hasShownErrorAlert === false) {\n setPendingChanges(currentChanges => {\n const nextChanges = { ...currentChanges };\n nextChanges[rowId]._meta.errors = {\n ...nextChanges[rowId]._meta.errors,\n hasShownErrorAlert: true,\n };\n return nextChanges;\n });\n }\n }\n\n function getRowSaveStatus(rowId: string) {\n if (!isEnabled) {\n return false;\n }\n\n return saveStates[rowId];\n }\n\n function setRowSaveStatus(rowId: string, status: 'pending' | 'complete' | undefined) {\n setSaveState(currentStates => {\n const nextStates = { ...currentStates };\n\n if (status) {\n nextStates[rowId] = status;\n } else {\n delete nextStates[rowId];\n }\n\n return nextStates;\n });\n }\n\n function getRowMoveReason(rowId: string) {\n return pendingChanges[rowId]?._meta.moveReason ? Object.values(pendingChanges[rowId]._meta.moveReason)[0] : undefined;\n }\n\n function hasChanges(rowId?: string) {\n if (!isEnabled) {\n return false;\n }\n\n return rowId ? !!pendingChanges[rowId] : !!Object.keys(pendingChanges).length;\n }\n\n function hasErrors<T extends TType>(table: ReactTable<T>, tableRef: React.RefObject<TableRef>) {\n if (!isEnabled) {\n return false;\n }\n\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const focusIsInsideTable = tableRef.current?.contains(document.activeElement);\n\n let activeRow;\n\n if (tableMeta.rowActive.rowActiveIndex !== undefined) {\n activeRow = table.getRowModel().rows[tableMeta.rowActive.rowActiveIndex];\n }\n\n return Object.keys(\n getErrors().filter(error => {\n if (activeRow?.id && focusIsInsideTable) {\n return error.rowId === activeRow?.id ? error.pendingChange._meta.errors.hasShownErrorAlert : true;\n }\n\n return true;\n })\n ).length;\n }\n\n function getErrors<T extends TType>() {\n return Object.keys(pendingChanges)\n .filter(hasRowErrors)\n .map(rowId => ({ rowId, pendingChange: pendingChanges[rowId] as PendingChange<T> }));\n }\n\n function resetChanges(rowId: string) {\n setPendingChanges(currentChanges => {\n const nextChanges = { ...currentChanges };\n delete nextChanges[rowId];\n return nextChanges;\n });\n }\n\n async function saveChanges(rowId: string | undefined = undefined) {\n if (!handleSave) {\n console.warn('Tried to save, but Table has no onSave handler');\n return;\n }\n\n // we save back to pendingChanges, so make a copy of it's state when save was triggered\n const changesToSave = rowId ? { [rowId]: pendingChanges[rowId] } : { ...pendingChanges };\n const changes = Object.keys(changesToSave);\n\n if (changes.length) {\n changes.map(async rowId => {\n const pendingChange = changesToSave[rowId];\n\n const changeSet = getChangesetFromChanges(pendingChange);\n\n try {\n // set saving = true\n setRowSaveStatus(rowId, 'pending');\n\n // re-run validation, maybe a cell is already invalid but has never been blurred\n if (validator) {\n const errors = await validator(changeSet);\n\n if (errors && Object.keys(errors).length) {\n throw errors;\n }\n }\n\n // send new data to the server\n await handleSave(changeSet);\n\n // cleanup changes, we don't need them after saving\n resetChanges(rowId);\n setRowSaveStatus(rowId, 'complete');\n } catch (error) {\n // the onSave handler should throw errors when something fails, e.g. validation, network errors etc\n // this code handles those errors and maps them either to row errors or cell specific errors\n let rowError;\n let cellErrors;\n\n if (typeof error === 'string') {\n rowError = error;\n } else if (error instanceof Error) {\n rowError = error.message;\n\n // most of our apis return error objects within this shape\n if (typeof (error as any).response?.data === 'object') {\n cellErrors = (error as any).response?.data;\n }\n } else if (typeof error === 'object') {\n cellErrors = error;\n }\n\n if (rowError || cellErrors) {\n setPendingChanges(currentChanges => {\n const nextChanges = { ...currentChanges };\n nextChanges[rowId]._meta.errors = {\n row: rowError,\n cells: cellErrors,\n hasShownErrorAlert: nextChanges[rowId]._meta.errors?.hasShownErrorAlert ?? false,\n };\n return nextChanges;\n });\n }\n\n setRowSaveStatus(rowId, undefined);\n }\n });\n }\n }\n\n return {\n getCellValue,\n getCellError,\n setCellValue,\n validateCell,\n hasChanges,\n hasErrors,\n getErrors,\n saveChanges,\n resetChanges,\n hasRowErrors,\n hasRowErrorsSeen,\n setRowErrorsSeen,\n getRowSaveStatus,\n setRowSaveStatus,\n getRowMoveReason,\n };\n}\n\nfunction useLastFocusedCellIndex(): [number | undefined, (index: number | undefined) => void] {\n // store the last focused cell, so that up/down arrow key navigation remains in the same column\n const lastFocusedCellIndexRef = React.useRef<number | undefined>(undefined);\n const setLastFocusedCellIndex = React.useCallback((index: number | undefined) => {\n lastFocusedCellIndexRef.current = index;\n }, []);\n\n return [lastFocusedCellIndexRef.current, setLastFocusedCellIndex];\n}\n\nfunction getChangesetFromChanges<TType = unknown>(changes: PendingChange<TType>): TType {\n // extract the original data from the row changes\n const { _meta, ...changeset } = changes ?? {};\n // and mix them in with the changes, ready to send to the server\n return { ..._meta?.original, ...changeset };\n}\n"],"names":["useTableEditing","isEnabled","handleSave","validator","isEditing","toggleEditing","React","useState","isDetailedMode","toggleDetailedMode","lastFocusedCellIndex","setLastFocusedCellIndex","useLastFocusedCellIndex","pendingChangesFns","usePendingChanges","handleBlur","useCallback","event","relatedTarget","currentTarget","isElementInsideOrTriggeredFromContainer","saveChanges","useGlobalKeyDown","key","meta","shift","undefined","preventDefault","rowId","console","warn","Promise","resolve","changesToSave","pendingChanges","changes","Object","keys","length","map","pendingChange","changeSet","getChangesetFromChanges","_catch","_temp3","_result","_exit","then","resetChanges","setRowSaveStatus","_temp2","errors","error","rowError","cellErrors","Error","_error$response","message","response","data","_error$response2","setPendingChanges","currentChanges","nextChanges","_meta","row","cells","hasShownErrorAlert","_nextChanges$rowId$_m","_nextChanges$rowId$_m2","e","reject","validateCell","cell","id","_temp","column","saveStates","setSaveState","getCellValue","_pendingChanges$cell$","getCellError","_pendingChanges$cell$2","_pendingChanges$cell$3","_pendingChanges$cell$4","setCellValue","change","rowIndex","rowChanges","_currentChanges$cell$","original","moveReason","_currentChanges$cell$2","_currentChanges$cell$3","reason","willRowMove","filter","k","hasRowErrors","_pendingChanges$rowId","_pendingChanges$rowId2","_pendingChanges$rowId3","_pendingChanges$rowId4","_pendingChanges$rowId5","hasRowErrorsSeen","_pendingChanges$rowId6","setRowErrorsSeen","_pendingChanges$rowId7","getRowSaveStatus","status","currentStates","nextStates","getRowMoveReason","_pendingChanges$rowId8","values","hasChanges","hasErrors","table","tableRef","tableMeta","options","focusIsInsideTable","_tableRef$current","current","contains","document","activeElement","activeRow","rowActive","rowActiveIndex","getRowModel","rows","getErrors","_activeRow","_activeRow2","lastFocusedCellIndexRef","useRef","index","changeset"],"mappings":";;;;;;SAQgBA,eAAe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IACZkD,YAAY;IACZM,gBAAgB;IAChBE,gBAAgB;IAChBE,gBAAgB;IAChB3D,gBAAgB;IAChB+D;GACH;AACL;AAEA,SAASpG,uBAAuBA;;EAE5B,MAAM2H,uBAAuB,GAAGjI,cAAK,CAACkI,MAAM,CAAqB9G,SAAS,CAAC;EAC3E,MAAMf,uBAAuB,GAAGL,cAAK,CAACU,WAAW,CAAEyH,KAAyB;IACxEF,uBAAuB,CAACZ,OAAO,GAAGc,KAAK;GAC1C,EAAE,EAAE,CAAC;EAEN,OAAO,CAACF,uBAAuB,CAACZ,OAAO,EAAEhH,uBAAuB,CAAC;AACrE;AAEA,SAAS+B,uBAAuBA,CAAkBP,OAA6B;;EAE3E,MAAM;IAAE6B,KAAK;IAAE,GAAG0E;GAAW,GAAGvG,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAI,EAAE;;EAE7C,OAAO;IAAE,IAAG6B,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAE0B,QAAQ;IAAE,GAAGgD;GAAW;AAC/C;;;;"}
1
+ {"version":3,"file":"useTableEditing.js","sources":["../../../../../../../../src/components/Table3/features/useTableEditing.ts"],"sourcesContent":["import React from 'react';\nimport { Cell as ReactTableCell, Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { Table3EditingSaveHandler, Table3EditingValidatorFn } from '../types';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../utils/dom';\nimport { useGlobalKeyDown } from '../../../hooks/useGlobalKeyDown';\nimport { willRowMove } from '../util/editing';\nimport { TableRef } from '../../../primitives/Table/types';\nimport { isDate } from 'date-fns';\n\nexport function useTableEditing<TType = unknown>(\n isEnabled = false,\n handleSave: Table3EditingSaveHandler<TType> | undefined,\n validator: Table3EditingValidatorFn<TType> | undefined\n) {\n // used to switch the table into editing mode\n const [isEditing, toggleEditing] = React.useState(false);\n\n // used to switch the editing between \"detailed\" mode\n const [isDetailedMode, toggleDetailedMode] = React.useState(false);\n\n // store the last focused cell, so that up/down arrow key navigation remains in the same column\n const [lastFocusedCellIndex, setLastFocusedCellIndex] = useLastFocusedCellIndex();\n\n // store pending changes for each row\n // changes are saved as soon as the active row changes, so in most cases this will only contain the active row's changes\n // but not always - if validation or server requests fail when saving, those rows remain until the failure is resolved\n const pendingChangesFns = usePendingChanges<TType>(isEnabled, handleSave, validator);\n\n // if focus leaves the table in any way, trigger a save\n const handleBlur = React.useCallback(\n (event: React.FocusEvent<HTMLTableElement>) => {\n // custom event from datepicker, and it doesn't have the relatedTarget property set.\n const isClosingDatepicker = isDate((event as any).detail);\n\n if (\n event.relatedTarget !== event.currentTarget &&\n !isElementInsideOrTriggeredFromContainer(event.relatedTarget, event.currentTarget) &&\n !isClosingDatepicker\n ) {\n pendingChangesFns.saveChanges();\n }\n },\n [pendingChangesFns.saveChanges]\n );\n\n // TODO: using useGlobalKeyDown prevents trigger when focused on inputs, but it's more \"proper\"\n useGlobalKeyDown(isEnabled && isEditing ? { key: 's', meta: true, shift: false } : undefined, event => {\n event.preventDefault();\n pendingChangesFns.saveChanges();\n });\n\n return {\n isEnabled,\n isEditing,\n isDetailedMode,\n toggleDetailedMode: isEnabled ? toggleDetailedMode : () => undefined,\n toggleEditing: isEnabled ? toggleEditing : () => undefined,\n lastFocusedCellIndex,\n setLastFocusedCellIndex,\n ...pendingChangesFns,\n handleBlur: isEnabled && isEditing ? handleBlur : () => undefined,\n };\n}\n\ntype SaveState = 'pending' | 'complete';\ntype PendingChange<TType = unknown> = Partial<TType> & {\n _meta: {\n original: TType;\n moveReason: Record<string, 'search' | 'sorting' | 'filter'>;\n errors: {\n row: string;\n cells: Record<string, string>;\n hasShownErrorAlert: boolean;\n };\n status?: SaveState;\n };\n};\n\nfunction usePendingChanges<TType = unknown>(\n isEnabled: boolean,\n handleSave: Table3EditingSaveHandler<TType> | undefined,\n validator: Table3EditingValidatorFn<TType> | undefined\n) {\n const [pendingChanges, setPendingChanges] = React.useState<Record<string, PendingChange<TType>>>({});\n // we maintain save status as separate state because 'complete' needs to briefly show after pendingChanges are deleted\n const [saveStates, setSaveState] = React.useState<Record<string, SaveState>>({});\n\n function getCellValue<T extends TType>(cell: ReactTableCell<T, unknown>): unknown | undefined {\n return pendingChanges[cell.row.id]?.[cell.column.id];\n }\n\n function getCellError<T extends TType>(cell: ReactTableCell<T, unknown>): string | undefined {\n return pendingChanges[cell.row.id]?._meta.errors?.cells?.[cell.column.id];\n }\n\n const setCellValue = React.useCallback(function <T extends TType>(\n cell: ReactTableCell<T, unknown>,\n change: unknown,\n rowIndex: number\n ) {\n setPendingChanges(currentChanges => {\n const nextChanges = { ...currentChanges };\n const rowChanges = {\n ...currentChanges[cell.row.id],\n _meta: {\n ...currentChanges[cell.row.id]?._meta,\n original: cell.row.original,\n moveReason: {\n ...currentChanges[cell.row.id]?._meta.moveReason,\n },\n errors: {\n ...currentChanges[cell.row.id]?._meta.errors,\n },\n },\n } as PendingChange<T>;\n\n // update if the change is different to the original (saved) value,\n // otherwise remove any change - no point saving the same value\n if (change !== cell.row.original[cell.column.id]) {\n rowChanges[cell.column.id] = change;\n\n // determine if the row will move position based on this change, and save why it will move\n const reason = willRowMove(cell, change, rowIndex);\n\n if (reason) {\n rowChanges._meta.moveReason[cell.column.id] = reason;\n } else {\n delete rowChanges._meta.moveReason[cell.column.id];\n }\n } else {\n delete rowChanges[cell.column.id];\n }\n\n // set the changes for the row...\n // or delete if there are no changes left, so that we don't store changes with unchanged data\n if (Object.keys(rowChanges).filter(k => k !== '_meta').length) {\n nextChanges[cell.row.id] = rowChanges;\n } else {\n delete nextChanges[cell.row.id];\n }\n\n return nextChanges;\n });\n },\n []);\n\n async function validateCell<T extends TType>(cell: ReactTableCell<T, unknown>) {\n if (!validator || !isEnabled) {\n return;\n }\n\n const changeSet = getChangesetFromChanges(pendingChanges[cell.row.id]);\n\n // only validate if the cell being blurred actually has any changes\n if (cell.column.id in changeSet) {\n const errors = ((await validator(changeSet)) ?? {}) as Record<string, string>;\n\n setPendingChanges(currentChanges => {\n const nextChanges = { ...currentChanges };\n nextChanges[cell.row.id]._meta = {\n ...nextChanges[cell.row.id]._meta,\n errors: {\n ...nextChanges[cell.row.id]._meta.errors,\n cells: errors,\n hasShownErrorAlert:\n Object.keys(errors).length && !nextChanges[cell.row.id]._meta.errors.hasShownErrorAlert\n ? false\n : nextChanges[cell.row.id]._meta.errors.hasShownErrorAlert,\n },\n };\n return nextChanges;\n });\n }\n }\n\n function hasRowErrors(rowId: string) {\n if (!isEnabled) {\n return false;\n }\n\n return (\n !!pendingChanges[rowId]?._meta.errors?.row || !!Object.keys(pendingChanges[rowId]?._meta.errors?.cells ?? {}).length\n );\n }\n\n function hasRowErrorsSeen(rowId: string) {\n if (!isEnabled) {\n return false;\n }\n\n return hasRowErrors(rowId) && !!pendingChanges[rowId]._meta.errors?.hasShownErrorAlert;\n }\n\n function setRowErrorsSeen(rowId: string) {\n if (pendingChanges[rowId]._meta.errors?.hasShownErrorAlert === false) {\n setPendingChanges(currentChanges => {\n const nextChanges = { ...currentChanges };\n nextChanges[rowId]._meta.errors = {\n ...nextChanges[rowId]._meta.errors,\n hasShownErrorAlert: true,\n };\n return nextChanges;\n });\n }\n }\n\n function getRowSaveStatus(rowId: string) {\n if (!isEnabled) {\n return false;\n }\n\n return saveStates[rowId];\n }\n\n function setRowSaveStatus(rowId: string, status: 'pending' | 'complete' | undefined) {\n setSaveState(currentStates => {\n const nextStates = { ...currentStates };\n\n if (status) {\n nextStates[rowId] = status;\n } else {\n delete nextStates[rowId];\n }\n\n return nextStates;\n });\n }\n\n function getRowMoveReason(rowId: string) {\n return pendingChanges[rowId]?._meta.moveReason ? Object.values(pendingChanges[rowId]._meta.moveReason)[0] : undefined;\n }\n\n function hasChanges(rowId?: string) {\n if (!isEnabled) {\n return false;\n }\n\n return rowId ? !!pendingChanges[rowId] : !!Object.keys(pendingChanges).length;\n }\n\n function hasErrors<T extends TType>(table: ReactTable<T>, tableRef: React.RefObject<TableRef>) {\n if (!isEnabled) {\n return false;\n }\n\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const focusIsInsideTable = tableRef.current?.contains(document.activeElement);\n\n let activeRow;\n\n if (tableMeta.rowActive.rowActiveIndex !== undefined) {\n activeRow = table.getRowModel().rows[tableMeta.rowActive.rowActiveIndex];\n }\n\n return Object.keys(\n getErrors().filter(error => {\n if (activeRow?.id && focusIsInsideTable) {\n return error.rowId === activeRow?.id ? error.pendingChange._meta.errors.hasShownErrorAlert : true;\n }\n\n return true;\n })\n ).length;\n }\n\n function getErrors<T extends TType>() {\n return Object.keys(pendingChanges)\n .filter(hasRowErrors)\n .map(rowId => ({ rowId, pendingChange: pendingChanges[rowId] as PendingChange<T> }));\n }\n\n function resetChanges(rowId: string) {\n setPendingChanges(currentChanges => {\n const nextChanges = { ...currentChanges };\n delete nextChanges[rowId];\n return nextChanges;\n });\n }\n\n async function saveChanges(rowId: string | undefined = undefined) {\n if (!handleSave) {\n console.warn('Tried to save, but Table has no onSave handler');\n return;\n }\n\n // we save back to pendingChanges, so make a copy of it's state when save was triggered\n const changesToSave = rowId ? { [rowId]: pendingChanges[rowId] } : { ...pendingChanges };\n const changes = Object.keys(changesToSave);\n\n if (changes.length) {\n changes.map(async rowId => {\n const pendingChange = changesToSave[rowId];\n\n const changeSet = getChangesetFromChanges(pendingChange);\n\n try {\n // set saving = true\n setRowSaveStatus(rowId, 'pending');\n\n // re-run validation, maybe a cell is already invalid but has never been blurred\n if (validator) {\n const errors = await validator(changeSet);\n\n if (errors && Object.keys(errors).length) {\n throw errors;\n }\n }\n\n // send new data to the server\n await handleSave(changeSet);\n\n // cleanup changes, we don't need them after saving\n resetChanges(rowId);\n setRowSaveStatus(rowId, 'complete');\n } catch (error) {\n // the onSave handler should throw errors when something fails, e.g. validation, network errors etc\n // this code handles those errors and maps them either to row errors or cell specific errors\n let rowError;\n let cellErrors;\n\n if (typeof error === 'string') {\n rowError = error;\n } else if (error instanceof Error) {\n rowError = error.message;\n\n // most of our apis return error objects within this shape\n if (typeof (error as any).response?.data === 'object') {\n cellErrors = (error as any).response?.data;\n }\n } else if (typeof error === 'object') {\n cellErrors = error;\n }\n\n if (rowError || cellErrors) {\n setPendingChanges(currentChanges => {\n const nextChanges = { ...currentChanges };\n nextChanges[rowId]._meta.errors = {\n row: rowError,\n cells: cellErrors,\n hasShownErrorAlert: nextChanges[rowId]._meta.errors?.hasShownErrorAlert ?? false,\n };\n return nextChanges;\n });\n }\n\n setRowSaveStatus(rowId, undefined);\n }\n });\n }\n }\n\n return {\n getCellValue,\n getCellError,\n setCellValue,\n validateCell,\n hasChanges,\n hasErrors,\n getErrors,\n saveChanges,\n resetChanges,\n hasRowErrors,\n hasRowErrorsSeen,\n setRowErrorsSeen,\n getRowSaveStatus,\n setRowSaveStatus,\n getRowMoveReason,\n };\n}\n\nfunction useLastFocusedCellIndex(): [number | undefined, (index: number | undefined) => void] {\n // store the last focused cell, so that up/down arrow key navigation remains in the same column\n const lastFocusedCellIndexRef = React.useRef<number | undefined>(undefined);\n const setLastFocusedCellIndex = React.useCallback((index: number | undefined) => {\n lastFocusedCellIndexRef.current = index;\n }, []);\n\n return [lastFocusedCellIndexRef.current, setLastFocusedCellIndex];\n}\n\nfunction getChangesetFromChanges<TType = unknown>(changes: PendingChange<TType>): TType {\n // extract the original data from the row changes\n const { _meta, ...changeset } = changes ?? {};\n // and mix them in with the changes, ready to send to the server\n return { ..._meta?.original, ...changeset };\n}\n"],"names":["useTableEditing","isEnabled","handleSave","validator","isEditing","toggleEditing","React","useState","isDetailedMode","toggleDetailedMode","lastFocusedCellIndex","setLastFocusedCellIndex","useLastFocusedCellIndex","pendingChangesFns","usePendingChanges","handleBlur","useCallback","event","isClosingDatepicker","isDate","detail","relatedTarget","currentTarget","isElementInsideOrTriggeredFromContainer","saveChanges","useGlobalKeyDown","key","meta","shift","undefined","preventDefault","rowId","console","warn","Promise","resolve","changesToSave","pendingChanges","changes","Object","keys","length","map","pendingChange","changeSet","getChangesetFromChanges","_catch","_temp3","_result","_exit","then","resetChanges","setRowSaveStatus","_temp2","errors","error","rowError","cellErrors","Error","_error$response","message","response","data","_error$response2","setPendingChanges","currentChanges","nextChanges","_meta","row","cells","hasShownErrorAlert","_nextChanges$rowId$_m","_nextChanges$rowId$_m2","e","reject","validateCell","cell","id","_temp","column","saveStates","setSaveState","getCellValue","_pendingChanges$cell$","getCellError","_pendingChanges$cell$2","_pendingChanges$cell$3","_pendingChanges$cell$4","setCellValue","change","rowIndex","rowChanges","_currentChanges$cell$","original","moveReason","_currentChanges$cell$2","_currentChanges$cell$3","reason","willRowMove","filter","k","hasRowErrors","_pendingChanges$rowId","_pendingChanges$rowId2","_pendingChanges$rowId3","_pendingChanges$rowId4","_pendingChanges$rowId5","hasRowErrorsSeen","_pendingChanges$rowId6","setRowErrorsSeen","_pendingChanges$rowId7","getRowSaveStatus","status","currentStates","nextStates","getRowMoveReason","_pendingChanges$rowId8","values","hasChanges","hasErrors","table","tableRef","tableMeta","options","focusIsInsideTable","_tableRef$current","current","contains","document","activeElement","activeRow","rowActive","rowActiveIndex","getRowModel","rows","getErrors","_activeRow","_activeRow2","lastFocusedCellIndexRef","useRef","index","changeset"],"mappings":";;;;;;;SASgBA,eAAeA,CAC3BC,SAAS,GAAG,KAAK,EACjBC,UAAuD,EACvDC,SAAsD;;EAGtD,MAAM,CAACC,SAAS,EAAEC,aAAa,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;;EAGxD,MAAM,CAACC,cAAc,EAAEC,kBAAkB,CAAC,GAAGH,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;;EAGlE,MAAM,CAACG,oBAAoB,EAAEC,uBAAuB,CAAC,GAAGC,uBAAuB,EAAE;;;;EAKjF,MAAMC,iBAAiB,GAAGC,iBAAiB,CAAQb,SAAS,EAAEC,UAAU,EAAEC,SAAS,CAAC;;EAGpF,MAAMY,UAAU,GAAGT,cAAK,CAACU,WAAW,CAC/BC,KAAyC;;IAEtC,MAAMC,mBAAmB,GAAGC,MAAM,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,uBAAuBA,CAAkBP,OAA6B;;EAE3E,MAAM;IAAE6B,KAAK;IAAE,GAAG0E;GAAW,GAAGvG,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAI,EAAE;;EAE7C,OAAO;IAAE,IAAG6B,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAE0B,QAAQ;IAAE,GAAGgD;GAAW;AAC/C;;;;"}
@@ -1,7 +1,6 @@
1
1
  import React__default from 'react';
2
2
  import { flexRender } from '@tanstack/react-table';
3
3
  import { isInternalColumn } from '../../../../../useTableManager/util/columns.js';
4
- import { RowContext } from '../../../Row/RowContext.js';
5
4
  import { getCellAttributes } from '../util.js';
6
5
 
7
6
  function DisplayCell(props) {
@@ -12,23 +11,20 @@ function DisplayCell(props) {
12
11
  isHighlighted,
13
12
  ...cellAttributes
14
13
  } = props;
15
- const {
16
- isHovered
17
- } = React__default.useContext(RowContext);
18
14
  const columnMeta = cell.column.columnDef.meta;
19
15
  const attributes = getCellAttributes(cell, index, isHighlighted);
20
16
  const isTruncated = !!columnMeta.enableTruncate;
17
+ const value = cell.getValue();
21
18
  let content;
22
19
  if (isInternalColumn(cell.column.id)) {
23
20
  content = flexRender(cell.column.columnDef.cell, cell.getContext());
24
21
  } else {
25
22
  var _ref, _columnMeta$renderer, _columnMeta$renderer2;
26
- content = (_ref = (_columnMeta$renderer = (_columnMeta$renderer2 = columnMeta.renderer) === null || _columnMeta$renderer2 === void 0 ? void 0 : _columnMeta$renderer2.call(columnMeta, cell.getValue(), cell.row.original)) !== null && _columnMeta$renderer !== void 0 ? _columnMeta$renderer : cell.getValue()) !== null && _ref !== void 0 ? _ref : null;
23
+ content = (_ref = (_columnMeta$renderer = (_columnMeta$renderer2 = columnMeta.renderer) === null || _columnMeta$renderer2 === void 0 ? void 0 : _columnMeta$renderer2.call(columnMeta, value, cell.row.original)) !== null && _columnMeta$renderer !== void 0 ? _columnMeta$renderer : value) !== null && _ref !== void 0 ? _ref : null;
27
24
  }
28
25
  return /*#__PURE__*/React__default.createElement(MemoedDisplayCell, Object.assign({}, cellAttributes, attributes, {
29
26
  cellRef: cellRef,
30
- isTruncated: isTruncated,
31
- key: `${cell.id}_${isHovered}`
27
+ isTruncated: isTruncated
32
28
  }), content);
33
29
  }
34
30
  const MemoedDisplayCell = /*#__PURE__*/React__default.memo(function MemoedDisplayCell(props) {
@@ -1 +1 @@
1
- {"version":3,"file":"DisplayCell.js","sources":["../../../../../../../../../../../../src/primitives/Table/Core/components/Columns/Cell/BuiltIns/DisplayCell.tsx"],"sourcesContent":["import React from 'react';\nimport { ColumnMeta as ReactTableColumnMeta, flexRender } from '@tanstack/react-table';\nimport { getCellAttributes } from '../util';\nimport { TableCellRendererProps } from '../../../../types';\nimport { RowContext } from '../../../Row/RowContext';\nimport { isInternalColumn } from '../../../../../useTableManager/util/columns';\n\nexport function DisplayCell<TType = unknown>(props: TableCellRendererProps<TType>) {\n const { cell, cellRef, index, isHighlighted, ...cellAttributes } = props;\n const { isHovered } = React.useContext(RowContext);\n const columnMeta = cell.column.columnDef.meta as ReactTableColumnMeta<TType, unknown>;\n const attributes = getCellAttributes(cell, index, isHighlighted);\n const isTruncated = !!columnMeta.enableTruncate;\n let content;\n\n if (isInternalColumn(cell.column.id)) {\n content = flexRender(cell.column.columnDef.cell, cell.getContext());\n } else {\n content = columnMeta.renderer?.(cell.getValue<TType>(), cell.row.original) ?? cell.getValue() ?? null;\n }\n\n return (\n <MemoedDisplayCell\n {...cellAttributes}\n {...attributes}\n cellRef={cellRef}\n isTruncated={isTruncated}\n key={`${cell.id}_${isHovered}`}>\n {content}\n </MemoedDisplayCell>\n );\n}\n\ntype MemoedDisplayCellProps = React.TdHTMLAttributes<HTMLTableCellElement> & {\n cellRef: any;\n isTruncated: boolean;\n};\n\nconst MemoedDisplayCell = React.memo(function MemoedDisplayCell(props: MemoedDisplayCellProps) {\n const { cellRef, children, isTruncated, ...cellAttributes } = props;\n\n return (\n <td {...cellAttributes} ref={cellRef}>\n {isTruncated ? <span className=\"truncate print:overflow-visible print:whitespace-normal\">{children}</span> : children}\n </td>\n );\n});\n"],"names":["DisplayCell","props","cell","cellRef","index","isHighlighted","cellAttributes","isHovered","React","useContext","RowContext","columnMeta","column","columnDef","meta","attributes","getCellAttributes","isTruncated","enableTruncate","content","isInternalColumn","id","flexRender","getContext","_ref","_columnMeta$renderer","_columnMeta$renderer2","renderer","call","getValue","row","original","MemoedDisplayCell","key","memo","children","ref","className"],"mappings":";;;;;;SAOgBA,WAAWA,CAAkBC,KAAoC;EAC7E,MAAM;IAAEC,IAAI;IAAEC,OAAO;IAAEC,KAAK;IAAEC,aAAa;IAAE,GAAGC;GAAgB,GAAGL,KAAK;EACxE,MAAM;IAAEM;GAAW,GAAGC,cAAK,CAACC,UAAU,CAACC,UAAU,CAAC;EAClD,MAAMC,UAAU,GAAGT,IAAI,CAACU,MAAM,CAACC,SAAS,CAACC,IAA4C;EACrF,MAAMC,UAAU,GAAGC,iBAAiB,CAACd,IAAI,EAAEE,KAAK,EAAEC,aAAa,CAAC;EAChE,MAAMY,WAAW,GAAG,CAAC,CAACN,UAAU,CAACO,cAAc;EAC/C,IAAIC,OAAO;EAEX,IAAIC,gBAAgB,CAAClB,IAAI,CAACU,MAAM,CAACS,EAAE,CAAC,EAAE;IAClCF,OAAO,GAAGG,UAAU,CAACpB,IAAI,CAACU,MAAM,CAACC,SAAS,CAACX,IAAI,EAAEA,IAAI,CAACqB,UAAU,EAAE,CAAC;GACtE,MAAM;IAAA,IAAAC,IAAA,EAAAC,oBAAA,EAAAC,qBAAA;IACHP,OAAO,IAAAK,IAAA,IAAAC,oBAAA,IAAAC,qBAAA,GAAGf,UAAU,CAACgB,QAAQ,cAAAD,qBAAA,uBAAnBA,qBAAA,CAAAE,IAAA,CAAAjB,UAAU,EAAYT,IAAI,CAAC2B,QAAQ,EAAS,EAAE3B,IAAI,CAAC4B,GAAG,CAACC,QAAQ,CAAC,cAAAN,oBAAA,cAAAA,oBAAA,GAAIvB,IAAI,CAAC2B,QAAQ,EAAE,cAAAL,IAAA,cAAAA,IAAA,GAAI,IAAI;;EAGzG,oBACIhB,6BAACwB,iBAAiB,oBACV1B,cAAc,EACdS,UAAU;IACdZ,OAAO,EAAEA,OAAO;IAChBc,WAAW,EAAEA,WAAW;IACxBgB,GAAG,KAAK/B,IAAI,CAACmB,MAAMd;MAClBY,OAAO,CACQ;AAE5B;AAOA,MAAMa,iBAAiB,gBAAGxB,cAAK,CAAC0B,IAAI,CAAC,SAASF,iBAAiBA,CAAC/B,KAA6B;EACzF,MAAM;IAAEE,OAAO;IAAEgC,QAAQ;IAAElB,WAAW;IAAE,GAAGX;GAAgB,GAAGL,KAAK;EAEnE,oBACIO,qDAAQF,cAAc;IAAE8B,GAAG,EAAEjC;MACxBc,WAAW,gBAAGT;IAAM6B,SAAS,EAAC;KAA2DF,QAAQ,CAAQ,GAAGA,QAAQ,CACpH;AAEb,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"DisplayCell.js","sources":["../../../../../../../../../../../../src/primitives/Table/Core/components/Columns/Cell/BuiltIns/DisplayCell.tsx"],"sourcesContent":["import React from 'react';\nimport { ColumnMeta as ReactTableColumnMeta, flexRender } from '@tanstack/react-table';\nimport { getCellAttributes } from '../util';\nimport { TableCellRendererProps } from '../../../../types';\nimport { isInternalColumn } from '../../../../../useTableManager/util/columns';\n\nexport function DisplayCell<TType = unknown>(props: TableCellRendererProps<TType>) {\n const { cell, cellRef, index, isHighlighted, ...cellAttributes } = props;\n const columnMeta = cell.column.columnDef.meta as ReactTableColumnMeta<TType, unknown>;\n const attributes = getCellAttributes(cell, index, isHighlighted);\n const isTruncated = !!columnMeta.enableTruncate;\n const value = cell.getValue<TType>();\n\n let content;\n\n if (isInternalColumn(cell.column.id)) {\n content = flexRender(cell.column.columnDef.cell, cell.getContext());\n } else {\n content = columnMeta.renderer?.(value, cell.row.original) ?? value ?? null;\n }\n\n return (\n <MemoedDisplayCell {...cellAttributes} {...attributes} cellRef={cellRef} isTruncated={isTruncated}>\n {content}\n </MemoedDisplayCell>\n );\n}\n\ntype MemoedDisplayCellProps = React.TdHTMLAttributes<HTMLTableCellElement> & {\n cellRef: any;\n isTruncated: boolean;\n};\n\nconst MemoedDisplayCell = React.memo(function MemoedDisplayCell(props: MemoedDisplayCellProps) {\n const { cellRef, children, isTruncated, ...cellAttributes } = props;\n\n return (\n <td {...cellAttributes} ref={cellRef}>\n {isTruncated ? <span className=\"truncate print:overflow-visible print:whitespace-normal\">{children}</span> : children}\n </td>\n );\n});\n"],"names":["DisplayCell","props","cell","cellRef","index","isHighlighted","cellAttributes","columnMeta","column","columnDef","meta","attributes","getCellAttributes","isTruncated","enableTruncate","value","getValue","content","isInternalColumn","id","flexRender","getContext","_ref","_columnMeta$renderer","_columnMeta$renderer2","renderer","call","row","original","React","MemoedDisplayCell","memo","children","ref","className"],"mappings":";;;;;SAMgBA,WAAWA,CAAkBC,KAAoC;EAC7E,MAAM;IAAEC,IAAI;IAAEC,OAAO;IAAEC,KAAK;IAAEC,aAAa;IAAE,GAAGC;GAAgB,GAAGL,KAAK;EACxE,MAAMM,UAAU,GAAGL,IAAI,CAACM,MAAM,CAACC,SAAS,CAACC,IAA4C;EACrF,MAAMC,UAAU,GAAGC,iBAAiB,CAACV,IAAI,EAAEE,KAAK,EAAEC,aAAa,CAAC;EAChE,MAAMQ,WAAW,GAAG,CAAC,CAACN,UAAU,CAACO,cAAc;EAC/C,MAAMC,KAAK,GAAGb,IAAI,CAACc,QAAQ,EAAS;EAEpC,IAAIC,OAAO;EAEX,IAAIC,gBAAgB,CAAChB,IAAI,CAACM,MAAM,CAACW,EAAE,CAAC,EAAE;IAClCF,OAAO,GAAGG,UAAU,CAAClB,IAAI,CAACM,MAAM,CAACC,SAAS,CAACP,IAAI,EAAEA,IAAI,CAACmB,UAAU,EAAE,CAAC;GACtE,MAAM;IAAA,IAAAC,IAAA,EAAAC,oBAAA,EAAAC,qBAAA;IACHP,OAAO,IAAAK,IAAA,IAAAC,oBAAA,IAAAC,qBAAA,GAAGjB,UAAU,CAACkB,QAAQ,cAAAD,qBAAA,uBAAnBA,qBAAA,CAAAE,IAAA,CAAAnB,UAAU,EAAYQ,KAAK,EAAEb,IAAI,CAACyB,GAAG,CAACC,QAAQ,CAAC,cAAAL,oBAAA,cAAAA,oBAAA,GAAIR,KAAK,cAAAO,IAAA,cAAAA,IAAA,GAAI,IAAI;;EAG9E,oBACIO,6BAACC,iBAAiB,oBAAKxB,cAAc,EAAMK,UAAU;IAAER,OAAO,EAAEA,OAAO;IAAEU,WAAW,EAAEA;MACjFI,OAAO,CACQ;AAE5B;AAOA,MAAMa,iBAAiB,gBAAGD,cAAK,CAACE,IAAI,CAAC,SAASD,iBAAiBA,CAAC7B,KAA6B;EACzF,MAAM;IAAEE,OAAO;IAAE6B,QAAQ;IAAEnB,WAAW;IAAE,GAAGP;GAAgB,GAAGL,KAAK;EAEnE,oBACI4B,qDAAQvB,cAAc;IAAE2B,GAAG,EAAE9B;MACxBU,WAAW,gBAAGgB;IAAMK,SAAS,EAAC;KAA2DF,QAAQ,CAAQ,GAAGA,QAAQ,CACpH;AAEb,CAAC,CAAC;;;;"}
@@ -29,7 +29,7 @@ const MemoedFooter = /*#__PURE__*/React__default.memo(function MemoedFooter(prop
29
29
  const style = {};
30
30
  if (isPinned) {
31
31
  // pinned columns should be offset from either the left or right
32
- style[isPinned] = `${footer.column.getStart(isPinned) - 1}px`;
32
+ style[isPinned] = `${footer.column.getStart(isPinned)}px`;
33
33
  }
34
34
  let content;
35
35
  let align;
@@ -1 +1 @@
1
- {"version":3,"file":"Footer.js","sources":["../../../../../../../../../../src/primitives/Table/Core/components/Footer/Footer.tsx"],"sourcesContent":["import React from 'react';\nimport {\n Header as ReactTableHeader,\n ColumnMeta as ReactTableColumnMeta,\n flexRender,\n Table as ReactTable,\n} from '@tanstack/react-table';\nimport { Summary } from './Summary';\n\nexport type FootProps<TType = unknown> = {\n table: ReactTable<TType>;\n};\nexport function Foot<TType = unknown>(props: FootProps<TType>) {\n const nonGroupedHeaders = props.table.getFooterGroups()[0].headers.filter(header => !header.column.getIsGrouped());\n return (\n <tfoot>\n <tr>\n {nonGroupedHeaders.map((header, index) => (\n <Footer key={header.id} header={header} index={index} />\n ))}\n </tr>\n </tfoot>\n );\n}\n\nexport type FooterProps<TType = unknown> = {\n header: ReactTableHeader<TType, unknown>;\n index: number;\n};\nexport function Footer<TType = unknown>(props: FooterProps<TType>) {\n return <MemoedFooter footer={props.header} index={props.index} />;\n}\n\nexport type MemoedFooterProps<TType = unknown> = {\n footer: ReactTableHeader<TType, unknown>;\n index: number;\n};\nconst MemoedFooter = React.memo(function MemoedFooter<TType = unknown>(props: MemoedFooterProps<TType>) {\n const { footer, index } = props;\n const columnMeta = footer.column.columnDef.meta as ReactTableColumnMeta<TType, unknown>;\n\n // getIsPinned returns true for split header groups, even if the split group has no pinned sub headers\n const isHeaderGroup = !!footer.subHeaders?.length;\n const isPinned = isHeaderGroup\n ? footer.subHeaders.find(x => x.column.getIsPinned())?.column.getIsPinned()\n : footer.column.getIsPinned();\n\n const style: React.CSSProperties = {};\n\n if (isPinned) {\n // pinned columns should be offset from either the left or right\n style[isPinned] = `${footer.column.getStart(isPinned) - 1}px`;\n }\n\n let content;\n let align;\n\n if (index === 0) {\n align = 'left';\n content = <Summary table={footer.getContext().table} />;\n } else {\n align = columnMeta.align;\n content = footer.isPlaceholder ? null : flexRender(footer.column.columnDef.footer, footer.getContext());\n }\n\n return (\n <td\n key={footer.id}\n data-cell-align={align}\n data-cell-id={footer.id}\n data-cell-pinned={isPinned ? isPinned : undefined}\n style={style}>\n {content}\n </td>\n );\n}) as <TType = unknown>(props: MemoedFooterProps<TType>) => JSX.Element;\n"],"names":["Foot","props","nonGroupedHeaders","table","getFooterGroups","headers","filter","header","column","getIsGrouped","React","map","index","Footer","key","id","MemoedFooter","footer","memo","columnMeta","columnDef","meta","isHeaderGroup","_footer$subHeaders","subHeaders","length","isPinned","_footer$subHeaders$fi","find","x","getIsPinned","style","getStart","content","align","Summary","getContext","isPlaceholder","flexRender","undefined"],"mappings":";;;;SAYgBA,IAAIA,CAAkBC,KAAuB;EACzD,MAAMC,iBAAiB,GAAGD,KAAK,CAACE,KAAK,CAACC,eAAe,EAAE,CAAC,CAAC,CAAC,CAACC,OAAO,CAACC,MAAM,CAACC,MAAM,IAAI,CAACA,MAAM,CAACC,MAAM,CAACC,YAAY,EAAE,CAAC;EAClH,oBACIC,yDACIA,yCACKR,iBAAiB,CAACS,GAAG,CAAC,CAACJ,MAAM,EAAEK,KAAK,oBACjCF,6BAACG,MAAM;IAACC,GAAG,EAAEP,MAAM,CAACQ,EAAE;IAAER,MAAM,EAAEA,MAAM;IAAEK,KAAK,EAAEA;IAAS,CAC3D,CAAC,CACD,CACD;AAEhB;SAMgBC,MAAMA,CAAkBZ,KAAyB;EAC7D,oBAAOS,6BAACM,YAAY;IAACC,MAAM,EAAEhB,KAAK,CAACM,MAAM;IAAEK,KAAK,EAAEX,KAAK,CAACW;IAAS;AACrE;AAMA,MAAMI,YAAY,gBAAGN,cAAK,CAACQ,IAAI,CAAC,SAASF,YAAYA,CAAkBf,KAA+B;;EAClG,MAAM;IAAEgB,MAAM;IAAEL;GAAO,GAAGX,KAAK;EAC/B,MAAMkB,UAAU,GAAGF,MAAM,CAACT,MAAM,CAACY,SAAS,CAACC,IAA4C;;EAGvF,MAAMC,aAAa,GAAG,CAAC,GAAAC,kBAAA,GAACN,MAAM,CAACO,UAAU,cAAAD,kBAAA,eAAjBA,kBAAA,CAAmBE,MAAM;EACjD,MAAMC,QAAQ,GAAGJ,aAAa,IAAAK,qBAAA,GACxBV,MAAM,CAACO,UAAU,CAACI,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACrB,MAAM,CAACsB,WAAW,EAAE,CAAC,cAAAH,qBAAA,uBAAnDA,qBAAA,CAAqDnB,MAAM,CAACsB,WAAW,EAAE,GACzEb,MAAM,CAACT,MAAM,CAACsB,WAAW,EAAE;EAEjC,MAAMC,KAAK,GAAwB,EAAE;EAErC,IAAIL,QAAQ,EAAE;;IAEVK,KAAK,CAACL,QAAQ,CAAC,MAAMT,MAAM,CAACT,MAAM,CAACwB,QAAQ,CAACN,QAAQ,CAAC,GAAG,KAAK;;EAGjE,IAAIO,OAAO;EACX,IAAIC,KAAK;EAET,IAAItB,KAAK,KAAK,CAAC,EAAE;IACbsB,KAAK,GAAG,MAAM;IACdD,OAAO,gBAAGvB,6BAACyB,OAAO;MAAChC,KAAK,EAAEc,MAAM,CAACmB,UAAU,EAAE,CAACjC;MAAS;GAC1D,MAAM;IACH+B,KAAK,GAAGf,UAAU,CAACe,KAAK;IACxBD,OAAO,GAAGhB,MAAM,CAACoB,aAAa,GAAG,IAAI,GAAGC,UAAU,CAACrB,MAAM,CAACT,MAAM,CAACY,SAAS,CAACH,MAAM,EAAEA,MAAM,CAACmB,UAAU,EAAE,CAAC;;EAG3G,oBACI1B;IACII,GAAG,EAAEG,MAAM,CAACF,EAAE;uBACGmB,KAAK;oBACRjB,MAAM,CAACF,EAAE;wBACLW,QAAQ,GAAGA,QAAQ,GAAGa,SAAS;IACjDR,KAAK,EAAEA;KACNE,OAAO,CACP;AAEb,CAAC,CAAsE;;;;"}
1
+ {"version":3,"file":"Footer.js","sources":["../../../../../../../../../../src/primitives/Table/Core/components/Footer/Footer.tsx"],"sourcesContent":["import React from 'react';\nimport {\n Header as ReactTableHeader,\n ColumnMeta as ReactTableColumnMeta,\n flexRender,\n Table as ReactTable,\n} from '@tanstack/react-table';\nimport { Summary } from './Summary';\n\nexport type FootProps<TType = unknown> = {\n table: ReactTable<TType>;\n};\nexport function Foot<TType = unknown>(props: FootProps<TType>) {\n const nonGroupedHeaders = props.table.getFooterGroups()[0].headers.filter(header => !header.column.getIsGrouped());\n return (\n <tfoot>\n <tr>\n {nonGroupedHeaders.map((header, index) => (\n <Footer key={header.id} header={header} index={index} />\n ))}\n </tr>\n </tfoot>\n );\n}\n\nexport type FooterProps<TType = unknown> = {\n header: ReactTableHeader<TType, unknown>;\n index: number;\n};\nexport function Footer<TType = unknown>(props: FooterProps<TType>) {\n return <MemoedFooter footer={props.header} index={props.index} />;\n}\n\nexport type MemoedFooterProps<TType = unknown> = {\n footer: ReactTableHeader<TType, unknown>;\n index: number;\n};\nconst MemoedFooter = React.memo(function MemoedFooter<TType = unknown>(props: MemoedFooterProps<TType>) {\n const { footer, index } = props;\n const columnMeta = footer.column.columnDef.meta as ReactTableColumnMeta<TType, unknown>;\n\n // getIsPinned returns true for split header groups, even if the split group has no pinned sub headers\n const isHeaderGroup = !!footer.subHeaders?.length;\n const isPinned = isHeaderGroup\n ? footer.subHeaders.find(x => x.column.getIsPinned())?.column.getIsPinned()\n : footer.column.getIsPinned();\n\n const style: React.CSSProperties = {};\n\n if (isPinned) {\n // pinned columns should be offset from either the left or right\n style[isPinned] = `${footer.column.getStart(isPinned)}px`;\n }\n\n let content;\n let align;\n\n if (index === 0) {\n align = 'left';\n content = <Summary table={footer.getContext().table} />;\n } else {\n align = columnMeta.align;\n content = footer.isPlaceholder ? null : flexRender(footer.column.columnDef.footer, footer.getContext());\n }\n\n return (\n <td\n key={footer.id}\n data-cell-align={align}\n data-cell-id={footer.id}\n data-cell-pinned={isPinned ? isPinned : undefined}\n style={style}>\n {content}\n </td>\n );\n}) as <TType = unknown>(props: MemoedFooterProps<TType>) => JSX.Element;\n"],"names":["Foot","props","nonGroupedHeaders","table","getFooterGroups","headers","filter","header","column","getIsGrouped","React","map","index","Footer","key","id","MemoedFooter","footer","memo","columnMeta","columnDef","meta","isHeaderGroup","_footer$subHeaders","subHeaders","length","isPinned","_footer$subHeaders$fi","find","x","getIsPinned","style","getStart","content","align","Summary","getContext","isPlaceholder","flexRender","undefined"],"mappings":";;;;SAYgBA,IAAIA,CAAkBC,KAAuB;EACzD,MAAMC,iBAAiB,GAAGD,KAAK,CAACE,KAAK,CAACC,eAAe,EAAE,CAAC,CAAC,CAAC,CAACC,OAAO,CAACC,MAAM,CAACC,MAAM,IAAI,CAACA,MA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K,GAAG,MAAM;IACdD,OAAO,gBAAGvB,6BAACyB,OAAO;MAAChC,KAAK,EAAEc,MAAM,CAACmB,UAAU,EAAE,CAACjC;MAAS;GAC1D,MAAM;IACH+B,KAAK,GAAGf,UAAU,CAACe,KAAK;IACxBD,OAAO,GAAGhB,MAAM,CAACoB,aAAa,GAAG,IAAI,GAAGC,UAAU,CAACrB,MAAM,CAACT,MAAM,CAACY,SAAS,CAACH,MAAM,EAAEA,MAAM,CAACmB,UAAU,EAAE,CAAC;;EAG3G,oBACI1B;IACII,GAAG,EAAEG,MAAM,CAACF,EAAE;uBACGmB,KAAK;oBACRjB,MAAM,CAACF,EAAE;wBACLW,QAAQ,GAAGA,QAAQ,GAAGa,SAAS;IACjDR,KAAK,EAAEA;KACNE,OAAO,CACP;AAEb,CAAC,CAAsE;;;;"}
@@ -14,11 +14,11 @@ function SkeletonRow(props) {
14
14
  }));
15
15
  }
16
16
  return /*#__PURE__*/React__default.createElement(Skeleton, {
17
- id: row.id,
18
- cells: row.getVisibleCells()
17
+ cellsCount: row.getVisibleCells().length
19
18
  });
20
19
  }
21
20
  function RowWithServerLoading(props) {
21
+ var _table$getState$group, _table$getState;
22
22
  const {
23
23
  index,
24
24
  row,
@@ -40,23 +40,25 @@ function RowWithServerLoading(props) {
40
40
  (_tableMeta$server$loa = (_tableMeta$server = tableMeta.server).loadPage) === null || _tableMeta$server$loa === void 0 ? void 0 : _tableMeta$server$loa.call(_tableMeta$server, pageIndex, table.getState().sorting, table.getState().columnFilters, table.getState().globalFilter);
41
41
  }
42
42
  }, [inView]);
43
+ const groupedCellCount = (_table$getState$group = (_table$getState = table.getState()) === null || _table$getState === void 0 ? void 0 : _table$getState.grouping.length) !== null && _table$getState$group !== void 0 ? _table$getState$group : 0;
44
+ const ungroupedCellCount = row.getVisibleCells().length - groupedCellCount;
43
45
  return /*#__PURE__*/React__default.createElement(Skeleton, {
44
- cells: row.getVisibleCells(),
46
+ cellsCount: ungroupedCellCount,
45
47
  ref: ref
46
48
  });
47
49
  }
48
50
  const Skeleton = /*#__PURE__*/React__default.forwardRef(function Skeleton(props, ref) {
49
51
  const {
50
- cells
52
+ cellsCount
51
53
  } = props;
52
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("tr", {
54
+ return /*#__PURE__*/React__default.createElement("tr", {
53
55
  ref: ref
54
- }, cells.map(cell => ( /*#__PURE__*/React__default.createElement("td", {
55
- key: cell.id
56
+ }, Array(cellsCount).fill(null).map((_, index) => ( /*#__PURE__*/React__default.createElement("td", {
57
+ key: index
56
58
  }, /*#__PURE__*/React__default.createElement("span", {
57
59
  className: "bg-grey-100 text-grey-700 h-4 w-full text-center text-xs"
58
- }))))));
60
+ })))));
59
61
  });
60
62
 
61
- export { RowWithServerLoading, Skeleton, SkeletonRow };
63
+ export { SkeletonRow };
62
64
  //# sourceMappingURL=SkeletonRow.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SkeletonRow.js","sources":["../../../../../../../../../../../src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta, Row as ReactTableRow } from '@tanstack/react-table';\nimport { useInView } from 'react-intersection-observer';\n\nexport type RowProps<TType = unknown> = {\n index: number;\n row: ReactTableRow<TType>;\n table: ReactTable<TType>;\n};\n\nexport function SkeletonRow<TType = unknown>(props: RowProps<TType>) {\n const { index, row, table } = props;\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n\n if (tableMeta.server.isEnabled) {\n return <RowWithServerLoading {...props} index={index} />;\n }\n\n return <Skeleton id={row.id} cells={row.getVisibleCells()} />;\n}\n\nexport function RowWithServerLoading<TType = unknown>(props: RowProps<TType>) {\n const { index, row, table } = props;\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n\n const pageIndex = (Math.floor(index / tableMeta.server.pageSize) * tableMeta.server.pageSize) / tableMeta.server.pageSize;\n\n const { ref, inView } = useInView({\n threshold: 0,\n triggerOnce: true,\n initialInView: pageIndex === 0,\n });\n\n React.useEffect(() => {\n if (inView) {\n tableMeta.server.loadPage?.(\n pageIndex,\n table.getState().sorting,\n table.getState().columnFilters,\n table.getState().globalFilter\n );\n }\n }, [inView]);\n\n return <Skeleton cells={row.getVisibleCells()} ref={ref} />;\n}\n\nexport const Skeleton = React.forwardRef(function Skeleton(props: any, ref: React.Ref<HTMLTableRowElement>) {\n const { cells } = props;\n\n return (\n <>\n <tr ref={ref}>\n {cells.map(cell => (\n <td key={cell.id}>\n <span className=\"bg-grey-100 text-grey-700 h-4 w-full text-center text-xs\" />\n </td>\n ))}\n </tr>\n </>\n );\n});\n"],"names":["SkeletonRow","props","index","row","table","tableMeta","options","meta","server","isEnabled","React","RowWithServerLoading","Skeleton","id","cells","getVisibleCells","pageIndex","Math","floor","pageSize","ref","inView","useInView","threshold","triggerOnce","initialInView","useEffect","_tableMeta$server$loa","_tableMeta$server","loadPage","call","getState","sorting","columnFilters","globalFilter","forwardRef","map","cell","key","className"],"mappings":";;;SAUgBA,WAAWA,CAAkBC,KAAsB;EAC/D,MAAM;IAAEC,KAAK;IAAEC,GAAG;IAAEC;GAAO,GAAGH,KAAK;EACnC,MAAMI,SAAS,GAAGD,KAAK,CAACE,OAAO,CAACC,IAA6B;EAE7D,IAAIF,SAAS,CAACG,MAAM,CAACC,SAAS,EAAE;IAC5B,oBAAOC,6BAACC,oBAAoB,oBAAKV,KAAK;MAAEC,KAAK,EAAEA;OAAS;;EAG5D,oBAAOQ,6BAACE,QAAQ;IAACC,EAAE,EAAEV,GAAG,CAACU,EAAE;IAAEC,KAAK,EAAEX,GAAG,CAACY,eAAe;IAAM;AACjE;SAEgBJ,oBAAoBA,CAAkBV,KAAsB;EACxE,MAAM;IAAEC,KAAK;IAAEC,GAAG;IAAEC;GAAO,GAAGH,KAAK;EACnC,MAAMI,SAAS,GAAGD,KAAK,CAACE,OAAO,CAACC,IAA6B;EAE7D,MAAMS,SAAS,GAAIC,I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/Row/BuiltIns/SkeletonRow.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta, Row as ReactTableRow } from '@tanstack/react-table';\nimport { useInView } from 'react-intersection-observer';\n\nexport type RowProps<TType = unknown> = {\n index: number;\n row: ReactTableRow<TType>;\n table: ReactTable<TType>;\n};\n\nexport function SkeletonRow<TType = unknown>(props: RowProps<TType>) {\n const { index, row, table } = props;\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n\n if (tableMeta.server.isEnabled) {\n return <RowWithServerLoading {...props} index={index} />;\n }\n\n return <Skeleton cellsCount={row.getVisibleCells().length} />;\n}\n\nfunction RowWithServerLoading<TType = unknown>(props: RowProps<TType>) {\n const { index, row, table } = props;\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n\n const pageIndex = (Math.floor(index / tableMeta.server.pageSize) * tableMeta.server.pageSize) / tableMeta.server.pageSize;\n\n const { ref, inView } = useInView({\n threshold: 0,\n triggerOnce: true,\n initialInView: pageIndex === 0,\n });\n\n React.useEffect(() => {\n if (inView) {\n tableMeta.server.loadPage?.(\n pageIndex,\n table.getState().sorting,\n table.getState().columnFilters,\n table.getState().globalFilter\n );\n }\n }, [inView]);\n\n const groupedCellCount = table.getState()?.grouping.length ?? 0;\n const ungroupedCellCount = row.getVisibleCells().length - groupedCellCount;\n\n return <Skeleton cellsCount={ungroupedCellCount} ref={ref} />;\n}\n\nconst Skeleton = React.forwardRef(function Skeleton(props: { cellsCount: number }, ref: React.Ref<HTMLTableRowElement>) {\n const { cellsCount } = props;\n\n return (\n <tr ref={ref}>\n {Array(cellsCount)\n .fill(null)\n .map((_, index) => (\n <td key={index}>\n <span className=\"bg-grey-100 text-grey-700 h-4 w-full text-center text-xs\" />\n </td>\n ))}\n </tr>\n );\n});\n"],"names":["SkeletonRow","props","index","row","table","tableMeta","options","meta","server","isEnabled","React","RowWithServerLoading","Skeleton","cellsCount","getVisibleCells","length","pageIndex","Math","floor","pageSize","ref","inView","useInView","threshold","triggerOnce","initialInView","useEffect","_tableMeta$server$loa","_tableMeta$server","loadPage","call","getState","sorting","columnFilters","globalFilter","groupedCellCount","_table$getState$group","_table$getState","grouping","ungroupedCellCount","forwardRef","Array","fill","map","_","key","className"],"mappings":";;;SAUgBA,WAAWA,CAAkBC,KAAsB;EAC/D,MAAM;IAAEC,KAAK;IAAEC,GAAG;IAAEC;GAAO,GAAGH,KAAK;EACnC,MAAMI,SAAS,GAAGD,KAAK,CAACE,OAAO,CAACC,IAA6B;EAE7D,IAAIF,SAAS,CAACG,MAAM,CAACC,SAAS,EAAE;IAC5B,oBAAOC,6BAACC,oBAAoB,oBAAKV,KAAK;MAAEC,KAAK,EAAEA;OAAS;;EAG5D,oBAAOQ,6BAACE,QAAQ;IAACC,UAAU,EAAEV,GAAG,CAACW,eAAe,EAAE,CAACC;IAAU;AACjE;AAEA,SAASJ,oBAAoBA,CAAkBV,KAAsB;;EACjE,MAAM;IAAEC,KAAK;IAAEC,GAAG;IAAEC;GAAO,GAAGH,KAAK;EACnC,MAAMI,SAAS,GAAGD,KAAK,CAACE,OAAO,CAACC,IAA6B;EAE7D,MAAMS,SAAS,GAAIC,IAAI,CAACC,KAAK,CAAChB,KAAK,GAAGG,SAAS,CAACG,MAAM,CAACW,QAAQ,CAAC,GAAGd,SAAS,CAACG,MAAM,CAACW,QAAQ,GAAId,SAAS,CAACG,MAAM,CAACW,QAAQ;EAEzH,MAAM;IAAEC,GAAG;IAAEC;GAAQ,GAAGC,SAAS,CAAC;IAC9BC,SAAS,EAAE,CAAC;IACZC,WAAW,EAAE,IAAI;IACjBC,aAAa,EAAET,SAAS,KAAK;GAChC,CAAC;EAEFN,cAAK,CAACgB,SAAS,CAAC;IACZ,IAAIL,MAAM,EAAE;MAAA,IAAAM,qBAAA,EAAAC,iBAAA;MACR,CAAAD,qBAAA,IAAAC,iBAAA,GAAAvB,SAAS,CAACG,MAAM,EAACqB,QAAQ,cAAAF,qBAAA,uBAAzBA,qBAAA,CAAAG,IAAA,CAAAF,iBAAA,EACIZ,SAAS,EACTZ,KAAK,CAAC2B,QAAQ,EAAE,CAACC,OAAO,EACxB5B,KAAK,CAAC2B,QAAQ,EAAE,CAACE,aAAa,EAC9B7B,KAAK,CAAC2B,QAAQ,EAAE,CAACG,YAAY,CAChC;;GAER,EAAE,CAACb,MAAM,CAAC,CAAC;EAEZ,MAAMc,gBAAgB,IAAAC,qBAAA,IAAAC,eAAA,GAAGjC,KAAK,CAAC2B,QAAQ,EAAE,cAAAM,eAAA,uBAAhBA,eAAA,CAAkBC,QAAQ,CAACvB,MAAM,cAAAqB,qBAAA,cAAAA,qBAAA,GAAI,CAAC;EAC/D,MAAMG,kBAAkB,GAAGpC,GAAG,CAACW,eAAe,EAAE,CAACC,MAAM,GAAGoB,gBAAgB;EAE1E,oBAAOzB,6BAACE,QAAQ;IAACC,UAAU,EAAE0B,kBAAkB;IAAEnB,GAAG,EAAEA;IAAO;AACjE;AAEA,MAAMR,QAAQ,gBAAGF,cAAK,CAAC8B,UAAU,CAAC,SAAS5B,QAAQA,CAACX,KAA6B,EAAEmB,GAAmC;EAClH,MAAM;IAAEP;GAAY,GAAGZ,KAAK;EAE5B,oBACIS;IAAIU,GAAG,EAAEA;KACJqB,KAAK,CAAC5B,UAAU,CAAC,CACb6B,IAAI,CAAC,IAAI,CAAC,CACVC,GAAG,CAAC,CAACC,CAAC,EAAE1C,KAAK,oBACVQ;IAAImC,GAAG,EAAE3C;kBACLQ;IAAMoC,SAAS,EAAC;IAA6D,CAC5E,CACR,CAAC,CACL;AAEb,CAAC,CAAC;;;;"}
@@ -4,7 +4,7 @@ import { HEADER_ROW_HEIGHT_ESTIMATE, ROW_HEIGHT_ESTIMATES } from '../util/rows.j
4
4
  import { Row } from '../components/Row/Row.js';
5
5
 
6
6
  const TABLE_SCROLL_PADDING_BOTTOM = 36;
7
- const TABLE_PADDING_BOTTOM = 120;
7
+ const TABLE_PADDING_BOTTOM = 0;
8
8
  function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex) {
9
9
  var _table$getState$group, _ref, _virtualItems$padding, _virtualItems$padding2, _ref2, _virtualItems;
10
10
  const tableMeta = table.options.meta;
@@ -77,7 +77,7 @@ function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex) {
77
77
  let content = null;
78
78
  if (rows.length) {
79
79
  style = {
80
- height: `${virtualiser.getTotalSize()}px`,
80
+ height: `${virtualiser.getTotalSize() - HEADER_OFFSET_TOTAL}px`,
81
81
  paddingBottom,
82
82
  paddingTop
83
83
  };
@@ -156,7 +156,7 @@ function useRowGroupVirtualisation(table) {
156
156
  });
157
157
  }
158
158
  return indexes;
159
- }, []);
159
+ }, [rows]);
160
160
  // this is taken from the react-virtual docs/examples
161
161
  const rangeExtractor = React__default.useCallback(range => {
162
162
  var _reverse$find;
@@ -1 +1 @@
1
- {"version":3,"file":"useTableRenderer.js","sources":["../../../../../../../../../src/primitives/Table/Core/features/useTableRenderer.tsx"],"sourcesContent":["import React, { CSSProperties } from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport {\n useVirtualizer,\n defaultRangeExtractor,\n ScrollToOptions as ReactVirtualScrollToOptions,\n VirtualItem,\n} from '@tanstack/react-virtual';\nimport { HEADER_ROW_HEIGHT_ESTIMATE, ROW_HEIGHT_ESTIMATES } from '../util/rows';\nimport { Row } from '../components/Row/Row';\nimport { useTableRenderers } from '../types';\nimport { TableRef } from '../../types';\n\nconst TABLE_SCROLL_PADDING_BOTTOM = 36;\nconst TABLE_PADDING_BOTTOM = 120;\n\nexport function useTableRenderer<TType = unknown>(\n renderers: useTableRenderers<TType>,\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n defaultRowActiveIndex?: number | undefined\n) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const rows = table.getRowModel().rows;\n const HEADER_OFFSET_TOTAL = HEADER_ROW_HEIGHT_ESTIMATE * table.getHeaderGroups().length;\n const isTableGrouped = !!table.getState().grouping?.length;\n\n // expanded rows\n const { createRowMeasurer, estimateSize } = useRowHeightVirtualisation<TType>(table);\n\n // row groups\n const rangeExtractor = useRowGroupVirtualisation<TType>(table);\n\n const virtualiser = useVirtualizer({\n count: rows.length,\n estimateSize,\n getScrollElement: () => tableRef.current,\n overscan: tableMeta.printing.isPrinting ? rows.length : undefined,\n rangeExtractor,\n scrollPaddingStart: isTableGrouped ? HEADER_ROW_HEIGHT_ESTIMATE : undefined,\n scrollPaddingEnd: HEADER_OFFSET_TOTAL + TABLE_SCROLL_PADDING_BOTTOM,\n paddingEnd: TABLE_PADDING_BOTTOM,\n });\n\n const virtualItems = virtualiser.getVirtualItems();\n\n const scrollToIndex = React.useCallback(\n (index: number, options: ReactVirtualScrollToOptions = { align: 'auto', behavior: 'smooth' }) => {\n const notSmooth: ReactVirtualScrollToOptions = { ...options, behavior: 'auto' };\n\n if (tableRef.current) {\n if (index === 0) {\n virtualiser.scrollToOffset(0, notSmooth);\n } else if (index >= virtualItems.length - 1) {\n // scrolling to the last row isn't easy when rows have dynamic height\n // because you don't know all the heights until they render...\n // so when you skip to the last you don't know if \"the end\" is actually the end\n virtualiser.scrollToIndex(index, notSmooth);\n\n // https://github.com/TanStack/virtual/issues/216\n setTimeout(() => {\n virtualiser.scrollToIndex(index, notSmooth);\n\n setTimeout(() => {\n virtualiser.scrollToIndex(index, notSmooth);\n }, 150);\n }, 150);\n } else {\n virtualiser.scrollToIndex(index, options);\n }\n }\n },\n [virtualItems.length, tableRef.current]\n );\n\n // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0\n const paddingStartIndex = isTableGrouped && rows.length > 1 ? 1 : 0;\n\n // styling for offsetting rows - this \"is\" the virtualisation\n const [paddingTop, paddingBottom] =\n virtualItems.length > 0\n ? [\n // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0\n Math.max(\n 0,\n virtualItems[paddingStartIndex]?.start -\n virtualiser.options.scrollMargin -\n virtualItems[paddingStartIndex]?.size ?? 0\n ),\n Math.max(0, virtualiser.getTotalSize() - virtualItems[virtualItems.length - 1]?.end ?? 0),\n ]\n : [0, 0];\n\n // ensure default active rows are scrolled to\n React.useEffect(() => {\n if (defaultRowActiveIndex) {\n scrollToIndex(defaultRowActiveIndex, { align: 'center', behavior: 'auto' });\n }\n }, []);\n\n // rendered output\n let style: CSSProperties = {};\n let content: (JSX.Element | null)[] | null = null;\n\n if (rows.length) {\n style = {\n height: `${virtualiser.getTotalSize()}px`,\n paddingBottom,\n paddingTop,\n };\n content = virtualItems.map(virtualRow => {\n // there appears to be a react-virtual bug where it inserts a single `undefined` item at the end of the row, which crashes here\n if (!virtualRow) {\n return null;\n }\n\n const row = rows[virtualRow.index];\n const measureRow = createRowMeasurer(virtualiser.resizeItem, virtualRow);\n return (\n <Row\n key={row.id}\n row={row}\n index={virtualRow.index}\n table={table}\n measureRow={measureRow}\n renderer={renderers.row}\n cellRenderer={renderers.cell}\n />\n );\n });\n }\n\n return {\n rows: content,\n style,\n scrollToIndex,\n };\n}\n\n// support varying row heights - variable row heights, row expansion\nfunction useRowHeightVirtualisation<TType = unknown>(table: ReactTable<TType>) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const rows = table.getRowModel().rows;\n const expandedState = table.getState().expanded;\n\n const [expandedRowHeightsCache, setExpandedRowHeightsCache] = React.useState<Record<number, number>>({});\n\n // look at all registered expanded row heights and use them to form a more accurate average size\n // it might be worth considering if taking the max, or an upper bound, would be better\n const averageExpandedRowHeight = React.useMemo(() => {\n const values: number[] = Object.values(expandedRowHeightsCache);\n return values.length ? values.reduce((a, b) => a + b, 0) / values.length : 0;\n }, [expandedRowHeightsCache]);\n\n // row heights\n const estimateSize = React.useCallback(\n (index: number) => {\n const rowHeight = tableMeta.rowHeight.height\n ? ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height]\n : ROW_HEIGHT_ESTIMATES.medium;\n\n if (expandedState === true || rows[index]?.getIsExpanded?.()) {\n return rowHeight + averageExpandedRowHeight;\n }\n\n return rowHeight;\n },\n [tableMeta.rowHeight.height, averageExpandedRowHeight, expandedState]\n );\n\n const createRowMeasurer = React.useCallback(\n (resizeItem: (item: VirtualItem, size: number) => void, virtualRow: VirtualItem) =>\n (rowHeight: number, expansionHeight?: number) => {\n // register the expansion height so that it can be used to determine an average\n if (expansionHeight) {\n setExpandedRowHeightsCache(cache => ({ ...cache, [virtualRow.index]: expansionHeight }));\n }\n\n // update the whole row's size to include the expanded height\n resizeItem(virtualRow, rowHeight + (expansionHeight ?? 0));\n },\n []\n );\n\n return { estimateSize, createRowMeasurer };\n}\n\n// support virtualised row groups (where the row group headers are sticky)\nfunction useRowGroupVirtualisation<TType = unknown>(table: ReactTable<TType>) {\n const rows = table.getRowModel().rows;\n const isTableGrouped = !!table.getState().grouping.length;\n\n const rowGroupIndexes = React.useMemo(() => {\n const indexes: number[] = [];\n\n if (isTableGrouped) {\n rows.forEach((row, index) => {\n if (row.getIsGrouped()) {\n indexes.push(index);\n }\n });\n }\n\n return indexes;\n }, []);\n\n // this is taken from the react-virtual docs/examples\n const rangeExtractor = React.useCallback(\n range => {\n const activeRowGroupIndex =\n [...rowGroupIndexes].reverse().find(index => range.startIndex >= index) ?? rowGroupIndexes[0];\n\n const next = new Set([activeRowGroupIndex, ...defaultRangeExtractor(range)]);\n return [...next].sort((a, b) => a - b);\n },\n [rowGroupIndexes]\n );\n\n return isTableGrouped ? rangeExtractor : undefined;\n}\n"],"names":["TABLE_SCROLL_PADDING_BOTTOM","TABLE_PADDING_BOTTOM","useTableRenderer","renderers","table","tableRef","defaultRowActiveIndex","tableMeta","options","meta","rows","getRowModel","HEADER_OFFSET_TOTAL","HEADER_ROW_HEIGHT_ESTIMATE","getHeaderGroups","length","isTableGrouped","_table$getState$group","getState","grouping","createRowMeasurer","estimateSize","useRowHeightVirtualisation","rangeExtractor","useRowGroupVirtualisation","virtualiser","useVirtualizer","count","getScrollElement","current","overscan","printing","isPrinting","undefined","scrollPaddingStart","scrollPaddingEnd","paddingEnd","virtualItems","getVirtualItems","scrollToIndex","React","useCallback","index","align","behavior","notSmooth","scrollToOffset","setTimeout","paddingStartIndex","paddingTop","paddingBottom","Math","max","_ref","_virtualItems$padding","start","scrollMargin","_virtualItems$padding2","size","_ref2","getTotalSize","_virtualItems","end","useEffect","style","content","height","map","virtualRow","row","measureRow","resizeItem","Row","key","id","renderer","cellRenderer","cell","expandedState","expanded","expandedRowHeightsCache","setExpandedRowHeightsCache","useState","averageExpandedRowHeight","useMemo","values","Object","reduce","a","b","rowHeight","ROW_HEIGHT_ESTIMATES","medium","_rows$index","_rows$index$getIsExpa","getIsExpanded","call","expansionHeight","cache","rowGroupIndexes","indexes","forEach","getIsGrouped","push","range","activeRowGroupIndex","_reverse$find","reverse","find","startIndex","next","Set","defaultRangeExtractor","sort"],"mappings":";;;;;AAaA,MAAMA,2BAA2B,GAAG,EAAE;AACtC,MAAMC,oBAAoB,GAAG,GAAG;SAEhBC,gBAAgBA,CAC5BC,SAAmC,EACnCC,KAAwB,EACxBC,QAAmC,EACnCC,qBAA0C;;EAE1C,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,IAAI,GAAGN,KAAK,CAACO,WAAW,EAAE,CAACD,IAAI;EACrC,MAAME,mBAAmB,GAAGC,0BAA0B,GAAGT,KAAK,CAACU,eAAe,EAAE,CAACC,MAAM;EACvF,MAAMC,cAAc,GAAG,CAAC,GAAAC,qBAAA,GAACb,KAAK,CAACc,QAAQ,EAAE,CAACC,QAAQ,cAAAF,qBAAA,eAAzBA,qBAAA,CAA2BF,MAAM;;EAG1D,MAAM;IAAEK,iBAAiB;IAAEC;GAAc,GAAGC,0BAA0B,CAAQlB,KAAK,CAAC;;EAGpF,MAAMmB,cAAc,GAAGC,yBAAyB,CAAQpB,KAAK,CAAC;EAE9D,MAAMqB,WAAW,GAAGC,cAAc,CAAC;IAC/BC,KAAK,EAAEjB,IAAI,CAACK,MAAM;IAClBM,YAAY;IAC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AMgB,OAAO,GAAa,EAAE;IAE5B,IAAIpF,cAAc,EAAE;MAChBN,IAAI,CAAC2F,OAAO,CAAC,CAAChC,GAAG,EAAE3B,KAAK;QACpB,IAAI2B,GAAG,CAACiC,YAAY,EAAE,EAAE;UACpBF,OAAO,CAACG,IAAI,CAAC7D,KAAK,CAAC;;OAE1B,CAAC;;IAGN,OAAO0D,OAAO;GACjB,EAAE,EAAE,CAAC;;EAGN,MAAM7E,cAAc,GAAGiB,cAAK,CAACC,WAAW,CACpC+D,KAAK;;IACD,MAAMC,mBAAmB,IAAAC,aAAA,GACrB,CAAC,GAAGP,eAAe,CAAC,CAACQ,OAAO,EAAE,CAACC,IAAI,CAAClE,KAAK,IAAI8D,KAAK,CAACK,UAAU,IAAInE,KAAK,CAAC,cAAAgE,aAAA,cAAAA,aAAA,GAAIP,eAAe,CAAC,CAAC,CAAC;IAEjG,MAAMW,IAAI,GAAG,IAAIC,GAAG,CAAC,CAACN,mBAAmB,EAAE,GAAGO,qBAAqB,CAACR,KAAK,CAAC,CAAC,CAAC;IAC5E,OAAO,CAAC,GAAGM,IAAI,CAAC,CAACG,IAAI,CAAC,CAACzB,CAAC,EAAEC,CAAC,KAAKD,CAAC,GAAGC,CAAC,CAAC;GACzC,EACD,CAACU,eAAe,CAAC,CACpB;EAED,OAAOnF,cAAc,GAAGO,cAAc,GAAGU,SAAS;AACtD;;;;"}
1
+ {"version":3,"file":"useTableRenderer.js","sources":["../../../../../../../../../src/primitives/Table/Core/features/useTableRenderer.tsx"],"sourcesContent":["import React, { CSSProperties } from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport {\n useVirtualizer,\n defaultRangeExtractor,\n ScrollToOptions as ReactVirtualScrollToOptions,\n VirtualItem,\n} from '@tanstack/react-virtual';\nimport { HEADER_ROW_HEIGHT_ESTIMATE, ROW_HEIGHT_ESTIMATES } from '../util/rows';\nimport { Row } from '../components/Row/Row';\nimport { useTableRenderers } from '../types';\nimport { TableRef } from '../../types';\n\nconst TABLE_SCROLL_PADDING_BOTTOM = 36;\nconst TABLE_PADDING_BOTTOM = 0;\n\nexport function useTableRenderer<TType = unknown>(\n renderers: useTableRenderers<TType>,\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n defaultRowActiveIndex?: number | undefined\n) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const rows = table.getRowModel().rows;\n const HEADER_OFFSET_TOTAL = HEADER_ROW_HEIGHT_ESTIMATE * table.getHeaderGroups().length;\n const isTableGrouped = !!table.getState().grouping?.length;\n\n // expanded rows\n const { createRowMeasurer, estimateSize } = useRowHeightVirtualisation<TType>(table);\n\n // row groups\n const rangeExtractor = useRowGroupVirtualisation<TType>(table);\n\n const virtualiser = useVirtualizer({\n count: rows.length,\n estimateSize,\n getScrollElement: () => tableRef.current,\n overscan: tableMeta.printing.isPrinting ? rows.length : undefined,\n rangeExtractor,\n scrollPaddingStart: isTableGrouped ? HEADER_ROW_HEIGHT_ESTIMATE : undefined,\n scrollPaddingEnd: HEADER_OFFSET_TOTAL + TABLE_SCROLL_PADDING_BOTTOM,\n paddingEnd: TABLE_PADDING_BOTTOM,\n });\n\n const virtualItems = virtualiser.getVirtualItems();\n\n const scrollToIndex = React.useCallback(\n (index: number, options: ReactVirtualScrollToOptions = { align: 'auto', behavior: 'smooth' }) => {\n const notSmooth: ReactVirtualScrollToOptions = { ...options, behavior: 'auto' };\n\n if (tableRef.current) {\n if (index === 0) {\n virtualiser.scrollToOffset(0, notSmooth);\n } else if (index >= virtualItems.length - 1) {\n // scrolling to the last row isn't easy when rows have dynamic height\n // because you don't know all the heights until they render...\n // so when you skip to the last you don't know if \"the end\" is actually the end\n virtualiser.scrollToIndex(index, notSmooth);\n\n // https://github.com/TanStack/virtual/issues/216\n setTimeout(() => {\n virtualiser.scrollToIndex(index, notSmooth);\n\n setTimeout(() => {\n virtualiser.scrollToIndex(index, notSmooth);\n }, 150);\n }, 150);\n } else {\n virtualiser.scrollToIndex(index, options);\n }\n }\n },\n [virtualItems.length, tableRef.current]\n );\n\n // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0\n const paddingStartIndex = isTableGrouped && rows.length > 1 ? 1 : 0;\n\n // styling for offsetting rows - this \"is\" the virtualisation\n const [paddingTop, paddingBottom] =\n virtualItems.length > 0\n ? [\n // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0\n Math.max(\n 0,\n virtualItems[paddingStartIndex]?.start -\n virtualiser.options.scrollMargin -\n virtualItems[paddingStartIndex]?.size ?? 0\n ),\n Math.max(0, virtualiser.getTotalSize() - virtualItems[virtualItems.length - 1]?.end ?? 0),\n ]\n : [0, 0];\n\n // ensure default active rows are scrolled to\n React.useEffect(() => {\n if (defaultRowActiveIndex) {\n scrollToIndex(defaultRowActiveIndex, { align: 'center', behavior: 'auto' });\n }\n }, []);\n\n // rendered output\n let style: CSSProperties = {};\n let content: (JSX.Element | null)[] | null = null;\n\n if (rows.length) {\n style = {\n height: `${virtualiser.getTotalSize() - HEADER_OFFSET_TOTAL}px`,\n paddingBottom,\n paddingTop,\n };\n content = virtualItems.map(virtualRow => {\n // there appears to be a react-virtual bug where it inserts a single `undefined` item at the end of the row, which crashes here\n if (!virtualRow) {\n return null;\n }\n\n const row = rows[virtualRow.index];\n const measureRow = createRowMeasurer(virtualiser.resizeItem, virtualRow);\n return (\n <Row\n key={row.id}\n row={row}\n index={virtualRow.index}\n table={table}\n measureRow={measureRow}\n renderer={renderers.row}\n cellRenderer={renderers.cell}\n />\n );\n });\n }\n\n return {\n rows: content,\n style,\n scrollToIndex,\n };\n}\n\n// support varying row heights - variable row heights, row expansion\nfunction useRowHeightVirtualisation<TType = unknown>(table: ReactTable<TType>) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const rows = table.getRowModel().rows;\n const expandedState = table.getState().expanded;\n\n const [expandedRowHeightsCache, setExpandedRowHeightsCache] = React.useState<Record<number, number>>({});\n\n // look at all registered expanded row heights and use them to form a more accurate average size\n // it might be worth considering if taking the max, or an upper bound, would be better\n const averageExpandedRowHeight = React.useMemo(() => {\n const values: number[] = Object.values(expandedRowHeightsCache);\n return values.length ? values.reduce((a, b) => a + b, 0) / values.length : 0;\n }, [expandedRowHeightsCache]);\n\n // row heights\n const estimateSize = React.useCallback(\n (index: number) => {\n const rowHeight = tableMeta.rowHeight.height\n ? ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height]\n : ROW_HEIGHT_ESTIMATES.medium;\n\n if (expandedState === true || rows[index]?.getIsExpanded?.()) {\n return rowHeight + averageExpandedRowHeight;\n }\n\n return rowHeight;\n },\n [tableMeta.rowHeight.height, averageExpandedRowHeight, expandedState]\n );\n\n const createRowMeasurer = React.useCallback(\n (resizeItem: (item: VirtualItem, size: number) => void, virtualRow: VirtualItem) =>\n (rowHeight: number, expansionHeight?: number) => {\n // register the expansion height so that it can be used to determine an average\n if (expansionHeight) {\n setExpandedRowHeightsCache(cache => ({ ...cache, [virtualRow.index]: expansionHeight }));\n }\n\n // update the whole row's size to include the expanded height\n resizeItem(virtualRow, rowHeight + (expansionHeight ?? 0));\n },\n []\n );\n\n return { estimateSize, createRowMeasurer };\n}\n\n// support virtualised row groups (where the row group headers are sticky)\nfunction useRowGroupVirtualisation<TType = unknown>(table: ReactTable<TType>) {\n const rows = table.getRowModel().rows;\n const isTableGrouped = !!table.getState().grouping.length;\n\n const rowGroupIndexes = React.useMemo(() => {\n const indexes: number[] = [];\n\n if (isTableGrouped) {\n rows.forEach((row, index) => {\n if (row.getIsGrouped()) {\n indexes.push(index);\n }\n });\n }\n\n return indexes;\n }, [rows]);\n\n // this is taken from the react-virtual docs/examples\n const rangeExtractor = React.useCallback(\n range => {\n const activeRowGroupIndex =\n [...rowGroupIndexes].reverse().find(index => range.startIndex >= index) ?? rowGroupIndexes[0];\n\n const next = new Set([activeRowGroupIndex, ...defaultRangeExtractor(range)]);\n return [...next].sort((a, b) => a - b);\n },\n [rowGroupIndexes]\n );\n\n return isTableGrouped ? rangeExtractor : undefined;\n}\n"],"names":["TABLE_SCROLL_PADDING_BOTTOM","TABLE_PADDING_BOTTOM","useTableRenderer","renderers","table","tableRef","defaultRowActiveIndex","tableMeta","options","meta","rows","getRowModel","HEADER_OFFSET_TOTAL","HEADER_ROW_HEIGHT_ESTIMATE","getHeaderGroups","length","isTableGrouped","_table$getState$group","getState","grouping","createRowMeasurer","estimateSize","useRowHeightVirtualisation","rangeExtractor","useRowGroupVirtualisation","virtualiser","useVirtualizer","count","getScrollElement","current","overscan","printing","isPrinting","undefined","scrollPaddingStart","scrollPaddingEnd","paddingEnd","virtualItems","getVirtualItems","scrollToIndex","React","useCallback","index","align","behavior","notSmooth","scrollToOffset","setTimeout","paddingStartIndex","paddingTop","paddingBottom","Math","max","_ref","_virtualItems$padding","start","scrollMargin","_virtualItems$padding2","size","_ref2","getTotalSize","_virtualItems","end","useEffect","style","content","height","map","virtualRow","row","measureRow","resizeItem","Row","key","id","renderer","cellRenderer","cell","expandedState","expanded","expandedRowHeightsCache","setExpandedRowHeightsCache","useState","averageExpandedRowHeight","useMemo","values","Object","reduce","a","b","rowHeight","ROW_HEIGHT_ESTIMATES","medium","_rows$index","_rows$index$getIsExpa","getIsExpanded","call","expansionHeight","cache","rowGroupIndexes","indexes","forEach","getIsGrouped","push","range","activeRowGroupIndex","_reverse$find","reverse","find","startIndex","next","Set","defaultRangeExtractor","sort"],"mappings":";;;;;AAaA,MAAMA,2BAA2B,GAAG,EAAE;AACtC,MAAMC,oBAAoB,GAAG,CAAC;SAEdC,gBAAgBA,CAC5BC,SAAmC,EACnCC,KAAwB,EACxBC,QAAmC,EACnCC,qBAA0C;;EAE1C,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,IAAI,GAAGN,KAAK,CAACO,WAAW,EAAE,CAACD,IAAI;EACrC,MAAME,mBAAmB,GAAGC,0BAA0B,GAAGT,KAAK,CAACU,eAAe,EAAE,CAACC,MAAM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GO,cAAc,GAAGU,SAAS;AACtD;;;;"}
@@ -22,7 +22,8 @@ function useTableStyleColumnFreezing(tableId, table) {
22
22
  // add right border, hide the header seperator and add shadow when scrolled
23
23
  // we have to be specific so that nested tables don't inherit the same css
24
24
  styles.push(`table[data-taco^='table']#${tableId} > thead > tr > th:nth-child(${index + 1}),
25
- table[data-taco^='table']#${tableId} > tbody > tr > td:nth-child(${index + 1}) {
25
+ table[data-taco^='table']#${tableId} > tbody > tr > td:nth-child(${index + 1}),
26
+ table[data-taco^='table']#${tableId} > tfoot > tr > td:nth-child(${index + 1}):not([data-cell-id^="__"]) {
26
27
  border-right-width: 1px;
27
28
  }\ntable[data-taco^='table']#${tableId} > thead > tr > th:nth-child(${index + 1})[data-cell-id^="__"],
28
29
  table[data-taco^='table']#${tableId} > tbody > tr > td:nth-child(${index + 1})[data-cell-id^="__"] {
@@ -30,7 +31,8 @@ function useTableStyleColumnFreezing(tableId, table) {
30
31
  }\ntable[data-taco^='table']#${tableId} > thead > tr > th:nth-child(${index + 1}):after {
31
32
  content: none;
32
33
  }\ntable[data-taco^='table'][data-table-horizontally-scrolled="true"]#${tableId} > thead > tr > th:nth-child(${index + 1}),
33
- table[data-taco^='table'][data-table-horizontally-scrolled="true"]#${tableId} > tbody > tr > td:nth-child(${index + 1}) {
34
+ table[data-taco^='table'][data-table-horizontally-scrolled="true"]#${tableId} > tbody > tr > td:nth-child(${index + 1}),
35
+ table[data-taco^='table'][data-table-horizontally-scrolled="true"]#${tableId} > tfoot > tr > td:nth-child(${index + 1}) {
34
36
  border-right-color: rgb(221, 221, 221);
35
37
  box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), 6px 0px 6px rgb(0 0 0/8%);
36
38
  }`);
@@ -1 +1 @@
1
- {"version":3,"file":"useTableStyleColumnFreezing.js","sources":["../../../../../../../../../src/primitives/Table/Core/features/useTableStyleColumnFreezing.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable } from '@tanstack/react-table';\n\nexport function useTableStyleColumnFreezing<TType = unknown>(tableId: string, table: ReactTable<TType>) {\n const { columnPinning, columnSizing } = table.getState();\n\n const stylesheet = React.useMemo(() => {\n const styles: string[] = [];\n\n // might be a better way to get this information, but it wasn't obvious\n const all = table\n .getFlatHeaders()\n .filter(column => !column.subHeaders.length)\n .map(x => x.id);\n const left = table.getLeftFlatHeaders().filter(column => !column.subHeaders.length);\n const right = table.getRightFlatHeaders().filter(column => !column.subHeaders.length);\n\n if (left.length) {\n left.forEach(cell => {\n styles.push(`table[data-taco^='table']#${tableId} [data-cell-id=\"${cell.column.id}\"] {\n left: ${cell.column.getStart(cell.column.getIsPinned())}px;\n }`);\n });\n const leftIds = left.map(x => x.id);\n const index = all.indexOf(leftIds[leftIds.length - 1]);\n\n // add right border, hide the header seperator and add shadow when scrolled\n // we have to be specific so that nested tables don't inherit the same css\n styles.push(`table[data-taco^='table']#${tableId} > thead > tr > th:nth-child(${index + 1}),\n table[data-taco^='table']#${tableId} > tbody > tr > td:nth-child(${index + 1}) {\n border-right-width: 1px;\n }\\ntable[data-taco^='table']#${tableId} > thead > tr > th:nth-child(${index + 1})[data-cell-id^=\"__\"],\n table[data-taco^='table']#${tableId} > tbody > tr > td:nth-child(${index + 1})[data-cell-id^=\"__\"] {\n border-right-color: transparent;\n }\\ntable[data-taco^='table']#${tableId} > thead > tr > th:nth-child(${index + 1}):after {\n content: none;\n }\\ntable[data-taco^='table'][data-table-horizontally-scrolled=\"true\"]#${tableId} > thead > tr > th:nth-child(${\n index + 1\n }),\n table[data-taco^='table'][data-table-horizontally-scrolled=\"true\"]#${tableId} > tbody > tr > td:nth-child(${\n index + 1\n }) {\n border-right-color: rgb(221, 221, 221);\n box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), 6px 0px 6px rgb(0 0 0/8%);\n }`);\n }\n\n if (right.length) {\n right.forEach(cell => {\n styles.push(`table[data-taco^='table']#${tableId} [data-cell-id=\"${cell.column.id}\"] {\n right: ${cell.column.getStart(cell.column.getIsPinned())}px;\n }`);\n });\n const rightIds = right.map(x => x.id);\n const index = all.indexOf(rightIds[rightIds.length - 1]);\n\n styles.push(`table[data-taco^='table']#${tableId} > thead > tr > th:nth-child(${index + 1}):not([data-cell-id^=\"__\"]),\n table[data-taco^='table']#${tableId} > tbody > tr > td:nth-child(${index + 1}):not([data-cell-id^=\"__\"]) {\n border-left-width: 1px;\n }`);\n }\n\n return styles.join('\\n');\n }, [columnPinning, columnSizing]);\n\n return { stylesheet };\n}\n"],"names":["useTableStyleColumnFreezing","tableId","table","columnPinning","columnSizing","getState","stylesheet","React","useMemo","styles","all","getFlatHeaders","filter","column","subHeaders","length","map","x","id","left","getLeftFlatHeaders","right","getRightFlatHeaders","forEach","cell","push","getStart","getIsPinned","leftIds","index","indexOf","rightIds","join"],"mappings":";;SAGgBA,2BAA2BA,CAAkBC,OAAe,EAAEC,KAAwB;EAClG,MAAM;IAAEC,aAAa;IAAEC;GAAc,GAAGF,KAAK,CAACG,QAAQ,EAAE;EAExD,MAAMC,UAAU,GAAGC,cAAK,CAACC,OAAO,CAAC;IAC7B,MAAMC,MAAM,GAAa,EAAE;;IAG3B,MAAMC,GAAG,GAAGR,KAAK,CACZS,cAAc,EAAE,CAChBC,MAAM,CAACC,MAAM,IAAI,CAACA,MAAM,CAACC,UAAU,CAACC,MAAM,CAAC,CAC3CC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACC,EAAE,CAAC;IACnB,MAAMC,IAAI,GAAGjB,KAAK,CAACkB,kBAAkB,EAAE,CAACR,MAAM,CAACC,MAAM,IAAI,CAACA,MAAM,CAACC,UAAU,CAACC,MAAM,CAAC;IACnF,MAAMM,KAAK,GAAGnB,KAAK,CAACoB,mBAAmB,EAAE,CAACV,MAAM,CAACC,MAAM,IAAI,CAACA,MAAM,CAACC,UAAU,CAACC,MAAM,CAAC;IAErF,IAAII,IAAI,CAACJ,MAAM,EAAE;MACbI,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AAC;;IAGX,OAAOpB,MAAM,CAACuB,IAAI,CAAC,IAAI,CAAC;GAC3B,EAAE,CAAC7B,aAAa,EAAEC,YAAY,CAAC,CAAC;EAEjC,OAAO;IAAEE;GAAY;AACzB;;;;"}
1
+ {"version":3,"file":"useTableStyleColumnFreezing.js","sources":["../../../../../../../../../src/primitives/Table/Core/features/useTableStyleColumnFreezing.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable } from '@tanstack/react-table';\n\nexport function useTableStyleColumnFreezing<TType = unknown>(tableId: string, table: ReactTable<TType>) {\n const { columnPinning, columnSizing } = table.getState();\n\n const stylesheet = React.useMemo(() => {\n const styles: string[] = [];\n\n // might be a better way to get this information, but it wasn't obvious\n const all = table\n .getFlatHeaders()\n .filter(column => !column.subHeaders.length)\n .map(x => x.id);\n const left = table.getLeftFlatHeaders().filter(column => !column.subHeaders.length);\n const right = table.getRightFlatHeaders().filter(column => !column.subHeaders.length);\n\n if (left.length) {\n left.forEach(cell => {\n styles.push(`table[data-taco^='table']#${tableId} [data-cell-id=\"${cell.column.id}\"] {\n left: ${cell.column.getStart(cell.column.getIsPinned())}px;\n }`);\n });\n const leftIds = left.map(x => x.id);\n const index = all.indexOf(leftIds[leftIds.length - 1]);\n\n // add right border, hide the header seperator and add shadow when scrolled\n // we have to be specific so that nested tables don't inherit the same css\n styles.push(`table[data-taco^='table']#${tableId} > thead > tr > th:nth-child(${index + 1}),\n table[data-taco^='table']#${tableId} > tbody > tr > td:nth-child(${index + 1}),\n table[data-taco^='table']#${tableId} > tfoot > tr > td:nth-child(${index + 1}):not([data-cell-id^=\"__\"]) {\n border-right-width: 1px;\n }\\ntable[data-taco^='table']#${tableId} > thead > tr > th:nth-child(${index + 1})[data-cell-id^=\"__\"],\n table[data-taco^='table']#${tableId} > tbody > tr > td:nth-child(${index + 1})[data-cell-id^=\"__\"] {\n border-right-color: transparent;\n }\\ntable[data-taco^='table']#${tableId} > thead > tr > th:nth-child(${index + 1}):after {\n content: none;\n }\\ntable[data-taco^='table'][data-table-horizontally-scrolled=\"true\"]#${tableId} > thead > tr > th:nth-child(${\n index + 1\n }),\n table[data-taco^='table'][data-table-horizontally-scrolled=\"true\"]#${tableId} > tbody > tr > td:nth-child(${\n index + 1\n }),\n table[data-taco^='table'][data-table-horizontally-scrolled=\"true\"]#${tableId} > tfoot > tr > td:nth-child(${\n index + 1\n }) {\n border-right-color: rgb(221, 221, 221);\n box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), 6px 0px 6px rgb(0 0 0/8%);\n }`);\n }\n\n if (right.length) {\n right.forEach(cell => {\n styles.push(`table[data-taco^='table']#${tableId} [data-cell-id=\"${cell.column.id}\"] {\n right: ${cell.column.getStart(cell.column.getIsPinned())}px;\n }`);\n });\n const rightIds = right.map(x => x.id);\n const index = all.indexOf(rightIds[rightIds.length - 1]);\n\n styles.push(`table[data-taco^='table']#${tableId} > thead > tr > th:nth-child(${index + 1}):not([data-cell-id^=\"__\"]),\n table[data-taco^='table']#${tableId} > tbody > tr > td:nth-child(${index + 1}):not([data-cell-id^=\"__\"]) {\n border-left-width: 1px;\n }`);\n }\n\n return styles.join('\\n');\n }, [columnPinning, columnSizing]);\n\n return { stylesheet };\n}\n"],"names":["useTableStyleColumnFreezing","tableId","table","columnPinning","columnSizing","getState","stylesheet","React","useMemo","styles","all","getFlatHeaders","filter","column","subHeaders","length","map","x","id","left","getLeftFlatHeaders","right","getRightFlatHeaders","forEach","cell","push","getStart","getIsPinned","leftIds","index","indexOf","rightIds","join"],"mappings":";;SAGgBA,2BAA2BA,CAAkBC,OAAe,EAAEC,KAAwB;EAClG,MAAM;IAAEC,aAAa;IAAEC;GAAc,GAAGF,KAAK,CAACG,QAAQ,EAAE;EAExD,MAAMC,UAAU,GAAGC,cAAK,CAACC,OAAO,CAAC;IAC7B,MAAMC,MAAM,GAAa,EAAE;;IAG3B,MAAMC,GAAG,GAAGR,KAAK,CACZS,cAAc,EAAE,CAChBC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ACC,IAAI;QACdf,MAAM,CAACgB,IAAI,8BAA8BxB,0BAA0BuB,IAAI,CAACX,MAAM,CAACK;6BAClEM,IAAI,CAACX,MAAM,CAACa,QAAQ,CAACF,IAAI,CAACX,MAAM,CAACc,WAAW,EAAE;kBACzD,CAAC;OACN,CAAC;MACF,MAAMI,QAAQ,GAAGV,KAAK,CAACL,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACC,EAAE,CAAC;MACrC,MAAMW,KAAK,GAAGnB,GAAG,CAACoB,OAAO,CAACC,QAAQ,CAACA,QAAQ,CAAChB,MAAM,GAAG,CAAC,CAAC,CAAC;MAExDN,MAAM,CAACgB,IAAI,8BAA8BxB,uCAAuC4B,KAAK,GAAG;4CACxD5B,uCAAuC4B,KAAK,GAAG;;kBAEzE,CAAC;;IAGX,OAAOpB,MAAM,CAACuB,IAAI,CAAC,IAAI,CAAC;GAC3B,EAAE,CAAC7B,aAAa,EAAEC,YAAY,CAAC,CAAC;EAEjC,OAAO;IAAEE;GAAY;AACzB;;;;"}
@@ -9,7 +9,7 @@ function useTableStyleGrid(tableId, table, fontSize) {
9
9
  // header body ?footer
10
10
  const gridTemplateRows = table.getRowModel().rows.length ? 'min-content 1fr min-content' : 'min-content 1fr';
11
11
  return React__default.useMemo(() => {
12
- let printGridTemplateColumns = '';
12
+ let printGridTemplateColumns = 0;
13
13
  const printHiddenColumns = [];
14
14
  const gridTemplateColumns = allVisibleColumns.reduce((accum, column, index) => {
15
15
  var _column$columnDef$min, _column$columnDef$met;
@@ -19,7 +19,6 @@ function useTableStyleGrid(tableId, table, fontSize) {
19
19
  const minSize = (_column$columnDef$min = column.columnDef.minSize) !== null && _column$columnDef$min !== void 0 ? _column$columnDef$min : globalMinSize;
20
20
  const width = columnSizing[column.id];
21
21
  let size;
22
- let printSize;
23
22
  if (isInternalColumn(column.id)) {
24
23
  if (column.id === '__actions') {
25
24
  const minWidth = tableMeta.rowActions.rowActionsLength * 32 + 8; /* button margins l+r */
@@ -43,22 +42,24 @@ function useTableStyleGrid(tableId, table, fontSize) {
43
42
  } else {
44
43
  size = `minmax(max-content, auto)`;
45
44
  }
45
+ // printing
46
46
  if (((_column$columnDef$met = column.columnDef.meta) === null || _column$columnDef$met === void 0 ? void 0 : _column$columnDef$met.enablePrinting) === false) {
47
- printSize = '';
48
47
  printHiddenColumns.push(column.id);
49
48
  } else {
50
- printSize = 'auto';
49
+ printGridTemplateColumns++;
51
50
  }
52
- printGridTemplateColumns = `${printGridTemplateColumns} ${printSize}`.trim();
53
51
  return `${accum} ${size}`.trim();
54
52
  }, '');
55
- // we have to be specific so that nested tables don't inherit the same css
56
- const hiddenColumns = printHiddenColumns.map(id => `table[data-taco^='table']#${tableId} > thead > tr > th[data-cell-id='${id}']\n,table[data-taco^='table']#${tableId} > tbody > tr > td[data-cell-id='${id}']\n`).join(',');
53
+ // normal grid
57
54
  const style = {
58
55
  gridTemplateColumns,
59
56
  gridTemplateRows
60
57
  };
61
- const stylesheet = `@media print { table[data-taco^='table']#${tableId} { grid-template-columns: ${printGridTemplateColumns}; } ${hiddenColumns ? `${hiddenColumns} { display: none; }` : ''}}`;
58
+ // printing grid
59
+ // we have to be specific so that nested tables don't inherit the same css
60
+ const hiddenColumns = printHiddenColumns.map(id => `table[data-taco^='table']#${tableId} > thead > tr > th[data-cell-id='${id}']\n,table[data-taco^='table']#${tableId} > tbody > tr > td[data-cell-id='${id}']\n`).join(',');
61
+ const stylesheet = `@media print { table[data-taco^='table']#${tableId} { grid-template-columns: repeat(${printGridTemplateColumns}, auto) !important; }
62
+ table[data-taco^='table']#${tableId} [data-cell-id^='__']${hiddenColumns ? `, ${hiddenColumns}` : ''} { display: none; }}`;
62
63
  return {
63
64
  style,
64
65
  stylesheet
@@ -1 +1 @@
1
- {"version":3,"file":"useTableStyleGrid.js","sources":["../../../../../../../../../src/primitives/Table/Core/features/useTableStyleGrid.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { TableFontSize } from '../../types';\nimport { getCellMinWidth, isInternalColumn } from '../../useTableManager/util/columns';\n\nexport function useTableStyleGrid<TType = unknown>(tableId: string, table: ReactTable<TType>, fontSize: TableFontSize) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const allVisibleColumns = table.getVisibleLeafColumns();\n const columnSizing = table.getState().columnSizing;\n const globalMinSize = getCellMinWidth(fontSize);\n\n // header body ?footer\n const gridTemplateRows = table.getRowModel().rows.length ? 'min-content 1fr min-content' : 'min-content 1fr';\n\n return React.useMemo(() => {\n let printGridTemplateColumns = '';\n const printHiddenColumns: string[] = [];\n\n const gridTemplateColumns = allVisibleColumns.reduce((accum, column, index) => {\n if (table.options.enableGrouping && column.getIsGrouped()) {\n return accum;\n }\n\n const minSize = column.columnDef.minSize ?? globalMinSize;\n const width = columnSizing[column.id] as number | 'grow';\n\n let size;\n let printSize;\n\n if (isInternalColumn(column.id)) {\n if (column.id === '__actions') {\n const minWidth = tableMeta.rowActions.rowActionsLength * 32 + 8; /* button margins l+r */\n size = `minmax(${minWidth}px, auto)`;\n } else {\n // getSize method is used instead of columnSizing state because internal columns have defined widths\n size = `${column.getSize()}px`;\n }\n } else if (width !== undefined) {\n const isLastColumn = index === allVisibleColumns.length - 1;\n\n if (width === 'grow' || (Number.isNaN(width) && !isLastColumn)) {\n size = `minmax(max-content, 1fr)`;\n } else {\n const minWidth = width < minSize ? minSize : width;\n\n if (isLastColumn) {\n size = `minmax(${minWidth}px, auto)`;\n } else {\n size = `${minWidth}px`;\n }\n }\n } else {\n size = `minmax(max-content, auto)`;\n }\n\n if (column.columnDef.meta?.enablePrinting === false) {\n printSize = '';\n printHiddenColumns.push(column.id);\n } else {\n printSize = 'auto';\n }\n\n printGridTemplateColumns = `${printGridTemplateColumns} ${printSize}`.trim();\n\n return `${accum} ${size}`.trim();\n }, '');\n\n // we have to be specific so that nested tables don't inherit the same css\n const hiddenColumns = printHiddenColumns\n .map(\n id =>\n `table[data-taco^='table']#${tableId} > thead > tr > th[data-cell-id='${id}']\\n,table[data-taco^='table']#${tableId} > tbody > tr > td[data-cell-id='${id}']\\n`\n )\n .join(',');\n\n const style: React.CSSProperties = {\n gridTemplateColumns,\n gridTemplateRows,\n };\n\n const stylesheet = `@media print { table[data-taco^='table']#${tableId} { grid-template-columns: ${printGridTemplateColumns}; } ${\n hiddenColumns ? `${hiddenColumns} { display: none; }` : ''\n }}`;\n\n return { style, stylesheet };\n }, [allVisibleColumns, columnSizing, globalMinSize, tableMeta.rowActions.rowActionsLength]);\n}\n"],"names":["useTableStyleGrid","tableId","table","fontSize","tableMeta","options","meta","allVisibleColumns","getVisibleLeafColumns","columnSizing","getState","globalMinSize","getCellMinWidth","gridTemplateRows","getRowModel","rows","length","React","useMemo","printGridTemplateColumns","printHiddenColumns","gridTemplateColumns","reduce","accum","column","index","enableGrouping","getIsGrouped","minSize","_column$columnDef$min","columnDef","width","id","size","printSize","isInternalColumn","minWidth","rowActions","rowActionsLength","getSize","undefined","isLastColumn","Number","isNaN","_column$columnDef$met","enablePrinting","push","trim","hiddenColumns","map","join","style","stylesheet"],"mappings":";;;SAKgBA,iBAAiBA,CAAkBC,OAAe,EAAEC,KAAwB,EAAEC,QAAuB;EACjH,MAAMC,SAAS,GAAGF,KAAK,CAACG,OAAO,CAACC,IAA6B;EAC7D,MAAMC,iBAAiB,GAAGL,KAAK,CAACM,qBAAqB,EAAE;EACvD,MAAMC,YAAY,GAAGP,KAAK,CAACQ,QAAQ,EAAE,CAACD,YAAY;EAClD,MAAME,aAAa,GAAGC,eAAe,CAACT,QAAQ,CAAC;;EAG/C,MAAMU,gBAAgB,GAAGX,KAAK,CAACY,WAAW,EAAE,CAACC,IAAI,CAACC,MAAM,GAAG,6BAA6B,GAAG,iBAAiB;EAE5G,OAAOC,cAAK,CAACC,OAAO,CAAC;IACjB,IAAIC,wBAAwB,GAAG,EAAE;IACjC,MAAMC,kBAAkB,GAAa,EAAE;IAEvC,MAAMC,mBAAmB,GAAGd,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AAA,CAAuBC,cAAc,MAAK,KAAK,EAAE;QACjDX,SAAS,GAAG,EAAE;QACdd,kBAAkB,CAAC0B,IAAI,CAACtB,MAAM,CAACQ,EAAE,CAAC;OACrC,MAAM;QACHE,SAAS,GAAG,MAAM;;MAGtBf,wBAAwB,MAAMA,4BAA4Be,WAAW,CAACa,IAAI,EAAE;MAE5E,UAAUxB,SAASU,MAAM,CAACc,IAAI,EAAE;KACnC,EAAE,EAAE,CAAC;;IAGN,MAAMC,aAAa,GAAG5B,kBAAkB,CACnC6B,GAAG,CACAjB,EAAE,iCAC+B/B,2CAA2C+B,oCAAoC/B,2CAA2C+B,QAAQ,CACtK,CACAkB,IAAI,CAAC,GAAG,CAAC;IAEd,MAAMC,KAAK,GAAwB;MAC/B9B,mBAAmB;MACnBR;KACH;IAED,MAAMuC,UAAU,+CAA+CnD,oCAAoCkB,+BAC/F6B,aAAa,MAAMA,kCAAkC,GAAG,KACzD;IAEH,OAAO;MAAEG,KAAK;MAAEC;KAAY;GAC/B,EAAE,CAAC7C,iBAAiB,EAAEE,YAAY,EAAEE,aAAa,EAAEP,SAAS,CAACiC,UAAU,CAACC,gBAAgB,CAAC,CAAC;AAC/F;;;;"}
1
+ {"version":3,"file":"useTableStyleGrid.js","sources":["../../../../../../../../../src/primitives/Table/Core/features/useTableStyleGrid.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { TableFontSize } from '../../types';\nimport { getCellMinWidth, isInternalColumn } from '../../useTableManager/util/columns';\n\nexport function useTableStyleGrid<TType = unknown>(tableId: string, table: ReactTable<TType>, fontSize: TableFontSize) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const allVisibleColumns = table.getVisibleLeafColumns();\n const columnSizing = table.getState().columnSizing;\n const globalMinSize = getCellMinWidth(fontSize);\n\n // header body ?footer\n const gridTemplateRows = table.getRowModel().rows.length ? 'min-content 1fr min-content' : 'min-content 1fr';\n\n return React.useMemo(() => {\n let printGridTemplateColumns = 0;\n const printHiddenColumns: string[] = [];\n\n const gridTemplateColumns = allVisibleColumns.reduce((accum, column, index) => {\n if (table.options.enableGrouping && column.getIsGrouped()) {\n return accum;\n }\n\n const minSize = column.columnDef.minSize ?? globalMinSize;\n const width = columnSizing[column.id] as number | 'grow';\n\n let size;\n\n if (isInternalColumn(column.id)) {\n if (column.id === '__actions') {\n const minWidth = tableMeta.rowActions.rowActionsLength * 32 + 8; /* button margins l+r */\n size = `minmax(${minWidth}px, auto)`;\n } else {\n // getSize method is used instead of columnSizing state because internal columns have defined widths\n size = `${column.getSize()}px`;\n }\n } else if (width !== undefined) {\n const isLastColumn = index === allVisibleColumns.length - 1;\n\n if (width === 'grow' || (Number.isNaN(width) && !isLastColumn)) {\n size = `minmax(max-content, 1fr)`;\n } else {\n const minWidth = width < minSize ? minSize : width;\n\n if (isLastColumn) {\n size = `minmax(${minWidth}px, auto)`;\n } else {\n size = `${minWidth}px`;\n }\n }\n } else {\n size = `minmax(max-content, auto)`;\n }\n\n // printing\n if (column.columnDef.meta?.enablePrinting === false) {\n printHiddenColumns.push(column.id);\n } else {\n printGridTemplateColumns++;\n }\n\n return `${accum} ${size}`.trim();\n }, '');\n\n // normal grid\n const style: React.CSSProperties = {\n gridTemplateColumns,\n gridTemplateRows,\n };\n\n // printing grid\n // we have to be specific so that nested tables don't inherit the same css\n const hiddenColumns = printHiddenColumns\n .map(\n id =>\n `table[data-taco^='table']#${tableId} > thead > tr > th[data-cell-id='${id}']\\n,table[data-taco^='table']#${tableId} > tbody > tr > td[data-cell-id='${id}']\\n`\n )\n .join(',');\n const stylesheet = `@media print { table[data-taco^='table']#${tableId} { grid-template-columns: repeat(${printGridTemplateColumns}, auto) !important; }\n table[data-taco^='table']#${tableId} [data-cell-id^='__']${\n hiddenColumns ? `, ${hiddenColumns}` : ''\n } { display: none; }}`;\n\n return { style, stylesheet };\n }, [allVisibleColumns, columnSizing, globalMinSize, tableMeta.rowActions.rowActionsLength]);\n}\n"],"names":["useTableStyleGrid","tableId","table","fontSize","tableMeta","options","meta","allVisibleColumns","getVisibleLeafColumns","columnSizing","getState","globalMinSize","getCellMinWidth","gridTemplateRows","getRowModel","rows","length","React","useMemo","printGridTemplateColumns","printHiddenColumns","gridTemplateColumns","reduce","accum","column","index","enableGrouping","getIsGrouped","minSize","_column$columnDef$min","columnDef","width","id","size","isInternalColumn","minWidth","rowActions","rowActionsLength","getSize","undefined","isLastColumn","Number","isNaN","_column$columnDef$met","enablePrinting","push","trim","style","hiddenColumns","map","join","stylesheet"],"mappings":";;;SAKgBA,iBAAiBA,CAAkBC,OAAe,EAAEC,KAAwB,EAAEC,QAAuB;EACjH,MAAMC,SAAS,GAAGF,KAAK,CAACG,OAAO,CAACC,IAA6B;EAC7D,MAAMC,iBAAiB,GAAGL,KAAK,CAACM,qBAAqB,EAAE;EACvD,MAAMC,YAAY,GAAGP,KAAK,CAACQ,QAAQ,EAAE,CAACD,YAAY;EAClD,MAAME,aAAa,GAAGC,eAAe,CAACT,QAAQ,CAAC;;EAG/C,MAAMU,gBAAgB,GAAGX,KAAK,CAACY,WAAW,EAAE,CAACC,IAAI,CAACC,MAAM,GAAG,6BAA6B,GAAG,iBAAiB;EAE5G,OAAOC,cAAK,CAACC,OAAO,CAAC;IACjB,IAAIC,wBAAwB,GAAG,CAAC;IAChC,MAAMC,kBAAkB,GAAa,EAAE;IAEvC,MAAMC,mBAAmB,GAAGd,iBAAiB,CAACe,MAAM,CAAC,CAACC,KAAK,EAAEC,MAAM,EAAEC,KAAK;;MACtE,IAAIvB,KAAK,CAACG,OAAO,CAACqB,cAAc,IAAIF,MAAM,CAACG,YAAY,EAAE,EAAE;QACvD,OAAOJ,KAAK;;MAGhB,MAAMK,OAAO,IAAAC,qBAAA,GAAGL,MAAM,CAACM,SAAS,CAACF,OAAO,cAAAC,qBAAA,cAAAA,qBAAA,GAAIlB,aAAa;MACzD,MAAMoB,KAAK,GAAGtB,YAAY,CAACe,MAAM,CA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/B,2CAA2C+B,QAAQ,CACtK,CACAkB,IAAI,CAAC,GAAG,CAAC;IACd,MAAMC,UAAU,+CAA+ClD,2CAA2CkB;oCAC9ElB,+BACxB+C,aAAa,QAAQA,eAAe,GAAG,wBACrB;IAEtB,OAAO;MAAED,KAAK;MAAEI;KAAY;GAC/B,EAAE,CAAC5C,iBAAiB,EAAEE,YAAY,EAAEE,aAAa,EAAEP,SAAS,CAACgC,UAAU,CAACC,gBAAgB,CAAC,CAAC;AAC/F;;;;"}
@@ -56,7 +56,7 @@ function orderColumn(column, {
56
56
  }
57
57
  }
58
58
  // ordering
59
- function ensureOrdering(columns, settingsOrder, internalColumnsPinnedToTheRight = ['__actions']) {
59
+ function ensureOrdering(columns, settingsOrder, pinnedOrder = [], internalColumnsPinnedToTheRight = ['__actions']) {
60
60
  // internal columns come with a defined order
61
61
  const internalColumns = columns.filter(column => isInternalColumn(column.id) && !internalColumnsPinnedToTheRight.includes(String(column.id))).map(column => column.id);
62
62
  // columns with ordering disabled should be moved to the front
@@ -92,6 +92,12 @@ function ensureOrdering(columns, settingsOrder, internalColumnsPinnedToTheRight
92
92
  // Append absent columns at the end
93
93
  .concat(columnsAbsentInSettingsOrder);
94
94
  }
95
+ // if pinned columns are defined, make sure they are sorted first, this ensures state matches the freezing "upto" behaviour
96
+ if (Array.isArray(pinnedOrder)) {
97
+ orderingEnabled.sort(
98
+ // the magic >>> 0 here ensures that columns that aren't found in settings, but are children, are pushed to the end
99
+ (a, b) => (pinnedOrder.indexOf(a) >>> 0) - (pinnedOrder.indexOf(b) >>> 0));
100
+ }
95
101
  const order = [...internalColumns, ...orderingDisabled, ...orderingEnabled];
96
102
  // actions should always be last, enforce that
97
103
  internalColumnsPinnedToTheRight.forEach(id => {