@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
package/README.md
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
# Strapi plugin page-builder
|
|
2
2
|
|
|
3
3
|
A quick description of page-builder.
|
|
4
|
-
|
|
5
|
-
# Notes
|
|
6
|
-
|
|
7
|
-
In the `builder.ts` service, we refer to the template uid twice. This is necessary because the template json is editted by the page UID that comes second. If a change in modules has been made, this change will be removed again from the template once the page is updated. This is because the page has a reference to the template and will edit the template.json.
|
package/dist/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const page_1 = __importDefault(require("./page"));
|
|
7
|
+
exports.default = {
|
|
8
|
+
page: page_1.default
|
|
9
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const filter_underscore_arguments_1 = require("../utils/filter-underscore-arguments");
|
|
4
|
+
const constants_1 = require("../../shared/utils/constants");
|
|
5
|
+
const getPageBySlug = (strapi) => {
|
|
6
|
+
const typeDefs = () => {
|
|
7
|
+
return `
|
|
8
|
+
extend type Page {
|
|
9
|
+
collectionTypeId: String
|
|
10
|
+
collectionType: GenericMorph
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type Query {
|
|
14
|
+
getPageBySlug(path: String, _locale: String, _publicationState: PublicationState): PageEntity
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
`;
|
|
18
|
+
};
|
|
19
|
+
const resolvers = (strapi) => {
|
|
20
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
21
|
+
return {
|
|
22
|
+
Query: {
|
|
23
|
+
getPageBySlug: {
|
|
24
|
+
resolve: async (_parent, args, ctx) => {
|
|
25
|
+
var _a;
|
|
26
|
+
const filteredArgs = {
|
|
27
|
+
...(0, filter_underscore_arguments_1.filterUnderscoreArguments)(args)
|
|
28
|
+
};
|
|
29
|
+
const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
|
|
30
|
+
const getPage = async () => {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
const id = constants_1.PAGE_UID;
|
|
33
|
+
const transformedArgs = transformArgs(filteredArgs, {
|
|
34
|
+
contentType: strapi.contentTypes[id],
|
|
35
|
+
usePagination: false
|
|
36
|
+
});
|
|
37
|
+
const results = await strapi.entityService.findMany(id, {
|
|
38
|
+
filters: transformedArgs,
|
|
39
|
+
locale: args._locale,
|
|
40
|
+
publicationState: args._publicationState,
|
|
41
|
+
populate: '*'
|
|
42
|
+
});
|
|
43
|
+
const entityResponse = toEntityResponse(results[0], {
|
|
44
|
+
args: transformedArgs,
|
|
45
|
+
resourceUID: id
|
|
46
|
+
});
|
|
47
|
+
if (!(entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value)) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const collectionTypeDataFilter = (_b = (_a = entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) === null || _a === void 0 ? void 0 : _a.collectionTypeData) === null || _b === void 0 ? void 0 : _b.filter(Boolean);
|
|
51
|
+
const collectionType = collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter === null || collectionTypeDataFilter === void 0 ? void 0 : collectionTypeDataFilter[0] : null;
|
|
52
|
+
const addedAttributes = {
|
|
53
|
+
collectionType,
|
|
54
|
+
collectionTypeId: (collectionType === null || collectionType === void 0 ? void 0 : collectionType.id) || null
|
|
55
|
+
};
|
|
56
|
+
const result = {
|
|
57
|
+
...entityResponse.value,
|
|
58
|
+
...addedAttributes
|
|
59
|
+
};
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
62
|
+
const results = await getPage();
|
|
63
|
+
if (((_a = Object.values(results)) === null || _a === void 0 ? void 0 : _a.filter(Boolean).length) > 0) {
|
|
64
|
+
return results;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw new Error(ctx.koaContext.response.message);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const resolversConfig = {
|
|
75
|
+
'Query.getPageBySlug': {
|
|
76
|
+
auth: false
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
typeDefs: typeDefs(),
|
|
81
|
+
resolvers: resolvers(strapi),
|
|
82
|
+
resolversConfig
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
exports.default = getPageBySlug;
|
package/dist/server/register.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const page_1 = __importDefault(require("./queries/page"));
|
|
3
7
|
exports.default = async ({ strapi }) => {
|
|
4
8
|
var _a, _b;
|
|
9
|
+
const extensionService = strapi.plugin('graphql').service('extension');
|
|
10
|
+
extensionService.use((0, page_1.default)(strapi));
|
|
5
11
|
await ((_b = (_a = strapi.services) === null || _a === void 0 ? void 0 : _a['plugin::page-builder.builder']) === null || _b === void 0 ? void 0 : _b.buildContentTypes());
|
|
6
12
|
};
|
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const partition_1 = __importDefault(require("lodash/partition"));
|
|
7
|
-
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
8
7
|
const page_start_json_1 = __importDefault(require("../schema/page-start.json"));
|
|
9
8
|
const page_end_json_1 = __importDefault(require("../schema/page-end.json"));
|
|
10
9
|
const pluginId_1 = __importDefault(require("../../admin/src/pluginId"));
|
|
@@ -13,8 +12,6 @@ const reload_strapi_on_load_1 = require("../utils/reload-strapi-on-load");
|
|
|
13
12
|
const page_type_start_json_1 = __importDefault(require("../schema/page-type-start.json"));
|
|
14
13
|
const page_type_end_json_1 = __importDefault(require("../schema/page-type-end.json"));
|
|
15
14
|
const template_start_json_1 = __importDefault(require("../schema/template-start.json"));
|
|
16
|
-
const template_end_json_1 = __importDefault(require("../schema/template-end.json"));
|
|
17
|
-
// We use template twice, see Readme for more info
|
|
18
15
|
const UIDS = [constants_1.TEMPLATE_UID, constants_1.PAGE_TYPE_UID, constants_1.PAGE_UID];
|
|
19
16
|
exports.default = {
|
|
20
17
|
async buildContentTypes() {
|
|
@@ -54,11 +51,8 @@ exports.default = {
|
|
|
54
51
|
await ctb.createContentTypes(newTypes.map((c) => ({ contentType: c.contentType, components: [] })));
|
|
55
52
|
}
|
|
56
53
|
if ((updateTypes || []).length > 0) {
|
|
57
|
-
for (const updateType of updateTypes) {
|
|
54
|
+
for await (const updateType of updateTypes) {
|
|
58
55
|
await ctb.editContentType(updateType.uid, { contentType: updateType.contentType, components: [] });
|
|
59
|
-
if (updateType.uid === constants_1.PAGE_UID) {
|
|
60
|
-
strapi.reload();
|
|
61
|
-
}
|
|
62
56
|
}
|
|
63
57
|
}
|
|
64
58
|
},
|
|
@@ -73,7 +67,7 @@ exports.default = {
|
|
|
73
67
|
update: this.getPageTypeContentType()
|
|
74
68
|
},
|
|
75
69
|
[constants_1.TEMPLATE_UID]: {
|
|
76
|
-
create: this.getTemplateContentType(
|
|
70
|
+
create: this.getTemplateContentType(),
|
|
77
71
|
update: this.getTemplateContentType()
|
|
78
72
|
}
|
|
79
73
|
};
|
|
@@ -82,9 +76,6 @@ exports.default = {
|
|
|
82
76
|
getPageContentType(create) {
|
|
83
77
|
const page = create ? page_start_json_1.default : page_end_json_1.default;
|
|
84
78
|
const contentType = this.mergeCollectionTypeWithModules(page, constants_1.PAGE_UID);
|
|
85
|
-
if (this.collectionTypesAreEqual(contentType, constants_1.TEMPLATE_UID)) {
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
79
|
return { uid: constants_1.PAGE_UID, contentType };
|
|
89
80
|
},
|
|
90
81
|
getPageTypeContentType(create) {
|
|
@@ -92,8 +83,8 @@ exports.default = {
|
|
|
92
83
|
const contentType = this.mergeCollectionTypeWithModules(pageType, constants_1.PAGE_TYPE_UID);
|
|
93
84
|
return { uid: constants_1.PAGE_TYPE_UID, contentType };
|
|
94
85
|
},
|
|
95
|
-
getTemplateContentType(
|
|
96
|
-
const pageType =
|
|
86
|
+
getTemplateContentType() {
|
|
87
|
+
const pageType = template_start_json_1.default;
|
|
97
88
|
const contentType = this.mergeCollectionTypeWithModules(pageType, constants_1.TEMPLATE_UID);
|
|
98
89
|
return { uid: constants_1.TEMPLATE_UID, contentType };
|
|
99
90
|
},
|
|
@@ -113,11 +104,6 @@ exports.default = {
|
|
|
113
104
|
}
|
|
114
105
|
};
|
|
115
106
|
},
|
|
116
|
-
collectionTypesAreEqual(collectionType, uid) {
|
|
117
|
-
const { pluginOptions: oldPluginOptions, __schema__: oldSchema } = strapi.contentType(uid) || {};
|
|
118
|
-
return ((0, isEqual_1.default)(oldSchema.attributes, collectionType === null || collectionType === void 0 ? void 0 : collectionType.attributes) &&
|
|
119
|
-
(0, isEqual_1.default)(oldPluginOptions, collectionType === null || collectionType === void 0 ? void 0 : collectionType.pluginOptions));
|
|
120
|
-
},
|
|
121
107
|
getConfigModuleComponents() {
|
|
122
108
|
var _a;
|
|
123
109
|
return (((_a = strapi.config.get(`plugin.${pluginId_1.default}`)) === null || _a === void 0 ? void 0 : _a.modules) || []).filter(Boolean);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterUnderscoreArguments = void 0;
|
|
4
|
+
const filterUnderscoreArguments = (args) => {
|
|
5
|
+
const newArgs = {};
|
|
6
|
+
const objectArray = Object.keys(args);
|
|
7
|
+
objectArray.forEach((key) => {
|
|
8
|
+
if (!key.startsWith('_')) {
|
|
9
|
+
newArgs[key] = args[key];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return newArgs;
|
|
13
|
+
};
|
|
14
|
+
exports.filterUnderscoreArguments = filterUnderscoreArguments;
|