@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,161 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { EditorConfigContext as t } from "../esm/lib/components/metadata-field-configurator/context/editor-config-context.js";
|
|
3
|
-
import "../esm/lib/utils/constants.js";
|
|
4
|
-
import n from "../esm/lib/components/metadata-field-configurator/components/confirmation-modal/confirmation-modal.js";
|
|
5
|
-
import r from "../esm/lib/messages.js";
|
|
6
|
-
import { useMetadataTemplateFormSchema as i } from "../esm/lib/hooks/useMetadataTemplateFormSchema.js";
|
|
7
|
-
import { convertApiMetadataTemplateFieldToLocalConfiguratorField as a } from "../esm/lib/utils/template-type-conversion/convertTemplateFieldToLocalConfigurator.js";
|
|
8
|
-
import { mapFieldsWithUniqueKeys as o } from "../esm/lib/utils/template-type-conversion/mapFieldsWithUniqueKeys.js";
|
|
9
|
-
import { generateJSONPatchTemplateOperations as s } from "../esm/lib/utils/template-type-conversion/generateJSONPatchTemplateOperations.js";
|
|
10
|
-
import { t as c } from "./metadata-template-editor-form.js";
|
|
11
|
-
import { EmptyState as l, LoadingIndicator as u, Text as d, useNotification as ee } from "@box/blueprint-web";
|
|
12
|
-
import { useIntl as te } from "react-intl";
|
|
13
|
-
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
14
|
-
import { forwardRef as m, useCallback as h, useEffect as g, useImperativeHandle as _, useMemo as v, useState as y } from "react";
|
|
15
|
-
import { ArrowsRotating as b } from "@box/blueprint-web-assets/icons/Line";
|
|
16
|
-
import { Formik as x } from "formik";
|
|
17
|
-
import { ErrorState404 as S } from "@box/blueprint-web-assets/illustrations/Medium";
|
|
18
|
-
import '../styles/metadata-template-editor.css';var C = {
|
|
19
|
-
loading: "_loading_fd3t9_1",
|
|
20
|
-
error: "_error_fd3t9_8"
|
|
21
|
-
}, ne = {
|
|
22
|
-
displayName: "",
|
|
23
|
-
templateKey: "",
|
|
24
|
-
fields: [],
|
|
25
|
-
hidden: !1
|
|
26
|
-
}, w = /*#__PURE__*/ m(function({ onCancel: m, onDirtyStateChange: w, onValidationChange: re, onSubmitError: ie, onTemplateLoad: T, taxonomyOptions: ae, fetchTaxonomies: E, disabledFieldTypes: D, taxonomyInitialStateLabels: O, formId: k, hideActions: A = !1, fieldExtensions: j, ...M }, N) {
|
|
27
|
-
let P = i(), { formatMessage: F } = te(), { addNotification: I } = ee(), L = M.mode === e.Edit, R = M.mode === e.ReadOnly, [z, B] = y(!1), [V, H] = y(!1), U = h(() => {
|
|
28
|
-
z ? H(!0) : m?.();
|
|
29
|
-
}, [z, m]);
|
|
30
|
-
_(N, () => ({ requestClose: U }), [U]);
|
|
31
|
-
let W = h((e) => {
|
|
32
|
-
B(e), w?.(e);
|
|
33
|
-
}, [w]), [G, K] = y(L || R), [q, J] = y(!1), [oe, se] = y(0), [Y, X] = y(void 0), Z = L || R ? M.fetchTemplate : void 0, ce = () => {
|
|
34
|
-
se((e) => e + 1);
|
|
35
|
-
};
|
|
36
|
-
g(() => {
|
|
37
|
-
if (!Z) return;
|
|
38
|
-
let e = !1;
|
|
39
|
-
return K(!0), J(!1), X(void 0), (async () => {
|
|
40
|
-
try {
|
|
41
|
-
let t = await Z();
|
|
42
|
-
e || X(t);
|
|
43
|
-
} catch {
|
|
44
|
-
e || J(!0);
|
|
45
|
-
} finally {
|
|
46
|
-
e || K(!1);
|
|
47
|
-
}
|
|
48
|
-
})(), () => {
|
|
49
|
-
e = !0;
|
|
50
|
-
};
|
|
51
|
-
}, [Z, oe]), g(() => {
|
|
52
|
-
Y !== void 0 && T?.(Y);
|
|
53
|
-
}, [Y, T]);
|
|
54
|
-
let Q = L || R ? void 0 : M.namespace, $ = v(() => Y ? {
|
|
55
|
-
displayName: Y.displayName,
|
|
56
|
-
templateKey: Y.templateKey,
|
|
57
|
-
namespace: Y.namespace,
|
|
58
|
-
hidden: Y.isHidden,
|
|
59
|
-
fields: Y.fields.map((e) => a(e))
|
|
60
|
-
} : {
|
|
61
|
-
...ne,
|
|
62
|
-
namespace: Q ?? ""
|
|
63
|
-
}, [Y, Q]), le = v(() => ({
|
|
64
|
-
disabledFieldTypes: D,
|
|
65
|
-
taxonomyInitialStateLabels: O
|
|
66
|
-
}), [D, O]);
|
|
67
|
-
return G ? /* @__PURE__ */ f("div", {
|
|
68
|
-
className: C.loading,
|
|
69
|
-
children: /* @__PURE__ */ f(u, {
|
|
70
|
-
size: "large",
|
|
71
|
-
"aria-label": F(r.loading)
|
|
72
|
-
})
|
|
73
|
-
}) : q ? /* @__PURE__ */ f("div", {
|
|
74
|
-
className: C.error,
|
|
75
|
-
children: /* @__PURE__ */ f(l, {
|
|
76
|
-
body: /* @__PURE__ */ f(d, {
|
|
77
|
-
as: "p",
|
|
78
|
-
children: F(r.fetchError)
|
|
79
|
-
}),
|
|
80
|
-
illustration: S,
|
|
81
|
-
size: "large",
|
|
82
|
-
children: /* @__PURE__ */ f(l.PrimaryAction, {
|
|
83
|
-
startIcon: b,
|
|
84
|
-
onClick: ce,
|
|
85
|
-
children: F(r.reload)
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
}) : /* @__PURE__ */ p(t.Provider, {
|
|
89
|
-
value: le,
|
|
90
|
-
children: [/* @__PURE__ */ f(x, {
|
|
91
|
-
initialValues: $,
|
|
92
|
-
validationSchema: R ? void 0 : P,
|
|
93
|
-
onSubmit: async (e) => {
|
|
94
|
-
if (!R) try {
|
|
95
|
-
if (L) {
|
|
96
|
-
let t = s($, e);
|
|
97
|
-
await M.onEditTemplate(t, {
|
|
98
|
-
namespaceFQN: $.namespace,
|
|
99
|
-
templateKey: $.templateKey
|
|
100
|
-
});
|
|
101
|
-
} else {
|
|
102
|
-
let t = o(e.fields), n = {
|
|
103
|
-
namespace: e.namespace,
|
|
104
|
-
templateKey: e.templateKey,
|
|
105
|
-
displayName: e.displayName,
|
|
106
|
-
hidden: e.hidden,
|
|
107
|
-
fields: t
|
|
108
|
-
};
|
|
109
|
-
await M.onCreateTemplate(n);
|
|
110
|
-
}
|
|
111
|
-
I({
|
|
112
|
-
sensitivity: "foreground",
|
|
113
|
-
variant: "success",
|
|
114
|
-
styledText: F(r.saveSuccessNotification),
|
|
115
|
-
typeIconAriaLabel: F(r.notificationSuccessIconAriaLabel),
|
|
116
|
-
closeButtonAriaLabel: F(r.notificationCloseButtonAriaLabel)
|
|
117
|
-
});
|
|
118
|
-
} catch (e) {
|
|
119
|
-
let t;
|
|
120
|
-
if (e instanceof Error && "status" in e) {
|
|
121
|
-
let { status: n } = e;
|
|
122
|
-
t = F(n === 409 ? r.displayNameUsedBefore : r.saveErrorNotification);
|
|
123
|
-
} else t = F(r.saveErrorNotification);
|
|
124
|
-
I({
|
|
125
|
-
sensitivity: "foreground",
|
|
126
|
-
variant: "error",
|
|
127
|
-
styledText: t,
|
|
128
|
-
typeIconAriaLabel: F(r.notificationErrorIconAriaLabel),
|
|
129
|
-
closeButtonAriaLabel: F(r.notificationCloseButtonAriaLabel)
|
|
130
|
-
});
|
|
131
|
-
try {
|
|
132
|
-
ie?.(e);
|
|
133
|
-
} catch {}
|
|
134
|
-
throw e;
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
children: /* @__PURE__ */ f(c, {
|
|
138
|
-
formId: k,
|
|
139
|
-
onCancel: U,
|
|
140
|
-
taxonomyOptions: ae,
|
|
141
|
-
fetchTaxonomies: E,
|
|
142
|
-
hideActions: A,
|
|
143
|
-
isEditMode: L,
|
|
144
|
-
readOnly: R,
|
|
145
|
-
onDirtyStateChange: W,
|
|
146
|
-
onValidationChange: re,
|
|
147
|
-
fieldExtensions: j
|
|
148
|
-
})
|
|
149
|
-
}), V && /* @__PURE__ */ f(n, {
|
|
150
|
-
onClose: () => H(!1),
|
|
151
|
-
onConfirm: () => {
|
|
152
|
-
H(!1), m?.();
|
|
153
|
-
},
|
|
154
|
-
title: F(r.unsavedChangesTitle),
|
|
155
|
-
body: F(r.unsavedChangesBody),
|
|
156
|
-
confirmLabel: F(r.unsavedChangesDiscard),
|
|
157
|
-
cancelLabel: F(r.unsavedChangesKeepEditing)
|
|
158
|
-
})]
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
export { w as t };
|
|
1
|
+
import{o as MetadataTemplateEditorMode}from"./types.js";import{EditorConfigContext}from"../esm/lib/components/metadata-field-configurator/context/editor-config-context.js";import"../esm/lib/utils/constants.js";import ConfirmationModal from"../esm/lib/components/metadata-field-configurator/components/confirmation-modal/confirmation-modal.js";import messages_default from"../esm/lib/messages.js";import{useMetadataTemplateFormSchema}from"../esm/lib/hooks/useMetadataTemplateFormSchema.js";import{convertApiMetadataTemplateFieldToLocalConfiguratorField}from"../esm/lib/utils/template-type-conversion/convertTemplateFieldToLocalConfigurator.js";import{mapFieldsWithUniqueKeys}from"../esm/lib/utils/template-type-conversion/mapFieldsWithUniqueKeys.js";import{generateJSONPatchTemplateOperations}from"../esm/lib/utils/template-type-conversion/generateJSONPatchTemplateOperations.js";import{t as MetadataTemplateEditorForm}from"./metadata-template-editor-form.js";import{EmptyState,LoadingIndicator,Text,useNotification}from"@box/blueprint-web";import{useIntl}from"react-intl";import{jsx,jsxs}from"react/jsx-runtime";import{forwardRef,useCallback,useEffect,useImperativeHandle,useMemo,useState}from"react";import{ArrowsRotating}from"@box/blueprint-web-assets/icons/Line";import{Formik}from"formik";import{ErrorState404}from"@box/blueprint-web-assets/illustrations/Medium";import '../styles/metadata-template-editor.css';var metadata_template_editor_module_default={loading:`_loading_fd3t9_1`,error:`_error_fd3t9_8`},DEFAULT_VALUES={displayName:``,templateKey:``,fields:[],hidden:!1},MetadataTemplateEditor=forwardRef(function({onCancel,onDirtyStateChange,onValidationChange,onSubmitError,onTemplateLoad,taxonomyOptions,fetchTaxonomies,disabledFieldTypes,taxonomyInitialStateLabels,formId,hideActions=!1,fieldExtensions,...modeProps},ref){let schema=useMetadataTemplateFormSchema(),{formatMessage}=useIntl(),{addNotification}=useNotification(),isEditMode=modeProps.mode===MetadataTemplateEditorMode.Edit,isReadOnlyMode=modeProps.mode===MetadataTemplateEditorMode.ReadOnly,[isDirty,setIsDirty]=useState(!1),[isUnsavedChangesModalOpen,setIsUnsavedChangesModalOpen]=useState(!1),handleCancel=useCallback(()=>{isDirty?setIsUnsavedChangesModalOpen(!0):onCancel?.()},[isDirty,onCancel]);useImperativeHandle(ref,()=>({requestClose:handleCancel}),[handleCancel]);let handleDirtyStateChange=useCallback(dirty=>{setIsDirty(dirty),onDirtyStateChange?.(dirty)},[onDirtyStateChange]),[isLoading,setIsLoading]=useState(isEditMode||isReadOnlyMode),[hasFetchError,setHasFetchError]=useState(!1),[retryCount,setRetryCount]=useState(0),[fetchedValues,setFetchedValues]=useState(void 0),fetchTemplate=isEditMode||isReadOnlyMode?modeProps.fetchTemplate:void 0,handleRetry=()=>{setRetryCount(c=>c+1)};useEffect(()=>{if(!fetchTemplate)return;let cancelled=!1;return setIsLoading(!0),setHasFetchError(!1),setFetchedValues(void 0),(async()=>{try{let response=await fetchTemplate();cancelled||setFetchedValues(response)}catch{cancelled||setHasFetchError(!0)}finally{cancelled||setIsLoading(!1)}})(),()=>{cancelled=!0}},[fetchTemplate,retryCount]),useEffect(()=>{fetchedValues!==void 0&&onTemplateLoad?.(fetchedValues)},[fetchedValues,onTemplateLoad]);let createNamespace=isEditMode||isReadOnlyMode?void 0:modeProps.namespace,mergedInitialValues=useMemo(()=>fetchedValues?{displayName:fetchedValues.displayName,templateKey:fetchedValues.templateKey,namespace:fetchedValues.namespace,hidden:fetchedValues.isHidden,fields:fetchedValues.fields.map(field=>convertApiMetadataTemplateFieldToLocalConfiguratorField(field))}:{...DEFAULT_VALUES,namespace:createNamespace??``},[fetchedValues,createNamespace]),editorConfigValue=useMemo(()=>({disabledFieldTypes,taxonomyInitialStateLabels}),[disabledFieldTypes,taxonomyInitialStateLabels]);return isLoading?jsx(`div`,{className:metadata_template_editor_module_default.loading,children:jsx(LoadingIndicator,{size:`large`,"aria-label":formatMessage(messages_default.loading)})}):hasFetchError?jsx(`div`,{className:metadata_template_editor_module_default.error,children:jsx(EmptyState,{body:jsx(Text,{as:`p`,children:formatMessage(messages_default.fetchError)}),illustration:ErrorState404,size:`large`,children:jsx(EmptyState.PrimaryAction,{startIcon:ArrowsRotating,onClick:handleRetry,children:formatMessage(messages_default.reload)})})}):jsxs(EditorConfigContext.Provider,{value:editorConfigValue,children:[jsx(Formik,{initialValues:mergedInitialValues,validationSchema:isReadOnlyMode?void 0:schema,onSubmit:async values=>{if(!isReadOnlyMode)try{if(isEditMode){let patchItems=generateJSONPatchTemplateOperations(mergedInitialValues,values);await modeProps.onEditTemplate(patchItems,{namespaceFQN:mergedInitialValues.namespace,templateKey:mergedInitialValues.templateKey})}else{let convertedFields=mapFieldsWithUniqueKeys(values.fields),createBody={namespace:values.namespace,templateKey:values.templateKey,displayName:values.displayName,hidden:values.hidden,fields:convertedFields};await modeProps.onCreateTemplate(createBody)}addNotification({sensitivity:`foreground`,variant:`success`,styledText:formatMessage(messages_default.saveSuccessNotification),typeIconAriaLabel:formatMessage(messages_default.notificationSuccessIconAriaLabel),closeButtonAriaLabel:formatMessage(messages_default.notificationCloseButtonAriaLabel)})}catch(error){let errorMessage;if(error instanceof Error&&`status`in error){let{status}=error;errorMessage=formatMessage(status===409?messages_default.displayNameUsedBefore:messages_default.saveErrorNotification)}else errorMessage=formatMessage(messages_default.saveErrorNotification);addNotification({sensitivity:`foreground`,variant:`error`,styledText:errorMessage,typeIconAriaLabel:formatMessage(messages_default.notificationErrorIconAriaLabel),closeButtonAriaLabel:formatMessage(messages_default.notificationCloseButtonAriaLabel)});try{onSubmitError?.(error)}catch{}throw error}},children:jsx(MetadataTemplateEditorForm,{formId,onCancel:handleCancel,taxonomyOptions,fetchTaxonomies,hideActions,isEditMode,readOnly:isReadOnlyMode,onDirtyStateChange:handleDirtyStateChange,onValidationChange,fieldExtensions})}),isUnsavedChangesModalOpen&&jsx(ConfirmationModal,{onClose:()=>setIsUnsavedChangesModalOpen(!1),onConfirm:()=>{setIsUnsavedChangesModalOpen(!1),onCancel?.()},title:formatMessage(messages_default.unsavedChangesTitle),body:formatMessage(messages_default.unsavedChangesBody),confirmLabel:formatMessage(messages_default.unsavedChangesDiscard),cancelLabel:formatMessage(messages_default.unsavedChangesKeepEditing)})]})});export{MetadataTemplateEditor as t};
|
|
@@ -1,230 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useFieldConfigurator as t } from "../esm/lib/components/metadata-field-configurator/context/field-configurator-context.js";
|
|
3
|
-
import n from "../esm/lib/components/metadata-field-configurator/messages/dropdown-messages.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 { Trash as m } from "@box/blueprint-web-assets/icons/Line";
|
|
10
|
-
import h from "clsx";
|
|
11
|
-
import g from "lodash/uniqueId";
|
|
12
|
-
import { DndContext as _, DragOverlay as v, KeyboardSensor as y, PointerSensor as b, TouchSensor as x, closestCenter as S, useSensor as C, useSensors as w } from "@dnd-kit/core";
|
|
13
|
-
import { SortableContext as ee, arrayMove as T, sortableKeyboardCoordinates as te, useSortable as E, verticalListSortingStrategy as D } from "@dnd-kit/sortable";
|
|
14
|
-
import { CSS as O } from "@dnd-kit/utilities";
|
|
15
|
-
import '../styles/sortable-option-list.css';var k = {
|
|
16
|
-
sortableOptionList: "_sortableOptionList_dhce1_1",
|
|
17
|
-
option: "_option_dhce1_9",
|
|
18
|
-
editable: "_editable_dhce1_9",
|
|
19
|
-
dragging: "_dragging_dhce1_22",
|
|
20
|
-
dragHandle: "_dragHandle_dhce1_26",
|
|
21
|
-
input: "_input_dhce1_41",
|
|
22
|
-
deleteButtonContainer: "_deleteButtonContainer_dhce1_47",
|
|
23
|
-
optionDragOverlay: "_optionDragOverlay_dhce1_53"
|
|
24
|
-
};
|
|
25
|
-
function ne(e, t, n, r, i, a) {
|
|
26
|
-
let o = t?.dropdown?.options?.[n] && typeof e == "object" && !!e && typeof e.dropdown == "object" && e.dropdown?.options?.[n]?.key;
|
|
27
|
-
if (typeof o != "string") return "";
|
|
28
|
-
if (a !== null && r.id !== a) {
|
|
29
|
-
let e = i.find((e) => e.id === a)?.key;
|
|
30
|
-
if (e && r.key === e && i.some((t, r) => r !== n && t.key === e)) return "";
|
|
31
|
-
}
|
|
32
|
-
return o;
|
|
33
|
-
}
|
|
34
|
-
function re({ option: e, index: t, isFieldReadOnly: n, onInputChange: a, onDelete: o, onInputRef: u, error: d, handleBlur: f, canDelete: p, dragAriaLabel: g, inputPlaceholder: _, deleteAriaLabel: v }) {
|
|
35
|
-
let { attributes: y, listeners: b, setNodeRef: x, transform: S, transition: C, isDragging: w } = E({ id: e.id });
|
|
36
|
-
return /* @__PURE__ */ c("li", {
|
|
37
|
-
ref: x,
|
|
38
|
-
style: {
|
|
39
|
-
transform: O.Translate.toString(S),
|
|
40
|
-
transition: C
|
|
41
|
-
},
|
|
42
|
-
className: h(k.option, {
|
|
43
|
-
[k.dragging]: w,
|
|
44
|
-
[k.editable]: !n
|
|
45
|
-
}),
|
|
46
|
-
children: [
|
|
47
|
-
!n && /* @__PURE__ */ s("div", {
|
|
48
|
-
className: k.dragHandle,
|
|
49
|
-
...b,
|
|
50
|
-
...y,
|
|
51
|
-
"aria-label": g,
|
|
52
|
-
tabIndex: -1,
|
|
53
|
-
children: /* @__PURE__ */ s(l, {
|
|
54
|
-
fontSize: 20,
|
|
55
|
-
"aria-hidden": "true"
|
|
56
|
-
})
|
|
57
|
-
}),
|
|
58
|
-
/* @__PURE__ */ s(i, {
|
|
59
|
-
disabled: n,
|
|
60
|
-
placeholder: _,
|
|
61
|
-
label: _,
|
|
62
|
-
hideLabel: !0,
|
|
63
|
-
onBlur: f,
|
|
64
|
-
id: `dropdown.options.${t}.key`,
|
|
65
|
-
name: `dropdown.options.${t}.key`,
|
|
66
|
-
value: e.key,
|
|
67
|
-
className: k.input,
|
|
68
|
-
onChange: (t) => a(t, e.id),
|
|
69
|
-
ref: (e) => u(e, t),
|
|
70
|
-
error: d
|
|
71
|
-
}),
|
|
72
|
-
!n && /* @__PURE__ */ s("div", {
|
|
73
|
-
className: k.deleteButtonContainer,
|
|
74
|
-
children: /* @__PURE__ */ s(r, {
|
|
75
|
-
onClick: () => o(e),
|
|
76
|
-
"aria-label": v,
|
|
77
|
-
icon: m,
|
|
78
|
-
size: "x-small",
|
|
79
|
-
variant: "default",
|
|
80
|
-
tabIndex: -1,
|
|
81
|
-
focusable: !0,
|
|
82
|
-
disabled: !p,
|
|
83
|
-
className: k.deleteButton
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
]
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
function A({ shouldFocusLastOption: E = !1, onFocusConsumed: O }) {
|
|
90
|
-
let { formatMessage: A } = a(), { values: j, errors: ie, touched: M, setFieldValue: N, setFieldTouched: ae, setTouched: P, handleBlur: oe } = t(), F = w(C(b, { activationConstraint: { distance: 8 } }), C(x, { activationConstraint: {
|
|
91
|
-
delay: 250,
|
|
92
|
-
tolerance: 5
|
|
93
|
-
} }), C(y, { coordinateGetter: te })), { 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);
|
|
94
|
-
d(() => {
|
|
95
|
-
z(I);
|
|
96
|
-
}, [I]), d(() => () => {
|
|
97
|
-
H.current && clearTimeout(H.current);
|
|
98
|
-
}, []);
|
|
99
|
-
let Y = u((e) => {
|
|
100
|
-
N("dropdown", {
|
|
101
|
-
...j.dropdown,
|
|
102
|
-
options: e
|
|
103
|
-
});
|
|
104
|
-
}, [j.dropdown, N]), se = (e, t) => {
|
|
105
|
-
V(t);
|
|
106
|
-
let n = R.map((n, r) => n.id === t ? (ae(`dropdown.options.${r}.key`, !0), {
|
|
107
|
-
...n,
|
|
108
|
-
key: e.target.value
|
|
109
|
-
}) : n);
|
|
110
|
-
z(n), Y(n);
|
|
111
|
-
}, X = () => {
|
|
112
|
-
J(null), K(!1);
|
|
113
|
-
}, Z = (e) => {
|
|
114
|
-
if (!e) return;
|
|
115
|
-
let t = R.filter((t) => t.id !== e);
|
|
116
|
-
z(t), Y(t), e === B && V(null);
|
|
117
|
-
let n = { ...M }, r = n.dropdown;
|
|
118
|
-
r?.options && (r.options = r.options.filter((t, n) => R[n]?.id !== e)), P(n), t.length === 0 && N("dropdown", {
|
|
119
|
-
...j.dropdown,
|
|
120
|
-
options: [{
|
|
121
|
-
id: g(),
|
|
122
|
-
key: "",
|
|
123
|
-
isNew: !0
|
|
124
|
-
}]
|
|
125
|
-
}), X();
|
|
126
|
-
}, ce = (e) => {
|
|
127
|
-
e.isNew ? Z(e.id) : (J(e), K(!0));
|
|
128
|
-
}, le = ({ active: e }) => {
|
|
129
|
-
W(String(e.id));
|
|
130
|
-
}, ue = () => {
|
|
131
|
-
W(null);
|
|
132
|
-
}, Q = (e) => {
|
|
133
|
-
W(null);
|
|
134
|
-
let { active: t, over: n } = e;
|
|
135
|
-
if (n && t.id !== n.id) {
|
|
136
|
-
let e = R.findIndex((e) => e.id === t.id), r = R.findIndex((e) => e.id === n.id);
|
|
137
|
-
if (e !== -1 && r !== -1) {
|
|
138
|
-
let t = T(R, e, r);
|
|
139
|
-
z(t), Y(t);
|
|
140
|
-
let n = M?.dropdown?.options;
|
|
141
|
-
n && n.length > 0 && P({
|
|
142
|
-
...M,
|
|
143
|
-
dropdown: {
|
|
144
|
-
...M.dropdown ?? {},
|
|
145
|
-
options: T(n, e, r)
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}, de = u((e, t) => {
|
|
151
|
-
e && E && t === R.length - 1 && (H.current && clearTimeout(H.current), H.current = setTimeout(() => {
|
|
152
|
-
e.focus(), O(), H.current = null;
|
|
153
|
-
}, 0));
|
|
154
|
-
}, [
|
|
155
|
-
E,
|
|
156
|
-
O,
|
|
157
|
-
R.length
|
|
158
|
-
]), $ = U ? R.find((e) => e.id === U) : null;
|
|
159
|
-
return /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ c(_, {
|
|
160
|
-
sensors: F,
|
|
161
|
-
collisionDetection: S,
|
|
162
|
-
onDragStart: le,
|
|
163
|
-
onDragEnd: Q,
|
|
164
|
-
onDragCancel: ue,
|
|
165
|
-
children: [/* @__PURE__ */ s(ee, {
|
|
166
|
-
items: R.map((e) => e.id),
|
|
167
|
-
strategy: D,
|
|
168
|
-
children: /* @__PURE__ */ s("ul", {
|
|
169
|
-
className: k.sortableOptionList,
|
|
170
|
-
children: R.map((e, t) => /* @__PURE__ */ s(re, {
|
|
171
|
-
option: e,
|
|
172
|
-
index: t,
|
|
173
|
-
isFieldReadOnly: !!L,
|
|
174
|
-
onInputChange: se,
|
|
175
|
-
onDelete: ce,
|
|
176
|
-
onInputRef: de,
|
|
177
|
-
error: ne(ie, M, t, e, R, B),
|
|
178
|
-
handleBlur: oe,
|
|
179
|
-
canDelete: R.length >= 2,
|
|
180
|
-
dragAriaLabel: A(n.dragAndDropOptionAriaLabel),
|
|
181
|
-
inputPlaceholder: A(n.addAnOptionOptionPlaceholder),
|
|
182
|
-
deleteAriaLabel: A(n.deleteDropdownOptionAriaLabel)
|
|
183
|
-
}, e.id))
|
|
184
|
-
})
|
|
185
|
-
}), /* @__PURE__ */ s(v, {
|
|
186
|
-
dropAnimation: null,
|
|
187
|
-
children: $ ? /* @__PURE__ */ c("li", {
|
|
188
|
-
className: h(k.option, k.optionDragOverlay, { [k.editable]: !L }),
|
|
189
|
-
children: [
|
|
190
|
-
!L && /* @__PURE__ */ s("div", {
|
|
191
|
-
className: k.dragHandle,
|
|
192
|
-
children: /* @__PURE__ */ s(l, {
|
|
193
|
-
fontSize: 20,
|
|
194
|
-
"aria-hidden": "true"
|
|
195
|
-
})
|
|
196
|
-
}),
|
|
197
|
-
/* @__PURE__ */ s(i, {
|
|
198
|
-
disabled: L,
|
|
199
|
-
placeholder: A(n.addAnOptionOptionPlaceholder),
|
|
200
|
-
label: A(n.addAnOptionOptionPlaceholder),
|
|
201
|
-
hideLabel: !0,
|
|
202
|
-
id: "drag-overlay-option",
|
|
203
|
-
name: "drag-overlay-option",
|
|
204
|
-
value: $.key,
|
|
205
|
-
className: k.input
|
|
206
|
-
}),
|
|
207
|
-
!L && /* @__PURE__ */ s("div", {
|
|
208
|
-
className: k.deleteButtonContainer,
|
|
209
|
-
children: /* @__PURE__ */ s(r, {
|
|
210
|
-
icon: m,
|
|
211
|
-
size: "x-small",
|
|
212
|
-
variant: "default",
|
|
213
|
-
tabIndex: -1,
|
|
214
|
-
focusable: !0,
|
|
215
|
-
disabled: R.length < 2,
|
|
216
|
-
className: k.deleteButton,
|
|
217
|
-
"aria-label": ""
|
|
218
|
-
})
|
|
219
|
-
})
|
|
220
|
-
]
|
|
221
|
-
}) : null
|
|
222
|
-
})]
|
|
223
|
-
}), G && /* @__PURE__ */ s(e, {
|
|
224
|
-
onClose: X,
|
|
225
|
-
onConfirm: () => Z(q?.id ?? null),
|
|
226
|
-
title: A(n.deleteOptionTitle, { optionName: q?.key ?? "" }),
|
|
227
|
-
body: A(n.deleteOptionDescription)
|
|
228
|
-
})] });
|
|
229
|
-
}
|
|
230
|
-
export { A as t };
|
|
1
|
+
import ConfirmationModal from"../esm/lib/components/metadata-field-configurator/components/confirmation-modal/confirmation-modal.js";import{useFieldConfigurator}from"../esm/lib/components/metadata-field-configurator/context/field-configurator-context.js";import dropdown_messages_default from"../esm/lib/components/metadata-field-configurator/messages/dropdown-messages.js";import{IconButton,TextInput}from"@box/blueprint-web";import{useIntl}from"react-intl";import{Fragment,jsx,jsxs}from"react/jsx-runtime";import{DragDots}from"@box/blueprint-web-assets/icons/Fill";import{useCallback,useEffect,useRef,useState}from"react";import{Trash}from"@box/blueprint-web-assets/icons/Line";import clsx from"clsx";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/sortable-option-list.css';var sortable_option_list_module_default={sortableOptionList:`_sortableOptionList_dhce1_1`,option:`_option_dhce1_9`,editable:`_editable_dhce1_9`,dragging:`_dragging_dhce1_22`,dragHandle:`_dragHandle_dhce1_26`,input:`_input_dhce1_41`,deleteButtonContainer:`_deleteButtonContainer_dhce1_47`,optionDragOverlay:`_optionDragOverlay_dhce1_53`};function getOptionError(errors,touched,index,option,allOptions,lastChangedOptionId){let err=touched?.dropdown?.options?.[index]&&typeof errors==`object`&&!!errors&&typeof errors.dropdown==`object`&&errors.dropdown?.options?.[index]?.key;if(typeof err!=`string`)return``;if(lastChangedOptionId!==null&&option.id!==lastChangedOptionId){let lastChangedKey=allOptions.find(opt=>opt.id===lastChangedOptionId)?.key;if(lastChangedKey&&option.key===lastChangedKey&&allOptions.some((opt,i)=>i!==index&&opt.key===lastChangedKey))return``}return err}function SortableOptionItem({option,index,isFieldReadOnly,onInputChange,onDelete,onInputRef,error,handleBlur,canDelete,dragAriaLabel,inputPlaceholder,deleteAriaLabel}){let{attributes,listeners,setNodeRef,transform,transition,isDragging}=useSortable({id:option.id});return jsxs(`li`,{ref:setNodeRef,style:{transform:CSS.Translate.toString(transform),transition},className:clsx(sortable_option_list_module_default.option,{[sortable_option_list_module_default.dragging]:isDragging,[sortable_option_list_module_default.editable]:!isFieldReadOnly}),children:[!isFieldReadOnly&&jsx(`div`,{className:sortable_option_list_module_default.dragHandle,...listeners,...attributes,"aria-label":dragAriaLabel,tabIndex:-1,children:jsx(DragDots,{fontSize:20,"aria-hidden":`true`})}),jsx(TextInput,{disabled:isFieldReadOnly,placeholder:inputPlaceholder,label:inputPlaceholder,hideLabel:!0,onBlur:handleBlur,id:`dropdown.options.${index}.key`,name:`dropdown.options.${index}.key`,value:option.key,className:sortable_option_list_module_default.input,onChange:e=>onInputChange(e,option.id),ref:el=>onInputRef(el,index),error}),!isFieldReadOnly&&jsx(`div`,{className:sortable_option_list_module_default.deleteButtonContainer,children:jsx(IconButton,{onClick:()=>onDelete(option),"aria-label":deleteAriaLabel,icon:Trash,size:`x-small`,variant:`default`,tabIndex:-1,focusable:!0,disabled:!canDelete,className:sortable_option_list_module_default.deleteButton})})]})}function SortableOptionList({shouldFocusLastOption=!1,onFocusConsumed}){let{formatMessage}=useIntl(),{values,errors,touched,setFieldValue,setFieldTouched,setTouched,handleBlur}=useFieldConfigurator(),sensors=useSensors(useSensor(PointerSensor,{activationConstraint:{distance:8}}),useSensor(TouchSensor,{activationConstraint:{delay:250,tolerance:5}}),useSensor(KeyboardSensor,{coordinateGetter:sortableKeyboardCoordinates})),{options}=values.dropdown,{isFieldReadOnly}=values,[currentItems,setCurrentItems]=useState(options),[lastChangedOptionId,setLastChangedOptionId]=useState(null),focusTimeoutRef=useRef(null),[activeId,setActiveId]=useState(null),[isConfirmationModalOpen,setIsConfirmationModalOpen]=useState(!1),[optionToDelete,setOptionToDelete]=useState(null);useEffect(()=>{setCurrentItems(options)},[options]),useEffect(()=>()=>{focusTimeoutRef.current&&clearTimeout(focusTimeoutRef.current)},[]);let updateFormValue=useCallback(newItems=>{setFieldValue(`dropdown`,{...values.dropdown,options:newItems})},[values.dropdown,setFieldValue]),handleInputChange=(event,optionId)=>{setLastChangedOptionId(optionId);let updatedItems=currentItems.map((option,index)=>option.id===optionId?(setFieldTouched(`dropdown.options.${index}.key`,!0),{...option,key:event.target.value}):option);setCurrentItems(updatedItems),updateFormValue(updatedItems)},closeConfirmationModal=()=>{setOptionToDelete(null),setIsConfirmationModalOpen(!1)},handleDelete=optionId=>{if(!optionId)return;let updatedItems=currentItems.filter(option=>option.id!==optionId);setCurrentItems(updatedItems),updateFormValue(updatedItems),optionId===lastChangedOptionId&&setLastChangedOptionId(null);let updatedTouched={...touched},dropdownTouched=updatedTouched.dropdown;dropdownTouched?.options&&(dropdownTouched.options=dropdownTouched.options.filter((_,index)=>currentItems[index]?.id!==optionId)),setTouched(updatedTouched),updatedItems.length===0&&setFieldValue(`dropdown`,{...values.dropdown,options:[{id:uniqueId(),key:``,isNew:!0}]}),closeConfirmationModal()},openConfirmationModal=option=>{option.isNew?handleDelete(option.id):(setOptionToDelete(option),setIsConfirmationModalOpen(!0))},handleDragStart=({active})=>{setActiveId(String(active.id))},handleDragCancel=()=>{setActiveId(null)},handleDragEnd=event=>{setActiveId(null);let{active,over}=event;if(over&&active.id!==over.id){let oldIndex=currentItems.findIndex(item=>item.id===active.id),newIndex=currentItems.findIndex(item=>item.id===over.id);if(oldIndex!==-1&&newIndex!==-1){let newItems=arrayMove(currentItems,oldIndex,newIndex);setCurrentItems(newItems),updateFormValue(newItems);let touchedOptions=touched?.dropdown?.options;touchedOptions&&touchedOptions.length>0&&setTouched({...touched,dropdown:{...touched.dropdown??{},options:arrayMove(touchedOptions,oldIndex,newIndex)}})}}},handleInputRef=useCallback((inputElement,index)=>{inputElement&&shouldFocusLastOption&&index===currentItems.length-1&&(focusTimeoutRef.current&&clearTimeout(focusTimeoutRef.current),focusTimeoutRef.current=setTimeout(()=>{inputElement.focus(),onFocusConsumed(),focusTimeoutRef.current=null},0))},[shouldFocusLastOption,onFocusConsumed,currentItems.length]),activeOption=activeId?currentItems.find(item=>item.id===activeId):null;return jsxs(Fragment,{children:[jsxs(DndContext,{sensors,collisionDetection:closestCenter,onDragStart:handleDragStart,onDragEnd:handleDragEnd,onDragCancel:handleDragCancel,children:[jsx(SortableContext,{items:currentItems.map(item=>item.id),strategy:verticalListSortingStrategy,children:jsx(`ul`,{className:sortable_option_list_module_default.sortableOptionList,children:currentItems.map((option,index)=>jsx(SortableOptionItem,{option,index,isFieldReadOnly:!!isFieldReadOnly,onInputChange:handleInputChange,onDelete:openConfirmationModal,onInputRef:handleInputRef,error:getOptionError(errors,touched,index,option,currentItems,lastChangedOptionId),handleBlur,canDelete:currentItems.length>=2,dragAriaLabel:formatMessage(dropdown_messages_default.dragAndDropOptionAriaLabel),inputPlaceholder:formatMessage(dropdown_messages_default.addAnOptionOptionPlaceholder),deleteAriaLabel:formatMessage(dropdown_messages_default.deleteDropdownOptionAriaLabel)},option.id))})}),jsx(DragOverlay,{dropAnimation:null,children:activeOption?jsxs(`li`,{className:clsx(sortable_option_list_module_default.option,sortable_option_list_module_default.optionDragOverlay,{[sortable_option_list_module_default.editable]:!isFieldReadOnly}),children:[!isFieldReadOnly&&jsx(`div`,{className:sortable_option_list_module_default.dragHandle,children:jsx(DragDots,{fontSize:20,"aria-hidden":`true`})}),jsx(TextInput,{disabled:isFieldReadOnly,placeholder:formatMessage(dropdown_messages_default.addAnOptionOptionPlaceholder),label:formatMessage(dropdown_messages_default.addAnOptionOptionPlaceholder),hideLabel:!0,id:`drag-overlay-option`,name:`drag-overlay-option`,value:activeOption.key,className:sortable_option_list_module_default.input}),!isFieldReadOnly&&jsx(`div`,{className:sortable_option_list_module_default.deleteButtonContainer,children:jsx(IconButton,{icon:Trash,size:`x-small`,variant:`default`,tabIndex:-1,focusable:!0,disabled:currentItems.length<2,className:sortable_option_list_module_default.deleteButton,"aria-label":``})})]}):null})]}),isConfirmationModalOpen&&jsx(ConfirmationModal,{onClose:closeConfirmationModal,onConfirm:()=>handleDelete(optionToDelete?.id??null),title:formatMessage(dropdown_messages_default.deleteOptionTitle,{optionName:optionToDelete?.key??``}),body:formatMessage(dropdown_messages_default.deleteOptionDescription)})]})}export{SortableOptionList as t};
|
|
@@ -1,123 +1 @@
|
|
|
1
|
-
import {
|
|
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 = { taxonomyFieldConfiguration: "_taxonomyFieldConfiguration_1smhd_1" }, S = () => {
|
|
16
|
-
let { formatMessage: S } = m(), { values: C, errors: w, touched: T, setFieldValue: E } = t(), { onTaxonomySelect: D } = o({
|
|
17
|
-
values: C,
|
|
18
|
-
setFieldValue: E
|
|
19
|
-
}), { 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;
|
|
20
|
-
y(() => {
|
|
21
|
-
O.length > 0 && E("taxonomy", {
|
|
22
|
-
...C.taxonomy,
|
|
23
|
-
availableTaxonomies: O.map((e) => ({
|
|
24
|
-
...e,
|
|
25
|
-
selected: e.taxonomyKey === C.taxonomy.taxonomyKey
|
|
26
|
-
})),
|
|
27
|
-
selectedLevels: C.taxonomy.selectedLevels,
|
|
28
|
-
selection: C.taxonomy.selectedLevels.length > 1 ? e.AllowAny : e.RequireSpecific
|
|
29
|
-
});
|
|
30
|
-
}, [O]);
|
|
31
|
-
let N = (t) => {
|
|
32
|
-
let n = t === e.AllowAny ? j.map((e) => e.level) : [j[0].level];
|
|
33
|
-
E("taxonomy", {
|
|
34
|
-
...C.taxonomy,
|
|
35
|
-
selection: t,
|
|
36
|
-
selectedLevels: n
|
|
37
|
-
});
|
|
38
|
-
}, P = k?.label ?? S(r.chooseTaxonomyLevel), F = !!w.taxonomy?.taxonomyKey && !!T.taxonomy?.taxonomyKey;
|
|
39
|
-
if (!k && C.isFieldNew) return /* @__PURE__ */ _(h, { children: [F && /* @__PURE__ */ g(u, {
|
|
40
|
-
variant: "error",
|
|
41
|
-
variantIconAriaLabel: S(r.noTaxonomySelectedError),
|
|
42
|
-
children: S(r.noTaxonomySelectedError)
|
|
43
|
-
}), /* @__PURE__ */ g(a, {})] });
|
|
44
|
-
let I = C.isFieldReadOnly || !C.isFieldNew;
|
|
45
|
-
return /* @__PURE__ */ _("div", {
|
|
46
|
-
className: x.taxonomyFieldConfiguration,
|
|
47
|
-
children: [
|
|
48
|
-
/* @__PURE__ */ g(f.Item, {
|
|
49
|
-
name: "allowMultipleSelections",
|
|
50
|
-
disabled: I,
|
|
51
|
-
checked: C.taxonomy.allowMultipleSelections,
|
|
52
|
-
label: S(r.allowMultipleTaxonomySelections),
|
|
53
|
-
onCheckedChange: (e) => {
|
|
54
|
-
E("taxonomy", {
|
|
55
|
-
...C.taxonomy,
|
|
56
|
-
allowMultipleSelections: e
|
|
57
|
-
});
|
|
58
|
-
},
|
|
59
|
-
value: C.taxonomy.allowMultipleSelections.toString()
|
|
60
|
-
}),
|
|
61
|
-
/* @__PURE__ */ g("div", { children: /* @__PURE__ */ g(c, {
|
|
62
|
-
triggerButton: /* @__PURE__ */ g(p, {
|
|
63
|
-
disabled: I,
|
|
64
|
-
icon: v,
|
|
65
|
-
children: P
|
|
66
|
-
}),
|
|
67
|
-
data: s(C.taxonomy.availableTaxonomies, C.taxonomy.taxonomySearchValue),
|
|
68
|
-
onClick: D,
|
|
69
|
-
onSearchValue: (e) => {
|
|
70
|
-
E("taxonomy", {
|
|
71
|
-
...C.taxonomy,
|
|
72
|
-
taxonomySearchValue: e
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}) }),
|
|
76
|
-
j.length > 0 && /* @__PURE__ */ g(i, {
|
|
77
|
-
levels: j,
|
|
78
|
-
selectedLevels: A
|
|
79
|
-
}),
|
|
80
|
-
k && j.length > 1 && /* @__PURE__ */ g(d.Legend, {
|
|
81
|
-
header: S(r.selection),
|
|
82
|
-
children: /* @__PURE__ */ _(d.Group, {
|
|
83
|
-
disabled: I,
|
|
84
|
-
defaultValue: e.RequireSpecific,
|
|
85
|
-
loop: !0,
|
|
86
|
-
name: "selection",
|
|
87
|
-
onValueChange: N,
|
|
88
|
-
orientation: "vertical",
|
|
89
|
-
value: C.taxonomy.selection,
|
|
90
|
-
children: [/* @__PURE__ */ g(d.Item, {
|
|
91
|
-
label: /* @__PURE__ */ _(h, { children: [S(r.requiredSelection), /* @__PURE__ */ _(l.Root, {
|
|
92
|
-
modal: !1,
|
|
93
|
-
children: [/* @__PURE__ */ g(l.Trigger, {
|
|
94
|
-
disabled: C.taxonomy.selection !== e.RequireSpecific || I,
|
|
95
|
-
children: /* @__PURE__ */ g(p, {
|
|
96
|
-
icon: v,
|
|
97
|
-
children: M ?? S(r.chooseTaxonomyLevel)
|
|
98
|
-
})
|
|
99
|
-
}), /* @__PURE__ */ g(l.Content, {
|
|
100
|
-
align: "start",
|
|
101
|
-
children: k?.levels?.map((e) => /* @__PURE__ */ g(l.Item, {
|
|
102
|
-
onClick: () => {
|
|
103
|
-
E("taxonomy", {
|
|
104
|
-
...C.taxonomy,
|
|
105
|
-
selectedLevels: [e.level]
|
|
106
|
-
});
|
|
107
|
-
},
|
|
108
|
-
children: e.name
|
|
109
|
-
}, e.level))
|
|
110
|
-
})]
|
|
111
|
-
})] }),
|
|
112
|
-
value: e.RequireSpecific
|
|
113
|
-
}), /* @__PURE__ */ g(d.Item, {
|
|
114
|
-
disabled: I,
|
|
115
|
-
label: S(r.anyLevelSelection),
|
|
116
|
-
value: e.AllowAny
|
|
117
|
-
})]
|
|
118
|
-
})
|
|
119
|
-
})
|
|
120
|
-
]
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
export { S as t };
|
|
1
|
+
import{c as TaxonomySelection}from"./types.js";import{useFieldConfigurator}from"../esm/lib/components/metadata-field-configurator/context/field-configurator-context.js";import{useTaxonomyOptions}from"../esm/lib/components/metadata-field-configurator/context/taxonomy-options-context.js";import taxonomy_messages_default from"../esm/lib/components/metadata-field-configurator/messages/taxonomy-messages.js";import{t as LevelsChain}from"./levels-chain.js";import{t as TaxonomyFieldConfiguratorInitialState}from"./taxonomy-field-configurator-initial-state.js";import{useTaxonomySelect}from"../esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/useTaxonomySelect.js";import{filterTaxonomiesByValue}from"../esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/utils.js";import{t as TaxonomySelector}from"./taxonomy-selector.js";import{DropdownMenu,InlineNotice,Radio,Switch,TextButton}from"@box/blueprint-web";import{useIntl}from"react-intl";import{Fragment,jsx,jsxs}from"react/jsx-runtime";import{Caret}from"@box/blueprint-web-assets/icons/Fill";import{useEffect,useMemo}from"react";import '../styles/taxonomy-field-configuration.css';var taxonomy_field_configuration_module_default={taxonomyFieldConfiguration:`_taxonomyFieldConfiguration_1smhd_1`},TaxonomyFieldConfiguration=()=>{let{formatMessage}=useIntl(),{values,errors,touched,setFieldValue}=useFieldConfigurator(),{onTaxonomySelect}=useTaxonomySelect({values,setFieldValue}),{options:taxonomyOptionsFromContext}=useTaxonomyOptions(),selectedTaxonomy=values.taxonomy.availableTaxonomies.find(taxonomy=>taxonomy.selected),{selectedLevels}=values.taxonomy,selectableLevels=useMemo(()=>selectedTaxonomy?selectedTaxonomy.levels:[],[selectedTaxonomy]),selectedLevelName=values.taxonomy.selection===TaxonomySelection.RequireSpecific&&selectedLevels.length>0?selectableLevels[selectedLevels[0]-1]?.name:void 0;useEffect(()=>{taxonomyOptionsFromContext.length>0&&setFieldValue(`taxonomy`,{...values.taxonomy,availableTaxonomies:taxonomyOptionsFromContext.map(taxonomy=>({...taxonomy,selected:taxonomy.taxonomyKey===values.taxonomy.taxonomyKey})),selectedLevels:values.taxonomy.selectedLevels,selection:values.taxonomy.selectedLevels.length>1?TaxonomySelection.AllowAny:TaxonomySelection.RequireSpecific})},[taxonomyOptionsFromContext]);let handleSelectionChange=value=>{let newSelectedLevels=value===TaxonomySelection.AllowAny?selectableLevels.map(l=>l.level):[selectableLevels[0].level];setFieldValue(`taxonomy`,{...values.taxonomy,selection:value,selectedLevels:newSelectedLevels})},taxonomySelectorLabel=selectedTaxonomy?.label??formatMessage(taxonomy_messages_default.chooseTaxonomyLevel),hasTaxonomyError=!!errors.taxonomy?.taxonomyKey&&!!touched.taxonomy?.taxonomyKey;if(!selectedTaxonomy&&values.isFieldNew)return jsxs(Fragment,{children:[hasTaxonomyError&&jsx(InlineNotice,{variant:`error`,variantIconAriaLabel:formatMessage(taxonomy_messages_default.noTaxonomySelectedError),children:formatMessage(taxonomy_messages_default.noTaxonomySelectedError)}),jsx(TaxonomyFieldConfiguratorInitialState,{})]});let isDisabled=values.isFieldReadOnly||!values.isFieldNew;return jsxs(`div`,{className:taxonomy_field_configuration_module_default.taxonomyFieldConfiguration,children:[jsx(Switch.Item,{name:`allowMultipleSelections`,disabled:isDisabled,checked:values.taxonomy.allowMultipleSelections,label:formatMessage(taxonomy_messages_default.allowMultipleTaxonomySelections),onCheckedChange:checked=>{setFieldValue(`taxonomy`,{...values.taxonomy,allowMultipleSelections:checked})},value:values.taxonomy.allowMultipleSelections.toString()}),jsx(`div`,{children:jsx(TaxonomySelector,{triggerButton:jsx(TextButton,{disabled:isDisabled,icon:Caret,children:taxonomySelectorLabel}),data:filterTaxonomiesByValue(values.taxonomy.availableTaxonomies,values.taxonomy.taxonomySearchValue),onClick:onTaxonomySelect,onSearchValue:value=>{setFieldValue(`taxonomy`,{...values.taxonomy,taxonomySearchValue:value})}})}),selectableLevels.length>0&&jsx(LevelsChain,{levels:selectableLevels,selectedLevels}),selectedTaxonomy&&selectableLevels.length>1&&jsx(Radio.Legend,{header:formatMessage(taxonomy_messages_default.selection),children:jsxs(Radio.Group,{disabled:isDisabled,defaultValue:TaxonomySelection.RequireSpecific,loop:!0,name:`selection`,onValueChange:handleSelectionChange,orientation:`vertical`,value:values.taxonomy.selection,children:[jsx(Radio.Item,{label:jsxs(Fragment,{children:[formatMessage(taxonomy_messages_default.requiredSelection),jsxs(DropdownMenu.Root,{modal:!1,children:[jsx(DropdownMenu.Trigger,{disabled:values.taxonomy.selection!==TaxonomySelection.RequireSpecific||isDisabled,children:jsx(TextButton,{icon:Caret,children:selectedLevelName??formatMessage(taxonomy_messages_default.chooseTaxonomyLevel)})}),jsx(DropdownMenu.Content,{align:`start`,children:selectedTaxonomy?.levels?.map(entry=>jsx(DropdownMenu.Item,{onClick:()=>{setFieldValue(`taxonomy`,{...values.taxonomy,selectedLevels:[entry.level]})},children:entry.name},entry.level))})]})]}),value:TaxonomySelection.RequireSpecific}),jsx(Radio.Item,{disabled:isDisabled,label:formatMessage(taxonomy_messages_default.anyLevelSelection),value:TaxonomySelection.AllowAny})]})})]})};export{TaxonomyFieldConfiguration as t};
|
|
@@ -1,49 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useFieldConfigurator as t } from "../esm/lib/components/metadata-field-configurator/context/field-configurator-context.js";
|
|
3
|
-
import n from "../esm/lib/components/metadata-field-configurator/messages/taxonomy-messages.js";
|
|
4
|
-
import { useTaxonomySelect as r } from "../esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/useTaxonomySelect.js";
|
|
5
|
-
import { filterTaxonomiesByValue as i } from "../esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/utils.js";
|
|
6
|
-
import { t as a } from "./taxonomy-selector.js";
|
|
7
|
-
import { Text as o } from "@box/blueprint-web";
|
|
8
|
-
import { FormattedMessage as s } from "react-intl";
|
|
9
|
-
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
10
|
-
import "react";
|
|
11
|
-
import '../styles/taxonomy-field-configurator-initial-state.css';var u = {
|
|
12
|
-
taxonomyFieldConfiguratorInitialState: "_taxonomyFieldConfiguratorInitialState_il5v7_1",
|
|
13
|
-
subheader: "_subheader_il5v7_10"
|
|
14
|
-
}, d = () => {
|
|
15
|
-
let { values: d, setFieldValue: f } = t(), { onTaxonomySelect: p } = r({
|
|
16
|
-
values: d,
|
|
17
|
-
setFieldValue: f
|
|
18
|
-
}), { taxonomyInitialStateLabels: m } = e();
|
|
19
|
-
return /* @__PURE__ */ l("div", {
|
|
20
|
-
className: u.taxonomyFieldConfiguratorInitialState,
|
|
21
|
-
children: [
|
|
22
|
-
/* @__PURE__ */ c(o, {
|
|
23
|
-
as: "h1",
|
|
24
|
-
color: "textOnLightDefault",
|
|
25
|
-
variant: "titleMedium",
|
|
26
|
-
children: m?.header ?? /* @__PURE__ */ c(s, { ...n.callToActionHeader })
|
|
27
|
-
}),
|
|
28
|
-
/* @__PURE__ */ c(o, {
|
|
29
|
-
as: "p",
|
|
30
|
-
className: u.subheader,
|
|
31
|
-
color: "textOnLightDefault",
|
|
32
|
-
variant: "bodyDefault",
|
|
33
|
-
children: m?.subheader ?? /* @__PURE__ */ c(s, { ...n.callToActionSubheader })
|
|
34
|
-
}),
|
|
35
|
-
/* @__PURE__ */ c(a, {
|
|
36
|
-
data: i(d.taxonomy.availableTaxonomies, d.taxonomy.taxonomySearchValue),
|
|
37
|
-
onClick: p,
|
|
38
|
-
resetValueOnHide: !0,
|
|
39
|
-
onSearchValue: (e) => {
|
|
40
|
-
f("taxonomy", {
|
|
41
|
-
...d.taxonomy,
|
|
42
|
-
taxonomySearchValue: e
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
]
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
export { d as t };
|
|
1
|
+
import{useEditorConfig}from"../esm/lib/components/metadata-field-configurator/context/editor-config-context.js";import{useFieldConfigurator}from"../esm/lib/components/metadata-field-configurator/context/field-configurator-context.js";import taxonomy_messages_default from"../esm/lib/components/metadata-field-configurator/messages/taxonomy-messages.js";import{useTaxonomySelect}from"../esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/useTaxonomySelect.js";import{filterTaxonomiesByValue}from"../esm/lib/components/metadata-field-configurator/components/type-specific-configuration/taxonomy/utils.js";import{t as TaxonomySelector}from"./taxonomy-selector.js";import{Text}from"@box/blueprint-web";import{FormattedMessage}from"react-intl";import{jsx,jsxs}from"react/jsx-runtime";import"react";import '../styles/taxonomy-field-configurator-initial-state.css';var taxonomy_field_configurator_initial_state_module_default={taxonomyFieldConfiguratorInitialState:`_taxonomyFieldConfiguratorInitialState_il5v7_1`,subheader:`_subheader_il5v7_10`},TaxonomyFieldConfiguratorInitialState=()=>{let{values,setFieldValue}=useFieldConfigurator(),{onTaxonomySelect}=useTaxonomySelect({values,setFieldValue}),{taxonomyInitialStateLabels}=useEditorConfig();return jsxs(`div`,{className:taxonomy_field_configurator_initial_state_module_default.taxonomyFieldConfiguratorInitialState,children:[jsx(Text,{as:`h1`,color:`textOnLightDefault`,variant:`titleMedium`,children:taxonomyInitialStateLabels?.header??jsx(FormattedMessage,{...taxonomy_messages_default.callToActionHeader})}),jsx(Text,{as:`p`,className:taxonomy_field_configurator_initial_state_module_default.subheader,color:`textOnLightDefault`,variant:`bodyDefault`,children:taxonomyInitialStateLabels?.subheader??jsx(FormattedMessage,{...taxonomy_messages_default.callToActionSubheader})}),jsx(TaxonomySelector,{data:filterTaxonomiesByValue(values.taxonomy.availableTaxonomies,values.taxonomy.taxonomySearchValue),onClick:onTaxonomySelect,resetValueOnHide:!0,onSearchValue:value=>{setFieldValue(`taxonomy`,{...values.taxonomy,taxonomySearchValue:value})}})]})};export{TaxonomyFieldConfiguratorInitialState as t};
|