@lowdefy/client 4.0.0-alpha.14 → 4.0.0-alpha.17

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.
@@ -14,12 +14,13 @@
14
14
  limitations under the License.
15
15
  */ import { type, urlQuery as urlQueryFn } from '@lowdefy/helpers';
16
16
  function getCallbackUrl({ lowdefy , callbackUrl ={} }) {
17
- const { home , pageId , urlQuery } = callbackUrl;
17
+ const { home , pageId , urlQuery , url } = callbackUrl;
18
18
  if ([
19
19
  !home,
20
- !pageId
20
+ !pageId,
21
+ !url
21
22
  ].filter((v)=>!v).length > 1) {
22
- throw Error(`Invalid Link: To avoid ambiguity, only one of 'home' or 'pageId' can be defined.`);
23
+ throw Error(`Invalid Link: To avoid ambiguity, only one of 'home', 'pageId' or 'url' can be defined.`);
23
24
  }
24
25
  const query = type.isNone(urlQuery) ? '' : `${urlQueryFn.stringify(urlQuery)}`;
25
26
  if (home === true) {
@@ -28,12 +29,15 @@ function getCallbackUrl({ lowdefy , callbackUrl ={} }) {
28
29
  if (type.isString(pageId)) {
29
30
  return `/${pageId}${query ? `?${query}` : ''}`;
30
31
  }
32
+ if (type.isString(url)) {
33
+ return `${url}${query ? `?${query}` : ''}`;
34
+ }
31
35
  return undefined;
32
36
  }
33
37
  function createAuthMethods({ lowdefy , auth }) {
34
38
  // login and logout are Lowdefy function that handle action params
35
39
  // signIn and signOut are the next-auth methods
36
- function login({ providerId , callbackUrl , authUrl ={} } = {}) {
40
+ function login({ authUrl , callbackUrl , providerId } = {}) {
37
41
  if (type.isNone(providerId) && auth.authConfig.providers.length === 1) {
38
42
  providerId = auth.authConfig.providers[0].id;
39
43
  }
@@ -42,11 +46,16 @@ function createAuthMethods({ lowdefy , auth }) {
42
46
  lowdefy,
43
47
  callbackUrl
44
48
  })
45
- }, authUrl.urlQuery);
49
+ }, authUrl?.urlQuery);
46
50
  }
47
- // TODO: fix callbackUrl
48
- function logout() {
49
- auth.signOut();
51
+ function logout({ callbackUrl , redirect } = {}) {
52
+ auth.signOut({
53
+ callbackUrl: getCallbackUrl({
54
+ lowdefy,
55
+ callbackUrl
56
+ }),
57
+ redirect
58
+ });
50
59
  }
51
60
  return {
52
61
  login,
@@ -31,6 +31,8 @@ const CategorySwitch = ({ block , Blocks , context , loading , lowdefy })=>{
31
31
  if (loading && type.isObject(block.eval.skeleton)) {
32
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
@@ -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
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
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
65
  return /*#__PURE__*/ React.createElement(BlockLayout, {
66
- blockStyle: skeleton.style,
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,7 +76,7 @@ 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
79
+ properties: skeleton.properties ?? blockProperties
80
80
  }));
81
81
  }
82
82
  };
@@ -16,7 +16,7 @@
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)=>{
@@ -24,7 +24,7 @@ const LoadingContainer = ({ blockId , Component , context , layout , lowdefy , s
24
24
  area: layoutParamsToArea({
25
25
  area: skeleton.areas[areaKey] || {},
26
26
  areaKey,
27
- layout
27
+ layout: skeleton.layout ?? blockLayout
28
28
  }),
29
29
  areaStyle: [
30
30
  areaStyle,
@@ -43,10 +43,10 @@ const LoadingContainer = ({ blockId , Component , context , layout , lowdefy , s
43
43
  })));
44
44
  });
45
45
  return /*#__PURE__*/ React.createElement(BlockLayout, {
46
- blockStyle: skeleton.style,
46
+ blockStyle: skeleton.style ?? blockStyle,
47
47
  highlightBorders: lowdefy.lowdefyGlobal.highlightBorders,
48
48
  id: `s-bl-${blockId}-${skeleton.id}`,
49
- layout: layout,
49
+ layout: skeleton.layout ?? blockLayout,
50
50
  makeCssClass: makeCssClass
51
51
  }, /*#__PURE__*/ React.createElement(Component, {
52
52
  basePath: lowdefy.basePath,
@@ -59,7 +59,7 @@ const LoadingContainer = ({ blockId , Component , context , layout , lowdefy , s
59
59
  makeCssClass
60
60
  },
61
61
  pageId: lowdefy.pageId,
62
- properties: skeleton.properties
62
+ properties: skeleton.properties ?? blockProperties
63
63
  }));
64
64
  };
65
65
  export default LoadingContainer;
@@ -16,16 +16,16 @@
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,
@@ -48,10 +48,10 @@ const LoadingList = ({ blockId , Component , context , layout , lowdefy , skelet
48
48
  });
49
49
  });
50
50
  return /*#__PURE__*/ React.createElement(BlockLayout, {
51
- blockStyle: skeleton.style,
51
+ blockStyle: skeleton.style ?? blockStyle,
52
52
  highlightBorders: lowdefy.lowdefyGlobal.highlightBorders,
53
53
  id: `s-bl-${blockId}-${skeleton.id}`,
54
- layout: layout,
54
+ layout: skeleton.layout ?? blockLayout,
55
55
  makeCssClass: makeCssClass
56
56
  }, /*#__PURE__*/ React.createElement(Component, {
57
57
  basePath: lowdefy.basePath,
@@ -63,7 +63,7 @@ const LoadingList = ({ blockId , Component , context , layout , lowdefy , skelet
63
63
  makeCssClass
64
64
  },
65
65
  pageId: lowdefy.pageId,
66
- properties: skeleton.properties
66
+ properties: skeleton.properties ?? blockProperties
67
67
  }));
68
68
  };
69
69
  export default LoadingList;
@@ -2,6 +2,7 @@ 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
8
  onClick: ()=>lowdefy._internal.router.back(),
@@ -50,8 +50,11 @@ function initLowdefyContext({ auth , Components , config , router , stage , type
50
50
  lowdefy.pageId = config.pageConfig.pageId;
51
51
  lowdefy.urlQuery = urlQuery.parse(window.location.search.slice(1));
52
52
  lowdefy.user = auth?.session?.user ?? null;
53
- lowdefy._internal.window = window;
54
- lowdefy._internal.document = window.document;
53
+ lowdefy._internal.globals = {
54
+ document: window.document,
55
+ fetch: window.fetch,
56
+ window
57
+ };
55
58
  lowdefy._internal.router = router;
56
59
  lowdefy._internal.link = setupLink(lowdefy);
57
60
  lowdefy._internal.updateBlock = (blockId)=>lowdefy._internal.updaters[blockId] && lowdefy._internal.updaters[blockId]();
package/dist/setupLink.js CHANGED
@@ -14,7 +14,8 @@
14
14
  limitations under the License.
15
15
  */ import { createLink } from '@lowdefy/engine';
16
16
  function setupLink(lowdefy) {
17
- const { router , window } = lowdefy._internal;
17
+ const { router } = lowdefy._internal;
18
+ const { window } = lowdefy._internal.globals;
18
19
  const backLink = ()=>router.back();
19
20
  const disabledLink = ()=>{};
20
21
  const newOriginLink = ({ url , query , newTab })=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/client",
3
- "version": "4.0.0-alpha.14",
3
+ "version": "4.0.0-alpha.17",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy Client",
6
6
  "homepage": "https://lowdefy.com",
@@ -43,17 +43,17 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@ant-design/icons": "4.7.0",
46
- "@lowdefy/block-utils": "4.0.0-alpha.14",
47
- "@lowdefy/engine": "4.0.0-alpha.14",
48
- "@lowdefy/helpers": "4.0.0-alpha.14",
49
- "@lowdefy/layout": "4.0.0-alpha.14",
46
+ "@lowdefy/block-utils": "4.0.0-alpha.17",
47
+ "@lowdefy/engine": "4.0.0-alpha.17",
48
+ "@lowdefy/helpers": "4.0.0-alpha.17",
49
+ "@lowdefy/layout": "4.0.0-alpha.17",
50
50
  "classnames": "2.3.1",
51
51
  "react": "18.1.0",
52
52
  "react-dom": "18.1.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@emotion/jest": "11.9.1",
56
- "@lowdefy/jest-yaml-transform": "4.0.0-alpha.14",
56
+ "@lowdefy/jest-yaml-transform": "4.0.0-alpha.17",
57
57
  "@swc/cli": "0.1.57",
58
58
  "@swc/core": "1.2.194",
59
59
  "@swc/jest": "0.2.21",
@@ -68,5 +68,5 @@
68
68
  "publishConfig": {
69
69
  "access": "public"
70
70
  },
71
- "gitHead": "9cc0b7280c82a16689c31aaf71be278f3a40edc6"
71
+ "gitHead": "9172974b2fe19c527d3f0ea66b8dbde827ac9c0e"
72
72
  }