@indietabletop/appkit 3.2.0-1 → 3.2.0-10
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/ExternalLink.tsx +10 -0
- package/lib/FormSubmitButton.tsx +58 -0
- package/lib/FullscreenDismissBlocker.tsx +23 -0
- package/lib/IndieTabletopClubLogo.tsx +44 -0
- package/lib/IndieTabletopClubSymbol.tsx +37 -0
- package/lib/Letterhead/index.tsx +85 -0
- package/lib/Letterhead/stories.tsx +45 -0
- package/lib/Letterhead/style.css.ts +141 -0
- package/lib/LetterheadForm/LetterheadReadonlyTextField.stories.tsx +21 -0
- package/lib/LetterheadForm/LetterheadSubmitError.stories.tsx +23 -0
- package/lib/LetterheadForm/LetterheadTextField.stories.tsx +23 -0
- package/lib/LetterheadForm/index.tsx +94 -0
- package/lib/LetterheadForm/style.css.ts +80 -0
- package/lib/LoadingIndicator.tsx +39 -0
- package/lib/ServiceWorkerHandler.tsx +53 -0
- package/lib/animations.css.ts +17 -0
- package/lib/append-copy-to-text.test.ts +29 -0
- package/lib/append-copy-to-text.ts +35 -0
- package/lib/async-op.ts +246 -0
- package/lib/atomic.css.ts +11 -0
- package/{dist/caught-value.js → lib/caught-value.ts} +10 -8
- package/lib/class-names.ts +33 -0
- package/lib/client.ts +288 -0
- package/lib/common.css.ts +48 -0
- package/lib/failureMessages.test.ts +138 -0
- package/lib/failureMessages.ts +76 -0
- package/lib/globals.css.ts +45 -0
- package/{dist/index.d.ts → lib/index.ts} +9 -1
- package/lib/internal.css.ts +10 -0
- package/lib/media.ts +50 -0
- package/lib/storybook/decorators.tsx +10 -0
- package/lib/structs.ts +17 -0
- package/{dist/types.d.ts → lib/types.ts} +11 -6
- package/lib/use-async-op.ts +16 -0
- package/lib/use-document-background-color.ts +16 -0
- package/lib/use-form.ts +73 -0
- package/{dist/use-is-installed.js → lib/use-is-installed.ts} +7 -3
- package/lib/use-media-query.ts +21 -0
- package/lib/use-reverting-state.ts +32 -0
- package/lib/use-scroll-restoration.ts +99 -0
- package/lib/validations.ts +25 -0
- package/lib/vars.css.ts +9 -0
- package/package.json +13 -6
- package/dist/ExternalLink.d.ts +0 -3
- package/dist/ExternalLink.js +0 -4
- package/dist/FormSubmitButton.d.ts +0 -7
- package/dist/FormSubmitButton.js +0 -16
- package/dist/FullscreenDismissBlocker.d.ts +0 -5
- package/dist/FullscreenDismissBlocker.js +0 -19
- package/dist/IndieTabletopClubLogo.d.ts +0 -7
- package/dist/IndieTabletopClubLogo.js +0 -6
- package/dist/IndieTabletopClubSymbol.d.ts +0 -7
- package/dist/IndieTabletopClubSymbol.js +0 -5
- package/dist/Letterhead.d.ts +0 -6
- package/dist/Letterhead.js +0 -14
- package/dist/LetterheadFooter.d.ts +0 -1
- package/dist/LetterheadFooter.js +0 -17
- package/dist/LoadingIndicator.d.ts +0 -3
- package/dist/LoadingIndicator.js +0 -17
- package/dist/ServiceWorkerHandler.d.ts +0 -11
- package/dist/ServiceWorkerHandler.js +0 -42
- package/dist/animations.css.d.ts +0 -3
- package/dist/animations.css.js +0 -14
- package/dist/append-copy-to-text.d.ts +0 -10
- package/dist/append-copy-to-text.js +0 -29
- package/dist/async-op.d.ts +0 -87
- package/dist/async-op.js +0 -223
- package/dist/caught-value.d.ts +0 -15
- package/dist/class-names.d.ts +0 -4
- package/dist/class-names.js +0 -6
- package/dist/client.d.ts +0 -117
- package/dist/client.js +0 -201
- package/dist/common.css.d.ts +0 -5
- package/dist/common.css.js +0 -38
- package/dist/globals.css.d.ts +0 -1
- package/dist/globals.css.js +0 -35
- package/dist/index.js +0 -25
- package/dist/internal.css.d.ts +0 -4
- package/dist/internal.css.js +0 -21
- package/dist/media.d.ts +0 -39
- package/dist/media.js +0 -49
- package/dist/structs.d.ts +0 -20
- package/dist/structs.js +0 -15
- package/dist/types.js +0 -1
- package/dist/use-async-op.d.ts +0 -6
- package/dist/use-async-op.js +0 -12
- package/dist/use-document-background-color.d.ts +0 -4
- package/dist/use-document-background-color.js +0 -14
- package/dist/use-form.d.ts +0 -29
- package/dist/use-form.js +0 -33
- package/dist/use-is-installed.d.ts +0 -8
- package/dist/use-media-query.d.ts +0 -1
- package/dist/use-media-query.js +0 -15
- package/dist/use-reverting-state.d.ts +0 -5
- package/dist/use-reverting-state.js +0 -26
- package/dist/use-scroll-restoration.d.ts +0 -25
- package/dist/use-scroll-restoration.js +0 -67
package/dist/client.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { Failure, Success } from "@indietabletop/appkit/async-op";
|
|
2
|
-
import { mask, object, string, Struct } from "superstruct";
|
|
3
|
-
import { currentUser, sessionInfo } from "./structs.js";
|
|
4
|
-
export class IndieTabletopClient {
|
|
5
|
-
constructor(props) {
|
|
6
|
-
Object.defineProperty(this, "origin", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
configurable: true,
|
|
9
|
-
writable: true,
|
|
10
|
-
value: void 0
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(this, "onCurrentUser", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: void 0
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(this, "onSessionInfo", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: void 0
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(this, "onSessionExpired", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: void 0
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(this, "refreshTokenPromise", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: void 0
|
|
35
|
-
});
|
|
36
|
-
this.origin = props.apiOrigin;
|
|
37
|
-
this.onCurrentUser = props.onCurrentUser;
|
|
38
|
-
this.onSessionInfo = props.onSessionInfo;
|
|
39
|
-
this.onSessionExpired = props.onSessionExpired;
|
|
40
|
-
}
|
|
41
|
-
async fetch(path, struct, init) {
|
|
42
|
-
// If json was provided, we stringify it. Otherwise we use body.
|
|
43
|
-
const body = init?.json ? JSON.stringify(init.json) : init?.body;
|
|
44
|
-
// If json was provided, we make sure that content type is correctly set.
|
|
45
|
-
const headers = init?.json
|
|
46
|
-
? { ...init?.headers, "Content-Type": "application/json" }
|
|
47
|
-
: init?.headers;
|
|
48
|
-
try {
|
|
49
|
-
const res = await fetch(`${this.origin}${path}`, {
|
|
50
|
-
// Defaults
|
|
51
|
-
credentials: "include",
|
|
52
|
-
// Overrides
|
|
53
|
-
...init,
|
|
54
|
-
body,
|
|
55
|
-
headers,
|
|
56
|
-
});
|
|
57
|
-
if (!res.ok) {
|
|
58
|
-
console.error(res);
|
|
59
|
-
return new Failure({ type: "API_ERROR", code: res.status });
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
const data = mask(await res.json(), struct);
|
|
63
|
-
return new Success(data);
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
console.error(error);
|
|
67
|
-
return new Failure({ type: "VALIDATION_ERROR" });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
console.error(error);
|
|
72
|
-
if (error instanceof Error) {
|
|
73
|
-
return new Failure({ type: "NETWORK_ERROR" });
|
|
74
|
-
}
|
|
75
|
-
return new Failure({ type: "UNKNOWN_ERROR" });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Fetches data and retries 401 failures after attempting to refresh tokens.
|
|
80
|
-
*/
|
|
81
|
-
async fetchWithAuth(path, struct, init) {
|
|
82
|
-
const op = await this.fetch(path, struct, init);
|
|
83
|
-
if (op.isSuccess) {
|
|
84
|
-
return op;
|
|
85
|
-
}
|
|
86
|
-
if (op.failure.type === "API_ERROR" && op.failure.code === 401) {
|
|
87
|
-
console.info("API request failed with error 401. Refreshing tokens.");
|
|
88
|
-
const refreshOp = await this.refreshTokens();
|
|
89
|
-
if (refreshOp.isSuccess) {
|
|
90
|
-
console.info("Tokens refreshed. Retrying request.");
|
|
91
|
-
return await this.fetch(path, struct, init);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
console.info("Could not refresh tokens.");
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return op;
|
|
98
|
-
}
|
|
99
|
-
async login(payload) {
|
|
100
|
-
const result = await this.fetch("/v1/sessions", object({
|
|
101
|
-
currentUser: currentUser(),
|
|
102
|
-
sessionInfo: sessionInfo(),
|
|
103
|
-
}), {
|
|
104
|
-
method: "POST",
|
|
105
|
-
json: { email: payload.email, plaintextPassword: payload.password },
|
|
106
|
-
});
|
|
107
|
-
if (result.isSuccess) {
|
|
108
|
-
this.onCurrentUser?.(result.value.currentUser);
|
|
109
|
-
this.onSessionInfo?.(result.value.sessionInfo);
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
|
-
async logout() {
|
|
114
|
-
return await this.fetch("/v1/sessions", object({ message: string() }), {
|
|
115
|
-
method: "DELETE",
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
async join(payload) {
|
|
119
|
-
const res = await this.fetch("/v1/users", object({
|
|
120
|
-
currentUser: currentUser(),
|
|
121
|
-
sessionInfo: sessionInfo(),
|
|
122
|
-
tokenId: string(),
|
|
123
|
-
}), {
|
|
124
|
-
method: "POST",
|
|
125
|
-
json: {
|
|
126
|
-
email: payload.email,
|
|
127
|
-
plaintextPassword: payload.password,
|
|
128
|
-
acceptedTos: payload.acceptedTos,
|
|
129
|
-
subscribedToNewsletter: payload.subscribedToNewsletter,
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
if (res.isSuccess) {
|
|
133
|
-
this.onCurrentUser?.(res.value.currentUser);
|
|
134
|
-
this.onSessionInfo?.(res.value.sessionInfo);
|
|
135
|
-
}
|
|
136
|
-
return res;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Triggers token refresh process.
|
|
140
|
-
*
|
|
141
|
-
* Note that we do not want to perform multiple concurrent token refresh
|
|
142
|
-
* actions, as that will result in unnecessary 401s. For this reason, a
|
|
143
|
-
* reference to t
|
|
144
|
-
*/
|
|
145
|
-
async refreshTokens() {
|
|
146
|
-
// If there is an ongoing token refresh in progress return that. This should
|
|
147
|
-
// only deal the response payload, none of the side-effects and cleanup,
|
|
148
|
-
// which will be handled by the initial invocation.
|
|
149
|
-
const ongoingRequest = this.refreshTokenPromise;
|
|
150
|
-
if (ongoingRequest) {
|
|
151
|
-
console.info("Token refresh ongoing. Reusing existing promise.");
|
|
152
|
-
return await ongoingRequest;
|
|
153
|
-
}
|
|
154
|
-
// Cache the promise on an instance property to share a reference from
|
|
155
|
-
// other potential invocations.
|
|
156
|
-
this.refreshTokenPromise = this.fetch("/v1/sessions/access-tokens", object({ sessionInfo: sessionInfo() }), { method: "POST" });
|
|
157
|
-
const result = await this.refreshTokenPromise;
|
|
158
|
-
if (result.isSuccess) {
|
|
159
|
-
this.onSessionInfo?.(result.value.sessionInfo);
|
|
160
|
-
}
|
|
161
|
-
if (result.isFailure &&
|
|
162
|
-
result.failure.type === "API_ERROR" &&
|
|
163
|
-
result.failure.code === 401) {
|
|
164
|
-
this.onSessionExpired?.();
|
|
165
|
-
}
|
|
166
|
-
// Make sure to reset the shared reference so that subsequent invocations
|
|
167
|
-
// once again initiate token refresh.
|
|
168
|
-
delete this.refreshTokenPromise;
|
|
169
|
-
return result;
|
|
170
|
-
}
|
|
171
|
-
async requestPasswordReset(payload) {
|
|
172
|
-
return await this.fetch(`/v1/password-reset-tokens`, object({ message: string(), tokenId: string() }), { method: "POST", json: payload });
|
|
173
|
-
}
|
|
174
|
-
async checkPasswordResetCode(payload) {
|
|
175
|
-
const queryParams = new URLSearchParams({ plaintextCode: payload.code });
|
|
176
|
-
return await this.fetch(`/v1/password-reset-tokens/${payload.tokenId}?${queryParams}`, object({ message: string() }), { method: "GET" });
|
|
177
|
-
}
|
|
178
|
-
async setNewPassword(payload) {
|
|
179
|
-
const queryParams = new URLSearchParams({ plaintextCode: payload.code });
|
|
180
|
-
return await this.fetch(`/v1/password-reset-tokens/${payload.tokenId}?${queryParams}`, object({ message: string() }), { method: "PUT", json: { plaintextPassword: payload.password } });
|
|
181
|
-
}
|
|
182
|
-
async requestUserVerification() {
|
|
183
|
-
return await this.fetch(`/v1/user-verification-tokens`, object({ message: string(), tokenId: string() }), { method: "POST" });
|
|
184
|
-
}
|
|
185
|
-
async verifyUser(payload) {
|
|
186
|
-
const queryParams = new URLSearchParams({ plaintextCode: payload.code });
|
|
187
|
-
const req = await this.fetch(`/v1/user-verification-tokens/${payload.tokenId}?${queryParams}`, object({ message: string() }), { method: "PUT" });
|
|
188
|
-
if (req.isSuccess) {
|
|
189
|
-
await this.refreshTokens();
|
|
190
|
-
await this.getCurrentUser();
|
|
191
|
-
}
|
|
192
|
-
return req;
|
|
193
|
-
}
|
|
194
|
-
async getCurrentUser() {
|
|
195
|
-
const result = await this.fetchWithAuth(`/v1/users/me`, currentUser());
|
|
196
|
-
if (result.isSuccess) {
|
|
197
|
-
this.onCurrentUser?.(result.value);
|
|
198
|
-
}
|
|
199
|
-
return result;
|
|
200
|
-
}
|
|
201
|
-
}
|
package/dist/common.css.d.ts
DELETED
package/dist/common.css.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { style } from "@vanilla-extract/css";
|
|
2
|
-
import { Hover, MinWidth } from "./media.js";
|
|
3
|
-
export const itcSymbol = style({
|
|
4
|
-
inlineSize: "2.5rem",
|
|
5
|
-
blockSize: "2.5rem",
|
|
6
|
-
margin: "0rem auto 0.75rem",
|
|
7
|
-
"@media": {
|
|
8
|
-
[MinWidth.MEDIUM]: {
|
|
9
|
-
marginBlock: "-1rem 1.5rem",
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
export const manofa = style({
|
|
14
|
-
fontFamily: `"manofa", sans-serif`,
|
|
15
|
-
});
|
|
16
|
-
export const minion = style({
|
|
17
|
-
fontFamily: `"minion-pro", serif`,
|
|
18
|
-
});
|
|
19
|
-
export const itcCard = style([
|
|
20
|
-
minion,
|
|
21
|
-
{
|
|
22
|
-
backgroundColor: "white",
|
|
23
|
-
},
|
|
24
|
-
]);
|
|
25
|
-
export const interactiveText = style({
|
|
26
|
-
display: "inline",
|
|
27
|
-
textDecoration: "underline",
|
|
28
|
-
textDecorationColor: "hsl(from currentcolor h s l / 0.3)",
|
|
29
|
-
textUnderlineOffset: "0.15em",
|
|
30
|
-
"@media": {
|
|
31
|
-
[Hover.HOVER]: {
|
|
32
|
-
transition: "text-decoration-color 200ms",
|
|
33
|
-
":hover": {
|
|
34
|
-
textDecorationColor: "hsl(from currentcolor h s l / 1)",
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
});
|
package/dist/globals.css.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/globals.css.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { globalStyle } from "@vanilla-extract/css";
|
|
2
|
-
globalStyle(":root", {
|
|
3
|
-
fontSynthesis: "none",
|
|
4
|
-
textRendering: "optimizeLegibility",
|
|
5
|
-
WebkitFontSmoothing: "antialiased",
|
|
6
|
-
MozOsxFontSmoothing: "grayscale",
|
|
7
|
-
});
|
|
8
|
-
globalStyle("*", {
|
|
9
|
-
boxSizing: "border-box",
|
|
10
|
-
});
|
|
11
|
-
globalStyle("img, picture, svg", {
|
|
12
|
-
display: "block",
|
|
13
|
-
});
|
|
14
|
-
globalStyle("a", {
|
|
15
|
-
display: "block",
|
|
16
|
-
color: "inherit",
|
|
17
|
-
textDecoration: "none",
|
|
18
|
-
});
|
|
19
|
-
globalStyle("input, textarea", {
|
|
20
|
-
fontFamily: "inherit",
|
|
21
|
-
});
|
|
22
|
-
globalStyle("button", {
|
|
23
|
-
display: "block",
|
|
24
|
-
fontSize: "inherit",
|
|
25
|
-
fontFamily: "inherit",
|
|
26
|
-
backgroundColor: "transparent",
|
|
27
|
-
border: "none",
|
|
28
|
-
color: "inherit",
|
|
29
|
-
cursor: "pointer",
|
|
30
|
-
padding: 0,
|
|
31
|
-
});
|
|
32
|
-
globalStyle("body, h1, h2, h3, h4, h5, h6, p, ul, li, ol", {
|
|
33
|
-
margin: 0,
|
|
34
|
-
padding: 0,
|
|
35
|
-
});
|
package/dist/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Components
|
|
2
|
-
export * from "./ExternalLink.js";
|
|
3
|
-
export * from "./FormSubmitButton.js";
|
|
4
|
-
export * from "./FullscreenDismissBlocker.js";
|
|
5
|
-
export * from "./IndieTabletopClubSymbol.js";
|
|
6
|
-
export * from "./LetterheadFooter.js";
|
|
7
|
-
export * from "./LoadingIndicator.js";
|
|
8
|
-
export * from "./ServiceWorkerHandler.js";
|
|
9
|
-
// Hooks
|
|
10
|
-
export * from "./use-async-op.js";
|
|
11
|
-
export * from "./use-document-background-color.js";
|
|
12
|
-
export * from "./use-form.js";
|
|
13
|
-
export * from "./use-is-installed.js";
|
|
14
|
-
export * from "./use-media-query.js";
|
|
15
|
-
export * from "./use-reverting-state.js";
|
|
16
|
-
export * from "./use-scroll-restoration.js";
|
|
17
|
-
// Utils
|
|
18
|
-
export * from "./append-copy-to-text.js";
|
|
19
|
-
export * from "./async-op.js";
|
|
20
|
-
export * from "./caught-value.js";
|
|
21
|
-
export * from "./class-names.js";
|
|
22
|
-
export * from "./client.js";
|
|
23
|
-
export * from "./media.js";
|
|
24
|
-
export * from "./structs.js";
|
|
25
|
-
export * from "./types.js";
|
package/dist/internal.css.d.ts
DELETED
package/dist/internal.css.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { createVar, style } from "@vanilla-extract/css";
|
|
2
|
-
import { bounce } from "./animations.css.js";
|
|
3
|
-
import { minion } from "./common.css.js";
|
|
4
|
-
export const animationDelay = createVar();
|
|
5
|
-
export const dot = style({
|
|
6
|
-
fill: "currentcolor",
|
|
7
|
-
opacity: 0.8,
|
|
8
|
-
animation: `${bounce} 2s ${animationDelay} infinite`,
|
|
9
|
-
});
|
|
10
|
-
export const padding = createVar();
|
|
11
|
-
export const letterhead = style([
|
|
12
|
-
minion,
|
|
13
|
-
{
|
|
14
|
-
vars: { [padding]: "clamp(1rem, 8vw, 4rem)" },
|
|
15
|
-
backgroundColor: "white",
|
|
16
|
-
padding: `max(1rem, calc(${padding} - .5rem)) ${padding} ${padding}`,
|
|
17
|
-
borderRadius: "1rem",
|
|
18
|
-
marginInline: "auto",
|
|
19
|
-
maxInlineSize: "36rem",
|
|
20
|
-
},
|
|
21
|
-
]);
|
package/dist/media.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
|
|
3
|
-
*/
|
|
4
|
-
export declare enum PrefersColorScheme {
|
|
5
|
-
LIGHT = "(prefers-color-scheme: light)",
|
|
6
|
-
DARK = "(prefers-color-scheme: dark)"
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion
|
|
10
|
-
*/
|
|
11
|
-
export declare enum PrefersReducedMotion {
|
|
12
|
-
NO_PREFERENCE = "(prefers-reduced-motion: no-preference)",
|
|
13
|
-
REDUCE = "(prefers-reduced-motion: reduce)"
|
|
14
|
-
}
|
|
15
|
-
export declare enum Hover {
|
|
16
|
-
NONE = "(hover: none)",
|
|
17
|
-
HOVER = "(hover: hover) and (pointer: fine)"
|
|
18
|
-
}
|
|
19
|
-
export declare enum MediaType {
|
|
20
|
-
PRINT = "print",
|
|
21
|
-
SCREEN = "screen"
|
|
22
|
-
}
|
|
23
|
-
export declare enum MinHeight {
|
|
24
|
-
TALL = "(min-height: 40em)"
|
|
25
|
-
}
|
|
26
|
-
export declare enum MinWidth {
|
|
27
|
-
SMALL = "(min-width: 28em)",
|
|
28
|
-
MEDIUM = "(min-width: 50em)",
|
|
29
|
-
WIDE = "(min-width: 66em)",
|
|
30
|
-
X_WIDE = "(min-width: 80em)",
|
|
31
|
-
XX_WIDE = "(min-width: 140em)"
|
|
32
|
-
}
|
|
33
|
-
export declare enum DisplayMode {
|
|
34
|
-
STANDALONE = "(display-mode: standalone)"
|
|
35
|
-
}
|
|
36
|
-
export declare enum Pointer {
|
|
37
|
-
COARSE = "(pointer: coarse)",
|
|
38
|
-
FINE = "(pointer: fine)"
|
|
39
|
-
}
|
package/dist/media.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
|
|
3
|
-
*/
|
|
4
|
-
export var PrefersColorScheme;
|
|
5
|
-
(function (PrefersColorScheme) {
|
|
6
|
-
PrefersColorScheme["LIGHT"] = "(prefers-color-scheme: light)";
|
|
7
|
-
PrefersColorScheme["DARK"] = "(prefers-color-scheme: dark)";
|
|
8
|
-
})(PrefersColorScheme || (PrefersColorScheme = {}));
|
|
9
|
-
/**
|
|
10
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion
|
|
11
|
-
*/
|
|
12
|
-
export var PrefersReducedMotion;
|
|
13
|
-
(function (PrefersReducedMotion) {
|
|
14
|
-
PrefersReducedMotion["NO_PREFERENCE"] = "(prefers-reduced-motion: no-preference)";
|
|
15
|
-
PrefersReducedMotion["REDUCE"] = "(prefers-reduced-motion: reduce)";
|
|
16
|
-
})(PrefersReducedMotion || (PrefersReducedMotion = {}));
|
|
17
|
-
export var Hover;
|
|
18
|
-
(function (Hover) {
|
|
19
|
-
Hover["NONE"] = "(hover: none)";
|
|
20
|
-
// Some Samsung phones incorrectly report that they have "hover" even though they
|
|
21
|
-
// do not. Adding the pointer query correctly filters these phones out.
|
|
22
|
-
Hover["HOVER"] = "(hover: hover) and (pointer: fine)";
|
|
23
|
-
})(Hover || (Hover = {}));
|
|
24
|
-
export var MediaType;
|
|
25
|
-
(function (MediaType) {
|
|
26
|
-
MediaType["PRINT"] = "print";
|
|
27
|
-
MediaType["SCREEN"] = "screen";
|
|
28
|
-
})(MediaType || (MediaType = {}));
|
|
29
|
-
export var MinHeight;
|
|
30
|
-
(function (MinHeight) {
|
|
31
|
-
MinHeight["TALL"] = "(min-height: 40em)";
|
|
32
|
-
})(MinHeight || (MinHeight = {}));
|
|
33
|
-
export var MinWidth;
|
|
34
|
-
(function (MinWidth) {
|
|
35
|
-
MinWidth["SMALL"] = "(min-width: 28em)";
|
|
36
|
-
MinWidth["MEDIUM"] = "(min-width: 50em)";
|
|
37
|
-
MinWidth["WIDE"] = "(min-width: 66em)";
|
|
38
|
-
MinWidth["X_WIDE"] = "(min-width: 80em)";
|
|
39
|
-
MinWidth["XX_WIDE"] = "(min-width: 140em)";
|
|
40
|
-
})(MinWidth || (MinWidth = {}));
|
|
41
|
-
export var DisplayMode;
|
|
42
|
-
(function (DisplayMode) {
|
|
43
|
-
DisplayMode["STANDALONE"] = "(display-mode: standalone)";
|
|
44
|
-
})(DisplayMode || (DisplayMode = {}));
|
|
45
|
-
export var Pointer;
|
|
46
|
-
(function (Pointer) {
|
|
47
|
-
Pointer["COARSE"] = "(pointer: coarse)";
|
|
48
|
-
Pointer["FINE"] = "(pointer: fine)";
|
|
49
|
-
})(Pointer || (Pointer = {}));
|
package/dist/structs.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare function currentUser(): import("superstruct").Struct<{
|
|
2
|
-
id: string;
|
|
3
|
-
email: string;
|
|
4
|
-
isVerified: boolean;
|
|
5
|
-
prefersScrollbarVisibility?: "ALWAYS" | undefined;
|
|
6
|
-
}, {
|
|
7
|
-
id: import("superstruct").Struct<string, null>;
|
|
8
|
-
email: import("superstruct").Struct<string, null>;
|
|
9
|
-
isVerified: import("superstruct").Struct<boolean, null>;
|
|
10
|
-
prefersScrollbarVisibility: import("superstruct").Struct<"ALWAYS" | undefined, {
|
|
11
|
-
ALWAYS: "ALWAYS";
|
|
12
|
-
}>;
|
|
13
|
-
}>;
|
|
14
|
-
export declare function sessionInfo(): import("superstruct").Struct<{
|
|
15
|
-
expiresTs: number;
|
|
16
|
-
createdTs: number;
|
|
17
|
-
}, {
|
|
18
|
-
expiresTs: import("superstruct").Struct<number, null>;
|
|
19
|
-
createdTs: import("superstruct").Struct<number, null>;
|
|
20
|
-
}>;
|
package/dist/structs.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { boolean, enums, number, object, optional, string } from "superstruct";
|
|
2
|
-
export function currentUser() {
|
|
3
|
-
return object({
|
|
4
|
-
id: string(),
|
|
5
|
-
email: string(),
|
|
6
|
-
isVerified: boolean(),
|
|
7
|
-
prefersScrollbarVisibility: optional(enums(["ALWAYS"])),
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
export function sessionInfo() {
|
|
11
|
-
return object({
|
|
12
|
-
expiresTs: number(),
|
|
13
|
-
createdTs: number(),
|
|
14
|
-
});
|
|
15
|
-
}
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import { currentUser, sessionInfo } from "./structs.js";
|
package/dist/use-async-op.d.ts
DELETED
package/dist/use-async-op.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState } from "react";
|
|
2
|
-
import { Failure, Pending, Success } from "./async-op.js";
|
|
3
|
-
export function useAsyncOp() {
|
|
4
|
-
const [op, setOp] = useState(new Pending());
|
|
5
|
-
const setSuccess = useCallback((value) => {
|
|
6
|
-
setOp(new Success(value));
|
|
7
|
-
}, []);
|
|
8
|
-
const setFailure = useCallback((failure) => {
|
|
9
|
-
setOp(new Failure(failure));
|
|
10
|
-
}, []);
|
|
11
|
-
return { op, setSuccess, setFailure };
|
|
12
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* Sets document background color, reverting it to previous color on unmount.
|
|
4
|
-
*/
|
|
5
|
-
export function useDocumentBackgroundColor(bodyColor) {
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
const style = window.document.documentElement.style;
|
|
8
|
-
const originalColor = style.backgroundColor;
|
|
9
|
-
style.backgroundColor = bodyColor;
|
|
10
|
-
return () => {
|
|
11
|
-
style.backgroundColor = originalColor;
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
}
|
package/dist/use-form.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type FormStoreState } from "@ariakit/react";
|
|
2
|
-
import { Failure, Success } from "@indietabletop/appkit/async-op";
|
|
3
|
-
type Validator<T> = (value: T) => string | null;
|
|
4
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
5
|
-
export declare function useForm<T extends object, R>(props: {
|
|
6
|
-
defaultValues: T;
|
|
7
|
-
validate?: {
|
|
8
|
-
[K in keyof T]?: Validator<T[K]>;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Handles form submission login.
|
|
12
|
-
*
|
|
13
|
-
* This function should return a Success or Failure. Failures should always contain a string
|
|
14
|
-
* which will be used as the form error message.
|
|
15
|
-
*/
|
|
16
|
-
onSubmit: (state: FormStoreState<T>) => MaybePromise<Success<R> | Failure<string>>;
|
|
17
|
-
/**
|
|
18
|
-
* If submission was successful (i.e. onSubmit returned a Success), will be run to perform any
|
|
19
|
-
* side-effect necessary.
|
|
20
|
-
*
|
|
21
|
-
* Typically this is used for navigation on mutating some local state.
|
|
22
|
-
*/
|
|
23
|
-
onSuccess?: (value: R, state: FormStoreState<T>) => MaybePromise<void>;
|
|
24
|
-
}): {
|
|
25
|
-
form: import("@ariakit/react").FormStore<T>;
|
|
26
|
-
submitName: string;
|
|
27
|
-
op: Success<R> | Failure<string> | null;
|
|
28
|
-
};
|
|
29
|
-
export {};
|
package/dist/use-form.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { useFormStore } from "@ariakit/react";
|
|
2
|
-
import { Failure, Success } from "@indietabletop/appkit/async-op";
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
export function useForm(props) {
|
|
5
|
-
const submitName = "submit";
|
|
6
|
-
const [op, setOp] = useState(null);
|
|
7
|
-
const form = useFormStore({
|
|
8
|
-
defaultValues: props.defaultValues,
|
|
9
|
-
});
|
|
10
|
-
form.useSubmit(async (state) => {
|
|
11
|
-
const submitOp = await props.onSubmit(state);
|
|
12
|
-
if (submitOp.isFailure) {
|
|
13
|
-
form.setError(submitName, submitOp.failure);
|
|
14
|
-
}
|
|
15
|
-
if (submitOp.isSuccess) {
|
|
16
|
-
await props.onSuccess?.(submitOp.value, state);
|
|
17
|
-
}
|
|
18
|
-
setOp(submitOp);
|
|
19
|
-
});
|
|
20
|
-
form.useValidate((state) => {
|
|
21
|
-
if (props.validate) {
|
|
22
|
-
const entries = Object.entries(props.validate);
|
|
23
|
-
for (const [key, validate] of entries) {
|
|
24
|
-
const value = state.values[key];
|
|
25
|
-
const message = validate(value);
|
|
26
|
-
if (message) {
|
|
27
|
-
form.setError(key, message);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
return { form, submitName, op };
|
|
33
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks whether the app is installed.
|
|
3
|
-
*
|
|
4
|
-
* Note that this doesn't check whether the app is installed on the device at
|
|
5
|
-
* all, only whether the currently running process is within an installed window
|
|
6
|
-
* or running within a browser.
|
|
7
|
-
*/
|
|
8
|
-
export declare function useIsInstalled(): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useMediaQuery(query: string): boolean;
|
package/dist/use-media-query.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from "react";
|
|
2
|
-
export function useMediaQuery(query) {
|
|
3
|
-
const [isMatch, setMatch] = useState(window.matchMedia(query).matches);
|
|
4
|
-
useEffect(() => {
|
|
5
|
-
const mql = window.matchMedia(query);
|
|
6
|
-
const handleChange = ({ matches }) => {
|
|
7
|
-
setMatch(matches);
|
|
8
|
-
};
|
|
9
|
-
mql.addEventListener("change", handleChange);
|
|
10
|
-
return () => {
|
|
11
|
-
mql.removeEventListener("change", handleChange);
|
|
12
|
-
};
|
|
13
|
-
}, [query]);
|
|
14
|
-
return isMatch;
|
|
15
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sets a state that will automatically revert to null after specified number
|
|
3
|
-
* of milliseconds.
|
|
4
|
-
*/
|
|
5
|
-
export declare function useRevertingState<T>(initialState: T, revertAfterMs: number): readonly [T | null, import("react").Dispatch<import("react").SetStateAction<T | null>>];
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* Sets a state that will automatically revert to null after specified number
|
|
4
|
-
* of milliseconds.
|
|
5
|
-
*/
|
|
6
|
-
export function useRevertingState(initialState, revertAfterMs) {
|
|
7
|
-
const [state, setState] = useState(initialState);
|
|
8
|
-
const timeoutRef = useRef(null);
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
const timeoutId = timeoutRef.current;
|
|
11
|
-
if (timeoutId) {
|
|
12
|
-
clearInterval(timeoutId);
|
|
13
|
-
}
|
|
14
|
-
if (state) {
|
|
15
|
-
timeoutRef.current = setTimeout(() => {
|
|
16
|
-
setState(null);
|
|
17
|
-
}, revertAfterMs);
|
|
18
|
-
}
|
|
19
|
-
return () => {
|
|
20
|
-
if (timeoutId) {
|
|
21
|
-
clearTimeout(timeoutId);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}, [revertAfterMs, state]);
|
|
25
|
-
return [state, setState];
|
|
26
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Handles scroll restoration on window.
|
|
3
|
-
*
|
|
4
|
-
* This hook behaves a little differently than the default browser scroll
|
|
5
|
-
* restoration. This is due to limitations of Wouter (our router of choice)
|
|
6
|
-
* as well the need to make the app feel more app-like.
|
|
7
|
-
*
|
|
8
|
-
* Every scroll position is remembered however the user has got to it (we
|
|
9
|
-
* don't differentiate between new entries in browser history and back
|
|
10
|
-
* navigation), but they are only restored if the user last visited the
|
|
11
|
-
* location less than 60 minutes ago.
|
|
12
|
-
*/
|
|
13
|
-
export declare function useScrollRestoration(
|
|
14
|
-
/**
|
|
15
|
-
* The current path, provided by your router of choice.
|
|
16
|
-
*/
|
|
17
|
-
pathname: string, options?: {
|
|
18
|
-
/**
|
|
19
|
-
* A list of paths where scroll restoration should never be performed.
|
|
20
|
-
*
|
|
21
|
-
* This list should have stable identity for optimal performance. Make
|
|
22
|
-
* sure to use `useMemo` or define the list in module scope.
|
|
23
|
-
*/
|
|
24
|
-
neverRestore?: string[];
|
|
25
|
-
}): void;
|