shared-lib-web 0.0.2 → 0.0.4
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 +192 -528
- package/dist/components/app-brand.d.ts.map +1 -1
- package/dist/components/app-brand.js +9 -5
- package/dist/components/app-brand.js.map +1 -1
- package/dist/components/coming-soon.d.ts.map +1 -1
- package/dist/components/coming-soon.js +3 -2
- package/dist/components/coming-soon.js.map +1 -1
- package/dist/components/language-switcher.d.ts +5 -1
- package/dist/components/language-switcher.d.ts.map +1 -1
- package/dist/components/language-switcher.js +20 -7
- package/dist/components/language-switcher.js.map +1 -1
- package/dist/components/otp-modal.d.ts +5 -0
- package/dist/components/otp-modal.d.ts.map +1 -0
- package/dist/components/otp-modal.js +77 -0
- package/dist/components/otp-modal.js.map +1 -0
- package/dist/components/settings-menu.d.ts +4 -0
- package/dist/components/settings-menu.d.ts.map +1 -1
- package/dist/components/settings-menu.js +15 -2
- package/dist/components/settings-menu.js.map +1 -1
- package/dist/context/use-ui.d.ts.map +1 -1
- package/dist/context/use-ui.js +4 -3
- package/dist/context/use-ui.js.map +1 -1
- package/dist/i18n/browser-language.d.ts +9 -0
- package/dist/i18n/browser-language.d.ts.map +1 -0
- package/dist/i18n/browser-language.js +89 -0
- package/dist/i18n/browser-language.js.map +1 -0
- package/dist/i18n/default-messages.d.ts.map +1 -1
- package/dist/i18n/default-messages.js +15 -0
- package/dist/i18n/default-messages.js.map +1 -1
- package/dist/i18n/locale-groups.d.ts +18 -0
- package/dist/i18n/locale-groups.d.ts.map +1 -0
- package/dist/i18n/locale-groups.js +74 -0
- package/dist/i18n/locale-groups.js.map +1 -0
- package/dist/i18n/locale-service.d.ts +22 -4
- package/dist/i18n/locale-service.d.ts.map +1 -1
- package/dist/i18n/locale-service.js +95 -27
- package/dist/i18n/locale-service.js.map +1 -1
- package/dist/i18n/locale-signal.d.ts +18 -0
- package/dist/i18n/locale-signal.d.ts.map +1 -0
- package/dist/i18n/locale-signal.js +142 -0
- package/dist/i18n/locale-signal.js.map +1 -0
- package/dist/i18n/translator.d.ts +8 -1
- package/dist/i18n/translator.d.ts.map +1 -1
- package/dist/i18n/translator.js +36 -12
- package/dist/i18n/translator.js.map +1 -1
- package/dist/index.d.ts +24 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/dist/interfaces/app-types.d.ts +6 -0
- package/dist/interfaces/app-types.d.ts.map +1 -1
- package/dist/interfaces/ui-config.d.ts +184 -15
- package/dist/interfaces/ui-config.d.ts.map +1 -1
- package/dist/interfaces/ui-context.d.ts +1 -1
- package/dist/interfaces/ui-context.d.ts.map +1 -1
- package/dist/layouts/auth-layout.js +1 -1
- package/dist/layouts/auth-layout.js.map +1 -1
- package/dist/providers/provider-effects.d.ts +2 -2
- package/dist/providers/provider-effects.d.ts.map +1 -1
- package/dist/providers/provider-effects.js +4 -1
- package/dist/providers/provider-effects.js.map +1 -1
- package/dist/providers/register-config.d.ts.map +1 -1
- package/dist/providers/register-config.js +2 -0
- package/dist/providers/register-config.js.map +1 -1
- package/dist/providers/shared-web-ui-provider.d.ts +7 -19
- package/dist/providers/shared-web-ui-provider.d.ts.map +1 -1
- package/dist/providers/shared-web-ui-provider.js +21 -22
- package/dist/providers/shared-web-ui-provider.js.map +1 -1
- package/dist/query/query-param.d.ts +4 -1
- package/dist/query/query-param.d.ts.map +1 -1
- package/dist/query/query-param.js +6 -3
- package/dist/query/query-param.js.map +1 -1
- package/dist/state/api-loader.d.ts +19 -0
- package/dist/state/api-loader.d.ts.map +1 -0
- package/dist/state/api-loader.js +187 -0
- package/dist/state/api-loader.js.map +1 -0
- package/dist/state/auth-service.d.ts +9 -0
- package/dist/state/auth-service.d.ts.map +1 -1
- package/dist/state/auth-service.js +70 -3
- package/dist/state/auth-service.js.map +1 -1
- package/dist/state/branch-service.d.ts +1 -1
- package/dist/state/branch-service.js +3 -3
- package/dist/state/branch-service.js.map +1 -1
- package/dist/state/company-service.d.ts +16 -0
- package/dist/state/company-service.d.ts.map +1 -0
- package/dist/state/company-service.js +97 -0
- package/dist/state/company-service.js.map +1 -0
- package/dist/state/language-service.d.ts +5 -2
- package/dist/state/language-service.d.ts.map +1 -1
- package/dist/state/language-service.js +12 -7
- package/dist/state/language-service.js.map +1 -1
- package/dist/state/layout-choice-service.d.ts +10 -0
- package/dist/state/layout-choice-service.d.ts.map +1 -0
- package/dist/state/layout-choice-service.js +34 -0
- package/dist/state/layout-choice-service.js.map +1 -0
- package/dist/state/menu-service.d.ts +1 -1
- package/dist/state/menu-service.js +2 -2
- package/dist/state/menu-service.js.map +1 -1
- package/dist/state/otp-service.d.ts +69 -0
- package/dist/state/otp-service.d.ts.map +1 -0
- package/dist/state/otp-service.js +212 -0
- package/dist/state/otp-service.js.map +1 -0
- package/dist/state/preference-sync.d.ts +1 -1
- package/dist/state/preference-sync.d.ts.map +1 -1
- package/dist/state/preference-sync.js +11 -3
- package/dist/state/preference-sync.js.map +1 -1
- package/dist/state/signals.d.ts +9 -1
- package/dist/state/signals.d.ts.map +1 -1
- package/dist/state/signals.js +28 -4
- package/dist/state/signals.js.map +1 -1
- package/dist/theme/custom-themes.d.ts +28 -0
- package/dist/theme/custom-themes.d.ts.map +1 -0
- package/dist/theme/custom-themes.js +218 -0
- package/dist/theme/custom-themes.js.map +1 -0
- package/dist/theme/dark-themes.d.ts +9 -1
- package/dist/theme/dark-themes.d.ts.map +1 -1
- package/dist/theme/dark-themes.js +74 -2
- package/dist/theme/dark-themes.js.map +1 -1
- package/dist/theme/logo.d.ts +6 -3
- package/dist/theme/logo.d.ts.map +1 -1
- package/dist/theme/logo.js +17 -3
- package/dist/theme/logo.js.map +1 -1
- package/dist/theme/theme-service.d.ts +14 -3
- package/dist/theme/theme-service.d.ts.map +1 -1
- package/dist/theme/theme-service.js +64 -10
- package/dist/theme/theme-service.js.map +1 -1
- package/dist/types/field-wrapper.d.ts +2 -0
- package/dist/types/field-wrapper.d.ts.map +1 -1
- package/dist/types/field-wrapper.js +3 -2
- package/dist/types/field-wrapper.js.map +1 -1
- package/dist/types/type.otp.d.ts +2 -0
- package/dist/types/type.otp.d.ts.map +1 -1
- package/dist/types/type.otp.js +2 -2
- package/dist/types/type.otp.js.map +1 -1
- package/dist/utils/app-http.d.ts +41 -1
- package/dist/utils/app-http.d.ts.map +1 -1
- package/dist/utils/app-http.js +188 -12
- package/dist/utils/app-http.js.map +1 -1
- package/dist/utils/content-util.d.ts +6 -0
- package/dist/utils/content-util.d.ts.map +1 -0
- package/dist/utils/content-util.js +45 -0
- package/dist/utils/content-util.js.map +1 -0
- package/dist/utils/error-util.d.ts +3 -0
- package/dist/utils/error-util.d.ts.map +1 -0
- package/dist/utils/error-util.js +58 -0
- package/dist/utils/error-util.js.map +1 -0
- package/dist/utils/language-util.d.ts +3 -3
- package/dist/utils/language-util.d.ts.map +1 -1
- package/dist/utils/language-util.js +7 -7
- package/dist/utils/language-util.js.map +1 -1
- package/dist/utils/menu-util.js +1 -1
- package/dist/utils/menu-util.js.map +1 -1
- package/dist/utils/signal-source.d.ts +4 -0
- package/dist/utils/signal-source.d.ts.map +1 -0
- package/dist/utils/signal-source.js +13 -0
- package/dist/utils/signal-source.js.map +1 -0
- package/dist/utils/storage-keys.d.ts +5 -0
- package/dist/utils/storage-keys.d.ts.map +1 -1
- package/dist/utils/storage-keys.js +5 -0
- package/dist/utils/storage-keys.js.map +1 -1
- package/package.json +3 -3
- package/src/components/app-brand.tsx +9 -5
- package/src/components/coming-soon.tsx +3 -2
- package/src/components/language-switcher.tsx +26 -7
- package/src/components/otp-modal.tsx +154 -0
- package/src/components/settings-menu.tsx +28 -2
- package/src/context/use-ui.ts +4 -3
- package/src/i18n/browser-language.ts +98 -0
- package/src/i18n/default-messages.ts +15 -0
- package/src/i18n/locale-groups.ts +87 -0
- package/src/i18n/locale-service.ts +99 -27
- package/src/i18n/locale-signal.ts +173 -0
- package/src/i18n/translator.ts +38 -12
- package/src/index.ts +102 -4
- package/src/interfaces/app-types.ts +6 -0
- package/src/interfaces/ui-config.ts +191 -15
- package/src/interfaces/ui-context.ts +1 -1
- package/src/layouts/auth-layout.tsx +1 -1
- package/src/providers/provider-effects.ts +5 -2
- package/src/providers/register-config.ts +2 -0
- package/src/providers/shared-web-ui-provider.tsx +26 -43
- package/src/query/query-param.ts +6 -2
- package/src/state/api-loader.ts +205 -0
- package/src/state/auth-service.ts +84 -3
- package/src/state/branch-service.ts +3 -3
- package/src/state/company-service.ts +107 -0
- package/src/state/language-service.ts +12 -7
- package/src/state/layout-choice-service.ts +40 -0
- package/src/state/menu-service.ts +2 -2
- package/src/state/otp-service.ts +283 -0
- package/src/state/preference-sync.ts +11 -3
- package/src/state/signals.ts +36 -4
- package/src/theme/custom-themes.ts +236 -0
- package/src/theme/dark-themes.ts +80 -3
- package/src/theme/logo.ts +19 -4
- package/src/theme/org-themes.json +70 -0
- package/src/theme/theme-service.ts +70 -10
- package/src/types/field-wrapper.tsx +5 -2
- package/src/types/type.otp.tsx +11 -2
- package/src/utils/app-http.ts +205 -12
- package/src/utils/content-util.ts +49 -0
- package/src/utils/error-util.ts +64 -0
- package/src/utils/language-util.ts +7 -7
- package/src/utils/menu-util.ts +1 -1
- package/src/utils/signal-source.ts +15 -0
- package/src/utils/storage-keys.ts +6 -0
package/src/index.ts
CHANGED
|
@@ -21,12 +21,24 @@ export type {
|
|
|
21
21
|
NavItem,
|
|
22
22
|
NavigationMode,
|
|
23
23
|
ScreenPermissions,
|
|
24
|
+
ApiSource,
|
|
25
|
+
AppType,
|
|
26
|
+
ValueSignal,
|
|
27
|
+
CompanyDetails,
|
|
28
|
+
CompanySource,
|
|
29
|
+
CustomTheme,
|
|
30
|
+
CustomThemeEntry,
|
|
31
|
+
CustomThemeMap,
|
|
32
|
+
CustomThemes,
|
|
33
|
+
CustomThemesModule,
|
|
34
|
+
LocaleBundle,
|
|
35
|
+
ThemesLoader,
|
|
24
36
|
Theme,
|
|
25
37
|
PageMode,
|
|
26
38
|
ToastPosition,
|
|
27
39
|
UiConfig,
|
|
28
40
|
} from "./interfaces/ui-config.ts";
|
|
29
|
-
export type { HttpConfig } from "./interfaces/ui-config.ts";
|
|
41
|
+
export type { HttpConfig, OtpConfig } from "./interfaces/ui-config.ts";
|
|
30
42
|
export type {
|
|
31
43
|
AuthUser,
|
|
32
44
|
BranchOption,
|
|
@@ -77,6 +89,9 @@ export {
|
|
|
77
89
|
queryParamsSignal,
|
|
78
90
|
progressSignal,
|
|
79
91
|
themeSignal,
|
|
92
|
+
appTypeSignal,
|
|
93
|
+
customThemesSignal,
|
|
94
|
+
companyDetailsSignal,
|
|
80
95
|
toastsSignal,
|
|
81
96
|
translationSignal,
|
|
82
97
|
uiConfigSignal,
|
|
@@ -113,19 +128,52 @@ export {
|
|
|
113
128
|
changeLanguage,
|
|
114
129
|
loadLocaleMessages,
|
|
115
130
|
readDefaultLanguage,
|
|
131
|
+
readFallbackLanguage,
|
|
132
|
+
readBrowserLanguage,
|
|
133
|
+
readStartLanguageCandidates,
|
|
116
134
|
unwrapLocaleModule,
|
|
117
135
|
} from "./i18n/locale-service.ts";
|
|
118
|
-
export {
|
|
136
|
+
export { MAX_KEY_PARTS, findDeepLocaleKeys, interpolate, lookupMessage, translate } from "./i18n/translator.ts";
|
|
119
137
|
export { RTL_LANGUAGE_CODES, findLanguageOption, resolveDirection } from "./i18n/direction.ts";
|
|
138
|
+
export { matchLanguageCode, readBrowserLanguageCodes } from "./i18n/browser-language.ts";
|
|
139
|
+
export { isSignalSource } from "./utils/signal-source.ts";
|
|
140
|
+
export {
|
|
141
|
+
LOCALE_WAIT_MS,
|
|
142
|
+
fillLocaleBundle,
|
|
143
|
+
requestedLocalesSignal,
|
|
144
|
+
type WritableLocaleBundleSignal,
|
|
145
|
+
} from "./i18n/locale-signal.ts";
|
|
146
|
+
export {
|
|
147
|
+
ROOT_LOCALE_GROUP,
|
|
148
|
+
loadLocaleGroups,
|
|
149
|
+
readLocaleFilePath,
|
|
150
|
+
type LocaleFileLoader,
|
|
151
|
+
type LocaleGroupFiles,
|
|
152
|
+
} from "./i18n/locale-groups.ts";
|
|
120
153
|
export { DEFAULT_UI_MESSAGES } from "./i18n/default-messages.ts";
|
|
121
154
|
export {
|
|
122
155
|
changeTheme,
|
|
123
156
|
isDarkThemeName,
|
|
124
157
|
readDarkThemeNames,
|
|
158
|
+
readThemeNames,
|
|
125
159
|
splitThemesByMode,
|
|
126
160
|
type ThemeGroups,
|
|
127
161
|
} from "./theme/theme-service.ts";
|
|
128
|
-
export { DEFAULT_DARK_THEMES } from "./theme/dark-themes.ts";
|
|
162
|
+
export { DAISYUI_THEMES, DEFAULT_DARK_THEMES } from "./theme/dark-themes.ts";
|
|
163
|
+
export {
|
|
164
|
+
buildCustomThemeCss,
|
|
165
|
+
isValidCustomTheme,
|
|
166
|
+
followConfigThemes,
|
|
167
|
+
loadConfigThemes,
|
|
168
|
+
mergeCustomThemes,
|
|
169
|
+
setCustomThemes,
|
|
170
|
+
toCustomThemeList,
|
|
171
|
+
unwrapThemesModule,
|
|
172
|
+
} from "./theme/custom-themes.ts";
|
|
173
|
+
export { isCompanyPending, readAppNameLabel, readCompanyDetails, setCompanyDetails } from "./state/company-service.ts";
|
|
174
|
+
export { readLogoUrl } from "./theme/logo.ts";
|
|
175
|
+
export { readContent } from "./utils/content-util.ts";
|
|
176
|
+
export { readErrorMessage } from "./utils/error-util.ts";
|
|
129
177
|
export { ShowToast, clearToasts, removeToast } from "./state/toast-service.ts";
|
|
130
178
|
export { ShowProgress } from "./state/progress-service.ts";
|
|
131
179
|
export { closeSidebar, toggleSidebar } from "./state/sidebar-service.ts";
|
|
@@ -144,9 +192,13 @@ export {
|
|
|
144
192
|
AUTH_USER_KEY,
|
|
145
193
|
authUserSignal,
|
|
146
194
|
endSession,
|
|
195
|
+
handleSessionEvent,
|
|
196
|
+
startSessionSync,
|
|
147
197
|
redirectToLogoutUrl,
|
|
148
198
|
isAuthenticatedSignal,
|
|
149
199
|
readAccessToken,
|
|
200
|
+
readTokenKey,
|
|
201
|
+
refreshSessionToken,
|
|
150
202
|
restoreSession,
|
|
151
203
|
sessionTokenSignal,
|
|
152
204
|
startSession,
|
|
@@ -156,9 +208,15 @@ export {
|
|
|
156
208
|
export {
|
|
157
209
|
API_BASE_URL_ENV,
|
|
158
210
|
AppHttp,
|
|
211
|
+
isHttpUrl,
|
|
212
|
+
joinUrl,
|
|
159
213
|
readJwtToken,
|
|
160
214
|
toAbsoluteUrl,
|
|
161
215
|
uploadToSignedUrl,
|
|
216
|
+
clearSharedGetCache,
|
|
217
|
+
jwtRegenerateCall,
|
|
218
|
+
readRegenerateUrl,
|
|
219
|
+
ensureFreshToken,
|
|
162
220
|
type HttpHeaders,
|
|
163
221
|
type HttpParams,
|
|
164
222
|
} from "./utils/app-http.ts";
|
|
@@ -206,6 +264,7 @@ export {
|
|
|
206
264
|
REGEN_EXPIRES_AT,
|
|
207
265
|
REMEMBER_ME,
|
|
208
266
|
PREFERENCE_EVENT,
|
|
267
|
+
SESSION_EVENT,
|
|
209
268
|
ACTIVE_SESSION_ID,
|
|
210
269
|
LAYOUT_CHOICE,
|
|
211
270
|
SCREEN_ACCESS,
|
|
@@ -231,6 +290,20 @@ export {
|
|
|
231
290
|
} from "./utils/menu-util.ts";
|
|
232
291
|
export { clearMenu, setMenu, setMenuLoading } from "./state/menu-service.ts";
|
|
233
292
|
export { setLanguages } from "./state/language-service.ts";
|
|
293
|
+
export {
|
|
294
|
+
applySavedLayoutChoice,
|
|
295
|
+
changeLayoutChoice,
|
|
296
|
+
layoutChoiceSignal,
|
|
297
|
+
toLayoutChoice,
|
|
298
|
+
type LayoutChoice,
|
|
299
|
+
} from "./state/layout-choice-service.ts";
|
|
300
|
+
export {
|
|
301
|
+
callApiSource,
|
|
302
|
+
clearSessionData,
|
|
303
|
+
loadConfigCompany,
|
|
304
|
+
loadConfigLanguages,
|
|
305
|
+
loadSessionData,
|
|
306
|
+
} from "./state/api-loader.ts";
|
|
234
307
|
export {
|
|
235
308
|
readDefaultLanguageCode,
|
|
236
309
|
readLanguageRows,
|
|
@@ -272,7 +345,7 @@ export { findNavTrail, isNavItemActive, isPathMatch } from "./layouts/navigation
|
|
|
272
345
|
|
|
273
346
|
// ---- Components ----
|
|
274
347
|
export { AppBrand, type AppBrandProps } from "./components/app-brand.tsx";
|
|
275
|
-
export { LanguageSwitcher } from "./components/language-switcher.tsx";
|
|
348
|
+
export { LanguageSwitcher, type LanguageSwitcherProps } from "./components/language-switcher.tsx";
|
|
276
349
|
export { ThemeSwitcher } from "./components/theme-switcher.tsx";
|
|
277
350
|
export { ToastContainer } from "./components/toast-container.tsx";
|
|
278
351
|
export { UserMenu, readInitials, type UserMenuItem, type UserMenuProps } from "./components/user-menu.tsx";
|
|
@@ -285,6 +358,31 @@ export { PageLoader } from "./components/page-loader.tsx";
|
|
|
285
358
|
export { TopProgress } from "./components/top-progress.tsx";
|
|
286
359
|
export { ScrollToTop, scrollToTop, type ScrollToTopProps } from "./components/scroll-to-top.tsx";
|
|
287
360
|
export { SettingsMenu, closeSettings, openSettings, type SettingsMenuProps } from "./components/settings-menu.tsx";
|
|
361
|
+
export { OTP_FORM_ID, OtpModal } from "./components/otp-modal.tsx";
|
|
362
|
+
export {
|
|
363
|
+
DEFAULT_OTP_LENGTH,
|
|
364
|
+
DEFAULT_OTP_RESEND_SECONDS,
|
|
365
|
+
cancelOtpModal,
|
|
366
|
+
closeOtpModal,
|
|
367
|
+
formatOtpCountdown,
|
|
368
|
+
handleOtpResend,
|
|
369
|
+
handleOtpVerify,
|
|
370
|
+
openOtpModal,
|
|
371
|
+
otpIsSendingSignal,
|
|
372
|
+
otpIsVerifyingSignal,
|
|
373
|
+
otpModalSignal,
|
|
374
|
+
otpResendSecondsSignal,
|
|
375
|
+
otpSendCall,
|
|
376
|
+
otpSessionSignal,
|
|
377
|
+
readOtpConfig,
|
|
378
|
+
readOtpLength,
|
|
379
|
+
stopOtpResendCountdown,
|
|
380
|
+
type OtpFormType,
|
|
381
|
+
type OtpModalState,
|
|
382
|
+
type OtpOpenOptions,
|
|
383
|
+
type OtpSession,
|
|
384
|
+
type OtpVerifiedResult,
|
|
385
|
+
} from "./state/otp-service.ts";
|
|
288
386
|
|
|
289
387
|
// ---- Skeletons ----
|
|
290
388
|
export { SkeletonArticle } from "./skeleton/skeleton-article.tsx";
|
|
@@ -83,11 +83,15 @@ export interface LanguageRowType {
|
|
|
83
83
|
code?: string;
|
|
84
84
|
langCode?: string;
|
|
85
85
|
languageCode?: string;
|
|
86
|
+
/** The code as sor /load/LANG sends it: { "key": "en-US", "label": "English", "locale": "English", "disabled": false }. */
|
|
87
|
+
key?: string;
|
|
86
88
|
id?: string;
|
|
87
89
|
/** Name shown in the switcher (usually in that language, "Français"). */
|
|
88
90
|
name?: string;
|
|
89
91
|
label?: string;
|
|
90
92
|
nameLang?: Record<string, string>;
|
|
93
|
+
/** The language's own name ("Français", "हिन्दी"); shown when label and name are missing. */
|
|
94
|
+
locale?: string;
|
|
91
95
|
/** Flag emoji or short text. */
|
|
92
96
|
flag?: string;
|
|
93
97
|
/** "ltr" or "rtl". When missing: rtl for ar, he, fa, ur. */
|
|
@@ -98,6 +102,8 @@ export interface LanguageRowType {
|
|
|
98
102
|
default?: boolean;
|
|
99
103
|
/** false hides the language. */
|
|
100
104
|
active?: boolean;
|
|
105
|
+
/** true hides the language (sor /load/LANG). */
|
|
106
|
+
disabled?: boolean;
|
|
101
107
|
/** Lower numbers come first. */
|
|
102
108
|
priority?: number;
|
|
103
109
|
}
|
|
@@ -13,6 +13,75 @@ export type Direction = LangDirType;
|
|
|
13
13
|
/** A DaisyUI theme name, for example "light", "dark", "corporate", "dracula". */
|
|
14
14
|
export type Theme = string;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* A custom DaisyUI theme as plain data, so it can live in a JSON file or come from an API:
|
|
18
|
+
* { "name": "org-light", "isDark": false, "variables": { "color-primary": "oklch(55.8% 0.154 249.1)" } }
|
|
19
|
+
* The library turns it into [data-theme="org-light"] { color-scheme: light; --color-primary: ...; }.
|
|
20
|
+
* Several themes are an object keyed by theme name (see CustomThemeMap).
|
|
21
|
+
*/
|
|
22
|
+
export interface CustomTheme {
|
|
23
|
+
/** data-theme name: lowercase letters, digits and "-", for example "org-light". */
|
|
24
|
+
name: Theme;
|
|
25
|
+
/** true for a dark theme (color-scheme: dark, dark logo, dark markdown editor). Default false. */
|
|
26
|
+
isDark?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* DaisyUI theme variables, with or without "--" (the same names as in a DaisyUI theme):
|
|
29
|
+
* color-base-100/200/300, color-base-content, color-primary, color-primary-content, color-secondary(-content),
|
|
30
|
+
* color-accent(-content), color-neutral(-content), color-info/success/warning/error(-content),
|
|
31
|
+
* radius-selector, radius-field, radius-box, size-selector, size-field, border, depth, noise.
|
|
32
|
+
*/
|
|
33
|
+
variables: Record<string, string>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Texts per language code for a loadLocale signal: { "en-US": {...}, "fr-FR": {...} }; null = no texts. */
|
|
37
|
+
export type LocaleBundle = Record<string, LocaleMessages | null>;
|
|
38
|
+
|
|
39
|
+
/** One entry of a CustomThemeMap: "name" may be left out (the key is the name). */
|
|
40
|
+
export type CustomThemeEntry = Omit<CustomTheme, "name"> & { name?: Theme };
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The custom themes as an object keyed by theme name (the JSON format of a themes file / API reply):
|
|
44
|
+
* { "org-dark": { "isDark": true, "name": "org-dark", "variables": { ... } },
|
|
45
|
+
* "org-light": { "isDark": false, "name": "org-light", "variables": { ... } } }
|
|
46
|
+
*/
|
|
47
|
+
export type CustomThemeMap = Record<Theme, CustomThemeEntry>;
|
|
48
|
+
|
|
49
|
+
/** Custom themes: the object keyed by theme name (CustomThemeMap), or a plain list. */
|
|
50
|
+
export type CustomThemes = CustomThemeMap | CustomTheme[];
|
|
51
|
+
|
|
52
|
+
/** What a themes loader may return: the themes (object or list), or a JSON module with a default export. */
|
|
53
|
+
export type CustomThemesModule = CustomThemes | { default: CustomThemes };
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Loads the custom themes lazily (like loadLocale), from a JSON file or an API:
|
|
57
|
+
* function loadThemes(): Promise<CustomThemesModule> { return import("./theme/org-themes.json"); }
|
|
58
|
+
* async function loadThemes(): Promise<CustomThemesModule> { const reply = await fetch("/themes.json"); return reply.json(); }
|
|
59
|
+
*/
|
|
60
|
+
export type ThemesLoader = () => Promise<CustomThemesModule>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Company / brand details from the backend (config.loadCompanyDetails or setCompanyDetails):
|
|
64
|
+
* { "appName": "YourAppName", "companyName": "YourBrandName",
|
|
65
|
+
* "faviconUrl": "https://www.w3.org/favicon.ico", "logoUrl": "https://www.w3.org/Icons/w3c_home.png",
|
|
66
|
+
* "logoDarkUrl": "https://www.w3.org/Icons/w3c_home.png" }
|
|
67
|
+
* Every field is optional; a missing field keeps the config value (appName, logoUrl / logoDarkUrl).
|
|
68
|
+
*/
|
|
69
|
+
export interface CompanyDetails {
|
|
70
|
+
/** App label in the header, sidebar and login, and the browser tab title. Wins over config.appName. */
|
|
71
|
+
appName?: string;
|
|
72
|
+
/** Company / brand name: alt text of the logo; read it with companyDetailsSignal (for example in a footer). */
|
|
73
|
+
companyName?: string;
|
|
74
|
+
/** Browser tab icon: written to <link rel="icon">. */
|
|
75
|
+
faviconUrl?: string;
|
|
76
|
+
/** Logo image URL (light themes; also dark themes without logoDarkUrl). Wins over config.logoUrl / config.logoDarkUrl. */
|
|
77
|
+
logoUrl?: string;
|
|
78
|
+
/** Logo image URL on dark themes. Default: logoUrl. Wins over config.logoDarkUrl. */
|
|
79
|
+
logoDarkUrl?: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** What a company details reply may be: the details, or { data: details }; null = not here yet. */
|
|
83
|
+
export type CompanySource = CompanyDetails | { data: CompanyDetails } | null;
|
|
84
|
+
|
|
16
85
|
/**
|
|
17
86
|
* Translations for one language.
|
|
18
87
|
* Values are text or nested groups: { "nav": { "home": "Home" } } is read with t("nav.home").
|
|
@@ -95,6 +164,11 @@ export interface LayoutConfig {
|
|
|
95
164
|
isSidebarCollapsible?: boolean;
|
|
96
165
|
/** "inline": language and theme switchers in the header. "menu": one settings button that opens them. Default "inline". */
|
|
97
166
|
headerSettings?: "inline" | "menu";
|
|
167
|
+
/**
|
|
168
|
+
* Show the layout choice (App layout / Aside layout) in the settings dialog — for apps that render AppLayout or
|
|
169
|
+
* AsideLayout from layoutChoiceSignal (a shell). Saved as LAYOUT_CHOICE. Default false.
|
|
170
|
+
*/
|
|
171
|
+
showLayoutChoice?: boolean;
|
|
98
172
|
/** Where toasts appear. Default "top-end". */
|
|
99
173
|
toastPosition?: ToastPosition;
|
|
100
174
|
/** Show a "scroll to top" button on long pages. Default true. */
|
|
@@ -103,18 +177,61 @@ export interface LayoutConfig {
|
|
|
103
177
|
pageParam?: string;
|
|
104
178
|
/**
|
|
105
179
|
* Where the current page lives in the address:
|
|
106
|
-
* "query"
|
|
107
|
-
* "path" http://host/profiles
|
|
180
|
+
* "query" http://host/?page=profiles (default for type "spa")
|
|
181
|
+
* "path" http://host/profiles (default for type "shell"; the server must answer every path
|
|
182
|
+
* with index.html)
|
|
108
183
|
*/
|
|
109
184
|
pageMode?: PageMode;
|
|
110
185
|
}
|
|
111
186
|
|
|
187
|
+
/**
|
|
188
|
+
* What the app is, passed as <SharedWebUiProvider type="...">:
|
|
189
|
+
* "spa" a normal single app (default): layouts, menu, login, ?page=... pages
|
|
190
|
+
* "shell" the root app that hosts microfrontends: like "spa", but pages are paths by default (/settings)
|
|
191
|
+
* "mfe" a microfrontend inside a shell: page layouts only. The shell owns the menu, branches, logos and app name,
|
|
192
|
+
* so loadMenuNavigation / loadBranches are not called and appName, logoUrl, logoDarkUrl, homePath and
|
|
193
|
+
* branchLabel are not used.
|
|
194
|
+
*/
|
|
195
|
+
export type AppType = "spa" | "shell" | "mfe";
|
|
196
|
+
|
|
197
|
+
/** Anything with a reactive value: a @preact/signals signal or computed (read only). */
|
|
198
|
+
export interface ValueSignal<TValue = unknown> {
|
|
199
|
+
readonly value: TValue;
|
|
200
|
+
peek(): TValue;
|
|
201
|
+
subscribe(listener: (value: TValue) => void): () => void;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* A backend source of the config, one of:
|
|
206
|
+
* - your function that returns the reply (like loadThemes / loadLocale)
|
|
207
|
+
* - a URL / path (sent with AppHttp.Get; a path gets the base URL, see AppHttp)
|
|
208
|
+
* - a signal you fill yourself: null = not here yet (menu: skeleton, branches: no switcher), then the reply;
|
|
209
|
+
* every new value is applied at once (the provider does not call anything for a signal)
|
|
210
|
+
* Replies may be { data: [...], meta } or the list.
|
|
211
|
+
*/
|
|
212
|
+
export type ApiSource = string | (() => Promise<unknown>) | ValueSignal<unknown>;
|
|
213
|
+
|
|
112
214
|
/** "query" = ?page=profiles, "path" = /profiles. */
|
|
113
215
|
export type PageMode = "query" | "path";
|
|
114
216
|
|
|
115
217
|
/** Toast corner / edge. "end" is right in LTR and left in RTL. */
|
|
116
218
|
export type ToastPosition = "top-start" | "top-center" | "top-end" | "bottom-start" | "bottom-center" | "bottom-end";
|
|
117
219
|
|
|
220
|
+
/**
|
|
221
|
+
* The one-time code (OTP) services used by OtpModal / openOtpModal. URLs or paths (a path gets the base URL):
|
|
222
|
+
* http: { otp: { sendUrl: `${MsUrl.sor}/otp-send`, verifyUrl: `${MsUrl.sor}/otp-verify`, resendSeconds: 180 } }
|
|
223
|
+
*/
|
|
224
|
+
export interface OtpConfig {
|
|
225
|
+
/** POST { userid } -> { data: { message, oid, uid } } (or the object itself). */
|
|
226
|
+
sendUrl: string;
|
|
227
|
+
/** POST { otp, oid, uid } -> { data: { message, oid, uid } } (or the object itself). */
|
|
228
|
+
verifyUrl: string;
|
|
229
|
+
/** Seconds before "Resend code" works again. Default 180. */
|
|
230
|
+
resendSeconds?: number;
|
|
231
|
+
/** Number of characters of the code. Default 6. */
|
|
232
|
+
length?: number;
|
|
233
|
+
}
|
|
234
|
+
|
|
118
235
|
/** Backend settings used by AppHttp and the session. */
|
|
119
236
|
export interface HttpConfig {
|
|
120
237
|
/** API base URL, for example "https://api.example.com/api" or "/api". window.env API_BASE_URL wins when set. */
|
|
@@ -125,10 +242,18 @@ export interface HttpConfig {
|
|
|
125
242
|
tokenKey?: string;
|
|
126
243
|
/** Extra headers sent with every request. */
|
|
127
244
|
headers?: Record<string, string>;
|
|
128
|
-
/** URL of the options loader used by AppHttp.Load(id) — the id is added: `${loadUrl}/${id}`. Default:
|
|
245
|
+
/** URL (or path, added to the base URL) of the options loader used by AppHttp.Load(id) — the id is added: `${loadUrl}/${id}`. Default: "/load". */
|
|
129
246
|
loadUrl?: string;
|
|
130
247
|
/** Show the top progress bar during requests. Default true. */
|
|
131
248
|
showProgress?: boolean;
|
|
249
|
+
/**
|
|
250
|
+
* URL (or path) of the JWT regenerate service (GET, answers { token } or { data: { token } }), for example
|
|
251
|
+
* `${MsUrl.utils}/jwt-regenerate`. Before a request, when JwtValid(token) is false, AppHttp gets a new token
|
|
252
|
+
* (saved in sessionStorage); an error logs out (endSession -> logoutUrl). Not set: no regeneration.
|
|
253
|
+
*/
|
|
254
|
+
regenerateUrl?: string;
|
|
255
|
+
/** One-time code services of OtpModal (send / verify). Not set: openOtpModal shows an error toast. */
|
|
256
|
+
otp?: OtpConfig;
|
|
132
257
|
}
|
|
133
258
|
|
|
134
259
|
/** The whole configuration of an app. */
|
|
@@ -139,6 +264,30 @@ export interface UiConfig {
|
|
|
139
264
|
* - window.env names: REACT_APP_ORG_API_BASE_URL (AppStorage.envData("API_BASE_URL"))
|
|
140
265
|
*/
|
|
141
266
|
appNameKey: string;
|
|
267
|
+
/**
|
|
268
|
+
* Loads the supported languages (backend list): called once when the provider mounts, like loadThemes.
|
|
269
|
+
* On an error the default language stays. By hand: setLanguages(reply).
|
|
270
|
+
*/
|
|
271
|
+
loadSupportLanguages?: ApiSource;
|
|
272
|
+
/**
|
|
273
|
+
* Loads the branches of the signed-in user: called after sign in (and on start when a session is restored),
|
|
274
|
+
* BEFORE loadMenuNavigation, so the menu request already sends x-branch-id. Removed on sign out.
|
|
275
|
+
* Not called for type "mfe". By hand: setBranches(reply).
|
|
276
|
+
*/
|
|
277
|
+
loadBranches?: ApiSource;
|
|
278
|
+
/**
|
|
279
|
+
* Loads the menu of the signed-in user: called after sign in (and on start when a session is restored); the menu
|
|
280
|
+
* shows a skeleton until it answers, an error shows an empty menu. Removed on sign out. Not called for type "mfe".
|
|
281
|
+
* Without it the menu is config.navigation. By hand: setMenuLoading() -> setMenu(reply).
|
|
282
|
+
*/
|
|
283
|
+
loadMenuNavigation?: ApiSource;
|
|
284
|
+
/**
|
|
285
|
+
* Loads the company details ({ appName, companyName, faviconUrl, logoUrl, logoDarkUrl }): called once when the provider mounts,
|
|
286
|
+
* like loadSupportLanguages. Its values win over appName / logoUrl / logoDarkUrl; faviconUrl sets the tab icon.
|
|
287
|
+
* Type "mfe": usually not set (the shell owns the brand); an MFE that shows the brand (an auth MFE) may set it.
|
|
288
|
+
* By hand: setCompanyDetails(reply).
|
|
289
|
+
*/
|
|
290
|
+
loadCompanyDetails?: ApiSource;
|
|
142
291
|
/** Label shown in the header, sidebar and login: t(appName), so plain text or a translation key. Default: appNameKey. */
|
|
143
292
|
appName?: string;
|
|
144
293
|
/** Optional logo image URL (light themes). */
|
|
@@ -147,24 +296,51 @@ export interface UiConfig {
|
|
|
147
296
|
logoDarkUrl?: string;
|
|
148
297
|
/**
|
|
149
298
|
* Static language list. Not needed when the languages come from the backend:
|
|
150
|
-
* pass them with
|
|
299
|
+
* pass them with config.loadSupportLanguages or setLanguages(langResponse).
|
|
151
300
|
*/
|
|
152
301
|
languages?: LanguageOption[];
|
|
153
|
-
/**
|
|
154
|
-
|
|
155
|
-
|
|
302
|
+
/**
|
|
303
|
+
* The texts of a language: a function loadLocale(code) (lazy JSON / API), or a SIGNAL with a LocaleBundle
|
|
304
|
+
* ({ "en-US": {...} }) that the app fills — the library adds the codes it needs to requestedLocalesSignal and
|
|
305
|
+
* waits; fillLocaleBundle(signal, loader) does the filling.
|
|
306
|
+
*/
|
|
307
|
+
loadLocale?: LocaleCodeLoader | ValueSignal<LocaleBundle | null>;
|
|
308
|
+
/**
|
|
309
|
+
* Language code used on the first visit (nothing saved; a backend isDefault language still wins).
|
|
310
|
+
* Optional: without it the browser / system language (navigator.languages matched to the list,
|
|
311
|
+
* "fr-CA" -> "fr-FR"), else "en-US". Keys missing in a language are shown in defaultLanguage (else "en-US").
|
|
312
|
+
*/
|
|
156
313
|
defaultLanguage?: string;
|
|
157
|
-
/**
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
314
|
+
/**
|
|
315
|
+
* DaisyUI themes offered in the theme switcher. Optional, default: all 35 DaisyUI themes
|
|
316
|
+
* (enable them in your CSS: @plugin "daisyui" { themes: all; }). The customThemes are always listed first.
|
|
317
|
+
*/
|
|
318
|
+
themes?: Theme[];
|
|
319
|
+
/**
|
|
320
|
+
* Your own themes as data (for example imported from a JSON file), an object keyed by theme name
|
|
321
|
+
* ({ "org-light": {...}, "org-dark": {...} }) or a list; no CSS file needed. Themes that arrive later
|
|
322
|
+
* (fetched JSON) go through setCustomThemes(json).
|
|
323
|
+
*/
|
|
324
|
+
customThemes?: CustomThemes;
|
|
325
|
+
/**
|
|
326
|
+
* Custom themes loaded when the provider mounts (JSON file or API), like loadLocale — or a SIGNAL with the themes
|
|
327
|
+
* (null = not here yet; every new value replaces them). They are added to customThemes (same name: the loaded one
|
|
328
|
+
* wins). A saved custom theme stays on screen while they load.
|
|
329
|
+
*/
|
|
330
|
+
loadThemes?: ThemesLoader | ValueSignal<CustomThemesModule | null>;
|
|
331
|
+
/**
|
|
332
|
+
* Theme used on the first visit (nothing saved yet). Optional: without it the browser preference decides,
|
|
333
|
+
* "dark" when it prefers a dark colour scheme, otherwise "light".
|
|
334
|
+
*/
|
|
335
|
+
defaultTheme?: Theme;
|
|
336
|
+
/**
|
|
337
|
+
* Which of the themes are dark (used for dark logos and the markdown editor). Default: the DaisyUI dark themes.
|
|
338
|
+
* Custom themes with isDark: true are always added.
|
|
339
|
+
*/
|
|
164
340
|
darkThemes?: Theme[];
|
|
165
341
|
/**
|
|
166
342
|
* Static navigation items. Optional when the menu comes from the backend:
|
|
167
|
-
* pass it with
|
|
343
|
+
* pass it with config.loadMenuNavigation or setMenu(menuResponse).
|
|
168
344
|
*/
|
|
169
345
|
navigation?: NavItem[];
|
|
170
346
|
/** How backend menus are converted (root group flattening). */
|
|
@@ -23,7 +23,7 @@ export interface UiContextValue {
|
|
|
23
23
|
isReady: boolean;
|
|
24
24
|
/** Languages from the config. */
|
|
25
25
|
languages: LanguageOption[];
|
|
26
|
-
/** Themes
|
|
26
|
+
/** Themes of the switcher: the custom themes first, then config.themes (default: all DaisyUI themes). */
|
|
27
27
|
themes: Theme[];
|
|
28
28
|
/** themes without the dark ones (config order). */
|
|
29
29
|
lightThemes: Theme[];
|
|
@@ -25,7 +25,7 @@ export function AuthLayout(props: AuthLayoutProps) {
|
|
|
25
25
|
return (
|
|
26
26
|
<div className="flex min-h-screen flex-col bg-base-200">
|
|
27
27
|
<header className="flex justify-end gap-1 p-3">
|
|
28
|
-
<LanguageSwitcher />
|
|
28
|
+
<LanguageSwitcher isFullName />
|
|
29
29
|
<ThemeSwitcher />
|
|
30
30
|
</header>
|
|
31
31
|
<main className="flex flex-1 items-center justify-center p-4">
|
|
@@ -5,16 +5,19 @@
|
|
|
5
5
|
import { initializeLanguage, readActiveConfig } from "../i18n/locale-service.ts";
|
|
6
6
|
import { isTranslationReadySignal } from "../state/signals.ts";
|
|
7
7
|
import { startDocumentSync } from "../state/document-sync.ts";
|
|
8
|
+
import { followConfigThemes, loadConfigThemes } from "../theme/custom-themes.ts";
|
|
8
9
|
import { initializeTheme } from "../theme/theme-service.ts";
|
|
9
10
|
|
|
10
11
|
/** Empty dependency list: run the effect only once. */
|
|
11
12
|
export const RUN_ONCE: never[] = [];
|
|
12
13
|
|
|
13
|
-
/** Applies the saved theme
|
|
14
|
-
export function initializeThemeOnMount(): void {
|
|
14
|
+
/** Applies the saved theme, starts syncing <html> attributes and loads / follows config.loadThemes. */
|
|
15
|
+
export function initializeThemeOnMount(): () => void {
|
|
15
16
|
const config = readActiveConfig();
|
|
16
17
|
initializeTheme(config);
|
|
17
18
|
startDocumentSync();
|
|
19
|
+
void loadConfigThemes(config);
|
|
20
|
+
return followConfigThemes(config);
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
/** Shows the app even when a locale file fails, so the screen is never stuck on loading. */
|
|
@@ -9,6 +9,7 @@ import { forgetAppliedLanguages } from "../state/language-service.ts";
|
|
|
9
9
|
import { forgetAppliedMenu } from "../state/menu-service.ts";
|
|
10
10
|
import { initializeNavigation } from "../state/navigation-service.ts";
|
|
11
11
|
import { languagesSignal, uiConfigSignal } from "../state/signals.ts";
|
|
12
|
+
import { setCustomThemes } from "../theme/custom-themes.ts";
|
|
12
13
|
import { setAppConfig } from "../utils/app-config.ts";
|
|
13
14
|
import { AppStorage } from "../utils/app-storage.ts";
|
|
14
15
|
|
|
@@ -21,6 +22,7 @@ export function registerUiConfig(config: UiConfig): void {
|
|
|
21
22
|
setAppConfig(config);
|
|
22
23
|
uiConfigSignal.value = config;
|
|
23
24
|
languagesSignal.value = config.languages ?? [];
|
|
25
|
+
setCustomThemes(config.customThemes);
|
|
24
26
|
forgetAppliedLanguages();
|
|
25
27
|
initializeNavigation(config);
|
|
26
28
|
forgetAppliedMenu();
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
// shared-web-ui-provider.tsx
|
|
2
|
-
// The single entry point of the
|
|
2
|
+
// The single entry point of the app. Wrap your app once:
|
|
3
3
|
//
|
|
4
|
-
// <SharedWebUiProvider config={config}>
|
|
4
|
+
// <SharedWebUiProvider type="spa" config={config}> type: "spa" (default) | "shell" | "mfe"
|
|
5
5
|
// <App />
|
|
6
6
|
// </SharedWebUiProvider>
|
|
7
7
|
//
|
|
8
|
-
// Menu and
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// <SharedWebUiProvider config={config} branch={branchResponse}> (isDefault / disabled come with the rows)
|
|
8
|
+
// Menu, languages and branches come from the backend through config loaders (the provider calls them itself):
|
|
9
|
+
// loadSupportLanguages, loadBranches, loadMenuNavigation (like loadThemes)
|
|
10
|
+
// lang on start; branch and nav after sign in (removed on sign out). Type "mfe" calls only lang.
|
|
11
|
+
// By hand (no loaders): setLanguages(reply), setBranches(reply), setMenu(reply).
|
|
13
12
|
//
|
|
14
13
|
// It provides: config context, theme, translations, query parameter sync and toasts.
|
|
15
|
-
// There is no router: the current page is
|
|
14
|
+
// There is no router: the current page is ?page=... (or the path for pageMode "path" / type "shell").
|
|
16
15
|
|
|
17
16
|
import { useLayoutEffect, type ReactNode } from "react";
|
|
18
17
|
import { startScrollListener } from "../components/scroll-to-top.tsx";
|
|
@@ -20,13 +19,13 @@ import { ToastContainer } from "../components/toast-container.tsx";
|
|
|
20
19
|
import { TopProgress } from "../components/top-progress.tsx";
|
|
21
20
|
import { MediaViewer } from "../types/media-viewer.tsx";
|
|
22
21
|
import { UiContext, readContextState } from "../context/ui-context.ts";
|
|
23
|
-
import type {
|
|
24
|
-
import type { UiConfig } from "../interfaces/ui-config.ts";
|
|
22
|
+
import type { AppType, UiConfig } from "../interfaces/ui-config.ts";
|
|
25
23
|
import { startQueryParamSync } from "../query/query-param.ts";
|
|
26
|
-
import {
|
|
24
|
+
import { startApiLoading } from "../state/api-loader.ts";
|
|
25
|
+
import { applySavedLayoutChoice } from "../state/layout-choice-service.ts";
|
|
27
26
|
import { startPreferenceSync } from "../state/preference-sync.ts";
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
27
|
+
import { startSessionSync } from "../state/auth-service.ts";
|
|
28
|
+
import { appTypeSignal } from "../state/signals.ts";
|
|
30
29
|
import { startEscapeListener } from "../utils/event-util.ts";
|
|
31
30
|
import { RUN_ONCE } from "./provider-effects.ts";
|
|
32
31
|
import { ThemeProvider } from "./theme-provider.tsx";
|
|
@@ -34,53 +33,37 @@ import { TranslationProvider } from "./translation-provider.tsx";
|
|
|
34
33
|
import { registerUiConfig } from "./register-config.ts";
|
|
35
34
|
|
|
36
35
|
export interface SharedWebUiProviderProps {
|
|
37
|
-
/** The app configuration (usually imported from config.ts). */
|
|
36
|
+
/** The app configuration (usually imported from config.ts). Backend loaders: loadSupportLanguages, loadBranches, loadMenuNavigation. */
|
|
38
37
|
config: UiConfig;
|
|
39
38
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* What the app is: "spa" (default), "shell" (hosts microfrontends; pages are paths by default) or "mfe"
|
|
40
|
+
* (a microfrontend: page layouts only; no menu / branch calls; appName, logos, homePath, branchLabel unused).
|
|
42
41
|
*/
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Languages from the backend: the reply { data: [...], meta } or the list. Replaces config.languages.
|
|
46
|
-
* null = not here yet (config.defaultLanguage is shown meanwhile). Texts load with config.loadLocale(code).
|
|
47
|
-
*/
|
|
48
|
-
lang?: LangSource | null;
|
|
49
|
-
/**
|
|
50
|
-
* Branches from the backend: the reply { data: [...], meta } or the list ({ id, name, nameLang?, isDefault?, disabled? }).
|
|
51
|
-
* The row with isDefault is selected when the user has none saved; disabled rows can not be selected.
|
|
52
|
-
* null or [] = no branch switcher. The selected branch is sent as x-branch-id by AppHttp.
|
|
53
|
-
*/
|
|
54
|
-
branch?: BranchSource | null;
|
|
42
|
+
type?: AppType;
|
|
55
43
|
/** Your app. */
|
|
56
44
|
children?: ReactNode;
|
|
57
45
|
/** Shown while the first locale file loads. */
|
|
58
46
|
loadingFallback?: ReactNode;
|
|
59
47
|
}
|
|
60
48
|
|
|
61
|
-
/**
|
|
62
|
-
export function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
): void {
|
|
67
|
-
registerMenu(nav);
|
|
68
|
-
registerLanguages(lang);
|
|
69
|
-
registerBranches(branch);
|
|
49
|
+
/** Saves the app type (before the config, so the page mode is right on the first render). */
|
|
50
|
+
export function registerAppType(type: AppType): void {
|
|
51
|
+
if (appTypeSignal.peek() !== type) {
|
|
52
|
+
appTypeSignal.value = type;
|
|
53
|
+
}
|
|
70
54
|
}
|
|
71
55
|
|
|
72
56
|
export function SharedWebUiProvider(props: SharedWebUiProviderProps) {
|
|
73
|
-
const { config,
|
|
57
|
+
const { config, type = "spa", children, loadingFallback } = props;
|
|
58
|
+
registerAppType(type);
|
|
74
59
|
registerUiConfig(config);
|
|
75
|
-
// nav / lang / branch are written to signals AFTER the render (layout effect, still before the paint), so no other
|
|
76
|
-
// component is updated while this one renders (React warns about that).
|
|
77
|
-
const applyInputs = applyProviderInputs.bind(null, nav, lang, branch);
|
|
78
|
-
const inputs = [nav, lang, branch];
|
|
79
|
-
useLayoutEffect(applyInputs, inputs);
|
|
80
60
|
useLayoutEffect(startQueryParamSync, RUN_ONCE);
|
|
81
61
|
useLayoutEffect(startEscapeListener, RUN_ONCE);
|
|
82
62
|
useLayoutEffect(startScrollListener, RUN_ONCE);
|
|
83
63
|
useLayoutEffect(startPreferenceSync, RUN_ONCE);
|
|
64
|
+
useLayoutEffect(startSessionSync, RUN_ONCE);
|
|
65
|
+
useLayoutEffect(applySavedLayoutChoice, RUN_ONCE);
|
|
66
|
+
useLayoutEffect(startApiLoading, RUN_ONCE);
|
|
84
67
|
const contextState = readContextState(config);
|
|
85
68
|
|
|
86
69
|
return (
|