@sonamu-kit/react-components 0.4.7 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ui/calendar.js +12 -6
- package/dist/components/ui/calendar.js.map +1 -1
- package/dist/components/ui/carousel.js +12 -16
- package/dist/components/ui/carousel.js.map +1 -1
- package/dist/components/ui/common-modal.d.ts +6 -6
- package/dist/components/ui/common-modal.js.map +1 -1
- package/dist/components/ui/date-input.js +6 -5
- package/dist/components/ui/date-input.js.map +1 -1
- package/dist/components/ui/file-input.js +131 -130
- package/dist/components/ui/file-input.js.map +1 -1
- package/dist/components/ui/input.js +21 -20
- package/dist/components/ui/input.js.map +1 -1
- package/dist/components/ui/month-picker-multiple.js +31 -19
- package/dist/components/ui/month-picker-multiple.js.map +1 -1
- package/dist/components/ui/pagination.js +18 -17
- package/dist/components/ui/pagination.js.map +1 -1
- package/dist/components/ui/select/enum-select.js +4 -2
- package/dist/components/ui/select/enum-select.js.map +1 -1
- package/dist/components/ui/select/id-async-select.d.ts +32 -14
- package/dist/components/ui/select/id-async-select.js +185 -144
- package/dist/components/ui/select/id-async-select.js.map +1 -1
- package/dist/components/ui/select/select.js +199 -158
- package/dist/components/ui/select/select.js.map +1 -1
- package/dist/components/ui/sidebar.d.ts +2 -1
- package/dist/components/ui/sidebar.js +54 -45
- package/dist/components/ui/sidebar.js.map +1 -1
- package/dist/components/ui/sonamu-filter/constants.d.ts +27 -3
- package/dist/components/ui/sonamu-filter/constants.js.map +1 -1
- package/dist/components/ui/sonamu-filter/rule-row-input.js +18 -15
- package/dist/components/ui/sonamu-filter/rule-row-input.js.map +1 -1
- package/dist/components/ui/sonamu-filter/sonamu-filter-modal.js +34 -37
- package/dist/components/ui/sonamu-filter/sonamu-filter-modal.js.map +1 -1
- package/dist/components/ui/sonamu-filter/sonamu-filter-popover.js +17 -12
- package/dist/components/ui/sonamu-filter/sonamu-filter-popover.js.map +1 -1
- package/dist/components/ui/sonamu-filter/types.d.ts +14 -9
- package/dist/components/ui/sonamu-filter/utils.d.ts +9 -7
- package/dist/components/ui/sonamu-filter/utils.js +39 -20
- package/dist/components/ui/sonamu-filter/utils.js.map +1 -1
- package/dist/components/ui/sonamu-filter/value-input.js +65 -50
- package/dist/components/ui/sonamu-filter/value-input.js.map +1 -1
- package/dist/contexts/sonamu-context.js +34 -10
- package/dist/contexts/sonamu-context.js.map +1 -1
- package/dist/demo/components/FormDebugPanel.d.ts +1 -1
- package/dist/hooks/use-toast.d.ts +1 -1
- package/dist/hooks/use-toast.js.map +1 -1
- package/dist/lib/base-helpers.d.ts +1 -1
- package/dist/lib/base-helpers.js +7 -7
- package/dist/lib/base-helpers.js.map +1 -1
- package/dist/lib/caster.d.ts +3 -2
- package/dist/lib/caster.js +37 -19
- package/dist/lib/caster.js.map +1 -1
- package/dist/lib/form-helpers.js +38 -35
- package/dist/lib/form-helpers.js.map +1 -1
- package/dist/lib/list-helpers.d.ts +2 -2
- package/dist/lib/list-helpers.js +33 -36
- package/dist/lib/list-helpers.js.map +1 -1
- package/dist/lib/use-mobile.js +5 -7
- package/dist/lib/use-mobile.js.map +1 -1
- package/dist/lib/utils.d.ts +0 -14
- package/dist/lib/utils.js +24 -14
- package/dist/lib/utils.js.map +1 -1
- package/dist/styles/globals.css +38 -106
- package/package.json +5 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-helpers.js","names":[],"sources":["../../src/lib/base-helpers.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */ // 파싱 결과이므로 any 허용\n\nimport { format } from \"date-fns\";\nimport qs from \"qs\";\nimport { isObject } from \"radashi\";\nimport { type z } from \"zod\";\n\nimport { caster } from \"./caster\";\n\n// ============================================================================\n// UI Utilities\n// ============================================================================\n\nexport function hidden(condition: boolean | undefined): string {\n return condition === true ? \"hidden\" : \"\";\n}\n\n// ============================================================================\n// URL / Search Params Conversion\n// ============================================================================\n\nexport function searchParamsToParams<T extends z.ZodType<any>>(\n searchParams: URLSearchParams,\n paramsSchema: T,\n): z.infer<T> {\n const obj = qs.parse(searchParams.toString());\n return caster(paramsSchema, obj);\n}\n\nexport function paramsToSearchParams<T>(params: T): {\n [key in string]: string | string[];\n} {\n return Object.fromEntries(\n // oxlint-disable-next-line unicorn/prefer-array-flat-map -- 여기는 flatMap 사용하면 깨짐\n Object.entries(params
|
|
1
|
+
{"version":3,"file":"base-helpers.js","names":[],"sources":["../../src/lib/base-helpers.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */ // 파싱 결과이므로 any 허용\n\nimport { format } from \"date-fns\";\nimport qs from \"qs\";\nimport { isObject } from \"radashi\";\nimport { type z } from \"zod\";\n\nimport { caster } from \"./caster\";\n\n// ============================================================================\n// UI Utilities\n// ============================================================================\n\nexport function hidden(condition: boolean | undefined): string {\n return condition === true ? \"hidden\" : \"\";\n}\n\n// ============================================================================\n// URL / Search Params Conversion\n// ============================================================================\n\nexport function searchParamsToParams<T extends z.ZodType<any>>(\n searchParams: URLSearchParams,\n paramsSchema: T,\n): z.infer<T> {\n const obj = qs.parse(searchParams.toString());\n return caster(paramsSchema, obj);\n}\n\nexport function paramsToSearchParams<T extends object>(\n params: T,\n): {\n [key in string]: string | string[];\n} {\n return Object.fromEntries(\n // oxlint-disable-next-line unicorn/prefer-array-flat-map -- 여기는 flatMap 사용하면 깨짐\n Object.entries(params)\n .filter(([, value]) => {\n return value !== undefined;\n })\n .map(([key, value]) => {\n if (Array.isArray(value)) {\n return [[`${key}[]`, value]];\n } else if (isObject(value)) {\n return Object.entries(value).map(([subKey, subValue]) => {\n return [`${key}[${subKey}]`, String(subValue)];\n });\n } else {\n return [[key, String(value)]];\n }\n })\n .flat(),\n );\n}\n\n// ============================================================================\n// Formatting Utilities\n// ============================================================================\n\nexport function sqlDateToDateString(sqlDateString: string | null) {\n if (sqlDateString === null) {\n return null;\n } else {\n return sqlDateString.slice(0, 10);\n }\n}\n\nexport function numF(num: number | null | undefined): string | number | undefined | null {\n return num && new Intl.NumberFormat().format(num);\n}\n\nexport function dateF(dateValue: string | Date | null | undefined): string | null {\n if (dateValue === null || dateValue === undefined) {\n return null;\n } else if (dateValue instanceof Date) {\n // toISOString은 UTC로 고정되어 로컬 시간대와 어긋난다. 로컬 기준으로 포맷한다.\n return format(dateValue, \"yyyy-MM-dd\");\n } else {\n return dateValue.slice(0, 10);\n }\n}\n\nexport function datetimeF(dateValue: string | Date | null | undefined): string | null {\n if (dateValue === null || dateValue === undefined) {\n return null;\n } else if (dateValue instanceof Date) {\n // toISOString은 UTC로 고정되어 로컬 시간대와 어긋난다. 로컬 기준으로 포맷한다.\n return format(dateValue, \"yyyy-MM-dd HH:mm:ss\");\n } else {\n return dateValue.slice(0, 19);\n }\n}\n\n// ============================================================================\n// Array Utilities\n// ============================================================================\n\nexport function arrayableToArray<T extends number | string | boolean>(\n val: T | T[] | undefined,\n): T[] {\n return val ? (Array.isArray(val) ? val : [val]) : [];\n}\n\n// ============================================================================\n// Function Reference Utilities\n// ============================================================================\n\nexport function caller<T extends Function>(): { set: (func: T) => void; call: T };\nexport function caller() {\n let savedFunc: Function | null = null;\n return {\n set: (func: Function) => {\n savedFunc = func;\n },\n call: (...args: unknown[]) => {\n if (savedFunc) {\n savedFunc.call(args);\n }\n },\n };\n}\n"],"mappings":";;;;;AAaA,SAAgB,EAAO,GAAwC;CAC7D,OAAO,MAAc,KAAO,WAAW;AACzC;AAMA,SAAgB,EACd,GACA,GACY;CAEZ,OAAO,EAAO,GADF,EAAG,MAAM,EAAa,SAAS,CACf,CAAG;AACjC;AAEA,SAAgB,EACd,GAGA;CACA,OAAO,OAAO,YAEZ,OAAO,QAAQ,CAAM,EAClB,QAAQ,GAAG,OACH,MAAU,KAAA,CAClB,EACA,KAAK,CAAC,GAAK,OACN,MAAM,QAAQ,CAAK,IACd,CAAC,CAAC,GAAG,EAAI,KAAK,CAAK,CAAC,IAClB,EAAS,CAAK,IAChB,OAAO,QAAQ,CAAK,EAAE,KAAK,CAAC,GAAQ,OAClC,CAAC,GAAG,EAAI,GAAG,EAAO,IAAI,OAAO,CAAQ,CAAC,CAC9C,IAEM,CAAC,CAAC,GAAK,OAAO,CAAK,CAAC,CAAC,CAE/B,EACA,KAAK,CACV;AACF;AAMA,SAAgB,EAAoB,GAA8B;CAI9D,OAHE,MAAkB,OACb,OAEA,EAAc,MAAM,GAAG,EAAE;AAEpC;AAEA,SAAgB,EAAK,GAAoE;CACvF,OAAO,KAAO,IAAI,KAAK,aAAa,EAAE,OAAO,CAAG;AAClD;AAEA,SAAgB,EAAM,GAA4D;CAO9E,OANE,KAAc,OACT,OACE,aAAqB,OAEvB,EAAO,GAAW,YAAY,IAE9B,EAAU,MAAM,GAAG,EAAE;AAEhC;AAEA,SAAgB,EAAU,GAA4D;CAOlF,OANE,KAAc,OACT,OACE,aAAqB,OAEvB,EAAO,GAAW,qBAAqB,IAEvC,EAAU,MAAM,GAAG,EAAE;AAEhC;AAMA,SAAgB,EACd,GACK;CACL,OAAO,IAAO,MAAM,QAAQ,CAAG,IAAI,IAAM,CAAC,CAAG,IAAK,CAAC;AACrD;AAOA,SAAgB,IAAS;CACvB,IAAI,IAA6B;CACjC,OAAO;EACL,MAAM,MAAmB;GACvB,IAAY;EACd;EACA,OAAO,GAAG,MAAoB;GAC5B,AAAI,KACF,EAAU,KAAK,CAAI;EAEvB;CACF;AACF"}
|
package/dist/lib/caster.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
2
|
+
export declare function getZodObjectFields(zodObject: z.ZodObject): Record<string, z.ZodType>;
|
|
3
|
+
export declare function caster<T extends z.ZodType<any>>(zodType: T, raw: any): z.infer<T>;
|
|
4
|
+
export declare function fastifyCaster<T extends Record<string, z.ZodType>>(schema: z.ZodObject<T>): z.ZodPipe<z.ZodTransform<any, unknown>, z.ZodObject<T, z.core.$strip>>;
|
package/dist/lib/caster.js
CHANGED
|
@@ -1,27 +1,45 @@
|
|
|
1
1
|
import { z as e } from "zod";
|
|
2
2
|
//#region src/lib/caster.ts
|
|
3
|
-
function t(
|
|
4
|
-
return
|
|
3
|
+
function t(n) {
|
|
4
|
+
return n instanceof e.ZodNumber ? !0 : n instanceof e.ZodNullable || n instanceof e.ZodOptional ? t(n.unwrap()) : !1;
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (a.some((e) => t(e))) if (Array.isArray(i)) {
|
|
11
|
-
let t = a.find((t) => t instanceof e.ZodNumber);
|
|
12
|
-
if (!t) throw Error("Expected to find a number type in union");
|
|
13
|
-
return i.map((e) => n(t, e));
|
|
14
|
-
} else return Number(i);
|
|
15
|
-
} else if (r instanceof e.ZodBoolean && (i === "true" || i === "false")) return i === "true";
|
|
16
|
-
else if (r instanceof e.ZodArray) return i.map((e) => n(r.element, e));
|
|
17
|
-
else if (r instanceof e.ZodObject && typeof i == "object") return Object.keys(i).reduce((e, t) => (e[t] = n(r.shape[t], i[t]), e), {});
|
|
18
|
-
else if (r instanceof e.ZodOptional) return n(r._def.innerType, i);
|
|
19
|
-
return i;
|
|
6
|
+
var n = e.string(), r = e.record(e.string(), e.unknown()), i = e.custom((t) => t instanceof e.ZodType), a = e.record(e.string(), i);
|
|
7
|
+
function o(e) {
|
|
8
|
+
let t = Object.entries(e.def).find(([e]) => e === "shape");
|
|
9
|
+
return a.parse(t?.[1]);
|
|
20
10
|
}
|
|
21
|
-
function
|
|
22
|
-
|
|
11
|
+
function s(i, a) {
|
|
12
|
+
if (t(i) && n.safeParse(a).success) return Number(a);
|
|
13
|
+
if (i instanceof e.ZodUnion) {
|
|
14
|
+
if (i.options.some((e) => t(e))) {
|
|
15
|
+
if (Array.isArray(a)) {
|
|
16
|
+
let e = i.options.find((e) => t(e));
|
|
17
|
+
if (e === void 0) throw Error("Expected to find a number type in union");
|
|
18
|
+
return a.map((t) => s(e, t));
|
|
19
|
+
}
|
|
20
|
+
return Number(a);
|
|
21
|
+
}
|
|
22
|
+
} else if (i instanceof e.ZodBoolean && (a === "true" || a === "false")) return a === "true";
|
|
23
|
+
else if (i instanceof e.ZodArray && Array.isArray(a)) return a.map((e) => s(i.element, e));
|
|
24
|
+
else if (i instanceof e.ZodObject) {
|
|
25
|
+
let e = r.safeParse(a);
|
|
26
|
+
if (e.success) {
|
|
27
|
+
let t = o(i);
|
|
28
|
+
return Object.fromEntries(Object.entries(e.data).map(([e, n]) => {
|
|
29
|
+
let r = t[e];
|
|
30
|
+
return [e, r === void 0 ? n : s(r, n)];
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
} else if (i instanceof e.ZodOptional || i instanceof e.ZodNullable) return s(i.unwrap(), a);
|
|
34
|
+
return a;
|
|
35
|
+
}
|
|
36
|
+
function c(e, t) {
|
|
37
|
+
return s(e, t);
|
|
38
|
+
}
|
|
39
|
+
function l(t) {
|
|
40
|
+
return e.preprocess((e) => s(t, e), t);
|
|
23
41
|
}
|
|
24
42
|
//#endregion
|
|
25
|
-
export {
|
|
43
|
+
export { c as caster, l as fastifyCaster, o as getZodObjectFields };
|
|
26
44
|
|
|
27
45
|
//# sourceMappingURL=caster.js.map
|
package/dist/lib/caster.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caster.js","names":[],"sources":["../../src/lib/caster.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */ // caster 함수에는 any가 필요함\nimport { z } from \"zod\";\n\n// optional, nullable 무관하게 ZodNumber 체크\nfunction isZodNumberAnyway(zodType:
|
|
1
|
+
{"version":3,"file":"caster.js","names":[],"sources":["../../src/lib/caster.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */ // caster 함수에는 any가 필요함\nimport { z } from \"zod\";\n\n// optional, nullable 무관하게 ZodNumber 체크\nfunction isZodNumberAnyway(zodType: any): boolean {\n if (zodType instanceof z.ZodNumber) {\n return true;\n }\n if (zodType instanceof z.ZodNullable || zodType instanceof z.ZodOptional) {\n return isZodNumberAnyway(zodType.unwrap());\n }\n return false;\n}\n\nconst stringValue = z.string();\nconst objectValue = z.record(z.string(), z.unknown());\nconst zodTypeValue = z.custom<z.ZodType>((value) => value instanceof z.ZodType);\nconst zodFieldsValue = z.record(z.string(), zodTypeValue);\n\nexport function getZodObjectFields(zodObject: z.ZodObject): Record<string, z.ZodType> {\n const fieldsEntry = Object.entries(zodObject.def).find(([property]) => property === \"shape\");\n return zodFieldsValue.parse(fieldsEntry?.[1]);\n}\n\n// ZodType을 이용해 입력값을 타입에 맞게 변환합니다.\nfunction coerceInput(zodType: any, raw: any): any {\n if (isZodNumberAnyway(zodType) && stringValue.safeParse(raw).success) {\n return Number(raw);\n }\n\n if (zodType instanceof z.ZodUnion) {\n if (zodType.options.some((option: any) => isZodNumberAnyway(option))) {\n if (Array.isArray(raw)) {\n const numberType = zodType.options.find((option: any) => isZodNumberAnyway(option));\n if (numberType === undefined) {\n throw new Error(\"Expected to find a number type in union\");\n }\n return raw.map((element) => coerceInput(numberType, element));\n }\n return Number(raw);\n }\n } else if (zodType instanceof z.ZodBoolean && (raw === \"true\" || raw === \"false\")) {\n return raw === \"true\";\n } else if (zodType instanceof z.ZodArray && Array.isArray(raw)) {\n return raw.map((element) => coerceInput(zodType.element, element));\n } else if (zodType instanceof z.ZodObject) {\n const parsedObject = objectValue.safeParse(raw);\n if (parsedObject.success) {\n const fields = getZodObjectFields(zodType);\n return Object.fromEntries(\n Object.entries(parsedObject.data).map(([key, value]) => {\n const fieldType = fields[key];\n return [key, fieldType === undefined ? value : coerceInput(fieldType, value)];\n }),\n );\n }\n } else if (zodType instanceof z.ZodOptional || zodType instanceof z.ZodNullable) {\n return coerceInput(zodType.unwrap(), raw);\n }\n\n return raw;\n}\n\nexport function caster<T extends z.ZodType<any>>(zodType: T, raw: any): z.infer<T>;\nexport function caster(zodType: any, raw: any): any {\n return coerceInput(zodType, raw);\n}\n\nexport function fastifyCaster<T extends Record<string, z.ZodType>>(schema: z.ZodObject<T>) {\n return z.preprocess((raw) => coerceInput(schema, raw), schema);\n}\n"],"mappings":";;AAIA,SAAS,EAAkB,GAAuB;CAOhD,OANI,aAAmB,EAAE,YAChB,KAEL,aAAmB,EAAE,eAAe,aAAmB,EAAE,cACpD,EAAkB,EAAQ,OAAO,CAAC,IAEpC;AACT;AAEA,IAAM,IAAc,EAAE,OAAO,GACvB,IAAc,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,GAC9C,IAAe,EAAE,QAAmB,MAAU,aAAiB,EAAE,OAAO,GACxE,IAAiB,EAAE,OAAO,EAAE,OAAO,GAAG,CAAY;AAExD,SAAgB,EAAmB,GAAmD;CACpF,IAAM,IAAc,OAAO,QAAQ,EAAU,GAAG,EAAE,MAAM,CAAC,OAAc,MAAa,OAAO;CAC3F,OAAO,EAAe,MAAM,IAAc,EAAE;AAC9C;AAGA,SAAS,EAAY,GAAc,GAAe;CAChD,IAAI,EAAkB,CAAO,KAAK,EAAY,UAAU,CAAG,EAAE,SAC3D,OAAO,OAAO,CAAG;CAGnB,IAAI,aAAmB,EAAE;MACnB,EAAQ,QAAQ,MAAM,MAAgB,EAAkB,CAAM,CAAC,GAAG;GACpE,IAAI,MAAM,QAAQ,CAAG,GAAG;IACtB,IAAM,IAAa,EAAQ,QAAQ,MAAM,MAAgB,EAAkB,CAAM,CAAC;IAClF,IAAI,MAAe,KAAA,GACjB,MAAU,MAAM,yCAAyC;IAE3D,OAAO,EAAI,KAAK,MAAY,EAAY,GAAY,CAAO,CAAC;GAC9D;GACA,OAAO,OAAO,CAAG;EACnB;QACK,IAAI,aAAmB,EAAE,eAAe,MAAQ,UAAU,MAAQ,UACvE,OAAO,MAAQ;MACV,IAAI,aAAmB,EAAE,YAAY,MAAM,QAAQ,CAAG,GAC3D,OAAO,EAAI,KAAK,MAAY,EAAY,EAAQ,SAAS,CAAO,CAAC;MAC5D,IAAI,aAAmB,EAAE,WAAW;EACzC,IAAM,IAAe,EAAY,UAAU,CAAG;EAC9C,IAAI,EAAa,SAAS;GACxB,IAAM,IAAS,EAAmB,CAAO;GACzC,OAAO,OAAO,YACZ,OAAO,QAAQ,EAAa,IAAI,EAAE,KAAK,CAAC,GAAK,OAAW;IACtD,IAAM,IAAY,EAAO;IACzB,OAAO,CAAC,GAAK,MAAc,KAAA,IAAY,IAAQ,EAAY,GAAW,CAAK,CAAC;GAC9E,CAAC,CACH;EACF;CACF,OAAO,IAAI,aAAmB,EAAE,eAAe,aAAmB,EAAE,aAClE,OAAO,EAAY,EAAQ,OAAO,GAAG,CAAG;CAG1C,OAAO;AACT;AAGA,SAAgB,EAAO,GAAc,GAAe;CAClD,OAAO,EAAY,GAAS,CAAG;AACjC;AAEA,SAAgB,EAAmD,GAAwB;CACzF,OAAO,EAAE,YAAY,MAAQ,EAAY,GAAQ,CAAG,GAAG,CAAM;AAC/D"}
|
package/dist/lib/form-helpers.js
CHANGED
|
@@ -1,74 +1,77 @@
|
|
|
1
1
|
import { useSonamuBaseContext as e } from "../contexts/sonamu-context.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { getZodObjectFields as t } from "./caster.js";
|
|
3
|
+
import { useState as n } from "react";
|
|
4
|
+
import { get as r, set as i } from "radashi";
|
|
5
|
+
import { z as a } from "zod";
|
|
5
6
|
//#region src/lib/form-helpers.ts
|
|
6
|
-
|
|
7
|
+
var o = a.record(a.string(), a.any()), s = a.string();
|
|
8
|
+
async function c(e, t) {
|
|
7
9
|
if (e instanceof File) {
|
|
8
10
|
let [n] = await t([e]);
|
|
9
11
|
return n;
|
|
10
12
|
}
|
|
11
|
-
if (Array.isArray(e)) return e.length > 0 && e.every((e) => e instanceof File) ? await t(e) : await Promise.all(e.map((e) =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (Array.isArray(e)) return e.length > 0 && e.every((e) => e instanceof File) ? await t(e) : await Promise.all(e.map((e) => c(e, t)));
|
|
14
|
+
let n = o.safeParse(e);
|
|
15
|
+
if (n.success && Object.prototype.toString.call(e) === "[object Object]") {
|
|
16
|
+
let e = {};
|
|
17
|
+
for (let [r, i] of Object.entries(n.data)) e[r] = await c(i, t);
|
|
18
|
+
return e;
|
|
16
19
|
}
|
|
17
20
|
return e;
|
|
18
21
|
}
|
|
19
|
-
function
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
22
|
+
function l(e, n) {
|
|
23
|
+
let i = n.replace(/\./g, ".shape.").replace(/\[[^\]]+\]/g, ".element").replace(/^\.element/, "element"), o;
|
|
24
|
+
return e instanceof a.ZodObject ? o = r(t(e), i) : e instanceof a.ZodArray && (o = r(e, i)), o === void 0 ? "normal" : o instanceof a.ZodOptional ? "optional" : o instanceof a.ZodNullable ? "nullable" : "normal";
|
|
25
|
+
}
|
|
26
|
+
function u(t, a) {
|
|
27
|
+
let [o, u] = n(a), [d, f] = n(/* @__PURE__ */ new Map()), { uploader: p } = e();
|
|
25
28
|
return {
|
|
26
|
-
form:
|
|
27
|
-
setForm:
|
|
28
|
-
register: (e,
|
|
29
|
-
let
|
|
30
|
-
value:
|
|
29
|
+
form: o,
|
|
30
|
+
setForm: u,
|
|
31
|
+
register: (e, n) => {
|
|
32
|
+
let a = n ?? l(t, e), s = r(o, e), c = d.get(e), p = {
|
|
33
|
+
value: s ?? "",
|
|
31
34
|
onValueChange: (t) => {
|
|
32
|
-
|
|
35
|
+
c !== void 0 && f((t) => {
|
|
33
36
|
let n = new Map(t);
|
|
34
37
|
return n.delete(e), n;
|
|
35
38
|
});
|
|
36
39
|
let n = t;
|
|
37
|
-
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
...
|
|
40
|
+
a === "nullable" ? n = t === "" ? null : t : a === "optional" && (n = t === "" ? void 0 : t);
|
|
41
|
+
let r = e.indexOf(".") === -1 && e.indexOf("[") === -1;
|
|
42
|
+
u(n === void 0 && r ? {
|
|
43
|
+
...o,
|
|
41
44
|
[e]: void 0
|
|
42
|
-
} :
|
|
45
|
+
} : i(o, e, n));
|
|
43
46
|
}
|
|
44
47
|
};
|
|
45
|
-
return
|
|
48
|
+
return c && (p.error = c), p;
|
|
46
49
|
},
|
|
47
50
|
submit: (e) => async () => {
|
|
48
|
-
let t = await
|
|
49
|
-
return
|
|
51
|
+
let t = await c(o, p);
|
|
52
|
+
return u(t), await e(t);
|
|
50
53
|
},
|
|
51
54
|
addError: (e, t) => {
|
|
52
|
-
|
|
55
|
+
f((n) => {
|
|
53
56
|
let r = new Map(n);
|
|
54
|
-
return r.set(e,
|
|
57
|
+
return r.set(e, s.safeParse(t).success ? { content: String(t) } : t), r;
|
|
55
58
|
});
|
|
56
59
|
},
|
|
57
60
|
removeError: (e) => {
|
|
58
|
-
|
|
61
|
+
f((t) => {
|
|
59
62
|
let n = new Map(t);
|
|
60
63
|
return n.delete(e), n;
|
|
61
64
|
});
|
|
62
65
|
},
|
|
63
66
|
clearError: () => {
|
|
64
|
-
|
|
67
|
+
f(/* @__PURE__ */ new Map());
|
|
65
68
|
},
|
|
66
69
|
reset: () => {
|
|
67
|
-
|
|
70
|
+
u(a);
|
|
68
71
|
}
|
|
69
72
|
};
|
|
70
73
|
}
|
|
71
74
|
//#endregion
|
|
72
|
-
export {
|
|
75
|
+
export { u as useTypeForm };
|
|
73
76
|
|
|
74
77
|
//# sourceMappingURL=form-helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-helpers.js","names":[],"sources":["../../src/lib/form-helpers.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */ // 파싱 결과이므로 any 허용\n\nimport { get, set } from \"radashi\";\nimport { useState } from \"react\";\nimport { z } from \"zod\";\n\nimport { type SonamuFile } from \"@/contexts\";\nimport { useSonamuBaseContext } from \"@/contexts\";\n\nimport { type ErrorObj } from \"./types\";\n\n/**\n * FormRegisterReturn\n *\n * register 함수의 반환 타입입니다.\n */\nexport type FormRegisterReturn = {\n value: any;\n onValueChange: (value: any) => void;\n onRowChange?: (row: any) => void;\n error?: ErrorObj;\n};\n\n/**\n * traverseAndUploadFiles\n *\n * 폼 데이터 안에 중첩되어 있는 File 객체들을 재귀적으로 찾아서 업로드하고,\n * File 객체를 업로드된 SonamuFile 객체로 변환하는 헬퍼 함수입니다.\n *\n * @param value - 검사할 값 (원시값, File, 배열, 객체 등 모든 타입 가능)\n * @param uploader - File 배열을 받아서 업로드된 SonamuFile 배열을 반환하는 함수\n * @returns 변환된 값 (File 객체는 SonamuFile 객체로, 나머지는 원본 구조 유지)\n */\nasync function traverseAndUploadFiles(\n value: any,\n uploader: (files: File[]) => Promise<SonamuFile[]>,\n): Promise<any> {\n // 1. File 객체를 발견한 경우\n if (value instanceof File) {\n const [sonamuFile] = await uploader([value]);\n return sonamuFile;\n }\n\n // 2. 배열을 발견한 경우\n if (Array.isArray(value)) {\n // 2-1. 배열의 모든 요소가 File이면 일괄 업로드 (성능 최적화)\n if (value.length > 0 && value.every((item) => item instanceof File)) {\n return await uploader(value);\n }\n // 2-2. 배열에 File이 아닌 요소가 섞여 있으면 각 요소를 재귀적으로 처리\n return await Promise.all(value.map((item) => traverseAndUploadFiles(item, uploader)));\n }\n\n // 3. 일반 객체를 발견한 경우 (null, Date, RegExp 등 특수 객체 제외)\n
|
|
1
|
+
{"version":3,"file":"form-helpers.js","names":[],"sources":["../../src/lib/form-helpers.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */ // 파싱 결과이므로 any 허용\n\nimport { get, set } from \"radashi\";\nimport { useState } from \"react\";\nimport { z } from \"zod\";\n\nimport { type SonamuFile } from \"@/contexts\";\nimport { useSonamuBaseContext } from \"@/contexts\";\n\nimport { getZodObjectFields } from \"./caster\";\nimport { type ErrorObj } from \"./types\";\n\nconst plainObjectValue = z.record(z.string(), z.any());\nconst stringValue = z.string();\n\n/**\n * FormRegisterReturn\n *\n * register 함수의 반환 타입입니다.\n */\nexport type FormRegisterReturn = {\n value: any;\n onValueChange: (value: any) => void;\n onRowChange?: (row: any) => void;\n error?: ErrorObj;\n};\n\n/**\n * traverseAndUploadFiles\n *\n * 폼 데이터 안에 중첩되어 있는 File 객체들을 재귀적으로 찾아서 업로드하고,\n * File 객체를 업로드된 SonamuFile 객체로 변환하는 헬퍼 함수입니다.\n *\n * @param value - 검사할 값 (원시값, File, 배열, 객체 등 모든 타입 가능)\n * @param uploader - File 배열을 받아서 업로드된 SonamuFile 배열을 반환하는 함수\n * @returns 변환된 값 (File 객체는 SonamuFile 객체로, 나머지는 원본 구조 유지)\n */\nasync function traverseAndUploadFiles(\n value: any,\n uploader: (files: File[]) => Promise<SonamuFile[]>,\n): Promise<any> {\n // 1. File 객체를 발견한 경우\n if (value instanceof File) {\n const [sonamuFile] = await uploader([value]);\n return sonamuFile;\n }\n\n // 2. 배열을 발견한 경우\n if (Array.isArray(value)) {\n // 2-1. 배열의 모든 요소가 File이면 일괄 업로드 (성능 최적화)\n if (value.length > 0 && value.every((item) => item instanceof File)) {\n return await uploader(value);\n }\n // 2-2. 배열에 File이 아닌 요소가 섞여 있으면 각 요소를 재귀적으로 처리\n return await Promise.all(value.map((item) => traverseAndUploadFiles(item, uploader)));\n }\n\n // 3. 일반 객체를 발견한 경우 (null, Date, RegExp 등 특수 객체 제외)\n const parsedObject = plainObjectValue.safeParse(value);\n if (parsedObject.success && Object.prototype.toString.call(value) === \"[object Object]\") {\n // 객체의 각 속성을 재귀적으로 순회하며 File 객체를 찾아서 업로드\n const result: any = {};\n for (const [key, val] of Object.entries(parsedObject.data)) {\n result[key] = await traverseAndUploadFiles(val, uploader);\n }\n return result;\n }\n\n // 4. 원시값(string, number, boolean 등)은 변환 없이 그대로 반환\n return value;\n}\n\nfunction getEmptyStringTo<T extends z.ZodObject<any> | z.ZodArray<any>>(\n zType: T,\n objPath: string,\n): \"normal\" | \"nullable\" | \"optional\" {\n const zTypeObjPath = objPath\n .replace(/\\./g, \".shape.\")\n .replace(/\\[[^\\]]+\\]/g, \".element\")\n .replace(/^\\.element/, \"element\");\n\n let targetZType: unknown;\n if (zType instanceof z.ZodObject) {\n targetZType = get(getZodObjectFields(zType), zTypeObjPath);\n } else if (zType instanceof z.ZodArray) {\n targetZType = get(zType, zTypeObjPath);\n }\n\n if (targetZType === undefined) {\n return \"normal\";\n } else if (targetZType instanceof z.ZodOptional) {\n return \"optional\";\n } else if (targetZType instanceof z.ZodNullable) {\n return \"nullable\";\n }\n return \"normal\";\n}\n\nexport function useTypeForm<T extends z.ZodObject<any> | z.ZodArray<any>, U extends z.infer<T>>(\n zType: T,\n defaultValue: U,\n) {\n const [form, setForm] = useState<z.infer<T>>(defaultValue);\n const [errorObjs, setErrorObjs] = useState(new Map());\n const { uploader } = useSonamuBaseContext();\n\n return {\n form,\n setForm,\n register: (\n objPath: string,\n _emptyStringTo?: \"normal\" | \"nullable\" | \"optional\",\n ): FormRegisterReturn => {\n const emptyStringTo = _emptyStringTo ?? getEmptyStringTo(zType, objPath);\n const srcValue = get(form, objPath);\n\n const error = errorObjs.get(objPath);\n\n // value 업데이트 로직\n const updateValue = (newValue: any) => {\n if (error !== undefined) {\n setErrorObjs((p) => {\n const newP = new Map(p);\n newP.delete(objPath);\n return newP;\n });\n }\n\n let processedValue = newValue;\n if (emptyStringTo === \"nullable\") {\n processedValue = newValue === \"\" ? null : newValue;\n } else if (emptyStringTo === \"optional\") {\n processedValue = newValue === \"\" ? undefined : newValue;\n }\n\n // 최상위 속성인지 확인\n const isTopLevelPath = objPath.indexOf(\".\") === -1 && objPath.indexOf(\"[\") === -1;\n\n // radashi의 set은 undefined 값을 처리하지 못하므로, 최상위 속성은 직접 설정\n // 관련 이슈: https://github.com/sodiray/radash/issues/432\n if (processedValue === undefined && isTopLevelPath) {\n setForm({ ...form, [objPath]: undefined });\n } else {\n setForm(set(form, objPath, processedValue));\n }\n };\n\n const result: FormRegisterReturn = {\n value: srcValue === undefined || srcValue === null ? \"\" : srcValue,\n onValueChange: updateValue,\n };\n\n // error가 있으면 추가\n if (error) {\n result.error = error;\n }\n\n return result;\n },\n submit:\n <R>(callback: (formData: z.infer<T>) => Promise<R>) =>\n async () => {\n const transformedForm = await traverseAndUploadFiles(form, uploader);\n setForm(transformedForm);\n return await callback(transformedForm);\n },\n addError: (objPath: string, errorMessage: string | ErrorObj): void => {\n setErrorObjs((p) => {\n const newP = new Map(p);\n newP.set(\n objPath,\n stringValue.safeParse(errorMessage).success\n ? { content: String(errorMessage) }\n : errorMessage,\n );\n return newP;\n });\n },\n removeError: (objPath: string): void => {\n setErrorObjs((p) => {\n const newP = new Map(p);\n newP.delete(objPath);\n return newP;\n });\n },\n clearError: (): void => {\n setErrorObjs(new Map());\n },\n reset: (): void => {\n setForm(defaultValue);\n },\n };\n}\n"],"mappings":"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"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
type ZodKeys<T extends z.ZodType<any>> = keyof z.infer<T>;
|
|
4
|
-
export declare function useListParams<U extends z.
|
|
4
|
+
export declare function useListParams<U extends z.ZodObject<any>, T extends Partial<z.infer<U>>>(zType: U, defaultValue: T, options?: {
|
|
5
5
|
disableSearchParams?: boolean;
|
|
6
6
|
}): {
|
|
7
7
|
listParams: T;
|
|
8
|
-
setListParams: (newParams:
|
|
8
|
+
setListParams: (newParams: Partial<z.infer<U>>) => void;
|
|
9
9
|
register: (name: ZodKeys<U>) => any;
|
|
10
10
|
};
|
|
11
11
|
export declare function useSelection<T>(allKeys: T[], defaultSelectedKeys?: T[]): {
|
package/dist/lib/list-helpers.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { unique as
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { useState as e } from "react";
|
|
2
|
+
import { unique as t } from "radashi";
|
|
3
|
+
import { useRouter as n, useSearch as r } from "@tanstack/react-router";
|
|
4
|
+
import i from "fast-deep-equal";
|
|
5
5
|
//#region src/lib/list-helpers.ts
|
|
6
|
-
function
|
|
6
|
+
function a(e, t) {
|
|
7
7
|
return e.filter((e) => t.includes(e));
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
let o =
|
|
11
|
-
if (
|
|
12
|
-
let
|
|
13
|
-
return
|
|
9
|
+
function o(e, t, a) {
|
|
10
|
+
let o = r({ strict: !1 }), s = n(), c = (() => {
|
|
11
|
+
if (a?.disableSearchParams) return t;
|
|
12
|
+
let n = e.safeParse(o);
|
|
13
|
+
return n.success ? {
|
|
14
14
|
...t,
|
|
15
|
-
...
|
|
15
|
+
...n.data
|
|
16
16
|
} : t;
|
|
17
17
|
})(), l = (e) => {
|
|
18
|
-
|
|
18
|
+
i(c, e) || s.navigate({ search: () => e });
|
|
19
19
|
};
|
|
20
|
-
function u(
|
|
21
|
-
let
|
|
20
|
+
function u(n) {
|
|
21
|
+
let r = c[n], i = t[n];
|
|
22
22
|
return {
|
|
23
|
-
value:
|
|
23
|
+
value: r ?? i ?? (n === "page" ? 1 : ""),
|
|
24
24
|
onValueChange: (t) => {
|
|
25
|
-
l(
|
|
25
|
+
l(n === "page" ? e.parse({
|
|
26
26
|
...c,
|
|
27
27
|
page: t
|
|
28
|
-
} : {
|
|
28
|
+
}) : e.parse({
|
|
29
29
|
...c,
|
|
30
30
|
page: 1,
|
|
31
|
-
[
|
|
32
|
-
});
|
|
31
|
+
[n]: t === "" ? void 0 : t
|
|
32
|
+
}));
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
}
|
|
@@ -39,32 +39,29 @@ function s(e, t, n) {
|
|
|
39
39
|
register: u
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
let [
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
o(r, e).length !== e.length && s(new Map(Array.from(a).filter(([e, t]) => r.includes(e))));
|
|
47
|
-
}, [r, a]);
|
|
48
|
-
let u = Array.from(a).filter(([e, t]) => r.includes(e) && t).map(([e]) => e);
|
|
42
|
+
function s(n, r = []) {
|
|
43
|
+
let [i, o] = e(new Map(n.map((e) => [e, r.includes(e)]))), [s, c] = e(0), l = Array.from(i.keys());
|
|
44
|
+
a(n, l).length !== l.length && o(new Map(Array.from(i).filter(([e]) => n.includes(e))));
|
|
45
|
+
let u = Array.from(i).filter(([e, t]) => n.includes(e) && t).map(([e]) => e);
|
|
49
46
|
return {
|
|
50
|
-
getSelected: (e) =>
|
|
47
|
+
getSelected: (e) => i.get(e) ?? !1,
|
|
51
48
|
toggle: (e) => {
|
|
52
|
-
|
|
49
|
+
o((t) => new Map([...t, [e, !(t.get(e) ?? !1)]]));
|
|
53
50
|
},
|
|
54
51
|
selectedKeys: u,
|
|
55
|
-
deselectAll: () =>
|
|
56
|
-
selectAll: () =>
|
|
57
|
-
isAllSelected: u.length ===
|
|
58
|
-
handleCheckboxClick: (e,
|
|
52
|
+
deselectAll: () => o(new Map(n.map((e) => [e, !1]))),
|
|
53
|
+
selectAll: () => o(new Map(n.map((e) => [e, !0]))),
|
|
54
|
+
isAllSelected: u.length === n.length,
|
|
55
|
+
handleCheckboxClick: (e, r) => {
|
|
59
56
|
let i = e.currentTarget.getElementsByTagName("input");
|
|
60
57
|
if (e.shiftKey && !i[0]?.checked) {
|
|
61
|
-
let [e, i] =
|
|
62
|
-
|
|
63
|
-
} else
|
|
58
|
+
let [e, i] = s < r ? [s, r] : [r + 1, s];
|
|
59
|
+
o(new Map(t([...u, ...n.slice(e, i)]).map((e) => [e, !0])));
|
|
60
|
+
} else c(r);
|
|
64
61
|
}
|
|
65
62
|
};
|
|
66
63
|
}
|
|
67
64
|
//#endregion
|
|
68
|
-
export {
|
|
65
|
+
export { o as useListParams, s as useSelection };
|
|
69
66
|
|
|
70
67
|
//# sourceMappingURL=list-helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-helpers.js","names":[],"sources":["../../src/lib/list-helpers.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */ // 파싱 결과이므로 any 허용\n\nimport {
|
|
1
|
+
{"version":3,"file":"list-helpers.js","names":[],"sources":["../../src/lib/list-helpers.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */ // 파싱 결과이므로 any 허용\n\nimport {\n type RootRoute,\n type Router,\n type NavigateOptions,\n useRouter,\n useSearch,\n} from \"@tanstack/react-router\";\nimport equal from \"fast-deep-equal\";\nimport { unique } from \"radashi\";\nimport type React from \"react\";\nimport { useState } from \"react\";\nimport { type z } from \"zod\";\n\n// radashi에 intersection이 없으므로 직접 구현\nfunction intersection<T>(arr1: T[], arr2: T[]): T[] {\n return arr1.filter((item) => arr2.includes(item));\n}\n\ntype ZodKeys<T extends z.ZodType<any>> = keyof z.infer<T>;\ninterface RouterSearch {}\ninterface RouterSearchValidator {\n parse(input: RouterSearch): RouterSearch;\n}\ntype ListParamsRouter = Router<RootRoute<unknown, RouterSearchValidator>>;\n\nexport function useListParams<U extends z.ZodObject<any>, T extends Partial<z.infer<U>>>(\n zType: U,\n defaultValue: T,\n options?: {\n disableSearchParams?: boolean;\n },\n) {\n const search = useSearch({ strict: false });\n const router = useRouter<ListParamsRouter>();\n\n // URL에서 파라미터 파싱\n const listParams = (() => {\n if (options?.disableSearchParams) {\n return defaultValue;\n }\n\n const parsed = zType.safeParse(search);\n if (parsed.success) {\n return { ...defaultValue, ...parsed.data };\n }\n return defaultValue;\n })();\n\n const setListParams = (newParams: Partial<z.infer<U>>) => {\n if (equal(listParams, newParams)) {\n return;\n }\n\n const navigation: NavigateOptions<ListParamsRouter> = {\n // 현재 검색 파라미터를 새 목록 상태로 교체하되 직렬화와 히스토리는 라우터에 맡깁니다.\n search: () => newParams,\n };\n router.navigate(navigation);\n };\n\n function register(name: ZodKeys<U>): any {\n const currentValue = listParams[name];\n const defaultVal = defaultValue[name];\n\n return {\n value: currentValue ?? defaultVal ?? (name === \"page\" ? 1 : \"\"),\n onValueChange: (value: any) => {\n if (name === \"page\") {\n setListParams(zType.parse({ ...listParams, page: value }));\n } else {\n setListParams(\n zType.parse({\n ...listParams,\n page: 1,\n [name]: value === \"\" ? undefined : value,\n }),\n );\n }\n },\n };\n }\n\n return {\n listParams,\n setListParams,\n register,\n };\n}\n\nexport function useSelection<T>(allKeys: T[], defaultSelectedKeys: T[] = []) {\n const [selection, setSelection] = useState(\n new Map(allKeys.map((key) => [key, defaultSelectedKeys.includes(key)])),\n );\n const [lastIndex, setLastIndex] = useState(0);\n\n // 전체 키에서 제거된 선택 항목은 같은 렌더에서 정리합니다.\n const selectionKeys = Array.from(selection.keys());\n if (intersection(allKeys, selectionKeys).length !== selectionKeys.length) {\n setSelection(new Map(Array.from(selection).filter(([key]) => allKeys.includes(key))));\n }\n\n const selectedKeys = Array.from(selection)\n .filter(([key, value]) => allKeys.includes(key) && value)\n .map(([key]) => key);\n\n return {\n getSelected: (key: T) => selection.get(key) ?? false,\n toggle: (key: T) => {\n setSelection((currentSelection) => {\n return new Map([...currentSelection, [key, !(currentSelection.get(key) ?? false)]]);\n });\n },\n selectedKeys,\n deselectAll: () => setSelection(new Map(allKeys.map((key) => [key, false]))),\n selectAll: () => setSelection(new Map(allKeys.map((key) => [key, true]))),\n isAllSelected: selectedKeys.length === allKeys.length,\n handleCheckboxClick: (e: React.MouseEvent<HTMLInputElement>, index: number) => {\n const input = e.currentTarget.getElementsByTagName(\"input\");\n if (e.shiftKey && !input[0]?.checked) {\n const [begin, end] = (() => {\n if (lastIndex < index) {\n return [lastIndex, index];\n } else {\n return [index + 1, lastIndex];\n }\n })();\n setSelection(\n new Map(unique([...selectedKeys, ...allKeys.slice(begin, end)]).map((k: T) => [k, true])),\n );\n } else {\n setLastIndex(index);\n }\n },\n };\n}\n"],"mappings":";;;;;AAgBA,SAAS,EAAgB,GAAW,GAAgB;CAClD,OAAO,EAAK,QAAQ,MAAS,EAAK,SAAS,CAAI,CAAC;AAClD;AASA,SAAgB,EACd,GACA,GACA,GAGA;CACA,IAAM,IAAS,EAAU,EAAE,QAAQ,GAAM,CAAC,GACpC,IAAS,EAA4B,GAGrC,WAAoB;EACxB,IAAI,GAAS,qBACX,OAAO;EAGT,IAAM,IAAS,EAAM,UAAU,CAAM;EAIrC,OAHI,EAAO,UACF;GAAE,GAAG;GAAc,GAAG,EAAO;EAAK,IAEpC;CACT,GAAG,GAEG,KAAiB,MAAmC;EACpD,EAAM,GAAY,CAAS,KAQ/B,EAAO,SAAS,EAFd,cAAc,EAEA,CAAU;CAC5B;CAEA,SAAS,EAAS,GAAuB;EACvC,IAAM,IAAe,EAAW,IAC1B,IAAa,EAAa;EAEhC,OAAO;GACL,OAAO,KAAgB,MAAe,MAAS,SAAS,IAAI;GAC5D,gBAAgB,MAAe;IAC7B,AACE,EADE,MAAS,SACG,EAAM,MAAM;KAAE,GAAG;KAAY,MAAM;IAAM,CAAC,IAGtD,EAAM,MAAM;KACV,GAAG;KACH,MAAM;MACL,IAAO,MAAU,KAAK,KAAA,IAAY;IACrC,CAAC,CACH;GAEJ;EACF;CACF;CAEA,OAAO;EACL;EACA;EACA;CACF;AACF;AAEA,SAAgB,EAAgB,GAAc,IAA2B,CAAC,GAAG;CAC3E,IAAM,CAAC,GAAW,KAAgB,EAChC,IAAI,IAAI,EAAQ,KAAK,MAAQ,CAAC,GAAK,EAAoB,SAAS,CAAG,CAAC,CAAC,CAAC,CACxE,GACM,CAAC,GAAW,KAAgB,EAAS,CAAC,GAGtC,IAAgB,MAAM,KAAK,EAAU,KAAK,CAAC;CACjD,AAAI,EAAa,GAAS,CAAa,EAAE,WAAW,EAAc,UAChE,EAAa,IAAI,IAAI,MAAM,KAAK,CAAS,EAAE,QAAQ,CAAC,OAAS,EAAQ,SAAS,CAAG,CAAC,CAAC,CAAC;CAGtF,IAAM,IAAe,MAAM,KAAK,CAAS,EACtC,QAAQ,CAAC,GAAK,OAAW,EAAQ,SAAS,CAAG,KAAK,CAAK,EACvD,KAAK,CAAC,OAAS,CAAG;CAErB,OAAO;EACL,cAAc,MAAW,EAAU,IAAI,CAAG,KAAK;EAC/C,SAAS,MAAW;GAClB,GAAc,MACL,IAAI,IAAI,CAAC,GAAG,GAAkB,CAAC,GAAK,EAAE,EAAiB,IAAI,CAAG,KAAK,GAAM,CAAC,CAAC,CACnF;EACH;EACA;EACA,mBAAmB,EAAa,IAAI,IAAI,EAAQ,KAAK,MAAQ,CAAC,GAAK,EAAK,CAAC,CAAC,CAAC;EAC3E,iBAAiB,EAAa,IAAI,IAAI,EAAQ,KAAK,MAAQ,CAAC,GAAK,EAAI,CAAC,CAAC,CAAC;EACxE,eAAe,EAAa,WAAW,EAAQ;EAC/C,sBAAsB,GAAuC,MAAkB;GAC7E,IAAM,IAAQ,EAAE,cAAc,qBAAqB,OAAO;GAC1D,IAAI,EAAE,YAAY,CAAC,EAAM,IAAI,SAAS;IACpC,IAAM,CAAC,GAAO,KACR,IAAY,IACP,CAAC,GAAW,CAAK,IAEjB,CAAC,IAAQ,GAAG,CAAS;IAGhC,EACE,IAAI,IAAI,EAAO,CAAC,GAAG,GAAc,GAAG,EAAQ,MAAM,GAAO,CAAG,CAAC,CAAC,EAAE,KAAK,MAAS,CAAC,GAAG,EAAI,CAAC,CAAC,CAC1F;GACF,OACE,EAAa,CAAK;EAEtB;CACF;AACF"}
|
package/dist/lib/use-mobile.js
CHANGED
|
@@ -2,13 +2,11 @@ import * as e from "react";
|
|
|
2
2
|
//#region src/lib/use-mobile.ts
|
|
3
3
|
var t = 768;
|
|
4
4
|
function n() {
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return e.addEventListener("change", n), r(window.innerWidth < t), () => e.removeEventListener("change", n);
|
|
11
|
-
}, []), !!n;
|
|
5
|
+
let n = e.useCallback((e) => {
|
|
6
|
+
let n = window.matchMedia(`(max-width: ${t - 1}px)`);
|
|
7
|
+
return n.addEventListener("change", e), () => n.removeEventListener("change", e);
|
|
8
|
+
}, []);
|
|
9
|
+
return e.useSyncExternalStore(n, () => window.matchMedia(`(max-width: ${t - 1}px)`).matches, () => !1);
|
|
12
10
|
}
|
|
13
11
|
//#endregion
|
|
14
12
|
export { n as useIsMobile };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mobile.js","names":[],"sources":["../../src/lib/use-mobile.ts"],"sourcesContent":["import * as React from \"react\";\n\nconst MOBILE_BREAKPOINT = 768;\n\nexport function useIsMobile() {\n const
|
|
1
|
+
{"version":3,"file":"use-mobile.js","names":[],"sources":["../../src/lib/use-mobile.ts"],"sourcesContent":["import * as React from \"react\";\n\nconst MOBILE_BREAKPOINT = 768;\n\nexport function useIsMobile() {\n const subscribe = React.useCallback((onStoreChange: () => void) => {\n const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);\n mql.addEventListener(\"change\", onStoreChange);\n return () => mql.removeEventListener(\"change\", onStoreChange);\n }, []);\n\n return React.useSyncExternalStore(\n subscribe,\n () => window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`).matches,\n () => false,\n );\n}\n"],"mappings":";;AAEA,IAAM,IAAoB;AAE1B,SAAgB,IAAc;CAC5B,IAAM,IAAY,EAAM,aAAa,MAA8B;EACjE,IAAM,IAAM,OAAO,WAAW,eAAe,IAAoB,EAAE,IAAI;EAEvE,OADA,EAAI,iBAAiB,UAAU,CAAa,SAC/B,EAAI,oBAAoB,UAAU,CAAa;CAC9D,GAAG,CAAC,CAAC;CAEL,OAAO,EAAM,qBACX,SACM,OAAO,WAAW,eAAe,IAAoB,EAAE,IAAI,EAAE,eAC7D,EACR;AACF"}
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -13,18 +13,4 @@ export declare function cn(...inputs: ClassValue[]): string;
|
|
|
13
13
|
* normalizeToArray(undefined) // undefined
|
|
14
14
|
*/
|
|
15
15
|
export declare function normalizeToArray<T>(value: T | T[] | undefined): T[] | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* useObjectUrls 훅
|
|
18
|
-
*
|
|
19
|
-
* 로컬 File 객체 배열을 받아서 브라우저 메모리 기반 미리보기용 Object URL을 생성하고,
|
|
20
|
-
* 컴포넌트가 언마운트되거나 파일이 변경될 때 자동으로 메모리를 해제합니다.
|
|
21
|
-
*
|
|
22
|
-
* **동작 방식**:
|
|
23
|
-
* 1. File 배열을 받아서 각 파일마다 `URL.createObjectURL()`로 임시 URL 생성
|
|
24
|
-
* 2. 생성된 URL은 `blob:http://...` 형태로, 브라우저 메모리를 직접 참조
|
|
25
|
-
* 3. 컴포넌트 언마운트나 파일 변경 시 cleanup 함수가 `URL.revokeObjectURL()`로 메모리 해제
|
|
26
|
-
*
|
|
27
|
-
* @param files - 미리보기할 File 객체 배열
|
|
28
|
-
* @returns 생성된 Object URL 문자열 배열
|
|
29
|
-
*/
|
|
30
16
|
export declare function useObjectUrls(files: File[]): string[];
|
package/dist/lib/utils.js
CHANGED
|
@@ -1,23 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { clsx as
|
|
3
|
-
import { twMerge as
|
|
1
|
+
import { useMemo as e, useSyncExternalStore as t } from "react";
|
|
2
|
+
import { clsx as n } from "clsx";
|
|
3
|
+
import { twMerge as r } from "tailwind-merge";
|
|
4
4
|
//#region src/lib/utils.ts
|
|
5
|
-
function
|
|
6
|
-
return
|
|
5
|
+
function i(...e) {
|
|
6
|
+
return r(n(e));
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function a(e) {
|
|
9
9
|
return e === void 0 ? void 0 : Array.isArray(e) ? e : [e];
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
var o = [], s = class {
|
|
12
|
+
files;
|
|
13
|
+
urls = o;
|
|
14
|
+
constructor(e) {
|
|
15
|
+
this.files = e;
|
|
16
|
+
}
|
|
17
|
+
getSnapshot = () => this.urls;
|
|
18
|
+
subscribe = (e) => {
|
|
19
|
+
let t = this.files.map((e) => URL.createObjectURL(e));
|
|
20
|
+
return this.urls = t, e(), () => {
|
|
21
|
+
for (let e of t) URL.revokeObjectURL(e);
|
|
22
|
+
this.urls === t && (this.urls = o);
|
|
17
23
|
};
|
|
18
|
-
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
function c(n) {
|
|
27
|
+
let r = e(() => new s(n), [n]);
|
|
28
|
+
return t(r.subscribe, r.getSnapshot, () => o);
|
|
19
29
|
}
|
|
20
30
|
//#endregion
|
|
21
|
-
export {
|
|
31
|
+
export { i as cn, a as normalizeToArray, c as useObjectUrls };
|
|
22
32
|
|
|
23
33
|
//# sourceMappingURL=utils.js.map
|
package/dist/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../src/lib/utils.ts"],"sourcesContent":["import { clsx } from \"clsx\";\nimport { type ClassValue } from \"clsx\";\nimport {
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../src/lib/utils.ts"],"sourcesContent":["import { clsx } from \"clsx\";\nimport { type ClassValue } from \"clsx\";\nimport { useMemo, useSyncExternalStore } from \"react\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\n/**\n * 값을 배열로 정규화합니다.\n * 이미 배열이면 그대로 반환하고, 단일 값이면 배열로 감싸서 반환합니다.\n *\n * @param value - 정규화할 값 (단일 값 또는 배열)\n * @returns 배열로 정규화된 값 (undefined면 undefined 반환)\n *\n * @example\n * normalizeToArray(50) // [50]\n * normalizeToArray([20, 80]) // [20, 80]\n * normalizeToArray(undefined) // undefined\n */\nexport function normalizeToArray<T>(value: T | T[] | undefined): T[] | undefined {\n return value === undefined ? undefined : Array.isArray(value) ? value : [value];\n}\n\n/**\n * useObjectUrls 훅\n *\n * 로컬 File 객체 배열을 받아서 브라우저 메모리 기반 미리보기용 Object URL을 생성하고,\n * 컴포넌트가 언마운트되거나 파일이 변경될 때 자동으로 메모리를 해제합니다.\n *\n * **동작 방식**:\n * 1. File 배열을 받아서 각 파일마다 `URL.createObjectURL()`로 임시 URL 생성\n * 2. 생성된 URL은 `blob:http://...` 형태로, 브라우저 메모리를 직접 참조\n * 3. 컴포넌트 언마운트나 파일 변경 시 cleanup 함수가 `URL.revokeObjectURL()`로 메모리 해제\n *\n * @param files - 미리보기할 File 객체 배열\n * @returns 생성된 Object URL 문자열 배열\n */\nconst EMPTY_OBJECT_URLS: string[] = [];\n\nclass ObjectUrlStore {\n private urls = EMPTY_OBJECT_URLS;\n\n constructor(private readonly files: File[]) {}\n\n getSnapshot = () => this.urls;\n\n subscribe = (onStoreChange: () => void) => {\n const created = this.files.map((file) => URL.createObjectURL(file));\n this.urls = created;\n onStoreChange();\n\n return () => {\n for (const url of created) {\n URL.revokeObjectURL(url);\n }\n if (this.urls === created) {\n this.urls = EMPTY_OBJECT_URLS;\n }\n };\n };\n}\n\nexport function useObjectUrls(files: File[]): string[] {\n const store = useMemo(() => new ObjectUrlStore(files), [files]);\n\n return useSyncExternalStore(store.subscribe, store.getSnapshot, () => EMPTY_OBJECT_URLS);\n}\n"],"mappings":";;;;AAKA,SAAgB,EAAG,GAAG,GAAsB;CAC1C,OAAO,EAAQ,EAAK,CAAM,CAAC;AAC7B;AAcA,SAAgB,EAAoB,GAA6C;CAC/E,OAAO,MAAU,KAAA,IAAY,KAAA,IAAY,MAAM,QAAQ,CAAK,IAAI,IAAQ,CAAC,CAAK;AAChF;AAgBA,IAAM,IAA8B,CAAC,GAE/B,IAAN,MAAqB;CAGU;CAF7B,OAAe;CAEf,YAAY,GAAgC;EAAf,KAAA,QAAA;CAAgB;CAE7C,oBAAoB,KAAK;CAEzB,aAAa,MAA8B;EACzC,IAAM,IAAU,KAAK,MAAM,KAAK,MAAS,IAAI,gBAAgB,CAAI,CAAC;EAIlE,OAHA,KAAK,OAAO,GACZ,EAAc,SAED;GACX,KAAK,IAAM,KAAO,GAChB,IAAI,gBAAgB,CAAG;GAEzB,AAAI,KAAK,SAAS,MAChB,KAAK,OAAO;EAEhB;CACF;AACF;AAEA,SAAgB,EAAc,GAAyB;CACrD,IAAM,IAAQ,QAAc,IAAI,EAAe,CAAK,GAAG,CAAC,CAAK,CAAC;CAE9D,OAAO,EAAqB,EAAM,WAAW,EAAM,mBAAmB,CAAiB;AACzF"}
|