@webspatial/react-sdk 0.0.11 → 0.0.13
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 +56 -16
- package/dist/default/index.js.map +1 -1
- package/dist/web/index.js +56 -16
- package/dist/web/index.js.map +1 -1
- package/package.json +2 -2
package/dist/web/index.js
CHANGED
|
@@ -193,7 +193,8 @@ function simplifyEntityTree(rootTree) {
|
|
|
193
193
|
visible: node.visible,
|
|
194
194
|
cornerRadius: node.components[0].cornerRadius,
|
|
195
195
|
backgroundMaterial: node.components[0].backgroundMaterial,
|
|
196
|
-
isOpaque: node.components[0].isOpaque
|
|
196
|
+
isOpaque: node.components[0].isOpaque,
|
|
197
|
+
isScrollEnabled: node.components[0].isScrollEnabled
|
|
197
198
|
};
|
|
198
199
|
nodeMap[node.id] = newNode;
|
|
199
200
|
if (!parent) {
|
|
@@ -465,6 +466,12 @@ var SpatialWindowManager = class {
|
|
|
465
466
|
entity;
|
|
466
467
|
webview;
|
|
467
468
|
window = null;
|
|
469
|
+
parentSpatialWindowManager;
|
|
470
|
+
isFixedPosition;
|
|
471
|
+
constructor(options) {
|
|
472
|
+
this.isFixedPosition = options.isFixedPosition || false;
|
|
473
|
+
this.parentSpatialWindowManager = options.parentSpatialWindowManager;
|
|
474
|
+
}
|
|
468
475
|
setDebugName(debugName) {
|
|
469
476
|
this.entity?._setName(debugName);
|
|
470
477
|
}
|
|
@@ -481,7 +488,7 @@ var SpatialWindowManager = class {
|
|
|
481
488
|
var ent = await wc.getEntity();
|
|
482
489
|
await this.entity.setParent(ent);
|
|
483
490
|
}
|
|
484
|
-
async initInternalFromWindow(
|
|
491
|
+
async initInternalFromWindow() {
|
|
485
492
|
if (true) return;
|
|
486
493
|
var w = await getSession().createWindowContext();
|
|
487
494
|
this.window = w;
|
|
@@ -492,14 +499,27 @@ var SpatialWindowManager = class {
|
|
|
492
499
|
await this.webview.setScrollWithParent(true);
|
|
493
500
|
await this.webview.setScrollEnabled(false);
|
|
494
501
|
await this.entity.setComponent(this.webview);
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
502
|
+
this.setEntityParentByCSSPosition(this.isFixedPosition);
|
|
503
|
+
}
|
|
504
|
+
async updateCSSPosition(isFixedPosition) {
|
|
505
|
+
if (this.isFixedPosition === isFixedPosition) {
|
|
506
|
+
return;
|
|
507
|
+
} else {
|
|
508
|
+
this.isFixedPosition = isFixedPosition;
|
|
509
|
+
}
|
|
510
|
+
return this.setEntityParentByCSSPosition(isFixedPosition);
|
|
511
|
+
}
|
|
512
|
+
async setEntityParentByCSSPosition(isFixedPosition) {
|
|
513
|
+
if (this.initPromise) {
|
|
514
|
+
await this.initPromise;
|
|
515
|
+
if (isFixedPosition || !this.parentSpatialWindowManager) {
|
|
500
516
|
var wc = await getSession().getCurrentWindowComponent();
|
|
501
517
|
var ent = await wc.getEntity();
|
|
502
518
|
await this.entity.setParent(ent);
|
|
519
|
+
} else {
|
|
520
|
+
const parentSpatialWindowManager = this.parentSpatialWindowManager;
|
|
521
|
+
await parentSpatialWindowManager.initPromise;
|
|
522
|
+
this.entity.setParent(parentSpatialWindowManager.entity);
|
|
503
523
|
}
|
|
504
524
|
}
|
|
505
525
|
}
|
|
@@ -507,8 +527,8 @@ var SpatialWindowManager = class {
|
|
|
507
527
|
this.initPromise = this.initInternal(url);
|
|
508
528
|
await this.initPromise;
|
|
509
529
|
}
|
|
510
|
-
async initFromWidow(
|
|
511
|
-
this.initPromise = this.initInternalFromWindow(
|
|
530
|
+
async initFromWidow() {
|
|
531
|
+
this.initPromise = this.initInternalFromWindow();
|
|
512
532
|
await this.initPromise;
|
|
513
533
|
}
|
|
514
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 }) {
|
|
@@ -562,8 +582,10 @@ function usePortalContainer(options) {
|
|
|
562
582
|
let spawnedResult;
|
|
563
583
|
async function asyncCreatePortalContainer() {
|
|
564
584
|
const session = getSession();
|
|
565
|
-
let windowMgr = new SpatialWindowManager(
|
|
566
|
-
|
|
585
|
+
let windowMgr = new SpatialWindowManager({
|
|
586
|
+
parentSpatialWindowManager: parentSpatialWindowManager || void 0
|
|
587
|
+
});
|
|
588
|
+
await windowMgr.initFromWidow();
|
|
567
589
|
if (isDestroyed) {
|
|
568
590
|
windowMgr.destroy();
|
|
569
591
|
return;
|
|
@@ -962,6 +984,12 @@ function useSyncSpatialProps(spatialWindowManager, props, domRect, anchor, corne
|
|
|
962
984
|
} else {
|
|
963
985
|
Object.assign(cornerRadiusObject, cornerRadius);
|
|
964
986
|
}
|
|
987
|
+
const isFixedPosition = stylePosition == "fixed";
|
|
988
|
+
useEffect3(() => {
|
|
989
|
+
if (spatialWindowManager && spatialWindowManager.webview) {
|
|
990
|
+
spatialWindowManager.updateCSSPosition(isFixedPosition);
|
|
991
|
+
}
|
|
992
|
+
}, [spatialWindowManager, isFixedPosition]);
|
|
965
993
|
useEffect3(() => {
|
|
966
994
|
if (spatialWindowManager && spatialWindowManager.webview) {
|
|
967
995
|
const webview = spatialWindowManager.webview;
|
|
@@ -985,7 +1013,7 @@ function useSyncSpatialProps(spatialWindowManager, props, domRect, anchor, corne
|
|
|
985
1013
|
const webview = spatialWindowManager.webview;
|
|
986
1014
|
(async function() {
|
|
987
1015
|
webview.setScrollEnabled(allowScroll || styleOverflow == "scroll");
|
|
988
|
-
const isFixed = scrollWithParent == false ||
|
|
1016
|
+
const isFixed = scrollWithParent == false || isFixedPosition;
|
|
989
1017
|
webview.setScrollWithParent(!isFixed);
|
|
990
1018
|
})();
|
|
991
1019
|
}
|
|
@@ -993,9 +1021,19 @@ function useSyncSpatialProps(spatialWindowManager, props, domRect, anchor, corne
|
|
|
993
1021
|
spatialWindowManager,
|
|
994
1022
|
allowScroll,
|
|
995
1023
|
scrollWithParent,
|
|
996
|
-
|
|
1024
|
+
isFixedPosition,
|
|
997
1025
|
styleOverflow
|
|
998
1026
|
]);
|
|
1027
|
+
useEffect3(() => {
|
|
1028
|
+
if (spatialWindowManager && spatialWindowManager.webview) {
|
|
1029
|
+
const webview = spatialWindowManager.webview;
|
|
1030
|
+
(async function() {
|
|
1031
|
+
webview.setScrollEnabled(allowScroll || styleOverflow == "scroll");
|
|
1032
|
+
const isFixed = scrollWithParent == false || stylePosition == "fixed";
|
|
1033
|
+
webview.setScrollWithParent(!isFixed);
|
|
1034
|
+
})();
|
|
1035
|
+
}
|
|
1036
|
+
}, [spatialWindowManager, allowScroll, scrollWithParent, stylePosition]);
|
|
999
1037
|
useEffect3(() => {
|
|
1000
1038
|
if (spatialWindowManager) {
|
|
1001
1039
|
;
|
|
@@ -1083,17 +1121,19 @@ function useSyncDomRect(spatialId) {
|
|
|
1083
1121
|
if (!dom) {
|
|
1084
1122
|
return;
|
|
1085
1123
|
}
|
|
1124
|
+
const computedStyle = getComputedStyle(dom);
|
|
1125
|
+
inheritedPortalStyleRef.current = getInheritedStyleProps(computedStyle);
|
|
1126
|
+
const stylePosition = inheritedPortalStyleRef.current.position;
|
|
1127
|
+
const isFixedPosition = stylePosition === "fixed";
|
|
1086
1128
|
let domRect2 = dom.getBoundingClientRect();
|
|
1087
1129
|
let rectType = domRect2rectType(domRect2);
|
|
1088
1130
|
const parentDom = spatialReactContextObject?.queryParentSpatialDom(spatialId);
|
|
1089
|
-
if (parentDom) {
|
|
1131
|
+
if (!isFixedPosition && parentDom) {
|
|
1090
1132
|
const parentDomRect = parentDom.getBoundingClientRect();
|
|
1091
1133
|
const parentRectType = domRect2rectType(parentDomRect);
|
|
1092
1134
|
rectType.x -= parentRectType.x;
|
|
1093
1135
|
rectType.y -= parentRectType.y;
|
|
1094
1136
|
}
|
|
1095
|
-
const computedStyle = getComputedStyle(dom);
|
|
1096
|
-
inheritedPortalStyleRef.current = getInheritedStyleProps(computedStyle);
|
|
1097
1137
|
const anchor = parseTransformOrigin(computedStyle);
|
|
1098
1138
|
anchorRef.current = anchor;
|
|
1099
1139
|
const cornerRadius = parseCornerRadius(computedStyle);
|