@webspatial/react-sdk 0.0.15 → 0.0.16-alpha.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.
- package/dist/default/index.js +74 -24
- package/dist/default/index.js.map +1 -1
- package/dist/web/index.js +74 -24
- package/dist/web/index.js.map +1 -1
- package/package.json +2 -2
package/dist/web/index.js
CHANGED
|
@@ -194,7 +194,8 @@ function simplifyEntityTree(rootTree) {
|
|
|
194
194
|
cornerRadius: node.components[0].cornerRadius,
|
|
195
195
|
backgroundMaterial: node.components[0].backgroundMaterial,
|
|
196
196
|
isOpaque: node.components[0].isOpaque,
|
|
197
|
-
isScrollEnabled: node.components[0].isScrollEnabled
|
|
197
|
+
isScrollEnabled: node.components[0].isScrollEnabled,
|
|
198
|
+
scrollWithParent: node.components[0].scrollWithParent
|
|
198
199
|
};
|
|
199
200
|
nodeMap[node.id] = newNode;
|
|
200
201
|
if (!parent) {
|
|
@@ -531,9 +532,9 @@ var SpatialWindowManager = class {
|
|
|
531
532
|
this.initPromise = this.initInternalFromWindow();
|
|
532
533
|
await this.initPromise;
|
|
533
534
|
}
|
|
534
|
-
async resize(rect, offset, rotation = { x: 0, y: 0, z: 0, w: 1 }, scale = { x: 1, y: 1, z: 1 }, rotationOrigin = { x: 0, y: 0, z: 0 }) {
|
|
535
|
+
async resize(rect, offset, rotation = { x: 0, y: 0, z: 0, w: 1 }, scale = { x: 1, y: 1, z: 1 }, rotationOrigin = { x: 0, y: 0, z: 0 }, parrentOffset = 0) {
|
|
535
536
|
let targetPosX = rect.x + rect.width / 2;
|
|
536
|
-
let targetPosY = rect.y + rect.height / 2 +
|
|
537
|
+
let targetPosY = rect.y + rect.height / 2 + parrentOffset;
|
|
537
538
|
if (!this.webview) {
|
|
538
539
|
return;
|
|
539
540
|
}
|
|
@@ -948,7 +949,7 @@ function syncDefaultSpatialStyle(openedWindow, debugName) {
|
|
|
948
949
|
openedWindow.document.head.appendChild(styleElement);
|
|
949
950
|
openedWindow.document.body.style.display = "inline-block";
|
|
950
951
|
}
|
|
951
|
-
function useSyncSpatialProps(spatialWindowManager, props, domRect, anchor, cornerRadiusFromStyle, opacity, stylePosition) {
|
|
952
|
+
function useSyncSpatialProps(spatialWindowManager, props, domRect, anchor, cornerRadiusFromStyle, opacity, stylePosition, isSubPortal) {
|
|
952
953
|
let { allowScroll, scrollWithParent, style, spatialStyle = {} } = props;
|
|
953
954
|
let {
|
|
954
955
|
position = { x: 0, y: 0, z: 1 },
|
|
@@ -1041,7 +1042,8 @@ function useSyncSpatialProps(spatialWindowManager, props, domRect, anchor, corne
|
|
|
1041
1042
|
position,
|
|
1042
1043
|
rotation,
|
|
1043
1044
|
scale,
|
|
1044
|
-
anchor
|
|
1045
|
+
anchor,
|
|
1046
|
+
isSubPortal ? 0 : window.scrollY
|
|
1045
1047
|
);
|
|
1046
1048
|
spatialWindowManager?.setZIndex(zIndex);
|
|
1047
1049
|
})();
|
|
@@ -1125,12 +1127,14 @@ function useSyncDomRect(spatialId) {
|
|
|
1125
1127
|
const isFixedPosition = stylePosition === "fixed";
|
|
1126
1128
|
let domRect2 = dom.getBoundingClientRect();
|
|
1127
1129
|
let rectType = domRect2rectType(domRect2);
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1130
|
+
if (!isFixedPosition) {
|
|
1131
|
+
const parentDom = spatialReactContextObject?.queryParentSpatialDom(spatialId);
|
|
1132
|
+
if (parentDom) {
|
|
1133
|
+
const parentDomRect = parentDom.getBoundingClientRect();
|
|
1134
|
+
const parentRectType = domRect2rectType(parentDomRect);
|
|
1135
|
+
rectType.x -= parentRectType.x;
|
|
1136
|
+
rectType.y -= parentRectType.y;
|
|
1137
|
+
}
|
|
1134
1138
|
}
|
|
1135
1139
|
const anchor = parseTransformOrigin(computedStyle);
|
|
1136
1140
|
anchorRef.current = anchor;
|
|
@@ -1205,7 +1209,8 @@ function PortalInstance(inProps) {
|
|
|
1205
1209
|
anchor,
|
|
1206
1210
|
cornerRadius,
|
|
1207
1211
|
opacity,
|
|
1208
|
-
inheritedPortalStyle.position
|
|
1212
|
+
inheritedPortalStyle.position,
|
|
1213
|
+
isSubPortal
|
|
1209
1214
|
);
|
|
1210
1215
|
const JSXPortalInstance = renderJSXPortalInstance(
|
|
1211
1216
|
props,
|
|
@@ -2392,9 +2397,12 @@ var Model3DNative = class {
|
|
|
2392
2397
|
if (!this.entity || !this.spatialModel3DComponent) {
|
|
2393
2398
|
return;
|
|
2394
2399
|
}
|
|
2400
|
+
const computedStyle = getComputedStyle(dom);
|
|
2401
|
+
const isFixed = computedStyle.position === "fixed";
|
|
2402
|
+
const scrollY = isFixed ? 0 : window.scrollY;
|
|
2395
2403
|
const rect = dom.getBoundingClientRect();
|
|
2396
2404
|
const targetPosX = rect.left + (rect.right - rect.left) / 2;
|
|
2397
|
-
const targetPosY = rect.bottom + (rect.top - rect.bottom) / 2 +
|
|
2405
|
+
const targetPosY = rect.bottom + (rect.top - rect.bottom) / 2 + scrollY;
|
|
2398
2406
|
const { spatialTransform } = options;
|
|
2399
2407
|
const { position, rotation, scale } = spatialTransform;
|
|
2400
2408
|
const entity = this.entity;
|
|
@@ -2411,7 +2419,6 @@ var Model3DNative = class {
|
|
|
2411
2419
|
await entity.updateTransform();
|
|
2412
2420
|
const spatialModel3DComponent = this.spatialModel3DComponent;
|
|
2413
2421
|
await spatialModel3DComponent.setResolution(rect.width, rect.height);
|
|
2414
|
-
const computedStyle = getComputedStyle(dom);
|
|
2415
2422
|
const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
|
|
2416
2423
|
await spatialModel3DComponent.setOpacity(opacity);
|
|
2417
2424
|
const anchor = parseTransformOrigin(computedStyle);
|
|
@@ -2422,7 +2429,7 @@ var Model3DNative = class {
|
|
|
2422
2429
|
return;
|
|
2423
2430
|
}
|
|
2424
2431
|
const targetPosX = rect.x + rect.width / 2;
|
|
2425
|
-
const targetPosY = rect.y + rect.height / 2
|
|
2432
|
+
const targetPosY = rect.y + rect.height / 2;
|
|
2426
2433
|
const { position, rotation, scale } = spatialTransform;
|
|
2427
2434
|
const entity = this.entity;
|
|
2428
2435
|
entity.transform.position.x = targetPosX + position.x;
|
|
@@ -2449,6 +2456,19 @@ var Model3DNative = class {
|
|
|
2449
2456
|
this.spatialModel3DComponent.setOpacity(opacity);
|
|
2450
2457
|
}
|
|
2451
2458
|
}
|
|
2459
|
+
async setScrollWithParent(scrollWithParent) {
|
|
2460
|
+
if (this.spatialModel3DComponent) {
|
|
2461
|
+
this.spatialModel3DComponent.setScrollWithParent(scrollWithParent);
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
async changeParentEntity(parentEntity) {
|
|
2465
|
+
if (this.parentEntity !== parentEntity) {
|
|
2466
|
+
if (this.entity) {
|
|
2467
|
+
await this.entity.setParent(parentEntity);
|
|
2468
|
+
}
|
|
2469
|
+
this.parentEntity = parentEntity;
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2452
2472
|
set onDragStart(callback) {
|
|
2453
2473
|
if (this.spatialModel3DComponent) {
|
|
2454
2474
|
this.spatialModel3DComponent.onDragStart = callback;
|
|
@@ -2866,17 +2886,21 @@ function useSyncDomInfoFromStandardInstance(spatialId) {
|
|
|
2866
2886
|
return;
|
|
2867
2887
|
}
|
|
2868
2888
|
modelRef.current = dom;
|
|
2889
|
+
const computedStyle = getComputedStyle(dom);
|
|
2890
|
+
inheritedPortalStyleRef.current = getInheritedStyleProps(computedStyle);
|
|
2891
|
+
const stylePosition = inheritedPortalStyleRef.current.position;
|
|
2892
|
+
const isFixedPosition = stylePosition === "fixed";
|
|
2869
2893
|
let domRect2 = dom.getBoundingClientRect();
|
|
2870
2894
|
let rectType = domRect2rectType(domRect2);
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2895
|
+
if (!isFixedPosition) {
|
|
2896
|
+
const parentDom = spatialReactContextObject?.queryParentSpatialDom(spatialId);
|
|
2897
|
+
if (parentDom) {
|
|
2898
|
+
const parentDomRect = parentDom.getBoundingClientRect();
|
|
2899
|
+
const parentRectType = domRect2rectType(parentDomRect);
|
|
2900
|
+
rectType.x -= parentRectType.x;
|
|
2901
|
+
rectType.y -= parentRectType.y;
|
|
2902
|
+
}
|
|
2877
2903
|
}
|
|
2878
|
-
const computedStyle = getComputedStyle(dom);
|
|
2879
|
-
inheritedPortalStyleRef.current = getInheritedStyleProps(computedStyle);
|
|
2880
2904
|
const anchor = parseTransformOrigin(computedStyle);
|
|
2881
2905
|
anchorRef.current = anchor;
|
|
2882
2906
|
const opacity = parseFloat(computedStyle.getPropertyValue("opacity"));
|
|
@@ -3050,6 +3074,22 @@ function renderModel3DPortalInstance(spatialId, props) {
|
|
|
3050
3074
|
model3DNativeRef.current.setOpacity(opacity);
|
|
3051
3075
|
}
|
|
3052
3076
|
}, [model3DNativeRef.current, opacity]);
|
|
3077
|
+
const isFixedPosition = inheritedPortalStyle.position == "fixed";
|
|
3078
|
+
useEffect13(() => {
|
|
3079
|
+
if (model3DNativeRef.current) {
|
|
3080
|
+
model3DNativeRef.current.setScrollWithParent(
|
|
3081
|
+
inheritedPortalStyle.position !== "fixed"
|
|
3082
|
+
);
|
|
3083
|
+
if (isFixedPosition) {
|
|
3084
|
+
;
|
|
3085
|
+
(async function() {
|
|
3086
|
+
var wc = await getSession().getCurrentWindowComponent();
|
|
3087
|
+
var ent = await wc.getEntity();
|
|
3088
|
+
model3DNativeRef.current?.changeParentEntity(ent);
|
|
3089
|
+
})();
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
}, [model3DNativeRef.current, isFixedPosition]);
|
|
3053
3093
|
const onSuccess = useCallback5(() => {
|
|
3054
3094
|
;
|
|
3055
3095
|
modelRef.current.ready = true;
|
|
@@ -3087,7 +3127,7 @@ function renderModel3DPortalInstance(spatialId, props) {
|
|
|
3087
3127
|
}
|
|
3088
3128
|
};
|
|
3089
3129
|
}, [modelUrl]);
|
|
3090
|
-
const needRenderPlaceHolder = inheritedPortalStyle.position !== "absolute";
|
|
3130
|
+
const needRenderPlaceHolder = inheritedPortalStyle.position !== "absolute" && inheritedPortalStyle.position !== "fixed";
|
|
3091
3131
|
if (!needRenderPlaceHolder && phase !== "failure") {
|
|
3092
3132
|
return /* @__PURE__ */ jsx12(Fragment2, {});
|
|
3093
3133
|
} else {
|
|
@@ -3344,6 +3384,16 @@ function ModelBase(inProps, ref) {
|
|
|
3344
3384
|
);
|
|
3345
3385
|
const isWebEnv = !getSession();
|
|
3346
3386
|
if (isWebEnv) {
|
|
3387
|
+
useEffect16(() => {
|
|
3388
|
+
if (gltfSourceURL == "") {
|
|
3389
|
+
console.warn("Unable to display model, no gltf/glb source provided");
|
|
3390
|
+
if (props2.onLoad) {
|
|
3391
|
+
props2.onLoad({
|
|
3392
|
+
target: { ready: false, currentSrc: gltfSourceURL }
|
|
3393
|
+
});
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
}, []);
|
|
3347
3397
|
const myModelViewer = useRef12(null);
|
|
3348
3398
|
const { className, style = {}, ...props2 } = inProps;
|
|
3349
3399
|
const isDragging = useRef12(false);
|