@economic/taco 2.35.0 → 2.36.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. package/dist/components/Dialog/components/Content.d.ts +5 -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/Menu/Menu.d.ts +2 -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/Menu/components/Separator.d.ts +3 -2
  8. package/dist/components/Navigation2/components/Link.d.ts +1 -1
  9. package/dist/components/Provider/Localization.d.ts +6 -0
  10. package/dist/components/Report/Report.d.ts +1 -1
  11. package/dist/components/Select2/Select2.d.ts +4 -25
  12. package/dist/components/Select2/components/Option.d.ts +2 -2
  13. package/dist/components/Select2/components/Search.d.ts +1 -7
  14. package/dist/components/Table3/Table3.d.ts +29 -1
  15. package/dist/components/Table3/components/Row/Editing/CreateRowButton.d.ts +11 -0
  16. package/dist/components/Table3/features/useTableEditing.d.ts +1 -0
  17. package/dist/components/Table3/types.d.ts +16 -1
  18. package/dist/components/Table3/util/editing.d.ts +1 -0
  19. package/dist/components/Tag/Tag.d.ts +1 -1
  20. package/dist/esm/index.css +41 -21
  21. package/dist/esm/node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js +161 -1
  22. package/dist/esm/node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js.map +1 -1
  23. package/dist/esm/packages/taco/src/components/Combobox/useCombobox.js +1 -1
  24. package/dist/esm/packages/taco/src/components/Combobox/useCombobox.js.map +1 -1
  25. package/dist/esm/packages/taco/src/components/Dialog/components/Content.js.map +1 -1
  26. package/dist/esm/packages/taco/src/components/Icon/components/{ESignature.js → DocumentSignedSolid.js} +4 -4
  27. package/dist/esm/packages/taco/src/components/Icon/components/DocumentSignedSolid.js.map +1 -0
  28. package/dist/esm/packages/taco/src/components/Icon/components/{Home2.js → House.js} +4 -4
  29. package/dist/esm/packages/taco/src/components/Icon/components/{Home2.js.map → House.js.map} +1 -1
  30. package/dist/esm/packages/taco/src/components/Icon/components/{Home.js → HouseSolid.js} +4 -4
  31. package/dist/esm/packages/taco/src/components/Icon/components/HouseSolid.js.map +1 -0
  32. package/dist/esm/packages/taco/src/components/Icon/components/index.js +6 -6
  33. package/dist/esm/packages/taco/src/components/Icon/components/index.js.map +1 -1
  34. package/dist/esm/packages/taco/src/components/Menu/Menu.js.map +1 -1
  35. package/dist/esm/packages/taco/src/components/Menu/components/Separator.js +7 -5
  36. package/dist/esm/packages/taco/src/components/Menu/components/Separator.js.map +1 -1
  37. package/dist/esm/packages/taco/src/components/Provider/Localization.js +7 -1
  38. package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
  39. package/dist/esm/packages/taco/src/components/Select2/Select2.js +8 -55
  40. package/dist/esm/packages/taco/src/components/Select2/Select2.js.map +1 -1
  41. package/dist/esm/packages/taco/src/components/Select2/components/Search.js +2 -12
  42. package/dist/esm/packages/taco/src/components/Select2/components/Search.js.map +1 -1
  43. package/dist/esm/packages/taco/src/components/Table3/Table3.js +8 -1
  44. package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
  45. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/util.js +3 -2
  46. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/util.js.map +1 -1
  47. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js +24 -3
  48. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js.map +1 -1
  49. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateRowButton.js +90 -0
  50. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateRowButton.js.map +1 -0
  51. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +53 -15
  52. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js.map +1 -1
  53. package/dist/esm/packages/taco/src/components/Table3/useTable3.js +2 -1
  54. package/dist/esm/packages/taco/src/components/Table3/useTable3.js.map +1 -1
  55. package/dist/esm/packages/taco/src/components/Table3/util/editing.js +20 -1
  56. package/dist/esm/packages/taco/src/components/Table3/util/editing.js.map +1 -1
  57. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js +5 -2
  58. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js.map +1 -1
  59. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Header/Header.js +2 -1
  60. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Header/Header.js.map +1 -1
  61. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Header/components/Menu.js +2 -4
  62. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Header/components/Menu.js.map +1 -1
  63. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js +2 -3
  64. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js.map +1 -1
  65. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/ManageFiltersPopover.js +5 -4
  66. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/ManageFiltersPopover.js.map +1 -1
  67. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterColumn.js +4 -3
  68. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterColumn.js.map +1 -1
  69. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterComparator.js +4 -3
  70. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterComparator.js.map +1 -1
  71. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterValue.js +3 -2
  72. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterValue.js.map +1 -1
  73. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +1 -1
  74. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
  75. package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
  76. package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js +6 -1
  77. package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js.map +1 -1
  78. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowClick.js +11 -8
  79. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowClick.js.map +1 -1
  80. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +2 -1
  81. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
  82. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/presets.js +3 -1
  83. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/presets.js.map +1 -1
  84. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +9 -0
  85. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
  86. package/dist/esm/packages/taco/src/utils/dom.js +2 -2
  87. package/dist/esm/packages/taco/src/utils/dom.js.map +1 -1
  88. package/dist/index.css +41 -21
  89. package/dist/primitives/Table/Core/components/Header/components/Menu.d.ts +1 -0
  90. package/dist/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterColumn.d.ts +1 -1
  91. package/dist/primitives/Table/types.d.ts +8 -6
  92. package/dist/primitives/Table/useTableManager/features/useTableRowClick.d.ts +4 -4
  93. package/dist/primitives/Table/useTableManager/useTableManager.d.ts +1 -1
  94. package/dist/primitives/Table/useTableManager/util/presets.d.ts +1 -1
  95. package/dist/primitives/Table/useTableManager/util/setup.d.ts +2 -2
  96. package/dist/taco.cjs.development.js +463 -156
  97. package/dist/taco.cjs.development.js.map +1 -1
  98. package/dist/taco.cjs.production.min.js +1 -1
  99. package/dist/taco.cjs.production.min.js.map +1 -1
  100. package/dist/utils/dom.d.ts +1 -1
  101. package/package.json +2 -2
  102. package/dist/components/Table/Table.storyexample.d.ts +0 -9
  103. package/dist/esm/packages/taco/src/components/Icon/components/ESignature.js.map +0 -1
  104. package/dist/esm/packages/taco/src/components/Icon/components/Home.js.map +0 -1
  105. /package/dist/components/Icon/components/{ESignature.d.ts → DocumentSignedSolid.d.ts} +0 -0
  106. /package/dist/components/Icon/components/{Home.d.ts → House.d.ts} +0 -0
  107. /package/dist/components/Icon/components/{Home2.d.ts → HouseSolid.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sources":["../../../../../../../../../../src/components/Table3/components/Columns/Cell/util.ts"],"sourcesContent":["import React from 'react';\nimport { TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { useAugmentedFocusManager } from '../../../../../primitives/Table/Core/components/Body/util';\nimport { TableCellRendererProps } from '../../../../../primitives/Table/Core/types';\nimport { RowContext } from '../../../../../primitives/Table/Core/components/Row/RowContext';\nimport { hasFocusableElement } from '../../../../../utils/dom';\n\nexport function useEditingCellAutofocus<TType = unknown>(props: TableCellRendererProps<TType>) {\n const focusManager = useAugmentedFocusManager();\n const { rowIndex } = React.useContext(RowContext);\n const table = props.cell.getContext().table;\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const isActiveRow = tableMeta.rowActive.rowActiveIndex === rowIndex;\n\n const autoFocus = props.index === tableMeta.editing.lastFocusedCellIndex && isActiveRow;\n\n // focus the cell so that we trigger it's handle focus\n React.useEffect(() => {\n if (props.cellRef.current) {\n const isFocusedElementInCurrentRow = props.cellRef.current.closest('tr')?.contains(document.activeElement);\n const isFocusedElementSearch = document.activeElement?.getAttribute('name') === 'table-search';\n\n if (autoFocus && !isFocusedElementInCurrentRow && !isFocusedElementSearch) {\n props.cellRef.current?.focus();\n }\n }\n }, [autoFocus]);\n\n // when the cell receives focus we actually want to focus the control inside it...\n const handleFocus = (event: React.FocusEvent<HTMLTableCellElement>) => {\n const tableElement = props.cellRef.current?.closest('table');\n\n if (tableElement && table.getIsSomeColumnsPinned() && !props.cell.column.getIsPinned()) {\n const columnFreezingOffset = table.getLeftTotalSize();\n const targetRect = event.currentTarget.getBoundingClientRect();\n const tableRect = tableElement.getBoundingClientRect();\n const leftOffsetFromScrollContainer = targetRect.left - tableRect.left;\n const scrollbarWidth = tableElement.offsetWidth - tableElement.clientWidth; // the width of table vertical scrollbar\n\n if (\n // When pinned column overlaps the focused cell\n leftOffsetFromScrollContainer < columnFreezingOffset ||\n // When focused cell goes behidn the edge of the table\n leftOffsetFromScrollContainer + targetRect.width > tableRect.width - scrollbarWidth\n ) {\n tableElement.scrollTo(props.cell.column.getStart() - columnFreezingOffset, tableElement.scrollTop);\n }\n }\n\n if (event.target === event.currentTarget && hasFocusableElement(event.currentTarget)) {\n focusManager.focusNext();\n }\n };\n\n return handleFocus;\n}\n"],"names":["useEditingCellAutofocus","props","focusManager","useAugmentedFocusManager","rowIndex","React","useContext","RowContext","table","cell","getContext","tableMeta","options","meta","isActiveRow","rowActive","rowActiveIndex","autoFocus","index","editing","lastFocusedCellIndex","useEffect","cellRef","current","_props$cellRef$curren","_document$activeEleme","isFocusedElementInCurrentRow","closest","contains","document","activeElement","isFocusedElementSearch","getAttribute","_props$cellRef$curren2","focus","handleFocus","event","tableElement","_props$cellRef$curren3","getIsSomeColumnsPinned","column","getIsPinned","columnFreezingOffset","getLeftTotalSize","targetRect","currentTarget","getBoundingClientRect","tableRect","leftOffsetFromScrollContainer","left","scrollbarWidth","offsetWidth","clientWidth","width","scrollTo","getStart","scrollTop","target","hasFocusableElement","focusNext"],"mappings":";;;;;SAOgBA,uBAAuBA,CAAkBC,KAAoC;EACzF,MAAMC,YAAY,GAAGC,wBAAwB,EAAE;EAC/C,MAAM;IAAEC;GAAU,GAAGC,cAAK,CAACC,UAAU,CAACC,UAAU,CAAC;EACjD,MAAMC,KAAK,GAAGP,KAAK,CAACQ,IAAI,CAACC,UAAU,EAAE,CAACF,KAAK;EAC3C,MAAMG,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,WAAW,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,KAAK,CAACS,aAAa,CAACC,qBAAqB,EAAE;MAC9D,MAAMC,SAAS,GAAGV,YAAY,CAACS,qBAAqB,EAAE;MACtD,MAAME,6BAA6B,GAAGJ,UAAU,CAACK,IAAI,GAAGF,SAAS,CAACE,IAAI;MACtE,MAAMC,cAAc,GAAGb,YAAY,CAACc,WAAW,GAAGd,YAAY,CAACe,WAAW,CAAC;MAE3E;;MAEIJ,6BAA6B,GAAGN,oBAAoB;;MAEpDM,6BAA6B,GAAGJ,UAAU,CAACS,KAAK,GAAGN,SAAS,CAACM,KAAK,GAAGH,cAAc,EACrF;QACEb,YAAY,CAACiB,QAAQ,CAACrD,KAAK,CAACQ,IAAI,CAAC+B,MAAM,CAACe,QAAQ,EAAE,GAAGb,oBAAoB,EAAEL,YAAY,CAACmB,SAAS,CAAC;;;IAI1G,IAAIpB,KAAK,CAACqB,MAAM,KAAKrB,KAAK,CAACS,aAAa,IAAIa,mBAAmB,CAACtB,KAAK,CAACS,aAAa,CAAC,EAAE;MAClF3C,YAAY,CAACyD,SAAS,EAAE;;GAE/B;EAED,OAAOxB,WAAW;AACtB;;;;"}
1
+ {"version":3,"file":"util.js","sources":["../../../../../../../../../../src/components/Table3/components/Columns/Cell/util.ts"],"sourcesContent":["import React from 'react';\nimport { TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { useAugmentedFocusManager } from '../../../../../primitives/Table/Core/components/Body/util';\nimport { TableCellRendererProps } from '../../../../../primitives/Table/Core/types';\nimport { RowContext } from '../../../../../primitives/Table/Core/components/Row/RowContext';\nimport { hasFocusableElement } from '../../../../../utils/dom';\n\nexport function useEditingCellAutofocus<TType = unknown>(props: TableCellRendererProps<TType>) {\n const focusManager = useAugmentedFocusManager();\n const { rowIndex } = React.useContext(RowContext);\n const table = props.cell.getContext().table;\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const isActiveRow = tableMeta.rowActive.rowActiveIndex === rowIndex;\n\n const autoFocus = props.index === tableMeta.editing.lastFocusedCellIndex && isActiveRow;\n\n // focus the cell so that we trigger it's handle focus\n React.useEffect(() => {\n if (props.cellRef.current) {\n const isFocusedElementInCurrentRow = props.cellRef.current.closest('tr')?.contains(document.activeElement);\n const isFocusedElementSearch = document.activeElement?.getAttribute('name') === 'table-search';\n const isFocusedElementMenu = document.activeElement?.getAttribute('role') === 'menu';\n\n if (autoFocus && !isFocusedElementInCurrentRow && !isFocusedElementSearch && !isFocusedElementMenu) {\n props.cellRef.current?.focus();\n }\n }\n }, [autoFocus]);\n\n // when the cell receives focus we actually want to focus the control inside it...\n const handleFocus = (event: React.FocusEvent<HTMLTableCellElement>) => {\n const tableElement = props.cellRef.current?.closest('table');\n\n if (tableElement && table.getIsSomeColumnsPinned() && !props.cell.column.getIsPinned()) {\n const columnFreezingOffset = table.getLeftTotalSize();\n const targetRect = event.currentTarget.getBoundingClientRect();\n const tableRect = tableElement.getBoundingClientRect();\n const leftOffsetFromScrollContainer = targetRect.left - tableRect.left;\n const scrollbarWidth = tableElement.offsetWidth - tableElement.clientWidth; // the width of table vertical scrollbar\n\n if (\n // When pinned column overlaps the focused cell\n leftOffsetFromScrollContainer < columnFreezingOffset ||\n // When focused cell goes behidn the edge of the table\n leftOffsetFromScrollContainer + targetRect.width > tableRect.width - scrollbarWidth\n ) {\n tableElement.scrollTo(props.cell.column.getStart() - columnFreezingOffset, tableElement.scrollTop);\n }\n }\n\n if (event.target === event.currentTarget && hasFocusableElement(event.currentTarget)) {\n focusManager.focusNext();\n }\n };\n\n return handleFocus;\n}\n"],"names":["useEditingCellAutofocus","props","focusManager","useAugmentedFocusManager","rowIndex","React","useContext","RowContext","table","cell","getContext","tableMeta","options","meta","isActiveRow","rowActive","rowActiveIndex","autoFocus","index","editing","lastFocusedCellIndex","useEffect","cellRef","current","_props$cellRef$curren","_document$activeEleme","_document$activeEleme2","isFocusedElementInCurrentRow","closest","contains","document","activeElement","isFocusedElementSearch","getAttribute","isFocusedElementMenu","_props$cellRef$curren2","focus","handleFocus","event","tableElement","_props$cellRef$curren3","getIsSomeColumnsPinned","column","getIsPinned","columnFreezingOffset","getLeftTotalSize","targetRect","currentTarget","getBoundingClientRect","tableRect","leftOffsetFromScrollContainer","left","scrollbarWidth","offsetWidth","clientWidth","width","scrollTo","getStart","scrollTop","target","hasFocusableElement","focusNext"],"mappings":";;;;;SAOgBA,uBAAuBA,CAAkBC,KAAoC;EACzF,MAAMC,YAAY,GAAGC,wBAAwB,EAAE;EAC/C,MAAM;IAAEC;GAAU,GAAGC,cAAK,CAACC,UAAU,CAACC,UAAU,CAAC;EACjD,MAAMC,KAAK,GAAGP,KAAK,CAACQ,IAAI,CAACC,UAAU,EAAE,CAACF,KAAK;EAC3C,MAAMG,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,WAAW,GAAGH,SAAS,CAACI,SAAS,CAACC,cAAc,KAAKZ,QAAQ;EAEnE,MAAMa,SAAS,GAAGhB,KAAK,CAACiB,KAAK,KAAKP,SAAS,CAACQ,OAAO,CAACC,oBAAoB,IAAIN,WAAW;;EAGvFT,cAAK,CAACgB,SAAS,CAAC;IACZ,IAAIpB,KAAK,CAACqB,OAAO,CAACC,OAAO,EAAE;MAAA,IAAAC,qBAAA,EAAAC,qBAAA,EAAAC,sBAAA;MACvB,MAAMC,4BAA4B,IAAAH,qBAAA,GAAGvB,KAAK,CAACqB,OAAO,CAACC,OAAO,CAACK,OAAO,CAAC,IAAI,CAAC,cAAAJ,qBAAA,uBAAnCA,qBAAA,CAAqCK,QAAQ,CAACC,QAAQ,CAACC,aAAa,CAAC;MAC1G,MAAMC,sBAAsB,GAAG,EAAAP,qBAAA,GAAAK,QAAQ,CAACC,aAAa,cAAAN,qBAAA,uBAAtBA,qBAAA,CAAwBQ,YAAY,CAAC,MAAM,CAAC,MAAK,cAAc;MAC9F,MAAMC,oBAAoB,GAAG,EAAAR,sBAAA,GAAAI,QAAQ,CAACC,aAAa,cAAAL,sBAAA,uBAAtBA,sBAAA,CAAwBO,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B,KAAK,CAACS,aAAa,IAAIa,mBAAmB,CAACtB,KAAK,CAACS,aAAa,CAAC,EAAE;MAClF7C,YAAY,CAAC2D,SAAS,EAAE;;GAE/B;EAED,OAAOxB,WAAW;AACtB;;;;"}
@@ -20,6 +20,22 @@ function Alert(props) {
20
20
  const tableMeta = table.options.meta;
21
21
  const [showFilterResetDialog, setShowFilterResetDialog] = React__default.useState(false);
22
22
  const pendingChangesWithErrors = tableMeta.editing.getErrors();
23
+ const resetPendingChanges = tableMeta.editing.resetChanges;
24
+ const allRows = table.getPreFilteredRowModel().rows;
25
+ // This effect deletes error in the alert if the row that has the error is deleted.
26
+ React__default.useEffect(() => {
27
+ pendingChangesWithErrors.forEach(errorRow => {
28
+ const errorRowId = errorRow.rowId;
29
+ try {
30
+ // getRow throws error if it fails to find the row
31
+ if (!table.getRow(errorRowId)) {
32
+ resetPendingChanges(errorRowId);
33
+ }
34
+ } catch {
35
+ resetPendingChanges(errorRowId);
36
+ }
37
+ });
38
+ }, [allRows.length]);
23
39
  const activeRow = React__default.useMemo(() => tableMeta.rowActive.rowActiveIndex ? table.getRowModel().rows[tableMeta.rowActive.rowActiveIndex] : undefined, [tableMeta.rowActive.rowActiveIndex]);
24
40
  // mark errors being rendered as seen
25
41
  React__default.useEffect(() => {
@@ -48,18 +64,23 @@ function Alert(props) {
48
64
  const title = (pendingChangesWithErrors.length === 1 ? validationTexts.alert.titleOne : validationTexts.alert.titlePlural).replace('[COUNT]', String(pendingChangesWithErrors.length));
49
65
  // generate links to each invalid row, to go into the error message
50
66
  const links = [];
51
- const rowIdentityColumn = tableMeta.rowIdentityColumnId ? table.getColumn(tableMeta.rowIdentityColumnId) : undefined;
67
+ const rowIdentityColumn = tableMeta.rowIdentityColumnAccessor ?
68
+ // Since rowIdentityColumnAccessor can have multiple ids, we use the first id to refer to the row in Alert
69
+ table.getColumn(String(tableMeta.rowIdentityColumnAccessor[0])) : undefined;
52
70
  pendingChangesWithErrors.forEach((error, index) => {
53
71
  // if appropriate, concatenate the item with the text "and"
54
72
  if (pendingChangesWithErrors.length > 1 && index === pendingChangesWithErrors.length - 1) {
55
73
  // Add space before and after `messageAnd` text
56
74
  links.push(` ${validationTexts.alert.messageAnd} `);
57
75
  }
58
- const rowIndex = table.getRowModel().rows.findIndex(row => row.id === error.rowId);
76
+ const rowIndex = table.getFilteredRowModel().rows.findIndex(row => row.id === error.rowId);
59
77
  const handleClick = () => {
78
+ // if row is visible
60
79
  if (rowIndex > -1) {
61
80
  scrollToRow(rowIndex);
62
- } else {
81
+ }
82
+ // if row is filtered out
83
+ else {
63
84
  setShowFilterResetDialog(error.rowId);
64
85
  }
65
86
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Alert.js","sources":["../../../../../../../../../src/components/Table3/components/Editing/Alert.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { ScrollToOptions as ReactVirtualScrollToOptions } from '@tanstack/react-virtual';\nimport { Alert as BaseAlert, AlertProps as BaseAlertProps } from '../../../Alert/Alert';\nimport { TableRef } from '../../../../primitives/Table/types';\nimport { Tooltip } from '../../../Tooltip/Tooltip';\nimport { useLocalization } from '../../../Provider/Localization';\nimport { Dialog, DialogProps } from '../../../Dialog/Dialog';\nimport { Group } from '../../../Group/Group';\nimport { Button } from '../../../Button/Button';\n\ntype AlertProps<TType = unknown> = Omit<BaseAlertProps, 'children'> & {\n scrollToIndex: (index: number, options: ReactVirtualScrollToOptions) => void;\n table: ReactTable<TType>;\n tableRef: React.RefObject<TableRef>;\n};\n\nexport function Alert<TType = unknown>(props: AlertProps<TType>) {\n const { scrollToIndex, table, tableRef, ...attributes } = props;\n const { texts } = useLocalization();\n const validationTexts = texts.table3.editing.validation;\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const [showFilterResetDialog, setShowFilterResetDialog] = React.useState<string | false>(false);\n\n const pendingChangesWithErrors = tableMeta.editing.getErrors<TType>();\n\n const activeRow = React.useMemo(\n () => (tableMeta.rowActive.rowActiveIndex ? table.getRowModel().rows[tableMeta.rowActive.rowActiveIndex] : undefined),\n [tableMeta.rowActive.rowActiveIndex]\n );\n\n // mark errors being rendered as seen\n React.useEffect(() => {\n pendingChangesWithErrors.forEach(error => {\n if (activeRow && error.rowId === activeRow.id) {\n return;\n }\n\n tableMeta.editing.setRowErrorsSeen(error.rowId);\n });\n }, [pendingChangesWithErrors]);\n\n function scrollToRow(rowIndex: number) {\n tableMeta.rowActive.setRowActiveIndex(rowIndex);\n scrollToIndex(rowIndex, { align: 'center' });\n\n requestAnimationFrame(() => {\n const cell = tableRef.current?.querySelector(\n 'tbody > tr[data-row-active=\"true\"] > td[data-cell-editing-invalid=\"true\"]'\n );\n\n if (cell) {\n (cell as HTMLElement).focus?.();\n }\n });\n }\n\n // generate the \"N unsaved entries\" title\n const title = (\n pendingChangesWithErrors.length === 1 ? validationTexts.alert.titleOne : validationTexts.alert.titlePlural\n ).replace('[COUNT]', String(pendingChangesWithErrors.length));\n\n // generate links to each invalid row, to go into the error message\n const links: React.ReactNode[] = [];\n const rowIdentityColumn = tableMeta.rowIdentityColumnId ? table.getColumn(tableMeta.rowIdentityColumnId) : undefined;\n\n pendingChangesWithErrors.forEach((error, index) => {\n // if appropriate, concatenate the item with the text \"and\"\n if (pendingChangesWithErrors.length > 1 && index === pendingChangesWithErrors.length - 1) {\n // Add space before and after `messageAnd` text\n links.push(` ${validationTexts.alert.messageAnd} `);\n }\n const rowIndex = table.getRowModel().rows.findIndex(row => row.id === error.rowId);\n\n const handleClick = () => {\n if (rowIndex > -1) {\n scrollToRow(rowIndex);\n } else {\n setShowFilterResetDialog(error.rowId);\n }\n };\n\n let tooltip;\n\n if (error.pendingChange._meta.errors.row) {\n tooltip = error.pendingChange._meta.errors.row;\n } else {\n const firstCellErrorColumnId = Object.keys(error.pendingChange._meta.errors.cells)[0];\n const columnName = table.getAllColumns().find(column => column.id === firstCellErrorColumnId)?.columnDef.meta?.header;\n tooltip = `${columnName}: ${error.pendingChange._meta.errors.cells[firstCellErrorColumnId]}`;\n }\n\n links.push(\n <Tooltip key={error.rowId} title={tooltip}>\n <span className=\"text-blue\" onClick={handleClick} role=\"button\">\n {rowIdentityColumn ? error.pendingChange._meta.original[rowIdentityColumn.id] : rowIndex + 1}\n </span>\n </Tooltip>\n );\n\n // if appropriate, concatenate the item with the text \",\"\n if (pendingChangesWithErrors.length > 2 && index < pendingChangesWithErrors.length - 2) {\n links.push(', ');\n }\n });\n\n // generate the \"Row N is incomplete and hasn't been saved\" error message\n const message = (links.length === 1 ? validationTexts.alert.messageOne : validationTexts.alert.messagePlural)\n .split(/(\\[\\w+\\])/)\n .map(part => {\n if (part === '[COLUMN]') {\n return rowIdentityColumn?.columnDef.meta?.header ?? validationTexts.alert.messageRow;\n }\n\n if (part === '[ROW]') {\n return links;\n }\n\n return part;\n });\n\n const handleResetFilters = () => {\n table.resetGlobalFilter();\n table.resetColumnFilters();\n\n requestAnimationFrame(() => {\n const rowIndex = table.getRowModel().rows.findIndex(row => row.id === showFilterResetDialog);\n\n if (rowIndex > -1) {\n scrollToRow(rowIndex);\n }\n\n setShowFilterResetDialog(false);\n });\n };\n\n return (\n <>\n <BaseAlert {...attributes} state=\"error\">\n <span className=\"font-bold\">{title}</span>&nbsp;{message}\n </BaseAlert>\n <FilterResetDialog\n open={showFilterResetDialog !== false}\n onChange={() => setShowFilterResetDialog(false)}\n onSubmit={handleResetFilters}\n />\n </>\n );\n}\n\ntype FilterResetDialogProps = Omit<DialogProps, 'children'> & {\n onSubmit: () => void;\n};\n\nfunction FilterResetDialog(props: FilterResetDialogProps) {\n const { onSubmit: handleSubmit, ...dialogProps } = props;\n const { texts } = useLocalization();\n\n return (\n <Dialog {...dialogProps} size=\"xs\">\n <Dialog.Content aria-label=\"Create a new account\">\n <Dialog.Title>{texts.table3.editing.validation.resetFiltersDialog.title}</Dialog.Title>\n\n <p>{texts.table3.editing.validation.resetFiltersDialog.description}</p>\n\n <Dialog.Footer>\n <Group>\n <Dialog.Close>\n <Button>{texts.table3.editing.validation.resetFiltersDialog.cancel}</Button>\n </Dialog.Close>\n <Button appearance=\"primary\" onClick={handleSubmit}>\n {texts.table3.editing.validation.resetFiltersDialog.confirm}\n </Button>\n </Group>\n </Dialog.Footer>\n </Dialog.Content>\n </Dialog>\n );\n}\n"],"names":["Alert","props","scrollToIndex","table","tableRef","attributes","texts","useLocalization","validationTexts","table3","editing","validation","tableMeta","options","meta","showFilterResetDialog","setShowFilterResetDialog","React","useState","pendingChangesWithErrors","getErrors","activeRow","useMemo","rowActive","rowActiveIndex","getRowModel","rows","undefined","useEffect","forEach","error","rowId","id","setRowErrorsSeen","scrollToRow","rowIndex","setRowActiveIndex","align","requestAnimationFrame","cell","_tableRef$current","current","querySelector","_cell$focus","focus","call","title","length","alert","titleOne","titlePlural","replace","String","links","rowIdentityColumn","rowIdentityColumnId","getColumn","index","push","messageAnd","findIndex","row","handleClick","tooltip","pendingChange","_meta","errors","_table$getAllColumns$","_table$getAllColumns$2","firstCellErrorColumnId","Object","keys","cells","columnName","getAllColumns","find","column","columnDef","header","Tooltip","key","className","onClick","role","original","message","messageOne","messagePlural","split","map","part","_rowIdentityColumn$co","_rowIdentityColumn$co2","messageRow","handleResetFilters","resetGlobalFilter","resetColumnFilters","BaseAlert","state","FilterResetDialog","open","onChange","onSubmit","handleSubmit","dialogProps","Dialog","size","Content","Title","resetFiltersDialog","description","Footer","Group","Close","Button","cancel","appearance","confirm"],"mappings":";;;;;;;;SAiBgBA,KAAKA,CAAkBC,KAAwB;EAC3D,MAAM;IAAEC,aAAa;IAAEC,KAAK;IAAEC,QAAQ;IAAE,GAAGC;GAAY,GAAGJ,KAAK;EAC/D,MAAM;IAAEK;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,eAAe,GAAGF,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU;EACvD,MAAMC,SAAS,GAAGT,KAAK,CAACU,OAAO,CAACC,IAA6B;EAC7D,MAAM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vB1F,6BAACwF,MAAM,CAACG,KAAK,QAAEtG,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAACkG,kBAAkB,CAAC/D,KAAK,CAAgB,eAEvF7B,wCAAIX,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAACkG,kBAAkB,CAACC,WAAW,CAAK,eAEvE7F,6BAACwF,MAAM,CAACM,MAAM,qBACV9F,6BAAC+F,KAAK,qBACF/F,6BAACwF,MAAM,CAACQ,KAAK,qBACThG,6BAACiG,MAAM,QAAE5G,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAACkG,kBAAkB,CAACM,MAAM,CAAU,CACjE,eACflG,6BAACiG,MAAM;IAACE,UAAU,EAAC,SAAS;IAAClC,OAAO,EAAEqB;KACjCjG,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAACkG,kBAAkB,CAACQ,OAAO,CACtD,CACL,CACI,CACH,CACZ;AAEjB;;;;"}
1
+ {"version":3,"file":"Alert.js","sources":["../../../../../../../../../src/components/Table3/components/Editing/Alert.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { ScrollToOptions as ReactVirtualScrollToOptions } from '@tanstack/react-virtual';\nimport { Alert as BaseAlert, AlertProps as BaseAlertProps } from '../../../Alert/Alert';\nimport { TableRef } from '../../../../primitives/Table/types';\nimport { Tooltip } from '../../../Tooltip/Tooltip';\nimport { useLocalization } from '../../../Provider/Localization';\nimport { Dialog, DialogProps } from '../../../Dialog/Dialog';\nimport { Group } from '../../../Group/Group';\nimport { Button } from '../../../Button/Button';\n\ntype AlertProps<TType = unknown> = Omit<BaseAlertProps, 'children'> & {\n scrollToIndex: (index: number, options: ReactVirtualScrollToOptions) => void;\n table: ReactTable<TType>;\n tableRef: React.RefObject<TableRef>;\n};\n\nexport function Alert<TType = unknown>(props: AlertProps<TType>) {\n const { scrollToIndex, table, tableRef, ...attributes } = props;\n const { texts } = useLocalization();\n const validationTexts = texts.table3.editing.validation;\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const [showFilterResetDialog, setShowFilterResetDialog] = React.useState<string | false>(false);\n\n const pendingChangesWithErrors = tableMeta.editing.getErrors<TType>();\n const resetPendingChanges = tableMeta.editing.resetChanges;\n\n const allRows = table.getPreFilteredRowModel().rows;\n\n // This effect deletes error in the alert if the row that has the error is deleted.\n React.useEffect(() => {\n pendingChangesWithErrors.forEach(errorRow => {\n const errorRowId = errorRow.rowId;\n\n try {\n // getRow throws error if it fails to find the row\n if (!table.getRow(errorRowId)) {\n resetPendingChanges(errorRowId);\n }\n } catch {\n resetPendingChanges(errorRowId);\n }\n });\n }, [allRows.length]);\n\n const activeRow = React.useMemo(\n () => (tableMeta.rowActive.rowActiveIndex ? table.getRowModel().rows[tableMeta.rowActive.rowActiveIndex] : undefined),\n [tableMeta.rowActive.rowActiveIndex]\n );\n\n // mark errors being rendered as seen\n React.useEffect(() => {\n pendingChangesWithErrors.forEach(error => {\n if (activeRow && error.rowId === activeRow.id) {\n return;\n }\n\n tableMeta.editing.setRowErrorsSeen(error.rowId);\n });\n }, [pendingChangesWithErrors]);\n\n function scrollToRow(rowIndex: number) {\n tableMeta.rowActive.setRowActiveIndex(rowIndex);\n scrollToIndex(rowIndex, { align: 'center' });\n\n requestAnimationFrame(() => {\n const cell = tableRef.current?.querySelector(\n 'tbody > tr[data-row-active=\"true\"] > td[data-cell-editing-invalid=\"true\"]'\n );\n\n if (cell) {\n (cell as HTMLElement).focus?.();\n }\n });\n }\n\n // generate the \"N unsaved entries\" title\n const title = (\n pendingChangesWithErrors.length === 1 ? validationTexts.alert.titleOne : validationTexts.alert.titlePlural\n ).replace('[COUNT]', String(pendingChangesWithErrors.length));\n\n // generate links to each invalid row, to go into the error message\n const links: React.ReactNode[] = [];\n const rowIdentityColumn = tableMeta.rowIdentityColumnAccessor\n ? // Since rowIdentityColumnAccessor can have multiple ids, we use the first id to refer to the row in Alert\n table.getColumn(String(tableMeta.rowIdentityColumnAccessor[0]))\n : undefined;\n\n pendingChangesWithErrors.forEach((error, index) => {\n // if appropriate, concatenate the item with the text \"and\"\n if (pendingChangesWithErrors.length > 1 && index === pendingChangesWithErrors.length - 1) {\n // Add space before and after `messageAnd` text\n links.push(` ${validationTexts.alert.messageAnd} `);\n }\n\n const rowIndex = table.getFilteredRowModel().rows.findIndex(row => row.id === error.rowId);\n\n const handleClick = () => {\n // if row is visible\n if (rowIndex > -1) {\n scrollToRow(rowIndex);\n }\n // if row is filtered out\n else {\n setShowFilterResetDialog(error.rowId);\n }\n };\n\n let tooltip;\n\n if (error.pendingChange._meta.errors.row) {\n tooltip = error.pendingChange._meta.errors.row;\n } else {\n const firstCellErrorColumnId = Object.keys(error.pendingChange._meta.errors.cells)[0];\n const columnName = table.getAllColumns().find(column => column.id === firstCellErrorColumnId)?.columnDef.meta?.header;\n tooltip = `${columnName}: ${error.pendingChange._meta.errors.cells[firstCellErrorColumnId]}`;\n }\n\n links.push(\n <Tooltip key={error.rowId} title={tooltip}>\n <span className=\"text-blue\" onClick={handleClick} role=\"button\">\n {rowIdentityColumn ? error.pendingChange._meta.original[rowIdentityColumn.id] : rowIndex + 1}\n </span>\n </Tooltip>\n );\n\n // if appropriate, concatenate the item with the text \",\"\n if (pendingChangesWithErrors.length > 2 && index < pendingChangesWithErrors.length - 2) {\n links.push(', ');\n }\n });\n\n // generate the \"Row N is incomplete and hasn't been saved\" error message\n const message = (links.length === 1 ? validationTexts.alert.messageOne : validationTexts.alert.messagePlural)\n .split(/(\\[\\w+\\])/)\n .map(part => {\n if (part === '[COLUMN]') {\n return rowIdentityColumn?.columnDef.meta?.header ?? validationTexts.alert.messageRow;\n }\n\n if (part === '[ROW]') {\n return links;\n }\n\n return part;\n });\n\n const handleResetFilters = () => {\n table.resetGlobalFilter();\n table.resetColumnFilters();\n\n requestAnimationFrame(() => {\n const rowIndex = table.getRowModel().rows.findIndex(row => row.id === showFilterResetDialog);\n\n if (rowIndex > -1) {\n scrollToRow(rowIndex);\n }\n\n setShowFilterResetDialog(false);\n });\n };\n\n return (\n <>\n <BaseAlert {...attributes} state=\"error\">\n <span className=\"font-bold\">{title}</span>&nbsp;{message}\n </BaseAlert>\n <FilterResetDialog\n open={showFilterResetDialog !== false}\n onChange={() => setShowFilterResetDialog(false)}\n onSubmit={handleResetFilters}\n />\n </>\n );\n}\n\ntype FilterResetDialogProps = Omit<DialogProps, 'children'> & {\n onSubmit: () => void;\n};\n\nfunction FilterResetDialog(props: FilterResetDialogProps) {\n const { onSubmit: handleSubmit, ...dialogProps } = props;\n const { texts } = useLocalization();\n\n return (\n <Dialog {...dialogProps} size=\"xs\">\n <Dialog.Content aria-label=\"Create a new account\">\n <Dialog.Title>{texts.table3.editing.validation.resetFiltersDialog.title}</Dialog.Title>\n\n <p>{texts.table3.editing.validation.resetFiltersDialog.description}</p>\n\n <Dialog.Footer>\n <Group>\n <Dialog.Close>\n <Button>{texts.table3.editing.validation.resetFiltersDialog.cancel}</Button>\n </Dialog.Close>\n <Button appearance=\"primary\" onClick={handleSubmit}>\n {texts.table3.editing.validation.resetFiltersDialog.confirm}\n </Button>\n </Group>\n </Dialog.Footer>\n </Dialog.Content>\n </Dialog>\n );\n}\n"],"names":["Alert","props","scrollToIndex","table","tableRef","attributes","texts","useLocalization","validationTexts","table3","editing","validation","tableMeta","options","meta","showFilterResetDialog","setShowFilterResetDialog","React","useState","pendingChangesWithErrors","getErrors","resetPendingChanges","resetChanges","allRows","getPreFilteredRowModel","rows","useEffect","forEach","errorRow","errorRowId","rowId","getRow","length","activeRow","useMemo","rowActive","rowActiveIndex","getRowModel","undefined","error","id","setRowErrorsSeen","scrollToRow","rowIndex","setRowActiveIndex","align","requestAnimationFrame","cell","_tableRef$current","current","querySelector","_cell$focus","focus","call","title","alert","titleOne","titlePlural","replace","String","links","rowIdentityColumn","rowIdentityColumnAccessor","getColumn","index","push","messageAnd","getFilteredRowModel","findIndex","row","handleClick","tooltip","pendingChange","_meta","errors","_table$getAllColumns$","_table$getAllColumns$2","firstCellErrorColumnId","Object","keys","cells","columnName","getAllColumns","find","column","columnDef","header","Tooltip","key","className","onClick","role","original","message","messageOne","messagePlural","split","map","part","_rowIdentityColumn$co","_rowIdentityColumn$co2","messageRow","handleResetFilters","resetGlobalFilter","resetColumnFilters","BaseAlert","state","FilterResetDialog","open","onChange","onSubmit","handleSubmit","dialogProps","Dialog","size","Content","Title","resetFiltersDialog","description","Footer","Group","Close","Button","cancel","appearance","confirm"],"mappings":";;;;;;;;SAiBgBA,KAAKA,CAAkBC,KAAwB;EAC3D,MAAM;IAAEC,aAAa;IAAEC,KAAK;IAAEC,QAAQ;IAAE,GAAGC;GAAY,GAAGJ,KAAK;EAC/D,MAAM;IAAEK;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,eAAe,GAAGF,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU;EACvD,MAAMC,SAAS,GAAGT,KAAK,CAACU,OAAO,CAACC,IAA6B;EAC7D,MAAM,CAACC,qBAAqB,EAAEC,wBAAwB,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAiB,KAAK,CAAC;EAE/F,MAAMC,wBAAwB,GAAGP,SAAS,CAACF,OAAO,CAACU,SAAS,EAAS;EACrE,MAAMC,mBAAmB,GAAGT,SAAS,CAACF,OAAO,CAACY,YAAY;EAE1D,MAAMC,OAAO,GAAGpB,KAAK,CAACqB,sBAAsB,EAAE,CAACC,IAAI;;EAGnDR,cAAK,CAACS,SAAS,CAAC;IACZP,wBAAwB,CAACQ,OAAO,CAACC,QAAQ;MACrC,MAAMC,UAAU,GAAGD,QAAQ,CAACE,KAAK;MAEjC,IAAI;;QAEA,IAAI,CAAC3B,KAAK,CAAC4B,MAAM,CAACF,UAAU,CAAC,EAAE;UAC3BR,mBAAmB,CAACQ,UAAU,CAAC;;OAEtC,CAAC,MAAM;QACJR,mBAAmB,CAACQ,UAAU,CAAC;;KAEtC,CAAC;GACL,EAA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AE9G,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAAC0G,kBAAkB,CAAC/D,KAAK,CAAgB,eAEvFrC,wCAAIX,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAAC0G,kBAAkB,CAACC,WAAW,CAAK,eAEvErG,6BAACgG,MAAM,CAACM,MAAM,qBACVtG,6BAACuG,KAAK,qBACFvG,6BAACgG,MAAM,CAACQ,KAAK,qBACTxG,6BAACyG,MAAM,QAAEpH,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAAC0G,kBAAkB,CAACM,MAAM,CAAU,CACjE,eACf1G,6BAACyG,MAAM;IAACE,UAAU,EAAC,SAAS;IAAClC,OAAO,EAAEqB;KACjCzG,KAAK,CAACG,MAAM,CAACC,OAAO,CAACC,UAAU,CAAC0G,kBAAkB,CAACQ,OAAO,CACtD,CACL,CACI,CACH,CACZ;AAEjB;;;;"}
@@ -0,0 +1,90 @@
1
+ import React__default from 'react';
2
+ import { useLocalization } from '../../../../Provider/Localization.js';
3
+ import { Button } from '../../../../Button/Button.js';
4
+ import { animateCreateRow } from '../../../util/editing.js';
5
+
6
+ function CreateNewRowButton(props) {
7
+ const {
8
+ onCreate,
9
+ scrollToIndex,
10
+ table,
11
+ tableMeta
12
+ } = props;
13
+ const {
14
+ texts
15
+ } = useLocalization();
16
+ const rows = table.getCoreRowModel().rows;
17
+ const [rowCreated, setRowCreated] = React__default.useState({
18
+ rowFinder: undefined
19
+ });
20
+ const handleKeyDown = event => {
21
+ if (!tableMeta.editing.hasChanges() && event.key === 'Tab') {
22
+ !tableMeta.editing.saveChanges();
23
+ }
24
+ };
25
+ const handleCreate = function () {
26
+ try {
27
+ if (!onCreate) {
28
+ return Promise.resolve();
29
+ }
30
+ const createdRow = rows.find(row => {
31
+ var _rowCreated$rowFinder;
32
+ return rowCreated === null || rowCreated === void 0 ? void 0 : (_rowCreated$rowFinder = rowCreated.rowFinder) === null || _rowCreated$rowFinder === void 0 ? void 0 : _rowCreated$rowFinder.call(rowCreated, row.original);
33
+ });
34
+ const _temp = function () {
35
+ if (createdRow) {
36
+ return Promise.resolve(tableMeta.editing.saveChanges()).then(function () {
37
+ if (!tableMeta.editing.hasRowErrors(createdRow.id)) {
38
+ const rowFinder = onCreate();
39
+ setRowCreated({
40
+ rowFinder
41
+ });
42
+ }
43
+ });
44
+ } else {
45
+ const rowFinder = onCreate();
46
+ setRowCreated({
47
+ rowFinder
48
+ });
49
+ }
50
+ }();
51
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
52
+ } catch (e) {
53
+ return Promise.reject(e);
54
+ }
55
+ };
56
+ React__default.useEffect(() => {
57
+ if (typeof (rowCreated === null || rowCreated === void 0 ? void 0 : rowCreated.rowFinder) === 'function') {
58
+ const createdRow = rows.find(row => {
59
+ var _rowCreated$rowFinder2;
60
+ return rowCreated === null || rowCreated === void 0 ? void 0 : (_rowCreated$rowFinder2 = rowCreated.rowFinder) === null || _rowCreated$rowFinder2 === void 0 ? void 0 : _rowCreated$rowFinder2.call(rowCreated, row.original);
61
+ });
62
+ if (createdRow) {
63
+ const rowInTable = table.getRowModel().rows.find(row => {
64
+ var _rowCreated$rowFinder3;
65
+ return rowCreated === null || rowCreated === void 0 ? void 0 : (_rowCreated$rowFinder3 = rowCreated.rowFinder) === null || _rowCreated$rowFinder3 === void 0 ? void 0 : _rowCreated$rowFinder3.call(rowCreated, row.original);
66
+ });
67
+ if (rowInTable) {
68
+ tableMeta.editing.toggleEditing(true);
69
+ tableMeta.rowActive.setRowActiveIndex(createdRow.index);
70
+ scrollToIndex(createdRow.index);
71
+ requestAnimationFrame(() => animateCreateRow(createdRow.id));
72
+ }
73
+ requestAnimationFrame(() => tableMeta.editing.addCreatedRowChangeset(createdRow));
74
+ }
75
+ }
76
+ }, [rowCreated]);
77
+ return /*#__PURE__*/React__default.createElement("tr", {
78
+ onClick: handleCreate,
79
+ className: "border-grey-300 hover:bg-grey-100 group !sticky bottom-10 left-0 z-[21] !block cursor-pointer border-t"
80
+ }, /*#__PURE__*/React__default.createElement("td", {
81
+ className: "!border-t-0 !bg-transparent"
82
+ }, /*#__PURE__*/React__default.createElement(Button, {
83
+ onKeyDown: handleKeyDown,
84
+ className: "group-hover:bg-grey-200 sticky left-0",
85
+ appearance: "transparent"
86
+ }, "+ ", texts.table3.editing.buttons.create.label)));
87
+ }
88
+
89
+ export default CreateNewRowButton;
90
+ //# sourceMappingURL=CreateRowButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateRowButton.js","sources":["../../../../../../../../../../src/components/Table3/components/Row/Editing/CreateRowButton.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { ScrollToOptions } from '@tanstack/react-virtual';\nimport { Button } from '../../../../Button/Button';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { animateCreateRow } from '../../../util/editing';\n\ntype Props<TType = unknown> = {\n table: ReactTable<TType>;\n tableMeta: ReactTableMeta<TType>;\n onCreate: (() => (row: Partial<TType>) => boolean) | undefined;\n scrollToIndex: (index: number, options?: ScrollToOptions) => void;\n};\n\nexport default function CreateNewRowButton<TType = unknown>(props: Props<TType>) {\n const { onCreate, scrollToIndex, table, tableMeta } = props;\n const { texts } = useLocalization();\n const rows = table.getCoreRowModel().rows;\n const [rowCreated, setRowCreated] = React.useState<{ rowFinder: ((row: Partial<TType>) => boolean) | undefined }>({\n rowFinder: undefined,\n });\n\n const handleKeyDown = event => {\n if (!tableMeta.editing.hasChanges() && event.key === 'Tab') {\n !tableMeta.editing.saveChanges();\n }\n };\n\n const handleCreate = async () => {\n if (!onCreate) {\n return;\n }\n const createdRow = rows.find(row => rowCreated?.rowFinder?.(row.original));\n\n if (createdRow) {\n await tableMeta.editing.saveChanges();\n\n if (!tableMeta.editing.hasRowErrors(createdRow.id)) {\n const rowFinder = onCreate();\n\n setRowCreated({ rowFinder });\n }\n } else {\n const rowFinder = onCreate();\n setRowCreated({ rowFinder });\n }\n };\n\n React.useEffect(() => {\n if (typeof rowCreated?.rowFinder === 'function') {\n const createdRow = rows.find(row => rowCreated?.rowFinder?.(row.original));\n\n if (createdRow) {\n const rowInTable = table.getRowModel().rows.find(row => rowCreated?.rowFinder?.(row.original));\n if (rowInTable) {\n tableMeta.editing.toggleEditing(true);\n tableMeta.rowActive.setRowActiveIndex(createdRow.index);\n scrollToIndex(createdRow.index);\n requestAnimationFrame(() => animateCreateRow(createdRow.id));\n }\n requestAnimationFrame(() => tableMeta.editing.addCreatedRowChangeset(createdRow));\n }\n }\n }, [rowCreated]);\n\n return (\n <tr\n onClick={handleCreate}\n className=\"border-grey-300 hover:bg-grey-100 group !sticky bottom-10 left-0 z-[21] !block cursor-pointer border-t\">\n <td className=\"!border-t-0 !bg-transparent\">\n <Button onKeyDown={handleKeyDown} className=\"group-hover:bg-grey-200 sticky left-0\" appearance=\"transparent\">\n + {texts.table3.editing.buttons.create.label}\n </Button>\n </td>\n </tr>\n );\n}\n"],"names":["CreateNewRowButton","props","onCreate","scrollToIndex","table","tableMeta","texts","useLocalization","rows","getCoreRowModel","rowCreated","setRowCreated","React","useState","rowFinder","undefined","handleKeyDown","event","editing","hasChanges","key","saveChanges","handleCreate","Promise","resolve","createdRow","find","row","_rowCreated$rowFinder","call","original","_temp","then","hasRowErrors","id","e","reject","useEffect","_rowCreated$rowFinder2","rowInTable","getRowModel","_rowCreated$rowFinder3","toggleEditing","rowActive","setRowActiveIndex","index","requestAnimationFrame","animateCreateRow","addCreatedRowChangeset","onClick","className","Button","onKeyDown","appearance","table3","buttons","create","label"],"mappings":";;;;;SAcwBA,kBAAkBA,CAAkBC,KAAmB;EAC3E,MAAM;IAAEC,QAAQ;IAAEC,aAAa;IAAEC,KAAK;IAAEC;GAAW,GAAGJ,KAAK;EAC3D,MAAM;IAAEK;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,IAAI,GAAGJ,KAAK,CAACK,eAAe,EAAE,CAACD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uCAAuC;IAACG,UAAU,EAAC;WACxF/C,KAAK,CAACgD,MAAM,CAACpC,OAAO,CAACqC,OAAO,CAACC,MAAM,CAACC,KAAK,CACvC,CACR,CACJ;AAEb;;;;"}
@@ -1,6 +1,6 @@
1
1
  import React__default from 'react';
2
2
  import { useGlobalKeyDown } from '../../../hooks/useGlobalKeyDown.js';
3
- import { _catch } from '../../../../../../node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js';
3
+ import { _forOf, _catch } from '../../../../../../node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js';
4
4
  import { willRowMove } from '../util/editing.js';
5
5
 
6
6
  function useTableEditing(isEnabled = false, handleSave, validator) {
@@ -36,6 +36,7 @@ function useTableEditing(isEnabled = false, handleSave, validator) {
36
36
  function usePendingChanges(isEnabled, handleSave, validator) {
37
37
  const saveChanges = function (rowId = undefined) {
38
38
  try {
39
+ let _exit = false;
39
40
  if (!handleSave) {
40
41
  console.warn('Tried to save, but Table has no onSave handler');
41
42
  return Promise.resolve();
@@ -47,13 +48,12 @@ function usePendingChanges(isEnabled, handleSave, validator) {
47
48
  ...pendingChanges
48
49
  };
49
50
  const changes = Object.keys(changesToSave);
50
- if (changes.length) {
51
- changes.map(function (rowId) {
52
- try {
53
- let _exit = false;
51
+ return Promise.resolve(function () {
52
+ if (changes.length) {
53
+ return _forOf(changes, function (rowId) {
54
54
  const pendingChange = changesToSave[rowId];
55
55
  const changeSet = getChangesetFromChanges(pendingChange);
56
- return Promise.resolve(_catch(function () {
56
+ return _catch(function () {
57
57
  function _temp3(_result) {
58
58
  return _exit ? _result : Promise.resolve(handleSave(changeSet)).then(function () {
59
59
  // cleanup changes, we don't need them after saving
@@ -61,6 +61,10 @@ function usePendingChanges(isEnabled, handleSave, validator) {
61
61
  setRowSaveStatus(rowId, 'complete');
62
62
  });
63
63
  }
64
+ if (getRowSaveStatus(rowId) === 'pending') {
65
+ _exit = true;
66
+ return;
67
+ }
64
68
  // set saving = true
65
69
  setRowSaveStatus(rowId, 'pending');
66
70
  // re-run validation, maybe a cell is already invalid but has never been blurred
@@ -107,13 +111,12 @@ function usePendingChanges(isEnabled, handleSave, validator) {
107
111
  });
108
112
  }
109
113
  setRowSaveStatus(rowId, undefined);
110
- }));
111
- } catch (e) {
112
- return Promise.reject(e);
113
- }
114
- });
115
- }
116
- return Promise.resolve();
114
+ });
115
+ }, function () {
116
+ return _exit;
117
+ });
118
+ }
119
+ }());
117
120
  } catch (e) {
118
121
  return Promise.reject(e);
119
122
  }
@@ -150,6 +153,40 @@ function usePendingChanges(isEnabled, handleSave, validator) {
150
153
  return Promise.reject(e);
151
154
  }
152
155
  };
156
+ const addCreatedRowChangeset = function (row) {
157
+ try {
158
+ const cells = row.getAllCells();
159
+ setPendingChanges(currentChanges => {
160
+ return cells.reduce((changes, cell) => {
161
+ if (cell.getValue()) {
162
+ var _currentChanges$cell$4, _currentChanges$cell$5, _currentChanges$cell$6;
163
+ return {
164
+ ...changes,
165
+ [cell.row.id]: {
166
+ ...changes[cell.row.id],
167
+ [cell.column.id]: cell.getValue(),
168
+ _meta: {
169
+ ...((_currentChanges$cell$4 = currentChanges[cell.row.id]) === null || _currentChanges$cell$4 === void 0 ? void 0 : _currentChanges$cell$4._meta),
170
+ original: cell.row.original,
171
+ moveReason: {
172
+ ...((_currentChanges$cell$5 = currentChanges[cell.row.id]) === null || _currentChanges$cell$5 === void 0 ? void 0 : _currentChanges$cell$5._meta.moveReason)
173
+ },
174
+ errors: {
175
+ ...((_currentChanges$cell$6 = currentChanges[cell.row.id]) === null || _currentChanges$cell$6 === void 0 ? void 0 : _currentChanges$cell$6._meta.errors)
176
+ }
177
+ }
178
+ }
179
+ };
180
+ } else {
181
+ return changes;
182
+ }
183
+ }, currentChanges);
184
+ });
185
+ return Promise.resolve();
186
+ } catch (e) {
187
+ return Promise.reject(e);
188
+ }
189
+ };
153
190
  const [pendingChanges, setPendingChanges] = React__default.useState({});
154
191
  // we maintain save status as separate state because 'complete' needs to briefly show after pendingChanges are deleted
155
192
  const [saveStates, setSaveState] = React__default.useState({});
@@ -276,8 +313,8 @@ function usePendingChanges(isEnabled, handleSave, validator) {
276
313
  return Object.keys(getErrors().filter(error => {
277
314
  var _activeRow;
278
315
  if ((_activeRow = activeRow) !== null && _activeRow !== void 0 && _activeRow.id && focusIsInsideTable) {
279
- var _activeRow2;
280
- return error.rowId === ((_activeRow2 = activeRow) === null || _activeRow2 === void 0 ? void 0 : _activeRow2.id) ? error.pendingChange._meta.errors.hasShownErrorAlert : true;
316
+ var _activeRow2, _error$pendingChange$;
317
+ return error.rowId === ((_activeRow2 = activeRow) === null || _activeRow2 === void 0 ? void 0 : _activeRow2.id) ? (_error$pendingChange$ = error.pendingChange._meta.errors) === null || _error$pendingChange$ === void 0 ? void 0 : _error$pendingChange$.hasShownErrorAlert : true;
281
318
  }
282
319
  return true;
283
320
  })).length;
@@ -302,6 +339,7 @@ function usePendingChanges(isEnabled, handleSave, validator) {
302
339
  getCellError,
303
340
  setCellValue,
304
341
  validateCell,
342
+ addCreatedRowChangeset,
305
343
  hasChanges,
306
344
  hasErrors,
307
345
  getErrors,
@@ -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 { 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 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 };\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","useGlobalKeyDown","key","meta","shift","undefined","event","preventDefault","saveChanges","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","useCallback","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":";;;;;SAOgBA,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;EAEpFY,gBAAgB,CAACd,SAAS,IAAIG,SAAS,GAAG;IAAEY,GAAG,EAAE,GAAG;IAAEC,IAAI,EAAE,IAAI;IAAEC,KAAK,EAAE;GAAO,GAAGC,SAAS,EAAEC,KAAK;IAC/FA,KAAK,CAACC,cAAc,EAAE;IACtBR,iBAAiB,CAACS,WAAW,EAAE;GAClC,CAAC;EAEF,OAAO;IACHrB,SAAS;IACTG,SAAS;IACTI,cAAc;IACdC,kBAAkB,EAAER,SAAS,GAAGQ,kBAAkB,GAAG,MAAMU,SAAS;IACpEd,aAAa,EAAEJ,SAAS,GAAGI,aAAa,GAAG,MAAMc,SAAS;IAC1DT,oBAAoB;IACpBC,uBAAuB;IACvB,GAAGE;GACN;AACL;AAgBA,SAASC,iBAAiBA,CACtBb,SAAkB,EAClBC,UAAuD,EACvDC,SAAsD;QAsMvCmB,WAAW,aAACC,QAA4BJ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;AACL;AAEA,SAAShG,uBAAuBA;;EAE5B,MAAMuH,uBAAuB,GAAG7H,cAAK,CAAC8H,MAAM,CAAqBjH,SAAS,CAAC;EAC3E,MAAMR,uBAAuB,GAAGL,cAAK,CAAC2E,WAAW,CAAEoD,KAAyB;IACxEF,uBAAuB,CAACZ,OAAO,GAAGc,KAAK;GAC1C,EAAE,EAAE,CAAC;EAEN,OAAO,CAACF,uBAAuB,CAACZ,OAAO,EAAE5G,uBAAuB,CAAC;AACrE;AAEA,SAAS0B,uBAAuBA,CAAkBP,OAA6B;;EAE3E,MAAM;IAAE6B,KAAK;IAAE,GAAG2E;GAAW,GAAGxG,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAI,EAAE;;EAE7C,OAAO;IAAE,IAAG6B,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAE2B,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 { 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 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 };\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 async function addCreatedRowChangeset(row) {\n const cells = row.getAllCells();\n\n setPendingChanges(currentChanges => {\n return cells.reduce((changes, cell) => {\n if (cell.getValue()) {\n return {\n ...changes,\n [cell.row.id]: {\n ...changes[cell.row.id],\n [cell.column.id]: cell.getValue(),\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 },\n };\n } else {\n return changes;\n }\n }, currentChanges);\n });\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 for (const rowId of changes) {\n const pendingChange = changesToSave[rowId];\n\n const changeSet = getChangesetFromChanges(pendingChange);\n try {\n if (getRowSaveStatus(rowId) === 'pending') return;\n\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 // 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 addCreatedRowChangeset,\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","useGlobalKeyDown","key","meta","shift","undefined","event","preventDefault","saveChanges","rowId","console","warn","Promise","resolve","changesToSave","pendingChanges","changes","Object","keys","length","_forOf","pendingChange","changeSet","getChangesetFromChanges","_catch","_temp3","_result","_exit","then","resetChanges","setRowSaveStatus","getRowSaveStatus","_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","addCreatedRowChangeset","getAllCells","reduce","getValue","_currentChanges$cell$4","_currentChanges$cell$5","_currentChanges$cell$6","original","moveReason","saveStates","setSaveState","getCellValue","_pendingChanges$cell$","getCellError","_pendingChanges$cell$2","_pendingChanges$cell$3","_pendingChanges$cell$4","setCellValue","useCallback","change","rowIndex","rowChanges","_currentChanges$cell$","_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","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","_error$pendingChange$","map","lastFocusedCellIndexRef","useRef","index","changeset"],"mappings":";;;;;SAOgBA,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;EAEpFY,gBAAgB,CAACd,SAAS,IAAIG,SAAS,GAAG;IAAEY,GAAG,EAAE,GAAG;IAAEC,IAAI,EAAE,IAAI;IAAEC,KAAK,EAAE;GAAO,GAAGC,SAAS,EAAEC,KAAK;IAC/FA,KAAK,CAACC,cAAc,EAAE;IACtBR,iBAAiB,CAACS,WAA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KAAuB,CAAC,CAAC;;EAG5F,SAASoB,YAAYA,CAACpB,KAAa;IAC/BkC,iBAAiB,CAACC,cAAc;MAC5B,MAAMC,WAAW,GAAG;QAAE,GAAGD;OAAgB;MACzC,OAAOC,WAAW,CAACpC,KAAK,CAAC;MACzB,OAAOoC,WAAW;KACrB,CAAC;;EA2EN,OAAO;IACHyB,YAAY;IACZE,YAAY;IACZI,YAAY;IACZtB,YAAY;IACZK,sBAAsB;IACtB6C,UAAU;IACVC,SAAS;IACTgB,SAAS;IACTjH,WAAW;IACXqB,YAAY;IACZ2D,YAAY;IACZM,gBAAgB;IAChBE,gBAAgB;IAChBjE,gBAAgB;IAChBD,gBAAgB;IAChBuE;GACH;AACL;AAEA,SAASvG,uBAAuBA;;EAE5B,MAAMgI,uBAAuB,GAAGtI,cAAK,CAACuI,MAAM,CAAqB1H,SAAS,CAAC;EAC3E,MAAMR,uBAAuB,GAAGL,cAAK,CAACqF,WAAW,CAAEmD,KAAyB;IACxEF,uBAAuB,CAACd,OAAO,GAAGgB,KAAK;GAC1C,EAAE,EAAE,CAAC;EAEN,OAAO,CAACF,uBAAuB,CAACd,OAAO,EAAEnH,uBAAuB,CAAC;AACrE;AAEA,SAAS0B,uBAAuBA,CAAkBP,OAA6B;;EAE3E,MAAM;IAAE8B,KAAK;IAAE,GAAGmF;GAAW,GAAGjH,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAI,EAAE;;EAE7C,OAAO;IAAE,IAAG8B,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEoB,QAAQ;IAAE,GAAG+D;GAAW;AAC/C;;;;"}
@@ -12,6 +12,7 @@ const RENDERERS = {
12
12
  };
13
13
  function useTable3(props, ref) {
14
14
  const editing = useTableEditing(props.enableEditing, props.onSave, props.validator);
15
+ const creationEnabled = editing.isEnabled && !!props.enableCreation;
15
16
  const extendedProps = {
16
17
  ...props,
17
18
  enableRowActions: editing.isEditing ? true : props.enableRowActions,
@@ -21,7 +22,7 @@ function useTable3(props, ref) {
21
22
  onClear: () => editing.resetChanges(rowId),
22
23
  onSave: () => editing.saveChanges(rowId),
23
24
  onExit: () => editing.toggleEditing(false),
24
- isLastRow: table.meta.rowActive.rowActiveIndex === table.meta.length - 1
25
+ isLastRow: !creationEnabled && table.meta.rowActive.rowActiveIndex === table.meta.length - 1
25
26
  }))] : props.rowActions
26
27
  };
27
28
  const meta = {
@@ -1 +1 @@
1
- {"version":3,"file":"useTable3.js","sources":["../../../../../../../src/components/Table3/useTable3.tsx"],"sourcesContent":["import React from 'react';\nimport { RowData } from '@tanstack/react-table';\nimport { useTable } from '../../primitives/Table/Core/useTable';\nimport { useTableEditingListener } from './listeners/useTableEditingListener';\nimport { useTableEditing } from './features/useTableEditing';\nimport { Table3Props, Table3Ref } from './types';\nimport { TableRowActionRenderer } from '../../primitives/Table/types';\nimport { Cell } from './components/Columns/Cell/Cell';\nimport { EditingActionMenu } from './components/Columns/Internal/EditingActionsMenu';\nimport { Row } from './components/Row/Row';\n\nconst RENDERERS = {\n row: Row,\n cell: Cell,\n};\n\ndeclare module '@tanstack/table-core' {\n interface TableMeta<TData extends RowData> {\n editing: ReturnType<typeof useTableEditing>;\n }\n}\n\ntype Table3Meta = {\n editing: ReturnType<typeof useTableEditing>;\n};\n\nexport function useTable3<TType>(props: Table3Props<TType>, ref: React.Ref<Table3Ref>) {\n const editing = useTableEditing(props.enableEditing, props.onSave, props.validator);\n const extendedProps: Table3Props<TType> = {\n ...props,\n enableRowActions: editing.isEditing ? true : props.enableRowActions,\n rowActions: editing.isEditing\n ? ([\n (_, rowId) => (\n <EditingActionMenu\n hasChanges={editing.hasChanges(rowId)}\n hasErrors={editing.hasRowErrors(rowId)}\n onClear={() => editing.resetChanges(rowId)}\n onSave={() => editing.saveChanges(rowId)}\n onExit={() => editing.toggleEditing(false)}\n isLastRow={table.meta.rowActive.rowActiveIndex === table.meta.length - 1}\n />\n ),\n ] as TableRowActionRenderer<TType>[])\n : props.rowActions,\n };\n const meta = { editing };\n const table = useTable<TType, Table3Meta>(extendedProps, ref, RENDERERS, meta);\n\n // listeners\n useTableEditingListener<TType>(table.instance, table.ref);\n\n React.useEffect(() => {\n if (table.ref.current) {\n (table.ref.current as Table3Ref).instance.toggleEditing = (enabled: boolean | undefined) =>\n table.meta.editing.toggleEditing(enabled ?? (editing => !editing));\n }\n }, [table.ref.current]);\n\n return table;\n}\n"],"names":["RENDERERS","row","Row","cell","Cell","useTable3","props","ref","editing","useTableEditing","enableEditing","onSave","validator","extendedProps","enableRowActions","isEditing","rowActions","_","rowId","React","EditingActionMenu","hasChanges","hasErrors","hasRowErrors","onClear","resetChanges","saveChanges","onExit","toggleEditing","isLastRow","table","meta","rowActive","rowActiveIndex","length","useTable","useTableEditingListener","instance","useEffect","current","enabled"],"mappings":";;;;;;;;AAWA,MAAMA,SAAS,GAAG;EACdC,GAAG,EAAEC,GAAG;EACRC,IAAI,EAAEC;CACT;SAYeC,SAASA,CAAQC,KAAyB,EAAEC,GAAyB;EACjF,MAAMC,OAAO,GAAGC,eAAe,CAACH,KAAK,CAACI,aAAa,EAAEJ,KAAK,CAACK,MAAM,EAAEL,KAAK,CAACM,SAAS,CAAC;EACnF,MAAMC,aAAa,GAAuB;IACtC,GAAGP,KAAK;IACRQ,gBAAgB,EAAEN,OAAO,CAACO,SAAS,GAAG,IAAI,GAAGT,KAAK,CAACQ,gBAAgB;IACnEE,UAAU,EAAER,OAAO,CAACO,SAAS,GACtB,CACG,CAACE,CAAC,EAAEC,KAAK,oBACLC,6BAACC,iBAAiB;MACdC,UAAU,EAAEb,OAAO,CAACa,UAAU,CAACH,KAAK,CAAC;MACrCI,SAAS,EAAEd,OAAO,CAACe,YAAY,CAACL,KAAK,CAAC;MACtCM,OAAO,EAAEA,MAAMhB,OAAO,CAACiB,YAAY,CAACP,KAAK,CAAC;MAC1CP,MAAM,EAAEA,MAAMH,OAAO,CAACkB,WAAW,CAACR,KAAK,CAAC;MACxCS,MAAM,EAAEA,MAAMnB,OAAO,CAACoB,aAAa,CAAC,KAAK,CAAC;MAC1CC,SAAS,EAAEC,KAAK,CAACC,IAAI,CAACC,SAAS,CAACC,cAAc,KAAKH,KAAK,CAACC,IAAI,CAACG,MAAM,GAAG;MACzE,CACL,CACgC,GACrC5B,KAAK,CAACU;GACf;EACD,MAAMe,IAAI,GAAG;IAAEvB;GAAS;EACxB,MAAMsB,KAAK,GAAGK,QAAQ,CAAoBtB,aAAa,EAAEN,GAAG,EAAEP,SAAS,EAAE+B,IAAI,CAAC;;EAG9EK,uBAAuB,CAAQN,KAAK,CAACO,QAAQ,EAAEP,KAAK,CAACvB,GAAG,CAAC;EAEzDY,cAAK,CAACmB,SAAS,CAAC;IACZ,IAAIR,KAAK,CAACvB,GAAG,CAACgC,OAAO,EAAE;MAClBT,KAAK,CAACvB,GAAG,CAACgC,OAAqB,CAACF,QAAQ,CAACT,aAAa,GAAIY,OAA4B,IACnFV,KAAK,CAACC,IAAI,CAACvB,OAAO,CAACoB,aAAa,CAACY,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAKhC,OAAO,IAAI,CAACA,OAAQ,CAAC;;GAE7E,EAAE,CAACsB,KAAK,CAACvB,GAAG,CAACgC,OAAO,CAAC,CAAC;EAEvB,OAAOT,KAAK;AAChB;;;;"}
1
+ {"version":3,"file":"useTable3.js","sources":["../../../../../../../src/components/Table3/useTable3.tsx"],"sourcesContent":["import React from 'react';\nimport { RowData } from '@tanstack/react-table';\nimport { useTable } from '../../primitives/Table/Core/useTable';\nimport { useTableEditingListener } from './listeners/useTableEditingListener';\nimport { useTableEditing } from './features/useTableEditing';\nimport { Table3Props, Table3Ref } from './types';\nimport { TableRowActionRenderer } from '../../primitives/Table/types';\nimport { Cell } from './components/Columns/Cell/Cell';\nimport { EditingActionMenu } from './components/Columns/Internal/EditingActionsMenu';\nimport { Row } from './components/Row/Row';\n\nconst RENDERERS = {\n row: Row,\n cell: Cell,\n};\n\ndeclare module '@tanstack/table-core' {\n interface TableMeta<TData extends RowData> {\n editing: ReturnType<typeof useTableEditing>;\n }\n}\n\ntype Table3Meta = {\n editing: ReturnType<typeof useTableEditing>;\n};\n\nexport function useTable3<TType>(props: Table3Props<TType>, ref: React.Ref<Table3Ref>) {\n const editing = useTableEditing(props.enableEditing, props.onSave, props.validator);\n const creationEnabled = editing.isEnabled && !!props.enableCreation;\n\n const extendedProps: Table3Props<TType> = {\n ...props,\n enableRowActions: editing.isEditing ? true : props.enableRowActions,\n rowActions: editing.isEditing\n ? ([\n (_, rowId) => (\n <EditingActionMenu\n hasChanges={editing.hasChanges(rowId)}\n hasErrors={editing.hasRowErrors(rowId)}\n onClear={() => editing.resetChanges(rowId)}\n onSave={() => editing.saveChanges(rowId)}\n onExit={() => editing.toggleEditing(false)}\n isLastRow={!creationEnabled && table.meta.rowActive.rowActiveIndex === table.meta.length - 1}\n />\n ),\n ] as TableRowActionRenderer<TType>[])\n : props.rowActions,\n };\n const meta = { editing };\n const table = useTable<TType, Table3Meta>(extendedProps, ref, RENDERERS, meta);\n\n // listeners\n useTableEditingListener<TType>(table.instance, table.ref);\n\n React.useEffect(() => {\n if (table.ref.current) {\n (table.ref.current as Table3Ref).instance.toggleEditing = (enabled: boolean | undefined) =>\n table.meta.editing.toggleEditing(enabled ?? (editing => !editing));\n }\n }, [table.ref.current]);\n\n return table;\n}\n"],"names":["RENDERERS","row","Row","cell","Cell","useTable3","props","ref","editing","useTableEditing","enableEditing","onSave","validator","creationEnabled","isEnabled","enableCreation","extendedProps","enableRowActions","isEditing","rowActions","_","rowId","React","EditingActionMenu","hasChanges","hasErrors","hasRowErrors","onClear","resetChanges","saveChanges","onExit","toggleEditing","isLastRow","table","meta","rowActive","rowActiveIndex","length","useTable","useTableEditingListener","instance","useEffect","current","enabled"],"mappings":";;;;;;;;AAWA,MAAMA,SAAS,GAAG;EACdC,GAAG,EAAEC,GAAG;EACRC,IAAI,EAAEC;CACT;SAYeC,SAASA,CAAQC,KAAyB,EAAEC,GAAyB;EACjF,MAAMC,OAAO,GAAG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Q,CAACT,aAAa,GAAIY,OAA4B,IACnFV,KAAK,CAACC,IAAI,CAAC1B,OAAO,CAACuB,aAAa,CAACY,OAAO,aAAPA,OAAO,cAAPA,OAAO,GAAKnC,OAAO,IAAI,CAACA,OAAQ,CAAC;;GAE7E,EAAE,CAACyB,KAAK,CAAC1B,GAAG,CAACmC,OAAO,CAAC,CAAC;EAEvB,OAAOT,KAAK;AAChB;;;;"}
@@ -64,6 +64,25 @@ function willRowMoveAfterSorting(cell, change, rowIndex) {
64
64
  }
65
65
  return ((_resortedRows$index = resortedRows[index]) === null || _resortedRows$index === void 0 ? void 0 : _resortedRows$index.id) !== cell.row.id;
66
66
  }
67
+ function animateCreateRow(id) {
68
+ const templateRow = document.querySelector(`[data-row-id="${id}"]`);
69
+ if (templateRow) {
70
+ var _templateRow$querySel;
71
+ (_templateRow$querySel = templateRow.querySelector(':first-child')) === null || _templateRow$querySel === void 0 ? void 0 : _templateRow$querySel.focus();
72
+ templateRow.scrollIntoView();
73
+ const keyframes = [{
74
+ background: '#b2c7ef'
75
+ }, {
76
+ background: '#ebebeb'
77
+ }];
78
+ for (const child of templateRow.children) {
79
+ child.animate(keyframes, {
80
+ duration: 1000,
81
+ easing: 'ease-out'
82
+ });
83
+ }
84
+ }
85
+ }
67
86
 
68
- export { willRowMove };
87
+ export { animateCreateRow, willRowMove };
69
88
  //# sourceMappingURL=editing.js.map