Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphand-react

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphand-react - npm Package Compare versions

Comparing version 0.0.18-beta to 0.0.19-beta

2

dist/index.js

@@ -1,2 +0,2 @@

var e=require("fast-deep-equal/react"),t=require("react"),r=require("bson"),n=require("lodash"),o=require("flatted"),i=require("react/jsx-runtime");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=/*#__PURE__*/u(e),l=/*#__PURE__*/u(t),a=/*#__PURE__*/u(n);function c(){return c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c.apply(this,arguments)}function d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(e,t)}function f(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var p=/*#__PURE__*/function(e){var t,r;function n(t){var r;return(r=e.call(this,t)||this).state={res:void 0,loading:!1,error:null},r.setRes=function(e,t){void 0===t&&(t=null);try{return Promise.resolve(new Promise(function(n){!1!==r.props.debounce?(r.state.loading||r.setState({loading:!0}),r.debounceTimeout&&clearTimeout(r.debounceTimeout),r.debounceTimeout=setTimeout(function(){r.setState({res:e,loading:!1,error:t},n)},r.props.debounce)):r.setState({res:e,loading:!1,error:t},n)}))}catch(e){return Promise.reject(e)}},r.update=function(){try{var e=function(){r.updating=!1};r.updating=!0,r.setState({loading:!0});var t=r.props.promise,n=f(function(){function e(){var e=function(){var e,t;if(o)return null!=(e=r.subscription)&&e.unsubscribe&&r.subscription.unsubscribe(),r.props.subscribe&&null!=(t=n)&&t.subscribe&&(r.subscription=n.subscribe(r.setRes)),Promise.resolve(new Promise(function(e){return r.setRes(n,e)})).then(function(){});var i=function(){if(r.state.loading)return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})}();return i&&i.then?i.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}var n,o=!0,i=r.props.checkUpdate?Promise.resolve(Promise.all([t,r.props.promise])).then(function(e){var t=e[0];o=!s.default(t,e[1]),n=t}):Promise.resolve(t).then(function(e){n=e});return i&&i.then?i.then(e):e()},function(){return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})});return Promise.resolve(n&&n.then?n.then(e):e())}catch(e){return Promise.reject(e)}},t.promise&&void 0===t.promise.then&&(r.state.res=t.promise),r}r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,d(t,r);var o=n.prototype;return o.componentDidMount=function(){try{var e=this,t=f(function(){function t(){var t,n;null!=(t=e.subscription)&&t.unsubscribe&&e.subscription.unsubscribe(),e.props.subscribe&&null!=(n=r)&&n.subscribe&&(e.subscription=r.subscribe(e.setRes))}var r=e.props.promise,n=function(){var t,n;if(e.props.promise&&void 0!==e.props.promise.then||!s.default(null==(t=e.state.res)?void 0:t.query,null==(n=e.props.promise)?void 0:n.query))return Promise.resolve(e.props.promise).then(function(t){e.setRes(r=t)})}();return n&&n.then?n.then(t):t()},function(t){console.error(t),e.setRes(void 0,t)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},o.getUpdateKey=function(e){var t,r;if(e.updateKey)return e.updateKey;var n,o,i=[];return null!=(t=e.promise)&&t.model&&i.push(null==(n=e.promise)?void 0:n.model),null!=(r=e.promise)&&r.query&&i.push(null==(o=e.promise)?void 0:o.query),i},o.componentDidUpdate=function(e,t){try{var r=this;return(!s.default(r.getUpdateKey(r.props),r.getUpdateKey(e))||r.props.update&&!r.updating)&&r.update(),Promise.resolve()}catch(e){return Promise.reject(e)}},o.componentWillUnmount=function(){var e;null!=(e=this.subscription)&&e.unsubscribe&&this.subscription.unsubscribe()},o.renderCallback=function(){var e=this.props.callback||this.props.children;return"function"==typeof e?e(this.state.res,this.state.loading,this.state.error):e},o.renderFallback=function(){var e=this.props.fallback;return"function"==typeof e?e(this.state.res,this.state.loading,this.state.error):e},o.render=function(){var e=void 0===this.state.res?this.renderFallback():this.renderCallback();return void 0!==e?e:null},n}(l.default.Component);p.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!1,checkUpdate:!1,debounce:!1};var v=function(e){var n,u,d,f=e.template,p=e.children,v=e.fields,m=e.model,b=e.instance,h=e.map,y=e.controls,g=e.translatable,P=e.values,j=e.fieldsOptions,O=e.onChange,S=e.onSubmit,k=e.processErrors,E=e.resetAfterSubmit,C=!(!P||!O);m=m||(null==b?void 0:b.constructor),v="function"==typeof v?v(m.fields):v||m.fields;var V=t.useRef(b||(null==(n=m)?void 0:n.hydrate(P))||null),w=t.useRef([]),F=t.useRef(),R=t.useRef((null==(u=V.current)?void 0:u._id)||(new r.ObjectID).toString()),_=t.useState(!1),q=_[0],x=_[1],I=t.useState([]),L=I[0],T=I[1],A=t.useState(P||(null==(d=V.current)?void 0:d.toJSON())||{}),G=A[0],U=A[1],K=t.useState(!0),M=K[0],D=K[1];P=C?P:G;var $=R.current;t.useEffect(function(){try{var e=function(){M&&D(!1)},t=function(){if(m)return Promise.resolve(m.init()).then(function(){})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(e){return Promise.reject(e)}},[]);var B=function(e){var t;return null==(t=w.current)?void 0:t.includes(e)},N={id:$,values:P,formRef:F.current,isModified:B},z=function(){/*#__PURE__*/return i.jsxs(l.default.Fragment,{children:[W(),"function"==typeof y?y(e):y||null]})},J=function(e,t,r,n){void 0===r&&(r={}),void 0===n&&(n=!0);var o=Object.assign({},r,e.inputOptions,j&&j[t]);if(o.hidden)return null;var i=P[t],u=n?e.getter(i,V.current,t):i,s={errors:L.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)}),value:u,onChange:function(e){return Q(t,e)},options:o,id:$+":"+t,slug:t,handleSubmit:H};return e.renderInput(s)},W=function(){var e;return(h=null!=(e=h)?e:Object.keys(v).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)})).map(function(e){return J(v[e],e)})},H=function(t){try{t&&(t.preventDefault(),t.stopPropagation());var r=function(t,r){try{var n=(i=w.current.reduce(function(t,r){var n=a.default.get(P,r),o=a.default.get(e.values||{},r);return void 0===n&&o!==n?(t.$unset=t.$unset||{},t.$unset[r]=!0,delete t[r]):t[r]=n,t},{}),x(!0),T([]),null!=(o=m)&&o.beforeFormSubmit&&m.beforeFormSubmit(i,N),Promise.resolve(S(i)).then(function(){var e;(E=null!=(e=E)?e:!!V.current)&&(void 0).resetInstance().then(function(){return(void 0).resetValues()}),x(!1)}))}catch(e){return r(e)}var o,i;return n&&n.then?n.then(void 0,r):n}(0,function(e){var t=k(e.graphandErrors||[]);x(!1),T(t)});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Q=function(e,t){try{var r,n=X(e,t);return B(e)&&n?w.current=w.current.filter(function(t){return t!==e}):n||B(e)||w.current.push(e),Promise.resolve(function(e,t){void 0===t&&(t=!1);try{var r,n=function(){var e;null!=(e=m)&&e.afterFormChange&&m.afterFormChange(P,N)};void 0===e&&(e=P),null!=(r=m)&&r.beforeFormChange&&m.beforeFormChange(e,N);var o=function(){if(C)return Promise.resolve(O(e,t)).then(function(){});U(e)}();return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}}(c({},P,(r={},r[e]=t,r)))).then(function(){})}catch(e){return Promise.reject(e)}},X=function(e,t){var r,n=null==(r=V.current)?void 0:r.get(e,!0),i=o.stringify(n),u=o.stringify(t);return s.default(i,u)},Y=f||p||/*#__PURE__*/l.default.createElement(z);/*#__PURE__*/return l.default.isValidElement(Y)||Array.isArray(Y)&&Y.every(function(e){/*#__PURE__*/return l.default.isValidElement(e)})?/*#__PURE__*/i.jsx("form",{ref:F,onSubmit:H,children:Y}):Y({fields:Object.keys(v).reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=function(e,r){return void 0===e&&(e={}),J(v[t],t,e,r)},r))},{render:function(e,t,r){return void 0===t&&(t={}),J(v[e],e,t,r)},renderDefault:W}),isLoading:q,isInitializing:M,errors:L,handleSubmit:H,isTranslatable:g,formRef:F,values:P,modified:w.current||[]})};v.defaultProps={model:null,fields:null,map:null,fieldsOptions:{},getFieldOptions:null,instance:null,errors:[],onSubmit:function(){return null},submitLabel:"Valider",template:null,resetAfterSubmit:void 0,preventLeave:!1,translatable:!1,values:void 0,onChange:void 0,processErrors:function(e){return e},controls:function(e){return[/*#__PURE__*/i.jsx("button",{className:"btn btn-primary",type:"submit",children:e.submitLabel})]}};var m={options:{types:{}},__construct:function(e,t){void 0===t&&(t={});var r=e.constructor.lib,n=r.GraphandModelPromise,o=r.GraphandModel,i=r.GraphandModelListPromise,u=r.GraphandModelList,s=r.GraphandField,a=r.AggregationExecutor;s.InputComponent=null,s.ViewComponent=null,n.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/l.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/l.default.createElement(p,c({promise:this,callback:e,fallback:t},r))},o.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/l.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/l.default.createElement(p,c({promise:this,callback:e,fallback:t},r))},i.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/l.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/l.default.createElement(p,c({promise:this,callback:e,fallback:t},r))},u.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/l.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/l.default.createElement(p,c({promise:this,callback:e,fallback:t},r))},a.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/l.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/l.default.createElement(p,c({promise:this,callback:e,fallback:t},r))},s.prototype.renderInput=function(e){void 0===e&&(e={});var r,n=Object.getPrototypeOf(this).constructor,o=this.InputComponent||n.InputComponent;return o||(o=null==(r=t.fields[n.__fieldType])?void 0:r.input),o?/*#__PURE__*/l.default.createElement(o,c({},e,{field:this})):null},s.prototype.renderView=function(e){void 0===e&&(e={});var r,n=Object.getPrototypeOf(this).constructor,o=this.ViewComponent||n.ViewComponent;return o||(o=null==(r=t.fields[n.__fieldType])?void 0:r.view),o?/*#__PURE__*/l.default.createElement(o,c({},e,{field:this})):"string"==typeof e.value?e.value:null},o.prototype.renderFieldView=function(e,t,r){void 0===r&&(r={});var n=Object.getPrototypeOf(this).constructor;t&&"object"==typeof t&&(Object.assign(r,t),t=void 0);var o=n.fields&&n.fields[e];return(null==o?void 0:o.renderView({value:this.get(e,t),item:this,slug:e,options:r}))||null},o.prototype.renderFieldInput=function(e,t,r){void 0===r&&(r={});var n=Object.getPrototypeOf(this).constructor;t&&"object"==typeof t&&(Object.assign(r,t),t=void 0);var o=n.fields&&n.fields[e];return(null==o?void 0:o.renderInput({value:this.get(e,t),item:this,slug:e,options:r}))||null}}};exports.GraphandForm=v,exports.GraphandPluginReact=m,exports.PromiseSuspense=p,exports.default=m,exports.useList=function(e,r,n){void 0===r&&(r={});var o,i=t.useState([]),u=i[0],s=i[1],l=t.useState(!1)[0];return t.useEffect(function(){return e.getList(r).then(s).then(function(e){return e&&(o=e.subscribe(s))}),function(){var e;return null==(e=o)?void 0:e.unsubscribe()}}),[u,l]};
var e=require("fast-deep-equal/react"),t=require("react"),r=require("bson"),n=require("lodash"),o=require("flatted"),i=require("react/jsx-runtime");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=/*#__PURE__*/u(e),l=/*#__PURE__*/u(t),a=/*#__PURE__*/u(n);function c(){return c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c.apply(this,arguments)}function d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(e,t)}function f(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var p=/*#__PURE__*/function(e){var t,r;function n(t){var r;return(r=e.call(this,t)||this).state={res:void 0,loading:!1,error:null},r.setRes=function(e,t){void 0===t&&(t=null);try{return Promise.resolve(new Promise(function(n){!1!==r.props.debounce?(r.state.loading||r.setState({loading:!0}),r.debounceTimeout&&clearTimeout(r.debounceTimeout),r.debounceTimeout=setTimeout(function(){r.setState({res:e,loading:!1,error:t},n)},r.props.debounce)):r.setState({res:e,loading:!1,error:t},n)}))}catch(e){return Promise.reject(e)}},r.update=function(){try{var e=function(){r.updating=!1};r.updating=!0,r.setState({loading:!0});var t=r.props.promise,n=f(function(){function e(){var e=function(){var e,t;if(o)return null!=(e=r.subscription)&&e.unsubscribe&&r.subscription.unsubscribe(),r.props.subscribe&&null!=(t=n)&&t.subscribe&&(r.subscription=n.subscribe(r.setRes)),Promise.resolve(new Promise(function(e){return r.setRes(n,e)})).then(function(){});var i=function(){if(r.state.loading)return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})}();return i&&i.then?i.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}var n,o=!0,i=r.props.checkUpdate?Promise.resolve(Promise.all([t,r.props.promise])).then(function(e){var t=e[0];o=!s.default(t,e[1]),n=t}):Promise.resolve(t).then(function(e){n=e});return i&&i.then?i.then(e):e()},function(){return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})});return Promise.resolve(n&&n.then?n.then(e):e())}catch(e){return Promise.reject(e)}},t.promise&&void 0===t.promise.then&&(r.state.res=t.promise),r}r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,d(t,r);var o=n.prototype;return o.componentDidMount=function(){try{var e=this,t=f(function(){function t(){var t,n;null!=(t=e.subscription)&&t.unsubscribe&&e.subscription.unsubscribe(),e.props.subscribe&&null!=(n=r)&&n.subscribe&&(e.subscription=r.subscribe(e.setRes))}var r=e.props.promise,n=function(){var t,n;if(e.props.promise&&void 0!==e.props.promise.then||!s.default(null==(t=e.state.res)?void 0:t.query,null==(n=e.props.promise)?void 0:n.query))return Promise.resolve(e.props.promise).then(function(t){e.setRes(r=t)})}();return n&&n.then?n.then(t):t()},function(t){console.error(t),e.setRes(void 0,t)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},o.getUpdateKey=function(e){var t,r;if(e.updateKey)return e.updateKey;var n,o,i=[];return null!=(t=e.promise)&&t.model&&i.push(null==(n=e.promise)?void 0:n.model),null!=(r=e.promise)&&r.query&&i.push(null==(o=e.promise)?void 0:o.query),i},o.componentDidUpdate=function(e,t){try{var r=this;return(!s.default(r.getUpdateKey(r.props),r.getUpdateKey(e))||r.props.update&&!r.updating)&&r.update(),Promise.resolve()}catch(e){return Promise.reject(e)}},o.componentWillUnmount=function(){var e;null!=(e=this.subscription)&&e.unsubscribe&&this.subscription.unsubscribe()},o.renderCallback=function(){var e=this.props.callback||this.props.children;return"function"==typeof e?e(this.state.res,this.state.loading,this.state.error):e},o.renderFallback=function(){var e=this.props.fallback;return"function"==typeof e?e(this.state.res,this.state.loading,this.state.error):e},o.render=function(){var e=void 0===this.state.res?this.renderFallback():this.renderCallback();return void 0!==e?e:null},n}(l.default.Component);p.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!1,checkUpdate:!1,debounce:!1};var v=function(e){var n,u,d,f=e.template,p=e.children,v=e.fields,m=e.model,b=e.instance,h=e.map,y=e.controls,g=e.translatable,P=e.values,j=e.fieldsOptions,O=e.onChange,S=e.onSubmit,k=e.processErrors,E=e.resetAfterSubmit,C=!(!P||!O);m=m||(null==b?void 0:b.constructor),v="function"==typeof v?v(m.fields):v||m.fields;var R=t.useRef(b||(null==(n=m)?void 0:n.hydrate(P))||null),w=t.useRef([]),V=t.useRef(),F=t.useRef((null==(u=R.current)?void 0:u._id)||(new r.ObjectID).toString()),_=t.useState(!1),q=_[0],x=_[1],I=t.useState([]),L=I[0],T=I[1],A=t.useState(P||(null==(d=R.current)?void 0:d.toJSON())||{}),G=A[0],U=A[1],D=t.useState(!0),K=D[0],M=D[1];P=C?P:G;var N=F.current;t.useEffect(function(){try{var e=function(){K&&M(!1)},t=function(){if(m)return Promise.resolve(m.init()).then(function(){})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(e){return Promise.reject(e)}},[]);var $=function(e){var t;return null==(t=w.current)?void 0:t.includes(e)},B={id:N,values:P,instance:R.current,formRef:V.current,isModified:$},J=function(e,t,r,n){void 0===r&&(r={}),void 0===n&&(n=!0);var o=Object.assign({},r,e.inputOptions,j&&j[t]);if(o.hidden)return null;var i=P[t],u=n?e.getter(i,R.current,t):i,s={errors:L.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)}),value:u,onChange:function(e){return W(t,e)},options:o,id:N+":"+t,slug:t,handleSubmit:z};return e.renderInput(s)},z=function(t){try{t&&(t.preventDefault(),t.stopPropagation());var r=function(t,r){try{var n=(i=w.current.reduce(function(t,r){var n=a.default.get(P,r),o=a.default.get(e.values||{},r);return void 0===n&&o!==n?(t.$unset=t.$unset||{},t.$unset[r]=!0,delete t[r]):t[r]=n,t},{}),x(!0),T([]),null!=(o=m)&&o.beforeFormSubmit&&m.beforeFormSubmit(i,B),Promise.resolve(S(i)).then(function(){var t,r;(E=null!=(t=E)?t:!!R.current)&&U(e.values||(null==(r=R.current)?void 0:r.toJSON())||{}),x(!1)}))}catch(e){return r(e)}var o,i;return n&&n.then?n.then(void 0,r):n}(0,function(e){var t=k(e.graphandErrors||[]);x(!1),T(t)});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},W=function(e,t){try{var r,n=H(e,t);return $(e)&&n?w.current=w.current.filter(function(t){return t!==e}):n||$(e)||w.current.push(e),Promise.resolve(function(e,t){void 0===t&&(t=!1);try{var r,n=function(){var e;null!=(e=m)&&e.afterFormChange&&m.afterFormChange(P,B)};void 0===e&&(e=P),null!=(r=m)&&r.beforeFormChange&&m.beforeFormChange(e,B);var o=function(){if(C)return Promise.resolve(O(e,t)).then(function(){});U(e)}();return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}}(c({},P,(r={},r[e]=t,r)))).then(function(){})}catch(e){return Promise.reject(e)}},H=function(e,t){var r,n=null==(r=R.current)?void 0:r.get(e,!0),i=o.stringify(n),u=o.stringify(t);return s.default(i,u)},Q=f||p||function(t){/*#__PURE__*/return i.jsxs("form",{ref:t.formRef,onSubmit:t.handleSubmit,children:[t.fields.renderDefault(),"function"==typeof y?y(e):y||null]})};/*#__PURE__*/return l.default.isValidElement(Q)||Array.isArray(Q)&&Q.every(function(e){/*#__PURE__*/return l.default.isValidElement(e)})?/*#__PURE__*/i.jsx("form",{ref:V,onSubmit:z,children:Q}):Q({fields:Object.keys(v).reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=function(e,r){return void 0===e&&(e={}),J(v[t],t,e,r)},r))},{render:function(e,t,r){return void 0===t&&(t={}),J(v[e],e,t,r)},renderDefault:function(){var e;return(h=null!=(e=h)?e:Object.keys(v).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)})).map(function(e){return J(v[e],e)})}}),isLoading:q,isInitializing:K,errors:L,handleSubmit:z,isTranslatable:g,formRef:V,values:P,modified:w.current||[]})};v.defaultProps={model:null,fields:null,map:null,fieldsOptions:{},getFieldOptions:null,instance:null,errors:[],onSubmit:function(){return null},submitLabel:"Valider",template:null,resetAfterSubmit:void 0,preventLeave:!1,translatable:!1,values:void 0,onChange:void 0,processErrors:function(e){return e},controls:function(e){return[/*#__PURE__*/i.jsx("button",{className:"btn btn-primary",type:"submit",children:e.submitLabel})]}};var m={options:{types:{}},__construct:function(e,t){void 0===t&&(t={});var r=e.constructor.lib,n=r.GraphandModelPromise,o=r.GraphandModel,i=r.GraphandModelListPromise,u=r.GraphandModelList,s=r.GraphandField,a=r.AggregationExecutor;s.InputComponent=null,s.ViewComponent=null,n.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/l.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/l.default.createElement(p,c({promise:this,callback:e,fallback:t},r))},o.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/l.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/l.default.createElement(p,c({promise:this,callback:e,fallback:t},r))},i.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/l.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/l.default.createElement(p,c({promise:this,callback:e,fallback:t},r))},u.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/l.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/l.default.createElement(p,c({promise:this,callback:e,fallback:t},r))},a.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/l.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/l.default.createElement(p,c({promise:this,callback:e,fallback:t},r))},s.prototype.renderInput=function(e){void 0===e&&(e={});var r,n=Object.getPrototypeOf(this).constructor,o=this.InputComponent||n.InputComponent;return o||(o=null==(r=t.fields[n.__fieldType])?void 0:r.input),o?/*#__PURE__*/l.default.createElement(o,c({},e,{field:this})):null},s.prototype.renderView=function(e){void 0===e&&(e={});var r,n=Object.getPrototypeOf(this).constructor,o=this.ViewComponent||n.ViewComponent;return o||(o=null==(r=t.fields[n.__fieldType])?void 0:r.view),o?/*#__PURE__*/l.default.createElement(o,c({},e,{field:this})):"string"==typeof e.value?e.value:null},o.prototype.renderFieldView=function(e,t,r){void 0===r&&(r={});var n=Object.getPrototypeOf(this).constructor;t&&"object"==typeof t&&(Object.assign(r,t),t=void 0);var o=n.fields&&n.fields[e];return(null==o?void 0:o.renderView({value:this.get(e,t),item:this,slug:e,options:r}))||null},o.prototype.renderFieldInput=function(e,t,r){void 0===r&&(r={});var n=Object.getPrototypeOf(this).constructor;t&&"object"==typeof t&&(Object.assign(r,t),t=void 0);var o=n.fields&&n.fields[e];return(null==o?void 0:o.renderInput({value:this.get(e,t),item:this,slug:e,options:r}))||null}}};exports.GraphandForm=v,exports.GraphandPluginReact=m,exports.PromiseSuspense=p,exports.default=m,exports.useList=function(e,r,n){void 0===r&&(r={});var o,i=t.useState([]),u=i[0],s=i[1],l=t.useState(!1)[0];return t.useEffect(function(){return e.getList(r).then(s).then(function(e){return e&&(o=e.subscribe(s))}),function(){var e;return null==(e=o)?void 0:e.unsubscribe()}}),[u,l]};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import e from"fast-deep-equal/react";import t,{useRef as r,useState as n,useEffect as o}from"react";import{ObjectID as i}from"bson";import u from"lodash";import{stringify as s}from"flatted";import{jsx as l,jsxs as c}from"react/jsx-runtime";function a(){return a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a.apply(this,arguments)}function p(e,t){return p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},p(e,t)}function d(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var f=/*#__PURE__*/function(t){var r,n;function o(r){var n;return(n=t.call(this,r)||this).state={res:void 0,loading:!1,error:null},n.setRes=function(e,t){void 0===t&&(t=null);try{return Promise.resolve(new Promise(function(r){!1!==n.props.debounce?(n.state.loading||n.setState({loading:!0}),n.debounceTimeout&&clearTimeout(n.debounceTimeout),n.debounceTimeout=setTimeout(function(){n.setState({res:e,loading:!1,error:t},r)},n.props.debounce)):n.setState({res:e,loading:!1,error:t},r)}))}catch(e){return Promise.reject(e)}},n.update=function(){try{var t=function(){n.updating=!1};n.updating=!0,n.setState({loading:!0});var r=n.props.promise,o=d(function(){function t(){var e=function(){var e,t;if(i)return null!=(e=n.subscription)&&e.unsubscribe&&n.subscription.unsubscribe(),n.props.subscribe&&null!=(t=o)&&t.subscribe&&(n.subscription=o.subscribe(n.setRes)),Promise.resolve(new Promise(function(e){return n.setRes(o,e)})).then(function(){});var r=function(){if(n.state.loading)return Promise.resolve(new Promise(function(e){return n.setState({loading:!1},e)})).then(function(){})}();return r&&r.then?r.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}var o,i=!0,u=n.props.checkUpdate?Promise.resolve(Promise.all([r,n.props.promise])).then(function(t){var r=t[0];i=!e(r,t[1]),o=r}):Promise.resolve(r).then(function(e){o=e});return u&&u.then?u.then(t):t()},function(){return Promise.resolve(new Promise(function(e){return n.setState({loading:!1},e)})).then(function(){})});return Promise.resolve(o&&o.then?o.then(t):t())}catch(e){return Promise.reject(e)}},r.promise&&void 0===r.promise.then&&(n.state.res=r.promise),n}n=t,(r=o).prototype=Object.create(n.prototype),r.prototype.constructor=r,p(r,n);var i=o.prototype;return i.componentDidMount=function(){try{var t=this,r=d(function(){function r(){var e,r;null!=(e=t.subscription)&&e.unsubscribe&&t.subscription.unsubscribe(),t.props.subscribe&&null!=(r=n)&&r.subscribe&&(t.subscription=n.subscribe(t.setRes))}var n=t.props.promise,o=function(){var r,o;if(t.props.promise&&void 0!==t.props.promise.then||!e(null==(r=t.state.res)?void 0:r.query,null==(o=t.props.promise)?void 0:o.query))return Promise.resolve(t.props.promise).then(function(e){t.setRes(n=e)})}();return o&&o.then?o.then(r):r()},function(e){console.error(e),t.setRes(void 0,e)});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},i.getUpdateKey=function(e){var t,r;if(e.updateKey)return e.updateKey;var n,o,i=[];return null!=(t=e.promise)&&t.model&&i.push(null==(n=e.promise)?void 0:n.model),null!=(r=e.promise)&&r.query&&i.push(null==(o=e.promise)?void 0:o.query),i},i.componentDidUpdate=function(t,r){try{var n=this;return(!e(n.getUpdateKey(n.props),n.getUpdateKey(t))||n.props.update&&!n.updating)&&n.update(),Promise.resolve()}catch(e){return Promise.reject(e)}},i.componentWillUnmount=function(){var e;null!=(e=this.subscription)&&e.unsubscribe&&this.subscription.unsubscribe()},i.renderCallback=function(){var e=this.props.callback||this.props.children;return"function"==typeof e?e(this.state.res,this.state.loading,this.state.error):e},i.renderFallback=function(){var e=this.props.fallback;return"function"==typeof e?e(this.state.res,this.state.loading,this.state.error):e},i.render=function(){var e=void 0===this.state.res?this.renderFallback():this.renderCallback();return void 0!==e?e:null},o}(t.Component);f.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!1,checkUpdate:!1,debounce:!1};var v=function(p){var d,f,v,m=p.template,b=p.children,h=p.fields,y=p.model,g=p.instance,P=p.map,j=p.controls,O=p.translatable,k=p.values,E=p.fieldsOptions,S=p.onChange,C=p.onSubmit,V=p.processErrors,w=p.resetAfterSubmit,F=!(!k||!S);y=y||(null==g?void 0:g.constructor),h="function"==typeof h?h(y.fields):h||y.fields;var _=r(g||(null==(d=y)?void 0:d.hydrate(k))||null),I=r([]),R=r(),T=r((null==(f=_.current)?void 0:f._id)||(new i).toString()),A=n(!1),L=A[0],U=A[1],K=n([]),M=K[0],q=K[1],G=n(k||(null==(v=_.current)?void 0:v.toJSON())||{}),x=G[0],D=G[1],$=n(!0),B=$[0],N=$[1];k=F?k:x;var z=T.current;o(function(){try{var e=function(){B&&N(!1)},t=function(){if(y)return Promise.resolve(y.init()).then(function(){})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(e){return Promise.reject(e)}},[]);var J=function(e){var t;return null==(t=I.current)?void 0:t.includes(e)},W={id:z,values:k,formRef:R.current,isModified:J},H=function(){/*#__PURE__*/return c(t.Fragment,{children:[X(),"function"==typeof j?j(p):j||null]})},Q=function(e,t,r,n){void 0===r&&(r={}),void 0===n&&(n=!0);var o=Object.assign({},r,e.inputOptions,E&&E[t]);if(o.hidden)return null;var i=k[t],u=n?e.getter(i,_.current,t):i,s={errors:M.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)}),value:u,onChange:function(e){return Z(t,e)},options:o,id:z+":"+t,slug:t,handleSubmit:Y};return e.renderInput(s)},X=function(){var e;return(P=null!=(e=P)?e:Object.keys(h).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)})).map(function(e){return Q(h[e],e)})},Y=function(e){try{e&&(e.preventDefault(),e.stopPropagation());var t=function(e,t){try{var r=(o=I.current.reduce(function(e,t){var r=u.get(k,t),n=u.get(p.values||{},t);return void 0===r&&n!==r?(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]):e[t]=r,e},{}),U(!0),q([]),null!=(n=y)&&n.beforeFormSubmit&&y.beforeFormSubmit(o,W),Promise.resolve(C(o)).then(function(){var e;(w=null!=(e=w)?e:!!_.current)&&(void 0).resetInstance().then(function(){return(void 0).resetValues()}),U(!1)}))}catch(e){return t(e)}var n,o;return r&&r.then?r.then(void 0,t):r}(0,function(e){var t=V(e.graphandErrors||[]);U(!1),q(t)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Z=function(e,t){try{var r,n=ee(e,t);return J(e)&&n?I.current=I.current.filter(function(t){return t!==e}):n||J(e)||I.current.push(e),Promise.resolve(function(e,t){void 0===t&&(t=!1);try{var r,n=function(){var e;null!=(e=y)&&e.afterFormChange&&y.afterFormChange(k,W)};void 0===e&&(e=k),null!=(r=y)&&r.beforeFormChange&&y.beforeFormChange(e,W);var o=function(){if(F)return Promise.resolve(S(e,t)).then(function(){});D(e)}();return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}}(a({},k,(r={},r[e]=t,r)))).then(function(){})}catch(e){return Promise.reject(e)}},ee=function(t,r){var n,o=null==(n=_.current)?void 0:n.get(t,!0),i=s(o),u=s(r);return e(i,u)},te=m||b||/*#__PURE__*/t.createElement(H);/*#__PURE__*/return t.isValidElement(te)||Array.isArray(te)&&te.every(function(e){/*#__PURE__*/return t.isValidElement(e)})?/*#__PURE__*/l("form",{ref:R,onSubmit:Y,children:te}):te({fields:Object.keys(h).reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=function(e,r){return void 0===e&&(e={}),Q(h[t],t,e,r)},r))},{render:function(e,t,r){return void 0===t&&(t={}),Q(h[e],e,t,r)},renderDefault:X}),isLoading:L,isInitializing:B,errors:M,handleSubmit:Y,isTranslatable:O,formRef:R,values:k,modified:I.current||[]})};v.defaultProps={model:null,fields:null,map:null,fieldsOptions:{},getFieldOptions:null,instance:null,errors:[],onSubmit:function(){return null},submitLabel:"Valider",template:null,resetAfterSubmit:void 0,preventLeave:!1,translatable:!1,values:void 0,onChange:void 0,processErrors:function(e){return e},controls:function(e){return[/*#__PURE__*/l("button",{className:"btn btn-primary",type:"submit",children:e.submitLabel})]}};var m={options:{types:{}},__construct:function(e,r){void 0===r&&(r={});var n=e.constructor.lib,o=n.GraphandModelPromise,i=n.GraphandModel,u=n.GraphandModelListPromise,s=n.GraphandModelList,l=n.GraphandField,c=n.AggregationExecutor;l.InputComponent=null,l.ViewComponent=null,o.prototype.suspense=function(e,r,n){return void 0===r&&(r=null),void 0===n&&(n={}),r&&!/*#__PURE__*/t.isValidElement(r)&&"object"==typeof r&&(Object.assign(n,r),r=null),/*#__PURE__*/t.createElement(f,a({promise:this,callback:e,fallback:r},n))},i.prototype.suspense=function(e,r,n){return void 0===r&&(r=null),void 0===n&&(n={}),r&&!/*#__PURE__*/t.isValidElement(r)&&"object"==typeof r&&(Object.assign(n,r),r=null),/*#__PURE__*/t.createElement(f,a({promise:this,callback:e,fallback:r},n))},u.prototype.suspense=function(e,r,n){return void 0===r&&(r=null),void 0===n&&(n={}),r&&!/*#__PURE__*/t.isValidElement(r)&&"object"==typeof r&&(Object.assign(n,r),r=null),/*#__PURE__*/t.createElement(f,a({promise:this,callback:e,fallback:r},n))},s.prototype.suspense=function(e,r,n){return void 0===r&&(r=null),void 0===n&&(n={}),r&&!/*#__PURE__*/t.isValidElement(r)&&"object"==typeof r&&(Object.assign(n,r),r=null),/*#__PURE__*/t.createElement(f,a({promise:this,callback:e,fallback:r},n))},c.prototype.suspense=function(e,r,n){return void 0===r&&(r=null),void 0===n&&(n={}),r&&!/*#__PURE__*/t.isValidElement(r)&&"object"==typeof r&&(Object.assign(n,r),r=null),/*#__PURE__*/t.createElement(f,a({promise:this,callback:e,fallback:r},n))},l.prototype.renderInput=function(e){void 0===e&&(e={});var n,o=Object.getPrototypeOf(this).constructor,i=this.InputComponent||o.InputComponent;return i||(i=null==(n=r.fields[o.__fieldType])?void 0:n.input),i?/*#__PURE__*/t.createElement(i,a({},e,{field:this})):null},l.prototype.renderView=function(e){void 0===e&&(e={});var n,o=Object.getPrototypeOf(this).constructor,i=this.ViewComponent||o.ViewComponent;return i||(i=null==(n=r.fields[o.__fieldType])?void 0:n.view),i?/*#__PURE__*/t.createElement(i,a({},e,{field:this})):"string"==typeof e.value?e.value:null},i.prototype.renderFieldView=function(e,t,r){void 0===r&&(r={});var n=Object.getPrototypeOf(this).constructor;t&&"object"==typeof t&&(Object.assign(r,t),t=void 0);var o=n.fields&&n.fields[e];return(null==o?void 0:o.renderView({value:this.get(e,t),item:this,slug:e,options:r}))||null},i.prototype.renderFieldInput=function(e,t,r){void 0===r&&(r={});var n=Object.getPrototypeOf(this).constructor;t&&"object"==typeof t&&(Object.assign(r,t),t=void 0);var o=n.fields&&n.fields[e];return(null==o?void 0:o.renderInput({value:this.get(e,t),item:this,slug:e,options:r}))||null}}};function b(e,t,r){void 0===t&&(t={});var i,u=n([]),s=u[0],l=u[1],c=n(!1)[0];return o(function(){return e.getList(t).then(l).then(function(e){return e&&(i=e.subscribe(l))}),function(){var e;return null==(e=i)?void 0:e.unsubscribe()}}),[s,c]}export{v as GraphandForm,m as GraphandPluginReact,f as PromiseSuspense,m as default,b as useList};
import e from"fast-deep-equal/react";import t,{useRef as r,useState as n,useEffect as o}from"react";import{ObjectID as i}from"bson";import u from"lodash";import{stringify as s}from"flatted";import{jsx as l,jsxs as c}from"react/jsx-runtime";function a(){return a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a.apply(this,arguments)}function p(e,t){return p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},p(e,t)}function d(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var f=/*#__PURE__*/function(t){var r,n;function o(r){var n;return(n=t.call(this,r)||this).state={res:void 0,loading:!1,error:null},n.setRes=function(e,t){void 0===t&&(t=null);try{return Promise.resolve(new Promise(function(r){!1!==n.props.debounce?(n.state.loading||n.setState({loading:!0}),n.debounceTimeout&&clearTimeout(n.debounceTimeout),n.debounceTimeout=setTimeout(function(){n.setState({res:e,loading:!1,error:t},r)},n.props.debounce)):n.setState({res:e,loading:!1,error:t},r)}))}catch(e){return Promise.reject(e)}},n.update=function(){try{var t=function(){n.updating=!1};n.updating=!0,n.setState({loading:!0});var r=n.props.promise,o=d(function(){function t(){var e=function(){var e,t;if(i)return null!=(e=n.subscription)&&e.unsubscribe&&n.subscription.unsubscribe(),n.props.subscribe&&null!=(t=o)&&t.subscribe&&(n.subscription=o.subscribe(n.setRes)),Promise.resolve(new Promise(function(e){return n.setRes(o,e)})).then(function(){});var r=function(){if(n.state.loading)return Promise.resolve(new Promise(function(e){return n.setState({loading:!1},e)})).then(function(){})}();return r&&r.then?r.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}var o,i=!0,u=n.props.checkUpdate?Promise.resolve(Promise.all([r,n.props.promise])).then(function(t){var r=t[0];i=!e(r,t[1]),o=r}):Promise.resolve(r).then(function(e){o=e});return u&&u.then?u.then(t):t()},function(){return Promise.resolve(new Promise(function(e){return n.setState({loading:!1},e)})).then(function(){})});return Promise.resolve(o&&o.then?o.then(t):t())}catch(e){return Promise.reject(e)}},r.promise&&void 0===r.promise.then&&(n.state.res=r.promise),n}n=t,(r=o).prototype=Object.create(n.prototype),r.prototype.constructor=r,p(r,n);var i=o.prototype;return i.componentDidMount=function(){try{var t=this,r=d(function(){function r(){var e,r;null!=(e=t.subscription)&&e.unsubscribe&&t.subscription.unsubscribe(),t.props.subscribe&&null!=(r=n)&&r.subscribe&&(t.subscription=n.subscribe(t.setRes))}var n=t.props.promise,o=function(){var r,o;if(t.props.promise&&void 0!==t.props.promise.then||!e(null==(r=t.state.res)?void 0:r.query,null==(o=t.props.promise)?void 0:o.query))return Promise.resolve(t.props.promise).then(function(e){t.setRes(n=e)})}();return o&&o.then?o.then(r):r()},function(e){console.error(e),t.setRes(void 0,e)});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},i.getUpdateKey=function(e){var t,r;if(e.updateKey)return e.updateKey;var n,o,i=[];return null!=(t=e.promise)&&t.model&&i.push(null==(n=e.promise)?void 0:n.model),null!=(r=e.promise)&&r.query&&i.push(null==(o=e.promise)?void 0:o.query),i},i.componentDidUpdate=function(t,r){try{var n=this;return(!e(n.getUpdateKey(n.props),n.getUpdateKey(t))||n.props.update&&!n.updating)&&n.update(),Promise.resolve()}catch(e){return Promise.reject(e)}},i.componentWillUnmount=function(){var e;null!=(e=this.subscription)&&e.unsubscribe&&this.subscription.unsubscribe()},i.renderCallback=function(){var e=this.props.callback||this.props.children;return"function"==typeof e?e(this.state.res,this.state.loading,this.state.error):e},i.renderFallback=function(){var e=this.props.fallback;return"function"==typeof e?e(this.state.res,this.state.loading,this.state.error):e},i.render=function(){var e=void 0===this.state.res?this.renderFallback():this.renderCallback();return void 0!==e?e:null},o}(t.Component);f.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!1,checkUpdate:!1,debounce:!1};var v=function(p){var d,f,v,m=p.template,b=p.children,h=p.fields,y=p.model,g=p.instance,P=p.map,j=p.controls,O=p.translatable,k=p.values,S=p.fieldsOptions,E=p.onChange,C=p.onSubmit,w=p.processErrors,V=p.resetAfterSubmit,F=!(!k||!E);y=y||(null==g?void 0:g.constructor),h="function"==typeof h?h(y.fields):h||y.fields;var _=r(g||(null==(d=y)?void 0:d.hydrate(k))||null),R=r([]),I=r(),T=r((null==(f=_.current)?void 0:f._id)||(new i).toString()),A=n(!1),L=A[0],U=A[1],K=n([]),M=K[0],q=K[1],D=n(k||(null==(v=_.current)?void 0:v.toJSON())||{}),G=D[0],x=D[1],N=n(!0),$=N[0],B=N[1];k=F?k:G;var J=T.current;o(function(){try{var e=function(){$&&B(!1)},t=function(){if(y)return Promise.resolve(y.init()).then(function(){})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(e){return Promise.reject(e)}},[]);var z=function(e){var t;return null==(t=R.current)?void 0:t.includes(e)},W={id:J,values:k,instance:_.current,formRef:I.current,isModified:z},H=function(e,t,r,n){void 0===r&&(r={}),void 0===n&&(n=!0);var o=Object.assign({},r,e.inputOptions,S&&S[t]);if(o.hidden)return null;var i=k[t],u=n?e.getter(i,_.current,t):i,s={errors:M.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)}),value:u,onChange:function(e){return X(t,e)},options:o,id:J+":"+t,slug:t,handleSubmit:Q};return e.renderInput(s)},Q=function(e){try{e&&(e.preventDefault(),e.stopPropagation());var t=function(e,t){try{var r=(o=R.current.reduce(function(e,t){var r=u.get(k,t),n=u.get(p.values||{},t);return void 0===r&&n!==r?(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]):e[t]=r,e},{}),U(!0),q([]),null!=(n=y)&&n.beforeFormSubmit&&y.beforeFormSubmit(o,W),Promise.resolve(C(o)).then(function(){var e,t;(V=null!=(e=V)?e:!!_.current)&&x(p.values||(null==(t=_.current)?void 0:t.toJSON())||{}),U(!1)}))}catch(e){return t(e)}var n,o;return r&&r.then?r.then(void 0,t):r}(0,function(e){var t=w(e.graphandErrors||[]);U(!1),q(t)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},X=function(e,t){try{var r,n=Y(e,t);return z(e)&&n?R.current=R.current.filter(function(t){return t!==e}):n||z(e)||R.current.push(e),Promise.resolve(function(e,t){void 0===t&&(t=!1);try{var r,n=function(){var e;null!=(e=y)&&e.afterFormChange&&y.afterFormChange(k,W)};void 0===e&&(e=k),null!=(r=y)&&r.beforeFormChange&&y.beforeFormChange(e,W);var o=function(){if(F)return Promise.resolve(E(e,t)).then(function(){});x(e)}();return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}}(a({},k,(r={},r[e]=t,r)))).then(function(){})}catch(e){return Promise.reject(e)}},Y=function(t,r){var n,o=null==(n=_.current)?void 0:n.get(t,!0),i=s(o),u=s(r);return e(i,u)},Z=m||b||function(e){/*#__PURE__*/return c("form",{ref:e.formRef,onSubmit:e.handleSubmit,children:[e.fields.renderDefault(),"function"==typeof j?j(p):j||null]})};/*#__PURE__*/return t.isValidElement(Z)||Array.isArray(Z)&&Z.every(function(e){/*#__PURE__*/return t.isValidElement(e)})?/*#__PURE__*/l("form",{ref:I,onSubmit:Q,children:Z}):Z({fields:Object.keys(h).reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=function(e,r){return void 0===e&&(e={}),H(h[t],t,e,r)},r))},{render:function(e,t,r){return void 0===t&&(t={}),H(h[e],e,t,r)},renderDefault:function(){var e;return(P=null!=(e=P)?e:Object.keys(h).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)})).map(function(e){return H(h[e],e)})}}),isLoading:L,isInitializing:$,errors:M,handleSubmit:Q,isTranslatable:O,formRef:I,values:k,modified:R.current||[]})};v.defaultProps={model:null,fields:null,map:null,fieldsOptions:{},getFieldOptions:null,instance:null,errors:[],onSubmit:function(){return null},submitLabel:"Valider",template:null,resetAfterSubmit:void 0,preventLeave:!1,translatable:!1,values:void 0,onChange:void 0,processErrors:function(e){return e},controls:function(e){return[/*#__PURE__*/l("button",{className:"btn btn-primary",type:"submit",children:e.submitLabel})]}};var m={options:{types:{}},__construct:function(e,r){void 0===r&&(r={});var n=e.constructor.lib,o=n.GraphandModelPromise,i=n.GraphandModel,u=n.GraphandModelListPromise,s=n.GraphandModelList,l=n.GraphandField,c=n.AggregationExecutor;l.InputComponent=null,l.ViewComponent=null,o.prototype.suspense=function(e,r,n){return void 0===r&&(r=null),void 0===n&&(n={}),r&&!/*#__PURE__*/t.isValidElement(r)&&"object"==typeof r&&(Object.assign(n,r),r=null),/*#__PURE__*/t.createElement(f,a({promise:this,callback:e,fallback:r},n))},i.prototype.suspense=function(e,r,n){return void 0===r&&(r=null),void 0===n&&(n={}),r&&!/*#__PURE__*/t.isValidElement(r)&&"object"==typeof r&&(Object.assign(n,r),r=null),/*#__PURE__*/t.createElement(f,a({promise:this,callback:e,fallback:r},n))},u.prototype.suspense=function(e,r,n){return void 0===r&&(r=null),void 0===n&&(n={}),r&&!/*#__PURE__*/t.isValidElement(r)&&"object"==typeof r&&(Object.assign(n,r),r=null),/*#__PURE__*/t.createElement(f,a({promise:this,callback:e,fallback:r},n))},s.prototype.suspense=function(e,r,n){return void 0===r&&(r=null),void 0===n&&(n={}),r&&!/*#__PURE__*/t.isValidElement(r)&&"object"==typeof r&&(Object.assign(n,r),r=null),/*#__PURE__*/t.createElement(f,a({promise:this,callback:e,fallback:r},n))},c.prototype.suspense=function(e,r,n){return void 0===r&&(r=null),void 0===n&&(n={}),r&&!/*#__PURE__*/t.isValidElement(r)&&"object"==typeof r&&(Object.assign(n,r),r=null),/*#__PURE__*/t.createElement(f,a({promise:this,callback:e,fallback:r},n))},l.prototype.renderInput=function(e){void 0===e&&(e={});var n,o=Object.getPrototypeOf(this).constructor,i=this.InputComponent||o.InputComponent;return i||(i=null==(n=r.fields[o.__fieldType])?void 0:n.input),i?/*#__PURE__*/t.createElement(i,a({},e,{field:this})):null},l.prototype.renderView=function(e){void 0===e&&(e={});var n,o=Object.getPrototypeOf(this).constructor,i=this.ViewComponent||o.ViewComponent;return i||(i=null==(n=r.fields[o.__fieldType])?void 0:n.view),i?/*#__PURE__*/t.createElement(i,a({},e,{field:this})):"string"==typeof e.value?e.value:null},i.prototype.renderFieldView=function(e,t,r){void 0===r&&(r={});var n=Object.getPrototypeOf(this).constructor;t&&"object"==typeof t&&(Object.assign(r,t),t=void 0);var o=n.fields&&n.fields[e];return(null==o?void 0:o.renderView({value:this.get(e,t),item:this,slug:e,options:r}))||null},i.prototype.renderFieldInput=function(e,t,r){void 0===r&&(r={});var n=Object.getPrototypeOf(this).constructor;t&&"object"==typeof t&&(Object.assign(r,t),t=void 0);var o=n.fields&&n.fields[e];return(null==o?void 0:o.renderInput({value:this.get(e,t),item:this,slug:e,options:r}))||null}}};function b(e,t,r){void 0===t&&(t={});var i,u=n([]),s=u[0],l=u[1],c=n(!1)[0];return o(function(){return e.getList(t).then(l).then(function(e){return e&&(i=e.subscribe(l))}),function(){var e;return null==(e=i)?void 0:e.unsubscribe()}}),[s,c]}export{v as GraphandForm,m as GraphandPluginReact,f as PromiseSuspense,m as default,b as useList};
//# sourceMappingURL=index.modern.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("fast-deep-equal/react"),require("react"),require("bson"),require("lodash"),require("flatted"),require("react/jsx-runtime")):"function"==typeof define&&define.amd?define(["exports","fast-deep-equal/react","react","bson","lodash","flatted","react/jsx-runtime"],t):t((e||self).graphandReact={},e.isEqual,e.react,e.bson,e.lodash,e.flatted,e.jsxRuntime)}(this,function(e,t,n,r,o,i,u){function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=/*#__PURE__*/s(t),a=/*#__PURE__*/s(n),c=/*#__PURE__*/s(o);function d(){return d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},d.apply(this,arguments)}function f(e,t){return f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},f(e,t)}function p(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var v=/*#__PURE__*/function(e){var t,n;function r(t){var n;return(n=e.call(this,t)||this).state={res:void 0,loading:!1,error:null},n.setRes=function(e,t){void 0===t&&(t=null);try{return Promise.resolve(new Promise(function(r){!1!==n.props.debounce?(n.state.loading||n.setState({loading:!0}),n.debounceTimeout&&clearTimeout(n.debounceTimeout),n.debounceTimeout=setTimeout(function(){n.setState({res:e,loading:!1,error:t},r)},n.props.debounce)):n.setState({res:e,loading:!1,error:t},r)}))}catch(e){return Promise.reject(e)}},n.update=function(){try{var e=function(){n.updating=!1};n.updating=!0,n.setState({loading:!0});var t=n.props.promise,r=p(function(){function e(){var e=function(){var e,t;if(o)return null!=(e=n.subscription)&&e.unsubscribe&&n.subscription.unsubscribe(),n.props.subscribe&&null!=(t=r)&&t.subscribe&&(n.subscription=r.subscribe(n.setRes)),Promise.resolve(new Promise(function(e){return n.setRes(r,e)})).then(function(){});var i=function(){if(n.state.loading)return Promise.resolve(new Promise(function(e){return n.setState({loading:!1},e)})).then(function(){})}();return i&&i.then?i.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}var r,o=!0,i=n.props.checkUpdate?Promise.resolve(Promise.all([t,n.props.promise])).then(function(e){var t=e[0];o=!l.default(t,e[1]),r=t}):Promise.resolve(t).then(function(e){r=e});return i&&i.then?i.then(e):e()},function(){return Promise.resolve(new Promise(function(e){return n.setState({loading:!1},e)})).then(function(){})});return Promise.resolve(r&&r.then?r.then(e):e())}catch(e){return Promise.reject(e)}},t.promise&&void 0===t.promise.then&&(n.state.res=t.promise),n}n=e,(t=r).prototype=Object.create(n.prototype),t.prototype.constructor=t,f(t,n);var o=r.prototype;return o.componentDidMount=function(){try{var e=this,t=p(function(){function t(){var t,r;null!=(t=e.subscription)&&t.unsubscribe&&e.subscription.unsubscribe(),e.props.subscribe&&null!=(r=n)&&r.subscribe&&(e.subscription=n.subscribe(e.setRes))}var n=e.props.promise,r=function(){var t,r;if(e.props.promise&&void 0!==e.props.promise.then||!l.default(null==(t=e.state.res)?void 0:t.query,null==(r=e.props.promise)?void 0:r.query))return Promise.resolve(e.props.promise).then(function(t){e.setRes(n=t)})}();return r&&r.then?r.then(t):t()},function(t){console.error(t),e.setRes(void 0,t)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},o.getUpdateKey=function(e){var t,n;if(e.updateKey)return e.updateKey;var r,o,i=[];return null!=(t=e.promise)&&t.model&&i.push(null==(r=e.promise)?void 0:r.model),null!=(n=e.promise)&&n.query&&i.push(null==(o=e.promise)?void 0:o.query),i},o.componentDidUpdate=function(e,t){try{var n=this;return(!l.default(n.getUpdateKey(n.props),n.getUpdateKey(e))||n.props.update&&!n.updating)&&n.update(),Promise.resolve()}catch(e){return Promise.reject(e)}},o.componentWillUnmount=function(){var e;null!=(e=this.subscription)&&e.unsubscribe&&this.subscription.unsubscribe()},o.renderCallback=function(){var e=this.props.callback||this.props.children;return"function"==typeof e?e(this.state.res,this.state.loading,this.state.error):e},o.renderFallback=function(){var e=this.props.fallback;return"function"==typeof e?e(this.state.res,this.state.loading,this.state.error):e},o.render=function(){var e=void 0===this.state.res?this.renderFallback():this.renderCallback();return void 0!==e?e:null},r}(a.default.Component);v.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!1,checkUpdate:!1,debounce:!1};var m=void 0,b=function(e){var t,o,s,f=e.template,p=e.children,v=e.fields,b=e.model,h=e.instance,y=e.map,g=e.controls,P=e.translatable,j=e.values,O=e.fieldsOptions,S=e.onChange,E=e.onSubmit,k=e.processErrors,C=e.resetAfterSubmit,R=!(!j||!S);b=b||(null==h?void 0:h.constructor),v="function"==typeof v?v(b.fields):v||b.fields;var V=n.useRef(h||(null==(t=b)?void 0:t.hydrate(j))||null),w=n.useRef([]),F=n.useRef(),q=n.useRef((null==(o=V.current)?void 0:o._id)||(new r.ObjectID).toString()),_=n.useState(!1),x=_[0],I=_[1],T=n.useState([]),L=T[0],A=T[1],G=n.useState(j||(null==(s=V.current)?void 0:s.toJSON())||{}),U=G[0],K=G[1],M=n.useState(!0),D=M[0],$=M[1];j=R?j:U;var B=q.current;n.useEffect(function(){try{var e=function(){D&&$(!1)},t=function(){if(b)return Promise.resolve(b.init()).then(function(){})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(e){return Promise.reject(e)}},[]);var N=function(e){var t;return null==(t=w.current)?void 0:t.includes(e)},z={id:B,values:j,formRef:F.current,isModified:N},J=function(){/*#__PURE__*/return u.jsxs(a.default.Fragment,{children:[H(),"function"==typeof g?g(e):g||null]})},W=function(e,t,n,r){void 0===n&&(n={}),void 0===r&&(r=!0);var o=Object.assign({},n,e.inputOptions,O&&O[t]);if(o.hidden)return null;var i=j[t],u=r?e.getter(i,V.current,t):i,s={errors:L.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)}),value:u,onChange:function(e){return X(t,e)},options:o,id:B+":"+t,slug:t,handleSubmit:Q};return e.renderInput(s)},H=function(){var e;return(y=null!=(e=y)?e:Object.keys(v).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)})).map(function(e){return W(v[e],e)})},Q=function(t){try{t&&(t.preventDefault(),t.stopPropagation());var n=function(t,n){try{var r=(i=w.current.reduce(function(t,n){var r=c.default.get(j,n),o=c.default.get(e.values||{},n);return void 0===r&&o!==r?(t.$unset=t.$unset||{},t.$unset[n]=!0,delete t[n]):t[n]=r,t},{}),I(!0),A([]),null!=(o=b)&&o.beforeFormSubmit&&b.beforeFormSubmit(i,z),Promise.resolve(E(i)).then(function(){var e;(C=null!=(e=C)?e:!!V.current)&&m.resetInstance().then(function(){return m.resetValues()}),I(!1)}))}catch(e){return n(e)}var o,i;return r&&r.then?r.then(void 0,n):r}(0,function(e){var t=k(e.graphandErrors||[]);I(!1),A(t)});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},X=function(e,t){try{var n,r=Y(e,t);return N(e)&&r?w.current=w.current.filter(function(t){return t!==e}):r||N(e)||w.current.push(e),Promise.resolve(function(e,t){void 0===t&&(t=!1);try{var n,r=function(){var e;null!=(e=b)&&e.afterFormChange&&b.afterFormChange(j,z)};void 0===e&&(e=j),null!=(n=b)&&n.beforeFormChange&&b.beforeFormChange(e,z);var o=function(){if(R)return Promise.resolve(S(e,t)).then(function(){});K(e)}();return Promise.resolve(o&&o.then?o.then(r):r())}catch(e){return Promise.reject(e)}}(d({},j,(n={},n[e]=t,n)))).then(function(){})}catch(e){return Promise.reject(e)}},Y=function(e,t){var n,r=null==(n=V.current)?void 0:n.get(e,!0),o=i.stringify(r),u=i.stringify(t);return l.default(o,u)},Z=f||p||/*#__PURE__*/a.default.createElement(J);/*#__PURE__*/return a.default.isValidElement(Z)||Array.isArray(Z)&&Z.every(function(e){/*#__PURE__*/return a.default.isValidElement(e)})?/*#__PURE__*/u.jsx("form",{ref:F,onSubmit:Q,children:Z}):Z({fields:Object.keys(v).reduce(function(e,t){var n;return Object.assign(e,((n={})[t]=function(e,n){return void 0===e&&(e={}),W(v[t],t,e,n)},n))},{render:function(e,t,n){return void 0===t&&(t={}),W(v[e],e,t,n)},renderDefault:H}),isLoading:x,isInitializing:D,errors:L,handleSubmit:Q,isTranslatable:P,formRef:F,values:j,modified:w.current||[]})};b.defaultProps={model:null,fields:null,map:null,fieldsOptions:{},getFieldOptions:null,instance:null,errors:[],onSubmit:function(){return null},submitLabel:"Valider",template:null,resetAfterSubmit:void 0,preventLeave:!1,translatable:!1,values:void 0,onChange:void 0,processErrors:function(e){return e},controls:function(e){return[/*#__PURE__*/u.jsx("button",{className:"btn btn-primary",type:"submit",children:e.submitLabel})]}};var h={options:{types:{}},__construct:function(e,t){void 0===t&&(t={});var n=e.constructor.lib,r=n.GraphandModelPromise,o=n.GraphandModel,i=n.GraphandModelListPromise,u=n.GraphandModelList,s=n.GraphandField,l=n.AggregationExecutor;s.InputComponent=null,s.ViewComponent=null,r.prototype.suspense=function(e,t,n){return void 0===t&&(t=null),void 0===n&&(n={}),t&&!/*#__PURE__*/a.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(n,t),t=null),/*#__PURE__*/a.default.createElement(v,d({promise:this,callback:e,fallback:t},n))},o.prototype.suspense=function(e,t,n){return void 0===t&&(t=null),void 0===n&&(n={}),t&&!/*#__PURE__*/a.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(n,t),t=null),/*#__PURE__*/a.default.createElement(v,d({promise:this,callback:e,fallback:t},n))},i.prototype.suspense=function(e,t,n){return void 0===t&&(t=null),void 0===n&&(n={}),t&&!/*#__PURE__*/a.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(n,t),t=null),/*#__PURE__*/a.default.createElement(v,d({promise:this,callback:e,fallback:t},n))},u.prototype.suspense=function(e,t,n){return void 0===t&&(t=null),void 0===n&&(n={}),t&&!/*#__PURE__*/a.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(n,t),t=null),/*#__PURE__*/a.default.createElement(v,d({promise:this,callback:e,fallback:t},n))},l.prototype.suspense=function(e,t,n){return void 0===t&&(t=null),void 0===n&&(n={}),t&&!/*#__PURE__*/a.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(n,t),t=null),/*#__PURE__*/a.default.createElement(v,d({promise:this,callback:e,fallback:t},n))},s.prototype.renderInput=function(e){void 0===e&&(e={});var n,r=Object.getPrototypeOf(this).constructor,o=this.InputComponent||r.InputComponent;return o||(o=null==(n=t.fields[r.__fieldType])?void 0:n.input),o?/*#__PURE__*/a.default.createElement(o,d({},e,{field:this})):null},s.prototype.renderView=function(e){void 0===e&&(e={});var n,r=Object.getPrototypeOf(this).constructor,o=this.ViewComponent||r.ViewComponent;return o||(o=null==(n=t.fields[r.__fieldType])?void 0:n.view),o?/*#__PURE__*/a.default.createElement(o,d({},e,{field:this})):"string"==typeof e.value?e.value:null},o.prototype.renderFieldView=function(e,t,n){void 0===n&&(n={});var r=Object.getPrototypeOf(this).constructor;t&&"object"==typeof t&&(Object.assign(n,t),t=void 0);var o=r.fields&&r.fields[e];return(null==o?void 0:o.renderView({value:this.get(e,t),item:this,slug:e,options:n}))||null},o.prototype.renderFieldInput=function(e,t,n){void 0===n&&(n={});var r=Object.getPrototypeOf(this).constructor;t&&"object"==typeof t&&(Object.assign(n,t),t=void 0);var o=r.fields&&r.fields[e];return(null==o?void 0:o.renderInput({value:this.get(e,t),item:this,slug:e,options:n}))||null}}};e.GraphandForm=b,e.GraphandPluginReact=h,e.PromiseSuspense=v,e.default=h,e.useList=function(e,t,r){void 0===t&&(t={});var o,i=n.useState([]),u=i[0],s=i[1],l=n.useState(!1)[0];return n.useEffect(function(){return e.getList(t).then(s).then(function(e){return e&&(o=e.subscribe(s))}),function(){var e;return null==(e=o)?void 0:e.unsubscribe()}}),[u,l]}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("fast-deep-equal/react"),require("react"),require("bson"),require("lodash"),require("flatted"),require("react/jsx-runtime")):"function"==typeof define&&define.amd?define(["exports","fast-deep-equal/react","react","bson","lodash","flatted","react/jsx-runtime"],t):t((e||self).graphandReact={},e.isEqual,e.react,e.bson,e.lodash,e.flatted,e.jsxRuntime)}(this,function(e,t,r,n,o,i,u){function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=/*#__PURE__*/s(t),a=/*#__PURE__*/s(r),c=/*#__PURE__*/s(o);function d(){return d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},d.apply(this,arguments)}function f(e,t){return f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},f(e,t)}function p(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var v=/*#__PURE__*/function(e){var t,r;function n(t){var r;return(r=e.call(this,t)||this).state={res:void 0,loading:!1,error:null},r.setRes=function(e,t){void 0===t&&(t=null);try{return Promise.resolve(new Promise(function(n){!1!==r.props.debounce?(r.state.loading||r.setState({loading:!0}),r.debounceTimeout&&clearTimeout(r.debounceTimeout),r.debounceTimeout=setTimeout(function(){r.setState({res:e,loading:!1,error:t},n)},r.props.debounce)):r.setState({res:e,loading:!1,error:t},n)}))}catch(e){return Promise.reject(e)}},r.update=function(){try{var e=function(){r.updating=!1};r.updating=!0,r.setState({loading:!0});var t=r.props.promise,n=p(function(){function e(){var e=function(){var e,t;if(o)return null!=(e=r.subscription)&&e.unsubscribe&&r.subscription.unsubscribe(),r.props.subscribe&&null!=(t=n)&&t.subscribe&&(r.subscription=n.subscribe(r.setRes)),Promise.resolve(new Promise(function(e){return r.setRes(n,e)})).then(function(){});var i=function(){if(r.state.loading)return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})}();return i&&i.then?i.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}var n,o=!0,i=r.props.checkUpdate?Promise.resolve(Promise.all([t,r.props.promise])).then(function(e){var t=e[0];o=!l.default(t,e[1]),n=t}):Promise.resolve(t).then(function(e){n=e});return i&&i.then?i.then(e):e()},function(){return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})});return Promise.resolve(n&&n.then?n.then(e):e())}catch(e){return Promise.reject(e)}},t.promise&&void 0===t.promise.then&&(r.state.res=t.promise),r}r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,f(t,r);var o=n.prototype;return o.componentDidMount=function(){try{var e=this,t=p(function(){function t(){var t,n;null!=(t=e.subscription)&&t.unsubscribe&&e.subscription.unsubscribe(),e.props.subscribe&&null!=(n=r)&&n.subscribe&&(e.subscription=r.subscribe(e.setRes))}var r=e.props.promise,n=function(){var t,n;if(e.props.promise&&void 0!==e.props.promise.then||!l.default(null==(t=e.state.res)?void 0:t.query,null==(n=e.props.promise)?void 0:n.query))return Promise.resolve(e.props.promise).then(function(t){e.setRes(r=t)})}();return n&&n.then?n.then(t):t()},function(t){console.error(t),e.setRes(void 0,t)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},o.getUpdateKey=function(e){var t,r;if(e.updateKey)return e.updateKey;var n,o,i=[];return null!=(t=e.promise)&&t.model&&i.push(null==(n=e.promise)?void 0:n.model),null!=(r=e.promise)&&r.query&&i.push(null==(o=e.promise)?void 0:o.query),i},o.componentDidUpdate=function(e,t){try{var r=this;return(!l.default(r.getUpdateKey(r.props),r.getUpdateKey(e))||r.props.update&&!r.updating)&&r.update(),Promise.resolve()}catch(e){return Promise.reject(e)}},o.componentWillUnmount=function(){var e;null!=(e=this.subscription)&&e.unsubscribe&&this.subscription.unsubscribe()},o.renderCallback=function(){var e=this.props.callback||this.props.children;return"function"==typeof e?e(this.state.res,this.state.loading,this.state.error):e},o.renderFallback=function(){var e=this.props.fallback;return"function"==typeof e?e(this.state.res,this.state.loading,this.state.error):e},o.render=function(){var e=void 0===this.state.res?this.renderFallback():this.renderCallback();return void 0!==e?e:null},n}(a.default.Component);v.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!1,checkUpdate:!1,debounce:!1};var m=function(e){var t,o,s,f=e.template,p=e.children,v=e.fields,m=e.model,b=e.instance,h=e.map,y=e.controls,g=e.translatable,P=e.values,j=e.fieldsOptions,O=e.onChange,S=e.onSubmit,k=e.processErrors,E=e.resetAfterSubmit,R=!(!P||!O);m=m||(null==b?void 0:b.constructor),v="function"==typeof v?v(m.fields):v||m.fields;var C=r.useRef(b||(null==(t=m)?void 0:t.hydrate(P))||null),w=r.useRef([]),V=r.useRef(),q=r.useRef((null==(o=C.current)?void 0:o._id)||(new n.ObjectID).toString()),F=r.useState(!1),_=F[0],x=F[1],T=r.useState([]),I=T[0],L=T[1],A=r.useState(P||(null==(s=C.current)?void 0:s.toJSON())||{}),G=A[0],U=A[1],D=r.useState(!0),K=D[0],M=D[1];P=R?P:G;var N=q.current;r.useEffect(function(){try{var e=function(){K&&M(!1)},t=function(){if(m)return Promise.resolve(m.init()).then(function(){})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(e){return Promise.reject(e)}},[]);var $=function(e){var t;return null==(t=w.current)?void 0:t.includes(e)},B={id:N,values:P,instance:C.current,formRef:V.current,isModified:$},J=function(e,t,r,n){void 0===r&&(r={}),void 0===n&&(n=!0);var o=Object.assign({},r,e.inputOptions,j&&j[t]);if(o.hidden)return null;var i=P[t],u=n?e.getter(i,C.current,t):i,s={errors:I.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)}),value:u,onChange:function(e){return W(t,e)},options:o,id:N+":"+t,slug:t,handleSubmit:z};return e.renderInput(s)},z=function(t){try{t&&(t.preventDefault(),t.stopPropagation());var r=function(t,r){try{var n=(i=w.current.reduce(function(t,r){var n=c.default.get(P,r),o=c.default.get(e.values||{},r);return void 0===n&&o!==n?(t.$unset=t.$unset||{},t.$unset[r]=!0,delete t[r]):t[r]=n,t},{}),x(!0),L([]),null!=(o=m)&&o.beforeFormSubmit&&m.beforeFormSubmit(i,B),Promise.resolve(S(i)).then(function(){var t,r;(E=null!=(t=E)?t:!!C.current)&&U(e.values||(null==(r=C.current)?void 0:r.toJSON())||{}),x(!1)}))}catch(e){return r(e)}var o,i;return n&&n.then?n.then(void 0,r):n}(0,function(e){var t=k(e.graphandErrors||[]);x(!1),L(t)});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},W=function(e,t){try{var r,n=H(e,t);return $(e)&&n?w.current=w.current.filter(function(t){return t!==e}):n||$(e)||w.current.push(e),Promise.resolve(function(e,t){void 0===t&&(t=!1);try{var r,n=function(){var e;null!=(e=m)&&e.afterFormChange&&m.afterFormChange(P,B)};void 0===e&&(e=P),null!=(r=m)&&r.beforeFormChange&&m.beforeFormChange(e,B);var o=function(){if(R)return Promise.resolve(O(e,t)).then(function(){});U(e)}();return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}}(d({},P,(r={},r[e]=t,r)))).then(function(){})}catch(e){return Promise.reject(e)}},H=function(e,t){var r,n=null==(r=C.current)?void 0:r.get(e,!0),o=i.stringify(n),u=i.stringify(t);return l.default(o,u)},Q=f||p||function(t){/*#__PURE__*/return u.jsxs("form",{ref:t.formRef,onSubmit:t.handleSubmit,children:[t.fields.renderDefault(),"function"==typeof y?y(e):y||null]})};/*#__PURE__*/return a.default.isValidElement(Q)||Array.isArray(Q)&&Q.every(function(e){/*#__PURE__*/return a.default.isValidElement(e)})?/*#__PURE__*/u.jsx("form",{ref:V,onSubmit:z,children:Q}):Q({fields:Object.keys(v).reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=function(e,r){return void 0===e&&(e={}),J(v[t],t,e,r)},r))},{render:function(e,t,r){return void 0===t&&(t={}),J(v[e],e,t,r)},renderDefault:function(){var e;return(h=null!=(e=h)?e:Object.keys(v).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)})).map(function(e){return J(v[e],e)})}}),isLoading:_,isInitializing:K,errors:I,handleSubmit:z,isTranslatable:g,formRef:V,values:P,modified:w.current||[]})};m.defaultProps={model:null,fields:null,map:null,fieldsOptions:{},getFieldOptions:null,instance:null,errors:[],onSubmit:function(){return null},submitLabel:"Valider",template:null,resetAfterSubmit:void 0,preventLeave:!1,translatable:!1,values:void 0,onChange:void 0,processErrors:function(e){return e},controls:function(e){return[/*#__PURE__*/u.jsx("button",{className:"btn btn-primary",type:"submit",children:e.submitLabel})]}};var b={options:{types:{}},__construct:function(e,t){void 0===t&&(t={});var r=e.constructor.lib,n=r.GraphandModelPromise,o=r.GraphandModel,i=r.GraphandModelListPromise,u=r.GraphandModelList,s=r.GraphandField,l=r.AggregationExecutor;s.InputComponent=null,s.ViewComponent=null,n.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/a.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/a.default.createElement(v,d({promise:this,callback:e,fallback:t},r))},o.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/a.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/a.default.createElement(v,d({promise:this,callback:e,fallback:t},r))},i.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/a.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/a.default.createElement(v,d({promise:this,callback:e,fallback:t},r))},u.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/a.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/a.default.createElement(v,d({promise:this,callback:e,fallback:t},r))},l.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!/*#__PURE__*/a.default.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),/*#__PURE__*/a.default.createElement(v,d({promise:this,callback:e,fallback:t},r))},s.prototype.renderInput=function(e){void 0===e&&(e={});var r,n=Object.getPrototypeOf(this).constructor,o=this.InputComponent||n.InputComponent;return o||(o=null==(r=t.fields[n.__fieldType])?void 0:r.input),o?/*#__PURE__*/a.default.createElement(o,d({},e,{field:this})):null},s.prototype.renderView=function(e){void 0===e&&(e={});var r,n=Object.getPrototypeOf(this).constructor,o=this.ViewComponent||n.ViewComponent;return o||(o=null==(r=t.fields[n.__fieldType])?void 0:r.view),o?/*#__PURE__*/a.default.createElement(o,d({},e,{field:this})):"string"==typeof e.value?e.value:null},o.prototype.renderFieldView=function(e,t,r){void 0===r&&(r={});var n=Object.getPrototypeOf(this).constructor;t&&"object"==typeof t&&(Object.assign(r,t),t=void 0);var o=n.fields&&n.fields[e];return(null==o?void 0:o.renderView({value:this.get(e,t),item:this,slug:e,options:r}))||null},o.prototype.renderFieldInput=function(e,t,r){void 0===r&&(r={});var n=Object.getPrototypeOf(this).constructor;t&&"object"==typeof t&&(Object.assign(r,t),t=void 0);var o=n.fields&&n.fields[e];return(null==o?void 0:o.renderInput({value:this.get(e,t),item:this,slug:e,options:r}))||null}}};e.GraphandForm=m,e.GraphandPluginReact=b,e.PromiseSuspense=v,e.default=b,e.useList=function(e,t,n){void 0===t&&(t={});var o,i=r.useState([]),u=i[0],s=i[1],l=r.useState(!1)[0];return r.useEffect(function(){return e.getList(t).then(s).then(function(e){return e&&(o=e.subscribe(s))}),function(){var e;return null==(e=o)?void 0:e.unsubscribe()}}),[u,l]}});
//# sourceMappingURL=index.umd.js.map
{
"name": "graphand-react",
"version": "0.0.18-beta",
"version": "0.0.19-beta",
"description": "",

@@ -34,3 +34,3 @@ "author": "pierrecabriere",

"eslint-plugin-standard": "^5.0.0",
"graphand-js": "^0.22.0-beta",
"graphand-js": "^0.22.1-beta",
"microbundle": "^0.14.2",

@@ -37,0 +37,0 @@ "prettier": "^2.5.1"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc