@strapi/content-type-builder 5.9.0 → 5.10.1
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/ListView-CDnrvVrV.mjs +1184 -0
- package/dist/admin/chunks/ListView-CDnrvVrV.mjs.map +1 -0
- package/dist/admin/chunks/ListView-CQwvSbZH.js +1186 -0
- package/dist/admin/chunks/ListView-CQwvSbZH.js.map +1 -0
- package/dist/admin/chunks/ar-Df0f0-PT.js +52 -0
- package/dist/admin/chunks/ar-Df0f0-PT.js.map +1 -0
- package/dist/admin/chunks/ar-sRW9VFC-.mjs +49 -0
- package/dist/admin/chunks/ar-sRW9VFC-.mjs.map +1 -0
- package/dist/admin/chunks/cs-BpQ26jiq.mjs +136 -0
- package/dist/{_chunks/cs-ChL4LaFY.mjs.map → admin/chunks/cs-BpQ26jiq.mjs.map} +1 -1
- package/dist/admin/chunks/cs-DeTwqc7p.js +140 -0
- package/dist/{_chunks/cs-Ci3js5EC.js.map → admin/chunks/cs-DeTwqc7p.js.map} +1 -1
- package/dist/admin/chunks/de-BJkS06jF.js +194 -0
- package/dist/{_chunks/de-DnlblIOh.js.map → admin/chunks/de-BJkS06jF.js.map} +1 -1
- package/dist/admin/chunks/de-DSxx5_x-.mjs +190 -0
- package/dist/{_chunks/de-DsHQNzp2.mjs.map → admin/chunks/de-DSxx5_x-.mjs.map} +1 -1
- package/dist/admin/chunks/dk-BnjVZ7A_.mjs +180 -0
- package/dist/{_chunks/es-BE_zx2_w.mjs.map → admin/chunks/dk-BnjVZ7A_.mjs.map} +1 -1
- package/dist/admin/chunks/dk-CGm-qVH7.js +184 -0
- package/dist/{_chunks/dk-D3XnOjYz.js.map → admin/chunks/dk-CGm-qVH7.js.map} +1 -1
- package/dist/admin/chunks/en-BJUu34b0.js +217 -0
- package/dist/{_chunks/en-CXG5y_vo.js.map → admin/chunks/en-BJUu34b0.js.map} +1 -1
- package/dist/admin/chunks/en-Bhut8Yay.mjs +213 -0
- package/dist/{_chunks/en-jBwb53yg.mjs.map → admin/chunks/en-Bhut8Yay.mjs.map} +1 -1
- package/dist/admin/chunks/es-DG8g9igJ.mjs +180 -0
- package/dist/admin/chunks/es-DG8g9igJ.mjs.map +1 -0
- package/dist/admin/chunks/es-J8kvHlNy.js +184 -0
- package/dist/{_chunks/es-DL8lez9W.js.map → admin/chunks/es-J8kvHlNy.js.map} +1 -1
- package/dist/admin/chunks/fr-C6y35iY7.js +76 -0
- package/dist/admin/chunks/fr-C6y35iY7.js.map +1 -0
- package/dist/admin/chunks/fr-UpV34MHY.mjs +73 -0
- package/dist/admin/chunks/fr-UpV34MHY.mjs.map +1 -0
- package/dist/admin/chunks/id-BWM18ljw.mjs +163 -0
- package/dist/{_chunks/ru-DGSjru5m.mjs.map → admin/chunks/id-BWM18ljw.mjs.map} +1 -1
- package/dist/admin/chunks/id-BvxV6wLP.js +167 -0
- package/dist/{_chunks/ru-C8A_4j0w.js.map → admin/chunks/id-BvxV6wLP.js.map} +1 -1
- package/dist/admin/chunks/index-BQ2VO38W.js +7781 -0
- package/dist/admin/chunks/index-BQ2VO38W.js.map +1 -0
- package/dist/admin/chunks/index-BZeN5KRn.js +1421 -0
- package/dist/admin/chunks/index-BZeN5KRn.js.map +1 -0
- package/dist/admin/chunks/index-BhX2euW0.mjs +1384 -0
- package/dist/admin/chunks/index-BhX2euW0.mjs.map +1 -0
- package/dist/admin/chunks/index-Cr5tfW7U.mjs +7754 -0
- package/dist/admin/chunks/index-Cr5tfW7U.mjs.map +1 -0
- package/dist/admin/chunks/it-1_vd9gV4.mjs +164 -0
- package/dist/{_chunks/tr-DsUerr-c.mjs.map → admin/chunks/it-1_vd9gV4.mjs.map} +1 -1
- package/dist/admin/chunks/it-C_IgFU-G.js +168 -0
- package/dist/{_chunks/sk-raWRcmPT.js.map → admin/chunks/it-C_IgFU-G.js.map} +1 -1
- package/dist/admin/chunks/ja-CWo4Qqq6.js +51 -0
- package/dist/admin/chunks/ja-CWo4Qqq6.js.map +1 -0
- package/dist/admin/chunks/ja-Cx23a2Ui.mjs +48 -0
- package/dist/admin/chunks/ja-Cx23a2Ui.mjs.map +1 -0
- package/dist/admin/chunks/ko-BsByJNEl.js +184 -0
- package/dist/admin/chunks/ko-BsByJNEl.js.map +1 -0
- package/dist/admin/chunks/ko-DC7paEx5.mjs +180 -0
- package/dist/admin/chunks/ko-DC7paEx5.mjs.map +1 -0
- package/dist/admin/chunks/ms-C3s4kxq6.mjs +160 -0
- package/dist/{_chunks/id-W1sKBFEw.mjs.map → admin/chunks/ms-C3s4kxq6.mjs.map} +1 -1
- package/dist/admin/chunks/ms-DPTzS7SH.js +164 -0
- package/dist/{_chunks/th-C83Bb_kR.js.map → admin/chunks/ms-DPTzS7SH.js.map} +1 -1
- package/dist/admin/chunks/nl-TzvfktV_.mjs +153 -0
- package/dist/{_chunks/nl-BaTAuelQ.mjs.map → admin/chunks/nl-TzvfktV_.mjs.map} +1 -1
- package/dist/admin/chunks/nl-db29QMOx.js +157 -0
- package/dist/{_chunks/nl-DQjrDEw0.js.map → admin/chunks/nl-db29QMOx.js.map} +1 -1
- package/dist/admin/chunks/pl-BdvupIN_.mjs +190 -0
- package/dist/admin/chunks/pl-BdvupIN_.mjs.map +1 -0
- package/dist/admin/chunks/pl-pYy1djj3.js +194 -0
- package/dist/admin/chunks/pl-pYy1djj3.js.map +1 -0
- package/dist/admin/chunks/pt-BQmWcdeG.js +52 -0
- package/dist/admin/chunks/pt-BQmWcdeG.js.map +1 -0
- package/dist/admin/chunks/pt-BR-CTPuXGWF.js +194 -0
- package/dist/{_chunks/pt-BR-DPd5nRnl.js.map → admin/chunks/pt-BR-CTPuXGWF.js.map} +1 -1
- package/dist/admin/chunks/pt-BR-DPrVmKeZ.mjs +190 -0
- package/dist/{_chunks/pt-BR-CCQGwXs0.mjs.map → admin/chunks/pt-BR-DPrVmKeZ.mjs.map} +1 -1
- package/dist/admin/chunks/pt-BTLIwmCv.mjs +49 -0
- package/dist/admin/chunks/pt-BTLIwmCv.mjs.map +1 -0
- package/dist/admin/chunks/ru-D46no502.mjs +165 -0
- package/dist/{_chunks/dk-BC7NAQR2.mjs.map → admin/chunks/ru-D46no502.mjs.map} +1 -1
- package/dist/admin/chunks/ru-DQiDXgUV.js +169 -0
- package/dist/admin/chunks/ru-DQiDXgUV.js.map +1 -0
- package/dist/admin/chunks/sk-Byr_l4Jc.mjs +164 -0
- package/dist/{_chunks/ko-DoNsXHXA.mjs.map → admin/chunks/sk-Byr_l4Jc.mjs.map} +1 -1
- package/dist/admin/chunks/sk-DrnebmXb.js +168 -0
- package/dist/{_chunks/it-DS4sM3km.js.map → admin/chunks/sk-DrnebmXb.js.map} +1 -1
- package/dist/admin/chunks/sv-Bbam7IDm.mjs +199 -0
- package/dist/admin/chunks/sv-Bbam7IDm.mjs.map +1 -0
- package/dist/admin/chunks/sv-CrWlNosi.js +203 -0
- package/dist/admin/chunks/sv-CrWlNosi.js.map +1 -0
- package/dist/admin/chunks/th-BbrCkfgX.js +165 -0
- package/dist/{_chunks/id-DYuTgqcc.js.map → admin/chunks/th-BbrCkfgX.js.map} +1 -1
- package/dist/admin/chunks/th-hfS0Wmk_.mjs +161 -0
- package/dist/{_chunks/it-D04lb2Wc.mjs.map → admin/chunks/th-hfS0Wmk_.mjs.map} +1 -1
- package/dist/admin/chunks/tr-CHdMj8m6.js +180 -0
- package/dist/admin/chunks/tr-CHdMj8m6.js.map +1 -0
- package/dist/admin/chunks/tr-DS7DBOhC.mjs +176 -0
- package/dist/admin/chunks/tr-DS7DBOhC.mjs.map +1 -0
- package/dist/admin/chunks/uk-BQEQ3weH.js +165 -0
- package/dist/{_chunks/uk-VwB0oiuV.js.map → admin/chunks/uk-BQEQ3weH.js.map} +1 -1
- package/dist/admin/chunks/uk-Cj8-BKeu.mjs +161 -0
- package/dist/{_chunks/sk-DVK4HfSC.mjs.map → admin/chunks/uk-Cj8-BKeu.mjs.map} +1 -1
- package/dist/admin/chunks/zh-BUVXH75-.mjs +199 -0
- package/dist/admin/chunks/zh-BUVXH75-.mjs.map +1 -0
- package/dist/admin/chunks/zh-CWj4avQA.js +203 -0
- package/dist/admin/chunks/zh-CWj4avQA.js.map +1 -0
- package/dist/admin/chunks/zh-Hans-BElOnuRb.mjs +144 -0
- package/dist/{_chunks/zh-Hans-Cc0M5PXr.mjs.map → admin/chunks/zh-Hans-BElOnuRb.mjs.map} +1 -1
- package/dist/admin/chunks/zh-Hans-lXbNiMp9.js +148 -0
- package/dist/{_chunks/zh-Hans-CLTLm_nt.js.map → admin/chunks/zh-Hans-lXbNiMp9.js.map} +1 -1
- package/dist/admin/index.js +24 -4
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +17 -7
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/src/components/ContentTypeBuilderNav/useContentTypeBuilderMenu.d.ts +5 -2
- package/dist/admin/src/components/DataManagerProvider/reducer.d.ts +97 -6
- package/dist/admin/src/components/FormModal/reducer.d.ts +110 -4
- package/dist/admin/src/components/ListRow.d.ts +2 -1
- package/dist/admin/src/contexts/DataManagerContext.d.ts +4 -4
- package/dist/admin/src/index.d.ts +2 -1
- package/dist/admin/src/pages/ListView/LinkToCMSettingsView.d.ts +1 -2
- package/dist/admin/src/pluginId.d.ts +1 -1
- package/dist/admin/src/reducers.d.ts +8 -1
- package/dist/admin/src/types.d.ts +2 -5
- package/dist/server/index.js +2504 -2151
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +2500 -2147
- package/dist/server/index.mjs.map +1 -1
- package/package.json +13 -10
- package/dist/_chunks/ListView-B7k6NgwS.mjs +0 -959
- package/dist/_chunks/ListView-B7k6NgwS.mjs.map +0 -1
- package/dist/_chunks/ListView-CsRxS9zZ.js +0 -964
- package/dist/_chunks/ListView-CsRxS9zZ.js.map +0 -1
- package/dist/_chunks/ar-BYDB75EB.mjs +0 -51
- package/dist/_chunks/ar-BYDB75EB.mjs.map +0 -1
- package/dist/_chunks/ar-OCxhAFUy.js +0 -51
- package/dist/_chunks/ar-OCxhAFUy.js.map +0 -1
- package/dist/_chunks/cs-ChL4LaFY.mjs +0 -139
- package/dist/_chunks/cs-Ci3js5EC.js +0 -139
- package/dist/_chunks/de-DnlblIOh.js +0 -193
- package/dist/_chunks/de-DsHQNzp2.mjs +0 -193
- package/dist/_chunks/dk-BC7NAQR2.mjs +0 -183
- package/dist/_chunks/dk-D3XnOjYz.js +0 -183
- package/dist/_chunks/en-CXG5y_vo.js +0 -216
- package/dist/_chunks/en-jBwb53yg.mjs +0 -216
- package/dist/_chunks/es-BE_zx2_w.mjs +0 -183
- package/dist/_chunks/es-DL8lez9W.js +0 -183
- package/dist/_chunks/fr-DnTxugIo.js +0 -75
- package/dist/_chunks/fr-DnTxugIo.js.map +0 -1
- package/dist/_chunks/fr-lU_OMJma.mjs +0 -75
- package/dist/_chunks/fr-lU_OMJma.mjs.map +0 -1
- package/dist/_chunks/id-DYuTgqcc.js +0 -166
- package/dist/_chunks/id-W1sKBFEw.mjs +0 -166
- package/dist/_chunks/index-97hm9i_H.mjs +0 -1331
- package/dist/_chunks/index-97hm9i_H.mjs.map +0 -1
- package/dist/_chunks/index-B5tHY87r.mjs +0 -6694
- package/dist/_chunks/index-B5tHY87r.mjs.map +0 -1
- package/dist/_chunks/index-BgMd59JL.js +0 -6730
- package/dist/_chunks/index-BgMd59JL.js.map +0 -1
- package/dist/_chunks/index-Cr85ijm8.js +0 -1357
- package/dist/_chunks/index-Cr85ijm8.js.map +0 -1
- package/dist/_chunks/it-D04lb2Wc.mjs +0 -167
- package/dist/_chunks/it-DS4sM3km.js +0 -167
- package/dist/_chunks/ja-BHLK_2_g.mjs +0 -50
- package/dist/_chunks/ja-BHLK_2_g.mjs.map +0 -1
- package/dist/_chunks/ja-BjouJgZf.js +0 -50
- package/dist/_chunks/ja-BjouJgZf.js.map +0 -1
- package/dist/_chunks/ko-D_71Pdfn.js +0 -183
- package/dist/_chunks/ko-D_71Pdfn.js.map +0 -1
- package/dist/_chunks/ko-DoNsXHXA.mjs +0 -183
- package/dist/_chunks/ms-BtGFDB9t.mjs +0 -163
- package/dist/_chunks/ms-BtGFDB9t.mjs.map +0 -1
- package/dist/_chunks/ms-Re1pSHmx.js +0 -163
- package/dist/_chunks/ms-Re1pSHmx.js.map +0 -1
- package/dist/_chunks/nl-BaTAuelQ.mjs +0 -156
- package/dist/_chunks/nl-DQjrDEw0.js +0 -156
- package/dist/_chunks/pl-BGwXgwH7.js +0 -193
- package/dist/_chunks/pl-BGwXgwH7.js.map +0 -1
- package/dist/_chunks/pl-CP2Zgp01.mjs +0 -193
- package/dist/_chunks/pl-CP2Zgp01.mjs.map +0 -1
- package/dist/_chunks/pt-BR-CCQGwXs0.mjs +0 -193
- package/dist/_chunks/pt-BR-DPd5nRnl.js +0 -193
- package/dist/_chunks/pt-CJoUDTHQ.js +0 -51
- package/dist/_chunks/pt-CJoUDTHQ.js.map +0 -1
- package/dist/_chunks/pt-DMeTMW2x.mjs +0 -51
- package/dist/_chunks/pt-DMeTMW2x.mjs.map +0 -1
- package/dist/_chunks/ru-C8A_4j0w.js +0 -168
- package/dist/_chunks/ru-DGSjru5m.mjs +0 -168
- package/dist/_chunks/sk-DVK4HfSC.mjs +0 -167
- package/dist/_chunks/sk-raWRcmPT.js +0 -167
- package/dist/_chunks/sv-BGb12eW3.mjs +0 -202
- package/dist/_chunks/sv-BGb12eW3.mjs.map +0 -1
- package/dist/_chunks/sv-BNN71SFE.js +0 -202
- package/dist/_chunks/sv-BNN71SFE.js.map +0 -1
- package/dist/_chunks/th--u3VqsON.mjs +0 -164
- package/dist/_chunks/th--u3VqsON.mjs.map +0 -1
- package/dist/_chunks/th-C83Bb_kR.js +0 -164
- package/dist/_chunks/tr-BW20CfcO.js +0 -179
- package/dist/_chunks/tr-BW20CfcO.js.map +0 -1
- package/dist/_chunks/tr-DsUerr-c.mjs +0 -179
- package/dist/_chunks/uk-Bx5IlOKX.mjs +0 -164
- package/dist/_chunks/uk-Bx5IlOKX.mjs.map +0 -1
- package/dist/_chunks/uk-VwB0oiuV.js +0 -164
- package/dist/_chunks/zh-BiOCwPJu.js +0 -202
- package/dist/_chunks/zh-BiOCwPJu.js.map +0 -1
- package/dist/_chunks/zh-CsUDN13W.mjs +0 -202
- package/dist/_chunks/zh-CsUDN13W.mjs.map +0 -1
- package/dist/_chunks/zh-Hans-CLTLm_nt.js +0 -147
- package/dist/_chunks/zh-Hans-Cc0M5PXr.mjs +0 -147
- package/dist/admin/src/components/DataManagerProvider/constants.d.ts +0 -17
- package/dist/admin/src/components/FormModal/constants.d.ts +0 -12
- package/dist/admin/src/pages/RecursivePath/RecursivePath.d.ts +0 -1
|
@@ -0,0 +1,1421 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Icons = require('@strapi/icons');
|
|
4
|
+
var toolkit = require('@reduxjs/toolkit');
|
|
5
|
+
var immer = require('immer');
|
|
6
|
+
var get = require('lodash/get');
|
|
7
|
+
var set = require('lodash/set');
|
|
8
|
+
var snakeCase = require('lodash/snakeCase');
|
|
9
|
+
var pluralize = require('pluralize');
|
|
10
|
+
var slugify = require('@sindresorhus/slugify');
|
|
11
|
+
var cloneDeep = require('lodash/cloneDeep');
|
|
12
|
+
var yup = require('yup');
|
|
13
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
14
|
+
var React = require('react');
|
|
15
|
+
var designSystem = require('@strapi/design-system');
|
|
16
|
+
var reactDom = require('react-dom');
|
|
17
|
+
var reactIntl = require('react-intl');
|
|
18
|
+
var styledComponents = require('styled-components');
|
|
19
|
+
|
|
20
|
+
function _interopNamespaceDefault(e) {
|
|
21
|
+
var n = Object.create(null);
|
|
22
|
+
if (e) {
|
|
23
|
+
Object.keys(e).forEach(function (k) {
|
|
24
|
+
if (k !== 'default') {
|
|
25
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
26
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () { return e[k]; }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
n.default = e;
|
|
34
|
+
return Object.freeze(n);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var yup__namespace = /*#__PURE__*/_interopNamespaceDefault(yup);
|
|
38
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
39
|
+
|
|
40
|
+
const PERMISSIONS = {
|
|
41
|
+
// This permission regards the main component (App) and is used to tell
|
|
42
|
+
// If the plugin link should be displayed in the menu
|
|
43
|
+
// And also if the plugin is accessible. This use case is found when a user types the url of the
|
|
44
|
+
// plugin directly in the browser
|
|
45
|
+
main: [
|
|
46
|
+
{
|
|
47
|
+
action: 'plugin::content-type-builder.read',
|
|
48
|
+
subject: null
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
const MAX_COMPONENT_DEPTH = 6;
|
|
53
|
+
|
|
54
|
+
const pluginId = 'content-type-builder';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* Retrieves the relation type
|
|
59
|
+
*/ const getRelationType = (relation, targetAttribute)=>{
|
|
60
|
+
const hasNotTargetAttribute = targetAttribute === undefined || targetAttribute === null;
|
|
61
|
+
if (relation === 'oneToOne' && hasNotTargetAttribute) {
|
|
62
|
+
return 'oneWay';
|
|
63
|
+
}
|
|
64
|
+
if (relation === 'oneToMany' && hasNotTargetAttribute) {
|
|
65
|
+
return 'manyWay';
|
|
66
|
+
}
|
|
67
|
+
return relation;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const makeUnique = (array)=>[
|
|
71
|
+
...new Set(array)
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
const retrieveComponentsFromSchema = (attributes, allComponentsData)=>{
|
|
75
|
+
const allComponents = attributes.reduce((acc, current)=>{
|
|
76
|
+
const type = current.type;
|
|
77
|
+
if (type === 'component') {
|
|
78
|
+
const currentComponentName = current.component;
|
|
79
|
+
// Push the existing compo
|
|
80
|
+
acc.push(currentComponentName);
|
|
81
|
+
const currentComponentAttributes = get(allComponentsData, [
|
|
82
|
+
currentComponentName,
|
|
83
|
+
'schema',
|
|
84
|
+
'attributes'
|
|
85
|
+
], []);
|
|
86
|
+
// Retrieve the nested ones
|
|
87
|
+
acc.push(...retrieveComponentsFromSchema(currentComponentAttributes, allComponentsData));
|
|
88
|
+
}
|
|
89
|
+
if (type === 'dynamiczone') {
|
|
90
|
+
const dynamicZoneComponents = current.components;
|
|
91
|
+
const componentsFromDZComponents = dynamicZoneComponents.reduce((acc2, currentUid)=>{
|
|
92
|
+
const compoAttrs = get(allComponentsData, [
|
|
93
|
+
currentUid,
|
|
94
|
+
'schema',
|
|
95
|
+
'attributes'
|
|
96
|
+
], []);
|
|
97
|
+
return [
|
|
98
|
+
...acc2,
|
|
99
|
+
...retrieveComponentsFromSchema(compoAttrs, allComponentsData)
|
|
100
|
+
];
|
|
101
|
+
}, []);
|
|
102
|
+
return [
|
|
103
|
+
...acc,
|
|
104
|
+
...dynamicZoneComponents,
|
|
105
|
+
...componentsFromDZComponents
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
return acc;
|
|
109
|
+
}, []);
|
|
110
|
+
return makeUnique(allComponents);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const DEFAULT_MODIFIED_DATA = {
|
|
114
|
+
components: {},
|
|
115
|
+
contentTypes: {}
|
|
116
|
+
};
|
|
117
|
+
const initialState$1 = {
|
|
118
|
+
components: {},
|
|
119
|
+
contentTypes: {},
|
|
120
|
+
initialComponents: {},
|
|
121
|
+
initialContentTypes: {},
|
|
122
|
+
initialData: {},
|
|
123
|
+
modifiedData: {
|
|
124
|
+
...DEFAULT_MODIFIED_DATA
|
|
125
|
+
},
|
|
126
|
+
reservedNames: {},
|
|
127
|
+
isLoading: true
|
|
128
|
+
};
|
|
129
|
+
const ONE_SIDE_RELATIONS = [
|
|
130
|
+
'oneWay',
|
|
131
|
+
'manyWay'
|
|
132
|
+
];
|
|
133
|
+
const getOppositeRelation = (originalRelation)=>{
|
|
134
|
+
if (originalRelation === 'manyToOne') {
|
|
135
|
+
return 'oneToMany';
|
|
136
|
+
}
|
|
137
|
+
if (originalRelation === 'oneToMany') {
|
|
138
|
+
return 'manyToOne';
|
|
139
|
+
}
|
|
140
|
+
return originalRelation;
|
|
141
|
+
};
|
|
142
|
+
const findAttributeIndex = (schema, attributeToFind)=>{
|
|
143
|
+
return schema.schema.attributes.findIndex(({ name })=>name === attributeToFind);
|
|
144
|
+
};
|
|
145
|
+
const slice$1 = toolkit.createSlice({
|
|
146
|
+
name: 'data-manager',
|
|
147
|
+
initialState: initialState$1,
|
|
148
|
+
reducers: {
|
|
149
|
+
init: (state, action)=>{
|
|
150
|
+
const { components, contentTypes, reservedNames } = action.payload;
|
|
151
|
+
state.components = components;
|
|
152
|
+
state.initialComponents = components;
|
|
153
|
+
state.initialContentTypes = contentTypes;
|
|
154
|
+
state.contentTypes = contentTypes;
|
|
155
|
+
state.reservedNames = reservedNames;
|
|
156
|
+
state.isLoading = false;
|
|
157
|
+
state.modifiedData = {
|
|
158
|
+
...DEFAULT_MODIFIED_DATA,
|
|
159
|
+
component: state.modifiedData.component ? components[state.modifiedData.component.uid] : undefined,
|
|
160
|
+
contentType: state.modifiedData.contentType ? contentTypes[state.modifiedData.contentType.uid] : undefined,
|
|
161
|
+
components: state.modifiedData.components ? Object.keys(state.modifiedData.components).reduce((acc, key)=>{
|
|
162
|
+
acc[key] = components[key];
|
|
163
|
+
return acc;
|
|
164
|
+
}, {}) : {},
|
|
165
|
+
contentTypes: state.modifiedData.contentTypes ? Object.keys(state.modifiedData.contentTypes).reduce((acc, key)=>{
|
|
166
|
+
acc[key] = contentTypes[key];
|
|
167
|
+
return acc;
|
|
168
|
+
}, {}) : {}
|
|
169
|
+
};
|
|
170
|
+
state.initialData = state.modifiedData;
|
|
171
|
+
},
|
|
172
|
+
addAttribute: (state, action)=>{
|
|
173
|
+
const { attributeToSet, forTarget, targetUid, shouldAddComponentToData } = action.payload;
|
|
174
|
+
const { name, ...rest } = attributeToSet;
|
|
175
|
+
delete rest.createComponent;
|
|
176
|
+
const pathToDataToEdit = [
|
|
177
|
+
'component',
|
|
178
|
+
'contentType'
|
|
179
|
+
].includes(forTarget) ? [
|
|
180
|
+
forTarget
|
|
181
|
+
] : [
|
|
182
|
+
forTarget,
|
|
183
|
+
targetUid
|
|
184
|
+
];
|
|
185
|
+
const currentAttributes = get(state, [
|
|
186
|
+
'modifiedData',
|
|
187
|
+
...pathToDataToEdit,
|
|
188
|
+
'schema',
|
|
189
|
+
'attributes'
|
|
190
|
+
], []).slice();
|
|
191
|
+
// Add the createdAttribute
|
|
192
|
+
const updatedAttributes = [
|
|
193
|
+
...currentAttributes,
|
|
194
|
+
{
|
|
195
|
+
...rest,
|
|
196
|
+
name
|
|
197
|
+
}
|
|
198
|
+
];
|
|
199
|
+
set(state, [
|
|
200
|
+
'modifiedData',
|
|
201
|
+
...pathToDataToEdit,
|
|
202
|
+
'schema',
|
|
203
|
+
'attributes'
|
|
204
|
+
], updatedAttributes);
|
|
205
|
+
if (shouldAddComponentToData) {
|
|
206
|
+
const componentToAddUID = rest.component;
|
|
207
|
+
const componentToAdd = state.components[componentToAddUID];
|
|
208
|
+
const isTemporaryComponent = componentToAdd?.isTemporary;
|
|
209
|
+
const hasComponentAlreadyBeenAdded = state.modifiedData.components?.[componentToAddUID] !== undefined;
|
|
210
|
+
if (isTemporaryComponent || hasComponentAlreadyBeenAdded) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// Initialize modifiedData.components if it is undefined
|
|
214
|
+
if (!state.modifiedData.components) {
|
|
215
|
+
state.modifiedData.components = {};
|
|
216
|
+
}
|
|
217
|
+
// Add the added component to the modifiedData.components
|
|
218
|
+
state.modifiedData.components[componentToAddUID] = componentToAdd;
|
|
219
|
+
const nestedComponents = retrieveComponentsFromSchema(componentToAdd.schema.attributes, state.components);
|
|
220
|
+
// We dont' need to set the already added components otherwise all modifications will be lost so we need to only add the not modified ones
|
|
221
|
+
const nestedComponentsToAddInModifiedData = nestedComponents.filter((compoUID)=>{
|
|
222
|
+
return get(state, [
|
|
223
|
+
'modifiedData',
|
|
224
|
+
'components',
|
|
225
|
+
compoUID
|
|
226
|
+
]) === undefined;
|
|
227
|
+
});
|
|
228
|
+
nestedComponentsToAddInModifiedData.forEach((compoUID)=>{
|
|
229
|
+
const compoSchema = get(state, [
|
|
230
|
+
'components',
|
|
231
|
+
compoUID
|
|
232
|
+
], {});
|
|
233
|
+
const isTemporary = compoSchema.isTemporary || false;
|
|
234
|
+
// If the nested component has not been saved we don't need to add them as they are already in the state
|
|
235
|
+
if (!isTemporary) {
|
|
236
|
+
if (!state.modifiedData.components) {
|
|
237
|
+
state.modifiedData.components = {};
|
|
238
|
+
}
|
|
239
|
+
state.modifiedData.components[compoUID] = compoSchema;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const isCreatingRelationAttribute = rest.type === 'relation';
|
|
245
|
+
if (isCreatingRelationAttribute) {
|
|
246
|
+
const target = rest.target;
|
|
247
|
+
const targetAttribute = rest.targetAttribute || null;
|
|
248
|
+
const relation = rest.relation;
|
|
249
|
+
const relationType = getRelationType(relation, targetAttribute);
|
|
250
|
+
const currentUid = get(state, [
|
|
251
|
+
'modifiedData',
|
|
252
|
+
...pathToDataToEdit,
|
|
253
|
+
'uid'
|
|
254
|
+
]);
|
|
255
|
+
// When the user in creating a relation with the same content type we need to create another attribute
|
|
256
|
+
// that is the opposite of the created one
|
|
257
|
+
if (rest.type === 'relation' && relationType !== 'oneWay' && relationType !== 'manyWay' && target === currentUid) {
|
|
258
|
+
const oppositeAttribute = {
|
|
259
|
+
name: targetAttribute,
|
|
260
|
+
relation: getOppositeRelation(relationType),
|
|
261
|
+
target,
|
|
262
|
+
targetAttribute: name,
|
|
263
|
+
type: 'relation'
|
|
264
|
+
};
|
|
265
|
+
if (rest.private) {
|
|
266
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
267
|
+
oppositeAttribute.private = rest.private;
|
|
268
|
+
}
|
|
269
|
+
const attributesToSet = [
|
|
270
|
+
...updatedAttributes,
|
|
271
|
+
oppositeAttribute
|
|
272
|
+
];
|
|
273
|
+
set(state, [
|
|
274
|
+
'modifiedData',
|
|
275
|
+
...pathToDataToEdit,
|
|
276
|
+
'schema',
|
|
277
|
+
'attributes'
|
|
278
|
+
], attributesToSet);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
addCreatedComponentToDynamicZone: (state, action)=>{
|
|
283
|
+
const { dynamicZoneTarget, componentsToAdd } = action.payload;
|
|
284
|
+
const dzAttributeIndex = findAttributeIndex(state.modifiedData.contentType, dynamicZoneTarget);
|
|
285
|
+
componentsToAdd.forEach((componentUid)=>{
|
|
286
|
+
if (!state.modifiedData.contentType) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (!state.modifiedData.contentType.schema.attributes[dzAttributeIndex].components) {
|
|
290
|
+
state.modifiedData.contentType.schema.attributes[dzAttributeIndex].components = [];
|
|
291
|
+
}
|
|
292
|
+
state.modifiedData.contentType.schema.attributes[dzAttributeIndex].components.push(componentUid);
|
|
293
|
+
});
|
|
294
|
+
},
|
|
295
|
+
addCustomFieldAttribute: (state, action)=>{
|
|
296
|
+
const { attributeToSet, forTarget, targetUid } = action.payload;
|
|
297
|
+
const { name, ...rest } = attributeToSet;
|
|
298
|
+
const pathToDataToEdit = [
|
|
299
|
+
'component',
|
|
300
|
+
'contentType'
|
|
301
|
+
].includes(forTarget) ? [
|
|
302
|
+
forTarget
|
|
303
|
+
] : [
|
|
304
|
+
forTarget,
|
|
305
|
+
targetUid
|
|
306
|
+
];
|
|
307
|
+
const currentAttributes = get(state, [
|
|
308
|
+
'modifiedData',
|
|
309
|
+
...pathToDataToEdit,
|
|
310
|
+
'schema',
|
|
311
|
+
'attributes'
|
|
312
|
+
], []).slice();
|
|
313
|
+
// Add the createdAttribute
|
|
314
|
+
const updatedAttributes = [
|
|
315
|
+
...currentAttributes,
|
|
316
|
+
{
|
|
317
|
+
...rest,
|
|
318
|
+
name
|
|
319
|
+
}
|
|
320
|
+
];
|
|
321
|
+
set(state, [
|
|
322
|
+
'modifiedData',
|
|
323
|
+
...pathToDataToEdit,
|
|
324
|
+
'schema',
|
|
325
|
+
'attributes'
|
|
326
|
+
], updatedAttributes);
|
|
327
|
+
},
|
|
328
|
+
changeDynamicZoneComponents: (state, action)=>{
|
|
329
|
+
const { dynamicZoneTarget, newComponents } = action.payload;
|
|
330
|
+
const dzAttributeIndex = findAttributeIndex(state.modifiedData.contentType, dynamicZoneTarget);
|
|
331
|
+
const currentDZComponents = (state.modifiedData.contentType?.schema.attributes[dzAttributeIndex]).components;
|
|
332
|
+
const updatedComponents = makeUnique([
|
|
333
|
+
...currentDZComponents,
|
|
334
|
+
...newComponents
|
|
335
|
+
]);
|
|
336
|
+
(state.modifiedData.contentType?.schema.attributes[dzAttributeIndex]).components = updatedComponents;
|
|
337
|
+
// Retrieve all the components that needs to be added to the modifiedData.components
|
|
338
|
+
const nestedComponents = retrieveComponentsFromSchema(immer.current(state.modifiedData.contentType?.schema.attributes), state.components);
|
|
339
|
+
// We dont' need to set the already added components otherwise all modifications will be lost so we need to only add the not modified ones
|
|
340
|
+
const nestedComponentsToAddInModifiedData = nestedComponents.filter((compoUID)=>{
|
|
341
|
+
return get(state, [
|
|
342
|
+
'modifiedData',
|
|
343
|
+
'components',
|
|
344
|
+
compoUID
|
|
345
|
+
]) === undefined;
|
|
346
|
+
});
|
|
347
|
+
nestedComponentsToAddInModifiedData.forEach((compoUID)=>{
|
|
348
|
+
const compoSchema = get(state, [
|
|
349
|
+
'components',
|
|
350
|
+
compoUID
|
|
351
|
+
], {});
|
|
352
|
+
const isTemporary = compoSchema.isTemporary || false;
|
|
353
|
+
// If the nested component has not been saved we don't need to add them as they are already in the state
|
|
354
|
+
if (!isTemporary) {
|
|
355
|
+
if (!state.modifiedData.components) {
|
|
356
|
+
state.modifiedData.components = {};
|
|
357
|
+
}
|
|
358
|
+
state.modifiedData.components[compoUID] = compoSchema;
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
},
|
|
362
|
+
createComponentSchema: (state, action)=>{
|
|
363
|
+
const { uid, data, componentCategory, shouldAddComponentToData } = action.payload;
|
|
364
|
+
const newSchema = {
|
|
365
|
+
uid: uid,
|
|
366
|
+
isTemporary: true,
|
|
367
|
+
category: componentCategory,
|
|
368
|
+
schema: {
|
|
369
|
+
...data,
|
|
370
|
+
attributes: []
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
state.components[uid] = newSchema;
|
|
374
|
+
if (shouldAddComponentToData) {
|
|
375
|
+
state.modifiedData.components[uid] = newSchema;
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
createSchema: (state, action)=>{
|
|
379
|
+
const { uid, data } = action.payload;
|
|
380
|
+
const newSchema = {
|
|
381
|
+
uid: uid,
|
|
382
|
+
isTemporary: true,
|
|
383
|
+
schema: {
|
|
384
|
+
...data,
|
|
385
|
+
attributes: []
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
state.contentTypes[uid] = newSchema;
|
|
389
|
+
},
|
|
390
|
+
editAttribute: (state, action)=>{
|
|
391
|
+
const { attributeToSet, forTarget, targetUid, initialAttribute } = action.payload;
|
|
392
|
+
const { name, ...rest } = attributeToSet;
|
|
393
|
+
const initialAttributeName = initialAttribute.name;
|
|
394
|
+
const pathToDataToEdit = [
|
|
395
|
+
'component',
|
|
396
|
+
'contentType'
|
|
397
|
+
].includes(forTarget) ? [
|
|
398
|
+
forTarget
|
|
399
|
+
] : [
|
|
400
|
+
forTarget,
|
|
401
|
+
targetUid
|
|
402
|
+
];
|
|
403
|
+
const initialAttributeIndex = findAttributeIndex(get(state, [
|
|
404
|
+
'modifiedData',
|
|
405
|
+
...pathToDataToEdit
|
|
406
|
+
]), initialAttributeName);
|
|
407
|
+
const isEditingRelation = rest.type === 'relation';
|
|
408
|
+
if (!isEditingRelation) {
|
|
409
|
+
set(state, [
|
|
410
|
+
'modifiedData',
|
|
411
|
+
...pathToDataToEdit,
|
|
412
|
+
'schema',
|
|
413
|
+
'attributes',
|
|
414
|
+
initialAttributeIndex
|
|
415
|
+
], attributeToSet);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const updatedAttributes = get(state, [
|
|
419
|
+
'modifiedData',
|
|
420
|
+
...pathToDataToEdit,
|
|
421
|
+
'schema',
|
|
422
|
+
'attributes'
|
|
423
|
+
]).slice();
|
|
424
|
+
// First create the current relation attribute updated
|
|
425
|
+
const toSet = {
|
|
426
|
+
name,
|
|
427
|
+
relation: rest.relation,
|
|
428
|
+
target: rest.target,
|
|
429
|
+
targetAttribute: rest.targetAttribute,
|
|
430
|
+
type: 'relation'
|
|
431
|
+
};
|
|
432
|
+
if (rest.private) {
|
|
433
|
+
toSet.private = rest.private;
|
|
434
|
+
}
|
|
435
|
+
if (rest.pluginOptions) {
|
|
436
|
+
toSet.pluginOptions = rest.pluginOptions;
|
|
437
|
+
}
|
|
438
|
+
const currentAttributeIndex = updatedAttributes.findIndex((value)=>{
|
|
439
|
+
return value.name !== undefined && value.name === initialAttribute.name;
|
|
440
|
+
});
|
|
441
|
+
// First set it in the updatedAttributes
|
|
442
|
+
if (currentAttributeIndex !== -1) {
|
|
443
|
+
updatedAttributes.splice(currentAttributeIndex, 1, toSet);
|
|
444
|
+
}
|
|
445
|
+
let oppositeAttributeNameToRemove = null;
|
|
446
|
+
let oppositeAttributeNameToUpdate = null;
|
|
447
|
+
let oppositeAttributeToCreate = null;
|
|
448
|
+
let initialOppositeAttribute = null;
|
|
449
|
+
const currentUid = get(state, [
|
|
450
|
+
'modifiedData',
|
|
451
|
+
...pathToDataToEdit,
|
|
452
|
+
'uid'
|
|
453
|
+
]);
|
|
454
|
+
const didChangeTargetRelation = initialAttribute.target !== rest.target;
|
|
455
|
+
const didCreateInternalRelation = rest.target === currentUid;
|
|
456
|
+
const relationType = getRelationType(rest.relation, rest.targetAttribute);
|
|
457
|
+
const initialRelationType = getRelationType(initialAttribute.relation, initialAttribute.targetAttribute);
|
|
458
|
+
const hadInternalRelation = initialAttribute.target === currentUid;
|
|
459
|
+
const didChangeRelationType = initialRelationType !== relationType;
|
|
460
|
+
const shouldRemoveOppositeAttributeBecauseOfTargetChange = didChangeTargetRelation && !didCreateInternalRelation && hadInternalRelation && isEditingRelation;
|
|
461
|
+
const shouldRemoveOppositeAttributeBecauseOfRelationTypeChange = didChangeRelationType && hadInternalRelation && [
|
|
462
|
+
'oneWay',
|
|
463
|
+
'manyWay'
|
|
464
|
+
].includes(relationType) && isEditingRelation;
|
|
465
|
+
const shouldUpdateOppositeAttributeBecauseOfRelationTypeChange = !ONE_SIDE_RELATIONS.includes(initialRelationType) && !ONE_SIDE_RELATIONS.includes(relationType) && hadInternalRelation && didCreateInternalRelation && isEditingRelation;
|
|
466
|
+
const shouldCreateOppositeAttributeBecauseOfRelationTypeChange = ONE_SIDE_RELATIONS.includes(initialRelationType) && !ONE_SIDE_RELATIONS.includes(relationType) && hadInternalRelation && didCreateInternalRelation && isEditingRelation;
|
|
467
|
+
const shouldCreateOppositeAttributeBecauseOfTargetChange = didChangeTargetRelation && didCreateInternalRelation && !ONE_SIDE_RELATIONS.includes(relationType);
|
|
468
|
+
// Store opposite attribute name to remove at the end of the loop
|
|
469
|
+
if (shouldRemoveOppositeAttributeBecauseOfTargetChange || shouldRemoveOppositeAttributeBecauseOfRelationTypeChange) {
|
|
470
|
+
oppositeAttributeNameToRemove = initialAttribute.targetAttribute;
|
|
471
|
+
}
|
|
472
|
+
// In case of oneWay or manyWay relation there isn't an opposite attribute
|
|
473
|
+
if (oppositeAttributeNameToRemove) {
|
|
474
|
+
const indexToRemove = updatedAttributes.findIndex((value)=>value.name === oppositeAttributeNameToRemove);
|
|
475
|
+
updatedAttributes.splice(indexToRemove, 1);
|
|
476
|
+
}
|
|
477
|
+
// In order to preserve plugin options need to get the initial opposite attribute settings
|
|
478
|
+
if (!shouldRemoveOppositeAttributeBecauseOfTargetChange) {
|
|
479
|
+
const initialTargetContentType = get(state, [
|
|
480
|
+
'initialContentTypes',
|
|
481
|
+
initialAttribute.target
|
|
482
|
+
]);
|
|
483
|
+
if (initialTargetContentType) {
|
|
484
|
+
const oppositeAttributeIndex = findAttributeIndex(initialTargetContentType, initialAttribute.targetAttribute);
|
|
485
|
+
initialOppositeAttribute = get(state, [
|
|
486
|
+
'initialContentTypes',
|
|
487
|
+
initialAttribute.target,
|
|
488
|
+
'schema',
|
|
489
|
+
'attributes',
|
|
490
|
+
oppositeAttributeIndex
|
|
491
|
+
]);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
// Create the opposite attribute
|
|
495
|
+
if (shouldCreateOppositeAttributeBecauseOfRelationTypeChange || shouldCreateOppositeAttributeBecauseOfTargetChange) {
|
|
496
|
+
oppositeAttributeToCreate = {
|
|
497
|
+
name: rest.targetAttribute,
|
|
498
|
+
relation: getOppositeRelation(relationType),
|
|
499
|
+
target: rest.target,
|
|
500
|
+
targetAttribute: name,
|
|
501
|
+
type: 'relation'
|
|
502
|
+
};
|
|
503
|
+
if (rest.private) {
|
|
504
|
+
oppositeAttributeToCreate.private = rest.private;
|
|
505
|
+
}
|
|
506
|
+
if (initialOppositeAttribute && initialOppositeAttribute.pluginOptions) {
|
|
507
|
+
oppositeAttributeToCreate.pluginOptions = initialOppositeAttribute.pluginOptions;
|
|
508
|
+
}
|
|
509
|
+
const indexOfInitialAttribute = updatedAttributes.findIndex(({ name })=>name === initialAttribute.name);
|
|
510
|
+
const indexOfUpdatedAttribute = updatedAttributes.findIndex(({ name: attrName })=>name === attrName);
|
|
511
|
+
const indexToInsert = (indexOfInitialAttribute === -1 ? indexOfUpdatedAttribute : indexOfInitialAttribute) + 1;
|
|
512
|
+
updatedAttributes.splice(indexToInsert, 0, oppositeAttributeToCreate);
|
|
513
|
+
}
|
|
514
|
+
if (shouldUpdateOppositeAttributeBecauseOfRelationTypeChange) {
|
|
515
|
+
oppositeAttributeNameToUpdate = initialAttribute.targetAttribute;
|
|
516
|
+
oppositeAttributeToCreate = {
|
|
517
|
+
name: rest.targetAttribute,
|
|
518
|
+
relation: getOppositeRelation(relationType),
|
|
519
|
+
target: rest.target,
|
|
520
|
+
targetAttribute: name,
|
|
521
|
+
type: 'relation'
|
|
522
|
+
};
|
|
523
|
+
if (rest.private) {
|
|
524
|
+
oppositeAttributeToCreate.private = rest.private;
|
|
525
|
+
}
|
|
526
|
+
if (initialOppositeAttribute && initialOppositeAttribute.pluginOptions) {
|
|
527
|
+
oppositeAttributeToCreate.pluginOptions = initialOppositeAttribute.pluginOptions;
|
|
528
|
+
}
|
|
529
|
+
if (oppositeAttributeNameToUpdate) {
|
|
530
|
+
const indexToUpdate = updatedAttributes.findIndex(({ name })=>name === oppositeAttributeNameToUpdate);
|
|
531
|
+
updatedAttributes.splice(indexToUpdate, 1, oppositeAttributeToCreate);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
set(state, [
|
|
535
|
+
'modifiedData',
|
|
536
|
+
...pathToDataToEdit,
|
|
537
|
+
'schema',
|
|
538
|
+
'attributes'
|
|
539
|
+
], updatedAttributes);
|
|
540
|
+
},
|
|
541
|
+
editCustomFieldAttribute: (state, action)=>{
|
|
542
|
+
const { forTarget, targetUid, initialAttribute, attributeToSet } = action.payload;
|
|
543
|
+
const initialAttributeName = initialAttribute.name;
|
|
544
|
+
const pathToDataToEdit = [
|
|
545
|
+
'component',
|
|
546
|
+
'contentType'
|
|
547
|
+
].includes(forTarget) ? [
|
|
548
|
+
forTarget
|
|
549
|
+
] : [
|
|
550
|
+
forTarget,
|
|
551
|
+
targetUid
|
|
552
|
+
];
|
|
553
|
+
const initialAttributeIndex = findAttributeIndex(get(state, [
|
|
554
|
+
'modifiedData',
|
|
555
|
+
...pathToDataToEdit
|
|
556
|
+
]), initialAttributeName);
|
|
557
|
+
set(state, [
|
|
558
|
+
'modifiedData',
|
|
559
|
+
...pathToDataToEdit,
|
|
560
|
+
'schema',
|
|
561
|
+
'attributes',
|
|
562
|
+
initialAttributeIndex
|
|
563
|
+
], attributeToSet);
|
|
564
|
+
},
|
|
565
|
+
updateInitialState: (state)=>{
|
|
566
|
+
state.initialData = state.modifiedData;
|
|
567
|
+
},
|
|
568
|
+
deleteNotSavedType: (state)=>{
|
|
569
|
+
// Doing so will also reset the modified and the initial data
|
|
570
|
+
state.contentTypes = state.initialContentTypes;
|
|
571
|
+
state.components = state.initialComponents;
|
|
572
|
+
},
|
|
573
|
+
reloadPlugin: ()=>{
|
|
574
|
+
return initialState$1;
|
|
575
|
+
},
|
|
576
|
+
removeComponentFromDynamicZone: (state, action)=>{
|
|
577
|
+
const { dzName, componentToRemoveIndex } = action.payload;
|
|
578
|
+
const dzAttributeIndex = findAttributeIndex(state.modifiedData.contentType, dzName);
|
|
579
|
+
if (state.modifiedData.contentType) {
|
|
580
|
+
state.modifiedData.contentType.schema.attributes[dzAttributeIndex].components.splice(componentToRemoveIndex, 1);
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
removeField: (state, action)=>{
|
|
584
|
+
const { mainDataKey, attributeToRemoveName } = action.payload;
|
|
585
|
+
const pathToAttributes = [
|
|
586
|
+
'modifiedData',
|
|
587
|
+
mainDataKey,
|
|
588
|
+
'schema',
|
|
589
|
+
'attributes'
|
|
590
|
+
];
|
|
591
|
+
const attributeToRemoveIndex = findAttributeIndex(state.modifiedData[mainDataKey], attributeToRemoveName);
|
|
592
|
+
const pathToAttributeToRemove = [
|
|
593
|
+
...pathToAttributes,
|
|
594
|
+
attributeToRemoveIndex
|
|
595
|
+
];
|
|
596
|
+
const attributeToRemoveData = get(state, pathToAttributeToRemove);
|
|
597
|
+
const isRemovingRelationAttribute = attributeToRemoveData.type === 'relation';
|
|
598
|
+
// Only content types can have relations with themselves since
|
|
599
|
+
// components can only have oneWay or manyWay relations
|
|
600
|
+
const canTheAttributeToRemoveHaveARelationWithItself = mainDataKey === 'contentType';
|
|
601
|
+
if (isRemovingRelationAttribute && canTheAttributeToRemoveHaveARelationWithItself) {
|
|
602
|
+
const { target, relation, targetAttribute } = attributeToRemoveData;
|
|
603
|
+
const relationType = getRelationType(relation, targetAttribute);
|
|
604
|
+
const uid = state.modifiedData.contentType?.uid;
|
|
605
|
+
const shouldRemoveOppositeAttribute = target === uid && !ONE_SIDE_RELATIONS.includes(relationType);
|
|
606
|
+
if (shouldRemoveOppositeAttribute) {
|
|
607
|
+
const attributes = state.modifiedData[mainDataKey]?.schema.attributes.slice();
|
|
608
|
+
const nextAttributes = attributes.filter((attribute)=>{
|
|
609
|
+
if (attribute.name === attributeToRemoveName) {
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
612
|
+
if (attribute.target === uid && attribute.targetAttribute === attributeToRemoveName) {
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
615
|
+
return true;
|
|
616
|
+
});
|
|
617
|
+
const schema = state.modifiedData[mainDataKey];
|
|
618
|
+
if (schema) {
|
|
619
|
+
schema.schema.attributes = nextAttributes;
|
|
620
|
+
}
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
// Find all uid fields that have the targetField set to the field we are removing
|
|
625
|
+
const uidFieldsToUpdate = state.modifiedData[mainDataKey].schema.attributes.slice().reduce((acc, current)=>{
|
|
626
|
+
if (current.type !== 'uid') {
|
|
627
|
+
return acc;
|
|
628
|
+
}
|
|
629
|
+
if (current.targetField !== attributeToRemoveName) {
|
|
630
|
+
return acc;
|
|
631
|
+
}
|
|
632
|
+
acc.push(current.name);
|
|
633
|
+
return acc;
|
|
634
|
+
}, []);
|
|
635
|
+
uidFieldsToUpdate.forEach((fieldName)=>{
|
|
636
|
+
const fieldIndex = findAttributeIndex(state.modifiedData[mainDataKey], fieldName);
|
|
637
|
+
delete state.modifiedData[mainDataKey]?.schema.attributes[fieldIndex].targetField;
|
|
638
|
+
});
|
|
639
|
+
state.modifiedData[mainDataKey]?.schema.attributes.splice(attributeToRemoveIndex, 1);
|
|
640
|
+
},
|
|
641
|
+
removeFieldFromDisplayedComponent: (state, action)=>{
|
|
642
|
+
const { attributeToRemoveName, componentUid } = action.payload;
|
|
643
|
+
const attributeToRemoveIndex = findAttributeIndex(state.modifiedData.components?.[componentUid], attributeToRemoveName);
|
|
644
|
+
state.modifiedData.components?.[componentUid]?.schema?.attributes?.splice(attributeToRemoveIndex, 1);
|
|
645
|
+
},
|
|
646
|
+
setModifiedData: (state, action)=>{
|
|
647
|
+
const { schemaToSet, hasJustCreatedSchema } = action.payload;
|
|
648
|
+
const schema = {
|
|
649
|
+
...DEFAULT_MODIFIED_DATA,
|
|
650
|
+
...schemaToSet
|
|
651
|
+
};
|
|
652
|
+
state.initialData = schema;
|
|
653
|
+
state.modifiedData = schema;
|
|
654
|
+
// Reset the state with the initial data
|
|
655
|
+
// All created components and content types will be lost
|
|
656
|
+
if (!hasJustCreatedSchema) {
|
|
657
|
+
state.components = state.initialComponents;
|
|
658
|
+
state.contentTypes = state.initialContentTypes;
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
updateSchema: (state, action)=>{
|
|
662
|
+
const { data, schemaType } = action.payload;
|
|
663
|
+
const schema = state.modifiedData[schemaType];
|
|
664
|
+
if (!schema) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
schema.schema.displayName = data.displayName;
|
|
668
|
+
if (schemaType === 'component') {
|
|
669
|
+
const { uid } = action.payload;
|
|
670
|
+
schema.category = data.category;
|
|
671
|
+
schema.schema.icon = data.icon;
|
|
672
|
+
const addedComponent = immer.current(schema);
|
|
673
|
+
state.components[uid] = addedComponent;
|
|
674
|
+
} else {
|
|
675
|
+
schema.schema.kind = data.kind;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
const { reducer: reducer$1, actions: actions$1 } = slice$1;
|
|
681
|
+
|
|
682
|
+
const nameToSlug = (name)=>slugify(name, {
|
|
683
|
+
separator: '-'
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
const createUid = (name)=>{
|
|
687
|
+
const modelName = nameToSlug(name);
|
|
688
|
+
return `api::${modelName}.${modelName}`;
|
|
689
|
+
};
|
|
690
|
+
// From `content-type-builder/services/Components/createComponentUid`
|
|
691
|
+
const createComponentUid = (name, category)=>{
|
|
692
|
+
return `${nameToSlug(category)}.${nameToSlug(name)}`;
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
const customFieldDefaultOptionsReducer = (acc, option)=>{
|
|
696
|
+
if (option.items) {
|
|
697
|
+
return option.items.reduce(customFieldDefaultOptionsReducer, acc);
|
|
698
|
+
}
|
|
699
|
+
if ('defaultValue' in option) {
|
|
700
|
+
const { name, defaultValue } = option;
|
|
701
|
+
acc.push({
|
|
702
|
+
name,
|
|
703
|
+
defaultValue
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
return acc;
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
/* eslint-disable no-confusing-arrow */ const shouldPluralizeName = (nature)=>[
|
|
710
|
+
'manyToMany',
|
|
711
|
+
'oneToMany',
|
|
712
|
+
'manyWay'
|
|
713
|
+
].includes(nature) ? 2 : 1;
|
|
714
|
+
const shouldPluralizeTargetAttribute = (nature)=>[
|
|
715
|
+
'manyToMany',
|
|
716
|
+
'manyToOne'
|
|
717
|
+
].includes(nature) ? 2 : 1;
|
|
718
|
+
|
|
719
|
+
const initialState = {
|
|
720
|
+
formErrors: {},
|
|
721
|
+
modifiedData: {},
|
|
722
|
+
initialData: {},
|
|
723
|
+
componentToCreate: {},
|
|
724
|
+
isCreatingComponentWhileAddingAField: false
|
|
725
|
+
};
|
|
726
|
+
const slice = toolkit.createSlice({
|
|
727
|
+
name: 'formModal',
|
|
728
|
+
initialState,
|
|
729
|
+
reducers: {
|
|
730
|
+
onChange: (state, action)=>{
|
|
731
|
+
const { keys, value } = action.payload;
|
|
732
|
+
const obj = state.modifiedData;
|
|
733
|
+
const hasDefaultValue = Boolean(obj.default);
|
|
734
|
+
// There is no need to remove the default key if the default value isn't defined
|
|
735
|
+
if (hasDefaultValue && keys.length === 1 && keys.includes('type')) {
|
|
736
|
+
const previousType = obj.type;
|
|
737
|
+
if (previousType && [
|
|
738
|
+
'date',
|
|
739
|
+
'datetime',
|
|
740
|
+
'time'
|
|
741
|
+
].includes(previousType)) {
|
|
742
|
+
// return obj.updateIn(keys, () => value).remove('default');
|
|
743
|
+
delete state.modifiedData.default;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
set(state, [
|
|
747
|
+
'modifiedData',
|
|
748
|
+
...keys
|
|
749
|
+
], value);
|
|
750
|
+
},
|
|
751
|
+
onChangeRelationTarget: (state, action)=>{
|
|
752
|
+
const { target: { oneThatIsCreatingARelationWithAnother, selectedContentTypeFriendlyName, targetContentTypeAllowedRelations, value } } = action.payload;
|
|
753
|
+
// Special case for the admin user...
|
|
754
|
+
let didChangeRelationTypeBecauseOfRestrictedRelation = false;
|
|
755
|
+
let changedRelationType = null;
|
|
756
|
+
set(state, [
|
|
757
|
+
'modifiedData',
|
|
758
|
+
'target'
|
|
759
|
+
], value);
|
|
760
|
+
const modifiedData = state.modifiedData;
|
|
761
|
+
// Don't change the relation type if the allowed relations are not restricted
|
|
762
|
+
// TODO: replace with an obj { relation: 'x', bidirctional: true|false } when BE ready
|
|
763
|
+
if (Array.isArray(targetContentTypeAllowedRelations)) {
|
|
764
|
+
const currentRelationType = getRelationType(modifiedData.relation, modifiedData.targetAttribute);
|
|
765
|
+
if (currentRelationType && !targetContentTypeAllowedRelations.includes(currentRelationType)) {
|
|
766
|
+
const relationToSet = targetContentTypeAllowedRelations[0];
|
|
767
|
+
didChangeRelationTypeBecauseOfRestrictedRelation = true;
|
|
768
|
+
changedRelationType = relationToSet;
|
|
769
|
+
if (relationToSet === 'oneWay') {
|
|
770
|
+
set(state, [
|
|
771
|
+
'modifiedData',
|
|
772
|
+
'relation'
|
|
773
|
+
], 'oneToOne');
|
|
774
|
+
} else if (relationToSet === 'manyWay') {
|
|
775
|
+
set(state, [
|
|
776
|
+
'modifiedData',
|
|
777
|
+
'relation'
|
|
778
|
+
], 'oneToMany');
|
|
779
|
+
} else {
|
|
780
|
+
set(state, [
|
|
781
|
+
'modifiedData',
|
|
782
|
+
'relation'
|
|
783
|
+
], relationToSet);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
let nameToSet;
|
|
788
|
+
if (didChangeRelationTypeBecauseOfRestrictedRelation && changedRelationType) {
|
|
789
|
+
nameToSet = pluralize(snakeCase(nameToSlug(selectedContentTypeFriendlyName)), shouldPluralizeName(changedRelationType));
|
|
790
|
+
} else {
|
|
791
|
+
nameToSet = pluralize(snakeCase(nameToSlug(selectedContentTypeFriendlyName)), shouldPluralizeName(modifiedData.relation));
|
|
792
|
+
}
|
|
793
|
+
set(state, [
|
|
794
|
+
'modifiedData',
|
|
795
|
+
'name'
|
|
796
|
+
], nameToSet);
|
|
797
|
+
const currentTargetAttribute = state.modifiedData.targetAttribute;
|
|
798
|
+
if (currentTargetAttribute === null) {
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
// Changing the target and the relation is either oneWay or manyWay
|
|
802
|
+
// Case when we need to change the relation to oneWay (ex: admin user)
|
|
803
|
+
if (didChangeRelationTypeBecauseOfRestrictedRelation && changedRelationType && [
|
|
804
|
+
'oneWay',
|
|
805
|
+
'manyWay'
|
|
806
|
+
].includes(changedRelationType)) {
|
|
807
|
+
set(state, [
|
|
808
|
+
'modifiedData',
|
|
809
|
+
'targetAttribute'
|
|
810
|
+
], null);
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
const targetAttributeToSet = pluralize(snakeCase(nameToSlug(oneThatIsCreatingARelationWithAnother)), shouldPluralizeTargetAttribute(modifiedData.relation));
|
|
814
|
+
set(state, [
|
|
815
|
+
'modifiedData',
|
|
816
|
+
'targetAttribute'
|
|
817
|
+
], targetAttributeToSet);
|
|
818
|
+
},
|
|
819
|
+
onChangeRelationType: (state, action)=>{
|
|
820
|
+
const { target: { oneThatIsCreatingARelationWithAnother, value } } = action.payload;
|
|
821
|
+
const currentName = state.modifiedData.name;
|
|
822
|
+
// Switching from oneWay
|
|
823
|
+
if (![
|
|
824
|
+
'oneWay',
|
|
825
|
+
'manyWay'
|
|
826
|
+
].includes(value)) {
|
|
827
|
+
set(state, [
|
|
828
|
+
'modifiedData',
|
|
829
|
+
'relation'
|
|
830
|
+
], value);
|
|
831
|
+
const currentTargetAttribute = state.modifiedData.targetAttribute;
|
|
832
|
+
set(state, [
|
|
833
|
+
'modifiedData',
|
|
834
|
+
'name'
|
|
835
|
+
], pluralize(snakeCase(nameToSlug(currentName)), shouldPluralizeName(value)));
|
|
836
|
+
set(state, [
|
|
837
|
+
'modifiedData',
|
|
838
|
+
'targetAttribute'
|
|
839
|
+
], pluralize(currentTargetAttribute || snakeCase(nameToSlug(oneThatIsCreatingARelationWithAnother)), shouldPluralizeTargetAttribute(value)));
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
if (value === 'oneWay') {
|
|
843
|
+
set(state, [
|
|
844
|
+
'modifiedData',
|
|
845
|
+
'relation'
|
|
846
|
+
], 'oneToOne');
|
|
847
|
+
set(state, [
|
|
848
|
+
'modifiedData',
|
|
849
|
+
'targetAttribute'
|
|
850
|
+
], null);
|
|
851
|
+
set(state, [
|
|
852
|
+
'modifiedData',
|
|
853
|
+
'name'
|
|
854
|
+
], pluralize(snakeCase(currentName), 1));
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
// manyWay
|
|
858
|
+
set(state, [
|
|
859
|
+
'modifiedData',
|
|
860
|
+
'relation'
|
|
861
|
+
], 'oneToMany');
|
|
862
|
+
set(state, [
|
|
863
|
+
'modifiedData',
|
|
864
|
+
'targetAttribute'
|
|
865
|
+
], null);
|
|
866
|
+
set(state, [
|
|
867
|
+
'modifiedData',
|
|
868
|
+
'name'
|
|
869
|
+
], pluralize(snakeCase(currentName), 2));
|
|
870
|
+
},
|
|
871
|
+
resetProps: ()=>{
|
|
872
|
+
return initialState;
|
|
873
|
+
},
|
|
874
|
+
resetPropsAndSetFormForAddingAnExistingCompo: (state, action)=>{
|
|
875
|
+
const { options = {} } = action.payload;
|
|
876
|
+
return {
|
|
877
|
+
...initialState,
|
|
878
|
+
modifiedData: {
|
|
879
|
+
type: 'component',
|
|
880
|
+
repeatable: true,
|
|
881
|
+
...options
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
},
|
|
885
|
+
resetPropsAndSaveCurrentData: (state, action)=>{
|
|
886
|
+
const { options = {} } = action.payload;
|
|
887
|
+
// This is run when the user has created a new component
|
|
888
|
+
const componentToCreate = state.modifiedData.componentToCreate;
|
|
889
|
+
const modifiedData = {
|
|
890
|
+
displayName: componentToCreate.displayName,
|
|
891
|
+
type: 'component',
|
|
892
|
+
repeatable: false,
|
|
893
|
+
...options,
|
|
894
|
+
component: createComponentUid(componentToCreate.displayName, componentToCreate.category)
|
|
895
|
+
};
|
|
896
|
+
return {
|
|
897
|
+
...initialState,
|
|
898
|
+
componentToCreate,
|
|
899
|
+
modifiedData,
|
|
900
|
+
isCreatingComponentWhileAddingAField: state.modifiedData.createComponent
|
|
901
|
+
};
|
|
902
|
+
},
|
|
903
|
+
resetPropsAndSetTheFormForAddingACompoToADz: (state)=>{
|
|
904
|
+
const createdDZ = state.modifiedData;
|
|
905
|
+
const dataToSet = {
|
|
906
|
+
...createdDZ,
|
|
907
|
+
createComponent: true,
|
|
908
|
+
componentToCreate: {
|
|
909
|
+
type: 'component'
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
return {
|
|
913
|
+
...initialState,
|
|
914
|
+
modifiedData: dataToSet
|
|
915
|
+
};
|
|
916
|
+
},
|
|
917
|
+
setDataToEdit: (state, action)=>{
|
|
918
|
+
const { data } = action.payload;
|
|
919
|
+
state.modifiedData = data;
|
|
920
|
+
state.initialData = data;
|
|
921
|
+
},
|
|
922
|
+
setAttributeDataSchema: (state, action)=>{
|
|
923
|
+
const { isEditing } = action.payload;
|
|
924
|
+
if (isEditing) {
|
|
925
|
+
const { modifiedDataToSetForEditing } = action.payload;
|
|
926
|
+
state.modifiedData = modifiedDataToSetForEditing;
|
|
927
|
+
state.initialData = modifiedDataToSetForEditing;
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
const { attributeType, nameToSetForRelation, targetUid, step, options = {} } = action.payload;
|
|
931
|
+
let dataToSet;
|
|
932
|
+
if (attributeType === 'component') {
|
|
933
|
+
if (step === '1') {
|
|
934
|
+
dataToSet = {
|
|
935
|
+
type: 'component',
|
|
936
|
+
createComponent: true,
|
|
937
|
+
componentToCreate: {
|
|
938
|
+
type: 'component'
|
|
939
|
+
}
|
|
940
|
+
};
|
|
941
|
+
} else {
|
|
942
|
+
dataToSet = {
|
|
943
|
+
...options,
|
|
944
|
+
type: 'component',
|
|
945
|
+
repeatable: true
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
} else if (attributeType === 'dynamiczone') {
|
|
949
|
+
dataToSet = {
|
|
950
|
+
...options,
|
|
951
|
+
type: 'dynamiczone',
|
|
952
|
+
components: []
|
|
953
|
+
};
|
|
954
|
+
} else if (attributeType === 'text') {
|
|
955
|
+
dataToSet = {
|
|
956
|
+
...options,
|
|
957
|
+
type: 'string'
|
|
958
|
+
};
|
|
959
|
+
} else if (attributeType === 'number' || attributeType === 'date') {
|
|
960
|
+
dataToSet = options;
|
|
961
|
+
} else if (attributeType === 'media') {
|
|
962
|
+
dataToSet = {
|
|
963
|
+
allowedTypes: [
|
|
964
|
+
'images',
|
|
965
|
+
'files',
|
|
966
|
+
'videos',
|
|
967
|
+
'audios'
|
|
968
|
+
],
|
|
969
|
+
type: 'media',
|
|
970
|
+
multiple: true,
|
|
971
|
+
...options
|
|
972
|
+
};
|
|
973
|
+
} else if (attributeType === 'enumeration') {
|
|
974
|
+
dataToSet = {
|
|
975
|
+
...options,
|
|
976
|
+
type: 'enumeration',
|
|
977
|
+
enum: []
|
|
978
|
+
};
|
|
979
|
+
} else if (attributeType === 'relation') {
|
|
980
|
+
dataToSet = {
|
|
981
|
+
name: snakeCase(nameToSetForRelation),
|
|
982
|
+
relation: 'oneToOne',
|
|
983
|
+
targetAttribute: null,
|
|
984
|
+
target: targetUid,
|
|
985
|
+
type: 'relation'
|
|
986
|
+
};
|
|
987
|
+
} else {
|
|
988
|
+
dataToSet = {
|
|
989
|
+
...options,
|
|
990
|
+
type: attributeType,
|
|
991
|
+
default: null
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
state.modifiedData = dataToSet;
|
|
995
|
+
},
|
|
996
|
+
setCustomFieldDataSchema: (state, action)=>{
|
|
997
|
+
const { isEditing } = action.payload;
|
|
998
|
+
if (isEditing) {
|
|
999
|
+
const { modifiedDataToSetForEditing } = action.payload;
|
|
1000
|
+
state.modifiedData = modifiedDataToSetForEditing;
|
|
1001
|
+
state.initialData = modifiedDataToSetForEditing;
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
const { customField, options = {} } = action.payload;
|
|
1005
|
+
state.modifiedData = {
|
|
1006
|
+
...options,
|
|
1007
|
+
type: customField.type
|
|
1008
|
+
};
|
|
1009
|
+
const allOptions = [
|
|
1010
|
+
...customField?.options?.base || [],
|
|
1011
|
+
...customField?.options?.advanced || []
|
|
1012
|
+
];
|
|
1013
|
+
const optionDefaults = allOptions.reduce(customFieldDefaultOptionsReducer, []);
|
|
1014
|
+
if (optionDefaults.length) {
|
|
1015
|
+
optionDefaults.forEach(({ name, defaultValue })=>set(state.modifiedData, name, defaultValue));
|
|
1016
|
+
}
|
|
1017
|
+
},
|
|
1018
|
+
setDynamicZoneDataSchema: (state, action)=>{
|
|
1019
|
+
const { attributeToEdit } = action.payload;
|
|
1020
|
+
state.modifiedData = attributeToEdit;
|
|
1021
|
+
state.initialData = attributeToEdit;
|
|
1022
|
+
},
|
|
1023
|
+
setErrors: (state, action)=>{
|
|
1024
|
+
state.formErrors = action.payload.errors;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
const { actions, reducer } = slice;
|
|
1029
|
+
|
|
1030
|
+
const reducers = {
|
|
1031
|
+
[`${pluginId}_formModal`]: reducer,
|
|
1032
|
+
[`${pluginId}_dataManagerProvider`]: reducer$1
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
// TODO V5 Convert any into real types
|
|
1036
|
+
const formsAPI = {
|
|
1037
|
+
components: {
|
|
1038
|
+
inputs: {},
|
|
1039
|
+
add ({ id, component }) {
|
|
1040
|
+
if (!this.inputs[id]) {
|
|
1041
|
+
this.inputs[id] = component;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
},
|
|
1045
|
+
types: {
|
|
1046
|
+
attribute: {
|
|
1047
|
+
},
|
|
1048
|
+
contentType: {
|
|
1049
|
+
validators: [],
|
|
1050
|
+
form: {
|
|
1051
|
+
advanced: [],
|
|
1052
|
+
base: []
|
|
1053
|
+
}
|
|
1054
|
+
},
|
|
1055
|
+
component: {
|
|
1056
|
+
validators: [],
|
|
1057
|
+
form: {
|
|
1058
|
+
advanced: [],
|
|
1059
|
+
base: []
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
},
|
|
1063
|
+
contentTypeSchemaMutations: [],
|
|
1064
|
+
addContentTypeSchemaMutation (cb) {
|
|
1065
|
+
this.contentTypeSchemaMutations.push(cb);
|
|
1066
|
+
},
|
|
1067
|
+
extendContentType ({ validator, form: { advanced, base } }) {
|
|
1068
|
+
const { contentType } = this.types;
|
|
1069
|
+
if (validator) {
|
|
1070
|
+
contentType.validators.push(validator);
|
|
1071
|
+
}
|
|
1072
|
+
contentType.form.advanced.push(advanced);
|
|
1073
|
+
contentType.form.base.push(base);
|
|
1074
|
+
},
|
|
1075
|
+
extendFields (fields, { validator, form: { advanced, base } }) {
|
|
1076
|
+
const formType = this.types.attribute;
|
|
1077
|
+
fields.forEach((field)=>{
|
|
1078
|
+
if (!formType[field]) {
|
|
1079
|
+
formType[field] = {
|
|
1080
|
+
validators: [],
|
|
1081
|
+
form: {
|
|
1082
|
+
advanced: [],
|
|
1083
|
+
base: []
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
if (validator) {
|
|
1088
|
+
formType[field].validators.push(validator);
|
|
1089
|
+
}
|
|
1090
|
+
formType[field].form.advanced.push(advanced);
|
|
1091
|
+
formType[field].form.base.push(base);
|
|
1092
|
+
});
|
|
1093
|
+
},
|
|
1094
|
+
getAdvancedForm (target, props = null) {
|
|
1095
|
+
const sectionsToAdd = get(this.types, [
|
|
1096
|
+
...target,
|
|
1097
|
+
'form',
|
|
1098
|
+
'advanced'
|
|
1099
|
+
], []).reduce((acc, current)=>{
|
|
1100
|
+
const sections = current(props);
|
|
1101
|
+
return [
|
|
1102
|
+
...acc,
|
|
1103
|
+
...sections
|
|
1104
|
+
];
|
|
1105
|
+
}, []);
|
|
1106
|
+
return sectionsToAdd;
|
|
1107
|
+
},
|
|
1108
|
+
makeCustomFieldValidator (attributeShape, validator, ...validatorArgs) {
|
|
1109
|
+
// When no validator, return the attribute shape
|
|
1110
|
+
if (!validator) return attributeShape;
|
|
1111
|
+
// Otherwise extend the shape with the provided validator
|
|
1112
|
+
return attributeShape.shape({
|
|
1113
|
+
options: yup__namespace.object().shape(validator(validatorArgs))
|
|
1114
|
+
});
|
|
1115
|
+
},
|
|
1116
|
+
makeValidator (target, initShape, ...args) {
|
|
1117
|
+
const validators = get(this.types, [
|
|
1118
|
+
...target,
|
|
1119
|
+
'validators'
|
|
1120
|
+
], []);
|
|
1121
|
+
const pluginOptionsShape = validators.reduce((acc, current)=>{
|
|
1122
|
+
const pluginOptionShape = current(args);
|
|
1123
|
+
return {
|
|
1124
|
+
...acc,
|
|
1125
|
+
...pluginOptionShape
|
|
1126
|
+
};
|
|
1127
|
+
}, {});
|
|
1128
|
+
return initShape.shape({
|
|
1129
|
+
pluginOptions: yup__namespace.object().shape(pluginOptionsShape)
|
|
1130
|
+
});
|
|
1131
|
+
},
|
|
1132
|
+
mutateContentTypeSchema (data, initialData) {
|
|
1133
|
+
let enhancedData = cloneDeep(data);
|
|
1134
|
+
const refData = cloneDeep(initialData);
|
|
1135
|
+
this.contentTypeSchemaMutations.forEach((cb)=>{
|
|
1136
|
+
enhancedData = cb(enhancedData, refData);
|
|
1137
|
+
});
|
|
1138
|
+
return enhancedData;
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
const prefixPluginTranslations = (trad, pluginId)=>{
|
|
1143
|
+
return Object.keys(trad).reduce((acc, current)=>{
|
|
1144
|
+
acc[`${pluginId}.${current}`] = trad[current];
|
|
1145
|
+
return acc;
|
|
1146
|
+
}, {});
|
|
1147
|
+
};
|
|
1148
|
+
|
|
1149
|
+
const AutoReloadOverlayBlockerContext = /*#__PURE__*/ React__namespace.createContext({});
|
|
1150
|
+
const MAX_ELAPSED_TIME = 30 * 1000;
|
|
1151
|
+
const AutoReloadOverlayBlockerProvider = ({ children })=>{
|
|
1152
|
+
const [isOpen, setIsOpen] = React__namespace.useState(false);
|
|
1153
|
+
const [config, setConfig] = React__namespace.useState({});
|
|
1154
|
+
const [failed, setFailed] = React__namespace.useState(false);
|
|
1155
|
+
const lockAppWithAutoreload = React__namespace.useCallback((config = {})=>{
|
|
1156
|
+
setIsOpen(true);
|
|
1157
|
+
setConfig(config);
|
|
1158
|
+
}, []);
|
|
1159
|
+
const unlockAppWithAutoreload = React__namespace.useCallback(()=>{
|
|
1160
|
+
setIsOpen(false);
|
|
1161
|
+
setConfig({});
|
|
1162
|
+
}, []);
|
|
1163
|
+
// eslint-disable-next-line consistent-return
|
|
1164
|
+
React__namespace.useEffect(()=>{
|
|
1165
|
+
if (isOpen) {
|
|
1166
|
+
const timeout = setTimeout(()=>{
|
|
1167
|
+
setFailed(true);
|
|
1168
|
+
}, MAX_ELAPSED_TIME);
|
|
1169
|
+
return ()=>{
|
|
1170
|
+
clearTimeout(timeout);
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
}, [
|
|
1174
|
+
isOpen
|
|
1175
|
+
]);
|
|
1176
|
+
let displayedIcon = config?.icon || 'reload';
|
|
1177
|
+
let description = {
|
|
1178
|
+
id: config?.description || 'components.OverlayBlocker.description',
|
|
1179
|
+
defaultMessage: "You're using a feature that needs the server to restart. The page will reload automatically."
|
|
1180
|
+
};
|
|
1181
|
+
let title = {
|
|
1182
|
+
id: config?.title || 'components.OverlayBlocker.title',
|
|
1183
|
+
defaultMessage: 'Waiting for restart'
|
|
1184
|
+
};
|
|
1185
|
+
if (failed) {
|
|
1186
|
+
displayedIcon = 'time';
|
|
1187
|
+
description = {
|
|
1188
|
+
id: 'components.OverlayBlocker.description.serverError',
|
|
1189
|
+
defaultMessage: 'The server should have restarted, please check your logs in the terminal.'
|
|
1190
|
+
};
|
|
1191
|
+
title = {
|
|
1192
|
+
id: 'components.OverlayBlocker.title.serverError',
|
|
1193
|
+
defaultMessage: 'The restart is taking longer than expected'
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
const autoReloadValue = React__namespace.useMemo(()=>({
|
|
1197
|
+
lockAppWithAutoreload,
|
|
1198
|
+
unlockAppWithAutoreload
|
|
1199
|
+
}), [
|
|
1200
|
+
lockAppWithAutoreload,
|
|
1201
|
+
unlockAppWithAutoreload
|
|
1202
|
+
]);
|
|
1203
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(AutoReloadOverlayBlockerContext.Provider, {
|
|
1204
|
+
value: autoReloadValue,
|
|
1205
|
+
children: [
|
|
1206
|
+
/*#__PURE__*/ jsxRuntime.jsx(Blocker, {
|
|
1207
|
+
displayedIcon: displayedIcon,
|
|
1208
|
+
isOpen: isOpen,
|
|
1209
|
+
description: description,
|
|
1210
|
+
title: title
|
|
1211
|
+
}),
|
|
1212
|
+
children
|
|
1213
|
+
]
|
|
1214
|
+
});
|
|
1215
|
+
};
|
|
1216
|
+
const Blocker = ({ displayedIcon, description, title, isOpen })=>{
|
|
1217
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
1218
|
+
// eslint-disable-next-line no-undef
|
|
1219
|
+
return isOpen && globalThis?.document?.body ? /*#__PURE__*/ reactDom.createPortal(/*#__PURE__*/ jsxRuntime.jsxs(Overlay, {
|
|
1220
|
+
id: "autoReloadOverlayBlocker",
|
|
1221
|
+
direction: "column",
|
|
1222
|
+
alignItems: "center",
|
|
1223
|
+
gap: 6,
|
|
1224
|
+
children: [
|
|
1225
|
+
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
|
|
1226
|
+
direction: "column",
|
|
1227
|
+
alignItems: "center",
|
|
1228
|
+
gap: 2,
|
|
1229
|
+
children: [
|
|
1230
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
|
|
1231
|
+
tag: "h1",
|
|
1232
|
+
variant: "alpha",
|
|
1233
|
+
children: formatMessage(title)
|
|
1234
|
+
}),
|
|
1235
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
|
|
1236
|
+
tag: "h2",
|
|
1237
|
+
textColor: "neutral600",
|
|
1238
|
+
fontSize: 4,
|
|
1239
|
+
fontWeight: "regular",
|
|
1240
|
+
children: formatMessage(description)
|
|
1241
|
+
})
|
|
1242
|
+
]
|
|
1243
|
+
}),
|
|
1244
|
+
displayedIcon === 'reload' && /*#__PURE__*/ jsxRuntime.jsx(IconBox, {
|
|
1245
|
+
padding: 6,
|
|
1246
|
+
background: "primary100",
|
|
1247
|
+
borderColor: "primary200",
|
|
1248
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(LoaderReload, {
|
|
1249
|
+
width: "4rem",
|
|
1250
|
+
height: "4rem"
|
|
1251
|
+
})
|
|
1252
|
+
}),
|
|
1253
|
+
displayedIcon === 'time' && /*#__PURE__*/ jsxRuntime.jsx(IconBox, {
|
|
1254
|
+
padding: 6,
|
|
1255
|
+
background: "primary100",
|
|
1256
|
+
borderColor: "primary200",
|
|
1257
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(Icons.Clock, {
|
|
1258
|
+
width: "4rem",
|
|
1259
|
+
height: "4rem"
|
|
1260
|
+
})
|
|
1261
|
+
}),
|
|
1262
|
+
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
|
|
1263
|
+
marginTop: 2,
|
|
1264
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Link, {
|
|
1265
|
+
href: "https://docs.strapi.io",
|
|
1266
|
+
isExternal: true,
|
|
1267
|
+
children: formatMessage({
|
|
1268
|
+
id: 'global.documentation',
|
|
1269
|
+
defaultMessage: 'Read the documentation'
|
|
1270
|
+
})
|
|
1271
|
+
})
|
|
1272
|
+
})
|
|
1273
|
+
]
|
|
1274
|
+
}), // eslint-disable-next-line no-undef
|
|
1275
|
+
globalThis.document.body) : null;
|
|
1276
|
+
};
|
|
1277
|
+
const rotation = styledComponents.keyframes`
|
|
1278
|
+
from {
|
|
1279
|
+
transform: rotate(0deg);
|
|
1280
|
+
}
|
|
1281
|
+
to {
|
|
1282
|
+
transform: rotate(359deg);
|
|
1283
|
+
}
|
|
1284
|
+
`;
|
|
1285
|
+
const LoaderReload = styledComponents.styled(Icons.ArrowClockwise)`
|
|
1286
|
+
animation: ${rotation} 1s infinite linear;
|
|
1287
|
+
`;
|
|
1288
|
+
const Overlay = styledComponents.styled(designSystem.Flex)`
|
|
1289
|
+
position: fixed;
|
|
1290
|
+
top: 0;
|
|
1291
|
+
right: 0;
|
|
1292
|
+
bottom: 0;
|
|
1293
|
+
left: 0;
|
|
1294
|
+
/* TODO: set this up in the theme for consistence z-index values */
|
|
1295
|
+
z-index: 1140;
|
|
1296
|
+
padding-top: 16rem;
|
|
1297
|
+
|
|
1298
|
+
& > * {
|
|
1299
|
+
position: relative;
|
|
1300
|
+
z-index: 1;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
&:before {
|
|
1304
|
+
content: '';
|
|
1305
|
+
position: fixed;
|
|
1306
|
+
top: 0;
|
|
1307
|
+
right: 0;
|
|
1308
|
+
bottom: 0;
|
|
1309
|
+
left: 0;
|
|
1310
|
+
background: ${({ theme })=>theme.colors.neutral0};
|
|
1311
|
+
opacity: 0.9;
|
|
1312
|
+
}
|
|
1313
|
+
`;
|
|
1314
|
+
const IconBox = styledComponents.styled(designSystem.Box)`
|
|
1315
|
+
border-radius: 50%;
|
|
1316
|
+
display: flex;
|
|
1317
|
+
align-items: center;
|
|
1318
|
+
justify-content: center;
|
|
1319
|
+
svg {
|
|
1320
|
+
> path {
|
|
1321
|
+
fill: ${({ theme })=>theme.colors.primary600} !important;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
`;
|
|
1325
|
+
/* -------------------------------------------------------------------------------------------------
|
|
1326
|
+
* Hook
|
|
1327
|
+
* -----------------------------------------------------------------------------------------------*/ const useAutoReloadOverlayBlocker = ()=>React__namespace.useContext(AutoReloadOverlayBlockerContext);
|
|
1328
|
+
|
|
1329
|
+
function __variableDynamicImportRuntime1__(path) {
|
|
1330
|
+
switch (path) {
|
|
1331
|
+
case './translations/ar.json': return Promise.resolve().then(function () { return require('./ar-Df0f0-PT.js'); });
|
|
1332
|
+
case './translations/cs.json': return Promise.resolve().then(function () { return require('./cs-DeTwqc7p.js'); });
|
|
1333
|
+
case './translations/de.json': return Promise.resolve().then(function () { return require('./de-BJkS06jF.js'); });
|
|
1334
|
+
case './translations/dk.json': return Promise.resolve().then(function () { return require('./dk-CGm-qVH7.js'); });
|
|
1335
|
+
case './translations/en.json': return Promise.resolve().then(function () { return require('./en-BJUu34b0.js'); });
|
|
1336
|
+
case './translations/es.json': return Promise.resolve().then(function () { return require('./es-J8kvHlNy.js'); });
|
|
1337
|
+
case './translations/fr.json': return Promise.resolve().then(function () { return require('./fr-C6y35iY7.js'); });
|
|
1338
|
+
case './translations/id.json': return Promise.resolve().then(function () { return require('./id-BvxV6wLP.js'); });
|
|
1339
|
+
case './translations/it.json': return Promise.resolve().then(function () { return require('./it-C_IgFU-G.js'); });
|
|
1340
|
+
case './translations/ja.json': return Promise.resolve().then(function () { return require('./ja-CWo4Qqq6.js'); });
|
|
1341
|
+
case './translations/ko.json': return Promise.resolve().then(function () { return require('./ko-BsByJNEl.js'); });
|
|
1342
|
+
case './translations/ms.json': return Promise.resolve().then(function () { return require('./ms-DPTzS7SH.js'); });
|
|
1343
|
+
case './translations/nl.json': return Promise.resolve().then(function () { return require('./nl-db29QMOx.js'); });
|
|
1344
|
+
case './translations/pl.json': return Promise.resolve().then(function () { return require('./pl-pYy1djj3.js'); });
|
|
1345
|
+
case './translations/pt-BR.json': return Promise.resolve().then(function () { return require('./pt-BR-CTPuXGWF.js'); });
|
|
1346
|
+
case './translations/pt.json': return Promise.resolve().then(function () { return require('./pt-BQmWcdeG.js'); });
|
|
1347
|
+
case './translations/ru.json': return Promise.resolve().then(function () { return require('./ru-DQiDXgUV.js'); });
|
|
1348
|
+
case './translations/sk.json': return Promise.resolve().then(function () { return require('./sk-DrnebmXb.js'); });
|
|
1349
|
+
case './translations/sv.json': return Promise.resolve().then(function () { return require('./sv-CrWlNosi.js'); });
|
|
1350
|
+
case './translations/th.json': return Promise.resolve().then(function () { return require('./th-BbrCkfgX.js'); });
|
|
1351
|
+
case './translations/tr.json': return Promise.resolve().then(function () { return require('./tr-CHdMj8m6.js'); });
|
|
1352
|
+
case './translations/uk.json': return Promise.resolve().then(function () { return require('./uk-BQEQ3weH.js'); });
|
|
1353
|
+
case './translations/zh-Hans.json': return Promise.resolve().then(function () { return require('./zh-Hans-lXbNiMp9.js'); });
|
|
1354
|
+
case './translations/zh.json': return Promise.resolve().then(function () { return require('./zh-CWj4avQA.js'); });
|
|
1355
|
+
default: return new Promise(function(resolve, reject) {
|
|
1356
|
+
(typeof queueMicrotask === 'function' ? queueMicrotask : setTimeout)(
|
|
1357
|
+
reject.bind(null, new Error("Unknown variable dynamic import: " + path))
|
|
1358
|
+
);
|
|
1359
|
+
})
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
// eslint-disable-next-line import/no-default-export
|
|
1363
|
+
var index = {
|
|
1364
|
+
register (app) {
|
|
1365
|
+
app.addReducers(reducers);
|
|
1366
|
+
app.addMenuLink({
|
|
1367
|
+
to: `plugins/${pluginId}`,
|
|
1368
|
+
icon: Icons.Layout,
|
|
1369
|
+
intlLabel: {
|
|
1370
|
+
id: `${pluginId}.plugin.name`,
|
|
1371
|
+
defaultMessage: 'Content-Type Builder'
|
|
1372
|
+
},
|
|
1373
|
+
permissions: PERMISSIONS.main,
|
|
1374
|
+
Component: ()=>Promise.resolve().then(function () { return require('./index-BQ2VO38W.js'); }).then(function (n) { return n.index; }),
|
|
1375
|
+
position: 5
|
|
1376
|
+
});
|
|
1377
|
+
app.registerPlugin({
|
|
1378
|
+
id: pluginId,
|
|
1379
|
+
name: pluginId,
|
|
1380
|
+
// Internal APIs exposed by the CTB for the other plugins to use
|
|
1381
|
+
apis: {
|
|
1382
|
+
forms: formsAPI
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
},
|
|
1386
|
+
bootstrap () {},
|
|
1387
|
+
async registerTrads ({ locales }) {
|
|
1388
|
+
const importedTrads = await Promise.all(locales.map((locale)=>{
|
|
1389
|
+
return __variableDynamicImportRuntime1__(`./translations/${locale}.json`).then(({ default: data })=>{
|
|
1390
|
+
return {
|
|
1391
|
+
data: prefixPluginTranslations(data, pluginId),
|
|
1392
|
+
locale
|
|
1393
|
+
};
|
|
1394
|
+
}).catch(()=>{
|
|
1395
|
+
return {
|
|
1396
|
+
data: {},
|
|
1397
|
+
locale
|
|
1398
|
+
};
|
|
1399
|
+
});
|
|
1400
|
+
}));
|
|
1401
|
+
return Promise.resolve(importedTrads);
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
exports.AutoReloadOverlayBlockerProvider = AutoReloadOverlayBlockerProvider;
|
|
1406
|
+
exports.MAX_COMPONENT_DEPTH = MAX_COMPONENT_DEPTH;
|
|
1407
|
+
exports.PERMISSIONS = PERMISSIONS;
|
|
1408
|
+
exports.actions = actions;
|
|
1409
|
+
exports.actions$1 = actions$1;
|
|
1410
|
+
exports.createComponentUid = createComponentUid;
|
|
1411
|
+
exports.createUid = createUid;
|
|
1412
|
+
exports.getRelationType = getRelationType;
|
|
1413
|
+
exports.index = index;
|
|
1414
|
+
exports.initialState = initialState;
|
|
1415
|
+
exports.initialState$1 = initialState$1;
|
|
1416
|
+
exports.makeUnique = makeUnique;
|
|
1417
|
+
exports.nameToSlug = nameToSlug;
|
|
1418
|
+
exports.pluginId = pluginId;
|
|
1419
|
+
exports.retrieveComponentsFromSchema = retrieveComponentsFromSchema;
|
|
1420
|
+
exports.useAutoReloadOverlayBlocker = useAutoReloadOverlayBlocker;
|
|
1421
|
+
//# sourceMappingURL=index-BZeN5KRn.js.map
|