@ibiz-template/core 0.0.1-alpha.6 → 0.0.1-beta.17

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.
Files changed (165) hide show
  1. package/dist/system/index.system.js +1 -0
  2. package/out/command/command-register.d.ts +66 -0
  3. package/out/command/command-register.d.ts.map +1 -0
  4. package/out/command/command-register.js +113 -0
  5. package/out/command/command.d.ts +54 -0
  6. package/out/command/command.d.ts.map +1 -0
  7. package/out/command/command.js +71 -0
  8. package/out/command/index.d.ts +10 -0
  9. package/out/command/index.d.ts.map +1 -0
  10. package/out/command/index.js +9 -0
  11. package/out/command/interface/command/command-option.d.ts +23 -0
  12. package/out/command/interface/command/command-option.d.ts.map +1 -0
  13. package/out/command/interface/command/command-option.js +1 -0
  14. package/out/command/interface/command/command.d.ts +74 -0
  15. package/out/command/interface/command/command.d.ts.map +1 -0
  16. package/out/command/interface/command/command.js +1 -0
  17. package/out/command/interface/disposable/disposable.d.ts +4 -0
  18. package/out/command/interface/disposable/disposable.d.ts.map +1 -0
  19. package/out/command/interface/disposable/disposable.js +1 -0
  20. package/out/command/interface/index.d.ts +4 -0
  21. package/out/command/interface/index.d.ts.map +1 -0
  22. package/out/command/interface/index.js +1 -0
  23. package/out/command/utils/index.d.ts +3 -0
  24. package/out/command/utils/index.d.ts.map +1 -0
  25. package/out/command/utils/index.js +2 -0
  26. package/out/command/utils/linked-list.d.ts +16 -0
  27. package/out/command/utils/linked-list.d.ts.map +1 -0
  28. package/out/command/utils/linked-list.js +120 -0
  29. package/out/command/utils/util.d.ts +27 -0
  30. package/out/command/utils/util.d.ts.map +1 -0
  31. package/out/command/utils/util.js +77 -0
  32. package/out/constant/index.d.ts +3 -0
  33. package/out/constant/index.d.ts.map +1 -1
  34. package/out/constant/index.js +3 -0
  35. package/out/constant/login-mode/login-mode.d.ts +23 -0
  36. package/out/constant/login-mode/login-mode.d.ts.map +1 -0
  37. package/out/constant/login-mode/login-mode.js +24 -0
  38. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts +23 -0
  39. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts.map +1 -0
  40. package/out/constant/menu-permission-mode/menu-permission-mode.js +24 -0
  41. package/out/constant/util/util.d.ts +5 -0
  42. package/out/constant/util/util.d.ts.map +1 -0
  43. package/out/constant/util/util.js +5 -0
  44. package/out/context/index.d.ts +19 -32
  45. package/out/context/index.d.ts.map +1 -1
  46. package/out/context/index.js +52 -60
  47. package/out/environment/environment.d.ts.map +1 -1
  48. package/out/environment/environment.js +11 -2
  49. package/out/error/http-error/http-error.d.ts.map +1 -1
  50. package/out/error/http-error/http-error.js +0 -4
  51. package/out/factory-center.d.ts +11 -0
  52. package/out/factory-center.d.ts.map +1 -0
  53. package/out/factory-center.js +10 -0
  54. package/out/ibizsys.d.ts +17 -1
  55. package/out/ibizsys.d.ts.map +1 -1
  56. package/out/ibizsys.js +17 -1
  57. package/out/index.d.ts +3 -1
  58. package/out/index.d.ts.map +1 -1
  59. package/out/index.js +3 -1
  60. package/out/install.d.ts.map +1 -1
  61. package/out/install.js +4 -2
  62. package/out/interface/click-outside/click-outside.d.ts +70 -0
  63. package/out/interface/click-outside/click-outside.d.ts.map +1 -0
  64. package/out/interface/click-outside/click-outside.js +1 -0
  65. package/out/interface/i-environment/i-environment.d.ts +72 -4
  66. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  67. package/out/interface/index.d.ts +1 -0
  68. package/out/interface/index.d.ts.map +1 -1
  69. package/out/interface/index.js +1 -1
  70. package/out/types.d.ts +10 -0
  71. package/out/types.d.ts.map +1 -1
  72. package/out/utils/click-outside/click-outside.d.ts +14 -0
  73. package/out/utils/click-outside/click-outside.d.ts.map +1 -0
  74. package/out/utils/click-outside/click-outside.js +85 -0
  75. package/out/utils/color/color.d.ts +13 -0
  76. package/out/utils/color/color.d.ts.map +1 -0
  77. package/out/utils/color/color.js +76 -0
  78. package/out/utils/download-file/download-file.d.ts +31 -0
  79. package/out/utils/download-file/download-file.d.ts.map +1 -0
  80. package/out/utils/download-file/download-file.js +107 -0
  81. package/out/utils/event/event.d.ts +34 -0
  82. package/out/utils/event/event.d.ts.map +1 -0
  83. package/out/utils/event/event.js +60 -0
  84. package/out/utils/index.d.ts +10 -1
  85. package/out/utils/index.d.ts.map +1 -1
  86. package/out/utils/index.js +10 -1
  87. package/out/utils/interceptor/core-interceptor.d.ts +15 -0
  88. package/out/utils/interceptor/core-interceptor.d.ts.map +1 -0
  89. package/out/utils/interceptor/core-interceptor.js +30 -0
  90. package/out/utils/interceptor/index.d.ts +3 -0
  91. package/out/utils/interceptor/index.d.ts.map +1 -0
  92. package/out/utils/interceptor/index.js +2 -0
  93. package/out/utils/interceptor/interceptor.d.ts +74 -3
  94. package/out/utils/interceptor/interceptor.d.ts.map +1 -1
  95. package/out/utils/interceptor/interceptor.js +73 -22
  96. package/out/utils/logger/logger.d.ts +3 -0
  97. package/out/utils/logger/logger.d.ts.map +1 -0
  98. package/out/utils/logger/logger.js +2 -0
  99. package/out/utils/net/http-response.d.ts +4 -9
  100. package/out/utils/net/http-response.d.ts.map +1 -1
  101. package/out/utils/net/http-response.js +0 -7
  102. package/out/utils/net/net.d.ts +82 -31
  103. package/out/utils/net/net.d.ts.map +1 -1
  104. package/out/utils/net/net.js +109 -40
  105. package/out/utils/sync/count-latch.d.ts +60 -0
  106. package/out/utils/sync/count-latch.d.ts.map +1 -0
  107. package/out/utils/sync/count-latch.js +93 -0
  108. package/out/utils/sync/index.d.ts +2 -0
  109. package/out/utils/sync/index.d.ts.map +1 -0
  110. package/out/utils/sync/index.js +1 -0
  111. package/out/utils/upload/select-file.d.ts +53 -0
  112. package/out/utils/upload/select-file.d.ts.map +1 -0
  113. package/out/utils/upload/select-file.js +47 -0
  114. package/out/utils/upload/upload-file.d.ts +46 -0
  115. package/out/utils/upload/upload-file.d.ts.map +1 -0
  116. package/out/utils/upload/upload-file.js +150 -0
  117. package/out/utils/url-helper/url-helper.d.ts +51 -0
  118. package/out/utils/url-helper/url-helper.d.ts.map +1 -0
  119. package/out/utils/url-helper/url-helper.js +59 -0
  120. package/out/utils/util/util.d.ts +20 -4
  121. package/out/utils/util/util.d.ts.map +1 -1
  122. package/out/utils/util/util.js +59 -5
  123. package/package.json +19 -9
  124. package/src/command/command-register.ts +135 -0
  125. package/src/command/command.ts +79 -0
  126. package/src/command/index.ts +11 -0
  127. package/src/command/interface/command/command-option.ts +22 -0
  128. package/src/command/interface/command/command.ts +86 -0
  129. package/src/command/interface/disposable/disposable.ts +3 -0
  130. package/src/command/interface/index.ts +9 -0
  131. package/src/command/utils/index.ts +2 -0
  132. package/src/command/utils/linked-list.ts +136 -0
  133. package/src/command/utils/util.ts +95 -0
  134. package/src/constant/index.ts +3 -0
  135. package/src/constant/login-mode/login-mode.ts +23 -0
  136. package/src/constant/menu-permission-mode/menu-permission-mode.ts +23 -0
  137. package/src/constant/util/util.ts +5 -0
  138. package/src/context/index.ts +69 -59
  139. package/src/environment/environment.ts +11 -2
  140. package/src/error/http-error/http-error.ts +0 -4
  141. package/src/factory-center.ts +9 -0
  142. package/src/ibizsys.ts +19 -1
  143. package/src/index.ts +3 -1
  144. package/src/install.ts +4 -2
  145. package/src/interface/click-outside/click-outside.ts +71 -0
  146. package/src/interface/i-environment/i-environment.ts +81 -4
  147. package/src/interface/index.ts +1 -0
  148. package/src/types.ts +10 -0
  149. package/src/utils/click-outside/click-outside.ts +110 -0
  150. package/src/utils/color/color.ts +84 -0
  151. package/src/utils/download-file/download-file.ts +109 -0
  152. package/src/utils/event/event.ts +77 -0
  153. package/src/utils/index.ts +10 -1
  154. package/src/utils/interceptor/core-interceptor.ts +35 -0
  155. package/src/utils/interceptor/index.ts +2 -0
  156. package/src/utils/interceptor/interceptor.ts +109 -22
  157. package/src/utils/logger/logger.ts +3 -0
  158. package/src/utils/net/http-response.ts +6 -9
  159. package/src/utils/net/net.ts +144 -51
  160. package/src/utils/sync/count-latch.ts +99 -0
  161. package/src/utils/sync/index.ts +1 -0
  162. package/src/utils/upload/select-file.ts +86 -0
  163. package/src/utils/upload/upload-file.ts +206 -0
  164. package/src/utils/url-helper/url-helper.ts +62 -0
  165. package/src/utils/util/util.ts +72 -14
@@ -0,0 +1 @@
1
+ System.register(["lodash-es","qx-util","axios","qs","pluralize"],(function(t){"use strict";var e,n,r,o,i,s,a,c,u,l,f;return{setters:[function(t){e=t.debounce,n=t.merge,r=t.uniqueId,o=t.isFunction,i=t.round,s=t.cloneDeep},function(t){a=t.getCookie,c=t.notNilEmpty},function(t){u=t.default},function(t){l=t.stringify},function(t){f=t.default}],execute:function(){function p(t,e){return e.forEach((function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach((function(n){if("default"!==n&&!(n in t)){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}))})),Object.freeze(t)}t({calcMimeByFileName:K,colorBlend:function(t,e,n,r){void 0===n&&(n=.5);void 0===r&&(r="hex");t=t.trim(),e=e.trim();var o=J(t),i=J(e),s=[X((1-n)*o[0]+n*i[0]),X((1-n)*o[1]+n*i[1]),X((1-n)*o[2]+n*i[2]),(1-n)*o[3]+n*i[3]];if("hex"===r){var a=[s[0].toString(16),s[1].toString(16),s[2].toString(16),0===s[3]?"00":X(255*s[3]).toString(16)];return"#".concat(a[0]).concat(a[1]).concat(a[2]).concat(a[3])}return"rgb(".concat(s[0]," ").concat(s[1]," ").concat(s[2]," / ").concat(s[3],")")},debounce:function(t,e,n){var r;return function(){for(var o=this,i=[],s=0;s<arguments.length;s++)i[s]=arguments[s];if(r&&clearTimeout(r),n){var a=!r;r=setTimeout((function(){r=null}),e),a&&t.apply(this,i)}else r=setTimeout((function(){t.apply(o,i)}),e)}},debounceAndAsyncMerge:function(t,n,r){var o,i=this,s=[],a=e((function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return h(i,void 0,void 0,(function(){var n,r;return v(this,(function(i){switch(i.label){case 0:o=void 0,i.label=1;case 1:return i.trys.push([1,3,,4]),[4,t.apply(void 0,y([],m(e),!1))];case 2:return n=i.sent(),s.forEach((function(t){t.resolve(n)})),s=[],[2,n];case 3:return r=i.sent(),s.forEach((function(t){t.reject(r)})),s=[],[3,4];case 4:return[2]}}))}))}),r);return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return h(i,void 0,void 0,(function(){var e;return v(this,(function(r){return e=t,o&&(e=n(o,e)),o=e,a.apply(void 0,y([],m(e),!1)),[2,new Promise((function(t,e){s.push({resolve:t,reject:e})}))]}))}))}},debounceAndMerge:function(t,n,r){var o,i=e((function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return o=void 0,t.apply(void 0,y([],m(e),!1))}),r);return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=t;return o&&(r=n(o,r)),o=r,i.apply(void 0,y([],m(r),!1))}},downloadFileFromBlob:function(t,e){var n=K(e),r=new Blob([t],{type:n}),o=URL.createObjectURL(r),i=document.createElement("a");i.href=o,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(o)},eventPath:V,fileListToArr:Y,getToken:j,install:function(){if(window.ibiz)throw new Error("ibiz 已经存在, 无需重复安装");window.ibiz=new Q,window.___fc=new Z,ibiz.net.addInterceptor("CoreInterceptor",new z)},isEventInside:H,isImage:function(t){var e=t.split(".").pop();if(!e)return!1;return[".jpeg","jpg","gif","png","bmp","svg"].includes(e)},isOverlap:function(t,e){return Array.from(new Set(y(y([],m(t),!1),m(e),!1))).length!==t.length+e.length},listenJSEvent:W,onClickOutside:function(t,e,n){void 0===n&&(n={});var r=n.window,o=void 0===r?G:r,i=n.ignore,s=void 0===i?[]:i,a=n.capture,c=void 0===a||a;if(!t)throw new T("target元素不存在");if(!o)throw new T("找不到window");var u,l=!0,f=function(e){return!y([t],m(s),!1).some((function(t){return H(e,t)}))},p=!1,d=function(t){p||(o.clearTimeout(u),l&&f(t)&&e(t))},h=[W(o,"click",d,{passive:!0,capture:c}),W(o,"pointerdown",(function(t){p||(l=f(t))}),{passive:!0}),W(o,"pointerup",(function(t){if(!p&&0===t.button){var e=V(t);t.composedPath=function(){return e},u=o.setTimeout((function(){return d(t)}),50)}}),{passive:!0})].filter(Boolean);return{stop:function(){return h.forEach((function(t){return t()}))},pause:function(){p=!0},proceed:function(){p=!1}}},plural:D,pluralLower:function(t){return D(t).toLowerCase()},selectFile:$,throttle:function(t,e){var n=null;return function(){for(var r=this,o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n||(n=setTimeout((function(){t.apply(r,o),n=null}),e))}},toDisposable:_,uploadFile:function(t){var e=this,a=n({multiple:!0,accept:"",separate:!0,beforeUpload:function(t,e){return!0},finish:function(t){},success:function(t,e){},error:function(t,e){},progress:function(t){}},t),c=function(t,n){return h(e,void 0,void 0,(function(){var e;return v(this,(function(r){switch(r.label){case 0:return a.request&&o(a.request)?[2,a.request(t)]:(e=new FormData,t.forEach((function(t){e.append("file",t)})),[4,ibiz.net.request(a.uploadUrl,{method:"post",baseURL:"",data:e,headers:{"Content-Type":"multipart/form-data"},onUploadProgress:n})]);case 1:return[2,r.sent()]}}))}))},u=function(t){return h(e,void 0,void 0,(function(){var e,n,o;return v(this,(function(u){switch(u.label){case 0:if(e=t.map((function(t){return{status:"uploading",name:t.name,uid:r(),percentage:0}})),!a.beforeUpload(t,e))return e.forEach((function(t){t.status="cancel"})),ibiz.log.debug("取消上传",e),[2,e];u.label=1;case 1:return u.trys.push([1,3,,4]),[4,c(t,(function(t){!function(t,e){e.forEach((function(e){e.percentage=i(100*t.progress)})),a.progress(s(e))}(t,e)}))];case 2:return n=u.sent(),e.forEach((function(t){t.status="finished"})),a.success(e,n),e.forEach((function(t){t.response=n})),[3,4];case 3:return o=u.sent(),e.forEach((function(t){t.status="fail"})),a.error(e,o),e.forEach((function(t){t.error=o})),ibiz.log.error(o),ibiz.log.error("".concat(t.map((function(t){return t.name})).join(","),"上传失败")),[3,4];case 4:return[2,e]}}))}))};$({accept:a.accept,multiple:a.multiple,onSelected:function(t){!function(t){h(e,void 0,void 0,(function(){var e,n,r,o=this;return v(this,(function(i){switch(i.label){case 0:return e=a.separate?t.map((function(t){return[t]})):[t],[4,Promise.allSettled(e.map((function(t){return h(o,void 0,void 0,(function(){return v(this,(function(e){return[2,u(t)]}))}))})))];case 1:return n=i.sent(),r=[],n.forEach((function(t){"fulfilled"===t.status&&r.push.apply(r,y([],m(t.value),!1))})),a.finish(r),[2]}}))}))}(t)}})}});var d=function(t,e){return d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},d(t,e)};function h(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function a(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))}function v(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function m(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function y(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}var g=function(){function t(e){this.element=e,this.next=t.Undefined,this.prev=t.Undefined}return t.Undefined=new t(void 0),t}(),b=t("LinkedList",function(){function t(){this._first=g.Undefined,this._last=g.Undefined,this._size=0}return Object.defineProperty(t.prototype,"size",{get:function(){return this._size},enumerable:!1,configurable:!0}),t.prototype.isEmpty=function(){return this._first===g.Undefined},t.prototype.clear=function(){for(var t=this._first;t!==g.Undefined;){var e=t.next;t.prev=g.Undefined,t.next=g.Undefined,t=e}this._first=g.Undefined,this._last=g.Undefined,this._size=0},t.prototype.unshift=function(t){return this._insert(t,!1)},t.prototype.push=function(t){return this._insert(t,!0)},t.prototype._insert=function(t,e){var n=this,r=new g(t);if(this._first===g.Undefined)this._first=r,this._last=r;else if(e){var o=this._last;this._last=r,r.prev=o,o.next=r}else{var i=this._first;this._first=r,r.next=i,i.prev=r}this._size+=1;var s=!1;return function(){s||(s=!0,n._remove(r))}},t.prototype.shift=function(){if(this._first!==g.Undefined){var t=this._first.element;return this._remove(this._first),t}},t.prototype.pop=function(){if(this._last!==g.Undefined){var t=this._last.element;return this._remove(this._last),t}},t.prototype._remove=function(t){if(t.prev!==g.Undefined&&t.next!==g.Undefined){var e=t.prev;e.next=t.next,t.next.prev=e}else t.prev===g.Undefined&&t.next===g.Undefined?(this._first=g.Undefined,this._last=g.Undefined):t.next===g.Undefined?(this._last=this._last.prev,this._last.next=g.Undefined):t.prev===g.Undefined&&(this._first=this._first.next,this._first.prev=g.Undefined);this._size-=1},t.prototype[Symbol.iterator]=function(){var t;return v(this,(function(e){switch(e.label){case 0:t=this._first,e.label=1;case 1:return t===g.Undefined?[3,3]:[4,t.element];case 2:return e.sent(),t=t.next,[3,1];case 3:return[2]}}))},t}());function w(t){var e,n=this,r=!1;return function(){return r?e:(r=!0,e=t.apply(n,arguments))}}function _(t){return{dispose:w((function(){t()}))}}var E,U,x=t("CommandsRegistry",function(){function t(){this.commands=new Map}return t.prototype.registerCommand=function(t,e,n){var r=this;if(!t)throw new Error("invalid command");if("string"==typeof t){if(!e)throw new Error("invalid command");return this.registerCommand({id:t,handler:e,opts:n})}var o=t.id,i=this.commands.get(o);i||(i=new b,this.commands.set(o,i));var s=i.unshift(t);return _((function(){s();var t=r.commands.get(o);(null==t?void 0:t.isEmpty())&&r.commands.delete(o)}))},t.prototype.hasCommand=function(t){return this.commands.has(t)},t.prototype.getCommand=function(t){var e=this.commands.get(t);if(e&&!e.isEmpty())return e[Symbol.iterator]().next().value},t.prototype.getCommands=function(){var t,e,n=new Map,r=this.commands.keys();try{for(var o=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(r),i=o.next();!i.done;i=o.next()){var s=i.value,a=this.getCommand(s);a&&n.set(s,a)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}return n},t.prototype.getCommandOpt=function(t){var e=this.getCommand(t);return null==e?void 0:e.opts},t}()),C=t("CommandController",function(){function t(){this.commandRegister=new x}return t.prototype.register=function(t,e,n){return this.commandRegister.registerCommand(t,e,n)},t.prototype.execute=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return h(this,void 0,void 0,(function(){var n;return v(this,(function(r){if(n=this.commandRegister.getCommand(t))return[2,n.handler.apply(n,y([],m(e),!1))];throw new Error("未注册指令: ".concat(t,",请先注册指令"))}))}))},t.prototype.hasCommand=function(t,e){var n=!!this.commandRegister.hasCommand(t);if(!0===e&&!0===n)throw new Error("未注册指令: ".concat(t,",请先注册指令"));return n},t.prototype.getCommandOpts=function(t){return this.commandRegister.getCommandOpt(t)},t}()),R=(t("commands",new C),t("CoreConst",function(){function t(){}return t.DEFAULT_MODEL_SERVICE_TAG="default",t.TOKEN="access_token",t}())),k=t("NOOP",(function(){}));t("HttpStatusMessageConst",{200:"服务器成功返回请求的数据。",201:"新建或修改数据成功。",202:"一个请求已经进入后台排队(异步任务)。",204:"删除数据成功。",400:"发出的请求有错误,服务器没有进行新建或修改数据的操作。",401:"用户没有权限(令牌、用户名、密码错误)。",403:"用户得到授权,但是访问是被禁止的。",404:"发出的请求针对的是不存在的记录,服务器没有进行操作。",406:"请求的格式不可得。",410:"请求的资源被永久删除,且不会再得到的。",422:"当创建一个对象时,发生一个验证错误。",500:"服务器发生错误,请检查服务器。",502:"网关错误。",503:"服务不可用,服务器暂时过载或维护。",504:"网关超时。"});t("LoginMode",E),function(t){t.DEFAULT="DEFAULT",t.CUSTOM="CUSTOM",t.CAS="CAS"}(E||t("LoginMode",E={})),t("MenuPermissionMode",U),function(t){t.MIXIN="MIXIN",t.RESOURCE="RESOURCE",t.RT="RT"}(U||t("MenuPermissionMode",U={}));t("IBizContext",function(){function t(t,e){if(void 0===t&&(t={}),e){var n=this;Object.defineProperty(this,"_parent",{enumerable:!1,value:e}),Object.defineProperty(this,"_context",{enumerable:!1,value:{}});var r={};Object.keys(e).forEach((function(t){r[t]={enumerable:!0,set:function(e){n._context[t]=null==e?null:e},get:function(){return void 0!==n._context[t]?n._context[t]:e[t]}}})),Object.defineProperties(this,r)}Object.assign(this,t)}return t.prototype.getOwnContext=function(){var t=this,e={};return Object.keys(this).forEach((function(n){Object.prototype.hasOwnProperty.call(t._parent,n)&&!Object.prototype.hasOwnProperty.call(t._context,n)||(e[n]=t[n])})),e},t}());var O=t("Environment",{dev:!1,logLevel:"ERROR",jsCdn:"https://cdn.jsdelivr.net",baseUrl:"",pluginBaseUrl:"./plugins",remoteModelUrl:"/remotemodel",assetsUrl:"./assets",dcSystem:"",downloadFileUrl:"/ibizutil/download",uploadFileUrl:"/ibizutil/upload",casLoginUrl:"",loginMode:E.DEFAULT,menuPermissionMode:U.MIXIN,enablePermission:!0}),P=t("HttpError",(function(t){this.name="HttpError";var e=t.response;this.response=t.response,e?(e.data?this.message=e.data.message:this.message=e.statusText,this.message||(this.message="网络异常,请稍后重试!"),this.status=e.status):(this.message=t.message,this.status=500)})),T=t("RuntimeError",(function(t){this.message=t,this.name="Runtime Error"}));function j(){return a(R.TOKEN)}var L,S,I,A=t("Interceptor",function(){function t(){}return t.prototype.onBeforeRequest=function(t){return h(this,void 0,void 0,(function(){return v(this,(function(e){return[2,t]}))}))},t.prototype.onRequestError=function(t){return Promise.reject(t)},t.prototype.onResponseSuccess=function(t){return h(this,void 0,void 0,(function(){return v(this,(function(e){return[2,t]}))}))},t.prototype.onResponseError=function(t){return Promise.reject(t)},t.prototype.use=function(t){this.requestTag=t.interceptors.request.use(this.onBeforeRequest,this.onRequestError),this.responseTag=t.interceptors.response.use(this.onResponseSuccess,this.onResponseError)},t.prototype.eject=function(t){this.requestTag&&t.interceptors.request.eject(this.requestTag),this.responseTag&&t.interceptors.response.eject(this.responseTag)},t}()),z=t("CoreInterceptor",function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}d(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(e,t),e.prototype.onBeforeRequest=function(e){return h(this,void 0,void 0,(function(){var n;return v(this,(function(r){switch(r.label){case 0:return[4,t.prototype.onBeforeRequest.call(this,e)];case 1:return r.sent(),e.headers||(e.headers={}),e.headers.Authorization="Bearer ".concat(j()),(n=ibiz.orgData)&&(n.systemid&&(e.headers.srfsystemid=n.systemid),n.orgid&&(e.headers.srforgid=n.orgid)),[2,e]}}))}))},e}(A)),M="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},q={};S=M,I=function(){var t=function(){},e="undefined",n=typeof window!==e&&typeof window.navigator!==e&&/Trident\/|MSIE /.test(window.navigator.userAgent),r=["trace","debug","info","warn","error"];function o(t,e){var n=t[e];if("function"==typeof n.bind)return n.bind(t);try{return Function.prototype.bind.call(n,t)}catch(e){return function(){return Function.prototype.apply.apply(n,[t,arguments])}}}function i(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function s(r){return"debug"===r&&(r="log"),typeof console!==e&&("trace"===r&&n?i:void 0!==console[r]?o(console,r):void 0!==console.log?o(console,"log"):t)}function a(e,n){for(var o=0;o<r.length;o++){var i=r[o];this[i]=o<e?t:this.methodFactory(i,e,n)}this.log=this.debug}function c(t,n,r){return function(){typeof console!==e&&(a.call(this,n,r),this[t].apply(this,arguments))}}function u(t,e,n){return s(t)||c.apply(this,arguments)}function l(t,n,o){var i,s=this;n=null==n?"WARN":n;var c="loglevel";function l(){var t;if(typeof window!==e&&c){try{t=window.localStorage[c]}catch(t){}if(typeof t===e)try{var n=window.document.cookie,r=n.indexOf(encodeURIComponent(c)+"=");-1!==r&&(t=/^([^;]+)/.exec(n.slice(r))[1])}catch(t){}return void 0===s.levels[t]&&(t=void 0),t}}"string"==typeof t?c+=":"+t:"symbol"==typeof t&&(c=void 0),s.name=t,s.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},s.methodFactory=o||u,s.getLevel=function(){return i},s.setLevel=function(n,o){if("string"==typeof n&&void 0!==s.levels[n.toUpperCase()]&&(n=s.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=s.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(i=n,!1!==o&&function(t){var n=(r[t]||"silent").toUpperCase();if(typeof window!==e&&c){try{return void(window.localStorage[c]=n)}catch(t){}try{window.document.cookie=encodeURIComponent(c)+"="+n+";"}catch(t){}}}(n),a.call(s,n,t),typeof console===e&&n<s.levels.SILENT)return"No console available for logging"},s.setDefaultLevel=function(t){n=t,l()||s.setLevel(t,!1)},s.resetLevel=function(){s.setLevel(n,!1),function(){if(typeof window!==e&&c){try{return void window.localStorage.removeItem(c)}catch(t){}try{window.document.cookie=encodeURIComponent(c)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(t){}}}()},s.enableAll=function(t){s.setLevel(s.levels.TRACE,t)},s.disableAll=function(t){s.setLevel(s.levels.SILENT,t)};var f=l();null==f&&(f=n),s.setLevel(f,!1)}var f=new l,p={};f.getLogger=function(t){if("symbol"!=typeof t&&"string"!=typeof t||""===t)throw new TypeError("You must supply a name when creating a logger.");var e=p[t];return e||(e=p[t]=new l(t,f.getLevel(),f.methodFactory)),e};var d=typeof window!==e?window.log:void 0;return f.noConflict=function(){return typeof window!==e&&window.log===f&&(window.log=d),f},f.getLoggers=function(){return p},f.default=f,f},(L={get exports(){return q},set exports(t){q=t}}).exports?L.exports=I():S.log=I();var F=p({__proto__:null,default:q},[q]);t("Logger",F);function N(t,e,n,r,o){var i="".concat(t,"-").concat(e);return n&&(i+="-".concat(n)),r&&(i+="__".concat(r)),o&&(i+="--".concat(o)),i}t("Namespace",function(){function t(t,e){this.block=t,this.namespace=e||"ibiz"}return t.prototype.b=function(t){return void 0===t&&(t=""),N(this.namespace,this.block,t,"","")},t.prototype.e=function(t){return t?N(this.namespace,this.block,"",t,""):""},t.prototype.m=function(t){return t?N(this.namespace,this.block,"","",t):""},t.prototype.be=function(t,e){return t&&e?N(this.namespace,this.block,t,e,""):""},t.prototype.em=function(t,e){return t&&e?N(this.namespace,this.block,"",t,e):""},t.prototype.bm=function(t,e){return t&&e?N(this.namespace,this.block,t,"",e):""},t.prototype.bem=function(t,e,n){return t&&e&&n?N(this.namespace,this.block,t,e,n):""},t.prototype.is=function(t,e){return t&&e?"".concat("is-").concat(t):""},t.prototype.cssVar=function(t){var e={};for(var n in t)t[n]&&(e[this.cssVarName(n)]=t[n]);return e},t.prototype.cssVarBlock=function(t){var e={};for(var n in t)t[n]&&(e[this.cssVarBlockName(n)]=t[n]);return e},t.prototype.cssVarName=function(t){return"--".concat(this.namespace,"-").concat(t)},t.prototype.cssVarBlockName=function(t){return"--".concat(this.namespace,"-").concat(this.block,"-").concat(t)},t}()),t("HttpResponse",(function(t,e,n){this.local=!0,this.ok=!1,this.headers={},this.config={},this.data=t,this.status=e||200,this.statusText=n||"",this.status>=200&&this.status<300&&(this.ok=!0)}));var B=t("Net",function(){function t(t){this.interceptors=new Map,this.instance=u.create(t)}return t.prototype.addInterceptor=function(t,e){e.use(this.instance),this.interceptors.set(t,e)},t.prototype.removeInterceptor=function(t){var e=this.interceptors.get(t);e&&(e.eject(this.instance),this.interceptors.delete(t))},Object.defineProperty(t.prototype,"presetConfig",{get:function(){return{baseURL:this.instance.defaults.baseURL||ibiz.env.baseUrl,headers:{"Content-Type":"application/json;charset=UTF-8",Accept:"application/json"}}},enumerable:!1,configurable:!0}),t.prototype.mergeConfig=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return 0===t.length?this.presetConfig:n.apply(void 0,y([this.presetConfig],m(t),!1))},t.prototype.post=function(t,e,n,r){return void 0===n&&(n={}),void 0===r&&(r={}),h(this,void 0,void 0,(function(){var o,i;return v(this,(function(s){switch(s.label){case 0:t=this.handleAppPresetParam(t,n),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.request(t,{method:"post",data:e,headers:r})];case 2:return o=s.sent(),[2,this.doResponseResult(o)];case 3:throw i=s.sent(),new P(i);case 4:return[2]}}))}))},t.prototype.get=function(t,e,r,o){return void 0===e&&(e={}),void 0===r&&(r={}),void 0===o&&(o={}),h(this,void 0,void 0,(function(){var i,s;return v(this,(function(a){switch(a.label){case 0:t=this.attachUrlParam(t,e),a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.request(t,n({method:"get",headers:r},o))];case 2:return i=a.sent(),[2,this.doResponseResult(i)];case 3:throw s=a.sent(),new P(s);case 4:return[2]}}))}))},t.prototype.delete=function(t,e,n){return void 0===n&&(n={}),h(this,void 0,void 0,(function(){var r,o;return v(this,(function(i){switch(i.label){case 0:t=this.handleAppPresetParam(t,e),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.request(t,{method:"delete",headers:n})];case 2:return r=i.sent(),[2,this.doResponseResult(r)];case 3:throw o=i.sent(),new P(o);case 4:return[2]}}))}))},t.prototype.put=function(t,e,n,r){return void 0===n&&(n={}),void 0===r&&(r={}),h(this,void 0,void 0,(function(){var o,i;return v(this,(function(s){switch(s.label){case 0:t=this.handleAppPresetParam(t,n),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.request(t,{method:"put",data:e,headers:r})];case 2:return o=s.sent(),[2,this.doResponseResult(o)];case 3:throw i=s.sent(),new P(i);case 4:return[2]}}))}))},t.prototype.getModel=function(t,e){return void 0===e&&(e={}),h(this,void 0,void 0,(function(){var n,r;return v(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.instance.get(t,{headers:e})];case 1:return n=o.sent(),[2,this.doResponseResult(n)];case 2:throw r=o.sent(),new P(r);case 3:return[2]}}))}))},t.prototype.request=function(t,e){return void 0===e&&(e={}),h(this,void 0,void 0,(function(){var n,r;return v(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.instance.request(this.mergeConfig({url:t},e))];case 1:return n=o.sent(),[2,this.doResponseResult(n)];case 2:throw r=o.sent(),new P(r);case 3:return[2]}}))}))},t.prototype.doResponseResult=function(t){var e=t;return e.status>=200&&e.status<=299&&(e.ok=!0),e},t.prototype.handleAppPresetParam=function(t,e){if(e){var n=Object.keys(e),r={};return n.forEach((function(t){t.startsWith("srf")&&c(e[t])&&(r[t]=e[t])})),this.attachUrlParam(t,e)}return t},t.prototype.attachUrlParam=function(t,e){var n=l(e);return c(n)&&(t=t.endsWith("?")||-1!==t.indexOf("?")&&t.endsWith("&")?"".concat(t).concat(n):-1===t.indexOf("?")||t.endsWith("&")?"".concat(t,"?").concat(n):"".concat(t,"&").concat(n)),t},t}());function D(t){return f(t)}t("UrlHelper",function(){function t(){}return Object.defineProperty(t,"routeBase",{get:function(){return"".concat(this.appBase,"/#")},enumerable:!1,configurable:!0}),Object.defineProperty(t,"appBase",{get:function(){var t=window.location,e=t.origin,n=t.pathname;return"".concat(e).concat(n).replace(/\/$/,"")},enumerable:!1,configurable:!0}),Object.defineProperty(t,"routePath",{get:function(){return window.location.hash.replace("#","")},enumerable:!1,configurable:!0}),Object.defineProperty(t,"fullPath",{get:function(){return window.location.href},enumerable:!1,configurable:!0}),t}());function V(t){var e=t.composedPath&&t.composedPath()||t.path;if(null!=e)return e;return[t.target].concat(function t(e,n){void 0===n&&(n=[]);var r=e.parentNode;return r?t(r,n.concat([r])):n}(t.target))}function W(t,e,n,r){void 0===r&&(r={}),t.addEventListener(e,n,r);var o=function(){t.removeEventListener(e,n,r),o=k};return function(){o()}}function H(t,e){return e&&(t.target===e||V(t).includes(e))}var G="undefined"!=typeof window?window:void 0;var X=Math.round;function J(t){var e=t.length,n=[];if("rgb"===t.slice(0,3).toLowerCase()){var r=t.match(/([\d|.%]{1,3})/g);n[0]=parseInt(r[0],10),n[1]=parseInt(r[1],10),n[2]=parseInt(r[2],10),n[3]=r[3]?-1!==r[3].indexOf("%")?parseInt(r[3],10)/100:parseFloat(r[3]):1}else{r=void 0;r=e<6?parseInt(String(t[1])+t[1]+t[2]+t[2]+t[3]+t[3]+(e>4?String(t[4])+t[4]:""),16):parseInt(t.slice(1),16),n[0]=r>>16&255,n[1]=r>>8&255,n[2]=255&r,n[3]=9===e||5===e?X((r>>24&255)/255*1e4)/1e4:1}return n}function K(t){var e="";switch(t.split(".").pop()){case".wps":e="application/kswps";break;case".doc":e="application/msword";break;case".docx":e="application/vnd.openxmlformats-officedocument.wordprocessingml.document";break;case".txt":e="text/plain";break;case".zip":e="application/zip";break;case".png":e="image/png";break;case".gif":e="image/gif";break;case".jpeg":case".jpg":e="image/jpeg";break;case".rtf":e="application/rtf";break;case".avi":e="video/x-msvideo";break;case".gz":e="application/x-gzip";break;case".tar":e="application/x-tar";break;case".xlsx":e="application/vnd.ms-excel";break;default:e=""}return e}function Y(t){for(var e=[],n=0;n<t.length;n++)e.push(t[n]);return e}function $(t){var e=n({multiple:!0,accept:""},t),r=document.createElement("input");r.setAttribute("type","file"),r.setAttribute("multiple","".concat(e.multiple)),r.setAttribute("accept",e.accept),r.onchange=function(t){var n=t.target,r=n.files?Y(n.files):[];0!==r.length&&(e.onSelected(r),n.value="")},document.body.appendChild(r),r.click(),document.body.removeChild(r)}t("CountLatch",function(){function t(){this.promise=null,this.resolve=null,this.count=0}return t.prototype.startPromise=function(){var t=this;this.promise=new Promise((function(e){t.resolve=e}))},t.prototype.endPromise=function(){this.resolve&&(this.resolve(),this.resolve=null,this.promise=null)},t.prototype.lock=function(){console.log("lock"),this.count+=1,this.promise||(console.log("startPromise"),this.startPromise())},t.prototype.unlock=function(){if(this.count<1)throw new T("lock和unlock次数不匹配!");console.log("unlock"),this.count-=1,0===this.count&&this.endPromise()},t.prototype.await=function(){return h(this,void 0,void 0,(function(){return v(this,(function(t){switch(t.label){case 0:return this.promise?[4,this.promise]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))},t}());var Q=t("IBizSys",(function(){this.env=O,this.log=F,this.net=new B,this.commands=new C})),Z=t("FactoryCenter",(function(){}))}}}));
@@ -0,0 +1,66 @@
1
+ import { ICommand, ICommandHandler, ICommandOption, ICommandRegistry, ICommandsMap, IDisposable } from './interface';
2
+ /**
3
+ * 命令注册中心
4
+ *
5
+ * @author chitanda
6
+ * @date 2022-06-27 13:06:50
7
+ * @export
8
+ * @class CommandRegisterService
9
+ * @implements {ICommandRegistry}
10
+ */
11
+ export declare class CommandsRegistry implements ICommandRegistry {
12
+ /**
13
+ * 已经注册的所有指令
14
+ *
15
+ * @author chitanda
16
+ * @date 2022-07-21 15:07:47
17
+ * @private
18
+ */
19
+ private readonly commands;
20
+ /**
21
+ * 注册指令
22
+ *
23
+ * @author chitanda
24
+ * @date 2022-06-27 13:06:31
25
+ * @param {(string | ICommand)} idOrCommand
26
+ * @param {ICommandHandler} [handler]
27
+ * @return {*} {IDisposable}
28
+ */
29
+ registerCommand(idOrCommand: string | ICommand, handler?: ICommandHandler, opts?: ICommandOption): IDisposable;
30
+ /**
31
+ * 指令是否已经注册
32
+ *
33
+ * @author chitanda
34
+ * @date 2022-07-21 15:07:58
35
+ * @param {string} id
36
+ * @return {*} {boolean}
37
+ */
38
+ hasCommand(id: string): boolean;
39
+ /**
40
+ * 查找指令
41
+ *
42
+ * @author chitanda
43
+ * @date 2022-07-21 16:07:12
44
+ * @param {string} id
45
+ * @return {*} {(ICommand | undefined)}
46
+ */
47
+ getCommand(id: string): ICommand | undefined;
48
+ /**
49
+ * 获取所有指令
50
+ *
51
+ * @author chitanda
52
+ * @date 2022-07-21 16:07:20
53
+ * @return {*} {ICommandsMap}
54
+ */
55
+ getCommands(): ICommandsMap;
56
+ /**
57
+ * 获取指令配置参数
58
+ *
59
+ * @author chitanda
60
+ * @date 2022-07-21 16:07:27
61
+ * @param {string} id
62
+ * @return {*} {(ICommandOption | undefined)}
63
+ */
64
+ getCommandOpt(id: string): ICommandOption | undefined;
65
+ }
66
+ //# sourceMappingURL=command-register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-register.d.ts","sourceRoot":"","sources":["../../src/command/command-register.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACZ,MAAM,aAAa,CAAC;AAGrB;;;;;;;;GAQG;AACH,qBAAa,gBAAiB,YAAW,gBAAgB;IACvD;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA2C;IAEpE;;;;;;;;OAQG;IACH,eAAe,CACb,WAAW,EAAE,MAAM,GAAG,QAAQ,EAC9B,OAAO,CAAC,EAAE,eAAe,EACzB,IAAI,CAAC,EAAE,cAAc,GACpB,WAAW;IAiCd;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI/B;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAQ5C;;;;;;OAMG;IACH,WAAW,IAAI,YAAY;IAY3B;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;CAItD"}
@@ -0,0 +1,113 @@
1
+ import { LinkedList, toDisposable } from './utils';
2
+ /**
3
+ * 命令注册中心
4
+ *
5
+ * @author chitanda
6
+ * @date 2022-06-27 13:06:50
7
+ * @export
8
+ * @class CommandRegisterService
9
+ * @implements {ICommandRegistry}
10
+ */
11
+ export class CommandsRegistry {
12
+ constructor() {
13
+ /**
14
+ * 已经注册的所有指令
15
+ *
16
+ * @author chitanda
17
+ * @date 2022-07-21 15:07:47
18
+ * @private
19
+ */
20
+ this.commands = new Map();
21
+ }
22
+ /**
23
+ * 注册指令
24
+ *
25
+ * @author chitanda
26
+ * @date 2022-06-27 13:06:31
27
+ * @param {(string | ICommand)} idOrCommand
28
+ * @param {ICommandHandler} [handler]
29
+ * @return {*} {IDisposable}
30
+ */
31
+ registerCommand(idOrCommand, handler, opts) {
32
+ if (!idOrCommand) {
33
+ throw new Error(`invalid command`);
34
+ }
35
+ if (typeof idOrCommand === 'string') {
36
+ if (!handler) {
37
+ throw new Error(`invalid command`);
38
+ }
39
+ return this.registerCommand({ id: idOrCommand, handler, opts });
40
+ }
41
+ const { id } = idOrCommand;
42
+ let commands = this.commands.get(id);
43
+ if (!commands) {
44
+ commands = new LinkedList();
45
+ this.commands.set(id, commands);
46
+ }
47
+ const removeFn = commands.unshift(idOrCommand);
48
+ const ret = toDisposable(() => {
49
+ removeFn();
50
+ const command = this.commands.get(id);
51
+ if (command === null || command === void 0 ? void 0 : command.isEmpty()) {
52
+ this.commands.delete(id);
53
+ }
54
+ });
55
+ return ret;
56
+ }
57
+ /**
58
+ * 指令是否已经注册
59
+ *
60
+ * @author chitanda
61
+ * @date 2022-07-21 15:07:58
62
+ * @param {string} id
63
+ * @return {*} {boolean}
64
+ */
65
+ hasCommand(id) {
66
+ return this.commands.has(id);
67
+ }
68
+ /**
69
+ * 查找指令
70
+ *
71
+ * @author chitanda
72
+ * @date 2022-07-21 16:07:12
73
+ * @param {string} id
74
+ * @return {*} {(ICommand | undefined)}
75
+ */
76
+ getCommand(id) {
77
+ const list = this.commands.get(id);
78
+ if (!list || list.isEmpty()) {
79
+ return undefined;
80
+ }
81
+ return list[Symbol.iterator]().next().value;
82
+ }
83
+ /**
84
+ * 获取所有指令
85
+ *
86
+ * @author chitanda
87
+ * @date 2022-07-21 16:07:20
88
+ * @return {*} {ICommandsMap}
89
+ */
90
+ getCommands() {
91
+ const result = new Map();
92
+ const keys = this.commands.keys();
93
+ for (const key of keys) {
94
+ const command = this.getCommand(key);
95
+ if (command) {
96
+ result.set(key, command);
97
+ }
98
+ }
99
+ return result;
100
+ }
101
+ /**
102
+ * 获取指令配置参数
103
+ *
104
+ * @author chitanda
105
+ * @date 2022-07-21 16:07:27
106
+ * @param {string} id
107
+ * @return {*} {(ICommandOption | undefined)}
108
+ */
109
+ getCommandOpt(id) {
110
+ const cmd = this.getCommand(id);
111
+ return cmd === null || cmd === void 0 ? void 0 : cmd.opts;
112
+ }
113
+ }
@@ -0,0 +1,54 @@
1
+ import { ICommandHandler, ICommandOption, IDisposable } from './interface';
2
+ /**
3
+ * 指令控制器
4
+ *
5
+ * @author chitanda
6
+ * @date 2022-06-28 19:06:51
7
+ * @export
8
+ * @class CommandController
9
+ */
10
+ export declare class CommandController {
11
+ private commandRegister;
12
+ /**
13
+ * 注册指令
14
+ *
15
+ * @author chitanda
16
+ * @date 2022-06-28 19:06:45
17
+ * @param {string} id
18
+ * @param {ICommandHandler} handler
19
+ * @param {ICommandOption} [opts]
20
+ * @return {*} {IDisposable}
21
+ */
22
+ register(id: string, handler: ICommandHandler, opts?: ICommandOption): IDisposable;
23
+ /**
24
+ * 执行指令
25
+ *
26
+ * @author chitanda
27
+ * @date 2022-06-28 19:06:38
28
+ * @template T
29
+ * @param {string} id
30
+ * @param {...unknown[]} args
31
+ * @return {*} {Promise<T>}
32
+ */
33
+ execute<T = undefined>(id: string, ...args: unknown[]): Promise<T>;
34
+ /**
35
+ * 判断指令是否存在,可直接抛出异常
36
+ *
37
+ * @author chitanda
38
+ * @date 2022-06-28 19:06:11
39
+ * @param {string} id
40
+ * @param {boolean} [err]
41
+ * @return {*} {boolean}
42
+ */
43
+ hasCommand(id: string, err?: boolean): boolean;
44
+ /**
45
+ * 获取指令配置参数
46
+ *
47
+ * @author chitanda
48
+ * @date 2022-07-21 17:07:11
49
+ * @param {string} id
50
+ * @return {*} {(ICommandOption | undefined)}
51
+ */
52
+ getCommandOpts(id: string): ICommandOption | undefined;
53
+ }
54
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/command/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG3E;;;;;;;GAOG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,eAAe,CAA0B;IAEjD;;;;;;;;;OASG;IACH,QAAQ,CACN,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,eAAe,EACxB,IAAI,CAAC,EAAE,cAAc,GACpB,WAAW;IAId;;;;;;;;;OASG;IACG,OAAO,CAAC,CAAC,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;IAQxE;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,OAAO;IAQ9C;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;CAGvD"}
@@ -0,0 +1,71 @@
1
+ import { CommandsRegistry } from './command-register';
2
+ /**
3
+ * 指令控制器
4
+ *
5
+ * @author chitanda
6
+ * @date 2022-06-28 19:06:51
7
+ * @export
8
+ * @class CommandController
9
+ */
10
+ export class CommandController {
11
+ constructor() {
12
+ this.commandRegister = new CommandsRegistry();
13
+ }
14
+ /**
15
+ * 注册指令
16
+ *
17
+ * @author chitanda
18
+ * @date 2022-06-28 19:06:45
19
+ * @param {string} id
20
+ * @param {ICommandHandler} handler
21
+ * @param {ICommandOption} [opts]
22
+ * @return {*} {IDisposable}
23
+ */
24
+ register(id, handler, opts) {
25
+ return this.commandRegister.registerCommand(id, handler, opts);
26
+ }
27
+ /**
28
+ * 执行指令
29
+ *
30
+ * @author chitanda
31
+ * @date 2022-06-28 19:06:38
32
+ * @template T
33
+ * @param {string} id
34
+ * @param {...unknown[]} args
35
+ * @return {*} {Promise<T>}
36
+ */
37
+ async execute(id, ...args) {
38
+ const command = this.commandRegister.getCommand(id);
39
+ if (command) {
40
+ return command.handler(...args);
41
+ }
42
+ throw new Error(`未注册指令: ${id},请先注册指令`);
43
+ }
44
+ /**
45
+ * 判断指令是否存在,可直接抛出异常
46
+ *
47
+ * @author chitanda
48
+ * @date 2022-06-28 19:06:11
49
+ * @param {string} id
50
+ * @param {boolean} [err]
51
+ * @return {*} {boolean}
52
+ */
53
+ hasCommand(id, err) {
54
+ const bol = !!this.commandRegister.hasCommand(id);
55
+ if (err === true && bol === true) {
56
+ throw new Error(`未注册指令: ${id},请先注册指令`);
57
+ }
58
+ return bol;
59
+ }
60
+ /**
61
+ * 获取指令配置参数
62
+ *
63
+ * @author chitanda
64
+ * @date 2022-07-21 17:07:11
65
+ * @param {string} id
66
+ * @return {*} {(ICommandOption | undefined)}
67
+ */
68
+ getCommandOpts(id) {
69
+ return this.commandRegister.getCommandOpt(id);
70
+ }
71
+ }
@@ -0,0 +1,10 @@
1
+ import { CommandController } from './command';
2
+ export * from './interface';
3
+ export * from './utils';
4
+ export { CommandsRegistry } from './command-register';
5
+ export { CommandController } from './command';
6
+ /**
7
+ * 命令控制器
8
+ */
9
+ export declare const commands: CommandController;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/command/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,QAAQ,mBAA0B,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { CommandController } from './command';
2
+ export * from './interface';
3
+ export * from './utils';
4
+ export { CommandsRegistry } from './command-register';
5
+ export { CommandController } from './command';
6
+ /**
7
+ * 命令控制器
8
+ */
9
+ export const commands = new CommandController();
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 指令参数, 主要用于在指令呈现时的展示参数
3
+ *
4
+ * @author chitanda
5
+ * @date 2022-06-28 17:06:47
6
+ * @export
7
+ * @interface ICommandOption
8
+ */
9
+ export interface ICommandOption {
10
+ readonly id: string;
11
+ readonly title: string;
12
+ readonly tooltip?: string;
13
+ readonly description?: string;
14
+ /**
15
+ * 只支持 svg 图标
16
+ *
17
+ * @author chitanda
18
+ * @date 2022-06-29 14:06:42
19
+ * @type {string}
20
+ */
21
+ readonly icon?: string;
22
+ }
23
+ //# sourceMappingURL=command-option.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-option.d.ts","sourceRoot":"","sources":["../../../../src/command/interface/command/command-option.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,74 @@
1
+ import { IDisposable } from '../disposable/disposable';
2
+ import { ICommandOption } from './command-option';
3
+ /**
4
+ * 注册指令
5
+ *
6
+ * @author chitanda
7
+ * @date 2022-06-27 13:06:25
8
+ * @export
9
+ * @interface ICommand
10
+ */
11
+ export interface ICommand {
12
+ id: string;
13
+ handler: ICommandHandler;
14
+ opts?: ICommandOption;
15
+ }
16
+ /**
17
+ * 触发指令声明
18
+ *
19
+ * @author chitanda
20
+ * @date 2022-06-28 17:06:10
21
+ * @export
22
+ * @interface Command
23
+ */
24
+ export interface Command {
25
+ /**
26
+ * Title of the command, like `save`.
27
+ */
28
+ title: string;
29
+ /**
30
+ * The identifier of the actual command handler.
31
+ * @see {@link commands.registerCommand}
32
+ */
33
+ command: string;
34
+ /**
35
+ * A tooltip for the command, when represented in the UI.
36
+ */
37
+ tooltip?: string;
38
+ /**
39
+ * Arguments that the command handler should be
40
+ * invoked with.
41
+ */
42
+ arguments?: any[];
43
+ }
44
+ /**
45
+ * 指令处理回调
46
+ *
47
+ * @author chitanda
48
+ * @date 2022-06-27 13:06:33
49
+ * @export
50
+ * @interface ICommandHandler
51
+ */
52
+ export interface ICommandHandler {
53
+ (...args: any[]): unknown | Promise<unknown>;
54
+ }
55
+ /**
56
+ * 指令控制器集
57
+ */
58
+ export type ICommandsMap = Map<string, ICommand>;
59
+ /**
60
+ * 注册服务
61
+ *
62
+ * @author chitanda
63
+ * @date 2022-06-27 13:06:16
64
+ * @export
65
+ * @interface ICommandRegistry
66
+ */
67
+ export interface ICommandRegistry {
68
+ registerCommand(id: string, command: ICommandHandler, opts: ICommandOption): IDisposable;
69
+ registerCommand(id: string, command: ICommandHandler): IDisposable;
70
+ registerCommand(command: ICommand): IDisposable;
71
+ getCommand(id: string): ICommand | undefined;
72
+ getCommands(): ICommandsMap;
73
+ }
74
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/command/interface/command/command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,eAAe,CAAC;IACzB,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe;IAC9B,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,eAAe,CACb,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,cAAc,GACnB,WAAW,CAAC;IACf,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,WAAW,CAAC;IACnE,eAAe,CAAC,OAAO,EAAE,QAAQ,GAAG,WAAW,CAAC;IAChD,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC7C,WAAW,IAAI,YAAY,CAAC;CAC7B"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export interface IDisposable {
2
+ dispose(): void;
3
+ }
4
+ //# sourceMappingURL=disposable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disposable.d.ts","sourceRoot":"","sources":["../../../../src/command/interface/disposable/disposable.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,OAAO,IAAI,IAAI,CAAC;CACjB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export { ICommand, Command, ICommandHandler, ICommandsMap, ICommandRegistry, } from './command/command';
2
+ export { ICommandOption } from './command/command-option';
3
+ export { IDisposable } from './disposable/disposable';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/command/interface/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,OAAO,EACP,eAAe,EACf,YAAY,EACZ,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export { LinkedList } from './linked-list';
2
+ export { toDisposable, debounce, throttle } from './util';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/command/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { LinkedList } from './linked-list';
2
+ export { toDisposable, debounce, throttle } from './util';
@@ -0,0 +1,16 @@
1
+ export declare class LinkedList<E> {
2
+ private _first;
3
+ private _last;
4
+ private _size;
5
+ get size(): number;
6
+ isEmpty(): boolean;
7
+ clear(): void;
8
+ unshift(element: E): () => void;
9
+ push(element: E): () => void;
10
+ private _insert;
11
+ shift(): E | undefined;
12
+ pop(): E | undefined;
13
+ private _remove;
14
+ [Symbol.iterator](): Iterator<E>;
15
+ }
16
+ //# sourceMappingURL=linked-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linked-list.d.ts","sourceRoot":"","sources":["../../../src/command/utils/linked-list.ts"],"names":[],"mappings":"AAoBA,qBAAa,UAAU,CAAC,CAAC;IACvB,OAAO,CAAC,MAAM,CAA2B;IAEzC,OAAO,CAAC,KAAK,CAA2B;IAExC,OAAO,CAAC,KAAK,CAAa;IAE1B,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,IAAI,OAAO;IAIlB,KAAK,IAAI,IAAI;IAcb,OAAO,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,IAAI;IAI/B,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,IAAI;IAI5B,OAAO,CAAC,OAAO;IA6Bf,KAAK,IAAI,CAAC,GAAG,SAAS;IAStB,GAAG,IAAI,CAAC,GAAG,SAAS;IASpB,OAAO,CAAC,OAAO;IAwBd,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC;CAOlC"}