@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SceneFromJson.d.ts","sourceRoot":"","sources":["../../src/scene/SceneFromJson.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
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, {
|
|
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
|
-
//
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
92
|
+
if (validationResult.warnings.length > 0) {
|
|
102
93
|
console.warn('Scene validation warnings:', validationResult.warnings);
|
|
103
94
|
}
|
|
104
|
-
|
|
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
|
}
|