@economic/taco 2.42.1 → 2.43.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6174,17 +6174,29 @@ const Combobox = /*#__PURE__*/React.forwardRef(function Combobox(props, ref) {
6174
6174
  const isWeakEqual = (leftDate, rightDate) => {
6175
6175
  return leftDate.getFullYear() === rightDate.getFullYear() && leftDate.getMonth() === rightDate.getMonth() && leftDate.getDate() === rightDate.getDate();
6176
6176
  };
6177
- const format = (date, mask = 'dd.mm.yy') => {
6178
- if (!date) {
6179
- return undefined;
6177
+ function parse(date) {
6178
+ let value;
6179
+ if (dateFns.isDate(date)) {
6180
+ value = date;
6181
+ } else if (typeof date === 'string') {
6182
+ value = parseFromISOString(date);
6180
6183
  }
6181
- const value = dateFns.isDate(date) ? date : dateFns.toDate(date);
6182
6184
  if (!dateFns.isValid(value)) {
6183
6185
  return undefined;
6184
6186
  }
6187
+ return value;
6188
+ }
6189
+ function format(date, mask = 'dd.mm.yy') {
6190
+ if (date === undefined) {
6191
+ return undefined;
6192
+ }
6193
+ const value = parse(date);
6194
+ if (!dateFns.isValid(value) || value === undefined) {
6195
+ return undefined;
6196
+ }
6185
6197
  const pad = v => String(v).length === 1 ? `0${v}` : v.toString();
6186
6198
  return mask.replace('dd', pad(value.getDate())).replace('mm', pad(value.getMonth() + 1)).replace('yy', String(value.getFullYear()).slice(2));
6187
- };
6199
+ }
6188
6200
  const parseFromCustomString = (date = '', mask = 'dd.mm.yy', defaultMonth = undefined, defaultYear = undefined) => {
6189
6201
  if (!date || !date.length) {
6190
6202
  return undefined;
@@ -6242,22 +6254,19 @@ const useDatepicker = ({
6242
6254
  const {
6243
6255
  formatting
6244
6256
  } = useLocalization();
6245
- const [internalValue, setInternalValue] = React.useState(value && dateFns.isValid(value) ? format(value, formatting.date) : '');
6257
+ const [internalValue, setInternalValue] = React.useState(format(value, formatting.date));
6258
+ const originalValueAsDate = parse(value);
6246
6259
  // update internal value if it changed 'externally'
6247
6260
  React.useEffect(() => {
6248
- if (value && dateFns.isValid(value)) {
6249
- const formattedValue = format(value, formatting.date);
6250
- if (formattedValue !== internalValue) {
6251
- setInternalValue(formattedValue);
6252
- }
6253
- } else {
6254
- setInternalValue('');
6261
+ const formattedValue = format(value, formatting.date);
6262
+ if (formattedValue !== internalValue) {
6263
+ setInternalValue(formattedValue);
6255
6264
  }
6256
6265
  }, [value]);
6257
6266
  // event handlers
6258
6267
  const handleInputBlur = event => {
6259
6268
  event.persist();
6260
- const valueAsDate = parseFromCustomString(event.target.value, 'dd.mm.yy', value === null || value === void 0 ? void 0 : value.getMonth(), value === null || value === void 0 ? void 0 : value.getFullYear());
6269
+ const valueAsDate = parseFromCustomString(event.target.value, 'dd.mm.yy', originalValueAsDate === null || originalValueAsDate === void 0 ? void 0 : originalValueAsDate.getMonth(), originalValueAsDate === null || originalValueAsDate === void 0 ? void 0 : originalValueAsDate.getFullYear());
6261
6270
  const formattedValue = valueAsDate ? format(valueAsDate) || '' : '';
6262
6271
  event.target.value = formattedValue;
6263
6272
  if (onChange) {
@@ -6281,7 +6290,7 @@ const useDatepicker = ({
6281
6290
  if (props.onKeyDown) {
6282
6291
  props.onKeyDown(event);
6283
6292
  }
6284
- if (!event.isPropagationStopped() && !event.isDefaultPrevented() && event.key === 'Enter') {
6293
+ if (event.key === 'Enter') {
6285
6294
  event.target.dispatchEvent(new Event('focusout', {
6286
6295
  bubbles: true
6287
6296
  }));
@@ -6300,7 +6309,7 @@ const useDatepicker = ({
6300
6309
  const calendarProps = {
6301
6310
  ...calendar,
6302
6311
  onChange: handleChange,
6303
- value
6312
+ value: originalValueAsDate
6304
6313
  };
6305
6314
  return {
6306
6315
  input: inputProps,
@@ -9816,17 +9825,8 @@ const dataTypes = {
9816
9825
  sortingFn: 'datetime',
9817
9826
  filterComparators: [exports.TableFilterComparator.IsEqualTo, exports.TableFilterComparator.IsNotEqualTo, exports.TableFilterComparator.IsGreaterThan, exports.TableFilterComparator.IsLessThan, exports.TableFilterComparator.IsGreaterThanOrEqualTo, exports.TableFilterComparator.IsLessThanOrEqualTo, exports.TableFilterComparator.IsBetween, exports.TableFilterComparator.IsEmpty, exports.TableFilterComparator.IsNotEmpty],
9818
9827
  getDisplayValue: (value, options) => {
9819
- if (value === undefined) {
9820
- return '';
9821
- }
9822
- if (dateFns.isDate(value)) {
9823
- var _format, _options$localization;
9824
- return (_format = format(value, options === null || options === void 0 ? void 0 : (_options$localization = options.localization) === null || _options$localization === void 0 ? void 0 : _options$localization.formatting.date)) !== null && _format !== void 0 ? _format : '';
9825
- } else if (typeof value === 'string') {
9826
- var _format2, _options$localization2;
9827
- return (_format2 = format(parseFromISOString(value), options === null || options === void 0 ? void 0 : (_options$localization2 = options.localization) === null || _options$localization2 === void 0 ? void 0 : _options$localization2.formatting.date)) !== null && _format2 !== void 0 ? _format2 : '';
9828
- }
9829
- return String(value);
9828
+ var _date$format, _options$localization;
9829
+ return (_date$format = format(value, options === null || options === void 0 ? void 0 : (_options$localization = options.localization) === null || _options$localization === void 0 ? void 0 : _options$localization.formatting.date)) !== null && _date$format !== void 0 ? _date$format : '';
9830
9830
  }
9831
9831
  },
9832
9832
  boolean: {
@@ -9839,11 +9839,11 @@ const dataTypes = {
9839
9839
  sortingFn: 'basic',
9840
9840
  filterComparators: [exports.TableFilterComparator.IsEqualTo, exports.TableFilterComparator.IsNotEqualTo, exports.TableFilterComparator.IsGreaterThan, exports.TableFilterComparator.IsLessThan, exports.TableFilterComparator.IsGreaterThanOrEqualTo, exports.TableFilterComparator.IsLessThanOrEqualTo, exports.TableFilterComparator.IsBetween, exports.TableFilterComparator.IsEmpty, exports.TableFilterComparator.IsNotEmpty],
9841
9841
  getDisplayValue: (value, options) => {
9842
- var _options$localization3;
9842
+ var _options$localization2;
9843
9843
  if (value === undefined) {
9844
9844
  return '';
9845
9845
  }
9846
- return new Intl.NumberFormat(options === null || options === void 0 ? void 0 : (_options$localization3 = options.localization) === null || _options$localization3 === void 0 ? void 0 : _options$localization3.locale, {
9846
+ return new Intl.NumberFormat(options === null || options === void 0 ? void 0 : (_options$localization2 = options.localization) === null || _options$localization2 === void 0 ? void 0 : _options$localization2.locale, {
9847
9847
  minimumFractionDigits: 2
9848
9848
  }).format(Number(value));
9849
9849
  }
@@ -19260,10 +19260,11 @@ const MemoedEditingCell = /*#__PURE__*/React__default.memo(function MemoedEditin
19260
19260
  }
19261
19261
  };
19262
19262
  if (type === 'datepicker') {
19263
+ const valueAsDate = parse(value);
19263
19264
  const handleChange = event => {
19264
19265
  const newDate = event.detail;
19265
- if (!value || !newDate || dateFns.isDate(value) && dateFns.isDate(newDate) && !isWeakEqual(value, newDate)) {
19266
- props.onChange(event.detail);
19266
+ if (!valueAsDate || !newDate || dateFns.isDate(valueAsDate) && dateFns.isDate(newDate) && !isWeakEqual(valueAsDate, newDate)) {
19267
+ props.onChange(newDate);
19267
19268
  }
19268
19269
  };
19269
19270
  return /*#__PURE__*/React__default.createElement(Datepicker, Object.assign({}, commonProps, {
@@ -19272,7 +19273,7 @@ const MemoedEditingCell = /*#__PURE__*/React__default.memo(function MemoedEditin
19272
19273
  onFocus: handleFocus,
19273
19274
  onKeyDown: handleInputKeyDown,
19274
19275
  ref: controlRef,
19275
- value: value
19276
+ value: valueAsDate
19276
19277
  }));
19277
19278
  }
19278
19279
  if (type === 'textarea') {
@@ -20863,6 +20864,7 @@ exports.isMacOs = isMacOs;
20863
20864
  exports.isPressingMetaKey = isPressingMetaKey;
20864
20865
  exports.isWeakEqual = isWeakEqual;
20865
20866
  exports.mergeRefs = mergeRefs;
20867
+ exports.parse = parse;
20866
20868
  exports.parseFromCustomString = parseFromCustomString;
20867
20869
  exports.parseFromISOString = parseFromISOString;
20868
20870
  exports.removeChildTableRow = removeChildTableRow;