@developer_tribe/react-builder 0.1.32 → 1.0.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/DeviceMockFrame.d.ts +2 -17
- package/dist/RenderPage.d.ts +4 -11
- package/dist/attributes-editor/Field.d.ts +16 -0
- package/dist/attributes-editor/FieldInfoTooltip.d.ts +7 -0
- package/dist/attributes-editor/LayoutPreviewPicker.d.ts +12 -0
- package/dist/attributes-editor/SpecialCategorySection.d.ts +19 -0
- package/dist/attributes-editor/types.d.ts +14 -0
- package/dist/background.jpg +0 -0
- package/dist/build-components/Button/Button.d.ts +1 -1
- package/dist/build-components/Button/ButtonProps.generated.d.ts +26 -1
- package/dist/build-components/Carousel/CarouselProps.generated.d.ts +27 -1
- package/dist/build-components/CarouselButtons/CarouselButtonsProps.generated.d.ts +25 -0
- package/dist/build-components/CarouselDots/CarouselDotsProps.generated.d.ts +25 -0
- package/dist/build-components/CarouselItem/CarouselItemProps.generated.d.ts +27 -1
- package/dist/build-components/CarouselProvider/CarouselProviderProps.generated.d.ts +27 -1
- package/dist/build-components/Image/ImageProps.generated.d.ts +25 -3
- package/dist/build-components/Onboard/OnboardProps.generated.d.ts +27 -1
- package/dist/build-components/OnboardButton/OnboardButtonProps.generated.d.ts +25 -0
- package/dist/build-components/OnboardButtons/OnboardButtonsProps.generated.d.ts +25 -0
- package/dist/build-components/OnboardDot/OnboardDot.d.ts +1 -1
- package/dist/build-components/OnboardDot/OnboardDotProps.generated.d.ts +22 -0
- package/dist/build-components/OnboardFooter/OnboardFooterProps.generated.d.ts +4 -5
- package/dist/build-components/OnboardImage/OnboardImageProps.generated.d.ts +25 -3
- package/dist/build-components/OnboardItem/OnboardItemProps.generated.d.ts +24 -3
- package/dist/build-components/OnboardProvider/OnboardProviderProps.generated.d.ts +25 -4
- package/dist/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.d.ts +4 -5
- package/dist/build-components/OnboardTitle/OnboardTitleProps.generated.d.ts +4 -5
- package/dist/build-components/Text/TextProps.generated.d.ts +4 -5
- package/dist/build-components/View/ViewProps.generated.d.ts +3 -4
- package/dist/build-components/index.d.ts +1 -0
- package/dist/build-components/patterns.generated.d.ts +4855 -132
- package/dist/components/AttributesEditorPanel.d.ts +9 -0
- package/dist/components/Breadcrumb.d.ts +15 -0
- package/dist/components/Builder.d.ts +9 -0
- package/dist/components/Checkbox.d.ts +17 -0
- package/dist/components/DeviceButton.d.ts +8 -0
- package/dist/components/DeviceNavigationBar.d.ts +10 -0
- package/dist/components/DeviceStatusBar.d.ts +9 -0
- package/dist/components/EditorHeader.d.ts +10 -0
- package/dist/index.cjs.js +6 -5
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.esm.js +6 -5
- package/dist/index.esm.js.map +1 -0
- package/dist/mockOS/components/MockLaunchScreenComponent.d.ts +6 -0
- package/dist/mockOS/components/MockOSRouter.d.ts +8 -0
- package/dist/mockOS/components/PermissionModal.d.ts +9 -0
- package/dist/mockOS/context/MockOSContext.d.ts +36 -0
- package/dist/mockOS/hooks/useMockNavigation.d.ts +3 -0
- package/dist/mockOS/hooks/useMockPermission.d.ts +3 -0
- package/dist/mockOS/index.d.ts +9 -0
- package/dist/mockOS/managers/mockPermissionManager.d.ts +10 -0
- package/dist/mockOS/managers/navigationManager.d.ts +17 -0
- package/dist/modals/AddComponentModal.d.ts +8 -0
- package/dist/modals/ColorModal.d.ts +9 -0
- package/dist/modals/DeviceSelectorModal.d.ts +9 -0
- package/dist/modals/LocalicationModal.d.ts +8 -0
- package/dist/modals/Modal.d.ts +12 -0
- package/dist/modals/index.d.ts +5 -0
- package/dist/pages/ProjectPage.d.ts +11 -0
- package/dist/pages/tabs/BuilderTab.d.ts +9 -0
- package/dist/pages/tabs/DebugTab.d.ts +7 -0
- package/dist/pages/tabs/PreviewTab.d.ts +3 -0
- package/dist/store.d.ts +15 -18
- package/dist/styles.css +1 -1
- package/dist/types/PreviewConfig.d.ts +6 -3
- package/dist/types/Project.d.ts +12 -2
- package/dist/utils/copyNode.d.ts +2 -0
- package/dist/utils/logger.d.ts +11 -0
- package/dist/utils/patterns.d.ts +24 -0
- package/dist/utils/useLogRender.d.ts +1 -0
- package/package.json +17 -9
- package/scripts/prebuild/utils/createBuildComponentsIndex.js +15 -1
- package/scripts/prebuild/utils/createGeneratedProps.js +11 -3
- package/scripts/prebuild/utils/validateAllComponentsOrThrow.js +45 -6
- package/scripts/prebuild/utils/validatePatternJson.js +13 -5
- package/src/AttributesEditor.tsx +434 -311
- package/src/DeviceMockFrame.tsx +42 -67
- package/src/RenderPage.tsx +8 -44
- package/src/assets/images/android.svg +43 -0
- package/src/assets/images/apple.svg +16 -0
- package/src/assets/images/background.jpg +0 -0
- package/src/assets/samples/carousel-sample.json +2 -3
- package/src/assets/samples/getSamples.ts +49 -12
- package/src/assets/samples/simple-1.json +1 -2
- package/src/assets/samples/simple-2.json +1 -2
- package/src/assets/samples/vpn-onboard-1.json +1 -2
- package/src/assets/samples/vpn-onboard-2.json +1 -2
- package/src/assets/samples/vpn-onboard-3.json +1 -2
- package/src/assets/samples/vpn-onboard-4.json +1 -2
- package/src/assets/samples/vpn-onboard-5.json +1 -2
- package/src/assets/samples/vpn-onboard-6.json +1 -2
- package/src/attributes-editor/Field.tsx +662 -0
- package/src/attributes-editor/FieldInfoTooltip.tsx +49 -0
- package/src/attributes-editor/LayoutPreviewPicker.tsx +199 -0
- package/src/attributes-editor/SpecialCategorySection.tsx +284 -0
- package/src/attributes-editor/types.ts +30 -0
- package/src/build-components/Button/Button.tsx +12 -2
- package/src/build-components/Button/ButtonProps.generated.ts +37 -1
- package/src/build-components/Button/pattern.json +31 -2
- package/src/build-components/Carousel/Carousel.tsx +17 -2
- package/src/build-components/Carousel/CarouselProps.generated.ts +39 -1
- package/src/build-components/Carousel/pattern.json +10 -0
- package/src/build-components/CarouselButtons/CarouselButtons.tsx +8 -2
- package/src/build-components/CarouselButtons/CarouselButtonsProps.generated.ts +36 -0
- package/src/build-components/CarouselButtons/pattern.json +22 -0
- package/src/build-components/CarouselDots/CarouselDots.tsx +42 -8
- package/src/build-components/CarouselDots/CarouselDotsProps.generated.ts +36 -0
- package/src/build-components/CarouselDots/pattern.json +15 -0
- package/src/build-components/CarouselItem/CarouselItem.tsx +7 -2
- package/src/build-components/CarouselItem/CarouselItemProps.generated.ts +39 -1
- package/src/build-components/CarouselItem/pattern.json +7 -0
- package/src/build-components/CarouselProvider/CarouselProvider.tsx +10 -2
- package/src/build-components/CarouselProvider/CarouselProviderProps.generated.ts +39 -1
- package/src/build-components/CarouselProvider/pattern.json +7 -0
- package/src/build-components/Image/Image.tsx +10 -2
- package/src/build-components/Image/ImageProps.generated.ts +36 -3
- package/src/build-components/Image/pattern.json +46 -3
- package/src/build-components/Onboard/Onboard.tsx +8 -1
- package/src/build-components/Onboard/OnboardProps.generated.ts +39 -1
- package/src/build-components/Onboard/pattern.json +11 -0
- package/src/build-components/OnboardButton/OnboardButton.tsx +53 -9
- package/src/build-components/OnboardButton/OnboardButtonProps.generated.ts +36 -0
- package/src/build-components/OnboardButton/pattern.json +71 -5
- package/src/build-components/OnboardButtons/OnboardButtons.tsx +27 -17
- package/src/build-components/OnboardButtons/OnboardButtonsProps.generated.ts +36 -0
- package/src/build-components/OnboardButtons/pattern.json +70 -4
- package/src/build-components/OnboardDot/OnboardDot.tsx +106 -4
- package/src/build-components/OnboardDot/OnboardDotProps.generated.ts +22 -0
- package/src/build-components/OnboardDot/pattern.json +54 -1
- package/src/build-components/OnboardFooter/OnboardFooter.tsx +14 -6
- package/src/build-components/OnboardFooter/OnboardFooterProps.generated.ts +4 -5
- package/src/build-components/OnboardFooter/pattern.json +58 -2
- package/src/build-components/OnboardImage/OnboardImage.tsx +29 -5
- package/src/build-components/OnboardImage/OnboardImageProps.generated.ts +36 -3
- package/src/build-components/OnboardImage/pattern.json +21 -0
- package/src/build-components/OnboardItem/OnboardItem.tsx +8 -1
- package/src/build-components/OnboardItem/OnboardItemProps.generated.ts +35 -3
- package/src/build-components/OnboardItem/pattern.json +38 -2
- package/src/build-components/OnboardProvider/OnboardProvider.tsx +22 -8
- package/src/build-components/OnboardProvider/OnboardProviderProps.generated.ts +37 -4
- package/src/build-components/OnboardProvider/pattern.json +51 -4
- package/src/build-components/OnboardSubtitle/OnboardSubtitle.tsx +2 -0
- package/src/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.ts +4 -5
- package/src/build-components/OnboardSubtitle/pattern.json +6 -0
- package/src/build-components/OnboardTitle/OnboardTitle.tsx +2 -0
- package/src/build-components/OnboardTitle/OnboardTitleProps.generated.ts +4 -5
- package/src/build-components/OnboardTitle/pattern.json +6 -0
- package/src/build-components/Text/Text.tsx +12 -6
- package/src/build-components/Text/TextProps.generated.ts +4 -5
- package/src/build-components/Text/pattern.json +38 -2
- package/src/build-components/View/View.tsx +11 -6
- package/src/build-components/View/ViewProps.generated.ts +3 -4
- package/src/build-components/View/pattern.json +227 -19
- package/src/build-components/index.ts +22 -0
- package/src/build-components/patterns.generated.ts +4905 -139
- package/src/components/AttributesEditorPanel.tsx +58 -0
- package/src/components/Breadcrumb.tsx +80 -0
- package/src/components/Builder.tsx +375 -0
- package/src/components/Checkbox.tsx +81 -0
- package/src/components/DeviceButton.tsx +39 -0
- package/src/components/DeviceNavigationBar.tsx +201 -0
- package/src/components/DeviceStatusBar.tsx +85 -0
- package/src/components/EditorHeader.tsx +138 -0
- package/src/index.ts +8 -4
- package/src/mockOS/components/MockLaunchScreenComponent.tsx +43 -0
- package/src/mockOS/components/MockOSRouter.tsx +115 -0
- package/src/mockOS/components/PermissionModal.tsx +270 -0
- package/src/mockOS/context/MockOSContext.tsx +179 -0
- package/src/mockOS/hooks/useMockNavigation.ts +11 -0
- package/src/mockOS/hooks/useMockPermission.ts +11 -0
- package/src/mockOS/index.ts +26 -0
- package/src/mockOS/managers/mockPermissionManager.ts +54 -0
- package/src/mockOS/managers/navigationManager.ts +91 -0
- package/src/modals/AddComponentModal.tsx +313 -0
- package/src/modals/ColorModal.tsx +268 -0
- package/src/modals/DeviceSelectorModal.tsx +57 -0
- package/src/modals/LocalicationModal.tsx +54 -0
- package/src/modals/Modal.tsx +57 -0
- package/src/modals/index.ts +5 -0
- package/src/pages/ProjectPage.tsx +150 -0
- package/src/pages/tabs/BuilderTab.tsx +33 -0
- package/src/pages/tabs/DebugTab.tsx +64 -0
- package/src/pages/tabs/PreviewTab.tsx +206 -0
- package/src/size-matters/index.ts +25 -5
- package/src/store.ts +56 -38
- package/src/styles/base/_global.scss +253 -0
- package/src/styles/components/_attributes-editor.scss +261 -0
- package/src/styles/components/_editor-shell.scss +189 -0
- package/src/styles/components/_mockos-router.scss +140 -0
- package/src/styles/components/_ui-components.scss +183 -0
- package/src/styles/foundation/_colors.scss +8 -0
- package/src/styles/foundation/_mixins.scss +22 -0
- package/src/styles/{_reset.scss → foundation/_reset.scss} +5 -2
- package/src/styles/foundation/_sizes.scss +37 -0
- package/src/styles/foundation/_typography.scss +4 -0
- package/src/styles/foundation/_variables.scss +3 -0
- package/src/styles/index.scss +22 -129
- package/src/styles/layout/_builder.scss +68 -0
- package/src/styles/layout/_pages.scss +3 -0
- package/src/styles/modals/_add-component.scss +122 -0
- package/src/styles/modals/_color-modal.scss +130 -0
- package/src/styles/modals/_device-selector.scss +18 -0
- package/src/styles/modals/_localication-modal.scss +68 -0
- package/src/styles/modals/_modal-shell.scss +46 -0
- package/src/styles/utilities/_carousel.scss +125 -0
- package/src/types/PreviewConfig.ts +14 -5
- package/src/types/Project.ts +15 -2
- package/src/types/images.d.ts +8 -0
- package/src/utils/copyNode.ts +7 -0
- package/src/utils/extractTextStyle.ts +8 -4
- package/src/utils/extractViewStyle.ts +51 -7
- package/src/utils/getDevices.ts +1 -0
- package/src/utils/logger.ts +76 -0
- package/src/utils/patterns.ts +33 -0
- package/src/utils/useLogRender.ts +13 -0
- package/dist/build-components/OnboardDot/OnboardExpandingDotProps.generated.d.ts +0 -10
- package/src/build-components/OnboardDot/OnboardExpandingDotProps.generated.ts +0 -20
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
type ModalProps = {
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
ariaLabelledBy?: string;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
contentClassName?: string;
|
|
9
|
+
closeOnOverlayClick?: boolean;
|
|
10
|
+
closeOnEsc?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function Modal({
|
|
14
|
+
onClose,
|
|
15
|
+
ariaLabelledBy,
|
|
16
|
+
children,
|
|
17
|
+
className,
|
|
18
|
+
contentClassName,
|
|
19
|
+
closeOnOverlayClick = true,
|
|
20
|
+
closeOnEsc = true,
|
|
21
|
+
}: ModalProps) {
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!closeOnEsc) return undefined;
|
|
24
|
+
if (typeof window === 'undefined') return undefined;
|
|
25
|
+
|
|
26
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
27
|
+
if (event.key === 'Escape') {
|
|
28
|
+
onClose();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
33
|
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
34
|
+
}, [closeOnEsc, onClose]);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div
|
|
38
|
+
className={`modal${className ? ` ${className}` : ''}`}
|
|
39
|
+
role="dialog"
|
|
40
|
+
aria-modal="true"
|
|
41
|
+
aria-labelledby={ariaLabelledBy}
|
|
42
|
+
>
|
|
43
|
+
<div
|
|
44
|
+
className="modal__overlay"
|
|
45
|
+
onClick={closeOnOverlayClick ? onClose : undefined}
|
|
46
|
+
/>
|
|
47
|
+
<div
|
|
48
|
+
className={`modal__content${contentClassName ? ` ${contentClassName}` : ''}`}
|
|
49
|
+
role="document"
|
|
50
|
+
>
|
|
51
|
+
{children}
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default Modal;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Node, RenderPage, Project } from '..';
|
|
3
|
+
import { EditorHeader } from '../components/EditorHeader';
|
|
4
|
+
import { AttributesEditorPanel } from '../components/AttributesEditorPanel';
|
|
5
|
+
import { BuilderTab } from './tabs/BuilderTab';
|
|
6
|
+
import { PreviewTab } from './tabs/PreviewTab';
|
|
7
|
+
import { DebugTab } from './tabs/DebugTab';
|
|
8
|
+
import { AppConfig, defaultAppConfig } from '../types/PreviewConfig';
|
|
9
|
+
import { useRenderStore } from '../store';
|
|
10
|
+
import { logger } from '../utils/logger';
|
|
11
|
+
import { useLogRender } from '../utils/useLogRender';
|
|
12
|
+
import type { LogLevel } from '../types/Project';
|
|
13
|
+
import backgroundImage from '../assets/images/background.jpg';
|
|
14
|
+
export type Tab = 'builder' | 'preview';
|
|
15
|
+
|
|
16
|
+
export type ProjectPageProps = {
|
|
17
|
+
project: Project;
|
|
18
|
+
onSaveProject: (project: Project) => void;
|
|
19
|
+
appConfig?: AppConfig;
|
|
20
|
+
logLevel?: LogLevel;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function ProjectPage({
|
|
24
|
+
project,
|
|
25
|
+
appConfig = defaultAppConfig,
|
|
26
|
+
onSaveProject,
|
|
27
|
+
logLevel,
|
|
28
|
+
}: ProjectPageProps) {
|
|
29
|
+
useLogRender('ProjectPage');
|
|
30
|
+
const [current, setCurrent] = useState<Node>(project.data);
|
|
31
|
+
const [editorData, setEditorData] = useState<Node>(project.data);
|
|
32
|
+
const [tab, setTab] = useState<Tab>('builder');
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
logger.info('ProjectPage', 'mount', { projectName: project.name });
|
|
36
|
+
useRenderStore.getState().setAppConfig(appConfig);
|
|
37
|
+
logger.verbose('ProjectPage', 'appConfig applied', appConfig);
|
|
38
|
+
return () => {
|
|
39
|
+
logger.info('ProjectPage', 'unmount');
|
|
40
|
+
};
|
|
41
|
+
}, [appConfig, project.name]);
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!logLevel) return;
|
|
45
|
+
logger.setLevel(logLevel);
|
|
46
|
+
}, [logLevel]);
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div className="container-full">
|
|
50
|
+
<EditorHeader
|
|
51
|
+
onSaveProject={() => {
|
|
52
|
+
logger.info('ProjectPage', 'save project', { name: project.name });
|
|
53
|
+
onSaveProject({
|
|
54
|
+
...project,
|
|
55
|
+
data: editorData,
|
|
56
|
+
});
|
|
57
|
+
}}
|
|
58
|
+
onRestoreProject={() => {
|
|
59
|
+
logger.info('ProjectPage', 'restore project', { name: project.name });
|
|
60
|
+
setEditorData(project.data);
|
|
61
|
+
setCurrent(project.data);
|
|
62
|
+
}}
|
|
63
|
+
current={current}
|
|
64
|
+
editorData={editorData}
|
|
65
|
+
setEditorData={setEditorData}
|
|
66
|
+
/>
|
|
67
|
+
<div className="editor-container">
|
|
68
|
+
<div className="split-left">
|
|
69
|
+
<div>
|
|
70
|
+
<div
|
|
71
|
+
className="editor-tabs"
|
|
72
|
+
role="tablist"
|
|
73
|
+
aria-label="Editor tabs"
|
|
74
|
+
>
|
|
75
|
+
<button
|
|
76
|
+
className={`editor-tab ${tab === 'builder' ? 'editor-tab--active' : ''}`}
|
|
77
|
+
role="tab"
|
|
78
|
+
aria-selected={tab === 'builder'}
|
|
79
|
+
onClick={() => {
|
|
80
|
+
setTab('builder');
|
|
81
|
+
logger.info('ProjectPage', 'tab change', { to: 'builder' });
|
|
82
|
+
}}
|
|
83
|
+
>
|
|
84
|
+
<span className="editor-tab__label">Builder</span>
|
|
85
|
+
</button>
|
|
86
|
+
<button
|
|
87
|
+
className={`editor-tab ${tab === 'preview' ? 'editor-tab--active' : ''}`}
|
|
88
|
+
role="tab"
|
|
89
|
+
aria-selected={tab === 'preview'}
|
|
90
|
+
onClick={() => {
|
|
91
|
+
setTab('preview');
|
|
92
|
+
logger.info('ProjectPage', 'tab change', { to: 'preview' });
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
<span className="editor-tab__label">Preview Config</span>
|
|
96
|
+
</button>
|
|
97
|
+
</div>
|
|
98
|
+
|
|
99
|
+
{tab === 'builder' && (
|
|
100
|
+
<BuilderTab
|
|
101
|
+
data={editorData}
|
|
102
|
+
setData={setEditorData}
|
|
103
|
+
current={current}
|
|
104
|
+
setCurrent={setCurrent}
|
|
105
|
+
/>
|
|
106
|
+
)}
|
|
107
|
+
|
|
108
|
+
{tab === 'preview' && <PreviewTab />}
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
<div className="split-right">
|
|
112
|
+
<div className="split-right__controls">
|
|
113
|
+
<DebugTab data={editorData} setData={setEditorData} />
|
|
114
|
+
</div>
|
|
115
|
+
<div
|
|
116
|
+
className="split-right-background"
|
|
117
|
+
style={{
|
|
118
|
+
backgroundImage: `url(${backgroundImage})`,
|
|
119
|
+
}}
|
|
120
|
+
/>
|
|
121
|
+
<RenderPage data={editorData} name={project.name} />
|
|
122
|
+
</div>
|
|
123
|
+
<div className="split-third">
|
|
124
|
+
<AttributesEditorPanel
|
|
125
|
+
current={current}
|
|
126
|
+
attributes={editorData}
|
|
127
|
+
onChange={(data) => {
|
|
128
|
+
setEditorData(data);
|
|
129
|
+
let nodeKey: string | undefined = undefined;
|
|
130
|
+
if (
|
|
131
|
+
data &&
|
|
132
|
+
typeof data === 'object' &&
|
|
133
|
+
!Array.isArray(data) &&
|
|
134
|
+
'key' in (data as any)
|
|
135
|
+
) {
|
|
136
|
+
nodeKey = (data as any).key as string | undefined;
|
|
137
|
+
}
|
|
138
|
+
logger.verbose(
|
|
139
|
+
'ProjectPage',
|
|
140
|
+
'attributes change',
|
|
141
|
+
nodeKey ? { nodeKey } : undefined,
|
|
142
|
+
);
|
|
143
|
+
}}
|
|
144
|
+
setCurrent={setCurrent}
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Node } from '../..';
|
|
2
|
+
import { useLogRender } from '../../utils/useLogRender';
|
|
3
|
+
import { Builder } from '../../components/Builder';
|
|
4
|
+
|
|
5
|
+
type BuilderTabProps = {
|
|
6
|
+
data: Node;
|
|
7
|
+
setData: (data: Node) => void;
|
|
8
|
+
current: Node;
|
|
9
|
+
setCurrent: (current: Node) => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function BuilderTab({
|
|
13
|
+
data,
|
|
14
|
+
setData,
|
|
15
|
+
current,
|
|
16
|
+
setCurrent,
|
|
17
|
+
}: BuilderTabProps) {
|
|
18
|
+
useLogRender('BuilderTab');
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
role="tabpanel"
|
|
22
|
+
className="editor-panel-builder editor-panel editor-panel--active"
|
|
23
|
+
aria-hidden={false}
|
|
24
|
+
>
|
|
25
|
+
<Builder
|
|
26
|
+
data={data}
|
|
27
|
+
setData={setData}
|
|
28
|
+
current={current}
|
|
29
|
+
setCurrent={setCurrent}
|
|
30
|
+
/>
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { JsonEditor } from 'json-edit-react';
|
|
3
|
+
import { Modal } from '../../modals';
|
|
4
|
+
import { Node } from '../..';
|
|
5
|
+
import { useLogRender } from '../../utils/useLogRender';
|
|
6
|
+
|
|
7
|
+
type DebugTabProps = {
|
|
8
|
+
data: Node;
|
|
9
|
+
setData: (data: Node) => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function DebugTab({ data, setData }: DebugTabProps) {
|
|
13
|
+
useLogRender('DebugTab');
|
|
14
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
15
|
+
return (
|
|
16
|
+
<>
|
|
17
|
+
<button
|
|
18
|
+
type="button"
|
|
19
|
+
className="editor-button debug-button"
|
|
20
|
+
title="Inspect raw JSON data"
|
|
21
|
+
onClick={() => setIsOpen(true)}
|
|
22
|
+
>
|
|
23
|
+
Debug JSON
|
|
24
|
+
</button>
|
|
25
|
+
{isOpen ? (
|
|
26
|
+
<Modal
|
|
27
|
+
onClose={() => setIsOpen(false)}
|
|
28
|
+
ariaLabelledBy="debug-json-editor-title"
|
|
29
|
+
className="modal--large modal--scrollable"
|
|
30
|
+
contentClassName="localication-modal__content"
|
|
31
|
+
>
|
|
32
|
+
<div className="modal__header localication-modal__header">
|
|
33
|
+
<div className="localication-modal__header-main">
|
|
34
|
+
<h3 id="debug-json-editor-title" className="modal__title">
|
|
35
|
+
Debug data
|
|
36
|
+
</h3>
|
|
37
|
+
<p className="localication-modal__description">
|
|
38
|
+
Inspect and edit the current node tree using the JSON editor.
|
|
39
|
+
</p>
|
|
40
|
+
</div>
|
|
41
|
+
<button
|
|
42
|
+
type="button"
|
|
43
|
+
className="editor-button"
|
|
44
|
+
onClick={() => setIsOpen(false)}
|
|
45
|
+
>
|
|
46
|
+
Close
|
|
47
|
+
</button>
|
|
48
|
+
</div>
|
|
49
|
+
<div className="localication-modal__body">
|
|
50
|
+
<div className="localication-modal__editor">
|
|
51
|
+
<JsonEditor
|
|
52
|
+
rootName="debug"
|
|
53
|
+
data={data as any}
|
|
54
|
+
setData={setData as any}
|
|
55
|
+
className="localication-modal__json-editor"
|
|
56
|
+
maxWidth={'100%'}
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
</Modal>
|
|
61
|
+
) : null}
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import React, { useCallback, useState } from 'react';
|
|
2
|
+
import { Localication } from '../..';
|
|
3
|
+
import { useLogRender } from '../../utils/useLogRender';
|
|
4
|
+
import { useRenderStore } from '../../store';
|
|
5
|
+
import { LocalicationModal } from '../../modals/LocalicationModal';
|
|
6
|
+
import { Checkbox } from '../../components/Checkbox';
|
|
7
|
+
|
|
8
|
+
type PreviewTabProps = {};
|
|
9
|
+
|
|
10
|
+
export function PreviewTab({}: PreviewTabProps) {
|
|
11
|
+
useLogRender('PreviewTab');
|
|
12
|
+
const { appConfig, setAppConfig } = useRenderStore((s) => ({
|
|
13
|
+
appConfig: s.appConfig,
|
|
14
|
+
setAppConfig: s.setAppConfig,
|
|
15
|
+
}));
|
|
16
|
+
const [isLocalicationModalOpen, setIsLocalicationModalOpen] = useState(false);
|
|
17
|
+
|
|
18
|
+
const handleLocalicationChange = useCallback(
|
|
19
|
+
(data: Localication) => {
|
|
20
|
+
setAppConfig({
|
|
21
|
+
...appConfig,
|
|
22
|
+
localication: data,
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
[appConfig, setAppConfig],
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div
|
|
30
|
+
role="tabpanel"
|
|
31
|
+
className="editor-panel editor-panel--active"
|
|
32
|
+
aria-hidden={false}
|
|
33
|
+
>
|
|
34
|
+
<div style={{ padding: 12 }}>
|
|
35
|
+
<div
|
|
36
|
+
style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}
|
|
37
|
+
>
|
|
38
|
+
<div>Default Language</div>
|
|
39
|
+
<select
|
|
40
|
+
value={appConfig.defaultLanguage ?? 'en'}
|
|
41
|
+
onChange={(e) => {
|
|
42
|
+
setAppConfig({
|
|
43
|
+
...appConfig,
|
|
44
|
+
defaultLanguage: e.target.value,
|
|
45
|
+
});
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
{Object.keys(appConfig.localication ?? {}).map((language) => (
|
|
49
|
+
<option key={language} value={language}>
|
|
50
|
+
{language}
|
|
51
|
+
</option>
|
|
52
|
+
))}
|
|
53
|
+
</select>
|
|
54
|
+
</div>
|
|
55
|
+
<div
|
|
56
|
+
style={{
|
|
57
|
+
display: 'grid',
|
|
58
|
+
gridTemplateColumns: 'repeat(2, minmax(0, 1fr))',
|
|
59
|
+
gap: 12,
|
|
60
|
+
marginTop: 8,
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
<div>Light Background Color</div>
|
|
64
|
+
<input
|
|
65
|
+
type="color"
|
|
66
|
+
value={appConfig.screenStyle?.light.backgroundColor ?? '#FDFDFD'}
|
|
67
|
+
onChange={(e) => {
|
|
68
|
+
const next = {
|
|
69
|
+
...appConfig.screenStyle,
|
|
70
|
+
light: {
|
|
71
|
+
...(appConfig.screenStyle?.light ?? {
|
|
72
|
+
color: '#161827',
|
|
73
|
+
}),
|
|
74
|
+
backgroundColor: e.target.value,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
setAppConfig({
|
|
79
|
+
...appConfig,
|
|
80
|
+
screenStyle: next,
|
|
81
|
+
});
|
|
82
|
+
}}
|
|
83
|
+
className="input input--color"
|
|
84
|
+
/>
|
|
85
|
+
<div>Light Color</div>
|
|
86
|
+
<input
|
|
87
|
+
type="color"
|
|
88
|
+
value={appConfig.screenStyle?.light.color ?? '#161827'}
|
|
89
|
+
onChange={(e) => {
|
|
90
|
+
const next = {
|
|
91
|
+
...appConfig.screenStyle,
|
|
92
|
+
light: {
|
|
93
|
+
...(appConfig.screenStyle?.light ?? {
|
|
94
|
+
backgroundColor: '#FDFDFD',
|
|
95
|
+
}),
|
|
96
|
+
color: e.target.value,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
setAppConfig({
|
|
101
|
+
...appConfig,
|
|
102
|
+
screenStyle: next,
|
|
103
|
+
});
|
|
104
|
+
}}
|
|
105
|
+
className="input input--color"
|
|
106
|
+
/>
|
|
107
|
+
<div>Dark Background Color</div>
|
|
108
|
+
<input
|
|
109
|
+
type="color"
|
|
110
|
+
value={appConfig.screenStyle?.dark.backgroundColor ?? '#12131A'}
|
|
111
|
+
onChange={(e) => {
|
|
112
|
+
const next = {
|
|
113
|
+
...appConfig.screenStyle,
|
|
114
|
+
dark: {
|
|
115
|
+
...(appConfig.screenStyle?.dark ?? {
|
|
116
|
+
color: '#E9EBF9',
|
|
117
|
+
}),
|
|
118
|
+
backgroundColor: e.target.value,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
setAppConfig({
|
|
123
|
+
...appConfig,
|
|
124
|
+
screenStyle: next,
|
|
125
|
+
});
|
|
126
|
+
}}
|
|
127
|
+
className="input input--color"
|
|
128
|
+
/>
|
|
129
|
+
<div>Dark Color</div>
|
|
130
|
+
<input
|
|
131
|
+
type="color"
|
|
132
|
+
value={appConfig.screenStyle?.dark.color ?? '#E9EBF9'}
|
|
133
|
+
onChange={(e) => {
|
|
134
|
+
const next = {
|
|
135
|
+
...appConfig.screenStyle,
|
|
136
|
+
dark: {
|
|
137
|
+
...(appConfig.screenStyle?.dark ?? {
|
|
138
|
+
backgroundColor: '#12131A',
|
|
139
|
+
}),
|
|
140
|
+
color: e.target.value,
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
setAppConfig({
|
|
144
|
+
...appConfig,
|
|
145
|
+
screenStyle: next,
|
|
146
|
+
});
|
|
147
|
+
}}
|
|
148
|
+
className="input input--color"
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
<div style={{ marginTop: 8 }}>
|
|
152
|
+
<Checkbox
|
|
153
|
+
label="Dark Mode"
|
|
154
|
+
checked={appConfig.theme === 'dark'}
|
|
155
|
+
onChange={(checked) => {
|
|
156
|
+
const nextTheme = checked ? 'dark' : 'light';
|
|
157
|
+
setAppConfig({
|
|
158
|
+
...appConfig,
|
|
159
|
+
theme: nextTheme,
|
|
160
|
+
});
|
|
161
|
+
}}
|
|
162
|
+
/>
|
|
163
|
+
</div>
|
|
164
|
+
<div style={{ marginTop: 8 }}>
|
|
165
|
+
<Checkbox
|
|
166
|
+
label="Is RTL"
|
|
167
|
+
checked={appConfig.isRtl ?? false}
|
|
168
|
+
onChange={(checked) => {
|
|
169
|
+
setAppConfig({
|
|
170
|
+
...appConfig,
|
|
171
|
+
isRtl: checked,
|
|
172
|
+
});
|
|
173
|
+
}}
|
|
174
|
+
/>
|
|
175
|
+
</div>
|
|
176
|
+
<div
|
|
177
|
+
style={{
|
|
178
|
+
marginTop: 16,
|
|
179
|
+
display: 'flex',
|
|
180
|
+
flexDirection: 'column',
|
|
181
|
+
gap: 8,
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
184
|
+
<div style={{ fontWeight: 600 }}>Localization</div>
|
|
185
|
+
<p style={{ margin: 0, fontSize: 13, color: '#4b5563' }}>
|
|
186
|
+
Manage translations for each language configured in your preview.
|
|
187
|
+
</p>
|
|
188
|
+
<button
|
|
189
|
+
type="button"
|
|
190
|
+
className="editor-button"
|
|
191
|
+
onClick={() => setIsLocalicationModalOpen(true)}
|
|
192
|
+
>
|
|
193
|
+
Open localization editor
|
|
194
|
+
</button>
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
{isLocalicationModalOpen ? (
|
|
198
|
+
<LocalicationModal
|
|
199
|
+
data={appConfig.localication ?? {}}
|
|
200
|
+
onChange={handleLocalicationChange}
|
|
201
|
+
onClose={() => setIsLocalicationModalOpen(false)}
|
|
202
|
+
/>
|
|
203
|
+
) : null}
|
|
204
|
+
</div>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
import { useRenderStore } from '../store';
|
|
2
|
+
import { defaultAppConfig } from '../types/PreviewConfig';
|
|
3
|
+
import { getDefaultDevice } from '../utils/getDevices';
|
|
4
|
+
|
|
5
|
+
const fallbackDevice = getDefaultDevice();
|
|
6
|
+
const fallbackBaseSize = defaultAppConfig.baseSize;
|
|
7
|
+
|
|
8
|
+
function ensureNumber(value: number | undefined, fallback: number) {
|
|
9
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
10
|
+
}
|
|
2
11
|
|
|
3
12
|
function getBaseDimensions() {
|
|
4
13
|
const currentState = useRenderStore.getState();
|
|
5
|
-
|
|
14
|
+
const device = currentState.device ?? fallbackDevice;
|
|
15
|
+
const baseSize = currentState.appConfig?.baseSize ?? fallbackBaseSize;
|
|
16
|
+
|
|
17
|
+
const deviceWidth = ensureNumber(device?.width, fallbackDevice.width);
|
|
18
|
+
const deviceHeight = ensureNumber(device?.height, fallbackDevice.height);
|
|
19
|
+
const baseWidth = ensureNumber(baseSize?.width, fallbackBaseSize.width);
|
|
20
|
+
const baseHeight = ensureNumber(baseSize?.height, fallbackBaseSize.height);
|
|
21
|
+
|
|
6
22
|
const [shortDimension, longDimension] =
|
|
7
|
-
|
|
8
|
-
? [
|
|
9
|
-
: [
|
|
23
|
+
deviceWidth < deviceHeight
|
|
24
|
+
? [deviceWidth, deviceHeight]
|
|
25
|
+
: [deviceHeight, deviceWidth];
|
|
10
26
|
|
|
11
|
-
return {
|
|
27
|
+
return {
|
|
28
|
+
baseSize: { width: baseWidth, height: baseHeight },
|
|
29
|
+
shortDimension,
|
|
30
|
+
longDimension,
|
|
31
|
+
};
|
|
12
32
|
}
|
|
13
33
|
export function scale(size: number) {
|
|
14
34
|
const { baseSize, shortDimension } = getBaseDimensions();
|
package/src/store.ts
CHANGED
|
@@ -1,56 +1,74 @@
|
|
|
1
1
|
import { createWithEqualityFn } from 'zustand/traditional';
|
|
2
2
|
import { shallow } from 'zustand/shallow';
|
|
3
3
|
import type { Device } from './types/Device';
|
|
4
|
-
import
|
|
4
|
+
import {
|
|
5
|
+
defaultAppConfig,
|
|
6
|
+
type AppConfig,
|
|
7
|
+
type Localication,
|
|
8
|
+
} from './types/PreviewConfig';
|
|
5
9
|
import { getDefaultDevice } from './utils/getDevices';
|
|
6
10
|
import { ScreenStyle } from './RenderPage';
|
|
11
|
+
import { createJSONStorage } from 'zustand/middleware';
|
|
12
|
+
import { Node } from './types/Node';
|
|
13
|
+
import type { LogEntry, LogLevel } from './types/Project';
|
|
7
14
|
|
|
8
15
|
type RenderStore = {
|
|
16
|
+
copiedNode: Node | null;
|
|
17
|
+
setCopiedNode: (node: Node | null) => void;
|
|
9
18
|
device: Device;
|
|
10
|
-
localication: Localication | null;
|
|
11
|
-
defaultLanguage?: string;
|
|
12
|
-
baseSize: {
|
|
13
|
-
width: number;
|
|
14
|
-
height: number;
|
|
15
|
-
};
|
|
16
|
-
theme: 'dark' | 'light';
|
|
17
|
-
screenStyle: ScreenStyle;
|
|
18
|
-
setBaseSize: (baseSize: { width: number; height: number }) => void;
|
|
19
19
|
setDevice: (device: Device) => void;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
appConfig: AppConfig;
|
|
21
|
+
setAppConfig: (appConfig: AppConfig) => void;
|
|
22
|
+
// Logging
|
|
23
|
+
logs: LogEntry[];
|
|
24
|
+
logLevel: LogLevel;
|
|
25
|
+
setLogLevel: (level: LogLevel) => void;
|
|
26
|
+
addLog: (
|
|
27
|
+
entry: Omit<LogEntry, 'id' | 'timestamp'> & {
|
|
28
|
+
id?: string;
|
|
29
|
+
timestamp?: number;
|
|
30
|
+
},
|
|
31
|
+
) => void;
|
|
32
|
+
clearLogs: () => void;
|
|
24
33
|
};
|
|
25
34
|
|
|
26
35
|
export const useRenderStore = createWithEqualityFn<RenderStore>()(
|
|
27
36
|
(set) => ({
|
|
37
|
+
copiedNode: null,
|
|
38
|
+
setCopiedNode: (node) => set({ copiedNode: node }),
|
|
28
39
|
device: getDefaultDevice(),
|
|
29
|
-
localication: null,
|
|
30
|
-
defaultLanguage: undefined,
|
|
31
|
-
baseSize: {
|
|
32
|
-
width: 390,
|
|
33
|
-
height: 844,
|
|
34
|
-
},
|
|
35
|
-
theme: 'light',
|
|
36
|
-
screenStyle: {
|
|
37
|
-
light: {
|
|
38
|
-
backgroundColor: '#FDFDFD',
|
|
39
|
-
color: '#161827',
|
|
40
|
-
seperatorColor: '#E5E7EB',
|
|
41
|
-
},
|
|
42
|
-
dark: {
|
|
43
|
-
backgroundColor: '#12131A',
|
|
44
|
-
color: '#E9EBF9',
|
|
45
|
-
seperatorColor: '#E5E7EB',
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
setBaseSize: (baseSize) => set({ baseSize }),
|
|
49
40
|
setDevice: (device) => set({ device }),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
appConfig: defaultAppConfig,
|
|
42
|
+
setAppConfig: (appConfig) => set({ appConfig }),
|
|
43
|
+
// Logging defaults
|
|
44
|
+
logs: [],
|
|
45
|
+
logLevel: 'INFO',
|
|
46
|
+
setLogLevel: (level) => set({ logLevel: level }),
|
|
47
|
+
addLog: (entry) =>
|
|
48
|
+
set((state) => {
|
|
49
|
+
const now = Date.now();
|
|
50
|
+
const id =
|
|
51
|
+
entry.id ?? `${now}-${Math.random().toString(36).slice(2, 8)}`;
|
|
52
|
+
const timestamp = entry.timestamp ?? now;
|
|
53
|
+
const newEntry: LogEntry = {
|
|
54
|
+
id,
|
|
55
|
+
timestamp,
|
|
56
|
+
level: entry.level,
|
|
57
|
+
source: entry.source,
|
|
58
|
+
message: entry.message,
|
|
59
|
+
payload: entry.payload,
|
|
60
|
+
};
|
|
61
|
+
return { logs: [...state.logs, newEntry] };
|
|
62
|
+
}),
|
|
63
|
+
clearLogs: () => set({ logs: [] }),
|
|
64
|
+
persist: {
|
|
65
|
+
name: 'render-store',
|
|
66
|
+
partialize: (state: RenderStore) => ({
|
|
67
|
+
copiedNode: state.copiedNode ?? null,
|
|
68
|
+
logLevel: state.logLevel,
|
|
69
|
+
}),
|
|
70
|
+
storage: createJSONStorage(() => localStorage),
|
|
71
|
+
},
|
|
54
72
|
}),
|
|
55
73
|
shallow,
|
|
56
74
|
);
|