@pallasoft/ps-input-components 1.10.0 → 1.11.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.
- package/dist/components/ps-cascader-input.d.ts +2 -1
- package/dist/components/ps-cascader-input.js +5 -4
- package/dist/components/ps-color-input.d.ts +2 -1
- package/dist/components/ps-color-input.js +3 -2
- package/dist/components/ps-combobox-input.d.ts +2 -1
- package/dist/components/ps-combobox-input.js +3 -2
- package/dist/components/ps-date-input.js +2 -1
- package/dist/components/ps-email-input.d.ts +3 -0
- package/dist/components/ps-email-input.js +17 -0
- package/dist/components/ps-multi-select-input.js +3 -2
- package/dist/components/ps-percent-input.d.ts +3 -0
- package/dist/components/ps-percent-input.js +16 -0
- package/dist/components/ps-phone-input.d.ts +14 -0
- package/dist/components/ps-phone-input.js +55 -0
- package/dist/components/ps-postal-code-input.d.ts +5 -0
- package/dist/components/ps-postal-code-input.js +14 -0
- package/dist/components/ps-required-mark.d.ts +4 -0
- package/dist/components/ps-required-mark.js +6 -0
- package/dist/components/ps-select-input.js +2 -1
- package/dist/components/ps-text-area-input.d.ts +1 -1
- package/dist/components/ps-text-area-input.js +2 -1
- package/dist/components/ps-text-input.js +2 -1
- package/dist/components/ps-url-input.d.ts +3 -0
- package/dist/components/ps-url-input.js +17 -0
- package/dist/constants/ps-phone-input-config.d.ts +10 -0
- package/dist/constants/ps-phone-input-config.js +13 -0
- package/dist/constants/ps-postal-code-formats.d.ts +5 -0
- package/dist/constants/ps-postal-code-formats.js +13 -0
- package/dist/constants/ps-text-format-config.d.ts +6 -0
- package/dist/constants/ps-text-format-config.js +9 -0
- package/dist/esm/components/ps-amount-input.js +10 -0
- package/dist/esm/components/ps-calendar-header.js +5 -0
- package/dist/esm/components/ps-cascader-input.js +45 -0
- package/dist/esm/components/ps-checkbox.js +7 -0
- package/dist/esm/components/ps-color-input.js +16 -0
- package/dist/esm/components/ps-color-picker.js +60 -0
- package/dist/esm/components/ps-combobox-input.js +10 -0
- package/dist/esm/components/ps-date-input.js +35 -0
- package/dist/esm/components/ps-dropdown.js +3 -0
- package/dist/esm/components/ps-email-input.js +13 -0
- package/dist/esm/components/ps-file-picker.js +27 -0
- package/dist/esm/components/ps-form-control.js +3 -0
- package/dist/esm/components/ps-multi-select-input.js +23 -0
- package/dist/esm/components/ps-percent-input.js +12 -0
- package/dist/esm/components/ps-phone-input.js +51 -0
- package/dist/esm/components/ps-postal-code-input.js +10 -0
- package/dist/esm/components/ps-required-mark.js +2 -0
- package/dist/esm/components/ps-select-input.js +22 -0
- package/dist/esm/components/ps-select-option-item.js +4 -0
- package/dist/esm/components/ps-text-area-input.js +4 -0
- package/dist/esm/components/ps-text-input.js +12 -0
- package/dist/esm/components/ps-toggle.js +3 -0
- package/dist/esm/components/ps-url-input.js +13 -0
- package/dist/esm/constants/ps-amount-input-config.js +7 -0
- package/dist/esm/constants/ps-color-input-config.js +13 -0
- package/dist/esm/constants/ps-date-input-config.js +8 -0
- package/dist/esm/constants/ps-phone-input-config.js +10 -0
- package/dist/esm/constants/ps-postal-code-formats.js +10 -0
- package/dist/esm/constants/ps-text-format-config.js +6 -0
- package/dist/esm/index.js +34 -0
- package/dist/esm/interfaces/color-hsv.js +1 -0
- package/dist/esm/interfaces/ps-highlight-part.js +1 -0
- package/dist/esm/interfaces/ps-phone-country-option.js +1 -0
- package/dist/esm/interfaces/ps-phone-display-data.js +1 -0
- package/dist/esm/interfaces/ps-postal-code-format.js +1 -0
- package/dist/esm/services/ps-amount-input-service.js +25 -0
- package/dist/esm/services/ps-cascader-service.js +22 -0
- package/dist/esm/services/ps-color-service.js +73 -0
- package/dist/esm/services/ps-combobox-input-service.js +6 -0
- package/dist/esm/services/ps-date-input-service.js +24 -0
- package/dist/esm/services/ps-phone-input-service.js +77 -0
- package/dist/esm/services/ps-postal-code-service.js +28 -0
- package/dist/esm/services/ps-select-input-service.js +8 -0
- package/dist/esm/services/ps-text-format-service.js +12 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +16 -0
- package/dist/interfaces/ps-highlight-part.d.ts +4 -0
- package/dist/interfaces/ps-highlight-part.js +2 -0
- package/dist/interfaces/ps-phone-country-option.d.ts +5 -0
- package/dist/interfaces/ps-phone-country-option.js +2 -0
- package/dist/interfaces/ps-phone-display-data.d.ts +4 -0
- package/dist/interfaces/ps-phone-display-data.js +2 -0
- package/dist/interfaces/ps-postal-code-format.d.ts +5 -0
- package/dist/interfaces/ps-postal-code-format.js +2 -0
- package/dist/services/ps-phone-input-service.d.ts +15 -0
- package/dist/services/ps-phone-input-service.js +81 -0
- package/dist/services/ps-postal-code-service.d.ts +4 -0
- package/dist/services/ps-postal-code-service.js +32 -0
- package/dist/services/ps-text-format-service.d.ts +4 -0
- package/dist/services/ps-text-format-service.js +16 -0
- package/package.json +6 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export class PsColorService {
|
|
2
|
+
static normaliseHex(value) {
|
|
3
|
+
const hex = value.trim().replace('#', '');
|
|
4
|
+
if (/^[0-9a-fA-F]{3}$/.test(hex))
|
|
5
|
+
return `#${hex
|
|
6
|
+
.split('')
|
|
7
|
+
.map((character) => character + character)
|
|
8
|
+
.join('')
|
|
9
|
+
.toUpperCase()}`;
|
|
10
|
+
return /^[0-9a-fA-F]{6}$/.test(hex) ? `#${hex.toUpperCase()}` : null;
|
|
11
|
+
}
|
|
12
|
+
static toHsv(value) {
|
|
13
|
+
const hex = PsColorService.normaliseHex(value);
|
|
14
|
+
if (!hex)
|
|
15
|
+
return { brightness: 100, hue: 0, saturation: 0 };
|
|
16
|
+
const red = parseInt(hex.slice(1, 3), 16) / 255;
|
|
17
|
+
const green = parseInt(hex.slice(3, 5), 16) / 255;
|
|
18
|
+
const blue = parseInt(hex.slice(5, 7), 16) / 255;
|
|
19
|
+
const max = Math.max(red, green, blue);
|
|
20
|
+
const min = Math.min(red, green, blue);
|
|
21
|
+
const delta = max - min;
|
|
22
|
+
let hue = 0;
|
|
23
|
+
if (delta !== 0) {
|
|
24
|
+
if (max === red)
|
|
25
|
+
hue = ((green - blue) / delta) % 6;
|
|
26
|
+
else if (max === green)
|
|
27
|
+
hue = (blue - red) / delta + 2;
|
|
28
|
+
else
|
|
29
|
+
hue = (red - green) / delta + 4;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
brightness: Math.round(max * 100),
|
|
33
|
+
hue: Math.round(((hue * 60) % 360) + (hue < 0 ? 360 : 0)),
|
|
34
|
+
saturation: Math.round((max === 0 ? 0 : delta / max) * 100),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
static toHex({ brightness, hue, saturation }) {
|
|
38
|
+
const value = brightness / 100;
|
|
39
|
+
const chroma = (saturation / 100) * value;
|
|
40
|
+
const second = chroma * (1 - Math.abs(((hue / 60) % 2) - 1));
|
|
41
|
+
const match = value - chroma;
|
|
42
|
+
const sector = Math.floor(hue / 60) % 6;
|
|
43
|
+
const channels = [
|
|
44
|
+
[chroma, second, 0],
|
|
45
|
+
[second, chroma, 0],
|
|
46
|
+
[0, chroma, second],
|
|
47
|
+
[0, second, chroma],
|
|
48
|
+
[second, 0, chroma],
|
|
49
|
+
[chroma, 0, second],
|
|
50
|
+
][sector];
|
|
51
|
+
return `#${channels
|
|
52
|
+
.map((channel) => Math.round((channel + match) * 255)
|
|
53
|
+
.toString(16)
|
|
54
|
+
.padStart(2, '0'))
|
|
55
|
+
.join('')
|
|
56
|
+
.toUpperCase()}`;
|
|
57
|
+
}
|
|
58
|
+
static readableTextOn(value) {
|
|
59
|
+
const hex = PsColorService.normaliseHex(value);
|
|
60
|
+
if (!hex)
|
|
61
|
+
return '#0F172A';
|
|
62
|
+
const channel = (part) => {
|
|
63
|
+
const normalised = part / 255;
|
|
64
|
+
return normalised <= 0.03928
|
|
65
|
+
? normalised / 12.92
|
|
66
|
+
: Math.pow((normalised + 0.055) / 1.055, 2.4);
|
|
67
|
+
};
|
|
68
|
+
const luminance = 0.2126 * channel(parseInt(hex.slice(1, 3), 16)) +
|
|
69
|
+
0.7152 * channel(parseInt(hex.slice(3, 5), 16)) +
|
|
70
|
+
0.0722 * channel(parseInt(hex.slice(5, 7), 16));
|
|
71
|
+
return 1.05 / (luminance + 0.05) >= 3 ? '#FFFFFF' : '#0F172A';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Common } from '@pallasoft/ps-utilities';
|
|
2
|
+
import { PsDateInputConfig } from '../constants/ps-date-input-config';
|
|
3
|
+
export class PsDateInputService {
|
|
4
|
+
static parse(value) {
|
|
5
|
+
if (value === undefined || value === '')
|
|
6
|
+
return null;
|
|
7
|
+
const date = Common.DateService.getDate(value);
|
|
8
|
+
return date.isValid() && date.format(PsDateInputConfig.valueFormat) === value
|
|
9
|
+
? date.toDate()
|
|
10
|
+
: null;
|
|
11
|
+
}
|
|
12
|
+
static parseBound(value) {
|
|
13
|
+
const date = PsDateInputService.parse(value);
|
|
14
|
+
return date === null ? undefined : date;
|
|
15
|
+
}
|
|
16
|
+
static format(date) {
|
|
17
|
+
return date === null
|
|
18
|
+
? ''
|
|
19
|
+
: Common.DateService.formatDate(date.getTime(), PsDateInputConfig.valueFormat);
|
|
20
|
+
}
|
|
21
|
+
static monthLabel(date) {
|
|
22
|
+
return Common.DateService.formatDate(date.getTime(), PsDateInputConfig.monthLabelFormat);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AsYouType, getCountries, getCountryCallingCode, parsePhoneNumberFromString, } from 'libphonenumber-js';
|
|
2
|
+
import { PsPhoneInputConfig } from '../constants/ps-phone-input-config';
|
|
3
|
+
export class PsPhoneInputService {
|
|
4
|
+
static isCountry(code) {
|
|
5
|
+
return getCountries().includes(code);
|
|
6
|
+
}
|
|
7
|
+
static countries(preferred) {
|
|
8
|
+
const names = new Intl.DisplayNames([PsPhoneInputConfig.locale], {
|
|
9
|
+
type: PsPhoneInputConfig.displayNamesType,
|
|
10
|
+
});
|
|
11
|
+
const options = getCountries().map((code) => {
|
|
12
|
+
const name = names.of(code);
|
|
13
|
+
return {
|
|
14
|
+
callingCode: getCountryCallingCode(code),
|
|
15
|
+
code,
|
|
16
|
+
label: name !== undefined ? name : code,
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
return options.sort((left, right) => {
|
|
20
|
+
if (left.code === preferred)
|
|
21
|
+
return -1;
|
|
22
|
+
if (right.code === preferred)
|
|
23
|
+
return 1;
|
|
24
|
+
return left.label.localeCompare(right.label);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
static display(value, fallbackCountry) {
|
|
28
|
+
const parsed = value.startsWith(PsPhoneInputConfig.plus)
|
|
29
|
+
? parsePhoneNumberFromString(value)
|
|
30
|
+
: undefined;
|
|
31
|
+
if (parsed !== undefined && parsed.country !== undefined)
|
|
32
|
+
return { country: parsed.country, national: parsed.formatNational() };
|
|
33
|
+
return { country: fallbackCountry, national: value };
|
|
34
|
+
}
|
|
35
|
+
static format(national, country) {
|
|
36
|
+
if (!PsPhoneInputService.isCountry(country))
|
|
37
|
+
return national;
|
|
38
|
+
return new AsYouType(country).input(national);
|
|
39
|
+
}
|
|
40
|
+
static toStored(national, country) {
|
|
41
|
+
const trimmed = national.trim();
|
|
42
|
+
if (trimmed === '' || !PsPhoneInputService.isCountry(country))
|
|
43
|
+
return trimmed;
|
|
44
|
+
const parsed = parsePhoneNumberFromString(trimmed, country);
|
|
45
|
+
return parsed !== undefined ? parsed.number : trimmed;
|
|
46
|
+
}
|
|
47
|
+
static isValid(national, country) {
|
|
48
|
+
if (national.trim() === '')
|
|
49
|
+
return true;
|
|
50
|
+
if (!PsPhoneInputService.isCountry(country))
|
|
51
|
+
return false;
|
|
52
|
+
const parsed = parsePhoneNumberFromString(national, country);
|
|
53
|
+
return parsed !== undefined && parsed.isValid();
|
|
54
|
+
}
|
|
55
|
+
static search(options, query) {
|
|
56
|
+
const term = query.trim().toLowerCase().replace(PsPhoneInputConfig.plus, '');
|
|
57
|
+
if (term === '')
|
|
58
|
+
return options;
|
|
59
|
+
return options.filter((option) => option.label.toLowerCase().includes(term) ||
|
|
60
|
+
option.code.toLowerCase() === term ||
|
|
61
|
+
option.callingCode.startsWith(term));
|
|
62
|
+
}
|
|
63
|
+
static highlight(label, query) {
|
|
64
|
+
const term = query.trim().toLowerCase();
|
|
65
|
+
const index = term === '' ? -1 : label.toLowerCase().indexOf(term);
|
|
66
|
+
if (index === -1)
|
|
67
|
+
return [{ isMatch: false, text: label }];
|
|
68
|
+
return [
|
|
69
|
+
{ isMatch: false, text: label.slice(0, index) },
|
|
70
|
+
{ isMatch: true, text: label.slice(index, index + term.length) },
|
|
71
|
+
{ isMatch: false, text: label.slice(index + term.length) },
|
|
72
|
+
].filter((part) => part.text !== '');
|
|
73
|
+
}
|
|
74
|
+
static callingCode(country) {
|
|
75
|
+
return PsPhoneInputService.isCountry(country) ? getCountryCallingCode(country) : '';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PsPostalCodeConfig, PsPostalCodeFormats } from '../constants/ps-postal-code-formats';
|
|
2
|
+
export class PsPostalCodeService {
|
|
3
|
+
static format(raw, country) {
|
|
4
|
+
const upper = raw.toUpperCase();
|
|
5
|
+
const format = PsPostalCodeFormats[country];
|
|
6
|
+
if (format === undefined)
|
|
7
|
+
return upper.replace(PsPostalCodeConfig.fallbackAllowed, '');
|
|
8
|
+
const compact = upper.replace(format.allowed, '');
|
|
9
|
+
if (format.groups.length === 0)
|
|
10
|
+
return upper.replace(PsPostalCodeConfig.fallbackAllowed, '');
|
|
11
|
+
const parts = [];
|
|
12
|
+
let cursor = 0;
|
|
13
|
+
for (const size of format.groups) {
|
|
14
|
+
if (cursor >= compact.length)
|
|
15
|
+
break;
|
|
16
|
+
parts.push(compact.slice(cursor, cursor + size));
|
|
17
|
+
cursor += size;
|
|
18
|
+
}
|
|
19
|
+
return parts.join(format.separator);
|
|
20
|
+
}
|
|
21
|
+
static maxLength(country) {
|
|
22
|
+
const format = PsPostalCodeFormats[country];
|
|
23
|
+
if (format === undefined || format.groups.length === 0)
|
|
24
|
+
return undefined;
|
|
25
|
+
return (format.groups.reduce((sum, size) => sum + size, 0) +
|
|
26
|
+
format.separator.length * (format.groups.length - 1));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export class PsSelectInputService {
|
|
2
|
+
static getDefaultValue(defaultValue, options) {
|
|
3
|
+
if (defaultValue !== null && defaultValue !== undefined)
|
|
4
|
+
return defaultValue;
|
|
5
|
+
const firstValue = options[0]?.value;
|
|
6
|
+
return firstValue !== null && firstValue !== undefined ? firstValue : '';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PsTextFormatConfig } from '../constants/ps-text-format-config';
|
|
2
|
+
export class PsTextFormatService {
|
|
3
|
+
static email(raw) {
|
|
4
|
+
return raw.replace(PsTextFormatConfig.whitespace, '').toLowerCase();
|
|
5
|
+
}
|
|
6
|
+
static url(raw) {
|
|
7
|
+
const trimmed = raw.trim();
|
|
8
|
+
if (trimmed === '' || PsTextFormatConfig.schemePattern.test(trimmed))
|
|
9
|
+
return trimmed;
|
|
10
|
+
return `${PsTextFormatConfig.httpsPrefix}${trimmed}`;
|
|
11
|
+
}
|
|
12
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,3 +16,19 @@ export * from './components/ps-toggle';
|
|
|
16
16
|
export * from './services/ps-amount-input-service';
|
|
17
17
|
export * from './services/ps-color-service';
|
|
18
18
|
export * from './interfaces/color-hsv';
|
|
19
|
+
export * from './components/ps-email-input';
|
|
20
|
+
export * from './components/ps-percent-input';
|
|
21
|
+
export * from './components/ps-phone-input';
|
|
22
|
+
export * from './components/ps-postal-code-input';
|
|
23
|
+
export * from './components/ps-url-input';
|
|
24
|
+
export * from './constants/ps-phone-input-config';
|
|
25
|
+
export * from './constants/ps-postal-code-formats';
|
|
26
|
+
export * from './constants/ps-text-format-config';
|
|
27
|
+
export * from './interfaces/ps-highlight-part';
|
|
28
|
+
export * from './interfaces/ps-phone-country-option';
|
|
29
|
+
export * from './interfaces/ps-phone-display-data';
|
|
30
|
+
export * from './interfaces/ps-postal-code-format';
|
|
31
|
+
export * from './services/ps-phone-input-service';
|
|
32
|
+
export * from './services/ps-postal-code-service';
|
|
33
|
+
export * from './services/ps-text-format-service';
|
|
34
|
+
export * from './components/ps-required-mark';
|
package/dist/index.js
CHANGED
|
@@ -32,3 +32,19 @@ __exportStar(require("./components/ps-toggle"), exports);
|
|
|
32
32
|
__exportStar(require("./services/ps-amount-input-service"), exports);
|
|
33
33
|
__exportStar(require("./services/ps-color-service"), exports);
|
|
34
34
|
__exportStar(require("./interfaces/color-hsv"), exports);
|
|
35
|
+
__exportStar(require("./components/ps-email-input"), exports);
|
|
36
|
+
__exportStar(require("./components/ps-percent-input"), exports);
|
|
37
|
+
__exportStar(require("./components/ps-phone-input"), exports);
|
|
38
|
+
__exportStar(require("./components/ps-postal-code-input"), exports);
|
|
39
|
+
__exportStar(require("./components/ps-url-input"), exports);
|
|
40
|
+
__exportStar(require("./constants/ps-phone-input-config"), exports);
|
|
41
|
+
__exportStar(require("./constants/ps-postal-code-formats"), exports);
|
|
42
|
+
__exportStar(require("./constants/ps-text-format-config"), exports);
|
|
43
|
+
__exportStar(require("./interfaces/ps-highlight-part"), exports);
|
|
44
|
+
__exportStar(require("./interfaces/ps-phone-country-option"), exports);
|
|
45
|
+
__exportStar(require("./interfaces/ps-phone-display-data"), exports);
|
|
46
|
+
__exportStar(require("./interfaces/ps-postal-code-format"), exports);
|
|
47
|
+
__exportStar(require("./services/ps-phone-input-service"), exports);
|
|
48
|
+
__exportStar(require("./services/ps-postal-code-service"), exports);
|
|
49
|
+
__exportStar(require("./services/ps-text-format-service"), exports);
|
|
50
|
+
__exportStar(require("./components/ps-required-mark"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type CountryCode } from 'libphonenumber-js';
|
|
2
|
+
import { PsHighlightPart } from '../interfaces/ps-highlight-part';
|
|
3
|
+
import { PsPhoneCountryOption } from '../interfaces/ps-phone-country-option';
|
|
4
|
+
import { PsPhoneDisplayData } from '../interfaces/ps-phone-display-data';
|
|
5
|
+
export declare class PsPhoneInputService {
|
|
6
|
+
static isCountry(code: string): code is CountryCode;
|
|
7
|
+
static countries(preferred: string): PsPhoneCountryOption[];
|
|
8
|
+
static display(value: string, fallbackCountry: string): PsPhoneDisplayData;
|
|
9
|
+
static format(national: string, country: string): string;
|
|
10
|
+
static toStored(national: string, country: string): string;
|
|
11
|
+
static isValid(national: string, country: string): boolean;
|
|
12
|
+
static search(options: PsPhoneCountryOption[], query: string): PsPhoneCountryOption[];
|
|
13
|
+
static highlight(label: string, query: string): PsHighlightPart[];
|
|
14
|
+
static callingCode(country: string): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsPhoneInputService = void 0;
|
|
4
|
+
const libphonenumber_js_1 = require("libphonenumber-js");
|
|
5
|
+
const ps_phone_input_config_1 = require("../constants/ps-phone-input-config");
|
|
6
|
+
class PsPhoneInputService {
|
|
7
|
+
static isCountry(code) {
|
|
8
|
+
return (0, libphonenumber_js_1.getCountries)().includes(code);
|
|
9
|
+
}
|
|
10
|
+
static countries(preferred) {
|
|
11
|
+
const names = new Intl.DisplayNames([ps_phone_input_config_1.PsPhoneInputConfig.locale], {
|
|
12
|
+
type: ps_phone_input_config_1.PsPhoneInputConfig.displayNamesType,
|
|
13
|
+
});
|
|
14
|
+
const options = (0, libphonenumber_js_1.getCountries)().map((code) => {
|
|
15
|
+
const name = names.of(code);
|
|
16
|
+
return {
|
|
17
|
+
callingCode: (0, libphonenumber_js_1.getCountryCallingCode)(code),
|
|
18
|
+
code,
|
|
19
|
+
label: name !== undefined ? name : code,
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
return options.sort((left, right) => {
|
|
23
|
+
if (left.code === preferred)
|
|
24
|
+
return -1;
|
|
25
|
+
if (right.code === preferred)
|
|
26
|
+
return 1;
|
|
27
|
+
return left.label.localeCompare(right.label);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
static display(value, fallbackCountry) {
|
|
31
|
+
const parsed = value.startsWith(ps_phone_input_config_1.PsPhoneInputConfig.plus)
|
|
32
|
+
? (0, libphonenumber_js_1.parsePhoneNumberFromString)(value)
|
|
33
|
+
: undefined;
|
|
34
|
+
if (parsed !== undefined && parsed.country !== undefined)
|
|
35
|
+
return { country: parsed.country, national: parsed.formatNational() };
|
|
36
|
+
return { country: fallbackCountry, national: value };
|
|
37
|
+
}
|
|
38
|
+
static format(national, country) {
|
|
39
|
+
if (!PsPhoneInputService.isCountry(country))
|
|
40
|
+
return national;
|
|
41
|
+
return new libphonenumber_js_1.AsYouType(country).input(national);
|
|
42
|
+
}
|
|
43
|
+
static toStored(national, country) {
|
|
44
|
+
const trimmed = national.trim();
|
|
45
|
+
if (trimmed === '' || !PsPhoneInputService.isCountry(country))
|
|
46
|
+
return trimmed;
|
|
47
|
+
const parsed = (0, libphonenumber_js_1.parsePhoneNumberFromString)(trimmed, country);
|
|
48
|
+
return parsed !== undefined ? parsed.number : trimmed;
|
|
49
|
+
}
|
|
50
|
+
static isValid(national, country) {
|
|
51
|
+
if (national.trim() === '')
|
|
52
|
+
return true;
|
|
53
|
+
if (!PsPhoneInputService.isCountry(country))
|
|
54
|
+
return false;
|
|
55
|
+
const parsed = (0, libphonenumber_js_1.parsePhoneNumberFromString)(national, country);
|
|
56
|
+
return parsed !== undefined && parsed.isValid();
|
|
57
|
+
}
|
|
58
|
+
static search(options, query) {
|
|
59
|
+
const term = query.trim().toLowerCase().replace(ps_phone_input_config_1.PsPhoneInputConfig.plus, '');
|
|
60
|
+
if (term === '')
|
|
61
|
+
return options;
|
|
62
|
+
return options.filter((option) => option.label.toLowerCase().includes(term) ||
|
|
63
|
+
option.code.toLowerCase() === term ||
|
|
64
|
+
option.callingCode.startsWith(term));
|
|
65
|
+
}
|
|
66
|
+
static highlight(label, query) {
|
|
67
|
+
const term = query.trim().toLowerCase();
|
|
68
|
+
const index = term === '' ? -1 : label.toLowerCase().indexOf(term);
|
|
69
|
+
if (index === -1)
|
|
70
|
+
return [{ isMatch: false, text: label }];
|
|
71
|
+
return [
|
|
72
|
+
{ isMatch: false, text: label.slice(0, index) },
|
|
73
|
+
{ isMatch: true, text: label.slice(index, index + term.length) },
|
|
74
|
+
{ isMatch: false, text: label.slice(index + term.length) },
|
|
75
|
+
].filter((part) => part.text !== '');
|
|
76
|
+
}
|
|
77
|
+
static callingCode(country) {
|
|
78
|
+
return PsPhoneInputService.isCountry(country) ? (0, libphonenumber_js_1.getCountryCallingCode)(country) : '';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.PsPhoneInputService = PsPhoneInputService;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsPostalCodeService = void 0;
|
|
4
|
+
const ps_postal_code_formats_1 = require("../constants/ps-postal-code-formats");
|
|
5
|
+
class PsPostalCodeService {
|
|
6
|
+
static format(raw, country) {
|
|
7
|
+
const upper = raw.toUpperCase();
|
|
8
|
+
const format = ps_postal_code_formats_1.PsPostalCodeFormats[country];
|
|
9
|
+
if (format === undefined)
|
|
10
|
+
return upper.replace(ps_postal_code_formats_1.PsPostalCodeConfig.fallbackAllowed, '');
|
|
11
|
+
const compact = upper.replace(format.allowed, '');
|
|
12
|
+
if (format.groups.length === 0)
|
|
13
|
+
return upper.replace(ps_postal_code_formats_1.PsPostalCodeConfig.fallbackAllowed, '');
|
|
14
|
+
const parts = [];
|
|
15
|
+
let cursor = 0;
|
|
16
|
+
for (const size of format.groups) {
|
|
17
|
+
if (cursor >= compact.length)
|
|
18
|
+
break;
|
|
19
|
+
parts.push(compact.slice(cursor, cursor + size));
|
|
20
|
+
cursor += size;
|
|
21
|
+
}
|
|
22
|
+
return parts.join(format.separator);
|
|
23
|
+
}
|
|
24
|
+
static maxLength(country) {
|
|
25
|
+
const format = ps_postal_code_formats_1.PsPostalCodeFormats[country];
|
|
26
|
+
if (format === undefined || format.groups.length === 0)
|
|
27
|
+
return undefined;
|
|
28
|
+
return (format.groups.reduce((sum, size) => sum + size, 0) +
|
|
29
|
+
format.separator.length * (format.groups.length - 1));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.PsPostalCodeService = PsPostalCodeService;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsTextFormatService = void 0;
|
|
4
|
+
const ps_text_format_config_1 = require("../constants/ps-text-format-config");
|
|
5
|
+
class PsTextFormatService {
|
|
6
|
+
static email(raw) {
|
|
7
|
+
return raw.replace(ps_text_format_config_1.PsTextFormatConfig.whitespace, '').toLowerCase();
|
|
8
|
+
}
|
|
9
|
+
static url(raw) {
|
|
10
|
+
const trimmed = raw.trim();
|
|
11
|
+
if (trimmed === '' || ps_text_format_config_1.PsTextFormatConfig.schemePattern.test(trimmed))
|
|
12
|
+
return trimmed;
|
|
13
|
+
return `${ps_text_format_config_1.PsTextFormatConfig.httpsPrefix}${trimmed}`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.PsTextFormatService = PsTextFormatService;
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pallasoft/ps-input-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
6
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
7
9
|
"exports": {
|
|
8
10
|
".": {
|
|
9
11
|
"types": "./dist/index.d.ts",
|
|
12
|
+
"module": "./dist/esm/index.js",
|
|
10
13
|
"require": "./dist/index.js",
|
|
11
14
|
"default": "./dist/index.js"
|
|
12
15
|
}
|
|
@@ -16,7 +19,7 @@
|
|
|
16
19
|
],
|
|
17
20
|
"scripts": {
|
|
18
21
|
"husky:prepare": "npx husky",
|
|
19
|
-
"build": "tsc",
|
|
22
|
+
"build": "tsc && tsc -p tsconfig.esm.json",
|
|
20
23
|
"setup:graphify": "sh scripts/graphify-setup.sh",
|
|
21
24
|
"update:graphify": "sh scripts/graphify-update.sh",
|
|
22
25
|
"lint": "npm run lint:eslint",
|
|
@@ -33,6 +36,7 @@
|
|
|
33
36
|
"@pallasoft/ps-design-system": "^1.3.0",
|
|
34
37
|
"@pallasoft/ps-icons": "^1.2.0",
|
|
35
38
|
"@pallasoft/ps-utilities": "^2.0.0",
|
|
39
|
+
"libphonenumber-js": "^1.13.13",
|
|
36
40
|
"react-aria-components": "^1.19.0",
|
|
37
41
|
"react-datepicker": "^9.1.0"
|
|
38
42
|
},
|