graphand-react
Advanced tools
Comparing version 0.1.0-beta to 0.1.1-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 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,C=e.resetAfterSubmit,F=e.delaySubmit,w=!(!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 R=t.useRef(h||(null==(u=b)?void 0:u.hydrate(j))||null),V=t.useRef([]),x=t.useRef(),_=t.useRef({}),q=t.useRef({}),I=t.useRef((null==(f=R.current)?void 0:f._id)||(new r.ObjectID).toString()),T=t.useState(!1),L=T[0],A=T[1],D=t.useState([]),G=D[0],U=D[1],K=t.useState(j||(null==(d=R.current)?void 0:d.toJSON())||{}),M=K[0],N=K[1],$=t.useState(!0),B=$[0],J=$[1];j=w?j:M;var z=I.current,W=_.current;t.useEffect(function(){try{var e=function(){B&&J(!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 H,Q=function(e){var t;return null==(t=V.current)?void 0:t.includes(e)},X=function(t){try{var r=function(){var t=function(t,r){try{var n=(i=V.current.reduce(function(e,t){var r=a.default.get(j,t);return void 0===r?(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]):e[t]=r,e},{}),null!=(o=b)&&o.beforeFormSubmit&&b.beforeFormSubmit(i,Y),Promise.resolve(k(i,Y)).then(function(){var t,r;(C=null!=(t=C)?t:!!R.current)&&N(e.values||(null==(r=R.current)?void 0:r.toJSON())||{}),A(!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||[]);A(!1),U(t)});if(t&&t.then)return t.then(function(){})};t&&(t.preventDefault(),t.stopPropagation()),A(!0),U([]);var n=function(){if(F)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={id:z,values:j,instance:R.current,formRef:x,isModified:Q,isLoading:L,isInitializing:B,errors:G,handleSubmit:X,inputOptions:q.current,modified:V.current||[]},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,q.current[t],O&&O[t]);if(o.hidden)return null;var i=j[t],u=n?e.getter(i,R.current,t):i,s=G.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)});W[t]={current:void 0};var l=c({},Y,{errors:s,value:u,onChange:function(e){return ee(t,e)},options:o,id:z+":"+t,slug:t,inputRef:W[t]});return e.renderInput(l)},ee=function(e,t){try{var r=te(e,t);Q(e)&&r?V.current=V.current.filter(function(t){return t!==e}):r||Q(e)||V.current.push(e);var n=function(){var r,n,o,i;if(w)return null!=(r=b)&&r.beforeFormChange&&b.beforeFormChange(newValues,Y),Promise.resolve(S(c({},j,(n={},n[e]=t,n)))).then(function(){var e;null!=(e=b)&&e.afterFormChange&&b.afterFormChange(j,Y)});null!=(o=b)&&o.beforeFormChange&&b.beforeFormChange(newValues,Y),N(function(r){var n;return c({},r,((n={})[e]=t,n))}),null!=(i=b)&&i.afterFormChange&&b.afterFormChange(j,Y)}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},te=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)},re=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(re)||Array.isArray(re)&&re.every(function(e){/*#__PURE__*/return l.default.isValidElement(e)})?/*#__PURE__*/i.jsx("form",{ref:x,onSubmit:X,children:re}):re((H=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 t=(e=H).render,r=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(o[r]=e[r]);return o}(e,["render","renderDefault"]),Object.keys(r).map(function(e){return t(e)});var e,t,r}}),c({},Y,{fields:H,isTranslatable:P})))};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},o.renderForm=function(e){/*#__PURE__*/return l.default.createElement(v,c({},e,{model:this}))},o.prototype.renderForm=function(e){/*#__PURE__*/return l.default.createElement(v,c({},e,{instance:this,model:this.constructor}))}}};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,C=e.resetAfterSubmit,F=e.delaySubmit,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([]),x=t.useRef(),_=t.useRef({}),q=t.useRef({}),I=t.useRef((null==(f=w.current)?void 0:f._id)||(new r.ObjectID).toString()),T=t.useState(!1),L=T[0],A=T[1],D=t.useState([]),G=D[0],U=D[1],K=t.useState(j||(null==(d=w.current)?void 0:d.toJSON())||{}),M=K[0],N=K[1],$=t.useState(!0),B=$[0],J=$[1];j=R?j:M;var z=I.current,W=_.current;t.useEffect(function(){try{var e=function(){var e;B&&J(!1),null!=(e=b)&&e.onFormChange&&b.onFormChange(j,Y)},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 H,Q=function(e){var t;return null==(t=V.current)?void 0:t.includes(e)},X=function(t){try{var r=function(){var t=function(t,r){try{var n=(i=V.current.reduce(function(e,t){var r=a.default.get(j,t);return void 0===r?(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]):e[t]=r,e},{}),null!=(o=b)&&o.beforeFormSubmit&&b.beforeFormSubmit(i,Y),Promise.resolve(k(i,Y)).then(function(){var t,r;(C=null!=(t=C)?t:!!w.current)&&N(e.values||(null==(r=w.current)?void 0:r.toJSON())||{}),A(!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||[]);A(!1),U(t)});if(t&&t.then)return t.then(function(){})};t&&(t.preventDefault(),t.stopPropagation()),A(!0),U([]);var n=function(){if(F)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={id:z,values:j,instance:w.current,formRef:x,isModified:Q,isLoading:L,isInitializing:B,errors:G,handleSubmit:X,inputOptions:q.current,modified:V.current||[]},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,q.current[t],O&&O[t]);if(o.hidden)return null;var i=j[t],u=n?e.getter(i,w.current,t):i,s=G.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)});W[t]={current:void 0};var l=c({},Y,{errors:s,value:u,onChange:function(e){return ee(t,e)},options:o,id:z+":"+t,slug:t,inputRef:W[t]});return e.renderInput(l)},ee=function(e,t){try{var r=te(e,t);Q(e)&&r?V.current=V.current.filter(function(t){return t!==e}):r||Q(e)||V.current.push(e);var n=function(){if(R){var r,n,o=c({},j,((r={})[e]=t,r));return null!=(n=b)&&n.beforeFormChange&&b.beforeFormChange(o,Y),Promise.resolve(S(o)).then(function(){})}N(function(r){var n,o,i=c({},r,((n={})[e]=t,n));return null!=(o=b)&&o.beforeFormChange&&b.beforeFormChange(i,Y),i})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},te=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)},re=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(re)||Array.isArray(re)&&re.every(function(e){/*#__PURE__*/return l.default.isValidElement(e)})?/*#__PURE__*/i.jsx("form",{ref:x,onSubmit:X,children:re}):re((H=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 t=(e=H).render,r=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(o[r]=e[r]);return o}(e,["render","renderDefault"]),Object.keys(r).map(function(e){return t(e)});var e,t,r}}),c({},Y,{fields:H,isTranslatable:P})))};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},o.renderForm=function(e){/*#__PURE__*/return l.default.createElement(v,c({},e,{model:this}))},o.prototype.renderForm=function(e){/*#__PURE__*/return l.default.createElement(v,c({},e,{instance:this,model:this.constructor}))}}};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 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(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,f(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);p.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 d,p,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,E=f.values,C=f.fieldsOptions,S=f.onChange,F=f.onSubmit,w=f.processErrors,V=f.resetAfterSubmit,_=f.delaySubmit,R=!(!E||!S);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 T=r(P||(null==(p=g)?void 0:p.hydrate(E))||null),I=r([]),A=r(),L=r({}),U=r({}),D=r((null==(v=T.current)?void 0:v._id)||(new i).toString()),K=n(!1),M=K[0],q=K[1],x=n([]),G=x[0],N=x[1],$=n(E||(null==(m=T.current)?void 0:m.toJSON())||{}),B=$[0],J=$[1],z=n(!0),W=z[0],H=z[1];E=R?E:B;var Q=D.current,X=L.current;o(function(){try{var e=function(){W&&H(!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 Y,Z=function(e){var t;return null==(t=I.current)?void 0:t.includes(e)},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(E,t);return void 0===r?(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]):e[t]=r,e},{}),null!=(n=g)&&n.beforeFormSubmit&&g.beforeFormSubmit(o,te),Promise.resolve(F(o,te)).then(function(){var e,t;(V=null!=(e=V)?e:!!T.current)&&J(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=w(e.graphandErrors||[]);q(!1),N(t)});if(e&&e.then)return e.then(function(){})};e&&(e.preventDefault(),e.stopPropagation()),q(!0),N([]);var r=function(){if(_)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={id:Q,values:E,instance:T.current,formRef:A,isModified:Z,isLoading:M,isInitializing:W,errors:G,handleSubmit:ee,inputOptions:U.current,modified:I.current||[]},re=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,U.current[t],C&&C[t]);if(o.hidden)return null;var i=E[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)});X[t]={current:void 0};var l=a({},te,{errors:s,value:u,onChange:function(e){return ne(t,e)},options:o,id:Q+":"+t,slug:t,inputRef:X[t]});return e.renderInput(l)},ne=function(e,t){try{var r=oe(e,t);Z(e)&&r?I.current=I.current.filter(function(t){return t!==e}):r||Z(e)||I.current.push(e);var n=function(){var r,n,o,i;if(R)return null!=(r=g)&&r.beforeFormChange&&g.beforeFormChange(newValues,te),Promise.resolve(S(a({},E,(n={},n[e]=t,n)))).then(function(){var e;null!=(e=g)&&e.afterFormChange&&g.afterFormChange(E,te)});null!=(o=g)&&o.beforeFormChange&&g.beforeFormChange(newValues,te),J(function(r){var n;return a({},r,((n={})[e]=t,n))}),null!=(i=g)&&i.afterFormChange&&g.afterFormChange(E,te)}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},oe=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)},ie=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(ie)||Array.isArray(ie)&&ie.every(function(e){/*#__PURE__*/return t.isValidElement(e)})?/*#__PURE__*/l("form",{ref:A,onSubmit:ee,children:ie}):ie((Y=Object.keys(y).reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=function(e,r){return void 0===e&&(e={}),re(y[t],t,e,r)},r))},{render:function(e,t,r){return void 0===t&&(t={}),re(y[e],e,t,r)},renderDefault:function(){return t=(e=Y).render,r=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(o[r]=e[r]);return o}(e,["render","renderDefault"]),Object.keys(r).map(function(e){return t(e)});var e,t,r}}),a({},te,{fields:Y,isTranslatable:k})))};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(p,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(p,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(p,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(p,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(p,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},i.renderForm=function(e){/*#__PURE__*/return t.createElement(v,a({},e,{model:this}))},i.prototype.renderForm=function(e){/*#__PURE__*/return t.createElement(v,a({},e,{instance:this,model:this.constructor}))}}};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,p 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 d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(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 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=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,d(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);f.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!1,checkUpdate:!1,debounce:!1};var v=function(d){var p,f,v,m,b=d.template,h=d.children,y=d.fields,g=d.model,P=d.instance,j=d.map,O=d.controls,k=d.translatable,E=d.values,S=d.fieldsOptions,C=d.onChange,F=d.onSubmit,w=d.processErrors,V=d.resetAfterSubmit,_=d.delaySubmit,R=!(!E||!C);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==(f=g)?void 0:f.hydrate(E))||null),I=r([]),A=r(),L=r({}),U=r({}),D=r((null==(v=T.current)?void 0:v._id)||(new i).toString()),K=n(!1),M=K[0],q=K[1],x=n([]),G=x[0],N=x[1],$=n(E||(null==(m=T.current)?void 0:m.toJSON())||{}),B=$[0],J=$[1],z=n(!0),W=z[0],H=z[1];E=R?E:B;var Q=D.current,X=L.current;o(function(){try{var e=function(){var e;W&&H(!1),null!=(e=g)&&e.onFormChange&&g.onFormChange(E,te)},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 Y,Z=function(e){var t;return null==(t=I.current)?void 0:t.includes(e)},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(E,t);return void 0===r?(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]):e[t]=r,e},{}),null!=(n=g)&&n.beforeFormSubmit&&g.beforeFormSubmit(o,te),Promise.resolve(F(o,te)).then(function(){var e,t;(V=null!=(e=V)?e:!!T.current)&&J(d.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=w(e.graphandErrors||[]);q(!1),N(t)});if(e&&e.then)return e.then(function(){})};e&&(e.preventDefault(),e.stopPropagation()),q(!0),N([]);var r=function(){if(_)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={id:Q,values:E,instance:T.current,formRef:A,isModified:Z,isLoading:M,isInitializing:W,errors:G,handleSubmit:ee,inputOptions:U.current,modified:I.current||[]},re=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,U.current[t],S&&S[t]);if(o.hidden)return null;var i=E[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)});X[t]={current:void 0};var l=a({},te,{errors:s,value:u,onChange:function(e){return ne(t,e)},options:o,id:Q+":"+t,slug:t,inputRef:X[t]});return e.renderInput(l)},ne=function(e,t){try{var r=oe(e,t);Z(e)&&r?I.current=I.current.filter(function(t){return t!==e}):r||Z(e)||I.current.push(e);var n=function(){if(R){var r,n,o=a({},E,((r={})[e]=t,r));return null!=(n=g)&&n.beforeFormChange&&g.beforeFormChange(o,te),Promise.resolve(C(o)).then(function(){})}J(function(r){var n,o,i=a({},r,((n={})[e]=t,n));return null!=(o=g)&&o.beforeFormChange&&g.beforeFormChange(i,te),i})}();return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},oe=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)},ie=b||h||function(e){/*#__PURE__*/return c("form",{ref:e.formRef,onSubmit:e.handleSubmit,children:[e.fields.renderDefault(),"function"==typeof O?O(d):O||null]})};/*#__PURE__*/return t.isValidElement(ie)||Array.isArray(ie)&&ie.every(function(e){/*#__PURE__*/return t.isValidElement(e)})?/*#__PURE__*/l("form",{ref:A,onSubmit:ee,children:ie}):ie((Y=Object.keys(y).reduce(function(e,t){var r;return Object.assign(e,((r={})[t]=function(e,r){return void 0===e&&(e={}),re(y[t],t,e,r)},r))},{render:function(e,t,r){return void 0===t&&(t={}),re(y[e],e,t,r)},renderDefault:function(){return t=(e=Y).render,r=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(o[r]=e[r]);return o}(e,["render","renderDefault"]),Object.keys(r).map(function(e){return t(e)});var e,t,r}}),a({},te,{fields:Y,isTranslatable:k})))};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},i.renderForm=function(e){/*#__PURE__*/return t.createElement(v,a({},e,{model:this}))},i.prototype.renderForm=function(e){/*#__PURE__*/return t.createElement(v,a({},e,{instance:this,model:this.constructor}))}}};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 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,h=e.model,b=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,C=e.resetAfterSubmit,F=e.delaySubmit,R=!(!P||!S);h=h||(null==b?void 0:b.constructor),m="function"==typeof m?m(h.fields):m||h.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(b||(null==(o=h)?void 0:o.hydrate(P))||null),V=n.useRef([]),q=n.useRef(),x=n.useRef({}),_=n.useRef({}),T=n.useRef((null==(s=w.current)?void 0:s._id)||(new r.ObjectID).toString()),I=n.useState(!1),L=I[0],A=I[1],D=n.useState([]),G=D[0],U=D[1],K=n.useState(P||(null==(d=w.current)?void 0:d.toJSON())||{}),M=K[0],N=K[1],$=n.useState(!0),B=$[0],J=$[1];P=R?P:M;var z=T.current,W=x.current;n.useEffect(function(){try{var e=function(){B&&J(!1)},t=function(){if(h)return Promise.resolve(h.init()).then(function(){})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(e){return Promise.reject(e)}},[]);var H,Q=function(e){var t;return null==(t=V.current)?void 0:t.includes(e)},X=function(t){try{var n=function(){var t=function(t,n){try{var r=(i=V.current.reduce(function(e,t){var n=c.default.get(P,t);return void 0===n?(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]):e[t]=n,e},{}),null!=(o=h)&&o.beforeFormSubmit&&h.beforeFormSubmit(i,Y),Promise.resolve(k(i,Y)).then(function(){var t,n;(C=null!=(t=C)?t:!!w.current)&&N(e.values||(null==(n=w.current)?void 0:n.toJSON())||{}),A(!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||[]);A(!1),U(t)});if(t&&t.then)return t.then(function(){})};t&&(t.preventDefault(),t.stopPropagation()),A(!0),U([]);var r=function(){if(F)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={id:z,values:P,instance:w.current,formRef:q,isModified:Q,isLoading:L,isInitializing:B,errors:G,handleSubmit:X,inputOptions:_.current,modified:V.current||[]},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,_.current[t],O&&O[t]);if(o.hidden)return null;var i=P[t],u=r?e.getter(i,w.current,t):i,s=G.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)});W[t]={current:void 0};var l=f({},Y,{errors:s,value:u,onChange:function(e){return ee(t,e)},options:o,id:z+":"+t,slug:t,inputRef:W[t]});return e.renderInput(l)},ee=function(e,t){try{var n=te(e,t);Q(e)&&n?V.current=V.current.filter(function(t){return t!==e}):n||Q(e)||V.current.push(e);var r=function(){var n,r,o,i;if(R)return null!=(n=h)&&n.beforeFormChange&&h.beforeFormChange(newValues,Y),Promise.resolve(S(f({},P,(r={},r[e]=t,r)))).then(function(){var e;null!=(e=h)&&e.afterFormChange&&h.afterFormChange(P,Y)});null!=(o=h)&&o.beforeFormChange&&h.beforeFormChange(newValues,Y),N(function(n){var r;return f({},n,((r={})[e]=t,r))}),null!=(i=h)&&i.afterFormChange&&h.afterFormChange(P,Y)}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},te=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)},ne=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(ne)||Array.isArray(ne)&&ne.every(function(e){/*#__PURE__*/return a.default.isValidElement(e)})?/*#__PURE__*/u.jsx("form",{ref:q,onSubmit:X,children:ne}):ne((H=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 t=(e=H).render,n=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)t.indexOf(n=i[r])>=0||(o[n]=e[n]);return o}(e,["render","renderDefault"]),Object.keys(n).map(function(e){return t(e)});var e,t,n}}),f({},Y,{fields:H,isTranslatable:j})))};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 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,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},o.renderForm=function(e){/*#__PURE__*/return a.default.createElement(m,f({},e,{model:this}))},o.prototype.renderForm=function(e){/*#__PURE__*/return a.default.createElement(m,f({},e,{instance:this,model:this.constructor}))}}};e.GraphandForm=m,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,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,j=e.translatable,P=e.values,O=e.fieldsOptions,S=e.onChange,k=e.onSubmit,E=e.processErrors,R=e.resetAfterSubmit,C=e.delaySubmit,F=!(!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(),x=n.useRef({}),_=n.useRef({}),T=n.useRef((null==(s=w.current)?void 0:s._id)||(new r.ObjectID).toString()),I=n.useState(!1),L=I[0],A=I[1],D=n.useState([]),G=D[0],U=D[1],K=n.useState(P||(null==(d=w.current)?void 0:d.toJSON())||{}),M=K[0],N=K[1],$=n.useState(!0),B=$[0],J=$[1];P=F?P:M;var z=T.current,W=x.current;n.useEffect(function(){try{var e=function(){var e;B&&J(!1),null!=(e=b)&&e.onFormChange&&b.onFormChange(P,Y)},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 H,Q=function(e){var t;return null==(t=V.current)?void 0:t.includes(e)},X=function(t){try{var n=function(){var t=function(t,n){try{var r=(i=V.current.reduce(function(e,t){var n=c.default.get(P,t);return void 0===n?(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]):e[t]=n,e},{}),null!=(o=b)&&o.beforeFormSubmit&&b.beforeFormSubmit(i,Y),Promise.resolve(k(i,Y)).then(function(){var t,n;(R=null!=(t=R)?t:!!w.current)&&N(e.values||(null==(n=w.current)?void 0:n.toJSON())||{}),A(!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||[]);A(!1),U(t)});if(t&&t.then)return t.then(function(){})};t&&(t.preventDefault(),t.stopPropagation()),A(!0),U([]);var r=function(){if(C)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={id:z,values:P,instance:w.current,formRef:q,isModified:Q,isLoading:L,isInitializing:B,errors:G,handleSubmit:X,inputOptions:_.current,modified:V.current||[]},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,_.current[t],O&&O[t]);if(o.hidden)return null;var i=P[t],u=r?e.getter(i,w.current,t):i,s=G.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)});W[t]={current:void 0};var l=f({},Y,{errors:s,value:u,onChange:function(e){return ee(t,e)},options:o,id:z+":"+t,slug:t,inputRef:W[t]});return e.renderInput(l)},ee=function(e,t){try{var n=te(e,t);Q(e)&&n?V.current=V.current.filter(function(t){return t!==e}):n||Q(e)||V.current.push(e);var r=function(){if(F){var n,r,o=f({},P,((n={})[e]=t,n));return null!=(r=b)&&r.beforeFormChange&&b.beforeFormChange(o,Y),Promise.resolve(S(o)).then(function(){})}N(function(n){var r,o,i=f({},n,((r={})[e]=t,r));return null!=(o=b)&&o.beforeFormChange&&b.beforeFormChange(i,Y),i})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},te=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)},ne=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(ne)||Array.isArray(ne)&&ne.every(function(e){/*#__PURE__*/return a.default.isValidElement(e)})?/*#__PURE__*/u.jsx("form",{ref:q,onSubmit:X,children:ne}):ne((H=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 t=(e=H).render,n=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)t.indexOf(n=i[r])>=0||(o[n]=e[n]);return o}(e,["render","renderDefault"]),Object.keys(n).map(function(e){return t(e)});var e,t,n}}),f({},Y,{fields:H,isTranslatable:j})))};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},o.renderForm=function(e){/*#__PURE__*/return a.default.createElement(m,f({},e,{model:this}))},o.prototype.renderForm=function(e){/*#__PURE__*/return a.default.createElement(m,f({},e,{instance:this,model:this.constructor}))}}};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.1.0-beta", | ||
"version": "0.1.1-beta", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "pierrecabriere", |
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
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
126962