@acellera/pm-rjsf 0.0.3 → 0.0.5

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/pm-rjsf.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import k from "react";
2
2
  import G from "@rjsf/mui";
3
- import { Accordion as $, AccordionSummary as K, AccordionDetails as U, FormLabel as L, Box as M, TextField as V, Grid as x, Tooltip as O, Typography as H, IconButton as X, Button as B, ButtonGroup as J, Menu as Y, MenuItem as E, ListItemIcon as R, ListItemText as D, ThemeProvider as Q, createTheme as Z } from "@mui/material";
3
+ import { Accordion as $, AccordionSummary as K, AccordionDetails as U, FormLabel as L, Box as _, TextField as V, Grid as x, Tooltip as O, Typography as H, IconButton as X, Button as B, ButtonGroup as J, Menu as Y, MenuItem as M, ListItemIcon as D, ListItemText as R, ThemeProvider as Q, createTheme as Z } from "@mui/material";
4
4
  import { customizeValidator as ee } from "@rjsf/validator-ajv8";
5
5
  import te from "ajv/dist/2020";
6
6
  import { getTemplate as ne, getUiOptions as ie, ADDITIONAL_PROPERTY_FLAG as z, canExpand as le } from "@rjsf/utils";
7
- import { ExpandMore as oe, Delete as re, DriveFolderUpload as ae, CloudDownload as se, ArrowDropDown as ce } from "@mui/icons-material";
8
- function de() {
7
+ import { ExpandMore as oe, Delete as re, DriveFolderUpload as ae, CloudDownload as se, ArrowDropDown as de } from "@mui/icons-material";
8
+ function ce() {
9
9
  return ee({
10
10
  AjvClass: te,
11
11
  customFormats: { path: () => !0 },
@@ -26,8 +26,8 @@ function w(e) {
26
26
  if (Array.isArray(e.anyOf)) {
27
27
  const i = e.anyOf.filter((n) => !(n && n.type === "null"));
28
28
  if (i.length === 1) {
29
- const { anyOf: n, ...o } = e;
30
- return w({ ...i[0], ...o });
29
+ const { anyOf: n, default: o, ...r } = e, d = { ...i[0], ...r };
30
+ return o != null && (d.default = o), w(d);
31
31
  }
32
32
  e = { ...e, anyOf: i };
33
33
  }
@@ -63,7 +63,7 @@ function pe(e) {
63
63
  }
64
64
  return t;
65
65
  }
66
- function _(e, t) {
66
+ function j(e, t) {
67
67
  const i = pe(e);
68
68
  return i ? l(
69
69
  O,
@@ -85,25 +85,25 @@ const q = {
85
85
  mb: 1.5
86
86
  };
87
87
  function ye(e) {
88
- const { children: t, errors: i, help: n, hidden: o, schema: a, registry: u, uiSchema: m } = e;
88
+ const { children: t, errors: i, help: n, hidden: o, schema: r, registry: d, uiSchema: m } = e;
89
89
  if (o) return l("div", { className: "hidden" }, t);
90
- const d = a && a.type, c = d === "object" || d === "array" || Array.isArray(d) && (d.includes("object") || d.includes("array"));
90
+ const u = r && r.type, c = u === "object" || u === "array" || Array.isArray(u) && (u.includes("object") || u.includes("array"));
91
91
  let s;
92
92
  if (c)
93
93
  s = t;
94
94
  else {
95
- const p = a && a.description ? String(a.description) : "", h = d === "boolean" || Array.isArray(d) && d.includes("boolean"), y = l(
95
+ const p = r && r.description ? String(r.description) : "", h = u === "boolean" || Array.isArray(u) && u.includes("boolean"), y = l(
96
96
  "div",
97
97
  h ? { style: { display: "inline-block" } } : null,
98
98
  t,
99
99
  i,
100
100
  n
101
101
  );
102
- s = _(p, y);
102
+ s = j(p, y);
103
103
  }
104
104
  const f = ne(
105
105
  "WrapIfAdditionalTemplate",
106
- u,
106
+ d,
107
107
  ie(m)
108
108
  );
109
109
  return l(f, { ...e }, s);
@@ -114,8 +114,8 @@ function he(e) {
114
114
  const s = t[c.name] && t[c.name]["ui:options"] && t[c.name]["ui:options"].group;
115
115
  s ? (o.get(s) || o.set(s, []).get(s)).push(c) : n.push(c);
116
116
  }
117
- const a = [], u = z in (e.schema || {}), m = t["ui:options"] && t["ui:options"].group, d = m && m === e.title;
118
- e.title && !u && !d && a.push(
117
+ const r = [], d = z in (e.schema || {}), m = t["ui:options"] && t["ui:options"].group, u = m && m === e.title;
118
+ e.title && !d && !u && r.push(
119
119
  l(i.TitleFieldTemplate, {
120
120
  key: "__title",
121
121
  id: e.idSchema.$id + "__title",
@@ -127,9 +127,9 @@ function he(e) {
127
127
  })
128
128
  );
129
129
  for (const c of n)
130
- a.push(l("div", { key: c.name, className: "pm-field" }, c.content));
130
+ r.push(l("div", { key: c.name, className: "pm-field" }, c.content));
131
131
  for (const [c, s] of o)
132
- a.push(
132
+ r.push(
133
133
  l(
134
134
  $,
135
135
  {
@@ -159,7 +159,7 @@ function he(e) {
159
159
  )
160
160
  )
161
161
  );
162
- return le(e.schema, e.uiSchema, e.formData) && a.push(
162
+ return le(e.schema, e.uiSchema, e.formData) && r.push(
163
163
  l(i.ButtonTemplates.AddButton, {
164
164
  key: "__add",
165
165
  className: "object-property-expand",
@@ -168,7 +168,7 @@ function he(e) {
168
168
  uiSchema: e.uiSchema,
169
169
  registry: e.registry
170
170
  })
171
- ), l("div", null, a);
171
+ ), l("div", null, r);
172
172
  }
173
173
  function be(e) {
174
174
  const {
@@ -176,10 +176,10 @@ function be(e) {
176
176
  classNames: i,
177
177
  style: n,
178
178
  disabled: o,
179
- id: a,
180
- label: u,
179
+ id: r,
180
+ label: d,
181
181
  onKeyChange: m,
182
- onDropPropertyClick: d,
182
+ onDropPropertyClick: u,
183
183
  readonly: c,
184
184
  schema: s,
185
185
  uiSchema: f,
@@ -187,9 +187,9 @@ function be(e) {
187
187
  } = e;
188
188
  if (!(z in s))
189
189
  return l("div", { className: i, style: n }, t);
190
- const h = p.templates.ButtonTemplates.RemoveButton, y = f && f["ui:options"] && f["ui:options"].keyLabel || u + " Key", I = a + "-key", T = /^newKey(-\d+)?$/.test(u || ""), v = s && s.description ? String(s.description) : "";
190
+ const h = p.templates.ButtonTemplates.RemoveButton, y = f && f["ui:options"] && f["ui:options"].keyLabel || d + " Key", I = r + "-key", T = /^newKey(-\d+)?$/.test(d || ""), v = s && s.description ? String(s.description) : "";
191
191
  return l(
192
- M,
192
+ _,
193
193
  { sx: q },
194
194
  l(
195
195
  "div",
@@ -197,18 +197,18 @@ function be(e) {
197
197
  l(
198
198
  "div",
199
199
  { style: { flex: "0 0 34%" } },
200
- _(
200
+ j(
201
201
  v,
202
202
  l(V, {
203
203
  id: I,
204
204
  label: y,
205
205
  size: "small",
206
206
  fullWidth: !0,
207
- defaultValue: T ? "" : u,
207
+ defaultValue: T ? "" : d,
208
208
  disabled: o || c,
209
- onBlur: (C) => {
210
- const g = C.target.value.trim();
211
- g && g !== u && m(g);
209
+ onBlur: (S) => {
210
+ const g = S.target.value.trim();
211
+ g && g !== d && m(g);
212
212
  }
213
213
  })
214
214
  )
@@ -219,7 +219,7 @@ function be(e) {
219
219
  { style: { flex: "0 0 auto", paddingTop: ".5rem" } },
220
220
  l(h, {
221
221
  disabled: o || c,
222
- onClick: d(u),
222
+ onClick: u(d),
223
223
  uiSchema: f,
224
224
  registry: p
225
225
  })
@@ -241,7 +241,7 @@ function xe(e) {
241
241
  return l(
242
242
  "div",
243
243
  { style: { marginTop: "8px", marginBottom: "2px" } },
244
- _(t, l("span", null, i))
244
+ j(t, l("span", null, i))
245
245
  );
246
246
  }
247
247
  function ke(e) {
@@ -257,7 +257,7 @@ function ke(e) {
257
257
  registry: e.registry
258
258
  })
259
259
  ), (e.items || []).forEach(
260
- ({ key: a, ...u }) => o.push(l(i, { key: a, ...u }))
260
+ ({ key: r, ...d }) => o.push(l(i, { key: r, ...d }))
261
261
  ), e.canAdd && o.push(
262
262
  l(t.ButtonTemplates.AddButton, {
263
263
  key: "__add",
@@ -274,19 +274,19 @@ function ve(e) {
274
274
  hasToolbar: i,
275
275
  hasCopy: n,
276
276
  hasMoveDown: o,
277
- hasMoveUp: a,
278
- hasRemove: u,
277
+ hasMoveUp: r,
278
+ hasRemove: d,
279
279
  index: m,
280
- onCopyIndexClick: d,
280
+ onCopyIndexClick: u,
281
281
  onDropIndexClick: c,
282
282
  onReorderClick: s,
283
283
  disabled: f,
284
284
  readonly: p,
285
285
  uiSchema: h,
286
286
  registry: y
287
- } = e, { CopyButton: I, MoveDownButton: T, MoveUpButton: v, RemoveButton: C } = y.templates.ButtonTemplates, g = { flex: 1, paddingLeft: 6, paddingRight: 6, fontWeight: "bold", minWidth: 0 };
287
+ } = e, { CopyButton: I, MoveDownButton: T, MoveUpButton: v, RemoveButton: S } = y.templates.ButtonTemplates, g = { flex: 1, paddingLeft: 6, paddingRight: 6, fontWeight: "bold", minWidth: 0 };
288
288
  return l(
289
- M,
289
+ _,
290
290
  { sx: q },
291
291
  l(
292
292
  x,
@@ -295,14 +295,14 @@ function ve(e) {
295
295
  i && l(
296
296
  x,
297
297
  { item: !0 },
298
- (a || o) && l(v, {
298
+ (r || o) && l(v, {
299
299
  style: g,
300
- disabled: f || p || !a,
300
+ disabled: f || p || !r,
301
301
  onClick: s(m, m - 1),
302
302
  uiSchema: h,
303
303
  registry: y
304
304
  }),
305
- (a || o) && l(T, {
305
+ (r || o) && l(T, {
306
306
  style: g,
307
307
  disabled: f || p || !o,
308
308
  onClick: s(m, m + 1),
@@ -312,11 +312,11 @@ function ve(e) {
312
312
  n && l(I, {
313
313
  style: g,
314
314
  disabled: f || p,
315
- onClick: d(m),
315
+ onClick: u(m),
316
316
  uiSchema: h,
317
317
  registry: y
318
318
  }),
319
- u && l(C, {
319
+ d && l(S, {
320
320
  style: g,
321
321
  disabled: f || p,
322
322
  onClick: c(m),
@@ -335,108 +335,108 @@ const Ie = {
335
335
  TitleFieldTemplate: xe,
336
336
  ArrayFieldTemplate: ke,
337
337
  ArrayFieldItemTemplate: ve
338
- }, r = k.createElement, P = [
338
+ }, a = k.createElement, P = [
339
339
  { key: "local", label: "From local file system", isInput: !0, Icon: ae },
340
340
  { key: "datacenter", label: "From datacenter", isInput: !1, Icon: se }
341
341
  ];
342
342
  function Te(e) {
343
- const { value: t, onChange: i, disabled: n = !1, readonly: o = !1, label: a, required: u } = e, m = /_\d+$/.test(e.id || ""), d = n || o, [c, s] = k.useState(null), [f, p] = k.useState(0), h = !!c, y = t ? String(t).split("/").pop() : "", I = (S) => S && i(S.name), T = () => i(void 0), v = P[f], C = a && !m ? r(
343
+ const { value: t, onChange: i, disabled: n = !1, readonly: o = !1, label: r, required: d } = e, m = /_\d+$/.test(e.id || ""), u = n || o, [c, s] = k.useState(null), [f, p] = k.useState(0), h = !!c, y = t ? String(t).split("/").pop() : "", I = (C) => C && i(C.name), T = () => i(void 0), v = P[f], S = r && !m ? a(
344
344
  x,
345
345
  { item: !0, zeroMinWidth: !0 },
346
- r(L, null, a, u ? " *" : null)
347
- ) : null, g = t ? r(
346
+ a(L, null, r, d ? " *" : null)
347
+ ) : null, g = t ? a(
348
348
  x,
349
349
  { item: !0, xs: !0, zeroMinWidth: !0 },
350
- r(
350
+ a(
351
351
  O,
352
352
  { title: y, arrow: !0, placement: "top" },
353
- r(H, { style: { textOverflow: "ellipsis", overflow: "hidden" } }, y)
353
+ a(H, { style: { textOverflow: "ellipsis", overflow: "hidden" } }, y)
354
354
  )
355
- ) : r(x, { item: !0, xs: !0 }, null);
355
+ ) : a(x, { item: !0, xs: !0 }, null);
356
356
  let F;
357
357
  if (t)
358
- F = r(
358
+ F = a(
359
359
  x,
360
360
  { item: !0, xs: "auto" },
361
- r(
361
+ a(
362
362
  O,
363
363
  { title: "Clear", arrow: !0, placement: "right" },
364
- r(
364
+ a(
365
365
  "span",
366
366
  null,
367
- r(
367
+ a(
368
368
  X,
369
- { onClick: T, size: "small", disabled: d },
370
- r(re, { fontSize: "small" })
369
+ { onClick: T, size: "small", disabled: u },
370
+ a(re, { fontSize: "small" })
371
371
  )
372
372
  )
373
373
  )
374
374
  );
375
375
  else {
376
- const S = v.isInput ? r(
376
+ const C = v.isInput ? a(
377
377
  B,
378
378
  {
379
379
  component: "label",
380
- disabled: d,
381
- endIcon: r(v.Icon, null),
380
+ disabled: u,
381
+ endIcon: a(v.Icon, null),
382
382
  sx: { px: 1.2, borderRadius: "4px 0 0 4px", borderRight: 0 }
383
383
  },
384
384
  "Select",
385
- r("input", {
385
+ a("input", {
386
386
  type: "file",
387
387
  hidden: !0,
388
388
  onChange: (b) => I(b.target.files && b.target.files[0])
389
389
  })
390
- ) : r(
390
+ ) : a(
391
391
  B,
392
392
  {
393
- disabled: d,
394
- endIcon: r(v.Icon, null),
393
+ disabled: u,
394
+ endIcon: a(v.Icon, null),
395
395
  sx: { px: 1.2, borderRadius: "4px 0 0 4px", borderRight: 0 },
396
396
  onClick: () => {
397
397
  }
398
398
  },
399
399
  "Select"
400
400
  );
401
- F = r(
401
+ F = a(
402
402
  x,
403
403
  { item: !0, xs: "auto" },
404
- r(
404
+ a(
405
405
  J,
406
406
  {
407
407
  variant: "outlined",
408
- disabled: d,
408
+ disabled: u,
409
409
  sx: { "& .MuiButtonGroup-grouped": { minWidth: 0 } }
410
410
  },
411
- S,
412
- r(
411
+ C,
412
+ a(
413
413
  B,
414
414
  {
415
415
  size: "small",
416
416
  onClick: (b) => s(b.currentTarget),
417
417
  sx: { width: "1em", borderRadius: "0 4px 4px 0" }
418
418
  },
419
- r(ce, null)
419
+ a(de, null)
420
420
  )
421
421
  ),
422
- r(
422
+ a(
423
423
  Y,
424
424
  { anchorEl: c, open: h, onClose: () => s(null) },
425
425
  P.map(
426
- (b, A) => b.isInput ? r(
427
- E,
426
+ (b, A) => b.isInput ? a(
427
+ M,
428
428
  { key: b.key, component: "label", selected: A === f },
429
- r(R, null, r(b.Icon, null)),
430
- r(D, null, b.label),
431
- r("input", {
429
+ a(D, null, a(b.Icon, null)),
430
+ a(R, null, b.label),
431
+ a("input", {
432
432
  type: "file",
433
433
  hidden: !0,
434
- onChange: (j) => {
435
- p(A), s(null), I(j.target.files && j.target.files[0]);
434
+ onChange: (E) => {
435
+ p(A), s(null), I(E.target.files && E.target.files[0]);
436
436
  }
437
437
  })
438
- ) : r(
439
- E,
438
+ ) : a(
439
+ M,
440
440
  {
441
441
  key: b.key,
442
442
  selected: A === f,
@@ -444,14 +444,14 @@ function Te(e) {
444
444
  p(A), s(null);
445
445
  }
446
446
  },
447
- r(R, null, r(b.Icon, null)),
448
- r(D, null, b.label)
447
+ a(D, null, a(b.Icon, null)),
448
+ a(R, null, b.label)
449
449
  )
450
450
  )
451
451
  )
452
452
  );
453
453
  }
454
- return r(
454
+ return a(
455
455
  x,
456
456
  {
457
457
  container: !0,
@@ -462,25 +462,25 @@ function Te(e) {
462
462
  wrap: "nowrap",
463
463
  sx: { mt: 0.5 }
464
464
  },
465
- C,
465
+ S,
466
466
  g,
467
467
  F
468
468
  );
469
469
  }
470
- const Ce = `
470
+ const Se = `
471
471
  .pm-field { margin: .5rem 0; }
472
472
  /* In an additionalProperties row, align the value's first field with the key
473
473
  field (drop its leading margin so both start at the row top). */
474
474
  .pm-ap-value > div > .pm-field:first-child { margin-top: 0; }
475
475
  `;
476
476
  let W = !1;
477
- function Se() {
477
+ function Ce() {
478
478
  if (W || typeof document > "u") return;
479
479
  W = !0;
480
480
  const e = document.createElement("style");
481
- e.setAttribute("data-pm-rjsf", ""), e.textContent = Ce, document.head.appendChild(e);
481
+ e.setAttribute("data-pm-rjsf", ""), e.textContent = Se, document.head.appendChild(e);
482
482
  }
483
- const Ae = de(), we = (e) => Z(e || {}, {
483
+ const Ae = ce(), we = (e) => Z(e || {}, {
484
484
  components: {
485
485
  MuiTextField: { defaultProps: { size: "small", fullWidth: !0 } },
486
486
  MuiFormControl: { defaultProps: { size: "small", fullWidth: !0 } },
@@ -492,24 +492,24 @@ function Fe(e, t) {
492
492
  if (!e || typeof e != "object") return e;
493
493
  const i = t && typeof t == "object" ? t : {};
494
494
  let n = null;
495
- for (const [o, a] of Object.entries(e)) {
496
- const u = a && a["ui:options"] && a["ui:options"].enabledBy;
497
- if (!u) continue;
498
- const m = !i[u];
499
- !!a["ui:disabled"] !== m && (n = n || { ...e }, n[o] = { ...a, "ui:disabled": m });
495
+ for (const [o, r] of Object.entries(e)) {
496
+ const d = r && r["ui:options"] && r["ui:options"].enabledBy;
497
+ if (!d) continue;
498
+ const m = !i[d];
499
+ !!r["ui:disabled"] !== m && (n = n || { ...e }, n[o] = { ...r, "ui:disabled": m });
500
500
  }
501
501
  return n || e;
502
502
  }
503
- function De({ schema: e, uiSchema: t, widgets: i, formData: n, onChange: o, ...a }) {
504
- Se();
505
- const [u, m] = k.useState(n), d = n !== void 0 ? n : u, c = (h, y) => {
503
+ function Re({ schema: e, uiSchema: t, widgets: i, formData: n, onChange: o, ...r }) {
504
+ Ce();
505
+ const [d, m] = k.useState(n), u = n !== void 0 ? n : d, c = (h, y) => {
506
506
  m(h.formData), o && o(h, y);
507
- }, s = me(e), f = Fe(t, d), p = { file: Te, ...i || {} };
507
+ }, s = me(e), f = Fe(t, u), p = { file: Te, ...i || {} };
508
508
  return k.createElement(
509
509
  Q,
510
510
  { theme: we },
511
511
  k.createElement(
512
- M,
512
+ _,
513
513
  { sx: { color: "text.primary" } },
514
514
  k.createElement(G, {
515
515
  schema: s,
@@ -517,9 +517,17 @@ function De({ schema: e, uiSchema: t, widgets: i, formData: n, onChange: o, ...a
517
517
  validator: Ae,
518
518
  templates: Ie,
519
519
  widgets: p,
520
- formData: d,
520
+ formData: u,
521
521
  onChange: c,
522
- ...a
522
+ // RJSF owns validation + error display. Native HTML5 validation hard-
523
+ // blocks submit when a `required` control is non-focusable (e.g. inside a
524
+ // collapsed accordion) and does so SILENTLY -- onSubmit never fires and
525
+ // nothing surfaces. Let RJSF validate instead so errors are visible.
526
+ noHtml5Validate: !0,
527
+ // Don't fabricate empty objects for optional submodels (Optional[Model]);
528
+ // leaving them absent keeps them valid until the user fills them in.
529
+ experimental_defaultFormStateBehavior: { emptyObjectFields: "skipEmptyDefaults" },
530
+ ...r
523
531
  })
524
532
  )
525
533
  );
@@ -530,13 +538,13 @@ export {
530
538
  ye as FieldTemplate,
531
539
  Te as FileWidget,
532
540
  he as GroupedObjectFieldTemplate,
533
- De as PMForm,
534
- Ce as PM_RJSF_CSS,
541
+ Re as PMForm,
542
+ Se as PM_RJSF_CSS,
535
543
  N as SPECIAL_DIRS,
536
544
  xe as TitleFieldTemplate,
537
545
  be as WrapIfAdditionalTemplate,
538
- Se as injectStyles,
539
- de as makeValidator,
546
+ Ce as injectStyles,
547
+ ce as makeValidator,
540
548
  me as prepareForRjsf,
541
549
  w as simplify,
542
550
  ue as stripSpecialDirs,