graphand-react
Advanced tools
Comparing version 0.0.22-beta to 0.0.23-beta
@@ -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(function(e){return r.setRes(e)})),Promise.resolve(new Promise(function(e){return r.setRes(n).finally(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(function(t){return e.setRes(t)}))}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,p=e.template,v=e.children,m=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,k=e.onSubmit,E=e.processErrors,C=e.resetAfterSubmit,R=!(!j||!S);b=b||(null==h?void 0:h.constructor),m="function"==typeof m?m(b.fields):m||b.fields,y=null!=(n=y)?n:Object.keys(m).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)}),m=y.reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=m[t],r))},{});var w=t.useRef(h||(null==(u=b)?void 0:u.hydrate(j))||null),V=t.useRef([]),F=t.useRef(),_=t.useRef((null==(d=w.current)?void 0:d._id)||(new r.ObjectID).toString()),q=t.useState(!1),x=q[0],I=q[1],L=t.useState([]),T=L[0],A=L[1],G=t.useState(j||(null==(f=w.current)?void 0:f.toJSON())||{}),U=G[0],D=G[1],K=t.useState(!0),M=K[0],N=K[1];j=R?j:U;var $=_.current;t.useEffect(function(){try{var e=function(){M&&N(!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 B=function(e){var t;return null==(t=V.current)?void 0:t.includes(e)},J={id:$,values:j,instance:w.current,formRef:F.current,isModified:B},z=function(e,t,r,n){if(void 0===r&&(r={}),void 0===n&&(n=!1),!e)return console.error("field "+t+" not found, render null"),null;var o=Object.assign({},r,e.inputOptions,O&&O[t]);if(o.hidden)return null;var i=j[t],u=n?e.getter(i,w.current,t):i,s={errors:T.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)}),value:u,onChange:function(e){return H(t,e)},options:o,id:$+":"+t,slug:t,instance:w.current,handleSubmit:W};return e.renderInput(s)},W=function(t){try{t&&(t.preventDefault(),t.stopPropagation());var r=function(t,r){try{var n=(i=V.current.reduce(function(t,r){var n=a.default.get(j,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},{}),I(!0),A([]),null!=(o=b)&&o.beforeFormSubmit&&b.beforeFormSubmit(i,J),Promise.resolve(k(i)).then(function(){var t,r;(C=null!=(t=C)?t:!!w.current)&&D(e.values||(null==(r=w.current)?void 0:r.toJSON())||{}),I(!1)}))}catch(e){return r(e)}var o,i;return n&&n.then?n.then(void 0,r):n}(0,function(e){var t=E(e.graphandErrors||[]);I(!1),A(t)});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},H=function(e,t){try{var r,n=Q(e,t);return B(e)&&n?V.current=V.current.filter(function(t){return t!==e}):n||B(e)||V.current.push(e),Promise.resolve(function(e,t){void 0===t&&(t=!1);try{var r,n=function(){var e;null!=(e=b)&&e.afterFormChange&&b.afterFormChange(j,J)};void 0===e&&(e=j),null!=(r=b)&&r.beforeFormChange&&b.beforeFormChange(e,J);var o=function(){if(R)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)}}(c({},j,(r={},r[e]=t,r)))).then(function(){})}catch(e){return Promise.reject(e)}},Q=function(e,t){var r,n=null==(r=w.current)?void 0:r.get(e,!0),i=o.stringify(n),u=o.stringify(t);return s.default(i,u)},X=p||v||function(t){/*#__PURE__*/return i.jsxs("form",{ref:t.formRef,onSubmit:t.handleSubmit,children:[t.fields.renderDefault(),"function"==typeof g?g(e):g||null]})};/*#__PURE__*/return l.default.isValidElement(X)||Array.isArray(X)&&X.every(function(e){/*#__PURE__*/return l.default.isValidElement(e)})?/*#__PURE__*/i.jsx("form",{ref:F,onSubmit:W,children:X}):X((console.log(Object.keys(m)),{fields:Object.keys(m).reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=function(e,r){return void 0===e&&(e={}),z(m[t],t,e,r)},r))},{render:function(e,t,r){return void 0===t&&(t={}),z(m[e],e,t,r)},renderDefault:function(){return Object.keys(m).map(function(e){return z(m[e],e)})}}),isLoading:x,isInitializing:M,errors:T,handleSubmit:W,isTranslatable:P,formRef:F,values:j,modified:V.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 f(e,t){return f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},f(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 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=d(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(function(e){return r.setRes(e)})),Promise.resolve(new Promise(function(e){return r.setRes(n).finally(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,f(t,r);var o=n.prototype;return o.componentDidMount=function(){try{var e=this,t=d(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(function(t){return e.setRes(t)}))}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,f,d,p=e.template,v=e.children,m=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,k=e.onSubmit,E=e.processErrors,R=e.resetAfterSubmit,w=e.delaySubmit,C=!(!j||!S);b=b||(null==h?void 0:h.constructor),m="function"==typeof m?m(b.fields):m||b.fields,y=null!=(n=y)?n:Object.keys(m).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)}),m=y.reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=m[t],r))},{});var V=t.useRef(h||(null==(u=b)?void 0:u.hydrate(j))||null),F=t.useRef([]),_=t.useRef(),q=t.useRef({}),x=t.useRef((null==(f=V.current)?void 0:f._id)||(new r.ObjectID).toString()),I=t.useState(!1),T=I[0],L=I[1],A=t.useState([]),G=A[0],U=A[1],D=t.useState(j||(null==(d=V.current)?void 0:d.raw)||{}),K=D[0],M=D[1],$=t.useState(!0),B=$[0],N=$[1];j=C?j:K;var z=x.current,J=q.current;t.useEffect(function(){try{var e=function(){B&&N(!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 W=function(e){var t;return null==(t=F.current)?void 0:t.includes(e)},H={id:z,values:j,instance:V.current,formRef:_.current,isModified:W},Q=function(e,t,r,n){if(void 0===r&&(r={}),void 0===n&&(n=!1),!e)return console.error("field "+t+" not found, render null"),null;var o=Object.assign({},r,e.inputOptions,O&&O[t]);if(o.hidden)return null;var i=j[t],u=n?e.getter(i,V.current,t):i,s=G.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)});J[t]={current:void 0};var l={errors:s,value:u,onChange:function(e){return Y(t,e)},options:o,formRef:_,id:z+":"+t,slug:t,instance:V.current,handleSubmit:X,inputRef:J[t]};return e.renderInput(l)},X=function(t){try{var r=function(){var t=function(t,r){try{var n=(i=F.current.reduce(function(t,r){var n=a.default.get(j,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},{}),null!=(o=b)&&o.beforeFormSubmit&&b.beforeFormSubmit(i,H),Promise.resolve(k(i)).then(function(){var t,r;(R=null!=(t=R)?t:!!V.current)&&M(e.values||(null==(r=V.current)?void 0:r.toJSON())||{}),L(!1)}))}catch(e){return r(e)}var o,i;return n&&n.then?n.then(void 0,r):n}(0,function(e){var t=E(e.graphandErrors||[]);L(!1),U(t)});if(t&&t.then)return t.then(function(){})};t&&(t.preventDefault(),t.stopPropagation()),L(!0),U([]);var n=function(){if(w)return Promise.resolve(new Promise(function(e){return setTimeout(e)})).then(function(){})}();return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},Y=function(e,t){try{var r,n=Z(e,t);return W(e)&&n?F.current=F.current.filter(function(t){return t!==e}):n||W(e)||F.current.push(e),Promise.resolve(function(e,t){void 0===t&&(t=!1);try{var r,n=function(){var e;null!=(e=b)&&e.afterFormChange&&b.afterFormChange(j,H)};void 0===e&&(e=j),null!=(r=b)&&r.beforeFormChange&&b.beforeFormChange(e,H);var o=function(){if(C)return Promise.resolve(S(e,t)).then(function(){});M(e)}();return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}}(c({},j,(r={},r[e]=t,r)))).then(function(){})}catch(e){return Promise.reject(e)}},Z=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)},ee=p||v||function(t){/*#__PURE__*/return i.jsxs("form",{ref:t.formRef,onSubmit:t.handleSubmit,children:[t.fields.renderDefault(),"function"==typeof g?g(e):g||null]})};/*#__PURE__*/return l.default.isValidElement(ee)||Array.isArray(ee)&&ee.every(function(e){/*#__PURE__*/return l.default.isValidElement(e)})?/*#__PURE__*/i.jsx("form",{ref:_,onSubmit:X,children:ee}):ee({fields:Object.keys(m).reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=function(e,r){return void 0===e&&(e={}),Q(m[t],t,e,r)},r))},{render:function(e,t,r){return void 0===t&&(t={}),Q(m[e],e,t,r)},renderDefault:function(){return Object.keys(m).map(function(e){return Q(m[e],e)})}}),isLoading:T,isInitializing:B,errors:G,handleSubmit:X,isTranslatable:P,formRef:_,values:j,modified:F.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(function(e){return n.setRes(e)})),Promise.resolve(new Promise(function(e){return n.setRes(o).finally(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(function(e){return t.setRes(e)}))}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,b=p.template,h=p.children,y=p.fields,g=p.model,P=p.instance,j=p.map,O=p.controls,k=p.translatable,S=p.values,E=p.fieldsOptions,C=p.onChange,w=p.onSubmit,V=p.processErrors,F=p.resetAfterSubmit,_=!(!S||!C);g=g||(null==P?void 0:P.constructor),y="function"==typeof y?y(g.fields):y||g.fields,j=null!=(d=j)?d:Object.keys(y).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)}),y=j.reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=y[t],r))},{});var R=r(P||(null==(f=g)?void 0:f.hydrate(S))||null),I=r([]),T=r(),A=r((null==(v=R.current)?void 0:v._id)||(new i).toString()),L=n(!1),U=L[0],K=L[1],M=n([]),q=M[0],D=M[1],G=n(S||(null==(m=R.current)?void 0:m.toJSON())||{}),x=G[0],N=G[1],$=n(!0),B=$[0],J=$[1];S=_?S:x;var z=A.current;o(function(){try{var e=function(){B&&J(!1)},t=function(){if(g)return Promise.resolve(g.init()).then(function(){})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(e){return Promise.reject(e)}},[]);var W=function(e){var t;return null==(t=I.current)?void 0:t.includes(e)},H={id:z,values:S,instance:R.current,formRef:T.current,isModified:W},Q=function(e,t,r,n){if(void 0===r&&(r={}),void 0===n&&(n=!1),!e)return console.error("field "+t+" not found, render null"),null;var o=Object.assign({},r,e.inputOptions,E&&E[t]);if(o.hidden)return null;var i=S[t],u=n?e.getter(i,R.current,t):i,s={errors:q.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)}),value:u,onChange:function(e){return Y(t,e)},options:o,id:z+":"+t,slug:t,instance:R.current,handleSubmit:X};return e.renderInput(s)},X=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(S,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},{}),K(!0),D([]),null!=(n=g)&&n.beforeFormSubmit&&g.beforeFormSubmit(o,H),Promise.resolve(w(o)).then(function(){var e,t;(F=null!=(e=F)?e:!!R.current)&&N(p.values||(null==(t=R.current)?void 0:t.toJSON())||{}),K(!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||[]);K(!1),D(t)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},Y=function(e,t){try{var r,n=Z(e,t);return W(e)&&n?I.current=I.current.filter(function(t){return t!==e}):n||W(e)||I.current.push(e),Promise.resolve(function(e,t){void 0===t&&(t=!1);try{var r,n=function(){var e;null!=(e=g)&&e.afterFormChange&&g.afterFormChange(S,H)};void 0===e&&(e=S),null!=(r=g)&&r.beforeFormChange&&g.beforeFormChange(e,H);var o=function(){if(_)return Promise.resolve(C(e,t)).then(function(){});N(e)}();return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}}(a({},S,(r={},r[e]=t,r)))).then(function(){})}catch(e){return Promise.reject(e)}},Z=function(t,r){var n,o=null==(n=R.current)?void 0:n.get(t,!0),i=s(o),u=s(r);return e(i,u)},ee=b||h||function(e){/*#__PURE__*/return c("form",{ref:e.formRef,onSubmit:e.handleSubmit,children:[e.fields.renderDefault(),"function"==typeof O?O(p):O||null]})};/*#__PURE__*/return t.isValidElement(ee)||Array.isArray(ee)&&ee.every(function(e){/*#__PURE__*/return t.isValidElement(e)})?/*#__PURE__*/l("form",{ref:T,onSubmit:X,children:ee}):ee((console.log(Object.keys(y)),{fields:Object.keys(y).reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=function(e,r){return void 0===e&&(e={}),Q(y[t],t,e,r)},r))},{render:function(e,t,r){return void 0===t&&(t={}),Q(y[e],e,t,r)},renderDefault:function(){return Object.keys(y).map(function(e){return Q(y[e],e)})}}),isLoading:U,isInitializing:B,errors:q,handleSubmit:X,isTranslatable:k,formRef:T,values:S,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 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 d=/*#__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=p(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(function(e){return n.setRes(e)})),Promise.resolve(new Promise(function(e){return n.setRes(o).finally(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,f(r,n);var i=o.prototype;return i.componentDidMount=function(){try{var t=this,r=p(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(function(e){return t.setRes(e)}))}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);d.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!1,checkUpdate:!1,debounce:!1};var v=function(f){var p,d,v,m,b=f.template,h=f.children,y=f.fields,g=f.model,P=f.instance,j=f.map,O=f.controls,k=f.translatable,S=f.values,E=f.fieldsOptions,w=f.onChange,C=f.onSubmit,V=f.processErrors,F=f.resetAfterSubmit,R=f.delaySubmit,_=!(!S||!w);g=g||(null==P?void 0:P.constructor),y="function"==typeof y?y(g.fields):y||g.fields,j=null!=(p=j)?p:Object.keys(y).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)}),y=j.reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=y[t],r))},{});var T=r(P||(null==(d=g)?void 0:d.hydrate(S))||null),I=r([]),A=r(),L=r({}),U=r((null==(v=T.current)?void 0:v._id)||(new i).toString()),K=n(!1),M=K[0],q=K[1],D=n([]),G=D[0],x=D[1],$=n(S||(null==(m=T.current)?void 0:m.raw)||{}),B=$[0],N=$[1],z=n(!0),J=z[0],W=z[1];S=_?S:B;var H=U.current,Q=L.current;o(function(){try{var e=function(){J&&W(!1)},t=function(){if(g)return Promise.resolve(g.init()).then(function(){})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(e){return Promise.reject(e)}},[]);var X=function(e){var t;return null==(t=I.current)?void 0:t.includes(e)},Y={id:H,values:S,instance:T.current,formRef:A.current,isModified:X},Z=function(e,t,r,n){if(void 0===r&&(r={}),void 0===n&&(n=!1),!e)return console.error("field "+t+" not found, render null"),null;var o=Object.assign({},r,e.inputOptions,E&&E[t]);if(o.hidden)return null;var i=S[t],u=n?e.getter(i,T.current,t):i,s=G.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)});Q[t]={current:void 0};var l={errors:s,value:u,onChange:function(e){return te(t,e)},options:o,formRef:A,id:H+":"+t,slug:t,instance:T.current,handleSubmit:ee,inputRef:Q[t]};return e.renderInput(l)},ee=function(e){try{var t=function(){var e=function(e,t){try{var r=(o=I.current.reduce(function(e,t){var r=u.get(S,t),n=u.get(f.values||{},t);return void 0===r&&n!==r?(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]):e[t]=r,e},{}),null!=(n=g)&&n.beforeFormSubmit&&g.beforeFormSubmit(o,Y),Promise.resolve(C(o)).then(function(){var e,t;(F=null!=(e=F)?e:!!T.current)&&N(f.values||(null==(t=T.current)?void 0:t.toJSON())||{}),q(!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||[]);q(!1),x(t)});if(e&&e.then)return e.then(function(){})};e&&(e.preventDefault(),e.stopPropagation()),q(!0),x([]);var r=function(){if(R)return Promise.resolve(new Promise(function(e){return setTimeout(e)})).then(function(){})}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},te=function(e,t){try{var r,n=re(e,t);return X(e)&&n?I.current=I.current.filter(function(t){return t!==e}):n||X(e)||I.current.push(e),Promise.resolve(function(e,t){void 0===t&&(t=!1);try{var r,n=function(){var e;null!=(e=g)&&e.afterFormChange&&g.afterFormChange(S,Y)};void 0===e&&(e=S),null!=(r=g)&&r.beforeFormChange&&g.beforeFormChange(e,Y);var o=function(){if(_)return Promise.resolve(w(e,t)).then(function(){});N(e)}();return Promise.resolve(o&&o.then?o.then(n):n())}catch(e){return Promise.reject(e)}}(a({},S,(r={},r[e]=t,r)))).then(function(){})}catch(e){return Promise.reject(e)}},re=function(t,r){var n,o=null==(n=T.current)?void 0:n.get(t,!0),i=s(o),u=s(r);return e(i,u)},ne=b||h||function(e){/*#__PURE__*/return c("form",{ref:e.formRef,onSubmit:e.handleSubmit,children:[e.fields.renderDefault(),"function"==typeof O?O(f):O||null]})};/*#__PURE__*/return t.isValidElement(ne)||Array.isArray(ne)&&ne.every(function(e){/*#__PURE__*/return t.isValidElement(e)})?/*#__PURE__*/l("form",{ref:A,onSubmit:ee,children:ne}):ne({fields:Object.keys(y).reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=function(e,r){return void 0===e&&(e={}),Z(y[t],t,e,r)},r))},{render:function(e,t,r){return void 0===t&&(t={}),Z(y[e],e,t,r)},renderDefault:function(){return Object.keys(y).map(function(e){return Z(y[e],e)})}}),isLoading:M,isInitializing:J,errors:G,handleSubmit:ee,isTranslatable:k,formRef:A,values:S,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(d,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(d,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(d,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(d,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(d,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,d 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(function(e){return n.setRes(e)})),Promise.resolve(new Promise(function(e){return n.setRes(r).finally(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(function(t){return e.setRes(t)}))}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=function(e){var t,o,s,f,p=e.template,v=e.children,m=e.fields,b=e.model,h=e.instance,y=e.map,g=e.controls,j=e.translatable,P=e.values,O=e.fieldsOptions,S=e.onChange,k=e.onSubmit,E=e.processErrors,R=e.resetAfterSubmit,C=!(!P||!S);b=b||(null==h?void 0:h.constructor),m="function"==typeof m?m(b.fields):m||b.fields,y=null!=(t=y)?t:Object.keys(m).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)}),m=y.reduce(function(e,t){var n;return Object.assign(e,((n={})[t]=m[t],n))},{});var w=n.useRef(h||(null==(o=b)?void 0:o.hydrate(P))||null),V=n.useRef([]),q=n.useRef(),F=n.useRef((null==(s=w.current)?void 0:s._id)||(new r.ObjectID).toString()),_=n.useState(!1),x=_[0],T=_[1],I=n.useState([]),L=I[0],A=I[1],G=n.useState(P||(null==(f=w.current)?void 0:f.toJSON())||{}),U=G[0],D=G[1],K=n.useState(!0),M=K[0],N=K[1];P=C?P:U;var $=F.current;n.useEffect(function(){try{var e=function(){M&&N(!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 B=function(e){var t;return null==(t=V.current)?void 0:t.includes(e)},J={id:$,values:P,instance:w.current,formRef:q.current,isModified:B},z=function(e,t,n,r){if(void 0===n&&(n={}),void 0===r&&(r=!1),!e)return console.error("field "+t+" not found, render null"),null;var o=Object.assign({},n,e.inputOptions,O&&O[t]);if(o.hidden)return null;var i=P[t],u=r?e.getter(i,w.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 H(t,e)},options:o,id:$+":"+t,slug:t,instance:w.current,handleSubmit:W};return e.renderInput(s)},W=function(t){try{t&&(t.preventDefault(),t.stopPropagation());var n=function(t,n){try{var r=(i=V.current.reduce(function(t,n){var r=c.default.get(P,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},{}),T(!0),A([]),null!=(o=b)&&o.beforeFormSubmit&&b.beforeFormSubmit(i,J),Promise.resolve(k(i)).then(function(){var t,n;(R=null!=(t=R)?t:!!w.current)&&D(e.values||(null==(n=w.current)?void 0:n.toJSON())||{}),T(!1)}))}catch(e){return n(e)}var o,i;return r&&r.then?r.then(void 0,n):r}(0,function(e){var t=E(e.graphandErrors||[]);T(!1),A(t)});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},H=function(e,t){try{var n,r=Q(e,t);return B(e)&&r?V.current=V.current.filter(function(t){return t!==e}):r||B(e)||V.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(P,J)};void 0===e&&(e=P),null!=(n=b)&&n.beforeFormChange&&b.beforeFormChange(e,J);var o=function(){if(C)return Promise.resolve(S(e,t)).then(function(){});D(e)}();return Promise.resolve(o&&o.then?o.then(r):r())}catch(e){return Promise.reject(e)}}(d({},P,(n={},n[e]=t,n)))).then(function(){})}catch(e){return Promise.reject(e)}},Q=function(e,t){var n,r=null==(n=w.current)?void 0:n.get(e,!0),o=i.stringify(r),u=i.stringify(t);return l.default(o,u)},X=p||v||function(t){/*#__PURE__*/return u.jsxs("form",{ref:t.formRef,onSubmit:t.handleSubmit,children:[t.fields.renderDefault(),"function"==typeof g?g(e):g||null]})};/*#__PURE__*/return a.default.isValidElement(X)||Array.isArray(X)&&X.every(function(e){/*#__PURE__*/return a.default.isValidElement(e)})?/*#__PURE__*/u.jsx("form",{ref:q,onSubmit:W,children:X}):X((console.log(Object.keys(m)),{fields:Object.keys(m).reduce(function(e,t){var n;return Object.assign(e,((n={})[t]=function(e,n){return void 0===e&&(e={}),z(m[t],t,e,n)},n))},{render:function(e,t,n){return void 0===t&&(t={}),z(m[e],e,t,n)},renderDefault:function(){return Object.keys(m).map(function(e){return z(m[e],e)})}}),isLoading:x,isInitializing:M,errors:L,handleSubmit:W,isTranslatable:j,formRef:q,values:P,modified:V.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 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=m,e.GraphandPluginReact=b,e.PromiseSuspense=v,e.default=b,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,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 f(){return f=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},f.apply(this,arguments)}function d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(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(function(e){return n.setRes(e)})),Promise.resolve(new Promise(function(e){return n.setRes(r).finally(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,d(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(function(t){return e.setRes(t)}))}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=function(e){var t,o,s,d,p=e.template,v=e.children,m=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,k=e.onSubmit,E=e.processErrors,R=e.resetAfterSubmit,w=e.delaySubmit,C=!(!j||!S);b=b||(null==h?void 0:h.constructor),m="function"==typeof m?m(b.fields):m||b.fields,y=null!=(t=y)?t:Object.keys(m).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)}),m=y.reduce(function(e,t){var n;return Object.assign(e,((n={})[t]=m[t],n))},{});var V=n.useRef(h||(null==(o=b)?void 0:o.hydrate(j))||null),q=n.useRef([]),F=n.useRef(),_=n.useRef({}),x=n.useRef((null==(s=V.current)?void 0:s._id)||(new r.ObjectID).toString()),T=n.useState(!1),I=T[0],L=T[1],A=n.useState([]),G=A[0],U=A[1],D=n.useState(j||(null==(d=V.current)?void 0:d.raw)||{}),K=D[0],M=D[1],$=n.useState(!0),B=$[0],N=$[1];j=C?j:K;var z=x.current,J=_.current;n.useEffect(function(){try{var e=function(){B&&N(!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 W=function(e){var t;return null==(t=q.current)?void 0:t.includes(e)},H={id:z,values:j,instance:V.current,formRef:F.current,isModified:W},Q=function(e,t,n,r){if(void 0===n&&(n={}),void 0===r&&(r=!1),!e)return console.error("field "+t+" not found, render null"),null;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=G.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)});J[t]={current:void 0};var l={errors:s,value:u,onChange:function(e){return Y(t,e)},options:o,formRef:F,id:z+":"+t,slug:t,instance:V.current,handleSubmit:X,inputRef:J[t]};return e.renderInput(l)},X=function(t){try{var n=function(){var t=function(t,n){try{var r=(i=q.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},{}),null!=(o=b)&&o.beforeFormSubmit&&b.beforeFormSubmit(i,H),Promise.resolve(k(i)).then(function(){var t,n;(R=null!=(t=R)?t:!!V.current)&&M(e.values||(null==(n=V.current)?void 0:n.toJSON())||{}),L(!1)}))}catch(e){return n(e)}var o,i;return r&&r.then?r.then(void 0,n):r}(0,function(e){var t=E(e.graphandErrors||[]);L(!1),U(t)});if(t&&t.then)return t.then(function(){})};t&&(t.preventDefault(),t.stopPropagation()),L(!0),U([]);var r=function(){if(w)return Promise.resolve(new Promise(function(e){return setTimeout(e)})).then(function(){})}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},Y=function(e,t){try{var n,r=Z(e,t);return W(e)&&r?q.current=q.current.filter(function(t){return t!==e}):r||W(e)||q.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,H)};void 0===e&&(e=j),null!=(n=b)&&n.beforeFormChange&&b.beforeFormChange(e,H);var o=function(){if(C)return Promise.resolve(S(e,t)).then(function(){});M(e)}();return Promise.resolve(o&&o.then?o.then(r):r())}catch(e){return Promise.reject(e)}}(f({},j,(n={},n[e]=t,n)))).then(function(){})}catch(e){return Promise.reject(e)}},Z=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)},ee=p||v||function(t){/*#__PURE__*/return u.jsxs("form",{ref:t.formRef,onSubmit:t.handleSubmit,children:[t.fields.renderDefault(),"function"==typeof g?g(e):g||null]})};/*#__PURE__*/return a.default.isValidElement(ee)||Array.isArray(ee)&&ee.every(function(e){/*#__PURE__*/return a.default.isValidElement(e)})?/*#__PURE__*/u.jsx("form",{ref:F,onSubmit:X,children:ee}):ee({fields:Object.keys(m).reduce(function(e,t){var n;return Object.assign(e,((n={})[t]=function(e,n){return void 0===e&&(e={}),Q(m[t],t,e,n)},n))},{render:function(e,t,n){return void 0===t&&(t={}),Q(m[e],e,t,n)},renderDefault:function(){return Object.keys(m).map(function(e){return Q(m[e],e)})}}),isLoading:I,isInitializing:B,errors:G,handleSubmit:X,isTranslatable:P,formRef:F,values:j,modified:q.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 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,f({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,f({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,f({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,f({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,f({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,f({},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,f({},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=m,e.GraphandPluginReact=b,e.PromiseSuspense=v,e.default=b,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]}}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "graphand-react", | ||
"version": "0.0.22-beta", | ||
"version": "0.0.23-beta", | ||
"description": "", | ||
@@ -34,3 +34,3 @@ "author": "pierrecabriere", | ||
"eslint-plugin-standard": "^5.0.0", | ||
"graphand-js": "^0.22.1-beta", | ||
"graphand-js": "^0.22.8-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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
124187
141