@lowdefy/server 4.0.0-alpha.6 → 4.0.0-alpha.7
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/next.config.js +2 -0
- package/package.json +17 -18
- package/src/components/LowdefyContext.js +13 -12
- package/src/components/Page.js +8 -4
- package/src/components/block/CategorySwitch.js +2 -5
- package/src/components/block/Container.js +1 -2
- package/src/components/block/List.js +1 -2
- package/src/components/{components.js → createComponents.js} +8 -4
- package/src/components/createLinkComponent.js +97 -0
- package/src/pages/[pageId].js +0 -2
- package/src/pages/_app.js +4 -2
- package/src/pages/index.js +1 -0
- package/src/utils/setupLink.js +22 -14
- package/public/.DS_Store +0 -0
package/next.config.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const withLess = require('next-with-less');
|
|
2
2
|
const lowdefyConfig = require('./build/config.json');
|
|
3
3
|
|
|
4
|
+
// TODO: Trance env and args from cli that is required on the server.
|
|
4
5
|
module.exports = withLess({
|
|
6
|
+
basePath: process.env.LOWDEFY_BASE_PATH || lowdefyConfig.basePath,
|
|
5
7
|
lessLoaderOptions: {
|
|
6
8
|
lessOptions: {
|
|
7
9
|
modifyVars: lowdefyConfig.theme.lessVariables,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/server",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.7",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -34,36 +34,35 @@
|
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build:lowdefy": "lowdefy-build",
|
|
36
36
|
"build:next": "next build",
|
|
37
|
-
"dev": "
|
|
38
|
-
"dev:prod": "yarn build:lowdefy && yarn && yarn build:next && next start",
|
|
37
|
+
"dev": "next dev",
|
|
39
38
|
"start": "next start",
|
|
40
39
|
"lint": "next lint",
|
|
41
40
|
"next": "next"
|
|
42
41
|
},
|
|
43
42
|
"dependencies": {
|
|
44
|
-
"@lowdefy/api": "4.0.0-alpha.
|
|
45
|
-
"@lowdefy/block-utils": "4.0.0-alpha.
|
|
46
|
-
"@lowdefy/engine": "4.0.0-alpha.
|
|
47
|
-
"@lowdefy/helpers": "4.0.0-alpha.
|
|
48
|
-
"@lowdefy/layout": "4.0.0-alpha.
|
|
49
|
-
"@lowdefy/node-utils": "4.0.0-alpha.
|
|
50
|
-
"@lowdefy/operators-js": "4.0.0-alpha.
|
|
51
|
-
"next": "12.0.
|
|
52
|
-
"next-auth": "4.
|
|
43
|
+
"@lowdefy/api": "4.0.0-alpha.7",
|
|
44
|
+
"@lowdefy/block-utils": "4.0.0-alpha.7",
|
|
45
|
+
"@lowdefy/engine": "4.0.0-alpha.7",
|
|
46
|
+
"@lowdefy/helpers": "4.0.0-alpha.7",
|
|
47
|
+
"@lowdefy/layout": "4.0.0-alpha.7",
|
|
48
|
+
"@lowdefy/node-utils": "4.0.0-alpha.7",
|
|
49
|
+
"@lowdefy/operators-js": "4.0.0-alpha.7",
|
|
50
|
+
"next": "12.0.10",
|
|
51
|
+
"next-auth": "4.1.2",
|
|
53
52
|
"process": "0.11.10",
|
|
54
|
-
"react": "18.0.0-
|
|
55
|
-
"react-dom": "18.0.0-
|
|
53
|
+
"react": "18.0.0-rc.0",
|
|
54
|
+
"react-dom": "18.0.0-rc.0",
|
|
56
55
|
"react-icons": "4.3.1"
|
|
57
56
|
},
|
|
58
57
|
"devDependencies": {
|
|
59
|
-
"@lowdefy/build": "4.0.0-alpha.
|
|
60
|
-
"@next/eslint-plugin-next": "12.0.
|
|
58
|
+
"@lowdefy/build": "4.0.0-alpha.7",
|
|
59
|
+
"@next/eslint-plugin-next": "12.0.10",
|
|
61
60
|
"less": "4.1.2",
|
|
62
61
|
"less-loader": "10.2.0",
|
|
63
|
-
"next-with-less": "2.0.
|
|
62
|
+
"next-with-less": "2.0.4"
|
|
64
63
|
},
|
|
65
64
|
"publishConfig": {
|
|
66
65
|
"access": "public"
|
|
67
66
|
},
|
|
68
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "52ec14639d00de910cf9b8ab25bf933ca891cff5"
|
|
69
68
|
}
|
|
@@ -16,34 +16,35 @@
|
|
|
16
16
|
|
|
17
17
|
import React from 'react';
|
|
18
18
|
|
|
19
|
+
import actions from '../../build/plugins/actions.js';
|
|
19
20
|
import callRequest from '../utils/callRequest.js';
|
|
20
21
|
import blockComponents from '../../build/plugins/blocks.js';
|
|
21
22
|
import operators from '../../build/plugins/operatorsClient.js';
|
|
22
|
-
import components from './components.js';
|
|
23
23
|
|
|
24
|
-
const LowdefyContext = ({ children }) => {
|
|
25
|
-
|
|
26
|
-
_internal
|
|
24
|
+
const LowdefyContext = ({ children, lowdefy }) => {
|
|
25
|
+
if (!lowdefy._internal) {
|
|
26
|
+
lowdefy._internal = {
|
|
27
|
+
actions,
|
|
27
28
|
blockComponents,
|
|
28
29
|
callRequest,
|
|
29
|
-
components,
|
|
30
|
+
components: {},
|
|
30
31
|
document,
|
|
31
32
|
operators,
|
|
32
33
|
updaters: {},
|
|
33
34
|
window,
|
|
34
35
|
displayMessage: ({ content }) => {
|
|
35
|
-
|
|
36
|
+
console.log(content);
|
|
36
37
|
return () => undefined;
|
|
37
38
|
},
|
|
38
39
|
link: () => undefined,
|
|
39
|
-
}
|
|
40
|
-
contexts
|
|
41
|
-
inputs
|
|
42
|
-
lowdefyGlobal
|
|
43
|
-
}
|
|
40
|
+
};
|
|
41
|
+
lowdefy.contexts = {};
|
|
42
|
+
lowdefy.inputs = {};
|
|
43
|
+
lowdefy.lowdefyGlobal = {};
|
|
44
|
+
}
|
|
44
45
|
lowdefy._internal.updateBlock = (blockId) =>
|
|
45
46
|
lowdefy._internal.updaters[blockId] && lowdefy._internal.updaters[blockId]();
|
|
46
|
-
return <>{children
|
|
47
|
+
return <>{children}</>;
|
|
47
48
|
};
|
|
48
49
|
|
|
49
50
|
export default LowdefyContext;
|
package/src/components/Page.js
CHANGED
|
@@ -16,25 +16,29 @@
|
|
|
16
16
|
|
|
17
17
|
import React from 'react';
|
|
18
18
|
|
|
19
|
+
import { urlQuery } from '@lowdefy/helpers';
|
|
19
20
|
import { useRouter } from 'next/router';
|
|
20
21
|
|
|
21
22
|
import Context from './Context.js';
|
|
22
23
|
import Head from './Head.js';
|
|
23
24
|
import Block from './block/Block.js';
|
|
24
25
|
import setupLink from '../utils/setupLink.js';
|
|
26
|
+
import createComponents from './createComponents.js';
|
|
25
27
|
|
|
26
28
|
const LoadingBlock = () => <div>Loading...</div>;
|
|
27
29
|
|
|
28
30
|
const Page = ({ lowdefy, pageConfig, rootConfig }) => {
|
|
29
31
|
const router = useRouter();
|
|
30
|
-
lowdefy._internal.basePath = router.basePath;
|
|
31
|
-
lowdefy._internal.pathname = router.pathname;
|
|
32
|
-
lowdefy._internal.query = router.query;
|
|
33
32
|
lowdefy._internal.router = router;
|
|
34
|
-
lowdefy._internal.link = setupLink(
|
|
33
|
+
lowdefy._internal.link = setupLink(lowdefy);
|
|
34
|
+
lowdefy._internal.components = createComponents(lowdefy);
|
|
35
|
+
|
|
36
|
+
lowdefy.basePath = lowdefy._internal.router.basePath;
|
|
35
37
|
lowdefy.home = rootConfig.home;
|
|
36
38
|
lowdefy.lowdefyGlobal = rootConfig.lowdefyGlobal;
|
|
37
39
|
lowdefy.menus = rootConfig.menus;
|
|
40
|
+
lowdefy.urlQuery = urlQuery.parse(window.location.search.slice(1));
|
|
41
|
+
|
|
38
42
|
return (
|
|
39
43
|
<Context config={pageConfig} lowdefy={lowdefy}>
|
|
40
44
|
{(context, loading) => {
|
|
@@ -64,12 +64,10 @@ const CategorySwitch = ({ block, Blocks, context, lowdefy }) => {
|
|
|
64
64
|
setValue: block.setValue,
|
|
65
65
|
triggerEvent: block.triggerEvent,
|
|
66
66
|
})}
|
|
67
|
-
|
|
68
|
-
basePath={lowdefy._internal.basePath}
|
|
67
|
+
basePath={lowdefy.basePath}
|
|
69
68
|
blockId={block.blockId}
|
|
70
69
|
components={lowdefy._internal.components}
|
|
71
70
|
events={block.eval.events}
|
|
72
|
-
homePageId={lowdefy.home.pageId}
|
|
73
71
|
key={block.blockId}
|
|
74
72
|
loading={block.loading}
|
|
75
73
|
menus={lowdefy.menus}
|
|
@@ -98,11 +96,10 @@ const CategorySwitch = ({ block, Blocks, context, lowdefy }) => {
|
|
|
98
96
|
registerMethod: block.registerMethod,
|
|
99
97
|
triggerEvent: block.triggerEvent,
|
|
100
98
|
})}
|
|
101
|
-
basePath={lowdefy.
|
|
99
|
+
basePath={lowdefy.basePath}
|
|
102
100
|
blockId={block.blockId}
|
|
103
101
|
components={lowdefy._internal.components}
|
|
104
102
|
events={block.eval.events}
|
|
105
|
-
homePageId={lowdefy.home.pageId}
|
|
106
103
|
key={block.blockId}
|
|
107
104
|
loading={block.loading}
|
|
108
105
|
menus={lowdefy.menus}
|
|
@@ -65,12 +65,11 @@ const Container = ({ block, Blocks, Component, context, lowdefy }) => {
|
|
|
65
65
|
registerMethod: block.registerMethod,
|
|
66
66
|
triggerEvent: block.triggerEvent,
|
|
67
67
|
})}
|
|
68
|
-
basePath={lowdefy.
|
|
68
|
+
basePath={lowdefy.basePath}
|
|
69
69
|
blockId={block.blockId}
|
|
70
70
|
components={lowdefy._internal.components}
|
|
71
71
|
content={content}
|
|
72
72
|
events={block.eval.events}
|
|
73
|
-
homePageId={lowdefy.home.pageId}
|
|
74
73
|
key={block.blockId}
|
|
75
74
|
loading={block.loading}
|
|
76
75
|
menus={lowdefy.menus}
|
|
@@ -72,11 +72,10 @@ const List = ({ block, Blocks, Component, context, lowdefy }) => {
|
|
|
72
72
|
triggerEvent: block.triggerEvent,
|
|
73
73
|
unshiftItem: block.unshiftItem,
|
|
74
74
|
})}
|
|
75
|
-
basePath={lowdefy.
|
|
75
|
+
basePath={lowdefy.basePath}
|
|
76
76
|
blockId={block.blockId}
|
|
77
77
|
components={lowdefy._internal.components}
|
|
78
78
|
events={block.eval.events}
|
|
79
|
-
homePageId={lowdefy.home.pageId}
|
|
80
79
|
key={block.blockId}
|
|
81
80
|
list={contentList}
|
|
82
81
|
loading={block.loading}
|
|
@@ -14,12 +14,16 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import Link from 'next/link';
|
|
18
17
|
import { createIcon } from '@lowdefy/block-utils';
|
|
19
18
|
|
|
19
|
+
import createLinkComponent from './createLinkComponent.js';
|
|
20
20
|
import icons from '../../build/plugins/icons.js';
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const createComponents = (lowdefy) => {
|
|
23
|
+
return {
|
|
24
|
+
Link: createLinkComponent(lowdefy),
|
|
25
|
+
Icon: createIcon(icons),
|
|
26
|
+
};
|
|
25
27
|
};
|
|
28
|
+
|
|
29
|
+
export default createComponents;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import NextLink from 'next/link';
|
|
3
|
+
import { createLink } from '@lowdefy/engine';
|
|
4
|
+
import { type } from '@lowdefy/helpers';
|
|
5
|
+
|
|
6
|
+
const createLinkComponent = (lowdefy) => {
|
|
7
|
+
const backLink = ({ ariaLabel, children, className, id, rel }) => (
|
|
8
|
+
<a
|
|
9
|
+
id={id}
|
|
10
|
+
onClick={() => lowdefy._internal.router.back()}
|
|
11
|
+
className={className}
|
|
12
|
+
rel={rel}
|
|
13
|
+
aria-label={ariaLabel || 'back'}
|
|
14
|
+
>
|
|
15
|
+
{type.isFunction(children) ? children(id) : children}
|
|
16
|
+
</a>
|
|
17
|
+
);
|
|
18
|
+
const newOriginLink = ({
|
|
19
|
+
ariaLabel,
|
|
20
|
+
children,
|
|
21
|
+
className,
|
|
22
|
+
id,
|
|
23
|
+
newTab,
|
|
24
|
+
pageId,
|
|
25
|
+
query,
|
|
26
|
+
rel,
|
|
27
|
+
url,
|
|
28
|
+
}) => {
|
|
29
|
+
return (
|
|
30
|
+
<a
|
|
31
|
+
id={id}
|
|
32
|
+
aria-label={ariaLabel}
|
|
33
|
+
className={className}
|
|
34
|
+
href={`${url}${query ? `?${query}` : ''}`}
|
|
35
|
+
rel={rel || (newTab && 'noopener noreferrer')}
|
|
36
|
+
target={newTab && '_blank'}
|
|
37
|
+
>
|
|
38
|
+
{type.isFunction(children) ? children(pageId || url || id) : children}
|
|
39
|
+
</a>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
const sameOriginLink = ({
|
|
43
|
+
ariaLabel,
|
|
44
|
+
children,
|
|
45
|
+
className,
|
|
46
|
+
id,
|
|
47
|
+
newTab,
|
|
48
|
+
pageId,
|
|
49
|
+
pathname,
|
|
50
|
+
query,
|
|
51
|
+
rel,
|
|
52
|
+
replace,
|
|
53
|
+
scroll,
|
|
54
|
+
setInput,
|
|
55
|
+
url,
|
|
56
|
+
}) => {
|
|
57
|
+
if (newTab) {
|
|
58
|
+
return (
|
|
59
|
+
// eslint-disable-next-line react/jsx-no-target-blank
|
|
60
|
+
<a
|
|
61
|
+
id={id}
|
|
62
|
+
aria-label={ariaLabel}
|
|
63
|
+
className={className}
|
|
64
|
+
href={`${window.location.origin}${lowdefy.basePath}${pathname}${
|
|
65
|
+
query ? `?${query}` : ''
|
|
66
|
+
}`}
|
|
67
|
+
rel={rel || 'noopener noreferrer'}
|
|
68
|
+
target="_blank"
|
|
69
|
+
>
|
|
70
|
+
{type.isFunction(children) ? children(pageId || url || id) : children}
|
|
71
|
+
</a>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return (
|
|
75
|
+
<NextLink href={{ pathname, query }} replace={replace} scroll={scroll}>
|
|
76
|
+
<a id={id} aria-label={ariaLabel} className={className} rel={rel} onClick={setInput}>
|
|
77
|
+
{type.isFunction(children) ? children(pageId || url || id) : children}
|
|
78
|
+
</a>
|
|
79
|
+
</NextLink>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
const noLink = ({ className, children, id }) => (
|
|
83
|
+
<span id={id} className={className}>
|
|
84
|
+
{type.isFunction(children) ? children(id) : children}
|
|
85
|
+
</span>
|
|
86
|
+
);
|
|
87
|
+
return createLink({
|
|
88
|
+
backLink,
|
|
89
|
+
lowdefy,
|
|
90
|
+
newOriginLink,
|
|
91
|
+
sameOriginLink,
|
|
92
|
+
noLink,
|
|
93
|
+
disabledLink: noLink,
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export default createLinkComponent;
|
package/src/pages/[pageId].js
CHANGED
|
@@ -23,8 +23,6 @@ export async function getServerSideProps(context) {
|
|
|
23
23
|
// TODO: get the right api context options
|
|
24
24
|
const apiContext = await createApiContext({ buildDirectory: './build' });
|
|
25
25
|
|
|
26
|
-
// TODO: Maybe we can only get rootConfig once?
|
|
27
|
-
// We can't do getServerSideProps on _app :(
|
|
28
26
|
const [rootConfig, pageConfig] = await Promise.all([
|
|
29
27
|
getRootConfig(apiContext),
|
|
30
28
|
getPageConfig(apiContext, { pageId }),
|
package/src/pages/_app.js
CHANGED
|
@@ -22,12 +22,14 @@ import LowdefyContext from '../components/LowdefyContext.js';
|
|
|
22
22
|
|
|
23
23
|
import '../../build/plugins/styles.less';
|
|
24
24
|
|
|
25
|
+
const lowdefy = {};
|
|
26
|
+
|
|
25
27
|
function App({ Component, pageProps }) {
|
|
26
28
|
return (
|
|
27
29
|
<ErrorBoundary>
|
|
28
30
|
<Suspense>
|
|
29
|
-
<LowdefyContext>
|
|
30
|
-
|
|
31
|
+
<LowdefyContext lowdefy={lowdefy}>
|
|
32
|
+
<Component lowdefy={lowdefy} {...pageProps} />
|
|
31
33
|
</LowdefyContext>
|
|
32
34
|
</Suspense>
|
|
33
35
|
</ErrorBoundary>
|
package/src/pages/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
|
|
|
19
19
|
import Page from '../components/Page.js';
|
|
20
20
|
|
|
21
21
|
export async function getServerSideProps() {
|
|
22
|
+
// TODO: is this build directory configurable from the cli?
|
|
22
23
|
const apiContext = await createApiContext({ buildDirectory: './build' });
|
|
23
24
|
const rootConfig = await getRootConfig(apiContext);
|
|
24
25
|
const { home } = rootConfig;
|
package/src/utils/setupLink.js
CHANGED
|
@@ -16,29 +16,37 @@
|
|
|
16
16
|
|
|
17
17
|
import { createLink } from '@lowdefy/engine';
|
|
18
18
|
|
|
19
|
-
function setupLink(
|
|
19
|
+
function setupLink(lowdefy) {
|
|
20
20
|
const { router, window } = lowdefy._internal;
|
|
21
|
-
const
|
|
21
|
+
const backLink = () => router.back();
|
|
22
|
+
const disabledLink = () => {};
|
|
23
|
+
const newOriginLink = ({ url, query, newTab }) => {
|
|
22
24
|
if (newTab) {
|
|
23
|
-
return window.open(`${
|
|
25
|
+
return window.open(`${url}${query ? `?${query}` : ''}`, '_blank').focus();
|
|
24
26
|
} else {
|
|
25
|
-
|
|
26
|
-
return router.push({
|
|
27
|
-
pathname: path,
|
|
28
|
-
// TODO: Do we handle urlQuery as a param here?
|
|
29
|
-
// query: {},
|
|
30
|
-
});
|
|
27
|
+
return window.location.assign(`${url}${query ? `?${query}` : ''}`);
|
|
31
28
|
}
|
|
32
29
|
};
|
|
33
|
-
const
|
|
30
|
+
const sameOriginLink = ({ newTab, pathname, query, setInput }) => {
|
|
34
31
|
if (newTab) {
|
|
35
|
-
return window
|
|
32
|
+
return window
|
|
33
|
+
.open(
|
|
34
|
+
`${window.location.origin}${lowdefy.basePath}${pathname}${query ? `?${query}` : ''}`,
|
|
35
|
+
'_blank'
|
|
36
|
+
)
|
|
37
|
+
.focus();
|
|
36
38
|
} else {
|
|
37
|
-
|
|
39
|
+
setInput();
|
|
40
|
+
return router.push({
|
|
41
|
+
pathname,
|
|
42
|
+
query,
|
|
43
|
+
});
|
|
38
44
|
}
|
|
39
45
|
};
|
|
40
|
-
const
|
|
41
|
-
|
|
46
|
+
const noLink = () => {
|
|
47
|
+
throw new Error(`Invalid Link.`);
|
|
48
|
+
};
|
|
49
|
+
return createLink({ backLink, disabledLink, lowdefy, newOriginLink, noLink, sameOriginLink });
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
export default setupLink;
|
package/public/.DS_Store
DELETED
|
Binary file
|