@ai4b-team/fsaos-gateway-sdk 4.3.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/iife/ui.js CHANGED
@@ -1,3 +1,3 @@
1
- /* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-11-10T14:04:27.053Z */
1
+ /* @fsaos/ui v2.0.0 — FSAOS UI Primitives — 2026-11-12T12:16:10.312Z */
2
2
  "use strict";var __FSAOS_UI__=(()=>{var m=Object.create;var r=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var y=(e,i)=>()=>(i||e((i={exports:{}}).exports,i),i.exports),N=(e,i)=>{for(var a in i)r(e,a,{get:i[a],enumerable:!0})},s=(e,i,a,l)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of u(i))!h.call(e,t)&&t!==a&&r(e,t,{get:()=>i[t],enumerable:!(l=g(i,t))||l.enumerable});return e};var x=(e,i,a)=>(a=e!=null?m(f(e)):{},s(i||!e||!e.__esModule?r(a,"default",{value:e,enumerable:!0}):a,e)),b=e=>s(r({},"__esModule",{value:!0}),e);var d=y((V,c)=>{c.exports=React});var P={};N(P,{Badge:()=>z,Breadcrumbs:()=>A,Button:()=>D,Card:()=>w,DataView:()=>R,Detail:()=>_,Empty:()=>I,FilePreview:()=>O,Form:()=>F,Grid:()=>k,Image:()=>G,Link:()=>E,Page:()=>v,Router:()=>T,Sidebar:()=>S,Spinner:()=>B,Stack:()=>C,Table:()=>j,Tabs:()=>W,Video:()=>H});var n=x(d(),1);function o(){return(typeof window<"u"&&window.__FSAOS_CONFIG__||{}).edgeBaseUrl||""}function v(e){return(0,n.createElement)("div",{style:{minHeight:"100vh",display:"flex",flexDirection:"column"},className:e.className||""},e.children)}function C(e){let i=e.direction||"vertical";return(0,n.createElement)("div",{style:{display:"flex",flexDirection:i==="horizontal"?"row":"column",gap:e.gap||"0.5rem",padding:e.padding||"0",alignItems:e.align||"stretch",justifyContent:e.justify||"flex-start",flex:e.flex||"initial"},className:e.className||""},e.children)}function k(e){return(0,n.createElement)("div",{style:{display:"grid",gridTemplateColumns:"repeat("+(e.columns||3)+", 1fr)",gap:e.gap||"1rem",padding:e.padding||"0"},className:e.className||""},e.children)}function S(e){return(0,n.createElement)("div",{style:{display:"flex",flexDirection:"row",minHeight:"100vh"},className:e.className||""},e.children)}function w(e){return(0,n.createElement)("div",{style:{border:"1px solid var(--color-border, #e5e7eb)",borderRadius:"var(--border-radius, 0.5rem)",padding:e.padding||"1rem",background:"var(--color-surface, #fff)"},className:e.className||"",onClick:e.onClick},e.children)}function z(e){return(0,n.createElement)("span",{style:{display:"inline-flex",alignItems:"center",padding:"0.125rem 0.5rem",fontSize:"0.75rem",fontWeight:"500",borderRadius:"9999px",background:e.color||"#e5e7eb",color:e.textColor||"#374151"},className:e.className||""},e.children||e.label)}function B(e){let i=e.size||"1.5rem";return(0,n.createElement)("div",{style:{width:i,height:i,border:"2px solid #e5e7eb",borderTopColor:"var(--color-primary, #3b82f6)",borderRadius:"50%",animation:"fsaos-spin 0.6s linear infinite"}})}function D(e){return(0,n.createElement)("button",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:"500",borderRadius:"var(--border-radius, 0.375rem)",border:e.variant==="outline"?"1px solid var(--color-border, #d1d5db)":"none",background:e.variant==="outline"||e.variant==="ghost"?"transparent":"var(--color-primary, #3b82f6)",color:e.variant==="outline"||e.variant==="ghost"?"var(--color-text, #1a1a1a)":"#fff",cursor:e.disabled?"not-allowed":"pointer",opacity:e.disabled?"0.5":"1",gap:"0.5rem"},className:e.className||"",onClick:e.onClick,disabled:e.disabled},e.children||e.label)}function I(e){return(0,n.createElement)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"3rem",color:"var(--color-text-secondary, #6b7280)",textAlign:"center"}},e.icon?(0,n.createElement)("div",{style:{fontSize:"2rem",marginBottom:"0.5rem"}},e.icon):null,(0,n.createElement)("div",{style:{fontWeight:500,marginBottom:"0.25rem"}},e.title||e.message||e.children||"No items"),e.description?(0,n.createElement)("div",{style:{fontSize:"0.875rem",opacity:.7}},e.description):null)}function R(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function j(e){return(0,n.createElement)("table",{className:e.className||""},e.children)}function F(e){return(0,n.createElement)("form",{className:e.className||"",onSubmit:e.onSubmit},e.children)}function _(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function T(e){return(0,n.createElement)("div",null,e.children)}function E(e){return(0,n.createElement)("a",{href:e.href||e.to,className:e.className||"",onClick:e.onClick},e.children)}function W(e){return(0,n.createElement)("div",{className:e.className||""},e.children)}function A(e){return(0,n.createElement)("nav",{className:e.className||""},e.children)}function G(e){return(0,n.createElement)("img",{src:e.src||(e.path?o()+e.path:""),alt:e.alt||"",className:e.className||"",style:e.style})}function H(e){return(0,n.createElement)("video",{src:e.src||(e.path?o()+e.path:""),controls:!0,className:e.className||""})}function O(e){return(0,n.createElement)("div",{className:e.className||""},e.children||"File preview")}return b(P);})();
3
3
  //# sourceMappingURL=ui.js.map
package/dist/index.cjs CHANGED
@@ -125,6 +125,7 @@ __export(src_exports, {
125
125
  itemsFilterFromQueryFilter: () => itemsFilterFromQueryFilter,
126
126
  listChildren: () => listChildren,
127
127
  loadMounts: () => loadMounts,
128
+ loadPublishedBundle: () => loadPublishedBundle,
128
129
  mount: () => mount2,
129
130
  mountRealtimeScope: () => mountRealtimeScope,
130
131
  normalizeItem: () => normalizeItem,
@@ -213,6 +214,7 @@ __export(src_exports, {
213
214
  usePersonalSections: () => usePersonalSections,
214
215
  usePinnedItems: () => usePinnedItems,
215
216
  usePrincipal: () => usePrincipal,
217
+ usePublishedComponent: () => usePublishedComponent,
216
218
  useRealtimeQuery: () => useRealtimeQuery,
217
219
  useRecentActivity: () => useRecentActivity,
218
220
  useResolve: () => useResolve,
@@ -223,7 +225,6 @@ __export(src_exports, {
223
225
  useSeatMember: () => useSeatMember,
224
226
  useTheme: () => useTheme,
225
227
  useTimelineHistory: () => useTimelineHistory,
226
- useTool: () => useTool,
227
228
  useTree: () => useTree,
228
229
  useType: () => useType,
229
230
  useTypeHelpers: () => useTypeHelpers,
@@ -2556,6 +2557,204 @@ function replaceMounts(refs, anchor) {
2556
2557
  });
2557
2558
  }
2558
2559
 
2560
+ // src/ui.ts
2561
+ var ui_exports = {};
2562
+ __export(ui_exports, {
2563
+ Badge: () => Badge,
2564
+ Breadcrumbs: () => Breadcrumbs,
2565
+ Button: () => Button,
2566
+ Card: () => Card,
2567
+ DataView: () => DataView,
2568
+ Detail: () => Detail,
2569
+ Empty: () => Empty,
2570
+ FilePreview: () => FilePreview,
2571
+ Form: () => Form,
2572
+ Grid: () => Grid,
2573
+ Image: () => Image,
2574
+ Link: () => Link,
2575
+ Page: () => Page,
2576
+ Router: () => Router,
2577
+ Sidebar: () => Sidebar,
2578
+ Spinner: () => Spinner,
2579
+ Stack: () => Stack,
2580
+ Table: () => Table,
2581
+ Tabs: () => Tabs,
2582
+ Video: () => Video
2583
+ });
2584
+ function getEdgeBaseUrl() {
2585
+ const config2 = typeof window !== "undefined" && window.__FSAOS_CONFIG__ || {};
2586
+ return config2.edgeBaseUrl || "";
2587
+ }
2588
+ function Page(props) {
2589
+ return React.createElement("div", {
2590
+ style: { minHeight: "100vh", display: "flex", flexDirection: "column" },
2591
+ className: props.className || ""
2592
+ }, props.children);
2593
+ }
2594
+ function Stack(props) {
2595
+ const dir = props.direction || "vertical";
2596
+ return React.createElement("div", {
2597
+ style: {
2598
+ display: "flex",
2599
+ flexDirection: dir === "horizontal" ? "row" : "column",
2600
+ gap: props.gap || "0.5rem",
2601
+ padding: props.padding || "0",
2602
+ alignItems: props.align || "stretch",
2603
+ justifyContent: props.justify || "flex-start",
2604
+ flex: props.flex || "initial"
2605
+ },
2606
+ className: props.className || ""
2607
+ }, props.children);
2608
+ }
2609
+ function Grid(props) {
2610
+ return React.createElement("div", {
2611
+ style: {
2612
+ display: "grid",
2613
+ gridTemplateColumns: "repeat(" + (props.columns || 3) + ", 1fr)",
2614
+ gap: props.gap || "1rem",
2615
+ padding: props.padding || "0"
2616
+ },
2617
+ className: props.className || ""
2618
+ }, props.children);
2619
+ }
2620
+ function Sidebar(props) {
2621
+ return React.createElement("div", {
2622
+ style: { display: "flex", flexDirection: "row", minHeight: "100vh" },
2623
+ className: props.className || ""
2624
+ }, props.children);
2625
+ }
2626
+ function Card(props) {
2627
+ return React.createElement("div", {
2628
+ style: {
2629
+ border: "1px solid var(--color-border, #e5e7eb)",
2630
+ borderRadius: "var(--border-radius, 0.5rem)",
2631
+ padding: props.padding || "1rem",
2632
+ background: "var(--color-surface, #fff)"
2633
+ },
2634
+ className: props.className || "",
2635
+ onClick: props.onClick
2636
+ }, props.children);
2637
+ }
2638
+ function Badge(props) {
2639
+ return React.createElement("span", {
2640
+ style: {
2641
+ display: "inline-flex",
2642
+ alignItems: "center",
2643
+ padding: "0.125rem 0.5rem",
2644
+ fontSize: "0.75rem",
2645
+ fontWeight: "500",
2646
+ borderRadius: "9999px",
2647
+ background: props.color || "#e5e7eb",
2648
+ color: props.textColor || "#374151"
2649
+ },
2650
+ className: props.className || ""
2651
+ }, props.children || props.label);
2652
+ }
2653
+ function Spinner(props) {
2654
+ const size = props.size || "1.5rem";
2655
+ return React.createElement("div", {
2656
+ style: {
2657
+ width: size,
2658
+ height: size,
2659
+ border: "2px solid #e5e7eb",
2660
+ borderTopColor: "var(--color-primary, #3b82f6)",
2661
+ borderRadius: "50%",
2662
+ animation: "fsaos-spin 0.6s linear infinite"
2663
+ }
2664
+ });
2665
+ }
2666
+ function Button(props) {
2667
+ return React.createElement("button", {
2668
+ style: {
2669
+ display: "inline-flex",
2670
+ alignItems: "center",
2671
+ justifyContent: "center",
2672
+ padding: "0.5rem 1rem",
2673
+ fontSize: "0.875rem",
2674
+ fontWeight: "500",
2675
+ borderRadius: "var(--border-radius, 0.375rem)",
2676
+ border: props.variant === "outline" ? "1px solid var(--color-border, #d1d5db)" : "none",
2677
+ background: props.variant === "outline" || props.variant === "ghost" ? "transparent" : "var(--color-primary, #3b82f6)",
2678
+ color: props.variant === "outline" || props.variant === "ghost" ? "var(--color-text, #1a1a1a)" : "#fff",
2679
+ cursor: props.disabled ? "not-allowed" : "pointer",
2680
+ opacity: props.disabled ? "0.5" : "1",
2681
+ gap: "0.5rem"
2682
+ },
2683
+ className: props.className || "",
2684
+ onClick: props.onClick,
2685
+ disabled: props.disabled
2686
+ }, props.children || props.label);
2687
+ }
2688
+ function Empty(props) {
2689
+ return React.createElement(
2690
+ "div",
2691
+ {
2692
+ style: {
2693
+ display: "flex",
2694
+ flexDirection: "column",
2695
+ alignItems: "center",
2696
+ justifyContent: "center",
2697
+ padding: "3rem",
2698
+ color: "var(--color-text-secondary, #6b7280)",
2699
+ textAlign: "center"
2700
+ }
2701
+ },
2702
+ props.icon ? React.createElement("div", { style: { fontSize: "2rem", marginBottom: "0.5rem" } }, props.icon) : null,
2703
+ React.createElement(
2704
+ "div",
2705
+ { style: { fontWeight: 500, marginBottom: "0.25rem" } },
2706
+ props.title || props.message || props.children || "No items"
2707
+ ),
2708
+ props.description ? React.createElement("div", { style: { fontSize: "0.875rem", opacity: 0.7 } }, props.description) : null
2709
+ );
2710
+ }
2711
+ function DataView(props) {
2712
+ return React.createElement("div", { className: props.className || "" }, props.children);
2713
+ }
2714
+ function Table(props) {
2715
+ return React.createElement("table", { className: props.className || "" }, props.children);
2716
+ }
2717
+ function Form(props) {
2718
+ return React.createElement("form", { className: props.className || "", onSubmit: props.onSubmit }, props.children);
2719
+ }
2720
+ function Detail(props) {
2721
+ return React.createElement("div", { className: props.className || "" }, props.children);
2722
+ }
2723
+ function Router(props) {
2724
+ return React.createElement("div", null, props.children);
2725
+ }
2726
+ function Link(props) {
2727
+ return React.createElement("a", {
2728
+ href: props.href || props.to,
2729
+ className: props.className || "",
2730
+ onClick: props.onClick
2731
+ }, props.children);
2732
+ }
2733
+ function Tabs(props) {
2734
+ return React.createElement("div", { className: props.className || "" }, props.children);
2735
+ }
2736
+ function Breadcrumbs(props) {
2737
+ return React.createElement("nav", { className: props.className || "" }, props.children);
2738
+ }
2739
+ function Image(props) {
2740
+ return React.createElement("img", {
2741
+ src: props.src || (props.path ? getEdgeBaseUrl() + props.path : ""),
2742
+ alt: props.alt || "",
2743
+ className: props.className || "",
2744
+ style: props.style
2745
+ });
2746
+ }
2747
+ function Video(props) {
2748
+ return React.createElement("video", {
2749
+ src: props.src || (props.path ? getEdgeBaseUrl() + props.path : ""),
2750
+ controls: true,
2751
+ className: props.className || ""
2752
+ });
2753
+ }
2754
+ function FilePreview(props) {
2755
+ return React.createElement("div", { className: props.className || "" }, props.children || "File preview");
2756
+ }
2757
+
2559
2758
  // src/mounted-reader-events.ts
2560
2759
  function inMountedReadScope(event) {
2561
2760
  if (typeof event.path !== "string") return false;
@@ -3496,7 +3695,6 @@ function useAsset(idOrPath) {
3496
3695
  return { data, loading, error };
3497
3696
  }
3498
3697
  var componentCache = {};
3499
- var componentCssCache = {};
3500
3698
  registerCleanup(() => {
3501
3699
  for (const key of Object.keys(componentCache)) {
3502
3700
  delete componentCache[key];
@@ -3521,9 +3719,11 @@ function sdkRequireShim(name) {
3521
3719
  return typeof window !== "undefined" && window.React ? { jsx: window.React.createElement, jsxs: window.React.createElement, Fragment: window.React.Fragment } : JsxRuntime__namespace;
3522
3720
  case "@fsaos/gateway":
3523
3721
  case "@fsaos/react":
3722
+ case "@ai4b-team/fsaos-gateway-sdk":
3524
3723
  return typeof window !== "undefined" && window.__FSAOS_GATEWAY__ || _sdkExports || {};
3525
3724
  case "@fsaos/ui":
3526
- return typeof window !== "undefined" && window.__FSAOS_UI__ || {};
3725
+ case "@ai4b-team/fsaos-gateway-sdk/ui":
3726
+ return typeof window !== "undefined" && window.__FSAOS_UI__ || ui_exports;
3527
3727
  case "@fsaos/theme":
3528
3728
  return {};
3529
3729
  default:
@@ -3531,30 +3731,42 @@ function sdkRequireShim(name) {
3531
3731
  return {};
3532
3732
  }
3533
3733
  }
3534
- function scopeComponentCss(cssText, scopeClass) {
3535
- return cssText.replace(
3536
- /^(\s*)(:root|body)(\s*[{,])/gm,
3537
- (_match, ws2, _sel, rest) => `${ws2}.${scopeClass}${rest}`
3538
- );
3539
- }
3540
- async function loadComponentCss(cssUrl, scopeId) {
3541
- if (componentCssCache[cssUrl]) return;
3734
+ var componentCss = {};
3735
+ async function fetchComponentCss(cssUrl) {
3542
3736
  try {
3543
3737
  const response = await fetch(cssUrl);
3544
- if (!response.ok) return;
3545
- let cssText = await response.text();
3546
- if (!cssText.trim()) return;
3547
- if (cssText.includes("No CSS bundle for this component")) return;
3548
- if (scopeId && !cssText.includes(`.fsaos-c-${scopeId}`)) ;
3549
- const style = document.createElement("style");
3550
- style.setAttribute("data-fsaos-component-css", cssUrl);
3551
- if (scopeId) ;
3552
- style.textContent = cssText;
3553
- document.head.appendChild(style);
3554
- componentCssCache[cssUrl] = style;
3738
+ if (!response.ok) return null;
3739
+ const cssText = await response.text();
3740
+ if (!cssText.trim()) return null;
3741
+ if (cssText.includes("No CSS bundle for this component")) return null;
3742
+ return cssText;
3555
3743
  } catch {
3744
+ return null;
3556
3745
  }
3557
3746
  }
3747
+ async function holdComponentCss(cssUrl, text = () => fetchComponentCss(cssUrl)) {
3748
+ let entry = componentCss[cssUrl];
3749
+ if (!entry) {
3750
+ entry = componentCss[cssUrl] = { users: 0, text: text(), style: null };
3751
+ }
3752
+ entry.users += 1;
3753
+ const cssText = await entry.text;
3754
+ if (componentCss[cssUrl] !== entry || entry.users === 0 || entry.style || !cssText) return;
3755
+ if (typeof document === "undefined") return;
3756
+ const style = document.createElement("style");
3757
+ style.setAttribute("data-fsaos-component-css", cssUrl);
3758
+ style.textContent = cssText;
3759
+ document.head.appendChild(style);
3760
+ entry.style = style;
3761
+ }
3762
+ function releaseComponentCss(cssUrl) {
3763
+ const entry = componentCss[cssUrl];
3764
+ if (!entry) return;
3765
+ entry.users -= 1;
3766
+ if (entry.users > 0) return;
3767
+ entry.style?.remove();
3768
+ delete componentCss[cssUrl];
3769
+ }
3558
3770
  function evaluateBundle(jsCode) {
3559
3771
  let registered = null;
3560
3772
  const previousRegister = window.__FSAOS_REGISTER__;
@@ -3580,65 +3792,84 @@ function evaluateBundle(jsCode) {
3580
3792
  }
3581
3793
  }
3582
3794
  }
3583
- function useComponent(path) {
3795
+ function useComponent(path, options) {
3584
3796
  const [Component, setComponent] = React.useState(null);
3585
3797
  const [loading, setLoading] = React.useState(true);
3586
3798
  const [error, setError] = React.useState(null);
3799
+ const shown = React.useRef(null);
3800
+ const pinnedVersion = Number.isSafeInteger(options?.version) && options.version > 0 ? options.version : null;
3587
3801
  React.useEffect(() => {
3588
3802
  if (!path) return;
3589
3803
  let cancelled = false;
3590
- setLoading(true);
3591
3804
  setError(null);
3805
+ if (shown.current?.path !== path) {
3806
+ if (shown.current?.cssUrl) releaseComponentCss(shown.current.cssUrl);
3807
+ shown.current = null;
3808
+ setComponent(null);
3809
+ setLoading(true);
3810
+ }
3592
3811
  const config2 = typeof window !== "undefined" && window.__FSAOS_CONFIG__ || {};
3593
3812
  const edgeBaseUrl = config2.edgeBaseUrl || "";
3594
3813
  (async () => {
3814
+ let heldCssUrl = null;
3595
3815
  try {
3596
3816
  let version = 1;
3597
3817
  let cacheKey = path + "@v1";
3598
3818
  let bundleUrl = edgeBaseUrl + path + "/__bundle.js";
3599
- try {
3600
- const metaResponse = await fetch(edgeBaseUrl + path + "/__meta", { cache: "no-store" });
3601
- if (metaResponse.ok) {
3602
- const meta = await metaResponse.json();
3603
- version = meta.version || 1;
3604
- cacheKey = path + "@v" + version;
3605
- bundleUrl = edgeBaseUrl + path + "/__bundle.v" + version + ".js";
3819
+ if (pinnedVersion !== null) {
3820
+ version = pinnedVersion;
3821
+ cacheKey = path + "@v" + version;
3822
+ bundleUrl = edgeBaseUrl + path + "/__bundle.v" + version + ".js";
3823
+ } else {
3824
+ try {
3825
+ const metaResponse = await fetch(edgeBaseUrl + path + "/__meta", { cache: "no-store" });
3826
+ if (metaResponse.ok) {
3827
+ const meta = await metaResponse.json();
3828
+ version = meta.version || 1;
3829
+ cacheKey = path + "@v" + version;
3830
+ bundleUrl = edgeBaseUrl + path + "/__bundle.v" + version + ".js";
3831
+ }
3832
+ } catch {
3833
+ bundleUrl = edgeBaseUrl + path + "/__bundle.js?v=" + Date.now();
3606
3834
  }
3607
- } catch {
3608
- bundleUrl = edgeBaseUrl + path + "/__bundle.js?v=" + Date.now();
3609
- }
3610
- if (cancelled) return;
3611
- if (componentCache[cacheKey]) {
3612
- setComponent(() => componentCache[cacheKey]);
3613
- setLoading(false);
3614
- return;
3615
- }
3616
- const jsResponse = await fetch(bundleUrl);
3617
- if (!jsResponse.ok) {
3618
- throw new Error(
3619
- `Failed to fetch bundle: ${jsResponse.status} ${jsResponse.statusText} (${bundleUrl})`
3620
- );
3621
3835
  }
3622
- const jsCode = await jsResponse.text();
3623
3836
  if (cancelled) return;
3624
3837
  const cssUrl = bundleUrl.replace(/__bundle(\.v\d+)?\.js(\?.*)?$/, "__bundle$1.css");
3625
- loadComponentCss(cssUrl).catch(() => {
3626
- });
3627
- const resolved = evaluateBundle(jsCode);
3838
+ heldCssUrl = cssUrl;
3839
+ const cssReady = holdComponentCss(cssUrl);
3840
+ let resolved = componentCache[cacheKey];
3628
3841
  if (!resolved) {
3629
- throw new Error(
3630
- "Bundle did not export a component. Expected window.__FSAOS_COMPONENT__ (FSAOS build) or a __FSAOS_REGISTER__(Component) call."
3631
- );
3632
- }
3633
- if (typeof resolved !== "function") {
3634
- throw new Error(`Bundle export is not a React component (got ${typeof resolved})`);
3842
+ const jsResponse = await fetch(bundleUrl);
3843
+ if (!jsResponse.ok) {
3844
+ throw new Error(
3845
+ `Failed to fetch bundle: ${jsResponse.status} ${jsResponse.statusText} (${bundleUrl})`
3846
+ );
3847
+ }
3848
+ const jsCode = await jsResponse.text();
3849
+ resolved = evaluateBundle(jsCode);
3850
+ if (!resolved) {
3851
+ throw new Error(
3852
+ "Bundle did not export a component. Expected window.__FSAOS_COMPONENT__ (FSAOS build) or a __FSAOS_REGISTER__(Component) call."
3853
+ );
3854
+ }
3855
+ if (typeof resolved !== "function") {
3856
+ throw new Error(`Bundle export is not a React component (got ${typeof resolved})`);
3857
+ }
3858
+ componentCache[cacheKey] = resolved;
3635
3859
  }
3636
- componentCache[cacheKey] = resolved;
3637
- if (!cancelled) {
3638
- setComponent(() => resolved);
3639
- setLoading(false);
3860
+ await cssReady;
3861
+ if (cancelled) {
3862
+ releaseComponentCss(cssUrl);
3863
+ return;
3640
3864
  }
3865
+ const previousCssUrl = shown.current?.cssUrl ?? null;
3866
+ shown.current = { path, cssUrl };
3867
+ heldCssUrl = null;
3868
+ setComponent(() => resolved);
3869
+ setLoading(false);
3870
+ if (previousCssUrl) releaseComponentCss(previousCssUrl);
3641
3871
  } catch (err) {
3872
+ if (heldCssUrl) releaseComponentCss(heldCssUrl);
3642
3873
  if (!cancelled) {
3643
3874
  setError(err instanceof Error ? err : new Error(String(err)));
3644
3875
  setLoading(false);
@@ -3648,9 +3879,179 @@ function useComponent(path) {
3648
3879
  return () => {
3649
3880
  cancelled = true;
3650
3881
  };
3651
- }, [path]);
3882
+ }, [path, pinnedVersion]);
3883
+ React.useEffect(() => () => {
3884
+ if (shown.current?.cssUrl) releaseComponentCss(shown.current.cssUrl);
3885
+ shown.current = null;
3886
+ }, []);
3652
3887
  return { Component, loading, error };
3653
3888
  }
3889
+ var IN_APP_SCRIPT = "embed/bundle.js";
3890
+ var IN_APP_STYLESHEET = "embed/bundle.css";
3891
+ var publishedBundles = /* @__PURE__ */ new Map();
3892
+ var publishedComponents = /* @__PURE__ */ new Map();
3893
+ registerCleanup(() => {
3894
+ publishedBundles.clear();
3895
+ publishedComponents.clear();
3896
+ });
3897
+ function plainRecord(value) {
3898
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
3899
+ }
3900
+ function liveRelease(source) {
3901
+ const published = plainRecord(plainRecord(source.type_data).published);
3902
+ const releaseItemId = published.published_release_item_id;
3903
+ const version = published.published_version;
3904
+ if (typeof releaseItemId !== "string" || !releaseItemId) return null;
3905
+ if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 1) return null;
3906
+ return { releaseItemId, version };
3907
+ }
3908
+ async function readSealedFile(file, sha256, what) {
3909
+ const envelope = await fetchOpenEnvelope(file.path, { mode: "render" });
3910
+ const url = plainRecord(plainRecord(envelope.render).props).url;
3911
+ if (typeof url !== "string" || !url) throw new Error(`The published ${what} could not be opened.`);
3912
+ const response = await fetch(url);
3913
+ if (!response.ok) {
3914
+ throw new Error(`Failed to read the published ${what}: ${response.status} ${response.statusText}`.trim());
3915
+ }
3916
+ const bytes = await response.arrayBuffer();
3917
+ const digest = Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes))).map((byte) => byte.toString(16).padStart(2, "0")).join("");
3918
+ if (digest !== sha256) throw new Error(`The published ${what} does not match the bytes its release sealed.`);
3919
+ return new TextDecoder().decode(bytes);
3920
+ }
3921
+ async function readPublishedBundle(componentId, releaseItemId, version) {
3922
+ const release = await fetchVfsItemById(releaseItemId);
3923
+ if (!release) throw new Error("The published release could not be read.");
3924
+ const record = plainRecord(release.type_data);
3925
+ if (release.item_type !== "revdev_release" || record.component_item_id !== componentId || record.status !== "committed" || Number(record.version) !== version) {
3926
+ throw new Error("This component's live version does not match its release record.");
3927
+ }
3928
+ const artifacts = plainRecord(record.artifacts);
3929
+ const scriptSha = plainRecord(artifacts[IN_APP_SCRIPT]).sha256;
3930
+ if (typeof scriptSha !== "string" || !scriptSha) return { status: "no_in_app_version", releaseItemId, version };
3931
+ const stylesheetSha = plainRecord(artifacts[IN_APP_STYLESHEET]).sha256;
3932
+ const wanted = typeof stylesheetSha === "string" && stylesheetSha ? [IN_APP_SCRIPT, IN_APP_STYLESHEET] : [IN_APP_SCRIPT];
3933
+ const buildItemId = record.build_item_id;
3934
+ if (typeof buildItemId !== "string" || !buildItemId) throw new Error("The published release names no build.");
3935
+ const { items } = await fetchItems(
3936
+ { type: "file", parent_id: buildItemId, field_in: { package_path: wanted }, limit: wanted.length },
3937
+ { throwOnError: true }
3938
+ );
3939
+ const fileAt = (path) => items.find((item) => plainRecord(item.type_data).package_path === path);
3940
+ const scriptFile = fileAt(IN_APP_SCRIPT);
3941
+ const stylesheetFile = wanted.length > 1 ? fileAt(IN_APP_STYLESHEET) : void 0;
3942
+ if (!scriptFile || wanted.length > 1 && !stylesheetFile) {
3943
+ throw new Error("The published release's in-app files could not be found in its build.");
3944
+ }
3945
+ const [script, stylesheet] = await Promise.all([
3946
+ readSealedFile(scriptFile, scriptSha, "script"),
3947
+ stylesheetFile ? readSealedFile(stylesheetFile, stylesheetSha, "stylesheet") : Promise.resolve(null)
3948
+ ]);
3949
+ return { status: "ready", releaseItemId, version, script, stylesheet: stylesheet?.trim() ? stylesheet : null };
3950
+ }
3951
+ function publishedBundle(componentId, releaseItemId, version) {
3952
+ let pending3 = publishedBundles.get(releaseItemId);
3953
+ if (!pending3) {
3954
+ pending3 = readPublishedBundle(componentId, releaseItemId, version);
3955
+ publishedBundles.set(releaseItemId, pending3);
3956
+ pending3.catch(() => {
3957
+ if (publishedBundles.get(releaseItemId) === pending3) publishedBundles.delete(releaseItemId);
3958
+ });
3959
+ }
3960
+ return pending3;
3961
+ }
3962
+ function loadPublishedBundle(source) {
3963
+ const live = liveRelease(source);
3964
+ if (!source.id || !live) return Promise.resolve({ status: "unpublished" });
3965
+ return publishedBundle(source.id, live.releaseItemId, live.version);
3966
+ }
3967
+ function usePublishedComponent(item) {
3968
+ const [onScreen, setOnScreen] = React.useState(null);
3969
+ const [status, setStatus] = React.useState("loading");
3970
+ const [error, setError] = React.useState(null);
3971
+ const shown = React.useRef(null);
3972
+ const known = item != null;
3973
+ const componentId = item?.id || null;
3974
+ const live = item ? liveRelease(item) : null;
3975
+ const releaseItemId = live?.releaseItemId ?? null;
3976
+ const version = live?.version ?? null;
3977
+ React.useEffect(() => {
3978
+ if (!known) return;
3979
+ const takeDown = () => {
3980
+ if (shown.current?.cssKey) releaseComponentCss(shown.current.cssKey);
3981
+ shown.current = null;
3982
+ setOnScreen(null);
3983
+ };
3984
+ if (!componentId || !releaseItemId || version === null) {
3985
+ takeDown();
3986
+ setError(null);
3987
+ setStatus("unpublished");
3988
+ return;
3989
+ }
3990
+ let cancelled = false;
3991
+ setError(null);
3992
+ if (shown.current && shown.current.componentId !== componentId) takeDown();
3993
+ if (!shown.current) setStatus("loading");
3994
+ (async () => {
3995
+ let heldCssKey = null;
3996
+ try {
3997
+ const bundle = await publishedBundle(componentId, releaseItemId, version);
3998
+ if (cancelled) return;
3999
+ if (bundle.status !== "ready") {
4000
+ takeDown();
4001
+ setStatus(bundle.status);
4002
+ return;
4003
+ }
4004
+ let resolved = publishedComponents.get(releaseItemId);
4005
+ if (!resolved) {
4006
+ resolved = evaluateBundle(bundle.script);
4007
+ if (!resolved) {
4008
+ throw new Error(
4009
+ "The published script did not hand over a component. Expected a __FSAOS_REGISTER__(Component) call or window.__FSAOS_COMPONENT__."
4010
+ );
4011
+ }
4012
+ if (typeof resolved !== "function") {
4013
+ throw new Error(`The published script handed over something that is not a React component (${typeof resolved}).`);
4014
+ }
4015
+ publishedComponents.set(releaseItemId, resolved);
4016
+ }
4017
+ const cssKey = bundle.stylesheet ? `release:${releaseItemId}` : null;
4018
+ if (cssKey) {
4019
+ heldCssKey = cssKey;
4020
+ await holdComponentCss(cssKey, async () => bundle.stylesheet);
4021
+ }
4022
+ if (cancelled) {
4023
+ if (heldCssKey) releaseComponentCss(heldCssKey);
4024
+ return;
4025
+ }
4026
+ const previousCssKey = shown.current?.cssKey ?? null;
4027
+ shown.current = { componentId, releaseItemId, cssKey };
4028
+ heldCssKey = null;
4029
+ setOnScreen({ Component: resolved, version });
4030
+ setStatus("ready");
4031
+ if (previousCssKey) releaseComponentCss(previousCssKey);
4032
+ } catch (err) {
4033
+ if (heldCssKey) releaseComponentCss(heldCssKey);
4034
+ if (cancelled) return;
4035
+ setError(err instanceof Error ? err : new Error(String(err)));
4036
+ if (!shown.current) setStatus("error");
4037
+ }
4038
+ })();
4039
+ return () => {
4040
+ cancelled = true;
4041
+ };
4042
+ }, [known, componentId, releaseItemId, version]);
4043
+ React.useEffect(() => () => {
4044
+ if (shown.current?.cssKey) releaseComponentCss(shown.current.cssKey);
4045
+ shown.current = null;
4046
+ }, []);
4047
+ return {
4048
+ Component: onScreen?.Component ?? null,
4049
+ status,
4050
+ error,
4051
+ /** The version on screen. */
4052
+ version: onScreen?.version ?? null
4053
+ };
4054
+ }
3654
4055
  var THEME_PROPERTIES = [
3655
4056
  "--color-primary",
3656
4057
  "--color-secondary",
@@ -3822,9 +4223,6 @@ function usePrincipal() {
3822
4223
  error: null
3823
4224
  };
3824
4225
  }
3825
- function useTool() {
3826
- return { data: null, loading: false, error: null };
3827
- }
3828
4226
  function ComponentRenderer(props) {
3829
4227
  const { path, ...rest } = props;
3830
4228
  const result = useComponent(path);
@@ -6479,6 +6877,7 @@ exports.isScopeReady = isScopeReady;
6479
6877
  exports.itemsFilterFromQueryFilter = itemsFilterFromQueryFilter;
6480
6878
  exports.listChildren = listChildren;
6481
6879
  exports.loadMounts = loadMounts;
6880
+ exports.loadPublishedBundle = loadPublishedBundle;
6482
6881
  exports.mount = mount2;
6483
6882
  exports.mountRealtimeScope = mountRealtimeScope;
6484
6883
  exports.normalizeItem = normalizeItem;
@@ -6567,6 +6966,7 @@ exports.usePersonalItemOrder = usePersonalItemOrder;
6567
6966
  exports.usePersonalSections = usePersonalSections;
6568
6967
  exports.usePinnedItems = usePinnedItems;
6569
6968
  exports.usePrincipal = usePrincipal;
6969
+ exports.usePublishedComponent = usePublishedComponent;
6570
6970
  exports.useRealtimeQuery = useRealtimeQuery;
6571
6971
  exports.useRecentActivity = useRecentActivity;
6572
6972
  exports.useResolve = useResolve;
@@ -6577,7 +6977,6 @@ exports.useSearch = useSearch;
6577
6977
  exports.useSeatMember = useSeatMember;
6578
6978
  exports.useTheme = useTheme;
6579
6979
  exports.useTimelineHistory = useTimelineHistory;
6580
- exports.useTool = useTool;
6581
6980
  exports.useTree = useTree;
6582
6981
  exports.useType = useType;
6583
6982
  exports.useTypeHelpers = useTypeHelpers;