@box/metadata-template-editor 1.20.9 → 1.20.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.
Files changed (95) hide show
  1. package/dist/chunks/chip.js +21 -0
  2. package/dist/chunks/dropdown-field-configuration.js +62 -0
  3. package/dist/chunks/field-context-menu.js +90 -0
  4. package/dist/chunks/field-selector.js +23 -0
  5. package/dist/chunks/field-type-dropdown.js +31 -0
  6. package/dist/chunks/levels-chain.js +125 -0
  7. package/dist/chunks/metadata-field-configurator.module.js +17 -16
  8. package/dist/chunks/metadata-field-list.js +229 -0
  9. package/dist/chunks/metadata-template-editor-form.js +107 -0
  10. package/dist/chunks/metadata-template-editor-modal.js +77 -0
  11. package/dist/chunks/metadata-template-editor.js +157 -0
  12. package/dist/chunks/sortable-option-list.js +231 -0
  13. package/dist/chunks/taxonomy-field-configuration.js +126 -0
  14. package/dist/chunks/taxonomy-field-configurator-initial-state.js +48 -0
  15. package/dist/chunks/taxonomy-selector.js +90 -0
  16. package/dist/chunks/types.js +22 -33
  17. package/dist/esm/index.js +13 -34
  18. package/dist/esm/lib/components/field-selector/field-selector.js +2 -39
  19. package/dist/esm/lib/components/field-selector/index.js +2 -4
  20. package/dist/esm/lib/components/field-selector/messages.js +10 -12
  21. package/dist/esm/lib/components/field-type-dropdown/field-type-dropdown.js +2 -47
  22. package/dist/esm/lib/components/field-type-dropdown/index.js +2 -4
  23. package/dist/esm/lib/components/field-type-dropdown/messages.js +10 -12
  24. package/dist/esm/lib/components/field-type-tiles/field-type-tiles.js +32 -39
  25. package/dist/esm/lib/components/field-type-tiles/index.js +2 -4
  26. package/dist/esm/lib/components/field-type-tiles/messages.js +10 -12
  27. package/dist/esm/lib/components/metadata-field-configurator/components/confirmation-modal/confirmation-modal.js +32 -45
  28. package/dist/esm/lib/components/metadata-field-configurator/components/confirmation-modal/messages.js +14 -16
  29. package/dist/esm/lib/components/metadata-field-configurator/components/field-action-slot/field-action-slot.js +62 -79
  30. package/dist/esm/lib/components/metadata-field-configurator/components/field-context-menu/field-context-menu.js +2 -115
  31. package/dist/esm/lib/components/metadata-field-configurator/components/field-edit-content/field-edit-content.js +83 -100
  32. package/dist/esm/lib/components/metadata-field-configurator/components/levels-chain/chip.js +2 -33
  33. package/dist/esm/lib/components/metadata-field-configurator/components/levels-chain/index.js +2 -4
  34. package/dist/esm/lib/components/metadata-field-configurator/components/levels-chain/levels-chain.js +2 -118
  35. package/dist/esm/lib/components/metadata-field-configurator/components/levels-chain/utils.js +16 -33
  36. package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/dropdown/__mocks__/getInitialValues.js +34 -32
  37. package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/dropdown/dropdown-default-values.js +10 -14
  38. package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/dropdown/dropdown-field-configuration.js +2 -66
  39. package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/dropdown/sortable-option-list.js +2 -294
  40. package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/index.js +3 -6
  41. package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/taxonomy-default-values.js +11 -15
  42. package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/taxonomy-field-configuration.js +2 -149
  43. package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/taxonomy-field-configurator-initial-state.js +2 -54
  44. package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/taxonomy-selector-messages.js +34 -36
  45. package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/taxonomy-selector.js +2 -103
  46. package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/useTaxonomySelect.js +15 -19
  47. package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/utils.js +2 -4
  48. package/dist/esm/lib/components/metadata-field-configurator/context/field-configurator-context.js +60 -66
  49. package/dist/esm/lib/components/metadata-field-configurator/context/field-extensions-context.js +5 -8
  50. package/dist/esm/lib/components/metadata-field-configurator/context/taxonomy-options-context.js +14 -20
  51. package/dist/esm/lib/components/metadata-field-configurator/hooks/useFieldConfiguratorBehavior.js +99 -118
  52. package/dist/esm/lib/components/metadata-field-configurator/hooks/useFieldValidation.js +52 -66
  53. package/dist/esm/lib/components/metadata-field-configurator/hooks/useTaxonomyFetch.js +23 -26
  54. package/dist/esm/lib/components/metadata-field-configurator/hooks/useTemplateFieldSchema.js +34 -43
  55. package/dist/esm/lib/components/metadata-field-configurator/index.js +5 -11
  56. package/dist/esm/lib/components/metadata-field-configurator/messages/configurator-messages.js +131 -134
  57. package/dist/esm/lib/components/metadata-field-configurator/messages/dropdown-messages.js +34 -36
  58. package/dist/esm/lib/components/metadata-field-configurator/messages/levels-chain-messages.js +14 -16
  59. package/dist/esm/lib/components/metadata-field-configurator/messages/taxonomy-messages.js +34 -36
  60. package/dist/esm/lib/components/metadata-field-configurator/metadata-field-configurator.js +94 -153
  61. package/dist/esm/lib/components/metadata-field-configurator/utils.js +42 -49
  62. package/dist/esm/lib/components/metadata-field-list/index.js +2 -5
  63. package/dist/esm/lib/components/metadata-field-list/metadata-field-list.js +2 -279
  64. package/dist/esm/lib/components/metadata-template-editor-form/metadata-template-editor-form.js +2 -137
  65. package/dist/esm/lib/components/metadata-template-editor-modal/index.js +2 -4
  66. package/dist/esm/lib/components/metadata-template-editor-modal/metadata-template-editor-modal.js +2 -103
  67. package/dist/esm/lib/hooks/useMetadataTemplateFormSchema.js +13 -15
  68. package/dist/esm/lib/hooks/useTemplateNameSchema.js +8 -10
  69. package/dist/esm/lib/index.js +7 -14
  70. package/dist/esm/lib/messages.js +114 -116
  71. package/dist/esm/lib/metadata-template-editor.js +2 -182
  72. package/dist/esm/lib/utils/constants.js +2 -8
  73. package/dist/esm/lib/utils/field-options/field-type-icon.js +14 -33
  74. package/dist/esm/lib/utils/field-options/index.js +4 -9
  75. package/dist/esm/lib/utils/field-options/messages.js +43 -46
  76. package/dist/esm/lib/utils/field-options/useFieldOptions.js +14 -18
  77. package/dist/esm/lib/utils/key-generation.js +16 -27
  78. package/dist/esm/lib/utils/template-type-conversion/convertLocalConfiguratorToTemplateField.js +63 -77
  79. package/dist/esm/lib/utils/template-type-conversion/convertTemplateFieldToLocalConfigurator.js +69 -89
  80. package/dist/esm/lib/utils/template-type-conversion/generateJSONPatchTemplateOperations.js +150 -169
  81. package/dist/esm/lib/utils/template-type-conversion/mapFieldsWithUniqueKeys.js +8 -13
  82. package/dist/styles/chip.css +1 -1
  83. package/dist/styles/dropdown-field-configuration.css +1 -1
  84. package/dist/styles/field-context-menu.css +1 -1
  85. package/dist/styles/levels-chain.css +1 -1
  86. package/dist/styles/metadata-field-configurator.css +1 -1
  87. package/dist/styles/metadata-field-list.css +1 -1
  88. package/dist/styles/metadata-template-editor-form.css +1 -1
  89. package/dist/styles/metadata-template-editor-modal.css +1 -1
  90. package/dist/styles/metadata-template-editor.css +1 -1
  91. package/dist/styles/sortable-option-list.css +1 -1
  92. package/dist/styles/taxonomy-field-configuration.css +1 -1
  93. package/dist/styles/taxonomy-field-configurator-initial-state.css +1 -1
  94. package/dist/styles/taxonomy-selector.css +1 -1
  95. package/package.json +6 -6
@@ -0,0 +1,107 @@
1
+ import { t as e } from "./field-selector.js";
2
+ import { t } from "./field-type-dropdown.js";
3
+ import { FieldTypeTiles as n } from "../esm/lib/components/field-type-tiles/field-type-tiles.js";
4
+ import { FieldExtensionsContext as r } from "../esm/lib/components/metadata-field-configurator/context/field-extensions-context.js";
5
+ import { createDefaultFieldValues as i } from "../esm/lib/components/metadata-field-configurator/utils.js";
6
+ import { t as a } from "./metadata-field-list.js";
7
+ import o from "../esm/lib/messages.js";
8
+ import { Button as s, Link as c, Text as l, TextInput as u } from "@box/blueprint-web";
9
+ import { FormattedMessage as d, useIntl as f } from "react-intl";
10
+ import { Fragment as p, jsx as m, jsxs as h } from "react/jsx-runtime";
11
+ import { useEffect as g, useMemo as _, useRef as v } from "react";
12
+ import { Form as y, useFormikContext as b } from "formik";
13
+ import '../styles/metadata-template-editor-form.css';var x = {
14
+ form: "_form_8cb30_1",
15
+ loading: "_loading_8cb30_8",
16
+ fields: "_fields_8cb30_15",
17
+ actions: "_actions_8cb30_21",
18
+ fieldsHeader: "_fieldsHeader_8cb30_28"
19
+ }, S = "bodyDefaultBold", C = "h2", w = "https://developer.box.com/guides/metadata/fields/", T = ({ formId: T, onCancel: E, taxonomyOptions: D, fetchTaxonomies: O, hideActions: k, isEditMode: A, onDirtyStateChange: j, onValidationChange: M, fieldExtensions: N }) => {
20
+ let P = f(), { errors: F, values: I, setFieldValue: L, isSubmitting: R, isValid: z, touched: B, handleChange: V, handleBlur: H, submitCount: U, dirty: W } = b(), G = v(null), K = _(() => {
21
+ if (!Array.isArray(F.fields)) return null;
22
+ let e = F.fields.findIndex(Boolean);
23
+ return e >= 0 ? e : null;
24
+ }, [F.fields]), q = (e) => {
25
+ let t = i(e.type);
26
+ L("fields", [...I.fields, t]);
27
+ }, J = (e) => {
28
+ L("fields", e);
29
+ };
30
+ g(() => {
31
+ j?.(W);
32
+ }, [W, j]), g(() => {
33
+ M?.(z);
34
+ }, [z, M]);
35
+ let Y = R || A && !W, X = /* @__PURE__ */ h(y, {
36
+ noValidate: !0,
37
+ id: T,
38
+ className: x.form,
39
+ children: [
40
+ /* @__PURE__ */ m("div", {
41
+ className: x.templateInfo,
42
+ children: /* @__PURE__ */ m(u, {
43
+ name: "displayName",
44
+ label: P.formatMessage(o.templateName),
45
+ placeholder: P.formatMessage(o.templateNameDescription),
46
+ value: I.displayName,
47
+ error: B.displayName && F.displayName ? F.displayName : void 0,
48
+ onChange: (e) => {
49
+ V(e);
50
+ },
51
+ onBlur: H
52
+ })
53
+ }),
54
+ /* @__PURE__ */ h("div", {
55
+ className: x.fieldsHeader,
56
+ children: [/* @__PURE__ */ m(l, {
57
+ as: C,
58
+ variant: S,
59
+ children: /* @__PURE__ */ m(d, { ...I.fields.length === 0 ? o.fieldsAddFirst : o.fields })
60
+ }), I.fields.length > 0 && /* @__PURE__ */ m(e, {
61
+ fields: I.fields,
62
+ onSelect: (e) => G.current?.scrollToAndExpand(e)
63
+ })]
64
+ }),
65
+ /* @__PURE__ */ m("div", {
66
+ className: x.fields,
67
+ children: I.fields.length === 0 ? /* @__PURE__ */ h(p, { children: [/* @__PURE__ */ m(n, { onFieldAdd: q }), /* @__PURE__ */ m(c, {
68
+ isExternal: !0,
69
+ className: x.fieldsLearnMoreLink,
70
+ href: w,
71
+ target: "_blank",
72
+ children: /* @__PURE__ */ m(d, { ...o.fieldsLearnMore })
73
+ })] }) : /* @__PURE__ */ h(p, { children: [/* @__PURE__ */ m(a, {
74
+ ref: G,
75
+ fields: I.fields,
76
+ taxonomyOptions: D,
77
+ fetchTaxonomies: O,
78
+ onChangeFields: J,
79
+ firstInvalidFieldIndex: K,
80
+ submitAttemptCount: U
81
+ }), /* @__PURE__ */ m(t, { onFieldAdd: q })] })
82
+ }),
83
+ !k && /* @__PURE__ */ h("div", {
84
+ className: x.actions,
85
+ children: [E && /* @__PURE__ */ m(s, {
86
+ variant: "secondary",
87
+ type: "button",
88
+ onClick: E,
89
+ loading: R,
90
+ disabled: R,
91
+ loadingAriaLabel: P.formatMessage(o.submitting),
92
+ children: P.formatMessage(o.cancel)
93
+ }), /* @__PURE__ */ m(s, {
94
+ variant: "primary",
95
+ type: "submit",
96
+ disabled: Y,
97
+ children: P.formatMessage(o.save)
98
+ })]
99
+ })
100
+ ]
101
+ });
102
+ return N === void 0 ? X : /* @__PURE__ */ m(r.Provider, {
103
+ value: N,
104
+ children: X
105
+ });
106
+ };
107
+ export { T as t };
@@ -0,0 +1,77 @@
1
+ import { o as e } from "./types.js";
2
+ import t from "../esm/lib/messages.js";
3
+ import { t as n } from "./metadata-template-editor.js";
4
+ import { Modal as r } from "@box/blueprint-web";
5
+ import { useIntl as i } from "react-intl";
6
+ import { jsx as a, jsxs as o } from "react/jsx-runtime";
7
+ import { useCallback as s, useEffect as c, useId as l, useRef as u, useState as d } from "react";
8
+ import f from "clsx";
9
+ import '../styles/metadata-template-editor-modal.css';var p = {
10
+ modal: "_modal_q1b7q_1",
11
+ centeredBody: "_centeredBody_q1b7q_7"
12
+ };
13
+ function m({ open: m, onOpenChange: h, onTemplateLoad: g, onValidationChange: _, onCancel: v, title: y, ...b }) {
14
+ let x = i(), S = l(), C = u(null), [w, T] = d(!1), [E, D] = d(!1), [O, k] = d(void 0), A = b.mode === e.Edit, j = s(() => {
15
+ v?.(), h(!1);
16
+ }, [v, h]);
17
+ c(() => {
18
+ m || (D(!1), k(void 0));
19
+ }, [m]);
20
+ let M = (e) => {
21
+ e ? h(e) : C.current?.requestClose();
22
+ }, N = (e) => {
23
+ k(e.displayName), g?.(e);
24
+ }, P = (e) => async (...t) => {
25
+ T(!0);
26
+ try {
27
+ await e(...t), h(!1);
28
+ } finally {
29
+ T(!1);
30
+ }
31
+ }, F = A ? {
32
+ ...b,
33
+ onEditTemplate: P(b.onEditTemplate)
34
+ } : {
35
+ ...b,
36
+ onCreateTemplate: P(b.onCreateTemplate)
37
+ }, I = w || A && !E, L = A && !O;
38
+ return /* @__PURE__ */ a(r, {
39
+ open: m,
40
+ onOpenChange: M,
41
+ children: /* @__PURE__ */ o(r.Content, {
42
+ size: "large",
43
+ className: p.modal,
44
+ children: [
45
+ /* @__PURE__ */ a(r.Header, { children: y ?? (A && O ? x.formatMessage(t.editTitle, { templateName: O }) : x.formatMessage(t.createTitle)) }),
46
+ /* @__PURE__ */ a(r.ScrollableContainer, {
47
+ className: f({ [p.centeredBody]: L }),
48
+ children: /* @__PURE__ */ a(r.Body, { children: /* @__PURE__ */ a(n, {
49
+ ...F,
50
+ ref: C,
51
+ formId: S,
52
+ hideActions: !0,
53
+ onCancel: j,
54
+ onDirtyStateChange: D,
55
+ onValidationChange: _,
56
+ onTemplateLoad: N
57
+ }) })
58
+ }),
59
+ /* @__PURE__ */ o(r.Footer, { children: [/* @__PURE__ */ a(r.Footer.SecondaryButton, {
60
+ onClick: () => C.current?.requestClose(),
61
+ size: "large",
62
+ children: x.formatMessage(t.cancel)
63
+ }), /* @__PURE__ */ a(r.Footer.PrimaryButton, {
64
+ variant: "primary",
65
+ type: "submit",
66
+ form: S,
67
+ loading: w,
68
+ loadingAriaLabel: x.formatMessage(t.submitting),
69
+ disabled: I,
70
+ children: x.formatMessage(t.save)
71
+ })] }),
72
+ /* @__PURE__ */ a(r.Close, { "aria-label": x.formatMessage(t.closeAriaLabel) })
73
+ ]
74
+ })
75
+ });
76
+ }
77
+ export { m as t };
@@ -0,0 +1,157 @@
1
+ import { o as e } from "./types.js";
2
+ import "../esm/lib/utils/constants.js";
3
+ import t from "../esm/lib/components/metadata-field-configurator/components/confirmation-modal/confirmation-modal.js";
4
+ import n from "../esm/lib/messages.js";
5
+ import { useMetadataTemplateFormSchema as r } from "../esm/lib/hooks/useMetadataTemplateFormSchema.js";
6
+ import { convertApiMetadataTemplateFieldToLocalConfiguratorField as i } from "../esm/lib/utils/template-type-conversion/convertTemplateFieldToLocalConfigurator.js";
7
+ import { mapFieldsWithUniqueKeys as a } from "../esm/lib/utils/template-type-conversion/mapFieldsWithUniqueKeys.js";
8
+ import { generateJSONPatchTemplateOperations as ee } from "../esm/lib/utils/template-type-conversion/generateJSONPatchTemplateOperations.js";
9
+ import { t as o } from "./metadata-template-editor-form.js";
10
+ import { EmptyState as s, LoadingIndicator as c, Text as l, useNotification as u } from "@box/blueprint-web";
11
+ import { useIntl as d } from "react-intl";
12
+ import { Fragment as te, jsx as f, jsxs as ne } from "react/jsx-runtime";
13
+ import { forwardRef as p, useCallback as m, useEffect as h, useImperativeHandle as re, useMemo as g, useState as _ } from "react";
14
+ import { ArrowsRotating as v } from "@box/blueprint-web-assets/icons/Line";
15
+ import { Formik as y } from "formik";
16
+ import { ErrorState404 as b } from "@box/blueprint-web-assets/illustrations/Medium";
17
+ import '../styles/metadata-template-editor.css';var x = {
18
+ form: "_form_1o2vk_1",
19
+ loading: "_loading_1o2vk_8",
20
+ error: "_error_1o2vk_15",
21
+ fields: "_fields_1o2vk_24",
22
+ addField: "_addField_1o2vk_30",
23
+ actions: "_actions_1o2vk_34"
24
+ }, ie = {
25
+ displayName: "",
26
+ templateKey: "",
27
+ fields: [],
28
+ hidden: !1
29
+ }, S = /* @__PURE__ */ p(function({ onCancel: p, onDirtyStateChange: S, onValidationChange: C, onSubmitError: w, onTemplateLoad: T, taxonomyOptions: E, fetchTaxonomies: D, formId: O, hideActions: k = !1, fieldExtensions: A, ...j }, M) {
30
+ let N = r(), { formatMessage: P } = d(), { addNotification: F } = u(), I = j.mode === e.Edit, [L, R] = _(!1), [z, B] = _(!1), V = m(() => {
31
+ L ? B(!0) : p?.();
32
+ }, [L, p]);
33
+ re(M, () => ({ requestClose: V }), [V]);
34
+ let H = m((e) => {
35
+ R(e), S?.(e);
36
+ }, [S]), [U, W] = _(I), [G, K] = _(!1), [q, J] = _(0), [Y, X] = _(void 0), Z = I ? j.fetchTemplate : void 0, ae = () => {
37
+ J((e) => e + 1);
38
+ };
39
+ h(() => {
40
+ if (!Z) return;
41
+ let e = !1;
42
+ return W(!0), K(!1), X(void 0), (async () => {
43
+ try {
44
+ let t = await Z();
45
+ e || X(t);
46
+ } catch {
47
+ e || K(!0);
48
+ } finally {
49
+ e || W(!1);
50
+ }
51
+ })(), () => {
52
+ e = !0;
53
+ };
54
+ }, [Z, q]), h(() => {
55
+ Y !== void 0 && T?.(Y);
56
+ }, [Y, T]);
57
+ let Q = I ? void 0 : j.namespace, $ = g(() => Y ? {
58
+ displayName: Y.displayName,
59
+ templateKey: Y.templateKey,
60
+ namespace: Y.namespace,
61
+ hidden: Y.isHidden,
62
+ fields: Y.fields.map((e) => i(e))
63
+ } : {
64
+ ...ie,
65
+ namespace: Q ?? ""
66
+ }, [Y, Q]);
67
+ return U ? /* @__PURE__ */ f("div", {
68
+ className: x.loading,
69
+ children: /* @__PURE__ */ f(c, {
70
+ size: "large",
71
+ "aria-label": P(n.loading)
72
+ })
73
+ }) : G ? /* @__PURE__ */ f("div", {
74
+ className: x.error,
75
+ children: /* @__PURE__ */ f(s, {
76
+ body: /* @__PURE__ */ f(l, {
77
+ as: "p",
78
+ children: P(n.fetchError)
79
+ }),
80
+ illustration: b,
81
+ size: "large",
82
+ children: /* @__PURE__ */ f(s.PrimaryAction, {
83
+ startIcon: v,
84
+ onClick: ae,
85
+ children: P(n.reload)
86
+ })
87
+ })
88
+ }) : /* @__PURE__ */ ne(te, { children: [/* @__PURE__ */ f(y, {
89
+ initialValues: $,
90
+ validationSchema: N,
91
+ onSubmit: async (e) => {
92
+ try {
93
+ if (I) {
94
+ let t = ee($, e);
95
+ await j.onEditTemplate(t, {
96
+ namespaceFQN: $.namespace,
97
+ templateKey: $.templateKey
98
+ });
99
+ } else {
100
+ let t = a(e.fields), n = {
101
+ namespace: e.namespace,
102
+ templateKey: e.templateKey,
103
+ displayName: e.displayName,
104
+ hidden: e.hidden,
105
+ fields: t
106
+ };
107
+ await j.onCreateTemplate(n);
108
+ }
109
+ F({
110
+ sensitivity: "foreground",
111
+ variant: "success",
112
+ styledText: P(n.saveSuccessNotification),
113
+ typeIconAriaLabel: P(n.notificationSuccessIconAriaLabel),
114
+ closeButtonAriaLabel: P(n.notificationCloseButtonAriaLabel)
115
+ });
116
+ } catch (e) {
117
+ let t;
118
+ if (e instanceof Error && "status" in e) {
119
+ let { status: r } = e;
120
+ t = P(r === 409 ? n.displayNameUsedBefore : n.saveErrorNotification);
121
+ } else t = P(n.saveErrorNotification);
122
+ F({
123
+ sensitivity: "foreground",
124
+ variant: "error",
125
+ styledText: t,
126
+ typeIconAriaLabel: P(n.notificationErrorIconAriaLabel),
127
+ closeButtonAriaLabel: P(n.notificationCloseButtonAriaLabel)
128
+ });
129
+ try {
130
+ w?.(e);
131
+ } catch {}
132
+ throw e;
133
+ }
134
+ },
135
+ children: /* @__PURE__ */ f(o, {
136
+ formId: O,
137
+ onCancel: V,
138
+ taxonomyOptions: E,
139
+ fetchTaxonomies: D,
140
+ hideActions: k,
141
+ isEditMode: I,
142
+ onDirtyStateChange: H,
143
+ onValidationChange: C,
144
+ fieldExtensions: A
145
+ })
146
+ }), z && /* @__PURE__ */ f(t, {
147
+ onClose: () => B(!1),
148
+ onConfirm: () => {
149
+ B(!1), p?.();
150
+ },
151
+ title: P(n.unsavedChangesTitle),
152
+ body: P(n.unsavedChangesBody),
153
+ confirmLabel: P(n.unsavedChangesDiscard),
154
+ cancelLabel: P(n.unsavedChangesKeepEditing)
155
+ })] });
156
+ });
157
+ export { S as t };
@@ -0,0 +1,231 @@
1
+ import { useFieldConfigurator as e } from "../esm/lib/components/metadata-field-configurator/context/field-configurator-context.js";
2
+ import t from "../esm/lib/components/metadata-field-configurator/messages/dropdown-messages.js";
3
+ import n from "../esm/lib/components/metadata-field-configurator/components/confirmation-modal/confirmation-modal.js";
4
+ import { IconButton as r, TextInput as i } from "@box/blueprint-web";
5
+ import { useIntl as a } from "react-intl";
6
+ import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
7
+ import { DragDots as l } from "@box/blueprint-web-assets/icons/Fill";
8
+ import { useCallback as u, useEffect as d, useRef as f, useState as p } from "react";
9
+ import m from "lodash/uniqueId";
10
+ import { Trash as h } from "@box/blueprint-web-assets/icons/Line";
11
+ import { DndContext as g, DragOverlay as _, KeyboardSensor as v, PointerSensor as y, TouchSensor as b, closestCenter as x, useSensor as S, useSensors as C } from "@dnd-kit/core";
12
+ import { SortableContext as ee, arrayMove as w, sortableKeyboardCoordinates as T, useSortable as E, verticalListSortingStrategy as te } from "@dnd-kit/sortable";
13
+ import { CSS as D } from "@dnd-kit/utilities";
14
+ import O from "clsx";
15
+ import '../styles/sortable-option-list.css';var k = {
16
+ sortableOptionList: "_sortableOptionList_1cieq_1",
17
+ option: "_option_1cieq_9",
18
+ editable: "_editable_1cieq_9",
19
+ dragging: "_dragging_1cieq_22",
20
+ dragHandle: "_dragHandle_1cieq_26",
21
+ inputContainer: "_inputContainer_1cieq_41",
22
+ input: "_input_1cieq_41",
23
+ deleteButtonContainer: "_deleteButtonContainer_1cieq_52",
24
+ optionDragOverlay: "_optionDragOverlay_1cieq_58"
25
+ };
26
+ function ne(e, t, n, r, i, a) {
27
+ let o = t?.dropdown?.options?.[n] && typeof e == "object" && !!e && typeof e.dropdown == "object" && e.dropdown?.options?.[n]?.key;
28
+ if (typeof o != "string") return "";
29
+ if (a !== null && r.id !== a) {
30
+ let e = i.find((e) => e.id === a)?.key;
31
+ if (e && r.key === e && i.some((t, r) => r !== n && t.key === e)) return "";
32
+ }
33
+ return o;
34
+ }
35
+ function re({ option: e, index: t, isFieldReadOnly: n, onInputChange: a, onDelete: o, onInputRef: u, error: d, handleBlur: f, canDelete: p, dragAriaLabel: m, inputPlaceholder: g, deleteAriaLabel: _ }) {
36
+ let { attributes: v, listeners: y, setNodeRef: b, transform: x, transition: S, isDragging: C } = E({ id: e.id });
37
+ return /* @__PURE__ */ c("li", {
38
+ ref: b,
39
+ style: {
40
+ transform: D.Translate.toString(x),
41
+ transition: S
42
+ },
43
+ className: O(k.option, {
44
+ [k.dragging]: C,
45
+ [k.editable]: !n
46
+ }),
47
+ children: [
48
+ !n && /* @__PURE__ */ s("div", {
49
+ className: k.dragHandle,
50
+ ...y,
51
+ ...v,
52
+ "aria-label": m,
53
+ tabIndex: -1,
54
+ children: /* @__PURE__ */ s(l, {
55
+ fontSize: 20,
56
+ "aria-hidden": "true"
57
+ })
58
+ }),
59
+ /* @__PURE__ */ s(i, {
60
+ disabled: n,
61
+ placeholder: g,
62
+ label: g,
63
+ hideLabel: !0,
64
+ onBlur: f,
65
+ id: `dropdown.options.${t}.key`,
66
+ name: `dropdown.options.${t}.key`,
67
+ value: e.key,
68
+ className: k.input,
69
+ onChange: (t) => a(t, e.id),
70
+ ref: (e) => u(e, t),
71
+ error: d
72
+ }),
73
+ !n && /* @__PURE__ */ s("div", {
74
+ className: k.deleteButtonContainer,
75
+ children: /* @__PURE__ */ s(r, {
76
+ onClick: () => o(e),
77
+ "aria-label": _,
78
+ icon: h,
79
+ size: "x-small",
80
+ variant: "default",
81
+ tabIndex: -1,
82
+ focusable: !0,
83
+ disabled: !p,
84
+ className: k.deleteButton
85
+ })
86
+ })
87
+ ]
88
+ });
89
+ }
90
+ function A({ shouldFocusLastOption: E = !1, onFocusConsumed: D }) {
91
+ let { formatMessage: A } = a(), { values: j, errors: ie, touched: M, setFieldValue: N, setFieldTouched: ae, setTouched: P, handleBlur: oe } = e(), F = C(S(y, { activationConstraint: { distance: 8 } }), S(b, { activationConstraint: {
92
+ delay: 250,
93
+ tolerance: 5
94
+ } }), S(v, { coordinateGetter: T })), { options: I } = j.dropdown, { isFieldReadOnly: L } = j, [R, z] = p(I), [B, V] = p(null), H = f(null), [U, W] = p(null), [G, K] = p(!1), [q, J] = p(null);
95
+ d(() => {
96
+ z(I);
97
+ }, [I]), d(() => () => {
98
+ H.current && clearTimeout(H.current);
99
+ }, []);
100
+ let Y = u((e) => {
101
+ N("dropdown", {
102
+ ...j.dropdown,
103
+ options: e
104
+ });
105
+ }, [j.dropdown, N]), se = (e, t) => {
106
+ V(t);
107
+ let n = R.map((n, r) => n.id === t ? (ae(`dropdown.options.${r}.key`, !0), {
108
+ ...n,
109
+ key: e.target.value
110
+ }) : n);
111
+ z(n), Y(n);
112
+ }, X = () => {
113
+ J(null), K(!1);
114
+ }, Z = (e) => {
115
+ if (!e) return;
116
+ let t = R.filter((t) => t.id !== e);
117
+ z(t), Y(t), e === B && V(null);
118
+ let n = { ...M }, r = n.dropdown;
119
+ r?.options && (r.options = r.options.filter((t, n) => R[n]?.id !== e)), P(n), t.length === 0 && N("dropdown", {
120
+ ...j.dropdown,
121
+ options: [{
122
+ id: m(),
123
+ key: "",
124
+ isNew: !0
125
+ }]
126
+ }), X();
127
+ }, ce = (e) => {
128
+ e.isNew ? Z(e.id) : (J(e), K(!0));
129
+ }, le = ({ active: e }) => {
130
+ W(String(e.id));
131
+ }, ue = () => {
132
+ W(null);
133
+ }, Q = (e) => {
134
+ W(null);
135
+ let { active: t, over: n } = e;
136
+ if (n && t.id !== n.id) {
137
+ let e = R.findIndex((e) => e.id === t.id), r = R.findIndex((e) => e.id === n.id);
138
+ if (e !== -1 && r !== -1) {
139
+ let t = w(R, e, r);
140
+ z(t), Y(t);
141
+ let n = M?.dropdown?.options;
142
+ n && n.length > 0 && P({
143
+ ...M,
144
+ dropdown: {
145
+ ...M.dropdown ?? {},
146
+ options: w(n, e, r)
147
+ }
148
+ });
149
+ }
150
+ }
151
+ }, de = u((e, t) => {
152
+ e && E && t === R.length - 1 && (H.current && clearTimeout(H.current), H.current = setTimeout(() => {
153
+ e.focus(), D(), H.current = null;
154
+ }, 0));
155
+ }, [
156
+ E,
157
+ D,
158
+ R.length
159
+ ]), $ = U ? R.find((e) => e.id === U) : null;
160
+ return /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ c(g, {
161
+ sensors: F,
162
+ collisionDetection: x,
163
+ onDragStart: le,
164
+ onDragEnd: Q,
165
+ onDragCancel: ue,
166
+ children: [/* @__PURE__ */ s(ee, {
167
+ items: R.map((e) => e.id),
168
+ strategy: te,
169
+ children: /* @__PURE__ */ s("ul", {
170
+ className: k.sortableOptionList,
171
+ children: R.map((e, n) => /* @__PURE__ */ s(re, {
172
+ option: e,
173
+ index: n,
174
+ isFieldReadOnly: !!L,
175
+ onInputChange: se,
176
+ onDelete: ce,
177
+ onInputRef: de,
178
+ error: ne(ie, M, n, e, R, B),
179
+ handleBlur: oe,
180
+ canDelete: R.length >= 2,
181
+ dragAriaLabel: A(t.dragAndDropOptionAriaLabel),
182
+ inputPlaceholder: A(t.addAnOptionOptionPlaceholder),
183
+ deleteAriaLabel: A(t.deleteDropdownOptionAriaLabel)
184
+ }, e.id))
185
+ })
186
+ }), /* @__PURE__ */ s(_, {
187
+ dropAnimation: null,
188
+ children: $ ? /* @__PURE__ */ c("li", {
189
+ className: O(k.option, k.optionDragOverlay, { [k.editable]: !L }),
190
+ children: [
191
+ !L && /* @__PURE__ */ s("div", {
192
+ className: k.dragHandle,
193
+ children: /* @__PURE__ */ s(l, {
194
+ fontSize: 20,
195
+ "aria-hidden": "true"
196
+ })
197
+ }),
198
+ /* @__PURE__ */ s(i, {
199
+ disabled: L,
200
+ placeholder: A(t.addAnOptionOptionPlaceholder),
201
+ label: A(t.addAnOptionOptionPlaceholder),
202
+ hideLabel: !0,
203
+ id: "drag-overlay-option",
204
+ name: "drag-overlay-option",
205
+ value: $.key,
206
+ className: k.input
207
+ }),
208
+ !L && /* @__PURE__ */ s("div", {
209
+ className: k.deleteButtonContainer,
210
+ children: /* @__PURE__ */ s(r, {
211
+ icon: h,
212
+ size: "x-small",
213
+ variant: "default",
214
+ tabIndex: -1,
215
+ focusable: !0,
216
+ disabled: R.length < 2,
217
+ className: k.deleteButton,
218
+ "aria-label": ""
219
+ })
220
+ })
221
+ ]
222
+ }) : null
223
+ })]
224
+ }), G && /* @__PURE__ */ s(n, {
225
+ onClose: X,
226
+ onConfirm: () => Z(q?.id ?? null),
227
+ title: A(t.deleteOptionTitle, { optionName: q?.key ?? "" }),
228
+ body: A(t.deleteOptionDescription)
229
+ })] });
230
+ }
231
+ export { A as t };
@@ -0,0 +1,126 @@
1
+ import { c as e } from "./types.js";
2
+ import { useFieldConfigurator as t } from "../esm/lib/components/metadata-field-configurator/context/field-configurator-context.js";
3
+ import { useTaxonomyOptions as n } from "../esm/lib/components/metadata-field-configurator/context/taxonomy-options-context.js";
4
+ import r from "../esm/lib/components/metadata-field-configurator/messages/taxonomy-messages.js";
5
+ import { t as i } from "./levels-chain.js";
6
+ import { t as a } from "./taxonomy-field-configurator-initial-state.js";
7
+ import { useTaxonomySelect as o } from "../esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/useTaxonomySelect.js";
8
+ import { filterTaxonomiesByValue as s } from "../esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/utils.js";
9
+ import { t as c } from "./taxonomy-selector.js";
10
+ import { DropdownMenu as l, InlineNotice as u, Radio as d, Switch as f, TextButton as p } from "@box/blueprint-web";
11
+ import { useIntl as m } from "react-intl";
12
+ import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
13
+ import { Caret as v } from "@box/blueprint-web-assets/icons/Fill";
14
+ import { useEffect as y, useMemo as b } from "react";
15
+ import '../styles/taxonomy-field-configuration.css';var x = {
16
+ taxonomyFieldConfiguration: "_taxonomyFieldConfiguration_ylhrs_1",
17
+ responsePlaceholder: "_responsePlaceholder_ylhrs_8"
18
+ }, S = () => {
19
+ let { formatMessage: S } = m(), { values: C, errors: w, touched: T, setFieldValue: E } = t(), { onTaxonomySelect: D } = o({
20
+ values: C,
21
+ setFieldValue: E
22
+ }), { options: O } = n(), k = C.taxonomy.availableTaxonomies.find((e) => e.selected), { selectedLevels: A } = C.taxonomy, j = b(() => k ? k.levels : [], [k]), M = C.taxonomy.selection === e.RequireSpecific && A.length > 0 ? j[A[0] - 1]?.name : void 0;
23
+ y(() => {
24
+ O.length > 0 && E("taxonomy", {
25
+ ...C.taxonomy,
26
+ availableTaxonomies: O.map((e) => ({
27
+ ...e,
28
+ selected: e.taxonomyKey === C.taxonomy.taxonomyKey
29
+ })),
30
+ selectedLevels: C.taxonomy.selectedLevels,
31
+ selection: C.taxonomy.selectedLevels.length > 1 ? e.AllowAny : e.RequireSpecific
32
+ });
33
+ }, [O]);
34
+ let N = (t) => {
35
+ let n = t === e.AllowAny ? j.map((e) => e.level) : [j[0].level];
36
+ E("taxonomy", {
37
+ ...C.taxonomy,
38
+ selection: t,
39
+ selectedLevels: n
40
+ });
41
+ }, P = k?.label ?? S(r.chooseTaxonomyLevel), F = !!w.taxonomy?.taxonomyKey && !!T.taxonomy?.taxonomyKey;
42
+ if (!k && C.isFieldNew) return /* @__PURE__ */ _(h, { children: [F && /* @__PURE__ */ g(u, {
43
+ variant: "error",
44
+ variantIconAriaLabel: S(r.noTaxonomySelectedError),
45
+ children: S(r.noTaxonomySelectedError)
46
+ }), /* @__PURE__ */ g(a, {})] });
47
+ let I = C.isFieldReadOnly || !C.isFieldNew;
48
+ return /* @__PURE__ */ _("div", {
49
+ className: x.taxonomyFieldConfiguration,
50
+ children: [
51
+ /* @__PURE__ */ g(f.Item, {
52
+ name: "allowMultipleSelections",
53
+ disabled: I,
54
+ checked: C.taxonomy.allowMultipleSelections,
55
+ label: S(r.allowMultipleTaxonomySelections),
56
+ onCheckedChange: (e) => {
57
+ E("taxonomy", {
58
+ ...C.taxonomy,
59
+ allowMultipleSelections: e
60
+ });
61
+ },
62
+ value: C.taxonomy.allowMultipleSelections.toString()
63
+ }),
64
+ /* @__PURE__ */ g("div", { children: /* @__PURE__ */ g(c, {
65
+ triggerButton: /* @__PURE__ */ g(p, {
66
+ disabled: I,
67
+ icon: v,
68
+ children: P
69
+ }),
70
+ data: s(C.taxonomy.availableTaxonomies, C.taxonomy.taxonomySearchValue),
71
+ onClick: D,
72
+ onSearchValue: (e) => {
73
+ E("taxonomy", {
74
+ ...C.taxonomy,
75
+ taxonomySearchValue: e
76
+ });
77
+ }
78
+ }) }),
79
+ j.length > 0 && /* @__PURE__ */ g(i, {
80
+ levels: j,
81
+ selectedLevels: A
82
+ }),
83
+ k && j.length > 1 && /* @__PURE__ */ g(d.Legend, {
84
+ header: S(r.selection),
85
+ children: /* @__PURE__ */ _(d.Group, {
86
+ disabled: I,
87
+ defaultValue: e.RequireSpecific,
88
+ loop: !0,
89
+ name: "selection",
90
+ onValueChange: N,
91
+ orientation: "vertical",
92
+ value: C.taxonomy.selection,
93
+ children: [/* @__PURE__ */ g(d.Item, {
94
+ label: /* @__PURE__ */ _(h, { children: [S(r.requiredSelection), /* @__PURE__ */ _(l.Root, {
95
+ modal: !1,
96
+ children: [/* @__PURE__ */ g(l.Trigger, {
97
+ disabled: C.taxonomy.selection !== e.RequireSpecific || I,
98
+ children: /* @__PURE__ */ g(p, {
99
+ icon: v,
100
+ children: M ?? S(r.chooseTaxonomyLevel)
101
+ })
102
+ }), /* @__PURE__ */ g(l.Content, {
103
+ align: "start",
104
+ children: k?.levels?.map((e) => /* @__PURE__ */ g(l.Item, {
105
+ onClick: () => {
106
+ E("taxonomy", {
107
+ ...C.taxonomy,
108
+ selectedLevels: [e.level]
109
+ });
110
+ },
111
+ children: e.name
112
+ }, e.level))
113
+ })]
114
+ })] }),
115
+ value: e.RequireSpecific
116
+ }), /* @__PURE__ */ g(d.Item, {
117
+ disabled: I,
118
+ label: S(r.anyLevelSelection),
119
+ value: e.AllowAny
120
+ })]
121
+ })
122
+ })
123
+ ]
124
+ });
125
+ };
126
+ export { S as t };