@capytale/iframe-react 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),C=require("react");const X=Symbol("Comlink.proxy"),mt=Symbol("Comlink.endpoint"),vt=Symbol("Comlink.releaseProxy"),N=Symbol("Comlink.finalizer"),V=Symbol("Comlink.thrown"),Z=t=>typeof t=="object"&&t!==null||typeof t=="function",pt={canHandle:t=>Z(t)&&t[X],serialize(t){const{port1:e,port2:n}=new MessageChannel;return z(t,e),[n,[n]]},deserialize(t){return t.start(),nt(t)}},Ct={canHandle:t=>Z(t)&&V in t,serialize({value:t}){let e;return t instanceof Error?e={isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:e={isError:!1,value:t},[e,[]]},deserialize(t){throw t.isError?Object.assign(new Error(t.value.message),t.value):t.value}},tt=new Map([["proxy",pt],["throw",Ct]]);function yt(t,e){for(const n of t)if(e===n||n==="*"||n instanceof RegExp&&n.test(e))return!0;return!1}function z(t,e=globalThis,n=["*"]){e.addEventListener("message",function r(o){if(!o||!o.data)return;if(!yt(n,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}const{id:i,type:u,path:l}=Object.assign({path:[]},o.data),g=(o.data.argumentList||[]).map(J);let f;try{const d=l.slice(0,-1).reduce((p,S)=>p[S],t),m=l.reduce((p,S)=>p[S],t);switch(u){case"GET":f=m;break;case"SET":d[l.slice(-1)[0]]=J(o.data.value),f=!0;break;case"APPLY":f=m.apply(d,g);break;case"CONSTRUCT":{const p=new m(...g);f=st(p)}break;case"ENDPOINT":{const{port1:p,port2:S}=new MessageChannel;z(t,S),f=ht(p,[p])}break;case"RELEASE":f=void 0;break;default:return}}catch(d){f={value:d,[V]:0}}Promise.resolve(f).catch(d=>({value:d,[V]:0})).then(d=>{const[m,p]=O(d);e.postMessage(Object.assign(Object.assign({},m),{id:i}),p),u==="RELEASE"&&(e.removeEventListener("message",r),et(e),N in t&&typeof t[N]=="function"&&t[N]())}).catch(d=>{const[m,p]=O({value:new TypeError("Unserializable return value"),[V]:0});e.postMessage(Object.assign(Object.assign({},m),{id:i}),p)})}),e.start&&e.start()}function St(t){return t.constructor.name==="MessagePort"}function et(t){St(t)&&t.close()}function nt(t,e){const n=new Map;return t.addEventListener("message",function(o){const{data:i}=o;if(!i||!i.id)return;const u=n.get(i.id);if(u)try{u(i)}finally{n.delete(i.id)}}),H(t,n,[],e)}function M(t){if(t)throw new Error("Proxy has been released and is not useable")}function ot(t){return k(t,new Map,{type:"RELEASE"}).then(()=>{et(t)})}const j=new WeakMap,I="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(j.get(t)||0)-1;j.set(t,e),e===0&&ot(t)});function wt(t,e){const n=(j.get(e)||0)+1;j.set(e,n),I&&I.register(t,e,t)}function At(t){I&&I.unregister(t)}function H(t,e,n=[],r=function(){}){let o=!1;const i=new Proxy(r,{get(u,l){if(M(o),l===vt)return()=>{At(i),ot(t),e.clear(),o=!0};if(l==="then"){if(n.length===0)return{then:()=>i};const g=k(t,e,{type:"GET",path:n.map(f=>f.toString())}).then(J);return g.then.bind(g)}return H(t,e,[...n,l])},set(u,l,g){M(o);const[f,d]=O(g);return k(t,e,{type:"SET",path:[...n,l].map(m=>m.toString()),value:f},d).then(J)},apply(u,l,g){M(o);const f=n[n.length-1];if(f===mt)return k(t,e,{type:"ENDPOINT"}).then(J);if(f==="bind")return H(t,e,n.slice(0,-1));const[d,m]=Q(g);return k(t,e,{type:"APPLY",path:n.map(p=>p.toString()),argumentList:d},m).then(J)},construct(u,l){M(o);const[g,f]=Q(l);return k(t,e,{type:"CONSTRUCT",path:n.map(d=>d.toString()),argumentList:g},f).then(J)}});return wt(i,t),i}function bt(t){return Array.prototype.concat.apply([],t)}function Q(t){const e=t.map(O);return[e.map(n=>n[0]),bt(e.map(n=>n[1]))]}const rt=new WeakMap;function ht(t,e){return rt.set(t,e),t}function st(t){return Object.assign(t,{[X]:!0})}function Ft(t,e=globalThis,n="*"){return{postMessage:(r,o)=>t.postMessage(r,n,o),addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}}function O(t){for(const[e,n]of tt)if(n.canHandle(t)){const[r,o]=n.serialize(t);return[{type:"HANDLER",name:e,value:r},o]}return[{type:"RAW",value:t},rt.get(t)||[]]}function J(t){switch(t.type){case"HANDLER":return tt.get(t.name).deserialize(t.value);case"RAW":return t.value}}function k(t,e,n,r){return new Promise(o=>{const i=Et();e.set(i,o),t.start&&t.start(),t.postMessage(Object.assign({id:i},n),r)})}function Et(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function Jt(t,e){return t.length===0?e:`[${t}] ${e}`}function Tt(t,e){let n=!1,r,o,i;function u(d){return Jt(t,d)}let l,g=!1;if(window.parent===window)console.warn(u("Contract link is not supported in standalone mode")),l={ready(){return Promise.resolve()},declare(){return Promise.resolve()},done(){return Promise.resolve()},provide(d,m,p){return Promise.resolve()}};else{const d=Ft(window.parent,void 0,e);z({declare(m){if(r==null)throw new Error(u("No handler for declare"));r(m)},done(){if(o==null)throw new Error(u("No handler for done"));o()},provide(m,p,S){if(i==null)throw new Error(u("No handler for provide"));i(m,p,S)}},d),l=nt(d),g=!0}const f=()=>{if(!n){if(r==null||o==null||i==null)return;n=!0,l.ready()}};return{declare:d=>l.declare(d),done:()=>l.done(),provide:(d,m,p)=>l.provide(d,m,st(p)),get name(){return t},get isReady(){return g},set onDeclare(d){r=d,f()},set onDone(d){o=d,f()},set onProvide(d){i=d,f()}}}function Rt(t){return function(e){let n,r=!1,o=!1,i,u,l=!1,g=!1,f,d,m,p;function S(){if(i!=null&&i!==0&&u!=null)return u}function F(a){if(i!=null&&u!=null&&!(a>i))return u}function b(){return m??(g?m=Promise.resolve():m=new Promise((a,c)=>{p=a}))}function T(){return f===void 0&&(f={get name(){return e},get version(){return i},get i(){return S()},v:a=>F(a)}),f}function x(){return d===void 0&&(d={get name(){return e},get version(){return g?i:void 0},get i(){return g?S():void 0},v:a=>g?F(a):void 0,get promise(){return i===0?Promise.reject(t("Remote interface not provided")):b().then(()=>{if(i===0)throw new Error(t("Remote interface not provided"));return T()})}}),d}function E(){p!=null&&(p(),p=void 0)}return{get name(){return e},get localVersion(){if(n!=null)return n},set localVersion(a){if(n!=null&&n!==a)throw new Error(t("A different local version is already set"));n=a},get localVersionSent(){return r},set localVersionSent(a){if(!a&&r)throw new Error(t("Local version already notified"));r=a,a&&n===0&&(o=!0)},get localInterfaceSent(){return o},set localInterfaceSent(a){if(n==null)throw new Error(t("Local version not set"));if(!a&&o)throw new Error(t("Local interface already sent."));o=a},get remoteVersion(){if(i!=null)return i},set remoteVersion(a){if(i!=null&&i!==a)throw new Error(t("A different remote version is already set for "+e+`(${i} -> ${a})`));i=a,a===0&&(l=!0)},get remoteVersionReceived(){return i!=null},setRemoteInterface:a=>{if(i==null)throw new Error(t("Remote version not set"));if(i===0){console.warn(t("Remote version is 0, remote interface is ignored."));return}if(l)throw new Error(t("Interface already provided."));u=a,l=!0},get remoteInterfaceReceived(){return l},depGroup:void 0,get isActivable(){return l&&o},get isActivated(){return g},activate(){if(!g){if(!l)throw new Error(t("Remote interface not provided."));if(!o)throw new Error(t("Local interface not sent"));g=!0,E()}},getRemote:()=>T(),getLazyRemote:()=>x(),get activationPromise(){return b()}}}}function kt(t){return function(e,n,r,o){let i=r,u=!1,l=!1;function g(){return e.every(f=>f.remoteVersionReceived&&f.localVersionSent)&&n.every(f=>f.remoteVersionReceived)}return{get isDeclared(){return l},set isDeclared(f){if(!f&&l)throw new Error(t("Factory already declared"));l=f},get isReady(){return g()},get isDone(){return u},get args(){return e},get deps(){return n},invoke(){if(u)throw new Error(t("Factory already invoked"));if(!g())throw new Error(t("Factory is not ready"));let f;o?f=e.map(p=>p.getRemote()):f=e[0].getRemote();let d;const m=n.length>0?n.map(p=>p.getRemote()):null;try{d=m==null?i(f):i(f,m)}catch(p){throw new Error(t("error in factory:"),{cause:p})}if(o||(d=[d]),d.length!=e.length)throw new Error(t("Invalid factory result"));return u=!0,i=null,d}}}}function xt(t){return function(e,n,r,o){let i=n,u=!1;function l(){return e.every(g=>g.isActivated)}return{get isReady(){return l()},get isDone(){return u},get args(){return e},invoke(){if(u||!l()){const d=new Error(t(u?"callback already invoked":"callback parameters are not ready"));throw o?.[1](d),d}const g=r?e.map(d=>d.getRemote()):e[0].getRemote();let f;try{f=i(g)}catch(d){o==null?console.error(t("error in callback:"),d):o[1](d)}finally{u=!0}o?.[0](f)}}}}function it(t,e){return t==null||t.length===0?e:`[${t}] ${e}`}function Lt(t){function e(a){return it(t.name,a)}const n=xt(e),r=Rt(e),o=kt(e),i={},u=[];let l=[],g;const f=()=>(g==null?g=0:g++,g);function d(a){let c=i[a];return c==null&&(c=r(a),c.localVersion==null&&(b&&(c.localVersion=0),T&&(c.localVersionSent=!0)),c.remoteVersion==null&&x&&(c.remoteVersion=0),i[a]=c),c}function m(a){return a.map(d)}function p(...a){const c=f(),v=Array(c).fill(!1);a.forEach(y=>{y.forEach(w=>{w.depGroup!=null&&(v[w.depGroup]=!0),w.depGroup=c})}),Object.values(i).forEach(y=>{y.depGroup!=null&&y.depGroup!==c&&v[y.depGroup]&&(y.depGroup=c)})}t.onDeclare=a=>{const c=m(a.map(v=>v.name));for(let v=0;v<a.length;v++)a[v].version!=null&&(c[v].remoteVersion=a[v].version);p(c),E()},t.onDone=()=>{x||(x=!0,Object.values(i).forEach(a=>{a.remoteVersion==null&&(a.remoteVersion=0)}),E())},t.onProvide=(a,c,v)=>{let y=i[a];if(y==null)throw new Error(e(`Contract not declared : ${a}`));if(y.remoteVersion!=c)throw new Error(e(`Remote declared version ${y.remoteVersion} of contract "${a}" but provided version ${c}.`));if(y.remoteInterfaceReceived)throw new Error(e(`Remote contract "${a}" is already provided.`));y.setRemoteInterface(v),E()};let S=!1,F=!1,b=!1,T=!1,x=!1;async function E(){if(F=!0,!S){for(S=!0;F;){if(F=!1,t.isReady){const a=u.filter(c=>!c.isDeclared);if(a.length>0)for(const c of a){const v=Array(c.args.length+c.deps.length);c.args.forEach((y,w)=>v[w]=y),c.deps.forEach((y,w)=>v[w+c.args.length]=y),await t.declare(v.map(y=>({name:y.name,version:y.localVersion}))),v.forEach(y=>{y.localVersion!=null&&(y.localVersionSent=!0)}),c.isDeclared=!0}}if(t.isReady&&b&&u.every(a=>a.isDeclared)){const a=Object.values(i).filter(c=>!c.localVersionSent&&c.localVersion!=null);if(a.length>0)for(const c of a)await t.declare([{name:c.name,version:c.localVersion}]),c.localVersionSent=!0;T||(T=!0,await t.done())}if(t.isReady){const a=u.filter(c=>!c.isDone&&c.isReady);if(a.length>0)for(const c of a){const v=c.invoke();for(let y=0;y<c.args.length;y++){const w=c.args[y];await t.provide(w.name,w.localVersion,v[y]),w.localInterfaceSent=!0}}}if(g!=null){const a=Array(g+1).fill(null);for(const c in i){const v=i[c];v.depGroup!=null&&(v.isActivable?a[v.depGroup]==null&&!v.isActivated&&(a[v.depGroup]=!0):a[v.depGroup]=!1)}if(a.some(c=>c===!0))for(const c in i){const v=i[c];v.depGroup!=null&&a[v.depGroup]&&v.activate()}}if(t.isReady){const a=l;l=[];const c=[];for(const v of a)!v.isDone&&v.isReady?v.invoke():c.push(v);c.push(...l),l=c}}S=!1}}return{get(a){return d(a)},declareFactory:(a,c,v,y)=>{if(b)throw new Error(e("Cannot declare a factory after done has been set to true."));const w=m(a.map(h=>h.name));{const h=w.filter($=>$.localVersion!=null);if(h.length>0)throw new Error(e("Cannot declare a factory for already implemented contracts : "+h.map($=>$.name).join(", ")))}for(let h=0;h<a.length;h++)w[h].localVersion=a[h].version;const R=m(c);p(w,R);const gt=o(w,R,v,y);u.push(gt),E()},declareCallback(a,c,v,y){const w=m(a),R=n(w,c,v,y);!S&&l.length===0&&R.isReady?R.invoke():(l.push(R),E())},get done(){return b},set done(a){if(b){if(!a)throw new Error(e("Cannot set done to false after it has been set to true."))}else a&&(b=!0,Object.values(i).forEach(c=>{c.localVersion==null&&(c.localVersion=0)}),E())}}}const Mt=/^\d+$/;function Pt(t){const[e,n,r]=t.split(":",3);if(n==null||r!=null||!Mt.test(n))return null;const o=parseInt(n);return isNaN(o)||o===0?null:{name:e,version:o}}function Gt(t){const e=Lt(t);function n(r){return it(t.name,r)}return{plug(r,o,i=void 0){if(e.done)throw new Error(n("Cannot plug after plugsDone."));i==null&&(i=o,o=[]);let u=!0;Array.isArray(r)||(r=[r],u=!1);const l=r.map(g=>{const f=Pt(g);if(f==null)throw new Error(n("Invalid contract id : "+g));return f});e.declareFactory(l,o,i,u)},plugsDone(){e.done=!0},use(r,o){let i=!0;Array.isArray(r)||(r=[r],i=!1),e.declareCallback(r,o,i)},exec(r,o){let i=!0;return Array.isArray(r)||(r=[r],i=!1),new Promise((...u)=>{e.declareCallback(r,o,i,u)})},get(r){return r.map(o=>e.get(o).getLazyRemote())}}}const at="app-agent";let q;function Dt(t){return q!=null||(q=Gt(Tt(at,t))),q}console.log(`[${at}@1.0.12] loaded`);const _=t=>{let e;const n=new Set,r=(f,d)=>{const m=typeof f=="function"?f(e):f;if(!Object.is(m,e)){const p=e;e=d??(typeof m!="object"||m===null)?m:Object.assign({},e,m),n.forEach(S=>S(e,p))}},o=()=>e,l={setState:r,getState:o,getInitialState:()=>g,subscribe:f=>(n.add(f),()=>n.delete(f))},g=e=t(r,o,l);return l},Vt=(t=>t?_(t):_),jt=t=>t;function It(t,e=jt){const n=C.useSyncExternalStore(t.subscribe,C.useCallback(()=>e(t.getState()),[t,e]),C.useCallback(()=>e(t.getInitialState()),[t,e]));return C.useDebugValue(n),n}const U=t=>{const e=Vt(t),n=r=>It(e,r);return Object.assign(n,e),n},lt=(t=>t?U(t):U),Ot=t=>(e,n,r)=>{const o=r.subscribe;return r.subscribe=((u,l,g)=>{let f=u;if(l){const d=g?.equalityFn||Object.is;let m=u(r.getState());f=p=>{const S=u(p);if(!d(m,S)){const F=m;l(m=S,F)}},g?.fireImmediately&&l(m,m)}return o(f)}),t(e,n,r)},$t=Ot,s=lt()($t(t=>({ready:!1,workflow:"current",mode:"assignment",theme:"light",saveCount:0,canSave:!1,afterSaveCount:0,isDirtyCount:0,loadedTextContent:null,loadedJsonContent:null,loadedJsonActivityContent:null,loadedJsonAssignmentContent:null,loadedJsonActivityBinaryData:null,loadedJsonAssignmentBinaryData:null,getTextContentFunction:()=>{throw console.error("[React bindings] getTextContentFunction is not set"),new Error("[React bindings] getTextContentFunction is not set")},getJsonContentFunction:()=>{throw console.error("[React bindings] getJsonContentFunction is not set"),new Error("[React bindings] getJsonContentFunction is not set")},getJsonActivityContentFunction:()=>{throw console.error("[React bindings] getJsonActivityContentFunction is not set"),new Error("[React bindings] getJsonActivityContentFunction is not set")},getJsonAssignmentContentFunction:()=>{throw console.error("[React bindings] getJsonAssignmentContentFunction is not set"),new Error("[React bindings] getJsonAssignmentContentFunction is not set")},getJsonActivitySplitContentFunction:()=>{throw console.error("[React bindings] getJsonActivitySplitContentFunction is not set"),new Error("[React bindings] getJsonActivitySplitContentFunction is not set")},getJsonAssignmentSplitContentFunction:()=>{throw console.error("[React bindings] getJsonAssignmentSplitContentFunction is not set"),new Error("[React bindings] getJsonAssignmentSplitContentFunction is not set")},sidebarActions:{},quickActions:{},activitySettingsCallback:null,llmGetFirstMessageContextFunction:null,setLlmGetFirstMessageContextFunction:e=>{t({llmGetFirstMessageContextFunction:e})},llmGetAllMessagesContextFunction:null,setLlmGetAllMessagesContextFunction:e=>{t({llmGetAllMessagesContextFunction:e})},llmGetAvailableToolsFunction:null,setLlmGetAvailableToolsFunction:e=>{t({llmGetAvailableToolsFunction:e})},llmCallToolFunction:null,setLlmCallToolFunction:e=>{t({llmCallToolFunction:e})},setGetTextContentFunction:e=>{t({getTextContentFunction:e})},llmDescribeToolFunction:null,setLlmDescribeToolFunction:e=>{t({llmDescribeToolFunction:e})},setGetJsonContentFunction:e=>{t({getJsonContentFunction:e})},setGetJsonActivityContentFunction:e=>{t({getJsonActivityContentFunction:e})},setGetJsonAssignmentContentFunction:e=>{t({getJsonAssignmentContentFunction:e})},setGetJsonActivitySplitContentFunction:e=>{t({getJsonActivitySplitContentFunction:e})},setGetJsonAssignmentSplitContentFunction:e=>{t({getJsonAssignmentSplitContentFunction:e})},setSidebarActions:e=>{t({sidebarActions:e})},setQuickActions:e=>{t({quickActions:e})},setActivitySettingsCallback:e=>{t({activitySettingsCallback:e})},incSaveCount:()=>t(e=>({saveCount:e.saveCount+1})),incDirtyCount:()=>t(e=>({isDirtyCount:e.isDirtyCount+1})),previewStartPreviewFunction:null,previewStopPreviewFunction:null,setPreviewStartPreviewFunction:e=>{t({previewStartPreviewFunction:e})},setPreviewStopPreviewFunction:e=>{t({previewStopPreviewFunction:e})}})));let Y=!1;const Nt=["meta-player-events:1","meta-player-ui:1","mode:1","reload:1","theme:1","workflow:1","trigger-save:1","simple-content(text):1","simple-content(json):1","simple-binary-data(text):1","simple-content-eval(text):1","simple-content-eval(json):1","separate-contents(json):1","separate-dual-contents(json):1","llm:1"],K={"mode:1":{setMode:t=>{s.setState({mode:t})}},"reload:1":{reloaded:t=>{console.log("[React bindings] Reloaded with state:",t),console.error("[React bindings] Not implemented yet")}},"theme:1":{setTheme:t=>{if(t===null){s.setState({theme:null});return}if(t!=="light"&&t!=="dark"){console.warn(`[React bindings] Invalid theme: ${t}. Expected 'light' or 'dark'.`),s.setState({theme:null});return}s.setState({theme:t})}},"workflow:1":{setWorkflow:t=>{s.setState({workflow:t})}},"workflow:2":{setWorkflow:t=>{s.setState({workflow:t})}},"trigger-save:1":{setCanSave(t){s.setState({canSave:t})}},"simple-content(text):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getTextContentFunction(),loadContent:t=>{s.setState({loadedTextContent:t})}},"simple-content(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getJsonContentFunction(),loadContent:t=>{s.setState({loadedJsonContent:t})}},"simple-binary-data(text):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getTextContentFunction(),loadContent:t=>{s.setState({loadedTextContent:t})}},"simple-content-eval(text):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getTextContentFunction(),loadContent:t=>{s.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getJsonContentFunction(),loadContent:t=>{s.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(json):2":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getJsonContentFunction(),loadContent:t=>{s.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(text):2":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getTextContentFunction(),loadContent:t=>{s.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"separate-contents(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{s.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>s.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>s.getState().getJsonAssignmentContentFunction()},"separate-contents-eval(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{s.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>s.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>s.getState().getJsonAssignmentContentFunction()},"separate-contents-eval(json):2":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{s.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>s.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>s.getState().getJsonAssignmentContentFunction()},"separate-dual-contents(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:({activityContent:t,assignmentContent:e,activityBinaryData:n,assignmentBinaryData:r})=>{s.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e,loadedJsonActivityBinaryData:n,loadedJsonAssignmentBinaryData:r})},getActivityContentAndData:()=>s.getState().getJsonActivitySplitContentFunction(),getAssignmentContentAndData:()=>s.getState().getJsonAssignmentSplitContentFunction()},"anti-cheat:1":{lock:()=>{},unlock:()=>{}},"meta-player-ui:1":{executeAction(t){if(t.startsWith("qa")){const n=s.getState().quickActions[t];n?n():console.error(`[React bindings] Quick action not found: ${t}`)}else{const n=s.getState().sidebarActions[t];n?n():console.error(`[React bindings] Sidebar action not found: ${t}`)}},executeFileUpload(t,e){if(t.startsWith("qa")){const r=s.getState().quickActions[t];r?r(e):console.error(`[React bindings] Quick action not found: ${t}`)}else{const r=s.getState().sidebarActions[t];r?r(e):console.error(`[React bindings] Sidebar action not found: ${t}`)}},updateSettings(t){const e=s.getState().activitySettingsCallback;e?e(t):console.warn("activitySettingsCallback is not set. Changes:",t)}},"meta-player-events:1":{handleEvent(t){t==="all-loaded"&&s.setState({ready:!0})}},"llm:1":{getFirstMessageContext:t=>{const e=s.getState().llmGetFirstMessageContextFunction;return e?e(t):""},getAllMessagesContext:t=>{const e=s.getState().llmGetAllMessagesContextFunction;return e?e(t):""},getAvailableTools:t=>{const e=s.getState().llmGetAvailableToolsFunction;return e?e(t):[]},callTool:(t,e,n)=>{const r=s.getState().llmCallToolFunction;if(!r)throw new Error("LLM call tool function is not set");return r(t,e,n)},getToolCallDescription:(t,e,n)=>{const r=s.getState().llmDescribeToolFunction;if(!r)throw new Error("LLM describe tool function is not set");return r(t,e,n)}},"preview:1":{startPreview:()=>{const t=s.getState().previewStartPreviewFunction;return t?t():!1},stopPreview:()=>{const t=s.getState().previewStopPreviewFunction;if(!t)throw new Error("Preview stop function is not set");return t()}}},A=Dt();function qt(t){if(!Y){Y=!0;for(const e of t){if(!Nt.includes(e))continue;if(!(e in K)){console.warn(`[React bindings] Contract handler for ${e} is not defined. Skipping plug.`);continue}const n=K[e];A.plug([e],([])=>[n])}A.plugsDone();for(const e of["simple-content(text):1","simple-content(json):1","simple-binary-data(text):1","simple-content-eval(text):1","simple-content-eval(json):1","simple-content-eval(json):2","simple-content-eval(text):2","separate-contents(json):1","separate-dual-contents(json):1"])if(t.includes(e)){const n=e.split(":")[0];A.use([n],([r])=>{s.subscribe(o=>o.isDirtyCount,()=>{r.i?.contentChanged()})})}}}const Bt=()=>s(t=>{if(t.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return t.mode}),Wt=()=>s(t=>{if(t.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return t.workflow}),Ht=()=>s(t=>{if(t.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return t.theme}),zt=()=>s(t=>t.incSaveCount),Qt=()=>s(t=>t.incDirtyCount),_t=()=>s(t=>t.loadedTextContent),Ut=()=>s(t=>t.loadedJsonContent),Yt=()=>s(t=>t.loadedJsonActivityContent),Kt=()=>s(t=>t.loadedJsonAssignmentContent),Xt=()=>s(t=>t.loadedJsonActivityBinaryData),Zt=()=>s(t=>t.loadedJsonAssignmentBinaryData),te=()=>C.useCallback(()=>s.getState().loadedTextContent,[]),ee=()=>C.useCallback(()=>s.getState().loadedJsonContent,[]),ne=()=>C.useCallback(()=>s.getState().loadedJsonActivityContent,[]),oe=()=>C.useCallback(()=>s.getState().loadedJsonAssignmentContent,[]),re=()=>C.useCallback(()=>({content:s.getState().loadedJsonActivityContent,binaryData:s.getState().loadedJsonActivityBinaryData}),[]),se=()=>C.useCallback(()=>({content:s.getState().loadedJsonAssignmentContent,binaryData:s.getState().loadedJsonAssignmentBinaryData}),[]),ie=t=>{const e=s(n=>n.setGetTextContentFunction);C.useEffect(()=>{e(t)},[t,e])},ae=t=>{const e=s(n=>n.setGetJsonContentFunction);C.useEffect(()=>{e(t)},[t,e])},le=t=>{const e=s(n=>n.setGetJsonActivityContentFunction);C.useEffect(()=>{e(t)},[t,e])},ce=t=>{const e=s(n=>n.setGetJsonAssignmentContentFunction);C.useEffect(()=>{e(t)},[t,e])},ue=t=>{const e=s(n=>n.setGetJsonActivitySplitContentFunction);C.useEffect(()=>{e(t)},[t,e])},de=t=>{const e=s(n=>n.setGetJsonAssignmentSplitContentFunction);C.useEffect(()=>{e(t)},[t,e])},fe=t=>{const e=s(n=>n.afterSaveCount);C.useEffect(()=>{e>0&&t()},[e])},ge=()=>(t,e)=>{A.use(["meta-player-ui"],([n])=>{if(n.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}n.i?.previewTextFile(t,e)})},me=()=>(t,e)=>{A.use(["meta-player-ui"],([n])=>{if(n.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}n.i?.previewImageFile(t,e)})};let P=0,B=0;const ve=(t,e)=>{const n=C.useMemo(t,e),r=s(o=>o.setSidebarActions);C.useEffect(()=>(P++,P>1&&console.error("[React bindings] Capytale iframe React: Multiple sidebar actions registered: ",P),()=>{P--}),[]),C.useEffect(()=>(A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}B++;const i=n.map((l,g)=>({type:l.type,title:l.title,icon:l.icon,id:`sa-${B}-${g}`,...l.type==="file-upload"?{accept:l.accept}:{}})),u={};n.forEach((l,g)=>{u[`sa-${B}-${g}`]=l.action}),o.i?.setSidebarActionButtons(i),r(u)}),()=>{r({}),A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}o.i?.setSidebarActionButtons([])})}),[n])};let G=0,W=0;const pe=(t,e)=>{const n=C.useMemo(t,e),r=s(o=>o.setQuickActions);C.useEffect(()=>(G++,G>1&&console.error("[React bindings] Capytale iframe React: Multiple quick actions registered: ",G),()=>{G--}),[]),C.useEffect(()=>(A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}W++;const i=n.map((l,g)=>({type:l.type,title:l.title,icon:l.icon,id:`qa-${W}-${g}`,...l.type==="file-upload"?{accept:l.accept}:{}})),u={};n.forEach((l,g)=>{u[`qa-${W}-${g}`]=l.action}),o.i?.setQuickActionButtons(i),r(u)}),()=>{r({}),A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}o.i?.setQuickActionButtons([])})}),[n])};let D=0;const ct=(t,e,n)=>{const r=C.useMemo(t,n),o=s(i=>i.setActivitySettingsCallback);C.useEffect(()=>(D++,D>1&&console.error("[React bindings] Capytale iframe React: Multiple settings registered: ",D),()=>{D--}),[]),C.useEffect(()=>(A.use(["meta-player-ui"],([i])=>{if(i.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}i.i?.setSettingsUI(r)}),o(e),()=>{o(null)}),[r])},ut=()=>C.useCallback(e=>A.exec(["meta-player-ui"],([n])=>{if(n.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"),new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return n.i?.showToast(e)}),[]),dt=()=>C.useCallback(e=>A.exec(["meta-player-ui"],([n])=>{if(n.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"),new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return n.i?.clearToast(e)}),[]),Ce=()=>C.useCallback(()=>A.exec(["meta-player-ui"],([e])=>{if(e.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"),new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return e.i?.clearToasts()}),[]),ft=(t,e)=>{const n=ut(),r=dt();return C.useEffect(()=>{if(t==null)return;const o=n(t);return()=>{o.then(i=>{i!=null&&r(i)})}},[n,r,...e]),null},ye=()=>C.useCallback(()=>A.exec(["trigger-save"],([e])=>{if(e.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat trigger-save"),new Error("Le MétaPlayer ne supporte pas le contrat trigger-save");return e.i?.triggerSave()}),[]),Se=()=>s(t=>t.canSave),we=(t,e)=>{const n=s(r=>r.setLlmGetFirstMessageContextFunction);C.useEffect(()=>(n(t),()=>{n(null)}),[e,n])},Ae=(t,e)=>{const n=s(r=>r.setLlmGetAllMessagesContextFunction);C.useEffect(()=>(n(t),()=>{n(null)}),[e,n])},be=(t,e,n,r)=>{const o=s(l=>l.setLlmGetAvailableToolsFunction),i=s(l=>l.setLlmCallToolFunction),u=s(l=>l.setLlmDescribeToolFunction);C.useEffect(()=>(o(t),i(e),u(n),()=>{o(null),i(null),u(null)}),[r,o,i,u])};function he(t){const e={};for(const n of t.fields)e[n.name]=n.defaultValue;return e}function Fe(t){return{[t.name]:t.defaultValues}}function Ee(t){return{[t.name]:t.defaultValue}}function Je(t){switch(t.type){case"form":return he(t);case"checkboxes":case"switches":return Fe(t);case"radio":return Ee(t);default:return{}}}function Te(t){const e={};for(const n of t)Object.assign(e,Je(n));return e}function Re(t){const n=lt()(r=>({...Te(t)}));return n.activitySettings=t,n}function ke(t){ct(()=>t.activitySettings,e=>{t.setState(e)},[])}function xe({store:t}){return ke(t),null}const Le=["meta-player-events:1","meta-player-ui:1","mode:1","workflow:1"];function Me({children:t,contracts:e,loadOnlyWhenReady:n=!0,activitySettingsStore:r}){const o=s(i=>i.ready);return C.useEffect(()=>{const i=[...e];for(const u of Le)i.includes(u)||i.push(u);qt(i)},[]),n&&!o?L.jsx("div",{className:"capy-loading-container",children:"Chargement en cours..."}):L.jsxs(L.Fragment,{children:[r&&L.jsx(xe,{store:r}),t]})}function Pe({message:t}){return ft(t,[t]),null}exports.Capytale=Me;exports.TemporaryToast=Pe;exports.createActivitySettingsStore=Re;exports.useAfterSaveAction=fe;exports.useCanSave=Se;exports.useClearToast=dt;exports.useClearToasts=Ce;exports.useGetLoadedJsonActivityContent=ne;exports.useGetLoadedJsonActivitySplitContent=re;exports.useGetLoadedJsonAssignmentContent=oe;exports.useGetLoadedJsonAssignmentSplitContent=se;exports.useGetLoadedJsonContent=ee;exports.useGetLoadedTextContent=te;exports.useJsonActivityContentSaveFunction=le;exports.useJsonActivitySplitContentSaveFunction=ue;exports.useJsonAssignmentContentSaveFunction=ce;exports.useJsonAssignmentSplitContentSaveFunction=de;exports.useJsonContentSaveFunction=ae;exports.useLLMAllMessagesContext=Ae;exports.useLLMFirstMessageContext=we;exports.useLLMTools=be;exports.useLoadedJsonActivityBinaryData=Xt;exports.useLoadedJsonActivityContent=Yt;exports.useLoadedJsonAssignmentBinaryData=Zt;exports.useLoadedJsonAssignmentContent=Kt;exports.useLoadedJsonContent=Ut;exports.useLoadedTextContent=_t;exports.useMode=Bt;exports.useNotifyIsDirty=Qt;exports.usePreviewImageFile=me;exports.usePreviewTextFile=ge;exports.useQuickActions=pe;exports.useRequestSave=zt;exports.useSettings=ct;exports.useShowToast=ut;exports.useSidebarActions=ve;exports.useTextContentSaveFunction=ie;exports.useTheme=Ht;exports.useToast=ft;exports.useTriggerSave=ye;exports.useWorkflow=Wt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),C=require("react");const X=Symbol("Comlink.proxy"),vt=Symbol("Comlink.endpoint"),mt=Symbol("Comlink.releaseProxy"),N=Symbol("Comlink.finalizer"),V=Symbol("Comlink.thrown"),Z=t=>typeof t=="object"&&t!==null||typeof t=="function",pt={canHandle:t=>Z(t)&&t[X],serialize(t){const{port1:e,port2:n}=new MessageChannel;return z(t,e),[n,[n]]},deserialize(t){return t.start(),nt(t)}},Ct={canHandle:t=>Z(t)&&V in t,serialize({value:t}){let e;return t instanceof Error?e={isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:e={isError:!1,value:t},[e,[]]},deserialize(t){throw t.isError?Object.assign(new Error(t.value.message),t.value):t.value}},tt=new Map([["proxy",pt],["throw",Ct]]);function yt(t,e){for(const n of t)if(e===n||n==="*"||n instanceof RegExp&&n.test(e))return!0;return!1}function z(t,e=globalThis,n=["*"]){e.addEventListener("message",function r(o){if(!o||!o.data)return;if(!yt(n,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}const{id:i,type:u,path:c}=Object.assign({path:[]},o.data),g=(o.data.argumentList||[]).map(J);let f;try{const d=c.slice(0,-1).reduce((p,S)=>p[S],t),v=c.reduce((p,S)=>p[S],t);switch(u){case"GET":f=v;break;case"SET":d[c.slice(-1)[0]]=J(o.data.value),f=!0;break;case"APPLY":f=v.apply(d,g);break;case"CONSTRUCT":{const p=new v(...g);f=st(p)}break;case"ENDPOINT":{const{port1:p,port2:S}=new MessageChannel;z(t,S),f=ht(p,[p])}break;case"RELEASE":f=void 0;break;default:return}}catch(d){f={value:d,[V]:0}}Promise.resolve(f).catch(d=>({value:d,[V]:0})).then(d=>{const[v,p]=O(d);e.postMessage(Object.assign(Object.assign({},v),{id:i}),p),u==="RELEASE"&&(e.removeEventListener("message",r),et(e),N in t&&typeof t[N]=="function"&&t[N]())}).catch(d=>{const[v,p]=O({value:new TypeError("Unserializable return value"),[V]:0});e.postMessage(Object.assign(Object.assign({},v),{id:i}),p)})}),e.start&&e.start()}function St(t){return t.constructor.name==="MessagePort"}function et(t){St(t)&&t.close()}function nt(t,e){const n=new Map;return t.addEventListener("message",function(o){const{data:i}=o;if(!i||!i.id)return;const u=n.get(i.id);if(u)try{u(i)}finally{n.delete(i.id)}}),H(t,n,[],e)}function M(t){if(t)throw new Error("Proxy has been released and is not useable")}function ot(t){return k(t,new Map,{type:"RELEASE"}).then(()=>{et(t)})}const j=new WeakMap,I="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(j.get(t)||0)-1;j.set(t,e),e===0&&ot(t)});function wt(t,e){const n=(j.get(e)||0)+1;j.set(e,n),I&&I.register(t,e,t)}function At(t){I&&I.unregister(t)}function H(t,e,n=[],r=function(){}){let o=!1;const i=new Proxy(r,{get(u,c){if(M(o),c===mt)return()=>{At(i),ot(t),e.clear(),o=!0};if(c==="then"){if(n.length===0)return{then:()=>i};const g=k(t,e,{type:"GET",path:n.map(f=>f.toString())}).then(J);return g.then.bind(g)}return H(t,e,[...n,c])},set(u,c,g){M(o);const[f,d]=O(g);return k(t,e,{type:"SET",path:[...n,c].map(v=>v.toString()),value:f},d).then(J)},apply(u,c,g){M(o);const f=n[n.length-1];if(f===vt)return k(t,e,{type:"ENDPOINT"}).then(J);if(f==="bind")return H(t,e,n.slice(0,-1));const[d,v]=Q(g);return k(t,e,{type:"APPLY",path:n.map(p=>p.toString()),argumentList:d},v).then(J)},construct(u,c){M(o);const[g,f]=Q(c);return k(t,e,{type:"CONSTRUCT",path:n.map(d=>d.toString()),argumentList:g},f).then(J)}});return wt(i,t),i}function bt(t){return Array.prototype.concat.apply([],t)}function Q(t){const e=t.map(O);return[e.map(n=>n[0]),bt(e.map(n=>n[1]))]}const rt=new WeakMap;function ht(t,e){return rt.set(t,e),t}function st(t){return Object.assign(t,{[X]:!0})}function Ft(t,e=globalThis,n="*"){return{postMessage:(r,o)=>t.postMessage(r,n,o),addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}}function O(t){for(const[e,n]of tt)if(n.canHandle(t)){const[r,o]=n.serialize(t);return[{type:"HANDLER",name:e,value:r},o]}return[{type:"RAW",value:t},rt.get(t)||[]]}function J(t){switch(t.type){case"HANDLER":return tt.get(t.name).deserialize(t.value);case"RAW":return t.value}}function k(t,e,n,r){return new Promise(o=>{const i=Et();e.set(i,o),t.start&&t.start(),t.postMessage(Object.assign({id:i},n),r)})}function Et(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function Jt(t,e){return t.length===0?e:`[${t}] ${e}`}function Tt(t,e){let n=!1,r,o,i;function u(d){return Jt(t,d)}let c,g=!1;if(window.parent===window)console.warn(u("Contract link is not supported in standalone mode")),c={ready(){return Promise.resolve()},declare(){return Promise.resolve()},done(){return Promise.resolve()},provide(d,v,p){return Promise.resolve()}};else{const d=Ft(window.parent,void 0,e);z({declare(v){if(r==null)throw new Error(u("No handler for declare"));r(v)},done(){if(o==null)throw new Error(u("No handler for done"));o()},provide(v,p,S){if(i==null)throw new Error(u("No handler for provide"));i(v,p,S)}},d),c=nt(d),g=!0}const f=()=>{if(!n){if(r==null||o==null||i==null)return;n=!0,c.ready()}};return{declare:d=>c.declare(d),done:()=>c.done(),provide:(d,v,p)=>c.provide(d,v,st(p)),get name(){return t},get isReady(){return g},set onDeclare(d){r=d,f()},set onDone(d){o=d,f()},set onProvide(d){i=d,f()}}}function Rt(t){return function(e){let n,r=!1,o=!1,i,u,c=!1,g=!1,f,d,v,p;function S(){if(i!=null&&i!==0&&u!=null)return u}function F(a){if(i!=null&&u!=null&&!(a>i))return u}function b(){return v??(g?v=Promise.resolve():v=new Promise((a,l)=>{p=a}))}function T(){return f===void 0&&(f={get name(){return e},get version(){return i},get i(){return S()},v:a=>F(a)}),f}function x(){return d===void 0&&(d={get name(){return e},get version(){return g?i:void 0},get i(){return g?S():void 0},v:a=>g?F(a):void 0,get promise(){return i===0?Promise.reject(t("Remote interface not provided")):b().then(()=>{if(i===0)throw new Error(t("Remote interface not provided"));return T()})}}),d}function E(){p!=null&&(p(),p=void 0)}return{get name(){return e},get localVersion(){if(n!=null)return n},set localVersion(a){if(n!=null&&n!==a)throw new Error(t("A different local version is already set"));n=a},get localVersionSent(){return r},set localVersionSent(a){if(!a&&r)throw new Error(t("Local version already notified"));r=a,a&&n===0&&(o=!0)},get localInterfaceSent(){return o},set localInterfaceSent(a){if(n==null)throw new Error(t("Local version not set"));if(!a&&o)throw new Error(t("Local interface already sent."));o=a},get remoteVersion(){if(i!=null)return i},set remoteVersion(a){if(i!=null&&i!==a)throw new Error(t("A different remote version is already set for "+e+`(${i} -> ${a})`));i=a,a===0&&(c=!0)},get remoteVersionReceived(){return i!=null},setRemoteInterface:a=>{if(i==null)throw new Error(t("Remote version not set"));if(i===0){console.warn(t("Remote version is 0, remote interface is ignored."));return}if(c)throw new Error(t("Interface already provided."));u=a,c=!0},get remoteInterfaceReceived(){return c},depGroup:void 0,get isActivable(){return c&&o},get isActivated(){return g},activate(){if(!g){if(!c)throw new Error(t("Remote interface not provided."));if(!o)throw new Error(t("Local interface not sent"));g=!0,E()}},getRemote:()=>T(),getLazyRemote:()=>x(),get activationPromise(){return b()}}}}function kt(t){return function(e,n,r,o){let i=r,u=!1,c=!1;function g(){return e.every(f=>f.remoteVersionReceived&&f.localVersionSent)&&n.every(f=>f.remoteVersionReceived)}return{get isDeclared(){return c},set isDeclared(f){if(!f&&c)throw new Error(t("Factory already declared"));c=f},get isReady(){return g()},get isDone(){return u},get args(){return e},get deps(){return n},invoke(){if(u)throw new Error(t("Factory already invoked"));if(!g())throw new Error(t("Factory is not ready"));let f;o?f=e.map(p=>p.getRemote()):f=e[0].getRemote();let d;const v=n.length>0?n.map(p=>p.getRemote()):null;try{d=v==null?i(f):i(f,v)}catch(p){throw new Error(t("error in factory:"),{cause:p})}if(o||(d=[d]),d.length!=e.length)throw new Error(t("Invalid factory result"));return u=!0,i=null,d}}}}function xt(t){return function(e,n,r,o){let i=n,u=!1;function c(){return e.every(g=>g.isActivated)}return{get isReady(){return c()},get isDone(){return u},get args(){return e},invoke(){if(u||!c()){const d=new Error(t(u?"callback already invoked":"callback parameters are not ready"));throw o?.[1](d),d}const g=r?e.map(d=>d.getRemote()):e[0].getRemote();let f;try{f=i(g)}catch(d){o==null?console.error(t("error in callback:"),d):o[1](d)}finally{u=!0}o?.[0](f)}}}}function it(t,e){return t==null||t.length===0?e:`[${t}] ${e}`}function Lt(t){function e(a){return it(t.name,a)}const n=xt(e),r=Rt(e),o=kt(e),i={},u=[];let c=[],g;const f=()=>(g==null?g=0:g++,g);function d(a){let l=i[a];return l==null&&(l=r(a),l.localVersion==null&&(b&&(l.localVersion=0),T&&(l.localVersionSent=!0)),l.remoteVersion==null&&x&&(l.remoteVersion=0),i[a]=l),l}function v(a){return a.map(d)}function p(...a){const l=f(),m=Array(l).fill(!1);a.forEach(y=>{y.forEach(w=>{w.depGroup!=null&&(m[w.depGroup]=!0),w.depGroup=l})}),Object.values(i).forEach(y=>{y.depGroup!=null&&y.depGroup!==l&&m[y.depGroup]&&(y.depGroup=l)})}t.onDeclare=a=>{const l=v(a.map(m=>m.name));for(let m=0;m<a.length;m++)a[m].version!=null&&(l[m].remoteVersion=a[m].version);p(l),E()},t.onDone=()=>{x||(x=!0,Object.values(i).forEach(a=>{a.remoteVersion==null&&(a.remoteVersion=0)}),E())},t.onProvide=(a,l,m)=>{let y=i[a];if(y==null)throw new Error(e(`Contract not declared : ${a}`));if(y.remoteVersion!=l)throw new Error(e(`Remote declared version ${y.remoteVersion} of contract "${a}" but provided version ${l}.`));if(y.remoteInterfaceReceived)throw new Error(e(`Remote contract "${a}" is already provided.`));y.setRemoteInterface(m),E()};let S=!1,F=!1,b=!1,T=!1,x=!1;async function E(){if(F=!0,!S){for(S=!0;F;){if(F=!1,t.isReady){const a=u.filter(l=>!l.isDeclared);if(a.length>0)for(const l of a){const m=Array(l.args.length+l.deps.length);l.args.forEach((y,w)=>m[w]=y),l.deps.forEach((y,w)=>m[w+l.args.length]=y),await t.declare(m.map(y=>({name:y.name,version:y.localVersion}))),m.forEach(y=>{y.localVersion!=null&&(y.localVersionSent=!0)}),l.isDeclared=!0}}if(t.isReady&&b&&u.every(a=>a.isDeclared)){const a=Object.values(i).filter(l=>!l.localVersionSent&&l.localVersion!=null);if(a.length>0)for(const l of a)await t.declare([{name:l.name,version:l.localVersion}]),l.localVersionSent=!0;T||(T=!0,await t.done())}if(t.isReady){const a=u.filter(l=>!l.isDone&&l.isReady);if(a.length>0)for(const l of a){const m=l.invoke();for(let y=0;y<l.args.length;y++){const w=l.args[y];await t.provide(w.name,w.localVersion,m[y]),w.localInterfaceSent=!0}}}if(g!=null){const a=Array(g+1).fill(null);for(const l in i){const m=i[l];m.depGroup!=null&&(m.isActivable?a[m.depGroup]==null&&!m.isActivated&&(a[m.depGroup]=!0):a[m.depGroup]=!1)}if(a.some(l=>l===!0))for(const l in i){const m=i[l];m.depGroup!=null&&a[m.depGroup]&&m.activate()}}if(t.isReady){const a=c;c=[];const l=[];for(const m of a)!m.isDone&&m.isReady?m.invoke():l.push(m);l.push(...c),c=l}}S=!1}}return{get(a){return d(a)},declareFactory:(a,l,m,y)=>{if(b)throw new Error(e("Cannot declare a factory after done has been set to true."));const w=v(a.map(h=>h.name));{const h=w.filter($=>$.localVersion!=null);if(h.length>0)throw new Error(e("Cannot declare a factory for already implemented contracts : "+h.map($=>$.name).join(", ")))}for(let h=0;h<a.length;h++)w[h].localVersion=a[h].version;const R=v(l);p(w,R);const gt=o(w,R,m,y);u.push(gt),E()},declareCallback(a,l,m,y){const w=v(a),R=n(w,l,m,y);!S&&c.length===0&&R.isReady?R.invoke():(c.push(R),E())},get done(){return b},set done(a){if(b){if(!a)throw new Error(e("Cannot set done to false after it has been set to true."))}else a&&(b=!0,Object.values(i).forEach(l=>{l.localVersion==null&&(l.localVersion=0)}),E())}}}const Mt=/^\d+$/;function Pt(t){const[e,n,r]=t.split(":",3);if(n==null||r!=null||!Mt.test(n))return null;const o=parseInt(n);return isNaN(o)||o===0?null:{name:e,version:o}}function Gt(t){const e=Lt(t);function n(r){return it(t.name,r)}return{plug(r,o,i=void 0){if(e.done)throw new Error(n("Cannot plug after plugsDone."));i==null&&(i=o,o=[]);let u=!0;Array.isArray(r)||(r=[r],u=!1);const c=r.map(g=>{const f=Pt(g);if(f==null)throw new Error(n("Invalid contract id : "+g));return f});e.declareFactory(c,o,i,u)},plugsDone(){e.done=!0},use(r,o){let i=!0;Array.isArray(r)||(r=[r],i=!1),e.declareCallback(r,o,i)},exec(r,o){let i=!0;return Array.isArray(r)||(r=[r],i=!1),new Promise((...u)=>{e.declareCallback(r,o,i,u)})},get(r){return r.map(o=>e.get(o).getLazyRemote())}}}const at="app-agent";let q;function Dt(t){return q!=null||(q=Gt(Tt(at,t))),q}console.log(`[${at}@1.0.12] loaded`);const _=t=>{let e;const n=new Set,r=(f,d)=>{const v=typeof f=="function"?f(e):f;if(!Object.is(v,e)){const p=e;e=d??(typeof v!="object"||v===null)?v:Object.assign({},e,v),n.forEach(S=>S(e,p))}},o=()=>e,c={setState:r,getState:o,getInitialState:()=>g,subscribe:f=>(n.add(f),()=>n.delete(f))},g=e=t(r,o,c);return c},Vt=(t=>t?_(t):_),jt=t=>t;function It(t,e=jt){const n=C.useSyncExternalStore(t.subscribe,C.useCallback(()=>e(t.getState()),[t,e]),C.useCallback(()=>e(t.getInitialState()),[t,e]));return C.useDebugValue(n),n}const U=t=>{const e=Vt(t),n=r=>It(e,r);return Object.assign(n,e),n},ct=(t=>t?U(t):U),Ot=t=>(e,n,r)=>{const o=r.subscribe;return r.subscribe=((u,c,g)=>{let f=u;if(c){const d=g?.equalityFn||Object.is;let v=u(r.getState());f=p=>{const S=u(p);if(!d(v,S)){const F=v;c(v=S,F)}},g?.fireImmediately&&c(v,v)}return o(f)}),t(e,n,r)},$t=Ot,s=ct()($t(t=>({ready:!1,workflow:"current",mode:"assignment",theme:"light",saveCount:0,canSave:!1,afterSaveCount:0,isDirtyCount:0,loadedTextContent:null,loadedJsonContent:null,loadedJsonActivityContent:null,loadedJsonAssignmentContent:null,loadedJsonActivityBinaryData:null,loadedJsonAssignmentBinaryData:null,getTextContentFunction:()=>{throw console.error("[React bindings] getTextContentFunction is not set"),new Error("[React bindings] getTextContentFunction is not set")},getJsonContentFunction:()=>{throw console.error("[React bindings] getJsonContentFunction is not set"),new Error("[React bindings] getJsonContentFunction is not set")},getJsonActivityContentFunction:()=>{throw console.error("[React bindings] getJsonActivityContentFunction is not set"),new Error("[React bindings] getJsonActivityContentFunction is not set")},getJsonAssignmentContentFunction:()=>{throw console.error("[React bindings] getJsonAssignmentContentFunction is not set"),new Error("[React bindings] getJsonAssignmentContentFunction is not set")},getJsonActivitySplitContentFunction:()=>{throw console.error("[React bindings] getJsonActivitySplitContentFunction is not set"),new Error("[React bindings] getJsonActivitySplitContentFunction is not set")},getJsonAssignmentSplitContentFunction:()=>{throw console.error("[React bindings] getJsonAssignmentSplitContentFunction is not set"),new Error("[React bindings] getJsonAssignmentSplitContentFunction is not set")},sidebarActions:{},quickActions:{},activitySettingsCallback:null,llmGetFirstMessageContextFunction:null,setLlmGetFirstMessageContextFunction:e=>{t({llmGetFirstMessageContextFunction:e})},llmGetAllMessagesContextFunction:null,setLlmGetAllMessagesContextFunction:e=>{t({llmGetAllMessagesContextFunction:e})},llmGetAvailableToolsFunction:null,setLlmGetAvailableToolsFunction:e=>{t({llmGetAvailableToolsFunction:e})},llmCallToolFunction:null,setLlmCallToolFunction:e=>{t({llmCallToolFunction:e})},setGetTextContentFunction:e=>{t({getTextContentFunction:e})},llmDescribeToolFunction:null,setLlmDescribeToolFunction:e=>{t({llmDescribeToolFunction:e})},setGetJsonContentFunction:e=>{t({getJsonContentFunction:e})},setGetJsonActivityContentFunction:e=>{t({getJsonActivityContentFunction:e})},setGetJsonAssignmentContentFunction:e=>{t({getJsonAssignmentContentFunction:e})},setGetJsonActivitySplitContentFunction:e=>{t({getJsonActivitySplitContentFunction:e})},setGetJsonAssignmentSplitContentFunction:e=>{t({getJsonAssignmentSplitContentFunction:e})},setSidebarActions:e=>{t({sidebarActions:e})},setQuickActions:e=>{t({quickActions:e})},setActivitySettingsCallback:e=>{t({activitySettingsCallback:e})},incSaveCount:()=>t(e=>({saveCount:e.saveCount+1})),incDirtyCount:()=>t(e=>({isDirtyCount:e.isDirtyCount+1})),previewStartPreviewFunction:null,previewStopPreviewFunction:null,setPreviewStartPreviewFunction:e=>{t({previewStartPreviewFunction:e})},setPreviewStopPreviewFunction:e=>{t({previewStopPreviewFunction:e})}})));let Y=!1;const Nt=["meta-player-events:1","meta-player-ui:1","mode:1","reload:1","theme:1","workflow:1","preview:1","trigger-save:1","simple-content(text):1","simple-content(json):1","simple-binary-data(text):1","simple-content-eval(text):1","simple-content-eval(json):1","separate-contents(json):1","separate-dual-contents(json):1","llm:1"],K={"mode:1":{setMode:t=>{s.setState({mode:t})}},"reload:1":{reloaded:t=>{console.log("[React bindings] Reloaded with state:",t),console.error("[React bindings] Not implemented yet")}},"theme:1":{setTheme:t=>{if(t===null){s.setState({theme:null});return}if(t!=="light"&&t!=="dark"){console.warn(`[React bindings] Invalid theme: ${t}. Expected 'light' or 'dark'.`),s.setState({theme:null});return}s.setState({theme:t})}},"workflow:1":{setWorkflow:t=>{s.setState({workflow:t})}},"workflow:2":{setWorkflow:t=>{s.setState({workflow:t})}},"preview:1":{startPreview:()=>{const t=s.getState().previewStartPreviewFunction;return t?t():!1},stopPreview:()=>{const t=s.getState().previewStopPreviewFunction;if(!t)throw new Error("Preview stop function is not set");return t()}},"trigger-save:1":{setCanSave(t){s.setState({canSave:t})}},"simple-content(text):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getTextContentFunction(),loadContent:t=>{s.setState({loadedTextContent:t})}},"simple-content(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getJsonContentFunction(),loadContent:t=>{s.setState({loadedJsonContent:t})}},"simple-binary-data(text):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getTextContentFunction(),loadContent:t=>{s.setState({loadedTextContent:t})}},"simple-content-eval(text):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getTextContentFunction(),loadContent:t=>{s.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getJsonContentFunction(),loadContent:t=>{s.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(json):2":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getJsonContentFunction(),loadContent:t=>{s.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(text):2":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>s.getState().getTextContentFunction(),loadContent:t=>{s.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"separate-contents(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{s.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>s.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>s.getState().getJsonAssignmentContentFunction()},"separate-contents-eval(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{s.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>s.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>s.getState().getJsonAssignmentContentFunction()},"separate-contents-eval(json):2":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{s.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>s.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>s.getState().getJsonAssignmentContentFunction()},"separate-dual-contents(json):1":{contentSaved:()=>{s.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:({activityContent:t,assignmentContent:e,activityBinaryData:n,assignmentBinaryData:r})=>{s.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e,loadedJsonActivityBinaryData:n,loadedJsonAssignmentBinaryData:r})},getActivityContentAndData:()=>s.getState().getJsonActivitySplitContentFunction(),getAssignmentContentAndData:()=>s.getState().getJsonAssignmentSplitContentFunction()},"anti-cheat:1":{lock:()=>{},unlock:()=>{}},"meta-player-ui:1":{executeAction(t){if(t.startsWith("qa")){const n=s.getState().quickActions[t];n?n():console.error(`[React bindings] Quick action not found: ${t}`)}else{const n=s.getState().sidebarActions[t];n?n():console.error(`[React bindings] Sidebar action not found: ${t}`)}},executeFileUpload(t,e){if(t.startsWith("qa")){const r=s.getState().quickActions[t];r?r(e):console.error(`[React bindings] Quick action not found: ${t}`)}else{const r=s.getState().sidebarActions[t];r?r(e):console.error(`[React bindings] Sidebar action not found: ${t}`)}},updateSettings(t){const e=s.getState().activitySettingsCallback;e?e(t):console.warn("activitySettingsCallback is not set. Changes:",t)}},"meta-player-events:1":{handleEvent(t){t==="all-loaded"&&s.setState({ready:!0})}},"llm:1":{getFirstMessageContext:t=>{const e=s.getState().llmGetFirstMessageContextFunction;return e?e(t):""},getAllMessagesContext:t=>{const e=s.getState().llmGetAllMessagesContextFunction;return e?e(t):""},getAvailableTools:t=>{const e=s.getState().llmGetAvailableToolsFunction;return e?e(t):[]},callTool:(t,e,n)=>{const r=s.getState().llmCallToolFunction;if(!r)throw new Error("LLM call tool function is not set");return r(t,e,n)},getToolCallDescription:(t,e,n)=>{const r=s.getState().llmDescribeToolFunction;if(!r)throw new Error("LLM describe tool function is not set");return r(t,e,n)}}},A=Dt();function qt(t){if(!Y){Y=!0;for(const e of t){if(!Nt.includes(e))continue;if(!(e in K)){console.warn(`[React bindings] Contract handler for ${e} is not defined. Skipping plug.`);continue}const n=K[e];A.plug([e],([])=>[n])}A.plugsDone();for(const e of["simple-content(text):1","simple-content(json):1","simple-binary-data(text):1","simple-content-eval(text):1","simple-content-eval(json):1","simple-content-eval(json):2","simple-content-eval(text):2","separate-contents(json):1","separate-dual-contents(json):1"])if(t.includes(e)){const n=e.split(":")[0];A.use([n],([r])=>{s.subscribe(o=>o.isDirtyCount,()=>{r.i?.contentChanged()})})}}}const Bt=()=>s(t=>{if(t.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return t.mode}),Wt=()=>s(t=>{if(t.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return t.workflow}),Ht=()=>s(t=>{if(t.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return t.theme}),zt=()=>s(t=>t.incSaveCount),Qt=()=>s(t=>t.incDirtyCount),_t=()=>s(t=>t.loadedTextContent),Ut=()=>s(t=>t.loadedJsonContent),Yt=()=>s(t=>t.loadedJsonActivityContent),Kt=()=>s(t=>t.loadedJsonAssignmentContent),Xt=()=>s(t=>t.loadedJsonActivityBinaryData),Zt=()=>s(t=>t.loadedJsonAssignmentBinaryData),te=()=>C.useCallback(()=>s.getState().loadedTextContent,[]),ee=()=>C.useCallback(()=>s.getState().loadedJsonContent,[]),ne=()=>C.useCallback(()=>s.getState().loadedJsonActivityContent,[]),oe=()=>C.useCallback(()=>s.getState().loadedJsonAssignmentContent,[]),re=()=>C.useCallback(()=>({content:s.getState().loadedJsonActivityContent,binaryData:s.getState().loadedJsonActivityBinaryData}),[]),se=()=>C.useCallback(()=>({content:s.getState().loadedJsonAssignmentContent,binaryData:s.getState().loadedJsonAssignmentBinaryData}),[]),ie=t=>{const e=s(n=>n.setGetTextContentFunction);C.useEffect(()=>{e(t)},[t,e])},ae=t=>{const e=s(n=>n.setGetJsonContentFunction);C.useEffect(()=>{e(t)},[t,e])},ce=t=>{const e=s(n=>n.setGetJsonActivityContentFunction);C.useEffect(()=>{e(t)},[t,e])},le=t=>{const e=s(n=>n.setGetJsonAssignmentContentFunction);C.useEffect(()=>{e(t)},[t,e])},ue=t=>{const e=s(n=>n.setGetJsonActivitySplitContentFunction);C.useEffect(()=>{e(t)},[t,e])},de=t=>{const e=s(n=>n.setGetJsonAssignmentSplitContentFunction);C.useEffect(()=>{e(t)},[t,e])},fe=t=>{const e=s(n=>n.afterSaveCount);C.useEffect(()=>{e>0&&t()},[e])},ge=()=>(t,e)=>{A.use(["meta-player-ui"],([n])=>{if(n.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}n.i?.previewTextFile(t,e)})},ve=()=>(t,e)=>{A.use(["meta-player-ui"],([n])=>{if(n.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}n.i?.previewImageFile(t,e)})};let P=0,B=0;const me=(t,e)=>{const n=C.useMemo(t,e),r=s(o=>o.setSidebarActions);C.useEffect(()=>(P++,P>1&&console.error("[React bindings] Capytale iframe React: Multiple sidebar actions registered: ",P),()=>{P--}),[]),C.useEffect(()=>(A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}B++;const i=n.map((c,g)=>({type:c.type,title:c.title,icon:c.icon,id:`sa-${B}-${g}`,...c.type==="file-upload"?{accept:c.accept}:{}})),u={};n.forEach((c,g)=>{u[`sa-${B}-${g}`]=c.action}),o.i?.setSidebarActionButtons(i),r(u)}),()=>{r({}),A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}o.i?.setSidebarActionButtons([])})}),[n])};let G=0,W=0;const pe=(t,e)=>{const n=C.useMemo(t,e),r=s(o=>o.setQuickActions);C.useEffect(()=>(G++,G>1&&console.error("[React bindings] Capytale iframe React: Multiple quick actions registered: ",G),()=>{G--}),[]),C.useEffect(()=>(A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}W++;const i=n.map((c,g)=>({type:c.type,title:c.title,icon:c.icon,id:`qa-${W}-${g}`,...c.type==="file-upload"?{accept:c.accept}:{}})),u={};n.forEach((c,g)=>{u[`qa-${W}-${g}`]=c.action}),o.i?.setQuickActionButtons(i),r(u)}),()=>{r({}),A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}o.i?.setQuickActionButtons([])})}),[n])};let D=0;const lt=(t,e,n)=>{const r=C.useMemo(t,n),o=s(i=>i.setActivitySettingsCallback);C.useEffect(()=>(D++,D>1&&console.error("[React bindings] Capytale iframe React: Multiple settings registered: ",D),()=>{D--}),[]),C.useEffect(()=>(A.use(["meta-player-ui"],([i])=>{if(i.version===0){console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}i.i?.setSettingsUI(r)}),o(e),()=>{o(null)}),[r])},ut=()=>C.useCallback(e=>A.exec(["meta-player-ui"],([n])=>{if(n.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"),new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return n.i?.showToast(e)}),[]),dt=()=>C.useCallback(e=>A.exec(["meta-player-ui"],([n])=>{if(n.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"),new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return n.i?.clearToast(e)}),[]),Ce=()=>C.useCallback(()=>A.exec(["meta-player-ui"],([e])=>{if(e.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"),new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return e.i?.clearToasts()}),[]),ft=(t,e)=>{const n=ut(),r=dt();return C.useEffect(()=>{if(t==null)return;const o=n(t);return()=>{o.then(i=>{i!=null&&r(i)})}},[n,r,...e]),null},ye=()=>C.useCallback(()=>A.exec(["trigger-save"],([e])=>{if(e.version===0)throw console.error("[React bindings] Le MétaPlayer ne supporte pas le contrat trigger-save"),new Error("Le MétaPlayer ne supporte pas le contrat trigger-save");return e.i?.triggerSave()}),[]),Se=()=>s(t=>t.canSave),we=(t,e)=>{const n=s(r=>r.setLlmGetFirstMessageContextFunction);C.useEffect(()=>(n(t),()=>{n(null)}),[e,n])},Ae=(t,e)=>{const n=s(r=>r.setLlmGetAllMessagesContextFunction);C.useEffect(()=>(n(t),()=>{n(null)}),[e,n])},be=(t,e,n,r)=>{const o=s(c=>c.setLlmGetAvailableToolsFunction),i=s(c=>c.setLlmCallToolFunction),u=s(c=>c.setLlmDescribeToolFunction);C.useEffect(()=>(o(t),i(e),u(n),()=>{o(null),i(null),u(null)}),[r,o,i,u])},he=(t,e,n)=>{const r=s(i=>i.setPreviewStartPreviewFunction),o=s(i=>i.setPreviewStopPreviewFunction);C.useEffect(()=>(r(t),o(e),()=>{r(null),o(null)}),[n,r,o])};function Fe(t){const e={};for(const n of t.fields)e[n.name]=n.defaultValue;return e}function Ee(t){return{[t.name]:t.defaultValues}}function Je(t){return{[t.name]:t.defaultValue}}function Te(t){switch(t.type){case"form":return Fe(t);case"checkboxes":case"switches":return Ee(t);case"radio":return Je(t);default:return{}}}function Re(t){const e={};for(const n of t)Object.assign(e,Te(n));return e}function ke(t){const n=ct()(r=>({...Re(t)}));return n.activitySettings=t,n}function xe(t){lt(()=>t.activitySettings,e=>{t.setState(e)},[])}function Le({store:t}){return xe(t),null}const Me=["meta-player-events:1","meta-player-ui:1","mode:1","workflow:1"];function Pe({children:t,contracts:e,loadOnlyWhenReady:n=!0,activitySettingsStore:r}){const o=s(i=>i.ready);return C.useEffect(()=>{const i=[...e];for(const u of Me)i.includes(u)||i.push(u);qt(i)},[]),n&&!o?L.jsx("div",{className:"capy-loading-container",children:"Chargement en cours..."}):L.jsxs(L.Fragment,{children:[r&&L.jsx(Le,{store:r}),t]})}function Ge({message:t}){return ft(t,[t]),null}exports.Capytale=Pe;exports.TemporaryToast=Ge;exports.createActivitySettingsStore=ke;exports.useAfterSaveAction=fe;exports.useCanSave=Se;exports.useClearToast=dt;exports.useClearToasts=Ce;exports.useGetLoadedJsonActivityContent=ne;exports.useGetLoadedJsonActivitySplitContent=re;exports.useGetLoadedJsonAssignmentContent=oe;exports.useGetLoadedJsonAssignmentSplitContent=se;exports.useGetLoadedJsonContent=ee;exports.useGetLoadedTextContent=te;exports.useJsonActivityContentSaveFunction=ce;exports.useJsonActivitySplitContentSaveFunction=ue;exports.useJsonAssignmentContentSaveFunction=le;exports.useJsonAssignmentSplitContentSaveFunction=de;exports.useJsonContentSaveFunction=ae;exports.useLLMAllMessagesContext=Ae;exports.useLLMFirstMessageContext=we;exports.useLLMTools=be;exports.useLoadedJsonActivityBinaryData=Xt;exports.useLoadedJsonActivityContent=Yt;exports.useLoadedJsonAssignmentBinaryData=Zt;exports.useLoadedJsonAssignmentContent=Kt;exports.useLoadedJsonContent=Ut;exports.useLoadedTextContent=_t;exports.useMode=Bt;exports.useNotifyIsDirty=Qt;exports.usePreviewAsStudent=he;exports.usePreviewImageFile=ve;exports.usePreviewTextFile=ge;exports.useQuickActions=pe;exports.useRequestSave=zt;exports.useSettings=lt;exports.useShowToast=ut;exports.useSidebarActions=me;exports.useTextContentSaveFunction=ie;exports.useTheme=Ht;exports.useToast=ft;exports.useTriggerSave=ye;exports.useWorkflow=Wt;
package/dist/index.d.ts CHANGED
@@ -309,7 +309,7 @@ export declare const useMode: () => "create" | "assignment" | "review" | "view";
309
309
 
310
310
  export declare const useNotifyIsDirty: () => () => void;
311
311
 
312
- export declare const usePreview: (startPreview: BooleanFunction, stopPreview: SimpleProcedure, deps: readonly unknown[]) => void;
312
+ export declare const usePreviewAsStudent: (startPreview: BooleanFunction, stopPreview: SimpleProcedure, deps: readonly unknown[]) => void;
313
313
 
314
314
  export declare const usePreviewImageFile: () => (title: string, url: string) => void;
315
315
 
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as U, jsxs as ft, Fragment as mt } from "react/jsx-runtime";
2
- import M, { useCallback as b, useEffect as w, useMemo as _ } from "react";
2
+ import L, { useCallback as b, useEffect as S, useMemo as _ } from "react";
3
3
  const et = /* @__PURE__ */ Symbol("Comlink.proxy"), pt = /* @__PURE__ */ Symbol("Comlink.endpoint"), vt = /* @__PURE__ */ Symbol("Comlink.releaseProxy"), q = /* @__PURE__ */ Symbol("Comlink.finalizer"), I = /* @__PURE__ */ Symbol("Comlink.thrown"), nt = (t) => typeof t == "object" && t !== null || typeof t == "function", Ct = {
4
4
  canHandle: (t) => nt(t) && t[et],
5
5
  serialize(t) {
@@ -111,7 +111,7 @@ function st(t, e) {
111
111
  }
112
112
  }), z(t, n, [], e);
113
113
  }
114
- function P(t) {
114
+ function M(t) {
115
115
  if (t)
116
116
  throw new Error("Proxy has been released and is not useable");
117
117
  }
@@ -138,7 +138,7 @@ function z(t, e, n = [], r = function() {
138
138
  let o = !1;
139
139
  const i = new Proxy(r, {
140
140
  get(u, l) {
141
- if (P(o), l === vt)
141
+ if (M(o), l === vt)
142
142
  return () => {
143
143
  bt(i), it(t), e.clear(), o = !0;
144
144
  };
@@ -154,7 +154,7 @@ function z(t, e, n = [], r = function() {
154
154
  return z(t, e, [...n, l]);
155
155
  },
156
156
  set(u, l, f) {
157
- P(o);
157
+ M(o);
158
158
  const [g, d] = $(f);
159
159
  return x(t, e, {
160
160
  type: "SET",
@@ -163,7 +163,7 @@ function z(t, e, n = [], r = function() {
163
163
  }, d).then(J);
164
164
  },
165
165
  apply(u, l, f) {
166
- P(o);
166
+ M(o);
167
167
  const g = n[n.length - 1];
168
168
  if (g === pt)
169
169
  return x(t, e, {
@@ -179,7 +179,7 @@ function z(t, e, n = [], r = function() {
179
179
  }, m).then(J);
180
180
  },
181
181
  construct(u, l) {
182
- P(o);
182
+ M(o);
183
183
  const [f, g] = Y(l);
184
184
  return x(t, e, {
185
185
  type: "CONSTRUCT",
@@ -347,7 +347,7 @@ function kt(t) {
347
347
  v: (a) => E(a)
348
348
  }), g;
349
349
  }
350
- function L() {
350
+ function P() {
351
351
  return d === void 0 && (d = {
352
352
  get name() {
353
353
  return e;
@@ -435,7 +435,7 @@ function kt(t) {
435
435
  }
436
436
  },
437
437
  getRemote: () => T(),
438
- getLazyRemote: () => L(),
438
+ getLazyRemote: () => P(),
439
439
  get activationPromise() {
440
440
  return h();
441
441
  }
@@ -490,7 +490,7 @@ function xt(t) {
490
490
  };
491
491
  };
492
492
  }
493
- function Lt(t) {
493
+ function Pt(t) {
494
494
  return function(e, n, r, o) {
495
495
  let i = n, u = !1;
496
496
  function l() {
@@ -528,16 +528,16 @@ function Lt(t) {
528
528
  function ct(t, e) {
529
529
  return t == null || t.length === 0 ? e : `[${t}] ${e}`;
530
530
  }
531
- function Mt(t) {
531
+ function Lt(t) {
532
532
  function e(a) {
533
533
  return ct(t.name, a);
534
534
  }
535
- const n = Lt(e), r = kt(e), o = xt(e), i = {}, u = [];
535
+ const n = Pt(e), r = kt(e), o = xt(e), i = {}, u = [];
536
536
  let l = [], f;
537
537
  const g = () => (f == null ? f = 0 : f++, f);
538
538
  function d(a) {
539
539
  let c = i[a];
540
- return c == null && (c = r(a), c.localVersion == null && (h && (c.localVersion = 0), T && (c.localVersionSent = !0)), c.remoteVersion == null && L && (c.remoteVersion = 0), i[a] = c), c;
540
+ return c == null && (c = r(a), c.localVersion == null && (h && (c.localVersion = 0), T && (c.localVersionSent = !0)), c.remoteVersion == null && P && (c.remoteVersion = 0), i[a] = c), c;
541
541
  }
542
542
  function m(a) {
543
543
  return a.map(d);
@@ -545,8 +545,8 @@ function Mt(t) {
545
545
  function v(...a) {
546
546
  const c = g(), p = Array(c).fill(!1);
547
547
  a.forEach((C) => {
548
- C.forEach((S) => {
549
- S.depGroup != null && (p[S.depGroup] = !0), S.depGroup = c;
548
+ C.forEach((w) => {
549
+ w.depGroup != null && (p[w.depGroup] = !0), w.depGroup = c;
550
550
  });
551
551
  }), Object.values(i).forEach((C) => {
552
552
  C.depGroup != null && C.depGroup !== c && p[C.depGroup] && (C.depGroup = c);
@@ -558,7 +558,7 @@ function Mt(t) {
558
558
  a[p].version != null && (c[p].remoteVersion = a[p].version);
559
559
  v(c), R();
560
560
  }, t.onDone = () => {
561
- L || (L = !0, Object.values(i).forEach((a) => {
561
+ P || (P = !0, Object.values(i).forEach((a) => {
562
562
  a.remoteVersion == null && (a.remoteVersion = 0);
563
563
  }), R());
564
564
  }, t.onProvide = (a, c, p) => {
@@ -571,7 +571,7 @@ function Mt(t) {
571
571
  throw new Error(e(`Remote contract "${a}" is already provided.`));
572
572
  C.setRemoteInterface(p), R();
573
573
  };
574
- let y = !1, E = !1, h = !1, T = !1, L = !1;
574
+ let y = !1, E = !1, h = !1, T = !1, P = !1;
575
575
  async function R() {
576
576
  if (E = !0, !y) {
577
577
  for (y = !0; E; ) {
@@ -580,7 +580,7 @@ function Mt(t) {
580
580
  if (a.length > 0)
581
581
  for (const c of a) {
582
582
  const p = Array(c.args.length + c.deps.length);
583
- c.args.forEach((C, S) => p[S] = C), c.deps.forEach((C, S) => p[S + c.args.length] = C), await t.declare(p.map((C) => ({ name: C.name, version: C.localVersion }))), p.forEach((C) => {
583
+ c.args.forEach((C, w) => p[w] = C), c.deps.forEach((C, w) => p[w + c.args.length] = C), await t.declare(p.map((C) => ({ name: C.name, version: C.localVersion }))), p.forEach((C) => {
584
584
  C.localVersion != null && (C.localVersionSent = !0);
585
585
  }), c.isDeclared = !0;
586
586
  }
@@ -598,8 +598,8 @@ function Mt(t) {
598
598
  for (const c of a) {
599
599
  const p = c.invoke();
600
600
  for (let C = 0; C < c.args.length; C++) {
601
- const S = c.args[C];
602
- await t.provide(S.name, S.localVersion, p[C]), S.localInterfaceSent = !0;
601
+ const w = c.args[C];
602
+ await t.provide(w.name, w.localVersion, p[C]), w.localInterfaceSent = !0;
603
603
  }
604
604
  }
605
605
  }
@@ -633,21 +633,21 @@ function Mt(t) {
633
633
  },
634
634
  declareFactory: (a, c, p, C) => {
635
635
  if (h) throw new Error(e("Cannot declare a factory after done has been set to true."));
636
- const S = m(a.map((F) => F.name));
636
+ const w = m(a.map((F) => F.name));
637
637
  {
638
- const F = S.filter((N) => N.localVersion != null);
638
+ const F = w.filter((N) => N.localVersion != null);
639
639
  if (F.length > 0)
640
640
  throw new Error(e("Cannot declare a factory for already implemented contracts : " + F.map((N) => N.name).join(", ")));
641
641
  }
642
642
  for (let F = 0; F < a.length; F++)
643
- S[F].localVersion = a[F].version;
643
+ w[F].localVersion = a[F].version;
644
644
  const k = m(c);
645
- v(S, k);
646
- const gt = o(S, k, p, C);
645
+ v(w, k);
646
+ const gt = o(w, k, p, C);
647
647
  u.push(gt), R();
648
648
  },
649
649
  declareCallback(a, c, p, C) {
650
- const S = m(a), k = n(S, c, p, C);
650
+ const w = m(a), k = n(w, c, p, C);
651
651
  !y && l.length === 0 && k.isReady ? k.invoke() : (l.push(k), R());
652
652
  },
653
653
  get done() {
@@ -663,15 +663,15 @@ function Mt(t) {
663
663
  }
664
664
  };
665
665
  }
666
- const Pt = /^\d+$/;
666
+ const Mt = /^\d+$/;
667
667
  function Gt(t) {
668
668
  const [e, n, r] = t.split(":", 3);
669
- if (n == null || r != null || !Pt.test(n)) return null;
669
+ if (n == null || r != null || !Mt.test(n)) return null;
670
670
  const o = parseInt(n);
671
671
  return isNaN(o) || o === 0 ? null : { name: e, version: o };
672
672
  }
673
673
  function Dt(t) {
674
- const e = Mt(t);
674
+ const e = Lt(t);
675
675
  function n(r) {
676
676
  return ct(t.name, r);
677
677
  }
@@ -725,12 +725,12 @@ const K = (t) => {
725
725
  return l;
726
726
  }, It = ((t) => t ? K(t) : K), jt = (t) => t;
727
727
  function Ot(t, e = jt) {
728
- const n = M.useSyncExternalStore(
728
+ const n = L.useSyncExternalStore(
729
729
  t.subscribe,
730
- M.useCallback(() => e(t.getState()), [t, e]),
731
- M.useCallback(() => e(t.getInitialState()), [t, e])
730
+ L.useCallback(() => e(t.getState()), [t, e]),
731
+ L.useCallback(() => e(t.getInitialState()), [t, e])
732
732
  );
733
- return M.useDebugValue(n), n;
733
+ return L.useDebugValue(n), n;
734
734
  }
735
735
  const X = (t) => {
736
736
  const e = It(t), n = (r) => Ot(e, r);
@@ -874,6 +874,7 @@ const qt = [
874
874
  "reload:1",
875
875
  "theme:1",
876
876
  "workflow:1",
877
+ "preview:1",
877
878
  "trigger-save:1",
878
879
  "simple-content(text):1",
879
880
  "simple-content(json):1",
@@ -919,6 +920,18 @@ const qt = [
919
920
  s.setState({ workflow: t });
920
921
  }
921
922
  },
923
+ "preview:1": {
924
+ startPreview: () => {
925
+ const t = s.getState().previewStartPreviewFunction;
926
+ return t ? t() : !1;
927
+ },
928
+ stopPreview: () => {
929
+ const t = s.getState().previewStopPreviewFunction;
930
+ if (!t)
931
+ throw new Error("Preview stop function is not set");
932
+ return t();
933
+ }
934
+ },
922
935
  "trigger-save:1": {
923
936
  setCanSave(t) {
924
937
  s.setState({ canSave: t });
@@ -1151,18 +1164,6 @@ const qt = [
1151
1164
  throw new Error("LLM describe tool function is not set");
1152
1165
  return r(t, e, n);
1153
1166
  }
1154
- },
1155
- "preview:1": {
1156
- startPreview: () => {
1157
- const t = s.getState().previewStartPreviewFunction;
1158
- return t ? t() : !1;
1159
- },
1160
- stopPreview: () => {
1161
- const t = s.getState().previewStopPreviewFunction;
1162
- if (!t)
1163
- throw new Error("Preview stop function is not set");
1164
- return t();
1165
- }
1166
1167
  }
1167
1168
  }, A = (
1168
1169
  // Workaround for typing inference issue
@@ -1238,47 +1239,47 @@ const re = () => s((t) => {
1238
1239
  const e = s(
1239
1240
  (n) => n.setGetTextContentFunction
1240
1241
  );
1241
- w(() => {
1242
+ S(() => {
1242
1243
  e(t);
1243
1244
  }, [t, e]);
1244
1245
  }, be = (t) => {
1245
1246
  const e = s(
1246
1247
  (n) => n.setGetJsonContentFunction
1247
1248
  );
1248
- w(() => {
1249
+ S(() => {
1249
1250
  e(t);
1250
1251
  }, [t, e]);
1251
1252
  }, he = (t) => {
1252
1253
  const e = s(
1253
1254
  (n) => n.setGetJsonActivityContentFunction
1254
1255
  );
1255
- w(() => {
1256
+ S(() => {
1256
1257
  e(t);
1257
1258
  }, [t, e]);
1258
1259
  }, Fe = (t) => {
1259
1260
  const e = s(
1260
1261
  (n) => n.setGetJsonAssignmentContentFunction
1261
1262
  );
1262
- w(() => {
1263
+ S(() => {
1263
1264
  e(t);
1264
1265
  }, [t, e]);
1265
1266
  }, Ee = (t) => {
1266
1267
  const e = s(
1267
1268
  (n) => n.setGetJsonActivitySplitContentFunction
1268
1269
  );
1269
- w(() => {
1270
+ S(() => {
1270
1271
  e(t);
1271
1272
  }, [t, e]);
1272
1273
  }, Re = (t) => {
1273
1274
  const e = s(
1274
1275
  (n) => n.setGetJsonAssignmentSplitContentFunction
1275
1276
  );
1276
- w(() => {
1277
+ S(() => {
1277
1278
  e(t);
1278
1279
  }, [t, e]);
1279
1280
  }, Je = (t) => {
1280
1281
  const e = s((n) => n.afterSaveCount);
1281
- w(() => {
1282
+ S(() => {
1282
1283
  e > 0 && t();
1283
1284
  }, [e]);
1284
1285
  }, Te = () => (t, e) => {
@@ -1305,12 +1306,12 @@ const re = () => s((t) => {
1305
1306
  let G = 0, B = 0;
1306
1307
  const xe = (t, e) => {
1307
1308
  const n = _(t, e), r = s((o) => o.setSidebarActions);
1308
- w(() => (G++, G > 1 && console.error(
1309
+ S(() => (G++, G > 1 && console.error(
1309
1310
  "[React bindings] Capytale iframe React: Multiple sidebar actions registered: ",
1310
1311
  G
1311
1312
  ), () => {
1312
1313
  G--;
1313
- }), []), w(() => (A.use(["meta-player-ui"], ([o]) => {
1314
+ }), []), S(() => (A.use(["meta-player-ui"], ([o]) => {
1314
1315
  if (o.version === 0) {
1315
1316
  console.error(
1316
1317
  "[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"
@@ -1341,14 +1342,14 @@ const xe = (t, e) => {
1341
1342
  }), [n]);
1342
1343
  };
1343
1344
  let D = 0, H = 0;
1344
- const Le = (t, e) => {
1345
+ const Pe = (t, e) => {
1345
1346
  const n = _(t, e), r = s((o) => o.setQuickActions);
1346
- w(() => (D++, D > 1 && console.error(
1347
+ S(() => (D++, D > 1 && console.error(
1347
1348
  "[React bindings] Capytale iframe React: Multiple quick actions registered: ",
1348
1349
  D
1349
1350
  ), () => {
1350
1351
  D--;
1351
- }), []), w(() => (A.use(["meta-player-ui"], ([o]) => {
1352
+ }), []), S(() => (A.use(["meta-player-ui"], ([o]) => {
1352
1353
  if (o.version === 0) {
1353
1354
  console.error(
1354
1355
  "[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"
@@ -1383,12 +1384,12 @@ const Bt = (t, e, n) => {
1383
1384
  const r = _(t, n), o = s(
1384
1385
  (i) => i.setActivitySettingsCallback
1385
1386
  );
1386
- w(() => (V++, V > 1 && console.error(
1387
+ S(() => (V++, V > 1 && console.error(
1387
1388
  "[React bindings] Capytale iframe React: Multiple settings registered: ",
1388
1389
  V
1389
1390
  ), () => {
1390
1391
  V--;
1391
- }), []), w(() => (A.use(["meta-player-ui"], ([i]) => {
1392
+ }), []), S(() => (A.use(["meta-player-ui"], ([i]) => {
1392
1393
  if (i.version === 0) {
1393
1394
  console.error(
1394
1395
  "[React bindings] Le MétaPlayer ne supporte pas le contrat meta-player-ui"
@@ -1420,7 +1421,7 @@ const Bt = (t, e, n) => {
1420
1421
  return n.i?.clearToast(e);
1421
1422
  }),
1422
1423
  []
1423
- ), Me = () => b(
1424
+ ), Le = () => b(
1424
1425
  () => A.exec(["meta-player-ui"], ([e]) => {
1425
1426
  if (e.version === 0)
1426
1427
  throw console.error(
@@ -1433,7 +1434,7 @@ const Bt = (t, e, n) => {
1433
1434
  []
1434
1435
  ), _t = (t, e) => {
1435
1436
  const n = Ht(), r = zt();
1436
- return w(() => {
1437
+ return S(() => {
1437
1438
  if (t == null)
1438
1439
  return;
1439
1440
  const o = n(t);
@@ -1443,7 +1444,7 @@ const Bt = (t, e, n) => {
1443
1444
  });
1444
1445
  };
1445
1446
  }, [n, r, ...e]), null;
1446
- }, Pe = () => b(() => A.exec(["trigger-save"], ([e]) => {
1447
+ }, Me = () => b(() => A.exec(["trigger-save"], ([e]) => {
1447
1448
  if (e.version === 0)
1448
1449
  throw console.error(
1449
1450
  "[React bindings] Le MétaPlayer ne supporte pas le contrat trigger-save"
@@ -1455,14 +1456,14 @@ const Bt = (t, e, n) => {
1455
1456
  const n = s(
1456
1457
  (r) => r.setLlmGetFirstMessageContextFunction
1457
1458
  );
1458
- w(() => (n(t), () => {
1459
+ S(() => (n(t), () => {
1459
1460
  n(null);
1460
1461
  }), [e, n]);
1461
1462
  }, Ve = (t, e) => {
1462
1463
  const n = s(
1463
1464
  (r) => r.setLlmGetAllMessagesContextFunction
1464
1465
  );
1465
- w(() => (n(t), () => {
1466
+ S(() => (n(t), () => {
1466
1467
  n(null);
1467
1468
  }), [e, n]);
1468
1469
  }, Ie = (t, e, n, r) => {
@@ -1473,7 +1474,7 @@ const Bt = (t, e, n) => {
1473
1474
  ), u = s(
1474
1475
  (l) => l.setLlmDescribeToolFunction
1475
1476
  );
1476
- w(() => (o(t), i(e), u(n), () => {
1477
+ S(() => (o(t), i(e), u(n), () => {
1477
1478
  o(null), i(null), u(null);
1478
1479
  }), [
1479
1480
  r,
@@ -1481,6 +1482,19 @@ const Bt = (t, e, n) => {
1481
1482
  i,
1482
1483
  u
1483
1484
  ]);
1485
+ }, je = (t, e, n) => {
1486
+ const r = s(
1487
+ (i) => i.setPreviewStartPreviewFunction
1488
+ ), o = s(
1489
+ (i) => i.setPreviewStopPreviewFunction
1490
+ );
1491
+ S(() => (r(t), o(e), () => {
1492
+ r(null), o(null);
1493
+ }), [
1494
+ n,
1495
+ r,
1496
+ o
1497
+ ]);
1484
1498
  };
1485
1499
  function Qt(t) {
1486
1500
  const e = {};
@@ -1513,7 +1527,7 @@ function Xt(t) {
1513
1527
  Object.assign(e, Kt(n));
1514
1528
  return e;
1515
1529
  }
1516
- function je(t) {
1530
+ function Oe(t) {
1517
1531
  const n = dt()((r) => ({
1518
1532
  ...Xt(t)
1519
1533
  }));
@@ -1539,14 +1553,14 @@ const ee = [
1539
1553
  "mode:1",
1540
1554
  "workflow:1"
1541
1555
  ];
1542
- function Oe({
1556
+ function $e({
1543
1557
  children: t,
1544
1558
  contracts: e,
1545
1559
  loadOnlyWhenReady: n = !0,
1546
1560
  activitySettingsStore: r
1547
1561
  }) {
1548
1562
  const o = s((i) => i.ready);
1549
- return w(() => {
1563
+ return S(() => {
1550
1564
  const i = [...e];
1551
1565
  for (const u of ee)
1552
1566
  i.includes(u) || i.push(u);
@@ -1556,17 +1570,17 @@ function Oe({
1556
1570
  t
1557
1571
  ] });
1558
1572
  }
1559
- function $e({ message: t }) {
1573
+ function Ne({ message: t }) {
1560
1574
  return _t(t, [t]), null;
1561
1575
  }
1562
1576
  export {
1563
- Oe as Capytale,
1564
- $e as TemporaryToast,
1565
- je as createActivitySettingsStore,
1577
+ $e as Capytale,
1578
+ Ne as TemporaryToast,
1579
+ Oe as createActivitySettingsStore,
1566
1580
  Je as useAfterSaveAction,
1567
1581
  Ge as useCanSave,
1568
1582
  zt as useClearToast,
1569
- Me as useClearToasts,
1583
+ Le as useClearToasts,
1570
1584
  Ce as useGetLoadedJsonActivityContent,
1571
1585
  Se as useGetLoadedJsonActivitySplitContent,
1572
1586
  ye as useGetLoadedJsonAssignmentContent,
@@ -1589,9 +1603,10 @@ export {
1589
1603
  ce as useLoadedTextContent,
1590
1604
  re as useMode,
1591
1605
  le as useNotifyIsDirty,
1606
+ je as usePreviewAsStudent,
1592
1607
  ke as usePreviewImageFile,
1593
1608
  Te as usePreviewTextFile,
1594
- Le as useQuickActions,
1609
+ Pe as useQuickActions,
1595
1610
  ae as useRequestSave,
1596
1611
  Bt as useSettings,
1597
1612
  Ht as useShowToast,
@@ -1599,6 +1614,6 @@ export {
1599
1614
  Ae as useTextContentSaveFunction,
1600
1615
  ie as useTheme,
1601
1616
  _t as useToast,
1602
- Pe as useTriggerSave,
1617
+ Me as useTriggerSave,
1603
1618
  se as useWorkflow
1604
1619
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capytale/iframe-react",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",