@declarion/react 0.255.0 → 0.307.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.
@@ -1,58 +1,58 @@
1
1
  import { renderSchemaField as e, resolveSchemaFieldLabel as t } from "../file-widgets/host.js";
2
- import { Pill as n } from "../primitives/Pill.js";
3
- import { HighlightsStrip as r } from "../chrome/HighlightsStrip.js";
4
- import { CopyButton as i } from "../shared/CopyButton.js";
5
- import { copyableValue as a } from "./FieldRow.js";
6
- import { useText as o } from "../../hooks/useText.js";
7
- import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
2
+ import { Pill as n, pillColor as r } from "../primitives/Pill.js";
3
+ import { HighlightsStrip as i } from "../chrome/HighlightsStrip.js";
4
+ import { CopyButton as a } from "../shared/CopyButton.js";
5
+ import { copyableValue as o } from "./FieldRow.js";
6
+ import { useText as s } from "../../hooks/useText.js";
7
+ import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
8
8
  // src/components/detail-layout/DetailHighlights.tsx
9
- function u(e, t) {
9
+ function d(e, t) {
10
10
  return new Set((e.highlights ?? []).filter((e) => t.fields.get(e) || t.files?.get(e)));
11
11
  }
12
- function d({ screen: u, entity: d, entityCode: f, record: p, refs: m, objectStatuses: h, schema: g }) {
13
- let _ = o(), v = u.highlights;
14
- if (!v || v.length === 0) return null;
15
- let y = [];
16
- for (let r of v) {
17
- let o = d.status_groups?.[r];
18
- if (o) {
19
- let e = h?.find((e) => e.group_code === r), t = e ? o.statuses.find((t) => t.code === e.status_code) : void 0;
20
- y.push({
21
- code: r,
22
- label: _(o.name),
23
- value: t ? /* @__PURE__ */ c(n, {
24
- tone: t.color ?? "slate",
12
+ function f({ screen: d, entity: f, entityCode: p, record: m, refs: h, objectStatuses: g, schema: _ }) {
13
+ let v = s(), y = d.highlights;
14
+ if (!y || y.length === 0) return null;
15
+ let b = [];
16
+ for (let i of y) {
17
+ let s = f.status_groups?.[i];
18
+ if (s) {
19
+ let e = g?.find((e) => e.group_code === i), t = e ? s.statuses.find((t) => t.code === e.status_code) : void 0;
20
+ b.push({
21
+ code: i,
22
+ label: v(s.name),
23
+ value: t ? /* @__PURE__ */ l(n, {
24
+ tone: r(t.color),
25
25
  size: "xs",
26
- children: _(t.name)
27
- }) : /* @__PURE__ */ c("span", {
26
+ children: v(t.name)
27
+ }) : /* @__PURE__ */ l("span", {
28
28
  style: { color: "var(--text-4)" },
29
29
  children: "—"
30
30
  })
31
31
  });
32
- } else if (d.fields.get(r) || d.files?.get(r)) {
32
+ } else if (f.fields.get(i) || f.files?.get(i)) {
33
33
  let n = e({
34
- entity: d,
35
- entityCode: f,
36
- fieldName: r,
37
- record: p,
34
+ entity: f,
35
+ entityCode: p,
36
+ fieldName: i,
37
+ record: m,
38
38
  mode: "display",
39
- refs: m,
40
- entities: g.entities,
41
- screens: g.screens,
39
+ refs: h,
40
+ entities: _.entities,
41
+ screens: _.screens,
42
42
  surface: "list",
43
- t: _
44
- }), o = a(d.fields.get(r), p[r]);
45
- y.push({
46
- code: r,
47
- label: t(_, d, r, g.entities),
48
- value: o ? /* @__PURE__ */ l(s, { children: [n, /* @__PURE__ */ c(i, {
49
- value: o,
43
+ t: v
44
+ }), r = o(f.fields.get(i), m[i]);
45
+ b.push({
46
+ code: i,
47
+ label: t(v, f, i, _.entities),
48
+ value: r ? /* @__PURE__ */ u(c, { children: [n, /* @__PURE__ */ l(a, {
49
+ value: r,
50
50
  size: "sm",
51
- title: _("record.field.copy_value", "Copy value")
51
+ title: v("record.field.copy_value", "Copy value")
52
52
  })] }) : n
53
53
  });
54
54
  }
55
55
  }
56
- return y.length === 0 ? null : /* @__PURE__ */ c(r, { items: y });
56
+ return b.length === 0 ? null : /* @__PURE__ */ l(i, { items: b });
57
57
  }
58
- export { d as DetailHighlights, u as highlightedFieldCodes };
58
+ export { f as DetailHighlights, d as highlightedFieldCodes };
@@ -1,32 +1,33 @@
1
1
  import { createEntity as e } from "../../api/data.js";
2
2
  import { buildQuickAddPayload as t, isQuickAddReady as n } from "../../lib/quick-add.js";
3
- import { ENTITY_CHILDREN_KEY as r } from "../../hooks/useChildrenData.js";
4
- import { pkValuePartsToId as i } from "../../types/schema.js";
5
- import { formatWireDateTime as a } from "../../lib/timestamp.js";
6
- import { useState as o } from "react";
7
- import { useMutation as s, useQueryClient as c } from "@tanstack/react-query";
3
+ import { withFillFrom as r } from "../../lib/fill-from.js";
4
+ import { ENTITY_CHILDREN_KEY as i } from "../../hooks/useChildrenData.js";
5
+ import { pkValuePartsToId as a } from "../../types/schema.js";
6
+ import { formatWireDateTime as o } from "../../lib/timestamp.js";
7
+ import { useRef as s, useState as c } from "react";
8
+ import { useMutation as l, useQueryClient as u } from "@tanstack/react-query";
8
9
  // src/components/detail-layout/useQuickAdd.ts
9
- function l(l, u, d, f) {
10
- let [p, m] = o(() => {
11
- let e = l.quick_add, t = f.entities[l.entity], n = {};
12
- if (e?.fields) for (let r of e.fields) e.defaults?.[r] == null ? t?.fields.get(r)?.type === "timestamp" && (n[r] = a()) : n[r] = e.defaults[r];
10
+ function d(d, f, p, m) {
11
+ let h = s(/* @__PURE__ */ new Set()), [g, _] = c(() => {
12
+ let e = d.quick_add, t = m.entities[d.entity], n = {};
13
+ if (e?.fields) for (let r of e.fields) e.defaults?.[r] == null ? t?.fields.get(r)?.type === "timestamp" && (n[r] = o()) : n[r] = e.defaults[r];
13
14
  return n;
14
- }), h = c(), { mutate: g, isPending: _, error: v, reset: y } = s({
15
- mutationFn: (t) => e(l.entity, t),
15
+ }), v = u(), { mutate: y, isPending: b, error: x, reset: S } = l({
16
+ mutationFn: (t) => e(d.entity, t),
16
17
  onMutate: async (e) => {
17
- let t = Array.isArray(d) ? i(d.map(String)) : d, n = [
18
- r,
19
- u,
18
+ let t = Array.isArray(p) ? a(p.map(String)) : p, n = [
19
+ i,
20
+ f,
20
21
  t,
21
- l.entity
22
+ d.entity
22
23
  ];
23
- await h.cancelQueries({ queryKey: n });
24
- let a = h.getQueriesData({ queryKey: n }), o = {
24
+ await v.cancelQueries({ queryKey: n });
25
+ let r = v.getQueriesData({ queryKey: n }), o = {
25
26
  ...e,
26
27
  id: `__optimistic_${crypto.randomUUID()}`,
27
28
  __optimistic: !0
28
29
  };
29
- return h.setQueriesData({ queryKey: n }, (e) => {
30
+ return v.setQueriesData({ queryKey: n }, (e) => {
30
31
  if (!e || typeof e != "object") return e;
31
32
  if ("pages" in e && Array.isArray(e.pages) && e.pages.length > 0) {
32
33
  let t = e, [n, ...r] = t.pages;
@@ -39,46 +40,43 @@ function l(l, u, d, f) {
39
40
  };
40
41
  }
41
42
  return e;
42
- }), { snapshots: a };
43
+ }), { snapshots: r };
43
44
  },
44
45
  onError: (e, t, n) => {
45
- if (n?.snapshots) for (let [e, t] of n.snapshots) h.setQueryData(e, t);
46
+ if (n?.snapshots) for (let [e, t] of n.snapshots) v.setQueryData(e, t);
46
47
  },
47
48
  onSuccess: () => {
48
- let e = l.quick_add, t = f.entities[l.entity], n = {};
49
- if (e?.fields) for (let r of e.fields) n[r] = e?.defaults?.[r] == null ? t?.fields.get(r)?.type === "timestamp" ? a() : "" : e.defaults[r];
50
- m(n);
49
+ let e = d.quick_add, t = m.entities[d.entity], n = {};
50
+ if (e?.fields) for (let r of e.fields) n[r] = e?.defaults?.[r] == null ? t?.fields.get(r)?.type === "timestamp" ? o() : "" : e.defaults[r];
51
+ _(n);
51
52
  },
52
53
  onSettled: () => {
53
- let e = Array.isArray(d) ? i(d.map(String)) : d;
54
- h.invalidateQueries({ queryKey: [
55
- r,
56
- u,
54
+ let e = Array.isArray(p) ? a(p.map(String)) : p;
55
+ v.invalidateQueries({ queryKey: [
56
+ i,
57
+ f,
57
58
  e,
58
- l.entity
59
+ d.entity
59
60
  ] });
60
61
  }
61
- }), b = l.quick_add, x = f.entities[l.entity], S = b?.fields.filter((e) => x?.fields.get(e)?.required && !x?.fields.get(e)?.generate) ?? [], C = n(p, S);
62
- function w(e) {
63
- if (e.preventDefault(), !b) return;
64
- let n = t(p, b.defaults, l.foreign_key, d);
65
- g(n);
62
+ }), C = d.quick_add, w = m.entities[d.entity], T = C?.fields.filter((e) => w?.fields.get(e)?.required && !w?.fields.get(e)?.generate) ?? [], E = n(g, T);
63
+ function D(e) {
64
+ if (e.preventDefault(), !C) return;
65
+ let n = t(g, C.defaults, d.foreign_key, p);
66
+ y(n);
66
67
  }
67
- function T(e, t) {
68
- v && y(), m((n) => ({
69
- ...n,
70
- [e]: t
71
- }));
68
+ function O(e, t) {
69
+ x && S(), _((n) => r(w ?? void 0, n, e, t, h.current));
72
70
  }
73
71
  return {
74
- values: p,
75
- quickAdd: b,
76
- childEntity: x,
77
- isPending: _,
78
- error: v,
79
- isReady: C,
80
- handleSubmit: w,
81
- handleFieldChange: T
72
+ values: g,
73
+ quickAdd: C,
74
+ childEntity: w,
75
+ isPending: b,
76
+ error: x,
77
+ isReady: E,
78
+ handleSubmit: D,
79
+ handleFieldChange: O
82
80
  };
83
81
  }
84
- export { l as useQuickAdd };
82
+ export { d as useQuickAdd };
@@ -1,37 +1,37 @@
1
- import { Pill as e } from "../primitives/Pill.js";
2
- import { Select as t } from "../primitives/Fields.js";
3
- import { coerceDisplayString as n } from "../../lib/display-value.js";
4
- import { jsx as r } from "react/jsx-runtime";
1
+ import { Pill as e, pillColor as t } from "../primitives/Pill.js";
2
+ import { Select as n } from "../primitives/Fields.js";
3
+ import { coerceDisplayString as r } from "../../lib/display-value.js";
4
+ import { jsx as i } from "react/jsx-runtime";
5
5
  // src/components/fields/EnumField.tsx
6
- var i = "__declarion_enum_null__";
7
- function a({ field: a, value: o, mode: s, onChange: c, fieldId: l, labelId: u, t: d }) {
8
- let f = a.values ?? [], p = f.find((e) => e.code === o);
9
- if (s === "display") return p ? /* @__PURE__ */ r(e, {
10
- tone: p.color ?? "slate",
6
+ var a = "__declarion_enum_null__";
7
+ function o({ field: o, value: s, mode: c, onChange: l, fieldId: u, labelId: d, t: f }) {
8
+ let p = o.values ?? [], m = p.find((e) => e.code === s);
9
+ if (c === "display") return m ? /* @__PURE__ */ i(e, {
10
+ tone: t(m.color),
11
11
  size: "xs",
12
- children: d(p.name)
13
- }) : /* @__PURE__ */ r("span", {
12
+ children: f(m.name)
13
+ }) : /* @__PURE__ */ i("span", {
14
14
  style: {
15
15
  fontSize: 12.5,
16
16
  color: "var(--text-4)"
17
17
  },
18
18
  children: "—"
19
19
  });
20
- let m = !a.required, h = o != null && o !== "" ? n(o) : i, g = [...m ? [{
21
- value: i,
22
- label: d("field.enum.none", "— None —")
23
- }] : [], ...f.map((e) => ({
20
+ let h = !o.required, g = s != null && s !== "" ? r(s) : a, _ = [...h ? [{
21
+ value: a,
22
+ label: f("field.enum.none", "— None —")
23
+ }] : [], ...p.map((e) => ({
24
24
  value: e.code,
25
- label: d(e.name) || e.code
25
+ label: f(e.name) || e.code
26
26
  }))];
27
- return /* @__PURE__ */ r(t, {
28
- id: l,
29
- "aria-labelledby": u,
30
- "aria-required": a.required || void 0,
31
- value: h,
32
- options: g,
33
- onChange: (e) => c?.(e === i ? null : e),
34
- placeholder: d("field.select_placeholder", "Select…")
27
+ return /* @__PURE__ */ i(n, {
28
+ id: u,
29
+ "aria-labelledby": d,
30
+ "aria-required": o.required || void 0,
31
+ value: g,
32
+ options: _,
33
+ onChange: (e) => l?.(e === a ? null : e),
34
+ placeholder: f("field.select_placeholder", "Select…")
35
35
  });
36
36
  }
37
- export { a as EnumField };
37
+ export { o as EnumField };
@@ -1,41 +1,28 @@
1
- import { Pill as e } from "../../../primitives/Pill.js";
2
- import { coerceDisplayString as t } from "../../../../lib/display-value.js";
3
- import { jsx as n } from "react/jsx-runtime";
1
+ import { Pill as e, pillColor as t } from "../../../primitives/Pill.js";
2
+ import { coerceDisplayString as n } from "../../../../lib/display-value.js";
3
+ import { jsx as r } from "react/jsx-runtime";
4
4
  // src/components/fields/cells/factories/badge.tsx
5
- var r = /* @__PURE__ */ new Set([
6
- "indigo",
7
- "emerald",
8
- "amber",
9
- "rose",
10
- "sky",
11
- "violet",
12
- "slate",
13
- "teal"
14
- ]);
15
- function i(e) {
16
- return e && r.has(e) ? e : "slate";
17
- }
18
- var a = (r) => {
19
- let { field: a, t: o } = r, s = /* @__PURE__ */ new Map();
5
+ var i = (i) => {
6
+ let { field: a, t: o } = i, s = /* @__PURE__ */ new Map();
20
7
  if (a.values) for (let e of a.values) s.set(e.code, {
21
- tone: i(e.color),
8
+ tone: t(e.color),
22
9
  label: o(e.name) || e.code
23
10
  });
24
- if (a.display?.value_map) for (let [e, t] of Object.entries(a.display.value_map)) {
25
- let n = s.get(e), r = t.color ? i(t.color) : n?.tone ?? "slate", a = (t.label ? o(t.label) : "") || n?.label || e;
11
+ if (a.display?.value_map) for (let [e, n] of Object.entries(a.display.value_map)) {
12
+ let r = s.get(e), i = n.color ? t(n.color) : r?.tone ?? "slate", a = (n.label ? o(n.label) : "") || r?.label || e;
26
13
  s.set(e, {
27
- tone: r,
14
+ tone: i,
28
15
  label: a
29
16
  });
30
17
  }
31
- return (r) => {
32
- if (r == null || r === "") return "—";
33
- let i = t(r), a = s.get(i);
34
- return /* @__PURE__ */ n(e, {
18
+ return (t) => {
19
+ if (t == null || t === "") return "—";
20
+ let i = n(t), a = s.get(i);
21
+ return /* @__PURE__ */ r(e, {
35
22
  tone: a?.tone ?? "slate",
36
23
  size: "xs",
37
24
  children: a?.label ?? i
38
25
  });
39
26
  };
40
27
  };
41
- export { a as badgeFactory };
28
+ export { i as badgeFactory };
@@ -1,34 +1,21 @@
1
- import { Pill as e } from "../../../primitives/Pill.js";
2
- import { coerceDisplayString as t } from "../../../../lib/display-value.js";
3
- import { jsx as n } from "react/jsx-runtime";
1
+ import { Pill as e, pillColor as t } from "../../../primitives/Pill.js";
2
+ import { coerceDisplayString as n } from "../../../../lib/display-value.js";
3
+ import { jsx as r } from "react/jsx-runtime";
4
4
  // src/components/fields/cells/factories/statusPill.tsx
5
- var r = /* @__PURE__ */ new Set([
6
- "indigo",
7
- "emerald",
8
- "amber",
9
- "rose",
10
- "sky",
11
- "violet",
12
- "slate",
13
- "teal"
14
- ]);
15
- function i(e) {
16
- return e && r.has(e) ? e : "slate";
17
- }
18
- var a = (r) => {
19
- let { entity: a, t: o } = r, s = /* @__PURE__ */ new Map();
20
- if (a?.status_groups) for (let e of Object.values(a.status_groups)) for (let t of e.statuses) s.set(t.code, {
21
- tone: i(t.color),
22
- label: o(t.name) || t.code
5
+ var i = (i) => {
6
+ let { entity: a, t: o } = i, s = /* @__PURE__ */ new Map();
7
+ if (a?.status_groups) for (let e of Object.values(a.status_groups)) for (let n of e.statuses) s.set(n.code, {
8
+ tone: t(n.color),
9
+ label: o(n.name) || n.code
23
10
  });
24
- return (r) => {
25
- if (r == null || r === "") return "—";
26
- let i = t(r), a = s.get(i);
27
- return /* @__PURE__ */ n(e, {
11
+ return (t) => {
12
+ if (t == null || t === "") return "—";
13
+ let i = n(t), a = s.get(i);
14
+ return /* @__PURE__ */ r(e, {
28
15
  tone: a?.tone ?? "slate",
29
16
  size: "xs",
30
17
  children: a?.label ?? i
31
18
  });
32
19
  };
33
20
  };
34
- export { a as statusPillFactory };
21
+ export { i as statusPillFactory };
@@ -1,43 +1,30 @@
1
1
  import { Chip as e } from "../../../primitives/Chip.js";
2
- import { Pill as t } from "../../../primitives/Pill.js";
3
- import { parseLangMap as n } from "../../langMap.js";
4
- import { jsx as r } from "react/jsx-runtime";
2
+ import { Pill as t, pillColor as n } from "../../../primitives/Pill.js";
3
+ import { parseLangMap as r } from "../../langMap.js";
4
+ import { jsx as i } from "react/jsx-runtime";
5
5
  // src/components/fields/cells/factories/tagList.tsx
6
- var i = /* @__PURE__ */ new Set([
7
- "indigo",
8
- "emerald",
9
- "amber",
10
- "rose",
11
- "sky",
12
- "violet",
13
- "slate",
14
- "teal"
15
- ]);
16
- function a(e) {
17
- return e && i.has(e) ? e : null;
18
- }
19
- var o = (i) => {
20
- let { field: o, t: s } = i, c = /* @__PURE__ */ new Map();
6
+ var a = (a) => {
7
+ let { field: o, t: s } = a, c = /* @__PURE__ */ new Map();
21
8
  if (o.display?.value_map) for (let [e, t] of Object.entries(o.display.value_map)) c.set(e, {
22
9
  label: t.label && s(t.label) || e,
23
- tone: a(t.color)
10
+ tone: t.color ? n(t.color) : null
24
11
  });
25
12
  let l = o.type === "multilang_array";
26
- return (i) => !Array.isArray(i) || i.length === 0 ? "—" : /* @__PURE__ */ r("span", {
13
+ return (n) => !Array.isArray(n) || n.length === 0 ? "—" : /* @__PURE__ */ i("span", {
27
14
  style: {
28
15
  display: "inline-flex",
29
16
  gap: 4,
30
17
  flexWrap: "wrap"
31
18
  },
32
- children: i.map((i, a) => {
33
- if (l) return /* @__PURE__ */ r(e, { children: s(n(i)) || "—" }, a);
34
- let o = String(i), u = c.get(o);
35
- return u?.tone ? /* @__PURE__ */ r(t, {
19
+ children: n.map((n, a) => {
20
+ if (l) return /* @__PURE__ */ i(e, { children: s(r(n)) || "—" }, a);
21
+ let o = String(n), u = c.get(o);
22
+ return u?.tone ? /* @__PURE__ */ i(t, {
36
23
  tone: u.tone,
37
24
  size: "xs",
38
25
  children: u.label
39
- }, `${o}-${a}`) : /* @__PURE__ */ r(e, { children: u?.label ?? o }, `${o}-${a}`);
26
+ }, `${o}-${a}`) : /* @__PURE__ */ i(e, { children: u?.label ?? o }, `${o}-${a}`);
40
27
  })
41
28
  });
42
29
  };
43
- export { o as tagListFactory };
30
+ export { a as tagListFactory };