@thewhateverapp/tile-sdk 0.14.8 → 0.14.10

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.
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { SceneRendererProps } from './SceneRenderer.js';
2
+ import { type SceneRendererProps } from './SceneRenderer.js';
3
3
  /**
4
4
  * Props for SceneFromJson
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"SceneFromJson.d.ts","sourceRoot":"","sources":["../../src/scene/SceneFromJson.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAK5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC;IAC1E,4DAA4D;IAC5D,IAAI,EAAE,OAAO,CAAC;IACd,uDAAuD;IACvD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CACtC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,UAAiB,EACjB,OAAO,EACP,SAAkB,EAClB,GAAG,KAAK,EACT,EAAE,kBAAkB,qBAuHpB"}
1
+ {"version":3,"file":"SceneFromJson.d.ts","sourceRoot":"","sources":["../../src/scene/SceneFromJson.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAG/D,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE5E;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC;IAC1E,4DAA4D;IAC5D,IAAI,EAAE,OAAO,CAAC;IACd,uDAAuD;IACvD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CACtC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,UAAiB,EACjB,OAAO,EACP,SAAkB,EAClB,GAAG,KAAK,EACT,EAAE,kBAAkB,qBAoGpB"}
@@ -1,6 +1,7 @@
1
1
  'use client';
2
- import React, { useState, useEffect, useMemo } from 'react';
2
+ import React, { useEffect, useMemo, useCallback } from 'react';
3
3
  import { validateScene } from '@thewhateverapp/scene-sdk';
4
+ import { SceneRenderer } from './SceneRenderer.js';
4
5
  /**
5
6
  * SceneFromJson - Renders a scene from a JSON object with validation
6
7
  *
@@ -16,16 +17,20 @@ import { validateScene } from '@thewhateverapp/scene-sdk';
16
17
  * ```
17
18
  */
18
19
  export function SceneFromJson({ json, showErrors = true, onEvent, container = 'tile', ...props }) {
19
- // SSR detection - only render SceneRenderer on client
20
- const [isClient, setIsClient] = useState(false);
21
- const [SceneRenderer, setSceneRenderer] = useState(null);
22
- // Load SceneRenderer dynamically on client only (pixi.js requires browser APIs)
23
- useEffect(() => {
24
- setIsClient(true);
25
- import('./SceneRenderer.js').then((mod) => {
26
- setSceneRenderer(() => mod.SceneRenderer);
27
- });
28
- }, []);
20
+ // Wrap onEvent to forward to parent window via postMessage
21
+ const wrappedOnEvent = useCallback((event, data) => {
22
+ // Call user's onEvent handler
23
+ onEvent?.(event, data);
24
+ // Forward to parent window for tile containers to handle
25
+ if (typeof window !== 'undefined' && window.parent !== window) {
26
+ window.parent.postMessage({
27
+ type: 'tile:event',
28
+ payload: { event, data },
29
+ timestamp: Date.now(),
30
+ }, '*' // Allow any parent origin (tile containers validate origin)
31
+ );
32
+ }
33
+ }, [onEvent]);
29
34
  // Container styles based on mode
30
35
  const containerStyle = container === 'none'
31
36
  ? undefined
@@ -58,20 +63,6 @@ export function SceneFromJson({ json, showErrors = true, onEvent, container = 't
58
63
  }
59
64
  }
60
65
  }, [validationResult]);
61
- // Loading placeholder for SSR and dynamic import
62
- const loadingPlaceholder = (React.createElement("div", { style: {
63
- width: '100%',
64
- height: '100%',
65
- backgroundColor: '#0a0a1a',
66
- display: 'flex',
67
- alignItems: 'center',
68
- justifyContent: 'center',
69
- } },
70
- React.createElement("div", { style: {
71
- color: '#666',
72
- fontSize: 14,
73
- fontFamily: 'system-ui, sans-serif',
74
- } }, "Loading...")));
75
66
  // Show errors if validation failed
76
67
  if (!validationResult.valid) {
77
68
  if (showErrors) {
@@ -98,13 +89,9 @@ export function SceneFromJson({ json, showErrors = true, onEvent, container = 't
98
89
  throw new Error(`Scene validation failed: ${validationResult.errors.map((e) => e.message).join(', ')}`);
99
90
  }
100
91
  // Show warnings in console
101
- if (validationResult.warnings.length > 0 && isClient) {
92
+ if (validationResult.warnings.length > 0) {
102
93
  console.warn('Scene validation warnings:', validationResult.warnings);
103
94
  }
104
- // Wait for client-side rendering and dynamic import
105
- if (!isClient || !SceneRenderer) {
106
- return containerStyle ? React.createElement("div", { style: containerStyle }, loadingPlaceholder) : loadingPlaceholder;
107
- }
108
- const sceneContent = (React.createElement(SceneRenderer, { spec: json, onEvent: onEvent, ...props }));
95
+ const sceneContent = (React.createElement(SceneRenderer, { spec: json, onEvent: wrappedOnEvent, ...props }));
109
96
  return containerStyle ? React.createElement("div", { style: containerStyle }, sceneContent) : sceneContent;
110
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thewhateverapp/tile-sdk",
3
- "version": "0.14.8",
3
+ "version": "0.14.10",
4
4
  "description": "SDK for building interactive tiles on The Whatever App platform",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",