@indietabletop/appkit 6.1.6 → 7.0.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 (269) hide show
  1. package/dist/AppConfig/AppConfig.d.ts +29 -0
  2. package/dist/AuthCard/AuthCard.d.ts +10 -0
  3. package/dist/AuthCard/AuthCard.stories.d.ts +34 -0
  4. package/dist/AuthCard/style.css.d.ts +23 -0
  5. package/dist/DialogTrigger/index.d.ts +13 -0
  6. package/dist/DocumentTitle/DocumentTitle.d.ts +3 -0
  7. package/dist/EnumMapper.d.ts +25 -0
  8. package/dist/ExternalLink.d.ts +3 -0
  9. package/dist/FullscreenDismissBlocker.d.ts +5 -0
  10. package/{lib/HistoryState.ts → dist/HistoryState.d.ts} +2 -5
  11. package/dist/IndieTabletopClubLogo.d.ts +7 -0
  12. package/dist/IndieTabletopClubSymbol.d.ts +7 -0
  13. package/dist/InfoPage/index.d.ts +8 -0
  14. package/dist/InfoPage/pages.d.ts +2 -0
  15. package/dist/InfoPage/style.css.d.ts +5 -0
  16. package/dist/Letterhead/index.d.ts +19 -0
  17. package/dist/Letterhead/stories.d.ts +13 -0
  18. package/dist/Letterhead/style.css.d.ts +46 -0
  19. package/dist/LetterheadForm/LetterheadReadonlyTextField.stories.d.ts +17 -0
  20. package/dist/LetterheadForm/LetterheadSubmitError.stories.d.ts +11 -0
  21. package/dist/LetterheadForm/LetterheadTextField.stories.d.ts +336 -0
  22. package/dist/LetterheadForm/index.d.ts +44 -0
  23. package/dist/LetterheadForm/style.css.d.ts +8 -0
  24. package/dist/LoadingIndicator.d.ts +3 -0
  25. package/dist/MiddotSeparated/MiddotSeparated.d.ts +8 -0
  26. package/dist/MiddotSeparated/MiddotSeparated.stories.d.ts +586 -0
  27. package/dist/MiddotSeparated/style.css.d.ts +1 -0
  28. package/dist/ModalDialog/index.d.ts +12 -0
  29. package/dist/ModalDialog/style.css.d.ts +58 -0
  30. package/dist/ModernIDB/Cursor.d.ts +56 -0
  31. package/dist/ModernIDB/ModernIDB.d.ts +66 -0
  32. package/dist/ModernIDB/ModernIDBError.d.ts +3 -0
  33. package/dist/ModernIDB/ObjectStore.d.ts +112 -0
  34. package/dist/ModernIDB/ObjectStoreIndex.d.ts +53 -0
  35. package/dist/ModernIDB/Transaction.d.ts +16 -0
  36. package/dist/ModernIDB/VersionChangeManager.d.ts +30 -0
  37. package/dist/ModernIDB/bindings/factory.d.ts +12 -0
  38. package/dist/ModernIDB/bindings/index.d.ts +2 -0
  39. package/{lib/ModernIDB/bindings/types.ts → dist/ModernIDB/bindings/types.d.ts} +13 -32
  40. package/dist/ModernIDB/bindings/utils.d.ts +2 -0
  41. package/dist/ModernIDB/index.d.ts +10 -0
  42. package/dist/ModernIDB/types.d.ts +88 -0
  43. package/dist/ModernIDB/utils.d.ts +4 -0
  44. package/dist/QRCode/QRCode.d.ts +7 -0
  45. package/dist/QRCode/QRCode.stories.d.ts +33 -0
  46. package/dist/QRCode/style.css.d.ts +4 -0
  47. package/dist/ReleaseInfo/index.d.ts +5 -0
  48. package/dist/RulesetResolver.d.ts +87 -0
  49. package/dist/SafariCheck/SafariCheck.d.ts +23 -0
  50. package/dist/SafariCheck/SafariCheck.stories.d.ts +73 -0
  51. package/dist/SafariCheck/style.css.d.ts +17 -0
  52. package/dist/ServiceWorkerHandler.d.ts +11 -0
  53. package/dist/ShareButton/ShareButton.d.ts +57 -0
  54. package/dist/ShareButton/ShareButton.stories.d.ts +1577 -0
  55. package/dist/ShareButton/test.css.d.ts +1 -0
  56. package/dist/SubscribeCard/LetterheadInfoCard.d.ts +2 -0
  57. package/dist/SubscribeCard/SubscribeByEmailCard.d.ts +24 -0
  58. package/dist/SubscribeCard/SubscribeByEmailCard.stories.d.ts +10 -0
  59. package/dist/SubscribeCard/SubscribeByPledgeCard.d.ts +36 -0
  60. package/dist/SubscribeCard/SubscribeByPledgeCard.stories.d.ts +65 -0
  61. package/dist/SubscribeCard/style.css.d.ts +4 -0
  62. package/dist/account/AccountIssueView.d.ts +3 -0
  63. package/dist/account/AlreadyLoggedInView.d.ts +5 -0
  64. package/dist/account/CurrentUserFetcher.d.ts +20 -0
  65. package/dist/account/CurrentUserFetcher.stories.d.ts +136 -0
  66. package/dist/account/FailureFallbackView.d.ts +1 -0
  67. package/dist/account/JoinCard.d.ts +14 -0
  68. package/dist/account/JoinCard.stories.d.ts +143 -0
  69. package/dist/account/LoadingView.d.ts +1 -0
  70. package/dist/account/LoginCard.d.ts +39 -0
  71. package/dist/account/LoginCard.stories.d.ts +217 -0
  72. package/dist/account/LoginView.d.ts +10 -0
  73. package/dist/account/NoConnectionView.d.ts +4 -0
  74. package/dist/account/PasswordResetCard.d.ts +15 -0
  75. package/dist/account/PasswordResetCard.stories.d.ts +128 -0
  76. package/dist/account/UserMismatchView.d.ts +6 -0
  77. package/dist/account/VerifyPage.d.ts +13 -0
  78. package/dist/account/style.css.d.ts +10 -0
  79. package/{lib/account/types.ts → dist/account/types.d.ts} +3 -6
  80. package/dist/account/useFetchCurrentUser.d.ts +28 -0
  81. package/dist/account/useRedirectPath.d.ts +6 -0
  82. package/dist/animations.css.d.ts +3 -0
  83. package/dist/append-copy-to-text.d.ts +10 -0
  84. package/dist/append-copy-to-text.test.d.ts +1 -0
  85. package/dist/appkit.css +1 -0
  86. package/dist/appkit.js +10692 -0
  87. package/dist/async-op.d.ts +101 -0
  88. package/dist/atomic.css.d.ts +6 -0
  89. package/{lib/caught-value.ts → dist/caught-value.d.ts} +1 -11
  90. package/{lib/class-names.ts → dist/class-names.d.ts} +6 -17
  91. package/dist/client.d.ts +424 -0
  92. package/dist/common.css.d.ts +5 -0
  93. package/dist/copyrightRange.d.ts +1 -0
  94. package/dist/copyrightRange.test.d.ts +1 -0
  95. package/dist/createSafeStorage.d.ts +34 -0
  96. package/dist/failureMessages.d.ts +20 -0
  97. package/dist/failureMessages.test.d.ts +1 -0
  98. package/dist/form/FormSubmitButton.d.ts +17 -0
  99. package/dist/form/SubmitErrorAlert.d.ts +5 -0
  100. package/dist/form/style.css.d.ts +3 -0
  101. package/dist/globals.css.d.ts +0 -0
  102. package/dist/groupBy.d.ts +1 -0
  103. package/dist/groupBy.test.d.ts +1 -0
  104. package/dist/hrefs.d.ts +32 -0
  105. package/dist/hrefs.test.d.ts +1 -0
  106. package/dist/idToDate.d.ts +5 -0
  107. package/dist/idToDate.test.d.ts +1 -0
  108. package/dist/ids.d.ts +1 -0
  109. package/dist/ids.test.d.ts +1 -0
  110. package/dist/index.d.ts +64 -0
  111. package/dist/internal.css.d.ts +2 -0
  112. package/dist/mailto.d.ts +8 -0
  113. package/dist/mailto.test.d.ts +1 -0
  114. package/dist/media.d.ts +39 -0
  115. package/dist/random.d.ts +3 -0
  116. package/dist/result/swr.d.ts +4 -0
  117. package/{lib/sleep.ts → dist/sleep.d.ts} +1 -3
  118. package/dist/store/index.d.ts +237 -0
  119. package/dist/store/store.d.ts +144 -0
  120. package/dist/store/types.d.ts +49 -0
  121. package/dist/store/utils.d.ts +10 -0
  122. package/dist/storybook/decorators.d.ts +3 -0
  123. package/dist/structs.d.ts +1 -0
  124. package/{lib/typeguards.ts → dist/typeguards.d.ts} +1 -3
  125. package/dist/typeguards.test.d.ts +1 -0
  126. package/{lib/types.ts → dist/types.d.ts} +12 -23
  127. package/dist/unique.d.ts +10 -0
  128. package/dist/unique.test.d.ts +1 -0
  129. package/dist/use-async-op.d.ts +6 -0
  130. package/dist/use-document-background-color.d.ts +4 -0
  131. package/dist/use-form.d.ts +29 -0
  132. package/dist/use-is-installed.d.ts +8 -0
  133. package/dist/use-media-query.d.ts +1 -0
  134. package/dist/use-reverting-state.d.ts +5 -0
  135. package/dist/use-scroll-restoration.d.ts +25 -0
  136. package/dist/useEnsureValue.d.ts +6 -0
  137. package/dist/useInvokeClient.d.ts +25 -0
  138. package/dist/useIsVisible.d.ts +4 -0
  139. package/dist/utm.d.ts +58 -0
  140. package/dist/utm.test.d.ts +1 -0
  141. package/dist/validations.d.ts +3 -0
  142. package/dist/vars.css.d.ts +10 -0
  143. package/package.json +12 -5
  144. package/lib/AppConfig/AppConfig.tsx +0 -61
  145. package/lib/AuthCard/AuthCard.stories.ts +0 -34
  146. package/lib/AuthCard/AuthCard.tsx +0 -64
  147. package/lib/AuthCard/style.css.ts +0 -49
  148. package/lib/DialogTrigger/index.tsx +0 -36
  149. package/lib/DocumentTitle/DocumentTitle.tsx +0 -10
  150. package/lib/EnumMapper.ts +0 -50
  151. package/lib/ExternalLink.tsx +0 -10
  152. package/lib/FullscreenDismissBlocker.tsx +0 -23
  153. package/lib/IndieTabletopClubLogo.tsx +0 -44
  154. package/lib/IndieTabletopClubSymbol.tsx +0 -37
  155. package/lib/InfoPage/index.tsx +0 -46
  156. package/lib/InfoPage/pages.tsx +0 -36
  157. package/lib/InfoPage/style.css.ts +0 -36
  158. package/lib/Letterhead/index.tsx +0 -85
  159. package/lib/Letterhead/stories.tsx +0 -41
  160. package/lib/Letterhead/style.css.ts +0 -152
  161. package/lib/LetterheadForm/LetterheadReadonlyTextField.stories.tsx +0 -17
  162. package/lib/LetterheadForm/LetterheadSubmitError.stories.tsx +0 -19
  163. package/lib/LetterheadForm/LetterheadTextField.stories.tsx +0 -19
  164. package/lib/LetterheadForm/index.tsx +0 -137
  165. package/lib/LetterheadForm/style.css.ts +0 -89
  166. package/lib/LoadingIndicator.tsx +0 -40
  167. package/lib/MiddotSeparated/MiddotSeparated.stories.ts +0 -26
  168. package/lib/MiddotSeparated/MiddotSeparated.tsx +0 -26
  169. package/lib/MiddotSeparated/style.css.ts +0 -10
  170. package/lib/ModalDialog/index.tsx +0 -28
  171. package/lib/ModalDialog/style.css.ts +0 -88
  172. package/lib/ModernIDB/Cursor.ts +0 -91
  173. package/lib/ModernIDB/ModernIDB.ts +0 -337
  174. package/lib/ModernIDB/ModernIDBError.ts +0 -9
  175. package/lib/ModernIDB/ObjectStore.ts +0 -195
  176. package/lib/ModernIDB/ObjectStoreIndex.ts +0 -102
  177. package/lib/ModernIDB/README.md +0 -9
  178. package/lib/ModernIDB/Transaction.ts +0 -40
  179. package/lib/ModernIDB/VersionChangeManager.ts +0 -57
  180. package/lib/ModernIDB/bindings/factory.tsx +0 -165
  181. package/lib/ModernIDB/bindings/index.ts +0 -2
  182. package/lib/ModernIDB/bindings/utils.tsx +0 -32
  183. package/lib/ModernIDB/index.ts +0 -10
  184. package/lib/ModernIDB/types.ts +0 -120
  185. package/lib/ModernIDB/utils.ts +0 -51
  186. package/lib/QRCode/QRCode.stories.tsx +0 -41
  187. package/lib/QRCode/QRCode.tsx +0 -54
  188. package/lib/QRCode/style.css.ts +0 -23
  189. package/lib/ReleaseInfo/index.tsx +0 -29
  190. package/lib/RulesetResolver.ts +0 -214
  191. package/lib/SafariCheck/SafariCheck.stories.tsx +0 -99
  192. package/lib/SafariCheck/SafariCheck.tsx +0 -273
  193. package/lib/SafariCheck/addToDock.svg +0 -13
  194. package/lib/SafariCheck/addToHomeScreen.svg +0 -12
  195. package/lib/SafariCheck/safari.svg +0 -32
  196. package/lib/SafariCheck/shareIcon.svg +0 -11
  197. package/lib/SafariCheck/style.css.ts +0 -106
  198. package/lib/ServiceWorkerHandler.tsx +0 -53
  199. package/lib/ShareButton/ShareButton.stories.tsx +0 -58
  200. package/lib/ShareButton/ShareButton.tsx +0 -153
  201. package/lib/ShareButton/test.css.ts +0 -3
  202. package/lib/SubscribeCard/LetterheadInfoCard.tsx +0 -23
  203. package/lib/SubscribeCard/SubscribeByEmailCard.stories.tsx +0 -69
  204. package/lib/SubscribeCard/SubscribeByEmailCard.tsx +0 -183
  205. package/lib/SubscribeCard/SubscribeByPledgeCard.stories.tsx +0 -133
  206. package/lib/SubscribeCard/SubscribeByPledgeCard.tsx +0 -127
  207. package/lib/SubscribeCard/style.css.ts +0 -14
  208. package/lib/account/AccountIssueView.tsx +0 -44
  209. package/lib/account/AlreadyLoggedInView.tsx +0 -47
  210. package/lib/account/CurrentUserFetcher.stories.tsx +0 -292
  211. package/lib/account/CurrentUserFetcher.tsx +0 -118
  212. package/lib/account/FailureFallbackView.tsx +0 -36
  213. package/lib/account/JoinCard.stories.tsx +0 -257
  214. package/lib/account/JoinCard.tsx +0 -301
  215. package/lib/account/LoadingView.tsx +0 -14
  216. package/lib/account/LoginCard.stories.tsx +0 -288
  217. package/lib/account/LoginCard.tsx +0 -100
  218. package/lib/account/LoginView.tsx +0 -151
  219. package/lib/account/NoConnectionView.tsx +0 -34
  220. package/lib/account/PasswordResetCard.stories.tsx +0 -242
  221. package/lib/account/PasswordResetCard.tsx +0 -296
  222. package/lib/account/UserMismatchView.tsx +0 -62
  223. package/lib/account/VerifyPage.tsx +0 -195
  224. package/lib/account/style.css.ts +0 -57
  225. package/lib/account/useFetchCurrentUser.tsx +0 -63
  226. package/lib/account/useRedirectPath.ts +0 -21
  227. package/lib/animations.css.ts +0 -17
  228. package/lib/append-copy-to-text.ts +0 -35
  229. package/lib/async-op.ts +0 -286
  230. package/lib/atomic.css.ts +0 -11
  231. package/lib/client.ts +0 -662
  232. package/lib/common.css.ts +0 -48
  233. package/lib/copyrightRange.ts +0 -10
  234. package/lib/createSafeStorage.ts +0 -91
  235. package/lib/failureMessages.ts +0 -108
  236. package/lib/form/FormSubmitButton.tsx +0 -58
  237. package/lib/form/SubmitErrorAlert.tsx +0 -21
  238. package/lib/form/style.css.ts +0 -9
  239. package/lib/globals.css.ts +0 -62
  240. package/lib/groupBy.ts +0 -25
  241. package/lib/hrefs.ts +0 -48
  242. package/lib/idToDate.ts +0 -8
  243. package/lib/ids.ts +0 -6
  244. package/lib/index.ts +0 -71
  245. package/lib/internal.css.ts +0 -10
  246. package/lib/mailto.ts +0 -40
  247. package/lib/media.ts +0 -50
  248. package/lib/random.ts +0 -19
  249. package/lib/result/swr.ts +0 -18
  250. package/lib/store/index.tsx +0 -241
  251. package/lib/store/store.ts +0 -479
  252. package/lib/store/types.ts +0 -45
  253. package/lib/store/utils.ts +0 -54
  254. package/lib/storybook/decorators.tsx +0 -10
  255. package/lib/structs.ts +0 -3
  256. package/lib/unique.ts +0 -24
  257. package/lib/use-async-op.ts +0 -16
  258. package/lib/use-document-background-color.ts +0 -16
  259. package/lib/use-form.ts +0 -78
  260. package/lib/use-is-installed.ts +0 -17
  261. package/lib/use-media-query.ts +0 -21
  262. package/lib/use-reverting-state.ts +0 -32
  263. package/lib/use-scroll-restoration.ts +0 -99
  264. package/lib/useEnsureValue.ts +0 -31
  265. package/lib/useInvokeClient.ts +0 -54
  266. package/lib/useIsVisible.ts +0 -27
  267. package/lib/utm.ts +0 -92
  268. package/lib/validations.ts +0 -25
  269. package/lib/vars.css.ts +0 -13
@@ -1,57 +0,0 @@
1
- import { VersionChangeObjectStore } from "./ObjectStore.ts";
2
- import { VersionChangeTransaction } from "./Transaction.ts";
3
- import type { KeyPath, ModernIDBSchema } from "./types.ts";
4
-
5
- export class VersionChangeManager<
6
- Schema extends ModernIDBSchema,
7
- IndexNames extends {
8
- [K in keyof Schema]?: string;
9
- } = never,
10
- > {
11
- readonly idbDatabase: IDBDatabase;
12
- readonly event: IDBVersionChangeEvent;
13
- readonly transaction: VersionChangeTransaction<Schema, IndexNames>;
14
-
15
- constructor(props: {
16
- idbDatabase: IDBDatabase;
17
- event: IDBVersionChangeEvent;
18
- idbTransaction: IDBTransaction;
19
- }) {
20
- this.idbDatabase = props.idbDatabase;
21
- this.event = props.event;
22
- this.transaction = new VersionChangeTransaction({
23
- transaction: props.idbTransaction,
24
- });
25
- }
26
-
27
- /**
28
- * Creates a new object store with the given name and options and returns a new IDBObjectStore.
29
- *
30
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBDatabase/createObjectStore)
31
- */
32
- createObjectStore<StoreName extends string & keyof Schema>(
33
- name: StoreName,
34
- options?: {
35
- autoIncrement?: boolean;
36
- keyPath?:
37
- | KeyPath<Schema[StoreName]>
38
- | KeyPath<Schema[StoreName]>[]
39
- | null;
40
- },
41
- ) {
42
- const objectStore = this.idbDatabase.createObjectStore(name, options);
43
- return new VersionChangeObjectStore<
44
- Schema[StoreName],
45
- IndexNames[StoreName] extends string ? IndexNames[StoreName] : never
46
- >(objectStore);
47
- }
48
-
49
- /**
50
- * Deletes the object store with the given name.
51
- *
52
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/IDBDatabase/deleteObjectStore)
53
- */
54
- deleteObjectStore(name: string): void {
55
- this.idbDatabase.deleteObjectStore(name);
56
- }
57
- }
@@ -1,165 +0,0 @@
1
- import {
2
- createContext,
3
- useContext,
4
- useEffect,
5
- useState,
6
- type ReactNode,
7
- } from "react";
8
- import { Failure, isAsyncOp, Pending, Success } from "../../async-op.ts";
9
- import { caughtValueToString } from "../../caught-value.ts";
10
- import { useAsyncOp } from "../../use-async-op.ts";
11
- import type { AnyModernIDB } from "../types.ts";
12
- import type {
13
- DatabaseOpenRequestOp,
14
- FlattenSuccessOps,
15
- InaccessibleDatabaseError,
16
- QueryOp,
17
- } from "./types.ts";
18
- import { toKnownError } from "./utils.tsx";
19
-
20
- export function createDatabaseBindings<T extends AnyModernIDB>(db: T) {
21
- const DatabaseContext = createContext(db);
22
-
23
- const DatabaseOpenRequest = createContext<DatabaseOpenRequestOp<T>>(
24
- new Pending(),
25
- );
26
-
27
- const cache = new Map<string, unknown>();
28
-
29
- /**
30
- * Performs an IndexedDB query and watches for changes.
31
- *
32
- * Note that queries will only be executed once IndexedDB is open.
33
- *
34
- * If query output is an AsyncOp, it will be flattened. In other words, you
35
- * will only get one 'layer' of async ops.
36
- *
37
- * Provide a cache key if you want to make sure that data is synchronously
38
- * available during mounts/unmounts.
39
- */
40
- function useQuery<Output>(
41
- /**
42
- * `query` must have stable identity.
43
- *
44
- * Make sure you use `useCallback` or a module-scoped function.
45
- */
46
- query: (db: T) => Promise<Output>,
47
-
48
- cacheKey?: string,
49
- ): FlattenSuccessOps<QueryOp<Output>> {
50
- const openRequest = useDatabaseOpenRequest();
51
- const [queryOp, setOp] = useState<QueryOp<Output>>(new Pending());
52
-
53
- useEffect(() => {
54
- async function runQuery(): Promise<void> {
55
- if (openRequest.isSuccess) {
56
- try {
57
- const data = await query(openRequest.value);
58
- const success = new Success(data);
59
- setOp(success);
60
-
61
- if (cacheKey) {
62
- cache.set(cacheKey, success);
63
- }
64
- } catch (error) {
65
- const failure = new Failure({
66
- type: "QUERY_ERROR" as const,
67
- error: caughtValueToString(error),
68
- });
69
-
70
- setOp(failure);
71
- if (cacheKey) {
72
- cache.set(cacheKey, failure);
73
- }
74
- }
75
- }
76
- }
77
-
78
- db.addEventListener("readwrite", runQuery);
79
- window.addEventListener("focus", runQuery);
80
- void runQuery();
81
-
82
- return () => {
83
- db.removeEventListener("readwrite", runQuery);
84
- window.removeEventListener("focus", runQuery);
85
- };
86
- }, [cacheKey, openRequest, query]);
87
-
88
- return openRequest.flatMap(() => {
89
- const flattenOutput = (output: Output) => {
90
- if (isAsyncOp(output)) {
91
- return output as FlattenSuccessOps<QueryOp<Output>>;
92
- }
93
-
94
- return new Success(output) as FlattenSuccessOps<QueryOp<Output>>;
95
- };
96
-
97
- if (cacheKey) {
98
- const lastResult = cache.get(cacheKey) as QueryOp<Output> | undefined;
99
-
100
- if (lastResult && queryOp.isPending) {
101
- return lastResult.flatMap(flattenOutput);
102
- }
103
- }
104
-
105
- return queryOp.flatMap(flattenOutput);
106
- });
107
- }
108
-
109
- function useDatabase() {
110
- return useContext(DatabaseContext);
111
- }
112
-
113
- function useDatabaseOpenRequest() {
114
- return useContext(DatabaseOpenRequest);
115
- }
116
-
117
- function DatabaseProvider(props: { children: ReactNode; open?: boolean }) {
118
- const { children, open = true } = props;
119
- const { op, setSuccess, setFailure } = useAsyncOp<
120
- T,
121
- InaccessibleDatabaseError
122
- >();
123
-
124
- useEffect(() => {
125
- if (!open) {
126
- return;
127
- }
128
-
129
- db.open({
130
- onBlocking() {
131
- setFailure({ type: "CLOSED_FOR_UPGRADE" });
132
- db.close();
133
- console.info("Database closed due to version upgrade.");
134
- },
135
- }).then(
136
- () => {
137
- setSuccess(db);
138
- console.info("Database open.");
139
- },
140
- (error: unknown) => {
141
- setFailure(toKnownError(error));
142
- console.warn(`Request to open database failed.`);
143
- },
144
- );
145
-
146
- return () => {
147
- db.close();
148
- console.info("Database closed.");
149
- };
150
- }, [setFailure, setSuccess, open]);
151
-
152
- return (
153
- <DatabaseOpenRequest.Provider value={op}>
154
- {children}
155
- </DatabaseOpenRequest.Provider>
156
- );
157
- }
158
-
159
- return {
160
- useQuery,
161
- useDatabase,
162
- useDatabaseOpenRequest,
163
- DatabaseProvider,
164
- };
165
- }
@@ -1,2 +0,0 @@
1
- export * from "./factory.tsx";
2
- export * from "./types.ts";
@@ -1,32 +0,0 @@
1
- import type { InaccessibleDatabaseError } from "./types.ts";
2
-
3
- export function toKnownError(error: unknown): InaccessibleDatabaseError {
4
- if (error instanceof Error) {
5
- switch (error.name) {
6
- case "OpenRequestBlockedError": {
7
- return {
8
- type: "UPGRADE_BLOCKED",
9
- };
10
- }
11
-
12
- case "VersionError": {
13
- return {
14
- type: "DB_VERSION_HIGHER_THAN_REQUESTED",
15
- message: error.message,
16
- };
17
- }
18
-
19
- default: {
20
- return {
21
- type: "UNKNOWN_ERROR",
22
- message: error.message,
23
- };
24
- }
25
- }
26
- }
27
-
28
- return {
29
- type: "UNKNOWN_ERROR",
30
- message: "A non-error object was thrown.",
31
- };
32
- }
@@ -1,10 +0,0 @@
1
- export * from "./bindings/index.ts";
2
- export * from "./Cursor.ts";
3
- export * from "./ModernIDB.ts";
4
- export * from "./ModernIDBError.ts";
5
- export * from "./ObjectStore.ts";
6
- export * from "./ObjectStoreIndex.ts";
7
- export * from "./Transaction.ts";
8
- export * from "./types.ts";
9
- export * from "./utils.ts";
10
- export * from "./VersionChangeManager.ts";
@@ -1,120 +0,0 @@
1
- import { ModernIDB } from "./ModernIDB.ts";
2
- import { VersionChangeManager } from "./VersionChangeManager.ts";
3
-
4
- /**
5
- * IDB supports "readonly", "readwrite", and "versionchange" transaction modes,
6
- * but "versionchange" can only be initiated automatically during DB upgrade.
7
- */
8
- export type TransactionMode = "readonly" | "readwrite";
9
-
10
- export type ModernIDBState = "open" | "opening" | "closed";
11
-
12
- export type ModernIDBSchema = {
13
- [key: string]: unknown;
14
- };
15
-
16
- export type ModernIDBIndexes<Schema extends ModernIDBSchema> = {
17
- [K in keyof Schema]?: string;
18
- };
19
-
20
- export type VersionChangeHandlerProps<
21
- Schema extends ModernIDBSchema,
22
- IndexNames extends ModernIDBIndexes<Schema>,
23
- > = {
24
- event: IDBVersionChangeEvent;
25
- manager: VersionChangeManager<Schema, IndexNames>;
26
- db: ModernIDB<Schema, IndexNames>;
27
- };
28
-
29
- export type VersionChangeHandler<
30
- Schema extends ModernIDBSchema,
31
- IndexNames extends ModernIDBIndexes<Schema>,
32
- > = (props: VersionChangeHandlerProps<Schema, IndexNames>) => void;
33
-
34
- export type BlockingHandlerProps<
35
- Schema extends ModernIDBSchema,
36
- IndexNames extends ModernIDBIndexes<Schema>,
37
- > = {
38
- event: IDBVersionChangeEvent;
39
- db: ModernIDB<Schema, IndexNames>;
40
- };
41
-
42
- export type BlockingHandler<
43
- Schema extends ModernIDBSchema,
44
- IndexNames extends ModernIDBIndexes<Schema>,
45
- > = (props: BlockingHandlerProps<Schema, IndexNames>) => void;
46
-
47
- export type OpenRequestHandlers<
48
- Schema extends ModernIDBSchema,
49
- IndexNames extends ModernIDBIndexes<Schema>,
50
- > = {
51
- /**
52
- * Called when the database is initialized from scratch.
53
- *
54
- * Should be used to set up all required stores and indexes.
55
- *
56
- * If error is thrown in this handler, the version change transaction will
57
- * be aborted.
58
- *
59
- * @example
60
- *
61
- * ```ts
62
- * onInit({ manager }) {
63
- * const store = manager.createObjectStore("items", { keyPath: "id" });
64
- * store.createIndex("createdTs", "createdTs");
65
- *
66
- * console.info("DB initialized.");
67
- * },
68
- * ```
69
- */
70
- onInit?: VersionChangeHandler<Schema, IndexNames>;
71
-
72
- /**
73
- * Called when there is an existing IDB database present, but is is of a lower
74
- * version than the latest.
75
- *
76
- * If error is thrown inside this handler, the version change transaction
77
- * will be aborted.
78
- *
79
- * @example
80
- * ```ts
81
- * onUpgrade({ manager, event }) {
82
- * switch (event.oldVersion) {
83
- * case 1: {
84
- * // We need a `settings` store in v2, but it did't exist in v1
85
- * const store = manager.createObjectStore("settings", { keyPath: "id" });
86
- * store.createIndex("createdTs", "createdTs");
87
- * }
88
- *
89
- * default: {
90
- * console.info(`Migration from DB v${event.oldVersion} complete.`);
91
- * }
92
- * }
93
- * }
94
- * ```
95
- */
96
- onUpgrade?: VersionChangeHandler<Schema, IndexNames>;
97
-
98
- /**
99
- * If a new connection opens which requests a higher version number than
100
- * is the current version number, a `versionchange` event will be dispatched
101
- * on the IDBDatabase instance. This handler can specify desired behaviour.
102
- * For example, you might want to close currently connected connections
103
- * to allow the version change to proceed.
104
- */
105
- onBlocking?: BlockingHandler<Schema, IndexNames>;
106
- };
107
-
108
- type ValidKeyValue = string | number | Date;
109
-
110
- export type KeyPath<T> = T extends { [key: string]: unknown }
111
- ? {
112
- [K in keyof T]: K extends string
113
- ? T[K] extends ValidKeyValue
114
- ? `${K}`
115
- : `${K}.${KeyPath<T[K]>}`
116
- : never;
117
- }[keyof T]
118
- : never;
119
-
120
- export type AnyModernIDB = ModernIDB<any, any>;
@@ -1,51 +0,0 @@
1
- export function transactionToPromise(
2
- transaction: IDBTransaction,
3
- ): Promise<Event> {
4
- return new Promise<Event>((resolve, reject) => {
5
- transaction.addEventListener("complete", resolve, { once: true });
6
- transaction.addEventListener("error", reject, { once: true });
7
- transaction.addEventListener("abort", reject, { once: true });
8
- });
9
- }
10
-
11
- export function requestToPromise<T>(request: IDBRequest<T>) {
12
- return new Promise<T>((resolve, reject) => {
13
- const success = () => resolve(request.result);
14
- const error = () => reject(request.error);
15
- request.addEventListener("success", success, { once: true });
16
- request.addEventListener("error", error, { once: true });
17
- });
18
- }
19
-
20
- export function openRequestToPromise(request: IDBOpenDBRequest) {
21
- return new Promise<IDBDatabase>((resolve, reject) => {
22
- const success = () => resolve(request.result);
23
- const error = () => reject(request.error);
24
- const blocked = () =>
25
- reject(
26
- new Error(
27
- "Operation blocked. An existing database connection is preventing this action.",
28
- ),
29
- );
30
-
31
- request.addEventListener("success", success, { once: true });
32
- request.addEventListener("error", error, { once: true });
33
- request.addEventListener("blocked", blocked, { once: true });
34
- });
35
- }
36
-
37
- export async function* requestToAsyncGenerator(
38
- request: IDBRequest<IDBCursorWithValue | null>,
39
- ) {
40
- let cursor = await requestToPromise(request);
41
-
42
- while (cursor) {
43
- yield cursor;
44
-
45
- if (request.readyState !== "pending") {
46
- cursor.continue();
47
- }
48
-
49
- cursor = await requestToPromise(request);
50
- }
51
- }
@@ -1,41 +0,0 @@
1
- import { http, HttpResponse } from "msw";
2
- import preview from "../../.storybook/preview.tsx";
3
- import { Failure, Pending, Success } from "../async-op.ts";
4
- import { QRCode } from "./QRCode.tsx";
5
-
6
- const meta = preview.meta({
7
- title: "Components/QR Code",
8
- component: QRCode,
9
- tags: ["autodocs"],
10
- args: {
11
- url: new Success("example.com"),
12
- },
13
- parameters: {
14
- msw: {
15
- handlers: {
16
- qr: http.get("http://mock.api/qr", async () => {
17
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 41 41" shape-rendering="crispEdges"><path fill="#ffffff" d="M0 0h41v41H0z"/><path stroke="#000000" d="M4 4.5h7m2 0h2m2 0h1m3 0h1m1 0h3m1 0h1m2 0h7M4 5.5h1m5 0h1m2 0h2m1 0h4m2 0h1m1 0h3m1 0h1m1 0h1m5 0h1M4 6.5h1m1 0h3m1 0h1m1 0h1m3 0h2m1 0h1m4 0h2m1 0h1m2 0h1m1 0h3m1 0h1M4 7.5h1m1 0h3m1 0h1m1 0h5m1 0h3m3 0h5m1 0h1m1 0h3m1 0h1M4 8.5h1m1 0h3m1 0h1m1 0h2m3 0h1m1 0h1m2 0h3m2 0h1m2 0h1m1 0h3m1 0h1M4 9.5h1m5 0h1m1 0h1m1 0h1m1 0h5m3 0h1m1 0h1m3 0h1m5 0h1M4 10.5h7m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h7M12 11.5h4m3 0h1m2 0h6M4 12.5h1m1 0h5m3 0h1m2 0h5m4 0h1m1 0h1m1 0h5M4 13.5h2m2 0h1m2 0h1m2 0h3m3 0h6m1 0h1m2 0h2m1 0h2m1 0h1M4 14.5h7m1 0h1m3 0h1m2 0h3m2 0h3m1 0h1m1 0h1m1 0h1m1 0h2M4 15.5h6m1 0h4m1 0h1m1 0h1m1 0h1m1 0h1m2 0h5m2 0h4M4 16.5h1m2 0h4m1 0h2m1 0h2m5 0h2m2 0h1m1 0h1m3 0h2m1 0h1M6 17.5h2m3 0h2m1 0h3m1 0h3m1 0h3m5 0h1m3 0h3M4 18.5h3m3 0h2m3 0h1m2 0h1m3 0h1m1 0h3m2 0h2m4 0h1M4 19.5h3m1 0h1m7 0h1m3 0h1m3 0h2m2 0h3m1 0h1m1 0h1M4 20.5h1m1 0h1m1 0h1m1 0h1m1 0h1m1 0h1m2 0h2m2 0h1m1 0h1m3 0h1m1 0h1m1 0h2m3 0h1M6 21.5h1m2 0h1m1 0h5m4 0h5m2 0h1m2 0h2m1 0h4M4 22.5h8m1 0h3m1 0h3m1 0h1m4 0h1m2 0h4m1 0h2M4 23.5h1m1 0h2m4 0h1m2 0h8m1 0h3m2 0h6M4 24.5h3m2 0h2m1 0h1m2 0h1m1 0h1m1 0h2m5 0h1m2 0h1m1 0h3m1 0h2M4 25.5h5m3 0h3m2 0h3m2 0h3m4 0h2m2 0h1m2 0h1M4 26.5h1m2 0h1m1 0h3m3 0h2m2 0h4m1 0h1m1 0h1m2 0h1m1 0h3m1 0h1M4 27.5h1m3 0h2m1 0h2m1 0h3m1 0h2m2 0h1m1 0h2m1 0h1m1 0h1m1 0h1m1 0h2m1 0h1M4 28.5h1m1 0h2m2 0h3m2 0h7m4 0h7m2 0h1M12 29.5h2m2 0h3m1 0h1m1 0h4m2 0h1m3 0h1m1 0h1m1 0h1M4 30.5h7m2 0h1m1 0h1m3 0h2m1 0h1m3 0h3m1 0h1m1 0h1m1 0h2M4 31.5h1m5 0h1m1 0h1m3 0h2m1 0h2m2 0h6m3 0h5M4 32.5h1m1 0h3m1 0h1m1 0h1m6 0h1m2 0h5m1 0h6M4 33.5h1m1 0h3m1 0h1m1 0h2m5 0h3m1 0h1m4 0h2m2 0h1m1 0h3M4 34.5h1m1 0h3m1 0h1m1 0h1m2 0h1m1 0h1m6 0h2m1 0h5m1 0h2M4 35.5h1m5 0h1m2 0h2m1 0h3m1 0h1m1 0h1m2 0h2m5 0h3M4 36.5h7m1 0h6m3 0h1m4 0h1m1 0h4m1 0h1m1 0h1"/></svg>`;
18
- const { buffer } = new TextEncoder().encode(svg);
19
-
20
- return HttpResponse.arrayBuffer(buffer, {
21
- headers: { "Content-Type": "image/svg+xml" },
22
- });
23
- }),
24
- },
25
- },
26
- },
27
- });
28
-
29
- export const SuccessCase = meta.story({});
30
-
31
- export const PendingCase = meta.story({
32
- args: {
33
- url: new Pending(),
34
- },
35
- });
36
-
37
- export const FailureCase = meta.story({
38
- args: {
39
- url: new Failure("Failed"),
40
- },
41
- });
@@ -1,54 +0,0 @@
1
- import { useAppConfig } from "../AppConfig/AppConfig.tsx";
2
- import type { AsyncOp } from "../async-op.ts";
3
- import { cx } from "../class-names.ts";
4
- import { LoadingIndicator } from "../LoadingIndicator.js";
5
- import { code } from "./style.css.ts";
6
-
7
- type QRCodeProps = {
8
- url: AsyncOp<string, unknown>;
9
- className?: string;
10
- };
11
-
12
- export function QRCode(props: QRCodeProps) {
13
- const { url: result } = props;
14
- const { client } = useAppConfig();
15
-
16
- return (
17
- <div {...cx(props, code.container)}>
18
- {result.unpack(
19
- (url) => {
20
- const params = new URLSearchParams({ url });
21
- const src = `${client.origin}/qr?${params}`;
22
- return (
23
- <img
24
- {...cx(code.image)}
25
- src={src}
26
- alt=""
27
- width={150}
28
- height={150}
29
- />
30
- );
31
- },
32
- () => {
33
- return (
34
- <svg
35
- width="24px"
36
- height="24px"
37
- viewBox="0 0 24 24"
38
- version="1.1"
39
- xmlns="http://www.w3.org/2000/svg"
40
- >
41
- <g strokeWidth="2" stroke="#000000" strokeLinecap="square">
42
- <line x1="7" y1="7" x2="17" y2="17" />
43
- <line x1="17" y1="7" x2="7" y2="17" />
44
- </g>
45
- </svg>
46
- );
47
- },
48
- () => {
49
- return <LoadingIndicator />;
50
- },
51
- )}
52
- </div>
53
- );
54
- }
@@ -1,23 +0,0 @@
1
- import { style } from "@vanilla-extract/css";
2
-
3
- export const code = {
4
- container: style({
5
- "@layer": {
6
- appkit: {
7
- display: "flex",
8
- alignItems: "center",
9
- justifyContent: "center",
10
- backgroundColor: "white",
11
- borderRadius: "0.5rem",
12
- maxInlineSize: "12rem",
13
- aspectRatio: "1",
14
- },
15
- },
16
- }),
17
-
18
- image: style({
19
- inlineSize: "100%",
20
- blockSize: "auto",
21
- borderRadius: "inherit",
22
- }),
23
- };
@@ -1,29 +0,0 @@
1
- export function ReleaseInfo(props: {
2
- branch?: string;
3
- shortcode?: string;
4
- backgroundColor?: string;
5
- }) {
6
- if (!props.branch || !props.shortcode) {
7
- return <>Release [local]</>;
8
- }
9
-
10
- return (
11
- <>
12
- {`Release `}
13
- <code
14
- style={{
15
- fontSize: "0.875em",
16
- backgroundColor: props.backgroundColor,
17
- paddingInline: "0.25rem",
18
- paddingBlock: "0.125rem",
19
- borderRadius: "0.25rem",
20
- fontFamily: "monospace",
21
- }}
22
- >
23
- {props.shortcode}
24
- </code>
25
-
26
- {props.branch === "main" ? "" : ` (${props.branch})`}
27
- </>
28
- );
29
- }