@webbio/strapi-plugin-page-builder 0.12.2-platform → 0.12.3-platform

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 (172) hide show
  1. package/README.md +166 -166
  2. package/admin/src/api/collection-type.ts +111 -111
  3. package/admin/src/api/entity-relation.ts +42 -42
  4. package/admin/src/api/has-page-relation.ts +37 -37
  5. package/admin/src/api/has-platform-relation.ts +40 -40
  6. package/admin/src/api/page-type-relation.ts +41 -41
  7. package/admin/src/api/platform-page-types.ts +45 -45
  8. package/admin/src/api/platform-relation.ts +42 -42
  9. package/admin/src/api/platform.ts +35 -35
  10. package/admin/src/api/search-filtered-entity.ts +114 -114
  11. package/admin/src/api/template.ts +39 -39
  12. package/admin/src/components/Combobox/index.tsx +83 -83
  13. package/admin/src/components/Combobox/react-select-custom-styles.tsx +121 -121
  14. package/admin/src/components/Combobox/styles.ts +46 -46
  15. package/admin/src/components/ConfirmModal/index.tsx +90 -90
  16. package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +127 -127
  17. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +149 -149
  18. package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/styles.ts +19 -19
  19. package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +82 -82
  20. package/admin/src/components/EditView/Details/index.tsx +48 -48
  21. package/admin/src/components/EditView/Details/styles.ts +51 -51
  22. package/admin/src/components/EditView/PageSettings/index.tsx +124 -124
  23. package/admin/src/components/EditView/Platform/platform-select.tsx +30 -30
  24. package/admin/src/components/EditView/Template/TemplateConfirmModal/index.tsx +36 -36
  25. package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +70 -70
  26. package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +41 -41
  27. package/admin/src/components/EditView/index.tsx +35 -35
  28. package/admin/src/components/EditView/page-type-select.tsx +32 -32
  29. package/admin/src/components/EditView/wrapper.tsx +41 -41
  30. package/admin/src/components/GlobalPlatformSelect/index.tsx +40 -40
  31. package/admin/src/components/GlobalPlatformSelect/styles.ts +27 -27
  32. package/admin/src/components/Initializer/index.tsx +24 -24
  33. package/admin/src/components/PageFilters/PageTypeFilter/index.tsx +39 -39
  34. package/admin/src/components/PageFilters/PlatformFilter/index.tsx +32 -32
  35. package/admin/src/components/PageFilters/filters.tsx +189 -189
  36. package/admin/src/components/PageFilters/index.tsx +35 -35
  37. package/admin/src/components/PageTypeEditView/TemplatePlatformSelect/index.tsx +76 -76
  38. package/admin/src/components/PageTypeEditView/index.tsx +53 -53
  39. package/admin/src/components/PlatformFilteredSelectField/InputIcon/index.tsx +23 -23
  40. package/admin/src/components/PlatformFilteredSelectField/Multi/index.tsx +210 -210
  41. package/admin/src/components/PlatformFilteredSelectField/Single/index.tsx +197 -197
  42. package/admin/src/components/PlatformFilteredSelectField/hooks/useRelationLoad.tsx +128 -128
  43. package/admin/src/components/PlatformFilteredSelectField/index.tsx +85 -85
  44. package/admin/src/components/PlatformFilteredSelectField/styles.tsx +77 -77
  45. package/admin/src/components/PlatformFilteredSelectField/utils/get-translations.ts +3 -3
  46. package/admin/src/components/PlatformFilteredSelectField/utils/relation-helper.ts +147 -147
  47. package/admin/src/components/PluginIcon/index.tsx +94 -94
  48. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/RelationInput.tsx +689 -689
  49. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/RelationInputDataManager.tsx +6 -6
  50. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/useRelation.ts +170 -170
  51. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/utils/getRelationLink.ts +5 -5
  52. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/components/Relations/utils/normalizeRelations.ts +52 -52
  53. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/constants/attributes.ts +3 -3
  54. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/useDragAndDrop.ts +253 -253
  55. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/useKeyboardDragAndDrop.ts +96 -96
  56. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/hooks/usePrev.ts +11 -11
  57. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/dragAndDrop.ts +8 -8
  58. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/paths.ts +29 -29
  59. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/refs.ts +19 -19
  60. package/admin/src/components/StrapiCore/admin/admin/src/content-manager/utils/translations.ts +3 -3
  61. package/admin/src/components/StrapiCore/content-manager/shared/contracts/collection-types.ts +300 -300
  62. package/admin/src/components/StrapiCore/content-manager/shared/contracts/components.ts +72 -72
  63. package/admin/src/components/StrapiCore/content-manager/shared/contracts/content-types.ts +116 -116
  64. package/admin/src/components/StrapiCore/content-manager/shared/contracts/index.ts +8 -8
  65. package/admin/src/components/StrapiCore/content-manager/shared/contracts/init.ts +22 -22
  66. package/admin/src/components/StrapiCore/content-manager/shared/contracts/relations.ts +80 -80
  67. package/admin/src/components/StrapiCore/content-manager/shared/contracts/review-workflows.ts +88 -88
  68. package/admin/src/components/StrapiCore/content-manager/shared/contracts/single-types.ts +112 -112
  69. package/admin/src/components/StrapiCore/content-manager/shared/contracts/uid.ts +48 -48
  70. package/admin/src/components/StrapiCore/content-manager/shared/index.ts +1 -1
  71. package/admin/src/constants.ts +3 -3
  72. package/admin/src/index.tsx +101 -101
  73. package/admin/src/middlewares/index.tsx +37 -37
  74. package/admin/src/pages/app/index.tsx +14 -14
  75. package/admin/src/pluginId.ts +5 -5
  76. package/admin/src/translations/en.json +9 -9
  77. package/admin/src/translations/nl.json +9 -9
  78. package/admin/src/utils/findDomElement.ts +6 -6
  79. package/admin/src/utils/findElementParent.ts +20 -20
  80. package/admin/src/utils/getObjectFromFormName.ts +42 -42
  81. package/admin/src/utils/getRequestUrl.ts +11 -11
  82. package/admin/src/utils/getTrad.ts +5 -5
  83. package/admin/src/utils/hooks/useDebounce.ts +17 -17
  84. package/admin/src/utils/hooks/useDefaultPlatformFromLocalStorage.ts +61 -61
  85. package/admin/src/utils/hooks/useGetLocaleFromUrl.ts +9 -9
  86. package/admin/src/utils/hooks/useHideOverviewFilterTags.ts +34 -34
  87. package/admin/src/utils/hooks/usePlatformFormData.ts +64 -64
  88. package/admin/src/utils/hooks/usePrevious.ts +12 -12
  89. package/admin/src/utils/sanitizeModules.ts +93 -93
  90. package/custom.d.ts +6 -6
  91. package/dist/package.json +1 -1
  92. package/dist/server/bootstrap.js +1 -1
  93. package/dist/server/graphql/page-by-path.js +20 -17
  94. package/dist/server/graphql/pages-by-uid.js +5 -5
  95. package/dist/server/services/private-content/graphql/index.js +27 -27
  96. package/dist/server/services/private-content/graphql/types/index.js +74 -74
  97. package/dist/tsconfig.server.tsbuildinfo +1 -1
  98. package/package.json +78 -78
  99. package/server/bootstrap/collection-type-lifecycles.ts +47 -47
  100. package/server/bootstrap/permissions.ts +161 -161
  101. package/server/bootstrap.ts +261 -261
  102. package/server/config/index.ts +4 -4
  103. package/server/content-types/index.ts +7 -7
  104. package/server/content-types/user-category/schema.json +23 -23
  105. package/server/controllers/collection-types.ts +32 -32
  106. package/server/controllers/index.ts +19 -19
  107. package/server/controllers/page-type.ts +18 -18
  108. package/server/controllers/page.ts +9 -9
  109. package/server/controllers/platform.ts +21 -21
  110. package/server/controllers/private-content.ts +17 -17
  111. package/server/controllers/sitemap.ts +32 -32
  112. package/server/controllers/template.ts +16 -16
  113. package/server/controllers/user-category.ts +3 -3
  114. package/server/destroy.ts +5 -5
  115. package/server/graphql/index.ts +9 -9
  116. package/server/graphql/page-by-path.ts +135 -132
  117. package/server/graphql/page-type.ts +67 -67
  118. package/server/graphql/pages-by-uid.ts +89 -89
  119. package/server/index.ts +23 -23
  120. package/server/middlewares/index.ts +1 -1
  121. package/server/policies/index.ts +5 -5
  122. package/server/policies/isAuthorizedPage.ts +11 -11
  123. package/server/register.ts +22 -22
  124. package/server/routes/index.ts +115 -115
  125. package/server/routes/user-category.ts +3 -3
  126. package/server/schema/page-end.json +96 -96
  127. package/server/schema/page-start.json +87 -87
  128. package/server/schema/page-type-end.json +53 -53
  129. package/server/schema/page-type-start.json +38 -38
  130. package/server/schema/platform-start.json +21 -21
  131. package/server/schema/template-end.json +40 -40
  132. package/server/schema/template-start.json +35 -35
  133. package/server/services/builder.ts +232 -232
  134. package/server/services/collection-types.ts +95 -95
  135. package/server/services/email.ts +127 -127
  136. package/server/services/index.ts +23 -23
  137. package/server/services/page-type.ts +30 -30
  138. package/server/services/page.ts +24 -24
  139. package/server/services/platform.ts +30 -30
  140. package/server/services/private-content/components/admin-email.json +22 -22
  141. package/server/services/private-content/components/email.json +22 -22
  142. package/server/services/private-content/components/platform-email.json +30 -30
  143. package/server/services/private-content/constants/index.ts +13 -13
  144. package/server/services/private-content/graphql/index.ts +88 -88
  145. package/server/services/private-content/graphql/resolvers/findOnePage.ts +40 -40
  146. package/server/services/private-content/graphql/resolvers/findPage.ts +45 -45
  147. package/server/services/private-content/graphql/resolvers/forgot-password.ts +34 -34
  148. package/server/services/private-content/graphql/resolvers/login.ts +56 -56
  149. package/server/services/private-content/graphql/resolvers/register.ts +78 -78
  150. package/server/services/private-content/graphql/resolvers/reset-password.ts +44 -44
  151. package/server/services/private-content/graphql/types/index.ts +96 -96
  152. package/server/services/private-content/index.ts +95 -95
  153. package/server/services/private-content/mail-template/txtMail.email.template.text.ts +6 -6
  154. package/server/services/private-content/page.ts +20 -20
  155. package/server/services/private-content/platform.ts +19 -19
  156. package/server/services/private-content/schemas/index.ts +28 -28
  157. package/server/services/private-content/user.ts +197 -197
  158. package/server/services/sitemap.ts +83 -83
  159. package/server/services/template.ts +13 -13
  160. package/server/services/user-category.ts +3 -3
  161. package/server/utils/filter-underscore-arguments.ts +12 -12
  162. package/server/utils/reload-strapi-on-load.ts +13 -13
  163. package/server/utils/strapi.ts +50 -50
  164. package/shared/utils/constants.ts +8 -8
  165. package/shared/utils/sleep.ts +1 -1
  166. package/strapi-admin.js +3 -3
  167. package/strapi-server.js +3 -3
  168. package/tsconfig.json +20 -20
  169. package/tsconfig.server.json +25 -25
  170. package/dist/server/graphql/page-by-slug.js +0 -89
  171. package/dist/server/utils/graphql.js +0 -100
  172. package/dist/server/utils/paginationValidation.js +0 -31
@@ -1,114 +1,114 @@
1
- import { useQuery, UseQueryOptions } from 'react-query';
2
- import orderBy from 'lodash/orderBy';
3
-
4
- import { useFetchClient } from '@strapi/helper-plugin';
5
- import qs from 'qs';
6
-
7
- export type SearchFilteredEntitiesResult = {
8
- pagination: {
9
- page: number;
10
- pageCount: number;
11
- pageSize: number;
12
- total: number;
13
- };
14
- results: {
15
- id: number;
16
- title: string;
17
- href: string;
18
- publicationState?: string | false;
19
- publishedAt?: string;
20
- }[];
21
- };
22
-
23
- type SearchFilteredEntitiesQueryParams = {
24
- fetchClient?: any;
25
- uid: string;
26
- page: number;
27
- locale: string;
28
- searchQuery?: string;
29
- platformTitle?: string;
30
- notIds?: number[];
31
- customFilters?: Record<string, any>[];
32
- };
33
-
34
- const QUERY_KEY = 'filteredEntities';
35
-
36
- export const getSearchFilteredEntities = async ({
37
- fetchClient,
38
- uid,
39
- page,
40
- locale,
41
- searchQuery,
42
- platformTitle,
43
- notIds,
44
- customFilters
45
- }: SearchFilteredEntitiesQueryParams): Promise<SearchFilteredEntitiesResult> => {
46
- try {
47
- const { get } = fetchClient;
48
- const notIdFilters = notIds && notIds.length > 0 ? notIds.map((id) => ({ id: { $ne: id } })) : [];
49
- const customFilterObject = Array.isArray(customFilters) ? customFilters : [];
50
-
51
- const filters = qs.stringify({
52
- page,
53
- pageSize: 20,
54
- locale,
55
- sort: searchQuery ? 'title:ASC' : undefined,
56
- _q: searchQuery || undefined,
57
- filters: {
58
- $and: [
59
- { platform: { title: { $contains: platformTitle || undefined } } },
60
- ...notIdFilters,
61
- ...customFilterObject
62
- ]
63
- }
64
- });
65
-
66
- const { data } = await get(`/content-manager/collection-types/${uid}?${filters}`);
67
- const mapResults = data.results.map(
68
- (result: Record<string, any>): SearchFilteredEntitiesResult['results'][number] => {
69
- const getPublicationState = () => {
70
- if (result?.publishedAt !== undefined) {
71
- return result?.publishedAt ? 'published' : 'draft';
72
- }
73
-
74
- return false;
75
- };
76
-
77
- return {
78
- id: result.id,
79
- title: result.title,
80
- publicationState: getPublicationState(),
81
- publishedAt: result?.publishedAt,
82
- href: `/content-manager/collectionType/${uid}/${result.id}`
83
- };
84
- }
85
- );
86
-
87
- return {
88
- pagination: data.pagination,
89
- results: orderBy(mapResults, ['title'], ['asc'])
90
- };
91
- } catch (e) {
92
- return {
93
- pagination: { page: 1, pageCount: 0, pageSize: 0, total: 0 },
94
- results: []
95
- };
96
- }
97
- };
98
-
99
- export const useSearchFilteredEntities = (
100
- params: SearchFilteredEntitiesQueryParams,
101
- options?: UseQueryOptions<SearchFilteredEntitiesResult, Error>
102
- ) => {
103
- const fetchClient = useFetchClient();
104
-
105
- return useQuery<SearchFilteredEntitiesResult, Error>(
106
- [QUERY_KEY, params],
107
- () =>
108
- getSearchFilteredEntities({
109
- ...params,
110
- fetchClient
111
- }),
112
- options
113
- );
114
- };
1
+ import { useQuery, UseQueryOptions } from 'react-query';
2
+ import orderBy from 'lodash/orderBy';
3
+
4
+ import { useFetchClient } from '@strapi/helper-plugin';
5
+ import qs from 'qs';
6
+
7
+ export type SearchFilteredEntitiesResult = {
8
+ pagination: {
9
+ page: number;
10
+ pageCount: number;
11
+ pageSize: number;
12
+ total: number;
13
+ };
14
+ results: {
15
+ id: number;
16
+ title: string;
17
+ href: string;
18
+ publicationState?: string | false;
19
+ publishedAt?: string;
20
+ }[];
21
+ };
22
+
23
+ type SearchFilteredEntitiesQueryParams = {
24
+ fetchClient?: any;
25
+ uid: string;
26
+ page: number;
27
+ locale: string;
28
+ searchQuery?: string;
29
+ platformTitle?: string;
30
+ notIds?: number[];
31
+ customFilters?: Record<string, any>[];
32
+ };
33
+
34
+ const QUERY_KEY = 'filteredEntities';
35
+
36
+ export const getSearchFilteredEntities = async ({
37
+ fetchClient,
38
+ uid,
39
+ page,
40
+ locale,
41
+ searchQuery,
42
+ platformTitle,
43
+ notIds,
44
+ customFilters
45
+ }: SearchFilteredEntitiesQueryParams): Promise<SearchFilteredEntitiesResult> => {
46
+ try {
47
+ const { get } = fetchClient;
48
+ const notIdFilters = notIds && notIds.length > 0 ? notIds.map((id) => ({ id: { $ne: id } })) : [];
49
+ const customFilterObject = Array.isArray(customFilters) ? customFilters : [];
50
+
51
+ const filters = qs.stringify({
52
+ page,
53
+ pageSize: 20,
54
+ locale,
55
+ sort: searchQuery ? 'title:ASC' : undefined,
56
+ _q: searchQuery || undefined,
57
+ filters: {
58
+ $and: [
59
+ { platform: { title: { $contains: platformTitle || undefined } } },
60
+ ...notIdFilters,
61
+ ...customFilterObject
62
+ ]
63
+ }
64
+ });
65
+
66
+ const { data } = await get(`/content-manager/collection-types/${uid}?${filters}`);
67
+ const mapResults = data.results.map(
68
+ (result: Record<string, any>): SearchFilteredEntitiesResult['results'][number] => {
69
+ const getPublicationState = () => {
70
+ if (result?.publishedAt !== undefined) {
71
+ return result?.publishedAt ? 'published' : 'draft';
72
+ }
73
+
74
+ return false;
75
+ };
76
+
77
+ return {
78
+ id: result.id,
79
+ title: result.title,
80
+ publicationState: getPublicationState(),
81
+ publishedAt: result?.publishedAt,
82
+ href: `/content-manager/collectionType/${uid}/${result.id}`
83
+ };
84
+ }
85
+ );
86
+
87
+ return {
88
+ pagination: data.pagination,
89
+ results: orderBy(mapResults, ['title'], ['asc'])
90
+ };
91
+ } catch (e) {
92
+ return {
93
+ pagination: { page: 1, pageCount: 0, pageSize: 0, total: 0 },
94
+ results: []
95
+ };
96
+ }
97
+ };
98
+
99
+ export const useSearchFilteredEntities = (
100
+ params: SearchFilteredEntitiesQueryParams,
101
+ options?: UseQueryOptions<SearchFilteredEntitiesResult, Error>
102
+ ) => {
103
+ const fetchClient = useFetchClient();
104
+
105
+ return useQuery<SearchFilteredEntitiesResult, Error>(
106
+ [QUERY_KEY, params],
107
+ () =>
108
+ getSearchFilteredEntities({
109
+ ...params,
110
+ fetchClient
111
+ }),
112
+ options
113
+ );
114
+ };
@@ -1,39 +1,39 @@
1
- import { useQuery } from 'react-query';
2
-
3
- import { useFetchClient } from '@strapi/helper-plugin';
4
-
5
- export type Template = {
6
- id: number;
7
- title: string;
8
- modules: Record<string, any>[];
9
- };
10
-
11
- const QUERY_KEY = 'templates';
12
-
13
- const fetchTemplates = async ({ fetchClient, platformId }: Record<string, any>): Promise<Template[]> => {
14
- try {
15
- if (!platformId) {
16
- throw new Error('No platformId');
17
- }
18
-
19
- const { get } = fetchClient;
20
- const result = await get(`/content-manager/collection-types/api::template.template?page=1&pageSize=999`);
21
-
22
- return result?.data?.results
23
- ?.filter((x?: Record<string, any>) => x?.platform?.id === platformId)
24
- ?.map((template: Record<string, any>) => ({ id: template.id, title: template.title, modules: template.modules }));
25
- } catch {
26
- return [];
27
- }
28
- };
29
-
30
- export const useGetTemplates = (params: Record<string, any>) => {
31
- const fetchClient = useFetchClient();
32
-
33
- return useQuery<Template[], Error>([QUERY_KEY, params], () =>
34
- fetchTemplates({
35
- ...params,
36
- fetchClient
37
- })
38
- );
39
- };
1
+ import { useQuery } from 'react-query';
2
+
3
+ import { useFetchClient } from '@strapi/helper-plugin';
4
+
5
+ export type Template = {
6
+ id: number;
7
+ title: string;
8
+ modules: Record<string, any>[];
9
+ };
10
+
11
+ const QUERY_KEY = 'templates';
12
+
13
+ const fetchTemplates = async ({ fetchClient, platformId }: Record<string, any>): Promise<Template[]> => {
14
+ try {
15
+ if (!platformId) {
16
+ throw new Error('No platformId');
17
+ }
18
+
19
+ const { get } = fetchClient;
20
+ const result = await get(`/content-manager/collection-types/api::template.template?page=1&pageSize=999`);
21
+
22
+ return result?.data?.results
23
+ ?.filter((x?: Record<string, any>) => x?.platform?.id === platformId)
24
+ ?.map((template: Record<string, any>) => ({ id: template.id, title: template.title, modules: template.modules }));
25
+ } catch {
26
+ return [];
27
+ }
28
+ };
29
+
30
+ export const useGetTemplates = (params: Record<string, any>) => {
31
+ const fetchClient = useFetchClient();
32
+
33
+ return useQuery<Template[], Error>([QUERY_KEY, params], () =>
34
+ fetchTemplates({
35
+ ...params,
36
+ fetchClient
37
+ })
38
+ );
39
+ };
@@ -1,83 +1,83 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { ClearIndicatorProps, DropdownIndicatorProps, GroupBase, components } from 'react-select';
3
- import AsyncSelect, { AsyncProps } from 'react-select/async';
4
-
5
- import { CarretDown, Cross } from '@strapi/icons';
6
- import { FieldLabel } from '@strapi/design-system';
7
-
8
- import S from './styles';
9
- import { useReactSelectCustomStyles } from './react-select-custom-styles';
10
-
11
- export interface IComboboxProps extends AsyncProps<IReactSelectValue, false, GroupBase<IReactSelectValue>> {
12
- customOption?: typeof components.Option<IReactSelectValue, false, GroupBase<IReactSelectValue>>;
13
- label?: string;
14
- id: string;
15
- extraLabelElement?: React.ReactNode;
16
- labelAction?: React.ReactNode;
17
- afterInput?: React.ReactNode;
18
- }
19
-
20
- export interface IReactSelectValue {
21
- value: string;
22
- label: string;
23
- initialSelected?: boolean;
24
- }
25
-
26
- const Combobox = (props: IComboboxProps) => {
27
- const { label, customOption, extraLabelElement, labelAction, id, afterInput, ...selectProps } = props;
28
- const styles = useReactSelectCustomStyles();
29
- const [inputValue, setInputValue] = useState<string | undefined>(props.inputValue);
30
-
31
- useEffect(() => {
32
- setInputValue(props.inputValue);
33
- }, [props.inputValue]);
34
-
35
- return (
36
- <S.Wrapper>
37
- {props.label && (
38
- <S.LabelWrapper>
39
- <FieldLabel action={labelAction}>{props.label}</FieldLabel>
40
- {extraLabelElement}
41
- </S.LabelWrapper>
42
- )}
43
- <S.ElementWrapper>
44
- <AsyncSelect
45
- {...selectProps}
46
- inputId={id}
47
- isClearable
48
- onInputChange={(value, actionMeta) => {
49
- props.onInputChange?.(value, actionMeta);
50
- setInputValue(value);
51
- }}
52
- styles={styles}
53
- inputValue={inputValue}
54
- components={{
55
- IndicatorSeparator: null,
56
- ClearIndicator,
57
- DropdownIndicator,
58
- Option: props.customOption || components.Option
59
- }}
60
- />
61
- {afterInput}
62
- </S.ElementWrapper>
63
- </S.Wrapper>
64
- );
65
- };
66
-
67
- export { Combobox };
68
-
69
- const ClearIndicator = (props: ClearIndicatorProps<IReactSelectValue, false>) => {
70
- return (
71
- <components.ClearIndicator {...props}>
72
- <Cross />
73
- </components.ClearIndicator>
74
- );
75
- };
76
-
77
- const DropdownIndicator = (props: DropdownIndicatorProps<IReactSelectValue, false>) => {
78
- return (
79
- <components.DropdownIndicator {...props}>
80
- <CarretDown />
81
- </components.DropdownIndicator>
82
- );
83
- };
1
+ import React, { useEffect, useState } from 'react';
2
+ import { ClearIndicatorProps, DropdownIndicatorProps, GroupBase, components } from 'react-select';
3
+ import AsyncSelect, { AsyncProps } from 'react-select/async';
4
+
5
+ import { CarretDown, Cross } from '@strapi/icons';
6
+ import { FieldLabel } from '@strapi/design-system';
7
+
8
+ import S from './styles';
9
+ import { useReactSelectCustomStyles } from './react-select-custom-styles';
10
+
11
+ export interface IComboboxProps extends AsyncProps<IReactSelectValue, false, GroupBase<IReactSelectValue>> {
12
+ customOption?: typeof components.Option<IReactSelectValue, false, GroupBase<IReactSelectValue>>;
13
+ label?: string;
14
+ id: string;
15
+ extraLabelElement?: React.ReactNode;
16
+ labelAction?: React.ReactNode;
17
+ afterInput?: React.ReactNode;
18
+ }
19
+
20
+ export interface IReactSelectValue {
21
+ value: string;
22
+ label: string;
23
+ initialSelected?: boolean;
24
+ }
25
+
26
+ const Combobox = (props: IComboboxProps) => {
27
+ const { label, customOption, extraLabelElement, labelAction, id, afterInput, ...selectProps } = props;
28
+ const styles = useReactSelectCustomStyles();
29
+ const [inputValue, setInputValue] = useState<string | undefined>(props.inputValue);
30
+
31
+ useEffect(() => {
32
+ setInputValue(props.inputValue);
33
+ }, [props.inputValue]);
34
+
35
+ return (
36
+ <S.Wrapper>
37
+ {props.label && (
38
+ <S.LabelWrapper>
39
+ <FieldLabel action={labelAction}>{props.label}</FieldLabel>
40
+ {extraLabelElement}
41
+ </S.LabelWrapper>
42
+ )}
43
+ <S.ElementWrapper>
44
+ <AsyncSelect
45
+ {...selectProps}
46
+ inputId={id}
47
+ isClearable
48
+ onInputChange={(value, actionMeta) => {
49
+ props.onInputChange?.(value, actionMeta);
50
+ setInputValue(value);
51
+ }}
52
+ styles={styles}
53
+ inputValue={inputValue}
54
+ components={{
55
+ IndicatorSeparator: null,
56
+ ClearIndicator,
57
+ DropdownIndicator,
58
+ Option: props.customOption || components.Option
59
+ }}
60
+ />
61
+ {afterInput}
62
+ </S.ElementWrapper>
63
+ </S.Wrapper>
64
+ );
65
+ };
66
+
67
+ export { Combobox };
68
+
69
+ const ClearIndicator = (props: ClearIndicatorProps<IReactSelectValue, false>) => {
70
+ return (
71
+ <components.ClearIndicator {...props}>
72
+ <Cross />
73
+ </components.ClearIndicator>
74
+ );
75
+ };
76
+
77
+ const DropdownIndicator = (props: DropdownIndicatorProps<IReactSelectValue, false>) => {
78
+ return (
79
+ <components.DropdownIndicator {...props}>
80
+ <CarretDown />
81
+ </components.DropdownIndicator>
82
+ );
83
+ };