@indietabletop/appkit 3.2.0 → 3.4.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.
- package/lib/client.ts +31 -0
- package/lib/globals.css.ts +11 -0
- package/lib/index.ts +1 -0
- package/lib/sleep.ts +14 -0
- package/package.json +1 -1
package/lib/client.ts
CHANGED
|
@@ -285,4 +285,35 @@ export class IndieTabletopClient {
|
|
|
285
285
|
|
|
286
286
|
return result;
|
|
287
287
|
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Uploads a file given S3 presigned config.
|
|
291
|
+
*/
|
|
292
|
+
async uploadFile(
|
|
293
|
+
file: File,
|
|
294
|
+
presigned: { url: string; key: string; fields: Record<string, string> },
|
|
295
|
+
): Promise<Success<string> | Failure<FailurePayload>> {
|
|
296
|
+
const formData = new FormData();
|
|
297
|
+
|
|
298
|
+
for (const [key, value] of Object.entries(presigned.fields)) {
|
|
299
|
+
formData.append(key, value);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
formData.append("file", file);
|
|
303
|
+
|
|
304
|
+
try {
|
|
305
|
+
const upload = await fetch(presigned.url, {
|
|
306
|
+
method: "POST",
|
|
307
|
+
body: formData,
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
if (!upload.ok) {
|
|
311
|
+
return new Failure({ type: "API_ERROR", code: upload.status });
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return new Success(`/${presigned.key}`);
|
|
315
|
+
} catch {
|
|
316
|
+
return new Failure({ type: "NETWORK_ERROR" });
|
|
317
|
+
}
|
|
318
|
+
}
|
|
288
319
|
}
|
package/lib/globals.css.ts
CHANGED
|
@@ -44,3 +44,14 @@ globalStyle("body, h1, h2, h3, h4, h5, h6, p, ul, li, ol", {
|
|
|
44
44
|
margin: 0,
|
|
45
45
|
padding: 0,
|
|
46
46
|
});
|
|
47
|
+
|
|
48
|
+
// Fathom SPA support depends on this image being added to the DOM, but they
|
|
49
|
+
// are sloppy about taking out of the document flow, meaning that on pages
|
|
50
|
+
// that are 100vh, there is a scrollbar flicker as the img element is added
|
|
51
|
+
// to the DOM and then removed. This fixes said issue.
|
|
52
|
+
globalStyle(`img[src^="https://cdn.usefathom.com/"]`, {
|
|
53
|
+
position: "absolute",
|
|
54
|
+
top: 0,
|
|
55
|
+
left: 0,
|
|
56
|
+
opacity: 0.01,
|
|
57
|
+
});
|
package/lib/index.ts
CHANGED
|
@@ -28,6 +28,7 @@ export * from "./client.ts";
|
|
|
28
28
|
export * from "./failureMessages.ts";
|
|
29
29
|
export * from "./media.ts";
|
|
30
30
|
export * from "./random.ts";
|
|
31
|
+
export * from "./sleep.ts";
|
|
31
32
|
export * from "./structs.ts";
|
|
32
33
|
export * from "./types.ts";
|
|
33
34
|
export * from "./validations.ts";
|
package/lib/sleep.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pause for the specified number of milliseconds.
|
|
3
|
+
*
|
|
4
|
+
* This function is useful for testing, or slowing down responses in cases
|
|
5
|
+
* where we want to wait for some short-lived cache to clear first.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* await sleep(2000) // Waits for 2s
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export function sleep(ms: number) {
|
|
13
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
14
|
+
}
|