@capytale/iframe-react 1.1.11 → 1.1.13

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"),v=require("react");const X=Symbol("Comlink.proxy"),gt=Symbol("Comlink.endpoint"),pt=Symbol("Comlink.releaseProxy"),N=Symbol("Comlink.finalizer"),G=Symbol("Comlink.thrown"),Z=t=>typeof t=="object"&&t!==null||typeof t=="function",mt={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)}},yt={canHandle:t=>Z(t)&&G 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",mt],["throw",yt]]);function Ct(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 s(o){if(!o||!o.data)return;if(!Ct(n,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}const{id:r,type:g,path:c}=Object.assign({path:[]},o.data),f=(o.data.argumentList||[]).map(k);let d;try{const u=c.slice(0,-1).reduce((y,S)=>y[S],t),p=c.reduce((y,S)=>y[S],t);switch(g){case"GET":d=p;break;case"SET":u[c.slice(-1)[0]]=k(o.data.value),d=!0;break;case"APPLY":d=p.apply(u,f);break;case"CONSTRUCT":{const y=new p(...f);d=st(y)}break;case"ENDPOINT":{const{port1:y,port2:S}=new MessageChannel;z(t,S),d=ht(y,[y])}break;case"RELEASE":d=void 0;break;default:return}}catch(u){d={value:u,[G]:0}}Promise.resolve(d).catch(u=>({value:u,[G]:0})).then(u=>{const[p,y]=$(u);e.postMessage(Object.assign(Object.assign({},p),{id:r}),y),g==="RELEASE"&&(e.removeEventListener("message",s),et(e),N in t&&typeof t[N]=="function"&&t[N]())}).catch(u=>{const[p,y]=$({value:new TypeError("Unserializable return value"),[G]:0});e.postMessage(Object.assign(Object.assign({},p),{id:r}),y)})}),e.start&&e.start()}function vt(t){return t.constructor.name==="MessagePort"}function et(t){vt(t)&&t.close()}function nt(t,e){const n=new Map;return t.addEventListener("message",function(o){const{data:r}=o;if(!r||!r.id)return;const g=n.get(r.id);if(g)try{g(r)}finally{n.delete(r.id)}}),H(t,n,[],e)}function P(t){if(t)throw new Error("Proxy has been released and is not useable")}function ot(t){return x(t,new Map,{type:"RELEASE"}).then(()=>{et(t)})}const I=new WeakMap,j="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{const e=(I.get(t)||0)-1;I.set(t,e),e===0&&ot(t)});function St(t,e){const n=(I.get(e)||0)+1;I.set(e,n),j&&j.register(t,e,t)}function wt(t){j&&j.unregister(t)}function H(t,e,n=[],s=function(){}){let o=!1;const r=new Proxy(s,{get(g,c){if(P(o),c===pt)return()=>{wt(r),ot(t),e.clear(),o=!0};if(c==="then"){if(n.length===0)return{then:()=>r};const f=x(t,e,{type:"GET",path:n.map(d=>d.toString())}).then(k);return f.then.bind(f)}return H(t,e,[...n,c])},set(g,c,f){P(o);const[d,u]=$(f);return x(t,e,{type:"SET",path:[...n,c].map(p=>p.toString()),value:d},u).then(k)},apply(g,c,f){P(o);const d=n[n.length-1];if(d===gt)return x(t,e,{type:"ENDPOINT"}).then(k);if(d==="bind")return H(t,e,n.slice(0,-1));const[u,p]=U(f);return x(t,e,{type:"APPLY",path:n.map(y=>y.toString()),argumentList:u},p).then(k)},construct(g,c){P(o);const[f,d]=U(c);return x(t,e,{type:"CONSTRUCT",path:n.map(u=>u.toString()),argumentList:f},d).then(k)}});return St(r,t),r}function At(t){return Array.prototype.concat.apply([],t)}function U(t){const e=t.map($);return[e.map(n=>n[0]),At(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 bt(t,e=globalThis,n="*"){return{postMessage:(s,o)=>t.postMessage(s,n,o),addEventListener:e.addEventListener.bind(e),removeEventListener:e.removeEventListener.bind(e)}}function $(t){for(const[e,n]of tt)if(n.canHandle(t)){const[s,o]=n.serialize(t);return[{type:"HANDLER",name:e,value:s},o]}return[{type:"RAW",value:t},rt.get(t)||[]]}function k(t){switch(t.type){case"HANDLER":return tt.get(t.name).deserialize(t.value);case"RAW":return t.value}}function x(t,e,n,s){return new Promise(o=>{const r=Et();e.set(r,o),t.start&&t.start(),t.postMessage(Object.assign({id:r},n),s)})}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 kt(t,e){let n=!1,s,o,r;function g(u){return Jt(t,u)}let c,f=!1;if(window.parent===window)console.warn(g("Contract link is not supported in standalone mode")),c={ready(){return Promise.resolve()},declare(){return Promise.resolve()},done(){return Promise.resolve()},provide(u,p,y){return Promise.resolve()}};else{const u=bt(window.parent,void 0,e);z({declare(p){if(s==null)throw new Error(g("No handler for declare"));s(p)},done(){if(o==null)throw new Error(g("No handler for done"));o()},provide(p,y,S){if(r==null)throw new Error(g("No handler for provide"));r(p,y,S)}},u),c=nt(u),f=!0}const d=()=>{if(!n){if(s==null||o==null||r==null)return;n=!0,c.ready()}};return{declare:u=>c.declare(u),done:()=>c.done(),provide:(u,p,y)=>c.provide(u,p,st(y)),get name(){return t},get isReady(){return f},set onDeclare(u){s=u,d()},set onDone(u){o=u,d()},set onProvide(u){r=u,d()}}}function Ft(t){return function(e){let n,s=!1,o=!1,r,g,c=!1,f=!1,d,u,p,y;function S(){if(r!=null&&r!==0&&g!=null)return g}function E(a){if(r!=null&&g!=null&&!(a>r))return g}function h(){return p??(f?p=Promise.resolve():p=new Promise((a,l)=>{y=a}))}function F(){return d===void 0&&(d={get name(){return e},get version(){return r},get i(){return S()},v:a=>E(a)}),d}function R(){return u===void 0&&(u={get name(){return e},get version(){return f?r:void 0},get i(){return f?S():void 0},v:a=>f?E(a):void 0,get promise(){return r===0?Promise.reject(t("Remote interface not provided")):h().then(()=>{if(r===0)throw new Error(t("Remote interface not provided"));return F()})}}),u}function J(){y!=null&&(y(),y=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 s},set localVersionSent(a){if(!a&&s)throw new Error(t("Local version already notified"));s=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(r!=null)return r},set remoteVersion(a){if(r!=null&&r!==a)throw new Error(t("A different remote version is already set for "+e+`(${r} -> ${a})`));r=a,a===0&&(c=!0)},get remoteVersionReceived(){return r!=null},setRemoteInterface:a=>{if(r==null)throw new Error(t("Remote version not set"));if(r===0){console.warn(t("Remote version is 0, remote interface is ignored."));return}if(c)throw new Error(t("Interface already provided."));g=a,c=!0},get remoteInterfaceReceived(){return c},depGroup:void 0,get isActivable(){return c&&o},get isActivated(){return f},activate(){if(!f){if(!c)throw new Error(t("Remote interface not provided."));if(!o)throw new Error(t("Local interface not sent"));f=!0,J()}},getRemote:()=>F(),getLazyRemote:()=>R(),get activationPromise(){return h()}}}}function Tt(t){return function(e,n,s,o){let r=s,g=!1,c=!1;function f(){return e.every(d=>d.remoteVersionReceived&&d.localVersionSent)&&n.every(d=>d.remoteVersionReceived)}return{get isDeclared(){return c},set isDeclared(d){if(!d&&c)throw new Error(t("Factory already declared"));c=d},get isReady(){return f()},get isDone(){return g},get args(){return e},get deps(){return n},invoke(){if(g)throw new Error(t("Factory already invoked"));if(!f())throw new Error(t("Factory is not ready"));let d;o?d=e.map(y=>y.getRemote()):d=e[0].getRemote();let u;const p=n.length>0?n.map(y=>y.getRemote()):null;try{u=p==null?r(d):r(d,p)}catch(y){throw new Error(t("error in factory:"),{cause:y})}if(o||(u=[u]),u.length!=e.length)throw new Error(t("Invalid factory result"));return g=!0,r=null,u}}}}function xt(t){return function(e,n,s,o){let r=n,g=!1;function c(){return e.every(f=>f.isActivated)}return{get isReady(){return c()},get isDone(){return g},get args(){return e},invoke(){if(g||!c()){const u=new Error(t(g?"callback already invoked":"callback parameters are not ready"));throw o?.[1](u),u}const f=s?e.map(u=>u.getRemote()):e[0].getRemote();let d;try{d=r(f)}catch(u){o==null?console.error(t("error in callback:"),u):o[1](u)}finally{g=!0}o?.[0](d)}}}}function at(t,e){return t==null||t.length===0?e:`[${t}] ${e}`}function Rt(t){function e(a){return at(t.name,a)}const n=xt(e),s=Ft(e),o=Tt(e),r={},g=[];let c=[],f;const d=()=>(f==null?f=0:f++,f);function u(a){let l=r[a];return l==null&&(l=s(a),l.localVersion==null&&(h&&(l.localVersion=0),F&&(l.localVersionSent=!0)),l.remoteVersion==null&&R&&(l.remoteVersion=0),r[a]=l),l}function p(a){return a.map(u)}function y(...a){const l=d(),m=Array(l).fill(!1);a.forEach(C=>{C.forEach(w=>{w.depGroup!=null&&(m[w.depGroup]=!0),w.depGroup=l})}),Object.values(r).forEach(C=>{C.depGroup!=null&&C.depGroup!==l&&m[C.depGroup]&&(C.depGroup=l)})}t.onDeclare=a=>{const l=p(a.map(m=>m.name));for(let m=0;m<a.length;m++)a[m].version!=null&&(l[m].remoteVersion=a[m].version);y(l),J()},t.onDone=()=>{R||(R=!0,Object.values(r).forEach(a=>{a.remoteVersion==null&&(a.remoteVersion=0)}),J())},t.onProvide=(a,l,m)=>{let C=r[a];if(C==null)throw new Error(e(`Contract not declared : ${a}`));if(C.remoteVersion!=l)throw new Error(e(`Remote declared version ${C.remoteVersion} of contract "${a}" but provided version ${l}.`));if(C.remoteInterfaceReceived)throw new Error(e(`Remote contract "${a}" is already provided.`));C.setRemoteInterface(m),J()};let S=!1,E=!1,h=!1,F=!1,R=!1;async function J(){if(E=!0,!S){for(S=!0;E;){if(E=!1,t.isReady){const a=g.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((C,w)=>m[w]=C),l.deps.forEach((C,w)=>m[w+l.args.length]=C),await t.declare(m.map(C=>({name:C.name,version:C.localVersion}))),m.forEach(C=>{C.localVersion!=null&&(C.localVersionSent=!0)}),l.isDeclared=!0}}if(t.isReady&&h&&g.every(a=>a.isDeclared)){const a=Object.values(r).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;F||(F=!0,await t.done())}if(t.isReady){const a=g.filter(l=>!l.isDone&&l.isReady);if(a.length>0)for(const l of a){const m=l.invoke();for(let C=0;C<l.args.length;C++){const w=l.args[C];await t.provide(w.name,w.localVersion,m[C]),w.localInterfaceSent=!0}}}if(f!=null){const a=Array(f+1).fill(null);for(const l in r){const m=r[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 r){const m=r[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 u(a)},declareFactory:(a,l,m,C)=>{if(h)throw new Error(e("Cannot declare a factory after done has been set to true."));const w=p(a.map(b=>b.name));{const b=w.filter(O=>O.localVersion!=null);if(b.length>0)throw new Error(e("Cannot declare a factory for already implemented contracts : "+b.map(O=>O.name).join(", ")))}for(let b=0;b<a.length;b++)w[b].localVersion=a[b].version;const T=p(l);y(w,T);const ft=o(w,T,m,C);g.push(ft),J()},declareCallback(a,l,m,C){const w=p(a),T=n(w,l,m,C);!S&&c.length===0&&T.isReady?T.invoke():(c.push(T),J())},get done(){return h},set done(a){if(h){if(!a)throw new Error(e("Cannot set done to false after it has been set to true."))}else a&&(h=!0,Object.values(r).forEach(l=>{l.localVersion==null&&(l.localVersion=0)}),J())}}}const Lt=/^\d+$/;function Pt(t){const[e,n,s]=t.split(":",3);if(n==null||s!=null||!Lt.test(n))return null;const o=parseInt(n);return isNaN(o)||o===0?null:{name:e,version:o}}function Mt(t){const e=Rt(t);function n(s){return at(t.name,s)}return{plug(s,o,r=void 0){if(e.done)throw new Error(n("Cannot plug after plugsDone."));r==null&&(r=o,o=[]);let g=!0;Array.isArray(s)||(s=[s],g=!1);const c=s.map(f=>{const d=Pt(f);if(d==null)throw new Error(n("Invalid contract id : "+f));return d});e.declareFactory(c,o,r,g)},plugsDone(){e.done=!0},use(s,o){let r=!0;Array.isArray(s)||(s=[s],r=!1),e.declareCallback(s,o,r)},exec(s,o){let r=!0;return Array.isArray(s)||(s=[s],r=!1),new Promise((...g)=>{e.declareCallback(s,o,r,g)})},get(s){return s.map(o=>e.get(o).getLazyRemote())}}}const it="app-agent";let q;function Vt(t){return q!=null||(q=Mt(kt(it,t))),q}console.log(`[${it}@1.0.12] loaded`);const Q=t=>{let e;const n=new Set,s=(d,u)=>{const p=typeof d=="function"?d(e):d;if(!Object.is(p,e)){const y=e;e=u??(typeof p!="object"||p===null)?p:Object.assign({},e,p),n.forEach(S=>S(e,y))}},o=()=>e,c={setState:s,getState:o,getInitialState:()=>f,subscribe:d=>(n.add(d),()=>n.delete(d))},f=e=t(s,o,c);return c},Dt=t=>t?Q(t):Q,Gt=t=>t;function It(t,e=Gt){const n=v.useSyncExternalStore(t.subscribe,v.useCallback(()=>e(t.getState()),[t,e]),v.useCallback(()=>e(t.getInitialState()),[t,e]));return v.useDebugValue(n),n}const _=t=>{const e=Dt(t),n=s=>It(e,s);return Object.assign(n,e),n},ct=t=>t?_(t):_,jt=t=>(e,n,s)=>{const o=s.subscribe;return s.subscribe=(g,c,f)=>{let d=g;if(c){const u=f?.equalityFn||Object.is;let p=g(s.getState());d=y=>{const S=g(y);if(!u(p,S)){const E=p;c(p=S,E)}},f?.fireImmediately&&c(p,p)}return o(d)},t(e,n,s)},$t=jt,i=ct()($t(t=>({ready:!1,workflow:"current",mode:"assignment",theme:"light",saveCount:0,afterSaveCount:0,isDirtyCount:0,loadedTextContent:null,loadedJsonContent:null,loadedJsonActivityContent:null,loadedJsonAssignmentContent:null,loadedJsonActivityBinaryData:null,loadedJsonAssignmentBinaryData:null,getTextContentFunction:()=>{throw console.error("getTextContentFunction is not set"),new Error("getTextContentFunction is not set")},getJsonContentFunction:()=>{throw console.error("getJsonContentFunction is not set"),new Error("getJsonContentFunction is not set")},getJsonActivityContentFunction:()=>{throw console.error("getJsonActivityContentFunction is not set"),new Error("getJsonActivityContentFunction is not set")},getJsonAssignmentContentFunction:()=>{throw console.error("getJsonAssignmentContentFunction is not set"),new Error("getJsonAssignmentContentFunction is not set")},getJsonActivitySplitContentFunction:()=>{throw console.error("getJsonActivitySplitContentFunction is not set"),new Error("getJsonActivitySplitContentFunction is not set")},getJsonAssignmentSplitContentFunction:()=>{throw console.error("getJsonAssignmentSplitContentFunction is not set"),new Error("getJsonAssignmentSplitContentFunction is not set")},sidebarActions:{},quickActions:{},activitySettingsCallback:null,setGetTextContentFunction:e=>{t({getTextContentFunction: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}))})));let Y=!1;const Ot=["meta-player-events:1","meta-player-ui:1","mode:1","reload:1","theme:1","workflow: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"],K={"mode:1":{setMode:t=>{i.setState({mode:t})}},"reload:1":{reloaded:t=>{console.log("Reloaded with state:",t),console.error("Not implemented yet")}},"theme:1":{setTheme:t=>{if(t===null){i.setState({theme:null});return}if(t!=="light"&&t!=="dark"){console.warn(`Invalid theme: ${t}. Expected 'light' or 'dark'.`),i.setState({theme:null});return}i.setState({theme:t})}},"workflow:1":{setWorkflow:t=>{i.setState({workflow:t})}},"simple-content(text):1":{contentSaved:()=>{i.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>i.getState().getTextContentFunction(),loadContent:t=>{i.setState({loadedTextContent:t})}},"simple-content(json):1":{contentSaved:()=>{i.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>i.getState().getJsonContentFunction(),loadContent:t=>{i.setState({loadedJsonContent:t})}},"simple-binary-data(text):1":{contentSaved:()=>{i.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>i.getState().getTextContentFunction(),loadContent:t=>{i.setState({loadedTextContent:t})}},"simple-content-eval(text):1":{contentSaved:()=>{i.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>i.getState().getTextContentFunction(),loadContent:t=>{i.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{i.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>i.getState().getJsonContentFunction(),loadContent:t=>{i.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(json):2":{contentSaved:()=>{i.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>i.getState().getJsonContentFunction(),loadContent:t=>{i.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(text):2":{contentSaved:()=>{i.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>i.getState().getTextContentFunction(),loadContent:t=>{i.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"separate-contents(json):1":{contentSaved:()=>{i.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{i.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>i.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>i.getState().getJsonAssignmentContentFunction()},"separate-dual-contents(json):1":{contentSaved:()=>{i.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:({activityContent:t,assignmentContent:e,activityBinaryData:n,assignmentBinaryData:s})=>{i.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e,loadedJsonActivityBinaryData:n,loadedJsonAssignmentBinaryData:s})},getActivityContentAndData:()=>i.getState().getJsonActivitySplitContentFunction(),getAssignmentContentAndData:()=>i.getState().getJsonAssignmentSplitContentFunction()},"meta-player-anti-cheat:1":{lock:()=>{},unlock:()=>{}},"meta-player-ui:1":{executeAction(t){if(t.startsWith("qa")){const n=i.getState().quickActions[t];n?n():console.error(`Quick action not found: ${t}`)}else{const n=i.getState().sidebarActions[t];n?n():console.error(`Sidebar action not found: ${t}`)}},executeFileUpload(t,e){if(t.startsWith("qa")){const s=i.getState().quickActions[t];s?s(e):console.error(`Quick action not found: ${t}`)}else{const s=i.getState().sidebarActions[t];s?s(e):console.error(`Sidebar action not found: ${t}`)}},updateSettings(t){const e=i.getState().activitySettingsCallback;e?e(t):console.warn("activitySettingsCallback is not set. Changes:",t)}},"meta-player-events:1":{handleEvent(t){t==="all-loaded"&&i.setState({ready:!0})}}},A=Vt();function Nt(t){if(Y){console.warn("Contracts have already been plugged. Skipping.");return}Y=!0;for(const e of t){if(!Ot.includes(e)){console.warn(`Contract ${e} is not implemented in Capytale. Skipping plug.`);continue}if(!(e in K)){console.warn(`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"])if(console.log(`Contract ${e} is being subscribed to content changes.`),t.includes(e)){console.log(`Subscribing to content changes for contract ${e}`);const n=e.split(":")[0];A.use([n],([s])=>{i.subscribe(o=>o.isDirtyCount,()=>{s.i?.contentChanged(),console.log(`Content changed for contract ${n}`)})})}}const qt=()=>i(t=>{if(t.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return t.mode}),Bt=()=>i(t=>{if(t.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return t.workflow}),Wt=()=>i(t=>{if(t.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return t.theme}),Ht=()=>i(t=>t.incSaveCount),zt=()=>i(t=>t.incDirtyCount),Ut=()=>i(t=>t.loadedTextContent),Qt=()=>i(t=>t.loadedJsonContent),_t=()=>i(t=>t.loadedJsonActivityContent),Yt=()=>i(t=>t.loadedJsonAssignmentContent),Kt=()=>i(t=>t.loadedJsonActivityBinaryData),Xt=()=>i(t=>t.loadedJsonAssignmentBinaryData),Zt=()=>v.useCallback(()=>i.getState().loadedTextContent,[]),te=()=>v.useCallback(()=>i.getState().loadedJsonContent,[]),ee=()=>v.useCallback(()=>i.getState().loadedJsonActivityContent,[]),ne=()=>v.useCallback(()=>i.getState().loadedJsonAssignmentContent,[]),oe=()=>v.useCallback(()=>({content:i.getState().loadedJsonActivityContent,binaryData:i.getState().loadedJsonActivityBinaryData}),[]),re=()=>v.useCallback(()=>({content:i.getState().loadedJsonAssignmentContent,binaryData:i.getState().loadedJsonAssignmentBinaryData}),[]),se=t=>{const e=i(n=>n.setGetTextContentFunction);v.useEffect(()=>{e(t)},[t,e])},ae=t=>{const e=i(n=>n.setGetJsonContentFunction);v.useEffect(()=>{e(t)},[t,e])},ie=t=>{const e=i(n=>n.setGetJsonActivityContentFunction);v.useEffect(()=>{e(t)},[t,e])},ce=t=>{const e=i(n=>n.setGetJsonAssignmentContentFunction);v.useEffect(()=>{e(t)},[t,e])},le=t=>{const e=i(n=>n.setGetJsonActivitySplitContentFunction);v.useEffect(()=>{e(t)},[t,e])},ue=t=>{const e=i(n=>n.setGetJsonAssignmentSplitContentFunction);v.useEffect(()=>{e(t)},[t,e])},de=t=>{const e=i(n=>n.afterSaveCount);v.useEffect(()=>{e>0&&t()},[e])},fe=()=>(t,e)=>{A.use(["meta-player-ui"],([n])=>{if(n.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}n.i?.previewTextFile(t,e)})},ge=()=>(t,e)=>{A.use(["meta-player-ui"],([n])=>{if(n.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}n.i?.previewImageFile(t,e)})};let M=0,B=0;const pe=(t,e)=>{const n=v.useMemo(t,e),s=i(o=>o.setSidebarActions);v.useEffect(()=>(M++,M>1&&console.error("Capytale iframe React: Multiple sidebar actions registered: ",M),()=>{M--}),[]),v.useEffect(()=>(A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}B++;const r=n.map((c,f)=>({type:c.type,title:c.title,icon:c.icon,id:`sa-${B}-${f}`,...c.type==="file-upload"?{accept:c.accept}:{}})),g={};n.forEach((c,f)=>{g[`sa-${B}-${f}`]=c.action}),o.i?.setSidebarActionButtons(r),s(g)}),()=>{s({}),A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}o.i?.setSidebarActionButtons([])})}),[n])};let V=0,W=0;const me=(t,e)=>{const n=v.useMemo(t,e),s=i(o=>o.setQuickActions);v.useEffect(()=>(V++,V>1&&console.error("Capytale iframe React: Multiple quick actions registered: ",V),()=>{V--}),[]),v.useEffect(()=>(A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}W++;const r=n.map((c,f)=>({type:c.type,title:c.title,icon:c.icon,id:`qa-${W}-${f}`,...c.type==="file-upload"?{accept:c.accept}:{}})),g={};n.forEach((c,f)=>{g[`qa-${W}-${f}`]=c.action}),o.i?.setQuickActionButtons(r),s(g)}),()=>{s({}),A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("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 s=v.useMemo(t,n),o=i(r=>r.setActivitySettingsCallback);v.useEffect(()=>(console.log("Mounting useSettings"),D++,D>1&&console.error("Capytale iframe React: Multiple settings registered: ",D),()=>{console.log("Unmounting useSettings"),D--}),[]),v.useEffect(()=>(A.use(["meta-player-ui"],([r])=>{if(r.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}console.log("Updating settings UI in MetaPlayer",s),r.i?.setSettingsUI(s)}),o(e),()=>{o(null)}),[s])},ut=()=>v.useCallback(e=>A.exec(["meta-player-ui"],([n])=>{if(n.version===0)throw console.error("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=()=>v.useCallback(e=>A.exec(["meta-player-ui"],([n])=>{if(n.version===0)throw console.error("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)}),[]),ye=()=>v.useCallback(()=>A.exec(["meta-player-ui"],([e])=>{if(e.version===0)throw console.error("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()}),[]);function Ce(t){const e={};for(const n of t.fields)e[n.name]=n.defaultValue;return e}function ve(t){return{[t.name]:t.defaultValues}}function Se(t){return{[t.name]:t.defaultValue}}function we(t){switch(t.type){case"form":return Ce(t);case"checkboxes":case"switches":return ve(t);case"radio":return Se(t);default:return{}}}function Ae(t){const e={};for(const n of t)Object.assign(e,we(n));return e}function he(t){const n=ct()(s=>({...Ae(t)}));return n.activitySettings=t,n}function be(t){lt(()=>t.activitySettings,e=>{t.setState(e)},[])}function Ee({store:t}){return be(t),null}const Je=["meta-player-events:1","mode:1","workflow:1"];function ke({children:t,contracts:e,loadOnlyWhenReady:n=!0,activitySettingsStore:s}){const o=i(r=>r.ready);return v.useEffect(()=>{const r=[...e];for(const g of Je)r.includes(g)||r.push(g);Nt(r)},[]),n&&!o?L.jsx("div",{className:"capy-loading-container",children:"Chargement en cours..."}):L.jsxs(L.Fragment,{children:[s&&L.jsx(Ee,{store:s}),t]})}function Fe({message:t}){const e=ut(),n=dt();v.useEffect(()=>{const s=e(t);return()=>{s.then(o=>{o!=null&&n(o)})}},[t,e,n])}exports.Capytale=ke;exports.TemporaryToast=Fe;exports.createActivitySettingsStore=he;exports.useAfterSaveAction=de;exports.useClearToast=dt;exports.useClearToasts=ye;exports.useGetLoadedJsonActivityContent=ee;exports.useGetLoadedJsonActivitySplitContent=oe;exports.useGetLoadedJsonAssignmentContent=ne;exports.useGetLoadedJsonAssignmentSplitContent=re;exports.useGetLoadedJsonContent=te;exports.useGetLoadedTextContent=Zt;exports.useJsonActivityContentSaveFunction=ie;exports.useJsonActivitySplitContentSaveFunction=le;exports.useJsonAssignmentContentSaveFunction=ce;exports.useJsonAssignmentSplitContentSaveFunction=ue;exports.useJsonContentSaveFunction=ae;exports.useLoadedJsonActivityBinaryData=Kt;exports.useLoadedJsonActivityContent=_t;exports.useLoadedJsonAssignmentBinaryData=Xt;exports.useLoadedJsonAssignmentContent=Yt;exports.useLoadedJsonContent=Qt;exports.useLoadedTextContent=Ut;exports.useMode=qt;exports.useNotifyIsDirty=zt;exports.usePreviewImageFile=ge;exports.usePreviewTextFile=fe;exports.useQuickActions=me;exports.useRequestSave=Ht;exports.useSettings=lt;exports.useShowToast=ut;exports.useSidebarActions=pe;exports.useTextContentSaveFunction=se;exports.useTheme=Wt;exports.useWorkflow=Bt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),v=require("react");const X=Symbol("Comlink.proxy"),ge=Symbol("Comlink.endpoint"),pe=Symbol("Comlink.releaseProxy"),N=Symbol("Comlink.finalizer"),D=Symbol("Comlink.thrown"),Z=e=>typeof e=="object"&&e!==null||typeof e=="function",me={canHandle:e=>Z(e)&&e[X],serialize(e){const{port1:t,port2:n}=new MessageChannel;return z(e,t),[n,[n]]},deserialize(e){return e.start(),ne(e)}},ye={canHandle:e=>Z(e)&&D in e,serialize({value:e}){let t;return e instanceof Error?t={isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:t={isError:!1,value:e},[t,[]]},deserialize(e){throw e.isError?Object.assign(new Error(e.value.message),e.value):e.value}},ee=new Map([["proxy",me],["throw",ye]]);function ve(e,t){for(const n of e)if(t===n||n==="*"||n instanceof RegExp&&n.test(t))return!0;return!1}function z(e,t=globalThis,n=["*"]){t.addEventListener("message",function s(o){if(!o||!o.data)return;if(!ve(n,o.origin)){console.warn(`Invalid origin '${o.origin}' for comlink proxy`);return}const{id:r,type:g,path:c}=Object.assign({path:[]},o.data),f=(o.data.argumentList||[]).map(k);let d;try{const u=c.slice(0,-1).reduce((y,S)=>y[S],e),p=c.reduce((y,S)=>y[S],e);switch(g){case"GET":d=p;break;case"SET":u[c.slice(-1)[0]]=k(o.data.value),d=!0;break;case"APPLY":d=p.apply(u,f);break;case"CONSTRUCT":{const y=new p(...f);d=se(y)}break;case"ENDPOINT":{const{port1:y,port2:S}=new MessageChannel;z(e,S),d=he(y,[y])}break;case"RELEASE":d=void 0;break;default:return}}catch(u){d={value:u,[D]:0}}Promise.resolve(d).catch(u=>({value:u,[D]:0})).then(u=>{const[p,y]=$(u);t.postMessage(Object.assign(Object.assign({},p),{id:r}),y),g==="RELEASE"&&(t.removeEventListener("message",s),te(t),N in e&&typeof e[N]=="function"&&e[N]())}).catch(u=>{const[p,y]=$({value:new TypeError("Unserializable return value"),[D]:0});t.postMessage(Object.assign(Object.assign({},p),{id:r}),y)})}),t.start&&t.start()}function Ce(e){return e.constructor.name==="MessagePort"}function te(e){Ce(e)&&e.close()}function ne(e,t){const n=new Map;return e.addEventListener("message",function(o){const{data:r}=o;if(!r||!r.id)return;const g=n.get(r.id);if(g)try{g(r)}finally{n.delete(r.id)}}),H(e,n,[],t)}function P(e){if(e)throw new Error("Proxy has been released and is not useable")}function oe(e){return x(e,new Map,{type:"RELEASE"}).then(()=>{te(e)})}const I=new WeakMap,j="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{const t=(I.get(e)||0)-1;I.set(e,t),t===0&&oe(e)});function Se(e,t){const n=(I.get(t)||0)+1;I.set(t,n),j&&j.register(e,t,e)}function we(e){j&&j.unregister(e)}function H(e,t,n=[],s=function(){}){let o=!1;const r=new Proxy(s,{get(g,c){if(P(o),c===pe)return()=>{we(r),oe(e),t.clear(),o=!0};if(c==="then"){if(n.length===0)return{then:()=>r};const f=x(e,t,{type:"GET",path:n.map(d=>d.toString())}).then(k);return f.then.bind(f)}return H(e,t,[...n,c])},set(g,c,f){P(o);const[d,u]=$(f);return x(e,t,{type:"SET",path:[...n,c].map(p=>p.toString()),value:d},u).then(k)},apply(g,c,f){P(o);const d=n[n.length-1];if(d===ge)return x(e,t,{type:"ENDPOINT"}).then(k);if(d==="bind")return H(e,t,n.slice(0,-1));const[u,p]=U(f);return x(e,t,{type:"APPLY",path:n.map(y=>y.toString()),argumentList:u},p).then(k)},construct(g,c){P(o);const[f,d]=U(c);return x(e,t,{type:"CONSTRUCT",path:n.map(u=>u.toString()),argumentList:f},d).then(k)}});return Se(r,e),r}function Ae(e){return Array.prototype.concat.apply([],e)}function U(e){const t=e.map($);return[t.map(n=>n[0]),Ae(t.map(n=>n[1]))]}const re=new WeakMap;function he(e,t){return re.set(e,t),e}function se(e){return Object.assign(e,{[X]:!0})}function be(e,t=globalThis,n="*"){return{postMessage:(s,o)=>e.postMessage(s,n,o),addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}function $(e){for(const[t,n]of ee)if(n.canHandle(e)){const[s,o]=n.serialize(e);return[{type:"HANDLER",name:t,value:s},o]}return[{type:"RAW",value:e},re.get(e)||[]]}function k(e){switch(e.type){case"HANDLER":return ee.get(e.name).deserialize(e.value);case"RAW":return e.value}}function x(e,t,n,s){return new Promise(o=>{const r=Ee();t.set(r,o),e.start&&e.start(),e.postMessage(Object.assign({id:r},n),s)})}function Ee(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function Je(e,t){return e.length===0?t:`[${e}] ${t}`}function ke(e,t){let n=!1,s,o,r;function g(u){return Je(e,u)}let c,f=!1;if(window.parent===window)console.warn(g("Contract link is not supported in standalone mode")),c={ready(){return Promise.resolve()},declare(){return Promise.resolve()},done(){return Promise.resolve()},provide(u,p,y){return Promise.resolve()}};else{const u=be(window.parent,void 0,t);z({declare(p){if(s==null)throw new Error(g("No handler for declare"));s(p)},done(){if(o==null)throw new Error(g("No handler for done"));o()},provide(p,y,S){if(r==null)throw new Error(g("No handler for provide"));r(p,y,S)}},u),c=ne(u),f=!0}const d=()=>{if(!n){if(s==null||o==null||r==null)return;n=!0,c.ready()}};return{declare:u=>c.declare(u),done:()=>c.done(),provide:(u,p,y)=>c.provide(u,p,se(y)),get name(){return e},get isReady(){return f},set onDeclare(u){s=u,d()},set onDone(u){o=u,d()},set onProvide(u){r=u,d()}}}function Fe(e){return function(t){let n,s=!1,o=!1,r,g,c=!1,f=!1,d,u,p,y;function S(){if(r!=null&&r!==0&&g!=null)return g}function E(a){if(r!=null&&g!=null&&!(a>r))return g}function h(){return p??(f?p=Promise.resolve():p=new Promise((a,l)=>{y=a}))}function F(){return d===void 0&&(d={get name(){return t},get version(){return r},get i(){return S()},v:a=>E(a)}),d}function R(){return u===void 0&&(u={get name(){return t},get version(){return f?r:void 0},get i(){return f?S():void 0},v:a=>f?E(a):void 0,get promise(){return r===0?Promise.reject(e("Remote interface not provided")):h().then(()=>{if(r===0)throw new Error(e("Remote interface not provided"));return F()})}}),u}function J(){y!=null&&(y(),y=void 0)}return{get name(){return t},get localVersion(){if(n!=null)return n},set localVersion(a){if(n!=null&&n!==a)throw new Error(e("A different local version is already set"));n=a},get localVersionSent(){return s},set localVersionSent(a){if(!a&&s)throw new Error(e("Local version already notified"));s=a,a&&n===0&&(o=!0)},get localInterfaceSent(){return o},set localInterfaceSent(a){if(n==null)throw new Error(e("Local version not set"));if(!a&&o)throw new Error(e("Local interface already sent."));o=a},get remoteVersion(){if(r!=null)return r},set remoteVersion(a){if(r!=null&&r!==a)throw new Error(e("A different remote version is already set for "+t+`(${r} -> ${a})`));r=a,a===0&&(c=!0)},get remoteVersionReceived(){return r!=null},setRemoteInterface:a=>{if(r==null)throw new Error(e("Remote version not set"));if(r===0){console.warn(e("Remote version is 0, remote interface is ignored."));return}if(c)throw new Error(e("Interface already provided."));g=a,c=!0},get remoteInterfaceReceived(){return c},depGroup:void 0,get isActivable(){return c&&o},get isActivated(){return f},activate(){if(!f){if(!c)throw new Error(e("Remote interface not provided."));if(!o)throw new Error(e("Local interface not sent"));f=!0,J()}},getRemote:()=>F(),getLazyRemote:()=>R(),get activationPromise(){return h()}}}}function Te(e){return function(t,n,s,o){let r=s,g=!1,c=!1;function f(){return t.every(d=>d.remoteVersionReceived&&d.localVersionSent)&&n.every(d=>d.remoteVersionReceived)}return{get isDeclared(){return c},set isDeclared(d){if(!d&&c)throw new Error(e("Factory already declared"));c=d},get isReady(){return f()},get isDone(){return g},get args(){return t},get deps(){return n},invoke(){if(g)throw new Error(e("Factory already invoked"));if(!f())throw new Error(e("Factory is not ready"));let d;o?d=t.map(y=>y.getRemote()):d=t[0].getRemote();let u;const p=n.length>0?n.map(y=>y.getRemote()):null;try{u=p==null?r(d):r(d,p)}catch(y){throw new Error(e("error in factory:"),{cause:y})}if(o||(u=[u]),u.length!=t.length)throw new Error(e("Invalid factory result"));return g=!0,r=null,u}}}}function xe(e){return function(t,n,s,o){let r=n,g=!1;function c(){return t.every(f=>f.isActivated)}return{get isReady(){return c()},get isDone(){return g},get args(){return t},invoke(){if(g||!c()){const u=new Error(e(g?"callback already invoked":"callback parameters are not ready"));throw o?.[1](u),u}const f=s?t.map(u=>u.getRemote()):t[0].getRemote();let d;try{d=r(f)}catch(u){o==null?console.error(e("error in callback:"),u):o[1](u)}finally{g=!0}o?.[0](d)}}}}function ae(e,t){return e==null||e.length===0?t:`[${e}] ${t}`}function Re(e){function t(a){return ae(e.name,a)}const n=xe(t),s=Fe(t),o=Te(t),r={},g=[];let c=[],f;const d=()=>(f==null?f=0:f++,f);function u(a){let l=r[a];return l==null&&(l=s(a),l.localVersion==null&&(h&&(l.localVersion=0),F&&(l.localVersionSent=!0)),l.remoteVersion==null&&R&&(l.remoteVersion=0),r[a]=l),l}function p(a){return a.map(u)}function y(...a){const l=d(),m=Array(l).fill(!1);a.forEach(C=>{C.forEach(w=>{w.depGroup!=null&&(m[w.depGroup]=!0),w.depGroup=l})}),Object.values(r).forEach(C=>{C.depGroup!=null&&C.depGroup!==l&&m[C.depGroup]&&(C.depGroup=l)})}e.onDeclare=a=>{const l=p(a.map(m=>m.name));for(let m=0;m<a.length;m++)a[m].version!=null&&(l[m].remoteVersion=a[m].version);y(l),J()},e.onDone=()=>{R||(R=!0,Object.values(r).forEach(a=>{a.remoteVersion==null&&(a.remoteVersion=0)}),J())},e.onProvide=(a,l,m)=>{let C=r[a];if(C==null)throw new Error(t(`Contract not declared : ${a}`));if(C.remoteVersion!=l)throw new Error(t(`Remote declared version ${C.remoteVersion} of contract "${a}" but provided version ${l}.`));if(C.remoteInterfaceReceived)throw new Error(t(`Remote contract "${a}" is already provided.`));C.setRemoteInterface(m),J()};let S=!1,E=!1,h=!1,F=!1,R=!1;async function J(){if(E=!0,!S){for(S=!0;E;){if(E=!1,e.isReady){const a=g.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((C,w)=>m[w]=C),l.deps.forEach((C,w)=>m[w+l.args.length]=C),await e.declare(m.map(C=>({name:C.name,version:C.localVersion}))),m.forEach(C=>{C.localVersion!=null&&(C.localVersionSent=!0)}),l.isDeclared=!0}}if(e.isReady&&h&&g.every(a=>a.isDeclared)){const a=Object.values(r).filter(l=>!l.localVersionSent&&l.localVersion!=null);if(a.length>0)for(const l of a)await e.declare([{name:l.name,version:l.localVersion}]),l.localVersionSent=!0;F||(F=!0,await e.done())}if(e.isReady){const a=g.filter(l=>!l.isDone&&l.isReady);if(a.length>0)for(const l of a){const m=l.invoke();for(let C=0;C<l.args.length;C++){const w=l.args[C];await e.provide(w.name,w.localVersion,m[C]),w.localInterfaceSent=!0}}}if(f!=null){const a=Array(f+1).fill(null);for(const l in r){const m=r[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 r){const m=r[l];m.depGroup!=null&&a[m.depGroup]&&m.activate()}}if(e.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 u(a)},declareFactory:(a,l,m,C)=>{if(h)throw new Error(t("Cannot declare a factory after done has been set to true."));const w=p(a.map(b=>b.name));{const b=w.filter(O=>O.localVersion!=null);if(b.length>0)throw new Error(t("Cannot declare a factory for already implemented contracts : "+b.map(O=>O.name).join(", ")))}for(let b=0;b<a.length;b++)w[b].localVersion=a[b].version;const T=p(l);y(w,T);const fe=o(w,T,m,C);g.push(fe),J()},declareCallback(a,l,m,C){const w=p(a),T=n(w,l,m,C);!S&&c.length===0&&T.isReady?T.invoke():(c.push(T),J())},get done(){return h},set done(a){if(h){if(!a)throw new Error(t("Cannot set done to false after it has been set to true."))}else a&&(h=!0,Object.values(r).forEach(l=>{l.localVersion==null&&(l.localVersion=0)}),J())}}}const Le=/^\d+$/;function Pe(e){const[t,n,s]=e.split(":",3);if(n==null||s!=null||!Le.test(n))return null;const o=parseInt(n);return isNaN(o)||o===0?null:{name:t,version:o}}function Me(e){const t=Re(e);function n(s){return ae(e.name,s)}return{plug(s,o,r=void 0){if(t.done)throw new Error(n("Cannot plug after plugsDone."));r==null&&(r=o,o=[]);let g=!0;Array.isArray(s)||(s=[s],g=!1);const c=s.map(f=>{const d=Pe(f);if(d==null)throw new Error(n("Invalid contract id : "+f));return d});t.declareFactory(c,o,r,g)},plugsDone(){t.done=!0},use(s,o){let r=!0;Array.isArray(s)||(s=[s],r=!1),t.declareCallback(s,o,r)},exec(s,o){let r=!0;return Array.isArray(s)||(s=[s],r=!1),new Promise((...g)=>{t.declareCallback(s,o,r,g)})},get(s){return s.map(o=>t.get(o).getLazyRemote())}}}const ie="app-agent";let q;function Ve(e){return q!=null||(q=Me(ke(ie,e))),q}console.log(`[${ie}@1.0.12] loaded`);const Q=e=>{let t;const n=new Set,s=(d,u)=>{const p=typeof d=="function"?d(t):d;if(!Object.is(p,t)){const y=t;t=u??(typeof p!="object"||p===null)?p:Object.assign({},t,p),n.forEach(S=>S(t,y))}},o=()=>t,c={setState:s,getState:o,getInitialState:()=>f,subscribe:d=>(n.add(d),()=>n.delete(d))},f=t=e(s,o,c);return c},Ge=e=>e?Q(e):Q,De=e=>e;function Ie(e,t=De){const n=v.useSyncExternalStore(e.subscribe,v.useCallback(()=>t(e.getState()),[e,t]),v.useCallback(()=>t(e.getInitialState()),[e,t]));return v.useDebugValue(n),n}const _=e=>{const t=Ge(e),n=s=>Ie(t,s);return Object.assign(n,t),n},ce=e=>e?_(e):_,je=e=>(t,n,s)=>{const o=s.subscribe;return s.subscribe=(g,c,f)=>{let d=g;if(c){const u=f?.equalityFn||Object.is;let p=g(s.getState());d=y=>{const S=g(y);if(!u(p,S)){const E=p;c(p=S,E)}},f?.fireImmediately&&c(p,p)}return o(d)},e(t,n,s)},$e=je,i=ce()($e(e=>({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("getTextContentFunction is not set"),new Error("getTextContentFunction is not set")},getJsonContentFunction:()=>{throw console.error("getJsonContentFunction is not set"),new Error("getJsonContentFunction is not set")},getJsonActivityContentFunction:()=>{throw console.error("getJsonActivityContentFunction is not set"),new Error("getJsonActivityContentFunction is not set")},getJsonAssignmentContentFunction:()=>{throw console.error("getJsonAssignmentContentFunction is not set"),new Error("getJsonAssignmentContentFunction is not set")},getJsonActivitySplitContentFunction:()=>{throw console.error("getJsonActivitySplitContentFunction is not set"),new Error("getJsonActivitySplitContentFunction is not set")},getJsonAssignmentSplitContentFunction:()=>{throw console.error("getJsonAssignmentSplitContentFunction is not set"),new Error("getJsonAssignmentSplitContentFunction is not set")},sidebarActions:{},quickActions:{},activitySettingsCallback:null,setGetTextContentFunction:t=>{e({getTextContentFunction:t})},setGetJsonContentFunction:t=>{e({getJsonContentFunction:t})},setGetJsonActivityContentFunction:t=>{e({getJsonActivityContentFunction:t})},setGetJsonAssignmentContentFunction:t=>{e({getJsonAssignmentContentFunction:t})},setGetJsonActivitySplitContentFunction:t=>{e({getJsonActivitySplitContentFunction:t})},setGetJsonAssignmentSplitContentFunction:t=>{e({getJsonAssignmentSplitContentFunction:t})},setSidebarActions:t=>{e({sidebarActions:t})},setQuickActions:t=>{e({quickActions:t})},setActivitySettingsCallback:t=>{e({activitySettingsCallback:t})},incSaveCount:()=>e(t=>({saveCount:t.saveCount+1})),incDirtyCount:()=>e(t=>({isDirtyCount:t.isDirtyCount+1}))})));let Y=!1;const Oe=["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"],K={"mode:1":{setMode:e=>{i.setState({mode:e})}},"reload:1":{reloaded:e=>{console.log("Reloaded with state:",e),console.error("Not implemented yet")}},"theme:1":{setTheme:e=>{if(e===null){i.setState({theme:null});return}if(e!=="light"&&e!=="dark"){console.warn(`Invalid theme: ${e}. Expected 'light' or 'dark'.`),i.setState({theme:null});return}i.setState({theme:e})}},"workflow:1":{setWorkflow:e=>{i.setState({workflow:e})}},"trigger-save:1":{setCanSave(e){i.setState({canSave:e})}},"simple-content(text):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getTextContentFunction(),loadContent:e=>{i.setState({loadedTextContent:e})}},"simple-content(json):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getJsonContentFunction(),loadContent:e=>{i.setState({loadedJsonContent:e})}},"simple-binary-data(text):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getTextContentFunction(),loadContent:e=>{i.setState({loadedTextContent:e})}},"simple-content-eval(text):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getTextContentFunction(),loadContent:e=>{i.setState({loadedTextContent:e})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getJsonContentFunction(),loadContent:e=>{i.setState({loadedJsonContent:e})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(json):2":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getJsonContentFunction(),loadContent:e=>{i.setState({loadedJsonContent:e})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(text):2":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},getContent:()=>i.getState().getTextContentFunction(),loadContent:e=>{i.setState({loadedTextContent:e})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"separate-contents(json):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},loadContent:(e,t)=>{i.setState({loadedJsonActivityContent:e,loadedJsonAssignmentContent:t})},getActivityContent:()=>i.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>i.getState().getJsonAssignmentContentFunction()},"separate-dual-contents(json):1":{contentSaved:()=>{i.setState(e=>({afterSaveCount:e.afterSaveCount+1}))},loadContent:({activityContent:e,assignmentContent:t,activityBinaryData:n,assignmentBinaryData:s})=>{i.setState({loadedJsonActivityContent:e,loadedJsonAssignmentContent:t,loadedJsonActivityBinaryData:n,loadedJsonAssignmentBinaryData:s})},getActivityContentAndData:()=>(console.log("Getting activity content and data"),i.getState().getJsonActivitySplitContentFunction()),getAssignmentContentAndData:()=>(console.log("Getting assignment content and data"),i.getState().getJsonAssignmentSplitContentFunction())},"meta-player-anti-cheat:1":{lock:()=>{},unlock:()=>{}},"meta-player-ui:1":{executeAction(e){if(console.log("Executing action:",e),e.startsWith("qa")){const n=i.getState().quickActions[e];n?n():console.error(`Quick action not found: ${e}`)}else{const n=i.getState().sidebarActions[e];n?n():console.error(`Sidebar action not found: ${e}`)}},executeFileUpload(e,t){if(e.startsWith("qa")){const s=i.getState().quickActions[e];s?s(t):console.error(`Quick action not found: ${e}`)}else{const s=i.getState().sidebarActions[e];s?s(t):console.error(`Sidebar action not found: ${e}`)}},updateSettings(e){const t=i.getState().activitySettingsCallback;t?t(e):console.warn("activitySettingsCallback is not set. Changes:",e)}},"meta-player-events:1":{handleEvent(e){e==="all-loaded"&&i.setState({ready:!0})}}},A=Ve();function Ne(e){if(console.log("Contracts to plug:",e),Y){console.warn("Contracts have already been plugged. Skipping.");return}Y=!0;for(const t of e){if(!Oe.includes(t)){console.warn(`Contract ${t} is not implemented in Capytale. Skipping plug.`);continue}if(!(t in K)){console.warn(`Contract handler for ${t} is not defined. Skipping plug.`);continue}const n=K[t];A.plug([t],([])=>(console.log(`Contract ${t} plugged.`),[n]))}A.plugsDone();for(const t 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(console.log(`Contract ${t} is being subscribed to content changes.`),e.includes(t)){console.log(`Subscribing to content changes for contract ${t}`);const n=t.split(":")[0];A.use([n],([s])=>{i.subscribe(o=>o.isDirtyCount,()=>{s.i?.contentChanged(),console.log(`Content changed for contract ${n}`)})})}}const qe=()=>i(e=>{if(e.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return e.mode}),Be=()=>i(e=>{if(e.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return e.workflow}),We=()=>i(e=>{if(e.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return e.theme}),He=()=>i(e=>e.incSaveCount),ze=()=>i(e=>e.incDirtyCount),Ue=()=>i(e=>e.loadedTextContent),Qe=()=>i(e=>e.loadedJsonContent),_e=()=>i(e=>e.loadedJsonActivityContent),Ye=()=>i(e=>e.loadedJsonAssignmentContent),Ke=()=>i(e=>e.loadedJsonActivityBinaryData),Xe=()=>i(e=>e.loadedJsonAssignmentBinaryData),Ze=()=>v.useCallback(()=>i.getState().loadedTextContent,[]),et=()=>v.useCallback(()=>i.getState().loadedJsonContent,[]),tt=()=>v.useCallback(()=>i.getState().loadedJsonActivityContent,[]),nt=()=>v.useCallback(()=>i.getState().loadedJsonAssignmentContent,[]),ot=()=>v.useCallback(()=>({content:i.getState().loadedJsonActivityContent,binaryData:i.getState().loadedJsonActivityBinaryData}),[]),rt=()=>v.useCallback(()=>({content:i.getState().loadedJsonAssignmentContent,binaryData:i.getState().loadedJsonAssignmentBinaryData}),[]),st=e=>{const t=i(n=>n.setGetTextContentFunction);v.useEffect(()=>{t(e)},[e,t])},at=e=>{const t=i(n=>n.setGetJsonContentFunction);v.useEffect(()=>{t(e)},[e,t])},it=e=>{const t=i(n=>n.setGetJsonActivityContentFunction);v.useEffect(()=>{t(e)},[e,t])},ct=e=>{const t=i(n=>n.setGetJsonAssignmentContentFunction);v.useEffect(()=>{t(e)},[e,t])},lt=e=>{const t=i(n=>n.setGetJsonActivitySplitContentFunction);v.useEffect(()=>{t(e)},[e,t])},ut=e=>{const t=i(n=>n.setGetJsonAssignmentSplitContentFunction);v.useEffect(()=>{t(e)},[e,t])},dt=e=>{const t=i(n=>n.afterSaveCount);v.useEffect(()=>{t>0&&e()},[t])},ft=()=>(e,t)=>{A.use(["meta-player-ui"],([n])=>{if(n.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}n.i?.previewTextFile(e,t)})},gt=()=>(e,t)=>{A.use(["meta-player-ui"],([n])=>{if(n.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}n.i?.previewImageFile(e,t)})};let M=0,B=0;const pt=(e,t)=>{const n=v.useMemo(e,t),s=i(o=>o.setSidebarActions);v.useEffect(()=>(M++,M>1&&console.error("Capytale iframe React: Multiple sidebar actions registered: ",M),()=>{M--}),[]),v.useEffect(()=>(A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}B++;const r=n.map((c,f)=>({type:c.type,title:c.title,icon:c.icon,id:`sa-${B}-${f}`,...c.type==="file-upload"?{accept:c.accept}:{}})),g={};n.forEach((c,f)=>{g[`sa-${B}-${f}`]=c.action}),o.i?.setSidebarActionButtons(r),s(g)}),()=>{s({}),A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}o.i?.setSidebarActionButtons([])})}),[n])};let V=0,W=0;const mt=(e,t)=>{const n=v.useMemo(e,t),s=i(o=>o.setQuickActions);v.useEffect(()=>(V++,V>1&&console.error("Capytale iframe React: Multiple quick actions registered: ",V),()=>{V--}),[]),v.useEffect(()=>(A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}W++;const r=n.map((c,f)=>({type:c.type,title:c.title,icon:c.icon,id:`qa-${W}-${f}`,...c.type==="file-upload"?{accept:c.accept}:{}})),g={};n.forEach((c,f)=>{g[`qa-${W}-${f}`]=c.action}),o.i?.setQuickActionButtons(r),s(g)}),()=>{s({}),A.use(["meta-player-ui"],([o])=>{if(o.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}o.i?.setQuickActionButtons([])})}),[n])};let G=0;const le=(e,t,n)=>{const s=v.useMemo(e,n),o=i(r=>r.setActivitySettingsCallback);v.useEffect(()=>(console.log("Mounting useSettings"),G++,G>1&&console.error("Capytale iframe React: Multiple settings registered: ",G),()=>{console.log("Unmounting useSettings"),G--}),[]),v.useEffect(()=>(A.use(["meta-player-ui"],([r])=>{if(r.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}console.log("Updating settings UI in MetaPlayer",s),r.i?.setSettingsUI(s)}),o(t),()=>{o(null)}),[s])},ue=()=>v.useCallback(t=>A.exec(["meta-player-ui"],([n])=>{if(n.version===0)throw console.error("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(t)}),[]),de=()=>v.useCallback(t=>A.exec(["meta-player-ui"],([n])=>{if(n.version===0)throw console.error("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(t)}),[]),yt=()=>v.useCallback(()=>A.exec(["meta-player-ui"],([t])=>{if(t.version===0)throw console.error("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 t.i?.clearToasts()}),[]),vt=()=>v.useCallback(()=>A.exec(["trigger-save"],([t])=>{if(t.version===0)throw console.error("Le MétaPlayer ne supporte pas le contrat trigger-save"),new Error("Le MétaPlayer ne supporte pas le contrat trigger-save");return t.i?.triggerSave()}),[]),Ct=()=>i(e=>e.canSave);function St(e){const t={};for(const n of e.fields)t[n.name]=n.defaultValue;return t}function wt(e){return{[e.name]:e.defaultValues}}function At(e){return{[e.name]:e.defaultValue}}function ht(e){switch(e.type){case"form":return St(e);case"checkboxes":case"switches":return wt(e);case"radio":return At(e);default:return{}}}function bt(e){const t={};for(const n of e)Object.assign(t,ht(n));return t}function Et(e){const n=ce()(s=>({...bt(e)}));return n.activitySettings=e,n}function Jt(e){le(()=>e.activitySettings,t=>{e.setState(t)},[])}function kt({store:e}){return Jt(e),null}const Ft=["meta-player-events:1","meta-player-ui:1","mode:1","workflow:1"];function Tt({children:e,contracts:t,loadOnlyWhenReady:n=!0,activitySettingsStore:s}){const o=i(r=>r.ready);return v.useEffect(()=>{const r=[...t];for(const g of Ft)r.includes(g)||r.push(g);Ne(r)},[]),n&&!o?L.jsx("div",{className:"capy-loading-container",children:"Chargement en cours..."}):L.jsxs(L.Fragment,{children:[s&&L.jsx(kt,{store:s}),e]})}function xt({message:e}){const t=ue(),n=de();return v.useEffect(()=>{const s=t(e);return()=>{s.then(o=>{o!=null&&n(o)})}},[e,t,n]),null}exports.Capytale=Tt;exports.TemporaryToast=xt;exports.createActivitySettingsStore=Et;exports.useAfterSaveAction=dt;exports.useCanSave=Ct;exports.useClearToast=de;exports.useClearToasts=yt;exports.useGetLoadedJsonActivityContent=tt;exports.useGetLoadedJsonActivitySplitContent=ot;exports.useGetLoadedJsonAssignmentContent=nt;exports.useGetLoadedJsonAssignmentSplitContent=rt;exports.useGetLoadedJsonContent=et;exports.useGetLoadedTextContent=Ze;exports.useJsonActivityContentSaveFunction=it;exports.useJsonActivitySplitContentSaveFunction=lt;exports.useJsonAssignmentContentSaveFunction=ct;exports.useJsonAssignmentSplitContentSaveFunction=ut;exports.useJsonContentSaveFunction=at;exports.useLoadedJsonActivityBinaryData=Ke;exports.useLoadedJsonActivityContent=_e;exports.useLoadedJsonAssignmentBinaryData=Xe;exports.useLoadedJsonAssignmentContent=Ye;exports.useLoadedJsonContent=Qe;exports.useLoadedTextContent=Ue;exports.useMode=qe;exports.useNotifyIsDirty=ze;exports.usePreviewImageFile=gt;exports.usePreviewTextFile=ft;exports.useQuickActions=mt;exports.useRequestSave=He;exports.useSettings=le;exports.useShowToast=ue;exports.useSidebarActions=pt;exports.useTextContentSaveFunction=st;exports.useTheme=We;exports.useTriggerSave=vt;exports.useWorkflow=Be;
package/dist/index.d.ts CHANGED
@@ -149,7 +149,7 @@ AddIdData<MetaPlayerAntiCheatV1, {
149
149
  }>
150
150
  ]>;
151
151
 
152
- declare type ForcedContactNames = "meta-player-events:1" | "mode:1" | "workflow:1";
152
+ declare type ForcedContactNames = "meta-player-events:1" | "mode:1" | "workflow:1" | "meta-player-ui:1";
153
153
 
154
154
  declare type FormField = (ActivitySettingsRange | ActivitySettingsInput | ActivitySettingsNumberInput | ActivitySettingsTextArea | ActivitySettingsOption | ActivitySettingsSelect) & {
155
155
  label: string;
@@ -268,12 +268,14 @@ declare type MPToastMessage = {
268
268
 
269
269
  export declare function TemporaryToast({ message }: {
270
270
  message: MPToastMessage;
271
- }): void;
271
+ }): null;
272
272
 
273
273
  declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
274
274
 
275
275
  export declare const useAfterSaveAction: (fn: () => any) => void;
276
276
 
277
+ export declare const useCanSave: () => boolean;
278
+
277
279
  export declare const useClearToast: () => (id: Awaited<ReturnType<ReturnType<typeof useShowToast>>>) => Promise<void>;
278
280
 
279
281
  export declare const useClearToasts: () => () => Promise<void>;
@@ -340,6 +342,8 @@ export declare const useTextContentSaveFunction: (fn: () => string | null | Prom
340
342
 
341
343
  export declare const useTheme: () => "light" | "dark";
342
344
 
345
+ export declare const useTriggerSave: () => () => Promise<boolean>;
346
+
343
347
  export declare const useWorkflow: () => "current" | "finished" | "corrected";
344
348
 
345
349
  export { }
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as Q, jsxs as gt, Fragment as pt } from "react/jsx-runtime";
2
- import P, { useCallback as E, useEffect as w, useMemo as U } from "react";
2
+ import V, { useCallback as A, useEffect as w, useMemo as U } from "react";
3
3
  const et = Symbol("Comlink.proxy"), mt = Symbol("Comlink.endpoint"), yt = Symbol("Comlink.releaseProxy"), q = Symbol("Comlink.finalizer"), I = Symbol("Comlink.thrown"), nt = (t) => typeof t == "object" && t !== null || typeof t == "function", vt = {
4
4
  canHandle: (t) => nt(t) && t[et],
5
5
  serialize(t) {
@@ -115,7 +115,7 @@ function M(t) {
115
115
  if (t)
116
116
  throw new Error("Proxy has been released and is not useable");
117
117
  }
118
- function it(t) {
118
+ function at(t) {
119
119
  return R(t, /* @__PURE__ */ new Map(), {
120
120
  type: "RELEASE"
121
121
  }).then(() => {
@@ -124,7 +124,7 @@ function it(t) {
124
124
  }
125
125
  const j = /* @__PURE__ */ new WeakMap(), $ = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
126
126
  const e = (j.get(t) || 0) - 1;
127
- j.set(t, e), e === 0 && it(t);
127
+ j.set(t, e), e === 0 && at(t);
128
128
  });
129
129
  function ht(t, e) {
130
130
  const n = (j.get(e) || 0) + 1;
@@ -140,7 +140,7 @@ function z(t, e, n = [], s = function() {
140
140
  get(g, c) {
141
141
  if (M(o), c === yt)
142
142
  return () => {
143
- At(r), it(t), e.clear(), o = !0;
143
+ At(r), at(t), e.clear(), o = !0;
144
144
  };
145
145
  if (c === "then") {
146
146
  if (n.length === 0)
@@ -197,9 +197,9 @@ function Y(t) {
197
197
  const e = t.map(O);
198
198
  return [e.map((n) => n[0]), bt(e.map((n) => n[1]))];
199
199
  }
200
- const at = /* @__PURE__ */ new WeakMap();
200
+ const it = /* @__PURE__ */ new WeakMap();
201
201
  function Et(t, e) {
202
- return at.set(t, e), t;
202
+ return it.set(t, e), t;
203
203
  }
204
204
  function ct(t) {
205
205
  return Object.assign(t, { [et]: !0 });
@@ -229,7 +229,7 @@ function O(t) {
229
229
  type: "RAW",
230
230
  value: t
231
231
  },
232
- at.get(t) || []
232
+ it.get(t) || []
233
233
  ];
234
234
  }
235
235
  function F(t) {
@@ -324,13 +324,13 @@ function Tt(t) {
324
324
  if (r != null && r !== 0 && g != null)
325
325
  return g;
326
326
  }
327
- function k(i) {
328
- if (r != null && g != null && !(i > r))
327
+ function k(a) {
328
+ if (r != null && g != null && !(a > r))
329
329
  return g;
330
330
  }
331
- function A() {
332
- return p ?? (f ? p = Promise.resolve() : p = new Promise((i, l) => {
333
- y = i;
331
+ function b() {
332
+ return p ?? (f ? p = Promise.resolve() : p = new Promise((a, l) => {
333
+ y = a;
334
334
  }));
335
335
  }
336
336
  function x() {
@@ -344,10 +344,10 @@ function Tt(t) {
344
344
  get i() {
345
345
  return C();
346
346
  },
347
- v: (i) => k(i)
347
+ v: (a) => k(a)
348
348
  }), d;
349
349
  }
350
- function V() {
350
+ function P() {
351
351
  return u === void 0 && (u = {
352
352
  get name() {
353
353
  return e;
@@ -358,9 +358,9 @@ function Tt(t) {
358
358
  get i() {
359
359
  return f ? C() : void 0;
360
360
  },
361
- v: (i) => f ? k(i) : void 0,
361
+ v: (a) => f ? k(a) : void 0,
362
362
  get promise() {
363
- return r === 0 ? Promise.reject(t("Remote interface not provided")) : A().then(() => {
363
+ return r === 0 ? Promise.reject(t("Remote interface not provided")) : b().then(() => {
364
364
  if (r === 0) throw new Error(t("Remote interface not provided"));
365
365
  return x();
366
366
  });
@@ -378,44 +378,44 @@ function Tt(t) {
378
378
  if (n != null)
379
379
  return n;
380
380
  },
381
- set localVersion(i) {
382
- if (n != null && n !== i) throw new Error(t("A different local version is already set"));
383
- n = i;
381
+ set localVersion(a) {
382
+ if (n != null && n !== a) throw new Error(t("A different local version is already set"));
383
+ n = a;
384
384
  },
385
385
  get localVersionSent() {
386
386
  return s;
387
387
  },
388
- set localVersionSent(i) {
389
- if (!i && s) throw new Error(t("Local version already notified"));
390
- s = i, i && n === 0 && (o = !0);
388
+ set localVersionSent(a) {
389
+ if (!a && s) throw new Error(t("Local version already notified"));
390
+ s = a, a && n === 0 && (o = !0);
391
391
  },
392
392
  get localInterfaceSent() {
393
393
  return o;
394
394
  },
395
- set localInterfaceSent(i) {
395
+ set localInterfaceSent(a) {
396
396
  if (n == null) throw new Error(t("Local version not set"));
397
- if (!i && o) throw new Error(t("Local interface already sent."));
398
- o = i;
397
+ if (!a && o) throw new Error(t("Local interface already sent."));
398
+ o = a;
399
399
  },
400
400
  get remoteVersion() {
401
401
  if (r != null)
402
402
  return r;
403
403
  },
404
- set remoteVersion(i) {
405
- if (r != null && r !== i) throw new Error(t("A different remote version is already set for " + e + `(${r} -> ${i})`));
406
- r = i, i === 0 && (c = !0);
404
+ set remoteVersion(a) {
405
+ if (r != null && r !== a) throw new Error(t("A different remote version is already set for " + e + `(${r} -> ${a})`));
406
+ r = a, a === 0 && (c = !0);
407
407
  },
408
408
  get remoteVersionReceived() {
409
409
  return r != null;
410
410
  },
411
- setRemoteInterface: (i) => {
411
+ setRemoteInterface: (a) => {
412
412
  if (r == null) throw new Error(t("Remote version not set"));
413
413
  if (r === 0) {
414
414
  console.warn(t("Remote version is 0, remote interface is ignored."));
415
415
  return;
416
416
  }
417
417
  if (c) throw new Error(t("Interface already provided."));
418
- g = i, c = !0;
418
+ g = a, c = !0;
419
419
  },
420
420
  get remoteInterfaceReceived() {
421
421
  return c;
@@ -435,9 +435,9 @@ function Tt(t) {
435
435
  }
436
436
  },
437
437
  getRemote: () => x(),
438
- getLazyRemote: () => V(),
438
+ getLazyRemote: () => P(),
439
439
  get activationPromise() {
440
- return A();
440
+ return b();
441
441
  }
442
442
  };
443
443
  };
@@ -490,7 +490,7 @@ function Rt(t) {
490
490
  };
491
491
  };
492
492
  }
493
- function Vt(t) {
493
+ function Pt(t) {
494
494
  return function(e, n, s, o) {
495
495
  let r = n, g = !1;
496
496
  function c() {
@@ -528,23 +528,23 @@ function Vt(t) {
528
528
  function lt(t, e) {
529
529
  return t == null || t.length === 0 ? e : `[${t}] ${e}`;
530
530
  }
531
- function Pt(t) {
532
- function e(i) {
533
- return lt(t.name, i);
531
+ function Vt(t) {
532
+ function e(a) {
533
+ return lt(t.name, a);
534
534
  }
535
- const n = Vt(e), s = Tt(e), o = Rt(e), r = {}, g = [];
535
+ const n = Pt(e), s = Tt(e), o = Rt(e), r = {}, g = [];
536
536
  let c = [], f;
537
537
  const d = () => (f == null ? f = 0 : f++, f);
538
- function u(i) {
539
- let l = r[i];
540
- return l == null && (l = s(i), l.localVersion == null && (A && (l.localVersion = 0), x && (l.localVersionSent = !0)), l.remoteVersion == null && V && (l.remoteVersion = 0), r[i] = l), l;
538
+ function u(a) {
539
+ let l = r[a];
540
+ return l == null && (l = s(a), l.localVersion == null && (b && (l.localVersion = 0), x && (l.localVersionSent = !0)), l.remoteVersion == null && P && (l.remoteVersion = 0), r[a] = l), l;
541
541
  }
542
- function p(i) {
543
- return i.map(u);
542
+ function p(a) {
543
+ return a.map(u);
544
544
  }
545
- function y(...i) {
545
+ function y(...a) {
546
546
  const l = d(), m = Array(l).fill(!1);
547
- i.forEach((v) => {
547
+ a.forEach((v) => {
548
548
  v.forEach((S) => {
549
549
  S.depGroup != null && (m[S.depGroup] = !0), S.depGroup = l;
550
550
  });
@@ -552,50 +552,50 @@ function Pt(t) {
552
552
  v.depGroup != null && v.depGroup !== l && m[v.depGroup] && (v.depGroup = l);
553
553
  });
554
554
  }
555
- t.onDeclare = (i) => {
556
- const l = p(i.map((m) => m.name));
557
- for (let m = 0; m < i.length; m++)
558
- i[m].version != null && (l[m].remoteVersion = i[m].version);
555
+ t.onDeclare = (a) => {
556
+ const l = p(a.map((m) => m.name));
557
+ for (let m = 0; m < a.length; m++)
558
+ a[m].version != null && (l[m].remoteVersion = a[m].version);
559
559
  y(l), J();
560
560
  }, t.onDone = () => {
561
- V || (V = !0, Object.values(r).forEach((i) => {
562
- i.remoteVersion == null && (i.remoteVersion = 0);
561
+ P || (P = !0, Object.values(r).forEach((a) => {
562
+ a.remoteVersion == null && (a.remoteVersion = 0);
563
563
  }), J());
564
- }, t.onProvide = (i, l, m) => {
565
- let v = r[i];
564
+ }, t.onProvide = (a, l, m) => {
565
+ let v = r[a];
566
566
  if (v == null)
567
- throw new Error(e(`Contract not declared : ${i}`));
567
+ throw new Error(e(`Contract not declared : ${a}`));
568
568
  if (v.remoteVersion != l)
569
- throw new Error(e(`Remote declared version ${v.remoteVersion} of contract "${i}" but provided version ${l}.`));
569
+ throw new Error(e(`Remote declared version ${v.remoteVersion} of contract "${a}" but provided version ${l}.`));
570
570
  if (v.remoteInterfaceReceived)
571
- throw new Error(e(`Remote contract "${i}" is already provided.`));
571
+ throw new Error(e(`Remote contract "${a}" is already provided.`));
572
572
  v.setRemoteInterface(m), J();
573
573
  };
574
- let C = !1, k = !1, A = !1, x = !1, V = !1;
574
+ let C = !1, k = !1, b = !1, x = !1, P = !1;
575
575
  async function J() {
576
576
  if (k = !0, !C) {
577
577
  for (C = !0; k; ) {
578
578
  if (k = !1, t.isReady) {
579
- const i = g.filter((l) => !l.isDeclared);
580
- if (i.length > 0)
581
- for (const l of i) {
579
+ const a = g.filter((l) => !l.isDeclared);
580
+ if (a.length > 0)
581
+ for (const l of a) {
582
582
  const m = Array(l.args.length + l.deps.length);
583
583
  l.args.forEach((v, S) => m[S] = v), l.deps.forEach((v, S) => m[S + l.args.length] = v), await t.declare(m.map((v) => ({ name: v.name, version: v.localVersion }))), m.forEach((v) => {
584
584
  v.localVersion != null && (v.localVersionSent = !0);
585
585
  }), l.isDeclared = !0;
586
586
  }
587
587
  }
588
- if (t.isReady && A && g.every((i) => i.isDeclared)) {
589
- const i = Object.values(r).filter((l) => !l.localVersionSent && l.localVersion != null);
590
- if (i.length > 0)
591
- for (const l of i)
588
+ if (t.isReady && b && g.every((a) => a.isDeclared)) {
589
+ const a = Object.values(r).filter((l) => !l.localVersionSent && l.localVersion != null);
590
+ if (a.length > 0)
591
+ for (const l of a)
592
592
  await t.declare([{ name: l.name, version: l.localVersion }]), l.localVersionSent = !0;
593
593
  x || (x = !0, await t.done());
594
594
  }
595
595
  if (t.isReady) {
596
- const i = g.filter((l) => !l.isDone && l.isReady);
597
- if (i.length > 0)
598
- for (const l of i) {
596
+ const a = g.filter((l) => !l.isDone && l.isReady);
597
+ if (a.length > 0)
598
+ for (const l of a) {
599
599
  const m = l.invoke();
600
600
  for (let v = 0; v < l.args.length; v++) {
601
601
  const S = l.args[v];
@@ -604,22 +604,22 @@ function Pt(t) {
604
604
  }
605
605
  }
606
606
  if (f != null) {
607
- const i = Array(f + 1).fill(null);
607
+ const a = Array(f + 1).fill(null);
608
608
  for (const l in r) {
609
609
  const m = r[l];
610
- m.depGroup != null && (m.isActivable ? i[m.depGroup] == null && !m.isActivated && (i[m.depGroup] = !0) : i[m.depGroup] = !1);
610
+ m.depGroup != null && (m.isActivable ? a[m.depGroup] == null && !m.isActivated && (a[m.depGroup] = !0) : a[m.depGroup] = !1);
611
611
  }
612
- if (i.some((l) => l === !0))
612
+ if (a.some((l) => l === !0))
613
613
  for (const l in r) {
614
614
  const m = r[l];
615
- m.depGroup != null && i[m.depGroup] && m.activate();
615
+ m.depGroup != null && a[m.depGroup] && m.activate();
616
616
  }
617
617
  }
618
618
  if (t.isReady) {
619
- const i = c;
619
+ const a = c;
620
620
  c = [];
621
621
  const l = [];
622
- for (const m of i)
622
+ for (const m of a)
623
623
  !m.isDone && m.isReady ? m.invoke() : l.push(m);
624
624
  l.push(...c), c = l;
625
625
  }
@@ -628,36 +628,36 @@ function Pt(t) {
628
628
  }
629
629
  }
630
630
  return {
631
- get(i) {
632
- return u(i);
631
+ get(a) {
632
+ return u(a);
633
633
  },
634
- declareFactory: (i, l, m, v) => {
635
- if (A) throw new Error(e("Cannot declare a factory after done has been set to true."));
636
- const S = p(i.map((b) => b.name));
634
+ declareFactory: (a, l, m, v) => {
635
+ if (b) throw new Error(e("Cannot declare a factory after done has been set to true."));
636
+ const S = p(a.map((E) => E.name));
637
637
  {
638
- const b = S.filter((N) => N.localVersion != null);
639
- if (b.length > 0)
640
- throw new Error(e("Cannot declare a factory for already implemented contracts : " + b.map((N) => N.name).join(", ")));
638
+ const E = S.filter((N) => N.localVersion != null);
639
+ if (E.length > 0)
640
+ throw new Error(e("Cannot declare a factory for already implemented contracts : " + E.map((N) => N.name).join(", ")));
641
641
  }
642
- for (let b = 0; b < i.length; b++)
643
- S[b].localVersion = i[b].version;
642
+ for (let E = 0; E < a.length; E++)
643
+ S[E].localVersion = a[E].version;
644
644
  const T = p(l);
645
645
  y(S, T);
646
646
  const ft = o(S, T, m, v);
647
647
  g.push(ft), J();
648
648
  },
649
- declareCallback(i, l, m, v) {
650
- const S = p(i), T = n(S, l, m, v);
649
+ declareCallback(a, l, m, v) {
650
+ const S = p(a), T = n(S, l, m, v);
651
651
  !C && c.length === 0 && T.isReady ? T.invoke() : (c.push(T), J());
652
652
  },
653
653
  get done() {
654
- return A;
654
+ return b;
655
655
  },
656
- set done(i) {
657
- if (A) {
658
- if (!i) throw new Error(e("Cannot set done to false after it has been set to true."));
656
+ set done(a) {
657
+ if (b) {
658
+ if (!a) throw new Error(e("Cannot set done to false after it has been set to true."));
659
659
  } else
660
- i && (A = !0, Object.values(r).forEach((l) => {
660
+ a && (b = !0, Object.values(r).forEach((l) => {
661
661
  l.localVersion == null && (l.localVersion = 0);
662
662
  }), J());
663
663
  }
@@ -671,7 +671,7 @@ function Dt(t) {
671
671
  return isNaN(o) || o === 0 ? null : { name: e, version: o };
672
672
  }
673
673
  function Lt(t) {
674
- const e = Pt(t);
674
+ const e = Vt(t);
675
675
  function n(s) {
676
676
  return lt(t.name, s);
677
677
  }
@@ -725,12 +725,12 @@ const K = (t) => {
725
725
  return c;
726
726
  }, It = (t) => t ? K(t) : K, jt = (t) => t;
727
727
  function $t(t, e = jt) {
728
- const n = P.useSyncExternalStore(
728
+ const n = V.useSyncExternalStore(
729
729
  t.subscribe,
730
- P.useCallback(() => e(t.getState()), [t, e]),
731
- P.useCallback(() => e(t.getInitialState()), [t, e])
730
+ V.useCallback(() => e(t.getState()), [t, e]),
731
+ V.useCallback(() => e(t.getInitialState()), [t, e])
732
732
  );
733
- return P.useDebugValue(n), n;
733
+ return V.useDebugValue(n), n;
734
734
  }
735
735
  const X = (t) => {
736
736
  const e = It(t), n = (s) => $t(e, s);
@@ -752,13 +752,14 @@ const X = (t) => {
752
752
  }
753
753
  return o(d);
754
754
  }, t(e, n, s);
755
- }, Nt = Ot, a = dt()(
755
+ }, Nt = Ot, i = dt()(
756
756
  Nt((t) => ({
757
757
  ready: !1,
758
758
  workflow: "current",
759
759
  mode: "assignment",
760
760
  theme: "light",
761
761
  saveCount: 0,
762
+ canSave: !1,
762
763
  afterSaveCount: 0,
763
764
  isDirtyCount: 0,
764
765
  loadedTextContent: null,
@@ -829,6 +830,7 @@ const qt = [
829
830
  "reload:1",
830
831
  "theme:1",
831
832
  "workflow:1",
833
+ "trigger-save:1",
832
834
  "simple-content(text):1",
833
835
  "simple-content(json):1",
834
836
  "simple-binary-data(text):1",
@@ -839,7 +841,7 @@ const qt = [
839
841
  ], tt = {
840
842
  "mode:1": {
841
843
  setMode: (t) => {
842
- a.setState({ mode: t });
844
+ i.setState({ mode: t });
843
845
  }
844
846
  },
845
847
  "reload:1": {
@@ -850,63 +852,68 @@ const qt = [
850
852
  "theme:1": {
851
853
  setTheme: (t) => {
852
854
  if (t === null) {
853
- a.setState({ theme: null });
855
+ i.setState({ theme: null });
854
856
  return;
855
857
  }
856
858
  if (t !== "light" && t !== "dark") {
857
- console.warn(`Invalid theme: ${t}. Expected 'light' or 'dark'.`), a.setState({ theme: null });
859
+ console.warn(`Invalid theme: ${t}. Expected 'light' or 'dark'.`), i.setState({ theme: null });
858
860
  return;
859
861
  }
860
- a.setState({ theme: t });
862
+ i.setState({ theme: t });
861
863
  }
862
864
  },
863
865
  "workflow:1": {
864
866
  setWorkflow: (t) => {
865
- a.setState({ workflow: t });
867
+ i.setState({ workflow: t });
868
+ }
869
+ },
870
+ "trigger-save:1": {
871
+ setCanSave(t) {
872
+ i.setState({ canSave: t });
866
873
  }
867
874
  },
868
875
  "simple-content(text):1": {
869
876
  contentSaved: () => {
870
- a.setState((t) => ({
877
+ i.setState((t) => ({
871
878
  afterSaveCount: t.afterSaveCount + 1
872
879
  }));
873
880
  },
874
- getContent: () => a.getState().getTextContentFunction(),
881
+ getContent: () => i.getState().getTextContentFunction(),
875
882
  loadContent: (t) => {
876
- a.setState({ loadedTextContent: t });
883
+ i.setState({ loadedTextContent: t });
877
884
  }
878
885
  },
879
886
  "simple-content(json):1": {
880
887
  contentSaved: () => {
881
- a.setState((t) => ({
888
+ i.setState((t) => ({
882
889
  afterSaveCount: t.afterSaveCount + 1
883
890
  }));
884
891
  },
885
- getContent: () => a.getState().getJsonContentFunction(),
892
+ getContent: () => i.getState().getJsonContentFunction(),
886
893
  loadContent: (t) => {
887
- a.setState({ loadedJsonContent: t });
894
+ i.setState({ loadedJsonContent: t });
888
895
  }
889
896
  },
890
897
  "simple-binary-data(text):1": {
891
898
  contentSaved: () => {
892
- a.setState((t) => ({
899
+ i.setState((t) => ({
893
900
  afterSaveCount: t.afterSaveCount + 1
894
901
  }));
895
902
  },
896
- getContent: () => a.getState().getTextContentFunction(),
903
+ getContent: () => i.getState().getTextContentFunction(),
897
904
  loadContent: (t) => {
898
- a.setState({ loadedTextContent: t });
905
+ i.setState({ loadedTextContent: t });
899
906
  }
900
907
  },
901
908
  "simple-content-eval(text):1": {
902
909
  contentSaved: () => {
903
- a.setState((t) => ({
910
+ i.setState((t) => ({
904
911
  afterSaveCount: t.afterSaveCount + 1
905
912
  }));
906
913
  },
907
- getContent: () => a.getState().getTextContentFunction(),
914
+ getContent: () => i.getState().getTextContentFunction(),
908
915
  loadContent: (t) => {
909
- a.setState({ loadedTextContent: t });
916
+ i.setState({ loadedTextContent: t });
910
917
  },
911
918
  getAssignmentContent: () => {
912
919
  throw new Error(
@@ -916,13 +923,13 @@ const qt = [
916
923
  },
917
924
  "simple-content-eval(json):1": {
918
925
  contentSaved: () => {
919
- a.setState((t) => ({
926
+ i.setState((t) => ({
920
927
  afterSaveCount: t.afterSaveCount + 1
921
928
  }));
922
929
  },
923
- getContent: () => a.getState().getJsonContentFunction(),
930
+ getContent: () => i.getState().getJsonContentFunction(),
924
931
  loadContent: (t) => {
925
- a.setState({ loadedJsonContent: t });
932
+ i.setState({ loadedJsonContent: t });
926
933
  },
927
934
  getAssignmentContent: () => {
928
935
  throw new Error(
@@ -932,13 +939,13 @@ const qt = [
932
939
  },
933
940
  "simple-content-eval(json):2": {
934
941
  contentSaved: () => {
935
- a.setState((t) => ({
942
+ i.setState((t) => ({
936
943
  afterSaveCount: t.afterSaveCount + 1
937
944
  }));
938
945
  },
939
- getContent: () => a.getState().getJsonContentFunction(),
946
+ getContent: () => i.getState().getJsonContentFunction(),
940
947
  loadContent: (t) => {
941
- a.setState({ loadedJsonContent: t });
948
+ i.setState({ loadedJsonContent: t });
942
949
  },
943
950
  getAssignmentContent: () => {
944
951
  throw new Error(
@@ -948,13 +955,13 @@ const qt = [
948
955
  },
949
956
  "simple-content-eval(text):2": {
950
957
  contentSaved: () => {
951
- a.setState((t) => ({
958
+ i.setState((t) => ({
952
959
  afterSaveCount: t.afterSaveCount + 1
953
960
  }));
954
961
  },
955
- getContent: () => a.getState().getTextContentFunction(),
962
+ getContent: () => i.getState().getTextContentFunction(),
956
963
  loadContent: (t) => {
957
- a.setState({ loadedTextContent: t });
964
+ i.setState({ loadedTextContent: t });
958
965
  },
959
966
  getAssignmentContent: () => {
960
967
  throw new Error(
@@ -964,22 +971,22 @@ const qt = [
964
971
  },
965
972
  "separate-contents(json):1": {
966
973
  contentSaved: () => {
967
- a.setState((t) => ({
974
+ i.setState((t) => ({
968
975
  afterSaveCount: t.afterSaveCount + 1
969
976
  }));
970
977
  },
971
978
  loadContent: (t, e) => {
972
- a.setState({
979
+ i.setState({
973
980
  loadedJsonActivityContent: t,
974
981
  loadedJsonAssignmentContent: e
975
982
  });
976
983
  },
977
- getActivityContent: () => a.getState().getJsonActivityContentFunction(),
978
- getAssignmentContent: () => a.getState().getJsonAssignmentContentFunction()
984
+ getActivityContent: () => i.getState().getJsonActivityContentFunction(),
985
+ getAssignmentContent: () => i.getState().getJsonAssignmentContentFunction()
979
986
  },
980
987
  "separate-dual-contents(json):1": {
981
988
  contentSaved: () => {
982
- a.setState((t) => ({
989
+ i.setState((t) => ({
983
990
  afterSaveCount: t.afterSaveCount + 1
984
991
  }));
985
992
  },
@@ -989,15 +996,15 @@ const qt = [
989
996
  activityBinaryData: n,
990
997
  assignmentBinaryData: s
991
998
  }) => {
992
- a.setState({
999
+ i.setState({
993
1000
  loadedJsonActivityContent: t,
994
1001
  loadedJsonAssignmentContent: e,
995
1002
  loadedJsonActivityBinaryData: n,
996
1003
  loadedJsonAssignmentBinaryData: s
997
1004
  });
998
1005
  },
999
- getActivityContentAndData: () => a.getState().getJsonActivitySplitContentFunction(),
1000
- getAssignmentContentAndData: () => a.getState().getJsonAssignmentSplitContentFunction()
1006
+ getActivityContentAndData: () => (console.log("Getting activity content and data"), i.getState().getJsonActivitySplitContentFunction()),
1007
+ getAssignmentContentAndData: () => (console.log("Getting assignment content and data"), i.getState().getJsonAssignmentSplitContentFunction())
1001
1008
  },
1002
1009
  "meta-player-anti-cheat:1": {
1003
1010
  lock: () => {
@@ -1007,25 +1014,25 @@ const qt = [
1007
1014
  },
1008
1015
  "meta-player-ui:1": {
1009
1016
  executeAction(t) {
1010
- if (t.startsWith("qa")) {
1011
- const n = a.getState().quickActions[t];
1017
+ if (console.log("Executing action:", t), t.startsWith("qa")) {
1018
+ const n = i.getState().quickActions[t];
1012
1019
  n ? n() : console.error(`Quick action not found: ${t}`);
1013
1020
  } else {
1014
- const n = a.getState().sidebarActions[t];
1021
+ const n = i.getState().sidebarActions[t];
1015
1022
  n ? n() : console.error(`Sidebar action not found: ${t}`);
1016
1023
  }
1017
1024
  },
1018
1025
  executeFileUpload(t, e) {
1019
1026
  if (t.startsWith("qa")) {
1020
- const s = a.getState().quickActions[t];
1027
+ const s = i.getState().quickActions[t];
1021
1028
  s ? s(e) : console.error(`Quick action not found: ${t}`);
1022
1029
  } else {
1023
- const s = a.getState().sidebarActions[t];
1030
+ const s = i.getState().sidebarActions[t];
1024
1031
  s ? s(e) : console.error(`Sidebar action not found: ${t}`);
1025
1032
  }
1026
1033
  },
1027
1034
  updateSettings(t) {
1028
- const e = a.getState().activitySettingsCallback;
1035
+ const e = i.getState().activitySettingsCallback;
1029
1036
  e ? e(t) : console.warn(
1030
1037
  "activitySettingsCallback is not set. Changes:",
1031
1038
  t
@@ -1034,12 +1041,12 @@ const qt = [
1034
1041
  },
1035
1042
  "meta-player-events:1": {
1036
1043
  handleEvent(t) {
1037
- t === "all-loaded" && a.setState({ ready: !0 });
1044
+ t === "all-loaded" && i.setState({ ready: !0 });
1038
1045
  }
1039
1046
  }
1040
1047
  }, h = Gt();
1041
1048
  function Bt(t) {
1042
- if (Z) {
1049
+ if (console.log("Contracts to plug:", t), Z) {
1043
1050
  console.warn("Contracts have already been plugged. Skipping.");
1044
1051
  return;
1045
1052
  }
@@ -1058,7 +1065,7 @@ function Bt(t) {
1058
1065
  continue;
1059
1066
  }
1060
1067
  const n = tt[e];
1061
- h.plug([e], ([]) => [n]);
1068
+ h.plug([e], ([]) => (console.log(`Contract ${e} plugged.`), [n]));
1062
1069
  }
1063
1070
  h.plugsDone();
1064
1071
  for (const e of [
@@ -1068,13 +1075,15 @@ function Bt(t) {
1068
1075
  "simple-content-eval(text):1",
1069
1076
  "simple-content-eval(json):1",
1070
1077
  "simple-content-eval(json):2",
1071
- "simple-content-eval(text):2"
1078
+ "simple-content-eval(text):2",
1079
+ "separate-contents(json):1",
1080
+ "separate-dual-contents(json):1"
1072
1081
  ])
1073
1082
  if (console.log(`Contract ${e} is being subscribed to content changes.`), t.includes(e)) {
1074
1083
  console.log(`Subscribing to content changes for contract ${e}`);
1075
1084
  const n = e.split(":")[0];
1076
1085
  h.use([n], ([s]) => {
1077
- a.subscribe(
1086
+ i.subscribe(
1078
1087
  (o) => o.isDirtyCount,
1079
1088
  () => {
1080
1089
  s.i?.contentChanged(), console.log(
@@ -1085,76 +1094,76 @@ function Bt(t) {
1085
1094
  });
1086
1095
  }
1087
1096
  }
1088
- const oe = () => a((t) => {
1097
+ const oe = () => i((t) => {
1089
1098
  if (t.mode === null)
1090
1099
  throw new Error("Mode is not set. Have you used contract 'mode'?");
1091
1100
  return t.mode;
1092
- }), re = () => a((t) => {
1101
+ }), re = () => i((t) => {
1093
1102
  if (t.workflow === null)
1094
1103
  throw new Error(
1095
1104
  "Workflow is not set. Have you used contract 'workflow'?"
1096
1105
  );
1097
1106
  return t.workflow;
1098
- }), se = () => a((t) => {
1107
+ }), se = () => i((t) => {
1099
1108
  if (t.theme === null)
1100
1109
  throw new Error("Theme is not set. Have you used contract 'theme'?");
1101
1110
  return t.theme;
1102
- }), ie = () => a((t) => t.incSaveCount), ae = () => a((t) => t.incDirtyCount), ce = () => a((t) => t.loadedTextContent), le = () => a((t) => t.loadedJsonContent), ue = () => a((t) => t.loadedJsonActivityContent), de = () => a((t) => t.loadedJsonAssignmentContent), fe = () => a((t) => t.loadedJsonActivityBinaryData), ge = () => a((t) => t.loadedJsonAssignmentBinaryData), pe = () => E(() => a.getState().loadedTextContent, []), me = () => E(() => a.getState().loadedJsonContent, []), ye = () => E(() => a.getState().loadedJsonActivityContent, []), ve = () => E(() => a.getState().loadedJsonAssignmentContent, []), Ce = () => E(
1111
+ }), ae = () => i((t) => t.incSaveCount), ie = () => i((t) => t.incDirtyCount), ce = () => i((t) => t.loadedTextContent), le = () => i((t) => t.loadedJsonContent), ue = () => i((t) => t.loadedJsonActivityContent), de = () => i((t) => t.loadedJsonAssignmentContent), fe = () => i((t) => t.loadedJsonActivityBinaryData), ge = () => i((t) => t.loadedJsonAssignmentBinaryData), pe = () => A(() => i.getState().loadedTextContent, []), me = () => A(() => i.getState().loadedJsonContent, []), ye = () => A(() => i.getState().loadedJsonActivityContent, []), ve = () => A(() => i.getState().loadedJsonAssignmentContent, []), Ce = () => A(
1103
1112
  () => ({
1104
- content: a.getState().loadedJsonActivityContent,
1105
- binaryData: a.getState().loadedJsonActivityBinaryData
1113
+ content: i.getState().loadedJsonActivityContent,
1114
+ binaryData: i.getState().loadedJsonActivityBinaryData
1106
1115
  }),
1107
1116
  []
1108
- ), Se = () => E(
1117
+ ), Se = () => A(
1109
1118
  () => ({
1110
- content: a.getState().loadedJsonAssignmentContent,
1111
- binaryData: a.getState().loadedJsonAssignmentBinaryData
1119
+ content: i.getState().loadedJsonAssignmentContent,
1120
+ binaryData: i.getState().loadedJsonAssignmentBinaryData
1112
1121
  }),
1113
1122
  []
1114
1123
  ), we = (t) => {
1115
- const e = a(
1124
+ const e = i(
1116
1125
  (n) => n.setGetTextContentFunction
1117
1126
  );
1118
1127
  w(() => {
1119
1128
  e(t);
1120
1129
  }, [t, e]);
1121
1130
  }, he = (t) => {
1122
- const e = a(
1131
+ const e = i(
1123
1132
  (n) => n.setGetJsonContentFunction
1124
1133
  );
1125
1134
  w(() => {
1126
1135
  e(t);
1127
1136
  }, [t, e]);
1128
1137
  }, Ae = (t) => {
1129
- const e = a(
1138
+ const e = i(
1130
1139
  (n) => n.setGetJsonActivityContentFunction
1131
1140
  );
1132
1141
  w(() => {
1133
1142
  e(t);
1134
1143
  }, [t, e]);
1135
1144
  }, be = (t) => {
1136
- const e = a(
1145
+ const e = i(
1137
1146
  (n) => n.setGetJsonAssignmentContentFunction
1138
1147
  );
1139
1148
  w(() => {
1140
1149
  e(t);
1141
1150
  }, [t, e]);
1142
1151
  }, Ee = (t) => {
1143
- const e = a(
1152
+ const e = i(
1144
1153
  (n) => n.setGetJsonActivitySplitContentFunction
1145
1154
  );
1146
1155
  w(() => {
1147
1156
  e(t);
1148
1157
  }, [t, e]);
1149
1158
  }, ke = (t) => {
1150
- const e = a(
1159
+ const e = i(
1151
1160
  (n) => n.setGetJsonAssignmentSplitContentFunction
1152
1161
  );
1153
1162
  w(() => {
1154
1163
  e(t);
1155
1164
  }, [t, e]);
1156
1165
  }, Je = (t) => {
1157
- const e = a((n) => n.afterSaveCount);
1166
+ const e = i((n) => n.afterSaveCount);
1158
1167
  w(() => {
1159
1168
  e > 0 && t();
1160
1169
  }, [e]);
@@ -1181,7 +1190,7 @@ const oe = () => a((t) => {
1181
1190
  };
1182
1191
  let D = 0, W = 0;
1183
1192
  const Te = (t, e) => {
1184
- const n = U(t, e), s = a((o) => o.setSidebarActions);
1193
+ const n = U(t, e), s = i((o) => o.setSidebarActions);
1185
1194
  w(() => (D++, D > 1 && console.error(
1186
1195
  "Capytale iframe React: Multiple sidebar actions registered: ",
1187
1196
  D
@@ -1219,7 +1228,7 @@ const Te = (t, e) => {
1219
1228
  };
1220
1229
  let L = 0, H = 0;
1221
1230
  const Re = (t, e) => {
1222
- const n = U(t, e), s = a((o) => o.setQuickActions);
1231
+ const n = U(t, e), s = i((o) => o.setQuickActions);
1223
1232
  w(() => (L++, L > 1 && console.error(
1224
1233
  "Capytale iframe React: Multiple quick actions registered: ",
1225
1234
  L
@@ -1257,7 +1266,7 @@ const Re = (t, e) => {
1257
1266
  };
1258
1267
  let G = 0;
1259
1268
  const Wt = (t, e, n) => {
1260
- const s = U(t, n), o = a(
1269
+ const s = U(t, n), o = i(
1261
1270
  (r) => r.setActivitySettingsCallback
1262
1271
  );
1263
1272
  w(() => (console.log("Mounting useSettings"), G++, G > 1 && console.error(
@@ -1278,25 +1287,31 @@ const Wt = (t, e, n) => {
1278
1287
  ), () => {
1279
1288
  o(null);
1280
1289
  }), [s]);
1281
- }, Ht = () => E((e) => h.exec(["meta-player-ui"], ([n]) => {
1290
+ }, Ht = () => A((e) => h.exec(["meta-player-ui"], ([n]) => {
1282
1291
  if (n.version === 0)
1283
1292
  throw console.error(
1284
1293
  "Le MétaPlayer ne supporte pas le contrat meta-player-ui"
1285
1294
  ), new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");
1286
1295
  return n.i?.showToast(e);
1287
- }), []), zt = () => E((e) => h.exec(["meta-player-ui"], ([n]) => {
1296
+ }), []), zt = () => A((e) => h.exec(["meta-player-ui"], ([n]) => {
1288
1297
  if (n.version === 0)
1289
1298
  throw console.error(
1290
1299
  "Le MétaPlayer ne supporte pas le contrat meta-player-ui"
1291
1300
  ), new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");
1292
1301
  return n.i?.clearToast(e);
1293
- }), []), Ve = () => E(() => h.exec(["meta-player-ui"], ([e]) => {
1302
+ }), []), Pe = () => A(() => h.exec(["meta-player-ui"], ([e]) => {
1294
1303
  if (e.version === 0)
1295
1304
  throw console.error(
1296
1305
  "Le MétaPlayer ne supporte pas le contrat meta-player-ui"
1297
1306
  ), new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");
1298
1307
  return e.i?.clearToasts();
1299
- }), []);
1308
+ }), []), Ve = () => A(() => h.exec(["trigger-save"], ([e]) => {
1309
+ if (e.version === 0)
1310
+ throw console.error(
1311
+ "Le MétaPlayer ne supporte pas le contrat trigger-save"
1312
+ ), new Error("Le MétaPlayer ne supporte pas le contrat trigger-save");
1313
+ return e.i?.triggerSave();
1314
+ }), []), Me = () => i((t) => t.canSave);
1300
1315
  function Ut(t) {
1301
1316
  const e = {};
1302
1317
  for (const n of t.fields)
@@ -1328,7 +1343,7 @@ function Kt(t) {
1328
1343
  Object.assign(e, Yt(n));
1329
1344
  return e;
1330
1345
  }
1331
- function Pe(t) {
1346
+ function De(t) {
1332
1347
  const n = dt()((s) => ({
1333
1348
  ...Kt(t)
1334
1349
  }));
@@ -1350,16 +1365,17 @@ function Zt({
1350
1365
  }
1351
1366
  const te = [
1352
1367
  "meta-player-events:1",
1368
+ "meta-player-ui:1",
1353
1369
  "mode:1",
1354
1370
  "workflow:1"
1355
1371
  ];
1356
- function Me({
1372
+ function Le({
1357
1373
  children: t,
1358
1374
  contracts: e,
1359
1375
  loadOnlyWhenReady: n = !0,
1360
1376
  activitySettingsStore: s
1361
1377
  }) {
1362
- const o = a((r) => r.ready);
1378
+ const o = i((r) => r.ready);
1363
1379
  return w(() => {
1364
1380
  const r = [...e];
1365
1381
  for (const g of te)
@@ -1370,24 +1386,25 @@ function Me({
1370
1386
  t
1371
1387
  ] });
1372
1388
  }
1373
- function De({ message: t }) {
1389
+ function Ge({ message: t }) {
1374
1390
  const e = Ht(), n = zt();
1375
- w(() => {
1391
+ return w(() => {
1376
1392
  const s = e(t);
1377
1393
  return () => {
1378
1394
  s.then((o) => {
1379
1395
  o != null && n(o);
1380
1396
  });
1381
1397
  };
1382
- }, [t, e, n]);
1398
+ }, [t, e, n]), null;
1383
1399
  }
1384
1400
  export {
1385
- Me as Capytale,
1386
- De as TemporaryToast,
1387
- Pe as createActivitySettingsStore,
1401
+ Le as Capytale,
1402
+ Ge as TemporaryToast,
1403
+ De as createActivitySettingsStore,
1388
1404
  Je as useAfterSaveAction,
1405
+ Me as useCanSave,
1389
1406
  zt as useClearToast,
1390
- Ve as useClearToasts,
1407
+ Pe as useClearToasts,
1391
1408
  ye as useGetLoadedJsonActivityContent,
1392
1409
  Ce as useGetLoadedJsonActivitySplitContent,
1393
1410
  ve as useGetLoadedJsonAssignmentContent,
@@ -1406,15 +1423,16 @@ export {
1406
1423
  le as useLoadedJsonContent,
1407
1424
  ce as useLoadedTextContent,
1408
1425
  oe as useMode,
1409
- ae as useNotifyIsDirty,
1426
+ ie as useNotifyIsDirty,
1410
1427
  xe as usePreviewImageFile,
1411
1428
  Fe as usePreviewTextFile,
1412
1429
  Re as useQuickActions,
1413
- ie as useRequestSave,
1430
+ ae as useRequestSave,
1414
1431
  Wt as useSettings,
1415
1432
  Ht as useShowToast,
1416
1433
  Te as useSidebarActions,
1417
1434
  we as useTextContentSaveFunction,
1418
1435
  se as useTheme,
1436
+ Ve as useTriggerSave,
1419
1437
  re as useWorkflow
1420
1438
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capytale/iframe-react",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -34,7 +34,7 @@
34
34
  "react-dom": ">=17.0.0 <20"
35
35
  },
36
36
  "devDependencies": {
37
- "@capytale/contracts": "^1.1.2",
37
+ "@capytale/contracts": "^1.1.3",
38
38
  "@types/node": "^22.13.1",
39
39
  "@types/react": "^18.3.18",
40
40
  "@types/react-dom": "^18.3.5",