@indietabletop/appkit 7.0.0-0 → 7.0.0-rc.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/AppConfig/AppConfig.tsx +80 -0
- package/lib/AppConfig/formatters.tsx +43 -0
- package/lib/AuthCard/AuthCard.stories.ts +34 -0
- package/lib/AuthCard/AuthCard.tsx +64 -0
- package/lib/AuthCard/style.css.ts +49 -0
- package/lib/CacheProvider.tsx +20 -0
- package/lib/DialogTrigger/index.tsx +36 -0
- package/lib/DocumentTitle/DocumentTitle.tsx +10 -0
- package/lib/EnumMapper.ts +50 -0
- package/lib/ExternalLink.tsx +10 -0
- package/lib/FullscreenDismissBlocker.tsx +23 -0
- package/{dist/HistoryState.d.ts → lib/HistoryState.ts} +5 -2
- package/lib/IndieTabletopClubLogo.tsx +44 -0
- package/lib/IndieTabletopClubSymbol.tsx +37 -0
- package/lib/InfoPage/index.tsx +46 -0
- package/lib/InfoPage/pages.tsx +36 -0
- package/lib/InfoPage/style.css.ts +36 -0
- package/lib/Letterhead/index.tsx +85 -0
- package/lib/Letterhead/stories.tsx +41 -0
- package/lib/Letterhead/style.css.ts +152 -0
- package/lib/LetterheadForm/LetterheadReadonlyTextField.stories.tsx +17 -0
- package/lib/LetterheadForm/LetterheadSubmitError.stories.tsx +19 -0
- package/lib/LetterheadForm/LetterheadTextField.stories.tsx +19 -0
- package/lib/LetterheadForm/index.tsx +137 -0
- package/lib/LetterheadForm/style.css.ts +89 -0
- package/lib/LoadingIndicator.tsx +40 -0
- package/lib/MiddotSeparated/MiddotSeparated.stories.ts +26 -0
- package/lib/MiddotSeparated/MiddotSeparated.tsx +26 -0
- package/lib/MiddotSeparated/style.css.ts +10 -0
- package/lib/ModalDialog/index.tsx +28 -0
- package/lib/ModalDialog/style.css.ts +88 -0
- package/lib/ModernIDB/Cursor.ts +91 -0
- package/lib/ModernIDB/ModernIDB.ts +337 -0
- package/lib/ModernIDB/ModernIDBError.ts +9 -0
- package/lib/ModernIDB/ObjectStore.ts +195 -0
- package/lib/ModernIDB/ObjectStoreIndex.ts +102 -0
- package/lib/ModernIDB/README.md +9 -0
- package/lib/ModernIDB/Transaction.ts +40 -0
- package/lib/ModernIDB/VersionChangeManager.ts +57 -0
- package/lib/ModernIDB/bindings/factory.tsx +165 -0
- package/lib/ModernIDB/bindings/index.ts +2 -0
- package/{dist/ModernIDB/bindings/types.d.ts → lib/ModernIDB/bindings/types.ts} +32 -13
- package/lib/ModernIDB/bindings/utils.tsx +32 -0
- package/lib/ModernIDB/index.ts +10 -0
- package/lib/ModernIDB/types.ts +120 -0
- package/lib/ModernIDB/utils.ts +51 -0
- package/lib/QRCode/QRCode.stories.tsx +41 -0
- package/lib/QRCode/QRCode.tsx +54 -0
- package/lib/QRCode/style.css.ts +23 -0
- package/lib/ReleaseInfo/index.tsx +29 -0
- package/lib/RulesetResolver.ts +214 -0
- package/lib/SafariCheck/SafariCheck.stories.tsx +99 -0
- package/lib/SafariCheck/SafariCheck.tsx +273 -0
- package/lib/SafariCheck/addToDock.svg +13 -0
- package/lib/SafariCheck/addToHomeScreen.svg +12 -0
- package/lib/SafariCheck/safari.svg +32 -0
- package/lib/SafariCheck/shareIcon.svg +11 -0
- package/lib/SafariCheck/style.css.ts +106 -0
- package/lib/ServiceWorkerHandler.tsx +53 -0
- package/lib/ShareButton/ShareButton.stories.tsx +58 -0
- package/lib/ShareButton/ShareButton.tsx +153 -0
- package/lib/ShareButton/test.css.ts +3 -0
- package/lib/SubscribeCard/LetterheadInfoCard.tsx +23 -0
- package/lib/SubscribeCard/SubscribeByEmailCard.stories.tsx +69 -0
- package/lib/SubscribeCard/SubscribeByEmailCard.tsx +183 -0
- package/lib/SubscribeCard/SubscribeByPledgeCard.stories.tsx +133 -0
- package/lib/SubscribeCard/SubscribeByPledgeCard.tsx +127 -0
- package/lib/SubscribeCard/style.css.ts +14 -0
- package/lib/Sync/SyncIcon.stories.tsx +67 -0
- package/lib/Sync/SyncIcon.tsx +102 -0
- package/lib/Sync/SyncLog.tsx +222 -0
- package/lib/Sync/SyncLogList.stories.tsx +219 -0
- package/lib/Sync/style.css.ts +126 -0
- package/lib/account/AccountIcon.tsx +15 -0
- package/lib/account/AccountIssueView.tsx +44 -0
- package/lib/account/AlreadyLoggedInView.tsx +47 -0
- package/lib/account/CurrentUserFetcher.stories.tsx +292 -0
- package/lib/account/CurrentUserFetcher.tsx +118 -0
- package/lib/account/FailureFallbackView.tsx +36 -0
- package/lib/account/JoinCard.stories.tsx +257 -0
- package/lib/account/JoinCard.tsx +301 -0
- package/lib/account/LoadingView.tsx +14 -0
- package/lib/account/LoginCard.stories.tsx +288 -0
- package/lib/account/LoginCard.tsx +100 -0
- package/lib/account/LoginView.tsx +151 -0
- package/lib/account/NoConnectionView.tsx +34 -0
- package/lib/account/PasswordResetCard.stories.tsx +242 -0
- package/lib/account/PasswordResetCard.tsx +296 -0
- package/lib/account/UserMismatchView.tsx +62 -0
- package/lib/account/VerifyPage.tsx +195 -0
- package/lib/account/iconMask.svg +3 -0
- package/lib/account/style.css.ts +81 -0
- package/{dist/account/types.d.ts → lib/account/types.ts} +6 -3
- package/lib/account/useFetchCurrentUser.tsx +63 -0
- package/lib/account/useRedirectPath.ts +21 -0
- package/lib/animations.css.ts +17 -0
- package/lib/append-copy-to-text.ts +35 -0
- package/lib/async-op.ts +286 -0
- package/lib/atomic.css.ts +11 -0
- package/{dist/caught-value.d.ts → lib/caught-value.ts} +11 -1
- package/{dist/class-names.d.ts → lib/class-names.ts} +17 -6
- package/lib/client.ts +662 -0
- package/lib/common.css.ts +48 -0
- package/lib/copyrightRange.ts +10 -0
- package/lib/createSafeStorage.ts +91 -0
- package/lib/createStrictContext.ts +15 -0
- package/lib/failureMessages.ts +108 -0
- package/lib/form/FormSubmitButton.tsx +58 -0
- package/lib/form/SubmitErrorAlert.tsx +21 -0
- package/lib/form/style.css.ts +9 -0
- package/lib/globals.css.ts +62 -0
- package/lib/groupBy.ts +25 -0
- package/lib/hrefs.ts +48 -0
- package/lib/idToDate.ts +8 -0
- package/lib/ids.ts +6 -0
- package/lib/index.ts +75 -0
- package/lib/internal.css.ts +10 -0
- package/lib/mailto.ts +40 -0
- package/lib/media.ts +50 -0
- package/lib/random.ts +19 -0
- package/lib/result/swr.ts +18 -0
- package/{dist/sleep.d.ts → lib/sleep.ts} +3 -1
- package/lib/store/index.tsx +294 -0
- package/lib/store/store.ts +482 -0
- package/lib/store/types.ts +45 -0
- package/lib/store/utils.ts +54 -0
- package/lib/storybook/decorators.tsx +10 -0
- package/lib/structs.ts +3 -0
- package/{dist/typeguards.d.ts → lib/typeguards.ts} +3 -1
- package/{dist/types.d.ts → lib/types.ts} +23 -12
- package/lib/unique.ts +24 -0
- package/lib/use-async-op.ts +16 -0
- package/lib/use-document-background-color.ts +16 -0
- package/lib/use-form.ts +78 -0
- package/lib/use-is-installed.ts +17 -0
- 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/useEnsureValue.ts +31 -0
- package/lib/useInvokeClient.ts +54 -0
- package/lib/useIsVisible.ts +27 -0
- package/lib/utm.ts +92 -0
- package/lib/validations.ts +25 -0
- package/lib/vars.css.ts +13 -0
- package/package.json +23 -29
- package/dist/AppConfig/AppConfig.d.ts +0 -29
- package/dist/AuthCard/AuthCard.d.ts +0 -10
- package/dist/AuthCard/AuthCard.stories.d.ts +0 -34
- package/dist/AuthCard/style.css.d.ts +0 -23
- package/dist/DialogTrigger/index.d.ts +0 -13
- package/dist/DocumentTitle/DocumentTitle.d.ts +0 -3
- package/dist/EnumMapper.d.ts +0 -25
- package/dist/ExternalLink.d.ts +0 -3
- package/dist/FullscreenDismissBlocker.d.ts +0 -5
- package/dist/IndieTabletopClubLogo.d.ts +0 -7
- package/dist/IndieTabletopClubSymbol.d.ts +0 -7
- package/dist/InfoPage/index.d.ts +0 -8
- package/dist/InfoPage/pages.d.ts +0 -2
- package/dist/InfoPage/style.css.d.ts +0 -5
- package/dist/Letterhead/index.d.ts +0 -19
- package/dist/Letterhead/stories.d.ts +0 -13
- package/dist/Letterhead/style.css.d.ts +0 -46
- package/dist/LetterheadForm/LetterheadReadonlyTextField.stories.d.ts +0 -17
- package/dist/LetterheadForm/LetterheadSubmitError.stories.d.ts +0 -11
- package/dist/LetterheadForm/LetterheadTextField.stories.d.ts +0 -336
- package/dist/LetterheadForm/index.d.ts +0 -44
- package/dist/LetterheadForm/style.css.d.ts +0 -8
- package/dist/LoadingIndicator.d.ts +0 -3
- package/dist/MiddotSeparated/MiddotSeparated.d.ts +0 -8
- package/dist/MiddotSeparated/MiddotSeparated.stories.d.ts +0 -586
- package/dist/MiddotSeparated/style.css.d.ts +0 -1
- package/dist/ModalDialog/index.d.ts +0 -12
- package/dist/ModalDialog/style.css.d.ts +0 -58
- package/dist/ModernIDB/Cursor.d.ts +0 -56
- package/dist/ModernIDB/ModernIDB.d.ts +0 -66
- package/dist/ModernIDB/ModernIDBError.d.ts +0 -3
- package/dist/ModernIDB/ObjectStore.d.ts +0 -112
- package/dist/ModernIDB/ObjectStoreIndex.d.ts +0 -53
- package/dist/ModernIDB/Transaction.d.ts +0 -16
- package/dist/ModernIDB/VersionChangeManager.d.ts +0 -30
- package/dist/ModernIDB/bindings/factory.d.ts +0 -12
- package/dist/ModernIDB/bindings/index.d.ts +0 -2
- package/dist/ModernIDB/bindings/utils.d.ts +0 -2
- package/dist/ModernIDB/index.d.ts +0 -10
- package/dist/ModernIDB/types.d.ts +0 -88
- package/dist/ModernIDB/utils.d.ts +0 -4
- package/dist/QRCode/QRCode.d.ts +0 -7
- package/dist/QRCode/QRCode.stories.d.ts +0 -33
- package/dist/QRCode/style.css.d.ts +0 -4
- package/dist/ReleaseInfo/index.d.ts +0 -5
- package/dist/RulesetResolver.d.ts +0 -87
- package/dist/SafariCheck/SafariCheck.d.ts +0 -23
- package/dist/SafariCheck/SafariCheck.stories.d.ts +0 -73
- package/dist/SafariCheck/style.css.d.ts +0 -17
- package/dist/ServiceWorkerHandler.d.ts +0 -11
- package/dist/ShareButton/ShareButton.d.ts +0 -57
- package/dist/ShareButton/ShareButton.stories.d.ts +0 -1577
- package/dist/ShareButton/test.css.d.ts +0 -1
- package/dist/SubscribeCard/LetterheadInfoCard.d.ts +0 -2
- package/dist/SubscribeCard/SubscribeByEmailCard.d.ts +0 -24
- package/dist/SubscribeCard/SubscribeByEmailCard.stories.d.ts +0 -10
- package/dist/SubscribeCard/SubscribeByPledgeCard.d.ts +0 -36
- package/dist/SubscribeCard/SubscribeByPledgeCard.stories.d.ts +0 -65
- package/dist/SubscribeCard/style.css.d.ts +0 -4
- package/dist/account/AccountIssueView.d.ts +0 -3
- package/dist/account/AlreadyLoggedInView.d.ts +0 -5
- package/dist/account/CurrentUserFetcher.d.ts +0 -20
- package/dist/account/CurrentUserFetcher.stories.d.ts +0 -136
- package/dist/account/FailureFallbackView.d.ts +0 -1
- package/dist/account/JoinCard.d.ts +0 -14
- package/dist/account/JoinCard.stories.d.ts +0 -143
- package/dist/account/LoadingView.d.ts +0 -1
- package/dist/account/LoginCard.d.ts +0 -39
- package/dist/account/LoginCard.stories.d.ts +0 -217
- package/dist/account/LoginView.d.ts +0 -10
- package/dist/account/NoConnectionView.d.ts +0 -4
- package/dist/account/PasswordResetCard.d.ts +0 -15
- package/dist/account/PasswordResetCard.stories.d.ts +0 -128
- package/dist/account/UserMismatchView.d.ts +0 -6
- package/dist/account/VerifyPage.d.ts +0 -13
- package/dist/account/style.css.d.ts +0 -10
- package/dist/account/useFetchCurrentUser.d.ts +0 -28
- package/dist/account/useRedirectPath.d.ts +0 -6
- package/dist/animations.css.d.ts +0 -3
- package/dist/append-copy-to-text.d.ts +0 -10
- package/dist/append-copy-to-text.test.d.ts +0 -1
- package/dist/appkit.css +0 -1
- package/dist/appkit.js +0 -10692
- package/dist/async-op.d.ts +0 -101
- package/dist/atomic.css.d.ts +0 -6
- package/dist/client.d.ts +0 -424
- package/dist/common.css.d.ts +0 -5
- package/dist/copyrightRange.d.ts +0 -1
- package/dist/copyrightRange.test.d.ts +0 -1
- package/dist/createSafeStorage.d.ts +0 -34
- package/dist/failureMessages.d.ts +0 -20
- package/dist/failureMessages.test.d.ts +0 -1
- package/dist/form/FormSubmitButton.d.ts +0 -17
- package/dist/form/SubmitErrorAlert.d.ts +0 -5
- package/dist/form/style.css.d.ts +0 -3
- package/dist/globals.css.d.ts +0 -0
- package/dist/groupBy.d.ts +0 -1
- package/dist/groupBy.test.d.ts +0 -1
- package/dist/hrefs.d.ts +0 -32
- package/dist/hrefs.test.d.ts +0 -1
- package/dist/idToDate.d.ts +0 -5
- package/dist/idToDate.test.d.ts +0 -1
- package/dist/ids.d.ts +0 -1
- package/dist/ids.test.d.ts +0 -1
- package/dist/index.d.ts +0 -64
- package/dist/internal.css.d.ts +0 -2
- package/dist/mailto.d.ts +0 -8
- package/dist/mailto.test.d.ts +0 -1
- package/dist/media.d.ts +0 -39
- package/dist/random.d.ts +0 -3
- package/dist/result/swr.d.ts +0 -4
- package/dist/store/index.d.ts +0 -237
- package/dist/store/store.d.ts +0 -144
- package/dist/store/types.d.ts +0 -49
- package/dist/store/utils.d.ts +0 -10
- package/dist/storybook/decorators.d.ts +0 -3
- package/dist/structs.d.ts +0 -1
- package/dist/typeguards.test.d.ts +0 -1
- package/dist/unique.d.ts +0 -10
- package/dist/unique.test.d.ts +0 -1
- package/dist/use-async-op.d.ts +0 -6
- package/dist/use-document-background-color.d.ts +0 -4
- package/dist/use-form.d.ts +0 -29
- package/dist/use-is-installed.d.ts +0 -8
- package/dist/use-media-query.d.ts +0 -1
- package/dist/use-reverting-state.d.ts +0 -5
- package/dist/use-scroll-restoration.d.ts +0 -25
- package/dist/useEnsureValue.d.ts +0 -6
- package/dist/useInvokeClient.d.ts +0 -25
- package/dist/useIsVisible.d.ts +0 -4
- package/dist/utm.d.ts +0 -58
- package/dist/utm.test.d.ts +0 -1
- package/dist/validations.d.ts +0 -3
- package/dist/vars.css.d.ts +0 -10
package/lib/async-op.ts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
type Falsy = null | undefined | false | 0 | 0n | "";
|
|
2
|
+
|
|
3
|
+
type Truthy<T> = Exclude<T, Falsy>;
|
|
4
|
+
|
|
5
|
+
interface Operation<SuccessValue, FailureValue> {
|
|
6
|
+
readonly type: "SUCCESS" | "FAILURE" | "PENDING";
|
|
7
|
+
readonly isPending: boolean;
|
|
8
|
+
readonly isSuccess: boolean;
|
|
9
|
+
readonly isFailure: boolean;
|
|
10
|
+
|
|
11
|
+
val: SuccessValue | FailureValue | null;
|
|
12
|
+
|
|
13
|
+
valueOrNull(): SuccessValue | null;
|
|
14
|
+
valueOrThrow(): SuccessValue;
|
|
15
|
+
hasTruthyValue(): boolean;
|
|
16
|
+
failureValueOrNull(): FailureValue | null;
|
|
17
|
+
failureValueOrThrow(): FailureValue;
|
|
18
|
+
|
|
19
|
+
flatMap<T extends AsyncOp<unknown, unknown>>(
|
|
20
|
+
mappingFn: (value: SuccessValue) => T,
|
|
21
|
+
): T | Failure<FailureValue> | Pending;
|
|
22
|
+
|
|
23
|
+
mapSuccess<MappedSuccess>(
|
|
24
|
+
mappingFn: (value: SuccessValue) => MappedSuccess,
|
|
25
|
+
): Operation<MappedSuccess, FailureValue>;
|
|
26
|
+
|
|
27
|
+
mapFailure<MappedFailure>(
|
|
28
|
+
mappingFn: (value: FailureValue) => MappedFailure,
|
|
29
|
+
): Operation<SuccessValue, MappedFailure>;
|
|
30
|
+
|
|
31
|
+
unpack<S, F, P>(
|
|
32
|
+
mapS: (value: SuccessValue) => S,
|
|
33
|
+
mapF: (failure: FailureValue) => F,
|
|
34
|
+
mapP: () => P,
|
|
35
|
+
): S | F | P;
|
|
36
|
+
|
|
37
|
+
toJSON(): object;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class Pending implements Operation<never, never> {
|
|
41
|
+
readonly type = "PENDING" as const;
|
|
42
|
+
readonly isPending = true as const;
|
|
43
|
+
readonly isSuccess = false as const;
|
|
44
|
+
readonly isFailure = false as const;
|
|
45
|
+
|
|
46
|
+
val = null;
|
|
47
|
+
|
|
48
|
+
valueOrNull(): null {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
valueOrThrow(): never {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`AsyncOp value was accessed but the op is in Pending state.`,
|
|
55
|
+
{ cause: this },
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
hasTruthyValue(): false {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
failureValueOrNull(): null {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
failureValueOrThrow(): never {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`AsyncOp failure value was accessed but the op is in Pending state.`,
|
|
70
|
+
{ cause: this },
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
flatMap() {
|
|
75
|
+
return new Pending();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
mapSuccess() {
|
|
79
|
+
return new Pending();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
mapFailure() {
|
|
83
|
+
return new Pending();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
unpack<S, F, P>(
|
|
87
|
+
_mapS: (value: never) => S,
|
|
88
|
+
_mapF: (failure: never) => F,
|
|
89
|
+
mapP: () => P,
|
|
90
|
+
): S | F | P {
|
|
91
|
+
return mapP();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
toJSON() {
|
|
95
|
+
return { type: this.type };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export class Success<SuccessValue> implements Operation<SuccessValue, never> {
|
|
100
|
+
readonly type = "SUCCESS" as const;
|
|
101
|
+
readonly isPending = false as const;
|
|
102
|
+
readonly isSuccess = true as const;
|
|
103
|
+
readonly isFailure = false as const;
|
|
104
|
+
readonly value: SuccessValue;
|
|
105
|
+
readonly val: SuccessValue;
|
|
106
|
+
|
|
107
|
+
constructor(value: SuccessValue) {
|
|
108
|
+
this.value = value;
|
|
109
|
+
this.val = value;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
valueOrNull(): SuccessValue {
|
|
113
|
+
return this.value;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
valueOrThrow(): SuccessValue {
|
|
117
|
+
return this.value;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
hasTruthyValue(): this is Success<Truthy<SuccessValue>> {
|
|
121
|
+
return !!this.value;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
failureValueOrNull(): null {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
failureValueOrThrow(): never {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`AsyncOp failure value was accessed but the op is in Success state.`,
|
|
131
|
+
{ cause: this },
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
flatMap<T extends AsyncOp<unknown, unknown>>(
|
|
136
|
+
mappingFn: (value: SuccessValue) => T,
|
|
137
|
+
) {
|
|
138
|
+
return mappingFn(this.value);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
mapSuccess<MappedValue>(mappingFn: (value: SuccessValue) => MappedValue) {
|
|
142
|
+
return new Success(mappingFn(this.value));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
mapFailure() {
|
|
146
|
+
return new Success(this.value);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
unpack<S, F, P>(
|
|
150
|
+
mapS: (value: SuccessValue) => S,
|
|
151
|
+
_mapF: (failure: never) => F,
|
|
152
|
+
_mapP: () => P,
|
|
153
|
+
): S | F | P {
|
|
154
|
+
return mapS(this.value);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
toJSON() {
|
|
158
|
+
return {
|
|
159
|
+
type: this.type,
|
|
160
|
+
value: this.value,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export class Failure<FailureValue> implements Operation<never, FailureValue> {
|
|
166
|
+
readonly type = "FAILURE" as const;
|
|
167
|
+
readonly isPending = false as const;
|
|
168
|
+
readonly isSuccess = false as const;
|
|
169
|
+
readonly isFailure = true as const;
|
|
170
|
+
readonly failure: FailureValue;
|
|
171
|
+
readonly val: FailureValue;
|
|
172
|
+
|
|
173
|
+
constructor(failure: FailureValue) {
|
|
174
|
+
this.failure = failure;
|
|
175
|
+
this.val = failure;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
valueOrNull(): null {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
valueOrThrow(): never {
|
|
183
|
+
throw new Error(
|
|
184
|
+
`AsyncOp value was accessed but the op is in Failure state.`,
|
|
185
|
+
{ cause: this },
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
hasTruthyValue(): false {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
failureValueOrNull(): FailureValue {
|
|
194
|
+
return this.failure;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
failureValueOrThrow(): FailureValue {
|
|
198
|
+
return this.failure;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
flatMap() {
|
|
202
|
+
return new Failure(this.failure);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
mapSuccess() {
|
|
206
|
+
return new Failure(this.failure);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
mapFailure<MappedFailure>(mappingFn: (value: FailureValue) => MappedFailure) {
|
|
210
|
+
return new Failure(mappingFn(this.failure));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
unpack<S, F, P>(
|
|
214
|
+
_mapS: (value: never) => S,
|
|
215
|
+
mapF: (failure: FailureValue) => F,
|
|
216
|
+
_mapP: () => P,
|
|
217
|
+
): S | F | P {
|
|
218
|
+
return mapF(this.failure);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
toJSON() {
|
|
222
|
+
return {
|
|
223
|
+
type: this.type,
|
|
224
|
+
failure: this.failure,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Folds multiple ops into a single op.
|
|
231
|
+
*
|
|
232
|
+
* To return a Success, all ops provided must be a Success. If any Failures are
|
|
233
|
+
* encountered, will return the first one found.
|
|
234
|
+
*
|
|
235
|
+
* If neither of these conditions is true, will return Pending.
|
|
236
|
+
*
|
|
237
|
+
* Note that if passed an empty array, will always return a Success (with an
|
|
238
|
+
* empty array as value). This mimics the semantics of many JS constructs, like
|
|
239
|
+
* Promise.all or Array.prototype.every.
|
|
240
|
+
*/
|
|
241
|
+
export function fold<Ops extends readonly AsyncOp<unknown, unknown>[] | []>(
|
|
242
|
+
ops: Ops,
|
|
243
|
+
): AsyncOp<
|
|
244
|
+
{
|
|
245
|
+
-readonly [Index in keyof Ops]: Ops[Index] extends AsyncOp<infer S, unknown>
|
|
246
|
+
? S
|
|
247
|
+
: never;
|
|
248
|
+
},
|
|
249
|
+
Ops[number] extends AsyncOp<unknown, infer F> ? F : never
|
|
250
|
+
> {
|
|
251
|
+
// Note that due to the semantics of `every`, if the array provided to `fold`
|
|
252
|
+
// is empty, the result will be a Success with an empty array.
|
|
253
|
+
if (ops.every((v) => v.isSuccess)) {
|
|
254
|
+
return new Success(
|
|
255
|
+
(ops as Success<unknown>[]).map((op) => op.value),
|
|
256
|
+
) as never;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const firstFail = ops.find((op) => op.isFailure);
|
|
260
|
+
if (firstFail) {
|
|
261
|
+
return firstFail as never;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return new Pending() as never;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function isAsyncOp(value: unknown): value is AsyncOp<unknown, unknown> {
|
|
268
|
+
return (
|
|
269
|
+
value instanceof Pending ||
|
|
270
|
+
value instanceof Success ||
|
|
271
|
+
value instanceof Failure
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export type AsyncOp<SuccessValue, FailureValue> =
|
|
276
|
+
| Pending
|
|
277
|
+
| Success<SuccessValue>
|
|
278
|
+
| Failure<FailureValue>;
|
|
279
|
+
|
|
280
|
+
export function fromTryCatch<T>(callback: () => T) {
|
|
281
|
+
try {
|
|
282
|
+
return new Success(callback());
|
|
283
|
+
} catch (cause) {
|
|
284
|
+
return new Failure(cause);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createSprinkles, defineProperties } from "@vanilla-extract/sprinkles";
|
|
2
|
+
|
|
3
|
+
const atomic = defineProperties({
|
|
4
|
+
properties: {
|
|
5
|
+
textAlign: ["start", "center", "end"],
|
|
6
|
+
},
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const textVariants = createSprinkles(atomic);
|
|
10
|
+
|
|
11
|
+
export type TextVariants = Parameters<typeof textVariants>[0];
|
|
@@ -12,4 +12,14 @@
|
|
|
12
12
|
* if so, returns its message. If a string was caught, it returns that.
|
|
13
13
|
* Otherwise, it returns "Unknown error".
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export function caughtValueToString(value: unknown): string {
|
|
16
|
+
if (value instanceof Error) {
|
|
17
|
+
return value.message;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof value === "string") {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return "Unknown error.";
|
|
25
|
+
}
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
type Falsy = false | null | undefined;
|
|
2
|
+
|
|
2
3
|
type PropsWithClassName = {
|
|
3
|
-
|
|
4
|
+
className?: ClassName;
|
|
4
5
|
};
|
|
6
|
+
|
|
5
7
|
type ClassName = string | PropsWithClassName | Falsy;
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
10
|
* Combines a list of strings or objects with className property into a single
|
|
8
11
|
* string. Falsy values are ignored.
|
|
9
12
|
*/
|
|
10
|
-
export
|
|
13
|
+
export function classNames(...classNames: ClassName[]) {
|
|
14
|
+
return classNames
|
|
15
|
+
.filter((cn) => !!cn)
|
|
16
|
+
.map((cn) => (typeof cn === "object" ? cn?.className : cn))
|
|
17
|
+
.join(" ");
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
/**
|
|
12
21
|
* Given a list of strings or objects with the className property, returns an
|
|
13
22
|
* object with className property and combined className. Falsy values will
|
|
@@ -16,7 +25,9 @@ export declare function classNames(...classNames: ClassName[]): string;
|
|
|
16
25
|
* @example
|
|
17
26
|
* <h1 {...cx(props, 'heading', 'bold')}>Hello world!</h1>
|
|
18
27
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
|
|
29
|
+
export function cx(...cns: ClassName[]) {
|
|
30
|
+
return {
|
|
31
|
+
className: classNames(...cns),
|
|
32
|
+
};
|
|
33
|
+
}
|