@vertesia/ui 0.79.3 → 0.79.4

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.
Files changed (77) hide show
  1. package/lib/esm/core/components/MenuList.js +2 -5
  2. package/lib/esm/core/components/MenuList.js.map +1 -1
  3. package/lib/esm/core/components/shadcn/dialog.js +16 -2
  4. package/lib/esm/core/components/shadcn/dialog.js.map +1 -1
  5. package/lib/esm/core/components/shadcn/filters/filter/SelectFilter.js +6 -9
  6. package/lib/esm/core/components/shadcn/filters/filter/SelectFilter.js.map +1 -1
  7. package/lib/esm/core/components/shadcn/filters/filterBar.js +1 -1
  8. package/lib/esm/core/components/shadcn/filters/filterBar.js.map +1 -1
  9. package/lib/esm/core/components/shadcn/selectBox.js +1 -1
  10. package/lib/esm/core/components/shadcn/selectBox.js.map +1 -1
  11. package/lib/esm/env/index.js +4 -1
  12. package/lib/esm/env/index.js.map +1 -1
  13. package/lib/esm/features/facets/CollectionsFacetsNav.js +5 -1
  14. package/lib/esm/features/facets/CollectionsFacetsNav.js.map +1 -1
  15. package/lib/esm/features/layout/GenericPageNavHeader.js +5 -2
  16. package/lib/esm/features/layout/GenericPageNavHeader.js.map +1 -1
  17. package/lib/esm/features/store/collections/EditCollectionView.js +1 -1
  18. package/lib/esm/features/store/collections/EditCollectionView.js.map +1 -1
  19. package/lib/esm/features/store/objects/DocumentSearchResults.js +2 -1
  20. package/lib/esm/features/store/objects/DocumentSearchResults.js.map +1 -1
  21. package/lib/esm/router/HistoryNavigator.js +22 -2
  22. package/lib/esm/router/HistoryNavigator.js.map +1 -1
  23. package/lib/esm/shell/login/UserInfo.js +2 -1
  24. package/lib/esm/shell/login/UserInfo.js.map +1 -1
  25. package/lib/esm/shell/login/UserSessionMenu.js +7 -1
  26. package/lib/esm/shell/login/UserSessionMenu.js.map +1 -1
  27. package/lib/esm/widgets/form/Form.js +5 -1
  28. package/lib/esm/widgets/form/Form.js.map +1 -1
  29. package/lib/esm/widgets/schema-editor/ManagedSchema.js +0 -3
  30. package/lib/esm/widgets/schema-editor/ManagedSchema.js.map +1 -1
  31. package/lib/esm/widgets/schema-editor/json-schema4-utils.js +1 -1
  32. package/lib/esm/widgets/schema-editor/json-schema4-utils.js.map +1 -1
  33. package/lib/tsconfig.tsbuildinfo +1 -1
  34. package/lib/types/core/components/shadcn/dialog.d.ts +2 -1
  35. package/lib/types/core/components/shadcn/dialog.d.ts.map +1 -1
  36. package/lib/types/core/components/shadcn/filters/filterBar.d.ts.map +1 -1
  37. package/lib/types/core/components/shadcn/selectBox.d.ts.map +1 -1
  38. package/lib/types/env/index.d.ts +3 -1
  39. package/lib/types/env/index.d.ts.map +1 -1
  40. package/lib/types/features/facets/CollectionsFacetsNav.d.ts.map +1 -1
  41. package/lib/types/features/layout/GenericPageNavHeader.d.ts.map +1 -1
  42. package/lib/types/features/store/objects/DocumentSearchResults.d.ts.map +1 -1
  43. package/lib/types/router/HistoryNavigator.d.ts +3 -0
  44. package/lib/types/router/HistoryNavigator.d.ts.map +1 -1
  45. package/lib/types/shell/login/UserInfo.d.ts.map +1 -1
  46. package/lib/types/shell/login/UserSessionMenu.d.ts.map +1 -1
  47. package/lib/types/widgets/form/Form.d.ts.map +1 -1
  48. package/lib/types/widgets/schema-editor/ManagedSchema.d.ts.map +1 -1
  49. package/lib/vertesia-ui-core.js +1 -1
  50. package/lib/vertesia-ui-core.js.map +1 -1
  51. package/lib/vertesia-ui-env.js +1 -1
  52. package/lib/vertesia-ui-env.js.map +1 -1
  53. package/lib/vertesia-ui-features.js +1 -1
  54. package/lib/vertesia-ui-features.js.map +1 -1
  55. package/lib/vertesia-ui-router.js +1 -1
  56. package/lib/vertesia-ui-router.js.map +1 -1
  57. package/lib/vertesia-ui-shell.js +1 -1
  58. package/lib/vertesia-ui-shell.js.map +1 -1
  59. package/lib/vertesia-ui-widgets.js +1 -1
  60. package/lib/vertesia-ui-widgets.js.map +1 -1
  61. package/package.json +7 -7
  62. package/src/core/components/MenuList.tsx +3 -6
  63. package/src/core/components/shadcn/dialog.tsx +19 -1
  64. package/src/core/components/shadcn/filters/filter/SelectFilter.tsx +31 -31
  65. package/src/core/components/shadcn/filters/filterBar.tsx +1 -0
  66. package/src/core/components/shadcn/selectBox.tsx +1 -0
  67. package/src/env/index.ts +7 -2
  68. package/src/features/facets/CollectionsFacetsNav.tsx +5 -1
  69. package/src/features/layout/GenericPageNavHeader.tsx +5 -2
  70. package/src/features/store/collections/EditCollectionView.tsx +2 -2
  71. package/src/features/store/objects/DocumentSearchResults.tsx +2 -1
  72. package/src/router/HistoryNavigator.ts +30 -2
  73. package/src/shell/login/UserInfo.tsx +2 -0
  74. package/src/shell/login/UserSessionMenu.tsx +12 -1
  75. package/src/widgets/form/Form.tsx +6 -1
  76. package/src/widgets/schema-editor/ManagedSchema.ts +0 -3
  77. package/src/widgets/schema-editor/json-schema4-utils.ts +1 -1
@@ -1,2 +1,2 @@
1
- import{jsx as t,jsxs as e}from"react/jsx-runtime";import{useRef as n,useEffect as a,createContext as r,useContext as i,useState as s,useMemo as o}from"react";import{useSafeLayoutEffect as h}from"@vertesia/ui/core";function c(t){return"/"===t||""===t}function l(t,e){return e=t.endsWith("/")&&e.startsWith("/")?t+e.substring(1):t.endsWith("/")||e.startsWith("/")?t+e:t+"/"+e}function u(t){if(""===t)return[];if("/"===t)return[""];let e=0,n=t.length;return t.startsWith("./")?e=2:t.startsWith("/")&&(e=1),t.endsWith("/")&&(n=t.length-1),(e>0||n<t.length?t.substring(e,n):t).split("/")}function d(t){if("string"==typeof t)return u(t);if(Array.isArray(t))return t;throw new Error(`Unsupported path object: ${t}`)}var m=Object.freeze({__proto__:null,getPathSegments:u,isRootPath:c,joinPath:l,toSegments:d});class p{path;params;hash;constructor(t){let e=t.lastIndexOf("#");e>-1?(this.hash=t.substring(e),t=t.substring(0,e)):this.hash="",e=t.indexOf("?"),e>-1?(this.path=t.substring(0,e),this.params=new URLSearchParams(t.substring(e+1))):(this.path=t,this.params=new URLSearchParams)}add(t){for(const[e,n]of Object.entries(t))this.params.set(e,n);return this}toString(){return this.path+"?"+this.params.toString()+this.hash}}const f=Symbol("BASE_PATH");class g{name;type;location;state;_canceled=!1;constructor(t,e,n,a){this.name=t,this.type=e,this.location=n,this.state=a}get isPageLoad(){return"initial"===this.type}get isBackForward(){return"popState"===this.type}get isLinkClick(){return"linkClick"===this.type}get isNavigation(){return"navigate"===this.type}get isCancelable(){return"beforeChange"===this.name}cancel(){if("afterChange"===this.name)throw new Error("Cannot cancel afterChange event");this._canceled=!0}}class w extends g{constructor(t,e,n){super("beforeChange",t,e,n)}}class v extends g{constructor(t,e,n){super("afterChange",t,e,n)}}class P{stickyParams;_popStateListener;_linkNavListener;_listeners=[];constructor(){}addListener(t){this._listeners.push(t)}fireLocationChange(t){for(const e of this._listeners)e(t)}firePageLoad(){this.fireLocationChange(new v("initial",new URL(window.location.href)))}addStickyParams(t){return this.stickyParams?new p(t).add(this.stickyParams).toString():t}navigate(t,e={}){if(e.basePath){let n=e.basePath;n.startsWith("/")||(n="/"+n),t=l(n,t)}t=this.addStickyParams(t),this._navigate(new URL(t,window.location.href),"navigate",e)}_navigate(t,e,n){const a=new w(e,t,n.state);if(this.fireLocationChange(a),a._canceled)return;const r=window.history.state,i={title:document.title,href:window.location.pathname+window.location.search+window.location.hash};let s=[];!n.replace&&r?.historyChain&&(s=[...r.historyChain]),n.replace||(s.push(i),s.length>10&&(s=s.slice(-10)));const o={from:window.location.href,historyChain:s,data:n.state||void 0};window.history[n.replace?"replaceState":"pushState"](o,"",t.href),this.fireLocationChange(new v(e,t,n.state))}start(){if("undefined"==typeof window)return;const t=t=>{let e=t.state?"popState":"linkClick";const n=new URL(window.location.href);let a;t.state?(e="popState",a=t.state.data):e="linkClick",this.fireLocationChange(new v(e,n,a))};this._popStateListener=t,this._linkNavListener=t=>{const e=function(t){if(t&&"a"===t.tagName.toLowerCase()){const e=t?.href.trim();if("string"==typeof e&&e.length>0)return new URL(e)}return null}(t.target);if(e&&e.origin===window.location.origin){t.preventDefault();const n=new URL(this.addStickyParams(e.href)),a=t[f]||t.target[f];a&&(n.pathname=l(a,n.pathname)),this._navigate(n,"linkClick",{})}},window.addEventListener("popstate",t),document.body.addEventListener("click",this._linkNavListener)}stop(){this._popStateListener&&window.removeEventListener("popstate",this._popStateListener),this._linkNavListener&&document.body.removeEventListener("click",this._linkNavListener)}}function b({basePath:e,children:r}){const i=n(null);return a((()=>{if(i.current){const t=i.current,n=t=>{"a"===t.target.tagName.toLowerCase()&&(t[f]=e)};return t.addEventListener("click",n),()=>{t.removeEventListener("click",n)}}}),[i.current]),t("div",{ref:i,className:"h-full w-full",children:r})}class L{tree=new C;loadMapping(t){for(const[e,n]of Object.entries(t))this.addSegments(u(e),n)}addPath(t,e){this.addSegments(u(t),e)}addSegments(t,e){let n=this.tree;for(let a=0,r=t.length;a<r;a++){const i=t[a];if(":"===i[0]){let e=n.wildcard;if(e){if(!(e instanceof S))throw new Error(`Failed to index path segments: ${t.join("/")}. A wildcard ":" segment will overwrite an existing wildcard segment at path: ${"/"+t.slice(0,a).join("/")}`)}else e=new S(i),n.wildcard=e;n=e}else{if("*"===i){if(n.wildcard)throw new Error(`Failed to index path segments: ${t.join("/")}. A wildcard "*" segment already exists at path: ${"/"+t.slice(0,a).join("/")}`);if(n.wildcard=new _(i,e),a<r-1)throw new Error(`Failed to index path segments: ${t.join("/")}. A wildcard segment must be the last segment`);return}{let t=n.children[i];t||(t=new k(i),n.children[i]=t),n=t}}}if(void 0!==n.value)throw new Error(`Failed to index path segments: ${t.join("/")}. A value already exists at path: ${"/"+t.join("/")}`);n.value=e}match(t){const e=d(t);if(0===e.length)return null;const n={};let a,r,i=this.tree;for(const t of e){const e=i.match(t,n);if(!e)return null;i=e}if(!i.value){if(i instanceof y&&i.wildcard instanceof _&&(i=i.wildcard.match("",n),!i.value))throw new Error("Wildcard segment node `*` must have a value");if(!i.value)return null}return n._&&n._.length>0?(a=e.slice(0,-n._.length),r=n._):a=e,{params:n,matchedSegments:a,remainingSegments:r,value:i.value}}}class y{name;value;children={};wildcard;constructor(t,e){this.name=t,this.value=e}match(t,e){let n=this.children[t];if(n)return n;if(this.wildcard){if(this.wildcard instanceof _)return this.wildcard.match(t,e);if(this.wildcard instanceof S)return e[this.wildcard.paramName]=t,this.wildcard;throw new Error("Unknown wildcard segment node type: "+this.wildcard.constructor.name)}return null}}class C extends y{constructor(){super("#root")}}class k extends y{constructor(t,e){super(t,e)}}class S extends y{paramName;constructor(t,e){super(t,e),this.paramName=t.substring(1)}}class _{name;value;constructor(t,e){this.name=t,this.value=e}match(t,e){return e._?t&&e._.push(t):e._=t?[t]:[],this}}class x{index;matcher=new L;constructor(t,e){this.index=e;for(const e of t)this.matcher.addPath(e.path,e)}match(t){const e=c(t)&&this.index;return this.matcher.match(e?this.index:t)}}class R extends x{prompt;observer;navigator=new P;constructor(t,e){super(t),this.navigator.addListener((t=>{if((!(t.isCancelable&&this.prompt&&this.prompt.when)||window.confirm(this.prompt.message))&&(this.observer&&this.observer(t),"afterChange"===t.name)){const n=this.match(t.location.pathname);n&&n.value?e({...n,state:t.state}):e(null)}}))}getTopRouter(){return this}setStickyParams(t){this.navigator.stickyParams=null!=t?t:void 0}withObserver(t){return this.observer=t,this}start(){this.navigator.start(),this.navigator.firePageLoad()}stop(){this.navigator.stop()}navigate(t,e){this.navigator.navigate(t,e)}}class E extends x{parent;basePath;constructor(t,e,n){super(n),this.parent=t,this.basePath=e}getTopRouter(){return this.parent instanceof R?this.parent:this.parent.getTopRouter()}navigate(t,e){let n;if(e?.isBasePathNested??!0){const t=e?.basePath;n=t?l(this.basePath,t):this.basePath}else n=e?.basePath??this.basePath;this.parent.navigate(t,{...e,basePath:n})}}const j=r(void 0);function N(){const t=i(j);if(!t)throw new Error("useRouter must be used within a RouterProvider");return t}function $(){const{navigate:t}=N();return t}function U(t){const{params:e}=N();return t?e[t]:e}function W(){const{location:t}=N();return t}function A(t){const{router:e}=N();a((()=>(e.getTopRouter().prompt=t,()=>{e.getTopRouter().prompt=void 0})),[]),a((()=>{if(t.when){const e=t.when,n=function(t){e&&(t.preventDefault(),t.returnValue="")};return window.addEventListener("beforeunload",n),()=>{window.removeEventListener("beforeunload",n)}}}),[t.when])}function O({children:e,onClick:n}){const a=$();return t("span",{onClick:t=>{const e=t.target.closest("a");e&&e.href&&(t.stopPropagation(),t.preventDefault(),a(e.href,{replace:!0}),n?.(t))},children:e})}function T({children:e,href:n,className:a,topLevelNav:r,clearBreadcrumbs:i=!1}){const{router:s}=N();return t("a",{href:n,className:a,onClick:t=>{t.stopPropagation(),t.preventDefault();(r?s.getTopRouter():s).navigate(n,{replace:i})},children:e})}function z({spinner:e}){const n=N(),a=n.route;if(a.Component){const e=a.Component;return t(e,{...n.params})}if(a.LazyComponent)return t(F,{route:a,spinner:e});throw new Error(`Invalid route for ${a.path}. Either Component or LazyCOmponent must be specified.`)}function F({route:e,spinner:n}){const[r,i]=s(null);return a((()=>{e.LazyComponent().then((t=>{if(!t.default)throw new Error(`Lazy module for ${e.path} does not have a default export`);i((()=>t.default))}))}),[e]),r?t(r,{}):n||null}function B({basePath:e,fixLinks:n=!1,children:a}){const r=N(),i=n?e=>t(b,{basePath:r.matchedRoutePath,children:e}):t=>t;return t(j.Provider,{value:{...r,navigate:(t,n)=>{const a=n?.basePath?l(e,n.basePath):e;return r.navigate(t,{...n,basePath:a})}},children:i(a||t(z,{}))})}function D(){const t=N();return e("div",{children:["Route not found for path ",t.matchedRoutePath]})}function I(){return{params:{},matchedSegments:[],state:null,value:{path:"virtual:404",Component:()=>t(D,{})}}}function H({routes:e,index:n,children:r,fixLinks:i=!1}){const h=N(),[c,l]=s(void 0),u=o((()=>{if("undefined"==typeof window)return null;const t=h.matchedRoutePath,a=new E(h.router,t,e);return a.index=n,a}),[]);a((()=>{if(u){if(h.matchedRoutePath!==u.basePath)return;const t=u.match(h.remainingPath||"/")||I();l(t)}}),[u,h.remainingPath]);const d=i?e=>t(b,{basePath:h.matchedRoutePath,children:e}):t=>t;return c&&t(j.Provider,{value:{...h,router:u,route:c.value,params:c.params,matchedRoutePath:"/"+c.matchedSegments.join("/"),remainingPath:c.remainingSegments?"/"+c.remainingSegments.join("/"):void 0,navigate:(t,e)=>u.navigate(t,e)},children:d(r||t(z,{}))})}function M({routes:e,index:n,onChange:a,children:r}){const[i,c]=s(void 0),l=o((()=>{if("undefined"==typeof window)return null;const t=new R(e,(e=>{null===e&&(e=I()),c({location:window.location,route:e.value,params:e.params,state:e.state,router:t,matchedRoutePath:"/"+e.matchedSegments.join("/"),remainingPath:e.remainingSegments?"/"+e.remainingSegments.join("/"):void 0,navigate:(e,n)=>t.navigate(e,n)})})).withObserver(a);return t.index=n,t}),[]);return h((()=>(l&&l.start(),()=>{l&&l.stop()})),[]),i&&t(j.Provider,{value:i,children:r||t(z,{})})}export{v as AfterLocationChangeEvent,f as BASE_PATH,x as BaseRouter,w as BeforeLocationChangeEvent,b as FixLinks,P as HistoryNavigator,g as LocationChangeEvent,O as Nav,T as NavLink,B as NestedNavigationContext,E as NestedRouter,H as NestedRouterProvider,m as Path,L as PathMatcher,j as ReactRouterContext,z as RouteComponent,R as Router,M as RouterProvider,W as useLocation,$ as useNavigate,A as useNavigationPrompt,U as useParams,N as useRouterContext};
1
+ import{jsx as t,jsxs as e}from"react/jsx-runtime";import{useRef as n,useEffect as a,createContext as r,useContext as i,useState as s,useMemo as o}from"react";import{useSafeLayoutEffect as h}from"@vertesia/ui/core";function c(t){return"/"===t||""===t}function l(t,e){return e=t.endsWith("/")&&e.startsWith("/")?t+e.substring(1):t.endsWith("/")||e.startsWith("/")?t+e:t+"/"+e}function d(t){if(""===t)return[];if("/"===t)return[""];let e=0,n=t.length;return t.startsWith("./")?e=2:t.startsWith("/")&&(e=1),t.endsWith("/")&&(n=t.length-1),(e>0||n<t.length?t.substring(e,n):t).split("/")}function u(t){if("string"==typeof t)return d(t);if(Array.isArray(t))return t;throw new Error(`Unsupported path object: ${t}`)}var p=Object.freeze({__proto__:null,getPathSegments:d,isRootPath:c,joinPath:l,toSegments:u});class m{path;params;hash;constructor(t){let e=t.lastIndexOf("#");e>-1?(this.hash=t.substring(e),t=t.substring(0,e)):this.hash="",e=t.indexOf("?"),e>-1?(this.path=t.substring(0,e),this.params=new URLSearchParams(t.substring(e+1))):(this.path=t,this.params=new URLSearchParams)}add(t){for(const[e,n]of Object.entries(t))this.params.set(e,n);return this}toString(){return this.path+"?"+this.params.toString()+this.hash}}const f=Symbol("BASE_PATH");class w{name;type;location;state;_canceled=!1;constructor(t,e,n,a){this.name=t,this.type=e,this.location=n,this.state=a}get isPageLoad(){return"initial"===this.type}get isBackForward(){return"popState"===this.type}get isLinkClick(){return"linkClick"===this.type}get isNavigation(){return"navigate"===this.type}get isCancelable(){return"beforeChange"===this.name}cancel(){if("afterChange"===this.name)throw new Error("Cannot cancel afterChange event");this._canceled=!0}}class g extends w{constructor(t,e,n){super("beforeChange",t,e,n)}}class v extends w{constructor(t,e,n){super("afterChange",t,e,n)}}class P{stickyParams;_popStateListener;_linkNavListener;_listeners=[];constructor(){}addListener(t){this._listeners.push(t)}fireLocationChange(t){for(const e of this._listeners)e(t)}firePageLoad(){this.fireLocationChange(new v("initial",new URL(window.location.href)))}addStickyParams(t){return this.stickyParams?new m(t).add(this.stickyParams).toString():t}navigate(t,e={}){if(e.stepsBack&&e.stepsBack>0)this.stepBack(e.stepsBack,e);else{if(e.basePath){let n=e.basePath;n.startsWith("/")||(n="/"+n),t=l(n,t)}t=this.addStickyParams(t),this._navigate(new URL(t,window.location.href),"navigate",e)}}stepBack(t,e={}){const n=window.history.state.historyChain||[],a=n.length>=t?new URL(n[n.length-t].href,window.location.href):new URL(window.location.origin,window.location.href);this._navigate(a,"popState",e);const r={from:window.location.href,historyChain:n.slice(0,-t),data:e.state||void 0,title:e.title||document.title};window.history.replaceState(r,"",a.href),this.fireLocationChange(new v("popState",a,e.state))}_navigate(t,e,n){const a=new g(e,t,n.state);if(this.fireLocationChange(a),a._canceled)return;const r=window.history.state,i={title:n.title||document.title,href:window.location.pathname+window.location.search+window.location.hash};let s=[];!n.replace&&r?.historyChain&&(s=[...r.historyChain]),n.replace||(s.push(i),s.length>10&&(s=s.slice(-10)));const o={from:window.location.href,historyChain:s,data:n.state||void 0,title:n.title||document.title};window.history[n.replace?"replaceState":"pushState"](o,"",t.href),this.fireLocationChange(new v(e,t,n.state))}start(){if("undefined"==typeof window)return;const t=t=>{let e=t.state?"popState":"linkClick";const n=new URL(window.location.href);let a;t.state?(e="popState",a=t.state.data):e="linkClick",this.fireLocationChange(new v(e,n,a))};this._popStateListener=t,this._linkNavListener=t=>{const e=function(t){if(t&&"a"===t.tagName.toLowerCase()){const e=t?.href.trim();if("string"==typeof e&&e.length>0)return new URL(e)}return null}(t.target);if(e&&e.origin===window.location.origin){t.preventDefault();const n=new URL(this.addStickyParams(e.href)),a=t[f]||t.target[f];a&&(n.pathname=l(a,n.pathname)),this._navigate(n,"linkClick",{})}},window.addEventListener("popstate",t),document.body.addEventListener("click",this._linkNavListener)}stop(){this._popStateListener&&window.removeEventListener("popstate",this._popStateListener),this._linkNavListener&&document.body.removeEventListener("click",this._linkNavListener)}}function b({basePath:e,children:r}){const i=n(null);return a((()=>{if(i.current){const t=i.current,n=t=>{"a"===t.target.tagName.toLowerCase()&&(t[f]=e)};return t.addEventListener("click",n),()=>{t.removeEventListener("click",n)}}}),[i.current]),t("div",{ref:i,className:"h-full w-full",children:r})}class L{tree=new k;loadMapping(t){for(const[e,n]of Object.entries(t))this.addSegments(d(e),n)}addPath(t,e){this.addSegments(d(t),e)}addSegments(t,e){let n=this.tree;for(let a=0,r=t.length;a<r;a++){const i=t[a];if(":"===i[0]){let e=n.wildcard;if(e){if(!(e instanceof S))throw new Error(`Failed to index path segments: ${t.join("/")}. A wildcard ":" segment will overwrite an existing wildcard segment at path: ${"/"+t.slice(0,a).join("/")}`)}else e=new S(i),n.wildcard=e;n=e}else{if("*"===i){if(n.wildcard)throw new Error(`Failed to index path segments: ${t.join("/")}. A wildcard "*" segment already exists at path: ${"/"+t.slice(0,a).join("/")}`);if(n.wildcard=new _(i,e),a<r-1)throw new Error(`Failed to index path segments: ${t.join("/")}. A wildcard segment must be the last segment`);return}{let t=n.children[i];t||(t=new C(i),n.children[i]=t),n=t}}}if(void 0!==n.value)throw new Error(`Failed to index path segments: ${t.join("/")}. A value already exists at path: ${"/"+t.join("/")}`);n.value=e}match(t){const e=u(t);if(0===e.length)return null;const n={};let a,r,i=this.tree;for(const t of e){const e=i.match(t,n);if(!e)return null;i=e}if(!i.value){if(i instanceof y&&i.wildcard instanceof _&&(i=i.wildcard.match("",n),!i.value))throw new Error("Wildcard segment node `*` must have a value");if(!i.value)return null}return n._&&n._.length>0?(a=e.slice(0,-n._.length),r=n._):a=e,{params:n,matchedSegments:a,remainingSegments:r,value:i.value}}}class y{name;value;children={};wildcard;constructor(t,e){this.name=t,this.value=e}match(t,e){let n=this.children[t];if(n)return n;if(this.wildcard){if(this.wildcard instanceof _)return this.wildcard.match(t,e);if(this.wildcard instanceof S)return e[this.wildcard.paramName]=t,this.wildcard;throw new Error("Unknown wildcard segment node type: "+this.wildcard.constructor.name)}return null}}class k extends y{constructor(){super("#root")}}class C extends y{constructor(t,e){super(t,e)}}class S extends y{paramName;constructor(t,e){super(t,e),this.paramName=t.substring(1)}}class _{name;value;constructor(t,e){this.name=t,this.value=e}match(t,e){return e._?t&&e._.push(t):e._=t?[t]:[],this}}class x{index;matcher=new L;constructor(t,e){this.index=e;for(const e of t)this.matcher.addPath(e.path,e)}match(t){const e=c(t)&&this.index;return this.matcher.match(e?this.index:t)}}class R extends x{prompt;observer;navigator=new P;constructor(t,e){super(t),this.navigator.addListener((t=>{if((!(t.isCancelable&&this.prompt&&this.prompt.when)||window.confirm(this.prompt.message))&&(this.observer&&this.observer(t),"afterChange"===t.name)){const n=this.match(t.location.pathname);n&&n.value?e({...n,state:t.state}):e(null)}}))}getTopRouter(){return this}setStickyParams(t){this.navigator.stickyParams=null!=t?t:void 0}withObserver(t){return this.observer=t,this}start(){this.navigator.start(),this.navigator.firePageLoad()}stop(){this.navigator.stop()}navigate(t,e){this.navigator.navigate(t,e)}}class E extends x{parent;basePath;constructor(t,e,n){super(n),this.parent=t,this.basePath=e}getTopRouter(){return this.parent instanceof R?this.parent:this.parent.getTopRouter()}navigate(t,e){let n;if(e?.isBasePathNested??!0){const t=e?.basePath;n=t?l(this.basePath,t):this.basePath}else n=e?.basePath??this.basePath;this.parent.navigate(t,{...e,basePath:n})}}const j=r(void 0);function N(){const t=i(j);if(!t)throw new Error("useRouter must be used within a RouterProvider");return t}function U(){const{navigate:t}=N();return t}function $(t){const{params:e}=N();return t?e[t]:e}function B(){const{location:t}=N();return t}function W(t){const{router:e}=N();a((()=>(e.getTopRouter().prompt=t,()=>{e.getTopRouter().prompt=void 0})),[]),a((()=>{if(t.when){const e=t.when,n=function(t){e&&(t.preventDefault(),t.returnValue="")};return window.addEventListener("beforeunload",n),()=>{window.removeEventListener("beforeunload",n)}}}),[t.when])}function A({children:e,onClick:n}){const a=U();return t("span",{onClick:t=>{const e=t.target.closest("a");e&&e.href&&(t.stopPropagation(),t.preventDefault(),a(e.href,{replace:!0}),n?.(t))},children:e})}function O({children:e,href:n,className:a,topLevelNav:r,clearBreadcrumbs:i=!1}){const{router:s}=N();return t("a",{href:n,className:a,onClick:t=>{t.stopPropagation(),t.preventDefault();(r?s.getTopRouter():s).navigate(n,{replace:i})},children:e})}function T({spinner:e}){const n=N(),a=n.route;if(a.Component){const e=a.Component;return t(e,{...n.params})}if(a.LazyComponent)return t(z,{route:a,spinner:e});throw new Error(`Invalid route for ${a.path}. Either Component or LazyCOmponent must be specified.`)}function z({route:e,spinner:n}){const[r,i]=s(null);return a((()=>{e.LazyComponent().then((t=>{if(!t.default)throw new Error(`Lazy module for ${e.path} does not have a default export`);i((()=>t.default))}))}),[e]),r?t(r,{}):n||null}function F({basePath:e,fixLinks:n=!1,children:a}){const r=N(),i=n?e=>t(b,{basePath:r.matchedRoutePath,children:e}):t=>t;return t(j.Provider,{value:{...r,navigate:(t,n)=>{const a=n?.basePath?l(e,n.basePath):e;return r.navigate(t,{...n,basePath:a})}},children:i(a||t(T,{}))})}function D(){const t=N();return e("div",{children:["Route not found for path ",t.matchedRoutePath]})}function I(){return{params:{},matchedSegments:[],state:null,value:{path:"virtual:404",Component:()=>t(D,{})}}}function H({routes:e,index:n,children:r,fixLinks:i=!1}){const h=N(),[c,l]=s(void 0),d=o((()=>{if("undefined"==typeof window)return null;const t=h.matchedRoutePath,a=new E(h.router,t,e);return a.index=n,a}),[]);a((()=>{if(d){if(h.matchedRoutePath!==d.basePath)return;const t=d.match(h.remainingPath||"/")||I();l(t)}}),[d,h.remainingPath]);const u=i?e=>t(b,{basePath:h.matchedRoutePath,children:e}):t=>t;return c&&t(j.Provider,{value:{...h,router:d,route:c.value,params:c.params,matchedRoutePath:"/"+c.matchedSegments.join("/"),remainingPath:c.remainingSegments?"/"+c.remainingSegments.join("/"):void 0,navigate:(t,e)=>d.navigate(t,e)},children:u(r||t(T,{}))})}function M({routes:e,index:n,onChange:a,children:r}){const[i,c]=s(void 0),l=o((()=>{if("undefined"==typeof window)return null;const t=new R(e,(e=>{null===e&&(e=I()),c({location:window.location,route:e.value,params:e.params,state:e.state,router:t,matchedRoutePath:"/"+e.matchedSegments.join("/"),remainingPath:e.remainingSegments?"/"+e.remainingSegments.join("/"):void 0,navigate:(e,n)=>t.navigate(e,n)})})).withObserver(a);return t.index=n,t}),[]);return h((()=>(l&&l.start(),()=>{l&&l.stop()})),[]),i&&t(j.Provider,{value:i,children:r||t(T,{})})}export{v as AfterLocationChangeEvent,f as BASE_PATH,x as BaseRouter,g as BeforeLocationChangeEvent,b as FixLinks,P as HistoryNavigator,w as LocationChangeEvent,A as Nav,O as NavLink,F as NestedNavigationContext,E as NestedRouter,H as NestedRouterProvider,p as Path,L as PathMatcher,j as ReactRouterContext,T as RouteComponent,R as Router,M as RouterProvider,B as useLocation,U as useNavigate,W as useNavigationPrompt,$ as useParams,N as useRouterContext};
2
2
  //# sourceMappingURL=vertesia-ui-router.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vertesia-ui-router.js","sources":["esm/router/path.js","esm/router/PathWithParams.js","esm/router/HistoryNavigator.js","esm/router/FixLinks.js","esm/router/PathMatcher.js","esm/router/Router.js","esm/router/Nav.js","esm/router/RouteComponent.js","esm/router/NestedNavigationContext.js","esm/router/Route404.js","esm/router/NestedRouterProvider.js","esm/router/RouterProvider.js"],"sourcesContent":["export function isRootPath(path) {\n return path === '/' || path === '';\n}\nexport function joinPath(path1, path2) {\n if (path1.endsWith('/') && path2.startsWith('/')) {\n path2 = path1 + path2.substring(1);\n }\n else if (path1.endsWith('/')) {\n path2 = path1 + path2;\n }\n else if (path2.startsWith('/')) {\n path2 = path1 + path2;\n }\n else {\n path2 = path1 + '/' + path2;\n }\n return path2;\n}\nexport function getPathSegments(path) {\n if (path === '') {\n return [];\n }\n if (path === '/') {\n return [''];\n }\n let s = 0, e = path.length;\n if (path.startsWith('./')) {\n s = 2;\n }\n else if (path.startsWith('/')) {\n s = 1;\n }\n if (path.endsWith('/')) {\n e = path.length - 1;\n }\n return (s > 0 || e < path.length ? path.substring(s, e) : path).split('/');\n}\nexport function toSegments(path) {\n if (typeof path === 'string') {\n return getPathSegments(path);\n }\n else if (Array.isArray(path)) {\n return path;\n }\n else {\n throw new Error(`Unsupported path object: ${path}`);\n }\n}\n// export class Path {\n// static parse(path: string, abs = false) {\n// if (abs !== undefined) {\n// abs = path.startsWith('/');\n// }\n// return new Path(getPathSegments(path), abs);\n// }\n// constructor(public segments: string[], public isAbsolute = false) {\n// }\n// getParameters() {\n// const out = [];\n// for (const segment of this.segments) {\n// if (segment[0] === ':') {\n// out.push(segment.substring(1));\n// }\n// }\n// if (this.segments[this.segments.length - 1] === '*') {\n// out.push('_');\n// }\n// return out;\n// }\n// resolveParameters(path: string) {\n// const params: PathMatchParams = {};\n// const resolvedSegments = getPathSegments(path);\n// if (resolvedSegments.length < this.segments.length) {\n// return null;\n// }\n// const segments = this.segments;\n// for (let i = 0, l = segments.length; i < l; i++) {\n// const seg = segments[i];\n// if (seg[0] === ':') {\n// params[seg.substring(1)] = resolvedSegments[i];\n// }\n// }\n// if (resolvedSegments.length - this.segments.length) {\n// params._ = resolvedSegments.slice(this.segments.length);\n// }\n// return params;\n// }\n// match(path: string | string[] | Path) {\n// const segments = toSegments(path);\n// if (segments.length < this.segments.length) {\n// return false;\n// }\n// let params: PathMatchParams | undefined;\n// const mySegments = this.segments;\n// for (let i = 0, l = mySegments.length; i < l; i++) {\n// const segment = mySegments[i];\n// if (segment === ':') {\n// if (!params) params = {};\n// params[segment.substring(1)] = segment;\n// } else if (segment !== segments[i]) {\n// if (i === l - 1 && segment === '*') {\n// if (!params) params = {};\n// params._ = segments.slice(i);\n// return params;\n// }\n// return false;\n// }\n// }\n// return params ? params : false;\n// }\n// join(path: Path | string | string[]) {\n// const segments = toSegments(path);\n// return new Path(this.segments.concat(segments), this.isAbsolute);\n// }\n// getRelativePath(path: Path | string | string[], asAbsolute: boolean = false) {\n// const segments = toSegments(path);\n// const extraSegmentsCount = segments.length - this.segments.length;\n// if (extraSegmentsCount <= 0) {\n// return null;\n// }\n// return new Path(segments.slice(this.segments.length), asAbsolute);\n// }\n// prependSegments(segments: string[]) {\n// this.segments = segments.concat(this.segments);\n// }\n// appendSegments(segments: string[]) {\n// this.segments = this.segments.concat(segments);\n// }\n// toAbsolutePath() {\n// return '/' + this.segments.join('/');\n// }\n// toRelativePath() {\n// return this.segments.join('/');\n// }\n// toString() {\n// const path = this.segments.join('/');\n// return this.isAbsolute ? '/' + path : path;\n// }\n// }\n//# sourceMappingURL=path.js.map","export class PathWithParams {\n path;\n params;\n hash;\n constructor(path) {\n let i = path.lastIndexOf('#');\n if (i > -1) {\n this.hash = path.substring(i);\n path = path.substring(0, i);\n }\n else {\n this.hash = '';\n }\n i = path.indexOf('?');\n if (i > -1) {\n this.path = path.substring(0, i);\n this.params = new URLSearchParams(path.substring(i + 1));\n }\n else {\n this.path = path;\n this.params = new URLSearchParams();\n }\n }\n add(params) {\n for (const [key, value] of Object.entries(params)) {\n this.params.set(key, value);\n }\n return this;\n }\n toString() {\n return this.path + '?' + this.params.toString() + this.hash;\n }\n}\n//# sourceMappingURL=PathWithParams.js.map","import { joinPath } from \"./path\";\nimport { PathWithParams } from \"./PathWithParams\";\nconst BASE_PATH = Symbol('BASE_PATH');\nexport { BASE_PATH };\nexport class LocationChangeEvent {\n name;\n type;\n location;\n state;\n _canceled = false;\n constructor(name, type, location, state) {\n this.name = name;\n this.type = type;\n this.location = location;\n this.state = state;\n }\n get isPageLoad() {\n return this.type === 'initial';\n }\n get isBackForward() {\n return this.type === 'popState';\n }\n get isLinkClick() {\n return this.type === 'linkClick';\n }\n get isNavigation() {\n return this.type === 'navigate';\n }\n get isCancelable() {\n return this.name === 'beforeChange';\n }\n cancel() {\n if (this.name === 'afterChange') {\n throw new Error('Cannot cancel afterChange event');\n }\n this._canceled = true;\n }\n}\nexport class BeforeLocationChangeEvent extends LocationChangeEvent {\n constructor(type, location, state) {\n super('beforeChange', type, location, state);\n }\n}\nexport class AfterLocationChangeEvent extends LocationChangeEvent {\n constructor(type, location, state) {\n super('afterChange', type, location, state);\n }\n}\nfunction getElementHrefAsUrl(elem) {\n if (elem && elem.tagName.toLowerCase() === 'a') {\n const href = elem?.href.trim();\n if (typeof href === 'string' && href.length > 0) {\n return new URL(href);\n }\n }\n return null;\n}\nexport class HistoryNavigator {\n // params to preserve in the query string when navigating\n stickyParams;\n _popStateListener;\n _linkNavListener;\n _listeners = [];\n constructor() {\n }\n addListener(listener) {\n this._listeners.push(listener);\n }\n fireLocationChange(event) {\n for (const listener of this._listeners) {\n listener(event);\n }\n }\n /**\n * Should be called when the page is first loaded.\n * It will fire a location change event with type `initial` and the current window.location as the location\n */\n firePageLoad() {\n this.fireLocationChange(new AfterLocationChangeEvent('initial', new URL(window.location.href)));\n }\n addStickyParams(path) {\n if (this.stickyParams) {\n return new PathWithParams(path).add(this.stickyParams).toString();\n }\n return path;\n }\n navigate(to, options = {}) {\n if (options.basePath) {\n let basePath = options.basePath;\n if (!basePath.startsWith('/')) {\n basePath = '/' + basePath;\n }\n to = joinPath(basePath, to);\n }\n to = this.addStickyParams(to);\n this._navigate(new URL(to, window.location.href), 'navigate', options);\n }\n _navigate(to, type, options) {\n const beforeEvent = new BeforeLocationChangeEvent(type, to, options.state);\n this.fireLocationChange(beforeEvent);\n if (beforeEvent._canceled) {\n return;\n }\n // Build navigation chain by preserving previous history\n const currentState = window.history.state;\n const currentTitle = document.title;\n // Create new history chain entry\n const newChainEntry = {\n title: currentTitle,\n href: window.location.pathname + window.location.search + window.location.hash\n };\n // Build the history chain - clear if using replace\n let historyChain = [];\n if (!options.replace && currentState?.historyChain) {\n historyChain = [...currentState.historyChain];\n }\n // Only add to chain if not replacing\n if (!options.replace) {\n historyChain.push(newChainEntry);\n // Limit chain length to prevent memory issues (keep last 10 entries)\n if (historyChain.length > 10) {\n historyChain = historyChain.slice(-10);\n }\n }\n const stateToStore = {\n from: window.location.href,\n historyChain: historyChain,\n data: options.state || undefined\n };\n window.history[options.replace ? 'replaceState' : 'pushState'](stateToStore, '', to.href);\n this.fireLocationChange(new AfterLocationChangeEvent(type, to, options.state));\n }\n start() {\n if (typeof window === \"undefined\") {\n return;\n }\n const _popStateListener = (ev) => {\n let type = ev.state ? 'popState' : 'linkClick';\n const to = new URL(window.location.href);\n let state = undefined;\n if (ev.state) {\n type = 'popState';\n state = ev.state.data;\n }\n else {\n type = 'linkClick';\n }\n this.fireLocationChange(new AfterLocationChangeEvent(type, to, state));\n };\n const _linkNavListener = (ev) => {\n const url = getElementHrefAsUrl(ev.target);\n if (url && url.origin === window.location.origin) {\n ev.preventDefault();\n const to = new URL(this.addStickyParams(url.href));\n const basePath = ev[BASE_PATH] || ev.target[BASE_PATH];\n if (basePath) {\n to.pathname = joinPath(basePath, to.pathname);\n }\n this._navigate(to, 'linkClick', {});\n }\n };\n this._popStateListener = _popStateListener;\n this._linkNavListener = _linkNavListener;\n window.addEventListener('popstate', _popStateListener);\n document.body.addEventListener('click', this._linkNavListener);\n }\n stop() {\n this._popStateListener && window.removeEventListener('popstate', this._popStateListener);\n this._linkNavListener && document.body.removeEventListener('click', this._linkNavListener);\n }\n}\n//# sourceMappingURL=HistoryNavigator.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect, useRef } from \"react\";\nimport { BASE_PATH } from \"./HistoryNavigator\";\nexport function FixLinks({ basePath, children }) {\n const ref = useRef(null);\n useEffect(() => {\n if (ref.current) {\n const divElem = ref.current;\n const listener = (ev) => {\n const elem = ev.target;\n if (elem.tagName.toLowerCase() === 'a') {\n ev[BASE_PATH] = basePath;\n }\n };\n divElem.addEventListener('click', listener);\n return () => {\n divElem.removeEventListener('click', listener);\n };\n }\n }, [ref.current]);\n return (_jsx(\"div\", { ref: ref, className: \"h-full w-full\", children: children }));\n}\n//# sourceMappingURL=FixLinks.js.map","import { getPathSegments, toSegments } from \"./path\";\n/**\n * Path matcher which support :param and *wildcard segments.\n * The wildcard segment is only supported as the last segment\n */\nexport class PathMatcher {\n tree = new RootSegmentNode();\n loadMapping(mapping) {\n for (const [key, value] of Object.entries(mapping)) {\n this.addSegments(getPathSegments(key), value);\n }\n }\n addPath(path, value) {\n this.addSegments(getPathSegments(path), value);\n }\n addSegments(segments, value) {\n let node = this.tree;\n for (let i = 0, l = segments.length; i < l; i++) {\n const segment = segments[i];\n if (segment[0] === ':') {\n let childNode = node.wildcard;\n if (!childNode) {\n childNode = new VariableSegmentNode(segment);\n node.wildcard = childNode;\n }\n else if (!(childNode instanceof VariableSegmentNode)) {\n throw new Error(`Failed to index path segments: ${segments.join('/')}. A wildcard \":\" segment will overwrite an existing wildcard segment at path: ${'/' + segments.slice(0, i).join(\"/\")}`);\n }\n node = childNode;\n }\n else if (segment === '*') {\n if (node.wildcard) {\n throw new Error(`Failed to index path segments: ${segments.join('/')}. A wildcard \"*\" segment already exists at path: ${'/' + segments.slice(0, i).join(\"/\")}`);\n }\n node.wildcard = new WildcardSegmentNode(segment, value);\n if (i < l - 1) {\n throw new Error(`Failed to index path segments: ${segments.join('/')}. A wildcard segment must be the last segment`);\n }\n return;\n }\n else {\n let childNode = node.children[segment];\n if (!childNode) {\n childNode = new LiteralSegmentNode(segment);\n node.children[segment] = childNode;\n } // else // a literal segment already exists\n node = childNode;\n }\n }\n if (node.value !== undefined) {\n throw new Error(`Failed to index path segments: ${segments.join('/')}. A value already exists at path: ${'/' + segments.join(\"/\")}`);\n }\n node.value = value;\n }\n match(path) {\n const segments = toSegments(path);\n if (segments.length === 0) {\n return null;\n }\n const params = {};\n let node = this.tree;\n for (const segment of segments) {\n const match = node.match(segment, params);\n if (match) {\n node = match;\n }\n else {\n return null;\n }\n }\n if (!node.value) { // not a leaf node (partial match)\n if (node instanceof ParentSegmentNode) {\n if (node.wildcard instanceof WildcardSegmentNode) {\n node = node.wildcard.match('', params);\n if (!node.value) {\n throw new Error(\"Wildcard segment node `*` must have a value\");\n }\n }\n }\n if (!node.value)\n return null; // not a leaf node, neither a trailing wildcard (partial match)\n }\n let matchedSegments, remainingSegments;\n if (params._ && params._.length > 0) {\n matchedSegments = segments.slice(0, -params._.length);\n remainingSegments = params._;\n }\n else {\n matchedSegments = segments;\n }\n return { params, matchedSegments, remainingSegments, value: node.value };\n }\n}\nclass ParentSegmentNode {\n name;\n value;\n children = {};\n wildcard;\n constructor(name, value) {\n this.name = name;\n this.value = value;\n }\n match(segment, params) {\n let node = this.children[segment];\n if (node) {\n return node;\n }\n else if (this.wildcard) {\n if (this.wildcard instanceof WildcardSegmentNode) {\n return this.wildcard.match(segment, params);\n }\n else if (this.wildcard instanceof VariableSegmentNode) {\n params[this.wildcard.paramName] = segment;\n return this.wildcard;\n }\n else {\n throw new Error(\"Unknown wildcard segment node type: \" + this.wildcard.constructor.name);\n }\n }\n else {\n return null;\n }\n }\n}\nclass RootSegmentNode extends ParentSegmentNode {\n constructor() {\n super(\"#root\");\n }\n}\nclass LiteralSegmentNode extends ParentSegmentNode {\n constructor(name, value) {\n super(name, value);\n }\n}\nclass VariableSegmentNode extends ParentSegmentNode {\n paramName;\n constructor(name, value) {\n super(name, value);\n this.paramName = name.substring(1);\n }\n}\nclass WildcardSegmentNode {\n name;\n value;\n constructor(name, value) {\n this.name = name;\n this.value = value;\n }\n match(segment, params) {\n if (!params._) {\n params._ = segment ? [segment] : [];\n }\n else {\n segment && params._.push(segment);\n }\n return this;\n }\n}\n//# sourceMappingURL=PathMatcher.js.map","import { createContext, useContext, useEffect } from \"react\";\nimport { HistoryNavigator } from \"./HistoryNavigator\";\nimport { PathMatcher } from \"./PathMatcher\";\nimport { isRootPath, joinPath } from \"./path\";\nexport class BaseRouter {\n // the path to use when navigating to the root of the router\n index;\n matcher = new PathMatcher();\n constructor(routes, index) {\n this.index = index;\n for (const route of routes) {\n this.matcher.addPath(route.path, route);\n }\n }\n match(path) {\n const useIndex = isRootPath(path) && this.index;\n return this.matcher.match(useIndex ? this.index : path);\n }\n}\nexport class Router extends BaseRouter {\n prompt;\n observer;\n navigator = new HistoryNavigator();\n constructor(routes, updateState) {\n super(routes);\n this.navigator.addListener((event) => {\n if (event.isCancelable && this.prompt && !!this.prompt.when) {\n if (!window.confirm(this.prompt.message))\n return;\n }\n if (this.observer) {\n this.observer(event);\n }\n // only process afterChange events\n if (event.name === \"afterChange\") {\n const match = this.match(event.location.pathname);\n if (match && match.value) {\n updateState({\n ...match,\n state: event.state,\n });\n }\n else {\n updateState(null);\n }\n }\n });\n }\n getTopRouter() {\n return this;\n }\n /**\n * Subsequent navigations will preserve the given params in the query string.\n * Use null to clear the sticky params.\n * @param params\n */\n setStickyParams(params) {\n this.navigator.stickyParams = params != null ? params : undefined;\n }\n withObserver(observer) {\n this.observer = observer;\n return this;\n }\n start() {\n this.navigator.start();\n // initialize with the current location\n this.navigator.firePageLoad();\n }\n stop() {\n this.navigator.stop();\n }\n navigate(path, options) {\n this.navigator.navigate(path, options);\n }\n}\nexport class NestedRouter extends BaseRouter {\n parent;\n basePath;\n constructor(parent, basePath, routes) {\n super(routes);\n this.parent = parent;\n this.basePath = basePath;\n }\n getTopRouter() {\n if (this.parent instanceof Router) {\n return this.parent;\n }\n else {\n return this.parent.getTopRouter();\n }\n }\n navigate(path, options) {\n // base path is nested by default in a NestedRouter unless explicitly set to false by caller\n const isBasePathNested = options?.isBasePathNested ?? true;\n let basePath;\n if (isBasePathNested) {\n const childBasePath = options?.basePath;\n // e.g. \"/store\" + \"/objects/123\" => \"/store/objects/123\"\n basePath = childBasePath ? joinPath(this.basePath, childBasePath) : this.basePath;\n }\n else {\n // e.g. \"/store\" + \"/studio\" => \"/studio\"\n basePath = options?.basePath ?? this.basePath;\n }\n this.parent.navigate(path, {\n ...options,\n basePath,\n });\n }\n}\nconst ReactRouterContext = createContext(undefined);\nexport { ReactRouterContext };\nexport function useRouterContext() {\n const ctx = useContext(ReactRouterContext);\n if (!ctx) {\n throw new Error(\"useRouter must be used within a RouterProvider\");\n }\n return ctx;\n}\nexport function useNavigate() {\n const { navigate } = useRouterContext();\n return navigate;\n}\nexport function useParams(arg) {\n const { params } = useRouterContext();\n if (arg) {\n return params[arg];\n }\n else {\n return params;\n }\n}\nexport function useLocation() {\n const { location } = useRouterContext();\n return location;\n}\nexport function useNavigationPrompt(prompt) {\n const { router } = useRouterContext();\n useEffect(() => {\n router.getTopRouter().prompt = prompt;\n return () => {\n router.getTopRouter().prompt = undefined;\n };\n }, []);\n useEffect(() => {\n if (prompt.when) {\n const doBlock = prompt.when;\n const listener = function (ev) {\n if (doBlock) {\n ev.preventDefault();\n ev.returnValue = \"\";\n }\n };\n window.addEventListener(\"beforeunload\", listener);\n return () => {\n window.removeEventListener(\"beforeunload\", listener);\n };\n }\n }, [prompt.when]);\n}\n//# sourceMappingURL=Router.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useNavigate, useRouterContext } from \"./Router\";\nexport function Nav({ children, onClick }) {\n const navigate = useNavigate();\n const _onClick = (ev) => {\n const link = ev.target.closest('a');\n if (link && link.href) {\n ev.stopPropagation();\n ev.preventDefault();\n navigate(link.href, { replace: true });\n onClick?.(ev);\n }\n };\n return (_jsx(\"span\", { onClick: _onClick, children: children }));\n}\nexport function NavLink({ children, href, className, topLevelNav, clearBreadcrumbs = false }) {\n const { router } = useRouterContext();\n const _onClick = (ev) => {\n ev.stopPropagation();\n ev.preventDefault();\n const actualRouter = topLevelNav ? router.getTopRouter() : router;\n actualRouter.navigate(href, { replace: clearBreadcrumbs });\n };\n return (_jsx(\"a\", { href: href, className: className, onClick: _onClick, children: children }));\n}\n//# sourceMappingURL=Nav.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect, useState } from \"react\";\nimport { useRouterContext } from \"./Router\";\nexport function RouteComponent({ spinner }) {\n const ctx = useRouterContext();\n const route = ctx.route;\n if (route.Component) {\n const Component = route.Component;\n return _jsx(Component, { ...ctx.params });\n }\n else if (route.LazyComponent) {\n return _jsx(LazyRouteComponent, { route: route, spinner: spinner });\n }\n else {\n throw new Error(`Invalid route for ${route.path}. Either Component or LazyCOmponent must be specified.`);\n }\n}\nfunction LazyRouteComponent({ route, spinner }) {\n const [Component, setComponent] = useState(null);\n useEffect(() => {\n route.LazyComponent().then(module => {\n if (!module.default) {\n throw new Error(`Lazy module for ${route.path} does not have a default export`);\n }\n // we need to wrap the component type in an arrow function\n // otherwise the setState function will execute the function as a state update function\n setComponent(() => module.default);\n });\n }, [route]);\n return Component ? (_jsx(Component, {})) : spinner || null;\n}\n//# sourceMappingURL=RouteComponent.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { FixLinks } from \"./FixLinks\";\nimport { RouteComponent } from \"./RouteComponent\";\nimport { ReactRouterContext, useRouterContext } from \"./Router\";\nimport { joinPath } from \"./path\";\nexport function NestedNavigationContext({ basePath, fixLinks = false, children }) {\n const ctx = useRouterContext();\n const wrapWithFixLinks = fixLinks ?\n (elem) => _jsx(FixLinks, { basePath: ctx.matchedRoutePath, children: elem })\n : (elem) => elem;\n return (_jsx(ReactRouterContext.Provider, { value: {\n ...ctx,\n navigate: (to, options) => {\n const actualBasePath = options?.basePath ? joinPath(basePath, options.basePath) : basePath;\n return ctx.navigate(to, { ...options, basePath: actualBasePath });\n }\n }, children: wrapWithFixLinks(children ? children : _jsx(RouteComponent, {})) }));\n}\n//# sourceMappingURL=NestedNavigationContext.js.map","import { jsxs as _jsxs, jsx as _jsx } from \"react/jsx-runtime\";\nimport { useRouterContext } from \"./Router\";\nexport function Route404Component() {\n const ctx = useRouterContext();\n return _jsxs(\"div\", { children: [\"Route not found for path \", ctx.matchedRoutePath] });\n}\nexport function createRoute404() {\n return {\n params: {},\n matchedSegments: [],\n state: null,\n value: {\n path: 'virtual:404',\n Component: () => _jsx(Route404Component, {})\n }\n };\n}\n//# sourceMappingURL=Route404.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { FixLinks } from \"./FixLinks\";\nimport { createRoute404 } from \"./Route404\";\nimport { RouteComponent } from \"./RouteComponent\";\nimport { NestedRouter, ReactRouterContext, useRouterContext } from \"./Router\";\nexport function NestedRouterProvider({ routes, index, children, fixLinks = false }) {\n const ctx = useRouterContext();\n const [nestedRouteMatch, setNestedRouteMatch] = useState(undefined);\n const nestedRouter = useMemo(() => {\n if (typeof window === 'undefined')\n return null;\n const basePath = ctx.matchedRoutePath;\n const nestedRouter = new NestedRouter(ctx.router, basePath, routes);\n nestedRouter.index = index;\n return nestedRouter;\n }, []);\n useEffect(() => {\n if (nestedRouter) {\n if (ctx.matchedRoutePath !== nestedRouter.basePath) {\n // the change doesn't belong to this nested router\n // it should be handled by the top level router which will change the page or the nested router\n return;\n }\n const route = nestedRouter.match(ctx.remainingPath || '/') || createRoute404();\n setNestedRouteMatch(route);\n }\n }, [nestedRouter, ctx.remainingPath]);\n const wrapWithFixLinks = fixLinks ?\n (elem) => _jsx(FixLinks, { basePath: ctx.matchedRoutePath, children: elem })\n : (elem) => elem;\n return nestedRouteMatch && (_jsx(ReactRouterContext.Provider, { value: {\n ...ctx,\n router: nestedRouter,\n route: nestedRouteMatch.value,\n params: nestedRouteMatch.params,\n matchedRoutePath: '/' + nestedRouteMatch.matchedSegments.join('/'),\n remainingPath: nestedRouteMatch.remainingSegments ? '/' + nestedRouteMatch.remainingSegments.join('/') : undefined,\n navigate: (to, options) => {\n return nestedRouter.navigate(to, options);\n }\n }, children: wrapWithFixLinks(children ? children : _jsx(RouteComponent, {})) }));\n}\n//# sourceMappingURL=NestedRouterProvider.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useSafeLayoutEffect } from \"@vertesia/ui/core\";\n//import { useSafeLayoutEffect } from \"../core\";\nimport { useMemo, useState } from \"react\";\nimport { RouteComponent } from \"./RouteComponent\";\nimport { ReactRouterContext, Router } from \"./Router\";\nimport { createRoute404 } from \"./Route404\";\nexport function RouterProvider({ routes, index, onChange, children }) {\n const [state, setState] = useState(undefined);\n const router = useMemo(() => {\n if (typeof window === 'undefined')\n return null;\n const router = new Router(routes, (match) => {\n if (match === null) {\n match = createRoute404();\n }\n setState({\n location: window.location,\n route: match.value,\n params: match.params,\n state: match.state,\n router: router,\n matchedRoutePath: '/' + match.matchedSegments.join('/'),\n remainingPath: match.remainingSegments ? '/' + match.remainingSegments.join('/') : undefined,\n navigate: (to, options) => {\n return router.navigate(to, options);\n }\n });\n }).withObserver(onChange);\n router.index = index;\n return router;\n }, []);\n useSafeLayoutEffect(() => {\n router && router.start();\n return () => {\n router && router.stop();\n };\n }, []);\n return state && (_jsx(ReactRouterContext.Provider, { value: state, children: children ? children : _jsx(RouteComponent, {}) }));\n}\n//# sourceMappingURL=RouterProvider.js.map"],"names":["isRootPath","path","joinPath","path1","path2","endsWith","startsWith","substring","getPathSegments","s","e","length","split","toSegments","Array","isArray","Error","PathWithParams","params","hash","constructor","i","lastIndexOf","this","indexOf","URLSearchParams","add","key","value","Object","entries","set","toString","BASE_PATH","Symbol","LocationChangeEvent","name","type","location","state","_canceled","isPageLoad","isBackForward","isLinkClick","isNavigation","isCancelable","cancel","BeforeLocationChangeEvent","super","AfterLocationChangeEvent","HistoryNavigator","stickyParams","_popStateListener","_linkNavListener","_listeners","addListener","listener","push","fireLocationChange","event","firePageLoad","URL","window","href","addStickyParams","navigate","to","options","basePath","_navigate","beforeEvent","currentState","history","newChainEntry","title","document","pathname","search","historyChain","replace","slice","stateToStore","from","data","undefined","start","ev","url","elem","tagName","toLowerCase","trim","getElementHrefAsUrl","target","origin","preventDefault","addEventListener","body","stop","removeEventListener","FixLinks","children","ref","useRef","useEffect","current","divElem","_jsx","className","PathMatcher","tree","RootSegmentNode","loadMapping","mapping","addSegments","addPath","segments","node","l","segment","childNode","wildcard","VariableSegmentNode","join","WildcardSegmentNode","LiteralSegmentNode","match","matchedSegments","remainingSegments","ParentSegmentNode","_","paramName","BaseRouter","index","matcher","routes","route","useIndex","Router","prompt","observer","navigator","updateState","when","confirm","message","getTopRouter","setStickyParams","withObserver","NestedRouter","parent","isBasePathNested","childBasePath","ReactRouterContext","createContext","useRouterContext","ctx","useContext","useNavigate","useParams","arg","useLocation","useNavigationPrompt","router","doBlock","returnValue","Nav","onClick","link","closest","stopPropagation","NavLink","topLevelNav","clearBreadcrumbs","RouteComponent","spinner","Component","LazyComponent","LazyRouteComponent","setComponent","useState","then","module","default","NestedNavigationContext","fixLinks","wrapWithFixLinks","matchedRoutePath","Provider","actualBasePath","Route404Component","_jsxs","createRoute404","NestedRouterProvider","nestedRouteMatch","setNestedRouteMatch","nestedRouter","useMemo","remainingPath","RouterProvider","onChange","setState","useSafeLayoutEffect"],"mappings":"sNAAO,SAASA,EAAWC,GACvB,MAAgB,MAATA,GAAyB,KAATA,CAC3B,CACO,SAASC,EAASC,EAAOC,GAa5B,OAXIA,EADAD,EAAME,SAAS,MAAQD,EAAME,WAAW,KAChCH,EAAQC,EAAMG,UAAU,GAE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AAMC,gBAAgBJ,KAAK,KACnD2E,cAAexE,EAAME,kBAAoB,IAAMF,EAAME,kBAAkBL,KAAK,UAAOvC,EACnFnB,SAAU,CAACC,EAAIC,IACJgG,EAAOlG,SAASC,EAAIC,QAGpCiF,aAAaoD,GAEhB,OADArC,EAAO9B,MAAQA,EACR8B,IACR,IAOH,OANAuC,GAAoB,KAChBvC,GAAUA,EAAO9E,QACV,KACH8E,GAAUA,EAAOjE,UAEtB,IACI3D,GAAUoE,EAAK8C,EAAmBmC,SAAU,CAAEhK,MAAOW,EAAO8D,SAAUA,GAAsBM,EAAKmE,EAAgB,CAAE,IAC9H"}
1
+ {"version":3,"file":"vertesia-ui-router.js","sources":["esm/router/path.js","esm/router/PathWithParams.js","esm/router/HistoryNavigator.js","esm/router/FixLinks.js","esm/router/PathMatcher.js","esm/router/Router.js","esm/router/Nav.js","esm/router/RouteComponent.js","esm/router/NestedNavigationContext.js","esm/router/Route404.js","esm/router/NestedRouterProvider.js","esm/router/RouterProvider.js"],"sourcesContent":["export function isRootPath(path) {\n return path === '/' || path === '';\n}\nexport function joinPath(path1, path2) {\n if (path1.endsWith('/') && path2.startsWith('/')) {\n path2 = path1 + path2.substring(1);\n }\n else if (path1.endsWith('/')) {\n path2 = path1 + path2;\n }\n else if (path2.startsWith('/')) {\n path2 = path1 + path2;\n }\n else {\n path2 = path1 + '/' + path2;\n }\n return path2;\n}\nexport function getPathSegments(path) {\n if (path === '') {\n return [];\n }\n if (path === '/') {\n return [''];\n }\n let s = 0, e = path.length;\n if (path.startsWith('./')) {\n s = 2;\n }\n else if (path.startsWith('/')) {\n s = 1;\n }\n if (path.endsWith('/')) {\n e = path.length - 1;\n }\n return (s > 0 || e < path.length ? path.substring(s, e) : path).split('/');\n}\nexport function toSegments(path) {\n if (typeof path === 'string') {\n return getPathSegments(path);\n }\n else if (Array.isArray(path)) {\n return path;\n }\n else {\n throw new Error(`Unsupported path object: ${path}`);\n }\n}\n// export class Path {\n// static parse(path: string, abs = false) {\n// if (abs !== undefined) {\n// abs = path.startsWith('/');\n// }\n// return new Path(getPathSegments(path), abs);\n// }\n// constructor(public segments: string[], public isAbsolute = false) {\n// }\n// getParameters() {\n// const out = [];\n// for (const segment of this.segments) {\n// if (segment[0] === ':') {\n// out.push(segment.substring(1));\n// }\n// }\n// if (this.segments[this.segments.length - 1] === '*') {\n// out.push('_');\n// }\n// return out;\n// }\n// resolveParameters(path: string) {\n// const params: PathMatchParams = {};\n// const resolvedSegments = getPathSegments(path);\n// if (resolvedSegments.length < this.segments.length) {\n// return null;\n// }\n// const segments = this.segments;\n// for (let i = 0, l = segments.length; i < l; i++) {\n// const seg = segments[i];\n// if (seg[0] === ':') {\n// params[seg.substring(1)] = resolvedSegments[i];\n// }\n// }\n// if (resolvedSegments.length - this.segments.length) {\n// params._ = resolvedSegments.slice(this.segments.length);\n// }\n// return params;\n// }\n// match(path: string | string[] | Path) {\n// const segments = toSegments(path);\n// if (segments.length < this.segments.length) {\n// return false;\n// }\n// let params: PathMatchParams | undefined;\n// const mySegments = this.segments;\n// for (let i = 0, l = mySegments.length; i < l; i++) {\n// const segment = mySegments[i];\n// if (segment === ':') {\n// if (!params) params = {};\n// params[segment.substring(1)] = segment;\n// } else if (segment !== segments[i]) {\n// if (i === l - 1 && segment === '*') {\n// if (!params) params = {};\n// params._ = segments.slice(i);\n// return params;\n// }\n// return false;\n// }\n// }\n// return params ? params : false;\n// }\n// join(path: Path | string | string[]) {\n// const segments = toSegments(path);\n// return new Path(this.segments.concat(segments), this.isAbsolute);\n// }\n// getRelativePath(path: Path | string | string[], asAbsolute: boolean = false) {\n// const segments = toSegments(path);\n// const extraSegmentsCount = segments.length - this.segments.length;\n// if (extraSegmentsCount <= 0) {\n// return null;\n// }\n// return new Path(segments.slice(this.segments.length), asAbsolute);\n// }\n// prependSegments(segments: string[]) {\n// this.segments = segments.concat(this.segments);\n// }\n// appendSegments(segments: string[]) {\n// this.segments = this.segments.concat(segments);\n// }\n// toAbsolutePath() {\n// return '/' + this.segments.join('/');\n// }\n// toRelativePath() {\n// return this.segments.join('/');\n// }\n// toString() {\n// const path = this.segments.join('/');\n// return this.isAbsolute ? '/' + path : path;\n// }\n// }\n//# sourceMappingURL=path.js.map","export class PathWithParams {\n path;\n params;\n hash;\n constructor(path) {\n let i = path.lastIndexOf('#');\n if (i > -1) {\n this.hash = path.substring(i);\n path = path.substring(0, i);\n }\n else {\n this.hash = '';\n }\n i = path.indexOf('?');\n if (i > -1) {\n this.path = path.substring(0, i);\n this.params = new URLSearchParams(path.substring(i + 1));\n }\n else {\n this.path = path;\n this.params = new URLSearchParams();\n }\n }\n add(params) {\n for (const [key, value] of Object.entries(params)) {\n this.params.set(key, value);\n }\n return this;\n }\n toString() {\n return this.path + '?' + this.params.toString() + this.hash;\n }\n}\n//# sourceMappingURL=PathWithParams.js.map","import { joinPath } from \"./path\";\nimport { PathWithParams } from \"./PathWithParams\";\nconst BASE_PATH = Symbol('BASE_PATH');\nexport { BASE_PATH };\nexport class LocationChangeEvent {\n name;\n type;\n location;\n state;\n _canceled = false;\n constructor(name, type, location, state) {\n this.name = name;\n this.type = type;\n this.location = location;\n this.state = state;\n }\n get isPageLoad() {\n return this.type === 'initial';\n }\n get isBackForward() {\n return this.type === 'popState';\n }\n get isLinkClick() {\n return this.type === 'linkClick';\n }\n get isNavigation() {\n return this.type === 'navigate';\n }\n get isCancelable() {\n return this.name === 'beforeChange';\n }\n cancel() {\n if (this.name === 'afterChange') {\n throw new Error('Cannot cancel afterChange event');\n }\n this._canceled = true;\n }\n}\nexport class BeforeLocationChangeEvent extends LocationChangeEvent {\n constructor(type, location, state) {\n super('beforeChange', type, location, state);\n }\n}\nexport class AfterLocationChangeEvent extends LocationChangeEvent {\n constructor(type, location, state) {\n super('afterChange', type, location, state);\n }\n}\nfunction getElementHrefAsUrl(elem) {\n if (elem && elem.tagName.toLowerCase() === 'a') {\n const href = elem?.href.trim();\n if (typeof href === 'string' && href.length > 0) {\n return new URL(href);\n }\n }\n return null;\n}\nexport class HistoryNavigator {\n // params to preserve in the query string when navigating\n stickyParams;\n _popStateListener;\n _linkNavListener;\n _listeners = [];\n constructor() {\n }\n addListener(listener) {\n this._listeners.push(listener);\n }\n fireLocationChange(event) {\n for (const listener of this._listeners) {\n listener(event);\n }\n }\n /**\n * Should be called when the page is first loaded.\n * It will fire a location change event with type `initial` and the current window.location as the location\n */\n firePageLoad() {\n this.fireLocationChange(new AfterLocationChangeEvent('initial', new URL(window.location.href)));\n }\n addStickyParams(path) {\n if (this.stickyParams) {\n return new PathWithParams(path).add(this.stickyParams).toString();\n }\n return path;\n }\n navigate(to, options = {}) {\n if (options.stepsBack && options.stepsBack > 0) {\n this.stepBack(options.stepsBack, options);\n return;\n }\n if (options.basePath) {\n let basePath = options.basePath;\n if (!basePath.startsWith('/')) {\n basePath = '/' + basePath;\n }\n to = joinPath(basePath, to);\n }\n to = this.addStickyParams(to);\n this._navigate(new URL(to, window.location.href), 'navigate', options);\n }\n stepBack(steps, options = {}) {\n const historyChain = window.history.state.historyChain || [];\n const to = historyChain.length >= steps\n ? new URL(historyChain[historyChain.length - steps].href, window.location.href)\n : new URL(window.location.origin, window.location.href);\n this._navigate(to, 'popState', options);\n const stateToStore = {\n from: window.location.href,\n historyChain: historyChain.slice(0, -steps),\n data: options.state || undefined,\n title: options.title || document.title\n };\n window.history['replaceState'](stateToStore, '', to.href);\n this.fireLocationChange(new AfterLocationChangeEvent('popState', to, options.state));\n }\n _navigate(to, type, options) {\n const beforeEvent = new BeforeLocationChangeEvent(type, to, options.state);\n this.fireLocationChange(beforeEvent);\n if (beforeEvent._canceled) {\n return;\n }\n // Build navigation chain by preserving previous history\n const currentState = window.history.state;\n const currentTitle = options.title || document.title;\n // Create new history chain entry\n const newChainEntry = {\n title: currentTitle,\n href: window.location.pathname + window.location.search + window.location.hash\n };\n // Build the history chain - clear if using replace\n let historyChain = [];\n if (!options.replace && currentState?.historyChain) {\n historyChain = [...currentState.historyChain];\n }\n // Only add to chain if not replacing\n if (!options.replace) {\n historyChain.push(newChainEntry);\n // Limit chain length to prevent memory issues (keep last 10 entries)\n if (historyChain.length > 10) {\n historyChain = historyChain.slice(-10);\n }\n }\n const stateToStore = {\n from: window.location.href,\n historyChain: historyChain,\n data: options.state || undefined,\n title: options.title || document.title\n };\n window.history[options.replace ? 'replaceState' : 'pushState'](stateToStore, '', to.href);\n this.fireLocationChange(new AfterLocationChangeEvent(type, to, options.state));\n }\n start() {\n if (typeof window === \"undefined\") {\n return;\n }\n const _popStateListener = (ev) => {\n let type = ev.state ? 'popState' : 'linkClick';\n const to = new URL(window.location.href);\n let state = undefined;\n if (ev.state) {\n type = 'popState';\n state = ev.state.data;\n }\n else {\n type = 'linkClick';\n }\n this.fireLocationChange(new AfterLocationChangeEvent(type, to, state));\n };\n const _linkNavListener = (ev) => {\n const url = getElementHrefAsUrl(ev.target);\n if (url && url.origin === window.location.origin) {\n ev.preventDefault();\n const to = new URL(this.addStickyParams(url.href));\n const basePath = ev[BASE_PATH] || ev.target[BASE_PATH];\n if (basePath) {\n to.pathname = joinPath(basePath, to.pathname);\n }\n this._navigate(to, 'linkClick', {});\n }\n };\n this._popStateListener = _popStateListener;\n this._linkNavListener = _linkNavListener;\n window.addEventListener('popstate', _popStateListener);\n document.body.addEventListener('click', this._linkNavListener);\n }\n stop() {\n this._popStateListener && window.removeEventListener('popstate', this._popStateListener);\n this._linkNavListener && document.body.removeEventListener('click', this._linkNavListener);\n }\n}\n//# sourceMappingURL=HistoryNavigator.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect, useRef } from \"react\";\nimport { BASE_PATH } from \"./HistoryNavigator\";\nexport function FixLinks({ basePath, children }) {\n const ref = useRef(null);\n useEffect(() => {\n if (ref.current) {\n const divElem = ref.current;\n const listener = (ev) => {\n const elem = ev.target;\n if (elem.tagName.toLowerCase() === 'a') {\n ev[BASE_PATH] = basePath;\n }\n };\n divElem.addEventListener('click', listener);\n return () => {\n divElem.removeEventListener('click', listener);\n };\n }\n }, [ref.current]);\n return (_jsx(\"div\", { ref: ref, className: \"h-full w-full\", children: children }));\n}\n//# sourceMappingURL=FixLinks.js.map","import { getPathSegments, toSegments } from \"./path\";\n/**\n * Path matcher which support :param and *wildcard segments.\n * The wildcard segment is only supported as the last segment\n */\nexport class PathMatcher {\n tree = new RootSegmentNode();\n loadMapping(mapping) {\n for (const [key, value] of Object.entries(mapping)) {\n this.addSegments(getPathSegments(key), value);\n }\n }\n addPath(path, value) {\n this.addSegments(getPathSegments(path), value);\n }\n addSegments(segments, value) {\n let node = this.tree;\n for (let i = 0, l = segments.length; i < l; i++) {\n const segment = segments[i];\n if (segment[0] === ':') {\n let childNode = node.wildcard;\n if (!childNode) {\n childNode = new VariableSegmentNode(segment);\n node.wildcard = childNode;\n }\n else if (!(childNode instanceof VariableSegmentNode)) {\n throw new Error(`Failed to index path segments: ${segments.join('/')}. A wildcard \":\" segment will overwrite an existing wildcard segment at path: ${'/' + segments.slice(0, i).join(\"/\")}`);\n }\n node = childNode;\n }\n else if (segment === '*') {\n if (node.wildcard) {\n throw new Error(`Failed to index path segments: ${segments.join('/')}. A wildcard \"*\" segment already exists at path: ${'/' + segments.slice(0, i).join(\"/\")}`);\n }\n node.wildcard = new WildcardSegmentNode(segment, value);\n if (i < l - 1) {\n throw new Error(`Failed to index path segments: ${segments.join('/')}. A wildcard segment must be the last segment`);\n }\n return;\n }\n else {\n let childNode = node.children[segment];\n if (!childNode) {\n childNode = new LiteralSegmentNode(segment);\n node.children[segment] = childNode;\n } // else // a literal segment already exists\n node = childNode;\n }\n }\n if (node.value !== undefined) {\n throw new Error(`Failed to index path segments: ${segments.join('/')}. A value already exists at path: ${'/' + segments.join(\"/\")}`);\n }\n node.value = value;\n }\n match(path) {\n const segments = toSegments(path);\n if (segments.length === 0) {\n return null;\n }\n const params = {};\n let node = this.tree;\n for (const segment of segments) {\n const match = node.match(segment, params);\n if (match) {\n node = match;\n }\n else {\n return null;\n }\n }\n if (!node.value) { // not a leaf node (partial match)\n if (node instanceof ParentSegmentNode) {\n if (node.wildcard instanceof WildcardSegmentNode) {\n node = node.wildcard.match('', params);\n if (!node.value) {\n throw new Error(\"Wildcard segment node `*` must have a value\");\n }\n }\n }\n if (!node.value)\n return null; // not a leaf node, neither a trailing wildcard (partial match)\n }\n let matchedSegments, remainingSegments;\n if (params._ && params._.length > 0) {\n matchedSegments = segments.slice(0, -params._.length);\n remainingSegments = params._;\n }\n else {\n matchedSegments = segments;\n }\n return { params, matchedSegments, remainingSegments, value: node.value };\n }\n}\nclass ParentSegmentNode {\n name;\n value;\n children = {};\n wildcard;\n constructor(name, value) {\n this.name = name;\n this.value = value;\n }\n match(segment, params) {\n let node = this.children[segment];\n if (node) {\n return node;\n }\n else if (this.wildcard) {\n if (this.wildcard instanceof WildcardSegmentNode) {\n return this.wildcard.match(segment, params);\n }\n else if (this.wildcard instanceof VariableSegmentNode) {\n params[this.wildcard.paramName] = segment;\n return this.wildcard;\n }\n else {\n throw new Error(\"Unknown wildcard segment node type: \" + this.wildcard.constructor.name);\n }\n }\n else {\n return null;\n }\n }\n}\nclass RootSegmentNode extends ParentSegmentNode {\n constructor() {\n super(\"#root\");\n }\n}\nclass LiteralSegmentNode extends ParentSegmentNode {\n constructor(name, value) {\n super(name, value);\n }\n}\nclass VariableSegmentNode extends ParentSegmentNode {\n paramName;\n constructor(name, value) {\n super(name, value);\n this.paramName = name.substring(1);\n }\n}\nclass WildcardSegmentNode {\n name;\n value;\n constructor(name, value) {\n this.name = name;\n this.value = value;\n }\n match(segment, params) {\n if (!params._) {\n params._ = segment ? [segment] : [];\n }\n else {\n segment && params._.push(segment);\n }\n return this;\n }\n}\n//# sourceMappingURL=PathMatcher.js.map","import { createContext, useContext, useEffect } from \"react\";\nimport { HistoryNavigator } from \"./HistoryNavigator\";\nimport { PathMatcher } from \"./PathMatcher\";\nimport { isRootPath, joinPath } from \"./path\";\nexport class BaseRouter {\n // the path to use when navigating to the root of the router\n index;\n matcher = new PathMatcher();\n constructor(routes, index) {\n this.index = index;\n for (const route of routes) {\n this.matcher.addPath(route.path, route);\n }\n }\n match(path) {\n const useIndex = isRootPath(path) && this.index;\n return this.matcher.match(useIndex ? this.index : path);\n }\n}\nexport class Router extends BaseRouter {\n prompt;\n observer;\n navigator = new HistoryNavigator();\n constructor(routes, updateState) {\n super(routes);\n this.navigator.addListener((event) => {\n if (event.isCancelable && this.prompt && !!this.prompt.when) {\n if (!window.confirm(this.prompt.message))\n return;\n }\n if (this.observer) {\n this.observer(event);\n }\n // only process afterChange events\n if (event.name === \"afterChange\") {\n const match = this.match(event.location.pathname);\n if (match && match.value) {\n updateState({\n ...match,\n state: event.state,\n });\n }\n else {\n updateState(null);\n }\n }\n });\n }\n getTopRouter() {\n return this;\n }\n /**\n * Subsequent navigations will preserve the given params in the query string.\n * Use null to clear the sticky params.\n * @param params\n */\n setStickyParams(params) {\n this.navigator.stickyParams = params != null ? params : undefined;\n }\n withObserver(observer) {\n this.observer = observer;\n return this;\n }\n start() {\n this.navigator.start();\n // initialize with the current location\n this.navigator.firePageLoad();\n }\n stop() {\n this.navigator.stop();\n }\n navigate(path, options) {\n this.navigator.navigate(path, options);\n }\n}\nexport class NestedRouter extends BaseRouter {\n parent;\n basePath;\n constructor(parent, basePath, routes) {\n super(routes);\n this.parent = parent;\n this.basePath = basePath;\n }\n getTopRouter() {\n if (this.parent instanceof Router) {\n return this.parent;\n }\n else {\n return this.parent.getTopRouter();\n }\n }\n navigate(path, options) {\n // base path is nested by default in a NestedRouter unless explicitly set to false by caller\n const isBasePathNested = options?.isBasePathNested ?? true;\n let basePath;\n if (isBasePathNested) {\n const childBasePath = options?.basePath;\n // e.g. \"/store\" + \"/objects/123\" => \"/store/objects/123\"\n basePath = childBasePath ? joinPath(this.basePath, childBasePath) : this.basePath;\n }\n else {\n // e.g. \"/store\" + \"/studio\" => \"/studio\"\n basePath = options?.basePath ?? this.basePath;\n }\n this.parent.navigate(path, {\n ...options,\n basePath,\n });\n }\n}\nconst ReactRouterContext = createContext(undefined);\nexport { ReactRouterContext };\nexport function useRouterContext() {\n const ctx = useContext(ReactRouterContext);\n if (!ctx) {\n throw new Error(\"useRouter must be used within a RouterProvider\");\n }\n return ctx;\n}\nexport function useNavigate() {\n const { navigate } = useRouterContext();\n return navigate;\n}\nexport function useParams(arg) {\n const { params } = useRouterContext();\n if (arg) {\n return params[arg];\n }\n else {\n return params;\n }\n}\nexport function useLocation() {\n const { location } = useRouterContext();\n return location;\n}\nexport function useNavigationPrompt(prompt) {\n const { router } = useRouterContext();\n useEffect(() => {\n router.getTopRouter().prompt = prompt;\n return () => {\n router.getTopRouter().prompt = undefined;\n };\n }, []);\n useEffect(() => {\n if (prompt.when) {\n const doBlock = prompt.when;\n const listener = function (ev) {\n if (doBlock) {\n ev.preventDefault();\n ev.returnValue = \"\";\n }\n };\n window.addEventListener(\"beforeunload\", listener);\n return () => {\n window.removeEventListener(\"beforeunload\", listener);\n };\n }\n }, [prompt.when]);\n}\n//# sourceMappingURL=Router.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useNavigate, useRouterContext } from \"./Router\";\nexport function Nav({ children, onClick }) {\n const navigate = useNavigate();\n const _onClick = (ev) => {\n const link = ev.target.closest('a');\n if (link && link.href) {\n ev.stopPropagation();\n ev.preventDefault();\n navigate(link.href, { replace: true });\n onClick?.(ev);\n }\n };\n return (_jsx(\"span\", { onClick: _onClick, children: children }));\n}\nexport function NavLink({ children, href, className, topLevelNav, clearBreadcrumbs = false }) {\n const { router } = useRouterContext();\n const _onClick = (ev) => {\n ev.stopPropagation();\n ev.preventDefault();\n const actualRouter = topLevelNav ? router.getTopRouter() : router;\n actualRouter.navigate(href, { replace: clearBreadcrumbs });\n };\n return (_jsx(\"a\", { href: href, className: className, onClick: _onClick, children: children }));\n}\n//# sourceMappingURL=Nav.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect, useState } from \"react\";\nimport { useRouterContext } from \"./Router\";\nexport function RouteComponent({ spinner }) {\n const ctx = useRouterContext();\n const route = ctx.route;\n if (route.Component) {\n const Component = route.Component;\n return _jsx(Component, { ...ctx.params });\n }\n else if (route.LazyComponent) {\n return _jsx(LazyRouteComponent, { route: route, spinner: spinner });\n }\n else {\n throw new Error(`Invalid route for ${route.path}. Either Component or LazyCOmponent must be specified.`);\n }\n}\nfunction LazyRouteComponent({ route, spinner }) {\n const [Component, setComponent] = useState(null);\n useEffect(() => {\n route.LazyComponent().then(module => {\n if (!module.default) {\n throw new Error(`Lazy module for ${route.path} does not have a default export`);\n }\n // we need to wrap the component type in an arrow function\n // otherwise the setState function will execute the function as a state update function\n setComponent(() => module.default);\n });\n }, [route]);\n return Component ? (_jsx(Component, {})) : spinner || null;\n}\n//# sourceMappingURL=RouteComponent.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { FixLinks } from \"./FixLinks\";\nimport { RouteComponent } from \"./RouteComponent\";\nimport { ReactRouterContext, useRouterContext } from \"./Router\";\nimport { joinPath } from \"./path\";\nexport function NestedNavigationContext({ basePath, fixLinks = false, children }) {\n const ctx = useRouterContext();\n const wrapWithFixLinks = fixLinks ?\n (elem) => _jsx(FixLinks, { basePath: ctx.matchedRoutePath, children: elem })\n : (elem) => elem;\n return (_jsx(ReactRouterContext.Provider, { value: {\n ...ctx,\n navigate: (to, options) => {\n const actualBasePath = options?.basePath ? joinPath(basePath, options.basePath) : basePath;\n return ctx.navigate(to, { ...options, basePath: actualBasePath });\n }\n }, children: wrapWithFixLinks(children ? children : _jsx(RouteComponent, {})) }));\n}\n//# sourceMappingURL=NestedNavigationContext.js.map","import { jsxs as _jsxs, jsx as _jsx } from \"react/jsx-runtime\";\nimport { useRouterContext } from \"./Router\";\nexport function Route404Component() {\n const ctx = useRouterContext();\n return _jsxs(\"div\", { children: [\"Route not found for path \", ctx.matchedRoutePath] });\n}\nexport function createRoute404() {\n return {\n params: {},\n matchedSegments: [],\n state: null,\n value: {\n path: 'virtual:404',\n Component: () => _jsx(Route404Component, {})\n }\n };\n}\n//# sourceMappingURL=Route404.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { FixLinks } from \"./FixLinks\";\nimport { createRoute404 } from \"./Route404\";\nimport { RouteComponent } from \"./RouteComponent\";\nimport { NestedRouter, ReactRouterContext, useRouterContext } from \"./Router\";\nexport function NestedRouterProvider({ routes, index, children, fixLinks = false }) {\n const ctx = useRouterContext();\n const [nestedRouteMatch, setNestedRouteMatch] = useState(undefined);\n const nestedRouter = useMemo(() => {\n if (typeof window === 'undefined')\n return null;\n const basePath = ctx.matchedRoutePath;\n const nestedRouter = new NestedRouter(ctx.router, basePath, routes);\n nestedRouter.index = index;\n return nestedRouter;\n }, []);\n useEffect(() => {\n if (nestedRouter) {\n if (ctx.matchedRoutePath !== nestedRouter.basePath) {\n // the change doesn't belong to this nested router\n // it should be handled by the top level router which will change the page or the nested router\n return;\n }\n const route = nestedRouter.match(ctx.remainingPath || '/') || createRoute404();\n setNestedRouteMatch(route);\n }\n }, [nestedRouter, ctx.remainingPath]);\n const wrapWithFixLinks = fixLinks ?\n (elem) => _jsx(FixLinks, { basePath: ctx.matchedRoutePath, children: elem })\n : (elem) => elem;\n return nestedRouteMatch && (_jsx(ReactRouterContext.Provider, { value: {\n ...ctx,\n router: nestedRouter,\n route: nestedRouteMatch.value,\n params: nestedRouteMatch.params,\n matchedRoutePath: '/' + nestedRouteMatch.matchedSegments.join('/'),\n remainingPath: nestedRouteMatch.remainingSegments ? '/' + nestedRouteMatch.remainingSegments.join('/') : undefined,\n navigate: (to, options) => {\n return nestedRouter.navigate(to, options);\n }\n }, children: wrapWithFixLinks(children ? children : _jsx(RouteComponent, {})) }));\n}\n//# sourceMappingURL=NestedRouterProvider.js.map","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useSafeLayoutEffect } from \"@vertesia/ui/core\";\n//import { useSafeLayoutEffect } from \"../core\";\nimport { useMemo, useState } from \"react\";\nimport { RouteComponent } from \"./RouteComponent\";\nimport { ReactRouterContext, Router } from \"./Router\";\nimport { createRoute404 } from \"./Route404\";\nexport function RouterProvider({ routes, index, onChange, children }) {\n const [state, setState] = useState(undefined);\n const router = useMemo(() => {\n if (typeof window === 'undefined')\n return null;\n const router = new Router(routes, (match) => {\n if (match === null) {\n match = createRoute404();\n }\n setState({\n location: window.location,\n route: match.value,\n params: match.params,\n state: match.state,\n router: router,\n matchedRoutePath: '/' + match.matchedSegments.join('/'),\n remainingPath: match.remainingSegments ? '/' + match.remainingSegments.join('/') : undefined,\n navigate: (to, options) => {\n return router.navigate(to, options);\n }\n });\n }).withObserver(onChange);\n router.index = index;\n return router;\n }, []);\n useSafeLayoutEffect(() => {\n router && router.start();\n return () => {\n router && router.stop();\n };\n }, []);\n return state && (_jsx(ReactRouterContext.Provider, { value: state, children: children ? children : _jsx(RouteComponent, {}) }));\n}\n//# sourceMappingURL=RouterProvider.js.map"],"names":["isRootPath","path","joinPath","path1","path2","endsWith","startsWith","substring","getPathSegments","s","e","length","split","toSegments","Array","isArray","Error","PathWithParams","params","hash","constructor","i","lastIndexOf","this","indexOf","URLSearchParams","add","key","value","Object","entries","set","toString","BASE_PATH","Symbol","LocationChangeEvent","name","type","location","state","_canceled","isPageLoad","isBackForward","isLinkClick","isNavigation","isCancelable","cancel","BeforeLocationChangeEvent","super","AfterLocationChangeEvent","HistoryNavigator","stickyParams","_popStateListener","_linkNavListener","_listeners","addListener","listener","push","fireLocationChange","event","firePageLoad","URL","window","href","addStickyParams","navigate","to","options","stepsBack","stepBack","basePath","_navigate","steps","historyChain","history","origin","stateToStore","from","slice","data","undefined","title","document","beforeEvent","currentState","newChainEntry","pathname","search","replace","start","ev","url","elem","tagName","toLowerCase","trim","getElementHrefAsUrl","target","preventDefault","addEventListener","body","stop","removeEventListener","FixLinks","children","ref","useRef","useEffect","current","divElem","_jsx","className","PathMatcher","tree","RootSegmentNode","loadMapping","mapping","addSegments","addPath","segments","node","l","segment","childNode","wildcard","VariableSegmentNode","join","WildcardSegmentNode","LiteralSegmentNode","match","matchedSegments","remainingSegments","ParentSegmentNode","_","paramName","BaseRouter","index","matcher","routes","route","useIndex","Router","prompt","observer","navigator","updateState","when","confirm","message","getTopRouter","setStickyParams","withObserver","NestedRouter","parent","isBasePathNested","childBasePath","ReactRouterContext","createContext","useRouterContext","ctx","useContext","useNavigate","useParams","arg","useLocation","useNavigationPrompt","router","doBlock","returnValue","Nav","onClick","link","closest","stopPropagation","NavLink","topLevelNav","clearBreadcrumbs","RouteComponent","spinner","Component","LazyComponent","LazyRouteComponent","setComponent","useState","then","module","default","NestedNavigationContext","fixLinks","wrapWithFixLinks","matchedRoutePath","Provider","actualBasePath","Route404Component","_jsxs","createRoute404","NestedRouterProvider","nestedRouteMatch","setNestedRouteMatch","nestedRouter","useMemo","remainingPath","RouterProvider","onChange","setState","useSafeLayoutEffect"],"mappings":"sNAAO,SAASA,EAAWC,GACvB,MAAgB,MAATA,GAAyB,KAATA,CAC3B,CACO,SAASC,EAASC,EAAOC,GAa5B,OAXIA,EADAD,EAAME,SAAS,MAAQD,EAAME,WAAW,KAChCH,EAAQC,EAAMG,UAAU,GAE3BJ,EAAME,SAAS,MAGfD,EAAME,WAAW,KAFdH,EAAQC,EAMRD,EAAQ,IAAMC,CAG9B,CACO,SAASI,EAAgBP,GAC5B,GAAa,KAATA,EACA,MAAO,GAEX,GAAa,MAATA,EACA,MAAO,CAAC,IAEZ,IAAIQ,EAAI,EAAGC,EAAIT,EAAKU,OAUpB,OATIV,EAAKK,WAAW,MAChBG,EAAI,EAECR,EAAKK,WAAW,OACrBG,EAAI,GAEJR,EAAKI,SAAS,OACdK,EAAIT,EAAKU,OAAS,IAEdF,EAAI,GAAKC,EAAIT,EAAKU,OAASV,EAAKM,UAAUE,EAAGC,GAAKT,GAAMW,MAAM,IAC1E,CACO,SAASC,EAAWZ,GACvB,GAAoB,iBAATA,EACP,OAAOO,EAAgBP,GAEtB,GAAIa,MAAMC,QAAQd,GACnB,OAAOA,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MAAMwG,EAAS,IAAIzB,EAAOH,GAAST,IACjB,OAAVA,IACAA,EAAQkE,KAEZS,EAAS,CACLtK,SAAUwB,OAAOxB,SACjBqG,MAAOV,EAAMrG,MACbV,OAAQ+G,EAAM/G,OACdqB,MAAO0F,EAAM1F,MACb+H,OAAQA,EACRwB,iBAAkB,IAAM7D,EAAMC,gBAAgBJ,KAAK,KACnD2E,cAAexE,EAAME,kBAAoB,IAAMF,EAAME,kBAAkBL,KAAK,UAAO9C,EACnFf,SAAU,CAACC,EAAIC,IACJmG,EAAOrG,SAASC,EAAIC,QAGpCoF,aAAaoD,GAEhB,OADArC,EAAO9B,MAAQA,EACR8B,IACR,IAOH,OANAuC,GAAoB,KAChBvC,GAAUA,EAAO7E,QACV,KACH6E,GAAUA,EAAOjE,UAEtB,IACI9D,GAAUuE,EAAK8C,EAAmBmC,SAAU,CAAEnK,MAAOW,EAAOiE,SAAUA,GAAsBM,EAAKmE,EAAgB,CAAE,IAC9H"}
@@ -1,2 +1,2 @@
1
- import{jsxs as e,jsx as t,Fragment as n}from"react/jsx-runtime";import{Button as i,VModal as a,VModalTitle as o,VModalBody as r,useToast as l,Input as c,Spinner as s,SelectStack as d,VSelectBox as m,useSafeLayoutEffect as u,ErrorBox as h,Center as p,useFetch as f,SelectBox as g,Modal as v,ModalTitle as x,ModalBody as y,ModalFooter as b,VTabs as N,VTabsBar as w,VTabsPanel as k,VTooltip as C,Avatar as j,ModeToggle as S,MenuList as P,ToastProvider as z,ThemeProvider as L}from"@vertesia/ui/core";import{useState as I,useEffect as T,Fragment as A,createContext as _,useContext as U}from"react";import{useUserSession as E,useUXTracking as O,setFirebaseTenant as D,getFirebaseAuth as W,UserNotFoundError as q,fetchComposableTokenFromFirebaseToken as M,UserSessionProvider as R,LastSelectedAccountId_KEY as F,LastSelectedProjectId_KEY as Y}from"@vertesia/ui/session";import{Env as G}from"@vertesia/ui/env";import V from"clsx";import{signInWithRedirect as B,OAuthProvider as J,GoogleAuthProvider as H,GithubAuthProvider as $,getAuth as K}from"firebase/auth";import{useLocation as Q}from"@vertesia/ui/router";import{Popover as X}from"@vertesia/ui/widgets";import{getTenantIdFromProject as Z}from"@vertesia/common";import{Check as ee,CopyIcon as te,LockIcon as ne}from"lucide-react";import{UserPermissionProvider as ie}from"@vertesia/ui/features";import{Transition as ae}from"@headlessui/react";function oe(){const n=E(),{client:l,account:c}=n,[s,d]=I(!1),[m,u]=I([]);T((()=>{l.account.listInvites().then((e=>{if(e.length>0){const t=e.filter((e=>e.data.account));if(0===t.length)return void console.log("No valid invites found, closing modal");console.log("Found valid invites",t.length),d(!0),u(t)}else console.log("No invites found, closing modal"),d(!1)})).catch((e=>{console.error("Error fetching invites",e)}))}),[c?.id]);const h=()=>d(!1),p=m.map((a=>a.data.account?e("div",{className:"flex flex-row w-full justify-between border rounded-sm px-2 py-2 ",children:[e("div",{className:"flex flex-col",children:[t("div",{className:"w-full font-semibold",children:a.data.account.name??a.data.account}),a.data.project&&e("div",{className:"w-full text-base",children:["- ",a.data.project.name]}),e("div",{className:"text-xs",children:["Role: ",a.data.role]}),a.data.invited_by&&e("div",{className:"text-xs",children:["by ",a.data.invited_by.name??a.data.invited_by]})]}),e("div",{className:"flex flex-col gap-4",children:[t(i,{size:"xs",onClick:()=>(async e=>{await l.account.acceptInvite(e.id),await n.fetchAccounts();const t=m.filter((t=>t.id!==e.id)).filter((e=>e.data.account));t.length>0?u(t):h()})(a),children:"Accept"})," ",t(i,{size:"xs",variant:"secondary",onClick:()=>(async e=>{await l.account.rejectInvite(e.id);const t=m.filter((t=>t.id!==e.id));u(t),0===t.length&&h()})(a),children:"Reject"})]})]},a.id):(console.warn("Invite has no account data",a),null)));return t("div",{children:e(a,{isOpen:s,onClose:h,children:[t(o,{children:"Review Invites"}),e(r,{children:[t("div",{className:"text-sm pb-4",children:"You have received the following invites to join other accounts. Please review and accept or declined them."}),p]})]})})}function re({redirectTo:a}){const[o,r]=I(!1),{trackEvent:d}=O(),[m,u]=I(""),h=l();return e(n,{children:[t(c,{value:m,onChange:u,placeholder:"Enter your enterprise email",type:"email"}),o?t("div",{className:"w-full flex justify-center",children:t(s,{})}):t(i,{variant:"outline",onClick:async()=>{if(!m)return;/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(m)?(r(!0),D(m).then((e=>{if(!e)return h({title:"Tenant not found",status:"error",duration:5e3}),void r(!1);localStorage.setItem("tenantName",e.name??"");const t=function(e){if(!G.firebase)throw new Error("Firebase configuration is not available in the environment");switch(G.firebase.providerType){case"oidc":default:return new J("oidc.main");case"google":{let t=e||window.location.pathname||"/";"/"!==t[0]&&(t="/"+t);const n=new H;return n.addScope("profile"),n.addScope("email"),n.setCustomParameters({prompt:"select_account",redirect_uri:window.location.origin+t}),n}case"microsoft":return new J("microsoft.com");case"github":return new J("github.com")}}(a);d("enterprise_signin",{firebaseTenantName:e.name}),G.logger.info("Enterprise single sign-in",{vertesia:{email:m,firebaseTenantName:e.name,firebaseTenantId:e.firebaseTenantId}}),B(W(),t),r(!1)}))):h({title:"Invalid email address",status:"error",duration:5e3})},className:"w-full mt-2 py-4 flex rounded-lg hover:shadow-sm transition duration-150 text-center",children:t("span",{className:"text-sm font-semibold",children:"Continue with Enterprise SSO"})})]})}function le({}){return e(i,{variant:"outline",onClick:()=>{localStorage.removeItem("tenantName");let e="https://dengenlabs.firebaseapp.com/__/auth/handler"+window.location.pathname;"/"!==e[0]&&(e="/"+e);const t=new $;t.addScope("profile"),t.addScope("email"),B(W(),t)},className:"w-full py-5 flex rounded-lg hover:shadow-sm transition duration-150 text-center mb-2",children:[t("img",{className:"size-6 bg-white rounded-full",src:"https://www.svgrepo.com/show/503359/github.svg",loading:"lazy",alt:"github logo"}),t("span",{className:"text-sm font-semibold",children:"Continue with GitHub"})]})}function ce({redirectTo:n}){return e(i,{variant:"outline",onClick:()=>{localStorage.removeItem("tenantName");let e=n||window.location.pathname||"/";"/"!==e[0]&&(e="/"+e);const t=new H;t.addScope("profile"),t.addScope("email"),t.setCustomParameters({prompt:"select_account",redirect_uri:window.location.origin+e}),B(W(),t)},className:"w-full py-5 flex rounded-lg hover:shadow-sm transition duration-150 text-center mb-2",children:[t("img",{className:"size-6",src:"https://www.svgrepo.com/show/475656/google-color.svg",loading:"lazy",alt:"google logo"}),t("span",{className:"text-sm font-semibold",children:"Continue with Google"})]})}function se({redirectTo:n}){return e(i,{variant:"outline",onClick:()=>{localStorage.removeItem("tenantName");let e=n||window.location.pathname||"/";"/"!==e[0]&&(e="/"+e);const t=new J("microsoft.com");t.addScope("profile"),t.addScope("email"),B(W(),t)},className:"w-full py-5 flex rounded-lg hover:shadow-sm transition duration-150 text-center",children:[t("img",{className:"size-6",src:"https://learn.microsoft.com/en-us/entra/identity-platform/media/howto-add-branding-in-apps/ms-symbollockup_mssymbol_19.svg",loading:"lazy",alt:"microsoft logo"}),t("span",{className:"text-sm font-semibold",children:"Continue with Microsoft"})]})}const de=[{id:1,label:"1-10 employees"},{id:11,label:"11-100 employees"},{id:101,label:"101-1000 employees"},{id:1001,label:"1001-5000 employees"},{id:5001,label:"5000+ employees"}],me=[{id:"personal",label:"Personal",description:"For personal use, or for a small team."},{id:"company",label:"Company",description:"For a company or organization."}],ue=[{id:"testing",label:"Just Testing or Evaluating LLMs"},{id:"exploring",label:"Actively Exploring LLMs on a Project"},{id:"using",label:"Already Using LLMs in Production"},{id:"migrating",label:"Migrating to different LLMs"},{id:"other",label:"Other"}];function he({onSignup:a,goBack:o}){const[r,l]=I(void 0),[s,u]=I(void 0),[h,p]=I(void 0),[f,g]=I(void 0),[v,x]=I(void 0),[y,b]=I(void 0),[N,w]=I(void 0),k="company"===r;T((()=>{const e=K().currentUser;e?b(e):console.error("No user found")}),[y]);return e("div",{className:"flex flex-col space-y-2",children:[e("div",{className:"prose",children:[e("p",{className:"prose text-sm text-muted pt-4",children:["Welcome to Vertesia, ",y?.displayName," (",y?.email,"). Please tell us a little bit about yourself and you'll be on your way. No credit card is required."]}),N&&t("div",{className:"text-destructive",children:N})]}),t(pe,{label:"Account Type",children:t(d,{options:me,selected:me.find((e=>e.id===r)),onSelect:e=>l(e.id)})}),k&&e(n,{children:[t(pe,{label:"Company Size",children:t(m,{className:"w-full border border-accent bg-muted",value:s,options:de,onChange:u,optionLabel:e=>e?.label,placeholder:"Select Company Size"})}),t(pe,{label:"Company Name",children:t(c,{value:h,onChange:p,type:"text",required:!0})}),t(pe,{label:"Company Website",children:t(c,{value:f,onChange:g,type:"text"})})]}),t(pe,{label:"Project Maturity",children:t(m,{className:"w-full border border-accent bg-muted",options:ue,value:ue.find((e=>e.id===v)),optionLabel:e=>e?.label,placeholder:"Select Project Maturity",onChange:e=>x(e?.id)})}),e("div",{className:"pt-8 flex flex-col",children:[t(i,{variant:"primary",onClick:async()=>{if(!(r?k&&!h?(w("Please enter an organization name"),0):!k||s||(w("Please select a company size"),0):(w("Please select an account type"),0)))return;if(!r)return;const e={accountType:r,companyName:h,companySize:s?.id,companyWebsite:f,maturity:v};window.localStorage.setItem("composableSignupData",JSON.stringify(e));const t=await(K().currentUser?.getIdToken());console.log("Got firebase token",K(),t),t?a(e,t):console.error("No firebase token found")},size:"xl",children:t("span",{className:"text-lg",children:"Sign Up"})}),t(i,{variant:"ghost",size:"xl",className:"mt-4",onClick:o,children:t("span",{className:"",children:"Wrong account, go back"})})]})]})}function pe({label:n,children:i}){return e("div",{className:"flex flex-col space-y-2 pt-4",children:[t("div",{className:"text-sm text-muted",children:n}),i]})}function fe({allowedPrefix:e,isNested:n=!1,lightLogo:i,darkLogo:a}){const[o,r]=I(!1);return u((()=>{e&&r(window.location.href.startsWith(e))}),[]),o?null:t(ge,{isNested:n,lightLogo:i,darkLogo:a})}function ge({isNested:n=!1,lightLogo:i,darkLogo:a}){const{isLoading:o,user:r,authError:l}=E();return o||r?null:t("div",{style:{zIndex:999998},className:(n?"absolute":"fixed")+"overflow-y-auto ",children:e("div",{className:V("flex flex-col items-center justify-center py-14 px-4"),children:[t(ve,{authError:l,lightLogo:i,darkLogo:a}),e("div",{className:"flex gap-x-6 mt-10 justify-center text-muted",children:[t("a",{href:"https://vertesiahq.com/privacy",className:"text-sm",children:"Privacy Policy"}),t("a",{href:"https://vertesiahq.com/terms",className:"text-sm",children:"Terms of Service"})]})]})})}function ve({authError:a,darkLogo:o,lightLogo:r}){const[l,c]=I(void 0),[s,d]=I(!1),{signOut:m}=E(),{trackEvent:u}=O();history.replaceState({},"","/");const h=()=>{c(void 0),d(!0)};T((()=>{a instanceof q&&(console.log("User not found, redirecting to signup"),h())}),[a]);return e(n,{children:[r&&t("img",{src:r,alt:"logo",className:"h-15 block dark:hidden"}),o&&t("img",{src:o,alt:"logo",className:"h-15 hidden dark:block"}),l&&e("div",{className:"my-6",children:["Need to make a change?"," ",t(i,{onClick:h,children:" Go back"})]}),t("div",{className:"flex flex-col space-y-2",children:s&&!localStorage.getItem("tenantName")?t(he,{onSignup:(e,t)=>{console.log("Got Signup data",e),c(e);const n={signupData:e,firebaseToken:t};fetch(G.endpoints.studio+"/auth/signup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}).then((e=>{console.log("Signup successful",n,e),u("sign_up"),window.location.href="/"}))},goBack:()=>{console.log("Going back, signing out"),c(void 0),d(!1),m()}}):e("div",{className:"flex flex-col",children:[t("div",{className:"my-4",children:t("h2",{className:"text-2xl font-bold text-center",children:"Log in or Sign up"})}),e("div",{className:"max-w-2xl text-center my-2 px-2",children:["First time here? No problem, it's free to try!",t("br",{}),"We'll just ask you a couple of questions next and you'll be on your way."]}),e("div",{className:"flex items-center flex-col",children:[e("div",{className:"py-4 w-70",children:[t(ce,{}),t(le,{}),t(se,{})]}),e("div",{className:"flex items-center flex-row w-70 text-muted",children:[t("hr",{className:"w-full"}),t("div",{className:"px-2 text-xs",children:"OR"}),t("hr",{className:"w-full"})]}),t("div",{className:"py-4 w-70",children:t(re,{})})]}),a&&t("div",{className:"text-center",children:e("div",{className:"",children:["Sorry, we have not been able to sign you in.",t("br",{}),"Please try again or contact",t("a",{className:"text-info mx-1",href:"mailto:support@vertesiahq.com",children:"support@vertesiahq.com"}),"if it persists.",e("pre",{className:"mt-2",children:["Error: ",a.message]})]})})]})})]})}function xe(){const[e,n]=I(),[i,a]=I(),o=function(e){const t=new URLSearchParams(e.search);let n=t.get("redirect_uri");const i=t.get("code");return n&&i?(n=decodeURI(n),n.startsWith("http://127.0.0.1:")||n.startsWith("http://localhost:")?{redirect:n,code:i,profile:t.get("profile")??"default",project:t.get("project")??void 0,account:t.get("account")??void 0}:null):null}(Q()),r=l(),c=async e=>{if(!o)return;if(!e.profile)return void r({title:"Profile is required",description:"Please enter a profile name to save the client authorization",status:"error",duration:2e3});if(!e.account)return void r({title:"Account is required",description:"Please select an account to authorize the client to access the ComposablePrompts servers",status:"error",duration:2e3});if(!e.project)return void r({title:"Project is required",description:"Please select a project to authorize the client to access the ComposablePrompts servers",status:"error",duration:2e3});let t;try{const i=await M(e.account,e.project,86400);i?(t={...e,studio_server_url:G.endpoints.studio,zeno_server_url:G.endpoints.zeno,token:i},await fetch(o.redirect,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n(t)):r({title:"Failed to get composable token",status:"error",duration:5e3})}catch(e){t?(a(e),n(t)):r({title:"Error authorizing client",description:e.message,status:"error",duration:5e3})}},s=o?e?t(be,{payload:e,error:i}):t(ye,{clientInfo:o,onAccept:c}):t(h,{title:"Invalid request",children:"This page should be called by a terminal client to authenticate against the ComposablePrompts servers"});return t("div",{className:"w-full flex flex-col items-center gap-4 mt-24",children:s})}function ye({onAccept:i,clientInfo:a}){const{client:o,user:r}=E(),{data:l,error:c}=f((()=>r?o.projects.list():Promise.resolve([])),[r]);if(c)return t(h,{title:"Error loading projects",children:c.message});const d=G.isLocalDev?"Local Dev":G.isDev?"Staging":"Production";return r&&l?e(n,{children:[e("div",{className:"w-1/3",children:[e("div",{className:"mb-4 text-xl font-semibold text-gray-800",children:["Authorizing client on ",d," environment."]}),e("div",{className:"mb-2 text-md text-gray-800",children:[t("div",{children:"A client app wants authorization to access the composable prompt servers in your name."}),e("div",{children:["The client app code is ",t("b",{children:a.code}),". You can check if the code is correct in the terminal."]})]}),e("div",{className:"mb-2 text-sm text-gray-600",children:[t("div",{children:"You must choose the target account and project for the client to access."}),t("div",{children:"Also, enter a profile name that will be used to save the authorization in your client configuration."})]})]}),t(Ne,{onAccept:i,allProjects:l,data:a})]}):t(s,{size:"lg"})}function be({payload:n,error:a}){const o=l();return e("div",{children:[a?e("div",{children:[e(h,{title:"Failed to send the authorization token to the cli tool",children:['This can happen due to security checks on Safari. The error is "',a.message,'"']}),t("div",{children:"Don't worry, you can still authenticate the cli tool by pasting the authentication token in the terminal. You can close this page."})]}):t("div",{children:"The client is authenticated. You can close this page."}),t(p,{className:"mt-4",children:t(i,{variant:"secondary",onClick:()=>{n&&(navigator.clipboard.writeText(JSON.stringify(n)),o({title:"Authentication Payload copied",description:a?"You can paste the authentication payload in the terminal to authenticate the client.":"You can close the page now.",status:"success",duration:5e3}))},children:"Copy the Authentication Payload"})})]})}function Ne({allProjects:n,data:a,onAccept:o}){const{accounts:r,account:l,project:s}=E(),[d,m]=I((()=>({profile:a.profile,account:a.account??l?.id,project:a.project??s?.id}))),u=n.filter((e=>e.account===d.account));return e("div",{className:"w-1/3",children:[e("div",{className:"mb-4 flex flex-col gap-2",children:[t("span",{className:"font-semibold text-gray-600",children:"Profile Name"}),t(c,{type:"text",value:d.profile,onChange:e=>{m({...d,profile:e})}})]}),e("div",{className:"mb-4 flex flex-col gap-2",children:[t("span",{className:"font-semibold text-gray-600",children:"Account"}),t(we,{value:d.account,onChange:e=>{m({...d,account:e.id,project:void 0})},accounts:r||[]})]}),e("div",{className:"mb-4 flex flex-col gap-2",children:[t("span",{className:"font-semibold text-gray-600",children:"Project"}),t(ke,{value:d.project,onChange:e=>{m({...d,project:e.id})},projects:u})]}),t("div",{className:"pt-2",children:t(i,{size:"xl",onClick:()=>o(d),children:"Authorize Client"})})]})}function we({value:e,accounts:n,onChange:i}){return t(g,{options:n,value:n?.find((t=>t.id===e)),onChange:e=>{i(e)},by:"id",optionLabel:e=>e.name,placeholder:"Select Account"})}function ke({value:e,projects:n,onChange:i}){return t(g,{by:"id",value:n.find((t=>t.id===e)),options:n,optionLabel:e=>e.name,placeholder:"Select Project",onChange:e=>{i(e)}})}function Ce({isOpen:n,onClose:a}){return e(v,{isOpen:n,onClose:a,children:[t(x,{children:"Sign In"}),e(y,{className:"flex justify-center",children:[t(ce,{}),t(le,{}),t(se,{})]}),t(b,{justify:"end",children:t(i,{variant:"ghost",onClick:a,children:"Cancel"})})]})}function je({title:n,value:i}){const[a,o]=I(!1);return e("div",{className:"w-full flex justify-between items-center mb-1",children:[e("div",{className:"flex flex-col w-[calc(100%-3rem)]",children:[t("div",{className:"text-sm px-2 dark:text-slate-200",children:n}),t(C,{description:i,size:"xs",placement:"left",children:e("div",{className:"text-xs truncate text-muted w-full text-left px-2",children:[i," "]})})]}),a?t(ee,{className:"size-4 cursor-pointer text-success"}):t(te,{className:"size-4 cursor-pointer text-gray-400 dark:text-slate-400",onClick:()=>function(e){navigator.clipboard.writeText(e),o(!0),setTimeout((()=>o(!1)),2e3)}(i)})]})}function Se(){const n=E(),{account:i,project:a,client:o,authToken:r}=n,l=new URL(o.baseUrl).hostname,c=new URL(o.store.baseUrl).hostname,s=a?Z(a):"",d=[{name:"user",label:"User",content:e("div",{className:"space-y-1 p-2",children:[t(je,{title:"Organization ID",value:i?.id??"Unknown"}),t(je,{title:"Project ID",value:a?.id??"Unknown"}),t(je,{title:"User ID",value:r?.sub??"Unknown"}),t(je,{title:"Organization Roles",value:r?.account_roles?.join(",")??"Unknown"}),t(je,{title:"Project Roles",value:r?.project_roles?.join(",")??"Unknown"})]})},{name:"environment",label:"Environment",content:e("div",{className:"space-y-1 p-2",children:[t(je,{title:"Tenant ID",value:s}),t(je,{title:"Environment",value:G.type}),t(je,{title:"Server",value:l}),t(je,{title:"Store",value:c}),t(je,{title:"App Version",value:G.version})]})}];return t("div",{className:"w-full",children:e(N,{defaultValue:"user",tabs:d,fullWidth:!0,updateHash:!1,children:[t(w,{}),t(k,{})]})})}function Pe({}){const{user:a,isLoading:o}=E(),[r,l]=I(!1);return o?t(s,{}):a?t("div",{className:"px-3",children:t(ze,{asMenuTrigger:!0})}):e(n,{children:[t(i,{onClick:()=>l(!0),children:"Sign In"}),t(Ce,{isOpen:r,onClose:()=>l(!1)})]})}function ze({className:n,asMenuTrigger:i=!1}){const a=E(),{user:o}=a;return a&&o?e(X,{strategy:"fixed",placement:"bottom-start",zIndex:100,children:[t(X.Trigger,{click:!0,children:t("div",{className:V(n,"flex items-center justify-start",i&&"cursor-pointer"),children:t(j,{size:"sm",color:"bg-amber-500",shape:"circle",name:o?.name})})}),t(X.Content,{className:"w-[280px] mx-2 my-1",children:t("div",{className:"bg-white dark:bg-slate-900 shadow-lg rounded-md ring-1 ring-gray-200 dark:ring-slate-700",children:e("div",{className:"divide-y divide-gray-200 dark:divide-slate-700",children:[e("div",{className:"py-2 pl-2",children:[t("p",{className:"px-4 dark:text-white mb-1",children:o?.name??"Unknown"}),t("p",{className:"px-4 text-xs text-gray-500",children:o?.email??""})]}),t("div",{className:"w-full p-1",children:t(Se,{})}),t("div",{className:"py-2 pl-2",children:t(S,{})}),t("div",{className:"py-2",children:t(P,{children:t(P.Item,{className:"px-2",onClick:()=>a.logout(),children:"Sign out"})})})]})})})]}):null}function Le(e){return!!e&&(e.endsWith("@vertesiahq.com")||e.endsWith("@becomposable.com")||e.endsWith("@composableprompts.com"))}function Ie({icon:e}){const{isLoading:n}=E(),[i,a]=I(!0);return T((()=>{n||a(!1)}),[n]),t(ae,{appear:!0,show:i,as:A,unmount:!0,leave:"transition ease-in duration-500",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:t("div",{style:{zIndex:999999},className:"fixed inset-x-0 inset-y-0",children:t("div",{className:"flex w-full h-full items-center justify-center",children:t("div",{className:"animate-[spin_4s_linear_infinite]",children:t("div",{className:"animate-pulse rounded-full bg-transparent",children:e||t(Te,{})})})})})})}function Te(){return e("svg",{className:"w-8 h-8 text-indigo-600",viewBox:"0 0 50 50",xmlns:"http://www.w3.org/2000/svg",children:[t("defs",{children:e("linearGradient",{id:"spinner-gradient",x1:"1",y1:"0",x2:"0",y2:"1",children:[t("stop",{offset:"0%",stopColor:"currentColor",stopOpacity:"1"}),t("stop",{offset:"100%",stopColor:"currentColor",stopOpacity:"0"})]})}),t("circle",{cx:"25",cy:"25",r:"20",stroke:"url(#spinner-gradient)",strokeWidth:"5",fill:"none",strokeLinecap:"round"})]})}function Ae({children:n,lightLogo:i,darkLogo:a,loadingIcon:o}){return t(z,{children:t(R,{children:e(L,{defaultTheme:"system",storageKey:"vite-ui-theme",children:[t(Ie,{icon:o}),t(fe,{allowedPrefix:"/shared/",lightLogo:i,darkLogo:a}),t(ie,{children:n})]})})})}const _e=_(null);function Ue({installation:e,children:n}){return t(_e.Provider,{value:e,children:n})}function Ee(){return U(_e)}function Oe({app:n,onChange:i,placeholder:a}){const{client:o,project:r}=E(),{data:l,error:c}=f((()=>o.apps.getAppInstallationProjects(n)),[n.id,n.name]);return c?e("span",{className:"text-red-600",children:["Error: failed to fetch projects: ",c.message]}):t(De,{placeholder:a,initialValue:r?.id,projects:l||[],onChange:e=>{i&&!i(e)||(localStorage.setItem(F,e.account),localStorage.setItem(Y+"-"+e.account,e.id),window.location.reload())}})}function De({initialValue:e,projects:n,onChange:i,placeholder:a="Select Project"}){const[o,r]=I();let l=!o&&e?n.find((t=>t.id===e)):o;return t(g,{by:"id",value:l,options:n,optionLabel:e=>e.name,placeholder:a,onChange:e=>{r(e),i(e)}})}function We({name:e,AccessDenied:n=Me,children:i}){return e?t(qe,{name:e,AccessDenied:n,children:i}):t(Re,{})}function qe({name:e,AccessDenied:n=Me,children:i}){const{authToken:a,client:o}=E(),[r,l]=I(null),[c,s]=I("loading");return T((()=>{if(a){a.apps.includes(e)?o.apps.getAppInstallationByName(e).then((t=>{t?(s("loaded"),l(t)):(console.log(`App ${e} not found!`),s("error"))})):s("error")}else s("loading")}),[e,a]),"loading"===c?null:"error"===c?t(n,{name:e}):r?t(Ue,{installation:r,children:i}):void 0}function Me({name:n}){const{project:i}=E();return e(p,{className:"pt-10 flex flex-col items-center text-center text-gray-700",children:[t(ne,{className:"w-10 h-10 mb-4 text-gray-500"}),t("div",{className:"text-xl font-semibold",children:"Access Denied"}),e("div",{className:"mt-2 text-sm text-gray-500",children:["You don't have permission to view the ",t("span",{className:"font-semibold",children:n})," app in project: ",e("span",{className:"font-semibold",children:["«",i?.name,"»"]}),"."]}),t("div",{className:"mt-4",children:t(Oe,{app:{name:n},onChange:e=>{localStorage.setItem(F,e.account),localStorage.setItem(Y+"-"+e.account,e.id),window.location.reload()}})})]})}function Re(){return e(p,{className:"pt-10 flex flex-col items-center text-center text-gray-700",children:[t(ne,{className:"w-10 h-10 mb-4 text-gray-500"}),t("div",{className:"text-xl font-semibold",children:"Application not registered"}),e("div",{className:"mt-2 text-sm text-gray-500",children:["Before starting to code a Vertesia application you must register an application manifest in Vertesia Studio then install it in one or more projects.",t("p",{}),"Then use the created app name as a parameter to ",t("code",{children:'<StandaloneApp name="your-app-name">'})," in the ",t("code",{children:"src/main.tsx"})," file."]})]})}export{_e as AppInstallationContext,Ue as AppInstallationProvider,Oe as AppProjectSelector,oe as InviteAcceptModal,fe as SigninScreen,We as StandaloneApp,qe as StandaloneAppImpl,xe as TerminalLogin,Pe as UserSessionMenu,Ae as VertesiaShell,Le as isVertesiaEmail,Ee as useAppInstallation};
1
+ import{jsxs as e,jsx as t,Fragment as n}from"react/jsx-runtime";import{Button as i,VModal as a,VModalTitle as o,VModalBody as r,useToast as l,Input as c,Spinner as s,SelectStack as d,VSelectBox as m,useSafeLayoutEffect as u,ErrorBox as h,Center as p,useFetch as f,SelectBox as g,Modal as v,ModalTitle as x,ModalBody as y,ModalFooter as b,VTabs as N,VTabsBar as w,VTabsPanel as k,VTooltip as C,Avatar as j,ModeToggle as S,MenuList as P,ToastProvider as z,ThemeProvider as I}from"@vertesia/ui/core";import{useState as L,useEffect as T,Fragment as A,createContext as _,useContext as U}from"react";import{useUserSession as E,useUXTracking as O,setFirebaseTenant as D,getFirebaseAuth as W,UserNotFoundError as q,fetchComposableTokenFromFirebaseToken as M,UserSessionProvider as R,LastSelectedAccountId_KEY as F,LastSelectedProjectId_KEY as V}from"@vertesia/ui/session";import{Env as Y}from"@vertesia/ui/env";import G from"clsx";import{signInWithRedirect as B,OAuthProvider as J,GoogleAuthProvider as H,GithubAuthProvider as K,getAuth as $}from"firebase/auth";import{useLocation as Q,useNavigate as X}from"@vertesia/ui/router";import{getTenantIdFromProject as Z,Permission as ee}from"@vertesia/common";import{Popover as te}from"@vertesia/ui/widgets";import{Check as ne,CopyIcon as ie,LockIcon as ae}from"lucide-react";import{useUserPermissions as oe,UserPermissionProvider as re}from"@vertesia/ui/features";import{Transition as le}from"@headlessui/react";function ce(){const n=E(),{client:l,account:c}=n,[s,d]=L(!1),[m,u]=L([]);T((()=>{l.account.listInvites().then((e=>{if(e.length>0){const t=e.filter((e=>e.data.account));if(0===t.length)return void console.log("No valid invites found, closing modal");console.log("Found valid invites",t.length),d(!0),u(t)}else console.log("No invites found, closing modal"),d(!1)})).catch((e=>{console.error("Error fetching invites",e)}))}),[c?.id]);const h=()=>d(!1),p=m.map((a=>a.data.account?e("div",{className:"flex flex-row w-full justify-between border rounded-sm px-2 py-2 ",children:[e("div",{className:"flex flex-col",children:[t("div",{className:"w-full font-semibold",children:a.data.account.name??a.data.account}),a.data.project&&e("div",{className:"w-full text-base",children:["- ",a.data.project.name]}),e("div",{className:"text-xs",children:["Role: ",a.data.role]}),a.data.invited_by&&e("div",{className:"text-xs",children:["by ",a.data.invited_by.name??a.data.invited_by]})]}),e("div",{className:"flex flex-col gap-4",children:[t(i,{size:"xs",onClick:()=>(async e=>{await l.account.acceptInvite(e.id),await n.fetchAccounts();const t=m.filter((t=>t.id!==e.id)).filter((e=>e.data.account));t.length>0?u(t):h()})(a),children:"Accept"})," ",t(i,{size:"xs",variant:"secondary",onClick:()=>(async e=>{await l.account.rejectInvite(e.id);const t=m.filter((t=>t.id!==e.id));u(t),0===t.length&&h()})(a),children:"Reject"})]})]},a.id):(console.warn("Invite has no account data",a),null)));return t("div",{children:e(a,{isOpen:s,onClose:h,children:[t(o,{children:"Review Invites"}),e(r,{children:[t("div",{className:"text-sm pb-4",children:"You have received the following invites to join other accounts. Please review and accept or declined them."}),p]})]})})}function se({redirectTo:a}){const[o,r]=L(!1),{trackEvent:d}=O(),[m,u]=L(""),h=l();return e(n,{children:[t(c,{value:m,onChange:u,placeholder:"Enter your enterprise email",type:"email"}),o?t("div",{className:"w-full flex justify-center",children:t(s,{})}):t(i,{variant:"outline",onClick:async()=>{if(!m)return;/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(m)?(r(!0),D(m).then((e=>{if(!e)return h({title:"Tenant not found",status:"error",duration:5e3}),void r(!1);localStorage.setItem("tenantName",e.name??"");const t=function(e){if(!Y.firebase)throw new Error("Firebase configuration is not available in the environment");switch(Y.firebase.providerType){case"oidc":default:return new J("oidc.main");case"google":{let t=e||window.location.pathname||"/";"/"!==t[0]&&(t="/"+t);const n=new H;return n.addScope("profile"),n.addScope("email"),n.setCustomParameters({prompt:"select_account",redirect_uri:window.location.origin+t}),n}case"microsoft":return new J("microsoft.com");case"github":return new J("github.com")}}(a);d("enterprise_signin",{firebaseTenantName:e.name}),Y.logger.info("Enterprise single sign-in",{vertesia:{email:m,firebaseTenantName:e.name,firebaseTenantId:e.firebaseTenantId}}),B(W(),t),r(!1)}))):h({title:"Invalid email address",status:"error",duration:5e3})},className:"w-full mt-2 py-4 flex rounded-lg hover:shadow-sm transition duration-150 text-center",children:t("span",{className:"text-sm font-semibold",children:"Continue with Enterprise SSO"})})]})}function de({}){return e(i,{variant:"outline",onClick:()=>{localStorage.removeItem("tenantName");let e="https://dengenlabs.firebaseapp.com/__/auth/handler"+window.location.pathname;"/"!==e[0]&&(e="/"+e);const t=new K;t.addScope("profile"),t.addScope("email"),B(W(),t)},className:"w-full py-5 flex rounded-lg hover:shadow-sm transition duration-150 text-center mb-2",children:[t("img",{className:"size-6 bg-white rounded-full",src:"https://www.svgrepo.com/show/503359/github.svg",loading:"lazy",alt:"github logo"}),t("span",{className:"text-sm font-semibold",children:"Continue with GitHub"})]})}function me({redirectTo:n}){return e(i,{variant:"outline",onClick:()=>{localStorage.removeItem("tenantName");let e=n||window.location.pathname||"/";"/"!==e[0]&&(e="/"+e);const t=new H;t.addScope("profile"),t.addScope("email"),t.setCustomParameters({prompt:"select_account",redirect_uri:window.location.origin+e}),B(W(),t)},className:"w-full py-5 flex rounded-lg hover:shadow-sm transition duration-150 text-center mb-2",children:[t("img",{className:"size-6",src:"https://www.svgrepo.com/show/475656/google-color.svg",loading:"lazy",alt:"google logo"}),t("span",{className:"text-sm font-semibold",children:"Continue with Google"})]})}function ue({redirectTo:n}){return e(i,{variant:"outline",onClick:()=>{localStorage.removeItem("tenantName");let e=n||window.location.pathname||"/";"/"!==e[0]&&(e="/"+e);const t=new J("microsoft.com");t.addScope("profile"),t.addScope("email"),B(W(),t)},className:"w-full py-5 flex rounded-lg hover:shadow-sm transition duration-150 text-center",children:[t("img",{className:"size-6",src:"https://learn.microsoft.com/en-us/entra/identity-platform/media/howto-add-branding-in-apps/ms-symbollockup_mssymbol_19.svg",loading:"lazy",alt:"microsoft logo"}),t("span",{className:"text-sm font-semibold",children:"Continue with Microsoft"})]})}const he=[{id:1,label:"1-10 employees"},{id:11,label:"11-100 employees"},{id:101,label:"101-1000 employees"},{id:1001,label:"1001-5000 employees"},{id:5001,label:"5000+ employees"}],pe=[{id:"personal",label:"Personal",description:"For personal use, or for a small team."},{id:"company",label:"Company",description:"For a company or organization."}],fe=[{id:"testing",label:"Just Testing or Evaluating LLMs"},{id:"exploring",label:"Actively Exploring LLMs on a Project"},{id:"using",label:"Already Using LLMs in Production"},{id:"migrating",label:"Migrating to different LLMs"},{id:"other",label:"Other"}];function ge({onSignup:a,goBack:o}){const[r,l]=L(void 0),[s,u]=L(void 0),[h,p]=L(void 0),[f,g]=L(void 0),[v,x]=L(void 0),[y,b]=L(void 0),[N,w]=L(void 0),k="company"===r;T((()=>{const e=$().currentUser;e?b(e):console.error("No user found")}),[y]);return e("div",{className:"flex flex-col space-y-2",children:[e("div",{className:"prose",children:[e("p",{className:"prose text-sm text-muted pt-4",children:["Welcome to Vertesia, ",y?.displayName," (",y?.email,"). Please tell us a little bit about yourself and you'll be on your way. No credit card is required."]}),N&&t("div",{className:"text-destructive",children:N})]}),t(ve,{label:"Account Type",children:t(d,{options:pe,selected:pe.find((e=>e.id===r)),onSelect:e=>l(e.id)})}),k&&e(n,{children:[t(ve,{label:"Company Size",children:t(m,{className:"w-full border border-accent bg-muted",value:s,options:he,onChange:u,optionLabel:e=>e?.label,placeholder:"Select Company Size"})}),t(ve,{label:"Company Name",children:t(c,{value:h,onChange:p,type:"text",required:!0})}),t(ve,{label:"Company Website",children:t(c,{value:f,onChange:g,type:"text"})})]}),t(ve,{label:"Project Maturity",children:t(m,{className:"w-full border border-accent bg-muted",options:fe,value:fe.find((e=>e.id===v)),optionLabel:e=>e?.label,placeholder:"Select Project Maturity",onChange:e=>x(e?.id)})}),e("div",{className:"pt-8 flex flex-col",children:[t(i,{variant:"primary",onClick:async()=>{if(!(r?k&&!h?(w("Please enter an organization name"),0):!k||s||(w("Please select a company size"),0):(w("Please select an account type"),0)))return;if(!r)return;const e={accountType:r,companyName:h,companySize:s?.id,companyWebsite:f,maturity:v};window.localStorage.setItem("composableSignupData",JSON.stringify(e));const t=await($().currentUser?.getIdToken());console.log("Got firebase token",$(),t),t?a(e,t):console.error("No firebase token found")},size:"xl",children:t("span",{className:"text-lg",children:"Sign Up"})}),t(i,{variant:"ghost",size:"xl",className:"mt-4",onClick:o,children:t("span",{className:"",children:"Wrong account, go back"})})]})]})}function ve({label:n,children:i}){return e("div",{className:"flex flex-col space-y-2 pt-4",children:[t("div",{className:"text-sm text-muted",children:n}),i]})}function xe({allowedPrefix:e,isNested:n=!1,lightLogo:i,darkLogo:a}){const[o,r]=L(!1);return u((()=>{e&&r(window.location.href.startsWith(e))}),[]),o?null:t(ye,{isNested:n,lightLogo:i,darkLogo:a})}function ye({isNested:n=!1,lightLogo:i,darkLogo:a}){const{isLoading:o,user:r,authError:l}=E();return o||r?null:t("div",{style:{zIndex:999998},className:(n?"absolute":"fixed")+"overflow-y-auto ",children:e("div",{className:G("flex flex-col items-center justify-center py-14 px-4"),children:[t(be,{authError:l,lightLogo:i,darkLogo:a}),e("div",{className:"flex gap-x-6 mt-10 justify-center text-muted",children:[t("a",{href:"https://vertesiahq.com/privacy",className:"text-sm",children:"Privacy Policy"}),t("a",{href:"https://vertesiahq.com/terms",className:"text-sm",children:"Terms of Service"})]})]})})}function be({authError:a,darkLogo:o,lightLogo:r}){const[l,c]=L(void 0),[s,d]=L(!1),{signOut:m}=E(),{trackEvent:u}=O();history.replaceState({},"","/");const h=()=>{c(void 0),d(!0)};T((()=>{a instanceof q&&(console.log("User not found, redirecting to signup"),h())}),[a]);return e(n,{children:[r&&t("img",{src:r,alt:"logo",className:"h-15 block dark:hidden"}),o&&t("img",{src:o,alt:"logo",className:"h-15 hidden dark:block"}),l&&e("div",{className:"my-6",children:["Need to make a change?"," ",t(i,{onClick:h,children:" Go back"})]}),t("div",{className:"flex flex-col space-y-2",children:s&&!localStorage.getItem("tenantName")?t(ge,{onSignup:(e,t)=>{console.log("Got Signup data",e),c(e);const n={signupData:e,firebaseToken:t};fetch(Y.endpoints.studio+"/auth/signup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}).then((e=>{console.log("Signup successful",n,e),u("sign_up"),window.location.href="/"}))},goBack:()=>{console.log("Going back, signing out"),c(void 0),d(!1),m()}}):e("div",{className:"flex flex-col",children:[t("div",{className:"my-4",children:t("h2",{className:"text-2xl font-bold text-center",children:"Log in or Sign up"})}),e("div",{className:"max-w-2xl text-center my-2 px-2",children:["First time here? No problem, it's free to try!",t("br",{}),"We'll just ask you a couple of questions next and you'll be on your way."]}),e("div",{className:"flex items-center flex-col",children:[e("div",{className:"py-4 w-70",children:[t(me,{}),t(de,{}),t(ue,{})]}),e("div",{className:"flex items-center flex-row w-70 text-muted",children:[t("hr",{className:"w-full"}),t("div",{className:"px-2 text-xs",children:"OR"}),t("hr",{className:"w-full"})]}),t("div",{className:"py-4 w-70",children:t(se,{})})]}),a&&t("div",{className:"text-center",children:e("div",{className:"",children:["Sorry, we have not been able to sign you in.",t("br",{}),"Please try again or contact",t("a",{className:"text-info mx-1",href:"mailto:support@vertesiahq.com",children:"support@vertesiahq.com"}),"if it persists.",e("pre",{className:"mt-2",children:["Error: ",a.message]})]})})]})})]})}function Ne(){const[e,n]=L(),[i,a]=L(),o=function(e){const t=new URLSearchParams(e.search);let n=t.get("redirect_uri");const i=t.get("code");return n&&i?(n=decodeURI(n),n.startsWith("http://127.0.0.1:")||n.startsWith("http://localhost:")?{redirect:n,code:i,profile:t.get("profile")??"default",project:t.get("project")??void 0,account:t.get("account")??void 0}:null):null}(Q()),r=l(),c=async e=>{if(!o)return;if(!e.profile)return void r({title:"Profile is required",description:"Please enter a profile name to save the client authorization",status:"error",duration:2e3});if(!e.account)return void r({title:"Account is required",description:"Please select an account to authorize the client to access the ComposablePrompts servers",status:"error",duration:2e3});if(!e.project)return void r({title:"Project is required",description:"Please select a project to authorize the client to access the ComposablePrompts servers",status:"error",duration:2e3});let t;try{const i=await M(e.account,e.project,86400);i?(t={...e,studio_server_url:Y.endpoints.studio,zeno_server_url:Y.endpoints.zeno,token:i},await fetch(o.redirect,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n(t)):r({title:"Failed to get composable token",status:"error",duration:5e3})}catch(e){t?(a(e),n(t)):r({title:"Error authorizing client",description:e.message,status:"error",duration:5e3})}},s=o?e?t(ke,{payload:e,error:i}):t(we,{clientInfo:o,onAccept:c}):t(h,{title:"Invalid request",children:"This page should be called by a terminal client to authenticate against the ComposablePrompts servers"});return t("div",{className:"w-full flex flex-col items-center gap-4 mt-24",children:s})}function we({onAccept:i,clientInfo:a}){const{client:o,user:r}=E(),{data:l,error:c}=f((()=>r?o.projects.list():Promise.resolve([])),[r]);if(c)return t(h,{title:"Error loading projects",children:c.message});const d=Y.isLocalDev?"Local Dev":Y.isDev?"Staging":"Production";return r&&l?e(n,{children:[e("div",{className:"w-1/3",children:[e("div",{className:"mb-4 text-xl font-semibold text-gray-800",children:["Authorizing client on ",d," environment."]}),e("div",{className:"mb-2 text-md text-gray-800",children:[t("div",{children:"A client app wants authorization to access the composable prompt servers in your name."}),e("div",{children:["The client app code is ",t("b",{children:a.code}),". You can check if the code is correct in the terminal."]})]}),e("div",{className:"mb-2 text-sm text-gray-600",children:[t("div",{children:"You must choose the target account and project for the client to access."}),t("div",{children:"Also, enter a profile name that will be used to save the authorization in your client configuration."})]})]}),t(Ce,{onAccept:i,allProjects:l,data:a})]}):t(s,{size:"lg"})}function ke({payload:n,error:a}){const o=l();return e("div",{children:[a?e("div",{children:[e(h,{title:"Failed to send the authorization token to the cli tool",children:['This can happen due to security checks on Safari. The error is "',a.message,'"']}),t("div",{children:"Don't worry, you can still authenticate the cli tool by pasting the authentication token in the terminal. You can close this page."})]}):t("div",{children:"The client is authenticated. You can close this page."}),t(p,{className:"mt-4",children:t(i,{variant:"secondary",onClick:()=>{n&&(navigator.clipboard.writeText(JSON.stringify(n)),o({title:"Authentication Payload copied",description:a?"You can paste the authentication payload in the terminal to authenticate the client.":"You can close the page now.",status:"success",duration:5e3}))},children:"Copy the Authentication Payload"})})]})}function Ce({allProjects:n,data:a,onAccept:o}){const{accounts:r,account:l,project:s}=E(),[d,m]=L((()=>({profile:a.profile,account:a.account??l?.id,project:a.project??s?.id}))),u=n.filter((e=>e.account===d.account));return e("div",{className:"w-1/3",children:[e("div",{className:"mb-4 flex flex-col gap-2",children:[t("span",{className:"font-semibold text-gray-600",children:"Profile Name"}),t(c,{type:"text",value:d.profile,onChange:e=>{m({...d,profile:e})}})]}),e("div",{className:"mb-4 flex flex-col gap-2",children:[t("span",{className:"font-semibold text-gray-600",children:"Account"}),t(je,{value:d.account,onChange:e=>{m({...d,account:e.id,project:void 0})},accounts:r||[]})]}),e("div",{className:"mb-4 flex flex-col gap-2",children:[t("span",{className:"font-semibold text-gray-600",children:"Project"}),t(Se,{value:d.project,onChange:e=>{m({...d,project:e.id})},projects:u})]}),t("div",{className:"pt-2",children:t(i,{size:"xl",onClick:()=>o(d),children:"Authorize Client"})})]})}function je({value:e,accounts:n,onChange:i}){return t(g,{options:n,value:n?.find((t=>t.id===e)),onChange:e=>{i(e)},by:"id",optionLabel:e=>e.name,placeholder:"Select Account"})}function Se({value:e,projects:n,onChange:i}){return t(g,{by:"id",value:n.find((t=>t.id===e)),options:n,optionLabel:e=>e.name,placeholder:"Select Project",onChange:e=>{i(e)}})}function Pe({isOpen:n,onClose:a}){return e(v,{isOpen:n,onClose:a,children:[t(x,{children:"Sign In"}),e(y,{className:"flex justify-center",children:[t(me,{}),t(de,{}),t(ue,{})]}),t(b,{justify:"end",children:t(i,{variant:"ghost",onClick:a,children:"Cancel"})})]})}function ze({title:n,value:i}){const[a,o]=L(!1);return e("div",{className:"w-full flex justify-between items-center mb-1",children:[e("div",{className:"flex flex-col w-[calc(100%-3rem)]",children:[t("div",{className:"text-sm px-2 dark:text-slate-200",children:n}),t(C,{description:i,size:"xs",placement:"left",children:e("div",{className:"text-xs truncate text-muted w-full text-left px-2",children:[i," "]})})]}),a?t(ne,{className:"size-4 cursor-pointer text-success"}):t(ie,{className:"size-4 cursor-pointer text-gray-400 dark:text-slate-400",onClick:()=>function(e){navigator.clipboard.writeText(e),o(!0),setTimeout((()=>o(!1)),2e3)}(i)})]})}function Ie(){const n=E(),{account:i,project:a,client:o,authToken:r}=n,l=new URL(o.baseUrl).hostname,c=new URL(o.store.baseUrl).hostname,s=a?Z(a):"",d=[{name:"user",label:"User",content:e("div",{className:"space-y-1 p-2",children:[t(ze,{title:"Organization ID",value:i?.id??"Unknown"}),t(ze,{title:"Project ID",value:a?.id??"Unknown"}),t(ze,{title:"User ID",value:r?.sub??"Unknown"}),t(ze,{title:"Organization Roles",value:r?.account_roles?.join(",")??"Unknown"}),t(ze,{title:"Project Roles",value:r?.project_roles?.join(",")??"Unknown"})]})},{name:"environment",label:"Environment",content:e("div",{className:"space-y-1 p-2",children:[t(ze,{title:"Tenant ID",value:s}),t(ze,{title:"Environment",value:Y.type}),t(ze,{title:"Server",value:l}),t(ze,{title:"Store",value:c}),t(ze,{title:"App Version",value:Y.version}),t(ze,{title:"SDK Version",value:Y.sdkVersion||"unknown"})]})}];return t("div",{className:"w-full",children:e(N,{defaultValue:"user",tabs:d,fullWidth:!0,updateHash:!1,children:[t(w,{}),t(k,{})]})})}function Le({}){const{user:a,isLoading:o}=E(),[r,l]=L(!1);return o?t(s,{}):a?t("div",{className:"px-3",children:t(Te,{asMenuTrigger:!0})}):e(n,{children:[t(i,{onClick:()=>l(!0),children:"Sign In"}),t(Pe,{isOpen:r,onClose:()=>l(!1)})]})}function Te({className:n,asMenuTrigger:i=!1}){const a=E(),o=X(),r=oe(),{user:l}=a;if(!a||!l)return null;const c=r.hasPermission(ee.project_admin);return e(te,{strategy:"fixed",placement:"bottom-start",zIndex:100,children:[t(te.Trigger,{click:!0,children:t("div",{className:G(n,"flex items-center justify-start",i&&"cursor-pointer"),children:t(j,{size:"sm",color:"bg-amber-500",shape:"circle",name:l?.name})})}),t(te.Content,{className:"w-[280px] mx-2 my-1",children:t("div",{className:"bg-white dark:bg-slate-900 shadow-lg rounded-md ring-1 ring-gray-200 dark:ring-slate-700",children:e("div",{className:"divide-y divide-gray-200 dark:divide-slate-700",children:[e("div",{className:"py-2 pl-2",children:[t("p",{className:"px-4 dark:text-white mb-1",children:l?.name??"Unknown"}),t("p",{className:"px-4 text-xs text-gray-500",children:l?.email??""})]}),t("div",{className:"w-full p-1",children:t(Ie,{})}),t("div",{className:"py-2 pl-2",children:t(S,{})}),t("div",{className:"py-2",children:e(P,{children:[c&&t(P.Item,{className:"px-2",onClick:()=>o("/settings",{replace:!0}),children:"Settings"}),t(P.Item,{className:"px-2",onClick:()=>a.logout(),children:"Sign out"})]})})]})})})]})}function Ae(e){return!!e&&(e.endsWith("@vertesiahq.com")||e.endsWith("@becomposable.com")||e.endsWith("@composableprompts.com"))}function _e({icon:e}){const{isLoading:n}=E(),[i,a]=L(!0);return T((()=>{n||a(!1)}),[n]),t(le,{appear:!0,show:i,as:A,unmount:!0,leave:"transition ease-in duration-500",leaveFrom:"opacity-100",leaveTo:"opacity-0",children:t("div",{style:{zIndex:999999},className:"fixed inset-x-0 inset-y-0",children:t("div",{className:"flex w-full h-full items-center justify-center",children:t("div",{className:"animate-[spin_4s_linear_infinite]",children:t("div",{className:"animate-pulse rounded-full bg-transparent",children:e||t(Ue,{})})})})})})}function Ue(){return e("svg",{className:"w-8 h-8 text-indigo-600",viewBox:"0 0 50 50",xmlns:"http://www.w3.org/2000/svg",children:[t("defs",{children:e("linearGradient",{id:"spinner-gradient",x1:"1",y1:"0",x2:"0",y2:"1",children:[t("stop",{offset:"0%",stopColor:"currentColor",stopOpacity:"1"}),t("stop",{offset:"100%",stopColor:"currentColor",stopOpacity:"0"})]})}),t("circle",{cx:"25",cy:"25",r:"20",stroke:"url(#spinner-gradient)",strokeWidth:"5",fill:"none",strokeLinecap:"round"})]})}function Ee({children:n,lightLogo:i,darkLogo:a,loadingIcon:o}){return t(z,{children:t(R,{children:e(I,{defaultTheme:"system",storageKey:"vite-ui-theme",children:[t(_e,{icon:o}),t(xe,{allowedPrefix:"/shared/",lightLogo:i,darkLogo:a}),t(re,{children:n})]})})})}const Oe=_(null);function De({installation:e,children:n}){return t(Oe.Provider,{value:e,children:n})}function We(){return U(Oe)}function qe({app:n,onChange:i,placeholder:a}){const{client:o,project:r}=E(),{data:l,error:c}=f((()=>o.apps.getAppInstallationProjects(n)),[n.id,n.name]);return c?e("span",{className:"text-red-600",children:["Error: failed to fetch projects: ",c.message]}):t(Me,{placeholder:a,initialValue:r?.id,projects:l||[],onChange:e=>{i&&!i(e)||(localStorage.setItem(F,e.account),localStorage.setItem(V+"-"+e.account,e.id),window.location.reload())}})}function Me({initialValue:e,projects:n,onChange:i,placeholder:a="Select Project"}){const[o,r]=L();let l=!o&&e?n.find((t=>t.id===e)):o;return t(g,{by:"id",value:l,options:n,optionLabel:e=>e.name,placeholder:a,onChange:e=>{r(e),i(e)}})}function Re({name:e,AccessDenied:n=Ve,children:i}){return e?t(Fe,{name:e,AccessDenied:n,children:i}):t(Ye,{})}function Fe({name:e,AccessDenied:n=Ve,children:i}){const{authToken:a,client:o}=E(),[r,l]=L(null),[c,s]=L("loading");return T((()=>{if(a){a.apps.includes(e)?o.apps.getAppInstallationByName(e).then((t=>{t?(s("loaded"),l(t)):(console.log(`App ${e} not found!`),s("error"))})):s("error")}else s("loading")}),[e,a]),"loading"===c?null:"error"===c?t(n,{name:e}):r?t(De,{installation:r,children:i}):void 0}function Ve({name:n}){const{project:i}=E();return e(p,{className:"pt-10 flex flex-col items-center text-center text-gray-700",children:[t(ae,{className:"w-10 h-10 mb-4 text-gray-500"}),t("div",{className:"text-xl font-semibold",children:"Access Denied"}),e("div",{className:"mt-2 text-sm text-gray-500",children:["You don't have permission to view the ",t("span",{className:"font-semibold",children:n})," app in project: ",e("span",{className:"font-semibold",children:["«",i?.name,"»"]}),"."]}),t("div",{className:"mt-4",children:t(qe,{app:{name:n},onChange:e=>{localStorage.setItem(F,e.account),localStorage.setItem(V+"-"+e.account,e.id),window.location.reload()}})})]})}function Ye(){return e(p,{className:"pt-10 flex flex-col items-center text-center text-gray-700",children:[t(ae,{className:"w-10 h-10 mb-4 text-gray-500"}),t("div",{className:"text-xl font-semibold",children:"Application not registered"}),e("div",{className:"mt-2 text-sm text-gray-500",children:["Before starting to code a Vertesia application you must register an application manifest in Vertesia Studio then install it in one or more projects.",t("p",{}),"Then use the created app name as a parameter to ",t("code",{children:'<StandaloneApp name="your-app-name">'})," in the ",t("code",{children:"src/main.tsx"})," file."]})]})}export{Oe as AppInstallationContext,De as AppInstallationProvider,qe as AppProjectSelector,ce as InviteAcceptModal,xe as SigninScreen,Re as StandaloneApp,Fe as StandaloneAppImpl,Ne as TerminalLogin,Le as UserSessionMenu,Ee as VertesiaShell,Ae as isVertesiaEmail,We as useAppInstallation};
2
2
  //# sourceMappingURL=vertesia-ui-shell.js.map