@nivaro/react 0.3.143 → 0.3.144

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,37 @@
1
- import { jsxs as u, jsx as l } from "react/jsx-runtime";
2
- import { GitBranch as b, AlertTriangle as w } from "lucide-react";
3
- import { useState as p, useCallback as x } from "react";
4
- import { cn as m } from "../../../lib/utils.js";
5
- import { amberStrip as k } from "../panel-style.js";
6
- import { loopSentence as g } from "./field-sources.js";
7
- const y = {
1
+ import { jsxs as u, jsx as a } from "react/jsx-runtime";
2
+ import { GitBranch as k, AlertTriangle as y } from "lucide-react";
3
+ import { useState as g, useCallback as v } from "react";
4
+ import { cn as w } from "../../../lib/utils.js";
5
+ import { amberStrip as N } from "../panel-style.js";
6
+ import { loopSentence as b } from "./field-sources.js";
7
+ const S = {
8
8
  required: "amber",
9
9
  readonly: "slate",
10
10
  hidden: "slate",
11
11
  filled: "violet"
12
- }, h = "nvr:layout-editor:rules-view";
13
- function z() {
14
- const [e, n] = p(() => {
12
+ }, C = /* @__PURE__ */ new Set(["hidden", "filled"]);
13
+ function R(e) {
14
+ return [...new Set(e.map((t) => t.tip || t.text))].join(`
15
+ `);
16
+ }
17
+ const m = "nvr:layout-editor:rules-view";
18
+ function M() {
19
+ const [e, t] = g(() => {
15
20
  try {
16
- return window.localStorage.getItem(h) !== "off";
21
+ return window.localStorage.getItem(m) !== "off";
17
22
  } catch {
18
23
  return !0;
19
24
  }
20
- }), r = x((a) => {
21
- n(a);
25
+ }), r = v((d) => {
26
+ t(d);
22
27
  try {
23
- window.localStorage.setItem(h, a ? "on" : "off");
28
+ window.localStorage.setItem(m, d ? "on" : "off");
24
29
  } catch {
25
30
  }
26
31
  }, []);
27
32
  return [e, r];
28
33
  }
29
- function j({ on: e, onChange: n }) {
34
+ function _({ on: e, onChange: t }) {
30
35
  return /* @__PURE__ */ u(
31
36
  "button",
32
37
  {
@@ -35,97 +40,103 @@ function j({ on: e, onChange: n }) {
35
40
  "aria-label": "Rules",
36
41
  "data-rules-view": e ? "on" : "off",
37
42
  "data-tip": e ? "Hide the rule tags and default values on the canvas" : "Show why fields are required, read-only or hidden, section rules and default values",
38
- onClick: () => n(!e),
39
- className: m(
43
+ onClick: () => t(!e),
44
+ className: w(
40
45
  "inline-flex h-8 items-center gap-1 rounded-md px-2 text-[12px] font-medium transition-colors",
41
46
  e ? "bg-accent text-slate-900 dark:text-foreground" : "text-slate-500 hover:bg-muted hover:text-slate-800 dark:text-muted-foreground dark:hover:text-foreground"
42
47
  ),
43
48
  children: [
44
- /* @__PURE__ */ l(b, { className: "h-3.5 w-3.5" }),
45
- /* @__PURE__ */ l("span", { "data-tb-wide": "", children: "Rules" })
49
+ /* @__PURE__ */ a(k, { className: "h-3.5 w-3.5" }),
50
+ /* @__PURE__ */ a("span", { "data-tb-wide": "", children: "Rules" })
46
51
  ]
47
52
  }
48
53
  );
49
54
  }
50
- function E(e, n) {
55
+ function q(e, t) {
51
56
  var i;
52
57
  const r = /* @__PURE__ */ new Map();
53
58
  for (const o of e.loops) {
54
- const t = g(o, e.describe, e.groupLabel);
55
- for (const d of o.fields) r.set(d, [...r.get(d) ?? [], t]);
59
+ const n = b(o, e.describe, e.groupLabel);
60
+ for (const c of o.fields) r.set(c, [...r.get(c) ?? [], n]);
56
61
  }
57
- if (r.size > 0 || (((i = n.ghostTags) == null ? void 0 : i.size) ?? 0) > 0 || n.chips && (e.fieldChips.size > 0 || e.groupChips.size > 0))
62
+ if (r.size > 0 || (((i = t.ghostTags) == null ? void 0 : i.size) ?? 0) > 0 || t.chips && (e.fieldChips.size > 0 || e.groupChips.size > 0))
58
63
  return (o) => {
59
- var f;
60
- const t = [];
64
+ var p;
65
+ const n = [];
61
66
  if (o.kind === "group") {
62
- if (n.chips)
67
+ if (t.chips)
63
68
  for (const s of e.groupChips.get(o.key) ?? [])
64
- t.push({ text: s.text, tone: "slate", tip: s.tip, onClick: () => n.open(s.open, o) });
65
- return t;
69
+ n.push({ text: s.text, tone: "slate", tip: s.tip, onClick: () => t.open(s.open, o) });
70
+ return n;
66
71
  }
67
- if (o.kind !== "field" && o.kind !== "header") return t;
68
- const d = r.get(o.field);
69
- if (d && t.push({
72
+ if (o.kind !== "field" && o.kind !== "header") return n;
73
+ const c = r.get(o.field);
74
+ if (c && n.push({
70
75
  text: "Rule loop",
71
76
  tone: "amber",
72
- tip: d.join(" · "),
77
+ tip: c.join(" · "),
73
78
  highlight: !0,
74
79
  kind: "loop"
75
- }), n.chips)
76
- for (const s of e.fieldChips.get(o.field) ?? [])
77
- t.push({
78
- text: s.text,
79
- tone: y[s.state],
80
- tip: s.tip,
81
- onClick: () => n.open(s.open, o)
80
+ }), t.chips) {
81
+ const s = /* @__PURE__ */ new Map();
82
+ for (const l of e.fieldChips.get(o.field) ?? [])
83
+ t.readOnlyView && !C.has(l.state) || s.set(l.state, [...s.get(l.state) ?? [], l]);
84
+ for (const [l, f] of s)
85
+ n.push({
86
+ text: f.map((x) => x.text).join(" · "),
87
+ tone: S[l],
88
+ icon: l,
89
+ iconOnly: !0,
90
+ tip: R(f),
91
+ onClick: () => t.open(f[0].open, o)
82
92
  });
83
- const c = (f = n.ghostTags) == null ? void 0 : f.get(o.field);
84
- return c && t.push({ text: c, tone: "slate", tip: "What a new record starts with" }), t;
93
+ }
94
+ const h = (p = t.ghostTags) == null ? void 0 : p.get(o.field);
95
+ return h && n.push({ text: h, tone: "slate", tip: "What a new record starts with" }), n;
85
96
  };
86
97
  }
87
- function L({
98
+ function A({
88
99
  explain: e,
89
- onShow: n
100
+ onShow: t
90
101
  }) {
91
- const [r, a] = p(!1);
102
+ const [r, d] = g(!1);
92
103
  if (e.loops.length === 0) return null;
93
- const i = e.loops.map((t) => ({
94
- field: t.fields[0],
95
- text: g(t, e.describe, e.groupLabel)
104
+ const i = e.loops.map((n) => ({
105
+ field: n.fields[0],
106
+ text: b(n, e.describe, e.groupLabel)
96
107
  })), o = r ? i : i.slice(0, 1);
97
108
  return /* @__PURE__ */ u(
98
109
  "div",
99
110
  {
100
111
  role: "note",
101
112
  "data-rule-loops": "",
102
- className: m(
113
+ className: w(
103
114
  "flex shrink-0 items-start gap-2 border-b px-4 py-1.5 text-[12.5px]",
104
- k
115
+ N
105
116
  ),
106
117
  children: [
107
- /* @__PURE__ */ l(w, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }),
108
- /* @__PURE__ */ l("ul", { className: "m-0 min-w-0 flex-1 list-none space-y-0.5 p-0", children: o.map((t) => /* @__PURE__ */ u("li", { className: "flex min-w-0 items-baseline gap-2", children: [
118
+ /* @__PURE__ */ a(y, { className: "mt-0.5 h-3.5 w-3.5 shrink-0" }),
119
+ /* @__PURE__ */ a("ul", { className: "m-0 min-w-0 flex-1 list-none space-y-0.5 p-0", children: o.map((n) => /* @__PURE__ */ u("li", { className: "flex min-w-0 items-baseline gap-2", children: [
109
120
  /* @__PURE__ */ u("span", { className: "min-w-0", children: [
110
121
  "Rule loop: ",
111
- t.text,
122
+ n.text,
112
123
  "."
113
124
  ] }),
114
- /* @__PURE__ */ l(
125
+ /* @__PURE__ */ a(
115
126
  "button",
116
127
  {
117
128
  type: "button",
118
- onClick: () => n(t.field),
129
+ onClick: () => t(n.field),
119
130
  className: "shrink-0 font-medium underline underline-offset-2 hover:no-underline",
120
131
  children: "Show"
121
132
  }
122
133
  )
123
- ] }, t.text)) }),
124
- i.length > 1 && /* @__PURE__ */ l(
134
+ ] }, n.text)) }),
135
+ i.length > 1 && /* @__PURE__ */ a(
125
136
  "button",
126
137
  {
127
138
  type: "button",
128
- onClick: () => a(!r),
139
+ onClick: () => d(!r),
129
140
  className: "shrink-0 font-medium underline underline-offset-2 hover:no-underline",
130
141
  children: r ? "Fewer" : `${i.length - 1} more`
131
142
  }
@@ -135,8 +146,8 @@ function L({
135
146
  );
136
147
  }
137
148
  export {
138
- L as RuleLoopsBanner,
139
- j as RulesToggle,
140
- E as explainMarks,
141
- z as useRulesView
149
+ A as RuleLoopsBanner,
150
+ _ as RulesToggle,
151
+ q as explainMarks,
152
+ M as useRulesView
142
153
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.143",
3
+ "version": "0.3.144",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",