@entropic-bond/crud-panel 4.1.1 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
{
|
|
5
5
|
${s}
|
|
6
6
|
}
|
|
7
|
-
`)}}static propInfo(n,t){return U.createInstance(n).getPropInfo(t)}},U._factoryMap={},U);Xt([se],ot.prototype,"_id",2);let it=ot;function se(n,t){return Zt()(n,t)}function Zt(n){return function(t,s){Object.getOwnPropertyDescriptor(t,"_persistentProperties")||(t._persistentProperties?t._persistentProperties=[...t._persistentProperties]:t._persistentProperties=[]);const l=t._persistentProperties.find(c=>c.name===s);l?Object.assign(l,n):t._persistentProperties.push({name:s,...n})}}function er(n,t){return s=>{it.registerFactory(n,s,t),s.prototype.__className=n}}const st=class me{static registerCloudStorage(t,s){me._cloudStorageFactoryMap[t]=s}static createInstance(t){const s=me._cloudStorageFactoryMap[t];if(!s)throw new Error(`You should register the ${t} cloud storage provider prior to use it`);return s()}get className(){return this.__className}static useCloudStorage(t){me._defaultCloudStorage=t}static get defaultCloudStorage(){if(!me._defaultCloudStorage)throw new Error("You should define a default cloud storage provider prior to use it");return me._defaultCloudStorage}};st._cloudStorageFactoryMap={};let ye=st;function tr(n,t){return ye.registerCloudStorage(n,t),s=>{s.prototype.__className=n}}var rr=Object.defineProperty,nr=Object.getOwnPropertyDescriptor,or=(n,t,s,l)=>{for(var c=l>1?void 0:l?nr(t,s):t,y=n.length-1,D;y>=0;y--)(D=n[y])&&(c=(l?D(t,s,c):D(c))||c);return l&&c&&rr(t,s,c),c};let Ve=class extends ye{constructor(n=""){super(),this._simulateDelay=0,this._pendingPromises=[],this.mockFileSystem={},this._pathToMockFiles=n}simulateDelay(n){return this._simulateDelay=n,this}resolveWithDelay(n){if(this._simulateDelay<=0)return Promise.resolve(n);const t=new Promise(s=>{setTimeout(()=>s(n),this._simulateDelay)});return this._pendingPromises.push(t),t.finally(()=>this._pendingPromises=this._pendingPromises.filter(s=>s===t)),t}save(n,t){const s=n;this._onProgress&&this._onProgress(0,100),this.mockFileSystem[n]=JSON.stringify(t),this._onProgress&&this._onProgress(100,100);const l=t instanceof File?t.name:s;return this.resolveWithDelay(l)}uploadControl(){return{resume:()=>{},pause:()=>{},cancel:()=>{},onProgress:n=>this._onProgress=n}}getUrl(n){return Promise.resolve(this._pathToMockFiles+n)}delete(n){return delete this.mockFileSystem[n],this.resolveWithDelay()}};Ve=or([tr("MockCloudStorage",()=>new Ve)],Ve);var ir=Object.defineProperty,sr=Object.getOwnPropertyDescriptor,ae=(n,t,s,l)=>{for(var c=l>1?void 0:l?sr(t,s):t,y=n.length-1,D;y>=0;y--)(D=n[y])&&(c=(l?D(t,s,c):D(c))||c);return l&&c&&ir(t,s,c),c};let te=class extends it{constructor(){super(...arguments),this._onChange=new J}async save({data:n,fileName:t,progress:s,cloudStorageProvider:l}={}){const c=n||this._pendingData;c&&(this._reference&&await this.delete(),this.provider=l||ye.defaultCloudStorage,this._originalFileName=t||(c instanceof File?c.name:void 0),this._reference=await this.provider.save(this.id,c,s),this._url=await this.provider.getUrl(this._reference),this._pendingData=void 0,this._onChange.notify({event:0,storedFile:this}))}uploadControl(){return this.provider.uploadControl()}async delete(){if(!this._reference)throw new Error("Cannot delete a not stored file");await this.provider.delete(this._reference),this._reference=void 0,this._url=void 0,this._onChange.notify({event:2,storedFile:this})}set provider(n){this._provider=n,this._cloudStorageProviderName=n.className}get provider(){if(!this._provider)try{this._provider=ye.createInstance(this._cloudStorageProviderName)}catch{this._provider=ye.defaultCloudStorage}return this._provider}get url(){return this._url}get mimeType(){return this._mimeType}setDataToStore(n){return this._pendingData=n,this._originalFileName=n instanceof File?n.name:void 0,this._mimeType=n instanceof Blob?n.type:void 0,this._onChange.notify({event:1,pendingData:n,storedFile:this}),this}get originalFileName(){return this._originalFileName}onChange(n){return this._onChange.subscribe(n)}};ae([se],te.prototype,"_reference",2),ae([se],te.prototype,"_url",2),ae([se],te.prototype,"_cloudStorageProviderName",2),ae([se],te.prototype,"_originalFileName",2),ae([se],te.prototype,"_mimeType",2),te=ae([er("StoredFile")],te);function ar(n,t="-"){if(!n)return"";const s=n.slice(1).replace(/( |[A-Z])/g,l=>l===" "?"-":t+l[0].toLowerCase());return n[0].toLocaleLowerCase()+s.replace(/--/g,"-")}class ur{constructor(){this._stages={},this._onProgress=new J}notifyBusy(t,s){this.pushStage({name:s??"",progress:t?0:1,total:1})}pushStage(t){this._stages[t.name]=t;const s=Object.values(this._stages).reduce((l,c,y,D)=>l+c.progress/c.total/D.length,0);this._onProgress.notify({busy:s<1,overallProgress:s,stages:this._stages}),s>=1&&(this._stages={})}onProgress(t){return this._onProgress.subscribe(t)}}const re=class re{constructor(t){this.progressController=new ur,this.onChangeHdl=new J,this.onErrorHdl=new J,this.validator={},this.setDocument(t||this.createDocument())}allRequiredPropertiesFilled(){return this.nonFilledRequiredProperties.length<=0}get nonFilledRequiredProperties(){return this.requiredProperties.filter(t=>this.validateProp(t))}get requiredProperties(){if(!this.document)throw new Error(re.errorMessages.missedDocument);return this.document.getPersistentProperties().filter(t=>this.document.isRequired(t.name)).map(t=>t.name)}addValidator(t,s,l){this.validator[t]={func:s,errorMessage:l}}removeValidator(t){delete this.validator[t]}failedValidationError(t){var s;return(s=this.validator[t])==null?void 0:s.errorMessage}validateProp(t){if(!this.document)throw new Error(re.errorMessages.missedDocument);const s=this.document[t];return this.validator[t]?!this.validator[t].func(s):!this.document.isPropValueValid(t)}storeDoc(){if(!this.document)throw new Error(re.errorMessages.missedDocument);return this.model.save(this.document)}deleteDoc(){if(!this.document)throw new Error(re.errorMessages.missedDocument);return this.model.delete(this.document.id)}queryDocs(t){let s=this.model.find();return t&&(s=s.limit(t)),s}findDocs(t){}async setFilter(t){return this._filter=t,this.onChangeHdl.notify({action:"filterChange"}),this}resetFilter(){return this._filter=void 0,this.onChangeHdl.notify({action:"filterChange"}),this}onChange(t){return this.onChangeHdl.subscribe(t)}onError(t){return this.onErrorHdl.subscribe(t)}notifyChange(t){this.onChangeHdl.notify(t)}newDocument(){return this.setDocument(this.createDocument())}async storeDocument(){const t="Saving main document";try{this.progressController.notifyBusy(!0,t),await this.storeDoc(),this.onChangeHdl.notify({documentCollection:await this.documentCollection(),action:"saved"})}catch(s){if(this.onChangeHdl.notify({error:this.errorToError(s)}),this.onErrorHdl.notify(this.errorToError(s)),this.throwOnError)throw s}finally{this.progressController.notifyBusy(!1,t)}}async deleteDocument(){const t="Delete main document";try{this.progressController.notifyBusy(!0,t),await this.deleteDoc(),this.onChangeHdl.notify({documentCollection:await this.documentCollection(),action:"deleted"})}catch(s){if(this.onChangeHdl.notify({error:this.errorToError(s)}),this.onErrorHdl.notify(this.errorToError(s)),this.throwOnError)throw s}finally{this.progressController.notifyBusy(!1,t)}}async documentCollection(t){const s="Retrieving document collection";let l=[];try{this.progressController.notifyBusy(!0,s);const c=this.findDocs(t);c?l=await c:l=await this.queryDocs(t).get()}catch(c){if(this.onChangeHdl.notify({error:this.errorToError(c)}),this.onErrorHdl.notify(this.errorToError(c)),this.throwOnError)throw c}finally{this.progressController.notifyBusy(!1,s)}return l}filter(t){return t.filter(s=>{var l;return((l=this._filter)==null?void 0:l.call(this,s))??!0})}onProgress(t){return this.progressController.onProgress(t)}get model(){return this._model||(this._model=this.getModel())}setDocument(t){return this._document!==t&&(this.unsubscribeDocument&&this.unsubscribeDocument(),t&&(this.unsubscribeDocument=t.onChange(s=>this.onChangeHdl.notify({documentProps:s}))),this._document=t,this.onChangeHdl.notify({documentChanged:this._document})),this}set document(t){this.setDocument(t)}get document(){return this._document}managedThrow(t){if(this.onChangeHdl.notify({error:this.errorToError(t)}),this.onErrorHdl.notify(this.errorToError(t)),this.throwOnError)throw this.errorToError(t)}errorToError(t){return t instanceof Error?t:typeof t=="string"?new Error(t):"code"in t?new Error(t.code):"message"in t?new Error(t.error):new Error(JSON.stringify(t))}get throwOnError(){return this.onErrorHdl.subscribersCount===0}};re.errorMessages={missedDocument:"No document to save"};let xe=re;function cr(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var We={exports:{}},g={};/**
|
|
7
|
+
`)}}static propInfo(n,t){return U.createInstance(n).getPropInfo(t)}},U._factoryMap={},U);Xt([se],ot.prototype,"_id",2);let it=ot;function se(n,t){return Zt()(n,t)}function Zt(n){return function(t,s){Object.getOwnPropertyDescriptor(t,"_persistentProperties")||(t._persistentProperties?t._persistentProperties=[...t._persistentProperties]:t._persistentProperties=[]);const l=t._persistentProperties.find(c=>c.name===s);l?Object.assign(l,n):t._persistentProperties.push({name:s,...n})}}function er(n,t){return s=>{it.registerFactory(n,s,t),s.prototype.__className=n}}const st=class me{static registerCloudStorage(t,s){me._cloudStorageFactoryMap[t]=s}static createInstance(t){const s=me._cloudStorageFactoryMap[t];if(!s)throw new Error(`You should register the ${t} cloud storage provider prior to use it`);return s()}get className(){return this.__className}static useCloudStorage(t){me._defaultCloudStorage=t}static get defaultCloudStorage(){if(!me._defaultCloudStorage)throw new Error("You should define a default cloud storage provider prior to use it");return me._defaultCloudStorage}};st._cloudStorageFactoryMap={};let ye=st;function tr(n,t){return ye.registerCloudStorage(n,t),s=>{s.prototype.__className=n}}var rr=Object.defineProperty,nr=Object.getOwnPropertyDescriptor,or=(n,t,s,l)=>{for(var c=l>1?void 0:l?nr(t,s):t,y=n.length-1,D;y>=0;y--)(D=n[y])&&(c=(l?D(t,s,c):D(c))||c);return l&&c&&rr(t,s,c),c};let Ve=class extends ye{constructor(n=""){super(),this._simulateDelay=0,this._pendingPromises=[],this.mockFileSystem={},this._pathToMockFiles=n}simulateDelay(n){return this._simulateDelay=n,this}resolveWithDelay(n){if(this._simulateDelay<=0)return Promise.resolve(n);const t=new Promise(s=>{setTimeout(()=>s(n),this._simulateDelay)});return this._pendingPromises.push(t),t.finally(()=>this._pendingPromises=this._pendingPromises.filter(s=>s===t)),t}save(n,t){const s=n;this._onProgress&&this._onProgress(0,100),this.mockFileSystem[n]=JSON.stringify(t),this._onProgress&&this._onProgress(100,100);const l=t instanceof File?t.name:s;return this.resolveWithDelay(l)}uploadControl(){return{resume:()=>{},pause:()=>{},cancel:()=>{},onProgress:n=>this._onProgress=n}}getUrl(n){return Promise.resolve(this._pathToMockFiles+n)}delete(n){return delete this.mockFileSystem[n],this.resolveWithDelay()}};Ve=or([tr("MockCloudStorage",()=>new Ve)],Ve);var ir=Object.defineProperty,sr=Object.getOwnPropertyDescriptor,ae=(n,t,s,l)=>{for(var c=l>1?void 0:l?sr(t,s):t,y=n.length-1,D;y>=0;y--)(D=n[y])&&(c=(l?D(t,s,c):D(c))||c);return l&&c&&ir(t,s,c),c};let te=class extends it{constructor(){super(...arguments),this._onChange=new J}async save({data:n,fileName:t,progress:s,cloudStorageProvider:l}={}){const c=n||this._pendingData;c&&(this._reference&&await this.delete(),this.provider=l||ye.defaultCloudStorage,this._originalFileName=t||(c instanceof File?c.name:void 0),this._reference=await this.provider.save(this.id,c,s),this._url=await this.provider.getUrl(this._reference),this._pendingData=void 0,this._onChange.notify({event:0,storedFile:this}))}uploadControl(){return this.provider.uploadControl()}async delete(){if(!this._reference)throw new Error("Cannot delete a not stored file");await this.provider.delete(this._reference),this._reference=void 0,this._url=void 0,this._onChange.notify({event:2,storedFile:this})}set provider(n){this._provider=n,this._cloudStorageProviderName=n.className}get provider(){if(!this._provider)try{this._provider=ye.createInstance(this._cloudStorageProviderName)}catch{this._provider=ye.defaultCloudStorage}return this._provider}get url(){return this._url}get mimeType(){return this._mimeType}setDataToStore(n){return this._pendingData=n,this._originalFileName=n instanceof File?n.name:void 0,this._mimeType=n instanceof Blob?n.type:void 0,this._onChange.notify({event:1,pendingData:n,storedFile:this}),this}get originalFileName(){return this._originalFileName}onChange(n){return this._onChange.subscribe(n)}};ae([se],te.prototype,"_reference",2),ae([se],te.prototype,"_url",2),ae([se],te.prototype,"_cloudStorageProviderName",2),ae([se],te.prototype,"_originalFileName",2),ae([se],te.prototype,"_mimeType",2),te=ae([er("StoredFile")],te);function ar(n,t="-"){if(!n)return"";const s=n.slice(1).replace(/( |[A-Z])/g,l=>l===" "?"-":t+l[0].toLowerCase());return n[0].toLocaleLowerCase()+s.replace(/--/g,"-")}class ur{constructor(){this._stages={},this._onProgress=new J}notifyBusy(t,s){this.pushStage({name:s??"",progress:t?0:1,total:1})}pushStage(t){this._stages[t.name]=t;const s=Object.values(this._stages).reduce((l,c,y,D)=>l+c.progress/c.total/D.length,0);this._onProgress.notify({busy:s<1,overallProgress:s,stages:this._stages}),s>=1&&(this._stages={})}onProgress(t){return this._onProgress.subscribe(t)}}const re=class re{constructor(t){this.progressController=new ur,this.onChangeHdl=new J,this.onErrorHdl=new J,this.validator={},this.setDocument(t||this.createDocument())}allRequiredPropertiesFilled(){return this.nonFilledRequiredProperties.length<=0}get nonFilledRequiredProperties(){return this.requiredProperties.filter(t=>this.validateProp(t))}get requiredProperties(){if(!this.document)throw new Error(re.errorMessages.missedDocument);return this.document.getPersistentProperties().filter(t=>this.document.isRequired(t.name)).map(t=>t.name).concat(Object.keys(this.validator))}addValidator(t,s,l){this.validator[t]={func:s,errorMessage:l}}removeValidator(t){delete this.validator[t]}failedValidationError(t){var s;return(s=this.validator[t])==null?void 0:s.errorMessage}validateProp(t){if(!this.document)throw new Error(re.errorMessages.missedDocument);const s=this.document[t];return this.validator[t]?!this.validator[t].func(s):!this.document.isPropValueValid(t)}storeDoc(){if(!this.document)throw new Error(re.errorMessages.missedDocument);return this.model.save(this.document)}deleteDoc(){if(!this.document)throw new Error(re.errorMessages.missedDocument);return this.model.delete(this.document.id)}queryDocs(t){let s=this.model.find();return t&&(s=s.limit(t)),s}findDocs(t){}async setFilter(t){return this._filter=t,this.onChangeHdl.notify({action:"filterChange"}),this}resetFilter(){return this._filter=void 0,this.onChangeHdl.notify({action:"filterChange"}),this}onChange(t){return this.onChangeHdl.subscribe(t)}onError(t){return this.onErrorHdl.subscribe(t)}notifyChange(t){this.onChangeHdl.notify(t)}newDocument(){return this.setDocument(this.createDocument())}async storeDocument(){const t="Saving main document";try{this.progressController.notifyBusy(!0,t),await this.storeDoc(),this.onChangeHdl.notify({documentCollection:await this.documentCollection(),action:"saved"})}catch(s){if(this.onChangeHdl.notify({error:this.errorToError(s)}),this.onErrorHdl.notify(this.errorToError(s)),this.throwOnError)throw s}finally{this.progressController.notifyBusy(!1,t)}}async deleteDocument(){const t="Delete main document";try{this.progressController.notifyBusy(!0,t),await this.deleteDoc(),this.onChangeHdl.notify({documentCollection:await this.documentCollection(),action:"deleted"})}catch(s){if(this.onChangeHdl.notify({error:this.errorToError(s)}),this.onErrorHdl.notify(this.errorToError(s)),this.throwOnError)throw s}finally{this.progressController.notifyBusy(!1,t)}}async documentCollection(t){const s="Retrieving document collection";let l=[];try{this.progressController.notifyBusy(!0,s);const c=this.findDocs(t);c?l=await c:l=await this.queryDocs(t).get()}catch(c){if(this.onChangeHdl.notify({error:this.errorToError(c)}),this.onErrorHdl.notify(this.errorToError(c)),this.throwOnError)throw c}finally{this.progressController.notifyBusy(!1,s)}return l}filter(t){return t.filter(s=>{var l;return((l=this._filter)==null?void 0:l.call(this,s))??!0})}onProgress(t){return this.progressController.onProgress(t)}get model(){return this._model||(this._model=this.getModel())}setDocument(t){return this._document!==t&&(this.unsubscribeDocument&&this.unsubscribeDocument(),t&&(this.unsubscribeDocument=t.onChange(s=>this.onChangeHdl.notify({documentProps:s}))),this._document=t,this.onChangeHdl.notify({documentChanged:this._document})),this}set document(t){this.setDocument(t)}get document(){return this._document}managedThrow(t){if(this.onChangeHdl.notify({error:this.errorToError(t)}),this.onErrorHdl.notify(this.errorToError(t)),this.throwOnError)throw this.errorToError(t)}errorToError(t){return t instanceof Error?t:typeof t=="string"?new Error(t):"code"in t?new Error(t.code):"message"in t?new Error(t.error):new Error(JSON.stringify(t))}get throwOnError(){return this.onErrorHdl.subscribersCount===0}};re.errorMessages={missedDocument:"No document to save"};let xe=re;function cr(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var We={exports:{}},g={};/**
|
|
8
8
|
* @license React
|
|
9
9
|
* react.production.min.js
|
|
10
10
|
*
|