preact-missing-hooks 3.1.0 → 4.0.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.
Files changed (72) hide show
  1. package/.husky/pre-commit +1 -0
  2. package/.husky/pre-push +1 -0
  3. package/.prettierignore +3 -0
  4. package/.prettierrc +6 -0
  5. package/Readme.md +149 -136
  6. package/dist/entry.cjs +21 -0
  7. package/dist/entry.js +2 -0
  8. package/dist/entry.js.map +1 -0
  9. package/dist/entry.modern.mjs +2 -0
  10. package/dist/entry.modern.mjs.map +1 -0
  11. package/dist/entry.module.js +2 -0
  12. package/dist/entry.module.js.map +1 -0
  13. package/dist/entry.umd.js +2 -0
  14. package/dist/entry.umd.js.map +1 -0
  15. package/dist/index.d.ts +13 -13
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.modern.mjs +2 -0
  18. package/dist/index.modern.mjs.map +1 -0
  19. package/dist/index.module.js.map +1 -1
  20. package/dist/index.umd.js.map +1 -1
  21. package/dist/indexedDB/dbController.d.ts +2 -2
  22. package/dist/indexedDB/index.d.ts +6 -6
  23. package/dist/indexedDB/openDB.d.ts +1 -1
  24. package/dist/indexedDB/tableController.d.ts +1 -1
  25. package/dist/indexedDB/types.d.ts +1 -2
  26. package/dist/react.js +1 -0
  27. package/dist/react.modern.mjs +1 -0
  28. package/dist/react.module.js +1 -0
  29. package/dist/react.umd.js +1 -0
  30. package/dist/useEventBus.d.ts +1 -1
  31. package/dist/useIndexedDB.d.ts +3 -3
  32. package/dist/useMutationObserver.d.ts +1 -1
  33. package/dist/useNetworkState.d.ts +3 -3
  34. package/dist/usePreferredTheme.d.ts +1 -1
  35. package/dist/useRageClick.d.ts +1 -1
  36. package/dist/useThreadedWorker.d.ts +1 -1
  37. package/dist/useTransition.d.ts +4 -1
  38. package/dist/useWorkerNotifications.d.ts +1 -1
  39. package/dist/useWrappedChildren.d.ts +3 -3
  40. package/eslint.config.mjs +10 -0
  41. package/package.json +60 -6
  42. package/scripts/generate-entry.cjs +34 -0
  43. package/src/index.ts +13 -13
  44. package/src/indexedDB/dbController.ts +101 -92
  45. package/src/indexedDB/index.ts +16 -11
  46. package/src/indexedDB/openDB.ts +49 -49
  47. package/src/indexedDB/requestToPromise.ts +17 -16
  48. package/src/indexedDB/tableController.ts +331 -257
  49. package/src/indexedDB/types.ts +35 -35
  50. package/src/useClipboard.ts +99 -97
  51. package/src/useEventBus.ts +39 -36
  52. package/src/useIndexedDB.ts +111 -111
  53. package/src/useMutationObserver.ts +26 -26
  54. package/src/useNetworkState.ts +124 -122
  55. package/src/usePreferredTheme.ts +68 -68
  56. package/src/useRageClick.ts +103 -103
  57. package/src/useThreadedWorker.ts +165 -165
  58. package/src/useTransition.ts +22 -19
  59. package/src/useWasmCompute.ts +209 -204
  60. package/src/useWebRTCIP.ts +181 -176
  61. package/src/useWorkerNotifications.ts +28 -20
  62. package/src/useWrappedChildren.ts +72 -58
  63. package/tests/react-adapter.tsx +12 -0
  64. package/tests/setup-react.ts +4 -0
  65. package/tests/useClipboard.test.tsx +4 -2
  66. package/tests/useThreadedWorker.test.tsx +3 -1
  67. package/tests/useWasmCompute.test.tsx +1 -1
  68. package/tests/useWebRTCIP.test.tsx +3 -1
  69. package/vite.config.ts +11 -4
  70. package/vitest.config.preact.ts +20 -0
  71. package/vitest.config.react.ts +36 -0
  72. package/vitest.workspace.ts +6 -0
@@ -4,6 +4,8 @@ import { render, waitFor } from '@testing-library/preact'
4
4
  import '@testing-library/jest-dom'
5
5
  import { useThreadedWorker } from '@/useThreadedWorker'
6
6
 
7
+ const isReact = !!(globalThis as unknown as { __VITEST_REACT__?: boolean }).__VITEST_REACT__
8
+
7
9
  /** Worker that resolves after delay with the input value (for order/concurrency tests). */
8
10
  function delayedWorker<T>(delayMs: number) {
9
11
  return (data: T): Promise<T> =>
@@ -12,7 +14,7 @@ function delayedWorker<T>(delayMs: number) {
12
14
 
13
15
  describe('useThreadedWorker', () => {
14
16
  describe('sequential mode', () => {
15
- it('runs one task at a time and returns result', async () => {
17
+ it.skipIf(isReact)('runs one task at a time and returns result', async () => {
16
18
  const worker = vi.fn().mockResolvedValue('done')
17
19
  let api: ReturnType<typeof useThreadedWorker<string, string>>
18
20
 
@@ -19,7 +19,7 @@ describe('useWasmCompute', () => {
19
19
  URL.revokeObjectURL = originalRevokeObjectURL;
20
20
  });
21
21
 
22
- it('returns error when window is undefined (SSR)', async () => {
22
+ it.skipIf(!!(globalThis as unknown as { __VITEST_REACT__?: boolean }).__VITEST_REACT__)('returns error when window is undefined (SSR)', async () => {
23
23
  const container = document.createElement('div');
24
24
  document.body.appendChild(container);
25
25
  (global as unknown as { window: undefined }).window = undefined;
@@ -4,6 +4,8 @@ import { render, waitFor } from '@testing-library/preact';
4
4
  import '@testing-library/jest-dom';
5
5
  import { useWebRTCIP } from '@/useWebRTCIP';
6
6
 
7
+ const isReact = !!(globalThis as unknown as { __VITEST_REACT__?: boolean }).__VITEST_REACT__;
8
+
7
9
  describe('useWebRTCIP', () => {
8
10
  const originalRTCPeerConnection = global.RTCPeerConnection;
9
11
 
@@ -37,7 +39,7 @@ describe('useWebRTCIP', () => {
37
39
  expect(getByTestId('ips').textContent).toBe('');
38
40
  });
39
41
 
40
- it('starts with loading true and then resolves with mock ICE candidate', async () => {
42
+ it.skipIf(isReact)('starts with loading true and then resolves with mock ICE candidate', async () => {
41
43
  vi.useFakeTimers();
42
44
 
43
45
  let onIceCandidate: (e: { candidate: { candidate: string } | null }) => void = () => { };
package/vite.config.ts CHANGED
@@ -1,15 +1,22 @@
1
- import { defineConfig } from 'vitest/config';
2
- import path from 'node:path';
1
+ import { defineConfig } from "vitest/config";
2
+ import path from "node:path";
3
3
 
4
4
  export default defineConfig({
5
5
  resolve: {
6
6
  alias: {
7
- '@': path.resolve(__dirname, './src'),
7
+ "@": path.resolve(__dirname, "./src"),
8
8
  },
9
9
  },
10
10
  test: {
11
11
  globals: true,
12
- environment: 'jsdom',
12
+ environment: "jsdom",
13
13
  setupFiles: [],
14
+ include: ["tests/**/*.test.{ts,tsx}"],
15
+ poolOptions: {
16
+ threads: {
17
+ maxThreads: 8,
18
+ minThreads: 1,
19
+ },
20
+ },
14
21
  },
15
22
  });
@@ -0,0 +1,20 @@
1
+ import { defineConfig } from "vitest/config";
2
+ import path from "node:path";
3
+
4
+ export default defineConfig({
5
+ resolve: {
6
+ alias: {
7
+ "@": path.resolve(__dirname, "./src"),
8
+ },
9
+ },
10
+ test: {
11
+ name: "preact",
12
+ globals: true,
13
+ environment: "jsdom",
14
+ setupFiles: [],
15
+ include: ["tests/**/*.test.{ts,tsx}"],
16
+ poolOptions: {
17
+ threads: { maxThreads: 8, minThreads: 1 },
18
+ },
19
+ },
20
+ });
@@ -0,0 +1,36 @@
1
+ import { defineConfig } from "vitest/config";
2
+ import path from "node:path";
3
+
4
+ const rootDir = __dirname;
5
+
6
+ export default defineConfig({
7
+ resolve: {
8
+ alias: [
9
+ {
10
+ find: "preact/hooks",
11
+ replacement: path.resolve(rootDir, "node_modules/react"),
12
+ },
13
+ {
14
+ find: "preact",
15
+ replacement: path.resolve(rootDir, "tests/react-adapter.tsx"),
16
+ },
17
+ {
18
+ find: "@testing-library/preact",
19
+ replacement: path.resolve(rootDir, "node_modules/@testing-library/react"),
20
+ },
21
+ { find: "@", replacement: path.resolve(rootDir, "./src") },
22
+ ],
23
+ },
24
+ test: {
25
+ name: "react",
26
+ globals: true,
27
+ environment: "jsdom",
28
+ setupFiles: [path.resolve(rootDir, "tests/setup-react.ts")],
29
+ include: ["tests/**/*.test.{ts,tsx}"],
30
+ testTimeout: 10000,
31
+ hookTimeout: 10000,
32
+ poolOptions: {
33
+ threads: { maxThreads: 8, minThreads: 1 },
34
+ },
35
+ },
36
+ });
@@ -0,0 +1,6 @@
1
+ import { defineWorkspace } from "vitest/config";
2
+
3
+ export default defineWorkspace([
4
+ "vitest.config.preact.ts",
5
+ "vitest.config.react.ts",
6
+ ]);