@devtron-labs/devtron-fe-common-lib 1.22.0-beta-9 → 1.22.0-beta-11

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,604 +0,0 @@
1
- import { j as n, aN as v, aP as J, aO as K } from "./@vendor-BfI9BrhH.js";
2
- import V, { useState as q, useEffect as Y, forwardRef as G, useMemo as E } from "react";
3
- import z, { getDefaultRegistry as Q } from "@rjsf/core";
4
- import { T as O, j as w, c as N, b as F, S as X, i as Z, g as ee, a as te, d as R, e as ne } from "./@code-editor-DlyF0flC.js";
5
- import { getUiOptions as B, getTemplate as $, getSubmitButtonOptions as re, ADDITIONAL_PROPERTY_FLAG as L, errorId as se, englishStringTranslator as ae, TranslatableString as oe, titleId as le, canExpand as ie, deepEquals as ce } from "@rjsf/utils";
6
- import { ReactComponent as de } from "./assets/ic-add.cfaa779b.svg";
7
- import { ReactComponent as ue } from "./assets/ic-warning.ecf7ff97.svg";
8
- import { ReactComponent as me } from "./assets/ic-cross.01e03666.svg";
9
- import './assets/@common-rjsf.css';const P = {
10
- SELECT: "Please select an option",
11
- INPUT: "Please enter an input",
12
- OBJECT_KEY: "Please enter a value for the key"
13
- }, pe = "Key not available", Je = {
14
- "ui:submitButtonOptions": {
15
- norender: !0
16
- }
17
- }, U = "rjsf-form-select-portal-target", fe = ({
18
- children: e,
19
- disabled: t,
20
- hasToolbar: s,
21
- hasRemove: r,
22
- index: a,
23
- onDropIndexClick: i,
24
- readonly: l,
25
- registry: o,
26
- uiSchema: c
27
- }) => {
28
- const { RemoveButton: d } = o.templates.ButtonTemplates;
29
- return /* @__PURE__ */ n.jsxs("div", { className: "dc__position-rel display-grid rjsf-form-template__array-field-item flex-align-center", children: [
30
- e,
31
- /* @__PURE__ */ n.jsx("div", { className: "dc__position-abs remove-btn__container", style: { right: "-28px", top: "9px" }, children: s && r && /* @__PURE__ */ n.jsx(
32
- d,
33
- {
34
- disabled: t || l,
35
- onClick: i(a),
36
- uiSchema: c,
37
- registry: o
38
- }
39
- ) })
40
- ] });
41
- }, S = ({
42
- showLabel: e,
43
- label: t,
44
- required: s,
45
- children: r,
46
- id: a,
47
- rawDescription: i,
48
- shouldAlignCenter: l = !0
49
- }) => /* @__PURE__ */ n.jsxs(
50
- "div",
51
- {
52
- className: e ? `display-grid dc__gap-12 rjsf-form-template__field ${l ? "" : "rjsf-form-template__field--align-top"}` : "",
53
- children: [
54
- e && /* @__PURE__ */ n.jsxs("label", { className: "cn-7 fs-13 lh-20 fw-4 flexbox mb-0", htmlFor: a, children: [
55
- /* @__PURE__ */ n.jsx(O, { alwaysShowTippyOnHover: !!i, content: i, children: /* @__PURE__ */ n.jsx("span", { className: `dc__ellipsis-right ${i ? "dc__underline-dotted" : ""}`, children: t || pe }) }),
56
- s && /* @__PURE__ */ n.jsx("span", { className: "cr-5", children: " *" })
57
- ] }),
58
- r
59
- ]
60
- }
61
- ), A = ({ label: e, canAdd: t, onAddClick: s, disabled: r, readonly: a, uiSchema: i, registry: l }) => {
62
- const {
63
- ButtonTemplates: { AddButton: o }
64
- } = l.templates;
65
- return t && /* @__PURE__ */ n.jsx(
66
- o,
67
- {
68
- label: e,
69
- onClick: s,
70
- disabled: r || a,
71
- uiSchema: i,
72
- registry: l
73
- }
74
- );
75
- }, he = ({
76
- canAdd: e,
77
- className: t,
78
- disabled: s,
79
- idSchema: r,
80
- uiSchema: a,
81
- items: i,
82
- onAddClick: l,
83
- readonly: o,
84
- registry: c,
85
- required: d,
86
- title: f
87
- }) => {
88
- const m = B(a), h = $("ArrayFieldItemTemplate", c, m), u = m.title || f;
89
- return /* @__PURE__ */ n.jsx("fieldset", { className: t, id: r.$id, children: i.length ? /* @__PURE__ */ n.jsxs(n.Fragment, { children: [
90
- i.map(({ key: x, ...p }, j) => {
91
- const _ = {
92
- ...p.children,
93
- props: {
94
- ...p.children.props
95
- }
96
- };
97
- return /* @__PURE__ */ n.jsx(h, { ...p, children: _ }, x);
98
- }),
99
- /* @__PURE__ */ n.jsx(
100
- A,
101
- {
102
- label: u,
103
- canAdd: e,
104
- onAddClick: l,
105
- disabled: s,
106
- readonly: o,
107
- uiSchema: a,
108
- registry: c
109
- }
110
- )
111
- ] }) : /* @__PURE__ */ n.jsx(S, { label: u, required: d, showLabel: !0, id: r.$id, children: /* @__PURE__ */ n.jsx(
112
- A,
113
- {
114
- label: u,
115
- canAdd: e,
116
- onAddClick: l,
117
- disabled: s,
118
- readonly: o,
119
- uiSchema: a,
120
- registry: c
121
- }
122
- ) }) });
123
- }, {
124
- templates: { BaseInputTemplate: _e }
125
- } = Q(), xe = ({ placeholder: e, ...t }) => {
126
- const { schema: s } = t;
127
- return /* @__PURE__ */ n.jsx(
128
- _e,
129
- {
130
- placeholder: s.placeholder || e || P.INPUT,
131
- ...t,
132
- className: "form__input cn-9 fs-13 lh-20 fw-4"
133
- }
134
- );
135
- }, k = ({
136
- label: e,
137
- icon: t,
138
- iconType: s,
139
- registry: r,
140
- uiSchema: a,
141
- ...i
142
- }) => {
143
- const l = `Add ${e}`;
144
- return /* @__PURE__ */ n.jsx("div", { className: "flexbox flex-justify-start", children: /* @__PURE__ */ n.jsxs(
145
- "button",
146
- {
147
- ...i,
148
- type: "button",
149
- className: "dc__outline-none-imp p-0 dc__transparent flex dc__gap-4 cursor dc__mxw-250",
150
- title: "Add",
151
- children: [
152
- /* @__PURE__ */ n.jsx(de, { className: "icon-dim-16 fcb-5" }),
153
- /* @__PURE__ */ n.jsx(O, { placement: "right", content: l, children: /* @__PURE__ */ n.jsx("span", { className: "cb-5 fs-13 lh-34 dc__truncate", children: l }) })
154
- ]
155
- }
156
- ) });
157
- }, je = ({ icon: e, iconType: t, registry: s, uiSchema: r, ...a }) => /* @__PURE__ */ n.jsx("button", { ...a, type: "button", className: "dc__outline-none-imp p-0 dc__transparent flex cursor", title: "Remove", children: /* @__PURE__ */ n.jsx(me, { className: "icon-dim-16 fcn-6" }) }), ge = ({ uiSchema: e }) => {
158
- const { submitText: t, norender: s, props: r = {} } = re(e);
159
- return s ? null : /* @__PURE__ */ n.jsx("div", { className: "flexbox flex-justify-end", children: /* @__PURE__ */ n.jsx("button", { type: "submit", ...r, className: `cta ${r.className || ""}`, children: t }) });
160
- }, C = ({
161
- id: e,
162
- title: t,
163
- required: s,
164
- description: r
165
- }) => /* @__PURE__ */ n.jsxs("legend", { className: "fs-13 fw-6 cn-9 lh-20 dc__no-border pb-9 mb-0", id: e, children: [
166
- /* @__PURE__ */ n.jsx(O, { alwaysShowTippyOnHover: !!r, content: r, children: /* @__PURE__ */ n.jsx("span", { className: `${r ? "dc__underline-dotted" : ""}`, children: t }) }),
167
- s && /* @__PURE__ */ n.jsx("span", { className: "cr-5", children: " *" })
168
- ] }), be = (e) => {
169
- const {
170
- id: t,
171
- label: s,
172
- children: r,
173
- errors: a,
174
- hidden: i,
175
- required: l,
176
- displayLabel: o,
177
- registry: c,
178
- uiSchema: d,
179
- classNames: f,
180
- schema: m,
181
- rawDescription: h
182
- } = e, u = B(d), x = $(
183
- "WrapIfAdditionalTemplate",
184
- c,
185
- u
186
- ), p = L in m, j = (o || m.type === "boolean") && !p, _ = m.type === "array";
187
- return i ? /* @__PURE__ */ n.jsx("div", { className: "hidden", children: r }) : (
188
- // NOTE: need to override the margins of default rjsf css
189
- /* @__PURE__ */ n.jsxs("div", { className: `${f} mb-0`, children: [
190
- _ && /* @__PURE__ */ n.jsx(
191
- C,
192
- {
193
- id: t,
194
- title: s,
195
- required: l,
196
- registry: c,
197
- uiSchema: d,
198
- schema: m,
199
- description: h
200
- }
201
- ),
202
- /* @__PURE__ */ n.jsx(
203
- S,
204
- {
205
- label: s,
206
- showLabel: j,
207
- id: t,
208
- required: l,
209
- rawDescription: h,
210
- children: /* @__PURE__ */ n.jsx(x, { ...e, children: r })
211
- }
212
- ),
213
- a
214
- ] })
215
- );
216
- }, ye = ({ errors: e = [], idSchema: t }) => {
217
- const s = se(t);
218
- return e.length > 0 && /* @__PURE__ */ n.jsx("span", { className: "display-grid rjsf-form-template__field--error dc__gap-12", id: s, children: e.filter((r) => !!r).map((r, a) => /* @__PURE__ */ n.jsxs(V.Fragment, { children: [
219
- /* @__PURE__ */ n.jsx("span", {}),
220
- /* @__PURE__ */ n.jsxs("span", { className: "form__error", children: [
221
- /* @__PURE__ */ n.jsx(ue, { className: "form__icon form__icon--error" }),
222
- r
223
- ] })
224
- ] }, a)) });
225
- }, Te = (e, t) => {
226
- switch (e) {
227
- case oe.NewStringDefault:
228
- return "";
229
- default:
230
- return ae(e, t);
231
- }
232
- }, Ke = (e) => {
233
- try {
234
- const t = new URL(e).origin === window.location.origin;
235
- return {
236
- href: e,
237
- target: t ? "_self" : "_blank",
238
- rel: t ? void 0 : "external noreferrer",
239
- url: e
240
- };
241
- } catch {
242
- return {
243
- href: e,
244
- target: "_blank",
245
- url: `${e} (Invalid URL)`
246
- };
247
- }
248
- }, Ve = (e) => {
249
- const t = typeof e;
250
- switch (t) {
251
- case "boolean":
252
- case "string":
253
- case "number":
254
- return t;
255
- case "object":
256
- return Array.isArray(e) ? "array" : e === null ? "null" : t;
257
- default:
258
- return "null";
259
- }
260
- }, T = (e) => {
261
- if (!e)
262
- return "";
263
- const t = e.trim(), r = (/^\/.+$/g.test(t) ? t : `/${t}`).replaceAll(/\./g, "/");
264
- return /(\/(([^/~])|(~[01]))*)/g.test(r) ? r : "";
265
- }, I = {
266
- value: !1,
267
- path: ""
268
- }, ve = (e) => {
269
- if (!e)
270
- return null;
271
- const t = structuredClone(e);
272
- return typeof t == "string" ? {
273
- value: !0,
274
- path: T(t)
275
- } : typeof t != "object" ? structuredClone(I) : Object.hasOwn(t, "condition") && "condition" in t && Object.hasOwn(t, "value") && "value" in t ? {
276
- value: t.condition,
277
- path: T(t.value)
278
- } : Object.hasOwn(t, "value") && "value" in t && Object.hasOwn(t, "path") && "path" in t ? {
279
- value: t.value,
280
- path: T(t.path)
281
- } : structuredClone(I);
282
- }, H = (e, t, s) => {
283
- e && (e.type === "object" && e.properties && typeof e.properties == "object" && Object.entries(e.properties).forEach(([r, a]) => {
284
- H(a, `${t}/${r}`, s);
285
- }), (e.type === "boolean" || e.type === "string" || e.type === "number" || e.type === "integer") && (s[t] = T(e.updatePath ?? t)));
286
- }, Ne = (e) => {
287
- const t = {};
288
- return H(e, "", t), t;
289
- }, M = (e, t, s) => {
290
- if (t >= s.length)
291
- return e;
292
- const r = s[t];
293
- if (t === s.length - 1) {
294
- const a = structuredClone(e);
295
- return delete a[r], a;
296
- }
297
- if (e[r] && (e[r] = M(e[r], t + 1, s)), Object.keys(e[r] ?? {}).length === 0) {
298
- const a = structuredClone(e);
299
- return delete a[r], a;
300
- }
301
- return e;
302
- }, Se = (e, t) => {
303
- if (!e || typeof e != "object" || Array.isArray(e))
304
- throw new Error("Invalid object");
305
- if (!t || !t.startsWith("/"))
306
- throw new Error("Invalid path");
307
- const s = t.split("/").slice(1);
308
- return M(e, 0, s);
309
- }, D = ({
310
- formState: e,
311
- formData: t,
312
- schemaPathToUpdatePathMap: s
313
- }) => {
314
- let r = structuredClone(e);
315
- return r && (Object.entries(s).forEach(([a, i]) => {
316
- if (a === i || !i)
317
- return;
318
- const l = v({
319
- json: t,
320
- path: N(a),
321
- resultType: "value",
322
- wrap: !1
323
- });
324
- l === void 0 ? r = Se(r, a) : r = w([F(a, l), r]);
325
- const o = v({
326
- json: e,
327
- path: N(a),
328
- resultType: "value",
329
- wrap: !1
330
- });
331
- o !== void 0 && (r = w([F(i, o), r]));
332
- }), t && r ? J(t, K(t, r), !1, !1).newDocument : r);
333
- }, we = ({ formData: e, schemaPathToUpdatePathMap: t }) => w([
334
- ...Object.entries(t).map(([s, r]) => {
335
- if (s === r || !r)
336
- return {};
337
- const a = v({
338
- json: e,
339
- path: N(r),
340
- resultType: "value",
341
- wrap: !1
342
- });
343
- return a === void 0 ? {} : F(s, a);
344
- }),
345
- structuredClone(e)
346
- ]), Fe = ({
347
- disabled: e,
348
- formData: t,
349
- idSchema: s,
350
- onAddClick: r,
351
- properties: a,
352
- readonly: i,
353
- registry: l,
354
- required: o,
355
- schema: c,
356
- title: d,
357
- uiSchema: f,
358
- formContext: m
359
- }) => {
360
- const h = !!c.additionalProperties, u = ie(c, f, t) && /* @__PURE__ */ n.jsx(
361
- k,
362
- {
363
- label: d,
364
- className: "object-property-expand",
365
- onClick: r(c),
366
- disabled: e || i,
367
- uiSchema: f,
368
- registry: l
369
- }
370
- ), x = a.filter((p) => {
371
- const j = c.properties?.[p.name]?.hidden;
372
- if (!j)
373
- return !0;
374
- try {
375
- const _ = ve(j);
376
- if (!_.path)
377
- throw new Error("Empty path property of hidden descriptor field");
378
- const y = v({
379
- path: N(_.path),
380
- json: m,
381
- resultType: "value",
382
- wrap: !1
383
- });
384
- return !(y === void 0 || ce(_.value, y));
385
- } catch {
386
- return !0;
387
- }
388
- }).map((p) => p.content);
389
- return h ? a.length ? /* @__PURE__ */ n.jsxs(n.Fragment, { children: [
390
- /* @__PURE__ */ n.jsx(
391
- S,
392
- {
393
- label: d,
394
- required: o,
395
- showLabel: !0,
396
- id: s.$id,
397
- shouldAlignCenter: !1,
398
- children: /* @__PURE__ */ n.jsx("div", { children: x })
399
- }
400
- ),
401
- u
402
- ] }) : /* @__PURE__ */ n.jsx(S, { label: d, required: o, showLabel: !0, id: s.$id, children: u }) : /* @__PURE__ */ n.jsxs(n.Fragment, { children: [
403
- x,
404
- u
405
- ] });
406
- }, Oe = (e) => {
407
- const { idSchema: t, registry: s, required: r, schema: a, title: i, uiSchema: l, description: o } = e, c = !!a.additionalProperties, d = i && !c;
408
- return /* @__PURE__ */ n.jsxs("fieldset", { id: t.$id, children: [
409
- d && /* @__PURE__ */ n.jsx(
410
- C,
411
- {
412
- id: le(t),
413
- title: i,
414
- required: r,
415
- schema: a,
416
- uiSchema: l,
417
- registry: s,
418
- description: o
419
- }
420
- ),
421
- /* @__PURE__ */ n.jsx(
422
- "div",
423
- {
424
- className: `${a.properties && !c && t.$id !== "root" ? "dc__border-left pl-12" : ""} ${t.$id === "root" ? "dc__separated-flexbox dc__separated-flexbox--vertical" : "flexbox-col dc__gap-8"}`,
425
- children: /* @__PURE__ */ n.jsx(Fe, { ...e })
426
- }
427
- )
428
- ] });
429
- }, Pe = ({
430
- id: e,
431
- disabled: t,
432
- label: s,
433
- onKeyChange: r,
434
- onDropPropertyClick: a,
435
- readonly: i,
436
- schema: l,
437
- children: o,
438
- uiSchema: c,
439
- registry: d
440
- }) => {
441
- const { templates: f } = d, { RemoveButton: m } = f.ButtonTemplates, h = L in l;
442
- return /* @__PURE__ */ n.jsx(n.Fragment, { children: h ? /* @__PURE__ */ n.jsxs("div", { className: "dc__position-rel rjsf-form-template__additional-fields display-grid dc__gap-8 flex-align-center", children: [
443
- /* @__PURE__ */ n.jsx("div", { children: /* @__PURE__ */ n.jsx(
444
- "input",
445
- {
446
- type: "text",
447
- className: "form__input cn-9 fs-13 lh-20 fw-4",
448
- id: `${e}-key`,
449
- onBlur: (u) => r(u.target.value),
450
- placeholder: P.OBJECT_KEY,
451
- defaultValue: s
452
- }
453
- ) }),
454
- /* @__PURE__ */ n.jsx("div", { children: o }),
455
- /* @__PURE__ */ n.jsx("div", { className: "dc__position-abs remove-btn__container", style: { right: "-28px", top: "9px" }, children: /* @__PURE__ */ n.jsx(
456
- m,
457
- {
458
- disabled: t || i,
459
- onClick: a(s),
460
- uiSchema: c,
461
- registry: d
462
- }
463
- ) })
464
- ] }) : o });
465
- }, Ce = ({
466
- id: e,
467
- onChange: t,
468
- value: s,
469
- disabled: r,
470
- readonly: a,
471
- autofocus: i
472
- }) => {
473
- const l = Z(s) ? !1 : s, o = () => {
474
- t(!l);
475
- };
476
- return /* @__PURE__ */ n.jsxs("div", { className: "flexbox dc__align-items-center dc__gap-8", children: [
477
- /* @__PURE__ */ n.jsx(
478
- X,
479
- {
480
- name: e,
481
- ariaLabel: e,
482
- onChange: o,
483
- isChecked: l,
484
- autoFocus: i,
485
- isDisabled: r || a
486
- }
487
- ),
488
- /* @__PURE__ */ n.jsx("span", { className: "dc__capitalize", children: l.toString() })
489
- ] });
490
- }, Ee = (e) => {
491
- const {
492
- id: t,
493
- multiple: s = !1,
494
- options: r,
495
- value: a,
496
- disabled: i,
497
- readonly: l,
498
- autofocus: o = !1,
499
- onChange: c,
500
- onBlur: d,
501
- onFocus: f,
502
- placeholder: m,
503
- schema: h
504
- } = e, { enumOptions: u = [] } = r, x = s ? [] : null, p = (g) => {
505
- c(s ? g.map((b) => b.value) : g.value);
506
- }, [j, _] = q();
507
- Y(() => {
508
- _(ee(8));
509
- }, []);
510
- const y = (g) => s ? u.filter((b) => g.some((W) => R(W, b.value))) : u.find((b) => R(g, b.value));
511
- return /* @__PURE__ */ n.jsx(
512
- te,
513
- {
514
- inputId: `devtron-rjsf-select__${t}`,
515
- name: t,
516
- isMulti: s,
517
- value: typeof a > "u" ? x : y(a),
518
- autoFocus: o,
519
- onChange: p,
520
- options: u,
521
- onBlur: () => d(t, a),
522
- onFocus: () => f(t, a),
523
- placeholder: h.placeholder || m || P.SELECT,
524
- isDisabled: i || l,
525
- menuPortalTarget: document.getElementById(U),
526
- menuPosition: "fixed"
527
- },
528
- j
529
- );
530
- }, Re = {
531
- CheckboxWidget: Ce,
532
- SelectWidget: Ee
533
- }, Ae = {
534
- ArrayFieldItemTemplate: fe,
535
- ArrayFieldTemplate: he,
536
- BaseInputTemplate: xe,
537
- ButtonTemplates: { AddButton: k, RemoveButton: je, SubmitButton: ge },
538
- FieldTemplate: be,
539
- FieldErrorTemplate: ye,
540
- ObjectFieldTemplate: Oe,
541
- TitleFieldTemplate: C,
542
- WrapIfAdditionalTemplate: Pe
543
- }, Ie = z, De = ne, qe = G((e, t) => {
544
- const { schemaPathToUpdatePathMap: s, isUpdatePathKeywordPresent: r } = E(() => {
545
- const o = Ne(e.schema);
546
- return {
547
- schemaPathToUpdatePathMap: o,
548
- isUpdatePathKeywordPresent: Object.entries(o).some(([c, d]) => c !== d)
549
- };
550
- }, [e.schema]), a = E(() => r ? we({ formData: e.formData ?? {}, schemaPathToUpdatePathMap: s }) : e.formData, [e.formData, s, r]), i = (o) => {
551
- if (!e.onChange)
552
- return;
553
- const c = D({
554
- formState: o.formData,
555
- formData: e.formData,
556
- schemaPathToUpdatePathMap: s
557
- });
558
- e.onChange({ ...o, formData: c });
559
- }, l = (o, c) => {
560
- if (!e.onSubmit)
561
- return;
562
- const d = D({
563
- formState: o.formData,
564
- formData: e.formData,
565
- schemaPathToUpdatePathMap: s
566
- });
567
- e.onSubmit?.({ ...o, formData: d }, c);
568
- };
569
- return /* @__PURE__ */ n.jsxs(n.Fragment, { children: [
570
- /* @__PURE__ */ n.jsx(
571
- Ie,
572
- {
573
- noHtml5Validate: !0,
574
- showErrorList: !1,
575
- autoComplete: "off",
576
- ...e,
577
- formData: a,
578
- ...r ? {
579
- onChange: i,
580
- onSubmit: l
581
- } : {},
582
- className: `rjsf-form-template__container ${e.className || ""}`,
583
- validator: De,
584
- templates: {
585
- ...Ae,
586
- ...e.templates
587
- },
588
- formContext: a,
589
- widgets: { ...Re, ...e.widgets },
590
- translateString: Te,
591
- ref: t
592
- }
593
- ),
594
- /* @__PURE__ */ n.jsx("div", { id: U })
595
- ] });
596
- });
597
- export {
598
- Je as H,
599
- qe as R,
600
- Ke as a,
601
- Ne as b,
602
- T as c,
603
- Ve as g
604
- };