@lowdefy/server-dev 4.0.0-alpha.7 → 4.0.0-alpha.8

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 (54) hide show
  1. package/package.json +27 -30
  2. package/src/components/App.js +0 -57
  3. package/src/components/Context.js +0 -62
  4. package/src/components/Head.js +0 -28
  5. package/src/components/LowdefyContext.js +0 -50
  6. package/src/components/Page.js +0 -54
  7. package/src/components/Reload.js +0 -43
  8. package/src/components/block/Block.js +0 -57
  9. package/src/components/block/CategorySwitch.js +0 -117
  10. package/src/components/block/Container.js +0 -86
  11. package/src/components/block/List.js +0 -93
  12. package/src/components/block/LoadingBlock.js +0 -22
  13. package/src/components/block/MountEvents.js +0 -46
  14. package/src/components/createComponents.js +0 -29
  15. package/src/components/createLinkComponent.js +0 -97
  16. package/src/manager/getContext.mjs +0 -79
  17. package/src/manager/processes/initialBuild.mjs +0 -27
  18. package/src/manager/processes/installPlugins.mjs +0 -36
  19. package/src/manager/processes/lowdefyBuild.mjs +0 -39
  20. package/src/manager/processes/nextBuild.mjs +0 -31
  21. package/src/manager/processes/readDotEnv.mjs +0 -28
  22. package/src/manager/processes/reloadClients.mjs +0 -26
  23. package/src/manager/processes/restartServer.mjs +0 -27
  24. package/src/manager/processes/shutdownServer.mjs +0 -35
  25. package/src/manager/processes/startNextServer.mjs +0 -45
  26. package/src/manager/processes/startServer.mjs +0 -31
  27. package/src/manager/processes/startWatchers.mjs +0 -31
  28. package/src/manager/run.mjs +0 -92
  29. package/src/manager/utils/BatchChanges.mjs +0 -67
  30. package/src/manager/utils/getLowdefyVersion.mjs +0 -51
  31. package/src/manager/utils/setupWatcher.mjs +0 -49
  32. package/src/manager/utils/spawnProcess.mjs +0 -55
  33. package/src/manager/watchers/envWatcher.mjs +0 -34
  34. package/src/manager/watchers/lowdefyBuildWatcher.mjs +0 -45
  35. package/src/manager/watchers/nextBuildWatcher.mjs +0 -93
  36. package/src/pages/404.js +0 -19
  37. package/src/pages/[pageId].js +0 -19
  38. package/src/pages/_app.js +0 -39
  39. package/src/pages/_document.js +0 -38
  40. package/src/pages/api/auth/[...nextauth].js +0 -28
  41. package/src/pages/api/page/[pageId].js +0 -29
  42. package/src/pages/api/ping.js +0 -19
  43. package/src/pages/api/reload.js +0 -50
  44. package/src/pages/api/request/[pageId]/[requestId].js +0 -45
  45. package/src/pages/api/root.js +0 -25
  46. package/src/pages/index.js +0 -19
  47. package/src/utils/callRequest.js +0 -27
  48. package/src/utils/request.js +0 -36
  49. package/src/utils/setPageId.js +0 -33
  50. package/src/utils/setupLink.js +0 -52
  51. package/src/utils/useMutateCache.js +0 -34
  52. package/src/utils/usePageConfig.js +0 -29
  53. package/src/utils/useRootConfig.js +0 -29
  54. package/src/utils/waitForRestartedServer.js +0 -32
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "4.0.0-alpha.7",
3
+ "version": "4.0.0-alpha.8",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -32,45 +32,42 @@
32
32
  ".eslintrc.yaml"
33
33
  ],
34
34
  "scripts": {
35
- "build:lowdefy": "lowdefy-build",
36
- "build:next": "next build",
37
- "dev": "next dev",
38
- "start": "node src/manager/run.mjs",
35
+ "start": "node manager/run.mjs",
39
36
  "lint": "next lint",
40
37
  "next": "next"
41
38
  },
42
39
  "dependencies": {
43
- "@lowdefy/api": "4.0.0-alpha.7",
44
- "@lowdefy/block-utils": "4.0.0-alpha.7",
45
- "@lowdefy/blocks-antd": "4.0.0-alpha.7",
46
- "@lowdefy/blocks-basic": "4.0.0-alpha.7",
47
- "@lowdefy/blocks-color-selectors": "4.0.0-alpha.7",
48
- "@lowdefy/blocks-echarts": "4.0.0-alpha.7",
49
- "@lowdefy/blocks-loaders": "4.0.0-alpha.7",
50
- "@lowdefy/blocks-markdown": "4.0.0-alpha.7",
51
- "@lowdefy/build": "4.0.0-alpha.7",
52
- "@lowdefy/connection-axios-http": "4.0.0-alpha.7",
53
- "@lowdefy/engine": "4.0.0-alpha.7",
54
- "@lowdefy/helpers": "4.0.0-alpha.7",
55
- "@lowdefy/layout": "4.0.0-alpha.7",
56
- "@lowdefy/node-utils": "4.0.0-alpha.7",
57
- "@lowdefy/operators-change-case": "4.0.0-alpha.7",
58
- "@lowdefy/operators-diff": "4.0.0-alpha.7",
59
- "@lowdefy/operators-js": "4.0.0-alpha.7",
60
- "@lowdefy/operators-mql": "4.0.0-alpha.7",
61
- "@lowdefy/operators-nunjucks": "4.0.0-alpha.7",
62
- "@lowdefy/operators-uuid": "4.0.0-alpha.7",
63
- "@lowdefy/operators-yaml": "4.0.0-alpha.7",
40
+ "@lowdefy/api": "4.0.0-alpha.8",
41
+ "@lowdefy/block-utils": "4.0.0-alpha.8",
42
+ "@lowdefy/blocks-antd": "4.0.0-alpha.8",
43
+ "@lowdefy/blocks-basic": "4.0.0-alpha.8",
44
+ "@lowdefy/blocks-color-selectors": "4.0.0-alpha.8",
45
+ "@lowdefy/blocks-echarts": "4.0.0-alpha.8",
46
+ "@lowdefy/blocks-loaders": "4.0.0-alpha.8",
47
+ "@lowdefy/blocks-markdown": "4.0.0-alpha.8",
48
+ "@lowdefy/build": "4.0.0-alpha.8",
49
+ "@lowdefy/connection-axios-http": "4.0.0-alpha.8",
50
+ "@lowdefy/engine": "4.0.0-alpha.8",
51
+ "@lowdefy/helpers": "4.0.0-alpha.8",
52
+ "@lowdefy/layout": "4.0.0-alpha.8",
53
+ "@lowdefy/node-utils": "4.0.0-alpha.8",
54
+ "@lowdefy/operators-change-case": "4.0.0-alpha.8",
55
+ "@lowdefy/operators-diff": "4.0.0-alpha.8",
56
+ "@lowdefy/operators-js": "4.0.0-alpha.8",
57
+ "@lowdefy/operators-mql": "4.0.0-alpha.8",
58
+ "@lowdefy/operators-nunjucks": "4.0.0-alpha.8",
59
+ "@lowdefy/operators-uuid": "4.0.0-alpha.8",
60
+ "@lowdefy/operators-yaml": "4.0.0-alpha.8",
64
61
  "chokidar": "3.5.3",
65
62
  "dotenv": "15.0.0",
66
- "js-yaml": "4.1.0",
67
63
  "next": "12.0.10",
68
64
  "next-auth": "4.1.2",
69
65
  "opener": "1.5.2",
70
- "react": "18.0.0-rc.0",
71
- "react-dom": "18.0.0-rc.0",
66
+ "react": "17.0.2",
67
+ "react-dom": "17.0.2",
72
68
  "react-icons": "4.3.1",
73
69
  "swr": "1.1.2",
70
+ "yaml": "2.0.0-10",
74
71
  "yargs": "17.3.1"
75
72
  },
76
73
  "devDependencies": {
@@ -82,5 +79,5 @@
82
79
  "publishConfig": {
83
80
  "access": "public"
84
81
  },
85
- "gitHead": "52ec14639d00de910cf9b8ab25bf933ca891cff5"
82
+ "gitHead": "9d56b83cf45e868afe3a1eeba750fe826eb74c8c"
86
83
  }
@@ -1,57 +0,0 @@
1
- /*
2
- Copyright 2020-2021 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import React from 'react';
18
-
19
- import { urlQuery } from '@lowdefy/helpers';
20
- import { useRouter } from 'next/router';
21
-
22
- import Page from './Page.js';
23
- import Reload from './Reload.js';
24
- import setPageId from '../utils/setPageId.js';
25
- import setupLink from '../utils/setupLink.js';
26
- import useRootConfig from '../utils/useRootConfig.js';
27
- import createComponents from './createComponents.js';
28
-
29
- const App = ({ lowdefy }) => {
30
- const router = useRouter();
31
- const { data: rootConfig } = useRootConfig(router.basePath);
32
-
33
- window.lowdefy = lowdefy;
34
-
35
- lowdefy._internal.router = router;
36
- lowdefy._internal.link = setupLink(lowdefy);
37
- lowdefy._internal.components = createComponents(lowdefy);
38
-
39
- lowdefy.basePath = lowdefy._internal.router.basePath;
40
- lowdefy.home = rootConfig.home;
41
- lowdefy.lowdefyGlobal = rootConfig.lowdefyGlobal;
42
- lowdefy.menus = rootConfig.menus;
43
- lowdefy.urlQuery = urlQuery.parse(window.location.search.slice(1));
44
-
45
- const redirect = setPageId(lowdefy);
46
- if (redirect) {
47
- lowdefy._internal.router.push(`/${lowdefy.pageId}`);
48
- }
49
-
50
- return (
51
- <Reload lowdefy={lowdefy}>
52
- <Page lowdefy={lowdefy} />
53
- </Reload>
54
- );
55
- };
56
-
57
- export default App;
@@ -1,62 +0,0 @@
1
- /*
2
- Copyright 2020-2021 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import React, { useEffect, useState } from 'react';
18
- import getContext from '@lowdefy/engine';
19
-
20
- import MountEvents from './block/MountEvents.js';
21
-
22
- const Context = ({ children, lowdefy, config }) => {
23
- const [context, setContext] = useState({});
24
-
25
- useEffect(() => {
26
- let mounted = true;
27
- const mount = async () => {
28
- const ctx = await getContext({
29
- config,
30
- lowdefy,
31
- development: true,
32
- });
33
- if (mounted) {
34
- setContext(ctx);
35
- }
36
- };
37
- mount();
38
- return () => {
39
- mounted = false;
40
- };
41
- }, [config, lowdefy]);
42
- const loadingPage = context.id !== config.id;
43
-
44
- if (loadingPage) {
45
- return children(context, loadingPage, 'pager');
46
- }
47
-
48
- return (
49
- <MountEvents
50
- asyncEventName="onEnterAsync"
51
- context={context}
52
- eventName="onEnter"
53
- triggerEvent={({ name, context }) =>
54
- context._internal.RootBlocks.areas.root.blocks[0].triggerEvent({ name })
55
- }
56
- >
57
- {(loading) => children(context, loading, 'mounter')}
58
- </MountEvents>
59
- );
60
- };
61
-
62
- export default Context;
@@ -1,28 +0,0 @@
1
- /*
2
- Copyright 2020-2021 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import React from 'react';
18
- import Head from 'next/head';
19
-
20
- const BindHead = ({ properties }) => {
21
- return (
22
- <Head>
23
- <title>{properties.title}</title>
24
- </Head>
25
- );
26
- };
27
-
28
- export default BindHead;
@@ -1,50 +0,0 @@
1
- /*
2
- Copyright 2020-2021 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import React from 'react';
18
-
19
- import actions from '../../build/plugins/actions.js';
20
- import callRequest from '../utils/callRequest.js';
21
- import blockComponents from '../../build/plugins/blocks.js';
22
- import operators from '../../build/plugins/operatorsClient.js';
23
-
24
- const LowdefyContext = ({ children, lowdefy }) => {
25
- if (!lowdefy._internal) {
26
- lowdefy._internal = {
27
- actions,
28
- blockComponents,
29
- callRequest,
30
- components: {},
31
- document,
32
- operators,
33
- updaters: {},
34
- window,
35
- displayMessage: ({ content }) => {
36
- console.log(content);
37
- return () => undefined;
38
- },
39
- link: () => undefined,
40
- };
41
- lowdefy.contexts = {};
42
- lowdefy.inputs = {};
43
- lowdefy.lowdefyGlobal = {};
44
- }
45
- lowdefy._internal.updateBlock = (blockId) =>
46
- lowdefy._internal.updaters[blockId] && lowdefy._internal.updaters[blockId]();
47
- return <>{children}</>;
48
- };
49
-
50
- export default LowdefyContext;
@@ -1,54 +0,0 @@
1
- /*
2
- Copyright 2020-2021 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import React from 'react';
18
-
19
- import Block from './block/Block.js';
20
- import Context from './Context.js';
21
- import Head from './Head.js';
22
- import usePageConfig from '../utils/usePageConfig.js';
23
-
24
- const LoadingBlock = () => <div>Loading...</div>;
25
-
26
- const Page = ({ lowdefy }) => {
27
- const { data: pageConfig } = usePageConfig(lowdefy.pageId, lowdefy.basePath);
28
- if (!pageConfig) {
29
- lowdefy._internal.router.replace(`/404`);
30
- return <LoadingBlock />;
31
- }
32
- return (
33
- <Context config={pageConfig} lowdefy={lowdefy}>
34
- {(context, loading) => {
35
- if (loading) {
36
- return <LoadingBlock />;
37
- }
38
- return (
39
- <>
40
- <Head properties={context._internal.RootBlocks.map[pageConfig.id].eval.properties} />
41
- <Block
42
- block={context._internal.RootBlocks.map[pageConfig.id]}
43
- Blocks={context._internal.RootBlocks}
44
- context={context}
45
- lowdefy={lowdefy}
46
- />
47
- </>
48
- );
49
- }}
50
- </Context>
51
- );
52
- };
53
-
54
- export default Page;
@@ -1,43 +0,0 @@
1
- /*
2
- Copyright 2020-2021 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import React, { useEffect } from 'react';
18
-
19
- import useMutateCache from '../utils/useMutateCache.js';
20
- import waitForRestartedServer from '../utils/waitForRestartedServer.js';
21
-
22
- const Reload = ({ children, lowdefy }) => {
23
- const mutateCache = useMutateCache(lowdefy.basePath);
24
- useEffect(() => {
25
- const sse = new EventSource(`${lowdefy.basePath}/api/reload`);
26
-
27
- sse.addEventListener('reload', () => {
28
- mutateCache();
29
- console.log('Reloaded config.');
30
- });
31
-
32
- sse.onerror = () => {
33
- sse.close();
34
- waitForRestartedServer(lowdefy);
35
- };
36
- return () => {
37
- sse.close();
38
- };
39
- }, []);
40
- return <>{children}</>;
41
- };
42
-
43
- export default Reload;
@@ -1,57 +0,0 @@
1
- /*
2
- Copyright 2020-2021 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import React, { Suspense, useState } from 'react';
18
-
19
- import { ErrorBoundary } from '@lowdefy/block-utils';
20
-
21
- import CategorySwitch from './CategorySwitch.js';
22
- import LoadingBlock from './LoadingBlock.js';
23
- import MountEvents from './MountEvents.js';
24
-
25
- const Block = ({ block, Blocks, context, isRoot, lowdefy }) => {
26
- const [updates, setUpdate] = useState(0);
27
- lowdefy._internal.updaters[block.id] = () => setUpdate(updates + 1);
28
- return (
29
- <ErrorBoundary>
30
- <Suspense fallback={<LoadingBlock block={block} lowdefy={lowdefy} />}>
31
- <MountEvents
32
- asyncEventName="onMountAsync"
33
- context={context}
34
- eventName="onMount"
35
- triggerEvent={block.triggerEvent}
36
- >
37
- {(loading) =>
38
- loading ? (
39
- <LoadingBlock block={block} lowdefy={lowdefy} />
40
- ) : (
41
- <CategorySwitch
42
- block={block}
43
- Blocks={Blocks}
44
- context={context}
45
- isRoot={isRoot}
46
- lowdefy={lowdefy}
47
- updates={updates}
48
- />
49
- )
50
- }
51
- </MountEvents>
52
- </Suspense>
53
- </ErrorBoundary>
54
- );
55
- };
56
-
57
- export default Block;
@@ -1,117 +0,0 @@
1
- /*
2
- Copyright 2020-2021 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import React from 'react';
18
- import { BlockLayout } from '@lowdefy/layout';
19
- import { makeCssClass } from '@lowdefy/block-utils';
20
-
21
- import Container from './Container.js';
22
- import List from './List.js';
23
-
24
- const CategorySwitch = ({ block, Blocks, context, lowdefy }) => {
25
- if (!block.eval) return null; // Renderer updates before eval is executed for the first time on lists. See #520
26
- if (block.eval.visible === false)
27
- return <div id={`vs-${block.blockId}`} style={{ display: 'none' }} />;
28
- const Component = lowdefy._internal.blockComponents[block.type];
29
- switch (Component.meta.category) {
30
- case 'list':
31
- return (
32
- <List
33
- block={block}
34
- Blocks={Blocks}
35
- Component={Component}
36
- context={context}
37
- lowdefy={lowdefy}
38
- />
39
- );
40
- case 'container':
41
- return (
42
- <Container
43
- block={block}
44
- Blocks={Blocks}
45
- Component={Component}
46
- context={context}
47
- lowdefy={lowdefy}
48
- />
49
- );
50
- case 'input':
51
- return (
52
- <BlockLayout
53
- id={`bl-${block.blockId}`}
54
- blockStyle={block.eval.style}
55
- highlightBorders={lowdefy.lowdefyGlobal.highlightBorders}
56
- layout={block.eval.layout || {}}
57
- makeCssClass={makeCssClass}
58
- >
59
- <Component
60
- methods={Object.assign(block.methods, {
61
- makeCssClass,
62
- registerEvent: block.registerEvent,
63
- registerMethod: block.registerMethod,
64
- setValue: block.setValue,
65
- triggerEvent: block.triggerEvent,
66
- })}
67
- basePath={lowdefy.basePath}
68
- blockId={block.blockId}
69
- components={lowdefy._internal.components}
70
- events={block.eval.events}
71
- key={block.blockId}
72
- loading={block.loading}
73
- menus={lowdefy.menus}
74
- pageId={lowdefy.pageId}
75
- properties={block.eval.properties}
76
- required={block.eval.required}
77
- user={lowdefy.user}
78
- validation={block.eval.validation}
79
- value={block.value}
80
- />
81
- </BlockLayout>
82
- );
83
- default:
84
- return (
85
- <BlockLayout
86
- id={`bl-${block.blockId}`}
87
- blockStyle={block.eval.style}
88
- highlightBorders={lowdefy.lowdefyGlobal.highlightBorders}
89
- layout={block.eval.layout || {}}
90
- makeCssClass={makeCssClass}
91
- >
92
- <Component
93
- methods={Object.assign(block.methods, {
94
- makeCssClass,
95
- registerEvent: block.registerEvent,
96
- registerMethod: block.registerMethod,
97
- triggerEvent: block.triggerEvent,
98
- })}
99
- basePath={lowdefy.basePath}
100
- blockId={block.blockId}
101
- components={lowdefy._internal.components}
102
- events={block.eval.events}
103
- key={block.blockId}
104
- loading={block.loading}
105
- menus={lowdefy.menus}
106
- pageId={lowdefy.pageId}
107
- properties={block.eval.properties}
108
- required={block.eval.required}
109
- user={lowdefy.user}
110
- validation={block.eval.validation}
111
- />
112
- </BlockLayout>
113
- );
114
- }
115
- };
116
-
117
- export default CategorySwitch;
@@ -1,86 +0,0 @@
1
- /*
2
- Copyright 2020-2021 Lowdefy, Inc
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import React from 'react';
18
- import { Area, BlockLayout, layoutParamsToArea } from '@lowdefy/layout';
19
- import { makeCssClass } from '@lowdefy/block-utils';
20
-
21
- import Block from './Block.js';
22
-
23
- const Container = ({ block, Blocks, Component, context, lowdefy }) => {
24
- const content = {};
25
- // eslint-disable-next-line prefer-destructuring
26
- const areas = Blocks.subBlocks[block.id][0].areas;
27
- Object.keys(areas).forEach((areaKey) => {
28
- content[areaKey] = (areaStyle) => (
29
- <Area
30
- id={`ar-${block.blockId}-${areaKey}`}
31
- key={`ar-${block.blockId}-${areaKey}`}
32
- area={layoutParamsToArea({
33
- area: block.eval.areas[areaKey] || {},
34
- areaKey,
35
- layout: block.eval.layout || {},
36
- })}
37
- areaStyle={[areaStyle, block.eval.areas[areaKey] && block.eval.areas[areaKey].style]}
38
- highlightBorders={lowdefy.lowdefyGlobal.highlightBorders}
39
- makeCssClass={makeCssClass}
40
- >
41
- {areas[areaKey].blocks.map((bl) => (
42
- <Block
43
- key={`co-${bl.blockId}`}
44
- Blocks={Blocks.subBlocks[block.id][0]}
45
- block={bl}
46
- context={context}
47
- lowdefy={lowdefy}
48
- />
49
- ))}
50
- </Area>
51
- );
52
- });
53
- return (
54
- <BlockLayout
55
- id={`bl-${block.blockId}`}
56
- blockStyle={block.eval.style}
57
- highlightBorders={lowdefy.lowdefyGlobal.highlightBorders}
58
- layout={block.eval.layout || {}}
59
- makeCssClass={makeCssClass}
60
- >
61
- <Component
62
- methods={Object.assign(block.methods, {
63
- makeCssClass,
64
- registerEvent: block.registerEvent,
65
- registerMethod: block.registerMethod,
66
- triggerEvent: block.triggerEvent,
67
- })}
68
- basePath={lowdefy.basePath}
69
- blockId={block.blockId}
70
- components={lowdefy._internal.components}
71
- content={content}
72
- events={block.eval.events}
73
- key={block.blockId}
74
- loading={block.loading}
75
- menus={lowdefy.menus}
76
- pageId={lowdefy.pageId}
77
- properties={block.eval.properties}
78
- required={block.eval.required}
79
- user={lowdefy.user}
80
- validation={block.eval.validation}
81
- />
82
- </BlockLayout>
83
- );
84
- };
85
-
86
- export default Container;