@equinor/amplify-component-lib 9.14.0-beta.0 → 9.14.0-beta.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.
@@ -1 +1 @@
1
- import{jsx as t}from"react/jsx-runtime";import{createContext as e,useState as r,useRef as n,useMemo as o,useEffect as i,useCallback as s,useContext as u}from"react";import{useNavigate as l,useLocation as c}from"@tanstack/react-router";import{useOnScreenMultiple as a}from"../atoms/hooks/useOnScreenMultiple.js";import{getValues as m}from"./TableOfContentsProvider.utils.js";const d=e(void 0);function h(){const t=u(d);if(void 0===t)throw new Error("'useTableOfContents' must be used within provider");return t}const f=({items:e,children:u,hashNavigation:h})=>{const f=l(),{hash:p}=c(),[v,g]=r(e[0]?.value),[b,I]=r([]),[O,w]=r(""!==p),M=n(!1),j=o(()=>e.flatMap(t=>m([],t)),[e]);i(()=>{I(j.map(t=>document.getElementById(t)))},[j]),i(()=>{p.length||(M.current=!0)},[p]);const k=s(t=>{if(t.value===v)return!0;if(t.children&&v){return m([],t).includes(v)}return!1},[v]),x=a(b),y=n(-1),A=s((t,e)=>{const r=j.findIndex(e=>e===t),n=b[r];if(n){const t=e?.shouldInstantlyJumpOnMount&&O?"instant":e?.behavior??"smooth";n.scrollIntoView({block:"start",behavior:t}),y.current=r;let o=1/0,i=0;const s=()=>{const t=n?.getBoundingClientRect().top;if(t===o){if(i+=1,i>1)return g(j[r]),h&&(f({to:`#${j[r]}`,replace:!0}),w(!1)),void(y.current=-1)}else i=0,o=t;requestAnimationFrame(s)};requestAnimationFrame(s)}},[b,h,f,O,j]);return i(()=>{if(0===x.length||x.length!==j.length||-1!==y.current)return;let t=-1;for(let e=x.length-1;e>=0;e--)x[e]&&(t=e);if(-1===t||void 0===j.at(t))return;const e=p.replace("#","");if(!M.current&&e.length&&j.includes(e))return A(e,{behavior:"instant",shouldInstantlyJumpOnMount:!0}),void(M.current=!0);g(j[t]),h&&f({to:`#${j[t]}`,replace:!0})},[h,f,j,x]),t(d.Provider,{value:{items:e,selected:v,setSelected:A,isActive:k},children:u})};export{f as TableOfContentsProvider,h as useTableOfContents};
1
+ import{jsx as t}from"react/jsx-runtime";import{createContext as e,useState as r,useRef as n,useMemo as o,useEffect as i,useCallback as s,useContext as c}from"react";import{useNavigate as l,useLocation as u}from"@tanstack/react-router";import{useOnScreenMultiple as a}from"../atoms/hooks/useOnScreenMultiple.js";import{getValues as h}from"./TableOfContentsProvider.utils.js";const m=e(void 0);function d(){const t=c(m);if(void 0===t)throw new Error("'useTableOfContents' must be used within provider");return t}const f=({items:e,children:c,hashNavigation:d})=>{const f=l(),{hash:v}=u(),[p,b]=r(e[0]?.value),[g,I]=r([]),w=n(!1),O=o(()=>e.flatMap(t=>h([],t)),[e]);i(()=>{I(O.map(t=>document.getElementById(t)))},[O]),i(()=>{v.length||(w.current=!0)},[v]);const k=s(t=>{if(t.value===p)return!0;if(t.children&&p){return h([],t).includes(p)}return!1},[p]),C=a(g),M=n(-1),j=s((t,e)=>{const r=O.findIndex(e=>e===t);if(d)return b(O[r]),void f({to:".",hash:`#${O[r]}`,hashScrollIntoView:{block:"start",behavior:e?.shouldInstantlyJumpOnMount?"instant":e?.behavior??"smooth"},replace:!0});const n=g[r];if(n){const t=e?.behavior??"smooth";n.scrollIntoView({block:"start",behavior:t}),M.current=r;let o=1/0,i=0;const s=()=>{const t=n?.getBoundingClientRect().top;if(t===o){if(i+=1,i>1)return b(O[r]),void(M.current=-1)}else i=0,o=t;requestAnimationFrame(s)};requestAnimationFrame(s)}},[g,d,f,O]);return i(()=>{if(v&&!w.current){w.current=!0;const t=decodeURIComponent(v.replace("#",""));if(!t.length||!O.includes(t))return;j(t,{behavior:"instant",shouldInstantlyJumpOnMount:!0})}},[j,v,O]),i(()=>{if(0===C.length||C.length!==O.length||-1!==M.current||!w.current)return;let t=-1;for(let e=C.length-1;e>=0;e--)C[e]&&(t=e);-1!==t&&void 0!==O.at(t)&&j(O[t])},[j,O,C]),t(m.Provider,{value:{items:e,selected:p,setSelected:j,isActive:k},children:c})};export{f as TableOfContentsProvider,d as useTableOfContents};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/amplify-component-lib",
3
- "version": "9.14.0-beta.0",
3
+ "version": "9.14.0-beta.2",
4
4
  "description": "Frontend Typescript components for the Amplify team",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",