@developer_tribe/react-builder 0.1.16 → 0.1.18

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.
@@ -229,25 +229,56 @@ function mapFooterFromGeneralComponents(generalComponents: any[]): Node | null {
229
229
  const footer = generalComponents.find((gc) => gc?.layout === 'footer-layout');
230
230
  if (!footer) return null;
231
231
  const texts = (footer?.attributes?.texts || []) as any[];
232
- const children: Node[] = [];
232
+ const linkedWords: { text_key?: string; color?: string; page?: string }[] =
233
+ [];
234
+ let baseTextKey: string | undefined;
235
+ let baseTextColor: string | undefined;
233
236
 
234
237
  for (const t of texts) {
235
238
  if (t?.layout === 'Text') {
236
239
  const textKey = t?.attributes?.text_localization_key || '';
237
240
  const color = t?.attributes?.text_color || undefined;
238
- children.push({
239
- type: 'text',
240
- attributes: color ? { color } : undefined,
241
- children: textKey,
242
- });
241
+ if (!baseTextKey) baseTextKey = textKey;
242
+ if (!baseTextColor && typeof color === 'string') baseTextColor = color;
243
+
244
+ // Extract linked words if present
245
+ const lws = (t?.attributes?.linkedwords || []) as any[];
246
+ for (const w of lws) {
247
+ if (w?.layout === 'LinkedWords') {
248
+ const text_key = w?.attributes?.linked_word_localization_key as
249
+ | string
250
+ | undefined;
251
+ const lwColor = w?.attributes?.linked_word_color as
252
+ | string
253
+ | undefined;
254
+ const page = w?.attributes?.page as string | undefined;
255
+ linkedWords.push({ text_key, color: lwColor, page });
256
+ }
257
+ }
243
258
  }
244
259
  }
245
260
 
246
- if (children.length === 0) return null;
261
+ const attributes: Record<string, unknown> = { gap: 8 };
262
+ if (baseTextKey) attributes.textLocalizationKey = baseTextKey;
263
+ if (baseTextColor) attributes.textColor = baseTextColor;
264
+ const first = linkedWords[0];
265
+ const second = linkedWords[1];
266
+ if (first) {
267
+ if (first.text_key)
268
+ attributes.linkedWordFirstLocalizationKey = first.text_key;
269
+ if (first.color) attributes.linkedWordFirstColor = first.color;
270
+ if (first.page) attributes.linkedWordFirstPage = first.page;
271
+ }
272
+ if (second) {
273
+ if (second.text_key)
274
+ attributes.linkedWordSecondLocalizationKey = second.text_key;
275
+ if (second.color) attributes.linkedWordSecondColor = second.color;
276
+ if (second.page) attributes.linkedWordSecondPage = second.page;
277
+ }
247
278
 
248
279
  return {
249
280
  type: 'OnboardFooter',
250
- attributes: { gap: 8 },
251
- children,
281
+ attributes,
282
+ children: undefined as unknown as Node,
252
283
  } as NodeData;
253
284
  }
@@ -26,6 +26,10 @@ type Pattern = {
26
26
  children: unknown;
27
27
  attributes: Record<string, string | string[]>;
28
28
  };
29
+ // Optional custom complex types referenced by attributes like "X[]" or "X"
30
+ // Each entry maps a type name (e.g., "EventObject") to its field schema
31
+ // where the inner record maps fieldName -> primitive type or enum options
32
+ types?: Record<string, Record<string, string | string[]>>;
29
33
  };
30
34
 
31
35
  const patterns: Pattern[] = [
@@ -61,3 +65,35 @@ export function getAttributeSchema(
61
65
  const p = getPatternByType(type);
62
66
  return p?.pattern.attributes;
63
67
  }
68
+
69
+ /**
70
+ * Returns the schema of a custom complex type declared under a component pattern's `types` block.
71
+ * For example, OnboardButton.pattern.types.EventObject
72
+ */
73
+ export function getTypeSchema(
74
+ componentType?: string | null,
75
+ typeName?: string | null,
76
+ ): Record<string, string | string[]> | undefined {
77
+ if (!componentType || !typeName) return undefined;
78
+ const p = getPatternByType(componentType);
79
+ // Some JSON imports may not type-check "types" so we fallback to any access
80
+ const types: Record<string, Record<string, string | string[]>> | undefined = (
81
+ p as unknown as {
82
+ types?: Record<string, Record<string, string | string[]>>;
83
+ }
84
+ )?.types;
85
+ return types?.[typeName];
86
+ }
87
+
88
+ /** Utility: returns true if the type name refers to a primitive scalar */
89
+ export function isPrimitiveType(typeName: string): boolean {
90
+ return (
91
+ typeName === 'string' || typeName === 'number' || typeName === 'boolean'
92
+ );
93
+ }
94
+
95
+ /** Utility: parse `X[]` forms and return the item type if present */
96
+ export function getArrayItemType(typeName: string): string | null {
97
+ if (typeof typeName !== 'string') return null;
98
+ return typeName.endsWith('[]') ? typeName.slice(0, -2) : null;
99
+ }