@riboseinc/anafero-cli 0.0.16 → 0.0.18

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/bootstrap.js CHANGED
@@ -132617,25 +132617,42 @@ var VersionWorkspace = function({
132617
132617
  hasFragment ? `#${rpath.split("#")[1]}` : null
132618
132618
  ];
132619
132619
  }, [expandUnversionedPath]);
132620
+ const scrollToResource = (0, import_react218.useCallback)((resourceURI) => {
132621
+ const el = document.getElementById(resourceURI) ?? document.querySelector(`[about="${resourceURI}"]`);
132622
+ if (el) {
132623
+ try {
132624
+ el.scrollIntoView();
132625
+ } catch (e2) {
132626
+ console.error("Failed to scroll element into view", resourceURI);
132627
+ }
132628
+ } else {
132629
+ console.error("Element not found for resource to scroll to", resourceURI);
132630
+ }
132631
+ }, []);
132620
132632
  (0, import_react218.useEffect)(() => {
132621
132633
  const handlePopState = function() {
132622
132634
  const uri = typeof history.state?.res === "string" ? history.state.res : void 0;
132623
132635
  let path = null;
132624
- try {
132625
- path = locateResource(uri);
132626
- } catch (e2) {
132627
- console.error("Error locating resource while popping state", e2);
132636
+ if (uri) {
132637
+ try {
132638
+ path = locateResource(uri);
132639
+ } catch (e2) {
132640
+ console.error("Error locating resource while popping state", e2);
132641
+ path = null;
132642
+ }
132643
+ } else {
132628
132644
  path = null;
132629
132645
  }
132630
132646
  if (uri && path) {
132631
132647
  const [, fragment] = expandResourcePath(path);
132632
132648
  dispatch({ type: "activated_resource", uri });
132633
132649
  if (fragment) {
132634
- window.location.hash = fragment;
132650
+ setTimeout(() => {
132651
+ setQueuedFragment(fragment.slice(1));
132652
+ }, 200);
132635
132653
  }
132636
132654
  } else {
132637
- console.warn("When popping state, could not resolve resource URI or locate resource path");
132638
- window.location.reload();
132655
+ console.warn("While popping state, could not resolve resource URI or locate resource path", uri, history.state?.res);
132639
132656
  return;
132640
132657
  }
132641
132658
  };
@@ -132657,6 +132674,7 @@ var VersionWorkspace = function({
132657
132674
  dispatch({ type: "activated_resource", uri: res });
132658
132675
  }
132659
132676
  }, [expandResourcePath, locateResource, state.activeResourceURI]);
132677
+ const [queuedFragment, setQueuedFragment] = (0, import_react218.useState)("");
132660
132678
  const setUpInterceptor = (0, import_react218.useCallback)((resourcesRef) => {
132661
132679
  intercept_nav_default(resourcesRef, {
132662
132680
  // shadowDom: true,
@@ -132666,12 +132684,12 @@ var VersionWorkspace = function({
132666
132684
  return;
132667
132685
  }
132668
132686
  const url2 = new URL(href, document.baseURI);
132669
- const absoluteHref = url2.pathname;
132687
+ const absoluteHref = decodeURIComponent(url2.pathname);
132670
132688
  const resourceURI = reverseResource(absoluteHref);
132671
132689
  if (resourceURI) {
132672
132690
  dispatch({ type: "activated_resource", uri: resourceURI });
132673
132691
  if (url2.hash) {
132674
- window.location.hash = url2.hash;
132692
+ setQueuedFragment(decodeURIComponent(url2.hash.slice(1)));
132675
132693
  }
132676
132694
  evt.stopPropagation();
132677
132695
  evt.preventDefault();
@@ -132713,6 +132731,16 @@ var VersionWorkspace = function({
132713
132731
  }, [hierarchy, state.expandedResourceURIs, actualSelected]);
132714
132732
  const routerProps = (0, import_react218.useMemo)(() => ({ router: { navigate } }), [navigate]);
132715
132733
  const isLoading = Object.values(resourceDeps).find((val) => typeof val === "function");
132734
+ (0, import_react218.useEffect)(() => {
132735
+ if (!isLoading && queuedFragment) {
132736
+ const elID = queuedFragment;
132737
+ window.location.hash = `#${encodeURIComponent(elID)}`;
132738
+ setTimeout(() => {
132739
+ scrollToResource(elID);
132740
+ setQueuedFragment("");
132741
+ }, 500);
132742
+ }
132743
+ }, [isLoading, queuedFragment]);
132716
132744
  const lastVisibleResourceMarkerIntersection = useInView({
132717
132745
  threshold: 0,
132718
132746
  initialInView: true