pds-dev-kit-web 2.2.319-alpha.2 → 2.2.320-trialguard.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.
Files changed (91) hide show
  1. package/dist/index.d.ts +4 -6
  2. package/dist/index.js +2 -11
  3. package/dist/src/common/utils/sanitizeHtml.d.ts +2 -0
  4. package/dist/src/common/utils/sanitizeHtml.js +47 -0
  5. package/dist/src/core/pricing/index.d.ts +0 -4
  6. package/dist/src/core/pricing/index.js +0 -4
  7. package/dist/src/desktop/components/RichTextEditor/HTMLReader.js +2 -1
  8. package/dist/src/desktop/components/index.d.ts +1 -2
  9. package/dist/src/desktop/components/index.js +2 -4
  10. package/dist/src/desktop/index.d.ts +1 -1
  11. package/dist/src/desktop/index.js +1 -2
  12. package/dist/src/desktop/panels/LocalizedContentModal/LocalizedContentModal.js +2 -1
  13. package/dist/src/mobile/components/index.d.ts +1 -2
  14. package/dist/src/mobile/components/index.js +1 -3
  15. package/dist/src/mobile/index.d.ts +1 -1
  16. package/dist/src/mobile/index.js +1 -2
  17. package/dist/src/sub/DynamicLayout/DynamicLayout.d.ts +1 -1
  18. package/dist/src/sub/DynamicLayout/DynamicLayout.js +3 -2
  19. package/dist/src/sub/DynamicLayout/components/ComponentBlocks/RichText/RichText.js +2 -1
  20. package/dist/src/sub/DynamicLayout/components/desktop/Item/Item.js +2 -1
  21. package/dist/src/sub/DynamicLayout/components/mobile/Item/Item.js +2 -1
  22. package/dist/src/sub/DynamicLayout/sections/CustomSection/components/ComponentBlock/componentBlocks/Button/Button.js +3 -2
  23. package/dist/src/sub/DynamicLayout/sections/CustomSection/components/ComponentBlock/componentBlocks/Embed/EmbedIframe.d.ts +6 -0
  24. package/dist/src/sub/DynamicLayout/sections/CustomSection/components/ComponentBlock/componentBlocks/Embed/EmbedIframe.js +7 -15
  25. package/dist/src/sub/DynamicLayout/sections/CustomSection/components/ComponentBlock/componentBlocks/Text/Text.js +3 -2
  26. package/dist/src/sub/DynamicLayout/sections/FullscreenIframeSection/templates/TemplateA/desktop/D_TemplateA.js +9 -14
  27. package/dist/src/sub/DynamicLayout/sections/FullscreenIframeSection/templates/TemplateA/mobile/M_TemplateA.js +9 -14
  28. package/dist/src/sub/DynamicLayout/types.d.ts +2 -0
  29. package/package.json +3 -6
  30. package/release-note.md +3 -11
  31. package/dist/src/core/pricing/hooks/useNewPriceTextField.d.ts +0 -68
  32. package/dist/src/core/pricing/hooks/useNewPriceTextField.js +0 -210
  33. package/dist/src/core/pricing/input-utils.d.ts +0 -32
  34. package/dist/src/core/pricing/input-utils.js +0 -119
  35. package/dist/src/core/pricing/policy-context.d.ts +0 -14
  36. package/dist/src/core/pricing/policy-context.js +0 -35
  37. package/dist/src/core/pricing/policy-model.d.ts +0 -39
  38. package/dist/src/core/pricing/policy-model.js +0 -79
  39. package/dist/src/desktop/components/NewPriceTextField/NewPriceTextField.d.ts +0 -8
  40. package/dist/src/desktop/components/NewPriceTextField/NewPriceTextField.js +0 -240
  41. package/dist/src/desktop/components/NewPriceTextField/index.d.ts +0 -1
  42. package/dist/src/desktop/components/NewPriceTextField/index.js +0 -8
  43. package/dist/src/mobile/components/NewPriceTextField/NewPriceTextField.d.ts +0 -8
  44. package/dist/src/mobile/components/NewPriceTextField/NewPriceTextField.js +0 -234
  45. package/dist/src/mobile/components/NewPriceTextField/index.d.ts +0 -1
  46. package/dist/src/mobile/components/NewPriceTextField/index.js +0 -8
  47. package/dist/storybook-static/0.b73eaee9a88f178d62ed.manager.bundle.d.ts +0 -0
  48. package/dist/storybook-static/0.b73eaee9a88f178d62ed.manager.bundle.js +0 -74
  49. package/dist/storybook-static/1.f296d183a17268696d73.manager.bundle.d.ts +0 -0
  50. package/dist/storybook-static/1.f296d183a17268696d73.manager.bundle.js +0 -190
  51. package/dist/storybook-static/10.9998ba67d65d81d20896.manager.bundle.d.ts +0 -0
  52. package/dist/storybook-static/10.9998ba67d65d81d20896.manager.bundle.js +0 -62
  53. package/dist/storybook-static/11.49c687eaa6261f8b7be2.manager.bundle.d.ts +0 -2
  54. package/dist/storybook-static/11.49c687eaa6261f8b7be2.manager.bundle.js +0 -534
  55. package/dist/storybook-static/12.c9538ed3766c96f289e7.manager.bundle.d.ts +0 -2
  56. package/dist/storybook-static/12.c9538ed3766c96f289e7.manager.bundle.js +0 -2
  57. package/dist/storybook-static/5.fa71488e730c5c7f885f.manager.bundle.d.ts +0 -18
  58. package/dist/storybook-static/5.fa71488e730c5c7f885f.manager.bundle.js +0 -527
  59. package/dist/storybook-static/6.8096ae4aadde0743697b.manager.bundle.d.ts +0 -3
  60. package/dist/storybook-static/6.8096ae4aadde0743697b.manager.bundle.js +0 -141
  61. package/dist/storybook-static/7.b34baecbd082bc7b188d.manager.bundle.d.ts +0 -0
  62. package/dist/storybook-static/7.b34baecbd082bc7b188d.manager.bundle.js +0 -8
  63. package/dist/storybook-static/8.15577edffecf900a8de2.manager.bundle.d.ts +0 -0
  64. package/dist/storybook-static/8.15577edffecf900a8de2.manager.bundle.js +0 -25
  65. package/dist/storybook-static/9.d7d85aa0a49a98f17218.manager.bundle.d.ts +0 -0
  66. package/dist/storybook-static/9.d7d85aa0a49a98f17218.manager.bundle.js +0 -94
  67. package/dist/storybook-static/main.ce406c7e93b98325390e.manager.bundle.d.ts +0 -2
  68. package/dist/storybook-static/main.ce406c7e93b98325390e.manager.bundle.js +0 -3824
  69. package/dist/storybook-static/runtime~main.909d038f912f063e8837.manager.bundle.d.ts +0 -1
  70. package/dist/storybook-static/runtime~main.909d038f912f063e8837.manager.bundle.js +0 -34
  71. package/dist/storybook-static/vendors~main.d3455eed64b243c89325.manager.bundle.d.ts +0 -3
  72. package/dist/storybook-static/vendors~main.d3455eed64b243c89325.manager.bundle.js +0 -11787
  73. package/storybook-static/0.b73eaee9a88f178d62ed.manager.bundle.js +0 -1
  74. package/storybook-static/1.f296d183a17268696d73.manager.bundle.js +0 -1
  75. package/storybook-static/10.9998ba67d65d81d20896.manager.bundle.js +0 -1
  76. package/storybook-static/11.49c687eaa6261f8b7be2.manager.bundle.js +0 -2
  77. package/storybook-static/11.49c687eaa6261f8b7be2.manager.bundle.js.LICENSE.txt +0 -12
  78. package/storybook-static/12.c9538ed3766c96f289e7.manager.bundle.js +0 -1
  79. package/storybook-static/5.fa71488e730c5c7f885f.manager.bundle.js +0 -2
  80. package/storybook-static/5.fa71488e730c5c7f885f.manager.bundle.js.LICENSE.txt +0 -8
  81. package/storybook-static/6.8096ae4aadde0743697b.manager.bundle.js +0 -1
  82. package/storybook-static/7.b34baecbd082bc7b188d.manager.bundle.js +0 -1
  83. package/storybook-static/8.15577edffecf900a8de2.manager.bundle.js +0 -1
  84. package/storybook-static/9.d7d85aa0a49a98f17218.manager.bundle.js +0 -1
  85. package/storybook-static/favicon.ico +0 -0
  86. package/storybook-static/index.html +0 -47
  87. package/storybook-static/main.ce406c7e93b98325390e.manager.bundle.js +0 -1
  88. package/storybook-static/runtime~main.909d038f912f063e8837.manager.bundle.js +0 -1
  89. package/storybook-static/vendors~main.d3455eed64b243c89325.manager.bundle.js +0 -2
  90. package/storybook-static/vendors~main.d3455eed64b243c89325.manager.bundle.js.LICENSE.txt +0 -88
  91. package/vitest.config.ts +0 -8
@@ -5,25 +5,20 @@ var react_1 = require("react");
5
5
  var DynamicLayout_1 = require("../../../../../../DynamicLayout");
6
6
  var Section_1 = require("../../../../../components/Section");
7
7
  function TemplateA() {
8
- var sectionActionHandler = (0, react_1.useContext)(DynamicLayout_1.dynamicLayoutContext).sectionActionHandler;
8
+ var _a = (0, react_1.useContext)(DynamicLayout_1.dynamicLayoutContext), sectionActionHandler = _a.sectionActionHandler, iframeRefreshKey = _a.iframeRefreshKey;
9
9
  var section = (0, react_1.useContext)(Section_1.sectionContext);
10
- var checkInvalidUrl = function (url) {
10
+ // NOTE: 섹션이 처음 그려질 때와 iframeRefreshKey가 바뀔 때만 정합니다. 다시 그려질 때마다 바꾸면 iframe 문서가 다시 로드됩니다.
11
+ var cacheKey = (0, react_1.useMemo)(function () { return String(Date.now()); }, [iframeRefreshKey]);
12
+ var iframeSrc = (0, react_1.useMemo)(function () {
11
13
  try {
12
- // eslint-disable-next-line no-new
13
- new URL(url);
14
- return false;
14
+ var url = new URL(section.properties.multiPurposeUrl);
15
+ url.searchParams.set('cache', cacheKey);
16
+ return url.toString();
15
17
  }
16
18
  catch (_a) {
17
- return true;
18
- }
19
- };
20
- var generateSrc = function (src) {
21
- var isInvalidUrl = checkInvalidUrl(src);
22
- if (isInvalidUrl) {
23
19
  return 'about:blank';
24
20
  }
25
- return "".concat(src, "?cache=").concat(new Date().getTime());
26
- };
21
+ }, [section.properties.multiPurposeUrl, cacheKey]);
27
22
  var onIframeLoad = function (event) {
28
23
  if (sectionActionHandler) {
29
24
  sectionActionHandler({
@@ -32,6 +27,6 @@ function TemplateA() {
32
27
  });
33
28
  }
34
29
  };
35
- return ((0, jsx_runtime_1.jsx)("iframe", { "x-dlayout-section-element-name": "Iframe", id: String(section.id), title: section.manifest.schema, src: generateSrc(section.properties.multiPurposeUrl), style: { border: 'none', width: '100%', height: '100%', display: 'block' }, referrerPolicy: "strict-origin", sandbox: "allow-forms allow-same-origin allow-scripts", onLoad: onIframeLoad }));
30
+ return ((0, jsx_runtime_1.jsx)("iframe", { "x-dlayout-section-element-name": "Iframe", id: String(section.id), title: section.manifest.schema, src: iframeSrc, style: { border: 'none', width: '100%', height: '100%', display: 'block' }, referrerPolicy: "strict-origin", sandbox: "allow-forms allow-same-origin allow-scripts", onLoad: onIframeLoad }));
36
31
  }
37
32
  exports.default = TemplateA;
@@ -242,6 +242,8 @@ export type DynamicLayoutProps = {
242
242
  zoomScale?: number;
243
243
  queryData?: QueryData;
244
244
  placementRestriction?: PlaceRestrictionType;
245
+ /** NOTE: 값이 바뀔 때만 Fullscreen-Iframe 섹션의 iframe을 다시 불러옵니다. (편집기의 새로고침 버튼용) */
246
+ iframeRefreshKey?: number;
245
247
  };
246
248
  export type PlaceRestrictionValue = {
247
249
  columnWInit: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pds-dev-kit-web",
3
- "version": "2.2.319-alpha.2",
3
+ "version": "2.2.320-trialguard.0",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -10,6 +10,7 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@tinymce/tinymce-react": "^4.3.0",
13
+ "dompurify": "3.4.17",
13
14
  "i18next": "^21.3.2",
14
15
  "i18next-browser-languagedetector": "^6.1.2",
15
16
  "i18next-intervalplural-postprocessor": "^3.0.0",
@@ -24,7 +25,6 @@
24
25
  },
25
26
  "scripts": {
26
27
  "build": "rm -rf ./dist && tsc && tsc-alias && npm run copy:tinymce",
27
- "test": "vitest run",
28
28
  "copy:tinymce": "node scripts/copy-tinymce.js",
29
29
  "prepare": "husky install",
30
30
  "prepack": "npm run build",
@@ -62,10 +62,8 @@
62
62
  "eslint-import-resolver-typescript": "^2.4.0",
63
63
  "eslint-plugin-better-styled-components": "^1.1.2",
64
64
  "eslint-plugin-import": "^2.23.4",
65
- "eslint-plugin-jsx-a11y": "^6.10.2",
66
65
  "eslint-plugin-prettier": "^4.0.0",
67
66
  "eslint-plugin-react": "^7.24.0",
68
- "eslint-plugin-react-hooks": "^4.6.2",
69
67
  "google-spreadsheet": "^3.1.15",
70
68
  "husky": "^8.0.3",
71
69
  "lint-staged": "^11.0.0",
@@ -81,8 +79,7 @@
81
79
  "stylelint-order": "^6.0.4",
82
80
  "tsc-alias": "^1.8.3",
83
81
  "tsconfig-paths": "^4.1.2",
84
- "typescript": "^4.9.5",
85
- "vitest": "^1.6.1"
82
+ "typescript": "^4.9.5"
86
83
  },
87
84
  "peerDependencies": {
88
85
  "react": "^17.0.2 || ^18.0.0",
package/release-note.md CHANGED
@@ -1,15 +1,7 @@
1
1
  # PDS-DEV-KIT-WEB Release Notes
2
- ## [unreleased]
3
-
4
- ### 업데이트 사항
5
- * NewPriceTextField(D_/M_) 추가 — Web - PriceTextField (2.2) 문서 스펙대로 새로 작성. 통화 정책은 PricingPolicyProvider로 공급하며, 폼 값이 단일 원천이라 외부 setValue/reset이 즉시 반영됨. 기존 PriceTextField는 변경 없음.
6
- * 통화 정책 API 추가 — createPricingPolicy, PricingPolicyProvider, usePricingPolicy
7
-
8
- ## [v2.2.318]
2
+ ## [v2.2.319]
9
3
  ## daily|https://design.storybook.publ.biz/
10
4
 
11
5
  ### 업데이트 사항
12
- * React 18 앱에서 React가 중복 설치되어 TextField 등 폼 컴포넌트가 동작하지 않던 문제 수정 (react, react-dom, styled-components, react-hook-form, react-router-dom을 peerDependencies로 전환)
13
- * 사용하는 앱에 함께 설치되던 불필요한 의존성 제거 (react-scripts, 테스트·타입 패키지 등)
14
- * nuka-carousel 5 업그레이드 (ImageSlide, React 18 지원)
15
- * Storybook·Chromatic 제거, 패키지 빌드를 배포 시점(prepack)으로 이동
6
+ * Fullscreen-Iframe 섹션이 화면을 다시 그릴 때마다 iframe을 다시 불러오던 문제 수정 (주소에 ?·#이 있을 때 cache 값이 잘못 붙던 문제 포함)
7
+ * DynamicLayout에 iframeRefreshKey 추가: 값이 바뀔 때만 iframe을 다시 불러옴 (편집기 새로고침 버튼용)
@@ -1,68 +0,0 @@
1
- /// <reference types="react" />
2
- import type { CurrencyCode } from '../types';
3
- import type { IFormValues, PDSTextType } from '../../../common/types';
4
- import type { Path } from 'react-hook-form';
5
- type InputElement = HTMLInputElement | HTMLTextAreaElement;
6
- export type NewPriceTextFieldValidation = {
7
- /** false면 필수 검증 해제, 문자열이면 그 문구로 필수 검증 */
8
- required?: boolean | string;
9
- /** 키 단위로 기본 검증(min/max/format)을 덮어쓰거나 추가한다 */
10
- validate?: Record<string, (value: string) => string | boolean | undefined>;
11
- };
12
- export type NewPriceTextFieldProps = {
13
- name: Path<IFormValues>;
14
- hintText?: PDSTextType;
15
- defaultAmount?: number;
16
- validation?: NewPriceTextFieldValidation;
17
- size?: 'large' | 'rlarge' | 'medium' | 'small';
18
- state?: 'normal' | 'read_only';
19
- responsiveMode?: 'none' | 'use';
20
- customWidth?: string;
21
- deleteBtnMode?: 'none' | 'use';
22
- useRequirementMode?: 'none' | 'use';
23
- onChange?: (e: React.ChangeEvent<InputElement>) => void;
24
- onBlur?: (e: React.FocusEvent<InputElement>) => void;
25
- onFocus?: (e: React.FocusEvent<InputElement>) => void;
26
- onKeyDown?: (e: React.KeyboardEvent<InputElement>) => void;
27
- onKeyUp?: (e: React.KeyboardEvent<InputElement>) => void;
28
- onTarget?: () => void;
29
- onCurrencyChange?: (selectedCurrency: string) => void;
30
- onValueChange?: (data: {
31
- selectedCurrency: string;
32
- baseCurrencyValue: number;
33
- calculatedValue: number;
34
- displayValue: string;
35
- }) => void;
36
- };
37
- export type CurrencyOption = {
38
- value: CurrencyCode;
39
- text: string;
40
- currency: CurrencyCode;
41
- state: 'normal';
42
- };
43
- export declare function useNewPriceTextField({ name, hintText, defaultAmount, validation, state, useRequirementMode, onChange, onBlur, onFocus, onKeyDown, onKeyUp, onTarget, onCurrencyChange, onValueChange }: NewPriceTextFieldProps): {
44
- hintText: string | number | object | null | undefined;
45
- displayValue: string;
46
- rules: {
47
- required: string | boolean;
48
- validate: Record<string, (value: string) => string | boolean | undefined>;
49
- };
50
- errorMessage: string | undefined;
51
- isFocused: boolean;
52
- isInputReadOnly: boolean;
53
- baseCurrency: CurrencyCode;
54
- selectedCurrency: CurrencyCode;
55
- currencyOptions: CurrencyOption[];
56
- dropdownState: "normal" | "read_only";
57
- handlers: {
58
- onChange: (e: React.ChangeEvent<InputElement>) => void;
59
- onBlur: (e: React.FocusEvent<InputElement>) => void;
60
- onFocus: (e: React.FocusEvent<InputElement>) => void;
61
- onKeyDown: ((e: import("react").KeyboardEvent<InputElement>) => void) | undefined;
62
- onKeyUp: ((e: import("react").KeyboardEvent<InputElement>) => void) | undefined;
63
- onTarget: () => void | undefined;
64
- onDelete: () => void;
65
- selectCurrency: (currency: CurrencyCode) => void;
66
- };
67
- };
68
- export {};
@@ -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;