@lowdefy/server 4.0.0-alpha.1 → 4.0.0-alpha.10

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 (39) hide show
  1. package/.eslintrc.yaml +1 -0
  2. package/README.md +17 -1
  3. package/lib/Page.js +50 -0
  4. package/lowdefy/build.mjs +51 -0
  5. package/lowdefy/createCustomPluginTypesMap.mjs +66 -0
  6. package/next.config.js +36 -0
  7. package/package.json +29 -20
  8. package/{src/utils/request.js → pages/404.js} +20 -17
  9. package/{src/pages → pages}/[pageId].js +4 -5
  10. package/{src/components/Head.js → pages/_app.js} +13 -10
  11. package/pages/_document.js +38 -0
  12. package/{src/pages → pages}/api/auth/[...nextauth].js +1 -1
  13. package/{src/pages → pages}/api/request/[pageId]/[requestId].js +9 -6
  14. package/{src/pages → pages}/index.js +8 -12
  15. package/{src/public → public}/apple-touch-icon.png +0 -0
  16. package/public/favicon.ico +0 -0
  17. package/{src/public → public}/icon-512.png +0 -0
  18. package/{src/public → public}/icon.svg +0 -0
  19. package/{src/public → public}/logo-dark-theme.png +0 -0
  20. package/{src/public → public}/logo-light-theme.png +0 -0
  21. package/{src/public → public}/logo-square-dark-theme.png +0 -0
  22. package/{src/public → public}/logo-square-light-theme.png +0 -0
  23. package/{src/public → public}/manifest.webmanifest +0 -0
  24. package/src/components/Context.js +0 -61
  25. package/src/components/LowdefyContext.js +0 -47
  26. package/src/components/Page.js +0 -60
  27. package/src/components/block/Block.js +0 -57
  28. package/src/components/block/CategorySwitch.js +0 -120
  29. package/src/components/block/Container.js +0 -87
  30. package/src/components/block/List.js +0 -94
  31. package/src/components/block/LoadingBlock.js +0 -22
  32. package/src/components/block/MountEvents.js +0 -46
  33. package/src/components/components.js +0 -25
  34. package/src/pages/_app.js +0 -37
  35. package/src/plugins/icons.js +0 -35
  36. package/src/plugins/style.less +0 -3
  37. package/src/public/icon-32.png +0 -0
  38. package/src/utils/callRequest.js +0 -27
  39. package/src/utils/setupLink.js +0 -44
package/.eslintrc.yaml ADDED
@@ -0,0 +1 @@
1
+ extends: 'plugin:@next/next/core-web-vitals'
package/README.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @lowdefy/server
2
2
 
3
+ ## Development
4
+
5
+ To run the server in locally as a development server, run the following:
6
+
7
+ - Run `yarn && yarn build` at the root of the repository.
8
+ - Add a `lowdefy.yaml` file in the server directory (`packages/server`).
9
+ - run `yarn dev` in the server directory.
10
+
11
+ To run the server in locally as a development server, with a next production build, run the following:
12
+
13
+ - Run `yarn && yarn build` at the root of the repository.
14
+ - Add a `lowdefy.yaml` file in the server directory (`packages/server`).
15
+ - run `yarn dev:prod` in the server directory.
16
+
17
+ > When running a development server, the `package.json` file is updated with the plugins used in the Lowdefy app. Please do not commit the changes made to the `package.json`, `.pnp.cjs` and `yarn.lock` files.
18
+
3
19
  ## Licence
4
20
 
5
- [Apache-2.0](https://github.com/lowdefy/lowdefy/blob/main/LICENSE)
21
+ [Apache-2.0](https://github.com/lowdefy/lowdefy/blob/main/LICENSE)
package/lib/Page.js ADDED
@@ -0,0 +1,50 @@
1
+ /*
2
+ Copyright 2020-2022 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 { useRouter } from 'next/router';
20
+ import Client from '@lowdefy/client';
21
+ import Head from 'next/head';
22
+ import Link from 'next/link';
23
+
24
+ import actions from '../build/plugins/actions.js';
25
+ import blocks from '../build/plugins/blocks.js';
26
+ import icons from '../build/plugins/icons.js';
27
+ import operators from '../build/plugins/operatorsClient.js';
28
+
29
+ const Page = ({ pageConfig, rootConfig }) => {
30
+ const router = useRouter();
31
+ return (
32
+ <Client
33
+ Components={{ Head, Link }}
34
+ config={{
35
+ pageConfig,
36
+ rootConfig,
37
+ }}
38
+ router={router}
39
+ types={{
40
+ actions,
41
+ blocks,
42
+ icons,
43
+ operators,
44
+ }}
45
+ window={window}
46
+ />
47
+ );
48
+ };
49
+
50
+ export default Page;
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ Copyright 2020-2022 Lowdefy, Inc
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ */
17
+
18
+ import path from 'path';
19
+ import yargs from 'yargs';
20
+ import { hideBin } from 'yargs/helpers';
21
+
22
+ import build from '@lowdefy/build';
23
+ import createCustomPluginTypesMap from './createCustomPluginTypesMap.mjs';
24
+
25
+ const argv = yargs(hideBin(process.argv)).argv;
26
+
27
+ async function run() {
28
+ const directories = {
29
+ build: path.resolve(
30
+ argv.buildDirectory ||
31
+ process.env.LOWDEFY_DIRECTORY_BUILD ||
32
+ path.join(process.cwd(), 'build')
33
+ ),
34
+ config: path.resolve(
35
+ argv.configDirectory || process.env.LOWDEFY_DIRECTORY_CONFIG || process.cwd()
36
+ ),
37
+ server: path.resolve(
38
+ argv.serverDirectory || process.env.LOWDEFY_DIRECTORY_SERVER || process.cwd()
39
+ ),
40
+ };
41
+
42
+ const customTypesMap = await createCustomPluginTypesMap({ directories });
43
+ await build({
44
+ customTypesMap,
45
+ directories,
46
+ logger: console,
47
+ refResolver: argv.refResolver || process.env.LOWDEFY_BUILD_REF_RESOLVER,
48
+ });
49
+ }
50
+
51
+ run();
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ Copyright 2020-2022 Lowdefy, Inc
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ */
17
+
18
+ import path from 'path';
19
+ import { get } from '@lowdefy/helpers';
20
+ import { readFile } from '@lowdefy/node-utils';
21
+ import { createPluginTypesMap } from '@lowdefy/build';
22
+ import YAML from 'yaml';
23
+
24
+ async function getPluginDefinitions({ directories }) {
25
+ let lowdefyYaml = await readFile(path.join(directories.config, 'lowdefy.yaml'));
26
+ if (!lowdefyYaml) {
27
+ lowdefyYaml = await readFile(path.join(directories.config, 'lowdefy.yml'));
28
+ }
29
+ const lowdefy = YAML.parse(lowdefyYaml);
30
+ return get(lowdefy, 'plugins', { default: [] });
31
+ }
32
+
33
+ async function createCustomPluginTypesMap({ directories }) {
34
+ const customTypesMap = {
35
+ actions: {},
36
+ blocks: {},
37
+ connections: {},
38
+ icons: {},
39
+ operators: {
40
+ client: {},
41
+ server: {},
42
+ },
43
+ requests: {},
44
+ styles: {
45
+ packages: {},
46
+ blocks: {},
47
+ },
48
+ };
49
+
50
+ const pluginDefinitions = await getPluginDefinitions({ directories });
51
+
52
+ for (const plugin of pluginDefinitions) {
53
+ const { default: types } = await import(`${plugin.name}/types`);
54
+ createPluginTypesMap({
55
+ packageTypes: types,
56
+ typesMap: customTypesMap,
57
+ packageName: plugin.name,
58
+ version: plugin.version,
59
+ typePrefix: plugin.typePrefix,
60
+ });
61
+ }
62
+
63
+ return customTypesMap;
64
+ }
65
+
66
+ export default createCustomPluginTypesMap;
package/next.config.js ADDED
@@ -0,0 +1,36 @@
1
+ const withLess = require('next-with-less');
2
+ const lowdefyConfig = require('./build/config.json');
3
+
4
+ // TODO: Trace env and args from cli that is required on the server.
5
+ module.exports = withLess({
6
+ basePath: process.env.LOWDEFY_BASE_PATH || lowdefyConfig.basePath,
7
+ lessLoaderOptions: {
8
+ lessOptions: {
9
+ modifyVars: lowdefyConfig.theme.lessVariables,
10
+ },
11
+ },
12
+ reactStrictMode: true,
13
+ webpack: (config, { isServer }) => {
14
+ if (!isServer) {
15
+ config.resolve.fallback = {
16
+ assert: false,
17
+ buffer: false,
18
+ crypto: false,
19
+ events: false,
20
+ fs: false,
21
+ path: false,
22
+ process: require.resolve('process/browser'),
23
+ util: false,
24
+ };
25
+ }
26
+ return config;
27
+ },
28
+ poweredByHeader: false,
29
+ // productionBrowserSourceMaps: true
30
+ // experimental: {
31
+ // concurrentFeatures: true,
32
+ // },
33
+ eslint: {
34
+ ignoreDuringBuilds: true,
35
+ },
36
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.10",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -26,11 +26,15 @@
26
26
  "url": "https://github.com/lowdefy/lowdefy.git"
27
27
  },
28
28
  "files": [
29
- "src/*"
29
+ "lib/*",
30
+ "lowdefy/*",
31
+ "pages/*",
32
+ "public/*",
33
+ "next.config.js",
34
+ ".eslintrc.yaml"
30
35
  ],
31
36
  "scripts": {
32
- "build": "yarn build:lowdefy && yarn build:next",
33
- "build:lowdefy": "lowdefy-build",
37
+ "build:lowdefy": "node lowdefy/build.mjs",
34
38
  "build:next": "next build",
35
39
  "dev": "next dev",
36
40
  "start": "next start",
@@ -38,29 +42,34 @@
38
42
  "next": "next"
39
43
  },
40
44
  "dependencies": {
41
- "@lowdefy/api": "4.0.0-alpha.1",
42
- "@lowdefy/block-utils": "4.0.0-alpha.1",
43
- "@lowdefy/blocks-antd": "4.0.0-alpha.1",
44
- "@lowdefy/blocks-basic": "4.0.0-alpha.1",
45
- "@lowdefy/connection-axios-http": "4.0.0-alpha.1",
46
- "@lowdefy/engine": "4.0.0-alpha.1",
47
- "@lowdefy/helpers": "4.0.0-alpha.1",
48
- "@lowdefy/layout": "4.0.0-alpha.1",
49
- "next": "12.0.3",
50
- "next-auth": "4.0.0-beta.6",
51
- "react": "18.0.0-alpha-327d5c484-20211106",
52
- "react-dom": "18.0.0-alpha-327d5c484-20211106",
45
+ "@lowdefy/actions-core": "4.0.0-alpha.10",
46
+ "@lowdefy/api": "4.0.0-alpha.10",
47
+ "@lowdefy/blocks-antd": "4.0.0-alpha.10",
48
+ "@lowdefy/blocks-basic": "4.0.0-alpha.10",
49
+ "@lowdefy/blocks-loaders": "4.0.0-alpha.10",
50
+ "@lowdefy/client": "4.0.0-alpha.10",
51
+ "@lowdefy/helpers": "4.0.0-alpha.10",
52
+ "@lowdefy/layout": "4.0.0-alpha.10",
53
+ "@lowdefy/node-utils": "4.0.0-alpha.10",
54
+ "@lowdefy/operators-js": "4.0.0-alpha.10",
55
+ "next": "12.0.10",
56
+ "next-auth": "4.1.2",
57
+ "process": "0.11.10",
58
+ "react": "17.0.2",
59
+ "react-dom": "17.0.2",
53
60
  "react-icons": "4.3.1"
54
61
  },
55
62
  "devDependencies": {
56
- "@lowdefy/build": "4.0.0-alpha.1",
57
- "@next/eslint-plugin-next": "12.0.4",
63
+ "@lowdefy/build": "4.0.0-alpha.10",
64
+ "@next/eslint-plugin-next": "12.0.10",
58
65
  "less": "4.1.2",
59
66
  "less-loader": "10.2.0",
60
- "next-with-less": "2.0.2"
67
+ "next-with-less": "2.0.4",
68
+ "yaml": "1.10.2",
69
+ "yargs": "17.3.1"
61
70
  },
62
71
  "publishConfig": {
63
72
  "access": "public"
64
73
  },
65
- "gitHead": "c97a8fa6b5a641e7d50df09f5601a9c586eeb65a"
74
+ "gitHead": "d697b4b5f354697d9481a371b90a00ca0944f486"
66
75
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -14,22 +14,25 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- async function request({ url, method = 'GET', body }) {
18
- const res = await fetch(url, {
19
- method,
20
- headers: {
21
- 'Content-Type': 'application/json',
17
+ import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
+
19
+ import Page from '../lib/Page.js';
20
+
21
+ export async function getStaticProps() {
22
+ // TODO: get the right api context options
23
+ const apiContext = await createApiContext({ buildDirectory: './build' });
24
+
25
+ const [rootConfig, pageConfig] = await Promise.all([
26
+ getRootConfig(apiContext),
27
+ getPageConfig(apiContext, { pageId: '404' }),
28
+ ]);
29
+
30
+ return {
31
+ props: {
32
+ pageConfig,
33
+ rootConfig,
22
34
  },
23
- body: JSON.stringify(body),
24
- });
25
- if (!res.ok) {
26
- // TODO: check
27
- const body = await res.json();
28
- console.log(res);
29
- console.log(body);
30
- throw new Error(body.message || 'Request error');
31
- }
32
- return res.json();
35
+ };
33
36
  }
34
37
 
35
- export default request;
38
+ export default Page;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -16,14 +16,13 @@
16
16
 
17
17
  import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
18
 
19
- import Page from '../components/Page.js';
19
+ import Page from '../lib/Page.js';
20
20
 
21
21
  export async function getServerSideProps(context) {
22
22
  const { pageId } = context.params;
23
- const apiContext = await createApiContext({ buildDirectory: './.lowdefy/build' });
23
+ // TODO: get the right api context options
24
+ const apiContext = await createApiContext({ buildDirectory: './build' });
24
25
 
25
- // TODO: Maybe we can only get rootConfig once?
26
- // We can't do getServerSideProps on _app :(
27
26
  const [rootConfig, pageConfig] = await Promise.all([
28
27
  getRootConfig(apiContext),
29
28
  getPageConfig(apiContext, { pageId }),
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -15,14 +15,17 @@
15
15
  */
16
16
 
17
17
  import React from 'react';
18
- import Head from 'next/head';
18
+ import dynamic from 'next/dynamic';
19
19
 
20
- const BindHead = ({ properties }) => {
21
- return (
22
- <Head>
23
- <title>{properties.title}</title>
24
- </Head>
25
- );
26
- };
20
+ // Must be in _app due to next specifications.
21
+ import '../build/plugins/styles.less';
27
22
 
28
- export default BindHead;
23
+ function App({ Component, pageProps }) {
24
+ return <Component {...pageProps} />;
25
+ }
26
+
27
+ const DynamicApp = dynamic(() => Promise.resolve(App), {
28
+ ssr: false,
29
+ });
30
+
31
+ export default DynamicApp;
@@ -0,0 +1,38 @@
1
+ /*
2
+ Copyright 2020-2022 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 Document, { Html, Head, Main, NextScript } from 'next/document';
19
+
20
+ class LowdefyDocument extends Document {
21
+ render() {
22
+ return (
23
+ <Html>
24
+ <Head>
25
+ <link rel="manifest" href="/manifest.webmanifest" />
26
+ <link rel="icon" type="image/svg+xml" href="/icon.svg" />
27
+ <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
28
+ </Head>
29
+ <body>
30
+ <Main />
31
+ <NextScript />
32
+ </body>
33
+ </Html>
34
+ );
35
+ }
36
+ }
37
+
38
+ export default LowdefyDocument;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -15,20 +15,23 @@
15
15
  */
16
16
 
17
17
  import { callRequest, createApiContext } from '@lowdefy/api';
18
- import connections from '../../../../../.lowdefy/build/plugins/connections.js';
18
+ import { getSecretsFromEnv } from '@lowdefy/node-utils';
19
+ import connections from '../../../../build/plugins/connections.js';
20
+ import operators from '../../../../build/plugins/operatorsServer.js';
19
21
 
20
22
  export default async function handler(req, res) {
21
23
  try {
22
24
  if (req.method !== 'POST') {
23
25
  throw new Error('Only POST requests are supported.');
24
26
  }
27
+ // TODO: configure API context
25
28
  const apiContext = await createApiContext({
26
- buildDirectory: './.lowdefy/build',
29
+ buildDirectory: './build',
27
30
  connections,
28
- // TODO
31
+ // TODO: use a logger like pino
29
32
  logger: console,
30
- // TODO
31
- secrets: {},
33
+ operators,
34
+ secrets: getSecretsFromEnv(),
32
35
  });
33
36
  const { pageId, requestId } = req.query;
34
37
  const { payload } = req.body;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2021 Lowdefy, Inc
2
+ Copyright 2020-2022 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -14,13 +14,15 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import { createApiContext, getHome, getPageConfig, getRootConfig } from '@lowdefy/api';
17
+ import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
18
 
19
- import Page from '../components/Page.js';
19
+ import Page from '../lib/Page.js';
20
20
 
21
21
  export async function getServerSideProps() {
22
- const apiContext = await createApiContext({ buildDirectory: './.lowdefy/build' });
23
- const home = await getHome(apiContext);
22
+ // TODO: is this build directory configurable from the cli?
23
+ const apiContext = await createApiContext({ buildDirectory: './build' });
24
+ const rootConfig = await getRootConfig(apiContext);
25
+ const { home } = rootConfig;
24
26
  if (home.configured === false) {
25
27
  return {
26
28
  redirect: {
@@ -29,12 +31,7 @@ export async function getServerSideProps() {
29
31
  },
30
32
  };
31
33
  }
32
-
33
- const [rootConfig, pageConfig] = await Promise.all([
34
- getRootConfig(apiContext),
35
- getPageConfig(apiContext, { pageId: home.pageId }),
36
- ]);
37
-
34
+ const pageConfig = await getPageConfig(apiContext, { pageId: home.pageId });
38
35
  if (!pageConfig) {
39
36
  return {
40
37
  redirect: {
@@ -43,7 +40,6 @@ export async function getServerSideProps() {
43
40
  },
44
41
  };
45
42
  }
46
-
47
43
  return {
48
44
  props: {
49
45
  pageConfig,
File without changes
Binary file
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,61 +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
- });
32
- if (mounted) {
33
- setContext(ctx);
34
- }
35
- };
36
- mount();
37
- return () => {
38
- mounted = false;
39
- };
40
- }, [config, lowdefy]);
41
- const loadingPage = context.id !== config.id;
42
-
43
- if (loadingPage) {
44
- return children(context, loadingPage, 'pager');
45
- }
46
-
47
- return (
48
- <MountEvents
49
- asyncEventName="onEnterAsync"
50
- context={context}
51
- eventName="onEnter"
52
- triggerEvent={({ name, context }) =>
53
- context._internal.RootBlocks.areas.root.blocks[0].triggerEvent({ name })
54
- }
55
- >
56
- {(loading) => children(context, loading, 'mounter')}
57
- </MountEvents>
58
- );
59
- };
60
-
61
- export default Context;