@developer_tribe/react-builder 0.1.21 → 0.1.23
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/build-components/OnboardButtons/OnboardButtonsProps.generated.d.ts +2 -0
- package/dist/build-components/OnboardDot/OnboardDotProps.generated.d.ts +5 -0
- package/dist/build-components/OnboardProvider/OnboardProvider.d.ts +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/utils/isOnboard.d.ts +1 -1
- package/package.json +1 -1
- package/src/build-components/OnboardButton/OnboardButton.tsx +2 -2
- package/src/build-components/OnboardButtons/OnboardButtons.tsx +13 -14
- package/src/build-components/OnboardButtons/OnboardButtonsProps.generated.ts +2 -0
- package/src/build-components/OnboardButtons/pattern.json +3 -1
- package/src/build-components/OnboardDot/OnboardDotProps.generated.ts +5 -0
- package/src/build-components/OnboardDot/pattern.json +6 -1
- package/src/build-components/OnboardProvider/OnboardProvider.tsx +10 -5
- package/src/utils/isOnboard.ts +3 -3
- package/src/utils/novaToJson.ts +51 -5
- package/src/utils/patterns.ts +2 -2
|
@@ -3,6 +3,6 @@ export declare const isOnboardProvider: (node: Node) => node is NodeData;
|
|
|
3
3
|
export declare const isOnboard: (node: Node) => node is NodeData;
|
|
4
4
|
export declare const isOnboardItem: (node: Node) => node is NodeData;
|
|
5
5
|
export declare const isOnboardExpandingDot: (node: Node) => node is NodeData;
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const isOnboardTitle: (node: Node) => node is NodeData;
|
|
7
7
|
export declare const isOnboardSubtitle: (node: Node) => node is NodeData;
|
|
8
8
|
export declare const isOnboardComponent: (node: Node) => boolean;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
2
|
import type { OnboardButtonComponentProps } from './OnboardButtonProps.generated';
|
|
3
|
-
import {
|
|
3
|
+
import { onboardContext } from '../OnboardProvider/OnboardProvider';
|
|
4
4
|
import { mainNodeContext } from '../../RenderMainNode';
|
|
5
5
|
|
|
6
6
|
function OnboardButton({ node }: OnboardButtonComponentProps) {
|
|
7
|
-
const emblaApi = useContext(
|
|
7
|
+
const { emblaApi } = useContext(onboardContext) ?? {};
|
|
8
8
|
const { localication, defaultLanguage } = useContext(mainNodeContext) ?? {};
|
|
9
9
|
|
|
10
10
|
const labelRaw = node.attributes?.labelKey ?? '';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useContext, useEffect, useState } from 'react';
|
|
2
2
|
import type { Node } from '../../types/Node';
|
|
3
3
|
import type { OnboardButtonsComponentProps } from './OnboardButtonsProps.generated';
|
|
4
|
-
import {
|
|
4
|
+
import { onboardContext } from '../OnboardProvider/OnboardProvider';
|
|
5
5
|
import RenderNode from '../RenderNode.generated';
|
|
6
6
|
|
|
7
7
|
const THEME_COLORS = {
|
|
@@ -9,22 +9,21 @@ const THEME_COLORS = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
function OnboardButtons({ node }: OnboardButtonsComponentProps) {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const ctx = useContext(onboardContext) ?? {};
|
|
13
|
+
const emblaApi = ctx.emblaApi;
|
|
14
|
+
const [selectedIndex, setSelectedIndex] = useState(ctx.selectedIndex ?? 0);
|
|
14
15
|
|
|
15
16
|
useEffect(() => {
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
}, [emblaApi]);
|
|
17
|
+
if (typeof ctx.selectedIndex === 'number') {
|
|
18
|
+
setSelectedIndex(ctx.selectedIndex);
|
|
19
|
+
}
|
|
20
|
+
}, [ctx.selectedIndex]);
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
) {
|
|
27
|
-
return null;
|
|
22
|
+
// New condition logic: hide when condition is carousel-index and does not match
|
|
23
|
+
const condition = (node.attributes as any)?.condition;
|
|
24
|
+
const conditionVariable = (node.attributes as any)?.conditionVariable;
|
|
25
|
+
if (condition === 'carousel-index' && typeof conditionVariable === 'number') {
|
|
26
|
+
if (conditionVariable !== selectedIndex) return null;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
const direction =
|
|
@@ -12,6 +12,11 @@ export interface OnboardDotPropsGenerated {
|
|
|
12
12
|
| 'sliding_border'
|
|
13
13
|
| 'sliding_dot'
|
|
14
14
|
| 'liquid_like';
|
|
15
|
+
inactive_dot_opacity?: number;
|
|
16
|
+
expanding_dot_width?: number;
|
|
17
|
+
dot_style?: string;
|
|
18
|
+
container_style?: string;
|
|
19
|
+
active_dot_color?: string;
|
|
15
20
|
};
|
|
16
21
|
}
|
|
17
22
|
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
useEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
2
8
|
import type { NodeData } from '../../types/Node';
|
|
3
9
|
import type { OnboardProviderComponentProps } from './OnboardProviderProps.generated';
|
|
4
|
-
import { carouselContext } from '../CarouselProvider/CarouselProvider';
|
|
5
10
|
import { mainNodeContext } from '../../RenderMainNode';
|
|
6
|
-
import { isNodeArray } from '../../utils/analyseNode';
|
|
7
11
|
import useEmblaCarousel from 'embla-carousel-react';
|
|
8
12
|
import RenderNode from '../RenderNode.generated';
|
|
9
13
|
|
|
14
|
+
export const onboardContext = createContext<any>(undefined);
|
|
10
15
|
function OnboardProvider({ node }: OnboardProviderComponentProps) {
|
|
11
16
|
const [emblaRef, emblaApi] = useEmblaCarousel(node.attributes as any);
|
|
12
17
|
const { theme, setWarning } = useContext(mainNodeContext) ?? {};
|
|
@@ -43,7 +48,7 @@ function OnboardProvider({ node }: OnboardProviderComponentProps) {
|
|
|
43
48
|
}, [theme]);
|
|
44
49
|
|
|
45
50
|
return (
|
|
46
|
-
<
|
|
51
|
+
<onboardContext.Provider value={{ emblaApi, selectedIndex }}>
|
|
47
52
|
<div className="carousel-provider">
|
|
48
53
|
<div className="embla">
|
|
49
54
|
<div className="embla__viewport" ref={emblaRef}>
|
|
@@ -51,7 +56,7 @@ function OnboardProvider({ node }: OnboardProviderComponentProps) {
|
|
|
51
56
|
</div>
|
|
52
57
|
</div>
|
|
53
58
|
</div>
|
|
54
|
-
</
|
|
59
|
+
</onboardContext.Provider>
|
|
55
60
|
);
|
|
56
61
|
}
|
|
57
62
|
|
package/src/utils/isOnboard.ts
CHANGED
|
@@ -20,9 +20,9 @@ export const isOnboardExpandingDot = (node: Node): node is NodeData => {
|
|
|
20
20
|
return 'type' in node && (node as NodeData).type === 'OnboardExpandingDot';
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export const
|
|
23
|
+
export const isOnboardTitle = (node: Node): node is NodeData => {
|
|
24
24
|
if (!node || typeof node !== 'object' || Array.isArray(node)) return false;
|
|
25
|
-
return 'type' in node && (node as NodeData).type === '
|
|
25
|
+
return 'type' in node && (node as NodeData).type === 'OnboardTitle';
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
export const isOnboardSubtitle = (node: Node): node is NodeData => {
|
|
@@ -36,7 +36,7 @@ export const isOnboardComponent = (node: Node): boolean => {
|
|
|
36
36
|
isOnboard(node) ||
|
|
37
37
|
isOnboardItem(node) ||
|
|
38
38
|
isOnboardExpandingDot(node) ||
|
|
39
|
-
|
|
39
|
+
isOnboardTitle(node) ||
|
|
40
40
|
isOnboardSubtitle(node) ||
|
|
41
41
|
(function isOnboardButtons(n: Node): n is NodeData {
|
|
42
42
|
if (!n || typeof n !== 'object' || Array.isArray(n)) return false;
|
package/src/utils/novaToJson.ts
CHANGED
|
@@ -77,12 +77,19 @@ function buildCarouselItem(
|
|
|
77
77
|
const components = (page?.attributes?.components || []) as any[];
|
|
78
78
|
const children: Node[] = [];
|
|
79
79
|
|
|
80
|
+
// Resolve page index for condition mapping
|
|
81
|
+
const currentKey = page?.attributes?.key as string | undefined;
|
|
82
|
+
const pageIndex =
|
|
83
|
+
typeof currentKey === 'string' && pageKeyToIndex.has(currentKey)
|
|
84
|
+
? pageKeyToIndex.get(currentKey)!
|
|
85
|
+
: undefined;
|
|
86
|
+
|
|
80
87
|
for (const comp of components) {
|
|
81
88
|
if (comp?.layout === 'title-layout') {
|
|
82
89
|
const title = comp?.attributes?.title_localization_key || '';
|
|
83
90
|
const color = comp?.attributes?.title_color || undefined;
|
|
84
91
|
children.push({
|
|
85
|
-
type: '
|
|
92
|
+
type: 'OnboardTitle',
|
|
86
93
|
attributes: color ? { color } : undefined,
|
|
87
94
|
children: title,
|
|
88
95
|
});
|
|
@@ -195,11 +202,14 @@ function buildCarouselItem(
|
|
|
195
202
|
}
|
|
196
203
|
|
|
197
204
|
if (buttonNodes.length > 0) {
|
|
198
|
-
// Place buttons
|
|
199
|
-
|
|
205
|
+
// Place buttons at provider level with visibility conditioned by page index
|
|
206
|
+
providerLevelButtons.push({
|
|
200
207
|
type: 'OnboardButtons',
|
|
201
208
|
attributes: {
|
|
202
209
|
...(direction ? { buttons_direction: direction } : {}),
|
|
210
|
+
...(typeof pageIndex === 'number'
|
|
211
|
+
? { condition: 'carousel-index', conditionVariable: pageIndex }
|
|
212
|
+
: {}),
|
|
203
213
|
},
|
|
204
214
|
children: buttonNodes as unknown as Node,
|
|
205
215
|
} as unknown as NodeData);
|
|
@@ -223,16 +233,52 @@ function mapDotsFromGeneralComponents(generalComponents: any[]): Node | null {
|
|
|
223
233
|
const dots = generalComponents.find((gc) => gc?.layout === 'dots-layout');
|
|
224
234
|
if (!dots) return null;
|
|
225
235
|
const dotArray = dots?.attributes?.dot || [];
|
|
226
|
-
const
|
|
236
|
+
const firstDot = dotArray?.[0];
|
|
237
|
+
const dotType = firstDot?.layout as
|
|
227
238
|
| 'expanding_dot'
|
|
228
239
|
| 'normal_dot'
|
|
229
240
|
| 'scaling_dot'
|
|
230
241
|
| 'sliding_border'
|
|
231
242
|
| 'sliding_dot'
|
|
232
243
|
| 'liquid_like';
|
|
244
|
+
const dotAttrs = (firstDot?.attributes || {}) as Record<string, unknown>;
|
|
245
|
+
|
|
246
|
+
const parseNumber = (value: unknown): number | undefined => {
|
|
247
|
+
if (typeof value === 'number') return value;
|
|
248
|
+
if (typeof value === 'string' && value.trim().length > 0) {
|
|
249
|
+
const n = Number(value);
|
|
250
|
+
return Number.isFinite(n) ? n : undefined;
|
|
251
|
+
}
|
|
252
|
+
return undefined;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const inactiveDotOpacity = parseNumber(dotAttrs?.inactive_dot_opacity);
|
|
256
|
+
const expandingDotWidth = parseNumber(dotAttrs?.expanding_dot_width);
|
|
257
|
+
const dot_style =
|
|
258
|
+
typeof dotAttrs?.dot_style === 'string'
|
|
259
|
+
? (dotAttrs.dot_style as string)
|
|
260
|
+
: undefined;
|
|
261
|
+
const container_style =
|
|
262
|
+
typeof dotAttrs?.container_style === 'string'
|
|
263
|
+
? (dotAttrs.container_style as string)
|
|
264
|
+
: undefined;
|
|
265
|
+
const active_dot_color =
|
|
266
|
+
typeof dotAttrs?.active_dot_color === 'string'
|
|
267
|
+
? (dotAttrs.active_dot_color as string)
|
|
268
|
+
: undefined;
|
|
269
|
+
|
|
270
|
+
const attributes: Record<string, unknown> = {};
|
|
271
|
+
if (dotType) attributes.dotType = dotType;
|
|
272
|
+
if (inactiveDotOpacity !== undefined)
|
|
273
|
+
attributes.inactive_dot_opacity = inactiveDotOpacity;
|
|
274
|
+
if (expandingDotWidth !== undefined)
|
|
275
|
+
attributes.expanding_dot_width = expandingDotWidth;
|
|
276
|
+
if (dot_style) attributes.dot_style = dot_style;
|
|
277
|
+
if (container_style) attributes.container_style = container_style;
|
|
278
|
+
if (active_dot_color) attributes.active_dot_color = active_dot_color;
|
|
233
279
|
return {
|
|
234
280
|
type: 'OnboardDot',
|
|
235
|
-
attributes:
|
|
281
|
+
attributes: Object.keys(attributes).length ? attributes : undefined,
|
|
236
282
|
children: undefined as unknown as Node,
|
|
237
283
|
} as unknown as NodeData;
|
|
238
284
|
}
|
package/src/utils/patterns.ts
CHANGED
|
@@ -13,7 +13,7 @@ import onboardItemPattern from '../build-components/OnboardItem/pattern.json';
|
|
|
13
13
|
import onboardImagePattern from '../build-components/OnboardImage/pattern.json';
|
|
14
14
|
import onboardButtonsPattern from '../build-components/OnboardButtons/pattern.json';
|
|
15
15
|
import onboardButtonPattern from '../build-components/OnboardButton/pattern.json';
|
|
16
|
-
import
|
|
16
|
+
import OnboardTitlePattern from '../build-components/OnboardTitle/pattern.json';
|
|
17
17
|
import onboardSubtitlePattern from '../build-components/OnboardSubtitle/pattern.json';
|
|
18
18
|
import onboardFooterPattern from '../build-components/OnboardFooter/pattern.json';
|
|
19
19
|
import onboardExpandingDotPattern from '../build-components/OnboardDot/pattern.json';
|
|
@@ -48,7 +48,7 @@ const patterns: Pattern[] = [
|
|
|
48
48
|
onboardImagePattern as Pattern,
|
|
49
49
|
onboardButtonsPattern as Pattern,
|
|
50
50
|
onboardButtonPattern as Pattern,
|
|
51
|
-
|
|
51
|
+
OnboardTitlePattern as Pattern,
|
|
52
52
|
onboardSubtitlePattern as Pattern,
|
|
53
53
|
onboardFooterPattern as Pattern,
|
|
54
54
|
onboardExpandingDotPattern as Pattern,
|