@economic/taco 1.1.4 → 1.1.5-alpha.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -82
- package/dist/components/Icon/components/LogOut.d.ts +3 -0
- package/dist/components/Icon/components/Menu.d.ts +3 -0
- package/dist/components/Icon/components/Numbers.d.ts +3 -0
- package/dist/components/Icon/components/Profile.d.ts +3 -0
- package/dist/components/Icon/components/index.d.ts +1 -1
- package/dist/components/Input/Input.d.ts +1 -1
- package/dist/components/Menu/Menu.d.ts +2 -2
- package/dist/components/Menu/components/Item.d.ts +1 -1
- package/dist/components/Menu/components/Link.d.ts +1 -1
- package/dist/components/Tour/Tour.d.ts +2 -0
- package/dist/esm/components/Banner/util.js +1 -1
- package/dist/esm/components/Banner/util.js.map +1 -1
- package/dist/esm/components/Button/util.js +18 -23
- package/dist/esm/components/Button/util.js.map +1 -1
- package/dist/esm/components/Card/Card.js +3 -0
- package/dist/esm/components/Card/Card.js.map +1 -1
- package/dist/esm/components/Combobox/Combobox.js +1 -0
- package/dist/esm/components/Combobox/Combobox.js.map +1 -1
- package/dist/esm/components/Combobox/useCombobox.js +67 -87
- package/dist/esm/components/Combobox/useCombobox.js.map +1 -1
- package/dist/esm/components/Datepicker/useDatepicker.js +27 -34
- package/dist/esm/components/Datepicker/useDatepicker.js.map +1 -1
- package/dist/esm/components/Dialog/Context.js +4 -4
- package/dist/esm/components/Dialog/Context.js.map +1 -1
- package/dist/esm/components/Dialog/components/Content.js +39 -44
- package/dist/esm/components/Dialog/components/Content.js.map +1 -1
- package/dist/esm/components/Dialog/components/Drawer.js +3 -3
- package/dist/esm/components/Dialog/components/Drawer.js.map +1 -1
- package/dist/esm/components/Dialog/components/Extra.js +2 -2
- package/dist/esm/components/Dialog/components/Extra.js.map +1 -1
- package/dist/esm/components/Dialog/components/Trigger.js +3 -3
- package/dist/esm/components/Dialog/components/Trigger.js.map +1 -1
- package/dist/esm/components/Hanger/Hanger.js +1 -1
- package/dist/esm/components/Hanger/Hanger.js.map +1 -1
- package/dist/esm/components/Icon/components/LogOut.js +20 -0
- package/dist/esm/components/Icon/components/LogOut.js.map +1 -0
- package/dist/esm/components/Icon/components/Menu.js +18 -0
- package/dist/esm/components/Icon/components/Menu.js.map +1 -0
- package/dist/esm/components/Icon/components/Numbers.js +18 -0
- package/dist/esm/components/Icon/components/Numbers.js.map +1 -0
- package/dist/esm/components/Icon/components/Profile.js +20 -0
- package/dist/esm/components/Icon/components/Profile.js.map +1 -0
- package/dist/esm/components/Icon/components/index.js +12 -4
- package/dist/esm/components/Icon/components/index.js.map +1 -1
- package/dist/esm/components/Input/util.js +2 -2
- package/dist/esm/components/Input/util.js.map +1 -1
- package/dist/esm/components/Listbox/ScrollableList.js +64 -83
- package/dist/esm/components/Listbox/ScrollableList.js.map +1 -1
- package/dist/esm/components/Listbox/useListbox.js +51 -60
- package/dist/esm/components/Listbox/useListbox.js.map +1 -1
- package/dist/esm/components/Listbox/useMultiListbox.js +64 -91
- package/dist/esm/components/Listbox/useMultiListbox.js.map +1 -1
- package/dist/esm/components/Listbox/useTypeahead.js +10 -9
- package/dist/esm/components/Listbox/useTypeahead.js.map +1 -1
- package/dist/esm/components/Listbox/util.js +48 -85
- package/dist/esm/components/Listbox/util.js.map +1 -1
- package/dist/esm/components/Menu/Context.js +2 -2
- package/dist/esm/components/Menu/Context.js.map +1 -1
- package/dist/esm/components/Menu/components/Checkbox.js +9 -10
- package/dist/esm/components/Menu/components/Checkbox.js.map +1 -1
- package/dist/esm/components/Menu/components/Content.js +9 -11
- package/dist/esm/components/Menu/components/Content.js.map +1 -1
- package/dist/esm/components/Menu/components/Header.js +3 -3
- package/dist/esm/components/Menu/components/Header.js.map +1 -1
- package/dist/esm/components/Menu/components/Item.js +30 -31
- package/dist/esm/components/Menu/components/Item.js.map +1 -1
- package/dist/esm/components/Menu/components/Link.js +10 -11
- package/dist/esm/components/Menu/components/Link.js.map +1 -1
- package/dist/esm/components/Menu/components/RadioGroup.js +17 -19
- package/dist/esm/components/Menu/components/RadioGroup.js.map +1 -1
- package/dist/esm/components/Menu/components/Separator.js +1 -1
- package/dist/esm/components/Menu/components/Separator.js.map +1 -1
- package/dist/esm/components/Menu/components/Trigger.js +4 -4
- package/dist/esm/components/Menu/components/Trigger.js.map +1 -1
- package/dist/esm/components/Pagination/PageNumbers.js +23 -28
- package/dist/esm/components/Pagination/PageNumbers.js.map +1 -1
- package/dist/esm/components/Pagination/usePagination.js +7 -21
- package/dist/esm/components/Pagination/usePagination.js.map +1 -1
- package/dist/esm/components/Pagination/usePaginationShortcuts.js +9 -9
- package/dist/esm/components/Pagination/usePaginationShortcuts.js.map +1 -1
- package/dist/esm/components/Popover/Popover.js +1 -1
- package/dist/esm/components/Popover/Popover.js.map +1 -1
- package/dist/esm/components/Popover/Primitives.js +7 -8
- package/dist/esm/components/Popover/Primitives.js.map +1 -1
- package/dist/esm/components/SearchInput/SearchInput.js +4 -1
- package/dist/esm/components/SearchInput/SearchInput.js.map +1 -1
- package/dist/esm/components/Select/useSelect.js +63 -81
- package/dist/esm/components/Select/useSelect.js.map +1 -1
- package/dist/esm/components/Table/components/BaseTable.js +23 -30
- package/dist/esm/components/Table/components/BaseTable.js.map +1 -1
- package/dist/esm/components/Table/components/PaginatedTable.js +3 -7
- package/dist/esm/components/Table/components/PaginatedTable.js.map +1 -1
- package/dist/esm/components/Table/components/Table.js +18 -25
- package/dist/esm/components/Table/components/Table.js.map +1 -1
- package/dist/esm/components/Table/components/WindowedTable.js +89 -109
- package/dist/esm/components/Table/components/WindowedTable.js.map +1 -1
- package/dist/esm/components/Table/hooks/plugins/useRowActions.js +122 -146
- package/dist/esm/components/Table/hooks/plugins/useRowActions.js.map +1 -1
- package/dist/esm/components/Table/hooks/plugins/useRowDraggable.js +57 -61
- package/dist/esm/components/Table/hooks/plugins/useRowDraggable.js.map +1 -1
- package/dist/esm/components/Table/hooks/plugins/useRowEditing.js +39 -36
- package/dist/esm/components/Table/hooks/plugins/useRowEditing.js.map +1 -1
- package/dist/esm/components/Table/hooks/plugins/useRowSelect.js +79 -89
- package/dist/esm/components/Table/hooks/plugins/useRowSelect.js.map +1 -1
- package/dist/esm/components/Table/hooks/useRowCreation.js +29 -64
- package/dist/esm/components/Table/hooks/useRowCreation.js.map +1 -1
- package/dist/esm/components/Table/hooks/useTable.js +119 -141
- package/dist/esm/components/Table/hooks/useTable.js.map +1 -1
- package/dist/esm/components/Table/hooks/useTableKeyboardNavigation.js +13 -16
- package/dist/esm/components/Table/hooks/useTableKeyboardNavigation.js.map +1 -1
- package/dist/esm/components/Table/util/renderColumn.js +10 -10
- package/dist/esm/components/Table/util/renderColumn.js.map +1 -1
- package/dist/esm/components/Table/util/renderRow.js +37 -46
- package/dist/esm/components/Table/util/renderRow.js.map +1 -1
- package/dist/esm/components/Table/util/rowIndexPath.js +14 -16
- package/dist/esm/components/Table/util/rowIndexPath.js.map +1 -1
- package/dist/esm/components/Table/util/sortTypes.js +23 -31
- package/dist/esm/components/Table/util/sortTypes.js.map +1 -1
- package/dist/esm/components/Table/util.js +29 -41
- package/dist/esm/components/Table/util.js.map +1 -1
- package/dist/esm/components/Toast/Toast.js +21 -22
- package/dist/esm/components/Toast/Toast.js.map +1 -1
- package/dist/esm/components/Toast/util.js +2 -2
- package/dist/esm/components/Toast/util.js.map +1 -1
- package/dist/esm/components/Tour/Tour.js +3 -1
- package/dist/esm/components/Tour/Tour.js.map +1 -1
- package/dist/esm/index.css +661 -661
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/primitives/Button.js +9 -13
- package/dist/esm/primitives/Button.js.map +1 -1
- package/dist/esm/utils/date.js.map +1 -1
- package/dist/esm/utils/hooks/useBoundingClientRectListener.js.map +1 -1
- package/dist/esm/utils/hooks/useDraggable.js +16 -17
- package/dist/esm/utils/hooks/useDraggable.js.map +1 -1
- package/dist/esm/utils/hooks/useDropTarget.js.map +1 -1
- package/dist/esm/utils/hooks/useListKeyboardNavigation.js.map +1 -1
- package/dist/esm/utils/hooks/useListScrollTo.js.map +1 -1
- package/dist/esm/utils/hooks/useOnClickOutside.js.map +1 -1
- package/dist/esm/utils/hooks/useProxiedRef.js.map +1 -1
- package/dist/esm/utils/hooks/useTimer.js +9 -17
- package/dist/esm/utils/hooks/useTimer.js.map +1 -1
- package/dist/esm/utils/input.js +7 -11
- package/dist/esm/utils/input.js.map +1 -1
- package/dist/esm/utils/mergeRefs.js +1 -1
- package/dist/esm/utils/mergeRefs.js.map +1 -1
- package/dist/esm/utils/taillwind.js +2 -2
- package/dist/esm/utils/taillwind.js.map +1 -1
- package/dist/index.css +661 -661
- package/dist/index.d.ts +4 -1
- package/dist/taco.cjs.development.js +1566 -1823
- 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/dist/utils/mergeRefs.d.ts +1 -1
- package/package.json +6 -7
- package/plugins/tailwindcss-aria-attributes.js +73 -73
- package/tailwind.config.js +9 -0
- package/types.json +2612 -7006
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useRowDraggable.js","sources":["../../../../../../src/components/Table/hooks/plugins/useRowDraggable.tsx"],"sourcesContent":["import React from 'react';\nimport { actions, PluginHook } from 'react-table';\nimport { Icon } from '../../../Icon/Icon';\nimport { RowDragHandler } from '../../types';\nimport { sanitizeRowProps } from '../../util';\n\nconst pluginName = 'useRowDraggable';\n\nactions.resetRowDragging = 'resetRowDragging';\nactions.toggleRowDragging = 'toggleRowDragging';\n\nfunction reducer(state: any, action: any): object {\n if (action.type === actions.init) {\n return {\n draggingRowIndexPath: null,\n ...state,\n };\n }\n\n if (action.type === actions.resetRowDragging) {\n return {\n ...state,\n draggingRowIndexPath: null,\n };\n }\n\n if (action.type === actions.toggleRowDragging) {\n const { indexPath } = action;\n return {\n ...state,\n draggingRowIndexPath: indexPath,\n };\n }\n\n return state;\n}\n\nconst prepareRow = (row: any, { instance }: any): void => {\n row.toggleRowDragging = () => {\n if (instance.state.draggingRowIndexPath === row.id) {\n instance.dispatch({ type: actions.resetRowDragging });\n } else {\n instance.dispatch({ type: actions.toggleRowDragging, indexPath: row.id });\n }\n };\n\n if (instance.state.draggingRowIndexPath) {\n row.isDragging = instance.state.draggingRowIndexPath === row.id || !!instance.state.selectedRowIds?.[row.id];\n } else {\n row.isDragging = false;\n }\n};\n\nconst visibleColumns = (columns: any) => {\n return [\n {\n id: 'draggable',\n className: 'yt-table__cell--draggable flex-col px-0',\n Cell: () => <Icon name=\"drag\" className=\"text-grey-darkest invisible w-[20px] cursor-grab\" />,\n flex: '0 0 20px',\n },\n ...columns,\n ];\n};\n\nconst getRowProps =\n (onRowDrag: RowDragHandler<any>) =>\n (props: any, { instance, row }: any) => {\n const onDragStart = (event: React.DragEvent): void => {\n event.persist();\n row.toggleRowDragging();\n\n const indexPaths = [row.id, ...Object.keys(instance.state.selectedRowIds)];\n const data = instance.rows.filter((r: any) => indexPaths.includes(r.id)).map(sanitizeRowProps);\n\n const showPlaceholder = (placeholder: string) => {\n const element = window.document.createElement('div');\n element.id = 'yt-table__drag__placeholder';\n element.innerText = placeholder;\n window.document.body.appendChild(element);\n\n if (typeof DataTransfer.prototype.setDragImage === 'function') {\n event.dataTransfer.setDragImage(element, 0, 20);\n }\n };\n\n onRowDrag(data, showPlaceholder, event);\n };\n\n const onDragEnd = (): void => {\n const element: HTMLElement | null = document.getElementById('yt-table__drag__placeholder');\n\n if (element && element.parentNode) {\n element.parentNode.removeChild(element);\n }\n\n row.toggleRowDragging();\n };\n\n return [\n props,\n {\n draggable: true,\n onDragStart,\n onDragEnd,\n },\n ];\n };\n\nexport const useRowDraggable = (onRowDrag: RowDragHandler<any> | undefined): PluginHook<{}> => {\n const plugin = (hooks: any): void => {\n if (onRowDrag) {\n hooks.stateReducers.push(reducer);\n hooks.prepareRow.push(prepareRow);\n hooks.visibleColumns.push(visibleColumns);\n hooks.getRowProps.push(getRowProps(onRowDrag));\n }\n };\n plugin.pluginName = pluginName;\n\n return plugin;\n};\n"],"names":["pluginName","actions","resetRowDragging","toggleRowDragging","reducer","state","action","type","init","draggingRowIndexPath","indexPath","prepareRow","row","instance","id","dispatch","isDragging","selectedRowIds","visibleColumns","columns","className","Cell","React","Icon","name","flex","getRowProps","onRowDrag","props","onDragStart","event","persist","indexPaths","Object","keys","data","rows","filter","r","includes","map","sanitizeRowProps","showPlaceholder","placeholder","element","window","document","createElement","innerText","body","appendChild","DataTransfer","prototype","setDragImage","dataTransfer","onDragEnd","getElementById","parentNode","removeChild","draggable","useRowDraggable","plugin","hooks","stateReducers","push"],"mappings":"
|
1
|
+
{"version":3,"file":"useRowDraggable.js","sources":["../../../../../../src/components/Table/hooks/plugins/useRowDraggable.tsx"],"sourcesContent":["import React from 'react';\nimport { actions, PluginHook } from 'react-table';\nimport { Icon } from '../../../Icon/Icon';\nimport { RowDragHandler } from '../../types';\nimport { sanitizeRowProps } from '../../util';\n\nconst pluginName = 'useRowDraggable';\n\nactions.resetRowDragging = 'resetRowDragging';\nactions.toggleRowDragging = 'toggleRowDragging';\n\nfunction reducer(state: any, action: any): object {\n if (action.type === actions.init) {\n return {\n draggingRowIndexPath: null,\n ...state,\n };\n }\n\n if (action.type === actions.resetRowDragging) {\n return {\n ...state,\n draggingRowIndexPath: null,\n };\n }\n\n if (action.type === actions.toggleRowDragging) {\n const { indexPath } = action;\n return {\n ...state,\n draggingRowIndexPath: indexPath,\n };\n }\n\n return state;\n}\n\nconst prepareRow = (row: any, { instance }: any): void => {\n row.toggleRowDragging = () => {\n if (instance.state.draggingRowIndexPath === row.id) {\n instance.dispatch({ type: actions.resetRowDragging });\n } else {\n instance.dispatch({ type: actions.toggleRowDragging, indexPath: row.id });\n }\n };\n\n if (instance.state.draggingRowIndexPath) {\n row.isDragging = instance.state.draggingRowIndexPath === row.id || !!instance.state.selectedRowIds?.[row.id];\n } else {\n row.isDragging = false;\n }\n};\n\nconst visibleColumns = (columns: any) => {\n return [\n {\n id: 'draggable',\n className: 'yt-table__cell--draggable flex-col px-0',\n Cell: () => <Icon name=\"drag\" className=\"text-grey-darkest invisible w-[20px] cursor-grab\" />,\n flex: '0 0 20px',\n },\n ...columns,\n ];\n};\n\nconst getRowProps =\n (onRowDrag: RowDragHandler<any>) =>\n (props: any, { instance, row }: any) => {\n const onDragStart = (event: React.DragEvent): void => {\n event.persist();\n row.toggleRowDragging();\n\n const indexPaths = [row.id, ...Object.keys(instance.state.selectedRowIds)];\n const data = instance.rows.filter((r: any) => indexPaths.includes(r.id)).map(sanitizeRowProps);\n\n const showPlaceholder = (placeholder: string) => {\n const element = window.document.createElement('div');\n element.id = 'yt-table__drag__placeholder';\n element.innerText = placeholder;\n window.document.body.appendChild(element);\n\n if (typeof DataTransfer.prototype.setDragImage === 'function') {\n event.dataTransfer.setDragImage(element, 0, 20);\n }\n };\n\n onRowDrag(data, showPlaceholder, event);\n };\n\n const onDragEnd = (): void => {\n const element: HTMLElement | null = document.getElementById('yt-table__drag__placeholder');\n\n if (element && element.parentNode) {\n element.parentNode.removeChild(element);\n }\n\n row.toggleRowDragging();\n };\n\n return [\n props,\n {\n draggable: true,\n onDragStart,\n onDragEnd,\n },\n ];\n };\n\nexport const useRowDraggable = (onRowDrag: RowDragHandler<any> | undefined): PluginHook<{}> => {\n const plugin = (hooks: any): void => {\n if (onRowDrag) {\n hooks.stateReducers.push(reducer);\n hooks.prepareRow.push(prepareRow);\n hooks.visibleColumns.push(visibleColumns);\n hooks.getRowProps.push(getRowProps(onRowDrag));\n }\n };\n plugin.pluginName = pluginName;\n\n return plugin;\n};\n"],"names":["pluginName","actions","resetRowDragging","toggleRowDragging","reducer","state","action","type","init","draggingRowIndexPath","indexPath","prepareRow","row","instance","id","dispatch","isDragging","selectedRowIds","visibleColumns","columns","className","Cell","React","Icon","name","flex","getRowProps","onRowDrag","props","onDragStart","event","persist","indexPaths","Object","keys","data","rows","filter","r","includes","map","sanitizeRowProps","showPlaceholder","placeholder","element","window","document","createElement","innerText","body","appendChild","DataTransfer","prototype","setDragImage","dataTransfer","onDragEnd","getElementById","parentNode","removeChild","draggable","useRowDraggable","plugin","hooks","stateReducers","push"],"mappings":";;;;;AAMA,MAAMA,UAAU,GAAG,iBAAnB;AAEAC,OAAO,CAACC,gBAAR,GAA2B,kBAA3B;AACAD,OAAO,CAACE,iBAAR,GAA4B,mBAA5B;;AAEA,SAASC,OAAT,CAAiBC,KAAjB,EAA6BC,MAA7B;EACI,IAAIA,MAAM,CAACC,IAAP,KAAgBN,OAAO,CAACO,IAA5B,EAAkC;IAC9B,OAAO;MACHC,oBAAoB,EAAE,IADnB;MAEH,GAAGJ;KAFP;;;EAMJ,IAAIC,MAAM,CAACC,IAAP,KAAgBN,OAAO,CAACC,gBAA5B,EAA8C;IAC1C,OAAO,EACH,GAAGG,KADA;MAEHI,oBAAoB,EAAE;KAF1B;;;EAMJ,IAAIH,MAAM,CAACC,IAAP,KAAgBN,OAAO,CAACE,iBAA5B,EAA+C;IAC3C,MAAM;MAAEO;QAAcJ,MAAtB;IACA,OAAO,EACH,GAAGD,KADA;MAEHI,oBAAoB,EAAEC;KAF1B;;;EAMJ,OAAOL,KAAP;AACH;;AAED,MAAMM,UAAU,GAAG,CAACC,GAAD,EAAW;EAAEC;AAAF,CAAX;EACfD,GAAG,CAACT,iBAAJ,GAAwB;IACpB,IAAIU,QAAQ,CAACR,KAAT,CAAeI,oBAAf,KAAwCG,GAAG,CAACE,EAAhD,EAAoD;MAChDD,QAAQ,CAACE,QAAT,CAAkB;QAAER,IAAI,EAAEN,OAAO,CAACC;OAAlC;KADJ,MAEO;MACHW,QAAQ,CAACE,QAAT,CAAkB;QAAER,IAAI,EAAEN,OAAO,CAACE,iBAAhB;QAAmCO,SAAS,EAAEE,GAAG,CAACE;OAApE;;GAJR;;EAQA,IAAID,QAAQ,CAACR,KAAT,CAAeI,oBAAnB,EAAyC;IAAA;;IACrCG,GAAG,CAACI,UAAJ,GAAiBH,QAAQ,CAACR,KAAT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,IAAI,OAAOO,YAAY,CAACC,SAAb,CAAuBC,YAA9B,KAA+C,UAAnD,EAA+D;QAC3DvB,KAAK,CAACwB,YAAN,CAAmBD,YAAnB,CAAgCT,OAAhC,EAAyC,CAAzC,EAA4C,EAA5C;;KAPR;;IAWAjB,SAAS,CAACQ,IAAD,EAAOO,eAAP,EAAwBZ,KAAxB,CAAT;GAlBJ;;EAqBA,MAAMyB,SAAS,GAAG;IACd,MAAMX,OAAO,GAAuBE,QAAQ,CAACU,cAAT,CAAwB,6BAAxB,CAApC;;IAEA,IAAIZ,OAAO,IAAIA,OAAO,CAACa,UAAvB,EAAmC;MAC/Bb,OAAO,CAACa,UAAR,CAAmBC,WAAnB,CAA+Bd,OAA/B;;;IAGJhC,GAAG,CAACT,iBAAJ;GAPJ;;EAUA,OAAO,CACHyB,KADG,EAEH;IACI+B,SAAS,EAAE,IADf;IAEI9B,WAFJ;IAGI0B;GALD,CAAP;AAQH,CA1CL;;MA4CaK,eAAe,GAAIjC,SAAD;EAC3B,MAAMkC,MAAM,GAAIC,KAAD;IACX,IAAInC,SAAJ,EAAe;MACXmC,KAAK,CAACC,aAAN,CAAoBC,IAApB,CAAyB5D,OAAzB;MACA0D,KAAK,CAACnD,UAAN,CAAiBqD,IAAjB,CAAsBrD,UAAtB;MACAmD,KAAK,CAAC5C,cAAN,CAAqB8C,IAArB,CAA0B9C,cAA1B;MACA4C,KAAK,CAACpC,WAAN,CAAkBsC,IAAlB,CAAuBtC,WAAW,CAACC,SAAD,CAAlC;;GALR;;EAQAkC,MAAM,CAAC7D,UAAP,GAAoBA,UAApB;EAEA,OAAO6D,MAAP;AACH;;;;"}
|
@@ -1,87 +1,90 @@
|
|
1
|
-
import { extends as _extends } from '../../../../_virtual/_rollupPluginBabelHelpers.js';
|
2
1
|
import React__default from 'react';
|
3
2
|
import { actions } from 'react-table';
|
4
3
|
|
5
|
-
|
4
|
+
const pluginName = 'useRowEditing';
|
6
5
|
actions.resetRowEditing = 'resetRowEditing';
|
7
6
|
actions.toggleRowEditing = 'toggleRowEditing';
|
8
7
|
actions.toggleEditing = 'toggleEditing';
|
9
8
|
|
10
9
|
function reducer(state, action) {
|
11
10
|
if (action.type === actions.init) {
|
12
|
-
return
|
11
|
+
return {
|
13
12
|
allowEditing: true,
|
14
|
-
editingRowUniqueId: null
|
15
|
-
|
13
|
+
editingRowUniqueId: null,
|
14
|
+
...state
|
15
|
+
};
|
16
16
|
}
|
17
17
|
|
18
18
|
if (action.type === actions.resetRowEditing || action.type === actions.resetPage || action.type === actions.gotoPage) {
|
19
|
-
return
|
19
|
+
return { ...state,
|
20
20
|
editingRowUniqueId: null
|
21
|
-
}
|
21
|
+
};
|
22
22
|
}
|
23
23
|
|
24
24
|
if (action.type === actions.toggleRowEditing) {
|
25
|
-
|
26
|
-
|
25
|
+
const {
|
26
|
+
id
|
27
|
+
} = action;
|
28
|
+
return { ...state,
|
27
29
|
editingRowUniqueId: id
|
28
|
-
}
|
30
|
+
};
|
29
31
|
}
|
30
32
|
|
31
33
|
if (action.type === actions.toggleEditing) {
|
32
|
-
return
|
34
|
+
return { ...state,
|
33
35
|
allowEditing: !state.allowEditing
|
34
|
-
}
|
36
|
+
};
|
35
37
|
}
|
36
38
|
|
37
39
|
return state;
|
38
40
|
}
|
39
41
|
|
40
42
|
function useInstance(instance) {
|
41
|
-
|
42
|
-
|
43
|
+
const {
|
44
|
+
dispatch
|
45
|
+
} = instance;
|
46
|
+
const resetRowEditing = React__default.useCallback(() => {
|
43
47
|
dispatch({
|
44
48
|
type: actions.resetRowEditing
|
45
49
|
});
|
46
50
|
}, [dispatch]);
|
47
|
-
|
51
|
+
const toggleRowEditing = React__default.useCallback(id => {
|
48
52
|
dispatch({
|
49
53
|
type: actions.toggleRowEditing,
|
50
|
-
id
|
54
|
+
id
|
51
55
|
});
|
52
56
|
}, [dispatch]);
|
53
|
-
|
57
|
+
const toggleEditing = React__default.useCallback(() => {
|
54
58
|
dispatch({
|
55
59
|
type: actions.toggleEditing
|
56
60
|
});
|
57
61
|
}, [dispatch]);
|
58
62
|
Object.assign(instance, {
|
59
|
-
resetRowEditing
|
60
|
-
toggleRowEditing
|
61
|
-
toggleEditing
|
63
|
+
resetRowEditing,
|
64
|
+
toggleRowEditing,
|
65
|
+
toggleEditing
|
62
66
|
});
|
63
67
|
}
|
64
68
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
row.toggleRowEditing = function () {
|
71
|
-
if (instance.state.editingRowUniqueId === id) {
|
72
|
-
instance.resetRowEditing();
|
73
|
-
} else {
|
74
|
-
instance.toggleRowEditing(id);
|
75
|
-
}
|
76
|
-
};
|
69
|
+
const prepareRow = uniqueId => (row, {
|
70
|
+
instance
|
71
|
+
}) => {
|
72
|
+
const id = row.original[uniqueId];
|
77
73
|
|
78
|
-
|
79
|
-
|
74
|
+
row.toggleRowEditing = () => {
|
75
|
+
if (instance.state.editingRowUniqueId === id) {
|
76
|
+
instance.resetRowEditing();
|
77
|
+
} else {
|
78
|
+
instance.toggleRowEditing(id);
|
79
|
+
}
|
80
80
|
};
|
81
|
+
|
82
|
+
row.isEditing = row.original._createKey ? instance.state.editingRowUniqueId === row.original._createKey : instance.state.editingRowUniqueId === id;
|
83
|
+
row.canEdit = instance.state.allowEditing && (row.isEditing || !instance.state.editingRowUniqueId);
|
81
84
|
};
|
82
85
|
|
83
|
-
|
84
|
-
|
86
|
+
const useRowEditing = uniqueId => {
|
87
|
+
const plugin = hooks => {
|
85
88
|
if (uniqueId) {
|
86
89
|
hooks.stateReducers.push(reducer);
|
87
90
|
hooks.useInstance.push(useInstance);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useRowEditing.js","sources":["../../../../../../src/components/Table/hooks/plugins/useRowEditing.tsx"],"sourcesContent":["import React from 'react';\nimport { actions, PluginHook } from 'react-table';\n\nconst pluginName = 'useRowEditing';\n\nactions.resetRowEditing = 'resetRowEditing';\nactions.toggleRowEditing = 'toggleRowEditing';\nactions.toggleEditing = 'toggleEditing';\n\nfunction reducer(state: any, action: any): object {\n if (action.type === actions.init) {\n return {\n allowEditing: true,\n editingRowUniqueId: null,\n ...state,\n };\n }\n\n if (action.type === actions.resetRowEditing || action.type === actions.resetPage || action.type === actions.gotoPage) {\n return {\n ...state,\n editingRowUniqueId: null,\n };\n }\n\n if (action.type === actions.toggleRowEditing) {\n const { id } = action;\n return {\n ...state,\n editingRowUniqueId: id,\n };\n }\n\n if (action.type === actions.toggleEditing) {\n return {\n ...state,\n allowEditing: !state.allowEditing,\n };\n }\n\n return state;\n}\n\nfunction useInstance(instance: any): void {\n const { dispatch } = instance;\n\n const resetRowEditing = React.useCallback(() => {\n dispatch({ type: actions.resetRowEditing });\n }, [dispatch]);\n\n const toggleRowEditing = React.useCallback(\n id => {\n dispatch({ type: actions.toggleRowEditing, id });\n },\n [dispatch]\n );\n\n const toggleEditing = React.useCallback(() => {\n dispatch({ type: actions.toggleEditing });\n }, [dispatch]);\n\n Object.assign(instance, {\n resetRowEditing,\n toggleRowEditing,\n toggleEditing,\n });\n}\n\nconst prepareRow =\n <T extends {}>(uniqueId: keyof T) =>\n (row: any, { instance }: any): void => {\n const id = row.original[uniqueId];\n\n row.toggleRowEditing = () => {\n if (instance.state.editingRowUniqueId === id) {\n instance.resetRowEditing();\n } else {\n instance.toggleRowEditing(id);\n }\n };\n\n row.isEditing = row.original._createKey\n ? instance.state.editingRowUniqueId === row.original._createKey\n : instance.state.editingRowUniqueId === id;\n row.canEdit = instance.state.allowEditing && (row.isEditing || !instance.state.editingRowUniqueId);\n };\n\nexport const useRowEditing = <T extends {}>(uniqueId: keyof T | undefined): PluginHook<{}> => {\n const plugin = (hooks: any): void => {\n if (uniqueId) {\n hooks.stateReducers.push(reducer);\n hooks.useInstance.push(useInstance);\n hooks.prepareRow.push(prepareRow<T>(uniqueId));\n }\n };\n plugin.pluginName = pluginName;\n\n return plugin;\n};\n"],"names":["pluginName","actions","resetRowEditing","toggleRowEditing","toggleEditing","reducer","state","action","type","init","allowEditing","editingRowUniqueId","resetPage","gotoPage","id","useInstance","instance","dispatch","React","useCallback","Object","assign","prepareRow","uniqueId","row","original","isEditing","_createKey","canEdit","useRowEditing","plugin","hooks","stateReducers","push"],"mappings":"
|
1
|
+
{"version":3,"file":"useRowEditing.js","sources":["../../../../../../src/components/Table/hooks/plugins/useRowEditing.tsx"],"sourcesContent":["import React from 'react';\nimport { actions, PluginHook } from 'react-table';\n\nconst pluginName = 'useRowEditing';\n\nactions.resetRowEditing = 'resetRowEditing';\nactions.toggleRowEditing = 'toggleRowEditing';\nactions.toggleEditing = 'toggleEditing';\n\nfunction reducer(state: any, action: any): object {\n if (action.type === actions.init) {\n return {\n allowEditing: true,\n editingRowUniqueId: null,\n ...state,\n };\n }\n\n if (action.type === actions.resetRowEditing || action.type === actions.resetPage || action.type === actions.gotoPage) {\n return {\n ...state,\n editingRowUniqueId: null,\n };\n }\n\n if (action.type === actions.toggleRowEditing) {\n const { id } = action;\n return {\n ...state,\n editingRowUniqueId: id,\n };\n }\n\n if (action.type === actions.toggleEditing) {\n return {\n ...state,\n allowEditing: !state.allowEditing,\n };\n }\n\n return state;\n}\n\nfunction useInstance(instance: any): void {\n const { dispatch } = instance;\n\n const resetRowEditing = React.useCallback(() => {\n dispatch({ type: actions.resetRowEditing });\n }, [dispatch]);\n\n const toggleRowEditing = React.useCallback(\n id => {\n dispatch({ type: actions.toggleRowEditing, id });\n },\n [dispatch]\n );\n\n const toggleEditing = React.useCallback(() => {\n dispatch({ type: actions.toggleEditing });\n }, [dispatch]);\n\n Object.assign(instance, {\n resetRowEditing,\n toggleRowEditing,\n toggleEditing,\n });\n}\n\nconst prepareRow =\n <T extends {}>(uniqueId: keyof T) =>\n (row: any, { instance }: any): void => {\n const id = row.original[uniqueId];\n\n row.toggleRowEditing = () => {\n if (instance.state.editingRowUniqueId === id) {\n instance.resetRowEditing();\n } else {\n instance.toggleRowEditing(id);\n }\n };\n\n row.isEditing = row.original._createKey\n ? instance.state.editingRowUniqueId === row.original._createKey\n : instance.state.editingRowUniqueId === id;\n row.canEdit = instance.state.allowEditing && (row.isEditing || !instance.state.editingRowUniqueId);\n };\n\nexport const useRowEditing = <T extends {}>(uniqueId: keyof T | undefined): PluginHook<{}> => {\n const plugin = (hooks: any): void => {\n if (uniqueId) {\n hooks.stateReducers.push(reducer);\n hooks.useInstance.push(useInstance);\n hooks.prepareRow.push(prepareRow<T>(uniqueId));\n }\n };\n plugin.pluginName = pluginName;\n\n return plugin;\n};\n"],"names":["pluginName","actions","resetRowEditing","toggleRowEditing","toggleEditing","reducer","state","action","type","init","allowEditing","editingRowUniqueId","resetPage","gotoPage","id","useInstance","instance","dispatch","React","useCallback","Object","assign","prepareRow","uniqueId","row","original","isEditing","_createKey","canEdit","useRowEditing","plugin","hooks","stateReducers","push"],"mappings":";;;AAGA,MAAMA,UAAU,GAAG,eAAnB;AAEAC,OAAO,CAACC,eAAR,GAA0B,iBAA1B;AACAD,OAAO,CAACE,gBAAR,GAA2B,kBAA3B;AACAF,OAAO,CAACG,aAAR,GAAwB,eAAxB;;AAEA,SAASC,OAAT,CAAiBC,KAAjB,EAA6BC,MAA7B;EACI,IAAIA,MAAM,CAACC,IAAP,KAAgBP,OAAO,CAACQ,IAA5B,EAAkC;IAC9B,OAAO;MACHC,YAAY,EAAE,IADX;MAEHC,kBAAkB,EAAE,IAFjB;MAGH,GAAGL;KAHP;;;EAOJ,IAAIC,MAAM,CAACC,IAAP,KAAgBP,OAAO,CAACC,eAAxB,IAA2CK,MAAM,CAACC,IAAP,KAAgBP,OAAO,CAACW,SAAnE,IAAgFL,MAAM,CAACC,IAAP,KAAgBP,OAAO,CAACY,QAA5G,EAAsH;IAClH,OAAO,EACH,GAAGP,KADA;MAEHK,kBAAkB,EAAE;KAFxB;;;EAMJ,IAAIJ,MAAM,CAACC,IAAP,KAAgBP,OAAO,CAACE,gBAA5B,EAA8C;IAC1C,MAAM;MAAEW;QAAOP,MAAf;IACA,OAAO,EACH,GAAGD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F,GAAG,CAACC,QAAJ,CAAaE,UAAb,GACVX,QAAQ,CAACV,KAAT,CAAeK,kBAAf,KAAsCa,GAAG,CAACC,QAAJ,CAAaE,UADzC,GAEVX,QAAQ,CAACV,KAAT,CAAeK,kBAAf,KAAsCG,EAF5C;EAGAU,GAAG,CAACI,OAAJ,GAAcZ,QAAQ,CAACV,KAAT,CAAeI,YAAf,KAAgCc,GAAG,CAACE,SAAJ,IAAiB,CAACV,QAAQ,CAACV,KAAT,CAAeK,kBAAjE,CAAd;AACH,CAjBL;;MAmBakB,aAAa,GAAkBN,QAAf;EACzB,MAAMO,MAAM,GAAIC,KAAD;IACX,IAAIR,QAAJ,EAAc;MACVQ,KAAK,CAACC,aAAN,CAAoBC,IAApB,CAAyB5B,OAAzB;MACA0B,KAAK,CAAChB,WAAN,CAAkBkB,IAAlB,CAAuBlB,WAAvB;MACAgB,KAAK,CAACT,UAAN,CAAiBW,IAAjB,CAAsBX,UAAU,CAAIC,QAAJ,CAAhC;;GAJR;;EAOAO,MAAM,CAAC9B,UAAP,GAAoBA,UAApB;EAEA,OAAO8B,MAAP;AACH;;;;"}
|
@@ -1,112 +1,102 @@
|
|
1
|
-
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../../../../_virtual/_rollupPluginBabelHelpers.js';
|
2
1
|
import React__default from 'react';
|
3
2
|
import { Checkbox } from '../../../Checkbox/Checkbox.js';
|
4
3
|
import { useRowSelect as useRowSelect$1 } from 'react-table';
|
5
4
|
|
6
|
-
|
7
|
-
_excluded2 = ["onChange"];
|
5
|
+
// this wraps react-table's internal useRowSelect hook
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
const toggleBetween = (fromRowIndex, toRowIndex) => {
|
8
|
+
const fromIndex = toRowIndex < fromRowIndex ? toRowIndex : fromRowIndex;
|
9
|
+
const toIndex = toRowIndex > fromRowIndex ? toRowIndex : fromRowIndex;
|
12
10
|
return [fromIndex, toIndex];
|
13
11
|
}; // react-table calls "index paths" row ids. we named them indexPaths to reduce confusion with natural ids
|
14
12
|
// the selection hook usess react-table's row selection, so this hok references row.id - it is the index path
|
15
13
|
|
16
14
|
|
17
|
-
|
18
|
-
|
15
|
+
const useRowSelect = onSelectedRows => {
|
16
|
+
const plugin = hooks => {
|
19
17
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
20
18
|
useRowSelect$1(hooks);
|
21
19
|
|
22
20
|
if (onSelectedRows) {
|
23
|
-
|
24
|
-
|
25
|
-
var nextState = _extends({}, state);
|
26
|
-
|
27
|
-
if (checked) {
|
28
|
-
nextState[indexPath] = true;
|
29
|
-
} else {
|
30
|
-
delete nextState[indexPath];
|
31
|
-
}
|
32
|
-
|
33
|
-
return nextState;
|
34
|
-
});
|
35
|
-
};
|
36
|
-
|
37
|
-
var prepareRow = function prepareRow(row) {
|
38
|
-
row.toggleRowSelected = function () {
|
39
|
-
return toggleRowSelected(row.id, !row.isSelected);
|
21
|
+
const toggleRowSelected = (indexPath, checked) => onSelectedRows(state => {
|
22
|
+
const nextState = { ...state
|
40
23
|
};
|
41
|
-
};
|
42
24
|
|
43
|
-
|
25
|
+
if (checked) {
|
26
|
+
nextState[indexPath] = true;
|
27
|
+
} else {
|
28
|
+
delete nextState[indexPath];
|
29
|
+
}
|
44
30
|
|
45
|
-
|
46
|
-
|
47
|
-
return [{
|
48
|
-
id: 'selection',
|
49
|
-
Header: function Header(_ref) {
|
50
|
-
var getToggleAllRowsSelectedProps = _ref.getToggleAllRowsSelectedProps,
|
51
|
-
rows = _ref.rows;
|
52
|
-
|
53
|
-
var _getToggleAllRowsSele = getToggleAllRowsSelectedProps(),
|
54
|
-
props = _objectWithoutPropertiesLoose(_getToggleAllRowsSele, _excluded);
|
55
|
-
|
56
|
-
var onChange = function onChange(checked) {
|
57
|
-
if (checked) {
|
58
|
-
// this intentionally only selects top level rows - sub rows add too much complexity
|
59
|
-
onSelectedRows(Object.assign({}, Array(rows.length).fill(true)));
|
60
|
-
} else {
|
61
|
-
onSelectedRows({});
|
62
|
-
}
|
63
|
-
};
|
64
|
-
|
65
|
-
return React__default.createElement(Checkbox, Object.assign({}, props, {
|
66
|
-
onChange: onChange
|
67
|
-
}));
|
68
|
-
},
|
69
|
-
Cell: function Cell(_ref2) {
|
70
|
-
var row = _ref2.row,
|
71
|
-
rows = _ref2.rows;
|
72
|
-
|
73
|
-
var _row$getToggleRowSele = row.getToggleRowSelectedProps(),
|
74
|
-
props = _objectWithoutPropertiesLoose(_row$getToggleRowSele, _excluded2); // row.index refers to the index in the original data, not the current index
|
75
|
-
|
76
|
-
|
77
|
-
var sortedIndex = rows.findIndex(function (r) {
|
78
|
-
return r.index === row.index;
|
79
|
-
});
|
80
|
-
|
81
|
-
var onClick = function onClick(event) {
|
82
|
-
if (event.shiftKey) {
|
83
|
-
var _toggleBetween = toggleBetween(lastSelectedSortedIndex.current || 0, sortedIndex),
|
84
|
-
fromIndex = _toggleBetween[0],
|
85
|
-
toIndex = _toggleBetween[1];
|
86
|
-
|
87
|
-
for (var i = fromIndex; i <= toIndex; i++) {
|
88
|
-
toggleRowSelected(rows[i].id, true);
|
89
|
-
}
|
90
|
-
} else {
|
91
|
-
toggleRowSelected(row.id, !props.checked);
|
92
|
-
}
|
31
|
+
return nextState;
|
32
|
+
});
|
93
33
|
|
94
|
-
|
95
|
-
|
34
|
+
const prepareRow = row => {
|
35
|
+
row.toggleRowSelected = () => toggleRowSelected(row.id, !row.isSelected);
|
36
|
+
};
|
96
37
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
38
|
+
hooks.prepareRow.push(prepareRow); // eslint-disable-next-line react-hooks/rules-of-hooks
|
39
|
+
|
40
|
+
const lastSelectedSortedIndex = React__default.useRef();
|
41
|
+
hooks.visibleColumns.push(columns => [{
|
42
|
+
id: 'selection',
|
43
|
+
Header: ({
|
44
|
+
getToggleAllRowsSelectedProps,
|
45
|
+
rows
|
46
|
+
}) => {
|
47
|
+
const {
|
48
|
+
onChange: _,
|
49
|
+
...props
|
50
|
+
} = getToggleAllRowsSelectedProps();
|
51
|
+
|
52
|
+
const onChange = checked => {
|
53
|
+
if (checked) {
|
54
|
+
// this intentionally only selects top level rows - sub rows add too much complexity
|
55
|
+
onSelectedRows(Object.assign({}, Array(rows.length).fill(true)));
|
56
|
+
} else {
|
57
|
+
onSelectedRows({});
|
58
|
+
}
|
59
|
+
};
|
60
|
+
|
61
|
+
return React__default.createElement(Checkbox, Object.assign({}, props, {
|
62
|
+
onChange: onChange
|
63
|
+
}));
|
64
|
+
},
|
65
|
+
Cell: ({
|
66
|
+
row,
|
67
|
+
rows
|
68
|
+
}) => {
|
69
|
+
const {
|
70
|
+
onChange: _,
|
71
|
+
...props
|
72
|
+
} = row.getToggleRowSelectedProps(); // row.index refers to the index in the original data, not the current index
|
73
|
+
|
74
|
+
const sortedIndex = rows.findIndex(r => r.index === row.index);
|
75
|
+
|
76
|
+
const onClick = event => {
|
77
|
+
if (event.shiftKey) {
|
78
|
+
const [fromIndex, toIndex] = toggleBetween(lastSelectedSortedIndex.current || 0, sortedIndex);
|
79
|
+
|
80
|
+
for (let i = fromIndex; i <= toIndex; i++) {
|
81
|
+
toggleRowSelected(rows[i].id, true);
|
103
82
|
}
|
104
|
-
}
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
83
|
+
} else {
|
84
|
+
toggleRowSelected(row.id, !props.checked);
|
85
|
+
}
|
86
|
+
|
87
|
+
lastSelectedSortedIndex.current = sortedIndex;
|
88
|
+
};
|
89
|
+
|
90
|
+
return React__default.createElement(Checkbox, Object.assign({}, props, {
|
91
|
+
className: "mt-2.5",
|
92
|
+
onClick: onClick,
|
93
|
+
// this is necessary to remove console spam from eslint
|
94
|
+
onChange: () => false
|
95
|
+
}));
|
96
|
+
},
|
97
|
+
flex: '0 0 36px',
|
98
|
+
className: 'flex-col justify-start !py-0'
|
99
|
+
}, ...columns]);
|
110
100
|
}
|
111
101
|
};
|
112
102
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useRowSelect.js","sources":["../../../../../../src/components/Table/hooks/plugins/useRowSelect.tsx"],"sourcesContent":["// this wraps react-table's internal useRowSelect hook\nimport React from 'react';\nimport { useRowSelect as useBaseRowSelect, Row, PluginHook } from 'react-table';\nimport { Checkbox } from '../../../Checkbox/Checkbox';\nimport { SelectedRowsHandler } from '../../types';\n\nconst toggleBetween = (fromRowIndex: number, toRowIndex: number): [number, number] => {\n const fromIndex = toRowIndex < fromRowIndex ? toRowIndex : fromRowIndex;\n const toIndex = toRowIndex > fromRowIndex ? toRowIndex : fromRowIndex;\n\n return [fromIndex, toIndex];\n};\n\n// react-table calls \"index paths\" row ids. we named them indexPaths to reduce confusion with natural ids\n// the selection hook usess react-table's row selection, so this hok references row.id - it is the index path\n\nexport const useRowSelect = (onSelectedRows: SelectedRowsHandler | undefined): PluginHook<{}> => {\n const plugin = (hooks: any): void => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useBaseRowSelect(hooks);\n\n if (onSelectedRows) {\n const toggleRowSelected = (indexPath: string, checked: boolean): void =>\n onSelectedRows(state => {\n const nextState = { ...state };\n\n if (checked) {\n nextState[indexPath] = true;\n } else {\n delete nextState[indexPath];\n }\n\n return nextState;\n });\n\n const prepareRow = (row: any) => {\n row.toggleRowSelected = () => toggleRowSelected(row.id, !row.isSelected);\n };\n\n hooks.prepareRow.push(prepareRow);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const lastSelectedSortedIndex = React.useRef();\n\n hooks.visibleColumns.push((columns: any) => [\n {\n id: 'selection',\n Header: ({ getToggleAllRowsSelectedProps, rows }: any) => {\n const { onChange: _, ...props } = getToggleAllRowsSelectedProps();\n\n const onChange = (checked): void => {\n if (checked) {\n // this intentionally only selects top level rows - sub rows add too much complexity\n onSelectedRows(Object.assign({}, Array(rows.length).fill(true)));\n } else {\n onSelectedRows({});\n }\n };\n\n return <Checkbox {...props} onChange={onChange} />;\n },\n Cell: ({ row, rows }: any) => {\n const { onChange: _, ...props } = row.getToggleRowSelectedProps();\n // row.index refers to the index in the original data, not the current index\n const sortedIndex = rows.findIndex((r: Row) => r.index === row.index);\n\n const onClick = (event: React.MouseEvent): void => {\n if (event.shiftKey) {\n const [fromIndex, toIndex] = toggleBetween(lastSelectedSortedIndex.current || 0, sortedIndex);\n\n for (let i = fromIndex; i <= toIndex; i++) {\n toggleRowSelected(rows[i].id, true);\n }\n } else {\n toggleRowSelected(row.id, !props.checked);\n }\n\n lastSelectedSortedIndex.current = sortedIndex;\n };\n\n return (\n <Checkbox\n {...props}\n className=\"mt-2.5\"\n onClick={onClick}\n // this is necessary to remove console spam from eslint\n onChange={() => false}\n />\n );\n },\n flex: '0 0 36px',\n className: 'flex-col justify-start !py-0',\n },\n ...columns,\n ]);\n }\n };\n plugin.pluginName = 'useRowSelect';\n return plugin;\n};\n"],"names":["toggleBetween","fromRowIndex","toRowIndex","fromIndex","toIndex","useRowSelect","onSelectedRows","plugin","hooks","useBaseRowSelect","toggleRowSelected","indexPath","checked","state","nextState","prepareRow","row","id","isSelected","push","lastSelectedSortedIndex","React","useRef","visibleColumns","columns","Header","getToggleAllRowsSelectedProps","rows","
|
1
|
+
{"version":3,"file":"useRowSelect.js","sources":["../../../../../../src/components/Table/hooks/plugins/useRowSelect.tsx"],"sourcesContent":["// this wraps react-table's internal useRowSelect hook\nimport React from 'react';\nimport { useRowSelect as useBaseRowSelect, Row, PluginHook } from 'react-table';\nimport { Checkbox } from '../../../Checkbox/Checkbox';\nimport { SelectedRowsHandler } from '../../types';\n\nconst toggleBetween = (fromRowIndex: number, toRowIndex: number): [number, number] => {\n const fromIndex = toRowIndex < fromRowIndex ? toRowIndex : fromRowIndex;\n const toIndex = toRowIndex > fromRowIndex ? toRowIndex : fromRowIndex;\n\n return [fromIndex, toIndex];\n};\n\n// react-table calls \"index paths\" row ids. we named them indexPaths to reduce confusion with natural ids\n// the selection hook usess react-table's row selection, so this hok references row.id - it is the index path\n\nexport const useRowSelect = (onSelectedRows: SelectedRowsHandler | undefined): PluginHook<{}> => {\n const plugin = (hooks: any): void => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useBaseRowSelect(hooks);\n\n if (onSelectedRows) {\n const toggleRowSelected = (indexPath: string, checked: boolean): void =>\n onSelectedRows(state => {\n const nextState = { ...state };\n\n if (checked) {\n nextState[indexPath] = true;\n } else {\n delete nextState[indexPath];\n }\n\n return nextState;\n });\n\n const prepareRow = (row: any) => {\n row.toggleRowSelected = () => toggleRowSelected(row.id, !row.isSelected);\n };\n\n hooks.prepareRow.push(prepareRow);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const lastSelectedSortedIndex = React.useRef();\n\n hooks.visibleColumns.push((columns: any) => [\n {\n id: 'selection',\n Header: ({ getToggleAllRowsSelectedProps, rows }: any) => {\n const { onChange: _, ...props } = getToggleAllRowsSelectedProps();\n\n const onChange = (checked): void => {\n if (checked) {\n // this intentionally only selects top level rows - sub rows add too much complexity\n onSelectedRows(Object.assign({}, Array(rows.length).fill(true)));\n } else {\n onSelectedRows({});\n }\n };\n\n return <Checkbox {...props} onChange={onChange} />;\n },\n Cell: ({ row, rows }: any) => {\n const { onChange: _, ...props } = row.getToggleRowSelectedProps();\n // row.index refers to the index in the original data, not the current index\n const sortedIndex = rows.findIndex((r: Row) => r.index === row.index);\n\n const onClick = (event: React.MouseEvent): void => {\n if (event.shiftKey) {\n const [fromIndex, toIndex] = toggleBetween(lastSelectedSortedIndex.current || 0, sortedIndex);\n\n for (let i = fromIndex; i <= toIndex; i++) {\n toggleRowSelected(rows[i].id, true);\n }\n } else {\n toggleRowSelected(row.id, !props.checked);\n }\n\n lastSelectedSortedIndex.current = sortedIndex;\n };\n\n return (\n <Checkbox\n {...props}\n className=\"mt-2.5\"\n onClick={onClick}\n // this is necessary to remove console spam from eslint\n onChange={() => false}\n />\n );\n },\n flex: '0 0 36px',\n className: 'flex-col justify-start !py-0',\n },\n ...columns,\n ]);\n }\n };\n plugin.pluginName = 'useRowSelect';\n return plugin;\n};\n"],"names":["toggleBetween","fromRowIndex","toRowIndex","fromIndex","toIndex","useRowSelect","onSelectedRows","plugin","hooks","useBaseRowSelect","toggleRowSelected","indexPath","checked","state","nextState","prepareRow","row","id","isSelected","push","lastSelectedSortedIndex","React","useRef","visibleColumns","columns","Header","getToggleAllRowsSelectedProps","rows","onChange","_","props","Object","assign","Array","length","fill","Checkbox","Cell","getToggleRowSelectedProps","sortedIndex","findIndex","r","index","onClick","event","shiftKey","current","i","className","flex","pluginName"],"mappings":";;;;AAAA;;AAMA,MAAMA,aAAa,GAAG,CAACC,YAAD,EAAuBC,UAAvB;EAClB,MAAMC,SAAS,GAAGD,UAAU,GAAGD,YAAb,GAA4BC,UAA5B,GAAyCD,YAA3D;EACA,MAAMG,OAAO,GAAGF,UAAU,GAAGD,YAAb,GAA4BC,UAA5B,GAAyCD,YAAzD;EAEA,OAAO,CAACE,SAAD,EAAYC,OAAZ,CAAP;AACH,CALD;AAQA;;;MAEaC,YAAY,GAAIC,cAAD;EACxB,MAAMC,MAAM,GAAIC,KAAD;;IAEXC,cAAgB,CAACD,KAAD,CAAhB;;IAEA,IAAIF,cAAJ,EAAoB;MAChB,MAAMI,iBAAiB,GAAG,CAACC,SAAD,EAAoBC,OAApB,KACtBN,cAAc,CAACO,KAAK;QAChB,MAAMC,SAAS,GAAG,EAAE,GAAGD;SAAvB;;QAEA,IAAID,OAAJ,EAAa;UACTE,SAAS,CAACH,SAAD,CAAT,GAAuB,IAAvB;SADJ,MAEO;UACH,OAAOG,SAAS,CAACH,SAAD,CAAhB;;;QAGJ,OAAOG,SAAP;OATU,CADlB;;MAaA,MAAMC,UAAU,GAAIC,GAAD;QACfA,GAAG,CAACN,iBAAJ,GAAwB,MAAMA,iBAAiB,CAACM,GAAG,CAACC,EAAL,EAAS,CAACD,GAAG,CAACE,UAAd,CAA/C;OADJ;;MAIAV,KAAK,CAACO,UAAN,CAAiBI,IAAjB,CAAsBJ,UA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ACoB,CAAD,CAAJ,CAAQ9B,EAAT,EAAa,IAAb,CAAjB;;aAJR,MAMO;cACHP,iBAAiB,CAACM,GAAG,CAACC,EAAL,EAAS,CAACa,KAAK,CAAClB,OAAhB,CAAjB;;;YAGJQ,uBAAuB,CAAC0B,OAAxB,GAAkCP,WAAlC;WAXJ;;UAcA,OACIlB,4BAAA,CAACe,QAAD,oBACQN;YACJkB,SAAS,EAAC;YACVL,OAAO,EAAEA;;YAETf,QAAQ,EAAE,MAAM;YALpB,CADJ;SAnCR;QA6CIqB,IAAI,EAAE,UA7CV;QA8CID,SAAS,EAAE;OA/CyB,EAiDxC,GAAGxB,OAjDqC,CAA5C;;GA3BR;;EAgFAjB,MAAM,CAAC2C,UAAP,GAAoB,cAApB;EACA,OAAO3C,MAAP;AACH;;;;"}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
|
2
1
|
import React__default from 'react';
|
3
2
|
import { v4 } from 'uuid';
|
4
3
|
import set from 'lodash-es/set';
|
@@ -8,27 +7,17 @@ import get from 'lodash-es/get';
|
|
8
7
|
import compact from 'lodash-es/compact';
|
9
8
|
import pullAt from 'lodash-es/pullAt';
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
|
16
|
-
if (values === void 0) {
|
17
|
-
values = {};
|
18
|
-
}
|
19
|
-
|
20
|
-
var nexTRow = JSON.parse(JSON.stringify(data));
|
21
|
-
var childRowIndexPath;
|
10
|
+
const insertChildTableRow = (data, rowIndexPath = undefined, values = {}) => {
|
11
|
+
const nexTRow = JSON.parse(JSON.stringify(data));
|
12
|
+
let childRowIndexPath;
|
22
13
|
|
23
14
|
if (rowIndexPath) {
|
24
15
|
var _currentRow$subRows;
|
25
16
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
return "[" + i + "]";
|
31
|
-
}).join('.subRows') + '.subRows';
|
17
|
+
const rowIndexes = convertRowIndexPathToNumberArray(rowIndexPath);
|
18
|
+
const currentRow = getByRowIndexPath(nexTRow, rowIndexes.join('.'));
|
19
|
+
const nextSubRows = (_currentRow$subRows = currentRow === null || currentRow === void 0 ? void 0 : currentRow.subRows) !== null && _currentRow$subRows !== void 0 ? _currentRow$subRows : [];
|
20
|
+
const path = rowIndexes.map(i => `[${i}]`).join('.subRows') + '.subRows';
|
32
21
|
nextSubRows.unshift(values);
|
33
22
|
set(nexTRow, path, nextSubRows); // rebuild the new id
|
34
23
|
|
@@ -41,22 +30,18 @@ var insertChildTableRow = function insertChildTableRow(data, rowIndexPath, value
|
|
41
30
|
|
42
31
|
return [nexTRow, childRowIndexPath];
|
43
32
|
};
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
33
|
+
const removeChildTableRow = (data, rowIndexPath) => {
|
34
|
+
const nexTRow = JSON.parse(JSON.stringify(data));
|
35
|
+
const rowIndexes = convertRowIndexPathToNumberArray(rowIndexPath);
|
36
|
+
const rootIndex = Number(rowIndexes.shift());
|
48
37
|
|
49
38
|
if (rowIndexes.length) {
|
50
39
|
// unset
|
51
|
-
|
52
|
-
return "subRows[" + index + "]";
|
53
|
-
}).join('.');
|
40
|
+
const unsetPath = rowIndexes.map(index => `subRows[${index}]`).join('.');
|
54
41
|
unset(nexTRow[rootIndex], unsetPath); // remove empty value from subRows
|
55
42
|
|
56
43
|
rowIndexes.pop();
|
57
|
-
|
58
|
-
return "subRows[" + index + "]";
|
59
|
-
}).join('.') + '.subRows' : 'subRows';
|
44
|
+
const setPath = rowIndexes.length ? rowIndexes.map(index => `subRows[${index}]`).join('.') + '.subRows' : 'subRows';
|
60
45
|
set(nexTRow[rootIndex], setPath, compact(get(nexTRow[rootIndex], setPath)));
|
61
46
|
} else {
|
62
47
|
pullAt(nexTRow, rootIndex);
|
@@ -64,26 +49,17 @@ var removeChildTableRow = function removeChildTableRow(data, rowIndexPath) {
|
|
64
49
|
|
65
50
|
return nexTRow;
|
66
51
|
};
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
var _React$useState2 = React__default.useState(undefined),
|
73
|
-
activeRowIndexPath = _React$useState2[0],
|
74
|
-
setActiveRowIndexPath = _React$useState2[1];
|
75
|
-
|
76
|
-
React__default.useEffect(function () {
|
52
|
+
const useTableRowCreation = (data, tableRef) => {
|
53
|
+
const [internalData, setInternalData] = React__default.useState(JSON.parse(JSON.stringify(data)));
|
54
|
+
const [activeRowIndexPath, setActiveRowIndexPath] = React__default.useState(undefined);
|
55
|
+
React__default.useEffect(() => {
|
77
56
|
if (activeRowIndexPath !== undefined) {
|
78
57
|
// keep the same edit key, so that we don't remount the row/form
|
79
|
-
|
58
|
+
const currentRow = getByRowIndexPath(internalData, activeRowIndexPath); // get the active creation rows parent
|
80
59
|
|
81
|
-
|
82
|
-
|
83
|
-
var _insertChildTableRow = insertChildTableRow(JSON.parse(JSON.stringify(data)), parentId, currentRow),
|
84
|
-
nexTRow = _insertChildTableRow[0],
|
85
|
-
newRowIndexPath = _insertChildTableRow[1]; // update and set that row as active, we basically just changed it's position in our internal data
|
60
|
+
const parentId = getParentRowIndexPath(activeRowIndexPath); // insert a new empty row in the external data (with the same key)
|
86
61
|
|
62
|
+
const [nexTRow, newRowIndexPath] = insertChildTableRow(JSON.parse(JSON.stringify(data)), parentId, currentRow); // update and set that row as active, we basically just changed it's position in our internal data
|
87
63
|
|
88
64
|
setActiveRowIndexPath(newRowIndexPath);
|
89
65
|
setInternalData(nexTRow);
|
@@ -96,23 +72,12 @@ var useTableRowCreation = function useTableRowCreation(data, tableRef) {
|
|
96
72
|
}
|
97
73
|
}, [JSON.stringify(data)]);
|
98
74
|
|
99
|
-
|
100
|
-
|
101
|
-
rowIndexPath = undefined;
|
102
|
-
}
|
103
|
-
|
104
|
-
if (values === void 0) {
|
105
|
-
values = {};
|
106
|
-
}
|
107
|
-
|
108
|
-
var _createKey = v4();
|
109
|
-
|
110
|
-
var _insertChildTableRow2 = insertChildTableRow(internalData, rowIndexPath, _extends({}, values, {
|
111
|
-
_createKey: _createKey
|
112
|
-
})),
|
113
|
-
nexTRow = _insertChildTableRow2[0],
|
114
|
-
newRowIndexPath = _insertChildTableRow2[1];
|
75
|
+
const create = (rowIndexPath = undefined, values = {}) => {
|
76
|
+
const _createKey = v4();
|
115
77
|
|
78
|
+
const [nexTRow, newRowIndexPath] = insertChildTableRow(internalData, rowIndexPath, { ...values,
|
79
|
+
_createKey
|
80
|
+
});
|
116
81
|
setActiveRowIndexPath(newRowIndexPath);
|
117
82
|
setInternalData(nexTRow);
|
118
83
|
|
@@ -123,16 +88,16 @@ var useTableRowCreation = function useTableRowCreation(data, tableRef) {
|
|
123
88
|
return newRowIndexPath;
|
124
89
|
};
|
125
90
|
|
126
|
-
|
127
|
-
|
91
|
+
const remove = rowIndexPath => {
|
92
|
+
const nexTRow = removeChildTableRow(internalData, rowIndexPath);
|
128
93
|
setInternalData(nexTRow);
|
129
94
|
setActiveRowIndexPath(undefined);
|
130
95
|
};
|
131
96
|
|
132
97
|
return {
|
133
98
|
data: internalData,
|
134
|
-
create
|
135
|
-
remove
|
99
|
+
create,
|
100
|
+
remove,
|
136
101
|
isCreating: activeRowIndexPath !== undefined
|
137
102
|
};
|
138
103
|
};
|