UNPKG

4.93 kBJavaScriptView Raw
1(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):(a=a||self,b(a.dataObjectHooks={}))})(this,function(a){"use strict";function b(a){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},b(a)}function c(a,b){return d(a)||e(a,b)||f()}function d(a){if(Array.isArray(a))return a}function e(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}function f(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function g(a,c){var d=window.af.data,e=new d.DataProviderHandler({dataSourceId:a.getDataSourceId(),timeout:3e4}),f=a.getFields();return new Promise(function(a,d){var g={filterString:"",whereClause:"string"==typeof c?c:"",whereObject:"object"===b(c)?c:null};e.retrieve(g,function(b,c){if(null!==b)d(b);else{var e=[],g=!0,h=!1,j=void 0;try{for(var k,l=c[Symbol.iterator]();!(g=(k=l.next()).done);g=!0){for(var m=k.value,n={},o=0;o<m.length;o++)n[f[o].name]=m[o];e.push(n)}}catch(a){h=!0,j=a}finally{try{g||null==l.return||l.return()}finally{if(h)throw j}}a(e)}})})}function h(a,b){var c=i(a,b),d=c.isLoading,e=c.data,f=c.refresh,g=0<e.length?e[0]:{};return{record:g,refresh:f,isLoading:d}}function i(a,b){function d(){o(!0),g(a,b).then(function(a){0<a.length?i(a):i([]),o(!1)})}var e=m([]),f=c(e,2),h=f[0],i=f[1],j=m(!0),k=c(j,2),l=k[0],o=k[1];return n(function(){d()},[a,b]),{data:h,refresh:d,isLoading:l}}const{React:j}=window,k=j.PureComponent,l=j.Component,m=j.useState,n=j.useEffect;var o=["onFieldChanged","onRecordCreated","onRecordDeleted","onRecordRefreshed","onAfterSave","onCancelEdit","onDataLoaded"];a.useCurrentIndex=function(a){var b=m(a.getCurrentIndex()),d=c(b,2),e=d[0],f=d[1];return n(function(){return a.attachEvent("onCurrentIndexChanged",f),f(a.getCurrentIndex()),function(){return a.detachEvent("onCurrentIndexChanged",f)}},[a]),e},a.useDirty=function(a){var b=m(!1),d=c(b,2),e=d[0],f=d[1];return n(function(){return a.attachEvent("onDirtyChanged",f),f(a.isDirty()),function(){a.detachEvent("onDirtyChanged",f)}},[a]),e},a.useError=function(a){var b=m(null),d=c(b,2),e=d[0],f=d[1];return n(function(){return a.attachEvent("onDataLoadFailed",f),function(){a.detachEvent("onDataLoadFailed",f)}},[a]),e},a.useLoading=function(a){function b(){h(!0)}function d(){h(!1)}var e=m(a.isDataLoading()),f=c(e,2),g=f[0],h=f[1];return n(function(){return a.attachEvent("onBeforeLoad",b),a.attachEvent("onDataLoaded",d),a.attachEvent("onDataLoadFailed",d),h(a.isDataLoading()),function(){a.detachEvent("onBeforeLoad",b),a.detachEvent("onDataLoaded",d),a.detachEvent("onDataLoadFailed",d)}},[a]),g},a.useStatus=function(a){function b(){j(!0)}function d(){j(!1)}function e(){p(!0)}function f(){p(!1)}var g=m(!1),h=c(g,2),i=h[0],j=h[1],k=m(!1),l=c(k,2),o=l[0],p=l[1];return n(function(){return a.attachEvent("onBeforeSave",b),a.attachEvent("onAfterSave",d),a.attachEvent("onSaveFailed",d),a.attachEvent("onRecordDeleting",e),a.attachEvent("onRecordDeleted",f),function(){a.detachEvent("onBeforeSave",b),a.detachEvent("onAfterSave",d),a.detachEvent("onSaveFailed",d),a.detachEvent("onRecordDeleting",e),a.detachEvent("onRecordDeleted",f)}},[a]),{isDeleting:o,isSaving:i}},a.usePermissions=function(a){var b=m(a.isDeleteAllowed()),d=c(b,2),e=d[0],f=d[1],g=m(a.isInsertAllowed()),h=c(g,2),i=h[0],j=h[1],k=m(a.isUpdateAllowed()),l=c(k,2),o=l[0],p=l[1];return n(function(){return a.attachEvent("onAllowDeleteChanged",f),a.attachEvent("onAllowInsertChanged",j),a.attachEvent("onAllowUpdateChanged",p),function(){a.detachEvent("onAllowDeleteChanged",f),a.detachEvent("onAllowInsertChanged",j),a.detachEvent("onAllowUpdateChanged",p)}},[a]),{allowDelete:e,allowInsert:i,allowUpdate:o}},a.useCurrentRow=function(a){function b(){g(a.currentRow())}var d=m({}),e=c(d,2),f=e[0],g=e[1];return n(function(){var c=["onCurrentIndexChanged"].concat(o);return c.forEach(function(c){return a.attachEvent(c,b)}),b(),function(){return c.forEach(function(c){return a.detachEvent(c,b)})}},[a]),f},a.useData=function(a){function b(){g(a.getData())}var d=m([]),e=c(d,2),f=e[0],g=e[1];return n(function(){return o.forEach(function(c){return a.attachEvent(c,b)}),b(),function(){return o.forEach(function(c){return a.detachEvent(c,b)})}},[a]),f},a.useSingleRecord=function(a,b){return console.warn("DEPRECATED: useSingleRecord has been renamed to useRecord"),h(a,b)},a.useDataWithoutState=function(a,b){return console.warn("DEPRECATED: useDataWithoutState has been renamed to useRecord"),i(a,b)},a.useFetchData=i,a.useFetchRecord=h,a.getData=g,Object.defineProperty(a,"__esModule",{value:!0})});