@riboseinc/anafero-cli 0.0.18 → 0.0.19

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,18 +132617,6 @@ 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
- }, []);
132632
132620
  (0, import_react218.useEffect)(() => {
132633
132621
  const handlePopState = function() {
132634
132622
  const uri = typeof history.state?.res === "string" ? history.state.res : void 0;
@@ -132674,8 +132662,11 @@ var VersionWorkspace = function({
132674
132662
  dispatch({ type: "activated_resource", uri: res });
132675
132663
  }
132676
132664
  }, [expandResourcePath, locateResource, state.activeResourceURI]);
132677
- const [queuedFragment, setQueuedFragment] = (0, import_react218.useState)("");
132665
+ const [resourceContainerElement, setResourceContainerElement] = (0, import_react218.useState)(null);
132678
132666
  const setUpInterceptor = (0, import_react218.useCallback)((resourcesRef) => {
132667
+ if (resourcesRef) {
132668
+ setResourceContainerElement(resourcesRef);
132669
+ }
132679
132670
  intercept_nav_default(resourcesRef, {
132680
132671
  // shadowDom: true,
132681
132672
  }, function handleIntercept(evt, el) {
@@ -132731,16 +132722,50 @@ var VersionWorkspace = function({
132731
132722
  }, [hierarchy, state.expandedResourceURIs, actualSelected]);
132732
132723
  const routerProps = (0, import_react218.useMemo)(() => ({ router: { navigate } }), [navigate]);
132733
132724
  const isLoading = Object.values(resourceDeps).find((val) => typeof val === "function");
132725
+ const [queuedFragment, setQueuedFragment] = (0, import_react218.useState)("");
132726
+ const scrollToResource = (0, import_react218.useCallback)(() => {
132727
+ if (!queuedFragment) {
132728
+ return;
132729
+ }
132730
+ if (!resourceContainerElement) {
132731
+ console.warn("Cannot scroll to resource: no resource container element");
132732
+ return;
132733
+ }
132734
+ const el = document.getElementById(queuedFragment) ?? resourceContainerElement.querySelector(`[about="${queuedFragment}"]`);
132735
+ if (el) {
132736
+ try {
132737
+ el.scrollIntoView();
132738
+ } catch (e2) {
132739
+ console.error("Failed to scroll element into view", queuedFragment);
132740
+ }
132741
+ setQueuedFragment("");
132742
+ } else {
132743
+ console.error("Element not found for resource to scroll to", queuedFragment);
132744
+ }
132745
+ }, [resourceContainerElement, queuedFragment]);
132734
132746
  (0, import_react218.useEffect)(() => {
132735
- if (!isLoading && queuedFragment) {
132736
- const elID = queuedFragment;
132737
- window.location.hash = `#${encodeURIComponent(elID)}`;
132738
- setTimeout(() => {
132739
- scrollToResource(elID);
132747
+ if (!isLoading && queuedFragment && resourceContainerElement) {
132748
+ const resourceID = queuedFragment;
132749
+ window.location.hash = `#${encodeURIComponent(resourceID)}`;
132750
+ const observer = new MutationObserver(scrollToResource);
132751
+ scrollToResource();
132752
+ observer.observe(resourceContainerElement, {
132753
+ attributes: false,
132754
+ childList: true,
132755
+ characterData: false,
132756
+ subtree: true
132757
+ });
132758
+ const timeout2 = setTimeout(() => {
132740
132759
  setQueuedFragment("");
132741
- }, 500);
132760
+ }, 5e3);
132761
+ return function() {
132762
+ observer.disconnect();
132763
+ window.clearTimeout(timeout2);
132764
+ };
132742
132765
  }
132743
- }, [isLoading, queuedFragment]);
132766
+ return function() {
132767
+ };
132768
+ }, [isLoading, queuedFragment, scrollToResource, resourceContainerElement]);
132744
132769
  const lastVisibleResourceMarkerIntersection = useInView({
132745
132770
  threshold: 0,
132746
132771
  initialInView: true