@lowdefy/client 5.0.0 → 5.2.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.
@@ -23,6 +23,7 @@ const Container = ({ block, Blocks, Component, context, loading, lowdefy })=>{
23
23
  // eslint-disable-next-line prefer-destructuring
24
24
  const slots = Blocks.subSlots[block.id][0].slots;
25
25
  Object.keys(slots).forEach((slotKey, i)=>{
26
+ if (slots[slotKey].blocks.length === 0) return;
26
27
  content[slotKey] = (contentStyle)=>/*#__PURE__*/ React.createElement(Area, {
27
28
  area: block.eval.slots[slotKey],
28
29
  areaKey: slotKey,
@@ -23,6 +23,7 @@ const InputContainer = ({ block, Blocks, Component, context, loading, lowdefy })
23
23
  // eslint-disable-next-line prefer-destructuring
24
24
  const slots = Blocks.subSlots[block.id][0].slots;
25
25
  Object.keys(slots).forEach((slotKey, i)=>{
26
+ if (slots[slotKey].blocks.length === 0) return;
26
27
  content[slotKey] = (contentStyle)=>/*#__PURE__*/ React.createElement(Area, {
27
28
  area: block.eval.slots[slotKey],
28
29
  areaKey: slotKey,
@@ -15,6 +15,7 @@
15
15
  */ import React from 'react';
16
16
  import { Area, BlockLayout } from '@lowdefy/layout';
17
17
  import { cn } from '@lowdefy/block-utils';
18
+ import { get } from '@lowdefy/helpers';
18
19
  import Block from './Block.js';
19
20
  import resolveClassNames from './resolveClassNames.js';
20
21
  const List = ({ block, Blocks, Component, context, loading, lowdefy })=>{
@@ -23,6 +24,7 @@ const List = ({ block, Blocks, Component, context, loading, lowdefy })=>{
23
24
  const contentList = [];
24
25
  Blocks.subSlots[block.id].forEach((SBlock)=>{
25
26
  Object.keys(SBlock.slots).forEach((slotKey)=>{
27
+ if (SBlock.slots[slotKey].blocks.length === 0) return;
26
28
  content[slotKey] = (contentStyle)=>/*#__PURE__*/ React.createElement(Area, {
27
29
  area: block.eval.slots[slotKey],
28
30
  areaKey: slotKey,
@@ -70,6 +72,7 @@ const List = ({ block, Blocks, Component, context, loading, lowdefy })=>{
70
72
  events: block.eval.events ?? {},
71
73
  key: block.blockId,
72
74
  list: contentList,
75
+ value: get(context.state, block.blockId) ?? [],
73
76
  loading: loading,
74
77
  menus: lowdefy.menus,
75
78
  pageId: lowdefy.pageId,
@@ -3,9 +3,10 @@ import { createLink } from '@lowdefy/engine';
3
3
  import { type } from '@lowdefy/helpers';
4
4
  const createLinkComponent = (lowdefy, Link)=>{
5
5
  const { window } = lowdefy._internal.globals;
6
- const backLink = ({ ariaLabel, children, className, id, onClick = ()=>{}, rel })=>/*#__PURE__*/ React.createElement("a", {
6
+ const backLink = ({ ariaLabel, children, className, id, onClick = ()=>{}, rel, style })=>/*#__PURE__*/ React.createElement("a", {
7
7
  id: id,
8
8
  className: className,
9
+ style: style,
9
10
  rel: rel,
10
11
  "aria-label": ariaLabel ?? 'back',
11
12
  onClick: (...params)=>{
@@ -13,11 +14,12 @@ const createLinkComponent = (lowdefy, Link)=>{
13
14
  onClick(...params);
14
15
  }
15
16
  }, type.isFunction(children) ? children(id) : children);
16
- const newOriginLink = ({ ariaLabel, children, className, href, id, onClick = ()=>{}, newTab, pageId, query, rel, url })=>{
17
+ const newOriginLink = ({ ariaLabel, children, className, href, id, onClick = ()=>{}, newTab, pageId, query, rel, style, url })=>{
17
18
  return /*#__PURE__*/ React.createElement("a", {
18
19
  id: id,
19
20
  "aria-label": ariaLabel,
20
21
  className: className,
22
+ style: style,
21
23
  href: href ?? `${url}${query ? `?${query}` : ''}`,
22
24
  rel: rel ?? (newTab && 'noopener noreferrer'),
23
25
  target: newTab && '_blank',
@@ -27,13 +29,14 @@ const createLinkComponent = (lowdefy, Link)=>{
27
29
  }
28
30
  }, type.isFunction(children) ? children(pageId ?? url ?? id) : children);
29
31
  };
30
- const sameOriginLink = ({ ariaLabel, children, className, id, newTab, onClick = ()=>{}, pageId, pathname, query, rel, replace, scroll, setInput, url })=>{
32
+ const sameOriginLink = ({ ariaLabel, children, className, id, newTab, onClick = ()=>{}, pageId, pathname, query, rel, replace, scroll, setInput, style, url })=>{
31
33
  if (newTab) {
32
34
  return(// eslint-disable-next-line react/jsx-no-target-blank
33
35
  /*#__PURE__*/ React.createElement("a", {
34
36
  id: id,
35
37
  "aria-label": ariaLabel,
36
38
  className: className,
39
+ style: style,
37
40
  href: `${window.location.origin}${lowdefy.basePath}${pathname}${query ? `?${query}` : ''}`,
38
41
  rel: rel ?? 'noopener noreferrer',
39
42
  target: "_blank",
@@ -54,6 +57,7 @@ const createLinkComponent = (lowdefy, Link)=>{
54
57
  id: id,
55
58
  "aria-label": ariaLabel,
56
59
  className: className,
60
+ style: style,
57
61
  rel: rel,
58
62
  onClick: (...params)=>{
59
63
  setInput();
@@ -61,9 +65,10 @@ const createLinkComponent = (lowdefy, Link)=>{
61
65
  }
62
66
  }, type.isFunction(children) ? children(pageId ?? url ?? id) : children));
63
67
  };
64
- const noLink = ({ className, children, id, onClick = ()=>{} })=>/*#__PURE__*/ React.createElement("span", {
68
+ const noLink = ({ className, children, id, onClick = ()=>{}, style })=>/*#__PURE__*/ React.createElement("span", {
65
69
  id: id,
66
70
  className: className,
71
+ style: style,
67
72
  onClick: onClick
68
73
  }, type.isFunction(children) ? children(id) : children);
69
74
  return createLink({
@@ -0,0 +1,31 @@
1
+ /*
2
+ Copyright 2020-2026 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
+ */ // Create a container element for antd's CSS-in-JS injection that is positioned
16
+ // AFTER the @layer order declaration in <head>. Without this, antd's StyleProvider
17
+ // prepends <style> tags to the top of <head>, placing them before the @layer
18
+ // declaration and breaking the cascade layer priority (antd becomes lowest instead
19
+ // of overriding Tailwind's preflight).
20
+ function getOrCreateAntdCssContainer() {
21
+ if (typeof document === 'undefined') return undefined;
22
+ const existing = document.getElementById('__antd-css-container');
23
+ if (existing) return existing;
24
+ const anchor = document.getElementById('__lf-layer-order');
25
+ if (!anchor) return undefined;
26
+ const container = document.createElement('div');
27
+ container.id = '__antd-css-container';
28
+ anchor.after(container);
29
+ return container;
30
+ }
31
+ export default getOrCreateAntdCssContainer;
package/dist/index.js CHANGED
@@ -14,4 +14,5 @@
14
14
  limitations under the License.
15
15
  */ import Client from './Client.js';
16
16
  export default Client;
17
+ export { default as getOrCreateAntdCssContainer } from './getOrCreateAntdCssContainer.js';
17
18
  export { default as useDarkMode } from './useDarkMode.js';
@@ -12,7 +12,7 @@
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 { useCallback, useEffect, useState } from 'react';
15
+ */ import { useCallback, useEffect, useMemo, useState } from 'react';
16
16
  import { theme as antdTheme } from 'antd';
17
17
  const algorithmMap = {
18
18
  default: antdTheme.defaultAlgorithm,
@@ -52,7 +52,23 @@ function resolveIsDark({ configDarkMode, userPreference, systemIsDark }) {
52
52
  // userPreference is 'system' — follow OS
53
53
  return systemIsDark;
54
54
  }
55
- function useDarkMode({ baseAlgorithm, configDarkMode }) {
55
+ function mergeComponents(shared, mode) {
56
+ if (!shared && !mode) return undefined;
57
+ const keys = new Set([
58
+ ...Object.keys(shared ?? {}),
59
+ ...Object.keys(mode ?? {})
60
+ ]);
61
+ const merged = {};
62
+ keys.forEach((name)=>{
63
+ merged[name] = {
64
+ ...(shared ?? {})[name] ?? {},
65
+ ...(mode ?? {})[name] ?? {}
66
+ };
67
+ });
68
+ return merged;
69
+ }
70
+ function useDarkMode({ antd, configDarkMode }) {
71
+ const baseAlgorithm = antd?.algorithm;
56
72
  const cleanAlgorithm = stripDarkFromAlgorithm(baseAlgorithm);
57
73
  const [userPreference, setUserPreference] = useState(()=>{
58
74
  return window.localStorage?.getItem('lowdefy_darkMode') ?? 'system';
@@ -79,6 +95,53 @@ function useDarkMode({ baseAlgorithm, configDarkMode }) {
79
95
  systemIsDark
80
96
  });
81
97
  window.__lowdefy_isDark = isDark;
82
- return resolveAlgorithm(mergeAlgorithm(cleanAlgorithm, isDark));
98
+ const sharedToken = antd?.token;
99
+ const lightToken = antd?.lightToken;
100
+ const darkToken = antd?.darkToken;
101
+ const sharedComponents = antd?.components;
102
+ const lightComponents = antd?.lightComponents;
103
+ const darkComponents = antd?.darkComponents;
104
+ const token = useMemo(()=>{
105
+ const modeToken = isDark ? darkToken : lightToken;
106
+ if (!sharedToken && !modeToken) return undefined;
107
+ return {
108
+ ...sharedToken ?? {},
109
+ ...modeToken ?? {}
110
+ };
111
+ }, [
112
+ isDark,
113
+ sharedToken,
114
+ lightToken,
115
+ darkToken
116
+ ]);
117
+ const components = useMemo(()=>mergeComponents(sharedComponents, isDark ? darkComponents : lightComponents), [
118
+ isDark,
119
+ sharedComponents,
120
+ lightComponents,
121
+ darkComponents
122
+ ]);
123
+ // Keep the <html> background in sync with the resolved mode. The _document.js
124
+ // inline script sets an initial background before hydration; this effect takes
125
+ // over once React is active and updates on every dark/light toggle.
126
+ const darkBg = darkToken?.colorBgLayout;
127
+ const lightBg = lightToken?.colorBgLayout;
128
+ useEffect(()=>{
129
+ if (isDark) {
130
+ document.documentElement.style.backgroundColor = darkBg ?? '#000';
131
+ } else if (lightBg) {
132
+ document.documentElement.style.backgroundColor = lightBg;
133
+ } else {
134
+ document.documentElement.style.removeProperty('background-color');
135
+ }
136
+ }, [
137
+ isDark,
138
+ darkBg,
139
+ lightBg
140
+ ]);
141
+ return {
142
+ algorithm: resolveAlgorithm(mergeAlgorithm(cleanAlgorithm, isDark)),
143
+ token,
144
+ components
145
+ };
83
146
  }
84
147
  export default useDarkMode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/client",
3
- "version": "5.0.0",
3
+ "version": "5.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy Client",
6
6
  "homepage": "https://lowdefy.com",
@@ -35,19 +35,19 @@
35
35
  "dependencies": {
36
36
  "@ant-design/icons": "6.1.0",
37
37
  "antd": "6.3.1",
38
- "@lowdefy/block-utils": "5.0.0",
39
- "@lowdefy/engine": "5.0.0",
40
- "@lowdefy/errors": "5.0.0",
41
- "@lowdefy/helpers": "5.0.0",
42
- "@lowdefy/layout": "5.0.0",
43
- "@lowdefy/logger": "5.0.0",
38
+ "@lowdefy/block-utils": "5.2.0",
39
+ "@lowdefy/engine": "5.2.0",
40
+ "@lowdefy/errors": "5.2.0",
41
+ "@lowdefy/helpers": "5.2.0",
42
+ "@lowdefy/layout": "5.2.0",
43
+ "@lowdefy/logger": "5.2.0",
44
44
  "react": "18.2.0",
45
45
  "react-dom": "18.2.0",
46
46
  "tinykeys": "^3.0.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@jest/globals": "28.1.3",
50
- "@lowdefy/jest-yaml-transform": "5.0.0",
50
+ "@lowdefy/jest-yaml-transform": "5.2.0",
51
51
  "@swc/cli": "0.8.0",
52
52
  "@swc/core": "1.15.18",
53
53
  "@swc/jest": "0.2.39",