@firecms/core 3.0.0-canary.203 → 3.0.0-canary.205
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/form/EntityForm.d.ts +3 -12
- package/dist/index.es.js +205 -485
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +205 -485
- package/dist/index.umd.js.map +1 -1
- package/dist/internal/useBuildSideEntityController.d.ts +2 -2
- package/dist/util/resolutions.d.ts +6 -1
- package/package.json +5 -5
- package/src/core/EntityEditView.tsx +17 -69
- package/src/core/EntitySidePanel.tsx +2 -2
- package/src/form/EntityForm.tsx +138 -165
- package/src/internal/useBuildSideEntityController.tsx +28 -14
- package/src/util/resolutions.ts +26 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef } from "react";
|
|
2
2
|
import {
|
|
3
|
+
CustomizationController,
|
|
3
4
|
EntityCollection,
|
|
4
5
|
EntitySidePanelProps,
|
|
5
6
|
NavigationController,
|
|
@@ -10,17 +11,28 @@ import {
|
|
|
10
11
|
} from "../types";
|
|
11
12
|
import { getNavigationEntriesFromPath, NavigationViewInternal } from "../util/navigation_from_path";
|
|
12
13
|
import { useLocation } from "react-router-dom";
|
|
13
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
removeInitialAndTrailingSlashes,
|
|
16
|
+
resolveCollection,
|
|
17
|
+
resolveDefaultSelectedView,
|
|
18
|
+
resolvedSelectedEntityView
|
|
19
|
+
} from "../util";
|
|
14
20
|
import { ADDITIONAL_TAB_WIDTH, CONTAINER_FULL_WIDTH, FORM_CONTAINER_WIDTH } from "./common";
|
|
15
|
-
import { useLargeLayout } from "../hooks";
|
|
21
|
+
import { useCustomizationController, useLargeLayout } from "../hooks";
|
|
16
22
|
import { EntitySidePanel } from "../core/EntitySidePanel";
|
|
17
23
|
|
|
18
24
|
const NEW_URL_HASH = "new_side";
|
|
19
25
|
const SIDE_URL_HASH = "side";
|
|
20
26
|
|
|
21
|
-
export function getEntityViewWidth(props: EntitySidePanelProps<any>, small: boolean): string {
|
|
27
|
+
export function getEntityViewWidth(props: EntitySidePanelProps<any>, small: boolean, customizationController: CustomizationController): string {
|
|
22
28
|
if (small) return CONTAINER_FULL_WIDTH;
|
|
23
|
-
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
selectedSecondaryForm
|
|
32
|
+
} = resolvedSelectedEntityView(props.collection?.entityViews, customizationController, props.selectedTab);
|
|
33
|
+
|
|
34
|
+
const shouldUseSmallLayout = !props.selectedTab || Boolean(selectedSecondaryForm);
|
|
35
|
+
|
|
24
36
|
let resolvedWidth: string | undefined;
|
|
25
37
|
if (props.width) {
|
|
26
38
|
resolvedWidth = typeof props.width === "number" ? `${props.width}px` : props.width;
|
|
@@ -28,7 +40,7 @@ export function getEntityViewWidth(props: EntitySidePanelProps<any>, small: bool
|
|
|
28
40
|
resolvedWidth = typeof props.collection.sideDialogWidth === "number" ? `${props.collection.sideDialogWidth}px` : props.collection.sideDialogWidth;
|
|
29
41
|
}
|
|
30
42
|
|
|
31
|
-
if (!
|
|
43
|
+
if (!shouldUseSmallLayout) {
|
|
32
44
|
return `calc(${ADDITIONAL_TAB_WIDTH} + ${resolvedWidth ?? FORM_CONTAINER_WIDTH})`
|
|
33
45
|
} else {
|
|
34
46
|
if (resolvedWidth) {
|
|
@@ -89,6 +101,7 @@ export const useBuildSideEntityController = (navigation: NavigationController,
|
|
|
89
101
|
|
|
90
102
|
const location = useLocation();
|
|
91
103
|
const initialised = useRef<boolean>(false);
|
|
104
|
+
const customizationController = useCustomizationController();
|
|
92
105
|
|
|
93
106
|
const smallLayout = !useLargeLayout();
|
|
94
107
|
|
|
@@ -105,9 +118,9 @@ export const useBuildSideEntityController = (navigation: NavigationController,
|
|
|
105
118
|
for (let i = 0; i < panelsFromUrl.length; i++) {
|
|
106
119
|
const props = panelsFromUrl[i];
|
|
107
120
|
if (i === 0)
|
|
108
|
-
sideDialogsController.replace(propsToSidePanel(props, navigation.buildUrlCollectionPath, navigation.resolveIdsFrom, smallLayout));
|
|
121
|
+
sideDialogsController.replace(propsToSidePanel(props, navigation.buildUrlCollectionPath, navigation.resolveIdsFrom, smallLayout, customizationController));
|
|
109
122
|
else
|
|
110
|
-
sideDialogsController.open(propsToSidePanel(props, navigation.buildUrlCollectionPath, navigation.resolveIdsFrom, smallLayout))
|
|
123
|
+
sideDialogsController.open(propsToSidePanel(props, navigation.buildUrlCollectionPath, navigation.resolveIdsFrom, smallLayout, customizationController))
|
|
111
124
|
}
|
|
112
125
|
}
|
|
113
126
|
initialised.current = true;
|
|
@@ -127,7 +140,7 @@ export const useBuildSideEntityController = (navigation: NavigationController,
|
|
|
127
140
|
return;
|
|
128
141
|
}
|
|
129
142
|
const lastPanel = panelsFromUrl[panelsFromUrl.length - 1];
|
|
130
|
-
const panelProps = propsToSidePanel(lastPanel, navigation.buildUrlCollectionPath, navigation.resolveIdsFrom, smallLayout);
|
|
143
|
+
const panelProps = propsToSidePanel(lastPanel, navigation.buildUrlCollectionPath, navigation.resolveIdsFrom, smallLayout, customizationController);
|
|
131
144
|
const lastCurrentPanel = currentPanelKeys.length > 0 ? currentPanelKeys[currentPanelKeys.length - 1] : undefined;
|
|
132
145
|
if (!lastCurrentPanel || lastCurrentPanel !== panelProps.key) {
|
|
133
146
|
sideDialogsController.replace(panelProps);
|
|
@@ -140,7 +153,7 @@ export const useBuildSideEntityController = (navigation: NavigationController,
|
|
|
140
153
|
useEffect(() => {
|
|
141
154
|
const updatedSidePanels = sideDialogsController.sidePanels.map(sidePanelProps => {
|
|
142
155
|
if (sidePanelProps.additional) {
|
|
143
|
-
return propsToSidePanel(sidePanelProps.additional, navigation.buildUrlCollectionPath, navigation.resolveIdsFrom, smallLayout);
|
|
156
|
+
return propsToSidePanel(sidePanelProps.additional, navigation.buildUrlCollectionPath, navigation.resolveIdsFrom, smallLayout, customizationController);
|
|
144
157
|
}
|
|
145
158
|
return sidePanelProps;
|
|
146
159
|
});
|
|
@@ -172,7 +185,8 @@ export const useBuildSideEntityController = (navigation: NavigationController,
|
|
|
172
185
|
},
|
|
173
186
|
navigation.buildUrlCollectionPath,
|
|
174
187
|
navigation.resolveIdsFrom,
|
|
175
|
-
smallLayout
|
|
188
|
+
smallLayout,
|
|
189
|
+
customizationController
|
|
176
190
|
));
|
|
177
191
|
|
|
178
192
|
}, [sideDialogsController, navigation.buildUrlCollectionPath, navigation.resolveIdsFrom, smallLayout]);
|
|
@@ -183,7 +197,7 @@ export const useBuildSideEntityController = (navigation: NavigationController,
|
|
|
183
197
|
throw Error("If you want to copy an entity you need to provide an entityId");
|
|
184
198
|
}
|
|
185
199
|
|
|
186
|
-
sideDialogsController.replace(propsToSidePanel(props, navigation.buildUrlCollectionPath, navigation.resolveIdsFrom, smallLayout));
|
|
200
|
+
sideDialogsController.replace(propsToSidePanel(props, navigation.buildUrlCollectionPath, navigation.resolveIdsFrom, smallLayout, customizationController));
|
|
187
201
|
|
|
188
202
|
}, [navigation.buildUrlCollectionPath, navigation.resolveIdsFrom, sideDialogsController, smallLayout]);
|
|
189
203
|
|
|
@@ -242,11 +256,11 @@ export function buildSidePanelsFromUrl(path: string, collections: EntityCollecti
|
|
|
242
256
|
return sidePanel ? [sidePanel] : [];
|
|
243
257
|
}
|
|
244
258
|
|
|
245
|
-
|
|
246
259
|
const propsToSidePanel = (props: EntitySidePanelProps,
|
|
247
260
|
buildUrlCollectionPath: (path: string) => string,
|
|
248
261
|
resolveIdsFrom: (pathWithAliases: string) => string,
|
|
249
|
-
smallLayout: boolean
|
|
262
|
+
smallLayout: boolean,
|
|
263
|
+
customizationController: CustomizationController): SideDialogPanelProps => {
|
|
250
264
|
|
|
251
265
|
const collectionPath = removeInitialAndTrailingSlashes(props.path);
|
|
252
266
|
|
|
@@ -261,7 +275,7 @@ const propsToSidePanel = (props: EntitySidePanelProps,
|
|
|
261
275
|
formProps: props.formProps
|
|
262
276
|
};
|
|
263
277
|
|
|
264
|
-
const entityViewWidth = getEntityViewWidth(props, smallLayout);
|
|
278
|
+
const entityViewWidth = getEntityViewWidth(props, smallLayout, customizationController);
|
|
265
279
|
|
|
266
280
|
return {
|
|
267
281
|
key: `${props.path}/${props.entityId}`,
|
package/src/util/resolutions.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ArrayProperty,
|
|
3
3
|
CMSType,
|
|
4
|
+
CustomizationController,
|
|
4
5
|
EntityCollection,
|
|
5
6
|
EntityCustomView,
|
|
6
7
|
EntityValues,
|
|
@@ -218,11 +219,11 @@ export function resolveProperty<T extends CMSType = CMSType, M extends Record<st
|
|
|
218
219
|
}
|
|
219
220
|
|
|
220
221
|
export function getArrayResolvedProperties<M>({
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
222
|
+
propertyKey,
|
|
223
|
+
propertyValue,
|
|
224
|
+
property,
|
|
225
|
+
...props
|
|
226
|
+
}: {
|
|
226
227
|
propertyValue: any,
|
|
227
228
|
propertyKey?: string,
|
|
228
229
|
property: ArrayProperty<any> | ResolvedArrayProperty<any>,
|
|
@@ -430,3 +431,23 @@ export function resolveEntityView(entityView: string | EntityCustomView<any>, co
|
|
|
430
431
|
return entityView;
|
|
431
432
|
}
|
|
432
433
|
}
|
|
434
|
+
|
|
435
|
+
export function resolvedSelectedEntityView<M extends Record<string, any>>(
|
|
436
|
+
customViews: (string | EntityCustomView<M>)[] | undefined,
|
|
437
|
+
customizationController: CustomizationController,
|
|
438
|
+
selectedTab?: string
|
|
439
|
+
) {
|
|
440
|
+
const resolvedEntityViews = customViews ? customViews
|
|
441
|
+
.map(e => resolveEntityView(e, customizationController.entityViews))
|
|
442
|
+
.filter(Boolean) as EntityCustomView[]
|
|
443
|
+
: [];
|
|
444
|
+
|
|
445
|
+
const selectedEntityView = resolvedEntityViews.find(e => e.key === selectedTab);
|
|
446
|
+
const selectedSecondaryForm = customViews
|
|
447
|
+
&& resolvedEntityViews.filter(e => e.includeActions).find(e => e.key === selectedTab);
|
|
448
|
+
return {
|
|
449
|
+
resolvedEntityViews,
|
|
450
|
+
selectedEntityView,
|
|
451
|
+
selectedSecondaryForm
|
|
452
|
+
};
|
|
453
|
+
}
|