@nivaro/react 0.3.108 → 0.3.109

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.
@@ -441,10 +441,10 @@ function ee(e) {
441
441
  return `${/^[aeiou]/i.test(e) ? "an" : "a"} ${e}`;
442
442
  }
443
443
  function ne(e, n) {
444
- const t = `a ${_(b(e.parent_collection, n).singular)} record`;
445
- if (!i(e.parent_id)) return t;
446
- const r = I(e.parent_collection, e.parent_id, n);
447
- return !r || r === w ? t : r;
444
+ const t = _(b(e.parent_collection, n).singular), r = `${/^[aeiou]/i.test(t) ? "an" : "a"} ${t} record`;
445
+ if (!i(e.parent_id)) return r;
446
+ const o = I(e.parent_collection, e.parent_id, n);
447
+ return !o || o === w ? r : o;
448
448
  }
449
449
  function D(e) {
450
450
  const n = i(e.value);
@@ -31,6 +31,7 @@ const R = [
31
31
  "hidden_for_roles",
32
32
  "locked_for_roles",
33
33
  "read_width",
34
+ "form_width",
34
35
  "editor_note",
35
36
  "i18n"
36
37
  ], Y = [
@@ -155,7 +156,8 @@ function H(t, e, s, o) {
155
156
  visible_when: null,
156
157
  hidden_for_roles: null,
157
158
  locked_for_roles: null,
158
- read_width: null
159
+ read_width: null,
160
+ form_width: null
159
161
  };
160
162
  }
161
163
  const g = (t, e) => t < e ? -1 : t > e ? 1 : 0, h = (t, e) => (t.id ?? Number.MAX_SAFE_INTEGER) - (e.id ?? Number.MAX_SAFE_INTEGER);
@@ -175,11 +177,11 @@ function p(t, e) {
175
177
  }
176
178
  function u(t, e) {
177
179
  const s = [];
178
- return t.groups.forEach((o, l) => {
179
- o.parent_key === e && s.push({ m: o, tie: P(o.key), i: l });
180
- }), e === null && t.placements.forEach((o, l) => {
181
- f(o) && s.push({ m: o, tie: P(o.field), i: t.groups.length + l });
182
- }), s.sort((o, l) => o.m.sort - l.m.sort || o.tie - l.tie || h(o.m, l.m) || o.i - l.i).map((o) => o.m);
180
+ return t.groups.forEach((o, _) => {
181
+ o.parent_key === e && s.push({ m: o, tie: P(o.key), i: _ });
182
+ }), e === null && t.placements.forEach((o, _) => {
183
+ f(o) && s.push({ m: o, tie: P(o.field), i: t.groups.length + _ });
184
+ }), s.sort((o, _) => o.m.sort - _.m.sort || o.tie - _.tie || h(o.m, _.m) || o.i - _.i).map((o) => o.m);
183
185
  }
184
186
  function c(t) {
185
187
  t.forEach((e, s) => {
@@ -201,8 +203,8 @@ function J(t, e) {
201
203
  placements: t.placements.map((o) => ({ ...o }))
202
204
  };
203
205
  if (!Array.isArray(e)) throw new N("ops must be an array", 0);
204
- return e.forEach((o, l) => {
205
- B(s, o, l), V(s);
206
+ return e.forEach((o, _) => {
207
+ B(s, o, _), V(s);
206
208
  }), K({ ...s, rev: t.rev });
207
209
  }
208
210
  function B(t, e, s) {
@@ -210,10 +212,10 @@ function B(t, e, s) {
210
212
  throw new N(n, s);
211
213
  };
212
214
  (!e || typeof e != "object") && o("Each op must be an object");
213
- const l = (n, r, i) => {
215
+ const _ = (n, r, i) => {
214
216
  (typeof i != "number" || !Number.isFinite(i)) && o("index must be a number");
215
- const _ = Math.max(0, Math.min(n.length, Math.floor(i)));
216
- return [...n.slice(0, _), r, ...n.slice(_)];
217
+ const l = Math.max(0, Math.min(n.length, Math.floor(i)));
218
+ return [...n.slice(0, l), r, ...n.slice(l)];
217
219
  }, y = (n, r) => {
218
220
  if (n == null) return {};
219
221
  (typeof n != "object" || Array.isArray(n)) && o("patch must be an object");
@@ -222,13 +224,13 @@ function B(t, e, s) {
222
224
  return n;
223
225
  }, A = (n) => {
224
226
  const r = y(n, L);
225
- return r.type !== void 0 && !m.includes(r.type) && o(`Group type must be one of ${m.join(", ")}`), r.read_width != null && !["full", "half", "third"].includes(r.read_width) && o("read_width must be 'full', 'half', 'third' or null"), r.editor_note != null && (typeof r.editor_note != "string" || r.editor_note.length > 4e3) && o("A note must be text of at most 4000 characters"), r;
227
+ return r.type !== void 0 && !m.includes(r.type) && o(`Group type must be one of ${m.join(", ")}`), r.read_width != null && !["full", "half", "third"].includes(r.read_width) && o("read_width must be 'full', 'half', 'third' or null"), r.form_width != null && !["full", "half"].includes(r.form_width) && o("form_width must be 'full', 'half' or null"), r.editor_note != null && (typeof r.editor_note != "string" || r.editor_note.length > 4e3) && o("A note must be text of at most 4000 characters"), r;
226
228
  }, k = (n) => {
227
229
  (!n || typeof n.field != "string") && o("A placement needs a field");
228
230
  const r = n;
229
231
  M.includes(r.field) && o(`"${r.field}" is a reserved name`);
230
232
  const i = t.placements.find(
231
- (_) => _.field === r.field && _.group_key === (r.group_key ?? null)
233
+ (l) => l.field === r.field && l.group_key === (r.group_key ?? null)
232
234
  );
233
235
  return i || o(`"${r.field}" is not placed in ${r.group_key ?? "Ungrouped"}`), i;
234
236
  }, b = (n) => {
@@ -241,11 +243,11 @@ function B(t, e, s) {
241
243
  (!r || r.key === d) && o(`No group "${n}"`), r.type === "container" && o("Fields go in the tabs of a container"), r.type === "content" && o("A text block holds text, not fields");
242
244
  }, T = (n, r) => {
243
245
  if (n === null) return;
244
- const i = t.groups.find((_) => _.key === n);
246
+ const i = t.groups.find((l) => l.key === n);
245
247
  (i == null ? void 0 : i.type) !== "container" && o(`"${n}" is not a container`), r !== "tab" && o("Only tabs go inside a container");
246
248
  }, S = (n, r) => {
247
- const i = f(n) ? u(t, null).filter((_) => _ !== n) : p(t, n.group_key).filter((_) => _ !== n);
248
- c(l(i, n, r));
249
+ const i = f(n) ? u(t, null).filter((l) => l !== n) : p(t, n.group_key).filter((l) => l !== n);
250
+ c(_(i, n, r));
249
251
  };
250
252
  switch (e.op) {
251
253
  case "place": {
@@ -280,8 +282,8 @@ function B(t, e, s) {
280
282
  m.includes(r) || o(`Group type must be one of ${m.join(", ")}`);
281
283
  const i = e.parent_key ?? null;
282
284
  T(i, r);
283
- const _ = { ...H(e.key, e.label, r, i), ...n }, w = u(t, i);
284
- t.groups.push(_), c(l(w, _, e.index));
285
+ const l = { ...H(e.key, e.label, r, i), ...n }, w = u(t, i);
286
+ t.groups.push(l), c(_(w, l, e.index));
285
287
  return;
286
288
  }
287
289
  case "group_update": {
@@ -294,14 +296,14 @@ function B(t, e, s) {
294
296
  let r;
295
297
  if (e.key === d || f({ field: e.key, group_key: null })) {
296
298
  n !== null && o("This stays at the top level of the form");
297
- const i = e.key === d ? t.groups.find((_) => _.key === d) : t.placements.find((_) => _.field === e.key && _.group_key === null);
299
+ const i = e.key === d ? t.groups.find((l) => l.key === d) : t.placements.find((l) => l.field === e.key && l.group_key === null);
298
300
  i || o(`"${e.key}" is not on this form`), r = i;
299
301
  } else {
300
302
  const i = b(e.key);
301
303
  T(n, i.type), i.parent_key = n, r = i;
302
304
  }
303
305
  c(
304
- l(
306
+ _(
305
307
  u(t, n).filter((i) => i !== r),
306
308
  r,
307
309
  e.index
@@ -314,8 +316,8 @@ function B(t, e, s) {
314
316
  e.placements !== "ungroup" && e.placements !== "delete" && o("placements must be 'ungroup' or 'delete'");
315
317
  const r = u(t, n.parent_key), i = u(t, n.key);
316
318
  for (const a of i) a.parent_key = n.parent_key;
317
- const _ = r.indexOf(n);
318
- c([...r.slice(0, _), ...i, ...r.slice(_ + 1)]), t.groups = t.groups.filter((a) => a !== n);
319
+ const l = r.indexOf(n);
320
+ c([...r.slice(0, l), ...i, ...r.slice(l + 1)]), t.groups = t.groups.filter((a) => a !== n);
319
321
  const w = p(t, n.key);
320
322
  if (t.placements = t.placements.filter((a) => a.group_key !== n.key), e.placements === "delete") return;
321
323
  const v = p(t, null), U = u(t, null), E = w.filter(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.108",
3
+ "version": "0.3.109",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",