@developer_tribe/react-builder 1.2.0 → 1.2.2
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/hooks/useExtractTextStyle.d.ts +9 -0
- package/dist/hooks/useExtractViewStyle.d.ts +9 -0
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.native.cjs.js +1 -1
- package/dist/index.native.cjs.js.map +1 -1
- package/dist/index.native.d.ts +1 -0
- package/dist/index.native.esm.js +1 -1
- package/dist/index.native.esm.js.map +1 -1
- package/dist/pages/ProjectPage.d.ts +10 -3
- package/dist/types/Fonts.d.ts +5 -1
- package/dist/utils/extractTextStyle/extractTextStyle.d.ts +9 -0
- package/dist/utils/extractTextStyle.d.ts +2 -10
- package/dist/utils/extractViewStyle/extractViewStyle.d.ts +9 -0
- package/dist/utils/extractViewStyle.d.ts +2 -9
- package/package.json +1 -1
- package/src/build-components/BIcon/BIcon.tsx +5 -6
- package/src/build-components/BackgroundImage/BackgroundImage.tsx +2 -5
- package/src/build-components/Button/Button.tsx +20 -15
- package/src/build-components/Carousel/Carousel.tsx +5 -5
- package/src/build-components/CarouselButtons/CarouselButtons.tsx +3 -6
- package/src/build-components/CarouselDots/CarouselDots.tsx +3 -5
- package/src/build-components/CarouselItem/CarouselItem.tsx +3 -6
- package/src/build-components/CarouselProvider/CarouselProvider.tsx +2 -5
- package/src/build-components/Main/Main.tsx +5 -9
- package/src/build-components/OnboardButton/OnboardButton.tsx +5 -5
- package/src/build-components/OnboardButtons/OnboardButtons.tsx +6 -6
- package/src/build-components/OnboardDot/OnboardDot.tsx +8 -4
- package/src/build-components/OnboardFooter/OnboardFooter.tsx +10 -10
- package/src/build-components/OnboardImage/OnboardImage.tsx +6 -6
- package/src/build-components/OnboardItem/OnboardItem.tsx +5 -6
- package/src/build-components/OnboardProvider/OnboardProvider.tsx +13 -10
- package/src/build-components/PaywallBackground/PaywallBackground.tsx +2 -5
- package/src/build-components/PaywallCloseButton/PaywallCloseButton.tsx +5 -5
- package/src/build-components/PaywallOptions/PaywallOptionButton.tsx +2 -5
- package/src/build-components/PaywallProvider/PaywallProvider.tsx +5 -5
- package/src/build-components/PaywallSubscribeButton/PaywallSubscribeButton.tsx +5 -5
- package/src/build-components/RadioButton/RadioButton.tsx +5 -5
- package/src/build-components/Text/Text.tsx +2 -5
- package/src/build-components/View/View.tsx +3 -6
- package/src/hooks/useExtractTextStyle.ts +30 -0
- package/src/hooks/useExtractViewStyle.ts +28 -0
- package/src/index.native.ts +3 -0
- package/src/index.ts +2 -0
- package/src/pages/ProjectPage.tsx +15 -5
- package/src/types/Fonts.ts +5 -1
- package/src/utils/extractTextStyle/extractTextStyle.ts +160 -0
- package/src/utils/extractTextStyle.ts +2 -160
- package/src/utils/extractViewStyle/extractViewStyle.ts +145 -0
- package/src/utils/extractViewStyle.ts +2 -145
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { ViewPropsGenerated } from '../../build-components/View/ViewProps.generated';
|
|
2
|
+
import type { NodeData } from '../../types/Node';
|
|
3
|
+
import type { AppConfig } from '../../types/PreviewConfig';
|
|
4
|
+
import type { ProjectColors } from '../../types/Project';
|
|
5
|
+
import { parseSize } from '../../size-matters';
|
|
6
|
+
import { parseColor } from '../parseColor';
|
|
7
|
+
|
|
8
|
+
export type ExtractViewStyleOptions = {
|
|
9
|
+
appConfig?: AppConfig;
|
|
10
|
+
projectColors?: ProjectColors;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function extractViewStyle<T extends ViewPropsGenerated['attributes']>(
|
|
14
|
+
node: NodeData<T>,
|
|
15
|
+
options: ExtractViewStyleOptions = {},
|
|
16
|
+
) {
|
|
17
|
+
const attributes = node.attributes;
|
|
18
|
+
const styleBag = (attributes as any)?.style as
|
|
19
|
+
| Record<string, unknown>
|
|
20
|
+
| undefined;
|
|
21
|
+
const get = <K extends keyof ViewPropsGenerated['attributes']>(
|
|
22
|
+
key: K,
|
|
23
|
+
): ViewPropsGenerated['attributes'][K] | undefined => {
|
|
24
|
+
const direct = (attributes as any)?.[key];
|
|
25
|
+
if (direct !== undefined && direct !== null) return direct;
|
|
26
|
+
return styleBag?.[key as unknown as string] as any;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const scrollable = (get('scrollable') as any) ?? false;
|
|
30
|
+
const style: React.CSSProperties = {
|
|
31
|
+
display: 'flex',
|
|
32
|
+
flexDirection: 'column',
|
|
33
|
+
};
|
|
34
|
+
if (!attributes) return style;
|
|
35
|
+
const isEmptySizeValue = (value: unknown) =>
|
|
36
|
+
value === undefined ||
|
|
37
|
+
value === null ||
|
|
38
|
+
(typeof value === 'string' && value.trim() === '');
|
|
39
|
+
if (scrollable) {
|
|
40
|
+
// Important for flex children: allow the element to shrink so overflow scroll can work.
|
|
41
|
+
style.minWidth = 0;
|
|
42
|
+
style.minHeight = 0;
|
|
43
|
+
if (get('flexDirection') === 'row') {
|
|
44
|
+
style.overflowX = 'auto';
|
|
45
|
+
style.overflowY = 'hidden';
|
|
46
|
+
style.maxWidth = '100%';
|
|
47
|
+
style.maxHeight = '100%';
|
|
48
|
+
} else {
|
|
49
|
+
style.overflowY = 'auto';
|
|
50
|
+
style.overflowX = 'hidden';
|
|
51
|
+
style.maxHeight = '100%';
|
|
52
|
+
style.maxWidth = '100%';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const flexDirection = get('flexDirection');
|
|
56
|
+
if (flexDirection) style.flexDirection = flexDirection as any;
|
|
57
|
+
const alignItems = get('alignItems');
|
|
58
|
+
if (alignItems)
|
|
59
|
+
style.alignItems = alignItems as React.CSSProperties['alignItems'];
|
|
60
|
+
const justifyContent = get('justifyContent');
|
|
61
|
+
if (justifyContent)
|
|
62
|
+
style.justifyContent =
|
|
63
|
+
justifyContent as React.CSSProperties['justifyContent'];
|
|
64
|
+
const setParsedSize = <K extends keyof React.CSSProperties>(
|
|
65
|
+
property: K,
|
|
66
|
+
rawValue: string | number | undefined,
|
|
67
|
+
) => {
|
|
68
|
+
if (isEmptySizeValue(rawValue)) return;
|
|
69
|
+
const parsed = parseSize(rawValue);
|
|
70
|
+
style[property] = parsed as React.CSSProperties[K];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
setParsedSize('gap', get('gap') as any);
|
|
74
|
+
setParsedSize('padding', get('padding') as any);
|
|
75
|
+
setParsedSize('margin', get('margin') as any);
|
|
76
|
+
|
|
77
|
+
const paddingHorizontal = get('paddingHorizontal') as any;
|
|
78
|
+
if (!isEmptySizeValue(paddingHorizontal)) {
|
|
79
|
+
const parsed = parseSize(paddingHorizontal);
|
|
80
|
+
style.paddingLeft = parsed as React.CSSProperties['paddingLeft'];
|
|
81
|
+
style.paddingRight = parsed as React.CSSProperties['paddingRight'];
|
|
82
|
+
}
|
|
83
|
+
const paddingVertical = get('paddingVertical') as any;
|
|
84
|
+
if (!isEmptySizeValue(paddingVertical)) {
|
|
85
|
+
const parsed = parseSize(paddingVertical);
|
|
86
|
+
style.paddingTop = parsed as React.CSSProperties['paddingTop'];
|
|
87
|
+
style.paddingBottom = parsed as React.CSSProperties['paddingBottom'];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Explicit per-side paddings should override paddingHorizontal/paddingVertical.
|
|
91
|
+
setParsedSize('paddingTop', get('paddingTop') as any);
|
|
92
|
+
setParsedSize('paddingBottom', get('paddingBottom') as any);
|
|
93
|
+
setParsedSize('paddingLeft', get('paddingLeft') as any);
|
|
94
|
+
setParsedSize('paddingRight', get('paddingRight') as any);
|
|
95
|
+
|
|
96
|
+
const marginHorizontalRaw =
|
|
97
|
+
((attributes as Record<string, unknown>).marginHorizontal as
|
|
98
|
+
| string
|
|
99
|
+
| number
|
|
100
|
+
| undefined) ?? (styleBag?.marginHorizontal as any);
|
|
101
|
+
if (!isEmptySizeValue(marginHorizontalRaw)) {
|
|
102
|
+
const parsed = parseSize(marginHorizontalRaw);
|
|
103
|
+
style.marginLeft = parsed as React.CSSProperties['marginLeft'];
|
|
104
|
+
style.marginRight = parsed as React.CSSProperties['marginRight'];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const marginVertical = get('marginVertical') as any;
|
|
108
|
+
if (!isEmptySizeValue(marginVertical)) {
|
|
109
|
+
const parsed = parseSize(marginVertical);
|
|
110
|
+
style.marginTop = parsed as React.CSSProperties['marginTop'];
|
|
111
|
+
style.marginBottom = parsed as React.CSSProperties['marginBottom'];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setParsedSize('marginTop', get('marginTop') as any);
|
|
115
|
+
setParsedSize('marginBottom', get('marginBottom') as any);
|
|
116
|
+
setParsedSize('marginLeft', get('marginLeft') as any);
|
|
117
|
+
setParsedSize('marginRight', get('marginRight') as any);
|
|
118
|
+
const backgroundColor = get('backgroundColor') as any;
|
|
119
|
+
if (backgroundColor) {
|
|
120
|
+
style.backgroundColor =
|
|
121
|
+
parseColor(backgroundColor, {
|
|
122
|
+
projectColors: options.projectColors,
|
|
123
|
+
appConfig: options.appConfig,
|
|
124
|
+
}) ?? backgroundColor;
|
|
125
|
+
}
|
|
126
|
+
setParsedSize('borderRadius', get('borderRadius') as any);
|
|
127
|
+
setParsedSize('width', get('width') as any);
|
|
128
|
+
setParsedSize('minWidth', get('minWidth') as any);
|
|
129
|
+
setParsedSize('maxWidth', get('maxWidth') as any);
|
|
130
|
+
setParsedSize('height', get('height') as any);
|
|
131
|
+
setParsedSize('minHeight', get('minHeight') as any);
|
|
132
|
+
setParsedSize('maxHeight', get('maxHeight') as any);
|
|
133
|
+
const flex = get('flex') as any;
|
|
134
|
+
if (flex !== undefined) style.flex = flex as React.CSSProperties['flex'];
|
|
135
|
+
const position = get('position') as any;
|
|
136
|
+
if (position) style.position = position as React.CSSProperties['position'];
|
|
137
|
+
setParsedSize('top', get('top') as any);
|
|
138
|
+
setParsedSize('bottom', get('bottom') as any);
|
|
139
|
+
setParsedSize('left', get('left') as any);
|
|
140
|
+
setParsedSize('right', get('right') as any);
|
|
141
|
+
const zIndex = get('zIndex') as any;
|
|
142
|
+
if (zIndex !== undefined)
|
|
143
|
+
style.zIndex = zIndex as React.CSSProperties['zIndex'];
|
|
144
|
+
return style;
|
|
145
|
+
}
|
|
@@ -1,145 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { AppConfig } from '../types/PreviewConfig';
|
|
4
|
-
import type { ProjectColors } from '../types/Project';
|
|
5
|
-
import { parseSize } from '../size-matters';
|
|
6
|
-
import { parseColor } from './parseColor';
|
|
7
|
-
|
|
8
|
-
export type ExtractViewStyleOptions = {
|
|
9
|
-
appConfig?: AppConfig;
|
|
10
|
-
projectColors?: ProjectColors;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export function extractViewStyle<T extends ViewPropsGenerated['attributes']>(
|
|
14
|
-
node: NodeData<T>,
|
|
15
|
-
options: ExtractViewStyleOptions = {},
|
|
16
|
-
) {
|
|
17
|
-
const attributes = node.attributes;
|
|
18
|
-
const styleBag = (attributes as any)?.style as
|
|
19
|
-
| Record<string, unknown>
|
|
20
|
-
| undefined;
|
|
21
|
-
const get = <K extends keyof ViewPropsGenerated['attributes']>(
|
|
22
|
-
key: K,
|
|
23
|
-
): ViewPropsGenerated['attributes'][K] | undefined => {
|
|
24
|
-
const direct = (attributes as any)?.[key];
|
|
25
|
-
if (direct !== undefined && direct !== null) return direct;
|
|
26
|
-
return styleBag?.[key as unknown as string] as any;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const scrollable = (get('scrollable') as any) ?? false;
|
|
30
|
-
const style: React.CSSProperties = {
|
|
31
|
-
display: 'flex',
|
|
32
|
-
flexDirection: 'column',
|
|
33
|
-
};
|
|
34
|
-
if (!attributes) return style;
|
|
35
|
-
const isEmptySizeValue = (value: unknown) =>
|
|
36
|
-
value === undefined ||
|
|
37
|
-
value === null ||
|
|
38
|
-
(typeof value === 'string' && value.trim() === '');
|
|
39
|
-
if (scrollable) {
|
|
40
|
-
// Important for flex children: allow the element to shrink so overflow scroll can work.
|
|
41
|
-
style.minWidth = 0;
|
|
42
|
-
style.minHeight = 0;
|
|
43
|
-
if (get('flexDirection') === 'row') {
|
|
44
|
-
style.overflowX = 'auto';
|
|
45
|
-
style.overflowY = 'hidden';
|
|
46
|
-
style.maxWidth = '100%';
|
|
47
|
-
style.maxHeight = '100%';
|
|
48
|
-
} else {
|
|
49
|
-
style.overflowY = 'auto';
|
|
50
|
-
style.overflowX = 'hidden';
|
|
51
|
-
style.maxHeight = '100%';
|
|
52
|
-
style.maxWidth = '100%';
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const flexDirection = get('flexDirection');
|
|
56
|
-
if (flexDirection) style.flexDirection = flexDirection as any;
|
|
57
|
-
const alignItems = get('alignItems');
|
|
58
|
-
if (alignItems)
|
|
59
|
-
style.alignItems = alignItems as React.CSSProperties['alignItems'];
|
|
60
|
-
const justifyContent = get('justifyContent');
|
|
61
|
-
if (justifyContent)
|
|
62
|
-
style.justifyContent =
|
|
63
|
-
justifyContent as React.CSSProperties['justifyContent'];
|
|
64
|
-
const setParsedSize = <K extends keyof React.CSSProperties>(
|
|
65
|
-
property: K,
|
|
66
|
-
rawValue: string | number | undefined,
|
|
67
|
-
) => {
|
|
68
|
-
if (isEmptySizeValue(rawValue)) return;
|
|
69
|
-
const parsed = parseSize(rawValue);
|
|
70
|
-
style[property] = parsed as React.CSSProperties[K];
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
setParsedSize('gap', get('gap') as any);
|
|
74
|
-
setParsedSize('padding', get('padding') as any);
|
|
75
|
-
setParsedSize('margin', get('margin') as any);
|
|
76
|
-
|
|
77
|
-
const paddingHorizontal = get('paddingHorizontal') as any;
|
|
78
|
-
if (!isEmptySizeValue(paddingHorizontal)) {
|
|
79
|
-
const parsed = parseSize(paddingHorizontal);
|
|
80
|
-
style.paddingLeft = parsed as React.CSSProperties['paddingLeft'];
|
|
81
|
-
style.paddingRight = parsed as React.CSSProperties['paddingRight'];
|
|
82
|
-
}
|
|
83
|
-
const paddingVertical = get('paddingVertical') as any;
|
|
84
|
-
if (!isEmptySizeValue(paddingVertical)) {
|
|
85
|
-
const parsed = parseSize(paddingVertical);
|
|
86
|
-
style.paddingTop = parsed as React.CSSProperties['paddingTop'];
|
|
87
|
-
style.paddingBottom = parsed as React.CSSProperties['paddingBottom'];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Explicit per-side paddings should override paddingHorizontal/paddingVertical.
|
|
91
|
-
setParsedSize('paddingTop', get('paddingTop') as any);
|
|
92
|
-
setParsedSize('paddingBottom', get('paddingBottom') as any);
|
|
93
|
-
setParsedSize('paddingLeft', get('paddingLeft') as any);
|
|
94
|
-
setParsedSize('paddingRight', get('paddingRight') as any);
|
|
95
|
-
|
|
96
|
-
const marginHorizontalRaw =
|
|
97
|
-
((attributes as Record<string, unknown>).marginHorizontal as
|
|
98
|
-
| string
|
|
99
|
-
| number
|
|
100
|
-
| undefined) ?? (styleBag?.marginHorizontal as any);
|
|
101
|
-
if (!isEmptySizeValue(marginHorizontalRaw)) {
|
|
102
|
-
const parsed = parseSize(marginHorizontalRaw);
|
|
103
|
-
style.marginLeft = parsed as React.CSSProperties['marginLeft'];
|
|
104
|
-
style.marginRight = parsed as React.CSSProperties['marginRight'];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const marginVertical = get('marginVertical') as any;
|
|
108
|
-
if (!isEmptySizeValue(marginVertical)) {
|
|
109
|
-
const parsed = parseSize(marginVertical);
|
|
110
|
-
style.marginTop = parsed as React.CSSProperties['marginTop'];
|
|
111
|
-
style.marginBottom = parsed as React.CSSProperties['marginBottom'];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
setParsedSize('marginTop', get('marginTop') as any);
|
|
115
|
-
setParsedSize('marginBottom', get('marginBottom') as any);
|
|
116
|
-
setParsedSize('marginLeft', get('marginLeft') as any);
|
|
117
|
-
setParsedSize('marginRight', get('marginRight') as any);
|
|
118
|
-
const backgroundColor = get('backgroundColor') as any;
|
|
119
|
-
if (backgroundColor) {
|
|
120
|
-
style.backgroundColor =
|
|
121
|
-
parseColor(backgroundColor, {
|
|
122
|
-
projectColors: options.projectColors,
|
|
123
|
-
appConfig: options.appConfig,
|
|
124
|
-
}) ?? backgroundColor;
|
|
125
|
-
}
|
|
126
|
-
setParsedSize('borderRadius', get('borderRadius') as any);
|
|
127
|
-
setParsedSize('width', get('width') as any);
|
|
128
|
-
setParsedSize('minWidth', get('minWidth') as any);
|
|
129
|
-
setParsedSize('maxWidth', get('maxWidth') as any);
|
|
130
|
-
setParsedSize('height', get('height') as any);
|
|
131
|
-
setParsedSize('minHeight', get('minHeight') as any);
|
|
132
|
-
setParsedSize('maxHeight', get('maxHeight') as any);
|
|
133
|
-
const flex = get('flex') as any;
|
|
134
|
-
if (flex !== undefined) style.flex = flex as React.CSSProperties['flex'];
|
|
135
|
-
const position = get('position') as any;
|
|
136
|
-
if (position) style.position = position as React.CSSProperties['position'];
|
|
137
|
-
setParsedSize('top', get('top') as any);
|
|
138
|
-
setParsedSize('bottom', get('bottom') as any);
|
|
139
|
-
setParsedSize('left', get('left') as any);
|
|
140
|
-
setParsedSize('right', get('right') as any);
|
|
141
|
-
const zIndex = get('zIndex') as any;
|
|
142
|
-
if (zIndex !== undefined)
|
|
143
|
-
style.zIndex = zIndex as React.CSSProperties['zIndex'];
|
|
144
|
-
return style;
|
|
145
|
-
}
|
|
1
|
+
export type { ExtractViewStyleOptions } from './extractViewStyle/extractViewStyle';
|
|
2
|
+
export { extractViewStyle } from './extractViewStyle/extractViewStyle';
|