@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.
- package/dist/default/index.js +117 -88
- package/dist/default/index.js.map +1 -1
- package/dist/jsx/jsx-dev-runtime.js +1 -1
- package/dist/jsx/jsx-dev-runtime.web.js +1 -1
- package/dist/jsx/jsx-runtime.js +1 -1
- package/dist/jsx/jsx-runtime.web.js +1 -1
- package/dist/web/index.js +117 -88
- package/dist/web/index.js.map +1 -1
- package/package.json +2 -2
package/dist/default/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
|
+
window.__webspatialsdk__['react-sdk-version'] = "1.1.0"
|
|
6
6
|
window.__webspatialsdk__['XR_ENV'] = "avp"
|
|
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
|
-
|
|
191
|
+
prop2
|
|
197
192
|
);
|
|
198
193
|
}
|
|
199
194
|
const value2 = Reflect.get(target2, prop2);
|
|
200
195
|
if (typeof value2 === "function") {
|
|
201
|
-
|
|
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
|
}
|
|
@@ -2182,7 +2203,7 @@ function useEntityTransform(entity, { position, rotation, scale }) {
|
|
|
2182
2203
|
}
|
|
2183
2204
|
|
|
2184
2205
|
// src/reality/hooks/useEntityEvent.tsx
|
|
2185
|
-
import { useEffect as
|
|
2206
|
+
import { useEffect as useEffect17 } from "react";
|
|
2186
2207
|
|
|
2187
2208
|
// src/reality/type.ts
|
|
2188
2209
|
var eventMap = {
|
|
@@ -2202,11 +2223,88 @@ var eventMap = {
|
|
|
2202
2223
|
onSpatialMagnifyEnd: "spatialmagnifyend"
|
|
2203
2224
|
};
|
|
2204
2225
|
|
|
2226
|
+
// src/reality/hooks/useEntityRef.tsx
|
|
2227
|
+
import { useImperativeHandle } from "react";
|
|
2228
|
+
var useEntityRef = (ref, instance) => {
|
|
2229
|
+
useImperativeHandle(ref, () => instance);
|
|
2230
|
+
};
|
|
2231
|
+
var EntityRef = class {
|
|
2232
|
+
_entity;
|
|
2233
|
+
_ctx;
|
|
2234
|
+
constructor(entity = null, ctx = null) {
|
|
2235
|
+
this._entity = entity;
|
|
2236
|
+
this._ctx = ctx;
|
|
2237
|
+
}
|
|
2238
|
+
updateEntity(entity) {
|
|
2239
|
+
if (entity) this._entity = entity;
|
|
2240
|
+
}
|
|
2241
|
+
updateCtx(ctx) {
|
|
2242
|
+
if (ctx) this._ctx = ctx;
|
|
2243
|
+
}
|
|
2244
|
+
destroy() {
|
|
2245
|
+
this._entity?.destroy();
|
|
2246
|
+
}
|
|
2247
|
+
get entity() {
|
|
2248
|
+
return this._entity;
|
|
2249
|
+
}
|
|
2250
|
+
get id() {
|
|
2251
|
+
return this._entity?.userData?.id;
|
|
2252
|
+
}
|
|
2253
|
+
get name() {
|
|
2254
|
+
return this._entity?.userData?.name;
|
|
2255
|
+
}
|
|
2256
|
+
async convertFromEntityToEntity(fromEntityId, toEntityId, position) {
|
|
2257
|
+
if (!this._entity) return position;
|
|
2258
|
+
try {
|
|
2259
|
+
const fromEnt = await this._ctx?.resourceRegistry.get(fromEntityId);
|
|
2260
|
+
const toEnt = await this._ctx?.resourceRegistry.get(toEntityId);
|
|
2261
|
+
if (!fromEnt || !toEnt) return position;
|
|
2262
|
+
const ret = await this._entity.convertFromEntityToEntity(
|
|
2263
|
+
fromEnt.id,
|
|
2264
|
+
toEnt.id,
|
|
2265
|
+
position
|
|
2266
|
+
);
|
|
2267
|
+
return ret?.data ?? position;
|
|
2268
|
+
} catch {
|
|
2269
|
+
return position;
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
async convertFromEntityToReality(entityId, position) {
|
|
2273
|
+
if (!this._entity) return position;
|
|
2274
|
+
try {
|
|
2275
|
+
const ent = await this._ctx?.resourceRegistry.get(entityId);
|
|
2276
|
+
if (!ent) return position;
|
|
2277
|
+
const ret = await this._entity.convertFromEntityToScene(ent.id, position);
|
|
2278
|
+
return ret?.data ?? position;
|
|
2279
|
+
} catch {
|
|
2280
|
+
return position;
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
async convertFromRealityToEntity(entityId, position) {
|
|
2284
|
+
if (!this._entity) return position;
|
|
2285
|
+
try {
|
|
2286
|
+
const ent = await this._ctx?.resourceRegistry.get(entityId);
|
|
2287
|
+
if (!ent) return position;
|
|
2288
|
+
const ret = await this._entity.convertFromSceneToEntity(ent.id, position);
|
|
2289
|
+
return ret?.data ?? position;
|
|
2290
|
+
} catch {
|
|
2291
|
+
return position;
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
};
|
|
2295
|
+
|
|
2205
2296
|
// src/reality/hooks/useEntityEvent.tsx
|
|
2206
2297
|
function createEventProxy2(ev, instance) {
|
|
2207
2298
|
return new Proxy(ev, {
|
|
2208
2299
|
get(target, prop) {
|
|
2209
|
-
if (prop === "
|
|
2300
|
+
if (prop === "currentTarget") {
|
|
2301
|
+
return instance;
|
|
2302
|
+
}
|
|
2303
|
+
if (prop === "target") {
|
|
2304
|
+
const origin = target.__origin;
|
|
2305
|
+
if (origin) {
|
|
2306
|
+
return new EntityRef(origin, null);
|
|
2307
|
+
}
|
|
2210
2308
|
return instance;
|
|
2211
2309
|
}
|
|
2212
2310
|
const val = target[prop];
|
|
@@ -2215,7 +2313,7 @@ function createEventProxy2(ev, instance) {
|
|
|
2215
2313
|
});
|
|
2216
2314
|
}
|
|
2217
2315
|
var useEntityEvent = ({ instance, ...handlers }) => {
|
|
2218
|
-
|
|
2316
|
+
useEffect17(() => {
|
|
2219
2317
|
const entity = instance.entity;
|
|
2220
2318
|
if (!entity) return;
|
|
2221
2319
|
const boundHandlers = [];
|
|
@@ -2234,10 +2332,10 @@ var useEntityEvent = ({ instance, ...handlers }) => {
|
|
|
2234
2332
|
};
|
|
2235
2333
|
|
|
2236
2334
|
// src/reality/hooks/useEntityId.tsx
|
|
2237
|
-
import { useEffect as
|
|
2335
|
+
import { useEffect as useEffect18 } from "react";
|
|
2238
2336
|
var useEntityId = ({ id, entity }) => {
|
|
2239
2337
|
const ctx = useRealityContext();
|
|
2240
|
-
|
|
2338
|
+
useEffect18(() => {
|
|
2241
2339
|
if (!id || !entity || !ctx) return;
|
|
2242
2340
|
ctx.resourceRegistry.add(id, Promise.resolve(entity));
|
|
2243
2341
|
return () => {
|
|
@@ -2248,7 +2346,7 @@ var useEntityId = ({ id, entity }) => {
|
|
|
2248
2346
|
};
|
|
2249
2347
|
|
|
2250
2348
|
// src/reality/hooks/useEntity.tsx
|
|
2251
|
-
import { useEffect as
|
|
2349
|
+
import { useEffect as useEffect19, useRef as useRef7 } from "react";
|
|
2252
2350
|
var useEntity = ({
|
|
2253
2351
|
ref,
|
|
2254
2352
|
id,
|
|
@@ -2270,9 +2368,9 @@ var useEntity = ({
|
|
|
2270
2368
|
}) => {
|
|
2271
2369
|
const ctx = useRealityContext();
|
|
2272
2370
|
const parent = useParentContext();
|
|
2273
|
-
const instanceRef =
|
|
2371
|
+
const instanceRef = useRef7(new EntityRef(null, ctx));
|
|
2274
2372
|
const forceUpdate = useForceUpdate2();
|
|
2275
|
-
|
|
2373
|
+
useEffect19(() => {
|
|
2276
2374
|
if (!ctx) return;
|
|
2277
2375
|
const controller = new AbortController();
|
|
2278
2376
|
const init = async () => {
|
|
@@ -2321,76 +2419,6 @@ var useEntity = ({
|
|
|
2321
2419
|
return instanceRef.current.entity;
|
|
2322
2420
|
};
|
|
2323
2421
|
|
|
2324
|
-
// src/reality/hooks/useEntityRef.tsx
|
|
2325
|
-
import { useImperativeHandle } from "react";
|
|
2326
|
-
var useEntityRef = (ref, instance) => {
|
|
2327
|
-
useImperativeHandle(ref, () => instance);
|
|
2328
|
-
};
|
|
2329
|
-
var EntityRef = class {
|
|
2330
|
-
_entity;
|
|
2331
|
-
_ctx;
|
|
2332
|
-
constructor(entity = null, ctx = null) {
|
|
2333
|
-
this._entity = entity;
|
|
2334
|
-
this._ctx = ctx;
|
|
2335
|
-
}
|
|
2336
|
-
updateEntity(entity) {
|
|
2337
|
-
if (entity) this._entity = entity;
|
|
2338
|
-
}
|
|
2339
|
-
updateCtx(ctx) {
|
|
2340
|
-
if (ctx) this._ctx = ctx;
|
|
2341
|
-
}
|
|
2342
|
-
destroy() {
|
|
2343
|
-
this._entity?.destroy();
|
|
2344
|
-
}
|
|
2345
|
-
get entity() {
|
|
2346
|
-
return this._entity;
|
|
2347
|
-
}
|
|
2348
|
-
get id() {
|
|
2349
|
-
return this._entity?.userData?.id;
|
|
2350
|
-
}
|
|
2351
|
-
get name() {
|
|
2352
|
-
return this._entity?.userData?.name;
|
|
2353
|
-
}
|
|
2354
|
-
async convertFromEntityToEntity(fromEntityId, toEntityId, position) {
|
|
2355
|
-
if (!this._entity) return position;
|
|
2356
|
-
try {
|
|
2357
|
-
const fromEnt = await this._ctx?.resourceRegistry.get(fromEntityId);
|
|
2358
|
-
const toEnt = await this._ctx?.resourceRegistry.get(toEntityId);
|
|
2359
|
-
if (!fromEnt || !toEnt) return position;
|
|
2360
|
-
const ret = await this._entity.convertFromEntityToEntity(
|
|
2361
|
-
fromEnt.id,
|
|
2362
|
-
toEnt.id,
|
|
2363
|
-
position
|
|
2364
|
-
);
|
|
2365
|
-
return ret?.data ?? position;
|
|
2366
|
-
} catch {
|
|
2367
|
-
return position;
|
|
2368
|
-
}
|
|
2369
|
-
}
|
|
2370
|
-
async convertFromEntityToReality(entityId, position) {
|
|
2371
|
-
if (!this._entity) return position;
|
|
2372
|
-
try {
|
|
2373
|
-
const ent = await this._ctx?.resourceRegistry.get(entityId);
|
|
2374
|
-
if (!ent) return position;
|
|
2375
|
-
const ret = await this._entity.convertFromEntityToScene(ent.id, position);
|
|
2376
|
-
return ret?.data ?? position;
|
|
2377
|
-
} catch {
|
|
2378
|
-
return position;
|
|
2379
|
-
}
|
|
2380
|
-
}
|
|
2381
|
-
async convertFromRealityToEntity(entityId, position) {
|
|
2382
|
-
if (!this._entity) return position;
|
|
2383
|
-
try {
|
|
2384
|
-
const ent = await this._ctx?.resourceRegistry.get(entityId);
|
|
2385
|
-
if (!ent) return position;
|
|
2386
|
-
const ret = await this._entity.convertFromSceneToEntity(ent.id, position);
|
|
2387
|
-
return ret?.data ?? position;
|
|
2388
|
-
} catch {
|
|
2389
|
-
return position;
|
|
2390
|
-
}
|
|
2391
|
-
}
|
|
2392
|
-
};
|
|
2393
|
-
|
|
2394
2422
|
// src/reality/hooks/useForceUpdate.tsx
|
|
2395
2423
|
import { useCallback as useCallback7, useState as useState7 } from "react";
|
|
2396
2424
|
var useForceUpdate2 = () => {
|
|
@@ -2484,6 +2512,7 @@ var GeometryEntity = forwardRef11(
|
|
|
2484
2512
|
await ent.addComponent(modelComponent);
|
|
2485
2513
|
return ent;
|
|
2486
2514
|
} catch (error) {
|
|
2515
|
+
console.error(error);
|
|
2487
2516
|
await manager.dispose();
|
|
2488
2517
|
return null;
|
|
2489
2518
|
}
|
|
@@ -2822,7 +2851,7 @@ var Model = withSSRSupported(forwardRef19(ModelBase));
|
|
|
2822
2851
|
Model.displayName = "Model";
|
|
2823
2852
|
|
|
2824
2853
|
// src/index.ts
|
|
2825
|
-
var version = "1.0
|
|
2854
|
+
var version = "1.1.0";
|
|
2826
2855
|
if (typeof window !== "undefined") {
|
|
2827
2856
|
initPolyfill();
|
|
2828
2857
|
}
|