@musecat/functionkit 1.2.1 → 1.3.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.
package/AGENTS.md ADDED
@@ -0,0 +1,128 @@
1
+ # FunctionKit (@musecat/functionkit)
2
+
3
+ React 19 frontend utility library. Single package, ESM.
4
+
5
+ ## Import Convention Enforcement (Mandatory)
6
+
7
+ - **Barrel imports are the rule:** `import { useDebounce } from "@musecat/functionkit"`.
8
+ - **Subpath imports are only allowed when:** the export is not in the barrel (`useCheckInvisible`, `SwitchCase`, `ScrolltoTop`) or tree-shaking is absolutely required.
9
+ - **Type imports also go through the barrel:** `import type { AppLocale, DateInput } from "@musecat/functionkit"`.
10
+ - **No reimplementation:** If FunctionKit already provides a feature, reuse it. Never write a duplicate.
11
+
12
+ ## SSR Safety Classification
13
+
14
+ | Category | Condition | Examples |
15
+ |---|---|---|
16
+ | **SSR-safe** | No `"use client"`, pure function | `formatLongDate`, `mergeRefs`, `SwitchCase`, `getDeviceInfo`, `floatingMotion`, `seen`, `parseClientCookieNames`, `debounce` |
17
+ | **Client-only** | `"use client"` or `window` access | All hooks, `ViewportPortal`, `ScrolltoTop`, `browserStorage`, `cookie` (except `parseClientCookieNames`), `clipboardShare`, `isEditableKeyboardTarget` |
18
+
19
+ SSR-safe functions can be used freely in Server Components, RSC, and Client Components. Client-only items must only be used in `"use client"` components.
20
+
21
+ ## Barrel Export Mapping
22
+
23
+ The barrel (`index.ts`) exports 63 named exports. **Items NOT in the barrel (require subpath imports):**
24
+ - `SwitchCase` — component subpath
25
+ - `ScrolltoTop` — component subpath
26
+ - `useCheckInvisible` — `@musecat/functionkit/hooks/useCheckInvisible`
27
+ - `useCheckScroll` — `@musecat/functionkit/hooks/useCheckScroll`
28
+
29
+ When adding new features, register them in the barrel.
30
+
31
+ ## Hook Selection Guidelines
32
+
33
+ | Scenario | Hook to Use |
34
+ |---|---|
35
+ | Debounce rapid state changes | `useDebounce` or `useDebouncedCallback` |
36
+ | Polling / repeated execution | `useInterval` |
37
+ | Delayed single execution | `useTimeout` |
38
+ | Keyboard list navigation | `useKeyboardListNavigation` |
39
+ | Long press gesture | `useLongPress` |
40
+ | Single/double click distinction | `useDoubleClick` |
41
+ | Geolocation tracking | `useGeolocation` |
42
+ | Client date formatting | `useClientDateTime` |
43
+ | Relative time ("3 minutes ago") | `useRelativeDateTime` |
44
+ | IntersectionObserver | `useIntersectionObserver` |
45
+ | Keyboard avoidance (mobile) | `useAvoidKeyboard` |
46
+ | Viewport height | `useViewportHeight` |
47
+ | Media query matching | `useViewportMatch` |
48
+ | Scroll position detection | `useCheckScroll` (subpath) |
49
+ | Element visibility detection | `useCheckInvisible` (subpath) |
50
+ | Toggle state | `useToggleState` |
51
+ | Hydration guard | `useHasMounted` |
52
+ | Stable callback reference | `usePreservedCallback` |
53
+ | Deep equality reference | `usePreservedReference` |
54
+ | Ref lifecycle | `useRefEffect` |
55
+
56
+ ## Component Selection Guidelines
57
+
58
+ - **SwitchCase** — Prefer over inline &&/ternary for multi-branch rendering. SSR-safe.
59
+ - **ViewportPortal** — Fixed-position overlays, modals, toasts. Client-only.
60
+ - **ScrolltoTop** — Scroll reset on page navigation. Client-only.
61
+
62
+ Never write raw `createContext` + `Provider` + `useContext` boilerplate. Use `buildContext` instead.
63
+
64
+ ## DateTime Formatting Guidelines
65
+
66
+ | Context | Use | SSR-safe |
67
+ |---|---|---|
68
+ | Server static date | `formatServerDate` / `formatServerDateTime` | Yes |
69
+ | Client date | `formatClientDate` / `formatClientDateTime` | No |
70
+ | Relative time ("3분 전") | `formatServerRelative` (server) / `formatClientRelative` (client) | Mixed |
71
+ | Remaining time ("2일 3시간 남음") | `formatRemainingText` | Yes |
72
+ | UTC key ("YYYY-MM-DD") | `formatUtcDateKey` / `parseUtcDateInput` | Yes |
73
+ | Raw formatters | `formatLongDate`, `formatDotDate`, `formatKoreanTime` etc. | Yes |
74
+
75
+ **Locale handling:** `DateInput` accepts `string | number | Date`. Use `normalizeAppLocale("ko")` → `"kr"`, `toIntlLocale("kr")` → `"ko-KR"`.
76
+
77
+ ## Cookie & Storage API Guidelines
78
+
79
+ | Operation | API | SSR-safe |
80
+ |---|---|---|
81
+ | Read cookie | `getClientCookie(name)` | No |
82
+ | Write cookie | `setClientCookie(name, value, days?)` | No |
83
+ | Delete cookie | `clearClientCookie(name)` / `clearAllClientCookies()` | No |
84
+ | Parse cookie names | `parseClientCookieNames(cookieString)` | **Yes** |
85
+ | localStorage | `getLocalStorage` / `updateLocalStorage` / `removeLocalStorage` | No |
86
+ | sessionStorage | `getSessionStorage` / `updateSessionStorage` / `removeSessionStorage` | No |
87
+
88
+ `clearAllClientCookies` tries all domain/path combinations — use with caution.
89
+
90
+ ## Context & Utility Patterns
91
+
92
+ - **`buildContext`:** Creates `createContext` + Provider + `useContext` in one call. `const [useMyCtx, MyProvider] = buildContext<MyType>()`.
93
+ - **`mergeRefs`:** Merges multiple refs into a single callback ref. Use when forwarding refs.
94
+ - **`getDeviceInfo`:** UA-based device detection. Callable at module scope. Returns `isMobile`, `isIOS`, `isAndroid`, etc.
95
+ - **`isEditableKeyboardTarget`:** Checks if a key event target is an editable element. Use before keyboard navigation.
96
+ - **`NavigatorClipboard` / `NavigatorShare`:** Clipboard copy/share with automatic fallback on failure.
97
+ - **`floatingMotion`:** `getFloatingMotionPreset` for tooltip/popover/modal animation configs. 4 modes (anchored, center-selected, modal-center, mobile-sheet).
98
+ - **`seen`:** `hasSeenKey` / `buildSeenValue` for "user has already seen" state management. SSR-safe.
99
+ - **`subscribeKeyboardHeight`:** Low-level keyboard height change detection. Used internally by `useKeyboardHeight`.
100
+
101
+ ## Test Failure Resolution
102
+
103
+ When a test fails, do not blindly patch it to turn green. Reason about intent:
104
+ 1. Understand the hook/component's design contract — what it should do vs. what it actually does.
105
+ 2. If the test correctly captures the intended behavior and the code violates it, fix the code.
106
+ 3. If the code correctly implements the intended behavior and the test reflects outdated assumptions, fix the test.
107
+ 4. If neither is clearly right, treat the source as the source of truth and align the test unless you have explicit user instruction to change the behavior.
108
+
109
+ ## Documentation Maintenance
110
+
111
+ - **Documentation MUST Be Updated Immediately:** Every time you add, modify, or remove a hook, component, util, or any exported API/type, you MUST update the corresponding `.agents/references/` doc in the **same batch of tool calls** — not later, not after tests, not when asked. You must check what changed and update refs before moving to the next task.
112
+ - When the barrel (`index.ts`) export list changes, update the Barrel Export Mapping section above.
113
+ - Before using any feature, read the corresponding `.agents/references/` doc first.
114
+ - If references have drifted from the actual code due to manual changes, analyze the source code and git history to align them.
115
+
116
+ ### Reference File Mapping
117
+
118
+ | Category | File(s) |
119
+ |---|---|
120
+ | Components | `.agents/references/components/SwitchCase.md`, `ScrolltoTop.md`, `ViewportPortal.md` |
121
+ | Hooks | `.agents/references/hooks/usePreservedCallback.md`, `usePreservedReference.md`, `useRefEffect.md`, `useDebounce.md`, `useDebouncedCallback.md`, `useInterval.md`, `useTimeout.md`, `useKeyboardListNavigation.md`, `useLongPress.md`, `useDoubleClick.md`, `useIntersectionObserver.md`, `useCheckInvisible.md`, `useCheckScroll.md`, `useViewportHeight.md`, `useViewportMatch.md`, `useAvoidKeyboard.md`, `useToggleState.md`, `useHasMounted.md`, `useGeolocation.md`, `useKeyboardHeight.md`, `useClientDateTime.md`, `useRelativeDateTime.md` |
122
+ | Cookie | `.agents/references/cookie/cookie.md` |
123
+ | DateTime | `.agents/references/datetime/dateTime.shared.md`, `dateTime.client.md`, `dateTime.server.md` |
124
+ | Utils | `.agents/references/utils/buildContext.md`, `mergeRefs.md`, `floatingMotion.md`, `browserStorage.md`, `getDeviceInfo.md`, `clipboardShare.md`, `isEditableKeyboardTarget.md`, `seen.md`, `subscribeKeyboardHeight.md` |
125
+
126
+ ### usePreservedCallback Trade-off
127
+
128
+ `usePreservedCallback` uses `useRef` + `useEffect` to keep a stable callback reference that always calls the latest version. Because the ref is synced via `useEffect` (after paint), the returned callback may hold a **stale value** during the first render or in the gap between a re-render and the effect flush. In practice this is never an issue — the callback is only invoked in event handlers that fire post-paint. This is the same pattern used by react-hook-form, Radix UI, and others. If synchronous invocation during render is required, use a regular `useCallback` with inline deps instead.
package/CLAUDE.md ADDED
@@ -0,0 +1 @@
1
+ @AGENTS.md
package/README.md CHANGED
@@ -37,6 +37,8 @@ This package includes `.agents/references/` directory with detailed documentatio
37
37
 
38
38
  - [toss/react-simplikit](https://github.com/toss/react-simplikit/)
39
39
 
40
+ Built with [TypeScript](https://www.typescriptlang.org/) and [tsc-alias](https://github.com/Tober68/tsc-alias).
41
+
40
42
  ## License
41
43
 
42
44
  [MIT License](./LICENSE) © Musecat Team.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@musecat/functionkit",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "React 19 + TypeScript frontend utility library — hooks, components, datetime, cookie, and utils",
5
5
  "keywords": [
6
6
  "react",
@@ -17,8 +17,10 @@
17
17
  },
18
18
  "files": [
19
19
  "index.ts",
20
- "packages/",
20
+ "packages",
21
21
  ".agents/",
22
+ "AGENTS.md",
23
+ "CLAUDE.md",
22
24
  "README.md",
23
25
  "LICENSE"
24
26
  ],
@@ -61,5 +63,8 @@
61
63
  "jsdom": "^26.0.0",
62
64
  "prettier": "^3.9.5",
63
65
  "vitest": "^4.1.10"
66
+ },
67
+ "allowScripts": {
68
+ "esbuild@0.27.7": true
64
69
  }
65
70
  }