pds-dev-kit-web 2.2.319-alpha.2 → 2.2.319

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.
Files changed (80) hide show
  1. package/dist/index.d.ts +4 -6
  2. package/dist/index.js +2 -11
  3. package/dist/src/core/pricing/index.d.ts +0 -4
  4. package/dist/src/core/pricing/index.js +0 -4
  5. package/dist/src/desktop/components/index.d.ts +1 -2
  6. package/dist/src/desktop/components/index.js +2 -4
  7. package/dist/src/desktop/index.d.ts +1 -1
  8. package/dist/src/desktop/index.js +1 -2
  9. package/dist/src/mobile/components/index.d.ts +1 -2
  10. package/dist/src/mobile/components/index.js +1 -3
  11. package/dist/src/mobile/index.d.ts +1 -1
  12. package/dist/src/mobile/index.js +1 -2
  13. package/dist/src/sub/DynamicLayout/DynamicLayout.d.ts +1 -1
  14. package/dist/src/sub/DynamicLayout/DynamicLayout.js +3 -2
  15. package/dist/src/sub/DynamicLayout/sections/FullscreenIframeSection/templates/TemplateA/desktop/D_TemplateA.js +9 -14
  16. package/dist/src/sub/DynamicLayout/sections/FullscreenIframeSection/templates/TemplateA/mobile/M_TemplateA.js +9 -14
  17. package/dist/src/sub/DynamicLayout/types.d.ts +2 -0
  18. package/package.json +2 -6
  19. package/release-note.md +3 -11
  20. package/dist/src/core/pricing/hooks/useNewPriceTextField.d.ts +0 -68
  21. package/dist/src/core/pricing/hooks/useNewPriceTextField.js +0 -210
  22. package/dist/src/core/pricing/input-utils.d.ts +0 -32
  23. package/dist/src/core/pricing/input-utils.js +0 -119
  24. package/dist/src/core/pricing/policy-context.d.ts +0 -14
  25. package/dist/src/core/pricing/policy-context.js +0 -35
  26. package/dist/src/core/pricing/policy-model.d.ts +0 -39
  27. package/dist/src/core/pricing/policy-model.js +0 -79
  28. package/dist/src/desktop/components/NewPriceTextField/NewPriceTextField.d.ts +0 -8
  29. package/dist/src/desktop/components/NewPriceTextField/NewPriceTextField.js +0 -240
  30. package/dist/src/desktop/components/NewPriceTextField/index.d.ts +0 -1
  31. package/dist/src/desktop/components/NewPriceTextField/index.js +0 -8
  32. package/dist/src/mobile/components/NewPriceTextField/NewPriceTextField.d.ts +0 -8
  33. package/dist/src/mobile/components/NewPriceTextField/NewPriceTextField.js +0 -234
  34. package/dist/src/mobile/components/NewPriceTextField/index.d.ts +0 -1
  35. package/dist/src/mobile/components/NewPriceTextField/index.js +0 -8
  36. package/dist/storybook-static/0.b73eaee9a88f178d62ed.manager.bundle.d.ts +0 -0
  37. package/dist/storybook-static/0.b73eaee9a88f178d62ed.manager.bundle.js +0 -74
  38. package/dist/storybook-static/1.f296d183a17268696d73.manager.bundle.d.ts +0 -0
  39. package/dist/storybook-static/1.f296d183a17268696d73.manager.bundle.js +0 -190
  40. package/dist/storybook-static/10.9998ba67d65d81d20896.manager.bundle.d.ts +0 -0
  41. package/dist/storybook-static/10.9998ba67d65d81d20896.manager.bundle.js +0 -62
  42. package/dist/storybook-static/11.49c687eaa6261f8b7be2.manager.bundle.d.ts +0 -2
  43. package/dist/storybook-static/11.49c687eaa6261f8b7be2.manager.bundle.js +0 -534
  44. package/dist/storybook-static/12.c9538ed3766c96f289e7.manager.bundle.d.ts +0 -2
  45. package/dist/storybook-static/12.c9538ed3766c96f289e7.manager.bundle.js +0 -2
  46. package/dist/storybook-static/5.fa71488e730c5c7f885f.manager.bundle.d.ts +0 -18
  47. package/dist/storybook-static/5.fa71488e730c5c7f885f.manager.bundle.js +0 -527
  48. package/dist/storybook-static/6.8096ae4aadde0743697b.manager.bundle.d.ts +0 -3
  49. package/dist/storybook-static/6.8096ae4aadde0743697b.manager.bundle.js +0 -141
  50. package/dist/storybook-static/7.b34baecbd082bc7b188d.manager.bundle.d.ts +0 -0
  51. package/dist/storybook-static/7.b34baecbd082bc7b188d.manager.bundle.js +0 -8
  52. package/dist/storybook-static/8.15577edffecf900a8de2.manager.bundle.d.ts +0 -0
  53. package/dist/storybook-static/8.15577edffecf900a8de2.manager.bundle.js +0 -25
  54. package/dist/storybook-static/9.d7d85aa0a49a98f17218.manager.bundle.d.ts +0 -0
  55. package/dist/storybook-static/9.d7d85aa0a49a98f17218.manager.bundle.js +0 -94
  56. package/dist/storybook-static/main.ce406c7e93b98325390e.manager.bundle.d.ts +0 -2
  57. package/dist/storybook-static/main.ce406c7e93b98325390e.manager.bundle.js +0 -3824
  58. package/dist/storybook-static/runtime~main.909d038f912f063e8837.manager.bundle.d.ts +0 -1
  59. package/dist/storybook-static/runtime~main.909d038f912f063e8837.manager.bundle.js +0 -34
  60. package/dist/storybook-static/vendors~main.d3455eed64b243c89325.manager.bundle.d.ts +0 -3
  61. package/dist/storybook-static/vendors~main.d3455eed64b243c89325.manager.bundle.js +0 -11787
  62. package/storybook-static/0.b73eaee9a88f178d62ed.manager.bundle.js +0 -1
  63. package/storybook-static/1.f296d183a17268696d73.manager.bundle.js +0 -1
  64. package/storybook-static/10.9998ba67d65d81d20896.manager.bundle.js +0 -1
  65. package/storybook-static/11.49c687eaa6261f8b7be2.manager.bundle.js +0 -2
  66. package/storybook-static/11.49c687eaa6261f8b7be2.manager.bundle.js.LICENSE.txt +0 -12
  67. package/storybook-static/12.c9538ed3766c96f289e7.manager.bundle.js +0 -1
  68. package/storybook-static/5.fa71488e730c5c7f885f.manager.bundle.js +0 -2
  69. package/storybook-static/5.fa71488e730c5c7f885f.manager.bundle.js.LICENSE.txt +0 -8
  70. package/storybook-static/6.8096ae4aadde0743697b.manager.bundle.js +0 -1
  71. package/storybook-static/7.b34baecbd082bc7b188d.manager.bundle.js +0 -1
  72. package/storybook-static/8.15577edffecf900a8de2.manager.bundle.js +0 -1
  73. package/storybook-static/9.d7d85aa0a49a98f17218.manager.bundle.js +0 -1
  74. package/storybook-static/favicon.ico +0 -0
  75. package/storybook-static/index.html +0 -47
  76. package/storybook-static/main.ce406c7e93b98325390e.manager.bundle.js +0 -1
  77. package/storybook-static/runtime~main.909d038f912f063e8837.manager.bundle.js +0 -1
  78. package/storybook-static/vendors~main.d3455eed64b243c89325.manager.bundle.js +0 -2
  79. package/storybook-static/vendors~main.d3455eed64b243c89325.manager.bundle.js.LICENSE.txt +0 -88
  80. package/vitest.config.ts +0 -8
@@ -1,210 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.useNewPriceTextField = void 0;
15
- var react_1 = require("react");
16
- var react_hook_form_1 = require("react-hook-form");
17
- var react_i18next_1 = require("react-i18next");
18
- var types_1 = require("../../../common/types");
19
- var input_utils_1 = require("../input-utils");
20
- var policy_context_1 = require("../policy-context");
21
- var service_1 = require("../service");
22
- function useNewPriceTextField(_a) {
23
- var _b;
24
- var name = _a.name, hintText = _a.hintText, defaultAmount = _a.defaultAmount, validation = _a.validation, _c = _a.state, state = _c === void 0 ? 'normal' : _c, _d = _a.useRequirementMode, useRequirementMode = _d === void 0 ? 'use' : _d, onChange = _a.onChange, onBlur = _a.onBlur, onFocus = _a.onFocus, onKeyDown = _a.onKeyDown, onKeyUp = _a.onKeyUp, onTarget = _a.onTarget, onCurrencyChange = _a.onCurrencyChange, onValueChange = _a.onValueChange;
25
- var t = (0, react_i18next_1.useTranslation)('translation').t;
26
- var policy = (0, policy_context_1.usePricingPolicy)();
27
- var baseCurrency = policy.baseCurrency;
28
- var basePolicy = policy.policies[baseCurrency];
29
- if (!basePolicy) {
30
- throw new Error("NewPriceTextField: policy for base currency ".concat(baseCurrency, " is missing"));
31
- }
32
- var decimalDigits = basePolicy.decimalDigits;
33
- var _e = (0, react_hook_form_1.useFormContext)(), setValue = _e.setValue, watch = _e.watch, trigger = _e.trigger, errors = _e.formState.errors;
34
- var formValue = watch(name);
35
- var rawValue = (0, input_utils_1.toRawValue)(formValue);
36
- var _f = (0, react_1.useState)(baseCurrency), selectedCurrency = _f[0], setSelectedCurrency = _f[1];
37
- var _g = (0, react_1.useState)(false), isFocused = _g[0], setIsFocused = _g[1];
38
- var didInitRef = (0, react_1.useRef)(false);
39
- /** 마운트 시 폼이 비어 있고 defaultAmount가 있으면 1회만 기록. 폼 값이 있으면 폼이 우선 */
40
- (0, react_1.useEffect)(function () {
41
- if (didInitRef.current) {
42
- return;
43
- }
44
- didInitRef.current = true;
45
- if (defaultAmount !== undefined && rawValue === '') {
46
- setValue(name, (0, input_utils_1.normalizePriceOnBlur)(String(defaultAmount), decimalDigits));
47
- }
48
- // eslint-disable-next-line react-hooks/exhaustive-deps
49
- }, []);
50
- /** 기준 통화가 바뀌면(정책 교체) 선택 통화도 기준 통화로 */
51
- (0, react_1.useEffect)(function () {
52
- setSelectedCurrency(baseCurrency);
53
- }, [baseCurrency]);
54
- var isInputReadOnly = state === 'read_only' || selectedCurrency !== baseCurrency;
55
- var dropdownState = policy.multiCurrency && policy.currencies.length > 1 ? 'normal' : 'read_only';
56
- var currencyOptions = (0, react_1.useMemo)(function () {
57
- return policy.currencies.map(function (currency) { return ({
58
- value: currency,
59
- text: currency,
60
- currency: currency,
61
- state: 'normal'
62
- }); });
63
- }, [policy.currencies]);
64
- /** 기준 통화 금액 → 선택 통화 금액 */
65
- var calculatedValue = (0, react_1.useMemo)(function () {
66
- if (rawValue === '') {
67
- return 0;
68
- }
69
- var amount = Number(rawValue);
70
- if (Number.isNaN(amount)) {
71
- return 0;
72
- }
73
- if (selectedCurrency === baseCurrency) {
74
- return amount;
75
- }
76
- var rate = policy.exchangeRates[selectedCurrency];
77
- var baseRate = policy.exchangeRates[baseCurrency];
78
- if (!rate || !baseRate) {
79
- // 환율이 없으면 렌더 중 throw 대신 빈 표시 (createPricingPolicy를 거친 정책에서는 발생하지 않음)
80
- return Number.NaN;
81
- }
82
- return service_1.PricingService.exchangePrice(amount, baseCurrency, selectedCurrency, policy.exchangeRates);
83
- }, [rawValue, selectedCurrency, baseCurrency, policy.exchangeRates]);
84
- var displayValue = (0, react_1.useMemo)(function () {
85
- var _a, _b;
86
- if (rawValue === '' || Number.isNaN(calculatedValue)) {
87
- return '';
88
- }
89
- if (selectedCurrency === baseCurrency) {
90
- return isFocused ? (0, input_utils_1.groupDigits)(rawValue) : (0, input_utils_1.formatAmount)(rawValue, decimalDigits);
91
- }
92
- var selectedDigits = (_b = (_a = policy.policies[selectedCurrency]) === null || _a === void 0 ? void 0 : _a.decimalDigits) !== null && _b !== void 0 ? _b : 0;
93
- return (0, input_utils_1.formatAmount)(calculatedValue, selectedDigits);
94
- }, [
95
- rawValue,
96
- selectedCurrency,
97
- baseCurrency,
98
- isFocused,
99
- decimalDigits,
100
- calculatedValue,
101
- policy.policies
102
- ]);
103
- /** react-hook-form 검증 규칙: 문서의 기본 3종 + required, 소비자 validation으로 키 단위 재정의 */
104
- var rules = (0, react_1.useMemo)(function () {
105
- var _a;
106
- var required = false;
107
- if ((validation === null || validation === void 0 ? void 0 : validation.required) !== undefined) {
108
- required = validation.required;
109
- }
110
- else if (useRequirementMode === 'use') {
111
- required = String(t('str_please_enter_price'));
112
- }
113
- // 문구는 react-i18next의 t로 만든다. bare i18next 싱글턴은 소비 앱에서 중첩 설치되면
114
- // 초기화되지 않아 undefined를 돌려주므로(검증이 통과로 처리됨) 쓰지 않는다.
115
- var translate = function (key, options) { return String(t(key, options)); };
116
- var validate = __assign({ price: function (value) { return (0, input_utils_1.validatePriceAmount)(value, basePolicy, translate); } }, ((_a = validation === null || validation === void 0 ? void 0 : validation.validate) !== null && _a !== void 0 ? _a : {}));
117
- return { required: required, validate: validate };
118
- }, [validation, useRequirementMode, basePolicy, t]);
119
- var errorMessage = (_b = (0, types_1.getErrorByName)(errors, name)) === null || _b === void 0 ? void 0 : _b.message;
120
- /** 값이 비어 있지 않을 때만 통화·환산값을 알린다 */
121
- (0, react_1.useEffect)(function () {
122
- var _a, _b;
123
- if (!onValueChange || rawValue === '' || Number.isNaN(calculatedValue)) {
124
- return;
125
- }
126
- var selectedDigits = (_b = (_a = policy.policies[selectedCurrency]) === null || _a === void 0 ? void 0 : _a.decimalDigits) !== null && _b !== void 0 ? _b : 0;
127
- onValueChange({
128
- selectedCurrency: selectedCurrency,
129
- baseCurrencyValue: Number(rawValue),
130
- calculatedValue: calculatedValue,
131
- displayValue: (0, input_utils_1.formatAmount)(calculatedValue, selectedDigits)
132
- });
133
- // eslint-disable-next-line react-hooks/exhaustive-deps
134
- }, [rawValue, selectedCurrency, calculatedValue]);
135
- var handleChange = (0, react_1.useCallback)(function (e) {
136
- if (isInputReadOnly) {
137
- return;
138
- }
139
- var input = e.target;
140
- var selectionStart = input.selectionStart;
141
- var previousDisplay = displayValue;
142
- var next = (0, input_utils_1.sanitizePriceInput)(input.value, decimalDigits);
143
- if (next === null) {
144
- input.value = previousDisplay;
145
- return;
146
- }
147
- setValue(name, next, { shouldValidate: true, shouldDirty: true });
148
- onChange === null || onChange === void 0 ? void 0 : onChange(e);
149
- // 콤마가 추가·삭제되면 커서를 같은 자리로
150
- if (previousDisplay && selectionStart !== null) {
151
- setTimeout(function () {
152
- var commaCount = (input.value.match(/,/g) || []).length;
153
- var previousCommaCount = (previousDisplay.match(/,/g) || []).length;
154
- var nextPosition = selectionStart + (commaCount - previousCommaCount);
155
- input.setSelectionRange(nextPosition, nextPosition);
156
- }, 0);
157
- }
158
- }, [isInputReadOnly, displayValue, decimalDigits, setValue, name, onChange]);
159
- var handleBlur = (0, react_1.useCallback)(function (e) {
160
- setIsFocused(false);
161
- var validated = false;
162
- if (selectedCurrency === baseCurrency && rawValue !== '') {
163
- var normalized = (0, input_utils_1.normalizePriceOnBlur)(rawValue, decimalDigits);
164
- if (normalized !== rawValue) {
165
- setValue(name, normalized, { shouldValidate: true, shouldDirty: true });
166
- validated = true;
167
- }
168
- }
169
- if (!validated) {
170
- trigger(name);
171
- }
172
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
173
- }, [selectedCurrency, baseCurrency, rawValue, decimalDigits, setValue, trigger, name, onBlur]);
174
- var handleFocus = (0, react_1.useCallback)(function (e) {
175
- if (!isInputReadOnly) {
176
- setIsFocused(true);
177
- }
178
- onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
179
- }, [isInputReadOnly, onFocus]);
180
- var handleDelete = (0, react_1.useCallback)(function () {
181
- setValue(name, '', { shouldValidate: true, shouldDirty: true });
182
- }, [setValue, name]);
183
- var selectCurrency = (0, react_1.useCallback)(function (currency) {
184
- setSelectedCurrency(currency);
185
- onCurrencyChange === null || onCurrencyChange === void 0 ? void 0 : onCurrencyChange(currency);
186
- }, [onCurrencyChange]);
187
- return {
188
- hintText: hintText !== null && hintText !== void 0 ? hintText : t('str_please_enter_price'),
189
- displayValue: displayValue,
190
- rules: rules,
191
- errorMessage: errorMessage,
192
- isFocused: isFocused,
193
- isInputReadOnly: isInputReadOnly,
194
- baseCurrency: baseCurrency,
195
- selectedCurrency: selectedCurrency,
196
- currencyOptions: currencyOptions,
197
- dropdownState: dropdownState,
198
- handlers: {
199
- onChange: handleChange,
200
- onBlur: handleBlur,
201
- onFocus: handleFocus,
202
- onKeyDown: onKeyDown,
203
- onKeyUp: onKeyUp,
204
- onTarget: function () { return onTarget === null || onTarget === void 0 ? void 0 : onTarget(); },
205
- onDelete: handleDelete,
206
- selectCurrency: selectCurrency
207
- }
208
- };
209
- }
210
- exports.useNewPriceTextField = useNewPriceTextField;
@@ -1,32 +0,0 @@
1
- /**
2
- * PriceTextField 입력값 정제·포맷 순수 함수 모음.
3
- * 통화 정책(소수 자릿수)만 인자로 받고 React/RHF에 의존하지 않는다.
4
- */
5
- /** 폼에 들어 있는 값을 콤마·공백 없는 숫자 문자열로 바꾼다. */
6
- export declare function toRawValue(formValue: unknown): string;
7
- /** 입력 중 표시용: 정수부에만 천 단위 콤마를 넣는다. */
8
- export declare function groupDigits(raw: string): string;
9
- /**
10
- * 키 입력 결과를 정제한다.
11
- * @returns 허용된 숫자 문자열(콤마 없음) 또는 거부 시 null
12
- */
13
- export declare function sanitizePriceInput(input: string, decimalDigits: number): string | null;
14
- /** blur 시 소수 자릿수를 고정한다. 입력 단계에서 자릿수를 이미 제한하므로 반올림은 일어나지 않는다. */
15
- export declare function normalizePriceOnBlur(raw: string, decimalDigits: number): string;
16
- /** 표시용 포맷: 자릿수 고정 + 천 단위 콤마 */
17
- export declare function formatAmount(amount: number | string, decimalDigits: number): string;
18
- /** 검증에 필요한 통화 정책 부분집합 (policy-model의 CurrencyPolicy와 호환) */
19
- export type PriceAmountPolicy = {
20
- code: string;
21
- decimalDigits: number;
22
- minAmount: number;
23
- maxAmount: number;
24
- paymentUnit: number;
25
- };
26
- /** react-i18next의 t 와 같은 모양. bare i18next 싱글턴에 의존하지 않기 위해 주입받는다 */
27
- export type PriceMessageTranslator = (key: string, options?: Record<string, unknown>) => string;
28
- /**
29
- * 가격 입력값을 정책(최소·최대·단위·소수 자릿수)으로 검증한다.
30
- * @returns 오류 문구(i18n 적용) 또는 통과 시 undefined. 빈 값은 통과(required는 별도 처리)
31
- */
32
- export declare function validatePriceAmount(value: string, policy: PriceAmountPolicy, t: PriceMessageTranslator): string | undefined;
@@ -1,119 +0,0 @@
1
- "use strict";
2
- /**
3
- * PriceTextField 입력값 정제·포맷 순수 함수 모음.
4
- * 통화 정책(소수 자릿수)만 인자로 받고 React/RHF에 의존하지 않는다.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.validatePriceAmount = exports.formatAmount = exports.normalizePriceOnBlur = exports.sanitizePriceInput = exports.groupDigits = exports.toRawValue = void 0;
8
- /** 폼에 들어 있는 값을 콤마·공백 없는 숫자 문자열로 바꾼다. */
9
- function toRawValue(formValue) {
10
- if (formValue === null || formValue === undefined) {
11
- return '';
12
- }
13
- return String(formValue).replace(/[,\s]/g, '');
14
- }
15
- exports.toRawValue = toRawValue;
16
- /** 입력 중 표시용: 정수부에만 천 단위 콤마를 넣는다. */
17
- function groupDigits(raw) {
18
- if (!raw) {
19
- return '';
20
- }
21
- var _a = raw.split('.'), integerPart = _a[0], decimalPart = _a[1];
22
- var grouped = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
23
- return decimalPart !== undefined ? "".concat(grouped, ".").concat(decimalPart) : grouped;
24
- }
25
- exports.groupDigits = groupDigits;
26
- /**
27
- * 키 입력 결과를 정제한다.
28
- * @returns 허용된 숫자 문자열(콤마 없음) 또는 거부 시 null
29
- */
30
- function sanitizePriceInput(input, decimalDigits) {
31
- var raw = input.replace(/[,\s]/g, '');
32
- if (raw === '') {
33
- return '';
34
- }
35
- if (!/^\d*\.?\d*$/.test(raw)) {
36
- return null;
37
- }
38
- if (decimalDigits === 0 && raw.includes('.')) {
39
- return null;
40
- }
41
- var _a = raw.split('.'), fraction = _a[1];
42
- if (fraction !== undefined && fraction.length > decimalDigits) {
43
- return null;
44
- }
45
- return raw;
46
- }
47
- exports.sanitizePriceInput = sanitizePriceInput;
48
- /** blur 시 소수 자릿수를 고정한다. 입력 단계에서 자릿수를 이미 제한하므로 반올림은 일어나지 않는다. */
49
- function normalizePriceOnBlur(raw, decimalDigits) {
50
- if (raw === '' || raw === '.') {
51
- return '';
52
- }
53
- var numeric = Number(raw);
54
- if (Number.isNaN(numeric)) {
55
- return '';
56
- }
57
- return numeric.toFixed(decimalDigits);
58
- }
59
- exports.normalizePriceOnBlur = normalizePriceOnBlur;
60
- /** 표시용 포맷: 자릿수 고정 + 천 단위 콤마 */
61
- function formatAmount(amount, decimalDigits) {
62
- var fixed = Number(amount).toFixed(decimalDigits);
63
- return decimalDigits > 0
64
- ? fixed.replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
65
- : fixed.replace(/(\d)(?=(\d{3})+$)/g, '$1,');
66
- }
67
- exports.formatAmount = formatAmount;
68
- function getDecimalPlaces(value) {
69
- var decimalStr = value.toString().split('.')[1];
70
- return decimalStr ? decimalStr.length : 0;
71
- }
72
- function isDivisible(amount, unit) {
73
- var precision = Math.pow(10, Math.max(getDecimalPlaces(amount), getDecimalPlaces(unit)));
74
- var intAmount = Math.round(amount * precision);
75
- var intUnit = Math.round(unit * precision);
76
- return intAmount % intUnit === 0;
77
- }
78
- /**
79
- * 가격 입력값을 정책(최소·최대·단위·소수 자릿수)으로 검증한다.
80
- * @returns 오류 문구(i18n 적용) 또는 통과 시 undefined. 빈 값은 통과(required는 별도 처리)
81
- */
82
- function validatePriceAmount(value, policy, t) {
83
- var raw = toRawValue(value);
84
- if (raw === '') {
85
- return undefined;
86
- }
87
- var amount = Number(raw);
88
- if (Number.isNaN(amount)) {
89
- return t('str_please_enter_price');
90
- }
91
- var currency = policy.code;
92
- if (amount < policy.minAmount) {
93
- return t('str_min_price', {
94
- minPrice: formatAmount(policy.minAmount, policy.decimalDigits),
95
- currency: currency
96
- });
97
- }
98
- if (amount > policy.maxAmount) {
99
- return t('str_max_price', {
100
- maxPrice: formatAmount(policy.maxAmount, policy.decimalDigits),
101
- currency: currency
102
- });
103
- }
104
- var unitMessage = function () {
105
- return t('str_price_unit', {
106
- priceUnit: formatAmount(policy.paymentUnit, policy.decimalDigits),
107
- currency: currency
108
- });
109
- };
110
- var _a = raw.split('.'), fraction = _a[1];
111
- if (fraction !== undefined && fraction.length > policy.decimalDigits) {
112
- return unitMessage();
113
- }
114
- if (!isDivisible(amount, policy.paymentUnit)) {
115
- return unitMessage();
116
- }
117
- return undefined;
118
- }
119
- exports.validatePriceAmount = validatePriceAmount;
@@ -1,14 +0,0 @@
1
- import type { PricingPolicy, PricingPolicyInput } from './policy-model';
2
- import type { ReactNode } from 'react';
3
- type Props = {
4
- /** 완성된 정책 또는 createPricingPolicy 입력 */
5
- policy: PricingPolicy | PricingPolicyInput;
6
- children: ReactNode;
7
- };
8
- /**
9
- * 채널 통화 정책을 하위 NewPriceTextField에 공급한다.
10
- * 소비 앱은 채널 프로바이더 안쪽에서 한 번만 감싼다.
11
- */
12
- export declare function PricingPolicyProvider({ policy, children }: Props): JSX.Element;
13
- export declare function usePricingPolicy(): PricingPolicy;
14
- export {};
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.usePricingPolicy = exports.PricingPolicyProvider = void 0;
15
- var jsx_runtime_1 = require("react/jsx-runtime");
16
- var react_1 = require("react");
17
- var policy_model_1 = require("./policy-model");
18
- var PricingPolicyContext = (0, react_1.createContext)(policy_model_1.DEFAULT_PRICING_POLICY);
19
- function isPricingPolicy(policy) {
20
- return 'policies' in policy && 'currencies' in policy;
21
- }
22
- /**
23
- * 채널 통화 정책을 하위 NewPriceTextField에 공급한다.
24
- * 소비 앱은 채널 프로바이더 안쪽에서 한 번만 감싼다.
25
- */
26
- function PricingPolicyProvider(_a) {
27
- var policy = _a.policy, children = _a.children;
28
- var value = (0, react_1.useMemo)(function () { return (isPricingPolicy(policy) ? policy : (0, policy_model_1.createPricingPolicy)(policy)); }, [policy]);
29
- return (0, jsx_runtime_1.jsx)(PricingPolicyContext.Provider, __assign({ value: value }, { children: children }));
30
- }
31
- exports.PricingPolicyProvider = PricingPolicyProvider;
32
- function usePricingPolicy() {
33
- return (0, react_1.useContext)(PricingPolicyContext);
34
- }
35
- exports.usePricingPolicy = usePricingPolicy;
@@ -1,39 +0,0 @@
1
- import { CurrencyCode } from './types';
2
- import type { ExchangeRateMap } from './types';
3
- /** 통화 하나의 입력·표시 규칙 */
4
- export type CurrencyPolicy = {
5
- code: CurrencyCode;
6
- /** 소수 자릿수 (KRW 0, USD 2) */
7
- decimalDigits: number;
8
- minAmount: number;
9
- maxAmount: number;
10
- /** 입력 단위 (KRW 100, USD 0.01) */
11
- paymentUnit: number;
12
- };
13
- /** 채널 단위 통화 정책. PricingPolicyProvider로 공급한다. */
14
- export type PricingPolicy = {
15
- baseCurrency: CurrencyCode;
16
- /** 드롭다운 순서. 첫 번째는 항상 기준 통화 */
17
- currencies: CurrencyCode[];
18
- /** 기준 통화 대비 환율. 기준 통화는 1 */
19
- exchangeRates: ExchangeRateMap;
20
- /** true면 드롭다운 선택 가능, false면 읽기 전용 */
21
- multiCurrency: boolean;
22
- policies: Partial<Record<CurrencyCode, CurrencyPolicy>>;
23
- };
24
- /** 소비 앱이 채널 정보로 정책을 만들 때 쓰는 입력 */
25
- export type PricingPolicyInput = {
26
- baseCurrency: CurrencyCode;
27
- altCurrencies?: CurrencyCode[];
28
- /** 기준 통화 대비 환율. 기준 통화 항목은 생략 가능(1로 간주). 기준 통화가 1이 아니면 그 값으로 나눠 정규화 */
29
- exchangeRates?: ExchangeRateMap;
30
- /** 생략하면 보조 통화가 하나라도 있을 때 true */
31
- multiCurrency?: boolean;
32
- /** 통화별 소수 자릿수 재정의 (예: 채널의 baseCurrencyDecimalPlaces) */
33
- decimalDigits?: Partial<Record<CurrencyCode, number>>;
34
- /** 통화별 최소·최대·단위 재정의 (채널 계약 예외) */
35
- limits?: Partial<Record<CurrencyCode, Partial<Pick<CurrencyPolicy, 'minAmount' | 'maxAmount' | 'paymentUnit'>>>>;
36
- };
37
- export declare function createPricingPolicy(input: PricingPolicyInput): PricingPolicy;
38
- /** Provider가 없을 때 쓰는 기본 정책: KRW 단일 통화 */
39
- export declare const DEFAULT_PRICING_POLICY: PricingPolicy;
@@ -1,79 +0,0 @@
1
- "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DEFAULT_PRICING_POLICY = exports.createPricingPolicy = void 0;
13
- var policy_1 = require("./policy");
14
- var types_1 = require("./types");
15
- function buildCurrencyPolicy(code, input) {
16
- var _a, _b, _c, _d, _e, _f;
17
- var defaults = policy_1.DEFAULT_CURRENCY_PRICE_POLICIES[code];
18
- var currency = types_1.CURRENCY_MAP[code];
19
- if (!defaults || !currency) {
20
- throw new Error("createPricingPolicy: unsupported currency: ".concat(code));
21
- }
22
- var limits = (_a = input.limits) === null || _a === void 0 ? void 0 : _a[code];
23
- return {
24
- code: code,
25
- decimalDigits: (_c = (_b = input.decimalDigits) === null || _b === void 0 ? void 0 : _b[code]) !== null && _c !== void 0 ? _c : currency.decimalDigits,
26
- minAmount: (_d = limits === null || limits === void 0 ? void 0 : limits.minAmount) !== null && _d !== void 0 ? _d : Number(defaults.minPayment.amount),
27
- maxAmount: (_e = limits === null || limits === void 0 ? void 0 : limits.maxAmount) !== null && _e !== void 0 ? _e : Number(defaults.maxPayment.amount),
28
- paymentUnit: (_f = limits === null || limits === void 0 ? void 0 : limits.paymentUnit) !== null && _f !== void 0 ? _f : defaults.paymentUnit
29
- };
30
- }
31
- /**
32
- * 환율을 "기준 통화 = 1" 기준으로 정규화한다.
33
- * 입력이 {KRW: 1300, USD: 1}(USD 기준)이어도 기준 통화 KRW면 {KRW: 1, USD: 1/1300}이 된다.
34
- * 보조 통화에 환율이 없거나 0·음수·NaN이면 조용히 틀린 금액을 보여주는 대신 에러를 낸다.
35
- */
36
- function normalizeExchangeRates(baseCurrency, altCurrencies, input) {
37
- var _a;
38
- var rates = input !== null && input !== void 0 ? input : {};
39
- // API가 Decimal을 문자열("1500.0000000000")로 내려주는 경우가 있어 숫자로 강제 변환한다
40
- var baseRateRaw = rates[baseCurrency];
41
- var baseRate = baseRateRaw === undefined ? 1 : Number(baseRateRaw);
42
- if (!Number.isFinite(baseRate) || baseRate <= 0) {
43
- throw new Error("createPricingPolicy: invalid exchange rate for ".concat(baseCurrency));
44
- }
45
- var normalized = (_a = {}, _a[baseCurrency] = 1, _a);
46
- altCurrencies.forEach(function (code) {
47
- var rateRaw = rates[code];
48
- if (rateRaw === undefined || rateRaw === null) {
49
- throw new Error("createPricingPolicy: missing exchange rate for ".concat(code));
50
- }
51
- var rate = Number(rateRaw);
52
- if (!Number.isFinite(rate) || rate <= 0) {
53
- throw new Error("createPricingPolicy: invalid exchange rate for ".concat(code));
54
- }
55
- normalized[code] = rate / baseRate;
56
- });
57
- return normalized;
58
- }
59
- function createPricingPolicy(input) {
60
- var _a, _b;
61
- var altCurrencies = ((_a = input.altCurrencies) !== null && _a !== void 0 ? _a : []).filter(function (code, index, list) { return code !== input.baseCurrency && list.indexOf(code) === index; });
62
- var currencies = __spreadArray([input.baseCurrency], altCurrencies, true);
63
- var policies = {};
64
- currencies.forEach(function (code) {
65
- policies[code] = buildCurrencyPolicy(code, input);
66
- });
67
- return {
68
- baseCurrency: input.baseCurrency,
69
- currencies: currencies,
70
- exchangeRates: normalizeExchangeRates(input.baseCurrency, altCurrencies, input.exchangeRates),
71
- multiCurrency: (_b = input.multiCurrency) !== null && _b !== void 0 ? _b : altCurrencies.length > 0,
72
- policies: policies
73
- };
74
- }
75
- exports.createPricingPolicy = createPricingPolicy;
76
- /** Provider가 없을 때 쓰는 기본 정책: KRW 단일 통화 */
77
- exports.DEFAULT_PRICING_POLICY = createPricingPolicy({
78
- baseCurrency: types_1.CurrencyCode.KRW
79
- });
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- import type { NewPriceTextFieldProps } from '../../../core/pricing';
3
- /**
4
- * 문서: Web - PriceTextField (Added in 2.2)
5
- * 통화 정책은 PricingPolicyProvider에서 받고, 값은 react-hook-form 폼이 단일 원천이다.
6
- */
7
- declare function NewPriceTextField(props: NewPriceTextFieldProps): JSX.Element;
8
- export default NewPriceTextField;