@weaverse/hydrogen 5.20.1 → 5.20.2
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/index.js +106 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +106 -54
- package/dist/index.mjs.map +1 -1
- package/dist/types/utils/is-same-loader-payload.d.ts +39 -0
- package/dist/types/utils/is-same-loader-payload.d.ts.map +1 -0
- package/dist/types/utils/sync-reused-instance.d.ts +5 -3
- package/dist/types/utils/sync-reused-instance.d.ts.map +1 -1
- package/dist/types/utils/use-studio.d.ts +0 -1
- package/dist/types/utils/use-studio.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/utils/is-same-loader-payload.ts +187 -0
- package/src/utils/sync-reused-instance.ts +11 -8
- package/src/utils/use-studio.ts +0 -37
- package/dist/types/utils/pixel.d.ts +0 -16
- package/dist/types/utils/pixel.d.ts.map +0 -1
- package/src/utils/pixel.ts +0 -71
package/dist/index.js
CHANGED
|
@@ -618,12 +618,116 @@ function normalizeRequestInfo(params, browserLocation = getBrowserLocation()) {
|
|
|
618
618
|
};
|
|
619
619
|
}
|
|
620
620
|
|
|
621
|
+
// src/utils/is-same-loader-payload.ts
|
|
622
|
+
function isJsonOmitted(value) {
|
|
623
|
+
return value === void 0 || typeof value === "function" || typeof value === "symbol";
|
|
624
|
+
}
|
|
625
|
+
function isObjectLike(value) {
|
|
626
|
+
return value !== null && typeof value === "object";
|
|
627
|
+
}
|
|
628
|
+
function isThenable(value) {
|
|
629
|
+
return typeof value.then === "function";
|
|
630
|
+
}
|
|
631
|
+
function isPlainObject(value) {
|
|
632
|
+
const proto = Object.getPrototypeOf(value);
|
|
633
|
+
return proto === Object.prototype || proto === null;
|
|
634
|
+
}
|
|
635
|
+
function toJsonValue(value) {
|
|
636
|
+
return typeof value.toJSON === "function" ? value.toJSON() : value;
|
|
637
|
+
}
|
|
638
|
+
function toFiniteOrNull(value) {
|
|
639
|
+
return typeof value === "number" && !Number.isFinite(value) ? null : value;
|
|
640
|
+
}
|
|
641
|
+
function isSameLoaderPayload(left, right) {
|
|
642
|
+
const activePairs = [];
|
|
643
|
+
function isSame(rawA, rawB) {
|
|
644
|
+
if (Object.is(rawA, rawB)) {
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
const a = toFiniteOrNull(rawA);
|
|
648
|
+
const b = toFiniteOrNull(rawB);
|
|
649
|
+
if (a === b) {
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
if (!(isObjectLike(a) && isObjectLike(b))) {
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
if (isThenable(a) || isThenable(b)) {
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
for (let index = 0; index < activePairs.length; index += 2) {
|
|
659
|
+
if (activePairs[index] === a && activePairs[index + 1] === b) {
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
activePairs.push(a, b);
|
|
664
|
+
try {
|
|
665
|
+
return isSameOpenPair(a, b);
|
|
666
|
+
} finally {
|
|
667
|
+
activePairs.length -= 2;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
function isSameOpenPair(a, b) {
|
|
671
|
+
const aJson = toJsonValue(a);
|
|
672
|
+
const bJson = toJsonValue(b);
|
|
673
|
+
if (aJson !== a || bJson !== b) {
|
|
674
|
+
return isSame(aJson, bJson);
|
|
675
|
+
}
|
|
676
|
+
if (Array.isArray(a) !== Array.isArray(b)) {
|
|
677
|
+
return false;
|
|
678
|
+
}
|
|
679
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
680
|
+
return isSameArray(a, b);
|
|
681
|
+
}
|
|
682
|
+
if (!(isPlainObject(a) && isPlainObject(b))) {
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
return isSameObject(a, b);
|
|
686
|
+
}
|
|
687
|
+
function isSameArray(a, b) {
|
|
688
|
+
if (a.length !== b.length) {
|
|
689
|
+
return false;
|
|
690
|
+
}
|
|
691
|
+
for (let index = 0; index < a.length; index++) {
|
|
692
|
+
const aItem = isJsonOmitted(a[index]) ? null : a[index];
|
|
693
|
+
const bItem = isJsonOmitted(b[index]) ? null : b[index];
|
|
694
|
+
if (!isSame(aItem, bItem)) {
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return true;
|
|
699
|
+
}
|
|
700
|
+
function isSameObject(a, b) {
|
|
701
|
+
let aKeyCount = 0;
|
|
702
|
+
for (const key of Object.keys(a)) {
|
|
703
|
+
if (isJsonOmitted(a[key])) {
|
|
704
|
+
continue;
|
|
705
|
+
}
|
|
706
|
+
aKeyCount++;
|
|
707
|
+
if (!isSame(a[key], b[key])) {
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
let bKeyCount = 0;
|
|
712
|
+
for (const key of Object.keys(b)) {
|
|
713
|
+
if (!isJsonOmitted(b[key])) {
|
|
714
|
+
bKeyCount++;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
return aKeyCount === bKeyCount;
|
|
718
|
+
}
|
|
719
|
+
return isSame(left, right);
|
|
720
|
+
}
|
|
721
|
+
|
|
621
722
|
// src/utils/sync-reused-instance.ts
|
|
622
723
|
function syncReusedInstance(weaverse, params) {
|
|
623
724
|
weaverse.requestInfo = params.requestInfo;
|
|
624
725
|
weaverse.internal = params.internal;
|
|
625
|
-
let dataChanged =
|
|
626
|
-
let contextChanged =
|
|
726
|
+
let dataChanged = !isSameLoaderPayload(weaverse.data, params.data);
|
|
727
|
+
let contextChanged = !isSameLoaderPayload(
|
|
728
|
+
weaverse.dataContext ?? null,
|
|
729
|
+
params.dataContext ?? null
|
|
730
|
+
);
|
|
627
731
|
if (contextChanged) {
|
|
628
732
|
weaverse.dataContext = params.dataContext ?? null;
|
|
629
733
|
}
|
|
@@ -638,35 +742,6 @@ function syncReusedInstance(weaverse, params) {
|
|
|
638
742
|
weaverse.triggerUpdate();
|
|
639
743
|
}
|
|
640
744
|
}
|
|
641
|
-
|
|
642
|
-
// src/utils/pixel.ts
|
|
643
|
-
var currentNavigationKey = null;
|
|
644
|
-
var firedPageIds = /* @__PURE__ */ new Set();
|
|
645
|
-
var mountedInstances = 0;
|
|
646
|
-
function observeNavigation(navigationKey) {
|
|
647
|
-
if (navigationKey !== currentNavigationKey) {
|
|
648
|
-
currentNavigationKey = navigationKey;
|
|
649
|
-
firedPageIds.clear();
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
function shouldFirePixel(navigationKey, pageId) {
|
|
653
|
-
observeNavigation(navigationKey);
|
|
654
|
-
if (firedPageIds.has(pageId)) {
|
|
655
|
-
return false;
|
|
656
|
-
}
|
|
657
|
-
firedPageIds.add(pageId);
|
|
658
|
-
return true;
|
|
659
|
-
}
|
|
660
|
-
function registerPixelInstance() {
|
|
661
|
-
mountedInstances += 1;
|
|
662
|
-
return () => {
|
|
663
|
-
mountedInstances -= 1;
|
|
664
|
-
if (mountedInstances === 0) {
|
|
665
|
-
currentNavigationKey = null;
|
|
666
|
-
firedPageIds.clear();
|
|
667
|
-
}
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
745
|
var ThemeSettingsStore = class {
|
|
671
746
|
/** Current merged theme setting values. */
|
|
672
747
|
settings = {};
|
|
@@ -852,29 +927,6 @@ function useStudio(weaverse) {
|
|
|
852
927
|
react.loadScript(src).then(waitForStudio).then((studio) => studio?.init(weaverse)).catch(console.error);
|
|
853
928
|
}
|
|
854
929
|
}, [pathname, search, navigation.state]);
|
|
855
|
-
usePixel(weaverse);
|
|
856
|
-
}
|
|
857
|
-
function usePixel(context) {
|
|
858
|
-
let { projectId, pageId, isDesignMode, weaverseHost } = context;
|
|
859
|
-
let { key: navigationKey } = reactRouter.useLocation();
|
|
860
|
-
react$1.useEffect(() => {
|
|
861
|
-
if (!(projectId && pageId) || isDesignMode) {
|
|
862
|
-
return;
|
|
863
|
-
}
|
|
864
|
-
observeNavigation(navigationKey);
|
|
865
|
-
}, [navigationKey, projectId, pageId, isDesignMode]);
|
|
866
|
-
react$1.useEffect(() => {
|
|
867
|
-
if (!(projectId && pageId) || isDesignMode) {
|
|
868
|
-
return;
|
|
869
|
-
}
|
|
870
|
-
let unregister = registerPixelInstance();
|
|
871
|
-
if (shouldFirePixel(navigationKey, pageId)) {
|
|
872
|
-
let img = new Image();
|
|
873
|
-
img.onload = () => img.remove();
|
|
874
|
-
img.src = `${weaverseHost}/api/public/px?projectId=${projectId}&pageId=${pageId}`;
|
|
875
|
-
}
|
|
876
|
-
return unregister;
|
|
877
|
-
}, []);
|
|
878
930
|
}
|
|
879
931
|
var WeaverseHydrogenItem = class extends react.WeaverseItemStore {
|
|
880
932
|
/**
|