@pallasoft/ps-input-components 1.18.2 → 1.19.1

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,6 @@
1
+ import { type PsSelectInputProps } from './ps-select-input';
2
+ export interface PsCurrencyInputProps extends Omit<PsSelectInputProps, 'options'> {
3
+ currencies: string[];
4
+ locale?: string;
5
+ }
6
+ export declare const PsCurrencyInput: ({ currencies, locale, ...props }: PsCurrencyInputProps) => import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsCurrencyInput = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const ps_currency_input_service_1 = require("../services/ps-currency-input-service");
6
+ const ps_select_input_1 = require("./ps-select-input");
7
+ const PsCurrencyInput = ({ currencies, locale, ...props }) => ((0, jsx_runtime_1.jsx)(ps_select_input_1.PsSelectInput, { ...props, options: ps_currency_input_service_1.PsCurrencyInputService.options(currencies, locale) }));
8
+ exports.PsCurrencyInput = PsCurrencyInput;
@@ -0,0 +1,5 @@
1
+ export declare const PsCurrencyInputConfig: {
2
+ readonly locale: "en";
3
+ readonly separator: " · ";
4
+ readonly displayType: "currency";
5
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsCurrencyInputConfig = void 0;
4
+ exports.PsCurrencyInputConfig = {
5
+ locale: 'en',
6
+ separator: ' · ',
7
+ displayType: 'currency',
8
+ };
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { PsCurrencyInputService } from '../services/ps-currency-input-service';
3
+ import { PsSelectInput } from './ps-select-input';
4
+ export const PsCurrencyInput = ({ currencies, locale, ...props }) => (_jsx(PsSelectInput, { ...props, options: PsCurrencyInputService.options(currencies, locale) }));
@@ -0,0 +1,5 @@
1
+ export const PsCurrencyInputConfig = {
2
+ locale: 'en',
3
+ separator: ' · ',
4
+ displayType: 'currency',
5
+ };
package/dist/esm/index.js CHANGED
@@ -37,3 +37,6 @@ export * from './components/ps-year-input';
37
37
  export * from './constants/ps-year-input-config';
38
38
  export * from './services/ps-year-input-service';
39
39
  export * from './constants/ps-cascader-config';
40
+ export * from './components/ps-currency-input';
41
+ export * from './constants/ps-currency-input-config';
42
+ export * from './services/ps-currency-input-service';
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -1,25 +1,9 @@
1
- import { PsAmountInputConfig } from '../constants/ps-amount-input-config';
1
+ import { Common } from '@pallasoft/ps-utilities';
2
2
  export class PsAmountInputService {
3
3
  static normalise(raw) {
4
- const trimmed = raw.trim();
5
- const isBracketed = trimmed.startsWith(PsAmountInputConfig.openBracket) &&
6
- trimmed.endsWith(PsAmountInputConfig.closeBracket);
7
- const isNegative = isBracketed || trimmed.startsWith(PsAmountInputConfig.minus);
8
- const kept = trimmed.replace(PsAmountInputConfig.disallowed, '');
9
- const pointIndex = kept.indexOf(PsAmountInputConfig.point);
10
- const digits = pointIndex === -1
11
- ? kept
12
- : `${kept.slice(0, pointIndex + 1)}${kept
13
- .slice(pointIndex + 1)
14
- .split(PsAmountInputConfig.point)
15
- .join('')}`;
16
- if (digits === '')
17
- return isNegative && !isBracketed ? PsAmountInputConfig.minus : '';
18
- return isNegative ? `${PsAmountInputConfig.minus}${digits}` : digits;
4
+ return Common.AmountService.normalise(raw);
19
5
  }
20
6
  static toNumber(raw) {
21
- const normalised = PsAmountInputService.normalise(raw);
22
- const parsed = Number(normalised);
23
- return normalised === '' || !Number.isFinite(parsed) ? 0 : parsed;
7
+ return Common.AmountService.toNumber(raw);
24
8
  }
25
9
  }
@@ -0,0 +1,10 @@
1
+ import { PsCurrencyInputConfig } from '../constants/ps-currency-input-config';
2
+ export class PsCurrencyInputService {
3
+ static options(currencies, locale = PsCurrencyInputConfig.locale) {
4
+ const names = new Intl.DisplayNames([locale], { type: PsCurrencyInputConfig.displayType });
5
+ return [...new Set(currencies.map((code) => code.toUpperCase()))].map((code) => ({
6
+ label: `${code}${PsCurrencyInputConfig.separator}${names.of(code) ?? code}`,
7
+ value: code,
8
+ }));
9
+ }
10
+ }
@@ -1,56 +1,27 @@
1
- import { AsYouType, getCountries, getCountryCallingCode, parsePhoneNumberFromString, } from 'libphonenumber-js';
1
+ import { Common } from '@pallasoft/ps-utilities';
2
2
  import { PsPhoneInputConfig } from '../constants/ps-phone-input-config';
3
3
  export class PsPhoneInputService {
4
4
  static isCountry(code) {
5
- return getCountries().includes(code);
5
+ return Common.PhoneService.isCountry(code);
6
6
  }
7
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
- });
8
+ return Common.PhoneService.countries(preferred, PsPhoneInputConfig.locale);
26
9
  }
27
10
  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 };
11
+ return Common.PhoneService.display(value, fallbackCountry);
34
12
  }
35
13
  static format(national, country) {
36
- if (!PsPhoneInputService.isCountry(country))
37
- return national;
38
- return new AsYouType(country).input(national);
14
+ return Common.PhoneService.format(national, country);
39
15
  }
40
16
  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;
17
+ return Common.PhoneService.toStored(national, country);
46
18
  }
47
19
  static isValid(national, country) {
48
20
  if (national.trim() === '')
49
21
  return true;
50
22
  if (!PsPhoneInputService.isCountry(country))
51
23
  return false;
52
- const parsed = parsePhoneNumberFromString(national, country);
53
- return parsed !== undefined && parsed.isValid();
24
+ return Common.PhoneService.isValid(national, country);
54
25
  }
55
26
  static search(options, query) {
56
27
  const term = query.trim().toLowerCase().replace(PsPhoneInputConfig.plus, '');
@@ -72,6 +43,6 @@ export class PsPhoneInputService {
72
43
  ].filter((part) => part.text !== '');
73
44
  }
74
45
  static callingCode(country) {
75
- return PsPhoneInputService.isCountry(country) ? getCountryCallingCode(country) : '';
46
+ return Common.PhoneService.callingCode(country);
76
47
  }
77
48
  }
@@ -1,28 +1,9 @@
1
- import { PsPostalCodeConfig, PsPostalCodeFormats } from '../constants/ps-postal-code-formats';
1
+ import { Common } from '@pallasoft/ps-utilities';
2
2
  export class PsPostalCodeService {
3
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);
4
+ return Common.PostalCodeService.format(raw, country);
20
5
  }
21
6
  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));
7
+ return Common.PostalCodeService.maxLength(country);
27
8
  }
28
9
  }
package/dist/index.d.ts CHANGED
@@ -37,3 +37,6 @@ export * from './components/ps-year-input';
37
37
  export * from './constants/ps-year-input-config';
38
38
  export * from './services/ps-year-input-service';
39
39
  export * from './constants/ps-cascader-config';
40
+ export * from './components/ps-currency-input';
41
+ export * from './constants/ps-currency-input-config';
42
+ export * from './services/ps-currency-input-service';
package/dist/index.js CHANGED
@@ -53,3 +53,6 @@ __exportStar(require("./components/ps-year-input"), exports);
53
53
  __exportStar(require("./constants/ps-year-input-config"), exports);
54
54
  __exportStar(require("./services/ps-year-input-service"), exports);
55
55
  __exportStar(require("./constants/ps-cascader-config"), exports);
56
+ __exportStar(require("./components/ps-currency-input"), exports);
57
+ __exportStar(require("./constants/ps-currency-input-config"), exports);
58
+ __exportStar(require("./services/ps-currency-input-service"), exports);
@@ -1,29 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PsAmountInputService = void 0;
4
- const ps_amount_input_config_1 = require("../constants/ps-amount-input-config");
4
+ const ps_utilities_1 = require("@pallasoft/ps-utilities");
5
5
  class PsAmountInputService {
6
6
  static normalise(raw) {
7
- const trimmed = raw.trim();
8
- const isBracketed = trimmed.startsWith(ps_amount_input_config_1.PsAmountInputConfig.openBracket) &&
9
- trimmed.endsWith(ps_amount_input_config_1.PsAmountInputConfig.closeBracket);
10
- const isNegative = isBracketed || trimmed.startsWith(ps_amount_input_config_1.PsAmountInputConfig.minus);
11
- const kept = trimmed.replace(ps_amount_input_config_1.PsAmountInputConfig.disallowed, '');
12
- const pointIndex = kept.indexOf(ps_amount_input_config_1.PsAmountInputConfig.point);
13
- const digits = pointIndex === -1
14
- ? kept
15
- : `${kept.slice(0, pointIndex + 1)}${kept
16
- .slice(pointIndex + 1)
17
- .split(ps_amount_input_config_1.PsAmountInputConfig.point)
18
- .join('')}`;
19
- if (digits === '')
20
- return isNegative && !isBracketed ? ps_amount_input_config_1.PsAmountInputConfig.minus : '';
21
- return isNegative ? `${ps_amount_input_config_1.PsAmountInputConfig.minus}${digits}` : digits;
7
+ return ps_utilities_1.Common.AmountService.normalise(raw);
22
8
  }
23
9
  static toNumber(raw) {
24
- const normalised = PsAmountInputService.normalise(raw);
25
- const parsed = Number(normalised);
26
- return normalised === '' || !Number.isFinite(parsed) ? 0 : parsed;
10
+ return ps_utilities_1.Common.AmountService.toNumber(raw);
27
11
  }
28
12
  }
29
13
  exports.PsAmountInputService = PsAmountInputService;
@@ -0,0 +1,4 @@
1
+ import type { PsSelectOption } from '../components/ps-select-input';
2
+ export declare class PsCurrencyInputService {
3
+ static options(currencies: string[], locale?: string): PsSelectOption[];
4
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsCurrencyInputService = void 0;
4
+ const ps_currency_input_config_1 = require("../constants/ps-currency-input-config");
5
+ class PsCurrencyInputService {
6
+ static options(currencies, locale = ps_currency_input_config_1.PsCurrencyInputConfig.locale) {
7
+ const names = new Intl.DisplayNames([locale], { type: ps_currency_input_config_1.PsCurrencyInputConfig.displayType });
8
+ return [...new Set(currencies.map((code) => code.toUpperCase()))].map((code) => ({
9
+ label: `${code}${ps_currency_input_config_1.PsCurrencyInputConfig.separator}${names.of(code) ?? code}`,
10
+ value: code,
11
+ }));
12
+ }
13
+ }
14
+ exports.PsCurrencyInputService = PsCurrencyInputService;
@@ -1,59 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PsPhoneInputService = void 0;
4
- const libphonenumber_js_1 = require("libphonenumber-js");
4
+ const ps_utilities_1 = require("@pallasoft/ps-utilities");
5
5
  const ps_phone_input_config_1 = require("../constants/ps-phone-input-config");
6
6
  class PsPhoneInputService {
7
7
  static isCountry(code) {
8
- return (0, libphonenumber_js_1.getCountries)().includes(code);
8
+ return ps_utilities_1.Common.PhoneService.isCountry(code);
9
9
  }
10
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
- });
11
+ return ps_utilities_1.Common.PhoneService.countries(preferred, ps_phone_input_config_1.PsPhoneInputConfig.locale);
29
12
  }
30
13
  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 };
14
+ return ps_utilities_1.Common.PhoneService.display(value, fallbackCountry);
37
15
  }
38
16
  static format(national, country) {
39
- if (!PsPhoneInputService.isCountry(country))
40
- return national;
41
- return new libphonenumber_js_1.AsYouType(country).input(national);
17
+ return ps_utilities_1.Common.PhoneService.format(national, country);
42
18
  }
43
19
  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;
20
+ return ps_utilities_1.Common.PhoneService.toStored(national, country);
49
21
  }
50
22
  static isValid(national, country) {
51
23
  if (national.trim() === '')
52
24
  return true;
53
25
  if (!PsPhoneInputService.isCountry(country))
54
26
  return false;
55
- const parsed = (0, libphonenumber_js_1.parsePhoneNumberFromString)(national, country);
56
- return parsed !== undefined && parsed.isValid();
27
+ return ps_utilities_1.Common.PhoneService.isValid(national, country);
57
28
  }
58
29
  static search(options, query) {
59
30
  const term = query.trim().toLowerCase().replace(ps_phone_input_config_1.PsPhoneInputConfig.plus, '');
@@ -75,7 +46,7 @@ class PsPhoneInputService {
75
46
  ].filter((part) => part.text !== '');
76
47
  }
77
48
  static callingCode(country) {
78
- return PsPhoneInputService.isCountry(country) ? (0, libphonenumber_js_1.getCountryCallingCode)(country) : '';
49
+ return ps_utilities_1.Common.PhoneService.callingCode(country);
79
50
  }
80
51
  }
81
52
  exports.PsPhoneInputService = PsPhoneInputService;
@@ -1,32 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PsPostalCodeService = void 0;
4
- const ps_postal_code_formats_1 = require("../constants/ps-postal-code-formats");
4
+ const ps_utilities_1 = require("@pallasoft/ps-utilities");
5
5
  class PsPostalCodeService {
6
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);
7
+ return ps_utilities_1.Common.PostalCodeService.format(raw, country);
23
8
  }
24
9
  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));
10
+ return ps_utilities_1.Common.PostalCodeService.maxLength(country);
30
11
  }
31
12
  }
32
13
  exports.PsPostalCodeService = PsPostalCodeService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-input-components",
3
- "version": "1.18.2",
3
+ "version": "1.19.1",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -9,6 +9,7 @@
9
9
  "exports": {
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
+ "import": "./dist/esm/index.js",
12
13
  "module": "./dist/esm/index.js",
13
14
  "require": "./dist/index.js",
14
15
  "default": "./dist/index.js"
@@ -19,7 +20,7 @@
19
20
  ],
20
21
  "scripts": {
21
22
  "husky:prepare": "npx husky",
22
- "build": "tsc && tsc -p tsconfig.esm.json",
23
+ "build": "tsc && tsc -p tsconfig.esm.json && node -e \"require('fs').writeFileSync('dist/esm/package.json', JSON.stringify({ type: 'module' }))\"",
23
24
  "setup:graphify": "sh scripts/graphify-setup.sh",
24
25
  "update:graphify": "sh scripts/graphify-update.sh",
25
26
  "lint": "npm run lint:eslint",
@@ -35,7 +36,7 @@
35
36
  "@pallasoft/ps-core-components": "^2.10.0",
36
37
  "@pallasoft/ps-design-system": "^1.5.0",
37
38
  "@pallasoft/ps-icons": "^1.5.4",
38
- "@pallasoft/ps-utilities": "^2.2.0",
39
+ "@pallasoft/ps-utilities": "^2.8.0",
39
40
  "libphonenumber-js": "^1.13.13",
40
41
  "react-aria-components": "^1.19.0",
41
42
  "react-datepicker": "^9.1.0"