@webbio/strapi-plugin-page-builder 0.0.13 → 0.0.15

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.
@@ -1,12 +1,6 @@
1
1
  import styled, { css } from 'styled-components';
2
2
 
3
- import { Typography, Button } from '@strapi/design-system';
4
-
5
- const SubtleType = styled(Typography)`
6
- ${({ _theme }) => css`
7
- text-transform: capitalize;
8
- `}
9
- `;
3
+ import { Button } from '@strapi/design-system';
10
4
 
11
5
  const CreateButton = styled(Button)`
12
6
  ${({ _theme }) => css`
@@ -19,7 +13,6 @@ const CreateButton = styled(Button)`
19
13
  `;
20
14
 
21
15
  const CreatePageButtonStyles = {
22
- SubtleType,
23
16
  CreateButton
24
17
  };
25
18
 
@@ -35,8 +35,8 @@ const EditLink = styled(Button)`
35
35
  ${({ _theme }) => css`
36
36
  text-decoration: none;
37
37
 
38
- > div {
39
- display: flex;
38
+ svg {
39
+ flex-shrink: 0;
40
40
  }
41
41
  `}
42
42
  `;
@@ -1,73 +1,17 @@
1
1
  import { prefixPluginTranslations } from '@strapi/helper-plugin';
2
2
 
3
- import { getFetchClient } from '@strapi/helper-plugin';
4
-
5
3
  import pluginPkg from '../../package.json';
6
4
  import pluginId from './pluginId';
7
5
  import Initializer from './components/Initializer';
8
- import PluginIcon from './components/PluginIcon';
9
6
  import PageTypeFilter from './components/PageTypeFilter';
10
7
  import { EditView } from './components/EditView';
11
- import getRequestUrl from './utils/getRequestUrl';
12
- import { PAGE_UID } from '../../shared/utils/constants';
8
+ import middlewares from './middlewares';
13
9
 
14
10
  const name = pluginPkg.strapi.name;
15
11
 
16
- const middleware =
17
- () =>
18
- ({ getState }: any) =>
19
- (next: any) =>
20
- async (action: any) => {
21
- // If data is being fetched or after a save
22
- if (
23
- action.type === 'ContentManager/CrudReducer/GET_DATA_SUCCEEDED' ||
24
- action.type === 'ContentManager/CrudReducer/SUBMIT_SUCCEEDED'
25
- ) {
26
- const store = getState();
27
- const layoutSlice = store['content-manager_editViewLayoutManager'];
28
- const uid = layoutSlice.currentLayout.contentType.uid;
29
-
30
- if (uid !== PAGE_UID) {
31
- return next(action);
32
- }
33
-
34
- const { get } = await getFetchClient();
35
- const { data: pageData } = await get(`${getRequestUrl('page')}/${action.data.id}`);
36
-
37
- action.data.collectionTypeTitle = pageData?.collectionTypeData?.title;
38
- action.data.collectionTypeId = pageData?.collectionTypeData?.id;
39
- action.data.initialPageType = pageData?.pageType ? pageData.pageType : undefined;
40
-
41
- return next(action);
42
- }
43
- return next(action);
44
- };
45
-
46
- const middlewares = [middleware];
47
-
48
12
  export default {
49
13
  register(app: any) {
50
14
  app.addMiddlewares(middlewares);
51
- app.addMenuLink({
52
- to: `/plugins/${pluginId}`,
53
- icon: PluginIcon,
54
- intlLabel: {
55
- id: `${pluginId}.plugin.name`,
56
- defaultMessage: name
57
- },
58
- Component: async () => {
59
- const component = await import(/* webpackChunkName: "[request]" */ './pages/App');
60
-
61
- return component;
62
- },
63
- permissions: [
64
- // Uncomment to set the permissions of the plugin here
65
- // {
66
- // action: '', // the action name should be plugin::plugin-name.actionType
67
- // subject: null,
68
- // },
69
- ]
70
- });
71
15
  const plugin = {
72
16
  id: pluginId,
73
17
  initializer: Initializer,
@@ -80,11 +24,11 @@ export default {
80
24
 
81
25
  bootstrap(app: any) {
82
26
  app.injectContentManagerComponent('editView', 'right-links', {
83
- name: 'collectionType-picker',
27
+ name: 'collection-type-picker',
84
28
  Component: EditView
85
29
  });
86
30
  app.injectContentManagerComponent('listView', 'actions', {
87
- name: 'collectionType-picker',
31
+ name: 'page-type-filter',
88
32
  Component: PageTypeFilter
89
33
  });
90
34
  },
@@ -0,0 +1,37 @@
1
+ import { getFetchClient } from '@strapi/helper-plugin';
2
+
3
+ import { PAGE_UID } from '../../../shared/utils/constants';
4
+ import getRequestUrl from '../utils/getRequestUrl';
5
+
6
+ const middleware =
7
+ () =>
8
+ ({ getState }: any) =>
9
+ (next: any) =>
10
+ async (action: any) => {
11
+ // If data is being fetched or after a save
12
+ if (
13
+ action.type === 'ContentManager/CrudReducer/GET_DATA_SUCCEEDED' ||
14
+ action.type === 'ContentManager/CrudReducer/SUBMIT_SUCCEEDED'
15
+ ) {
16
+ const store = getState();
17
+ const layoutSlice = store['content-manager_editViewLayoutManager'];
18
+ const uid = layoutSlice.currentLayout.contentType.uid;
19
+
20
+ if (uid !== PAGE_UID) {
21
+ return next(action);
22
+ }
23
+
24
+ const { get } = await getFetchClient();
25
+ const { data: pageData } = await get(`${getRequestUrl('page')}/${action.data.id}`);
26
+
27
+ action.data.collectionTypeTitle = pageData?.collectionTypeData?.title;
28
+ action.data.collectionTypeId = pageData?.collectionTypeData?.id;
29
+ action.data.initialPageType = pageData?.pageType ? pageData.pageType : undefined;
30
+
31
+ return next(action);
32
+ }
33
+ return next(action);
34
+ };
35
+
36
+ const middlewares = [middleware];
37
+ export default middlewares;
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -71,23 +71,32 @@ exports.default = {
71
71
  },
72
72
  getPageContentType(create) {
73
73
  const page = create ? page_start_json_1.default : page_end_json_1.default;
74
- const contentType = this.addModulesToCollectionType(page);
74
+ const contentType = this.mergeCollectionTypeWithModules(page, constants_1.PAGE_UID);
75
75
  return { uid: constants_1.PAGE_UID, contentType };
76
76
  },
77
77
  getPageTypeContentType(create) {
78
78
  const pageType = create ? page_type_start_json_1.default : page_type_end_json_1.default;
79
- const contentType = this.addModulesToCollectionType(pageType);
79
+ const contentType = this.mergeCollectionTypeWithModules(pageType, constants_1.PAGE_TYPE_UID);
80
80
  return { uid: constants_1.PAGE_TYPE_UID, contentType };
81
81
  },
82
82
  getTemplateContentType() {
83
- const contentType = this.addModulesToCollectionType(template_json_1.default);
83
+ const contentType = this.mergeCollectionTypeWithModules(template_json_1.default, constants_1.TEMPLATE_UID);
84
84
  return { uid: constants_1.TEMPLATE_UID, contentType };
85
85
  },
86
- addModulesToCollectionType(collectionType) {
86
+ mergeCollectionTypeWithModules(collectionType, uid) {
87
+ const { pluginOptions: oldPluginOptions, __schema__: { attributes: oldAttributes } } = strapi.contentType(uid) || {};
87
88
  const components = this.getConfigModuleComponents();
88
89
  return {
89
90
  ...collectionType,
90
- attributes: { ...collectionType.attributes, modules: { ...collectionType.attributes.modules, components } }
91
+ pluginOptions: {
92
+ ...oldPluginOptions,
93
+ ...collectionType === null || collectionType === void 0 ? void 0 : collectionType.pluginOptions
94
+ },
95
+ attributes: {
96
+ ...oldAttributes,
97
+ ...collectionType.attributes,
98
+ modules: { ...collectionType.attributes.modules, components }
99
+ }
91
100
  };
92
101
  },
93
102
  getConfigModuleComponents() {
@@ -4,12 +4,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const uniqBy_1 = __importDefault(require("lodash/uniqBy"));
7
+ const constants_1 = require("../../shared/utils/constants");
7
8
  exports.default = {
8
9
  async hasPageRelation(uid) {
9
10
  var _a, _b, _c, _d;
10
11
  const contentType = (_a = strapi.contentTypes) === null || _a === void 0 ? void 0 : _a[uid];
12
+ const pageTypesWithUid = (await strapi.entityService.findMany(constants_1.PAGE_TYPE_UID, {
13
+ filters: {
14
+ uid: {
15
+ $eq: uid
16
+ }
17
+ }
18
+ })) || [];
11
19
  return {
12
- hasPageRelation: Boolean(((_b = contentType === null || contentType === void 0 ? void 0 : contentType.attributes) === null || _b === void 0 ? void 0 : _b.page) && ((_d = (_c = contentType === null || contentType === void 0 ? void 0 : contentType.attributes) === null || _c === void 0 ? void 0 : _c.page) === null || _d === void 0 ? void 0 : _d.morphBy) === 'collectionTypeData')
20
+ hasPageRelation: Boolean(((_b = contentType === null || contentType === void 0 ? void 0 : contentType.attributes) === null || _b === void 0 ? void 0 : _b.page) &&
21
+ ((_d = (_c = contentType === null || contentType === void 0 ? void 0 : contentType.attributes) === null || _c === void 0 ? void 0 : _c.page) === null || _d === void 0 ? void 0 : _d.morphBy) === 'collectionTypeData' &&
22
+ pageTypesWithUid.length > 0)
13
23
  };
14
24
  },
15
25
  async getTranslationPageLinks(uid, ids) {