@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.
Files changed (223) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -0
  3. package/admin/src/InjectedComponents/ContentManager/EditSettingViewButton.js +76 -0
  4. package/admin/src/InjectedComponents/ContentManager/EditViewLink.js +44 -0
  5. package/admin/src/assets/images/logo.svg +1 -0
  6. package/admin/src/components/AllowedTypesSelect/MenuList.js +115 -0
  7. package/admin/src/components/AllowedTypesSelect/Text.js +26 -0
  8. package/admin/src/components/AllowedTypesSelect/index.js +55 -0
  9. package/admin/src/components/AttributeOption/Button.js +50 -0
  10. package/admin/src/components/AttributeOption/Card.js +26 -0
  11. package/admin/src/components/AttributeOption/index.js +127 -0
  12. package/admin/src/components/BooleanBox/CT.js +21 -0
  13. package/admin/src/components/BooleanBox/Enumeration.js +10 -0
  14. package/admin/src/components/BooleanBox/EnumerationWrapper.js +14 -0
  15. package/admin/src/components/BooleanBox/Label.js +9 -0
  16. package/admin/src/components/BooleanBox/ST.js +21 -0
  17. package/admin/src/components/BooleanBox/Wrapper.js +75 -0
  18. package/admin/src/components/BooleanBox/icons/CTSelected.js +136 -0
  19. package/admin/src/components/BooleanBox/icons/CTUnselected.js +136 -0
  20. package/admin/src/components/BooleanBox/icons/STSelected.js +80 -0
  21. package/admin/src/components/BooleanBox/icons/STUnselected.js +76 -0
  22. package/admin/src/components/BooleanBox/index.js +103 -0
  23. package/admin/src/components/CheckboxWithDescription/Wrapper.js +12 -0
  24. package/admin/src/components/CheckboxWithDescription/index.js +40 -0
  25. package/admin/src/components/ComponentCard/Close.js +12 -0
  26. package/admin/src/components/ComponentCard/Wrapper.js +84 -0
  27. package/admin/src/components/ComponentCard/index.js +62 -0
  28. package/admin/src/components/ComponentIconPicker/Cell.js +40 -0
  29. package/admin/src/components/ComponentIconPicker/CellRenderer.js +36 -0
  30. package/admin/src/components/ComponentIconPicker/Search.js +12 -0
  31. package/admin/src/components/ComponentIconPicker/SearchWrapper.js +34 -0
  32. package/admin/src/components/ComponentIconPicker/Wrapper.js +60 -0
  33. package/admin/src/components/ComponentIconPicker/index.js +143 -0
  34. package/admin/src/components/ComponentList/index.js +78 -0
  35. package/admin/src/components/ComponentSelect/Category.js +20 -0
  36. package/admin/src/components/ComponentSelect/CategoryName.js +11 -0
  37. package/admin/src/components/ComponentSelect/MenuList.js +110 -0
  38. package/admin/src/components/ComponentSelect/MultipleMenuList.js +271 -0
  39. package/admin/src/components/ComponentSelect/Value.js +83 -0
  40. package/admin/src/components/ComponentSelect/index.js +83 -0
  41. package/admin/src/components/ComponentSelect/utils/HasSomeSubArray.js +5 -0
  42. package/admin/src/components/ComponentSelect/utils/hasSubArray.js +5 -0
  43. package/admin/src/components/CreatableSelect/index.js +58 -0
  44. package/admin/src/components/CustomCheckbox/StyledCustomCheckbox.js +25 -0
  45. package/admin/src/components/CustomCheckbox/index.js +71 -0
  46. package/admin/src/components/CustomLink/P.js +17 -0
  47. package/admin/src/components/CustomLink/StyledCustomLink.js +20 -0
  48. package/admin/src/components/CustomLink/index.js +31 -0
  49. package/admin/src/components/DynamicZoneList/ComponentButton.js +39 -0
  50. package/admin/src/components/DynamicZoneList/index.js +124 -0
  51. package/admin/src/components/HeaderModalNavContainer/index.js +25 -0
  52. package/admin/src/components/HeaderNavLink/Wrapper.js +21 -0
  53. package/admin/src/components/HeaderNavLink/index.js +50 -0
  54. package/admin/src/components/List/List.js +131 -0
  55. package/admin/src/components/List/index.js +295 -0
  56. package/admin/src/components/ListButton/index.js +9 -0
  57. package/admin/src/components/ListHeader/Title.js +19 -0
  58. package/admin/src/components/ListHeader/Wrapper.js +24 -0
  59. package/admin/src/components/ListHeader/index.js +37 -0
  60. package/admin/src/components/ListRow/Wrapper.js +76 -0
  61. package/admin/src/components/ListRow/index.js +334 -0
  62. package/admin/src/components/ModalHeader/ComponentIcon.js +21 -0
  63. package/admin/src/components/ModalHeader/ComponentInfos.js +22 -0
  64. package/admin/src/components/ModalHeader/ComponentInfosWrapper.js +9 -0
  65. package/admin/src/components/ModalHeader/DropdownInfos.js +50 -0
  66. package/admin/src/components/ModalHeader/Icon.js +26 -0
  67. package/admin/src/components/ModalHeader/IconWrapper.js +11 -0
  68. package/admin/src/components/ModalHeader/Item.js +19 -0
  69. package/admin/src/components/ModalHeader/Menu.js +8 -0
  70. package/admin/src/components/ModalHeader/Toggle.js +14 -0
  71. package/admin/src/components/ModalHeader/Wrapper.js +12 -0
  72. package/admin/src/components/ModalHeader/index.js +105 -0
  73. package/admin/src/components/RelationForm/Wrapper.js +9 -0
  74. package/admin/src/components/RelationForm/index.js +66 -0
  75. package/admin/src/components/RelationFormBox/Wrapper.js +34 -0
  76. package/admin/src/components/RelationFormBox/index.js +85 -0
  77. package/admin/src/components/RelationFormNaturePicker/Wrapper.js +53 -0
  78. package/admin/src/components/RelationFormNaturePicker/index.js +112 -0
  79. package/admin/src/components/RelationTargetPicker/Item.js +62 -0
  80. package/admin/src/components/RelationTargetPicker/Wrapper.js +89 -0
  81. package/admin/src/components/RelationTargetPicker/index.js +88 -0
  82. package/admin/src/components/SelectCheckbox/index.js +8 -0
  83. package/admin/src/components/SelectMenuSubUl/ToggleUl.js +23 -0
  84. package/admin/src/components/SelectMenuSubUl/index.js +23 -0
  85. package/admin/src/components/SelectMenuUl/index.js +66 -0
  86. package/admin/src/components/Td/index.js +37 -0
  87. package/admin/src/components/UpperFirst/index.js +14 -0
  88. package/admin/src/components/WrapperSelect/index.js +89 -0
  89. package/admin/src/containers/App/Wrapper.js +14 -0
  90. package/admin/src/containers/App/index.js +39 -0
  91. package/admin/src/containers/App/utils/icons.json +962 -0
  92. package/admin/src/containers/DataManagerProvider/constants.js +15 -0
  93. package/admin/src/containers/DataManagerProvider/index.js +610 -0
  94. package/admin/src/containers/DataManagerProvider/reducer.js +461 -0
  95. package/admin/src/containers/DataManagerProvider/selectors.js +25 -0
  96. package/admin/src/containers/DataManagerProvider/utils/cleanData.js +167 -0
  97. package/admin/src/containers/DataManagerProvider/utils/createDataObject.js +8 -0
  98. package/admin/src/containers/DataManagerProvider/utils/createModifiedDataSchema.js +91 -0
  99. package/admin/src/containers/DataManagerProvider/utils/retrieveComponentsFromSchema.js +55 -0
  100. package/admin/src/containers/DataManagerProvider/utils/retrieveComponentsThatHaveComponents.js +35 -0
  101. package/admin/src/containers/DataManagerProvider/utils/retrieveNestedComponents.js +34 -0
  102. package/admin/src/containers/DataManagerProvider/utils/retrieveSpecificInfoFromComponents.js +12 -0
  103. package/admin/src/containers/FormModal/CustomButton.js +12 -0
  104. package/admin/src/containers/FormModal/attributes/advancedForm.js +269 -0
  105. package/admin/src/containers/FormModal/attributes/attributeOptions.js +99 -0
  106. package/admin/src/containers/FormModal/attributes/baseForm.js +322 -0
  107. package/admin/src/containers/FormModal/attributes/commonBaseForm.js +7 -0
  108. package/admin/src/containers/FormModal/attributes/form.js +9 -0
  109. package/admin/src/containers/FormModal/attributes/index.js +4 -0
  110. package/admin/src/containers/FormModal/attributes/nameField.js +19 -0
  111. package/admin/src/containers/FormModal/attributes/types.js +309 -0
  112. package/admin/src/containers/FormModal/attributes/uiHelpers.js +11 -0
  113. package/admin/src/containers/FormModal/attributes/validation/common.js +151 -0
  114. package/admin/src/containers/FormModal/category/createCategorySchema.js +28 -0
  115. package/admin/src/containers/FormModal/category/form.js +27 -0
  116. package/admin/src/containers/FormModal/category/index.js +3 -0
  117. package/admin/src/containers/FormModal/category/regex.js +3 -0
  118. package/admin/src/containers/FormModal/component/componentField.js +25 -0
  119. package/admin/src/containers/FormModal/component/createComponentSchema.js +49 -0
  120. package/admin/src/containers/FormModal/component/form.js +67 -0
  121. package/admin/src/containers/FormModal/component/index.js +4 -0
  122. package/admin/src/containers/FormModal/constants.js +11 -0
  123. package/admin/src/containers/FormModal/contentType/createContentTypeSchema.js +44 -0
  124. package/admin/src/containers/FormModal/contentType/form.js +116 -0
  125. package/admin/src/containers/FormModal/contentType/index.js +2 -0
  126. package/admin/src/containers/FormModal/dynamicZone/form.js +45 -0
  127. package/admin/src/containers/FormModal/dynamicZone/index.js +2 -0
  128. package/admin/src/containers/FormModal/forms/index.js +164 -0
  129. package/admin/src/containers/FormModal/index.js +1552 -0
  130. package/admin/src/containers/FormModal/reducer.js +293 -0
  131. package/admin/src/containers/FormModal/selectors.js +24 -0
  132. package/admin/src/containers/FormModal/utils/canEditContentType.js +19 -0
  133. package/admin/src/containers/FormModal/utils/createHeadersArray.js +37 -0
  134. package/admin/src/containers/FormModal/utils/createHeadersObjectFromArray.js +27 -0
  135. package/admin/src/containers/FormModal/utils/createUid.js +17 -0
  136. package/admin/src/containers/FormModal/utils/getAttributesToDisplay.js +35 -0
  137. package/admin/src/containers/FormModal/utils/getModalTitleSubHeader.js +25 -0
  138. package/admin/src/containers/FormModal/utils/getNextSearch.js +17 -0
  139. package/admin/src/containers/FormModal/utils/index.js +6 -0
  140. package/admin/src/containers/FormModal/utils/relations.js +9 -0
  141. package/admin/src/containers/FormModal/utils/staticData.js +43 -0
  142. package/admin/src/containers/Initializer/index.js +26 -0
  143. package/admin/src/containers/LeftMenu/Wrapper.js +14 -0
  144. package/admin/src/containers/LeftMenu/index.js +220 -0
  145. package/admin/src/containers/ListView/Wrapper.js +16 -0
  146. package/admin/src/containers/ListView/index.js +322 -0
  147. package/admin/src/containers/NotFoundPage/index.js +20 -0
  148. package/admin/src/containers/RecursivePath/index.js +22 -0
  149. package/admin/src/contexts/DataManagerContext.js +5 -0
  150. package/admin/src/contexts/ListViewContext.js +5 -0
  151. package/admin/src/hooks/useDataManager.js +6 -0
  152. package/admin/src/hooks/useListView.js +6 -0
  153. package/admin/src/icons/Curve.js +26 -0
  154. package/admin/src/icons/ManyToMany.js +98 -0
  155. package/admin/src/icons/ManyToOne.js +64 -0
  156. package/admin/src/icons/ManyWay.js +36 -0
  157. package/admin/src/icons/OneToMany.js +65 -0
  158. package/admin/src/icons/OneToOne.js +47 -0
  159. package/admin/src/icons/OneWay.js +38 -0
  160. package/admin/src/index.js +83 -0
  161. package/admin/src/lifecycles.js +13 -0
  162. package/admin/src/permissions.js +9 -0
  163. package/admin/src/pluginId.js +5 -0
  164. package/admin/src/reducers.js +10 -0
  165. package/admin/src/translations/ar.json +48 -0
  166. package/admin/src/translations/cs.json +151 -0
  167. package/admin/src/translations/de.json +187 -0
  168. package/admin/src/translations/dk.json +181 -0
  169. package/admin/src/translations/en.json +188 -0
  170. package/admin/src/translations/es.json +188 -0
  171. package/admin/src/translations/fr.json +87 -0
  172. package/admin/src/translations/id.json +187 -0
  173. package/admin/src/translations/index.js +51 -0
  174. package/admin/src/translations/it.json +187 -0
  175. package/admin/src/translations/ja.json +50 -0
  176. package/admin/src/translations/ko.json +57 -0
  177. package/admin/src/translations/ms.json +179 -0
  178. package/admin/src/translations/nl.json +171 -0
  179. package/admin/src/translations/pl.json +152 -0
  180. package/admin/src/translations/pt-BR.json +51 -0
  181. package/admin/src/translations/pt.json +51 -0
  182. package/admin/src/translations/ru.json +188 -0
  183. package/admin/src/translations/sk.json +186 -0
  184. package/admin/src/translations/th.json +181 -0
  185. package/admin/src/translations/tr.json +51 -0
  186. package/admin/src/translations/uk.json +180 -0
  187. package/admin/src/translations/zh-Hans.json +188 -0
  188. package/admin/src/translations/zh.json +178 -0
  189. package/admin/src/utils/convertAttrObjToArray.js +7 -0
  190. package/admin/src/utils/formAPI.js +112 -0
  191. package/admin/src/utils/getAttributeDisplayedType.js +31 -0
  192. package/admin/src/utils/getComponents.js +31 -0
  193. package/admin/src/utils/getTrad.js +5 -0
  194. package/admin/src/utils/makeSearch.js +15 -0
  195. package/admin/src/utils/makeUnique.js +3 -0
  196. package/config/functions/bootstrap.js +14 -0
  197. package/config/routes.json +144 -0
  198. package/controllers/Builder.js +7 -0
  199. package/controllers/ComponentCategories.js +43 -0
  200. package/controllers/Components.js +152 -0
  201. package/controllers/Connections.js +9 -0
  202. package/controllers/ContentTypes.js +143 -0
  203. package/controllers/validation/common.js +118 -0
  204. package/controllers/validation/component-category.js +21 -0
  205. package/controllers/validation/component.js +89 -0
  206. package/controllers/validation/content-type.js +161 -0
  207. package/controllers/validation/data-transform.js +32 -0
  208. package/controllers/validation/model-schema.js +91 -0
  209. package/controllers/validation/relations.js +56 -0
  210. package/controllers/validation/types.js +277 -0
  211. package/package.json +63 -0
  212. package/services/Builder.js +7 -0
  213. package/services/ComponentCategories.js +88 -0
  214. package/services/Components.js +103 -0
  215. package/services/ContentTypes.js +263 -0
  216. package/services/api-handler.js +158 -0
  217. package/services/constants.js +59 -0
  218. package/services/schema-builder/component-builder.js +137 -0
  219. package/services/schema-builder/content-type-builder.js +256 -0
  220. package/services/schema-builder/index.js +196 -0
  221. package/services/schema-builder/schema-handler.js +297 -0
  222. package/utils/attributes.js +154 -0
  223. package/utils/helpers.js +31 -0
@@ -0,0 +1,110 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { components } from 'react-select';
4
+ import { upperFirst } from 'lodash';
5
+ import { useQuery } from 'strapi-helper-plugin';
6
+ import useDataManager from '../../hooks/useDataManager';
7
+ import Ul from '../SelectMenuUl';
8
+ import Category from './Category';
9
+
10
+ /* eslint-disable jsx-a11y/click-events-have-key-events */
11
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
12
+ /* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
13
+
14
+ const MenuList = ({
15
+ selectProps: { isAddingAComponentToAnotherComponent, name, onClickOption, refState, value },
16
+ ...rest
17
+ }) => {
18
+ const {
19
+ componentsGroupedByCategory,
20
+ componentsThatHaveOtherComponentInTheirAttributes,
21
+ } = useDataManager();
22
+
23
+ const query = useQuery();
24
+ const Component = components.MenuList;
25
+ const forTarget = query.get('forTarget');
26
+ const uid = query.get('targetUid');
27
+ const isTargetAComponent = ['component', 'components'].includes(forTarget);
28
+
29
+ return (
30
+ <Component {...rest}>
31
+ <Ul>
32
+ {Object.keys(componentsGroupedByCategory)
33
+ .sort()
34
+ .map(categoryName => {
35
+ return (
36
+ <li key={categoryName}>
37
+ <Category categoryName={categoryName} />
38
+ <Ul style={{ marginTop: '-4px' }} maxHeight="100%">
39
+ {componentsGroupedByCategory[categoryName].map(component => {
40
+ if (
41
+ (isAddingAComponentToAnotherComponent &&
42
+ componentsThatHaveOtherComponentInTheirAttributes.includes(
43
+ component.uid
44
+ )) ||
45
+ (isTargetAComponent && component.uid === uid)
46
+ ) {
47
+ return null;
48
+ }
49
+
50
+ const isSelected = value.value === component.uid;
51
+
52
+ return (
53
+ <li
54
+ key={component.uid}
55
+ className="li"
56
+ onClick={() => {
57
+ refState.current.select.blur();
58
+ onClickOption({
59
+ target: { name, value: component.uid },
60
+ });
61
+ }}
62
+ >
63
+ <p
64
+ datadescr={upperFirst(component.schema.name)}
65
+ style={{
66
+ color: isSelected ? '#007eff' : '',
67
+ fontWeight: isSelected ? '700' : '400',
68
+ }}
69
+ >
70
+ {upperFirst(component.schema.name)}
71
+ </p>
72
+ </li>
73
+ );
74
+ })}
75
+ </Ul>
76
+ </li>
77
+ );
78
+ })}
79
+ </Ul>
80
+ </Component>
81
+ );
82
+ };
83
+
84
+ MenuList.defaultProps = {
85
+ selectProps: {
86
+ isAddingAComponentToAnotherComponent: false,
87
+ refState: {
88
+ current: {
89
+ select: {
90
+ blur: () => {},
91
+ },
92
+ },
93
+ },
94
+ value: {
95
+ value: '',
96
+ },
97
+ },
98
+ };
99
+
100
+ MenuList.propTypes = {
101
+ selectProps: PropTypes.shape({
102
+ isAddingAComponentToAnotherComponent: PropTypes.bool,
103
+ name: PropTypes.string.isRequired,
104
+ onClickOption: PropTypes.func.isRequired,
105
+ refState: PropTypes.object,
106
+ value: PropTypes.object,
107
+ }),
108
+ };
109
+
110
+ export default MenuList;
@@ -0,0 +1,271 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { components } from 'react-select';
4
+ import { FormattedMessage } from 'react-intl';
5
+ import { get } from 'lodash';
6
+ import { useQuery } from 'strapi-helper-plugin';
7
+ import { CheckboxWrapper, Label } from '@buffetjs/styles';
8
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
9
+ import useDataManager from '../../hooks/useDataManager';
10
+ import getTrad from '../../utils/getTrad';
11
+ import SelectCheckbox from '../SelectCheckbox';
12
+ import Ul from '../SelectMenuUl';
13
+ import SubUl from '../SelectMenuSubUl';
14
+ import UpperFirst from '../UpperFirst';
15
+
16
+ import hasSubArray from './utils/hasSubArray';
17
+ import hasSomeSubArray from './utils/HasSomeSubArray';
18
+
19
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
20
+ /* eslint-disable jsx-a11y/click-events-have-key-events */
21
+
22
+ const MultipleMenuList = ({
23
+ selectProps: { name, addComponentsToDynamicZone, inputValue, value },
24
+ ...rest
25
+ }) => {
26
+ const { componentsGroupedByCategory, modifiedData } = useDataManager();
27
+ const query = useQuery();
28
+ const dzName = query.get('dynamicZoneTarget');
29
+ const alreadyUsedComponents = get(
30
+ modifiedData,
31
+ ['contentType', 'schema', 'attributes', dzName, 'components'],
32
+ []
33
+ );
34
+ const filteredComponentsGroupedByCategory = Object.keys(componentsGroupedByCategory).reduce(
35
+ (acc, current) => {
36
+ const filteredComponents = componentsGroupedByCategory[current].filter(({ uid }) => {
37
+ return !alreadyUsedComponents.includes(uid);
38
+ });
39
+
40
+ if (filteredComponents.length > 0) {
41
+ acc[current] = filteredComponents;
42
+ }
43
+
44
+ return acc;
45
+ },
46
+ {}
47
+ );
48
+
49
+ const collapsesObject = Object.keys(filteredComponentsGroupedByCategory).reduce(
50
+ (acc, current) => {
51
+ acc[current] = false;
52
+
53
+ return acc;
54
+ },
55
+ {}
56
+ );
57
+ const [collapses, setCollapses] = useState(collapsesObject);
58
+ const [options, setOptions] = useState(filteredComponentsGroupedByCategory);
59
+
60
+ // Search for component
61
+ useEffect(() => {
62
+ const formattedOptions = Object.keys(filteredComponentsGroupedByCategory).reduce(
63
+ (acc, current) => {
64
+ const filteredComponents = filteredComponentsGroupedByCategory[current].filter(
65
+ ({ schema: { name } }) => {
66
+ return name.includes(inputValue);
67
+ }
68
+ );
69
+
70
+ if (filteredComponents.length > 0) {
71
+ acc[current] = filteredComponents;
72
+ }
73
+
74
+ return acc;
75
+ },
76
+ {}
77
+ );
78
+
79
+ setOptions(formattedOptions);
80
+
81
+ const categoriesToOpen = Object.keys(formattedOptions);
82
+
83
+ if (inputValue !== '') {
84
+ // Close collapses
85
+ Object.keys(filteredComponentsGroupedByCategory)
86
+ .filter(cat => categoriesToOpen.indexOf(cat) === -1)
87
+ .forEach(catName => {
88
+ setCollapses(prevState => ({ ...prevState, [catName]: false }));
89
+ });
90
+
91
+ categoriesToOpen.forEach(catName => {
92
+ setCollapses(prevState => ({ ...prevState, [catName]: true }));
93
+ });
94
+ } else {
95
+ // Close all collapses
96
+ categoriesToOpen.forEach((catName, index) => {
97
+ setCollapses(prevState => ({ ...prevState, [catName]: index === 0 }));
98
+ });
99
+ }
100
+ // eslint-disable-next-line react-hooks/exhaustive-deps
101
+ }, [inputValue]);
102
+
103
+ const toggleCollapse = catName => {
104
+ setCollapses(prevState => ({
105
+ ...prevState,
106
+ [catName]: !prevState[catName],
107
+ }));
108
+ };
109
+
110
+ const Component = components.MenuList;
111
+
112
+ const allComponentsCategory = Object.keys(options).reduce((acc, current) => {
113
+ const categoryCompos = options[current].map(compo => {
114
+ return compo.uid;
115
+ });
116
+
117
+ acc[current] = categoryCompos;
118
+
119
+ return acc;
120
+ }, {});
121
+
122
+ const getCategoryValue = categoryName => {
123
+ const componentsCategory = allComponentsCategory[categoryName];
124
+
125
+ return hasSubArray(value.value, componentsCategory);
126
+ };
127
+
128
+ const doesCategoryHasSomeElements = categoryName => {
129
+ const componentsCategory = allComponentsCategory[categoryName];
130
+
131
+ return hasSomeSubArray(value.value, componentsCategory);
132
+ };
133
+
134
+ const handleChangeCategory = ({ target }) => {
135
+ // refState.current.select.blur();
136
+ const dataTarget = {
137
+ name,
138
+ components: allComponentsCategory[target.name],
139
+ shouldAddComponents: target.value,
140
+ };
141
+ addComponentsToDynamicZone({ target: dataTarget });
142
+ };
143
+
144
+ const handleChange = ({ target }) => {
145
+ const dataTarget = {
146
+ name,
147
+ components: [target.name],
148
+ shouldAddComponents: target.value,
149
+ };
150
+
151
+ addComponentsToDynamicZone({ target: dataTarget });
152
+ };
153
+
154
+ return (
155
+ <Component {...rest}>
156
+ <Ul>
157
+ {Object.keys(options).length === 0 && (
158
+ <FormattedMessage
159
+ id={getTrad(
160
+ `components.componentSelect.no-component-available${
161
+ inputValue === '' ? '' : '.with-search'
162
+ }`
163
+ )}
164
+ >
165
+ {msg => <li style={{ paddingTop: 11 }}>{msg}</li>}
166
+ </FormattedMessage>
167
+ )}
168
+ {Object.keys(options).map(categoryName => {
169
+ const isChecked = getCategoryValue(categoryName);
170
+ const someChecked = !isChecked && doesCategoryHasSomeElements(categoryName);
171
+ const target = { name: categoryName, value: !isChecked };
172
+
173
+ return (
174
+ <li key={categoryName} className="li-multi-menu">
175
+ <div style={{ marginTop: 3 }}>
176
+ <CheckboxWrapper style={{ display: 'flex' }}>
177
+ <Label
178
+ htmlFor="overrideReactSelectBehavior"
179
+ onClick={() => {
180
+ handleChangeCategory({ target });
181
+ }}
182
+ >
183
+ <SelectCheckbox
184
+ id="checkCategory"
185
+ checked={isChecked}
186
+ name={categoryName}
187
+ onChange={() => {}}
188
+ someChecked={someChecked}
189
+ />
190
+ <UpperFirst content={categoryName} />
191
+ </Label>
192
+ <div
193
+ style={{
194
+ width: '150px',
195
+ textAlign: 'right',
196
+ flexGrow: 2,
197
+ }}
198
+ onClick={e => {
199
+ e.stopPropagation();
200
+ toggleCollapse(categoryName);
201
+ }}
202
+ >
203
+ <FontAwesomeIcon
204
+ className="chevron"
205
+ icon={collapses[categoryName] ? 'chevron-up' : 'chevron-down'}
206
+ />
207
+ </div>
208
+ </CheckboxWrapper>
209
+ </div>
210
+ <SubUl tag="ul" isOpen={collapses[categoryName]}>
211
+ {options[categoryName].map(component => {
212
+ const isChecked = get(value, 'value', []).includes(component.uid);
213
+ const target = { name: component.uid, value: !isChecked };
214
+
215
+ return (
216
+ <li key={component.uid}>
217
+ <CheckboxWrapper>
218
+ <Label
219
+ htmlFor={component.uid}
220
+ message={component.schema.name}
221
+ onClick={() => {
222
+ handleChange({ target });
223
+ }}
224
+ >
225
+ <SelectCheckbox
226
+ id="check"
227
+ name={component.uid}
228
+ // Remove the handler
229
+ onChange={() => {}}
230
+ checked={isChecked}
231
+ />
232
+ {component.schema.name}
233
+ </Label>
234
+ </CheckboxWrapper>
235
+ </li>
236
+ );
237
+ })}
238
+ </SubUl>
239
+ </li>
240
+ );
241
+ })}
242
+ </Ul>
243
+ </Component>
244
+ );
245
+ };
246
+
247
+ MultipleMenuList.defaultProps = {
248
+ selectProps: {
249
+ inputValue: '',
250
+ refState: {
251
+ current: {
252
+ select: {
253
+ blur: () => {},
254
+ },
255
+ },
256
+ },
257
+ value: {},
258
+ },
259
+ };
260
+
261
+ MultipleMenuList.propTypes = {
262
+ selectProps: PropTypes.shape({
263
+ addComponentsToDynamicZone: PropTypes.func.isRequired,
264
+ inputValue: PropTypes.string,
265
+ name: PropTypes.string.isRequired,
266
+ refState: PropTypes.object,
267
+ value: PropTypes.object,
268
+ }),
269
+ };
270
+
271
+ export default MultipleMenuList;
@@ -0,0 +1,83 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { components } from 'react-select';
4
+ import { get, size } from 'lodash';
5
+ import { FormattedMessage } from 'react-intl';
6
+ import useDataManager from '../../hooks/useDataManager';
7
+ import getTrad from '../../utils/getTrad';
8
+ import UpperFirst from '../UpperFirst';
9
+
10
+ const Value = ({ children, ...props }) => {
11
+ const SingleValue = components.SingleValue;
12
+ const { components: appComponents } = useDataManager();
13
+ const value = children;
14
+ const selectedComponent = get(appComponents, value, {
15
+ category: '',
16
+ schema: { name: '' },
17
+ });
18
+ const {
19
+ category,
20
+ schema: { name },
21
+ } = selectedComponent;
22
+ const {
23
+ selectProps: {
24
+ componentCategory,
25
+ componentName,
26
+ isCreatingComponent,
27
+ isMultiple,
28
+ },
29
+ } = props;
30
+
31
+ const displayedCategory = isCreatingComponent ? componentCategory : category;
32
+ const displayedName = isCreatingComponent ? componentName : name;
33
+ const style = { color: '#333740' };
34
+ const valueLength = size(value);
35
+ const message =
36
+ valueLength > '0'
37
+ ? getTrad('components.componentSelect.value-components')
38
+ : getTrad('components.componentSelect.value-component');
39
+
40
+ return (
41
+ <SingleValue {...props}>
42
+ {!!value && !isMultiple && (
43
+ <>
44
+ <span style={{ fontWeight: 700, ...style }}>
45
+ <UpperFirst content={displayedCategory} />
46
+ </span>
47
+ <span style={style}>&nbsp;—&nbsp;</span>
48
+ <span style={style}>{displayedName}</span>
49
+ </>
50
+ )}
51
+ {isMultiple && (
52
+ <FormattedMessage id={message} values={{ number: valueLength }}>
53
+ {msg => <span style={style}>{msg}</span>}
54
+ </FormattedMessage>
55
+ )}
56
+ </SingleValue>
57
+ );
58
+ };
59
+
60
+ Value.defaultProps = {
61
+ children: null,
62
+ selectProps: {
63
+ componentCategory: null,
64
+ componentName: null,
65
+ isCreatingComponent: false,
66
+ isMultiple: false,
67
+ },
68
+ };
69
+
70
+ Value.propTypes = {
71
+ children: PropTypes.oneOfType([
72
+ PropTypes.string,
73
+ PropTypes.arrayOf(PropTypes.string),
74
+ ]),
75
+ selectProps: PropTypes.shape({
76
+ componentCategory: PropTypes.string,
77
+ componentName: PropTypes.string,
78
+ isCreatingComponent: PropTypes.bool,
79
+ isMultiple: PropTypes.bool,
80
+ }),
81
+ };
82
+
83
+ export default Value;
@@ -0,0 +1,83 @@
1
+ import React, { useRef } from 'react';
2
+ import Select from 'react-select';
3
+ import PropTypes from 'prop-types';
4
+ import MenuList from './MenuList';
5
+ import MultipleMenuList from './MultipleMenuList';
6
+ import Value from './Value';
7
+
8
+ const ComponentSelect = ({
9
+ addComponentsToDynamicZone,
10
+ componentCategoryNeededForAddingAfieldWhileCreatingAComponent,
11
+ componentNameNeededForAddingAfieldWhileCreatingAComponent,
12
+ isAddingAComponentToAnotherComponent,
13
+ isCreatingComponentWhileAddingAField,
14
+ isMultiple,
15
+ onChange,
16
+ name,
17
+ value,
18
+ styles,
19
+ }) => {
20
+ // Create a ref in order to access the StateManager
21
+ // So we can close the menu after clicking on a menu item
22
+ // This allows us to get rid of the menuIsOpen state management
23
+ // So we let the custom components taking care of it
24
+ const ref = useRef();
25
+ const handleChange = (inputValue, actionMeta) => {
26
+ const { action } = actionMeta;
27
+
28
+ if (action === 'clear') {
29
+ onChange({ target: { name, value: '' } });
30
+ }
31
+ };
32
+
33
+ const MenuListCompo = isMultiple ? MultipleMenuList : MenuList;
34
+
35
+ return (
36
+ <Select
37
+ addComponentsToDynamicZone={addComponentsToDynamicZone}
38
+ isAddingAComponentToAnotherComponent={isAddingAComponentToAnotherComponent}
39
+ isClearable={!isMultiple}
40
+ isDisabled={isCreatingComponentWhileAddingAField}
41
+ isCreatingComponent={isCreatingComponentWhileAddingAField}
42
+ isMultiple={isMultiple}
43
+ componentCategory={componentCategoryNeededForAddingAfieldWhileCreatingAComponent}
44
+ componentName={componentNameNeededForAddingAfieldWhileCreatingAComponent}
45
+ name={name}
46
+ onChange={handleChange}
47
+ onClickOption={onChange}
48
+ styles={styles}
49
+ value={{ label: value, value }}
50
+ options={[]}
51
+ ref={ref}
52
+ refState={ref}
53
+ components={{
54
+ MenuList: MenuListCompo,
55
+ SingleValue: Value,
56
+ }}
57
+ />
58
+ );
59
+ };
60
+
61
+ ComponentSelect.defaultProps = {
62
+ componentCategoryNeededForAddingAfieldWhileCreatingAComponent: null,
63
+ componentNameNeededForAddingAfieldWhileCreatingAComponent: null,
64
+ isAddingAComponentToAnotherComponent: false,
65
+ isCreatingComponentWhileAddingAField: false,
66
+ isMultiple: false,
67
+ value: null,
68
+ };
69
+
70
+ ComponentSelect.propTypes = {
71
+ addComponentsToDynamicZone: PropTypes.func.isRequired,
72
+ componentCategoryNeededForAddingAfieldWhileCreatingAComponent: PropTypes.string,
73
+ componentNameNeededForAddingAfieldWhileCreatingAComponent: PropTypes.string,
74
+ isAddingAComponentToAnotherComponent: PropTypes.bool,
75
+ isCreatingComponentWhileAddingAField: PropTypes.bool,
76
+ isMultiple: PropTypes.bool,
77
+ name: PropTypes.string.isRequired,
78
+ onChange: PropTypes.func.isRequired,
79
+ styles: PropTypes.object.isRequired,
80
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
81
+ };
82
+
83
+ export default ComponentSelect;
@@ -0,0 +1,5 @@
1
+ const hasSomeSubArray = (master, sub) => {
2
+ return sub.some(v => master.indexOf(v) !== -1);
3
+ };
4
+
5
+ export default hasSomeSubArray;
@@ -0,0 +1,5 @@
1
+ const hasSubArray = (master, sub) => {
2
+ return sub.every(v => master.indexOf(v) !== -1);
3
+ };
4
+
5
+ export default hasSubArray;
@@ -0,0 +1,58 @@
1
+ import React from 'react';
2
+ import Creatable from 'react-select/creatable';
3
+ import PropTypes from 'prop-types';
4
+ import { uniqBy } from 'lodash';
5
+ import useDataManager from '../../hooks/useDataManager';
6
+
7
+ const CreatableSelect = ({ onChange, name, styles, value }) => {
8
+ const { allComponentsCategories } = useDataManager();
9
+
10
+ const handleChange = (inputValue, actionMeta) => {
11
+ const { action } = actionMeta;
12
+
13
+ if (action === 'clear') {
14
+ onChange({ target: { name, value: '' } });
15
+ }
16
+
17
+ if (action === 'create-option' || action === 'select-option') {
18
+ onChange({ target: { name, value: inputValue.value } });
19
+ }
20
+ };
21
+
22
+ const formatOptions = () => {
23
+ const options = allComponentsCategories.map(cat => ({ value: cat, label: cat }));
24
+
25
+ if (value) {
26
+ return uniqBy(options.concat({ value, label: value }), 'value');
27
+ }
28
+
29
+ return options;
30
+ };
31
+
32
+ const getValue = () => {
33
+ return formatOptions().find(el => el.value === value);
34
+ };
35
+
36
+ return (
37
+ <Creatable
38
+ defaultValue={getValue()}
39
+ isClearable
40
+ onChange={handleChange}
41
+ styles={styles}
42
+ options={formatOptions()}
43
+ />
44
+ );
45
+ };
46
+
47
+ CreatableSelect.defaultProps = {
48
+ value: null,
49
+ };
50
+
51
+ CreatableSelect.propTypes = {
52
+ name: PropTypes.string.isRequired,
53
+ onChange: PropTypes.func.isRequired,
54
+ styles: PropTypes.object.isRequired,
55
+ value: PropTypes.string,
56
+ };
57
+
58
+ export default CreatableSelect;
@@ -0,0 +1,25 @@
1
+ /**
2
+ *
3
+ * StyledCustomCheckbox
4
+ *
5
+ */
6
+
7
+ import styled from 'styled-components';
8
+
9
+ const StyledCustomCheckbox = styled.div`
10
+ width: 100%;
11
+ padding: 0;
12
+ padding-bottom: 15px;
13
+
14
+ .no-label {
15
+ padding-top: 7px;
16
+ > div:first-child {
17
+ padding-bottom: 13px;
18
+ }
19
+ label {
20
+ display: none;
21
+ }
22
+ }
23
+ `;
24
+
25
+ export default StyledCustomCheckbox;