tiun 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/docs/components/images.md +34 -4
- data/docs/components/images.ru.md +33 -4
- data/docs/components/login.md +2 -0
- data/docs/components/login.ru.md +2 -0
- data/docs/components/profile.md +3 -1
- data/docs/components/profile.ru.md +3 -1
- data/docs/components/schema-records.md +2 -0
- data/docs/components/schema-records.ru.md +2 -0
- data/docs/components/signup.md +3 -1
- data/docs/components/signup.ru.md +3 -1
- data/docs/components/theme.md +3 -1
- data/docs/components/theme.ru.md +3 -1
- data/docs/reference.ru.md +6 -6
- data/lib/config/locale/ru.yml +0 -3
- data/lib/tiun/auth/token_identity.rb +9 -0
- data/lib/tiun/controller/auth/identity.rb +78 -19
- data/lib/tiun/controller/auth/registration.rb +23 -0
- data/lib/tiun/controller/auth.rb +4 -4
- data/lib/tiun/controller/base/representation.rb +12 -1
- data/lib/tiun/mailer/confirmation.rb +10 -2
- data/lib/tiun/model/account.rb +79 -3
- data/lib/tiun/model/auth.rb +2 -0
- data/lib/tiun/model/me.rb +83 -2
- data/lib/tiun/model/settings.rb +7 -0
- data/lib/tiun/model/token.rb +2 -2
- data/lib/tiun/proceed/schemas/constants.rb +1 -0
- data/lib/tiun/proceed/schemas/spans.rb +1 -0
- data/lib/tiun/routes/mounts.rb +7 -4
- data/lib/tiun/service/email_confirmation.rb +84 -12
- data/lib/tiun/version.rb +1 -1
- data/package-lock.json +2 -2
- data/package.json +1 -1
- data/src/components/Component.tsx +4 -1
- data/src/components/Image.tsx +36 -25
- data/src/components/Index.tsx +193 -24
- data/src/components/Loader.tsx +11 -9
- data/src/components/Lorem.tsx +7 -1
- data/src/components/Modal.tsx +8 -1
- data/src/components/Paginator.tsx +9 -3
- data/src/components/Records.tsx +45 -18
- data/src/components/calendar-browser.scss +14 -4
- data/src/components/form/Login.tsx +12 -6
- data/src/components/form/auth.scss +44 -130
- data/src/components/form/forms.scss +9 -8
- data/src/components/form/types.ts +2 -0
- data/src/components/image.scss +10 -7
- data/src/components/records.scss +4 -0
- data/src/components/theme-palettes/dark.scss +1 -0
- data/src/concern/application.ts +3 -2
- data/src/concern/spansViewProps.tsx +14 -1
- data/src/concern/useRecordsResource.ts +2 -0
- data/src/decorators/withField.tsx +10 -7
- data/src/decorators/withForm.tsx +12 -6
- data/src/schema/Schema.ts +10 -0
- data/src/services/calendar/daylight.ts +31 -4
- data/src/services/methods.ts +1 -1
- data/src/services/records/useRecordPages.ts +23 -3
- data/src/services/session/renewal.ts +69 -6
- data/src/services/useAppearance.ts +22 -11
- data/src/services/useSwitch.ts +23 -17
- data/src/theme/configuration.ts +21 -7
- metadata +2 -2
data/src/components/Index.tsx
CHANGED
|
@@ -5,13 +5,20 @@ import type { ComponentType, ReactNode } from "react";
|
|
|
5
5
|
import type { FormData } from "./form/types.js";
|
|
6
6
|
import { I18n, translations } from "../services/i18n/I18n.js";
|
|
7
7
|
import { Meta, serverMeta } from "../services/Meta.js";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
findResource,
|
|
10
|
+
findResourceMethod,
|
|
11
|
+
isPolicyAllowed,
|
|
12
|
+
pageReadResource,
|
|
13
|
+
resourceAllowed,
|
|
14
|
+
withResourceAccess,
|
|
15
|
+
} from "../services/Resource.js";
|
|
9
16
|
import type { RouteLocation, RouteViewProps, RouterValue } from "../decorators/withRouter.js";
|
|
10
17
|
import { RoutedView } from "./View.js";
|
|
11
18
|
import { appearanceConfiguration } from "../theme/configuration.js";
|
|
12
19
|
import { themeResource } from "../theme/resource.js";
|
|
13
20
|
import { messages, scopedMessages } from "../services/i18n/messages.js";
|
|
14
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
21
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
15
22
|
import { TranslationContext, useI18nLoading, useI18nUpdates } from "../concern/i18n.js";
|
|
16
23
|
import type { ApplicationState } from "../concern/application.js";
|
|
17
24
|
import { CatchWrapper } from "./CatchWrapper.js";
|
|
@@ -24,7 +31,7 @@ import type { SessionUser } from "../services/session/renewal.js";
|
|
|
24
31
|
import { withAppearance } from "../decorators/withAppearance.js";
|
|
25
32
|
import { Toast } from "./Toast.js";
|
|
26
33
|
import type { TranslationTree } from "../services/i18n/I18n.js";
|
|
27
|
-
import { useSessionRenewal } from "../services/session/renewal.js";
|
|
34
|
+
import { ownerOf, readBrowserUser, useSessionRenewal } from "../services/session/renewal.js";
|
|
28
35
|
import { withRouter } from "../decorators/withRouter.js";
|
|
29
36
|
|
|
30
37
|
export interface IndexProps<T, User extends SessionUser> {
|
|
@@ -47,6 +54,17 @@ const RoutedApplication = withRouter("div");
|
|
|
47
54
|
// eslint-disable-next-line one-var, @typescript-eslint/naming-convention -- The decorated application is a JSX component.
|
|
48
55
|
const ApplicationAppearance = withAppearance("div");
|
|
49
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Finds the same-origin GET resource for the browser's signed-in user.
|
|
59
|
+
* @param meta Application metadata with the named resource.
|
|
60
|
+
* @returns A path when the current user resource requires authentication.
|
|
61
|
+
*/
|
|
62
|
+
function browserUserPath(meta: ServerMeta): string | undefined {
|
|
63
|
+
const name = applicationConfiguration(meta).current_user_resource ?? "user.me",
|
|
64
|
+
resource = findResource(meta, name);
|
|
65
|
+
return findResourceMethod(resource, "get")?.auth === "required" ? themeResource(meta, name, "get") : undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
50
68
|
/**
|
|
51
69
|
* Loads the application metadata and provides translations to its routed shell.
|
|
52
70
|
* @param props Application bootstrap, services, and host components.
|
|
@@ -73,10 +91,13 @@ export function Index<T = unknown, User extends SessionUser = SessionUser>(props
|
|
|
73
91
|
);
|
|
74
92
|
useI18nUpdates(locale);
|
|
75
93
|
|
|
76
|
-
const [user, setUser] = useState(props.user ?? null),
|
|
77
|
-
owner =
|
|
94
|
+
const [user, setUser] = useState(() => (browserUserPath(bootstrap) ? null : (props.user ?? null))),
|
|
95
|
+
owner = ownerOf(user) ?? "",
|
|
96
|
+
previousOwner = useRef(owner),
|
|
78
97
|
recordCache = useMemo(() => new Map<string, FormData>(), [owner]);
|
|
79
98
|
// eslint-disable-next-line one-var -- Group state hooks separately from derived request state.
|
|
99
|
+
const activeRouter = useRef<RouterValue | null>(null);
|
|
100
|
+
// eslint-disable-next-line one-var -- Keep resource request state together.
|
|
80
101
|
const [snapshot, setSnapshot] = useState<{ source: Meta; url: string; meta: ServerMeta } | null>(null),
|
|
81
102
|
[notice, setNotice] = useState(""),
|
|
82
103
|
[error, setError] = useState(false),
|
|
@@ -100,13 +121,79 @@ export function Index<T = unknown, User extends SessionUser = SessionUser>(props
|
|
|
100
121
|
const config = applicationConfiguration(meta),
|
|
101
122
|
labels = messages(meta, props.initial?.labels, locale);
|
|
102
123
|
const theme = appearanceConfiguration(meta, config.appearance_resource);
|
|
124
|
+
const userPath = browserUserPath(configuration),
|
|
125
|
+
[checkedUserPath, setCheckedUserPath] = useState<string>(),
|
|
126
|
+
userRequest = useRef<AbortController | null>(null);
|
|
127
|
+
const sessionPending = Boolean(userPath && checkedUserPath !== userPath);
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Reconciles the browser identity with the current user resource.
|
|
131
|
+
* - Supersedes a lookup that began before the latest session operation.
|
|
132
|
+
* @param credentials Session credentials from the completed operation or null.
|
|
133
|
+
* @returns The confirmed account, or null for a guest.
|
|
134
|
+
*/
|
|
135
|
+
const syncUser = useCallback(
|
|
136
|
+
async (credentials: User | null): Promise<User | null> => {
|
|
137
|
+
userRequest.current?.abort();
|
|
138
|
+
if (!userPath) {
|
|
139
|
+
setUser(credentials);
|
|
140
|
+
return credentials;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const request = new AbortController();
|
|
144
|
+
userRequest.current = request;
|
|
145
|
+
try {
|
|
146
|
+
const confirmed = await readBrowserUser(userPath, credentials, request.signal);
|
|
147
|
+
request.signal.throwIfAborted();
|
|
148
|
+
setUser(confirmed);
|
|
149
|
+
setCheckedUserPath(userPath);
|
|
150
|
+
return confirmed;
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (!request.signal.aborted) {
|
|
153
|
+
setUser(null);
|
|
154
|
+
setCheckedUserPath(userPath);
|
|
155
|
+
}
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
[userPath],
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (userPath) {
|
|
164
|
+
void syncUser(props.user ?? null).catch(() => {});
|
|
165
|
+
}
|
|
166
|
+
return () => userRequest.current?.abort();
|
|
167
|
+
}, [userPath, props.user, syncUser]);
|
|
168
|
+
|
|
103
169
|
// eslint-disable-next-line one-var -- Keep the session setup with the renewal hook.
|
|
104
170
|
const renewPath = themeResource(meta, theme.session_resource, "put");
|
|
105
171
|
// eslint-disable-next-line one-var -- Keep the hook separate from the endpoint lookup.
|
|
106
|
-
const renewSession = useSessionRenewal(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
172
|
+
const renewSession = useSessionRenewal(
|
|
173
|
+
user,
|
|
174
|
+
/**
|
|
175
|
+
* Handles token rotation or rechecks the browser's cookie after a rejected refresh.
|
|
176
|
+
* @param next The refreshed credentials or null when renewal failed.
|
|
177
|
+
* @returns No value. A cookie check updates the user asynchronously.
|
|
178
|
+
*/
|
|
179
|
+
(next) => {
|
|
180
|
+
if (!userPath) {
|
|
181
|
+
setUser(next);
|
|
182
|
+
} else if (!next) {
|
|
183
|
+
void syncUser(null).catch(() => {});
|
|
184
|
+
} else {
|
|
185
|
+
setUser((current) =>
|
|
186
|
+
current && ownerOf(current) === ownerOf(next)
|
|
187
|
+
? { ...current, refresh_token: next.refresh_token, session_token: next.session_token }
|
|
188
|
+
: current,
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
metadataPath: backendMetadata.url,
|
|
194
|
+
...(typeof renewPath === "string" && { renewUrl: renewPath }),
|
|
195
|
+
},
|
|
196
|
+
);
|
|
110
197
|
|
|
111
198
|
const registry = useMemo(
|
|
112
199
|
() => (typeof props.registry === "function" ? props.registry(meta, locale) : props.registry),
|
|
@@ -138,7 +225,7 @@ export function Index<T = unknown, User extends SessionUser = SessionUser>(props
|
|
|
138
225
|
// eslint-disable-next-line one-var -- Keep the view access check separate from the React hook.
|
|
139
226
|
const isViewAllowed = (name: string): boolean => {
|
|
140
227
|
const declaration = schema.pageDefinitions[name];
|
|
141
|
-
if (!declaration || !schema.view(name) || !isPolicyAllowed(declaration.policy,
|
|
228
|
+
if (!declaration || !schema.view(name) || !isPolicyAllowed(declaration.policy, permissions)) {
|
|
142
229
|
return false;
|
|
143
230
|
}
|
|
144
231
|
// eslint-disable-next-line one-var -- Resolve the read operation only for admitted views.
|
|
@@ -147,6 +234,77 @@ export function Index<T = unknown, User extends SessionUser = SessionUser>(props
|
|
|
147
234
|
return resource === undefined || resourceAllowed(meta, resource, "get");
|
|
148
235
|
};
|
|
149
236
|
|
|
237
|
+
/**
|
|
238
|
+
* Checks whether the route is part of the administration dashboard.
|
|
239
|
+
* @param router Current route and its path resolver.
|
|
240
|
+
* @returns True for the configured dashboard path or an administrative view name.
|
|
241
|
+
*/
|
|
242
|
+
// eslint-disable-next-line one-var -- Keep the administrative route check separate.
|
|
243
|
+
const isAdministrativeRoute = (router: Pick<RouterValue, "location" | "path" | "view">): boolean => {
|
|
244
|
+
const dashboardPath = router.path({ view: config.dashboard_view ?? "" });
|
|
245
|
+
return (
|
|
246
|
+
router.view?.startsWith(config.administrative_prefix ?? "dashboard.") === true ||
|
|
247
|
+
(typeof dashboardPath === "string" &&
|
|
248
|
+
dashboardPath !== "" &&
|
|
249
|
+
router.location.pathname === new URL(dashboardPath, router.location.url).pathname)
|
|
250
|
+
);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Checks whether a visitor can use the sign-in shell of the current dashboard route.
|
|
255
|
+
* @param administrative Whether the route belongs to the dashboard.
|
|
256
|
+
* @returns True when a guest should stay on the dashboard for sign-in.
|
|
257
|
+
*/
|
|
258
|
+
// eslint-disable-next-line one-var -- Keep guest access independent of route classification.
|
|
259
|
+
const isGuestDashboard = (administrative: boolean): boolean =>
|
|
260
|
+
administrative &&
|
|
261
|
+
owner === "" &&
|
|
262
|
+
((config.dashboard_view ?? "") !== "" || (config.administrative_prefix ?? "") !== "");
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Returns to an accessible root after the active view is denied.
|
|
266
|
+
* - Waits for metadata and the current user before checking access.
|
|
267
|
+
* - Keeps the direct guest sign-in shell.
|
|
268
|
+
* - Keeps the current address when there is no accessible root.
|
|
269
|
+
* @param router Current route and its navigation methods.
|
|
270
|
+
* @param signedOut Whether the current user has just lost their session.
|
|
271
|
+
* @returns Nothing.
|
|
272
|
+
*/
|
|
273
|
+
// eslint-disable-next-line one-var -- Run the same policy after navigation and after metadata arrives.
|
|
274
|
+
const redirectDeniedView = (
|
|
275
|
+
router: Pick<RouterValue, "location" | "navigate" | "path" | "view">,
|
|
276
|
+
signedOut = false,
|
|
277
|
+
): void => {
|
|
278
|
+
if (!ready || sessionPending || typeof router.view !== "string" || router.location.pathname === "/") {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const dashboard = isAdministrativeRoute(router),
|
|
282
|
+
dashboardView = config.dashboard_view;
|
|
283
|
+
if (!signedOut && isGuestDashboard(dashboard)) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (
|
|
287
|
+
isViewAllowed(router.view) &&
|
|
288
|
+
(!signedOut || !dashboard || typeof dashboardView === "undefined" || isViewAllowed(dashboardView))
|
|
289
|
+
) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// eslint-disable-next-line one-var -- Resolve the fallback only if access to the current route was denied.
|
|
294
|
+
const root = schema.matchRoute("/")?.view.name;
|
|
295
|
+
if (typeof root === "string" && isViewAllowed(root)) {
|
|
296
|
+
router.navigate("/", { replace: true });
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
useEffect(() => {
|
|
301
|
+
if (ready && activeRouter.current) {
|
|
302
|
+
const signedOut = previousOwner.current !== "" && owner === "";
|
|
303
|
+
previousOwner.current = owner;
|
|
304
|
+
redirectDeniedView(activeRouter.current, signedOut);
|
|
305
|
+
}
|
|
306
|
+
}, [ready, sessionPending, owner, permissions]);
|
|
307
|
+
|
|
150
308
|
/**
|
|
151
309
|
* Selects a text from the view labels, application labels or standard locale.
|
|
152
310
|
* @param key Name of the label, including nested keys.
|
|
@@ -172,14 +330,30 @@ export function Index<T = unknown, User extends SessionUser = SessionUser>(props
|
|
|
172
330
|
initial: props.initial ?? EMPTY,
|
|
173
331
|
initialUrl,
|
|
174
332
|
labels,
|
|
175
|
-
|
|
176
|
-
|
|
333
|
+
/**
|
|
334
|
+
* Verifies that the newly authenticated account owns the browser session.
|
|
335
|
+
* @param credentials Session credentials from the sign-in response.
|
|
336
|
+
* @returns A promise that rejects when the sign-in did not establish that session.
|
|
337
|
+
*/
|
|
338
|
+
login: async (credentials) => {
|
|
339
|
+
const confirmed = await syncUser(credentials);
|
|
340
|
+
if (!confirmed || ownerOf(confirmed) !== ownerOf(credentials)) {
|
|
341
|
+
throw new Error(locale.t("tiun.components.login.errors.request"));
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
/** Reads the server session after successful sign-out. Takes no arguments and returns completion. */
|
|
345
|
+
logout: async () => {
|
|
346
|
+
if (await syncUser(null)) {
|
|
347
|
+
throw new Error(locale.t("tiun.components.login.errors.logout"));
|
|
348
|
+
}
|
|
349
|
+
},
|
|
177
350
|
meta,
|
|
178
351
|
notify: setNotice,
|
|
179
352
|
ready,
|
|
180
353
|
recordCache,
|
|
181
354
|
reload: () => setRevision((value) => value + 1),
|
|
182
355
|
renewSession,
|
|
356
|
+
sessionPending,
|
|
183
357
|
/**
|
|
184
358
|
* Updates editable profile fields while keeping the active session and its permissions.
|
|
185
359
|
* @param owner Identifier of the session that owns the profile.
|
|
@@ -307,31 +481,26 @@ export function Index<T = unknown, User extends SessionUser = SessionUser>(props
|
|
|
307
481
|
!ready ? pending(false, router) : <p role="status">{label("missing", "tiun.defaults.errors.404.name")}</p>
|
|
308
482
|
}
|
|
309
483
|
onRouteChange={(router) => {
|
|
484
|
+
activeRouter.current = router;
|
|
310
485
|
if (router.location.url !== initialUrl) setHasNavigated(true);
|
|
486
|
+
redirectDeniedView(router);
|
|
311
487
|
}}
|
|
312
488
|
renderLayout={(page, router) => {
|
|
313
489
|
/**
|
|
314
490
|
* Keeps the current route header around the waiting, guest or signed-in contents.
|
|
491
|
+
* - Keeps the administrative view mounted while its query filters change.
|
|
315
492
|
* @param page {ReactNode} The matched route element.
|
|
316
493
|
* @param router {RouterValue} The route and its navigation methods.
|
|
317
494
|
* @returns {ReactNode} The routed page with access and loading feedback.
|
|
318
495
|
*/
|
|
319
496
|
const { hash, pathname, search } = router.location,
|
|
320
|
-
dashboardPath = router.path({ view: config.dashboard_view ?? "" }),
|
|
321
497
|
denied = typeof router.view === "string" && !isViewAllowed(router.view),
|
|
322
|
-
isAdministrative =
|
|
323
|
-
|
|
324
|
-
(typeof dashboardPath === "string" &&
|
|
325
|
-
dashboardPath !== "" &&
|
|
326
|
-
pathname === new URL(dashboardPath, router.location.url).pathname),
|
|
327
|
-
showGuestDashboard =
|
|
328
|
-
isAdministrative &&
|
|
329
|
-
owner === "" &&
|
|
330
|
-
((config.dashboard_view ?? "") !== "" || (config.administrative_prefix ?? "") !== "");
|
|
498
|
+
isAdministrative = isAdministrativeRoute(router),
|
|
499
|
+
showGuestDashboard = isGuestDashboard(isAdministrative);
|
|
331
500
|
// Общая шапка остаётся смонтированной при загрузке вида и смене фрагмента модала.
|
|
332
501
|
const fragmentView =
|
|
333
502
|
hash && router.view !== schema.matchRoute(pathname)?.view.name ? router.view : undefined;
|
|
334
|
-
const pageKey = JSON.stringify([pathname, search, fragmentView]);
|
|
503
|
+
const pageKey = JSON.stringify([pathname, isAdministrative ? "" : search, fragmentView]);
|
|
335
504
|
const isConfigured = React.isValidElement<RouteViewProps<T>>(page) && page.type === RoutedView;
|
|
336
505
|
let content = page;
|
|
337
506
|
if (showGuestDashboard) {
|
|
@@ -348,7 +517,7 @@ export function Index<T = unknown, User extends SessionUser = SessionUser>(props
|
|
|
348
517
|
/>
|
|
349
518
|
);
|
|
350
519
|
}
|
|
351
|
-
} else if (!ready) {
|
|
520
|
+
} else if (!ready || (denied && sessionPending)) {
|
|
352
521
|
content = pending(isAdministrative, router);
|
|
353
522
|
} else if (denied) {
|
|
354
523
|
content = (
|
data/src/components/Loader.tsx
CHANGED
|
@@ -34,7 +34,9 @@ const defaultSize = 2.5,
|
|
|
34
34
|
const ignorePage = (): void => {};
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* Loads pages and shows their progress
|
|
37
|
+
* Loads pages and shows their progress, or displays an operation's meteor.
|
|
38
|
+
* - Shows the counter as soon as a table read succeeds, including an empty result.
|
|
39
|
+
* - Shows nonempty counters again on scrolling.
|
|
38
40
|
* @param props Request, page receiver, loading state and indicator presentation.
|
|
39
41
|
* @returns Visible loading feedback or null.
|
|
40
42
|
*/
|
|
@@ -53,16 +55,15 @@ export function Loader({
|
|
|
53
55
|
}: LoaderProps) {
|
|
54
56
|
const requestState = useRecordsResource(request, onPage ?? ignorePage),
|
|
55
57
|
hasRequest = request !== undefined,
|
|
56
|
-
|
|
58
|
+
reportTableResult = request?.node.view === "table",
|
|
59
|
+
range = requestState.range,
|
|
57
60
|
[counterVisible, setCounterVisible] = useState(false);
|
|
58
61
|
useEffect(() => {
|
|
59
62
|
if (hasRequest) onRequestState?.(requestState);
|
|
60
63
|
}, [hasRequest, onRequestState, requestState]);
|
|
61
64
|
useEffect(() => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
65
|
+
setCounterVisible(false);
|
|
66
|
+
if (!hasRequest || !range) return;
|
|
66
67
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
67
68
|
|
|
68
69
|
/** Shows the counter until scrolling has stopped for two seconds. Takes no arguments and returns void. */
|
|
@@ -74,17 +75,18 @@ export function Loader({
|
|
|
74
75
|
}, counterDuration);
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
|
|
78
|
+
if (reportTableResult) showCounter();
|
|
79
|
+
if (range.total > 0) window.addEventListener("scroll", showCounter, { passive: true });
|
|
78
80
|
return () => {
|
|
79
81
|
window.removeEventListener("scroll", showCounter);
|
|
80
82
|
clearTimeout(timer);
|
|
81
83
|
};
|
|
82
|
-
}, [
|
|
84
|
+
}, [hasRequest, range, reportTableResult]);
|
|
83
85
|
const { t } = useI18n(),
|
|
84
86
|
dimension = Number.isFinite(size) && size > 0 ? size : defaultSize,
|
|
85
87
|
style = { "--tiun-loader-size": `${dimension}rem` } as CSSProperties;
|
|
86
88
|
if (hasRequest) {
|
|
87
|
-
if (!
|
|
89
|
+
if (!range || !counterVisible) return null;
|
|
88
90
|
|
|
89
91
|
const { loadedCount, total } = requestState;
|
|
90
92
|
const pagination = request.node.pagination;
|
data/src/components/Lorem.tsx
CHANGED
|
@@ -234,7 +234,13 @@ function configuredLorem<T>(props: ConfiguredLoremProps<T>): ReactNode {
|
|
|
234
234
|
case "span":
|
|
235
235
|
return <Span key={key} value={current} {...spanOptions(schema, definition, current)} />;
|
|
236
236
|
case "spans": {
|
|
237
|
-
const props = spansViewProps(
|
|
237
|
+
const props = spansViewProps(
|
|
238
|
+
schema,
|
|
239
|
+
definition,
|
|
240
|
+
current,
|
|
241
|
+
{ hideIfEmpty: true, ...incoming() },
|
|
242
|
+
configured?.pagination,
|
|
243
|
+
);
|
|
238
244
|
return props ? <Spans key={key} {...props} /> : null;
|
|
239
245
|
}
|
|
240
246
|
case "name": {
|
data/src/components/Modal.tsx
CHANGED
|
@@ -30,7 +30,7 @@ const isBackdropEvent = ({ currentTarget, target, clientX, clientY }: React.Mous
|
|
|
30
30
|
* Opens a native modal and restores focus after closing it.
|
|
31
31
|
* - If the browser focuses a fixed field's remove button, initial focus stays on the dialog.
|
|
32
32
|
* - A backdrop click or Escape requests dismissal.
|
|
33
|
-
* -
|
|
33
|
+
* - Pointer, mouse and touch input inside the modal stops before reaching the surrounding view.
|
|
34
34
|
* @param props Accessible name, children, appearance and optional dismissal controls.
|
|
35
35
|
* @returns The independent dialog element.
|
|
36
36
|
*/
|
|
@@ -127,9 +127,16 @@ export function Modal({
|
|
|
127
127
|
dismiss();
|
|
128
128
|
}
|
|
129
129
|
}}
|
|
130
|
+
onPointerCancel={contain}
|
|
131
|
+
onPointerMove={contain}
|
|
130
132
|
onPointerUp={contain}
|
|
131
133
|
onMouseDown={contain}
|
|
134
|
+
onMouseMove={contain}
|
|
132
135
|
onMouseUp={contain}
|
|
136
|
+
onTouchCancel={contain}
|
|
137
|
+
onTouchEnd={contain}
|
|
138
|
+
onTouchMove={contain}
|
|
139
|
+
onTouchStart={contain}
|
|
133
140
|
onDoubleClick={contain}
|
|
134
141
|
onContextMenu={contain}
|
|
135
142
|
onWheel={contain}
|
|
@@ -16,6 +16,8 @@ export interface PaginatorProps {
|
|
|
16
16
|
readonly renderFeedback?: boolean;
|
|
17
17
|
readonly loadingFeedback?: ReactNode;
|
|
18
18
|
readonly renderCounter?: boolean;
|
|
19
|
+
/** Shows the meteor while automatic pagination waits for a response. */
|
|
20
|
+
readonly showLoading?: boolean;
|
|
19
21
|
readonly rangeUnit?: "pages" | "records";
|
|
20
22
|
/** The built-in control is round for either value. */
|
|
21
23
|
readonly buttonStyle?: "text" | "circle";
|
|
@@ -208,10 +210,14 @@ export function Paginator<T>(input: PaginatorProps & AxiosPaginatorProps<T>) {
|
|
|
208
210
|
showButton = hasControl && kind === "button" && !underLoadLimit,
|
|
209
211
|
// eslint-disable-next-line sort-vars -- This feedback depends on whether the button occupies its slot.
|
|
210
212
|
showAutomaticFeedback =
|
|
211
|
-
|
|
213
|
+
busy &&
|
|
214
|
+
!showButton &&
|
|
215
|
+
(props.showLoading === true ||
|
|
216
|
+
(kind === "button" && (props.renderFeedback !== false || props.loadingFeedback != null))),
|
|
212
217
|
counterPage =
|
|
213
218
|
props.rangeUnit !== "pages" ? loaded : currentRange ? reportedPages : reportedPages === 0 ? 0 : legacyPage,
|
|
214
|
-
counterTotal = props.rangeUnit !== "pages" ? recordTotal : resolvedTotalPages
|
|
219
|
+
counterTotal = props.rangeUnit !== "pages" ? recordTotal : resolvedTotalPages,
|
|
220
|
+
showCounter = props.renderCounter !== false && (visible || (busy && props.showLoading === true));
|
|
215
221
|
return (
|
|
216
222
|
<div className="tiun-paginator" aria-busy={Boolean(props.loading)}>
|
|
217
223
|
{props.renderFeedback !== false && props.error && (
|
|
@@ -246,7 +252,7 @@ export function Paginator<T>(input: PaginatorProps & AxiosPaginatorProps<T>) {
|
|
|
246
252
|
: null}
|
|
247
253
|
</div>
|
|
248
254
|
)}
|
|
249
|
-
{
|
|
255
|
+
{showCounter && counterPage != null && counterTotal != null && (
|
|
250
256
|
<div className="tiun-paginator-popup" style={props.outterDivStyle} role="status">
|
|
251
257
|
<span style={props.innerDivStyle}>
|
|
252
258
|
{props.i18n?.pages?.(counterPage, counterTotal) ?? `${counterPage} / ${counterTotal}`}
|
data/src/components/Records.tsx
CHANGED
|
@@ -56,10 +56,11 @@ export function Records<T>({
|
|
|
56
56
|
const { t } = useI18n(),
|
|
57
57
|
columns = props.columns ?? [],
|
|
58
58
|
containerRef = useRef<HTMLDivElement>(null),
|
|
59
|
-
[layout, setLayout] = useState<{
|
|
60
|
-
height:
|
|
61
|
-
positions: []
|
|
62
|
-
|
|
59
|
+
[layout, setLayout] = useState<{
|
|
60
|
+
height: number;
|
|
61
|
+
positions: { left: number; top: number; width: number }[];
|
|
62
|
+
waitingForImages: boolean;
|
|
63
|
+
}>({ height: 0, positions: [], waitingForImages: false }),
|
|
63
64
|
[expanded, setExpanded] = useState<ReadonlySet<RecordKey>>(() => new Set(props.defaultExpandedKeys)),
|
|
64
65
|
defaults = JSON.stringify(props.defaultExpandedKeys ?? []);
|
|
65
66
|
|
|
@@ -73,6 +74,13 @@ export function Records<T>({
|
|
|
73
74
|
return;
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Measures the stack using the actual heights of its records.
|
|
79
|
+
* - Skips gaps for records that occupy no space.
|
|
80
|
+
* - Pauses automatic pagination while hidden images are loading.
|
|
81
|
+
* No arguments.
|
|
82
|
+
* @returns Nothing. Updates layout and loading state from the current DOM.
|
|
83
|
+
*/
|
|
76
84
|
const measure = (): void => {
|
|
77
85
|
const available = root.clientWidth,
|
|
78
86
|
baseRem = rootRem(root),
|
|
@@ -86,28 +94,40 @@ export function Records<T>({
|
|
|
86
94
|
element = child as HTMLElement,
|
|
87
95
|
top = heights[column]!;
|
|
88
96
|
element.style.width = toRem(columnWidth, root);
|
|
89
|
-
|
|
97
|
+
const { height } = element.getBoundingClientRect();
|
|
98
|
+
if (height > 0) {
|
|
99
|
+
heights[column] = top + height + columnGap;
|
|
100
|
+
}
|
|
90
101
|
return { left: offset + column * (columnWidth + columnGap), top, width: columnWidth };
|
|
91
102
|
}),
|
|
92
|
-
|
|
103
|
+
placement = {
|
|
104
|
+
height: Math.max(0, Math.max(...heights) - columnGap),
|
|
105
|
+
positions,
|
|
106
|
+
waitingForImages:
|
|
107
|
+
root.querySelector(
|
|
108
|
+
':is(.tiun-image-quiet, [data-image-reserve])[data-image-state="loading"] img:not([loading="lazy"])',
|
|
109
|
+
) !== null,
|
|
110
|
+
};
|
|
93
111
|
|
|
94
|
-
setLayout((previous) =>
|
|
95
|
-
JSON.stringify(previous) === JSON.stringify({ height: stackHeight, positions })
|
|
96
|
-
? previous
|
|
97
|
-
: { height: stackHeight, positions },
|
|
98
|
-
);
|
|
112
|
+
setLayout((previous) => (JSON.stringify(previous) === JSON.stringify(placement) ? previous : placement));
|
|
99
113
|
};
|
|
100
114
|
|
|
101
115
|
measure();
|
|
102
116
|
const observer = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(measure);
|
|
103
117
|
observer?.observe(root);
|
|
104
118
|
observer?.observe(root.ownerDocument.documentElement);
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
119
|
+
const mutationObserver = root.ownerDocument.defaultView?.MutationObserver,
|
|
120
|
+
attributeObserver = mutationObserver ? new mutationObserver(measure) : undefined;
|
|
121
|
+
attributeObserver?.observe(root.ownerDocument.documentElement, {
|
|
108
122
|
attributeFilter: ["style", "class"],
|
|
109
123
|
attributes: true,
|
|
110
124
|
});
|
|
125
|
+
attributeObserver?.observe(root, {
|
|
126
|
+
attributeFilter: ["data-image-state"],
|
|
127
|
+
attributes: true,
|
|
128
|
+
childList: true,
|
|
129
|
+
subtree: true,
|
|
130
|
+
});
|
|
111
131
|
|
|
112
132
|
Array.from(root.children).forEach((child) => observer?.observe(child));
|
|
113
133
|
|
|
@@ -115,7 +135,7 @@ export function Records<T>({
|
|
|
115
135
|
window.addEventListener("resize", measure);
|
|
116
136
|
return () => {
|
|
117
137
|
observer?.disconnect();
|
|
118
|
-
|
|
138
|
+
attributeObserver?.disconnect();
|
|
119
139
|
root.removeEventListener("load", measure, true);
|
|
120
140
|
window.removeEventListener("resize", measure);
|
|
121
141
|
};
|
|
@@ -298,7 +318,7 @@ export function Records<T>({
|
|
|
298
318
|
<Paginator
|
|
299
319
|
{...props.pagination}
|
|
300
320
|
kind={props.pagination?.kind ?? (props.manualFetch ? "button" : "hidden")}
|
|
301
|
-
loading={props.loading}
|
|
321
|
+
loading={props.loading === true || (view === "stack" && layout.waitingForImages)}
|
|
302
322
|
error={props.error}
|
|
303
323
|
hasMore={props.hasMore ?? false}
|
|
304
324
|
fetchFunc={props.onFetchNext}
|
|
@@ -516,6 +536,8 @@ export function RecordsWithLoader({
|
|
|
516
536
|
const { schema, definition: node } = props,
|
|
517
537
|
[query, setQuery] = useState(""),
|
|
518
538
|
activeQuery = useRef(query),
|
|
539
|
+
[displayedQuery, setDisplayedQuery] = useState(query),
|
|
540
|
+
acceptedQuery = useRef(query),
|
|
519
541
|
[searchDraft, setSearchDraft] = useState(""),
|
|
520
542
|
[items, setItems] = useState<readonly unknown[]>([]),
|
|
521
543
|
[currentWrite, setCurrentWrite] = useState<StoredRecord>(),
|
|
@@ -534,11 +556,17 @@ export function RecordsWithLoader({
|
|
|
534
556
|
}
|
|
535
557
|
/**
|
|
536
558
|
* Applies an accepted page to the records owned by this list.
|
|
559
|
+
* - Replaces the displayed search and its local edits when its response is accepted.
|
|
537
560
|
* @param page Records returned by Loader.
|
|
538
561
|
* @param replace Whether the page replaces the old list.
|
|
539
562
|
* @returns Nothing.
|
|
540
563
|
*/
|
|
541
564
|
const receive = useCallback((page: readonly unknown[], replace: boolean): void => {
|
|
565
|
+
if (replace && activeQuery.current !== acceptedQuery.current) {
|
|
566
|
+
acceptedQuery.current = activeQuery.current;
|
|
567
|
+
setDisplayedQuery(acceptedQuery.current);
|
|
568
|
+
setCurrentWrite(undefined);
|
|
569
|
+
}
|
|
542
570
|
setItems((previous) => (replace ? page : previous.concat(page)));
|
|
543
571
|
}, []);
|
|
544
572
|
return (
|
|
@@ -550,10 +578,9 @@ export function RecordsWithLoader({
|
|
|
550
578
|
isMetadataPending={isMetadataPending}
|
|
551
579
|
resource={resource}
|
|
552
580
|
pageSize={searchResultsPerPage}
|
|
553
|
-
query={
|
|
581
|
+
query={displayedQuery}
|
|
554
582
|
searchData={searchData}
|
|
555
583
|
onSearch={(value) => {
|
|
556
|
-
setCurrentWrite(undefined);
|
|
557
584
|
setQuery(value);
|
|
558
585
|
}}
|
|
559
586
|
onSearchDraft={setSearchDraft}
|
|
@@ -7,6 +7,13 @@
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
.tiun-calendar[data-style="round"] {
|
|
10
|
+
.tiun-calendar-weekdays,
|
|
11
|
+
.tiun-calendar-days {
|
|
12
|
+
grid-template-columns: repeat(7, min(calc(1.84rem + 2px), 100% / 7));
|
|
13
|
+
justify-content: center;
|
|
14
|
+
padding-inline: 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
10
17
|
.tiun-calendar-types button {
|
|
11
18
|
border: 0;
|
|
12
19
|
font-size: 1rem;
|
|
@@ -35,7 +42,9 @@
|
|
|
35
42
|
|
|
36
43
|
.tiun-calendar-day {
|
|
37
44
|
border: 0;
|
|
38
|
-
|
|
45
|
+
width: 100%;
|
|
46
|
+
height: auto;
|
|
47
|
+
aspect-ratio: 1;
|
|
39
48
|
margin: 0;
|
|
40
49
|
padding: 0;
|
|
41
50
|
}
|
|
@@ -50,14 +59,14 @@
|
|
|
50
59
|
font-size: min(1.2rem, 7.5cqi);
|
|
51
60
|
|
|
52
61
|
&:has(+ .tiun-calendar-secondary) {
|
|
53
|
-
transform: translateY(
|
|
62
|
+
transform: translateY(2px);
|
|
54
63
|
}
|
|
55
64
|
}
|
|
56
65
|
|
|
57
66
|
.tiun-calendar-secondary {
|
|
58
67
|
font-size: calc(0.5375rem + 0.5px);
|
|
59
68
|
font-size: calc(min(0.6rem, 3.75cqi) - 0.0625rem + 0.5px);
|
|
60
|
-
transform: translateY(
|
|
69
|
+
transform: translateY(0.5px);
|
|
61
70
|
}
|
|
62
71
|
.tiun-calendar-day:is([data-today="true"], [data-selected="true"]) {
|
|
63
72
|
color: var(--tiun-calendar-on-selected, #fff);
|
|
@@ -65,7 +74,8 @@
|
|
|
65
74
|
box-shadow: none;
|
|
66
75
|
}
|
|
67
76
|
.tiun-calendar-day[data-today="true"][data-selected="true"] {
|
|
68
|
-
box-shadow: inset 0 0 0 0.15rem
|
|
77
|
+
box-shadow: inset 0 0 0 0.15rem
|
|
78
|
+
var(--tiun-calendar-today-selected-ring, var(--tiun-calendar-selected, DeepSkyBlue));
|
|
69
79
|
}
|
|
70
80
|
}
|
|
71
81
|
|