@jwcarman/roux-web 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/README.md +21 -2
- package/dist/api/client.d.ts +17 -0
- package/dist/api/client.js +57 -0
- package/dist/api/config.d.ts +11 -0
- package/dist/api/config.js +15 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +4 -0
- package/dist/api/serverAction.d.ts +23 -0
- package/dist/api/serverAction.js +28 -0
- package/dist/feedback/ConfirmProvider.d.ts +21 -0
- package/dist/feedback/ConfirmProvider.js +50 -0
- package/dist/feedback/ErrorMessage.d.ts +7 -0
- package/dist/feedback/ErrorMessage.js +11 -0
- package/dist/feedback/index.d.ts +4 -0
- package/dist/feedback/index.js +5 -0
- package/dist/feedback/notify.d.ts +16 -0
- package/dist/feedback/notify.js +27 -0
- package/dist/feedback/toaster.d.ts +7 -0
- package/dist/feedback/toaster.js +29 -0
- package/dist/form/FormDialog.d.ts +34 -0
- package/dist/form/FormDialog.js +36 -0
- package/dist/form/errors.d.ts +8 -0
- package/dist/form/errors.js +17 -0
- package/dist/form/fields/CheckboxField.d.ts +4 -0
- package/dist/form/fields/CheckboxField.js +25 -0
- package/dist/form/fields/FormField.d.ts +20 -0
- package/dist/form/fields/FormField.js +24 -0
- package/dist/form/fields/InputField.d.ts +5 -0
- package/dist/form/fields/InputField.js +21 -0
- package/dist/form/fields/NumberField.d.ts +10 -0
- package/dist/form/fields/NumberField.js +26 -0
- package/dist/form/fields/RadioGroupField.d.ts +8 -0
- package/dist/form/fields/RadioGroupField.js +33 -0
- package/dist/form/fields/SelectField.d.ts +12 -0
- package/dist/form/fields/SelectField.js +25 -0
- package/dist/form/fields/TextAreaField.d.ts +5 -0
- package/dist/form/fields/TextAreaField.js +21 -0
- package/dist/form/fields/formComponents.d.ts +18 -0
- package/dist/form/fields/formComponents.js +50 -0
- package/dist/form/form.d.ts +73 -0
- package/dist/form/form.js +54 -0
- package/dist/form/formContext.d.ts +2 -0
- package/dist/form/formContext.js +4 -0
- package/dist/form/index.d.ts +13 -0
- package/dist/form/index.js +14 -0
- package/dist/form/values.d.ts +20 -0
- package/dist/form/values.js +24 -0
- package/dist/paging/index.d.ts +1 -0
- package/dist/paging/index.js +1 -0
- package/dist/paging/paging.d.ts +80 -0
- package/dist/paging/paging.js +71 -0
- package/dist/problem/index.d.ts +1 -0
- package/dist/problem/index.js +1 -0
- package/dist/problem/problem.d.ts +22 -0
- package/dist/problem/problem.js +24 -0
- package/dist/table/FilterChips.d.ts +16 -0
- package/dist/table/FilterChips.js +28 -0
- package/dist/table/QueryTable.d.ts +11 -0
- package/dist/table/QueryTable.js +29 -0
- package/dist/table/SimpleQueryTable.d.ts +17 -0
- package/dist/table/SimpleQueryTable.js +37 -0
- package/dist/table/TablePageSizeSelect.d.ts +9 -0
- package/dist/table/TablePageSizeSelect.js +35 -0
- package/dist/table/TablePagination.d.ts +5 -0
- package/dist/table/TablePagination.js +65 -0
- package/dist/table/TableStatus.d.ts +6 -0
- package/dist/table/TableStatus.js +27 -0
- package/dist/table/TableView.d.ts +7 -0
- package/dist/table/TableView.js +31 -0
- package/dist/table/TanstackTable.d.ts +16 -0
- package/dist/table/TanstackTable.js +61 -0
- package/dist/table/index.d.ts +11 -0
- package/dist/table/index.js +12 -0
- package/dist/table/selectColumn.d.ts +17 -0
- package/dist/table/selectColumn.js +36 -0
- package/dist/table/useDebounce.d.ts +2 -0
- package/dist/table/useDebounce.js +10 -0
- package/dist/table/useQueryTable.d.ts +49 -0
- package/dist/table/useQueryTable.js +127 -0
- package/package.json +85 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 James Carman
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @jwcarman/roux-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The web half of [roux](https://github.com/jwcarman/roux): the React plumbing a roux application needs, written
|
|
4
|
+
once. It is ESM-only and has one subpath per concern.
|
|
5
|
+
|
|
6
|
+
## Subpaths
|
|
7
|
+
|
|
8
|
+
- `@jwcarman/roux-web/problem`: types and helpers for RFC 9457 Problem Details.
|
|
9
|
+
- `@jwcarman/roux-web/api`: the API client, server actions, and error notification.
|
|
10
|
+
- `@jwcarman/roux-web/paging`: paging types and helpers.
|
|
11
|
+
- `@jwcarman/roux-web/table`: a TanStack Table wrapper driven by a query.
|
|
12
|
+
- `@jwcarman/roux-web/feedback`: toasts, confirmation dialogs and error messages.
|
|
13
|
+
- `@jwcarman/roux-web/form`: TanStack Form fields and dialogs.
|
|
14
|
+
|
|
15
|
+
## Peer dependencies
|
|
16
|
+
|
|
17
|
+
The app supplies `@chakra-ui/react`, `@emotion/react`, `@tanstack/react-form`, `@tanstack/react-query`,
|
|
18
|
+
`@tanstack/react-table`, `react` and `react-icons`.
|
|
19
|
+
|
|
20
|
+
See the [repository README](https://github.com/jwcarman/roux#readme) for the Java modules and how to use roux.
|
|
21
|
+
|
|
22
|
+
Licensed under the Apache License 2.0.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Problem } from "../problem/problem";
|
|
2
|
+
export declare class ApiError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
readonly problem: Problem;
|
|
5
|
+
constructor(status: number, problem?: Problem);
|
|
6
|
+
}
|
|
7
|
+
/** True when the error is an API call that failed because the session is gone. */
|
|
8
|
+
export declare function isSessionLost(error: unknown): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Calls the listener whenever an `/api/**` call (under the configured `sessionPathPrefix`) answers 401: the session expired, was signed out
|
|
11
|
+
* elsewhere, or lost the credential it signed in with. The session provider listens and refreshes,
|
|
12
|
+
* which sends the user to sign in; pages need not handle it. Returns the unsubscribe function.
|
|
13
|
+
*/
|
|
14
|
+
export declare function onSessionLost(listener: () => void): () => void;
|
|
15
|
+
export declare function get(path: string): Promise<Response>;
|
|
16
|
+
export declare function send(method: "POST" | "PUT" | "DELETE", path: string, body?: unknown): Promise<Response>;
|
|
17
|
+
export declare function getJson<T>(path: string): Promise<T>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { problemOf as e } from "../problem/problem.js";
|
|
2
|
+
import { apiSettings as t } from "./config.js";
|
|
3
|
+
// src/api/client.ts
|
|
4
|
+
var n = class extends Error {
|
|
5
|
+
status;
|
|
6
|
+
problem;
|
|
7
|
+
constructor(e, t = {
|
|
8
|
+
type: "about:blank",
|
|
9
|
+
title: "",
|
|
10
|
+
status: e
|
|
11
|
+
}) {
|
|
12
|
+
super(t.detail ?? `Request failed with status ${e}`), this.status = e, this.problem = t;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
function r(e) {
|
|
16
|
+
return e instanceof n && e.status === 401;
|
|
17
|
+
}
|
|
18
|
+
var i = /* @__PURE__ */ new Set();
|
|
19
|
+
function a(e) {
|
|
20
|
+
return i.add(e), () => i.delete(e);
|
|
21
|
+
}
|
|
22
|
+
function o(e, n) {
|
|
23
|
+
return n.status === 401 && e.startsWith(t().sessionPathPrefix) && i.forEach((e) => e()), n;
|
|
24
|
+
}
|
|
25
|
+
function s() {
|
|
26
|
+
let e = document.cookie.split("; ").find((e) => e.startsWith("XSRF-TOKEN="));
|
|
27
|
+
return e === void 0 ? void 0 : decodeURIComponent(e.slice(11));
|
|
28
|
+
}
|
|
29
|
+
async function c() {
|
|
30
|
+
s() === void 0 && await fetch(t().csrfBootstrapPath, { credentials: "same-origin" });
|
|
31
|
+
let e = s();
|
|
32
|
+
return e === void 0 ? {} : { "X-XSRF-TOKEN": e };
|
|
33
|
+
}
|
|
34
|
+
async function l(e) {
|
|
35
|
+
return o(e, await fetch(e, {
|
|
36
|
+
credentials: "same-origin",
|
|
37
|
+
headers: { Accept: "application/json" }
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
async function u(e, t, n) {
|
|
41
|
+
let r = {
|
|
42
|
+
Accept: "application/json",
|
|
43
|
+
...await c()
|
|
44
|
+
};
|
|
45
|
+
return n !== void 0 && (r["Content-Type"] = "application/json"), o(t, await fetch(t, {
|
|
46
|
+
method: e,
|
|
47
|
+
credentials: "same-origin",
|
|
48
|
+
headers: r,
|
|
49
|
+
body: JSON.stringify(n)
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
async function d(t) {
|
|
53
|
+
let r = await l(t);
|
|
54
|
+
if (!r.ok) throw new n(r.status, await e(r));
|
|
55
|
+
return await r.json();
|
|
56
|
+
}
|
|
57
|
+
export { n as ApiError, l as get, d as getJson, r as isSessionLost, a as onSessionLost, u as send };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Where the API client finds the CSRF token and which paths' 401s mean the session is lost. */
|
|
2
|
+
export interface ApiSettings {
|
|
3
|
+
/** What the client calls, before its first write, to get the CSRF cookie. */
|
|
4
|
+
csrfBootstrapPath: string;
|
|
5
|
+
/** The paths whose 401 means the session is lost. */
|
|
6
|
+
sessionPathPrefix: string;
|
|
7
|
+
}
|
|
8
|
+
/** Changes the settings named in `settings`, keeping the others. */
|
|
9
|
+
export declare function configureApi(settings: Partial<ApiSettings>): void;
|
|
10
|
+
/** The settings in force: who's paths (`/who/me` and `/api/`) unless {@link configureApi} changed them. */
|
|
11
|
+
export declare function apiSettings(): ApiSettings;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ApiError as e, get as t, getJson as n, isSessionLost as r, onSessionLost as i, send as a } from "./client.js";
|
|
2
|
+
import { apiSettings as o, configureApi as s } from "./config.js";
|
|
3
|
+
import { useServerAction as c } from "./serverAction.js";
|
|
4
|
+
export { e as ApiError, o as apiSettings, s as configureApi, t as get, n as getJson, r as isSessionLost, i as onSessionLost, a as send, c as useServerAction };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type QueryKey } from "@tanstack/react-query";
|
|
2
|
+
export interface ServerActionOptions<Variables> {
|
|
3
|
+
/** Sends the request, such as `(skill) => send("POST", `/api/skills/${skill.id}/archive`)`. */
|
|
4
|
+
request: (variables: Variables) => Promise<Response>;
|
|
5
|
+
/** What the user reads when the server gives no reason, such as `Could not archive Oi-zuki`. */
|
|
6
|
+
failure: (variables: Variables) => string;
|
|
7
|
+
/** The queries to refresh once the request is answered, refused or not: a refusal often means the page is out of date. */
|
|
8
|
+
refreshes?: (variables: Variables) => QueryKey[];
|
|
9
|
+
/** Runs once the request succeeds, before the refresh: a success toast, closing a dialog. */
|
|
10
|
+
onSuccess?: (response: Response, variables: Variables) => void | Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export interface ServerAction<Variables> {
|
|
13
|
+
/** Sends the request; true when it succeeded. A refusal has already been shown to the user. */
|
|
14
|
+
run: (variables: Variables) => Promise<boolean>;
|
|
15
|
+
/** Whether a request is out, for a button's loading state. */
|
|
16
|
+
pending: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* One request that changes something, as a TanStack Query mutation. A refusal tells the user the
|
|
20
|
+
* server's reason (its Problem Detail), or `failure` when it gave none; either way the queries
|
|
21
|
+
* named by `refreshes` are refreshed. For a form's submission, use `showProblem` instead.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useServerAction<Variables = void>(options: ServerActionOptions<Variables>): ServerAction<Variables>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ApiError as e } from "./client.js";
|
|
2
|
+
import { notify as t } from "../feedback/notify.js";
|
|
3
|
+
import { problemOf as n } from "../problem/problem.js";
|
|
4
|
+
import { useMutation as r, useQueryClient as i } from "@tanstack/react-query";
|
|
5
|
+
// src/api/serverAction.ts
|
|
6
|
+
function a(a) {
|
|
7
|
+
let o = i(), s = r({
|
|
8
|
+
mutationFn: async (t) => {
|
|
9
|
+
let r = await a.request(t);
|
|
10
|
+
if (!r.ok) throw new e(r.status, await n(r));
|
|
11
|
+
return r;
|
|
12
|
+
},
|
|
13
|
+
onSuccess: (e, t) => a.onSuccess?.(e, t),
|
|
14
|
+
onError: (n, r) => {
|
|
15
|
+
let i = a.failure(r);
|
|
16
|
+
n instanceof e ? t.problem(n.problem, i) : t.error(i);
|
|
17
|
+
},
|
|
18
|
+
onSettled: async (e, t, n) => {
|
|
19
|
+
let r = a.refreshes?.(n) ?? [];
|
|
20
|
+
await Promise.all(r.map((e) => o.invalidateQueries({ queryKey: e })));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
run: (e) => s.mutateAsync(e).then(() => !0, () => !1),
|
|
25
|
+
pending: s.isPending
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export { a as useServerAction };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface ConfirmOptions {
|
|
3
|
+
title: string;
|
|
4
|
+
message: string;
|
|
5
|
+
/** The confirming button's label: the action, such as "Deactivate". */
|
|
6
|
+
confirmLabel: string;
|
|
7
|
+
/** Colors the confirming button as a destructive action. */
|
|
8
|
+
destructive?: boolean;
|
|
9
|
+
}
|
|
10
|
+
type Confirm = (options: ConfirmOptions) => Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Asks before an action with consequences: `if (await confirm({...})) deactivate()`. Resolves true
|
|
13
|
+
* when confirmed, false on Cancel, Escape or closing. Cancel has focus first, so Enter alone never
|
|
14
|
+
* confirms.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useConfirm(): Confirm;
|
|
17
|
+
/** The app's one confirmation dialog, for `useConfirm`. */
|
|
18
|
+
export declare function ConfirmProvider({ children }: {
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
}): import("react").JSX.Element;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Button as e, CloseButton as t, Dialog as n, Portal as r } from "@chakra-ui/react";
|
|
2
|
+
import { jsx as i, jsxs as a } from "react/jsx-runtime";
|
|
3
|
+
import { createContext as o, useContext as s, useRef as c, useState as l } from "react";
|
|
4
|
+
// src/feedback/ConfirmProvider.tsx
|
|
5
|
+
var u = "red", d = o(null);
|
|
6
|
+
function f() {
|
|
7
|
+
let e = s(d);
|
|
8
|
+
if (e === null) throw Error("useConfirm outside ConfirmProvider");
|
|
9
|
+
return e;
|
|
10
|
+
}
|
|
11
|
+
function p({ children: o }) {
|
|
12
|
+
let [s, f] = l(null), p = c(null), [m] = l(() => (e) => new Promise((t) => f({
|
|
13
|
+
options: e,
|
|
14
|
+
resolve: t
|
|
15
|
+
})));
|
|
16
|
+
function h(e) {
|
|
17
|
+
s?.resolve(e), f(null);
|
|
18
|
+
}
|
|
19
|
+
return /* @__PURE__ */ a(d, {
|
|
20
|
+
value: m,
|
|
21
|
+
children: [o, /* @__PURE__ */ i(n.Root, {
|
|
22
|
+
role: "alertdialog",
|
|
23
|
+
open: s !== null,
|
|
24
|
+
onOpenChange: () => h(!1),
|
|
25
|
+
initialFocusEl: () => p.current,
|
|
26
|
+
children: /* @__PURE__ */ a(r, { children: [/* @__PURE__ */ i(n.Backdrop, {}), /* @__PURE__ */ i(n.Positioner, { children: /* @__PURE__ */ a(n.Content, { children: [
|
|
27
|
+
/* @__PURE__ */ i(n.Header, { children: /* @__PURE__ */ i(n.Title, { children: s?.options.title }) }),
|
|
28
|
+
/* @__PURE__ */ i(n.Body, { children: s?.options.message }),
|
|
29
|
+
/* @__PURE__ */ a(n.Footer, { children: [/* @__PURE__ */ i(e, {
|
|
30
|
+
ref: p,
|
|
31
|
+
variant: "outline",
|
|
32
|
+
onClick: () => h(!1),
|
|
33
|
+
children: "Cancel"
|
|
34
|
+
}), /* @__PURE__ */ i(e, {
|
|
35
|
+
colorPalette: s?.options.destructive ? u : void 0,
|
|
36
|
+
onClick: () => h(!0),
|
|
37
|
+
children: s?.options.confirmLabel
|
|
38
|
+
})] }),
|
|
39
|
+
/* @__PURE__ */ i(n.CloseTrigger, {
|
|
40
|
+
asChild: !0,
|
|
41
|
+
children: /* @__PURE__ */ i(t, {
|
|
42
|
+
size: "sm",
|
|
43
|
+
"aria-label": "Close"
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
] }) })] })
|
|
47
|
+
})]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export { p as ConfirmProvider, f as useConfirm };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface ErrorMessageProps {
|
|
3
|
+
title?: string;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
/** An error alert (`role="alert"`), announced when it appears. */
|
|
7
|
+
export declare function ErrorMessage({ title, children }: ErrorMessageProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Alert as e } from "@chakra-ui/react";
|
|
2
|
+
import { jsx as t, jsxs as n } from "react/jsx-runtime";
|
|
3
|
+
// src/feedback/ErrorMessage.tsx
|
|
4
|
+
function r({ title: r, children: i }) {
|
|
5
|
+
return /* @__PURE__ */ n(e.Root, {
|
|
6
|
+
status: "error",
|
|
7
|
+
role: "alert",
|
|
8
|
+
children: [/* @__PURE__ */ t(e.Indicator, {}), /* @__PURE__ */ n(e.Content, { children: [r && /* @__PURE__ */ t(e.Title, { children: r }), /* @__PURE__ */ t(e.Description, { children: i })] })]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export { r as ErrorMessage };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ConfirmProvider as e, useConfirm as t } from "./ConfirmProvider.js";
|
|
2
|
+
import { ErrorMessage as n } from "./ErrorMessage.js";
|
|
3
|
+
import { notify as r } from "./notify.js";
|
|
4
|
+
import { Toaster as i, toaster as a } from "./toaster.js";
|
|
5
|
+
export { e as ConfirmProvider, n as ErrorMessage, i as Toaster, r as notify, a as toaster, t as useConfirm };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Problem } from "../problem";
|
|
2
|
+
/**
|
|
3
|
+
* Tells the user how an action went: `notify.success("Invitation sent")`,
|
|
4
|
+
* `notify.error("Couldn't save", detail)`. For the outcome of an action; a field's mistake stays under
|
|
5
|
+
* the field.
|
|
6
|
+
*/
|
|
7
|
+
export declare const notify: {
|
|
8
|
+
/** `action` adds a button to the toast, such as Undo. */
|
|
9
|
+
success(title: string, action?: {
|
|
10
|
+
label: string;
|
|
11
|
+
onClick: () => void;
|
|
12
|
+
}): void;
|
|
13
|
+
error(title: string, detail?: string): void;
|
|
14
|
+
/** A failed request: the problem's detail, or `fallback`; a server error adds its reference. */
|
|
15
|
+
problem(problem: Problem, fallback: string): void;
|
|
16
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { toaster as e } from "./toaster.js";
|
|
2
|
+
// src/feedback/notify.ts
|
|
3
|
+
var t = {
|
|
4
|
+
success(t, n) {
|
|
5
|
+
e.create({
|
|
6
|
+
type: "success",
|
|
7
|
+
title: t,
|
|
8
|
+
action: n
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
error(t, n) {
|
|
12
|
+
e.create({
|
|
13
|
+
type: "error",
|
|
14
|
+
title: t,
|
|
15
|
+
description: n
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
problem(t, n) {
|
|
19
|
+
let r = t.errorId === void 0 ? void 0 : `Reference: ${t.errorId}`;
|
|
20
|
+
e.create({
|
|
21
|
+
type: "error",
|
|
22
|
+
title: t.detail ?? n,
|
|
23
|
+
description: r
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export { t as notify };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The app's one toaster; show toasts through `notify`, not this directly. */
|
|
2
|
+
export declare const toaster: import("@ark-ui/react").CreateToasterReturn<import("react").ReactNode>;
|
|
3
|
+
/**
|
|
4
|
+
* Where toasts appear, mounted once beside the app. A failure is an alert, announced at once; any
|
|
5
|
+
* other toast is a status, announced when the reader is idle.
|
|
6
|
+
*/
|
|
7
|
+
export declare function Toaster(): import("react").JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Portal as e, Stack as t, Toast as n, Toaster as r, createToaster as i } from "@chakra-ui/react";
|
|
2
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
3
|
+
// src/feedback/toaster.tsx
|
|
4
|
+
var s = i({
|
|
5
|
+
placement: "bottom-end",
|
|
6
|
+
pauseOnPageIdle: !0
|
|
7
|
+
});
|
|
8
|
+
function c() {
|
|
9
|
+
return /* @__PURE__ */ a(e, { children: /* @__PURE__ */ a(r, {
|
|
10
|
+
toaster: s,
|
|
11
|
+
insetInline: { mdDown: "4" },
|
|
12
|
+
children: (e) => /* @__PURE__ */ o(n.Root, {
|
|
13
|
+
width: { md: "sm" },
|
|
14
|
+
role: e.type === "error" ? "alert" : "status",
|
|
15
|
+
children: [
|
|
16
|
+
/* @__PURE__ */ a(n.Indicator, {}),
|
|
17
|
+
/* @__PURE__ */ o(t, {
|
|
18
|
+
gap: "1",
|
|
19
|
+
flex: "1",
|
|
20
|
+
maxWidth: "100%",
|
|
21
|
+
children: [e.title && /* @__PURE__ */ a(n.Title, { children: e.title }), e.description && /* @__PURE__ */ a(n.Description, { children: e.description })]
|
|
22
|
+
}),
|
|
23
|
+
e.action && /* @__PURE__ */ a(n.ActionTrigger, { children: e.action.label }),
|
|
24
|
+
/* @__PURE__ */ a(n.CloseTrigger, {})
|
|
25
|
+
]
|
|
26
|
+
})
|
|
27
|
+
}) });
|
|
28
|
+
}
|
|
29
|
+
export { c as Toaster, s as toaster };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ComponentType, type ReactElement, type ReactNode } from "react";
|
|
2
|
+
/** What FormDialog needs of a `useAppForm` form. */
|
|
3
|
+
interface DialogForm {
|
|
4
|
+
AppForm: ComponentType<{
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}>;
|
|
7
|
+
Form: ComponentType<{
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}>;
|
|
10
|
+
SubmitButton: ComponentType<{
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
}>;
|
|
13
|
+
reset: () => void;
|
|
14
|
+
}
|
|
15
|
+
export interface FormDialogProps {
|
|
16
|
+
/** The caller's `useAppForm` form; its `onSubmit` saves, and closes the dialog on success. */
|
|
17
|
+
form: DialogForm;
|
|
18
|
+
title: string;
|
|
19
|
+
/** The button that opens the dialog; focus returns to it when the dialog closes. */
|
|
20
|
+
trigger: ReactElement;
|
|
21
|
+
submitLabel: string;
|
|
22
|
+
open: boolean;
|
|
23
|
+
onOpenChange: (open: boolean) => void;
|
|
24
|
+
/** The form's fields. */
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A form in a dialog: create or edit something without leaving the page. The submit button sits in
|
|
29
|
+
* the footer beside Cancel; Escape, Cancel and the close button close it; it opens empty each time.
|
|
30
|
+
* Errors stay in the open dialog; the caller closes it when the save succeeds, as the last step of
|
|
31
|
+
* `onSubmit`: the form is still submitting (its button disabled) until `onSubmit` returns.
|
|
32
|
+
*/
|
|
33
|
+
export declare function FormDialog({ form, title, trigger, submitLabel, open, onOpenChange, children }: FormDialogProps): import("react").JSX.Element;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Button as e, CloseButton as t, Dialog as n, Portal as r, Stack as i } from "@chakra-ui/react";
|
|
2
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect as s } from "react";
|
|
4
|
+
// src/form/FormDialog.tsx
|
|
5
|
+
function c({ form: c, title: l, trigger: u, submitLabel: d, open: f, onOpenChange: p, children: m }) {
|
|
6
|
+
return s(() => {
|
|
7
|
+
f || c.reset();
|
|
8
|
+
}, [f, c]), /* @__PURE__ */ o(n.Root, {
|
|
9
|
+
open: f,
|
|
10
|
+
onOpenChange: (e) => p(e.open),
|
|
11
|
+
children: [/* @__PURE__ */ a(n.Trigger, {
|
|
12
|
+
asChild: !0,
|
|
13
|
+
children: u
|
|
14
|
+
}), /* @__PURE__ */ o(r, { children: [/* @__PURE__ */ a(n.Backdrop, {}), /* @__PURE__ */ a(n.Positioner, { children: /* @__PURE__ */ o(n.Content, { children: [/* @__PURE__ */ a(c.AppForm, { children: /* @__PURE__ */ o(c.Form, { children: [
|
|
15
|
+
/* @__PURE__ */ a(n.Header, { children: /* @__PURE__ */ a(n.Title, { children: l }) }),
|
|
16
|
+
/* @__PURE__ */ a(n.Body, { children: /* @__PURE__ */ a(i, {
|
|
17
|
+
gap: "4",
|
|
18
|
+
children: m
|
|
19
|
+
}) }),
|
|
20
|
+
/* @__PURE__ */ o(n.Footer, { children: [/* @__PURE__ */ a(n.ActionTrigger, {
|
|
21
|
+
asChild: !0,
|
|
22
|
+
children: /* @__PURE__ */ a(e, {
|
|
23
|
+
variant: "outline",
|
|
24
|
+
children: "Cancel"
|
|
25
|
+
})
|
|
26
|
+
}), /* @__PURE__ */ a(c.SubmitButton, { children: d })] })
|
|
27
|
+
] }) }), /* @__PURE__ */ a(n.CloseTrigger, {
|
|
28
|
+
asChild: !0,
|
|
29
|
+
children: /* @__PURE__ */ a(t, {
|
|
30
|
+
size: "sm",
|
|
31
|
+
"aria-label": "Close"
|
|
32
|
+
})
|
|
33
|
+
})] }) })] })]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export { c as FormDialog };
|