@economic/taco 1.19.0 → 1.20.0
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/dist/components/AlertDialog/components/Content.d.ts +1 -1
- package/dist/components/Calendar/Calendar.d.ts +1 -1
- package/dist/components/Calendar/Calendar.stories.d.ts +1 -1
- package/dist/components/Datepicker/Datepicker.d.ts +1 -1
- package/dist/components/Datepicker/Datepicker.stories.d.ts +1 -1
- package/dist/components/Dialog/components/Content.d.ts +1 -1
- package/dist/components/Dialog/components/Drawer.d.ts +1 -1
- package/dist/components/IconButton/IconButton.d.ts +2 -2
- package/dist/components/Input/Input.d.ts +1 -1
- package/dist/components/Listbox/Listbox.d.ts +2 -2
- package/dist/components/Listbox/Listbox.stories.d.ts +1 -1
- package/dist/components/Listbox/ScrollableList.d.ts +1 -1
- package/dist/components/Menu/components/Checkbox.d.ts +1 -1
- package/dist/components/Menu/components/Content.d.ts +1 -1
- package/dist/components/Menu/components/Item.d.ts +1 -1
- package/dist/components/Menu/components/Link.d.ts +1 -1
- package/dist/components/Menu/components/Trigger.d.ts +1 -1
- package/dist/components/Provider/Localization.d.ts +10 -0
- package/dist/components/SearchInput/SearchInput.d.ts +1 -1
- package/dist/components/SearchInput/SearchInput.stories.d.ts +1 -1
- package/dist/components/Select/Select.d.ts +1 -1
- package/dist/components/Select/Select.stories.d.ts +1 -1
- package/dist/components/Select2/components/Option.d.ts +1 -1
- package/dist/components/Select2/components/Search.d.ts +1 -1
- package/dist/components/Select2/components/Trigger.d.ts +1 -1
- package/dist/components/Shortcut/Shortcut.d.ts +5 -0
- package/dist/components/Table2/Table2.d.ts +17 -0
- package/dist/components/Table2/Table2.stories.d.ts +50 -0
- package/dist/components/Table2/components/BatchActionsMenu.d.ts +10 -0
- package/dist/components/Table2/components/ColumnSettingsButton.d.ts +7 -0
- package/dist/components/Table2/components/EditModeButton.d.ts +7 -0
- package/dist/components/Table2/components/RowDensityButton.d.ts +7 -0
- package/dist/components/Table2/components/Search.d.ts +3 -0
- package/dist/components/Table2/components/ShortcutsGuideButton.d.ts +7 -0
- package/dist/components/Table2/components/column/Base.d.ts +12 -0
- package/dist/components/Table2/components/column/Cell.d.ts +15 -0
- package/dist/components/Table2/components/column/Footer.d.ts +9 -0
- package/dist/components/Table2/components/column/Header.d.ts +11 -0
- package/dist/components/Table2/components/column/Indicator.d.ts +16 -0
- package/dist/components/Table2/components/column/ValidationError.d.ts +5 -0
- package/dist/components/Table2/components/column/utils.d.ts +2 -0
- package/dist/components/Table2/components/filters/FiltersButton.d.ts +7 -0
- package/dist/components/Table2/components/filters/components/Column.d.ts +11 -0
- package/dist/components/Table2/components/filters/components/ColumnFilter.d.ts +9 -0
- package/dist/components/Table2/components/filters/components/Comparator.d.ts +11 -0
- package/dist/components/Table2/components/filters/components/InferredControl.d.ts +10 -0
- package/dist/components/Table2/components/row/Context.d.ts +15 -0
- package/dist/components/Table2/components/row/ExpandedRow.d.ts +6 -0
- package/dist/components/Table2/components/row/Row.d.ts +7 -0
- package/dist/components/Table2/hooks/listeners/useActiveCellStateListener.d.ts +3 -0
- package/dist/components/Table2/hooks/listeners/useActiveRowStateListener.d.ts +3 -0
- package/dist/components/Table2/hooks/listeners/useColumnOffsetStateListener.d.ts +4 -0
- package/dist/components/Table2/hooks/listeners/useRowSelectionListener.d.ts +3 -0
- package/dist/components/Table2/hooks/listeners/useSettingsStateListener.d.ts +3 -0
- package/dist/components/Table2/hooks/useActiveCell.d.ts +26 -0
- package/dist/components/Table2/hooks/useActiveRow.d.ts +10 -0
- package/dist/components/Table2/hooks/useColumnDefinitions.d.ts +36 -0
- package/dist/components/Table2/hooks/useEditMode.d.ts +28 -0
- package/dist/components/Table2/hooks/useGridTemplate.d.ts +2 -0
- package/dist/components/Table2/hooks/useSeparatedChildren.d.ts +1 -0
- package/dist/components/Table2/hooks/useTable.d.ts +40 -0
- package/dist/components/Table2/hooks/useVirtualiser.d.ts +23 -0
- package/dist/components/Table2/types.d.ts +138 -0
- package/dist/components/Table2/utilities/cell.d.ts +13 -0
- package/dist/components/Table2/utilities/columns.d.ts +13 -0
- package/dist/components/Table2/utilities/filterFn.d.ts +3 -0
- package/dist/components/Tag/Tag.d.ts +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +1 -1
- package/dist/components/Tooltip/Tooltip.stories.d.ts +1 -1
- package/dist/esm/index.css +3 -3
- package/dist/esm/node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js +14 -1
- package/dist/esm/node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Checkbox/Checkbox.js +13 -5
- package/dist/esm/packages/taco/src/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Provider/Localization.js +7 -0
- package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Shortcut/Shortcut.js +18 -0
- package/dist/esm/packages/taco/src/components/Shortcut/Shortcut.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/Table2.js +374 -0
- package/dist/esm/packages/taco/src/components/Table2/Table2.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/BatchActionsMenu.js +83 -0
- package/dist/esm/packages/taco/src/components/Table2/components/BatchActionsMenu.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/ColumnSettingsButton.js +238 -0
- package/dist/esm/packages/taco/src/components/Table2/components/ColumnSettingsButton.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/EditModeButton.js +58 -0
- package/dist/esm/packages/taco/src/components/Table2/components/EditModeButton.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/RowDensityButton.js +31 -0
- package/dist/esm/packages/taco/src/components/Table2/components/RowDensityButton.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/Search.js +55 -0
- package/dist/esm/packages/taco/src/components/Table2/components/Search.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/ShortcutsGuideButton.js +88 -0
- package/dist/esm/packages/taco/src/components/Table2/components/ShortcutsGuideButton.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/Base.js +32 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/Base.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/Cell.js +498 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/Cell.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/Footer.js +27 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/Footer.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/Header.js +159 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/Header.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/Indicator.js +78 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/Indicator.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/ValidationError.js +30 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/ValidationError.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/utils.js +38 -0
- package/dist/esm/packages/taco/src/components/Table2/components/column/utils.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/filters/FiltersButton.js +89 -0
- package/dist/esm/packages/taco/src/components/Table2/components/filters/FiltersButton.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/filters/components/Column.js +31 -0
- package/dist/esm/packages/taco/src/components/Table2/components/filters/components/Column.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/filters/components/ColumnFilter.js +121 -0
- package/dist/esm/packages/taco/src/components/Table2/components/filters/components/ColumnFilter.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/filters/components/Comparator.js +60 -0
- package/dist/esm/packages/taco/src/components/Table2/components/filters/components/Comparator.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/filters/components/InferredControl.js +96 -0
- package/dist/esm/packages/taco/src/components/Table2/components/filters/components/InferredControl.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/row/Context.js +26 -0
- package/dist/esm/packages/taco/src/components/Table2/components/row/Context.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/row/ExpandedRow.js +33 -0
- package/dist/esm/packages/taco/src/components/Table2/components/row/ExpandedRow.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/components/row/Row.js +58 -0
- package/dist/esm/packages/taco/src/components/Table2/components/row/Row.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/listeners/useActiveRowStateListener.js +19 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/listeners/useActiveRowStateListener.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/listeners/useColumnOffsetStateListener.js +44 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/listeners/useColumnOffsetStateListener.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/listeners/useRowSelectionListener.js +17 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/listeners/useRowSelectionListener.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/listeners/useSettingsStateListener.js +25 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/listeners/useSettingsStateListener.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useActiveRow.js +33 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useActiveRow.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useColumnDefinitions.js +106 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useColumnDefinitions.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useEditMode.js +112 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useEditMode.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useGridTemplate.js +32 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useGridTemplate.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useSeparatedChildren.js +20 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useSeparatedChildren.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useTable.js +200 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useTable.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useVirtualiser.js +49 -0
- package/dist/esm/packages/taco/src/components/Table2/hooks/useVirtualiser.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/types.js +16 -0
- package/dist/esm/packages/taco/src/components/Table2/types.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/utilities/cell.js +41 -0
- package/dist/esm/packages/taco/src/components/Table2/utilities/cell.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/utilities/columns.js +309 -0
- package/dist/esm/packages/taco/src/components/Table2/utilities/columns.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table2/utilities/filterFn.js +96 -0
- package/dist/esm/packages/taco/src/components/Table2/utilities/filterFn.js.map +1 -0
- package/dist/esm/packages/taco/src/hooks/useBoundaryOverflowDetection.js +16 -0
- package/dist/esm/packages/taco/src/hooks/useBoundaryOverflowDetection.js.map +1 -0
- package/dist/esm/packages/taco/src/hooks/useGlobalKeyboardShortcut.js +13 -0
- package/dist/esm/packages/taco/src/hooks/useGlobalKeyboardShortcut.js.map +1 -0
- package/dist/esm/packages/taco/src/index.js +4 -2
- package/dist/esm/packages/taco/src/index.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Sortable/components/Container.js +59 -0
- package/dist/esm/packages/taco/src/primitives/Sortable/components/Container.js.map +1 -0
- package/dist/esm/packages/taco/src/primitives/Sortable/components/Item.js +47 -0
- package/dist/esm/packages/taco/src/primitives/Sortable/components/Item.js.map +1 -0
- package/dist/esm/packages/taco/src/primitives/Sortable/components/List.js +28 -0
- package/dist/esm/packages/taco/src/primitives/Sortable/components/List.js.map +1 -0
- package/dist/esm/packages/taco/src/utils/date.js +4 -1
- package/dist/esm/packages/taco/src/utils/date.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/dom.js +2 -1
- package/dist/esm/packages/taco/src/utils/dom.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/hooks/useTruncated.js +20 -0
- package/dist/esm/packages/taco/src/utils/hooks/useTruncated.js.map +1 -0
- package/dist/hooks/useGlobalKeyboardShortcut.d.ts +1 -0
- package/dist/index.css +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/primitives/Sortable/Sortable.d.ts +2 -2
- package/dist/taco.cjs.development.js +3438 -90
- 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/date.d.ts +1 -0
- package/dist/utils/hooks/useTruncated.d.ts +3 -0
- package/package.json +4 -2
- package/tailwind.config.js +11 -1
- package/types.json +1291 -2
@@ -34,8 +34,14 @@ var unset = _interopDefault(require('lodash/unset'));
|
|
34
34
|
var get = _interopDefault(require('lodash/get'));
|
35
35
|
var compact = _interopDefault(require('lodash/compact'));
|
36
36
|
var pullAt = _interopDefault(require('lodash/pullAt'));
|
37
|
-
var
|
37
|
+
var reactTable$1 = require('@tanstack/react-table');
|
38
38
|
var PrimitiveSwitch = require('@radix-ui/react-switch');
|
39
|
+
var ReactDOM = _interopDefault(require('react-dom'));
|
40
|
+
var reactVirtual = require('react-virtual');
|
41
|
+
var core = require('@dnd-kit/core');
|
42
|
+
var sortable = require('@dnd-kit/sortable');
|
43
|
+
var utilities = require('@dnd-kit/utilities');
|
44
|
+
var TabsPrimitive = require('@radix-ui/react-tabs');
|
39
45
|
var Joyride = require('react-joyride');
|
40
46
|
var Joyride__default = _interopDefault(Joyride);
|
41
47
|
|
@@ -3628,6 +3634,13 @@ const defaultLocalisationTexts = {
|
|
3628
3634
|
newSubRow: 'New row (shift + n)',
|
3629
3635
|
loading: 'Loading...'
|
3630
3636
|
},
|
3637
|
+
table2: {
|
3638
|
+
rowWillMove: 'Row will move',
|
3639
|
+
rowWillBeFiltered: 'Row will be filtered',
|
3640
|
+
searchFilterMovementReason: 'Due to global search filter applied on the table, this row will be hidden after editing',
|
3641
|
+
tableFilterMovementReason: 'Due to a filter applied on the [COLUMN] column, this row will be hidden after editing',
|
3642
|
+
sortingMovementReason: 'Due to sorting applied on the [COLUMN] column, this row will move position after editing'
|
3643
|
+
},
|
3631
3644
|
select: {
|
3632
3645
|
allOptionsSelected: 'All'
|
3633
3646
|
},
|
@@ -3915,14 +3928,15 @@ const Checkbox = /*#__PURE__*/React.forwardRef(function Checkbox(props, ref) {
|
|
3915
3928
|
...otherProps
|
3916
3929
|
} = props;
|
3917
3930
|
const id = useId(props.id);
|
3918
|
-
const className = cn('bg-white h-5 w-5 border rounded text-sm flex-shrink-0
|
3931
|
+
const className = cn('bg-white h-5 w-5 border rounded text-sm flex-shrink-0 mt-[0.1rem] focus:yt-focus',
|
3919
3932
|
//hover:shadow-[0_0_0_1px_rgba(235,235,235,1)]
|
3920
|
-
|
3933
|
+
{
|
3921
3934
|
'border-grey-300 text-blue-500 hover:text-blue-300 focus:border-blue-500 focus:hover:border-blue-300': !props.disabled && !invalid,
|
3922
3935
|
'border-grey-200 text-blue-300 cursor-not-allowed': props.disabled,
|
3923
3936
|
'bg-[rgba(255,255,0,0.2)] disabled:bg-[rgba(255,255,0,0.075)]': highlighted,
|
3924
|
-
'border-red-500 text-red-500 hover:text-red-300 hover:border-red-300 focus:border-red-500 focus:hover:border-red-300': invalid && !props.disabled
|
3925
|
-
|
3937
|
+
'border-red-500 text-red-500 hover:text-red-300 hover:border-red-300 focus:border-red-500 focus:hover:border-red-300': invalid && !props.disabled,
|
3938
|
+
'self-start': !!label
|
3939
|
+
}, props.className);
|
3926
3940
|
let handleChange;
|
3927
3941
|
if (onChange) {
|
3928
3942
|
handleChange = checked => onChange(checked === 'indeterminate' ? false : checked);
|
@@ -3934,11 +3948,18 @@ const Checkbox = /*#__PURE__*/React.forwardRef(function Checkbox(props, ref) {
|
|
3934
3948
|
id
|
3935
3949
|
};
|
3936
3950
|
}
|
3951
|
+
// the enter keyboard shortcut isn't supported by default, but we want it
|
3952
|
+
const handleKeyDown = event => {
|
3953
|
+
if (event.key === 'Enter') {
|
3954
|
+
event.currentTarget.click();
|
3955
|
+
}
|
3956
|
+
};
|
3937
3957
|
const element = /*#__PURE__*/React.createElement(CheckboxPrimitive.Root, Object.assign({}, otherProps, labelledByProps, {
|
3938
3958
|
"data-taco": "checkbox",
|
3939
3959
|
checked: indeterminate ? 'indeterminate' : checked,
|
3940
3960
|
className: className,
|
3941
3961
|
onCheckedChange: handleChange,
|
3962
|
+
onKeyDown: handleKeyDown,
|
3942
3963
|
ref: ref
|
3943
3964
|
}), /*#__PURE__*/React.createElement(CheckboxPrimitive.Indicator, {
|
3944
3965
|
className: "flex h-full w-full"
|
@@ -3949,7 +3970,7 @@ const Checkbox = /*#__PURE__*/React.forwardRef(function Checkbox(props, ref) {
|
|
3949
3970
|
if (label) {
|
3950
3971
|
const labelContainerClassName = cn('flex items-center cursor-pointer gap-2', {
|
3951
3972
|
'cursor-not-allowed text-grey-300': props.disabled
|
3952
|
-
}
|
3973
|
+
});
|
3953
3974
|
return /*#__PURE__*/React.createElement("span", {
|
3954
3975
|
className: labelContainerClassName
|
3955
3976
|
}, element, /*#__PURE__*/React.createElement("label", {
|
@@ -4899,6 +4920,9 @@ const Combobox = /*#__PURE__*/React.forwardRef(function Combobox(props, ref) {
|
|
4899
4920
|
}))))));
|
4900
4921
|
});
|
4901
4922
|
|
4923
|
+
const isWeakEqual = (leftDate, rightDate) => {
|
4924
|
+
return leftDate.getFullYear() === rightDate.getFullYear() && leftDate.getMonth() === rightDate.getMonth() && leftDate.getDay() === rightDate.getDay();
|
4925
|
+
};
|
4902
4926
|
const format = (date, mask = 'dd.mm.yy') => {
|
4903
4927
|
if (!date) {
|
4904
4928
|
return undefined;
|
@@ -7826,6 +7850,19 @@ function _catch(body, recover) {
|
|
7826
7850
|
return result;
|
7827
7851
|
}
|
7828
7852
|
|
7853
|
+
// Asynchronously await a promise and pass the result to a finally continuation
|
7854
|
+
function _finallyRethrows(body, finalizer) {
|
7855
|
+
try {
|
7856
|
+
var result = body();
|
7857
|
+
} catch (e) {
|
7858
|
+
return finalizer(true, e);
|
7859
|
+
}
|
7860
|
+
if (result && result.then) {
|
7861
|
+
return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
|
7862
|
+
}
|
7863
|
+
return finalizer(false, result);
|
7864
|
+
}
|
7865
|
+
|
7829
7866
|
const AVAILABLE_COLORS = /*#__PURE__*/Object.keys(TAG_COLORS);
|
7830
7867
|
const EditPopover = props => {
|
7831
7868
|
const {
|
@@ -8094,6 +8131,7 @@ const Title$4 = /*#__PURE__*/React__default.forwardRef(function Select2Title(pro
|
|
8094
8131
|
}));
|
8095
8132
|
});
|
8096
8133
|
|
8134
|
+
const isOverflowing = element => element !== null ? element.scrollWidth > element.offsetWidth : false;
|
8097
8135
|
const getIndexOfFirstChildOverflowingParent = (element, overscan = 0) => {
|
8098
8136
|
let index = 0;
|
8099
8137
|
let boundaryChildIndex = null;
|
@@ -8829,6 +8867,19 @@ const ControlledHiddenField = props => {
|
|
8829
8867
|
};
|
8830
8868
|
Select2.displayName = 'Select2';
|
8831
8869
|
|
8870
|
+
const Shortcut$1 = ({
|
8871
|
+
keys,
|
8872
|
+
...props
|
8873
|
+
}) => {
|
8874
|
+
const className = cn('inline-flex gap-0.5', props.className);
|
8875
|
+
return /*#__PURE__*/React__default.createElement("span", Object.assign({}, props, {
|
8876
|
+
className: className
|
8877
|
+
}), keys.map(key => /*#__PURE__*/React__default.createElement("kbd", {
|
8878
|
+
key: key,
|
8879
|
+
className: "wcag-blue-900 inline-flex h-4 items-center rounded px-1 font-mono text-xs font-normal"
|
8880
|
+
}, key)));
|
8881
|
+
};
|
8882
|
+
|
8832
8883
|
const sanitizeRowProps = (row, rowExpansionRenderer) => {
|
8833
8884
|
var _row$subRows;
|
8834
8885
|
const props = {
|
@@ -10299,96 +10350,362 @@ const useTableRowCreation = (data, tableRef) => {
|
|
10299
10350
|
};
|
10300
10351
|
};
|
10301
10352
|
|
10302
|
-
const
|
10303
|
-
|
10304
|
-
|
10305
|
-
|
10306
|
-
|
10307
|
-
|
10308
|
-
|
10309
|
-
|
10310
|
-
|
10311
|
-
|
10312
|
-
|
10313
|
-
|
10314
|
-
return
|
10315
|
-
|
10316
|
-
|
10317
|
-
|
10318
|
-
|
10319
|
-
|
10320
|
-
|
10321
|
-
|
10322
|
-
|
10323
|
-
|
10324
|
-
|
10325
|
-
|
10326
|
-
|
10327
|
-
|
10328
|
-
|
10329
|
-
|
10330
|
-
|
10353
|
+
const COLUMN_ID_FOR_DRAGGABLE = '__draggable';
|
10354
|
+
const COLUMN_ID_FOR_SELECTION = '__select';
|
10355
|
+
const COLUMN_ID_FOR_EXPANSION = '__expansion';
|
10356
|
+
const COLUMN_ID_FOR_ACTIONS = '__actions';
|
10357
|
+
const isInternalColumn = id => id === COLUMN_ID_FOR_SELECTION || id === COLUMN_ID_FOR_EXPANSION || id === COLUMN_ID_FOR_ACTIONS || id === COLUMN_ID_FOR_DRAGGABLE;
|
10358
|
+
const MIN_COLUMN_SIZE = 80; // accounts for padding and sort controls
|
10359
|
+
const toggleBetween$1 = (fromRowIndex, toRowIndex) => {
|
10360
|
+
const fromIndex = toRowIndex < fromRowIndex ? toRowIndex : fromRowIndex;
|
10361
|
+
const toIndex = toRowIndex > fromRowIndex ? toRowIndex : fromRowIndex;
|
10362
|
+
return [fromIndex, toIndex];
|
10363
|
+
};
|
10364
|
+
function createRowDraggableColumn(onRowDrag) {
|
10365
|
+
return {
|
10366
|
+
id: COLUMN_ID_FOR_DRAGGABLE,
|
10367
|
+
cell: ({
|
10368
|
+
row,
|
10369
|
+
table
|
10370
|
+
}) => {
|
10371
|
+
const meta = table.options.meta;
|
10372
|
+
const GHOST_ELEMENT_ID = 'taco_table_dragging';
|
10373
|
+
const onDragStart = event => {
|
10374
|
+
const rows = row.getIsSelected() ? table.getSelectedRowModel().rows : [row, ...table.getSelectedRowModel().rows];
|
10375
|
+
meta.setDragging(rows.reduce((dragging, rowBeingDragged) => ({
|
10376
|
+
...dragging,
|
10377
|
+
[rowBeingDragged.id]: true
|
10378
|
+
}), {}));
|
10379
|
+
const data = rows.map(row => row.original);
|
10380
|
+
// set a default data value so that the consumer doesn't have to
|
10381
|
+
event.dataTransfer.setData('text', JSON.stringify(data));
|
10382
|
+
const showPlaceholder = text => {
|
10383
|
+
const ghost = document.createElement('div');
|
10384
|
+
ghost.id = GHOST_ELEMENT_ID;
|
10385
|
+
ghost.className = 'wcag-blue rounded flex w-48 p-4 absolute -ml-[100vw]';
|
10386
|
+
ghost.innerText = text;
|
10387
|
+
document.body.appendChild(ghost);
|
10388
|
+
event.dataTransfer.setDragImage(ghost, 0, 0);
|
10389
|
+
};
|
10390
|
+
const setDataTransfer = text => event.dataTransfer.setData('text', text);
|
10391
|
+
onRowDrag(data, showPlaceholder, setDataTransfer);
|
10392
|
+
};
|
10393
|
+
const onDragEnd = () => {
|
10394
|
+
var _document$getElementB;
|
10395
|
+
(_document$getElementB = document.getElementById(GHOST_ELEMENT_ID)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
|
10396
|
+
meta.setDragging({});
|
10397
|
+
};
|
10398
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
10399
|
+
draggable: true,
|
10400
|
+
onDragStart: onDragStart,
|
10401
|
+
onDragEnd: onDragEnd
|
10402
|
+
}, /*#__PURE__*/React__default.createElement(Icon, {
|
10403
|
+
"aria-label": "Drag row",
|
10404
|
+
name: "drag",
|
10405
|
+
className: "text-grey-darkest invisible w-[20px] cursor-grab active:cursor-grabbing group-hover/row:visible group-[[aria-grabbed]]/row:text-white"
|
10406
|
+
}));
|
10407
|
+
},
|
10408
|
+
meta: {
|
10409
|
+
align: 'center',
|
10410
|
+
className: 'items-center !px-0',
|
10411
|
+
disableTruncation: true,
|
10412
|
+
headerClassName: 'items-center !px-0'
|
10413
|
+
},
|
10414
|
+
// sizing
|
10415
|
+
enableResizing: false,
|
10416
|
+
size: 10
|
10417
|
+
};
|
10418
|
+
}
|
10419
|
+
function createRowSelectionColumn(enableMultipleRowSelection, lastSelectedRowIndex, onRowDrag, tableRef) {
|
10420
|
+
let header;
|
10421
|
+
let cell;
|
10422
|
+
if (enableMultipleRowSelection) {
|
10423
|
+
header = ({
|
10424
|
+
table
|
10425
|
+
}) => /*#__PURE__*/React__default.createElement(Tooltip, {
|
10426
|
+
title: /*#__PURE__*/React__default.createElement(React__default.Fragment, null, table.getIsAllPageRowsSelected() ? 'Deselect all' : 'Select all', /*#__PURE__*/React__default.createElement(Shortcut$1, {
|
10427
|
+
className: "ml-2",
|
10428
|
+
keys: ['Ctrl', 'A']
|
10429
|
+
}))
|
10430
|
+
}, /*#__PURE__*/React__default.createElement(Checkbox, {
|
10431
|
+
"aria-label": table.getIsAllPageRowsSelected() ? 'Deselect all rows' : 'Select all rows',
|
10432
|
+
className: "hover:border-blue !mt-0",
|
10433
|
+
checked: table.getIsAllPageRowsSelected(),
|
10434
|
+
indeterminate: table.getIsSomePageRowsSelected(),
|
10435
|
+
onChange: checked => table.toggleAllPageRowsSelected(checked),
|
10436
|
+
onClick: () => {
|
10437
|
+
var _tableRef$current;
|
10438
|
+
(_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : _tableRef$current.focus();
|
10439
|
+
},
|
10440
|
+
tabIndex: -1
|
10441
|
+
}));
|
10442
|
+
cell = ({
|
10443
|
+
row,
|
10444
|
+
table
|
10445
|
+
}) => {
|
10446
|
+
const meta = table.options.meta;
|
10447
|
+
const handleClick = event => {
|
10448
|
+
var _tableRef$current2;
|
10449
|
+
event.stopPropagation();
|
10450
|
+
if (event.shiftKey) {
|
10451
|
+
const [fromIndex, toIndex] = toggleBetween$1((lastSelectedRowIndex === null || lastSelectedRowIndex === void 0 ? void 0 : lastSelectedRowIndex.current) || 0, row.index);
|
10452
|
+
table.getRowModel().rows.slice(fromIndex, toIndex + 1).forEach(row => row.toggleSelected(true));
|
10453
|
+
} else {
|
10454
|
+
row.toggleSelected();
|
10455
|
+
}
|
10456
|
+
lastSelectedRowIndex.current = row.index;
|
10457
|
+
meta.setActiveRowIndex(row.index);
|
10458
|
+
(_tableRef$current2 = tableRef.current) === null || _tableRef$current2 === void 0 ? void 0 : _tableRef$current2.focus();
|
10459
|
+
};
|
10460
|
+
return /*#__PURE__*/React__default.createElement(Tooltip, {
|
10461
|
+
title: /*#__PURE__*/React__default.createElement(React__default.Fragment, null, table.getIsAllPageRowsSelected() ? 'Deselect' : 'Select', /*#__PURE__*/React__default.createElement(Shortcut$1, {
|
10462
|
+
className: "ml-2",
|
10463
|
+
keys: ['Space']
|
10464
|
+
}))
|
10465
|
+
}, /*#__PURE__*/React__default.createElement(Checkbox, {
|
10466
|
+
"aria-label": row.getIsSelected() ? 'Deselect row' : 'Select row',
|
10467
|
+
className: "hover:border-blue !mt-[0.45rem]",
|
10468
|
+
checked: row.getIsSelected(),
|
10469
|
+
onClick: handleClick,
|
10470
|
+
// this is necessary to remove console spam from eslint
|
10471
|
+
onChange: () => false,
|
10472
|
+
tabIndex: -1
|
10473
|
+
}));
|
10474
|
+
};
|
10475
|
+
} else {
|
10476
|
+
cell = ({
|
10477
|
+
row,
|
10478
|
+
table
|
10479
|
+
}) => {
|
10480
|
+
const meta = table.options.meta;
|
10481
|
+
const className = 'border-grey-300 focus:yt-focus flex h-5 w-5 mt-[0.45rem] flex-shrink-0 items-center justify-center self-start rounded-full border-2 bg-white hover:border-[5px] aria-checked:border-blue-500 aria-checked:bg-blue-500 hover:aria-checked:border-blue-300';
|
10482
|
+
const handleClick = event => {
|
10483
|
+
var _tableRef$current3;
|
10484
|
+
event.stopPropagation();
|
10485
|
+
row.toggleSelected();
|
10486
|
+
meta.setActiveRowIndex(row.index);
|
10487
|
+
(_tableRef$current3 = tableRef.current) === null || _tableRef$current3 === void 0 ? void 0 : _tableRef$current3.focus();
|
10488
|
+
};
|
10489
|
+
return /*#__PURE__*/React__default.createElement("button", {
|
10490
|
+
className: className,
|
10491
|
+
"aria-checked": row.getIsSelected(),
|
10492
|
+
onClick: handleClick,
|
10493
|
+
role: "radio",
|
10494
|
+
tabIndex: -1,
|
10495
|
+
type: "button"
|
10496
|
+
}, row.getIsSelected() ? /*#__PURE__*/React__default.createElement("span", {
|
10497
|
+
className: "h-2.5 w-2.5 rounded-full bg-white"
|
10498
|
+
}) : null);
|
10499
|
+
};
|
10500
|
+
}
|
10501
|
+
return {
|
10502
|
+
id: COLUMN_ID_FOR_SELECTION,
|
10503
|
+
header,
|
10504
|
+
cell,
|
10505
|
+
meta: {
|
10506
|
+
align: 'center',
|
10507
|
+
className: onRowDrag ? '!pl-0 !pr-3' : '!px-3',
|
10508
|
+
disableTruncation: true,
|
10509
|
+
headerClassName: onRowDrag ? '!pl-0 !pr-3' : '!px-3'
|
10510
|
+
},
|
10511
|
+
// sizing
|
10512
|
+
enableResizing: false,
|
10513
|
+
size: 46
|
10514
|
+
};
|
10515
|
+
}
|
10516
|
+
function createRowExpansionColumn() {
|
10517
|
+
return {
|
10518
|
+
id: COLUMN_ID_FOR_EXPANSION,
|
10519
|
+
header: ({
|
10520
|
+
table
|
10521
|
+
}) => /*#__PURE__*/React__default.createElement(Tooltip, {
|
10522
|
+
title: table.getIsSomeRowsExpanded() ? 'Collapse all' : 'Expand all'
|
10523
|
+
}, /*#__PURE__*/React__default.createElement(IconButton, {
|
10524
|
+
title: table.getIsSomeRowsExpanded() ? 'Collapse all rows' : 'Expand all rows',
|
10525
|
+
appearance: "discrete",
|
10526
|
+
className: "-mb-2 -mt-1.5",
|
10527
|
+
icon: table.getIsSomeRowsExpanded() ? 'chevron-down-double' : 'chevron-right-double',
|
10528
|
+
onClick: event => {
|
10529
|
+
event.stopPropagation();
|
10530
|
+
table.toggleAllRowsExpanded(table.getIsSomeRowsExpanded() ? false : true);
|
10531
|
+
},
|
10532
|
+
tabIndex: -1
|
10533
|
+
})),
|
10534
|
+
cell: ({
|
10535
|
+
row
|
10536
|
+
}) => /*#__PURE__*/React__default.createElement(Tooltip, {
|
10537
|
+
title: /*#__PURE__*/React__default.createElement(React__default.Fragment, null, row.getIsExpanded() ? 'Collapse' : 'Expand', /*#__PURE__*/React__default.createElement(Shortcut$1, {
|
10538
|
+
className: "ml-2",
|
10539
|
+
keys: ['Ctrl', row.getIsExpanded() ? '←' : '→']
|
10540
|
+
}))
|
10541
|
+
}, /*#__PURE__*/React__default.createElement(IconButton, {
|
10542
|
+
title: row.getIsExpanded() ? 'Collapse row' : 'Expand row',
|
10543
|
+
appearance: "discrete",
|
10544
|
+
icon: row.getIsExpanded() ? 'chevron-down' : 'chevron-right',
|
10545
|
+
onClick: event => {
|
10546
|
+
event.stopPropagation();
|
10547
|
+
row.toggleExpanded();
|
10548
|
+
},
|
10549
|
+
tabIndex: -1
|
10550
|
+
})),
|
10551
|
+
meta: {
|
10552
|
+
align: 'center',
|
10553
|
+
className: 'items-center !p-0',
|
10554
|
+
disableTruncation: true,
|
10555
|
+
headerClassName: 'items-center hover:!bg-white !p-0'
|
10556
|
+
},
|
10557
|
+
// sizing
|
10558
|
+
enableResizing: false,
|
10559
|
+
size: 36
|
10560
|
+
};
|
10561
|
+
}
|
10562
|
+
const getActionPropertyValue = (property, row) => typeof property === 'function' ? property(row) : property;
|
10563
|
+
function RowActionCell({
|
10564
|
+
row,
|
10565
|
+
table,
|
10566
|
+
actions,
|
10567
|
+
moreActions
|
10568
|
+
}) {
|
10569
|
+
const isVisible = action => typeof action.visible !== 'undefined' ? typeof action.visible === 'function' ? action.visible(row.original) : action.visible : true;
|
10570
|
+
const visibleActions = actions.filter(isVisible);
|
10571
|
+
const visibleMoreActions = moreActions.filter(isVisible);
|
10572
|
+
if (table.options.meta.activeRowIndex !== row.index && table.options.meta.hoveredRowIndex !== row.index) {
|
10573
|
+
const totalButtons = visibleActions.length + (visibleMoreActions.length ? 1 : 0);
|
10574
|
+
// this is necessary because row actions is has this mount hover delay, which makes the
|
10575
|
+
// size calculation in the header get set before rendering - meaning the size doesn't include the buttons
|
10576
|
+
// when we cache icons this can go
|
10577
|
+
const paddingSize = 8;
|
10578
|
+
const buttonSize = 32;
|
10579
|
+
return /*#__PURE__*/React__default.createElement("span", {
|
10580
|
+
className: "flex",
|
10581
|
+
style: {
|
10582
|
+
width: paddingSize + totalButtons * buttonSize
|
10583
|
+
}
|
10584
|
+
});
|
10585
|
+
}
|
10586
|
+
return /*#__PURE__*/React__default.createElement("span", {
|
10587
|
+
className: "-mb-2 -mt-1.5 text-right"
|
10588
|
+
}, visibleActions.map((action, i) => /*#__PURE__*/React__default.createElement(IconButton, {
|
10589
|
+
key: i,
|
10590
|
+
"aria-label": getActionPropertyValue(action.ariaLabel, row.original),
|
10591
|
+
appearance: "discrete",
|
10592
|
+
dialog: action.dialog ? action.dialog(row.original) : undefined,
|
10593
|
+
disabled: getActionPropertyValue(action.disabled, row.original),
|
10594
|
+
icon: getActionPropertyValue(action.icon, row.original),
|
10595
|
+
onClick: event => {
|
10596
|
+
event.stopPropagation();
|
10597
|
+
if (action.onClick) {
|
10598
|
+
action.onClick(row.original);
|
10599
|
+
}
|
10600
|
+
},
|
10601
|
+
tooltip: getActionPropertyValue(action.text, row.original)
|
10602
|
+
})), visibleMoreActions.length ? /*#__PURE__*/React__default.createElement(IconButton, {
|
10603
|
+
"aria-label": "View other actions",
|
10604
|
+
appearance: "discrete",
|
10605
|
+
icon: "more",
|
10606
|
+
onClick: event => {
|
10607
|
+
event.preventDefault();
|
10608
|
+
},
|
10609
|
+
menu: menuProps => /*#__PURE__*/React__default.createElement(Menu$1, Object.assign({}, menuProps), /*#__PURE__*/React__default.createElement(Menu$1.Content, null, visibleMoreActions.map((action, i) => /*#__PURE__*/React__default.createElement(Menu$1.Item, {
|
10610
|
+
key: i,
|
10611
|
+
dialog: action.dialog ? action.dialog(row.original) : undefined,
|
10612
|
+
disabled: getActionPropertyValue(action.disabled, row.original),
|
10613
|
+
icon: getActionPropertyValue(action.icon, row.original),
|
10614
|
+
onClick: () => {
|
10615
|
+
if (action.onClick) {
|
10616
|
+
action.onClick(row.original);
|
10617
|
+
}
|
10618
|
+
}
|
10619
|
+
}, getActionPropertyValue(action.text, row.original))))),
|
10620
|
+
tooltip: "Other actions..."
|
10621
|
+
}) : null);
|
10622
|
+
}
|
10623
|
+
function createRowActionsColumn(rowActions) {
|
10624
|
+
const actions = rowActions.slice(0, 3);
|
10625
|
+
const moreActions = rowActions.slice(3);
|
10626
|
+
return {
|
10627
|
+
id: COLUMN_ID_FOR_ACTIONS,
|
10628
|
+
cell: ({
|
10629
|
+
row,
|
10630
|
+
table
|
10631
|
+
}) => /*#__PURE__*/React__default.createElement(RowActionCell, {
|
10632
|
+
row: row,
|
10633
|
+
table: table,
|
10634
|
+
actions: actions,
|
10635
|
+
moreActions: moreActions
|
10636
|
+
}),
|
10637
|
+
meta: {
|
10638
|
+
align: 'right',
|
10639
|
+
className: row => cn('items-center print:opacity-0 group-[[aria-current]]/row:sticky group-hover/row:sticky right-0 bg-transparent !px-1', {
|
10640
|
+
'group-hover/row:!shadow-[-6px_0px_6px_theme(colors.grey.100)] group-[[aria-current]]/row:!shadow-[-6px_0px_6px_theme(colors.grey.100)]': !row.getIsSelected(),
|
10641
|
+
'shadow-[-6px_0px_6px_theme(colors.blue.100)]': row.getIsSelected()
|
10642
|
+
}),
|
10643
|
+
disableTruncation: true,
|
10644
|
+
headerClassName: 'hover:!bg-white !px-1'
|
10645
|
+
},
|
10646
|
+
// sizing
|
10647
|
+
enableResizing: false
|
10648
|
+
};
|
10649
|
+
}
|
10650
|
+
|
10651
|
+
const getDensityPadding = (density, editing = false) => {
|
10652
|
+
switch (density) {
|
10653
|
+
case 'compact':
|
10654
|
+
return editing ? 'py-0' : 'py-1.5';
|
10655
|
+
case 'comfortable':
|
10656
|
+
return editing ? 'py-2' : 'py-3.5';
|
10657
|
+
case 'spacious':
|
10658
|
+
return editing ? 'py-3' : 'py-5';
|
10659
|
+
default:
|
10660
|
+
return editing ? 'py-1' : 'py-2.5';
|
10661
|
+
}
|
10662
|
+
};
|
10663
|
+
const getCellSizingClasses = (density = 'normal', editing = false) => {
|
10664
|
+
return cn('flex items-center', getDensityPadding(density, editing), editing ? 'px-[7px]' : 'px-4');
|
10665
|
+
};
|
10666
|
+
const getCellAlignmentClasses = (alignment = 'left') => ({
|
10667
|
+
'justify-start text-left': alignment === 'left',
|
10668
|
+
'justify-end text-right': alignment === 'right',
|
10669
|
+
'justify-center text-center': alignment === 'center'
|
10331
10670
|
});
|
10332
|
-
const
|
10671
|
+
const getPinnedShadowClasses = (column, columnPinning, isHorizontallyOffset) => {
|
10672
|
+
const pinned = !!column.getIsPinned();
|
10673
|
+
// react-table has column.getPinnedIndex() but it does not exclude hidden columns, so the number is wrong
|
10674
|
+
const pinnedIndex = columnPinning.indexOf(column.id);
|
10675
|
+
const isLastPinned = pinned && pinnedIndex === columnPinning.length - 1;
|
10676
|
+
const hidePinnedShadow = !isHorizontallyOffset && (column.id === COLUMN_ID_FOR_EXPANSION || column.id === COLUMN_ID_FOR_SELECTION);
|
10677
|
+
return {
|
10678
|
+
'shadow-[6px_0px_6px_rgb(0_0_0/8%),1px_0px_0px_theme(colors.grey.300)]': isLastPinned && isHorizontallyOffset,
|
10679
|
+
'shadow-[1px_0px_0px_theme(colors.grey.300)]': isLastPinned && !isHorizontallyOffset && !hidePinnedShadow
|
10680
|
+
};
|
10681
|
+
};
|
10682
|
+
const isKeyboardFocusableElement = element => {
|
10683
|
+
const focussableNodeNames = ['A', 'BUTTON', 'INPUT', 'TEXTAREA', 'SELECT', 'DETAILS'];
|
10684
|
+
return focussableNodeNames.includes(element.nodeName) && !element.hasAttribute('disabled') && !element.hasAttribute('readonly') && !element.getAttribute('aria-hidden');
|
10685
|
+
};
|
10686
|
+
|
10687
|
+
const ColumnBase = /*#__PURE__*/React__default.forwardRef(function Table2ColumnBase(props, ref) {
|
10688
|
+
var _column$columnDef$met;
|
10333
10689
|
const {
|
10334
|
-
|
10335
|
-
|
10336
|
-
|
10690
|
+
column,
|
10691
|
+
scrolled,
|
10692
|
+
style,
|
10693
|
+
table,
|
10694
|
+
...attributes
|
10337
10695
|
} = props;
|
10338
|
-
const
|
10339
|
-
|
10696
|
+
const pinned = !!column.getIsPinned();
|
10697
|
+
const meta = table.options.meta;
|
10698
|
+
const left = meta.columnOffsets[column.id];
|
10699
|
+
const columnPinning = table.getLeftVisibleLeafColumns().map(c => c.id);
|
10700
|
+
const className = cn('border-grey-300', getPinnedShadowClasses(column, columnPinning, scrolled), getCellAlignmentClasses((_column$columnDef$met = column.columnDef.meta) === null || _column$columnDef$met === void 0 ? void 0 : _column$columnDef$met.align), {
|
10701
|
+
'cursor-pointer': !!attributes.onClick
|
10702
|
+
}, attributes.className);
|
10703
|
+
return /*#__PURE__*/React__default.createElement("div", Object.assign({}, attributes, {
|
10340
10704
|
className: className,
|
10341
|
-
disabled: disabled,
|
10342
|
-
ref: ref,
|
10343
10705
|
style: {
|
10344
|
-
|
10706
|
+
...style,
|
10707
|
+
left: pinned && Number.isInteger(left) ? left : undefined
|
10345
10708
|
},
|
10346
|
-
value: id
|
10347
|
-
}));
|
10348
|
-
});
|
10349
|
-
const TabContent = /*#__PURE__*/React.forwardRef(function Tab(props, ref) {
|
10350
|
-
const {
|
10351
|
-
id,
|
10352
|
-
...otherProps
|
10353
|
-
} = props;
|
10354
|
-
const className = cn('yt-tab__panel outline-none', props.className);
|
10355
|
-
return /*#__PURE__*/React.createElement(TabsPrimitive.Content, Object.assign({}, otherProps, {
|
10356
|
-
className: className,
|
10357
|
-
ref: ref,
|
10358
|
-
value: id
|
10359
|
-
}));
|
10360
|
-
});
|
10361
|
-
Tabs.List = TabList;
|
10362
|
-
Tabs.Trigger = TabTrigger;
|
10363
|
-
Tabs.Content = TabContent;
|
10364
|
-
|
10365
|
-
const Textarea = /*#__PURE__*/React.forwardRef(function Textarea(props, ref) {
|
10366
|
-
const {
|
10367
|
-
defaultValue: _,
|
10368
|
-
highlighted,
|
10369
|
-
invalid,
|
10370
|
-
onKeyDown,
|
10371
|
-
...otherProps
|
10372
|
-
} = props;
|
10373
|
-
const classNames = cn(getInputClasses(props), 'py-1 min-h-[75px] disabled:resize-none', props.className);
|
10374
|
-
// home and end keys only navigate to the start/end of textarea value if the textarea container does not scroll
|
10375
|
-
// if it has scroll height then the browser reverts to native scrolling behaviour only
|
10376
|
-
// so we manually override it to ensure _our_ desired behaviour remains intact
|
10377
|
-
const handleKeyDown = event => {
|
10378
|
-
if (event.key === 'Home' || event.key === 'End') {
|
10379
|
-
event.preventDefault();
|
10380
|
-
const position = event.key === 'End' ? event.currentTarget.value.length : 0;
|
10381
|
-
event.currentTarget.setSelectionRange(position, position);
|
10382
|
-
event.currentTarget.scrollTop = event.key === 'End' ? event.currentTarget.scrollHeight : 0;
|
10383
|
-
}
|
10384
|
-
if (onKeyDown) {
|
10385
|
-
onKeyDown(event);
|
10386
|
-
}
|
10387
|
-
};
|
10388
|
-
return /*#__PURE__*/React.createElement("textarea", Object.assign({}, otherProps, {
|
10389
|
-
className: classNames,
|
10390
|
-
"data-taco": "textarea",
|
10391
|
-
onKeyDown: handleKeyDown,
|
10392
10709
|
ref: ref
|
10393
10710
|
}));
|
10394
10711
|
});
|
@@ -10434,6 +10751,3034 @@ const Switch = /*#__PURE__*/React.forwardRef(function Switch(props, ref) {
|
|
10434
10751
|
});
|
10435
10752
|
Switch.displayName = 'Switch';
|
10436
10753
|
|
10754
|
+
var Table2FilterComparator;
|
10755
|
+
(function (Table2FilterComparator) {
|
10756
|
+
Table2FilterComparator[Table2FilterComparator["Contains"] = 0] = "Contains";
|
10757
|
+
Table2FilterComparator[Table2FilterComparator["DoesNotContain"] = 1] = "DoesNotContain";
|
10758
|
+
Table2FilterComparator[Table2FilterComparator["IsEqualTo"] = 2] = "IsEqualTo";
|
10759
|
+
Table2FilterComparator[Table2FilterComparator["IsNotEqualTo"] = 3] = "IsNotEqualTo";
|
10760
|
+
Table2FilterComparator[Table2FilterComparator["IsGreaterThan"] = 4] = "IsGreaterThan";
|
10761
|
+
Table2FilterComparator[Table2FilterComparator["IsLessThan"] = 5] = "IsLessThan";
|
10762
|
+
Table2FilterComparator[Table2FilterComparator["IsBetween"] = 6] = "IsBetween";
|
10763
|
+
Table2FilterComparator[Table2FilterComparator["IsOneOf"] = 7] = "IsOneOf";
|
10764
|
+
Table2FilterComparator[Table2FilterComparator["IsNoneOf"] = 8] = "IsNoneOf";
|
10765
|
+
Table2FilterComparator[Table2FilterComparator["IsAllOf"] = 9] = "IsAllOf";
|
10766
|
+
})(Table2FilterComparator || (Table2FilterComparator = {}));
|
10767
|
+
|
10768
|
+
const toLowerCase = value => String(value !== null && value !== void 0 ? value : '').toLocaleLowerCase();
|
10769
|
+
const isWeakContains = (left, right) => toLowerCase(left).includes(toLowerCase(right));
|
10770
|
+
const isWeakEqual$1 = (left, right) => toLowerCase(left) === toLowerCase(right);
|
10771
|
+
const globalFilterFn = (value, query) => isWeakContains(value, query);
|
10772
|
+
// the filter type is only settable on the column definition, which would re-render all columns
|
10773
|
+
// so instead we store it in the filter value, but that means we also have to destructure that
|
10774
|
+
// before we filter - that's why this custom filter function exists
|
10775
|
+
const columnFilterFn = (value, filter) => {
|
10776
|
+
try {
|
10777
|
+
if (filter.value === undefined || filter.value === null || filter.value === '') {
|
10778
|
+
return true;
|
10779
|
+
}
|
10780
|
+
switch (filter.comparator) {
|
10781
|
+
case Table2FilterComparator.Contains:
|
10782
|
+
return isWeakContains(value, filter.value);
|
10783
|
+
case Table2FilterComparator.DoesNotContain:
|
10784
|
+
return !isWeakContains(value, filter.value);
|
10785
|
+
case Table2FilterComparator.IsEqualTo:
|
10786
|
+
{
|
10787
|
+
if (dateFns.isDate(value)) {
|
10788
|
+
return dateFns.isDate(filter.value) && isWeakEqual(value, filter.value);
|
10789
|
+
} else if (typeof filter.value === 'boolean') {
|
10790
|
+
return value === filter.value;
|
10791
|
+
}
|
10792
|
+
return isWeakEqual$1(value, filter.value);
|
10793
|
+
}
|
10794
|
+
case Table2FilterComparator.IsNotEqualTo:
|
10795
|
+
{
|
10796
|
+
if (dateFns.isDate(value)) {
|
10797
|
+
return dateFns.isDate(filter.value) && isWeakEqual(value, filter.value) === false;
|
10798
|
+
} else if (typeof filter.value === 'boolean') {
|
10799
|
+
return value !== filter.value;
|
10800
|
+
}
|
10801
|
+
return !isWeakEqual$1(value, filter.value);
|
10802
|
+
}
|
10803
|
+
case Table2FilterComparator.IsGreaterThan:
|
10804
|
+
{
|
10805
|
+
if (dateFns.isDate(value)) {
|
10806
|
+
return dateFns.isDate(filter.value) && dateFns.isAfter(value, filter.value);
|
10807
|
+
} else {
|
10808
|
+
const valueAsNumber = parseInt(value);
|
10809
|
+
return !isNaN(valueAsNumber) && filter.value !== undefined && valueAsNumber > filter.value;
|
10810
|
+
}
|
10811
|
+
}
|
10812
|
+
case Table2FilterComparator.IsLessThan:
|
10813
|
+
{
|
10814
|
+
if (dateFns.isDate(value)) {
|
10815
|
+
return dateFns.isDate(filter.value) && dateFns.isBefore(value, filter.value);
|
10816
|
+
} else {
|
10817
|
+
const valueAsNumber = parseInt(value);
|
10818
|
+
return !isNaN(valueAsNumber) && filter.value !== undefined && valueAsNumber < filter.value;
|
10819
|
+
}
|
10820
|
+
}
|
10821
|
+
case Table2FilterComparator.IsBetween:
|
10822
|
+
{
|
10823
|
+
const [fromValue, toValue] = filter.value;
|
10824
|
+
if (dateFns.isDate(value)) {
|
10825
|
+
if (dateFns.isDate(fromValue) && dateFns.isBefore(value, fromValue)) {
|
10826
|
+
return false;
|
10827
|
+
} else if (dateFns.isDate(toValue) && dateFns.isAfter(value, toValue)) {
|
10828
|
+
return false;
|
10829
|
+
}
|
10830
|
+
return true;
|
10831
|
+
} else {
|
10832
|
+
const valueAsNumber = parseInt(value);
|
10833
|
+
if (isNaN(valueAsNumber)) {
|
10834
|
+
return false;
|
10835
|
+
}
|
10836
|
+
if (fromValue !== undefined && valueAsNumber < fromValue) {
|
10837
|
+
return false;
|
10838
|
+
} else if (toValue !== undefined && valueAsNumber > toValue) {
|
10839
|
+
return false;
|
10840
|
+
}
|
10841
|
+
return true;
|
10842
|
+
}
|
10843
|
+
}
|
10844
|
+
case Table2FilterComparator.IsOneOf:
|
10845
|
+
return Array.isArray(filter.value) ? filter.value.includes(value) : false;
|
10846
|
+
case Table2FilterComparator.IsNoneOf:
|
10847
|
+
return Array.isArray(filter.value) ? filter.value.includes(value) === false : false;
|
10848
|
+
case Table2FilterComparator.IsAllOf:
|
10849
|
+
return Array.isArray(filter.value) && Array.isArray(value) ? filter.value.filter(v => value.includes(v)).length === filter.value.length : false;
|
10850
|
+
}
|
10851
|
+
return false;
|
10852
|
+
} catch (e) {
|
10853
|
+
console.error(e);
|
10854
|
+
return true;
|
10855
|
+
}
|
10856
|
+
};
|
10857
|
+
|
10858
|
+
var MOVE_DIR;
|
10859
|
+
(function (MOVE_DIR) {
|
10860
|
+
MOVE_DIR[MOVE_DIR["FIRST"] = 0] = "FIRST";
|
10861
|
+
MOVE_DIR[MOVE_DIR["LAST"] = 1] = "LAST";
|
10862
|
+
MOVE_DIR[MOVE_DIR["PREV"] = 2] = "PREV";
|
10863
|
+
MOVE_DIR[MOVE_DIR["NEXT"] = 3] = "NEXT";
|
10864
|
+
})(MOVE_DIR || (MOVE_DIR = {}));
|
10865
|
+
const useEditMode = handleSave => {
|
10866
|
+
const enableEditMode = !!handleSave;
|
10867
|
+
const [editMode, setEditMode] = React__default.useState({
|
10868
|
+
enableEditMode,
|
10869
|
+
isEditing: false,
|
10870
|
+
columnIndex: 0
|
10871
|
+
});
|
10872
|
+
React__default.useEffect(() => {
|
10873
|
+
setEditMode(editMode => ({
|
10874
|
+
...editMode,
|
10875
|
+
enableEditMode
|
10876
|
+
}));
|
10877
|
+
}, [enableEditMode]);
|
10878
|
+
const _moveActiveColumn = (moveDirection, focussableColumnIndexes, moveRow) => {
|
10879
|
+
var _focussableColumnInde, _focussableColumnInde2;
|
10880
|
+
const firstDataColumnIndex = (_focussableColumnInde = focussableColumnIndexes.at(0)) !== null && _focussableColumnInde !== void 0 ? _focussableColumnInde : 0;
|
10881
|
+
const lastDataColumnIndex = (_focussableColumnInde2 = focussableColumnIndexes.at(-1)) !== null && _focussableColumnInde2 !== void 0 ? _focussableColumnInde2 : 0;
|
10882
|
+
if (!editMode.enableEditMode) {
|
10883
|
+
return;
|
10884
|
+
}
|
10885
|
+
setEditMode(({
|
10886
|
+
columnIndex: currentColumnIndex,
|
10887
|
+
...currentEditMode
|
10888
|
+
}) => {
|
10889
|
+
let nextCellIndex;
|
10890
|
+
switch (moveDirection) {
|
10891
|
+
case MOVE_DIR.FIRST:
|
10892
|
+
nextCellIndex = firstDataColumnIndex;
|
10893
|
+
break;
|
10894
|
+
case MOVE_DIR.LAST:
|
10895
|
+
nextCellIndex = lastDataColumnIndex;
|
10896
|
+
break;
|
10897
|
+
case MOVE_DIR.PREV:
|
10898
|
+
// moves to the last data column of the previous row, if the current column is the first column
|
10899
|
+
if (currentColumnIndex === firstDataColumnIndex) {
|
10900
|
+
moveRow === null || moveRow === void 0 ? void 0 : moveRow(MOVE_DIR.PREV);
|
10901
|
+
nextCellIndex = lastDataColumnIndex;
|
10902
|
+
} else {
|
10903
|
+
nextCellIndex = focussableColumnIndexes[getNextIndex(-1, currentColumnIndex, focussableColumnIndexes)];
|
10904
|
+
}
|
10905
|
+
break;
|
10906
|
+
case MOVE_DIR.NEXT:
|
10907
|
+
// moves to the first data column of the next row, if the current column is the last column
|
10908
|
+
if (currentColumnIndex === lastDataColumnIndex) {
|
10909
|
+
moveRow === null || moveRow === void 0 ? void 0 : moveRow(MOVE_DIR.NEXT);
|
10910
|
+
nextCellIndex = firstDataColumnIndex;
|
10911
|
+
} else {
|
10912
|
+
nextCellIndex = focussableColumnIndexes[getNextIndex(1, currentColumnIndex, focussableColumnIndexes)];
|
10913
|
+
}
|
10914
|
+
break;
|
10915
|
+
}
|
10916
|
+
return {
|
10917
|
+
...currentEditMode,
|
10918
|
+
columnIndex: nextCellIndex
|
10919
|
+
};
|
10920
|
+
});
|
10921
|
+
};
|
10922
|
+
// output
|
10923
|
+
const toggleEditing = (isEditing, columnIndex = 0) => {
|
10924
|
+
if (!editMode.enableEditMode) {
|
10925
|
+
return;
|
10926
|
+
}
|
10927
|
+
setEditMode(editMode => ({
|
10928
|
+
...editMode,
|
10929
|
+
isEditing: isEditing !== null && isEditing !== void 0 ? isEditing : !editMode.isEditing,
|
10930
|
+
columnIndex
|
10931
|
+
}));
|
10932
|
+
};
|
10933
|
+
const moveToPreviousColumn = (focussableColumnIndexes, moveRow) => _moveActiveColumn(MOVE_DIR.PREV, focussableColumnIndexes, moveRow);
|
10934
|
+
const moveToNextColumn = (focussableColumnIndexes, moveRow) => _moveActiveColumn(MOVE_DIR.NEXT, focussableColumnIndexes, moveRow);
|
10935
|
+
const moveToFirstColumn = focussableColumnIndexes => _moveActiveColumn(MOVE_DIR.FIRST, focussableColumnIndexes);
|
10936
|
+
const moveToLastColumn = focussableColumnIndexes => _moveActiveColumn(MOVE_DIR.LAST, focussableColumnIndexes);
|
10937
|
+
const setColumn = columnIndex => {
|
10938
|
+
if (!editMode.enableEditMode) {
|
10939
|
+
return;
|
10940
|
+
}
|
10941
|
+
setEditMode(currentEditMode => ({
|
10942
|
+
...currentEditMode,
|
10943
|
+
columnIndex
|
10944
|
+
}));
|
10945
|
+
};
|
10946
|
+
return {
|
10947
|
+
...editMode,
|
10948
|
+
onSave: handleSave,
|
10949
|
+
toggleEditing,
|
10950
|
+
moveToPreviousColumn,
|
10951
|
+
moveToNextColumn,
|
10952
|
+
moveToFirstColumn,
|
10953
|
+
moveToLastColumn,
|
10954
|
+
setColumn
|
10955
|
+
};
|
10956
|
+
};
|
10957
|
+
const getNextIndex = (direction, currentIndex, focussableColumnIndexes) => {
|
10958
|
+
const currentIndexPosition = focussableColumnIndexes.indexOf(currentIndex);
|
10959
|
+
const length = focussableColumnIndexes.length;
|
10960
|
+
if (direction === -1) {
|
10961
|
+
return currentIndexPosition - 1 > 0 ? currentIndexPosition - 1 : 0;
|
10962
|
+
}
|
10963
|
+
return currentIndexPosition + 1 < length ? currentIndexPosition + 1 : currentIndexPosition;
|
10964
|
+
};
|
10965
|
+
|
10966
|
+
const RowContext = /*#__PURE__*/React__default.createContext({
|
10967
|
+
validationErrors: null,
|
10968
|
+
setValidationErrors: () => undefined,
|
10969
|
+
isRowIndicatorVisible: false,
|
10970
|
+
setIsRowIndicatorVisible: () => undefined
|
10971
|
+
});
|
10972
|
+
const useRowContext = () => {
|
10973
|
+
const context = React__default.useContext(RowContext);
|
10974
|
+
if (context === undefined) {
|
10975
|
+
throw new Error('useRowContext must be used within a RowProvider');
|
10976
|
+
}
|
10977
|
+
return context;
|
10978
|
+
};
|
10979
|
+
const RowProvider = ({
|
10980
|
+
children,
|
10981
|
+
...providerProps
|
10982
|
+
}) => {
|
10983
|
+
return /*#__PURE__*/React__default.createElement(RowContext.Provider, {
|
10984
|
+
value: providerProps
|
10985
|
+
}, children);
|
10986
|
+
};
|
10987
|
+
|
10988
|
+
var IndicatorReason;
|
10989
|
+
(function (IndicatorReason) {
|
10990
|
+
IndicatorReason["SEARCH"] = "SEARCH";
|
10991
|
+
IndicatorReason["SORTING"] = "SORTING";
|
10992
|
+
IndicatorReason["FILTER"] = "FILTER";
|
10993
|
+
})(IndicatorReason || (IndicatorReason = {}));
|
10994
|
+
const useIndicatorText = reason => {
|
10995
|
+
let title = '';
|
10996
|
+
let description = '';
|
10997
|
+
const {
|
10998
|
+
texts: {
|
10999
|
+
table2: tableTexts
|
11000
|
+
}
|
11001
|
+
} = useLocalization();
|
11002
|
+
switch (reason) {
|
11003
|
+
case IndicatorReason.SEARCH:
|
11004
|
+
title = tableTexts.rowWillBeFiltered;
|
11005
|
+
description = tableTexts.searchFilterMovementReason;
|
11006
|
+
break;
|
11007
|
+
case IndicatorReason.SORTING:
|
11008
|
+
title = tableTexts.rowWillMove;
|
11009
|
+
description = tableTexts.sortingMovementReason;
|
11010
|
+
break;
|
11011
|
+
case IndicatorReason.FILTER:
|
11012
|
+
title = tableTexts.rowWillBeFiltered;
|
11013
|
+
description = tableTexts.tableFilterMovementReason;
|
11014
|
+
break;
|
11015
|
+
}
|
11016
|
+
return {
|
11017
|
+
title,
|
11018
|
+
description
|
11019
|
+
};
|
11020
|
+
};
|
11021
|
+
const Indicator = ({
|
11022
|
+
reason,
|
11023
|
+
columnName,
|
11024
|
+
mountNode
|
11025
|
+
}) => {
|
11026
|
+
const container = React__default.useMemo(() => {
|
11027
|
+
const element = document.createElement('div');
|
11028
|
+
element.className += '-translate-y-1/2 z-[13] rounded-full items-center wcag-blue-500 absolute left-0 top-full ml-1 whitespace-nowrap px-1 py-0.5 text-xs font-bold shadow-sm';
|
11029
|
+
return element;
|
11030
|
+
}, []);
|
11031
|
+
const indicatorText = useIndicatorText(reason);
|
11032
|
+
const {
|
11033
|
+
validationErrors
|
11034
|
+
} = useRowContext();
|
11035
|
+
const hasValidationErrorsInRow = !!validationErrors;
|
11036
|
+
React__default.useEffect(() => {
|
11037
|
+
// mountNode could be null when rows are filtered
|
11038
|
+
mountNode === null || mountNode === void 0 ? void 0 : mountNode.classList.add('relative');
|
11039
|
+
mountNode === null || mountNode === void 0 ? void 0 : mountNode.appendChild(container);
|
11040
|
+
return () => {
|
11041
|
+
mountNode === null || mountNode === void 0 ? void 0 : mountNode.classList.remove('relative');
|
11042
|
+
mountNode === null || mountNode === void 0 ? void 0 : mountNode.removeChild(container);
|
11043
|
+
};
|
11044
|
+
}, [hasValidationErrorsInRow]);
|
11045
|
+
// Using react portal inside a react tree component is an unorthodox way, but in order to avoid much code refactoring
|
11046
|
+
// and being able to use Taco Tooltip component in side the visual indicator, portal is used.
|
11047
|
+
return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React__default.createElement(Tooltip, {
|
11048
|
+
title: indicatorText.description.replace('[COLUMN]', columnName)
|
11049
|
+
}, /*#__PURE__*/React__default.createElement("span", {
|
11050
|
+
className: "flex gap-1 hover:cursor-pointer"
|
11051
|
+
}, /*#__PURE__*/React__default.createElement(Icon, {
|
11052
|
+
name: "info",
|
11053
|
+
className: "!h-4 !w-4 rounded-full bg-white !p-0 text-blue-500"
|
11054
|
+
}), indicatorText.title)), container);
|
11055
|
+
};
|
11056
|
+
|
11057
|
+
const useTruncated = (element, deps = []) => {
|
11058
|
+
const isTruncated = targetElement => {
|
11059
|
+
if (targetElement !== null) {
|
11060
|
+
return targetElement.offsetWidth < targetElement.scrollWidth;
|
11061
|
+
}
|
11062
|
+
return false;
|
11063
|
+
};
|
11064
|
+
const [truncated, setTruncated] = React__default.useState(isTruncated(element));
|
11065
|
+
React__default.useEffect(() => {
|
11066
|
+
setTruncated(isTruncated(element));
|
11067
|
+
}, [element, ...deps]);
|
11068
|
+
return {
|
11069
|
+
truncated
|
11070
|
+
};
|
11071
|
+
};
|
11072
|
+
|
11073
|
+
const ValidationError = ({
|
11074
|
+
className,
|
11075
|
+
...props
|
11076
|
+
}) => {
|
11077
|
+
const ref = React__default.useRef(null);
|
11078
|
+
const {
|
11079
|
+
truncated
|
11080
|
+
} = useTruncated(ref.current);
|
11081
|
+
const error = /*#__PURE__*/React__default.createElement("span", Object.assign({
|
11082
|
+
className: cn('truncate px-px text-xs font-normal leading-normal text-red-500', {
|
11083
|
+
'hover:cursor-pointer': truncated
|
11084
|
+
}, className),
|
11085
|
+
ref: ref,
|
11086
|
+
role: "alert"
|
11087
|
+
}, props));
|
11088
|
+
if (truncated) {
|
11089
|
+
return /*#__PURE__*/React__default.createElement(Tooltip, {
|
11090
|
+
title: props.children
|
11091
|
+
}, error);
|
11092
|
+
}
|
11093
|
+
return error;
|
11094
|
+
};
|
11095
|
+
|
11096
|
+
const hasChanged = (value, newValue) => {
|
11097
|
+
if (dateFns.isDate(value) && dateFns.isDate(newValue)) {
|
11098
|
+
return !isWeakEqual(value, newValue);
|
11099
|
+
} else if (Array.isArray(value)) {
|
11100
|
+
return JSON.stringify(value) !== JSON.stringify(newValue);
|
11101
|
+
}
|
11102
|
+
return value !== newValue;
|
11103
|
+
};
|
11104
|
+
const willRowMoveAfterSorting = (value, cell, rowIndex, rows, desc) => {
|
11105
|
+
const miniSortRows = [{
|
11106
|
+
...cell.row,
|
11107
|
+
original: {
|
11108
|
+
...cell.row.original,
|
11109
|
+
[cell.column.id]: value
|
11110
|
+
}
|
11111
|
+
}];
|
11112
|
+
// getValue is used by the built-in sort functons, so we need to make sure it returns the changed value
|
11113
|
+
miniSortRows[0].getValue = () => value;
|
11114
|
+
let index = 0;
|
11115
|
+
if (rowIndex > 0) {
|
11116
|
+
miniSortRows.unshift(rows[rowIndex - 1]);
|
11117
|
+
index = 1;
|
11118
|
+
}
|
11119
|
+
if (rowIndex < rows.length - 1) {
|
11120
|
+
miniSortRows.push(rows[rowIndex + 1]);
|
11121
|
+
}
|
11122
|
+
let resortedRows = [...miniSortRows].sort((a, b) => cell.column.getSortingFn()(a, b, cell.column.id));
|
11123
|
+
if (desc) {
|
11124
|
+
resortedRows = resortedRows.reverse();
|
11125
|
+
}
|
11126
|
+
return resortedRows[index].id !== cell.row.id;
|
11127
|
+
};
|
11128
|
+
|
11129
|
+
const Cell = function Cell(props) {
|
11130
|
+
var _cell$column$columnDe, _cell$column$columnDe2, _cell$column$columnDe3, _table$options$meta;
|
11131
|
+
const {
|
11132
|
+
cell,
|
11133
|
+
index,
|
11134
|
+
isLastRow,
|
11135
|
+
rowIndex,
|
11136
|
+
rows,
|
11137
|
+
scrollToIndex,
|
11138
|
+
scrollToOffset,
|
11139
|
+
table,
|
11140
|
+
tableRef,
|
11141
|
+
...columnProps
|
11142
|
+
} = props;
|
11143
|
+
const meta = table.options.meta;
|
11144
|
+
const {
|
11145
|
+
addFocussableColumnIndex,
|
11146
|
+
focussableColumnIndexes: allFocussableColumnIndexes
|
11147
|
+
} = meta;
|
11148
|
+
const {
|
11149
|
+
validationErrors,
|
11150
|
+
isRowIndicatorVisible
|
11151
|
+
} = useRowContext();
|
11152
|
+
const hasValidationErrorsInRow = !!validationErrors;
|
11153
|
+
const internalRef = React__default.useRef(null);
|
11154
|
+
const controlRef = React__default.useRef(null);
|
11155
|
+
const disableTruncation = (_cell$column$columnDe = cell.column.columnDef.meta) === null || _cell$column$columnDe === void 0 ? void 0 : _cell$column$columnDe.disableTruncation;
|
11156
|
+
const cellClassName = (_cell$column$columnDe2 = cell.column.columnDef.meta) === null || _cell$column$columnDe2 === void 0 ? void 0 : _cell$column$columnDe2.className;
|
11157
|
+
const isActiveRow = meta.activeRowIndex === rowIndex;
|
11158
|
+
const isHoveredRow = meta.hoveredRowIndex === rowIndex;
|
11159
|
+
const isPinned = !!cell.column.getIsPinned();
|
11160
|
+
const isDragging = meta.dragging[cell.row.id];
|
11161
|
+
const isSelected = cell.row.getIsSelected();
|
11162
|
+
const isDataColumn = !isInternalColumn(cell.column.id);
|
11163
|
+
const hasCellControl = !!((_cell$column$columnDe3 = cell.column.columnDef.meta) !== null && _cell$column$columnDe3 !== void 0 && _cell$column$columnDe3.control);
|
11164
|
+
const allVisibleColumns = table.getVisibleLeafColumns();
|
11165
|
+
const lastColumnIndex = allVisibleColumns.length > 0 ? allVisibleColumns.length - 1 : 0;
|
11166
|
+
// editing
|
11167
|
+
const isEditingThisRow = meta.editMode.isEditing && isActiveRow;
|
11168
|
+
const canEditThisCell = isEditingThisRow && isDataColumn;
|
11169
|
+
const isEditingThisCell = canEditThisCell && meta.editMode.columnIndex === index;
|
11170
|
+
const isHoveringThisRowWhileEditing = meta.editMode.isEditing && isHoveredRow;
|
11171
|
+
// ensure the active row is always visible
|
11172
|
+
React__default.useEffect(() => {
|
11173
|
+
if (isActiveRow && internalRef.current) {
|
11174
|
+
internalRef.current.scrollIntoView({
|
11175
|
+
behavior: 'smooth',
|
11176
|
+
block: 'nearest',
|
11177
|
+
inline: 'nearest'
|
11178
|
+
});
|
11179
|
+
}
|
11180
|
+
}, [isActiveRow, hasValidationErrorsInRow]);
|
11181
|
+
React__default.useEffect(() => {
|
11182
|
+
// Adds padding to the table so that indicator doesn't get cropped
|
11183
|
+
if (isRowIndicatorVisible && meta.activeRowIndex === rows.length - 1) {
|
11184
|
+
var _tableRef$current;
|
11185
|
+
(_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : _tableRef$current.classList.add('pb-4');
|
11186
|
+
}
|
11187
|
+
return () => {
|
11188
|
+
var _tableRef$current2;
|
11189
|
+
return (_tableRef$current2 = tableRef.current) === null || _tableRef$current2 === void 0 ? void 0 : _tableRef$current2.classList.remove('pb-4');
|
11190
|
+
};
|
11191
|
+
}, [isRowIndicatorVisible]);
|
11192
|
+
const className = cn({
|
11193
|
+
'border-b': !isLastRow,
|
11194
|
+
'sticky z-10': isPinned,
|
11195
|
+
// use isHoveredRow rather than css group-hover/row because we want to hide hover state when keyboard navigating
|
11196
|
+
'bg-white': !isActiveRow && !isSelected && !isHoveredRow,
|
11197
|
+
'bg-grey-100': !isActiveRow && !isSelected && isHoveredRow,
|
11198
|
+
'bg-grey-200 group-hover/row:bg-grey-200': isActiveRow && !isSelected,
|
11199
|
+
'bg-blue-100': isSelected,
|
11200
|
+
'!wcag-blue-500': isDragging,
|
11201
|
+
'[&>*]:!grayscale [&_.bg-white]:!bg-grey-100': !isEditingThisRow && isHoveringThisRowWhileEditing,
|
11202
|
+
'!bg-red-100': hasValidationErrorsInRow,
|
11203
|
+
'z-[11]': isPinned && isActiveRow,
|
11204
|
+
'z-[12]': isPinned && isActiveRow && index === 0,
|
11205
|
+
'border-blue !border-y-2 border-x-0': isRowIndicatorVisible,
|
11206
|
+
'border-l-2 rounded-l': isRowIndicatorVisible && index === 0,
|
11207
|
+
'border-r-2 rounded-r': isRowIndicatorVisible && index === lastColumnIndex
|
11208
|
+
}, getCellSizingClasses((_table$options$meta = table.options.meta) === null || _table$options$meta === void 0 ? void 0 : _table$options$meta.rowDensity, (isEditingThisRow || isHoveringThisRowWhileEditing) && hasCellControl), typeof cellClassName === 'function' ? cellClassName(cell.row) : cellClassName);
|
11209
|
+
const handleMouseDown = event => {
|
11210
|
+
// only detect left clicks
|
11211
|
+
if (event.button === 0) {
|
11212
|
+
const activeElement = document.activeElement;
|
11213
|
+
const isActiveElementControl = activeElement === null || activeElement === void 0 ? void 0 : activeElement.closest('[role="cell"]');
|
11214
|
+
const hasActiveRowChanged = meta.activeRowIndex !== rowIndex;
|
11215
|
+
// When user clicks on a cell that is not in the active row, for some reason blur event is not called on the cell
|
11216
|
+
// previous cell control element so we need to manually call it in order to save the changes in that cell
|
11217
|
+
if (isActiveElementControl && hasActiveRowChanged) {
|
11218
|
+
activeElement.blur();
|
11219
|
+
}
|
11220
|
+
meta.setActiveRowIndex(rowIndex);
|
11221
|
+
if (meta.editMode.isEditing) {
|
11222
|
+
if (allFocussableColumnIndexes.includes(index)) {
|
11223
|
+
meta.editMode.setColumn(index);
|
11224
|
+
} else {
|
11225
|
+
meta.editMode.setColumn(allFocussableColumnIndexes[0]);
|
11226
|
+
}
|
11227
|
+
}
|
11228
|
+
}
|
11229
|
+
};
|
11230
|
+
const attributes = {
|
11231
|
+
...columnProps,
|
11232
|
+
// base props,
|
11233
|
+
column: cell.column,
|
11234
|
+
table,
|
11235
|
+
// dom attributes
|
11236
|
+
className,
|
11237
|
+
'data-column-index': index,
|
11238
|
+
'data-row-index': rowIndex,
|
11239
|
+
onMouseDown: handleMouseDown,
|
11240
|
+
ref: internalRef,
|
11241
|
+
role: 'cell'
|
11242
|
+
};
|
11243
|
+
const [detailModeEditing, setDetailModeEditing] = React__default.useState(false);
|
11244
|
+
// reset the editing state when we move column
|
11245
|
+
React__default.useEffect(() => {
|
11246
|
+
if (meta.editMode.columnIndex !== index) {
|
11247
|
+
setDetailModeEditing(false);
|
11248
|
+
}
|
11249
|
+
}, [meta.editMode.columnIndex]);
|
11250
|
+
React__default.useEffect(() => {
|
11251
|
+
if (isEditingThisRow && controlRef.current && isKeyboardFocusableElement(controlRef.current)) {
|
11252
|
+
addFocussableColumnIndex(index);
|
11253
|
+
}
|
11254
|
+
}, [isEditingThisRow, allFocussableColumnIndexes, addFocussableColumnIndex, index]);
|
11255
|
+
const moveRow = moveDirection => {
|
11256
|
+
if (moveDirection === MOVE_DIR.PREV) {
|
11257
|
+
meta.moveToPreviousRow(rows, nextIndex => scrollToIndex(nextIndex - 1));
|
11258
|
+
} else if (moveDirection === MOVE_DIR.NEXT) {
|
11259
|
+
meta.moveToNextRow(rows, nextIndex => scrollToIndex(nextIndex + 2));
|
11260
|
+
}
|
11261
|
+
};
|
11262
|
+
if (meta.editMode.onSave && hasCellControl && (canEditThisCell || isHoveringThisRowWhileEditing && isDataColumn)) {
|
11263
|
+
attributes.onMouseDown = event => {
|
11264
|
+
handleMouseDown(event);
|
11265
|
+
const target = event.target;
|
11266
|
+
const isTargetInput = target !== null && target.nodeName === 'INPUT';
|
11267
|
+
// event.target?.select is only truthy for input elements
|
11268
|
+
// if event.target is active element, then that means we should select the text
|
11269
|
+
if (isTargetInput && target !== document.activeElement) {
|
11270
|
+
event.preventDefault();
|
11271
|
+
setTimeout(() => {
|
11272
|
+
target.select();
|
11273
|
+
}, 1);
|
11274
|
+
} else if (isTargetInput && target === document.activeElement) {
|
11275
|
+
// if user left clicks on the input then we are into edit mode
|
11276
|
+
// only detect left clicks
|
11277
|
+
if (event.button === 0) {
|
11278
|
+
setDetailModeEditing(true);
|
11279
|
+
}
|
11280
|
+
}
|
11281
|
+
};
|
11282
|
+
if (canEditThisCell) {
|
11283
|
+
var _allFocussableColumnI, _allFocussableColumnI2;
|
11284
|
+
const firstDataColumnIndex = (_allFocussableColumnI = allFocussableColumnIndexes.at(0)) !== null && _allFocussableColumnI !== void 0 ? _allFocussableColumnI : 0;
|
11285
|
+
const lastDataColumnIndex = (_allFocussableColumnI2 = allFocussableColumnIndexes.at(-1)) !== null && _allFocussableColumnI2 !== void 0 ? _allFocussableColumnI2 : 0;
|
11286
|
+
attributes.onKeyDown = event => {
|
11287
|
+
const control = event.target;
|
11288
|
+
const isControlInput = control.nodeName === 'INPUT' && (control === null || control === void 0 ? void 0 : control.getAttribute('data-inline-editing-component')) === 'true';
|
11289
|
+
// For some reason, Taco Input keyboard event always return true when "event.isDefaultPrevented()" is
|
11290
|
+
// called. So we need to check if the control is input or not so that we don't return early.
|
11291
|
+
if (!isControlInput && (event.isDefaultPrevented() || event.isPropagationStopped())) {
|
11292
|
+
return;
|
11293
|
+
}
|
11294
|
+
if (control.tagName === 'INPUT') {
|
11295
|
+
if (event.key === 'Enter') {
|
11296
|
+
event.preventDefault();
|
11297
|
+
const input = control;
|
11298
|
+
if (detailModeEditing) {
|
11299
|
+
var _input$select;
|
11300
|
+
input === null || input === void 0 ? void 0 : (_input$select = input.select) === null || _input$select === void 0 ? void 0 : _input$select.call(input);
|
11301
|
+
setDetailModeEditing(false);
|
11302
|
+
} else {
|
11303
|
+
var _input$setSelectionRa, _input$value, _input$value2;
|
11304
|
+
(_input$setSelectionRa = input.setSelectionRange) === null || _input$setSelectionRa === void 0 ? void 0 : _input$setSelectionRa.call(input, (_input$value = input.value) === null || _input$value === void 0 ? void 0 : _input$value.length, (_input$value2 = input.value) === null || _input$value2 === void 0 ? void 0 : _input$value2.length);
|
11305
|
+
setDetailModeEditing(true);
|
11306
|
+
}
|
11307
|
+
return;
|
11308
|
+
}
|
11309
|
+
}
|
11310
|
+
// Don't exit edit mode if the target of the escape isn't a child of the cell (e.g. if its a popover).
|
11311
|
+
if (event.key === 'Escape' && event.currentTarget.contains(control)) {
|
11312
|
+
var _tableRef$current3;
|
11313
|
+
event.preventDefault();
|
11314
|
+
meta.editMode.toggleEditing(false);
|
11315
|
+
(_tableRef$current3 = tableRef.current) === null || _tableRef$current3 === void 0 ? void 0 : _tableRef$current3.focus();
|
11316
|
+
return;
|
11317
|
+
}
|
11318
|
+
if (!detailModeEditing && event.key === 'ArrowLeft' || event.key === 'Tab' && event.shiftKey) {
|
11319
|
+
event.preventDefault();
|
11320
|
+
const isFirstRow = rowIndex === 0;
|
11321
|
+
const isFirstColumn = index === firstDataColumnIndex;
|
11322
|
+
if (event.ctrlKey || event.metaKey) {
|
11323
|
+
// If the current active column is the first column then we don't do any thing so that focus
|
11324
|
+
// remains on the first column.
|
11325
|
+
if (!isFirstColumn) {
|
11326
|
+
control.blur();
|
11327
|
+
meta.editMode.moveToFirstColumn(allFocussableColumnIndexes);
|
11328
|
+
}
|
11329
|
+
} else {
|
11330
|
+
// If it is first row and first column, then don't move column.
|
11331
|
+
if (!isFirstRow || !isFirstColumn) {
|
11332
|
+
control.blur();
|
11333
|
+
meta.editMode.moveToPreviousColumn(allFocussableColumnIndexes, moveRow);
|
11334
|
+
}
|
11335
|
+
}
|
11336
|
+
return;
|
11337
|
+
}
|
11338
|
+
if (!detailModeEditing && event.key === 'ArrowRight' || event.key === 'Tab' && !event.shiftKey) {
|
11339
|
+
event.preventDefault();
|
11340
|
+
const isLastRow = rowIndex === rows.length - 1;
|
11341
|
+
const isLastColumn = index === lastDataColumnIndex;
|
11342
|
+
if (event.ctrlKey || event.metaKey) {
|
11343
|
+
// If the current active column is the last column then we don't do any thing so that focus
|
11344
|
+
// remains on the last column.
|
11345
|
+
if (!isLastColumn) {
|
11346
|
+
control.blur();
|
11347
|
+
meta.editMode.moveToLastColumn(allFocussableColumnIndexes);
|
11348
|
+
}
|
11349
|
+
} else {
|
11350
|
+
// If it is last row and last column, then don't move column.
|
11351
|
+
if (!isLastRow || !isLastColumn) {
|
11352
|
+
control.blur();
|
11353
|
+
meta.editMode.moveToNextColumn(allFocussableColumnIndexes, moveRow);
|
11354
|
+
}
|
11355
|
+
}
|
11356
|
+
return;
|
11357
|
+
}
|
11358
|
+
if (!detailModeEditing && event.key === 'ArrowUp') {
|
11359
|
+
event.preventDefault();
|
11360
|
+
// if it is the first row then return early, so that focus on the cell is not lost
|
11361
|
+
if (rowIndex === 0) {
|
11362
|
+
return;
|
11363
|
+
}
|
11364
|
+
control.blur();
|
11365
|
+
if (event.ctrlKey || event.metaKey) {
|
11366
|
+
meta.setActiveRowIndex(0);
|
11367
|
+
scrollToOffset(0);
|
11368
|
+
} else {
|
11369
|
+
moveRow(MOVE_DIR.PREV);
|
11370
|
+
}
|
11371
|
+
meta.setHoveredRowIndex(undefined);
|
11372
|
+
return;
|
11373
|
+
}
|
11374
|
+
if (!detailModeEditing && event.key === 'ArrowDown') {
|
11375
|
+
event.preventDefault();
|
11376
|
+
// if it is the last row then return early, so that focus on the cell is not lost
|
11377
|
+
if (rowIndex === rows.length - 1) {
|
11378
|
+
return;
|
11379
|
+
}
|
11380
|
+
control.blur();
|
11381
|
+
if (event.ctrlKey || event.metaKey) {
|
11382
|
+
meta.setActiveRowIndex(rows.length - 1);
|
11383
|
+
scrollToIndex(rows.length + 20);
|
11384
|
+
} else {
|
11385
|
+
moveRow(MOVE_DIR.NEXT);
|
11386
|
+
}
|
11387
|
+
meta.setHoveredRowIndex(undefined);
|
11388
|
+
return;
|
11389
|
+
}
|
11390
|
+
};
|
11391
|
+
}
|
11392
|
+
return /*#__PURE__*/React__default.createElement(ColumnBase, Object.assign({}, attributes), /*#__PURE__*/React__default.createElement(EditingCell, {
|
11393
|
+
cell: cell,
|
11394
|
+
cellRef: internalRef,
|
11395
|
+
columnIndex: index,
|
11396
|
+
isEditingThisCell: isEditingThisCell,
|
11397
|
+
onSave: meta.editMode.onSave,
|
11398
|
+
rowIndex: rowIndex,
|
11399
|
+
table: table,
|
11400
|
+
ref: controlRef,
|
11401
|
+
rowValues: rows[rowIndex].original,
|
11402
|
+
rowsLength: rows.length
|
11403
|
+
}));
|
11404
|
+
} else {
|
11405
|
+
if (meta.onRowClick) {
|
11406
|
+
attributes.onClick = () => {
|
11407
|
+
var _meta$onRowClick;
|
11408
|
+
(_meta$onRowClick = meta.onRowClick) === null || _meta$onRowClick === void 0 ? void 0 : _meta$onRowClick.call(meta, cell.row.original);
|
11409
|
+
};
|
11410
|
+
}
|
11411
|
+
}
|
11412
|
+
return /*#__PURE__*/React__default.createElement(ColumnBase, Object.assign({}, attributes), /*#__PURE__*/React__default.createElement("div", {
|
11413
|
+
className: disableTruncation ? '-my-[0.45rem]' : 'truncate'
|
11414
|
+
}, reactTable$1.flexRender(cell.column.columnDef.cell, cell.getContext())));
|
11415
|
+
};
|
11416
|
+
const EditingCell = /*#__PURE__*/React__default.memo( /*#__PURE__*/React__default.forwardRef((props, ref) => {
|
11417
|
+
var _cell$column$columnDe4, _cell$column$columnDe5, _cellRef$current, _cellRef$current$pare;
|
11418
|
+
const {
|
11419
|
+
cell,
|
11420
|
+
cellRef,
|
11421
|
+
columnIndex,
|
11422
|
+
isEditingThisCell = false,
|
11423
|
+
onSave: handleSave,
|
11424
|
+
rowIndex,
|
11425
|
+
rowValues,
|
11426
|
+
table
|
11427
|
+
} = props;
|
11428
|
+
const {
|
11429
|
+
validationErrors,
|
11430
|
+
setValidationErrors,
|
11431
|
+
setIsRowIndicatorVisible
|
11432
|
+
} = useRowContext();
|
11433
|
+
const controlRef = useMergedRef(ref);
|
11434
|
+
const cellId = cell.column.id;
|
11435
|
+
const cellValidationError = validationErrors === null || validationErrors === void 0 ? void 0 : validationErrors[cellId];
|
11436
|
+
const value = cell.getValue();
|
11437
|
+
const ariaLabel = cell.column.columnDef.header;
|
11438
|
+
const meta = table.options.meta;
|
11439
|
+
const {
|
11440
|
+
globalFilter
|
11441
|
+
} = table.getState();
|
11442
|
+
const [state, setState] = React__default.useState(value);
|
11443
|
+
const [rowMoveReason, setRowMoveReason] = React__default.useState(null);
|
11444
|
+
const isHoveringAnotherRowWhileEditing = meta.editMode.isEditing && meta.activeRowIndex !== rowIndex && meta.hoveredRowIndex === rowIndex;
|
11445
|
+
const showValidationError = !isHoveringAnotherRowWhileEditing && !!cellValidationError;
|
11446
|
+
// On each save, the initialValue will be set to the new value of the cell
|
11447
|
+
const initialValue = React__default.useRef(value);
|
11448
|
+
// It is important that we let consumers pass a newValue as an argument because when setState is called before
|
11449
|
+
// onBlur then saveIfChanged method gets the stale state value. This happens because the rerender hasn't happened
|
11450
|
+
// before the saveIfChanged method is called.
|
11451
|
+
const saveIfChanged = function (eventOrNewValue) {
|
11452
|
+
try {
|
11453
|
+
let newValue = state;
|
11454
|
+
// if eventOrNewValue is not an event object
|
11455
|
+
if (!eventOrNewValue.target) {
|
11456
|
+
newValue = eventOrNewValue;
|
11457
|
+
}
|
11458
|
+
const _temp2 = function () {
|
11459
|
+
if (hasChanged(value, newValue)) {
|
11460
|
+
const _temp = _catch(function () {
|
11461
|
+
const updatedRow = {
|
11462
|
+
...cell.row.original,
|
11463
|
+
[cellId]: newValue
|
11464
|
+
};
|
11465
|
+
return Promise.resolve(handleSave(updatedRow, cellId)).then(function () {
|
11466
|
+
// Reset error if save was successful
|
11467
|
+
setValidationErrors(null);
|
11468
|
+
});
|
11469
|
+
}, function (error) {
|
11470
|
+
setValidationErrors(error);
|
11471
|
+
});
|
11472
|
+
if (_temp && _temp.then) return _temp.then(function () {});
|
11473
|
+
}
|
11474
|
+
}();
|
11475
|
+
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
|
11476
|
+
} catch (e) {
|
11477
|
+
return Promise.reject(e);
|
11478
|
+
}
|
11479
|
+
};
|
11480
|
+
// Ensures we "auto focus" the field if the cell is being edited.
|
11481
|
+
React__default.useEffect(() => {
|
11482
|
+
var _meta$tableRef$curren;
|
11483
|
+
const isFocusInsideTable = (_meta$tableRef$curren = meta.tableRef.current) === null || _meta$tableRef$curren === void 0 ? void 0 : _meta$tableRef$curren.contains(document.activeElement);
|
11484
|
+
// When control is blurred then body gets the focus that's why we have to make sure if activeElement
|
11485
|
+
// is body then we focus the cell if it is being edited.
|
11486
|
+
const isBodyFocussed = document.body === document.activeElement;
|
11487
|
+
// Don't focus cell if any table popup(filter popup, column settings popup) is open.
|
11488
|
+
if (isEditingThisCell && (isFocusInsideTable || isBodyFocussed)) {
|
11489
|
+
var _controlRef$current, _controlRef$current$f;
|
11490
|
+
(_controlRef$current = controlRef.current) === null || _controlRef$current === void 0 ? void 0 : (_controlRef$current$f = _controlRef$current.focus) === null || _controlRef$current$f === void 0 ? void 0 : _controlRef$current$f.call(_controlRef$current);
|
11491
|
+
}
|
11492
|
+
}, [isEditingThisCell, controlRef.current]);
|
11493
|
+
// make sure the cell becomes active if the field is focused
|
11494
|
+
const handleFocus = event => {
|
11495
|
+
var _event$target;
|
11496
|
+
meta.editMode.setColumn(columnIndex);
|
11497
|
+
if ((_event$target = event.target) !== null && _event$target !== void 0 && _event$target.select) {
|
11498
|
+
var _event$target2;
|
11499
|
+
(_event$target2 = event.target) === null || _event$target2 === void 0 ? void 0 : _event$target2.select();
|
11500
|
+
}
|
11501
|
+
};
|
11502
|
+
React__default.useEffect(() => {
|
11503
|
+
if (hasChanged(initialValue.current, state)) {
|
11504
|
+
showIndicator();
|
11505
|
+
} else {
|
11506
|
+
hideIndicator();
|
11507
|
+
}
|
11508
|
+
return hideIndicator;
|
11509
|
+
}, [state]);
|
11510
|
+
const showIndicator = () => {
|
11511
|
+
var _table$getState$sorti;
|
11512
|
+
let willRowMoveReason = undefined;
|
11513
|
+
const isFilteredByGlobalFilter = Object.values({
|
11514
|
+
...rowValues,
|
11515
|
+
[cellId]: state
|
11516
|
+
}).some(cellValue =>
|
11517
|
+
// Global filter can be undefined when there is no text being searched so we pass an empty string to
|
11518
|
+
// globalFilterFn as query in that case.
|
11519
|
+
globalFilterFn(String(cellValue), globalFilter ? String(globalFilter) : ''));
|
11520
|
+
if (!isFilteredByGlobalFilter) {
|
11521
|
+
willRowMoveReason = IndicatorReason.SEARCH;
|
11522
|
+
} else if (cell.column.getIsFiltered() && !columnFilterFn(state, cell.column.getFilterValue())) {
|
11523
|
+
willRowMoveReason = IndicatorReason.FILTER;
|
11524
|
+
} else if (!willRowMoveReason && cell.column.getIsSorted() && willRowMoveAfterSorting(state, cell, rowIndex, table.getRowModel().rows, !!((_table$getState$sorti = table.getState().sorting.find(s => s.id === cell.column.id)) !== null && _table$getState$sorti !== void 0 && _table$getState$sorti.desc))) {
|
11525
|
+
willRowMoveReason = IndicatorReason.SORTING;
|
11526
|
+
}
|
11527
|
+
if (willRowMoveReason !== undefined) {
|
11528
|
+
meta.setShouldPauseSortingAndFiltering(true);
|
11529
|
+
setRowMoveReason(willRowMoveReason);
|
11530
|
+
setIsRowIndicatorVisible(true);
|
11531
|
+
}
|
11532
|
+
};
|
11533
|
+
const hideIndicator = () => {
|
11534
|
+
setRowMoveReason(null);
|
11535
|
+
setIsRowIndicatorVisible(false);
|
11536
|
+
};
|
11537
|
+
const cellControl = (_cell$column$columnDe4 = cell.column.columnDef.meta) === null || _cell$column$columnDe4 === void 0 ? void 0 : _cell$column$columnDe4.control;
|
11538
|
+
const attributes = {
|
11539
|
+
'aria-label': ariaLabel,
|
11540
|
+
onBlur: saveIfChanged,
|
11541
|
+
onFocus: handleFocus,
|
11542
|
+
ref,
|
11543
|
+
// This is a temporary fix to enable up/down arrow key shortcuts on input in quick mode. For some reason,
|
11544
|
+
// the preventDefault is true on Taco Input, so the keyboard shortcuts doesn't work. By adding this
|
11545
|
+
// data attribute we make sure the event is coming from a control component, and then we can make sure
|
11546
|
+
// keyboard shortcut works as expected.
|
11547
|
+
'data-inline-editing-component': 'true'
|
11548
|
+
};
|
11549
|
+
const className = cn(getCellAlignmentClasses((_cell$column$columnDe5 = cell.column.columnDef.meta) === null || _cell$column$columnDe5 === void 0 ? void 0 : _cell$column$columnDe5.align));
|
11550
|
+
const indicatorMountNode = (_cellRef$current = cellRef.current) === null || _cellRef$current === void 0 ? void 0 : (_cellRef$current$pare = _cellRef$current.parentElement) === null || _cellRef$current$pare === void 0 ? void 0 : _cellRef$current$pare.querySelector(':first-child');
|
11551
|
+
let controlComponent;
|
11552
|
+
if (cellControl) {
|
11553
|
+
if (typeof cellControl === 'function') {
|
11554
|
+
controlComponent = cellControl({
|
11555
|
+
onBlur: saveIfChanged,
|
11556
|
+
onFocus: handleFocus,
|
11557
|
+
ref: controlRef,
|
11558
|
+
setValue: setState,
|
11559
|
+
value: state,
|
11560
|
+
'data-inline-editing-component': 'true'
|
11561
|
+
}, cell.row.original);
|
11562
|
+
} else {
|
11563
|
+
switch (cellControl) {
|
11564
|
+
case 'datepicker':
|
11565
|
+
controlComponent = /*#__PURE__*/React__default.createElement(Datepicker, Object.assign({}, attributes, {
|
11566
|
+
onBlur: event => {
|
11567
|
+
const newDate = event.detail;
|
11568
|
+
saveIfChanged(newDate);
|
11569
|
+
},
|
11570
|
+
onChange: event => {
|
11571
|
+
setState(event.detail);
|
11572
|
+
},
|
11573
|
+
ref: controlRef,
|
11574
|
+
value: state
|
11575
|
+
}));
|
11576
|
+
break;
|
11577
|
+
case 'switch':
|
11578
|
+
controlComponent = /*#__PURE__*/React__default.createElement(Switch, Object.assign({}, attributes, {
|
11579
|
+
className: "mx-2",
|
11580
|
+
checked: Boolean(state),
|
11581
|
+
onChange: setState,
|
11582
|
+
ref: controlRef
|
11583
|
+
}));
|
11584
|
+
break;
|
11585
|
+
default:
|
11586
|
+
controlComponent = /*#__PURE__*/React__default.createElement(Input, Object.assign({}, attributes, {
|
11587
|
+
className: className,
|
11588
|
+
onChange: event => {
|
11589
|
+
setState(event.target.value);
|
11590
|
+
},
|
11591
|
+
ref: controlRef,
|
11592
|
+
value: String(state !== null && state !== void 0 ? state : '')
|
11593
|
+
}));
|
11594
|
+
break;
|
11595
|
+
}
|
11596
|
+
}
|
11597
|
+
}
|
11598
|
+
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, !!rowMoveReason && /*#__PURE__*/React__default.createElement(Indicator, {
|
11599
|
+
reason: rowMoveReason,
|
11600
|
+
columnName: String(cell.column.columnDef.header),
|
11601
|
+
mountNode: indicatorMountNode
|
11602
|
+
}), /*#__PURE__*/React__default.createElement("span", {
|
11603
|
+
className: "relative flex-grow"
|
11604
|
+
}, controlComponent, showValidationError && /*#__PURE__*/React__default.createElement(ValidationError, null, String(cellValidationError))));
|
11605
|
+
}));
|
11606
|
+
|
11607
|
+
const Header$1 = function Header(props) {
|
11608
|
+
var _header$column$column, _header$column$column2, _asc$desc$header$colu, _header$column$column4, _header$column$column5, _header$column$column6, _header$column$column7, _asc$desc$header$colu2, _header$column$column8;
|
11609
|
+
const {
|
11610
|
+
header,
|
11611
|
+
index,
|
11612
|
+
isLastColumn,
|
11613
|
+
table,
|
11614
|
+
tableRef,
|
11615
|
+
...columnProps
|
11616
|
+
} = props;
|
11617
|
+
const textRef = React__default.useRef(null);
|
11618
|
+
const pinned = !!header.column.getIsPinned();
|
11619
|
+
const isOtherColumnBeingResized = table.getState().columnSizingInfo.isResizingColumn && table.getState().columnSizingInfo.isResizingColumn !== header.id;
|
11620
|
+
const className = cn('group/header sticky top-0 bg-white border-b-2 relative font-bold z-[15] hover:z-[16]', {
|
11621
|
+
'z-[16]': header.column.getIsResizing(),
|
11622
|
+
'z-[17]': pinned,
|
11623
|
+
'cursor-pointer select-none': header.column.getCanSort(),
|
11624
|
+
'hover:bg-grey-100': header.column.getCanSort() || header.column.getCanResize() || ((_header$column$column = header.column.columnDef.meta) === null || _header$column$column === void 0 ? void 0 : _header$column$column.menu),
|
11625
|
+
'pointer-events-none': isOtherColumnBeingResized
|
11626
|
+
}, getCellSizingClasses('normal'), (_header$column$column2 = header.column.columnDef.meta) === null || _header$column$column2 === void 0 ? void 0 : _header$column$column2.headerClassName, props.className);
|
11627
|
+
// set the column size after the first render (after auto layout with 'max-content') has run
|
11628
|
+
// this way columns default to fit their content, then we save that size for resizing
|
11629
|
+
const refCallback = node => {
|
11630
|
+
if (node && !table.getState().columnSizing[header.id]) {
|
11631
|
+
const size = Math.ceil(node.getBoundingClientRect().width);
|
11632
|
+
table.setColumnSizing(sizes => ({
|
11633
|
+
...sizes,
|
11634
|
+
[header.id]: !isInternalColumn(header.id) && size < MIN_COLUMN_SIZE ? MIN_COLUMN_SIZE : size
|
11635
|
+
}));
|
11636
|
+
}
|
11637
|
+
};
|
11638
|
+
// we use mousedown because clicking and dragging resize and then letting go over the
|
11639
|
+
// column, results in sorting being applied
|
11640
|
+
const handleMouseDown = header.column.getCanSort() ? event => {
|
11641
|
+
// only detect left clicks
|
11642
|
+
if (event.button === 0) {
|
11643
|
+
var _tableRef$current;
|
11644
|
+
event.preventDefault();
|
11645
|
+
table.resetRowSelection();
|
11646
|
+
header.column.toggleSorting();
|
11647
|
+
(_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : _tableRef$current.focus();
|
11648
|
+
}
|
11649
|
+
} : undefined;
|
11650
|
+
const handleResizerDoubleClick = () => {
|
11651
|
+
var _header$column$column3;
|
11652
|
+
const size = (_header$column$column3 = header.column.columnDef.meta) === null || _header$column$column3 === void 0 ? void 0 : _header$column$column3.defaultWidth;
|
11653
|
+
table.setColumnSizing(sizes => {
|
11654
|
+
const nextSizes = {
|
11655
|
+
...sizes
|
11656
|
+
};
|
11657
|
+
if (size) {
|
11658
|
+
nextSizes[header.id] = !isInternalColumn(header.id) && size < MIN_COLUMN_SIZE ? MIN_COLUMN_SIZE : size;
|
11659
|
+
} else {
|
11660
|
+
delete nextSizes[header.id];
|
11661
|
+
}
|
11662
|
+
return nextSizes;
|
11663
|
+
});
|
11664
|
+
};
|
11665
|
+
const handleResizerClick = event => {
|
11666
|
+
event.stopPropagation();
|
11667
|
+
event.preventDefault();
|
11668
|
+
};
|
11669
|
+
const handleResize = event => {
|
11670
|
+
// prevent the parent onMouseDown propagating
|
11671
|
+
event.stopPropagation();
|
11672
|
+
header.getResizeHandler()(event);
|
11673
|
+
};
|
11674
|
+
const content = /*#__PURE__*/React__default.createElement("div", {
|
11675
|
+
className: "truncate",
|
11676
|
+
ref: textRef
|
11677
|
+
}, reactTable$1.flexRender(header.column.columnDef.header, header.getContext()));
|
11678
|
+
return /*#__PURE__*/React__default.createElement(ColumnBase, Object.assign({}, columnProps, {
|
11679
|
+
// base props
|
11680
|
+
column: header.column,
|
11681
|
+
table: table,
|
11682
|
+
"aria-sort": (_asc$desc$header$colu = {
|
11683
|
+
asc: 'ascending',
|
11684
|
+
desc: 'descending'
|
11685
|
+
}[header.column.getIsSorted()]) !== null && _asc$desc$header$colu !== void 0 ? _asc$desc$header$colu : 'none',
|
11686
|
+
className: className,
|
11687
|
+
onMouseDown: handleMouseDown,
|
11688
|
+
ref: refCallback,
|
11689
|
+
role: "columnheader",
|
11690
|
+
"data-column-index": index
|
11691
|
+
}), isInternalColumn(header.id) ? reactTable$1.flexRender(header.column.columnDef.header, header.getContext()) : /*#__PURE__*/React__default.createElement("div", {
|
11692
|
+
className: cn('flex flex-grow overflow-hidden', {
|
11693
|
+
'group-hover/header:-ml-2': !!header.column.getIsSorted() && !!((_header$column$column4 = header.column.columnDef.meta) !== null && _header$column$column4 !== void 0 && _header$column$column4.menu)
|
11694
|
+
}, getCellAlignmentClasses((_header$column$column5 = header.column.columnDef.meta) === null || _header$column$column5 === void 0 ? void 0 : _header$column$column5.align))
|
11695
|
+
}, isOverflowing(textRef.current) ? /*#__PURE__*/React__default.createElement(Tooltip, {
|
11696
|
+
title: (_header$column$column6 = (_header$column$column7 = header.column.columnDef.meta) === null || _header$column$column7 === void 0 ? void 0 : _header$column$column7.tooltip) !== null && _header$column$column6 !== void 0 ? _header$column$column6 : content,
|
11697
|
+
placement: "top"
|
11698
|
+
}, content) : content, (_asc$desc$header$colu2 = {
|
11699
|
+
asc: /*#__PURE__*/React__default.createElement(Icon, {
|
11700
|
+
name: "chevron-up-solid",
|
11701
|
+
className: "pointer-events-none -my-0.5"
|
11702
|
+
}),
|
11703
|
+
desc: /*#__PURE__*/React__default.createElement(Icon, {
|
11704
|
+
name: "chevron-down-solid",
|
11705
|
+
className: "pointer-events-none -my-0.5"
|
11706
|
+
})
|
11707
|
+
}[header.column.getIsSorted()]) !== null && _asc$desc$header$colu2 !== void 0 ? _asc$desc$header$colu2 : null), (_header$column$column8 = header.column.columnDef.meta) !== null && _header$column$column8 !== void 0 && _header$column$column8.menu ? /*#__PURE__*/React__default.createElement(HeaderMenu, {
|
11708
|
+
header: header
|
11709
|
+
}) : null, header.column.getCanResize() ? /*#__PURE__*/React__default.createElement(Tooltip, {
|
11710
|
+
placement: "top",
|
11711
|
+
title: "Resize column"
|
11712
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
11713
|
+
className: cn('invisible absolute right-0 top-0 flex h-full cursor-col-resize touch-none select-none rounded py-0.5 group-hover/header:visible', {
|
11714
|
+
'-mr-2.5 w-5 justify-center': !isLastColumn,
|
11715
|
+
'w-2': isLastColumn,
|
11716
|
+
'!visible': header.column.getIsResizing()
|
11717
|
+
}),
|
11718
|
+
onDoubleClick: handleResizerDoubleClick,
|
11719
|
+
onMouseDown: handleResize,
|
11720
|
+
onTouchStart: handleResize,
|
11721
|
+
// this prevents sort handlers being activated
|
11722
|
+
onClick: handleResizerClick
|
11723
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
11724
|
+
className: cn('h-full w-1 rounded', {
|
11725
|
+
'!bg-blue-500': header.column.getIsResizing(),
|
11726
|
+
'bg-grey-500 hover:bg-grey-700': !header.column.getIsResizing()
|
11727
|
+
})
|
11728
|
+
}))) : null);
|
11729
|
+
};
|
11730
|
+
const HeaderMenu = ({
|
11731
|
+
header
|
11732
|
+
}) => {
|
11733
|
+
const [open, setOpen] = React__default.useState(false);
|
11734
|
+
const className = cn('-my-0.5 -mr-1 -ml-0.5 hidden !h-6 !min-h-[theme(spacing.6)] !w-6 !min-w-[theme(spacing.6)] flex-shrink-0 justify-end group-hover/header:flex', {
|
11735
|
+
'!flex': open
|
11736
|
+
});
|
11737
|
+
return header.column.columnDef.meta ?
|
11738
|
+
/*#__PURE__*/
|
11739
|
+
// This div catches the mousedown events from menu item and menu trigger and prevents
|
11740
|
+
// mousedown event from bubbling up to the Header component to prevent toggling sorting
|
11741
|
+
React__default.createElement("div", {
|
11742
|
+
onMouseDown: event => event.stopPropagation()
|
11743
|
+
}, header.column.columnDef.meta.menu({
|
11744
|
+
trigger: /*#__PURE__*/React__default.createElement(IconButton, {
|
11745
|
+
className: className,
|
11746
|
+
icon: "more"
|
11747
|
+
}),
|
11748
|
+
open: open,
|
11749
|
+
onChange: setOpen
|
11750
|
+
})) : null;
|
11751
|
+
};
|
11752
|
+
|
11753
|
+
const Footer$2 = function Footer(props) {
|
11754
|
+
const {
|
11755
|
+
footer,
|
11756
|
+
index,
|
11757
|
+
table,
|
11758
|
+
...columnProps
|
11759
|
+
} = props;
|
11760
|
+
const isPinned = !!footer.column.getIsPinned();
|
11761
|
+
const className = cn('group/header sticky bottom-0 bg-white border-t-2 relative ', {
|
11762
|
+
'z-[1]': isPinned
|
11763
|
+
}, props.className);
|
11764
|
+
return /*#__PURE__*/React__default.createElement(ColumnBase, Object.assign({}, columnProps, {
|
11765
|
+
// base props
|
11766
|
+
column: footer.column,
|
11767
|
+
table: table,
|
11768
|
+
className: className,
|
11769
|
+
role: "cell",
|
11770
|
+
"data-column-index": index
|
11771
|
+
}));
|
11772
|
+
};
|
11773
|
+
|
11774
|
+
function useColumnDefinitions(children, options, tableRef) {
|
11775
|
+
const lastSelectedRowIndex = React__default.useRef();
|
11776
|
+
const columnHelper = reactTable$1.createColumnHelper();
|
11777
|
+
return React__default.useMemo(() => {
|
11778
|
+
var _options$actionsForRo;
|
11779
|
+
// cannot be typed correctly until https://github.com/TanStack/table/discussions/4530 is resolved
|
11780
|
+
const columns = [];
|
11781
|
+
const defaultColumnPinning = [];
|
11782
|
+
const defaultColumnSizing = {};
|
11783
|
+
const defaultColumnVisibility = {};
|
11784
|
+
const defaultSorting = [];
|
11785
|
+
const footers = {};
|
11786
|
+
React__default.Children.toArray(children).forEach(child => {
|
11787
|
+
if ( /*#__PURE__*/React__default.isValidElement(child)) {
|
11788
|
+
var _child$props$minWidth;
|
11789
|
+
if (child.props.defaultPinned && options.enableColumnPinning) {
|
11790
|
+
defaultColumnPinning.push(child.props.accessor);
|
11791
|
+
}
|
11792
|
+
if (child.props.defaultWidth) {
|
11793
|
+
defaultColumnSizing[child.props.accessor] = child.props.defaultWidth;
|
11794
|
+
}
|
11795
|
+
if (child.props.defaultHidden && options.enableColumnHiding) {
|
11796
|
+
defaultColumnVisibility[child.props.accessor] = false;
|
11797
|
+
}
|
11798
|
+
if (child.props.sort !== undefined) {
|
11799
|
+
defaultSorting.push({
|
11800
|
+
id: child.props.accessor,
|
11801
|
+
desc: child.props.sort === 'desc'
|
11802
|
+
});
|
11803
|
+
}
|
11804
|
+
if (child.props.footer) {
|
11805
|
+
footers[child.props.accessor] = child.props.footer;
|
11806
|
+
}
|
11807
|
+
columns.push({
|
11808
|
+
accessorKey: child.props.accessor,
|
11809
|
+
id: child.props.accessor,
|
11810
|
+
cell: props => {
|
11811
|
+
if (typeof child.props.renderer === 'function') {
|
11812
|
+
return child.props.renderer(props.getValue(), props.row.original);
|
11813
|
+
}
|
11814
|
+
return props.getValue();
|
11815
|
+
},
|
11816
|
+
header: child.props.header,
|
11817
|
+
meta: {
|
11818
|
+
align: child.props.align,
|
11819
|
+
className: child.props.className,
|
11820
|
+
control: child.props.control,
|
11821
|
+
dataType: child.props.dataType,
|
11822
|
+
defaultWidth: child.props.defaultWidth,
|
11823
|
+
disableReordering: child.props.disableReordering,
|
11824
|
+
disableTruncation: child.props.disableTruncation,
|
11825
|
+
menu: child.props.menu,
|
11826
|
+
tooltip: child.props.tooltip
|
11827
|
+
},
|
11828
|
+
enableHiding: !child.props.disableHiding,
|
11829
|
+
// filtering
|
11830
|
+
enableColumnFilter: !child.props.disableFiltering,
|
11831
|
+
filterFn: options.enableColumnFiltering && !child.props.disableFiltering ? 'tacoFilter' : undefined,
|
11832
|
+
// sizing
|
11833
|
+
enableResizing: !child.props.disableResizing,
|
11834
|
+
minSize: (_child$props$minWidth = child.props.minWidth) !== null && _child$props$minWidth !== void 0 ? _child$props$minWidth : MIN_COLUMN_SIZE,
|
11835
|
+
size: child.props.defaultWidth,
|
11836
|
+
// sorting
|
11837
|
+
enableSorting: !child.props.disableSorting,
|
11838
|
+
sortingFn: getSortingFn(child.props.dataType)
|
11839
|
+
});
|
11840
|
+
}
|
11841
|
+
});
|
11842
|
+
if (options.enableRowExpansion) {
|
11843
|
+
columns.unshift(columnHelper.display(createRowExpansionColumn()));
|
11844
|
+
defaultColumnPinning.unshift(COLUMN_ID_FOR_EXPANSION);
|
11845
|
+
}
|
11846
|
+
if (options.enableRowSelection) {
|
11847
|
+
columns.unshift(columnHelper.display(createRowSelectionColumn(options.enableMultipleRowSelection, lastSelectedRowIndex, options.onRowDrag, tableRef)));
|
11848
|
+
defaultColumnPinning.unshift(COLUMN_ID_FOR_SELECTION);
|
11849
|
+
}
|
11850
|
+
if (options.onRowDrag) {
|
11851
|
+
columns.unshift(columnHelper.display(createRowDraggableColumn(options.onRowDrag)));
|
11852
|
+
defaultColumnPinning.unshift(COLUMN_ID_FOR_DRAGGABLE);
|
11853
|
+
}
|
11854
|
+
if ((_options$actionsForRo = options.actionsForRow) !== null && _options$actionsForRo !== void 0 && _options$actionsForRo.length) {
|
11855
|
+
columns.push(columnHelper.display(createRowActionsColumn(options.actionsForRow)));
|
11856
|
+
}
|
11857
|
+
return {
|
11858
|
+
columns,
|
11859
|
+
defaultColumnPinning,
|
11860
|
+
defaultColumnSizing,
|
11861
|
+
defaultColumnVisibility,
|
11862
|
+
defaultSorting,
|
11863
|
+
footers
|
11864
|
+
};
|
11865
|
+
}, [children]);
|
11866
|
+
}
|
11867
|
+
const getSortingFn = dataType => {
|
11868
|
+
if (dataType && dataType !== 'boolean') {
|
11869
|
+
return dataType;
|
11870
|
+
}
|
11871
|
+
return 'auto';
|
11872
|
+
};
|
11873
|
+
|
11874
|
+
const isResizingPinnedColumn = (columnId, table) => {
|
11875
|
+
var _table$getState$colum, _table$getState$colum2;
|
11876
|
+
return !!columnId && ((_table$getState$colum = table.getState().columnPinning.left) === null || _table$getState$colum === void 0 ? void 0 : _table$getState$colum.includes((_table$getState$colum2 = table.getState().columnSizingInfo) === null || _table$getState$colum2 === void 0 ? void 0 : _table$getState$colum2.isResizingColumn));
|
11877
|
+
};
|
11878
|
+
const getOffsetsFromSize = (pinning, visibility, sizing) => {
|
11879
|
+
const pinned = pinning.left.filter(c => visibility[c] !== false);
|
11880
|
+
const offsets = {};
|
11881
|
+
let leftOffset = 0;
|
11882
|
+
for (const k of pinned) {
|
11883
|
+
if (!Number.isInteger(sizing[k])) {
|
11884
|
+
break;
|
11885
|
+
}
|
11886
|
+
offsets[k] = leftOffset;
|
11887
|
+
leftOffset += sizing[k];
|
11888
|
+
}
|
11889
|
+
return offsets;
|
11890
|
+
};
|
11891
|
+
// pinned columns have position sticky, and because we support more than one of them
|
11892
|
+
// we must set a 'left' css value. this hook listens to changes on state that will
|
11893
|
+
// affect the left offset (resize, visibility, pinning) and updates offsets based on width
|
11894
|
+
const useColumnOffsetStateListener = (table, setColumnOffsets) => {
|
11895
|
+
const {
|
11896
|
+
columnPinning,
|
11897
|
+
columnSizing,
|
11898
|
+
columnSizingInfo,
|
11899
|
+
columnVisibility
|
11900
|
+
} = table.getState();
|
11901
|
+
React__default.useEffect(() => {
|
11902
|
+
if (isResizingPinnedColumn(columnSizingInfo.isResizingColumn, table)) {
|
11903
|
+
setColumnOffsets(getOffsetsFromSize(columnPinning, columnVisibility, columnSizing));
|
11904
|
+
}
|
11905
|
+
}, [columnSizingInfo]);
|
11906
|
+
React__default.useEffect(() => {
|
11907
|
+
setColumnOffsets(getOffsetsFromSize(columnPinning, columnVisibility, columnSizing));
|
11908
|
+
}, [columnVisibility]);
|
11909
|
+
React__default.useEffect(() => {
|
11910
|
+
setColumnOffsets(getOffsetsFromSize(columnPinning, columnVisibility, columnSizing));
|
11911
|
+
}, [columnPinning.left]);
|
11912
|
+
};
|
11913
|
+
|
11914
|
+
const useRowSelectionListener = (table, onRowSelect) => {
|
11915
|
+
React__default.useEffect(() => {
|
11916
|
+
if (onRowSelect) {
|
11917
|
+
if (table.options.enableMultiRowSelection) {
|
11918
|
+
onRowSelect(table.getSelectedRowModel().rows.map(row => row.original));
|
11919
|
+
} else {
|
11920
|
+
var _table$getSelectedRow, _table$getSelectedRow2;
|
11921
|
+
onRowSelect((_table$getSelectedRow = (_table$getSelectedRow2 = table.getSelectedRowModel().rows[0]) === null || _table$getSelectedRow2 === void 0 ? void 0 : _table$getSelectedRow2.original) !== null && _table$getSelectedRow !== void 0 ? _table$getSelectedRow : undefined);
|
11922
|
+
}
|
11923
|
+
}
|
11924
|
+
}, [table.getState().rowSelection]);
|
11925
|
+
};
|
11926
|
+
|
11927
|
+
const useSettingsStateListener = (table, onChangeSettings) => {
|
11928
|
+
const meta = table.options.meta;
|
11929
|
+
const state = table.getState();
|
11930
|
+
React__default.useEffect(() => {
|
11931
|
+
let handler;
|
11932
|
+
if (typeof onChangeSettings === 'function') {
|
11933
|
+
handler = setTimeout(() => onChangeSettings({
|
11934
|
+
columnFilters: state.columnFilters,
|
11935
|
+
columnOrder: state.columnOrder,
|
11936
|
+
columnPinning: state.columnPinning,
|
11937
|
+
columnSizing: state.columnSizing,
|
11938
|
+
columnVisibility: state.columnVisibility,
|
11939
|
+
globalFilter: state.globalFilter,
|
11940
|
+
rowDensity: meta.rowDensity,
|
11941
|
+
sorting: state.sorting
|
11942
|
+
}), 250);
|
11943
|
+
}
|
11944
|
+
return () => clearTimeout(handler);
|
11945
|
+
}, [state.columnFilters, state.columnOrder, state.columnPinning, state.columnSizing, state.columnVisibility, state.globalFilter, meta.rowDensity, state.sorting]);
|
11946
|
+
};
|
11947
|
+
|
11948
|
+
const useActiveRow = (defaultActiveRowIndex = 0) => {
|
11949
|
+
const [activeRowIndex, _setActiveRow] = React__default.useState(defaultActiveRowIndex);
|
11950
|
+
const moveActiveRow = (direction, rows, callback) => {
|
11951
|
+
_setActiveRow(rowIndex => {
|
11952
|
+
const nextRowIndex = getNextIndex$1(direction, rowIndex, rows.length);
|
11953
|
+
if (callback) {
|
11954
|
+
callback(nextRowIndex);
|
11955
|
+
}
|
11956
|
+
return nextRowIndex;
|
11957
|
+
});
|
11958
|
+
};
|
11959
|
+
// output
|
11960
|
+
const moveToPreviousRow = (rows, callback) => moveActiveRow(-1, rows, callback);
|
11961
|
+
const moveToNextRow = (rows, callback) => moveActiveRow(1, rows, callback);
|
11962
|
+
const setActiveRowIndex = rowIndex => _setActiveRow(rowIndex);
|
11963
|
+
return {
|
11964
|
+
activeRowIndex,
|
11965
|
+
setActiveRowIndex,
|
11966
|
+
moveToPreviousRow,
|
11967
|
+
moveToNextRow
|
11968
|
+
};
|
11969
|
+
};
|
11970
|
+
const getNextIndex$1 = (direction, currentIndex, length) => {
|
11971
|
+
if (direction === -1) {
|
11972
|
+
return currentIndex - 1 > 0 ? currentIndex - 1 : 0;
|
11973
|
+
}
|
11974
|
+
return currentIndex + 1 < length ? currentIndex + 1 : currentIndex;
|
11975
|
+
};
|
11976
|
+
|
11977
|
+
const useActiveRowStateListener = (table, rows, activeRowIndex) => {
|
11978
|
+
const meta = table.options.meta;
|
11979
|
+
React__default.useEffect(() => {
|
11980
|
+
if (meta.editMode.isEditing && meta.shouldPauseSortingAndFiltering) {
|
11981
|
+
meta.setShouldPauseSortingAndFiltering(false);
|
11982
|
+
}
|
11983
|
+
}, [activeRowIndex.activeRowIndex]);
|
11984
|
+
// if a filter would exclude the active row, reset it to 0
|
11985
|
+
React__default.useEffect(() => {
|
11986
|
+
if (activeRowIndex.activeRowIndex > rows.length - 1) {
|
11987
|
+
meta.setActiveRowIndex(rows.length ? rows.length - 1 : 0);
|
11988
|
+
}
|
11989
|
+
}, [table.getState().columnFilters, rows.length]);
|
11990
|
+
};
|
11991
|
+
|
11992
|
+
function useTable$1(children, props, ref) {
|
11993
|
+
var _settings$columnOrder, _ref, _settings$columnPinni, _settings$columnPinni2, _settings$columnSizin, _settings$columnVisib, _settings$rowDensity;
|
11994
|
+
const {
|
11995
|
+
actionsForRow = [],
|
11996
|
+
data,
|
11997
|
+
defaultActiveRowIndex,
|
11998
|
+
disableColumnFiltering = false,
|
11999
|
+
disableColumnHiding = false,
|
12000
|
+
disableColumnPinning = false,
|
12001
|
+
disableColumnReordering = false,
|
12002
|
+
disableColumnResizing = false,
|
12003
|
+
disableRowDensity = false,
|
12004
|
+
disableRowExpansion = false,
|
12005
|
+
disableRowSelection = false,
|
12006
|
+
disableMultipleRowSelection = false,
|
12007
|
+
disableSearch = false,
|
12008
|
+
disableSorting = false,
|
12009
|
+
expandedRowRenderer,
|
12010
|
+
manualColumnFiltering = false,
|
12011
|
+
manualSearch = false,
|
12012
|
+
manualSorting = false,
|
12013
|
+
onChangeSettings,
|
12014
|
+
onRowClick,
|
12015
|
+
onRowDrag,
|
12016
|
+
onRowSelect,
|
12017
|
+
onSave,
|
12018
|
+
settings = {},
|
12019
|
+
// experimental
|
12020
|
+
_experimentalActionsForTable
|
12021
|
+
} = props;
|
12022
|
+
const enableRowExpansion = !disableRowExpansion && !!expandedRowRenderer;
|
12023
|
+
const enableRowSelection = !disableRowSelection && (!!onRowSelect || !!(_experimentalActionsForTable !== null && _experimentalActionsForTable !== void 0 && _experimentalActionsForTable.length));
|
12024
|
+
const enableMultipleRowSelection = !disableMultipleRowSelection && enableRowSelection;
|
12025
|
+
const {
|
12026
|
+
columns,
|
12027
|
+
defaultColumnPinning,
|
12028
|
+
defaultColumnSizing,
|
12029
|
+
defaultSorting,
|
12030
|
+
defaultColumnVisibility,
|
12031
|
+
footers
|
12032
|
+
} = useColumnDefinitions(children, {
|
12033
|
+
actionsForRow,
|
12034
|
+
enableColumnFiltering: !disableColumnFiltering,
|
12035
|
+
enableColumnHiding: !disableColumnHiding,
|
12036
|
+
enableColumnPinning: !disableColumnPinning,
|
12037
|
+
enableRowExpansion,
|
12038
|
+
enableRowSelection,
|
12039
|
+
enableMultipleRowSelection,
|
12040
|
+
onRowDrag
|
12041
|
+
}, ref);
|
12042
|
+
// defaults
|
12043
|
+
const initialState = {
|
12044
|
+
columnOrder: (_settings$columnOrder = settings === null || settings === void 0 ? void 0 : settings.columnOrder) !== null && _settings$columnOrder !== void 0 ? _settings$columnOrder : columns.map(column => column.id),
|
12045
|
+
columnPinning: {
|
12046
|
+
left: (_ref = (_settings$columnPinni = settings === null || settings === void 0 ? void 0 : (_settings$columnPinni2 = settings.columnPinning) === null || _settings$columnPinni2 === void 0 ? void 0 : _settings$columnPinni2.left) !== null && _settings$columnPinni !== void 0 ? _settings$columnPinni : defaultColumnPinning) !== null && _ref !== void 0 ? _ref : [],
|
12047
|
+
right: []
|
12048
|
+
},
|
12049
|
+
columnSizing: (_settings$columnSizin = settings === null || settings === void 0 ? void 0 : settings.columnSizing) !== null && _settings$columnSizin !== void 0 ? _settings$columnSizin : defaultColumnSizing,
|
12050
|
+
columnVisibility: (_settings$columnVisib = settings === null || settings === void 0 ? void 0 : settings.columnVisibility) !== null && _settings$columnVisib !== void 0 ? _settings$columnVisib : defaultColumnVisibility
|
12051
|
+
};
|
12052
|
+
// Data column index - these are needed to make sure left and right arrow key shortcuts focuses only the data columns
|
12053
|
+
const dataColumnStartOffset = [!!onRowDrag, !!enableRowExpansion, !!enableRowSelection].reduce((t, e) => t + (e ? 1 : 0), 0);
|
12054
|
+
const dataColumnEndOffset = actionsForRow.length ? 1 : 0;
|
12055
|
+
// custom
|
12056
|
+
const activeRow = useActiveRow(defaultActiveRowIndex);
|
12057
|
+
const [hoveredRowIndex, setHoveredRowIndex] = React__default.useState(undefined);
|
12058
|
+
const editMode = useEditMode(onSave);
|
12059
|
+
const [columnOffsets, setColumnOffsets] = React__default.useState(getOffsetsFromSize(initialState.columnPinning, initialState.columnVisibility, initialState.columnSizing));
|
12060
|
+
const [rowDensity, setRowDensity] = React__default.useState((_settings$rowDensity = settings === null || settings === void 0 ? void 0 : settings.rowDensity) !== null && _settings$rowDensity !== void 0 ? _settings$rowDensity : 'normal');
|
12061
|
+
const [dragging, setDragging] = React__default.useState({});
|
12062
|
+
const [shouldPauseSortingAndFiltering, setShouldPauseSortingAndFiltering] = React__default.useState(false);
|
12063
|
+
const [shouldDisableTableActions, setShouldDisableTableActions] = React__default.useState(false);
|
12064
|
+
// For some reason, using state instead of ref didn't work as expected, that's why ref is used
|
12065
|
+
const focussableColumnIndexes = React__default.useRef([]);
|
12066
|
+
// some options get set even if they are undefined, so we have to do it conditionally
|
12067
|
+
const options = {
|
12068
|
+
enableExpanding: enableRowExpansion,
|
12069
|
+
enableColumnFilters: !disableColumnFiltering,
|
12070
|
+
enableColumnResizing: !disableColumnResizing,
|
12071
|
+
enableGlobalFilter: !disableSearch,
|
12072
|
+
enableHiding: !disableColumnHiding,
|
12073
|
+
enablePinning: !disableColumnPinning,
|
12074
|
+
enableRowSelection: enableRowSelection,
|
12075
|
+
enableMultiRowSelection: enableMultipleRowSelection,
|
12076
|
+
enableSorting: !disableSorting
|
12077
|
+
};
|
12078
|
+
// resizing
|
12079
|
+
if (options.enableColumnResizing) {
|
12080
|
+
options.columnResizeMode = 'onChange';
|
12081
|
+
}
|
12082
|
+
// sorting
|
12083
|
+
if (options.enableSorting) {
|
12084
|
+
var _settings$sorting;
|
12085
|
+
initialState.sorting = (_settings$sorting = settings === null || settings === void 0 ? void 0 : settings.sorting) !== null && _settings$sorting !== void 0 ? _settings$sorting : defaultSorting;
|
12086
|
+
if (manualSorting) {
|
12087
|
+
options.manualSorting = true;
|
12088
|
+
} else {
|
12089
|
+
options.getSortedRowModel = reactTable$1.getSortedRowModel();
|
12090
|
+
}
|
12091
|
+
}
|
12092
|
+
// filtering
|
12093
|
+
if (options.enableColumnFilters) {
|
12094
|
+
var _settings$columnFilte;
|
12095
|
+
initialState.columnFilters = (_settings$columnFilte = settings === null || settings === void 0 ? void 0 : settings.columnFilters) !== null && _settings$columnFilte !== void 0 ? _settings$columnFilte : [];
|
12096
|
+
if (manualColumnFiltering) {
|
12097
|
+
options.manualFiltering = true;
|
12098
|
+
} else {
|
12099
|
+
options.filterFns = {
|
12100
|
+
tacoFilter: (row, columnId, filter) => columnFilterFn(row.getValue(columnId), filter)
|
12101
|
+
};
|
12102
|
+
options.getFilteredRowModel = reactTable$1.getFilteredRowModel();
|
12103
|
+
}
|
12104
|
+
}
|
12105
|
+
// search
|
12106
|
+
if (options.enableGlobalFilter) {
|
12107
|
+
if (manualSearch) {
|
12108
|
+
options.manualFiltering = true;
|
12109
|
+
} else {
|
12110
|
+
options.globalFilterFn = (row, columnId, query) => globalFilterFn(row.getValue(columnId), query);
|
12111
|
+
options.getFilteredRowModel = reactTable$1.getFilteredRowModel();
|
12112
|
+
}
|
12113
|
+
}
|
12114
|
+
const table = reactTable$1.useReactTable({
|
12115
|
+
data,
|
12116
|
+
columns: columns,
|
12117
|
+
getCoreRowModel: reactTable$1.getCoreRowModel(),
|
12118
|
+
initialState,
|
12119
|
+
...options,
|
12120
|
+
meta: {
|
12121
|
+
...activeRow,
|
12122
|
+
editMode,
|
12123
|
+
// offsets
|
12124
|
+
columnOffsets,
|
12125
|
+
// density
|
12126
|
+
enableRowDensity: !disableRowDensity,
|
12127
|
+
rowDensity,
|
12128
|
+
setRowDensity,
|
12129
|
+
// dragging
|
12130
|
+
dragging,
|
12131
|
+
setDragging,
|
12132
|
+
// computed
|
12133
|
+
enableColumnReordering: !disableColumnReordering,
|
12134
|
+
// resorting
|
12135
|
+
shouldPauseSortingAndFiltering,
|
12136
|
+
setShouldPauseSortingAndFiltering,
|
12137
|
+
// other
|
12138
|
+
onRowClick,
|
12139
|
+
hoveredRowIndex,
|
12140
|
+
setHoveredRowIndex,
|
12141
|
+
// data column positions
|
12142
|
+
dataColumnStartOffset,
|
12143
|
+
dataColumnEndOffset,
|
12144
|
+
// disable table actions
|
12145
|
+
shouldDisableTableActions,
|
12146
|
+
setShouldDisableTableActions,
|
12147
|
+
// active row column indexes
|
12148
|
+
focussableColumnIndexes: focussableColumnIndexes.current,
|
12149
|
+
addFocussableColumnIndex: index => {
|
12150
|
+
if (!focussableColumnIndexes.current.includes(index)) {
|
12151
|
+
focussableColumnIndexes.current = [...focussableColumnIndexes.current, index].sort((a, b) => a - b);
|
12152
|
+
}
|
12153
|
+
},
|
12154
|
+
resetFocussableColumnIndexes: () => {
|
12155
|
+
focussableColumnIndexes.current = [];
|
12156
|
+
},
|
12157
|
+
// table ref
|
12158
|
+
tableRef: ref
|
12159
|
+
}
|
12160
|
+
});
|
12161
|
+
const tableRows = table.getRowModel().rows;
|
12162
|
+
const lastSortedOrFilteredRows = React__default.useRef(tableRows);
|
12163
|
+
if (!shouldPauseSortingAndFiltering) {
|
12164
|
+
lastSortedOrFilteredRows.current = tableRows;
|
12165
|
+
}
|
12166
|
+
const rows = shouldPauseSortingAndFiltering ? lastSortedOrFilteredRows.current : tableRows;
|
12167
|
+
// state listeners
|
12168
|
+
useActiveRowStateListener(table, rows, activeRow);
|
12169
|
+
useColumnOffsetStateListener(table, setColumnOffsets);
|
12170
|
+
useRowSelectionListener(table, onRowSelect);
|
12171
|
+
useSettingsStateListener(table, onChangeSettings);
|
12172
|
+
return {
|
12173
|
+
rows,
|
12174
|
+
table,
|
12175
|
+
footers
|
12176
|
+
};
|
12177
|
+
}
|
12178
|
+
|
12179
|
+
const densitySizeEstimates = {
|
12180
|
+
compact: 33,
|
12181
|
+
normal: 41,
|
12182
|
+
comfortable: 49,
|
12183
|
+
spacious: 57
|
12184
|
+
};
|
12185
|
+
const useVirtualiser = ({
|
12186
|
+
rows,
|
12187
|
+
table
|
12188
|
+
}, tableRef) => {
|
12189
|
+
var _virtualiser$virtualI, _virtualiser$virtualI2, _virtualiser$virtualI3, _virtualiser$virtualI4;
|
12190
|
+
const [expandedRowSizes, setExpandedRowSizes] = React__default.useState({});
|
12191
|
+
const firstAvailableExpandedRowHeight = React__default.useMemo(() => {
|
12192
|
+
const values = Object.values(expandedRowSizes);
|
12193
|
+
return values.length ? values.reduce((a, b) => a + b, 0) / values.length : 0;
|
12194
|
+
}, [expandedRowSizes]);
|
12195
|
+
const meta = table.options.meta;
|
12196
|
+
const estimateSize = React__default.useCallback(index => {
|
12197
|
+
var _table$getState$expan;
|
12198
|
+
const rowHeight = meta.rowDensity ? densitySizeEstimates[meta.rowDensity] : densitySizeEstimates.normal;
|
12199
|
+
if (table.getState().expanded === true || (_table$getState$expan = table.getState().expanded) !== null && _table$getState$expan !== void 0 && _table$getState$expan[index]) {
|
12200
|
+
var _ref, _expandedRowSizes$ind;
|
12201
|
+
return rowHeight + ((_ref = (_expandedRowSizes$ind = expandedRowSizes[index]) !== null && _expandedRowSizes$ind !== void 0 ? _expandedRowSizes$ind : firstAvailableExpandedRowHeight) !== null && _ref !== void 0 ? _ref : 0);
|
12202
|
+
}
|
12203
|
+
return rowHeight;
|
12204
|
+
}, [meta.rowDensity, expandedRowSizes, table.getState().expanded]);
|
12205
|
+
const virtualiser = reactVirtual.useVirtual({
|
12206
|
+
parentRef: tableRef,
|
12207
|
+
size: rows.length,
|
12208
|
+
estimateSize,
|
12209
|
+
overscan: 10
|
12210
|
+
});
|
12211
|
+
const paddingTop = virtualiser.virtualItems.length > 0 ? ((_virtualiser$virtualI = virtualiser.virtualItems) === null || _virtualiser$virtualI === void 0 ? void 0 : (_virtualiser$virtualI2 = _virtualiser$virtualI[0]) === null || _virtualiser$virtualI2 === void 0 ? void 0 : _virtualiser$virtualI2.start) || 0 : 0;
|
12212
|
+
const paddingBottom = virtualiser.virtualItems.length > 0 ? virtualiser.totalSize - (((_virtualiser$virtualI3 = virtualiser.virtualItems) === null || _virtualiser$virtualI3 === void 0 ? void 0 : (_virtualiser$virtualI4 = _virtualiser$virtualI3[virtualiser.virtualItems.length - 1]) === null || _virtualiser$virtualI4 === void 0 ? void 0 : _virtualiser$virtualI4.end) || 0) : 0;
|
12213
|
+
return {
|
12214
|
+
virtualiser,
|
12215
|
+
virtualiserOffsets: {
|
12216
|
+
top: paddingTop,
|
12217
|
+
bottom: paddingBottom
|
12218
|
+
},
|
12219
|
+
setExpandedRowSizes
|
12220
|
+
};
|
12221
|
+
};
|
12222
|
+
|
12223
|
+
const useGridTemplate = table => {
|
12224
|
+
const allVisibleColumns = table.getVisibleLeafColumns();
|
12225
|
+
return allVisibleColumns.reduce((accum, column, index) => {
|
12226
|
+
let size;
|
12227
|
+
const isLastColumn = index === allVisibleColumns.length - 1;
|
12228
|
+
const width = table.getState().columnSizing[column.id];
|
12229
|
+
if (column.id === COLUMN_ID_FOR_ACTIONS) {
|
12230
|
+
size = `minmax(max-content, auto)`;
|
12231
|
+
} else if (isInternalColumn(column.id)) {
|
12232
|
+
size = `${column.getSize()}px`;
|
12233
|
+
} else if (width) {
|
12234
|
+
if (isLastColumn) {
|
12235
|
+
size = `minmax(${width}px, auto)`;
|
12236
|
+
} else if (column.columnDef.minSize && width < column.columnDef.minSize) {
|
12237
|
+
// react-table is supposed to handle minSize itself but it is really buggy
|
12238
|
+
size = `${column.columnDef.minSize}px`;
|
12239
|
+
} else {
|
12240
|
+
size = `${width}px`;
|
12241
|
+
}
|
12242
|
+
} else if (column.getCanResize()) {
|
12243
|
+
size = 'minmax(max-content, auto)';
|
12244
|
+
} else {
|
12245
|
+
size = 'max-content';
|
12246
|
+
}
|
12247
|
+
return `${accum} ${size}`;
|
12248
|
+
}, '');
|
12249
|
+
};
|
12250
|
+
|
12251
|
+
const RowDensityButton = ({
|
12252
|
+
table
|
12253
|
+
}) => {
|
12254
|
+
const meta = table.options.meta;
|
12255
|
+
return /*#__PURE__*/React__default.createElement(IconButton, {
|
12256
|
+
"aria-label": "Change row density",
|
12257
|
+
icon: `density-${meta.rowDensity}`,
|
12258
|
+
menu: menuProps => /*#__PURE__*/React__default.createElement(Menu$1, Object.assign({}, menuProps), /*#__PURE__*/React__default.createElement(Menu$1.Content, {
|
12259
|
+
align: "end"
|
12260
|
+
}, /*#__PURE__*/React__default.createElement(Menu$1.RadioGroup, {
|
12261
|
+
onChange: rowDensity => meta.setRowDensity(rowDensity),
|
12262
|
+
value: meta.rowDensity
|
12263
|
+
}, /*#__PURE__*/React__default.createElement(Menu$1.RadioGroup.Item, {
|
12264
|
+
value: "compact"
|
12265
|
+
}, "Compact"), /*#__PURE__*/React__default.createElement(Menu$1.RadioGroup.Item, {
|
12266
|
+
value: "normal"
|
12267
|
+
}, "Normal"), /*#__PURE__*/React__default.createElement(Menu$1.RadioGroup.Item, {
|
12268
|
+
value: "comfortable"
|
12269
|
+
}, "Comfortable"), /*#__PURE__*/React__default.createElement(Menu$1.RadioGroup.Item, {
|
12270
|
+
value: "spacious"
|
12271
|
+
}, "Spacious")))),
|
12272
|
+
tooltip: "Row density"
|
12273
|
+
});
|
12274
|
+
};
|
12275
|
+
|
12276
|
+
function getContainerById(children, id) {
|
12277
|
+
var _lists$find;
|
12278
|
+
const lists = React__default.Children.toArray(children).filter(child => child.type.displayName === 'SortableList');
|
12279
|
+
const list = lists.find(list => list.props.id === id);
|
12280
|
+
if (list) {
|
12281
|
+
return list === null || list === void 0 ? void 0 : list.props;
|
12282
|
+
}
|
12283
|
+
return (_lists$find = lists.find(l => React__default.Children.toArray(l.props.children).findIndex(child => child.props.id === id) > -1)) === null || _lists$find === void 0 ? void 0 : _lists$find.props;
|
12284
|
+
}
|
12285
|
+
function Container(externalProps) {
|
12286
|
+
const {
|
12287
|
+
children,
|
12288
|
+
reorder,
|
12289
|
+
move
|
12290
|
+
} = externalProps;
|
12291
|
+
function handleDragOver(event) {
|
12292
|
+
const {
|
12293
|
+
active,
|
12294
|
+
over
|
12295
|
+
} = event;
|
12296
|
+
if (!(active !== null && active !== void 0 && active.id) || !(over !== null && over !== void 0 && over.id)) {
|
12297
|
+
return;
|
12298
|
+
}
|
12299
|
+
const activeList = getContainerById(children, active.id);
|
12300
|
+
const overList = getContainerById(children, over.id);
|
12301
|
+
if (!(activeList !== null && activeList !== void 0 && activeList.id) || !(overList !== null && overList !== void 0 && overList.id) || activeList.id === overList.id) {
|
12302
|
+
return;
|
12303
|
+
}
|
12304
|
+
move(active.id, activeList === null || activeList === void 0 ? void 0 : activeList.id, overList.id);
|
12305
|
+
}
|
12306
|
+
function handleDragEnd(event) {
|
12307
|
+
const {
|
12308
|
+
active,
|
12309
|
+
over
|
12310
|
+
} = event;
|
12311
|
+
if (!(active !== null && active !== void 0 && active.id) || !(over !== null && over !== void 0 && over.id)) {
|
12312
|
+
return;
|
12313
|
+
}
|
12314
|
+
const activeList = getContainerById(children, active.id);
|
12315
|
+
const overList = getContainerById(children, over.id);
|
12316
|
+
if (!(activeList !== null && activeList !== void 0 && activeList.id) || !(overList !== null && overList !== void 0 && overList.id) || activeList.id !== overList.id) {
|
12317
|
+
return;
|
12318
|
+
}
|
12319
|
+
reorder(active.id, over.id, overList.id);
|
12320
|
+
}
|
12321
|
+
return /*#__PURE__*/React__default.createElement(core.DndContext, Object.assign({
|
12322
|
+
collisionDetection: core.closestCenter
|
12323
|
+
}, externalProps, {
|
12324
|
+
onDragOver: handleDragOver,
|
12325
|
+
onDragEnd: handleDragEnd
|
12326
|
+
}), children);
|
12327
|
+
}
|
12328
|
+
Container.displayName = 'SortableContainer';
|
12329
|
+
|
12330
|
+
function Item$3(props) {
|
12331
|
+
const {
|
12332
|
+
asChild,
|
12333
|
+
children,
|
12334
|
+
disabled = false,
|
12335
|
+
id
|
12336
|
+
} = props;
|
12337
|
+
const {
|
12338
|
+
attributes,
|
12339
|
+
listeners,
|
12340
|
+
setNodeRef,
|
12341
|
+
transform,
|
12342
|
+
transition
|
12343
|
+
} = sortable.useSortable({
|
12344
|
+
disabled,
|
12345
|
+
id
|
12346
|
+
});
|
12347
|
+
const style = {
|
12348
|
+
transform: utilities.CSS.Transform.toString(transform),
|
12349
|
+
transition
|
12350
|
+
};
|
12351
|
+
const onPointerDown = event => {
|
12352
|
+
// allow form components, like checkboxes, to be active
|
12353
|
+
if (event.target === event.currentTarget) {
|
12354
|
+
listeners === null || listeners === void 0 ? void 0 : listeners.onPointerDown(event);
|
12355
|
+
}
|
12356
|
+
};
|
12357
|
+
const elProps = {
|
12358
|
+
...attributes,
|
12359
|
+
...listeners,
|
12360
|
+
onPointerDown,
|
12361
|
+
ref: setNodeRef,
|
12362
|
+
style
|
12363
|
+
};
|
12364
|
+
if (asChild) {
|
12365
|
+
return /*#__PURE__*/React__default.cloneElement(children, elProps);
|
12366
|
+
}
|
12367
|
+
return /*#__PURE__*/React__default.createElement("div", Object.assign({}, elProps), children);
|
12368
|
+
}
|
12369
|
+
Item$3.displayName = 'SortableListItem';
|
12370
|
+
|
12371
|
+
function List$1(externalProps) {
|
12372
|
+
const {
|
12373
|
+
children,
|
12374
|
+
id,
|
12375
|
+
...props
|
12376
|
+
} = externalProps;
|
12377
|
+
const {
|
12378
|
+
setNodeRef
|
12379
|
+
} = core.useDroppable({
|
12380
|
+
id
|
12381
|
+
});
|
12382
|
+
const items = React__default.Children.toArray(children).map(child => child.props);
|
12383
|
+
return /*#__PURE__*/React__default.createElement(sortable.SortableContext, {
|
12384
|
+
id: id,
|
12385
|
+
items: items,
|
12386
|
+
strategy: sortable.verticalListSortingStrategy
|
12387
|
+
}, /*#__PURE__*/React__default.createElement("div", Object.assign({}, props, {
|
12388
|
+
ref: id ? setNodeRef : undefined
|
12389
|
+
}), children));
|
12390
|
+
}
|
12391
|
+
List$1.displayName = 'SortableList';
|
12392
|
+
|
12393
|
+
const OrderableColumn = /*#__PURE__*/React__default.forwardRef((props, ref) => {
|
12394
|
+
var _column$columnDef$hea;
|
12395
|
+
const {
|
12396
|
+
canBeReordered,
|
12397
|
+
column,
|
12398
|
+
isReorderingAllowed,
|
12399
|
+
...attributes
|
12400
|
+
} = props;
|
12401
|
+
let icon;
|
12402
|
+
if (canBeReordered) {
|
12403
|
+
icon = /*#__PURE__*/React__default.createElement(Icon, {
|
12404
|
+
name: "drag",
|
12405
|
+
className: "text-grey-500 hover:text-grey-700 mr-0.5 -ml-2 -mt-px cursor-move"
|
12406
|
+
});
|
12407
|
+
} else if (isReorderingAllowed) {
|
12408
|
+
icon = /*#__PURE__*/React__default.createElement("span", {
|
12409
|
+
className: "mr-0.5 inline-flex w-4"
|
12410
|
+
});
|
12411
|
+
}
|
12412
|
+
return /*#__PURE__*/React__default.createElement("div", Object.assign({}, attributes, {
|
12413
|
+
className: "hover:bg-grey-100 aria-pressed:bg-grey-200 flex w-full items-center justify-between gap-x-2 rounded py-1 px-2 aria-pressed:z-10",
|
12414
|
+
ref: ref
|
12415
|
+
}), /*#__PURE__*/React__default.createElement("span", {
|
12416
|
+
className: "pointer-events-none"
|
12417
|
+
}, icon, (_column$columnDef$hea = column.columnDef.header) !== null && _column$columnDef$hea !== void 0 ? _column$columnDef$hea : column.columnDef.id), column.getCanHide() ? /*#__PURE__*/React__default.createElement(Checkbox, {
|
12418
|
+
checked: column.getIsVisible(),
|
12419
|
+
onChange: column.toggleVisibility
|
12420
|
+
}) : null);
|
12421
|
+
});
|
12422
|
+
const isOrderingAllowed = (table, column) => {
|
12423
|
+
var _column$columnDef$met;
|
12424
|
+
const meta = table.options.meta;
|
12425
|
+
if (table.options.enablePinning) {
|
12426
|
+
return true;
|
12427
|
+
}
|
12428
|
+
return meta.enableColumnReordering ? !((_column$columnDef$met = column.columnDef.meta) !== null && _column$columnDef$met !== void 0 && _column$columnDef$met.disableReordering) : false;
|
12429
|
+
};
|
12430
|
+
const SortableColumnContainer = ({
|
12431
|
+
state,
|
12432
|
+
moveColumn,
|
12433
|
+
reorderColumn,
|
12434
|
+
table
|
12435
|
+
}) => {
|
12436
|
+
var _ref;
|
12437
|
+
const meta = table.options.meta;
|
12438
|
+
const reorder = (activeId, overId, listId) => {
|
12439
|
+
const draggedColumn = state[listId].find(c => c.id === activeId);
|
12440
|
+
const targetColumn = state[listId].find(c => c.id === overId);
|
12441
|
+
if (draggedColumn && targetColumn) {
|
12442
|
+
reorderColumn(draggedColumn.id, targetColumn.id, listId === 'pinned');
|
12443
|
+
}
|
12444
|
+
};
|
12445
|
+
const move = (activeId, oldListId) => {
|
12446
|
+
const column = state[oldListId].find(c => c.id === activeId);
|
12447
|
+
if (column) {
|
12448
|
+
moveColumn(column);
|
12449
|
+
}
|
12450
|
+
};
|
12451
|
+
const isReorderingAllowed = (_ref = meta.enableColumnReordering || table.options.enablePinning) !== null && _ref !== void 0 ? _ref : false;
|
12452
|
+
if (!table.options.enablePinning) {
|
12453
|
+
return /*#__PURE__*/React__default.createElement(Container, {
|
12454
|
+
reorder: reorder,
|
12455
|
+
move: move
|
12456
|
+
}, /*#__PURE__*/React__default.createElement(List$1, {
|
12457
|
+
id: "other",
|
12458
|
+
className: "flex min-h-[theme(spacing.8)] flex-col gap-y-px px-2"
|
12459
|
+
}, state.other.map(column => {
|
12460
|
+
var _column$columnDef$met2;
|
12461
|
+
const canBeReordered = isOrderingAllowed(table, column);
|
12462
|
+
return /*#__PURE__*/React__default.createElement(Item$3, {
|
12463
|
+
key: column.id,
|
12464
|
+
disabled: (_column$columnDef$met2 = column.columnDef.meta) === null || _column$columnDef$met2 === void 0 ? void 0 : _column$columnDef$met2.disableReordering,
|
12465
|
+
id: column.id,
|
12466
|
+
asChild: true
|
12467
|
+
}, /*#__PURE__*/React__default.createElement(OrderableColumn, {
|
12468
|
+
canBeReordered: canBeReordered,
|
12469
|
+
column: column,
|
12470
|
+
isReorderingAllowed: isReorderingAllowed,
|
12471
|
+
onDoubleClick: event => {
|
12472
|
+
event.stopPropagation();
|
12473
|
+
move(column.id, 'other');
|
12474
|
+
}
|
12475
|
+
}));
|
12476
|
+
})));
|
12477
|
+
}
|
12478
|
+
return /*#__PURE__*/React__default.createElement(Container, {
|
12479
|
+
reorder: reorder,
|
12480
|
+
move: move
|
12481
|
+
}, /*#__PURE__*/React__default.createElement("h5", {
|
12482
|
+
className: "mx-4"
|
12483
|
+
}, "Pinned columns"), /*#__PURE__*/React__default.createElement(List$1, {
|
12484
|
+
id: "pinned",
|
12485
|
+
className: "flex min-h-[theme(spacing.8)] flex-col gap-y-px px-2"
|
12486
|
+
}, state.pinned.length ? state.pinned.map(column => {
|
12487
|
+
var _column$columnDef$met3;
|
12488
|
+
const canBeReordered = isOrderingAllowed(table, column);
|
12489
|
+
return /*#__PURE__*/React__default.createElement(Item$3, {
|
12490
|
+
key: column.id,
|
12491
|
+
disabled: (_column$columnDef$met3 = column.columnDef.meta) === null || _column$columnDef$met3 === void 0 ? void 0 : _column$columnDef$met3.disableReordering,
|
12492
|
+
id: column.id,
|
12493
|
+
asChild: true
|
12494
|
+
}, /*#__PURE__*/React__default.createElement(OrderableColumn, {
|
12495
|
+
canBeReordered: canBeReordered,
|
12496
|
+
column: column,
|
12497
|
+
isReorderingAllowed: isReorderingAllowed,
|
12498
|
+
onDoubleClick: event => {
|
12499
|
+
event.stopPropagation();
|
12500
|
+
move(column.id, 'pinned');
|
12501
|
+
}
|
12502
|
+
}));
|
12503
|
+
}) : /*#__PURE__*/React__default.createElement("p", {
|
12504
|
+
className: "text-grey-500 mb-0 flex h-8 items-center px-2"
|
12505
|
+
}, "Drop column here to pin")), /*#__PURE__*/React__default.createElement("h5", {
|
12506
|
+
className: "mx-4"
|
12507
|
+
}, "Other columns"), /*#__PURE__*/React__default.createElement(List$1, {
|
12508
|
+
id: "other",
|
12509
|
+
className: "flex min-h-[theme(spacing.8)] flex-col gap-y-px px-2"
|
12510
|
+
}, state.other.length ? state.other.map(column => {
|
12511
|
+
var _column$columnDef$met4;
|
12512
|
+
const canBeReordered = isOrderingAllowed(table, column);
|
12513
|
+
return /*#__PURE__*/React__default.createElement(Item$3, {
|
12514
|
+
key: column.id,
|
12515
|
+
disabled: (_column$columnDef$met4 = column.columnDef.meta) === null || _column$columnDef$met4 === void 0 ? void 0 : _column$columnDef$met4.disableReordering,
|
12516
|
+
id: column.id,
|
12517
|
+
asChild: true
|
12518
|
+
}, /*#__PURE__*/React__default.createElement(OrderableColumn, {
|
12519
|
+
canBeReordered: canBeReordered,
|
12520
|
+
column: column,
|
12521
|
+
isReorderingAllowed: isReorderingAllowed,
|
12522
|
+
onDoubleClick: event => {
|
12523
|
+
event.stopPropagation();
|
12524
|
+
move(column.id, 'other');
|
12525
|
+
}
|
12526
|
+
}));
|
12527
|
+
}) : /*#__PURE__*/React__default.createElement("p", {
|
12528
|
+
className: "text-grey-500 mb-0 flex h-8 items-center px-2"
|
12529
|
+
}, "Drop column here to unpin")));
|
12530
|
+
};
|
12531
|
+
const reorder = (draggedColumnId, targetColumnId, list = []) => {
|
12532
|
+
const nextColumnOrder = [...list];
|
12533
|
+
nextColumnOrder.splice(nextColumnOrder.findIndex(c => c.id === targetColumnId), 0, nextColumnOrder.splice(nextColumnOrder.findIndex(c => c.id === draggedColumnId), 1)[0]);
|
12534
|
+
return nextColumnOrder;
|
12535
|
+
};
|
12536
|
+
const ColumnSettingsButton = ({
|
12537
|
+
table
|
12538
|
+
}) => {
|
12539
|
+
const [query, setQuery] = React__default.useState('');
|
12540
|
+
const columns = table.getAllLeafColumns().filter(column => !isInternalColumn(column.id));
|
12541
|
+
const [state, setState] = React__default.useState({
|
12542
|
+
pinned: columns.filter(column => column.getIsPinned()),
|
12543
|
+
other: columns.filter(column => !column.getIsPinned())
|
12544
|
+
});
|
12545
|
+
const pinColumn = column => {
|
12546
|
+
if (state.pinned.find(c => c.id === column.id)) {
|
12547
|
+
setState(currentState => ({
|
12548
|
+
pinned: currentState.pinned.filter(c => c.id !== column.id),
|
12549
|
+
other: [column].concat(...currentState.other)
|
12550
|
+
}));
|
12551
|
+
} else {
|
12552
|
+
setState(currentState => ({
|
12553
|
+
pinned: currentState.pinned.concat(column),
|
12554
|
+
other: currentState.other.filter(c => c.id !== column.id)
|
12555
|
+
}));
|
12556
|
+
}
|
12557
|
+
};
|
12558
|
+
const reorderColumn = (draggedColumnId, targetColumnId, pinned) => {
|
12559
|
+
if (pinned) {
|
12560
|
+
setState(currentState => ({
|
12561
|
+
...currentState,
|
12562
|
+
pinned: reorder(draggedColumnId, targetColumnId, currentState.pinned)
|
12563
|
+
}));
|
12564
|
+
} else {
|
12565
|
+
setState(currentState => ({
|
12566
|
+
...currentState,
|
12567
|
+
other: reorder(draggedColumnId, targetColumnId, currentState.other)
|
12568
|
+
}));
|
12569
|
+
}
|
12570
|
+
};
|
12571
|
+
// probably a more elegant way to do this without local state but had
|
12572
|
+
// a range of issues using the native apis directly
|
12573
|
+
React__default.useEffect(() => {
|
12574
|
+
const internals = [];
|
12575
|
+
if (table.options.enableRowSelection) {
|
12576
|
+
internals.push(COLUMN_ID_FOR_SELECTION);
|
12577
|
+
}
|
12578
|
+
if (table.options.enableExpanding) {
|
12579
|
+
internals.push(COLUMN_ID_FOR_EXPANSION);
|
12580
|
+
}
|
12581
|
+
table.setColumnPinning({
|
12582
|
+
left: internals.concat(...state.pinned.map(c => c.id))
|
12583
|
+
});
|
12584
|
+
table.setColumnOrder(internals.concat([...state.pinned, ...state.other].map(c => c.id)));
|
12585
|
+
}, [state]);
|
12586
|
+
return /*#__PURE__*/React__default.createElement(IconButton, {
|
12587
|
+
"aria-label": "Change column settings",
|
12588
|
+
icon: "columns",
|
12589
|
+
popover: popoverProps => /*#__PURE__*/React__default.createElement(Popover, Object.assign({}, popoverProps), /*#__PURE__*/React__default.createElement(Popover.Content, {
|
12590
|
+
align: "end"
|
12591
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
12592
|
+
className: "flex w-60 flex-col gap-2"
|
12593
|
+
}, /*#__PURE__*/React__default.createElement(Input, {
|
12594
|
+
onChange: event => setQuery(event.target.value),
|
12595
|
+
placeholder: "Search column...",
|
12596
|
+
value: query
|
12597
|
+
}), /*#__PURE__*/React__default.createElement("div", {
|
12598
|
+
className: "-ml-4 -mb-2 max-h-64 w-[calc(100%_+_theme(spacing.8))] overflow-auto"
|
12599
|
+
}, query ? columns.filter(column => {
|
12600
|
+
var _column$columnDef$hea2;
|
12601
|
+
return (_column$columnDef$hea2 = column.columnDef.header) === null || _column$columnDef$hea2 === void 0 ? void 0 : _column$columnDef$hea2.toString().includes(query);
|
12602
|
+
}).map(column => /*#__PURE__*/React__default.createElement(OrderableColumn, {
|
12603
|
+
key: column.id,
|
12604
|
+
canBeReordered: false,
|
12605
|
+
column: column,
|
12606
|
+
isReorderingAllowed: false
|
12607
|
+
})) : /*#__PURE__*/React__default.createElement(SortableColumnContainer, {
|
12608
|
+
state: state,
|
12609
|
+
moveColumn: pinColumn,
|
12610
|
+
reorderColumn: reorderColumn,
|
12611
|
+
table: table
|
12612
|
+
}))))),
|
12613
|
+
tooltip: "Column settings"
|
12614
|
+
});
|
12615
|
+
};
|
12616
|
+
|
12617
|
+
const ExpandedRow = ({
|
12618
|
+
index,
|
12619
|
+
setSize,
|
12620
|
+
...props
|
12621
|
+
}) => {
|
12622
|
+
const ref = React__default.useRef(null);
|
12623
|
+
React__default.useEffect(() => {
|
12624
|
+
if (ref.current) {
|
12625
|
+
var _ref$current;
|
12626
|
+
const height = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.getBoundingClientRect().height;
|
12627
|
+
setSize(sizes => {
|
12628
|
+
if (height !== sizes[index]) {
|
12629
|
+
var _ref$current2;
|
12630
|
+
return {
|
12631
|
+
...sizes,
|
12632
|
+
[index]: (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.getBoundingClientRect().height
|
12633
|
+
};
|
12634
|
+
}
|
12635
|
+
return sizes;
|
12636
|
+
});
|
12637
|
+
}
|
12638
|
+
}, []);
|
12639
|
+
return /*#__PURE__*/React__default.createElement("div", Object.assign({
|
12640
|
+
className: "border-grey-300 bg-grey-50 col-span-full border-b p-4"
|
12641
|
+
}, props, {
|
12642
|
+
ref: ref
|
12643
|
+
}));
|
12644
|
+
};
|
12645
|
+
|
12646
|
+
const useSeparatedChildren$1 = initialChildren => {
|
12647
|
+
return React__default.useMemo(() => {
|
12648
|
+
const columns = [];
|
12649
|
+
let toolbar;
|
12650
|
+
React__default.Children.toArray(initialChildren).forEach(child => {
|
12651
|
+
var _child$type, _child$type2;
|
12652
|
+
if (((_child$type = child.type) === null || _child$type === void 0 ? void 0 : _child$type.displayName) === 'Table2Column') {
|
12653
|
+
columns.push(child);
|
12654
|
+
} else if (((_child$type2 = child.type) === null || _child$type2 === void 0 ? void 0 : _child$type2.displayName) === 'Table2Toolbar') {
|
12655
|
+
toolbar = child;
|
12656
|
+
}
|
12657
|
+
});
|
12658
|
+
return [columns, toolbar];
|
12659
|
+
}, [initialChildren]);
|
12660
|
+
};
|
12661
|
+
|
12662
|
+
const useBoundaryOverflowDetection = (ref, dependencies = []) => {
|
12663
|
+
const [boundaryIndex, setBoundaryIndex] = React__default.useState();
|
12664
|
+
React__default.useEffect(() => {
|
12665
|
+
if (ref.current) {
|
12666
|
+
const boundaryChildIndex = getIndexOfFirstChildOverflowingParent(ref.current);
|
12667
|
+
setBoundaryIndex(boundaryChildIndex);
|
12668
|
+
}
|
12669
|
+
}, [ref, ...dependencies]);
|
12670
|
+
return boundaryIndex;
|
12671
|
+
};
|
12672
|
+
|
12673
|
+
const BUTTON_CLASSES = /*#__PURE__*/cn( /*#__PURE__*/getButtonClasses(), 'hover:bg-white/[0.08] disabled:opacity-50 disabled:cursor-not-allowed flex-shrink-0 rounded px-2');
|
12674
|
+
function unwrapActionProperty(property, rowsData) {
|
12675
|
+
return typeof property === 'function' ? property(rowsData) : property;
|
12676
|
+
}
|
12677
|
+
function createActionButton(actions, rowsData, onReset) {
|
12678
|
+
return actions.map((action, index) => {
|
12679
|
+
const button = /*#__PURE__*/React__default.createElement("button", {
|
12680
|
+
className: BUTTON_CLASSES,
|
12681
|
+
disabled: unwrapActionProperty(action.disabled, rowsData),
|
12682
|
+
onClick: action.onClick ? () => action.onClick ? action.onClick(rowsData, onReset) : undefined : undefined
|
12683
|
+
}, action.icon ? /*#__PURE__*/React__default.createElement(Icon, {
|
12684
|
+
name: unwrapActionProperty(action.icon, rowsData)
|
12685
|
+
}) : null, unwrapActionProperty(action.text, rowsData));
|
12686
|
+
return /*#__PURE__*/React__default.createElement(React__default.Fragment, {
|
12687
|
+
key: index
|
12688
|
+
}, typeof action.dialog === 'function' ? action.dialog(rowsData, onReset)({
|
12689
|
+
trigger: button
|
12690
|
+
}) : button);
|
12691
|
+
});
|
12692
|
+
}
|
12693
|
+
function BatchActionsMenu({
|
12694
|
+
actionsForTable = [],
|
12695
|
+
summary,
|
12696
|
+
table,
|
12697
|
+
...props
|
12698
|
+
}) {
|
12699
|
+
const className = cn('bg-blue-900 yt-shadow flex w-96 flex-col gap-2 divide-y divide-white/25 rounded p-2 text-white', props.className);
|
12700
|
+
const ref = React__default.useRef(null);
|
12701
|
+
const boundaryIndex = useBoundaryOverflowDetection(ref, actionsForTable);
|
12702
|
+
const rows = table.getSelectedRowModel().rows;
|
12703
|
+
const rowsData = rows.map(row => row.original);
|
12704
|
+
const handleReset = () => table.toggleAllRowsSelected(false);
|
12705
|
+
const isVisible = action => typeof action.visible !== 'undefined' ? typeof action.visible === 'function' ? action.visible(rowsData) : action.visible : true;
|
12706
|
+
const visibleActions = actionsForTable.filter(isVisible);
|
12707
|
+
let content;
|
12708
|
+
if (boundaryIndex !== undefined && boundaryIndex !== null && boundaryIndex < actionsForTable.length) {
|
12709
|
+
const actions = visibleActions.slice(0, boundaryIndex);
|
12710
|
+
const moreActions = visibleActions.slice(boundaryIndex);
|
12711
|
+
content = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, createActionButton(actions, rowsData, handleReset), moreActions.length ? /*#__PURE__*/React__default.createElement(Menu$1, null, /*#__PURE__*/React__default.createElement(Menu$1.Trigger, null, /*#__PURE__*/React__default.createElement("button", {
|
12712
|
+
className: cn(BUTTON_CLASSES, 'ml-auto w-8')
|
12713
|
+
}, /*#__PURE__*/React__default.createElement(Icon, {
|
12714
|
+
name: "more",
|
12715
|
+
className: "m-0 p-0"
|
12716
|
+
}))), /*#__PURE__*/React__default.createElement(Menu$1.Content, null, moreActions.map((action, index) => /*#__PURE__*/React__default.createElement(Menu$1.Item, {
|
12717
|
+
key: index,
|
12718
|
+
dialog: action.dialog ? action.dialog(rowsData, handleReset) : undefined,
|
12719
|
+
disabled: unwrapActionProperty(action.disabled, rowsData),
|
12720
|
+
icon: unwrapActionProperty(action.icon, rowsData),
|
12721
|
+
onClick: action.onClick ? () => action.onClick ? action.onClick(rowsData, handleReset) : undefined : undefined
|
12722
|
+
}, unwrapActionProperty(action.text, rowsData))))) : null);
|
12723
|
+
} else {
|
12724
|
+
content = createActionButton(visibleActions, rowsData, handleReset);
|
12725
|
+
}
|
12726
|
+
return /*#__PURE__*/React__default.createElement("div", Object.assign({}, props, {
|
12727
|
+
className: className,
|
12728
|
+
tabIndex: 0
|
12729
|
+
}), /*#__PURE__*/React__default.createElement("div", {
|
12730
|
+
className: "flex items-center justify-between gap-2 px-2"
|
12731
|
+
}, rows.length, " items selected ", summary ? ` - ${summary(rowsData)}` : undefined, /*#__PURE__*/React__default.createElement(Tooltip, {
|
12732
|
+
title: "Reset selected",
|
12733
|
+
placement: "top"
|
12734
|
+
}, /*#__PURE__*/React__default.createElement("button", {
|
12735
|
+
"aria-label": "Reset selected",
|
12736
|
+
className: "rounded hover:bg-white/[0.08]",
|
12737
|
+
onClick: handleReset
|
12738
|
+
}, /*#__PURE__*/React__default.createElement(Icon, {
|
12739
|
+
name: "close"
|
12740
|
+
})))), /*#__PURE__*/React__default.createElement("div", {
|
12741
|
+
className: "flex w-full gap-px overflow-hidden px-1 pt-2",
|
12742
|
+
ref: ref
|
12743
|
+
}, content));
|
12744
|
+
}
|
12745
|
+
|
12746
|
+
const HOVER_THRESHOLD_MS = 50;
|
12747
|
+
const Row$1 = ({
|
12748
|
+
row,
|
12749
|
+
rowIndex,
|
12750
|
+
table,
|
12751
|
+
...props
|
12752
|
+
}) => {
|
12753
|
+
const meta = table.options.meta;
|
12754
|
+
const isActiveRow = meta.activeRowIndex === rowIndex;
|
12755
|
+
const isDragging = meta.dragging[row.id];
|
12756
|
+
const [validationErrors, setValidationErrors] = React__default.useState(null);
|
12757
|
+
const [isRowIndicatorVisible, setIsRowIndicatorVisible] = React__default.useState(false);
|
12758
|
+
// This effect aims to focus the first focussable cell when edit mode is turned on.
|
12759
|
+
React__default.useEffect(() => {
|
12760
|
+
var _meta$tableRef$curren;
|
12761
|
+
const isFocusInsideTable = (_meta$tableRef$curren = meta.tableRef.current) === null || _meta$tableRef$curren === void 0 ? void 0 : _meta$tableRef$curren.contains(document.activeElement);
|
12762
|
+
// If the foucs is outside the table i.e., table action popups, search etc., then don't focus the first cell.
|
12763
|
+
if (meta.editMode.isEditing && isActiveRow && isFocusInsideTable) {
|
12764
|
+
meta.editMode.moveToFirstColumn(meta.focussableColumnIndexes);
|
12765
|
+
}
|
12766
|
+
// We are intentionally not adding activeRow to the depency variable so that everytime active row is changed,
|
12767
|
+
// first focussable cell is not focussed.
|
12768
|
+
}, [meta.editMode.isEditing, meta.focussableColumnIndexes]);
|
12769
|
+
const handleSetValidationErrors = errors => {
|
12770
|
+
if (errors !== null) {
|
12771
|
+
meta.setShouldDisableTableActions(true);
|
12772
|
+
}
|
12773
|
+
setValidationErrors(errors);
|
12774
|
+
};
|
12775
|
+
const hoverTimerRef = React__default.useRef();
|
12776
|
+
const handleEnter = () => {
|
12777
|
+
hoverTimerRef.current = setTimeout(() => meta.setHoveredRowIndex(rowIndex), HOVER_THRESHOLD_MS);
|
12778
|
+
};
|
12779
|
+
const handleLeave = () => {
|
12780
|
+
clearTimeout(hoverTimerRef.current);
|
12781
|
+
hoverTimerRef.current = undefined;
|
12782
|
+
meta.setHoveredRowIndex(undefined);
|
12783
|
+
};
|
12784
|
+
return /*#__PURE__*/React__default.createElement(RowProvider, {
|
12785
|
+
validationErrors: validationErrors,
|
12786
|
+
setValidationErrors: handleSetValidationErrors,
|
12787
|
+
isRowIndicatorVisible: isRowIndicatorVisible,
|
12788
|
+
setIsRowIndicatorVisible: setIsRowIndicatorVisible
|
12789
|
+
}, /*#__PURE__*/React__default.createElement("div", Object.assign({}, props, {
|
12790
|
+
role: "row",
|
12791
|
+
draggable: true,
|
12792
|
+
"aria-current": isActiveRow ? 'true' : undefined,
|
12793
|
+
"aria-grabbed": isDragging ? 'true' : undefined,
|
12794
|
+
onMouseEnter: handleEnter,
|
12795
|
+
onMouseLeave: handleLeave
|
12796
|
+
})));
|
12797
|
+
};
|
12798
|
+
|
12799
|
+
const Column$1 = ({
|
12800
|
+
allColumns,
|
12801
|
+
column,
|
12802
|
+
index,
|
12803
|
+
table,
|
12804
|
+
...props
|
12805
|
+
}) => {
|
12806
|
+
const handleChange = id => {
|
12807
|
+
table.setColumnFilters(currentColumnFilters => {
|
12808
|
+
const nextColumnFilters = [...currentColumnFilters];
|
12809
|
+
nextColumnFilters[index].id = id;
|
12810
|
+
nextColumnFilters[index].value = {};
|
12811
|
+
return nextColumnFilters;
|
12812
|
+
});
|
12813
|
+
};
|
12814
|
+
return /*#__PURE__*/React__default.createElement(Select2, Object.assign({}, props, {
|
12815
|
+
autoFocus: true,
|
12816
|
+
onChange: handleChange,
|
12817
|
+
value: column.id
|
12818
|
+
}), allColumns.map(c => /*#__PURE__*/React__default.createElement(Select2.Option, {
|
12819
|
+
key: c.id,
|
12820
|
+
disabled: !c.getCanFilter() || c.id !== column.id && !!table.getState().columnFilters.find(f => f.id === c.id),
|
12821
|
+
value: c.id
|
12822
|
+
}, String(c.columnDef.header))));
|
12823
|
+
};
|
12824
|
+
|
12825
|
+
const Comparator = ({
|
12826
|
+
column,
|
12827
|
+
comparator,
|
12828
|
+
validComparators,
|
12829
|
+
...props
|
12830
|
+
}) => {
|
12831
|
+
const handleChange = comparator => {
|
12832
|
+
column.setFilterValue(currentFilterValue => ({
|
12833
|
+
comparator,
|
12834
|
+
value: comparator === Table2FilterComparator.IsBetween ? [] : currentFilterValue.value
|
12835
|
+
}));
|
12836
|
+
};
|
12837
|
+
React__default.useEffect(() => {
|
12838
|
+
if (comparator === undefined) {
|
12839
|
+
const initialComparator = validComparators[0];
|
12840
|
+
column.setFilterValue(currentFilterValue => ({
|
12841
|
+
comparator: initialComparator,
|
12842
|
+
value: initialComparator === Table2FilterComparator.IsBetween && !Array.isArray(currentFilterValue.value) ? [] : currentFilterValue.value
|
12843
|
+
}));
|
12844
|
+
}
|
12845
|
+
}, []);
|
12846
|
+
return /*#__PURE__*/React__default.createElement(Select2, Object.assign({}, props, {
|
12847
|
+
onChange: handleChange,
|
12848
|
+
value: comparator
|
12849
|
+
}), validComparators.map(comp => /*#__PURE__*/React__default.createElement(Select2.Option, {
|
12850
|
+
key: comp,
|
12851
|
+
value: comp
|
12852
|
+
}, getComparatorText(comp))));
|
12853
|
+
};
|
12854
|
+
const getComparatorText = comparator => {
|
12855
|
+
switch (comparator) {
|
12856
|
+
case Table2FilterComparator.Contains:
|
12857
|
+
return 'Contains';
|
12858
|
+
case Table2FilterComparator.DoesNotContain:
|
12859
|
+
return 'Does not contain';
|
12860
|
+
case Table2FilterComparator.IsEqualTo:
|
12861
|
+
return 'Is';
|
12862
|
+
case Table2FilterComparator.IsNotEqualTo:
|
12863
|
+
return 'Is not';
|
12864
|
+
case Table2FilterComparator.IsGreaterThan:
|
12865
|
+
return 'Is greater than';
|
12866
|
+
case Table2FilterComparator.IsLessThan:
|
12867
|
+
return 'Is less than';
|
12868
|
+
case Table2FilterComparator.IsBetween:
|
12869
|
+
return 'Is between';
|
12870
|
+
case Table2FilterComparator.IsOneOf:
|
12871
|
+
return 'Is one of';
|
12872
|
+
case Table2FilterComparator.IsNoneOf:
|
12873
|
+
return 'Is none of';
|
12874
|
+
case Table2FilterComparator.IsAllOf:
|
12875
|
+
return 'Is all of';
|
12876
|
+
}
|
12877
|
+
};
|
12878
|
+
|
12879
|
+
const InferredControl = ({
|
12880
|
+
column,
|
12881
|
+
comparator,
|
12882
|
+
value
|
12883
|
+
}) => {
|
12884
|
+
var _column$columnDef$met2, _column$columnDef$met3;
|
12885
|
+
const ariaLabel = column.columnDef.header;
|
12886
|
+
if (comparator === Table2FilterComparator.IsBetween) {
|
12887
|
+
var _column$columnDef$met;
|
12888
|
+
const fromValue = Array.isArray(value) ? value[0] : undefined;
|
12889
|
+
const toValue = Array.isArray(value) ? value[1] : undefined;
|
12890
|
+
if (((_column$columnDef$met = column.columnDef.meta) === null || _column$columnDef$met === void 0 ? void 0 : _column$columnDef$met.dataType) === 'datetime') {
|
12891
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
12892
|
+
className: "flex flex-grow items-center gap-2"
|
12893
|
+
}, /*#__PURE__*/React__default.createElement(Datepicker, {
|
12894
|
+
"aria-label": ariaLabel,
|
12895
|
+
onChange: event => column.setFilterValue(currentValue => ({
|
12896
|
+
...currentValue,
|
12897
|
+
value: [event.detail, toValue]
|
12898
|
+
})),
|
12899
|
+
value: fromValue
|
12900
|
+
}), /*#__PURE__*/React__default.createElement(Datepicker, {
|
12901
|
+
"aria-label": ariaLabel,
|
12902
|
+
onChange: event => column.setFilterValue(currentValue => ({
|
12903
|
+
...currentValue,
|
12904
|
+
value: [fromValue, event.detail]
|
12905
|
+
})),
|
12906
|
+
value: toValue
|
12907
|
+
}));
|
12908
|
+
}
|
12909
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
12910
|
+
className: "flex flex-grow items-center gap-2"
|
12911
|
+
}, /*#__PURE__*/React__default.createElement(Input, {
|
12912
|
+
"aria-label": ariaLabel,
|
12913
|
+
className: "flex-grow",
|
12914
|
+
placeholder: "from",
|
12915
|
+
onChange: event => {
|
12916
|
+
const value = parseInt(event.target.value);
|
12917
|
+
column.setFilterValue(currentValue => ({
|
12918
|
+
...currentValue,
|
12919
|
+
value: [isNaN(value) ? undefined : value, toValue]
|
12920
|
+
}));
|
12921
|
+
},
|
12922
|
+
value: fromValue !== null && fromValue !== void 0 ? fromValue : ''
|
12923
|
+
}), /*#__PURE__*/React__default.createElement(Input, {
|
12924
|
+
className: "flex-grow",
|
12925
|
+
placeholder: "to",
|
12926
|
+
onChange: event => {
|
12927
|
+
const value = parseInt(event.target.value);
|
12928
|
+
column.setFilterValue(currentValue => ({
|
12929
|
+
...currentValue,
|
12930
|
+
value: [fromValue, isNaN(value) ? undefined : value]
|
12931
|
+
}));
|
12932
|
+
},
|
12933
|
+
value: toValue !== null && toValue !== void 0 ? toValue : ''
|
12934
|
+
}));
|
12935
|
+
}
|
12936
|
+
if (((_column$columnDef$met2 = column.columnDef.meta) === null || _column$columnDef$met2 === void 0 ? void 0 : _column$columnDef$met2.dataType) === 'datetime') {
|
12937
|
+
return /*#__PURE__*/React__default.createElement(Datepicker, {
|
12938
|
+
"aria-label": ariaLabel,
|
12939
|
+
onChange: event => column.setFilterValue(currentValue => ({
|
12940
|
+
...currentValue,
|
12941
|
+
value: event.detail
|
12942
|
+
})),
|
12943
|
+
value: value
|
12944
|
+
});
|
12945
|
+
} else if (((_column$columnDef$met3 = column.columnDef.meta) === null || _column$columnDef$met3 === void 0 ? void 0 : _column$columnDef$met3.dataType) === 'boolean') {
|
12946
|
+
return /*#__PURE__*/React__default.createElement(Switch, {
|
12947
|
+
"aria-label": ariaLabel,
|
12948
|
+
onChange: checked => column.setFilterValue(currentValue => ({
|
12949
|
+
...currentValue,
|
12950
|
+
value: checked
|
12951
|
+
})),
|
12952
|
+
checked: value
|
12953
|
+
});
|
12954
|
+
}
|
12955
|
+
return /*#__PURE__*/React__default.createElement(Input, {
|
12956
|
+
"aria-label": ariaLabel,
|
12957
|
+
className: "flex-grow",
|
12958
|
+
onChange: event => column.setFilterValue(currentValue => ({
|
12959
|
+
...currentValue,
|
12960
|
+
value: event.target.value
|
12961
|
+
})),
|
12962
|
+
required: true,
|
12963
|
+
value: value !== null && value !== void 0 ? value : ''
|
12964
|
+
});
|
12965
|
+
};
|
12966
|
+
|
12967
|
+
const ColumnFilter = props => {
|
12968
|
+
var _column$columnDef$hea, _column$columnDef$met, _column$columnDef$met2, _control;
|
12969
|
+
const {
|
12970
|
+
allColumns,
|
12971
|
+
column,
|
12972
|
+
index,
|
12973
|
+
table
|
12974
|
+
} = props;
|
12975
|
+
const {
|
12976
|
+
comparator,
|
12977
|
+
value
|
12978
|
+
} = column.getFilterValue();
|
12979
|
+
const ariaLabel = String((_column$columnDef$hea = column.columnDef.header) !== null && _column$columnDef$hea !== void 0 ? _column$columnDef$hea : '');
|
12980
|
+
const ref = React__default.useRef(null);
|
12981
|
+
let control;
|
12982
|
+
const controlType = (_column$columnDef$met = (_column$columnDef$met2 = column.columnDef.meta) === null || _column$columnDef$met2 === void 0 ? void 0 : _column$columnDef$met2.control) !== null && _column$columnDef$met !== void 0 ? _column$columnDef$met : 'input';
|
12983
|
+
if (typeof controlType === 'function') {
|
12984
|
+
control = controlType({
|
12985
|
+
onBlur: () => Promise.resolve(),
|
12986
|
+
onFocus: () => Promise.resolve(),
|
12987
|
+
ref,
|
12988
|
+
setValue: value => column.setFilterValue(currentValue => ({
|
12989
|
+
...currentValue,
|
12990
|
+
value
|
12991
|
+
})),
|
12992
|
+
value,
|
12993
|
+
disabled: false,
|
12994
|
+
readOnly: false
|
12995
|
+
});
|
12996
|
+
} else if (controlType === 'input') {
|
12997
|
+
control = /*#__PURE__*/React__default.createElement(Input, {
|
12998
|
+
"aria-label": ariaLabel,
|
12999
|
+
onChange: event => column.setFilterValue(currentValue => ({
|
13000
|
+
...currentValue,
|
13001
|
+
value: event.target.value
|
13002
|
+
})),
|
13003
|
+
value: String(value !== null && value !== void 0 ? value : '')
|
13004
|
+
});
|
13005
|
+
} else if (controlType === 'datepicker') {
|
13006
|
+
control = /*#__PURE__*/React__default.createElement(Datepicker, {
|
13007
|
+
"aria-label": ariaLabel,
|
13008
|
+
onChange: event => column.setFilterValue(currentValue => ({
|
13009
|
+
...currentValue,
|
13010
|
+
value: event.detail
|
13011
|
+
})),
|
13012
|
+
value: value
|
13013
|
+
});
|
13014
|
+
} else if (controlType === 'switch') {
|
13015
|
+
control = /*#__PURE__*/React__default.createElement(Switch, {
|
13016
|
+
"aria-label": ariaLabel,
|
13017
|
+
checked: Boolean(value),
|
13018
|
+
onChange: checked => column.setFilterValue(currentValue => ({
|
13019
|
+
...currentValue,
|
13020
|
+
value: checked
|
13021
|
+
}))
|
13022
|
+
});
|
13023
|
+
}
|
13024
|
+
const handleRemove = () => column.setFilterValue(undefined);
|
13025
|
+
const comparators = guessComparatorsBasedOnControl(controlType, control);
|
13026
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
13027
|
+
className: "mb-2 flex gap-2"
|
13028
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
13029
|
+
className: "flex w-14 flex-shrink-0 items-center justify-end pr-2 text-right"
|
13030
|
+
}, index === 0 ? 'Where' : 'And'), /*#__PURE__*/React__default.createElement(Column$1, {
|
13031
|
+
className: "!w-32 flex-shrink-0",
|
13032
|
+
allColumns: allColumns,
|
13033
|
+
column: column,
|
13034
|
+
index: index,
|
13035
|
+
table: table
|
13036
|
+
}), /*#__PURE__*/React__default.createElement(Comparator, {
|
13037
|
+
className: "!w-32 flex-shrink-0",
|
13038
|
+
column: column,
|
13039
|
+
comparator: comparator,
|
13040
|
+
validComparators: comparators
|
13041
|
+
}), comparator !== undefined ? /*#__PURE__*/React__default.createElement("div", {
|
13042
|
+
className: "flex flex-grow items-center"
|
13043
|
+
}, (_control = control) !== null && _control !== void 0 ? _control : /*#__PURE__*/React__default.createElement(InferredControl, {
|
13044
|
+
column: column,
|
13045
|
+
comparator: comparator,
|
13046
|
+
value: value
|
13047
|
+
})) : null, /*#__PURE__*/React__default.createElement(IconButton, {
|
13048
|
+
appearance: "discrete",
|
13049
|
+
icon: "close",
|
13050
|
+
onClick: handleRemove
|
13051
|
+
}));
|
13052
|
+
};
|
13053
|
+
const guessComparatorsBasedOnControl = (control, instance) => {
|
13054
|
+
if ( /*#__PURE__*/React__default.isValidElement(instance)) {
|
13055
|
+
const {
|
13056
|
+
props,
|
13057
|
+
type
|
13058
|
+
} = instance;
|
13059
|
+
if (type.displayName === 'Select2') {
|
13060
|
+
if (props.multiple) {
|
13061
|
+
return [Table2FilterComparator.IsOneOf, Table2FilterComparator.IsNoneOf, Table2FilterComparator.IsAllOf];
|
13062
|
+
}
|
13063
|
+
return [Table2FilterComparator.IsEqualTo, Table2FilterComparator.IsNotEqualTo];
|
13064
|
+
}
|
13065
|
+
}
|
13066
|
+
switch (control) {
|
13067
|
+
case 'datepicker':
|
13068
|
+
return [Table2FilterComparator.IsEqualTo, Table2FilterComparator.IsNotEqualTo, Table2FilterComparator.IsGreaterThan, Table2FilterComparator.IsLessThan, Table2FilterComparator.IsBetween];
|
13069
|
+
case 'switch':
|
13070
|
+
return [Table2FilterComparator.IsEqualTo];
|
13071
|
+
default:
|
13072
|
+
return [Table2FilterComparator.Contains, Table2FilterComparator.DoesNotContain, Table2FilterComparator.IsEqualTo, Table2FilterComparator.IsNotEqualTo, Table2FilterComparator.IsGreaterThan, Table2FilterComparator.IsLessThan, Table2FilterComparator.IsBetween];
|
13073
|
+
}
|
13074
|
+
};
|
13075
|
+
|
13076
|
+
const useGlobalKeyboardShortcut = handler => {
|
13077
|
+
React__default.useEffect(() => {
|
13078
|
+
document.addEventListener('keydown', handler);
|
13079
|
+
return () => {
|
13080
|
+
document.removeEventListener('keydown', handler);
|
13081
|
+
};
|
13082
|
+
}, [handler]);
|
13083
|
+
};
|
13084
|
+
|
13085
|
+
const FiltersButton = ({
|
13086
|
+
length,
|
13087
|
+
table
|
13088
|
+
}) => {
|
13089
|
+
const ref = React__default.useRef(null);
|
13090
|
+
const allColumns = table.getAllLeafColumns().filter(column => !isInternalColumn(column.id));
|
13091
|
+
const {
|
13092
|
+
shouldDisableTableActions
|
13093
|
+
} = table.options.meta;
|
13094
|
+
const columnFilters = table.getState().columnFilters;
|
13095
|
+
const filteredColumns = columnFilters.reduce((columns, columnFilter) => {
|
13096
|
+
const column = allColumns.find(c => c.id === columnFilter.id);
|
13097
|
+
if (column) {
|
13098
|
+
return [...columns, column];
|
13099
|
+
}
|
13100
|
+
return columns;
|
13101
|
+
}, []);
|
13102
|
+
const handleAdd = () => {
|
13103
|
+
const firstFilterableColumn = allColumns.find(c => c.getCanFilter() && !columnFilters.find(f => f.id === c.id));
|
13104
|
+
if (firstFilterableColumn) {
|
13105
|
+
firstFilterableColumn.setFilterValue({
|
13106
|
+
comparator: undefined,
|
13107
|
+
value: undefined
|
13108
|
+
});
|
13109
|
+
}
|
13110
|
+
};
|
13111
|
+
const handleReset = () => {
|
13112
|
+
table.resetColumnFilters();
|
13113
|
+
};
|
13114
|
+
useGlobalKeyboardShortcut(event => {
|
13115
|
+
if (event.key === 'f' && (event.ctrlKey || event.metaKey) && event.shiftKey) {
|
13116
|
+
var _ref$current;
|
13117
|
+
event.preventDefault();
|
13118
|
+
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.click();
|
13119
|
+
}
|
13120
|
+
});
|
13121
|
+
return /*#__PURE__*/React__default.createElement(Button$1, {
|
13122
|
+
appearance: columnFilters.length ? 'primary' : 'default',
|
13123
|
+
className: cn({
|
13124
|
+
'!wcag-blue-100': columnFilters.length
|
13125
|
+
}),
|
13126
|
+
disabled: shouldDisableTableActions,
|
13127
|
+
popover: popoverProps => /*#__PURE__*/React__default.createElement(Popover, Object.assign({}, popoverProps), /*#__PURE__*/React__default.createElement(Popover.Content, null, /*#__PURE__*/React__default.createElement("div", {
|
13128
|
+
className: "flex w-[40rem] flex-col gap-4"
|
13129
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
13130
|
+
className: "flex w-full items-center gap-2"
|
13131
|
+
}, /*#__PURE__*/React__default.createElement("h4", {
|
13132
|
+
className: "mb-0 inline-flex"
|
13133
|
+
}, "Filter"), /*#__PURE__*/React__default.createElement("p", {
|
13134
|
+
className: "text-grey-700 mb-0 mr-auto mt-px inline-flex"
|
13135
|
+
}, "Viewing ", table.getFilteredRowModel().rows.length, " of ", length)), /*#__PURE__*/React__default.createElement("div", {
|
13136
|
+
className: "flex flex-col gap-2"
|
13137
|
+
}, filteredColumns.map((column, index) => /*#__PURE__*/React__default.createElement(ColumnFilter, {
|
13138
|
+
key: `${column.id}_${index}`,
|
13139
|
+
allColumns: allColumns,
|
13140
|
+
index: index,
|
13141
|
+
column: column,
|
13142
|
+
table: table
|
13143
|
+
}))), /*#__PURE__*/React__default.createElement(Group, {
|
13144
|
+
className: "justify-between"
|
13145
|
+
}, /*#__PURE__*/React__default.createElement(Button$1, {
|
13146
|
+
appearance: "discrete",
|
13147
|
+
onClick: handleAdd
|
13148
|
+
}, "+ Add filter"), columnFilters.length ? /*#__PURE__*/React__default.createElement(Button$1, {
|
13149
|
+
onClick: handleReset
|
13150
|
+
}, "Clear all filters") : null)))),
|
13151
|
+
ref: ref,
|
13152
|
+
tooltip: /*#__PURE__*/React__default.createElement(React__default.Fragment, null, columnFilters.length ? 'Change filters' : 'Apply filters', /*#__PURE__*/React__default.createElement(Shortcut$1, {
|
13153
|
+
className: "ml-2",
|
13154
|
+
keys: ['Ctrl', 'Shift', 'F']
|
13155
|
+
}))
|
13156
|
+
}, /*#__PURE__*/React__default.createElement(Icon, {
|
13157
|
+
name: columnFilters.length ? 'filter-solid' : 'filter'
|
13158
|
+
}), columnFilters.length ? `Filters (${columnFilters.length})` : 'Filters');
|
13159
|
+
};
|
13160
|
+
|
13161
|
+
const Search$2 = props => {
|
13162
|
+
const {
|
13163
|
+
value,
|
13164
|
+
...attributes
|
13165
|
+
} = props;
|
13166
|
+
const ref = React__default.useRef(null);
|
13167
|
+
const handleKeyDown = event => {
|
13168
|
+
if (event.key === 'Escape') {
|
13169
|
+
var _props$onSearch;
|
13170
|
+
(_props$onSearch = props.onSearch) === null || _props$onSearch === void 0 ? void 0 : _props$onSearch.call(props, '');
|
13171
|
+
}
|
13172
|
+
};
|
13173
|
+
// gets called when the "clear" button is clicked
|
13174
|
+
const handleInput = event => {
|
13175
|
+
if (props.onInput) {
|
13176
|
+
props.onInput(event);
|
13177
|
+
}
|
13178
|
+
if (!event.isDefaultPrevented() && !event.currentTarget.value) {
|
13179
|
+
var _props$onSearch2;
|
13180
|
+
(_props$onSearch2 = props.onSearch) === null || _props$onSearch2 === void 0 ? void 0 : _props$onSearch2.call(props, '');
|
13181
|
+
}
|
13182
|
+
};
|
13183
|
+
const handleBlur = event => {
|
13184
|
+
var _props$onSearch3;
|
13185
|
+
const value = event.target.value;
|
13186
|
+
(_props$onSearch3 = props.onSearch) === null || _props$onSearch3 === void 0 ? void 0 : _props$onSearch3.call(props, value);
|
13187
|
+
};
|
13188
|
+
useGlobalKeyboardShortcut(event => {
|
13189
|
+
if (event.key === 'f' && (event.ctrlKey || event.metaKey)) {
|
13190
|
+
if (document.activeElement !== ref.current) {
|
13191
|
+
var _ref$current;
|
13192
|
+
event.preventDefault();
|
13193
|
+
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
13194
|
+
}
|
13195
|
+
}
|
13196
|
+
});
|
13197
|
+
const className = cn('w-48', {
|
13198
|
+
'!wcag-blue-100': !!value
|
13199
|
+
});
|
13200
|
+
return /*#__PURE__*/React__default.createElement(SearchInput, Object.assign({}, attributes, {
|
13201
|
+
className: className,
|
13202
|
+
onBlur: handleBlur,
|
13203
|
+
onInput: handleInput,
|
13204
|
+
onKeyDown: handleKeyDown,
|
13205
|
+
ref: ref
|
13206
|
+
}));
|
13207
|
+
};
|
13208
|
+
|
13209
|
+
const ShortcutsGuideButton = ({
|
13210
|
+
table
|
13211
|
+
}) => {
|
13212
|
+
const meta = table.options.meta;
|
13213
|
+
const shortcuts = [];
|
13214
|
+
if (table.options.enableGlobalFilter) {
|
13215
|
+
shortcuts.push({
|
13216
|
+
feature: 'Search',
|
13217
|
+
keys: ['Ctrl', 'F']
|
13218
|
+
});
|
13219
|
+
}
|
13220
|
+
if (table.options.enableColumnFilters) {
|
13221
|
+
shortcuts.push({
|
13222
|
+
feature: 'Filter',
|
13223
|
+
keys: ['Ctrl', 'Shift', 'F']
|
13224
|
+
});
|
13225
|
+
}
|
13226
|
+
shortcuts.push({
|
13227
|
+
feature: 'Previous row',
|
13228
|
+
keys: ['Up']
|
13229
|
+
});
|
13230
|
+
shortcuts.push({
|
13231
|
+
feature: 'Next row',
|
13232
|
+
keys: ['Down']
|
13233
|
+
});
|
13234
|
+
if (meta.editMode.enableEditMode) {
|
13235
|
+
shortcuts.push({
|
13236
|
+
feature: 'Edit cell',
|
13237
|
+
keys: ['Enter']
|
13238
|
+
});
|
13239
|
+
shortcuts.push({
|
13240
|
+
feature: 'Previous column',
|
13241
|
+
keys: ['Left']
|
13242
|
+
});
|
13243
|
+
shortcuts.push({
|
13244
|
+
feature: 'Next column',
|
13245
|
+
keys: ['Right']
|
13246
|
+
});
|
13247
|
+
} else if (meta.onRowClick) {
|
13248
|
+
shortcuts.push({
|
13249
|
+
feature: 'Activate current row',
|
13250
|
+
keys: ['Enter']
|
13251
|
+
});
|
13252
|
+
}
|
13253
|
+
if (table.options.enableRowSelection) {
|
13254
|
+
shortcuts.push({
|
13255
|
+
feature: 'Select current row',
|
13256
|
+
keys: ['Space']
|
13257
|
+
});
|
13258
|
+
shortcuts.push({
|
13259
|
+
feature: 'Select all rows',
|
13260
|
+
keys: ['Ctrl', 'A']
|
13261
|
+
});
|
13262
|
+
}
|
13263
|
+
if (table.options.enableExpanding) {
|
13264
|
+
shortcuts.push({
|
13265
|
+
feature: 'Expand current row',
|
13266
|
+
keys: ['Ctrl', 'Right']
|
13267
|
+
});
|
13268
|
+
shortcuts.push({
|
13269
|
+
feature: 'Collapse current row',
|
13270
|
+
keys: ['Ctrl', 'Left']
|
13271
|
+
});
|
13272
|
+
}
|
13273
|
+
return /*#__PURE__*/React__default.createElement(IconButton, {
|
13274
|
+
"aria-label": "View keyboard shortcuts",
|
13275
|
+
icon: "shortcuts",
|
13276
|
+
popover: popoverProps => /*#__PURE__*/React__default.createElement(Popover, Object.assign({}, popoverProps), /*#__PURE__*/React__default.createElement(Popover.Content, {
|
13277
|
+
align: "end"
|
13278
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
13279
|
+
className: "flex flex-col gap-y-1"
|
13280
|
+
}, shortcuts.map(shortcut => /*#__PURE__*/React__default.createElement("span", {
|
13281
|
+
className: "flex items-center justify-between gap-x-8",
|
13282
|
+
key: shortcut.feature
|
13283
|
+
}, /*#__PURE__*/React__default.createElement("span", null, shortcut.feature), /*#__PURE__*/React__default.createElement(Shortcut$1, {
|
13284
|
+
keys: shortcut.keys
|
13285
|
+
})))))),
|
13286
|
+
rounded: true
|
13287
|
+
});
|
13288
|
+
};
|
13289
|
+
|
13290
|
+
const EditModeButton = /*#__PURE__*/React__default.forwardRef(function EditModeButton(props, ref) {
|
13291
|
+
const {
|
13292
|
+
table,
|
13293
|
+
tableRef
|
13294
|
+
} = props;
|
13295
|
+
const internalRef = useMergedRef(ref);
|
13296
|
+
const meta = table.options.meta;
|
13297
|
+
const {
|
13298
|
+
isEditing
|
13299
|
+
} = meta.editMode;
|
13300
|
+
const showWarning = React__default.useCallback(event => {
|
13301
|
+
if (isEditing) {
|
13302
|
+
event.returnValue = true;
|
13303
|
+
return true;
|
13304
|
+
}
|
13305
|
+
return false;
|
13306
|
+
}, [isEditing]);
|
13307
|
+
useGlobalKeyboardShortcut(event => {
|
13308
|
+
if (event.key === 'e' && (event.ctrlKey || event.metaKey)) {
|
13309
|
+
var _internalRef$current;
|
13310
|
+
event.preventDefault();
|
13311
|
+
(_internalRef$current = internalRef.current) === null || _internalRef$current === void 0 ? void 0 : _internalRef$current.click();
|
13312
|
+
}
|
13313
|
+
});
|
13314
|
+
React__default.useEffect(() => {
|
13315
|
+
window.addEventListener('beforeunload', showWarning);
|
13316
|
+
return () => window.removeEventListener('beforeunload', showWarning);
|
13317
|
+
}, [showWarning]);
|
13318
|
+
const handleClick = () => {
|
13319
|
+
var _tableRef$current;
|
13320
|
+
meta.editMode.toggleEditing();
|
13321
|
+
(_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : _tableRef$current.focus();
|
13322
|
+
};
|
13323
|
+
return /*#__PURE__*/React__default.createElement(Button$1, {
|
13324
|
+
onClick: handleClick,
|
13325
|
+
className: cn({
|
13326
|
+
'!wcag-blue-100': meta.editMode.isEditing
|
13327
|
+
}),
|
13328
|
+
ref: internalRef,
|
13329
|
+
tooltip: /*#__PURE__*/React__default.createElement(React__default.Fragment, null, "Edit", /*#__PURE__*/React__default.createElement(Shortcut$1, {
|
13330
|
+
className: "ml-2",
|
13331
|
+
keys: ['Ctrl', 'E']
|
13332
|
+
}))
|
13333
|
+
}, /*#__PURE__*/React__default.createElement(Icon, {
|
13334
|
+
name: "edit"
|
13335
|
+
}), "Edit");
|
13336
|
+
});
|
13337
|
+
|
13338
|
+
function Column$2(_) {
|
13339
|
+
return null;
|
13340
|
+
}
|
13341
|
+
Column$2.displayName = 'Table2Column';
|
13342
|
+
function Toolbar(props) {
|
13343
|
+
const className = cn('flex-grow', props.className);
|
13344
|
+
return /*#__PURE__*/React__default.createElement("div", Object.assign({}, props, {
|
13345
|
+
className: className
|
13346
|
+
}));
|
13347
|
+
}
|
13348
|
+
Toolbar.displayName = 'Table2Toolbar';
|
13349
|
+
const Table2 = /*#__PURE__*/React__default.forwardRef(function Table2(props, ref) {
|
13350
|
+
// dom
|
13351
|
+
const {
|
13352
|
+
emptyState: EmptyState,
|
13353
|
+
expandedRowRenderer,
|
13354
|
+
length = props.data.length,
|
13355
|
+
loadMore,
|
13356
|
+
onRowClick,
|
13357
|
+
_experimentalActionsForTable,
|
13358
|
+
_experimentalActionsForTableSummary
|
13359
|
+
} = props;
|
13360
|
+
const tableRef = useMergedRef(ref);
|
13361
|
+
const timeoutIdRef = React__default.useRef();
|
13362
|
+
// react-table
|
13363
|
+
const [columns, toolbar] = useSeparatedChildren$1(props.children);
|
13364
|
+
const {
|
13365
|
+
rows,
|
13366
|
+
table,
|
13367
|
+
footers
|
13368
|
+
} = useTable$1(columns, props, tableRef);
|
13369
|
+
const meta = table.options.meta;
|
13370
|
+
const {
|
13371
|
+
columnVisibility,
|
13372
|
+
columnOrder,
|
13373
|
+
globalFilter
|
13374
|
+
} = table.getState();
|
13375
|
+
// If column visibility or order changes then we turn off the edit mode so that control indexes gets computed
|
13376
|
+
// when user turns on the editing mode again. This is a temporary solution to make sure the keyboard navigation
|
13377
|
+
// still keeps working on changes in column visibility, order, or both
|
13378
|
+
React__default.useEffect(() => {
|
13379
|
+
meta.resetFocussableColumnIndexes();
|
13380
|
+
}, [columnVisibility, columnOrder]);
|
13381
|
+
React__default.useEffect(() => {
|
13382
|
+
// Whenever edit mode is turned off we reset the focussableColumnIndexes ref to an empty array so that
|
13383
|
+
// we don't have stale values, in case column visibility or ordering changes
|
13384
|
+
if (!meta.editMode.isEditing) {
|
13385
|
+
meta.resetFocussableColumnIndexes();
|
13386
|
+
}
|
13387
|
+
}, [meta.editMode.isEditing]);
|
13388
|
+
React__default.useEffect(() => {
|
13389
|
+
return () => clearTimeout(timeoutIdRef.current);
|
13390
|
+
}, []);
|
13391
|
+
// virtualiser
|
13392
|
+
const {
|
13393
|
+
virtualiser,
|
13394
|
+
virtualiserOffsets,
|
13395
|
+
setExpandedRowSizes
|
13396
|
+
} = useVirtualiser({
|
13397
|
+
rows,
|
13398
|
+
table
|
13399
|
+
}, tableRef);
|
13400
|
+
// css grid
|
13401
|
+
const gridTemplateColumns = useGridTemplate(table);
|
13402
|
+
// handlers
|
13403
|
+
const editButtonRef = React__default.useRef(null);
|
13404
|
+
// support grid like keyboard navigation between cells
|
13405
|
+
const handleKeyDown = event => {
|
13406
|
+
if (document.activeElement === tableRef.current) {
|
13407
|
+
if (event.key === 'ArrowUp') {
|
13408
|
+
event.preventDefault();
|
13409
|
+
if (event.ctrlKey || event.metaKey) {
|
13410
|
+
meta.setActiveRowIndex(0);
|
13411
|
+
virtualiser.scrollToOffset(0);
|
13412
|
+
} else {
|
13413
|
+
meta.moveToPreviousRow(rows, nextIndex => virtualiser.scrollToIndex(nextIndex - 1));
|
13414
|
+
}
|
13415
|
+
return;
|
13416
|
+
} else if (event.key === 'ArrowDown') {
|
13417
|
+
event.preventDefault();
|
13418
|
+
if (event.ctrlKey || event.metaKey) {
|
13419
|
+
meta.setActiveRowIndex(rows.length - 1);
|
13420
|
+
virtualiser.scrollToOffset(virtualiser.totalSize + 1);
|
13421
|
+
} else {
|
13422
|
+
meta.moveToNextRow(rows, nextIndex => virtualiser.scrollToIndex(nextIndex + 2));
|
13423
|
+
}
|
13424
|
+
return;
|
13425
|
+
}
|
13426
|
+
const canToggleRowExpansion = table.options.enableExpanding;
|
13427
|
+
if (event.key === 'ArrowLeft') {
|
13428
|
+
event.preventDefault();
|
13429
|
+
if (event.ctrlKey || event.metaKey) {
|
13430
|
+
if (canToggleRowExpansion) {
|
13431
|
+
var _rows$meta$activeRowI;
|
13432
|
+
(_rows$meta$activeRowI = rows[meta.activeRowIndex]) === null || _rows$meta$activeRowI === void 0 ? void 0 : _rows$meta$activeRowI.toggleExpanded(false);
|
13433
|
+
}
|
13434
|
+
}
|
13435
|
+
return;
|
13436
|
+
}
|
13437
|
+
if (event.key === 'ArrowRight') {
|
13438
|
+
event.preventDefault();
|
13439
|
+
if (event.ctrlKey || event.metaKey) {
|
13440
|
+
if (canToggleRowExpansion) {
|
13441
|
+
var _rows$meta$activeRowI2;
|
13442
|
+
(_rows$meta$activeRowI2 = rows[meta === null || meta === void 0 ? void 0 : meta.activeRowIndex]) === null || _rows$meta$activeRowI2 === void 0 ? void 0 : _rows$meta$activeRowI2.toggleExpanded(true);
|
13443
|
+
}
|
13444
|
+
}
|
13445
|
+
return;
|
13446
|
+
}
|
13447
|
+
if (event.key === 'Enter') {
|
13448
|
+
event.preventDefault();
|
13449
|
+
if (onRowClick) {
|
13450
|
+
onRowClick(rows[meta === null || meta === void 0 ? void 0 : meta.activeRowIndex].original);
|
13451
|
+
}
|
13452
|
+
return;
|
13453
|
+
}
|
13454
|
+
if (event.key === ' ') {
|
13455
|
+
event.preventDefault();
|
13456
|
+
if (table.options.enableRowSelection) {
|
13457
|
+
var _rows$meta$activeRowI3;
|
13458
|
+
(_rows$meta$activeRowI3 = rows[meta.activeRowIndex]) === null || _rows$meta$activeRowI3 === void 0 ? void 0 : _rows$meta$activeRowI3.toggleSelected();
|
13459
|
+
}
|
13460
|
+
return;
|
13461
|
+
}
|
13462
|
+
if (event.ctrlKey || event.metaKey) {
|
13463
|
+
event.preventDefault();
|
13464
|
+
if (event.key === 'a') {
|
13465
|
+
if (table.options.enableRowSelection) {
|
13466
|
+
table.toggleAllRowsSelected();
|
13467
|
+
}
|
13468
|
+
}
|
13469
|
+
return;
|
13470
|
+
}
|
13471
|
+
}
|
13472
|
+
};
|
13473
|
+
let handleBlur;
|
13474
|
+
if (meta.editMode.isEditing) {
|
13475
|
+
handleBlur = event => {
|
13476
|
+
var _elementGainingFocus, _elementGainingFocus$, _event$currentTarget;
|
13477
|
+
let elementGainingFocus = event.relatedTarget;
|
13478
|
+
if (elementGainingFocus === undefined) {
|
13479
|
+
return;
|
13480
|
+
}
|
13481
|
+
// we might be focusing on a select or a popover that was triggered from inside the table
|
13482
|
+
// so see if the element gaining focus is inside a portal and look up its controller
|
13483
|
+
const portalId = (_elementGainingFocus = elementGainingFocus) === null || _elementGainingFocus === void 0 ? void 0 : (_elementGainingFocus$ = _elementGainingFocus.closest('[data-radix-popper-content-wrapper] > :first-child')) === null || _elementGainingFocus$ === void 0 ? void 0 : _elementGainingFocus$.id;
|
13484
|
+
if (portalId) {
|
13485
|
+
var _event$currentTarget$;
|
13486
|
+
elementGainingFocus = (_event$currentTarget$ = event.currentTarget.querySelector(`[aria-controls="${portalId}"]`)) !== null && _event$currentTarget$ !== void 0 ? _event$currentTarget$ : event.relatedTarget;
|
13487
|
+
}
|
13488
|
+
if (!((_event$currentTarget = event.currentTarget) !== null && _event$currentTarget !== void 0 && _event$currentTarget.contains(elementGainingFocus)) && elementGainingFocus !== editButtonRef.current) {
|
13489
|
+
// When we call manually blur on control component while navigating to the next cell, then when this
|
13490
|
+
// handler is run, the related target is not the next control component and active element is null,
|
13491
|
+
// that's why we explictly need to check what's the next focussed element in order to figure out whether
|
13492
|
+
// we should disabled the sorting or not.
|
13493
|
+
timeoutIdRef.current = setTimeout(() => {
|
13494
|
+
const parentRow = event.target.closest('[role="row"]');
|
13495
|
+
const isNewFocussedElementInSameRow = parentRow === null || parentRow === void 0 ? void 0 : parentRow.contains(document.activeElement);
|
13496
|
+
// When we manually call blur on control component and focus another component then
|
13497
|
+
// we have to make sure we
|
13498
|
+
if (meta.shouldPauseSortingAndFiltering && !isNewFocussedElementInSameRow) {
|
13499
|
+
// if client side - unpause sorting
|
13500
|
+
meta.setShouldPauseSortingAndFiltering(false);
|
13501
|
+
}
|
13502
|
+
});
|
13503
|
+
}
|
13504
|
+
};
|
13505
|
+
}
|
13506
|
+
// extract - infinite loading
|
13507
|
+
// TODO: this can probably be extracted into a hook
|
13508
|
+
// we only show the pinned shadow on display columns when scrolling is active
|
13509
|
+
const [scrolled, setScrolled] = React__default.useState(false);
|
13510
|
+
// extract - infinite loading
|
13511
|
+
const loadingRef = React__default.useRef(false);
|
13512
|
+
const handleScroll = function (event) {
|
13513
|
+
try {
|
13514
|
+
const _temp5 = function () {
|
13515
|
+
if (event.currentTarget.scrollLeft > 0 && !scrolled) {
|
13516
|
+
setScrolled(true);
|
13517
|
+
} else {
|
13518
|
+
const _temp4 = function () {
|
13519
|
+
if (event.currentTarget.scrollLeft === 0 && scrolled) {
|
13520
|
+
setScrolled(false);
|
13521
|
+
} else {
|
13522
|
+
const _temp3 = function () {
|
13523
|
+
if (typeof loadMore === 'function') {
|
13524
|
+
const _temp2 = function () {
|
13525
|
+
if (event.currentTarget.scrollHeight - event.currentTarget.scrollTop - event.currentTarget.clientHeight < 600 && !loadingRef.current) {
|
13526
|
+
const _temp = _finallyRethrows(function () {
|
13527
|
+
const isAllRowsSelected = table.getIsAllRowsSelected();
|
13528
|
+
loadingRef.current = true;
|
13529
|
+
return Promise.resolve(loadMore()).then(function () {
|
13530
|
+
if (isAllRowsSelected) {
|
13531
|
+
table.toggleAllRowsSelected(true);
|
13532
|
+
}
|
13533
|
+
});
|
13534
|
+
}, function (_wasThrown, _result) {
|
13535
|
+
loadingRef.current = false;
|
13536
|
+
if (_wasThrown) throw _result;
|
13537
|
+
return _result;
|
13538
|
+
});
|
13539
|
+
if (_temp && _temp.then) return _temp.then(function () {});
|
13540
|
+
}
|
13541
|
+
}();
|
13542
|
+
if (_temp2 && _temp2.then) return _temp2.then(function () {});
|
13543
|
+
}
|
13544
|
+
}();
|
13545
|
+
if (_temp3 && _temp3.then) return _temp3.then(function () {});
|
13546
|
+
}
|
13547
|
+
}();
|
13548
|
+
if (_temp4 && _temp4.then) return _temp4.then(function () {});
|
13549
|
+
}
|
13550
|
+
}();
|
13551
|
+
return Promise.resolve(_temp5 && _temp5.then ? _temp5.then(function () {}) : void 0);
|
13552
|
+
} catch (e) {
|
13553
|
+
return Promise.reject(e);
|
13554
|
+
}
|
13555
|
+
};
|
13556
|
+
let handleMouseLeave;
|
13557
|
+
if (meta.hoveredRowIndex !== undefined) {
|
13558
|
+
// sometimes the row's onMouseLeave doesn't trigger, this adds some extra redundancy
|
13559
|
+
handleMouseLeave = () => meta.setHoveredRowIndex(undefined);
|
13560
|
+
}
|
13561
|
+
const className = cn('bg-white border border-grey-300 focus:yt-focus focus:border-blue-500 grid overflow-auto relative rounded group', props.className);
|
13562
|
+
const enableSettingsButton = table.options.enablePinning || table.options.enableHiding || meta.enableColumnReordering;
|
13563
|
+
const hasInternalToolbar = enableSettingsButton || meta.editMode.enableEditMode || table.options.enableColumnFilters || meta.enableRowDensity || table.options.enableGlobalFilter;
|
13564
|
+
const hasToolbar = !!toolbar || hasInternalToolbar;
|
13565
|
+
const hasFooters = React__default.useMemo(() => {
|
13566
|
+
const summaryIds = Object.keys(footers);
|
13567
|
+
const visibleIds = Object.keys(columnVisibility).filter(c => !columnVisibility[c]);
|
13568
|
+
return summaryIds.length && summaryIds.some(v => !visibleIds.includes(v));
|
13569
|
+
}, [footers, columnVisibility]);
|
13570
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
13571
|
+
className: "flex h-full w-full flex-col gap-4"
|
13572
|
+
}, hasToolbar ? /*#__PURE__*/React__default.createElement("div", {
|
13573
|
+
className: "flex flex-wrap gap-2"
|
13574
|
+
}, toolbar, hasInternalToolbar ? /*#__PURE__*/React__default.createElement(Group, {
|
13575
|
+
className: "ml-auto flex-shrink-0 print:hidden"
|
13576
|
+
}, meta.editMode.enableEditMode ? /*#__PURE__*/React__default.createElement(EditModeButton, {
|
13577
|
+
ref: editButtonRef,
|
13578
|
+
table: table,
|
13579
|
+
tableRef: tableRef
|
13580
|
+
}) : null, table.options.enableColumnFilters ? /*#__PURE__*/React__default.createElement(FiltersButton, {
|
13581
|
+
length: length,
|
13582
|
+
table: table
|
13583
|
+
}) : null, meta.enableRowDensity ? /*#__PURE__*/React__default.createElement(RowDensityButton, {
|
13584
|
+
table: table
|
13585
|
+
}) : null, enableSettingsButton ? /*#__PURE__*/React__default.createElement(ColumnSettingsButton, {
|
13586
|
+
table: table
|
13587
|
+
}) : null, table.options.enableGlobalFilter ? /*#__PURE__*/React__default.createElement(Search$2, {
|
13588
|
+
disabled: meta.shouldDisableTableActions,
|
13589
|
+
onSearch: table.setGlobalFilter,
|
13590
|
+
placeholder: "Search...",
|
13591
|
+
value: globalFilter
|
13592
|
+
}) : null) : null, /*#__PURE__*/React__default.createElement(ShortcutsGuideButton, {
|
13593
|
+
table: table
|
13594
|
+
})) : null, /*#__PURE__*/React__default.createElement("div", {
|
13595
|
+
className: className,
|
13596
|
+
onBlur: handleBlur,
|
13597
|
+
onKeyDown: handleKeyDown,
|
13598
|
+
onMouseLeave: handleMouseLeave,
|
13599
|
+
onScroll: handleScroll,
|
13600
|
+
ref: tableRef,
|
13601
|
+
role: "table",
|
13602
|
+
style: {
|
13603
|
+
gridTemplateColumns,
|
13604
|
+
gridTemplateRows: rows.length ? undefined : '40px',
|
13605
|
+
// create a new stacking context so our internal z-indexes don't effect external components
|
13606
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
|
13607
|
+
opacity: 0.999
|
13608
|
+
},
|
13609
|
+
tabIndex: 0
|
13610
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
13611
|
+
className: "contents",
|
13612
|
+
role: "rowgroup"
|
13613
|
+
}, table.getHeaderGroups().map(headerGroup => /*#__PURE__*/React__default.createElement("div", {
|
13614
|
+
className: "contents",
|
13615
|
+
key: headerGroup.id,
|
13616
|
+
role: "row"
|
13617
|
+
}, headerGroup.headers.map((header, columnIndex) => /*#__PURE__*/React__default.createElement(Header$1, {
|
13618
|
+
key: header.id,
|
13619
|
+
header: header,
|
13620
|
+
index: columnIndex,
|
13621
|
+
isLastColumn: columnIndex === headerGroup.headers.length - 1,
|
13622
|
+
scrolled: scrolled,
|
13623
|
+
table: table,
|
13624
|
+
tableRef: tableRef
|
13625
|
+
}))))), rows.length ? /*#__PURE__*/React__default.createElement("div", {
|
13626
|
+
className: "contents",
|
13627
|
+
role: "rowgroup"
|
13628
|
+
}, virtualiserOffsets.top ? /*#__PURE__*/React__default.createElement("div", {
|
13629
|
+
style: {
|
13630
|
+
height: virtualiserOffsets.top
|
13631
|
+
},
|
13632
|
+
className: "col-span-full"
|
13633
|
+
}) : null, virtualiser.virtualItems.map(virtualRow => {
|
13634
|
+
const row = rows[virtualRow.index];
|
13635
|
+
return /*#__PURE__*/React__default.createElement(React__default.Fragment, {
|
13636
|
+
key: row.id
|
13637
|
+
}, /*#__PURE__*/React__default.createElement(Row$1, {
|
13638
|
+
className: "group/row contents",
|
13639
|
+
row: row,
|
13640
|
+
rowIndex: virtualRow.index,
|
13641
|
+
table: table
|
13642
|
+
}, row.getVisibleCells().map((cell, columnIndex) => /*#__PURE__*/React__default.createElement(Cell, {
|
13643
|
+
cell: cell,
|
13644
|
+
key: `${cell.id}_${cell.getValue()}`,
|
13645
|
+
index: columnIndex,
|
13646
|
+
isLastRow: virtualRow.index === rows.length - 1,
|
13647
|
+
rows: rows,
|
13648
|
+
rowIndex: virtualRow.index,
|
13649
|
+
scrolled: scrolled,
|
13650
|
+
scrollToIndex: virtualiser.scrollToIndex,
|
13651
|
+
scrollToOffset: virtualiser.scrollToOffset,
|
13652
|
+
table: table,
|
13653
|
+
tableRef: tableRef
|
13654
|
+
}))), row.getIsExpanded() && expandedRowRenderer ? /*#__PURE__*/React__default.createElement(ExpandedRow, {
|
13655
|
+
index: virtualRow.index,
|
13656
|
+
setSize: setExpandedRowSizes
|
13657
|
+
}, expandedRowRenderer(row.original)) : null);
|
13658
|
+
}), virtualiserOffsets.bottom ? /*#__PURE__*/React__default.createElement("div", {
|
13659
|
+
style: {
|
13660
|
+
height: virtualiserOffsets.bottom
|
13661
|
+
},
|
13662
|
+
className: "col-span-full"
|
13663
|
+
}) : null) : /*#__PURE__*/React__default.createElement("div", {
|
13664
|
+
className: "col-span-full min-h-[theme(spacing.8)]"
|
13665
|
+
}, EmptyState ? /*#__PURE__*/React__default.createElement(EmptyState, null) : null), hasFooters ? /*#__PURE__*/React__default.createElement("div", {
|
13666
|
+
role: "rowgroup",
|
13667
|
+
className: "contents"
|
13668
|
+
}, table.getFooterGroups().map(footerGroup => /*#__PURE__*/React__default.createElement("div", {
|
13669
|
+
key: footerGroup.id,
|
13670
|
+
role: "row",
|
13671
|
+
className: "contents"
|
13672
|
+
}, footerGroup.headers.map((footer, cellIndex) => /*#__PURE__*/React__default.createElement(Footer$2, {
|
13673
|
+
key: footer.id,
|
13674
|
+
footer: footer,
|
13675
|
+
index: cellIndex,
|
13676
|
+
scrolled: scrolled,
|
13677
|
+
table: table
|
13678
|
+
}, footers[footer.id] ? footers[footer.id](rows.map(row => row.original[footer.id])) : null))))) : null), !!_experimentalActionsForTable && table.options.enableRowSelection && (table.getIsSomeRowsSelected() || table.getIsAllRowsSelected()) ? /*#__PURE__*/React__default.createElement(BatchActionsMenu, {
|
13679
|
+
className: "fixed-center-x bottom-0 z-50 mb-4 print:hidden",
|
13680
|
+
actionsForTable: _experimentalActionsForTable,
|
13681
|
+
summary: _experimentalActionsForTableSummary,
|
13682
|
+
table: table
|
13683
|
+
}) : null);
|
13684
|
+
});
|
13685
|
+
Table2.Column = Column$2;
|
13686
|
+
Table2.Toolbar = Toolbar;
|
13687
|
+
|
13688
|
+
const Tabs = /*#__PURE__*/React.forwardRef(function Tabs(props, ref) {
|
13689
|
+
const {
|
13690
|
+
id,
|
13691
|
+
defaultId,
|
13692
|
+
children,
|
13693
|
+
onChange,
|
13694
|
+
orientation = 'horizontal',
|
13695
|
+
...otherProps
|
13696
|
+
} = props;
|
13697
|
+
const className = cn('yt-tabs', `yt-tabs--${orientation}`, {
|
13698
|
+
'flex w-full': orientation === 'vertical'
|
13699
|
+
}, props.className);
|
13700
|
+
return /*#__PURE__*/React.createElement(TabsPrimitive.Root, Object.assign({}, otherProps, {
|
13701
|
+
className: className,
|
13702
|
+
"data-taco": "tabs",
|
13703
|
+
defaultValue: defaultId,
|
13704
|
+
dir: "ltr",
|
13705
|
+
onValueChange: onChange,
|
13706
|
+
orientation: orientation,
|
13707
|
+
ref: ref,
|
13708
|
+
value: id
|
13709
|
+
}), children);
|
13710
|
+
});
|
13711
|
+
const TabList = /*#__PURE__*/React.forwardRef(function Tab(props, ref) {
|
13712
|
+
const className = cn('yt-tab__list border-b border-grey-300 flex flex-row m-0 mb-4', props.className);
|
13713
|
+
return /*#__PURE__*/React.createElement(TabsPrimitive.List, Object.assign({}, props, {
|
13714
|
+
className: className,
|
13715
|
+
ref: ref
|
13716
|
+
}));
|
13717
|
+
});
|
13718
|
+
const TabTrigger = /*#__PURE__*/React.forwardRef(function Tab(props, ref) {
|
13719
|
+
const {
|
13720
|
+
id,
|
13721
|
+
disabled,
|
13722
|
+
...otherProps
|
13723
|
+
} = props;
|
13724
|
+
const className = cn('yt-tab bg-transparent border-b-2 border-transparent text-grey-700 m-0 py-2 px-4', disabled ? 'cursor-not-allowed !text-grey-500' : 'cursor-pointer rounded-t hover:border-grey-300 aria-selected:border-blue-500 aria-selected:text-black aria-selected:hover:border-blue-300 hover:text-black active:yt-focus active:border-blue-500 focus:yt-focus focus:border-blue-500', props.className);
|
13725
|
+
return /*#__PURE__*/React.createElement(TabsPrimitive.Trigger, Object.assign({}, otherProps, {
|
13726
|
+
className: className,
|
13727
|
+
disabled: disabled,
|
13728
|
+
ref: ref,
|
13729
|
+
style: {
|
13730
|
+
transition: 'border 0.2s ease-in'
|
13731
|
+
},
|
13732
|
+
value: id
|
13733
|
+
}));
|
13734
|
+
});
|
13735
|
+
const TabContent = /*#__PURE__*/React.forwardRef(function Tab(props, ref) {
|
13736
|
+
const {
|
13737
|
+
id,
|
13738
|
+
...otherProps
|
13739
|
+
} = props;
|
13740
|
+
const className = cn('yt-tab__panel outline-none', props.className);
|
13741
|
+
return /*#__PURE__*/React.createElement(TabsPrimitive.Content, Object.assign({}, otherProps, {
|
13742
|
+
className: className,
|
13743
|
+
ref: ref,
|
13744
|
+
value: id
|
13745
|
+
}));
|
13746
|
+
});
|
13747
|
+
Tabs.List = TabList;
|
13748
|
+
Tabs.Trigger = TabTrigger;
|
13749
|
+
Tabs.Content = TabContent;
|
13750
|
+
|
13751
|
+
const Textarea = /*#__PURE__*/React.forwardRef(function Textarea(props, ref) {
|
13752
|
+
const {
|
13753
|
+
defaultValue: _,
|
13754
|
+
highlighted,
|
13755
|
+
invalid,
|
13756
|
+
onKeyDown,
|
13757
|
+
...otherProps
|
13758
|
+
} = props;
|
13759
|
+
const classNames = cn(getInputClasses(props), 'py-1 min-h-[75px] disabled:resize-none', props.className);
|
13760
|
+
// home and end keys only navigate to the start/end of textarea value if the textarea container does not scroll
|
13761
|
+
// if it has scroll height then the browser reverts to native scrolling behaviour only
|
13762
|
+
// so we manually override it to ensure _our_ desired behaviour remains intact
|
13763
|
+
const handleKeyDown = event => {
|
13764
|
+
if (event.key === 'Home' || event.key === 'End') {
|
13765
|
+
event.preventDefault();
|
13766
|
+
const position = event.key === 'End' ? event.currentTarget.value.length : 0;
|
13767
|
+
event.currentTarget.setSelectionRange(position, position);
|
13768
|
+
event.currentTarget.scrollTop = event.key === 'End' ? event.currentTarget.scrollHeight : 0;
|
13769
|
+
}
|
13770
|
+
if (onKeyDown) {
|
13771
|
+
onKeyDown(event);
|
13772
|
+
}
|
13773
|
+
};
|
13774
|
+
return /*#__PURE__*/React.createElement("textarea", Object.assign({}, otherProps, {
|
13775
|
+
className: classNames,
|
13776
|
+
"data-taco": "textarea",
|
13777
|
+
onKeyDown: handleKeyDown,
|
13778
|
+
ref: ref
|
13779
|
+
}));
|
13780
|
+
});
|
13781
|
+
|
10437
13782
|
const Tooltip$1 = ({
|
10438
13783
|
continuous,
|
10439
13784
|
index,
|
@@ -10615,10 +13960,12 @@ exports.RadioGroup = RadioGroup;
|
|
10615
13960
|
exports.SearchInput = SearchInput;
|
10616
13961
|
exports.Select = Select;
|
10617
13962
|
exports.Select2 = Select2;
|
13963
|
+
exports.Shortcut = Shortcut$1;
|
10618
13964
|
exports.Spinner = Spinner;
|
10619
13965
|
exports.Switch = Switch;
|
10620
13966
|
exports.TAG_COLORS = TAG_COLORS;
|
10621
13967
|
exports.Table = Table;
|
13968
|
+
exports.Table2 = Table2;
|
10622
13969
|
exports.Tabs = Tabs;
|
10623
13970
|
exports.Tag = Tag$1;
|
10624
13971
|
exports.Textarea = Textarea;
|
@@ -10640,6 +13987,7 @@ exports.getParentRowIndexPath = getParentRowIndexPath;
|
|
10640
13987
|
exports.getRadioGroupItemValueAsString = getRadioGroupItemValueAsString;
|
10641
13988
|
exports.icons = icons;
|
10642
13989
|
exports.insertChildTableRow = insertChildTableRow;
|
13990
|
+
exports.isWeakEqual = isWeakEqual;
|
10643
13991
|
exports.mergeRefs = mergeRefs;
|
10644
13992
|
exports.parseFromCustomString = parseFromCustomString;
|
10645
13993
|
exports.parseFromISOString = parseFromISOString;
|