@musecat/functionkit 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/.agents/references/components/ScrolltoTop.md +36 -0
  2. package/.agents/references/components/SwitchCase.md +47 -0
  3. package/.agents/references/components/ViewportPortal.md +34 -0
  4. package/.agents/references/cookie/cookie.md +47 -0
  5. package/.agents/references/datetime/dateTime.client.md +42 -0
  6. package/.agents/references/datetime/dateTime.server.md +42 -0
  7. package/.agents/references/datetime/dateTime.shared.md +86 -0
  8. package/.agents/references/hooks/useAvoidKeyboard.md +29 -0
  9. package/.agents/references/hooks/useCheckInvisible.md +36 -0
  10. package/.agents/references/hooks/useCheckScroll.md +36 -0
  11. package/.agents/references/hooks/useClientDateTime.md +39 -0
  12. package/.agents/references/hooks/useDebounce.md +46 -0
  13. package/.agents/references/hooks/useDebouncedCallback.md +34 -0
  14. package/.agents/references/hooks/useDoubleClick.md +40 -0
  15. package/.agents/references/hooks/useGeolocation.md +37 -0
  16. package/.agents/references/hooks/useHasMounted.md +27 -0
  17. package/.agents/references/hooks/useIntersectionObserver.md +37 -0
  18. package/.agents/references/hooks/useInterval.md +40 -0
  19. package/.agents/references/hooks/useKeyboardHeight.md +33 -0
  20. package/.agents/references/hooks/useKeyboardListNavigation.md +58 -0
  21. package/.agents/references/hooks/useLongPress.md +48 -0
  22. package/.agents/references/hooks/usePreservedCallback.md +33 -0
  23. package/.agents/references/hooks/usePreservedReference.md +34 -0
  24. package/.agents/references/hooks/useRefEffect.md +35 -0
  25. package/.agents/references/hooks/useRelativeDateTime.md +35 -0
  26. package/.agents/references/hooks/useTimeout.md +42 -0
  27. package/.agents/references/hooks/useToggleState.md +39 -0
  28. package/.agents/references/hooks/useViewportHeight.md +26 -0
  29. package/.agents/references/hooks/useViewportMatch.md +32 -0
  30. package/.agents/references/utils/browserStorage.md +41 -0
  31. package/.agents/references/utils/buildContext.md +47 -0
  32. package/.agents/references/utils/clipboardShare.md +59 -0
  33. package/.agents/references/utils/floatingMotion.md +67 -0
  34. package/.agents/references/utils/getDeviceInfo.md +43 -0
  35. package/.agents/references/utils/isEditableKeyboardTarget.md +35 -0
  36. package/.agents/references/utils/mergeRefs.md +29 -0
  37. package/.agents/references/utils/seen.md +37 -0
  38. package/.agents/references/utils/subscribeKeyboardHeight.md +35 -0
  39. package/AGENTS.md +103 -396
  40. package/README.md +18 -5
  41. package/index.ts +63 -68
  42. package/package.json +27 -13
  43. package/packages/components/ScrolltoTop.tsx +3 -3
  44. package/packages/components/SwitchCase.tsx +7 -7
  45. package/packages/components/ViewportPortal.tsx +23 -23
  46. package/packages/cookie/cookie.shared.ts +97 -101
  47. package/packages/datetime/dateTime.client.ts +86 -86
  48. package/packages/datetime/dateTime.server.ts +86 -86
  49. package/packages/datetime/dateTime.shared.ts +281 -281
  50. package/packages/hooks/useAvoidKeyboard.ts +15 -15
  51. package/packages/hooks/useCheckInvisible.ts +16 -16
  52. package/packages/hooks/useCheckScroll.ts +10 -10
  53. package/packages/hooks/useClientDateTime.ts +33 -33
  54. package/packages/hooks/useDebounce.ts +95 -95
  55. package/packages/hooks/useDebouncedCallback.ts +45 -45
  56. package/packages/hooks/useDoubleClick.ts +43 -43
  57. package/packages/hooks/useGeolocation.ts +130 -130
  58. package/packages/hooks/useHasMounted.ts +5 -5
  59. package/packages/hooks/useIntersectionObserver.ts +20 -20
  60. package/packages/hooks/useInterval.ts +46 -45
  61. package/packages/hooks/useKeyboardHeight.ts +9 -9
  62. package/packages/hooks/useKeyboardListNavigation.ts +156 -156
  63. package/packages/hooks/useLongPress.ts +98 -98
  64. package/packages/hooks/usePreservedCallback.ts +12 -12
  65. package/packages/hooks/usePreservedReference.ts +10 -10
  66. package/packages/hooks/useRefEffect.ts +19 -19
  67. package/packages/hooks/useRelativeDateTime.ts +37 -37
  68. package/packages/hooks/useTimeout.ts +41 -41
  69. package/packages/hooks/useToggleState.ts +5 -5
  70. package/packages/hooks/useViewportHeight.ts +13 -13
  71. package/packages/hooks/useViewportMatch.ts +16 -22
  72. package/packages/utils/browserStorage.ts +26 -26
  73. package/packages/utils/buildContext.tsx +10 -10
  74. package/packages/utils/checkDevice.ts +64 -64
  75. package/packages/utils/clipboardShare.tsx +31 -31
  76. package/packages/utils/clipboardShare.types.ts +7 -7
  77. package/packages/utils/floatingMotion.ts +71 -71
  78. package/packages/utils/keyboardTarget.ts +9 -9
  79. package/packages/utils/mergeRefs.ts +9 -9
  80. package/packages/utils/seen.ts +15 -15
  81. package/packages/utils/subscribeKeyboardHeight.ts +46 -46
  82. package/tests/components/ScrolltoTop.test.tsx +15 -0
  83. package/tests/components/SwitchCase.test.tsx +34 -0
  84. package/tests/components/ViewportPortal.test.tsx +42 -0
  85. package/tests/cookie/cookie.test.ts +156 -0
  86. package/tests/datetime/datetime.test.ts +250 -0
  87. package/tests/hooks/useAvoidKeyboard.test.ts +12 -0
  88. package/tests/hooks/useCheckInvisible.test.ts +28 -0
  89. package/tests/hooks/useCheckScroll.test.ts +23 -0
  90. package/tests/hooks/useClientDateTime.test.ts +14 -0
  91. package/tests/hooks/useDebounce.test.ts +71 -0
  92. package/tests/hooks/useDebouncedCallback.test.ts +34 -0
  93. package/tests/hooks/useDoubleClick.test.ts +31 -0
  94. package/tests/hooks/useGeolocation.test.ts +50 -0
  95. package/tests/hooks/useHasMounted.test.ts +10 -0
  96. package/tests/hooks/useIntersectionObserver.test.ts +13 -0
  97. package/tests/hooks/useInterval.test.ts +31 -0
  98. package/tests/hooks/useKeyboardHeight.test.ts +10 -0
  99. package/tests/hooks/useKeyboardListNavigation.test.ts +82 -0
  100. package/tests/hooks/useLongPress.test.ts +52 -0
  101. package/tests/hooks/usePreservedCallback.test.ts +35 -0
  102. package/tests/hooks/usePreservedReference.test.ts +35 -0
  103. package/tests/hooks/useRefEffect.test.ts +30 -0
  104. package/tests/hooks/useRelativeDateTime.test.ts +19 -0
  105. package/tests/hooks/useTimeout.test.ts +34 -0
  106. package/tests/hooks/useToggleState.test.ts +35 -0
  107. package/tests/hooks/useViewportHeight.test.ts +10 -0
  108. package/tests/hooks/useViewportMatch.test.ts +35 -0
  109. package/tests/setup.ts +9 -0
  110. package/tests/utils/browserStorage.test.ts +54 -0
  111. package/tests/utils/buildContext.test.tsx +27 -0
  112. package/tests/utils/checkDevice.test.ts +84 -0
  113. package/tests/utils/clipboardShare.test.ts +78 -0
  114. package/tests/utils/floatingMotion.test.ts +84 -0
  115. package/tests/utils/keyboardTarget.test.ts +44 -0
  116. package/tests/utils/mergeRefs.test.ts +18 -0
  117. package/tests/utils/seen.test.ts +31 -0
  118. package/tests/utils/subscribeKeyboardHeight.test.ts +50 -0
  119. package/tsconfig.json +16 -16
  120. package/vitest.config.ts +16 -0
@@ -0,0 +1,18 @@
1
+ import { describe, test, expect, vi } from "vitest";
2
+ import { mergeRefs } from "@/packages/utils/mergeRefs";
3
+
4
+ describe("mergeRefs", () => {
5
+ test("merges multiple refs", () => {
6
+ const ref1 = vi.fn();
7
+ const ref2 = { current: null };
8
+ const ref3 = null;
9
+
10
+ const merged = mergeRefs(ref1, ref2, ref3);
11
+ const element = document.createElement("div");
12
+
13
+ merged(element as any);
14
+
15
+ expect(ref1).toHaveBeenCalledWith(element);
16
+ expect(ref2.current).toBe(element);
17
+ });
18
+ });
@@ -0,0 +1,31 @@
1
+ import { describe, test, expect } from "vitest";
2
+ import {
3
+ parseSeen,
4
+ hasSeenKey,
5
+ buildSeenValue,
6
+ SEEN_STORAGE_KEY,
7
+ } from "@/packages/utils/seen";
8
+
9
+ describe("seen", () => {
10
+ test("SEEN_STORAGE_KEY", () => {
11
+ expect(SEEN_STORAGE_KEY).toBe("seen");
12
+ });
13
+
14
+ test("parseSeen", () => {
15
+ expect(parseSeen(null)).toEqual({});
16
+ expect(parseSeen('{"a":true}')).toEqual({ a: true });
17
+ expect(parseSeen("invalid json")).toEqual({});
18
+ expect(parseSeen("[]")).toEqual({});
19
+ });
20
+
21
+ test("hasSeenKey", () => {
22
+ expect(hasSeenKey('{"a":true}', "a")).toBe(true);
23
+ expect(hasSeenKey('{"a":true}', "b")).toBe(false);
24
+ expect(hasSeenKey(null, "a")).toBe(false);
25
+ });
26
+
27
+ test("buildSeenValue", () => {
28
+ const result = buildSeenValue('{"a":true}', "b");
29
+ expect(JSON.parse(result)).toEqual({ a: true, b: true });
30
+ });
31
+ });
@@ -0,0 +1,50 @@
1
+ import { describe, test, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { subscribeKeyboardHeight } from "@/packages/utils/subscribeKeyboardHeight";
3
+
4
+ describe("subscribeKeyboardHeight", () => {
5
+ let visualViewport: any;
6
+
7
+ beforeEach(() => {
8
+ visualViewport = {
9
+ height: 600,
10
+ width: 390,
11
+ offsetTop: 0,
12
+ addEventListener: vi.fn(),
13
+ removeEventListener: vi.fn(),
14
+ };
15
+ Object.defineProperty(window, "visualViewport", {
16
+ value: visualViewport,
17
+ writable: true,
18
+ configurable: true,
19
+ });
20
+ Object.defineProperty(window, "innerHeight", {
21
+ value: 800,
22
+ writable: true,
23
+ configurable: true,
24
+ });
25
+ });
26
+
27
+ afterEach(() => { vi.useRealTimers(); });
28
+
29
+ test("subscribes to resize events", () => {
30
+ const callback = vi.fn();
31
+ subscribeKeyboardHeight({ callback });
32
+ expect(visualViewport.addEventListener).toHaveBeenCalledWith("resize", expect.any(Function));
33
+ expect(visualViewport.addEventListener).toHaveBeenCalledWith("scroll", expect.any(Function));
34
+ });
35
+
36
+ test("calls immediately when immediate is true", () => {
37
+ vi.useFakeTimers();
38
+ const callback = vi.fn();
39
+ subscribeKeyboardHeight({ callback, immediate: true });
40
+ vi.advanceTimersByTime(16);
41
+ expect(callback).toHaveBeenCalled();
42
+ });
43
+
44
+ test("returns unsubscribe function", () => {
45
+ const callback = vi.fn();
46
+ const { unsubscribe } = subscribeKeyboardHeight({ callback });
47
+ unsubscribe();
48
+ expect(visualViewport.removeEventListener).toHaveBeenCalled();
49
+ });
50
+ });
package/tsconfig.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ES2017",
4
- "lib": ["dom", "dom.iterable", "esnext"],
5
- "allowJs": true,
6
- "skipLibCheck": true,
7
- "strict": true,
8
- "noEmit": true,
9
- "esModuleInterop": true,
10
- "module": "esnext",
11
- "moduleResolution": "bundler",
12
- "resolveJsonModule": true,
13
- "isolatedModules": true,
14
- "jsx": "react-jsx",
15
- "incremental": true
16
- },
17
- "include": ["**/*.ts", "**/*.tsx"]
2
+ "compilerOptions": {
3
+ "target": "ES2017",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "esModuleInterop": true,
10
+ "module": "esnext",
11
+ "moduleResolution": "bundler",
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "jsx": "react-jsx",
15
+ "incremental": true
16
+ },
17
+ "include": ["**/*.ts", "**/*.tsx"]
18
18
  }
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from "vitest/config";
2
+ import path from "path";
3
+
4
+ export default defineConfig({
5
+ test: {
6
+ environment: "jsdom",
7
+ setupFiles: ["./tests/setup.ts"],
8
+ include: ["tests/**/*.test.{ts,tsx}"],
9
+ globals: true,
10
+ },
11
+ resolve: {
12
+ alias: {
13
+ "@": path.resolve(__dirname, "./"),
14
+ },
15
+ },
16
+ });