@basiln/utils 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,6 +23,9 @@ yarn add @basiln/utils
23
23
  - [composeEventHandlers](#composeeventhandlers)
24
24
  - [getVar](#getvar)
25
25
  - [Format](#format)
26
+ - [DomainFormat](#domainformat)
27
+ - [useCombinedRefs](#usecombinedrefs)
28
+ - [useControllableState](#usecontrollablestate)
26
29
 
27
30
  ### `If`
28
31
 
@@ -322,3 +325,63 @@ Format.phone('01012345678'); // '010-1234-5678'
322
325
  Format.commaize('123456'); // '123,456'
323
326
  Format.padTime(1); // '01'
324
327
  ```
328
+
329
+ ---
330
+
331
+ ### `DomainFormat`
332
+
333
+ 도메인 관련 데이터를 원하는 형식으로 변환하는 포맷팅 유틸입니다.
334
+
335
+ #### 사용법
336
+
337
+ ```tsx
338
+ // 기본
339
+ DomainFormat.modeName('H'); // 난방
340
+ DomainFormat.modeColor('H'); // #e77676
341
+ DomainFormat.wind(3) // 강풍
342
+ DomainFormat.airLevelName(4) // 좋음
343
+ DomainFormat.airLevelColor(1) // #ff5d47
344
+ DomainFormat.userLevel({level: '1'}) // 마스터
345
+ DomainFormat.userLevel({level: '1', language: 'en'}) // MASTER
346
+
347
+ // Mode 추가가 필요한 경우
348
+ DomainFormat.modeName('R', {R: '실외기 잠금'}); // 실외기 잠금
349
+ DomainFormat.modeColor('R', {N: 'gray'}); // 'gray'
350
+ ```
351
+ ---
352
+ ### `useCombinedRefs`
353
+ 컴포넌트 내부에 선언된 ref와, 사용하는 부분에서 forwarded된 ref를 합칠 수 있도록 하는 hook 입니다.
354
+ #### 사용법
355
+ ```tsx
356
+ const TextField = forwardRef((props, forwardedRef) => {
357
+ const ref = useRef<HTMLInputElement | null>(null);
358
+ const combinedRefs = useCombinedRefs(ref, forwardedRef);
359
+ return <input ref={ref} />
360
+ })
361
+ ```
362
+ ---
363
+ ### `useControllableState`
364
+ 사용자의 입력을 통해 상태를 관리할 때와 사용자의 입력을 상태로 관리하지 않고 싶을 때 두 경우 모두를 지원하는 hook 입니다.
365
+ #### 사용법 ([참고](https://github.com/seedn-corp/leaf-airmate-web-fe/blob/20bec52b87814e7c0a9f174b08bdaa0bff2e8680/src/components/historyInfo/Select/index.tsx#L14-L33))
366
+ ```tsx
367
+ const [value, setValue] = useControllableState({
368
+ prop: valueFromProps,
369
+ defaultProp: defaultValue,
370
+ onChange: onValueChange,
371
+ });
372
+ return (
373
+ <SelectProvider
374
+ value={value}
375
+ onValueChange={setValue}
376
+ triggerWidth={triggerWidth}
377
+ onTriggerWidthChange={setTriggerWidth}
378
+ >
379
+ <SelectPrimitive.Root value={value} onValueChange={setValue} {...restProps}>
380
+ <div ref={ref}>{children}</div>
381
+ </SelectPrimitive.Root>
382
+ </SelectProvider>
383
+ );
384
+ });
385
+
386
+ ```
387
+
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/DomainFormat.ts
21
+ var DomainFormat_exports = {};
22
+ __export(DomainFormat_exports, {
23
+ DomainFormat: () => DomainFormat
24
+ });
25
+ module.exports = __toCommonJS(DomainFormat_exports);
26
+ function formatModeName(mode, customMapping = {}) {
27
+ const defaultModeMapping = {
28
+ H: "\uB09C\uBC29",
29
+ C: "\uB0C9\uBC29",
30
+ W: "\uC1A1\uD48D"
31
+ };
32
+ const combinedMapping = { ...defaultModeMapping, ...customMapping };
33
+ if (!(mode in combinedMapping)) {
34
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uBAA8\uB4DC\uC785\uB2C8\uB2E4. mode: ${mode}`);
35
+ }
36
+ return combinedMapping[mode];
37
+ }
38
+ function formatModeColor(mode, customMapping = {}) {
39
+ const defaultColorMapping = {
40
+ H: "#e77676",
41
+ C: "#9fc6ff",
42
+ W: "#a8e379"
43
+ };
44
+ const combinedMapping = { ...defaultColorMapping, ...customMapping };
45
+ if (!(mode in combinedMapping)) {
46
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uBAA8\uB4DC\uC785\uB2C8\uB2E4. mode: ${mode}`);
47
+ }
48
+ return combinedMapping[mode];
49
+ }
50
+ function formatWind(wind, customMapping = {}) {
51
+ const defaultWindMapping = {
52
+ 1: "\uBBF8\uD48D",
53
+ 2: "\uC57D\uD48D",
54
+ 3: "\uAC15\uD48D"
55
+ };
56
+ const combinedMapping = { ...defaultWindMapping, ...customMapping };
57
+ if (!(wind in combinedMapping)) {
58
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uD48D\uB7C9\uC785\uB2C8\uB2E4. wind: ${wind}`);
59
+ }
60
+ return combinedMapping[wind];
61
+ }
62
+ function formatAirLevelName(level) {
63
+ const airLevelMapping = {
64
+ 1: "\uB9E4\uC6B0 \uB098\uC068",
65
+ 2: "\uB098\uC068",
66
+ 3: "\uBCF4\uD1B5",
67
+ 4: "\uC88B\uC74C",
68
+ 5: "\uB9E4\uC6B0 \uC88B\uC74C"
69
+ };
70
+ if (!(level in airLevelMapping)) {
71
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uB808\uBCA8\uC785\uB2C8\uB2E4. level: ${level}`);
72
+ }
73
+ return airLevelMapping[level];
74
+ }
75
+ function formatAirLevelColor(level) {
76
+ const colorMapping = {
77
+ 1: "#ff5d47",
78
+ 2: "#ff961c",
79
+ 3: "#ffca42",
80
+ 4: "#63ff60",
81
+ 5: "#49ffe9"
82
+ };
83
+ if (!(level in colorMapping)) {
84
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uB808\uBCA8\uC785\uB2C8\uB2E4. level: ${level}`);
85
+ }
86
+ return colorMapping[level];
87
+ }
88
+ var formatUserLevel = ({ level, language = "ko" }) => {
89
+ const userLevelMapping = {
90
+ en: {
91
+ "1": "MASTER",
92
+ "2": "MASTER KID",
93
+ "3": "SENIOR",
94
+ "4": "JUNIOR"
95
+ },
96
+ ko: {
97
+ "1": "\uB9C8\uC2A4\uD130",
98
+ "2": "\uB9C8\uC2A4\uD130\uD0A4\uC988",
99
+ "3": "\uC2DC\uB2C8\uC5B4",
100
+ "4": "\uC8FC\uB2C8\uC5B4"
101
+ }
102
+ };
103
+ if (!(language in userLevelMapping)) {
104
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC5B8\uC5B4\uC785\uB2C8\uB2E4. language: ${language}`);
105
+ }
106
+ if (!(level in userLevelMapping[language])) {
107
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uB808\uBCA8\uC785\uB2C8\uB2E4. level: ${level}`);
108
+ }
109
+ return userLevelMapping[language][level];
110
+ };
111
+ var DomainFormat = {
112
+ modeName: formatModeName,
113
+ modeColor: formatModeColor,
114
+ wind: formatWind,
115
+ airLevelName: formatAirLevelName,
116
+ airLevelColor: formatAirLevelColor,
117
+ userLevel: formatUserLevel
118
+ };
119
+ // Annotate the CommonJS export names for ESM import in node:
120
+ 0 && (module.exports = {
121
+ DomainFormat
122
+ });
123
+ //# sourceMappingURL=DomainFormat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/DomainFormat.ts"],"sourcesContent":["export type Mode = 'H' | 'C' | 'W';\nexport type Wind = 1 | 2 | 3;\nexport type AirLevel = 1 | 2 | 3 | 4 | 5;\nexport type UserLevel = '1' | '2' | '3' | '4';\nexport type Language = 'en' | 'ko';\n\nfunction formatModeName(mode: Mode, customMapping: Record<string, string> = {}): string {\n const defaultModeMapping: Record<Mode, string> = {\n H: '난방',\n C: '냉방',\n W: '송풍',\n };\n\n const combinedMapping = { ...defaultModeMapping, ...customMapping };\n\n if (!(mode in combinedMapping)) {\n throw new Error(`지원하지 않는 모드입니다. mode: ${mode}`);\n }\n\n return combinedMapping[mode];\n}\n\nfunction formatModeColor(mode: Mode, customMapping: Record<string, string> = {}) {\n const defaultColorMapping: Record<Mode, string> = {\n H: '#e77676',\n C: '#9fc6ff',\n W: '#a8e379',\n };\n\n const combinedMapping = { ...defaultColorMapping, ...customMapping };\n\n if (!(mode in combinedMapping)) {\n throw new Error(`지원하지 않는 모드입니다. mode: ${mode}`);\n }\n\n return combinedMapping[mode];\n}\n\nfunction formatWind(wind: Wind, customMapping: Record<string, string> = {}) {\n const defaultWindMapping: Record<Wind, string> = {\n 1: '미풍',\n 2: '약풍',\n 3: '강풍',\n };\n\n const combinedMapping = { ...defaultWindMapping, ...customMapping };\n\n if (!(wind in combinedMapping)) {\n throw new Error(`지원하지 않는 풍량입니다. wind: ${wind}`);\n }\n\n return combinedMapping[wind];\n}\n\nfunction formatAirLevelName(level: AirLevel) {\n const airLevelMapping: Record<AirLevel, string> = {\n 1: '매우 나쁨',\n 2: '나쁨',\n 3: '보통',\n 4: '좋음',\n 5: '매우 좋음',\n };\n\n if (!(level in airLevelMapping)) {\n throw new Error(`지원하지 않는 레벨입니다. level: ${level}`);\n }\n\n return airLevelMapping[level];\n}\n\nfunction formatAirLevelColor(level: AirLevel) {\n const colorMapping: Record<AirLevel, string> = {\n 1: '#ff5d47',\n 2: '#ff961c',\n 3: '#ffca42',\n 4: '#63ff60',\n 5: '#49ffe9',\n };\n\n if (!(level in colorMapping)) {\n throw new Error(`지원하지 않는 레벨입니다. level: ${level}`);\n }\n\n return colorMapping[level];\n}\n\nconst formatUserLevel = ({ level, language = 'ko' }: { level: UserLevel; language?: Language }) => {\n const userLevelMapping: Record<Language, Record<UserLevel, string>> = {\n en: {\n '1': 'MASTER',\n '2': 'MASTER KID',\n '3': 'SENIOR',\n '4': 'JUNIOR',\n },\n ko: {\n '1': '마스터',\n '2': '마스터키즈',\n '3': '시니어',\n '4': '주니어',\n },\n };\n\n if (!(language in userLevelMapping)) {\n throw new Error(`지원하지 않는 언어입니다. language: ${language}`);\n }\n\n if (!(level in userLevelMapping[language])) {\n throw new Error(`지원하지 않는 레벨입니다. level: ${level}`);\n }\n\n return userLevelMapping[language][level];\n};\n\nexport const DomainFormat = {\n modeName: formatModeName,\n modeColor: formatModeColor,\n wind: formatWind,\n airLevelName: formatAirLevelName,\n airLevelColor: formatAirLevelColor,\n userLevel: formatUserLevel,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,SAAS,eAAe,MAAY,gBAAwC,CAAC,GAAW;AACtF,QAAM,qBAA2C;AAAA,IAC/C,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AAEA,QAAM,kBAAkB,EAAE,GAAG,oBAAoB,GAAG,cAAc;AAElE,MAAI,EAAE,QAAQ,kBAAkB;AAC9B,UAAM,IAAI,MAAM,+EAAwB,IAAI,EAAE;AAAA,EAChD;AAEA,SAAO,gBAAgB,IAAI;AAC7B;AAEA,SAAS,gBAAgB,MAAY,gBAAwC,CAAC,GAAG;AAC/E,QAAM,sBAA4C;AAAA,IAChD,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AAEA,QAAM,kBAAkB,EAAE,GAAG,qBAAqB,GAAG,cAAc;AAEnE,MAAI,EAAE,QAAQ,kBAAkB;AAC9B,UAAM,IAAI,MAAM,+EAA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I,MAAM,mFAA4B,QAAQ,EAAE;AAAA,EACxD;AAEA,MAAI,EAAE,SAAS,iBAAiB,QAAQ,IAAI;AAC1C,UAAM,IAAI,MAAM,gFAAyB,KAAK,EAAE;AAAA,EAClD;AAEA,SAAO,iBAAiB,QAAQ,EAAE,KAAK;AACzC;AAEO,IAAM,eAAe;AAAA,EAC1B,UAAU;AAAA,EACV,WAAW;AAAA,EACX,MAAM;AAAA,EACN,cAAc;AAAA,EACd,eAAe;AAAA,EACf,WAAW;AACb;","names":[]}
@@ -0,0 +1,7 @@
1
+ import {
2
+ DomainFormat
3
+ } from "./chunk-WWR7M6ID.mjs";
4
+ export {
5
+ DomainFormat
6
+ };
7
+ //# sourceMappingURL=DomainFormat.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,19 @@
1
+ // src/useCombinedRefs.ts
2
+ import { useCallback } from "react";
3
+ var useCombinedRefs = (...refs) => useCallback(
4
+ (element) => refs.forEach((ref) => {
5
+ if (!ref) {
6
+ return;
7
+ }
8
+ if (typeof ref === "function") {
9
+ return ref(element);
10
+ }
11
+ ref.current = element;
12
+ }),
13
+ [refs]
14
+ );
15
+
16
+ export {
17
+ useCombinedRefs
18
+ };
19
+ //# sourceMappingURL=chunk-D2YRH4XY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useCombinedRefs.ts"],"sourcesContent":["import { type Ref, useCallback } from 'react';\n// Reference: https://github.com/facebook/react/issues/13029#issuecomment-497641073\nexport const useCombinedRefs = <T>(...refs: Array<Ref<T>>): Ref<T> =>\n useCallback(\n (element: T) =>\n refs.forEach((ref) => {\n if (!ref) {\n return;\n }\n if (typeof ref === 'function') {\n return ref(element);\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (ref as any).current = element;\n }),\n [refs]\n );\n"],"mappings":";AAAA,SAAmB,mBAAmB;AAE/B,IAAM,kBAAkB,IAAO,SACpC;AAAA,EACE,CAAC,YACC,KAAK,QAAQ,CAAC,QAAQ;AACpB,QAAI,CAAC,KAAK;AACR;AAAA,IACF;AACA,QAAI,OAAO,QAAQ,YAAY;AAC7B,aAAO,IAAI,OAAO;AAAA,IACpB;AAEA,IAAC,IAAY,UAAU;AAAA,EACzB,CAAC;AAAA,EACH,CAAC,IAAI;AACP;","names":[]}
@@ -0,0 +1,57 @@
1
+ import {
2
+ usePreservedCallback_default
3
+ } from "./chunk-QGQNMD22.mjs";
4
+
5
+ // src/useControllableState.ts
6
+ import * as React from "react";
7
+ function noop() {
8
+ }
9
+ var useControllableState = ({
10
+ prop,
11
+ defaultProp,
12
+ onChange = noop
13
+ }) => {
14
+ const [uncontrolledProp, setUncontrolledProp] = useUncontrolledState({
15
+ defaultProp,
16
+ onChange
17
+ });
18
+ const isControlled = prop !== void 0;
19
+ const value = isControlled ? prop : uncontrolledProp;
20
+ const handleChange = usePreservedCallback_default(onChange);
21
+ const setValue = React.useCallback(
22
+ (nextValue) => {
23
+ if (isControlled) {
24
+ const setter = nextValue;
25
+ const value2 = typeof nextValue === "function" ? setter(prop) : nextValue;
26
+ if (value2 !== prop) handleChange(value2);
27
+ } else {
28
+ setUncontrolledProp(nextValue);
29
+ }
30
+ },
31
+ [isControlled, prop, setUncontrolledProp, handleChange]
32
+ );
33
+ return [value, setValue];
34
+ };
35
+ var useUncontrolledState = ({
36
+ defaultProp,
37
+ onChange = noop
38
+ }) => {
39
+ const uncontrolledState = React.useState(defaultProp);
40
+ const [value] = uncontrolledState;
41
+ const prevValueRef = React.useRef(value);
42
+ const handleChange = usePreservedCallback_default(onChange);
43
+ React.useEffect(() => {
44
+ if (prevValueRef.current !== value) {
45
+ handleChange(value);
46
+ prevValueRef.current = value;
47
+ }
48
+ }, [value, prevValueRef, handleChange]);
49
+ return uncontrolledState;
50
+ };
51
+ var useControllableState_default = useControllableState;
52
+
53
+ export {
54
+ useControllableState,
55
+ useControllableState_default
56
+ };
57
+ //# sourceMappingURL=chunk-HOC4D4DT.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useControllableState.ts"],"sourcesContent":["import * as React from 'react';\n\nimport usePreservedCallback from './usePreservedCallback';\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noop() {}\nexport type UseControllableStateParams<T> = {\n prop?: T | undefined;\n defaultProp?: T | undefined;\n onChange?: (state: T) => void;\n};\ntype SetStateFn<T> = (prevState?: T) => T;\n/**\n * @description\n * Radix UI's useControllableState\n */\nexport const useControllableState = <T>({\n prop,\n defaultProp,\n onChange = noop,\n}: UseControllableStateParams<T>) => {\n const [uncontrolledProp, setUncontrolledProp] = useUncontrolledState({\n defaultProp,\n onChange,\n });\n const isControlled = prop !== undefined;\n const value = isControlled ? prop : uncontrolledProp;\n const handleChange = usePreservedCallback(onChange);\n const setValue: React.Dispatch<React.SetStateAction<T | undefined>> = React.useCallback(\n (nextValue) => {\n if (isControlled) {\n const setter = nextValue as SetStateFn<T>;\n const value = typeof nextValue === 'function' ? setter(prop) : nextValue;\n if (value !== prop) handleChange(value as T);\n } else {\n setUncontrolledProp(nextValue);\n }\n },\n [isControlled, prop, setUncontrolledProp, handleChange]\n );\n return [value, setValue] as const;\n};\nconst useUncontrolledState = <T>({\n defaultProp,\n onChange = noop,\n}: Omit<UseControllableStateParams<T>, 'prop'>) => {\n const uncontrolledState = React.useState<T | undefined>(defaultProp);\n const [value] = uncontrolledState;\n const prevValueRef = React.useRef(value);\n const handleChange = usePreservedCallback(onChange);\n React.useEffect(() => {\n if (prevValueRef.current !== value) {\n handleChange(value as T);\n prevValueRef.current = value;\n }\n }, [value, prevValueRef, handleChange]);\n return uncontrolledState;\n};\nexport default useControllableState;\n"],"mappings":";;;;;AAAA,YAAY,WAAW;AAIvB,SAAS,OAAO;AAAC;AAWV,IAAM,uBAAuB,CAAI;AAAA,EACtC;AAAA,EACA;AAAA,EACA,WAAW;AACb,MAAqC;AACnC,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,qBAAqB;AAAA,IACnE;AAAA,IACA;AAAA,EACF,CAAC;AACD,QAAM,eAAe,SAAS;AAC9B,QAAM,QAAQ,eAAe,OAAO;AACpC,QAAM,eAAe,6BAAqB,QAAQ;AAClD,QAAM,WAAsE;AAAA,IAC1E,CAAC,cAAc;AACb,UAAI,cAAc;AAChB,cAAM,SAAS;AACf,cAAMA,SAAQ,OAAO,cAAc,aAAa,OAAO,IAAI,IAAI;AAC/D,YAAIA,WAAU,KAAM,cAAaA,MAAU;AAAA,MAC7C,OAAO;AACL,4BAAoB,SAAS;AAAA,MAC/B;AAAA,IACF;AAAA,IACA,CAAC,cAAc,MAAM,qBAAqB,YAAY;AAAA,EACxD;AACA,SAAO,CAAC,OAAO,QAAQ;AACzB;AACA,IAAM,uBAAuB,CAAI;AAAA,EAC/B;AAAA,EACA,WAAW;AACb,MAAmD;AACjD,QAAM,oBAA0B,eAAwB,WAAW;AACnE,QAAM,CAAC,KAAK,IAAI;AAChB,QAAM,eAAqB,aAAO,KAAK;AACvC,QAAM,eAAe,6BAAqB,QAAQ;AAClD,EAAM,gBAAU,MAAM;AACpB,QAAI,aAAa,YAAY,OAAO;AAClC,mBAAa,KAAU;AACvB,mBAAa,UAAU;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,OAAO,cAAc,YAAY,CAAC;AACtC,SAAO;AACT;AACA,IAAO,+BAAQ;","names":["value"]}
@@ -0,0 +1,15 @@
1
+ // src/usePreservedCallback.ts
2
+ import { useEffect, useMemo, useRef } from "react";
3
+ var usePreservedCallback = (callback) => {
4
+ const callbackRef = useRef(callback);
5
+ useEffect(() => {
6
+ callbackRef.current = callback;
7
+ }, [callback]);
8
+ return useMemo(() => (...args) => callbackRef.current?.(...args), []);
9
+ };
10
+ var usePreservedCallback_default = usePreservedCallback;
11
+
12
+ export {
13
+ usePreservedCallback_default
14
+ };
15
+ //# sourceMappingURL=chunk-QGQNMD22.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/usePreservedCallback.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst usePreservedCallback = <T extends (...args: any[]) => any>(callback: T): T => {\n const callbackRef = useRef(callback);\n useEffect(() => {\n callbackRef.current = callback;\n }, [callback]);\n return useMemo(() => ((...args) => callbackRef.current?.(...args)) as T, []);\n};\nexport default usePreservedCallback;\n"],"mappings":";AAAA,SAAS,WAAW,SAAS,cAAc;AAE3C,IAAM,uBAAuB,CAAoC,aAAmB;AAClF,QAAM,cAAc,OAAO,QAAQ;AACnC,YAAU,MAAM;AACd,gBAAY,UAAU;AAAA,EACxB,GAAG,CAAC,QAAQ,CAAC;AACb,SAAO,QAAQ,MAAO,IAAI,SAAS,YAAY,UAAU,GAAG,IAAI,GAAS,CAAC,CAAC;AAC7E;AACA,IAAO,+BAAQ;","names":[]}
@@ -0,0 +1,99 @@
1
+ // src/DomainFormat.ts
2
+ function formatModeName(mode, customMapping = {}) {
3
+ const defaultModeMapping = {
4
+ H: "\uB09C\uBC29",
5
+ C: "\uB0C9\uBC29",
6
+ W: "\uC1A1\uD48D"
7
+ };
8
+ const combinedMapping = { ...defaultModeMapping, ...customMapping };
9
+ if (!(mode in combinedMapping)) {
10
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uBAA8\uB4DC\uC785\uB2C8\uB2E4. mode: ${mode}`);
11
+ }
12
+ return combinedMapping[mode];
13
+ }
14
+ function formatModeColor(mode, customMapping = {}) {
15
+ const defaultColorMapping = {
16
+ H: "#e77676",
17
+ C: "#9fc6ff",
18
+ W: "#a8e379"
19
+ };
20
+ const combinedMapping = { ...defaultColorMapping, ...customMapping };
21
+ if (!(mode in combinedMapping)) {
22
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uBAA8\uB4DC\uC785\uB2C8\uB2E4. mode: ${mode}`);
23
+ }
24
+ return combinedMapping[mode];
25
+ }
26
+ function formatWind(wind, customMapping = {}) {
27
+ const defaultWindMapping = {
28
+ 1: "\uBBF8\uD48D",
29
+ 2: "\uC57D\uD48D",
30
+ 3: "\uAC15\uD48D"
31
+ };
32
+ const combinedMapping = { ...defaultWindMapping, ...customMapping };
33
+ if (!(wind in combinedMapping)) {
34
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uD48D\uB7C9\uC785\uB2C8\uB2E4. wind: ${wind}`);
35
+ }
36
+ return combinedMapping[wind];
37
+ }
38
+ function formatAirLevelName(level) {
39
+ const airLevelMapping = {
40
+ 1: "\uB9E4\uC6B0 \uB098\uC068",
41
+ 2: "\uB098\uC068",
42
+ 3: "\uBCF4\uD1B5",
43
+ 4: "\uC88B\uC74C",
44
+ 5: "\uB9E4\uC6B0 \uC88B\uC74C"
45
+ };
46
+ if (!(level in airLevelMapping)) {
47
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uB808\uBCA8\uC785\uB2C8\uB2E4. level: ${level}`);
48
+ }
49
+ return airLevelMapping[level];
50
+ }
51
+ function formatAirLevelColor(level) {
52
+ const colorMapping = {
53
+ 1: "#ff5d47",
54
+ 2: "#ff961c",
55
+ 3: "#ffca42",
56
+ 4: "#63ff60",
57
+ 5: "#49ffe9"
58
+ };
59
+ if (!(level in colorMapping)) {
60
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uB808\uBCA8\uC785\uB2C8\uB2E4. level: ${level}`);
61
+ }
62
+ return colorMapping[level];
63
+ }
64
+ var formatUserLevel = ({ level, language = "ko" }) => {
65
+ const userLevelMapping = {
66
+ en: {
67
+ "1": "MASTER",
68
+ "2": "MASTER KID",
69
+ "3": "SENIOR",
70
+ "4": "JUNIOR"
71
+ },
72
+ ko: {
73
+ "1": "\uB9C8\uC2A4\uD130",
74
+ "2": "\uB9C8\uC2A4\uD130\uD0A4\uC988",
75
+ "3": "\uC2DC\uB2C8\uC5B4",
76
+ "4": "\uC8FC\uB2C8\uC5B4"
77
+ }
78
+ };
79
+ if (!(language in userLevelMapping)) {
80
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC5B8\uC5B4\uC785\uB2C8\uB2E4. language: ${language}`);
81
+ }
82
+ if (!(level in userLevelMapping[language])) {
83
+ throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uB808\uBCA8\uC785\uB2C8\uB2E4. level: ${level}`);
84
+ }
85
+ return userLevelMapping[language][level];
86
+ };
87
+ var DomainFormat = {
88
+ modeName: formatModeName,
89
+ modeColor: formatModeColor,
90
+ wind: formatWind,
91
+ airLevelName: formatAirLevelName,
92
+ airLevelColor: formatAirLevelColor,
93
+ userLevel: formatUserLevel
94
+ };
95
+
96
+ export {
97
+ DomainFormat
98
+ };
99
+ //# sourceMappingURL=chunk-WWR7M6ID.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/DomainFormat.ts"],"sourcesContent":["export type Mode = 'H' | 'C' | 'W';\nexport type Wind = 1 | 2 | 3;\nexport type AirLevel = 1 | 2 | 3 | 4 | 5;\nexport type UserLevel = '1' | '2' | '3' | '4';\nexport type Language = 'en' | 'ko';\n\nfunction formatModeName(mode: Mode, customMapping: Record<string, string> = {}): string {\n const defaultModeMapping: Record<Mode, string> = {\n H: '난방',\n C: '냉방',\n W: '송풍',\n };\n\n const combinedMapping = { ...defaultModeMapping, ...customMapping };\n\n if (!(mode in combinedMapping)) {\n throw new Error(`지원하지 않는 모드입니다. mode: ${mode}`);\n }\n\n return combinedMapping[mode];\n}\n\nfunction formatModeColor(mode: Mode, customMapping: Record<string, string> = {}) {\n const defaultColorMapping: Record<Mode, string> = {\n H: '#e77676',\n C: '#9fc6ff',\n W: '#a8e379',\n };\n\n const combinedMapping = { ...defaultColorMapping, ...customMapping };\n\n if (!(mode in combinedMapping)) {\n throw new Error(`지원하지 않는 모드입니다. mode: ${mode}`);\n }\n\n return combinedMapping[mode];\n}\n\nfunction formatWind(wind: Wind, customMapping: Record<string, string> = {}) {\n const defaultWindMapping: Record<Wind, string> = {\n 1: '미풍',\n 2: '약풍',\n 3: '강풍',\n };\n\n const combinedMapping = { ...defaultWindMapping, ...customMapping };\n\n if (!(wind in combinedMapping)) {\n throw new Error(`지원하지 않는 풍량입니다. wind: ${wind}`);\n }\n\n return combinedMapping[wind];\n}\n\nfunction formatAirLevelName(level: AirLevel) {\n const airLevelMapping: Record<AirLevel, string> = {\n 1: '매우 나쁨',\n 2: '나쁨',\n 3: '보통',\n 4: '좋음',\n 5: '매우 좋음',\n };\n\n if (!(level in airLevelMapping)) {\n throw new Error(`지원하지 않는 레벨입니다. level: ${level}`);\n }\n\n return airLevelMapping[level];\n}\n\nfunction formatAirLevelColor(level: AirLevel) {\n const colorMapping: Record<AirLevel, string> = {\n 1: '#ff5d47',\n 2: '#ff961c',\n 3: '#ffca42',\n 4: '#63ff60',\n 5: '#49ffe9',\n };\n\n if (!(level in colorMapping)) {\n throw new Error(`지원하지 않는 레벨입니다. level: ${level}`);\n }\n\n return colorMapping[level];\n}\n\nconst formatUserLevel = ({ level, language = 'ko' }: { level: UserLevel; language?: Language }) => {\n const userLevelMapping: Record<Language, Record<UserLevel, string>> = {\n en: {\n '1': 'MASTER',\n '2': 'MASTER KID',\n '3': 'SENIOR',\n '4': 'JUNIOR',\n },\n ko: {\n '1': '마스터',\n '2': '마스터키즈',\n '3': '시니어',\n '4': '주니어',\n },\n };\n\n if (!(language in userLevelMapping)) {\n throw new Error(`지원하지 않는 언어입니다. language: ${language}`);\n }\n\n if (!(level in userLevelMapping[language])) {\n throw new Error(`지원하지 않는 레벨입니다. level: ${level}`);\n }\n\n return userLevelMapping[language][level];\n};\n\nexport const DomainFormat = {\n modeName: formatModeName,\n modeColor: formatModeColor,\n wind: formatWind,\n airLevelName: formatAirLevelName,\n airLevelColor: formatAirLevelColor,\n userLevel: formatUserLevel,\n};\n"],"mappings":";AAMA,SAAS,eAAe,MAAY,gBAAwC,CAAC,GAAW;AACt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AAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AAEA,MAAI,EAAE,SAAS,eAAe;AAC5B,UAAM,IAAI,MAAM,gFAAyB,KAAK,EAAE;AAAA,EAClD;AAEA,SAAO,aAAa,KAAK;AAC3B;AAEA,IAAM,kBAAkB,CAAC,EAAE,OAAO,WAAW,KAAK,MAAiD;AACjG,QAAM,mBAAgE;AAAA,IACpE,IAAI;AAAA,MACF,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAAA,IACA,IAAI;AAAA,MACF,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAAA,EACF;AAEA,MAAI,EAAE,YAAY,mBAAmB;AACnC,UAAM,IAAI,MAAM,mFAA4B,QAAQ,EAAE;AAAA,EACxD;AAEA,MAAI,EAAE,SAAS,iBAAiB,QAAQ,IAAI;AAC1C,UAAM,IAAI,MAAM,gFAAyB,KAAK,EAAE;AAAA,EAClD;AAEA,SAAO,iBAAiB,QAAQ,EAAE,KAAK;AACzC;AAEO,IAAM,eAAe;AAAA,EAC1B,UAAU;AAAA,EACV,WAAW;AAAA,EACX,MAAM;AAAA,EACN,cAAc;AAAA,EACd,eAAe;AAAA,EACf,WAAW;AACb;","names":[]}
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
- import React__default, { ReactNode, FC, PropsWithChildren, HTMLAttributes, CSSProperties, ComponentPropsWithoutRef } from 'react';
3
+ import React__default, { ReactNode, FC, PropsWithChildren, HTMLAttributes, CSSProperties, ComponentPropsWithoutRef, Ref } from 'react';
4
4
  import * as styled_components from 'styled-components';
5
5
 
6
6
  type ChooseWhenProps = {
@@ -225,4 +225,39 @@ declare function formatCommaizeNumber(value: Value): string;
225
225
  */
226
226
  declare function padTime(value: Value): string;
227
227
 
228
- export { Choose, type ChooseOtherwiseProps, type ChooseProps, type ChooseWhenProps, type DebouncedFunction, Flex, type FlexProps, Format, type HexToRgbaProps, If, type IfProps, type JosaProps, type MultiLineEllipsisProps, SafeArea, type SafeAreaCssValueProps, type SafeAreaProps, Spacing, type SpacingProps, Validate, type VariableType, composeEventHandlers, createContext, debounce, ellipsis, getVar, hexToRgba, josa, multiLineEllipsis, queryString, useSafeArea };
228
+ type Mode = 'H' | 'C' | 'W';
229
+ type Wind = 1 | 2 | 3;
230
+ type AirLevel = 1 | 2 | 3 | 4 | 5;
231
+ type UserLevel = '1' | '2' | '3' | '4';
232
+ type Language = 'en' | 'ko';
233
+ declare function formatModeName(mode: Mode, customMapping?: Record<string, string>): string;
234
+ declare function formatModeColor(mode: Mode, customMapping?: Record<string, string>): string;
235
+ declare function formatWind(wind: Wind, customMapping?: Record<string, string>): string;
236
+ declare function formatAirLevelName(level: AirLevel): string;
237
+ declare function formatAirLevelColor(level: AirLevel): string;
238
+ declare const DomainFormat: {
239
+ modeName: typeof formatModeName;
240
+ modeColor: typeof formatModeColor;
241
+ wind: typeof formatWind;
242
+ airLevelName: typeof formatAirLevelName;
243
+ airLevelColor: typeof formatAirLevelColor;
244
+ userLevel: ({ level, language }: {
245
+ level: UserLevel;
246
+ language?: Language;
247
+ }) => string;
248
+ };
249
+
250
+ declare const useCombinedRefs: <T>(...refs: Array<Ref<T>>) => Ref<T>;
251
+
252
+ type UseControllableStateParams<T> = {
253
+ prop?: T | undefined;
254
+ defaultProp?: T | undefined;
255
+ onChange?: (state: T) => void;
256
+ };
257
+ /**
258
+ * @description
259
+ * Radix UI's useControllableState
260
+ */
261
+ declare const useControllableState: <T>({ prop, defaultProp, onChange, }: UseControllableStateParams<T>) => readonly [T | undefined, React.Dispatch<React.SetStateAction<T | undefined>>];
262
+
263
+ export { type AirLevel, Choose, type ChooseOtherwiseProps, type ChooseProps, type ChooseWhenProps, type DebouncedFunction, DomainFormat, Flex, type FlexProps, Format, type HexToRgbaProps, If, type IfProps, type JosaProps, type Mode, type MultiLineEllipsisProps, SafeArea, type SafeAreaCssValueProps, type SafeAreaProps, Spacing, type SpacingProps, type UseControllableStateParams, type UserLevel, Validate, type VariableType, type Wind, composeEventHandlers, createContext, debounce, ellipsis, getVar, hexToRgba, josa, multiLineEllipsis, queryString, useCombinedRefs, useControllableState, useSafeArea };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React from 'react';
3
- import React__default, { ReactNode, FC, PropsWithChildren, HTMLAttributes, CSSProperties, ComponentPropsWithoutRef } from 'react';
3
+ import React__default, { ReactNode, FC, PropsWithChildren, HTMLAttributes, CSSProperties, ComponentPropsWithoutRef, Ref } from 'react';
4
4
  import * as styled_components from 'styled-components';
5
5
 
6
6
  type ChooseWhenProps = {
@@ -225,4 +225,39 @@ declare function formatCommaizeNumber(value: Value): string;
225
225
  */
226
226
  declare function padTime(value: Value): string;
227
227
 
228
- export { Choose, type ChooseOtherwiseProps, type ChooseProps, type ChooseWhenProps, type DebouncedFunction, Flex, type FlexProps, Format, type HexToRgbaProps, If, type IfProps, type JosaProps, type MultiLineEllipsisProps, SafeArea, type SafeAreaCssValueProps, type SafeAreaProps, Spacing, type SpacingProps, Validate, type VariableType, composeEventHandlers, createContext, debounce, ellipsis, getVar, hexToRgba, josa, multiLineEllipsis, queryString, useSafeArea };
228
+ type Mode = 'H' | 'C' | 'W';
229
+ type Wind = 1 | 2 | 3;
230
+ type AirLevel = 1 | 2 | 3 | 4 | 5;
231
+ type UserLevel = '1' | '2' | '3' | '4';
232
+ type Language = 'en' | 'ko';
233
+ declare function formatModeName(mode: Mode, customMapping?: Record<string, string>): string;
234
+ declare function formatModeColor(mode: Mode, customMapping?: Record<string, string>): string;
235
+ declare function formatWind(wind: Wind, customMapping?: Record<string, string>): string;
236
+ declare function formatAirLevelName(level: AirLevel): string;
237
+ declare function formatAirLevelColor(level: AirLevel): string;
238
+ declare const DomainFormat: {
239
+ modeName: typeof formatModeName;
240
+ modeColor: typeof formatModeColor;
241
+ wind: typeof formatWind;
242
+ airLevelName: typeof formatAirLevelName;
243
+ airLevelColor: typeof formatAirLevelColor;
244
+ userLevel: ({ level, language }: {
245
+ level: UserLevel;
246
+ language?: Language;
247
+ }) => string;
248
+ };
249
+
250
+ declare const useCombinedRefs: <T>(...refs: Array<Ref<T>>) => Ref<T>;
251
+
252
+ type UseControllableStateParams<T> = {
253
+ prop?: T | undefined;
254
+ defaultProp?: T | undefined;
255
+ onChange?: (state: T) => void;
256
+ };
257
+ /**
258
+ * @description
259
+ * Radix UI's useControllableState
260
+ */
261
+ declare const useControllableState: <T>({ prop, defaultProp, onChange, }: UseControllableStateParams<T>) => readonly [T | undefined, React.Dispatch<React.SetStateAction<T | undefined>>];
262
+
263
+ export { type AirLevel, Choose, type ChooseOtherwiseProps, type ChooseProps, type ChooseWhenProps, type DebouncedFunction, DomainFormat, Flex, type FlexProps, Format, type HexToRgbaProps, If, type IfProps, type JosaProps, type Mode, type MultiLineEllipsisProps, SafeArea, type SafeAreaCssValueProps, type SafeAreaProps, Spacing, type SpacingProps, type UseControllableStateParams, type UserLevel, Validate, type VariableType, type Wind, composeEventHandlers, createContext, debounce, ellipsis, getVar, hexToRgba, josa, multiLineEllipsis, queryString, useCombinedRefs, useControllableState, useSafeArea };