@webbio/strapi-plugin-page-builder 0.0.21 → 0.0.23
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 +0 -4
- package/dist/package.json +1 -1
- package/dist/server/queries/index.js +9 -0
- package/dist/server/queries/page.js +85 -0
- package/dist/server/register.js +6 -0
- package/dist/server/schema/page-end.json +0 -6
- package/dist/server/services/builder.js +4 -18
- package/dist/server/utils/filter-underscore-arguments.js +14 -0
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/server/queries/index.ts +5 -0
- package/server/queries/page.ts +101 -0
- package/server/register.ts +6 -0
- package/server/schema/page-end.json +0 -6
- package/server/services/builder.ts +4 -23
- package/server/utils/filter-underscore-arguments.ts +12 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/server/schema/template-end.json +0 -41
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Strapi } from '@strapi/strapi';
|
|
2
|
+
|
|
3
|
+
import { filterUnderscoreArguments } from '../utils/filter-underscore-arguments';
|
|
4
|
+
import { PAGE_UID } from '../../shared/utils/constants';
|
|
5
|
+
|
|
6
|
+
const getPageBySlug = (strapi: Strapi) => {
|
|
7
|
+
const typeDefs = () => {
|
|
8
|
+
return `
|
|
9
|
+
extend type Page {
|
|
10
|
+
collectionTypeId: String
|
|
11
|
+
collectionType: GenericMorph
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type Query {
|
|
15
|
+
getPageBySlug(path: String, _locale: String, _publicationState: PublicationState): PageEntity
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
`;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const resolvers = (strapi: Strapi) => {
|
|
22
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
Query: {
|
|
26
|
+
getPageBySlug: {
|
|
27
|
+
resolve: async (_parent: any, args: Record<string, any>, ctx: any) => {
|
|
28
|
+
const filteredArgs = {
|
|
29
|
+
...filterUnderscoreArguments(args)
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
|
|
33
|
+
|
|
34
|
+
const getPage = async () => {
|
|
35
|
+
const id = PAGE_UID;
|
|
36
|
+
|
|
37
|
+
const transformedArgs = transformArgs(filteredArgs, {
|
|
38
|
+
contentType: strapi.contentTypes[id],
|
|
39
|
+
usePagination: false
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const results = await strapi.entityService.findMany(id, {
|
|
43
|
+
filters: transformedArgs,
|
|
44
|
+
locale: args._locale,
|
|
45
|
+
publicationState: args._publicationState,
|
|
46
|
+
populate: '*'
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const entityResponse = toEntityResponse(results[0], {
|
|
50
|
+
args: transformedArgs,
|
|
51
|
+
resourceUID: id
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (!entityResponse?.value) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const collectionTypeDataFilter = entityResponse?.value?.collectionTypeData?.filter(Boolean);
|
|
59
|
+
|
|
60
|
+
const collectionType = collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter?.[0] : null;
|
|
61
|
+
|
|
62
|
+
const addedAttributes = {
|
|
63
|
+
collectionType,
|
|
64
|
+
collectionTypeId: collectionType?.id || null
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const result = {
|
|
68
|
+
...entityResponse.value,
|
|
69
|
+
...addedAttributes
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return result;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const results: Record<string, any> = await getPage();
|
|
76
|
+
|
|
77
|
+
if (Object.values(results)?.filter(Boolean).length > 0) {
|
|
78
|
+
return results;
|
|
79
|
+
} else {
|
|
80
|
+
throw new Error(ctx.koaContext.response.message);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const resolversConfig = {
|
|
89
|
+
'Query.getPageBySlug': {
|
|
90
|
+
auth: false
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
typeDefs: typeDefs(),
|
|
96
|
+
resolvers: resolvers(strapi),
|
|
97
|
+
resolversConfig
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export default getPageBySlug;
|
package/server/register.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Strapi } from '@strapi/strapi';
|
|
2
2
|
|
|
3
|
+
import getPageBySlug from './queries/page';
|
|
4
|
+
|
|
3
5
|
export default async ({ strapi }: { strapi: Strapi }) => {
|
|
6
|
+
const extensionService = strapi.plugin('graphql').service('extension');
|
|
7
|
+
|
|
8
|
+
extensionService.use(getPageBySlug(strapi));
|
|
9
|
+
|
|
4
10
|
await strapi.services?.['plugin::page-builder.builder']?.buildContentTypes();
|
|
5
11
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import partition from 'lodash/partition';
|
|
2
|
-
import isEqual from 'lodash/isEqual';
|
|
3
2
|
|
|
4
3
|
import { Service } from '@strapi/strapi/lib/types/core/common';
|
|
5
4
|
|
|
@@ -11,9 +10,7 @@ import { reloadStrapiOnLoad } from '../utils/reload-strapi-on-load';
|
|
|
11
10
|
import pageTypeStart from '../schema/page-type-start.json';
|
|
12
11
|
import pageTypeEnd from '../schema/page-type-end.json';
|
|
13
12
|
import templateStart from '../schema/template-start.json';
|
|
14
|
-
import templateEnd from '../schema/template-end.json';
|
|
15
13
|
|
|
16
|
-
// We use template twice, see Readme for more info
|
|
17
14
|
const UIDS = [TEMPLATE_UID, PAGE_TYPE_UID, PAGE_UID];
|
|
18
15
|
|
|
19
16
|
export default {
|
|
@@ -70,12 +67,8 @@ export default {
|
|
|
70
67
|
}
|
|
71
68
|
|
|
72
69
|
if ((updateTypes || []).length > 0) {
|
|
73
|
-
for (const updateType of updateTypes) {
|
|
70
|
+
for await (const updateType of updateTypes) {
|
|
74
71
|
await ctb.editContentType(updateType.uid, { contentType: updateType.contentType, components: [] });
|
|
75
|
-
|
|
76
|
-
if (updateType.uid === PAGE_UID) {
|
|
77
|
-
strapi.reload();
|
|
78
|
-
}
|
|
79
72
|
}
|
|
80
73
|
}
|
|
81
74
|
},
|
|
@@ -90,7 +83,7 @@ export default {
|
|
|
90
83
|
update: this.getPageTypeContentType()
|
|
91
84
|
},
|
|
92
85
|
[TEMPLATE_UID]: {
|
|
93
|
-
create: this.getTemplateContentType(
|
|
86
|
+
create: this.getTemplateContentType(),
|
|
94
87
|
update: this.getTemplateContentType()
|
|
95
88
|
}
|
|
96
89
|
};
|
|
@@ -101,10 +94,6 @@ export default {
|
|
|
101
94
|
const page = create ? pageStart : pageEnd;
|
|
102
95
|
const contentType = this.mergeCollectionTypeWithModules(page, PAGE_UID);
|
|
103
96
|
|
|
104
|
-
if (this.collectionTypesAreEqual(contentType, TEMPLATE_UID)) {
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
97
|
return { uid: PAGE_UID, contentType };
|
|
109
98
|
},
|
|
110
99
|
getPageTypeContentType(create?: boolean) {
|
|
@@ -113,8 +102,8 @@ export default {
|
|
|
113
102
|
|
|
114
103
|
return { uid: PAGE_TYPE_UID, contentType };
|
|
115
104
|
},
|
|
116
|
-
getTemplateContentType(
|
|
117
|
-
const pageType =
|
|
105
|
+
getTemplateContentType() {
|
|
106
|
+
const pageType = templateStart;
|
|
118
107
|
const contentType = this.mergeCollectionTypeWithModules(pageType, TEMPLATE_UID);
|
|
119
108
|
|
|
120
109
|
return { uid: TEMPLATE_UID, contentType };
|
|
@@ -137,14 +126,6 @@ export default {
|
|
|
137
126
|
}
|
|
138
127
|
};
|
|
139
128
|
},
|
|
140
|
-
collectionTypesAreEqual(collectionType: Record<string, any>, uid: string) {
|
|
141
|
-
const { pluginOptions: oldPluginOptions, __schema__: oldSchema } = strapi.contentType(uid) || {};
|
|
142
|
-
|
|
143
|
-
return (
|
|
144
|
-
isEqual(oldSchema.attributes, collectionType?.attributes) &&
|
|
145
|
-
isEqual(oldPluginOptions, collectionType?.pluginOptions)
|
|
146
|
-
);
|
|
147
|
-
},
|
|
148
129
|
getConfigModuleComponents() {
|
|
149
130
|
return (strapi.config.get(`plugin.${pluginId}`)?.modules || []).filter(Boolean);
|
|
150
131
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const filterUnderscoreArguments = (args: Record<string, any>) => {
|
|
2
|
+
const newArgs = {};
|
|
3
|
+
const objectArray = Object.keys(args);
|
|
4
|
+
|
|
5
|
+
objectArray.forEach((key) => {
|
|
6
|
+
if (!key.startsWith('_')) {
|
|
7
|
+
newArgs[key] = args[key];
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
return newArgs;
|
|
12
|
+
};
|