@developer_tribe/react-builder 0.1.28 → 0.1.30
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/OnboardButton/OnboardButtonProps.generated.d.ts +2 -2
- package/dist/build-components/patterns.generated.d.ts +2 -2
- package/dist/index.cjs.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +2 -2
- package/dist/utils/querySelector.d.ts +2 -0
- package/package.json +1 -1
- package/src/build-components/OnboardButton/OnboardButton.tsx +6 -2
- package/src/build-components/OnboardButton/OnboardButtonProps.generated.ts +2 -2
- package/src/build-components/OnboardButton/pattern.json +2 -2
- package/src/build-components/patterns.generated.ts +2 -2
- package/src/index.ts +1 -0
- package/src/utils/novaToJson.ts +12 -4
- package/src/utils/querySelector.ts +43 -0
package/package.json
CHANGED
|
@@ -22,14 +22,18 @@ function OnboardButton({ node }: OnboardButtonComponentProps) {
|
|
|
22
22
|
|
|
23
23
|
const handleClick = () => {
|
|
24
24
|
const events = (node.attributes as any)?.events || [];
|
|
25
|
+
let navigateHandled = false;
|
|
25
26
|
for (const e of events) {
|
|
26
27
|
if (e.type === 'Permission') {
|
|
27
28
|
alert(`Permission requested: ${e.permission ?? 'unknown'}`);
|
|
28
29
|
} else if (e.type === 'Navigate') {
|
|
29
|
-
|
|
30
|
+
if (typeof node.attributes?.targetIndex === 'number') {
|
|
31
|
+
emblaApi?.scrollTo(node.attributes.targetIndex);
|
|
32
|
+
navigateHandled = true;
|
|
33
|
+
}
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
|
-
if (typeof node.attributes?.targetIndex === 'number') {
|
|
36
|
+
if (!navigateHandled && typeof node.attributes?.targetIndex === 'number') {
|
|
33
37
|
emblaApi?.scrollTo(node.attributes.targetIndex);
|
|
34
38
|
}
|
|
35
39
|
};
|
|
@@ -4,8 +4,8 @@ import type { NodeData } from '../../types/Node';
|
|
|
4
4
|
|
|
5
5
|
export interface EventObjectGenerated {
|
|
6
6
|
type?: 'Permission' | 'Navigate';
|
|
7
|
-
permission?:
|
|
8
|
-
|
|
7
|
+
permission?: 'att' | 'notification' | 'rating' | 'null';
|
|
8
|
+
navigate_to?: 'string' | 'null';
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface OnboardButtonPropsGenerated {
|
|
@@ -118,8 +118,8 @@ export const patterns = [
|
|
|
118
118
|
types: {
|
|
119
119
|
EventObject: {
|
|
120
120
|
type: ['Permission', 'Navigate'],
|
|
121
|
-
permission: '
|
|
122
|
-
|
|
121
|
+
permission: ['att', 'notification', 'rating', 'null'],
|
|
122
|
+
navigate_to: ['string', 'null'],
|
|
123
123
|
},
|
|
124
124
|
},
|
|
125
125
|
},
|
package/src/index.ts
CHANGED
package/src/utils/novaToJson.ts
CHANGED
|
@@ -215,7 +215,7 @@ function buildCarouselItem(
|
|
|
215
215
|
const normalizedEvents: {
|
|
216
216
|
type: 'Permission' | 'Navigate';
|
|
217
217
|
permission?: string;
|
|
218
|
-
|
|
218
|
+
navigate_to?: string | null;
|
|
219
219
|
}[] = [];
|
|
220
220
|
for (const action of actions) {
|
|
221
221
|
//@eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -230,12 +230,20 @@ function buildCarouselItem(
|
|
|
230
230
|
const nextKey = e?.attributes?.next_page_key as
|
|
231
231
|
| string
|
|
232
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;
|
|
233
241
|
normalizedEvents.push({
|
|
234
242
|
type: 'Navigate',
|
|
235
|
-
|
|
243
|
+
navigate_to,
|
|
236
244
|
});
|
|
237
|
-
if (
|
|
238
|
-
targetIndex = pageKeyToIndex.get(nextKey)!;
|
|
245
|
+
if (hasTarget) {
|
|
246
|
+
targetIndex = pageKeyToIndex.get(nextKey!)!;
|
|
239
247
|
}
|
|
240
248
|
}
|
|
241
249
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Node, NodeData } from '../types/Node';
|
|
2
|
+
|
|
3
|
+
function isNodeData(value: Node): value is NodeData<Record<string, unknown>> {
|
|
4
|
+
if (value === null || value === undefined) return false;
|
|
5
|
+
if (Array.isArray(value)) return false;
|
|
6
|
+
if (typeof value === 'string') return false;
|
|
7
|
+
if (typeof value !== 'object') return false;
|
|
8
|
+
return (
|
|
9
|
+
'type' in (value as Record<string, unknown>) &&
|
|
10
|
+
'children' in (value as Record<string, unknown>)
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function querySelector(node: Node, selector: string): NodeData[] {
|
|
15
|
+
if (node === null || node === undefined) return [];
|
|
16
|
+
if (!selector) return [];
|
|
17
|
+
|
|
18
|
+
const isKeySearch = selector.startsWith('#');
|
|
19
|
+
const keyToMatch = isKeySearch ? selector.slice(1) : undefined;
|
|
20
|
+
|
|
21
|
+
const matches = (n: NodeData): boolean => {
|
|
22
|
+
if (isKeySearch) return n.key === keyToMatch;
|
|
23
|
+
return n.type === selector;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const result: NodeData[] = [];
|
|
27
|
+
|
|
28
|
+
const visit = (current: Node) => {
|
|
29
|
+
if (current === null || current === undefined) return;
|
|
30
|
+
if (Array.isArray(current)) {
|
|
31
|
+
for (const child of current) visit(child);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (typeof current === 'string') return;
|
|
35
|
+
if (isNodeData(current)) {
|
|
36
|
+
if (matches(current)) result.push(current);
|
|
37
|
+
visit(current.children);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
visit(node);
|
|
42
|
+
return result;
|
|
43
|
+
}
|