@superblocksteam/library 2.0.124-next.0 → 2.0.124-next.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/lib/index.js +18 -1
- package/dist/lib/index.js.map +1 -1
- package/package.json +4 -4
package/dist/lib/index.js
CHANGED
|
@@ -1902,6 +1902,16 @@ function useTypedApi() {
|
|
|
1902
1902
|
//#endregion
|
|
1903
1903
|
//#region src/lib/internal-details/use-embed-message-listeners.ts
|
|
1904
1904
|
/**
|
|
1905
|
+
* Normalizes a hash to match `window.location.hash` semantics: empty when
|
|
1906
|
+
* absent, otherwise prefixed with `#`. React Router accepts a bare hash but
|
|
1907
|
+
* `window.location.hash` always carries the leading `#`, so we align both
|
|
1908
|
+
* before comparing.
|
|
1909
|
+
*/
|
|
1910
|
+
function normalizeHash(hash) {
|
|
1911
|
+
if (!hash) return "";
|
|
1912
|
+
return hash.startsWith("#") ? hash : `#${hash}`;
|
|
1913
|
+
}
|
|
1914
|
+
/**
|
|
1905
1915
|
* Hook that sets up common message listeners for embedded apps.
|
|
1906
1916
|
* Used by both edit-mode and deployed-mode EmbedWrapper components.
|
|
1907
1917
|
*/
|
|
@@ -1913,14 +1923,21 @@ function useEmbedMessageListeners(navigate, superblocksContext) {
|
|
|
1913
1923
|
};
|
|
1914
1924
|
iframeMessageHandler.addEventListener("sb-global-sync", globalSyncListener);
|
|
1915
1925
|
const navigateToListener = async (event) => {
|
|
1916
|
-
const { route, routeParams, queryParams } = event.data.payload;
|
|
1926
|
+
const { hash, route, routeParams, queryParams } = event.data.payload;
|
|
1917
1927
|
const eventSearch = new URLSearchParams(queryParams);
|
|
1918
1928
|
const nextSearch = new URLSearchParams(window.location.search);
|
|
1919
1929
|
for (const [key, value] of eventSearch.entries()) nextSearch.set(key, value);
|
|
1930
|
+
const previousHref = window.location.href;
|
|
1931
|
+
const previousHash = window.location.hash;
|
|
1920
1932
|
await navigate({
|
|
1933
|
+
hash,
|
|
1921
1934
|
pathname: generatePath(route, routeParams),
|
|
1922
1935
|
search: nextSearch.toString()
|
|
1923
1936
|
});
|
|
1937
|
+
if (normalizeHash(hash) !== previousHash) window.dispatchEvent(new HashChangeEvent("hashchange", {
|
|
1938
|
+
newURL: window.location.href,
|
|
1939
|
+
oldURL: previousHref
|
|
1940
|
+
}));
|
|
1924
1941
|
};
|
|
1925
1942
|
iframeMessageHandler.addEventListener("route-change", navigateToListener);
|
|
1926
1943
|
const embedPropertyChangeListener = (event) => {
|