@pallasoft/ps-input-components 1.9.0 → 1.10.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-amount-input.d.ts +3 -0
- package/dist/components/ps-amount-input.js +14 -0
- package/dist/constants/ps-amount-input-config.d.ts +7 -0
- package/dist/constants/ps-amount-input-config.js +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/services/ps-amount-input-service.d.ts +4 -0
- package/dist/services/ps-amount-input-service.js +29 -0
- package/package.json +2 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsAmountInput = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const ps_amount_input_service_1 = require("../services/ps-amount-input-service");
|
|
6
|
+
const ps_text_input_1 = require("./ps-text-input");
|
|
7
|
+
const PsAmountInput = ({ className, onChange, ...props }) => ((0, jsx_runtime_1.jsx)(ps_text_input_1.PsTextInput, { ...props, autoComplete: 'off', className: className, inputMode: 'decimal', onChange: (event) => {
|
|
8
|
+
const normalised = ps_amount_input_service_1.PsAmountInputService.normalise(event.target.value);
|
|
9
|
+
if (normalised !== event.target.value)
|
|
10
|
+
event.target.value = normalised;
|
|
11
|
+
if (onChange)
|
|
12
|
+
onChange(event);
|
|
13
|
+
}, type: 'text' }));
|
|
14
|
+
exports.PsAmountInput = PsAmountInput;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './components/ps-cascader-input';
|
|
2
|
+
export * from './components/ps-amount-input';
|
|
2
3
|
export * from './components/ps-checkbox';
|
|
3
4
|
export * from './components/ps-color-input';
|
|
4
5
|
export * from './components/ps-color-picker';
|
|
@@ -12,5 +13,6 @@ export * from './components/ps-select-input';
|
|
|
12
13
|
export * from './components/ps-text-area-input';
|
|
13
14
|
export * from './components/ps-text-input';
|
|
14
15
|
export * from './components/ps-toggle';
|
|
16
|
+
export * from './services/ps-amount-input-service';
|
|
15
17
|
export * from './services/ps-color-service';
|
|
16
18
|
export * from './interfaces/color-hsv';
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./components/ps-cascader-input"), exports);
|
|
18
|
+
__exportStar(require("./components/ps-amount-input"), exports);
|
|
18
19
|
__exportStar(require("./components/ps-checkbox"), exports);
|
|
19
20
|
__exportStar(require("./components/ps-color-input"), exports);
|
|
20
21
|
__exportStar(require("./components/ps-color-picker"), exports);
|
|
@@ -28,5 +29,6 @@ __exportStar(require("./components/ps-select-input"), exports);
|
|
|
28
29
|
__exportStar(require("./components/ps-text-area-input"), exports);
|
|
29
30
|
__exportStar(require("./components/ps-text-input"), exports);
|
|
30
31
|
__exportStar(require("./components/ps-toggle"), exports);
|
|
32
|
+
__exportStar(require("./services/ps-amount-input-service"), exports);
|
|
31
33
|
__exportStar(require("./services/ps-color-service"), exports);
|
|
32
34
|
__exportStar(require("./interfaces/color-hsv"), exports);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsAmountInputService = void 0;
|
|
4
|
+
const ps_amount_input_config_1 = require("../constants/ps-amount-input-config");
|
|
5
|
+
class PsAmountInputService {
|
|
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;
|
|
22
|
+
}
|
|
23
|
+
static toNumber(raw) {
|
|
24
|
+
const normalised = PsAmountInputService.normalise(raw);
|
|
25
|
+
const parsed = Number(normalised);
|
|
26
|
+
return normalised === '' || !Number.isFinite(parsed) ? 0 : parsed;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.PsAmountInputService = PsAmountInputService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pallasoft/ps-input-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@internationalized/date": "^3.12.2",
|
|
32
|
-
"@pallasoft/ps-core-components": "^2.
|
|
32
|
+
"@pallasoft/ps-core-components": "^2.3.1",
|
|
33
33
|
"@pallasoft/ps-design-system": "^1.3.0",
|
|
34
34
|
"@pallasoft/ps-icons": "^1.2.0",
|
|
35
35
|
"@pallasoft/ps-utilities": "^2.0.0",
|