@webbio/strapi-plugin-page-builder 0.0.30 → 0.1.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/README.md +95 -0
- package/admin/src/api/template.ts +4 -2
- package/admin/src/components/EditView/CollectionTypeSearch/index.tsx +6 -0
- package/admin/src/components/EditView/CollectionTypeSettings/CreatePageButton/index.tsx +5 -3
- package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +14 -3
- package/admin/src/components/EditView/PageSettings/index.tsx +13 -6
- package/admin/src/components/EditView/Template/TemplateSelect/index.tsx +7 -2
- package/admin/src/components/EditView/Template/TemplateSelect/use-template-modules.ts +11 -3
- package/admin/src/components/EditView/index.tsx +3 -1
- package/admin/src/components/EditView/page-type-select.tsx +3 -1
- package/admin/src/constants.ts +2 -0
- package/admin/src/index.tsx +1 -1
- package/dist/package.json +10 -10
- package/dist/server/bootstrap.js +86 -17
- package/dist/server/controllers/collection-types.js +0 -2
- package/dist/server/controllers/index.js +3 -1
- package/dist/server/controllers/page-type.js +0 -1
- package/dist/server/controllers/page.js +0 -8
- package/dist/server/controllers/platform.js +20 -0
- package/dist/server/controllers/template.js +15 -0
- package/dist/server/graphql/index.js +2 -0
- package/dist/server/graphql/page-by-slug.js +4 -4
- package/dist/server/graphql/page-type.js +4 -1
- package/dist/server/graphql/pages-by-uid.js +105 -0
- package/dist/server/register.js +2 -0
- package/dist/server/routes/index.js +16 -0
- package/dist/server/schema/platform-start.json +31 -0
- package/dist/server/services/builder.js +6 -3
- package/dist/server/services/index.js +3 -1
- package/dist/server/services/page-type.js +7 -4
- package/dist/server/services/platform.js +36 -0
- package/dist/server/services/template.js +14 -0
- package/dist/server/utils/graphql.js +4 -1
- package/dist/server/utils/paginationValidation.js +31 -0
- package/dist/server/utils/strapi.js +42 -0
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/server/bootstrap.ts +94 -17
- package/server/controllers/collection-types.ts +4 -4
- package/server/controllers/index.ts +3 -1
- package/server/controllers/page-type.ts +3 -2
- package/server/controllers/page.ts +0 -11
- package/server/controllers/template.ts +16 -0
- package/server/graphql/index.ts +2 -0
- package/server/graphql/page-by-slug.ts +1 -1
- package/server/graphql/page-type.ts +13 -4
- package/server/graphql/pages-by-uid.ts +127 -0
- package/server/register.ts +2 -0
- package/server/routes/index.ts +16 -0
- package/server/services/builder.ts +13 -12
- package/server/services/collection-types.ts +6 -6
- package/server/services/index.ts +3 -1
- package/server/services/page-type.ts +7 -3
- package/server/services/template.ts +14 -0
- package/server/utils/graphql.ts +4 -1
- package/server/utils/paginationValidation.ts +39 -0
- package/server/utils/strapi.ts +49 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/.prettierignore +0 -17
package/README.md
CHANGED
|
@@ -1,3 +1,98 @@
|
|
|
1
1
|
# Strapi plugin page-builder
|
|
2
2
|
|
|
3
3
|
A quick description of page-builder.
|
|
4
|
+
|
|
5
|
+
# Werking van de plugin
|
|
6
|
+
|
|
7
|
+
Voeg de plugin aan de plugin.ts toe
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
'page-builder': {
|
|
11
|
+
enabled: true,
|
|
12
|
+
config: {
|
|
13
|
+
modules: [
|
|
14
|
+
'modules.header',
|
|
15
|
+
'modules.cta',
|
|
16
|
+
...
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
In de modules array voeg je alle modules toe die beschikbaar moeten zijn op een pagina. Deze worden bij het opstarten van de server automatisch toegevoegd aan `Page` en `Template`.
|
|
23
|
+
|
|
24
|
+
De collectiontypes `Page`, `Template` en `PageType` worden aangemaakt of bijgewerkt op het moment van opstarten van de server. Het kan zijn dat de server een keer crasht, start deze dan even opnieuw op.
|
|
25
|
+
|
|
26
|
+
## Page Types
|
|
27
|
+
|
|
28
|
+
Maak voor elke pagina type een Page Type aan. Deze kan, maar hoeft niet, gekoppeld worden aan een collection type. Je moet altijd een UID invoeren, als je wenst geen koppeling te maken met een collection type, vul hier alsnog iets in. Het kan zijn dat dit deel van de plugin nog niet werkt, hier is nog niet mee getest.
|
|
29
|
+
hasPage moet toegevoegd worden aan de collectiontype. Dit komt doordat er gefilterd moet kunnen worden middels graphql. Er is een custom manier gebouwd om ervoor te zorgen dat pages gefilterd kan worden.
|
|
30
|
+
|
|
31
|
+
Voor elk collection type die een page type is, moet deze properties toegevoegd worden:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
"page": {
|
|
35
|
+
"type": "relation",
|
|
36
|
+
"relation": "morphMany",
|
|
37
|
+
"target": "api::page.page",
|
|
38
|
+
"morphBy": "collectionTypeData"
|
|
39
|
+
},
|
|
40
|
+
"hasPage": {
|
|
41
|
+
"type": "boolean",
|
|
42
|
+
"default": false
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Zodra dit goed is ingesteld, kan je via deze collectie types direct een pagina aanmaken.
|
|
47
|
+
|
|
48
|
+
## Page
|
|
49
|
+
|
|
50
|
+
Op een page kan je in de Edit View een page type selecteren. Op basis daarvan wordt er een template geselecteerd (indien gekozen in een page type) en kan je zoeken in verschillende entiteiten binnen die page type. Deze kan je koppelen aan een pagina.
|
|
51
|
+
|
|
52
|
+
## Template
|
|
53
|
+
|
|
54
|
+
Een template is niets anders dan een sjabloon die je eenmalig kan toevoegen op een pagina. Dit kan via een page type gaan maar kan ook zonder de page type. Een modal zal eerst nog vragen of je zeker bent van je keuze, alle modules zullen vervangen worden.
|
|
55
|
+
|
|
56
|
+
## Platform
|
|
57
|
+
|
|
58
|
+
Om wijzigignen aan te brengen in een platform, moeten deze in de schema aangepast worden van de api. `/src/api/platform/content-types/platform/schema.json`
|
|
59
|
+
|
|
60
|
+
Voor elk collectiontype die je wil toevoegen aan het platform, moet deze relatie toegevoegd worden:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
"collectiontype": {
|
|
64
|
+
"type": "relation",
|
|
65
|
+
"relation": "oneToMany",
|
|
66
|
+
"target": "UID van collection type",
|
|
67
|
+
"mappedBy": "platform"
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
bijvoorbeeld :
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
"faqs": {
|
|
75
|
+
"type": "relation",
|
|
76
|
+
"relation": "oneToMany",
|
|
77
|
+
"target": "api::faq.faq",
|
|
78
|
+
"mappedBy": "platform"
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Een platform zit altijd aan een pagina gekoppeld. Deze moet handmatig in de pagina toegevoegd worden.
|
|
83
|
+
|
|
84
|
+
# Known bugs
|
|
85
|
+
|
|
86
|
+
- Bij het opslaan van een collectietype wil de gekoppelde pagina of type in het ui wel eens verdwijnen.
|
|
87
|
+
- Na het ontkoppelen en opslaan van een collectie item op een pagina, staat deze nog als "Geselecteerd" in de dropdown.
|
|
88
|
+
|
|
89
|
+
# Improvements
|
|
90
|
+
|
|
91
|
+
- Deze readme updaten en naar engels vertalen.
|
|
92
|
+
- Intl gebruiken voor de teksten.
|
|
93
|
+
- Pagetype mag ook een default parent page relation hebben. Bij het aanmaken van een pagina obv een page type, deze relatie als default aan de aangemaakte pagina koppelen. Als ik bijvoorbeeld een post pagina maak, dan wordt de pagina automatisch aan de "actueel" pagina gekoppeld zodat al mijn posts die parent hebben.
|
|
94
|
+
- Filteren op Page in GraphQL binnen een collectiontype met een morph op een page kan niet. Strapi staat dit niet toe. Wellicht in de toekomst wel.
|
|
95
|
+
- Slug en path genereren op basis van de titel van het collection type waarvan je een pagina aanmaakt. Nu wordt deze leeggelaten. Dit moet zorgvuldig gebeuren, bij een bestaande slug wil je bijvoorbeeld een -2 toevoegen oid.
|
|
96
|
+
- Dit vorige punt geldt ook andersom, dus als je een entity koppelt vanuit een pagina. Als de titel en slug nog leeg zijn, vul die dan automatisch in.
|
|
97
|
+
- In het overzicht van een collectiontype moet duidelijk worden of en welke pagina er gekoppeld is. [https://share.getcloudapp.com/BluzGYEd](https://share.getcloudapp.com/BluzGYEd)
|
|
98
|
+
- Bij Page Types moet je handmatig de collectiontype uid invoeren. Dit zou idealiter een select zijn van alle mogelijke collecion type uids. Ook moet dit een mogelijkheid bieden voor geen uid.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useQuery } from 'react-query';
|
|
2
2
|
import { useFetchClient } from '@strapi/helper-plugin';
|
|
3
|
+
import getRequestUrl from '../utils/getRequestUrl';
|
|
3
4
|
|
|
4
5
|
export type Template = {
|
|
5
6
|
id: number;
|
|
@@ -11,8 +12,9 @@ const QUERY_KEY = ['templates'];
|
|
|
11
12
|
|
|
12
13
|
const fetchTemplates = async ({ fetchClient }: any): Promise<Template[]> => {
|
|
13
14
|
const { get } = fetchClient;
|
|
14
|
-
const result = await get(
|
|
15
|
-
|
|
15
|
+
const result = await get(getRequestUrl('/template'));
|
|
16
|
+
|
|
17
|
+
return result?.data;
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
export const useGetTemplates = (params: any) => {
|
|
@@ -32,6 +32,12 @@ export const CollectionTypeSearch = ({ uid }: Props) => {
|
|
|
32
32
|
const isPagePageType = !uid;
|
|
33
33
|
const searchEntitiesIsEnabled = !isPagePageType;
|
|
34
34
|
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (form.isCreatingEntry) {
|
|
37
|
+
setSelected(null);
|
|
38
|
+
}
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
35
41
|
const getItems = async (inputValue?: string): Promise<IReactSelectValue[]> => {
|
|
36
42
|
const searchEntities = await getSearchEntities({
|
|
37
43
|
fetchClient,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import { useHistory } from 'react-router-dom';
|
|
3
3
|
|
|
4
4
|
import { Plus } from '@strapi/icons';
|
|
@@ -15,7 +15,7 @@ export const CreatePageButton = () => {
|
|
|
15
15
|
const history = useHistory();
|
|
16
16
|
const { layout, initialData } = useCMEditViewDataManager();
|
|
17
17
|
|
|
18
|
-
const { post, get } = useFetchClient();
|
|
18
|
+
const { post, get, put } = useFetchClient();
|
|
19
19
|
const url = `/content-manager/collectionType/${PAGE_UID}/create`;
|
|
20
20
|
|
|
21
21
|
const handleCreatePage = async (e: React.MouseEvent<HTMLAnchorElement>) => {
|
|
@@ -41,8 +41,10 @@ export const CreatePageButton = () => {
|
|
|
41
41
|
layoutUid: layout.uid,
|
|
42
42
|
relatedEntityId: createLocalizedPage ? linkedPages.data?.[0]?.id : undefined
|
|
43
43
|
});
|
|
44
|
-
|
|
45
44
|
if (newPage?.id) {
|
|
45
|
+
await put(`/content-manager/collection-types/${layout.uid}/${initialData.id}`, {
|
|
46
|
+
hasPage: true
|
|
47
|
+
});
|
|
46
48
|
history.push(`/content-manager/collectionType/${PAGE_UID}/${newPage.id}?plugins[i18n][locale]=${locale}`);
|
|
47
49
|
}
|
|
48
50
|
} catch (error) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
|
4
4
|
import { Flex } from '@strapi/design-system';
|
|
@@ -10,7 +10,7 @@ import { PAGE_TYPE_PAGE, PAGE_UID } from '../../../../../shared/utils/constants'
|
|
|
10
10
|
import S from '../Details/styles';
|
|
11
11
|
|
|
12
12
|
export const CollectionTypeSettings = () => {
|
|
13
|
-
const { layout, isCreatingEntry, initialData } = useCMEditViewDataManager();
|
|
13
|
+
const { layout, isCreatingEntry, initialData, onChange } = useCMEditViewDataManager();
|
|
14
14
|
|
|
15
15
|
const isUserCreatedContentType = layout.uid.startsWith('api::');
|
|
16
16
|
const linkedPage = initialData.page?.[0];
|
|
@@ -18,12 +18,23 @@ export const CollectionTypeSettings = () => {
|
|
|
18
18
|
const showCreatePageButton = isUserCreatedContentType && !isCreatingEntry && !linkedPage;
|
|
19
19
|
const url = generateLink(linkedPage?.id, initialData?.locale);
|
|
20
20
|
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (isCreatingEntry) {
|
|
23
|
+
onChange({
|
|
24
|
+
target: {
|
|
25
|
+
name: 'page',
|
|
26
|
+
value: null
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
21
32
|
if (isCreatingEntry) {
|
|
22
33
|
return null;
|
|
23
34
|
}
|
|
24
35
|
|
|
25
36
|
return (
|
|
26
|
-
<Wrapper title="
|
|
37
|
+
<Wrapper title="Gekoppelde pagina">
|
|
27
38
|
<Flex direction="column" gap={4} width="100%" alignItems="start">
|
|
28
39
|
{showCreatePageButton && <CreatePageButton />}
|
|
29
40
|
|
|
@@ -3,7 +3,6 @@ import React, { useEffect, useMemo, useState } from 'react';
|
|
|
3
3
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
|
4
4
|
import { Stack, Flex } from '@strapi/design-system';
|
|
5
5
|
import { Cog, Cross } from '@strapi/icons';
|
|
6
|
-
|
|
7
6
|
import { TemplateSelect } from '../Template/TemplateSelect';
|
|
8
7
|
import { PageTypeSelect } from '../page-type-select';
|
|
9
8
|
import { CollectionTypeSearch } from '../CollectionTypeSearch';
|
|
@@ -14,9 +13,10 @@ import S from '../Details/styles';
|
|
|
14
13
|
|
|
15
14
|
export const PageSettings = () => {
|
|
16
15
|
const { isCreatingEntry, initialData, onChange, modifiedData } = useCMEditViewDataManager();
|
|
17
|
-
const { data:
|
|
18
|
-
|
|
16
|
+
const { data: pageTypesData } = useGetPageTypes({});
|
|
17
|
+
const [pageTypes, setPageTypes] = useState(pageTypesData);
|
|
19
18
|
const [selectedPageType, setSelectedPageType] = useState<PageType | undefined | null>(initialData?.initialPageType);
|
|
19
|
+
const [hasSelectedPlatform, setHasSelectedPlatform] = useState<boolean>(true);
|
|
20
20
|
const [isEditting, setIsEditting] = useState(false);
|
|
21
21
|
const showEditFields = useMemo(
|
|
22
22
|
() => isCreatingEntry || !selectedPageType?.id || !initialData.collectionTypeTitle || isEditting,
|
|
@@ -35,6 +35,7 @@ export const PageSettings = () => {
|
|
|
35
35
|
|
|
36
36
|
useEffect(() => {
|
|
37
37
|
setSelectedPageType(initialData?.initialPageType);
|
|
38
|
+
|
|
38
39
|
setIsEditting(false);
|
|
39
40
|
}, [initialData]);
|
|
40
41
|
|
|
@@ -65,18 +66,24 @@ export const PageSettings = () => {
|
|
|
65
66
|
value: pageType.id
|
|
66
67
|
};
|
|
67
68
|
setFormValue('pageType', [formPageType]);
|
|
69
|
+
setHasSelectedPlatform(false);
|
|
68
70
|
} else {
|
|
69
71
|
removePageType();
|
|
70
72
|
}
|
|
71
73
|
};
|
|
72
74
|
|
|
73
75
|
return (
|
|
74
|
-
<Wrapper title="
|
|
76
|
+
<Wrapper title="Gekoppelde type">
|
|
75
77
|
<Flex direction="column" gap={4} width="100%">
|
|
76
78
|
{showEditFields ? (
|
|
77
79
|
<Stack spacing={4} width="100%">
|
|
78
|
-
<PageTypeSelect
|
|
79
|
-
|
|
80
|
+
<PageTypeSelect
|
|
81
|
+
pageTypes={pageTypes}
|
|
82
|
+
selectedPageType={selectedPageType}
|
|
83
|
+
onChange={handleSelectPageType}
|
|
84
|
+
disabled={hasSelectedPlatform}
|
|
85
|
+
/>
|
|
86
|
+
<TemplateSelect disabled={hasSelectedPlatform} />
|
|
80
87
|
{selectedPageType?.uid && <CollectionTypeSearch uid={selectedPageType.uid} />}
|
|
81
88
|
</Stack>
|
|
82
89
|
) : (
|
|
@@ -5,7 +5,11 @@ import { Template } from '../../../../api/template';
|
|
|
5
5
|
import TemplateConfirmModal from '../TemplateConfirmModal';
|
|
6
6
|
import { useTemplateModules } from './use-template-modules';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
interface Props {
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const TemplateSelect = ({ disabled }: Props) => {
|
|
9
13
|
const { onChange, modifiedData } = useCMEditViewDataManager();
|
|
10
14
|
const [selectedTemplate, setSelectedTemplate] = useState<Template | null>(null);
|
|
11
15
|
const { templates, replaceContentTypeModules } = useTemplateModules(onChange);
|
|
@@ -33,7 +37,7 @@ export const TemplateSelect = () => {
|
|
|
33
37
|
|
|
34
38
|
useEffect(() => {
|
|
35
39
|
if (selectedTemplate !== null) {
|
|
36
|
-
replaceContentTypeModules(selectedTemplate.
|
|
40
|
+
replaceContentTypeModules(selectedTemplate.id);
|
|
37
41
|
}
|
|
38
42
|
}, [selectedTemplate]);
|
|
39
43
|
|
|
@@ -44,6 +48,7 @@ export const TemplateSelect = () => {
|
|
|
44
48
|
placeholder="Choose a template"
|
|
45
49
|
value={selectedTemplate?.id || 0}
|
|
46
50
|
onChange={handleSelectChange}
|
|
51
|
+
disabled={disabled}
|
|
47
52
|
>
|
|
48
53
|
<SingleSelectOption value={0}>None</SingleSelectOption>
|
|
49
54
|
{templates?.map((template) => (
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import { Template, useGetTemplates } from '../../../../api/template';
|
|
2
|
-
|
|
3
2
|
import { sanitizeModules } from '../../../../utils/sanitizeModules';
|
|
3
|
+
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
|
+
import getRequestUrl from '../../../../utils/getRequestUrl';
|
|
4
5
|
|
|
5
6
|
type OnChangeFormType = (props: { target: Record<string, any>; shouldSetInitialValue: boolean }) => void;
|
|
6
7
|
|
|
7
8
|
export const useTemplateModules = (onChange: OnChangeFormType) => {
|
|
8
9
|
const { data: templates } = useGetTemplates({});
|
|
10
|
+
const fetchClient = useFetchClient();
|
|
9
11
|
|
|
10
12
|
return {
|
|
11
13
|
findTemplate,
|
|
12
14
|
templates,
|
|
13
|
-
replaceContentTypeModules: (
|
|
15
|
+
replaceContentTypeModules: (id: number) => replaceContentTypeModules(id, fetchClient, onChange)
|
|
14
16
|
};
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
const findTemplate = (templates?: Template[], selectedTemplateId?: string | number) =>
|
|
18
20
|
templates?.find((template) => template.id === Number(selectedTemplateId));
|
|
19
21
|
|
|
20
|
-
const
|
|
22
|
+
const sanatizeContentTypeModules = (onChange: OnChangeFormType, modules: Record<string, any>[]) => {
|
|
21
23
|
const sanitizedModules = sanitizeModules(modules);
|
|
22
24
|
|
|
23
25
|
return onChange({
|
|
@@ -28,3 +30,9 @@ const replaceContentTypeModules = (onChange: OnChangeFormType, modules: Record<s
|
|
|
28
30
|
shouldSetInitialValue: true
|
|
29
31
|
});
|
|
30
32
|
};
|
|
33
|
+
|
|
34
|
+
const replaceContentTypeModules = async (id: number, fetchClient: any, onChange: OnChangeFormType) => {
|
|
35
|
+
const { get } = fetchClient;
|
|
36
|
+
const result = await get(getRequestUrl(`/template/${id}`));
|
|
37
|
+
return sanatizeContentTypeModules(onChange, result.data.modules);
|
|
38
|
+
};
|
|
@@ -13,7 +13,9 @@ export const EditView = () => {
|
|
|
13
13
|
const isPageCollectionType = layout.uid === PAGE_UID;
|
|
14
14
|
const isCollectionType = layout.kind === 'collectionType';
|
|
15
15
|
|
|
16
|
-
const { data: hasPageRelation, isLoading } = useHasPageRelation({
|
|
16
|
+
const { data: hasPageRelation, isLoading } = useHasPageRelation({
|
|
17
|
+
uid: layout.uid
|
|
18
|
+
});
|
|
17
19
|
|
|
18
20
|
if (isPageCollectionType) {
|
|
19
21
|
return <PageSettings />;
|
|
@@ -9,15 +9,17 @@ interface Props {
|
|
|
9
9
|
onChange: (pageTypeId: string) => void;
|
|
10
10
|
selectedPageType?: PageType | null;
|
|
11
11
|
pageTypes?: PageType[];
|
|
12
|
+
disabled: boolean;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
export const PageTypeSelect = ({ onChange, pageTypes, selectedPageType }: Props) => {
|
|
15
|
+
export const PageTypeSelect = ({ onChange, pageTypes, selectedPageType, disabled }: Props) => {
|
|
15
16
|
return (
|
|
16
17
|
<SingleSelect
|
|
17
18
|
label="Page type"
|
|
18
19
|
placeholder="Choose a page type"
|
|
19
20
|
value={selectedPageType?.id || PAGE_TYPE_PAGE}
|
|
20
21
|
onChange={onChange}
|
|
22
|
+
disabled={disabled}
|
|
21
23
|
>
|
|
22
24
|
<SingleSelectOption value={PAGE_TYPE_PAGE}>Page</SingleSelectOption>
|
|
23
25
|
{pageTypes?.map((pageType: PageType) => (
|
package/admin/src/constants.ts
CHANGED
package/admin/src/index.tsx
CHANGED
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webbio/strapi-plugin-page-builder",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "This is the description of the plugin.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"develop": "tsc -p tsconfig.server.json -w",
|
|
@@ -20,17 +20,17 @@
|
|
|
20
20
|
"url": "https://github.com/webbio/strapi-plugin-page-builder.git"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@strapi/design-system": "^1.
|
|
24
|
-
"@strapi/helper-plugin": "^4.
|
|
25
|
-
"@strapi/icons": "^1.
|
|
26
|
-
"@strapi/typescript-utils": "^4.
|
|
27
|
-
"@strapi/utils": "^4.
|
|
23
|
+
"@strapi/design-system": "^1.11.0",
|
|
24
|
+
"@strapi/helper-plugin": "^4.13.6",
|
|
25
|
+
"@strapi/icons": "^1.11.0",
|
|
26
|
+
"@strapi/typescript-utils": "^4.13.6",
|
|
27
|
+
"@strapi/utils": "^4.13.6",
|
|
28
28
|
"react-select": "^5.7.4"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@strapi/typescript-utils": "^4.
|
|
32
|
-
"@types/react": "^
|
|
33
|
-
"@types/react-dom": "^18.
|
|
31
|
+
"@strapi/typescript-utils": "^4.13.6",
|
|
32
|
+
"@types/react": "^18.2.21",
|
|
33
|
+
"@types/react-dom": "^18.2.7",
|
|
34
34
|
"@types/react-router-dom": "^5.3.3",
|
|
35
35
|
"@types/styled-components": "^5.1.26",
|
|
36
36
|
"react": "^18.2.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"typescript": "5.1.6"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@strapi/strapi": "^4.
|
|
43
|
+
"@strapi/strapi": "^4.13.6",
|
|
44
44
|
"@webbio/strapi-plugin-slug": "^0.1.0",
|
|
45
45
|
"react": "^17.0.0 || ^18.0.0",
|
|
46
46
|
"react-dom": "^17.0.0 || ^18.0.0",
|
package/dist/server/bootstrap.js
CHANGED
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const utils_1 = require("@strapi/utils");
|
|
4
4
|
const constants_1 = require("../shared/utils/constants");
|
|
5
5
|
exports.default = async ({ strapi }) => {
|
|
6
|
+
var _a, _b;
|
|
6
7
|
// TODO: refactor to own function
|
|
7
8
|
try {
|
|
8
|
-
const pageTypes = await strapi.entityService.findMany(
|
|
9
|
+
const pageTypes = (await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_TYPE_UID, {
|
|
9
10
|
limit: -1
|
|
10
|
-
});
|
|
11
|
+
})));
|
|
11
12
|
const pagePermissions = pageTypes.map((pageType) => {
|
|
12
13
|
const name = `page-type-is-${pageType.uid}`;
|
|
13
14
|
const displayName = pageType.title;
|
|
@@ -50,27 +51,28 @@ exports.default = async ({ strapi }) => {
|
|
|
50
51
|
};
|
|
51
52
|
return data;
|
|
52
53
|
};
|
|
53
|
-
strapi.db.lifecycles.subscribe({
|
|
54
|
+
(_b = strapi.db) === null || _b === void 0 ? void 0 : _b.lifecycles.subscribe({
|
|
54
55
|
// @ts-ignore
|
|
55
56
|
models: [constants_1.PAGE_UID],
|
|
56
57
|
async beforeCreate(event) {
|
|
57
|
-
var _a, _b;
|
|
58
|
+
var _a, _b, _c, _d;
|
|
58
59
|
let { data } = event.params;
|
|
59
60
|
const collectionTypeId = data === null || data === void 0 ? void 0 : data.collectionTypeId;
|
|
60
61
|
const pageTypeId = ((_b = (_a = data === null || data === void 0 ? void 0 : data.pageType.connect) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.id) || data.initialPageType;
|
|
61
62
|
if (collectionTypeId && pageTypeId) {
|
|
62
|
-
const
|
|
63
|
-
const collectionToConnect = await strapi.entityService.findOne(uid, collectionTypeId, {
|
|
63
|
+
const pageType = await ((_c = strapi.entityService) === null || _c === void 0 ? void 0 : _c.findOne(constants_1.PAGE_TYPE_UID, pageTypeId));
|
|
64
|
+
const collectionToConnect = await ((_d = strapi.entityService) === null || _d === void 0 ? void 0 : _d.findOne(pageType === null || pageType === void 0 ? void 0 : pageType.uid, collectionTypeId, {
|
|
64
65
|
populate: { page: true }
|
|
65
|
-
});
|
|
66
|
-
|
|
66
|
+
}));
|
|
67
|
+
const page = collectionToConnect === null || collectionToConnect === void 0 ? void 0 : collectionToConnect.page;
|
|
68
|
+
if (page && page.length > 0) {
|
|
67
69
|
throw new utils_1.errors.ValidationError('You can only link one CollectionType to one page');
|
|
68
70
|
}
|
|
69
|
-
data = updateCollectionTypeData(data, collectionTypeId, uid);
|
|
71
|
+
data = updateCollectionTypeData(data, collectionTypeId, pageType === null || pageType === void 0 ? void 0 : pageType.uid);
|
|
70
72
|
}
|
|
71
73
|
},
|
|
72
74
|
async beforeUpdate(event) {
|
|
73
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
75
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
74
76
|
let data = (_a = event === null || event === void 0 ? void 0 : event.params) === null || _a === void 0 ? void 0 : _a.data;
|
|
75
77
|
const collectionTypeId = data === null || data === void 0 ? void 0 : data.collectionTypeId;
|
|
76
78
|
const pageTypeId = ((_d = (_c = (_b = data === null || data === void 0 ? void 0 : data.pageType) === null || _b === void 0 ? void 0 : _b.connect) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.id) || (data === null || data === void 0 ? void 0 : data.initialPageType);
|
|
@@ -79,16 +81,83 @@ exports.default = async ({ strapi }) => {
|
|
|
79
81
|
data.collectionTypeData = undefined;
|
|
80
82
|
}
|
|
81
83
|
if (collectionTypeId && pageTypeId && !removedPageType) {
|
|
82
|
-
const
|
|
83
|
-
const collectionToConnect = await strapi.entityService.findOne(uid, collectionTypeId, {
|
|
84
|
+
const pageType = await ((_h = strapi.entityService) === null || _h === void 0 ? void 0 : _h.findOne(constants_1.PAGE_TYPE_UID, pageTypeId));
|
|
85
|
+
const collectionToConnect = await ((_j = strapi.entityService) === null || _j === void 0 ? void 0 : _j.findOne(pageType === null || pageType === void 0 ? void 0 : pageType.uid, collectionTypeId, {
|
|
84
86
|
populate: { page: true }
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
!(collectionToConnect === null || collectionToConnect === void 0 ? void 0 : collectionToConnect.page.some((p) => p.id === data.id))) {
|
|
87
|
+
}));
|
|
88
|
+
const page = collectionToConnect === null || collectionToConnect === void 0 ? void 0 : collectionToConnect.page;
|
|
89
|
+
if (page && (page === null || page === void 0 ? void 0 : page.length) > 0 && !page.some((p) => p.id === data.id)) {
|
|
89
90
|
throw new utils_1.errors.ValidationError('You can only link one CollectionType to one page');
|
|
90
91
|
}
|
|
91
|
-
data = updateCollectionTypeData(data, collectionTypeId, uid);
|
|
92
|
+
data = updateCollectionTypeData(data, collectionTypeId, pageType === null || pageType === void 0 ? void 0 : pageType.uid);
|
|
93
|
+
}
|
|
94
|
+
// needs to check if the collectionTypeData is already connected to another page
|
|
95
|
+
// if so, remove the hasPage for filtering
|
|
96
|
+
// const foundPage = await strapi.entityService?.findOne(PAGE_UID, data.id, { populate: '*' });
|
|
97
|
+
// if (
|
|
98
|
+
// data.collectionTypeData &&
|
|
99
|
+
// foundPage &&
|
|
100
|
+
// foundPage.collectionTypeData &&
|
|
101
|
+
// +data.collectionTypeData.id !== foundPage.collectionTypeData[0].id
|
|
102
|
+
// ) {
|
|
103
|
+
// await strapi.entityService?.update(foundPage.collectionTypeData[0].__type, foundPage.collectionTypeData[0].id, {
|
|
104
|
+
// data: {
|
|
105
|
+
// id: foundPage.collectionTypeData[0].id,
|
|
106
|
+
// hasPage: false
|
|
107
|
+
// }
|
|
108
|
+
// });
|
|
109
|
+
// }
|
|
110
|
+
},
|
|
111
|
+
async afterUpdate(event) {
|
|
112
|
+
var _a, _b;
|
|
113
|
+
const data = (_a = event === null || event === void 0 ? void 0 : event.params) === null || _a === void 0 ? void 0 : _a.data;
|
|
114
|
+
console.log(data);
|
|
115
|
+
if (data.collectionTypeData) {
|
|
116
|
+
await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.update(data.collectionTypeData.__type, data.collectionTypeData.id, {
|
|
117
|
+
data: {
|
|
118
|
+
id: data.collectionTypeData.id,
|
|
119
|
+
hasPage: true
|
|
120
|
+
}
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
async afterCreate(event) {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
const data = (_a = event === null || event === void 0 ? void 0 : event.params) === null || _a === void 0 ? void 0 : _a.data;
|
|
127
|
+
if (data.collectionTypeData) {
|
|
128
|
+
await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.update(data.collectionTypeData.__type, data.collectionTypeData.id, {
|
|
129
|
+
data: {
|
|
130
|
+
id: data.collectionTypeData.id,
|
|
131
|
+
hasPage: true
|
|
132
|
+
}
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
async beforeDelete(event) {
|
|
137
|
+
var _a, _b;
|
|
138
|
+
const foundPage = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findOne(constants_1.PAGE_UID, event.params.where.id, { populate: '*' }));
|
|
139
|
+
if (foundPage && foundPage.collectionTypeData) {
|
|
140
|
+
await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.update(foundPage.collectionTypeData[0].__type, foundPage.collectionTypeData[0].id, {
|
|
141
|
+
data: {
|
|
142
|
+
id: foundPage.collectionTypeData[0].id,
|
|
143
|
+
hasPage: false
|
|
144
|
+
}
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
async beforeDeleteMany(event) {
|
|
149
|
+
var _a, _b;
|
|
150
|
+
const pagesToUnConnect = event.params.where['$and'][0].id['$in'];
|
|
151
|
+
for (const pageId of pagesToUnConnect) {
|
|
152
|
+
const foundPage = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findOne(constants_1.PAGE_UID, pageId, { populate: '*' }));
|
|
153
|
+
if (foundPage && foundPage.collectionTypeData) {
|
|
154
|
+
await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.update(foundPage.collectionTypeData[0].__type, foundPage.collectionTypeData[0].id, {
|
|
155
|
+
data: {
|
|
156
|
+
id: foundPage.collectionTypeData[0].id,
|
|
157
|
+
hasPage: false
|
|
158
|
+
}
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
92
161
|
}
|
|
93
162
|
}
|
|
94
163
|
});
|
|
@@ -4,7 +4,6 @@ exports.default = {
|
|
|
4
4
|
async hasPageRelation(ctx) {
|
|
5
5
|
var _a;
|
|
6
6
|
const uid = (_a = ctx.params) === null || _a === void 0 ? void 0 : _a.uid;
|
|
7
|
-
// @ts-ignore
|
|
8
7
|
return strapi.service('plugin::page-builder.collection-types').hasPageRelation(uid);
|
|
9
8
|
},
|
|
10
9
|
async getTranslationPageLinks(ctx) {
|
|
@@ -13,7 +12,6 @@ exports.default = {
|
|
|
13
12
|
if (!uid || (idsArr === null || idsArr === void 0 ? void 0 : idsArr.length) === 0) {
|
|
14
13
|
return undefined;
|
|
15
14
|
}
|
|
16
|
-
// @ts-ignore
|
|
17
15
|
return strapi.service('plugin::page-builder.collection-types').getTranslationPageLinks(uid, idsArr);
|
|
18
16
|
}
|
|
19
17
|
};
|
|
@@ -6,8 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const page_1 = __importDefault(require("./page"));
|
|
7
7
|
const page_type_1 = __importDefault(require("./page-type"));
|
|
8
8
|
const collection_types_1 = __importDefault(require("./collection-types"));
|
|
9
|
+
const template_1 = __importDefault(require("./template"));
|
|
9
10
|
exports.default = {
|
|
10
11
|
page: page_1.default,
|
|
11
12
|
'page-type': page_type_1.default,
|
|
12
|
-
'collection-types': collection_types_1.default
|
|
13
|
+
'collection-types': collection_types_1.default,
|
|
14
|
+
template: template_1.default
|
|
13
15
|
};
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const constants_1 = require("../../shared/utils/constants");
|
|
4
3
|
exports.default = {
|
|
5
4
|
async getPage(ctx) {
|
|
6
5
|
var _a, _b;
|
|
7
6
|
const id = (_a = ctx.params) === null || _a === void 0 ? void 0 : _a.id;
|
|
8
7
|
return (_b = strapi.service('plugin::page-builder.page')) === null || _b === void 0 ? void 0 : _b.getPage(id);
|
|
9
|
-
},
|
|
10
|
-
async findOneBySlug(ctx) {
|
|
11
|
-
var _a;
|
|
12
|
-
const { slug = '' } = ctx.params;
|
|
13
|
-
const entity = await ((_a = strapi.service(constants_1.PAGE_UID)) === null || _a === void 0 ? void 0 : _a.find({ filters: { slug } }));
|
|
14
|
-
const sanitizedEntity = await this.sanitizeOutput(entity, ctx);
|
|
15
|
-
return this.transformResponse(sanitizedEntity);
|
|
16
8
|
}
|
|
17
9
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
async findAll() {
|
|
5
|
+
return await strapi.service('plugin::page-builder.platform').findAll();
|
|
6
|
+
},
|
|
7
|
+
async findOneByUid(ctx) {
|
|
8
|
+
var _a;
|
|
9
|
+
const uid = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.params) === null || _a === void 0 ? void 0 : _a.uid;
|
|
10
|
+
if (!uid) {
|
|
11
|
+
return ctx.badRequest('uid is missing.');
|
|
12
|
+
}
|
|
13
|
+
return await strapi.service('plugin::page-builder.platform').findOneByUid(uid);
|
|
14
|
+
},
|
|
15
|
+
async findPageTypesByPlatform(ctx) {
|
|
16
|
+
var _a;
|
|
17
|
+
const platform = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.params) === null || _a === void 0 ? void 0 : _a.platform;
|
|
18
|
+
return await strapi.services['plugin::page-builder.platform'].findPageTypesByPlatform(platform);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
async findOneById(ctx) {
|
|
5
|
+
var _a;
|
|
6
|
+
const id = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.params) === null || _a === void 0 ? void 0 : _a.id;
|
|
7
|
+
if (!id) {
|
|
8
|
+
return ctx.badRequest('id is missing.');
|
|
9
|
+
}
|
|
10
|
+
return await strapi.service('plugin::page-builder.template').findOne(id);
|
|
11
|
+
},
|
|
12
|
+
async findAll() {
|
|
13
|
+
return await strapi.service('plugin::page-builder.template').findAll();
|
|
14
|
+
}
|
|
15
|
+
};
|