@developer_tribe/react-builder 0.1.23 → 0.1.25

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 (59) hide show
  1. package/dist/build-components/Button/getDefaults.d.ts +3 -0
  2. package/dist/build-components/Carousel/getDefaults.d.ts +3 -0
  3. package/dist/build-components/CarouselButtons/getDefaults.d.ts +3 -0
  4. package/dist/build-components/CarouselDots/getDefaults.d.ts +3 -0
  5. package/dist/build-components/CarouselItem/getDefaults.d.ts +3 -0
  6. package/dist/build-components/CarouselProvider/getDefaults.d.ts +3 -0
  7. package/dist/build-components/Image/getDefaults.d.ts +3 -0
  8. package/dist/build-components/Onboard/getDefaults.d.ts +3 -0
  9. package/dist/build-components/OnboardButton/getDefaults.d.ts +3 -0
  10. package/dist/build-components/OnboardButtons/getDefaults.d.ts +3 -0
  11. package/dist/build-components/OnboardDot/getDefaults.d.ts +3 -0
  12. package/dist/build-components/OnboardFooter/getDefaults.d.ts +3 -0
  13. package/dist/build-components/OnboardImage/getDefaults.d.ts +3 -0
  14. package/dist/build-components/OnboardItem/getDefaults.d.ts +3 -0
  15. package/dist/build-components/OnboardProvider/getDefaults.d.ts +3 -0
  16. package/dist/build-components/OnboardSubtitle/getDefaults.d.ts +3 -0
  17. package/dist/build-components/OnboardTitle/getDefaults.d.ts +3 -0
  18. package/dist/build-components/Text/getDefaults.d.ts +3 -0
  19. package/dist/build-components/View/getDefaults.d.ts +3 -0
  20. package/dist/build-components/getDefaults.d.ts +25 -0
  21. package/dist/build-components/index.d.ts +1 -0
  22. package/dist/index.cjs.js +1 -1
  23. package/dist/index.esm.js +1 -1
  24. package/dist/types/Device.d.ts +2 -2
  25. package/package.json +1 -1
  26. package/scripts/prebuild/build-components.js +4 -0
  27. package/scripts/prebuild/utils/createBuildComponentsIndex.js +4 -1
  28. package/scripts/prebuild/utils/createBuildComponentsRootGetDefaults.js +64 -0
  29. package/scripts/prebuild/utils/createGetDefaultsPerComponent.js +28 -0
  30. package/scripts/prebuild/utils/createRootGetDefaults.js +52 -0
  31. package/scripts/prebuild/utils/index.js +3 -0
  32. package/scripts/prebuild/utils/validateAllComponentsOrThrow.js +2 -2
  33. package/src/assets/devices.json +88 -88
  34. package/src/build-components/Button/getDefaults.ts +11 -0
  35. package/src/build-components/Carousel/getDefaults.ts +11 -0
  36. package/src/build-components/CarouselButtons/getDefaults.ts +13 -0
  37. package/src/build-components/CarouselDots/getDefaults.ts +13 -0
  38. package/src/build-components/CarouselItem/getDefaults.ts +13 -0
  39. package/src/build-components/CarouselProvider/getDefaults.ts +13 -0
  40. package/src/build-components/Image/getDefaults.ts +11 -0
  41. package/src/build-components/Onboard/getDefaults.ts +11 -0
  42. package/src/build-components/OnboardButton/getDefaults.ts +13 -0
  43. package/src/build-components/OnboardButtons/getDefaults.ts +13 -0
  44. package/src/build-components/OnboardDot/getDefaults.ts +13 -0
  45. package/src/build-components/OnboardFooter/OnboardFooter.tsx +157 -14
  46. package/src/build-components/OnboardFooter/getDefaults.ts +13 -0
  47. package/src/build-components/OnboardImage/getDefaults.ts +13 -0
  48. package/src/build-components/OnboardItem/getDefaults.ts +13 -0
  49. package/src/build-components/OnboardProvider/getDefaults.ts +13 -0
  50. package/src/build-components/OnboardSubtitle/getDefaults.ts +13 -0
  51. package/src/build-components/OnboardSubtitle/pattern.json +4 -0
  52. package/src/build-components/OnboardTitle/getDefaults.ts +13 -0
  53. package/src/build-components/OnboardTitle/pattern.json +4 -0
  54. package/src/build-components/Text/getDefaults.ts +11 -0
  55. package/src/build-components/View/getDefaults.ts +11 -0
  56. package/src/build-components/getDefaults.ts +149 -0
  57. package/src/build-components/index.ts +2 -0
  58. package/src/types/Device.ts +2 -2
  59. package/src/utils/getDevices.ts +7 -1
@@ -0,0 +1,11 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { ButtonPropsGenerated } from './ButtonProps.generated';
5
+
6
+ export type ButtonDefaults = Partial<ButtonPropsGenerated['attributes']>;
7
+
8
+ export function getDefaults(): ButtonDefaults {
9
+ return ((pattern as unknown as { default?: unknown })?.default ??
10
+ {}) as ButtonDefaults;
11
+ }
@@ -0,0 +1,11 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { CarouselPropsGenerated } from './CarouselProps.generated';
5
+
6
+ export type CarouselDefaults = Partial<CarouselPropsGenerated['attributes']>;
7
+
8
+ export function getDefaults(): CarouselDefaults {
9
+ return ((pattern as unknown as { default?: unknown })?.default ??
10
+ {}) as CarouselDefaults;
11
+ }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { CarouselButtonsPropsGenerated } from './CarouselButtonsProps.generated';
5
+
6
+ export type CarouselButtonsDefaults = Partial<
7
+ CarouselButtonsPropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): CarouselButtonsDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as CarouselButtonsDefaults;
13
+ }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { CarouselDotsPropsGenerated } from './CarouselDotsProps.generated';
5
+
6
+ export type CarouselDotsDefaults = Partial<
7
+ CarouselDotsPropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): CarouselDotsDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as CarouselDotsDefaults;
13
+ }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { CarouselItemPropsGenerated } from './CarouselItemProps.generated';
5
+
6
+ export type CarouselItemDefaults = Partial<
7
+ CarouselItemPropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): CarouselItemDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as CarouselItemDefaults;
13
+ }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { CarouselProviderPropsGenerated } from './CarouselProviderProps.generated';
5
+
6
+ export type CarouselProviderDefaults = Partial<
7
+ CarouselProviderPropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): CarouselProviderDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as CarouselProviderDefaults;
13
+ }
@@ -0,0 +1,11 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { ImagePropsGenerated } from './ImageProps.generated';
5
+
6
+ export type ImageDefaults = Partial<ImagePropsGenerated['attributes']>;
7
+
8
+ export function getDefaults(): ImageDefaults {
9
+ return ((pattern as unknown as { default?: unknown })?.default ??
10
+ {}) as ImageDefaults;
11
+ }
@@ -0,0 +1,11 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { OnboardPropsGenerated } from './OnboardProps.generated';
5
+
6
+ export type OnboardDefaults = Partial<OnboardPropsGenerated['attributes']>;
7
+
8
+ export function getDefaults(): OnboardDefaults {
9
+ return ((pattern as unknown as { default?: unknown })?.default ??
10
+ {}) as OnboardDefaults;
11
+ }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { OnboardButtonPropsGenerated } from './OnboardButtonProps.generated';
5
+
6
+ export type OnboardButtonDefaults = Partial<
7
+ OnboardButtonPropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): OnboardButtonDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as OnboardButtonDefaults;
13
+ }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { OnboardButtonsPropsGenerated } from './OnboardButtonsProps.generated';
5
+
6
+ export type OnboardButtonsDefaults = Partial<
7
+ OnboardButtonsPropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): OnboardButtonsDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as OnboardButtonsDefaults;
13
+ }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { OnboardDotPropsGenerated } from './OnboardDotProps.generated';
5
+
6
+ export type OnboardDotDefaults = Partial<
7
+ OnboardDotPropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): OnboardDotDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as OnboardDotDefaults;
13
+ }
@@ -2,8 +2,89 @@ import React, { useContext } from 'react';
2
2
  import type { OnboardFooterComponentProps } from './OnboardFooterProps.generated';
3
3
  import { mainNodeContext } from '../../RenderMainNode';
4
4
 
5
+ type Segment =
6
+ | { type: 'text'; value: string }
7
+ | {
8
+ type: 'match';
9
+ value: string;
10
+ color?: string;
11
+ page?: string;
12
+ };
13
+
14
+ function escapeRegExp(str: string) {
15
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
16
+ }
17
+
18
+ function buildSegments(
19
+ text: string,
20
+ patterns: { value: string; color?: string; page?: string }[],
21
+ ): { segments: Segment[]; matchCount: number } {
22
+ type RawMatch = {
23
+ start: number;
24
+ end: number;
25
+ value: string;
26
+ color?: string;
27
+ page?: string;
28
+ };
29
+
30
+ const rawMatches: RawMatch[] = [];
31
+
32
+ for (const p of patterns) {
33
+ if (!p.value) continue;
34
+ const re = new RegExp(escapeRegExp(p.value), 'gi');
35
+ for (const m of text.matchAll(re)) {
36
+ if (m.index == null) continue;
37
+ const matched = m[0];
38
+ if (!matched) continue;
39
+ rawMatches.push({
40
+ start: m.index,
41
+ end: m.index + matched.length,
42
+ value: matched,
43
+ color: p.color,
44
+ page: p.page,
45
+ });
46
+ }
47
+ }
48
+
49
+ if (rawMatches.length === 0) {
50
+ return { segments: [{ type: 'text', value: text }], matchCount: 0 };
51
+ }
52
+
53
+ rawMatches.sort((a, b) => {
54
+ if (a.start !== b.start) return a.start - b.start;
55
+ const lenA = a.end - a.start;
56
+ const lenB = b.end - b.start;
57
+ return lenB - lenA;
58
+ });
59
+
60
+ const kept: RawMatch[] = [];
61
+ let lastEnd = -1;
62
+ for (const m of rawMatches) {
63
+ if (m.start >= lastEnd) {
64
+ kept.push(m);
65
+ lastEnd = m.end;
66
+ }
67
+ }
68
+
69
+ const segments: Segment[] = [];
70
+ let cursor = 0;
71
+ for (const { start, end, value, color, page } of kept) {
72
+ if (start > cursor) {
73
+ segments.push({ type: 'text', value: text.slice(cursor, start) });
74
+ }
75
+ segments.push({ type: 'match', value, color, page });
76
+ cursor = end;
77
+ }
78
+ if (cursor < text.length) {
79
+ segments.push({ type: 'text', value: text.slice(cursor) });
80
+ }
81
+
82
+ return { segments, matchCount: kept.length };
83
+ }
84
+
5
85
  function OnboardFooter({ node }: OnboardFooterComponentProps) {
6
- const { localication, defaultLanguage } = useContext(mainNodeContext) ?? {};
86
+ const { localication, defaultLanguage, setWarning } =
87
+ useContext(mainNodeContext) ?? {};
7
88
  const t = (key?: string) =>
8
89
  key ? (localication?.[defaultLanguage ?? 'en']?.[key] ?? key) : '';
9
90
 
@@ -44,19 +125,81 @@ function OnboardFooter({ node }: OnboardFooterComponentProps) {
44
125
 
45
126
  return (
46
127
  <div className="primitive primitive-footer" style={style}>
47
- {!!text && <p style={{ color: node?.attributes?.textColor }}>{text}</p>}
48
- <div style={{ display: 'flex', gap: 8 }}>
49
- {node?.attributes?.linkedWordFirstLocalizationKey && (
50
- <span style={linkStyle(node?.attributes?.linkedWordFirstColor)}>
51
- {t(node?.attributes?.linkedWordFirstLocalizationKey)}
52
- </span>
53
- )}
54
- {node?.attributes?.linkedWordSecondLocalizationKey && (
55
- <span style={linkStyle(node?.attributes?.linkedWordSecondColor)}>
56
- {t(node?.attributes?.linkedWordSecondLocalizationKey)}
57
- </span>
58
- )}
59
- </div>
128
+ {!!text &&
129
+ (() => {
130
+ const firstText = t(node?.attributes?.linkedWordFirstLocalizationKey);
131
+ const secondText = t(
132
+ node?.attributes?.linkedWordSecondLocalizationKey,
133
+ );
134
+ const { segments, matchCount } = buildSegments(text, [
135
+ {
136
+ value: firstText,
137
+ color: node?.attributes?.linkedWordFirstColor,
138
+ page: (node?.attributes as any)?.linkedWordFirstPage,
139
+ },
140
+ {
141
+ value: secondText,
142
+ color: node?.attributes?.linkedWordSecondColor,
143
+ page: (node?.attributes as any)?.linkedWordSecondPage,
144
+ },
145
+ ]);
146
+
147
+ const textColor = node?.attributes?.textColor;
148
+
149
+ const handleClick = (page?: string) => {
150
+ if (!page) return;
151
+ // Demo environment: surface intent via warning banner if available
152
+ if (setWarning) setWarning(`Navigate to page: ${page}`);
153
+ };
154
+
155
+ return (
156
+ <>
157
+ <p style={{ color: textColor }}>
158
+ {segments.map((seg, i) =>
159
+ seg.type === 'text' ? (
160
+ <span key={i}>{seg.value}</span>
161
+ ) : (
162
+ <span
163
+ key={i}
164
+ style={linkStyle(seg.color)}
165
+ onClick={() => handleClick(seg.page)}
166
+ >
167
+ {seg.value}
168
+ </span>
169
+ ),
170
+ )}
171
+ </p>
172
+ {matchCount === 0 && (
173
+ <div style={{ display: 'flex', gap: 8 }}>
174
+ {node?.attributes?.linkedWordFirstLocalizationKey && (
175
+ <span
176
+ style={linkStyle(node?.attributes?.linkedWordFirstColor)}
177
+ onClick={() =>
178
+ handleClick(
179
+ (node?.attributes as any)?.linkedWordFirstPage,
180
+ )
181
+ }
182
+ >
183
+ {firstText}
184
+ </span>
185
+ )}
186
+ {node?.attributes?.linkedWordSecondLocalizationKey && (
187
+ <span
188
+ style={linkStyle(node?.attributes?.linkedWordSecondColor)}
189
+ onClick={() =>
190
+ handleClick(
191
+ (node?.attributes as any)?.linkedWordSecondPage,
192
+ )
193
+ }
194
+ >
195
+ {secondText}
196
+ </span>
197
+ )}
198
+ </div>
199
+ )}
200
+ </>
201
+ );
202
+ })()}
60
203
  </div>
61
204
  );
62
205
  }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { OnboardFooterPropsGenerated } from './OnboardFooterProps.generated';
5
+
6
+ export type OnboardFooterDefaults = Partial<
7
+ OnboardFooterPropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): OnboardFooterDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as OnboardFooterDefaults;
13
+ }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { OnboardImagePropsGenerated } from './OnboardImageProps.generated';
5
+
6
+ export type OnboardImageDefaults = Partial<
7
+ OnboardImagePropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): OnboardImageDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as OnboardImageDefaults;
13
+ }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { OnboardItemPropsGenerated } from './OnboardItemProps.generated';
5
+
6
+ export type OnboardItemDefaults = Partial<
7
+ OnboardItemPropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): OnboardItemDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as OnboardItemDefaults;
13
+ }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { OnboardProviderPropsGenerated } from './OnboardProviderProps.generated';
5
+
6
+ export type OnboardProviderDefaults = Partial<
7
+ OnboardProviderPropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): OnboardProviderDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as OnboardProviderDefaults;
13
+ }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { OnboardSubtitlePropsGenerated } from './OnboardSubtitleProps.generated';
5
+
6
+ export type OnboardSubtitleDefaults = Partial<
7
+ OnboardSubtitlePropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): OnboardSubtitleDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as OnboardSubtitleDefaults;
13
+ }
@@ -21,5 +21,9 @@
21
21
  "900"
22
22
  ]
23
23
  }
24
+ },
25
+ "default": {
26
+ "fontSize": 14,
27
+ "fontWeight": "600"
24
28
  }
25
29
  }
@@ -0,0 +1,13 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { OnboardTitlePropsGenerated } from './OnboardTitleProps.generated';
5
+
6
+ export type OnboardTitleDefaults = Partial<
7
+ OnboardTitlePropsGenerated['attributes']
8
+ >;
9
+
10
+ export function getDefaults(): OnboardTitleDefaults {
11
+ return ((pattern as unknown as { default?: unknown })?.default ??
12
+ {}) as OnboardTitleDefaults;
13
+ }
@@ -21,5 +21,9 @@
21
21
  "900"
22
22
  ]
23
23
  }
24
+ },
25
+ "default": {
26
+ "fontSize": 24,
27
+ "fontWeight": "700"
24
28
  }
25
29
  }
@@ -0,0 +1,11 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { TextPropsGenerated } from './TextProps.generated';
5
+
6
+ export type TextDefaults = Partial<TextPropsGenerated['attributes']>;
7
+
8
+ export function getDefaults(): TextDefaults {
9
+ return ((pattern as unknown as { default?: unknown })?.default ??
10
+ {}) as TextDefaults;
11
+ }
@@ -0,0 +1,11 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import pattern from './pattern.json';
4
+ import type { ViewPropsGenerated } from './ViewProps.generated';
5
+
6
+ export type ViewDefaults = Partial<ViewPropsGenerated['attributes']>;
7
+
8
+ export function getDefaults(): ViewDefaults {
9
+ return ((pattern as unknown as { default?: unknown })?.default ??
10
+ {}) as ViewDefaults;
11
+ }
@@ -0,0 +1,149 @@
1
+ /* AUTO-GENERATED FILE - DO NOT EDIT */
2
+
3
+ import { getDefaults as getButtonDefaults } from './Button/getDefaults';
4
+ import { getDefaults as getCarouselDefaults } from './Carousel/getDefaults';
5
+ import { getDefaults as getCarouselButtonsDefaults } from './CarouselButtons/getDefaults';
6
+ import { getDefaults as getCarouselDotsDefaults } from './CarouselDots/getDefaults';
7
+ import { getDefaults as getCarouselItemDefaults } from './CarouselItem/getDefaults';
8
+ import { getDefaults as getCarouselProviderDefaults } from './CarouselProvider/getDefaults';
9
+ import { getDefaults as getImageDefaults } from './Image/getDefaults';
10
+ import { getDefaults as getOnboardDefaults } from './Onboard/getDefaults';
11
+ import { getDefaults as getOnboardButtonDefaults } from './OnboardButton/getDefaults';
12
+ import { getDefaults as getOnboardButtonsDefaults } from './OnboardButtons/getDefaults';
13
+ import { getDefaults as getOnboardDotDefaults } from './OnboardDot/getDefaults';
14
+ import { getDefaults as getOnboardFooterDefaults } from './OnboardFooter/getDefaults';
15
+ import { getDefaults as getOnboardImageDefaults } from './OnboardImage/getDefaults';
16
+ import { getDefaults as getOnboardItemDefaults } from './OnboardItem/getDefaults';
17
+ import { getDefaults as getOnboardProviderDefaults } from './OnboardProvider/getDefaults';
18
+ import { getDefaults as getOnboardSubtitleDefaults } from './OnboardSubtitle/getDefaults';
19
+ import { getDefaults as getOnboardTitleDefaults } from './OnboardTitle/getDefaults';
20
+ import { getDefaults as getTextDefaults } from './Text/getDefaults';
21
+ import { getDefaults as getViewDefaults } from './View/getDefaults';
22
+ import type {
23
+ ButtonPropsGenerated,
24
+ CarouselPropsGenerated,
25
+ CarouselButtonsPropsGenerated,
26
+ CarouselDotsPropsGenerated,
27
+ CarouselItemPropsGenerated,
28
+ CarouselProviderPropsGenerated,
29
+ ImagePropsGenerated,
30
+ OnboardPropsGenerated,
31
+ OnboardButtonPropsGenerated,
32
+ OnboardButtonsPropsGenerated,
33
+ OnboardDotPropsGenerated,
34
+ OnboardFooterPropsGenerated,
35
+ OnboardImagePropsGenerated,
36
+ OnboardItemPropsGenerated,
37
+ OnboardProviderPropsGenerated,
38
+ OnboardSubtitlePropsGenerated,
39
+ OnboardTitlePropsGenerated,
40
+ TextPropsGenerated,
41
+ ViewPropsGenerated,
42
+ } from './index';
43
+ import type { NodeData } from '../types/Node';
44
+
45
+ export type Types = {
46
+ button: ButtonPropsGenerated['attributes'];
47
+ carousel: CarouselPropsGenerated['attributes'];
48
+ carouselButtons: CarouselButtonsPropsGenerated['attributes'];
49
+ carouselDots: CarouselDotsPropsGenerated['attributes'];
50
+ carouselItem: CarouselItemPropsGenerated['attributes'];
51
+ carouselProvider: CarouselProviderPropsGenerated['attributes'];
52
+ image: ImagePropsGenerated['attributes'];
53
+ Onboard: OnboardPropsGenerated['attributes'];
54
+ OnboardButton: OnboardButtonPropsGenerated['attributes'];
55
+ OnboardButtons: OnboardButtonsPropsGenerated['attributes'];
56
+ OnboardDot: OnboardDotPropsGenerated['attributes'];
57
+ OnboardFooter: OnboardFooterPropsGenerated['attributes'];
58
+ OnboardImage: OnboardImagePropsGenerated['attributes'];
59
+ OnboardItem: OnboardItemPropsGenerated['attributes'];
60
+ OnboardProvider: OnboardProviderPropsGenerated['attributes'];
61
+ OnboardSubtitle: OnboardSubtitlePropsGenerated['attributes'];
62
+ OnboardTitle: OnboardTitlePropsGenerated['attributes'];
63
+ text: TextPropsGenerated['attributes'];
64
+ view: ViewPropsGenerated['attributes'];
65
+ };
66
+
67
+ export type List<T> = T extends keyof Types ? Types[T] : never;
68
+
69
+ export function getDefaults<T extends keyof Types>(
70
+ type: T,
71
+ node: NodeData<List<T>>,
72
+ ): Partial<Types[T]> {
73
+ let defaults: Partial<Types[T]> = {};
74
+
75
+ switch (type as unknown as string) {
76
+ case 'button':
77
+ defaults = getButtonDefaults() as Partial<Types[T]>;
78
+ break;
79
+ case 'carousel':
80
+ defaults = getCarouselDefaults() as Partial<Types[T]>;
81
+ break;
82
+ case 'carouselButtons':
83
+ defaults = getCarouselButtonsDefaults() as Partial<Types[T]>;
84
+ break;
85
+ case 'carouselDots':
86
+ defaults = getCarouselDotsDefaults() as Partial<Types[T]>;
87
+ break;
88
+ case 'carouselItem':
89
+ defaults = getCarouselItemDefaults() as Partial<Types[T]>;
90
+ break;
91
+ case 'carouselProvider':
92
+ defaults = getCarouselProviderDefaults() as Partial<Types[T]>;
93
+ break;
94
+ case 'image':
95
+ defaults = getImageDefaults() as Partial<Types[T]>;
96
+ break;
97
+ case 'Onboard':
98
+ defaults = getOnboardDefaults() as Partial<Types[T]>;
99
+ break;
100
+ case 'OnboardButton':
101
+ defaults = getOnboardButtonDefaults() as Partial<Types[T]>;
102
+ break;
103
+ case 'OnboardButtons':
104
+ defaults = getOnboardButtonsDefaults() as Partial<Types[T]>;
105
+ break;
106
+ case 'OnboardDot':
107
+ defaults = getOnboardDotDefaults() as Partial<Types[T]>;
108
+ break;
109
+ case 'OnboardFooter':
110
+ defaults = getOnboardFooterDefaults() as Partial<Types[T]>;
111
+ break;
112
+ case 'OnboardImage':
113
+ defaults = getOnboardImageDefaults() as Partial<Types[T]>;
114
+ break;
115
+ case 'OnboardItem':
116
+ defaults = getOnboardItemDefaults() as Partial<Types[T]>;
117
+ break;
118
+ case 'OnboardProvider':
119
+ defaults = getOnboardProviderDefaults() as Partial<Types[T]>;
120
+ break;
121
+ case 'OnboardSubtitle':
122
+ defaults = getOnboardSubtitleDefaults() as Partial<Types[T]>;
123
+ break;
124
+ case 'OnboardTitle':
125
+ defaults = getOnboardTitleDefaults() as Partial<Types[T]>;
126
+ break;
127
+ case 'text':
128
+ defaults = getTextDefaults() as Partial<Types[T]>;
129
+ break;
130
+ case 'view':
131
+ defaults = getViewDefaults() as Partial<Types[T]>;
132
+ break;
133
+ default:
134
+ defaults = {} as Partial<Types[T]>;
135
+ }
136
+
137
+ if (
138
+ (node as unknown as { type?: string })?.type !== (type as unknown as string)
139
+ ) {
140
+ throw new Error(
141
+ `getDefaults: node.type mismatch; expected ${String(type)}, received ${(node as unknown as { type?: string })?.type ?? 'undefined'}`,
142
+ );
143
+ }
144
+
145
+ (node as unknown as { attributes?: unknown }).attributes =
146
+ defaults as Types[T];
147
+
148
+ return defaults;
149
+ }
@@ -2,6 +2,8 @@
2
2
 
3
3
  export { default as RenderNode } from './RenderNode.generated';
4
4
 
5
+ export { getDefaults } from './getDefaults';
6
+
5
7
  export type {
6
8
  ButtonPropsGenerated,
7
9
  ButtonComponentProps,
@@ -6,7 +6,7 @@ export interface Device {
6
6
  type: 'phone' | 'tablet';
7
7
  /**
8
8
  * Relative importance for generic targeting and display ordering.
9
- * 1 = highest importance, 5 = lowest importance
9
+ * 1 = highest importance, 100 = lowest importance
10
10
  */
11
- importance?: 1 | 2 | 3 | 4 | 5;
11
+ importance?: number;
12
12
  }
@@ -2,5 +2,11 @@ import { Device } from '../types/Device';
2
2
  import devices from '../assets/devices.json';
3
3
 
4
4
  export function getDevices(): Device[] {
5
- return devices as Device[];
5
+ const deviceList = (devices as Device[]).slice();
6
+ deviceList.sort((a, b) => {
7
+ const ai = a.importance ?? 999;
8
+ const bi = b.importance ?? 999;
9
+ return ai - bi;
10
+ });
11
+ return deviceList;
6
12
  }