@akemona-org/strapi-plugin-content-type-builder 3.7.0
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/LICENSE +22 -0
- package/README.md +19 -0
- package/admin/src/InjectedComponents/ContentManager/EditSettingViewButton.js +76 -0
- package/admin/src/InjectedComponents/ContentManager/EditViewLink.js +44 -0
- package/admin/src/assets/images/logo.svg +1 -0
- package/admin/src/components/AllowedTypesSelect/MenuList.js +115 -0
- package/admin/src/components/AllowedTypesSelect/Text.js +26 -0
- package/admin/src/components/AllowedTypesSelect/index.js +55 -0
- package/admin/src/components/AttributeOption/Button.js +50 -0
- package/admin/src/components/AttributeOption/Card.js +26 -0
- package/admin/src/components/AttributeOption/index.js +127 -0
- package/admin/src/components/BooleanBox/CT.js +21 -0
- package/admin/src/components/BooleanBox/Enumeration.js +10 -0
- package/admin/src/components/BooleanBox/EnumerationWrapper.js +14 -0
- package/admin/src/components/BooleanBox/Label.js +9 -0
- package/admin/src/components/BooleanBox/ST.js +21 -0
- package/admin/src/components/BooleanBox/Wrapper.js +75 -0
- package/admin/src/components/BooleanBox/icons/CTSelected.js +136 -0
- package/admin/src/components/BooleanBox/icons/CTUnselected.js +136 -0
- package/admin/src/components/BooleanBox/icons/STSelected.js +80 -0
- package/admin/src/components/BooleanBox/icons/STUnselected.js +76 -0
- package/admin/src/components/BooleanBox/index.js +103 -0
- package/admin/src/components/CheckboxWithDescription/Wrapper.js +12 -0
- package/admin/src/components/CheckboxWithDescription/index.js +40 -0
- package/admin/src/components/ComponentCard/Close.js +12 -0
- package/admin/src/components/ComponentCard/Wrapper.js +84 -0
- package/admin/src/components/ComponentCard/index.js +62 -0
- package/admin/src/components/ComponentIconPicker/Cell.js +40 -0
- package/admin/src/components/ComponentIconPicker/CellRenderer.js +36 -0
- package/admin/src/components/ComponentIconPicker/Search.js +12 -0
- package/admin/src/components/ComponentIconPicker/SearchWrapper.js +34 -0
- package/admin/src/components/ComponentIconPicker/Wrapper.js +60 -0
- package/admin/src/components/ComponentIconPicker/index.js +143 -0
- package/admin/src/components/ComponentList/index.js +78 -0
- package/admin/src/components/ComponentSelect/Category.js +20 -0
- package/admin/src/components/ComponentSelect/CategoryName.js +11 -0
- package/admin/src/components/ComponentSelect/MenuList.js +110 -0
- package/admin/src/components/ComponentSelect/MultipleMenuList.js +271 -0
- package/admin/src/components/ComponentSelect/Value.js +83 -0
- package/admin/src/components/ComponentSelect/index.js +83 -0
- package/admin/src/components/ComponentSelect/utils/HasSomeSubArray.js +5 -0
- package/admin/src/components/ComponentSelect/utils/hasSubArray.js +5 -0
- package/admin/src/components/CreatableSelect/index.js +58 -0
- package/admin/src/components/CustomCheckbox/StyledCustomCheckbox.js +25 -0
- package/admin/src/components/CustomCheckbox/index.js +71 -0
- package/admin/src/components/CustomLink/P.js +17 -0
- package/admin/src/components/CustomLink/StyledCustomLink.js +20 -0
- package/admin/src/components/CustomLink/index.js +31 -0
- package/admin/src/components/DynamicZoneList/ComponentButton.js +39 -0
- package/admin/src/components/DynamicZoneList/index.js +124 -0
- package/admin/src/components/HeaderModalNavContainer/index.js +25 -0
- package/admin/src/components/HeaderNavLink/Wrapper.js +21 -0
- package/admin/src/components/HeaderNavLink/index.js +50 -0
- package/admin/src/components/List/List.js +131 -0
- package/admin/src/components/List/index.js +295 -0
- package/admin/src/components/ListButton/index.js +9 -0
- package/admin/src/components/ListHeader/Title.js +19 -0
- package/admin/src/components/ListHeader/Wrapper.js +24 -0
- package/admin/src/components/ListHeader/index.js +37 -0
- package/admin/src/components/ListRow/Wrapper.js +76 -0
- package/admin/src/components/ListRow/index.js +334 -0
- package/admin/src/components/ModalHeader/ComponentIcon.js +21 -0
- package/admin/src/components/ModalHeader/ComponentInfos.js +22 -0
- package/admin/src/components/ModalHeader/ComponentInfosWrapper.js +9 -0
- package/admin/src/components/ModalHeader/DropdownInfos.js +50 -0
- package/admin/src/components/ModalHeader/Icon.js +26 -0
- package/admin/src/components/ModalHeader/IconWrapper.js +11 -0
- package/admin/src/components/ModalHeader/Item.js +19 -0
- package/admin/src/components/ModalHeader/Menu.js +8 -0
- package/admin/src/components/ModalHeader/Toggle.js +14 -0
- package/admin/src/components/ModalHeader/Wrapper.js +12 -0
- package/admin/src/components/ModalHeader/index.js +105 -0
- package/admin/src/components/RelationForm/Wrapper.js +9 -0
- package/admin/src/components/RelationForm/index.js +66 -0
- package/admin/src/components/RelationFormBox/Wrapper.js +34 -0
- package/admin/src/components/RelationFormBox/index.js +85 -0
- package/admin/src/components/RelationFormNaturePicker/Wrapper.js +53 -0
- package/admin/src/components/RelationFormNaturePicker/index.js +112 -0
- package/admin/src/components/RelationTargetPicker/Item.js +62 -0
- package/admin/src/components/RelationTargetPicker/Wrapper.js +89 -0
- package/admin/src/components/RelationTargetPicker/index.js +88 -0
- package/admin/src/components/SelectCheckbox/index.js +8 -0
- package/admin/src/components/SelectMenuSubUl/ToggleUl.js +23 -0
- package/admin/src/components/SelectMenuSubUl/index.js +23 -0
- package/admin/src/components/SelectMenuUl/index.js +66 -0
- package/admin/src/components/Td/index.js +37 -0
- package/admin/src/components/UpperFirst/index.js +14 -0
- package/admin/src/components/WrapperSelect/index.js +89 -0
- package/admin/src/containers/App/Wrapper.js +14 -0
- package/admin/src/containers/App/index.js +39 -0
- package/admin/src/containers/App/utils/icons.json +962 -0
- package/admin/src/containers/DataManagerProvider/constants.js +15 -0
- package/admin/src/containers/DataManagerProvider/index.js +610 -0
- package/admin/src/containers/DataManagerProvider/reducer.js +461 -0
- package/admin/src/containers/DataManagerProvider/selectors.js +25 -0
- package/admin/src/containers/DataManagerProvider/utils/cleanData.js +167 -0
- package/admin/src/containers/DataManagerProvider/utils/createDataObject.js +8 -0
- package/admin/src/containers/DataManagerProvider/utils/createModifiedDataSchema.js +91 -0
- package/admin/src/containers/DataManagerProvider/utils/retrieveComponentsFromSchema.js +55 -0
- package/admin/src/containers/DataManagerProvider/utils/retrieveComponentsThatHaveComponents.js +35 -0
- package/admin/src/containers/DataManagerProvider/utils/retrieveNestedComponents.js +34 -0
- package/admin/src/containers/DataManagerProvider/utils/retrieveSpecificInfoFromComponents.js +12 -0
- package/admin/src/containers/FormModal/CustomButton.js +12 -0
- package/admin/src/containers/FormModal/attributes/advancedForm.js +269 -0
- package/admin/src/containers/FormModal/attributes/attributeOptions.js +99 -0
- package/admin/src/containers/FormModal/attributes/baseForm.js +322 -0
- package/admin/src/containers/FormModal/attributes/commonBaseForm.js +7 -0
- package/admin/src/containers/FormModal/attributes/form.js +9 -0
- package/admin/src/containers/FormModal/attributes/index.js +4 -0
- package/admin/src/containers/FormModal/attributes/nameField.js +19 -0
- package/admin/src/containers/FormModal/attributes/types.js +309 -0
- package/admin/src/containers/FormModal/attributes/uiHelpers.js +11 -0
- package/admin/src/containers/FormModal/attributes/validation/common.js +151 -0
- package/admin/src/containers/FormModal/category/createCategorySchema.js +28 -0
- package/admin/src/containers/FormModal/category/form.js +27 -0
- package/admin/src/containers/FormModal/category/index.js +3 -0
- package/admin/src/containers/FormModal/category/regex.js +3 -0
- package/admin/src/containers/FormModal/component/componentField.js +25 -0
- package/admin/src/containers/FormModal/component/createComponentSchema.js +49 -0
- package/admin/src/containers/FormModal/component/form.js +67 -0
- package/admin/src/containers/FormModal/component/index.js +4 -0
- package/admin/src/containers/FormModal/constants.js +11 -0
- package/admin/src/containers/FormModal/contentType/createContentTypeSchema.js +44 -0
- package/admin/src/containers/FormModal/contentType/form.js +116 -0
- package/admin/src/containers/FormModal/contentType/index.js +2 -0
- package/admin/src/containers/FormModal/dynamicZone/form.js +45 -0
- package/admin/src/containers/FormModal/dynamicZone/index.js +2 -0
- package/admin/src/containers/FormModal/forms/index.js +164 -0
- package/admin/src/containers/FormModal/index.js +1552 -0
- package/admin/src/containers/FormModal/reducer.js +293 -0
- package/admin/src/containers/FormModal/selectors.js +24 -0
- package/admin/src/containers/FormModal/utils/canEditContentType.js +19 -0
- package/admin/src/containers/FormModal/utils/createHeadersArray.js +37 -0
- package/admin/src/containers/FormModal/utils/createHeadersObjectFromArray.js +27 -0
- package/admin/src/containers/FormModal/utils/createUid.js +17 -0
- package/admin/src/containers/FormModal/utils/getAttributesToDisplay.js +35 -0
- package/admin/src/containers/FormModal/utils/getModalTitleSubHeader.js +25 -0
- package/admin/src/containers/FormModal/utils/getNextSearch.js +17 -0
- package/admin/src/containers/FormModal/utils/index.js +6 -0
- package/admin/src/containers/FormModal/utils/relations.js +9 -0
- package/admin/src/containers/FormModal/utils/staticData.js +43 -0
- package/admin/src/containers/Initializer/index.js +26 -0
- package/admin/src/containers/LeftMenu/Wrapper.js +14 -0
- package/admin/src/containers/LeftMenu/index.js +220 -0
- package/admin/src/containers/ListView/Wrapper.js +16 -0
- package/admin/src/containers/ListView/index.js +322 -0
- package/admin/src/containers/NotFoundPage/index.js +20 -0
- package/admin/src/containers/RecursivePath/index.js +22 -0
- package/admin/src/contexts/DataManagerContext.js +5 -0
- package/admin/src/contexts/ListViewContext.js +5 -0
- package/admin/src/hooks/useDataManager.js +6 -0
- package/admin/src/hooks/useListView.js +6 -0
- package/admin/src/icons/Curve.js +26 -0
- package/admin/src/icons/ManyToMany.js +98 -0
- package/admin/src/icons/ManyToOne.js +64 -0
- package/admin/src/icons/ManyWay.js +36 -0
- package/admin/src/icons/OneToMany.js +65 -0
- package/admin/src/icons/OneToOne.js +47 -0
- package/admin/src/icons/OneWay.js +38 -0
- package/admin/src/index.js +83 -0
- package/admin/src/lifecycles.js +13 -0
- package/admin/src/permissions.js +9 -0
- package/admin/src/pluginId.js +5 -0
- package/admin/src/reducers.js +10 -0
- package/admin/src/translations/ar.json +48 -0
- package/admin/src/translations/cs.json +151 -0
- package/admin/src/translations/de.json +187 -0
- package/admin/src/translations/dk.json +181 -0
- package/admin/src/translations/en.json +188 -0
- package/admin/src/translations/es.json +188 -0
- package/admin/src/translations/fr.json +87 -0
- package/admin/src/translations/id.json +187 -0
- package/admin/src/translations/index.js +51 -0
- package/admin/src/translations/it.json +187 -0
- package/admin/src/translations/ja.json +50 -0
- package/admin/src/translations/ko.json +57 -0
- package/admin/src/translations/ms.json +179 -0
- package/admin/src/translations/nl.json +171 -0
- package/admin/src/translations/pl.json +152 -0
- package/admin/src/translations/pt-BR.json +51 -0
- package/admin/src/translations/pt.json +51 -0
- package/admin/src/translations/ru.json +188 -0
- package/admin/src/translations/sk.json +186 -0
- package/admin/src/translations/th.json +181 -0
- package/admin/src/translations/tr.json +51 -0
- package/admin/src/translations/uk.json +180 -0
- package/admin/src/translations/zh-Hans.json +188 -0
- package/admin/src/translations/zh.json +178 -0
- package/admin/src/utils/convertAttrObjToArray.js +7 -0
- package/admin/src/utils/formAPI.js +112 -0
- package/admin/src/utils/getAttributeDisplayedType.js +31 -0
- package/admin/src/utils/getComponents.js +31 -0
- package/admin/src/utils/getTrad.js +5 -0
- package/admin/src/utils/makeSearch.js +15 -0
- package/admin/src/utils/makeUnique.js +3 -0
- package/config/functions/bootstrap.js +14 -0
- package/config/routes.json +144 -0
- package/controllers/Builder.js +7 -0
- package/controllers/ComponentCategories.js +43 -0
- package/controllers/Components.js +152 -0
- package/controllers/Connections.js +9 -0
- package/controllers/ContentTypes.js +143 -0
- package/controllers/validation/common.js +118 -0
- package/controllers/validation/component-category.js +21 -0
- package/controllers/validation/component.js +89 -0
- package/controllers/validation/content-type.js +161 -0
- package/controllers/validation/data-transform.js +32 -0
- package/controllers/validation/model-schema.js +91 -0
- package/controllers/validation/relations.js +56 -0
- package/controllers/validation/types.js +277 -0
- package/package.json +63 -0
- package/services/Builder.js +7 -0
- package/services/ComponentCategories.js +88 -0
- package/services/Components.js +103 -0
- package/services/ContentTypes.js +263 -0
- package/services/api-handler.js +158 -0
- package/services/constants.js +59 -0
- package/services/schema-builder/component-builder.js +137 -0
- package/services/schema-builder/content-type-builder.js +256 -0
- package/services/schema-builder/index.js +196 -0
- package/services/schema-builder/schema-handler.js +297 -0
- package/utils/attributes.js +154 -0
- package/utils/helpers.js +31 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const yup = require('yup');
|
|
4
|
+
const { typeKinds, coreUids } = require('../../services/constants');
|
|
5
|
+
const { validators, isValidName } = require('./common');
|
|
6
|
+
|
|
7
|
+
const REVERSE_RELATIONS = ['oneToOne', 'oneToMany', 'manyToOne', 'manyToMany'];
|
|
8
|
+
const STRAPI_USER_RELATIONS = ['oneWay', 'manyWay'];
|
|
9
|
+
|
|
10
|
+
const isValidNature = validNatures =>
|
|
11
|
+
function(value) {
|
|
12
|
+
const allowedRelations =
|
|
13
|
+
this.parent.target === coreUids.STRAPI_USER ? STRAPI_USER_RELATIONS : validNatures;
|
|
14
|
+
|
|
15
|
+
return allowedRelations.includes(value)
|
|
16
|
+
? true
|
|
17
|
+
: this.createError({
|
|
18
|
+
path: this.path,
|
|
19
|
+
message: `must be one of the following values: ${allowedRelations.join(', ')}`,
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports = (obj, validNatures) => {
|
|
24
|
+
const contentTypesUIDs = Object.keys(strapi.contentTypes)
|
|
25
|
+
.filter(key => strapi.contentTypes[key].kind === typeKinds.COLLECTION_TYPE)
|
|
26
|
+
.filter(key => !key.startsWith(coreUids.PREFIX) || key === coreUids.STRAPI_USER)
|
|
27
|
+
.concat(['__self__', '__contentType__']);
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
target: yup
|
|
31
|
+
.string()
|
|
32
|
+
.oneOf(contentTypesUIDs)
|
|
33
|
+
.required(),
|
|
34
|
+
nature: yup
|
|
35
|
+
.string()
|
|
36
|
+
.test('isValidNature', isValidNature(validNatures))
|
|
37
|
+
.required(),
|
|
38
|
+
unique: validators.unique.nullable(),
|
|
39
|
+
configurable: yup.boolean().nullable(),
|
|
40
|
+
autoPopulate: yup.boolean().nullable(),
|
|
41
|
+
dominant: yup.boolean().nullable(),
|
|
42
|
+
columnName: yup.string().nullable(),
|
|
43
|
+
targetAttribute: REVERSE_RELATIONS.includes(obj.nature)
|
|
44
|
+
? yup
|
|
45
|
+
.string()
|
|
46
|
+
.test(isValidName)
|
|
47
|
+
.required()
|
|
48
|
+
: yup
|
|
49
|
+
.string()
|
|
50
|
+
.test(isValidName)
|
|
51
|
+
.nullable(),
|
|
52
|
+
targetColumnName: yup.string().nullable(),
|
|
53
|
+
private: yup.boolean().nullable(),
|
|
54
|
+
pluginOptions: yup.object(),
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const yup = require('yup');
|
|
5
|
+
|
|
6
|
+
const { hasComponent } = require('../../utils/attributes');
|
|
7
|
+
const { modelTypes, VALID_UID_TARGETS } = require('../../services/constants');
|
|
8
|
+
const {
|
|
9
|
+
validators,
|
|
10
|
+
areEnumValuesUnique,
|
|
11
|
+
isValidDefaultJSON,
|
|
12
|
+
isValidName,
|
|
13
|
+
isValidEnum,
|
|
14
|
+
isValidUID,
|
|
15
|
+
isValidRegExpPattern,
|
|
16
|
+
} = require('./common');
|
|
17
|
+
|
|
18
|
+
const maxLengthIsGreaterThanOrEqualToMinLength = {
|
|
19
|
+
name: 'isGreaterThanMin',
|
|
20
|
+
message: 'maxLength must be greater or equal to minLength',
|
|
21
|
+
test: function(value) {
|
|
22
|
+
const { minLength } = this.parent;
|
|
23
|
+
if (!_.isUndefined(minLength) && !_.isUndefined(value) && value < minLength) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return true;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const getTypeValidator = (attribute, { types, modelType, attributes }) => {
|
|
32
|
+
return yup.object({
|
|
33
|
+
type: yup
|
|
34
|
+
.string()
|
|
35
|
+
.oneOf(types)
|
|
36
|
+
.required(),
|
|
37
|
+
configurable: yup.boolean().nullable(),
|
|
38
|
+
private: yup.boolean().nullable(),
|
|
39
|
+
pluginOptions: yup.object(),
|
|
40
|
+
...getTypeShape(attribute, { modelType, attributes }),
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const getTypeShape = (attribute, { modelType, attributes } = {}) => {
|
|
45
|
+
switch (attribute.type) {
|
|
46
|
+
/**
|
|
47
|
+
* complexe types
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
case 'media': {
|
|
51
|
+
return {
|
|
52
|
+
multiple: yup.boolean(),
|
|
53
|
+
required: validators.required,
|
|
54
|
+
unique: validators.unique,
|
|
55
|
+
allowedTypes: yup
|
|
56
|
+
.array()
|
|
57
|
+
.of(yup.string().oneOf(['images', 'videos', 'files']))
|
|
58
|
+
.min(1),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
case 'uid': {
|
|
63
|
+
return {
|
|
64
|
+
required: validators.required,
|
|
65
|
+
targetField: yup
|
|
66
|
+
.string()
|
|
67
|
+
.oneOf(
|
|
68
|
+
Object.keys(attributes).filter(key =>
|
|
69
|
+
VALID_UID_TARGETS.includes(_.get(attributes[key], 'type'))
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
.nullable(),
|
|
73
|
+
default: yup
|
|
74
|
+
.string()
|
|
75
|
+
.test(
|
|
76
|
+
'isValidDefaultUID',
|
|
77
|
+
'cannot define a default UID if the targetField is set',
|
|
78
|
+
function(value) {
|
|
79
|
+
const { targetField } = this.parent;
|
|
80
|
+
if (_.isNil(targetField) || _.isNil(value)) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
.test(isValidUID),
|
|
88
|
+
minLength: validators.minLength,
|
|
89
|
+
maxLength: validators.maxLength.max(256).test(maxLengthIsGreaterThanOrEqualToMinLength),
|
|
90
|
+
options: yup.object().shape({
|
|
91
|
+
separator: yup.string(),
|
|
92
|
+
lowercase: yup.boolean(),
|
|
93
|
+
decamelize: yup.boolean(),
|
|
94
|
+
customReplacements: yup.array().of(
|
|
95
|
+
yup
|
|
96
|
+
.array()
|
|
97
|
+
.of(yup.string())
|
|
98
|
+
.min(2)
|
|
99
|
+
.max(2)
|
|
100
|
+
),
|
|
101
|
+
preserveLeadingUnderscore: yup.boolean(),
|
|
102
|
+
}),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* scalar types
|
|
108
|
+
*/
|
|
109
|
+
case 'string':
|
|
110
|
+
case 'text': {
|
|
111
|
+
return {
|
|
112
|
+
default: yup.string(),
|
|
113
|
+
required: validators.required,
|
|
114
|
+
unique: validators.unique,
|
|
115
|
+
minLength: validators.minLength,
|
|
116
|
+
maxLength: validators.maxLength,
|
|
117
|
+
regex: yup.string().test(isValidRegExpPattern),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
case 'richtext': {
|
|
121
|
+
return {
|
|
122
|
+
default: yup.string(),
|
|
123
|
+
required: validators.required,
|
|
124
|
+
minLength: validators.minLength,
|
|
125
|
+
maxLength: validators.maxLength,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
case 'json': {
|
|
129
|
+
return {
|
|
130
|
+
default: yup.mixed().test(isValidDefaultJSON),
|
|
131
|
+
required: validators.required,
|
|
132
|
+
unique: validators.unique,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
case 'enumeration': {
|
|
136
|
+
return {
|
|
137
|
+
enum: yup
|
|
138
|
+
.array()
|
|
139
|
+
.of(
|
|
140
|
+
yup
|
|
141
|
+
.string()
|
|
142
|
+
.test(isValidEnum)
|
|
143
|
+
.required()
|
|
144
|
+
)
|
|
145
|
+
.min(1)
|
|
146
|
+
.test(areEnumValuesUnique)
|
|
147
|
+
.required(),
|
|
148
|
+
default: yup.string().when('enum', enumVal => yup.string().oneOf(enumVal)),
|
|
149
|
+
enumName: yup.string().test(isValidName),
|
|
150
|
+
required: validators.required,
|
|
151
|
+
unique: validators.unique,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
case 'password': {
|
|
155
|
+
return {
|
|
156
|
+
required: validators.required,
|
|
157
|
+
minLength: validators.minLength,
|
|
158
|
+
maxLength: validators.maxLength,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
case 'email': {
|
|
162
|
+
return {
|
|
163
|
+
default: yup.string().email(),
|
|
164
|
+
required: validators.required,
|
|
165
|
+
unique: validators.unique,
|
|
166
|
+
minLength: validators.minLength,
|
|
167
|
+
maxLength: validators.maxLength,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
case 'integer': {
|
|
171
|
+
return {
|
|
172
|
+
default: yup.number().integer(),
|
|
173
|
+
required: validators.required,
|
|
174
|
+
unique: validators.unique,
|
|
175
|
+
min: yup.number().integer(),
|
|
176
|
+
max: yup.number().integer(),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
case 'biginteger': {
|
|
180
|
+
return {
|
|
181
|
+
default: yup
|
|
182
|
+
.string()
|
|
183
|
+
.nullable()
|
|
184
|
+
.matches(/^\d*$/),
|
|
185
|
+
required: validators.required,
|
|
186
|
+
unique: validators.unique,
|
|
187
|
+
min: yup
|
|
188
|
+
.string()
|
|
189
|
+
.nullable()
|
|
190
|
+
.matches(/^\d*$/),
|
|
191
|
+
max: yup
|
|
192
|
+
.string()
|
|
193
|
+
.nullable()
|
|
194
|
+
.matches(/^\d*$/),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
case 'float': {
|
|
198
|
+
return {
|
|
199
|
+
default: yup.number(),
|
|
200
|
+
required: validators.required,
|
|
201
|
+
unique: validators.unique,
|
|
202
|
+
min: yup.number(),
|
|
203
|
+
max: yup.number(),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
case 'decimal': {
|
|
207
|
+
return {
|
|
208
|
+
default: yup.number(),
|
|
209
|
+
required: validators.required,
|
|
210
|
+
unique: validators.unique,
|
|
211
|
+
min: yup.number(),
|
|
212
|
+
max: yup.number(),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
case 'time':
|
|
216
|
+
case 'datetime':
|
|
217
|
+
case 'date': {
|
|
218
|
+
return {
|
|
219
|
+
default: yup.string(),
|
|
220
|
+
required: validators.required,
|
|
221
|
+
unique: validators.unique,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
case 'boolean': {
|
|
225
|
+
return {
|
|
226
|
+
default: yup.boolean(),
|
|
227
|
+
required: validators.required,
|
|
228
|
+
unique: validators.unique,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
case 'component': {
|
|
233
|
+
return {
|
|
234
|
+
required: validators.required,
|
|
235
|
+
repeatable: yup.boolean(),
|
|
236
|
+
component: yup
|
|
237
|
+
.string()
|
|
238
|
+
.test({
|
|
239
|
+
name: 'Check max component nesting is 1 lvl',
|
|
240
|
+
test: function(compoUID) {
|
|
241
|
+
const targetCompo = strapi.components[compoUID];
|
|
242
|
+
if (!targetCompo) return true; // ignore this error as it will fail beforehand
|
|
243
|
+
|
|
244
|
+
if (modelType === modelTypes.COMPONENT && hasComponent(targetCompo)) {
|
|
245
|
+
return this.createError({
|
|
246
|
+
path: this.path,
|
|
247
|
+
message: `${targetCompo.modelName} already is a nested component. You cannot have more than one level of nesting inside your components.`,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return true;
|
|
251
|
+
},
|
|
252
|
+
})
|
|
253
|
+
.required(),
|
|
254
|
+
min: yup.number(),
|
|
255
|
+
max: yup.number(),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
case 'dynamiczone': {
|
|
260
|
+
return {
|
|
261
|
+
required: validators.required,
|
|
262
|
+
components: yup
|
|
263
|
+
.array()
|
|
264
|
+
.of(yup.string().required())
|
|
265
|
+
.test('isArray', '${path} must be an array', value => Array.isArray(value)),
|
|
266
|
+
min: yup.number(),
|
|
267
|
+
max: yup.number(),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
default: {
|
|
272
|
+
return {};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
module.exports = getTypeValidator;
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@akemona-org/strapi-plugin-content-type-builder",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "3.7.0",
|
|
7
|
+
"description": "Strapi plugin to create content type (API).",
|
|
8
|
+
"strapi": {
|
|
9
|
+
"name": "Content Type Builder",
|
|
10
|
+
"icon": "paint-brush",
|
|
11
|
+
"description": "content-type-builder.plugin.description"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@akemona-org/strapi-generate": "3.7.0",
|
|
15
|
+
"@akemona-org/strapi-generate-api": "3.7.0",
|
|
16
|
+
"@akemona-org/strapi-helper-plugin": "3.7.0",
|
|
17
|
+
"@akemona-org/strapi-utils": "3.7.0",
|
|
18
|
+
"@buffetjs/core": "3.3.8",
|
|
19
|
+
"@buffetjs/custom": "3.3.8",
|
|
20
|
+
"@buffetjs/hooks": "3.3.8",
|
|
21
|
+
"@buffetjs/icons": "3.3.8",
|
|
22
|
+
"@buffetjs/styles": "3.3.8",
|
|
23
|
+
"@buffetjs/utils": "3.3.8",
|
|
24
|
+
"@sindresorhus/slugify": "1.1.0",
|
|
25
|
+
"fs-extra": "^9.1.0",
|
|
26
|
+
"immutable": "^3.8.2",
|
|
27
|
+
"lodash": "4.17.21",
|
|
28
|
+
"pluralize": "^8.0.0",
|
|
29
|
+
"react": "^16.14.0",
|
|
30
|
+
"react-dom": "^16.9.0",
|
|
31
|
+
"react-intl": "4.5.0",
|
|
32
|
+
"react-redux": "7.2.3",
|
|
33
|
+
"react-router": "^5.2.0",
|
|
34
|
+
"react-router-dom": "^5.0.0",
|
|
35
|
+
"reactstrap": "8.4.1",
|
|
36
|
+
"redux": "^4.0.1",
|
|
37
|
+
"redux-immutable": "^4.0.0",
|
|
38
|
+
"reselect": "^4.0.0",
|
|
39
|
+
"yup": "^0.32.9"
|
|
40
|
+
},
|
|
41
|
+
"author": {
|
|
42
|
+
"name": "Akemona team",
|
|
43
|
+
"email": "strapi@akemona.com",
|
|
44
|
+
"url": "https://strapi.akemona.com"
|
|
45
|
+
},
|
|
46
|
+
"maintainers": [
|
|
47
|
+
{
|
|
48
|
+
"name": "Akemona team",
|
|
49
|
+
"email": "strapi@akemona.com",
|
|
50
|
+
"url": "https://strapi.akemona.com"
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git://github.com/akemona/strapi.git"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=10.16.0 <=14.x.x",
|
|
59
|
+
"npm": ">=6.0.0"
|
|
60
|
+
},
|
|
61
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
62
|
+
"gitHead": "129a8d6191b55810fd66448dcc47fee829df986c"
|
|
63
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { join } = require('path');
|
|
4
|
+
|
|
5
|
+
const { nameToSlug } = require('@akemona-org/strapi-utils');
|
|
6
|
+
const createBuilder = require('./schema-builder');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Edit a category name and move components to the write folder
|
|
10
|
+
* @param {string} name category name
|
|
11
|
+
* @param {Object} infos new category data
|
|
12
|
+
*/
|
|
13
|
+
const editCategory = async (name, infos) => {
|
|
14
|
+
const componentsDir = join(strapi.dir, 'components');
|
|
15
|
+
const newName = nameToSlug(infos.name);
|
|
16
|
+
|
|
17
|
+
// don't do anything the name doesn't change
|
|
18
|
+
if (name === newName) return;
|
|
19
|
+
|
|
20
|
+
if (!categoryExists(name)) {
|
|
21
|
+
throw strapi.errors.notFound('cateogry.notFound');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (categoryExists(newName)) {
|
|
25
|
+
throw strapi.errors.badRequest('Name already taken');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const builder = createBuilder();
|
|
29
|
+
|
|
30
|
+
builder.components.forEach((component) => {
|
|
31
|
+
const oldUID = component.uid;
|
|
32
|
+
const newUID = `${newName}.${component.modelName}`;
|
|
33
|
+
|
|
34
|
+
// only edit the components in this specific category
|
|
35
|
+
if (component.category !== name) return;
|
|
36
|
+
|
|
37
|
+
component.setUID(newUID).setDir(join(componentsDir, newName));
|
|
38
|
+
|
|
39
|
+
builder.components.forEach((compo) => {
|
|
40
|
+
compo.updateComponent(oldUID, newUID);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
builder.contentTypes.forEach((ct) => {
|
|
44
|
+
ct.updateComponent(oldUID, newUID);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await builder.writeFiles();
|
|
49
|
+
|
|
50
|
+
return newName;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Deletes a category and its components
|
|
55
|
+
* @param {string} name category name to delete
|
|
56
|
+
*/
|
|
57
|
+
const deleteCategory = async (name) => {
|
|
58
|
+
if (!categoryExists(name)) {
|
|
59
|
+
throw strapi.errors.notFound('cateogry.notFound');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const builder = createBuilder();
|
|
63
|
+
|
|
64
|
+
builder.components.forEach((component) => {
|
|
65
|
+
if (component.category === name) {
|
|
66
|
+
builder.deleteComponent(component.uid);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
await builder.writeFiles();
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Checks if a category exists
|
|
75
|
+
* @param {string} name category name to serach for
|
|
76
|
+
*/
|
|
77
|
+
const categoryExists = (name) => {
|
|
78
|
+
const matchingIndex = Object.values(strapi.components).findIndex(
|
|
79
|
+
(component) => component.category === name
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
return matchingIndex > -1;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
module.exports = {
|
|
86
|
+
editCategory,
|
|
87
|
+
deleteCategory,
|
|
88
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const pluralize = require('pluralize');
|
|
5
|
+
|
|
6
|
+
const { formatAttributes, replaceTemporaryUIDs } = require('../utils/attributes');
|
|
7
|
+
const createBuilder = require('./schema-builder');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Formats a component attributes
|
|
11
|
+
* @param {string} uid - string
|
|
12
|
+
* @param {Object} component - strapi component model
|
|
13
|
+
*/
|
|
14
|
+
const formatComponent = component => {
|
|
15
|
+
const { uid, modelName, connection, collectionName, info, category } = component;
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
uid,
|
|
19
|
+
category,
|
|
20
|
+
apiId: modelName,
|
|
21
|
+
schema: {
|
|
22
|
+
icon: _.get(info, 'icon'),
|
|
23
|
+
name: _.get(info, 'name') || _.upperFirst(pluralize(uid)),
|
|
24
|
+
description: _.get(info, 'description', ''),
|
|
25
|
+
connection,
|
|
26
|
+
collectionName,
|
|
27
|
+
pluginOptions: component.pluginOptions,
|
|
28
|
+
attributes: formatAttributes(component),
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Creates a component and handle the nested components sent with it
|
|
35
|
+
* @param {Object} params params object
|
|
36
|
+
* @param {Object} params.component Main component to create
|
|
37
|
+
* @param {Array<Object>} params.components List of nested components to created or edit
|
|
38
|
+
*/
|
|
39
|
+
const createComponent = async ({ component, components = [] }) => {
|
|
40
|
+
const builder = createBuilder();
|
|
41
|
+
|
|
42
|
+
const uidMap = builder.createNewComponentUIDMap(components);
|
|
43
|
+
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
|
44
|
+
|
|
45
|
+
const newComponent = builder.createComponent(replaceTmpUIDs(component));
|
|
46
|
+
|
|
47
|
+
components.forEach(component => {
|
|
48
|
+
if (!_.has(component, 'uid')) {
|
|
49
|
+
return builder.createComponent(replaceTmpUIDs(component));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return builder.editComponent(replaceTmpUIDs(component));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await builder.writeFiles();
|
|
56
|
+
return newComponent;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Edits a component and handle the nested components sent with it
|
|
61
|
+
* @param {Object} params params object
|
|
62
|
+
* @param {Object} params.component Main component to create
|
|
63
|
+
* @param {Array<Object>} params.components List of nested components to created or edit
|
|
64
|
+
*/
|
|
65
|
+
const editComponent = async (uid, { component, components = [] }) => {
|
|
66
|
+
const builder = createBuilder();
|
|
67
|
+
|
|
68
|
+
const uidMap = builder.createNewComponentUIDMap(components);
|
|
69
|
+
const replaceTmpUIDs = replaceTemporaryUIDs(uidMap);
|
|
70
|
+
|
|
71
|
+
const updatedComponent = builder.editComponent({
|
|
72
|
+
uid,
|
|
73
|
+
...replaceTmpUIDs(component),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
components.forEach(component => {
|
|
77
|
+
if (!_.has(component, 'uid')) {
|
|
78
|
+
return builder.createComponent(replaceTmpUIDs(component));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return builder.editComponent(replaceTmpUIDs(component));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
await builder.writeFiles();
|
|
85
|
+
return updatedComponent;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const deleteComponent = async uid => {
|
|
89
|
+
const builder = createBuilder();
|
|
90
|
+
|
|
91
|
+
const deletedComponent = builder.deleteComponent(uid);
|
|
92
|
+
|
|
93
|
+
await builder.writeFiles();
|
|
94
|
+
return deletedComponent;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
module.exports = {
|
|
98
|
+
createComponent,
|
|
99
|
+
editComponent,
|
|
100
|
+
deleteComponent,
|
|
101
|
+
|
|
102
|
+
formatComponent,
|
|
103
|
+
};
|