UNPKG

devfty

Version:

Devfty is a library for developer building low code factory

2 lines (1 loc) 18.1 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).devfty={})}(this,function(t){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function p(t){return(p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t){t=function(t,e){if("object"!=p(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0===n)return("string"===e?String:Number)(t);if("object"!=p(n=n.call(t,e||"default")))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==p(t)?t:t+""}function u(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,o(r.key),r)}}function i(t,e,n){return e&&u(t.prototype,e),n&&u(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(t,e){return(n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&n(t,e)}function c(t,e){if(e&&("object"==p(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");e=t;if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function F(t,e){if(null==t)return{};var n,r=function(t,e){if(null==t)return{};var n,r={};for(n in t)if({}.hasOwnProperty.call(t,n)){if(-1!==e.indexOf(n))continue;r[n]=t[n]}return r}(t,e);if(Object.getOwnPropertySymbols)for(var o=Object.getOwnPropertySymbols(t),u=0;u<o.length;u++)n=o[u],-1===e.indexOf(n)&&{}.propertyIsEnumerable.call(t,n)&&(r[n]=t[n]);return r}function l(t,e,n){(e=o(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n}var G=function(){function t(){r(this,t),l(this,"cache",{})}return i(t,[{key:"setCache",value:function(t,e){this.cache[t]=e}},{key:"getCache",value:function(t){var e;return null==(e=this.cache)?void 0:e[t]}},{key:"clearCache",value:function(t){delete this.cache[t]}}]),t}(),V=function(){function t(){r(this,t),l(this,"events",new Map)}return i(t,[{key:"on",value:function(t,e){var n=null==(n=this.events)?void 0:n.get(t);(n=Array.isArray(n)?n:[]).push(e),null!=(e=this.events)&&e.set(t,n)}},{key:"execute",value:function(t){for(var e=arguments.length,n=new Array(1<e?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];var o=null==(o=this.events)?void 0:o.get(t);Array.isArray(o)&&o.forEach(function(t){"function"==typeof t&&t.apply(void 0,n)})}},{key:"un",value:function(t,e){var n,r=null==(r=this.events)?void 0:r.get(t);Array.isArray(r)&&(r=r.filter(function(t){return t!==e}),null!=(n=this.events))&&n.set(t,r)}},{key:"clearEvents",value:function(){var t;null!=(t=this.events)&&t.clear()}}]),t}();function f(n){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}();return function(){var t,e=s(n);return c(this,r?(t=s(this).constructor,Reflect.construct(e,arguments,t)):e.apply(this,arguments))}}var y=function(){function n(t){r(this,n),l(this,"_data",{}),Object.assign(this._data,t);var t=new G,e=new V;this._set_data("events",e),this._set_data("cache",t),this._set_data("controls",[])}return i(n,[{key:"_del_data",value:function(t){t&&delete this._data[t]}},{key:"_cls_data",value:function(){this._data=null}},{key:"_set_data",value:function(t,e){this._data[t]=e}},{key:"_get_data",value:function(t){return this._data[t]}},{key:"getState",value:function(t){var e,n=this._get_data("controls")||[];return 0<(null===n?void 0:n.length)?(e=null==(n=n[0])||null==(e=n.getState)?void 0:e.call(n,t),this._set_data("value",e),e):this._get_data(t)}},{key:"setState",value:function(t,e){var n=this._get_data("controls")||[];0<(null===n?void 0:n.length)&&null!=(n=n[0])&&n.setState(t,e),this._set_data(t,e)}},{key:"get",value:function(t){return this._data[t]}},{key:"bindControl",value:function(t){this._set_data("controls",[t])}},{key:"unbindControl",value:function(t){this._set_data("controls",[])}},{key:"getVisible",value:function(){return this.getState("visible")}},{key:"setVisible",value:function(t){return this.setState("visible",!!t)}},{key:"getValue",value:function(){return this.getState("value")}},{key:"setValue",value:function(t){return this.setState("value",!!t)}},{key:"on",value:function(t,e){var n;null!=(n=this._get_data("events"))&&n.on(t,e)}},{key:"execute",value:function(t){for(var e,n=arguments.length,r=new Array(1<n?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];null!=(e=this._get_data("events"))&&e.execute.apply(e,[t].concat(r))}},{key:"un",value:function(t,e){var n;null!=(n=this._get_data("events"))&&n.un(t,e)}},{key:"setCache",value:function(t,e){var n;null!=(n=this._get_data("cache"))&&n.setCache(t,e)}},{key:"getCache",value:function(t){var e;return null==(e=this._get_data("cache"))?void 0:e.getCache(t)}},{key:"clearCache",value:function(t){var e;null!=(e=this._get_data("cache"))&&e.clearCache(t)}}]),n}(),J={FilterModel:function(){a(e,y);var t=f(e);function e(){return r(this,e),t.apply(this,arguments)}return i(e,[{key:"mounted",value:function(){var e=this,t=this.get("conditions"),n={};t.forEach(function(t){e.get(t.name),n[t.name]=t.defaultValue}),this._set_data("params",n)}},{key:"unmounted",value:function(){this._set_data("params",{}),this._set_data("conditions",[])}},{key:"getParams",value:function(){var n=this,r={};return this.get("conditions").forEach(function(t){var e=n.get(t.name);r[t.name]=null==e?void 0:e.getValue()}),this._set_data("params",r),r}},{key:"search",value:function(){var t=this.getParams();this.execute("search",t)}}]),e}(),SimpleModel:function(){a(n,y);var e=f(n);function n(t){return r(this,n),e.call(this,t)}return i(n,[{key:"getDisabled",value:function(){return this.getState("disabled")}},{key:"setDisabled",value:function(t){return this.setState("disabled",!!t)}},{key:"getReadonly",value:function(){return this.getState("readonly")}},{key:"setReadonly",value:function(t){this.setState("readonly",!!t)}}]),n}(),ViewModel:function(){a(e,y);var t=f(e);function e(){return r(this,e),t.apply(this,arguments)}return i(e)}()},q=["component","children","render"];function B(n){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}();return function(){var t,e=s(n);return c(this,r?(t=s(this).constructor,Reflect.construct(e,arguments,t)):e.apply(this,arguments))}}var H=!1,d={},v=null;function I(t){var u;if(Array.isArray(t))return u=[],t.forEach(function(t,e){var n,r,o;t.component&&(o=t.component,n=t.children,r=t.render,t=F(t,q),o={component:d[o],children:I(n)},t.index=e,"function"==typeof r?u.push(r({node:o,props:t})):"function"==typeof v?u.push(v({node:o,props:t})):(Object.assign(o,t),u.push(o)))}),u}var L=function(){a(e,y);var t=B(e);function e(){return r(this,e),t.apply(this,arguments)}return i(e,[{key:"init",value:function(t){H||("function"==typeof t&&t(),H=!0)}},{key:"initComponent",value:function(t,e){if(t)"string"==typeof t?d[t]?d[t]=e:console.log("[warning] Component ".concat(t," is exist!")):Object.assign(d,t)}},{key:"initRenderFactory",value:function(t){v=t}},{key:"initRequest",value:function(){}},{key:"render",value:I}]),e}();function U(t,e,n,r,o,u,i){try{var a=t[u](i),c=a.value}catch(t){return n(t)}a.done?e(c):Promise.resolve(c).then(r,o)}function h(a){return function(){var t=this,i=arguments;return new Promise(function(e,n){var r=a.apply(t,i);function o(t){U(r,e,n,o,u,"next",t)}function u(t){U(r,e,n,o,u,"throw",t)}o(void 0)})}}var x,b,m,X={exports:{}},e={exports:{}},_=((_=e).exports=function(t,e){this.v=t,this.k=e},_.exports.__esModule=!0,_.exports.default=_.exports,{exports:{}}),g={exports:{}};function w(t,e,n,r){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}x.exports=w=function(t,e,n,r){e?o?o(t,e,{value:n,enumerable:!r,configurable:!r,writable:!r}):t[e]=n:((r=function(e,n){w(t,e,function(t){return this._invoke(e,n,t)})})("next",0),r("throw",1),r("return",2))},x.exports.__esModule=!0,x.exports.default=x.exports,w(t,e,n,r)}function Y(){var d,t="function"==typeof Symbol?Symbol:{},e=t.iterator||"@@iterator",n=t.toStringTag||"@@toStringTag";function r(t,e,n,r){var o,u,i,a,c,s,l,f,p,e=e&&e.prototype instanceof h?e:h,e=Object.create(e.prototype);return m(e,"_invoke",(o=t,u=n,l=r||[],f=!1,p={p:s=0,n:0,v:d,a:y,f:y.bind(d,4),d:function(t,e){return i=t,a=0,c=d,p.n=e,v}},function(t,e,n){if(1<s)throw TypeError("Generator is already running");for(f&&1===e&&y(e,n),a=e,c=n;(x=a<2?d:c)||!f;){i||(a?a<3?(1<a&&(p.n=-1),y(a,c)):p.n=c:p.v=c);try{if(s=2,i){if(x=i[t=a?t:"next"]){if(!(x=x.call(i,c)))throw TypeError("iterator result is not an object");if(!x.done)return x;c=x.value,a<2&&(a=0)}else 1===a&&(x=i.return)&&x.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+t+"' method"),a=1);i=d}else if((x=(f=p.n<0)?c:o.call(u,p))!==v)break}catch(t){i=d,a=1,c=t}finally{s=1}}return{value:x,done:f}}),!0),e;function y(t,e){for(a=t,c=e,x=0;!f&&s&&!n&&x<l.length;x++){var n,r=l[x],o=p.p,u=r[2];3<t?(n=u===e)&&(c=r[(a=r[4])?5:a=3],r[4]=r[5]=d):r[0]<=o&&((n=t<2&&o<r[1])?(a=0,p.v=e,p.n=r[1]):o<u&&(n=t<3||r[0]>e||u<e)&&(r[4]=t,r[5]=e,p.n=u,a=0))}if(n||1<t)return v;throw f=!0,e}}var v={};function h(){}function o(){}function u(){}var x=Object.getPrototypeOf,t=[][e]?x(x([][e]())):(m(x={},e,function(){return this}),x),i=u.prototype=h.prototype=Object.create(t);function a(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,u):(t.__proto__=u,m(t,n,"GeneratorFunction")),t.prototype=Object.create(i),t}return m(i,"constructor",o.prototype=u),m(u,"constructor",o),m(u,n,o.displayName="GeneratorFunction"),m(i),m(i,n,"Generator"),m(i,e,function(){return this}),m(i,"toString",function(){return"[object Generator]"}),b.exports=function(){return{w:r,m:a}},b.exports.__esModule=!0,(b.exports.default=b.exports)()}(x=g).exports=w,x.exports.__esModule=!0,x.exports.default=x.exports,b=_,m=g.exports,b.exports=Y,b.exports.__esModule=!0,b.exports.default=b.exports;var z,O,K,Q,W,k,Z,S,$,tt,et,nt,rt,ot,j,ut={exports:{}},P={exports:{}},T={exports:{}},g=(z=e.exports,O=g.exports,(g=T).exports=function t(a,c){var o;this.next||(O(t.prototype),O(t.prototype,"function"==typeof Symbol&&Symbol.asyncIterator||"@asyncIterator",function(){return this})),O(this,"_invoke",function(n,t,r){function e(){return new c(function(t,e){!function e(t,n,r,o){try{var u=a[t](n),i=u.value;return i instanceof z?c.resolve(i.v).then(function(t){e("next",t,r,o)},function(t){e("throw",t,r,o)}):c.resolve(i).then(function(t){u.value=t,r(u)},function(t){return e("throw",t,r,o)})}catch(t){o(t)}}(n,r,t,e)})}return o=o?o.then(e,e):e()},!0)},g.exports.__esModule=!0,g.exports.default=g.exports,K=_.exports,Q=T.exports,(g=P).exports=function(t,e,n,r,o){return new Q(K().w(t,e,n,r),o||Promise)},g.exports.__esModule=!0,g.exports.default=g.exports,W=P.exports,(g=ut).exports=function(t,e,n,r,o){var u=W(t,e,n,r,o);return u.next().then(function(t){return t.done?t.value:u.next()})},g.exports.__esModule=!0,g.exports.default=g.exports,{exports:{}}),R=((R=g).exports=function(t){var e,n=Object(t),r=[];for(e in n)r.unshift(e);return function t(){for(;r.length;)if((e=r.pop())in n)return t.value=e,t.done=!1,t;return t.done=!0,t}},R.exports.__esModule=!0,R.exports.default=R.exports,{exports:{}}),M={exports:{}};function C(t){return k.exports=C="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},k.exports.__esModule=!0,k.exports.default=k.exports,C(t)}function E(){var o=tt(),t=o.m(E),e=(Object.getPrototypeOf?Object.getPrototypeOf(t):t.__proto__).constructor;function u(t){t="function"==typeof t&&t.constructor;return!!t&&(t===e||"GeneratorFunction"===(t.displayName||t.name))}var n={throw:1,return:2,break:3,continue:3};function i(t){var o,u;return function(r){o||(o={stop:function(){return u(r.a,2)},catch:function(){return r.v},abrupt:function(t,e){return u(r.a,n[t],e)},delegateYield:function(t,e,n){return o.resultName=e,u(r.d,j(t),n)},finish:function(t){return u(r.f,t)}},u=function(t,e,n){r.p=o.prev,r.n=o.next;try{return t(e,n)}finally{o.next=r.n}}),o.resultName&&(o[o.resultName]=r.v,o.resultName=void 0),o.sent=r.v,o.next=r.n;try{return t.call(this,o)}finally{r.p=o.prev,r.n=o.next}}}return S.exports=E=function(){return{wrap:function(t,e,n,r){return o.w(i(t),e,n,r&&r.reverse())},isGeneratorFunction:u,mark:o.m,awrap:function(t,e){return new $(t,e)},AsyncIterator:rt,async:function(t,e,n,r,o){return(u(e)?nt:et)(i(t),e,n,r,o)},keys:ot,values:j}},S.exports.__esModule=!0,(S.exports.default=S.exports)()}(k=M).exports=C,k.exports.__esModule=!0,k.exports.default=k.exports,D=R,Z=M.exports.default,D.exports=function(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return{value:(t=t&&n>=t.length?void 0:t)&&t[n++],done:!t}}}}throw new TypeError(Z(t)+" is not iterable")},D.exports.__esModule=!0,D.exports.default=D.exports,S=X,$=e.exports,tt=_.exports,et=ut.exports,nt=P.exports,rt=T.exports,ot=g.exports,j=R.exports,S.exports=E,S.exports.__esModule=!0,S.exports.default=S.exports;var M=X.exports(),N=M;try{regeneratorRuntime=M}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=M:Function("r","regeneratorRuntime = r")(M)}function it(e,t){var n,r=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)),r}function A(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?it(Object(n),!0).forEach(function(t){l(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):it(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function at(e){return new Promise(function(n,t){!function o(u){var i=new XMLHttpRequest,t=(void 0===u.times&&(u.times=3),u.id=u.id||+new Date,u.url),e="object"===p(u.param)?JSON.stringify(u.param):u.param||"";if(u.noNeedDpm||(t+="?d=".concat(u.id)),u.urlParams)for(var n=0;n<u.urlParams.length;n++){var r=u.urlParams[n];t+="&".concat(r.key,"=").concat(r.value)}console.info("http[".concat(u.id,"] :: url = ").concat(t,", postData=").concat(e));var e=u.param,a=(u.method||"GET").toUpperCase(),c=u.timeout||5e3,s=u.type||"text",l=u.callback,f=!1;i.onreadystatechange=function(){if(console.info("http[".concat(u.id,"] :: readyState = ").concat(i.readyState)),!f&&4===i.readyState){console.info("http[".concat(u.id,"] :: header = ").concat(i.getAllResponseHeaders())),console.info("http[".concat(u.id,"] :: status = ").concat(i.status)),404!==i.status&&console.info("http[".concat(u.id,"] :: responseText = ").concat(i.responseText)),f=!0;var e,n=null,r=(200!==i.status&&(n={code:i.status,text:i.statusText,toString:function(){return"".concat(this.code,": ").concat(this.text)}}),i.responseText);if("json"===s.toLowerCase())try{r=JSON.parse(r)}catch(t){n={code:555,text:"json parse error",toString:function(){return"".concat(this.code,": ").concat(this.text)}},r=null}if(n&&0<u.times)u.times=u.times-1,o(u);else{try{e=JSON.parse(r)}catch(t){console.info("callback parse error! err:".concat(JSON.stringify(t))),e=r}l(e,n,i,u)}}},i.open(a,t,!0),"POST"===a?(i.setRequestHeader("Access-Control-Allow-Origin","*"),i.setRequestHeader("Content-type","application/json"),"string"!=typeof e&&(e=JSON.stringify(e))):e=null,i.send(e),setTimeout(function(){var t;f||(f=!0,i.abort(),0<u.times?(u.times=u.times-1,o(u)):(t={code:-1001,text:"Timeout",toString:function(){return"".concat(this.code,": ").concat(this.text)}},console.info("http[".concat(u.id,"] :: error").concat(JSON.stringify(t))),l(null,t,i,u)))},c)}(A(A({},e),{},{callback:function(t,e){n(t,e)}}))})}var ct={get:function(t,e,n){var o=A({url:t,method:"get",params:e||{}},n);return new Promise(function(){var n=h(N.mark(function t(e,n){var r;return N.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,at(o);case 2:r=t.sent,e((null==r?void 0:r.data)||r);case 4:case"end":return t.stop()}},t)}));return function(t,e){return n.apply(this,arguments)}}())},getText:function(t,e,n){var o=A({url:t,method:"get",params:e||{}},n);return new Promise(function(){var n=h(N.mark(function t(e,n){var r;return N.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,at(o);case 2:r=t.sent,e(r);case 4:case"end":return t.stop()}},t)}));return function(t,e){return n.apply(this,arguments)}}())},post:function(t,e,n){var o=A({url:t,method:"post",data:parseToFormData(e||{})},n);return new Promise(function(){var n=h(N.mark(function t(e,n){var r;return N.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,ct(o);case 2:r=t.sent,e(null==r?void 0:r.data);case 4:case"end":return t.stop()}},t)}));return function(t,e){return n.apply(this,arguments)}}())}},D={builder:new L,utils:{cache:new G,event:new V,models:J,request:ct}};t.default=D,Object.defineProperty(t,"__esModule",{value:!0})});