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

graphand-react

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphand-react - npm Package Compare versions

Comparing version 0.0.2-beta to 0.0.3-beta

2

dist/index.js

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

function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("fast-deep-equal/react")),n=e(require("react")),r=e(require("lodash")),i=require("flatted");function o(){return(o=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}).apply(this,arguments)}function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var a=function(e){function n(n){var r;return(r=e.call(this,n)||this).state={res:void 0,loading:!1},r.update=function(){try{var e=function(){r.updating=!1};r.updating=!0,r.setState({loading:!0});var n=r.props.promise,i=u(function(){function e(){var e=function(){var e,t,n;if(o)return null!==(e=r.subscription)&&void 0!==e&&e.unsubscribe&&(null===(n=r.subscription)||void 0===n||n.unsubscribe()),r.props.subscribe&&null!==(t=i)&&void 0!==t&&t.subscribe&&(r.subscription=i.subscribe(function(e){return r.setState({res:e})})),Promise.resolve(new Promise(function(e){return r.setState({res:i,loading:!1},e)})).then(function(){});var s=function(){if(r.state.loading)return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})}();return s&&s.then?s.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}var i,o=!0,s=r.props.checkUpdate?Promise.resolve(Promise.all([n,r.props.promise])).then(function(e){var n=e[0];o=!t(n,e[1]),i=n}):Promise.resolve(n).then(function(e){i=e});return s&&s.then?s.then(e):e()},function(){return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})});return Promise.resolve(i&&i.then?i.then(e):e())}catch(e){return Promise.reject(e)}},n.promise&&void 0===n.promise.then&&(r.state.res=n.promise),r}s(n,e);var r=n.prototype;return r.componentDidMount=function(){try{var e=this,n=u(function(){function n(){var t;e.props.subscribe&&null!==(t=r)&&void 0!==t&&t.subscribe&&(e.subscription=r.subscribe(function(t){return e.setState({res:t})}))}var r=e.props.promise,i=function(){var n,i;if(e.props.promise&&void 0!==e.props.promise.then||!t(null===(n=e.state.res)||void 0===n?void 0:n.query,null===(i=e.props.promise)||void 0===i?void 0:i.query))return Promise.resolve(e.props.promise).then(function(t){e.setState({res:r=t})})}();return i&&i.then?i.then(n):n()},function(t){console.error(t),e.setState({res:void 0})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},r.componentDidUpdate=function(e,n){try{return(!t(this.props.updateKey,e.updateKey)||this.props.update&&!this.updating)&&this.update(),Promise.resolve()}catch(e){return Promise.reject(e)}},r.componentWillUnmount=function(){this.subscription&&this.subscription.unsubscribe()},r.renderCallback=function(){var e=this.props.callback||this.props.children;return"function"==typeof e?e(this.state.res,this.state.loading):e},r.renderFallback=function(){var e=this.props.fallback;return"function"==typeof e?e(this.state.res,this.state.loading):e},r.render=function(){var e=void 0===this.state.res?this.renderFallback():this.renderCallback();return void 0!==e?e:null},n}(n.Component);a.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!0,checkUpdate:!1};var c=function(e){function a(s){var a;return(a=e.call(this,s)||this).modified=[],a.submitted=!1,a.inputsRefs={},a.state={loading:!1,errors:[],values:{},initializing:!0},a.handleSubmit=function(e){try{e.preventDefault(),e.stopPropagation();var t=u(function(){var e=a.modified.reduce(function(e,t){return e[t]=r.get(a.values,t),void 0===r.get(e,t)&&(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]),e},a.props.values||{});return a.setState({loading:!0,errors:[]}),a.model&&a.model.beforeFormSubmit&&a.model.beforeFormSubmit.call(a.model,e,l(a)),Promise.resolve(a.props.onSubmit(e)).then(function(){var e;(null!=(e=a.props.resetAfterSubmit)?e:Boolean(a.props.instance))&&a.resetInstance().then(function(){return a.resetValues()}),a.setState({loading:!1})})},function(e){var t=Array.isArray(e)?e:[e];t=a.props.mapErrors(t),a.setState({errors:t,loading:!1});var n=t[0];if(n){var r=a.inputsRefs[n.field];r&&r.current&&r.current.focus&&r.current.focus()}});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},a.handleChange=function(e,t){void 0===t&&(t=!1);try{var n=function(){a.model&&a.model.afterFormChange&&a.model.afterFormChange.call(a.model,e,l(a))};void 0===e&&(e=a.values),a.model&&a.model.beforeFormChange&&a.model.beforeFormChange.call(a.model,e,l(a));var r=function(){if(a.props.onChange)return Promise.resolve(a.props.onChange(e,t)).then(function(){});var n=function(){if(!t)return Promise.resolve(new Promise(function(t){return a.setState({values:e},t)})).then(function(){});a.state.values=e}();return n&&n.then?n.then(function(){}):void 0}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},a.handleFieldChange=function(e,n,r){try{var s,l,u=null===(s=a.instance)||void 0===s?void 0:s.get(e,!0,r),c=i.stringify(u),d=i.stringify(n),p=t(c,d),f=r?"translations."+r+"."+e:e;a.isModified(f)&&p?a.modified=a.modified.filter(function(e){return e!==f}):p||a.isModified(f)||a.modified.push(f);var m=o({},a.values,((l={})[f]=n,l));return Promise.resolve(a.handleChange(m)).then(function(){})}catch(e){return Promise.reject(e)}},a.renderField=function(e,t,i,s){void 0===i&&(i={}),void 0===s&&(s=!0);var l=o({},i,e.inputOptions||{},a.props.fieldsOptions[t]||{});if(a.inputsRefs[t]=a.inputsRefs[t]||n.createRef(),l.hidden)return null;if(!a.props.translatable||!e.translatable){var u=a.props.getFieldOptions&&a.props.getFieldOptions(e,t)||{},c=a.values[t],d={errors:a.errors.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)}),value:s?e.getter(c,a.instance,t):c,onChange:function(e){return a.handleFieldChange(t,e)},options:o({},l,u),id:a.id+":"+t,inputRef:a.inputsRefs[t]};return e.renderInput(d)}return(a.model._client._project.locales.map(function(e){var t;return e===(null===(t=a.model._client._project)||void 0===t?void 0:t.defaultLocale)?null:e})||[null]).map(function(n){var i=t,u=r.get(a.values,n?"translations."+n+"."+i:t),c=n&&e.name?n+" - "+e.name:e.name,d=a.props.getFieldOptions&&a.props.getFieldOptions(e,i,n)||{},p={errors:a.errors.filter(function(e){return new RegExp("^"+i).test(null==e?void 0:e.field)}),value:s?e.getter(u,a.instance,i):u,onChange:function(e){return a.handleFieldChange(i,e,n)},options:o({},l,d,{label:c}),id:a.id+":"+i,inputRef:a.inputsRefs[t]};return e.renderInput(p)})},a.defaultFields=function(){return(a.props.map||Object.keys(a.fields).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)})).map(function(e){var t=a.fields[e];return t?a.renderField(t,e):null})},a.defaultTemplate=function(){return n.createElement(n.Fragment,null,a.defaultFields(),a.props.controls&&"function"==typeof a.props.controls?a.props.controls(a.props):a.props.controls||null)},a.resetInstance=function(){try{return Promise.resolve(a.props.instance).then(function(e){a.instance=e,a.instance||(a.instance=a.model&&new a.model(a.props.values))})}catch(e){return Promise.reject(e)}},a.resetValues=function(e){var t;void 0===e&&(e=!1),a.id=(null===(t=a.instance)||void 0===t?void 0:t._id)||Math.random().toString(36).substr(2,9);var n=l(a).fields,r=Object.keys(n).reduce(function(e,t){var r,i;return a.props.instance&&(i=a.instance.get(t,!0,n)),void 0===i&&(i=a.props.values&&a.props.values[t]),void 0===i&&(i=n[t].defaultValue),Object.assign(e,((r={})[t]=i,r))},{});a.handleChange(r,e)},a.isModified=function(e){return a.modified.includes(e)},a.markModified=function(e){a.modified.includes(e)||a.modified.push(e)},a.unmarkModified=function(e){a.modified.includes(e)&&(a.modified=a.modified.filter(function(t){return t!==e}))},a.formRef=n.createRef(),a}s(a,e);var c,d=a.prototype;return d.componentDidMount=function(){try{var e=this;return Promise.resolve(e.resetInstance()).then(function(){function t(){e.resetValues(),e.setState({initializing:!1})}var n=function(){if(e.model)return e.model.fieldsObserver&&e.model.fieldsObserver.list.subscribe(function(){return e.forceUpdate()}),Promise.resolve(e.model.init()).then(function(){})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},d.shouldComponentUpdate=function(e,n){return!t(this.state,n)||!t(this.props,e)},d.componentDidUpdate=function(){try{var e=this;return Promise.resolve(e.props.instance).then(function(t){var n;(null==t?void 0:t._id)===(null===(n=e.instance)||void 0===n?void 0:n._id)||!e.model||e.model.fields instanceof Promise||(e.instance=t,e.resetValues())})}catch(e){return Promise.reject(e)}},d.getDefaultFields=function(){var e=this.values;return this.instance&&((e=this.instance.clone()).model=this.instance.model,e.assign(this.values,!1)),this.model?o({},this.model.getFields(e),this.model.virtualFields,this.props.virtualFields):o({},this.props.virtualFields)},d.load=function(){this.setState({loading:!0})},d.unload=function(){this.setState({loading:!1})},d.getArgs=function(){var e=this;return{fields:Object.keys(this.fields).reduce(function(t,n){var r=e.fields[n];return r&&(t[n]=function(t,i){return void 0===t&&(t={}),e.renderField(r,n,t,i)}),t},{render:function(t,n,r){void 0===n&&(n={});var i=e.fields[t];return i?e.renderField(i,t,n,r):(console.warn("field "+t+" not found, render null"),null)},renderDefault:this.defaultFields}),isLoading:this.state.loading,isInitializing:this.state.initializing,errors:this.errors,handleSubmit:this.handleSubmit,isTranslatable:this.props.translatable,formRef:this.formRef,values:this.values}},d.render=function(){var e=this.props.template||this.props.children||this.defaultTemplate;if(n.isValidElement(e)||Array.isArray(e)&&e.every(function(e){return n.isValidElement(e)}))return n.createElement("form",{ref:this.formRef,onSubmit:this.handleSubmit},e);var t=this.getArgs();return null==e?void 0:e.call(this,t)},(c=[{key:"values",get:function(){return this.props.values||this.state.values}},{key:"model",get:function(){var e;return this.props.model||(null===(e=this.props.instance)||void 0===e?void 0:e.constructor)}},{key:"fields",get:function(){return this.props.fields&&"function"==typeof this.props.fields?this.props.fields(this.getDefaultFields()):this.props.fields||this.getDefaultFields()}},{key:"errors",get:function(){return this.state.errors.concat(this.props.errors)}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(a.prototype,c),a}(n.Component);function d(e){var t=e.constructor.lib,r=t.GraphandModel,i=t.GraphandModelListPromise,s=t.GraphandModelList,l=t.GraphandField,u=t.AggregationExecutor;t.GraphandModelPromise.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({promise:this,callback:e,fallback:t},r))},r.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({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&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({promise:this,callback:e,fallback:t},r))},s.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({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&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({promise:this,callback:e,fallback:t},r))},l.InputComponent=function(){return null},l.ViewComponent=function(){return null},l.prototype.renderInput=function(e){void 0===e&&(e={});var t=Object.getPrototypeOf(this);return n.createElement(this.InputComponent||t.constructor.InputComponent,o({},e,{field:this}))},l.prototype.renderView=function(e){void 0===e&&(e={});var t=Object.getPrototypeOf(this);return n.createElement(this.ViewComponent||t.constructor.ViewComponent,o({},e,{field:this}))},r.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 i=r.fields[e];return(null==i?void 0:i.renderView({value:this.get(e,t),item:this,slug:e,options:n}))||null},r.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 i=r.fields[e];return(null==i?void 0:i.renderInput({value:this.get(e,t),item:this,slug:e,options:n}))||null}}c.defaultProps={model:null,virtualFields:{},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,mapErrors:function(e){return e},controls:function(e){return[n.createElement("button",{className:"btn btn-primary",type:"submit"},e.submitLabel)]}},exports.GraphandForm=c,exports.GraphandPluginReact=d,exports.PromiseSuspense=a,exports.default=d;
function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("fast-deep-equal/react")),n=e(require("react")),r=e(require("lodash")),i=require("flatted");function o(){return(o=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}).apply(this,arguments)}function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var a=function(e){function n(n){var r;return(r=e.call(this,n)||this).state={res:void 0,loading:!1},r.update=function(){try{var e=function(){r.updating=!1};r.updating=!0,r.setState({loading:!0});var n=r.props.promise,i=u(function(){function e(){var e=function(){var e,t,n;if(o)return null!==(e=r.subscription)&&void 0!==e&&e.unsubscribe&&(null===(n=r.subscription)||void 0===n||n.unsubscribe()),r.props.subscribe&&null!==(t=i)&&void 0!==t&&t.subscribe&&(r.subscription=i.subscribe(function(e){return r.setState({res:e})})),Promise.resolve(new Promise(function(e){return r.setState({res:i,loading:!1},e)})).then(function(){});var s=function(){if(r.state.loading)return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})}();return s&&s.then?s.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}var i,o=!0,s=r.props.checkUpdate?Promise.resolve(Promise.all([n,r.props.promise])).then(function(e){var n=e[0];o=!t(n,e[1]),i=n}):Promise.resolve(n).then(function(e){i=e});return s&&s.then?s.then(e):e()},function(){return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})});return Promise.resolve(i&&i.then?i.then(e):e())}catch(e){return Promise.reject(e)}},n.promise&&void 0===n.promise.then&&(r.state.res=n.promise),r}s(n,e);var r=n.prototype;return r.componentDidMount=function(){try{var e=this,n=u(function(){function n(){var t;e.props.subscribe&&null!==(t=r)&&void 0!==t&&t.subscribe&&(e.subscription=r.subscribe(function(t){return e.setState({res:t})}))}var r=e.props.promise,i=function(){var n,i;if(e.props.promise&&void 0!==e.props.promise.then||!t(null===(n=e.state.res)||void 0===n?void 0:n.query,null===(i=e.props.promise)||void 0===i?void 0:i.query))return Promise.resolve(e.props.promise).then(function(t){e.setState({res:r=t})})}();return i&&i.then?i.then(n):n()},function(t){console.error(t),e.setState({res:void 0})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},r.componentDidUpdate=function(e,n){try{return(!t(this.props.updateKey,e.updateKey)||this.props.update&&!this.updating)&&this.update(),Promise.resolve()}catch(e){return Promise.reject(e)}},r.componentWillUnmount=function(){this.subscription&&this.subscription.unsubscribe()},r.renderCallback=function(){var e=this.props.callback||this.props.children;return"function"==typeof e?e(this.state.res,this.state.loading):e},r.renderFallback=function(){var e=this.props.fallback;return"function"==typeof e?e(this.state.res,this.state.loading):e},r.render=function(){var e=void 0===this.state.res?this.renderFallback():this.renderCallback();return void 0!==e?e:null},n}(n.Component);a.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!0,checkUpdate:!1};var c=function(e){function a(s){var a;return(a=e.call(this,s)||this).modified=[],a.submitted=!1,a.inputsRefs={},a.state={loading:!1,errors:[],values:{},initializing:!0},a.handleSubmit=function(e){try{e.preventDefault(),e.stopPropagation();var t=u(function(){var e=a.modified.reduce(function(e,t){return e[t]=r.get(a.values,t),void 0===r.get(e,t)&&(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]),e},a.props.values||{});return a.setState({loading:!0,errors:[]}),a.model&&a.model.beforeFormSubmit&&a.model.beforeFormSubmit.call(a.model,e,l(a)),Promise.resolve(a.props.onSubmit(e)).then(function(){var e;(null!=(e=a.props.resetAfterSubmit)?e:Boolean(a.props.instance))&&a.resetInstance().then(function(){return a.resetValues()}),a.setState({loading:!1})})},function(e){var t=Array.isArray(e)?e:[e];t=a.props.mapErrors(t),a.setState({errors:t,loading:!1});var n=t[0];if(n){var r=a.inputsRefs[n.field];r&&r.current&&r.current.focus&&r.current.focus()}});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},a.handleChange=function(e,t){void 0===t&&(t=!1);try{var n=function(){a.model&&a.model.afterFormChange&&a.model.afterFormChange.call(a.model,e,l(a))};void 0===e&&(e=a.values),a.model&&a.model.beforeFormChange&&a.model.beforeFormChange.call(a.model,e,l(a));var r=function(){if(a.props.onChange)return Promise.resolve(a.props.onChange(e,t)).then(function(){});var n=function(){if(!t)return Promise.resolve(new Promise(function(t){return a.setState({values:e},t)})).then(function(){});a.state.values=e}();return n&&n.then?n.then(function(){}):void 0}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},a.handleFieldChange=function(e,n,r){try{var s,l,u=null===(s=a.instance)||void 0===s?void 0:s.get(e,!0,r),c=i.stringify(u),d=i.stringify(n),p=t(c,d),f=r?"translations."+r+"."+e:e;a.isModified(f)&&p?a.modified=a.modified.filter(function(e){return e!==f}):p||a.isModified(f)||a.modified.push(f);var m=o({},a.values,((l={})[f]=n,l));return Promise.resolve(a.handleChange(m)).then(function(){})}catch(e){return Promise.reject(e)}},a.renderField=function(e,t,i,s){void 0===i&&(i={}),void 0===s&&(s=!0);var l=o({},i,e.inputOptions||{},a.props.fieldsOptions[t]||{});if(a.inputsRefs[t]=a.inputsRefs[t]||n.createRef(),l.hidden)return null;if(!a.props.translatable||!e.translatable){var u=a.props.getFieldOptions&&a.props.getFieldOptions(e,t)||{},c=a.values[t],d={errors:a.errors.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)}),value:s?e.getter(c,a.instance,t):c,onChange:function(e){return a.handleFieldChange(t,e)},options:o({},l,u),id:a.id+":"+t,inputRef:a.inputsRefs[t]};return e.renderInput(d)}return(a.model._client._project.locales.map(function(e){var t;return e===(null===(t=a.model._client._project)||void 0===t?void 0:t.defaultLocale)?null:e})||[null]).map(function(n){var i=t,u=r.get(a.values,n?"translations."+n+"."+i:t),c=n&&e.name?n+" - "+e.name:e.name,d=a.props.getFieldOptions&&a.props.getFieldOptions(e,i,n)||{},p={errors:a.errors.filter(function(e){return new RegExp("^"+i).test(null==e?void 0:e.field)}),value:s?e.getter(u,a.instance,i):u,onChange:function(e){return a.handleFieldChange(i,e,n)},options:o({},l,d,{label:c}),id:a.id+":"+i,inputRef:a.inputsRefs[t]};return e.renderInput(p)})},a.defaultFields=function(){return(a.props.map||Object.keys(a.fields).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)})).map(function(e){var t=a.fields[e];return t?a.renderField(t,e):null})},a.defaultTemplate=function(){return n.createElement(n.Fragment,null,a.defaultFields(),a.props.controls&&"function"==typeof a.props.controls?a.props.controls(a.props):a.props.controls||null)},a.resetInstance=function(){try{return Promise.resolve(a.props.instance).then(function(e){a.instance=e,a.instance||(a.instance=a.model&&new a.model(a.props.values))})}catch(e){return Promise.reject(e)}},a.resetValues=function(e){var t;void 0===e&&(e=!1),a.id=(null===(t=a.instance)||void 0===t?void 0:t._id)||Math.random().toString(36).substr(2,9);var n=l(a).fields,r=Object.keys(n).reduce(function(e,t){var r,i;return a.props.instance&&(i=a.instance.get(t,!0,n)),void 0===i&&(i=a.props.values&&a.props.values[t]),void 0===i&&(i=n[t].defaultValue),Object.assign(e,((r={})[t]=i,r))},{});a.handleChange(r,e)},a.isModified=function(e){return a.modified.includes(e)},a.markModified=function(e){a.modified.includes(e)||a.modified.push(e)},a.unmarkModified=function(e){a.modified.includes(e)&&(a.modified=a.modified.filter(function(t){return t!==e}))},a.formRef=n.createRef(),a}s(a,e);var c,d=a.prototype;return d.componentDidMount=function(){try{var e=this;return Promise.resolve(e.resetInstance()).then(function(){function t(){e.resetValues(),e.setState({initializing:!1})}var n=function(){if(e.model)return e.model.fieldsObserver&&e.model.fieldsObserver.list.subscribe(function(){return e.forceUpdate()}),Promise.resolve(e.model.init()).then(function(){})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},d.shouldComponentUpdate=function(e,n){return!t(this.state,n)||!t(this.props,e)},d.componentDidUpdate=function(){try{var e=this;return Promise.resolve(e.props.instance).then(function(t){var n;(null==t?void 0:t._id)===(null===(n=e.instance)||void 0===n?void 0:n._id)||!e.model||e.model.fields instanceof Promise||(e.instance=t,e.resetValues())})}catch(e){return Promise.reject(e)}},d.getDefaultFields=function(){var e=this.values;return this.instance&&((e=this.instance.clone()).model=this.instance.model,e.assign(this.values,!1)),this.model?o({},this.model.getFields(e),this.model.virtualFields,this.props.virtualFields):o({},this.props.virtualFields)},d.load=function(){this.setState({loading:!0})},d.unload=function(){this.setState({loading:!1})},d.getArgs=function(){var e=this;return{fields:Object.keys(this.fields).reduce(function(t,n){var r=e.fields[n];return r&&(t[n]=function(t,i){return void 0===t&&(t={}),e.renderField(r,n,t,i)}),t},{render:function(t,n,r){void 0===n&&(n={});var i=e.fields[t];return i?e.renderField(i,t,n,r):(console.warn("field "+t+" not found, render null"),null)},renderDefault:this.defaultFields}),isLoading:this.state.loading,isInitializing:this.state.initializing,errors:this.errors,handleSubmit:this.handleSubmit,isTranslatable:this.props.translatable,formRef:this.formRef,values:this.values}},d.render=function(){var e=this.props.template||this.props.children||n.createElement(this.defaultTemplate);if(n.isValidElement(e)||Array.isArray(e)&&e.every(function(e){return n.isValidElement(e)}))return n.createElement("form",{ref:this.formRef,onSubmit:this.handleSubmit},e);var t=this.getArgs();return null==e?void 0:e.call(this,t)},(c=[{key:"values",get:function(){return this.props.values||this.state.values}},{key:"model",get:function(){var e;return this.props.model||(null===(e=this.props.instance)||void 0===e?void 0:e.constructor)}},{key:"fields",get:function(){return this.props.fields&&"function"==typeof this.props.fields?this.props.fields(this.getDefaultFields()):this.props.fields||this.getDefaultFields()}},{key:"errors",get:function(){return this.state.errors.concat(this.props.errors)}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(a.prototype,c),a}(n.Component);function d(e){var t=e.constructor.lib,r=t.GraphandModel,i=t.GraphandModelListPromise,s=t.GraphandModelList,l=t.GraphandField,u=t.AggregationExecutor;t.GraphandModelPromise.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({promise:this,callback:e,fallback:t},r))},r.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({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&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({promise:this,callback:e,fallback:t},r))},s.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({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&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({promise:this,callback:e,fallback:t},r))},l.InputComponent=function(){return null},l.ViewComponent=function(){return null},l.prototype.renderInput=function(e){void 0===e&&(e={});var t=Object.getPrototypeOf(this);return n.createElement(this.InputComponent||t.constructor.InputComponent,o({},e,{field:this}))},l.prototype.renderView=function(e){void 0===e&&(e={});var t=Object.getPrototypeOf(this);return n.createElement(this.ViewComponent||t.constructor.ViewComponent,o({},e,{field:this}))},r.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 i=r.fields[e];return(null==i?void 0:i.renderView({value:this.get(e,t),item:this,slug:e,options:n}))||null},r.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 i=r.fields[e];return(null==i?void 0:i.renderInput({value:this.get(e,t),item:this,slug:e,options:n}))||null}}c.defaultProps={model:null,virtualFields:{},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,mapErrors:function(e){return e},controls:function(e){return[n.createElement("button",{className:"btn btn-primary",type:"submit"},e.submitLabel)]}},exports.GraphandForm=c,exports.GraphandPluginReact=d,exports.PromiseSuspense=a,exports.default=d;
//# sourceMappingURL=index.js.map

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

import e from"fast-deep-equal/react";import t from"react";import n from"lodash";import{stringify as r}from"flatted";function i(){return(i=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}).apply(this,arguments)}function o(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var u=function(t){function n(n){var r;return(r=t.call(this,n)||this).state={res:void 0,loading:!1},r.update=function(){try{var t=function(){r.updating=!1};r.updating=!0,r.setState({loading:!0});var n=r.props.promise,i=l(function(){function t(){var e=function(){var e,t,n;if(o)return null!==(e=r.subscription)&&void 0!==e&&e.unsubscribe&&(null===(n=r.subscription)||void 0===n||n.unsubscribe()),r.props.subscribe&&null!==(t=i)&&void 0!==t&&t.subscribe&&(r.subscription=i.subscribe(function(e){return r.setState({res:e})})),Promise.resolve(new Promise(function(e){return r.setState({res:i,loading:!1},e)})).then(function(){});var s=function(){if(r.state.loading)return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})}();return s&&s.then?s.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}var i,o=!0,s=r.props.checkUpdate?Promise.resolve(Promise.all([n,r.props.promise])).then(function(t){var n=t[0];o=!e(n,t[1]),i=n}):Promise.resolve(n).then(function(e){i=e});return s&&s.then?s.then(t):t()},function(){return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})});return Promise.resolve(i&&i.then?i.then(t):t())}catch(e){return Promise.reject(e)}},n.promise&&void 0===n.promise.then&&(r.state.res=n.promise),r}o(n,t);var r=n.prototype;return r.componentDidMount=function(){try{var t=this,n=l(function(){function n(){var e;t.props.subscribe&&null!==(e=r)&&void 0!==e&&e.subscribe&&(t.subscription=r.subscribe(function(e){return t.setState({res:e})}))}var r=t.props.promise,i=function(){var n,i;if(t.props.promise&&void 0!==t.props.promise.then||!e(null===(n=t.state.res)||void 0===n?void 0:n.query,null===(i=t.props.promise)||void 0===i?void 0:i.query))return Promise.resolve(t.props.promise).then(function(e){t.setState({res:r=e})})}();return i&&i.then?i.then(n):n()},function(e){console.error(e),t.setState({res:void 0})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},r.componentDidUpdate=function(t,n){try{return(!e(this.props.updateKey,t.updateKey)||this.props.update&&!this.updating)&&this.update(),Promise.resolve()}catch(e){return Promise.reject(e)}},r.componentWillUnmount=function(){this.subscription&&this.subscription.unsubscribe()},r.renderCallback=function(){var e=this.props.callback||this.props.children;return"function"==typeof e?e(this.state.res,this.state.loading):e},r.renderFallback=function(){var e=this.props.fallback;return"function"==typeof e?e(this.state.res,this.state.loading):e},r.render=function(){var e=void 0===this.state.res?this.renderFallback():this.renderCallback();return void 0!==e?e:null},n}(t.Component);u.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!0,checkUpdate:!1};var a=function(u){function a(o){var a;return(a=u.call(this,o)||this).modified=[],a.submitted=!1,a.inputsRefs={},a.state={loading:!1,errors:[],values:{},initializing:!0},a.handleSubmit=function(e){try{e.preventDefault(),e.stopPropagation();var t=l(function(){var e=a.modified.reduce(function(e,t){return e[t]=n.get(a.values,t),void 0===n.get(e,t)&&(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]),e},a.props.values||{});return a.setState({loading:!0,errors:[]}),a.model&&a.model.beforeFormSubmit&&a.model.beforeFormSubmit.call(a.model,e,s(a)),Promise.resolve(a.props.onSubmit(e)).then(function(){var e;(null!=(e=a.props.resetAfterSubmit)?e:Boolean(a.props.instance))&&a.resetInstance().then(function(){return a.resetValues()}),a.setState({loading:!1})})},function(e){var t=Array.isArray(e)?e:[e];t=a.props.mapErrors(t),a.setState({errors:t,loading:!1});var n=t[0];if(n){var r=a.inputsRefs[n.field];r&&r.current&&r.current.focus&&r.current.focus()}});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},a.handleChange=function(e,t){void 0===t&&(t=!1);try{var n=function(){a.model&&a.model.afterFormChange&&a.model.afterFormChange.call(a.model,e,s(a))};void 0===e&&(e=a.values),a.model&&a.model.beforeFormChange&&a.model.beforeFormChange.call(a.model,e,s(a));var r=function(){if(a.props.onChange)return Promise.resolve(a.props.onChange(e,t)).then(function(){});var n=function(){if(!t)return Promise.resolve(new Promise(function(t){return a.setState({values:e},t)})).then(function(){});a.state.values=e}();return n&&n.then?n.then(function(){}):void 0}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},a.handleFieldChange=function(t,n,o){try{var s,l,u=null===(s=a.instance)||void 0===s?void 0:s.get(t,!0,o),c=r(u),d=r(n),p=e(c,d),f=o?"translations."+o+"."+t:t;a.isModified(f)&&p?a.modified=a.modified.filter(function(e){return e!==f}):p||a.isModified(f)||a.modified.push(f);var m=i({},a.values,((l={})[f]=n,l));return Promise.resolve(a.handleChange(m)).then(function(){})}catch(e){return Promise.reject(e)}},a.renderField=function(e,r,o,s){void 0===o&&(o={}),void 0===s&&(s=!0);var l=i({},o,e.inputOptions||{},a.props.fieldsOptions[r]||{});if(a.inputsRefs[r]=a.inputsRefs[r]||t.createRef(),l.hidden)return null;if(!a.props.translatable||!e.translatable){var u=a.props.getFieldOptions&&a.props.getFieldOptions(e,r)||{},c=a.values[r],d={errors:a.errors.filter(function(e){return new RegExp("^"+r).test(null==e?void 0:e.field)}),value:s?e.getter(c,a.instance,r):c,onChange:function(e){return a.handleFieldChange(r,e)},options:i({},l,u),id:a.id+":"+r,inputRef:a.inputsRefs[r]};return e.renderInput(d)}return(a.model._client._project.locales.map(function(e){var t;return e===(null===(t=a.model._client._project)||void 0===t?void 0:t.defaultLocale)?null:e})||[null]).map(function(t){var o=r,u=n.get(a.values,t?"translations."+t+"."+o:r),c=t&&e.name?t+" - "+e.name:e.name,d=a.props.getFieldOptions&&a.props.getFieldOptions(e,o,t)||{},p={errors:a.errors.filter(function(e){return new RegExp("^"+o).test(null==e?void 0:e.field)}),value:s?e.getter(u,a.instance,o):u,onChange:function(e){return a.handleFieldChange(o,e,t)},options:i({},l,d,{label:c}),id:a.id+":"+o,inputRef:a.inputsRefs[r]};return e.renderInput(p)})},a.defaultFields=function(){return(a.props.map||Object.keys(a.fields).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)})).map(function(e){var t=a.fields[e];return t?a.renderField(t,e):null})},a.defaultTemplate=function(){return t.createElement(t.Fragment,null,a.defaultFields(),a.props.controls&&"function"==typeof a.props.controls?a.props.controls(a.props):a.props.controls||null)},a.resetInstance=function(){try{return Promise.resolve(a.props.instance).then(function(e){a.instance=e,a.instance||(a.instance=a.model&&new a.model(a.props.values))})}catch(e){return Promise.reject(e)}},a.resetValues=function(e){var t;void 0===e&&(e=!1),a.id=(null===(t=a.instance)||void 0===t?void 0:t._id)||Math.random().toString(36).substr(2,9);var n=s(a).fields,r=Object.keys(n).reduce(function(e,t){var r,i;return a.props.instance&&(i=a.instance.get(t,!0,n)),void 0===i&&(i=a.props.values&&a.props.values[t]),void 0===i&&(i=n[t].defaultValue),Object.assign(e,((r={})[t]=i,r))},{});a.handleChange(r,e)},a.isModified=function(e){return a.modified.includes(e)},a.markModified=function(e){a.modified.includes(e)||a.modified.push(e)},a.unmarkModified=function(e){a.modified.includes(e)&&(a.modified=a.modified.filter(function(t){return t!==e}))},a.formRef=t.createRef(),a}o(a,u);var c,d=a.prototype;return d.componentDidMount=function(){try{var e=this;return Promise.resolve(e.resetInstance()).then(function(){function t(){e.resetValues(),e.setState({initializing:!1})}var n=function(){if(e.model)return e.model.fieldsObserver&&e.model.fieldsObserver.list.subscribe(function(){return e.forceUpdate()}),Promise.resolve(e.model.init()).then(function(){})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},d.shouldComponentUpdate=function(t,n){return!e(this.state,n)||!e(this.props,t)},d.componentDidUpdate=function(){try{var e=this;return Promise.resolve(e.props.instance).then(function(t){var n;(null==t?void 0:t._id)===(null===(n=e.instance)||void 0===n?void 0:n._id)||!e.model||e.model.fields instanceof Promise||(e.instance=t,e.resetValues())})}catch(e){return Promise.reject(e)}},d.getDefaultFields=function(){var e=this.values;return this.instance&&((e=this.instance.clone()).model=this.instance.model,e.assign(this.values,!1)),this.model?i({},this.model.getFields(e),this.model.virtualFields,this.props.virtualFields):i({},this.props.virtualFields)},d.load=function(){this.setState({loading:!0})},d.unload=function(){this.setState({loading:!1})},d.getArgs=function(){var e=this;return{fields:Object.keys(this.fields).reduce(function(t,n){var r=e.fields[n];return r&&(t[n]=function(t,i){return void 0===t&&(t={}),e.renderField(r,n,t,i)}),t},{render:function(t,n,r){void 0===n&&(n={});var i=e.fields[t];return i?e.renderField(i,t,n,r):(console.warn("field "+t+" not found, render null"),null)},renderDefault:this.defaultFields}),isLoading:this.state.loading,isInitializing:this.state.initializing,errors:this.errors,handleSubmit:this.handleSubmit,isTranslatable:this.props.translatable,formRef:this.formRef,values:this.values}},d.render=function(){var e=this.props.template||this.props.children||this.defaultTemplate;if(t.isValidElement(e)||Array.isArray(e)&&e.every(function(e){return t.isValidElement(e)}))return t.createElement("form",{ref:this.formRef,onSubmit:this.handleSubmit},e);var n=this.getArgs();return null==e?void 0:e.call(this,n)},(c=[{key:"values",get:function(){return this.props.values||this.state.values}},{key:"model",get:function(){var e;return this.props.model||(null===(e=this.props.instance)||void 0===e?void 0:e.constructor)}},{key:"fields",get:function(){return this.props.fields&&"function"==typeof this.props.fields?this.props.fields(this.getDefaultFields()):this.props.fields||this.getDefaultFields()}},{key:"errors",get:function(){return this.state.errors.concat(this.props.errors)}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(a.prototype,c),a}(t.Component);function c(e){var n=e.constructor.lib,r=n.GraphandModel,o=n.GraphandModelListPromise,s=n.GraphandModelList,l=n.GraphandField,a=n.AggregationExecutor;n.GraphandModelPromise.prototype.suspense=function(e,n,r){return void 0===n&&(n=null),void 0===r&&(r={}),n&&!t.isValidElement(n)&&"object"==typeof n&&(Object.assign(r,n),n=null),t.createElement(u,i({promise:this,callback:e,fallback:n},r))},r.prototype.suspense=function(e,n,r){return void 0===n&&(n=null),void 0===r&&(r={}),n&&!t.isValidElement(n)&&"object"==typeof n&&(Object.assign(r,n),n=null),t.createElement(u,i({promise:this,callback:e,fallback:n},r))},o.prototype.suspense=function(e,n,r){return void 0===n&&(n=null),void 0===r&&(r={}),n&&!t.isValidElement(n)&&"object"==typeof n&&(Object.assign(r,n),n=null),t.createElement(u,i({promise:this,callback:e,fallback:n},r))},s.prototype.suspense=function(e,n,r){return void 0===n&&(n=null),void 0===r&&(r={}),n&&!t.isValidElement(n)&&"object"==typeof n&&(Object.assign(r,n),n=null),t.createElement(u,i({promise:this,callback:e,fallback:n},r))},a.prototype.suspense=function(e,n,r){return void 0===n&&(n=null),void 0===r&&(r={}),n&&!t.isValidElement(n)&&"object"==typeof n&&(Object.assign(r,n),n=null),t.createElement(u,i({promise:this,callback:e,fallback:n},r))},l.InputComponent=function(){return null},l.ViewComponent=function(){return null},l.prototype.renderInput=function(e){void 0===e&&(e={});var n=Object.getPrototypeOf(this);return t.createElement(this.InputComponent||n.constructor.InputComponent,i({},e,{field:this}))},l.prototype.renderView=function(e){void 0===e&&(e={});var n=Object.getPrototypeOf(this);return t.createElement(this.ViewComponent||n.constructor.ViewComponent,i({},e,{field:this}))},r.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 i=r.fields[e];return(null==i?void 0:i.renderView({value:this.get(e,t),item:this,slug:e,options:n}))||null},r.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 i=r.fields[e];return(null==i?void 0:i.renderInput({value:this.get(e,t),item:this,slug:e,options:n}))||null}}a.defaultProps={model:null,virtualFields:{},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,mapErrors:function(e){return e},controls:function(e){return[t.createElement("button",{className:"btn btn-primary",type:"submit"},e.submitLabel)]}};export default c;export{a as GraphandForm,c as GraphandPluginReact,u as PromiseSuspense};
import e from"fast-deep-equal/react";import t from"react";import n from"lodash";import{stringify as r}from"flatted";function i(){return(i=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}).apply(this,arguments)}function o(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var u=function(t){function n(n){var r;return(r=t.call(this,n)||this).state={res:void 0,loading:!1},r.update=function(){try{var t=function(){r.updating=!1};r.updating=!0,r.setState({loading:!0});var n=r.props.promise,i=l(function(){function t(){var e=function(){var e,t,n;if(o)return null!==(e=r.subscription)&&void 0!==e&&e.unsubscribe&&(null===(n=r.subscription)||void 0===n||n.unsubscribe()),r.props.subscribe&&null!==(t=i)&&void 0!==t&&t.subscribe&&(r.subscription=i.subscribe(function(e){return r.setState({res:e})})),Promise.resolve(new Promise(function(e){return r.setState({res:i,loading:!1},e)})).then(function(){});var s=function(){if(r.state.loading)return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})}();return s&&s.then?s.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}var i,o=!0,s=r.props.checkUpdate?Promise.resolve(Promise.all([n,r.props.promise])).then(function(t){var n=t[0];o=!e(n,t[1]),i=n}):Promise.resolve(n).then(function(e){i=e});return s&&s.then?s.then(t):t()},function(){return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})});return Promise.resolve(i&&i.then?i.then(t):t())}catch(e){return Promise.reject(e)}},n.promise&&void 0===n.promise.then&&(r.state.res=n.promise),r}o(n,t);var r=n.prototype;return r.componentDidMount=function(){try{var t=this,n=l(function(){function n(){var e;t.props.subscribe&&null!==(e=r)&&void 0!==e&&e.subscribe&&(t.subscription=r.subscribe(function(e){return t.setState({res:e})}))}var r=t.props.promise,i=function(){var n,i;if(t.props.promise&&void 0!==t.props.promise.then||!e(null===(n=t.state.res)||void 0===n?void 0:n.query,null===(i=t.props.promise)||void 0===i?void 0:i.query))return Promise.resolve(t.props.promise).then(function(e){t.setState({res:r=e})})}();return i&&i.then?i.then(n):n()},function(e){console.error(e),t.setState({res:void 0})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},r.componentDidUpdate=function(t,n){try{return(!e(this.props.updateKey,t.updateKey)||this.props.update&&!this.updating)&&this.update(),Promise.resolve()}catch(e){return Promise.reject(e)}},r.componentWillUnmount=function(){this.subscription&&this.subscription.unsubscribe()},r.renderCallback=function(){var e=this.props.callback||this.props.children;return"function"==typeof e?e(this.state.res,this.state.loading):e},r.renderFallback=function(){var e=this.props.fallback;return"function"==typeof e?e(this.state.res,this.state.loading):e},r.render=function(){var e=void 0===this.state.res?this.renderFallback():this.renderCallback();return void 0!==e?e:null},n}(t.Component);u.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!0,checkUpdate:!1};var a=function(u){function a(o){var a;return(a=u.call(this,o)||this).modified=[],a.submitted=!1,a.inputsRefs={},a.state={loading:!1,errors:[],values:{},initializing:!0},a.handleSubmit=function(e){try{e.preventDefault(),e.stopPropagation();var t=l(function(){var e=a.modified.reduce(function(e,t){return e[t]=n.get(a.values,t),void 0===n.get(e,t)&&(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]),e},a.props.values||{});return a.setState({loading:!0,errors:[]}),a.model&&a.model.beforeFormSubmit&&a.model.beforeFormSubmit.call(a.model,e,s(a)),Promise.resolve(a.props.onSubmit(e)).then(function(){var e;(null!=(e=a.props.resetAfterSubmit)?e:Boolean(a.props.instance))&&a.resetInstance().then(function(){return a.resetValues()}),a.setState({loading:!1})})},function(e){var t=Array.isArray(e)?e:[e];t=a.props.mapErrors(t),a.setState({errors:t,loading:!1});var n=t[0];if(n){var r=a.inputsRefs[n.field];r&&r.current&&r.current.focus&&r.current.focus()}});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},a.handleChange=function(e,t){void 0===t&&(t=!1);try{var n=function(){a.model&&a.model.afterFormChange&&a.model.afterFormChange.call(a.model,e,s(a))};void 0===e&&(e=a.values),a.model&&a.model.beforeFormChange&&a.model.beforeFormChange.call(a.model,e,s(a));var r=function(){if(a.props.onChange)return Promise.resolve(a.props.onChange(e,t)).then(function(){});var n=function(){if(!t)return Promise.resolve(new Promise(function(t){return a.setState({values:e},t)})).then(function(){});a.state.values=e}();return n&&n.then?n.then(function(){}):void 0}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},a.handleFieldChange=function(t,n,o){try{var s,l,u=null===(s=a.instance)||void 0===s?void 0:s.get(t,!0,o),c=r(u),d=r(n),p=e(c,d),f=o?"translations."+o+"."+t:t;a.isModified(f)&&p?a.modified=a.modified.filter(function(e){return e!==f}):p||a.isModified(f)||a.modified.push(f);var m=i({},a.values,((l={})[f]=n,l));return Promise.resolve(a.handleChange(m)).then(function(){})}catch(e){return Promise.reject(e)}},a.renderField=function(e,r,o,s){void 0===o&&(o={}),void 0===s&&(s=!0);var l=i({},o,e.inputOptions||{},a.props.fieldsOptions[r]||{});if(a.inputsRefs[r]=a.inputsRefs[r]||t.createRef(),l.hidden)return null;if(!a.props.translatable||!e.translatable){var u=a.props.getFieldOptions&&a.props.getFieldOptions(e,r)||{},c=a.values[r],d={errors:a.errors.filter(function(e){return new RegExp("^"+r).test(null==e?void 0:e.field)}),value:s?e.getter(c,a.instance,r):c,onChange:function(e){return a.handleFieldChange(r,e)},options:i({},l,u),id:a.id+":"+r,inputRef:a.inputsRefs[r]};return e.renderInput(d)}return(a.model._client._project.locales.map(function(e){var t;return e===(null===(t=a.model._client._project)||void 0===t?void 0:t.defaultLocale)?null:e})||[null]).map(function(t){var o=r,u=n.get(a.values,t?"translations."+t+"."+o:r),c=t&&e.name?t+" - "+e.name:e.name,d=a.props.getFieldOptions&&a.props.getFieldOptions(e,o,t)||{},p={errors:a.errors.filter(function(e){return new RegExp("^"+o).test(null==e?void 0:e.field)}),value:s?e.getter(u,a.instance,o):u,onChange:function(e){return a.handleFieldChange(o,e,t)},options:i({},l,d,{label:c}),id:a.id+":"+o,inputRef:a.inputsRefs[r]};return e.renderInput(p)})},a.defaultFields=function(){return(a.props.map||Object.keys(a.fields).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)})).map(function(e){var t=a.fields[e];return t?a.renderField(t,e):null})},a.defaultTemplate=function(){return t.createElement(t.Fragment,null,a.defaultFields(),a.props.controls&&"function"==typeof a.props.controls?a.props.controls(a.props):a.props.controls||null)},a.resetInstance=function(){try{return Promise.resolve(a.props.instance).then(function(e){a.instance=e,a.instance||(a.instance=a.model&&new a.model(a.props.values))})}catch(e){return Promise.reject(e)}},a.resetValues=function(e){var t;void 0===e&&(e=!1),a.id=(null===(t=a.instance)||void 0===t?void 0:t._id)||Math.random().toString(36).substr(2,9);var n=s(a).fields,r=Object.keys(n).reduce(function(e,t){var r,i;return a.props.instance&&(i=a.instance.get(t,!0,n)),void 0===i&&(i=a.props.values&&a.props.values[t]),void 0===i&&(i=n[t].defaultValue),Object.assign(e,((r={})[t]=i,r))},{});a.handleChange(r,e)},a.isModified=function(e){return a.modified.includes(e)},a.markModified=function(e){a.modified.includes(e)||a.modified.push(e)},a.unmarkModified=function(e){a.modified.includes(e)&&(a.modified=a.modified.filter(function(t){return t!==e}))},a.formRef=t.createRef(),a}o(a,u);var c,d=a.prototype;return d.componentDidMount=function(){try{var e=this;return Promise.resolve(e.resetInstance()).then(function(){function t(){e.resetValues(),e.setState({initializing:!1})}var n=function(){if(e.model)return e.model.fieldsObserver&&e.model.fieldsObserver.list.subscribe(function(){return e.forceUpdate()}),Promise.resolve(e.model.init()).then(function(){})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},d.shouldComponentUpdate=function(t,n){return!e(this.state,n)||!e(this.props,t)},d.componentDidUpdate=function(){try{var e=this;return Promise.resolve(e.props.instance).then(function(t){var n;(null==t?void 0:t._id)===(null===(n=e.instance)||void 0===n?void 0:n._id)||!e.model||e.model.fields instanceof Promise||(e.instance=t,e.resetValues())})}catch(e){return Promise.reject(e)}},d.getDefaultFields=function(){var e=this.values;return this.instance&&((e=this.instance.clone()).model=this.instance.model,e.assign(this.values,!1)),this.model?i({},this.model.getFields(e),this.model.virtualFields,this.props.virtualFields):i({},this.props.virtualFields)},d.load=function(){this.setState({loading:!0})},d.unload=function(){this.setState({loading:!1})},d.getArgs=function(){var e=this;return{fields:Object.keys(this.fields).reduce(function(t,n){var r=e.fields[n];return r&&(t[n]=function(t,i){return void 0===t&&(t={}),e.renderField(r,n,t,i)}),t},{render:function(t,n,r){void 0===n&&(n={});var i=e.fields[t];return i?e.renderField(i,t,n,r):(console.warn("field "+t+" not found, render null"),null)},renderDefault:this.defaultFields}),isLoading:this.state.loading,isInitializing:this.state.initializing,errors:this.errors,handleSubmit:this.handleSubmit,isTranslatable:this.props.translatable,formRef:this.formRef,values:this.values}},d.render=function(){var e=this.props.template||this.props.children||t.createElement(this.defaultTemplate);if(t.isValidElement(e)||Array.isArray(e)&&e.every(function(e){return t.isValidElement(e)}))return t.createElement("form",{ref:this.formRef,onSubmit:this.handleSubmit},e);var n=this.getArgs();return null==e?void 0:e.call(this,n)},(c=[{key:"values",get:function(){return this.props.values||this.state.values}},{key:"model",get:function(){var e;return this.props.model||(null===(e=this.props.instance)||void 0===e?void 0:e.constructor)}},{key:"fields",get:function(){return this.props.fields&&"function"==typeof this.props.fields?this.props.fields(this.getDefaultFields()):this.props.fields||this.getDefaultFields()}},{key:"errors",get:function(){return this.state.errors.concat(this.props.errors)}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(a.prototype,c),a}(t.Component);function c(e){var n=e.constructor.lib,r=n.GraphandModel,o=n.GraphandModelListPromise,s=n.GraphandModelList,l=n.GraphandField,a=n.AggregationExecutor;n.GraphandModelPromise.prototype.suspense=function(e,n,r){return void 0===n&&(n=null),void 0===r&&(r={}),n&&!t.isValidElement(n)&&"object"==typeof n&&(Object.assign(r,n),n=null),t.createElement(u,i({promise:this,callback:e,fallback:n},r))},r.prototype.suspense=function(e,n,r){return void 0===n&&(n=null),void 0===r&&(r={}),n&&!t.isValidElement(n)&&"object"==typeof n&&(Object.assign(r,n),n=null),t.createElement(u,i({promise:this,callback:e,fallback:n},r))},o.prototype.suspense=function(e,n,r){return void 0===n&&(n=null),void 0===r&&(r={}),n&&!t.isValidElement(n)&&"object"==typeof n&&(Object.assign(r,n),n=null),t.createElement(u,i({promise:this,callback:e,fallback:n},r))},s.prototype.suspense=function(e,n,r){return void 0===n&&(n=null),void 0===r&&(r={}),n&&!t.isValidElement(n)&&"object"==typeof n&&(Object.assign(r,n),n=null),t.createElement(u,i({promise:this,callback:e,fallback:n},r))},a.prototype.suspense=function(e,n,r){return void 0===n&&(n=null),void 0===r&&(r={}),n&&!t.isValidElement(n)&&"object"==typeof n&&(Object.assign(r,n),n=null),t.createElement(u,i({promise:this,callback:e,fallback:n},r))},l.InputComponent=function(){return null},l.ViewComponent=function(){return null},l.prototype.renderInput=function(e){void 0===e&&(e={});var n=Object.getPrototypeOf(this);return t.createElement(this.InputComponent||n.constructor.InputComponent,i({},e,{field:this}))},l.prototype.renderView=function(e){void 0===e&&(e={});var n=Object.getPrototypeOf(this);return t.createElement(this.ViewComponent||n.constructor.ViewComponent,i({},e,{field:this}))},r.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 i=r.fields[e];return(null==i?void 0:i.renderView({value:this.get(e,t),item:this,slug:e,options:n}))||null},r.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 i=r.fields[e];return(null==i?void 0:i.renderInput({value:this.get(e,t),item:this,slug:e,options:n}))||null}}a.defaultProps={model:null,virtualFields:{},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,mapErrors:function(e){return e},controls:function(e){return[t.createElement("button",{className:"btn btn-primary",type:"submit"},e.submitLabel)]}};export default c;export{a as GraphandForm,c as GraphandPluginReact,u as PromiseSuspense};
//# 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("lodash"),require("flatted")):"function"==typeof define&&define.amd?define(["exports","fast-deep-equal/react","react","lodash","flatted"],t):t((e=e||self).graphandReact={},e.isEqual,e.react,e.lodash,e.flatted)}(this,function(e,t,n,r,i){function o(){return(o=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}).apply(this,arguments)}function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n,r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var a=function(e){function n(n){var r;return(r=e.call(this,n)||this).state={res:void 0,loading:!1},r.update=function(){try{var e=function(){r.updating=!1};r.updating=!0,r.setState({loading:!0});var n=r.props.promise,i=u(function(){function e(){var e=function(){var e,t,n;if(o)return null!==(e=r.subscription)&&void 0!==e&&e.unsubscribe&&(null===(n=r.subscription)||void 0===n||n.unsubscribe()),r.props.subscribe&&null!==(t=i)&&void 0!==t&&t.subscribe&&(r.subscription=i.subscribe(function(e){return r.setState({res:e})})),Promise.resolve(new Promise(function(e){return r.setState({res:i,loading:!1},e)})).then(function(){});var s=function(){if(r.state.loading)return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})}();return s&&s.then?s.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}var i,o=!0,s=r.props.checkUpdate?Promise.resolve(Promise.all([n,r.props.promise])).then(function(e){var n=e[0];o=!t(n,e[1]),i=n}):Promise.resolve(n).then(function(e){i=e});return s&&s.then?s.then(e):e()},function(){return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})});return Promise.resolve(i&&i.then?i.then(e):e())}catch(e){return Promise.reject(e)}},n.promise&&void 0===n.promise.then&&(r.state.res=n.promise),r}s(n,e);var r=n.prototype;return r.componentDidMount=function(){try{var e=this,n=u(function(){function n(){var t;e.props.subscribe&&null!==(t=r)&&void 0!==t&&t.subscribe&&(e.subscription=r.subscribe(function(t){return e.setState({res:t})}))}var r=e.props.promise,i=function(){var n,i;if(e.props.promise&&void 0!==e.props.promise.then||!t(null===(n=e.state.res)||void 0===n?void 0:n.query,null===(i=e.props.promise)||void 0===i?void 0:i.query))return Promise.resolve(e.props.promise).then(function(t){e.setState({res:r=t})})}();return i&&i.then?i.then(n):n()},function(t){console.error(t),e.setState({res:void 0})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},r.componentDidUpdate=function(e,n){try{return(!t(this.props.updateKey,e.updateKey)||this.props.update&&!this.updating)&&this.update(),Promise.resolve()}catch(e){return Promise.reject(e)}},r.componentWillUnmount=function(){this.subscription&&this.subscription.unsubscribe()},r.renderCallback=function(){var e=this.props.callback||this.props.children;return"function"==typeof e?e(this.state.res,this.state.loading):e},r.renderFallback=function(){var e=this.props.fallback;return"function"==typeof e?e(this.state.res,this.state.loading):e},r.render=function(){var e=void 0===this.state.res?this.renderFallback():this.renderCallback();return void 0!==e?e:null},n}(n.Component);a.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!0,checkUpdate:!1};var c=function(e){function a(s){var a;return(a=e.call(this,s)||this).modified=[],a.submitted=!1,a.inputsRefs={},a.state={loading:!1,errors:[],values:{},initializing:!0},a.handleSubmit=function(e){try{e.preventDefault(),e.stopPropagation();var t=u(function(){var e=a.modified.reduce(function(e,t){return e[t]=r.get(a.values,t),void 0===r.get(e,t)&&(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]),e},a.props.values||{});return a.setState({loading:!0,errors:[]}),a.model&&a.model.beforeFormSubmit&&a.model.beforeFormSubmit.call(a.model,e,l(a)),Promise.resolve(a.props.onSubmit(e)).then(function(){var e;(null!=(e=a.props.resetAfterSubmit)?e:Boolean(a.props.instance))&&a.resetInstance().then(function(){return a.resetValues()}),a.setState({loading:!1})})},function(e){var t=Array.isArray(e)?e:[e];t=a.props.mapErrors(t),a.setState({errors:t,loading:!1});var n=t[0];if(n){var r=a.inputsRefs[n.field];r&&r.current&&r.current.focus&&r.current.focus()}});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},a.handleChange=function(e,t){void 0===t&&(t=!1);try{var n=function(){a.model&&a.model.afterFormChange&&a.model.afterFormChange.call(a.model,e,l(a))};void 0===e&&(e=a.values),a.model&&a.model.beforeFormChange&&a.model.beforeFormChange.call(a.model,e,l(a));var r=function(){if(a.props.onChange)return Promise.resolve(a.props.onChange(e,t)).then(function(){});var n=function(){if(!t)return Promise.resolve(new Promise(function(t){return a.setState({values:e},t)})).then(function(){});a.state.values=e}();return n&&n.then?n.then(function(){}):void 0}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},a.handleFieldChange=function(e,n,r){try{var s,l,u=null===(s=a.instance)||void 0===s?void 0:s.get(e,!0,r),c=i.stringify(u),d=i.stringify(n),p=t(c,d),f=r?"translations."+r+"."+e:e;a.isModified(f)&&p?a.modified=a.modified.filter(function(e){return e!==f}):p||a.isModified(f)||a.modified.push(f);var m=o({},a.values,((l={})[f]=n,l));return Promise.resolve(a.handleChange(m)).then(function(){})}catch(e){return Promise.reject(e)}},a.renderField=function(e,t,i,s){void 0===i&&(i={}),void 0===s&&(s=!0);var l=o({},i,e.inputOptions||{},a.props.fieldsOptions[t]||{});if(a.inputsRefs[t]=a.inputsRefs[t]||n.createRef(),l.hidden)return null;if(!a.props.translatable||!e.translatable){var u=a.props.getFieldOptions&&a.props.getFieldOptions(e,t)||{},c=a.values[t],d={errors:a.errors.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)}),value:s?e.getter(c,a.instance,t):c,onChange:function(e){return a.handleFieldChange(t,e)},options:o({},l,u),id:a.id+":"+t,inputRef:a.inputsRefs[t]};return e.renderInput(d)}return(a.model._client._project.locales.map(function(e){var t;return e===(null===(t=a.model._client._project)||void 0===t?void 0:t.defaultLocale)?null:e})||[null]).map(function(n){var i=t,u=r.get(a.values,n?"translations."+n+"."+i:t),c=n&&e.name?n+" - "+e.name:e.name,d=a.props.getFieldOptions&&a.props.getFieldOptions(e,i,n)||{},p={errors:a.errors.filter(function(e){return new RegExp("^"+i).test(null==e?void 0:e.field)}),value:s?e.getter(u,a.instance,i):u,onChange:function(e){return a.handleFieldChange(i,e,n)},options:o({},l,d,{label:c}),id:a.id+":"+i,inputRef:a.inputsRefs[t]};return e.renderInput(p)})},a.defaultFields=function(){return(a.props.map||Object.keys(a.fields).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)})).map(function(e){var t=a.fields[e];return t?a.renderField(t,e):null})},a.defaultTemplate=function(){return n.createElement(n.Fragment,null,a.defaultFields(),a.props.controls&&"function"==typeof a.props.controls?a.props.controls(a.props):a.props.controls||null)},a.resetInstance=function(){try{return Promise.resolve(a.props.instance).then(function(e){a.instance=e,a.instance||(a.instance=a.model&&new a.model(a.props.values))})}catch(e){return Promise.reject(e)}},a.resetValues=function(e){var t;void 0===e&&(e=!1),a.id=(null===(t=a.instance)||void 0===t?void 0:t._id)||Math.random().toString(36).substr(2,9);var n=l(a).fields,r=Object.keys(n).reduce(function(e,t){var r,i;return a.props.instance&&(i=a.instance.get(t,!0,n)),void 0===i&&(i=a.props.values&&a.props.values[t]),void 0===i&&(i=n[t].defaultValue),Object.assign(e,((r={})[t]=i,r))},{});a.handleChange(r,e)},a.isModified=function(e){return a.modified.includes(e)},a.markModified=function(e){a.modified.includes(e)||a.modified.push(e)},a.unmarkModified=function(e){a.modified.includes(e)&&(a.modified=a.modified.filter(function(t){return t!==e}))},a.formRef=n.createRef(),a}s(a,e);var c,d=a.prototype;return d.componentDidMount=function(){try{var e=this;return Promise.resolve(e.resetInstance()).then(function(){function t(){e.resetValues(),e.setState({initializing:!1})}var n=function(){if(e.model)return e.model.fieldsObserver&&e.model.fieldsObserver.list.subscribe(function(){return e.forceUpdate()}),Promise.resolve(e.model.init()).then(function(){})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},d.shouldComponentUpdate=function(e,n){return!t(this.state,n)||!t(this.props,e)},d.componentDidUpdate=function(){try{var e=this;return Promise.resolve(e.props.instance).then(function(t){var n;(null==t?void 0:t._id)===(null===(n=e.instance)||void 0===n?void 0:n._id)||!e.model||e.model.fields instanceof Promise||(e.instance=t,e.resetValues())})}catch(e){return Promise.reject(e)}},d.getDefaultFields=function(){var e=this.values;return this.instance&&((e=this.instance.clone()).model=this.instance.model,e.assign(this.values,!1)),this.model?o({},this.model.getFields(e),this.model.virtualFields,this.props.virtualFields):o({},this.props.virtualFields)},d.load=function(){this.setState({loading:!0})},d.unload=function(){this.setState({loading:!1})},d.getArgs=function(){var e=this;return{fields:Object.keys(this.fields).reduce(function(t,n){var r=e.fields[n];return r&&(t[n]=function(t,i){return void 0===t&&(t={}),e.renderField(r,n,t,i)}),t},{render:function(t,n,r){void 0===n&&(n={});var i=e.fields[t];return i?e.renderField(i,t,n,r):(console.warn("field "+t+" not found, render null"),null)},renderDefault:this.defaultFields}),isLoading:this.state.loading,isInitializing:this.state.initializing,errors:this.errors,handleSubmit:this.handleSubmit,isTranslatable:this.props.translatable,formRef:this.formRef,values:this.values}},d.render=function(){var e=this.props.template||this.props.children||this.defaultTemplate;if(n.isValidElement(e)||Array.isArray(e)&&e.every(function(e){return n.isValidElement(e)}))return n.createElement("form",{ref:this.formRef,onSubmit:this.handleSubmit},e);var t=this.getArgs();return null==e?void 0:e.call(this,t)},(c=[{key:"values",get:function(){return this.props.values||this.state.values}},{key:"model",get:function(){var e;return this.props.model||(null===(e=this.props.instance)||void 0===e?void 0:e.constructor)}},{key:"fields",get:function(){return this.props.fields&&"function"==typeof this.props.fields?this.props.fields(this.getDefaultFields()):this.props.fields||this.getDefaultFields()}},{key:"errors",get:function(){return this.state.errors.concat(this.props.errors)}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(a.prototype,c),a}(n.Component);function d(e){var t=e.constructor.lib,r=t.GraphandModel,i=t.GraphandModelListPromise,s=t.GraphandModelList,l=t.GraphandField,u=t.AggregationExecutor;t.GraphandModelPromise.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({promise:this,callback:e,fallback:t},r))},r.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({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&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({promise:this,callback:e,fallback:t},r))},s.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({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&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({promise:this,callback:e,fallback:t},r))},l.InputComponent=function(){return null},l.ViewComponent=function(){return null},l.prototype.renderInput=function(e){void 0===e&&(e={});var t=Object.getPrototypeOf(this);return n.createElement(this.InputComponent||t.constructor.InputComponent,o({},e,{field:this}))},l.prototype.renderView=function(e){void 0===e&&(e={});var t=Object.getPrototypeOf(this);return n.createElement(this.ViewComponent||t.constructor.ViewComponent,o({},e,{field:this}))},r.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 i=r.fields[e];return(null==i?void 0:i.renderView({value:this.get(e,t),item:this,slug:e,options:n}))||null},r.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 i=r.fields[e];return(null==i?void 0:i.renderInput({value:this.get(e,t),item:this,slug:e,options:n}))||null}}c.defaultProps={model:null,virtualFields:{},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,mapErrors:function(e){return e},controls:function(e){return[n.createElement("button",{className:"btn btn-primary",type:"submit"},e.submitLabel)]}},e.GraphandForm=c,e.GraphandPluginReact=d,e.PromiseSuspense=a,e.default=d});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("fast-deep-equal/react"),require("react"),require("lodash"),require("flatted")):"function"==typeof define&&define.amd?define(["exports","fast-deep-equal/react","react","lodash","flatted"],t):t((e=e||self).graphandReact={},e.isEqual,e.react,e.lodash,e.flatted)}(this,function(e,t,n,r,i){function o(){return(o=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}).apply(this,arguments)}function s(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n,r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var a=function(e){function n(n){var r;return(r=e.call(this,n)||this).state={res:void 0,loading:!1},r.update=function(){try{var e=function(){r.updating=!1};r.updating=!0,r.setState({loading:!0});var n=r.props.promise,i=u(function(){function e(){var e=function(){var e,t,n;if(o)return null!==(e=r.subscription)&&void 0!==e&&e.unsubscribe&&(null===(n=r.subscription)||void 0===n||n.unsubscribe()),r.props.subscribe&&null!==(t=i)&&void 0!==t&&t.subscribe&&(r.subscription=i.subscribe(function(e){return r.setState({res:e})})),Promise.resolve(new Promise(function(e){return r.setState({res:i,loading:!1},e)})).then(function(){});var s=function(){if(r.state.loading)return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})}();return s&&s.then?s.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}var i,o=!0,s=r.props.checkUpdate?Promise.resolve(Promise.all([n,r.props.promise])).then(function(e){var n=e[0];o=!t(n,e[1]),i=n}):Promise.resolve(n).then(function(e){i=e});return s&&s.then?s.then(e):e()},function(){return Promise.resolve(new Promise(function(e){return r.setState({loading:!1},e)})).then(function(){})});return Promise.resolve(i&&i.then?i.then(e):e())}catch(e){return Promise.reject(e)}},n.promise&&void 0===n.promise.then&&(r.state.res=n.promise),r}s(n,e);var r=n.prototype;return r.componentDidMount=function(){try{var e=this,n=u(function(){function n(){var t;e.props.subscribe&&null!==(t=r)&&void 0!==t&&t.subscribe&&(e.subscription=r.subscribe(function(t){return e.setState({res:t})}))}var r=e.props.promise,i=function(){var n,i;if(e.props.promise&&void 0!==e.props.promise.then||!t(null===(n=e.state.res)||void 0===n?void 0:n.query,null===(i=e.props.promise)||void 0===i?void 0:i.query))return Promise.resolve(e.props.promise).then(function(t){e.setState({res:r=t})})}();return i&&i.then?i.then(n):n()},function(t){console.error(t),e.setState({res:void 0})});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},r.componentDidUpdate=function(e,n){try{return(!t(this.props.updateKey,e.updateKey)||this.props.update&&!this.updating)&&this.update(),Promise.resolve()}catch(e){return Promise.reject(e)}},r.componentWillUnmount=function(){this.subscription&&this.subscription.unsubscribe()},r.renderCallback=function(){var e=this.props.callback||this.props.children;return"function"==typeof e?e(this.state.res,this.state.loading):e},r.renderFallback=function(){var e=this.props.fallback;return"function"==typeof e?e(this.state.res,this.state.loading):e},r.render=function(){var e=void 0===this.state.res?this.renderFallback():this.renderCallback();return void 0!==e?e:null},n}(n.Component);a.defaultProps={promise:Promise.resolve(),callback:null,fallback:null,update:void 0,updateKey:void 0,subscribe:!0,checkUpdate:!1};var c=function(e){function a(s){var a;return(a=e.call(this,s)||this).modified=[],a.submitted=!1,a.inputsRefs={},a.state={loading:!1,errors:[],values:{},initializing:!0},a.handleSubmit=function(e){try{e.preventDefault(),e.stopPropagation();var t=u(function(){var e=a.modified.reduce(function(e,t){return e[t]=r.get(a.values,t),void 0===r.get(e,t)&&(e.$unset=e.$unset||{},e.$unset[t]=!0,delete e[t]),e},a.props.values||{});return a.setState({loading:!0,errors:[]}),a.model&&a.model.beforeFormSubmit&&a.model.beforeFormSubmit.call(a.model,e,l(a)),Promise.resolve(a.props.onSubmit(e)).then(function(){var e;(null!=(e=a.props.resetAfterSubmit)?e:Boolean(a.props.instance))&&a.resetInstance().then(function(){return a.resetValues()}),a.setState({loading:!1})})},function(e){var t=Array.isArray(e)?e:[e];t=a.props.mapErrors(t),a.setState({errors:t,loading:!1});var n=t[0];if(n){var r=a.inputsRefs[n.field];r&&r.current&&r.current.focus&&r.current.focus()}});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},a.handleChange=function(e,t){void 0===t&&(t=!1);try{var n=function(){a.model&&a.model.afterFormChange&&a.model.afterFormChange.call(a.model,e,l(a))};void 0===e&&(e=a.values),a.model&&a.model.beforeFormChange&&a.model.beforeFormChange.call(a.model,e,l(a));var r=function(){if(a.props.onChange)return Promise.resolve(a.props.onChange(e,t)).then(function(){});var n=function(){if(!t)return Promise.resolve(new Promise(function(t){return a.setState({values:e},t)})).then(function(){});a.state.values=e}();return n&&n.then?n.then(function(){}):void 0}();return Promise.resolve(r&&r.then?r.then(n):n())}catch(e){return Promise.reject(e)}},a.handleFieldChange=function(e,n,r){try{var s,l,u=null===(s=a.instance)||void 0===s?void 0:s.get(e,!0,r),c=i.stringify(u),d=i.stringify(n),p=t(c,d),f=r?"translations."+r+"."+e:e;a.isModified(f)&&p?a.modified=a.modified.filter(function(e){return e!==f}):p||a.isModified(f)||a.modified.push(f);var m=o({},a.values,((l={})[f]=n,l));return Promise.resolve(a.handleChange(m)).then(function(){})}catch(e){return Promise.reject(e)}},a.renderField=function(e,t,i,s){void 0===i&&(i={}),void 0===s&&(s=!0);var l=o({},i,e.inputOptions||{},a.props.fieldsOptions[t]||{});if(a.inputsRefs[t]=a.inputsRefs[t]||n.createRef(),l.hidden)return null;if(!a.props.translatable||!e.translatable){var u=a.props.getFieldOptions&&a.props.getFieldOptions(e,t)||{},c=a.values[t],d={errors:a.errors.filter(function(e){return new RegExp("^"+t).test(null==e?void 0:e.field)}),value:s?e.getter(c,a.instance,t):c,onChange:function(e){return a.handleFieldChange(t,e)},options:o({},l,u),id:a.id+":"+t,inputRef:a.inputsRefs[t]};return e.renderInput(d)}return(a.model._client._project.locales.map(function(e){var t;return e===(null===(t=a.model._client._project)||void 0===t?void 0:t.defaultLocale)?null:e})||[null]).map(function(n){var i=t,u=r.get(a.values,n?"translations."+n+"."+i:t),c=n&&e.name?n+" - "+e.name:e.name,d=a.props.getFieldOptions&&a.props.getFieldOptions(e,i,n)||{},p={errors:a.errors.filter(function(e){return new RegExp("^"+i).test(null==e?void 0:e.field)}),value:s?e.getter(u,a.instance,i):u,onChange:function(e){return a.handleFieldChange(i,e,n)},options:o({},l,d,{label:c}),id:a.id+":"+i,inputRef:a.inputsRefs[t]};return e.renderInput(p)})},a.defaultFields=function(){return(a.props.map||Object.keys(a.fields).filter(function(e){return!["_id","createdBy","createdAt","updatedBy","updatedAt"].includes(e)})).map(function(e){var t=a.fields[e];return t?a.renderField(t,e):null})},a.defaultTemplate=function(){return n.createElement(n.Fragment,null,a.defaultFields(),a.props.controls&&"function"==typeof a.props.controls?a.props.controls(a.props):a.props.controls||null)},a.resetInstance=function(){try{return Promise.resolve(a.props.instance).then(function(e){a.instance=e,a.instance||(a.instance=a.model&&new a.model(a.props.values))})}catch(e){return Promise.reject(e)}},a.resetValues=function(e){var t;void 0===e&&(e=!1),a.id=(null===(t=a.instance)||void 0===t?void 0:t._id)||Math.random().toString(36).substr(2,9);var n=l(a).fields,r=Object.keys(n).reduce(function(e,t){var r,i;return a.props.instance&&(i=a.instance.get(t,!0,n)),void 0===i&&(i=a.props.values&&a.props.values[t]),void 0===i&&(i=n[t].defaultValue),Object.assign(e,((r={})[t]=i,r))},{});a.handleChange(r,e)},a.isModified=function(e){return a.modified.includes(e)},a.markModified=function(e){a.modified.includes(e)||a.modified.push(e)},a.unmarkModified=function(e){a.modified.includes(e)&&(a.modified=a.modified.filter(function(t){return t!==e}))},a.formRef=n.createRef(),a}s(a,e);var c,d=a.prototype;return d.componentDidMount=function(){try{var e=this;return Promise.resolve(e.resetInstance()).then(function(){function t(){e.resetValues(),e.setState({initializing:!1})}var n=function(){if(e.model)return e.model.fieldsObserver&&e.model.fieldsObserver.list.subscribe(function(){return e.forceUpdate()}),Promise.resolve(e.model.init()).then(function(){})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},d.shouldComponentUpdate=function(e,n){return!t(this.state,n)||!t(this.props,e)},d.componentDidUpdate=function(){try{var e=this;return Promise.resolve(e.props.instance).then(function(t){var n;(null==t?void 0:t._id)===(null===(n=e.instance)||void 0===n?void 0:n._id)||!e.model||e.model.fields instanceof Promise||(e.instance=t,e.resetValues())})}catch(e){return Promise.reject(e)}},d.getDefaultFields=function(){var e=this.values;return this.instance&&((e=this.instance.clone()).model=this.instance.model,e.assign(this.values,!1)),this.model?o({},this.model.getFields(e),this.model.virtualFields,this.props.virtualFields):o({},this.props.virtualFields)},d.load=function(){this.setState({loading:!0})},d.unload=function(){this.setState({loading:!1})},d.getArgs=function(){var e=this;return{fields:Object.keys(this.fields).reduce(function(t,n){var r=e.fields[n];return r&&(t[n]=function(t,i){return void 0===t&&(t={}),e.renderField(r,n,t,i)}),t},{render:function(t,n,r){void 0===n&&(n={});var i=e.fields[t];return i?e.renderField(i,t,n,r):(console.warn("field "+t+" not found, render null"),null)},renderDefault:this.defaultFields}),isLoading:this.state.loading,isInitializing:this.state.initializing,errors:this.errors,handleSubmit:this.handleSubmit,isTranslatable:this.props.translatable,formRef:this.formRef,values:this.values}},d.render=function(){var e=this.props.template||this.props.children||n.createElement(this.defaultTemplate);if(n.isValidElement(e)||Array.isArray(e)&&e.every(function(e){return n.isValidElement(e)}))return n.createElement("form",{ref:this.formRef,onSubmit:this.handleSubmit},e);var t=this.getArgs();return null==e?void 0:e.call(this,t)},(c=[{key:"values",get:function(){return this.props.values||this.state.values}},{key:"model",get:function(){var e;return this.props.model||(null===(e=this.props.instance)||void 0===e?void 0:e.constructor)}},{key:"fields",get:function(){return this.props.fields&&"function"==typeof this.props.fields?this.props.fields(this.getDefaultFields()):this.props.fields||this.getDefaultFields()}},{key:"errors",get:function(){return this.state.errors.concat(this.props.errors)}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(a.prototype,c),a}(n.Component);function d(e){var t=e.constructor.lib,r=t.GraphandModel,i=t.GraphandModelListPromise,s=t.GraphandModelList,l=t.GraphandField,u=t.AggregationExecutor;t.GraphandModelPromise.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({promise:this,callback:e,fallback:t},r))},r.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({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&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({promise:this,callback:e,fallback:t},r))},s.prototype.suspense=function(e,t,r){return void 0===t&&(t=null),void 0===r&&(r={}),t&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({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&&!n.isValidElement(t)&&"object"==typeof t&&(Object.assign(r,t),t=null),n.createElement(a,o({promise:this,callback:e,fallback:t},r))},l.InputComponent=function(){return null},l.ViewComponent=function(){return null},l.prototype.renderInput=function(e){void 0===e&&(e={});var t=Object.getPrototypeOf(this);return n.createElement(this.InputComponent||t.constructor.InputComponent,o({},e,{field:this}))},l.prototype.renderView=function(e){void 0===e&&(e={});var t=Object.getPrototypeOf(this);return n.createElement(this.ViewComponent||t.constructor.ViewComponent,o({},e,{field:this}))},r.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 i=r.fields[e];return(null==i?void 0:i.renderView({value:this.get(e,t),item:this,slug:e,options:n}))||null},r.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 i=r.fields[e];return(null==i?void 0:i.renderInput({value:this.get(e,t),item:this,slug:e,options:n}))||null}}c.defaultProps={model:null,virtualFields:{},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,mapErrors:function(e){return e},controls:function(e){return[n.createElement("button",{className:"btn btn-primary",type:"submit"},e.submitLabel)]}},e.GraphandForm=c,e.GraphandPluginReact=d,e.PromiseSuspense=a,e.default=d});
//# sourceMappingURL=index.umd.js.map
{
"name": "graphand-react",
"version": "0.0.2-beta",
"version": "0.0.3-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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc