@capytale/iframe-react 1.0.2 → 1.0.4
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.es.js +125 -83
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react/jsx-runtime"),u=require("react"),F=require("@capytale/app-agent"),h=t=>{let e;const n=new Set,s=(a,p)=>{const f=typeof a=="function"?a(e):a;if(!Object.is(f,e)){const v=e;e=p??(typeof f!="object"||f===null)?f:Object.assign({},e,f),n.forEach(g=>g(e,v))}},i=()=>e,l={setState:s,getState:i,getInitialState:()=>r,subscribe:a=>(n.add(a),()=>n.delete(a))},r=e=t(s,i,l);return l},M=t=>t?h(t):h,E=t=>t;function q(t,e=E){const n=u.useSyncExternalStore(t.subscribe,()=>e(t.getState()),()=>e(t.getInitialState()));return u.useDebugValue(n),n}const x=t=>{const e=M(t),n=s=>q(e,s);return Object.assign(n,e),n},I=t=>t?x(t):x,J=t=>(e,n,s)=>{const i=s.subscribe;return s.subscribe=(c,l,r)=>{let a=c;if(l){const p=(r==null?void 0:r.equalityFn)||Object.is;let f=c(s.getState());a=v=>{const g=c(v);if(!p(f,g)){const T=f;l(f=g,T)}},r!=null&&r.fireImmediately&&l(f,f)}return i(a)},t(e,n,s)},$=J,o=I()($(t=>({ready:!1,workflow:"current",mode:"assignment",theme:"light",saveCount:0,afterSaveCount:0,isDirtyCount:0,loadedTextContent:null,loadedJsonContent:null,getTextContentFunction:()=>(console.error("getTextContentFunction is not set"),null),getJsonContentFunction:()=>(console.error("getJsonContentFunction is not set"),null),sidebarActions:{},quickActions:{},activitySettings:null,setGetTextContentFunction:e=>{t({getTextContentFunction:e})},setGetJsonContentFunction:e=>{t({getJsonContentFunction:e})},setSidebarActions:e=>{t({sidebarActions:e})},setQuickActions:e=>{t({quickActions:e})},setActivitySettings:e=>{t({activitySettings:e})},incSaveCount:()=>t(e=>({saveCount:e.saveCount+1})),incDirtyCount:()=>t(e=>({isDirtyCount:e.isDirtyCount+1}))}))),j=["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"],k={"mode:1":{setMode:t=>{o.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){o.setState({theme:null});return}if(t!=="light"&&t!=="dark"){console.warn(`Invalid theme: ${t}. Expected 'light' or 'dark'.`),o.setState({theme:null});return}o.setState({theme:t})}},"workflow:1":{setWorkflow:t=>{o.setState({workflow:t})}},"simple-content(text):1":{contentSaved:()=>{o.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>o.getState().getTextContentFunction(),loadContent:t=>{o.setState({loadedTextContent:t})}},"simple-content(json):1":{contentSaved:()=>{o.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>o.getState().getJsonContentFunction(),loadContent:t=>{o.setState({loadedJsonContent:t})}},"simple-binary-data(text):1":{contentSaved:()=>{o.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>o.getState().getTextContentFunction(),loadContent:t=>{o.setState({loadedTextContent:t})}},"simple-content-eval(text):1":{contentSaved:()=>{o.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>o.getState().getTextContentFunction(),loadContent:t=>{o.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{o.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>o.getState().getJsonContentFunction(),loadContent:t=>{o.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"meta-player-ui:1":{executeAction(t){if(t.startsWith("qa")){const n=o.getState().quickActions[t];n?n():console.error(`Quick action not found: ${t}`)}else{const n=o.getState().sidebarActions[t];n?n():console.error(`Sidebar action not found: ${t}`)}},executeFileUpload(t,e){if(t.startsWith("qa")){const s=o.getState().quickActions[t];s?s(e):console.error(`Quick action not found: ${t}`)}else{const s=o.getState().sidebarActions[t];s?s(e):console.error(`Sidebar action not found: ${t}`)}},updateSettings(t){o.setState({activitySettings:t})}},"meta-player-events:1":{handleEvent(t){t==="all-loaded"&&o.setState({ready:!0})}}},S=F.getSocket();function P(t){for(const e of t){if(!j.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];S.plug([e],([])=>[n])}S.plugsDone();for(const e of["simple-content(text):1","simple-content(json):1","simple-binary-data(text):1","simple-content-eval(text):1"])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];S.use([n],([s])=>{o.subscribe(i=>i.isDirtyCount,()=>{var i;(i=s.i)==null||i.contentChanged(),console.log(`Content changed for contract ${n}`)})})}}function L({children:t,contracts:e,loadOnlyWhenReady:n=!0}){const s=o(i=>i.ready);return u.useEffect(()=>{const i=e.includes("meta-player-events:1")?e:[...e,"meta-player-events:1"];P(i)},[]),n&&!s?w.jsx("div",{className:"container",children:"Chargement en cours..."}):w.jsx("div",{className:"container",children:t})}const R=()=>o(t=>{if(t.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return t.mode}),D=()=>o(t=>{if(t.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return t.workflow}),Q=()=>o(t=>{if(t.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return t.theme}),W=()=>o(t=>t.incSaveCount),N=()=>o(t=>t.incDirtyCount),O=()=>o(t=>t.loadedTextContent),G=()=>o(t=>t.loadedJsonContent),H=t=>{const e=o(n=>n.setGetTextContentFunction);u.useEffect(()=>{e(t)},[t,e])},U=t=>{const e=o(n=>n.setGetJsonContentFunction);u.useEffect(()=>{e(t)},[t,e])},B=t=>{const e=o(n=>n.afterSaveCount);u.useEffect(()=>{e>0&&t()},[e])},V=()=>(t,e)=>{S.use(["meta-player-ui"],([n])=>{var s;if(n.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(s=n.i)==null||s.previewTextFile(t,e)})},_=()=>(t,e)=>{S.use(["meta-player-ui"],([n])=>{var s;if(n.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(s=n.i)==null||s.previewImageFile(t,e)})};let C=0,b=0;const z=(t,e)=>{const n=u.useMemo(t,e),s=o(i=>i.setSidebarActions);u.useEffect(()=>(C++,C>1&&console.error("Capytale iframe React: Multiple sidebar actions registered: ",C),()=>{C--}),[]),u.useEffect(()=>(S.use(["meta-player-ui"],([i])=>{var l;if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}b++;const d=n.map((r,a)=>({type:r.type,title:r.title,icon:r.icon,id:`sa-${b}-${a}`,...r.type==="file-upload"?{accept:r.accept}:{}})),c={};n.forEach((r,a)=>{c[`sa-${b}-${a}`]=r.action}),(l=i.i)==null||l.setSidebarActionButtons(d),s(c)}),()=>{s({}),S.use(["meta-player-ui"],([i])=>{var d;if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(d=i.i)==null||d.setSidebarActionButtons([])})}),[n])};let y=0,A=0;const K=(t,e)=>{const n=u.useMemo(t,e),s=o(i=>i.setQuickActions);u.useEffect(()=>(y++,y>1&&console.error("Capytale iframe React: Multiple quick actions registered: ",y),()=>{y--}),[]),u.useEffect(()=>(S.use(["meta-player-ui"],([i])=>{var l;if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}A++;const d=n.map((r,a)=>({type:r.type,title:r.title,icon:r.icon,id:`qa-${A}-${a}`,...r.type==="file-upload"?{accept:r.accept}:{}})),c={};n.forEach((r,a)=>{c[`qa-${A}-${a}`]=r.action}),(l=i.i)==null||l.setQuickActionButtons(d),s(c)}),()=>{s({}),S.use(["meta-player-ui"],([i])=>{var d;if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(d=i.i)==null||d.setQuickActionButtons([])})}),[n])};let m=0;const X=(t,e)=>{const n=u.useMemo(t,e),s=o(c=>c.setActivitySettings),i=o(c=>c.activitySettings),d=u.useRef("");return u.useEffect(()=>(console.log("Mounting useSettings"),m++,m>1&&console.error("Capytale iframe React: Multiple settings registered: ",m),()=>{m--}),[]),u.useEffect(()=>{const c=JSON.stringify(n);if(c!==d.current)return d.current=c,S.use(["meta-player-ui"],([l])=>{var r;if(l.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}console.log("Updating settings UI in MetaPlayer",n),(r=l.i)==null||r.setSettingsUI(n)}),()=>{s(null)}},[n]),i},Y=()=>e=>{S.use(["meta-player-ui"],([n])=>{var s;if(n.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(s=n.i)==null||s.showToast(e)})};exports.Capytale=L;exports.useAfterSaveAction=B;exports.useJsonContentSaveFunction=U;exports.useLoadedJsonContent=G;exports.useLoadedTextContent=O;exports.useMode=R;exports.useNotifyIsDirty=N;exports.usePreviewImageFile=_;exports.usePreviewTextFile=V;exports.useQuickActions=K;exports.useRequestSave=W;exports.useSettings=X;exports.useShowToast=Y;exports.useSidebarActions=z;exports.useTextContentSaveFunction=H;exports.useTheme=Q;exports.useWorkflow=D;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react/jsx-runtime"),u=require("react"),E=require("@capytale/app-agent"),x=t=>{let e;const n=new Set,s=(c,p)=>{const S=typeof c=="function"?c(e):c;if(!Object.is(S,e)){const y=e;e=p??(typeof S!="object"||S===null)?S:Object.assign({},e,S),n.forEach(g=>g(e,y))}},i=()=>e,l={setState:s,getState:i,getInitialState:()=>a,subscribe:c=>(n.add(c),()=>n.delete(c))},a=e=t(s,i,l);return l},M=t=>t?x(t):x,q=t=>t;function j(t,e=q){const n=u.useSyncExternalStore(t.subscribe,()=>e(t.getState()),()=>e(t.getInitialState()));return u.useDebugValue(n),n}const h=t=>{const e=M(t),n=s=>j(e,s);return Object.assign(n,e),n},J=t=>t?h(t):h,I=t=>(e,n,s)=>{const i=s.subscribe;return s.subscribe=(r,l,a)=>{let c=r;if(l){const p=(a==null?void 0:a.equalityFn)||Object.is;let S=r(s.getState());c=y=>{const g=r(y);if(!p(S,g)){const F=S;l(S=g,F)}},a!=null&&a.fireImmediately&&l(S,S)}return i(c)},t(e,n,s)},$=I,o=J()($(t=>({ready:!1,workflow:"current",mode:"assignment",theme:"light",saveCount:0,afterSaveCount:0,isDirtyCount:0,loadedTextContent:null,loadedJsonContent:null,getTextContentFunction:()=>(console.error("getTextContentFunction is not set"),null),getJsonContentFunction:()=>(console.error("getJsonContentFunction is not set"),null),sidebarActions:{},quickActions:{},activitySettings:null,setGetTextContentFunction:e=>{t({getTextContentFunction:e})},setGetJsonContentFunction:e=>{t({getJsonContentFunction:e})},setSidebarActions:e=>{t({sidebarActions:e})},setQuickActions:e=>{t({quickActions:e})},setActivitySettings:e=>{t({activitySettings:e})},incSaveCount:()=>t(e=>({saveCount:e.saveCount+1})),incDirtyCount:()=>t(e=>({isDirtyCount:e.isDirtyCount+1}))})));let k=!1;const P=["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"],T={"mode:1":{setMode:t=>{o.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){o.setState({theme:null});return}if(t!=="light"&&t!=="dark"){console.warn(`Invalid theme: ${t}. Expected 'light' or 'dark'.`),o.setState({theme:null});return}o.setState({theme:t})}},"workflow:1":{setWorkflow:t=>{o.setState({workflow:t})}},"simple-content(text):1":{contentSaved:()=>{o.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>o.getState().getTextContentFunction(),loadContent:t=>{o.setState({loadedTextContent:t})}},"simple-content(json):1":{contentSaved:()=>{o.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>o.getState().getJsonContentFunction(),loadContent:t=>{o.setState({loadedJsonContent:t})}},"simple-binary-data(text):1":{contentSaved:()=>{o.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>o.getState().getTextContentFunction(),loadContent:t=>{o.setState({loadedTextContent:t})}},"simple-content-eval(text):1":{contentSaved:()=>{o.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>o.getState().getTextContentFunction(),loadContent:t=>{o.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{o.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>o.getState().getJsonContentFunction(),loadContent:t=>{o.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(json):2":{contentSaved:()=>{o.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>o.getState().getJsonContentFunction(),loadContent:t=>{o.setState({loadedJsonContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(json)")}},"simple-content-eval(text):2":{contentSaved:()=>{o.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>o.getState().getTextContentFunction(),loadContent:t=>{o.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"meta-player-ui:1":{executeAction(t){if(t.startsWith("qa")){const n=o.getState().quickActions[t];n?n():console.error(`Quick action not found: ${t}`)}else{const n=o.getState().sidebarActions[t];n?n():console.error(`Sidebar action not found: ${t}`)}},executeFileUpload(t,e){if(t.startsWith("qa")){const s=o.getState().quickActions[t];s?s(e):console.error(`Quick action not found: ${t}`)}else{const s=o.getState().sidebarActions[t];s?s(e):console.error(`Sidebar action not found: ${t}`)}},updateSettings(t){o.setState({activitySettings:t})}},"meta-player-events:1":{handleEvent(t){t==="all-loaded"&&o.setState({ready:!0})}}},f=E.getSocket();function L(t){if(k){console.warn("Contracts have already been plugged. Skipping.");return}k=!0;for(const e of t){if(!P.includes(e)){console.warn(`Contract ${e} is not implemented in Capytale. Skipping plug.`);continue}if(!(e in T)){console.warn(`Contract handler for ${e} is not defined. Skipping plug.`);continue}const n=T[e];f.plug([e],([])=>[n])}f.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];f.use([n],([s])=>{o.subscribe(i=>i.isDirtyCount,()=>{var i;(i=s.i)==null||i.contentChanged(),console.log(`Content changed for contract ${n}`)})})}}function R({children:t,contracts:e,loadOnlyWhenReady:n=!0}){const s=o(i=>i.ready);return u.useEffect(()=>{const i=e.includes("meta-player-events:1")?e:[...e,"meta-player-events:1"];L(i)},[]),n&&!s?w.jsx("div",{className:"container",children:"Chargement en cours..."}):w.jsx("div",{className:"container",children:t})}const D=()=>o(t=>{if(t.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return t.mode}),Q=()=>o(t=>{if(t.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return t.workflow}),W=()=>o(t=>{if(t.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return t.theme}),N=()=>o(t=>t.incSaveCount),O=()=>o(t=>t.incDirtyCount),G=()=>o(t=>t.loadedTextContent),H=()=>o(t=>t.loadedJsonContent),U=t=>{const e=o(n=>n.setGetTextContentFunction);u.useEffect(()=>{e(t)},[t,e])},B=t=>{const e=o(n=>n.setGetJsonContentFunction);u.useEffect(()=>{e(t)},[t,e])},V=t=>{const e=o(n=>n.afterSaveCount);u.useEffect(()=>{e>0&&t()},[e])},_=()=>(t,e)=>{f.use(["meta-player-ui"],([n])=>{var s;if(n.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(s=n.i)==null||s.previewTextFile(t,e)})},z=()=>(t,e)=>{f.use(["meta-player-ui"],([n])=>{var s;if(n.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(s=n.i)==null||s.previewImageFile(t,e)})};let C=0,b=0;const K=(t,e)=>{const n=u.useMemo(t,e),s=o(i=>i.setSidebarActions);u.useEffect(()=>(C++,C>1&&console.error("Capytale iframe React: Multiple sidebar actions registered: ",C),()=>{C--}),[]),u.useEffect(()=>(f.use(["meta-player-ui"],([i])=>{var l;if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}b++;const d=n.map((a,c)=>({type:a.type,title:a.title,icon:a.icon,id:`sa-${b}-${c}`,...a.type==="file-upload"?{accept:a.accept}:{}})),r={};n.forEach((a,c)=>{r[`sa-${b}-${c}`]=a.action}),(l=i.i)==null||l.setSidebarActionButtons(d),s(r)}),()=>{s({}),f.use(["meta-player-ui"],([i])=>{var d;if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(d=i.i)==null||d.setSidebarActionButtons([])})}),[n])};let m=0,A=0;const X=(t,e)=>{const n=u.useMemo(t,e),s=o(i=>i.setQuickActions);u.useEffect(()=>(m++,m>1&&console.error("Capytale iframe React: Multiple quick actions registered: ",m),()=>{m--}),[]),u.useEffect(()=>(f.use(["meta-player-ui"],([i])=>{var l;if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}A++;const d=n.map((a,c)=>({type:a.type,title:a.title,icon:a.icon,id:`qa-${A}-${c}`,...a.type==="file-upload"?{accept:a.accept}:{}})),r={};n.forEach((a,c)=>{r[`qa-${A}-${c}`]=a.action}),(l=i.i)==null||l.setQuickActionButtons(d),s(r)}),()=>{s({}),f.use(["meta-player-ui"],([i])=>{var d;if(i.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(d=i.i)==null||d.setQuickActionButtons([])})}),[n])};let v=0;const Y=(t,e)=>{const n=u.useMemo(t,e),s=o(r=>r.setActivitySettings),i=o(r=>r.activitySettings),d=u.useRef("");return u.useEffect(()=>(console.log("Mounting useSettings"),v++,v>1&&console.error("Capytale iframe React: Multiple settings registered: ",v),()=>{v--}),[]),u.useEffect(()=>{const r=JSON.stringify(n);if(r!==d.current)return d.current=r,f.use(["meta-player-ui"],([l])=>{var a;if(l.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}console.log("Updating settings UI in MetaPlayer",n),(a=l.i)==null||a.setSettingsUI(n)}),()=>{s(null)}},[n]),i},Z=()=>e=>{f.use(["meta-player-ui"],([n])=>{var s;if(n.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(s=n.i)==null||s.showToast(e)})};exports.Capytale=R;exports.useAfterSaveAction=V;exports.useJsonContentSaveFunction=B;exports.useLoadedJsonContent=H;exports.useLoadedTextContent=G;exports.useMode=D;exports.useNotifyIsDirty=O;exports.usePreviewImageFile=z;exports.usePreviewTextFile=_;exports.useQuickActions=X;exports.useRequestSave=N;exports.useSettings=Y;exports.useShowToast=Z;exports.useSidebarActions=K;exports.useTextContentSaveFunction=U;exports.useTheme=W;exports.useWorkflow=Q;
|
package/dist/index.es.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import x, { useEffect as S, useMemo as
|
|
3
|
-
import { getSocket as
|
|
1
|
+
import { jsx as h } from "react/jsx-runtime";
|
|
2
|
+
import x, { useEffect as S, useMemo as w, useRef as J } from "react";
|
|
3
|
+
import { getSocket as $ } from "@capytale/app-agent";
|
|
4
4
|
const k = (t) => {
|
|
5
5
|
let e;
|
|
6
|
-
const n = /* @__PURE__ */ new Set(), s = (c,
|
|
6
|
+
const n = /* @__PURE__ */ new Set(), s = (c, g) => {
|
|
7
7
|
const d = typeof c == "function" ? c(e) : c;
|
|
8
8
|
if (!Object.is(d, e)) {
|
|
9
|
-
const
|
|
10
|
-
e =
|
|
9
|
+
const y = e;
|
|
10
|
+
e = g ?? (typeof d != "object" || d === null) ? d : Object.assign({}, e, d), n.forEach((f) => f(e, y));
|
|
11
11
|
}
|
|
12
|
-
}, i = () => e,
|
|
13
|
-
return
|
|
14
|
-
},
|
|
15
|
-
function
|
|
12
|
+
}, i = () => e, l = { setState: s, getState: i, getInitialState: () => r, subscribe: (c) => (n.add(c), () => n.delete(c)) }, r = e = t(s, i, l);
|
|
13
|
+
return l;
|
|
14
|
+
}, j = (t) => t ? k(t) : k, q = (t) => t;
|
|
15
|
+
function I(t, e = q) {
|
|
16
16
|
const n = x.useSyncExternalStore(
|
|
17
17
|
t.subscribe,
|
|
18
18
|
() => e(t.getState()),
|
|
@@ -21,27 +21,27 @@ function J(t, e = I) {
|
|
|
21
21
|
return x.useDebugValue(n), n;
|
|
22
22
|
}
|
|
23
23
|
const T = (t) => {
|
|
24
|
-
const e =
|
|
24
|
+
const e = j(t), n = (s) => I(e, s);
|
|
25
25
|
return Object.assign(n, e), n;
|
|
26
|
-
},
|
|
26
|
+
}, P = (t) => t ? T(t) : T, D = (t) => (e, n, s) => {
|
|
27
27
|
const i = s.subscribe;
|
|
28
|
-
return s.subscribe = (a,
|
|
28
|
+
return s.subscribe = (a, l, r) => {
|
|
29
29
|
let c = a;
|
|
30
|
-
if (
|
|
31
|
-
const
|
|
30
|
+
if (l) {
|
|
31
|
+
const g = (r == null ? void 0 : r.equalityFn) || Object.is;
|
|
32
32
|
let d = a(s.getState());
|
|
33
|
-
c = (
|
|
34
|
-
const
|
|
35
|
-
if (!
|
|
36
|
-
const
|
|
37
|
-
|
|
33
|
+
c = (y) => {
|
|
34
|
+
const f = a(y);
|
|
35
|
+
if (!g(d, f)) {
|
|
36
|
+
const E = d;
|
|
37
|
+
l(d = f, E);
|
|
38
38
|
}
|
|
39
|
-
}, r != null && r.fireImmediately &&
|
|
39
|
+
}, r != null && r.fireImmediately && l(d, d);
|
|
40
40
|
}
|
|
41
41
|
return i(c);
|
|
42
42
|
}, t(e, n, s);
|
|
43
|
-
},
|
|
44
|
-
|
|
43
|
+
}, L = D, o = P()(
|
|
44
|
+
L((t) => ({
|
|
45
45
|
ready: !1,
|
|
46
46
|
workflow: "current",
|
|
47
47
|
mode: "assignment",
|
|
@@ -76,7 +76,9 @@ const T = (t) => {
|
|
|
76
76
|
})),
|
|
77
77
|
incDirtyCount: () => t((e) => ({ isDirtyCount: e.isDirtyCount + 1 }))
|
|
78
78
|
}))
|
|
79
|
-
)
|
|
79
|
+
);
|
|
80
|
+
let F = !1;
|
|
81
|
+
const R = [
|
|
80
82
|
"meta-player-events:1",
|
|
81
83
|
"meta-player-ui:1",
|
|
82
84
|
"mode:1",
|
|
@@ -88,7 +90,7 @@ const T = (t) => {
|
|
|
88
90
|
"simple-binary-data(text):1",
|
|
89
91
|
"simple-content-eval(text):1",
|
|
90
92
|
"simple-content-eval(json):1"
|
|
91
|
-
],
|
|
93
|
+
], M = {
|
|
92
94
|
"mode:1": {
|
|
93
95
|
setMode: (t) => {
|
|
94
96
|
o.setState({ mode: t });
|
|
@@ -184,6 +186,38 @@ const T = (t) => {
|
|
|
184
186
|
);
|
|
185
187
|
}
|
|
186
188
|
},
|
|
189
|
+
"simple-content-eval(json):2": {
|
|
190
|
+
contentSaved: () => {
|
|
191
|
+
o.setState((t) => ({
|
|
192
|
+
afterSaveCount: t.afterSaveCount + 1
|
|
193
|
+
}));
|
|
194
|
+
},
|
|
195
|
+
getContent: () => o.getState().getJsonContentFunction(),
|
|
196
|
+
loadContent: (t) => {
|
|
197
|
+
o.setState({ loadedJsonContent: t });
|
|
198
|
+
},
|
|
199
|
+
getAssignmentContent: () => {
|
|
200
|
+
throw new Error(
|
|
201
|
+
"getAssignmentContent is not implemented for simple-content-eval(json)"
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
"simple-content-eval(text):2": {
|
|
206
|
+
contentSaved: () => {
|
|
207
|
+
o.setState((t) => ({
|
|
208
|
+
afterSaveCount: t.afterSaveCount + 1
|
|
209
|
+
}));
|
|
210
|
+
},
|
|
211
|
+
getContent: () => o.getState().getTextContentFunction(),
|
|
212
|
+
loadContent: (t) => {
|
|
213
|
+
o.setState({ loadedTextContent: t });
|
|
214
|
+
},
|
|
215
|
+
getAssignmentContent: () => {
|
|
216
|
+
throw new Error(
|
|
217
|
+
"getAssignmentContent is not implemented for simple-content-eval(text)"
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
},
|
|
187
221
|
"meta-player-ui:1": {
|
|
188
222
|
executeAction(t) {
|
|
189
223
|
if (t.startsWith("qa")) {
|
|
@@ -212,22 +246,27 @@ const T = (t) => {
|
|
|
212
246
|
t === "all-loaded" && o.setState({ ready: !0 });
|
|
213
247
|
}
|
|
214
248
|
}
|
|
215
|
-
}, p =
|
|
216
|
-
function
|
|
249
|
+
}, p = $();
|
|
250
|
+
function Q(t) {
|
|
251
|
+
if (F) {
|
|
252
|
+
console.warn("Contracts have already been plugged. Skipping.");
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
F = !0;
|
|
217
256
|
for (const e of t) {
|
|
218
|
-
if (!
|
|
257
|
+
if (!R.includes(e)) {
|
|
219
258
|
console.warn(
|
|
220
259
|
`Contract ${e} is not implemented in Capytale. Skipping plug.`
|
|
221
260
|
);
|
|
222
261
|
continue;
|
|
223
262
|
}
|
|
224
|
-
if (!(e in
|
|
263
|
+
if (!(e in M)) {
|
|
225
264
|
console.warn(
|
|
226
265
|
`Contract handler for ${e} is not defined. Skipping plug.`
|
|
227
266
|
);
|
|
228
267
|
continue;
|
|
229
268
|
}
|
|
230
|
-
const n =
|
|
269
|
+
const n = M[e];
|
|
231
270
|
p.plug([e], ([]) => [n]);
|
|
232
271
|
}
|
|
233
272
|
p.plugsDone();
|
|
@@ -235,7 +274,10 @@ function R(t) {
|
|
|
235
274
|
"simple-content(text):1",
|
|
236
275
|
"simple-content(json):1",
|
|
237
276
|
"simple-binary-data(text):1",
|
|
238
|
-
"simple-content-eval(text):1"
|
|
277
|
+
"simple-content-eval(text):1",
|
|
278
|
+
"simple-content-eval(json):1",
|
|
279
|
+
"simple-content-eval(json):2",
|
|
280
|
+
"simple-content-eval(text):2"
|
|
239
281
|
])
|
|
240
282
|
if (console.log(`Contract ${e} is being subscribed to content changes.`), t.includes(e)) {
|
|
241
283
|
console.log(`Subscribing to content changes for contract ${e}`);
|
|
@@ -248,7 +290,7 @@ function R(t) {
|
|
|
248
290
|
});
|
|
249
291
|
}
|
|
250
292
|
}
|
|
251
|
-
function
|
|
293
|
+
function H({
|
|
252
294
|
children: t,
|
|
253
295
|
contracts: e,
|
|
254
296
|
loadOnlyWhenReady: n = !0
|
|
@@ -256,41 +298,41 @@ function G({
|
|
|
256
298
|
const s = o((i) => i.ready);
|
|
257
299
|
return S(() => {
|
|
258
300
|
const i = e.includes("meta-player-events:1") ? e : [...e, "meta-player-events:1"];
|
|
259
|
-
|
|
260
|
-
}, []), n && !s ? /* @__PURE__ */
|
|
301
|
+
Q(i);
|
|
302
|
+
}, []), n && !s ? /* @__PURE__ */ h("div", { className: "container", children: "Chargement en cours..." }) : /* @__PURE__ */ h("div", { className: "container", children: t });
|
|
261
303
|
}
|
|
262
|
-
const
|
|
304
|
+
const O = () => o((t) => {
|
|
263
305
|
if (t.mode === null)
|
|
264
306
|
throw new Error("Mode is not set. Have you used contract 'mode'?");
|
|
265
307
|
return t.mode;
|
|
266
|
-
}),
|
|
308
|
+
}), U = () => o((t) => {
|
|
267
309
|
if (t.workflow === null)
|
|
268
310
|
throw new Error("Workflow is not set. Have you used contract 'workflow'?");
|
|
269
311
|
return t.workflow;
|
|
270
|
-
}),
|
|
312
|
+
}), B = () => o((t) => {
|
|
271
313
|
if (t.theme === null)
|
|
272
314
|
throw new Error("Theme is not set. Have you used contract 'theme'?");
|
|
273
315
|
return t.theme;
|
|
274
|
-
}),
|
|
316
|
+
}), V = () => o((t) => t.incSaveCount), _ = () => o((t) => t.incDirtyCount), z = () => o((t) => t.loadedTextContent), K = () => o((t) => t.loadedJsonContent), X = (t) => {
|
|
275
317
|
const e = o(
|
|
276
318
|
(n) => n.setGetTextContentFunction
|
|
277
319
|
);
|
|
278
320
|
S(() => {
|
|
279
321
|
e(t);
|
|
280
322
|
}, [t, e]);
|
|
281
|
-
},
|
|
323
|
+
}, Y = (t) => {
|
|
282
324
|
const e = o(
|
|
283
325
|
(n) => n.setGetJsonContentFunction
|
|
284
326
|
);
|
|
285
327
|
S(() => {
|
|
286
328
|
e(t);
|
|
287
329
|
}, [t, e]);
|
|
288
|
-
},
|
|
330
|
+
}, Z = (t) => {
|
|
289
331
|
const e = o((n) => n.afterSaveCount);
|
|
290
332
|
S(() => {
|
|
291
333
|
e > 0 && t();
|
|
292
334
|
}, [e]);
|
|
293
|
-
},
|
|
335
|
+
}, tt = () => (t, e) => {
|
|
294
336
|
p.use(["meta-player-ui"], ([n]) => {
|
|
295
337
|
var s;
|
|
296
338
|
if (n.version === 0) {
|
|
@@ -299,7 +341,7 @@ const H = () => o((t) => {
|
|
|
299
341
|
}
|
|
300
342
|
(s = n.i) == null || s.previewTextFile(t, e);
|
|
301
343
|
});
|
|
302
|
-
},
|
|
344
|
+
}, et = () => (t, e) => {
|
|
303
345
|
p.use(["meta-player-ui"], ([n]) => {
|
|
304
346
|
var s;
|
|
305
347
|
if (n.version === 0) {
|
|
@@ -310,18 +352,18 @@ const H = () => o((t) => {
|
|
|
310
352
|
});
|
|
311
353
|
};
|
|
312
354
|
let C = 0, b = 0;
|
|
313
|
-
const
|
|
314
|
-
const n =
|
|
355
|
+
const nt = (t, e) => {
|
|
356
|
+
const n = w(t, e), s = o((i) => i.setSidebarActions);
|
|
315
357
|
S(() => (C++, C > 1 && console.error("Capytale iframe React: Multiple sidebar actions registered: ", C), () => {
|
|
316
358
|
C--;
|
|
317
359
|
}), []), S(() => (p.use(["meta-player-ui"], ([i]) => {
|
|
318
|
-
var
|
|
360
|
+
var l;
|
|
319
361
|
if (i.version === 0) {
|
|
320
362
|
console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");
|
|
321
363
|
return;
|
|
322
364
|
}
|
|
323
365
|
b++;
|
|
324
|
-
const
|
|
366
|
+
const u = n.map((r, c) => ({
|
|
325
367
|
type: r.type,
|
|
326
368
|
title: r.title,
|
|
327
369
|
icon: r.icon,
|
|
@@ -330,31 +372,31 @@ const et = (t, e) => {
|
|
|
330
372
|
})), a = {};
|
|
331
373
|
n.forEach((r, c) => {
|
|
332
374
|
a[`sa-${b}-${c}`] = r.action;
|
|
333
|
-
}), (
|
|
375
|
+
}), (l = i.i) == null || l.setSidebarActionButtons(u), s(a);
|
|
334
376
|
}), () => {
|
|
335
377
|
s({}), p.use(["meta-player-ui"], ([i]) => {
|
|
336
|
-
var
|
|
378
|
+
var u;
|
|
337
379
|
if (i.version === 0) {
|
|
338
380
|
console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");
|
|
339
381
|
return;
|
|
340
382
|
}
|
|
341
|
-
(
|
|
383
|
+
(u = i.i) == null || u.setSidebarActionButtons([]);
|
|
342
384
|
});
|
|
343
385
|
}), [n]);
|
|
344
386
|
};
|
|
345
387
|
let m = 0, A = 0;
|
|
346
|
-
const
|
|
347
|
-
const n =
|
|
388
|
+
const ot = (t, e) => {
|
|
389
|
+
const n = w(t, e), s = o((i) => i.setQuickActions);
|
|
348
390
|
S(() => (m++, m > 1 && console.error("Capytale iframe React: Multiple quick actions registered: ", m), () => {
|
|
349
391
|
m--;
|
|
350
392
|
}), []), S(() => (p.use(["meta-player-ui"], ([i]) => {
|
|
351
|
-
var
|
|
393
|
+
var l;
|
|
352
394
|
if (i.version === 0) {
|
|
353
395
|
console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");
|
|
354
396
|
return;
|
|
355
397
|
}
|
|
356
398
|
A++;
|
|
357
|
-
const
|
|
399
|
+
const u = n.map((r, c) => ({
|
|
358
400
|
type: r.type,
|
|
359
401
|
title: r.title,
|
|
360
402
|
icon: r.icon,
|
|
@@ -363,38 +405,38 @@ const nt = (t, e) => {
|
|
|
363
405
|
})), a = {};
|
|
364
406
|
n.forEach((r, c) => {
|
|
365
407
|
a[`qa-${A}-${c}`] = r.action;
|
|
366
|
-
}), (
|
|
408
|
+
}), (l = i.i) == null || l.setQuickActionButtons(u), s(a);
|
|
367
409
|
}), () => {
|
|
368
410
|
s({}), p.use(["meta-player-ui"], ([i]) => {
|
|
369
|
-
var
|
|
411
|
+
var u;
|
|
370
412
|
if (i.version === 0) {
|
|
371
413
|
console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");
|
|
372
414
|
return;
|
|
373
415
|
}
|
|
374
|
-
(
|
|
416
|
+
(u = i.i) == null || u.setQuickActionButtons([]);
|
|
375
417
|
});
|
|
376
418
|
}), [n]);
|
|
377
419
|
};
|
|
378
|
-
let
|
|
379
|
-
const
|
|
380
|
-
const n =
|
|
381
|
-
return S(() => (console.log("Mounting useSettings"),
|
|
382
|
-
|
|
420
|
+
let v = 0;
|
|
421
|
+
const st = (t, e) => {
|
|
422
|
+
const n = w(t, e), s = o((a) => a.setActivitySettings), i = o((a) => a.activitySettings), u = J("");
|
|
423
|
+
return S(() => (console.log("Mounting useSettings"), v++, v > 1 && console.error("Capytale iframe React: Multiple settings registered: ", v), () => {
|
|
424
|
+
v--;
|
|
383
425
|
}), []), S(() => {
|
|
384
426
|
const a = JSON.stringify(n);
|
|
385
|
-
if (a !==
|
|
386
|
-
return
|
|
427
|
+
if (a !== u.current)
|
|
428
|
+
return u.current = a, p.use(["meta-player-ui"], ([l]) => {
|
|
387
429
|
var r;
|
|
388
|
-
if (
|
|
430
|
+
if (l.version === 0) {
|
|
389
431
|
console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");
|
|
390
432
|
return;
|
|
391
433
|
}
|
|
392
|
-
console.log("Updating settings UI in MetaPlayer", n), (r =
|
|
434
|
+
console.log("Updating settings UI in MetaPlayer", n), (r = l.i) == null || r.setSettingsUI(n);
|
|
393
435
|
}), () => {
|
|
394
436
|
s(null);
|
|
395
437
|
};
|
|
396
438
|
}, [n]), i;
|
|
397
|
-
},
|
|
439
|
+
}, it = () => (e) => {
|
|
398
440
|
p.use(["meta-player-ui"], ([n]) => {
|
|
399
441
|
var s;
|
|
400
442
|
if (n.version === 0) {
|
|
@@ -405,21 +447,21 @@ const ot = (t, e) => {
|
|
|
405
447
|
});
|
|
406
448
|
};
|
|
407
449
|
export {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
450
|
+
H as Capytale,
|
|
451
|
+
Z as useAfterSaveAction,
|
|
452
|
+
Y as useJsonContentSaveFunction,
|
|
453
|
+
K as useLoadedJsonContent,
|
|
454
|
+
z as useLoadedTextContent,
|
|
455
|
+
O as useMode,
|
|
456
|
+
_ as useNotifyIsDirty,
|
|
457
|
+
et as usePreviewImageFile,
|
|
458
|
+
tt as usePreviewTextFile,
|
|
459
|
+
ot as useQuickActions,
|
|
460
|
+
V as useRequestSave,
|
|
461
|
+
st as useSettings,
|
|
462
|
+
it as useShowToast,
|
|
463
|
+
nt as useSidebarActions,
|
|
464
|
+
X as useTextContentSaveFunction,
|
|
465
|
+
B as useTheme,
|
|
466
|
+
U as useWorkflow
|
|
425
467
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capytale/iframe-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@capytale/app-agent": "^1.0.
|
|
29
|
+
"@capytale/app-agent": "^1.0.8",
|
|
30
30
|
"@capytale/contracts": "^1.0.2",
|
|
31
31
|
"zustand": "^5.0.6"
|
|
32
32
|
},
|