@declarion/react 0.250.0 → 0.252.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.
@@ -6,7 +6,16 @@ function i({ header: i, children: a, scrollRef: o }) {
6
6
  let s = e(), c = s.isPhone ? t(12) : {
7
7
  paddingLeft: "24px",
8
8
  paddingRight: "24px"
9
- };
9
+ }, l = /* @__PURE__ */ n("div", {
10
+ "data-testid": "page-shell-header",
11
+ style: {
12
+ flexShrink: 0,
13
+ paddingTop: s.isPhone ? 14 : 24,
14
+ paddingBottom: 8,
15
+ ...c
16
+ },
17
+ children: i
18
+ });
10
19
  return /* @__PURE__ */ r("div", {
11
20
  style: {
12
21
  height: "100%",
@@ -15,36 +24,33 @@ function i({ header: i, children: a, scrollRef: o }) {
15
24
  overflow: "hidden",
16
25
  background: "var(--background)"
17
26
  },
18
- children: [/* @__PURE__ */ n("div", {
19
- "data-testid": "page-shell-header",
20
- style: {
21
- flexShrink: 0,
22
- paddingTop: s.isPhone ? 14 : 24,
23
- paddingBottom: 8,
24
- ...c
25
- },
26
- children: i
27
- }), /* @__PURE__ */ n("div", {
27
+ children: [!s.isPhone && l, /* @__PURE__ */ r("div", {
28
28
  ref: o,
29
+ "data-testid": "page-shell-scroll",
29
30
  style: {
30
31
  flex: 1,
31
32
  minHeight: 0,
32
33
  overflowY: "auto",
33
- paddingTop: 4,
34
- paddingBottom: "calc(24px + var(--safe-area-bottom))",
35
- ...c,
36
34
  minWidth: 0,
37
35
  WebkitOverflowScrolling: "touch"
38
36
  },
39
- children: /* @__PURE__ */ n("div", {
37
+ children: [s.isPhone && l, /* @__PURE__ */ n("div", {
40
38
  style: {
41
- display: "flex",
42
- flexDirection: "column",
43
- gap: 16,
39
+ paddingTop: 4,
40
+ paddingBottom: "calc(24px + var(--safe-area-bottom))",
41
+ ...c,
44
42
  minWidth: 0
45
43
  },
46
- children: a
47
- })
44
+ children: /* @__PURE__ */ n("div", {
45
+ style: {
46
+ display: "flex",
47
+ flexDirection: "column",
48
+ gap: 16,
49
+ minWidth: 0
50
+ },
51
+ children: a
52
+ })
53
+ })]
48
54
  })]
49
55
  });
50
56
  }
@@ -1,28 +1,32 @@
1
- import { Suspense as e, lazy as t } from "react";
2
- import { jsx as n } from "react/jsx-runtime";
1
+ import { IconBtn as e } from "../primitives/IconBtn.js";
2
+ import { Icon as t } from "../primitives/Icons.js";
3
+ import { useText as n } from "../../hooks/useText.js";
4
+ import { coerceDisplayString as r } from "../../lib/display-value.js";
5
+ import { Suspense as i, lazy as a, useState as o } from "react";
6
+ import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
3
7
  // src/components/fields/JsonField.tsx
4
- var r = t(() => import("./JsonEditor.js").then((e) => ({ default: e.JsonEditor })));
5
- function i() {
6
- return /* @__PURE__ */ n("div", { className: "h-20 rounded-md border border-border bg-muted animate-pulse" });
8
+ var u = a(() => import("./JsonEditor.js").then((e) => ({ default: e.JsonEditor })));
9
+ function d() {
10
+ return /* @__PURE__ */ c("div", { className: "h-20 rounded-md border border-border bg-muted animate-pulse" });
7
11
  }
8
- function a(e) {
12
+ function f(e) {
9
13
  return e == null ? !0 : typeof e == "string" ? e.trim() === "" : Array.isArray(e) ? e.length === 0 : typeof e == "object" && Object.keys(e).length === 0;
10
14
  }
11
- function o(e) {
15
+ function p(e) {
12
16
  return Array.isArray(e) && e.every((e) => [
13
17
  "string",
14
18
  "number",
15
19
  "boolean"
16
20
  ].includes(typeof e));
17
21
  }
18
- function s({ value: t, mode: s, onChange: c, fieldId: l }) {
19
- return s === "display" ? a(t) ? /* @__PURE__ */ n("span", {
22
+ function m({ value: e, mode: t, onChange: n, fieldId: r }) {
23
+ return t === "display" ? f(e) ? /* @__PURE__ */ c("span", {
20
24
  style: {
21
25
  fontSize: 12.5,
22
26
  color: "var(--text-4)"
23
27
  },
24
28
  children: "—"
25
- }) : o(t) ? /* @__PURE__ */ n("ul", {
29
+ }) : p(e) ? /* @__PURE__ */ c("ul", {
26
30
  className: "mono",
27
31
  style: {
28
32
  margin: 0,
@@ -31,20 +35,101 @@ function s({ value: t, mode: s, onChange: c, fieldId: l }) {
31
35
  fontSize: 12.5,
32
36
  lineHeight: 1.7
33
37
  },
34
- children: t.map((e, t) => /* @__PURE__ */ n("li", { children: String(e) }, t))
35
- }) : /* @__PURE__ */ n(e, {
36
- fallback: /* @__PURE__ */ n(i, {}),
37
- children: /* @__PURE__ */ n(r, {
38
- value: t,
39
- readOnly: !0
40
- })
41
- }) : /* @__PURE__ */ n(e, {
42
- fallback: /* @__PURE__ */ n(i, {}),
43
- children: /* @__PURE__ */ n(r, {
44
- value: t,
45
- onChange: c,
46
- id: l
38
+ children: e.map((e, t) => /* @__PURE__ */ c("li", { children: String(e) }, t))
39
+ }) : /* @__PURE__ */ c(S, { value: e }) : /* @__PURE__ */ c(i, {
40
+ fallback: /* @__PURE__ */ c(d, {}),
41
+ children: /* @__PURE__ */ c(u, {
42
+ value: e,
43
+ onChange: n,
44
+ id: r
47
45
  })
48
46
  });
49
47
  }
50
- export { s as JsonField, a as isEmptyJsonValue };
48
+ var h = {
49
+ position: "relative",
50
+ border: "1px solid var(--border)",
51
+ borderRadius: "var(--radius-md)",
52
+ padding: 12,
53
+ background: "var(--surface-2)"
54
+ }, g = {
55
+ display: "flex",
56
+ flexDirection: "column",
57
+ gap: 8
58
+ }, _ = {
59
+ display: "flex",
60
+ flexWrap: "wrap",
61
+ alignItems: "baseline",
62
+ gap: 8
63
+ }, v = {
64
+ fontSize: 11.5,
65
+ fontWeight: 500,
66
+ color: "var(--text-3)",
67
+ width: 120,
68
+ flexShrink: 0,
69
+ overflowWrap: "anywhere"
70
+ }, y = {
71
+ ...g,
72
+ paddingLeft: 10,
73
+ borderLeft: "2px solid var(--border)"
74
+ }, b = {
75
+ minWidth: 0,
76
+ flex: "1 1 14rem",
77
+ fontSize: 12.5,
78
+ overflowWrap: "anywhere"
79
+ }, x = {
80
+ position: "absolute",
81
+ top: 6,
82
+ right: 6
83
+ };
84
+ function S({ value: r }) {
85
+ let a = n(), [s, f] = o(!1), p = s ? a("field.json.hide_source", "Hide JSON") : a("field.json.show_source", "Show JSON");
86
+ return /* @__PURE__ */ l("div", {
87
+ style: h,
88
+ children: [/* @__PURE__ */ c("div", {
89
+ style: x,
90
+ children: /* @__PURE__ */ c(e, {
91
+ size: 22,
92
+ icon: /* @__PURE__ */ c(t.code, { size: 13 }),
93
+ onClick: () => f((e) => !e),
94
+ title: p,
95
+ "aria-label": p,
96
+ "aria-pressed": s
97
+ })
98
+ }), s ? /* @__PURE__ */ c(i, {
99
+ fallback: /* @__PURE__ */ c(d, {}),
100
+ children: /* @__PURE__ */ c(u, {
101
+ value: r,
102
+ readOnly: !0
103
+ })
104
+ }) : /* @__PURE__ */ c(w, { value: r })]
105
+ });
106
+ }
107
+ function C({ value: e, nested: t }) {
108
+ let n = Array.isArray(e) ? e.map((e, t) => [String(t + 1), e]) : Object.entries(e);
109
+ return /* @__PURE__ */ c("div", {
110
+ style: t ? y : g,
111
+ children: n.map(([e, t]) => /* @__PURE__ */ l("div", {
112
+ style: _,
113
+ children: [/* @__PURE__ */ c("span", {
114
+ style: v,
115
+ children: e
116
+ }), /* @__PURE__ */ c("div", {
117
+ style: b,
118
+ children: /* @__PURE__ */ c(w, {
119
+ value: t,
120
+ nested: !0
121
+ })
122
+ })]
123
+ }, e))
124
+ });
125
+ }
126
+ function w({ value: e, nested: t }) {
127
+ return f(e) ? /* @__PURE__ */ c("span", {
128
+ style: { color: "var(--text-4)" },
129
+ children: "—"
130
+ }) : p(e) ? /* @__PURE__ */ c(s, { children: e.map(String).join(", ") }) : typeof e == "object" ? /* @__PURE__ */ c(C, {
131
+ value: e,
132
+ nested: t
133
+ }) : /* @__PURE__ */ c(s, { children: r(e) });
134
+ }
135
+ export { m as JsonField, f as isEmptyJsonValue };
@@ -33,8 +33,8 @@ function d(e) {
33
33
  entities: m
34
34
  }) : /* @__PURE__ */ l(o, { ...e });
35
35
  }
36
- function f({ structDef: e, value: n, mode: r, onChange: i, fieldId: o, labelId: f, nested: p = !1, refs: m, entities: h }) {
37
- let g = s(), _ = c(), v = o ?? _, y = typeof n == "object" && n && !Array.isArray(n) ? n : {}, b = e.fields.names(), x = {
36
+ function f({ structDef: e, value: n, mode: r, onChange: i, fieldId: o, labelId: f, nested: p = !1, refs: h, entities: g }) {
37
+ let _ = s(), v = c(), y = o ?? v, b = typeof n == "object" && n && !Array.isArray(n) ? n : {}, x = e.fields.names(), S = {
38
38
  display: "flex",
39
39
  flexDirection: "column",
40
40
  gap: r === "display" ? 8 : 12,
@@ -43,16 +43,12 @@ function f({ structDef: e, value: n, mode: r, onChange: i, fieldId: o, labelId:
43
43
  padding: 12,
44
44
  background: "var(--surface-2)"
45
45
  };
46
- if (r === "display") return b.some((e) => y[e] != null && y[e] !== "") ? /* @__PURE__ */ l("div", {
47
- style: p ? {
48
- display: "flex",
49
- flexDirection: "column",
50
- gap: 8
51
- } : x,
52
- children: b.map((t) => {
46
+ if (r === "display") return x.some((e) => b[e] != null && b[e] !== "") ? /* @__PURE__ */ l("div", {
47
+ style: p ? m : S,
48
+ children: x.map((t) => {
53
49
  let n = e.fields.get(t);
54
50
  if (!n) return null;
55
- let r = y[t];
51
+ let r = b[t];
56
52
  return r == null ? null : /* @__PURE__ */ u("div", {
57
53
  style: {
58
54
  display: "flex",
@@ -65,33 +61,35 @@ function f({ structDef: e, value: n, mode: r, onChange: i, fieldId: o, labelId:
65
61
  fontSize: 11.5,
66
62
  fontWeight: 500,
67
63
  color: "var(--text-3)",
68
- minWidth: 100,
69
- flexShrink: 0
64
+ width: 120,
65
+ flexShrink: 0,
66
+ overflowWrap: "anywhere"
70
67
  },
71
- title: g(n.display?.description) || void 0,
72
- children: n.display ? g(n.display.name) : t
68
+ title: _(n.display?.description) || void 0,
69
+ children: n.display ? _(n.display.name) : t
73
70
  }), /* @__PURE__ */ l("div", {
74
71
  style: {
75
72
  minWidth: 0,
76
- flex: "1 1 14rem"
73
+ flex: "1 1 14rem",
74
+ overflowWrap: "anywhere"
77
75
  },
78
76
  children: n.type === "structure" && n.structure ? /* @__PURE__ */ l(d, {
79
77
  field: n,
80
78
  fieldName: t,
81
79
  value: r,
82
80
  mode: "display",
83
- t: g,
81
+ t: _,
84
82
  nested: !0,
85
- refs: m,
86
- entities: h
83
+ refs: h,
84
+ entities: g
87
85
  }) : a({
88
86
  field: n,
89
87
  fieldName: t,
90
88
  value: r,
91
89
  mode: "display",
92
- t: g,
93
- refs: m,
94
- entities: h
90
+ t: _,
91
+ refs: h,
92
+ entities: g
95
93
  })
96
94
  })]
97
95
  }, t);
@@ -103,21 +101,21 @@ function f({ structDef: e, value: n, mode: r, onChange: i, fieldId: o, labelId:
103
101
  },
104
102
  children: "—"
105
103
  });
106
- let S = (e) => (t) => {
104
+ let C = (e) => (t) => {
107
105
  i?.({
108
- ...y,
106
+ ...b,
109
107
  [e]: t
110
108
  });
111
109
  };
112
110
  return /* @__PURE__ */ l("div", {
113
- style: x,
111
+ style: S,
114
112
  id: o,
115
113
  role: "group",
116
114
  "aria-labelledby": f,
117
- children: b.map((n) => {
115
+ children: x.map((n) => {
118
116
  let r = e.fields.get(n);
119
117
  if (!r) return null;
120
- let i = r.type === "structure" && !!r.structure, o = `${v}-${n}`, s = `${o}-label`;
118
+ let i = r.type === "structure" && !!r.structure, o = `${y}-${n}`, s = `${o}-label`;
121
119
  return /* @__PURE__ */ u("div", {
122
120
  style: {
123
121
  display: "flex",
@@ -128,25 +126,25 @@ function f({ structDef: e, value: n, mode: r, onChange: i, fieldId: o, labelId:
128
126
  required: r.required,
129
127
  id: s,
130
128
  htmlFor: i ? void 0 : o,
131
- children: r.display ? g(r.display.name) : n
129
+ children: r.display ? _(r.display.name) : n
132
130
  }), i ? /* @__PURE__ */ l(d, {
133
131
  field: r,
134
- t: g,
132
+ t: _,
135
133
  fieldName: n,
136
- value: y[n],
134
+ value: b[n],
137
135
  mode: "edit",
138
- onChange: S(n),
136
+ onChange: C(n),
139
137
  fieldId: o,
140
138
  labelId: s
141
139
  }) : a({
142
140
  field: r,
143
141
  fieldName: n,
144
- value: y[n],
142
+ value: b[n],
145
143
  mode: "edit",
146
- onChange: S(n),
144
+ onChange: C(n),
147
145
  fieldId: o,
148
146
  labelId: s,
149
- t: g
147
+ t: _
150
148
  })]
151
149
  }, n);
152
150
  })
@@ -227,4 +225,11 @@ function p({ structDef: t, value: i, mode: a, onChange: o, fieldId: d, labelId:
227
225
  }) })]
228
226
  });
229
227
  }
228
+ var m = {
229
+ display: "flex",
230
+ flexDirection: "column",
231
+ gap: 8,
232
+ paddingLeft: 10,
233
+ borderLeft: "2px solid var(--border)"
234
+ };
230
235
  export { d as StructureField };
@@ -0,0 +1,44 @@
1
+ import { EMPTY_CELL as e } from "./emptyCell.js";
2
+ import { coerceDisplayString as t } from "../../../../lib/display-value.js";
3
+ import { jsx as n } from "react/jsx-runtime";
4
+ // src/components/fields/cells/factories/duration.tsx
5
+ var r = {
6
+ ns: 1,
7
+ us: 1e3,
8
+ ms: 1e6,
9
+ s: 1e9,
10
+ min: 6e10,
11
+ h: 36e11
12
+ }, i = [
13
+ ["h", "hour"],
14
+ ["min", "minute"],
15
+ ["s", "second"],
16
+ ["ms", "millisecond"],
17
+ ["us", "microsecond"],
18
+ ["ns", "nanosecond"]
19
+ ], a = {
20
+ fontSize: 12.5,
21
+ fontVariantNumeric: "tabular-nums"
22
+ }, o = (o) => {
23
+ let { field: s, fieldName: c, t: l } = o, u = s.unit ? s.unit.display || s.unit.storage : void 0, d = new Map(i.map(([e, t]) => [e, new Intl.NumberFormat(l.language, {
24
+ style: "unit",
25
+ unit: t,
26
+ unitDisplay: "short",
27
+ maximumFractionDigits: 1
28
+ })]));
29
+ return (o, s) => {
30
+ if (o == null || o === "") return e;
31
+ let l = r[s.$units?.[c] || u || ""], f = typeof o == "number" ? o : Number(o);
32
+ if (l === void 0 || !Number.isFinite(f)) return /* @__PURE__ */ n("span", {
33
+ style: a,
34
+ children: t(o)
35
+ });
36
+ let p = f * l, [m] = i.find(([e]) => Math.abs(p) >= r[e]) ?? ["ns"];
37
+ return /* @__PURE__ */ n("span", {
38
+ className: "num",
39
+ style: a,
40
+ children: d.get(m).format(p / r[m])
41
+ });
42
+ };
43
+ };
44
+ export { r as NANOSECONDS_PER_UNIT, o as durationFactory };
@@ -7,21 +7,22 @@ import { dateFactory as a, timeFactory as o } from "./factories/date.js";
7
7
  import { timeAgoFactory as s, timestampFullFactory as c } from "./factories/timestamp.js";
8
8
  import { nextRunFactory as l } from "./factories/nextRun.js";
9
9
  import { moneyFactory as u } from "./factories/money.js";
10
- import { refLinkFactory as d } from "./factories/refLink.js";
11
- import { urlFactory as f } from "./factories/url.js";
12
- import { emailFactory as p } from "./factories/email.js";
13
- import { phoneFactory as m } from "./factories/phone.js";
14
- import { numberFactory as h } from "./factories/number.js";
15
- import { codeFactory as g } from "./factories/code.js";
16
- import { linkFactory as _ } from "./factories/link.js";
17
- import { jsonFactory as v } from "./factories/json.js";
18
- import { markdownFactory as y } from "./factories/markdown.js";
19
- import { passwordMaskFactory as b } from "./factories/passwordMask.js";
20
- import { richTextPreviewFactory as x } from "./factories/richTextPreview.js";
21
- import { multilangInlineFactory as S } from "./factories/multilangInline.js";
22
- import { fileReferenceFactory as C } from "./factories/fileReference.js";
10
+ import { durationFactory as d } from "./factories/duration.js";
11
+ import { refLinkFactory as f } from "./factories/refLink.js";
12
+ import { urlFactory as p } from "./factories/url.js";
13
+ import { emailFactory as m } from "./factories/email.js";
14
+ import { phoneFactory as h } from "./factories/phone.js";
15
+ import { numberFactory as g } from "./factories/number.js";
16
+ import { codeFactory as _ } from "./factories/code.js";
17
+ import { linkFactory as v } from "./factories/link.js";
18
+ import { jsonFactory as y } from "./factories/json.js";
19
+ import { markdownFactory as b } from "./factories/markdown.js";
20
+ import { passwordMaskFactory as x } from "./factories/passwordMask.js";
21
+ import { richTextPreviewFactory as S } from "./factories/richTextPreview.js";
22
+ import { multilangInlineFactory as C } from "./factories/multilangInline.js";
23
+ import { fileReferenceFactory as w } from "./factories/fileReference.js";
23
24
  // src/components/fields/cells/registry.ts
24
- var w = {
25
+ var T = {
25
26
  text: e,
26
27
  bool_pill: t,
27
28
  badge: n,
@@ -33,25 +34,26 @@ var w = {
33
34
  time: o,
34
35
  next_run: l,
35
36
  money: u,
36
- ref_link: d,
37
- file_ref: C,
38
- url: f,
39
- email: p,
40
- phone: m,
41
- number: h,
42
- percent: h,
43
- code: g,
44
- link: _,
45
- json: v,
46
- markdown: y,
47
- password_mask: b,
48
- rich_text_preview: x,
49
- multilang_inline: S
37
+ duration: d,
38
+ ref_link: f,
39
+ file_ref: w,
40
+ url: p,
41
+ email: m,
42
+ phone: h,
43
+ number: g,
44
+ percent: g,
45
+ code: _,
46
+ link: v,
47
+ json: y,
48
+ markdown: b,
49
+ password_mask: x,
50
+ rich_text_preview: S,
51
+ multilang_inline: C
50
52
  };
51
- Object.keys(w).sort();
52
- function T(e) {
53
- let t = e.field.display?.widget ?? "text", n = w[t];
53
+ Object.keys(T).sort();
54
+ function E(e) {
55
+ let t = e.field.display?.widget ?? "text", n = T[t];
54
56
  if (!n) throw Error(`resolveCellRenderer: no factory registered for widget "${t}" (field "${e.fieldName}"). The engine must stamp a smart default at YAML-load time; an unknown widget here indicates an out-of-sync allow-list.`);
55
57
  return n(e);
56
58
  }
57
- export { T as resolveCellRenderer };
59
+ export { E as resolveCellRenderer };