@developer_tribe/react-builder 0.1.27 → 0.1.29

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.
Files changed (76) hide show
  1. package/dist/RenderPage.d.ts +13 -13
  2. package/dist/build-components/OnboardButton/OnboardButtonProps.generated.d.ts +2 -2
  3. package/dist/build-components/OnboardFooter/OnboardFooterProps.generated.d.ts +18 -4
  4. package/dist/build-components/OnboardItem/OnboardItemProps.generated.d.ts +6 -1
  5. package/dist/build-components/OnboardProvider/OnboardProviderProps.generated.d.ts +4 -0
  6. package/dist/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.d.ts +23 -1
  7. package/dist/build-components/OnboardTitle/OnboardTitleProps.generated.d.ts +23 -0
  8. package/dist/build-components/Text/TextProps.generated.d.ts +23 -0
  9. package/dist/build-components/View/ViewProps.generated.d.ts +15 -3
  10. package/dist/build-components/index.d.ts +1 -0
  11. package/dist/build-components/patterns.generated.d.ts +389 -0
  12. package/dist/index.cjs.js +28 -1
  13. package/dist/index.d.ts +1 -2
  14. package/dist/index.esm.js +28 -1
  15. package/dist/size-matters/index.d.ts +6 -0
  16. package/dist/store.d.ts +25 -0
  17. package/dist/styles.css +1 -1
  18. package/dist/types/PreviewConfig.d.ts +2 -0
  19. package/dist/utils/getDevices.d.ts +1 -0
  20. package/dist/utils/patterns.d.ts +3 -2
  21. package/package.json +2 -1
  22. package/scripts/prebuild/build-components.js +2 -0
  23. package/scripts/prebuild/utils/createBuildComponentsIndex.js +5 -1
  24. package/scripts/prebuild/utils/createPatternsGenerated.js +23 -0
  25. package/scripts/prebuild/utils/index.js +1 -0
  26. package/scripts/prebuild/utils/validateAllComponentsOrThrow.js +126 -1
  27. package/src/RenderPage.tsx +33 -29
  28. package/src/build-components/Button/Button.tsx +2 -2
  29. package/src/build-components/Carousel/Carousel.tsx +2 -2
  30. package/src/build-components/CarouselButtons/CarouselButtons.tsx +2 -2
  31. package/src/build-components/CarouselDots/CarouselDots.tsx +2 -2
  32. package/src/build-components/CarouselItem/CarouselItem.tsx +2 -2
  33. package/src/build-components/CarouselProvider/CarouselProvider.tsx +2 -2
  34. package/src/build-components/Image/Image.tsx +2 -3
  35. package/src/build-components/Onboard/Onboard.tsx +2 -2
  36. package/src/build-components/OnboardButton/OnboardButton.tsx +13 -6
  37. package/src/build-components/OnboardButton/OnboardButtonProps.generated.ts +2 -2
  38. package/src/build-components/OnboardButton/pattern.json +2 -2
  39. package/src/build-components/OnboardButtons/OnboardButtons.tsx +14 -9
  40. package/src/build-components/OnboardDot/OnboardDot.tsx +2 -2
  41. package/src/build-components/OnboardFooter/OnboardFooter.tsx +22 -12
  42. package/src/build-components/OnboardFooter/OnboardFooterProps.generated.ts +29 -4
  43. package/src/build-components/OnboardFooter/pattern.json +4 -19
  44. package/src/build-components/OnboardImage/OnboardImage.tsx +2 -2
  45. package/src/build-components/OnboardItem/OnboardItem.tsx +20 -19
  46. package/src/build-components/OnboardItem/OnboardItemProps.generated.ts +6 -1
  47. package/src/build-components/OnboardItem/pattern.json +12 -1
  48. package/src/build-components/OnboardProvider/OnboardProvider.tsx +15 -12
  49. package/src/build-components/OnboardProvider/OnboardProviderProps.generated.ts +4 -0
  50. package/src/build-components/OnboardProvider/pattern.json +11 -1
  51. package/src/build-components/OnboardSubtitle/OnboardSubtitle.tsx +3 -17
  52. package/src/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.ts +29 -1
  53. package/src/build-components/OnboardSubtitle/pattern.json +3 -19
  54. package/src/build-components/OnboardTitle/OnboardTitle.tsx +4 -17
  55. package/src/build-components/OnboardTitle/OnboardTitleProps.generated.ts +29 -0
  56. package/src/build-components/OnboardTitle/pattern.json +5 -19
  57. package/src/build-components/Text/Text.tsx +21 -9
  58. package/src/build-components/Text/TextProps.generated.ts +29 -0
  59. package/src/build-components/Text/pattern.json +1 -0
  60. package/src/build-components/View/View.tsx +3 -3
  61. package/src/build-components/View/ViewProps.generated.ts +15 -3
  62. package/src/build-components/View/pattern.json +15 -3
  63. package/src/build-components/index.ts +2 -0
  64. package/src/build-components/patterns.generated.ts +502 -0
  65. package/src/build-components/useNode.ts +1 -0
  66. package/src/index.ts +1 -2
  67. package/src/size-matters/index.ts +64 -0
  68. package/src/store.ts +56 -0
  69. package/src/styles/_reset.scss +30 -0
  70. package/src/styles/index.scss +2 -0
  71. package/src/types/PreviewConfig.ts +2 -2
  72. package/src/utils/getDevices.ts +4 -0
  73. package/src/utils/novaToJson.ts +46 -8
  74. package/src/utils/patterns.ts +14 -45
  75. package/dist/RenderMainNode.d.ts +0 -16
  76. package/src/RenderMainNode.tsx +0 -37
package/src/store.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { createWithEqualityFn } from 'zustand/traditional';
2
+ import { shallow } from 'zustand/shallow';
3
+ import type { Device } from './types/Device';
4
+ import type { Localication } from './types/PreviewConfig';
5
+ import { getDefaultDevice } from './utils/getDevices';
6
+ import { ScreenStyle } from './RenderPage';
7
+
8
+ type RenderStore = {
9
+ 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
+ setDevice: (device: Device) => void;
20
+ setLocalication: (localication: Localication | null) => void;
21
+ setDefaultLanguage: (defaultLanguage?: string) => void;
22
+ setTheme: (theme: 'dark' | 'light') => void;
23
+ setScreenStyle: (screenStyle: ScreenStyle) => void;
24
+ };
25
+
26
+ export const useRenderStore = createWithEqualityFn<RenderStore>()(
27
+ (set) => ({
28
+ 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
+ setDevice: (device) => set({ device }),
50
+ setLocalication: (localication) => set({ localication }),
51
+ setDefaultLanguage: (defaultLanguage) => set({ defaultLanguage }),
52
+ setTheme: (theme) => set({ theme }),
53
+ setScreenStyle: (screenStyle) => set({ screenStyle }),
54
+ }),
55
+ shallow,
56
+ );
@@ -0,0 +1,30 @@
1
+ *,
2
+ *::before,
3
+ *::after {
4
+ box-sizing: border-box;
5
+ }
6
+ html,
7
+ body,
8
+ #root {
9
+ height: 100%;
10
+ margin: 0;
11
+ padding: 0;
12
+ }
13
+ body {
14
+ background: #fff;
15
+ //font-family: $font-sans;
16
+ -webkit-font-smoothing: antialiased;
17
+ -moz-osx-font-smoothing: grayscale;
18
+ overflow: hidden; /* Prevent page scroll; panels will handle their own scroll */
19
+ }
20
+ button {
21
+ font-family: inherit;
22
+ }
23
+ input,
24
+ button {
25
+ font-size: 100%;
26
+ }
27
+ p {
28
+ margin: 0;
29
+ padding: 0;
30
+ }
@@ -1,3 +1,5 @@
1
+ @use './reset';
2
+
1
3
  .embla {
2
4
  max-width: 48rem;
3
5
  margin: auto;
@@ -5,8 +5,8 @@ export interface PreviewConfig {
5
5
  screenSize: TargetedScreenSize;
6
6
  isRtl: boolean;
7
7
  screenStyle: {
8
- light: { backgroundColor: string; color: string };
9
- dark: { backgroundColor: string; color: string };
8
+ light: { backgroundColor: string; color: string; seperatorColor?: string };
9
+ dark: { backgroundColor: string; color: string; seperatorColor?: string };
10
10
  };
11
11
  localication: Localication;
12
12
  defaultLanguage?: string;
@@ -10,3 +10,7 @@ export function getDevices(): Device[] {
10
10
  });
11
11
  return deviceList;
12
12
  }
13
+
14
+ export function getDefaultDevice(): Device {
15
+ return getDevices()[0];
16
+ }
@@ -95,17 +95,29 @@ function buildCarouselItem(
95
95
  if (comp?.layout === 'title-layout') {
96
96
  const title = comp?.attributes?.title_localization_key || '';
97
97
  const color = comp?.attributes?.title_color || undefined;
98
- const { fontSize: titleFontSize, fontWeight: titleFontWeight } =
99
- extractTextStyleAttributesFromComponent(comp);
98
+ const {
99
+ fontSize: titleFontSize,
100
+ textAlign: titleTextAlign,
101
+ marginTop: titleMarginTop,
102
+ fontWeight: titleFontWeight,
103
+ } = extractTextStyleAttributesFromComponent(comp);
100
104
  children.push({
101
105
  type: 'OnboardTitle',
102
106
  attributes:
103
- color || titleFontSize || titleFontWeight
107
+ color ||
108
+ titleFontSize ||
109
+ titleTextAlign ||
110
+ titleMarginTop ||
111
+ titleFontWeight
104
112
  ? {
105
113
  ...(color ? { color } : {}),
106
114
  ...(typeof titleFontSize === 'number'
107
115
  ? { fontSize: titleFontSize }
108
116
  : {}),
117
+ ...(titleTextAlign ? { textAlign: titleTextAlign } : {}),
118
+ ...(typeof titleMarginTop === 'number'
119
+ ? { marginTop: titleMarginTop }
120
+ : {}),
109
121
  ...(titleFontWeight ? { fontWeight: titleFontWeight } : {}),
110
122
  }
111
123
  : undefined,
@@ -117,18 +129,26 @@ function buildCarouselItem(
117
129
  const {
118
130
  fontSize: subtitleFontSize,
119
131
  textAlign: subtitleTextAlign,
132
+ marginTop: subtitleMarginTop,
120
133
  fontWeight: subtitleFontWeight,
121
134
  } = extractTextStyleAttributesFromComponent(comp);
122
135
  children.push({
123
136
  type: 'OnboardSubtitle',
124
137
  attributes:
125
- color || subtitleFontSize || subtitleTextAlign || subtitleFontWeight
138
+ color ||
139
+ subtitleFontSize ||
140
+ subtitleTextAlign ||
141
+ subtitleMarginTop ||
142
+ subtitleFontWeight
126
143
  ? {
127
144
  ...(color ? { color } : {}),
128
145
  ...(typeof subtitleFontSize === 'number'
129
146
  ? { fontSize: subtitleFontSize }
130
147
  : {}),
131
148
  ...(subtitleTextAlign ? { textAlign: subtitleTextAlign } : {}),
149
+ ...(typeof subtitleMarginTop === 'number'
150
+ ? { marginTop: subtitleMarginTop }
151
+ : {}),
132
152
  ...(subtitleFontWeight
133
153
  ? { fontWeight: subtitleFontWeight }
134
154
  : {}),
@@ -195,7 +215,7 @@ function buildCarouselItem(
195
215
  const normalizedEvents: {
196
216
  type: 'Permission' | 'Navigate';
197
217
  permission?: string;
198
- next_page_key?: string;
218
+ navigate_to?: string | null;
199
219
  }[] = [];
200
220
  for (const action of actions) {
201
221
  //@eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -210,12 +230,20 @@ function buildCarouselItem(
210
230
  const nextKey = e?.attributes?.next_page_key as
211
231
  | string
212
232
  | undefined;
233
+ // If key exists among simple-onboard-layout pages, prefer index navigation
234
+ const hasTarget =
235
+ typeof nextKey === 'string' && pageKeyToIndex.has(nextKey);
236
+ const navigate_to = hasTarget
237
+ ? null
238
+ : typeof nextKey === 'string'
239
+ ? nextKey
240
+ : null;
213
241
  normalizedEvents.push({
214
242
  type: 'Navigate',
215
- next_page_key: nextKey,
243
+ navigate_to,
216
244
  });
217
- if (typeof nextKey === 'string' && pageKeyToIndex.has(nextKey)) {
218
- targetIndex = pageKeyToIndex.get(nextKey)!;
245
+ if (hasTarget) {
246
+ targetIndex = pageKeyToIndex.get(nextKey!)!;
219
247
  }
220
248
  }
221
249
  }
@@ -275,6 +303,7 @@ function buildCarouselItem(
275
303
  function extractTextStyleAttributesFromComponent(comp: any): {
276
304
  fontSize?: number;
277
305
  textAlign?: 'left' | 'center' | 'right' | 'justify';
306
+ marginTop?: number;
278
307
  fontWeight?:
279
308
  | 'normal'
280
309
  | 'bold'
@@ -291,6 +320,7 @@ function extractTextStyleAttributesFromComponent(comp: any): {
291
320
  const result: {
292
321
  fontSize?: number;
293
322
  textAlign?: 'left' | 'center' | 'right' | 'justify';
323
+ marginTop?: number;
294
324
  fontWeight?:
295
325
  | 'normal'
296
326
  | 'bold'
@@ -348,6 +378,14 @@ function extractTextStyleAttributesFromComponent(comp: any): {
348
378
  result.textAlign = align as typeof result.textAlign;
349
379
  }
350
380
 
381
+ const rawMarginTop = style?.marginTop;
382
+ if (typeof rawMarginTop === 'number' && Number.isFinite(rawMarginTop)) {
383
+ result.marginTop = rawMarginTop;
384
+ } else if (typeof rawMarginTop === 'string') {
385
+ const n = Number.parseInt(rawMarginTop, 10);
386
+ if (Number.isFinite(n)) result.marginTop = n;
387
+ }
388
+
351
389
  const rawWeight = style?.fontWeight;
352
390
  let normalizedWeight: string | undefined;
353
391
  if (typeof rawWeight === 'number' && Number.isFinite(rawWeight)) {
@@ -1,65 +1,34 @@
1
- import imagePattern from '../build-components/Image/pattern.json';
2
- import textPattern from '../build-components/Text/pattern.json';
3
- import buttonPattern from '../build-components/Button/pattern.json';
4
- import viewPattern from '../build-components/View/pattern.json';
5
- import carouselPattern from '../build-components/Carousel/pattern.json';
6
- import carouselButtonsPattern from '../build-components/CarouselButtons/pattern.json';
7
- import carouselDotsPattern from '../build-components/CarouselDots/pattern.json';
8
- import carouselItemPattern from '../build-components/CarouselItem/pattern.json';
9
- import carouselProviderPattern from '../build-components/CarouselProvider/pattern.json';
10
- import onboardPattern from '../build-components/Onboard/pattern.json';
11
- import onboardProviderPattern from '../build-components/OnboardProvider/pattern.json';
12
- import onboardItemPattern from '../build-components/OnboardItem/pattern.json';
13
- import onboardImagePattern from '../build-components/OnboardImage/pattern.json';
14
- import onboardButtonsPattern from '../build-components/OnboardButtons/pattern.json';
15
- import onboardButtonPattern from '../build-components/OnboardButton/pattern.json';
16
- import OnboardTitlePattern from '../build-components/OnboardTitle/pattern.json';
17
- import onboardSubtitlePattern from '../build-components/OnboardSubtitle/pattern.json';
18
- import onboardFooterPattern from '../build-components/OnboardFooter/pattern.json';
19
- import onboardExpandingDotPattern from '../build-components/OnboardDot/pattern.json';
1
+ import { patterns as generatedPatterns } from '../build-components';
20
2
  import type { NodeDefaultAttribute } from '../types/Node';
21
3
 
22
4
  type Pattern = {
23
5
  schemaVersion: number;
24
6
  allowUnknownAttributes: boolean;
7
+ extends: string;
25
8
  pattern: {
26
9
  type: string;
27
10
  children: unknown;
28
- attributes: Record<string, string | string[]>;
11
+ attributes?: Record<string, string | string[]>;
29
12
  };
13
+ defaults?: NodeDefaultAttribute;
14
+
30
15
  // Optional custom complex types referenced by attributes like "X[]" or "X"
31
16
  // Each entry maps a type name (e.g., "EventObject") to its field schema
32
17
  // where the inner record maps fieldName -> primitive type or enum options
33
18
  types?: Record<string, Record<string, string | string[]>>;
34
19
  // Optional defaults to be applied to node.attributes if not provided
35
- defaults?: NodeDefaultAttribute;
36
20
  };
37
21
 
38
- const patterns: Pattern[] = [
39
- imagePattern as Pattern,
40
- textPattern as Pattern,
41
- buttonPattern as Pattern,
42
- viewPattern as Pattern,
43
- carouselPattern as Pattern,
44
- carouselButtonsPattern as Pattern,
45
- carouselDotsPattern as Pattern,
46
- carouselItemPattern as Pattern,
47
- carouselProviderPattern as Pattern,
48
- onboardPattern as Pattern,
49
- onboardProviderPattern as Pattern,
50
- onboardItemPattern as Pattern,
51
- onboardImagePattern as Pattern,
52
- onboardButtonsPattern as Pattern,
53
- onboardButtonPattern as Pattern,
54
- OnboardTitlePattern as Pattern,
55
- onboardSubtitlePattern as Pattern,
56
- onboardFooterPattern as Pattern,
57
- onboardExpandingDotPattern as Pattern,
58
- ];
22
+ const patterns: Pattern[] = generatedPatterns as unknown as Pattern[];
23
+
24
+ // Build a fast lookup map without normalization for direct access
25
+ const patternIndex: Map<string, Pattern> = new Map(
26
+ patterns.map((p) => [p.pattern.type, p]),
27
+ );
59
28
 
60
- export function getPatternByType(type?: string | null) {
61
- if (!type) return undefined;
62
- return patterns.find((p) => p.pattern.type === type);
29
+ export function getPatternByType(type?: string | null): Pattern | undefined {
30
+ if (typeof type !== 'string') return undefined;
31
+ return patternIndex.get(type);
63
32
  }
64
33
 
65
34
  export function getAttributeSchema(
@@ -1,16 +0,0 @@
1
- import { Localication } from './types/PreviewConfig';
2
- export declare const mainNodeContext: import("react").Context<{
3
- localication?: Localication;
4
- defaultLanguage?: string;
5
- theme?: "light" | "dark";
6
- warning?: string;
7
- setWarning?: (message: string) => void;
8
- } | null>;
9
- export declare function RenderMainNode({ children, localication, defaultLanguage, theme, }: {
10
- localication?: Localication;
11
- defaultLanguage?: string;
12
- theme?: 'light' | 'dark';
13
- children: React.ReactNode;
14
- warning?: string;
15
- setWarning?: (message: string) => void;
16
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,37 +0,0 @@
1
- import { createContext, useState } from 'react';
2
- import { Node } from './index';
3
-
4
- import { Localication } from './types/PreviewConfig';
5
- import RenderNode from './build-components/RenderNode.generated';
6
- export const mainNodeContext = createContext<{
7
- localication?: Localication;
8
- defaultLanguage?: string;
9
- theme?: 'light' | 'dark';
10
- warning?: string;
11
- setWarning?: (message: string) => void;
12
- } | null>(null);
13
-
14
- export function RenderMainNode({
15
- children,
16
- localication,
17
- defaultLanguage,
18
- theme,
19
- }: {
20
- localication?: Localication;
21
- defaultLanguage?: string;
22
- theme?: 'light' | 'dark';
23
- children: React.ReactNode;
24
- warning?: string;
25
- setWarning?: (message: string) => void;
26
- }) {
27
- const [warning, setWarning] = useState<string>('');
28
-
29
- return (
30
- <mainNodeContext.Provider
31
- value={{ localication, defaultLanguage, theme, warning, setWarning }}
32
- >
33
- {warning && <div className="warning">{warning}</div>}
34
- {children}
35
- </mainNodeContext.Provider>
36
- );
37
- }