preact-missing-hooks 3.1.0 → 4.1.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 (82) 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 +333 -137
  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 +14 -13
  16. package/dist/index.js +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.modern.mjs +2 -0
  19. package/dist/index.modern.mjs.map +1 -0
  20. package/dist/index.module.js +1 -1
  21. package/dist/index.module.js.map +1 -1
  22. package/dist/index.umd.js +1 -1
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/indexedDB/dbController.d.ts +2 -2
  25. package/dist/indexedDB/index.d.ts +6 -6
  26. package/dist/indexedDB/openDB.d.ts +1 -1
  27. package/dist/indexedDB/tableController.d.ts +1 -1
  28. package/dist/indexedDB/types.d.ts +1 -2
  29. package/dist/react.js +1 -0
  30. package/dist/react.modern.mjs +1 -0
  31. package/dist/react.module.js +1 -0
  32. package/dist/react.umd.js +1 -0
  33. package/dist/useEventBus.d.ts +1 -1
  34. package/dist/useIndexedDB.d.ts +3 -3
  35. package/dist/useLLMMetadata.d.ts +71 -0
  36. package/dist/useMutationObserver.d.ts +1 -1
  37. package/dist/useNetworkState.d.ts +3 -3
  38. package/dist/usePreferredTheme.d.ts +1 -1
  39. package/dist/useRageClick.d.ts +1 -1
  40. package/dist/useThreadedWorker.d.ts +1 -1
  41. package/dist/useTransition.d.ts +4 -1
  42. package/dist/useWorkerNotifications.d.ts +1 -1
  43. package/dist/useWrappedChildren.d.ts +3 -3
  44. package/docs/README.md +111 -0
  45. package/docs/index.html +58 -20
  46. package/docs/main.js +49 -0
  47. package/eslint.config.mjs +10 -0
  48. package/package.json +60 -6
  49. package/scripts/generate-entry.cjs +34 -0
  50. package/src/index.ts +14 -13
  51. package/src/indexedDB/dbController.ts +101 -92
  52. package/src/indexedDB/index.ts +16 -11
  53. package/src/indexedDB/openDB.ts +49 -49
  54. package/src/indexedDB/requestToPromise.ts +17 -16
  55. package/src/indexedDB/tableController.ts +331 -257
  56. package/src/indexedDB/types.ts +35 -35
  57. package/src/useClipboard.ts +99 -97
  58. package/src/useEventBus.ts +39 -36
  59. package/src/useIndexedDB.ts +111 -111
  60. package/src/useLLMMetadata.ts +418 -0
  61. package/src/useMutationObserver.ts +26 -26
  62. package/src/useNetworkState.ts +124 -122
  63. package/src/usePreferredTheme.ts +68 -68
  64. package/src/useRageClick.ts +103 -103
  65. package/src/useThreadedWorker.ts +165 -165
  66. package/src/useTransition.ts +22 -19
  67. package/src/useWasmCompute.ts +209 -204
  68. package/src/useWebRTCIP.ts +181 -176
  69. package/src/useWorkerNotifications.ts +28 -20
  70. package/src/useWrappedChildren.ts +72 -58
  71. package/tests/preact-as-react.ts +5 -0
  72. package/tests/react-adapter.tsx +12 -0
  73. package/tests/setup-react.ts +4 -0
  74. package/tests/useClipboard.test.tsx +4 -2
  75. package/tests/useLLMMetadata.test.tsx +149 -0
  76. package/tests/useThreadedWorker.test.tsx +3 -1
  77. package/tests/useWasmCompute.test.tsx +1 -1
  78. package/tests/useWebRTCIP.test.tsx +3 -1
  79. package/vite.config.ts +11 -4
  80. package/vitest.config.preact.ts +21 -0
  81. package/vitest.config.react.ts +36 -0
  82. package/vitest.workspace.ts +6 -0
@@ -1,49 +1,49 @@
1
- /**
2
- * Opens IndexedDB and runs onupgradeneeded to create stores and indexes.
3
- * Singleton per (name, version).
4
- * @module indexedDB/openDB
5
- */
6
-
7
- import type { IndexedDBConfig, TableSchema } from './types';
8
- import { requestToPromise } from './requestToPromise';
9
-
10
- const connectionCache = new Map<string, Promise<IDBDatabase>>();
11
-
12
- /**
13
- * Opens the database and creates/upgrades object stores and indexes from config.
14
- * Uses a singleton cache per (name, version); repeated calls with the same config reuse the same connection.
15
- */
16
- export function openDB(config: IndexedDBConfig): Promise<IDBDatabase> {
17
- const key = `${config.name}_v${config.version}`;
18
- let promise = connectionCache.get(key);
19
- if (promise) return promise;
20
- promise = _openDB(config);
21
- connectionCache.set(key, promise);
22
- return promise;
23
- }
24
-
25
- function _openDB(config: IndexedDBConfig): Promise<IDBDatabase> {
26
- return new Promise<IDBDatabase>((resolve, reject) => {
27
- const request = indexedDB.open(config.name, config.version);
28
- request.onerror = () => reject(request.error ?? new DOMException('Failed to open database'));
29
- request.onsuccess = () => resolve(request.result);
30
- request.onupgradeneeded = (event: IDBVersionChangeEvent) => {
31
- const db = (event.target as IDBOpenDBRequest).result;
32
- const tables = config.tables;
33
- for (const tableName of Object.keys(tables)) {
34
- const schema = tables[tableName] as TableSchema;
35
- if (!db.objectStoreNames.contains(tableName)) {
36
- const store = db.createObjectStore(tableName, {
37
- keyPath: schema.keyPath,
38
- autoIncrement: schema.autoIncrement ?? false,
39
- });
40
- if (schema.indexes) {
41
- for (const indexName of schema.indexes) {
42
- store.createIndex(indexName, indexName, { unique: false });
43
- }
44
- }
45
- }
46
- }
47
- };
48
- });
49
- }
1
+ /**
2
+ * Opens IndexedDB and runs onupgradeneeded to create stores and indexes.
3
+ * Singleton per (name, version).
4
+ * @module indexedDB/openDB
5
+ */
6
+
7
+ import type { IndexedDBConfig, TableSchema } from "./types";
8
+
9
+ const connectionCache = new Map<string, Promise<IDBDatabase>>();
10
+
11
+ /**
12
+ * Opens the database and creates/upgrades object stores and indexes from config.
13
+ * Uses a singleton cache per (name, version); repeated calls with the same config reuse the same connection.
14
+ */
15
+ export function openDB(config: IndexedDBConfig): Promise<IDBDatabase> {
16
+ const key = `${config.name}_v${config.version}`;
17
+ let promise = connectionCache.get(key);
18
+ if (promise) return promise;
19
+ promise = _openDB(config);
20
+ connectionCache.set(key, promise);
21
+ return promise;
22
+ }
23
+
24
+ function _openDB(config: IndexedDBConfig): Promise<IDBDatabase> {
25
+ return new Promise<IDBDatabase>((resolve, reject) => {
26
+ const request = indexedDB.open(config.name, config.version);
27
+ request.onerror = () =>
28
+ reject(request.error ?? new DOMException("Failed to open database"));
29
+ request.onsuccess = () => resolve(request.result);
30
+ request.onupgradeneeded = (event: IDBVersionChangeEvent) => {
31
+ const db = (event.target as IDBOpenDBRequest).result;
32
+ const tables = config.tables;
33
+ for (const tableName of Object.keys(tables)) {
34
+ const schema = tables[tableName] as TableSchema;
35
+ if (!db.objectStoreNames.contains(tableName)) {
36
+ const store = db.createObjectStore(tableName, {
37
+ keyPath: schema.keyPath,
38
+ autoIncrement: schema.autoIncrement ?? false,
39
+ });
40
+ if (schema.indexes) {
41
+ for (const indexName of schema.indexes) {
42
+ store.createIndex(indexName, indexName, { unique: false });
43
+ }
44
+ }
45
+ }
46
+ }
47
+ };
48
+ });
49
+ }
@@ -1,16 +1,17 @@
1
- /**
2
- * Wraps an IDBRequest in a Promise.
3
- * @module indexedDB/requestToPromise
4
- */
5
-
6
- /**
7
- * Converts an IDBRequest to a Promise. Rejects with the request's error on failure.
8
- * @param request - Native IndexedDB request.
9
- * @returns Promise that resolves with the request result or rejects with DOMException.
10
- */
11
- export function requestToPromise<T>(request: IDBRequest<T>): Promise<T> {
12
- return new Promise<T>((resolve, reject) => {
13
- request.onsuccess = () => resolve(request.result);
14
- request.onerror = () => reject(request.error ?? new DOMException('Unknown IndexedDB error'));
15
- });
16
- }
1
+ /**
2
+ * Wraps an IDBRequest in a Promise.
3
+ * @module indexedDB/requestToPromise
4
+ */
5
+
6
+ /**
7
+ * Converts an IDBRequest to a Promise. Rejects with the request's error on failure.
8
+ * @param request - Native IndexedDB request.
9
+ * @returns Promise that resolves with the request result or rejects with DOMException.
10
+ */
11
+ export function requestToPromise<T>(request: IDBRequest<T>): Promise<T> {
12
+ return new Promise<T>((resolve, reject) => {
13
+ request.onsuccess = () => resolve(request.result);
14
+ request.onerror = () =>
15
+ reject(request.error ?? new DOMException("Unknown IndexedDB error"));
16
+ });
17
+ }