@capytale/iframe-react 1.1.4 → 1.1.6
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 +2 -1
- package/dist/index.es.js +171 -134
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),c=require("react"),L=require("@capytale/app-agent"),b=t=>{let e;const o=new Set,s=(C,S)=>{const d=typeof C=="function"?C(e):C;if(!Object.is(d,e)){const A=e;e=S??(typeof d!="object"||d===null)?d:Object.assign({},e,d),o.forEach(f=>f(e,A))}},i=()=>e,a={setState:s,getState:i,getInitialState:()=>u,subscribe:C=>(o.add(C),()=>o.delete(C))},u=e=t(s,i,a);return a},G=t=>t?b(t):b,D=t=>t;function M(t,e=D){const o=c.useSyncExternalStore(t.subscribe,c.useCallback(()=>e(t.getState()),[t,e]),c.useCallback(()=>e(t.getInitialState()),[t,e]));return c.useDebugValue(o),o}const w=t=>{const e=G(t),o=s=>M(e,s);return Object.assign(o,e),o},x=t=>t?w(t):w,j=t=>(e,o,s)=>{const i=s.subscribe;return s.subscribe=(l,a,u)=>{let C=l;if(a){const S=u?.equalityFn||Object.is;let d=l(s.getState());C=A=>{const f=l(A);if(!S(d,f)){const E=d;a(d=f,E)}},u?.fireImmediately&&a(d,d)}return i(C)},t(e,o,s)},I=j,n=x()(I(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 h=!1;const q=["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=>{n.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){n.setState({theme:null});return}if(t!=="light"&&t!=="dark"){console.warn(`Invalid theme: ${t}. Expected 'light' or 'dark'.`),n.setState({theme:null});return}n.setState({theme:t})}},"workflow:1":{setWorkflow:t=>{n.setState({workflow:t})}},"simple-content(text):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getTextContentFunction(),loadContent:t=>{n.setState({loadedTextContent:t})}},"simple-content(json):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getJsonContentFunction(),loadContent:t=>{n.setState({loadedJsonContent:t})}},"simple-binary-data(text):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getTextContentFunction(),loadContent:t=>{n.setState({loadedTextContent:t})}},"simple-content-eval(text):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getTextContentFunction(),loadContent:t=>{n.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getJsonContentFunction(),loadContent:t=>{n.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(json):2":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getJsonContentFunction(),loadContent:t=>{n.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(text):2":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getTextContentFunction(),loadContent:t=>{n.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"separate-contents(json):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{n.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>n.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>n.getState().getJsonAssignmentContentFunction()},"separate-dual-contents(json):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:({activityContent:t,assignmentContent:e,activityBinaryData:o,assignmentBinaryData:s})=>{n.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e,loadedJsonActivityBinaryData:o,loadedJsonAssignmentBinaryData:s})},getActivityContentAndData:()=>n.getState().getJsonActivitySplitContentFunction(),getAssignmentContentAndData:()=>n.getState().getJsonAssignmentSplitContentFunction()},"meta-player-anti-cheat:1":{lock:()=>{},unlock:()=>{}},"meta-player-ui:1":{executeAction(t){if(t.startsWith("qa")){const o=n.getState().quickActions[t];o?o():console.error(`Quick action not found: ${t}`)}else{const o=n.getState().sidebarActions[t];o?o():console.error(`Sidebar action not found: ${t}`)}},executeFileUpload(t,e){if(t.startsWith("qa")){const s=n.getState().quickActions[t];s?s(e):console.error(`Quick action not found: ${t}`)}else{const s=n.getState().sidebarActions[t];s?s(e):console.error(`Sidebar action not found: ${t}`)}},updateSettings(t){const e=n.getState().activitySettingsCallback;e?e(t):console.warn("activitySettingsCallback is not set. Changes:",t)}},"meta-player-events:1":{handleEvent(t){t==="all-loaded"&&n.setState({ready:!0})}}},g=L.getSocket();function $(t){if(h){console.warn("Contracts have already been plugged. Skipping.");return}h=!0;for(const e of t){if(!q.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 o=k[e];g.plug([e],([])=>[o])}g.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 o=e.split(":")[0];g.use([o],([s])=>{n.subscribe(i=>i.isDirtyCount,()=>{s.i?.contentChanged(),console.log(`Content changed for contract ${o}`)})})}}const B=()=>n(t=>{if(t.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return t.mode}),P=()=>n(t=>{if(t.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return t.workflow}),R=()=>n(t=>{if(t.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return t.theme}),O=()=>n(t=>t.incSaveCount),W=()=>n(t=>t.incDirtyCount),Q=()=>n(t=>t.loadedTextContent),V=()=>n(t=>t.loadedJsonContent),N=()=>n(t=>t.loadedJsonActivityContent),H=()=>n(t=>t.loadedJsonAssignmentContent),U=()=>n(t=>t.loadedJsonActivityBinaryData),_=()=>n(t=>t.loadedJsonAssignmentBinaryData),z=()=>()=>n.getState().loadedTextContent,K=()=>()=>n.getState().loadedJsonContent,X=()=>()=>n.getState().loadedJsonActivityContent,Y=()=>()=>n.getState().loadedJsonAssignmentContent,Z=()=>()=>({content:n.getState().loadedJsonActivityContent,binaryData:n.getState().loadedJsonActivityBinaryData}),tt=()=>()=>({content:n.getState().loadedJsonAssignmentContent,binaryData:n.getState().loadedJsonAssignmentBinaryData}),et=t=>{const e=n(o=>o.setGetTextContentFunction);c.useEffect(()=>{e(t)},[t,e])},nt=t=>{const e=n(o=>o.setGetJsonContentFunction);c.useEffect(()=>{e(t)},[t,e])},ot=t=>{const e=n(o=>o.setGetJsonActivityContentFunction);c.useEffect(()=>{e(t)},[t,e])},st=t=>{const e=n(o=>o.setGetJsonAssignmentContentFunction);c.useEffect(()=>{e(t)},[t,e])},it=t=>{const e=n(o=>o.setGetJsonActivitySplitContentFunction);c.useEffect(()=>{e(t)},[t,e])},at=t=>{const e=n(o=>o.setGetJsonAssignmentSplitContentFunction);c.useEffect(()=>{e(t)},[t,e])},ct=t=>{const e=n(o=>o.afterSaveCount);c.useEffect(()=>{e>0&&t()},[e])},rt=()=>(t,e)=>{g.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?.previewTextFile(t,e)})},ut=()=>(t,e)=>{g.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?.previewImageFile(t,e)})};let v=0,J=0;const lt=(t,e)=>{const o=c.useMemo(t,e),s=n(i=>i.setSidebarActions);c.useEffect(()=>(v++,v>1&&console.error("Capytale iframe React: Multiple sidebar actions registered: ",v),()=>{v--}),[]),c.useEffect(()=>(g.use(["meta-player-ui"],([i])=>{if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}J++;const r=o.map((a,u)=>({type:a.type,title:a.title,icon:a.icon,id:`sa-${J}-${u}`,...a.type==="file-upload"?{accept:a.accept}:{}})),l={};o.forEach((a,u)=>{l[`sa-${J}-${u}`]=a.action}),i.i?.setSidebarActionButtons(r),s(l)}),()=>{s({}),g.use(["meta-player-ui"],([i])=>{if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}i.i?.setSidebarActionButtons([])})}),[o])};let y=0,F=0;const dt=(t,e)=>{const o=c.useMemo(t,e),s=n(i=>i.setQuickActions);c.useEffect(()=>(y++,y>1&&console.error("Capytale iframe React: Multiple quick actions registered: ",y),()=>{y--}),[]),c.useEffect(()=>(g.use(["meta-player-ui"],([i])=>{if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}F++;const r=o.map((a,u)=>({type:a.type,title:a.title,icon:a.icon,id:`qa-${F}-${u}`,...a.type==="file-upload"?{accept:a.accept}:{}})),l={};o.forEach((a,u)=>{l[`qa-${F}-${u}`]=a.action}),i.i?.setQuickActionButtons(r),s(l)}),()=>{s({}),g.use(["meta-player-ui"],([i])=>{if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}i.i?.setQuickActionButtons([])})}),[o])};let m=0;const T=(t,e,o)=>{const s=c.useMemo(t,o),i=n(r=>r.setActivitySettingsCallback);c.useEffect(()=>(console.log("Mounting useSettings"),m++,m>1&&console.error("Capytale iframe React: Multiple settings registered: ",m),()=>{m--}),[]),c.useEffect(()=>(g.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)}),i(e),()=>{i(null)}),[s])},gt=()=>e=>{g.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?.showToast(e)})};function Ct(t){const e={};for(const o of t.fields)e[o.name]=o.defaultValue;return e}function St(t){return{[t.name]:t.defaultValues}}function ft(t){return{[t.name]:t.defaultValue}}function pt(t){switch(t.type){case"form":return Ct(t);case"checkboxes":case"switches":return St(t);case"radio":return ft(t);default:return{}}}function vt(t){const e={};for(const o of t)Object.assign(e,pt(o));return e}function yt(t){const o=x()(s=>({...vt(t)}));return o.activitySettings=t,o}function mt(t){T(()=>t.activitySettings,e=>{t.setState(e)},[])}function At({store:t}){return mt(t),null}const Jt=["meta-player-events:1","mode:1","workflow:1"];function Ft({children:t,contracts:e,loadOnlyWhenReady:o=!0,activitySettingsStore:s}){const i=n(r=>r.ready);return c.useEffect(()=>{const r=[...e];for(const l of Jt)r.includes(l)||r.push(l);$(r)},[]),o&&!i?p.jsx("div",{className:"capy-loading-container",children:"Chargement en cours..."}):p.jsxs(p.Fragment,{children:[s&&p.jsx(At,{store:s}),t]})}exports.Capytale=Ft;exports.createActivitySettingsStore=yt;exports.useAfterSaveAction=ct;exports.useGetLoadedJsonActivityContent=X;exports.useGetLoadedJsonActivitySplitContent=Z;exports.useGetLoadedJsonAssignmentContent=Y;exports.useGetLoadedJsonAssignmentSplitContent=tt;exports.useGetLoadedJsonContent=K;exports.useGetLoadedTextContent=z;exports.useJsonActivityContentSaveFunction=ot;exports.useJsonActivitySplitContentSaveFunction=it;exports.useJsonAssignmentContentSaveFunction=st;exports.useJsonAssignmentSplitContentSaveFunction=at;exports.useJsonContentSaveFunction=nt;exports.useLoadedJsonActivityBinaryData=U;exports.useLoadedJsonActivityContent=N;exports.useLoadedJsonAssignmentBinaryData=_;exports.useLoadedJsonAssignmentContent=H;exports.useLoadedJsonContent=V;exports.useLoadedTextContent=Q;exports.useMode=B;exports.useNotifyIsDirty=W;exports.usePreviewImageFile=ut;exports.usePreviewTextFile=rt;exports.useQuickActions=dt;exports.useRequestSave=O;exports.useSettings=T;exports.useShowToast=gt;exports.useSidebarActions=lt;exports.useTextContentSaveFunction=et;exports.useTheme=R;exports.useWorkflow=P;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),a=require("react"),L=require("@capytale/app-agent"),b=t=>{let e;const o=new Set,s=(C,S)=>{const d=typeof C=="function"?C(e):C;if(!Object.is(d,e)){const A=e;e=S??(typeof d!="object"||d===null)?d:Object.assign({},e,d),o.forEach(f=>f(e,A))}},i=()=>e,c={setState:s,getState:i,getInitialState:()=>u,subscribe:C=>(o.add(C),()=>o.delete(C))},u=e=t(s,i,c);return c},G=t=>t?b(t):b,D=t=>t;function M(t,e=D){const o=a.useSyncExternalStore(t.subscribe,a.useCallback(()=>e(t.getState()),[t,e]),a.useCallback(()=>e(t.getInitialState()),[t,e]));return a.useDebugValue(o),o}const w=t=>{const e=G(t),o=s=>M(e,s);return Object.assign(o,e),o},x=t=>t?w(t):w,j=t=>(e,o,s)=>{const i=s.subscribe;return s.subscribe=(l,c,u)=>{let C=l;if(c){const S=u?.equalityFn||Object.is;let d=l(s.getState());C=A=>{const f=l(A);if(!S(d,f)){const E=d;c(d=f,E)}},u?.fireImmediately&&c(d,d)}return i(C)},t(e,o,s)},I=j,n=x()(I(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 h=!1;const q=["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=>{n.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){n.setState({theme:null});return}if(t!=="light"&&t!=="dark"){console.warn(`Invalid theme: ${t}. Expected 'light' or 'dark'.`),n.setState({theme:null});return}n.setState({theme:t})}},"workflow:1":{setWorkflow:t=>{n.setState({workflow:t})}},"simple-content(text):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getTextContentFunction(),loadContent:t=>{n.setState({loadedTextContent:t})}},"simple-content(json):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getJsonContentFunction(),loadContent:t=>{n.setState({loadedJsonContent:t})}},"simple-binary-data(text):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getTextContentFunction(),loadContent:t=>{n.setState({loadedTextContent:t})}},"simple-content-eval(text):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getTextContentFunction(),loadContent:t=>{n.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getJsonContentFunction(),loadContent:t=>{n.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(json):2":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getJsonContentFunction(),loadContent:t=>{n.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(text):2":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>n.getState().getTextContentFunction(),loadContent:t=>{n.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"separate-contents(json):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:(t,e)=>{n.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e})},getActivityContent:()=>n.getState().getJsonActivityContentFunction(),getAssignmentContent:()=>n.getState().getJsonAssignmentContentFunction()},"separate-dual-contents(json):1":{contentSaved:()=>{n.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},loadContent:({activityContent:t,assignmentContent:e,activityBinaryData:o,assignmentBinaryData:s})=>{n.setState({loadedJsonActivityContent:t,loadedJsonAssignmentContent:e,loadedJsonActivityBinaryData:o,loadedJsonAssignmentBinaryData:s})},getActivityContentAndData:()=>n.getState().getJsonActivitySplitContentFunction(),getAssignmentContentAndData:()=>n.getState().getJsonAssignmentSplitContentFunction()},"meta-player-anti-cheat:1":{lock:()=>{},unlock:()=>{}},"meta-player-ui:1":{executeAction(t){if(t.startsWith("qa")){const o=n.getState().quickActions[t];o?o():console.error(`Quick action not found: ${t}`)}else{const o=n.getState().sidebarActions[t];o?o():console.error(`Sidebar action not found: ${t}`)}},executeFileUpload(t,e){if(t.startsWith("qa")){const s=n.getState().quickActions[t];s?s(e):console.error(`Quick action not found: ${t}`)}else{const s=n.getState().sidebarActions[t];s?s(e):console.error(`Sidebar action not found: ${t}`)}},updateSettings(t){const e=n.getState().activitySettingsCallback;e?e(t):console.warn("activitySettingsCallback is not set. Changes:",t)}},"meta-player-events:1":{handleEvent(t){t==="all-loaded"&&n.setState({ready:!0})}}},g=L.getSocket();function $(t){if(h){console.warn("Contracts have already been plugged. Skipping.");return}h=!0;for(const e of t){if(!q.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 o=k[e];g.plug([e],([])=>[o])}g.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 o=e.split(":")[0];g.use([o],([s])=>{n.subscribe(i=>i.isDirtyCount,()=>{s.i?.contentChanged(),console.log(`Content changed for contract ${o}`)})})}}const B=()=>n(t=>{if(t.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return t.mode}),P=()=>n(t=>{if(t.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return t.workflow}),R=()=>n(t=>{if(t.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return t.theme}),O=()=>n(t=>t.incSaveCount),W=()=>n(t=>t.incDirtyCount),Q=()=>n(t=>t.loadedTextContent),V=()=>n(t=>t.loadedJsonContent),N=()=>n(t=>t.loadedJsonActivityContent),U=()=>n(t=>t.loadedJsonAssignmentContent),H=()=>n(t=>t.loadedJsonActivityBinaryData),_=()=>n(t=>t.loadedJsonAssignmentBinaryData),z=()=>a.useCallback(()=>n.getState().loadedTextContent,[]),K=()=>a.useCallback(()=>n.getState().loadedJsonContent,[]),X=()=>a.useCallback(()=>n.getState().loadedJsonActivityContent,[]),Y=()=>a.useCallback(()=>n.getState().loadedJsonAssignmentContent,[]),Z=()=>a.useCallback(()=>({content:n.getState().loadedJsonActivityContent,binaryData:n.getState().loadedJsonActivityBinaryData}),[]),tt=()=>a.useCallback(()=>({content:n.getState().loadedJsonAssignmentContent,binaryData:n.getState().loadedJsonAssignmentBinaryData}),[]),et=t=>{const e=n(o=>o.setGetTextContentFunction);a.useEffect(()=>{e(t)},[t,e])},nt=t=>{const e=n(o=>o.setGetJsonContentFunction);a.useEffect(()=>{e(t)},[t,e])},ot=t=>{const e=n(o=>o.setGetJsonActivityContentFunction);a.useEffect(()=>{e(t)},[t,e])},st=t=>{const e=n(o=>o.setGetJsonAssignmentContentFunction);a.useEffect(()=>{e(t)},[t,e])},it=t=>{const e=n(o=>o.setGetJsonActivitySplitContentFunction);a.useEffect(()=>{e(t)},[t,e])},at=t=>{const e=n(o=>o.setGetJsonAssignmentSplitContentFunction);a.useEffect(()=>{e(t)},[t,e])},ct=t=>{const e=n(o=>o.afterSaveCount);a.useEffect(()=>{e>0&&t()},[e])},rt=()=>(t,e)=>{g.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?.previewTextFile(t,e)})},ut=()=>(t,e)=>{g.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?.previewImageFile(t,e)})};let v=0,J=0;const lt=(t,e)=>{const o=a.useMemo(t,e),s=n(i=>i.setSidebarActions);a.useEffect(()=>(v++,v>1&&console.error("Capytale iframe React: Multiple sidebar actions registered: ",v),()=>{v--}),[]),a.useEffect(()=>(g.use(["meta-player-ui"],([i])=>{if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}J++;const r=o.map((c,u)=>({type:c.type,title:c.title,icon:c.icon,id:`sa-${J}-${u}`,...c.type==="file-upload"?{accept:c.accept}:{}})),l={};o.forEach((c,u)=>{l[`sa-${J}-${u}`]=c.action}),i.i?.setSidebarActionButtons(r),s(l)}),()=>{s({}),g.use(["meta-player-ui"],([i])=>{if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}i.i?.setSidebarActionButtons([])})}),[o])};let y=0,F=0;const dt=(t,e)=>{const o=a.useMemo(t,e),s=n(i=>i.setQuickActions);a.useEffect(()=>(y++,y>1&&console.error("Capytale iframe React: Multiple quick actions registered: ",y),()=>{y--}),[]),a.useEffect(()=>(g.use(["meta-player-ui"],([i])=>{if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}F++;const r=o.map((c,u)=>({type:c.type,title:c.title,icon:c.icon,id:`qa-${F}-${u}`,...c.type==="file-upload"?{accept:c.accept}:{}})),l={};o.forEach((c,u)=>{l[`qa-${F}-${u}`]=c.action}),i.i?.setQuickActionButtons(r),s(l)}),()=>{s({}),g.use(["meta-player-ui"],([i])=>{if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}i.i?.setQuickActionButtons([])})}),[o])};let m=0;const T=(t,e,o)=>{const s=a.useMemo(t,o),i=n(r=>r.setActivitySettingsCallback);a.useEffect(()=>(console.log("Mounting useSettings"),m++,m>1&&console.error("Capytale iframe React: Multiple settings registered: ",m),()=>{console.log("Unmounting useSettings"),m--}),[]),a.useEffect(()=>(g.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)}),i(e),()=>{i(null)}),[s])},gt=()=>e=>{g.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?.showToast(e)})};function Ct(t){const e={};for(const o of t.fields)e[o.name]=o.defaultValue;return e}function St(t){return{[t.name]:t.defaultValues}}function ft(t){return{[t.name]:t.defaultValue}}function pt(t){switch(t.type){case"form":return Ct(t);case"checkboxes":case"switches":return St(t);case"radio":return ft(t);default:return{}}}function vt(t){const e={};for(const o of t)Object.assign(e,pt(o));return e}function yt(t){const o=x()(s=>({...vt(t)}));return o.activitySettings=t,o}function mt(t){T(()=>t.activitySettings,e=>{t.setState(e)},[])}function At({store:t}){return mt(t),null}const Jt=["meta-player-events:1","mode:1","workflow:1"];function Ft({children:t,contracts:e,loadOnlyWhenReady:o=!0,activitySettingsStore:s}){const i=n(r=>r.ready);return a.useEffect(()=>{const r=[...e];for(const l of Jt)r.includes(l)||r.push(l);$(r)},[]),o&&!i?p.jsx("div",{className:"capy-loading-container",children:"Chargement en cours..."}):p.jsxs(p.Fragment,{children:[s&&p.jsx(At,{store:s}),t]})}exports.Capytale=Ft;exports.createActivitySettingsStore=yt;exports.useAfterSaveAction=ct;exports.useGetLoadedJsonActivityContent=X;exports.useGetLoadedJsonActivitySplitContent=Z;exports.useGetLoadedJsonAssignmentContent=Y;exports.useGetLoadedJsonAssignmentSplitContent=tt;exports.useGetLoadedJsonContent=K;exports.useGetLoadedTextContent=z;exports.useJsonActivityContentSaveFunction=ot;exports.useJsonActivitySplitContentSaveFunction=it;exports.useJsonAssignmentContentSaveFunction=st;exports.useJsonAssignmentSplitContentSaveFunction=at;exports.useJsonContentSaveFunction=nt;exports.useLoadedJsonActivityBinaryData=H;exports.useLoadedJsonActivityContent=N;exports.useLoadedJsonAssignmentBinaryData=_;exports.useLoadedJsonAssignmentContent=U;exports.useLoadedJsonContent=V;exports.useLoadedTextContent=Q;exports.useMode=B;exports.useNotifyIsDirty=W;exports.usePreviewImageFile=ut;exports.usePreviewTextFile=rt;exports.useQuickActions=dt;exports.useRequestSave=O;exports.useSettings=T;exports.useShowToast=gt;exports.useSidebarActions=lt;exports.useTextContentSaveFunction=et;exports.useTheme=R;exports.useWorkflow=P;
|
package/dist/index.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ declare type ActivitySettingsRange = {
|
|
|
70
70
|
|
|
71
71
|
declare type ActivitySettingsSection = (ActivitySettingsMultipleOptionsSection | ActivitySettingsRadioOptionsSection | ActivitySettingsFormSection) & {
|
|
72
72
|
title: string;
|
|
73
|
+
modes?: ("assignment" | "create" | "review" | "view")[];
|
|
73
74
|
};
|
|
74
75
|
|
|
75
76
|
declare type ActivitySettingsSelect = {
|
|
@@ -320,7 +321,7 @@ export declare const useQuickActions: (actionsFn: () => Action[], deps: readonly
|
|
|
320
321
|
|
|
321
322
|
export declare const useRequestSave: () => () => void;
|
|
322
323
|
|
|
323
|
-
export declare const useSettings: <T extends ActivitySettings>(settingsUiFn: () =>
|
|
324
|
+
export declare const useSettings: <T extends ActivitySettings>(settingsUiFn: () => T | null, callback: (changes: Partial<InferValue<T>>) => void, deps: readonly unknown[]) => void;
|
|
324
325
|
|
|
325
326
|
export declare const useShowToast: () => (message: MPToastMessage) => void;
|
|
326
327
|
|
package/dist/index.es.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { getSocket as
|
|
4
|
-
const
|
|
1
|
+
import { jsx as h, jsxs as j, Fragment as M } from "react/jsx-runtime";
|
|
2
|
+
import v, { useCallback as S, useEffect as l, useMemo as w } from "react";
|
|
3
|
+
import { getSocket as I } from "@capytale/app-agent";
|
|
4
|
+
const k = (t) => {
|
|
5
5
|
let e;
|
|
6
|
-
const o = /* @__PURE__ */ new Set(), s = (C,
|
|
6
|
+
const o = /* @__PURE__ */ new Set(), s = (C, p) => {
|
|
7
7
|
const d = typeof C == "function" ? C(e) : C;
|
|
8
8
|
if (!Object.is(d, e)) {
|
|
9
|
-
const
|
|
10
|
-
e =
|
|
9
|
+
const J = e;
|
|
10
|
+
e = p ?? (typeof d != "object" || d === null) ? d : Object.assign({}, e, d), o.forEach((m) => m(e, J));
|
|
11
11
|
}
|
|
12
12
|
}, i = () => e, a = { setState: s, getState: i, getInitialState: () => r, subscribe: (C) => (o.add(C), () => o.delete(C)) }, r = e = t(s, i, a);
|
|
13
13
|
return a;
|
|
14
|
-
},
|
|
15
|
-
function
|
|
16
|
-
const o =
|
|
14
|
+
}, L = (t) => t ? k(t) : k, $ = (t) => t;
|
|
15
|
+
function q(t, e = $) {
|
|
16
|
+
const o = v.useSyncExternalStore(
|
|
17
17
|
t.subscribe,
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
v.useCallback(() => e(t.getState()), [t, e]),
|
|
19
|
+
v.useCallback(() => e(t.getInitialState()), [t, e])
|
|
20
20
|
);
|
|
21
|
-
return
|
|
21
|
+
return v.useDebugValue(o), o;
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
const e =
|
|
23
|
+
const x = (t) => {
|
|
24
|
+
const e = L(t), o = (s) => q(e, s);
|
|
25
25
|
return Object.assign(o, e), o;
|
|
26
|
-
},
|
|
26
|
+
}, E = (t) => t ? x(t) : x, B = (t) => (e, o, s) => {
|
|
27
27
|
const i = s.subscribe;
|
|
28
28
|
return s.subscribe = (u, a, r) => {
|
|
29
29
|
let C = u;
|
|
30
30
|
if (a) {
|
|
31
|
-
const
|
|
31
|
+
const p = r?.equalityFn || Object.is;
|
|
32
32
|
let d = u(s.getState());
|
|
33
|
-
C = (
|
|
34
|
-
const
|
|
35
|
-
if (!
|
|
36
|
-
const
|
|
37
|
-
a(d =
|
|
33
|
+
C = (J) => {
|
|
34
|
+
const m = u(J);
|
|
35
|
+
if (!p(d, m)) {
|
|
36
|
+
const G = d;
|
|
37
|
+
a(d = m, G);
|
|
38
38
|
}
|
|
39
39
|
}, r?.fireImmediately && a(d, d);
|
|
40
40
|
}
|
|
41
41
|
return i(C);
|
|
42
42
|
}, t(e, o, s);
|
|
43
|
-
},
|
|
44
|
-
|
|
43
|
+
}, P = B, n = E()(
|
|
44
|
+
P((t) => ({
|
|
45
45
|
ready: !1,
|
|
46
46
|
workflow: "current",
|
|
47
47
|
mode: "assignment",
|
|
@@ -109,8 +109,8 @@ const k = (t) => {
|
|
|
109
109
|
incDirtyCount: () => t((e) => ({ isDirtyCount: e.isDirtyCount + 1 }))
|
|
110
110
|
}))
|
|
111
111
|
);
|
|
112
|
-
let
|
|
113
|
-
const
|
|
112
|
+
let T = !1;
|
|
113
|
+
const R = [
|
|
114
114
|
"meta-player-events:1",
|
|
115
115
|
"meta-player-ui:1",
|
|
116
116
|
"mode:1",
|
|
@@ -124,7 +124,7 @@ const P = [
|
|
|
124
124
|
"simple-content-eval(json):1",
|
|
125
125
|
"separate-contents(json):1",
|
|
126
126
|
"separate-dual-contents(json):1"
|
|
127
|
-
],
|
|
127
|
+
], D = {
|
|
128
128
|
"mode:1": {
|
|
129
129
|
setMode: (t) => {
|
|
130
130
|
n.setState({ mode: t });
|
|
@@ -325,27 +325,27 @@ const P = [
|
|
|
325
325
|
t === "all-loaded" && n.setState({ ready: !0 });
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
|
-
}, g =
|
|
329
|
-
function
|
|
330
|
-
if (
|
|
328
|
+
}, g = I();
|
|
329
|
+
function O(t) {
|
|
330
|
+
if (T) {
|
|
331
331
|
console.warn("Contracts have already been plugged. Skipping.");
|
|
332
332
|
return;
|
|
333
333
|
}
|
|
334
|
-
|
|
334
|
+
T = !0;
|
|
335
335
|
for (const e of t) {
|
|
336
|
-
if (!
|
|
336
|
+
if (!R.includes(e)) {
|
|
337
337
|
console.warn(
|
|
338
338
|
`Contract ${e} is not implemented in Capytale. Skipping plug.`
|
|
339
339
|
);
|
|
340
340
|
continue;
|
|
341
341
|
}
|
|
342
|
-
if (!(e in
|
|
342
|
+
if (!(e in D)) {
|
|
343
343
|
console.warn(
|
|
344
344
|
`Contract handler for ${e} is not defined. Skipping plug.`
|
|
345
345
|
);
|
|
346
346
|
continue;
|
|
347
347
|
}
|
|
348
|
-
const o =
|
|
348
|
+
const o = D[e];
|
|
349
349
|
g.plug([e], ([]) => [o]);
|
|
350
350
|
}
|
|
351
351
|
g.plugsDone();
|
|
@@ -373,194 +373,231 @@ function R(t) {
|
|
|
373
373
|
});
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
|
-
const
|
|
376
|
+
const tt = () => n((t) => {
|
|
377
377
|
if (t.mode === null)
|
|
378
378
|
throw new Error("Mode is not set. Have you used contract 'mode'?");
|
|
379
379
|
return t.mode;
|
|
380
|
-
}),
|
|
380
|
+
}), et = () => n((t) => {
|
|
381
381
|
if (t.workflow === null)
|
|
382
|
-
throw new Error(
|
|
382
|
+
throw new Error(
|
|
383
|
+
"Workflow is not set. Have you used contract 'workflow'?"
|
|
384
|
+
);
|
|
383
385
|
return t.workflow;
|
|
384
|
-
}),
|
|
386
|
+
}), nt = () => n((t) => {
|
|
385
387
|
if (t.theme === null)
|
|
386
388
|
throw new Error("Theme is not set. Have you used contract 'theme'?");
|
|
387
389
|
return t.theme;
|
|
388
|
-
}),
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
390
|
+
}), ot = () => n((t) => t.incSaveCount), st = () => n((t) => t.incDirtyCount), it = () => n((t) => t.loadedTextContent), at = () => n((t) => t.loadedJsonContent), ct = () => n((t) => t.loadedJsonActivityContent), rt = () => n((t) => t.loadedJsonAssignmentContent), lt = () => n((t) => t.loadedJsonActivityBinaryData), ut = () => n((t) => t.loadedJsonAssignmentBinaryData), dt = () => S(() => n.getState().loadedTextContent, []), gt = () => S(() => n.getState().loadedJsonContent, []), Ct = () => S(() => n.getState().loadedJsonActivityContent, []), St = () => S(() => n.getState().loadedJsonAssignmentContent, []), pt = () => S(
|
|
391
|
+
() => ({
|
|
392
|
+
content: n.getState().loadedJsonActivityContent,
|
|
393
|
+
binaryData: n.getState().loadedJsonActivityBinaryData
|
|
394
|
+
}),
|
|
395
|
+
[]
|
|
396
|
+
), mt = () => S(
|
|
397
|
+
() => ({
|
|
398
|
+
content: n.getState().loadedJsonAssignmentContent,
|
|
399
|
+
binaryData: n.getState().loadedJsonAssignmentBinaryData
|
|
400
|
+
}),
|
|
401
|
+
[]
|
|
402
|
+
), vt = (t) => {
|
|
395
403
|
const e = n(
|
|
396
404
|
(o) => o.setGetTextContentFunction
|
|
397
405
|
);
|
|
398
406
|
l(() => {
|
|
399
407
|
e(t);
|
|
400
408
|
}, [t, e]);
|
|
401
|
-
},
|
|
409
|
+
}, yt = (t) => {
|
|
402
410
|
const e = n(
|
|
403
411
|
(o) => o.setGetJsonContentFunction
|
|
404
412
|
);
|
|
405
413
|
l(() => {
|
|
406
414
|
e(t);
|
|
407
415
|
}, [t, e]);
|
|
408
|
-
},
|
|
416
|
+
}, ft = (t) => {
|
|
409
417
|
const e = n(
|
|
410
418
|
(o) => o.setGetJsonActivityContentFunction
|
|
411
419
|
);
|
|
412
420
|
l(() => {
|
|
413
421
|
e(t);
|
|
414
422
|
}, [t, e]);
|
|
415
|
-
},
|
|
423
|
+
}, At = (t) => {
|
|
416
424
|
const e = n(
|
|
417
425
|
(o) => o.setGetJsonAssignmentContentFunction
|
|
418
426
|
);
|
|
419
427
|
l(() => {
|
|
420
428
|
e(t);
|
|
421
429
|
}, [t, e]);
|
|
422
|
-
},
|
|
430
|
+
}, Jt = (t) => {
|
|
423
431
|
const e = n(
|
|
424
432
|
(o) => o.setGetJsonActivitySplitContentFunction
|
|
425
433
|
);
|
|
426
434
|
l(() => {
|
|
427
435
|
e(t);
|
|
428
436
|
}, [t, e]);
|
|
429
|
-
},
|
|
437
|
+
}, Ft = (t) => {
|
|
430
438
|
const e = n(
|
|
431
439
|
(o) => o.setGetJsonAssignmentSplitContentFunction
|
|
432
440
|
);
|
|
433
441
|
l(() => {
|
|
434
442
|
e(t);
|
|
435
443
|
}, [t, e]);
|
|
436
|
-
},
|
|
444
|
+
}, bt = (t) => {
|
|
437
445
|
const e = n((o) => o.afterSaveCount);
|
|
438
446
|
l(() => {
|
|
439
447
|
e > 0 && t();
|
|
440
448
|
}, [e]);
|
|
441
|
-
},
|
|
449
|
+
}, wt = () => (t, e) => {
|
|
442
450
|
g.use(["meta-player-ui"], ([o]) => {
|
|
443
451
|
if (o.version === 0) {
|
|
444
|
-
console.error(
|
|
452
|
+
console.error(
|
|
453
|
+
"Le MétaPlayer ne supporte pas le contrat meta-player-ui"
|
|
454
|
+
);
|
|
445
455
|
return;
|
|
446
456
|
}
|
|
447
457
|
o.i?.previewTextFile(t, e);
|
|
448
458
|
});
|
|
449
|
-
},
|
|
459
|
+
}, ht = () => (t, e) => {
|
|
450
460
|
g.use(["meta-player-ui"], ([o]) => {
|
|
451
461
|
if (o.version === 0) {
|
|
452
|
-
console.error(
|
|
462
|
+
console.error(
|
|
463
|
+
"Le MétaPlayer ne supporte pas le contrat meta-player-ui"
|
|
464
|
+
);
|
|
453
465
|
return;
|
|
454
466
|
}
|
|
455
467
|
o.i?.previewImageFile(t, e);
|
|
456
468
|
});
|
|
457
469
|
};
|
|
458
|
-
let
|
|
459
|
-
const
|
|
460
|
-
const o =
|
|
461
|
-
l(() => (
|
|
462
|
-
|
|
470
|
+
let y = 0, F = 0;
|
|
471
|
+
const kt = (t, e) => {
|
|
472
|
+
const o = w(t, e), s = n((i) => i.setSidebarActions);
|
|
473
|
+
l(() => (y++, y > 1 && console.error(
|
|
474
|
+
"Capytale iframe React: Multiple sidebar actions registered: ",
|
|
475
|
+
y
|
|
476
|
+
), () => {
|
|
477
|
+
y--;
|
|
463
478
|
}), []), l(() => (g.use(["meta-player-ui"], ([i]) => {
|
|
464
479
|
if (i.version === 0) {
|
|
465
|
-
console.error(
|
|
480
|
+
console.error(
|
|
481
|
+
"Le MétaPlayer ne supporte pas le contrat meta-player-ui"
|
|
482
|
+
);
|
|
466
483
|
return;
|
|
467
484
|
}
|
|
468
|
-
|
|
485
|
+
F++;
|
|
469
486
|
const c = o.map((a, r) => ({
|
|
470
487
|
type: a.type,
|
|
471
488
|
title: a.title,
|
|
472
489
|
icon: a.icon,
|
|
473
|
-
id: `sa-${
|
|
490
|
+
id: `sa-${F}-${r}`,
|
|
474
491
|
...a.type === "file-upload" ? { accept: a.accept } : {}
|
|
475
492
|
})), u = {};
|
|
476
493
|
o.forEach((a, r) => {
|
|
477
|
-
u[`sa-${
|
|
494
|
+
u[`sa-${F}-${r}`] = a.action;
|
|
478
495
|
}), i.i?.setSidebarActionButtons(c), s(u);
|
|
479
496
|
}), () => {
|
|
480
497
|
s({}), g.use(["meta-player-ui"], ([i]) => {
|
|
481
498
|
if (i.version === 0) {
|
|
482
|
-
console.error(
|
|
499
|
+
console.error(
|
|
500
|
+
"Le MétaPlayer ne supporte pas le contrat meta-player-ui"
|
|
501
|
+
);
|
|
483
502
|
return;
|
|
484
503
|
}
|
|
485
504
|
i.i?.setSidebarActionButtons([]);
|
|
486
505
|
});
|
|
487
506
|
}), [o]);
|
|
488
507
|
};
|
|
489
|
-
let
|
|
490
|
-
const
|
|
491
|
-
const o =
|
|
492
|
-
l(() => (
|
|
493
|
-
|
|
508
|
+
let f = 0, b = 0;
|
|
509
|
+
const xt = (t, e) => {
|
|
510
|
+
const o = w(t, e), s = n((i) => i.setQuickActions);
|
|
511
|
+
l(() => (f++, f > 1 && console.error(
|
|
512
|
+
"Capytale iframe React: Multiple quick actions registered: ",
|
|
513
|
+
f
|
|
514
|
+
), () => {
|
|
515
|
+
f--;
|
|
494
516
|
}), []), l(() => (g.use(["meta-player-ui"], ([i]) => {
|
|
495
517
|
if (i.version === 0) {
|
|
496
|
-
console.error(
|
|
518
|
+
console.error(
|
|
519
|
+
"Le MétaPlayer ne supporte pas le contrat meta-player-ui"
|
|
520
|
+
);
|
|
497
521
|
return;
|
|
498
522
|
}
|
|
499
|
-
|
|
523
|
+
b++;
|
|
500
524
|
const c = o.map((a, r) => ({
|
|
501
525
|
type: a.type,
|
|
502
526
|
title: a.title,
|
|
503
527
|
icon: a.icon,
|
|
504
|
-
id: `qa-${
|
|
528
|
+
id: `qa-${b}-${r}`,
|
|
505
529
|
...a.type === "file-upload" ? { accept: a.accept } : {}
|
|
506
530
|
})), u = {};
|
|
507
531
|
o.forEach((a, r) => {
|
|
508
|
-
u[`qa-${
|
|
532
|
+
u[`qa-${b}-${r}`] = a.action;
|
|
509
533
|
}), i.i?.setQuickActionButtons(c), s(u);
|
|
510
534
|
}), () => {
|
|
511
535
|
s({}), g.use(["meta-player-ui"], ([i]) => {
|
|
512
536
|
if (i.version === 0) {
|
|
513
|
-
console.error(
|
|
537
|
+
console.error(
|
|
538
|
+
"Le MétaPlayer ne supporte pas le contrat meta-player-ui"
|
|
539
|
+
);
|
|
514
540
|
return;
|
|
515
541
|
}
|
|
516
542
|
i.i?.setQuickActionButtons([]);
|
|
517
543
|
});
|
|
518
544
|
}), [o]);
|
|
519
545
|
};
|
|
520
|
-
let
|
|
521
|
-
const
|
|
522
|
-
const s =
|
|
523
|
-
|
|
524
|
-
|
|
546
|
+
let A = 0;
|
|
547
|
+
const V = (t, e, o) => {
|
|
548
|
+
const s = w(t, o), i = n(
|
|
549
|
+
(c) => c.setActivitySettingsCallback
|
|
550
|
+
);
|
|
551
|
+
l(() => (console.log("Mounting useSettings"), A++, A > 1 && console.error(
|
|
552
|
+
"Capytale iframe React: Multiple settings registered: ",
|
|
553
|
+
A
|
|
554
|
+
), () => {
|
|
555
|
+
console.log("Unmounting useSettings"), A--;
|
|
525
556
|
}), []), l(() => (g.use(["meta-player-ui"], ([c]) => {
|
|
526
557
|
if (c.version === 0) {
|
|
527
|
-
console.error(
|
|
558
|
+
console.error(
|
|
559
|
+
"Le MétaPlayer ne supporte pas le contrat meta-player-ui"
|
|
560
|
+
);
|
|
528
561
|
return;
|
|
529
562
|
}
|
|
530
563
|
console.log("Updating settings UI in MetaPlayer", s), c.i?.setSettingsUI(s);
|
|
531
|
-
}), i(
|
|
564
|
+
}), i(
|
|
565
|
+
e
|
|
566
|
+
), () => {
|
|
532
567
|
i(null);
|
|
533
568
|
}), [s]);
|
|
534
|
-
},
|
|
569
|
+
}, Tt = () => (e) => {
|
|
535
570
|
g.use(["meta-player-ui"], ([o]) => {
|
|
536
571
|
if (o.version === 0) {
|
|
537
|
-
console.error(
|
|
572
|
+
console.error(
|
|
573
|
+
"Le MétaPlayer ne supporte pas le contrat meta-player-ui"
|
|
574
|
+
);
|
|
538
575
|
return;
|
|
539
576
|
}
|
|
540
577
|
o.i?.showToast(e);
|
|
541
578
|
});
|
|
542
579
|
};
|
|
543
|
-
function
|
|
580
|
+
function W(t) {
|
|
544
581
|
const e = {};
|
|
545
582
|
for (const o of t.fields)
|
|
546
583
|
e[o.name] = o.defaultValue;
|
|
547
584
|
return e;
|
|
548
585
|
}
|
|
549
|
-
function
|
|
586
|
+
function Q(t) {
|
|
550
587
|
return { [t.name]: t.defaultValues };
|
|
551
588
|
}
|
|
552
|
-
function
|
|
589
|
+
function U(t) {
|
|
553
590
|
return { [t.name]: t.defaultValue };
|
|
554
591
|
}
|
|
555
592
|
function H(t) {
|
|
556
593
|
switch (t.type) {
|
|
557
594
|
case "form":
|
|
558
|
-
return
|
|
595
|
+
return W(t);
|
|
559
596
|
case "checkboxes":
|
|
560
597
|
case "switches":
|
|
561
|
-
return W(t);
|
|
562
|
-
case "radio":
|
|
563
598
|
return Q(t);
|
|
599
|
+
case "radio":
|
|
600
|
+
return U(t);
|
|
564
601
|
default:
|
|
565
602
|
return {};
|
|
566
603
|
}
|
|
@@ -571,14 +608,14 @@ function N(t) {
|
|
|
571
608
|
Object.assign(e, H(o));
|
|
572
609
|
return e;
|
|
573
610
|
}
|
|
574
|
-
function
|
|
575
|
-
const o =
|
|
611
|
+
function Dt(t) {
|
|
612
|
+
const o = E()((s) => ({
|
|
576
613
|
...N(t)
|
|
577
614
|
}));
|
|
578
615
|
return o.activitySettings = t, o;
|
|
579
616
|
}
|
|
580
|
-
function
|
|
581
|
-
|
|
617
|
+
function _(t) {
|
|
618
|
+
V(
|
|
582
619
|
() => t.activitySettings,
|
|
583
620
|
(e) => {
|
|
584
621
|
t.setState(e);
|
|
@@ -586,17 +623,17 @@ function U(t) {
|
|
|
586
623
|
[]
|
|
587
624
|
);
|
|
588
625
|
}
|
|
589
|
-
function
|
|
626
|
+
function z({
|
|
590
627
|
store: t
|
|
591
628
|
}) {
|
|
592
|
-
return
|
|
629
|
+
return _(t), null;
|
|
593
630
|
}
|
|
594
|
-
const
|
|
631
|
+
const K = [
|
|
595
632
|
"meta-player-events:1",
|
|
596
633
|
"mode:1",
|
|
597
634
|
"workflow:1"
|
|
598
635
|
];
|
|
599
|
-
function
|
|
636
|
+
function Et({
|
|
600
637
|
children: t,
|
|
601
638
|
contracts: e,
|
|
602
639
|
loadOnlyWhenReady: o = !0,
|
|
@@ -605,45 +642,45 @@ function Dt({
|
|
|
605
642
|
const i = n((c) => c.ready);
|
|
606
643
|
return l(() => {
|
|
607
644
|
const c = [...e];
|
|
608
|
-
for (const u of
|
|
645
|
+
for (const u of K)
|
|
609
646
|
c.includes(u) || c.push(u);
|
|
610
|
-
|
|
611
|
-
}, []), o && !i ? /* @__PURE__ */
|
|
612
|
-
s && /* @__PURE__ */
|
|
647
|
+
O(c);
|
|
648
|
+
}, []), o && !i ? /* @__PURE__ */ h("div", { className: "capy-loading-container", children: "Chargement en cours..." }) : /* @__PURE__ */ j(M, { children: [
|
|
649
|
+
s && /* @__PURE__ */ h(z, { store: s }),
|
|
613
650
|
t
|
|
614
651
|
] });
|
|
615
652
|
}
|
|
616
653
|
export {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
654
|
+
Et as Capytale,
|
|
655
|
+
Dt as createActivitySettingsStore,
|
|
656
|
+
bt as useAfterSaveAction,
|
|
657
|
+
Ct as useGetLoadedJsonActivityContent,
|
|
658
|
+
pt as useGetLoadedJsonActivitySplitContent,
|
|
659
|
+
St as useGetLoadedJsonAssignmentContent,
|
|
660
|
+
mt as useGetLoadedJsonAssignmentSplitContent,
|
|
661
|
+
gt as useGetLoadedJsonContent,
|
|
662
|
+
dt as useGetLoadedTextContent,
|
|
663
|
+
ft as useJsonActivityContentSaveFunction,
|
|
664
|
+
Jt as useJsonActivitySplitContentSaveFunction,
|
|
665
|
+
At as useJsonAssignmentContentSaveFunction,
|
|
666
|
+
Ft as useJsonAssignmentSplitContentSaveFunction,
|
|
667
|
+
yt as useJsonContentSaveFunction,
|
|
668
|
+
lt as useLoadedJsonActivityBinaryData,
|
|
669
|
+
ct as useLoadedJsonActivityContent,
|
|
670
|
+
ut as useLoadedJsonAssignmentBinaryData,
|
|
671
|
+
rt as useLoadedJsonAssignmentContent,
|
|
672
|
+
at as useLoadedJsonContent,
|
|
673
|
+
it as useLoadedTextContent,
|
|
674
|
+
tt as useMode,
|
|
675
|
+
st as useNotifyIsDirty,
|
|
676
|
+
ht as usePreviewImageFile,
|
|
677
|
+
wt as usePreviewTextFile,
|
|
678
|
+
xt as useQuickActions,
|
|
679
|
+
ot as useRequestSave,
|
|
680
|
+
V as useSettings,
|
|
681
|
+
Tt as useShowToast,
|
|
682
|
+
kt as useSidebarActions,
|
|
683
|
+
vt as useTextContentSaveFunction,
|
|
684
|
+
nt as useTheme,
|
|
685
|
+
et as useWorkflow
|
|
649
686
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capytale/iframe-react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@capytale/app-agent": "^1.0.12",
|
|
30
30
|
"@capytale/contracts": "^1.1.0",
|
|
31
|
-
"zustand": "^5.0.
|
|
31
|
+
"zustand": "^5.0.9"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"react": ">=17.0.0 <20",
|