@capytale/iframe-react 1.0.0
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 +6 -0
- package/dist/index.cjs.js +30 -0
- package/dist/index.d.ts +316 -0
- package/dist/index.es.js +1053 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("react"),ht=require("@capytale/app-agent");var B={exports:{}},q={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var Oe;function Et(){if(Oe)return q;Oe=1;var t=R,r=Symbol.for("react.element"),a=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,l=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,h={key:!0,ref:!0,__self:!0,__source:!0};function y(S,c,g){var E,m={},k=null,P=null;g!==void 0&&(k=""+g),c.key!==void 0&&(k=""+c.key),c.ref!==void 0&&(P=c.ref);for(E in c)s.call(c,E)&&!h.hasOwnProperty(E)&&(m[E]=c[E]);if(S&&S.defaultProps)for(E in c=S.defaultProps,c)m[E]===void 0&&(m[E]=c[E]);return{$$typeof:r,type:S,key:k,ref:P,props:m,_owner:l.current}}return q.Fragment=a,q.jsx=y,q.jsxs=y,q}var J={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var je;function Rt(){return je||(je=1,process.env.NODE_ENV!=="production"&&function(){var t=R,r=Symbol.for("react.element"),a=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),l=Symbol.for("react.strict_mode"),h=Symbol.for("react.profiler"),y=Symbol.for("react.provider"),S=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),g=Symbol.for("react.suspense"),E=Symbol.for("react.suspense_list"),m=Symbol.for("react.memo"),k=Symbol.for("react.lazy"),P=Symbol.for("react.offscreen"),L=Symbol.iterator,We="@@iterator";function qe(e){if(e===null||typeof e!="object")return null;var n=L&&e[L]||e[We];return typeof n=="function"?n:null}var D=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function T(e){{for(var n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];Je("error",e,o)}}function Je(e,n,o){{var i=D.ReactDebugCurrentFrame,v=i.getStackAddendum();v!==""&&(n+="%s",o=o.concat([v]));var p=o.map(function(d){return String(d)});p.unshift("Warning: "+n),Function.prototype.apply.call(console[e],console,p)}}var Le=!1,Ye=!1,Ue=!1,Ne=!1,Ve=!1,ie;ie=Symbol.for("react.module.reference");function Be(e){return!!(typeof e=="string"||typeof e=="function"||e===s||e===h||Ve||e===l||e===g||e===E||Ne||e===P||Le||Ye||Ue||typeof e=="object"&&e!==null&&(e.$$typeof===k||e.$$typeof===m||e.$$typeof===y||e.$$typeof===S||e.$$typeof===c||e.$$typeof===ie||e.getModuleId!==void 0))}function Ge(e,n,o){var i=e.displayName;if(i)return i;var v=n.displayName||n.name||"";return v!==""?o+"("+v+")":o}function se(e){return e.displayName||"Context"}function O(e){if(e==null)return null;if(typeof e.tag=="number"&&T("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case s:return"Fragment";case a:return"Portal";case h:return"Profiler";case l:return"StrictMode";case g:return"Suspense";case E:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case S:var n=e;return se(n)+".Consumer";case y:var o=e;return se(o._context)+".Provider";case c:return Ge(e,e.render,"ForwardRef");case m:var i=e.displayName||null;return i!==null?i:O(e.type)||"Memo";case k:{var v=e,p=v._payload,d=v._init;try{return O(d(p))}catch{return null}}}return null}var j=Object.assign,M=0,ue,ce,le,fe,de,ve,pe;function ge(){}ge.__reactDisabledLog=!0;function Qe(){{if(M===0){ue=console.log,ce=console.info,le=console.warn,fe=console.error,de=console.group,ve=console.groupCollapsed,pe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ge,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}M++}}function He(){{if(M--,M===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:j({},e,{value:ue}),info:j({},e,{value:ce}),warn:j({},e,{value:le}),error:j({},e,{value:fe}),group:j({},e,{value:de}),groupCollapsed:j({},e,{value:ve}),groupEnd:j({},e,{value:pe})})}M<0&&T("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var K=D.ReactCurrentDispatcher,z;function Y(e,n,o){{if(z===void 0)try{throw Error()}catch(v){var i=v.stack.trim().match(/\n( *(at )?)/);z=i&&i[1]||""}return`
|
|
18
|
+
`+z+e}}var X=!1,U;{var Ke=typeof WeakMap=="function"?WeakMap:Map;U=new Ke}function ye(e,n){if(!e||X)return"";{var o=U.get(e);if(o!==void 0)return o}var i;X=!0;var v=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var p;p=K.current,K.current=null,Qe();try{if(n){var d=function(){throw Error()};if(Object.defineProperty(d.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(d,[])}catch(w){i=w}Reflect.construct(e,[],d)}else{try{d.call()}catch(w){i=w}e.call(d.prototype)}}else{try{throw Error()}catch(w){i=w}e()}}catch(w){if(w&&i&&typeof w.stack=="string"){for(var f=w.stack.split(`
|
|
19
|
+
`),_=i.stack.split(`
|
|
20
|
+
`),b=f.length-1,C=_.length-1;b>=1&&C>=0&&f[b]!==_[C];)C--;for(;b>=1&&C>=0;b--,C--)if(f[b]!==_[C]){if(b!==1||C!==1)do if(b--,C--,C<0||f[b]!==_[C]){var x=`
|
|
21
|
+
`+f[b].replace(" at new "," at ");return e.displayName&&x.includes("<anonymous>")&&(x=x.replace("<anonymous>",e.displayName)),typeof e=="function"&&U.set(e,x),x}while(b>=1&&C>=0);break}}}finally{X=!1,K.current=p,He(),Error.prepareStackTrace=v}var $=e?e.displayName||e.name:"",F=$?Y($):"";return typeof e=="function"&&U.set(e,F),F}function ze(e,n,o){return ye(e,!1)}function Xe(e){var n=e.prototype;return!!(n&&n.isReactComponent)}function N(e,n,o){if(e==null)return"";if(typeof e=="function")return ye(e,Xe(e));if(typeof e=="string")return Y(e);switch(e){case g:return Y("Suspense");case E:return Y("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case c:return ze(e.render);case m:return N(e.type,n,o);case k:{var i=e,v=i._payload,p=i._init;try{return N(p(v),n,o)}catch{}}}return""}var W=Object.prototype.hasOwnProperty,Se={},me=D.ReactDebugCurrentFrame;function V(e){if(e){var n=e._owner,o=N(e.type,e._source,n?n.type:null);me.setExtraStackFrame(o)}else me.setExtraStackFrame(null)}function Ze(e,n,o,i,v){{var p=Function.call.bind(W);for(var d in e)if(p(e,d)){var f=void 0;try{if(typeof e[d]!="function"){var _=Error((i||"React class")+": "+o+" type `"+d+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[d]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw _.name="Invariant Violation",_}f=e[d](n,d,i,o,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(b){f=b}f&&!(f instanceof Error)&&(V(v),T("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",i||"React class",o,d,typeof f),V(null)),f instanceof Error&&!(f.message in Se)&&(Se[f.message]=!0,V(v),T("Failed %s type: %s",o,f.message),V(null))}}}var et=Array.isArray;function Z(e){return et(e)}function tt(e){{var n=typeof Symbol=="function"&&Symbol.toStringTag,o=n&&e[Symbol.toStringTag]||e.constructor.name||"Object";return o}}function nt(e){try{return be(e),!1}catch{return!0}}function be(e){return""+e}function Ce(e){if(nt(e))return T("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",tt(e)),be(e)}var he=D.ReactCurrentOwner,rt={key:!0,ref:!0,__self:!0,__source:!0},Ee,Re;function ot(e){if(W.call(e,"ref")){var n=Object.getOwnPropertyDescriptor(e,"ref").get;if(n&&n.isReactWarning)return!1}return e.ref!==void 0}function at(e){if(W.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function it(e,n){typeof e.ref=="string"&&he.current}function st(e,n){{var o=function(){Ee||(Ee=!0,T("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",n))};o.isReactWarning=!0,Object.defineProperty(e,"key",{get:o,configurable:!0})}}function ut(e,n){{var o=function(){Re||(Re=!0,T("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",n))};o.isReactWarning=!0,Object.defineProperty(e,"ref",{get:o,configurable:!0})}}var ct=function(e,n,o,i,v,p,d){var f={$$typeof:r,type:e,key:n,ref:o,props:d,_owner:p};return f._store={},Object.defineProperty(f._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(f,"_self",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.defineProperty(f,"_source",{configurable:!1,enumerable:!1,writable:!1,value:v}),Object.freeze&&(Object.freeze(f.props),Object.freeze(f)),f};function lt(e,n,o,i,v){{var p,d={},f=null,_=null;o!==void 0&&(Ce(o),f=""+o),at(n)&&(Ce(n.key),f=""+n.key),ot(n)&&(_=n.ref,it(n,v));for(p in n)W.call(n,p)&&!rt.hasOwnProperty(p)&&(d[p]=n[p]);if(e&&e.defaultProps){var b=e.defaultProps;for(p in b)d[p]===void 0&&(d[p]=b[p])}if(f||_){var C=typeof e=="function"?e.displayName||e.name||"Unknown":e;f&&st(d,C),_&&ut(d,C)}return ct(e,f,_,v,i,he.current,d)}}var ee=D.ReactCurrentOwner,Te=D.ReactDebugCurrentFrame;function I(e){if(e){var n=e._owner,o=N(e.type,e._source,n?n.type:null);Te.setExtraStackFrame(o)}else Te.setExtraStackFrame(null)}var te;te=!1;function ne(e){return typeof e=="object"&&e!==null&&e.$$typeof===r}function _e(){{if(ee.current){var e=O(ee.current.type);if(e)return`
|
|
22
|
+
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function ft(e){return""}var we={};function dt(e){{var n=_e();if(!n){var o=typeof e=="string"?e:e.displayName||e.name;o&&(n=`
|
|
24
|
+
|
|
25
|
+
Check the top-level render call using <`+o+">.")}return n}}function xe(e,n){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var o=dt(n);if(we[o])return;we[o]=!0;var i="";e&&e._owner&&e._owner!==ee.current&&(i=" It was passed a child from "+O(e._owner.type)+"."),I(e),T('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',o,i),I(null)}}function ke(e,n){{if(typeof e!="object")return;if(Z(e))for(var o=0;o<e.length;o++){var i=e[o];ne(i)&&xe(i,n)}else if(ne(e))e._store&&(e._store.validated=!0);else if(e){var v=qe(e);if(typeof v=="function"&&v!==e.entries)for(var p=v.call(e),d;!(d=p.next()).done;)ne(d.value)&&xe(d.value,n)}}}function vt(e){{var n=e.type;if(n==null||typeof n=="string")return;var o;if(typeof n=="function")o=n.propTypes;else if(typeof n=="object"&&(n.$$typeof===c||n.$$typeof===m))o=n.propTypes;else return;if(o){var i=O(n);Ze(o,e.props,"prop",i,e)}else if(n.PropTypes!==void 0&&!te){te=!0;var v=O(n);T("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",v||"Unknown")}typeof n.getDefaultProps=="function"&&!n.getDefaultProps.isReactClassApproved&&T("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function pt(e){{for(var n=Object.keys(e.props),o=0;o<n.length;o++){var i=n[o];if(i!=="children"&&i!=="key"){I(e),T("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",i),I(null);break}}e.ref!==null&&(I(e),T("Invalid attribute `ref` supplied to `React.Fragment`."),I(null))}}var Ae={};function Pe(e,n,o,i,v,p){{var d=Be(e);if(!d){var f="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(f+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var _=ft();_?f+=_:f+=_e();var b;e===null?b="null":Z(e)?b="array":e!==void 0&&e.$$typeof===r?(b="<"+(O(e.type)||"Unknown")+" />",f=" Did you accidentally export a JSX literal instead of a component?"):b=typeof e,T("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",b,f)}var C=lt(e,n,o,v,p);if(C==null)return C;if(d){var x=n.children;if(x!==void 0)if(i)if(Z(x)){for(var $=0;$<x.length;$++)ke(x[$],e);Object.freeze&&Object.freeze(x)}else T("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ke(x,e)}if(W.call(n,"key")){var F=O(e),w=Object.keys(n).filter(function(Ct){return Ct!=="key"}),re=w.length>0?"{key: someKey, "+w.join(": ..., ")+": ...}":"{key: someKey}";if(!Ae[F+re]){var bt=w.length>0?"{"+w.join(": ..., ")+": ...}":"{}";T(`A props object containing a "key" prop is being spread into JSX:
|
|
26
|
+
let props = %s;
|
|
27
|
+
<%s {...props} />
|
|
28
|
+
React keys must be passed directly to JSX without using spread:
|
|
29
|
+
let props = %s;
|
|
30
|
+
<%s key={someKey} {...props} />`,re,F,bt,F),Ae[F+re]=!0}}return e===s?pt(C):vt(C),C}}function gt(e,n,o){return Pe(e,n,o,!0)}function yt(e,n,o){return Pe(e,n,o,!1)}var St=yt,mt=gt;J.Fragment=s,J.jsx=St,J.jsxs=mt}()),J}var Fe;function Tt(){return Fe||(Fe=1,process.env.NODE_ENV==="production"?B.exports=Et():B.exports=Rt()),B.exports}var De=Tt();const Ie=t=>{let r;const a=new Set,s=(g,E)=>{const m=typeof g=="function"?g(r):g;if(!Object.is(m,r)){const k=r;r=E??(typeof m!="object"||m===null)?m:Object.assign({},r,m),a.forEach(P=>P(r,k))}},l=()=>r,S={setState:s,getState:l,getInitialState:()=>c,subscribe:g=>(a.add(g),()=>a.delete(g))},c=r=t(s,l,S);return S},_t=t=>t?Ie(t):Ie,wt=t=>t;function xt(t,r=wt){const a=R.useSyncExternalStore(t.subscribe,()=>r(t.getState()),()=>r(t.getInitialState()));return R.useDebugValue(a),a}const $e=t=>{const r=_t(t),a=s=>xt(r,s);return Object.assign(a,r),a},kt=t=>t?$e(t):$e,At=t=>(r,a,s)=>{const l=s.subscribe;return s.subscribe=(y,S,c)=>{let g=y;if(S){const E=(c==null?void 0:c.equalityFn)||Object.is;let m=y(s.getState());g=k=>{const P=y(k);if(!E(m,P)){const L=m;S(m=P,L)}},c!=null&&c.fireImmediately&&S(m,m)}return l(g)},t(r,a,s)},Pt=At,u=kt()(Pt(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:r=>{t({getTextContentFunction:r})},setGetJsonContentFunction:r=>{t({getJsonContentFunction:r})},setSidebarActions:r=>{t({sidebarActions:r})},setQuickActions:r=>{t({quickActions:r})},setActivitySettings:r=>{t({activitySettings:r})},incSaveCount:()=>t(r=>({saveCount:r.saveCount+1})),incDirtyCount:()=>t(r=>({isDirtyCount:r.isDirtyCount+1}))}))),Ot=["meta-player-events:1","meta-player-ui:1","mode:1","reload:1","theme:1","workflow:1","simple-content(text):1","simple-content(json):1","simple-binary-data(text):1","simple-content-eval(text):1","simple-content-eval(json):1"],Me={"mode:1":{setMode:t=>{u.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){u.setState({theme:null});return}if(t!=="light"&&t!=="dark"){console.warn(`Invalid theme: ${t}. Expected 'light' or 'dark'.`),u.setState({theme:null});return}u.setState({theme:t})}},"workflow:1":{setWorkflow:t=>{u.setState({workflow:t})}},"simple-content(text):1":{contentSaved:()=>{u.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>u.getState().getTextContentFunction(),loadContent:t=>{u.setState({loadedTextContent:t})}},"simple-content(json):1":{contentSaved:()=>{u.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>u.getState().getJsonContentFunction(),loadContent:t=>{u.setState({loadedJsonContent:t})}},"simple-binary-data(text):1":{contentSaved:()=>{u.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>u.getState().getTextContentFunction(),loadContent:t=>{u.setState({loadedTextContent:t})}},"simple-content-eval(text):1":{contentSaved:()=>{u.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>u.getState().getTextContentFunction(),loadContent:t=>{u.setState({loadedTextContent:t})},getAssignmentContent:()=>{throw new Error("getAssignmentContent is not implemented for simple-content-eval(text)")}},"simple-content-eval(json):1":{contentSaved:()=>{u.setState(t=>({afterSaveCount:t.afterSaveCount+1}))},getContent:()=>u.getState().getJsonContentFunction(),loadContent:t=>{u.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 a=u.getState().quickActions[t];a?a():console.error(`Quick action not found: ${t}`)}else{const a=u.getState().sidebarActions[t];a?a():console.error(`Sidebar action not found: ${t}`)}},executeFileUpload(t,r){if(t.startsWith("qa")){const s=u.getState().quickActions[t];s?s(r):console.error(`Quick action not found: ${t}`)}else{const s=u.getState().sidebarActions[t];s?s(r):console.error(`Sidebar action not found: ${t}`)}},updateSettings(t){u.setState({activitySettings:t})}},"meta-player-events:1":{handleEvent(t){t==="all-loaded"&&u.setState({ready:!0})}}},A=ht.getSocket();function jt(t){for(const r of t){if(!Ot.includes(r)){console.warn(`Contract ${r} is not implemented in Capytale. Skipping plug.`);continue}if(!(r in Me)){console.warn(`Contract handler for ${r} is not defined. Skipping plug.`);continue}const a=Me[r];A.plug([r],([])=>[a])}A.plugsDone();for(const r of["simple-content(text):1","simple-content(json):1","simple-binary-data(text):1","simple-content-eval(text):1"])if(console.log(`Contract ${r} is being subscribed to content changes.`),t.includes(r)){console.log(`Subscribing to content changes for contract ${r}`);const a=r.split(":")[0];A.use([a],([s])=>{u.subscribe(l=>l.isDirtyCount,()=>{var l;(l=s.i)==null||l.contentChanged(),console.log(`Content changed for contract ${a}`)})})}}function Ft({children:t,contracts:r,loadOnlyWhenReady:a=!0}){const s=u(l=>l.ready);return R.useEffect(()=>{const l=r.includes("meta-player-events:1")?r:[...r,"meta-player-events:1"];jt(l)},[]),a&&!s?De.jsx("div",{className:"container",children:"Chargement en cours..."}):De.jsx("div",{className:"container",children:t})}const Dt=()=>u(t=>{if(t.mode===null)throw new Error("Mode is not set. Have you used contract 'mode'?");return t.mode}),It=()=>u(t=>{if(t.workflow===null)throw new Error("Workflow is not set. Have you used contract 'workflow'?");return t.workflow}),$t=()=>u(t=>{if(t.theme===null)throw new Error("Theme is not set. Have you used contract 'theme'?");return t.theme}),Mt=()=>u(t=>t.incSaveCount),Wt=()=>u(t=>t.incDirtyCount),qt=()=>u(t=>t.loadedTextContent),Jt=()=>u(t=>t.loadedJsonContent),Lt=t=>{const r=u(a=>a.setGetTextContentFunction);R.useEffect(()=>{r(t)},[t,r])},Yt=t=>{const r=u(a=>a.setGetJsonContentFunction);R.useEffect(()=>{r(t)},[t,r])},Ut=t=>{const r=u(a=>a.afterSaveCount);R.useEffect(()=>{r>0&&t()},[r])},Nt=()=>(t,r)=>{A.use(["meta-player-ui"],([a])=>{var s;if(a.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(s=a.i)==null||s.previewTextFile(t,r)})},Vt=()=>(t,r)=>{A.use(["meta-player-ui"],([a])=>{var s;if(a.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(s=a.i)==null||s.previewImageFile(t,r)})};let G=0,oe=0;const Bt=(t,r)=>{const a=R.useMemo(t,r),s=u(l=>l.setSidebarActions);R.useEffect(()=>(G++,G>1&&console.error("Capytale iframe React: Multiple sidebar actions registered: ",G),()=>{G--}),[]),R.useEffect(()=>(A.use(["meta-player-ui"],([l])=>{var S;if(l.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}oe++;const h=a.map((c,g)=>({type:c.type,title:c.title,icon:c.icon,id:`sa-${oe}-${g}`,...c.type==="file-upload"?{accept:c.accept}:{}})),y={};a.forEach((c,g)=>{y[`sa-${oe}-${g}`]=c.action}),(S=l.i)==null||S.setSidebarActionButtons(h),s(y)}),()=>{s({}),A.use(["meta-player-ui"],([l])=>{var h;if(l.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(h=l.i)==null||h.setSidebarActionButtons([])})}),[a])};let Q=0,ae=0;const Gt=(t,r)=>{const a=R.useMemo(t,r),s=u(l=>l.setQuickActions);R.useEffect(()=>(Q++,Q>1&&console.error("Capytale iframe React: Multiple quick actions registered: ",Q),()=>{Q--}),[]),R.useEffect(()=>(A.use(["meta-player-ui"],([l])=>{var S;if(l.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}ae++;const h=a.map((c,g)=>({type:c.type,title:c.title,icon:c.icon,id:`qa-${ae}-${g}`,...c.type==="file-upload"?{accept:c.accept}:{}})),y={};a.forEach((c,g)=>{y[`qa-${ae}-${g}`]=c.action}),(S=l.i)==null||S.setQuickActionButtons(h),s(y)}),()=>{s({}),A.use(["meta-player-ui"],([l])=>{var h;if(l.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(h=l.i)==null||h.setQuickActionButtons([])})}),[a])};let H=0;const Qt=(t,r)=>{const a=R.useMemo(t,r),s=u(y=>y.setActivitySettings),l=u(y=>y.activitySettings),h=R.useRef("");return R.useEffect(()=>(console.log("Mounting useSettings"),H++,H>1&&console.error("Capytale iframe React: Multiple settings registered: ",H),()=>{H--}),[]),R.useEffect(()=>{const y=JSON.stringify(a);if(y!==h.current)return h.current=y,A.use(["meta-player-ui"],([S])=>{var c;if(S.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}console.log("Updating settings UI in MetaPlayer",a),(c=S.i)==null||c.setSettingsUI(a)}),()=>{s(null)}},[a]),l},Ht=()=>r=>{A.use(["meta-player-ui"],([a])=>{var s;if(a.version===0){console.error("Le MétaPlayer ne supporte pas le contrat meta-player-ui");return}(s=a.i)==null||s.showToast(r)})};exports.Capytale=Ft;exports.useAfterSaveAction=Ut;exports.useJsonContentSaveFunction=Yt;exports.useLoadedJsonContent=Jt;exports.useLoadedTextContent=qt;exports.useMode=Dt;exports.useNotifyIsDirty=Wt;exports.usePreviewImageFile=Vt;exports.usePreviewTextFile=Nt;exports.useQuickActions=Gt;exports.useRequestSave=Mt;exports.useSettings=Qt;exports.useShowToast=Ht;exports.useSidebarActions=Bt;exports.useTextContentSaveFunction=Lt;exports.useTheme=$t;exports.useWorkflow=It;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { CapytaleContracts } from '@capytale/contracts';
|
|
2
|
+
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
3
|
+
import { PropsWithChildren } from 'react';
|
|
4
|
+
|
|
5
|
+
export declare type Action = {
|
|
6
|
+
type: "action";
|
|
7
|
+
title: string;
|
|
8
|
+
icon: string;
|
|
9
|
+
action: () => any;
|
|
10
|
+
} | {
|
|
11
|
+
type: "file-upload";
|
|
12
|
+
accept?: string;
|
|
13
|
+
title: string;
|
|
14
|
+
icon: string;
|
|
15
|
+
action: (file: File) => any;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
declare type ActivitySettings = {
|
|
19
|
+
[id: string]: ActivitySettingsSection;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
declare type ActivitySettingsFormSection = {
|
|
23
|
+
type: "form";
|
|
24
|
+
fields: {
|
|
25
|
+
[name: string]: (ActivitySettingsRange | ActivitySettingsInput | ActivitySettingsTextArea | ActivitySettingsOption | ActivitySettingsSelect) & {
|
|
26
|
+
label: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
declare type ActivitySettingsInput = {
|
|
32
|
+
type: "input";
|
|
33
|
+
inputType: "color" | "date" | "datetime-local" | "email" | "month" | "number" | "password" | "search" | "tel" | "text" | "time" | "url" | "week";
|
|
34
|
+
value: string | number;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
declare type ActivitySettingsMultipleOptionsSection = {
|
|
38
|
+
type: "checkboxes" | "switches";
|
|
39
|
+
options: {
|
|
40
|
+
label: string;
|
|
41
|
+
name: string;
|
|
42
|
+
}[];
|
|
43
|
+
selectedOptionNames: string[];
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
declare type ActivitySettingsOption = {
|
|
47
|
+
type: "checkbox" | "switch";
|
|
48
|
+
value: boolean;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
declare type ActivitySettingsRadioOptionsSection = {
|
|
52
|
+
type: "radio";
|
|
53
|
+
options: {
|
|
54
|
+
label: string;
|
|
55
|
+
name: string;
|
|
56
|
+
}[];
|
|
57
|
+
selectedOptionName: string | null;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
declare type ActivitySettingsRange = {
|
|
61
|
+
type: "range";
|
|
62
|
+
min: number;
|
|
63
|
+
max: number;
|
|
64
|
+
step?: number;
|
|
65
|
+
value: number;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
declare type ActivitySettingsSection = (ActivitySettingsMultipleOptionsSection | ActivitySettingsRadioOptionsSection | ActivitySettingsFormSection) & {
|
|
69
|
+
title: string;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
declare type ActivitySettingsSelect = {
|
|
73
|
+
type: "select";
|
|
74
|
+
options: {
|
|
75
|
+
label: string;
|
|
76
|
+
name: string;
|
|
77
|
+
}[];
|
|
78
|
+
selectedOptionName: string;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
declare type ActivitySettingsTextArea = {
|
|
82
|
+
type: "textarea";
|
|
83
|
+
value: string;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
declare type AddId<C, I extends {
|
|
87
|
+
name: string;
|
|
88
|
+
variant?: string;
|
|
89
|
+
}> = I extends {
|
|
90
|
+
variant: string;
|
|
91
|
+
} ? C & {
|
|
92
|
+
name: `${I['name']}(${I['variant']})`;
|
|
93
|
+
} : C & {
|
|
94
|
+
name: I['name'];
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Un type utilitaire pour ajouter les propriétés d'identifications à un contrat
|
|
99
|
+
* ou à un tuple de contrats.
|
|
100
|
+
*
|
|
101
|
+
* @param C Le type de contrat ou de tuple de contrats.
|
|
102
|
+
* @param I Le nom et éventuellement la variante à ajouter.
|
|
103
|
+
*/
|
|
104
|
+
declare type AddIdData<C, I extends {
|
|
105
|
+
name: string;
|
|
106
|
+
variant?: string;
|
|
107
|
+
}> = C extends {}[] ? {
|
|
108
|
+
[Index in keyof C]: AddId<C[Index], I>;
|
|
109
|
+
} : AddId<C, I>;
|
|
110
|
+
|
|
111
|
+
declare type AllContracts = CapytaleContracts & CustomContracts;
|
|
112
|
+
|
|
113
|
+
export declare function Capytale({ children, contracts, loadOnlyWhenReady, }: PropsWithChildren<CapytaleProps>): JSX_2.Element;
|
|
114
|
+
|
|
115
|
+
declare type CapytaleProps = {
|
|
116
|
+
contracts: (keyof AllContracts)[];
|
|
117
|
+
loadOnlyWhenReady?: boolean;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Un type utilitaire pour indexer un ensemble de contrats par leur identifiant complet.
|
|
122
|
+
*
|
|
123
|
+
* @param T Un tuple de contrats.
|
|
124
|
+
*/
|
|
125
|
+
declare type CollectionOf<T extends {
|
|
126
|
+
name: string;
|
|
127
|
+
version: number;
|
|
128
|
+
}[]> = Indexed<IdContractTuple<T>>;
|
|
129
|
+
|
|
130
|
+
declare type CustomContracts = CollectionOf<[
|
|
131
|
+
AddIdData<MetaPlayerUIV1, {
|
|
132
|
+
name: "meta-player-ui";
|
|
133
|
+
}>,
|
|
134
|
+
AddIdData<MetaPlayerEventsV1, {
|
|
135
|
+
name: "meta-player-events";
|
|
136
|
+
}>
|
|
137
|
+
]>;
|
|
138
|
+
|
|
139
|
+
declare type IdContractTuple<T extends {
|
|
140
|
+
name: string;
|
|
141
|
+
version: number;
|
|
142
|
+
}[]> = {
|
|
143
|
+
[Index in keyof T]: [IdOf<T[Index]>, T[Index]];
|
|
144
|
+
}[number];
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Un type qui représente un identifiant de contrat.
|
|
148
|
+
* Il est composé du nom du contrat et de sa version.
|
|
149
|
+
* Exemple: `content:1`
|
|
150
|
+
*
|
|
151
|
+
* @param C Le type de contrat.
|
|
152
|
+
*/
|
|
153
|
+
declare type IdOf<C extends {
|
|
154
|
+
name: string;
|
|
155
|
+
version: number;
|
|
156
|
+
}> = `${C['name']}:${C['version']}`;
|
|
157
|
+
|
|
158
|
+
declare type Indexed<L extends [string, unknown]> = {
|
|
159
|
+
[I in L[0]]: Extract<L, [I, any]>[1];
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
declare type MetaPlayerEventsV1 = {
|
|
163
|
+
version: 1;
|
|
164
|
+
/**
|
|
165
|
+
* L'interface qui expose le *MetaPlayer* à l'*Application*.
|
|
166
|
+
*/
|
|
167
|
+
metaplayer: {};
|
|
168
|
+
/**
|
|
169
|
+
* L'interface qui expose l'*Application* au *MetaPlayer*.
|
|
170
|
+
*/
|
|
171
|
+
application: {
|
|
172
|
+
/**
|
|
173
|
+
* Le *MetaPlayer* appelle cette méthode pour indiquer à l'*Application* qu'un événement a eu lieu.
|
|
174
|
+
*
|
|
175
|
+
* @param event l'identifiant de l'événement qui a eu lieu (pour l'instant seulement "all-loaded", qui indique que tous les contrats liés au chargement initial de l'activité ont été appelés par le *MetaPlayer*).
|
|
176
|
+
*/
|
|
177
|
+
handleEvent(event: "all-loaded" | (string & {})): void;
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
declare type MetaPlayerUIV1 = {
|
|
182
|
+
version: 1;
|
|
183
|
+
/**
|
|
184
|
+
* L'interface qui expose le *MetaPlayer* à l'*Application*.
|
|
185
|
+
*/
|
|
186
|
+
metaplayer: {
|
|
187
|
+
/**
|
|
188
|
+
* L'*Application* peut appeler cette méthode pour définir les boutons d'action rapide.
|
|
189
|
+
* @param actions Un tableau d'objets décrivant les boutons d'action rapide.
|
|
190
|
+
*/
|
|
191
|
+
setQuickActionButtons(actions: QuickActionInfo[]): void;
|
|
192
|
+
/**
|
|
193
|
+
* L'*Application* peut appeler cette méthode pour définir les boutons d'action dans la barre latérale.
|
|
194
|
+
* @param actions Un tableau d'objets décrivant les boutons d'action dans la barre latérale.
|
|
195
|
+
*/
|
|
196
|
+
setSidebarActionButtons(actions: QuickActionInfo[]): void;
|
|
197
|
+
/**
|
|
198
|
+
* L'*Application* peut appeler cette méthode pour définir l'interface utilisateur des paramètres de l'activité.
|
|
199
|
+
* @param settingsUI Un objet décrivant l'interface utilisateur des paramètres de l'activité.
|
|
200
|
+
*/
|
|
201
|
+
setSettingsUI(settingsUI: ActivitySettings | null): void;
|
|
202
|
+
/**
|
|
203
|
+
* L'*Application* peut appeler cette méthode pour demander au *MetaPlayer* de prévisualiser un fichier texte.
|
|
204
|
+
* @param title le titre du fichier texte à prévisualiser.
|
|
205
|
+
* @param content le contenu du fichier texte à prévisualiser.
|
|
206
|
+
*/
|
|
207
|
+
previewTextFile(title: string, content: string): void;
|
|
208
|
+
/**
|
|
209
|
+
* L'*Application* peut appeler cette méthode pour demander au *MetaPlayer* de prévisualiser un fichier image.
|
|
210
|
+
* @param title le titre du fichier image à prévisualiser.
|
|
211
|
+
* @param url l'URL du fichier image à prévisualiser.
|
|
212
|
+
*/
|
|
213
|
+
previewImageFile(title: string, url: string): void;
|
|
214
|
+
/**
|
|
215
|
+
* L'*Application* peut appeler cette méthode pour afficher une notification.
|
|
216
|
+
* @param message Un objet décrivant le message à afficher.
|
|
217
|
+
*/
|
|
218
|
+
showToast(message: MPToastMessage): void;
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* L'interface qui expose l'*Application* au *MetaPlayer*.
|
|
222
|
+
*/
|
|
223
|
+
application: {
|
|
224
|
+
/**
|
|
225
|
+
* Le *MetaPlayer* appelle cette méthode pour indiquer à l'*Application* que l'utilisateur a cliqué sur un bouton de type action.
|
|
226
|
+
*
|
|
227
|
+
* @param id l'identifiant de l'action associée au bouton cliqué.
|
|
228
|
+
*/
|
|
229
|
+
executeAction(id: string): void;
|
|
230
|
+
/**
|
|
231
|
+
* Le *MetaPlayer* appelle cette méthode pour indiquer à l'*Application* que l'utilisateur a cliqué sur un bouton de type file-upload.
|
|
232
|
+
*
|
|
233
|
+
* @param id l'identifiant de l'action associée au bouton cliqué.
|
|
234
|
+
* @param file le fichier chargé par l'utilisateur.
|
|
235
|
+
*/
|
|
236
|
+
executeFileUpload(id: string, file: File): void;
|
|
237
|
+
/**
|
|
238
|
+
* Le *MetaPlayer* appelle cette méthode pour indiquer à l'*Application* que l'utilisateur a modifié les paramètres de l'activité.
|
|
239
|
+
*
|
|
240
|
+
* @param settingsUI Un objet décrivant l'interface utilisateur des paramètres de l'activité.
|
|
241
|
+
*/
|
|
242
|
+
updateSettings(settingsUI: ActivitySettings | null): void;
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
declare type MPToastMessage = {
|
|
247
|
+
/**
|
|
248
|
+
* Severity of the message.
|
|
249
|
+
*/
|
|
250
|
+
severity?: "error" | "success" | "info" | "warn" | "secondary" | "contrast";
|
|
251
|
+
/**
|
|
252
|
+
* Summary content of the message.
|
|
253
|
+
*/
|
|
254
|
+
summary?: string;
|
|
255
|
+
/**
|
|
256
|
+
* Detail content of the message.
|
|
257
|
+
*/
|
|
258
|
+
detail?: string;
|
|
259
|
+
/**
|
|
260
|
+
* Whether the message can be closed manually using the close icon.
|
|
261
|
+
*/
|
|
262
|
+
closable?: boolean;
|
|
263
|
+
/**
|
|
264
|
+
* When enabled, message is not removed automatically.
|
|
265
|
+
*/
|
|
266
|
+
sticky?: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Delay in milliseconds to close the message automatically.
|
|
269
|
+
*/
|
|
270
|
+
life?: number;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
declare type QuickActionInfo = {
|
|
274
|
+
title: string;
|
|
275
|
+
icon: string;
|
|
276
|
+
id: string;
|
|
277
|
+
} & ({
|
|
278
|
+
type: "action";
|
|
279
|
+
} | {
|
|
280
|
+
type: "file-upload";
|
|
281
|
+
accept?: string;
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
export declare const useAfterSaveAction: (fn: () => any) => void;
|
|
285
|
+
|
|
286
|
+
export declare const useJsonContentSaveFunction: (fn: () => any) => void;
|
|
287
|
+
|
|
288
|
+
export declare const useLoadedJsonContent: () => any;
|
|
289
|
+
|
|
290
|
+
export declare const useLoadedTextContent: () => string | null;
|
|
291
|
+
|
|
292
|
+
export declare const useMode: () => "assignment" | "create" | "review" | "view";
|
|
293
|
+
|
|
294
|
+
export declare const useNotifyIsDirty: () => () => void;
|
|
295
|
+
|
|
296
|
+
export declare const usePreviewImageFile: () => (title: string, url: string) => void;
|
|
297
|
+
|
|
298
|
+
export declare const usePreviewTextFile: () => (title: string, content: string) => void;
|
|
299
|
+
|
|
300
|
+
export declare const useQuickActions: (actionsFn: () => Action[], deps: readonly unknown[]) => void;
|
|
301
|
+
|
|
302
|
+
export declare const useRequestSave: () => () => void;
|
|
303
|
+
|
|
304
|
+
export declare const useSettings: (settingsUiFn: () => (ActivitySettings | null), deps: readonly unknown[]) => ActivitySettings | null;
|
|
305
|
+
|
|
306
|
+
export declare const useShowToast: () => (message: MPToastMessage) => void;
|
|
307
|
+
|
|
308
|
+
export declare const useSidebarActions: (actionsFn: () => Action[], deps: readonly unknown[]) => void;
|
|
309
|
+
|
|
310
|
+
export declare const useTextContentSaveFunction: (fn: () => string | null | Promise<string | null>) => void;
|
|
311
|
+
|
|
312
|
+
export declare const useTheme: () => "light" | "dark";
|
|
313
|
+
|
|
314
|
+
export declare const useWorkflow: () => "current" | "finished" | "corrected";
|
|
315
|
+
|
|
316
|
+
export { }
|