@nivaro/react 0.3.8 → 0.3.10
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.
- package/dist/components/fields/FileField.js +20 -19
- package/dist/full.css +1 -1
- package/dist/hooks/replayUploadQueue.js +107 -93
- package/dist/hooks/useNivaroForm.js +129 -126
- package/dist/hooks/useSessionRecorder.js +103 -101
- package/dist/index.d.ts +115 -2
- package/dist/index.js +466 -447
- package/dist/shared/components/CollectionBrowserView.js +1058 -1059
- package/dist/shared/components/ConformanceView.js +36 -35
- package/dist/shared/components/DataTable.js +230 -223
- package/dist/shared/components/ForceReloadBanner.js +58 -34
- package/dist/shared/components/ItemEditForm.js +3687 -3580
- package/dist/shared/components/JsonMapEditor.js +18 -17
- package/dist/shared/components/MatrixEditor.js +8 -7
- package/dist/shared/components/MyWorkView.js +32 -31
- package/dist/shared/components/PageRenderer.js +146 -145
- package/dist/shared/components/QueryTable.js +49 -49
- package/dist/shared/components/RecordGridEditor.js +76 -75
- package/dist/shared/components/ai/AiMemorySuggestions.js +15 -14
- package/dist/shared/components/ai/AskPanel.js +55 -54
- package/dist/shared/components/bulk/BulkActionButtons.js +30 -29
- package/dist/shared/components/bulk/PushBulkButtons.js +57 -56
- package/dist/shared/components/chat/ChatPanel.js +288 -287
- package/dist/shared/components/chat/SlashCommands.js +30 -29
- package/dist/shared/components/chat/chat-outbox.js +76 -75
- package/dist/shared/components/help-videos/recorder/useLeaveWarning.js +6 -5
- package/dist/shared/components/integrations/console/SignalCard.js +124 -123
- package/dist/shared/components/integrations/console/SnoozeMenu.js +24 -23
- package/dist/shared/components/item-edit/CloneDialog.js +85 -78
- package/dist/shared/components/item-edit/InlineTableField.js +301 -300
- package/dist/shared/components/item-edit/MembershipSetField.js +24 -23
- package/dist/shared/components/item-edit/QuickCreateButton.js +8 -7
- package/dist/shared/components/item-edit/RecordLiveSync.js +101 -100
- package/dist/shared/components/item-edit/staged-links.js +86 -0
- package/dist/shared/components/layout-editor/LayoutEditor.js +275 -274
- package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +18 -17
- package/dist/shared/components/layout-editor/inspector/HelpTab.js +37 -36
- package/dist/shared/components/layout-editor/matrix/FieldStateMatrix.js +50 -49
- package/dist/shared/components/panels/CommentPanel.js +237 -236
- package/dist/shared/components/profile/AiMemoryCard.js +15 -14
- package/dist/shared/components/profile/PersonAdminTools.js +70 -67
- package/dist/shared/components/profile/usePersonPresence.js +42 -37
- package/dist/shared/components/queue/QueueItemSheet.js +36 -35
- package/dist/shared/components/queue/QueueWorklist.js +597 -598
- package/dist/shared/lib/client-version.js +63 -0
- package/dist/shared/lib/force-reload.js +36 -0
- package/dist/shared/lib/load-error.js +11 -10
- package/dist/shared/lib/presence-live.js +73 -0
- package/dist/shared/lib/presence-state.js +39 -31
- package/dist/shared/lib/record-outbox.js +76 -75
- package/dist/shared/lib/request-gate.js +120 -102
- package/dist/shared/lib/rum.js +45 -36
- package/dist/shared/lib/safe-error.js +39 -0
- package/dist/shared/lib/server-clock.js +11 -7
- package/dist/shared/lib/signed-out.js +114 -0
- package/dist/shared/lib/socket-realtime.js +19 -17
- package/dist/shared/lib/unsaved-work.js +62 -0
- package/dist/shared/lib/use-online-users.js +11 -10
- package/dist/shared/lib/worker-socket.js +89 -79
- package/package.json +1 -1
|
@@ -1,146 +1,147 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { get as
|
|
1
|
+
import { useState as S, useRef as $, useEffect as A, useCallback as w, useMemo as G } from "react";
|
|
2
|
+
import { get as W, post as z, patch as ce } from "../lib/commands.js";
|
|
3
3
|
import { useFormSchema as de } from "./useFormSchema.js";
|
|
4
4
|
import { useOptionalNivaroClient as me } from "../shared/context.js";
|
|
5
5
|
import { applyValidationRule as pe } from "../shared/lib/validation-rules.js";
|
|
6
|
+
import { useUnsavedWork as ge } from "../shared/lib/unsaved-work.js";
|
|
6
7
|
function L(r, c) {
|
|
7
|
-
const
|
|
8
|
+
const l = c[r.when];
|
|
8
9
|
switch (r.op) {
|
|
9
10
|
case "eq":
|
|
10
|
-
return
|
|
11
|
+
return l === r.value;
|
|
11
12
|
case "neq":
|
|
12
|
-
return
|
|
13
|
+
return l !== r.value;
|
|
13
14
|
case "null":
|
|
14
|
-
return
|
|
15
|
+
return l == null || l === "";
|
|
15
16
|
case "nnull":
|
|
16
|
-
return
|
|
17
|
+
return l != null && l !== "";
|
|
17
18
|
case "in":
|
|
18
|
-
return Array.isArray(r.value) && r.value.includes(
|
|
19
|
+
return Array.isArray(r.value) && r.value.includes(l);
|
|
19
20
|
case "contains":
|
|
20
|
-
return typeof
|
|
21
|
+
return typeof l == "string" && l.includes(String(r.value ?? ""));
|
|
21
22
|
default:
|
|
22
23
|
return !0;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
function H(r, c) {
|
|
26
27
|
if (!r || r.length === 0) return !0;
|
|
27
|
-
let
|
|
28
|
+
let l = !0, g = !1;
|
|
28
29
|
for (const u of r) {
|
|
29
|
-
const
|
|
30
|
-
u.action === "show" ? (
|
|
30
|
+
const h = L(u, c);
|
|
31
|
+
u.action === "show" ? (g = !0, h && (l = !0)) : u.action === "hide" && h && (l = !1);
|
|
31
32
|
}
|
|
32
|
-
if (
|
|
33
|
-
const u = r.some((p) => p.action === "show" && L(p, c)),
|
|
34
|
-
if (!u && !
|
|
33
|
+
if (g) {
|
|
34
|
+
const u = r.some((p) => p.action === "show" && L(p, c)), h = r.some((p) => p.action === "hide" && L(p, c));
|
|
35
|
+
if (!u && !h) return !1;
|
|
35
36
|
}
|
|
36
|
-
return
|
|
37
|
+
return l;
|
|
37
38
|
}
|
|
38
|
-
function
|
|
39
|
+
function he(r, c) {
|
|
39
40
|
return r ? L(r, c) : !1;
|
|
40
41
|
}
|
|
41
|
-
function
|
|
42
|
-
const
|
|
42
|
+
function Q(r, c) {
|
|
43
|
+
const l = {};
|
|
43
44
|
if (r)
|
|
44
|
-
for (const
|
|
45
|
-
|
|
46
|
-
return c && Object.assign(
|
|
45
|
+
for (const g of r.fields)
|
|
46
|
+
g.defaultValue !== void 0 && g.defaultValue !== null && (l[g.field] = g.defaultValue);
|
|
47
|
+
return c && Object.assign(l, c), l;
|
|
47
48
|
}
|
|
48
|
-
function
|
|
49
|
+
function ye(r) {
|
|
49
50
|
return r == null || r === "" || Array.isArray(r) && r.length === 0;
|
|
50
51
|
}
|
|
51
|
-
function
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
for (const u of
|
|
52
|
+
function ve(r, c) {
|
|
53
|
+
const l = Object.keys(r), g = Object.keys(c);
|
|
54
|
+
if (l.length !== g.length) return !1;
|
|
55
|
+
for (const u of l)
|
|
55
56
|
if (!Object.hasOwn(c, u) || r[u] !== c[u]) return !1;
|
|
56
57
|
return !0;
|
|
57
58
|
}
|
|
58
|
-
function
|
|
59
|
-
const
|
|
59
|
+
function ke(r, c, l) {
|
|
60
|
+
const g = me(), u = l ?? g;
|
|
60
61
|
if (!u)
|
|
61
62
|
throw new Error(
|
|
62
63
|
"useNivaroForm requires a NivaroClient — pass one as the third argument or wrap the tree in <NivaroProvider>."
|
|
63
64
|
);
|
|
64
65
|
const {
|
|
65
|
-
mode:
|
|
66
|
+
mode: h,
|
|
66
67
|
itemId: p,
|
|
67
68
|
defaultValues: N,
|
|
68
69
|
onSuccess: q,
|
|
69
|
-
onError:
|
|
70
|
+
onError: b,
|
|
70
71
|
validate: F,
|
|
71
|
-
includeHidden:
|
|
72
|
-
layoutId:
|
|
73
|
-
layoutSlug:
|
|
72
|
+
includeHidden: X = !1,
|
|
73
|
+
layoutId: Y,
|
|
74
|
+
layoutSlug: Z,
|
|
74
75
|
fieldRulesDebounce: x = 300
|
|
75
76
|
} = c, {
|
|
76
|
-
schema:
|
|
77
|
+
schema: o,
|
|
77
78
|
loading: K,
|
|
78
|
-
error:
|
|
79
|
-
} = de(u, r,
|
|
79
|
+
error: ee
|
|
80
|
+
} = de(u, r, X, Y, Z), [f, j] = S({}), [V, D] = S({}), [te, k] = S({}), [re, P] = S(!1), [ne, C] = S(h === "edit"), O = $(!1), R = $(null), U = $(/* @__PURE__ */ new Map()), I = $(!0);
|
|
80
81
|
A(() => (I.current = !0, () => {
|
|
81
82
|
I.current = !1;
|
|
82
83
|
}), []), A(() => {
|
|
83
84
|
O.current = !1;
|
|
84
85
|
}, []), A(() => {
|
|
85
|
-
if (!
|
|
86
|
-
if (
|
|
86
|
+
if (!o || O.current) return;
|
|
87
|
+
if (h === "edit" && p != null) {
|
|
87
88
|
let e = !0;
|
|
88
89
|
C(!0);
|
|
89
|
-
const
|
|
90
|
+
const s = o.fields.filter(
|
|
90
91
|
(n) => {
|
|
91
|
-
var
|
|
92
|
-
return n.fieldType === "relation-m2m" && ((
|
|
92
|
+
var i, m, a;
|
|
93
|
+
return n.fieldType === "relation-m2m" && ((i = n.relation) == null ? void 0 : i.relatedCollection) && ((m = n.relation) == null ? void 0 : m.manyField) && ((a = n.relation) == null ? void 0 : a.junctionField);
|
|
93
94
|
}
|
|
94
95
|
);
|
|
95
|
-
return u.request(
|
|
96
|
+
return u.request(W(`/items/${r}/${p}`)).then(async (n) => {
|
|
96
97
|
if (!e) return;
|
|
97
|
-
const
|
|
98
|
-
...
|
|
98
|
+
const i = {
|
|
99
|
+
...Q(o, N),
|
|
99
100
|
...n.data ?? {}
|
|
100
101
|
};
|
|
101
|
-
if (
|
|
102
|
+
if (s.length > 0) {
|
|
102
103
|
const m = await Promise.allSettled(
|
|
103
|
-
|
|
104
|
-
const d = a.relation,
|
|
104
|
+
s.map((a) => {
|
|
105
|
+
const d = a.relation, v = d.junctionCollection ?? d.relatedCollection;
|
|
105
106
|
return u.request(
|
|
106
|
-
|
|
107
|
+
W(`/items/${v}`, {
|
|
107
108
|
filter: JSON.stringify({ [d.manyField]: { _eq: p } }),
|
|
108
109
|
fields: `id,${d.junctionField}`,
|
|
109
110
|
limit: 200
|
|
110
111
|
})
|
|
111
|
-
).then((
|
|
112
|
+
).then((y) => ({
|
|
112
113
|
field: a.field,
|
|
113
114
|
junctionField: d.junctionField,
|
|
114
|
-
rows:
|
|
115
|
+
rows: y.data ?? []
|
|
115
116
|
})).catch(() => ({ field: a.field, junctionField: d.junctionField, rows: [] }));
|
|
116
117
|
})
|
|
117
118
|
);
|
|
118
119
|
for (const a of m)
|
|
119
120
|
if (a.status === "fulfilled") {
|
|
120
|
-
const { field: d, junctionField:
|
|
121
|
-
|
|
121
|
+
const { field: d, junctionField: v, rows: y } = a.value, J = y.map((T) => T[v]).filter((T) => T != null);
|
|
122
|
+
i[d] = J;
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
|
-
e && (j(
|
|
125
|
+
e && (j(i), D(i), O.current = !0, C(!1));
|
|
125
126
|
}).catch((n) => {
|
|
126
|
-
e && (C(!1),
|
|
127
|
+
e && (C(!1), b == null || b(n instanceof Error ? n : new Error(String(n))));
|
|
127
128
|
}), () => {
|
|
128
129
|
e = !1;
|
|
129
130
|
};
|
|
130
131
|
}
|
|
131
|
-
const t =
|
|
132
|
+
const t = Q(o, N);
|
|
132
133
|
j(t), D(t), O.current = !0, C(!1);
|
|
133
|
-
}, [
|
|
134
|
+
}, [o, h, p, r, N, b, u]);
|
|
134
135
|
const E = w(
|
|
135
136
|
(t) => {
|
|
136
137
|
x <= 0 || (R.current && clearTimeout(R.current), R.current = setTimeout(() => {
|
|
137
138
|
R.current = null, u.request(
|
|
138
|
-
|
|
139
|
+
z("/field-rules/evaluate", { collection: r, data: t })
|
|
139
140
|
).then((e) => {
|
|
140
141
|
var n;
|
|
141
142
|
if (!I.current) return;
|
|
142
|
-
const
|
|
143
|
-
|
|
143
|
+
const s = (n = e.data) == null ? void 0 : n.updates;
|
|
144
|
+
s && Object.keys(s).length > 0 && j((i) => ({ ...i, ...s }));
|
|
144
145
|
}).catch(() => {
|
|
145
146
|
});
|
|
146
147
|
}, x));
|
|
@@ -150,139 +151,141 @@ function Re(r, c, o) {
|
|
|
150
151
|
A(() => () => {
|
|
151
152
|
R.current && clearTimeout(R.current);
|
|
152
153
|
}, []);
|
|
153
|
-
const
|
|
154
|
+
const se = w(
|
|
154
155
|
(t, e) => {
|
|
155
|
-
j((
|
|
156
|
-
const n = { ...
|
|
156
|
+
j((s) => {
|
|
157
|
+
const n = { ...s, [t]: e };
|
|
157
158
|
return E(n), n;
|
|
158
|
-
}),
|
|
159
|
-
if (!
|
|
160
|
-
const { [t]: n, ...
|
|
161
|
-
return
|
|
159
|
+
}), k((s) => {
|
|
160
|
+
if (!s[t]) return s;
|
|
161
|
+
const { [t]: n, ...i } = s;
|
|
162
|
+
return i;
|
|
162
163
|
});
|
|
163
164
|
},
|
|
164
165
|
[E]
|
|
165
166
|
), ie = w(
|
|
166
167
|
(t) => {
|
|
167
168
|
j((e) => {
|
|
168
|
-
const
|
|
169
|
-
return E(
|
|
169
|
+
const s = { ...e, ...t };
|
|
170
|
+
return E(s), s;
|
|
170
171
|
});
|
|
171
172
|
},
|
|
172
173
|
[E]
|
|
173
|
-
),
|
|
174
|
+
), oe = w(
|
|
174
175
|
(t) => {
|
|
175
|
-
j(t ?? V),
|
|
176
|
+
j(t ?? V), k({});
|
|
176
177
|
},
|
|
177
178
|
[V]
|
|
178
179
|
), le = w(
|
|
179
180
|
(t) => {
|
|
180
|
-
const e =
|
|
181
|
+
const e = o == null ? void 0 : o.fields.find((s) => s.field === t);
|
|
181
182
|
return e ? H(e.visibilityRules, f) : !0;
|
|
182
183
|
},
|
|
183
|
-
[
|
|
184
|
-
),
|
|
184
|
+
[o, f]
|
|
185
|
+
), ue = w(
|
|
185
186
|
(t) => {
|
|
186
|
-
const e =
|
|
187
|
-
return e ? e.readonly ? !0 :
|
|
187
|
+
const e = o == null ? void 0 : o.fields.find((s) => s.field === t);
|
|
188
|
+
return e ? e.readonly ? !0 : he(e.lockCondition, f) : !1;
|
|
188
189
|
},
|
|
189
|
-
[
|
|
190
|
-
),
|
|
190
|
+
[o, f]
|
|
191
|
+
), _ = w(() => {
|
|
191
192
|
const t = {};
|
|
192
|
-
if (!
|
|
193
|
-
for (const e of
|
|
193
|
+
if (!o) return t;
|
|
194
|
+
for (const e of o.fields) {
|
|
194
195
|
if (!H(e.visibilityRules, f)) continue;
|
|
195
|
-
const
|
|
196
|
-
e.required &&
|
|
197
|
-
for (const
|
|
198
|
-
if (
|
|
199
|
-
const m = pe(
|
|
196
|
+
const s = f[e.field];
|
|
197
|
+
e.required && ye(s) && (t[e.field] == null && (t[e.field] = []), t[e.field].push(`${e.label} is required`));
|
|
198
|
+
for (const i of e.validationRules ?? []) {
|
|
199
|
+
if (i.soft) continue;
|
|
200
|
+
const m = pe(i, s, e.label);
|
|
200
201
|
m && (t[e.field] == null && (t[e.field] = []), t[e.field].push(m));
|
|
201
202
|
}
|
|
202
203
|
const n = F == null ? void 0 : F[e.field];
|
|
203
204
|
if (n) {
|
|
204
|
-
const
|
|
205
|
-
|
|
205
|
+
const i = n(s, f);
|
|
206
|
+
i && (t[e.field] == null && (t[e.field] = []), t[e.field].push(i));
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
if (F)
|
|
209
|
-
for (const [e,
|
|
210
|
-
if (t[e] ||
|
|
211
|
-
const n =
|
|
210
|
+
for (const [e, s] of Object.entries(F)) {
|
|
211
|
+
if (t[e] || o.fields.some((i) => i.field === e)) continue;
|
|
212
|
+
const n = s(f[e], f);
|
|
212
213
|
n && (t[e] == null && (t[e] = []), t[e].push(n));
|
|
213
214
|
}
|
|
214
215
|
return t;
|
|
215
|
-
}, [
|
|
216
|
+
}, [o, f, F]), fe = w(
|
|
216
217
|
async (t) => {
|
|
217
|
-
var
|
|
218
|
-
(
|
|
219
|
-
const e =
|
|
220
|
-
if (
|
|
218
|
+
var s;
|
|
219
|
+
(s = t == null ? void 0 : t.preventDefault) == null || s.call(t);
|
|
220
|
+
const e = _();
|
|
221
|
+
if (k(e), !(Object.keys(e).length > 0)) {
|
|
221
222
|
P(!0);
|
|
222
223
|
try {
|
|
223
|
-
for (const m of
|
|
224
|
-
const
|
|
224
|
+
for (const m of U.current.values()) await m();
|
|
225
|
+
const i = (h === "edit" && p != null ? await u.request(
|
|
225
226
|
ce(`/items/${r}/${p}`, f)
|
|
226
227
|
) : await u.request(
|
|
227
|
-
|
|
228
|
+
z(`/items/${r}`, f)
|
|
228
229
|
)).data ?? f;
|
|
229
|
-
D(
|
|
230
|
+
D(i), q == null || q(i);
|
|
230
231
|
} catch (n) {
|
|
231
|
-
const
|
|
232
|
+
const i = n instanceof Error ? n : new Error(String(n)), m = n == null ? void 0 : n.response;
|
|
232
233
|
if (m != null && typeof m == "object") {
|
|
233
234
|
const a = m;
|
|
234
235
|
if (typeof a.field == "string" && typeof a.error == "string")
|
|
235
|
-
|
|
236
|
+
k((d) => ({
|
|
236
237
|
...d,
|
|
237
238
|
[a.field]: [a.error]
|
|
238
239
|
}));
|
|
239
240
|
else if (Array.isArray(a.errors)) {
|
|
240
241
|
const d = {};
|
|
241
|
-
for (const
|
|
242
|
-
if (
|
|
243
|
-
const
|
|
244
|
-
typeof
|
|
242
|
+
for (const v of a.errors)
|
|
243
|
+
if (v != null && typeof v == "object") {
|
|
244
|
+
const y = v;
|
|
245
|
+
typeof y.field == "string" && typeof y.message == "string" && (d[y.field] == null && (d[y.field] = []), d[y.field].push(y.message));
|
|
245
246
|
}
|
|
246
|
-
Object.keys(d).length > 0 &&
|
|
247
|
+
Object.keys(d).length > 0 && k((v) => ({ ...v, ...d }));
|
|
247
248
|
}
|
|
248
249
|
}
|
|
249
|
-
|
|
250
|
+
b == null || b(i);
|
|
250
251
|
} finally {
|
|
251
252
|
P(!1);
|
|
252
253
|
}
|
|
253
254
|
}
|
|
254
255
|
},
|
|
255
|
-
[
|
|
256
|
-
),
|
|
256
|
+
[_, h, p, r, f, u, q, b]
|
|
257
|
+
), B = G(() => !ve(f, V), [f, V]);
|
|
258
|
+
ge(B, "Unsaved form changes");
|
|
259
|
+
const M = G(() => {
|
|
257
260
|
const t = /* @__PURE__ */ new Map();
|
|
258
|
-
if (!
|
|
259
|
-
for (const e of
|
|
260
|
-
const
|
|
261
|
-
n.push(e), t.set(
|
|
261
|
+
if (!o) return t;
|
|
262
|
+
for (const e of o.fields) {
|
|
263
|
+
const s = e.group ?? null, n = t.get(s) ?? [];
|
|
264
|
+
n.push(e), t.set(s, n);
|
|
262
265
|
}
|
|
263
266
|
return t;
|
|
264
|
-
}, [
|
|
267
|
+
}, [o]), ae = G(() => o ? o.groups.filter((t) => (M.get(t.key) ?? []).some((s) => H(s.visibilityRules, f))) : [], [o, M, f]);
|
|
265
268
|
return {
|
|
266
|
-
schema:
|
|
269
|
+
schema: o,
|
|
267
270
|
schemaLoading: K,
|
|
268
|
-
schemaError:
|
|
271
|
+
schemaError: ee,
|
|
269
272
|
values: f,
|
|
270
273
|
initialValues: V,
|
|
271
|
-
errors:
|
|
272
|
-
isDirty:
|
|
273
|
-
isSubmitting:
|
|
274
|
-
isLoading: K ||
|
|
274
|
+
errors: te,
|
|
275
|
+
isDirty: B,
|
|
276
|
+
isSubmitting: re,
|
|
277
|
+
isLoading: K || ne,
|
|
275
278
|
isVisible: le,
|
|
276
|
-
isLocked:
|
|
277
|
-
setValue:
|
|
279
|
+
isLocked: ue,
|
|
280
|
+
setValue: se,
|
|
278
281
|
setValues: ie,
|
|
279
|
-
reset:
|
|
280
|
-
handleSubmit:
|
|
282
|
+
reset: oe,
|
|
283
|
+
handleSubmit: fe,
|
|
281
284
|
fieldsByGroup: M,
|
|
282
285
|
visibleGroups: ae,
|
|
283
|
-
gridFlushersRef:
|
|
286
|
+
gridFlushersRef: U
|
|
284
287
|
};
|
|
285
288
|
}
|
|
286
289
|
export {
|
|
287
|
-
|
|
290
|
+
ke as useNivaroForm
|
|
288
291
|
};
|