@lowdefy/server-dev 3.23.0-alpha.0 → 4.0.0-alpha.6
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/.eslintrc.yaml +1 -0
- package/README.md +0 -24
- package/next.config.js +34 -0
- package/package.json +46 -34
- package/public/apple-touch-icon.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/icon-512.png +0 -0
- package/public/icon.svg +17 -0
- package/public/logo-dark-theme.png +0 -0
- package/public/logo-light-theme.png +0 -0
- package/public/logo-square-dark-theme.png +0 -0
- package/public/logo-square-light-theme.png +0 -0
- package/public/manifest.webmanifest +16 -0
- package/src/components/App.js +55 -0
- package/src/components/Context.js +62 -0
- package/src/components/Head.js +28 -0
- package/src/components/LowdefyContext.js +50 -0
- package/src/components/Page.js +54 -0
- package/src/components/Reload.js +43 -0
- package/src/components/block/Block.js +57 -0
- package/src/components/block/CategorySwitch.js +120 -0
- package/src/components/block/Container.js +87 -0
- package/src/components/block/List.js +94 -0
- package/src/components/block/LoadingBlock.js +22 -0
- package/src/components/block/MountEvents.js +46 -0
- package/src/components/components.js +25 -0
- package/src/manager/BatchChanges.mjs +66 -0
- package/src/manager/getContext.mjs +64 -0
- package/src/manager/initialBuild.mjs +24 -0
- package/src/manager/processes/installPlugins.mjs +36 -0
- package/src/manager/processes/lowdefyBuild.mjs +38 -0
- package/src/manager/processes/nextBuild.mjs +31 -0
- package/src/manager/processes/reloadClients.mjs +26 -0
- package/src/manager/processes/startServer.mjs +31 -0
- package/src/manager/processes/startServerProcess.mjs +34 -0
- package/src/manager/run.mjs +41 -0
- package/src/manager/spawnProcess.mjs +55 -0
- package/src/manager/watchers/configWatcher.mjs +28 -0
- package/src/manager/watchers/envWatcher.mjs +32 -0
- package/src/manager/watchers/setupWatcher.mjs +43 -0
- package/src/manager/watchers/startWatchers.mjs +64 -0
- package/src/pages/404.js +19 -0
- package/src/pages/[pageId].js +19 -0
- package/src/pages/_app.js +37 -0
- package/src/pages/_document.js +38 -0
- package/src/pages/api/auth/[...nextauth].js +28 -0
- package/src/pages/api/page/[pageId].js +29 -0
- package/src/pages/api/ping.js +19 -0
- package/src/pages/api/reload.js +52 -0
- package/src/pages/api/request/[pageId]/[requestId].js +44 -0
- package/src/pages/api/root.js +25 -0
- package/src/pages/index.js +19 -0
- package/src/utils/callRequest.js +27 -0
- package/src/utils/request.js +36 -0
- package/src/utils/setPageId.js +33 -0
- package/src/utils/setupLink.js +44 -0
- package/src/utils/useMutateCache.js +34 -0
- package/src/utils/usePageConfig.js +32 -0
- package/src/utils/useRootConfig.js +29 -0
- package/src/utils/waitForRestartedServer.js +32 -0
- package/dist/server.js +0 -47
package/.eslintrc.yaml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
extends: 'plugin:@next/next/core-web-vitals'
|
package/README.md
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
1
|
# @lowdefy/server-dev
|
|
2
2
|
|
|
3
|
-
A Lowdefy server for local development.
|
|
4
|
-
|
|
5
|
-
The server consists of a Lowdefy Graphql server, and a static file server to serve the web client shell. The web shell is a minimal react app, that loads a Lowdefy renderer using [webpack module federation](https://webpack.js.org/concepts/module-federation/).
|
|
6
|
-
|
|
7
|
-
> If you wish to develop a Lowdefy app, use the development server in the [CLI](https://docs.lowdefy.com/cli). The code for the CLI can be found [here](https://github.com/lowdefy/lowdefy/tree/main/packages/cli)
|
|
8
|
-
|
|
9
|
-
## Running a development server
|
|
10
|
-
|
|
11
|
-
- Build the repository in development mode by running `yarn build:dev` at the root of the repository.
|
|
12
|
-
- Create a `lowdefy.yaml` file in the root of the package directory, and build this configuration with the cli using `lowdefy build`.
|
|
13
|
-
- Build the dev server using `yarn build`.
|
|
14
|
-
- Run the dev server using `yarn start`.
|
|
15
|
-
- Run a [`@lowdefy/renderer`](https://github.com/lowdefy/lowdefy/tree/main/packages/renderer) server at port 3001 using `yarn start` or `yarn serve`.
|
|
16
|
-
|
|
17
|
-
To make changes to the server, you need to run `yarn build` in dependencies that have changed (like `@lowdefy/graphql`), and then run `yarn build`.
|
|
18
|
-
|
|
19
|
-
## More Lowdefy resources
|
|
20
|
-
|
|
21
|
-
- Getting started with Lowdefy - https://docs.lowdefy.com/tutorial-start
|
|
22
|
-
- Lowdefy docs - https://docs.lowdefy.com
|
|
23
|
-
- Lowdefy website - https://lowdefy.com
|
|
24
|
-
- Community forum - https://github.com/lowdefy/lowdefy/discussions
|
|
25
|
-
- Bug reports and feature requests - https://github.com/lowdefy/lowdefy/issues
|
|
26
|
-
|
|
27
3
|
## Licence
|
|
28
4
|
|
|
29
5
|
[Apache-2.0](https://github.com/lowdefy/lowdefy/blob/main/LICENSE)
|
package/next.config.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const withLess = require('next-with-less');
|
|
2
|
+
const lowdefyConfig = require('./build/config.json');
|
|
3
|
+
|
|
4
|
+
module.exports = withLess({
|
|
5
|
+
lessLoaderOptions: {
|
|
6
|
+
lessOptions: {
|
|
7
|
+
modifyVars: lowdefyConfig.theme.lessVariables,
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
// reactStrictMode: true,
|
|
11
|
+
webpack: (config, { isServer }) => {
|
|
12
|
+
if (!isServer) {
|
|
13
|
+
config.resolve.fallback = {
|
|
14
|
+
assert: false,
|
|
15
|
+
buffer: false,
|
|
16
|
+
crypto: false,
|
|
17
|
+
events: false,
|
|
18
|
+
fs: false,
|
|
19
|
+
path: false,
|
|
20
|
+
process: false,
|
|
21
|
+
util: false,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return config;
|
|
25
|
+
},
|
|
26
|
+
poweredByHeader: false,
|
|
27
|
+
// productionBrowserSourceMaps: true
|
|
28
|
+
// experimental: {
|
|
29
|
+
// concurrentFeatures: true,
|
|
30
|
+
// },
|
|
31
|
+
eslint: {
|
|
32
|
+
ignoreDuringBuilds: true,
|
|
33
|
+
},
|
|
34
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/server-dev",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.6",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -26,47 +26,59 @@
|
|
|
26
26
|
"url": "https://github.com/lowdefy/lowdefy.git"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
|
-
"
|
|
29
|
+
"src/*",
|
|
30
|
+
"public/*",
|
|
31
|
+
"next.config.js",
|
|
32
|
+
".eslintrc.yaml"
|
|
30
33
|
],
|
|
31
34
|
"scripts": {
|
|
32
|
-
"
|
|
33
|
-
"build": "
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
35
|
+
"build:lowdefy": "lowdefy-build",
|
|
36
|
+
"build:next": "next build",
|
|
37
|
+
"dev": "next dev",
|
|
38
|
+
"start": "node src/manager/run.mjs",
|
|
39
|
+
"lint": "next lint",
|
|
40
|
+
"next": "next"
|
|
37
41
|
},
|
|
38
42
|
"dependencies": {
|
|
39
|
-
"@lowdefy/
|
|
40
|
-
"@lowdefy/
|
|
41
|
-
"@lowdefy/
|
|
42
|
-
"@lowdefy/
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
43
|
+
"@lowdefy/api": "4.0.0-alpha.6",
|
|
44
|
+
"@lowdefy/block-utils": "4.0.0-alpha.6",
|
|
45
|
+
"@lowdefy/blocks-antd": "4.0.0-alpha.6",
|
|
46
|
+
"@lowdefy/blocks-basic": "4.0.0-alpha.6",
|
|
47
|
+
"@lowdefy/blocks-color-selectors": "4.0.0-alpha.6",
|
|
48
|
+
"@lowdefy/blocks-echarts": "4.0.0-alpha.6",
|
|
49
|
+
"@lowdefy/blocks-loaders": "4.0.0-alpha.6",
|
|
50
|
+
"@lowdefy/blocks-markdown": "4.0.0-alpha.6",
|
|
51
|
+
"@lowdefy/build": "4.0.0-alpha.6",
|
|
52
|
+
"@lowdefy/connection-axios-http": "4.0.0-alpha.6",
|
|
53
|
+
"@lowdefy/engine": "4.0.0-alpha.6",
|
|
54
|
+
"@lowdefy/helpers": "4.0.0-alpha.6",
|
|
55
|
+
"@lowdefy/layout": "4.0.0-alpha.6",
|
|
56
|
+
"@lowdefy/node-utils": "4.0.0-alpha.6",
|
|
57
|
+
"@lowdefy/operators-change-case": "4.0.0-alpha.6",
|
|
58
|
+
"@lowdefy/operators-diff": "4.0.0-alpha.6",
|
|
59
|
+
"@lowdefy/operators-js": "4.0.0-alpha.6",
|
|
60
|
+
"@lowdefy/operators-mql": "4.0.0-alpha.6",
|
|
61
|
+
"@lowdefy/operators-nunjucks": "4.0.0-alpha.6",
|
|
62
|
+
"@lowdefy/operators-uuid": "4.0.0-alpha.6",
|
|
63
|
+
"@lowdefy/operators-yaml": "4.0.0-alpha.6",
|
|
64
|
+
"chokidar": "3.5.2",
|
|
65
|
+
"next": "12.0.3",
|
|
66
|
+
"next-auth": "4.0.0-beta.6",
|
|
67
|
+
"opener": "1.5.2",
|
|
68
|
+
"react": "18.0.0-alpha-327d5c484-20211106",
|
|
69
|
+
"react-dom": "18.0.0-alpha-327d5c484-20211106",
|
|
70
|
+
"react-icons": "4.3.1",
|
|
71
|
+
"swr": "1.0.1",
|
|
72
|
+
"yargs": "17.3.0"
|
|
47
73
|
},
|
|
48
74
|
"devDependencies": {
|
|
49
|
-
"@
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"@lowdefy/block-tools": "3.23.0-alpha.0",
|
|
54
|
-
"babel-jest": "26.6.3",
|
|
55
|
-
"babel-loader": "8.2.2",
|
|
56
|
-
"clean-webpack-plugin": "3.0.0",
|
|
57
|
-
"copy-webpack-plugin": "9.0.0",
|
|
58
|
-
"css-loader": "5.2.6",
|
|
59
|
-
"html-webpack-plugin": "5.3.1",
|
|
60
|
-
"jest": "26.6.3",
|
|
61
|
-
"nodemon": "2.0.7",
|
|
62
|
-
"react": "17.0.2",
|
|
63
|
-
"react-dom": "17.0.2",
|
|
64
|
-
"style-loader": "2.0.0",
|
|
65
|
-
"webpack": "5.38.1",
|
|
66
|
-
"webpack-cli": "4.7.0"
|
|
75
|
+
"@next/eslint-plugin-next": "12.0.4",
|
|
76
|
+
"less": "4.1.2",
|
|
77
|
+
"less-loader": "10.2.0",
|
|
78
|
+
"next-with-less": "2.0.2"
|
|
67
79
|
},
|
|
68
80
|
"publishConfig": {
|
|
69
81
|
"access": "public"
|
|
70
82
|
},
|
|
71
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "2530e31af795b6a3c75ac8f72c8dbe0ab5d1251b"
|
|
72
84
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/public/icon.svg
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
2
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
3
|
+
<svg width="100%" height="100%" viewBox="0 0 94 94" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
|
4
|
+
<g transform="matrix(1,0,0,1,-979.672,-59.6924)">
|
|
5
|
+
<g transform="matrix(1,0,0,1.03297,-38.3284,-294.615)">
|
|
6
|
+
<g transform="matrix(1,0,0,1,952,232)">
|
|
7
|
+
<path d="M160,129.634C160,119.35 151.375,111 140.751,111L85.249,111C74.625,111 66,119.35 66,129.634L66,183.366C66,193.65 74.625,202 85.249,202L140.751,202C151.375,202 160,193.65 160,183.366L160,129.634Z"/>
|
|
8
|
+
</g>
|
|
9
|
+
<g transform="matrix(0.872141,0,0,1,1002.6,346)">
|
|
10
|
+
<rect x="36" y="12" width="36" height="59" style="fill:white;"/>
|
|
11
|
+
</g>
|
|
12
|
+
<g transform="matrix(0.78125,0,0,0.862069,1010.84,356.663)">
|
|
13
|
+
<rect x="77" y="41" width="32" height="29" style="fill:rgb(24,144,255);"/>
|
|
14
|
+
</g>
|
|
15
|
+
</g>
|
|
16
|
+
</g>
|
|
17
|
+
</svg>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"short_name": "Lowdefy App",
|
|
3
|
+
"name": "Lowdefy App",
|
|
4
|
+
"description": "Lowdefy App",
|
|
5
|
+
"icons": [
|
|
6
|
+
{
|
|
7
|
+
"src": "/public/icon-512.png",
|
|
8
|
+
"type": "image/png",
|
|
9
|
+
"sizes": "512x512"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"start_url": "/",
|
|
13
|
+
"background_color": "#FFFFFF",
|
|
14
|
+
"display": "browser",
|
|
15
|
+
"scope": "/"
|
|
16
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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 { useRouter } from 'next/router';
|
|
20
|
+
|
|
21
|
+
import Page from './Page.js';
|
|
22
|
+
import Reload from './Reload.js';
|
|
23
|
+
import setPageId from '../utils/setPageId.js';
|
|
24
|
+
import setupLink from '../utils/setupLink.js';
|
|
25
|
+
import useRootConfig from '../utils/useRootConfig.js';
|
|
26
|
+
|
|
27
|
+
const App = ({ lowdefy }) => {
|
|
28
|
+
const router = useRouter();
|
|
29
|
+
const { data: rootConfig } = useRootConfig();
|
|
30
|
+
|
|
31
|
+
window.lowdefy = lowdefy;
|
|
32
|
+
|
|
33
|
+
lowdefy.home = rootConfig.home;
|
|
34
|
+
lowdefy.lowdefyGlobal = rootConfig.lowdefyGlobal;
|
|
35
|
+
lowdefy.menus = rootConfig.menus;
|
|
36
|
+
|
|
37
|
+
lowdefy._internal.basePath = router.basePath;
|
|
38
|
+
lowdefy._internal.pathname = router.pathname;
|
|
39
|
+
lowdefy._internal.query = router.query;
|
|
40
|
+
lowdefy._internal.router = router;
|
|
41
|
+
lowdefy._internal.link = setupLink({ lowdefy });
|
|
42
|
+
|
|
43
|
+
const redirect = setPageId(lowdefy);
|
|
44
|
+
if (redirect) {
|
|
45
|
+
lowdefy._internal.router.push(`/${lowdefy.pageId}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Reload lowdefy={lowdefy}>
|
|
50
|
+
<Page lowdefy={lowdefy} />
|
|
51
|
+
</Reload>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default App;
|
|
@@ -0,0 +1,62 @@
|
|
|
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;
|
|
@@ -0,0 +1,28 @@
|
|
|
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;
|
|
@@ -0,0 +1,50 @@
|
|
|
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 callRequest from '../utils/callRequest.js';
|
|
20
|
+
import blockComponents from '../../build/plugins/blocks.js';
|
|
21
|
+
import operators from '../../build/plugins/operatorsClient.js';
|
|
22
|
+
import components from './components.js';
|
|
23
|
+
|
|
24
|
+
const LowdefyContext = ({ children }) => {
|
|
25
|
+
const lowdefy = {
|
|
26
|
+
_internal: {
|
|
27
|
+
blockComponents,
|
|
28
|
+
callRequest,
|
|
29
|
+
components,
|
|
30
|
+
document,
|
|
31
|
+
operators,
|
|
32
|
+
updaters: {},
|
|
33
|
+
window,
|
|
34
|
+
displayMessage: ({ content }) => {
|
|
35
|
+
alert(content);
|
|
36
|
+
return () => undefined;
|
|
37
|
+
},
|
|
38
|
+
link: () => undefined,
|
|
39
|
+
},
|
|
40
|
+
contexts: {},
|
|
41
|
+
inputs: {},
|
|
42
|
+
lowdefyGlobal: {},
|
|
43
|
+
};
|
|
44
|
+
lowdefy._internal.updateBlock = (blockId) =>
|
|
45
|
+
lowdefy._internal.updaters[blockId] && lowdefy._internal.updaters[blockId]();
|
|
46
|
+
|
|
47
|
+
return <>{children(lowdefy)}</>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default LowdefyContext;
|
|
@@ -0,0 +1,54 @@
|
|
|
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);
|
|
28
|
+
if (!pageConfig) {
|
|
29
|
+
lowdefy._internal.router.push(`/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;
|
|
@@ -0,0 +1,43 @@
|
|
|
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();
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const sse = new EventSource('/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;
|
|
@@ -0,0 +1,57 @@
|
|
|
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;
|