@webspatial/react-sdk 1.2.0 → 1.2.1

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.
@@ -2,7 +2,7 @@
2
2
  (function(){
3
3
  if(typeof window === 'undefined') return;
4
4
  if(!window.__webspatialsdk__) window.__webspatialsdk__ = {}
5
- window.__webspatialsdk__['react-sdk-version'] = "1.2.0"
5
+ window.__webspatialsdk__['react-sdk-version'] = "1.2.1"
6
6
  window.__webspatialsdk__['XR_ENV'] = "avp"
7
7
  })()
8
8
 
@@ -1164,12 +1164,12 @@ function useSync2DFrame(spatialId, portalInstanceObject, spatializedContainerObj
1164
1164
 
1165
1165
  // src/spatialized-container/hooks/useSpatializedElement.ts
1166
1166
  import { useEffect as useEffect6, useState as useState3 } from "react";
1167
- function useSpatializedElement(createSpatializedElement3, portalInstanceObject) {
1167
+ function useSpatializedElement(createSpatializedElement2, portalInstanceObject) {
1168
1168
  const [spatializedElement, setSpatializedElement] = useState3();
1169
1169
  useEffect6(() => {
1170
1170
  let isDestroyed = false;
1171
1171
  let spatializedElement2;
1172
- createSpatializedElement3().then(
1172
+ createSpatializedElement2().then(
1173
1173
  (inSpatializedElement) => {
1174
1174
  if (!isDestroyed) {
1175
1175
  spatializedElement2 = inSpatializedElement;
@@ -1187,7 +1187,7 @@ function useSpatializedElement(createSpatializedElement3, portalInstanceObject)
1187
1187
  spatializedElement2 = void 0;
1188
1188
  }
1189
1189
  };
1190
- }, [createSpatializedElement3, portalInstanceObject]);
1190
+ }, [createSpatializedElement2, portalInstanceObject]);
1191
1191
  return spatializedElement;
1192
1192
  }
1193
1193
 
@@ -1221,7 +1221,7 @@ function renderPlaceholderInSubPortal(portalInstanceObject, El) {
1221
1221
  function PortalSpatializedContainer(props) {
1222
1222
  const {
1223
1223
  spatializedContent: Content,
1224
- createSpatializedElement: createSpatializedElement3,
1224
+ createSpatializedElement: createSpatializedElement2,
1225
1225
  getExtraSpatializedElementProperties: getExtraSpatializedElementProperties2,
1226
1226
  onSpatialTap,
1227
1227
  onSpatialDragStart,
@@ -1255,7 +1255,7 @@ function PortalSpatializedContainer(props) {
1255
1255
  }, []);
1256
1256
  useSync2DFrame(spatialId, portalInstanceObject, spatializedContainerObject);
1257
1257
  const spatializedElement = useSpatializedElement(
1258
- createSpatializedElement3,
1258
+ createSpatializedElement2,
1259
1259
  portalInstanceObject
1260
1260
  );
1261
1261
  const PlaceholderEl = renderPlaceholderInSubPortal(
@@ -1476,7 +1476,7 @@ function SpatializedContainerBase(inprops, ref) {
1476
1476
  const {
1477
1477
  component: Component,
1478
1478
  spatializedContent,
1479
- createSpatializedElement: createSpatializedElement3,
1479
+ createSpatializedElement: createSpatializedElement2,
1480
1480
  getExtraSpatializedElementProperties: getExtraSpatializedElementProperties2,
1481
1481
  onSpatialTap: onSpatialTap2,
1482
1482
  onSpatialDragStart: onSpatialDragStart2,
@@ -1555,7 +1555,7 @@ function SpatializedContainerBase(inprops, ref) {
1555
1555
  }, [spatialContainerRefProxy.current]);
1556
1556
  const {
1557
1557
  spatializedContent,
1558
- createSpatializedElement: createSpatializedElement3,
1558
+ createSpatializedElement: createSpatializedElement2,
1559
1559
  getExtraSpatializedElementProperties: getExtraSpatializedElementProperties2,
1560
1560
  ...restProps
1561
1561
  } = props;
@@ -1605,7 +1605,7 @@ function SpatializedContainerBase(inprops, ref) {
1605
1605
  );
1606
1606
  const {
1607
1607
  spatializedContent,
1608
- createSpatializedElement: createSpatializedElement3,
1608
+ createSpatializedElement: createSpatializedElement2,
1609
1609
  getExtraSpatializedElementProperties: getExtraSpatializedElementProperties2,
1610
1610
  ...restProps
1611
1611
  } = props;
@@ -1815,7 +1815,10 @@ import {
1815
1815
  useCallback as useCallback6,
1816
1816
  useContext as useContext8,
1817
1817
  useEffect as useEffect12,
1818
- useMemo as useMemo3
1818
+ useMemo as useMemo3,
1819
+ useState as useState6,
1820
+ useImperativeHandle,
1821
+ useRef as useRef4
1819
1822
  } from "react";
1820
1823
  import { Fragment as Fragment2, jsx as jsx8 } from "react/jsx-runtime";
1821
1824
  function getAbsoluteURL(url) {
@@ -1889,10 +1892,15 @@ function SpatializedContent2(props) {
1889
1892
  }, [onError]);
1890
1893
  return /* @__PURE__ */ jsx8(Fragment2, {});
1891
1894
  }
1892
- async function createSpatializedElement2() {
1893
- return getSession().createSpatializedStatic3DElement();
1894
- }
1895
1895
  function SpatializedStatic3DElementContainerBase(props, ref) {
1896
+ const containerRef = useRef4(null);
1897
+ const [elementCreated, setElementCreated] = useState6(false);
1898
+ useImperativeHandle(ref, () => elementCreated ? containerRef.current : null, [elementCreated]);
1899
+ const createSpatializedElement2 = useCallback6(async () => {
1900
+ const element = await getSession().createSpatializedStatic3DElement();
1901
+ setElementCreated(true);
1902
+ return element;
1903
+ }, [setElementCreated]);
1896
1904
  const extraRefProps = useCallback6(
1897
1905
  (domProxy) => {
1898
1906
  let modelTransform = new DOMMatrixReadOnly();
@@ -1925,7 +1933,7 @@ function SpatializedStatic3DElementContainerBase(props, ref) {
1925
1933
  return /* @__PURE__ */ jsx8(
1926
1934
  SpatializedContainer,
1927
1935
  {
1928
- ref,
1936
+ ref: containerRef,
1929
1937
  component: "div",
1930
1938
  createSpatializedElement: createSpatializedElement2,
1931
1939
  spatializedContent: SpatializedContent2,
@@ -1987,9 +1995,9 @@ function initScene(name, callback, options) {
1987
1995
  import { forwardRef as forwardRef9 } from "react";
1988
1996
 
1989
1997
  // src/spatialized-container-monitor/useMonitorDomChange.tsx
1990
- import { useRef as useRef4, useEffect as useEffect13, useMemo as useMemo4 } from "react";
1998
+ import { useRef as useRef5, useEffect as useEffect13, useMemo as useMemo4 } from "react";
1991
1999
  function useMonitorDomChange(inRef) {
1992
- const ref = useRef4(null);
2000
+ const ref = useRef5(null);
1993
2001
  useEffect13(() => {
1994
2002
  const observer = new MutationObserver((mutationsList) => {
1995
2003
  notifyDOMUpdate(mutationsList);
@@ -2098,7 +2106,7 @@ var ParentContext = createContext6(null);
2098
2106
  var useParentContext = () => useContext10(ParentContext);
2099
2107
 
2100
2108
  // src/reality/hooks/useEntityTransform.tsx
2101
- import { useEffect as useEffect15, useRef as useRef5 } from "react";
2109
+ import { useEffect as useEffect15, useRef as useRef6 } from "react";
2102
2110
 
2103
2111
  // src/reality/utils/ResourceRegistry.ts
2104
2112
  var ResourceRegistry = class {
@@ -2179,7 +2187,7 @@ var AbortResourceManager = class {
2179
2187
 
2180
2188
  // src/reality/hooks/useEntityTransform.tsx
2181
2189
  function useEntityTransform(entity, { position, rotation, scale }) {
2182
- const last = useRef5({});
2190
+ const last = useRef6({});
2183
2191
  useEffect15(() => {
2184
2192
  if (!entity) return;
2185
2193
  const shouldUpdate = !shallowEqualVec3(last.current.position, position) || !shallowEqualRotation(last.current.rotation, rotation) || !shallowEqualVec3(last.current.scale, scale);
@@ -2199,7 +2207,7 @@ function useEntityTransform(entity, { position, rotation, scale }) {
2199
2207
  }
2200
2208
 
2201
2209
  // src/reality/hooks/useEntityEvent.tsx
2202
- import { useEffect as useEffect17, useRef as useRef7 } from "react";
2210
+ import { useEffect as useEffect17, useRef as useRef8 } from "react";
2203
2211
 
2204
2212
  // src/reality/type.ts
2205
2213
  var eventMap = {
@@ -2220,9 +2228,9 @@ var eventMap = {
2220
2228
  };
2221
2229
 
2222
2230
  // src/reality/hooks/useEntityRef.tsx
2223
- import { useImperativeHandle } from "react";
2231
+ import { useImperativeHandle as useImperativeHandle2 } from "react";
2224
2232
  var useEntityRef = (ref, instance) => {
2225
- useImperativeHandle(ref, () => instance);
2233
+ useImperativeHandle2(ref, () => instance);
2226
2234
  };
2227
2235
  var EntityRef = class {
2228
2236
  _entity;
@@ -2342,7 +2350,7 @@ function createEventProxy2(ev, instance) {
2342
2350
  });
2343
2351
  }
2344
2352
  var useEntityEvent = ({ instance, ...handlers }) => {
2345
- const eventsSetRef = useRef7(/* @__PURE__ */ new Set());
2353
+ const eventsSetRef = useRef8(/* @__PURE__ */ new Set());
2346
2354
  useEffect17(() => {
2347
2355
  const entity = instance.entity;
2348
2356
  if (!entity) return;
@@ -2384,7 +2392,7 @@ var useEntityId = ({ id, entity }) => {
2384
2392
  };
2385
2393
 
2386
2394
  // src/reality/hooks/useEntity.tsx
2387
- import { useEffect as useEffect19, useRef as useRef8 } from "react";
2395
+ import { useEffect as useEffect19, useRef as useRef9 } from "react";
2388
2396
  var useEntity = ({
2389
2397
  ref,
2390
2398
  id,
@@ -2406,7 +2414,7 @@ var useEntity = ({
2406
2414
  }) => {
2407
2415
  const ctx = useRealityContext();
2408
2416
  const parent = useParentContext();
2409
- const instanceRef = useRef8(new EntityRef(null, ctx));
2417
+ const instanceRef = useRef9(new EntityRef(null, ctx));
2410
2418
  const forceUpdate = useForceUpdate2();
2411
2419
  useEffect19(() => {
2412
2420
  if (!ctx) return;
@@ -2458,9 +2466,9 @@ var useEntity = ({
2458
2466
  };
2459
2467
 
2460
2468
  // src/reality/hooks/useForceUpdate.tsx
2461
- import { useCallback as useCallback7, useState as useState7 } from "react";
2469
+ import { useCallback as useCallback7, useState as useState8 } from "react";
2462
2470
  var useForceUpdate2 = () => {
2463
- const [, setTick] = useState7(0);
2471
+ const [, setTick] = useState8(0);
2464
2472
  return useCallback7(() => setTick((tick) => tick + 1), []);
2465
2473
  };
2466
2474
 
@@ -2565,10 +2573,10 @@ var BoxEntity = forwardRef13(
2565
2573
  );
2566
2574
 
2567
2575
  // src/reality/components/UnlitMaterial.tsx
2568
- import { useEffect as useEffect20, useRef as useRef9 } from "react";
2576
+ import { useEffect as useEffect20, useRef as useRef10 } from "react";
2569
2577
  var UnlitMaterial = ({ children, ...options }) => {
2570
2578
  const ctx = useRealityContext();
2571
- const materialRef = useRef9();
2579
+ const materialRef = useRef10();
2572
2580
  useEffect20(() => {
2573
2581
  if (!ctx) return;
2574
2582
  const { session, reality, resourceRegistry } = ctx;
@@ -2685,7 +2693,7 @@ var SceneGraph = ({ children }) => {
2685
2693
  };
2686
2694
 
2687
2695
  // src/reality/components/ModelAsset.tsx
2688
- import { useEffect as useEffect21, useRef as useRef10 } from "react";
2696
+ import { useEffect as useEffect21, useRef as useRef11 } from "react";
2689
2697
  var resolveAssetUrl = (url) => {
2690
2698
  if (url.startsWith("http://") || url.startsWith("https://")) {
2691
2699
  return url;
@@ -2694,7 +2702,7 @@ var resolveAssetUrl = (url) => {
2694
2702
  };
2695
2703
  var ModelAsset = ({ children, ...options }) => {
2696
2704
  const ctx = useRealityContext();
2697
- const materialRef = useRef10();
2705
+ const materialRef = useRef11();
2698
2706
  useEffect21(() => {
2699
2707
  const controller = new AbortController();
2700
2708
  if (!ctx) return;
@@ -2763,8 +2771,8 @@ import {
2763
2771
  forwardRef as forwardRef19,
2764
2772
  useCallback as useCallback8,
2765
2773
  useEffect as useEffect22,
2766
- useRef as useRef11,
2767
- useState as useState8
2774
+ useRef as useRef12,
2775
+ useState as useState9
2768
2776
  } from "react";
2769
2777
  import { Fragment as Fragment3, jsx as jsx22, jsxs as jsxs3 } from "react/jsx-runtime";
2770
2778
  var Reality = forwardRef19(
@@ -2780,9 +2788,9 @@ var Reality = forwardRef19(
2780
2788
  onSpatialMagnifyEnd,
2781
2789
  ...props
2782
2790
  } = inProps;
2783
- const ctxRef = useRef11(null);
2784
- const creationId = useRef11(0);
2785
- const [isReady, setIsReady] = useState8(false);
2791
+ const ctxRef = useRef12(null);
2792
+ const creationId = useRef12(0);
2793
+ const [isReady, setIsReady] = useState9(false);
2786
2794
  const cleanupReality = useCallback8(() => {
2787
2795
  ctxRef.current?.resourceRegistry.destroy();
2788
2796
  ctxRef.current?.reality.destroy();
@@ -2872,7 +2880,7 @@ var Model = withSSRSupported(forwardRef20(ModelBase));
2872
2880
  Model.displayName = "Model";
2873
2881
 
2874
2882
  // src/index.ts
2875
- var version = "1.2.0";
2883
+ var version = "1.2.1";
2876
2884
  if (typeof window !== "undefined") {
2877
2885
  initPolyfill();
2878
2886
  }