@ohos-ports/ikas-localized-address 1.0.0-beta.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.
@@ -0,0 +1 @@
1
+ function n(n,e,t,r){return new(t||(t=Promise))((function(o,a){function l(n){try{i(r.next(n))}catch(n){a(n)}}function c(n){try{i(r.throw(n))}catch(n){a(n)}}function i(n){var e;n.done?o(n.value):(e=n.value,e instanceof t?e:new t((function(n){n(e)}))).then(l,c)}i((r=r.apply(n,e||[])).next())}))}function e(n,e){var t,r,o,a,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(c){return function(i){return function(c){if(t)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(l=0)),l;)try{if(t=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return l.label++,{value:c[1],done:!1};case 5:l.label++,r=c[1],c=[0];continue;case 7:c=l.ops.pop(),l.trys.pop();continue;default:if(!(o=l.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){l=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){l.label=c[1];break}if(6===c[0]&&l.label<o[1]){l.label=o[1],o=c;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(c);break}o[2]&&l.ops.pop(),l.trys.pop();continue}c=e.call(n,l)}catch(n){c=[6,n],r=0}finally{t=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,i])}}}function t(n,e,t){if(t||2===arguments.length)for(var r,o=0,a=e.length;o<a;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return n.concat(r||Array.prototype.slice.call(e))}export{n as __awaiter,e as __generator,t as __spreadArray};
@@ -0,0 +1,5 @@
1
+ export declare class LocalizedAddressConfig {
2
+ private static cdnUrl;
3
+ static getCDNUrl(): string;
4
+ static setCDNUrl(url?: string): void;
5
+ }
@@ -0,0 +1 @@
1
+ var n=function(){function n(){}return n.getCDNUrl=function(){return this.cdnUrl},n.setCDNUrl=function(n){n&&(this.cdnUrl=n)},n.cdnUrl="https://eu.myikas.com/",n}();export{n as LocalizedAddressConfig};
@@ -0,0 +1,3 @@
1
+ export * from "./models/address";
2
+ export * from "./config";
3
+ export * from "./models/address/model";
package/build/index.js ADDED
@@ -0,0 +1 @@
1
+ export{LocalizedAddress}from"./models/address/index.js";export{LocalizedAddressConfig}from"./config.js";export{AddressFormItem,BillingFormItem,COUNTRY_FORMS_LOCALES,IkasAddressFormInputType,LocalizedAddressModel}from"./models/address/model.js";
@@ -0,0 +1,140 @@
1
+ import { AddressFormItem, BillingFormItem, AddressForm, IkasAddressFormFields } from "./model";
2
+ export interface LocalizedAddressConstructorData<T> {
3
+ currentLocale?: string;
4
+ currentCountry?: string;
5
+ invisibleAddressFields?: AddressFormItem[];
6
+ invisibleBillingFields?: BillingFormItem[];
7
+ validateAddressForm?: boolean;
8
+ validateBillingForm?: boolean;
9
+ customAddressFormSettings?: IkasAddressFormFields;
10
+ message: LocalizedAddressValidatorMessage<T>;
11
+ }
12
+ export type LocalizedAddressValidatorMessage<T> = {
13
+ requiredRule: ((item: AddressFormItem, model: T) => string) | string;
14
+ invalidRule: ((item: AddressFormItem, model: T) => string) | string;
15
+ phoneRule: ((item: AddressFormItem, model: T) => string) | string;
16
+ };
17
+ export declare class LocalizedAddress {
18
+ private _initialized;
19
+ private _currentLocale;
20
+ private _currentCountry;
21
+ private _invisibleAddressFields;
22
+ private _invisibleBillingFields;
23
+ private _address;
24
+ private _validateAddressForm?;
25
+ private _validateBillingForm?;
26
+ private _customAddressFormSettings?;
27
+ private _isErrorsVisible;
28
+ private _message;
29
+ private _localizedAddressModel;
30
+ constructor(data: LocalizedAddressConstructorData<AddressForm>);
31
+ waitUntilInitialized(): Promise<unknown>;
32
+ init(): Promise<void>;
33
+ get initialized(): boolean;
34
+ get address(): AddressForm;
35
+ get isErrorsVisible(): boolean;
36
+ get currentCountry(): string;
37
+ get addressFormat(): AddressFormItem[][];
38
+ get addressFormatIgnoreCountry(): AddressFormItem[][];
39
+ get billingFormat(): BillingFormItem[][];
40
+ get fieldSettings(): {
41
+ firstName: import("./model").AddressFormField;
42
+ lastName: import("./model").AddressFormField;
43
+ identityNumber: import("./model").AddressFormField;
44
+ addressLine1: import("./model").AddressFormField;
45
+ addressLine2: import("./model").AddressFormField;
46
+ postalCode: import("./model").AddressFormField;
47
+ country: import("./model").AddressFormField;
48
+ state: import("./model").AddressFormField;
49
+ city: import("./model").AddressFormField;
50
+ district: import("./model").AddressFormField;
51
+ region: import("./model").AddressFormField;
52
+ phone: import("./model").AddressFormField;
53
+ company: import("./model").AddressFormField;
54
+ taxOffice: import("./model").AddressFormField;
55
+ taxNumber: import("./model").AddressFormField;
56
+ } | undefined;
57
+ get fieldLabels(): import("./model").IkasAddressFormLabels | undefined;
58
+ get isFreeTextCity(): boolean | undefined;
59
+ get isFreeTextDistrict(): boolean | undefined;
60
+ changeCountry(country: string): void;
61
+ changeAddress(address: AddressForm): void;
62
+ changeValidateAddressForm(value: boolean): void;
63
+ changeValidateBillingForm(value: boolean): void;
64
+ changeInvisibleAddressFields(value: AddressFormItem[] | undefined): void;
65
+ changeInvisibleBillingFields(value: BillingFormItem[] | undefined): void;
66
+ changeCustomAddressFormSettings(value: IkasAddressFormFields | undefined): void;
67
+ validate(): void;
68
+ resetValidate(): void;
69
+ getPostalAddressFormat({ countryCode, address, isBillingAddress, identityNumberFormat, }: GetPostalAddressFormatParams): string[] | undefined;
70
+ get validationResult(): {
71
+ firstName: {
72
+ hasError: boolean;
73
+ message: string;
74
+ };
75
+ lastName: {
76
+ hasError: boolean;
77
+ message: string;
78
+ };
79
+ identityNumber: {
80
+ hasError: boolean;
81
+ message: string;
82
+ };
83
+ addressLine1: {
84
+ hasError: boolean;
85
+ message: string;
86
+ };
87
+ addressLine2: {
88
+ hasError: boolean;
89
+ message: string;
90
+ };
91
+ postalCode: {
92
+ hasError: boolean;
93
+ message: string;
94
+ };
95
+ country: {
96
+ hasError: boolean;
97
+ message: string;
98
+ };
99
+ state: {
100
+ hasError: boolean;
101
+ message: string;
102
+ };
103
+ city: {
104
+ hasError: boolean;
105
+ message: string;
106
+ };
107
+ district: {
108
+ hasError: boolean;
109
+ message: string;
110
+ };
111
+ region: {
112
+ hasError: boolean;
113
+ message: string;
114
+ };
115
+ phone: {
116
+ hasError: boolean;
117
+ message: string;
118
+ };
119
+ company: {
120
+ hasError: boolean;
121
+ message: string;
122
+ };
123
+ taxOffice: {
124
+ hasError: boolean;
125
+ message: string;
126
+ };
127
+ taxNumber: {
128
+ hasError: boolean;
129
+ message: string;
130
+ };
131
+ } | undefined;
132
+ get isValidAddress(): boolean;
133
+ }
134
+ type GetPostalAddressFormatParams = {
135
+ countryCode?: string;
136
+ address: AddressForm;
137
+ isBillingAddress?: boolean;
138
+ identityNumberFormat?: (x: string) => string;
139
+ };
140
+ export {};
@@ -0,0 +1 @@
1
+ import{__awaiter as e,__spreadArray as i,__generator as t}from"../../_virtual/_tslib.js";import{makeAutoObservable as s}from"mobx";import r from"lodash";import{AddressFormItem as n,BillingFormItem as o,LocalizedAddressModel as d}from"./model.js";var l=function(){function l(e){this._initialized=!1,this._isErrorsVisible=!1,this._currentLocale=e.currentLocale||"tr",this._currentCountry=e.currentCountry||"TR",this._invisibleAddressFields=e.invisibleAddressFields,this._invisibleBillingFields=e.invisibleBillingFields,this._address={firstName:"",lastName:"",identityNumber:"",addressLine1:"",addressLine2:"",postalCode:"",country:"",state:"",city:"",district:"",phone:"",company:"",taxOffice:"",taxNumber:""},this._validateAddressForm=void 0===e.validateAddressForm||e.validateAddressForm,this._validateBillingForm=void 0!==e.validateBillingForm&&e.validateBillingForm,this._customAddressFormSettings=e.customAddressFormSettings||{},this._message=e.message,this._localizedAddressModel=new d({currentLocale:this._currentLocale}),this.init(),s(this)}return l.prototype.waitUntilInitialized=function(){var e=this;return new Promise((function(i){var t=setInterval((function(){e.initialized&&(clearInterval(t),i(null))}),100)}))},l.prototype.init=function(){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,this._localizedAddressModel.waitUntilInitialized()];case 1:return e.sent(),this._initialized=!0,[2]}}))}))},Object.defineProperty(l.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"address",{get:function(){return this._address},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"isErrorsVisible",{get:function(){return this._isErrorsVisible},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"currentCountry",{get:function(){return this._currentCountry},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"addressFormat",{get:function(){return this._localizedAddressModel.getAddressFormat(this.currentCountry,this._invisibleAddressFields)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"addressFormatIgnoreCountry",{get:function(){return this._localizedAddressModel.getAddressFormatIgnoreCountry(this.currentCountry,this._invisibleAddressFields)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"billingFormat",{get:function(){return this._localizedAddressModel.getBillingFormat(this.currentCountry,this._invisibleBillingFields)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"fieldSettings",{get:function(){return this._localizedAddressModel.getFieldSettings({country:this.currentCountry,invisibleAddressFields:this._invisibleAddressFields,invisibleBillingFields:this._invisibleBillingFields,validateAddressForm:this._validateAddressForm,validateBillingForm:this._validateBillingForm,customAddressFormSettings:this._customAddressFormSettings})},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"fieldLabels",{get:function(){return this._localizedAddressModel.getFieldLabels(this.currentCountry)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"isFreeTextCity",{get:function(){return this._localizedAddressModel.isFreeTextCity(this.currentCountry)},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"isFreeTextDistrict",{get:function(){return this._localizedAddressModel.isFreeTextDistrict(this.currentCountry)},enumerable:!1,configurable:!0}),l.prototype.changeCountry=function(e){this._currentCountry=e},l.prototype.changeAddress=function(e){this._address=e},l.prototype.changeValidateAddressForm=function(e){this._validateAddressForm=e},l.prototype.changeValidateBillingForm=function(e){this._validateBillingForm=e},l.prototype.changeInvisibleAddressFields=function(e){this._invisibleAddressFields=e},l.prototype.changeInvisibleBillingFields=function(e){this._invisibleBillingFields=e},l.prototype.changeCustomAddressFormSettings=function(e){this._customAddressFormSettings=e},l.prototype.validate=function(){this._isErrorsVisible=!0},l.prototype.resetValidate=function(){this._isErrorsVisible=!1},l.prototype.getPostalAddressFormat=function(e){var t=e.countryCode,s=e.address,r=e.isBillingAddress,d=void 0!==r&&r,l=e.identityNumberFormat;if(t){var a=this._localizedAddressModel.getAddressFormat(t,[n.COUNTRY,n.PHONE]),u=this._localizedAddressModel.getBillingFormat(t),c=[],m=[];return i(i([],a,!0),[[n.COUNTRY]],!1).map((function(e){var i=e.map((function(e){return e===n.FIRSTNAME?s.firstName:e===n.LASTNAME?s.lastName:e===n.IDENTITY_NUMBER?l&&s.identityNumber?l(s.identityNumber||""):s.identityNumber:e===n.ADDRESS_LINE_1?s.addressLine1:e===n.ADDRESS_LINE_2?s.addressLine2:e===n.POSTAL_CODE?s.postalCode:e===n.COUNTRY?s.country:e===n.STATE?s.state:e===n.CITY?s.city:e===n.DISTRICT?s.district:e===n.REGION?s.region:null})).join(" ");i&&c.push(i)})),d&&u.map((function(e){var i=e.map((function(e){return e===o.COMPANY?s.company:e===o.TAX_NUMBER?s.taxNumber:e===o.TAX_OFFICE?s.taxOffice:null})).join(" ");i&&m.push(i)})),m.map((function(e,i){c.splice(1+i,0,e)})),c}},Object.defineProperty(l.prototype,"validationResult",{get:function(){var e=this,i=this._localizedAddressModel.getValidationResult({country:this.currentCountry,address:this.address,invisibleAddressFields:this._invisibleAddressFields,invisibleBillingFields:this._invisibleBillingFields,validateAddressForm:this._validateAddressForm,validateBillingForm:this._validateBillingForm,customAddressFormSettings:this._customAddressFormSettings});if(i)return r.mapValues(i,(function(i,t){return{hasError:e._isErrorsVisible&&i.hasError,message:e._isErrorsVisible&&i.hasError?t===n.PHONE?e._message.phoneRule?"string"==typeof e._message.phoneRule?e._message.phoneRule:e._message.phoneRule(t,e.address):"":i.isEmpty?"string"==typeof e._message.requiredRule?e._message.requiredRule:e._message.requiredRule(t,e.address):"string"==typeof e._message.invalidRule?e._message.invalidRule:e._message.invalidRule(t,e.address):""}}))},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"isValidAddress",{get:function(){return this._localizedAddressModel.isValidAddress({country:this.currentCountry,address:this.address,invisibleAddressFields:this._invisibleAddressFields,invisibleBillingFields:this._invisibleBillingFields,validateAddressForm:this._validateAddressForm,validateBillingForm:this._validateBillingForm,customAddressFormSettings:this._customAddressFormSettings})},enumerable:!1,configurable:!0}),l}();export{l as LocalizedAddress};
@@ -0,0 +1,202 @@
1
+ export declare const COUNTRY_FORMS_LOCALES: string[];
2
+ export interface LocalizedAddressModelConstructorData {
3
+ currentLocale: string;
4
+ }
5
+ export declare class LocalizedAddressModel {
6
+ private _initialized;
7
+ private _currentLocale;
8
+ private _addressFormCountrySettings;
9
+ private _addressFormCountryLabels;
10
+ constructor(data: LocalizedAddressModelConstructorData);
11
+ init(): Promise<void>;
12
+ get initialized(): boolean;
13
+ waitUntilInitialized(): Promise<unknown>;
14
+ getFieldSettings(fieldSettingsParams: FieldSettingsParams): {
15
+ firstName: AddressFormField;
16
+ lastName: AddressFormField;
17
+ identityNumber: AddressFormField;
18
+ addressLine1: AddressFormField;
19
+ addressLine2: AddressFormField;
20
+ postalCode: AddressFormField;
21
+ country: AddressFormField;
22
+ state: AddressFormField;
23
+ city: AddressFormField;
24
+ district: AddressFormField;
25
+ region: AddressFormField;
26
+ phone: AddressFormField;
27
+ company: AddressFormField;
28
+ taxOffice: AddressFormField;
29
+ taxNumber: AddressFormField;
30
+ } | undefined;
31
+ getFieldLabels(country: string): IkasAddressFormLabels | undefined;
32
+ getAddressFormat(country: string, invisibleFields?: AddressFormItem[]): AddressFormItem[][];
33
+ getBillingFormat(country: string, invisibleFields?: BillingFormItem[]): BillingFormItem[][];
34
+ getAddressFormatIgnoreCountry(country: string, invisibleFields?: AddressFormItem[]): AddressFormItem[][];
35
+ getValidationResult(validationResultParams: ValidationResultParams): {
36
+ firstName: ErrorType;
37
+ lastName: ErrorType;
38
+ identityNumber: ErrorType;
39
+ addressLine1: ErrorType;
40
+ addressLine2: ErrorType;
41
+ postalCode: ErrorType;
42
+ country: ErrorType;
43
+ state: ErrorType;
44
+ city: ErrorType;
45
+ district: ErrorType;
46
+ region: ErrorType;
47
+ phone: ErrorType;
48
+ company: ErrorType;
49
+ taxOffice: ErrorType;
50
+ taxNumber: ErrorType;
51
+ } | undefined;
52
+ isValidAddress(validationResultParams: ValidationResultParams): boolean;
53
+ isValidField(value: string, fieldSettings: AddressFormField): ErrorType;
54
+ isFreeTextCity(country: string): boolean | undefined;
55
+ isFreeTextDistrict(country: string): boolean | undefined;
56
+ getCountrySettings(country: string): IkasAddressFormCountrySettings;
57
+ getCountryLabels(country: string): IkasAddressFormCountryLabels;
58
+ getAddressFormatView(addressFormat: string): AddressFormItem[][];
59
+ getBillingFormatView(billingFormat: string): BillingFormItem[][];
60
+ getAddressFormCountrySettings(): Promise<void>;
61
+ getAddressFormCountryLabels(): Promise<void>;
62
+ private getAddressFormSetting;
63
+ private getBillingFormSetting;
64
+ private getAddressFormLabel;
65
+ private validateByRegexString;
66
+ }
67
+ type FieldSettingsParams = {
68
+ country: string;
69
+ invisibleAddressFields?: AddressFormItem[];
70
+ invisibleBillingFields?: BillingFormItem[];
71
+ validateAddressForm?: boolean;
72
+ validateBillingForm?: boolean;
73
+ customAddressFormSettings?: CustomAddressFormSettings;
74
+ };
75
+ type ValidationResultParams = {
76
+ address: AddressForm;
77
+ } & FieldSettingsParams;
78
+ export type CustomAddressFormSettings = {
79
+ firstName?: AddressFormFieldSettings;
80
+ lastName?: AddressFormFieldSettings;
81
+ identityNumber?: AddressFormFieldSettings;
82
+ addressLine1?: AddressFormFieldSettings;
83
+ addressLine2?: AddressFormFieldSettings;
84
+ postalCode?: AddressFormFieldSettings;
85
+ country?: AddressFormFieldSettings;
86
+ state?: AddressFormFieldSettings;
87
+ city?: AddressFormFieldSettings;
88
+ district?: AddressFormFieldSettings;
89
+ region?: AddressFormFieldSettings;
90
+ phone?: AddressFormFieldSettings;
91
+ company?: AddressFormFieldSettings;
92
+ taxOffice?: AddressFormFieldSettings;
93
+ taxNumber?: AddressFormFieldSettings;
94
+ };
95
+ export type AddressFormFieldSettings = {
96
+ required?: boolean;
97
+ type?: IkasAddressFormInputType;
98
+ regex?: string;
99
+ };
100
+ export type ErrorType = {
101
+ hasError: boolean;
102
+ isInvalid: boolean;
103
+ isEmpty: boolean;
104
+ };
105
+ export type AddressForm = {
106
+ firstName?: string;
107
+ lastName?: string;
108
+ identityNumber?: string;
109
+ addressLine1?: string;
110
+ addressLine2?: string;
111
+ postalCode?: string;
112
+ country?: string;
113
+ state?: string;
114
+ city?: string;
115
+ district?: string;
116
+ region?: string;
117
+ phone?: string;
118
+ company?: string;
119
+ taxOffice?: string;
120
+ taxNumber?: string;
121
+ };
122
+ export type IkasAddressFormCountrySettings = {
123
+ id: string;
124
+ addressFormat: string;
125
+ billingFormat: string;
126
+ code: string;
127
+ iso2: string;
128
+ iso3: string;
129
+ phoneCode: string;
130
+ fields: IkasAddressFormFields;
131
+ };
132
+ export type IkasAddressFormFields = {
133
+ firstName?: AddressFormField;
134
+ lastName?: AddressFormField;
135
+ identityNumber?: AddressFormField;
136
+ addressLine1?: AddressFormField;
137
+ addressLine2?: AddressFormField;
138
+ postalCode?: AddressFormField;
139
+ country?: AddressFormField;
140
+ state?: AddressFormField;
141
+ city?: AddressFormField;
142
+ district?: AddressFormField;
143
+ region?: AddressFormField;
144
+ phone?: AddressFormField;
145
+ company?: AddressFormField;
146
+ taxOffice?: AddressFormField;
147
+ taxNumber?: AddressFormField;
148
+ };
149
+ export type AddressFormField = {
150
+ required: boolean;
151
+ type?: IkasAddressFormInputType;
152
+ regex?: string;
153
+ };
154
+ export declare enum IkasAddressFormInputType {
155
+ TEXT = "text",
156
+ DROPDOWN = "dropdown"
157
+ }
158
+ export type IkasAddressFormCountryLabels = {
159
+ name: string;
160
+ fields: IkasAddressFormLabels;
161
+ };
162
+ export type IkasAddressFormLabels = {
163
+ firstName?: AddressFormLabel;
164
+ lastName?: AddressFormLabel;
165
+ identityNumber?: AddressFormLabel;
166
+ addressLine1?: AddressFormLabel;
167
+ addressLine2?: AddressFormLabel;
168
+ postalCode?: AddressFormLabel;
169
+ country?: AddressFormLabel;
170
+ state?: AddressFormLabel;
171
+ city?: AddressFormLabel;
172
+ district?: AddressFormLabel;
173
+ region?: AddressFormLabel;
174
+ phone?: AddressFormLabel;
175
+ company?: AddressFormLabel;
176
+ taxOffice?: AddressFormLabel;
177
+ taxNumber?: AddressFormLabel;
178
+ };
179
+ export type AddressFormLabel = {
180
+ placeholder?: string;
181
+ label?: string;
182
+ };
183
+ export declare enum AddressFormItem {
184
+ FIRSTNAME = "firstName",
185
+ LASTNAME = "lastName",
186
+ IDENTITY_NUMBER = "identityNumber",
187
+ ADDRESS_LINE_1 = "addressLine1",
188
+ ADDRESS_LINE_2 = "addressLine2",
189
+ POSTAL_CODE = "postalCode",
190
+ COUNTRY = "country",
191
+ STATE = "state",
192
+ CITY = "city",
193
+ DISTRICT = "district",
194
+ REGION = "region",
195
+ PHONE = "phone"
196
+ }
197
+ export declare enum BillingFormItem {
198
+ COMPANY = "company",
199
+ TAX_OFFICE = "taxOffice",
200
+ TAX_NUMBER = "taxNumber"
201
+ }
202
+ export {};
@@ -0,0 +1 @@
1
+ import{__awaiter as e,__spreadArray as i,__generator as t}from"../../_virtual/_tslib.js";import{makeAutoObservable as o}from"mobx";import r from"lodash";import{LocalizedAddressConfig as d}from"../../config.js";var n,l,s,a=["tr","de","en","it","es","fr","ru"],u=function(){function u(e){this._initialized=!1,this._currentLocale=e.currentLocale,this.init(),o(this)}return u.prototype.init=function(){return e(this,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return[4,this.getAddressFormCountrySettings()];case 1:return e.sent(),[4,this.getAddressFormCountryLabels()];case 2:return e.sent(),this._initialized=!0,[2]}}))}))},Object.defineProperty(u.prototype,"initialized",{get:function(){return this._initialized},enumerable:!1,configurable:!0}),u.prototype.waitUntilInitialized=function(){var e=this;return new Promise((function(i){var t=setInterval((function(){e.initialized&&(clearInterval(t),i(null))}),100)}))},u.prototype.getFieldSettings=function(e){var i,t,o,r,d,n,a,u,v,c,g,m,p,h,y,f,F,b,N,A,L,x,S,C,E,T,O,_,I,R,V,B,q,D,w,M,P,U,Y,j,X,z=e.country,G=e.invisibleAddressFields,H=void 0===G?[]:G,k=e.invisibleBillingFields,W=void 0===k?[]:k,$=e.validateAddressForm,J=void 0===$||$,K=e.validateBillingForm,Q=void 0!==K&&K,Z=e.customAddressFormSettings,ee=void 0===Z?{}:Z,ie=this.getCountrySettings(z);if(ie){var te=ie.fields,oe=this.getAddressFormat(z),re=this.getBillingFormat(z);return{firstName:this.getAddressFormSetting(!0,null===(i=te.firstName)||void 0===i?void 0:i.type,null===(t=te.firstName)||void 0===t?void 0:t.regex,l.FIRSTNAME,oe,H,J,null==ee?void 0:ee.firstName),lastName:this.getAddressFormSetting(!0,null===(o=te.lastName)||void 0===o?void 0:o.type,null===(r=te.lastName)||void 0===r?void 0:r.regex,l.LASTNAME,oe,H,J,null==ee?void 0:ee.lastName),identityNumber:this.getAddressFormSetting(null===(d=te.identityNumber)||void 0===d?void 0:d.required,null===(n=te.identityNumber)||void 0===n?void 0:n.type,null===(a=te.identityNumber)||void 0===a?void 0:a.regex,l.IDENTITY_NUMBER,oe,H,J,null==ee?void 0:ee.identityNumber),addressLine1:this.getAddressFormSetting(!0,null===(u=te.addressLine1)||void 0===u?void 0:u.type,null===(v=te.addressLine1)||void 0===v?void 0:v.regex,l.ADDRESS_LINE_1,oe,H,J,null==ee?void 0:ee.addressLine1),addressLine2:this.getAddressFormSetting(null===(c=te.addressLine2)||void 0===c?void 0:c.required,null===(g=te.addressLine2)||void 0===g?void 0:g.type,null===(m=te.addressLine2)||void 0===m?void 0:m.regex,l.ADDRESS_LINE_2,oe,H,J,null==ee?void 0:ee.addressLine2),postalCode:this.getAddressFormSetting(null===(p=te.postalCode)||void 0===p?void 0:p.required,null===(h=te.postalCode)||void 0===h?void 0:h.type,null===(y=te.postalCode)||void 0===y?void 0:y.regex,l.POSTAL_CODE,oe,H,J,null==ee?void 0:ee.postalCode),country:this.getAddressFormSetting(!0,null===(f=te.country)||void 0===f?void 0:f.type,null===(F=te.country)||void 0===F?void 0:F.regex,l.COUNTRY,oe,H,J,null==ee?void 0:ee.country),state:this.getAddressFormSetting(null===(b=te.state)||void 0===b?void 0:b.required,null===(N=te.state)||void 0===N?void 0:N.type,null===(A=te.state)||void 0===A?void 0:A.regex,l.STATE,oe,H,J,null==ee?void 0:ee.state),city:this.getAddressFormSetting(null===(L=te.city)||void 0===L?void 0:L.required,null===(x=te.city)||void 0===x?void 0:x.type,null===(S=te.city)||void 0===S?void 0:S.regex,l.CITY,oe,H,J,null==ee?void 0:ee.city),district:this.getAddressFormSetting(null===(C=te.district)||void 0===C?void 0:C.required,null===(E=te.district)||void 0===E?void 0:E.type,null===(T=te.district)||void 0===T?void 0:T.regex,l.DISTRICT,oe,H,J,null==ee?void 0:ee.district),region:this.getAddressFormSetting(null===(O=te.region)||void 0===O?void 0:O.required,null===(_=te.region)||void 0===_?void 0:_.type,null===(I=te.region)||void 0===I?void 0:I.regex,l.REGION,oe,H,J,null==ee?void 0:ee.region),phone:this.getAddressFormSetting(null===(R=te.phone)||void 0===R?void 0:R.required,null===(V=te.phone)||void 0===V?void 0:V.type,(null===(B=te.phone)||void 0===B?void 0:B.regex)||/^\+?\d{10,}$/,l.PHONE,oe,H,J,null==ee?void 0:ee.phone),company:this.getBillingFormSetting(null===(q=te.company)||void 0===q?void 0:q.required,null===(D=te.company)||void 0===D?void 0:D.type,null===(w=te.company)||void 0===w?void 0:w.regex,s.COMPANY,re,W,Q,null==ee?void 0:ee.company),taxOffice:this.getBillingFormSetting(null===(M=te.taxOffice)||void 0===M?void 0:M.required,null===(P=te.taxOffice)||void 0===P?void 0:P.type,null===(U=te.taxOffice)||void 0===U?void 0:U.regex,s.TAX_OFFICE,re,W,Q,null==ee?void 0:ee.taxOffice),taxNumber:this.getBillingFormSetting(null===(Y=te.taxNumber)||void 0===Y?void 0:Y.required,null===(j=te.taxNumber)||void 0===j?void 0:j.type,null===(X=te.taxNumber)||void 0===X?void 0:X.regex,s.TAX_NUMBER,re,W,Q,null==ee?void 0:ee.taxNumber)}}},u.prototype.getFieldLabels=function(e){var i,t,o,r,d,n,l,s,a,u,v,c,g,m,p,h,y,f,F,b,N,A,L,x,S,C,E,T,O=this.getCountryLabels(e);if(O){var _=O.fields;return{firstName:this.getAddressFormLabel(null===(i=_.firstName)||void 0===i?void 0:i.label,null===(t=_.firstName)||void 0===t?void 0:t.placeholder),lastName:this.getAddressFormLabel(null===(o=_.lastName)||void 0===o?void 0:o.label,null===(r=_.lastName)||void 0===r?void 0:r.placeholder),identityNumber:this.getAddressFormLabel(null===(d=_.identityNumber)||void 0===d?void 0:d.label,null===(n=_.identityNumber)||void 0===n?void 0:n.placeholder),addressLine1:this.getAddressFormLabel(null===(l=_.addressLine1)||void 0===l?void 0:l.label,null===(s=_.addressLine1)||void 0===s?void 0:s.placeholder),addressLine2:this.getAddressFormLabel(null===(a=_.addressLine2)||void 0===a?void 0:a.label,null===(u=_.addressLine2)||void 0===u?void 0:u.placeholder),postalCode:this.getAddressFormLabel(null===(v=_.postalCode)||void 0===v?void 0:v.label,null===(c=_.postalCode)||void 0===c?void 0:c.placeholder),country:this.getAddressFormLabel(null===(g=_.country)||void 0===g?void 0:g.label,null===(m=_.country)||void 0===m?void 0:m.placeholder),state:this.getAddressFormLabel(null===(p=_.state)||void 0===p?void 0:p.label,null===(h=_.state)||void 0===h?void 0:h.placeholder),city:this.getAddressFormLabel(null===(y=_.city)||void 0===y?void 0:y.label,null===(f=_.city)||void 0===f?void 0:f.placeholder),district:this.getAddressFormLabel(null===(F=_.district)||void 0===F?void 0:F.label,null===(b=_.district)||void 0===b?void 0:b.placeholder),phone:this.getAddressFormLabel(null===(N=_.phone)||void 0===N?void 0:N.label,null===(A=_.phone)||void 0===A?void 0:A.placeholder),company:this.getAddressFormLabel(null===(L=_.company)||void 0===L?void 0:L.label,null===(x=_.company)||void 0===x?void 0:x.placeholder),taxOffice:this.getAddressFormLabel(null===(S=_.taxOffice)||void 0===S?void 0:S.label,null===(C=_.taxOffice)||void 0===C?void 0:C.placeholder),taxNumber:this.getAddressFormLabel(null===(E=_.taxNumber)||void 0===E?void 0:E.label,null===(T=_.taxNumber)||void 0===T?void 0:T.placeholder)}}},u.prototype.getAddressFormat=function(e,i){var t=this.getCountrySettings(e),o=this.getAddressFormatView(t.addressFormat),d=[];return o&&i&&i.length&&o.map((function(e){return r.difference(e,i)})).map((function(e){e.length>0&&d.push(e)})),i&&i.length?d:o},u.prototype.getBillingFormat=function(e,i){var t=this.getCountrySettings(e),o=this.getBillingFormatView(t.billingFormat),d=[];return o&&i&&i.length&&o.map((function(e){return r.difference(e,i)})).map((function(e){e.length>0&&d.push(e)})),i&&i.length?d:o},u.prototype.getAddressFormatIgnoreCountry=function(e,t){return this.getAddressFormat(e,i(i([],t||[],!0),[l.COUNTRY],!1))},u.prototype.getValidationResult=function(e){var i=e.address,t=e.country,o=e.invisibleAddressFields,r=e.invisibleBillingFields,d=e.validateAddressForm,n=e.validateBillingForm,l=e.customAddressFormSettings,s=this.getFieldSettings({country:t,invisibleAddressFields:o,invisibleBillingFields:r,validateAddressForm:d,validateBillingForm:n,customAddressFormSettings:l});if(s)return{firstName:this.isValidField(i.firstName||"",s.firstName),lastName:this.isValidField(i.lastName||"",s.lastName),identityNumber:this.isValidField(i.identityNumber||"",s.identityNumber),addressLine1:this.isValidField(i.addressLine1||"",s.addressLine1),addressLine2:this.isValidField(i.addressLine2||"",s.addressLine2),postalCode:this.isValidField(i.postalCode||"",s.postalCode),country:this.isValidField(i.country||"",s.country),state:this.isValidField(i.state||"",s.state),city:this.isValidField(i.city||"",s.city),district:this.isValidField(i.district||"",s.district),region:this.isValidField(i.region||"",s.region),phone:this.isValidField(i.phone||"",s.phone),company:this.isValidField(i.company||"",s.company),taxOffice:this.isValidField(i.taxOffice||"",s.taxOffice),taxNumber:this.isValidField(i.taxNumber||"",s.taxNumber)}},u.prototype.isValidAddress=function(e){var i=this.getValidationResult(e);return!!i&&Object.values(i).every((function(e){return!e.hasError}))},u.prototype.isValidField=function(e,i){var t=!1,o=!1,r=i.required||!1,d=i.regex||!1;return r&&!d&&(o=!e),r&&d&&(o=!e,t=!this.validateByRegexString(e,i.regex)),!r&&d&&e&&(t=!this.validateByRegexString(e,i.regex)),{hasError:t||o,isInvalid:t,isEmpty:o}},u.prototype.isFreeTextCity=function(e){var i=this.getFieldSettings({country:e});return i&&i.city&&i.city.type===n.TEXT},u.prototype.isFreeTextDistrict=function(e){var i=this.getFieldSettings({country:e});return i&&i.district&&i.district.type===n.TEXT},u.prototype.getCountrySettings=function(e){return this._addressFormCountrySettings.countrySettings[e]},u.prototype.getCountryLabels=function(e){return this._addressFormCountryLabels.countryLabels[e]},u.prototype.getAddressFormatView=function(e){return this._addressFormCountrySettings.addressFormats[e]},u.prototype.getBillingFormatView=function(e){return this._addressFormCountrySettings.billingFormats[e]},u.prototype.getAddressFormCountrySettings=function(){return e(this,void 0,void 0,(function(){var e,i;return t(this,(function(t){switch(t.label){case 0:return e=d.getCDNUrl()+"sf/static/location/settings.json",[4,fetch(e)];case 1:return[4,t.sent().json()];case 2:return i=t.sent(),this._addressFormCountrySettings=i,[2]}}))}))},u.prototype.getAddressFormCountryLabels=function(){return e(this,void 0,void 0,(function(){var e,i,o=this;return t(this,(function(t){switch(t.label){case 0:return a.find((function(e){return e===o._currentLocale}))||(this._currentLocale="en"),e="https://eu.myikas.com/sf/static/location/".concat(this._currentLocale,".json"),[4,fetch(e)];case 1:return[4,t.sent().json()];case 2:return i=t.sent(),this._addressFormCountryLabels=i,[2]}}))}))},u.prototype.getAddressFormSetting=function(e,i,t,o,r,d,n,l){var s=(d||[]).some((function(e){return e===o}))||!(r||[]).some((function(e){return e.some((function(e){return e===o}))}));return{required:!!n&&(!s&&(void 0===(null==l?void 0:l.required)?e||!1:null==l?void 0:l.required)),type:void 0===(null==l?void 0:l.type)?i:null==l?void 0:l.type,regex:n?s?void 0:void 0===(null==l?void 0:l.regex)?t:null==l?void 0:l.regex:void 0}},u.prototype.getBillingFormSetting=function(e,i,t,o,r,d,n,l){var s=(d||[]).some((function(e){return e===o}))||!(r||[]).some((function(e){return e.some((function(e){return e===o}))}));return{required:!!n&&(!s&&(void 0===(null==l?void 0:l.required)?e||!1:null==l?void 0:l.required)),type:void 0===(null==l?void 0:l.type)?i:null==l?void 0:l.type,regex:n?s?void 0:void 0===(null==l?void 0:l.regex)?t:null==l?void 0:l.regex:void 0}},u.prototype.getAddressFormLabel=function(e,i){return{label:e,placeholder:i}},u.prototype.validateByRegexString=function(e,i){return new RegExp(i).test(e)},u}();!function(e){e.TEXT="text",e.DROPDOWN="dropdown"}(n||(n={})),function(e){e.FIRSTNAME="firstName",e.LASTNAME="lastName",e.IDENTITY_NUMBER="identityNumber",e.ADDRESS_LINE_1="addressLine1",e.ADDRESS_LINE_2="addressLine2",e.POSTAL_CODE="postalCode",e.COUNTRY="country",e.STATE="state",e.CITY="city",e.DISTRICT="district",e.REGION="region",e.PHONE="phone"}(l||(l={})),function(e){e.COMPANY="company",e.TAX_OFFICE="taxOffice",e.TAX_NUMBER="taxNumber"}(s||(s={}));export{l as AddressFormItem,s as BillingFormItem,a as COUNTRY_FORMS_LOCALES,n as IkasAddressFormInputType,u as LocalizedAddressModel};
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@ohos-ports/ikas-localized-address",
3
+ "version": "1.0.0-beta.0",
4
+ "author": "ikas",
5
+ "license": "ISC",
6
+ "description": "Localized address model. (HarmonyOS / openharmony port of @ikas/localized-address)",
7
+ "main": "./build/index.js",
8
+ "module": "./build/index.js",
9
+ "files": [
10
+ "build"
11
+ ],
12
+ "type": "module",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/ohos-ports/ohos-ports.git",
16
+ "directory": "ports/ikas-localized-address/1.0.0"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
20
+ },
21
+ "keywords": ["harmonyos", "openharmony", "ohos-ports", "localized-address", "ikas"],
22
+ "scripts": {
23
+ "lint": "eslint *.ts*"
24
+ },
25
+ "peerDependencies": {
26
+ "lodash": "^4.17.21",
27
+ "mobx": "^6.1.3",
28
+ "mobx-react-lite": "^3.1.5"
29
+ }
30
+ }