@thewhateverapp/tile-sdk 0.14.7 → 0.14.9

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,KAAK,MAAM,OAAO,CAAC;AAG1B,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,qBAiFpB"}
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,qBAyIpB"}
@@ -1,7 +1,6 @@
1
1
  'use client';
2
- import React from 'react';
2
+ import React, { useState, useEffect, useMemo } from 'react';
3
3
  import { validateScene } from '@thewhateverapp/scene-sdk';
4
- import { SceneRenderer } from './SceneRenderer.js';
5
4
  /**
6
5
  * SceneFromJson - Renders a scene from a JSON object with validation
7
6
  *
@@ -17,6 +16,30 @@ import { SceneRenderer } from './SceneRenderer.js';
17
16
  * ```
18
17
  */
19
18
  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
+ }, []);
29
+ // Wrap onEvent to forward to parent window via postMessage
30
+ const wrappedOnEvent = React.useCallback((event, data) => {
31
+ // Call user's onEvent handler
32
+ onEvent?.(event, data);
33
+ // Forward to parent window for tile containers to handle
34
+ if (typeof window !== 'undefined' && window.parent !== window) {
35
+ window.parent.postMessage({
36
+ type: 'tile:event',
37
+ payload: { event, data },
38
+ timestamp: Date.now(),
39
+ }, '*' // Allow any parent origin (tile containers validate origin)
40
+ );
41
+ }
42
+ }, [onEvent]);
20
43
  // Container styles based on mode
21
44
  const containerStyle = container === 'none'
22
45
  ? undefined
@@ -25,7 +48,7 @@ export function SceneFromJson({ json, showErrors = true, onEvent, container = 't
25
48
  height: container === 'page' ? '100vh' : '100%',
26
49
  };
27
50
  // Validate the JSON
28
- const validationResult = React.useMemo(() => {
51
+ const validationResult = useMemo(() => {
29
52
  try {
30
53
  return validateScene(json);
31
54
  }
@@ -38,7 +61,7 @@ export function SceneFromJson({ json, showErrors = true, onEvent, container = 't
38
61
  }
39
62
  }, [json]);
40
63
  // Report validation errors to agent for correction
41
- React.useEffect(() => {
64
+ useEffect(() => {
42
65
  if (!validationResult.valid) {
43
66
  const errorMessage = `Scene Validation Errors:\n${validationResult.errors
44
67
  .map((e) => `${e.path}: ${e.message}`)
@@ -49,6 +72,20 @@ export function SceneFromJson({ json, showErrors = true, onEvent, container = 't
49
72
  }
50
73
  }
51
74
  }, [validationResult]);
75
+ // Loading placeholder for SSR and dynamic import
76
+ const loadingPlaceholder = (React.createElement("div", { style: {
77
+ width: '100%',
78
+ height: '100%',
79
+ backgroundColor: '#0a0a1a',
80
+ display: 'flex',
81
+ alignItems: 'center',
82
+ justifyContent: 'center',
83
+ } },
84
+ React.createElement("div", { style: {
85
+ color: '#666',
86
+ fontSize: 14,
87
+ fontFamily: 'system-ui, sans-serif',
88
+ } }, "Loading...")));
52
89
  // Show errors if validation failed
53
90
  if (!validationResult.valid) {
54
91
  if (showErrors) {
@@ -75,9 +112,13 @@ export function SceneFromJson({ json, showErrors = true, onEvent, container = 't
75
112
  throw new Error(`Scene validation failed: ${validationResult.errors.map((e) => e.message).join(', ')}`);
76
113
  }
77
114
  // Show warnings in console
78
- if (validationResult.warnings.length > 0) {
115
+ if (validationResult.warnings.length > 0 && isClient) {
79
116
  console.warn('Scene validation warnings:', validationResult.warnings);
80
117
  }
81
- const sceneContent = (React.createElement(SceneRenderer, { spec: json, onEvent: onEvent, ...props }));
118
+ // Wait for client-side rendering and dynamic import
119
+ if (!isClient || !SceneRenderer) {
120
+ return containerStyle ? React.createElement("div", { style: containerStyle }, loadingPlaceholder) : loadingPlaceholder;
121
+ }
122
+ const sceneContent = (React.createElement(SceneRenderer, { spec: json, onEvent: wrappedOnEvent, ...props }));
82
123
  return containerStyle ? React.createElement("div", { style: containerStyle }, sceneContent) : sceneContent;
83
124
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thewhateverapp/tile-sdk",
3
- "version": "0.14.7",
3
+ "version": "0.14.9",
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",