@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.
@@ -0,0 +1,2 @@
1
+ import { Node, NodeData } from '../types/Node';
2
+ export declare function querySelector(node: Node, selector: string): NodeData[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@developer_tribe/react-builder",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "type": "module",
5
5
  "restricted": true,
6
6
  "main": "dist/index.cjs.js",
@@ -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
- // no-op for web demo
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?: string;
8
- next_page_key?: string;
7
+ permission?: 'att' | 'notification' | 'rating' | 'null';
8
+ navigate_to?: 'string' | 'null';
9
9
  }
10
10
 
11
11
  export interface OnboardButtonPropsGenerated {
@@ -24,8 +24,8 @@
24
24
  "types": {
25
25
  "EventObject": {
26
26
  "type": ["Permission", "Navigate"],
27
- "permission": "string",
28
- "next_page_key": "string"
27
+ "permission": ["att", "notification", "rating", "null"],
28
+ "navigate_to": ["string", "null"]
29
29
  }
30
30
  }
31
31
  }
@@ -118,8 +118,8 @@ export const patterns = [
118
118
  types: {
119
119
  EventObject: {
120
120
  type: ['Permission', 'Navigate'],
121
- permission: 'string',
122
- next_page_key: 'string',
121
+ permission: ['att', 'notification', 'rating', 'null'],
122
+ navigate_to: ['string', 'null'],
123
123
  },
124
124
  },
125
125
  },
package/src/index.ts CHANGED
@@ -24,3 +24,4 @@ export type { Device } from './types/Device';
24
24
  export { AttributesEditor };
25
25
  export * from './build-components/index';
26
26
  export { default as useNode } from './build-components/useNode';
27
+ export { querySelector } from './utils/querySelector';
@@ -215,7 +215,7 @@ function buildCarouselItem(
215
215
  const normalizedEvents: {
216
216
  type: 'Permission' | 'Navigate';
217
217
  permission?: string;
218
- next_page_key?: string;
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
- next_page_key: nextKey,
243
+ navigate_to,
236
244
  });
237
- if (typeof nextKey === 'string' && pageKeyToIndex.has(nextKey)) {
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
+ }