@strapi/content-manager 0.0.0-experimental.e0df4d50334a17a1beb3d203bff414fbbff62f7b → 0.0.0-experimental.e12978dcee698470990e9c5c63384faf2c307443
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/admin/chunks/{ComponentConfigurationPage-C5H-5L1u.js → ComponentConfigurationPage-Ci3dN40b.js} +5 -6
- package/dist/admin/chunks/{ComponentConfigurationPage-C5H-5L1u.js.map → ComponentConfigurationPage-Ci3dN40b.js.map} +1 -1
- package/dist/admin/chunks/{ComponentConfigurationPage-BN2kOtDm.mjs → ComponentConfigurationPage-DFPdl9pm.mjs} +5 -6
- package/dist/admin/chunks/{ComponentConfigurationPage-BN2kOtDm.mjs.map → ComponentConfigurationPage-DFPdl9pm.mjs.map} +1 -1
- package/dist/admin/chunks/{EditConfigurationPage-BExtZuB7.js → EditConfigurationPage-7xe8u-Pp.js} +5 -6
- package/dist/admin/chunks/{EditConfigurationPage-BExtZuB7.js.map → EditConfigurationPage-7xe8u-Pp.js.map} +1 -1
- package/dist/admin/chunks/{EditConfigurationPage-tMgOELQG.mjs → EditConfigurationPage-BFse-urJ.mjs} +5 -6
- package/dist/admin/chunks/{EditConfigurationPage-tMgOELQG.mjs.map → EditConfigurationPage-BFse-urJ.mjs.map} +1 -1
- package/dist/admin/chunks/{EditViewPage-CYe7wAXF.mjs → EditViewPage-BNpRr7fZ.mjs} +99 -98
- package/dist/admin/chunks/EditViewPage-BNpRr7fZ.mjs.map +1 -0
- package/dist/admin/chunks/{EditViewPage-DFkloeMZ.js → EditViewPage-CwYSs8Cq.js} +99 -98
- package/dist/admin/chunks/EditViewPage-CwYSs8Cq.js.map +1 -0
- package/dist/admin/chunks/{Form-DTO0ZIaB.mjs → Form-D9Ee-exF.mjs} +3 -3
- package/dist/admin/chunks/{Form-DTO0ZIaB.mjs.map → Form-D9Ee-exF.mjs.map} +1 -1
- package/dist/admin/chunks/{Form-DGUP3zQO.js → Form-DDbxreII.js} +5 -5
- package/dist/admin/chunks/{Form-DGUP3zQO.js.map → Form-DDbxreII.js.map} +1 -1
- package/dist/admin/chunks/{History-CQznK1pG.js → History-D5joC76n.js} +17 -13
- package/dist/admin/chunks/History-D5joC76n.js.map +1 -0
- package/dist/admin/chunks/{History-C333pgXF.mjs → History-FuD7Tp5I.mjs} +16 -12
- package/dist/admin/chunks/History-FuD7Tp5I.mjs.map +1 -0
- package/dist/admin/chunks/{Input-BexkC_pp.mjs → Input-BHucdqva.mjs} +1108 -47
- package/dist/admin/chunks/Input-BHucdqva.mjs.map +1 -0
- package/dist/admin/chunks/{Input-DLJZHw9Y.js → Input-BJCenRYN.js} +1121 -57
- package/dist/admin/chunks/Input-BJCenRYN.js.map +1 -0
- package/dist/admin/chunks/{ListConfigurationPage-BX2WR7MI.mjs → ListConfigurationPage-3kSfz9xV.mjs} +4 -5
- package/dist/admin/chunks/{ListConfigurationPage-BX2WR7MI.mjs.map → ListConfigurationPage-3kSfz9xV.mjs.map} +1 -1
- package/dist/admin/chunks/{ListConfigurationPage-71I_stAM.js → ListConfigurationPage-CgJEcEkD.js} +6 -7
- package/dist/admin/chunks/{ListConfigurationPage-71I_stAM.js.map → ListConfigurationPage-CgJEcEkD.js.map} +1 -1
- package/dist/admin/chunks/{ListViewPage-DV3heO4F.js → ListViewPage-CvQ1w8IW.js} +7 -8
- package/dist/admin/chunks/{ListViewPage-DV3heO4F.js.map → ListViewPage-CvQ1w8IW.js.map} +1 -1
- package/dist/admin/chunks/{ListViewPage-BDeT3Dkk.mjs → ListViewPage-DPUYRHss.mjs} +3 -4
- package/dist/admin/chunks/{ListViewPage-BDeT3Dkk.mjs.map → ListViewPage-DPUYRHss.mjs.map} +1 -1
- package/dist/admin/chunks/{NoContentTypePage-9JHYpYVX.mjs → NoContentTypePage-BRLLtjLb.mjs} +2 -2
- package/dist/admin/chunks/{NoContentTypePage-9JHYpYVX.mjs.map → NoContentTypePage-BRLLtjLb.mjs.map} +1 -1
- package/dist/admin/chunks/{NoContentTypePage-COih9y2J.js → NoContentTypePage-C5Vut1Af.js} +2 -2
- package/dist/admin/chunks/{NoContentTypePage-COih9y2J.js.map → NoContentTypePage-C5Vut1Af.js.map} +1 -1
- package/dist/admin/chunks/{NoPermissionsPage-DTe9I47q.mjs → NoPermissionsPage-B5HJbcjm.mjs} +2 -2
- package/dist/admin/chunks/{NoPermissionsPage-DTe9I47q.mjs.map → NoPermissionsPage-B5HJbcjm.mjs.map} +1 -1
- package/dist/admin/chunks/{NoPermissionsPage-DGAwRIlN.js → NoPermissionsPage-BBXnpc7M.js} +2 -2
- package/dist/admin/chunks/{NoPermissionsPage-DGAwRIlN.js.map → NoPermissionsPage-BBXnpc7M.js.map} +1 -1
- package/dist/admin/chunks/{Preview-BEq0FXda.mjs → Preview-C3lnOgQx.mjs} +244 -116
- package/dist/admin/chunks/Preview-C3lnOgQx.mjs.map +1 -0
- package/dist/admin/chunks/{Preview-CXtc9yEV.js → Preview-DB7ZGawL.js} +240 -112
- package/dist/admin/chunks/Preview-DB7ZGawL.js.map +1 -0
- package/dist/admin/chunks/{en-C1CjdAtC.js → en-CH__IC8g.js} +4 -1
- package/dist/admin/chunks/{en-C1CjdAtC.js.map → en-CH__IC8g.js.map} +1 -1
- package/dist/admin/chunks/{en-LfhocNG2.mjs → en-DBP0Gaid.mjs} +4 -1
- package/dist/admin/chunks/{en-LfhocNG2.mjs.map → en-DBP0Gaid.mjs.map} +1 -1
- package/dist/admin/chunks/{index-Cs6qwFQu.mjs → index-DYrCidCq.mjs} +225 -140
- package/dist/admin/chunks/index-DYrCidCq.mjs.map +1 -0
- package/dist/admin/chunks/{index-BHimg6jW.js → index-DoUQnFTk.js} +227 -138
- package/dist/admin/chunks/index-DoUQnFTk.js.map +1 -0
- package/dist/admin/chunks/{layout-Dtahn4Ue.js → layout-CqndYVtU.js} +86 -13
- package/dist/admin/chunks/layout-CqndYVtU.js.map +1 -0
- package/dist/admin/chunks/{layout-DStNia_P.mjs → layout-D2NJmgCw.mjs} +78 -5
- package/dist/admin/chunks/layout-D2NJmgCw.mjs.map +1 -0
- package/dist/admin/chunks/{useDragAndDrop-gcqEJMnO.js → objects-BJTP843m.js} +73 -1
- package/dist/admin/chunks/objects-BJTP843m.js.map +1 -0
- package/dist/admin/chunks/{useDragAndDrop-HYwNDExe.mjs → objects-D2z-IJgu.mjs} +72 -2
- package/dist/admin/chunks/objects-D2z-IJgu.mjs.map +1 -0
- package/dist/admin/chunks/uk-BtM6WnaE.mjs +313 -0
- package/dist/admin/chunks/uk-BtM6WnaE.mjs.map +1 -0
- package/dist/admin/chunks/uk-DB6OgySY.js +318 -0
- package/dist/admin/chunks/uk-DB6OgySY.js.map +1 -0
- package/dist/admin/chunks/{relations-XOYEEqMz.js → usePrev-Cm_0-qRC.js} +18 -2
- package/dist/admin/chunks/usePrev-Cm_0-qRC.js.map +1 -0
- package/dist/admin/chunks/{relations-Cq8NRUto.mjs → usePrev-DinC2aha.mjs} +18 -4
- package/dist/admin/chunks/usePrev-DinC2aha.mjs.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/components/InjectionZone.d.ts +7 -1
- package/dist/admin/src/content-manager.d.ts +4 -0
- package/dist/admin/src/features/DocumentContext.d.ts +48 -0
- package/dist/admin/src/features/DocumentRBAC.d.ts +3 -2
- package/dist/admin/src/hooks/useDocument.d.ts +2 -0
- package/dist/admin/src/hooks/useDocumentActions.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +2 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/Relations/RelationModal.d.ts +7 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/{Relations.d.ts → Relations/Relations.d.ts} +9 -4
- package/dist/admin/src/pages/EditView/components/FormLayout.d.ts +5 -2
- package/dist/admin/src/pages/EditView/components/InputRenderer.d.ts +3 -3
- package/dist/admin/src/preview/components/PreviewContent.d.ts +1 -2
- package/dist/admin/src/preview/pages/Preview.d.ts +2 -0
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +1 -1
- package/dist/server/index.mjs.map +1 -1
- package/package.json +8 -8
- package/dist/admin/chunks/EditViewPage-CYe7wAXF.mjs.map +0 -1
- package/dist/admin/chunks/EditViewPage-DFkloeMZ.js.map +0 -1
- package/dist/admin/chunks/History-C333pgXF.mjs.map +0 -1
- package/dist/admin/chunks/History-CQznK1pG.js.map +0 -1
- package/dist/admin/chunks/Input-BexkC_pp.mjs.map +0 -1
- package/dist/admin/chunks/Input-DLJZHw9Y.js.map +0 -1
- package/dist/admin/chunks/Preview-BEq0FXda.mjs.map +0 -1
- package/dist/admin/chunks/Preview-CXtc9yEV.js.map +0 -1
- package/dist/admin/chunks/Relations-o7_hVGyK.js +0 -1318
- package/dist/admin/chunks/Relations-o7_hVGyK.js.map +0 -1
- package/dist/admin/chunks/Relations-qeZyLDgQ.mjs +0 -1291
- package/dist/admin/chunks/Relations-qeZyLDgQ.mjs.map +0 -1
- package/dist/admin/chunks/index-BHimg6jW.js.map +0 -1
- package/dist/admin/chunks/index-Cs6qwFQu.mjs.map +0 -1
- package/dist/admin/chunks/layout-DStNia_P.mjs.map +0 -1
- package/dist/admin/chunks/layout-Dtahn4Ue.js.map +0 -1
- package/dist/admin/chunks/objects-C3EebVVe.js +0 -76
- package/dist/admin/chunks/objects-C3EebVVe.js.map +0 -1
- package/dist/admin/chunks/objects-wl73iEma.mjs +0 -73
- package/dist/admin/chunks/objects-wl73iEma.mjs.map +0 -1
- package/dist/admin/chunks/relations-Cq8NRUto.mjs.map +0 -1
- package/dist/admin/chunks/relations-XOYEEqMz.js.map +0 -1
- package/dist/admin/chunks/uk-B24MoTVg.js +0 -145
- package/dist/admin/chunks/uk-B24MoTVg.js.map +0 -1
- package/dist/admin/chunks/uk-Cpgmm7gE.mjs +0 -140
- package/dist/admin/chunks/uk-Cpgmm7gE.mjs.map +0 -1
- package/dist/admin/chunks/useDragAndDrop-HYwNDExe.mjs.map +0 -1
- package/dist/admin/chunks/useDragAndDrop-gcqEJMnO.js.map +0 -1
- package/dist/admin/chunks/usePrev-Bjw2dhmq.mjs +0 -18
- package/dist/admin/chunks/usePrev-Bjw2dhmq.mjs.map +0 -1
- package/dist/admin/chunks/usePrev-DIYl-IAL.js +0 -21
- package/dist/admin/chunks/usePrev-DIYl-IAL.js.map +0 -1
@@ -6,7 +6,7 @@ var strapiAdmin = require('@strapi/admin/strapi-admin');
|
|
6
6
|
var designSystem = require('@strapi/design-system');
|
7
7
|
var Icons = require('@strapi/icons');
|
8
8
|
var reactIntl = require('react-intl');
|
9
|
-
var index = require('./index-
|
9
|
+
var index = require('./index-DoUQnFTk.js');
|
10
10
|
var styledComponents = require('styled-components');
|
11
11
|
var slate = require('slate');
|
12
12
|
var slateHistory = require('slate-history');
|
@@ -62,16 +62,15 @@ require('prismjs/components/prism-typescript');
|
|
62
62
|
require('prismjs/components/prism-tsx');
|
63
63
|
require('prismjs/components/prism-vbnet');
|
64
64
|
require('prismjs/components/prism-yaml');
|
65
|
-
var usePrev = require('./usePrev-
|
66
|
-
var
|
65
|
+
var usePrev = require('./usePrev-Cm_0-qRC.js');
|
66
|
+
var objects = require('./objects-BJTP843m.js');
|
67
67
|
var Toolbar = require('@radix-ui/react-toolbar');
|
68
68
|
var reactDndHtml5Backend = require('react-dnd-html5-backend');
|
69
69
|
var reactRouterDom = require('react-router-dom');
|
70
|
-
var objects = require('./objects-C3EebVVe.js');
|
71
|
-
var Relations = require('./Relations-o7_hVGyK.js');
|
72
70
|
var pipe$1 = require('lodash/fp/pipe');
|
73
71
|
var ComponentIcon = require('./ComponentIcon-C-EjOUPA.js');
|
74
|
-
var
|
72
|
+
var fractionalIndexing = require('fractional-indexing');
|
73
|
+
var reactWindow = require('react-window');
|
75
74
|
var CodeMirror = require('codemirror5');
|
76
75
|
var sanitizeHtml = require('sanitize-html');
|
77
76
|
var highlight_js = require('highlight.js');
|
@@ -2428,8 +2427,8 @@ const DropPlaceholder = styledComponents.styled(designSystem.Box)`
|
|
2428
2427
|
|
2429
2428
|
// Show drop placeholder 8px above or below the drop target
|
2430
2429
|
${({ dragDirection, theme, placeholderMargin })=>styledComponents.css`
|
2431
|
-
top: ${dragDirection ===
|
2432
|
-
bottom: ${dragDirection ===
|
2430
|
+
top: ${dragDirection === objects.DIRECTIONS.UPWARD && `-${theme.spaces[placeholderMargin]}`};
|
2431
|
+
bottom: ${dragDirection === objects.DIRECTIONS.DOWNWARD && `-${theme.spaces[placeholderMargin]}`};
|
2433
2432
|
`}
|
2434
2433
|
`;
|
2435
2434
|
const DragItem = styledComponents.styled(designSystem.Flex)`
|
@@ -2513,8 +2512,8 @@ const DragAndDropElement = ({ children, index: index$1, setDragDirection, dragDi
|
|
2513
2512
|
name1,
|
2514
2513
|
setLiveText
|
2515
2514
|
]);
|
2516
|
-
const [{ handlerId, isDragging, isOverDropTarget, direction }, blockRef, dropRef, dragRef] =
|
2517
|
-
type: `${
|
2515
|
+
const [{ handlerId, isDragging, isOverDropTarget, direction }, blockRef, dropRef, dragRef] = objects.useDragAndDrop(!disabled, {
|
2516
|
+
type: `${objects.ItemTypes.BLOCKS}_${name1}`,
|
2518
2517
|
index: index$1,
|
2519
2518
|
item: {
|
2520
2519
|
index: index$1,
|
@@ -3485,6 +3484,20 @@ const Initializer = ({ disabled, name, onClick })=>{
|
|
3485
3484
|
});
|
3486
3485
|
};
|
3487
3486
|
|
3487
|
+
/**
|
3488
|
+
* We use this component to wrap any individual component field in the Edit View,
|
3489
|
+
* this could be a component field in a dynamic zone, a component within a repeatable space,
|
3490
|
+
* or even nested components.
|
3491
|
+
*
|
3492
|
+
* We primarily need this to provide the component id to the components so that they can
|
3493
|
+
* correctly fetch their relations.
|
3494
|
+
*/ const [ComponentProvider, useComponent] = strapiAdmin.createContext('ComponentContext', {
|
3495
|
+
id: undefined,
|
3496
|
+
level: -1,
|
3497
|
+
uid: undefined,
|
3498
|
+
type: undefined
|
3499
|
+
});
|
3500
|
+
|
3488
3501
|
const AddComponentButton = ({ hasError, isDisabled, isOpen, children, onClick })=>{
|
3489
3502
|
return /*#__PURE__*/ jsxRuntime.jsx(StyledButton, {
|
3490
3503
|
type: "button",
|
@@ -3663,7 +3676,8 @@ const ComponentPicker = ({ dynamicComponentsByCategory = {}, isOpen, onClickAddC
|
|
3663
3676
|
const DynamicComponent = ({ componentUid, disabled, index: index$1, name, onRemoveComponentClick, onMoveComponent, onGrabItem, onDropItem, onCancel, dynamicComponentsByCategory = {}, onAddComponent, children })=>{
|
3664
3677
|
const { formatMessage } = reactIntl.useIntl();
|
3665
3678
|
const formValues = strapiAdmin.useForm('DynamicComponent', (state)=>state.values);
|
3666
|
-
const
|
3679
|
+
const documentMeta = index.useDocumentContext('DynamicComponent', (state)=>state.meta);
|
3680
|
+
const { edit: { components } } = index.useDocumentLayout(documentMeta.model);
|
3667
3681
|
const title = React__namespace.useMemo(()=>{
|
3668
3682
|
const { mainField } = components[componentUid]?.settings ?? {
|
3669
3683
|
mainField: 'id'
|
@@ -3693,8 +3707,8 @@ const DynamicComponent = ({ componentUid, disabled, index: index$1, name, onRemo
|
|
3693
3707
|
componentUid,
|
3694
3708
|
dynamicComponentsByCategory
|
3695
3709
|
]);
|
3696
|
-
const [{ handlerId, isDragging, handleKeyDown }, boxRef, dropRef, dragRef, dragPreviewRef] =
|
3697
|
-
type: `${
|
3710
|
+
const [{ handlerId, isDragging, handleKeyDown }, boxRef, dropRef, dragRef, dragPreviewRef] = objects.useDragAndDrop(!disabled, {
|
3711
|
+
type: `${objects.ItemTypes.DYNAMIC_ZONE}_${name}`,
|
3698
3712
|
index: index$1,
|
3699
3713
|
item: {
|
3700
3714
|
index: index$1,
|
@@ -4015,7 +4029,8 @@ const DynamicZone = ({ attribute, disabled: disabledProp, hint, label, labelActi
|
|
4015
4029
|
const { max = Infinity, min = -Infinity } = attribute ?? {};
|
4016
4030
|
const [addComponentIsOpen, setAddComponentIsOpen] = React__namespace.useState(false);
|
4017
4031
|
const [liveText, setLiveText] = React__namespace.useState('');
|
4018
|
-
const
|
4032
|
+
const document = index.useDocumentContext('DynamicZone', (state)=>state.document);
|
4033
|
+
const { components, isLoading } = document;
|
4019
4034
|
const disabled = disabledProp || isLoading;
|
4020
4035
|
const { addFieldRow, removeFieldRow, moveFieldRow } = strapiAdmin.useForm('DynamicZone', ({ addFieldRow, removeFieldRow, moveFieldRow })=>({
|
4021
4036
|
addFieldRow,
|
@@ -4143,7 +4158,7 @@ const DynamicZone = ({ attribute, disabled: disabledProp, hint, label, labelActi
|
|
4143
4158
|
componentName: label || name
|
4144
4159
|
});
|
4145
4160
|
};
|
4146
|
-
const level =
|
4161
|
+
const level = useComponent('DynamicZone', (state)=>state.level);
|
4147
4162
|
const ariaDescriptionId = React__namespace.useId();
|
4148
4163
|
return /*#__PURE__*/ jsxRuntime.jsx(DynamicZoneProvider, {
|
4149
4164
|
isInDynamicZone: true,
|
@@ -4175,7 +4190,7 @@ const DynamicZone = ({ attribute, disabled: disabledProp, hint, label, labelActi
|
|
4175
4190
|
}),
|
4176
4191
|
/*#__PURE__*/ jsxRuntime.jsx("ol", {
|
4177
4192
|
"aria-describedby": ariaDescriptionId,
|
4178
|
-
children: value.map((field, index)=>/*#__PURE__*/ jsxRuntime.jsx(
|
4193
|
+
children: value.map((field, index)=>/*#__PURE__*/ jsxRuntime.jsx(ComponentProvider, {
|
4179
4194
|
level: level + 1,
|
4180
4195
|
uid: field.__component,
|
4181
4196
|
// id is always a number in a dynamic zone.
|
@@ -4248,6 +4263,1055 @@ const NotAllowedInput = ({ hint, label, required, name })=>{
|
|
4248
4263
|
});
|
4249
4264
|
};
|
4250
4265
|
|
4266
|
+
function getCollectionType(url) {
|
4267
|
+
const regex = new RegExp(`(${index.COLLECTION_TYPES}|${index.SINGLE_TYPES})`);
|
4268
|
+
const match = url.match(regex);
|
4269
|
+
return match ? match[1] : undefined;
|
4270
|
+
}
|
4271
|
+
const CustomModalContent = styledComponents.styled(designSystem.Modal.Content)`
|
4272
|
+
width: 90%;
|
4273
|
+
max-width: 100%;
|
4274
|
+
height: 90%;
|
4275
|
+
max-height: 100%;
|
4276
|
+
`;
|
4277
|
+
const RelationModal = ({ open, onToggle })=>{
|
4278
|
+
const { formatMessage } = reactIntl.useIntl();
|
4279
|
+
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Modal.Root, {
|
4280
|
+
open: open,
|
4281
|
+
onOpenChange: onToggle,
|
4282
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs(CustomModalContent, {
|
4283
|
+
children: [
|
4284
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Modal.Header, {
|
4285
|
+
gap: 2,
|
4286
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Flex, {
|
4287
|
+
justifyContent: "space-between",
|
4288
|
+
alignItems: "center",
|
4289
|
+
width: "100%",
|
4290
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
4291
|
+
gap: 2,
|
4292
|
+
children: [
|
4293
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.IconButton, {
|
4294
|
+
withTooltip: false,
|
4295
|
+
label: "Back",
|
4296
|
+
variant: "ghost",
|
4297
|
+
disabled: true,
|
4298
|
+
onClick: ()=>{},
|
4299
|
+
marginRight: 1,
|
4300
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(Icons.ArrowLeft, {})
|
4301
|
+
}),
|
4302
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
|
4303
|
+
tag: "span",
|
4304
|
+
fontWeight: 600,
|
4305
|
+
children: formatMessage({
|
4306
|
+
id: 'content-manager.components.RelationInputModal.modal-title',
|
4307
|
+
defaultMessage: 'Edit a relation'
|
4308
|
+
})
|
4309
|
+
})
|
4310
|
+
]
|
4311
|
+
})
|
4312
|
+
})
|
4313
|
+
}),
|
4314
|
+
/*#__PURE__*/ jsxRuntime.jsx(RelationModalBody, {}),
|
4315
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Modal.Footer, {
|
4316
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
|
4317
|
+
onClick: onToggle,
|
4318
|
+
variant: "tertiary",
|
4319
|
+
children: formatMessage({
|
4320
|
+
id: 'app.components.Button.cancel',
|
4321
|
+
defaultMessage: 'Cancel'
|
4322
|
+
})
|
4323
|
+
})
|
4324
|
+
})
|
4325
|
+
]
|
4326
|
+
})
|
4327
|
+
});
|
4328
|
+
};
|
4329
|
+
const RelationModalBody = ()=>{
|
4330
|
+
const { formatMessage } = reactIntl.useIntl();
|
4331
|
+
const documentMeta = index.useDocumentContext('RelationModalBody', (state)=>state.meta);
|
4332
|
+
const documentResponse = index.useDocumentContext('RelationModalBody', (state)=>state.document);
|
4333
|
+
const documentLayoutResponse = index.useDocumentLayout(documentMeta.model);
|
4334
|
+
const plugins = strapiAdmin.useStrapiApp('RelationModalBody', (state)=>state.plugins);
|
4335
|
+
const initialValues = documentResponse.getInitialFormValues();
|
4336
|
+
const { permissions = [], isLoading: isLoadingPermissions, error } = strapiAdmin.useRBAC(index.PERMISSIONS.map((action)=>({
|
4337
|
+
action,
|
4338
|
+
subject: documentMeta.model
|
4339
|
+
})));
|
4340
|
+
const isLoading = isLoadingPermissions || documentLayoutResponse.isLoading || documentResponse.isLoading;
|
4341
|
+
if (isLoading && !documentResponse.document?.documentId) {
|
4342
|
+
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Loader, {
|
4343
|
+
small: true,
|
4344
|
+
children: formatMessage({
|
4345
|
+
id: 'content-manager.ListViewTable.relation-loading',
|
4346
|
+
defaultMessage: 'Relations are loading'
|
4347
|
+
})
|
4348
|
+
});
|
4349
|
+
}
|
4350
|
+
if (error || !documentMeta.model || documentLayoutResponse.error || !documentResponse.document || !documentResponse.meta || !documentResponse.schema || !initialValues) {
|
4351
|
+
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Flex, {
|
4352
|
+
alignItems: "center",
|
4353
|
+
height: "100%",
|
4354
|
+
justifyContent: "center",
|
4355
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.EmptyStateLayout, {
|
4356
|
+
icon: /*#__PURE__*/ jsxRuntime.jsx(Icons.WarningCircle, {
|
4357
|
+
width: "16rem"
|
4358
|
+
}),
|
4359
|
+
content: formatMessage({
|
4360
|
+
id: 'anErrorOccurred',
|
4361
|
+
defaultMessage: 'Whoops! Something went wrong. Please, try again.'
|
4362
|
+
})
|
4363
|
+
})
|
4364
|
+
});
|
4365
|
+
}
|
4366
|
+
const documentTitle = documentResponse.getTitle(documentLayoutResponse.edit.settings.mainField);
|
4367
|
+
const hasDraftAndPublished = documentResponse.schema?.options?.draftAndPublish ?? false;
|
4368
|
+
const props = {
|
4369
|
+
activeTab: 'draft',
|
4370
|
+
collectionType: documentMeta.collectionType,
|
4371
|
+
model: documentMeta.model,
|
4372
|
+
documentId: documentMeta.documentId,
|
4373
|
+
document: documentResponse.document,
|
4374
|
+
meta: documentResponse.meta
|
4375
|
+
};
|
4376
|
+
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Modal.Body, {
|
4377
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(index.DocumentRBAC, {
|
4378
|
+
permissions: permissions,
|
4379
|
+
model: documentMeta.model,
|
4380
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs(strapiAdmin.Form, {
|
4381
|
+
initialValues: initialValues,
|
4382
|
+
validate: (values, options)=>{
|
4383
|
+
const yupSchema = index.createYupSchema(documentResponse.schema?.attributes, documentResponse.components, {
|
4384
|
+
status: documentResponse.document?.status,
|
4385
|
+
...options
|
4386
|
+
});
|
4387
|
+
return yupSchema.validate(values, {
|
4388
|
+
abortEarly: false
|
4389
|
+
});
|
4390
|
+
},
|
4391
|
+
method: "PUT",
|
4392
|
+
children: [
|
4393
|
+
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
4394
|
+
alignItems: "flex-start",
|
4395
|
+
direction: "column",
|
4396
|
+
gap: 2,
|
4397
|
+
children: [
|
4398
|
+
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
4399
|
+
width: "100%",
|
4400
|
+
justifyContent: "space-between",
|
4401
|
+
gap: 2,
|
4402
|
+
children: [
|
4403
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
|
4404
|
+
tag: "h2",
|
4405
|
+
variant: "alpha",
|
4406
|
+
children: documentTitle
|
4407
|
+
}),
|
4408
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Flex, {
|
4409
|
+
gap: 2,
|
4410
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.DescriptionComponentRenderer, {
|
4411
|
+
props: props,
|
4412
|
+
descriptions: plugins['content-manager'].apis.getDocumentActions('relation-modal'),
|
4413
|
+
children: (actions)=>{
|
4414
|
+
const filteredActions = actions.filter((action)=>{
|
4415
|
+
return [
|
4416
|
+
action.position
|
4417
|
+
].flat().includes('relation-modal');
|
4418
|
+
});
|
4419
|
+
const [primaryAction, secondaryAction] = filteredActions;
|
4420
|
+
if (!primaryAction && !secondaryAction) return null;
|
4421
|
+
// Both actions are available when draft and publish enabled
|
4422
|
+
if (primaryAction && secondaryAction) {
|
4423
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
4424
|
+
children: [
|
4425
|
+
/*#__PURE__*/ jsxRuntime.jsx(index.DocumentActionButton, {
|
4426
|
+
...secondaryAction,
|
4427
|
+
variant: secondaryAction.variant || 'secondary'
|
4428
|
+
}),
|
4429
|
+
/*#__PURE__*/ jsxRuntime.jsx(index.DocumentActionButton, {
|
4430
|
+
...primaryAction,
|
4431
|
+
variant: primaryAction.variant || 'default'
|
4432
|
+
})
|
4433
|
+
]
|
4434
|
+
});
|
4435
|
+
}
|
4436
|
+
// Otherwise we just have the save action
|
4437
|
+
return /*#__PURE__*/ jsxRuntime.jsx(index.DocumentActionButton, {
|
4438
|
+
...primaryAction,
|
4439
|
+
variant: primaryAction.variant || 'secondary'
|
4440
|
+
});
|
4441
|
+
}
|
4442
|
+
})
|
4443
|
+
})
|
4444
|
+
]
|
4445
|
+
}),
|
4446
|
+
hasDraftAndPublished ? /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
|
4447
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(index.DocumentStatus, {
|
4448
|
+
status: documentResponse.document?.status
|
4449
|
+
})
|
4450
|
+
}) : null
|
4451
|
+
]
|
4452
|
+
}),
|
4453
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Flex, {
|
4454
|
+
flex: 1,
|
4455
|
+
overflow: "auto",
|
4456
|
+
alignItems: "stretch",
|
4457
|
+
paddingTop: 7,
|
4458
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
|
4459
|
+
overflow: "auto",
|
4460
|
+
flex: 1,
|
4461
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(FormLayout, {
|
4462
|
+
layout: documentLayoutResponse.edit.layout,
|
4463
|
+
hasBackground: false
|
4464
|
+
})
|
4465
|
+
})
|
4466
|
+
})
|
4467
|
+
]
|
4468
|
+
})
|
4469
|
+
})
|
4470
|
+
});
|
4471
|
+
};
|
4472
|
+
|
4473
|
+
/**
|
4474
|
+
* Remove a relation, whether it's been already saved or not.
|
4475
|
+
* It's used both in RelationsList, where the "remove relation" button is, and in the input,
|
4476
|
+
* because we sometimes need to remove a previous relation when selecting a new one.
|
4477
|
+
*/ function useHandleDisconnect(fieldName, consumerName) {
|
4478
|
+
const field = strapiAdmin.useField(fieldName);
|
4479
|
+
const removeFieldRow = strapiAdmin.useForm(consumerName, (state)=>state.removeFieldRow);
|
4480
|
+
const addFieldRow = strapiAdmin.useForm(consumerName, (state)=>state.addFieldRow);
|
4481
|
+
const handleDisconnect = (relation)=>{
|
4482
|
+
if (field.value && field.value.connect) {
|
4483
|
+
/**
|
4484
|
+
* A relation will exist in the `connect` array _if_ it has
|
4485
|
+
* been added without saving. In this case, we just remove it
|
4486
|
+
* from the connect array
|
4487
|
+
*/ const indexOfRelationInConnectArray = field.value.connect.findIndex((rel)=>rel.id === relation.id);
|
4488
|
+
if (indexOfRelationInConnectArray >= 0) {
|
4489
|
+
removeFieldRow(`${fieldName}.connect`, indexOfRelationInConnectArray);
|
4490
|
+
return;
|
4491
|
+
}
|
4492
|
+
}
|
4493
|
+
addFieldRow(`${fieldName}.disconnect`, {
|
4494
|
+
id: relation.id,
|
4495
|
+
apiData: {
|
4496
|
+
id: relation.id,
|
4497
|
+
documentId: relation.documentId,
|
4498
|
+
locale: relation.locale
|
4499
|
+
}
|
4500
|
+
});
|
4501
|
+
};
|
4502
|
+
return handleDisconnect;
|
4503
|
+
}
|
4504
|
+
/* -------------------------------------------------------------------------------------------------
|
4505
|
+
* RelationsField
|
4506
|
+
* -----------------------------------------------------------------------------------------------*/ const RELATIONS_TO_DISPLAY = 5;
|
4507
|
+
const ONE_WAY_RELATIONS = [
|
4508
|
+
'oneWay',
|
4509
|
+
'oneToOne',
|
4510
|
+
'manyToOne',
|
4511
|
+
'oneToManyMorph',
|
4512
|
+
'oneToOneMorph'
|
4513
|
+
];
|
4514
|
+
/**
|
4515
|
+
* TODO: we get a rather ugly flash when we remove a single relation from the list leaving
|
4516
|
+
* no other relations when we press save. The initial relation re-renders, probably because
|
4517
|
+
* of the lag in the Form cleaning it's "disconnect" array, whilst our data has not been invalidated.
|
4518
|
+
*
|
4519
|
+
* Could we invalidate relation data on the document actions? Should we?
|
4520
|
+
*/ /**
|
4521
|
+
* @internal
|
4522
|
+
* @description The relations field holds a lot of domain logic for handling relations which is rather complicated
|
4523
|
+
* At present we do not expose this to plugin developers, however, they are able to overwrite it themselves should
|
4524
|
+
* they wish to do so.
|
4525
|
+
*/ const RelationsField = /*#__PURE__*/ React__namespace.forwardRef(({ disabled, label, ...props }, ref)=>{
|
4526
|
+
const documentMeta = index.useDocumentContext('RelationsField', (state)=>state.meta);
|
4527
|
+
const documentResponse = index.useDocumentContext('RelationsField', (state)=>state.document);
|
4528
|
+
const [currentPage, setCurrentPage] = React__namespace.useState(1);
|
4529
|
+
const documentId = documentResponse.document?.documentId;
|
4530
|
+
const { formatMessage } = reactIntl.useIntl();
|
4531
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
4532
|
+
const params = index.buildValidParams(query);
|
4533
|
+
const isMorph = props.attribute.relation.toLowerCase().includes('morph');
|
4534
|
+
const isDisabled = isMorph || disabled;
|
4535
|
+
const { componentId, componentUID } = useComponent('RelationsField', ({ uid, id })=>({
|
4536
|
+
componentId: id,
|
4537
|
+
componentUID: uid
|
4538
|
+
}));
|
4539
|
+
const isSubmitting = strapiAdmin.useForm('RelationsList', (state)=>state.isSubmitting);
|
4540
|
+
React__namespace.useEffect(()=>{
|
4541
|
+
setCurrentPage(1);
|
4542
|
+
}, [
|
4543
|
+
isSubmitting
|
4544
|
+
]);
|
4545
|
+
/**
|
4546
|
+
* We'll always have a documentId in a created entry, so we look for a componentId first.
|
4547
|
+
* Same with `uid` and `documentModel`.
|
4548
|
+
*/ const id = componentId ? componentId.toString() : documentId;
|
4549
|
+
const model = componentUID ?? documentMeta.model;
|
4550
|
+
/**
|
4551
|
+
* The `name` prop is a complete path to the field, e.g. `field1.field2.field3`.
|
4552
|
+
* Where the above example would a nested field within two components, however
|
4553
|
+
* we only require the field on the component not the complete path since we query
|
4554
|
+
* individual components. Therefore we split the string and take the last item.
|
4555
|
+
*/ const [targetField] = props.name.split('.').slice(-1);
|
4556
|
+
const { data, isLoading, isFetching } = usePrev.useGetRelationsQuery({
|
4557
|
+
model,
|
4558
|
+
targetField,
|
4559
|
+
// below we don't run the query if there is no id.
|
4560
|
+
id,
|
4561
|
+
params: {
|
4562
|
+
...params,
|
4563
|
+
pageSize: RELATIONS_TO_DISPLAY,
|
4564
|
+
page: currentPage
|
4565
|
+
}
|
4566
|
+
}, {
|
4567
|
+
refetchOnMountOrArgChange: true,
|
4568
|
+
skip: !id,
|
4569
|
+
selectFromResult: (result)=>{
|
4570
|
+
return {
|
4571
|
+
...result,
|
4572
|
+
data: {
|
4573
|
+
...result.data,
|
4574
|
+
results: result.data?.results ? result.data.results : []
|
4575
|
+
}
|
4576
|
+
};
|
4577
|
+
}
|
4578
|
+
});
|
4579
|
+
const handleLoadMore = ()=>{
|
4580
|
+
setCurrentPage((prev)=>prev + 1);
|
4581
|
+
};
|
4582
|
+
const field = strapiAdmin.useField(props.name);
|
4583
|
+
const isFetchingMoreRelations = isLoading || isFetching;
|
4584
|
+
const realServerRelationsCount = 'pagination' in data && data.pagination ? data.pagination.total : 0;
|
4585
|
+
/**
|
4586
|
+
* Items that are already connected, but reordered would be in
|
4587
|
+
* this list, so to get an accurate figure, we remove them.
|
4588
|
+
*/ const relationsConnected = (field.value?.connect ?? []).filter((rel)=>data.results.findIndex((relation)=>relation.id === rel.id) === -1).length ?? 0;
|
4589
|
+
const relationsDisconnected = field.value?.disconnect?.length ?? 0;
|
4590
|
+
const relationsCount = realServerRelationsCount + relationsConnected - relationsDisconnected;
|
4591
|
+
/**
|
4592
|
+
* This is it, the source of truth for reordering in conjunction with partial loading & updating
|
4593
|
+
* of relations. Relations on load are given __temp_key__ when fetched, because we don't want to
|
4594
|
+
* create brand new keys everytime the data updates, just keep adding them onto the newly loaded ones.
|
4595
|
+
*/ const relations = React__namespace.useMemo(()=>{
|
4596
|
+
const ctx = {
|
4597
|
+
field: field.value,
|
4598
|
+
// @ts-expect-error – targetModel does exist on the attribute. But it's not typed.
|
4599
|
+
href: `../${index.COLLECTION_TYPES}/${props.attribute.targetModel}`,
|
4600
|
+
mainField: props.mainField
|
4601
|
+
};
|
4602
|
+
/**
|
4603
|
+
* Tidy up our data.
|
4604
|
+
*/ const transformations = pipe$1(removeConnected(ctx), removeDisconnected(ctx), addLabelAndHref(ctx));
|
4605
|
+
const transformedRels = transformations([
|
4606
|
+
...data.results
|
4607
|
+
]);
|
4608
|
+
/**
|
4609
|
+
* THIS IS CRUCIAL. If you don't sort by the __temp_key__ which comes from fractional indexing
|
4610
|
+
* then the list will be in the wrong order.
|
4611
|
+
*/ return [
|
4612
|
+
...transformedRels,
|
4613
|
+
...field.value?.connect ?? []
|
4614
|
+
].sort((a, b)=>{
|
4615
|
+
if (a.__temp_key__ < b.__temp_key__) return -1;
|
4616
|
+
if (a.__temp_key__ > b.__temp_key__) return 1;
|
4617
|
+
return 0;
|
4618
|
+
});
|
4619
|
+
}, [
|
4620
|
+
data.results,
|
4621
|
+
field.value,
|
4622
|
+
// @ts-expect-error – targetModel does exist on the attribute. But it's not typed.
|
4623
|
+
props.attribute.targetModel,
|
4624
|
+
props.mainField
|
4625
|
+
]);
|
4626
|
+
const handleDisconnect = useHandleDisconnect(props.name, 'RelationsField');
|
4627
|
+
const handleConnect = (relation)=>{
|
4628
|
+
const [lastItemInList] = relations.slice(-1);
|
4629
|
+
const item = {
|
4630
|
+
id: relation.id,
|
4631
|
+
apiData: {
|
4632
|
+
id: relation.id,
|
4633
|
+
documentId: relation.documentId,
|
4634
|
+
locale: relation.locale
|
4635
|
+
},
|
4636
|
+
status: relation.status,
|
4637
|
+
/**
|
4638
|
+
* If there's a last item, that's the first key we use to generate out next one.
|
4639
|
+
*/ __temp_key__: fractionalIndexing.generateNKeysBetween(lastItemInList?.__temp_key__ ?? null, null, 1)[0],
|
4640
|
+
// Fallback to `id` if there is no `mainField` value, which will overwrite the above `id` property with the exact same data.
|
4641
|
+
[props.mainField?.name ?? 'documentId']: relation[props.mainField?.name ?? 'documentId'],
|
4642
|
+
label: usePrev.getRelationLabel(relation, props.mainField),
|
4643
|
+
// @ts-expect-error – targetModel does exist on the attribute, but it's not typed.
|
4644
|
+
href: `../${index.COLLECTION_TYPES}/${props.attribute.targetModel}/${relation.documentId}?${relation.locale ? `plugins[i18n][locale]=${relation.locale}` : ''}`
|
4645
|
+
};
|
4646
|
+
if (ONE_WAY_RELATIONS.includes(props.attribute.relation)) {
|
4647
|
+
// Remove any existing relation so they can be replaced with the new one
|
4648
|
+
field.value?.connect?.forEach(handleDisconnect);
|
4649
|
+
relations.forEach(handleDisconnect);
|
4650
|
+
field.onChange(`${props.name}.connect`, [
|
4651
|
+
item
|
4652
|
+
]);
|
4653
|
+
} else {
|
4654
|
+
field.onChange(`${props.name}.connect`, [
|
4655
|
+
...field.value?.connect ?? [],
|
4656
|
+
item
|
4657
|
+
]);
|
4658
|
+
}
|
4659
|
+
};
|
4660
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
4661
|
+
ref: ref,
|
4662
|
+
direction: "column",
|
4663
|
+
gap: 3,
|
4664
|
+
justifyContent: "space-between",
|
4665
|
+
alignItems: "stretch",
|
4666
|
+
wrap: "wrap",
|
4667
|
+
children: [
|
4668
|
+
/*#__PURE__*/ jsxRuntime.jsxs(StyledFlex, {
|
4669
|
+
direction: "column",
|
4670
|
+
alignItems: "start",
|
4671
|
+
gap: 2,
|
4672
|
+
width: "100%",
|
4673
|
+
children: [
|
4674
|
+
/*#__PURE__*/ jsxRuntime.jsx(RelationsInput, {
|
4675
|
+
disabled: isDisabled,
|
4676
|
+
// NOTE: we should not default to using the documentId if the component is being created (componentUID is undefined)
|
4677
|
+
id: componentUID ? componentId ? `${componentId}` : '' : documentId,
|
4678
|
+
label: `${label} ${relationsCount > 0 ? `(${relationsCount})` : ''}`,
|
4679
|
+
model: model,
|
4680
|
+
onChange: handleConnect,
|
4681
|
+
...props
|
4682
|
+
}),
|
4683
|
+
'pagination' in data && data.pagination && data.pagination.pageCount > data.pagination.page ? /*#__PURE__*/ jsxRuntime.jsx(designSystem.TextButton, {
|
4684
|
+
disabled: isFetchingMoreRelations,
|
4685
|
+
onClick: handleLoadMore,
|
4686
|
+
loading: isFetchingMoreRelations,
|
4687
|
+
startIcon: /*#__PURE__*/ jsxRuntime.jsx(Icons.ArrowClockwise, {}),
|
4688
|
+
// prevent the label from line-wrapping
|
4689
|
+
shrink: 0,
|
4690
|
+
children: formatMessage({
|
4691
|
+
id: index.getTranslation('relation.loadMore'),
|
4692
|
+
defaultMessage: 'Load More'
|
4693
|
+
})
|
4694
|
+
}) : null
|
4695
|
+
]
|
4696
|
+
}),
|
4697
|
+
/*#__PURE__*/ jsxRuntime.jsx(RelationsList, {
|
4698
|
+
data: relations,
|
4699
|
+
serverData: data.results,
|
4700
|
+
disabled: isDisabled,
|
4701
|
+
name: props.name,
|
4702
|
+
isLoading: isFetchingMoreRelations,
|
4703
|
+
relationType: props.attribute.relation,
|
4704
|
+
// @ts-expect-error – targetModel does exist on the attribute. But it's not typed.
|
4705
|
+
targetModel: props.attribute.targetModel
|
4706
|
+
})
|
4707
|
+
]
|
4708
|
+
});
|
4709
|
+
});
|
4710
|
+
/**
|
4711
|
+
* TODO: this can be removed once we stop shipping Inputs with
|
4712
|
+
* labels wrapped round in DS@2.
|
4713
|
+
*/ const StyledFlex = styledComponents.styled(designSystem.Flex)`
|
4714
|
+
& > div {
|
4715
|
+
width: 100%;
|
4716
|
+
}
|
4717
|
+
`;
|
4718
|
+
/**
|
4719
|
+
* If it's in the connected array, it can get out of our data array,
|
4720
|
+
* we'll be putting it back in later and sorting it anyway.
|
4721
|
+
*/ const removeConnected = ({ field })=>(relations)=>{
|
4722
|
+
return relations.filter((relation)=>{
|
4723
|
+
const connectedRelations = field?.connect ?? [];
|
4724
|
+
return connectedRelations.findIndex((rel)=>rel.id === relation.id) === -1;
|
4725
|
+
});
|
4726
|
+
};
|
4727
|
+
/**
|
4728
|
+
* @description Removes relations that are in the `disconnect` array of the field
|
4729
|
+
*/ const removeDisconnected = ({ field })=>(relations)=>relations.filter((relation)=>{
|
4730
|
+
const disconnectedRelations = field?.disconnect ?? [];
|
4731
|
+
return disconnectedRelations.findIndex((rel)=>rel.id === relation.id) === -1;
|
4732
|
+
});
|
4733
|
+
/**
|
4734
|
+
* @description Adds a label and href to the relation object we use this to render
|
4735
|
+
* a better UI where we can link to the relation and display a human-readable label.
|
4736
|
+
*/ const addLabelAndHref = ({ mainField, href })=>(relations)=>relations.map((relation)=>{
|
4737
|
+
return {
|
4738
|
+
...relation,
|
4739
|
+
// Fallback to `id` if there is no `mainField` value, which will overwrite the above `documentId` property with the exact same data.
|
4740
|
+
[mainField?.name ?? 'documentId']: relation[mainField?.name ?? 'documentId'],
|
4741
|
+
label: usePrev.getRelationLabel(relation, mainField),
|
4742
|
+
href: `${href}/${relation.documentId}?${relation.locale ? `plugins[i18n][locale]=${relation.locale}` : ''}`
|
4743
|
+
};
|
4744
|
+
});
|
4745
|
+
/**
|
4746
|
+
* @description Contains all the logic for the combobox that can search
|
4747
|
+
* for relations and then add them to the field's connect array.
|
4748
|
+
*/ const RelationsInput = ({ hint, id, model, label, labelAction, name, mainField, placeholder, required, unique: _unique, 'aria-label': _ariaLabel, onChange, ...props })=>{
|
4749
|
+
const [textValue, setTextValue] = React__namespace.useState('');
|
4750
|
+
const [searchParams, setSearchParams] = React__namespace.useState({
|
4751
|
+
_q: '',
|
4752
|
+
page: 1
|
4753
|
+
});
|
4754
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
4755
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
4756
|
+
const { formatMessage } = reactIntl.useIntl();
|
4757
|
+
const fieldRef = strapiAdmin.useFocusInputField(name);
|
4758
|
+
const field = strapiAdmin.useField(name);
|
4759
|
+
const searchParamsDebounced = usePrev.useDebounce(searchParams, 300);
|
4760
|
+
const [searchForTrigger, { data, isLoading }] = usePrev.useLazySearchRelationsQuery();
|
4761
|
+
/**
|
4762
|
+
* Because we're using a lazy query, we need to trigger the search
|
4763
|
+
* when the component mounts and when the search params change.
|
4764
|
+
* We also need to trigger the search when the field value changes
|
4765
|
+
* so that we can filter out the relations that are already connected.
|
4766
|
+
*/ React__namespace.useEffect(()=>{
|
4767
|
+
/**
|
4768
|
+
* The `name` prop is a complete path to the field, e.g. `field1.field2.field3`.
|
4769
|
+
* Where the above example would a nested field within two components, however
|
4770
|
+
* we only require the field on the component not the complete path since we query
|
4771
|
+
* individual components. Therefore we split the string and take the last item.
|
4772
|
+
*/ const [targetField] = name.split('.').slice(-1);
|
4773
|
+
searchForTrigger({
|
4774
|
+
model,
|
4775
|
+
targetField,
|
4776
|
+
params: {
|
4777
|
+
...index.buildValidParams(query),
|
4778
|
+
id: id ?? '',
|
4779
|
+
pageSize: 10,
|
4780
|
+
idsToInclude: field.value?.disconnect?.map((rel)=>rel.id.toString()) ?? [],
|
4781
|
+
idsToOmit: field.value?.connect?.map((rel)=>rel.id.toString()) ?? [],
|
4782
|
+
...searchParamsDebounced
|
4783
|
+
}
|
4784
|
+
});
|
4785
|
+
}, [
|
4786
|
+
field.value?.connect,
|
4787
|
+
field.value?.disconnect,
|
4788
|
+
id,
|
4789
|
+
model,
|
4790
|
+
name,
|
4791
|
+
query,
|
4792
|
+
searchForTrigger,
|
4793
|
+
searchParamsDebounced
|
4794
|
+
]);
|
4795
|
+
const handleSearch = async (search)=>{
|
4796
|
+
setSearchParams((s)=>({
|
4797
|
+
...s,
|
4798
|
+
_q: search,
|
4799
|
+
page: 1
|
4800
|
+
}));
|
4801
|
+
};
|
4802
|
+
const hasNextPage = data?.pagination ? data.pagination.page < data.pagination.pageCount : false;
|
4803
|
+
const options = data?.results ?? [];
|
4804
|
+
const handleChange = (relationId)=>{
|
4805
|
+
if (!relationId) {
|
4806
|
+
return;
|
4807
|
+
}
|
4808
|
+
const relation = options.find((opt)=>opt.id.toString() === relationId);
|
4809
|
+
if (!relation) {
|
4810
|
+
// This is very unlikely to happen, but it ensures we don't have any data for.
|
4811
|
+
console.error("You've tried to add a relation with an id that does not exist in the options you can see, this is likely a bug with Strapi. Please open an issue.");
|
4812
|
+
toggleNotification({
|
4813
|
+
message: formatMessage({
|
4814
|
+
id: index.getTranslation('relation.error-adding-relation'),
|
4815
|
+
defaultMessage: 'An error occurred while trying to add the relation.'
|
4816
|
+
}),
|
4817
|
+
type: 'danger'
|
4818
|
+
});
|
4819
|
+
return;
|
4820
|
+
}
|
4821
|
+
/**
|
4822
|
+
* You need to give this relation a correct _temp_key_ but
|
4823
|
+
* this component doesn't know about those ones, you can't rely
|
4824
|
+
* on the connect array because that doesn't hold items that haven't
|
4825
|
+
* moved. So use a callback to fill in the gaps when connecting.
|
4826
|
+
*
|
4827
|
+
*/ onChange(relation);
|
4828
|
+
};
|
4829
|
+
const handleLoadMore = ()=>{
|
4830
|
+
if (!data || !data.pagination) {
|
4831
|
+
return;
|
4832
|
+
} else if (data.pagination.page < data.pagination.pageCount) {
|
4833
|
+
setSearchParams((s)=>({
|
4834
|
+
...s,
|
4835
|
+
page: s.page + 1
|
4836
|
+
}));
|
4837
|
+
}
|
4838
|
+
};
|
4839
|
+
React__namespace.useLayoutEffect(()=>{
|
4840
|
+
setTextValue('');
|
4841
|
+
}, [
|
4842
|
+
field.value
|
4843
|
+
]);
|
4844
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Field.Root, {
|
4845
|
+
error: field.error,
|
4846
|
+
hint: hint,
|
4847
|
+
name: name,
|
4848
|
+
required: required,
|
4849
|
+
children: [
|
4850
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Label, {
|
4851
|
+
action: labelAction,
|
4852
|
+
children: label
|
4853
|
+
}),
|
4854
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Combobox, {
|
4855
|
+
ref: fieldRef,
|
4856
|
+
name: name,
|
4857
|
+
autocomplete: "list",
|
4858
|
+
placeholder: placeholder || formatMessage({
|
4859
|
+
id: index.getTranslation('relation.add'),
|
4860
|
+
defaultMessage: 'Add relation'
|
4861
|
+
}),
|
4862
|
+
hasMoreItems: hasNextPage,
|
4863
|
+
loading: isLoading,
|
4864
|
+
onOpenChange: ()=>{
|
4865
|
+
handleSearch(textValue ?? '');
|
4866
|
+
},
|
4867
|
+
noOptionsMessage: ()=>formatMessage({
|
4868
|
+
id: index.getTranslation('relation.notAvailable'),
|
4869
|
+
defaultMessage: 'No relations available'
|
4870
|
+
}),
|
4871
|
+
loadingMessage: formatMessage({
|
4872
|
+
id: index.getTranslation('relation.isLoading'),
|
4873
|
+
defaultMessage: 'Relations are loading'
|
4874
|
+
}),
|
4875
|
+
onLoadMore: handleLoadMore,
|
4876
|
+
textValue: textValue,
|
4877
|
+
onChange: handleChange,
|
4878
|
+
onTextValueChange: (text)=>{
|
4879
|
+
setTextValue(text);
|
4880
|
+
},
|
4881
|
+
onInputChange: (event)=>{
|
4882
|
+
handleSearch(event.currentTarget.value);
|
4883
|
+
},
|
4884
|
+
...props,
|
4885
|
+
children: options.map((opt)=>{
|
4886
|
+
const textValue = usePrev.getRelationLabel(opt, mainField);
|
4887
|
+
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.ComboboxOption, {
|
4888
|
+
value: opt.id.toString(),
|
4889
|
+
textValue: textValue,
|
4890
|
+
children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
4891
|
+
gap: 2,
|
4892
|
+
justifyContent: "space-between",
|
4893
|
+
children: [
|
4894
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
|
4895
|
+
ellipsis: true,
|
4896
|
+
children: textValue
|
4897
|
+
}),
|
4898
|
+
opt.status ? /*#__PURE__*/ jsxRuntime.jsx(index.DocumentStatus, {
|
4899
|
+
status: opt.status
|
4900
|
+
}) : null
|
4901
|
+
]
|
4902
|
+
})
|
4903
|
+
}, opt.id);
|
4904
|
+
})
|
4905
|
+
}),
|
4906
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Error, {}),
|
4907
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Hint, {})
|
4908
|
+
]
|
4909
|
+
});
|
4910
|
+
};
|
4911
|
+
/* -------------------------------------------------------------------------------------------------
|
4912
|
+
* RelationsList
|
4913
|
+
* -----------------------------------------------------------------------------------------------*/ const RELATION_ITEM_HEIGHT = 50;
|
4914
|
+
const RELATION_GUTTER = 4;
|
4915
|
+
const RelationsList = ({ data, serverData, disabled, name, isLoading, relationType, targetModel })=>{
|
4916
|
+
const ariaDescriptionId = React__namespace.useId();
|
4917
|
+
const { formatMessage } = reactIntl.useIntl();
|
4918
|
+
const listRef = React__namespace.useRef(null);
|
4919
|
+
const outerListRef = React__namespace.useRef(null);
|
4920
|
+
const [overflow, setOverflow] = React__namespace.useState();
|
4921
|
+
const [liveText, setLiveText] = React__namespace.useState('');
|
4922
|
+
const field = strapiAdmin.useField(name);
|
4923
|
+
React__namespace.useEffect(()=>{
|
4924
|
+
if (data.length <= RELATIONS_TO_DISPLAY) {
|
4925
|
+
return setOverflow(undefined);
|
4926
|
+
}
|
4927
|
+
const handleNativeScroll = (e)=>{
|
4928
|
+
const el = e.target;
|
4929
|
+
const parentScrollContainerHeight = el.parentNode.scrollHeight;
|
4930
|
+
const maxScrollBottom = el.scrollHeight - el.scrollTop;
|
4931
|
+
if (el.scrollTop === 0) {
|
4932
|
+
return setOverflow('bottom');
|
4933
|
+
}
|
4934
|
+
if (maxScrollBottom === parentScrollContainerHeight) {
|
4935
|
+
return setOverflow('top');
|
4936
|
+
}
|
4937
|
+
return setOverflow('top-bottom');
|
4938
|
+
};
|
4939
|
+
const outerListRefCurrent = outerListRef?.current;
|
4940
|
+
if (!isLoading && data.length > 0 && outerListRefCurrent) {
|
4941
|
+
outerListRef.current.addEventListener('scroll', handleNativeScroll);
|
4942
|
+
}
|
4943
|
+
return ()=>{
|
4944
|
+
if (outerListRefCurrent) {
|
4945
|
+
outerListRefCurrent.removeEventListener('scroll', handleNativeScroll);
|
4946
|
+
}
|
4947
|
+
};
|
4948
|
+
}, [
|
4949
|
+
isLoading,
|
4950
|
+
data.length
|
4951
|
+
]);
|
4952
|
+
const getItemPos = (index)=>`${index + 1} of ${data.length}`;
|
4953
|
+
const handleMoveItem = (newIndex, oldIndex)=>{
|
4954
|
+
const item = data[oldIndex];
|
4955
|
+
setLiveText(formatMessage({
|
4956
|
+
id: index.getTranslation('dnd.reorder'),
|
4957
|
+
defaultMessage: '{item}, moved. New position in list: {position}.'
|
4958
|
+
}, {
|
4959
|
+
item: item.label ?? item.documentId,
|
4960
|
+
position: getItemPos(newIndex)
|
4961
|
+
}));
|
4962
|
+
/**
|
4963
|
+
* Splicing mutates the array, so we need to create a new array
|
4964
|
+
*/ const newData = [
|
4965
|
+
...data
|
4966
|
+
];
|
4967
|
+
const currentRow = data[oldIndex];
|
4968
|
+
const startKey = oldIndex > newIndex ? newData[newIndex - 1]?.__temp_key__ : newData[newIndex]?.__temp_key__;
|
4969
|
+
const endKey = oldIndex > newIndex ? newData[newIndex]?.__temp_key__ : newData[newIndex + 1]?.__temp_key__;
|
4970
|
+
/**
|
4971
|
+
* We're moving the relation between two other relations, so
|
4972
|
+
* we need to generate a new key that keeps the order
|
4973
|
+
*/ const [newKey] = fractionalIndexing.generateNKeysBetween(startKey, endKey, 1);
|
4974
|
+
newData.splice(oldIndex, 1);
|
4975
|
+
newData.splice(newIndex, 0, {
|
4976
|
+
...currentRow,
|
4977
|
+
__temp_key__: newKey
|
4978
|
+
});
|
4979
|
+
/**
|
4980
|
+
* Now we diff against the server to understand what's different so we
|
4981
|
+
* can keep the connect array nice and tidy. It also needs reversing because
|
4982
|
+
* we reverse the relations from the server in the first place.
|
4983
|
+
*/ const connectedRelations = newData.reduce((acc, relation, currentIndex, array)=>{
|
4984
|
+
const relationOnServer = serverData.find((oldRelation)=>oldRelation.id === relation.id);
|
4985
|
+
const relationInFront = array[currentIndex + 1];
|
4986
|
+
if (!relationOnServer || relationOnServer.__temp_key__ !== relation.__temp_key__) {
|
4987
|
+
const position = relationInFront ? {
|
4988
|
+
before: relationInFront.documentId,
|
4989
|
+
locale: relationInFront.locale,
|
4990
|
+
status: 'publishedAt' in relationInFront && relationInFront.publishedAt ? 'published' : 'draft'
|
4991
|
+
} : {
|
4992
|
+
end: true
|
4993
|
+
};
|
4994
|
+
const relationWithPosition = {
|
4995
|
+
...relation,
|
4996
|
+
...{
|
4997
|
+
apiData: {
|
4998
|
+
id: relation.id,
|
4999
|
+
documentId: relation.documentId,
|
5000
|
+
locale: relation.locale,
|
5001
|
+
position
|
5002
|
+
}
|
5003
|
+
}
|
5004
|
+
};
|
5005
|
+
return [
|
5006
|
+
...acc,
|
5007
|
+
relationWithPosition
|
5008
|
+
];
|
5009
|
+
}
|
5010
|
+
return acc;
|
5011
|
+
}, []).toReversed();
|
5012
|
+
field.onChange(`${name}.connect`, connectedRelations);
|
5013
|
+
};
|
5014
|
+
const handleGrabItem = (index$1)=>{
|
5015
|
+
const item = data[index$1];
|
5016
|
+
setLiveText(formatMessage({
|
5017
|
+
id: index.getTranslation('dnd.grab-item'),
|
5018
|
+
defaultMessage: `{item}, grabbed. Current position in list: {position}. Press up and down arrow to change position, Spacebar to drop, Escape to cancel.`
|
5019
|
+
}, {
|
5020
|
+
item: item.label ?? item.documentId,
|
5021
|
+
position: getItemPos(index$1)
|
5022
|
+
}));
|
5023
|
+
};
|
5024
|
+
const handleDropItem = (index$1)=>{
|
5025
|
+
const { href: _href, label, ...item } = data[index$1];
|
5026
|
+
setLiveText(formatMessage({
|
5027
|
+
id: index.getTranslation('dnd.drop-item'),
|
5028
|
+
defaultMessage: `{item}, dropped. Final position in list: {position}.`
|
5029
|
+
}, {
|
5030
|
+
item: label ?? item.documentId,
|
5031
|
+
position: getItemPos(index$1)
|
5032
|
+
}));
|
5033
|
+
};
|
5034
|
+
const handleCancel = (index$1)=>{
|
5035
|
+
const item = data[index$1];
|
5036
|
+
setLiveText(formatMessage({
|
5037
|
+
id: index.getTranslation('dnd.cancel-item'),
|
5038
|
+
defaultMessage: '{item}, dropped. Re-order cancelled.'
|
5039
|
+
}, {
|
5040
|
+
item: item.label ?? item.documentId
|
5041
|
+
}));
|
5042
|
+
};
|
5043
|
+
const handleDisconnect = useHandleDisconnect(name, 'RelationsList');
|
5044
|
+
/**
|
5045
|
+
* These relation types will only ever have one item
|
5046
|
+
* in their list, so you can't reorder a single item!
|
5047
|
+
*/ const canReorder = !ONE_WAY_RELATIONS.includes(relationType);
|
5048
|
+
const dynamicListHeight = data.length > RELATIONS_TO_DISPLAY ? Math.min(data.length, RELATIONS_TO_DISPLAY) * (RELATION_ITEM_HEIGHT + RELATION_GUTTER) + RELATION_ITEM_HEIGHT / 2 : Math.min(data.length, RELATIONS_TO_DISPLAY) * (RELATION_ITEM_HEIGHT + RELATION_GUTTER);
|
5049
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(ShadowBox, {
|
5050
|
+
$overflowDirection: overflow,
|
5051
|
+
children: [
|
5052
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.VisuallyHidden, {
|
5053
|
+
id: ariaDescriptionId,
|
5054
|
+
children: formatMessage({
|
5055
|
+
id: index.getTranslation('dnd.instructions'),
|
5056
|
+
defaultMessage: `Press spacebar to grab and re-order`
|
5057
|
+
})
|
5058
|
+
}),
|
5059
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.VisuallyHidden, {
|
5060
|
+
"aria-live": "assertive",
|
5061
|
+
children: liveText
|
5062
|
+
}),
|
5063
|
+
/*#__PURE__*/ jsxRuntime.jsx(reactWindow.FixedSizeList, {
|
5064
|
+
height: dynamicListHeight,
|
5065
|
+
ref: listRef,
|
5066
|
+
outerRef: outerListRef,
|
5067
|
+
itemCount: data.length,
|
5068
|
+
itemSize: RELATION_ITEM_HEIGHT + RELATION_GUTTER,
|
5069
|
+
itemData: {
|
5070
|
+
ariaDescribedBy: ariaDescriptionId,
|
5071
|
+
canDrag: canReorder,
|
5072
|
+
disabled,
|
5073
|
+
handleCancel,
|
5074
|
+
handleDropItem,
|
5075
|
+
handleGrabItem,
|
5076
|
+
handleMoveItem,
|
5077
|
+
name,
|
5078
|
+
handleDisconnect,
|
5079
|
+
relations: data,
|
5080
|
+
targetModel
|
5081
|
+
},
|
5082
|
+
itemKey: (index)=>data[index].id,
|
5083
|
+
innerElementType: "ol",
|
5084
|
+
children: ListItem
|
5085
|
+
})
|
5086
|
+
]
|
5087
|
+
});
|
5088
|
+
};
|
5089
|
+
const ShadowBox = styledComponents.styled(designSystem.Box)`
|
5090
|
+
position: relative;
|
5091
|
+
overflow: hidden;
|
5092
|
+
flex: 1;
|
5093
|
+
|
5094
|
+
&:before,
|
5095
|
+
&:after {
|
5096
|
+
position: absolute;
|
5097
|
+
width: 100%;
|
5098
|
+
height: 4px;
|
5099
|
+
z-index: 1;
|
5100
|
+
}
|
5101
|
+
|
5102
|
+
&:before {
|
5103
|
+
/* TODO: as for DS Table component we would need this to be handled by the DS theme */
|
5104
|
+
content: '';
|
5105
|
+
background: linear-gradient(rgba(3, 3, 5, 0.2) 0%, rgba(0, 0, 0, 0) 100%);
|
5106
|
+
top: 0;
|
5107
|
+
opacity: ${({ $overflowDirection })=>$overflowDirection === 'top-bottom' || $overflowDirection === 'top' ? 1 : 0};
|
5108
|
+
transition: opacity 0.2s ease-in-out;
|
5109
|
+
}
|
5110
|
+
|
5111
|
+
&:after {
|
5112
|
+
/* TODO: as for DS Table component we would need this to be handled by the DS theme */
|
5113
|
+
content: '';
|
5114
|
+
background: linear-gradient(0deg, rgba(3, 3, 5, 0.2) 0%, rgba(0, 0, 0, 0) 100%);
|
5115
|
+
bottom: 0;
|
5116
|
+
opacity: ${({ $overflowDirection })=>$overflowDirection === 'top-bottom' || $overflowDirection === 'bottom' ? 1 : 0};
|
5117
|
+
transition: opacity 0.2s ease-in-out;
|
5118
|
+
}
|
5119
|
+
`;
|
5120
|
+
const CustomTextButton = styledComponents.styled(designSystem.TextButton)`
|
5121
|
+
& > span {
|
5122
|
+
font-size: ${({ theme })=>theme.fontSizes[2]};
|
5123
|
+
}
|
5124
|
+
`;
|
5125
|
+
const ListItem = ({ data, index: index$1, style })=>{
|
5126
|
+
const [triggerRefetchDocument] = index.useLazyGetDocumentQuery();
|
5127
|
+
const { ariaDescribedBy, canDrag = false, disabled = false, handleCancel, handleDisconnect, handleDropItem, handleGrabItem, handleMoveItem, name, relations, targetModel } = data;
|
5128
|
+
const changeDocument = index.useDocumentContext('RelationsList', (state)=>state.changeDocument);
|
5129
|
+
const rootDocumentMeta = index.useDocumentContext('RelationsList', (state)=>state.rootDocumentMeta);
|
5130
|
+
const { formatMessage } = reactIntl.useIntl();
|
5131
|
+
const [isModalOpen, setIsModalOpen] = React__namespace.useState(false);
|
5132
|
+
const { href, id, label, status, documentId, apiData, locale } = relations[index$1];
|
5133
|
+
const [{ handlerId, isDragging, handleKeyDown }, relationRef, dropRef, dragRef, dragPreviewRef] = objects.useDragAndDrop(canDrag && !disabled, {
|
5134
|
+
type: `${objects.ItemTypes.RELATION}_${name}`,
|
5135
|
+
index: index$1,
|
5136
|
+
item: {
|
5137
|
+
displayedValue: label,
|
5138
|
+
status,
|
5139
|
+
id: id,
|
5140
|
+
index: index$1
|
5141
|
+
},
|
5142
|
+
onMoveItem: handleMoveItem,
|
5143
|
+
onDropItem: handleDropItem,
|
5144
|
+
onGrabItem: handleGrabItem,
|
5145
|
+
onCancel: handleCancel,
|
5146
|
+
dropSensitivity: objects.DROP_SENSITIVITY.REGULAR
|
5147
|
+
});
|
5148
|
+
const composedRefs = designSystem.useComposedRefs(relationRef, dragRef);
|
5149
|
+
const handleChangeModalContent = ()=>{
|
5150
|
+
if (changeDocument) {
|
5151
|
+
const newRelation = {
|
5152
|
+
documentId: documentId ?? apiData?.documentId,
|
5153
|
+
model: targetModel,
|
5154
|
+
collectionType: getCollectionType(href),
|
5155
|
+
params: {
|
5156
|
+
locale: locale || null
|
5157
|
+
}
|
5158
|
+
};
|
5159
|
+
changeDocument(newRelation);
|
5160
|
+
}
|
5161
|
+
};
|
5162
|
+
const handleToggleModal = ()=>{
|
5163
|
+
if (isModalOpen) {
|
5164
|
+
setIsModalOpen(false);
|
5165
|
+
const document = {
|
5166
|
+
collectionType: rootDocumentMeta.collectionType,
|
5167
|
+
model: rootDocumentMeta.model,
|
5168
|
+
documentId: rootDocumentMeta.documentId
|
5169
|
+
};
|
5170
|
+
// Change back to the root document
|
5171
|
+
changeDocument(document);
|
5172
|
+
// Read from cache or refetch root document
|
5173
|
+
triggerRefetchDocument(document, // Favor the cache
|
5174
|
+
true);
|
5175
|
+
} else {
|
5176
|
+
setIsModalOpen(true);
|
5177
|
+
}
|
5178
|
+
};
|
5179
|
+
React__namespace.useEffect(()=>{
|
5180
|
+
dragPreviewRef(reactDndHtml5Backend.getEmptyImage());
|
5181
|
+
}, [
|
5182
|
+
dragPreviewRef
|
5183
|
+
]);
|
5184
|
+
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
|
5185
|
+
style: style,
|
5186
|
+
tag: "li",
|
5187
|
+
ref: dropRef,
|
5188
|
+
"aria-describedby": ariaDescribedBy,
|
5189
|
+
cursor: canDrag ? 'all-scroll' : 'default',
|
5190
|
+
children: isDragging ? /*#__PURE__*/ jsxRuntime.jsx(RelationItemPlaceholder, {}) : /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
5191
|
+
paddingTop: 2,
|
5192
|
+
paddingBottom: 2,
|
5193
|
+
paddingLeft: canDrag ? 2 : 4,
|
5194
|
+
paddingRight: 4,
|
5195
|
+
hasRadius: true,
|
5196
|
+
borderColor: "neutral200",
|
5197
|
+
background: disabled ? 'neutral150' : 'neutral0',
|
5198
|
+
justifyContent: "space-between",
|
5199
|
+
ref: composedRefs,
|
5200
|
+
"data-handler-id": handlerId,
|
5201
|
+
children: [
|
5202
|
+
/*#__PURE__*/ jsxRuntime.jsxs(FlexWrapper, {
|
5203
|
+
gap: 1,
|
5204
|
+
children: [
|
5205
|
+
canDrag ? /*#__PURE__*/ jsxRuntime.jsx(designSystem.IconButton, {
|
5206
|
+
tag: "div",
|
5207
|
+
role: "button",
|
5208
|
+
tabIndex: 0,
|
5209
|
+
withTooltip: false,
|
5210
|
+
label: formatMessage({
|
5211
|
+
id: index.getTranslation('components.RelationInput.icon-button-aria-label'),
|
5212
|
+
defaultMessage: 'Drag'
|
5213
|
+
}),
|
5214
|
+
variant: "ghost",
|
5215
|
+
onKeyDown: handleKeyDown,
|
5216
|
+
disabled: disabled,
|
5217
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(Icons.Drag, {})
|
5218
|
+
}) : null,
|
5219
|
+
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
5220
|
+
width: "100%",
|
5221
|
+
minWidth: 0,
|
5222
|
+
justifyContent: "space-between",
|
5223
|
+
children: [
|
5224
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
|
5225
|
+
minWidth: 0,
|
5226
|
+
paddingTop: 1,
|
5227
|
+
paddingBottom: 1,
|
5228
|
+
paddingRight: 4,
|
5229
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Tooltip, {
|
5230
|
+
description: label,
|
5231
|
+
children: isModalOpen ? /*#__PURE__*/ jsxRuntime.jsx(CustomTextButton, {
|
5232
|
+
onClick: handleChangeModalContent,
|
5233
|
+
children: label
|
5234
|
+
}) : /*#__PURE__*/ jsxRuntime.jsx(CustomTextButton, {
|
5235
|
+
onClick: ()=>{
|
5236
|
+
handleChangeModalContent();
|
5237
|
+
setIsModalOpen(true);
|
5238
|
+
},
|
5239
|
+
children: label
|
5240
|
+
})
|
5241
|
+
})
|
5242
|
+
}),
|
5243
|
+
status ? /*#__PURE__*/ jsxRuntime.jsx(index.DocumentStatus, {
|
5244
|
+
status: status
|
5245
|
+
}) : null,
|
5246
|
+
isModalOpen && /*#__PURE__*/ jsxRuntime.jsx(RelationModal, {
|
5247
|
+
open: isModalOpen,
|
5248
|
+
onToggle: handleToggleModal
|
5249
|
+
})
|
5250
|
+
]
|
5251
|
+
})
|
5252
|
+
]
|
5253
|
+
}),
|
5254
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
|
5255
|
+
paddingLeft: 4,
|
5256
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.IconButton, {
|
5257
|
+
onClick: ()=>handleDisconnect(relations[index$1]),
|
5258
|
+
disabled: disabled,
|
5259
|
+
label: formatMessage({
|
5260
|
+
id: index.getTranslation('relation.disconnect'),
|
5261
|
+
defaultMessage: 'Remove'
|
5262
|
+
}),
|
5263
|
+
variant: "ghost",
|
5264
|
+
size: "S",
|
5265
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(Icons.Cross, {})
|
5266
|
+
})
|
5267
|
+
})
|
5268
|
+
]
|
5269
|
+
})
|
5270
|
+
});
|
5271
|
+
};
|
5272
|
+
const FlexWrapper = styledComponents.styled(designSystem.Flex)`
|
5273
|
+
width: 100%;
|
5274
|
+
/* Used to prevent endAction to be pushed out of container */
|
5275
|
+
min-width: 0;
|
5276
|
+
|
5277
|
+
& > div[role='button'] {
|
5278
|
+
cursor: all-scroll;
|
5279
|
+
}
|
5280
|
+
`;
|
5281
|
+
const DisconnectButton = styledComponents.styled.button`
|
5282
|
+
svg path {
|
5283
|
+
fill: ${({ theme, disabled })=>disabled ? theme.colors.neutral600 : theme.colors.neutral500};
|
5284
|
+
}
|
5285
|
+
|
5286
|
+
&:hover svg path,
|
5287
|
+
&:focus svg path {
|
5288
|
+
fill: ${({ theme, disabled })=>!disabled && theme.colors.neutral600};
|
5289
|
+
}
|
5290
|
+
`;
|
5291
|
+
const LinkEllipsis = styledComponents.styled(designSystem.Link)`
|
5292
|
+
display: block;
|
5293
|
+
|
5294
|
+
& > span {
|
5295
|
+
white-space: nowrap;
|
5296
|
+
overflow: hidden;
|
5297
|
+
text-overflow: ellipsis;
|
5298
|
+
display: block;
|
5299
|
+
}
|
5300
|
+
`;
|
5301
|
+
const RelationItemPlaceholder = ()=>/*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
|
5302
|
+
paddingTop: 2,
|
5303
|
+
paddingBottom: 2,
|
5304
|
+
paddingLeft: 4,
|
5305
|
+
paddingRight: 4,
|
5306
|
+
hasRadius: true,
|
5307
|
+
borderStyle: "dashed",
|
5308
|
+
borderColor: "primary600",
|
5309
|
+
borderWidth: "1px",
|
5310
|
+
background: "primary100",
|
5311
|
+
height: `calc(100% - ${RELATION_GUTTER}px)`
|
5312
|
+
});
|
5313
|
+
const MemoizedRelationsField = /*#__PURE__*/ React__namespace.memo(RelationsField);
|
5314
|
+
|
4251
5315
|
const uidApi = index.contentManagerApi.injectEndpoints({
|
4252
5316
|
endpoints: (builder)=>({
|
4253
5317
|
getDefaultUID: builder.query({
|
@@ -4304,7 +5368,7 @@ const UIDInput = /*#__PURE__*/ React__namespace.forwardRef(({ hint, label, label
|
|
4304
5368
|
const [showRegenerate, setShowRegenerate] = React__namespace.useState(false);
|
4305
5369
|
const isCloning = reactRouterDom.useMatch(index.CLONE_PATH) !== null;
|
4306
5370
|
const field = strapiAdmin.useField(name);
|
4307
|
-
const debouncedValue =
|
5371
|
+
const debouncedValue = usePrev.useDebounce(field.value, 300);
|
4308
5372
|
const hasChanged = debouncedValue !== field.initialValue;
|
4309
5373
|
const { toggleNotification } = strapiAdmin.useNotification();
|
4310
5374
|
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
@@ -6416,22 +7480,20 @@ const Wysiwyg = /*#__PURE__*/ React__namespace.forwardRef(({ hint, disabled, lab
|
|
6416
7480
|
});
|
6417
7481
|
const MemoizedWysiwyg = /*#__PURE__*/ React__namespace.memo(Wysiwyg);
|
6418
7482
|
|
6419
|
-
|
6420
|
-
|
6421
|
-
|
6422
|
-
|
6423
|
-
|
6424
|
-
|
6425
|
-
|
6426
|
-
*/ const InputRenderer = ({ visible, hint: providedHint, ...props })=>{
|
6427
|
-
const { id, document, collectionType } = index.useDoc();
|
6428
|
-
const isFormDisabled = strapiAdmin.useForm('InputRenderer', (state)=>state.disabled);
|
7483
|
+
const InputRenderer = ({ visible, hint: providedHint, ...props })=>{
|
7484
|
+
const { id: rootId } = index.useDoc();
|
7485
|
+
const documentMeta = index.useDocumentContext('InputRenderer', (state)=>state.meta);
|
7486
|
+
const documentResponse = index.useDocumentContext('InputRenderer', (state)=>state.document);
|
7487
|
+
const documentLayout = index.useDocumentLayout(documentMeta.model);
|
7488
|
+
const document = documentResponse?.document;
|
7489
|
+
const collectionType = documentMeta.collectionType;
|
6429
7490
|
const isInDynamicZone = useDynamicZone('isInDynamicZone', (state)=>state.isInDynamicZone);
|
7491
|
+
const isFormDisabled = strapiAdmin.useForm('InputRenderer', (state)=>state.disabled);
|
6430
7492
|
const canCreateFields = index.useDocumentRBAC('InputRenderer', (rbac)=>rbac.canCreateFields);
|
6431
7493
|
const canReadFields = index.useDocumentRBAC('InputRenderer', (rbac)=>rbac.canReadFields);
|
6432
7494
|
const canUpdateFields = index.useDocumentRBAC('InputRenderer', (rbac)=>rbac.canUpdateFields);
|
6433
7495
|
const canUserAction = index.useDocumentRBAC('InputRenderer', (rbac)=>rbac.canUserAction);
|
6434
|
-
let idToCheck =
|
7496
|
+
let idToCheck = rootId;
|
6435
7497
|
if (collectionType === index.SINGLE_TYPES) {
|
6436
7498
|
idToCheck = document?.documentId;
|
6437
7499
|
}
|
@@ -6447,7 +7509,8 @@ const MemoizedWysiwyg = /*#__PURE__*/ React__namespace.memo(Wysiwyg);
|
|
6447
7509
|
props.attribute.customField
|
6448
7510
|
] : undefined);
|
6449
7511
|
const hint = useFieldHint(providedHint, props.attribute);
|
6450
|
-
const { edit: { components } } = index.useDocLayout();
|
7512
|
+
const { edit: { components: rootDocumentComponents } } = index.useDocLayout();
|
7513
|
+
const components = Object.keys(rootDocumentComponents).length !== 0 ? rootDocumentComponents : documentLayout.edit.components;
|
6451
7514
|
// We pass field in case of Custom Fields to keep backward compatibility
|
6452
7515
|
const field = strapiAdmin.useField(props.name);
|
6453
7516
|
if (!visible) {
|
@@ -6524,14 +7587,7 @@ const MemoizedWysiwyg = /*#__PURE__*/ React__namespace.memo(Wysiwyg);
|
|
6524
7587
|
disabled: fieldIsDisabled
|
6525
7588
|
});
|
6526
7589
|
case 'relation':
|
6527
|
-
|
6528
|
-
return /*#__PURE__*/ jsxRuntime.jsx(Relations.MemoizedUnstableRelationsField, {
|
6529
|
-
...props,
|
6530
|
-
hint: hint,
|
6531
|
-
disabled: fieldIsDisabled
|
6532
|
-
});
|
6533
|
-
}
|
6534
|
-
return /*#__PURE__*/ jsxRuntime.jsx(Relations.MemoizedRelationsField, {
|
7590
|
+
return /*#__PURE__*/ jsxRuntime.jsx(MemoizedRelationsField, {
|
6535
7591
|
...props,
|
6536
7592
|
hint: hint,
|
6537
7593
|
disabled: fieldIsDisabled
|
@@ -6628,7 +7684,7 @@ const getMinMax = (attribute)=>{
|
|
6628
7684
|
};
|
6629
7685
|
}
|
6630
7686
|
};
|
6631
|
-
const MemoizedInputRenderer = /*#__PURE__*/
|
7687
|
+
const MemoizedInputRenderer = /*#__PURE__*/ React__namespace.memo(InputRenderer);
|
6632
7688
|
|
6633
7689
|
const RESPONSIVE_CONTAINER_BREAKPOINTS = {
|
6634
7690
|
sm: '27.5rem'
|
@@ -6636,16 +7692,21 @@ const RESPONSIVE_CONTAINER_BREAKPOINTS = {
|
|
6636
7692
|
const ResponsiveGridRoot = styledComponents.styled(designSystem.Grid.Root)`
|
6637
7693
|
container-type: inline-size;
|
6638
7694
|
`;
|
6639
|
-
|
6640
|
-
|
6641
|
-
|
6642
|
-
|
6643
|
-
|
6644
|
-
|
6645
|
-
|
6646
|
-
|
7695
|
+
// We need to use a different grid item for the responsive layout in the test environment
|
7696
|
+
// because @container is not supported in jsdom and it throws an error
|
7697
|
+
const ResponsiveGridItem = // TODO: we need to find a better solution to avoid using process.env.NODE_ENV in the code to fix the tests with this styled component
|
7698
|
+
process.env.NODE_ENV !== 'test' ? styledComponents.styled(designSystem.Grid.Item)`
|
7699
|
+
grid-column: span 12;
|
7700
|
+
@container (min-width: ${RESPONSIVE_CONTAINER_BREAKPOINTS.sm}) {
|
7701
|
+
${({ col })=>col && `grid-column: span ${col};`}
|
7702
|
+
}
|
7703
|
+
` : styledComponents.styled(designSystem.Grid.Item)`
|
7704
|
+
grid-column: span 12;
|
7705
|
+
`;
|
7706
|
+
const FormLayout = ({ layout, hasBackground = true })=>{
|
6647
7707
|
const { formatMessage } = reactIntl.useIntl();
|
6648
|
-
const
|
7708
|
+
const documentMeta = index.useDocumentContext('FormLayout', (state)=>state.meta);
|
7709
|
+
const model = documentMeta.model;
|
6649
7710
|
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Flex, {
|
6650
7711
|
direction: "column",
|
6651
7712
|
alignItems: "stretch",
|
@@ -6676,7 +7737,7 @@ const FormLayout = ({ layout, hasBackground = false })=>{
|
|
6676
7737
|
}, field.name);
|
6677
7738
|
}
|
6678
7739
|
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
|
6679
|
-
|
7740
|
+
...hasBackground && {
|
6680
7741
|
padding: 6,
|
6681
7742
|
borderColor: 'neutral150',
|
6682
7743
|
background: 'neutral0',
|
@@ -6718,9 +7779,9 @@ const FormLayout = ({ layout, hasBackground = false })=>{
|
|
6718
7779
|
const NonRepeatableComponent = ({ attribute, name, children, layout })=>{
|
6719
7780
|
const { formatMessage } = reactIntl.useIntl();
|
6720
7781
|
const { value } = strapiAdmin.useField(name);
|
6721
|
-
const level =
|
7782
|
+
const level = useComponent('NonRepeatableComponent', (state)=>state.level);
|
6722
7783
|
const isNested = level > 0;
|
6723
|
-
return /*#__PURE__*/ jsxRuntime.jsx(
|
7784
|
+
return /*#__PURE__*/ jsxRuntime.jsx(ComponentProvider, {
|
6724
7785
|
id: value?.id,
|
6725
7786
|
uid: attribute.component,
|
6726
7787
|
level: level + 1,
|
@@ -6778,7 +7839,7 @@ const RepeatableComponent = ({ attribute, disabled, name, mainField, children, l
|
|
6778
7839
|
const search = React__namespace.useMemo(()=>new URLSearchParams(searchString), [
|
6779
7840
|
searchString
|
6780
7841
|
]);
|
6781
|
-
const
|
7842
|
+
const components = index.useDocumentContext('RepeatableComponent', (state)=>state.document.components);
|
6782
7843
|
const { value = [], error, rawError } = strapiAdmin.useField(name);
|
6783
7844
|
const addFieldRow = strapiAdmin.useForm('RepeatableComponent', (state)=>state.addFieldRow);
|
6784
7845
|
const moveFieldRow = strapiAdmin.useForm('RepeatableComponent', (state)=>state.moveFieldRow);
|
@@ -6906,7 +7967,7 @@ const RepeatableComponent = ({ attribute, disabled, name, mainField, children, l
|
|
6906
7967
|
}));
|
6907
7968
|
};
|
6908
7969
|
const ariaDescriptionId = React__namespace.useId();
|
6909
|
-
const level =
|
7970
|
+
const level = useComponent('RepeatableComponent', (state)=>state.level);
|
6910
7971
|
if (value.length === 0) {
|
6911
7972
|
return /*#__PURE__*/ jsxRuntime.jsx(Initializer, {
|
6912
7973
|
disabled: disabled,
|
@@ -6936,7 +7997,7 @@ const RepeatableComponent = ({ attribute, disabled, name, mainField, children, l
|
|
6936
7997
|
children: [
|
6937
7998
|
value.map(({ __temp_key__: key, id }, index)=>{
|
6938
7999
|
const nameWithIndex = `${name}.${index}`;
|
6939
|
-
return /*#__PURE__*/ jsxRuntime.jsx(
|
8000
|
+
return /*#__PURE__*/ jsxRuntime.jsx(ComponentProvider, {
|
6940
8001
|
// id is always a number in a component
|
6941
8002
|
id: id,
|
6942
8003
|
uid: attribute.component,
|
@@ -7052,8 +8113,8 @@ const Component = ({ disabled, index: index$1, name, mainField = {
|
|
7052
8113
|
* components are not affected by the drag and drop of the parent component in
|
7053
8114
|
* their own re-ordering context.
|
7054
8115
|
*/ const componentKey = name.split('.').slice(0, -1).join('.');
|
7055
|
-
const [{ handlerId, isDragging, handleKeyDown }, boxRef, dropRef, dragRef, dragPreviewRef] =
|
7056
|
-
type: `${
|
8116
|
+
const [{ handlerId, isDragging, handleKeyDown }, boxRef, dropRef, dragRef, dragPreviewRef] = objects.useDragAndDrop(!disabled, {
|
8117
|
+
type: `${objects.ItemTypes.COMPONENT}_${componentKey}`,
|
7057
8118
|
index: index$1,
|
7058
8119
|
item: {
|
7059
8120
|
index: index$1,
|
@@ -7143,7 +8204,7 @@ const ComponentInput = ({ label, required, name, attribute, disabled, labelActio
|
|
7143
8204
|
const { formatMessage } = reactIntl.useIntl();
|
7144
8205
|
const field = strapiAdmin.useField(name);
|
7145
8206
|
const showResetComponent = !attribute.repeatable && field.value && !disabled;
|
7146
|
-
const
|
8207
|
+
const components = index.useDocumentContext('ComponentInput', (state)=>state.document.components);
|
7147
8208
|
const handleInitialisationClick = ()=>{
|
7148
8209
|
const schema = components[attribute.component];
|
7149
8210
|
const form = index.createDefaultForm(schema, components);
|
@@ -7208,8 +8269,11 @@ const ComponentInput = ({ label, required, name, attribute, disabled, labelActio
|
|
7208
8269
|
};
|
7209
8270
|
const MemoizedComponentInput = /*#__PURE__*/ React__namespace.memo(ComponentInput);
|
7210
8271
|
|
8272
|
+
exports.DisconnectButton = DisconnectButton;
|
7211
8273
|
exports.DynamicZone = DynamicZone;
|
8274
|
+
exports.FlexWrapper = FlexWrapper;
|
7212
8275
|
exports.FormLayout = FormLayout;
|
8276
|
+
exports.LinkEllipsis = LinkEllipsis;
|
7213
8277
|
exports.MemoizedBlocksInput = MemoizedBlocksInput;
|
7214
8278
|
exports.MemoizedComponentInput = MemoizedComponentInput;
|
7215
8279
|
exports.MemoizedUIDInput = MemoizedUIDInput;
|
@@ -7218,4 +8282,4 @@ exports.NotAllowedInput = NotAllowedInput;
|
|
7218
8282
|
exports.useDynamicZone = useDynamicZone;
|
7219
8283
|
exports.useFieldHint = useFieldHint;
|
7220
8284
|
exports.useLazyComponents = useLazyComponents;
|
7221
|
-
//# sourceMappingURL=Input-
|
8285
|
+
//# sourceMappingURL=Input-BJCenRYN.js.map
|