@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.
Files changed (60) hide show
  1. package/dist/components/fields/FileField.js +20 -19
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/replayUploadQueue.js +107 -93
  4. package/dist/hooks/useNivaroForm.js +129 -126
  5. package/dist/hooks/useSessionRecorder.js +103 -101
  6. package/dist/index.d.ts +115 -2
  7. package/dist/index.js +466 -447
  8. package/dist/shared/components/CollectionBrowserView.js +1058 -1059
  9. package/dist/shared/components/ConformanceView.js +36 -35
  10. package/dist/shared/components/DataTable.js +230 -223
  11. package/dist/shared/components/ForceReloadBanner.js +58 -34
  12. package/dist/shared/components/ItemEditForm.js +3687 -3580
  13. package/dist/shared/components/JsonMapEditor.js +18 -17
  14. package/dist/shared/components/MatrixEditor.js +8 -7
  15. package/dist/shared/components/MyWorkView.js +32 -31
  16. package/dist/shared/components/PageRenderer.js +146 -145
  17. package/dist/shared/components/QueryTable.js +49 -49
  18. package/dist/shared/components/RecordGridEditor.js +76 -75
  19. package/dist/shared/components/ai/AiMemorySuggestions.js +15 -14
  20. package/dist/shared/components/ai/AskPanel.js +55 -54
  21. package/dist/shared/components/bulk/BulkActionButtons.js +30 -29
  22. package/dist/shared/components/bulk/PushBulkButtons.js +57 -56
  23. package/dist/shared/components/chat/ChatPanel.js +288 -287
  24. package/dist/shared/components/chat/SlashCommands.js +30 -29
  25. package/dist/shared/components/chat/chat-outbox.js +76 -75
  26. package/dist/shared/components/help-videos/recorder/useLeaveWarning.js +6 -5
  27. package/dist/shared/components/integrations/console/SignalCard.js +124 -123
  28. package/dist/shared/components/integrations/console/SnoozeMenu.js +24 -23
  29. package/dist/shared/components/item-edit/CloneDialog.js +85 -78
  30. package/dist/shared/components/item-edit/InlineTableField.js +301 -300
  31. package/dist/shared/components/item-edit/MembershipSetField.js +24 -23
  32. package/dist/shared/components/item-edit/QuickCreateButton.js +8 -7
  33. package/dist/shared/components/item-edit/RecordLiveSync.js +101 -100
  34. package/dist/shared/components/item-edit/staged-links.js +86 -0
  35. package/dist/shared/components/layout-editor/LayoutEditor.js +275 -274
  36. package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +18 -17
  37. package/dist/shared/components/layout-editor/inspector/HelpTab.js +37 -36
  38. package/dist/shared/components/layout-editor/matrix/FieldStateMatrix.js +50 -49
  39. package/dist/shared/components/panels/CommentPanel.js +237 -236
  40. package/dist/shared/components/profile/AiMemoryCard.js +15 -14
  41. package/dist/shared/components/profile/PersonAdminTools.js +70 -67
  42. package/dist/shared/components/profile/usePersonPresence.js +42 -37
  43. package/dist/shared/components/queue/QueueItemSheet.js +36 -35
  44. package/dist/shared/components/queue/QueueWorklist.js +597 -598
  45. package/dist/shared/lib/client-version.js +63 -0
  46. package/dist/shared/lib/force-reload.js +36 -0
  47. package/dist/shared/lib/load-error.js +11 -10
  48. package/dist/shared/lib/presence-live.js +73 -0
  49. package/dist/shared/lib/presence-state.js +39 -31
  50. package/dist/shared/lib/record-outbox.js +76 -75
  51. package/dist/shared/lib/request-gate.js +120 -102
  52. package/dist/shared/lib/rum.js +45 -36
  53. package/dist/shared/lib/safe-error.js +39 -0
  54. package/dist/shared/lib/server-clock.js +11 -7
  55. package/dist/shared/lib/signed-out.js +114 -0
  56. package/dist/shared/lib/socket-realtime.js +19 -17
  57. package/dist/shared/lib/unsaved-work.js +62 -0
  58. package/dist/shared/lib/use-online-users.js +11 -10
  59. package/dist/shared/lib/worker-socket.js +89 -79
  60. package/package.json +1 -1
@@ -1,146 +1,147 @@
1
- import { useState as k, useRef as $, useEffect as A, useCallback as w, useMemo as G } from "react";
2
- import { get as z, post as Q, patch as ce } from "../lib/commands.js";
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 o = c[r.when];
8
+ const l = c[r.when];
8
9
  switch (r.op) {
9
10
  case "eq":
10
- return o === r.value;
11
+ return l === r.value;
11
12
  case "neq":
12
- return o !== r.value;
13
+ return l !== r.value;
13
14
  case "null":
14
- return o == null || o === "";
15
+ return l == null || l === "";
15
16
  case "nnull":
16
- return o != null && o !== "";
17
+ return l != null && l !== "";
17
18
  case "in":
18
- return Array.isArray(r.value) && r.value.includes(o);
19
+ return Array.isArray(r.value) && r.value.includes(l);
19
20
  case "contains":
20
- return typeof o == "string" && o.includes(String(r.value ?? ""));
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 o = !0, y = !1;
28
+ let l = !0, g = !1;
28
29
  for (const u of r) {
29
- const g = L(u, c);
30
- u.action === "show" ? (y = !0, g && (o = !0)) : u.action === "hide" && g && (o = !1);
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 (y) {
33
- const u = r.some((p) => p.action === "show" && L(p, c)), g = r.some((p) => p.action === "hide" && L(p, c));
34
- if (!u && !g) return !1;
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 o;
37
+ return l;
37
38
  }
38
- function ye(r, c) {
39
+ function he(r, c) {
39
40
  return r ? L(r, c) : !1;
40
41
  }
41
- function U(r, c) {
42
- const o = {};
42
+ function Q(r, c) {
43
+ const l = {};
43
44
  if (r)
44
- for (const y of r.fields)
45
- y.defaultValue !== void 0 && y.defaultValue !== null && (o[y.field] = y.defaultValue);
46
- return c && Object.assign(o, c), o;
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 ge(r) {
49
+ function ye(r) {
49
50
  return r == null || r === "" || Array.isArray(r) && r.length === 0;
50
51
  }
51
- function he(r, c) {
52
- const o = Object.keys(r), y = Object.keys(c);
53
- if (o.length !== y.length) return !1;
54
- for (const u of o)
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 Re(r, c, o) {
59
- const y = me(), u = o ?? y;
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: g,
66
+ mode: h,
66
67
  itemId: p,
67
68
  defaultValues: N,
68
69
  onSuccess: q,
69
- onError: v,
70
+ onError: b,
70
71
  validate: F,
71
- includeHidden: W = !1,
72
- layoutId: X,
73
- layoutSlug: Y,
72
+ includeHidden: X = !1,
73
+ layoutId: Y,
74
+ layoutSlug: Z,
74
75
  fieldRulesDebounce: x = 300
75
76
  } = c, {
76
- schema: l,
77
+ schema: o,
77
78
  loading: K,
78
- error: Z
79
- } = de(u, r, W, X, Y), [f, j] = k({}), [V, D] = k({}), [ee, S] = k({}), [te, P] = k(!1), [re, C] = k(g === "edit"), O = $(!1), R = $(null), _ = $(/* @__PURE__ */ new Map()), I = $(!0);
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 (!l || O.current) return;
86
- if (g === "edit" && p != null) {
86
+ if (!o || O.current) return;
87
+ if (h === "edit" && p != null) {
87
88
  let e = !0;
88
89
  C(!0);
89
- const i = l.fields.filter(
90
+ const s = o.fields.filter(
90
91
  (n) => {
91
- var s, m, a;
92
- return n.fieldType === "relation-m2m" && ((s = n.relation) == null ? void 0 : s.relatedCollection) && ((m = n.relation) == null ? void 0 : m.manyField) && ((a = n.relation) == null ? void 0 : a.junctionField);
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(z(`/items/${r}/${p}`)).then(async (n) => {
96
+ return u.request(W(`/items/${r}/${p}`)).then(async (n) => {
96
97
  if (!e) return;
97
- const s = {
98
- ...U(l, N),
98
+ const i = {
99
+ ...Q(o, N),
99
100
  ...n.data ?? {}
100
101
  };
101
- if (i.length > 0) {
102
+ if (s.length > 0) {
102
103
  const m = await Promise.allSettled(
103
- i.map((a) => {
104
- const d = a.relation, b = d.junctionCollection ?? d.relatedCollection;
104
+ s.map((a) => {
105
+ const d = a.relation, v = d.junctionCollection ?? d.relatedCollection;
105
106
  return u.request(
106
- z(`/items/${b}`, {
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((h) => ({
112
+ ).then((y) => ({
112
113
  field: a.field,
113
114
  junctionField: d.junctionField,
114
- rows: h.data ?? []
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: b, rows: h } = a.value, J = h.map((T) => T[b]).filter((T) => T != null);
121
- s[d] = J;
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(s), D(s), O.current = !0, C(!1));
125
+ e && (j(i), D(i), O.current = !0, C(!1));
125
126
  }).catch((n) => {
126
- e && (C(!1), v == null || v(n instanceof Error ? n : new Error(String(n))));
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 = U(l, N);
132
+ const t = Q(o, N);
132
133
  j(t), D(t), O.current = !0, C(!1);
133
- }, [l, g, p, r, N, v, u]);
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
- Q("/field-rules/evaluate", { collection: r, data: t })
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 i = (n = e.data) == null ? void 0 : n.updates;
143
- i && Object.keys(i).length > 0 && j((s) => ({ ...s, ...i }));
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 ne = w(
154
+ const se = w(
154
155
  (t, e) => {
155
- j((i) => {
156
- const n = { ...i, [t]: e };
156
+ j((s) => {
157
+ const n = { ...s, [t]: e };
157
158
  return E(n), n;
158
- }), S((i) => {
159
- if (!i[t]) return i;
160
- const { [t]: n, ...s } = i;
161
- return s;
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 i = { ...e, ...t };
169
- return E(i), i;
169
+ const s = { ...e, ...t };
170
+ return E(s), s;
170
171
  });
171
172
  },
172
173
  [E]
173
- ), se = w(
174
+ ), oe = w(
174
175
  (t) => {
175
- j(t ?? V), S({});
176
+ j(t ?? V), k({});
176
177
  },
177
178
  [V]
178
179
  ), le = w(
179
180
  (t) => {
180
- const e = l == null ? void 0 : l.fields.find((i) => i.field === t);
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
- [l, f]
184
- ), oe = w(
184
+ [o, f]
185
+ ), ue = w(
185
186
  (t) => {
186
- const e = l == null ? void 0 : l.fields.find((i) => i.field === t);
187
- return e ? e.readonly ? !0 : ye(e.lockCondition, f) : !1;
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
- [l, f]
190
- ), B = w(() => {
190
+ [o, f]
191
+ ), _ = w(() => {
191
192
  const t = {};
192
- if (!l) return t;
193
- for (const e of l.fields) {
193
+ if (!o) return t;
194
+ for (const e of o.fields) {
194
195
  if (!H(e.visibilityRules, f)) continue;
195
- const i = f[e.field];
196
- e.required && ge(i) && (t[e.field] == null && (t[e.field] = []), t[e.field].push(`${e.label} is required`));
197
- for (const s of e.validationRules ?? []) {
198
- if (s.soft) continue;
199
- const m = pe(s, i, e.label);
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 s = n(i, f);
205
- s && (t[e.field] == null && (t[e.field] = []), t[e.field].push(s));
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, i] of Object.entries(F)) {
210
- if (t[e] || l.fields.some((s) => s.field === e)) continue;
211
- const n = i(f[e], f);
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
- }, [l, f, F]), ue = w(
216
+ }, [o, f, F]), fe = w(
216
217
  async (t) => {
217
- var i;
218
- (i = t == null ? void 0 : t.preventDefault) == null || i.call(t);
219
- const e = B();
220
- if (S(e), !(Object.keys(e).length > 0)) {
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 _.current.values()) await m();
224
- const s = (g === "edit" && p != null ? await u.request(
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
- Q(`/items/${r}`, f)
228
+ z(`/items/${r}`, f)
228
229
  )).data ?? f;
229
- D(s), q == null || q(s);
230
+ D(i), q == null || q(i);
230
231
  } catch (n) {
231
- const s = n instanceof Error ? n : new Error(String(n)), m = n == null ? void 0 : n.response;
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
- S((d) => ({
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 b of a.errors)
242
- if (b != null && typeof b == "object") {
243
- const h = b;
244
- typeof h.field == "string" && typeof h.message == "string" && (d[h.field] == null && (d[h.field] = []), d[h.field].push(h.message));
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 && S((b) => ({ ...b, ...d }));
247
+ Object.keys(d).length > 0 && k((v) => ({ ...v, ...d }));
247
248
  }
248
249
  }
249
- v == null || v(s);
250
+ b == null || b(i);
250
251
  } finally {
251
252
  P(!1);
252
253
  }
253
254
  }
254
255
  },
255
- [B, g, p, r, f, u, q, v]
256
- ), fe = G(() => !he(f, V), [f, V]), M = G(() => {
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 (!l) return t;
259
- for (const e of l.fields) {
260
- const i = e.group ?? null, n = t.get(i) ?? [];
261
- n.push(e), t.set(i, n);
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
- }, [l]), ae = G(() => l ? l.groups.filter((t) => (M.get(t.key) ?? []).some((i) => H(i.visibilityRules, f))) : [], [l, M, f]);
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: l,
269
+ schema: o,
267
270
  schemaLoading: K,
268
- schemaError: Z,
271
+ schemaError: ee,
269
272
  values: f,
270
273
  initialValues: V,
271
- errors: ee,
272
- isDirty: fe,
273
- isSubmitting: te,
274
- isLoading: K || re,
274
+ errors: te,
275
+ isDirty: B,
276
+ isSubmitting: re,
277
+ isLoading: K || ne,
275
278
  isVisible: le,
276
- isLocked: oe,
277
- setValue: ne,
279
+ isLocked: ue,
280
+ setValue: se,
278
281
  setValues: ie,
279
- reset: se,
280
- handleSubmit: ue,
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
- Re as useNivaroForm
290
+ ke as useNivaroForm
288
291
  };