@tide-design/components 0.22.0 → 0.24.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.
@@ -31,9 +31,9 @@ type NumberFormatInputModeProps = {
31
31
  } | (Required<Pick<MaskFormatOptions, "mask">> & WithoutNumericOptions);
32
32
  export type NumberFormatInputProps = NumberFormatInputModeProps & NumberFormatInputOwnProps & Omit<ComponentProps<"input">, keyof NumberFormatInputOwnProps | "type" | "pattern" | "children" | "dangerouslySetInnerHTML">;
33
33
  /**
34
- * 칠 때 바로 포맷하는 숫자 입력. 천 단위 구분자·prefix·suffix·소수 자릿수(숫자 모드)와
34
+ * 칠 때 바로 포맷하는 숫자 입력. 자릿수 묶음·prefix·suffix·소수 자릿수(숫자 모드)와
35
35
  * `mask` 틀(패턴 모드)을 다룬다. `<input type="text">`이고 Field 안에서 label·설명·오류가 연결된다.
36
36
  * Tide props: `mask`, `value`, `defaultValue`, `onValueChange`, `size`, `invalid`, `prefix`, `suffix`, `decimalPlaces`, `fixedDecimalPlaces`, `allowNegative`, `groupStyle`, `groupSeparator`, `decimalSeparator`, `locale` ({@link NumberFormatInputOwnProps}). 나머지는 `<input>` 속성.
37
37
  */
38
- export declare function NumberFormatInput({ mask, value, defaultValue, onValueChange, prefix, suffix, decimalPlaces, fixedDecimalPlaces, allowNegative, groupStyle, groupSeparator, decimalSeparator, locale, inputMode, ref, onCompositionStart, onInput, ...props }: NumberFormatInputProps): ReactElement;
38
+ export declare function NumberFormatInput({ mask, value, defaultValue, onValueChange, prefix, suffix, decimalPlaces, fixedDecimalPlaces, allowNegative, groupStyle, groupSeparator, decimalSeparator, locale, inputMode, ref, onInput, onChange, ...props }: NumberFormatInputProps): ReactElement;
39
39
  export {};
@@ -1,74 +1,81 @@
1
1
  "use client";
2
2
 
3
3
  import { Input } from "../Input/Input.js";
4
- import { MaskModeInput } from "./components/MaskModeInput.js";
5
- import { NumericModeInput } from "./components/NumericModeInput.js";
6
- import { useNumberCompositionGuard } from "./hooks/useNumberCompositionGuard.js";
7
- import { maskDigits } from "./libs/maskFormat.js";
8
- import { toNumericString } from "./libs/numericFormat.js";
4
+ import { useNumberText } from "./hooks/useNumberText.js";
5
+ import { createInputGuard } from "./libs/inputGuard.js";
6
+ import { createMaskFormatter } from "./libs/maskFormatter.js";
7
+ import { createNumericFormatter } from "./libs/numericFormatter.js";
9
8
  import { jsx } from "react/jsx-runtime";
10
- import { useRef } from "react";
9
+ import { useLayoutEffect, useMemo, useRef } from "react";
10
+ import { useMaskito } from "@maskito/react";
11
+ import { mergeRefs } from "react-aria";
11
12
 
12
13
  // src/NumberFormatInput/NumberFormatInput.tsx
13
14
  /**
14
- * 칠 때 바로 포맷하는 숫자 입력. 천 단위 구분자·prefix·suffix·소수 자릿수(숫자 모드)와
15
+ * 칠 때 바로 포맷하는 숫자 입력. 자릿수 묶음·prefix·suffix·소수 자릿수(숫자 모드)와
15
16
  * `mask` 틀(패턴 모드)을 다룬다. `<input type="text">`이고 Field 안에서 label·설명·오류가 연결된다.
16
17
  * Tide props: `mask`, `value`, `defaultValue`, `onValueChange`, `size`, `invalid`, `prefix`, `suffix`, `decimalPlaces`, `fixedDecimalPlaces`, `allowNegative`, `groupStyle`, `groupSeparator`, `decimalSeparator`, `locale` ({@link NumberFormatInputOwnProps}). 나머지는 `<input>` 속성.
17
18
  */
18
- function NumberFormatInput({ mask, value, defaultValue, onValueChange, prefix, suffix, decimalPlaces, fixedDecimalPlaces, allowNegative, groupStyle, groupSeparator, decimalSeparator, locale, inputMode, ref, onCompositionStart, onInput, ...props }) {
19
- const compositionGuard = useNumberCompositionGuard({
20
- onCompositionStart,
21
- onInput
19
+ function NumberFormatInput({ mask, value, defaultValue, onValueChange, prefix, suffix, decimalPlaces, fixedDecimalPlaces, allowNegative, groupStyle, groupSeparator, decimalSeparator, locale, inputMode, ref, onInput, onChange, ...props }) {
20
+ const formatterKey = JSON.stringify(mask === void 0 ? {
21
+ prefix,
22
+ suffix,
23
+ decimalPlaces,
24
+ fixedDecimalPlaces,
25
+ allowNegative,
26
+ groupStyle,
27
+ groupSeparator,
28
+ decimalSeparator,
29
+ locale
30
+ } : { mask });
31
+ const formatter = useMemo(() => {
32
+ const options = JSON.parse(formatterKey);
33
+ return options.mask === void 0 ? createNumericFormatter(options) : createMaskFormatter(options.mask);
34
+ }, [formatterKey]);
35
+ const text = useNumberText({
36
+ formatter,
37
+ formatterKey,
38
+ value,
39
+ defaultValue,
40
+ onValueChange
22
41
  });
23
- const lastEmitted = useRef(null);
24
- const toDigits = (input) => {
25
- if (typeof input === "number") return mask === void 0 ? toNumericString(input, decimalPlaces) : String(input);
26
- return mask === void 0 ? input : maskDigits(input);
27
- };
28
- const libraryValue = value === void 0 ? void 0 : lastEmitted.current && Object.is(value, lastEmitted.current.value) ? lastEmitted.current.digits : value === null ? "" : toDigits(value);
29
- const handleValueChange = (values, { source }) => {
30
- if (source !== "event") return;
31
- const next = mask === void 0 ? values.floatValue ?? null : values.value === "" ? null : Number(values.value);
32
- lastEmitted.current = {
33
- value: next,
34
- digits: values.value
35
- };
36
- onValueChange?.({
37
- value: next,
38
- formattedValue: values.formattedValue,
39
- digits: values.value
40
- });
41
- };
42
- const shared = {
42
+ const { committedText, isDraft, onCompositionChange } = text;
43
+ const maskitoOptions = useMemo(() => ({
44
+ ...formatter.maskOptions,
45
+ plugins: [createInputGuard({
46
+ accepts: formatter.accepts,
47
+ getCommittedText: () => committedText.current,
48
+ onCompositionChange
49
+ }), ...formatter.maskOptions.plugins ?? []]
50
+ }), [
51
+ formatter,
52
+ committedText,
53
+ onCompositionChange
54
+ ]);
55
+ const maskitoRef = useMaskito({ options: maskitoOptions });
56
+ const inputRef = useRef(null);
57
+ const mergedRef = useMemo(() => mergeRefs(ref, maskitoRef, inputRef), [ref, maskitoRef]);
58
+ useLayoutEffect(() => {
59
+ const element = inputRef.current;
60
+ if (!isDraft && element?.matches(":focus")) formatter.limitCaret?.(element);
61
+ }, [
62
+ formatter,
63
+ isDraft,
64
+ text.text
65
+ ]);
66
+ return /* @__PURE__ */ jsx(Input, {
43
67
  ...props,
44
- ...compositionGuard,
68
+ ref: mergedRef,
45
69
  type: "text",
46
70
  inputMode: inputMode ?? (mask !== void 0 || decimalPlaces === 0 ? "numeric" : allowNegative ? void 0 : "decimal"),
47
- customInput: Input,
48
- getInputRef: ref,
49
- value: libraryValue,
50
- defaultValue: defaultValue === void 0 || defaultValue === null ? defaultValue : toDigits(defaultValue),
51
- valueIsNumericString: true,
52
- onValueChange: handleValueChange
53
- };
54
- if (mask !== void 0) return /* @__PURE__ */ jsx(MaskModeInput, {
55
- ...shared,
56
- mask
57
- });
58
- return /* @__PURE__ */ jsx(NumericModeInput, {
59
- ...shared,
60
- options: {
61
- prefix,
62
- suffix,
63
- decimalPlaces,
64
- fixedDecimalPlaces,
65
- allowNegative,
66
- groupStyle,
67
- groupSeparator,
68
- decimalSeparator,
69
- locale
70
- }
71
+ value: text.text,
72
+ onInput: (event) => {
73
+ text.onInput(event);
74
+ onInput?.(event);
75
+ },
76
+ onChange: onChange ?? noop
71
77
  });
72
78
  }
79
+ function noop() {}
73
80
 
74
81
  export { NumberFormatInput };
@@ -0,0 +1,80 @@
1
+ "use client";
2
+
3
+ import { useCallback, useLayoutEffect, useRef, useState } from "react";
4
+
5
+ // src/NumberFormatInput/hooks/useNumberText.ts
6
+ /** 화면 글자와 바깥 `value`를 맞추고 사용자가 바꾼 값만 알린다. 조합 중에는 알리지 않는다. */
7
+ function useNumberText({ formatter, formatterKey, value, defaultValue, onValueChange }) {
8
+ const fromOutside = (next) => {
9
+ const text = next === null || next === void 0 ? "" : formatter.format(formatter.fromValue(next));
10
+ return {
11
+ text,
12
+ digits: formatter.parse(text),
13
+ pending: [],
14
+ outside: value,
15
+ formatterKey
16
+ };
17
+ };
18
+ const [stored, setStored] = useState(() => fromOutside(value ?? defaultValue));
19
+ let state = stored;
20
+ if (state.formatterKey !== formatterKey) {
21
+ const text = formatter.format(state.digits);
22
+ state = {
23
+ ...state,
24
+ text,
25
+ digits: formatter.parse(text),
26
+ formatterKey
27
+ };
28
+ }
29
+ if (value !== void 0 && !Object.is(value, state.outside)) {
30
+ const returned = state.pending.findIndex((change) => Object.is(change.value, value) || Object.is(change.digits, value));
31
+ state = returned === -1 ? fromOutside(value) : {
32
+ ...state,
33
+ outside: value,
34
+ pending: state.pending.slice(returned + 1)
35
+ };
36
+ }
37
+ if (state !== stored) setStored(state);
38
+ const [draft, setDraft] = useState(null);
39
+ const composing = useRef(false);
40
+ const committedText = useRef(state.text);
41
+ const onCompositionChange = useCallback((next) => {
42
+ composing.current = next;
43
+ }, []);
44
+ useLayoutEffect(() => {
45
+ committedText.current = state.text;
46
+ }, [state.text]);
47
+ const commit = (text) => {
48
+ setDraft(null);
49
+ if (text === committedText.current) return;
50
+ committedText.current = text;
51
+ const digits = formatter.parse(text);
52
+ const next = formatter.toValue(digits);
53
+ setStored((previous) => ({
54
+ ...previous,
55
+ text,
56
+ digits,
57
+ pending: [...previous.pending.slice(-50), {
58
+ value: next,
59
+ digits
60
+ }]
61
+ }));
62
+ onValueChange?.({
63
+ value: next,
64
+ formattedValue: text,
65
+ digits
66
+ });
67
+ };
68
+ return {
69
+ text: draft ?? state.text,
70
+ isDraft: draft !== null,
71
+ committedText,
72
+ onCompositionChange,
73
+ onInput: (event) => {
74
+ if (composing.current) setDraft(event.currentTarget.value);
75
+ else commit(event.currentTarget.value);
76
+ }
77
+ };
78
+ }
79
+
80
+ export { useNumberText };
@@ -1,3 +1,2 @@
1
1
  import { NumberFormatInput, NumberFormatInputOwnProps, NumberFormatInputProps } from "./NumberFormatInput.js";
2
- import { NumberGroupStyle } from "./types.js";
3
- export { NumberFormatInput, type NumberFormatInputOwnProps, type NumberFormatInputProps, type NumberGroupStyle };
2
+ export { NumberFormatInput, type NumberFormatInputOwnProps, type NumberFormatInputProps };
@@ -0,0 +1,32 @@
1
+ import { maskitoCaretGuard } from "@maskito/kit";
2
+
3
+ // src/NumberFormatInput/libs/caretGuard.ts
4
+ /**
5
+ * 커서를 `getCaretRange`의 범위 안에 둔다. 선택은 제한하지 않아 전체를 선택해 복사할 수 있다.
6
+ * Chromium은 `selectionchange`를 다음 글자보다 늦게 보낼 수 있어 `keydown`에서도 옮긴다(ADR 0043).
7
+ */
8
+ function createCaretGuard(getCaretRange) {
9
+ const getLimits = (value, [from, to]) => from === to ? getCaretRange(value) : [0, value.length];
10
+ const limitCaret = (element) => {
11
+ const from = element.selectionStart ?? 0;
12
+ const [start, end] = getLimits(element.value, [from, element.selectionEnd ?? from]);
13
+ const next = Math.min(Math.max(from, start), end);
14
+ if (next !== from) element.setSelectionRange(next, next);
15
+ };
16
+ return {
17
+ limitCaret,
18
+ plugin: (element, options) => {
19
+ const stop = maskitoCaretGuard(getLimits)(element, options);
20
+ const onKeyDown = (event) => {
21
+ if (!event.isComposing) limitCaret(element);
22
+ };
23
+ element.addEventListener("keydown", onKeyDown, { capture: true });
24
+ return () => {
25
+ stop?.();
26
+ element.removeEventListener("keydown", onKeyDown, { capture: true });
27
+ };
28
+ }
29
+ };
30
+ }
31
+
32
+ export { createCaretGuard };
@@ -0,0 +1,44 @@
1
+ // src/NumberFormatInput/libs/fieldEdit.ts
2
+ /** `before`가 `after`로 바뀔 때 고친 범위와 새로 들어간 글자. 같은 숫자가 이어져도 맞도록 바뀐 뒤의 커서로 끝을 정한다. */
3
+ function findEdit(before, after) {
4
+ const tail = after.value.slice(after.selection[1]);
5
+ let tailLength = tail.length;
6
+ if (!before.value.endsWith(tail)) {
7
+ tailLength = 0;
8
+ while (tailLength < Math.min(before.value.length, after.value.length) && before.value.at(-1 - tailLength) === after.value.at(-1 - tailLength)) tailLength += 1;
9
+ }
10
+ const to = before.value.length - tailLength;
11
+ const afterEnd = after.value.length - tailLength;
12
+ const limit = Math.min(before.selection[0], to, afterEnd);
13
+ let from = 0;
14
+ while (from < limit && before.value.charAt(from) === after.value.charAt(from)) from += 1;
15
+ return {
16
+ from,
17
+ to,
18
+ text: after.value.slice(from, afterEnd)
19
+ };
20
+ }
21
+ /** `beforeinput`이 알려 준 변경. 선택이 없으면 Backspace는 앞 글자, Delete는 뒤 글자를 지운다. */
22
+ function intendedEdit(inputType, data, { value, selection: [from, to] }) {
23
+ if (inputType.startsWith("insert")) return {
24
+ from,
25
+ to,
26
+ text: data ?? ""
27
+ };
28
+ if (from !== to) return {
29
+ from,
30
+ to,
31
+ text: ""
32
+ };
33
+ return inputType === "deleteContentForward" ? {
34
+ from,
35
+ to: Math.min(to + 1, value.length),
36
+ text: ""
37
+ } : {
38
+ from: Math.max(from - 1, 0),
39
+ to,
40
+ text: ""
41
+ };
42
+ }
43
+
44
+ export { findEdit, intendedEdit };
@@ -1,5 +1,6 @@
1
1
  import { applyMask, maskDigits, sortMasks } from "./maskFormat.js";
2
- import { toLibraryNumericOptions, toNumericString } from "./numericFormat.js";
2
+ import { resolveSeparators, toNumericString } from "./numericFormat.js";
3
+ import { splitDigits } from "./splitDigits.js";
3
4
  import { numericFormatter } from "react-number-format";
4
5
 
5
6
  // src/NumberFormatInput/libs/formatNumber.ts
@@ -10,8 +11,26 @@ import { numericFormatter } from "react-number-format";
10
11
  function formatNumber(value, options = {}) {
11
12
  if (value === null || value === void 0 || Number.isNaN(value)) return "";
12
13
  if (options.mask !== void 0) return applyMask(maskDigits(String(value)), sortMasks(options.mask));
13
- const numStr = typeof value === "number" ? toNumericString(value, options.decimalPlaces) : value;
14
- return numericFormatter(numStr, toLibraryNumericOptions(options));
14
+ return formatNumeric(typeof value === "number" ? toNumericString(value, options.decimalPlaces) : value, options);
15
+ }
16
+ /**
17
+ * react-number-format은 정해진 묶음만 지원해 소수 자리·부호만 맡기고, 묶음은 Tide가 한다.
18
+ * prefix·suffix 안의 숫자나 점을 건드리지 않도록 묶은 뒤에 붙인다.
19
+ */
20
+ function formatNumeric(numStr, options) {
21
+ if (numStr === "" || numStr === "-") return numStr;
22
+ const { prefix = "", suffix = "", allowNegative = false } = options;
23
+ const { groupSize, group, decimal } = resolveSeparators(options);
24
+ const plain = numericFormatter(numStr, {
25
+ decimalScale: options.decimalPlaces,
26
+ fixedDecimalScale: options.fixedDecimalPlaces ?? false,
27
+ allowNegative,
28
+ decimalSeparator: "."
29
+ });
30
+ const sign = allowNegative && plain.startsWith("-") ? "-" : "";
31
+ const [integer = "", fraction] = plain.slice(sign.length).split(".");
32
+ const [zeros = ""] = /^[^1-9]*/.exec(integer) ?? [];
33
+ return `${sign}${prefix}${zeros}${integer.slice(zeros.length).replace(/\d+/g, (digits) => splitDigits(digits, groupSize).join(group))}${fraction === void 0 ? "" : `${decimal}${fraction}`}${suffix}`;
15
34
  }
16
35
 
17
36
  export { formatNumber };
@@ -0,0 +1,140 @@
1
+ import { findEdit, intendedEdit } from "./fieldEdit.js";
2
+
3
+ // src/NumberFormatInput/libs/inputGuard.ts
4
+ const replayableTypes = /* @__PURE__ */ new Set([
5
+ "insertText",
6
+ "insertCompositionText",
7
+ "insertFromComposition",
8
+ "deleteContentBackward",
9
+ "deleteContentForward",
10
+ "deleteCompositionText"
11
+ ]);
12
+ function readState(element) {
13
+ const { value, selectionStart, selectionEnd } = element;
14
+ return {
15
+ value,
16
+ selection: [selectionStart ?? value.length, selectionEnd ?? value.length]
17
+ };
18
+ }
19
+ function writeState(element, { value, selection }) {
20
+ if (element.value !== value) element.value = value;
21
+ if (element.matches(":focus")) element.setSelectionRange(selection[0], selection[1]);
22
+ }
23
+ /**
24
+ * Maskito가 `beforeinput`에서 막거나 계산하지 못한 변경(취소할 수 없는 입력, `beforeinput` 없는 입력, 조합)을
25
+ * 입력 전 상태로 되돌린 뒤 같은 변경을 Maskito의 `beforeinput` 처리에 다시 넘긴다. 타이머는 쓰지 않는다.
26
+ * Maskito보다 먼저 이벤트를 받아야 하므로 plugins의 맨 앞에 둔다(ADR 0043).
27
+ */
28
+ function createInputGuard(handlers) {
29
+ return (element) => {
30
+ const abort = new AbortController();
31
+ const { signal } = abort;
32
+ let known = readState(element);
33
+ let pending = null;
34
+ let composition = null;
35
+ let replaying = false;
36
+ const replay = (before, inputType, edit) => {
37
+ const isDeletion = edit.text === "";
38
+ replaying = true;
39
+ element.dispatchEvent(new InputEvent("input", { inputType: "insertCompositionText" }));
40
+ writeState(element, {
41
+ value: before.value,
42
+ selection: [edit.from, edit.to]
43
+ });
44
+ const event = new InputEvent("beforeinput", {
45
+ cancelable: true,
46
+ inputType: !isDeletion ? "insertText" : inputType === "deleteContentForward" ? inputType : "deleteContentBackward",
47
+ data: isDeletion ? null : edit.text
48
+ });
49
+ const accepted = !(isDeletion && edit.from === edit.to) && element.dispatchEvent(event);
50
+ replaying = false;
51
+ if (!accepted && !isDeletion) writeState(element, before);
52
+ };
53
+ const startComposition = () => {
54
+ composition = {
55
+ state: readState(element),
56
+ committed: handlers.getCommittedText()
57
+ };
58
+ handlers.onCompositionChange(true);
59
+ };
60
+ const endComposition = () => {
61
+ composition = null;
62
+ known = readState(element);
63
+ handlers.onCompositionChange(false);
64
+ };
65
+ const finishComposition = () => {
66
+ if (!composition) return;
67
+ const { state, committed } = composition;
68
+ pending = null;
69
+ const external = handlers.getCommittedText();
70
+ if (external !== committed) writeState(element, {
71
+ value: external,
72
+ selection: [external.length, external.length]
73
+ });
74
+ else if (element.value !== state.value) {
75
+ const edit = findEdit(state, readState(element));
76
+ if (edit.text === "" && state.selection[0] !== state.selection[1]) writeState(element, state);
77
+ else replay(state, "insertText", edit);
78
+ }
79
+ endComposition();
80
+ element.dispatchEvent(new InputEvent("input", {
81
+ bubbles: true,
82
+ inputType: "insertText"
83
+ }));
84
+ known = readState(element);
85
+ };
86
+ element.addEventListener("beforeinput", (event) => {
87
+ if (replaying || !event.isTrusted) return;
88
+ const { isComposing } = event;
89
+ if (composition && !isComposing) finishComposition();
90
+ else if (!composition && isComposing) startComposition();
91
+ if (composition) return;
92
+ pending = {
93
+ event,
94
+ state: readState(element)
95
+ };
96
+ }, { signal });
97
+ element.addEventListener("input", (event) => {
98
+ if (replaying || !event.isTrusted) return;
99
+ if (composition) {
100
+ const { text } = findEdit(composition.state, readState(element));
101
+ if (text !== "" && !handlers.accepts(text)) {
102
+ writeState(element, composition.state);
103
+ endComposition();
104
+ }
105
+ return;
106
+ }
107
+ const { inputType } = event;
108
+ const seen = pending;
109
+ pending = null;
110
+ if (!replayableTypes.has(inputType)) return;
111
+ const handled = seen?.event.inputType === inputType && seen.event.cancelable && !seen.event.defaultPrevented;
112
+ const before = seen?.state ?? known;
113
+ if (handled || element.value === before.value) return;
114
+ const edit = seen ? intendedEdit(seen.event.inputType, seen.event.data, before) : findEdit(before, readState(element));
115
+ replay(before, inputType, edit);
116
+ }, {
117
+ capture: true,
118
+ signal
119
+ });
120
+ element.addEventListener("input", () => {
121
+ if (!replaying && !composition) known = readState(element);
122
+ }, { signal });
123
+ element.addEventListener("compositionstart", startComposition, { signal });
124
+ element.addEventListener("compositionend", finishComposition, { signal });
125
+ element.addEventListener("blur", finishComposition, {
126
+ capture: true,
127
+ signal
128
+ });
129
+ element.addEventListener("focus", () => known = readState(element), { signal });
130
+ element.ownerDocument.addEventListener("selectionchange", () => {
131
+ if (!composition && element.matches(":focus")) known = readState(element);
132
+ }, { signal });
133
+ return () => {
134
+ if (composition) handlers.onCompositionChange(false);
135
+ abort.abort();
136
+ };
137
+ };
138
+ }
139
+
140
+ export { createInputGuard };
@@ -0,0 +1,69 @@
1
+ import { applyMask, maskDigits, maxMaskDigits, sortMasks } from "./maskFormat.js";
2
+
3
+ // src/NumberFormatInput/libs/maskFormatter.ts
4
+ const slotCount = (mask) => mask.split("#").length - 1;
5
+ /** 앞에서부터 숫자 `count`개를 지난 위치 */
6
+ function indexAfterDigits(text, count) {
7
+ let seen = 0;
8
+ for (let index = 0; index < text.length; index += 1) {
9
+ if (seen === count) return index;
10
+ if (/\d/.test(text.charAt(index))) seen += 1;
11
+ }
12
+ return text.length;
13
+ }
14
+ /** 패턴 모드 포맷 규칙. 틀은 `applyMask`로 채워 `formatNumber`와 같은 글자를 만든다. */
15
+ function createMaskFormatter(mask) {
16
+ const masks = sortMasks(mask);
17
+ const maxDigits = maxMaskDigits(masks);
18
+ const format = (digits) => applyMask(digits.slice(0, maxDigits), masks);
19
+ const digitsOnly = ({ elementState, data }, actionType) => {
20
+ if (actionType !== "insert") return {
21
+ elementState,
22
+ data
23
+ };
24
+ const { value, selection } = elementState;
25
+ const [from, to] = selection;
26
+ const digits = maskDigits(data);
27
+ const total = maskDigits(value.slice(0, from) + value.slice(to)).length + digits.length;
28
+ return digits === "" || total > maxDigits ? {
29
+ elementState: {
30
+ value,
31
+ selection: [to, to]
32
+ },
33
+ data: ""
34
+ } : {
35
+ elementState,
36
+ data: digits
37
+ };
38
+ };
39
+ const fillMask = ({ value, selection }) => {
40
+ const text = format(maskDigits(value));
41
+ if (text === value) return {
42
+ value,
43
+ selection
44
+ };
45
+ const move = (index) => indexAfterDigits(text, maskDigits(value.slice(0, index)).length);
46
+ return {
47
+ value: text,
48
+ selection: [move(selection[0]), move(selection[1])]
49
+ };
50
+ };
51
+ return {
52
+ maskOptions: {
53
+ mask: ({ value }) => {
54
+ const count = maskDigits(value).length;
55
+ const current = masks.find((item) => slotCount(item) >= count) ?? masks.at(-1) ?? "";
56
+ return Array.from(current, (char) => char === "#" ? /\d/ : char);
57
+ },
58
+ preprocessors: [digitsOnly],
59
+ postprocessors: [fillMask]
60
+ },
61
+ format,
62
+ parse: maskDigits,
63
+ toValue: (digits) => digits === "" ? null : Number(digits),
64
+ fromValue: (value) => maskDigits(String(value)),
65
+ accepts: (text) => maskDigits(text) !== ""
66
+ };
67
+ }
68
+
69
+ export { createMaskFormatter };
@@ -10,22 +10,18 @@ function localeSeparators(locale) {
10
10
  decimal: parts.find((part) => part.type === "decimal")?.value ?? "."
11
11
  };
12
12
  }
13
- /** Tide 옵션을 react-number-format 옵션으로 바꾼다. */
14
- function toLibraryNumericOptions(options) {
13
+ /** 묶을 자릿수와 구분자를 정한다. 입력 칸과 `formatNumber`가 함께 쓴다. */
14
+ function resolveSeparators(options) {
15
15
  const separators = localeSeparators(options.locale);
16
16
  const groupSeparator = options.groupSeparator ?? separators.group;
17
- const decimalSeparator = options.decimalSeparator ?? separators.decimal;
18
- const groupStyle = options.groupStyle ?? "thousand";
17
+ const decimal = options.decimalSeparator ?? separators.decimal;
18
+ const groupStyle = options.groupStyle ?? 0;
19
+ const groupSize = Number.isInteger(groupStyle) && groupStyle > 0 ? groupStyle : 0;
19
20
  return {
20
- prefix: options.prefix,
21
- suffix: options.suffix,
22
- decimalScale: options.decimalPlaces,
23
- fixedDecimalScale: options.fixedDecimalPlaces ?? false,
24
- allowNegative: options.allowNegative ?? false,
25
- thousandSeparator: groupStyle === "none" ? false : groupSeparator,
26
- thousandsGroupStyle: groupStyle,
27
- decimalSeparator,
28
- allowedDecimalSeparators: [decimalSeparator, "."].filter((char) => char !== groupSeparator)
21
+ groupSize,
22
+ group: groupSize === 0 ? "" : groupSeparator,
23
+ decimal,
24
+ decimalKeys: [decimal, "."].filter((char) => char !== groupSeparator)
29
25
  };
30
26
  }
31
27
  /**
@@ -44,4 +40,4 @@ function toNumericString(value, decimalPlaces) {
44
40
  }).format(value);
45
41
  }
46
42
 
47
- export { toLibraryNumericOptions, toNumericString };
43
+ export { resolveSeparators, toNumericString };
@@ -0,0 +1,156 @@
1
+ import { createCaretGuard } from "./caretGuard.js";
2
+ import { resolveSeparators, toNumericString } from "./numericFormat.js";
3
+ import { splitDigits } from "./splitDigits.js";
4
+ import { maskitoTransform } from "@maskito/core";
5
+ import { maskitoNumber } from "@maskito/kit";
6
+
7
+ // src/NumberFormatInput/libs/numericFormatter.ts
8
+ /** mask가 늘 버리는 글자. fixed는 넣는 글자 수만큼 덮어쓰므로 글자를 지우지 않고 이 글자로 바꾼다(ADR 0043). */
9
+ const REJECTED = "\0";
10
+ /** 대소문자·전각·호환 글자를 같게 본다(`M2`, `㎡`). */
11
+ const fold = (text) => text.normalize("NFKC").toLowerCase();
12
+ /** 숫자 모드 포맷 규칙. 구분자는 `formatNumber`와 같은 방법으로 고른다. */
13
+ function createNumericFormatter(options) {
14
+ const { groupSize, group, decimal, decimalKeys } = resolveSeparators(options);
15
+ const prefix = options.prefix ?? "";
16
+ const suffix = options.suffix ?? "";
17
+ const foldedSuffix = fold(suffix);
18
+ const allowNegative = options.allowNegative ?? false;
19
+ const { decimalPlaces } = options;
20
+ const params = {
21
+ prefix,
22
+ postfix: suffix,
23
+ thousandSeparator: group,
24
+ thousandSeparatorPattern: (integer) => splitDigits(/\d*$/.exec(integer)?.[0] ?? "", groupSize),
25
+ decimalSeparator: decimal,
26
+ decimalPseudoSeparators: decimalKeys.filter((key) => key !== decimal),
27
+ maximumFractionDigits: decimalPlaces ?? Infinity,
28
+ minimumFractionDigits: options.fixedDecimalPlaces ? decimalPlaces ?? 0 : 0,
29
+ minusSign: "-",
30
+ negativePattern: "minusFirst",
31
+ ...allowNegative ? {} : { min: 0 }
32
+ };
33
+ /** prefix·suffix를 뺀 숫자 부분. prefix·suffix 안의 점을 소수점으로 보지 않으려고 쓴다. */
34
+ const numberRange = (text) => {
35
+ let start = text.startsWith("-") ? 1 : 0;
36
+ if (prefix !== "" && text.startsWith(prefix, start)) start += prefix.length;
37
+ const end = suffix !== "" && text.endsWith(suffix) && text.length - suffix.length >= start ? text.length - suffix.length : text.length;
38
+ return [start, end];
39
+ };
40
+ const decimalIndex = (text) => {
41
+ const [start, end] = numberRange(text);
42
+ const index = text.slice(start, end).indexOf(decimal);
43
+ return index === -1 ? -1 : start + index;
44
+ };
45
+ const parse = (text) => {
46
+ const [start, end] = numberRange(text);
47
+ const body = Array.from(text.slice(start, end)).filter((char) => char >= "0" && char <= "9" || char === decimal).map((char) => char === decimal ? "." : char).join("");
48
+ return text.startsWith("-") ? `-${body}` : body;
49
+ };
50
+ /** 점이 이미 있으면 새 점은 무시한다. 바로 앞의 점을 넘거나 선택한 점을 바꾸는 것은 Maskito가 처리한다. */
51
+ const singleDecimal = ({ elementState, data }, actionType) => {
52
+ const index = decimalIndex(elementState.value);
53
+ const [from, to] = elementState.selection;
54
+ const passes = from === to ? from === index : from <= index && index < to;
55
+ if (actionType !== "insert" || !decimalKeys.includes(data) || index === -1 || passes) return {
56
+ elementState,
57
+ data
58
+ };
59
+ return {
60
+ elementState: {
61
+ value: elementState.value,
62
+ selection: [to, to]
63
+ },
64
+ data: ""
65
+ };
66
+ };
67
+ /** 글자 앞에 온 suffix 조각의 길이. 숫자나 공백만으로는 조각으로 보지 않고, 이어진 숫자 중간에서 끊지 않는다. */
68
+ const suffixPartLength = (text) => {
69
+ const first = text.charAt(0);
70
+ if (/[0-90-9-]/.test(first) || decimalKeys.includes(first)) return 0;
71
+ let length = 0;
72
+ while (length < text.length && foldedSuffix.includes(fold(text.slice(0, length + 1)))) length += 1;
73
+ const part = text.slice(0, length);
74
+ const whole = /^[0-90-9]/.test(text.slice(length)) ? part.replace(/[0-90-9]+$/, "") : part;
75
+ return whole.trim() === "" ? 0 : whole.length;
76
+ };
77
+ /** 넣는 글자에서 suffix 조각을 가린다. Maskito가 suffix의 점과 숫자를 값으로 읽기 전에 해야 한다. */
78
+ const hideSuffix = ({ elementState, data }, actionType) => {
79
+ if (actionType !== "insert" || suffix === "") return {
80
+ elementState,
81
+ data
82
+ };
83
+ let body = data.slice(0, numberRange(data)[0]);
84
+ let isHidden = false;
85
+ while (body.length < data.length) {
86
+ const rest = data.slice(body.length);
87
+ const length = suffixPartLength(rest);
88
+ isHidden ||= length > 0;
89
+ const isPunctuation = isHidden && decimalKeys.includes(rest.charAt(0)) && !/^.[0-90-9]/.test(rest);
90
+ body += length > 0 || isPunctuation ? REJECTED.repeat(length || 1) : rest.charAt(0);
91
+ }
92
+ return {
93
+ elementState,
94
+ data: body
95
+ };
96
+ };
97
+ const numberMask = maskitoNumber({
98
+ ...params,
99
+ postfix: ""
100
+ }).mask;
101
+ /**
102
+ * mask는 숫자 사이의 글자가 suffix에도 있으면(공백 등) suffix로 받고 뒤 숫자를 버린다. 그래서 숫자에 쓸 수 없는 글자를 가린다.
103
+ * Maskito가 prefix·suffix를 빼고 점과 부호를 정리한 뒤에 해야 한다.
104
+ */
105
+ const keepNumber = ({ elementState, data }, actionType) => {
106
+ const { value, selection } = elementState;
107
+ if (actionType !== "insert" || suffix === "") return {
108
+ elementState,
109
+ data
110
+ };
111
+ let accepted = value.slice(0, selection[0]);
112
+ return {
113
+ elementState,
114
+ data: Array.from(data, (char) => {
115
+ if (!numberMask.test(accepted + char)) return REJECTED.repeat(char.length);
116
+ accepted += char;
117
+ return char;
118
+ }).join("")
119
+ };
120
+ };
121
+ const caretGuard = prefix === "" && suffix === "" ? void 0 : createCaretGuard((value) => {
122
+ const [start, end] = numberRange(value);
123
+ return [prefix === "" ? 0 : start, end];
124
+ });
125
+ const base = maskitoNumber(params);
126
+ return {
127
+ maskOptions: {
128
+ ...base,
129
+ plugins: [...base.plugins ?? [], ...caretGuard ? [caretGuard.plugin] : []],
130
+ preprocessors: [
131
+ singleDecimal,
132
+ hideSuffix,
133
+ ...base.preprocessors ?? [],
134
+ keepNumber
135
+ ],
136
+ postprocessors: [...base.postprocessors ?? [], (state) => parse(state.value) === "" ? {
137
+ value: "",
138
+ selection: [0, 0]
139
+ } : state]
140
+ },
141
+ limitCaret: caretGuard?.limitCaret,
142
+ parse,
143
+ format: (digits) => {
144
+ const signed = allowNegative ? digits : digits.replace("-", "");
145
+ return signed === "" ? "" : maskitoTransform(signed.replace(".", decimal), maskitoNumber(params));
146
+ },
147
+ toValue: (digits) => {
148
+ const value = Number.parseFloat(digits);
149
+ return Number.isNaN(value) ? null : value;
150
+ },
151
+ fromValue: (value) => typeof value === "number" ? toNumericString(value, decimalPlaces) : value,
152
+ accepts: (text) => /[0-90-9]/.test(text) || decimalKeys.some((key) => text.includes(key)) || allowNegative && text.includes("-")
153
+ };
154
+ }
155
+
156
+ export { createNumericFormatter };
@@ -0,0 +1,10 @@
1
+ // src/NumberFormatInput/libs/splitDigits.ts
2
+ /** 숫자를 오른쪽부터 `size`자리씩 나눈다(`1234567`, 3 → `1`, `234`, `567`). `size`가 `0`이면 나누지 않는다. */
3
+ function splitDigits(digits, size) {
4
+ if (size === 0) return [digits];
5
+ const groups = [];
6
+ for (let end = digits.length; end > 0; end -= size) groups.unshift(digits.slice(Math.max(end - size, 0), end));
7
+ return groups;
8
+ }
9
+
10
+ export { splitDigits };
@@ -1,7 +1,4 @@
1
- import "../Input/Input.js";
2
- import "react-number-format";
3
- /** 숫자를 몇 자리씩 묶는지. `thousand` 1,234,567 · `wan` 123,4567(만 단위) · `none` 묶지 않음. */
4
- export type NumberGroupStyle = "thousand" | "wan" | "none";
1
+ import "@maskito/core";
5
2
  /** 숫자 모드 포맷 옵션. `NumberFormatInput`과 `formatNumber`가 같은 옵션으로 같은 글자를 만든다. */
6
3
  export interface NumericFormatOptions {
7
4
  /** 숫자 앞에 붙는 글자(예: `"₩"`). 값이 있을 때만 보인다. */
@@ -10,17 +7,20 @@ export interface NumericFormatOptions {
10
7
  suffix?: string;
11
8
  /** 소수 최대 자릿수. `0`이면 소수점을 받지 않는다. 기본값은 제한 없음. */
12
9
  decimalPlaces?: number;
13
- /** `decimalPlaces`만큼 소수 자리를 늘 채운다(`1` → `1.00`). 입력 칸은 blur 때 채운다. 기본값 `false`. */
10
+ /**
11
+ * `decimalPlaces`만큼 소수 자리를 늘 채운다(`1` → `1.00`). 입력 칸은 치는 중에도 채우고,
12
+ * 채운 소수 자리에 치면 그 자리를 덮어쓴다. 기본값 `false`.
13
+ */
14
14
  fixedDecimalPlaces?: boolean;
15
15
  /** 음수(`-`)를 받는다. 기본값 `false`. */
16
16
  allowNegative?: boolean;
17
- /** 자릿수 묶음 방식. 기본값 `thousand`. */
18
- groupStyle?: NumberGroupStyle;
19
- /** 묶음 구분자. 기본값은 `locale`의 구분자, `locale`이 없으면 `","`. */
17
+ /** 정수를 몇 자리씩 묶을지(`3` → `1,234,567`, `4` → `123,4567`). 기본값은 묶지 않음. 양의 정수가 아니면 묶지 않는다. */
18
+ groupStyle?: number;
19
+ /** 묶음 구분자. `groupStyle`을 줄 때만 보인다. 기본값은 `locale`의 구분자, `locale`이 없으면 `","`. */
20
20
  groupSeparator?: string;
21
21
  /** 소수점 글자. 기본값은 `locale`의 소수점, `locale`이 없으면 `"."`. */
22
22
  decimalSeparator?: string;
23
- /** 구분자 기본값을 가져올 BCP 47 locale(예: `"de-DE"`). 묶음 방식은 바꾸지 않는다. */
23
+ /** 구분자 기본값을 가져올 BCP 47 locale(예: `"de-DE"`). 소수점은 늘 적용되고, 묶으려면 `groupStyle`도 준다. */
24
24
  locale?: string;
25
25
  }
26
26
  /** 패턴 모드 포맷 옵션 */
package/dist/index.d.ts CHANGED
@@ -18,7 +18,7 @@ import { Textarea, TextareaOwnProps, TextareaProps } from "./Textarea/Textarea.j
18
18
  import "./NumberFormatInput/index.js";
19
19
  import { formatNumber } from "./NumberFormatInput/libs/formatNumber.js";
20
20
  import { NumberFormatInput, NumberFormatInputOwnProps, NumberFormatInputProps } from "./NumberFormatInput/NumberFormatInput.js";
21
- import { MaskFormatOptions, NumberFormatOptions, NumberGroupStyle, NumericFormatOptions } from "./NumberFormatInput/types.js";
21
+ import { MaskFormatOptions, NumberFormatOptions, NumericFormatOptions } from "./NumberFormatInput/types.js";
22
22
  import "./Checkbox/index.js";
23
23
  import { Checkbox, CheckboxOwnProps, CheckboxProps, CheckboxShape } from "./Checkbox/Checkbox.js";
24
24
  import "./CheckboxGroup/index.js";
@@ -121,4 +121,4 @@ import { TooltipTrigger, TooltipTriggerOwnProps, TooltipTriggerProps } from "./T
121
121
  import { TooltipPlacement } from "./Tooltip/types.js";
122
122
  import { TooltipContent, TooltipContentOwnProps, TooltipContentProps } from "./Tooltip/components/TooltipContent.js";
123
123
  import { Color, ColorFamilyName, ColorFamilyRegistry, FillVariant, Role, RoleRegistry, Size } from "./types.js";
124
- export { Accordion, type AccordionHeadingLevel, AccordionItem, type AccordionItemOwnProps, type AccordionItemProps, type AccordionOwnProps, AccordionPanel, type AccordionPanelOwnProps, type AccordionPanelProps, type AccordionProps, AccordionTrigger, type AccordionTriggerOwnProps, type AccordionTriggerProps, Alert, AlertDialog, type AlertDialogProps, type AlertOwnProps, type AlertProps, Avatar, type AvatarOwnProps, type AvatarProps, Badge, type BadgeOwnProps, type BadgeProps, Breadcrumb, BreadcrumbCurrent, type BreadcrumbCurrentProps, BreadcrumbItem, type BreadcrumbItemProps, BreadcrumbLink, type BreadcrumbLinkOwnProps, type BreadcrumbLinkProps, type BreadcrumbOwnProps, type BreadcrumbProps, Button, type ButtonOwnProps, type ButtonProps, Card, type CardOwnProps, type CardProps, Checkbox, CheckboxGroup, type CheckboxGroupOwnProps, type CheckboxGroupProps, type CheckboxOwnProps, type CheckboxProps, type CheckboxShape, type ChoiceOrientation, type Color, type ColorFamilyName, type ColorFamilyRegistry, Combobox, ComboboxItem, type ComboboxItemOwnProps, type ComboboxItemProps, type ComboboxOwnProps, type ComboboxProps, ComboboxSection, type ComboboxSectionProps, Dialog, DialogClose, type DialogCloseOwnProps, type DialogCloseProps, DialogContent, type DialogContentOwnProps, type DialogContentProps, DialogDescription, type DialogDescriptionProps, DialogFooter, type DialogFooterProps, DialogHeader, type DialogHeaderAlign, type DialogHeaderOwnProps, type DialogHeaderProps, type DialogProps, type DialogSize, DialogTitle, type DialogTitleProps, DialogTrigger, type DialogTriggerOwnProps, type DialogTriggerProps, Field, type FieldOwnProps, type FieldProps, type FillVariant, IconButton, type IconButtonOwnProps, type IconButtonProps, Input, type InputOwnProps, type InputProps, Link, type LinkOwnProps, type LinkProps, type MaskFormatOptions, Menu, MenuContent, type MenuContentOwnProps, type MenuContentProps, MenuItem, type MenuItemOwnProps, type MenuItemProps, type MenuPlacement, type MenuProps, MenuSection, type MenuSectionProps, MenuTrigger, type MenuTriggerOwnProps, type MenuTriggerProps, NumberFormatInput, type NumberFormatInputOwnProps, type NumberFormatInputProps, type NumberFormatOptions, type NumberGroupStyle, type NumericFormatOptions, Pagination, PaginationEllipsis, type PaginationEllipsisOwnProps, type PaginationEllipsisProps, PaginationItem, type PaginationItemProps, PaginationLink, type PaginationLinkOwnProps, type PaginationLinkProps, PaginationNext, type PaginationNextOwnProps, type PaginationNextProps, type PaginationOwnProps, PaginationPrevious, type PaginationPreviousOwnProps, type PaginationPreviousProps, type PaginationProps, Popover, PopoverContent, type PopoverContentOwnProps, type PopoverContentProps, type PopoverPlacement, type PopoverProps, PopoverTrigger, type PopoverTriggerOwnProps, type PopoverTriggerProps, Progress, type ProgressOwnProps, type ProgressProps, Radio, RadioGroup, type RadioGroupOwnProps, type RadioGroupProps, type RadioOwnProps, type RadioProps, type Role, type RoleRegistry, Select, SelectItem, type SelectItemOwnProps, type SelectItemProps, type SelectOwnProps, type SelectProps, SelectSection, type SelectSectionProps, Separator, type SeparatorOwnProps, type SeparatorProps, type Size, Skeleton, type SkeletonOwnProps, type SkeletonProps, Spinner, type SpinnerOwnProps, type SpinnerProps, Switch, type SwitchOwnProps, type SwitchProps, Tab, TabList, type TabListOwnProps, type TabListProps, type TabOwnProps, TabPanel, type TabPanelOwnProps, type TabPanelProps, type TabProps, Table, TableBody, type TableBodyProps, TableCell, type TableCellProps, TableHead, type TableHeadProps, TableHeaderCell, type TableHeaderCellOwnProps, type TableHeaderCellProps, type TableProps, TableRow, type TableRowProps, Tabs, type TabsActivationMode, type TabsOrientation, type TabsOwnProps, type TabsProps, type TabsShape, Tag, TagGroup, type TagGroupOwnProps, type TagGroupProps, type TagOwnProps, type TagProps, Textarea, type TextareaOwnProps, type TextareaProps, type ToastAction, type ToastOptions, ToastQueue, type ToastQueueOptions, ToastRegion, type ToastRegionOwnProps, type ToastRegionProps, Tooltip, TooltipContent, type TooltipContentOwnProps, type TooltipContentProps, type TooltipPlacement, type TooltipProps, TooltipTrigger, type TooltipTriggerOwnProps, type TooltipTriggerProps, VisuallyHidden, type VisuallyHiddenProps, cn, formatNumber };
124
+ export { Accordion, type AccordionHeadingLevel, AccordionItem, type AccordionItemOwnProps, type AccordionItemProps, type AccordionOwnProps, AccordionPanel, type AccordionPanelOwnProps, type AccordionPanelProps, type AccordionProps, AccordionTrigger, type AccordionTriggerOwnProps, type AccordionTriggerProps, Alert, AlertDialog, type AlertDialogProps, type AlertOwnProps, type AlertProps, Avatar, type AvatarOwnProps, type AvatarProps, Badge, type BadgeOwnProps, type BadgeProps, Breadcrumb, BreadcrumbCurrent, type BreadcrumbCurrentProps, BreadcrumbItem, type BreadcrumbItemProps, BreadcrumbLink, type BreadcrumbLinkOwnProps, type BreadcrumbLinkProps, type BreadcrumbOwnProps, type BreadcrumbProps, Button, type ButtonOwnProps, type ButtonProps, Card, type CardOwnProps, type CardProps, Checkbox, CheckboxGroup, type CheckboxGroupOwnProps, type CheckboxGroupProps, type CheckboxOwnProps, type CheckboxProps, type CheckboxShape, type ChoiceOrientation, type Color, type ColorFamilyName, type ColorFamilyRegistry, Combobox, ComboboxItem, type ComboboxItemOwnProps, type ComboboxItemProps, type ComboboxOwnProps, type ComboboxProps, ComboboxSection, type ComboboxSectionProps, Dialog, DialogClose, type DialogCloseOwnProps, type DialogCloseProps, DialogContent, type DialogContentOwnProps, type DialogContentProps, DialogDescription, type DialogDescriptionProps, DialogFooter, type DialogFooterProps, DialogHeader, type DialogHeaderAlign, type DialogHeaderOwnProps, type DialogHeaderProps, type DialogProps, type DialogSize, DialogTitle, type DialogTitleProps, DialogTrigger, type DialogTriggerOwnProps, type DialogTriggerProps, Field, type FieldOwnProps, type FieldProps, type FillVariant, IconButton, type IconButtonOwnProps, type IconButtonProps, Input, type InputOwnProps, type InputProps, Link, type LinkOwnProps, type LinkProps, type MaskFormatOptions, Menu, MenuContent, type MenuContentOwnProps, type MenuContentProps, MenuItem, type MenuItemOwnProps, type MenuItemProps, type MenuPlacement, type MenuProps, MenuSection, type MenuSectionProps, MenuTrigger, type MenuTriggerOwnProps, type MenuTriggerProps, NumberFormatInput, type NumberFormatInputOwnProps, type NumberFormatInputProps, type NumberFormatOptions, type NumericFormatOptions, Pagination, PaginationEllipsis, type PaginationEllipsisOwnProps, type PaginationEllipsisProps, PaginationItem, type PaginationItemProps, PaginationLink, type PaginationLinkOwnProps, type PaginationLinkProps, PaginationNext, type PaginationNextOwnProps, type PaginationNextProps, type PaginationOwnProps, PaginationPrevious, type PaginationPreviousOwnProps, type PaginationPreviousProps, type PaginationProps, Popover, PopoverContent, type PopoverContentOwnProps, type PopoverContentProps, type PopoverPlacement, type PopoverProps, PopoverTrigger, type PopoverTriggerOwnProps, type PopoverTriggerProps, Progress, type ProgressOwnProps, type ProgressProps, Radio, RadioGroup, type RadioGroupOwnProps, type RadioGroupProps, type RadioOwnProps, type RadioProps, type Role, type RoleRegistry, Select, SelectItem, type SelectItemOwnProps, type SelectItemProps, type SelectOwnProps, type SelectProps, SelectSection, type SelectSectionProps, Separator, type SeparatorOwnProps, type SeparatorProps, type Size, Skeleton, type SkeletonOwnProps, type SkeletonProps, Spinner, type SpinnerOwnProps, type SpinnerProps, Switch, type SwitchOwnProps, type SwitchProps, Tab, TabList, type TabListOwnProps, type TabListProps, type TabOwnProps, TabPanel, type TabPanelOwnProps, type TabPanelProps, type TabProps, Table, TableBody, type TableBodyProps, TableCell, type TableCellProps, TableHead, type TableHeadProps, TableHeaderCell, type TableHeaderCellOwnProps, type TableHeaderCellProps, type TableProps, TableRow, type TableRowProps, Tabs, type TabsActivationMode, type TabsOrientation, type TabsOwnProps, type TabsProps, type TabsShape, Tag, TagGroup, type TagGroupOwnProps, type TagGroupProps, type TagOwnProps, type TagProps, Textarea, type TextareaOwnProps, type TextareaProps, type ToastAction, type ToastOptions, ToastQueue, type ToastQueueOptions, ToastRegion, type ToastRegionOwnProps, type ToastRegionProps, Tooltip, TooltipContent, type TooltipContentOwnProps, type TooltipContentProps, type TooltipPlacement, type TooltipProps, TooltipTrigger, type TooltipTriggerOwnProps, type TooltipTriggerProps, VisuallyHidden, type VisuallyHiddenProps, cn, formatNumber };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tide-design/components",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Tide 디자인 시스템의 React Component",
5
5
  "keywords": [
6
6
  "accessibility",
@@ -34,8 +34,11 @@
34
34
  "./styles.css": "./dist/styles.css"
35
35
  },
36
36
  "dependencies": {
37
- "@tide-design/foundation": "0.22.0",
38
- "@tide-design/icons": "0.22.0",
37
+ "@maskito/core": "5.6.1",
38
+ "@maskito/kit": "5.6.1",
39
+ "@maskito/react": "5.6.1",
40
+ "@tide-design/foundation": "0.24.0",
41
+ "@tide-design/icons": "0.24.0",
39
42
  "clsx": "^2.1.1",
40
43
  "react-aria": "^3.53.1",
41
44
  "react-number-format": "^5.4.5",
@@ -1,22 +0,0 @@
1
- "use client";
2
-
3
- import { applyMask, maskDigits, maxMaskDigits, sortMasks } from "../libs/maskFormat.js";
4
- import { jsx } from "react/jsx-runtime";
5
- import { NumberFormatBase } from "react-number-format";
6
-
7
- // src/NumberFormatInput/components/MaskModeInput.tsx
8
- function MaskModeInput({ mask, ...props }) {
9
- const masks = sortMasks(mask);
10
- const maxDigits = maxMaskDigits(masks);
11
- return /* @__PURE__ */ jsx(NumberFormatBase, {
12
- ...props,
13
- format: (digits) => applyMask(digits, masks),
14
- removeFormatting: (text, change) => {
15
- const digits = maskDigits(text);
16
- if (digits.length > maxDigits && change) return maskDigits(change.lastValue);
17
- return digits.slice(0, maxDigits);
18
- }
19
- });
20
- }
21
-
22
- export { MaskModeInput };
@@ -1,16 +0,0 @@
1
- "use client";
2
-
3
- import { toLibraryNumericOptions } from "../libs/numericFormat.js";
4
- import { jsx } from "react/jsx-runtime";
5
- import { NumberFormatBase, useNumericFormat } from "react-number-format";
6
-
7
- // src/NumberFormatInput/components/NumericModeInput.tsx
8
- function NumericModeInput({ options, ...props }) {
9
- const baseProps = useNumericFormat({
10
- ...props,
11
- ...toLibraryNumericOptions(options)
12
- });
13
- return /* @__PURE__ */ jsx(NumberFormatBase, { ...baseProps });
14
- }
15
-
16
- export { NumericModeInput };
@@ -1,21 +0,0 @@
1
- "use client";
2
-
3
- import { useRef } from "react";
4
-
5
- // src/NumberFormatInput/hooks/useNumberCompositionGuard.ts
6
- /** IME 조합 중인 글자를 지워 조합 직전 값으로 되돌린다. 넘긴 처리기는 되돌린 뒤 부른다. */
7
- function useNumberCompositionGuard({ onCompositionStart, onInput }) {
8
- const valueBeforeComposition = useRef("");
9
- return {
10
- onCompositionStart: (event) => {
11
- valueBeforeComposition.current = event.currentTarget.value;
12
- onCompositionStart?.(event);
13
- },
14
- onInput: (event) => {
15
- if (event.nativeEvent.isComposing) event.currentTarget.value = valueBeforeComposition.current;
16
- onInput?.(event);
17
- }
18
- };
19
- }
20
-
21
- export { useNumberCompositionGuard };