@webspatial/react-sdk 1.0.5 → 1.1.0

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.0.5"
5
+ window.__webspatialsdk__['react-sdk-version'] = "1.1.0"
6
6
  window.__webspatialsdk__['XR_ENV'] = "avp"
7
7
  })()
8
8
 
@@ -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.0.5"
5
+ window.__webspatialsdk__['react-sdk-version'] = "1.1.0"
6
6
  window.__webspatialsdk__['XR_ENV'] = "web"
7
7
  })()
8
8
 
@@ -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.0.5"
5
+ window.__webspatialsdk__['react-sdk-version'] = "1.1.0"
6
6
  window.__webspatialsdk__['XR_ENV'] = "avp"
7
7
  })()
8
8
 
@@ -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.0.5"
5
+ window.__webspatialsdk__['react-sdk-version'] = "1.1.0"
6
6
  window.__webspatialsdk__['XR_ENV'] = "web"
7
7
  })()
8
8
 
package/dist/web/index.js CHANGED
@@ -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.0.5"
5
+ window.__webspatialsdk__['react-sdk-version'] = "1.1.0"
6
6
  window.__webspatialsdk__['XR_ENV'] = "web"
7
7
  })()
8
8
 
@@ -186,19 +186,40 @@ var SpatialContainerRefProxy = class {
186
186
  if (!self.styleProxy) {
187
187
  self.styleProxy = new Proxy(target.style, {
188
188
  get(target2, prop2) {
189
- if (prop2 === "visibility") {
190
- return self.transformVisibilityTaskContainerDom?.style.getPropertyValue(
191
- "visibility"
192
- );
193
- }
194
- if (prop2 === "transform") {
189
+ if (prop2 === "visibility" || prop2 === "transform") {
195
190
  return self.transformVisibilityTaskContainerDom?.style.getPropertyValue(
196
- "transform"
191
+ prop2
197
192
  );
198
193
  }
199
194
  const value2 = Reflect.get(target2, prop2);
200
195
  if (typeof value2 === "function") {
201
- return value2.bind(target2);
196
+ if (prop2 === "setProperty" || prop2 === "removeProperty" || prop2 === "getPropertyValue") {
197
+ return function(...args) {
198
+ const validProperties = ["visibility", "transform"];
199
+ const [property] = args;
200
+ if (validProperties.includes(property)) {
201
+ if (prop2 === "setProperty") {
202
+ const [, kValue] = args;
203
+ self.transformVisibilityTaskContainerDom?.style.setProperty(
204
+ property,
205
+ kValue
206
+ );
207
+ } else if (prop2 === "removeProperty") {
208
+ self.transformVisibilityTaskContainerDom?.style.removeProperty(
209
+ property
210
+ );
211
+ } else if (prop2 === "getPropertyValue") {
212
+ return self.transformVisibilityTaskContainerDom?.style.getPropertyValue(
213
+ property
214
+ );
215
+ }
216
+ } else {
217
+ return value2.apply(this, args);
218
+ }
219
+ }.bind(target2);
220
+ } else {
221
+ return value2.bind(target2);
222
+ }
202
223
  } else {
203
224
  return value2;
204
225
  }
@@ -2223,7 +2244,7 @@ function useEntityTransform(entity, { position, rotation, scale }) {
2223
2244
  }
2224
2245
 
2225
2246
  // src/reality/hooks/useEntityEvent.tsx
2226
- import { useEffect as useEffect16 } from "react";
2247
+ import { useEffect as useEffect17 } from "react";
2227
2248
 
2228
2249
  // src/reality/type.ts
2229
2250
  var eventMap = {
@@ -2243,11 +2264,88 @@ var eventMap = {
2243
2264
  onSpatialMagnifyEnd: "spatialmagnifyend"
2244
2265
  };
2245
2266
 
2267
+ // src/reality/hooks/useEntityRef.tsx
2268
+ import { useImperativeHandle } from "react";
2269
+ var useEntityRef = (ref, instance) => {
2270
+ useImperativeHandle(ref, () => instance);
2271
+ };
2272
+ var EntityRef = class {
2273
+ _entity;
2274
+ _ctx;
2275
+ constructor(entity = null, ctx = null) {
2276
+ this._entity = entity;
2277
+ this._ctx = ctx;
2278
+ }
2279
+ updateEntity(entity) {
2280
+ if (entity) this._entity = entity;
2281
+ }
2282
+ updateCtx(ctx) {
2283
+ if (ctx) this._ctx = ctx;
2284
+ }
2285
+ destroy() {
2286
+ this._entity?.destroy();
2287
+ }
2288
+ get entity() {
2289
+ return this._entity;
2290
+ }
2291
+ get id() {
2292
+ return this._entity?.userData?.id;
2293
+ }
2294
+ get name() {
2295
+ return this._entity?.userData?.name;
2296
+ }
2297
+ async convertFromEntityToEntity(fromEntityId, toEntityId, position) {
2298
+ if (!this._entity) return position;
2299
+ try {
2300
+ const fromEnt = await this._ctx?.resourceRegistry.get(fromEntityId);
2301
+ const toEnt = await this._ctx?.resourceRegistry.get(toEntityId);
2302
+ if (!fromEnt || !toEnt) return position;
2303
+ const ret = await this._entity.convertFromEntityToEntity(
2304
+ fromEnt.id,
2305
+ toEnt.id,
2306
+ position
2307
+ );
2308
+ return ret?.data ?? position;
2309
+ } catch {
2310
+ return position;
2311
+ }
2312
+ }
2313
+ async convertFromEntityToReality(entityId, position) {
2314
+ if (!this._entity) return position;
2315
+ try {
2316
+ const ent = await this._ctx?.resourceRegistry.get(entityId);
2317
+ if (!ent) return position;
2318
+ const ret = await this._entity.convertFromEntityToScene(ent.id, position);
2319
+ return ret?.data ?? position;
2320
+ } catch {
2321
+ return position;
2322
+ }
2323
+ }
2324
+ async convertFromRealityToEntity(entityId, position) {
2325
+ if (!this._entity) return position;
2326
+ try {
2327
+ const ent = await this._ctx?.resourceRegistry.get(entityId);
2328
+ if (!ent) return position;
2329
+ const ret = await this._entity.convertFromSceneToEntity(ent.id, position);
2330
+ return ret?.data ?? position;
2331
+ } catch {
2332
+ return position;
2333
+ }
2334
+ }
2335
+ };
2336
+
2246
2337
  // src/reality/hooks/useEntityEvent.tsx
2247
2338
  function createEventProxy2(ev, instance) {
2248
2339
  return new Proxy(ev, {
2249
2340
  get(target, prop) {
2250
- if (prop === "target" || prop === "currentTarget") {
2341
+ if (prop === "currentTarget") {
2342
+ return instance;
2343
+ }
2344
+ if (prop === "target") {
2345
+ const origin = target.__origin;
2346
+ if (origin) {
2347
+ return new EntityRef(origin, null);
2348
+ }
2251
2349
  return instance;
2252
2350
  }
2253
2351
  const val = target[prop];
@@ -2256,7 +2354,7 @@ function createEventProxy2(ev, instance) {
2256
2354
  });
2257
2355
  }
2258
2356
  var useEntityEvent = ({ instance, ...handlers }) => {
2259
- useEffect16(() => {
2357
+ useEffect17(() => {
2260
2358
  const entity = instance.entity;
2261
2359
  if (!entity) return;
2262
2360
  const boundHandlers = [];
@@ -2275,10 +2373,10 @@ var useEntityEvent = ({ instance, ...handlers }) => {
2275
2373
  };
2276
2374
 
2277
2375
  // src/reality/hooks/useEntityId.tsx
2278
- import { useEffect as useEffect17 } from "react";
2376
+ import { useEffect as useEffect18 } from "react";
2279
2377
  var useEntityId = ({ id, entity }) => {
2280
2378
  const ctx = useRealityContext();
2281
- useEffect17(() => {
2379
+ useEffect18(() => {
2282
2380
  if (!id || !entity || !ctx) return;
2283
2381
  ctx.resourceRegistry.add(id, Promise.resolve(entity));
2284
2382
  return () => {
@@ -2289,7 +2387,7 @@ var useEntityId = ({ id, entity }) => {
2289
2387
  };
2290
2388
 
2291
2389
  // src/reality/hooks/useEntity.tsx
2292
- import { useEffect as useEffect18, useRef as useRef6 } from "react";
2390
+ import { useEffect as useEffect19, useRef as useRef7 } from "react";
2293
2391
  var useEntity = ({
2294
2392
  ref,
2295
2393
  id,
@@ -2311,9 +2409,9 @@ var useEntity = ({
2311
2409
  }) => {
2312
2410
  const ctx = useRealityContext();
2313
2411
  const parent = useParentContext();
2314
- const instanceRef = useRef6(new EntityRef(null, ctx));
2412
+ const instanceRef = useRef7(new EntityRef(null, ctx));
2315
2413
  const forceUpdate = useForceUpdate2();
2316
- useEffect18(() => {
2414
+ useEffect19(() => {
2317
2415
  if (!ctx) return;
2318
2416
  const controller = new AbortController();
2319
2417
  const init = async () => {
@@ -2362,76 +2460,6 @@ var useEntity = ({
2362
2460
  return instanceRef.current.entity;
2363
2461
  };
2364
2462
 
2365
- // src/reality/hooks/useEntityRef.tsx
2366
- import { useImperativeHandle } from "react";
2367
- var useEntityRef = (ref, instance) => {
2368
- useImperativeHandle(ref, () => instance);
2369
- };
2370
- var EntityRef = class {
2371
- _entity;
2372
- _ctx;
2373
- constructor(entity = null, ctx = null) {
2374
- this._entity = entity;
2375
- this._ctx = ctx;
2376
- }
2377
- updateEntity(entity) {
2378
- if (entity) this._entity = entity;
2379
- }
2380
- updateCtx(ctx) {
2381
- if (ctx) this._ctx = ctx;
2382
- }
2383
- destroy() {
2384
- this._entity?.destroy();
2385
- }
2386
- get entity() {
2387
- return this._entity;
2388
- }
2389
- get id() {
2390
- return this._entity?.userData?.id;
2391
- }
2392
- get name() {
2393
- return this._entity?.userData?.name;
2394
- }
2395
- async convertFromEntityToEntity(fromEntityId, toEntityId, position) {
2396
- if (!this._entity) return position;
2397
- try {
2398
- const fromEnt = await this._ctx?.resourceRegistry.get(fromEntityId);
2399
- const toEnt = await this._ctx?.resourceRegistry.get(toEntityId);
2400
- if (!fromEnt || !toEnt) return position;
2401
- const ret = await this._entity.convertFromEntityToEntity(
2402
- fromEnt.id,
2403
- toEnt.id,
2404
- position
2405
- );
2406
- return ret?.data ?? position;
2407
- } catch {
2408
- return position;
2409
- }
2410
- }
2411
- async convertFromEntityToReality(entityId, position) {
2412
- if (!this._entity) return position;
2413
- try {
2414
- const ent = await this._ctx?.resourceRegistry.get(entityId);
2415
- if (!ent) return position;
2416
- const ret = await this._entity.convertFromEntityToScene(ent.id, position);
2417
- return ret?.data ?? position;
2418
- } catch {
2419
- return position;
2420
- }
2421
- }
2422
- async convertFromRealityToEntity(entityId, position) {
2423
- if (!this._entity) return position;
2424
- try {
2425
- const ent = await this._ctx?.resourceRegistry.get(entityId);
2426
- if (!ent) return position;
2427
- const ret = await this._entity.convertFromSceneToEntity(ent.id, position);
2428
- return ret?.data ?? position;
2429
- } catch {
2430
- return position;
2431
- }
2432
- }
2433
- };
2434
-
2435
2463
  // src/reality/hooks/useForceUpdate.tsx
2436
2464
  import { useCallback as useCallback7, useState as useState7 } from "react";
2437
2465
  var useForceUpdate2 = () => {
@@ -2525,6 +2553,7 @@ var GeometryEntity = forwardRef11(
2525
2553
  await ent.addComponent(modelComponent);
2526
2554
  return ent;
2527
2555
  } catch (error) {
2556
+ console.error(error);
2528
2557
  await manager.dispose();
2529
2558
  return null;
2530
2559
  }
@@ -2862,7 +2891,7 @@ var Model = withSSRSupported(forwardRef19(ModelBase));
2862
2891
  Model.displayName = "Model";
2863
2892
 
2864
2893
  // src/index.ts
2865
- var version = "1.0.5";
2894
+ var version = "1.1.0";
2866
2895
  if (typeof window !== "undefined") {
2867
2896
  initPolyfill();
2868
2897
  }