@oinone/kunlun-event 6.2.7 → 6.3.0

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.
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */function n(e,t,i,r){return new(i||(i=Promise))((function(s,n){function o(e){try{a(r.next(e))}catch(e){n(e)}}function c(e){try{a(r.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,c)}a((r=r.apply(e,t||[])).next())}))}const o=Symbol("__event_bus_consumer");function c(e,t){return s.register(o,e,t)}function a(e){return s.selector(o,e)}s.createStorage({key:o,matchKeys:["category","type"]});const u=Symbol("__event_bus_producer");function d(e,t){return s.register(u,e,t)}function l(e){return s.selector(u,e)}s.createStorage({key:u,matchKeys:["category","type"]});class _{static getConsumers(e){return _.consumers.get(_.generatorKeyByMessage(e))}static construct(t,r,s){var n;const o=a(t);if(!o)throw new Error(`Unsupported consumer. category: ${t.category}, type: ${t.type}`);const c=i(o,t.type,r,s);return c.el=null===(n=e().currentInstance)||void 0===n?void 0:n.vNode.el,c}static init(e){const t=_.generatorKeyByEngine(e);let i=_.consumers.get(t);i||(i=[],_.consumers.set(t,i)),i.push(e),e.start()}static dispose(e){const t=_.generatorKeyByEngine(e),i=e.key,r=_.consumers.get(t);if(!r)return!1;const s=r.findIndex((e=>e.key===i));if(-1===s)return!1;const n=r.splice(s,1);for(const e of n)e.dispose();return!0}static generatorKey(e,t){return`${e}#${t}`}static generatorKeyByEngine(e){return`${e.category}#${e.type}`}static generatorKeyByMessage(e){return`${e.category}#${e.type}`}}_.consumers=new Map;class E{static getProducer(e,t){return E.producers.get(E.generatorKey(e,t))}static construct(e,t){const r=l(e);if(!r)throw new Error(`Unsupported producer. category: ${e.category}, type: ${e.type}`);return i(r,e.type,t)}static init(e){const t=E.generatorKeyByEngine(e);E.dispose(t),E.producers.set(t,e),e.start()}static dispose(e){const t=E.producers.get(e);return t&&(E.producers.delete(e),t.isDisposed||t.dispose()),t}static generatorKey(e,t){return`${e}#${t}`}static generatorKeyByEngine(e){return`${e.category}#${e.type}`}}E.producers=new Map;class p{constructor(e,t){this._key=this.generatorKey(),this._category=e,this._type=t,this._isActivated=!1,this._isDisposed=!1}get key(){return this._key}get category(){return this._category}get type(){return this._type}get isActivated(){return this._isActivated}get isDisposed(){return this._isDisposed}start(){return!this.isActivated&&(this._isActivated=!0,this.$$start(),!0)}$$start(){}stop(){return!!this.isActivated&&(this._isActivated=!1,this.$$stop(),!0)}$$stop(){}dispose(){return!this.isDisposed&&(this.isActivated&&this.stop(),this._isDisposed=!0,this.$$dispose(),!0)}$$dispose(){}}let y=0;class h extends p{constructor(e,t,i){super(e,t),this._rawConvert=(null==i?void 0:i.convert)||this.$$convert,this._rawPublish=(null==i?void 0:i.publish)||this.$$publish}get rawConvert(){return this._rawConvert}get rawPublish(){return this._rawPublish}convert(e){return this.rawConvert(this,e)}publish(e){this.rawPublish(this,e)}$$publish(e,t){const i=this.convert(t);if(!i)return;const r=_.getConsumers(i);r&&r.length&&r.filter((e=>e.filter(t,i))).map((e=>n(this,void 0,void 0,(function*(){return e.consumer(i)}))))}generatorKey(){return"event_producer_"+y++}$$dispose(){E.dispose(E.generatorKeyByEngine(this))}}let f=0;class g extends p{constructor(e,t,i,r){super(e,t),this._config=(null==r?void 0:r.config)||{},this._rawFilter=(null==r?void 0:r.filter)||this.$$filter.bind(this),this._rawConsumer=i}get config(){return this._config}get rawFilter(){return this._rawFilter}get rawConsumer(){return this._rawConsumer}filter(e,t){return!!this.isActivated&&this.rawFilter(e,t)}$$filter(e,t){return!0}consumer(e){return this.rawConsumer(this,e)}generatorKey(){return"event_consumer_"+f++}$$dispose(){_.dispose(this)}}class I{static init(e,t){const{category:i,type:r}=e;let s=E.getProducer(i,r);return s||(s=E.construct({category:i,type:r},t),E.init(s)),s}static startProducer(e){const{category:t,type:i}=e,r=E.getProducer(t,i);return!!r&&r.start()}static stopProducer(e){const{category:t,type:i}=e,r=E.getProducer(t,i);return!!r&&r.stop()}static publish(e,t){const{category:i,type:r}=e,s=E.getProducer(i,r);if(!s)throw new Error("Invalid producer. please initialize the producer before publish.");s.publish(t)}static subscribe(e,t,i){const r=_.construct(e,t,i);return _.init(r),I.consumerMap.set(t,r),r}static unsubscribe(e){const t=I.consumerMap.get(e);return t&&(I.consumerMap.delete(e),_.dispose(t)),t}static startConsumer(e){const t=I.consumerMap.get(e);return!!t&&t.start()}static stopConsumer(e){const t=I.consumerMap.get(e);return!!t&&t.stop()}}var V,b;I.consumerMap=new Map,function(e){e.global="global",e.view="view",e.current="current"}(V||(V={})),function(e){e.html="html",e.keyboard="keyboard"}(b||(b={}));const w=["keypress","keyup","keydown"];class F{static init(e){return I.init({category:b.html,type:e})}static dispose(e){return E.dispose(`${b.html}#${e}`)}static subscribe(e,t,i,r=!0){return r&&F.init(e),I.subscribe({category:b.html,type:e},t,i)}}const O="global";class N{static init(){return I.init({category:b.keyboard,type:O})}static dispose(){return E.dispose(`${b.keyboard}#${O}`)}static subscribe(e,t,i,r=!0){return r&&N.init(),I.subscribe({category:b.keyboard,type:e},t,i)}}class D{}D.init=I.init,D.startProducer=I.startProducer,D.stopProducer=I.stopProducer,D.publish=I.publish,D.subscribe=I.subscribe,D.unsubscribe=I.unsubscribe,D.start=I.startConsumer,D.stop=I.stopConsumer,D.disposeProducer=E.dispose,D.disposeConsumer=_.dispose,D.subscribeHTMLEvent=F.subscribe,D.subscribeKeyboardEvent=N.subscribe;class m extends h{constructor(e,t,i){super(e,t,i)}$$convert(e,t){return{category:this.category,type:this.type,origin:t}}$$start(){document.addEventListener(this.type,this.publish.bind(this))}$$stop(){document.removeEventListener(this.type,this.publish.bind(this))}}class T extends g{constructor(e,t,i){super(b.html,e,t,i)}}c({category:b.html},T);class A extends m{constructor(e,t){super(b.html,e,t)}}d({category:b.html},A);class v extends g{constructor(e,t,i,r){super(e,t,i,r),this.initConfig()}initConfig(){const{config:e}=this;null==e.scope&&(e.scope=V.view),void 0===e.ctrl&&(e.ctrl=!1),void 0===e.shift&&(e.shift=!1),void 0===e.alt&&(e.alt=!1)}$$filter(e,i){const{scope:r,ctrl:s,alt:n,shift:o}=this.config;let c=!1;switch(r){case V.global:case V.current:c=!0;break;case V.view:{const{el:e}=this;if(!e)break;const{x:i,y:r}=e.getBoundingClientRect(),s=t().clickVisibleArea[0];if(s){const{el:t,x:n,y:o,ex:a,ey:u}=s;if(t)t.contains(e)&&(c=!0);else if(n<=i&&i<=a&&o<=r&&r<=u){c=!0;break}}break}}return!!c&&((null==s||s===i.ctrl)&&((null==o||o===i.shift)&&(null==n||n===i.alt)))}}class C extends v{constructor(e,t,i){super(b.html,e,t,i)}}class S extends v{constructor(e,t,i){super(b.keyboard,e,t,i)}}c({category:b.html,type:w},C),c({category:b.keyboard},S);class U extends m{$$convert(e,t){const i=r.newInstance(t);if(!i.isStateKey())return{category:this.category,type:this.type,origin:t,code:t.code,key:t.key,ctrl:i.isPressCtrl(),alt:i.isPressAlt(),shift:i.isPressShift()}}}class L extends U{constructor(e,t){super(b.html,e,t)}}class $ extends U{constructor(e,t){super(b.keyboard,e,t)}$$convert(e,t){const i=super.$$convert(e,t);return i&&(i.type=t.key),i}onKeydown(e){this.publish(e)}$$start(){document.addEventListener("keydown",this.onKeydown.bind(this))}$$stop(){document.removeEventListener("keydown",this.onKeydown.bind(this))}}var B,M,W,k;d({category:b.html,type:w},L),d({category:b.keyboard},$),function(e){e.FIELD="Field",e.VIEW="View",e.ACTION="Action"}(B||(B={})),function(e){e.ON_VIEW_BEFORE_CREATED="onViewBeforeCreated",e.ON_VIEW_CREATED="onViewCreated",e.ON_VIEW_BEFORE_MOUNT="onViewBeforeMount",e.ON_VIEW_MOUNTED="onViewMounted",e.ON_VIEW_BEFORE_UPDATE="onViewBeforeUpdate",e.ON_VIEW_UPDATED="onViewUpdated",e.ON_VIEW_ACTIVATED="onViewActivated",e.ON_VIEW_BEFORE_UNMOUNT="onViewBeforeUnmount",e.ON_VIEW_UNMOUNTED="onViewUnmounted",e.ON_VIEW_SUBMIT="onViewSubmit",e.ON_VIEW_SUBMIT_START="onViewSubmitStart",e.ON_VIEW_SUBMIT_END="onViewSubmitEnd",e.ON_VIEW_SUBMIT_SUCCESS="onViewSubmitSuccess",e.ON_VIEW_SUBMIT_FAILED="onViewSubmitFailed",e.ON_VIEW_VALIDATE_START="onViewValidateStart",e.ON_VIEW_VALIDATE_SUCCESS="onViewValidateSuccess",e.ON_VIEW_VALIDATE_FAILED="onViewValidateFailed",e.ON_VIEW_VALIDATE_END="onViewValidateEnd",e.ON_FIELD_BEFORE_CREATED="onFieldBeforeCreated",e.ON_FIELD_CREATED="onFieldCreated",e.ON_FIELD_BEFORE_MOUNT="onFieldBeforeMount",e.ON_FIELD_MOUNTED="onFieldMounted",e.ON_FIELD_BEFORE_UPDATE="onFieldBeforeUpdate",e.ON_FIELD_UPDATED="onFieldUpdated",e.ON_FIELD_ACTIVATED="onFieldActivated",e.ON_FIELD_BEFORE_UNMOUNT="onFieldBeforeUnmount",e.ON_FIELD_UNMOUNTED="onFieldUnmounted",e.ON_FIELD_FOCUS="onFieldFocus",e.ON_FIELD_CHANGE="onFieldChange",e.ON_FIELD_BLUR="onFieldBlur",e.ON_FIELD_VALIDATE_START="onFieldValidateStart",e.ON_FIELD_VALIDATE_SUCCESS="onFieldValidateSuccess",e.ON_FIELD_VALIDATE_FAILED="onFieldValidateFailed",e.ON_FIELD_VALIDATE_END="onFieldValidateEnd"}(M||(M={})),function(e){e.viewBeforeCreated="onViewBeforeCreated",e.viewCreated="onViewCreated",e.viewBeforeMount="onViewBeforeMount",e.viewMounted="onViewMounted",e.viewBeforeUpdate="onViewBeforeUpdate",e.viewUpdated="onViewUpdated",e.viewActivated="onViewActivated",e.viewBeforeUnmount="onViewBeforeUnmount",e.viewUnmounted="onViewUnmounted",e.viewSubmit="onViewSubmit",e.viewSubmitStart="onViewSubmitStart",e.viewSubmitEnd="onViewSubmitEnd",e.viewSubmitSuccess="onViewSubmitSuccess",e.viewSubmitFailed="onViewSubmitFailed",e.viewValidateStart="onViewValidateStart",e.viewValidateSuccess="onViewValidateSuccess",e.viewValidateFailed="onViewValidateFailed",e.viewValidateEnd="onViewValidateEnd"}(W||(W={})),function(e){e.beforeCreated="onFieldBeforeCreated",e.created="onFieldCreated",e.beforeMount="onFieldBeforeMount",e.mount="onFieldMounted",e.beforeUpdate="onFieldBeforeUpdate",e.updated="onViewUpdated",e.beforeUnmount="onFieldBeforeUnmount",e.unmounted="onFieldUnmounted",e.focus="onFieldFocus",e.change="onFieldChange",e.blur="onFieldBlur",e.validateStart="onFieldValidateStart",e.validateSuccess="onFieldValidateSuccess",e.validateFailed="onFieldValidateFailed",e.validateEnd="onFieldValidateEnd"}(k||(k={}));const R=e=>t=>P(t)===`[object ${e}]`,P=e=>Object.prototype.toString.call(e),x=e=>"function"==typeof e,K=Array.isArray,j=R("Object"),H=R("String"),z=R("Boolean"),G=R("Number"),q=e=>e&&e instanceof Map,J=e=>e&&e instanceof Set,Q=e=>e&&e instanceof WeakMap,X=e=>e&&e instanceof WeakSet,Y=e=>G(e)||/^\d+$/.test(e),Z=e=>"object"==typeof e,ee=R("RegExp");class te{constructor(e){if(!x(e))throw new Error("life cycle callback must be function");this.listener=this.buildListener(e)}buildListener(e){return t=>{x(e)&&e(t)}}notify(e){this.listener.call(e,e)}}class ie{static initialize(e){this.lifeCycles=e}static getLifeCycleIndex(e){return this.lifeCycles.findIndex((t=>t.type===e))}static getLifeCycle(){return this.lifeCycles}static getLifeCycleByType(e){const t=this.getLifeCycleIndex(e);return t>=0?this.lifeCycles[t]:null}static setType(e){this.heartType=e}static setLifeCycle(e,t,i){if(!(H(e)&&H(t)&&i instanceof te))return!1;if(!this.heartType)throw new Error('set fail, use "LifeCycleHeart.setType(type)" first, then call "setLifeCycle"');const r=this.getLifeCycleIndex(e);r>=0?t&&this.lifeCycles[r].pattern.push({identifier:t,lifes:[i]}):this.lifeCycles.push({type:e,registryType:this.heartType,pattern:[{identifier:t,lifes:[i]}]}),this.heartType=null}static publish(e,t,i){if(!e||!t||!i)return!1;const r=this.getLifeCycleIndex(e);if(r>=0&&t){const e=this.lifeCycles[r].pattern.find((e=>e.identifier===t));e&&e.lifes.forEach((e=>{e.notify(i)}))}}static disposeLifeCycle(e){}static dispose(e){this.lifeCycles.forEach((t=>{const i=t.pattern.findIndex((t=>t.identifier===e));i>=0&&t.pattern.splice(i,1)}))}}function re(e,t){return(i,r)=>{if(!H(i))throw new Error("arg[0] must be string, but now is "+typeof i);if(r){if(!x(r))throw new Error("arg[1] must be function");ie.setType(t),ie.setLifeCycle(e,i,new te(r))}}}function se(e){return re(e,B.FIELD)}ie.lifeCycles=[],ie.heartType=null;const ne=se(M.ON_FIELD_BEFORE_CREATED),oe=se(M.ON_FIELD_CREATED),ce=se(M.ON_FIELD_BEFORE_MOUNT),ae=se(M.ON_FIELD_MOUNTED),ue=se(M.ON_FIELD_BEFORE_UPDATE),de=se(M.ON_FIELD_UPDATED),le=se(M.ON_FIELD_BEFORE_UNMOUNT),_e=se(M.ON_FIELD_UNMOUNTED),Ee=se(M.ON_FIELD_VALIDATE_START),pe=se(M.ON_FIELD_VALIDATE_SUCCESS),ye=se(M.ON_FIELD_VALIDATE_FAILED),he=se(M.ON_FIELD_VALIDATE_END),fe=se(M.ON_FIELD_FOCUS),ge=se(M.ON_FIELD_CHANGE),Ie=se(M.ON_FIELD_BLUR);function Ve(e){return re(e,B.VIEW)}const be=Ve(M.ON_VIEW_BEFORE_CREATED),we=Ve(M.ON_VIEW_CREATED),Fe=Ve(M.ON_VIEW_BEFORE_MOUNT),Oe=Ve(M.ON_VIEW_MOUNTED),Ne=Ve(M.ON_VIEW_BEFORE_UPDATE),De=Ve(M.ON_VIEW_UPDATED),me=Ve(M.ON_VIEW_BEFORE_UNMOUNT),Te=Ve(M.ON_VIEW_UNMOUNTED),Ae=Ve(M.ON_VIEW_SUBMIT),ve=Ve(M.ON_VIEW_SUBMIT_START),Ce=Ve(M.ON_VIEW_SUBMIT_SUCCESS),Se=Ve(M.ON_VIEW_SUBMIT_FAILED),Ue=Ve(M.ON_VIEW_SUBMIT_END),Le=Ve(M.ON_VIEW_VALIDATE_START),$e=Ve(M.ON_VIEW_VALIDATE_SUCCESS),Be=Ve(M.ON_VIEW_VALIDATE_FAILED),Me=Ve(M.ON_VIEW_VALIDATE_END);export{g as AbstractEventConsumer,h as AbstractEventProducer,m as AbstractHTMLEventProducer,D as EventBus,b as EventCategory,V as EventConsumerScope,k as FieldEventNames,T as HTMLEventConsumer,A as HTMLEventProducer,C as HTMLKeyboardEventConsumer,L as HTMLKeyboardEventProducer,S as KeyboardEventConsumer,$ as KeyboardEventProducer,w as KeyboardTypes,te as LifeCycle,ie as LifeCycleHeart,M as LifeCycleTypes,B as RegistryType,W as ViewEventNames,K as isArr,z as isBool,x as isFn,q as isMap,G as isNum,Y as isNumberLike,Z as isObj,j as isPlainObj,ee as isRegExp,J as isSet,H as isStr,Q as isWeakMap,X as isWeakSet,ne as onFieldBeforeCreate,ce as onFieldBeforeMount,le as onFieldBeforeUnmount,ue as onFieldBeforeUpdate,Ie as onFieldBlur,oe as onFieldCreated,fe as onFieldFocus,ae as onFieldMounted,_e as onFieldUnmounted,de as onFieldUpdated,he as onFieldValidateEnd,ye as onFieldValidateFailed,Ee as onFieldValidateStart,pe as onFieldValidateSuccess,ge as onFieldValueChange,be as onViewBeforeCreated,Fe as onViewBeforeMount,me as onViewBeforeUnmount,Ne as onViewBeforeUpdate,we as onViewCreated,Oe as onViewMounted,Ae as onViewSubmit,Ue as onViewSubmitEnd,Se as onViewSubmitFailed,ve as onViewSubmitStart,Ce as onViewSubmitSuccess,Te as onViewUnmounted,De as onViewUpdated,Me as onViewValidateEnd,Be as onViewValidateFailed,Le as onViewValidateStart,$e as onViewValidateSuccess,c as registerEventConsumer,d as registerEventProducer,a as selectorEventConsumer,l as selectorEventProducer};
15
+ ***************************************************************************** */function n(e,t,i,r){return new(i||(i=Promise))(function(s,n){function o(e){try{a(r.next(e))}catch(e){n(e)}}function c(e){try{a(r.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(o,c)}a((r=r.apply(e,t||[])).next())})}const o=Symbol("__event_bus_consumer");function c(e,t){return s.register(o,e,t)}function a(e){return s.selector(o,e)}s.createStorage({key:o,matchKeys:["category","type"]});const u=Symbol("__event_bus_producer");function d(e,t){return s.register(u,e,t)}function l(e){return s.selector(u,e)}s.createStorage({key:u,matchKeys:["category","type"]});class _{static getConsumers(e){return _.consumers.get(_.generatorKeyByMessage(e))}static construct(t,r,s){var n;const o=a(t);if(!o)throw new Error(`Unsupported consumer. category: ${t.category}, type: ${t.type}`);const c=i(o,t.type,r,s);return c.el=null===(n=e().currentInstance)||void 0===n?void 0:n.vNode.el,c}static init(e){const t=_.generatorKeyByEngine(e);let i=_.consumers.get(t);i||(i=[],_.consumers.set(t,i)),i.push(e),e.start()}static dispose(e){const t=_.generatorKeyByEngine(e),i=e.key,r=_.consumers.get(t);if(!r)return!1;const s=r.findIndex(e=>e.key===i);if(-1===s)return!1;const n=r.splice(s,1);for(const e of n)e.dispose();return!0}static generatorKey(e,t){return`${e}#${t}`}static generatorKeyByEngine(e){return`${e.category}#${e.type}`}static generatorKeyByMessage(e){return`${e.category}#${e.type}`}}_.consumers=new Map;class E{static getProducer(e,t){return E.producers.get(E.generatorKey(e,t))}static construct(e,t){const r=l(e);if(!r)throw new Error(`Unsupported producer. category: ${e.category}, type: ${e.type}`);return i(r,e.type,t)}static init(e){const t=E.generatorKeyByEngine(e);E.dispose(t),E.producers.set(t,e),e.start()}static dispose(e){const t=E.producers.get(e);return t&&(E.producers.delete(e),t.isDisposed||t.dispose()),t}static generatorKey(e,t){return`${e}#${t}`}static generatorKeyByEngine(e){return`${e.category}#${e.type}`}}E.producers=new Map;class p{constructor(e,t){this._key=this.generatorKey(),this._category=e,this._type=t,this._isActivated=!1,this._isDisposed=!1}get key(){return this._key}get category(){return this._category}get type(){return this._type}get isActivated(){return this._isActivated}get isDisposed(){return this._isDisposed}start(){return!this.isActivated&&(this._isActivated=!0,this.$$start(),!0)}$$start(){}stop(){return!!this.isActivated&&(this._isActivated=!1,this.$$stop(),!0)}$$stop(){}dispose(){return!this.isDisposed&&(this.isActivated&&this.stop(),this._isDisposed=!0,this.$$dispose(),!0)}$$dispose(){}}let y=0;class h extends p{constructor(e,t,i){super(e,t),this._rawConvert=(null==i?void 0:i.convert)||this.$$convert,this._rawPublish=(null==i?void 0:i.publish)||this.$$publish}get rawConvert(){return this._rawConvert}get rawPublish(){return this._rawPublish}convert(e){return this.rawConvert(this,e)}publish(e){this.rawPublish(this,e)}$$publish(e,t){const i=this.convert(t);if(!i)return;const r=_.getConsumers(i);r&&r.length&&r.filter(e=>e.filter(t,i)).map(e=>n(this,void 0,void 0,function*(){return e.consumer(i)}))}generatorKey(){return"event_producer_"+y++}$$dispose(){E.dispose(E.generatorKeyByEngine(this))}}let f=0;class g extends p{constructor(e,t,i,r){super(e,t),this._config=(null==r?void 0:r.config)||{},this._rawFilter=(null==r?void 0:r.filter)||this.$$filter.bind(this),this._rawConsumer=i}get config(){return this._config}get rawFilter(){return this._rawFilter}get rawConsumer(){return this._rawConsumer}filter(e,t){return!!this.isActivated&&this.rawFilter(e,t)}$$filter(e,t){return!0}consumer(e){return this.rawConsumer(this,e)}generatorKey(){return"event_consumer_"+f++}$$dispose(){_.dispose(this)}}class I{static init(e,t){const{category:i,type:r}=e;let s=E.getProducer(i,r);return s||(s=E.construct({category:i,type:r},t),E.init(s)),s}static startProducer(e){const{category:t,type:i}=e,r=E.getProducer(t,i);return!!r&&r.start()}static stopProducer(e){const{category:t,type:i}=e,r=E.getProducer(t,i);return!!r&&r.stop()}static publish(e,t){const{category:i,type:r}=e,s=E.getProducer(i,r);if(!s)throw new Error("Invalid producer. please initialize the producer before publish.");s.publish(t)}static subscribe(e,t,i){const r=_.construct(e,t,i);return _.init(r),I.consumerMap.set(t,r),r}static unsubscribe(e){const t=I.consumerMap.get(e);return t&&(I.consumerMap.delete(e),_.dispose(t)),t}static startConsumer(e){const t=I.consumerMap.get(e);return!!t&&t.start()}static stopConsumer(e){const t=I.consumerMap.get(e);return!!t&&t.stop()}}var V,b;I.consumerMap=new Map,function(e){e.global="global",e.view="view",e.current="current"}(V||(V={})),function(e){e.html="html",e.keyboard="keyboard"}(b||(b={}));const w=["keypress","keyup","keydown"];class F{static init(e){return I.init({category:b.html,type:e})}static dispose(e){return E.dispose(`${b.html}#${e}`)}static subscribe(e,t,i,r=!0){return r&&F.init(e),I.subscribe({category:b.html,type:e},t,i)}}const O="global";class N{static init(){return I.init({category:b.keyboard,type:O})}static dispose(){return E.dispose(`${b.keyboard}#${O}`)}static subscribe(e,t,i,r=!0){return r&&N.init(),I.subscribe({category:b.keyboard,type:e},t,i)}}class D{}D.init=I.init,D.startProducer=I.startProducer,D.stopProducer=I.stopProducer,D.publish=I.publish,D.subscribe=I.subscribe,D.unsubscribe=I.unsubscribe,D.start=I.startConsumer,D.stop=I.stopConsumer,D.disposeProducer=E.dispose,D.disposeConsumer=_.dispose,D.subscribeHTMLEvent=F.subscribe,D.subscribeKeyboardEvent=N.subscribe;class m extends h{constructor(e,t,i){super(e,t,i)}$$convert(e,t){return{category:this.category,type:this.type,origin:t}}$$start(){document.addEventListener(this.type,this.publish.bind(this))}$$stop(){document.removeEventListener(this.type,this.publish.bind(this))}}class T extends g{constructor(e,t,i){super(b.html,e,t,i)}}c({category:b.html},T);class A extends m{constructor(e,t){super(b.html,e,t)}}d({category:b.html},A);class v extends g{constructor(e,t,i,r){super(e,t,i,r),this.initConfig()}initConfig(){const{config:e}=this;null==e.scope&&(e.scope=V.view),void 0===e.ctrl&&(e.ctrl=!1),void 0===e.shift&&(e.shift=!1),void 0===e.alt&&(e.alt=!1)}$$filter(e,i){const{scope:r,ctrl:s,alt:n,shift:o}=this.config;let c=!1;switch(r){case V.global:case V.current:c=!0;break;case V.view:{const{el:e}=this;if(!e)break;const{x:i,y:r}=e.getBoundingClientRect(),s=t().clickVisibleArea[0];if(s){const{el:t,x:n,y:o,ex:a,ey:u}=s;if(t)t.contains(e)&&(c=!0);else if(n<=i&&i<=a&&o<=r&&r<=u){c=!0;break}}break}}return!!c&&((null==s||s===i.ctrl)&&((null==o||o===i.shift)&&(null==n||n===i.alt)))}}class C extends v{constructor(e,t,i){super(b.html,e,t,i)}}class S extends v{constructor(e,t,i){super(b.keyboard,e,t,i)}}c({category:b.html,type:w},C),c({category:b.keyboard},S);class U extends m{$$convert(e,t){const i=r.newInstance(t);if(!i.isStateKey())return{category:this.category,type:this.type,origin:t,code:t.code,key:t.key,ctrl:i.isPressCtrl(),alt:i.isPressAlt(),shift:i.isPressShift()}}}class L extends U{constructor(e,t){super(b.html,e,t)}}class $ extends U{constructor(e,t){super(b.keyboard,e,t)}$$convert(e,t){const i=super.$$convert(e,t);return i&&(i.type=t.key),i}onKeydown(e){this.publish(e)}$$start(){document.addEventListener("keydown",this.onKeydown.bind(this))}$$stop(){document.removeEventListener("keydown",this.onKeydown.bind(this))}}var B,M,W,k;d({category:b.html,type:w},L),d({category:b.keyboard},$),function(e){e.FIELD="Field",e.VIEW="View",e.ACTION="Action"}(B||(B={})),function(e){e.ON_VIEW_BEFORE_CREATED="onViewBeforeCreated",e.ON_VIEW_CREATED="onViewCreated",e.ON_VIEW_BEFORE_MOUNT="onViewBeforeMount",e.ON_VIEW_MOUNTED="onViewMounted",e.ON_VIEW_BEFORE_UPDATE="onViewBeforeUpdate",e.ON_VIEW_UPDATED="onViewUpdated",e.ON_VIEW_ACTIVATED="onViewActivated",e.ON_VIEW_BEFORE_UNMOUNT="onViewBeforeUnmount",e.ON_VIEW_UNMOUNTED="onViewUnmounted",e.ON_VIEW_SUBMIT="onViewSubmit",e.ON_VIEW_SUBMIT_START="onViewSubmitStart",e.ON_VIEW_SUBMIT_END="onViewSubmitEnd",e.ON_VIEW_SUBMIT_SUCCESS="onViewSubmitSuccess",e.ON_VIEW_SUBMIT_FAILED="onViewSubmitFailed",e.ON_VIEW_VALIDATE_START="onViewValidateStart",e.ON_VIEW_VALIDATE_SUCCESS="onViewValidateSuccess",e.ON_VIEW_VALIDATE_FAILED="onViewValidateFailed",e.ON_VIEW_VALIDATE_END="onViewValidateEnd",e.ON_FIELD_BEFORE_CREATED="onFieldBeforeCreated",e.ON_FIELD_CREATED="onFieldCreated",e.ON_FIELD_BEFORE_MOUNT="onFieldBeforeMount",e.ON_FIELD_MOUNTED="onFieldMounted",e.ON_FIELD_BEFORE_UPDATE="onFieldBeforeUpdate",e.ON_FIELD_UPDATED="onFieldUpdated",e.ON_FIELD_ACTIVATED="onFieldActivated",e.ON_FIELD_BEFORE_UNMOUNT="onFieldBeforeUnmount",e.ON_FIELD_UNMOUNTED="onFieldUnmounted",e.ON_FIELD_FOCUS="onFieldFocus",e.ON_FIELD_CHANGE="onFieldChange",e.ON_FIELD_BLUR="onFieldBlur",e.ON_FIELD_VALIDATE_START="onFieldValidateStart",e.ON_FIELD_VALIDATE_SUCCESS="onFieldValidateSuccess",e.ON_FIELD_VALIDATE_FAILED="onFieldValidateFailed",e.ON_FIELD_VALIDATE_END="onFieldValidateEnd"}(M||(M={})),function(e){e.viewBeforeCreated="onViewBeforeCreated",e.viewCreated="onViewCreated",e.viewBeforeMount="onViewBeforeMount",e.viewMounted="onViewMounted",e.viewBeforeUpdate="onViewBeforeUpdate",e.viewUpdated="onViewUpdated",e.viewActivated="onViewActivated",e.viewBeforeUnmount="onViewBeforeUnmount",e.viewUnmounted="onViewUnmounted",e.viewSubmit="onViewSubmit",e.viewSubmitStart="onViewSubmitStart",e.viewSubmitEnd="onViewSubmitEnd",e.viewSubmitSuccess="onViewSubmitSuccess",e.viewSubmitFailed="onViewSubmitFailed",e.viewValidateStart="onViewValidateStart",e.viewValidateSuccess="onViewValidateSuccess",e.viewValidateFailed="onViewValidateFailed",e.viewValidateEnd="onViewValidateEnd"}(W||(W={})),function(e){e.beforeCreated="onFieldBeforeCreated",e.created="onFieldCreated",e.beforeMount="onFieldBeforeMount",e.mount="onFieldMounted",e.beforeUpdate="onFieldBeforeUpdate",e.updated="onViewUpdated",e.beforeUnmount="onFieldBeforeUnmount",e.unmounted="onFieldUnmounted",e.focus="onFieldFocus",e.change="onFieldChange",e.blur="onFieldBlur",e.validateStart="onFieldValidateStart",e.validateSuccess="onFieldValidateSuccess",e.validateFailed="onFieldValidateFailed",e.validateEnd="onFieldValidateEnd"}(k||(k={}));const R=e=>t=>P(t)===`[object ${e}]`,P=e=>Object.prototype.toString.call(e),x=e=>"function"==typeof e,K=Array.isArray,j=R("Object"),H=R("String"),z=R("Boolean"),G=R("Number"),q=e=>e&&e instanceof Map,J=e=>e&&e instanceof Set,Q=e=>e&&e instanceof WeakMap,X=e=>e&&e instanceof WeakSet,Y=e=>G(e)||/^\d+$/.test(e),Z=e=>"object"==typeof e,ee=R("RegExp");class te{constructor(e){if(!x(e))throw new Error("life cycle callback must be function");this.listener=this.buildListener(e)}buildListener(e){return t=>{x(e)&&e(t)}}notify(e){this.listener.call(e,e)}}class ie{static initialize(e){this.lifeCycles=e}static getLifeCycleIndex(e){return this.lifeCycles.findIndex(t=>t.type===e)}static getLifeCycle(){return this.lifeCycles}static getLifeCycleByType(e){const t=this.getLifeCycleIndex(e);return t>=0?this.lifeCycles[t]:null}static setType(e){this.heartType=e}static setLifeCycle(e,t,i){if(!(H(e)&&H(t)&&i instanceof te))return!1;if(!this.heartType)throw new Error('set fail, use "LifeCycleHeart.setType(type)" first, then call "setLifeCycle"');const r=this.getLifeCycleIndex(e);r>=0?t&&this.lifeCycles[r].pattern.push({identifier:t,lifes:[i]}):this.lifeCycles.push({type:e,registryType:this.heartType,pattern:[{identifier:t,lifes:[i]}]}),this.heartType=null}static publish(e,t,i){if(!e||!t||!i)return!1;const r=this.getLifeCycleIndex(e);if(r>=0&&t){const e=this.lifeCycles[r].pattern.find(e=>e.identifier===t);e&&e.lifes.forEach(e=>{e.notify(i)})}}static disposeLifeCycle(e){}static dispose(e){this.lifeCycles.forEach(t=>{const i=t.pattern.findIndex(t=>t.identifier===e);i>=0&&t.pattern.splice(i,1)})}}function re(e,t){return(i,r)=>{if(!H(i))throw new Error("arg[0] must be string, but now is "+typeof i);if(r){if(!x(r))throw new Error("arg[1] must be function");ie.setType(t),ie.setLifeCycle(e,i,new te(r))}}}function se(e){return re(e,B.FIELD)}ie.lifeCycles=[],ie.heartType=null;const ne=se(M.ON_FIELD_BEFORE_CREATED),oe=se(M.ON_FIELD_CREATED),ce=se(M.ON_FIELD_BEFORE_MOUNT),ae=se(M.ON_FIELD_MOUNTED),ue=se(M.ON_FIELD_BEFORE_UPDATE),de=se(M.ON_FIELD_UPDATED),le=se(M.ON_FIELD_BEFORE_UNMOUNT),_e=se(M.ON_FIELD_UNMOUNTED),Ee=se(M.ON_FIELD_VALIDATE_START),pe=se(M.ON_FIELD_VALIDATE_SUCCESS),ye=se(M.ON_FIELD_VALIDATE_FAILED),he=se(M.ON_FIELD_VALIDATE_END),fe=se(M.ON_FIELD_FOCUS),ge=se(M.ON_FIELD_CHANGE),Ie=se(M.ON_FIELD_BLUR);function Ve(e){return re(e,B.VIEW)}const be=Ve(M.ON_VIEW_BEFORE_CREATED),we=Ve(M.ON_VIEW_CREATED),Fe=Ve(M.ON_VIEW_BEFORE_MOUNT),Oe=Ve(M.ON_VIEW_MOUNTED),Ne=Ve(M.ON_VIEW_BEFORE_UPDATE),De=Ve(M.ON_VIEW_UPDATED),me=Ve(M.ON_VIEW_BEFORE_UNMOUNT),Te=Ve(M.ON_VIEW_UNMOUNTED),Ae=Ve(M.ON_VIEW_SUBMIT),ve=Ve(M.ON_VIEW_SUBMIT_START),Ce=Ve(M.ON_VIEW_SUBMIT_SUCCESS),Se=Ve(M.ON_VIEW_SUBMIT_FAILED),Ue=Ve(M.ON_VIEW_SUBMIT_END),Le=Ve(M.ON_VIEW_VALIDATE_START),$e=Ve(M.ON_VIEW_VALIDATE_SUCCESS),Be=Ve(M.ON_VIEW_VALIDATE_FAILED),Me=Ve(M.ON_VIEW_VALIDATE_END);export{g as AbstractEventConsumer,h as AbstractEventProducer,m as AbstractHTMLEventProducer,D as EventBus,b as EventCategory,V as EventConsumerScope,k as FieldEventNames,T as HTMLEventConsumer,A as HTMLEventProducer,C as HTMLKeyboardEventConsumer,L as HTMLKeyboardEventProducer,S as KeyboardEventConsumer,$ as KeyboardEventProducer,w as KeyboardTypes,te as LifeCycle,ie as LifeCycleHeart,M as LifeCycleTypes,B as RegistryType,W as ViewEventNames,K as isArr,z as isBool,x as isFn,q as isMap,G as isNum,Y as isNumberLike,Z as isObj,j as isPlainObj,ee as isRegExp,J as isSet,H as isStr,Q as isWeakMap,X as isWeakSet,ne as onFieldBeforeCreate,ce as onFieldBeforeMount,le as onFieldBeforeUnmount,ue as onFieldBeforeUpdate,Ie as onFieldBlur,oe as onFieldCreated,fe as onFieldFocus,ae as onFieldMounted,_e as onFieldUnmounted,de as onFieldUpdated,he as onFieldValidateEnd,ye as onFieldValidateFailed,Ee as onFieldValidateStart,pe as onFieldValidateSuccess,ge as onFieldValueChange,be as onViewBeforeCreated,Fe as onViewBeforeMount,me as onViewBeforeUnmount,Ne as onViewBeforeUpdate,we as onViewCreated,Oe as onViewMounted,Ae as onViewSubmit,Ue as onViewSubmitEnd,Se as onViewSubmitFailed,ve as onViewSubmitStart,Ce as onViewSubmitSuccess,Te as onViewUnmounted,De as onViewUpdated,Me as onViewValidateEnd,Be as onViewValidateFailed,Le as onViewValidateStart,$e as onViewValidateSuccess,c as registerEventConsumer,d as registerEventProducer,a as selectorEventConsumer,l as selectorEventProducer};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oinone/kunlun-event",
3
- "version": "6.2.7",
3
+ "version": "6.3.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "prebuild": "rimraf dist",
@@ -11,9 +11,9 @@
11
11
  "x-postpublish": "node ../../scripts/postpublish.js"
12
12
  },
13
13
  "devDependencies": {
14
- "@oinone/kunlun-environment": "6.2.7",
15
- "@oinone/kunlun-shared": "6.2.7",
16
- "@oinone/kunlun-spi": "6.2.7"
14
+ "@oinone/kunlun-environment": "6.3.0",
15
+ "@oinone/kunlun-shared": "6.3.0",
16
+ "@oinone/kunlun-spi": "6.3.0"
17
17
  },
18
18
  "gitHead": "2b4c0c7911626c105ca71c2d41e54af470e2e079"
19
19
  }