md-components-mdigial-azamat 0.0.290 → 0.0.291

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.
@@ -1,32 +1,36 @@
1
- import { useState as q, useRef as w, useCallback as F, useEffect as D, useMemo as O } from "react";
2
- const m = (c, o = 0) => {
1
+ import { useState as I, useRef as $, useEffect as h, useCallback as F, useMemo as k } from "react";
2
+ const m = (c, l = 0) => {
3
3
  const v = Number(c);
4
- return Number.isFinite(v) ? v : o;
5
- }, I = (c, o) => o === void 0 || o === "" ? !0 : typeof o == "boolean" ? !!Number(c) === o : String(c) === String(o), x = (c, o) => c.find((v) => v.key === o), N = (c) => {
4
+ return Number.isFinite(v) ? v : l;
5
+ }, j = (c, l) => l === void 0 || l === "" ? !0 : typeof l == "boolean" ? !!Number(c) === l : String(c) === String(l), N = (c, l) => c.find((v) => v.key === l), R = (c) => {
6
6
  if (c) {
7
7
  if (c.type === "select")
8
8
  return c.source;
9
9
  if (c.type === "range")
10
10
  return c.discreteOptionsSource;
11
11
  }
12
- }, z = (c) => {
13
- const [o, v] = q({}), R = w({}), K = c.datasets ?? [], i = c.fields ?? [], g = c.derivedVariables ?? [], E = c.formulas ?? [], b = F(
12
+ }, A = (c) => {
13
+ const [l, v] = I({}), f = $({}), E = $({}), K = c.datasets ?? [], i = c.fields ?? [], g = c.derivedVariables ?? [], M = c.formulas ?? [];
14
+ h(() => {
15
+ f.current = l;
16
+ }, [l]);
17
+ const b = F(
14
18
  (e, r) => {
15
19
  var y;
16
20
  if (!e)
17
21
  return null;
18
- const t = r ?? o, a = i.find(
22
+ const t = r ?? f.current, a = i.find(
19
23
  (V) => V.variable === e
20
- ), n = N(a);
24
+ ), n = R(a);
21
25
  if (!a || (n == null ? void 0 : n.mode) !== "dataset")
22
26
  return null;
23
- const u = x(K, n.datasetKey);
27
+ const u = N(K, n.datasetKey);
24
28
  if (!u || !n.valueFieldKey)
25
29
  return null;
26
30
  if (!n.collectionKey) {
27
31
  const V = t[e] ?? a.defaultValue;
28
32
  return u.items.find(
29
- (P) => P.values[n.valueFieldKey] == V
33
+ (w) => w.values[n.valueFieldKey] == V
30
34
  ) ?? null;
31
35
  }
32
36
  const s = b(
@@ -35,24 +39,24 @@ const m = (c, o = 0) => {
35
39
  );
36
40
  if (!s)
37
41
  return null;
38
- const l = t[e] ?? a.defaultValue;
42
+ const o = t[e] ?? a.defaultValue;
39
43
  return (((y = s.children) == null ? void 0 : y[n.collectionKey]) ?? []).find(
40
- (V) => V.values[n.valueFieldKey] == l
44
+ (V) => V.values[n.valueFieldKey] == o
41
45
  ) ?? null;
42
46
  },
43
- [K, i, o]
47
+ [K, i]
44
48
  ), p = F(
45
49
  (e, r) => {
46
50
  var n, u;
47
51
  if (((n = e.source) == null ? void 0 : n.mode) !== "dataset")
48
52
  return e.options || [];
49
- const t = x(K, e.source.datasetKey);
53
+ const t = N(K, e.source.datasetKey);
50
54
  if (!t || !e.source.labelFieldKey || !e.source.valueFieldKey)
51
55
  return [];
52
56
  if (!e.source.collectionKey)
53
- return t.items.map((s, l) => ({
57
+ return t.items.map((s, o) => ({
54
58
  id: s.id,
55
- label: String(s.values[e.source.labelFieldKey] ?? `Опция ${l + 1}`),
59
+ label: String(s.values[e.source.labelFieldKey] ?? `Опция ${o + 1}`),
56
60
  value: s.values[e.source.valueFieldKey] ?? ""
57
61
  }));
58
62
  const a = b(
@@ -60,9 +64,9 @@ const m = (c, o = 0) => {
60
64
  r
61
65
  );
62
66
  return a ? (((u = a.children) == null ? void 0 : u[e.source.collectionKey]) ?? []).map(
63
- (s, l) => ({
67
+ (s, o) => ({
64
68
  id: s.id,
65
- label: String(s.values[e.source.labelFieldKey] ?? `Опция ${l + 1}`),
69
+ label: String(s.values[e.source.labelFieldKey] ?? `Опция ${o + 1}`),
66
70
  value: s.values[e.source.valueFieldKey] ?? ""
67
71
  })
68
72
  ) : [];
@@ -74,13 +78,13 @@ const m = (c, o = 0) => {
74
78
  const t = e.discreteOptionsSource;
75
79
  if ((t == null ? void 0 : t.mode) !== "dataset")
76
80
  return [];
77
- const a = x(K, t.datasetKey);
81
+ const a = N(K, t.datasetKey);
78
82
  if (!a || !t.labelFieldKey || !t.valueFieldKey)
79
83
  return [];
80
84
  if (!t.collectionKey)
81
- return a.items.map((s, l) => ({
85
+ return a.items.map((s, o) => ({
82
86
  id: s.id,
83
- label: String(s.values[t.labelFieldKey] ?? `Опция ${l + 1}`),
87
+ label: String(s.values[t.labelFieldKey] ?? `Опция ${o + 1}`),
84
88
  value: s.values[t.valueFieldKey] ?? ""
85
89
  }));
86
90
  const n = b(
@@ -88,9 +92,9 @@ const m = (c, o = 0) => {
88
92
  r
89
93
  );
90
94
  return n ? (((u = n.children) == null ? void 0 : u[t.collectionKey]) ?? []).map(
91
- (s, l) => ({
95
+ (s, o) => ({
92
96
  id: s.id,
93
- label: String(s.values[t.labelFieldKey] ?? `Опция ${l + 1}`),
97
+ label: String(s.values[t.labelFieldKey] ?? `Опция ${o + 1}`),
94
98
  value: s.values[t.valueFieldKey] ?? ""
95
99
  })
96
100
  ) : [];
@@ -105,26 +109,26 @@ const m = (c, o = 0) => {
105
109
  return (n = a == null ? void 0 : a.values) == null ? void 0 : n[r];
106
110
  },
107
111
  [b]
108
- ), h = F(
112
+ ), D = F(
109
113
  (e, r) => {
110
114
  const t = e.visibleIf;
111
115
  if (!(t != null && t.sourceField))
112
116
  return !0;
113
- const a = r ?? o, n = t.datasetFieldKey ? d(
117
+ const a = r ?? f.current, n = t.datasetFieldKey ? d(
114
118
  t.sourceField,
115
119
  t.datasetFieldKey,
116
120
  a
117
121
  ) : a[t.sourceField];
118
- return I(n, t.equals);
122
+ return j(n, t.equals);
119
123
  },
120
- [d, o]
124
+ [d]
121
125
  );
122
- D(() => {
126
+ h(() => {
123
127
  v((e) => {
124
128
  const r = { ...e };
125
129
  let t = !1;
126
130
  return i.forEach((a) => {
127
- var u, s, l;
131
+ var u, s, o;
128
132
  if (r[a.variable] !== void 0)
129
133
  return;
130
134
  if (a.type === "select") {
@@ -138,7 +142,7 @@ const m = (c, o = 0) => {
138
142
  }
139
143
  if (a.type === "range" && ((s = a.discreteOptionsSource) == null ? void 0 : s.mode) === "dataset") {
140
144
  const y = S(a, r);
141
- r[a.variable] = a.defaultValue !== "" ? a.defaultValue : ((l = y[0]) == null ? void 0 : l.value) ?? "", t = !0;
145
+ r[a.variable] = a.defaultValue !== "" ? a.defaultValue : ((o = y[0]) == null ? void 0 : o.value) ?? "", t = !0;
142
146
  return;
143
147
  }
144
148
  const n = d(
@@ -149,76 +153,76 @@ const m = (c, o = 0) => {
149
153
  r[a.variable] = n !== void 0 ? n : a.defaultValue, t = !0;
150
154
  }), t ? r : e;
151
155
  });
152
- }, [i, d, S, p]), D(() => {
156
+ }, [i, d, S, p]), h(() => {
153
157
  v((e) => {
154
158
  const r = { ...e };
155
159
  let t = !1;
156
160
  return i.forEach((a) => {
157
161
  var y;
158
- const n = N(a);
162
+ const n = R(a);
159
163
  if ((n == null ? void 0 : n.mode) !== "dataset")
160
164
  return;
161
165
  const u = a.type === "select" ? p(a, r) : a.type === "range" ? S(a, r) : [], s = r[a.variable];
162
166
  u.some((V) => V.value == s) || (r[a.variable] = a.defaultValue !== "" ? a.defaultValue : ((y = u[0]) == null ? void 0 : y.value) ?? "", t = !0);
163
167
  }), t ? r : e;
164
168
  });
165
- }, [i, p]), D(() => {
169
+ }, [i, p]), h(() => {
166
170
  v((e) => {
167
171
  const r = { ...e };
168
172
  let t = !1;
169
173
  return i.forEach((a) => {
170
- const n = N(a);
174
+ const n = R(a);
171
175
  if ((n == null ? void 0 : n.mode) !== "dataset" || !n.collectionKey || !n.parentFieldVariable)
172
176
  return;
173
- const u = R.current[n.parentFieldVariable], s = e[n.parentFieldVariable];
177
+ const u = E.current[n.parentFieldVariable], s = e[n.parentFieldVariable];
174
178
  u !== s && (r[a.variable] = "", t = !0);
175
- }), R.current = r, t ? r : e;
179
+ }), E.current = r, t ? r : e;
176
180
  });
177
- }, [i, o]);
178
- const f = O(
181
+ }, [i]);
182
+ const x = k(
179
183
  () => g.reduce((e, r) => {
180
184
  const t = d(r.sourceField, r.datasetFieldKey);
181
185
  return e[r.variable] = t === void 0 ? "" : t, e;
182
186
  }, {}),
183
187
  [g, d]
184
- ), $ = F((e, r) => {
188
+ ), B = F((e, r) => {
185
189
  v((t) => ({
186
190
  ...t,
187
191
  [e]: r === "" ? "" : r
188
192
  }));
189
- }, []), M = O(() => {
193
+ }, []), O = k(() => {
190
194
  const e = {}, r = [
191
195
  ...i.map((t) => t.variable),
192
196
  ...g.map((t) => t.variable)
193
197
  ];
194
- return E.forEach((t) => {
198
+ return M.forEach((t) => {
195
199
  try {
196
200
  e[t.id] = new Function(...r, `return ${t.expression}`);
197
201
  } catch {
198
202
  e[t.id] = () => 0;
199
203
  }
200
204
  }), { keys: r, fns: e };
201
- }, [g, i, E]), k = F(
205
+ }, [g, i, M]), C = F(
202
206
  (e) => {
203
207
  try {
204
- const { keys: r, fns: t } = M, a = t[e];
208
+ const { keys: r, fns: t } = O, a = t[e];
205
209
  if (!a)
206
210
  return 0;
207
211
  const n = {
208
- ...o,
209
- ...f
212
+ ...l,
213
+ ...x
210
214
  };
211
- i.forEach((l) => {
212
- h(l) || (n[l.variable] = 0);
215
+ i.forEach((o) => {
216
+ D(o) || (n[o.variable] = 0);
213
217
  });
214
- const u = r.map((l) => m(n[l], 0)), s = a(...u);
218
+ const u = r.map((o) => m(n[o], 0)), s = a(...u);
215
219
  return isNaN(s) || !isFinite(s) ? 0 : s;
216
220
  } catch {
217
221
  return 0;
218
222
  }
219
223
  },
220
- [M, f, i, h, o]
221
- ), B = F(
224
+ [O, x, i, D, l]
225
+ ), P = F(
222
226
  (e) => {
223
227
  if (!e)
224
228
  return "";
@@ -226,15 +230,15 @@ const m = (c, o = 0) => {
226
230
  if (r) {
227
231
  const t = r[1], a = i.find((n) => n.variable === t);
228
232
  if (a && a.type === "select") {
229
- const n = p(a), u = o[t] ?? a.defaultValue, s = n.find((l) => l.value == u);
233
+ const n = p(a), u = l[t] ?? a.defaultValue, s = n.find((o) => o.value == u);
230
234
  return s ? s.label : "";
231
235
  }
232
- return String(o[t] || "");
236
+ return String(l[t] || "");
233
237
  }
234
238
  return e;
235
239
  },
236
- [i, p, o]
237
- ), C = F(
240
+ [i, p, l]
241
+ ), q = F(
238
242
  (e) => {
239
243
  const r = !!e.bindingSourceField, t = d(e.bindingSourceField, e.minDatasetFieldKey), a = d(e.bindingSourceField, e.maxDatasetFieldKey), n = d(e.bindingSourceField, e.stepDatasetFieldKey), u = d(
240
244
  e.bindingSourceField,
@@ -254,17 +258,17 @@ const m = (c, o = 0) => {
254
258
  [d]
255
259
  );
256
260
  return {
257
- values: o,
258
- handleValueChange: $,
259
- evaluateFormula: k,
260
- derivedValues: f,
261
- getDynamicSuffix: B,
261
+ values: l,
262
+ handleValueChange: B,
263
+ evaluateFormula: C,
264
+ derivedValues: x,
265
+ getDynamicSuffix: P,
262
266
  resolveRangeOptions: S,
263
267
  resolveSelectOptions: p,
264
- resolveNumericFieldProps: C,
265
- isFieldVisible: h
268
+ resolveNumericFieldProps: q,
269
+ isFieldVisible: D
266
270
  };
267
271
  };
268
272
  export {
269
- z as useCalculator
273
+ A as useCalculator
270
274
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "md-components-mdigial-azamat",
3
3
  "author": "Azamat Raimbekov",
4
4
  "private": false,
5
- "version": "0.0.290",
5
+ "version": "0.0.291",
6
6
  "type": "module",
7
7
  "main": "dist/main.js",
8
8
  "types": "dist/main.d.ts",