@entropic-bond/crud-panel 4.3.0 → 4.3.1
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
|
${i}
|
|
6
6
|
}
|
|
7
|
-
`)}}static propInfo(r,t){return Y.createInstance(r).getPropInfo(t)}static getSystemRegisteredReferencesWithCachedProps(){return Y.registeredClasses().reduce((r,t)=>{const i=Y.createInstance(t).getPersistentProperties().filter(f=>{var c;return(c=f.cachedPropsConfig)==null?void 0:c.cachedProps});return i.length>0&&(r[t]=i),r},{})}},Y._factoryMap={},Y);Yt([$e],at.prototype,"_id");let ct=at;function $e(r,t){return Ht()(r,t)}function Ht(r){return function(t,i){Object.getOwnPropertyDescriptor(t,"_persistentProperties")||(t._persistentProperties?t._persistentProperties=[...t._persistentProperties]:t._persistentProperties=[]);const f=t._persistentProperties.find(c=>c.name===i);f?Object.assign(f,r):t._persistentProperties.push({name:i,...r})}}function Ut(r,t){return i=>{ct.registerFactory(r,i,t),i.prototype.__className=r}}const lt=class Ue{static registerCloudStorage(t,i){Ue._cloudStorageFactoryMap[t]=i}static createInstance(t){const i=Ue._cloudStorageFactoryMap[t];if(!i)throw new Error(`You should register the ${t} cloud storage provider prior to use it`);return i()}get className(){return this.__className}static useCloudStorage(t){Ue._defaultCloudStorage=t}static get defaultCloudStorage(){if(!Ue._defaultCloudStorage)throw new Error("You should define a default cloud storage provider prior to use it");return Ue._defaultCloudStorage}};lt._cloudStorageFactoryMap={};let Ie=lt;function It(r,t){return Ie.registerCloudStorage(r,t),i=>{i.prototype.__className=r}}var qt=(r,t,i,f)=>{for(var c=t,g=r.length-1,S;g>=0;g--)(S=r[g])&&(c=S(c)||c);return c};let tt=class extends Ie{constructor(r=""){super(),this._simulateDelay=0,this._pendingPromises=[],this.mockFileSystem={},this._pathToMockFiles=r}simulateDelay(r){return this._simulateDelay=r,this}resolveWithDelay(r){if(this._simulateDelay<=0)return Promise.resolve(r);const t=new Promise(i=>{setTimeout(()=>i(r),this._simulateDelay)});return this._pendingPromises.push(t),t.finally(()=>this._pendingPromises=this._pendingPromises.filter(i=>i===t)),t}save(r,t){const i=r;this._onProgress&&this._onProgress(0,100),this.mockFileSystem[r]=JSON.stringify(t),this._onProgress&&this._onProgress(100,100);const f=t instanceof File?t.name:i;return this.resolveWithDelay(f)}uploadControl(){return{resume:()=>{},pause:()=>{},cancel:()=>{},onProgress:r=>this._onProgress=r}}getUrl(r){return Promise.resolve(this._pathToMockFiles+r)}delete(r){return delete this.mockFileSystem[r],this.resolveWithDelay()}};tt=qt([It("MockCloudStorage",()=>new tt)],tt);var Lt=Object.defineProperty,Wt=Object.getOwnPropertyDescriptor,xe=(r,t,i,f)=>{for(var c=f>1?void 0:f?Wt(t,i):t,g=r.length-1,S;g>=0;g--)(S=r[g])&&(c=(f?S(t,i,c):S(c))||c);return f&&c&&Lt(t,i,c),c};let Oe=class extends ct{constructor(){super(...arguments),this._onChange=new de}async save({data:r,fileName:t,progress:i,cloudStorageProvider:f}={}){const c=r||this._pendingData;c&&(this._reference&&await this.delete(),this.provider=f||Ie.defaultCloudStorage,this._originalFileName=t||(c instanceof File?c.name:void 0),this._reference=await this.provider.save(this.id,c,i),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(r){this._provider=r,this._cloudStorageProviderName=r.className}get provider(){if(!this._provider)try{this._provider=Ie.createInstance(this._cloudStorageProviderName)}catch{this._provider=Ie.defaultCloudStorage}return this._provider}get url(){return this._url}get mimeType(){return this._mimeType}setDataToStore(r){return this._pendingData=r,this._originalFileName=r instanceof File?r.name:void 0,this._mimeType=r instanceof Blob?r.type:void 0,this._onChange.notify({event:1,pendingData:r,storedFile:this}),this}get originalFileName(){return this._originalFileName}onChange(r){return this._onChange.subscribe(r)}};xe([$e],Oe.prototype,"_reference",2),xe([$e],Oe.prototype,"_url",2),xe([$e],Oe.prototype,"_cloudStorageProviderName",2),xe([$e],Oe.prototype,"_originalFileName",2),xe([$e],Oe.prototype,"_mimeType",2),Oe=xe([Ut("StoredFile")],Oe);function zt(r,t="-"){if(!r)return"";const i=r.slice(1).replace(/( |[A-Z])/g,f=>f===" "?"-":t+f[0].toLowerCase());return r[0].toLocaleLowerCase()+i.replace(/--/g,"-")}class Vt{constructor(){this._debug=!1,this._stages={},this._onProgress=new de}notifyBusy(t,i){this.pushStage({name:i??"",progress:t?0:1,total:1})}pushStage(t){this._stages[t.name]=t;const i=Object.values(this._stages).reduce((f,c,g,S)=>f+c.progress/c.total/S.length,0);this._onProgress.notify({busy:i<1,overallProgress:i,stages:this._stages}),i>=1&&(this._stages={}),this.debug&&console.log(`ProgressController ${t.name}: Progress: ${t.progress} Stages: ${t.total}`)}onProgress(t){return this._onProgress.subscribe(t)}set debug(t){this._debug=t}get debug(){return this._debug}}const he=class he{constructor(t){this.progressController=new Vt,this.onChangeHdl=new de,this.onErrorHdl=new de,this.validator={},this.setDocument(t||this.createDocument())}allRequiredPropertiesFilled(){return this.nonFilledRequiredProperties.length<=0&&this.validateGlobal()}get nonFilledRequiredProperties(){return this.requiredProperties.filter(t=>this.validateProp(t))}get requiredProperties(){if(!this.document)throw new Error(he.errorMessages.missedDocument);const t=this.document.getPersistentProperties().filter(f=>this.document.isRequired(f.name)).map(f=>f.name);return[...new Set(t.concat(Object.keys(this.validator)))]}addValidator(t,i,f){this.validator[t]={func:i,errorMessage:f}}removeValidator(t){delete this.validator[t]}addGlobalValidator(t,i){this.globalValidator={func:t,errorMessage:i}}removeGlobalValidator(){this.globalValidator=void 0}failedValidationError(t){var f,c,g;if(t)return(f=this.validator[t])==null?void 0:f.errorMessage;const i=this.nonFilledRequiredProperties[0];return i?(c=this.validator[i])==null?void 0:c.errorMessage:(g=this.globalValidator)==null?void 0:g.errorMessage}validateProp(t){if(!this.document)throw new Error(he.errorMessages.missedDocument);const i=this.document[t];return this.validator[t]?!this.validator[t].func(i):!this.document.isPropValueValid(t)}validateGlobal(){if(!this.document)throw new Error(he.errorMessages.missedDocument);return this.globalValidator?this.globalValidator.func(this.document):!0}storeDoc(){if(!this.document)throw new Error(he.errorMessages.missedDocument);return this.model.save(this.document)}deleteDoc(){if(!this.document)throw new Error(he.errorMessages.missedDocument);return this.model.delete(this.document.id)}queryDocs(t){let i=this.model.find();return t&&(i=i.limit(t)),i}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(i){if(this.onChangeHdl.notify({error:this.errorToError(i)}),this.onErrorHdl.notify(this.errorToError(i)),this.throwOnError)throw i}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(i){if(this.onChangeHdl.notify({error:this.errorToError(i)}),this.onErrorHdl.notify(this.errorToError(i)),this.throwOnError)throw i}finally{this.progressController.notifyBusy(!1,t)}}async documentCollection(t){const i="Retrieving document collection";let f=[];try{this.progressController.notifyBusy(!0,i);const c=this.findDocs(t);c?f=await c:f=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,i)}return f}filter(t){return t.filter(i=>{var f;return((f=this._filter)==null?void 0:f.call(this,i))??!0})}onProgress(t){return this.progressController.onProgress(t)}get model(){return this.
|
|
7
|
+
`)}}static propInfo(r,t){return Y.createInstance(r).getPropInfo(t)}static getSystemRegisteredReferencesWithCachedProps(){return Y.registeredClasses().reduce((r,t)=>{const i=Y.createInstance(t).getPersistentProperties().filter(f=>{var c;return(c=f.cachedPropsConfig)==null?void 0:c.cachedProps});return i.length>0&&(r[t]=i),r},{})}},Y._factoryMap={},Y);Yt([$e],at.prototype,"_id");let ct=at;function $e(r,t){return Ht()(r,t)}function Ht(r){return function(t,i){Object.getOwnPropertyDescriptor(t,"_persistentProperties")||(t._persistentProperties?t._persistentProperties=[...t._persistentProperties]:t._persistentProperties=[]);const f=t._persistentProperties.find(c=>c.name===i);f?Object.assign(f,r):t._persistentProperties.push({name:i,...r})}}function Ut(r,t){return i=>{ct.registerFactory(r,i,t),i.prototype.__className=r}}const lt=class Ue{static registerCloudStorage(t,i){Ue._cloudStorageFactoryMap[t]=i}static createInstance(t){const i=Ue._cloudStorageFactoryMap[t];if(!i)throw new Error(`You should register the ${t} cloud storage provider prior to use it`);return i()}get className(){return this.__className}static useCloudStorage(t){Ue._defaultCloudStorage=t}static get defaultCloudStorage(){if(!Ue._defaultCloudStorage)throw new Error("You should define a default cloud storage provider prior to use it");return Ue._defaultCloudStorage}};lt._cloudStorageFactoryMap={};let Ie=lt;function It(r,t){return Ie.registerCloudStorage(r,t),i=>{i.prototype.__className=r}}var qt=(r,t,i,f)=>{for(var c=t,g=r.length-1,S;g>=0;g--)(S=r[g])&&(c=S(c)||c);return c};let tt=class extends Ie{constructor(r=""){super(),this._simulateDelay=0,this._pendingPromises=[],this.mockFileSystem={},this._pathToMockFiles=r}simulateDelay(r){return this._simulateDelay=r,this}resolveWithDelay(r){if(this._simulateDelay<=0)return Promise.resolve(r);const t=new Promise(i=>{setTimeout(()=>i(r),this._simulateDelay)});return this._pendingPromises.push(t),t.finally(()=>this._pendingPromises=this._pendingPromises.filter(i=>i===t)),t}save(r,t){const i=r;this._onProgress&&this._onProgress(0,100),this.mockFileSystem[r]=JSON.stringify(t),this._onProgress&&this._onProgress(100,100);const f=t instanceof File?t.name:i;return this.resolveWithDelay(f)}uploadControl(){return{resume:()=>{},pause:()=>{},cancel:()=>{},onProgress:r=>this._onProgress=r}}getUrl(r){return Promise.resolve(this._pathToMockFiles+r)}delete(r){return delete this.mockFileSystem[r],this.resolveWithDelay()}};tt=qt([It("MockCloudStorage",()=>new tt)],tt);var Lt=Object.defineProperty,Wt=Object.getOwnPropertyDescriptor,xe=(r,t,i,f)=>{for(var c=f>1?void 0:f?Wt(t,i):t,g=r.length-1,S;g>=0;g--)(S=r[g])&&(c=(f?S(t,i,c):S(c))||c);return f&&c&&Lt(t,i,c),c};let Oe=class extends ct{constructor(){super(...arguments),this._onChange=new de}async save({data:r,fileName:t,progress:i,cloudStorageProvider:f}={}){const c=r||this._pendingData;c&&(this._reference&&await this.delete(),this.provider=f||Ie.defaultCloudStorage,this._originalFileName=t||(c instanceof File?c.name:void 0),this._reference=await this.provider.save(this.id,c,i),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(r){this._provider=r,this._cloudStorageProviderName=r.className}get provider(){if(!this._provider)try{this._provider=Ie.createInstance(this._cloudStorageProviderName)}catch{this._provider=Ie.defaultCloudStorage}return this._provider}get url(){return this._url}get mimeType(){return this._mimeType}setDataToStore(r){return this._pendingData=r,this._originalFileName=r instanceof File?r.name:void 0,this._mimeType=r instanceof Blob?r.type:void 0,this._onChange.notify({event:1,pendingData:r,storedFile:this}),this}get originalFileName(){return this._originalFileName}onChange(r){return this._onChange.subscribe(r)}};xe([$e],Oe.prototype,"_reference",2),xe([$e],Oe.prototype,"_url",2),xe([$e],Oe.prototype,"_cloudStorageProviderName",2),xe([$e],Oe.prototype,"_originalFileName",2),xe([$e],Oe.prototype,"_mimeType",2),Oe=xe([Ut("StoredFile")],Oe);function zt(r,t="-"){if(!r)return"";const i=r.slice(1).replace(/( |[A-Z])/g,f=>f===" "?"-":t+f[0].toLowerCase());return r[0].toLocaleLowerCase()+i.replace(/--/g,"-")}class Vt{constructor(){this._debug=!1,this._stages={},this._onProgress=new de}notifyBusy(t,i){this.pushStage({name:i??"",progress:t?0:1,total:1})}pushStage(t){this._stages[t.name]=t;const i=Object.values(this._stages).reduce((f,c,g,S)=>f+c.progress/c.total/S.length,0);this._onProgress.notify({busy:i<1,overallProgress:i,stages:this._stages}),i>=1&&(this._stages={}),this.debug&&console.log(`ProgressController ${t.name}: Progress: ${t.progress} Stages: ${t.total}`)}onProgress(t){return this._onProgress.subscribe(t)}set debug(t){this._debug=t}get debug(){return this._debug}}const he=class he{constructor(t){this.progressController=new Vt,this.onChangeHdl=new de,this.onErrorHdl=new de,this.validator={},this.setDocument(t||this.createDocument())}allRequiredPropertiesFilled(){return this.nonFilledRequiredProperties.length<=0&&this.validateGlobal()}get nonFilledRequiredProperties(){return this.requiredProperties.filter(t=>this.validateProp(t))}get requiredProperties(){if(!this.document)throw new Error(he.errorMessages.missedDocument);const t=this.document.getPersistentProperties().filter(f=>this.document.isRequired(f.name)).map(f=>f.name);return[...new Set(t.concat(Object.keys(this.validator)))]}addValidator(t,i,f){this.validator[t]={func:i,errorMessage:f}}removeValidator(t){delete this.validator[t]}addGlobalValidator(t,i){this.globalValidator={func:t,errorMessage:i}}removeGlobalValidator(){this.globalValidator=void 0}failedValidationError(t){var f,c,g;if(t)return(f=this.validator[t])==null?void 0:f.errorMessage;const i=this.nonFilledRequiredProperties[0];return i?(c=this.validator[i])==null?void 0:c.errorMessage:(g=this.globalValidator)==null?void 0:g.errorMessage}validateProp(t){if(!this.document)throw new Error(he.errorMessages.missedDocument);const i=this.document[t];return this.validator[t]?!this.validator[t].func(i):!this.document.isPropValueValid(t)}validateGlobal(){if(!this.document)throw new Error(he.errorMessages.missedDocument);return this.globalValidator?this.globalValidator.func(this.document):!0}storeDoc(){if(!this.document)throw new Error(he.errorMessages.missedDocument);return this.model.save(this.document)}deleteDoc(){if(!this.document)throw new Error(he.errorMessages.missedDocument);return this.model.delete(this.document.id)}queryDocs(t){let i=this.model.find();return t&&(i=i.limit(t)),i}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(i){if(this.onChangeHdl.notify({error:this.errorToError(i)}),this.onErrorHdl.notify(this.errorToError(i)),this.throwOnError)throw i}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(i){if(this.onChangeHdl.notify({error:this.errorToError(i)}),this.onErrorHdl.notify(this.errorToError(i)),this.throwOnError)throw i}finally{this.progressController.notifyBusy(!1,t)}}async documentCollection(t){const i="Retrieving document collection";let f=[];try{this.progressController.notifyBusy(!0,i);const c=this.findDocs(t);c?f=await c:f=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,i)}return f}filter(t){return t.filter(i=>{var f;return((f=this._filter)==null?void 0:f.call(this,i))??!0})}onProgress(t){return this.progressController.onProgress(t)}get model(){return this.getModel()}setDocument(t){return this._document!==t&&(this.unsubscribeDocument&&this.unsubscribeDocument(),t&&(this.unsubscribeDocument=t.onChange(i=>this.onChangeHdl.notify({documentProps:i}))),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}};he.errorMessages={missedDocument:"No document to save"};let rt=he;var Fe={exports:{}},qe={};/**
|
|
8
8
|
* @license React
|
|
9
9
|
* react-jsx-runtime.production.js
|
|
10
10
|
*
|