@firecms/core 3.0.0-canary.215 → 3.0.0-canary.217
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/core/EntityEditView.d.ts +2 -1
- package/dist/index.es.js +166 -143
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +166 -143
- package/dist/index.umd.js.map +1 -1
- package/dist/types/fields.d.ts +3 -1
- package/dist/types/properties.d.ts +6 -0
- package/dist/util/createFormexStub.d.ts +2 -0
- package/dist/util/objects.d.ts +1 -1
- package/dist/util/resolutions.d.ts +4 -4
- package/package.json +5 -5
- package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +1 -1
- package/src/components/EntityJsonPreview.tsx +3 -3
- package/src/core/EntityEditView.tsx +106 -60
- package/src/form/EntityForm.tsx +5 -3
- package/src/hooks/useBuildNavigationController.tsx +1 -1
- package/src/routes/FireCMSRoute.tsx +1 -1
- package/src/types/fields.tsx +3 -1
- package/src/types/properties.ts +7 -0
- package/src/util/createFormexStub.tsx +62 -0
- package/src/util/join_collections.ts +3 -1
- package/src/util/objects.ts +5 -1
- package/src/util/resolutions.ts +4 -2
- package/src/util/useStorageUploadController.tsx +17 -0
|
@@ -37,10 +37,11 @@ export interface EntityEditViewProps<M extends Record<string, any>> {
|
|
|
37
37
|
* an entity is opened.
|
|
38
38
|
*/
|
|
39
39
|
export declare function EntityEditView<M extends Record<string, any>, USER extends User>({ entityId, ...props }: EntityEditViewProps<M>): import("react/jsx-runtime").JSX.Element;
|
|
40
|
-
export declare function EntityEditViewInner<M extends Record<string, any>>({ path, entityId, selectedTab: selectedTabProp, collection, parentCollectionIds, onValuesModified, onSaved, onTabChange, entity, cachedDirtyValues, dataLoading, layout, barActions, status, setStatus, formProps }: EntityEditViewProps<M> & {
|
|
40
|
+
export declare function EntityEditViewInner<M extends Record<string, any>>({ path, entityId, selectedTab: selectedTabProp, collection, parentCollectionIds, onValuesModified, onSaved, onTabChange, entity, cachedDirtyValues, dataLoading, layout, barActions, status, setStatus, formProps, canEdit }: EntityEditViewProps<M> & {
|
|
41
41
|
entity?: Entity<M>;
|
|
42
42
|
cachedDirtyValues?: Partial<M>;
|
|
43
43
|
dataLoading: boolean;
|
|
44
44
|
status: EntityStatus;
|
|
45
45
|
setStatus: (status: EntityStatus) => void;
|
|
46
|
+
canEdit?: boolean;
|
|
46
47
|
}): import("react/jsx-runtime").JSX.Element;
|
package/dist/index.es.js
CHANGED
|
@@ -205,7 +205,7 @@ const pick = (obj, ...args) => ({
|
|
|
205
205
|
function isObject(item) {
|
|
206
206
|
return item && typeof item === "object" && !Array.isArray(item);
|
|
207
207
|
}
|
|
208
|
-
function mergeDeep(target, source) {
|
|
208
|
+
function mergeDeep(target, source, ignoreUndefined = false) {
|
|
209
209
|
const targetIsObject = isObject(target);
|
|
210
210
|
const output = targetIsObject ? {
|
|
211
211
|
...target
|
|
@@ -213,6 +213,9 @@ function mergeDeep(target, source) {
|
|
|
213
213
|
if (targetIsObject && isObject(source)) {
|
|
214
214
|
Object.keys(source).forEach((key) => {
|
|
215
215
|
const sourceElement = source[key];
|
|
216
|
+
if (ignoreUndefined && sourceElement === void 0) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
216
219
|
if (sourceElement instanceof Date) {
|
|
217
220
|
Object.assign(output, {
|
|
218
221
|
[key]: new Date(sourceElement.getTime())
|
|
@@ -855,8 +858,8 @@ function resolveEntityView(entityView, contextEntityViews) {
|
|
|
855
858
|
return entityView;
|
|
856
859
|
}
|
|
857
860
|
}
|
|
858
|
-
function resolvedSelectedEntityView(customViews, customizationController, selectedTab) {
|
|
859
|
-
const resolvedEntityViews = customViews ? customViews.map((e) => resolveEntityView(e, customizationController.entityViews)).filter(Boolean) : [];
|
|
861
|
+
function resolvedSelectedEntityView(customViews, customizationController, selectedTab, canEdit) {
|
|
862
|
+
const resolvedEntityViews = customViews ? customViews.map((e) => resolveEntityView(e, customizationController.entityViews)).filter((e) => Boolean(e)).filter((e) => canEdit || !e.includeActions) : [];
|
|
860
863
|
const selectedEntityView = resolvedEntityViews.find((e) => e.key === selectedTab);
|
|
861
864
|
const selectedSecondaryForm = customViews && resolvedEntityViews.filter((e) => e.includeActions).find((e) => e.key === selectedTab);
|
|
862
865
|
return {
|
|
@@ -3498,7 +3501,7 @@ function mergeCollection(target, source, parentPaths = [], modifyCollection) {
|
|
|
3498
3501
|
if (property) propertiesMerged[key] = mergePropertyOrBuilder(property, source.properties[key]);
|
|
3499
3502
|
else propertiesMerged[key] = source.properties[key];
|
|
3500
3503
|
});
|
|
3501
|
-
const mergedCollection = mergeDeep(target, source);
|
|
3504
|
+
const mergedCollection = mergeDeep(target, source, true);
|
|
3502
3505
|
const targetPropertiesOrder = getCollectionKeys(target);
|
|
3503
3506
|
const sourcePropertiesOrder = getCollectionKeys(source);
|
|
3504
3507
|
const mergedPropertiesOrder = [.../* @__PURE__ */ new Set([...sourcePropertiesOrder, ...targetPropertiesOrder])];
|
|
@@ -7443,6 +7446,7 @@ function useStorageUploadController({
|
|
|
7443
7446
|
const storage = property.dataType === "string" ? property.storage : property.dataType === "array" && property.of.dataType === "string" ? property.of.storage : void 0;
|
|
7444
7447
|
const multipleFilesSupported = property.dataType === "array";
|
|
7445
7448
|
if (!storage) throw Error("Storage meta must be specified");
|
|
7449
|
+
const processFile = storage?.processFile;
|
|
7446
7450
|
const metadata = storage?.metadata;
|
|
7447
7451
|
const size = multipleFilesSupported ? "medium" : "large";
|
|
7448
7452
|
const compression = storage?.imageCompression;
|
|
@@ -7519,29 +7523,42 @@ function useStorageUploadController({
|
|
|
7519
7523
|
}, [internalValue, multipleFilesSupported, onChange, storage, storageSource]);
|
|
7520
7524
|
const onFilesAdded = useCallback(async (acceptedFiles) => {
|
|
7521
7525
|
if (!acceptedFiles.length || disabled) return;
|
|
7526
|
+
if (processFile) {
|
|
7527
|
+
try {
|
|
7528
|
+
acceptedFiles = await Promise.all(acceptedFiles.map(async (file_1) => {
|
|
7529
|
+
const processedFile = await processFile(file_1);
|
|
7530
|
+
if (!processedFile) {
|
|
7531
|
+
return file_1;
|
|
7532
|
+
}
|
|
7533
|
+
return processedFile;
|
|
7534
|
+
}));
|
|
7535
|
+
} catch (e_1) {
|
|
7536
|
+
console.error("Error processing file with custom code. Attempting to continue uploading.", e_1);
|
|
7537
|
+
}
|
|
7538
|
+
}
|
|
7522
7539
|
let newInternalValue;
|
|
7523
7540
|
if (multipleFilesSupported) {
|
|
7524
|
-
newInternalValue = [...internalValue, ...await Promise.all(acceptedFiles.map(async (
|
|
7525
|
-
if (compression && compressionFormat(
|
|
7526
|
-
|
|
7541
|
+
newInternalValue = [...internalValue, ...await Promise.all(acceptedFiles.map(async (file_2) => {
|
|
7542
|
+
if (compression && compressionFormat(file_2)) {
|
|
7543
|
+
file_2 = await resizeAndCompressImage(file_2, compression);
|
|
7527
7544
|
}
|
|
7528
7545
|
return {
|
|
7529
7546
|
id: getRandomId$2(),
|
|
7530
|
-
file:
|
|
7531
|
-
fileName: await fileNameBuilder(
|
|
7547
|
+
file: file_2,
|
|
7548
|
+
fileName: await fileNameBuilder(file_2),
|
|
7532
7549
|
metadata,
|
|
7533
7550
|
size
|
|
7534
7551
|
};
|
|
7535
7552
|
}))];
|
|
7536
7553
|
} else {
|
|
7537
|
-
let
|
|
7538
|
-
if (compression && compressionFormat(
|
|
7539
|
-
|
|
7554
|
+
let file_3 = acceptedFiles[0];
|
|
7555
|
+
if (compression && compressionFormat(file_3)) {
|
|
7556
|
+
file_3 = await resizeAndCompressImage(file_3, compression);
|
|
7540
7557
|
}
|
|
7541
7558
|
newInternalValue = [{
|
|
7542
7559
|
id: getRandomId$2(),
|
|
7543
|
-
file:
|
|
7544
|
-
fileName: await fileNameBuilder(
|
|
7560
|
+
file: file_3,
|
|
7561
|
+
fileName: await fileNameBuilder(file_3),
|
|
7545
7562
|
metadata,
|
|
7546
7563
|
size
|
|
7547
7564
|
}];
|
|
@@ -9386,7 +9403,7 @@ const EntityCollectionRowActions = function EntityCollectionRowActions2({
|
|
|
9386
9403
|
] }, index_0)) }),
|
|
9387
9404
|
selectionEnabled && /* @__PURE__ */ jsx(Tooltip, { title: `Select ${entity.id}`, children: /* @__PURE__ */ jsx(Checkbox, { size: largeLayout ? "medium" : "small", checked: Boolean(isSelected), onCheckedChange }) })
|
|
9388
9405
|
] }),
|
|
9389
|
-
!hideId && size !== "xs" && /* @__PURE__ */ jsxs("div", { className: "w-[138px] overflow-hidden truncate font-mono text-xs text-text-secondary dark:text-text-secondary-dark max-w-full text-ellipsis px-2 align-center flex items-center gap-1", onClick: (event_1) => {
|
|
9406
|
+
!hideId && size !== "xs" && /* @__PURE__ */ jsxs("div", { className: "w-[138px] overflow-hidden truncate font-mono text-xs text-text-secondary dark:text-text-secondary-dark max-w-full text-ellipsis px-2 align-center justify-center flex items-center gap-1", onClick: (event_1) => {
|
|
9390
9407
|
event_1.stopPropagation();
|
|
9391
9408
|
}, children: [
|
|
9392
9409
|
hasDraft && /* @__PURE__ */ jsx(Tooltip, { title: "Local unsaved changes", className: "inline", children: /* @__PURE__ */ jsx(Chip, { colorScheme: "orangeDarker", className: "p-0.5", children: /* @__PURE__ */ jsx(EditIcon, { size: 12 }) }) }),
|
|
@@ -14310,11 +14327,11 @@ function EntityForm({
|
|
|
14310
14327
|
throw Error("INTERNAL: Collection and path must be defined in form context");
|
|
14311
14328
|
}
|
|
14312
14329
|
const dialogActions = /* @__PURE__ */ jsx(EntityFormActionsComponent, { collection: resolvedCollection, path, entity, layout: forceActionsAtTheBottom ? "bottom" : "side", savingError, formex, disabled: disabled_0, status, pluginActions, openEntityMode, showDefaultActions });
|
|
14313
|
-
return /* @__PURE__ */ jsx(Formex, { value:
|
|
14330
|
+
return /* @__PURE__ */ jsx(Formex, { value: formex, children: /* @__PURE__ */ jsxs("form", { onSubmit: formex.handleSubmit, onReset: () => formex.resetForm({
|
|
14314
14331
|
values: getInitialEntityValues(authController, collection, path, status, entity, customizationController.propertyConfigs)
|
|
14315
14332
|
}), noValidate: true, className: cls("flex-1 flex flex-row w-full overflow-y-auto justify-center", className), children: [
|
|
14316
14333
|
/* @__PURE__ */ jsx("div", { id: `form_${path}`, className: cls("relative flex flex-row max-w-4xl lg:max-w-3xl xl:max-w-4xl 2xl:max-w-6xl w-full h-fit"), children: /* @__PURE__ */ jsxs("div", { className: cls("flex flex-col w-full pt-12 pb-16 px-4 sm:px-8 md:px-10"), children: [
|
|
14317
|
-
|
|
14334
|
+
formex.dirty ? /* @__PURE__ */ jsx(Tooltip, { title: "Local unsaved changes", className: "self-end sticky top-4 z-10", children: /* @__PURE__ */ jsx(Chip, { size: "small", colorScheme: "orangeDarker", children: /* @__PURE__ */ jsx(EditIcon, { size: "smallest" }) }) }) : /* @__PURE__ */ jsx(Tooltip, { title: "In sync with the database", className: "self-end sticky top-4 z-10", children: /* @__PURE__ */ jsx(Chip, { size: "small", children: /* @__PURE__ */ jsx(CheckIcon, { size: "smallest" }) }) }),
|
|
14318
14335
|
formView
|
|
14319
14336
|
] }) }),
|
|
14320
14337
|
dialogActions
|
|
@@ -21097,7 +21114,7 @@ function EntityJsonPreview(t0) {
|
|
|
21097
21114
|
t4 = $[4];
|
|
21098
21115
|
}
|
|
21099
21116
|
useEffect(t3, t4);
|
|
21100
|
-
const t5 = mode === "dark" ? themes.vsDark : themes.
|
|
21117
|
+
const t5 = mode === "dark" ? themes.vsDark : themes.github;
|
|
21101
21118
|
let t6;
|
|
21102
21119
|
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
|
|
21103
21120
|
t6 = (t72) => {
|
|
@@ -21109,8 +21126,8 @@ function EntityJsonPreview(t0) {
|
|
|
21109
21126
|
} = t72;
|
|
21110
21127
|
return /* @__PURE__ */ jsx("pre", { ref: preRef, style: {
|
|
21111
21128
|
...style,
|
|
21112
|
-
|
|
21113
|
-
}, className: "
|
|
21129
|
+
backgroundColor: "inherit"
|
|
21130
|
+
}, className: "max-w-6xl mx-auto p-8 rounded text-sm", children: tokens.map((line, i) => /* @__PURE__ */ jsx("div", { ...getLineProps({
|
|
21114
21131
|
line
|
|
21115
21132
|
}), className: "text-wrap", children: line.map((token, key) => /* @__PURE__ */ jsx("span", { ...getTokenProps({
|
|
21116
21133
|
token
|
|
@@ -21131,128 +21148,100 @@ function EntityJsonPreview(t0) {
|
|
|
21131
21148
|
}
|
|
21132
21149
|
return t7;
|
|
21133
21150
|
}
|
|
21151
|
+
function createFormexStub(values) {
|
|
21152
|
+
const errorMessage = "You are in a read-only context. You cannot modify the formex controller.";
|
|
21153
|
+
return {
|
|
21154
|
+
values,
|
|
21155
|
+
initialValues: values,
|
|
21156
|
+
touched: {},
|
|
21157
|
+
dirty: false,
|
|
21158
|
+
errors: {},
|
|
21159
|
+
submitCount: 0,
|
|
21160
|
+
isSubmitting: false,
|
|
21161
|
+
isValidating: false,
|
|
21162
|
+
version: 0,
|
|
21163
|
+
canUndo: false,
|
|
21164
|
+
canRedo: false,
|
|
21165
|
+
setValues: () => {
|
|
21166
|
+
throw new Error(errorMessage);
|
|
21167
|
+
},
|
|
21168
|
+
setFieldValue: () => {
|
|
21169
|
+
throw new Error(errorMessage);
|
|
21170
|
+
},
|
|
21171
|
+
setFieldTouched: () => {
|
|
21172
|
+
throw new Error(errorMessage);
|
|
21173
|
+
},
|
|
21174
|
+
setDirty: () => {
|
|
21175
|
+
throw new Error(errorMessage);
|
|
21176
|
+
},
|
|
21177
|
+
setSubmitCount: () => {
|
|
21178
|
+
throw new Error(errorMessage);
|
|
21179
|
+
},
|
|
21180
|
+
setFieldError: () => {
|
|
21181
|
+
throw new Error(errorMessage);
|
|
21182
|
+
},
|
|
21183
|
+
handleChange: () => {
|
|
21184
|
+
throw new Error(errorMessage);
|
|
21185
|
+
},
|
|
21186
|
+
handleBlur: () => {
|
|
21187
|
+
throw new Error(errorMessage);
|
|
21188
|
+
},
|
|
21189
|
+
handleSubmit: () => {
|
|
21190
|
+
throw new Error(errorMessage);
|
|
21191
|
+
},
|
|
21192
|
+
validate: () => {
|
|
21193
|
+
throw new Error(errorMessage);
|
|
21194
|
+
},
|
|
21195
|
+
resetForm: () => {
|
|
21196
|
+
throw new Error(errorMessage);
|
|
21197
|
+
},
|
|
21198
|
+
setSubmitting: () => {
|
|
21199
|
+
throw new Error(errorMessage);
|
|
21200
|
+
},
|
|
21201
|
+
undo: () => {
|
|
21202
|
+
throw new Error(errorMessage);
|
|
21203
|
+
},
|
|
21204
|
+
redo: () => {
|
|
21205
|
+
throw new Error(errorMessage);
|
|
21206
|
+
}
|
|
21207
|
+
};
|
|
21208
|
+
}
|
|
21134
21209
|
const MAIN_TAB_VALUE = "__main_##Q$SC^#S6";
|
|
21135
21210
|
const JSON_TAB_VALUE = "__json";
|
|
21136
|
-
function EntityEditView(
|
|
21137
|
-
|
|
21138
|
-
|
|
21139
|
-
|
|
21140
|
-
if ($[0] !== t0) {
|
|
21141
|
-
({
|
|
21142
|
-
entityId,
|
|
21143
|
-
...props
|
|
21144
|
-
} = t0);
|
|
21145
|
-
$[0] = t0;
|
|
21146
|
-
$[1] = entityId;
|
|
21147
|
-
$[2] = props;
|
|
21148
|
-
} else {
|
|
21149
|
-
entityId = $[1];
|
|
21150
|
-
props = $[2];
|
|
21151
|
-
}
|
|
21152
|
-
let t1;
|
|
21153
|
-
if ($[3] !== entityId || $[4] !== props.collection || $[5] !== props.databaseId || $[6] !== props.path) {
|
|
21154
|
-
t1 = {
|
|
21155
|
-
path: props.path,
|
|
21156
|
-
entityId,
|
|
21157
|
-
collection: props.collection,
|
|
21158
|
-
databaseId: props.databaseId,
|
|
21159
|
-
useCache: false
|
|
21160
|
-
};
|
|
21161
|
-
$[3] = entityId;
|
|
21162
|
-
$[4] = props.collection;
|
|
21163
|
-
$[5] = props.databaseId;
|
|
21164
|
-
$[6] = props.path;
|
|
21165
|
-
$[7] = t1;
|
|
21166
|
-
} else {
|
|
21167
|
-
t1 = $[7];
|
|
21168
|
-
}
|
|
21211
|
+
function EntityEditView({
|
|
21212
|
+
entityId,
|
|
21213
|
+
...props
|
|
21214
|
+
}) {
|
|
21169
21215
|
const {
|
|
21170
21216
|
entity,
|
|
21171
|
-
dataLoading
|
|
21172
|
-
|
|
21173
|
-
|
|
21174
|
-
|
|
21175
|
-
|
|
21176
|
-
|
|
21177
|
-
|
|
21178
|
-
|
|
21179
|
-
|
|
21180
|
-
|
|
21181
|
-
|
|
21182
|
-
const cachedValues = t2;
|
|
21217
|
+
dataLoading,
|
|
21218
|
+
// eslint-disable-next-line no-unused-vars
|
|
21219
|
+
dataLoadingError
|
|
21220
|
+
} = useEntityFetch({
|
|
21221
|
+
path: props.path,
|
|
21222
|
+
entityId,
|
|
21223
|
+
collection: props.collection,
|
|
21224
|
+
databaseId: props.databaseId,
|
|
21225
|
+
useCache: false
|
|
21226
|
+
});
|
|
21227
|
+
const cachedValues = entityId ? getEntityFromCache(props.path + "/" + entityId) : getEntityFromCache(props.path + "#new");
|
|
21183
21228
|
const authController = useAuthController();
|
|
21184
21229
|
const initialStatus = props.copy ? "copy" : entityId ? "existing" : "new";
|
|
21185
21230
|
const [status, setStatus] = useState(initialStatus);
|
|
21186
|
-
|
|
21187
|
-
|
|
21188
|
-
|
|
21189
|
-
} else {
|
|
21190
|
-
t3 = entity ? canEditEntity(props.collection, authController, props.path, entity ?? null) : void 0;
|
|
21191
|
-
}
|
|
21192
|
-
const canEdit = t3;
|
|
21193
|
-
if (dataLoading && !cachedValues || (!entity || canEdit === void 0) && (status === "existing" || status === "copy")) {
|
|
21194
|
-
let t42;
|
|
21195
|
-
if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
|
|
21196
|
-
t42 = /* @__PURE__ */ jsx(CircularProgressCenter, {});
|
|
21197
|
-
$[11] = t42;
|
|
21231
|
+
const canEdit = useMemo(() => {
|
|
21232
|
+
if (status === "new" || status === "copy") {
|
|
21233
|
+
return true;
|
|
21198
21234
|
} else {
|
|
21199
|
-
|
|
21235
|
+
return entity ? canEditEntity(props.collection, authController, props.path, entity ?? null) : void 0;
|
|
21200
21236
|
}
|
|
21201
|
-
|
|
21237
|
+
}, [authController, entity, status]);
|
|
21238
|
+
if (dataLoading && !cachedValues || (!entity || canEdit === void 0) && (status === "existing" || status === "copy")) {
|
|
21239
|
+
return /* @__PURE__ */ jsx(CircularProgressCenter, {});
|
|
21202
21240
|
}
|
|
21203
21241
|
if (entityId && !entity && !cachedValues) {
|
|
21204
21242
|
console.error(`Entity with id ${entityId} not found in collection ${props.path}`);
|
|
21205
21243
|
}
|
|
21206
|
-
|
|
21207
|
-
const t42 = props.collection.singularName ?? props.collection.name;
|
|
21208
|
-
let t52;
|
|
21209
|
-
if ($[12] !== t42) {
|
|
21210
|
-
t52 = /* @__PURE__ */ jsx(Typography, { className: "mt-16 mb-8 mx-8", variant: "h4", children: t42 });
|
|
21211
|
-
$[12] = t42;
|
|
21212
|
-
$[13] = t52;
|
|
21213
|
-
} else {
|
|
21214
|
-
t52 = $[13];
|
|
21215
|
-
}
|
|
21216
|
-
const t6 = entity;
|
|
21217
|
-
let t7;
|
|
21218
|
-
if ($[14] !== props.collection || $[15] !== props.path || $[16] !== t6) {
|
|
21219
|
-
t7 = /* @__PURE__ */ jsx(EntityView, { className: "px-8", entity: t6, path: props.path, collection: props.collection });
|
|
21220
|
-
$[14] = props.collection;
|
|
21221
|
-
$[15] = props.path;
|
|
21222
|
-
$[16] = t6;
|
|
21223
|
-
$[17] = t7;
|
|
21224
|
-
} else {
|
|
21225
|
-
t7 = $[17];
|
|
21226
|
-
}
|
|
21227
|
-
let t8;
|
|
21228
|
-
if ($[18] !== t52 || $[19] !== t7) {
|
|
21229
|
-
t8 = /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
21230
|
-
t52,
|
|
21231
|
-
t7
|
|
21232
|
-
] });
|
|
21233
|
-
$[18] = t52;
|
|
21234
|
-
$[19] = t7;
|
|
21235
|
-
$[20] = t8;
|
|
21236
|
-
} else {
|
|
21237
|
-
t8 = $[20];
|
|
21238
|
-
}
|
|
21239
|
-
return t8;
|
|
21240
|
-
}
|
|
21241
|
-
const t4 = cachedValues;
|
|
21242
|
-
let t5;
|
|
21243
|
-
if ($[21] !== dataLoading || $[22] !== entity || $[23] !== entityId || $[24] !== props || $[25] !== status || $[26] !== t4) {
|
|
21244
|
-
t5 = /* @__PURE__ */ jsx(EntityEditViewInner, { ...props, entityId, entity, cachedDirtyValues: t4, dataLoading, status, setStatus });
|
|
21245
|
-
$[21] = dataLoading;
|
|
21246
|
-
$[22] = entity;
|
|
21247
|
-
$[23] = entityId;
|
|
21248
|
-
$[24] = props;
|
|
21249
|
-
$[25] = status;
|
|
21250
|
-
$[26] = t4;
|
|
21251
|
-
$[27] = t5;
|
|
21252
|
-
} else {
|
|
21253
|
-
t5 = $[27];
|
|
21254
|
-
}
|
|
21255
|
-
return t5;
|
|
21244
|
+
return /* @__PURE__ */ jsx(EntityEditViewInner, { ...props, entityId, entity, cachedDirtyValues: cachedValues, dataLoading, status, setStatus, canEdit });
|
|
21256
21245
|
}
|
|
21257
21246
|
function EntityEditViewInner({
|
|
21258
21247
|
path,
|
|
@@ -21270,7 +21259,8 @@ function EntityEditViewInner({
|
|
|
21270
21259
|
barActions,
|
|
21271
21260
|
status,
|
|
21272
21261
|
setStatus,
|
|
21273
|
-
formProps
|
|
21262
|
+
formProps,
|
|
21263
|
+
canEdit
|
|
21274
21264
|
}) {
|
|
21275
21265
|
const context = useFireCMSContext();
|
|
21276
21266
|
const [usedEntity, setUsedEntity] = useState(entity);
|
|
@@ -21286,8 +21276,8 @@ function EntityEditViewInner({
|
|
|
21286
21276
|
}), []);
|
|
21287
21277
|
const [selectedTab, setSelectedTab] = useState(selectedTabProp ?? defaultSelectedView ?? MAIN_TAB_VALUE);
|
|
21288
21278
|
useEffect(() => {
|
|
21289
|
-
if ((selectedTabProp ?? MAIN_TAB_VALUE) !== selectedTab) {
|
|
21290
|
-
setSelectedTab(selectedTabProp ?? MAIN_TAB_VALUE);
|
|
21279
|
+
if ((selectedTabProp ?? defaultSelectedView ?? MAIN_TAB_VALUE) !== selectedTab) {
|
|
21280
|
+
setSelectedTab(selectedTabProp ?? defaultSelectedView ?? MAIN_TAB_VALUE);
|
|
21291
21281
|
}
|
|
21292
21282
|
}, [selectedTabProp]);
|
|
21293
21283
|
const subcollections = (collection.subcollections ?? []).filter((c2) => !c2.hideFromNavigation);
|
|
@@ -21300,24 +21290,55 @@ function EntityEditViewInner({
|
|
|
21300
21290
|
resolvedEntityViews,
|
|
21301
21291
|
selectedEntityView,
|
|
21302
21292
|
selectedSecondaryForm
|
|
21303
|
-
} = resolvedSelectedEntityView(customViews, customizationController, selectedTab);
|
|
21293
|
+
} = resolvedSelectedEntityView(customViews, customizationController, selectedTab, canEdit);
|
|
21304
21294
|
const actionsAtTheBottom = !largeLayout || layout === "side_panel" || selectedEntityView?.includeActions === "bottom";
|
|
21305
21295
|
const mainViewVisible = selectedTab === MAIN_TAB_VALUE || Boolean(selectedSecondaryForm);
|
|
21296
|
+
const authController = useAuthController();
|
|
21306
21297
|
const customViewsView = customViews && resolvedEntityViews.filter((e) => !e.includeActions).map((customView) => {
|
|
21307
21298
|
if (!customView) return null;
|
|
21308
21299
|
const Builder = customView.Builder;
|
|
21309
21300
|
if (!Builder) {
|
|
21310
|
-
console.error("customView.Builder is not defined");
|
|
21301
|
+
console.error("INTERNAL: customView.Builder is not defined");
|
|
21302
|
+
return null;
|
|
21303
|
+
}
|
|
21304
|
+
if (!entityId) {
|
|
21305
|
+
console.error("INTERNAL: entityId is not defined");
|
|
21311
21306
|
return null;
|
|
21312
21307
|
}
|
|
21308
|
+
const formexStub = createFormexStub(usedEntity?.values ?? {});
|
|
21309
|
+
const usedFormContext = formContext ?? {
|
|
21310
|
+
entityId,
|
|
21311
|
+
openEntityMode: layout,
|
|
21312
|
+
status,
|
|
21313
|
+
values: usedEntity?.values ?? {},
|
|
21314
|
+
setFieldValue: (key, value) => {
|
|
21315
|
+
throw new Error("You can't update values in read only mode");
|
|
21316
|
+
},
|
|
21317
|
+
save: () => {
|
|
21318
|
+
throw new Error("You can't save in read only mode");
|
|
21319
|
+
},
|
|
21320
|
+
collection: resolveCollection({
|
|
21321
|
+
collection,
|
|
21322
|
+
path,
|
|
21323
|
+
entityId,
|
|
21324
|
+
values: usedEntity?.values ?? {},
|
|
21325
|
+
previousValues: usedEntity?.values ?? {},
|
|
21326
|
+
propertyConfigs: customizationController.propertyConfigs,
|
|
21327
|
+
authController
|
|
21328
|
+
}),
|
|
21329
|
+
path,
|
|
21330
|
+
entity: usedEntity,
|
|
21331
|
+
savingError: void 0,
|
|
21332
|
+
formex: formexStub
|
|
21333
|
+
};
|
|
21313
21334
|
return /* @__PURE__ */ jsx("div", { className: cls(defaultBorderMixin, "relative flex-1 w-full h-full overflow-auto", {
|
|
21314
21335
|
"hidden": selectedTab !== customView.key
|
|
21315
|
-
}), role: "tabpanel", children: /* @__PURE__ */ jsx(ErrorBoundary, { children:
|
|
21336
|
+
}), role: "tabpanel", children: /* @__PURE__ */ jsx(ErrorBoundary, { children: usedFormContext && /* @__PURE__ */ jsx(Builder, { collection, entity: usedEntity, modifiedValues: usedFormContext?.formex?.values ?? usedEntity?.values, formContext: usedFormContext }) }) }, `custom_view_${customView.key}`);
|
|
21316
21337
|
}).filter(Boolean);
|
|
21317
21338
|
const globalLoading = dataLoading && !usedEntity;
|
|
21318
21339
|
const jsonView = /* @__PURE__ */ jsx("div", { className: cls("relative flex-1 h-full overflow-auto w-full", {
|
|
21319
21340
|
"hidden": selectedTab !== JSON_TAB_VALUE
|
|
21320
|
-
}), role: "tabpanel", children: /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(EntityJsonPreview, { values: formContext?.values ?? {} }) }) }, "json_view");
|
|
21341
|
+
}), role: "tabpanel", children: /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(EntityJsonPreview, { values: formContext?.values ?? entity?.values ?? {} }) }) }, "json_view");
|
|
21321
21342
|
const subCollectionsViews = subcollections && subcollections.map((subcollection) => {
|
|
21322
21343
|
const subcollectionId = subcollection.id ?? subcollection.path;
|
|
21323
21344
|
const fullPath = usedEntity ? `${path}/${usedEntity?.id}/${removeInitialAndTrailingSlashes(subcollectionId)}` : void 0;
|
|
@@ -21327,18 +21348,21 @@ function EntityEditViewInner({
|
|
|
21327
21348
|
!globalLoading && (usedEntity && fullPath ? /* @__PURE__ */ jsx(EntityCollectionView, { fullPath, parentCollectionIds: [...parentCollectionIds, collection.id], isSubCollection: true, updateUrl: false, ...subcollection, openEntityMode: layout }) : /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center w-full h-full p-3", children: /* @__PURE__ */ jsx(Typography, { variant: "label", children: "You need to save your entity before adding additional collections" }) }))
|
|
21328
21349
|
] }, `subcol_${subcollectionId}`);
|
|
21329
21350
|
}).filter(Boolean);
|
|
21330
|
-
const onSideTabClick = (
|
|
21331
|
-
setSelectedTab(
|
|
21351
|
+
const onSideTabClick = (value_0) => {
|
|
21352
|
+
setSelectedTab(value_0);
|
|
21332
21353
|
if (status === "existing") {
|
|
21333
21354
|
onTabChange?.({
|
|
21334
21355
|
path,
|
|
21335
21356
|
entityId,
|
|
21336
|
-
selectedTab:
|
|
21357
|
+
selectedTab: value_0 === MAIN_TAB_VALUE ? void 0 : value_0,
|
|
21337
21358
|
collection
|
|
21338
21359
|
});
|
|
21339
21360
|
}
|
|
21340
21361
|
};
|
|
21341
|
-
const entityView = /* @__PURE__ */ jsx(
|
|
21362
|
+
const entityView = !canEdit ? /* @__PURE__ */ jsx("div", { className: cls("flex-1 flex flex-row w-full overflow-y-auto justify-center", !mainViewVisible ? "hidden" : ""), children: /* @__PURE__ */ jsxs("div", { className: cls("relative flex flex-col max-w-4xl lg:max-w-3xl xl:max-w-4xl 2xl:max-w-6xl w-full h-fit"), children: [
|
|
21363
|
+
/* @__PURE__ */ jsx(Typography, { className: "mt-16 mb-8 mx-8", variant: "h4", children: collection.singularName ?? collection.name }),
|
|
21364
|
+
/* @__PURE__ */ jsx(EntityView, { className: "px-8 h-full overflow-auto", entity, path, collection })
|
|
21365
|
+
] }) }) : /* @__PURE__ */ jsx(EntityForm, { collection, path, entityId: entityId ?? usedEntity?.id, onValuesModified, entity, initialDirtyValues: cachedDirtyValues, openEntityMode: layout, forceActionsAtTheBottom: actionsAtTheBottom, initialStatus: status, className: cls(!mainViewVisible ? "hidden" : "", formProps?.className), EntityFormActionsComponent: EntityEditViewFormActions, ...formProps, onEntityChange: (entity_0) => {
|
|
21342
21366
|
setUsedEntity(entity_0);
|
|
21343
21367
|
formProps?.onEntityChange?.(entity_0);
|
|
21344
21368
|
}, onStatusChange: (status_0) => {
|
|
@@ -21362,8 +21386,8 @@ function EntityEditViewInner({
|
|
|
21362
21386
|
barActions,
|
|
21363
21387
|
/* @__PURE__ */ jsx("div", { className: "flex-grow" }),
|
|
21364
21388
|
globalLoading && /* @__PURE__ */ jsx("div", { className: "self-center", children: /* @__PURE__ */ jsx(CircularProgress, { size: "small" }) }),
|
|
21365
|
-
/* @__PURE__ */ jsxs(Tabs, { value: selectedTab, onValueChange: (
|
|
21366
|
-
onSideTabClick(
|
|
21389
|
+
/* @__PURE__ */ jsxs(Tabs, { value: selectedTab, onValueChange: (value_1) => {
|
|
21390
|
+
onSideTabClick(value_1);
|
|
21367
21391
|
}, children: [
|
|
21368
21392
|
/* @__PURE__ */ jsx(Tab, { disabled: !hasAdditionalViews, value: JSON_TAB_VALUE, innerClassName: "block", className: "text-sm", children: /* @__PURE__ */ jsx(CodeIcon, { size: "small" }) }),
|
|
21369
21393
|
/* @__PURE__ */ jsx(Tab, { disabled: !hasAdditionalViews, value: MAIN_TAB_VALUE, className: "text-sm min-w-[120px]", children: collection.singularName ?? collection.name }),
|
|
@@ -23238,7 +23262,6 @@ function EntityFullScreenRoute({
|
|
|
23238
23262
|
return blocked.current;
|
|
23239
23263
|
});
|
|
23240
23264
|
} catch (e) {
|
|
23241
|
-
console.warn("Blocker not available, navigation will not be blocked");
|
|
23242
23265
|
}
|
|
23243
23266
|
const lastCollectionEntry = navigationEntries.findLast((entry_1) => entry_1.type === "collection");
|
|
23244
23267
|
if (isNew && !lastCollectionEntry) {
|