@declarion/react 0.163.0 → 0.167.0

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.
@@ -32,7 +32,10 @@ function w(e, t) {
32
32
  }
33
33
  return u(e, { row: t });
34
34
  }
35
- function T(e) {
35
+ function T(e, t, n) {
36
+ return n === "" && e.type === "string" && typeof e.default == "string" && C.test(e.default) && t !== "" && t != null;
37
+ }
38
+ function E(e) {
36
39
  return {
37
40
  type: e.type ?? "string",
38
41
  required: e.required,
@@ -46,18 +49,18 @@ function T(e) {
46
49
  ref: c(e.ref)
47
50
  };
48
51
  }
49
- function E(e, t) {
52
+ function D(e, t) {
50
53
  if (!e.includes("${")) return e;
51
54
  let n = u(e, { params: t });
52
55
  return n == null ? "" : d(n);
53
56
  }
54
- var D = /\$\{\s*([^}]+?)\s*\}/g;
55
- function O(e, t) {
57
+ var O = /\$\{\s*([^}]+?)\s*\}/g;
58
+ function k(e, t) {
56
59
  let n = `params.${t}`;
57
- for (let t of e.matchAll(D)) if (t[1] === n) return !0;
60
+ for (let t of e.matchAll(O)) if (t[1] === n) return !0;
58
61
  return !1;
59
62
  }
60
- function k({ param: e, value: t, onChange: r, statusGroups: i }) {
63
+ function A({ param: e, value: t, onChange: r, statusGroups: i }) {
61
64
  let a = p(), o = _(() => {
62
65
  let t = i ? Object.entries(i) : [];
63
66
  return [{
@@ -79,12 +82,12 @@ function k({ param: e, value: t, onChange: r, statusGroups: i }) {
79
82
  placeholder: a("action.dialog.select_status_group", "Select status group…")
80
83
  });
81
84
  }
82
- function A({ param: e, value: t, onChange: r, statusGroups: i, formData: a }) {
85
+ function j({ param: e, value: t, onChange: r, statusGroups: i, formData: a }) {
83
86
  let o = p(), s = _(() => {
84
87
  if (!i) return [];
85
88
  let t = e.filter?.status_group;
86
89
  if (t) {
87
- let e = E(t, a);
90
+ let e = D(t, a);
88
91
  return e && i[e] ? i[e].statuses : [];
89
92
  }
90
93
  return Object.values(i).flatMap((e) => e.statuses);
@@ -106,67 +109,69 @@ function A({ param: e, value: t, onChange: r, statusGroups: i, formData: a }) {
106
109
  placeholder: o("action.dialog.select_status", "Select status…")
107
110
  });
108
111
  }
109
- function j({ open: n, onOpenChange: c, action: u, actionName: d, onSubmit: C, isPending: E, row: D, bulkSelection: j }) {
110
- let M = p(), { data: N } = l(), P = u.resolved_params, F = u.resolved_hidden_defaults ?? {}, I = !!u.destructive, L = s(M, u), R = h(() => {
111
- E || c(!1);
112
- }, [E, c]), z = v(null);
112
+ function M({ open: n, onOpenChange: c, action: u, actionName: d, onSubmit: C, isPending: D, row: O, bulkSelection: M }) {
113
+ let N = p(), { data: P } = l(), F = u.resolved_params, I = u.resolved_hidden_defaults, L = !!u.destructive, R = s(N, u), z = h(() => {
114
+ D || c(!1);
115
+ }, [D, c]), B = v(null);
113
116
  g(() => {
114
- n && z.current?.focus();
117
+ n && B.current?.focus();
115
118
  }, [n]);
116
- let B = _(() => P ? Array.from(P) : [], [P]), V = _(() => {
117
- if (u.entity && N) return N.entities[u.entity]?.status_groups;
118
- }, [u.entity, N]), H = _(() => {
119
- if (u.entity && N) return N.entities[u.entity];
120
- }, [u.entity, N]), U = _(() => {
121
- if (H) {
122
- for (let [e, t] of H.fields) if (t.primary) return e;
123
- return H.primary_key?.[0];
119
+ let V = _(() => F ? Array.from(F) : [], [F]), H = _(() => {
120
+ if (u.entity && P) return P.entities[u.entity]?.status_groups;
121
+ }, [u.entity, P]), U = _(() => {
122
+ if (u.entity && P) return P.entities[u.entity];
123
+ }, [u.entity, P]), W = _(() => {
124
+ if (U) {
125
+ for (let [e, t] of U.fields) if (t.primary) return e;
126
+ return U.primary_key?.[0];
124
127
  }
125
- }, [H]), W = h(() => {
126
- let e = { ...F };
127
- for (let [t, n] of B) if (n.type === "id_array") e[t] = j && U ? j.map((e) => e[U]).filter((e) => e != null) : [];
128
+ }, [U]), G = h(() => {
129
+ let e = { ...I };
130
+ for (let [t, n] of V) if (n.type === "id_array") e[t] = M && W ? M.map((e) => e[W]).filter((e) => e != null) : [];
128
131
  else if (n.type === "entity_patch") e[t] = {};
129
132
  else if (n.type === "bool") {
130
- let r = w(n.default, D);
133
+ let r = w(n.default, O);
131
134
  e[t] = r === !0 || r === "true";
132
- } else e[t] = w(n.default, D);
135
+ } else e[t] = w(n.default, O);
133
136
  return e;
134
137
  }, [
135
- B,
136
- D,
137
- j,
138
- U
139
- ]), [G] = y(W), [K, q] = y(G);
140
- m(n && JSON.stringify(K) !== JSON.stringify(G));
141
- let J = h((e, t) => {
142
- q((n) => {
138
+ V,
139
+ O,
140
+ M,
141
+ W,
142
+ I
143
+ ]), [K] = y(G), [q, J] = y(K);
144
+ m(n && JSON.stringify(q) !== JSON.stringify(K));
145
+ let Y = h((e, t) => {
146
+ J((n) => {
143
147
  let r = {
144
148
  ...n,
145
149
  [e]: t
146
150
  };
147
- if (!P) return r;
148
- for (let [t, n] of P) {
151
+ if (!F) return r;
152
+ for (let [t, n] of F) {
149
153
  if (n.type !== "status") continue;
150
154
  let i = n.filter?.status_group;
151
- i && O(i, e) && (r[t] = "");
155
+ i && k(i, e) && (r[t] = "");
152
156
  }
153
157
  return r;
154
158
  });
155
- }, [P]), Y = h(() => {
156
- let e = { ...K };
157
- for (let [t, n] of B) {
158
- let r = K[t], i = r == null || r === "";
159
+ }, [F]), X = h(() => {
160
+ let e = { ...q };
161
+ for (let [t, n] of V) {
162
+ let r = q[t], i = r == null || r === "";
159
163
  if (n.required && i) return;
160
- i && delete e[t];
164
+ i && !T(n, K[t], r) && delete e[t];
161
165
  }
162
166
  C(e);
163
167
  }, [
168
+ q,
164
169
  K,
165
- B,
170
+ V,
166
171
  C
167
172
  ]);
168
173
  return n ? /* @__PURE__ */ S(b, { children: [/* @__PURE__ */ x("div", {
169
- onClick: R,
174
+ onClick: z,
170
175
  style: {
171
176
  position: "fixed",
172
177
  inset: 0,
@@ -176,14 +181,14 @@ function j({ open: n, onOpenChange: c, action: u, actionName: d, onSubmit: C, is
176
181
  }
177
182
  }), /* @__PURE__ */ S("div", {
178
183
  "data-testid": "action-dialog",
179
- ref: z,
184
+ ref: B,
180
185
  role: "dialog",
181
186
  "aria-modal": "true",
182
- "aria-busy": E,
187
+ "aria-busy": D,
183
188
  "aria-label": d,
184
189
  tabIndex: -1,
185
190
  onKeyDown: (e) => {
186
- e.key === "Escape" && R();
191
+ e.key === "Escape" && z();
187
192
  },
188
193
  style: {
189
194
  position: "fixed",
@@ -218,14 +223,14 @@ function j({ open: n, onOpenChange: c, action: u, actionName: d, onSubmit: C, is
218
223
  width: 28,
219
224
  height: 28,
220
225
  borderRadius: "var(--radius-md)",
221
- background: I ? "var(--danger-soft)" : "var(--accent-soft)",
222
- color: I ? "var(--danger)" : "var(--accent)",
226
+ background: L ? "var(--danger-soft)" : "var(--accent-soft)",
227
+ color: L ? "var(--danger)" : "var(--accent)",
223
228
  display: "inline-flex",
224
229
  alignItems: "center",
225
230
  justifyContent: "center",
226
231
  flexShrink: 0
227
232
  },
228
- children: x(I ? r.trash : r.bolt, { size: 15 })
233
+ children: x(L ? r.trash : r.bolt, { size: 15 })
229
234
  }),
230
235
  /* @__PURE__ */ S("div", {
231
236
  style: {
@@ -245,12 +250,12 @@ function j({ open: n, onOpenChange: c, action: u, actionName: d, onSubmit: C, is
245
250
  color: "var(--text-3)",
246
251
  marginTop: 2
247
252
  },
248
- children: M(u.display?.description) || (B.length > 0 ? M("action.dialog.params_hint", "Fill in the parameters below to execute this action.") : "")
253
+ children: N(u.display?.description) || (V.length > 0 ? N("action.dialog.params_hint", "Fill in the parameters below to execute this action.") : "")
249
254
  })]
250
255
  }),
251
256
  /* @__PURE__ */ x(i, {
252
257
  icon: /* @__PURE__ */ x(r.x, { size: 14 }),
253
- onClick: R
258
+ onClick: z
254
259
  })
255
260
  ]
256
261
  }),
@@ -264,19 +269,19 @@ function j({ open: n, onOpenChange: c, action: u, actionName: d, onSubmit: C, is
264
269
  minWidth: 0,
265
270
  minHeight: 0
266
271
  },
267
- children: [L && /* @__PURE__ */ x("div", {
272
+ children: [R && /* @__PURE__ */ x("div", {
268
273
  style: {
269
274
  fontSize: 12.5,
270
275
  lineHeight: 1.5,
271
276
  color: "var(--text-2)",
272
- background: I ? "var(--danger-soft)" : "var(--surface-2)",
277
+ background: L ? "var(--danger-soft)" : "var(--surface-2)",
273
278
  border: "1px solid var(--divider)",
274
279
  borderRadius: "var(--radius-md)",
275
280
  padding: "10px 12px"
276
281
  },
277
- children: L
282
+ children: R
278
283
  }), /* @__PURE__ */ x("fieldset", {
279
- disabled: E,
284
+ disabled: D,
280
285
  style: {
281
286
  border: 0,
282
287
  margin: 0,
@@ -285,45 +290,45 @@ function j({ open: n, onOpenChange: c, action: u, actionName: d, onSubmit: C, is
285
290
  display: "flex",
286
291
  flexDirection: "column",
287
292
  gap: 12,
288
- pointerEvents: E ? "none" : void 0,
289
- opacity: E ? .6 : 1
293
+ pointerEvents: D ? "none" : void 0,
294
+ opacity: D ? .6 : 1
290
295
  },
291
- children: B.map(([e, n]) => {
292
- let r = M(n.display?.name) || e;
296
+ children: V.map(([e, n]) => {
297
+ let r = N(n.display?.name) || e;
293
298
  if (n.type === "id_array") return null;
294
299
  let i;
295
300
  if (n.type === "entity_patch") {
296
301
  let t = typeof n.filter?.targets == "string" ? n.filter.targets : void 0;
297
302
  i = /* @__PURE__ */ x(f, {
298
- entity: H,
303
+ entity: U,
299
304
  filterTargets: t,
300
- selectedRows: j,
301
- value: K[e] ?? {},
302
- onChange: (t) => J(e, t)
305
+ selectedRows: M,
306
+ value: q[e] ?? {},
307
+ onChange: (t) => Y(e, t)
303
308
  });
304
- } else if (n.type === "status_group") i = /* @__PURE__ */ x(k, {
309
+ } else if (n.type === "status_group") i = /* @__PURE__ */ x(A, {
305
310
  param: n,
306
- value: K[e],
307
- onChange: (t) => J(e, t),
308
- statusGroups: V,
309
- formData: K
311
+ value: q[e],
312
+ onChange: (t) => Y(e, t),
313
+ statusGroups: H,
314
+ formData: q
310
315
  });
311
- else if (n.type === "status") i = /* @__PURE__ */ x(A, {
316
+ else if (n.type === "status") i = /* @__PURE__ */ x(j, {
312
317
  param: n,
313
- value: K[e],
314
- onChange: (t) => J(e, t),
315
- statusGroups: V,
316
- formData: K
318
+ value: q[e],
319
+ onChange: (t) => Y(e, t),
320
+ statusGroups: H,
321
+ formData: q
317
322
  });
318
323
  else {
319
- let t = T(n);
324
+ let t = E(n);
320
325
  i = o({
321
326
  field: t,
322
327
  fieldName: e,
323
- value: K[e],
328
+ value: q[e],
324
329
  mode: "edit",
325
- onChange: (t) => J(e, t),
326
- t: M
330
+ onChange: (t) => Y(e, t),
331
+ t: N
327
332
  });
328
333
  }
329
334
  return /* @__PURE__ */ S("div", {
@@ -341,7 +346,7 @@ function j({ open: n, onOpenChange: c, action: u, actionName: d, onSubmit: C, is
341
346
  marginTop: 4,
342
347
  marginBottom: 0
343
348
  },
344
- children: M(n.display.description)
349
+ children: N(n.display.description)
345
350
  })
346
351
  ]
347
352
  }, e);
@@ -363,21 +368,21 @@ function j({ open: n, onOpenChange: c, action: u, actionName: d, onSubmit: C, is
363
368
  children: [
364
369
  /* @__PURE__ */ x("div", { style: { flex: 1 } }),
365
370
  /* @__PURE__ */ x(e, {
366
- onClick: R,
367
- disabled: E,
368
- children: M("dialog.cancel", "Cancel")
371
+ onClick: z,
372
+ disabled: D,
373
+ children: N("dialog.cancel", "Cancel")
369
374
  }),
370
375
  /* @__PURE__ */ x(e, {
371
376
  kind: "primary",
372
- danger: I,
373
- icon: x(E ? a : I ? r.trash : r.bolt, { size: 13 }),
374
- onClick: Y,
375
- disabled: E,
376
- children: E ? M("action.dialog.working", "Working…") : d || M("dialog.confirm", "Confirm")
377
+ danger: L,
378
+ icon: x(D ? a : L ? r.trash : r.bolt, { size: 13 }),
379
+ onClick: X,
380
+ disabled: D,
381
+ children: D ? N("action.dialog.working", "Working…") : d || N("dialog.confirm", "Confirm")
377
382
  })
378
383
  ]
379
384
  })
380
385
  ]
381
386
  })] }) : null;
382
387
  }
383
- export { j as ActionDialog };
388
+ export { M as ActionDialog };
@@ -121,7 +121,9 @@ function F({ children: r }) {
121
121
  };
122
122
  switch (a.kind) {
123
123
  case "success": {
124
- let i = k(o), a = i ? { action: {
124
+ let i = k(o);
125
+ if (!r && !i && O(o)) return;
126
+ let a = i ? { action: {
125
127
  label: l("action.result.download", "Download"),
126
128
  onClick: () => {
127
129
  n(u, i.url, i.filename).catch((e) => {
@@ -14,12 +14,16 @@ function a(e) {
14
14
  }
15
15
  function o({ value: o, onChange: s, readOnly: c, id: l }) {
16
16
  let u = t(null), d = t(null), f = t(s);
17
- return e(() => {
17
+ e(() => {
18
18
  f.current = s;
19
- }, [s]), e(() => {
19
+ }, [s]);
20
+ let p = t(o);
21
+ return e(() => {
22
+ p.current = o;
23
+ }, [o]), e(() => {
20
24
  if (!u.current) return;
21
25
  let e = {
22
- content: a(o),
26
+ content: a(p.current),
23
27
  readOnly: c ?? !1,
24
28
  mode: c ? r.tree : r.text,
25
29
  mainMenuBar: !c,
@@ -45,12 +49,12 @@ function o({ value: o, onChange: s, readOnly: c, id: l }) {
45
49
  attributes: !0,
46
50
  attributeFilter: ["data-color-scheme"]
47
51
  });
48
- let s = i({
52
+ let o = i({
49
53
  target: u.current,
50
54
  props: e
51
55
  });
52
- return d.current = s, () => {
53
- n.disconnect(), s.destroy(), d.current = null;
56
+ return d.current = o, () => {
57
+ n.disconnect(), o.destroy(), d.current = null;
54
58
  };
55
59
  }, [c]), e(() => {
56
60
  d.current && c && d.current.updateProps({ content: a(o) });