@brett_lamy/ui 3.1.0 → 5.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 (241) hide show
  1. package/README.md +4 -4
  2. package/dist/components/animated-height.d.ts +3 -1
  3. package/dist/components/animated-height.d.ts.map +1 -1
  4. package/dist/components/animated-height.js +11 -11
  5. package/dist/components/artifact-chat-container.d.ts.map +1 -1
  6. package/dist/components/artifact-chat-container.js +81 -82
  7. package/dist/components/button.d.ts +4 -3
  8. package/dist/components/button.d.ts.map +1 -1
  9. package/dist/components/button.js +22 -9
  10. package/dist/components/canvas.d.ts +91 -0
  11. package/dist/components/canvas.d.ts.map +1 -0
  12. package/dist/components/canvas.js +296 -0
  13. package/dist/components/composer/composer-cards.d.ts +55 -0
  14. package/dist/components/composer/composer-cards.d.ts.map +1 -0
  15. package/dist/components/composer/composer-cards.js +351 -0
  16. package/dist/components/composer/composer.d.ts +9 -1
  17. package/dist/components/composer/composer.d.ts.map +1 -1
  18. package/dist/components/composer/composer.js +179 -154
  19. package/dist/components/context-menu.d.ts +25 -0
  20. package/dist/components/context-menu.d.ts.map +1 -0
  21. package/dist/components/context-menu.js +127 -0
  22. package/dist/components/credenza.d.ts.map +1 -1
  23. package/dist/components/credenza.js +52 -92
  24. package/dist/components/cron-editor.d.ts +47 -0
  25. package/dist/components/cron-editor.d.ts.map +1 -0
  26. package/dist/components/cron-editor.js +297 -0
  27. package/dist/components/dropdown-menu.d.ts +3 -1
  28. package/dist/components/dropdown-menu.d.ts.map +1 -1
  29. package/dist/components/dropdown-menu.js +5 -5
  30. package/dist/components/edge-drawer.d.ts.map +1 -1
  31. package/dist/components/edge-drawer.js +1 -0
  32. package/dist/components/file-upload.d.ts +121 -0
  33. package/dist/components/file-upload.d.ts.map +1 -0
  34. package/dist/components/file-upload.js +405 -0
  35. package/dist/components/filter-input.d.ts +22 -0
  36. package/dist/components/filter-input.d.ts.map +1 -0
  37. package/dist/components/filter-input.js +126 -0
  38. package/dist/components/filter.d.ts +154 -0
  39. package/dist/components/filter.d.ts.map +1 -0
  40. package/dist/components/filter.js +815 -0
  41. package/dist/components/floating-chat.d.ts.map +1 -1
  42. package/dist/components/floating-chat.js +71 -88
  43. package/dist/components/floating-sheet.d.ts +21 -5
  44. package/dist/components/floating-sheet.d.ts.map +1 -1
  45. package/dist/components/floating-sheet.js +113 -116
  46. package/dist/components/markdown-editor.d.ts +2 -0
  47. package/dist/components/markdown-editor.d.ts.map +1 -1
  48. package/dist/components/markdown-editor.js +46 -45
  49. package/dist/components/markdown-view.d.ts +6 -1
  50. package/dist/components/markdown-view.d.ts.map +1 -1
  51. package/dist/components/markdown-view.js +13 -11
  52. package/dist/components/navigation-stack.d.ts +3 -5
  53. package/dist/components/navigation-stack.d.ts.map +1 -1
  54. package/dist/components/navigation-stack.js +212 -382
  55. package/dist/components/passkey-enroll-dialog.d.ts +36 -0
  56. package/dist/components/passkey-enroll-dialog.d.ts.map +1 -0
  57. package/dist/components/passkey-enroll-dialog.js +234 -0
  58. package/dist/components/result-table.d.ts +38 -0
  59. package/dist/components/result-table.d.ts.map +1 -0
  60. package/dist/components/result-table.js +161 -0
  61. package/dist/components/schema-tree.d.ts +19 -0
  62. package/dist/components/schema-tree.d.ts.map +1 -0
  63. package/dist/components/schema-tree.js +172 -0
  64. package/dist/components/side-drawer.d.ts.map +1 -1
  65. package/dist/components/side-drawer.js +117 -143
  66. package/dist/components/slider.d.ts.map +1 -1
  67. package/dist/components/slider.js +4 -1
  68. package/dist/components/spinner-shapes.d.ts +263 -0
  69. package/dist/components/spinner-shapes.d.ts.map +1 -0
  70. package/dist/components/spinner-shapes.js +771 -0
  71. package/dist/components/spinner.d.ts +133 -3
  72. package/dist/components/spinner.d.ts.map +1 -1
  73. package/dist/components/spinner.js +445 -29
  74. package/dist/components/sql-console.d.ts +28 -0
  75. package/dist/components/sql-console.d.ts.map +1 -0
  76. package/dist/components/sql-console.js +348 -0
  77. package/dist/components/sql-editor.d.ts +47 -0
  78. package/dist/components/sql-editor.d.ts.map +1 -0
  79. package/dist/components/sql-editor.js +170 -0
  80. package/dist/components/tab-view.d.ts +2 -2
  81. package/dist/components/tab-view.d.ts.map +1 -1
  82. package/dist/components/tab-view.js +63 -49
  83. package/dist/components/tailscale-login-button.d.ts +53 -0
  84. package/dist/components/tailscale-login-button.d.ts.map +1 -0
  85. package/dist/components/tailscale-login-button.js +197 -0
  86. package/dist/components/time-input.d.ts +46 -0
  87. package/dist/components/time-input.d.ts.map +1 -0
  88. package/dist/components/time-input.js +258 -0
  89. package/dist/components/toast.d.ts +5 -2
  90. package/dist/components/toast.d.ts.map +1 -1
  91. package/dist/components/toast.js +249 -125
  92. package/dist/components/vault-gate.d.ts +60 -0
  93. package/dist/components/vault-gate.d.ts.map +1 -0
  94. package/dist/components/vault-gate.js +382 -0
  95. package/dist/index.css +1 -1
  96. package/dist/index.d.ts +86 -7
  97. package/dist/index.d.ts.map +1 -1
  98. package/dist/index.js +129 -85
  99. package/dist/lib/back-history.d.ts +5 -0
  100. package/dist/lib/back-history.d.ts.map +1 -0
  101. package/dist/lib/back-history.js +44 -0
  102. package/dist/lib/canvas-math.d.ts +82 -0
  103. package/dist/lib/canvas-math.d.ts.map +1 -0
  104. package/dist/lib/canvas-math.js +226 -0
  105. package/dist/lib/controllable-state.d.ts +4 -0
  106. package/dist/lib/controllable-state.d.ts.map +1 -0
  107. package/dist/lib/controllable-state.js +11 -0
  108. package/dist/lib/cron.d.ts +55 -0
  109. package/dist/lib/cron.d.ts.map +1 -0
  110. package/dist/lib/cron.js +269 -0
  111. package/dist/lib/edge-swipe.d.ts +36 -0
  112. package/dist/lib/edge-swipe.d.ts.map +1 -0
  113. package/dist/lib/edge-swipe.js +73 -0
  114. package/dist/lib/file-upload.d.ts +187 -0
  115. package/dist/lib/file-upload.d.ts.map +1 -0
  116. package/dist/lib/file-upload.js +349 -0
  117. package/dist/lib/filter-query.d.ts +90 -0
  118. package/dist/lib/filter-query.d.ts.map +1 -0
  119. package/dist/lib/filter-query.js +459 -0
  120. package/dist/lib/filter.d.ts +120 -0
  121. package/dist/lib/filter.d.ts.map +1 -0
  122. package/dist/lib/filter.js +399 -0
  123. package/dist/lib/format-bytes.d.ts +3 -0
  124. package/dist/lib/format-bytes.d.ts.map +1 -0
  125. package/dist/lib/format-bytes.js +16 -0
  126. package/dist/lib/gpu-cron.d.ts +51 -0
  127. package/dist/lib/gpu-cron.d.ts.map +1 -0
  128. package/dist/lib/gpu-cron.js +81 -0
  129. package/dist/lib/gpu-query/featurize.d.ts +19 -0
  130. package/dist/lib/gpu-query/featurize.d.ts.map +1 -0
  131. package/dist/lib/gpu-query/featurize.js +88 -0
  132. package/dist/lib/gpu-query/index.d.ts +73 -0
  133. package/dist/lib/gpu-query/index.d.ts.map +1 -0
  134. package/dist/lib/gpu-query/index.js +117 -0
  135. package/dist/lib/gpu-query/kernel.wgsl.d.ts +30 -0
  136. package/dist/lib/gpu-query/kernel.wgsl.d.ts.map +1 -0
  137. package/dist/lib/gpu-query/model.d.ts +8 -0
  138. package/dist/lib/gpu-query/model.d.ts.map +1 -0
  139. package/dist/lib/gpu-query/model.js +91 -0
  140. package/dist/lib/gpu-query/schema.d.ts +40 -0
  141. package/dist/lib/gpu-query/schema.d.ts.map +1 -0
  142. package/dist/lib/gpu-query/schema.js +0 -0
  143. package/dist/lib/gpu-query/webgpu.d.ts +12 -0
  144. package/dist/lib/gpu-query/webgpu.d.ts.map +1 -0
  145. package/dist/lib/gpu-query/weights.d.ts +17 -0
  146. package/dist/lib/gpu-query/weights.d.ts.map +1 -0
  147. package/dist/lib/gpu-query/weights.js +40 -0
  148. package/dist/lib/gpu-query/weights.json.d.ts +3 -0
  149. package/dist/lib/gpu-query/weights2.js +25 -0
  150. package/dist/lib/gpu-time.d.ts +77 -0
  151. package/dist/lib/gpu-time.d.ts.map +1 -0
  152. package/dist/lib/gpu-time.js +260 -0
  153. package/dist/lib/morph-path.d.ts +22 -0
  154. package/dist/lib/morph-path.d.ts.map +1 -0
  155. package/dist/lib/morph-path.js +42 -0
  156. package/dist/lib/passkey.d.ts +120 -0
  157. package/dist/lib/passkey.d.ts.map +1 -0
  158. package/dist/lib/passkey.js +186 -0
  159. package/dist/lib/persistent-state.d.ts +9 -0
  160. package/dist/lib/persistent-state.d.ts.map +1 -0
  161. package/dist/lib/persistent-state.js +37 -0
  162. package/dist/lib/pglite-core.d.ts +219 -0
  163. package/dist/lib/pglite-core.d.ts.map +1 -0
  164. package/dist/lib/pglite-core.js +273 -0
  165. package/dist/lib/pglite-files.d.ts +7 -0
  166. package/dist/lib/pglite-files.d.ts.map +1 -0
  167. package/dist/lib/pglite-files.js +17 -0
  168. package/dist/lib/pglite-schema.d.ts +58 -0
  169. package/dist/lib/pglite-schema.d.ts.map +1 -0
  170. package/dist/lib/pglite-schema.js +105 -0
  171. package/dist/lib/pglite-storage.d.ts +33 -0
  172. package/dist/lib/pglite-storage.d.ts.map +1 -0
  173. package/dist/lib/pglite-storage.js +55 -0
  174. package/dist/lib/pglite-transfer.d.ts +53 -0
  175. package/dist/lib/pglite-transfer.d.ts.map +1 -0
  176. package/dist/lib/pglite-transfer.js +126 -0
  177. package/dist/lib/pglite.d.ts +106 -0
  178. package/dist/lib/pglite.d.ts.map +1 -0
  179. package/dist/lib/pglite.js +298 -0
  180. package/dist/lib/pull-to-refresh.d.ts +24 -0
  181. package/dist/lib/pull-to-refresh.d.ts.map +1 -0
  182. package/dist/lib/pull-to-refresh.js +74 -0
  183. package/dist/lib/scroll-hidden.d.ts +6 -0
  184. package/dist/lib/scroll-hidden.d.ts.map +1 -0
  185. package/dist/lib/scroll-hidden.js +21 -0
  186. package/dist/lib/sheet-drag.d.ts +10 -2
  187. package/dist/lib/sheet-drag.d.ts.map +1 -1
  188. package/dist/lib/sheet-drag.js +72 -69
  189. package/dist/lib/sql-format.d.ts +62 -0
  190. package/dist/lib/sql-format.d.ts.map +1 -0
  191. package/dist/lib/sql-format.js +175 -0
  192. package/dist/lib/sql-lex.d.ts +25 -0
  193. package/dist/lib/sql-lex.d.ts.map +1 -0
  194. package/dist/lib/sql-lex.js +135 -0
  195. package/dist/lib/tab-lock.d.ts +28 -0
  196. package/dist/lib/tab-lock.d.ts.map +1 -0
  197. package/dist/lib/tab-lock.js +80 -0
  198. package/dist/lib/tailscale-connect.d.ts +56 -0
  199. package/dist/lib/tailscale-connect.d.ts.map +1 -0
  200. package/dist/lib/tailscale-connect.js +99 -0
  201. package/dist/lib/tailscale-fake.d.ts +33 -0
  202. package/dist/lib/tailscale-fake.d.ts.map +1 -0
  203. package/dist/lib/tailscale-fake.js +80 -0
  204. package/dist/lib/tailscale-policy.d.ts +71 -0
  205. package/dist/lib/tailscale-policy.d.ts.map +1 -0
  206. package/dist/lib/tailscale-policy.js +244 -0
  207. package/dist/lib/tailscale-react.d.ts +20 -0
  208. package/dist/lib/tailscale-react.d.ts.map +1 -0
  209. package/dist/lib/tailscale-react.js +37 -0
  210. package/dist/lib/tailscale-router/bridge.d.ts +60 -0
  211. package/dist/lib/tailscale-router/bridge.d.ts.map +1 -0
  212. package/dist/lib/tailscale-router/bridge.js +198 -0
  213. package/dist/lib/tailscale-router/react.d.ts +19 -0
  214. package/dist/lib/tailscale-router/react.d.ts.map +1 -0
  215. package/dist/lib/tailscale-router/react.js +52 -0
  216. package/dist/lib/tailscale.d.ts +204 -0
  217. package/dist/lib/tailscale.d.ts.map +1 -0
  218. package/dist/lib/tailscale.js +443 -0
  219. package/dist/lib/title-flight.d.ts +34 -0
  220. package/dist/lib/title-flight.d.ts.map +1 -0
  221. package/dist/lib/title-flight.js +123 -0
  222. package/dist/lib/vault-react.d.ts +49 -0
  223. package/dist/lib/vault-react.d.ts.map +1 -0
  224. package/dist/lib/vault-react.js +196 -0
  225. package/dist/lib/vault-storage.d.ts +30 -0
  226. package/dist/lib/vault-storage.d.ts.map +1 -0
  227. package/dist/lib/vault-storage.js +105 -0
  228. package/dist/lib/vault.d.ts +200 -0
  229. package/dist/lib/vault.d.ts.map +1 -0
  230. package/dist/lib/vault.js +641 -0
  231. package/dist/tailscale-sw.js +332 -0
  232. package/package.json +35 -5
  233. package/dist/components/icon-button.d.ts +0 -19
  234. package/dist/components/icon-button.d.ts.map +0 -1
  235. package/dist/components/icon-button.js +0 -31
  236. package/dist/components/measure-h.d.ts +0 -7
  237. package/dist/components/measure-h.d.ts.map +0 -1
  238. package/dist/components/measure-h.js +0 -20
  239. package/dist/components/snap-sheet.d.ts +0 -13
  240. package/dist/components/snap-sheet.d.ts.map +0 -1
  241. package/dist/components/snap-sheet.js +0 -100
@@ -0,0 +1,126 @@
1
+ import { DataDirVersionError as e, PGliteError as t, openDatabase as n, peekDataDirVersion as r, readServerInfo as i, runtimePostgresMajor as a } from "./pglite-core.js";
2
+ //#region src/lib/pglite-transfer.ts
3
+ async function o(e, n = "sql", r = {}) {
4
+ let a = await i(e), o = `pg${a.serverMajor}`;
5
+ try {
6
+ if (n === "sql") {
7
+ let { pgDump: t } = await import("@electric-sql/pglite-tools/pg_dump"), i = await t({
8
+ pg: e,
9
+ args: r.args,
10
+ fileName: r.fileName ?? `database-${o}.sql`
11
+ });
12
+ return {
13
+ file: i,
14
+ format: n,
15
+ postgresVersion: a.serverVersion,
16
+ postgresMajor: a.serverMajor,
17
+ pgliteVersion: a.pgliteVersion,
18
+ bytes: i.size
19
+ };
20
+ }
21
+ let t = await e.dumpDataDir("gzip"), i = r.fileName ?? `database-${o}${a.pgliteVersion ? `-pglite${a.pgliteVersion}` : ""}.tar.gz`, s = new File([t], i, { type: "application/gzip" });
22
+ return {
23
+ file: s,
24
+ format: n,
25
+ postgresVersion: a.serverVersion,
26
+ postgresMajor: a.serverMajor,
27
+ pgliteVersion: a.pgliteVersion,
28
+ bytes: s.size
29
+ };
30
+ } catch (e) {
31
+ throw e instanceof t ? e : new t("EXPORT_FAILED", `Could not export the database as ${n}: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
32
+ }
33
+ }
34
+ async function s(e) {
35
+ let t = new Uint8Array(await e.slice(0, 2).arrayBuffer());
36
+ if (t[0] === 31 && t[1] === 139) return "datadir";
37
+ let n = (e.name ?? "").toLowerCase();
38
+ return /\.(tar|tgz|tar\.gz)$/.test(n) ? "datadir" : "sql";
39
+ }
40
+ async function c(e, t) {
41
+ let n = new Uint8Array(await e.slice(0, 2).arrayBuffer()), r = n[0] === 31 && n[1] === 139, i = e.stream();
42
+ r && (i = i.pipeThrough(new DecompressionStream("gzip")));
43
+ let a = i.getReader(), o = /* @__PURE__ */ new Uint8Array(), s = async (e) => {
44
+ for (; o.length < e;) {
45
+ let { done: e, value: t } = await a.read();
46
+ if (e) return !1;
47
+ let n = new Uint8Array(o.length + t.length);
48
+ n.set(o), n.set(t, o.length), o = n;
49
+ }
50
+ return !0;
51
+ }, c = (e) => new TextDecoder().decode(e).replace(/\0.*$/s, "");
52
+ try {
53
+ for (;;) {
54
+ if (!await s(512)) return null;
55
+ let e = o.subarray(0, 512);
56
+ if (e.every((e) => e === 0)) return null;
57
+ let n = c(e.subarray(0, 100)), r = c(e.subarray(345, 500)), i = parseInt(c(e.subarray(124, 136)).trim() || "0", 8) || 0, a = Math.ceil(i / 512) * 512;
58
+ if (!await s(512 + a)) return null;
59
+ if (t(r ? `${r}/${n}` : n)) return c(o.subarray(512, 512 + i)).trim();
60
+ o = o.slice(512 + a);
61
+ }
62
+ } finally {
63
+ await a.cancel().catch(() => void 0);
64
+ }
65
+ }
66
+ async function l(e) {
67
+ return c(e, (e) => /(^|\/)PG_VERSION$/.test(e.replace(/^\.\//, "")) && !/(^|\/)(base|global|pg_[a-z_]+)\//.test(e));
68
+ }
69
+ function u(e) {
70
+ return /^-- Dumped from database version ([\d.]+)/m.exec(e.slice(0, 4e3))?.[1] ?? null;
71
+ }
72
+ async function d(e, n) {
73
+ let r = u(n), a = [], o = await i(e);
74
+ r && parseInt(r, 10) > o.serverMajor && a.push(`The dump was written by Postgres ${r}, newer than this database (${o.serverVersion}); statements it uses may not exist here.`);
75
+ try {
76
+ await e.exec(n);
77
+ } catch (n) {
78
+ throw await e.exec("rollback").catch(() => void 0), new t("IMPORT_FAILED", `The SQL dump could not be applied (nothing was changed): ${n instanceof Error ? n.message : String(n)}`, { cause: n });
79
+ } finally {
80
+ await e.exec("reset all").catch(() => void 0);
81
+ }
82
+ return {
83
+ format: "sql",
84
+ sourceVersion: r,
85
+ warnings: a,
86
+ applied: !0
87
+ };
88
+ }
89
+ async function f(i, o) {
90
+ let c = await s(o);
91
+ if (typeof i.exec == "function" && typeof i.query == "function") {
92
+ if (c === "datadir") throw new t("UNSUPPORTED", "A data-directory archive can only be loaded into a new database, not into one that is already open. Pass a config ({ dataDir: \"idb://new-name\" }) to importDatabase, or open a provider with loadDataDir.");
93
+ return d(i, await o.text());
94
+ }
95
+ let u = i;
96
+ if (c === "datadir") {
97
+ let t = await l(o), r = await a();
98
+ if (t && t !== r) throw new e(u.dataDir ?? "the archive", t, r);
99
+ return {
100
+ ...await n({
101
+ ...u,
102
+ loadDataDir: o
103
+ }),
104
+ format: c,
105
+ sourceVersion: t,
106
+ warnings: t ? [] : ["The archive has no PG_VERSION file; it was loaded without a version check."],
107
+ applied: !0
108
+ };
109
+ }
110
+ if (await r(u.dataDir ?? "memory://")) throw new t("DATABASE_EXISTS", `"${u.dataDir}" already holds a database. Import into a new name, or open it and import into the open database (which refuses to overwrite objects that exist).`);
111
+ let f = await n({
112
+ ...u,
113
+ loadDataDir: void 0
114
+ });
115
+ try {
116
+ let e = await d(f.db, await o.text());
117
+ return {
118
+ ...f,
119
+ ...e
120
+ };
121
+ } catch (e) {
122
+ throw await f.close(), e;
123
+ }
124
+ }
125
+ //#endregion
126
+ export { s as detectImportFormat, u as dumpVersion, o as exportDatabase, f as importDatabase, l as readArchiveVersion };
@@ -0,0 +1,106 @@
1
+ import { ReactNode } from 'react';
2
+ import { Database, DatabaseInfo, Migration, PGliteAssets, SqlError, SqlResult, SqlTransaction } from './pglite-core';
3
+ export type DatabaseStatus = 'loading' | 'ready' | 'error';
4
+ export interface DatabaseState {
5
+ status: DatabaseStatus;
6
+ /** The open database; `null` until `status` is `ready`. */
7
+ db: Database | null;
8
+ /** What went wrong opening it. A {@link DataDirVersionError} (`code === 'VERSION_MISMATCH'`) means the stored data is from another Postgres major. */
9
+ error: Error | null;
10
+ /** Postgres and PGlite versions, data directory, migrations applied by this open. */
11
+ info: DatabaseInfo | null;
12
+ /** Open again after an `error`. */
13
+ retry: () => void;
14
+ /** Re-runs every `useQuery` / `useSchema` on this provider. Writes made through `useExec` / `useTransaction` call it for you. */
15
+ invalidate: () => void;
16
+ /** Counts `invalidate()` calls. */
17
+ epoch: number;
18
+ }
19
+ export interface PGliteProviderProps {
20
+ /** `memory://` (default: gone on reload), `idb://<name>` (IndexedDB) or `opfs-ahp://<name>` (the origin private file system; needs `worker`). */
21
+ dataDir?: string;
22
+ /** Run PGlite in a Web Worker: `() => new Worker(new URL('./pglite.worker.ts', import.meta.url), { type: 'module' })`. Tabs sharing a `workerId` share one database. */
23
+ worker?: () => Worker;
24
+ workerId?: string;
25
+ extensions?: Record<string, unknown>;
26
+ /** Load the `live` extension for `useLiveQuery`. Default true. */
27
+ live?: boolean;
28
+ /** Applied after the database opens, in order; the applied ones must stay an unchanged prefix of the list. */
29
+ migrations?: readonly Migration[];
30
+ /** Restore a data-directory archive into a new database. */
31
+ loadDataDir?: Blob;
32
+ relaxedDurability?: boolean;
33
+ /** Host the WebAssembly yourself (main-thread databases). */
34
+ assets?: PGliteAssets;
35
+ /** Shown instead of `children` while the database opens. Without it, children render at once and the hooks report the status. */
36
+ fallback?: ReactNode;
37
+ /** Shown instead of `children` when it fails to open. Without it, children render and `useDatabaseStatus().error` has the error. */
38
+ errorFallback?: ReactNode | ((error: Error, retry: () => void) => ReactNode);
39
+ /** Called once the database is open and migrated. */
40
+ onReady?: (db: Database, info: DatabaseInfo) => void;
41
+ children?: ReactNode;
42
+ }
43
+ /** Opens a database and provides it to the hooks below. Only `dataDir`, `workerId` and `loadDataDir` re-open the
44
+ database when they change; the other options are read when it opens. */
45
+ export declare function PGliteProvider({ dataDir, worker, workerId, extensions, live, migrations, loadDataDir, relaxedDurability, assets, fallback, errorFallback, onReady, children, }: PGliteProviderProps): import("react/jsx-runtime").JSX.Element;
46
+ /** The database and its status. */
47
+ export declare function useDatabaseStatus(): DatabaseState;
48
+ /** The open database, or `null` while it opens (or failed to). Cast the type argument to reach PGlite's own API: `usePGlite<PGlite>()`. */
49
+ export declare function usePGlite<T extends Database = Database>(): T | null;
50
+ /** The open database; throws when there is none. For components rendered under a `fallback` provider (children mount only once ready). */
51
+ export declare function useReadyDatabase<T extends Database = Database>(): T;
52
+ export interface QueryState<T> {
53
+ rows: T[];
54
+ fields: SqlResult<T>['fields'];
55
+ /** The error of the last run (parse errors, missing tables, …) with its position in the SQL. */
56
+ error: SqlError | null;
57
+ /** True while the first result is loading and while a re-run is in flight. */
58
+ isLoading: boolean;
59
+ /** Run again now. Resolves when the new result is in. */
60
+ refetch: () => Promise<void>;
61
+ }
62
+ export interface UseQueryOptions {
63
+ /** `false` waits (the query is not run). Default true. */
64
+ enabled?: boolean;
65
+ /** Re-run when something calls `invalidate()` (writes through `useExec` / `useTransaction`). Default true. */
66
+ watch?: boolean;
67
+ }
68
+ /** Runs `sql` once the database is ready and again whenever `sql` or `params` change, a write goes through
69
+ `useExec` / `useTransaction`, or `refetch()` is called. Stale results (an older run finishing late) are dropped.
70
+ For results that follow the database's own changes, use `useLiveQuery`. */
71
+ export declare function useQuery<T = Record<string, unknown>>(sql: string, params?: readonly unknown[], { enabled, watch }?: UseQueryOptions): QueryState<T>;
72
+ export interface LiveQueryState<T> {
73
+ rows: T[];
74
+ fields: SqlResult<T>['fields'];
75
+ error: SqlError | null;
76
+ /** True until the first result arrives. */
77
+ isLoading: boolean;
78
+ }
79
+ export interface UseLiveQueryOptions {
80
+ /** A column that identifies a row: PGlite then diffs results incrementally instead of re-running the whole query. */
81
+ key?: string;
82
+ enabled?: boolean;
83
+ }
84
+ /** A query that stays up to date: PGlite's `live` extension watches the tables the query reads and pushes new results
85
+ * when they change — from any writer on the same database, including other tabs on a shared worker.
86
+ *
87
+ * Why not `@electric-sql/pglite-react`? Its `useLiveQuery` returns `undefined` until the first result, has no error
88
+ * or loading state, needs its own provider next to ours and pins an exact `@electric-sql/pglite` peer version. This
89
+ * is the same ~40 lines on top of `db.live`, wired to our provider's status. */
90
+ export declare function useLiveQuery<T = Record<string, unknown>>(sql: string, params?: readonly unknown[], { key, enabled }?: UseLiveQueryOptions): LiveQueryState<T>;
91
+ export interface MutationState {
92
+ isPending: boolean;
93
+ error: SqlError | null;
94
+ reset: () => void;
95
+ }
96
+ /** Writes. `exec(sql)` runs one or more statements (no parameters) and returns a result per statement; `run(sql,
97
+ * params)` runs one parameterised statement. A successful write calls `invalidate()`, so `useQuery`s refresh. */
98
+ export declare function useExec(): MutationState & {
99
+ exec: (sql: string) => Promise<SqlResult[]>;
100
+ run: <T = Record<string, unknown>>(sql: string, params?: readonly unknown[]) => Promise<SqlResult<T>>;
101
+ };
102
+ /** `transaction(async (tx) => { … })` — everything the callback does commits together, or none of it does (throw to roll back). Invalidates queries on commit. */
103
+ export declare function useTransaction(): MutationState & {
104
+ transaction: <R>(callback: (tx: SqlTransaction) => Promise<R>) => Promise<R>;
105
+ };
106
+ //# sourceMappingURL=pglite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pglite.d.ts","sourceRoot":"","sources":["../../src/lib/pglite.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAA4B,KAAK,YAAY,EAC7F,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EACnD,MAAM,mBAAmB,CAAC;AAwE3B,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,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
+ "use client";
2
+ import { openDatabase as e, parseDataDir as t, toSqlError as n } from "./pglite-core.js";
3
+ import { createContext as r, useCallback as i, useContext as a, useEffect as o, useId as s, useMemo as c, useRef as l, useState as u } from "react";
4
+ import { jsx as d } from "react/jsx-runtime";
5
+ //#region src/lib/pglite.tsx
6
+ var f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map();
7
+ function m(t, n) {
8
+ let r = f.get(t);
9
+ if (!r) {
10
+ let i = {
11
+ key: t,
12
+ refs: 0,
13
+ promise: void 0,
14
+ closeTimer: null,
15
+ closed: null,
16
+ close: async () => void 0
17
+ };
18
+ i.promise = (async () => {
19
+ await p.get(t);
20
+ let r = await e(n());
21
+ return i.close = r.close, {
22
+ db: r.db,
23
+ info: r.info
24
+ };
25
+ })(), i.promise.catch(() => {
26
+ f.get(t) === i && f.delete(t);
27
+ }), f.set(t, i), r = i;
28
+ }
29
+ return r.closeTimer && (clearTimeout(r.closeTimer), r.closeTimer = null), r.refs++, r;
30
+ }
31
+ function h(e) {
32
+ --e.refs > 0 || (e.closeTimer = setTimeout(() => {
33
+ if (e.refs > 0) return;
34
+ f.get(e.key) === e && f.delete(e.key);
35
+ let t = e.promise.then(() => e.close(), () => void 0).finally(() => {
36
+ p.get(e.key) === t && p.delete(e.key);
37
+ });
38
+ p.set(e.key, t);
39
+ }, 0));
40
+ }
41
+ var g = () => void 0, _ = r({
42
+ status: "loading",
43
+ db: null,
44
+ error: null,
45
+ info: null,
46
+ retry: g,
47
+ invalidate: g,
48
+ epoch: 0
49
+ });
50
+ function v({ dataDir: e = "memory://", worker: n, workerId: r, extensions: a, live: f, migrations: p, loadDataDir: g, relaxedDurability: v, assets: y, fallback: b, errorFallback: x, onReady: S, children: C }) {
51
+ let w = s(), [T, E] = u(0), [D, O] = u(0), [k, A] = u({
52
+ status: "loading",
53
+ db: null,
54
+ error: null,
55
+ info: null
56
+ }), j = l({});
57
+ j.current = {
58
+ dataDir: e,
59
+ worker: n,
60
+ workerId: r,
61
+ extensions: a,
62
+ live: f,
63
+ migrations: p,
64
+ loadDataDir: g,
65
+ relaxedDurability: v,
66
+ assets: y
67
+ };
68
+ let M = l(S);
69
+ M.current = S;
70
+ let N = t(e).kind === "memory" ? `memory://${w}` : `${t(e).dataDir}${r ? `#${r}` : ""}${g ? "#load" : ""}`;
71
+ o(() => {
72
+ let e = !1;
73
+ A((e) => e.status === "loading" && !e.db && !e.error ? e : {
74
+ status: "loading",
75
+ db: null,
76
+ error: null,
77
+ info: null
78
+ });
79
+ let t = m(N, () => j.current);
80
+ return t.promise.then(({ db: t, info: n }) => {
81
+ e || (A({
82
+ status: "ready",
83
+ db: t,
84
+ error: null,
85
+ info: n
86
+ }), M.current?.(t, n));
87
+ }, (t) => {
88
+ e || A({
89
+ status: "error",
90
+ db: null,
91
+ error: t instanceof Error ? t : Error(String(t)),
92
+ info: null
93
+ });
94
+ }), () => {
95
+ e = !0, h(t);
96
+ };
97
+ }, [N, T]);
98
+ let P = i(() => E((e) => e + 1), []), F = i(() => O((e) => e + 1), []), I = c(() => ({
99
+ ...k,
100
+ retry: P,
101
+ invalidate: F,
102
+ epoch: D
103
+ }), [
104
+ k,
105
+ P,
106
+ F,
107
+ D
108
+ ]), L = C;
109
+ return k.status === "loading" && b !== void 0 ? L = b : k.status === "error" && x !== void 0 && (L = typeof x == "function" ? x(k.error, P) : x), /* @__PURE__ */ d(_.Provider, {
110
+ value: I,
111
+ children: L
112
+ });
113
+ }
114
+ function y() {
115
+ return a(_);
116
+ }
117
+ function b() {
118
+ return a(_).db;
119
+ }
120
+ function x() {
121
+ let { db: e, status: t } = a(_);
122
+ if (!e) throw Error(`useReadyDatabase: the database is ${t}. Render this component under <PGliteProvider fallback={…}> or check useDatabaseStatus().`);
123
+ return e;
124
+ }
125
+ function S(e) {
126
+ return e?.length ? JSON.stringify(e, (e, t) => typeof t == "bigint" ? `${t}n` : t instanceof Uint8Array ? Array.from(t) : t) : "";
127
+ }
128
+ var C = [];
129
+ function w(e, t, { enabled: r = !0, watch: a = !0 } = {}) {
130
+ let { db: s, epoch: c, status: d, error: f } = y(), [p, m] = u({
131
+ rows: C,
132
+ fields: C,
133
+ error: null,
134
+ loading: !0
135
+ }), [h, g] = u(0), _ = l(0), v = a ? c : 0, b = S(t), x = l(t);
136
+ x.current = t;
137
+ let w = l([]);
138
+ o(() => {
139
+ if (!s || !r) return;
140
+ let t = ++_.current;
141
+ m((e) => e.loading ? e : {
142
+ ...e,
143
+ loading: !0
144
+ }), s.query(e, x.current ? [...x.current] : void 0).then((e) => {
145
+ t === _.current && m({
146
+ rows: e.rows,
147
+ fields: e.fields,
148
+ error: null,
149
+ loading: !1
150
+ });
151
+ }, (r) => {
152
+ t === _.current && m({
153
+ rows: C,
154
+ fields: C,
155
+ error: n(r, e),
156
+ loading: !1
157
+ });
158
+ }).finally(() => {
159
+ t === _.current && w.current.splice(0).forEach((e) => e());
160
+ });
161
+ }, [
162
+ s,
163
+ e,
164
+ b,
165
+ r,
166
+ h,
167
+ v
168
+ ]);
169
+ let T = i(() => new Promise((e) => {
170
+ w.current.push(e), g((e) => e + 1);
171
+ }), []), E = d === "error" && f ? n(f) : null;
172
+ return {
173
+ rows: p.rows,
174
+ fields: p.fields,
175
+ error: p.error ?? E,
176
+ isLoading: r && !E && (!s || p.loading),
177
+ refetch: T
178
+ };
179
+ }
180
+ function T(e, t, { key: r, enabled: i = !0 } = {}) {
181
+ let { db: a } = y(), [s, c] = u({
182
+ rows: C,
183
+ fields: C,
184
+ error: null,
185
+ isLoading: !0
186
+ }), d = S(t), f = l(t);
187
+ return f.current = t, o(() => {
188
+ if (!a || !i) return;
189
+ if (!a.live) {
190
+ c({
191
+ rows: C,
192
+ fields: C,
193
+ error: { message: "useLiveQuery needs the live extension: the provider was opened with live={false}." },
194
+ isLoading: !1
195
+ });
196
+ return;
197
+ }
198
+ let t = !1, o = f.current ? [...f.current] : void 0, s = (e) => {
199
+ t || c({
200
+ rows: e.rows,
201
+ fields: e.fields,
202
+ error: null,
203
+ isLoading: !1
204
+ });
205
+ }, l = g;
206
+ return (r ? a.live.incrementalQuery(e, o, r) : a.live.query(e, o)).then((e) => {
207
+ if (t) {
208
+ e.unsubscribe(s);
209
+ return;
210
+ }
211
+ s(e.initialResults), e.subscribe(s), l = () => void e.unsubscribe(s);
212
+ }, (r) => {
213
+ t || c({
214
+ rows: C,
215
+ fields: C,
216
+ error: n(r, e),
217
+ isLoading: !1
218
+ });
219
+ }), () => {
220
+ t = !0, l();
221
+ };
222
+ }, [
223
+ a,
224
+ e,
225
+ d,
226
+ r,
227
+ i
228
+ ]), s;
229
+ }
230
+ function E() {
231
+ let { db: e, invalidate: t } = y(), [r, a] = u({
232
+ isPending: !1,
233
+ error: null
234
+ }), o = i(async (r, i) => {
235
+ if (!e) throw Error("The database is not ready.");
236
+ a({
237
+ isPending: !0,
238
+ error: null
239
+ });
240
+ try {
241
+ let n = await i(e);
242
+ return t(), a({
243
+ isPending: !1,
244
+ error: null
245
+ }), n;
246
+ } catch (e) {
247
+ throw a({
248
+ isPending: !1,
249
+ error: n(e, r)
250
+ }), e;
251
+ }
252
+ }, [e, t]), s = i((e) => o(e, (t) => t.exec(e)), [o]), c = i((e, t) => o(e, (n) => n.query(e, t ? [...t] : void 0)), [o]), l = i(() => a({
253
+ isPending: !1,
254
+ error: null
255
+ }), []);
256
+ return {
257
+ exec: s,
258
+ run: c,
259
+ isPending: r.isPending,
260
+ error: r.error,
261
+ reset: l
262
+ };
263
+ }
264
+ function D() {
265
+ let { db: e, invalidate: t } = y(), [r, a] = u({
266
+ isPending: !1,
267
+ error: null
268
+ }), o = i(async (r) => {
269
+ if (!e) throw Error("The database is not ready.");
270
+ a({
271
+ isPending: !0,
272
+ error: null
273
+ });
274
+ try {
275
+ let n = await e.transaction(r);
276
+ return t(), a({
277
+ isPending: !1,
278
+ error: null
279
+ }), n;
280
+ } catch (e) {
281
+ throw a({
282
+ isPending: !1,
283
+ error: n(e)
284
+ }), e;
285
+ }
286
+ }, [e, t]), s = i(() => a({
287
+ isPending: !1,
288
+ error: null
289
+ }), []);
290
+ return {
291
+ transaction: o,
292
+ isPending: r.isPending,
293
+ error: r.error,
294
+ reset: s
295
+ };
296
+ }
297
+ //#endregion
298
+ export { v as PGliteProvider, y as useDatabaseStatus, E as useExec, T as useLiveQuery, b as usePGlite, w as useQuery, x as useReadyDatabase, D as useTransaction };
@@ -0,0 +1,24 @@
1
+ import { PointerEvent as ReactPointerEvent, RefObject } from 'react';
2
+ interface Options {
3
+ /** Called when a pull is released past the threshold. Return a promise to keep the spinner until it settles (it
4
+ * always shows for at least a moment). Pull-to-refresh is off without it. */
5
+ onRefresh?: () => void | Promise<unknown>;
6
+ /** The scroller the pull starts on (it must be at its top). */
7
+ scroller: RefObject<HTMLElement | null>;
8
+ /** The content that follows the finger. */
9
+ content: RefObject<HTMLElement | null>;
10
+ /** The spinner that fades in as the pull grows. */
11
+ spinner: RefObject<HTMLElement | null>;
12
+ }
13
+ export declare function usePullToRefresh({ onRefresh, scroller, content, spinner }: Options): {
14
+ refreshing: boolean;
15
+ /** Spread onto the scroller. */
16
+ bind: {
17
+ onPointerDown: (e: ReactPointerEvent) => void;
18
+ onPointerMove: (e: ReactPointerEvent) => void;
19
+ onPointerUp: () => void;
20
+ onPointerCancel: () => void;
21
+ };
22
+ };
23
+ export {};
24
+ //# sourceMappingURL=pull-to-refresh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pull-to-refresh.d.ts","sourceRoot":"","sources":["../../src/lib/pull-to-refresh.ts"],"names":[],"mappings":"AACA,OAAO,EAA+B,KAAK,YAAY,IAAI,iBAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAU5G,UAAU,OAAO;IACf;kFAC8E;IAC9E,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C,+DAA+D;IAC/D,QAAQ,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACxC,2CAA2C;IAC3C,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACvC,mDAAmD;IACnD,OAAO,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;CACxC;AAUD,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,OAAO;;IAwE/E,gCAAgC;;2BAzDjB,iBAAiB;2BAMjB,iBAAiB;;;;EAsDnC"}
@@ -0,0 +1,74 @@
1
+ "use client";
2
+ import { springCss as e } from "./motion.js";
3
+ import { useEffect as t, useRef as n, useState as r } from "react";
4
+ //#region src/lib/pull-to-refresh.ts
5
+ var i = 1100, a = 52, o = 54, s = (e) => typeof reportError == "function" ? reportError(e) : console.error(e);
6
+ function c({ onRefresh: c, scroller: l, content: u, spinner: d }) {
7
+ let f = n(null), [p, m] = r(!1), h = n(/* @__PURE__ */ new Set()), g = n(!0), _ = (e, t) => {
8
+ let n = setTimeout(() => {
9
+ h.current.delete(n), e();
10
+ }, t);
11
+ h.current.add(n);
12
+ };
13
+ t(() => {
14
+ g.current = !0;
15
+ let e = h.current;
16
+ return () => {
17
+ g.current = !1, e.forEach(clearTimeout), e.clear();
18
+ };
19
+ }, []);
20
+ let v = (e) => {
21
+ !c || p || e.button || (l.current?.scrollTop ?? 0) > 2 || (f.current = {
22
+ y0: e.clientY,
23
+ x0: e.clientX,
24
+ on: !1,
25
+ armed: !1
26
+ });
27
+ }, y = (e) => {
28
+ let t = f.current;
29
+ if (!t) return;
30
+ let n = e.clientY - t.y0, r = e.clientX - t.x0;
31
+ if (!t.on) {
32
+ if (n > 10 && n > Math.abs(r) * 1.3 && (l.current?.scrollTop ?? 0) <= 1) {
33
+ t.on = !0;
34
+ try {
35
+ l.current?.setPointerCapture(e.pointerId);
36
+ } catch {}
37
+ } else if (n < -6) {
38
+ f.current = null;
39
+ return;
40
+ } else return;
41
+ }
42
+ let i = Math.min(110, 56 * Math.log1p(Math.max(0, n - 10) / 40)), a = u.current, s = d.current;
43
+ a && (a.style.transition = "none", a.style.transform = `translateY(${i}px)`), s && (s.style.opacity = String(Math.min(1, i / 58)), s.style.transform = `translateX(-50%) rotate(${i * 3.2}deg) scale(${Math.min(1, .5 + i / 90)})`), t.armed = i > o;
44
+ }, b = () => {
45
+ let t = f.current;
46
+ if (!t || (f.current = null, !t.on)) return;
47
+ let n = u.current, r = d.current, o = (e) => _(() => {
48
+ n && (n.style.transition = "", n.style.transform = "");
49
+ }, e);
50
+ if (t.armed) {
51
+ m(!0), n && (n.style.transition = e("transform", "snappy"), n.style.transform = `translateY(${a}px)`), r && (r.style.opacity = "1", r.style.transform = "translateX(-50%)");
52
+ let t = new Promise((e) => _(e, i)), l = Promise.resolve();
53
+ try {
54
+ l = Promise.resolve(c?.());
55
+ } catch (e) {
56
+ s(e);
57
+ }
58
+ Promise.all([t, l.catch(s)]).then(() => {
59
+ g.current && (m(!1), n && (n.style.transition = e("transform", "smooth"), n.style.transform = "translateY(0)"), r && (r.style.opacity = "0"), o(560));
60
+ });
61
+ } else n && (n.style.transition = e("transform", "snappy"), n.style.transform = "translateY(0)", o(400)), r && (r.style.opacity = "0");
62
+ };
63
+ return {
64
+ refreshing: p,
65
+ bind: {
66
+ onPointerDown: v,
67
+ onPointerMove: y,
68
+ onPointerUp: b,
69
+ onPointerCancel: b
70
+ }
71
+ };
72
+ }
73
+ //#endregion
74
+ export { c as usePullToRefresh };
@@ -0,0 +1,6 @@
1
+ import { RefObject } from 'react';
2
+ /** Whether floating chrome (a TabBar, a floating sheet or chat) should hide: the shared chrome state says the
3
+ * bars are hidden, or `scrollRef` was scrolled down (it returns on scroll-up and at the top). Always false when
4
+ * `hideOnScroll` is off. */
5
+ export declare function useScrollHidden(hideOnScroll: boolean, scrollRef?: RefObject<HTMLElement | null>): boolean;
6
+ //# sourceMappingURL=scroll-hidden.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-hidden.d.ts","sourceRoot":"","sources":["../../src/lib/scroll-hidden.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAG5D;;6BAE6B;AAC7B,wBAAgB,eAAe,CAAC,YAAY,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,OAAO,CAsBzG"}
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { useChromeHidden as e } from "./theme.js";
3
+ import { useEffect as t, useState as n } from "react";
4
+ //#region src/lib/scroll-hidden.ts
5
+ function r(r, i) {
6
+ let a = e(), [o, s] = n(!1);
7
+ return t(() => {
8
+ let e = i?.current;
9
+ if (!e || !r) {
10
+ s(!1);
11
+ return;
12
+ }
13
+ let t = e.scrollTop, n = () => {
14
+ let n = e.scrollTop, r = n - t;
15
+ t = n, n < 4 ? s(!1) : r > 3 ? s(!0) : r < -3 && s(!1);
16
+ };
17
+ return e.addEventListener("scroll", n, { passive: !0 }), () => e.removeEventListener("scroll", n);
18
+ }, [i, r]), r && (a || o);
19
+ }
20
+ //#endregion
21
+ export { r as useScrollHidden };