@lowdefy/client 4.0.0-alpha.9 → 4.0.0-rc.0

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/dist/Client.js CHANGED
@@ -19,11 +19,12 @@ import DisplayMessage from './DisplayMessage.js';
19
19
  import Head from './Head.js';
20
20
  import ProgressBarController from './ProgressBarController.js';
21
21
  import initLowdefyContext from './initLowdefyContext.js';
22
- const Client = ({ Components , config , resetContext ={
22
+ const Client = ({ auth , Components , config , resetContext ={
23
23
  reset: false,
24
24
  setReset: ()=>undefined
25
25
  } , router , stage , types , window , })=>{
26
26
  const lowdefy = initLowdefyContext({
27
+ auth,
27
28
  Components,
28
29
  config,
29
30
  router,
@@ -31,7 +32,7 @@ const Client = ({ Components , config , resetContext ={
31
32
  types,
32
33
  window
33
34
  });
34
- return(/*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ProgressBarController, {
35
+ return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ProgressBarController, {
35
36
  id: "lowdefy-progress-bar",
36
37
  key: `${config.pageConfig.id}-progress-bar`,
37
38
  lowdefy: lowdefy,
@@ -52,16 +53,16 @@ const Client = ({ Components , config , resetContext ={
52
53
  resetContext: resetContext
53
54
  }, (context)=>{
54
55
  if (!context._internal.onInitDone) return '';
55
- return(/*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Head, {
56
+ return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Head, {
56
57
  Component: Components.Head,
57
- properties: context._internal.RootBlocks.map[config.pageConfig.id].eval.properties
58
+ properties: context._internal.RootBlocks.map[config.pageConfig.blockId].eval.properties
58
59
  }), /*#__PURE__*/ React.createElement(Block, {
59
- block: context._internal.RootBlocks.map[config.pageConfig.id],
60
+ block: context._internal.RootBlocks.map[config.pageConfig.blockId],
60
61
  Blocks: context._internal.RootBlocks,
61
62
  context: context,
62
63
  lowdefy: lowdefy,
63
64
  parentLoading: false
64
- })));
65
- })));
65
+ }));
66
+ }));
66
67
  };
67
68
  export default Client;
package/dist/Context.js CHANGED
@@ -21,7 +21,7 @@ const Context = ({ children , config , lowdefy , resetContext })=>{
21
21
  lowdefy,
22
22
  resetContext
23
23
  });
24
- return(/*#__PURE__*/ React.createElement(MountEvents, {
24
+ return /*#__PURE__*/ React.createElement(MountEvents, {
25
25
  context: context,
26
26
  triggerEvent: async ()=>{
27
27
  await context._internal.runOnInit(()=>{
@@ -40,6 +40,6 @@ const Context = ({ children , config , lowdefy , resetContext })=>{
40
40
  }, (loadingOnInit)=>{
41
41
  if (loadingOnInit) return '';
42
42
  return children(context);
43
- }));
43
+ });
44
44
  };
45
45
  export default Context;
@@ -15,7 +15,7 @@
15
15
  */ import React from 'react';
16
16
  import { makeCssClass } from '@lowdefy/block-utils';
17
17
  const DisplayMessage = ({ Component , id , methods })=>{
18
- return(/*#__PURE__*/ React.createElement(Component, {
18
+ return /*#__PURE__*/ React.createElement(Component, {
19
19
  blockId: id,
20
20
  key: id,
21
21
  methods: {
@@ -24,6 +24,6 @@ const DisplayMessage = ({ Component , id , methods })=>{
24
24
  triggerEvent: ()=>undefined
25
25
  },
26
26
  properties: {}
27
- }));
27
+ });
28
28
  };
29
29
  export default DisplayMessage;
@@ -29,12 +29,12 @@ let ErrorBoundary = class ErrorBoundary extends Component {
29
29
  return fallback(error);
30
30
  }
31
31
  if (fullPage) {
32
- return(/*#__PURE__*/ React.createElement(ErrorPage, {
32
+ return /*#__PURE__*/ React.createElement(ErrorPage, {
33
33
  code: error.number,
34
34
  description: description || error.description,
35
35
  message: message || error.message,
36
36
  name: name || error.name
37
- }));
37
+ });
38
38
  }
39
39
  // Throw to console but fail silently to user?
40
40
  return '';
package/dist/ErrorPage.js CHANGED
@@ -56,6 +56,5 @@ const ErrorPage = ({ code , description , message , name })=>/*#__PURE__*/ Reac
56
56
  }
57
57
  }, /*#__PURE__*/ React.createElement("a", {
58
58
  href: "/"
59
- }, "Return to home page"))))
60
- ;
59
+ }, "Return to home page"))));
61
60
  export default ErrorPage;
package/dist/Head.js CHANGED
@@ -14,6 +14,6 @@
14
14
  limitations under the License.
15
15
  */ import React from 'react';
16
16
  const BindHead = ({ Component , properties })=>{
17
- return(/*#__PURE__*/ React.createElement(Component, null, /*#__PURE__*/ React.createElement("title", null, properties.title)));
17
+ return /*#__PURE__*/ React.createElement(Component, null, /*#__PURE__*/ React.createElement("title", null, properties.title));
18
18
  };
19
19
  export default BindHead;
@@ -17,27 +17,21 @@ const MountEvents = ({ children , context , triggerEvent , triggerEventAsync })
17
17
  const [loading, setLoading] = useState(true);
18
18
  const [error, setError] = useState(null);
19
19
  useEffect(()=>{
20
- let mounted = true;
21
20
  setLoading(true);
22
21
  const mount = async ()=>{
23
22
  try {
24
23
  await triggerEvent();
25
- if (mounted) {
26
- triggerEventAsync();
27
- setLoading(false);
28
- }
24
+ triggerEventAsync();
25
+ setLoading(false);
29
26
  } catch (err) {
30
27
  setError(err);
31
28
  }
32
29
  };
33
- mount(); // TODO: check only run once.
34
- return ()=>{
35
- mounted = false;
36
- };
30
+ mount();
37
31
  }, [
38
32
  context
39
33
  ]);
40
34
  if (error) throw error;
41
- return(/*#__PURE__*/ React.createElement(React.Fragment, null, children(loading)));
35
+ return /*#__PURE__*/ React.createElement(React.Fragment, null, children(loading));
42
36
  };
43
37
  export default MountEvents;
@@ -57,10 +57,8 @@ const ProgressBarController = ({ id , lowdefy , resetContext })=>{
57
57
  useEffect(()=>{
58
58
  const timer = state.progress < 95 && setInterval(()=>dispatch({
59
59
  type: 'auto-increment'
60
- })
61
- , 500);
62
- return ()=>clearInterval(timer)
63
- ;
60
+ }), 500);
61
+ return ()=>clearInterval(timer);
64
62
  }, [
65
63
  state
66
64
  ]);
@@ -69,7 +67,7 @@ const ProgressBarController = ({ id , lowdefy , resetContext })=>{
69
67
  type: 'reset'
70
68
  });
71
69
  }
72
- return(/*#__PURE__*/ React.createElement(ProgressBar, {
70
+ return /*#__PURE__*/ React.createElement(ProgressBar, {
73
71
  basePath: lowdefy.basePath,
74
72
  blockId: id,
75
73
  components: lowdefy._internal.components,
@@ -78,8 +76,7 @@ const ProgressBarController = ({ id , lowdefy , resetContext })=>{
78
76
  makeCssClass
79
77
  },
80
78
  pageId: lowdefy.pageId,
81
- properties: state,
82
- user: lowdefy.user
83
- }));
79
+ properties: state
80
+ });
84
81
  };
85
82
  export default ProgressBarController;
@@ -0,0 +1,66 @@
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
+ */ import { type, urlQuery as urlQueryFn } from '@lowdefy/helpers';
16
+ function getCallbackUrl({ lowdefy , callbackUrl ={} }) {
17
+ const { home , pageId , urlQuery , url } = callbackUrl;
18
+ if ([
19
+ !home,
20
+ !pageId,
21
+ !url
22
+ ].filter((v)=>!v).length > 1) {
23
+ throw Error(`Invalid Link: To avoid ambiguity, only one of 'home', 'pageId' or 'url' can be defined.`);
24
+ }
25
+ const query = type.isNone(urlQuery) ? '' : `${urlQueryFn.stringify(urlQuery)}`;
26
+ if (home === true) {
27
+ return `/${lowdefy.home.configured ? '' : lowdefy.home.pageId}${query ? `?${query}` : ''}`;
28
+ }
29
+ if (type.isString(pageId)) {
30
+ return `/${pageId}${query ? `?${query}` : ''}`;
31
+ }
32
+ if (type.isString(url)) {
33
+ return `${url}${query ? `?${query}` : ''}`;
34
+ }
35
+ return undefined;
36
+ }
37
+ function createAuthMethods({ lowdefy , auth }) {
38
+ // login and logout are Lowdefy function that handle action params
39
+ // signIn and signOut are the next-auth methods
40
+ function login({ authUrl , callbackUrl , providerId , ...rest } = {}) {
41
+ if (type.isNone(providerId) && auth.authConfig.providers.length === 1) {
42
+ providerId = auth.authConfig.providers[0].id;
43
+ }
44
+ auth.signIn(providerId, {
45
+ ...rest,
46
+ callbackUrl: getCallbackUrl({
47
+ lowdefy,
48
+ callbackUrl
49
+ })
50
+ }, authUrl?.urlQuery);
51
+ }
52
+ function logout({ callbackUrl , redirect } = {}) {
53
+ auth.signOut({
54
+ callbackUrl: getCallbackUrl({
55
+ lowdefy,
56
+ callbackUrl
57
+ }),
58
+ redirect
59
+ });
60
+ }
61
+ return {
62
+ login,
63
+ logout
64
+ };
65
+ }
66
+ export default createAuthMethods;
@@ -18,9 +18,8 @@ import ErrorBoundary from '../ErrorBoundary.js';
18
18
  import MountEvents from '../MountEvents.js';
19
19
  const Block = ({ block , Blocks , context , lowdefy , parentLoading })=>{
20
20
  const [updates, setUpdate] = useState(0);
21
- lowdefy._internal.updaters[block.id] = ()=>setUpdate(updates + 1)
22
- ;
23
- return(/*#__PURE__*/ React.createElement(ErrorBoundary, null, /*#__PURE__*/ React.createElement(MountEvents, {
21
+ lowdefy._internal.updaters[block.id] = ()=>setUpdate(updates + 1);
22
+ return /*#__PURE__*/ React.createElement(ErrorBoundary, null, /*#__PURE__*/ React.createElement(MountEvents, {
24
23
  context: context,
25
24
  triggerEvent: async ()=>{
26
25
  context._internal.lowdefy._internal.progress.dispatch({
@@ -56,7 +55,6 @@ const Block = ({ block , Blocks , context , lowdefy , parentLoading })=>{
56
55
  loading: eventLoading || parentLoading || block.eval.loading,
57
56
  lowdefy: lowdefy,
58
57
  updates: updates
59
- })
60
- )));
58
+ })));
61
59
  };
62
60
  export default Block;
@@ -21,46 +21,48 @@ import List from './List.js';
21
21
  import LoadingBlock from './LoadingBlock.js';
22
22
  const CategorySwitch = ({ block , Blocks , context , loading , lowdefy })=>{
23
23
  if (!block.eval) return null; // TODO: check Renderer updates before eval is executed for the first time on lists. See #520
24
- if (block.eval.visible === false) return(/*#__PURE__*/ React.createElement("div", {
24
+ if (block.eval.visible === false) return /*#__PURE__*/ React.createElement("div", {
25
25
  id: `vs-${block.blockId}`,
26
26
  style: {
27
27
  display: 'none'
28
28
  }
29
- }));
29
+ });
30
30
  const Component = lowdefy._internal.blockComponents[block.type];
31
31
  if (loading && type.isObject(block.eval.skeleton)) {
32
- return(/*#__PURE__*/ React.createElement(LoadingBlock, {
32
+ return /*#__PURE__*/ React.createElement(LoadingBlock, {
33
33
  blockLayout: block.eval.layout,
34
+ blockProperties: block.eval.properties,
35
+ blockStyle: block.eval.style,
34
36
  context: context,
35
37
  lowdefy: lowdefy,
36
38
  skeleton: block.eval.skeleton
37
- }));
39
+ });
38
40
  }
39
41
  switch(Component.meta.category){
40
42
  case 'list':
41
- return(/*#__PURE__*/ React.createElement(List, {
43
+ return /*#__PURE__*/ React.createElement(List, {
42
44
  block: block,
43
45
  Blocks: Blocks,
44
46
  Component: Component,
45
47
  context: context,
46
48
  loading: loading,
47
49
  lowdefy: lowdefy
48
- }));
50
+ });
49
51
  case 'container':
50
- return(/*#__PURE__*/ React.createElement(Container, {
52
+ return /*#__PURE__*/ React.createElement(Container, {
51
53
  block: block,
52
54
  Blocks: Blocks,
53
55
  Component: Component,
54
56
  context: context,
55
57
  loading: loading,
56
58
  lowdefy: lowdefy
57
- }));
59
+ });
58
60
  case 'input':
59
- return(/*#__PURE__*/ React.createElement(BlockLayout, {
61
+ return /*#__PURE__*/ React.createElement(BlockLayout, {
60
62
  id: `bl-${block.blockId}`,
61
63
  blockStyle: block.eval.style,
62
64
  highlightBorders: lowdefy.lowdefyGlobal.highlightBorders,
63
- layout: block.eval.layout || {},
65
+ layout: block.eval.layout,
64
66
  makeCssClass: makeCssClass
65
67
  }, /*#__PURE__*/ React.createElement(Component, {
66
68
  methods: Object.assign(block.methods, {
@@ -80,16 +82,15 @@ const CategorySwitch = ({ block , Blocks , context , loading , lowdefy })=>{
80
82
  pageId: lowdefy.pageId,
81
83
  properties: block.eval.properties,
82
84
  required: block.eval.required,
83
- user: lowdefy.user,
84
85
  validation: block.eval.validation,
85
86
  value: block.value
86
- })));
87
+ }));
87
88
  default:
88
- return(/*#__PURE__*/ React.createElement(BlockLayout, {
89
+ return /*#__PURE__*/ React.createElement(BlockLayout, {
89
90
  id: `bl-${block.blockId}`,
90
91
  blockStyle: block.eval.style,
91
92
  highlightBorders: lowdefy.lowdefyGlobal.highlightBorders,
92
- layout: block.eval.layout || {},
93
+ layout: block.eval.layout,
93
94
  makeCssClass: makeCssClass
94
95
  }, /*#__PURE__*/ React.createElement(Component, {
95
96
  methods: Object.assign(block.methods, {
@@ -108,9 +109,8 @@ const CategorySwitch = ({ block , Blocks , context , loading , lowdefy })=>{
108
109
  pageId: lowdefy.pageId,
109
110
  properties: block.eval.properties,
110
111
  required: block.eval.required,
111
- user: lowdefy.user,
112
112
  validation: block.eval.validation
113
- })));
113
+ }));
114
114
  }
115
115
  };
116
116
  export default CategorySwitch;
@@ -25,13 +25,13 @@ const Container = ({ block , Blocks , Component , context , loading , lowdefy }
25
25
  id: `ar-${block.blockId}-${areaKey}`,
26
26
  key: `ar-${block.blockId}-${areaKey}-${i}`,
27
27
  area: layoutParamsToArea({
28
- area: block.eval.areas[areaKey] || {},
28
+ area: block.eval.areas[areaKey],
29
29
  areaKey,
30
- layout: block.eval.layout || {}
30
+ layout: block.eval.layout
31
31
  }),
32
32
  areaStyle: [
33
33
  areaStyle,
34
- block.eval.areas[areaKey] && block.eval.areas[areaKey].style
34
+ block.eval.areas[areaKey]?.style
35
35
  ],
36
36
  highlightBorders: lowdefy.lowdefyGlobal.highlightBorders,
37
37
  makeCssClass: makeCssClass
@@ -42,15 +42,13 @@ const Container = ({ block , Blocks , Component , context , loading , lowdefy }
42
42
  context: context,
43
43
  parentLoading: loading,
44
44
  lowdefy: lowdefy
45
- })
46
- ))
47
- ;
45
+ })));
48
46
  });
49
- return(/*#__PURE__*/ React.createElement(BlockLayout, {
47
+ return /*#__PURE__*/ React.createElement(BlockLayout, {
50
48
  id: `bl-${block.blockId}`,
51
49
  blockStyle: block.eval.style,
52
50
  highlightBorders: lowdefy.lowdefyGlobal.highlightBorders,
53
- layout: block.eval.layout || {},
51
+ layout: block.eval.layout,
54
52
  makeCssClass: makeCssClass
55
53
  }, /*#__PURE__*/ React.createElement(Component, {
56
54
  methods: Object.assign(block.methods, {
@@ -70,8 +68,7 @@ const Container = ({ block , Blocks , Component , context , loading , lowdefy }
70
68
  pageId: lowdefy.pageId,
71
69
  properties: block.eval.properties,
72
70
  required: block.eval.required,
73
- user: lowdefy.user,
74
71
  validation: block.eval.validation
75
- })));
72
+ }));
76
73
  };
77
74
  export default Container;
@@ -25,13 +25,13 @@ const List = ({ block , Blocks , Component , context , loading , lowdefy })=>{
25
25
  id: `ar-${block.blockId}-${SBlock.id}-${areaKey}`,
26
26
  key: `ar-${block.blockId}-${SBlock.id}-${areaKey}`,
27
27
  area: layoutParamsToArea({
28
- area: block.eval.areas[areaKey] || {},
28
+ area: block.eval.areas[areaKey],
29
29
  areaKey,
30
- layout: block.eval.layout || {}
30
+ layout: block.eval.layout
31
31
  }),
32
32
  areaStyle: [
33
33
  areaStyle,
34
- block.eval.areas[areaKey] && block.eval.areas[areaKey].style
34
+ block.eval.areas[areaKey]?.style
35
35
  ],
36
36
  highlightBorders: lowdefy.lowdefyGlobal.highlightBorders,
37
37
  makeCssClass: makeCssClass
@@ -42,19 +42,17 @@ const List = ({ block , Blocks , Component , context , loading , lowdefy })=>{
42
42
  context: context,
43
43
  parentLoading: loading,
44
44
  lowdefy: lowdefy
45
- })
46
- ))
47
- ;
45
+ })));
48
46
  });
49
47
  contentList.push({
50
48
  ...content
51
49
  });
52
50
  });
53
- return(/*#__PURE__*/ React.createElement(BlockLayout, {
51
+ return /*#__PURE__*/ React.createElement(BlockLayout, {
54
52
  id: `bl-${block.blockId}`,
55
53
  blockStyle: block.eval.style,
56
54
  highlightBorders: lowdefy.lowdefyGlobal.highlightBorders,
57
- layout: block.eval.layout || {},
55
+ layout: block.eval.layout,
58
56
  makeCssClass: makeCssClass
59
57
  }, /*#__PURE__*/ React.createElement(Component, {
60
58
  methods: Object.assign(block.methods, {
@@ -79,8 +77,7 @@ const List = ({ block , Blocks , Component , context , loading , lowdefy })=>{
79
77
  pageId: lowdefy.pageId,
80
78
  properties: block.eval.properties,
81
79
  required: block.eval.required,
82
- user: lowdefy.user,
83
80
  validation: block.eval.validation
84
- })));
81
+ }));
85
82
  };
86
83
  export default List;
@@ -29,7 +29,7 @@ const blockMethods = {
29
29
  triggerEvent: ()=>{},
30
30
  unshiftItem: ()=>{}
31
31
  };
32
- const LoadingBlock = ({ blockLayout , blockId , context , lowdefy , skeleton })=>{
32
+ const LoadingBlock = ({ blockId , blockLayout , blockProperties , blockStyle , context , lowdefy , skeleton , })=>{
33
33
  let Component = lowdefy._internal.blockComponents[skeleton.type];
34
34
  useEffect(()=>{
35
35
  if (!lowdefy._internal.blockComponents[skeleton.type]) {
@@ -41,32 +41,32 @@ const LoadingBlock = ({ blockLayout , blockId , context , lowdefy , skeleton })
41
41
  // default to box when a skeleton block is not found - should be a basic or loader block.
42
42
  Component = lowdefy._internal.blockComponents.Box;
43
43
  }
44
- const layout = skeleton.layout || blockLayout || {};
45
44
  switch(Component.meta.category){
46
45
  case 'list':
47
- return(/*#__PURE__*/ React.createElement(LoadingList, {
46
+ return /*#__PURE__*/ React.createElement(LoadingList, {
48
47
  blockId: blockId,
49
48
  Component: Component,
50
49
  context: context,
51
- layout: layout,
52
50
  lowdefy: lowdefy,
53
51
  skeleton: skeleton
54
- }));
52
+ });
55
53
  case 'container':
56
- return(/*#__PURE__*/ React.createElement(LoadingContainer, {
54
+ return /*#__PURE__*/ React.createElement(LoadingContainer, {
57
55
  blockId: blockId,
56
+ blockLayout: blockLayout,
57
+ blockProperties: blockProperties,
58
+ blockStyle: blockStyle,
58
59
  Component: Component,
59
60
  context: context,
60
- layout: layout,
61
61
  lowdefy: lowdefy,
62
62
  skeleton: skeleton
63
- }));
63
+ });
64
64
  default:
65
- return(/*#__PURE__*/ React.createElement(BlockLayout, {
66
- blockStyle: skeleton.style,
65
+ return /*#__PURE__*/ React.createElement(BlockLayout, {
66
+ blockStyle: skeleton.style ?? blockStyle,
67
67
  highlightBorders: lowdefy.lowdefyGlobal.highlightBorders,
68
68
  id: `s-bl-${blockId}-${skeleton.id}`,
69
- layout: layout,
69
+ layout: skeleton.layout ?? blockLayout,
70
70
  makeCssClass: makeCssClass
71
71
  }, /*#__PURE__*/ React.createElement(Component, {
72
72
  basePath: lowdefy.basePath,
@@ -76,9 +76,8 @@ const LoadingBlock = ({ blockLayout , blockId , context , lowdefy , skeleton })
76
76
  menus: lowdefy.menus,
77
77
  methods: blockMethods,
78
78
  pageId: lowdefy.pageId,
79
- properties: skeleton.properties,
80
- user: lowdefy.user
81
- })));
79
+ properties: skeleton.properties ?? blockProperties
80
+ }));
82
81
  }
83
82
  };
84
83
  export default LoadingBlock;
@@ -16,15 +16,15 @@
16
16
  import { Area, BlockLayout, layoutParamsToArea } from '@lowdefy/layout';
17
17
  import { makeCssClass } from '@lowdefy/block-utils';
18
18
  import LoadingBlock from './LoadingBlock.js';
19
- const LoadingContainer = ({ blockId , Component , context , layout , lowdefy , skeleton })=>{
19
+ const LoadingContainer = ({ blockId , blockLayout , blockProperties , blockStyle , Component , context , lowdefy , skeleton , })=>{
20
20
  const content = {};
21
21
  // eslint-disable-next-line prefer-destructuring
22
22
  Object.keys(skeleton.areas).forEach((areaKey, i)=>{
23
23
  content[areaKey] = (areaStyle)=>/*#__PURE__*/ React.createElement(Area, {
24
24
  area: layoutParamsToArea({
25
- area: skeleton.areas[areaKey] || {},
25
+ area: skeleton.areas[areaKey],
26
26
  areaKey,
27
- layout
27
+ layout: skeleton.layout ?? blockLayout
28
28
  }),
29
29
  areaStyle: [
30
30
  areaStyle,
@@ -40,15 +40,13 @@ const LoadingContainer = ({ blockId , Component , context , layout , lowdefy , s
40
40
  key: `s-co-${skl.id}-${k}`,
41
41
  lowdefy: lowdefy,
42
42
  skeleton: skl
43
- })
44
- ))
45
- ;
43
+ })));
46
44
  });
47
- return(/*#__PURE__*/ React.createElement(BlockLayout, {
48
- blockStyle: skeleton.style,
45
+ return /*#__PURE__*/ React.createElement(BlockLayout, {
46
+ blockStyle: skeleton.style ?? blockStyle,
49
47
  highlightBorders: lowdefy.lowdefyGlobal.highlightBorders,
50
48
  id: `s-bl-${blockId}-${skeleton.id}`,
51
- layout: layout,
49
+ layout: skeleton.layout ?? blockLayout,
52
50
  makeCssClass: makeCssClass
53
51
  }, /*#__PURE__*/ React.createElement(Component, {
54
52
  basePath: lowdefy.basePath,
@@ -61,8 +59,7 @@ const LoadingContainer = ({ blockId , Component , context , layout , lowdefy , s
61
59
  makeCssClass
62
60
  },
63
61
  pageId: lowdefy.pageId,
64
- properties: skeleton.properties,
65
- user: lowdefy.user
66
- })));
62
+ properties: skeleton.properties ?? blockProperties
63
+ }));
67
64
  };
68
65
  export default LoadingContainer;
@@ -16,20 +16,20 @@
16
16
  import { Area, BlockLayout, layoutParamsToArea } from '@lowdefy/layout';
17
17
  import { makeCssClass } from '@lowdefy/block-utils';
18
18
  import LoadingBlock from './LoadingBlock.js';
19
- const LoadingList = ({ blockId , Component , context , layout , lowdefy , skeleton })=>{
19
+ const LoadingList = ({ blockId , blockLayout , blockProperties , blockStyle , Component , context , lowdefy , skeleton , })=>{
20
20
  const content = {};
21
21
  const contentList = [];
22
22
  new Array(3).forEach(()=>{
23
23
  Object.keys(skeleton.areas).forEach((areaKey, i)=>{
24
24
  content[areaKey] = (areaStyle)=>/*#__PURE__*/ React.createElement(Area, {
25
25
  area: layoutParamsToArea({
26
- area: skeleton.areas[areaKey] || {},
26
+ area: skeleton.areas[areaKey],
27
27
  areaKey,
28
- layout
28
+ layout: skeleton.layout ?? blockLayout
29
29
  }),
30
30
  areaStyle: [
31
31
  areaStyle,
32
- skeleton.areas[areaKey] && skeleton.areas[areaKey].style
32
+ skeleton.areas[areaKey]?.style
33
33
  ],
34
34
  highlightBorders: lowdefy.lowdefyGlobal.highlightBorders,
35
35
  id: `s-ar-${blockId}-${skeleton.id}-${areaKey}`,
@@ -41,19 +41,17 @@ const LoadingList = ({ blockId , Component , context , layout , lowdefy , skelet
41
41
  key: `s-co-${skl.id}-${k}`,
42
42
  lowdefy: lowdefy,
43
43
  skeleton: skl
44
- })
45
- ))
46
- ;
44
+ })));
47
45
  });
48
46
  contentList.push({
49
47
  ...content
50
48
  });
51
49
  });
52
- return(/*#__PURE__*/ React.createElement(BlockLayout, {
53
- blockStyle: skeleton.style,
50
+ return /*#__PURE__*/ React.createElement(BlockLayout, {
51
+ blockStyle: skeleton.style ?? blockStyle,
54
52
  highlightBorders: lowdefy.lowdefyGlobal.highlightBorders,
55
53
  id: `s-bl-${blockId}-${skeleton.id}`,
56
- layout: layout,
54
+ layout: skeleton.layout ?? blockLayout,
57
55
  makeCssClass: makeCssClass
58
56
  }, /*#__PURE__*/ React.createElement(Component, {
59
57
  basePath: lowdefy.basePath,
@@ -65,8 +63,7 @@ const LoadingList = ({ blockId , Component , context , layout , lowdefy , skelet
65
63
  makeCssClass
66
64
  },
67
65
  pageId: lowdefy.pageId,
68
- properties: skeleton.properties,
69
- user: lowdefy.user
70
- })));
66
+ properties: skeleton.properties ?? blockProperties
67
+ }));
71
68
  };
72
69
  export default LoadingList;
@@ -1,3 +1,17 @@
1
+ function _extends() {
2
+ _extends = Object.assign || function(target) {
3
+ for(var i = 1; i < arguments.length; i++){
4
+ var source = arguments[i];
5
+ for(var key in source){
6
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
7
+ target[key] = source[key];
8
+ }
9
+ }
10
+ }
11
+ return target;
12
+ };
13
+ return _extends.apply(this, arguments);
14
+ }
1
15
  /*
2
16
  Copyright 2020-2022 Lowdefy, Inc
3
17
 
@@ -18,20 +32,6 @@ import { omit, type } from '@lowdefy/helpers';
18
32
  import Icon from '@ant-design/icons';
19
33
  import { blockDefaultProps, makeCssClass } from '@lowdefy/block-utils';
20
34
  import ErrorBoundary from './ErrorBoundary.js';
21
- function _extends() {
22
- _extends = Object.assign || function(target) {
23
- for(var i = 1; i < arguments.length; i++){
24
- var source = arguments[i];
25
- for(var key in source){
26
- if (Object.prototype.hasOwnProperty.call(source, key)) {
27
- target[key] = source[key];
28
- }
29
- }
30
- }
31
- return target;
32
- };
33
- return _extends.apply(this, arguments);
34
- }
35
35
  const lowdefyProps = [
36
36
  'actionLog',
37
37
  'basePath',
@@ -45,7 +45,6 @@ const lowdefyProps = [
45
45
  'registerEvent',
46
46
  'registerMethod',
47
47
  'schemaErrors',
48
- 'user',
49
48
  'validation',
50
49
  ];
51
50
  const createIcon = (Icons)=>{
@@ -78,7 +77,7 @@ const createIcon = (Icons)=>{
78
77
  if (!IconComp) {
79
78
  IconComp = AiOutlineExclamationCircle;
80
79
  }
81
- return(/*#__PURE__*/ React.createElement(React.Fragment, null, spin ? /*#__PURE__*/ React.createElement(AiOutlineLoading3Quarters, _extends({}, iconProps)) : /*#__PURE__*/ React.createElement(ErrorBoundary, {
80
+ return /*#__PURE__*/ React.createElement(React.Fragment, null, spin ? /*#__PURE__*/ React.createElement(AiOutlineLoading3Quarters, _extends({}, iconProps)) : /*#__PURE__*/ React.createElement(ErrorBoundary, {
82
81
  fallback: ()=>/*#__PURE__*/ React.createElement(AiOutlineExclamationCircle, _extends({}, {
83
82
  ...iconProps,
84
83
  color: '#F00'
@@ -87,16 +86,14 @@ const createIcon = (Icons)=>{
87
86
  id: blockId,
88
87
  onClick: onClick || events.onClick && (()=>methods.triggerEvent({
89
88
  name: 'onClick'
90
- })
91
- ),
89
+ })),
92
90
  size: propertiesObj.size,
93
91
  title: propertiesObj.title
94
- }, iconProps)))));
92
+ }, iconProps))));
95
93
  };
96
94
  const AntIcon = (all)=>/*#__PURE__*/ React.createElement(Icon, {
97
95
  component: ()=>/*#__PURE__*/ React.createElement(IconBlock, _extends({}, all))
98
- })
99
- ;
96
+ });
100
97
  AntIcon.defaultProps = blockDefaultProps;
101
98
  return AntIcon;
102
99
  };
@@ -2,24 +2,23 @@ import React from 'react';
2
2
  import { createLink } from '@lowdefy/engine';
3
3
  import { type } from '@lowdefy/helpers';
4
4
  const createLinkComponent = (lowdefy, Link)=>{
5
+ const { window } = lowdefy._internal.globals;
5
6
  const backLink = ({ ariaLabel , children , className , id , rel })=>/*#__PURE__*/ React.createElement("a", {
6
7
  id: id,
7
- onClick: ()=>lowdefy._internal.router.back()
8
- ,
8
+ onClick: ()=>lowdefy._internal.router.back(),
9
9
  className: className,
10
10
  rel: rel,
11
11
  "aria-label": ariaLabel || 'back'
12
- }, type.isFunction(children) ? children(id) : children)
13
- ;
12
+ }, type.isFunction(children) ? children(id) : children);
14
13
  const newOriginLink = ({ ariaLabel , children , className , id , newTab , pageId , query , rel , url , })=>{
15
- return(/*#__PURE__*/ React.createElement("a", {
14
+ return /*#__PURE__*/ React.createElement("a", {
16
15
  id: id,
17
16
  "aria-label": ariaLabel,
18
17
  className: className,
19
18
  href: `${url}${query ? `?${query}` : ''}`,
20
19
  rel: rel || newTab && 'noopener noreferrer',
21
20
  target: newTab && '_blank'
22
- }, type.isFunction(children) ? children(pageId || url || id) : children));
21
+ }, type.isFunction(children) ? children(pageId || url || id) : children);
23
22
  };
24
23
  const sameOriginLink = ({ ariaLabel , children , className , id , newTab , pageId , pathname , query , rel , replace , scroll , setInput , url , })=>{
25
24
  if (newTab) {
@@ -33,7 +32,7 @@ const createLinkComponent = (lowdefy, Link)=>{
33
32
  target: "_blank"
34
33
  }, type.isFunction(children) ? children(pageId || url || id) : children));
35
34
  }
36
- return(/*#__PURE__*/ React.createElement(Link, {
35
+ return /*#__PURE__*/ React.createElement(Link, {
37
36
  href: {
38
37
  pathname,
39
38
  query
@@ -46,13 +45,12 @@ const createLinkComponent = (lowdefy, Link)=>{
46
45
  className: className,
47
46
  rel: rel,
48
47
  onClick: setInput
49
- }, type.isFunction(children) ? children(pageId || url || id) : children)));
48
+ }, type.isFunction(children) ? children(pageId || url || id) : children));
50
49
  };
51
50
  const noLink = ({ className , children , id })=>/*#__PURE__*/ React.createElement("span", {
52
51
  id: id,
53
52
  className: className
54
- }, type.isFunction(children) ? children(id) : children)
55
- ;
53
+ }, type.isFunction(children) ? children(id) : children);
56
54
  return createLink({
57
55
  backLink,
58
56
  lowdefy,
@@ -12,9 +12,9 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import { urlQuery } from '@lowdefy/helpers';
16
- import callRequest from './callRequest.js';
15
+ */ import callRequest from './callRequest.js';
17
16
  import createIcon from './createIcon.js';
17
+ import createAuthMethods from './auth/createAuthMethods.js';
18
18
  import createLinkComponent from './createLinkComponent.js';
19
19
  import setupLink from './setupLink.js';
20
20
  const lowdefy = {
@@ -24,11 +24,9 @@ const lowdefy = {
24
24
  updaters: {},
25
25
  displayMessage: ({ content })=>{
26
26
  console.log(content);
27
- return ()=>undefined
28
- ;
27
+ return ()=>undefined;
29
28
  },
30
- link: ()=>undefined
31
- ,
29
+ link: ()=>undefined,
32
30
  progress: {
33
31
  state: {
34
32
  progress: 0
@@ -40,7 +38,7 @@ const lowdefy = {
40
38
  inputs: {},
41
39
  lowdefyGlobal: {}
42
40
  };
43
- function initLowdefyContext({ Components , config , router , stage , types , window }) {
41
+ function initLowdefyContext({ auth , Components , config , router , stage , types , window }) {
44
42
  if (stage === 'dev') {
45
43
  window.lowdefy = lowdefy;
46
44
  }
@@ -49,18 +47,25 @@ function initLowdefyContext({ Components , config , router , stage , types , win
49
47
  lowdefy.lowdefyGlobal = config.rootConfig.lowdefyGlobal;
50
48
  lowdefy.menus = config.rootConfig.menus;
51
49
  lowdefy.pageId = config.pageConfig.pageId;
52
- lowdefy.urlQuery = urlQuery.parse(window.location.search.slice(1));
53
- lowdefy._internal.window = window;
54
- lowdefy._internal.document = window.document;
50
+ lowdefy.user = auth?.session?.user ?? null;
51
+ lowdefy._internal.globals = {
52
+ document: window.document,
53
+ fetch: window.fetch,
54
+ window
55
+ };
55
56
  lowdefy._internal.router = router;
56
57
  lowdefy._internal.link = setupLink(lowdefy);
57
- lowdefy._internal.updateBlock = (blockId)=>lowdefy._internal.updaters[blockId] && lowdefy._internal.updaters[blockId]()
58
- ;
58
+ lowdefy._internal.updateBlock = (blockId)=>lowdefy._internal.updaters[blockId] && lowdefy._internal.updaters[blockId]();
59
59
  lowdefy._internal.components.Link = createLinkComponent(lowdefy, Components.Link);
60
60
  lowdefy._internal.components.Icon = createIcon(types.icons);
61
61
  lowdefy._internal.actions = types.actions;
62
62
  lowdefy._internal.blockComponents = types.blocks;
63
63
  lowdefy._internal.operators = types.operators;
64
+ // TODO: discuss not using object arguments
65
+ lowdefy._internal.auth = createAuthMethods({
66
+ lowdefy,
67
+ auth
68
+ });
64
69
  return lowdefy;
65
70
  }
66
71
  export default initLowdefyContext;
package/dist/setupLink.js CHANGED
@@ -14,9 +14,9 @@
14
14
  limitations under the License.
15
15
  */ import { createLink } from '@lowdefy/engine';
16
16
  function setupLink(lowdefy) {
17
- const { router , window } = lowdefy._internal;
18
- const backLink = ()=>router.back()
19
- ;
17
+ const { router } = lowdefy._internal;
18
+ const { window } = lowdefy._internal.globals;
19
+ const backLink = ()=>router.back();
20
20
  const disabledLink = ()=>{};
21
21
  const newOriginLink = ({ url , query , newTab })=>{
22
22
  if (newTab) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/client",
3
- "version": "4.0.0-alpha.9",
3
+ "version": "4.0.0-rc.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy Client",
6
6
  "homepage": "https://lowdefy.com",
@@ -33,39 +33,39 @@
33
33
  "dist/*"
34
34
  ],
35
35
  "scripts": {
36
- "build": "yarn swc",
36
+ "build": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start && pnpm copyfiles",
37
37
  "clean": "rm -rf dist",
38
38
  "copyfiles": "copyfiles -u 1 \"./src/**/*\" dist -e \"./src/**/*.js\" -e \"./src/**/*.yaml\" -e \"./src/**/*.snap\"",
39
- "prepare": "yarn build",
40
- "swc": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start && yarn copyfiles",
39
+ "prepublishOnly": "pnpm build",
41
40
  "test:watch": "jest --coverage --watch",
42
41
  "test": "jest --coverage"
43
42
  },
44
43
  "dependencies": {
45
44
  "@ant-design/icons": "4.7.0",
46
- "@lowdefy/block-utils": "4.0.0-alpha.9",
47
- "@lowdefy/engine": "4.0.0-alpha.9",
48
- "@lowdefy/helpers": "4.0.0-alpha.9",
49
- "@lowdefy/layout": "4.0.0-alpha.9",
45
+ "@lowdefy/block-utils": "4.0.0-rc.0",
46
+ "@lowdefy/engine": "4.0.0-rc.0",
47
+ "@lowdefy/helpers": "4.0.0-rc.0",
48
+ "@lowdefy/layout": "4.0.0-rc.0",
50
49
  "classnames": "2.3.1",
51
- "react": "17.0.2",
52
- "react-dom": "17.0.2"
50
+ "react": "18.2.0",
51
+ "react-dom": "18.2.0"
53
52
  },
54
53
  "devDependencies": {
55
- "@emotion/jest": "11.7.1",
56
- "@swc/cli": "0.1.55",
57
- "@swc/core": "1.2.135",
58
- "@swc/jest": "0.2.17",
59
- "@testing-library/dom": "8.11.3",
60
- "@testing-library/react": "13.0.0-alpha.4",
61
- "@testing-library/user-event": "14.0.0-alpha.14",
54
+ "@emotion/jest": "11.9.1",
55
+ "@lowdefy/jest-yaml-transform": "4.0.0-rc.0",
56
+ "@swc/cli": "0.1.57",
57
+ "@swc/core": "1.2.194",
58
+ "@swc/jest": "0.2.21",
59
+ "@testing-library/dom": "8.13.0",
60
+ "@testing-library/react": "13.3.0",
61
+ "@testing-library/user-event": "14.2.0",
62
62
  "copyfiles": "2.4.1",
63
- "jest": "27.5.1",
64
- "jest-serializer-html": "7.1.0",
65
- "jest-transform-yaml": "1.0.0"
63
+ "jest": "28.1.0",
64
+ "jest-environment-jsdom": "28.1.0",
65
+ "jest-serializer-html": "7.1.0"
66
66
  },
67
67
  "publishConfig": {
68
68
  "access": "public"
69
69
  },
70
- "gitHead": "98b544eca231bdcfca6c3a8601a891835d5ce571"
70
+ "gitHead": "f6872d7ff6da421710096536fce7b2016ef8f35c"
71
71
  }