@capytale/iframe-react 1.1.10 → 1.1.12
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 +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.es.js +225 -203
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),C=require("react");const X=Symbol("Comlink.proxy"),dt=Symbol("Comlink.endpoint"),ft=Symbol("Comlink.releaseProxy"),N=Symbol("Comlink.finalizer"),P=Symbol("Comlink.thrown"),Z=t=>typeof t=="object"&&t!==null||typeof t=="function",gt={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)}},mt={canHandle:t=>Z(t)&&P 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",gt],["throw",mt]]);function pt(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(!pt(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),m=c.reduce((y,S)=>y[S],t);switch(g){case"GET":d=m;break;case"SET":u[c.slice(-1)[0]]=k(o.data.value),d=!0;break;case"APPLY":d=m.apply(u,f);break;case"CONSTRUCT":{const y=new m(...f);d=st(y)}break;case"ENDPOINT":{const{port1:y,port2:S}=new MessageChannel;z(t,S),d=At(y,[y])}break;case"RELEASE":d=void 0;break;default:return}}catch(u){d={value:u,[P]:0}}Promise.resolve(d).catch(u=>({value:u,[P]:0})).then(u=>{const[m,y]=$(u);e.postMessage(Object.assign(Object.assign({},m),{id:r}),y),g==="RELEASE"&&(e.removeEventListener("message",s),et(e),N in t&&typeof t[N]=="function"&&t[N]())}).catch(u=>{const[m,y]=$({value:new TypeError("Unserializable return value"),[P]:0});e.postMessage(Object.assign(Object.assign({},m),{id:r}),y)})}),e.start&&e.start()}function yt(t){return t.constructor.name==="MessagePort"}function et(t){yt(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 V(t){if(t)throw new Error("Proxy has been released and is not useable")}function ot(t){return R(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 vt(t,e){const n=(I.get(e)||0)+1;I.set(e,n),j&&j.register(t,e,t)}function Ct(t){j&&j.unregister(t)}function H(t,e,n=[],s=function(){}){let o=!1;const r=new Proxy(s,{get(g,c){if(V(o),c===ft)return()=>{Ct(r),ot(t),e.clear(),o=!0};if(c==="then"){if(n.length===0)return{then:()=>r};const f=R(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){V(o);const[d,u]=$(f);return R(t,e,{type:"SET",path:[...n,c].map(m=>m.toString()),value:d},u).then(k)},apply(g,c,f){V(o);const d=n[n.length-1];if(d===dt)return R(t,e,{type:"ENDPOINT"}).then(k);if(d==="bind")return H(t,e,n.slice(0,-1));const[u,m]=U(f);return R(t,e,{type:"APPLY",path:n.map(y=>y.toString()),argumentList:u},m).then(k)},construct(g,c){V(o);const[f,d]=U(c);return R(t,e,{type:"CONSTRUCT",path:n.map(u=>u.toString()),argumentList:f},d).then(k)}});return vt(r,t),r}function St(t){return Array.prototype.concat.apply([],t)}function U(t){const e=t.map($);return[e.map(n=>n[0]),St(e.map(n=>n[1]))]}const rt=new WeakMap;function At(t,e){return rt.set(t,e),t}function st(t){return Object.assign(t,{[X]:!0})}function wt(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 R(t,e,n,s){return new Promise(o=>{const r=ht();e.set(r,o),t.start&&t.start(),t.postMessage(Object.assign({id:r},n),s)})}function ht(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}function bt(t,e){return t.length===0?e:`[${t}] ${e}`}function Et(t,e){let n=!1,s,o,r;function g(u){return bt(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,m,y){return Promise.resolve()}};else{const u=wt(window.parent,void 0,e);z({declare(m){if(s==null)throw new Error(g("No handler for declare"));s(m)},done(){if(o==null)throw new Error(g("No handler for done"));o()},provide(m,y,S){if(r==null)throw new Error(g("No handler for provide"));r(m,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,m,y)=>c.provide(u,m,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 Jt(t){return function(e){let n,s=!1,o=!1,r,g,c=!1,f=!1,d,u,m,y;function S(){if(r!=null&&r!==0&&g!=null)return g}function E(i){if(r!=null&&g!=null&&!(i>r))return g}function h(){return m??(f?m=Promise.resolve():m=new Promise((i,l)=>{y=i}))}function F(){return d===void 0&&(d={get name(){return e},get version(){return r},get i(){return S()},v:i=>E(i)}),d}function T(){return u===void 0&&(u={get name(){return e},get version(){return f?r:void 0},get i(){return f?S():void 0},v:i=>f?E(i):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(i){if(n!=null&&n!==i)throw new Error(t("A different local version is already set"));n=i},get localVersionSent(){return s},set localVersionSent(i){if(!i&&s)throw new Error(t("Local version already notified"));s=i,i&&n===0&&(o=!0)},get localInterfaceSent(){return o},set localInterfaceSent(i){if(n==null)throw new Error(t("Local version not set"));if(!i&&o)throw new Error(t("Local interface already sent."));o=i},get remoteVersion(){if(r!=null)return r},set remoteVersion(i){if(r!=null&&r!==i)throw new Error(t("A different remote version is already set for "+e+`(${r} -> ${i})`));r=i,i===0&&(c=!0)},get remoteVersionReceived(){return r!=null},setRemoteInterface:i=>{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=i,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:()=>T(),get activationPromise(){return h()}}}}function kt(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 m=n.length>0?n.map(y=>y.getRemote()):null;try{u=m==null?r(d):r(d,m)}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 Ft(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 it(t,e){return t==null||t.length===0?e:`[${t}] ${e}`}function xt(t){function e(i){return it(t.name,i)}const n=Ft(e),s=Jt(e),o=kt(e),r={},g=[];let c=[],f;const d=()=>(f==null?f=0:f++,f);function u(i){let l=r[i];return l==null&&(l=s(i),l.localVersion==null&&(h&&(l.localVersion=0),F&&(l.localVersionSent=!0)),l.remoteVersion==null&&T&&(l.remoteVersion=0),r[i]=l),l}function m(i){return i.map(u)}function y(...i){const l=d(),p=Array(l).fill(!1);i.forEach(v=>{v.forEach(A=>{A.depGroup!=null&&(p[A.depGroup]=!0),A.depGroup=l})}),Object.values(r).forEach(v=>{v.depGroup!=null&&v.depGroup!==l&&p[v.depGroup]&&(v.depGroup=l)})}t.onDeclare=i=>{const l=m(i.map(p=>p.name));for(let p=0;p<i.length;p++)i[p].version!=null&&(l[p].remoteVersion=i[p].version);y(l),J()},t.onDone=()=>{T||(T=!0,Object.values(r).forEach(i=>{i.remoteVersion==null&&(i.remoteVersion=0)}),J())},t.onProvide=(i,l,p)=>{let v=r[i];if(v==null)throw new Error(e(`Contract not declared : ${i}`));if(v.remoteVersion!=l)throw new Error(e(`Remote declared version ${v.remoteVersion} of contract "${i}" but provided version ${l}.`));if(v.remoteInterfaceReceived)throw new Error(e(`Remote contract "${i}" is already provided.`));v.setRemoteInterface(p),J()};let S=!1,E=!1,h=!1,F=!1,T=!1;async function J(){if(E=!0,!S){for(S=!0;E;){if(E=!1,t.isReady){const i=g.filter(l=>!l.isDeclared);if(i.length>0)for(const l of i){const p=Array(l.args.length+l.deps.length);l.args.forEach((v,A)=>p[A]=v),l.deps.forEach((v,A)=>p[A+l.args.length]=v),await t.declare(p.map(v=>({name:v.name,version:v.localVersion}))),p.forEach(v=>{v.localVersion!=null&&(v.localVersionSent=!0)}),l.isDeclared=!0}}if(t.isReady&&h&&g.every(i=>i.isDeclared)){const i=Object.values(r).filter(l=>!l.localVersionSent&&l.localVersion!=null);if(i.length>0)for(const l of i)await t.declare([{name:l.name,version:l.localVersion}]),l.localVersionSent=!0;F||(F=!0,await t.done())}if(t.isReady){const i=g.filter(l=>!l.isDone&&l.isReady);if(i.length>0)for(const l of i){const p=l.invoke();for(let v=0;v<l.args.length;v++){const A=l.args[v];await t.provide(A.name,A.localVersion,p[v]),A.localInterfaceSent=!0}}}if(f!=null){const i=Array(f+1).fill(null);for(const l in r){const p=r[l];p.depGroup!=null&&(p.isActivable?i[p.depGroup]==null&&!p.isActivated&&(i[p.depGroup]=!0):i[p.depGroup]=!1)}if(i.some(l=>l===!0))for(const l in r){const p=r[l];p.depGroup!=null&&i[p.depGroup]&&p.activate()}}if(t.isReady){const i=c;c=[];const l=[];for(const p of i)!p.isDone&&p.isReady?p.invoke():l.push(p);l.push(...c),c=l}}S=!1}}return{get(i){return u(i)},declareFactory:(i,l,p,v)=>{if(h)throw new Error(e("Cannot declare a factory after done has been set to true."));const A=m(i.map(b=>b.name));{const b=A.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<i.length;b++)A[b].localVersion=i[b].version;const x=m(l);y(A,x);const ut=o(A,x,p,v);g.push(ut),J()},declareCallback(i,l,p,v){const A=m(i),x=n(A,l,p,v);!S&&c.length===0&&x.isReady?x.invoke():(c.push(x),J())},get done(){return h},set done(i){if(h){if(!i)throw new Error(e("Cannot set done to false after it has been set to true."))}else i&&(h=!0,Object.values(r).forEach(l=>{l.localVersion==null&&(l.localVersion=0)}),J())}}}const Rt=/^\d+$/;function Tt(t){const[e,n,s]=t.split(":",3);if(n==null||s!=null||!Rt.test(n))return null;const o=parseInt(n);return isNaN(o)||o===0?null:{name:e,version:o}}function Lt(t){const e=xt(t);function n(s){return it(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=Tt(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 at="app-agent";let q;function Vt(t){return q!=null||(q=Lt(Et(at,t))),q}console.log(`[${at}@1.0.12] loaded`);const Q=t=>{let e;const n=new Set,s=(d,u)=>{const m=typeof d=="function"?d(e):d;if(!Object.is(m,e)){const y=e;e=u??(typeof m!="object"||m===null)?m:Object.assign({},e,m),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 Mt(t,e=Gt){const n=C.useSyncExternalStore(t.subscribe,C.useCallback(()=>e(t.getState()),[t,e]),C.useCallback(()=>e(t.getInitialState()),[t,e]));return C.useDebugValue(n),n}const _=t=>{const e=Dt(t),n=s=>Mt(e,s);return Object.assign(n,e),n},ct=t=>t?_(t):_,Pt=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 m=g(s.getState());d=y=>{const S=g(y);if(!u(m,S)){const E=m;c(m=S,E)}},f?.fireImmediately&&c(m,m)}return o(d)},t(e,n,s)},It=Pt,a=ct()(It(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 jt=["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=>{a.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){a.setState({theme:null});return}if(t!=="light"&&t!=="dark"){console.warn(`Invalid theme: ${t}. Expected 'light' or 'dark'.`),a.setState({theme:null});return}a.setState({theme:t})}},"workflow:1":{setWorkflow:t=>{a.setState({workflow:t})}},"simple-content(text):1":{contentSaved:()=>{a.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>a.getState().getTextContentFunction(),loadContent:t=>{a.setState({loadedTextContent:t})}},"simple-content(json):1":{contentSaved:()=>{a.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>a.getState().getJsonContentFunction(),loadContent:t=>{a.setState({loadedJsonContent:t})}},"simple-binary-data(text):1":{contentSaved:()=>{a.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>a.getState().getTextContentFunction(),loadContent:t=>{a.setState({loadedTextContent:t})}},"simple-content-eval(text):1":{contentSaved:()=>{a.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>a.getState().getTextContentFunction(),loadContent:t=>{a.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{a.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>a.getState().getJsonContentFunction(),loadContent:t=>{a.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(json):2":{contentSaved:()=>{a.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>a.getState().getJsonContentFunction(),loadContent:t=>{a.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(text):2":{contentSaved:()=>{a.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>a.getState().getTextContentFunction(),loadContent:t=>{a.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"separate-contents(json):1":{contentSaved:()=>{a.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{a.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>a.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>a.getState().getJsonAssignmentContentFunction()},"separate-dual-contents(json):1":{contentSaved:()=>{a.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:({activityContent:t,assignmentContent:e,activityBinaryData:n,assignmentBinaryData:s})=>{a.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e,loadedJsonActivityBinaryData:n,loadedJsonAssignmentBinaryData:s})},getActivityContentAndData:()=>a.getState().getJsonActivitySplitContentFunction(),getAssignmentContentAndData:()=>a.getState().getJsonAssignmentSplitContentFunction()},"meta-player-anti-cheat:1":{lock:()=>{},unlock:()=>{}},"meta-player-ui:1":{executeAction(t){if(t.startsWith("qa")){const n=a.getState().quickActions[t];n?n():console.error(`Quick action not found: ${t}`)}else{const n=a.getState().sidebarActions[t];n?n():console.error(`Sidebar action not found: ${t}`)}},executeFileUpload(t,e){if(t.startsWith("qa")){const s=a.getState().quickActions[t];s?s(e):console.error(`Quick action not found: ${t}`)}else{const s=a.getState().sidebarActions[t];s?s(e):console.error(`Sidebar action not found: ${t}`)}},updateSettings(t){const e=a.getState().activitySettingsCallback;e?e(t):console.warn("activitySettingsCallback is not set. Changes:",t)}},"meta-player-events:1":{handleEvent(t){t==="all-loaded"&&a.setState({ready:!0})}}},w=Vt();function $t(t){if(Y){console.warn("Contracts have already been plugged. Skipping.");return}Y=!0;for(const e of t){if(!jt.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];w.plug([e],([])=>[n])}w.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];w.use([n],([s])=>{a.subscribe(o=>o.isDirtyCount,()=>{s.i?.contentChanged(),console.log(`Content changed for contract ${n}`)})})}}const Ot=()=>a(t=>{if(t.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return t.mode}),Nt=()=>a(t=>{if(t.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return t.workflow}),qt=()=>a(t=>{if(t.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return t.theme}),Bt=()=>a(t=>t.incSaveCount),Wt=()=>a(t=>t.incDirtyCount),Ht=()=>a(t=>t.loadedTextContent),zt=()=>a(t=>t.loadedJsonContent),Ut=()=>a(t=>t.loadedJsonActivityContent),Qt=()=>a(t=>t.loadedJsonAssignmentContent),_t=()=>a(t=>t.loadedJsonActivityBinaryData),Yt=()=>a(t=>t.loadedJsonAssignmentBinaryData),Kt=()=>C.useCallback(()=>a.getState().loadedTextContent,[]),Xt=()=>C.useCallback(()=>a.getState().loadedJsonContent,[]),Zt=()=>C.useCallback(()=>a.getState().loadedJsonActivityContent,[]),te=()=>C.useCallback(()=>a.getState().loadedJsonAssignmentContent,[]),ee=()=>C.useCallback(()=>({content:a.getState().loadedJsonActivityContent,binaryData:a.getState().loadedJsonActivityBinaryData}),[]),ne=()=>C.useCallback(()=>({content:a.getState().loadedJsonAssignmentContent,binaryData:a.getState().loadedJsonAssignmentBinaryData}),[]),oe=t=>{const e=a(n=>n.setGetTextContentFunction);C.useEffect(()=>{e(t)},[t,e])},re=t=>{const e=a(n=>n.setGetJsonContentFunction);C.useEffect(()=>{e(t)},[t,e])},se=t=>{const e=a(n=>n.setGetJsonActivityContentFunction);C.useEffect(()=>{e(t)},[t,e])},ie=t=>{const e=a(n=>n.setGetJsonAssignmentContentFunction);C.useEffect(()=>{e(t)},[t,e])},ae=t=>{const e=a(n=>n.setGetJsonActivitySplitContentFunction);C.useEffect(()=>{e(t)},[t,e])},ce=t=>{const e=a(n=>n.setGetJsonAssignmentSplitContentFunction);C.useEffect(()=>{e(t)},[t,e])},le=t=>{const e=a(n=>n.afterSaveCount);C.useEffect(()=>{e>0&&t()},[e])},ue=()=>(t,e)=>{w.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)})},de=()=>(t,e)=>{w.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 D=0,B=0;const fe=(t,e)=>{const n=C.useMemo(t,e),s=a(o=>o.setSidebarActions);C.useEffect(()=>(D++,D>1&&console.error("Capytale iframe React: Multiple sidebar actions registered: ",D),()=>{D--}),[]),C.useEffect(()=>(w.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({}),w.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 G=0,W=0;const ge=(t,e)=>{const n=C.useMemo(t,e),s=a(o=>o.setQuickActions);C.useEffect(()=>(G++,G>1&&console.error("Capytale iframe React: Multiple quick actions registered: ",G),()=>{G--}),[]),C.useEffect(()=>(w.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({}),w.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 M=0;const lt=(t,e,n)=>{const s=C.useMemo(t,n),o=a(r=>r.setActivitySettingsCallback);C.useEffect(()=>(console.log("Mounting useSettings"),M++,M>1&&console.error("Capytale iframe React: Multiple settings registered: ",M),()=>{console.log("Unmounting useSettings"),M--}),[]),C.useEffect(()=>(w.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])},me=()=>e=>{w.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?.showToast(e)})};function pe(t){const e={};for(const n of t.fields)e[n.name]=n.defaultValue;return e}function ye(t){return{[t.name]:t.defaultValues}}function ve(t){return{[t.name]:t.defaultValue}}function Ce(t){switch(t.type){case"form":return pe(t);case"checkboxes":case"switches":return ye(t);case"radio":return ve(t);default:return{}}}function Se(t){const e={};for(const n of t)Object.assign(e,Ce(n));return e}function Ae(t){const n=ct()(s=>({...Se(t)}));return n.activitySettings=t,n}function we(t){lt(()=>t.activitySettings,e=>{t.setState(e)},[])}function he({store:t}){return we(t),null}const be=["meta-player-events:1","mode:1","workflow:1"];function Ee({children:t,contracts:e,loadOnlyWhenReady:n=!0,activitySettingsStore:s}){const o=a(r=>r.ready);return C.useEffect(()=>{const r=[...e];for(const g of be)r.includes(g)||r.push(g);$t(r)},[]),n&&!o?L.jsx("div",{className:"capy-loading-container",children:"Chargement en cours..."}):L.jsxs(L.Fragment,{children:[s&&L.jsx(he,{store:s}),t]})}exports.Capytale=Ee;exports.createActivitySettingsStore=Ae;exports.useAfterSaveAction=le;exports.useGetLoadedJsonActivityContent=Zt;exports.useGetLoadedJsonActivitySplitContent=ee;exports.useGetLoadedJsonAssignmentContent=te;exports.useGetLoadedJsonAssignmentSplitContent=ne;exports.useGetLoadedJsonContent=Xt;exports.useGetLoadedTextContent=Kt;exports.useJsonActivityContentSaveFunction=se;exports.useJsonActivitySplitContentSaveFunction=ae;exports.useJsonAssignmentContentSaveFunction=ie;exports.useJsonAssignmentSplitContentSaveFunction=ce;exports.useJsonContentSaveFunction=re;exports.useLoadedJsonActivityBinaryData=_t;exports.useLoadedJsonActivityContent=Ut;exports.useLoadedJsonAssignmentBinaryData=Yt;exports.useLoadedJsonAssignmentContent=Qt;exports.useLoadedJsonContent=zt;exports.useLoadedTextContent=Ht;exports.useMode=Ot;exports.useNotifyIsDirty=Wt;exports.usePreviewImageFile=de;exports.usePreviewTextFile=ue;exports.useQuickActions=ge;exports.useRequestSave=Bt;exports.useSettings=lt;exports.useShowToast=me;exports.useSidebarActions=fe;exports.useTextContentSaveFunction=oe;exports.useTheme=qt;exports.useWorkflow=Nt;
|
|
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();return v.useEffect(()=>{const s=e(t);return()=>{s.then(o=>{o!=null&&n(o)})}},[t,e,n]),null}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;
|
package/dist/index.d.ts
CHANGED
|
@@ -266,10 +266,18 @@ declare type MPToastMessage = {
|
|
|
266
266
|
life?: number;
|
|
267
267
|
};
|
|
268
268
|
|
|
269
|
+
export declare function TemporaryToast({ message }: {
|
|
270
|
+
message: MPToastMessage;
|
|
271
|
+
}): null;
|
|
272
|
+
|
|
269
273
|
declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
270
274
|
|
|
271
275
|
export declare const useAfterSaveAction: (fn: () => any) => void;
|
|
272
276
|
|
|
277
|
+
export declare const useClearToast: () => (id: Awaited<ReturnType<ReturnType<typeof useShowToast>>>) => Promise<void>;
|
|
278
|
+
|
|
279
|
+
export declare const useClearToasts: () => () => Promise<void>;
|
|
280
|
+
|
|
273
281
|
export declare const useGetLoadedJsonActivityContent: () => () => any;
|
|
274
282
|
|
|
275
283
|
export declare const useGetLoadedJsonActivitySplitContent: () => () => {
|
|
@@ -324,7 +332,7 @@ export declare const useRequestSave: () => () => void;
|
|
|
324
332
|
|
|
325
333
|
export declare const useSettings: <T extends ActivitySettings>(settingsUiFn: () => T | null, callback: (changes: Partial<InferValue<T>>) => void, deps: readonly unknown[]) => void;
|
|
326
334
|
|
|
327
|
-
export declare const useShowToast: () => (message: MPToastMessage) =>
|
|
335
|
+
export declare const useShowToast: () => (message: MPToastMessage) => Promise<number>;
|
|
328
336
|
|
|
329
337
|
export declare const useSidebarActions: (actionsFn: () => Action[], deps: readonly unknown[]) => void;
|
|
330
338
|
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as Q, jsxs as gt, Fragment as
|
|
2
|
-
import
|
|
3
|
-
const et = Symbol("Comlink.proxy"),
|
|
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";
|
|
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) {
|
|
6
6
|
const { port1: e, port2: n } = new MessageChannel();
|
|
@@ -10,7 +10,7 @@ const et = Symbol("Comlink.proxy"), pt = Symbol("Comlink.endpoint"), yt = Symbol
|
|
|
10
10
|
return t.start(), st(t);
|
|
11
11
|
}
|
|
12
12
|
}, Ct = {
|
|
13
|
-
canHandle: (t) => nt(t) &&
|
|
13
|
+
canHandle: (t) => nt(t) && I in t,
|
|
14
14
|
serialize({ value: t }) {
|
|
15
15
|
let e;
|
|
16
16
|
return t instanceof Error ? e = {
|
|
@@ -43,23 +43,23 @@ function _(t, e = globalThis, n = ["*"]) {
|
|
|
43
43
|
console.warn(`Invalid origin '${o.origin}' for comlink proxy`);
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
|
-
const { id: r, type: g, path: c } = Object.assign({ path: [] }, o.data), f = (o.data.argumentList || []).map(
|
|
46
|
+
const { id: r, type: g, path: c } = Object.assign({ path: [] }, o.data), f = (o.data.argumentList || []).map(F);
|
|
47
47
|
let d;
|
|
48
48
|
try {
|
|
49
|
-
const u = c.slice(0, -1).reduce((y, C) => y[C], t),
|
|
49
|
+
const u = c.slice(0, -1).reduce((y, C) => y[C], t), p = c.reduce((y, C) => y[C], t);
|
|
50
50
|
switch (g) {
|
|
51
51
|
case "GET":
|
|
52
|
-
d =
|
|
52
|
+
d = p;
|
|
53
53
|
break;
|
|
54
54
|
case "SET":
|
|
55
|
-
u[c.slice(-1)[0]] =
|
|
55
|
+
u[c.slice(-1)[0]] = F(o.data.value), d = !0;
|
|
56
56
|
break;
|
|
57
57
|
case "APPLY":
|
|
58
|
-
d =
|
|
58
|
+
d = p.apply(u, f);
|
|
59
59
|
break;
|
|
60
60
|
case "CONSTRUCT":
|
|
61
61
|
{
|
|
62
|
-
const y = new
|
|
62
|
+
const y = new p(...f);
|
|
63
63
|
d = ct(y);
|
|
64
64
|
}
|
|
65
65
|
break;
|
|
@@ -76,17 +76,17 @@ function _(t, e = globalThis, n = ["*"]) {
|
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
} catch (u) {
|
|
79
|
-
d = { value: u, [
|
|
79
|
+
d = { value: u, [I]: 0 };
|
|
80
80
|
}
|
|
81
|
-
Promise.resolve(d).catch((u) => ({ value: u, [
|
|
82
|
-
const [
|
|
83
|
-
e.postMessage(Object.assign(Object.assign({},
|
|
81
|
+
Promise.resolve(d).catch((u) => ({ value: u, [I]: 0 })).then((u) => {
|
|
82
|
+
const [p, y] = O(u);
|
|
83
|
+
e.postMessage(Object.assign(Object.assign({}, p), { id: r }), y), g === "RELEASE" && (e.removeEventListener("message", s), rt(e), q in t && typeof t[q] == "function" && t[q]());
|
|
84
84
|
}).catch((u) => {
|
|
85
|
-
const [
|
|
85
|
+
const [p, y] = O({
|
|
86
86
|
value: new TypeError("Unserializable return value"),
|
|
87
|
-
[
|
|
87
|
+
[I]: 0
|
|
88
88
|
});
|
|
89
|
-
e.postMessage(Object.assign(Object.assign({},
|
|
89
|
+
e.postMessage(Object.assign(Object.assign({}, p), { id: r }), y);
|
|
90
90
|
});
|
|
91
91
|
}), e.start && e.start();
|
|
92
92
|
}
|
|
@@ -111,7 +111,7 @@ function st(t, e) {
|
|
|
111
111
|
}
|
|
112
112
|
}), z(t, n, [], e);
|
|
113
113
|
}
|
|
114
|
-
function
|
|
114
|
+
function M(t) {
|
|
115
115
|
if (t)
|
|
116
116
|
throw new Error("Proxy has been released and is not useable");
|
|
117
117
|
}
|
|
@@ -138,7 +138,7 @@ function z(t, e, n = [], s = function() {
|
|
|
138
138
|
let o = !1;
|
|
139
139
|
const r = new Proxy(s, {
|
|
140
140
|
get(g, c) {
|
|
141
|
-
if (
|
|
141
|
+
if (M(o), c === yt)
|
|
142
142
|
return () => {
|
|
143
143
|
At(r), it(t), e.clear(), o = !0;
|
|
144
144
|
};
|
|
@@ -148,44 +148,44 @@ function z(t, e, n = [], s = function() {
|
|
|
148
148
|
const f = R(t, e, {
|
|
149
149
|
type: "GET",
|
|
150
150
|
path: n.map((d) => d.toString())
|
|
151
|
-
}).then(
|
|
151
|
+
}).then(F);
|
|
152
152
|
return f.then.bind(f);
|
|
153
153
|
}
|
|
154
154
|
return z(t, e, [...n, c]);
|
|
155
155
|
},
|
|
156
156
|
set(g, c, f) {
|
|
157
|
-
|
|
157
|
+
M(o);
|
|
158
158
|
const [d, u] = O(f);
|
|
159
159
|
return R(t, e, {
|
|
160
160
|
type: "SET",
|
|
161
|
-
path: [...n, c].map((
|
|
161
|
+
path: [...n, c].map((p) => p.toString()),
|
|
162
162
|
value: d
|
|
163
|
-
}, u).then(
|
|
163
|
+
}, u).then(F);
|
|
164
164
|
},
|
|
165
165
|
apply(g, c, f) {
|
|
166
|
-
|
|
166
|
+
M(o);
|
|
167
167
|
const d = n[n.length - 1];
|
|
168
|
-
if (d ===
|
|
168
|
+
if (d === mt)
|
|
169
169
|
return R(t, e, {
|
|
170
170
|
type: "ENDPOINT"
|
|
171
|
-
}).then(
|
|
171
|
+
}).then(F);
|
|
172
172
|
if (d === "bind")
|
|
173
173
|
return z(t, e, n.slice(0, -1));
|
|
174
|
-
const [u,
|
|
174
|
+
const [u, p] = Y(f);
|
|
175
175
|
return R(t, e, {
|
|
176
176
|
type: "APPLY",
|
|
177
177
|
path: n.map((y) => y.toString()),
|
|
178
178
|
argumentList: u
|
|
179
|
-
},
|
|
179
|
+
}, p).then(F);
|
|
180
180
|
},
|
|
181
181
|
construct(g, c) {
|
|
182
|
-
|
|
182
|
+
M(o);
|
|
183
183
|
const [f, d] = Y(c);
|
|
184
184
|
return R(t, e, {
|
|
185
185
|
type: "CONSTRUCT",
|
|
186
186
|
path: n.map((u) => u.toString()),
|
|
187
187
|
argumentList: f
|
|
188
|
-
}, d).then(
|
|
188
|
+
}, d).then(F);
|
|
189
189
|
}
|
|
190
190
|
});
|
|
191
191
|
return ht(r, t), r;
|
|
@@ -232,7 +232,7 @@ function O(t) {
|
|
|
232
232
|
at.get(t) || []
|
|
233
233
|
];
|
|
234
234
|
}
|
|
235
|
-
function
|
|
235
|
+
function F(t) {
|
|
236
236
|
switch (t.type) {
|
|
237
237
|
case "HANDLER":
|
|
238
238
|
return ot.get(t.name).deserialize(t.value);
|
|
@@ -269,24 +269,24 @@ function xt(t, e) {
|
|
|
269
269
|
done() {
|
|
270
270
|
return Promise.resolve();
|
|
271
271
|
},
|
|
272
|
-
provide(u,
|
|
272
|
+
provide(u, p, y) {
|
|
273
273
|
return Promise.resolve();
|
|
274
274
|
}
|
|
275
275
|
};
|
|
276
276
|
else {
|
|
277
277
|
const u = kt(window.parent, void 0, e);
|
|
278
278
|
_({
|
|
279
|
-
declare(
|
|
279
|
+
declare(p) {
|
|
280
280
|
if (s == null) throw new Error(g("No handler for declare"));
|
|
281
|
-
s(
|
|
281
|
+
s(p);
|
|
282
282
|
},
|
|
283
283
|
done() {
|
|
284
284
|
if (o == null) throw new Error(g("No handler for done"));
|
|
285
285
|
o();
|
|
286
286
|
},
|
|
287
|
-
provide(
|
|
287
|
+
provide(p, y, C) {
|
|
288
288
|
if (r == null) throw new Error(g("No handler for provide"));
|
|
289
|
-
r(
|
|
289
|
+
r(p, y, C);
|
|
290
290
|
}
|
|
291
291
|
}, u), c = st(u), f = !0;
|
|
292
292
|
}
|
|
@@ -299,7 +299,7 @@ function xt(t, e) {
|
|
|
299
299
|
return {
|
|
300
300
|
declare: (u) => c.declare(u),
|
|
301
301
|
done: () => c.done(),
|
|
302
|
-
provide: (u,
|
|
302
|
+
provide: (u, p, y) => c.provide(u, p, ct(y)),
|
|
303
303
|
get name() {
|
|
304
304
|
return t;
|
|
305
305
|
},
|
|
@@ -317,23 +317,23 @@ function xt(t, e) {
|
|
|
317
317
|
}
|
|
318
318
|
};
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function Tt(t) {
|
|
321
321
|
return function(e) {
|
|
322
|
-
let n, s = !1, o = !1, r, g, c = !1, f = !1, d, u,
|
|
322
|
+
let n, s = !1, o = !1, r, g, c = !1, f = !1, d, u, p, y;
|
|
323
323
|
function C() {
|
|
324
324
|
if (r != null && r !== 0 && g != null)
|
|
325
325
|
return g;
|
|
326
326
|
}
|
|
327
|
-
function
|
|
327
|
+
function k(i) {
|
|
328
328
|
if (r != null && g != null && !(i > r))
|
|
329
329
|
return g;
|
|
330
330
|
}
|
|
331
331
|
function A() {
|
|
332
|
-
return
|
|
332
|
+
return p ?? (f ? p = Promise.resolve() : p = new Promise((i, l) => {
|
|
333
333
|
y = i;
|
|
334
334
|
}));
|
|
335
335
|
}
|
|
336
|
-
function
|
|
336
|
+
function x() {
|
|
337
337
|
return d === void 0 && (d = {
|
|
338
338
|
get name() {
|
|
339
339
|
return e;
|
|
@@ -344,7 +344,7 @@ function Rt(t) {
|
|
|
344
344
|
get i() {
|
|
345
345
|
return C();
|
|
346
346
|
},
|
|
347
|
-
v: (i) =>
|
|
347
|
+
v: (i) => k(i)
|
|
348
348
|
}), d;
|
|
349
349
|
}
|
|
350
350
|
function V() {
|
|
@@ -358,16 +358,16 @@ function Rt(t) {
|
|
|
358
358
|
get i() {
|
|
359
359
|
return f ? C() : void 0;
|
|
360
360
|
},
|
|
361
|
-
v: (i) => f ?
|
|
361
|
+
v: (i) => f ? k(i) : void 0,
|
|
362
362
|
get promise() {
|
|
363
363
|
return r === 0 ? Promise.reject(t("Remote interface not provided")) : A().then(() => {
|
|
364
364
|
if (r === 0) throw new Error(t("Remote interface not provided"));
|
|
365
|
-
return
|
|
365
|
+
return x();
|
|
366
366
|
});
|
|
367
367
|
}
|
|
368
368
|
}), u;
|
|
369
369
|
}
|
|
370
|
-
function
|
|
370
|
+
function J() {
|
|
371
371
|
y != null && (y(), y = void 0);
|
|
372
372
|
}
|
|
373
373
|
return {
|
|
@@ -431,10 +431,10 @@ function Rt(t) {
|
|
|
431
431
|
if (!f) {
|
|
432
432
|
if (!c) throw new Error(t("Remote interface not provided."));
|
|
433
433
|
if (!o) throw new Error(t("Local interface not sent"));
|
|
434
|
-
f = !0,
|
|
434
|
+
f = !0, J();
|
|
435
435
|
}
|
|
436
436
|
},
|
|
437
|
-
getRemote: () =>
|
|
437
|
+
getRemote: () => x(),
|
|
438
438
|
getLazyRemote: () => V(),
|
|
439
439
|
get activationPromise() {
|
|
440
440
|
return A();
|
|
@@ -442,7 +442,7 @@ function Rt(t) {
|
|
|
442
442
|
};
|
|
443
443
|
};
|
|
444
444
|
}
|
|
445
|
-
function
|
|
445
|
+
function Rt(t) {
|
|
446
446
|
return function(e, n, s, o) {
|
|
447
447
|
let r = s, g = !1, c = !1;
|
|
448
448
|
function f() {
|
|
@@ -477,9 +477,9 @@ function Tt(t) {
|
|
|
477
477
|
let d;
|
|
478
478
|
o ? d = e.map((y) => y.getRemote()) : d = e[0].getRemote();
|
|
479
479
|
let u;
|
|
480
|
-
const
|
|
480
|
+
const p = n.length > 0 ? n.map((y) => y.getRemote()) : null;
|
|
481
481
|
try {
|
|
482
|
-
u =
|
|
482
|
+
u = p == null ? r(d) : r(d, p);
|
|
483
483
|
} catch (y) {
|
|
484
484
|
throw new Error(t("error in factory:"), { cause: y });
|
|
485
485
|
}
|
|
@@ -528,40 +528,40 @@ function Vt(t) {
|
|
|
528
528
|
function lt(t, e) {
|
|
529
529
|
return t == null || t.length === 0 ? e : `[${t}] ${e}`;
|
|
530
530
|
}
|
|
531
|
-
function
|
|
531
|
+
function Pt(t) {
|
|
532
532
|
function e(i) {
|
|
533
533
|
return lt(t.name, i);
|
|
534
534
|
}
|
|
535
|
-
const n = Vt(e), s =
|
|
535
|
+
const n = Vt(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
538
|
function u(i) {
|
|
539
539
|
let l = r[i];
|
|
540
|
-
return l == null && (l = s(i), l.localVersion == null && (A && (l.localVersion = 0),
|
|
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;
|
|
541
541
|
}
|
|
542
|
-
function
|
|
542
|
+
function p(i) {
|
|
543
543
|
return i.map(u);
|
|
544
544
|
}
|
|
545
545
|
function y(...i) {
|
|
546
|
-
const l = d(),
|
|
546
|
+
const l = d(), m = Array(l).fill(!1);
|
|
547
547
|
i.forEach((v) => {
|
|
548
548
|
v.forEach((S) => {
|
|
549
|
-
S.depGroup != null && (
|
|
549
|
+
S.depGroup != null && (m[S.depGroup] = !0), S.depGroup = l;
|
|
550
550
|
});
|
|
551
551
|
}), Object.values(r).forEach((v) => {
|
|
552
|
-
v.depGroup != null && v.depGroup !== l &&
|
|
552
|
+
v.depGroup != null && v.depGroup !== l && m[v.depGroup] && (v.depGroup = l);
|
|
553
553
|
});
|
|
554
554
|
}
|
|
555
555
|
t.onDeclare = (i) => {
|
|
556
|
-
const l =
|
|
557
|
-
for (let
|
|
558
|
-
i[
|
|
559
|
-
y(l),
|
|
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);
|
|
559
|
+
y(l), J();
|
|
560
560
|
}, t.onDone = () => {
|
|
561
561
|
V || (V = !0, Object.values(r).forEach((i) => {
|
|
562
562
|
i.remoteVersion == null && (i.remoteVersion = 0);
|
|
563
|
-
}),
|
|
564
|
-
}, t.onProvide = (i, l,
|
|
563
|
+
}), J());
|
|
564
|
+
}, t.onProvide = (i, l, m) => {
|
|
565
565
|
let v = r[i];
|
|
566
566
|
if (v == null)
|
|
567
567
|
throw new Error(e(`Contract not declared : ${i}`));
|
|
@@ -569,18 +569,18 @@ function Dt(t) {
|
|
|
569
569
|
throw new Error(e(`Remote declared version ${v.remoteVersion} of contract "${i}" but provided version ${l}.`));
|
|
570
570
|
if (v.remoteInterfaceReceived)
|
|
571
571
|
throw new Error(e(`Remote contract "${i}" is already provided.`));
|
|
572
|
-
v.setRemoteInterface(
|
|
572
|
+
v.setRemoteInterface(m), J();
|
|
573
573
|
};
|
|
574
|
-
let C = !1,
|
|
575
|
-
async function
|
|
576
|
-
if (
|
|
577
|
-
for (C = !0;
|
|
578
|
-
if (
|
|
574
|
+
let C = !1, k = !1, A = !1, x = !1, V = !1;
|
|
575
|
+
async function J() {
|
|
576
|
+
if (k = !0, !C) {
|
|
577
|
+
for (C = !0; k; ) {
|
|
578
|
+
if (k = !1, t.isReady) {
|
|
579
579
|
const i = g.filter((l) => !l.isDeclared);
|
|
580
580
|
if (i.length > 0)
|
|
581
581
|
for (const l of i) {
|
|
582
|
-
const
|
|
583
|
-
l.args.forEach((v, S) =>
|
|
582
|
+
const m = Array(l.args.length + l.deps.length);
|
|
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
|
}
|
|
@@ -590,37 +590,37 @@ function Dt(t) {
|
|
|
590
590
|
if (i.length > 0)
|
|
591
591
|
for (const l of i)
|
|
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
596
|
const i = g.filter((l) => !l.isDone && l.isReady);
|
|
597
597
|
if (i.length > 0)
|
|
598
598
|
for (const l of i) {
|
|
599
|
-
const
|
|
599
|
+
const m = l.invoke();
|
|
600
600
|
for (let v = 0; v < l.args.length; v++) {
|
|
601
601
|
const S = l.args[v];
|
|
602
|
-
await t.provide(S.name, S.localVersion,
|
|
602
|
+
await t.provide(S.name, S.localVersion, m[v]), S.localInterfaceSent = !0;
|
|
603
603
|
}
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
606
|
if (f != null) {
|
|
607
607
|
const i = Array(f + 1).fill(null);
|
|
608
608
|
for (const l in r) {
|
|
609
|
-
const
|
|
610
|
-
|
|
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);
|
|
611
611
|
}
|
|
612
612
|
if (i.some((l) => l === !0))
|
|
613
613
|
for (const l in r) {
|
|
614
|
-
const
|
|
615
|
-
|
|
614
|
+
const m = r[l];
|
|
615
|
+
m.depGroup != null && i[m.depGroup] && m.activate();
|
|
616
616
|
}
|
|
617
617
|
}
|
|
618
618
|
if (t.isReady) {
|
|
619
619
|
const i = c;
|
|
620
620
|
c = [];
|
|
621
621
|
const l = [];
|
|
622
|
-
for (const
|
|
623
|
-
!
|
|
622
|
+
for (const m of i)
|
|
623
|
+
!m.isDone && m.isReady ? m.invoke() : l.push(m);
|
|
624
624
|
l.push(...c), c = l;
|
|
625
625
|
}
|
|
626
626
|
}
|
|
@@ -631,9 +631,9 @@ function Dt(t) {
|
|
|
631
631
|
get(i) {
|
|
632
632
|
return u(i);
|
|
633
633
|
},
|
|
634
|
-
declareFactory: (i, l,
|
|
634
|
+
declareFactory: (i, l, m, v) => {
|
|
635
635
|
if (A) throw new Error(e("Cannot declare a factory after done has been set to true."));
|
|
636
|
-
const S =
|
|
636
|
+
const S = p(i.map((b) => b.name));
|
|
637
637
|
{
|
|
638
638
|
const b = S.filter((N) => N.localVersion != null);
|
|
639
639
|
if (b.length > 0)
|
|
@@ -641,14 +641,14 @@ function Dt(t) {
|
|
|
641
641
|
}
|
|
642
642
|
for (let b = 0; b < i.length; b++)
|
|
643
643
|
S[b].localVersion = i[b].version;
|
|
644
|
-
const
|
|
645
|
-
y(S,
|
|
646
|
-
const ft = o(S,
|
|
647
|
-
g.push(ft),
|
|
644
|
+
const T = p(l);
|
|
645
|
+
y(S, T);
|
|
646
|
+
const ft = o(S, T, m, v);
|
|
647
|
+
g.push(ft), J();
|
|
648
648
|
},
|
|
649
|
-
declareCallback(i, l,
|
|
650
|
-
const S =
|
|
651
|
-
!C && c.length === 0 &&
|
|
649
|
+
declareCallback(i, l, m, v) {
|
|
650
|
+
const S = p(i), T = n(S, l, m, v);
|
|
651
|
+
!C && c.length === 0 && T.isReady ? T.invoke() : (c.push(T), J());
|
|
652
652
|
},
|
|
653
653
|
get done() {
|
|
654
654
|
return A;
|
|
@@ -659,19 +659,19 @@ function Dt(t) {
|
|
|
659
659
|
} else
|
|
660
660
|
i && (A = !0, Object.values(r).forEach((l) => {
|
|
661
661
|
l.localVersion == null && (l.localVersion = 0);
|
|
662
|
-
}),
|
|
662
|
+
}), J());
|
|
663
663
|
}
|
|
664
664
|
};
|
|
665
665
|
}
|
|
666
|
-
const
|
|
667
|
-
function
|
|
666
|
+
const Mt = /^\d+$/;
|
|
667
|
+
function Dt(t) {
|
|
668
668
|
const [e, n, s] = t.split(":", 3);
|
|
669
|
-
if (n == null || s != null || !
|
|
669
|
+
if (n == null || s != null || !Mt.test(n)) return null;
|
|
670
670
|
const o = parseInt(n);
|
|
671
671
|
return isNaN(o) || o === 0 ? null : { name: e, version: o };
|
|
672
672
|
}
|
|
673
|
-
function
|
|
674
|
-
const e =
|
|
673
|
+
function Lt(t) {
|
|
674
|
+
const e = Pt(t);
|
|
675
675
|
function n(s) {
|
|
676
676
|
return lt(t.name, s);
|
|
677
677
|
}
|
|
@@ -682,7 +682,7 @@ function Gt(t) {
|
|
|
682
682
|
let g = !0;
|
|
683
683
|
Array.isArray(s) || (s = [s], g = !1);
|
|
684
684
|
const c = s.map((f) => {
|
|
685
|
-
const d =
|
|
685
|
+
const d = Dt(f);
|
|
686
686
|
if (d == null)
|
|
687
687
|
throw new Error(n("Invalid contract id : " + f));
|
|
688
688
|
return d;
|
|
@@ -709,31 +709,31 @@ function Gt(t) {
|
|
|
709
709
|
}
|
|
710
710
|
const ut = "app-agent";
|
|
711
711
|
let B;
|
|
712
|
-
function
|
|
713
|
-
return B != null || (B =
|
|
712
|
+
function Gt(t) {
|
|
713
|
+
return B != null || (B = Lt(xt(ut, t))), B;
|
|
714
714
|
}
|
|
715
715
|
console.log(`[${ut}@1.0.12] loaded`);
|
|
716
716
|
const K = (t) => {
|
|
717
717
|
let e;
|
|
718
718
|
const n = /* @__PURE__ */ new Set(), s = (d, u) => {
|
|
719
|
-
const
|
|
720
|
-
if (!Object.is(
|
|
719
|
+
const p = typeof d == "function" ? d(e) : d;
|
|
720
|
+
if (!Object.is(p, e)) {
|
|
721
721
|
const y = e;
|
|
722
|
-
e = u ?? (typeof
|
|
722
|
+
e = u ?? (typeof p != "object" || p === null) ? p : Object.assign({}, e, p), n.forEach((C) => C(e, y));
|
|
723
723
|
}
|
|
724
724
|
}, o = () => e, c = { setState: s, getState: o, getInitialState: () => f, subscribe: (d) => (n.add(d), () => n.delete(d)) }, f = e = t(s, o, c);
|
|
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 =
|
|
728
|
+
const n = P.useSyncExternalStore(
|
|
729
729
|
t.subscribe,
|
|
730
|
-
|
|
731
|
-
|
|
730
|
+
P.useCallback(() => e(t.getState()), [t, e]),
|
|
731
|
+
P.useCallback(() => e(t.getInitialState()), [t, e])
|
|
732
732
|
);
|
|
733
|
-
return
|
|
733
|
+
return P.useDebugValue(n), n;
|
|
734
734
|
}
|
|
735
735
|
const X = (t) => {
|
|
736
|
-
const e =
|
|
736
|
+
const e = It(t), n = (s) => $t(e, s);
|
|
737
737
|
return Object.assign(n, e), n;
|
|
738
738
|
}, dt = (t) => t ? X(t) : X, Ot = (t) => (e, n, s) => {
|
|
739
739
|
const o = s.subscribe;
|
|
@@ -741,14 +741,14 @@ const X = (t) => {
|
|
|
741
741
|
let d = g;
|
|
742
742
|
if (c) {
|
|
743
743
|
const u = f?.equalityFn || Object.is;
|
|
744
|
-
let
|
|
744
|
+
let p = g(s.getState());
|
|
745
745
|
d = (y) => {
|
|
746
746
|
const C = g(y);
|
|
747
|
-
if (!u(
|
|
748
|
-
const
|
|
749
|
-
c(
|
|
747
|
+
if (!u(p, C)) {
|
|
748
|
+
const k = p;
|
|
749
|
+
c(p = C, k);
|
|
750
750
|
}
|
|
751
|
-
}, f?.fireImmediately && c(
|
|
751
|
+
}, f?.fireImmediately && c(p, p);
|
|
752
752
|
}
|
|
753
753
|
return o(d);
|
|
754
754
|
}, t(e, n, s);
|
|
@@ -1037,7 +1037,7 @@ const qt = [
|
|
|
1037
1037
|
t === "all-loaded" && a.setState({ ready: !0 });
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
|
-
}, h =
|
|
1040
|
+
}, h = Gt();
|
|
1041
1041
|
function Bt(t) {
|
|
1042
1042
|
if (Z) {
|
|
1043
1043
|
console.warn("Contracts have already been plugged. Skipping.");
|
|
@@ -1085,80 +1085,80 @@ function Bt(t) {
|
|
|
1085
1085
|
});
|
|
1086
1086
|
}
|
|
1087
1087
|
}
|
|
1088
|
-
const
|
|
1088
|
+
const oe = () => a((t) => {
|
|
1089
1089
|
if (t.mode === null)
|
|
1090
1090
|
throw new Error("Mode is not set. Have you used contract 'mode'?");
|
|
1091
1091
|
return t.mode;
|
|
1092
|
-
}),
|
|
1092
|
+
}), re = () => a((t) => {
|
|
1093
1093
|
if (t.workflow === null)
|
|
1094
1094
|
throw new Error(
|
|
1095
1095
|
"Workflow is not set. Have you used contract 'workflow'?"
|
|
1096
1096
|
);
|
|
1097
1097
|
return t.workflow;
|
|
1098
|
-
}),
|
|
1098
|
+
}), se = () => a((t) => {
|
|
1099
1099
|
if (t.theme === null)
|
|
1100
1100
|
throw new Error("Theme is not set. Have you used contract 'theme'?");
|
|
1101
1101
|
return t.theme;
|
|
1102
|
-
}),
|
|
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(
|
|
1103
1103
|
() => ({
|
|
1104
1104
|
content: a.getState().loadedJsonActivityContent,
|
|
1105
1105
|
binaryData: a.getState().loadedJsonActivityBinaryData
|
|
1106
1106
|
}),
|
|
1107
1107
|
[]
|
|
1108
|
-
),
|
|
1108
|
+
), Se = () => E(
|
|
1109
1109
|
() => ({
|
|
1110
1110
|
content: a.getState().loadedJsonAssignmentContent,
|
|
1111
1111
|
binaryData: a.getState().loadedJsonAssignmentBinaryData
|
|
1112
1112
|
}),
|
|
1113
1113
|
[]
|
|
1114
|
-
),
|
|
1114
|
+
), we = (t) => {
|
|
1115
1115
|
const e = a(
|
|
1116
1116
|
(n) => n.setGetTextContentFunction
|
|
1117
1117
|
);
|
|
1118
1118
|
w(() => {
|
|
1119
1119
|
e(t);
|
|
1120
1120
|
}, [t, e]);
|
|
1121
|
-
},
|
|
1121
|
+
}, he = (t) => {
|
|
1122
1122
|
const e = a(
|
|
1123
1123
|
(n) => n.setGetJsonContentFunction
|
|
1124
1124
|
);
|
|
1125
1125
|
w(() => {
|
|
1126
1126
|
e(t);
|
|
1127
1127
|
}, [t, e]);
|
|
1128
|
-
},
|
|
1128
|
+
}, Ae = (t) => {
|
|
1129
1129
|
const e = a(
|
|
1130
1130
|
(n) => n.setGetJsonActivityContentFunction
|
|
1131
1131
|
);
|
|
1132
1132
|
w(() => {
|
|
1133
1133
|
e(t);
|
|
1134
1134
|
}, [t, e]);
|
|
1135
|
-
},
|
|
1135
|
+
}, be = (t) => {
|
|
1136
1136
|
const e = a(
|
|
1137
1137
|
(n) => n.setGetJsonAssignmentContentFunction
|
|
1138
1138
|
);
|
|
1139
1139
|
w(() => {
|
|
1140
1140
|
e(t);
|
|
1141
1141
|
}, [t, e]);
|
|
1142
|
-
},
|
|
1142
|
+
}, Ee = (t) => {
|
|
1143
1143
|
const e = a(
|
|
1144
1144
|
(n) => n.setGetJsonActivitySplitContentFunction
|
|
1145
1145
|
);
|
|
1146
1146
|
w(() => {
|
|
1147
1147
|
e(t);
|
|
1148
1148
|
}, [t, e]);
|
|
1149
|
-
},
|
|
1149
|
+
}, ke = (t) => {
|
|
1150
1150
|
const e = a(
|
|
1151
1151
|
(n) => n.setGetJsonAssignmentSplitContentFunction
|
|
1152
1152
|
);
|
|
1153
1153
|
w(() => {
|
|
1154
1154
|
e(t);
|
|
1155
1155
|
}, [t, e]);
|
|
1156
|
-
},
|
|
1156
|
+
}, Je = (t) => {
|
|
1157
1157
|
const e = a((n) => n.afterSaveCount);
|
|
1158
1158
|
w(() => {
|
|
1159
1159
|
e > 0 && t();
|
|
1160
1160
|
}, [e]);
|
|
1161
|
-
},
|
|
1161
|
+
}, Fe = () => (t, e) => {
|
|
1162
1162
|
h.use(["meta-player-ui"], ([n]) => {
|
|
1163
1163
|
if (n.version === 0) {
|
|
1164
1164
|
console.error(
|
|
@@ -1168,7 +1168,7 @@ const ee = () => a((t) => {
|
|
|
1168
1168
|
}
|
|
1169
1169
|
n.i?.previewTextFile(t, e);
|
|
1170
1170
|
});
|
|
1171
|
-
},
|
|
1171
|
+
}, xe = () => (t, e) => {
|
|
1172
1172
|
h.use(["meta-player-ui"], ([n]) => {
|
|
1173
1173
|
if (n.version === 0) {
|
|
1174
1174
|
console.error(
|
|
@@ -1179,14 +1179,14 @@ const ee = () => a((t) => {
|
|
|
1179
1179
|
n.i?.previewImageFile(t, e);
|
|
1180
1180
|
});
|
|
1181
1181
|
};
|
|
1182
|
-
let
|
|
1183
|
-
const
|
|
1182
|
+
let D = 0, W = 0;
|
|
1183
|
+
const Te = (t, e) => {
|
|
1184
1184
|
const n = U(t, e), s = a((o) => o.setSidebarActions);
|
|
1185
|
-
w(() => (
|
|
1185
|
+
w(() => (D++, D > 1 && console.error(
|
|
1186
1186
|
"Capytale iframe React: Multiple sidebar actions registered: ",
|
|
1187
|
-
|
|
1187
|
+
D
|
|
1188
1188
|
), () => {
|
|
1189
|
-
|
|
1189
|
+
D--;
|
|
1190
1190
|
}), []), w(() => (h.use(["meta-player-ui"], ([o]) => {
|
|
1191
1191
|
if (o.version === 0) {
|
|
1192
1192
|
console.error(
|
|
@@ -1217,14 +1217,14 @@ const Fe = (t, e) => {
|
|
|
1217
1217
|
});
|
|
1218
1218
|
}), [n]);
|
|
1219
1219
|
};
|
|
1220
|
-
let
|
|
1221
|
-
const
|
|
1220
|
+
let L = 0, H = 0;
|
|
1221
|
+
const Re = (t, e) => {
|
|
1222
1222
|
const n = U(t, e), s = a((o) => o.setQuickActions);
|
|
1223
|
-
w(() => (
|
|
1223
|
+
w(() => (L++, L > 1 && console.error(
|
|
1224
1224
|
"Capytale iframe React: Multiple quick actions registered: ",
|
|
1225
|
-
|
|
1225
|
+
L
|
|
1226
1226
|
), () => {
|
|
1227
|
-
|
|
1227
|
+
L--;
|
|
1228
1228
|
}), []), w(() => (h.use(["meta-player-ui"], ([o]) => {
|
|
1229
1229
|
if (o.version === 0) {
|
|
1230
1230
|
console.error(
|
|
@@ -1255,16 +1255,16 @@ const xe = (t, e) => {
|
|
|
1255
1255
|
});
|
|
1256
1256
|
}), [n]);
|
|
1257
1257
|
};
|
|
1258
|
-
let
|
|
1258
|
+
let G = 0;
|
|
1259
1259
|
const Wt = (t, e, n) => {
|
|
1260
1260
|
const s = U(t, n), o = a(
|
|
1261
1261
|
(r) => r.setActivitySettingsCallback
|
|
1262
1262
|
);
|
|
1263
|
-
w(() => (console.log("Mounting useSettings"),
|
|
1263
|
+
w(() => (console.log("Mounting useSettings"), G++, G > 1 && console.error(
|
|
1264
1264
|
"Capytale iframe React: Multiple settings registered: ",
|
|
1265
|
-
|
|
1265
|
+
G
|
|
1266
1266
|
), () => {
|
|
1267
|
-
console.log("Unmounting useSettings"),
|
|
1267
|
+
console.log("Unmounting useSettings"), G--;
|
|
1268
1268
|
}), []), w(() => (h.use(["meta-player-ui"], ([r]) => {
|
|
1269
1269
|
if (r.version === 0) {
|
|
1270
1270
|
console.error(
|
|
@@ -1278,55 +1278,63 @@ const Wt = (t, e, n) => {
|
|
|
1278
1278
|
), () => {
|
|
1279
1279
|
o(null);
|
|
1280
1280
|
}), [s]);
|
|
1281
|
-
},
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1281
|
+
}, Ht = () => E((e) => h.exec(["meta-player-ui"], ([n]) => {
|
|
1282
|
+
if (n.version === 0)
|
|
1283
|
+
throw console.error(
|
|
1284
|
+
"Le MétaPlayer ne supporte pas le contrat meta-player-ui"
|
|
1285
|
+
), new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");
|
|
1286
|
+
return n.i?.showToast(e);
|
|
1287
|
+
}), []), zt = () => E((e) => h.exec(["meta-player-ui"], ([n]) => {
|
|
1288
|
+
if (n.version === 0)
|
|
1289
|
+
throw console.error(
|
|
1290
|
+
"Le MétaPlayer ne supporte pas le contrat meta-player-ui"
|
|
1291
|
+
), new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");
|
|
1292
|
+
return n.i?.clearToast(e);
|
|
1293
|
+
}), []), Ve = () => E(() => h.exec(["meta-player-ui"], ([e]) => {
|
|
1294
|
+
if (e.version === 0)
|
|
1295
|
+
throw console.error(
|
|
1296
|
+
"Le MétaPlayer ne supporte pas le contrat meta-player-ui"
|
|
1297
|
+
), new Error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");
|
|
1298
|
+
return e.i?.clearToasts();
|
|
1299
|
+
}), []);
|
|
1300
|
+
function Ut(t) {
|
|
1293
1301
|
const e = {};
|
|
1294
1302
|
for (const n of t.fields)
|
|
1295
1303
|
e[n.name] = n.defaultValue;
|
|
1296
1304
|
return e;
|
|
1297
1305
|
}
|
|
1298
|
-
function
|
|
1306
|
+
function _t(t) {
|
|
1299
1307
|
return { [t.name]: t.defaultValues };
|
|
1300
1308
|
}
|
|
1301
|
-
function
|
|
1309
|
+
function Qt(t) {
|
|
1302
1310
|
return { [t.name]: t.defaultValue };
|
|
1303
1311
|
}
|
|
1304
|
-
function
|
|
1312
|
+
function Yt(t) {
|
|
1305
1313
|
switch (t.type) {
|
|
1306
1314
|
case "form":
|
|
1307
|
-
return
|
|
1315
|
+
return Ut(t);
|
|
1308
1316
|
case "checkboxes":
|
|
1309
1317
|
case "switches":
|
|
1310
|
-
return
|
|
1318
|
+
return _t(t);
|
|
1311
1319
|
case "radio":
|
|
1312
|
-
return
|
|
1320
|
+
return Qt(t);
|
|
1313
1321
|
default:
|
|
1314
1322
|
return {};
|
|
1315
1323
|
}
|
|
1316
1324
|
}
|
|
1317
|
-
function
|
|
1325
|
+
function Kt(t) {
|
|
1318
1326
|
const e = {};
|
|
1319
1327
|
for (const n of t)
|
|
1320
|
-
Object.assign(e,
|
|
1328
|
+
Object.assign(e, Yt(n));
|
|
1321
1329
|
return e;
|
|
1322
1330
|
}
|
|
1323
|
-
function
|
|
1331
|
+
function Pe(t) {
|
|
1324
1332
|
const n = dt()((s) => ({
|
|
1325
|
-
...
|
|
1333
|
+
...Kt(t)
|
|
1326
1334
|
}));
|
|
1327
1335
|
return n.activitySettings = t, n;
|
|
1328
1336
|
}
|
|
1329
|
-
function
|
|
1337
|
+
function Xt(t) {
|
|
1330
1338
|
Wt(
|
|
1331
1339
|
() => t.activitySettings,
|
|
1332
1340
|
(e) => {
|
|
@@ -1335,17 +1343,17 @@ function Yt(t) {
|
|
|
1335
1343
|
[]
|
|
1336
1344
|
);
|
|
1337
1345
|
}
|
|
1338
|
-
function
|
|
1346
|
+
function Zt({
|
|
1339
1347
|
store: t
|
|
1340
1348
|
}) {
|
|
1341
|
-
return
|
|
1349
|
+
return Xt(t), null;
|
|
1342
1350
|
}
|
|
1343
|
-
const
|
|
1351
|
+
const te = [
|
|
1344
1352
|
"meta-player-events:1",
|
|
1345
1353
|
"mode:1",
|
|
1346
1354
|
"workflow:1"
|
|
1347
1355
|
];
|
|
1348
|
-
function
|
|
1356
|
+
function Me({
|
|
1349
1357
|
children: t,
|
|
1350
1358
|
contracts: e,
|
|
1351
1359
|
loadOnlyWhenReady: n = !0,
|
|
@@ -1354,45 +1362,59 @@ function Ve({
|
|
|
1354
1362
|
const o = a((r) => r.ready);
|
|
1355
1363
|
return w(() => {
|
|
1356
1364
|
const r = [...e];
|
|
1357
|
-
for (const g of
|
|
1365
|
+
for (const g of te)
|
|
1358
1366
|
r.includes(g) || r.push(g);
|
|
1359
1367
|
Bt(r);
|
|
1360
|
-
}, []), n && !o ? /* @__PURE__ */ Q("div", { className: "capy-loading-container", children: "Chargement en cours..." }) : /* @__PURE__ */ gt(
|
|
1361
|
-
s && /* @__PURE__ */ Q(
|
|
1368
|
+
}, []), n && !o ? /* @__PURE__ */ Q("div", { className: "capy-loading-container", children: "Chargement en cours..." }) : /* @__PURE__ */ gt(pt, { children: [
|
|
1369
|
+
s && /* @__PURE__ */ Q(Zt, { store: s }),
|
|
1362
1370
|
t
|
|
1363
1371
|
] });
|
|
1364
1372
|
}
|
|
1373
|
+
function De({ message: t }) {
|
|
1374
|
+
const e = Ht(), n = zt();
|
|
1375
|
+
return w(() => {
|
|
1376
|
+
const s = e(t);
|
|
1377
|
+
return () => {
|
|
1378
|
+
s.then((o) => {
|
|
1379
|
+
o != null && n(o);
|
|
1380
|
+
});
|
|
1381
|
+
};
|
|
1382
|
+
}, [t, e, n]), null;
|
|
1383
|
+
}
|
|
1365
1384
|
export {
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1385
|
+
Me as Capytale,
|
|
1386
|
+
De as TemporaryToast,
|
|
1387
|
+
Pe as createActivitySettingsStore,
|
|
1388
|
+
Je as useAfterSaveAction,
|
|
1389
|
+
zt as useClearToast,
|
|
1390
|
+
Ve as useClearToasts,
|
|
1391
|
+
ye as useGetLoadedJsonActivityContent,
|
|
1392
|
+
Ce as useGetLoadedJsonActivitySplitContent,
|
|
1393
|
+
ve as useGetLoadedJsonAssignmentContent,
|
|
1394
|
+
Se as useGetLoadedJsonAssignmentSplitContent,
|
|
1395
|
+
me as useGetLoadedJsonContent,
|
|
1396
|
+
pe as useGetLoadedTextContent,
|
|
1397
|
+
Ae as useJsonActivityContentSaveFunction,
|
|
1398
|
+
Ee as useJsonActivitySplitContentSaveFunction,
|
|
1399
|
+
be as useJsonAssignmentContentSaveFunction,
|
|
1400
|
+
ke as useJsonAssignmentSplitContentSaveFunction,
|
|
1401
|
+
he as useJsonContentSaveFunction,
|
|
1402
|
+
fe as useLoadedJsonActivityBinaryData,
|
|
1403
|
+
ue as useLoadedJsonActivityContent,
|
|
1404
|
+
ge as useLoadedJsonAssignmentBinaryData,
|
|
1405
|
+
de as useLoadedJsonAssignmentContent,
|
|
1406
|
+
le as useLoadedJsonContent,
|
|
1407
|
+
ce as useLoadedTextContent,
|
|
1408
|
+
oe as useMode,
|
|
1409
|
+
ae as useNotifyIsDirty,
|
|
1410
|
+
xe as usePreviewImageFile,
|
|
1411
|
+
Fe as usePreviewTextFile,
|
|
1412
|
+
Re as useQuickActions,
|
|
1413
|
+
ie as useRequestSave,
|
|
1392
1414
|
Wt as useSettings,
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1415
|
+
Ht as useShowToast,
|
|
1416
|
+
Te as useSidebarActions,
|
|
1417
|
+
we as useTextContentSaveFunction,
|
|
1418
|
+
se as useTheme,
|
|
1419
|
+
re as useWorkflow
|
|
1398
1420
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capytale/iframe-react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@capytale/app-agent": "^1.0.12",
|
|
30
|
-
"@capytale/contracts": "^1.1.1",
|
|
31
30
|
"zustand": "^5.0.9"
|
|
32
31
|
},
|
|
33
32
|
"peerDependencies": {
|
|
@@ -35,6 +34,7 @@
|
|
|
35
34
|
"react-dom": ">=17.0.0 <20"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
37
|
+
"@capytale/contracts": "^1.1.2",
|
|
38
38
|
"@types/node": "^22.13.1",
|
|
39
39
|
"@types/react": "^18.3.18",
|
|
40
40
|
"@types/react-dom": "^18.3.5",
|