@economic/taco 2.30.2 → 2.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. package/dist/components/Table3/Table3.d.ts +18 -2
  2. package/dist/components/Table3/types.d.ts +11 -2
  3. package/dist/esm/packages/taco/src/components/Combobox/Combobox.js +1 -1
  4. package/dist/esm/packages/taco/src/components/Combobox/Combobox.js.map +1 -1
  5. package/dist/esm/packages/taco/src/components/Datepicker/Datepicker.js +2 -2
  6. package/dist/esm/packages/taco/src/components/Datepicker/Datepicker.js.map +1 -1
  7. package/dist/esm/packages/taco/src/components/Select/Select.js +2 -1
  8. package/dist/esm/packages/taco/src/components/Select/Select.js.map +1 -1
  9. package/dist/esm/packages/taco/src/components/Select/useSelect.js +19 -1
  10. package/dist/esm/packages/taco/src/components/Select/useSelect.js.map +1 -1
  11. package/dist/esm/packages/taco/src/components/Select2/components/Trigger.js +33 -12
  12. package/dist/esm/packages/taco/src/components/Select2/components/Trigger.js.map +1 -1
  13. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js +24 -3
  14. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js.map +1 -1
  15. package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
  16. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +2 -1
  17. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
  18. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +9 -0
  19. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
  20. package/dist/primitives/Table/types.d.ts +1 -1
  21. package/dist/primitives/Table/useTableManager/useTableManager.d.ts +1 -1
  22. package/dist/taco.cjs.development.js +92 -21
  23. package/dist/taco.cjs.development.js.map +1 -1
  24. package/dist/taco.cjs.production.min.js +1 -1
  25. package/dist/taco.cjs.production.min.js.map +1 -1
  26. package/package.json +2 -2
@@ -5992,7 +5992,7 @@ const Combobox = /*#__PURE__*/React.forwardRef(function Combobox(props, ref) {
5992
5992
  ref: ref
5993
5993
  }), /*#__PURE__*/React.createElement(Input, Object.assign({}, input, {
5994
5994
  autoComplete: "off",
5995
- button: props.inline ? ( /*#__PURE__*/React.createElement(IconButton
5995
+ button: props.readOnly ? undefined : props.inline ? ( /*#__PURE__*/React.createElement(IconButton
5996
5996
  // In case of inline combobox, this icon button acts only as visual chevron representation,
5997
5997
  // so should be taken out of screen reader scope.
5998
5998
  , {
@@ -6316,7 +6316,7 @@ const Datepicker = /*#__PURE__*/React.forwardRef(function Datepicker(props, ref)
6316
6316
  "data-taco": "datepicker",
6317
6317
  style: style
6318
6318
  }, /*#__PURE__*/React.createElement(Input, Object.assign({}, input, {
6319
- button: /*#__PURE__*/React.createElement(IconButton, {
6319
+ button: input.readOnly ? undefined : ( /*#__PURE__*/React.createElement(IconButton, {
6320
6320
  "aria-label": texts.datepicker.expand,
6321
6321
  disabled: input.disabled || input.readOnly,
6322
6322
  icon: "calendar",
@@ -6354,7 +6354,7 @@ const Datepicker = /*#__PURE__*/React.forwardRef(function Datepicker(props, ref)
6354
6354
  }
6355
6355
  }, texts.datepicker.clear))))))))),
6356
6356
  tooltip: texts.datepicker.calendar
6357
- })
6357
+ }))
6358
6358
  })));
6359
6359
  });
6360
6360
  Datepicker.displayName = 'Datepicker';
@@ -8984,12 +8984,30 @@ const useSelect = ({
8984
8984
  onChange(event);
8985
8985
  }
8986
8986
  };
8987
+ const handleButtonClick = event => {
8988
+ if (readOnly) {
8989
+ event.preventDefault();
8990
+ }
8991
+ };
8992
+ // select the value text if the select is readonly
8993
+ const handleButtonFocus = event => {
8994
+ if (readOnly) {
8995
+ const value = event.currentTarget.querySelector(':first-child');
8996
+ if (value) {
8997
+ var _window$getSelection, _window$getSelection$;
8998
+ (_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : (_window$getSelection$ = _window$getSelection.selectAllChildren) === null || _window$getSelection$ === void 0 ? void 0 : _window$getSelection$.call(_window$getSelection, value);
8999
+ }
9000
+ }
9001
+ };
8987
9002
  const button = {
8988
9003
  'aria-haspopup': 'listbox',
8989
9004
  'aria-label': ariaLabel ? `${ariaLabel} ${text}` : undefined,
8990
9005
  'aria-labelledby': ariaLabelledBy ? `${ariaLabelledBy} ${buttonId}` : undefined,
8991
- disabled: disabled || readOnly,
9006
+ 'aria-readonly': readOnly ? 'true' : undefined,
9007
+ disabled: disabled,
8992
9008
  id: buttonId,
9009
+ onClick: handleButtonClick,
9010
+ onFocus: handleButtonFocus,
8993
9011
  onKeyDown: !disabled && !readOnly ? handleButtonKeyDown : undefined,
8994
9012
  tabIndex,
8995
9013
  type: 'button'
@@ -9055,7 +9073,8 @@ const BaseSelect = /*#__PURE__*/React.forwardRef(function BaseSelect(props, ref)
9055
9073
  'yt-select--readonly': props.readOnly
9056
9074
  }, externalClassName);
9057
9075
  const inputClassname = cn(getInputClasses(props), 'h-8 text-left !pr-0', {
9058
- 'border-blue-500': popover.open
9076
+ 'border-blue-500': popover.open,
9077
+ 'select-text': otherProps.readOnly
9059
9078
  });
9060
9079
  React.useEffect(() => {
9061
9080
  if (autoFocus && internalRef.current) {
@@ -10041,6 +10060,13 @@ function mapTableChildrenToColumns(props, settings, options, internalColumns) {
10041
10060
  function configureReactTableOptions(options, props) {
10042
10061
  var _options$enableFilter, _options$enableColumn, _options$enableRowExp, _options$enableColumn2, _options$enableColumn3, _options$enableSortin;
10043
10062
  const enableRowSelection = options.enableRowSelection || options.enableRowSelectionSingle;
10063
+ const getRowIdentityColumnId = () => {
10064
+ if (!props.rowIdentityColumnId) {
10065
+ return undefined;
10066
+ }
10067
+ const rowIdentityColumnIds = [props.rowIdentityColumnId].flat();
10068
+ return originalRow => rowIdentityColumnIds.map(identityColumnId => String(originalRow[identityColumnId])).join('_');
10069
+ };
10044
10070
  const tableOptions = {
10045
10071
  defaultColumn: {
10046
10072
  enableColumnFilter: options.enableFiltering || true,
@@ -10065,6 +10091,8 @@ function configureReactTableOptions(options, props) {
10065
10091
  // models for default features
10066
10092
  getExpandedRowModel: reactTable.getExpandedRowModel(),
10067
10093
  getGroupedRowModel: reactTable.getGroupedRowModel(),
10094
+ // Use row indentity column values as id for each row
10095
+ getRowId: getRowIdentityColumnId(),
10068
10096
  groupedColumnMode: false
10069
10097
  };
10070
10098
  if (tableOptions.enableColumnResizing) {
@@ -11240,6 +11268,7 @@ function useTableManager(props, meta, internalColumns) {
11240
11268
  // ensure data is always valid
11241
11269
  const data = (_props$data = props.data) !== null && _props$data !== void 0 ? _props$data : [];
11242
11270
  const length = (_props$length = props.length) !== null && _props$length !== void 0 ? _props$length : data.length;
11271
+ const rowIdentityColumnId = props.rowIdentityColumnId !== undefined ? [props.rowIdentityColumnId].flat() : [];
11243
11272
  // create a react-table instance
11244
11273
  const instance = reactTable.useReactTable({
11245
11274
  data,
@@ -11267,7 +11296,7 @@ function useTableManager(props, meta, internalColumns) {
11267
11296
  rowDrag,
11268
11297
  rowDrop: rowDrop,
11269
11298
  rowExpansion: rowExpansion,
11270
- rowIdentityColumnId: props.rowIdentityColumnId,
11299
+ rowIdentityColumnId,
11271
11300
  rowGoto,
11272
11301
  rowGroups: rowGroups,
11273
11302
  rowHeight,
@@ -14551,13 +14580,19 @@ const Title$5 = /*#__PURE__*/React__default.forwardRef(function Select2Title(pro
14551
14580
 
14552
14581
  const Placeholder = ({
14553
14582
  disabled,
14583
+ readOnly,
14554
14584
  ...props
14555
- }) => ( /*#__PURE__*/React__default.createElement("div", Object.assign({}, props, {
14556
- className: cn({
14557
- 'text-grey-700': disabled,
14558
- 'text-grey-500': !disabled
14559
- })
14560
- })));
14585
+ }) => {
14586
+ if (readOnly) {
14587
+ return null;
14588
+ }
14589
+ return /*#__PURE__*/React__default.createElement("div", Object.assign({}, props, {
14590
+ className: cn({
14591
+ 'text-grey-700': disabled,
14592
+ 'text-grey-500': !disabled
14593
+ })
14594
+ }));
14595
+ };
14561
14596
  const Trigger$7 = /*#__PURE__*/React__default.forwardRef(function Select2Trigger(props, ref) {
14562
14597
  const {
14563
14598
  multiple,
@@ -14591,13 +14626,14 @@ const Button$3 = /*#__PURE__*/React__default.forwardRef(function Select2TriggerB
14591
14626
  open,
14592
14627
  readOnly
14593
14628
  } = useSelect2Context();
14594
- const className = cn('cursor-pointer px-1.5 h-fit', getInputClasses({
14629
+ const className = cn('px-1.5 h-fit', getInputClasses({
14595
14630
  ...props,
14596
14631
  disabled,
14597
14632
  highlighted,
14598
14633
  invalid,
14599
14634
  readOnly
14600
14635
  }).replace('w-full', '').replace('px-2', ''), getFontSize(fontSize), {
14636
+ 'select-text': readOnly,
14601
14637
  'w-full': !((_props$className = props.className) !== null && _props$className !== void 0 && _props$className.includes('w-'))
14602
14638
  }, props.className);
14603
14639
  const handleClick = event => {
@@ -14609,17 +14645,28 @@ const Button$3 = /*#__PURE__*/React__default.forwardRef(function Select2TriggerB
14609
14645
  onClick(event);
14610
14646
  }
14611
14647
  };
14648
+ // select the value text if the select is readonly
14649
+ const handleFocus = event => {
14650
+ if (readOnly) {
14651
+ const value = event.currentTarget.querySelector(':first-child');
14652
+ if (value) {
14653
+ var _window$getSelection, _window$getSelection$;
14654
+ (_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : (_window$getSelection$ = _window$getSelection.selectAllChildren) === null || _window$getSelection$ === void 0 ? void 0 : _window$getSelection$.call(_window$getSelection, value);
14655
+ }
14656
+ }
14657
+ };
14612
14658
  return /*#__PURE__*/React__default.createElement("button", Object.assign({}, otherProps, {
14613
14659
  "aria-invalid": invalid ? true : undefined,
14614
14660
  "aria-readonly": readOnly ? true : undefined,
14615
14661
  className: className,
14616
14662
  disabled: disabled,
14617
14663
  onClick: handleClick,
14664
+ onFocus: handleFocus,
14618
14665
  ref: ref,
14619
14666
  role: "combobox",
14620
- tabIndex: disabled || readOnly ? -1 : tabIndex,
14667
+ tabIndex: disabled ? -1 : tabIndex,
14621
14668
  type: "button"
14622
- }), children, /*#__PURE__*/React__default.createElement(Icon, {
14669
+ }), children, readOnly ? null : /*#__PURE__*/React__default.createElement(Icon, {
14623
14670
  name: open ? 'chevron-up' : 'chevron-down',
14624
14671
  className: "pointer-events-none -mr-1 ml-auto"
14625
14672
  }));
@@ -14642,7 +14689,8 @@ const Single = /*#__PURE__*/React__default.forwardRef(function Select2TriggerSin
14642
14689
  let output;
14643
14690
  if (placeholder && currentValue === undefined) {
14644
14691
  output = /*#__PURE__*/React__default.createElement(Placeholder, {
14645
- disabled: disabled
14692
+ disabled: disabled,
14693
+ readOnly: readOnly
14646
14694
  }, placeholder);
14647
14695
  } else if (currentValue) {
14648
14696
  if (tags && emptyValue !== value) {
@@ -14695,7 +14743,8 @@ const Multiple = /*#__PURE__*/React__default.forwardRef(function Select2TriggerM
14695
14743
  }, /*#__PURE__*/React__default.createElement("div", {
14696
14744
  className: "flex flex-wrap gap-1"
14697
14745
  }, valuesAsChildren.length === 0 ? ( /*#__PURE__*/React__default.createElement(Placeholder, {
14698
- disabled: disabled
14746
+ disabled: disabled,
14747
+ readOnly: readOnly
14699
14748
  }, placeholder)) : valuesAsChildren.map(child => ( /*#__PURE__*/React__default.createElement(Tag$1, {
14700
14749
  key: String(child.props.value),
14701
14750
  className: "truncate",
@@ -14755,7 +14804,8 @@ const MultipleValue = ({
14755
14804
  className: "flex gap-1 truncate",
14756
14805
  ref: el => setContentRef(el)
14757
14806
  }, valuesAsChildren.length === 0 ? ( /*#__PURE__*/React__default.createElement(Placeholder, {
14758
- disabled: disabled
14807
+ disabled: disabled,
14808
+ readOnly: readOnly
14759
14809
  }, placeholder)) : valuesAsChildren.map((child, index) => {
14760
14810
  const tag = /*#__PURE__*/React__default.createElement(Tag$1, {
14761
14811
  key: String(child.props.value),
@@ -18804,6 +18854,22 @@ function Alert$1(props) {
18804
18854
  const tableMeta = table.options.meta;
18805
18855
  const [showFilterResetDialog, setShowFilterResetDialog] = React__default.useState(false);
18806
18856
  const pendingChangesWithErrors = tableMeta.editing.getErrors();
18857
+ const deletePendingChange = tableMeta.editing.resetChanges;
18858
+ const allRows = table.getPreFilteredRowModel().rows;
18859
+ // This effect deletes error in the alert if the row that has the error is deleted.
18860
+ React__default.useEffect(() => {
18861
+ pendingChangesWithErrors.forEach(errorRow => {
18862
+ const errorRowId = errorRow.rowId;
18863
+ try {
18864
+ // getRow throws error if it fails to find the row
18865
+ if (!table.getRow(errorRowId)) {
18866
+ deletePendingChange(errorRowId);
18867
+ }
18868
+ } catch {
18869
+ deletePendingChange(errorRowId);
18870
+ }
18871
+ });
18872
+ }, [allRows.length]);
18807
18873
  const activeRow = React__default.useMemo(() => tableMeta.rowActive.rowActiveIndex ? table.getRowModel().rows[tableMeta.rowActive.rowActiveIndex] : undefined, [tableMeta.rowActive.rowActiveIndex]);
18808
18874
  // mark errors being rendered as seen
18809
18875
  React__default.useEffect(() => {
@@ -18832,18 +18898,23 @@ function Alert$1(props) {
18832
18898
  const title = (pendingChangesWithErrors.length === 1 ? validationTexts.alert.titleOne : validationTexts.alert.titlePlural).replace('[COUNT]', String(pendingChangesWithErrors.length));
18833
18899
  // generate links to each invalid row, to go into the error message
18834
18900
  const links = [];
18835
- const rowIdentityColumn = tableMeta.rowIdentityColumnId ? table.getColumn(tableMeta.rowIdentityColumnId) : undefined;
18901
+ const rowIdentityColumn = tableMeta.rowIdentityColumnId ?
18902
+ // Since rowIdentityColumnId can have multiple ids, we use the first id to refer to the row in Alert
18903
+ table.getColumn(tableMeta.rowIdentityColumnId[0]) : undefined;
18836
18904
  pendingChangesWithErrors.forEach((error, index) => {
18837
18905
  // if appropriate, concatenate the item with the text "and"
18838
18906
  if (pendingChangesWithErrors.length > 1 && index === pendingChangesWithErrors.length - 1) {
18839
18907
  // Add space before and after `messageAnd` text
18840
18908
  links.push(` ${validationTexts.alert.messageAnd} `);
18841
18909
  }
18842
- const rowIndex = table.getRowModel().rows.findIndex(row => row.id === error.rowId);
18910
+ const rowIndex = table.getFilteredRowModel().rows.findIndex(row => row.id === error.rowId);
18843
18911
  const handleClick = () => {
18912
+ // if row is visible
18844
18913
  if (rowIndex > -1) {
18845
18914
  scrollToRow(rowIndex);
18846
- } else {
18915
+ }
18916
+ // if row is filtered out
18917
+ else {
18847
18918
  setShowFilterResetDialog(error.rowId);
18848
18919
  }
18849
18920
  };