@oliasoft-open-source/react-ui-library 5.11.7-beta-6 → 5.11.7-beta-8

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/index.d.ts CHANGED
@@ -2211,8 +2211,8 @@ declare type TUpdateTableImportExportState = (value: ITableImportExportState | (
2211
2211
 
2212
2212
  export declare interface TValidationRule {
2213
2213
  fieldName: string;
2214
- defaultUnit: string;
2215
- validUnits: string[];
2214
+ defaultUnit?: string;
2215
+ validUnits?: string[];
2216
2216
  optionalColumn?: boolean;
2217
2217
  validator?: (value: string) => string | boolean | undefined | null;
2218
2218
  fieldNameValidator?: (params: {
package/dist/index.js CHANGED
@@ -3916,17 +3916,20 @@ const TableScrollWrapper = ({ table: e, children: t }) => {
3916
3916
  isValid: s
3917
3917
  };
3918
3918
  }, Table$1 = ({ validationRules: e, parsedResult: t, updateState: n, testId: r }) => {
3919
- let i = useMemo(() => t.fields.map((e) => ({ value: e })), [t.fields]), [a, s] = useState(20), [l, u] = useState(1), f = useRef([]), h = (l - 1) * a, g = a === 0 ? t.rows.length : h + a, [_, v] = useState([]), y = useCallback((r, a) => (!f.current.length && t.rows.length && (f.current = t.rows[0].map((e) => isNumericLike(e) ? "NumberInput" : "Input")), {
3920
- cells: r.map((r, o) => {
3921
- let { columnMessage: s = {}, validator: c = () => null } = e?.[o] ?? {}, l = i?.[o]?.value, u = `${`Row ${a + 1}`} → ${l}:`, d = c(r), p = t?.errors?.find((e) => e.startsWith(u)) ?? null, m = d || p || null;
3919
+ let i = useMemo(() => t.fields.map((e) => ({ value: e })), [t.fields]), [a, s] = useState(20), [l, u] = useState(1), f = useRef([]), h = (l - 1) * a, g = a === 0 ? t.rows.length : h + a, [_, v] = useState([]), y = useMemo(() => {
3920
+ let n = e.filter((e) => !e.optionalColumn);
3921
+ return t.fields.length === n.length ? n : e;
3922
+ }, [e, t.fields.length]), b = useCallback((e, r) => (!f.current.length && t.rows.length && (f.current = t.rows[0].map((e) => isNumericLike(e) ? "NumberInput" : "Input")), {
3923
+ cells: e.map((e, a) => {
3924
+ let { columnMessage: o = {}, validator: s = () => null } = y?.[a] ?? {}, c = i?.[a]?.value, l = `${`Row ${r + 1}`} → ${c}:`, u = s(e), d = t?.errors?.find((e) => e.startsWith(l)) ?? null, p = u || d || null;
3922
3925
  return {
3923
- name: l,
3924
- value: r,
3925
- type: f.current[o] ?? "Input",
3926
+ name: c,
3927
+ value: e,
3928
+ type: f.current[a] ?? "Input",
3926
3929
  disableValidationOnFocus: !0,
3927
- error: m,
3928
- validationCallback: (e, r) => {
3929
- let i = `Row ${a + 1}`, { updatedErrors: o, isValid: s } = getUpdatedErrors(t.errors, i, e, r);
3930
+ error: p,
3931
+ validationCallback: (e, i) => {
3932
+ let a = `Row ${r + 1}`, { updatedErrors: o, isValid: s } = getUpdatedErrors(t.errors, a, e, i);
3930
3933
  n({ parsedResult: {
3931
3934
  ...t,
3932
3935
  errors: o,
@@ -3934,7 +3937,7 @@ const TableScrollWrapper = ({ table: e, children: t }) => {
3934
3937
  } });
3935
3938
  },
3936
3939
  onChange: (e) => {
3937
- let { value: r } = e?.target ?? {}, i = `Row ${a + 1}`, s = c(r), { updatedErrors: u, isValid: d } = getUpdatedErrors(t.errors, i, l, s), f = t.rows.map((e, t) => t === a ? e.map((e, t) => t === o ? r : e) : e);
3940
+ let { value: i } = e?.target ?? {}, o = `Row ${r + 1}`, l = s(i), { updatedErrors: u, isValid: d } = getUpdatedErrors(t.errors, o, c, l), f = t.rows.map((e, t) => t === r ? e.map((e, t) => t === a ? i : e) : e);
3938
3941
  n({ parsedResult: {
3939
3942
  ...t,
3940
3943
  rows: f,
@@ -3942,17 +3945,17 @@ const TableScrollWrapper = ({ table: e, children: t }) => {
3942
3945
  isValid: d
3943
3946
  } }), v((e) => {
3944
3947
  let t = [...e];
3945
- return t[a] = y(f[a], a), t;
3948
+ return t[r] = b(f[r], r), t;
3946
3949
  });
3947
3950
  },
3948
- ...s
3951
+ ...o
3949
3952
  };
3950
3953
  }),
3951
3954
  actions: [{
3952
3955
  label: "Delete",
3953
3956
  icon: "minus",
3954
3957
  onClick: () => {
3955
- let e = t.rows.filter((e, t) => t !== a);
3958
+ let e = t.rows.filter((e, t) => t !== r);
3956
3959
  n({ parsedResult: {
3957
3960
  ...t,
3958
3961
  rows: e
@@ -3966,7 +3969,7 @@ const TableScrollWrapper = ({ table: e, children: t }) => {
3966
3969
  n
3967
3970
  ]);
3968
3971
  useEffect(() => {
3969
- v(t.rows.map((e, t) => y(e, t)));
3972
+ v(t.rows.map((e, t) => b(e, t)));
3970
3973
  }, [
3971
3974
  t.rows.length,
3972
3975
  i,
@@ -3974,24 +3977,24 @@ const TableScrollWrapper = ({ table: e, children: t }) => {
3974
3977
  t.errors,
3975
3978
  t.isValid
3976
3979
  ]);
3977
- let b = useMemo(() => t.fields.map((r, a) => {
3978
- let o = e?.[a], s = Array.isArray(o?.validUnits) ? o.validUnits : [], c = s?.some((e) => toLower(e) === placeholder$1);
3979
- if (!s.length || c) return {};
3980
- let l = t?.units?.[a], u = toLower(l), d = s?.some((e) => toLower(e) === u) ? l : o?.defaultUnit ?? "";
3980
+ let x = useMemo(() => t.fields.map((e, r) => {
3981
+ let a = y?.[r], o = Array.isArray(a?.validUnits) ? a.validUnits : [], s = o?.some((e) => toLower(e) === placeholder$1);
3982
+ if (!o.length || s) return {};
3983
+ let c = t?.units?.[r], l = toLower(c), u = o?.some((e) => toLower(e) === l) ? c : a?.defaultUnit ?? "";
3981
3984
  return {
3982
- key: i?.[a]?.value,
3983
- value: d,
3985
+ key: i?.[r]?.value,
3986
+ value: u,
3984
3987
  type: "Select",
3985
- disabled: !s.length || !d,
3986
- options: s.map((e) => ({
3988
+ disabled: !o.length || !u,
3989
+ options: o.map((e) => ({
3987
3990
  label: e,
3988
3991
  value: e
3989
3992
  })),
3990
3993
  onChange: (e) => {
3991
- let { value: r } = e?.target ?? {}, i = t.units.map((e, t) => t === a ? r : e);
3994
+ let { value: i } = e?.target ?? {}, a = t.units.map((e, t) => t === r ? i : e);
3992
3995
  n({ parsedResult: {
3993
3996
  ...t,
3994
- units: i
3997
+ units: a
3995
3998
  } });
3996
3999
  }
3997
4000
  };
@@ -4000,30 +4003,30 @@ const TableScrollWrapper = ({ table: e, children: t }) => {
4000
4003
  e,
4001
4004
  i,
4002
4005
  n
4003
- ]), x = useMemo(() => b.some((e) => !isEmpty(e)), [b]), S = useMemo(() => [{
4006
+ ]), S = useMemo(() => x.some((e) => !isEmpty(e)), [x]), C = useMemo(() => [{
4004
4007
  cells: i,
4005
4008
  actions: [{}]
4006
- }, ...x ? [{ cells: b }] : []], [
4009
+ }, ...S ? [{ cells: x }] : []], [
4007
4010
  i,
4008
- x,
4009
- b
4010
- ]), C = useMemo(() => _.slice(h, g), [
4011
+ S,
4012
+ x
4013
+ ]), w = useMemo(() => _.slice(h, g), [
4011
4014
  _,
4012
4015
  h,
4013
4016
  g
4014
- ]), w = useCallback(({ rowIndex: e }) => {
4017
+ ]), T = useCallback(({ rowIndex: e }) => {
4015
4018
  let n = h + e, r = t.rows[n];
4016
- return r ? y(r, n) : {
4019
+ return r ? b(r, n) : {
4017
4020
  cells: [],
4018
4021
  actions: []
4019
4022
  };
4020
4023
  }, [
4021
4024
  t.rows,
4022
- y,
4025
+ b,
4023
4026
  h
4024
4027
  ]);
4025
4028
  return /* @__PURE__ */ jsx(Table, {
4026
- beforeRenderRow: w,
4029
+ beforeRenderRow: T,
4027
4030
  onListReorder: ({ from: e, to: r }) => {
4028
4031
  let i = [...t.rows], [a] = i.splice(e, 1);
4029
4032
  i.splice(r, 0, a), n({ parsedResult: {
@@ -4037,12 +4040,12 @@ const TableScrollWrapper = ({ table: e, children: t }) => {
4037
4040
  table: {
4038
4041
  testId: `${r}-paste-with-review-modal-table`,
4039
4042
  draggable: !0,
4040
- headers: S,
4041
- rows: Array.from({ length: C?.length || 0 }, () => ({
4043
+ headers: C,
4044
+ rows: Array.from({ length: w?.length || 0 }, () => ({
4042
4045
  cells: [],
4043
4046
  actions: []
4044
4047
  })),
4045
- rowCount: C?.length,
4048
+ rowCount: w?.length,
4046
4049
  infiniteScroll: !0,
4047
4050
  footer: { pagination: {
4048
4051
  rowCount: t.rows.length,
@@ -4202,7 +4205,7 @@ var isValidLength = (e, t, n) => e >= t - n, isNonPlaceholderUnit = (e) => !!e &
4202
4205
  t.forEach((r, c) => {
4203
4206
  let l = n[c];
4204
4207
  if (!l || l?.optionalColumn) return;
4205
- let u = l.unitsValidator ?? defaultUnitsValidator, d = i?.[c];
4208
+ let u = l.unitsValidator ?? defaultUnitsValidator, d = i?.[c] ?? [];
4206
4209
  u({
4207
4210
  value: r,
4208
4211
  defaultAllowedValues: d,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/react-ui-library",
3
- "version": "5.11.7-beta-6",
3
+ "version": "5.11.7-beta-8",
4
4
  "description": "Reusable UI components for React projects",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/react-ui-library",
6
6
  "bugs": {