@capytale/iframe-react 1.0.3 → 1.0.5
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/README.md +5 -5
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +60 -53
- package/package.json +51 -51
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# Capytale iframe React
|
|
2
|
-
|
|
3
|
-
Une bibliothèque React pour intégrer une application React à la plateforme Capytale.
|
|
4
|
-
|
|
5
|
-
Elle gère la communication entre l'application React et le conteneur Capytale, en utilisant des contrats metaplayer-rpc.
|
|
1
|
+
# Capytale iframe React
|
|
2
|
+
|
|
3
|
+
Une bibliothèque React pour intégrer une application React à la plateforme Capytale.
|
|
4
|
+
|
|
5
|
+
Elle gère la communication entre l'application React et le conteneur Capytale, en utilisant des contrats metaplayer-rpc.
|
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"),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},E=t=>t?x(t):x,M=t=>t;function q(t,e=M){const n=u.useSyncExternalStore(t.subscribe,()=>e(t.getState()),()=>e(t.getInitialState()));return u.useDebugValue(n),n}const h=t=>{const e=E(t),n=s=>q(e,s);return Object.assign(n,e),n},j=t=>t?h(t):h,J=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 T=S;l(S=g,T)}},a!=null&&a.fireImmediately&&l(S,S)}return i(c)},t(e,n,s)},I=J,o=j()(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}))}))),$=["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)")}},"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=F.getSocket();function P(t){for(const e of t){if(!$.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];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 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)=>{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)})},_=()=>(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 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(()=>(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 K=(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 X=(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},Y=()=>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=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,6 +1,6 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
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
6
|
const n = /* @__PURE__ */ new Set(), s = (c, g) => {
|
|
@@ -11,19 +11,19 @@ const k = (t) => {
|
|
|
11
11
|
}
|
|
12
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
13
|
return l;
|
|
14
|
-
},
|
|
15
|
-
function
|
|
16
|
-
const n =
|
|
14
|
+
}, j = (t) => t ? k(t) : k, q = (t) => t;
|
|
15
|
+
function I(t, e = q) {
|
|
16
|
+
const n = x.useSyncExternalStore(
|
|
17
17
|
t.subscribe,
|
|
18
18
|
() => e(t.getState()),
|
|
19
19
|
() => e(t.getInitialState())
|
|
20
20
|
);
|
|
21
|
-
return
|
|
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
28
|
return s.subscribe = (a, l, r) => {
|
|
29
29
|
let c = a;
|
|
@@ -33,15 +33,15 @@ const T = (t) => {
|
|
|
33
33
|
c = (y) => {
|
|
34
34
|
const f = a(y);
|
|
35
35
|
if (!g(d, f)) {
|
|
36
|
-
const
|
|
37
|
-
l(d = f,
|
|
36
|
+
const E = d;
|
|
37
|
+
l(d = f, E);
|
|
38
38
|
}
|
|
39
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 });
|
|
@@ -244,22 +246,27 @@ const T = (t) => {
|
|
|
244
246
|
t === "all-loaded" && o.setState({ ready: !0 });
|
|
245
247
|
}
|
|
246
248
|
}
|
|
247
|
-
}, p =
|
|
248
|
-
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;
|
|
249
256
|
for (const e of t) {
|
|
250
|
-
if (!
|
|
257
|
+
if (!R.includes(e)) {
|
|
251
258
|
console.warn(
|
|
252
259
|
`Contract ${e} is not implemented in Capytale. Skipping plug.`
|
|
253
260
|
);
|
|
254
261
|
continue;
|
|
255
262
|
}
|
|
256
|
-
if (!(e in
|
|
263
|
+
if (!(e in M)) {
|
|
257
264
|
console.warn(
|
|
258
265
|
`Contract handler for ${e} is not defined. Skipping plug.`
|
|
259
266
|
);
|
|
260
267
|
continue;
|
|
261
268
|
}
|
|
262
|
-
const n =
|
|
269
|
+
const n = M[e];
|
|
263
270
|
p.plug([e], ([]) => [n]);
|
|
264
271
|
}
|
|
265
272
|
p.plugsDone();
|
|
@@ -283,7 +290,7 @@ function R(t) {
|
|
|
283
290
|
});
|
|
284
291
|
}
|
|
285
292
|
}
|
|
286
|
-
function
|
|
293
|
+
function H({
|
|
287
294
|
children: t,
|
|
288
295
|
contracts: e,
|
|
289
296
|
loadOnlyWhenReady: n = !0
|
|
@@ -291,41 +298,41 @@ function G({
|
|
|
291
298
|
const s = o((i) => i.ready);
|
|
292
299
|
return S(() => {
|
|
293
300
|
const i = e.includes("meta-player-events:1") ? e : [...e, "meta-player-events:1"];
|
|
294
|
-
|
|
295
|
-
}, []), 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 });
|
|
296
303
|
}
|
|
297
|
-
const
|
|
304
|
+
const O = () => o((t) => {
|
|
298
305
|
if (t.mode === null)
|
|
299
306
|
throw new Error("Mode is not set. Have you used contract 'mode'?");
|
|
300
307
|
return t.mode;
|
|
301
|
-
}),
|
|
308
|
+
}), U = () => o((t) => {
|
|
302
309
|
if (t.workflow === null)
|
|
303
310
|
throw new Error("Workflow is not set. Have you used contract 'workflow'?");
|
|
304
311
|
return t.workflow;
|
|
305
|
-
}),
|
|
312
|
+
}), B = () => o((t) => {
|
|
306
313
|
if (t.theme === null)
|
|
307
314
|
throw new Error("Theme is not set. Have you used contract 'theme'?");
|
|
308
315
|
return t.theme;
|
|
309
|
-
}),
|
|
316
|
+
}), V = () => o((t) => t.incSaveCount), _ = () => o((t) => t.incDirtyCount), z = () => o((t) => t.loadedTextContent), K = () => o((t) => t.loadedJsonContent), X = (t) => {
|
|
310
317
|
const e = o(
|
|
311
318
|
(n) => n.setGetTextContentFunction
|
|
312
319
|
);
|
|
313
320
|
S(() => {
|
|
314
321
|
e(t);
|
|
315
322
|
}, [t, e]);
|
|
316
|
-
},
|
|
323
|
+
}, Y = (t) => {
|
|
317
324
|
const e = o(
|
|
318
325
|
(n) => n.setGetJsonContentFunction
|
|
319
326
|
);
|
|
320
327
|
S(() => {
|
|
321
328
|
e(t);
|
|
322
329
|
}, [t, e]);
|
|
323
|
-
},
|
|
330
|
+
}, Z = (t) => {
|
|
324
331
|
const e = o((n) => n.afterSaveCount);
|
|
325
332
|
S(() => {
|
|
326
333
|
e > 0 && t();
|
|
327
334
|
}, [e]);
|
|
328
|
-
},
|
|
335
|
+
}, tt = () => (t, e) => {
|
|
329
336
|
p.use(["meta-player-ui"], ([n]) => {
|
|
330
337
|
var s;
|
|
331
338
|
if (n.version === 0) {
|
|
@@ -334,7 +341,7 @@ const H = () => o((t) => {
|
|
|
334
341
|
}
|
|
335
342
|
(s = n.i) == null || s.previewTextFile(t, e);
|
|
336
343
|
});
|
|
337
|
-
},
|
|
344
|
+
}, et = () => (t, e) => {
|
|
338
345
|
p.use(["meta-player-ui"], ([n]) => {
|
|
339
346
|
var s;
|
|
340
347
|
if (n.version === 0) {
|
|
@@ -345,7 +352,7 @@ const H = () => o((t) => {
|
|
|
345
352
|
});
|
|
346
353
|
};
|
|
347
354
|
let C = 0, b = 0;
|
|
348
|
-
const
|
|
355
|
+
const nt = (t, e) => {
|
|
349
356
|
const n = w(t, e), s = o((i) => i.setSidebarActions);
|
|
350
357
|
S(() => (C++, C > 1 && console.error("Capytale iframe React: Multiple sidebar actions registered: ", C), () => {
|
|
351
358
|
C--;
|
|
@@ -378,7 +385,7 @@ const et = (t, e) => {
|
|
|
378
385
|
}), [n]);
|
|
379
386
|
};
|
|
380
387
|
let m = 0, A = 0;
|
|
381
|
-
const
|
|
388
|
+
const ot = (t, e) => {
|
|
382
389
|
const n = w(t, e), s = o((i) => i.setQuickActions);
|
|
383
390
|
S(() => (m++, m > 1 && console.error("Capytale iframe React: Multiple quick actions registered: ", m), () => {
|
|
384
391
|
m--;
|
|
@@ -411,8 +418,8 @@ const nt = (t, e) => {
|
|
|
411
418
|
}), [n]);
|
|
412
419
|
};
|
|
413
420
|
let v = 0;
|
|
414
|
-
const
|
|
415
|
-
const n = w(t, e), s = o((a) => a.setActivitySettings), i = o((a) => a.activitySettings), u =
|
|
421
|
+
const st = (t, e) => {
|
|
422
|
+
const n = w(t, e), s = o((a) => a.setActivitySettings), i = o((a) => a.activitySettings), u = J("");
|
|
416
423
|
return S(() => (console.log("Mounting useSettings"), v++, v > 1 && console.error("Capytale iframe React: Multiple settings registered: ", v), () => {
|
|
417
424
|
v--;
|
|
418
425
|
}), []), S(() => {
|
|
@@ -429,7 +436,7 @@ const ot = (t, e) => {
|
|
|
429
436
|
s(null);
|
|
430
437
|
};
|
|
431
438
|
}, [n]), i;
|
|
432
|
-
},
|
|
439
|
+
}, it = () => (e) => {
|
|
433
440
|
p.use(["meta-player-ui"], ([n]) => {
|
|
434
441
|
var s;
|
|
435
442
|
if (n.version === 0) {
|
|
@@ -440,21 +447,21 @@ const ot = (t, e) => {
|
|
|
440
447
|
});
|
|
441
448
|
};
|
|
442
449
|
export {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
|
460
467
|
};
|
package/package.json
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@capytale/iframe-react",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"dev": "vite",
|
|
7
|
-
"build": "vite build",
|
|
8
|
-
"clean": "
|
|
9
|
-
"builddev": "vite build -m development",
|
|
10
|
-
"preview": "vite preview",
|
|
11
|
-
"prepublishOnly": "npm run clean && npm run build"
|
|
12
|
-
},
|
|
13
|
-
"main": "dist/index.cjs.js",
|
|
14
|
-
"module": "dist/index.es.js",
|
|
15
|
-
"types": "dist/index.d.ts",
|
|
16
|
-
"exports": {
|
|
17
|
-
".": {
|
|
18
|
-
"types": "./dist/index.d.ts",
|
|
19
|
-
"import": "./dist/index.es.js",
|
|
20
|
-
"require": "./dist/index.cjs.js",
|
|
21
|
-
"default": "./dist/index.es.js"
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"files": [
|
|
25
|
-
"dist"
|
|
26
|
-
],
|
|
27
|
-
"sideEffects": false,
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"@capytale/app-agent": "^1.0.
|
|
30
|
-
"@capytale/contracts": "^1.0.2",
|
|
31
|
-
"zustand": "^5.0.6"
|
|
32
|
-
},
|
|
33
|
-
"peerDependencies": {
|
|
34
|
-
"react": ">=17.0.0 <20",
|
|
35
|
-
"react-dom": ">=17.0.0 <20"
|
|
36
|
-
},
|
|
37
|
-
"devDependencies": {
|
|
38
|
-
"@types/node": "^22.13.1",
|
|
39
|
-
"@types/react": "^18.3.18",
|
|
40
|
-
"@types/react-dom": "^18.3.5",
|
|
41
|
-
"@vitejs/plugin-react": "^4.4.1",
|
|
42
|
-
"react": "^18.3.1",
|
|
43
|
-
"react-dom": "^18.3.1",
|
|
44
|
-
"typescript": "^5.8.3",
|
|
45
|
-
"vite": "^6.3.5",
|
|
46
|
-
"vite-plugin-dts": "^4.5.4"
|
|
47
|
-
},
|
|
48
|
-
"publishConfig": {
|
|
49
|
-
"access": "public"
|
|
50
|
-
}
|
|
51
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@capytale/iframe-react",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "vite",
|
|
7
|
+
"build": "vite build",
|
|
8
|
+
"clean": "",
|
|
9
|
+
"builddev": "vite build -m development",
|
|
10
|
+
"preview": "vite preview",
|
|
11
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
12
|
+
},
|
|
13
|
+
"main": "dist/index.cjs.js",
|
|
14
|
+
"module": "dist/index.es.js",
|
|
15
|
+
"types": "dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.es.js",
|
|
20
|
+
"require": "./dist/index.cjs.js",
|
|
21
|
+
"default": "./dist/index.es.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@capytale/app-agent": "^1.0.10",
|
|
30
|
+
"@capytale/contracts": "^1.0.2",
|
|
31
|
+
"zustand": "^5.0.6"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": ">=17.0.0 <20",
|
|
35
|
+
"react-dom": ">=17.0.0 <20"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^22.13.1",
|
|
39
|
+
"@types/react": "^18.3.18",
|
|
40
|
+
"@types/react-dom": "^18.3.5",
|
|
41
|
+
"@vitejs/plugin-react": "^4.4.1",
|
|
42
|
+
"react": "^18.3.1",
|
|
43
|
+
"react-dom": "^18.3.1",
|
|
44
|
+
"typescript": "^5.8.3",
|
|
45
|
+
"vite": "^6.3.5",
|
|
46
|
+
"vite-plugin-dts": "^4.5.4"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
}
|
|
51
|
+
}
|