@developer_tribe/react-builder 1.0.3 → 1.0.4
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/android.svg +43 -0
- package/dist/apple.svg +16 -0
- package/dist/attributes-editor/Field.d.ts +2 -1
- package/dist/attributes-editor/SizeField.d.ts +9 -0
- package/dist/build-components/BackgroundImage/BackgroundImageProps.generated.d.ts +1 -0
- package/dist/build-components/Button/ButtonProps.generated.d.ts +1 -0
- package/dist/build-components/Carousel/CarouselProps.generated.d.ts +1 -0
- package/dist/build-components/CarouselButtons/CarouselButtonsProps.generated.d.ts +1 -0
- package/dist/build-components/CarouselDots/CarouselDotsProps.generated.d.ts +1 -0
- package/dist/build-components/CarouselItem/CarouselItemProps.generated.d.ts +1 -0
- package/dist/build-components/CarouselProvider/CarouselProviderProps.generated.d.ts +1 -0
- package/dist/build-components/Image/ImageProps.generated.d.ts +1 -0
- package/dist/build-components/Onboard/OnboardProps.generated.d.ts +1 -0
- package/dist/build-components/OnboardButton/OnboardButtonProps.generated.d.ts +1 -1
- package/dist/build-components/OnboardButtons/OnboardButtonsProps.generated.d.ts +1 -0
- package/dist/build-components/OnboardDot/OnboardDotProps.generated.d.ts +2 -3
- package/dist/build-components/OnboardFooter/OnboardFooterProps.generated.d.ts +1 -0
- package/dist/build-components/OnboardImage/OnboardImageProps.generated.d.ts +2 -1
- package/dist/build-components/OnboardItem/OnboardItemProps.generated.d.ts +1 -0
- package/dist/build-components/OnboardProvider/OnboardProviderProps.generated.d.ts +1 -0
- package/dist/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.d.ts +1 -0
- package/dist/build-components/OnboardTitle/OnboardTitleProps.generated.d.ts +1 -0
- package/dist/build-components/Text/TextProps.generated.d.ts +1 -0
- package/dist/build-components/View/ViewProps.generated.d.ts +1 -0
- package/dist/build-components/patterns.generated.d.ts +194 -57
- package/dist/components/JsonTextEditor.d.ts +9 -0
- package/dist/index.cjs.js +5 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +5 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/pages/tabs/SideTool.d.ts +2 -1
- package/dist/store.d.ts +2 -0
- package/dist/styles.css +1 -1
- package/dist/utils/extractImageStyle.d.ts +2 -1
- package/dist/utils/extractViewStyle.d.ts +1 -2
- package/dist/utils/selection.d.ts +7 -0
- package/dist/utils/useMergedStyle.d.ts +2 -0
- package/package.json +2 -5
- package/src/.DS_Store +0 -0
- package/src/AttributesEditor.tsx +7 -2
- package/src/RenderPage.tsx +10 -6
- package/src/attributes-editor/Field.tsx +48 -160
- package/src/attributes-editor/SizeField.tsx +184 -0
- package/src/attributes-editor/SpecialCategorySection.tsx +10 -3
- package/src/build-components/BackgroundImage/BackgroundImage.tsx +7 -17
- package/src/build-components/BackgroundImage/BackgroundImageProps.generated.ts +1 -0
- package/src/build-components/Button/Button.tsx +7 -9
- package/src/build-components/Button/ButtonProps.generated.ts +1 -0
- package/src/build-components/Carousel/Carousel.tsx +7 -9
- package/src/build-components/Carousel/CarouselProps.generated.ts +1 -0
- package/src/build-components/CarouselButtons/CarouselButtonsProps.generated.ts +1 -0
- package/src/build-components/CarouselDots/CarouselDotsProps.generated.ts +1 -0
- package/src/build-components/CarouselItem/CarouselItemProps.generated.ts +1 -0
- package/src/build-components/CarouselProvider/CarouselProviderProps.generated.ts +1 -0
- package/src/build-components/Image/Image.tsx +11 -18
- package/src/build-components/Image/ImageProps.generated.ts +1 -0
- package/src/build-components/Image/pattern.json +1 -9
- package/src/build-components/Onboard/OnboardProps.generated.ts +1 -0
- package/src/build-components/OnboardButton/OnboardButton.tsx +0 -3
- package/src/build-components/OnboardButton/OnboardButtonProps.generated.ts +1 -1
- package/src/build-components/OnboardButtons/OnboardButtonsProps.generated.ts +1 -0
- package/src/build-components/OnboardDot/OnboardDot.tsx +59 -39
- package/src/build-components/OnboardDot/OnboardDotProps.generated.ts +2 -3
- package/src/build-components/OnboardDot/pattern.json +2 -18
- package/src/build-components/OnboardFooter/OnboardFooter.tsx +28 -15
- package/src/build-components/OnboardFooter/OnboardFooterProps.generated.ts +1 -0
- package/src/build-components/OnboardImage/OnboardImageProps.generated.ts +2 -1
- package/src/build-components/OnboardItem/OnboardItem.tsx +1 -11
- package/src/build-components/OnboardItem/OnboardItemProps.generated.ts +1 -0
- package/src/build-components/OnboardProvider/OnboardProvider.tsx +1 -8
- package/src/build-components/OnboardProvider/OnboardProviderProps.generated.ts +1 -0
- package/src/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.ts +1 -0
- package/src/build-components/OnboardTitle/OnboardTitleProps.generated.ts +1 -0
- package/src/build-components/Text/Text.tsx +9 -15
- package/src/build-components/Text/TextProps.generated.ts +1 -0
- package/src/build-components/View/View.tsx +7 -9
- package/src/build-components/View/ViewProps.generated.ts +1 -0
- package/src/build-components/View/pattern.json +9 -1
- package/src/build-components/patterns.generated.ts +194 -57
- package/src/components/Builder.tsx +61 -17
- package/src/components/DeviceNavigationBar.tsx +0 -1
- package/src/components/EditorHeader.tsx +11 -1
- package/src/components/JsonTextEditor.tsx +185 -0
- package/src/mockOS/components/MockOSRouter.tsx +6 -0
- package/src/mockOS/context/MockOSContext.tsx +0 -5
- package/src/mockOS/managers/mockPermissionManager.ts +0 -4
- package/src/mockOS/managers/navigationManager.ts +1 -6
- package/src/modals/ColorModal.tsx +103 -25
- package/src/modals/LocalicationModal.tsx +4 -5
- package/src/modals/Modal.tsx +8 -1
- package/src/pages/ProjectPage.tsx +7 -1
- package/src/pages/tabs/SideTool.tsx +10 -9
- package/src/store.ts +5 -0
- package/src/styles/base/_global.scss +5 -0
- package/src/styles/components/_editor-shell.scss +4 -2
- package/src/styles/modals/_color-modal.scss +30 -1
- package/src/styles/utilities/_carousel.scss +9 -8
- package/src/utils/extractImageStyle.ts +3 -6
- package/src/utils/extractTextStyle.ts +2 -81
- package/src/utils/extractViewStyle.ts +20 -15
- package/src/utils/selection.ts +24 -0
- package/src/utils/useMergedStyle.ts +16 -0
package/src/modals/Modal.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
2
3
|
|
|
3
4
|
type ModalProps = {
|
|
4
5
|
onClose: () => void;
|
|
@@ -33,7 +34,7 @@ export function Modal({
|
|
|
33
34
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
34
35
|
}, [closeOnEsc, onClose]);
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
const modalNode = (
|
|
37
38
|
<div
|
|
38
39
|
className={`modal${className ? ` ${className}` : ''}`}
|
|
39
40
|
role="dialog"
|
|
@@ -52,6 +53,12 @@ export function Modal({
|
|
|
52
53
|
</div>
|
|
53
54
|
</div>
|
|
54
55
|
);
|
|
56
|
+
|
|
57
|
+
if (typeof document === 'undefined') {
|
|
58
|
+
return modalNode;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return createPortal(modalNode, document.body);
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
export default Modal;
|
|
@@ -46,8 +46,14 @@ export function ProjectPage({
|
|
|
46
46
|
|
|
47
47
|
const handleDeleteNode = useCallback(
|
|
48
48
|
(nodeToDelete: Node) => {
|
|
49
|
-
//
|
|
49
|
+
// Extra warning for deleting the root node (editorData)
|
|
50
50
|
if (nodeToDelete === editorData) {
|
|
51
|
+
const shouldDeleteRoot = window.confirm(
|
|
52
|
+
'You are about to delete the root component. This will clear the entire screen. Continue?',
|
|
53
|
+
);
|
|
54
|
+
if (!shouldDeleteRoot) return;
|
|
55
|
+
setEditorData(null);
|
|
56
|
+
setCurrent(null);
|
|
51
57
|
return;
|
|
52
58
|
}
|
|
53
59
|
const updated: Node = deleteNodeFromTree(editorData, nodeToDelete);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { JsonTextEditor } from '../../components/JsonTextEditor';
|
|
3
3
|
import { Modal } from '../../modals';
|
|
4
4
|
import { Localication, Node } from '../..';
|
|
5
5
|
import { useLogRender } from '../../utils/useLogRender';
|
|
6
6
|
import { useRenderStore } from '../../store';
|
|
7
7
|
import { Checkbox } from '../../components/Checkbox';
|
|
8
8
|
import { LocalicationModal } from '../../modals/LocalicationModal';
|
|
9
|
+
import { analyseAndProccess } from '../../utils/analyseNode';
|
|
9
10
|
|
|
10
11
|
const screenStyleDefaults = {
|
|
11
12
|
light: { backgroundColor: '#FDFDFD', color: '#161827' },
|
|
@@ -17,7 +18,7 @@ type ScreenColorKey = keyof (typeof screenStyleDefaults)['light'];
|
|
|
17
18
|
|
|
18
19
|
type SideToolProps = {
|
|
19
20
|
data: Node;
|
|
20
|
-
setData:
|
|
21
|
+
setData: React.Dispatch<React.SetStateAction<Node>>;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
const colorFields = [
|
|
@@ -114,7 +115,6 @@ export function SideTool({ data, setData }: SideToolProps) {
|
|
|
114
115
|
display: 'flex',
|
|
115
116
|
flexDirection: 'column',
|
|
116
117
|
gap: 8,
|
|
117
|
-
backgroundColor: isCompactMode ? '#fff' : undefined,
|
|
118
118
|
}}
|
|
119
119
|
>
|
|
120
120
|
<button
|
|
@@ -128,7 +128,7 @@ export function SideTool({ data, setData }: SideToolProps) {
|
|
|
128
128
|
</button>
|
|
129
129
|
|
|
130
130
|
{isCompactPanelVisible && (
|
|
131
|
-
<div className="side-tool"
|
|
131
|
+
<div className="side-tool">
|
|
132
132
|
<select
|
|
133
133
|
value={appConfig.defaultLanguage ?? 'en'}
|
|
134
134
|
onChange={(e) =>
|
|
@@ -233,12 +233,13 @@ export function SideTool({ data, setData }: SideToolProps) {
|
|
|
233
233
|
</div>
|
|
234
234
|
<div className="localication-modal__body">
|
|
235
235
|
<div className="localication-modal__editor">
|
|
236
|
-
<
|
|
237
|
-
rootName="
|
|
238
|
-
|
|
239
|
-
|
|
236
|
+
<JsonTextEditor
|
|
237
|
+
rootName="node"
|
|
238
|
+
value={data ?? {}}
|
|
239
|
+
onChange={(next) =>
|
|
240
|
+
setData(analyseAndProccess(next as Node) as Node)
|
|
241
|
+
}
|
|
240
242
|
className="localication-modal__json-editor"
|
|
241
|
-
maxWidth="100%"
|
|
242
243
|
/>
|
|
243
244
|
</div>
|
|
244
245
|
</div>
|
package/src/store.ts
CHANGED
|
@@ -17,6 +17,8 @@ type RenderStore = {
|
|
|
17
17
|
setCopiedNode: (node: Node | null) => void;
|
|
18
18
|
current: Node | null;
|
|
19
19
|
setCurrent: (node: Node | null) => void;
|
|
20
|
+
forceRender: number;
|
|
21
|
+
incForceRender: () => void;
|
|
20
22
|
device: Device;
|
|
21
23
|
setDevice: (device: Device) => void;
|
|
22
24
|
appConfig: AppConfig;
|
|
@@ -44,6 +46,9 @@ export const useRenderStore = createWithEqualityFn<RenderStore>()(
|
|
|
44
46
|
setCopiedNode: (node) => set({ copiedNode: node }),
|
|
45
47
|
current: null,
|
|
46
48
|
setCurrent: (node) => set({ current: node }),
|
|
49
|
+
forceRender: 0,
|
|
50
|
+
incForceRender: () =>
|
|
51
|
+
set((state) => ({ forceRender: state.forceRender + 1 })),
|
|
47
52
|
device: getDefaultDevice(),
|
|
48
53
|
setDevice: (device) => set({ device }),
|
|
49
54
|
appConfig: defaultAppConfig,
|
|
@@ -191,12 +191,14 @@
|
|
|
191
191
|
.side-tool {
|
|
192
192
|
display: flex;
|
|
193
193
|
flex-direction: column;
|
|
194
|
+
height: 100%;
|
|
195
|
+
max-width: 220px;
|
|
194
196
|
gap: sizes.$spaceTight;
|
|
195
197
|
padding: sizes.$spaceTight;
|
|
196
198
|
border-radius: 4px;
|
|
197
199
|
border: 1px solid colors.$borderColor;
|
|
198
|
-
font-size:
|
|
199
|
-
|
|
200
|
+
font-size: 11xpx;
|
|
201
|
+
background: #fff;
|
|
200
202
|
}
|
|
201
203
|
|
|
202
204
|
.side-tool select {
|
|
@@ -83,6 +83,24 @@
|
|
|
83
83
|
padding: 4px 8px;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
.color-modal__add-color {
|
|
87
|
+
position: relative;
|
|
88
|
+
display: inline-flex;
|
|
89
|
+
align-items: center;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.color-modal__add-color-input {
|
|
93
|
+
position: absolute;
|
|
94
|
+
inset: 0;
|
|
95
|
+
opacity: 0;
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
width: 100%;
|
|
98
|
+
height: 100%;
|
|
99
|
+
border: 0;
|
|
100
|
+
padding: 0;
|
|
101
|
+
margin: 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
86
104
|
.color-section {
|
|
87
105
|
display: flex;
|
|
88
106
|
flex-direction: column;
|
|
@@ -155,5 +173,16 @@
|
|
|
155
173
|
}
|
|
156
174
|
|
|
157
175
|
.color-modal__input {
|
|
158
|
-
|
|
176
|
+
// Keep the input in the DOM so browsers allow opening the native color picker
|
|
177
|
+
// via user gesture (programmatic click/showPicker), but visually hide it.
|
|
178
|
+
position: absolute;
|
|
179
|
+
width: 1px;
|
|
180
|
+
height: 1px;
|
|
181
|
+
padding: 0;
|
|
182
|
+
margin: -1px;
|
|
183
|
+
overflow: hidden;
|
|
184
|
+
clip: rect(0 0 0 0);
|
|
185
|
+
white-space: nowrap;
|
|
186
|
+
border: 0;
|
|
187
|
+
opacity: 0;
|
|
159
188
|
}
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
.embla__container {
|
|
13
13
|
display: flex;
|
|
14
14
|
touch-action: pan-y pinch-zoom;
|
|
15
|
-
margin-left: calc(var(--slide-spacing) * -1);
|
|
16
15
|
}
|
|
17
16
|
.embla__slide {
|
|
18
17
|
transform: translate3d(0, 0, 0);
|
|
@@ -84,6 +83,7 @@
|
|
|
84
83
|
-webkit-appearance: none;
|
|
85
84
|
appearance: none;
|
|
86
85
|
background-color: transparent;
|
|
86
|
+
--embla-dot-color: var(--detail-medium-contrast);
|
|
87
87
|
touch-action: manipulation;
|
|
88
88
|
display: inline-flex;
|
|
89
89
|
text-decoration: none;
|
|
@@ -91,23 +91,24 @@
|
|
|
91
91
|
border: 0;
|
|
92
92
|
padding: 0;
|
|
93
93
|
margin: 0;
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
/* Keep a reasonable hit-area, but allow bigger dots to grow it. */
|
|
95
|
+
width: max(2.6rem, calc(var(--embla-dot-size, 1.4rem) + 1.2rem));
|
|
96
|
+
height: max(2.6rem, calc(var(--embla-dot-size, 1.4rem) + 1.2rem));
|
|
96
97
|
display: flex;
|
|
97
98
|
align-items: center;
|
|
98
99
|
border-radius: 50%;
|
|
99
100
|
}
|
|
100
101
|
.embla__dot:after {
|
|
101
|
-
|
|
102
|
-
width: 1.4rem;
|
|
103
|
-
height: 1.4rem;
|
|
102
|
+
background-color: var(--embla-dot-color);
|
|
103
|
+
width: var(--embla-dot-size, 1.4rem);
|
|
104
|
+
height: var(--embla-dot-size, 1.4rem);
|
|
104
105
|
border-radius: 50%;
|
|
105
106
|
display: flex;
|
|
106
107
|
align-items: center;
|
|
107
108
|
content: '';
|
|
108
109
|
}
|
|
109
|
-
.embla__dot--selected
|
|
110
|
-
|
|
110
|
+
.embla__dot--selected {
|
|
111
|
+
--embla-dot-color: var(--text-body);
|
|
111
112
|
}
|
|
112
113
|
.carousel-provider {
|
|
113
114
|
height: 100%;
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import { ImagePropsGenerated } from '../build-components/Image/ImageProps.generated';
|
|
2
2
|
import type { NodeData } from '../types/Node';
|
|
3
|
+
import { extractViewStyle, ExtractViewStyleOptions } from './extractViewStyle';
|
|
3
4
|
|
|
4
5
|
export function extractImageStyle<T extends ImagePropsGenerated['attributes']>(
|
|
5
6
|
node: NodeData<T>,
|
|
7
|
+
options: ExtractViewStyleOptions = {},
|
|
6
8
|
) {
|
|
7
9
|
const attributes = node.attributes;
|
|
8
10
|
const style: React.CSSProperties = {};
|
|
9
11
|
|
|
10
12
|
if (!attributes) return style;
|
|
11
13
|
|
|
12
|
-
if (attributes.width !== undefined) style.width = attributes.width;
|
|
13
|
-
if (attributes.height !== undefined) style.height = attributes.height;
|
|
14
|
-
if (attributes.borderRadius !== undefined)
|
|
15
|
-
style.borderRadius = attributes.borderRadius;
|
|
16
|
-
|
|
17
14
|
// Map resizeMode to CSS object-fit
|
|
18
15
|
if (attributes.resizeMode === 'cover') style.objectFit = 'cover';
|
|
19
16
|
else if (attributes.resizeMode === 'contain') style.objectFit = 'contain';
|
|
20
17
|
else if (attributes.resizeMode === 'stretch') style.objectFit = 'fill';
|
|
21
18
|
else if (attributes.resizeMode === 'center') style.objectFit = 'none';
|
|
22
19
|
|
|
23
|
-
return style;
|
|
20
|
+
return { ...extractViewStyle(node, options), ...style };
|
|
24
21
|
}
|
|
@@ -5,6 +5,7 @@ import { defaultAppConfig } from '../types/PreviewConfig';
|
|
|
5
5
|
import type { ProjectColors } from '../types/Project';
|
|
6
6
|
import { fs, parseSize } from '../size-matters';
|
|
7
7
|
import { parseColor } from './parseColor';
|
|
8
|
+
import { extractViewStyle } from './extractViewStyle';
|
|
8
9
|
|
|
9
10
|
type ExtractTextStyleOptions = {
|
|
10
11
|
appConfig?: AppConfig;
|
|
@@ -45,85 +46,5 @@ export function extractTextStyle<T extends TextPropsGenerated['attributes']>(
|
|
|
45
46
|
if (attributes.textAlign)
|
|
46
47
|
style.textAlign = attributes.textAlign as React.CSSProperties['textAlign'];
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
// Shorthand
|
|
50
|
-
if (attributes.padding !== undefined) style.padding = attributes.padding;
|
|
51
|
-
if (attributes.margin !== undefined) style.margin = attributes.margin;
|
|
52
|
-
|
|
53
|
-
// Axis shorthands
|
|
54
|
-
if (attributes.paddingHorizontal !== undefined) {
|
|
55
|
-
const v = parseSize(attributes.paddingHorizontal);
|
|
56
|
-
style.paddingLeft = v as React.CSSProperties['paddingLeft'];
|
|
57
|
-
style.paddingRight = v as React.CSSProperties['paddingRight'];
|
|
58
|
-
}
|
|
59
|
-
if (attributes.paddingVertical !== undefined) {
|
|
60
|
-
const v = parseSize(attributes.paddingVertical);
|
|
61
|
-
style.paddingTop = v as React.CSSProperties['paddingTop'];
|
|
62
|
-
style.paddingBottom = v as React.CSSProperties['paddingBottom'];
|
|
63
|
-
}
|
|
64
|
-
const marginHorizontalRaw = (attributes as Record<string, unknown>)
|
|
65
|
-
.marginHorizontal as string | number | undefined;
|
|
66
|
-
if (marginHorizontalRaw !== undefined) {
|
|
67
|
-
const v = parseSize(marginHorizontalRaw);
|
|
68
|
-
style.marginLeft = v as React.CSSProperties['marginLeft'];
|
|
69
|
-
style.marginRight = v as React.CSSProperties['marginRight'];
|
|
70
|
-
}
|
|
71
|
-
if (attributes.marginVertical !== undefined) {
|
|
72
|
-
const v = parseSize(attributes.marginVertical);
|
|
73
|
-
style.marginTop = v as React.CSSProperties['marginTop'];
|
|
74
|
-
style.marginBottom = v as React.CSSProperties['marginBottom'];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Edges
|
|
78
|
-
if (attributes.paddingTop !== undefined)
|
|
79
|
-
style.paddingTop = parseSize(
|
|
80
|
-
attributes.paddingTop,
|
|
81
|
-
) as React.CSSProperties['paddingTop'];
|
|
82
|
-
if (attributes.paddingBottom !== undefined)
|
|
83
|
-
style.paddingBottom = parseSize(
|
|
84
|
-
attributes.paddingBottom,
|
|
85
|
-
) as React.CSSProperties['paddingBottom'];
|
|
86
|
-
if (attributes.paddingLeft !== undefined)
|
|
87
|
-
style.paddingLeft = parseSize(
|
|
88
|
-
attributes.paddingLeft,
|
|
89
|
-
) as React.CSSProperties['paddingLeft'];
|
|
90
|
-
if (attributes.paddingRight !== undefined)
|
|
91
|
-
style.paddingRight = parseSize(
|
|
92
|
-
attributes.paddingRight,
|
|
93
|
-
) as React.CSSProperties['paddingRight'];
|
|
94
|
-
|
|
95
|
-
if (attributes.marginTop !== undefined)
|
|
96
|
-
style.marginTop = parseSize(
|
|
97
|
-
attributes.marginTop,
|
|
98
|
-
) as React.CSSProperties['marginTop'];
|
|
99
|
-
if (attributes.marginBottom !== undefined)
|
|
100
|
-
style.marginBottom = parseSize(
|
|
101
|
-
attributes.marginBottom,
|
|
102
|
-
) as React.CSSProperties['marginBottom'];
|
|
103
|
-
if (attributes.marginLeft !== undefined)
|
|
104
|
-
style.marginLeft = parseSize(
|
|
105
|
-
attributes.marginLeft,
|
|
106
|
-
) as React.CSSProperties['marginLeft'];
|
|
107
|
-
if (attributes.marginRight !== undefined)
|
|
108
|
-
style.marginRight = parseSize(
|
|
109
|
-
attributes.marginRight,
|
|
110
|
-
) as React.CSSProperties['marginRight'];
|
|
111
|
-
|
|
112
|
-
// Decor
|
|
113
|
-
if (attributes.backgroundColor) {
|
|
114
|
-
style.backgroundColor =
|
|
115
|
-
parseColor(attributes.backgroundColor, {
|
|
116
|
-
projectColors: options.projectColors,
|
|
117
|
-
appConfig: resolvedAppConfig,
|
|
118
|
-
}) ?? attributes.backgroundColor;
|
|
119
|
-
}
|
|
120
|
-
if (attributes.borderRadius !== undefined)
|
|
121
|
-
style.borderRadius =
|
|
122
|
-
attributes.borderRadius as React.CSSProperties['borderRadius'];
|
|
123
|
-
|
|
124
|
-
// Dimensions (rare for text but supported by schema)
|
|
125
|
-
if (attributes.width !== undefined) style.width = attributes.width;
|
|
126
|
-
if (attributes.height !== undefined) style.height = attributes.height;
|
|
127
|
-
|
|
128
|
-
return style;
|
|
49
|
+
return { ...extractViewStyle(node, options), ...style };
|
|
129
50
|
}
|
|
@@ -5,7 +5,7 @@ import type { ProjectColors } from '../types/Project';
|
|
|
5
5
|
import { parseSize } from '../size-matters';
|
|
6
6
|
import { parseColor } from './parseColor';
|
|
7
7
|
|
|
8
|
-
type ExtractViewStyleOptions = {
|
|
8
|
+
export type ExtractViewStyleOptions = {
|
|
9
9
|
appConfig?: AppConfig;
|
|
10
10
|
projectColors?: ProjectColors;
|
|
11
11
|
};
|
|
@@ -21,6 +21,10 @@ export function extractViewStyle<T extends ViewPropsGenerated['attributes']>(
|
|
|
21
21
|
flexDirection: 'column',
|
|
22
22
|
};
|
|
23
23
|
if (!attributes) return style;
|
|
24
|
+
const isEmptySizeValue = (value: unknown) =>
|
|
25
|
+
value === undefined ||
|
|
26
|
+
value === null ||
|
|
27
|
+
(typeof value === 'string' && value.trim() === '');
|
|
24
28
|
if (scrollable) {
|
|
25
29
|
if (attributes.flexDirection === 'row') {
|
|
26
30
|
style.overflowX = 'auto';
|
|
@@ -45,7 +49,7 @@ export function extractViewStyle<T extends ViewPropsGenerated['attributes']>(
|
|
|
45
49
|
property: K,
|
|
46
50
|
rawValue: string | number | undefined,
|
|
47
51
|
) => {
|
|
48
|
-
if (rawValue
|
|
52
|
+
if (isEmptySizeValue(rawValue)) return;
|
|
49
53
|
const parsed = parseSize(rawValue);
|
|
50
54
|
style[property] = parsed as React.CSSProperties[K];
|
|
51
55
|
};
|
|
@@ -54,44 +58,41 @@ export function extractViewStyle<T extends ViewPropsGenerated['attributes']>(
|
|
|
54
58
|
setParsedSize('padding', attributes.padding);
|
|
55
59
|
setParsedSize('margin', attributes.margin);
|
|
56
60
|
|
|
57
|
-
if (attributes.paddingHorizontal
|
|
61
|
+
if (!isEmptySizeValue(attributes.paddingHorizontal)) {
|
|
58
62
|
const parsed = parseSize(attributes.paddingHorizontal);
|
|
59
63
|
style.paddingLeft = parsed as React.CSSProperties['paddingLeft'];
|
|
60
64
|
style.paddingRight = parsed as React.CSSProperties['paddingRight'];
|
|
61
65
|
}
|
|
62
|
-
if (attributes.paddingVertical
|
|
66
|
+
if (!isEmptySizeValue(attributes.paddingVertical)) {
|
|
63
67
|
const parsed = parseSize(attributes.paddingVertical);
|
|
64
68
|
style.paddingTop = parsed as React.CSSProperties['paddingTop'];
|
|
65
69
|
style.paddingBottom = parsed as React.CSSProperties['paddingBottom'];
|
|
66
70
|
}
|
|
67
71
|
|
|
72
|
+
// Explicit per-side paddings should override paddingHorizontal/paddingVertical.
|
|
73
|
+
setParsedSize('paddingTop', attributes.paddingTop);
|
|
74
|
+
setParsedSize('paddingBottom', attributes.paddingBottom);
|
|
75
|
+
setParsedSize('paddingLeft', attributes.paddingLeft);
|
|
76
|
+
setParsedSize('paddingRight', attributes.paddingRight);
|
|
77
|
+
|
|
68
78
|
const marginHorizontalRaw = (attributes as Record<string, unknown>)
|
|
69
79
|
.marginHorizontal as string | number | undefined;
|
|
70
|
-
if (marginHorizontalRaw
|
|
80
|
+
if (!isEmptySizeValue(marginHorizontalRaw)) {
|
|
71
81
|
const parsed = parseSize(marginHorizontalRaw);
|
|
72
82
|
style.marginLeft = parsed as React.CSSProperties['marginLeft'];
|
|
73
83
|
style.marginRight = parsed as React.CSSProperties['marginRight'];
|
|
74
84
|
}
|
|
75
85
|
|
|
76
|
-
if (attributes.marginVertical
|
|
86
|
+
if (!isEmptySizeValue(attributes.marginVertical)) {
|
|
77
87
|
const parsed = parseSize(attributes.marginVertical);
|
|
78
88
|
style.marginTop = parsed as React.CSSProperties['marginTop'];
|
|
79
89
|
style.marginBottom = parsed as React.CSSProperties['marginBottom'];
|
|
80
90
|
}
|
|
81
91
|
|
|
82
|
-
setParsedSize('paddingTop', attributes.paddingTop);
|
|
83
|
-
setParsedSize('paddingBottom', attributes.paddingBottom);
|
|
84
|
-
setParsedSize('paddingLeft', attributes.paddingLeft);
|
|
85
|
-
setParsedSize('paddingRight', attributes.paddingRight);
|
|
86
92
|
setParsedSize('marginTop', attributes.marginTop);
|
|
87
93
|
setParsedSize('marginBottom', attributes.marginBottom);
|
|
88
94
|
setParsedSize('marginLeft', attributes.marginLeft);
|
|
89
95
|
setParsedSize('marginRight', attributes.marginRight);
|
|
90
|
-
console.log('attributes.backgroundColor', attributes.backgroundColor);
|
|
91
|
-
console.log(
|
|
92
|
-
'parseColor(attributes.backgroundColor)',
|
|
93
|
-
parseColor(attributes.backgroundColor),
|
|
94
|
-
);
|
|
95
96
|
if (attributes.backgroundColor) {
|
|
96
97
|
style.backgroundColor =
|
|
97
98
|
parseColor(attributes.backgroundColor, {
|
|
@@ -102,11 +103,15 @@ export function extractViewStyle<T extends ViewPropsGenerated['attributes']>(
|
|
|
102
103
|
setParsedSize('borderRadius', attributes.borderRadius);
|
|
103
104
|
setParsedSize('width', attributes.width);
|
|
104
105
|
setParsedSize('height', attributes.height);
|
|
106
|
+
if (attributes.flex !== undefined)
|
|
107
|
+
style.flex = attributes.flex as React.CSSProperties['flex'];
|
|
105
108
|
if (attributes.position)
|
|
106
109
|
style.position = attributes.position as React.CSSProperties['position'];
|
|
107
110
|
setParsedSize('top', attributes.top);
|
|
108
111
|
setParsedSize('bottom', attributes.bottom);
|
|
109
112
|
setParsedSize('left', attributes.left);
|
|
110
113
|
setParsedSize('right', attributes.right);
|
|
114
|
+
if (attributes.zIndex !== undefined)
|
|
115
|
+
style.zIndex = attributes.zIndex as React.CSSProperties['zIndex'];
|
|
111
116
|
return style;
|
|
112
117
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
|
|
3
|
+
export const SELECTED_OUTLINE_STYLE: CSSProperties = {
|
|
4
|
+
outline: '2px solid #2684FF',
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
function getNodeKey(value: unknown): string | undefined {
|
|
8
|
+
if (!value || typeof value !== 'object') return undefined;
|
|
9
|
+
if (!('key' in value)) return undefined;
|
|
10
|
+
const key = (value as { key?: unknown }).key;
|
|
11
|
+
return typeof key === 'string' ? key : undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function isNodeSelected(args: {
|
|
15
|
+
previewMode: boolean;
|
|
16
|
+
current?: unknown;
|
|
17
|
+
node?: unknown;
|
|
18
|
+
}): boolean {
|
|
19
|
+
const currentKey = getNodeKey(args.current);
|
|
20
|
+
const nodeKey = getNodeKey(args.node);
|
|
21
|
+
return (
|
|
22
|
+
!!args.previewMode && !!currentKey && !!nodeKey && currentKey === nodeKey
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
const EMPTY_STYLE: CSSProperties = {};
|
|
5
|
+
|
|
6
|
+
export function useMergedStyle(
|
|
7
|
+
base?: CSSProperties,
|
|
8
|
+
override?: CSSProperties,
|
|
9
|
+
): CSSProperties {
|
|
10
|
+
return useMemo(() => {
|
|
11
|
+
if (!base && !override) return EMPTY_STYLE;
|
|
12
|
+
if (!override) return base ?? EMPTY_STYLE;
|
|
13
|
+
if (!base) return override;
|
|
14
|
+
return { ...base, ...override };
|
|
15
|
+
}, [base, override]);
|
|
16
|
+
}
|