@oliasoft-open-source/react-ui-library 5.8.11-beta-3 → 5.8.12-beta-1

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.
Files changed (2) hide show
  1. package/dist/index.js +41 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { AiOutlineMinusSquare, AiOutlinePlusSquare } from "react-icons/ai";
7
7
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
8
8
  import ResizeObserver$1 from "resize-observer-polyfill";
9
9
  import { Arrow, mergeRefs, useHover, useLayer, useMousePositionAsTrigger } from "react-laag";
10
- import { cloneDeep, cloneDeepWith, debounce, get, isArray, isBoolean, isEmpty, isEqual, isFunction, isNil, isNumber, isObject, isPlainObject, isString, noop, set, toLower, toNumber } from "lodash";
10
+ import { cloneDeep, cloneDeepWith, debounce, every, get, isArray, isBoolean, isEmpty, isEqual, isFunction, isNil, isNumber, isObject, isPlainObject, isString, keys, noop, set, toLower, toNumber, values } from "lodash";
11
11
  import styled, { css } from "styled-components";
12
12
  import { Resizable } from "react-resizable";
13
13
  import { createPortal } from "react-dom";
@@ -4816,27 +4816,38 @@ const Toggle = ({ name: e, label: t, checked: n = !1, disabled: r, display: i, s
4816
4816
  } }, i);
4817
4817
  }
4818
4818
  }, [v, _]), O = useCallback((e) => {
4819
- if (!e || e.errorMessage) {
4819
+ let t = isPlainObject(e) && isString(e.errorMessage) ? e.errorMessage : void 0;
4820
+ if (t) {
4821
+ transitionToast({ message: {
4822
+ type: "Error",
4823
+ content: t || "Smart upload failed."
4824
+ } }, i);
4825
+ return;
4826
+ }
4827
+ if (!isArray(e) || e.length < 2 || !every(e, (e) => isPlainObject(e) && every(values(e), isString))) {
4820
4828
  transitionToast({ message: {
4821
4829
  type: "Error",
4822
- content: e?.errorMessage || "Smart upload failed."
4830
+ content: "Smart upload returned unexpected format.",
4831
+ details: JSON.stringify(e)
4823
4832
  } }, i);
4824
4833
  return;
4825
4834
  }
4826
- let [t, ...n] = e, a = {
4835
+ let [n, ...a] = e, o = keys(a[0]), s = {
4827
4836
  isValid: !0,
4828
- fields: Object.keys(n[0]),
4829
- units: Object.values(t),
4830
- rows: n.map((e) => Object.values(e)),
4837
+ fields: o,
4838
+ units: o.map((e) => n[e] ?? ""),
4839
+ rows: a.map((e) => o.map((t) => e[t] ?? "")),
4831
4840
  errors: []
4832
4841
  };
4833
- i(() => y({ parsedResult: a })), i(() => d(a));
4834
- let { onComplete: o } = r ?? {};
4835
- typeof o == "function" && o(a), b();
4842
+ i(() => y({ parsedResult: s })), i(() => d(s));
4843
+ let { onComplete: c } = r ?? {};
4844
+ isFunction(c) && c(s), b();
4836
4845
  }, [
4837
4846
  y,
4838
4847
  d,
4839
- r
4848
+ r,
4849
+ b,
4850
+ i
4840
4851
  ]);
4841
4852
  return {
4842
4853
  updateState: y,
@@ -6600,7 +6611,7 @@ const UnitInput = ({ name: e, placeholder: t = "", disabled: n = !1, disabledUni
6600
6611
  } : {
6601
6612
  value: G,
6602
6613
  unit: U
6603
- }), Ad = k || K?.value === void 0, [J, jd] = useState(w ? PredefinedOptionsMenuState.PREDEFINED : PredefinedOptionsMenuState.CUSTOM), Md = !!(O || n), Y = C && C.find((e) => {
6614
+ }), Nd = k || K?.value === void 0, [J, Pd] = useState(w ? PredefinedOptionsMenuState.PREDEFINED : PredefinedOptionsMenuState.CUSTOM), Fd = !!(O || n), Y = C && C.find((e) => {
6604
6615
  if (!e?.value) return;
6605
6616
  if (E) return E === e.valueKey;
6606
6617
  let t = isValueWithUnit(e.value) ? getUnit(e.value) : "", { value: n = l } = convertUnit({
@@ -6609,7 +6620,7 @@ const UnitInput = ({ name: e, placeholder: t = "", disabled: n = !1, disabledUni
6609
6620
  toUnit: t
6610
6621
  });
6611
6622
  return withUnit(n, t) === e.value;
6612
- }), Nd = () => {
6623
+ }), Id = () => {
6613
6624
  let e = l ?? "", t = K.unit;
6614
6625
  if (checkConversion({
6615
6626
  value: e,
@@ -6623,7 +6634,7 @@ const UnitInput = ({ name: e, placeholder: t = "", disabled: n = !1, disabledUni
6623
6634
  return null;
6624
6635
  }
6625
6636
  } else return getAltUnitsListByQuantity(u)?.map((e) => ["", e?.unit]);
6626
- }, Pd = (t) => {
6637
+ }, Ld = (t) => {
6627
6638
  let n = getStringName(e), r = t.target, { value: i, selectionStart: a } = r, o = withUnit(i, K?.unit || ""), s = A ? withUnit(convertAndGetValue(o, B), B) : o;
6628
6639
  h({ target: {
6629
6640
  value: s,
@@ -6636,7 +6647,7 @@ const UnitInput = ({ name: e, placeholder: t = "", disabled: n = !1, disabledUni
6636
6647
  }), R(() => {
6637
6648
  r.selectionStart = a, r.selectionEnd = a;
6638
6649
  });
6639
- }, Fd = (e, t) => {
6650
+ }, Rd = (e, t) => {
6640
6651
  t === K.unit || isNaN(Number(e)) || (q({
6641
6652
  value: e,
6642
6653
  unit: t
@@ -6667,7 +6678,7 @@ const UnitInput = ({ name: e, placeholder: t = "", disabled: n = !1, disabledUni
6667
6678
  e !== void 0 && q({
6668
6679
  value: e,
6669
6680
  unit: t
6670
- }), C && jd(Y && T ? PredefinedOptionsMenuState.PREDEFINED : PredefinedOptionsMenuState.CUSTOM);
6681
+ }), C && Pd(Y && T ? PredefinedOptionsMenuState.PREDEFINED : PredefinedOptionsMenuState.CUSTOM);
6671
6682
  }
6672
6683
  }, [
6673
6684
  U,
@@ -6675,7 +6686,7 @@ const UnitInput = ({ name: e, placeholder: t = "", disabled: n = !1, disabledUni
6675
6686
  i,
6676
6687
  T
6677
6688
  ]);
6678
- let X = Nd(), Z = label(K.unit) || K.unit || "", Id = p || !X || X && X.length === 1, Q = getStringName(e), $, Ld = (t) => {
6689
+ let X = Id(), Z = label(K.unit) || K.unit || "", zd = p || !X || X && X.length === 1, Q = getStringName(e), $, Bd = (t) => {
6679
6690
  let r = t?.value ? t.value : "", [i = "", a = ""] = isValueWithUnit(r) ? split(r) : [r], o = withPrettyUnitLabel(r);
6680
6691
  if (checkConversion({
6681
6692
  value: r,
@@ -6695,7 +6706,7 @@ const UnitInput = ({ name: e, placeholder: t = "", disabled: n = !1, disabledUni
6695
6706
  type: MenuType.OPTION,
6696
6707
  inline: !0,
6697
6708
  onClick: () => {
6698
- validateNumber(i).valid && !n && (jd(PredefinedOptionsMenuState.PREDEFINED), h({ target: {
6709
+ validateNumber(i).valid && !n && (Pd(PredefinedOptionsMenuState.PREDEFINED), h({ target: {
6699
6710
  value: r,
6700
6711
  name: typeof e == "string" ? e : e?.fieldName || "",
6701
6712
  predefinedSelected: !0,
@@ -6722,10 +6733,10 @@ const UnitInput = ({ name: e, placeholder: t = "", disabled: n = !1, disabledUni
6722
6733
  label: "Custom",
6723
6734
  selected: J === PredefinedOptionsMenuState.CUSTOM
6724
6735
  }], C?.length) {
6725
- let e = C.map(Ld);
6736
+ let e = C.map(Bd);
6726
6737
  $ = [...$, ...e];
6727
6738
  }
6728
- let Rd = (e) => {
6739
+ let Vd = (e) => {
6729
6740
  if (isValueWithUnit(e)) {
6730
6741
  let t = getUnit(e), { value: n } = safeConvertValue({
6731
6742
  value: e,
@@ -6737,7 +6748,7 @@ const UnitInput = ({ name: e, placeholder: t = "", disabled: n = !1, disabledUni
6737
6748
  return n;
6738
6749
  }
6739
6750
  return e;
6740
- }, zd = !C && (!F || F === GroupOrder.FIRST) ? GroupOrder.FIRST : GroupOrder.MIDDLE, Bd = !F || F === GroupOrder.LAST ? GroupOrder.LAST : GroupOrder.MIDDLE;
6751
+ }, Hd = !C && (!F || F === GroupOrder.FIRST) ? GroupOrder.FIRST : GroupOrder.MIDDLE, Ud = !F || F === GroupOrder.LAST ? GroupOrder.LAST : GroupOrder.MIDDLE;
6741
6752
  return /* @__PURE__ */ jsx("div", {
6742
6753
  className: J === PredefinedOptionsMenuState.PREDEFINED ? cx(unit_input_module_default.predefinedMenuActive) : "",
6743
6754
  children: /* @__PURE__ */ jsxs(InputGroup, {
@@ -6769,31 +6780,31 @@ const UnitInput = ({ name: e, placeholder: t = "", disabled: n = !1, disabledUni
6769
6780
  name: Q,
6770
6781
  testId: x,
6771
6782
  disabled: n,
6772
- placeholder: Rd(t),
6783
+ placeholder: Vd(t),
6773
6784
  value: K.value,
6774
- onChange: Pd,
6785
+ onChange: Ld,
6775
6786
  onFocus: v,
6776
6787
  error: i === null ? void 0 : i,
6777
6788
  warning: S === null ? void 0 : S,
6778
6789
  left: a,
6779
- allowEmpty: Ad,
6790
+ allowEmpty: Nd,
6780
6791
  validationCallback: (e, t) => D(Q, t),
6781
6792
  enableCosmeticRounding: j,
6782
6793
  enableDisplayRounding: M,
6783
6794
  roundDisplayValue: N,
6784
- groupOrder: zd,
6785
- disableInternalErrorValidationMessages: Md,
6795
+ groupOrder: Hd,
6796
+ disableInternalErrorValidationMessages: Fd,
6786
6797
  small: o,
6787
6798
  selectOnFocus: P,
6788
6799
  tooltip: I
6789
6800
  }, Q)
6790
6801
  }),
6791
- Z && (Id || !H ? /* @__PURE__ */ jsx(InputGroupAddon, {
6792
- groupOrder: Bd,
6802
+ Z && (zd || !H ? /* @__PURE__ */ jsx(InputGroupAddon, {
6803
+ groupOrder: Ud,
6793
6804
  small: o,
6794
6805
  children: Z
6795
6806
  }) : /* @__PURE__ */ jsx(Menu, {
6796
- groupOrder: Bd,
6807
+ groupOrder: Ud,
6797
6808
  maxHeight: 380,
6798
6809
  disabled: r,
6799
6810
  testId: x && `${x}-menu`,
@@ -6809,7 +6820,7 @@ const UnitInput = ({ name: e, placeholder: t = "", disabled: n = !1, disabledUni
6809
6820
  label: j ? safeRoundNumbers(i) : i,
6810
6821
  inline: !0,
6811
6822
  onClick: (n) => {
6812
- n.stopPropagation(), Fd(e, t);
6823
+ n.stopPropagation(), Rd(e, t);
6813
6824
  },
6814
6825
  description: r,
6815
6826
  selected: r === Z,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/react-ui-library",
3
- "version": "5.8.11-beta-3",
3
+ "version": "5.8.12-beta-1",
4
4
  "description": "Reusable UI components for React projects",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/react-ui-library",
6
6
  "bugs": {