1 |
- import{s as j,y as b,f as v,aD as I,O as x,z as g,P as _,Q as o,bF as B,bG as T,aF as R,E as z,G as A,bH as M,aX as U,a1 as k,o as L,ah as $}from"./index-DT8qTvyx.js";var F=function(u){var t,e=u.value,i=u.db,n=u.delimiter,s=n===void 0?",":n,a={code:0,province:"",provinceCode:0,city:"",cityCode:0,district:"",districtCode:0,street:""};if(!i||!e)return a;var r=e&&e.code||typeof e=="number"&&e||typeof e=="string"&&/(\d{6})/.test(e)&&RegExp.$1;if(r&&i[r]){r=parseInt(r,10),a.code=r;var l=r-r%1e4;i[l]&&(a.provinceCode=l,a.province=i[l]);var d=r-r%100;d!==l&&i[d]?(a.cityCode=d,a.city=i[d]):~((t=i.city[l])===null||t===void 0?void 0:t.indexOf(r))&&(a.cityCode=r,a.city=i[r]),r%100&&(a.district=i[r],a.districtCode=r)}return e&&e.street?a.street=e.street:typeof e=="string"&&~e.indexOf(s)&&(a.street=e.slice(e.indexOf(s)+s.length)),a},V=function(u){L(()=>import("./CityDB-BE15Pmsw.js"),[]).then(u)},G=function(u){j(t,u);function t(){var e=u!==null&&u.apply(this,arguments)||this;return e.state={code:0,province:"",provinceCode:0,city:"",cityCode:0,district:"",districtCode:0,street:""},e}return t.prototype.componentDidMount=function(){var e=this;this.loadDb(function(){return e.syncIn()})},t.prototype.componentDidUpdate=function(e){var i=this,n=this.props;n.value!==e.value&&this.loadDb(function(){return i.syncIn(n)})},t.prototype.loadDb=function(e){var i=this;if(this.state.db){e==null||e();return}V(function(n){i.setState({db:b(b({},n.default),{province:n.province,city:n.city,district:n.district})},e)})},t.prototype.handleProvinceChange=function(e){this.setState(e?{province:e.label,provinceCode:e.value,city:"",cityCode:0,district:"",districtCode:0,street:"",code:e?e.value:0}:{code:0,province:"",provinceCode:0,city:"",cityCode:0,district:"",districtCode:0,street:""},this.syncOut)},t.prototype.handleCityChange=function(e){if(e.value%100)return this.handleDistrictChange(e,{cityCode:e.value});this.setState(e?{city:e.label,cityCode:e.value,district:"",districtCode:0,street:"",code:e.value}:{city:"",cityCode:0,district:"",districtCode:0,street:"",code:this.state.provinceCode},this.syncOut)},t.prototype.handleDistrictChange=function(e,i){i===void 0&&(i={}),this.setState(e?b(b({},i),{district:e.label,districtCode:e.value,street:"",code:e.value}):b(b({},i),{district:"",districtCode:0,street:"",code:this.state.cityCode}),this.syncOut)},t.prototype.handleStreetChange=function(e){this.setState({street:e.currentTarget.value})},t.prototype.handleStreetEnd=function(){this.syncOut()},t.prototype.syncIn=function(e){e===void 0&&(e=this.props);var i=this.state.db,n=e.value,s=e.delimiter;i&&this.setState(F({value:n,delimiter:s,db:i}))},t.prototype.syncOut=function(){var e=this.props,i=e.onChange,n=e.allowStreet,s=e.joinValues,a=e.extractValue,r=e.delimiter,l=this.state,d=l.code,y=l.province,c=l.city,f=l.district,p=l.street,C=l.provinceCode,w=l.cityCode,h=l.districtCode;i((typeof a>"u"?s:a)?d?n&&p?[d,p].join(r):String(d):"":{code:d,provinceCode:C,province:y,cityCode:w,city:c,districtCode:h,district:f,street:p})},t.prototype.render=function(){var e,i,n=this.props,s=n.classnames,a=n.className;n.style;var r=n.disabled,l=n.allowCity,d=n.allowDistrict,y=n.allowStreet,c=n.searchable,f=n.translate,p=n.loadingConfig,C=n.popOverContainer,w=n.itemClassName,h=n.testIdBuilder,E=this.state,S=E.provinceCode,D=E.cityCode,N=E.districtCode,P=E.street,m=E.db;return m?v.createElement("div",{className:s("CityPicker",a)},v.createElement(I,{className:s(w),searchable:c,disabled:r,options:m.province.map(function(O){return{label:m[O],value:O}}),value:S||"",onChange:this.handleProvinceChange,popOverContainer:C,testIdBuilder:h==null?void 0:h.getChild("province")}),l&&m.city[S]&&m.city[S].length?v.createElement(I,{className:s(w),searchable:c,disabled:r,options:m.city[S].map(function(O){return{label:m[O],value:O}}),value:D||"",onChange:this.handleCityChange,popOverContainer:C,testIdBuilder:h==null?void 0:h.getChild("city")}):null,D&&d&&(!((i=(e=m.district[S])===null||e===void 0?void 0:e[D])===null||i===void 0)&&i.length)?v.createElement(I,{className:s(w),searchable:c,disabled:r,options:m.district[S][D].map(function(O){return{label:m[O],value:O}}),value:N||"",onChange:this.handleDistrictChange,popOverContainer:C,testIdBuilder:h==null?void 0:h.getChild("district")}):null,y&&S?v.createElement("input",b({className:s("CityPicker-input"),value:P||"",onChange:this.handleStreetChange,onBlur:this.handleStreetEnd,placeholder:f("City.street"),disabled:r},h==null?void 0:h.getChild("street").getTestId())):null):v.createElement(x,{show:!0,size:"sm",loadingConfig:p})},t.defaultProps={joinValues:!0,extractValue:!0,delimiter:",",allowCity:!0,allowDistrict:!0,allowStreet:!1},g([_,o("design:type",Function),o("design:paramtypes",[Object]),o("design:returntype",void 0)],t.prototype,"handleProvinceChange",null),g([_,o("design:type",Function),o("design:paramtypes",[Object]),o("design:returntype",void 0)],t.prototype,"handleCityChange",null),g([_,o("design:type",Function),o("design:paramtypes",[Object,Object]),o("design:returntype",void 0)],t.prototype,"handleDistrictChange",null),g([_,o("design:type",Function),o("design:paramtypes",[Object]),o("design:returntype",void 0)],t.prototype,"handleStreetChange",null),g([_,o("design:type",Function),o("design:paramtypes",[]),o("design:returntype",void 0)],t.prototype,"handleStreetEnd",null),g([_,o("design:type",Function),o("design:paramtypes",[Object]),o("design:returntype",void 0)],t.prototype,"syncIn",null),g([_,o("design:type",Function),o("design:paramtypes",[]),o("design:returntype",void 0)],t.prototype,"syncOut",null),t}(v.Component),H=B(T(G)),Q=function(u){j(t,u);function t(){var e=u!==null&&u.apply(this,arguments)||this;return e.state={db:null},e}return t.prototype.doAction=function(e,i,n){var s,a,r=this.props,l=r.resetValue,d=r.onChange,y=r.formStore,c=r.store,f=r.name,p=e==null?void 0:e.actionType;if(p==="clear")d("");else if(p==="reset"){var C=(a=R((s=y==null?void 0:y.pristine)!==null&&s!==void 0?s:c==null?void 0:c.pristine,f))!==null&&a!==void 0?a:l;d(C??"")}},t.prototype.handleChange=function(e){return z(this,void 0,void 0,function(){var i,n,s,a;return A(this,function(r){switch(r.label){case 0:return i=this.props,n=i.dispatchEvent,s=i.onChange,[4,n("change",$(this.props,{value:e},"value"))];case 1:return a=r.sent(),a!=null&&a.prevented?[2]:(s(e),[2])}})})},t.prototype.renderStatic=function(e){var i=this;e===void 0&&(e="");var n=this.props,s=n.value,a=n.delimiter,r=n.loadingConfig;if(!this.state.db)return V(function(p){i.setState({db:b(b({},p.default),{province:p.province,city:p.city,district:p.district})})}),v.createElement(x,{size:"sm",show:!0,loadingConfig:r});if(!s)return v.createElement(v.Fragment,null,e);var l=F({value:s,delimiter:a,db:this.state.db}),d=l.province,y=l.city,c=l.district,f=l.street;return v.createElement(v.Fragment,null,[d,y,c,f].filter(function(p){return!!p}).join(a))},t.prototype.render=function(){var e=this.props,i=e.value,n=e.allowCity,s=e.allowDistrict,a=e.extractValue,r=e.joinValues,l=e.allowStreet,d=e.disabled,y=e.searchable,c=e.env,f=e.mobileUI,p=e.popOverContainer,C=e.itemClassName,w=e.testIdBuilder;return f?v.createElement(M,{value:i,popOverContainer:c==null?void 0:c.getModalContainer,onChange:this.handleChange,allowCity:n,allowDistrict:s,extractValue:a,joinValues:r,allowStreet:l,disabled:d,mobileUI:f}):v.createElement(H,{itemClassName:C,popOverContainer:p||(c==null?void 0:c.getModalContainer),searchable:y,value:i,onChange:this.handleChange,allowCity:n,allowDistrict:s,extractValue:a,joinValues:r,allowStreet:l,disabled:d,testIdBuilder:w})},g([_,o("design:type",Function),o("design:paramtypes",[Object,Object,Boolean]),o("design:returntype",void 0)],t.prototype,"doAction",null),g([_,o("design:type",Function),o("design:paramtypes",[Object]),o("design:returntype",Promise)],t.prototype,"handleChange",null),g([U(),o("design:type",Function),o("design:paramtypes",[]),o("design:returntype",void 0)],t.prototype,"render",null),t}(v.Component),q=function(u){j(t,u);function t(){return u!==null&&u.apply(this,arguments)||this}return t=g([k({type:"input-city",sizeMutable:!1})],t),t}(Q);export{q as CheckboxControlRenderer,G as CityPicker,Q as LocationControl,H as default};
|