@box/metadata-template-editor 2.2.23 → 2.2.25
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/chunks/chip.js +1 -22
- package/dist/chunks/dropdown-field-configuration.js +1 -62
- package/dist/chunks/field-context-menu.js +1 -91
- package/dist/chunks/field-selector.js +1 -23
- package/dist/chunks/field-type-dropdown.js +1 -31
- package/dist/chunks/levels-chain.js +1 -120
- package/dist/chunks/metadata-field-configurator.module.js +1 -21
- package/dist/chunks/metadata-field-list.js +1 -280
- package/dist/chunks/metadata-template-editor-form.js +1 -132
- package/dist/chunks/metadata-template-editor-modal.js +1 -90
- package/dist/chunks/metadata-template-editor.js +1 -161
- package/dist/chunks/sortable-option-list.js +1 -230
- package/dist/chunks/taxonomy-field-configuration.js +1 -123
- package/dist/chunks/taxonomy-field-configurator-initial-state.js +1 -49
- package/dist/chunks/taxonomy-selector.js +1 -89
- package/dist/chunks/types.js +1 -23
- package/dist/esm/index.js +1 -22
- package/dist/esm/lib/components/field-selector/field-selector.js +1 -2
- package/dist/esm/lib/components/field-selector/index.js +1 -2
- package/dist/esm/lib/components/field-selector/messages.js +1 -12
- package/dist/esm/lib/components/field-type-dropdown/field-type-dropdown.js +1 -2
- package/dist/esm/lib/components/field-type-dropdown/index.js +1 -2
- package/dist/esm/lib/components/field-type-dropdown/messages.js +1 -12
- package/dist/esm/lib/components/field-type-tiles/field-type-tiles.js +1 -33
- package/dist/esm/lib/components/field-type-tiles/index.js +1 -2
- package/dist/esm/lib/components/field-type-tiles/messages.js +1 -12
- package/dist/esm/lib/components/metadata-field-configurator/components/confirmation-modal/confirmation-modal.js +1 -33
- package/dist/esm/lib/components/metadata-field-configurator/components/confirmation-modal/messages.js +1 -16
- package/dist/esm/lib/components/metadata-field-configurator/components/field-action-slot/field-action-slot.js +1 -67
- package/dist/esm/lib/components/metadata-field-configurator/components/field-context-menu/field-context-menu.js +1 -2
- package/dist/esm/lib/components/metadata-field-configurator/components/field-edit-content/field-edit-content.js +1 -84
- package/dist/esm/lib/components/metadata-field-configurator/components/levels-chain/chip.js +1 -2
- package/dist/esm/lib/components/metadata-field-configurator/components/levels-chain/index.js +1 -2
- package/dist/esm/lib/components/metadata-field-configurator/components/levels-chain/levels-chain.js +1 -2
- package/dist/esm/lib/components/metadata-field-configurator/components/levels-chain/utils.js +1 -17
- package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/dropdown/__mocks__/getInitialValues.js +1 -35
- package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/dropdown/dropdown-default-values.js +1 -11
- package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/dropdown/dropdown-field-configuration.js +1 -2
- package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/dropdown/sortable-option-list.js +1 -2
- package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/index.js +1 -3
- package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/taxonomy-default-values.js +1 -11
- package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/taxonomy-field-configuration.js +1 -2
- package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/taxonomy-field-configurator-initial-state.js +1 -2
- package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/taxonomy-selector-messages.js +1 -36
- package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/taxonomy-selector.js +1 -2
- package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/useTaxonomySelect.js +1 -15
- package/dist/esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/utils.js +1 -2
- package/dist/esm/lib/components/metadata-field-configurator/context/editor-config-context.js +1 -3
- package/dist/esm/lib/components/metadata-field-configurator/context/field-configurator-context.js +1 -62
- package/dist/esm/lib/components/metadata-field-configurator/context/field-extensions-context.js +1 -6
- package/dist/esm/lib/components/metadata-field-configurator/context/taxonomy-options-context.js +1 -17
- package/dist/esm/lib/components/metadata-field-configurator/hooks/useFieldConfiguratorBehavior.js +1 -102
- package/dist/esm/lib/components/metadata-field-configurator/hooks/useFieldValidation.js +1 -54
- package/dist/esm/lib/components/metadata-field-configurator/hooks/useTaxonomyFetch.js +1 -24
- package/dist/esm/lib/components/metadata-field-configurator/hooks/useTemplateFieldSchema.js +1 -35
- package/dist/esm/lib/components/metadata-field-configurator/index.js +1 -14
- package/dist/esm/lib/components/metadata-field-configurator/messages/configurator-messages.js +1 -133
- package/dist/esm/lib/components/metadata-field-configurator/messages/dropdown-messages.js +1 -36
- package/dist/esm/lib/components/metadata-field-configurator/messages/levels-chain-messages.js +1 -16
- package/dist/esm/lib/components/metadata-field-configurator/messages/taxonomy-messages.js +1 -36
- package/dist/esm/lib/components/metadata-field-configurator/metadata-field-configurator.js +1 -106
- package/dist/esm/lib/components/metadata-field-configurator/utils.js +1 -46
- package/dist/esm/lib/components/metadata-field-list/index.js +1 -2
- package/dist/esm/lib/components/metadata-field-list/metadata-field-list.js +1 -2
- package/dist/esm/lib/components/metadata-template-editor-form/metadata-template-editor-form.js +1 -2
- package/dist/esm/lib/components/metadata-template-editor-modal/index.js +1 -2
- package/dist/esm/lib/components/metadata-template-editor-modal/metadata-template-editor-modal.js +1 -2
- package/dist/esm/lib/hooks/useMetadataTemplateFormSchema.js +1 -14
- package/dist/esm/lib/hooks/useTemplateNameSchema.js +1 -10
- package/dist/esm/lib/index.js +1 -8
- package/dist/esm/lib/messages.js +1 -128
- package/dist/esm/lib/metadata-template-editor.js +1 -2
- package/dist/esm/lib/utils/constants.js +1 -2
- package/dist/esm/lib/utils/field-options/field-type-icon.js +1 -15
- package/dist/esm/lib/utils/field-options/index.js +1 -4
- package/dist/esm/lib/utils/field-options/messages.js +1 -45
- package/dist/esm/lib/utils/field-options/useFieldOptions.js +1 -16
- package/dist/esm/lib/utils/key-generation.js +1 -18
- package/dist/esm/lib/utils/template-type-conversion/convertLocalConfiguratorToTemplateField.js +1 -64
- package/dist/esm/lib/utils/template-type-conversion/convertTemplateFieldToLocalConfigurator.js +1 -70
- package/dist/esm/lib/utils/template-type-conversion/generateJSONPatchTemplateOperations.js +1 -160
- package/dist/esm/lib/utils/template-type-conversion/mapFieldsWithUniqueKeys.js +1 -9
- package/package.json +7 -7
|
@@ -1,280 +1 @@
|
|
|
1
|
-
import { a as e } from "./types.js";
|
|
2
|
-
import { FieldTypeIcon as t } from "../esm/lib/utils/field-options/field-type-icon.js";
|
|
3
|
-
import { EditorConfigContext as n, useEditorConfig as r } from "../esm/lib/components/metadata-field-configurator/context/editor-config-context.js";
|
|
4
|
-
import { general as i } from "../esm/lib/components/metadata-field-configurator/messages/configurator-messages.js";
|
|
5
|
-
import { useTemplateFieldSchema as a } from "../esm/lib/components/metadata-field-configurator/hooks/useTemplateFieldSchema.js";
|
|
6
|
-
import { TaxonomyOptionsContext as o } from "../esm/lib/components/metadata-field-configurator/context/taxonomy-options-context.js";
|
|
7
|
-
import { FieldExtensionsContext as s } from "../esm/lib/components/metadata-field-configurator/context/field-extensions-context.js";
|
|
8
|
-
import { useTaxonomyFetch as c } from "../esm/lib/components/metadata-field-configurator/hooks/useTaxonomyFetch.js";
|
|
9
|
-
import { MetadataFieldConfigurator as l } from "../esm/lib/components/metadata-field-configurator/metadata-field-configurator.js";
|
|
10
|
-
import { Accordion as u } from "@box/blueprint-web";
|
|
11
|
-
import { useIntl as d } from "react-intl";
|
|
12
|
-
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
13
|
-
import { forwardRef as m, useCallback as h, useEffect as g, useImperativeHandle as _, useMemo as v, useRef as y, useState as b } from "react";
|
|
14
|
-
import * as ee from "yup";
|
|
15
|
-
import x from "clsx";
|
|
16
|
-
import te from "lodash/cloneDeep";
|
|
17
|
-
import S from "lodash/uniqueId";
|
|
18
|
-
import { DndContext as ne, DragOverlay as re, KeyboardSensor as C, PointerSensor as ie, TouchSensor as ae, closestCenter as oe, useSensor as w, useSensors as se } from "@dnd-kit/core";
|
|
19
|
-
import { SortableContext as ce, arrayMove as T, sortableKeyboardCoordinates as le, useSortable as E, verticalListSortingStrategy as ue } from "@dnd-kit/sortable";
|
|
20
|
-
import { CSS as D } from "@dnd-kit/utilities";
|
|
21
|
-
import '../styles/metadata-field-list.css';var O = {
|
|
22
|
-
fieldList: "_fieldList_18x5c_1",
|
|
23
|
-
fieldItem: "_fieldItem_18x5c_11",
|
|
24
|
-
dragging: "_dragging_18x5c_11",
|
|
25
|
-
accordionRootContainer: "_accordionRootContainer_18x5c_15"
|
|
26
|
-
}, de = 150;
|
|
27
|
-
function k(e) {
|
|
28
|
-
return e.id;
|
|
29
|
-
}
|
|
30
|
-
var A = 150, fe = class extends C {
|
|
31
|
-
static activators = [{
|
|
32
|
-
eventName: "onKeyDown",
|
|
33
|
-
handler: (e, t, n) => {
|
|
34
|
-
let r = e.nativeEvent?.target ?? e.target ?? null;
|
|
35
|
-
return r instanceof HTMLElement && [
|
|
36
|
-
"BUTTON",
|
|
37
|
-
"INPUT",
|
|
38
|
-
"SELECT",
|
|
39
|
-
"TEXTAREA",
|
|
40
|
-
"A"
|
|
41
|
-
].includes(r.tagName) ? !1 : C.activators[0].handler(e, t, n);
|
|
42
|
-
}
|
|
43
|
-
}];
|
|
44
|
-
};
|
|
45
|
-
function pe({ field: e, index: t, maxIndex: n, isExpanded: r, onChangeField: i, onDeleteAtIndex: a, onDuplicateAtIndex: o, onReorderFields: s, onRequestExpand: c, submitAttemptCount: u }) {
|
|
46
|
-
let d = k(e), { attributes: p, listeners: m, setNodeRef: h, transform: g, transition: _, isDragging: v } = E({ id: d });
|
|
47
|
-
return /* @__PURE__ */ f("li", {
|
|
48
|
-
ref: h,
|
|
49
|
-
style: {
|
|
50
|
-
transform: D.Translate.toString(g),
|
|
51
|
-
transition: _
|
|
52
|
-
},
|
|
53
|
-
"data-field-id": d,
|
|
54
|
-
className: x(O.fieldItem, { [O.dragging]: v }),
|
|
55
|
-
children: /* @__PURE__ */ f(l, {
|
|
56
|
-
values: e,
|
|
57
|
-
onValuesChange: i,
|
|
58
|
-
index: t,
|
|
59
|
-
maxIndex: n,
|
|
60
|
-
onDelete: () => a(t),
|
|
61
|
-
onDuplicate: () => o(t),
|
|
62
|
-
onReorderFields: s,
|
|
63
|
-
dndDragHandleProps: {
|
|
64
|
-
listeners: m,
|
|
65
|
-
attributes: p
|
|
66
|
-
},
|
|
67
|
-
isExpanded: r,
|
|
68
|
-
onExpandedChange: (e) => {
|
|
69
|
-
e && c();
|
|
70
|
-
},
|
|
71
|
-
submitAttemptCount: u
|
|
72
|
-
})
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
var j = /*#__PURE__*/ m(function({ fields: m, onChangeFields: x, onDeleteFieldAtIndex: C, onDuplicateField: E, taxonomyOptions: D, fetchTaxonomies: j, disabledFieldTypes: M, taxonomyInitialStateLabels: N, firstInvalidFieldIndex: P, submitAttemptCount: F, fieldExtensions: I, onValidationChange: L, readOnly: R = !1 }, me) {
|
|
76
|
-
let { formatMessage: he } = d(), z = r(), ge = c(j, D), B = y(null), V = y(null), H = y(new Set(m.map((e) => k(e)))), U = a(), W = y(null);
|
|
77
|
-
g(() => {
|
|
78
|
-
W.current = null;
|
|
79
|
-
}, [L]), g(() => {
|
|
80
|
-
if (!L) return;
|
|
81
|
-
let e = !1, t = setTimeout(() => {
|
|
82
|
-
ee.array().of(U).validate(m, { abortEarly: !0 }).then(() => {
|
|
83
|
-
e || W.current === !0 || (W.current = !0, L(!0));
|
|
84
|
-
}).catch(() => {
|
|
85
|
-
e || W.current === !1 || (W.current = !1, L(!1));
|
|
86
|
-
});
|
|
87
|
-
}, de);
|
|
88
|
-
return () => {
|
|
89
|
-
e = !0, clearTimeout(t);
|
|
90
|
-
};
|
|
91
|
-
}, [
|
|
92
|
-
m,
|
|
93
|
-
U,
|
|
94
|
-
L
|
|
95
|
-
]);
|
|
96
|
-
let [G, K] = b(() => {
|
|
97
|
-
let e = m.find((e) => e.isFieldNew);
|
|
98
|
-
return e ? k(e) : null;
|
|
99
|
-
});
|
|
100
|
-
_(me, () => ({ scrollToAndExpand(e) {
|
|
101
|
-
V.current = e, G === e ? (V.current = null, setTimeout(() => {
|
|
102
|
-
(B.current?.querySelector(`[data-field-id="${e}"]`))?.scrollIntoView({
|
|
103
|
-
behavior: "smooth",
|
|
104
|
-
block: "nearest"
|
|
105
|
-
});
|
|
106
|
-
}, 0)) : K(e);
|
|
107
|
-
} }), [G]), g(() => {
|
|
108
|
-
m.forEach((e) => {
|
|
109
|
-
let t = k(e);
|
|
110
|
-
H.current.has(t) || (H.current.add(t), V.current = t, K(t));
|
|
111
|
-
});
|
|
112
|
-
}, [m]), g(() => {
|
|
113
|
-
if (P == null || !F) return;
|
|
114
|
-
let e = m[P];
|
|
115
|
-
if (!e) return;
|
|
116
|
-
let t = k(e);
|
|
117
|
-
K(t), requestAnimationFrame(() => {
|
|
118
|
-
(B.current?.querySelector(`[data-field-id="${t}"]`))?.scrollIntoView({
|
|
119
|
-
behavior: "smooth",
|
|
120
|
-
block: "nearest"
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
}, [F]), g(() => {
|
|
124
|
-
let e = V.current;
|
|
125
|
-
if (!e || e !== G) return;
|
|
126
|
-
V.current = null;
|
|
127
|
-
let t = setTimeout(() => {
|
|
128
|
-
(B.current?.querySelector(`[data-field-id="${e}"]`))?.scrollIntoView({
|
|
129
|
-
behavior: "smooth",
|
|
130
|
-
block: "nearest"
|
|
131
|
-
});
|
|
132
|
-
}, A);
|
|
133
|
-
return () => clearTimeout(t);
|
|
134
|
-
}, [G]);
|
|
135
|
-
let [q, J] = b(null), _e = se(w(ie, { activationConstraint: { distance: 8 } }), w(ae, { activationConstraint: {
|
|
136
|
-
delay: 250,
|
|
137
|
-
tolerance: 5
|
|
138
|
-
} }), w(fe, { coordinateGetter: le })), ve = h((e) => {
|
|
139
|
-
J(String(e.active.id));
|
|
140
|
-
}, []), ye = h((e) => {
|
|
141
|
-
J(null);
|
|
142
|
-
let { active: t, over: n } = e;
|
|
143
|
-
if (n && t.id !== n.id) {
|
|
144
|
-
let e = m.findIndex((e) => k(e) === t.id), r = m.findIndex((e) => k(e) === n.id);
|
|
145
|
-
e !== -1 && r !== -1 && x?.(T(m, e, r));
|
|
146
|
-
}
|
|
147
|
-
}, [m, x]), be = h(() => {
|
|
148
|
-
J(null);
|
|
149
|
-
}, []), xe = h((e, t) => {
|
|
150
|
-
x?.(m.map((n, r) => r === e ? t : n));
|
|
151
|
-
}, [m, x]), Se = h((e) => {
|
|
152
|
-
let t = m[e], n = k(t);
|
|
153
|
-
K((e) => e === n ? null : e), x?.(m.filter((t, n) => n !== e)), C?.(e, t);
|
|
154
|
-
}, [
|
|
155
|
-
m,
|
|
156
|
-
x,
|
|
157
|
-
C
|
|
158
|
-
]), Ce = h((t) => {
|
|
159
|
-
let n = m[t], r = te(n);
|
|
160
|
-
r.id = S("field-"), r.key = "", r.isFieldNew = !0, r.type === e.Dropdown && (r.dropdown.options = r.dropdown.options.map((e) => ({
|
|
161
|
-
...e,
|
|
162
|
-
id: S()
|
|
163
|
-
})));
|
|
164
|
-
let i = [...m];
|
|
165
|
-
i.splice(t + 1, 0, r), x?.(i), E?.(r);
|
|
166
|
-
}, [
|
|
167
|
-
m,
|
|
168
|
-
x,
|
|
169
|
-
E
|
|
170
|
-
]), we = h((e, t) => {
|
|
171
|
-
t < 0 || t >= m.length || x?.(T(m, e, t));
|
|
172
|
-
}, [m, x]), Y = h((e) => {
|
|
173
|
-
let t = e || null;
|
|
174
|
-
K(t), t && setTimeout(() => {
|
|
175
|
-
(B.current?.querySelector(`[data-field-id="${t}"]`))?.scrollIntoView({
|
|
176
|
-
behavior: "smooth",
|
|
177
|
-
block: "nearest"
|
|
178
|
-
});
|
|
179
|
-
}, A);
|
|
180
|
-
}, []), Te = m.map((e) => k(e)), X = q ? m.find((e) => k(e) === q) : null, Z = X ? t(X.type) : null, Ee = X ? ((t) => {
|
|
181
|
-
let n = t.name || he(i.fieldNameInputPlaceholder);
|
|
182
|
-
return t.type === e.Dropdown ? `${n} (${t.dropdown?.options?.length ?? 0})` : n;
|
|
183
|
-
})(X) : "", De = v(() => ({
|
|
184
|
-
disabledFieldTypes: M ?? z.disabledFieldTypes,
|
|
185
|
-
taxonomyInitialStateLabels: N ?? z.taxonomyInitialStateLabels
|
|
186
|
-
}), [
|
|
187
|
-
M,
|
|
188
|
-
N,
|
|
189
|
-
z
|
|
190
|
-
]), Oe = R ? /* @__PURE__ */ f("ul", {
|
|
191
|
-
ref: B,
|
|
192
|
-
className: O.fieldList,
|
|
193
|
-
children: m.map((e, t) => {
|
|
194
|
-
let n = k(e);
|
|
195
|
-
return /* @__PURE__ */ f("li", {
|
|
196
|
-
"data-field-id": n,
|
|
197
|
-
className: O.fieldItem,
|
|
198
|
-
children: /* @__PURE__ */ f(l, {
|
|
199
|
-
values: e,
|
|
200
|
-
onValuesChange: () => void 0,
|
|
201
|
-
index: t,
|
|
202
|
-
maxIndex: m.length - 1,
|
|
203
|
-
onDuplicate: () => void 0,
|
|
204
|
-
onReorderFields: () => void 0,
|
|
205
|
-
onDragStart: () => void 0,
|
|
206
|
-
onDragEnd: () => void 0,
|
|
207
|
-
onTouchStart: () => void 0,
|
|
208
|
-
isExpanded: G === n,
|
|
209
|
-
onExpandedChange: (e) => {
|
|
210
|
-
e && K(n);
|
|
211
|
-
},
|
|
212
|
-
readOnly: !0
|
|
213
|
-
})
|
|
214
|
-
}, n);
|
|
215
|
-
})
|
|
216
|
-
}) : /* @__PURE__ */ f(ce, {
|
|
217
|
-
items: Te,
|
|
218
|
-
strategy: ue,
|
|
219
|
-
children: /* @__PURE__ */ f("ul", {
|
|
220
|
-
ref: B,
|
|
221
|
-
className: O.fieldList,
|
|
222
|
-
children: m.map((e, t) => {
|
|
223
|
-
let n = k(e);
|
|
224
|
-
return /* @__PURE__ */ f(pe, {
|
|
225
|
-
field: e,
|
|
226
|
-
index: t,
|
|
227
|
-
maxIndex: m.length - 1,
|
|
228
|
-
isExpanded: G === n,
|
|
229
|
-
onChangeField: (e) => xe(t, e),
|
|
230
|
-
onDeleteAtIndex: Se,
|
|
231
|
-
onDuplicateAtIndex: Ce,
|
|
232
|
-
onReorderFields: we,
|
|
233
|
-
onRequestExpand: () => K(n),
|
|
234
|
-
submitAttemptCount: F
|
|
235
|
-
}, n);
|
|
236
|
-
})
|
|
237
|
-
})
|
|
238
|
-
}), Q = /* @__PURE__ */ f("div", {
|
|
239
|
-
className: O.accordionRootContainer,
|
|
240
|
-
children: /* @__PURE__ */ f(u, {
|
|
241
|
-
type: "single",
|
|
242
|
-
collapsible: !0,
|
|
243
|
-
value: G ?? "",
|
|
244
|
-
onValueChange: Y,
|
|
245
|
-
children: Oe
|
|
246
|
-
})
|
|
247
|
-
}), ke = R ? Q : /* @__PURE__ */ p(ne, {
|
|
248
|
-
sensors: _e,
|
|
249
|
-
collisionDetection: oe,
|
|
250
|
-
onDragStart: ve,
|
|
251
|
-
onDragEnd: ye,
|
|
252
|
-
onDragCancel: be,
|
|
253
|
-
children: [Q, /* @__PURE__ */ f(re, {
|
|
254
|
-
dropAnimation: null,
|
|
255
|
-
children: X && Z ? /* @__PURE__ */ f(u, {
|
|
256
|
-
type: "single",
|
|
257
|
-
children: /* @__PURE__ */ f(u.Item, {
|
|
258
|
-
value: "ghost",
|
|
259
|
-
title: Ee,
|
|
260
|
-
startElement: /* @__PURE__ */ f(Z, {
|
|
261
|
-
fontSize: "20px",
|
|
262
|
-
role: "presentation"
|
|
263
|
-
}),
|
|
264
|
-
children: null
|
|
265
|
-
})
|
|
266
|
-
}) : null
|
|
267
|
-
})]
|
|
268
|
-
}), $ = /* @__PURE__ */ f(n.Provider, {
|
|
269
|
-
value: De,
|
|
270
|
-
children: /* @__PURE__ */ f(o.Provider, {
|
|
271
|
-
value: ge,
|
|
272
|
-
children: ke
|
|
273
|
-
})
|
|
274
|
-
});
|
|
275
|
-
return I === void 0 ? $ : /* @__PURE__ */ f(s.Provider, {
|
|
276
|
-
value: I,
|
|
277
|
-
children: $
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
export { j as t };
|
|
1
|
+
import{a as FieldType}from"./types.js";import{FieldTypeIcon}from"../esm/lib/utils/field-options/field-type-icon.js";import{EditorConfigContext,useEditorConfig}from"../esm/lib/components/metadata-field-configurator/context/editor-config-context.js";import{general}from"../esm/lib/components/metadata-field-configurator/messages/configurator-messages.js";import{useTemplateFieldSchema}from"../esm/lib/components/metadata-field-configurator/hooks/useTemplateFieldSchema.js";import{TaxonomyOptionsContext}from"../esm/lib/components/metadata-field-configurator/context/taxonomy-options-context.js";import{FieldExtensionsContext}from"../esm/lib/components/metadata-field-configurator/context/field-extensions-context.js";import{useTaxonomyFetch}from"../esm/lib/components/metadata-field-configurator/hooks/useTaxonomyFetch.js";import{MetadataFieldConfigurator}from"../esm/lib/components/metadata-field-configurator/metadata-field-configurator.js";import{Accordion}from"@box/blueprint-web";import{useIntl}from"react-intl";import{jsx,jsxs}from"react/jsx-runtime";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useRef,useState}from"react";import*as Yup from"yup";import clsx from"clsx";import cloneDeep from"lodash/cloneDeep";import uniqueId from"lodash/uniqueId";import{DndContext,DragOverlay,KeyboardSensor,PointerSensor,TouchSensor,closestCenter,useSensor,useSensors}from"@dnd-kit/core";import{SortableContext,arrayMove,sortableKeyboardCoordinates,useSortable,verticalListSortingStrategy}from"@dnd-kit/sortable";import{CSS}from"@dnd-kit/utilities";import '../styles/metadata-field-list.css';var metadata_field_list_module_default={fieldList:`_fieldList_18x5c_1`,fieldItem:`_fieldItem_18x5c_11`,dragging:`_dragging_18x5c_11`,accordionRootContainer:`_accordionRootContainer_18x5c_15`},FIELDS_AGGREGATE_VALIDATION_DEBOUNCE_MS=150;function getFieldId(field){return field.id}var ACCORDION_ANIMATION_MS=150,FieldListKeyboardSensor=class extends KeyboardSensor{static activators=[{eventName:`onKeyDown`,handler:(event,options,context)=>{let target=event.nativeEvent?.target??event.target??null;return target instanceof HTMLElement&&[`BUTTON`,`INPUT`,`SELECT`,`TEXTAREA`,`A`].includes(target.tagName)?!1:KeyboardSensor.activators[0].handler(event,options,context)}}]};function SortableFieldItem({field,index,maxIndex,isExpanded,onChangeField,onDeleteAtIndex,onDuplicateAtIndex,onReorderFields,onRequestExpand,submitAttemptCount}){let id=getFieldId(field),{attributes,listeners,setNodeRef,transform,transition,isDragging}=useSortable({id});return jsx(`li`,{ref:setNodeRef,style:{transform:CSS.Translate.toString(transform),transition},"data-field-id":id,className:clsx(metadata_field_list_module_default.fieldItem,{[metadata_field_list_module_default.dragging]:isDragging}),children:jsx(MetadataFieldConfigurator,{values:field,onValuesChange:onChangeField,index,maxIndex,onDelete:()=>onDeleteAtIndex(index),onDuplicate:()=>onDuplicateAtIndex(index),onReorderFields,dndDragHandleProps:{listeners,attributes},isExpanded,onExpandedChange:expanded=>{expanded&&onRequestExpand()},submitAttemptCount})})}var MetadataFieldList=forwardRef(function({fields,onChangeFields,onDeleteFieldAtIndex,onDuplicateField,taxonomyOptions,fetchTaxonomies,disabledFieldTypes,taxonomyInitialStateLabels,firstInvalidFieldIndex,submitAttemptCount,fieldExtensions,onValidationChange,readOnly=!1},ref){let{formatMessage}=useIntl(),parentEditorConfig=useEditorConfig(),taxonomyContextValue=useTaxonomyFetch(fetchTaxonomies,taxonomyOptions),fieldListRef=useRef(null),pendingScrollFieldIdRef=useRef(null),seenFieldIdsRef=useRef(new Set(fields.map(field=>getFieldId(field)))),fieldSchema=useTemplateFieldSchema(),lastEmittedAggregateValidRef=useRef(null);useEffect(()=>{lastEmittedAggregateValidRef.current=null},[onValidationChange]),useEffect(()=>{if(!onValidationChange)return;let cancelled=!1,timeoutId=setTimeout(()=>{Yup.array().of(fieldSchema).validate(fields,{abortEarly:!0}).then(()=>{cancelled||lastEmittedAggregateValidRef.current===!0||(lastEmittedAggregateValidRef.current=!0,onValidationChange(!0))}).catch(()=>{cancelled||lastEmittedAggregateValidRef.current===!1||(lastEmittedAggregateValidRef.current=!1,onValidationChange(!1))})},FIELDS_AGGREGATE_VALIDATION_DEBOUNCE_MS);return()=>{cancelled=!0,clearTimeout(timeoutId)}},[fields,fieldSchema,onValidationChange]);let[expandedFieldKey,setExpandedFieldKey]=useState(()=>{let firstNewField=fields.find(f=>f.isFieldNew);return firstNewField?getFieldId(firstNewField):null});useImperativeHandle(ref,()=>({scrollToAndExpand(fieldId){pendingScrollFieldIdRef.current=fieldId,expandedFieldKey===fieldId?(pendingScrollFieldIdRef.current=null,setTimeout(()=>{(fieldListRef.current?.querySelector(`[data-field-id="${fieldId}"]`))?.scrollIntoView({behavior:`smooth`,block:`nearest`})},0)):setExpandedFieldKey(fieldId)}}),[expandedFieldKey]),useEffect(()=>{fields.forEach(field=>{let id=getFieldId(field);seenFieldIdsRef.current.has(id)||(seenFieldIdsRef.current.add(id),pendingScrollFieldIdRef.current=id,setExpandedFieldKey(id))})},[fields]),useEffect(()=>{if(firstInvalidFieldIndex==null||!submitAttemptCount)return;let field=fields[firstInvalidFieldIndex];if(!field)return;let fieldId=getFieldId(field);setExpandedFieldKey(fieldId),requestAnimationFrame(()=>{(fieldListRef.current?.querySelector(`[data-field-id="${fieldId}"]`))?.scrollIntoView({behavior:`smooth`,block:`nearest`})})},[submitAttemptCount]),useEffect(()=>{let fieldId=pendingScrollFieldIdRef.current;if(!fieldId||fieldId!==expandedFieldKey)return;pendingScrollFieldIdRef.current=null;let timer=setTimeout(()=>{(fieldListRef.current?.querySelector(`[data-field-id="${fieldId}"]`))?.scrollIntoView({behavior:`smooth`,block:`nearest`})},ACCORDION_ANIMATION_MS);return()=>clearTimeout(timer)},[expandedFieldKey]);let[activeFieldId,setActiveFieldId]=useState(null),sensors=useSensors(useSensor(PointerSensor,{activationConstraint:{distance:8}}),useSensor(TouchSensor,{activationConstraint:{delay:250,tolerance:5}}),useSensor(FieldListKeyboardSensor,{coordinateGetter:sortableKeyboardCoordinates})),handleDragStart=useCallback(event=>{setActiveFieldId(String(event.active.id))},[]),handleDragEnd=useCallback(event=>{setActiveFieldId(null);let{active,over}=event;if(over&&active.id!==over.id){let oldIndex=fields.findIndex(f=>getFieldId(f)===active.id),newIndex=fields.findIndex(f=>getFieldId(f)===over.id);oldIndex!==-1&&newIndex!==-1&&onChangeFields?.(arrayMove(fields,oldIndex,newIndex))}},[fields,onChangeFields]),handleDragCancel=useCallback(()=>{setActiveFieldId(null)},[]),handleFieldChange=useCallback((index,field)=>{onChangeFields?.(fields.map((f,i)=>i===index?field:f))},[fields,onChangeFields]),handleDeleteAtIndex=useCallback(index=>{let fieldToDelete=fields[index],fieldId=getFieldId(fieldToDelete);setExpandedFieldKey(prev=>prev===fieldId?null:prev),onChangeFields?.(fields.filter((_,i)=>i!==index)),onDeleteFieldAtIndex?.(index,fieldToDelete)},[fields,onChangeFields,onDeleteFieldAtIndex]),handleDuplicateAtIndex=useCallback(index=>{let fieldToDuplicate=fields[index],duplicated=cloneDeep(fieldToDuplicate);duplicated.id=uniqueId(`field-`),duplicated.key=``,duplicated.isFieldNew=!0,duplicated.type===FieldType.Dropdown&&(duplicated.dropdown.options=duplicated.dropdown.options.map(opt=>({...opt,id:uniqueId()})));let newFields=[...fields];newFields.splice(index+1,0,duplicated),onChangeFields?.(newFields),onDuplicateField?.(duplicated)},[fields,onChangeFields,onDuplicateField]),handleReorderFields=useCallback((fromIndex,toIndex)=>{toIndex<0||toIndex>=fields.length||onChangeFields?.(arrayMove(fields,fromIndex,toIndex))},[fields,onChangeFields]),handleAccordionValueChange=useCallback(value=>{let newKey=value||null;setExpandedFieldKey(newKey),newKey&&setTimeout(()=>{(fieldListRef.current?.querySelector(`[data-field-id="${newKey}"]`))?.scrollIntoView({behavior:`smooth`,block:`nearest`})},ACCORDION_ANIMATION_MS)},[]),items=fields.map(f=>getFieldId(f)),activeField=activeFieldId?fields.find(f=>getFieldId(f)===activeFieldId):null,OverlayTitleIcon=activeField?FieldTypeIcon(activeField.type):null,overlayTitle=activeField?(field=>{let name=field.name||formatMessage(general.fieldNameInputPlaceholder);return field.type===FieldType.Dropdown?`${name} (${field.dropdown?.options?.length??0})`:name})(activeField):``,editorConfigValue=useMemo(()=>({disabledFieldTypes:disabledFieldTypes??parentEditorConfig.disabledFieldTypes,taxonomyInitialStateLabels:taxonomyInitialStateLabels??parentEditorConfig.taxonomyInitialStateLabels}),[disabledFieldTypes,taxonomyInitialStateLabels,parentEditorConfig]),listItems=readOnly?jsx(`ul`,{ref:fieldListRef,className:metadata_field_list_module_default.fieldList,children:fields.map((field,index)=>{let fieldId=getFieldId(field);return jsx(`li`,{"data-field-id":fieldId,className:metadata_field_list_module_default.fieldItem,children:jsx(MetadataFieldConfigurator,{values:field,onValuesChange:()=>void 0,index,maxIndex:fields.length-1,onDuplicate:()=>void 0,onReorderFields:()=>void 0,onDragStart:()=>void 0,onDragEnd:()=>void 0,onTouchStart:()=>void 0,isExpanded:expandedFieldKey===fieldId,onExpandedChange:expanded=>{expanded&&setExpandedFieldKey(fieldId)},readOnly:!0})},fieldId)})}):jsx(SortableContext,{items,strategy:verticalListSortingStrategy,children:jsx(`ul`,{ref:fieldListRef,className:metadata_field_list_module_default.fieldList,children:fields.map((field,index)=>{let fieldId=getFieldId(field);return jsx(SortableFieldItem,{field,index,maxIndex:fields.length-1,isExpanded:expandedFieldKey===fieldId,onChangeField:updatedField=>handleFieldChange(index,updatedField),onDeleteAtIndex:handleDeleteAtIndex,onDuplicateAtIndex:handleDuplicateAtIndex,onReorderFields:handleReorderFields,onRequestExpand:()=>setExpandedFieldKey(fieldId),submitAttemptCount},fieldId)})})}),accordionContainer=jsx(`div`,{className:metadata_field_list_module_default.accordionRootContainer,children:jsx(Accordion,{type:`single`,collapsible:!0,value:expandedFieldKey??``,onValueChange:handleAccordionValueChange,children:listItems})}),coreContent=readOnly?accordionContainer:jsxs(DndContext,{sensors,collisionDetection:closestCenter,onDragStart:handleDragStart,onDragEnd:handleDragEnd,onDragCancel:handleDragCancel,children:[accordionContainer,jsx(DragOverlay,{dropAnimation:null,children:activeField&&OverlayTitleIcon?jsx(Accordion,{type:`single`,children:jsx(Accordion.Item,{value:`ghost`,title:overlayTitle,startElement:jsx(OverlayTitleIcon,{fontSize:`20px`,role:`presentation`}),children:null})}):null})]}),listContent=jsx(EditorConfigContext.Provider,{value:editorConfigValue,children:jsx(TaxonomyOptionsContext.Provider,{value:taxonomyContextValue,children:coreContent})});return fieldExtensions===void 0?listContent:jsx(FieldExtensionsContext.Provider,{value:fieldExtensions,children:listContent})});export{MetadataFieldList as t};
|
|
@@ -1,132 +1 @@
|
|
|
1
|
-
import { t as
|
|
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 { createDefaultFieldValues as r } from "../esm/lib/components/metadata-field-configurator/utils.js";
|
|
5
|
-
import { FieldExtensionsContext as i } from "../esm/lib/components/metadata-field-configurator/context/field-extensions-context.js";
|
|
6
|
-
import { t as a } from "./metadata-field-list.js";
|
|
7
|
-
import o from "../esm/lib/messages.js";
|
|
8
|
-
import { Button as s, EmptyState as c, Link as l, Text as u, TextInput as d } from "@box/blueprint-web";
|
|
9
|
-
import { FormattedMessage as f, useIntl as p } from "react-intl";
|
|
10
|
-
import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
11
|
-
import { useEffect as _, useMemo as v, useRef as y } from "react";
|
|
12
|
-
import b from "clsx";
|
|
13
|
-
import { Form as x, useFormikContext as ee } from "formik";
|
|
14
|
-
import { NoTemplates as S } from "@box/blueprint-web-assets/illustrations/Medium";
|
|
15
|
-
import '../styles/metadata-template-editor-form.css';var C = {
|
|
16
|
-
form: "_form_1r59b_1",
|
|
17
|
-
fields: "_fields_1r59b_10",
|
|
18
|
-
emptyFields: "_emptyFields_1r59b_16",
|
|
19
|
-
actions: "_actions_1r59b_21",
|
|
20
|
-
fieldsHeader: "_fieldsHeader_1r59b_28"
|
|
21
|
-
}, w = "bodyDefaultBold", T = "h2", E = "https://developer.box.com/guides/metadata/fields/", D = ({ formId: D, onCancel: O, taxonomyOptions: k, fetchTaxonomies: A, hideActions: te, isEditMode: ne, readOnly: j = !1, onDirtyStateChange: M, onValidationChange: N, fieldExtensions: P }) => {
|
|
22
|
-
let F = p(), { errors: I, values: L, setFieldValue: R, setFieldTouched: z, isSubmitting: B, isValid: V, handleChange: H, submitCount: U, dirty: W, touched: G } = ee(), K = y(null), q = y(!1), J = () => {
|
|
23
|
-
q.current = !0;
|
|
24
|
-
}, Y = () => {
|
|
25
|
-
q.current && z("displayName", !0);
|
|
26
|
-
}, X = v(() => {
|
|
27
|
-
if (!Array.isArray(I.fields)) return null;
|
|
28
|
-
let e = I.fields.findIndex(Boolean);
|
|
29
|
-
return e >= 0 ? e : null;
|
|
30
|
-
}, [I.fields]), Z = (e) => {
|
|
31
|
-
let t = r(e.type);
|
|
32
|
-
R("fields", [...L.fields, t]);
|
|
33
|
-
}, re = (e) => {
|
|
34
|
-
R("fields", e);
|
|
35
|
-
};
|
|
36
|
-
_(() => {
|
|
37
|
-
M?.(W);
|
|
38
|
-
}, [W, M]), _(() => {
|
|
39
|
-
N?.(V);
|
|
40
|
-
}, [V, N]);
|
|
41
|
-
let ie = B || ne && !W, Q;
|
|
42
|
-
Q = j && L.fields.length === 0 ? /* @__PURE__ */ h(c, {
|
|
43
|
-
size: "large",
|
|
44
|
-
illustration: S,
|
|
45
|
-
body: /* @__PURE__ */ h(u, {
|
|
46
|
-
as: "p",
|
|
47
|
-
children: F.formatMessage(o.noFields)
|
|
48
|
-
})
|
|
49
|
-
}) : j ? /* @__PURE__ */ h(a, {
|
|
50
|
-
ref: K,
|
|
51
|
-
fields: L.fields,
|
|
52
|
-
taxonomyOptions: k,
|
|
53
|
-
fetchTaxonomies: A,
|
|
54
|
-
readOnly: !0
|
|
55
|
-
}) : L.fields.length === 0 ? /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h(n, { onFieldAdd: Z }), /* @__PURE__ */ h(l, {
|
|
56
|
-
href: E,
|
|
57
|
-
isExternal: !0,
|
|
58
|
-
target: "_blank",
|
|
59
|
-
children: /* @__PURE__ */ h(f, { ...o.fieldsLearnMore })
|
|
60
|
-
})] }) : /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h(a, {
|
|
61
|
-
ref: K,
|
|
62
|
-
fields: L.fields,
|
|
63
|
-
taxonomyOptions: k,
|
|
64
|
-
fetchTaxonomies: A,
|
|
65
|
-
onChangeFields: re,
|
|
66
|
-
firstInvalidFieldIndex: X,
|
|
67
|
-
submitAttemptCount: U
|
|
68
|
-
}), /* @__PURE__ */ h(t, { onFieldAdd: Z })] });
|
|
69
|
-
let $ = /* @__PURE__ */ g(x, {
|
|
70
|
-
noValidate: !0,
|
|
71
|
-
id: D,
|
|
72
|
-
className: C.form,
|
|
73
|
-
children: [
|
|
74
|
-
/* @__PURE__ */ h("div", { children: /* @__PURE__ */ h(d, {
|
|
75
|
-
name: "displayName",
|
|
76
|
-
label: F.formatMessage(o.templateName),
|
|
77
|
-
placeholder: F.formatMessage(o.templateNameDescription),
|
|
78
|
-
value: L.displayName,
|
|
79
|
-
error: !j && G.displayName && I.displayName ? I.displayName : void 0,
|
|
80
|
-
onChange: (e) => {
|
|
81
|
-
H(e);
|
|
82
|
-
},
|
|
83
|
-
onPointerDown: J,
|
|
84
|
-
onKeyDown: J,
|
|
85
|
-
onBlur: Y,
|
|
86
|
-
readOnly: j
|
|
87
|
-
}) }),
|
|
88
|
-
/* @__PURE__ */ g("div", {
|
|
89
|
-
className: C.fieldsHeader,
|
|
90
|
-
children: [/* @__PURE__ */ h(u, {
|
|
91
|
-
as: T,
|
|
92
|
-
variant: w,
|
|
93
|
-
children: /* @__PURE__ */ h(f, { ...!j && L.fields.length === 0 ? o.fieldsAddFirst : o.fields })
|
|
94
|
-
}), L.fields.length > 0 && /* @__PURE__ */ h(e, {
|
|
95
|
-
fields: L.fields,
|
|
96
|
-
onSelect: (e) => K.current?.scrollToAndExpand(e)
|
|
97
|
-
})]
|
|
98
|
-
}),
|
|
99
|
-
/* @__PURE__ */ h("div", {
|
|
100
|
-
className: b(C.fields, { [C.emptyFields]: L.fields.length === 0 && j }),
|
|
101
|
-
children: Q
|
|
102
|
-
}),
|
|
103
|
-
!te && /* @__PURE__ */ h("div", {
|
|
104
|
-
className: C.actions,
|
|
105
|
-
children: j ? O && /* @__PURE__ */ h(s, {
|
|
106
|
-
variant: "primary",
|
|
107
|
-
type: "button",
|
|
108
|
-
onClick: O,
|
|
109
|
-
children: F.formatMessage(o.close)
|
|
110
|
-
}) : /* @__PURE__ */ g(m, { children: [O && /* @__PURE__ */ h(s, {
|
|
111
|
-
variant: "secondary",
|
|
112
|
-
type: "button",
|
|
113
|
-
onClick: O,
|
|
114
|
-
loading: B,
|
|
115
|
-
disabled: B,
|
|
116
|
-
loadingAriaLabel: F.formatMessage(o.submitting),
|
|
117
|
-
children: F.formatMessage(o.cancel)
|
|
118
|
-
}), /* @__PURE__ */ h(s, {
|
|
119
|
-
variant: "primary",
|
|
120
|
-
type: "submit",
|
|
121
|
-
disabled: ie,
|
|
122
|
-
children: F.formatMessage(o.save)
|
|
123
|
-
})] })
|
|
124
|
-
})
|
|
125
|
-
]
|
|
126
|
-
});
|
|
127
|
-
return P === void 0 ? $ : /* @__PURE__ */ h(i.Provider, {
|
|
128
|
-
value: P,
|
|
129
|
-
children: $
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
export { D as t };
|
|
1
|
+
import{t as FieldSelector}from"./field-selector.js";import{t as FieldTypeDropdown}from"./field-type-dropdown.js";import{FieldTypeTiles}from"../esm/lib/components/field-type-tiles/field-type-tiles.js";import{createDefaultFieldValues}from"../esm/lib/components/metadata-field-configurator/utils.js";import{FieldExtensionsContext}from"../esm/lib/components/metadata-field-configurator/context/field-extensions-context.js";import{t as MetadataFieldList}from"./metadata-field-list.js";import messages_default from"../esm/lib/messages.js";import{Button,EmptyState,Link,Text,TextInput}from"@box/blueprint-web";import{FormattedMessage,useIntl}from"react-intl";import{Fragment,jsx,jsxs}from"react/jsx-runtime";import{useEffect,useMemo,useRef}from"react";import clsx from"clsx";import{Form,useFormikContext}from"formik";import{NoTemplates}from"@box/blueprint-web-assets/illustrations/Medium";import '../styles/metadata-template-editor-form.css';var metadata_template_editor_form_module_default={form:`_form_1r59b_1`,fields:`_fields_1r59b_10`,emptyFields:`_emptyFields_1r59b_16`,actions:`_actions_1r59b_21`,fieldsHeader:`_fieldsHeader_1r59b_28`},FIELD_NAME_VARIANT=`bodyDefaultBold`,FIELD_NAME_VARIANT_AS_ELEMENT=`h2`,BOX_METADATA_FIELDS_GUIDE_URL=`https://developer.box.com/guides/metadata/fields/`,MetadataTemplateEditorForm=({formId,onCancel,taxonomyOptions,fetchTaxonomies,hideActions,isEditMode,readOnly=!1,onDirtyStateChange,onValidationChange,fieldExtensions})=>{let intl=useIntl(),{errors,values,setFieldValue,setFieldTouched,isSubmitting,isValid,handleChange,submitCount,dirty,touched}=useFormikContext(),fieldListRef=useRef(null),hasUserFocusedDisplayNameRef=useRef(!1),markDisplayNameUserFocused=()=>{hasUserFocusedDisplayNameRef.current=!0},handleDisplayNameBlur=()=>{hasUserFocusedDisplayNameRef.current&&setFieldTouched(`displayName`,!0)},firstInvalidFieldIndex=useMemo(()=>{if(!Array.isArray(errors.fields))return null;let idx=errors.fields.findIndex(Boolean);return idx>=0?idx:null},[errors.fields]),handleFieldAdd=fieldType=>{let newField=createDefaultFieldValues(fieldType.type);setFieldValue(`fields`,[...values.fields,newField])},handleFieldsChange=fields=>{setFieldValue(`fields`,fields)};useEffect(()=>{onDirtyStateChange?.(dirty)},[dirty,onDirtyStateChange]),useEffect(()=>{onValidationChange?.(isValid)},[isValid,onValidationChange]);let isSaveDisabled=isSubmitting||isEditMode&&!dirty,fieldsContent;fieldsContent=readOnly&&values.fields.length===0?jsx(EmptyState,{size:`large`,illustration:NoTemplates,body:jsx(Text,{as:`p`,children:intl.formatMessage(messages_default.noFields)})}):readOnly?jsx(MetadataFieldList,{ref:fieldListRef,fields:values.fields,taxonomyOptions,fetchTaxonomies,readOnly:!0}):values.fields.length===0?jsxs(Fragment,{children:[jsx(FieldTypeTiles,{onFieldAdd:handleFieldAdd}),jsx(Link,{href:BOX_METADATA_FIELDS_GUIDE_URL,isExternal:!0,target:`_blank`,children:jsx(FormattedMessage,{...messages_default.fieldsLearnMore})})]}):jsxs(Fragment,{children:[jsx(MetadataFieldList,{ref:fieldListRef,fields:values.fields,taxonomyOptions,fetchTaxonomies,onChangeFields:handleFieldsChange,firstInvalidFieldIndex,submitAttemptCount:submitCount}),jsx(FieldTypeDropdown,{onFieldAdd:handleFieldAdd})]});let formElement=jsxs(Form,{noValidate:!0,id:formId,className:metadata_template_editor_form_module_default.form,children:[jsx(`div`,{children:jsx(TextInput,{name:`displayName`,label:intl.formatMessage(messages_default.templateName),placeholder:intl.formatMessage(messages_default.templateNameDescription),value:values.displayName,error:!readOnly&&touched.displayName&&errors.displayName?errors.displayName:void 0,onChange:e=>{handleChange(e)},onPointerDown:markDisplayNameUserFocused,onKeyDown:markDisplayNameUserFocused,onBlur:handleDisplayNameBlur,readOnly})}),jsxs(`div`,{className:metadata_template_editor_form_module_default.fieldsHeader,children:[jsx(Text,{as:FIELD_NAME_VARIANT_AS_ELEMENT,variant:FIELD_NAME_VARIANT,children:jsx(FormattedMessage,{...!readOnly&&values.fields.length===0?messages_default.fieldsAddFirst:messages_default.fields})}),values.fields.length>0&&jsx(FieldSelector,{fields:values.fields,onSelect:fieldId=>fieldListRef.current?.scrollToAndExpand(fieldId)})]}),jsx(`div`,{className:clsx(metadata_template_editor_form_module_default.fields,{[metadata_template_editor_form_module_default.emptyFields]:values.fields.length===0&&readOnly}),children:fieldsContent}),!hideActions&&jsx(`div`,{className:metadata_template_editor_form_module_default.actions,children:readOnly?onCancel&&jsx(Button,{variant:`primary`,type:`button`,onClick:onCancel,children:intl.formatMessage(messages_default.close)}):jsxs(Fragment,{children:[onCancel&&jsx(Button,{variant:`secondary`,type:`button`,onClick:onCancel,loading:isSubmitting,disabled:isSubmitting,loadingAriaLabel:intl.formatMessage(messages_default.submitting),children:intl.formatMessage(messages_default.cancel)}),jsx(Button,{variant:`primary`,type:`submit`,disabled:isSaveDisabled,children:intl.formatMessage(messages_default.save)})]})})]});return fieldExtensions===void 0?formElement:jsx(FieldExtensionsContext.Provider,{value:fieldExtensions,children:formElement})};export{MetadataTemplateEditorForm as t};
|
|
@@ -1,90 +1 @@
|
|
|
1
|
-
import
|
|
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 { Fragment as a, jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
7
|
-
import { useCallback as c, useEffect as l, useId as u, useRef as d, useState as f } from "react";
|
|
8
|
-
import p from "clsx";
|
|
9
|
-
import '../styles/metadata-template-editor-modal.css';var m = {
|
|
10
|
-
modal: "_modal_1s9i6_1",
|
|
11
|
-
centeredBody: "_centeredBody_1s9i6_7",
|
|
12
|
-
modalScrollableContainer: "_modalScrollableContainer_1s9i6_15",
|
|
13
|
-
modalBody: "_modalBody_1s9i6_21"
|
|
14
|
-
};
|
|
15
|
-
function h({ open: h, onOpenChange: g, onTemplateLoad: _, onValidationChange: v, onCancel: y, title: b, ...x }) {
|
|
16
|
-
let S = i(), C = u(), w = d(null), [T, E] = f(!1), [D, O] = f(!1), [k, A] = f(void 0), j = x.mode === e.Edit, M = x.mode === e.ReadOnly, N = c(() => {
|
|
17
|
-
y?.(), g(!1);
|
|
18
|
-
}, [y, g]);
|
|
19
|
-
l(() => {
|
|
20
|
-
h || (O(!1), A(void 0));
|
|
21
|
-
}, [h]);
|
|
22
|
-
let P = (e) => {
|
|
23
|
-
e ? g(e) : w.current?.requestClose();
|
|
24
|
-
}, F = (e) => {
|
|
25
|
-
A(e.displayName), _?.(e);
|
|
26
|
-
}, I = (e) => async (...t) => {
|
|
27
|
-
E(!0);
|
|
28
|
-
try {
|
|
29
|
-
await e(...t), g(!1);
|
|
30
|
-
} finally {
|
|
31
|
-
E(!1);
|
|
32
|
-
}
|
|
33
|
-
}, L;
|
|
34
|
-
L = j ? {
|
|
35
|
-
...x,
|
|
36
|
-
onEditTemplate: I(x.onEditTemplate)
|
|
37
|
-
} : M ? x : {
|
|
38
|
-
...x,
|
|
39
|
-
onCreateTemplate: I(x.onCreateTemplate)
|
|
40
|
-
};
|
|
41
|
-
let R = T || j && !D, z = (j || M) && !k, B;
|
|
42
|
-
B = M ? k ? S.formatMessage(t.viewTitle, { templateName: k }) : "" : j && k ? S.formatMessage(t.editTitle, { templateName: k }) : S.formatMessage(t.createTitle);
|
|
43
|
-
let V = b ?? B;
|
|
44
|
-
return /* @__PURE__ */ o(r, {
|
|
45
|
-
open: h,
|
|
46
|
-
onOpenChange: P,
|
|
47
|
-
children: /* @__PURE__ */ s(r.Content, {
|
|
48
|
-
size: "large",
|
|
49
|
-
className: m.modal,
|
|
50
|
-
children: [
|
|
51
|
-
/* @__PURE__ */ o(r.Header, { children: V }),
|
|
52
|
-
/* @__PURE__ */ o(r.ScrollableContainer, {
|
|
53
|
-
className: p(m.modalScrollableContainer, { [m.centeredBody]: z }),
|
|
54
|
-
children: /* @__PURE__ */ o(r.Body, {
|
|
55
|
-
className: m.modalBody,
|
|
56
|
-
children: /* @__PURE__ */ o(n, {
|
|
57
|
-
...L,
|
|
58
|
-
ref: w,
|
|
59
|
-
formId: C,
|
|
60
|
-
hideActions: !0,
|
|
61
|
-
onCancel: N,
|
|
62
|
-
onDirtyStateChange: O,
|
|
63
|
-
onValidationChange: v,
|
|
64
|
-
onTemplateLoad: F
|
|
65
|
-
})
|
|
66
|
-
})
|
|
67
|
-
}),
|
|
68
|
-
/* @__PURE__ */ o(r.Footer, { children: M ? /* @__PURE__ */ o(r.Footer.PrimaryButton, {
|
|
69
|
-
onClick: N,
|
|
70
|
-
size: "large",
|
|
71
|
-
children: S.formatMessage(t.close)
|
|
72
|
-
}) : /* @__PURE__ */ s(a, { children: [/* @__PURE__ */ o(r.Footer.SecondaryButton, {
|
|
73
|
-
onClick: () => w.current?.requestClose(),
|
|
74
|
-
size: "large",
|
|
75
|
-
children: S.formatMessage(t.cancel)
|
|
76
|
-
}), /* @__PURE__ */ o(r.Footer.PrimaryButton, {
|
|
77
|
-
variant: "primary",
|
|
78
|
-
type: "submit",
|
|
79
|
-
form: C,
|
|
80
|
-
loading: T,
|
|
81
|
-
loadingAriaLabel: S.formatMessage(t.submitting),
|
|
82
|
-
disabled: R,
|
|
83
|
-
children: S.formatMessage(t.save)
|
|
84
|
-
})] }) }),
|
|
85
|
-
/* @__PURE__ */ o(r.Close, { "aria-label": S.formatMessage(t.closeAriaLabel) })
|
|
86
|
-
]
|
|
87
|
-
})
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
export { h as t };
|
|
1
|
+
import{o as MetadataTemplateEditorMode}from"./types.js";import messages_default from"../esm/lib/messages.js";import{t as MetadataTemplateEditor}from"./metadata-template-editor.js";import{Modal}from"@box/blueprint-web";import{useIntl}from"react-intl";import{Fragment,jsx,jsxs}from"react/jsx-runtime";import{useCallback,useEffect,useId,useRef,useState}from"react";import clsx from"clsx";import '../styles/metadata-template-editor-modal.css';var metadata_template_editor_modal_module_default={modal:`_modal_1s9i6_1`,centeredBody:`_centeredBody_1s9i6_7`,modalScrollableContainer:`_modalScrollableContainer_1s9i6_15`,modalBody:`_modalBody_1s9i6_21`};function MetadataTemplateEditorModal({open,onOpenChange,onTemplateLoad,onValidationChange,onCancel,title,...editorProps}){let intl=useIntl(),formId=useId(),editorRef=useRef(null),[isSubmitting,setIsSubmitting]=useState(!1),[isDirty,setIsDirty]=useState(!1),[loadedTemplateName,setLoadedTemplateName]=useState(void 0),isEditMode=editorProps.mode===MetadataTemplateEditorMode.Edit,isReadOnlyMode=editorProps.mode===MetadataTemplateEditorMode.ReadOnly,closeEditor=useCallback(()=>{onCancel?.(),onOpenChange(!1)},[onCancel,onOpenChange]);useEffect(()=>{open||(setIsDirty(!1),setLoadedTemplateName(void 0))},[open]);let handleOpenChange=newOpen=>{newOpen?onOpenChange(newOpen):editorRef.current?.requestClose()},handleTemplateLoad=template=>{setLoadedTemplateName(template.displayName),onTemplateLoad?.(template)},wrapSubmit=callback=>async(...args)=>{setIsSubmitting(!0);try{await callback(...args),onOpenChange(!1)}finally{setIsSubmitting(!1)}},wrappedEditorProps;wrappedEditorProps=isEditMode?{...editorProps,onEditTemplate:wrapSubmit(editorProps.onEditTemplate)}:isReadOnlyMode?editorProps:{...editorProps,onCreateTemplate:wrapSubmit(editorProps.onCreateTemplate)};let isSaveDisabled=isSubmitting||isEditMode&&!isDirty,isBodyCentered=(isEditMode||isReadOnlyMode)&&!loadedTemplateName,defaultTitle;defaultTitle=isReadOnlyMode?loadedTemplateName?intl.formatMessage(messages_default.viewTitle,{templateName:loadedTemplateName}):``:isEditMode&&loadedTemplateName?intl.formatMessage(messages_default.editTitle,{templateName:loadedTemplateName}):intl.formatMessage(messages_default.createTitle);let modalTitle=title??defaultTitle;return jsx(Modal,{open,onOpenChange:handleOpenChange,children:jsxs(Modal.Content,{size:`large`,className:metadata_template_editor_modal_module_default.modal,children:[jsx(Modal.Header,{children:modalTitle}),jsx(Modal.ScrollableContainer,{className:clsx(metadata_template_editor_modal_module_default.modalScrollableContainer,{[metadata_template_editor_modal_module_default.centeredBody]:isBodyCentered}),children:jsx(Modal.Body,{className:metadata_template_editor_modal_module_default.modalBody,children:jsx(MetadataTemplateEditor,{...wrappedEditorProps,ref:editorRef,formId,hideActions:!0,onCancel:closeEditor,onDirtyStateChange:setIsDirty,onValidationChange,onTemplateLoad:handleTemplateLoad})})}),jsx(Modal.Footer,{children:isReadOnlyMode?jsx(Modal.Footer.PrimaryButton,{onClick:closeEditor,size:`large`,children:intl.formatMessage(messages_default.close)}):jsxs(Fragment,{children:[jsx(Modal.Footer.SecondaryButton,{onClick:()=>editorRef.current?.requestClose(),size:`large`,children:intl.formatMessage(messages_default.cancel)}),jsx(Modal.Footer.PrimaryButton,{variant:`primary`,type:`submit`,form:formId,loading:isSubmitting,loadingAriaLabel:intl.formatMessage(messages_default.submitting),disabled:isSaveDisabled,children:intl.formatMessage(messages_default.save)})]})}),jsx(Modal.Close,{"aria-label":intl.formatMessage(messages_default.closeAriaLabel)})]})})}export{MetadataTemplateEditorModal as t};
|