@burojs/ui-shadcn 0.5.0 → 0.7.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/README.md +9 -0
- package/dist/bulk-summary-BWSAS7k2.js +143 -0
- package/dist/bulk-summary-BWSAS7k2.js.map +1 -0
- package/dist/bulk-summary-CrEij5vq.cjs +143 -0
- package/dist/bulk-summary-CrEij5vq.cjs.map +1 -0
- package/dist/candidates-relation-picker-CS_JZ4Fd.js +31 -0
- package/dist/candidates-relation-picker-CS_JZ4Fd.js.map +1 -0
- package/dist/candidates-relation-picker-y5M6_oe4.cjs +31 -0
- package/dist/candidates-relation-picker-y5M6_oe4.cjs.map +1 -0
- package/dist/{check-confirm-dialog-CkaVTPT9.js → check-confirm-dialog-2j0gOd7x.js} +392 -103
- package/dist/check-confirm-dialog-2j0gOd7x.js.map +1 -0
- package/dist/{check-confirm-dialog-BRByTFpg.cjs → check-confirm-dialog-C-NHgMST.cjs} +476 -102
- package/dist/check-confirm-dialog-C-NHgMST.cjs.map +1 -0
- package/dist/{dialog-B_rt9S1c.js → dialog-C123sVQ8.js} +4 -4
- package/dist/dialog-C123sVQ8.js.map +1 -0
- package/dist/{dialog-DRNUq9EA.cjs → dialog-vmMdfUWs.cjs} +3 -3
- package/dist/dialog-vmMdfUWs.cjs.map +1 -0
- package/dist/{filter-builder-B3mZFL-K.cjs → filter-builder-DFu0JP-1.cjs} +959 -128
- package/dist/filter-builder-DFu0JP-1.cjs.map +1 -0
- package/dist/{filter-builder-DOnaXNfP.js → filter-builder-DaWHUZuV.js} +863 -116
- package/dist/filter-builder-DaWHUZuV.js.map +1 -0
- package/dist/{flow-runtime-B6zOHYqI.cjs → flow-runtime-BpmrIUb6.cjs} +61 -29
- package/dist/flow-runtime-BpmrIUb6.cjs.map +1 -0
- package/dist/{flow-runtime-D8h99FSg.js → flow-runtime-DyqTmK3H.js} +62 -30
- package/dist/flow-runtime-DyqTmK3H.js.map +1 -0
- package/dist/{flow-screen-CX05b3G9.cjs → flow-screen-Bcz9NF2V.cjs} +132 -88
- package/dist/flow-screen-Bcz9NF2V.cjs.map +1 -0
- package/dist/{flow-screen-CmbARSqg.js → flow-screen-DCdli6Ha.js} +132 -88
- package/dist/flow-screen-DCdli6Ha.js.map +1 -0
- package/dist/index.cjs +951 -605
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +618 -332
- package/dist/index.d.ts +618 -332
- package/dist/index.js +863 -522
- package/dist/index.js.map +1 -1
- package/dist/{inline-flow-host-B7U1OJUe.cjs → inline-flow-host-3vw7LzzD.cjs} +5 -5
- package/dist/inline-flow-host-3vw7LzzD.cjs.map +1 -0
- package/dist/{inline-flow-host-C3H2UpSA.js → inline-flow-host-C0rI9B7f.js} +5 -5
- package/dist/inline-flow-host-C0rI9B7f.js.map +1 -0
- package/dist/label-66W1qbke.js.map +1 -1
- package/dist/label-w6JYf2cF.cjs.map +1 -1
- package/dist/lazy-relation-picker-dialog-Bt8lrEIu.cjs +153 -0
- package/dist/lazy-relation-picker-dialog-Bt8lrEIu.cjs.map +1 -0
- package/dist/lazy-relation-picker-dialog-CAScLPb2.js +135 -0
- package/dist/lazy-relation-picker-dialog-CAScLPb2.js.map +1 -0
- package/dist/markdown/index.d.cts +2 -3
- package/dist/markdown/index.d.ts +2 -3
- package/dist/{page-flow-route-CyXSvXSE.js → page-flow-route-BHUEpn0I.js} +36 -23
- package/dist/page-flow-route-BHUEpn0I.js.map +1 -0
- package/dist/{page-flow-route-CQ7HsbBm.cjs → page-flow-route-DS8IVTVH.cjs} +41 -28
- package/dist/page-flow-route-DS8IVTVH.cjs.map +1 -0
- package/dist/{place-node-SIp4XYQH.cjs → place-node-CNb3w-c7.cjs} +2227 -999
- package/dist/place-node-CNb3w-c7.cjs.map +1 -0
- package/dist/{place-node--GdsP688.js → place-node-CfzQvh4Y.js} +2164 -984
- package/dist/place-node-CfzQvh4Y.js.map +1 -0
- package/dist/{related-list-cards-B6x9HQQp.js → related-list-cards-BIqqY69Y.js} +9 -4
- package/dist/{related-list-cards-B6x9HQQp.js.map → related-list-cards-BIqqY69Y.js.map} +1 -1
- package/dist/{related-list-cards-nxuODlIA.cjs → related-list-cards-CelMxl4q.cjs} +9 -4
- package/dist/{related-list-cards-nxuODlIA.cjs.map → related-list-cards-CelMxl4q.cjs.map} +1 -1
- package/dist/{related-list-timeline-DEdfd-rr.js → related-list-timeline-CRh7xwLD.js} +6 -7
- package/dist/related-list-timeline-CRh7xwLD.js.map +1 -0
- package/dist/{related-list-timeline-BYJKEbmA.cjs → related-list-timeline-DsLdi8sv.cjs} +5 -6
- package/dist/related-list-timeline-DsLdi8sv.cjs.map +1 -0
- package/dist/{related-rows-B4levHcR.js → related-rows--uP2iKQC.js} +27 -17
- package/dist/related-rows--uP2iKQC.js.map +1 -0
- package/dist/{related-rows-zh5f_4QR.cjs → related-rows-MPnLCmPF.cjs} +32 -22
- package/dist/related-rows-MPnLCmPF.cjs.map +1 -0
- package/dist/{search-access-CURsWn-U.js → relation-create-C43cdPQt.js} +596 -29
- package/dist/relation-create-C43cdPQt.js.map +1 -0
- package/dist/{search-access-B7G5oR8n.cjs → relation-create-DDEYcKfw.cjs} +630 -32
- package/dist/relation-create-DDEYcKfw.cjs.map +1 -0
- package/dist/{relation-many-picker-gdAOD-qK.js → relation-many-picker-BJhaEqxz.js} +210 -107
- package/dist/relation-many-picker-BJhaEqxz.js.map +1 -0
- package/dist/{relation-many-picker-B-NCEUgX.cjs → relation-many-picker-DzuGJpEl.cjs} +218 -115
- package/dist/relation-many-picker-DzuGJpEl.cjs.map +1 -0
- package/dist/{relation-picker-BAY77ivO.js → relation-picker-D-tBBZW_.js} +40 -45
- package/dist/relation-picker-D-tBBZW_.js.map +1 -0
- package/dist/{relation-picker-Da_uhFvA.cjs → relation-picker-DaIMzf2H.cjs} +45 -50
- package/dist/relation-picker-DaIMzf2H.cjs.map +1 -0
- package/dist/{relation-picker-dialog-M0pQaWlp.cjs → relation-picker-dialog-9Vg5vvR1.cjs} +142 -40
- package/dist/relation-picker-dialog-9Vg5vvR1.cjs.map +1 -0
- package/dist/{relation-picker-dialog-hA9rYrZB.js → relation-picker-dialog-DoEY8EkH.js} +143 -41
- package/dist/relation-picker-dialog-DoEY8EkH.js.map +1 -0
- package/dist/relation-select-B8Fq4o-t.js +48 -0
- package/dist/relation-select-B8Fq4o-t.js.map +1 -0
- package/dist/relation-select-Cr3CfNLy.cjs +55 -0
- package/dist/relation-select-Cr3CfNLy.cjs.map +1 -0
- package/dist/{resource-page-router-OSQyRA5b.cjs → resource-page-router-C_kGW2o_.cjs} +552 -303
- package/dist/resource-page-router-C_kGW2o_.cjs.map +1 -0
- package/dist/{resource-page-router-T4vS5gbJ.js → resource-page-router-Diw6S6TK.js} +507 -258
- package/dist/resource-page-router-Diw6S6TK.js.map +1 -0
- package/dist/{rich-text-vTyVjDoa.cjs → rich-text-C_7JCvRo.cjs} +2 -2
- package/dist/{rich-text-vTyVjDoa.cjs.map → rich-text-C_7JCvRo.cjs.map} +1 -1
- package/dist/{rich-text-DFerywgz.js → rich-text-RcPBf6hr.js} +2 -2
- package/dist/{rich-text-DFerywgz.js.map → rich-text-RcPBf6hr.js.map} +1 -1
- package/dist/success-notices-Dl3M1fZP.cjs +46 -0
- package/dist/success-notices-Dl3M1fZP.cjs.map +1 -0
- package/dist/success-notices-LDEgEkc4.js +41 -0
- package/dist/success-notices-LDEgEkc4.js.map +1 -0
- package/dist/{toaster-C7CiYA4Z.cjs → toaster-BbByOytP.cjs} +72 -80
- package/dist/toaster-BbByOytP.cjs.map +1 -0
- package/dist/{toaster-CfCRLgR-.js → toaster-Ct_YHGs6.js} +66 -68
- package/dist/toaster-Ct_YHGs6.js.map +1 -0
- package/dist/{use-dialog-filter-state-BDcgS5Oz.js → use-dialog-filter-state-B_MqzHaT.js} +5 -4
- package/dist/use-dialog-filter-state-B_MqzHaT.js.map +1 -0
- package/dist/{use-dialog-filter-state-BBCC0OEK.cjs → use-dialog-filter-state-tNvqAAjh.cjs} +6 -5
- package/dist/use-dialog-filter-state-tNvqAAjh.cjs.map +1 -0
- package/dist/use-theme-DFlpXils.cjs.map +1 -1
- package/dist/use-theme-dnE3Od3I.js.map +1 -1
- package/package.json +11 -11
- package/dist/bulk-summary-CwSd6Yjb.cjs +0 -108
- package/dist/bulk-summary-CwSd6Yjb.cjs.map +0 -1
- package/dist/bulk-summary-GxMDP4bw.js +0 -108
- package/dist/bulk-summary-GxMDP4bw.js.map +0 -1
- package/dist/candidates-gate-CX2PBu6l.js +0 -63
- package/dist/candidates-gate-CX2PBu6l.js.map +0 -1
- package/dist/candidates-gate-DiFI52r7.cjs +0 -70
- package/dist/candidates-gate-DiFI52r7.cjs.map +0 -1
- package/dist/candidates-relation-picker-CBsVcnPR.js +0 -82
- package/dist/candidates-relation-picker-CBsVcnPR.js.map +0 -1
- package/dist/candidates-relation-picker-Dd_GVLlu.cjs +0 -84
- package/dist/candidates-relation-picker-Dd_GVLlu.cjs.map +0 -1
- package/dist/check-confirm-dialog-BRByTFpg.cjs.map +0 -1
- package/dist/check-confirm-dialog-CkaVTPT9.js.map +0 -1
- package/dist/dialog-B_rt9S1c.js.map +0 -1
- package/dist/dialog-DRNUq9EA.cjs.map +0 -1
- package/dist/filter-builder-B3mZFL-K.cjs.map +0 -1
- package/dist/filter-builder-DOnaXNfP.js.map +0 -1
- package/dist/flow-runtime-B6zOHYqI.cjs.map +0 -1
- package/dist/flow-runtime-D8h99FSg.js.map +0 -1
- package/dist/flow-screen-CX05b3G9.cjs.map +0 -1
- package/dist/flow-screen-CmbARSqg.js.map +0 -1
- package/dist/inline-flow-host-B7U1OJUe.cjs.map +0 -1
- package/dist/inline-flow-host-C3H2UpSA.js.map +0 -1
- package/dist/lazy-relation-picker-dialog-2oxnA6IR.js +0 -14
- package/dist/lazy-relation-picker-dialog-2oxnA6IR.js.map +0 -1
- package/dist/lazy-relation-picker-dialog-BfAGKzUG.cjs +0 -19
- package/dist/lazy-relation-picker-dialog-BfAGKzUG.cjs.map +0 -1
- package/dist/page-flow-route-CQ7HsbBm.cjs.map +0 -1
- package/dist/page-flow-route-CyXSvXSE.js.map +0 -1
- package/dist/peek-filter-CnqHwTMU.cjs +0 -51
- package/dist/peek-filter-CnqHwTMU.cjs.map +0 -1
- package/dist/peek-filter-ErLfO153.js +0 -28
- package/dist/peek-filter-ErLfO153.js.map +0 -1
- package/dist/place-node--GdsP688.js.map +0 -1
- package/dist/place-node-SIp4XYQH.cjs.map +0 -1
- package/dist/related-list-timeline-BYJKEbmA.cjs.map +0 -1
- package/dist/related-list-timeline-DEdfd-rr.js.map +0 -1
- package/dist/related-rows-B4levHcR.js.map +0 -1
- package/dist/related-rows-zh5f_4QR.cjs.map +0 -1
- package/dist/relation-create-BOaUe12G.cjs +0 -362
- package/dist/relation-create-BOaUe12G.cjs.map +0 -1
- package/dist/relation-create-Bg-eEJLs.js +0 -337
- package/dist/relation-create-Bg-eEJLs.js.map +0 -1
- package/dist/relation-many-picker-B-NCEUgX.cjs.map +0 -1
- package/dist/relation-many-picker-gdAOD-qK.js.map +0 -1
- package/dist/relation-picker-BAY77ivO.js.map +0 -1
- package/dist/relation-picker-Da_uhFvA.cjs.map +0 -1
- package/dist/relation-picker-dialog-M0pQaWlp.cjs.map +0 -1
- package/dist/relation-picker-dialog-hA9rYrZB.js.map +0 -1
- package/dist/resource-page-router-OSQyRA5b.cjs.map +0 -1
- package/dist/resource-page-router-T4vS5gbJ.js.map +0 -1
- package/dist/search-access-B7G5oR8n.cjs.map +0 -1
- package/dist/search-access-CURsWn-U.js.map +0 -1
- package/dist/shell-BPlk8hEa.js +0 -205
- package/dist/shell-BPlk8hEa.js.map +0 -1
- package/dist/shell-DxhlsPwm.cjs +0 -271
- package/dist/shell-DxhlsPwm.cjs.map +0 -1
- package/dist/toaster-C7CiYA4Z.cjs.map +0 -1
- package/dist/toaster-CfCRLgR-.js.map +0 -1
- package/dist/use-dialog-filter-state-BBCC0OEK.cjs.map +0 -1
- package/dist/use-dialog-filter-state-BDcgS5Oz.js.map +0 -1
|
@@ -39,57 +39,26 @@ function useLinkComponent() {
|
|
|
39
39
|
return (0, react.useContext)(LinkComponentContext);
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
42
|
-
//#region src/layout/language-storage.ts
|
|
43
|
-
const DEFAULT_LANGUAGE = "ru";
|
|
44
|
-
function loadLanguage(storageKey = _burojs_react.DEFAULT_LANGUAGE_STORAGE_KEY) {
|
|
45
|
-
if (typeof window === "undefined") return "ru";
|
|
46
|
-
try {
|
|
47
|
-
const saved = window.localStorage.getItem(storageKey);
|
|
48
|
-
if (saved === "ru" || saved === "en") return saved;
|
|
49
|
-
} catch {}
|
|
50
|
-
return "ru";
|
|
51
|
-
}
|
|
52
|
-
function saveLanguage(code, storageKey = _burojs_react.DEFAULT_LANGUAGE_STORAGE_KEY) {
|
|
53
|
-
if (typeof window === "undefined") return;
|
|
54
|
-
try {
|
|
55
|
-
window.localStorage.setItem(storageKey, code);
|
|
56
|
-
} catch {}
|
|
57
|
-
}
|
|
58
|
-
function loadLocale(storageKey = _burojs_react.DEFAULT_LANGUAGE_STORAGE_KEY) {
|
|
59
|
-
if (typeof window === "undefined") return void 0;
|
|
60
|
-
try {
|
|
61
|
-
return window.localStorage.getItem(storageKey) ?? void 0;
|
|
62
|
-
} catch {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function saveLocale(code, storageKey = _burojs_react.DEFAULT_LANGUAGE_STORAGE_KEY) {
|
|
67
|
-
if (typeof window === "undefined") return;
|
|
68
|
-
try {
|
|
69
|
-
window.localStorage.setItem(storageKey, code);
|
|
70
|
-
} catch {}
|
|
71
|
-
}
|
|
72
|
-
//#endregion
|
|
73
42
|
//#region src/lib/friendly-error.ts
|
|
74
43
|
const DEV_FACING = /^Error \(status code:|^Failed to fetch$|^NetworkError|^Load failed$|^TypeError: (Failed to fetch|NetworkError)/i;
|
|
75
44
|
const NETWORK = /Failed to fetch|NetworkError|Load failed|ERR_INTERNET_DISCONNECTED/i;
|
|
76
45
|
const HTTP_TRACE = /\b(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b[^\n]*->\s*(\d{3})\b/;
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
generic: "Попробуйте повторить действие."
|
|
83
|
-
},
|
|
84
|
-
en: {
|
|
85
|
-
title: "Request failed",
|
|
86
|
-
offline: "Cannot reach the server. Check your connection and try again.",
|
|
87
|
-
unavailable: "The service is temporarily unavailable. Try again in a minute.",
|
|
88
|
-
generic: "Please try again."
|
|
89
|
-
}
|
|
46
|
+
const en = {
|
|
47
|
+
title: "Request failed",
|
|
48
|
+
offline: "Cannot reach the server. Check your connection and try again.",
|
|
49
|
+
unavailable: "The service is temporarily unavailable. Try again in a minute.",
|
|
50
|
+
generic: "Please try again."
|
|
90
51
|
};
|
|
91
|
-
function
|
|
92
|
-
const
|
|
52
|
+
function friendlyStringsFrom(t) {
|
|
53
|
+
const pick = (name) => t(`requestError.${name}`, { defaultValue: en[name] }) || en[name];
|
|
54
|
+
return {
|
|
55
|
+
title: pick("title"),
|
|
56
|
+
offline: pick("offline"),
|
|
57
|
+
unavailable: pick("unavailable"),
|
|
58
|
+
generic: pick("generic")
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function toFriendlyError(message, description, strings) {
|
|
93
62
|
const raw = `${String(message ?? "")} ${String(description ?? "")}`;
|
|
94
63
|
const isDevFacing = DEV_FACING.test(String(message ?? "").trim());
|
|
95
64
|
const isNetwork = NETWORK.test(raw);
|
|
@@ -97,8 +66,8 @@ function toFriendlyError(message, description, locale) {
|
|
|
97
66
|
if (trace) {
|
|
98
67
|
const status = Number(trace[1]);
|
|
99
68
|
return {
|
|
100
|
-
title:
|
|
101
|
-
detail: status >= 500 ?
|
|
69
|
+
title: strings.title,
|
|
70
|
+
detail: status >= 500 ? strings.unavailable : strings.generic,
|
|
102
71
|
replaced: true
|
|
103
72
|
};
|
|
104
73
|
}
|
|
@@ -108,21 +77,42 @@ function toFriendlyError(message, description, locale) {
|
|
|
108
77
|
replaced: false
|
|
109
78
|
};
|
|
110
79
|
return {
|
|
111
|
-
title:
|
|
112
|
-
detail: isNetwork ?
|
|
80
|
+
title: strings.title,
|
|
81
|
+
detail: isNetwork ? strings.offline : String(description ?? "") || strings.generic,
|
|
113
82
|
replaced: true
|
|
114
83
|
};
|
|
115
84
|
}
|
|
85
|
+
function isNetworkFailure(text) {
|
|
86
|
+
return NETWORK.test(text);
|
|
87
|
+
}
|
|
88
|
+
function technicalTexts(error) {
|
|
89
|
+
if (error === null || typeof error !== "object") return [];
|
|
90
|
+
const out = [];
|
|
91
|
+
try {
|
|
92
|
+
const { details, cause } = error;
|
|
93
|
+
if (typeof details === "string") out.push(details);
|
|
94
|
+
else if (details !== null && typeof details === "object") {
|
|
95
|
+
const inner = details.message;
|
|
96
|
+
if (typeof inner === "string") out.push(inner);
|
|
97
|
+
}
|
|
98
|
+
if (cause instanceof Error) out.push(cause.message);
|
|
99
|
+
else if (typeof cause === "string") out.push(cause);
|
|
100
|
+
if (error instanceof Error) out.push(error.message);
|
|
101
|
+
} catch {}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
function technicalText(error) {
|
|
105
|
+
return technicalTexts(error)[0];
|
|
106
|
+
}
|
|
116
107
|
//#endregion
|
|
117
108
|
//#region src/notification/notification-provider.ts
|
|
118
109
|
function createNotificationProvider(options = {}) {
|
|
119
|
-
const resolveLocale = options.resolveLocale ?? (() => loadLocale());
|
|
120
110
|
return {
|
|
121
111
|
open: ({ type, message, description }) => {
|
|
122
112
|
let text = message;
|
|
123
113
|
let detail = description;
|
|
124
114
|
if (type === "error") {
|
|
125
|
-
const friendly = toFriendlyError(message, description,
|
|
115
|
+
const friendly = toFriendlyError(message, description, options.resolveStrings?.() ?? en);
|
|
126
116
|
text = friendly.title;
|
|
127
117
|
detail = friendly.detail;
|
|
128
118
|
}
|
|
@@ -138,34 +128,36 @@ function createNotificationProvider(options = {}) {
|
|
|
138
128
|
function Toaster(props) {
|
|
139
129
|
const t = (0, _burojs_react.useOptionalT)();
|
|
140
130
|
const { resolved: theme } = require_use_theme.useTheme();
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const sink = (0, react.useMemo)(() => createNotificationProvider({ resolveLocale: () => localeRef.current ?? loadLocale() }), []);
|
|
131
|
+
const tRef = (0, react.useRef)(t);
|
|
132
|
+
tRef.current = t;
|
|
133
|
+
const sink = (0, react.useMemo)(() => createNotificationProvider({ resolveStrings: () => friendlyStringsFrom(tRef.current) }), []);
|
|
145
134
|
(0, _burojs_react.useRegisterNotificationSink)(sink);
|
|
135
|
+
const { toastOptions, ...rest } = props;
|
|
136
|
+
const kitClassNames = {
|
|
137
|
+
toast: "group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
|
|
138
|
+
description: "group-[.toast]:text-muted-foreground",
|
|
139
|
+
actionButton: "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
|
|
140
|
+
cancelButton: "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
|
|
141
|
+
closeButton: "group-[.toast]:bg-background group-[.toast]:text-muted-foreground group-[.toast]:border-border group-[.toast]:hover:bg-muted group-[.toast]:hover:text-foreground"
|
|
142
|
+
};
|
|
146
143
|
return (0, react_jsx_runtime.jsx)(sonner.Toaster, {
|
|
147
|
-
|
|
144
|
+
customAriaLabel: props.customAriaLabel ?? props.containerAriaLabel ?? t("notifications.region", { defaultValue: "Notifications" }),
|
|
148
145
|
theme,
|
|
149
146
|
position: "top-right",
|
|
150
147
|
closeButton: true,
|
|
151
148
|
className: "toaster group",
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
149
|
+
...rest,
|
|
150
|
+
toastOptions: {
|
|
151
|
+
...toastOptions,
|
|
152
|
+
classNames: {
|
|
153
|
+
...kitClassNames,
|
|
154
|
+
...toastOptions?.classNames
|
|
155
|
+
},
|
|
156
|
+
closeButtonAriaLabel: toastOptions?.closeButtonAriaLabel ?? t("notifications.close", { defaultValue: "Close notification" })
|
|
157
|
+
}
|
|
160
158
|
});
|
|
161
159
|
}
|
|
162
160
|
//#endregion
|
|
163
|
-
Object.defineProperty(exports, "DEFAULT_LANGUAGE", {
|
|
164
|
-
enumerable: true,
|
|
165
|
-
get: function() {
|
|
166
|
-
return DEFAULT_LANGUAGE;
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
161
|
Object.defineProperty(exports, "LinkComponentProvider", {
|
|
170
162
|
enumerable: true,
|
|
171
163
|
get: function() {
|
|
@@ -208,28 +200,28 @@ Object.defineProperty(exports, "Toaster", {
|
|
|
208
200
|
return Toaster;
|
|
209
201
|
}
|
|
210
202
|
});
|
|
211
|
-
Object.defineProperty(exports, "
|
|
203
|
+
Object.defineProperty(exports, "friendlyStringsFrom", {
|
|
212
204
|
enumerable: true,
|
|
213
205
|
get: function() {
|
|
214
|
-
return
|
|
206
|
+
return friendlyStringsFrom;
|
|
215
207
|
}
|
|
216
208
|
});
|
|
217
|
-
Object.defineProperty(exports, "
|
|
209
|
+
Object.defineProperty(exports, "isNetworkFailure", {
|
|
218
210
|
enumerable: true,
|
|
219
211
|
get: function() {
|
|
220
|
-
return
|
|
212
|
+
return isNetworkFailure;
|
|
221
213
|
}
|
|
222
214
|
});
|
|
223
|
-
Object.defineProperty(exports, "
|
|
215
|
+
Object.defineProperty(exports, "technicalText", {
|
|
224
216
|
enumerable: true,
|
|
225
217
|
get: function() {
|
|
226
|
-
return
|
|
218
|
+
return technicalText;
|
|
227
219
|
}
|
|
228
220
|
});
|
|
229
|
-
Object.defineProperty(exports, "
|
|
221
|
+
Object.defineProperty(exports, "technicalTexts", {
|
|
230
222
|
enumerable: true,
|
|
231
223
|
get: function() {
|
|
232
|
-
return
|
|
224
|
+
return technicalTexts;
|
|
233
225
|
}
|
|
234
226
|
});
|
|
235
227
|
Object.defineProperty(exports, "toFriendlyError", {
|
|
@@ -245,4 +237,4 @@ Object.defineProperty(exports, "useLinkComponent", {
|
|
|
245
237
|
}
|
|
246
238
|
});
|
|
247
239
|
|
|
248
|
-
//# sourceMappingURL=toaster-
|
|
240
|
+
//# sourceMappingURL=toaster-BbByOytP.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toaster-BbByOytP.cjs","names":["PopoverPrimitive","React","cn","forwardRef","createContext","useContext","toast","useOptionalT","useTheme","useRef","useMemo","SonnerToaster"],"sources":["../src/primitives/popover.tsx","../src/layout/link-component.tsx","../src/lib/friendly-error.ts","../src/notification/notification-provider.ts","../src/notification/toaster.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { cn } from '../lib/cn.js';\n\n/**\n * Thin wrapper around Radix Popover, mirroring the structure of the\n * Dialog / Select primitives in this package so the Tailwind tokens\n * stay aligned. Re-exports `Root` / `Trigger` / `Anchor` / `Close`\n * directly (no styling needed) and styles `Content` to match the\n * shadcn Popover defaults.\n */\n\nconst Popover = PopoverPrimitive.Root;\nconst PopoverTrigger = PopoverPrimitive.Trigger;\nconst PopoverAnchor = PopoverPrimitive.Anchor;\nconst PopoverClose = PopoverPrimitive.Close;\n\nexport type PopoverContentProps = React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>;\n\nconst PopoverContent = React.forwardRef<\n React.ElementRef<typeof PopoverPrimitive.Content>,\n PopoverContentProps\n>(({ className, align = 'start', sideOffset = 4, ...props }, ref) => (\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n ref={ref}\n align={align}\n sideOffset={sideOffset}\n className={cn(\n 'z-50 w-72 rounded-md border bg-popover p-3 text-popover-foreground shadow-md outline-hidden',\n 'duration-[var(--duration-overlay)] ease-[var(--ease-overlay)]',\n 'data-[state=open]:animate-in data-[state=closed]:animate-out',\n 'data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',\n 'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',\n 'data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',\n className,\n )}\n {...props}\n />\n </PopoverPrimitive.Portal>\n));\nPopoverContent.displayName = PopoverPrimitive.Content.displayName;\n\nexport { Popover, PopoverTrigger, PopoverAnchor, PopoverClose, PopoverContent };\n","'use client';\nimport {\n type AnchorHTMLAttributes,\n type ComponentType,\n type ReactElement,\n type ReactNode,\n createContext,\n forwardRef,\n useContext,\n} from 'react';\n\n/**\n * Props every `LinkComponent` must accept. We intentionally mirror the\n * native `<a>` API surface so adopters writing a small wrapper around\n * their router's link primitive (next/link, react-router, TanStack\n * Router, etc.) can pass them straight through.\n *\n * `next/link` already accepts these names verbatim. `react-router`'s\n * `<Link>` uses `to` instead of `href` — adopters wrap once:\n *\n * const RouterLink: LinkComponent = ({ href, ...rest }) =>\n * <Link to={href} {...rest} />;\n */\nexport type LinkComponentProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & {\n href: string;\n children?: ReactNode;\n};\n\nexport type LinkComponent = ComponentType<LinkComponentProps>;\n\n/**\n * Default fallback — a plain `<a href>` anchor. Triggers a full\n * document load. Adopters that ship a SPA router (Next.js App Router,\n * react-router) install their router's `<Link>` via\n * `<LinkComponentProvider>` so internal navigation stays client-side.\n */\nconst DefaultLinkComponent: LinkComponent = forwardRef<HTMLAnchorElement, LinkComponentProps>(\n function DefaultLinkComponent({ children, ...rest }, ref) {\n return (\n <a ref={ref} {...rest}>\n {children}\n </a>\n );\n },\n);\n\nconst LinkComponentContext = createContext<LinkComponent>(DefaultLinkComponent);\n\nexport interface LinkComponentProviderProps {\n /**\n * The router-aware Link component to use throughout `@burojs/ui-shadcn` for\n * internal navigation. Pass `Link` from `next/link` for Next.js App Router;\n * wrap your router's link primitive once for react-router / TanStack Router.\n */\n linkComponent: LinkComponent;\n children: ReactNode;\n}\n\n/**\n * Install a router-aware `LinkComponent` for every framework component that\n * renders an internal navigation link (sidebar entries, action links, relation\n * cells, the list-empty Create CTA, …). Without it the framework falls back to\n * a raw `<a>` — correct, but a full document reload on every click.\n *\n * This is a link component and nothing else: the location and imperative\n * navigation are the `RouterAdapter`'s (`RouterAdapterProvider` and\n * `useRouteNavigate` from `@burojs/react`), the one router seam.\n *\n * import Link from 'next/link';\n * <LinkComponentProvider linkComponent={Link}>\n * <App />\n * </LinkComponentProvider>\n */\nexport function LinkComponentProvider({\n linkComponent,\n children,\n}: LinkComponentProviderProps): ReactElement {\n return (\n <LinkComponentContext.Provider value={linkComponent}>{children}</LinkComponentContext.Provider>\n );\n}\n\n/**\n * Read the current `LinkComponent`. Call this from any framework\n * component that needs to render an internal-navigation link, then\n * use the returned component in JSX:\n *\n * const RouterLink = useLinkComponent();\n * return <RouterLink href={href}>{label}</RouterLink>;\n *\n * Always returns a usable component — the default fallback emits a\n * raw `<a href>` so the component never has to null-check.\n */\nexport function useLinkComponent(): LinkComponent {\n return useContext(LinkComponentContext);\n}\n","/**\n * Turn a developer-facing error string into something a user can act on.\n *\n * Two surfaces need this and they are reached by different code paths — the\n * notification provider (a legacy query adapter's default query-error\n * toast) and the inline\n * error panel a list renders in place of its rows. Fixing only the first left\n * `/document_document` still printing a raw English «Failed to fetch» under a\n * Russian heading, which is how this ended up in a second acceptance round.\n * One helper, both call sites.\n *\n * Anything we do not recognise is passed through unchanged: a message written\n * by the adopter's own `onError` is almost certainly better than a generic\n * substitute.\n */\n\n/** A legacy query adapter's own untranslated wording plus the raw fetch/network failures. */\nconst DEV_FACING =\n /^Error \\(status code:|^Failed to fetch$|^NetworkError|^Load failed$|^TypeError: (Failed to fetch|NetworkError)/i;\nconst NETWORK = /Failed to fetch|NetworkError|Load failed|ERR_INTERNET_DISCONNECTED/i;\n/**\n * A machine transport trace, e.g.\n * «Temporal GET /namespaces/default/schedules?maximumPageSize=10 -> 502»\n *\n * A data provider that reports which call failed is doing the right thing —\n * that string belongs in a bug report. It does not belong in front of an\n * operator as the entire explanation of why their page is empty, which is\n * exactly what `/schedules` did when the Temporal cluster went down.\n *\n * Recognised by an HTTP verb followed by an arrow and a status code; nothing\n * an adopter would hand-write looks like this, so the pass-through contract\n * for adopter-authored messages is preserved.\n */\nconst HTTP_TRACE = /\\b(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\\b[^\\n]*->\\s*(\\d{3})\\b/;\n\n/** The four sentences a recognised failure is replaced with: the bundle keys `requestError.*`. */\nexport interface FriendlyErrorStrings {\n readonly title: string;\n readonly offline: string;\n readonly unavailable: string;\n readonly generic: string;\n}\n\n/**\n * The framework's code language: used where no i18n is configured, and for any\n * key the active bundles do not carry.\n */\nexport const en: FriendlyErrorStrings = {\n title: 'Request failed',\n offline: 'Cannot reach the server. Check your connection and try again.',\n unavailable: 'The service is temporarily unavailable. Try again in a minute.',\n generic: 'Please try again.',\n};\n\n/**\n * Resolve {@link FriendlyErrorStrings} through a translate function (`useT()`,\n * `useOptionalT()`), taking the English default for each key it cannot find.\n */\nexport function friendlyStringsFrom(\n t: (key: string, options?: { defaultValue?: string }) => string,\n): FriendlyErrorStrings {\n const pick = (name: keyof FriendlyErrorStrings): string =>\n t(`requestError.${name}`, { defaultValue: en[name] }) || en[name];\n return {\n title: pick('title'),\n offline: pick('offline'),\n unavailable: pick('unavailable'),\n generic: pick('generic'),\n };\n}\n\nexport interface FriendlyError {\n /** Short headline. Empty when the original message should be kept. */\n title: string;\n /** Explanation the user can act on. */\n detail: string;\n /** True when the input was recognised as developer-facing and replaced. */\n replaced: boolean;\n}\n\n/**\n * @param strings the sentences to substitute, already in the active language:\n * {@link friendlyStringsFrom} builds them from the app's translate function,\n * and {@link en} is the default where none is configured.\n */\nexport function toFriendlyError(\n message: unknown,\n description: unknown,\n strings: FriendlyErrorStrings,\n): FriendlyError {\n const raw = `${String(message ?? '')} ${String(description ?? '')}`;\n const isDevFacing = DEV_FACING.test(String(message ?? '').trim());\n const isNetwork = NETWORK.test(raw);\n const trace = HTTP_TRACE.exec(String(message ?? '').trim());\n\n if (trace) {\n // 5xx is the server's problem and waiting is the right advice; anything\n // else is at least not something the operator can read a URL out of.\n const status = Number(trace[1]);\n return {\n title: strings.title,\n detail: status >= 500 ? strings.unavailable : strings.generic,\n replaced: true,\n };\n }\n\n if (!isDevFacing && !isNetwork) {\n return {\n title: String(message ?? ''),\n detail: String(description ?? ''),\n replaced: false,\n };\n }\n return {\n title: strings.title,\n detail: isNetwork ? strings.offline : String(description ?? '') || strings.generic,\n replaced: true,\n };\n}\n\n/** Whether a technical text says the network itself failed (a dead connection, a refused fetch). */\nexport function isNetworkFailure(text: string): boolean {\n return NETWORK.test(text);\n}\n\n/**\n * Every developer-facing text a failure carries, most specific first: string `details`, else\n * `details.message`; then an `Error` cause's message or a string cause; then the message of the\n * error itself when it is a plain `Error`. A provider's `details` is often its own sentence\n * (\"did not answer a mutation; it may have been applied\"), so the thrown fetch error in `cause`\n * must stay readable behind it. A `DataError`'s `message` is a reference a user may read; this is\n * what it no longer carries.\n */\nexport function technicalTexts(error: unknown): readonly string[] {\n if (error === null || typeof error !== 'object') return [];\n const out: string[] = [];\n try {\n const { details, cause } = error as { readonly details?: unknown; readonly cause?: unknown };\n if (typeof details === 'string') out.push(details);\n else if (details !== null && typeof details === 'object') {\n const inner = (details as { readonly message?: unknown }).message;\n if (typeof inner === 'string') out.push(inner);\n }\n if (cause instanceof Error) out.push(cause.message);\n // The normaliser moves a legacy string `message` into `cause`.\n else if (typeof cause === 'string') out.push(cause);\n if (error instanceof Error) out.push(error.message);\n } catch {\n // A getter that throws on a hostile error object: there is no more technical text to read.\n }\n return out;\n}\n\n/** The first of {@link technicalTexts}: for the friendly path and development logs only. */\nexport function technicalText(error: unknown): string | undefined {\n return technicalTexts(error)[0];\n}\n","import type { NotificationSinkMessage } from '@burojs/react';\nimport { toast } from 'sonner';\nimport { type FriendlyErrorStrings, en, toFriendlyError } from '../lib/friendly-error.js';\n\n/** `<Toaster>`'s sink: `@burojs/react`'s `NotificationSink`, plus `close`. */\nexport interface NotificationSink {\n open(args: NotificationSinkMessage): void;\n close(key: string): void;\n}\n\n/**\n * A legacy query adapter can build its default query-error notification outside\n * our i18n bundle: the user saw «Error (status code: undefined)» / «Failed to fetch», plus it duplicated\n * the inline error state a list already renders. We can't localize a string we\n * don't own, so `toFriendlyError` recognises it and substitutes plain language.\n * The SAME helper backs the list's inline panel — see friendly-error.ts for why\n * that matters.\n */\nexport interface NotificationProviderOptions {\n /**\n * The sentences an error toast is rewritten with (`requestError.*` in the active bundle), or\n * `undefined` for the English defaults. `<Toaster>` passes one built from the app's translate\n * function; a sink built outside React passes its own.\n *\n * ⚠️ It is a FUNCTION, not a value, and that is load-bearing: both examples\n * build this sink once (`React.useMemo(…, [])`) and it has no React context\n * to subscribe to, so strings captured at construction would freeze in\n * whatever language was active on the first render. Called per toast instead.\n */\n readonly resolveStrings?: () => FriendlyErrorStrings | undefined;\n}\n\nexport function createNotificationProvider(\n options: NotificationProviderOptions = {},\n): NotificationSink {\n return {\n open: ({ type, message, description }) => {\n let text = message;\n let detail = description;\n if (type === 'error') {\n const friendly = toFriendlyError(message, description, options.resolveStrings?.() ?? en);\n text = friendly.title;\n detail = friendly.detail;\n }\n // `info` is a plain notice that dismisses itself — never `toast.loading`,\n // whose spinner stays on screen until someone closes it.\n const fn = type === 'error' ? toast.error : type === 'info' ? toast.info : toast.success;\n fn(text, { description: detail });\n },\n close: (key: string) => {\n toast.dismiss(key);\n },\n };\n}\n","'use client';\nimport { useOptionalT, useRegisterNotificationSink } from '@burojs/react';\nimport { useMemo, useRef } from 'react';\nimport { Toaster as SonnerToaster, type ToasterProps as SonnerProps, toast } from 'sonner';\nimport { friendlyStringsFrom } from '../lib/friendly-error.js';\nimport { useTheme } from '../layout/use-theme.js';\nimport { createNotificationProvider } from './notification-provider.js';\n\nexport interface ToasterProps extends SonnerProps {}\n\n/**\n * Shadcn-canonical Sonner setup, and — inside a `<BuroProvider>` — the app's\n * notification sink: the dispatcher's default `notify` (every handler's\n * `notify`, and a thrown handler's error) is delivered here. Outside a\n * provider it registers nothing and still renders anything sent with `toast()`.\n *\n * Bound to design tokens via `toastOptions.classNames`, so toasts inherit the\n * app's light/dark theme through the same CSS-variable cascade as the rest of\n * the UI; `theme` is reactive via `useTheme()`. The error sentences come from\n * the ACTIVE bundle (`requestError.*`), read per toast so a language switch is\n * honoured; with no i18n provider they are the English defaults.\n */\nexport function Toaster(props: ToasterProps): React.ReactElement {\n // `useOptionalT`: the toaster may sit outside a BuroProvider, so it must\n // degrade rather than throw.\n const t = useOptionalT();\n const { resolved: theme } = useTheme();\n const tRef = useRef(t);\n tRef.current = t;\n const sink = useMemo(\n () => createNotificationProvider({ resolveStrings: () => friendlyStringsFrom(tRef.current) }),\n [],\n );\n useRegisterNotificationSink(sink);\n\n const { toastOptions, ...rest } = props;\n const kitClassNames = {\n toast:\n 'group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg',\n description: 'group-[.toast]:text-muted-foreground',\n actionButton: 'group-[.toast]:bg-primary group-[.toast]:text-primary-foreground',\n cancelButton: 'group-[.toast]:bg-muted group-[.toast]:text-muted-foreground',\n closeButton:\n 'group-[.toast]:bg-background group-[.toast]:text-muted-foreground group-[.toast]:border-border group-[.toast]:hover:bg-muted group-[.toast]:hover:text-foreground',\n };\n\n return (\n <SonnerToaster\n /*\n ⚠️ Sonner's default accessible name is \"Notifications alt+T\" and reaches\n the accessibility tree on every page. `customAriaLabel` replaces it\n wholly (the hotkey hint leaves the name) with the adopter's own\n `customAriaLabel` or `containerAriaLabel` (sonner 2 ignores the latter\n once the former is set, so it is honoured here), else the bundle's\n `notifications.region`. The literal fallback is English, like every\n framework default.\n */\n customAriaLabel={\n props.customAriaLabel ??\n props.containerAriaLabel ??\n t('notifications.region', { defaultValue: 'Notifications' })\n }\n theme={theme}\n position=\"top-right\"\n closeButton\n className=\"toaster group\"\n {...rest}\n /*\n The adopter's `toastOptions` merge with ours instead of replacing them:\n the adopter wins per key, and per slot inside `classNames`. The close\n button's label is the bundle's `notifications.close` unless the adopter\n names their own.\n */\n toastOptions={{\n ...toastOptions,\n classNames: { ...kitClassNames, ...toastOptions?.classNames },\n closeButtonAriaLabel:\n toastOptions?.closeButtonAriaLabel ??\n t('notifications.close', { defaultValue: 'Close notification' }),\n }}\n />\n );\n}\n\nexport { toast };\n"],"mappings":";;;;;;;;;AAcA,MAAM,UAAUA,wBAAiB;AACjC,MAAM,iBAAiBA,wBAAiB;AACxC,MAAM,gBAAgBA,wBAAiB;AACvC,MAAM,eAAeA,wBAAiB;AAItC,MAAM,iBAAiBC,MAAM,YAG1B,EAAE,WAAW,QAAQ,SAAS,aAAa,GAAG,GAAG,SAAS,SAC3D,GAAA,kBAAA,IAAA,CAACD,wBAAiB,QAAlB,EAAA,WACE,GAAA,kBAAA,IAAA,CAACA,wBAAiB,SAAlB;CACO;CACE;CACK;CACZ,WAAWE,kBAAAA,GACT,+FACA,iEACA,gEACA,8DACA,gEACA,+JACA,SACF;CACA,GAAI;AACL,CAAA,EACsB,CAAA,CAC1B;AACD,eAAe,cAAcF,wBAAiB,QAAQ;;;ACPtD,MAAM,wBAAA,GAAsCG,MAAAA,WAAAA,CAC1C,SAAS,qBAAqB,EAAE,UAAU,GAAG,QAAQ,KAAK;CACxD,QACE,GAAA,kBAAA,IAAA,CAAC,KAAD;EAAQ;EAAK,GAAI;EACd;CACA,CAAA;AAEP,CACF;AAEA,MAAM,wBAAA,GAAuBC,MAAAA,cAAAA,CAA6B,oBAAoB;AA2B9E,SAAgB,sBAAsB,EACpC,eACA,YAC2C;CAC3C,QACE,GAAA,kBAAA,IAAA,CAAC,qBAAqB,UAAtB;EAA+B,OAAO;EAAgB;CAAwC,CAAA;AAElG;AAaA,SAAgB,m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AAsB,oBAAoB,KAAK,OAAO,EAAE,CAAC,GAC5F,CAAC,CACH;CACA,CAAA,GAAA,cAAA,4BAAA,CAA4B,IAAI;CAEhC,MAAM,EAAE,cAAc,GAAG,SAAS;CAClC,MAAM,gBAAgB;EACpB,OACE;EACF,aAAa;EACb,cAAc;EACd,cAAc;EACd,aACE;CACJ;CAEA,QACE,GAAA,kBAAA,IAAA,CAACC,OAAAA,SAAD;EAUE,iBACE,MAAM,mBACN,MAAM,sBACN,EAAE,wBAAwB,EAAE,cAAc,gBAAgB,CAAC;EAEtD;EACP,UAAS;EACT,aAAA;EACA,WAAU;EACV,GAAI;EAOJ,cAAc;GACZ,GAAG;GACH,YAAY;IAAE,GAAG;IAAe,GAAG,cAAc;GAAW;GAC5D,sBACE,cAAc,wBACd,EAAE,uBAAuB,EAAE,cAAc,qBAAqB,CAAC;EACnE;CACD,CAAA;AAEL"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { l as cn, n as useTheme } from "./use-theme-dnE3Od3I.js";
|
|
2
|
-
import {
|
|
2
|
+
import { useOptionalT, useRegisterNotificationSink } from "@burojs/react";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { createContext, forwardRef, useContext, useMemo, useRef } from "react";
|
|
5
5
|
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
@@ -38,57 +38,26 @@ function useLinkComponent() {
|
|
|
38
38
|
return useContext(LinkComponentContext);
|
|
39
39
|
}
|
|
40
40
|
//#endregion
|
|
41
|
-
//#region src/layout/language-storage.ts
|
|
42
|
-
const DEFAULT_LANGUAGE = "ru";
|
|
43
|
-
function loadLanguage(storageKey = DEFAULT_LANGUAGE_STORAGE_KEY) {
|
|
44
|
-
if (typeof window === "undefined") return "ru";
|
|
45
|
-
try {
|
|
46
|
-
const saved = window.localStorage.getItem(storageKey);
|
|
47
|
-
if (saved === "ru" || saved === "en") return saved;
|
|
48
|
-
} catch {}
|
|
49
|
-
return "ru";
|
|
50
|
-
}
|
|
51
|
-
function saveLanguage(code, storageKey = DEFAULT_LANGUAGE_STORAGE_KEY) {
|
|
52
|
-
if (typeof window === "undefined") return;
|
|
53
|
-
try {
|
|
54
|
-
window.localStorage.setItem(storageKey, code);
|
|
55
|
-
} catch {}
|
|
56
|
-
}
|
|
57
|
-
function loadLocale(storageKey = DEFAULT_LANGUAGE_STORAGE_KEY) {
|
|
58
|
-
if (typeof window === "undefined") return void 0;
|
|
59
|
-
try {
|
|
60
|
-
return window.localStorage.getItem(storageKey) ?? void 0;
|
|
61
|
-
} catch {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function saveLocale(code, storageKey = DEFAULT_LANGUAGE_STORAGE_KEY) {
|
|
66
|
-
if (typeof window === "undefined") return;
|
|
67
|
-
try {
|
|
68
|
-
window.localStorage.setItem(storageKey, code);
|
|
69
|
-
} catch {}
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
41
|
//#region src/lib/friendly-error.ts
|
|
73
42
|
const DEV_FACING = /^Error \(status code:|^Failed to fetch$|^NetworkError|^Load failed$|^TypeError: (Failed to fetch|NetworkError)/i;
|
|
74
43
|
const NETWORK = /Failed to fetch|NetworkError|Load failed|ERR_INTERNET_DISCONNECTED/i;
|
|
75
44
|
const HTTP_TRACE = /\b(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b[^\n]*->\s*(\d{3})\b/;
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
generic: "Попробуйте повторить действие."
|
|
82
|
-
},
|
|
83
|
-
en: {
|
|
84
|
-
title: "Request failed",
|
|
85
|
-
offline: "Cannot reach the server. Check your connection and try again.",
|
|
86
|
-
unavailable: "The service is temporarily unavailable. Try again in a minute.",
|
|
87
|
-
generic: "Please try again."
|
|
88
|
-
}
|
|
45
|
+
const en = {
|
|
46
|
+
title: "Request failed",
|
|
47
|
+
offline: "Cannot reach the server. Check your connection and try again.",
|
|
48
|
+
unavailable: "The service is temporarily unavailable. Try again in a minute.",
|
|
49
|
+
generic: "Please try again."
|
|
89
50
|
};
|
|
90
|
-
function
|
|
91
|
-
const
|
|
51
|
+
function friendlyStringsFrom(t) {
|
|
52
|
+
const pick = (name) => t(`requestError.${name}`, { defaultValue: en[name] }) || en[name];
|
|
53
|
+
return {
|
|
54
|
+
title: pick("title"),
|
|
55
|
+
offline: pick("offline"),
|
|
56
|
+
unavailable: pick("unavailable"),
|
|
57
|
+
generic: pick("generic")
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function toFriendlyError(message, description, strings) {
|
|
92
61
|
const raw = `${String(message ?? "")} ${String(description ?? "")}`;
|
|
93
62
|
const isDevFacing = DEV_FACING.test(String(message ?? "").trim());
|
|
94
63
|
const isNetwork = NETWORK.test(raw);
|
|
@@ -96,8 +65,8 @@ function toFriendlyError(message, description, locale) {
|
|
|
96
65
|
if (trace) {
|
|
97
66
|
const status = Number(trace[1]);
|
|
98
67
|
return {
|
|
99
|
-
title:
|
|
100
|
-
detail: status >= 500 ?
|
|
68
|
+
title: strings.title,
|
|
69
|
+
detail: status >= 500 ? strings.unavailable : strings.generic,
|
|
101
70
|
replaced: true
|
|
102
71
|
};
|
|
103
72
|
}
|
|
@@ -107,21 +76,42 @@ function toFriendlyError(message, description, locale) {
|
|
|
107
76
|
replaced: false
|
|
108
77
|
};
|
|
109
78
|
return {
|
|
110
|
-
title:
|
|
111
|
-
detail: isNetwork ?
|
|
79
|
+
title: strings.title,
|
|
80
|
+
detail: isNetwork ? strings.offline : String(description ?? "") || strings.generic,
|
|
112
81
|
replaced: true
|
|
113
82
|
};
|
|
114
83
|
}
|
|
84
|
+
function isNetworkFailure(text) {
|
|
85
|
+
return NETWORK.test(text);
|
|
86
|
+
}
|
|
87
|
+
function technicalTexts(error) {
|
|
88
|
+
if (error === null || typeof error !== "object") return [];
|
|
89
|
+
const out = [];
|
|
90
|
+
try {
|
|
91
|
+
const { details, cause } = error;
|
|
92
|
+
if (typeof details === "string") out.push(details);
|
|
93
|
+
else if (details !== null && typeof details === "object") {
|
|
94
|
+
const inner = details.message;
|
|
95
|
+
if (typeof inner === "string") out.push(inner);
|
|
96
|
+
}
|
|
97
|
+
if (cause instanceof Error) out.push(cause.message);
|
|
98
|
+
else if (typeof cause === "string") out.push(cause);
|
|
99
|
+
if (error instanceof Error) out.push(error.message);
|
|
100
|
+
} catch {}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
function technicalText(error) {
|
|
104
|
+
return technicalTexts(error)[0];
|
|
105
|
+
}
|
|
115
106
|
//#endregion
|
|
116
107
|
//#region src/notification/notification-provider.ts
|
|
117
108
|
function createNotificationProvider(options = {}) {
|
|
118
|
-
const resolveLocale = options.resolveLocale ?? (() => loadLocale());
|
|
119
109
|
return {
|
|
120
110
|
open: ({ type, message, description }) => {
|
|
121
111
|
let text = message;
|
|
122
112
|
let detail = description;
|
|
123
113
|
if (type === "error") {
|
|
124
|
-
const friendly = toFriendlyError(message, description,
|
|
114
|
+
const friendly = toFriendlyError(message, description, options.resolveStrings?.() ?? en);
|
|
125
115
|
text = friendly.title;
|
|
126
116
|
detail = friendly.detail;
|
|
127
117
|
}
|
|
@@ -137,28 +127,36 @@ function createNotificationProvider(options = {}) {
|
|
|
137
127
|
function Toaster$1(props) {
|
|
138
128
|
const t = useOptionalT();
|
|
139
129
|
const { resolved: theme } = useTheme();
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const sink = useMemo(() => createNotificationProvider({ resolveLocale: () => localeRef.current ?? loadLocale() }), []);
|
|
130
|
+
const tRef = useRef(t);
|
|
131
|
+
tRef.current = t;
|
|
132
|
+
const sink = useMemo(() => createNotificationProvider({ resolveStrings: () => friendlyStringsFrom(tRef.current) }), []);
|
|
144
133
|
useRegisterNotificationSink(sink);
|
|
134
|
+
const { toastOptions, ...rest } = props;
|
|
135
|
+
const kitClassNames = {
|
|
136
|
+
toast: "group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
|
|
137
|
+
description: "group-[.toast]:text-muted-foreground",
|
|
138
|
+
actionButton: "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
|
|
139
|
+
cancelButton: "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
|
|
140
|
+
closeButton: "group-[.toast]:bg-background group-[.toast]:text-muted-foreground group-[.toast]:border-border group-[.toast]:hover:bg-muted group-[.toast]:hover:text-foreground"
|
|
141
|
+
};
|
|
145
142
|
return jsx(Toaster, {
|
|
146
|
-
|
|
143
|
+
customAriaLabel: props.customAriaLabel ?? props.containerAriaLabel ?? t("notifications.region", { defaultValue: "Notifications" }),
|
|
147
144
|
theme,
|
|
148
145
|
position: "top-right",
|
|
149
146
|
closeButton: true,
|
|
150
147
|
className: "toaster group",
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
148
|
+
...rest,
|
|
149
|
+
toastOptions: {
|
|
150
|
+
...toastOptions,
|
|
151
|
+
classNames: {
|
|
152
|
+
...kitClassNames,
|
|
153
|
+
...toastOptions?.classNames
|
|
154
|
+
},
|
|
155
|
+
closeButtonAriaLabel: toastOptions?.closeButtonAriaLabel ?? t("notifications.close", { defaultValue: "Close notification" })
|
|
156
|
+
}
|
|
159
157
|
});
|
|
160
158
|
}
|
|
161
159
|
//#endregion
|
|
162
|
-
export {
|
|
160
|
+
export { technicalText as a, LinkComponentProvider as c, PopoverAnchor as d, PopoverClose as f, isNetworkFailure as i, useLinkComponent as l, PopoverTrigger as m, toast$1 as n, technicalTexts as o, PopoverContent as p, friendlyStringsFrom as r, toFriendlyError as s, Toaster$1 as t, Popover as u };
|
|
163
161
|
|
|
164
|
-
//# sourceMappingURL=toaster-
|
|
162
|
+
//# sourceMappingURL=toaster-Ct_YHGs6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toaster-Ct_YHGs6.js","names":["Toaster","SonnerToaster"],"sources":["../src/primitives/popover.tsx","../src/layout/link-component.tsx","../src/lib/friendly-error.ts","../src/notification/notification-provider.ts","../src/notification/toaster.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport * as PopoverPrimitive from '@radix-ui/react-popover';\nimport { cn } from '../lib/cn.js';\n\n/**\n * Thin wrapper around Radix Popover, mirroring the structure of the\n * Dialog / Select primitives in this package so the Tailwind tokens\n * stay aligned. Re-exports `Root` / `Trigger` / `Anchor` / `Close`\n * directly (no styling needed) and styles `Content` to match the\n * shadcn Popover defaults.\n */\n\nconst Popover = PopoverPrimitive.Root;\nconst PopoverTrigger = PopoverPrimitive.Trigger;\nconst PopoverAnchor = PopoverPrimitive.Anchor;\nconst PopoverClose = PopoverPrimitive.Close;\n\nexport type PopoverContentProps = React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>;\n\nconst PopoverContent = React.forwardRef<\n React.ElementRef<typeof PopoverPrimitive.Content>,\n PopoverContentProps\n>(({ className, align = 'start', sideOffset = 4, ...props }, ref) => (\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n ref={ref}\n align={align}\n sideOffset={sideOffset}\n className={cn(\n 'z-50 w-72 rounded-md border bg-popover p-3 text-popover-foreground shadow-md outline-hidden',\n 'duration-[var(--duration-overlay)] ease-[var(--ease-overlay)]',\n 'data-[state=open]:animate-in data-[state=closed]:animate-out',\n 'data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',\n 'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',\n 'data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',\n className,\n )}\n {...props}\n />\n </PopoverPrimitive.Portal>\n));\nPopoverContent.displayName = PopoverPrimitive.Content.displayName;\n\nexport { Popover, PopoverTrigger, PopoverAnchor, PopoverClose, PopoverContent };\n","'use client';\nimport {\n type AnchorHTMLAttributes,\n type ComponentType,\n type ReactElement,\n type ReactNode,\n createContext,\n forwardRef,\n useContext,\n} from 'react';\n\n/**\n * Props every `LinkComponent` must accept. We intentionally mirror the\n * native `<a>` API surface so adopters writing a small wrapper around\n * their router's link primitive (next/link, react-router, TanStack\n * Router, etc.) can pass them straight through.\n *\n * `next/link` already accepts these names verbatim. `react-router`'s\n * `<Link>` uses `to` instead of `href` — adopters wrap once:\n *\n * const RouterLink: LinkComponent = ({ href, ...rest }) =>\n * <Link to={href} {...rest} />;\n */\nexport type LinkComponentProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & {\n href: string;\n children?: ReactNode;\n};\n\nexport type LinkComponent = ComponentType<LinkComponentProps>;\n\n/**\n * Default fallback — a plain `<a href>` anchor. Triggers a full\n * document load. Adopters that ship a SPA router (Next.js App Router,\n * react-router) install their router's `<Link>` via\n * `<LinkComponentProvider>` so internal navigation stays client-side.\n */\nconst DefaultLinkComponent: LinkComponent = forwardRef<HTMLAnchorElement, LinkComponentProps>(\n function DefaultLinkComponent({ children, ...rest }, ref) {\n return (\n <a ref={ref} {...rest}>\n {children}\n </a>\n );\n },\n);\n\nconst LinkComponentContext = createContext<LinkComponent>(DefaultLinkComponent);\n\nexport interface LinkComponentProviderProps {\n /**\n * The router-aware Link component to use throughout `@burojs/ui-shadcn` for\n * internal navigation. Pass `Link` from `next/link` for Next.js App Router;\n * wrap your router's link primitive once for react-router / TanStack Router.\n */\n linkComponent: LinkComponent;\n children: ReactNode;\n}\n\n/**\n * Install a router-aware `LinkComponent` for every framework component that\n * renders an internal navigation link (sidebar entries, action links, relation\n * cells, the list-empty Create CTA, …). Without it the framework falls back to\n * a raw `<a>` — correct, but a full document reload on every click.\n *\n * This is a link component and nothing else: the location and imperative\n * navigation are the `RouterAdapter`'s (`RouterAdapterProvider` and\n * `useRouteNavigate` from `@burojs/react`), the one router seam.\n *\n * import Link from 'next/link';\n * <LinkComponentProvider linkComponent={Link}>\n * <App />\n * </LinkComponentProvider>\n */\nexport function LinkComponentProvider({\n linkComponent,\n children,\n}: LinkComponentProviderProps): ReactElement {\n return (\n <LinkComponentContext.Provider value={linkComponent}>{children}</LinkComponentContext.Provider>\n );\n}\n\n/**\n * Read the current `LinkComponent`. Call this from any framework\n * component that needs to render an internal-navigation link, then\n * use the returned component in JSX:\n *\n * const RouterLink = useLinkComponent();\n * return <RouterLink href={href}>{label}</RouterLink>;\n *\n * Always returns a usable component — the default fallback emits a\n * raw `<a href>` so the component never has to null-check.\n */\nexport function useLinkComponent(): LinkComponent {\n return useContext(LinkComponentContext);\n}\n","/**\n * Turn a developer-facing error string into something a user can act on.\n *\n * Two surfaces need this and they are reached by different code paths — the\n * notification provider (a legacy query adapter's default query-error\n * toast) and the inline\n * error panel a list renders in place of its rows. Fixing only the first left\n * `/document_document` still printing a raw English «Failed to fetch» under a\n * Russian heading, which is how this ended up in a second acceptance round.\n * One helper, both call sites.\n *\n * Anything we do not recognise is passed through unchanged: a message written\n * by the adopter's own `onError` is almost certainly better than a generic\n * substitute.\n */\n\n/** A legacy query adapter's own untranslated wording plus the raw fetch/network failures. */\nconst DEV_FACING =\n /^Error \\(status code:|^Failed to fetch$|^NetworkError|^Load failed$|^TypeError: (Failed to fetch|NetworkError)/i;\nconst NETWORK = /Failed to fetch|NetworkError|Load failed|ERR_INTERNET_DISCONNECTED/i;\n/**\n * A machine transport trace, e.g.\n * «Temporal GET /namespaces/default/schedules?maximumPageSize=10 -> 502»\n *\n * A data provider that reports which call failed is doing the right thing —\n * that string belongs in a bug report. It does not belong in front of an\n * operator as the entire explanation of why their page is empty, which is\n * exactly what `/schedules` did when the Temporal cluster went down.\n *\n * Recognised by an HTTP verb followed by an arrow and a status code; nothing\n * an adopter would hand-write looks like this, so the pass-through contract\n * for adopter-authored messages is preserved.\n */\nconst HTTP_TRACE = /\\b(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\\b[^\\n]*->\\s*(\\d{3})\\b/;\n\n/** The four sentences a recognised failure is replaced with: the bundle keys `requestError.*`. */\nexport interface FriendlyErrorStrings {\n readonly title: string;\n readonly offline: string;\n readonly unavailable: string;\n readonly generic: string;\n}\n\n/**\n * The framework's code language: used where no i18n is configured, and for any\n * key the active bundles do not carry.\n */\nexport const en: FriendlyErrorStrings = {\n title: 'Request failed',\n offline: 'Cannot reach the server. Check your connection and try again.',\n unavailable: 'The service is temporarily unavailable. Try again in a minute.',\n generic: 'Please try again.',\n};\n\n/**\n * Resolve {@link FriendlyErrorStrings} through a translate function (`useT()`,\n * `useOptionalT()`), taking the English default for each key it cannot find.\n */\nexport function friendlyStringsFrom(\n t: (key: string, options?: { defaultValue?: string }) => string,\n): FriendlyErrorStrings {\n const pick = (name: keyof FriendlyErrorStrings): string =>\n t(`requestError.${name}`, { defaultValue: en[name] }) || en[name];\n return {\n title: pick('title'),\n offline: pick('offline'),\n unavailable: pick('unavailable'),\n generic: pick('generic'),\n };\n}\n\nexport interface FriendlyError {\n /** Short headline. Empty when the original message should be kept. */\n title: string;\n /** Explanation the user can act on. */\n detail: string;\n /** True when the input was recognised as developer-facing and replaced. */\n replaced: boolean;\n}\n\n/**\n * @param strings the sentences to substitute, already in the active language:\n * {@link friendlyStringsFrom} builds them from the app's translate function,\n * and {@link en} is the default where none is configured.\n */\nexport function toFriendlyError(\n message: unknown,\n description: unknown,\n strings: FriendlyErrorStrings,\n): FriendlyError {\n const raw = `${String(message ?? '')} ${String(description ?? '')}`;\n const isDevFacing = DEV_FACING.test(String(message ?? '').trim());\n const isNetwork = NETWORK.test(raw);\n const trace = HTTP_TRACE.exec(String(message ?? '').trim());\n\n if (trace) {\n // 5xx is the server's problem and waiting is the right advice; anything\n // else is at least not something the operator can read a URL out of.\n const status = Number(trace[1]);\n return {\n title: strings.title,\n detail: status >= 500 ? strings.unavailable : strings.generic,\n replaced: true,\n };\n }\n\n if (!isDevFacing && !isNetwork) {\n return {\n title: String(message ?? ''),\n detail: String(description ?? ''),\n replaced: false,\n };\n }\n return {\n title: strings.title,\n detail: isNetwork ? strings.offline : String(description ?? '') || strings.generic,\n replaced: true,\n };\n}\n\n/** Whether a technical text says the network itself failed (a dead connection, a refused fetch). */\nexport function isNetworkFailure(text: string): boolean {\n return NETWORK.test(text);\n}\n\n/**\n * Every developer-facing text a failure carries, most specific first: string `details`, else\n * `details.message`; then an `Error` cause's message or a string cause; then the message of the\n * error itself when it is a plain `Error`. A provider's `details` is often its own sentence\n * (\"did not answer a mutation; it may have been applied\"), so the thrown fetch error in `cause`\n * must stay readable behind it. A `DataError`'s `message` is a reference a user may read; this is\n * what it no longer carries.\n */\nexport function technicalTexts(error: unknown): readonly string[] {\n if (error === null || typeof error !== 'object') return [];\n const out: string[] = [];\n try {\n const { details, cause } = error as { readonly details?: unknown; readonly cause?: unknown };\n if (typeof details === 'string') out.push(details);\n else if (details !== null && typeof details === 'object') {\n const inner = (details as { readonly message?: unknown }).message;\n if (typeof inner === 'string') out.push(inner);\n }\n if (cause instanceof Error) out.push(cause.message);\n // The normaliser moves a legacy string `message` into `cause`.\n else if (typeof cause === 'string') out.push(cause);\n if (error instanceof Error) out.push(error.message);\n } catch {\n // A getter that throws on a hostile error object: there is no more technical text to read.\n }\n return out;\n}\n\n/** The first of {@link technicalTexts}: for the friendly path and development logs only. */\nexport function technicalText(error: unknown): string | undefined {\n return technicalTexts(error)[0];\n}\n","import type { NotificationSinkMessage } from '@burojs/react';\nimport { toast } from 'sonner';\nimport { type FriendlyErrorStrings, en, toFriendlyError } from '../lib/friendly-error.js';\n\n/** `<Toaster>`'s sink: `@burojs/react`'s `NotificationSink`, plus `close`. */\nexport interface NotificationSink {\n open(args: NotificationSinkMessage): void;\n close(key: string): void;\n}\n\n/**\n * A legacy query adapter can build its default query-error notification outside\n * our i18n bundle: the user saw «Error (status code: undefined)» / «Failed to fetch», plus it duplicated\n * the inline error state a list already renders. We can't localize a string we\n * don't own, so `toFriendlyError` recognises it and substitutes plain language.\n * The SAME helper backs the list's inline panel — see friendly-error.ts for why\n * that matters.\n */\nexport interface NotificationProviderOptions {\n /**\n * The sentences an error toast is rewritten with (`requestError.*` in the active bundle), or\n * `undefined` for the English defaults. `<Toaster>` passes one built from the app's translate\n * function; a sink built outside React passes its own.\n *\n * ⚠️ It is a FUNCTION, not a value, and that is load-bearing: both examples\n * build this sink once (`React.useMemo(…, [])`) and it has no React context\n * to subscribe to, so strings captured at construction would freeze in\n * whatever language was active on the first render. Called per toast instead.\n */\n readonly resolveStrings?: () => FriendlyErrorStrings | undefined;\n}\n\nexport function createNotificationProvider(\n options: NotificationProviderOptions = {},\n): NotificationSink {\n return {\n open: ({ type, message, description }) => {\n let text = message;\n let detail = description;\n if (type === 'error') {\n const friendly = toFriendlyError(message, description, options.resolveStrings?.() ?? en);\n text = friendly.title;\n detail = friendly.detail;\n }\n // `info` is a plain notice that dismisses itself — never `toast.loading`,\n // whose spinner stays on screen until someone closes it.\n const fn = type === 'error' ? toast.error : type === 'info' ? toast.info : toast.success;\n fn(text, { description: detail });\n },\n close: (key: string) => {\n toast.dismiss(key);\n },\n };\n}\n","'use client';\nimport { useOptionalT, useRegisterNotificationSink } from '@burojs/react';\nimport { useMemo, useRef } from 'react';\nimport { Toaster as SonnerToaster, type ToasterProps as SonnerProps, toast } from 'sonner';\nimport { friendlyStringsFrom } from '../lib/friendly-error.js';\nimport { useTheme } from '../layout/use-theme.js';\nimport { createNotificationProvider } from './notification-provider.js';\n\nexport interface ToasterProps extends SonnerProps {}\n\n/**\n * Shadcn-canonical Sonner setup, and — inside a `<BuroProvider>` — the app's\n * notification sink: the dispatcher's default `notify` (every handler's\n * `notify`, and a thrown handler's error) is delivered here. Outside a\n * provider it registers nothing and still renders anything sent with `toast()`.\n *\n * Bound to design tokens via `toastOptions.classNames`, so toasts inherit the\n * app's light/dark theme through the same CSS-variable cascade as the rest of\n * the UI; `theme` is reactive via `useTheme()`. The error sentences come from\n * the ACTIVE bundle (`requestError.*`), read per toast so a language switch is\n * honoured; with no i18n provider they are the English defaults.\n */\nexport function Toaster(props: ToasterProps): React.ReactElement {\n // `useOptionalT`: the toaster may sit outside a BuroProvider, so it must\n // degrade rather than throw.\n const t = useOptionalT();\n const { resolved: theme } = useTheme();\n const tRef = useRef(t);\n tRef.current = t;\n const sink = useMemo(\n () => createNotificationProvider({ resolveStrings: () => friendlyStringsFrom(tRef.current) }),\n [],\n );\n useRegisterNotificationSink(sink);\n\n const { toastOptions, ...rest } = props;\n const kitClassNames = {\n toast:\n 'group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg',\n description: 'group-[.toast]:text-muted-foreground',\n actionButton: 'group-[.toast]:bg-primary group-[.toast]:text-primary-foreground',\n cancelButton: 'group-[.toast]:bg-muted group-[.toast]:text-muted-foreground',\n closeButton:\n 'group-[.toast]:bg-background group-[.toast]:text-muted-foreground group-[.toast]:border-border group-[.toast]:hover:bg-muted group-[.toast]:hover:text-foreground',\n };\n\n return (\n <SonnerToaster\n /*\n ⚠️ Sonner's default accessible name is \"Notifications alt+T\" and reaches\n the accessibility tree on every page. `customAriaLabel` replaces it\n wholly (the hotkey hint leaves the name) with the adopter's own\n `customAriaLabel` or `containerAriaLabel` (sonner 2 ignores the latter\n once the former is set, so it is honoured here), else the bundle's\n `notifications.region`. The literal fallback is English, like every\n framework default.\n */\n customAriaLabel={\n props.customAriaLabel ??\n props.containerAriaLabel ??\n t('notifications.region', { defaultValue: 'Notifications' })\n }\n theme={theme}\n position=\"top-right\"\n closeButton\n className=\"toaster group\"\n {...rest}\n /*\n The adopter's `toastOptions` merge with ours instead of replacing them:\n the adopter wins per key, and per slot inside `classNames`. The close\n button's label is the bundle's `notifications.close` unless the adopter\n names their own.\n */\n toastOptions={{\n ...toastOptions,\n classNames: { ...kitClassNames, ...toastOptions?.classNames },\n closeButtonAriaLabel:\n toastOptions?.closeButtonAriaLabel ??\n t('notifications.close', { defaultValue: 'Close notification' }),\n }}\n />\n );\n}\n\nexport {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esHiddenField, o as narrowSearchDecl } from "./relation-create-C43cdPQt.js";
|
|
2
|
+
import { EMPTY_FILTER_GROUP, composeListFilter, routeResourceKey } from "@burojs/core";
|
|
3
3
|
import { useApp, useFilterFields, useListAccess } from "@burojs/react";
|
|
4
4
|
import { useCallback, useMemo, useState } from "react";
|
|
5
5
|
//#region src/fields/use-dialog-filter-state.ts
|
|
6
|
-
function useDialogFilterState(
|
|
6
|
+
function useDialogFilterState(resourceInput, options) {
|
|
7
|
+
const resource = routeResourceKey(resourceInput);
|
|
7
8
|
const def = useApp().registry.get(resource);
|
|
8
9
|
const { available, fixed } = useFilterFields(resource, {
|
|
9
10
|
fixedFilters: options.fixedFilters,
|
|
@@ -84,4 +85,4 @@ function useDialogFilterState(resource, options) {
|
|
|
84
85
|
//#endregion
|
|
85
86
|
export { useDialogFilterState as t };
|
|
86
87
|
|
|
87
|
-
//# sourceMappingURL=use-dialog-filter-state-
|
|
88
|
+
//# sourceMappingURL=use-dialog-filter-state-B_MqzHaT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-dialog-filter-state-B_MqzHaT.js","names":[],"sources":["../src/fields/use-dialog-filter-state.ts"],"sourcesContent":["import {\n EMPTY_FILTER_GROUP,\n composeListFilter,\n type ErasedResourceHandle,\n type FilterExpression,\n type FilterGroup,\n type FixedFilterInput,\n type ResolvedFixedFilter,\n type SearchDecl,\n routeResourceKey,\n type ResourceNameOrRef,\n} from '@burojs/core';\nimport { useApp, useFilterFields, useListAccess, type FilterFieldSpec } from '@burojs/react';\nimport { namesHiddenField, narrowSearchDecl } from './search-access.js';\nimport { useCallback, useMemo, useState } from 'react';\n\n/** The portable erased AST — the only shape this module deals in. */\ntype ErasedExpression = FilterExpression<ErasedResourceHandle>;\n\n/** Options for {@link useDialogFilterState}. */\nexport interface UseDialogFilterStateOptions {\n /** Call-site narrowing (e.g. scope the target list to a product group). */\n readonly fixedFilters?: readonly FixedFilterInput[];\n /**\n * Fallback search field, used ONLY when the target resource declares no\n * `views.list.search`. Wrapped into a single-field `SearchFieldsDecl`\n * (`{ fields: [searchField] }`, implicit `contains` — same degenerate form\n * `searchToFilter` already gives a bare field-name string) so the override\n * goes through the exact same `composeListFilter` → `searchToFilter` path\n * as a real declaration, rather than a second hand-built predicate at the\n * call site. The target's own declaration always wins when present — this\n * is a fallback, not an override of a declared search.\n */\n readonly searchField?: string;\n /**\n * Gates the field-derivation walk (`useFilterFields`'s `categorizeField`\n * pass over every field of the resource). Defaults to `true`. A caller\n * whose UI isn't visible yet (e.g. `RelationPickerDialog` before it's\n * opened) should pass `false` to skip that work on every mount /\n * `fixedFilters`-identity change; the derivation recomputes in full the\n * next render where this flips back to `true`.\n */\n readonly enabled?: boolean;\n}\n\n/** Return shape of {@link useDialogFilterState}. */\nexport interface DialogFilterState {\n readonly group: FilterGroup;\n readonly setGroup: (next: FilterGroup) => void;\n readonly search: string;\n readonly setSearch: (next: string) => void;\n readonly page: number;\n readonly setPage: (page: number) => void;\n readonly available: readonly FilterFieldSpec[];\n readonly fixed: readonly ResolvedFixedFilter[];\n /** The single expression to hand the data provider. */\n readonly filter: ErasedExpression | undefined;\n /** Whether the target has a search for this user (no field left means no search box). */\n readonly searchEnabled: boolean;\n /** The read must not be sent: undecided access, or a filter naming a field the user may not view. */\n readonly blocked: boolean;\n readonly reset: () => void;\n}\n\n/**\n * Local (non-URL) filter state for the relation-picker's advanced-search\n * dialog.\n *\n * `useResourceList` cannot serve this: it unconditionally calls\n * `useResourceUrlState`, which throws without a `RouterAdapterProvider` and,\n * when one IS present, writes to `?<resource>.*`. A picker dialog mounted\n * inside a form for resource A, searching TARGET resource B, would then\n * write B's list state into the URL — clobbering a real B list page open on\n * another tab of the same app, and reading back whatever that page last\n * wrote on open. So this hook keeps `group`/`search`/`page` in plain\n * `useState` and reuses the SAME composition core's list controller uses\n * (`composeListFilter`) so the two never drift on what a filter means.\n *\n * No `pinned` slot: pinned controls are a list-PAGE affordance (permanent\n * screen real estate for a couple of always-visible facets); a modal has no\n * spare real estate to spend on them.\n */\nexport function useDialogFilterState<const N extends string = string>(\n resourceInput: ResourceNameOrRef<N>,\n options: UseDialogFilterStateOptions,\n): DialogFilterState {\n const resource = routeResourceKey(resourceInput);\n const app = useApp();\n const def = app.registry.get(resource);\n const { available, fixed } = useFilterFields(resource, {\n fixedFilters: options.fixedFilters,\n enabled: options.enabled,\n });\n\n const [group, setGroupState] = useState<FilterGroup>(EMPTY_FILTER_GROUP);\n const [search, setSearchState] = useState('');\n const [page, setPage] = useState(1);\n\n // Any change to WHAT is filtered invalidates the current page — the same\n // rule `useResourceList`'s URL-state controller applies to its own\n // group/search setters.\n const setGroup = useCallback((next: FilterGroup) => {\n setGroupState(next);\n setPage(1);\n }, []);\n\n const setSearch = useCallback((next: string) => {\n setSearchState(next);\n setPage(1);\n }, []);\n\n const reset = useCallback(() => {\n setGroupState(EMPTY_FILTER_GROUP);\n setSearchState('');\n setPage(1);\n }, []);\n\n // The target's own declaration always wins; `options.searchField` only\n // fills in when the target declares no search at all. Memoized so an\n // omitted declaration doesn't hand `composeListFilter`'s `filter` memo a\n // fresh `{ fields: [...] }` literal (and therefore a spurious recompute)\n // on every render — see `UseDialogFilterStateOptions.searchField`'s doc.\n const { searchField } = options;\n const access = useListAccess(resource);\n const accessReady = access.status === 'ready';\n const searchDecl = useMemo<SearchDecl | undefined>(() => {\n const declared = def?.views?.list?.search;\n const base =\n declared !== undefined\n ? declared\n : searchField === undefined\n ? undefined\n : { fields: [searchField] };\n return narrowSearchDecl(base, (field) => access.fieldVisible(field));\n }, [def, searchField, access]);\n const searchContext = useMemo(() => ({ resource, def }), [resource, def]);\n\n const filter = useMemo<ErasedExpression | undefined>(\n () => composeListFilter({ fixed, group, search, searchDecl, searchContext }),\n [fixed, group, search, searchDecl, searchContext],\n );\n\n // A read whose composed filter names a field the user may not view is forbidden (an author\n // predicate, or a function search's output); an undecided access sends nothing yet.\n const blocked = !accessReady || namesHiddenField(filter, (field) => access.fieldVisible(field));\n\n return useMemo<DialogFilterState>(\n () => ({\n searchEnabled: searchDecl !== undefined,\n blocked,\n group,\n setGroup,\n search,\n setSearch,\n page,\n setPage,\n available,\n fixed,\n filter,\n reset,\n }),\n [\n group,\n setGroup,\n search,\n setSearch,\n page,\n available,\n fixed,\n filter,\n reset,\n searchDecl,\n blocked,\n ],\n );\n}\n"],"mappings":";;;;;AAkFA,SAAgB,qBACd,eACA,SACmB;CACnB,MAAM,WAAW,iBAAiB,aAAa;CAE/C,MAAM,MADM,OACE,CAAC,CAAC,SAAS,IAAI,QAAQ;CACrC,MAAM,EAAE,WAAW,UAAU,gBAAgB,UAAU;EACrD,cAAc,QAAQ;EACtB,SAAS,QAAQ;CACnB,CAAC;CAED,MAAM,CAAC,OAAO,iBAAiB,SAAsB,kBAAkB;CACvE,MAAM,CAAC,QAAQ,kBAAkB,SAAS,EAAE;CAC5C,MAAM,CAAC,MAAM,WAAW,SAAS,CAAC;CAKlC,MAAM,WAAW,aAAa,SAAsB;EAClD,cAAc,IAAI;EAClB,QAAQ,CAAC;CACX,GAAG,CAAC,CAAC;CAEL,MAAM,YAAY,aAAa,SAAiB;EAC9C,eAAe,IAAI;EACnB,QAAQ,CAAC;CACX,GAAG,CAAC,CAAC;CAEL,MAAM,QAAQ,kBAAkB;EAC9B,cAAc,kBAAkB;EAChC,eAAe,EAAE;EACjB,QAAQ,CAAC;CACX,GAAG,CAAC,CAAC;CAOL,MAAM,EAAE,gBAAgB;CACxB,MAAM,SAAS,cAAc,QAAQ;CACrC,MAAM,cAAc,OAAO,WAAW;CACtC,MAAM,aAAa,cAAsC;EACvD,MAAM,WAAW,KAAK,OAAO,MAAM;EAOnC,OAAO,iBALL,aAAa,KAAA,IACT,WACA,gBAAgB,KAAA,IACd,KAAA,IACA,EAAE,QAAQ,CAAC,WAAW,EAAE,IACD,UAAU,OAAO,aAAa,KAAK,CAAC;CACrE,GAAG;EAAC;EAAK;EAAa;CAAM,CAAC;CAC7B,MAAM,gBAAgB,eAAe;EAAE;EAAU;CAAI,IAAI,CAAC,UAAU,GAAG,CAAC;CAExE,MAAM,SAAS,cACP,kBAAkB;EAAE;EAAO;EAAO;EAAQ;EAAY;CAAc,CAAC,GAC3E;EAAC;EAAO;EAAO;EAAQ;EAAY;CAAa,CAClD;CAIA,MAAM,UAAU,CAAC,eAAe,iBAAiB,SAAS,UAAU,OAAO,aAAa,KAAK,CAAC;CAE9F,OAAO,eACE;EACL,eAAe,eAAe,KAAA;EAC9B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;AACF"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_relation_create = require("./relation-create-DDEYcKfw.cjs");
|
|
2
2
|
let _burojs_core = require("@burojs/core");
|
|
3
3
|
let _burojs_react = require("@burojs/react");
|
|
4
4
|
let react = require("react");
|
|
5
5
|
//#region src/fields/use-dialog-filter-state.ts
|
|
6
|
-
function useDialogFilterState(
|
|
6
|
+
function useDialogFilterState(resourceInput, options) {
|
|
7
|
+
const resource = (0, _burojs_core.routeResourceKey)(resourceInput);
|
|
7
8
|
const def = (0, _burojs_react.useApp)().registry.get(resource);
|
|
8
9
|
const { available, fixed } = (0, _burojs_react.useFilterFields)(resource, {
|
|
9
10
|
fixedFilters: options.fixedFilters,
|
|
@@ -30,7 +31,7 @@ function useDialogFilterState(resource, options) {
|
|
|
30
31
|
const accessReady = access.status === "ready";
|
|
31
32
|
const searchDecl = (0, react.useMemo)(() => {
|
|
32
33
|
const declared = def?.views?.list?.search;
|
|
33
|
-
return
|
|
34
|
+
return require_relation_create.narrowSearchDecl(declared !== void 0 ? declared : searchField === void 0 ? void 0 : { fields: [searchField] }, (field) => access.fieldVisible(field));
|
|
34
35
|
}, [
|
|
35
36
|
def,
|
|
36
37
|
searchField,
|
|
@@ -53,7 +54,7 @@ function useDialogFilterState(resource, options) {
|
|
|
53
54
|
searchDecl,
|
|
54
55
|
searchContext
|
|
55
56
|
]);
|
|
56
|
-
const blocked = !accessReady ||
|
|
57
|
+
const blocked = !accessReady || require_relation_create.namesHiddenField(filter, (field) => access.fieldVisible(field));
|
|
57
58
|
return (0, react.useMemo)(() => ({
|
|
58
59
|
searchEnabled: searchDecl !== void 0,
|
|
59
60
|
blocked,
|
|
@@ -89,4 +90,4 @@ Object.defineProperty(exports, "useDialogFilterState", {
|
|
|
89
90
|
}
|
|
90
91
|
});
|
|
91
92
|
|
|
92
|
-
//# sourceMappingURL=use-dialog-filter-state-
|
|
93
|
+
//# sourceMappingURL=use-dialog-filter-state-tNvqAAjh.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-dialog-filter-state-tNvqAAjh.cjs","names":["routeResourceKey","useApp","useFilterFields","useState","EMPTY_FILTER_GROUP","useCallback","useListAccess","useMemo","narrowSearchDecl","composeListFilter","namesHiddenField"],"sources":["../src/fields/use-dialog-filter-state.ts"],"sourcesContent":["import {\n EMPTY_FILTER_GROUP,\n composeListFilter,\n type ErasedResourceHandle,\n type FilterExpression,\n type FilterGroup,\n type FixedFilterInput,\n type ResolvedFixedFilter,\n type SearchDecl,\n routeResourceKey,\n type ResourceNameOrRef,\n} from '@burojs/core';\nimport { useApp, useFilterFields, useListAccess, type FilterFieldSpec } from '@burojs/react';\nimport { namesHiddenField, narrowSearchDecl } from './search-access.js';\nimport { useCallback, useMemo, useState } from 'react';\n\n/** The portable erased AST — the only shape this module deals in. */\ntype ErasedExpression = FilterExpression<ErasedResourceHandle>;\n\n/** Options for {@link useDialogFilterState}. */\nexport interface UseDialogFilterStateOptions {\n /** Call-site narrowing (e.g. scope the target list to a product group). */\n readonly fixedFilters?: readonly FixedFilterInput[];\n /**\n * Fallback search field, used ONLY when the target resource declares no\n * `views.list.search`. Wrapped into a single-field `SearchFieldsDecl`\n * (`{ fields: [searchField] }`, implicit `contains` — same degenerate form\n * `searchToFilter` already gives a bare field-name string) so the override\n * goes through the exact same `composeListFilter` → `searchToFilter` path\n * as a real declaration, rather than a second hand-built predicate at the\n * call site. The target's own declaration always wins when present — this\n * is a fallback, not an override of a declared search.\n */\n readonly searchField?: string;\n /**\n * Gates the field-derivation walk (`useFilterFields`'s `categorizeField`\n * pass over every field of the resource). Defaults to `true`. A caller\n * whose UI isn't visible yet (e.g. `RelationPickerDialog` before it's\n * opened) should pass `false` to skip that work on every mount /\n * `fixedFilters`-identity change; the derivation recomputes in full the\n * next render where this flips back to `true`.\n */\n readonly enabled?: boolean;\n}\n\n/** Return shape of {@link useDialogFilterState}. */\nexport interface DialogFilterState {\n readonly group: FilterGroup;\n readonly setGroup: (next: FilterGroup) => void;\n readonly search: string;\n readonly setSearch: (next: string) => void;\n readonly page: number;\n readonly setPage: (page: number) => void;\n readonly available: readonly FilterFieldSpec[];\n readonly fixed: readonly ResolvedFixedFilter[];\n /** The single expression to hand the data provider. */\n readonly filter: ErasedExpression | undefined;\n /** Whether the target has a search for this user (no field left means no search box). */\n readonly searchEnabled: boolean;\n /** The read must not be sent: undecided access, or a filter naming a field the user may not view. */\n readonly blocked: boolean;\n readonly reset: () => void;\n}\n\n/**\n * Local (non-URL) filter state for the relation-picker's advanced-search\n * dialog.\n *\n * `useResourceList` cannot serve this: it unconditionally calls\n * `useResourceUrlState`, which throws without a `RouterAdapterProvider` and,\n * when one IS present, writes to `?<resource>.*`. A picker dialog mounted\n * inside a form for resource A, searching TARGET resource B, would then\n * write B's list state into the URL — clobbering a real B list page open on\n * another tab of the same app, and reading back whatever that page last\n * wrote on open. So this hook keeps `group`/`search`/`page` in plain\n * `useState` and reuses the SAME composition core's list controller uses\n * (`composeListFilter`) so the two never drift on what a filter means.\n *\n * No `pinned` slot: pinned controls are a list-PAGE affordance (permanent\n * screen real estate for a couple of always-visible facets); a modal has no\n * spare real estate to spend on them.\n */\nexport function useDialogFilterState<const N extends string = string>(\n resourceInput: ResourceNameOrRef<N>,\n options: UseDialogFilterStateOptions,\n): DialogFilterState {\n const resource = routeResourceKey(resourceInput);\n const app = useApp();\n const def = app.registry.get(resource);\n const { available, fixed } = useFilterFields(resource, {\n fixedFilters: options.fixedFilters,\n enabled: options.enabled,\n });\n\n const [group, setGroupState] = useState<FilterGroup>(EMPTY_FILTER_GROUP);\n const [search, setSearchState] = useState('');\n const [page, setPage] = useState(1);\n\n // Any change to WHAT is filtered invalidates the current page — the same\n // rule `useResourceList`'s URL-state controller applies to its own\n // group/search setters.\n const setGroup = useCallback((next: FilterGroup) => {\n setGroupState(next);\n setPage(1);\n }, []);\n\n const setSearch = useCallback((next: string) => {\n setSearchState(next);\n setPage(1);\n }, []);\n\n const reset = useCallback(() => {\n setGroupState(EMPTY_FILTER_GROUP);\n setSearchState('');\n setPage(1);\n }, []);\n\n // The target's own declaration always wins; `options.searchField` only\n // fills in when the target declares no search at all. Memoized so an\n // omitted declaration doesn't hand `composeListFilter`'s `filter` memo a\n // fresh `{ fields: [...] }` literal (and therefore a spurious recompute)\n // on every render — see `UseDialogFilterStateOptions.searchField`'s doc.\n const { searchField } = options;\n const access = useListAccess(resource);\n const accessReady = access.status === 'ready';\n const searchDecl = useMemo<SearchDecl | undefined>(() => {\n const declared = def?.views?.list?.search;\n const base =\n declared !== undefined\n ? declared\n : searchField === undefined\n ? undefined\n : { fields: [searchField] };\n return narrowSearchDecl(base, (field) => access.fieldVisible(field));\n }, [def, searchField, access]);\n const searchContext = useMemo(() => ({ resource, def }), [resource, def]);\n\n const filter = useMemo<ErasedExpression | undefined>(\n () => composeListFilter({ fixed, group, search, searchDecl, searchContext }),\n [fixed, group, search, searchDecl, searchContext],\n );\n\n // A read whose composed filter names a field the user may not view is forbidden (an author\n // predicate, or a function search's output); an undecided access sends nothing yet.\n const blocked = !accessReady || namesHiddenField(filter, (field) => access.fieldVisible(field));\n\n return useMemo<DialogFilterState>(\n () => ({\n searchEnabled: searchDecl !== undefined,\n blocked,\n group,\n setGroup,\n search,\n setSearch,\n page,\n setPage,\n available,\n fixed,\n filter,\n reset,\n }),\n [\n group,\n setGroup,\n search,\n setSearch,\n page,\n available,\n fixed,\n filter,\n reset,\n searchDecl,\n blocked,\n ],\n );\n}\n"],"mappings":";;;;;AAkFA,SAAgB,qBACd,eACA,SACmB;CACnB,MAAM,YAAA,GAAWA,aAAAA,iBAAAA,CAAiB,aAAa;CAE/C,MAAM,OAAA,GADMC,cAAAA,OAAAA,CACE,CAAC,CAAC,SAAS,IAAI,QAAQ;CACrC,MAAM,EAAE,WAAW,WAAA,GAAUC,cAAAA,gBAAAA,CAAgB,UAAU;EACrD,cAAc,QAAQ;EACtB,SAAS,QAAQ;CACnB,CAAC;CAED,MAAM,CAAC,OAAO,kBAAA,GAAiBC,MAAAA,SAAAA,CAAsBC,aAAAA,kBAAkB;CACvE,MAAM,CAAC,QAAQ,mBAAA,GAAkBD,MAAAA,SAAAA,CAAS,EAAE;CAC5C,MAAM,CAAC,MAAM,YAAA,GAAWA,MAAAA,SAAAA,CAAS,CAAC;CAKlC,MAAM,YAAA,GAAWE,MAAAA,YAAAA,EAAa,SAAsB;EAClD,cAAc,IAAI;EAClB,QAAQ,CAAC;CACX,GAAG,CAAC,CAAC;CAEL,MAAM,aAAA,GAAYA,MAAAA,YAAAA,EAAa,SAAiB;EAC9C,eAAe,IAAI;EACnB,QAAQ,CAAC;CACX,GAAG,CAAC,CAAC;CAEL,MAAM,SAAA,GAAQA,MAAAA,YAAAA,OAAkB;EAC9B,cAAcD,aAAAA,kBAAkB;EAChC,eAAe,EAAE;EACjB,QAAQ,CAAC;CACX,GAAG,CAAC,CAAC;CAOL,MAAM,EAAE,gBAAgB;CACxB,MAAM,UAAA,GAASE,cAAAA,cAAAA,CAAc,QAAQ;CACrC,MAAM,cAAc,OAAO,WAAW;CACtC,MAAM,cAAA,GAAaC,MAAAA,QAAAA,OAAsC;EACvD,MAAM,WAAW,KAAK,OAAO,MAAM;EAOnC,OAAOC,wBAAAA,iBALL,aAAa,KAAA,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