@economic/taco 2.46.4 → 2.46.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js +5 -3
- package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map +1 -1
- package/dist/taco.cjs.development.js +5 -3
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/package.json +2 -2
@@ -13,11 +13,13 @@ function useTableEditingListener(table, tableRef, scrollToIndex) {
|
|
13
13
|
// store the last row active index, otherwise everytime tableMeta.editing.saveChanges changes the hook runs again
|
14
14
|
const lastRowActiveIndexRef = React__default.useRef(tableMeta.rowActive.rowActiveIndex);
|
15
15
|
useLazyEffect(() => {
|
16
|
-
if (tableMeta.
|
16
|
+
if (tableMeta.rowActive.rowActiveIndex !== lastRowActiveIndexRef.current) {
|
17
17
|
lastRowActiveIndexRef.current = tableMeta.rowActive.rowActiveIndex;
|
18
|
-
tableMeta.editing.
|
18
|
+
if (tableMeta.editing.isEditing && lastRowActiveIndexRef.current !== undefined) {
|
19
|
+
tableMeta.editing.saveChanges(table);
|
20
|
+
}
|
19
21
|
}
|
20
|
-
}, [tableMeta.rowActive.rowActiveIndex
|
22
|
+
}, [tableMeta.rowActive.rowActiveIndex]);
|
21
23
|
// show a warning if the user navigates away without triggering save, such as using the browser back/forward button
|
22
24
|
const hasChanges = tableMeta.editing.hasChanges();
|
23
25
|
React__default.useEffect(() => {
|
package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTableEditingListener.js","sources":["../../../../../../../../src/components/Table3/listeners/useTableEditingListener.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { useLazyEffect } from '../../../hooks/useLazyEffect';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../utils/dom';\nimport { TableRef } from '../../../primitives/Table/types';\nimport { resetHighlightedColumnIndexes } from '../../../primitives/Table/useTableManager/util/search';\nimport { useLocalization } from '../../Provider/Localization';\nimport { useGlobalKeyDown } from '../../../hooks/useGlobalKeyDown';\nimport { shortcut } from '../util/editing';\n\nexport function useTableEditingListener<TType = unknown>(\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n scrollToIndex: (index: number) => void\n) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const localization = useLocalization();\n\n // save when the row changes\n // store the last row active index, otherwise everytime tableMeta.editing.saveChanges changes the hook runs again\n const lastRowActiveIndexRef = React.useRef<number | undefined>(tableMeta.rowActive.rowActiveIndex);\n\n useLazyEffect(() => {\n if (
|
1
|
+
{"version":3,"file":"useTableEditingListener.js","sources":["../../../../../../../../src/components/Table3/listeners/useTableEditingListener.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { useLazyEffect } from '../../../hooks/useLazyEffect';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../utils/dom';\nimport { TableRef } from '../../../primitives/Table/types';\nimport { resetHighlightedColumnIndexes } from '../../../primitives/Table/useTableManager/util/search';\nimport { useLocalization } from '../../Provider/Localization';\nimport { useGlobalKeyDown } from '../../../hooks/useGlobalKeyDown';\nimport { shortcut } from '../util/editing';\n\nexport function useTableEditingListener<TType = unknown>(\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n scrollToIndex: (index: number) => void\n) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const localization = useLocalization();\n\n // save when the row changes\n // store the last row active index, otherwise everytime tableMeta.editing.saveChanges changes the hook runs again\n const lastRowActiveIndexRef = React.useRef<number | undefined>(tableMeta.rowActive.rowActiveIndex);\n\n useLazyEffect(() => {\n if (tableMeta.rowActive.rowActiveIndex !== lastRowActiveIndexRef.current) {\n lastRowActiveIndexRef.current = tableMeta.rowActive.rowActiveIndex;\n\n if (tableMeta.editing.isEditing && lastRowActiveIndexRef.current !== undefined) {\n tableMeta.editing.saveChanges(table);\n }\n }\n }, [tableMeta.rowActive.rowActiveIndex]);\n\n // show a warning if the user navigates away without triggering save, such as using the browser back/forward button\n const hasChanges = tableMeta.editing.hasChanges();\n\n React.useEffect(() => {\n function showUnsavedChangesWarning(event: BeforeUnloadEvent) {\n if (tableMeta.editing.isEditing && hasChanges) {\n event.returnValue = true;\n return true;\n }\n\n return false;\n }\n\n window.addEventListener('beforeunload', showUnsavedChangesWarning);\n\n return () => {\n window.removeEventListener('beforeunload', showUnsavedChangesWarning);\n };\n }, [tableMeta.editing.isEditing, hasChanges]);\n\n const hasSavedChanges = tableMeta.editing.hasSaved();\n\n useLazyEffect(() => {\n if (hasSavedChanges) {\n resetHighlightedColumnIndexes(table.getState().globalFilter, table, localization);\n }\n }, [hasSavedChanges]);\n\n React.useEffect(() => {\n const onClickOutside = (event: MouseEvent) => {\n if (tableMeta.editing.isEditing) {\n const element = event.target as Element;\n const insideTable =\n element.getAttribute('data-taco') === 'backdrop' ||\n element.getAttribute('data-table') === 'editing-toggle' ||\n isElementInsideOrTriggeredFromContainer(element, tableRef.current);\n\n // users can click the white space below rows which could be inside the table, but a valid scenario to save\n if (!insideTable || element.tagName === 'TABLE' || element.tagName === 'TBODY') {\n tableMeta.editing.saveChanges(table);\n }\n }\n };\n\n document.addEventListener('click', onClickOutside);\n\n return () => document.removeEventListener('click', onClickOutside);\n }, [tableMeta.editing.isEditing, tableMeta.editing.saveChanges]);\n\n const rows = table.getRowModel().rows;\n\n // make sure pending changes are removed for rows that no longer exist\n useLazyEffect(() => {\n const pendingChanges = tableMeta.editing.getErrorsShownInAlert();\n\n pendingChanges.forEach(pendingChange => {\n try {\n table.getRow(pendingChange.rowId);\n } catch {\n tableMeta.editing.discardChanges(pendingChange.rowId, table);\n }\n });\n }, [rows.length]);\n\n // shortcuts\n useGlobalKeyDown(tableMeta.editing.isEnabled ? shortcut : undefined, (event: KeyboardEvent) => {\n event.preventDefault();\n tableMeta.editing.toggleEditing(!tableMeta.editing.isEditing, table, scrollToIndex);\n });\n\n useGlobalKeyDown(tableMeta.editing.isEditing ? { key: 's', meta: true, shift: false } : undefined, event => {\n event.preventDefault();\n tableMeta.editing.saveChanges(table);\n });\n}\n"],"names":["useTableEditingListener","table","tableRef","scrollToIndex","tableMeta","options","meta","localization","useLocalization","lastRowActiveIndexRef","React","useRef","rowActive","rowActiveIndex","useLazyEffect","current","editing","isEditing","undefined","saveChanges","hasChanges","useEffect","showUnsavedChangesWarning","event","returnValue","window","addEventListener","removeEventListener","hasSavedChanges","hasSaved","resetHighlightedColumnIndexes","getState","globalFilter","onClickOutside","element","target","insideTable","getAttribute","isElementInsideOrTriggeredFromContainer","tagName","document","rows","getRowModel","pendingChanges","getErrorsShownInAlert","forEach","pendingChange","getRow","rowId","discardChanges","length","useGlobalKeyDown","isEnabled","shortcut","preventDefault","toggleEditing","key","shift"],"mappings":";;;;;;;;SAUgBA,uBAAuBA,CACnCC,KAAwB,EACxBC,QAAmC,EACnCC,aAAsC;EAEtC,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,YAAY,GAAGC,eAAe,EAAE;;;EAItC,MAAMC,qBAAqB,GAAGC,cAAK,CAACC,MAAM,CAAqBP,SAAS,CAACQ,SAAS,CAACC,cAAc,CAAC;EAElGC,aAAa,CAAC;IACV,IAAIV,SAAS,CAACQ,SAAS,CAACC,cAAc,KAAKJ,qBAAqB,CAACM,OAAO,EAAE;MACtEN,qBAAqB,CAACM,OAAO,GAAGX,SAAS,CAACQ,SAAS,CAACC,cAAc;MAElE,IAAIT,SAAS,CAACY,OAAO,CAACC,SAAS,IAAIR,qBAAqB,CAACM,OAAO,KAAKG,SAAS,EAAE;QAC5Ed,SAAS,CAACY,OAAO,CAACG,WAAW,CAAClB,KAAK,CAAC;;;GAG/C,EAAE,CAACG,SAAS,CAACQ,SAAS,CAACC,cAAc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,CAAC;GACvC,CAAC;AACN;;;;"}
|
@@ -18473,11 +18473,13 @@ function useTableEditingListener(table, tableRef, scrollToIndex) {
|
|
18473
18473
|
// store the last row active index, otherwise everytime tableMeta.editing.saveChanges changes the hook runs again
|
18474
18474
|
const lastRowActiveIndexRef = React__default.useRef(tableMeta.rowActive.rowActiveIndex);
|
18475
18475
|
useLazyEffect(() => {
|
18476
|
-
if (tableMeta.
|
18476
|
+
if (tableMeta.rowActive.rowActiveIndex !== lastRowActiveIndexRef.current) {
|
18477
18477
|
lastRowActiveIndexRef.current = tableMeta.rowActive.rowActiveIndex;
|
18478
|
-
tableMeta.editing.
|
18478
|
+
if (tableMeta.editing.isEditing && lastRowActiveIndexRef.current !== undefined) {
|
18479
|
+
tableMeta.editing.saveChanges(table);
|
18480
|
+
}
|
18479
18481
|
}
|
18480
|
-
}, [tableMeta.rowActive.rowActiveIndex
|
18482
|
+
}, [tableMeta.rowActive.rowActiveIndex]);
|
18481
18483
|
// show a warning if the user navigates away without triggering save, such as using the browser back/forward button
|
18482
18484
|
const hasChanges = tableMeta.editing.hasChanges();
|
18483
18485
|
React__default.useEffect(() => {
|