@elderbyte/ngx-starter 20.4.7 → 20.4.9

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.
@@ -2036,54 +2036,54 @@ class PhoneFormatService {
2036
2036
  * Public API *
2037
2037
  * *
2038
2038
  **************************************************************************/
2039
- formatPhoneNumber(number, countryCode, config) {
2040
- if (!config || !config.dialingCode) {
2041
- return this.handleWithoutConfig(number, countryCode);
2042
- }
2043
- else {
2044
- return this.applyFormattingPerConfig(number, config);
2039
+ formatPhoneNumber(nr, config) {
2040
+ if (!config?.countryCode) {
2041
+ return nr;
2045
2042
  }
2043
+ const phoneNrBody = this.preparePhoneNumberBody(nr, config);
2044
+ const transformedBody = this.applyRegexTransform(phoneNrBody, config);
2045
+ return this.addPrefix(transformedBody, config);
2046
2046
  }
2047
2047
  /***************************************************************************
2048
2048
  * *
2049
2049
  * Private Methods *
2050
2050
  * *
2051
2051
  **************************************************************************/
2052
- applyFormattingPerConfig(number, config) {
2053
- let phoneNrBody = this.preparePhoneNumberBody(number, config);
2054
- if (config.bodyFormat) {
2055
- const [regex, format] = config.bodyFormat;
2056
- phoneNrBody = phoneNrBody.replace(regex, format);
2052
+ addPrefix(body, config) {
2053
+ let prefix = '';
2054
+ if (config.customPrefix !== undefined && config.customPrefix !== null) {
2055
+ prefix = config.customPrefix;
2056
+ }
2057
+ else {
2058
+ prefix = config.countryCode + ' ';
2057
2059
  }
2058
- const prefix = config.customPrefix ?? `${config.dialingCode} `;
2059
- return `${prefix}${phoneNrBody}`;
2060
+ return `${prefix}${body}`;
2060
2061
  }
2061
2062
  preparePhoneNumberBody(number, config) {
2062
2063
  const clean = this.cleanNumberString(number);
2063
- const withoutDialingCode = this.removeDialingCode(clean, config.dialingCode);
2064
- return withoutDialingCode.replace(/^0+/, ''); // remove leading zeros
2064
+ const withoutDialingCode = this.removeDialingCode(clean, config.countryCode);
2065
+ const withoutLeadingZeros = withoutDialingCode.replace(/^0+/, '');
2066
+ return withoutLeadingZeros;
2065
2067
  }
2066
2068
  cleanNumberString(number) {
2067
- const regex = /[^0-9+]/g; //
2068
- return number.replace(regex, '');
2069
- }
2070
- handleWithoutConfig(number, countryCode) {
2071
- if (!countryCode) {
2072
- return number;
2073
- }
2074
- else {
2075
- return countryCode + ' ' + number;
2076
- }
2069
+ return number.replace(/[^0-9+]/g, '');
2077
2070
  }
2078
- removeDialingCode(phoneNr, dialingCode) {
2079
- const dialingCodeWithDoubleZero = dialingCode.replace('+', '00');
2080
- for (const prefix of [dialingCode, dialingCodeWithDoubleZero]) {
2071
+ removeDialingCode(phoneNr, countryCode) {
2072
+ const dialingCodeWithDoubleZero = countryCode.replace('+', '00');
2073
+ for (const prefix of [countryCode, dialingCodeWithDoubleZero]) {
2081
2074
  if (phoneNr.startsWith(prefix)) {
2082
2075
  return phoneNr.slice(prefix.length);
2083
2076
  }
2084
2077
  }
2085
2078
  return phoneNr;
2086
2079
  }
2080
+ applyRegexTransform(phoneNrBody, config) {
2081
+ if (!config?.bodyFormat) {
2082
+ return phoneNrBody;
2083
+ }
2084
+ const [regex, format] = config.bodyFormat;
2085
+ return phoneNrBody.replace(regex, format);
2086
+ }
2087
2087
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: PhoneFormatService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
2088
2088
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: PhoneFormatService, providedIn: 'root' }); }
2089
2089
  }
@@ -2099,48 +2099,59 @@ class CountryPhoneFormatService {
2099
2099
  this.countryPhoneFormats = {
2100
2100
  '+41': {
2101
2101
  country: 'CH',
2102
- dialingCode: '+41',
2103
- bodyFormat: [/^(\d{2})(\d{3})(\d{2})(\d{2})$/, '$1 $2 $3 $4'],
2104
- customPrefix: '0',
2105
- },
2106
- '0041': {
2107
- country: 'CH',
2108
- dialingCode: '+41',
2102
+ countryCode: '+41',
2109
2103
  bodyFormat: [/^(\d{2})(\d{3})(\d{2})(\d{2})$/, '$1 $2 $3 $4'],
2110
2104
  customPrefix: '0',
2111
2105
  },
2112
2106
  '+423': {
2113
2107
  country: 'LI',
2114
- dialingCode: '+423',
2108
+ countryCode: '+423',
2115
2109
  bodyFormat: [/^(\d{3})(\d{4})$/, '$1 $2'],
2116
2110
  },
2117
2111
  '+49': {
2118
2112
  country: 'DE',
2119
- dialingCode: '+49',
2113
+ countryCode: '+49',
2120
2114
  },
2121
2115
  '+43': {
2122
2116
  country: 'AT',
2123
- dialingCode: '+43',
2117
+ countryCode: '+43',
2124
2118
  },
2125
2119
  '+33': {
2126
2120
  country: 'FR',
2127
- dialingCode: '+33',
2121
+ countryCode: '+33',
2128
2122
  },
2129
2123
  '+44': {
2130
2124
  country: 'GB',
2131
- dialingCode: '+44',
2125
+ countryCode: '+44',
2132
2126
  },
2133
2127
  '+1': {
2134
2128
  country: 'US',
2135
- dialingCode: '+1',
2129
+ countryCode: '+1',
2136
2130
  },
2137
2131
  };
2138
2132
  }
2139
- getCountryPhoneFormat(dialingCode) {
2140
- return this.countryPhoneFormats[dialingCode] ?? null;
2133
+ /***************************************************************************
2134
+ * *
2135
+ * Public API *
2136
+ * *
2137
+ **************************************************************************/
2138
+ getCountryPhoneFormat(countryCode) {
2139
+ if (!countryCode) {
2140
+ return null;
2141
+ }
2142
+ const cleanedCode = countryCode.replace(/^00/, '+');
2143
+ if (this.countryPhoneFormats[cleanedCode]) {
2144
+ return this.countryPhoneFormats[cleanedCode];
2145
+ }
2146
+ return {
2147
+ country: null,
2148
+ countryCode: cleanedCode,
2149
+ bodyFormat: null,
2150
+ };
2141
2151
  }
2142
- getCountry(dialingCode) {
2143
- return this.countryPhoneFormats[dialingCode]?.country ?? null;
2152
+ getCountry(countryCode) {
2153
+ const countryFormat = this.countryPhoneFormats[countryCode];
2154
+ return countryFormat?.country || null;
2144
2155
  }
2145
2156
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: CountryPhoneFormatService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
2146
2157
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: CountryPhoneFormatService, providedIn: 'root' }); }
@@ -2158,8 +2169,13 @@ class PhonePipe {
2158
2169
  this.phoneFormat = inject(PhoneFormatService);
2159
2170
  }
2160
2171
  transform(phoneNumber) {
2161
- const countryPhoneFormat = this.countryPhoneFormats.getCountryPhoneFormat(phoneNumber.countryCode);
2162
- return this.phoneFormat.formatPhoneNumber(phoneNumber.number, phoneNumber.countryCode, countryPhoneFormat);
2172
+ if (phoneNumber) {
2173
+ const countryPhoneFormat = this.countryPhoneFormats.getCountryPhoneFormat(phoneNumber.countryCode);
2174
+ return this.phoneFormat.formatPhoneNumber(phoneNumber.number, countryPhoneFormat);
2175
+ }
2176
+ else {
2177
+ return '';
2178
+ }
2163
2179
  }
2164
2180
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: PhonePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
2165
2181
  static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "20.1.3", ngImport: i0, type: PhonePipe, isStandalone: true, name: "phone" }); }
@@ -25937,8 +25953,10 @@ class ElderMultiSelectBase extends ElderSelectBase {
25937
25953
  return valueLoadRequest$.pipe(map((loaded) => {
25938
25954
  loaded.forEach((v, k) => existing.set(k, v));
25939
25955
  return existing;
25940
- }), map((allValuesMap) => Array.from(allValuesMap.values())) // TODO Sort?
25941
- );
25956
+ }), map((allValuesMap) => {
25957
+ // Sort entities by id order
25958
+ return ids.map((id) => allValuesMap.get(id)).filter((entity) => !!entity);
25959
+ }));
25942
25960
  }
25943
25961
  else {
25944
25962
  this.logger.warn('Failed to select value by Ids: ' + ids + ' - DataContext not available.');
@@ -26353,7 +26371,7 @@ class ElderMultiSelectChipsComponent extends ElderMultiSelectBase {
26353
26371
  drop(event) {
26354
26372
  const reordered = [...this.entities];
26355
26373
  moveItemInArray(reordered, event.previousIndex, event.currentIndex);
26356
- this.entities = reordered;
26374
+ this.updateValueByEntities(reordered);
26357
26375
  }
26358
26376
  resolveChipValue(e1) {
26359
26377
  return this.getEntityId(e1);