@eifi1/ui-kit 0.24.1 → 0.25.1
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/README.md +6 -6
- package/dist/chart.d.ts +2 -2
- package/dist/components/account-chips.d.ts +1 -1
- package/dist/components/amount-input.d.ts +2 -2
- package/dist/components/button-group.d.ts +2 -2
- package/dist/components/calculator.d.ts +2 -2
- package/dist/components/column-mapper.d.ts +28 -9
- package/dist/components/column-mapper.js +63 -77
- package/dist/components/column-mapper.js.map +1 -1
- package/dist/components/confirm-dialog.d.ts +2 -2
- package/dist/components/copy-button.d.ts +2 -2
- package/dist/components/danger-confirm.d.ts +2 -2
- package/dist/components/data-table-cells.d.ts +1 -1
- package/dist/components/data-table-filter-popover.d.ts +1 -1
- package/dist/components/data-table-filters.d.ts +1 -1
- package/dist/components/data-table-labels.d.ts +1 -1
- package/dist/components/data-table-pagination.d.ts +1 -1
- package/dist/components/data-table-pagination.js +6 -1
- package/dist/components/data-table-pagination.js.map +1 -1
- package/dist/components/data-table.d.ts +1 -1
- package/dist/components/data-table.js +7 -1
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/facing-pair.d.ts +2 -2
- package/dist/components/file-button.d.ts +2 -2
- package/dist/components/file-dropzone.d.ts +2 -2
- package/dist/components/form-actions.d.ts +2 -2
- package/dist/components/iban-input.d.ts +2 -2
- package/dist/components/language-select.d.ts +2 -2
- package/dist/components/money-field.d.ts +2 -2
- package/dist/components/number-field.d.ts +2 -2
- package/dist/components/number-input.d.ts +2 -2
- package/dist/components/numpad-sheet.d.ts +2 -2
- package/dist/components/phone-input.d.ts +2 -2
- package/dist/components/series-chart.d.ts +2 -2
- package/dist/components/settings-fields.d.ts +2 -2
- package/dist/components/share-card.d.ts +2 -2
- package/dist/components/swipeable-row.js +1 -1
- package/dist/components/swipeable-row.js.map +1 -1
- package/dist/components/table.d.ts +35 -1
- package/dist/components/table.js +4 -0
- package/dist/components/table.js.map +1 -1
- package/dist/components/text-link.d.ts +2 -2
- package/dist/components/time-input.d.ts +2 -2
- package/dist/components/tooltip.d.ts +103 -14
- package/dist/components/tooltip.js +194 -57
- package/dist/components/tooltip.js.map +1 -1
- package/dist/components/translation-review-editor.d.ts +9 -1
- package/dist/components/translation-review-editor.js +11 -1
- package/dist/components/translation-review-editor.js.map +1 -1
- package/dist/components/translation-review-labels.d.ts +10 -0
- package/dist/components/translation-review-labels.js +5 -1
- package/dist/components/translation-review-labels.js.map +1 -1
- package/dist/components/translation-review.d.ts +145 -8
- package/dist/components/translation-review.js +372 -91
- package/dist/components/translation-review.js.map +1 -1
- package/dist/components/ui.d.ts +2 -2
- package/dist/components/ui.js +55 -18
- package/dist/components/ui.js.map +1 -1
- package/dist/components/use-table-state.d.ts +1 -1
- package/dist/{data-table-labels-B7OdnM0S.d.ts → data-table-labels-Cdn1QS2k.d.ts} +21 -1
- package/dist/data-table.d.ts +1 -1
- package/dist/feedback/feedback-attachment.d.ts +2 -2
- package/dist/feedback/feedback-dialog.d.ts +2 -2
- package/dist/feedback/feedback-dialog.js +6 -1
- package/dist/feedback/feedback-dialog.js.map +1 -1
- package/dist/feedback/feedback-inbox.d.ts +2 -2
- package/dist/feedback/feedback-inbox.js +2 -0
- package/dist/feedback/feedback-inbox.js.map +1 -1
- package/dist/feedback/feedback-thread.d.ts +2 -2
- package/dist/{feedback-DOwPu-Il.d.ts → feedback-BXKH-ToU.d.ts} +32 -3
- package/dist/feedback.d.ts +2 -2
- package/dist/hooks/use-body-scroll-lock.js +16 -0
- package/dist/hooks/use-body-scroll-lock.js.map +1 -1
- package/dist/hooks/use-file-drop.d.ts +2 -2
- package/dist/hooks/use-search-param-state.d.ts +58 -3
- package/dist/hooks/use-search-param-state.js +107 -35
- package/dist/hooks/use-search-param-state.js.map +1 -1
- package/dist/i18n/defaults.d.ts +2 -2
- package/dist/i18n/german.d.ts +2 -2
- package/dist/i18n/german.js +8 -1
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +2 -2
- package/dist/i18n/languages.d.ts +2 -2
- package/dist/i18n/locales/de-CH.d.ts +2 -2
- package/dist/i18n/locales/en.d.ts +2 -2
- package/dist/i18n/locales/en.js +5 -1
- package/dist/i18n/locales/en.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +2 -2
- package/dist/i18n/locales/es.js +7 -1
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +2 -2
- package/dist/i18n/locales/fr.js +6 -1
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +2 -2
- package/dist/i18n/locales/hu.js +9 -1
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +2 -2
- package/dist/i18n/locales/it.js +6 -1
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +2 -2
- package/dist/i18n/locales/zh.js +6 -1
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.d.ts +2 -2
- package/dist/i18n/review.js +11 -0
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/strip-fade.d.ts +84 -5
- package/dist/lib/strip-fade.js +109 -11
- package/dist/lib/strip-fade.js.map +1 -1
- package/dist/lib/translation-review.d.ts +45 -1
- package/dist/lib/translation-review.js +38 -1
- package/dist/lib/translation-review.js.map +1 -1
- package/dist/rhf/fields.d.ts +2 -2
- package/dist/rhf/form.d.ts +2 -2
- package/dist/rhf.d.ts +2 -2
- package/dist/shell/app-shell.d.ts +2 -2
- package/dist/shell/top-bar-brand.d.ts +2 -2
- package/dist/shell.d.ts +2 -2
- package/dist/wizard/stepper-nav.d.ts +2 -2
- package/dist/wizard.d.ts +2 -2
- package/package.json +1 -1
- package/src/components/column-mapper.tsx +120 -113
- package/src/components/data-table-pagination.tsx +10 -1
- package/src/components/data-table.tsx +34 -1
- package/src/components/swipeable-row.tsx +1 -1
- package/src/components/table.tsx +39 -0
- package/src/components/tooltip.tsx +487 -104
- package/src/components/translation-review-editor.tsx +21 -1
- package/src/components/translation-review-labels.ts +17 -0
- package/src/components/translation-review.tsx +657 -109
- package/src/components/ui.tsx +104 -4
- package/src/feedback/feedback-dialog.tsx +21 -0
- package/src/feedback/feedback-inbox.tsx +19 -2
- package/src/hooks/use-body-scroll-lock.ts +25 -0
- package/src/hooks/use-search-param-state.ts +283 -41
- package/src/i18n/german.ts +10 -0
- package/src/i18n/locales/en.ts +7 -0
- package/src/i18n/locales/es.ts +9 -0
- package/src/i18n/locales/fr.ts +9 -0
- package/src/i18n/locales/hu.ts +11 -0
- package/src/i18n/locales/it.ts +9 -0
- package/src/i18n/locales/zh.ts +8 -0
- package/src/i18n/review.ts +11 -0
- package/src/index.ts +12 -0
- package/src/lib/strip-fade.ts +220 -15
- package/src/lib/translation-review.ts +85 -0
|
@@ -21,6 +21,9 @@ interface SearchParamStateOptions<T> {
|
|
|
21
21
|
* which are not steps anyone wants Back to walk through.
|
|
22
22
|
* - `"replace-on-clear"`: push when a value is set, replace when it is cleared (the
|
|
23
23
|
* "open a form, close it" pattern).
|
|
24
|
+
*
|
|
25
|
+
* Several writes in one tick (one handler) add at most ONE entry — see
|
|
26
|
+
* {@link useSearchParamState}.
|
|
24
27
|
*/
|
|
25
28
|
history?: "push" | "replace" | "replace-on-clear";
|
|
26
29
|
}
|
|
@@ -36,11 +39,63 @@ interface SearchParamStateOptions<T> {
|
|
|
36
39
|
* * an absent or unparseable param reads as the default, and
|
|
37
40
|
* * setting the default removes the param — the default view is the clean URL.
|
|
38
41
|
*
|
|
39
|
-
* Every other param in the query string is left as it is.
|
|
40
|
-
*
|
|
42
|
+
* Every other param in the query string is left as it is.
|
|
43
|
+
*
|
|
44
|
+
* **Setters compose** (0.25, keksdose live #378): setters called in a row — of one hook,
|
|
45
|
+
* or of several hooks under the same router — each build on the write before them, so
|
|
46
|
+
* `setStatus("open"); setNs("legal")` in one handler leaves both in the URL. react-
|
|
47
|
+
* router's own `setSearchParams(updater)` does not: it hands every updater the params of
|
|
48
|
+
* the render, so the last call used to write the others' old values back. The tick's
|
|
49
|
+
* writes add at most one history entry; see `history`. When the params belong
|
|
50
|
+
* together, {@link useSearchParamsState} writes them with one setter. A functional
|
|
51
|
+
* update receives the value as the writes before it left it.
|
|
52
|
+
*
|
|
41
53
|
* Requires a react-router Router.
|
|
42
54
|
*/
|
|
43
55
|
declare function useSearchParamState<T = string>(key: string, defaultValue: T, options?: SearchParamStateOptions<T>): [T, (next: Updater<T>) => void];
|
|
56
|
+
/** One field of {@link useSearchParamsState}: its default, and the single hook's options. */
|
|
57
|
+
interface SearchParamField<T> extends SearchParamStateOptions<T> {
|
|
58
|
+
/** The value when the param is absent or does not parse; writing it removes the param. */
|
|
59
|
+
default: T;
|
|
60
|
+
/** The param's name in the URL. Default: the field's name (`namespace: { param: "ns" }`). */
|
|
61
|
+
param?: string;
|
|
62
|
+
}
|
|
63
|
+
/** The fields of {@link useSearchParamsState}, one per key of the value object. */
|
|
64
|
+
type SearchParamFields<V> = {
|
|
65
|
+
[K in keyof V]: SearchParamField<V[K]>;
|
|
66
|
+
};
|
|
67
|
+
/** A partial value (fields left out — or `undefined` — stay as they are), or a function
|
|
68
|
+
* of the current value returning one. */
|
|
69
|
+
type SearchParamsUpdate<V> = Partial<V> | ((prev: V) => Partial<V>);
|
|
70
|
+
/**
|
|
71
|
+
* Several URL search params as ONE state object, with one setter that writes them in
|
|
72
|
+
* one navigation:
|
|
73
|
+
*
|
|
74
|
+
* const [filter, setFilter] = useSearchParamsState({
|
|
75
|
+
* status: { default: "all" as ReviewStatus | "all", parse: toStatus },
|
|
76
|
+
* namespace: { param: "ns", default: "all" },
|
|
77
|
+
* query: { param: "q", default: "", history: "replace" },
|
|
78
|
+
* });
|
|
79
|
+
* <TranslationReviewPanel filter={filter} onFilterChange={setFilter} />
|
|
80
|
+
*
|
|
81
|
+
* keksdose live #378: a filter bar reports all its filters on every change, and four
|
|
82
|
+
* single-param setters in a row clobbered each other (see {@link useSearchParamState},
|
|
83
|
+
* whose setters now compose too). This is the shape that never could: one setter, one
|
|
84
|
+
* write, every field's rules in one place.
|
|
85
|
+
*
|
|
86
|
+
* Each field takes what the single hook takes — `parse`, `serialize`, `history` /
|
|
87
|
+
* `replace` — and its `default` (the clean URL, as there) and optional `param` name.
|
|
88
|
+
* The setter takes a partial object or a function of the current one; fields it leaves
|
|
89
|
+
* out, or sets to `undefined`, stay as they are, and keys that are not fields are
|
|
90
|
+
* ignored, so a component's whole filter object can be handed over as it is. Its
|
|
91
|
+
* history is the single hook's rule over the fields that change: one entry, pushed if
|
|
92
|
+
* any of them asks to push, else the current entry rewritten. Setting what the URL
|
|
93
|
+
* already says navigates nowhere.
|
|
94
|
+
*
|
|
95
|
+
* The value object keeps its identity while its params do not change, so it can sit in
|
|
96
|
+
* a dependency array. Requires a react-router Router.
|
|
97
|
+
*/
|
|
98
|
+
declare function useSearchParamsState<V extends object>(fields: SearchParamFields<V>): [V, (next: SearchParamsUpdate<V>) => void];
|
|
44
99
|
/**
|
|
45
100
|
* The active tab in `?tab=` (or `key`), with the default tab as the clean URL, for the
|
|
46
101
|
* kit's `Tabs`:
|
|
@@ -80,4 +135,4 @@ type DialogParam = string | {
|
|
|
80
135
|
*/
|
|
81
136
|
declare function useDialogParam(param: DialogParam): [boolean, (open: boolean) => void];
|
|
82
137
|
|
|
83
|
-
export { type DialogParam, type SearchParamStateOptions, useDialogParam, useSearchParamState, useTabParam };
|
|
138
|
+
export { type DialogParam, type SearchParamField, type SearchParamFields, type SearchParamStateOptions, type SearchParamsUpdate, useDialogParam, useSearchParamState, useSearchParamsState, useTabParam };
|
|
@@ -1,47 +1,118 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { createContext, useContext, useMemo } from "react";
|
|
3
|
+
import * as ReactRouter from "react-router";
|
|
2
4
|
import { useLocation, useNavigate, useSearchParams } from "react-router";
|
|
3
5
|
const defaultSerialize = (value) => value === null || value === void 0 ? null : String(value);
|
|
4
6
|
function carriedState(state) {
|
|
5
7
|
return state && typeof state === "object" ? state : void 0;
|
|
6
8
|
}
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (!parse) return raw;
|
|
15
|
-
try {
|
|
16
|
-
const parsed = parse(raw);
|
|
17
|
-
return parsed === void 0 ? defaultValue : parsed;
|
|
18
|
-
} catch {
|
|
19
|
-
return defaultValue;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const value = read(params.get(key));
|
|
23
|
-
const defaultSerialized = serialize(defaultValue);
|
|
24
|
-
const toParam = (v) => {
|
|
25
|
-
const s = serialize(v);
|
|
26
|
-
return s === defaultSerialized ? null : s;
|
|
27
|
-
};
|
|
28
|
-
const setValue = (next) => {
|
|
29
|
-
const preview = typeof next === "function" ? next(value) : next;
|
|
30
|
-
const replace = history === "replace" || history === "replace-on-clear" && toParam(preview) === null;
|
|
31
|
-
setParams(
|
|
32
|
-
(prev) => {
|
|
33
|
-
const p = new URLSearchParams(prev);
|
|
34
|
-
const resolved = typeof next === "function" ? next(read(p.get(key))) : next;
|
|
35
|
-
const serialized = toParam(resolved);
|
|
36
|
-
if (serialized === null) p.delete(key);
|
|
37
|
-
else p.set(key, serialized);
|
|
38
|
-
return p;
|
|
39
|
-
},
|
|
40
|
-
replace ? { replace, state: carriedState(location.state) } : void 0
|
|
41
|
-
);
|
|
9
|
+
function paramRule(key, defaultValue, options) {
|
|
10
|
+
return {
|
|
11
|
+
key,
|
|
12
|
+
defaultValue,
|
|
13
|
+
parse: options.parse,
|
|
14
|
+
serialize: options.serialize ?? defaultSerialize,
|
|
15
|
+
history: options.history ?? (options.replace ? "replace" : "push")
|
|
42
16
|
};
|
|
17
|
+
}
|
|
18
|
+
function readParam(params, rule) {
|
|
19
|
+
const raw = params.get(rule.key);
|
|
20
|
+
if (raw === null) return rule.defaultValue;
|
|
21
|
+
if (!rule.parse) return raw;
|
|
22
|
+
try {
|
|
23
|
+
const parsed = rule.parse(raw);
|
|
24
|
+
return parsed === void 0 ? rule.defaultValue : parsed;
|
|
25
|
+
} catch {
|
|
26
|
+
return rule.defaultValue;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function putParam(params, rule, value) {
|
|
30
|
+
const serialized = rule.serialize(value);
|
|
31
|
+
const next = serialized === rule.serialize(rule.defaultValue) ? null : serialized;
|
|
32
|
+
const current = params.getAll(rule.key);
|
|
33
|
+
if (next === null ? current.length === 0 : current.length === 1 && current[0] === next) return null;
|
|
34
|
+
if (next === null) params.delete(rule.key);
|
|
35
|
+
else params.set(rule.key, next);
|
|
36
|
+
return rule.history === "push" || rule.history === "replace-on-clear" && next !== null;
|
|
37
|
+
}
|
|
38
|
+
const queuedByLocation = /* @__PURE__ */ new WeakMap();
|
|
39
|
+
const NO_DATA_ROUTER = createContext(null);
|
|
40
|
+
const DataRouterContext = readDataRouterContext();
|
|
41
|
+
function readDataRouterContext() {
|
|
42
|
+
try {
|
|
43
|
+
return ReactRouter.UNSAFE_DataRouterContext ?? NO_DATA_ROUTER;
|
|
44
|
+
} catch {
|
|
45
|
+
return NO_DATA_ROUTER;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function writeQuery(location, navigate, dataRouter, change) {
|
|
49
|
+
let queued = queuedByLocation.get(location);
|
|
50
|
+
if (!queued) {
|
|
51
|
+
queued = {
|
|
52
|
+
params: new URLSearchParams(location.search),
|
|
53
|
+
state: location.state,
|
|
54
|
+
pushedThisTick: false,
|
|
55
|
+
lastPushed: false
|
|
56
|
+
};
|
|
57
|
+
queuedByLocation.set(location, queued);
|
|
58
|
+
}
|
|
59
|
+
const before = queued.params.toString();
|
|
60
|
+
const wantsPush = change(queued.params);
|
|
61
|
+
const search = queued.params.toString();
|
|
62
|
+
if (search === before) return;
|
|
63
|
+
const loading = (dataRouter?.router?.state?.navigation?.state ?? "idle") !== "idle";
|
|
64
|
+
const push = queued.lastPushed && loading || wantsPush && !queued.pushedThisTick;
|
|
65
|
+
if (push) {
|
|
66
|
+
queued.state = null;
|
|
67
|
+
if (!queued.pushedThisTick) {
|
|
68
|
+
queued.pushedThisTick = true;
|
|
69
|
+
const record = queued;
|
|
70
|
+
queueMicrotask(() => {
|
|
71
|
+
record.pushedThisTick = false;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
queued.lastPushed = push;
|
|
76
|
+
void navigate(`?${search}`, push ? void 0 : { replace: true, state: carriedState(queued.state) });
|
|
77
|
+
}
|
|
78
|
+
function useQueryWriter() {
|
|
79
|
+
const location = useLocation();
|
|
80
|
+
const navigate = useNavigate();
|
|
81
|
+
const dataRouter = useContext(DataRouterContext);
|
|
82
|
+
const params = useMemo(() => new URLSearchParams(location.search), [location.search]);
|
|
83
|
+
return [params, (change) => writeQuery(location, navigate, dataRouter, change)];
|
|
84
|
+
}
|
|
85
|
+
function useSearchParamState(key, defaultValue, options = {}) {
|
|
86
|
+
const [params, write] = useQueryWriter();
|
|
87
|
+
const rule = paramRule(key, defaultValue, options);
|
|
88
|
+
const value = readParam(params, rule);
|
|
89
|
+
const setValue = (next) => write((query) => {
|
|
90
|
+
const resolved = typeof next === "function" ? next(readParam(query, rule)) : next;
|
|
91
|
+
return putParam(query, rule, resolved) === true;
|
|
92
|
+
});
|
|
43
93
|
return [value, setValue];
|
|
44
94
|
}
|
|
95
|
+
function useSearchParamsState(fields) {
|
|
96
|
+
const [params, write] = useQueryWriter();
|
|
97
|
+
const rules = Object.keys(fields).map((name) => {
|
|
98
|
+
const field = fields[name];
|
|
99
|
+
return [name, paramRule(field.param ?? name, field.default, field)];
|
|
100
|
+
});
|
|
101
|
+
const readAll = (query) => Object.fromEntries(rules.map(([name, rule]) => [name, readParam(query, rule)]));
|
|
102
|
+
const ownParams = JSON.stringify(rules.map(([name, rule]) => [name, params.getAll(rule.key)]));
|
|
103
|
+
const values = useMemo(() => readAll(params), [ownParams]);
|
|
104
|
+
const setValues = (next) => write((query) => {
|
|
105
|
+
const patch = typeof next === "function" ? next(readAll(query)) : next;
|
|
106
|
+
let push = false;
|
|
107
|
+
for (const [name, rule] of rules) {
|
|
108
|
+
const value = patch[name];
|
|
109
|
+
if (value === void 0) continue;
|
|
110
|
+
if (putParam(query, rule, value) === true) push = true;
|
|
111
|
+
}
|
|
112
|
+
return push;
|
|
113
|
+
});
|
|
114
|
+
return [values, setValues];
|
|
115
|
+
}
|
|
45
116
|
function useTabParam(defaultTab, options = {}) {
|
|
46
117
|
const { key = "tab", tabs } = options;
|
|
47
118
|
return useSearchParamState(key, defaultTab, {
|
|
@@ -89,6 +160,7 @@ function useDialogParam(param) {
|
|
|
89
160
|
export {
|
|
90
161
|
useDialogParam,
|
|
91
162
|
useSearchParamState,
|
|
163
|
+
useSearchParamsState,
|
|
92
164
|
useTabParam
|
|
93
165
|
};
|
|
94
166
|
//# sourceMappingURL=use-search-param-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/use-search-param-state.ts"],"sourcesContent":["import { useLocation, useNavigate, useSearchParams } from \"react-router\";\n\ntype Updater<T> = T | ((prev: T) => T);\n\nexport interface SearchParamStateOptions<T> {\n /**\n * The value of a param that IS present. Return `undefined` (or throw) for a value\n * that does not parse — a hand-edited or stale link — and the default is used.\n * Default: the raw string.\n */\n parse?: (raw: string) => T | undefined;\n /**\n * The param for a value, or `null` to remove it. Default: `String(value)`, and\n * `null` for `null` / `undefined`. A value that serialises the same as the default\n * removes the param too, so the default is always the clean URL.\n */\n serialize?: (value: T) => string | null;\n /** Shorthand for `history: \"replace\"`. */\n replace?: boolean;\n /**\n * What a change does to the browser history:\n * - `\"push\"` (default): a new entry, so Back undoes the change.\n * - `\"replace\"`: the current entry is rewritten — a tab, a sort, a view toggle,\n * which are not steps anyone wants Back to walk through.\n * - `\"replace-on-clear\"`: push when a value is set, replace when it is cleared (the\n * \"open a form, close it\" pattern).\n */\n history?: \"push\" | \"replace\" | \"replace-on-clear\";\n}\n\nconst defaultSerialize = (value: unknown): string | null =>\n value === null || value === undefined ? null : String(value);\n\n/** The route state of the current entry, carried over a `replace` so a query rewrite\n * does not drop what a navigation put there (a dialog's opener mark, below). */\nfunction carriedState(state: unknown): Record<string, unknown> | undefined {\n return state && typeof state === \"object\" ? (state as Record<string, unknown>) : undefined;\n}\n\n/**\n * One URL search param as React state: `const [view, setView] = useSearchParamState(\"view\", \"list\")`.\n *\n * Replaces the hand-rolled `setParams((prev) => { const p = new URLSearchParams(prev);\n * …set/delete…; return p })` blocks that keksdose had in a dozen pages and kastlan ported\n * as its own copy of this hook (shared/hooks/use-search-param-state.ts, both apps). The\n * kit's version takes the DEFAULT as an argument rather than inside `parse`, so the\n * two rules that follow from it cannot be forgotten at a call site:\n *\n * * an absent or unparseable param reads as the default, and\n * * setting the default removes the param — the default view is the clean URL.\n *\n * Every other param in the query string is left as it is. Two updates in one tick do\n * not compose — react-router resolves each against the params of the last render.\n * Requires a react-router Router.\n */\nexport function useSearchParamState<T = string>(\n key: string,\n defaultValue: T,\n options: SearchParamStateOptions<T> = {},\n): [T, (next: Updater<T>) => void] {\n const { parse, serialize = defaultSerialize as (value: T) => string | null } = options;\n const history = options.history ?? (options.replace ? \"replace\" : \"push\");\n const [params, setParams] = useSearchParams();\n const location = useLocation();\n\n const read = (raw: string | null): T => {\n if (raw === null) return defaultValue;\n if (!parse) return raw as unknown as T;\n try {\n const parsed = parse(raw);\n return parsed === undefined ? defaultValue : parsed;\n } catch {\n return defaultValue;\n }\n };\n const value = read(params.get(key));\n const defaultSerialized = serialize(defaultValue);\n const toParam = (v: T): string | null => {\n const s = serialize(v);\n return s === defaultSerialized ? null : s;\n };\n\n const setValue = (next: Updater<T>) => {\n // Resolved against the rendered value only to choose the history mode; the write\n // resolves again inside react-router's updater, against the params it hands over.\n const preview = typeof next === \"function\" ? (next as (prev: T) => T)(value) : next;\n const replace = history === \"replace\" || (history === \"replace-on-clear\" && toParam(preview) === null);\n setParams(\n (prev) => {\n const p = new URLSearchParams(prev);\n const resolved = typeof next === \"function\" ? (next as (prev: T) => T)(read(p.get(key))) : next;\n const serialized = toParam(resolved);\n if (serialized === null) p.delete(key);\n else p.set(key, serialized);\n return p;\n },\n replace ? { replace, state: carriedState(location.state) } : undefined,\n );\n };\n\n return [value, setValue];\n}\n\n/**\n * The active tab in `?tab=` (or `key`), with the default tab as the clean URL, for the\n * kit's `Tabs`:\n *\n * const [tab, setTab] = useTabParam(\"overview\", { tabs: [\"overview\", \"history\"] });\n * <Tabs tabs={…} active={tab} onChange={setTab} />\n *\n * Switching tabs REPLACES the history entry — a tab is a view of this page, not a\n * place Back should step through. `tabs`, when given, turns a param naming no tab (a\n * renamed tab, an old link) into the default rather than into a blank panel.\n * kastlan's use-tab-param.ts, with the validation it did not have.\n */\nexport function useTabParam<T extends string>(\n defaultTab: T,\n options: { key?: string; tabs?: readonly T[] } = {},\n): [T, (tab: T) => void] {\n const { key = \"tab\", tabs } = options;\n return useSearchParamState<T>(key, defaultTab, {\n parse: (raw) => (!tabs || (tabs as readonly string[]).includes(raw) ? (raw as T) : undefined),\n history: \"replace\",\n });\n}\n\n/** Where a dialog's open state lives: a param's presence (`\"edit\"` → `?edit=1`), or one\n * value of a shared param (`{ key: \"dialog\", value: \"create-lease\" }`). */\nexport type DialogParam = string | { key: string; value: string };\n\n/** The route-state mark an opener leaves on the entry it pushes, so the close knows it\n * may go BACK over it rather than add a second entry. */\nconst OPENED_BY_KIT = \"__uiKitDialogParam\";\n\n/**\n * A dialog's open state in the URL, for `Modal`'s `urlParam` and anything else that\n * opens one: `const [open, setOpen] = useDialogParam({ key: \"dialog\", value: \"create\" })`.\n *\n * * **Opening pushes** an entry, so the platform Back gesture closes the dialog — by\n * leaving the entry — and Forward opens it again, like any other step.\n * * **Closing goes back** over that entry when this hook pushed it, so a closed dialog\n * leaves no dead entry behind. A dialog that arrived OPEN (a deep link, a reload, a\n * plain `<Link>` to it) has nothing of ours to go back over, and its close removes the\n * param in place instead — Back from there leaves the page, as it should.\n *\n * That is why it is not `useSearchParamState`: going back is the only close that\n * leaves the history as it was before the dialog, and only the opener knows whether it\n * may.\n */\nexport function useDialogParam(param: DialogParam): [boolean, (open: boolean) => void] {\n const { key, value } = typeof param === \"string\" ? { key: param, value: \"1\" } : param;\n const [params, setParams] = useSearchParams();\n const location = useLocation();\n const navigate = useNavigate();\n const open = typeof param === \"string\" ? params.has(key) : params.get(key) === value;\n const mark = `${key}=${value}`;\n\n const setOpen = (next: boolean) => {\n if (next === open) return;\n const state = carriedState(location.state);\n if (next) {\n setParams(\n (prev) => {\n const p = new URLSearchParams(prev);\n p.set(key, value);\n return p;\n },\n { state: { ...state, [OPENED_BY_KIT]: mark } },\n );\n return;\n }\n if (state?.[OPENED_BY_KIT] === mark) {\n void navigate(-1);\n return;\n }\n setParams(\n (prev) => {\n const p = new URLSearchParams(prev);\n p.delete(key);\n return p;\n },\n { replace: true, state },\n );\n };\n\n return [open, setOpen];\n}\n"],"mappings":";AAAA,SAAS,aAAa,aAAa,uBAAuB;AA8B1D,MAAM,mBAAmB,CAAC,UACxB,UAAU,QAAQ,UAAU,SAAY,OAAO,OAAO,KAAK;AAI7D,SAAS,aAAa,OAAqD;AACzE,SAAO,SAAS,OAAO,UAAU,WAAY,QAAoC;AACnF;AAkBO,SAAS,oBACd,KACA,cACA,UAAsC,CAAC,GACN;AACjC,QAAM,EAAE,OAAO,YAAY,iBAAgD,IAAI;AAC/E,QAAM,UAAU,QAAQ,YAAY,QAAQ,UAAU,YAAY;AAClE,QAAM,CAAC,QAAQ,SAAS,IAAI,gBAAgB;AAC5C,QAAM,WAAW,YAAY;AAE7B,QAAM,OAAO,CAAC,QAA0B;AACtC,QAAI,QAAQ,KAAM,QAAO;AACzB,QAAI,CAAC,MAAO,QAAO;AACnB,QAAI;AACF,YAAM,SAAS,MAAM,GAAG;AACxB,aAAO,WAAW,SAAY,eAAe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AAM,WAAW,YAAY;AAC7B,QAAM,WAAW,YAAY;AAC7B,QAAM,OAAO,OAAO,UAAU,WAAW,OAAO,IAAI,GAAG,IAAI,OAAO,IAAI,GAAG,MAAM;AAC/E,QAAM,OAAO,GAAG,GAAG,IAAI,KAAK;AAE5B,QAAM,UAAU,CAAC,SAAkB;AACjC,QAAI,SAAS,KAAM;AACnB,UAAM,QAAQ,aAAa,SAAS,KAAK;AACzC,QAAI,MAAM;AACR;AAAA,QACE,CAAC,SAAS;AACR,gBAAM,IAAI,IAAI,gBAAgB,IAAI;AAClC,YAAE,IAAI,KAAK,KAAK;AAChB,iBAAO;AAAA,QACT;AAAA,QACA,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,aAAa,GAAG,KAAK,EAAE;AAAA,MAC/C;AACA;AAAA,IACF;AACA,QAAI,QAAQ,aAAa,MAAM,MAAM;AACnC,WAAK,SAAS,EAAE;AAChB;AAAA,IACF;AACA;AAAA,MACE,CAAC,SAAS;AACR,cAAM,IAAI,IAAI,gBAAgB,IAAI;AAClC,UAAE,OAAO,GAAG;AACZ,eAAO;AAAA,MACT;AAAA,MACA,EAAE,SAAS,MAAM,MAAM;AAAA,IACzB;AAAA,EACF;AAEA,SAAO,CAAC,MAAM,OAAO;AACvB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/use-search-param-state.ts"],"sourcesContent":["import { createContext, useContext, useMemo, type Context } from \"react\";\nimport * as ReactRouter from \"react-router\";\nimport { useLocation, useNavigate, useSearchParams, type Location, type NavigateFunction } from \"react-router\";\n\ntype Updater<T> = T | ((prev: T) => T);\n\nexport interface SearchParamStateOptions<T> {\n /**\n * The value of a param that IS present. Return `undefined` (or throw) for a value\n * that does not parse — a hand-edited or stale link — and the default is used.\n * Default: the raw string.\n */\n parse?: (raw: string) => T | undefined;\n /**\n * The param for a value, or `null` to remove it. Default: `String(value)`, and\n * `null` for `null` / `undefined`. A value that serialises the same as the default\n * removes the param too, so the default is always the clean URL.\n */\n serialize?: (value: T) => string | null;\n /** Shorthand for `history: \"replace\"`. */\n replace?: boolean;\n /**\n * What a change does to the browser history:\n * - `\"push\"` (default): a new entry, so Back undoes the change.\n * - `\"replace\"`: the current entry is rewritten — a tab, a sort, a view toggle,\n * which are not steps anyone wants Back to walk through.\n * - `\"replace-on-clear\"`: push when a value is set, replace when it is cleared (the\n * \"open a form, close it\" pattern).\n *\n * Several writes in one tick (one handler) add at most ONE entry — see\n * {@link useSearchParamState}.\n */\n history?: \"push\" | \"replace\" | \"replace-on-clear\";\n}\n\nconst defaultSerialize = (value: unknown): string | null =>\n value === null || value === undefined ? null : String(value);\n\n/** The route state of the current entry, carried over a `replace` so a query rewrite\n * does not drop what a navigation put there (a dialog's opener mark, below). */\nfunction carriedState(state: unknown): Record<string, unknown> | undefined {\n return state && typeof state === \"object\" ? (state as Record<string, unknown>) : undefined;\n}\n\n/* ── One param: read and write ───────────────────────────────────────────── */\n\n/** One param's rules — the single hook's arguments, or one field of the multi-key hook. */\ninterface ParamRule<T> {\n key: string;\n defaultValue: T;\n parse?: (raw: string) => T | undefined;\n serialize: (value: T) => string | null;\n history: \"push\" | \"replace\" | \"replace-on-clear\";\n}\n\nfunction paramRule<T>(key: string, defaultValue: T, options: SearchParamStateOptions<T>): ParamRule<T> {\n return {\n key,\n defaultValue,\n parse: options.parse,\n serialize: options.serialize ?? (defaultSerialize as (value: T) => string | null),\n history: options.history ?? (options.replace ? \"replace\" : \"push\"),\n };\n}\n\n/** An absent or unparseable param reads as the default. */\nfunction readParam<T>(params: URLSearchParams, rule: ParamRule<T>): T {\n const raw = params.get(rule.key);\n if (raw === null) return rule.defaultValue;\n if (!rule.parse) return raw as unknown as T;\n try {\n const parsed = rule.parse(raw);\n return parsed === undefined ? rule.defaultValue : parsed;\n } catch {\n return rule.defaultValue;\n }\n}\n\n/**\n * Writes `value` into `params` — the default removes the param. Returns `null` when\n * the param already says that (a write that changes nothing has no say in the history),\n * otherwise whether this change asks for an entry of its own.\n */\nfunction putParam<T>(params: URLSearchParams, rule: ParamRule<T>, value: T): boolean | null {\n const serialized = rule.serialize(value);\n const next = serialized === rule.serialize(rule.defaultValue) ? null : serialized;\n const current = params.getAll(rule.key);\n if (next === null ? current.length === 0 : current.length === 1 && current[0] === next) return null;\n if (next === null) params.delete(rule.key);\n else params.set(rule.key, next);\n return rule.history === \"push\" || (rule.history === \"replace-on-clear\" && next !== null);\n}\n\n/* ── Writes that compose ─────────────────────────────────────────────────── */\n\n/**\n * The query as the writes made against ONE rendered location leave it — shared by every\n * hook on that router, so a write builds on the one before it instead of on the render.\n *\n * Why this exists (keksdose live #378): react-router's `setSearchParams(updater)` hands\n * its updater `new URLSearchParams(searchParams)` — the params of the RENDER the setter\n * came from, in react-router 7 and 8 alike — not the previous call's result. keksdose\n * wired TranslationReviewPanel's `onFilterChange` to four of these setters (status,\n * source, ns, q); each started from the rendered URL, so the last wrote the old values\n * of the other three back and no filter select had any effect.\n *\n * Keyed by react-router's location object, which is one object per committed location\n * per router: every hook under a router reads the same one, a second router (another\n * test) has its own, and when react-router renders the next location this record is\n * unreachable — nothing queued outlives the navigation it belongs to. Until then a\n * later write builds on it even a tick on (a transition or a data router's loaders still\n * pending), which is what keeps two quick clicks from clobbering each other either. The\n * one cost: a navigation a data router's blocker stops leaves its writes here, and the\n * page's next write carries them again — the blocker asks again.\n */\ninterface QueuedQuery {\n /** The query with every write against this location so far. */\n params: URLSearchParams;\n /** The route state of the entry those writes now sit on, carried over a replace. */\n state: unknown;\n /** A write in the current tick pushed; the tick's later writes rewrite that entry. */\n pushedThisTick: boolean;\n /** The last navigation sent was a push. */\n lastPushed: boolean;\n}\n\nconst queuedByLocation = new WeakMap<Location, QueuedQuery>();\n\n/**\n * The data router's own state, read for ONE question: is a navigation still loading?\n * A data router whose loaders run commits a navigation only when they finish, and a\n * second `navigate` before then cancels the first — so a push followed by a replace\n * in the same tick would land as a replace alone. `UNSAFE_DataRouterContext` is in\n * react-router 6.4 through 8; read off the namespace with a stand-in, a release\n * without it costs only that refinement, not the import.\n */\ntype DataRouterProbe = { router?: { state?: { navigation?: { state?: string } } } } | null;\nconst NO_DATA_ROUTER = createContext<DataRouterProbe>(null);\nconst DataRouterContext: Context<DataRouterProbe> = readDataRouterContext();\n\n/**\n * A static member read (so a bundler still tree-shakes the namespace), inside a `try`:\n * a test's `vi.mock(\"react-router\", () => ({ … }))` without the original module throws\n * on ANY export it does not define, and it threw here at import (keksdose, 0.25.0) —\n * the hook then runs without the refinement, as on a router without the context.\n */\nfunction readDataRouterContext(): Context<DataRouterProbe> {\n try {\n return (\n (ReactRouter as unknown as { UNSAFE_DataRouterContext?: Context<DataRouterProbe> }).UNSAFE_DataRouterContext ??\n NO_DATA_ROUTER\n );\n } catch {\n return NO_DATA_ROUTER;\n }\n}\n\n/**\n * One write: `change` edits the queued query in place and says whether a param it\n * changed asks for its own entry. The navigation goes out at once — a lone write\n * behaves exactly as before, and a test can assert right after `act` — carrying the\n * whole queued query, so it includes every write before it.\n *\n * History, per tick (the writes one handler makes before a microtask runs):\n * - the FIRST write that asks to push pushes; every later write in the tick REPLACES\n * that entry, so a handler that sets four params adds one entry, and Back undoes\n * all four at once — they were one change;\n * - a write that asks to replace, before any push, rewrites the entry it found;\n * - so mixed modes combine as \"push if any write asked to push\", which keeps both\n * promises: a push-mode param's change is undone by Back, and a replace-mode param\n * never adds an entry of its own (it rides on the one the push made). A replace\n * write ahead of a push stays on the entry it rewrote, as it would one tick apart.\n * - a write that changes nothing has no say, and sends nothing.\n */\nfunction writeQuery(\n location: Location,\n navigate: NavigateFunction,\n dataRouter: DataRouterProbe,\n change: (params: URLSearchParams) => boolean,\n): void {\n let queued = queuedByLocation.get(location);\n if (!queued) {\n queued = {\n params: new URLSearchParams(location.search),\n state: location.state,\n pushedThisTick: false,\n lastPushed: false,\n };\n queuedByLocation.set(location, queued);\n }\n const before = queued.params.toString();\n const wantsPush = change(queued.params);\n const search = queued.params.toString();\n if (search === before) return;\n\n // A data router still loading our push has not written it to the history yet: a\n // replace now would cancel it. Push again — the new navigation takes its place.\n const loading = (dataRouter?.router?.state?.navigation?.state ?? \"idle\") !== \"idle\";\n const push = (queued.lastPushed && loading) || (wantsPush && !queued.pushedThisTick);\n if (push) {\n queued.state = null;\n if (!queued.pushedThisTick) {\n queued.pushedThisTick = true;\n const record = queued;\n queueMicrotask(() => {\n record.pushedThisTick = false;\n });\n }\n }\n queued.lastPushed = push;\n void navigate(`?${search}`, push ? undefined : { replace: true, state: carriedState(queued.state) });\n}\n\n/** The rendered query, and a write that composes with every other one on the router. */\nfunction useQueryWriter(): [URLSearchParams, (change: (params: URLSearchParams) => boolean) => void] {\n const location = useLocation();\n const navigate = useNavigate();\n const dataRouter = useContext(DataRouterContext);\n const params = useMemo(() => new URLSearchParams(location.search), [location.search]);\n return [params, (change) => writeQuery(location, navigate, dataRouter, change)];\n}\n\n/* ── The hooks ───────────────────────────────────────────────────────────── */\n\n/**\n * One URL search param as React state: `const [view, setView] = useSearchParamState(\"view\", \"list\")`.\n *\n * Replaces the hand-rolled `setParams((prev) => { const p = new URLSearchParams(prev);\n * …set/delete…; return p })` blocks that keksdose had in a dozen pages and kastlan ported\n * as its own copy of this hook (shared/hooks/use-search-param-state.ts, both apps). The\n * kit's version takes the DEFAULT as an argument rather than inside `parse`, so the\n * two rules that follow from it cannot be forgotten at a call site:\n *\n * * an absent or unparseable param reads as the default, and\n * * setting the default removes the param — the default view is the clean URL.\n *\n * Every other param in the query string is left as it is.\n *\n * **Setters compose** (0.25, keksdose live #378): setters called in a row — of one hook,\n * or of several hooks under the same router — each build on the write before them, so\n * `setStatus(\"open\"); setNs(\"legal\")` in one handler leaves both in the URL. react-\n * router's own `setSearchParams(updater)` does not: it hands every updater the params of\n * the render, so the last call used to write the others' old values back. The tick's\n * writes add at most one history entry; see `history`. When the params belong\n * together, {@link useSearchParamsState} writes them with one setter. A functional\n * update receives the value as the writes before it left it.\n *\n * Requires a react-router Router.\n */\nexport function useSearchParamState<T = string>(\n key: string,\n defaultValue: T,\n options: SearchParamStateOptions<T> = {},\n): [T, (next: Updater<T>) => void] {\n const [params, write] = useQueryWriter();\n const rule = paramRule(key, defaultValue, options);\n const value = readParam(params, rule);\n\n const setValue = (next: Updater<T>) =>\n write((query) => {\n // Resolved against the queued query, not the render: a second update in the same\n // handler sees the first one's result, as React's own functional updates do.\n const resolved = typeof next === \"function\" ? (next as (prev: T) => T)(readParam(query, rule)) : next;\n return putParam(query, rule, resolved) === true;\n });\n\n return [value, setValue];\n}\n\n/** One field of {@link useSearchParamsState}: its default, and the single hook's options. */\nexport interface SearchParamField<T> extends SearchParamStateOptions<T> {\n /** The value when the param is absent or does not parse; writing it removes the param. */\n default: T;\n /** The param's name in the URL. Default: the field's name (`namespace: { param: \"ns\" }`). */\n param?: string;\n}\n\n/** The fields of {@link useSearchParamsState}, one per key of the value object. */\nexport type SearchParamFields<V> = { [K in keyof V]: SearchParamField<V[K]> };\n\n/** A partial value (fields left out — or `undefined` — stay as they are), or a function\n * of the current value returning one. */\nexport type SearchParamsUpdate<V> = Partial<V> | ((prev: V) => Partial<V>);\n\n/**\n * Several URL search params as ONE state object, with one setter that writes them in\n * one navigation:\n *\n * const [filter, setFilter] = useSearchParamsState({\n * status: { default: \"all\" as ReviewStatus | \"all\", parse: toStatus },\n * namespace: { param: \"ns\", default: \"all\" },\n * query: { param: \"q\", default: \"\", history: \"replace\" },\n * });\n * <TranslationReviewPanel filter={filter} onFilterChange={setFilter} />\n *\n * keksdose live #378: a filter bar reports all its filters on every change, and four\n * single-param setters in a row clobbered each other (see {@link useSearchParamState},\n * whose setters now compose too). This is the shape that never could: one setter, one\n * write, every field's rules in one place.\n *\n * Each field takes what the single hook takes — `parse`, `serialize`, `history` /\n * `replace` — and its `default` (the clean URL, as there) and optional `param` name.\n * The setter takes a partial object or a function of the current one; fields it leaves\n * out, or sets to `undefined`, stay as they are, and keys that are not fields are\n * ignored, so a component's whole filter object can be handed over as it is. Its\n * history is the single hook's rule over the fields that change: one entry, pushed if\n * any of them asks to push, else the current entry rewritten. Setting what the URL\n * already says navigates nowhere.\n *\n * The value object keeps its identity while its params do not change, so it can sit in\n * a dependency array. Requires a react-router Router.\n */\nexport function useSearchParamsState<V extends object>(\n fields: SearchParamFields<V>,\n): [V, (next: SearchParamsUpdate<V>) => void] {\n const [params, write] = useQueryWriter();\n const rules = (Object.keys(fields) as Array<keyof V & string>).map((name) => {\n const field = fields[name];\n return [name, paramRule(field.param ?? name, field.default, field)] as const;\n });\n const readAll = (query: URLSearchParams): V =>\n Object.fromEntries(rules.map(([name, rule]) => [name, readParam(query, rule)])) as V;\n\n // The fields' own params, not the whole query: another param changing (a tab, a\n // dialog) leaves this object as it was. `fields` is a fresh literal every render;\n // what it reads is the same while the params and the field names are.\n const ownParams = JSON.stringify(rules.map(([name, rule]) => [name, params.getAll(rule.key)]));\n // eslint-disable-next-line react-hooks/exhaustive-deps -- keyed on what the value is read from; see above\n const values = useMemo(() => readAll(params), [ownParams]);\n\n const setValues = (next: SearchParamsUpdate<V>) =>\n write((query) => {\n const patch = typeof next === \"function\" ? next(readAll(query)) : next;\n let push = false;\n for (const [name, rule] of rules) {\n const value = patch[name];\n if (value === undefined) continue;\n if (putParam(query, rule as ParamRule<unknown>, value) === true) push = true;\n }\n return push;\n });\n\n return [values, setValues];\n}\n\n/**\n * The active tab in `?tab=` (or `key`), with the default tab as the clean URL, for the\n * kit's `Tabs`:\n *\n * const [tab, setTab] = useTabParam(\"overview\", { tabs: [\"overview\", \"history\"] });\n * <Tabs tabs={…} active={tab} onChange={setTab} />\n *\n * Switching tabs REPLACES the history entry — a tab is a view of this page, not a\n * place Back should step through. `tabs`, when given, turns a param naming no tab (a\n * renamed tab, an old link) into the default rather than into a blank panel.\n * kastlan's use-tab-param.ts, with the validation it did not have.\n */\nexport function useTabParam<T extends string>(\n defaultTab: T,\n options: { key?: string; tabs?: readonly T[] } = {},\n): [T, (tab: T) => void] {\n const { key = \"tab\", tabs } = options;\n return useSearchParamState<T>(key, defaultTab, {\n parse: (raw) => (!tabs || (tabs as readonly string[]).includes(raw) ? (raw as T) : undefined),\n history: \"replace\",\n });\n}\n\n/** Where a dialog's open state lives: a param's presence (`\"edit\"` → `?edit=1`), or one\n * value of a shared param (`{ key: \"dialog\", value: \"create-lease\" }`). */\nexport type DialogParam = string | { key: string; value: string };\n\n/** The route-state mark an opener leaves on the entry it pushes, so the close knows it\n * may go BACK over it rather than add a second entry. */\nconst OPENED_BY_KIT = \"__uiKitDialogParam\";\n\n/**\n * A dialog's open state in the URL, for `Modal`'s `urlParam` and anything else that\n * opens one: `const [open, setOpen] = useDialogParam({ key: \"dialog\", value: \"create\" })`.\n *\n * * **Opening pushes** an entry, so the platform Back gesture closes the dialog — by\n * leaving the entry — and Forward opens it again, like any other step.\n * * **Closing goes back** over that entry when this hook pushed it, so a closed dialog\n * leaves no dead entry behind. A dialog that arrived OPEN (a deep link, a reload, a\n * plain `<Link>` to it) has nothing of ours to go back over, and its close removes the\n * param in place instead — Back from there leaves the page, as it should.\n *\n * That is why it is not `useSearchParamState`: going back is the only close that\n * leaves the history as it was before the dialog, and only the opener knows whether it\n * may.\n */\nexport function useDialogParam(param: DialogParam): [boolean, (open: boolean) => void] {\n const { key, value } = typeof param === \"string\" ? { key: param, value: \"1\" } : param;\n const [params, setParams] = useSearchParams();\n const location = useLocation();\n const navigate = useNavigate();\n const open = typeof param === \"string\" ? params.has(key) : params.get(key) === value;\n const mark = `${key}=${value}`;\n\n const setOpen = (next: boolean) => {\n if (next === open) return;\n const state = carriedState(location.state);\n if (next) {\n setParams(\n (prev) => {\n const p = new URLSearchParams(prev);\n p.set(key, value);\n return p;\n },\n { state: { ...state, [OPENED_BY_KIT]: mark } },\n );\n return;\n }\n if (state?.[OPENED_BY_KIT] === mark) {\n void navigate(-1);\n return;\n }\n setParams(\n (prev) => {\n const p = new URLSearchParams(prev);\n p.delete(key);\n return p;\n },\n { replace: true, state },\n );\n };\n\n return [open, setOpen];\n}\n"],"mappings":";AAAA,SAA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,MAAM,MAAM;AAAA,IACzB;AAAA,EACF;AAEA,SAAO,CAAC,MAAM,OAAO;AACvB;","names":[]}
|
package/dist/i18n/defaults.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { cB as UiKitLabels } from '../feedback-
|
|
1
|
+
import { cB as UiKitLabels } from '../feedback-BXKH-ToU.js';
|
|
2
2
|
import 'react';
|
|
3
3
|
import '../components/tooltip.js';
|
|
4
4
|
import '../hooks/use-anchored-rect.js';
|
|
5
5
|
import '../lib/clipping.js';
|
|
6
|
-
import '../data-table-labels-
|
|
6
|
+
import '../data-table-labels-Cdn1QS2k.js';
|
|
7
7
|
import '../components/data-table-sort.js';
|
|
8
8
|
import '../components/swipeable-row.js';
|
|
9
9
|
import '../components/mini-calendar.js';
|
package/dist/i18n/german.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { cB as UiKitLabels } from '../feedback-
|
|
1
|
+
import { cB as UiKitLabels } from '../feedback-BXKH-ToU.js';
|
|
2
2
|
import 'react';
|
|
3
3
|
import '../components/tooltip.js';
|
|
4
4
|
import '../hooks/use-anchored-rect.js';
|
|
5
5
|
import '../lib/clipping.js';
|
|
6
|
-
import '../data-table-labels-
|
|
6
|
+
import '../data-table-labels-Cdn1QS2k.js';
|
|
7
7
|
import '../components/data-table-sort.js';
|
|
8
8
|
import '../components/swipeable-row.js';
|
|
9
9
|
import '../components/mini-calendar.js';
|
package/dist/i18n/german.js
CHANGED
|
@@ -694,6 +694,7 @@ function germanLabels(numberLocale) {
|
|
|
694
694
|
roleOf: (column) => `Was enth\xE4lt die Spalte \u201E${column}\u201C?`,
|
|
695
695
|
ignore: "Ignorieren",
|
|
696
696
|
requiredRole: (role) => `${role} (erforderlich)`,
|
|
697
|
+
requiredRoleShort: (role) => `${role} *`,
|
|
697
698
|
previewOf: (shown, total) => shown === 1 ? `Die erste von ${n(total)} Zeilen` : `Die ersten ${n(shown)} von ${n(total)} Zeilen`,
|
|
698
699
|
// `roles` arrives joined with "oder" ("Soll oder Haben").
|
|
699
700
|
oneOf: (roles) => `entweder ${roles}`,
|
|
@@ -745,7 +746,13 @@ function germanLabels(numberLocale) {
|
|
|
745
746
|
readOnly: "Sie k\xF6nnen diese Sprache lesen, aber nicht pr\xFCfen.",
|
|
746
747
|
scope: (areas) => `Ihre Pr\xFCfung ist beschr\xE4nkt auf: ${areas}.`,
|
|
747
748
|
exportCorrections: (count) => `Korrekturen exportieren (${n(count)})`,
|
|
748
|
-
failed: "Das hat nicht geklappt. Bitte erneut versuchen."
|
|
749
|
+
failed: "Das hat nicht geklappt. Bitte erneut versuchen.",
|
|
750
|
+
approvedToast: (count) => count === 1 ? "Text best\xE4tigt" : `${n(count)} Texte best\xE4tigt`,
|
|
751
|
+
groupCount: (unreviewed, total) => `${n(unreviewed)} ungepr\xFCft / ${n(total)}`,
|
|
752
|
+
approveGroup: (count) => `Ungepr\xFCfte best\xE4tigen (${n(count)})`,
|
|
753
|
+
// The group's name quoted, as `columnMapper.roleOf`'s column: it is often a key
|
|
754
|
+
// ("billing"), which unquoted would read as part of the sentence.
|
|
755
|
+
confirmGroup: (count, group) => count === 1 ? `Den ungepr\xFCften Text in \u201E${group}\u201C best\xE4tigen?` : `Alle ${n(count)} ungepr\xFCften Texte in \u201E${group}\u201C best\xE4tigen \u2013 auch die nicht angezeigten?`
|
|
749
756
|
}
|
|
750
757
|
};
|
|
751
758
|
}
|