@fluid-topics/ft-app-context 2.0.14 → 2.0.16
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/build/ft-app-context.d.ts +4 -14
- package/build/ft-app-context.js +26 -89
- package/build/ft-app-context.light.js +4 -4
- package/build/ft-app-context.min.js +18 -18
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/redux-stores/FtAppInfoStore.d.ts +8 -1
- package/build/redux-stores/FtAppInfoStore.js +11 -3
- package/build/redux-stores/FtAppStateManager.d.ts +42 -0
- package/build/redux-stores/FtAppStateManager.js +153 -0
- package/build/services/history/HistoryService.models.js +1 -2
- package/build/services/user/UserLocaleService.d.ts +5 -0
- package/build/services/user/UserLocaleService.js +6 -0
- package/package.json +4 -4
package/build/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./services";
|
|
|
6
6
|
export * from "./ft-app-context.styles";
|
|
7
7
|
export * from "./ft-app-context.properties";
|
|
8
8
|
export * from "./ft-app-context";
|
|
9
|
+
export * from "./redux-stores/FtAppStateManager";
|
|
9
10
|
declare global {
|
|
10
11
|
interface Window {
|
|
11
12
|
fluidTopicsBaseUrl?: string;
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FtReduxStore, Optional } from "@fluid-topics/ft-wc-utils";
|
|
2
|
-
import { FtDefaultLocales, FtMetadataConfiguration, FtPrivacyPolicyConfiguration, FtSearchLocale, FtSession, FtUiLocale } from "@fluid-topics/public-api";
|
|
2
|
+
import { FtDefaultLocales, FtMetadataConfiguration, FtPrivacyPolicyConfiguration, FtSearchLocale, FtSession, FtUiLocale, FtUserLocaleSummary } from "@fluid-topics/public-api";
|
|
3
3
|
import { PayloadAction } from "@reduxjs/toolkit";
|
|
4
4
|
export declare const FtAppInfoStoreName = "ft-app-info";
|
|
5
5
|
export interface FtAppInfoState {
|
|
@@ -11,6 +11,9 @@ export interface FtAppInfoState {
|
|
|
11
11
|
availableContentLocales: Array<FtSearchLocale>;
|
|
12
12
|
defaultLocales: FtDefaultLocales | undefined;
|
|
13
13
|
searchInAllLanguagesAllowed: boolean;
|
|
14
|
+
searchLanguageSetsUiLanguage: boolean;
|
|
15
|
+
uiLanguageSetsSearchLanguage: boolean;
|
|
16
|
+
uiLanguageSetsReaderLanguage: boolean;
|
|
14
17
|
metadataConfiguration: Optional<FtMetadataConfiguration>;
|
|
15
18
|
privacyPolicyConfiguration: Optional<FtPrivacyPolicyConfiguration>;
|
|
16
19
|
editorMode: boolean;
|
|
@@ -26,6 +29,10 @@ export declare class AuthenticationChangeEvent extends CustomEvent<Optional<FtSe
|
|
|
26
29
|
static eventName: string;
|
|
27
30
|
constructor(session: Optional<FtSession>);
|
|
28
31
|
}
|
|
32
|
+
export declare class UiLocaleChangedEvent extends CustomEvent<FtUserLocaleSummary> {
|
|
33
|
+
static eventName: string;
|
|
34
|
+
constructor(localeSummary: FtUserLocaleSummary);
|
|
35
|
+
}
|
|
29
36
|
declare const reducers: {
|
|
30
37
|
session: (state: FtAppInfoState, action: PayloadAction<Optional<FtSession>>) => void;
|
|
31
38
|
};
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { deepEqual, FtReduxStore } from "@fluid-topics/ft-wc-utils";
|
|
1
|
+
import { deepEqual, FtReduxStore, } from "@fluid-topics/ft-wc-utils";
|
|
2
2
|
export const FtAppInfoStoreName = "ft-app-info";
|
|
3
|
-
class AuthenticationChangeEvent extends CustomEvent {
|
|
3
|
+
export class AuthenticationChangeEvent extends CustomEvent {
|
|
4
4
|
constructor(session) {
|
|
5
5
|
super(AuthenticationChangeEvent.eventName, { detail: session });
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
AuthenticationChangeEvent.eventName = "authentication-change";
|
|
9
|
-
export
|
|
9
|
+
export class UiLocaleChangedEvent extends CustomEvent {
|
|
10
|
+
constructor(localeSummary) {
|
|
11
|
+
super(UiLocaleChangedEvent.eventName, { detail: localeSummary });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
UiLocaleChangedEvent.eventName = "ui-locale-changed";
|
|
10
15
|
const reducers = {
|
|
11
16
|
session: (state, action) => {
|
|
12
17
|
if (!deepEqual(state.session, action.payload)) {
|
|
@@ -27,6 +32,9 @@ export const ftAppInfoStore = FtReduxStore.get({
|
|
|
27
32
|
availableContentLocales: [],
|
|
28
33
|
defaultLocales: undefined,
|
|
29
34
|
searchInAllLanguagesAllowed: false,
|
|
35
|
+
searchLanguageSetsUiLanguage: false,
|
|
36
|
+
uiLanguageSetsSearchLanguage: false,
|
|
37
|
+
uiLanguageSetsReaderLanguage: false,
|
|
30
38
|
metadataConfiguration: undefined,
|
|
31
39
|
privacyPolicyConfiguration: undefined,
|
|
32
40
|
editorMode: false,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Debouncer, FtReduxStore, FtStateManager } from "@fluid-topics/ft-wc-utils";
|
|
2
|
+
import { FtAppInfoState, FtAppInfoStateReducers } from "./FtAppInfoStore";
|
|
3
|
+
import { FluidTopicsApi, FtLocalesConfiguration, FtMetadataConfiguration, FtSession } from "@fluid-topics/public-api";
|
|
4
|
+
import { UserLocaleService } from "../services/user/UserLocaleService";
|
|
5
|
+
export declare class FtAppStateManager extends FtStateManager {
|
|
6
|
+
readonly store: FtReduxStore<FtAppInfoState, FtAppInfoStateReducers>;
|
|
7
|
+
static build(apiProvider?: () => FluidTopicsApi | undefined): FtAppStateManager;
|
|
8
|
+
readonly apiProvider: () => FluidTopicsApi | undefined;
|
|
9
|
+
private cache;
|
|
10
|
+
withManualResources: boolean;
|
|
11
|
+
localesConfiguration: FtLocalesConfiguration | null;
|
|
12
|
+
userLocaleService: UserLocaleService;
|
|
13
|
+
constructor(store: FtReduxStore<FtAppInfoState, FtAppInfoStateReducers>, apiProvider?: () => FluidTopicsApi | undefined);
|
|
14
|
+
setWithManualResources(withManualResources: boolean): void;
|
|
15
|
+
initService(): Promise<void>;
|
|
16
|
+
updateIfNeeded(): Promise<void>;
|
|
17
|
+
private cleanSessionDebouncer;
|
|
18
|
+
private updateSession;
|
|
19
|
+
updateMetadataConfiguration(): Promise<void>;
|
|
20
|
+
updateLocalesConfiguration(): Promise<void>;
|
|
21
|
+
updateAvailableContentLocales(): Promise<void>;
|
|
22
|
+
private reloadConfiguration;
|
|
23
|
+
setBaseUrl(baseUrl?: string): void;
|
|
24
|
+
setApiIntegrationIdentifier(apiIntegrationIdentifier: string): void;
|
|
25
|
+
setApiIntegrationAppVersion(apiIntegrationAppVersion: string): void;
|
|
26
|
+
setUiLocale(uiLocale: string): void;
|
|
27
|
+
private setLocalesConfiguration;
|
|
28
|
+
private setAvailableContentLocales;
|
|
29
|
+
reloadDebouncer: Debouncer;
|
|
30
|
+
stopReloadDebouncer(): void;
|
|
31
|
+
requestUiLocaleUpdate(uiLocale: string): void;
|
|
32
|
+
setMetadataConfiguration(metadataConfiguration?: FtMetadataConfiguration): void;
|
|
33
|
+
setNoCustom(noCustom: boolean): void;
|
|
34
|
+
setEditorMode(editorMode: boolean): void;
|
|
35
|
+
setNoCustomComponent(noCustomComponent: boolean | string): void;
|
|
36
|
+
setSession(session?: FtSession): void;
|
|
37
|
+
setOpenExternalDocumentInNewTab(openExternalDocumentInNewTab: boolean): void;
|
|
38
|
+
setNavigatorOnline(navigatorOnline: boolean): void;
|
|
39
|
+
setForcedOffline(forcedOffline: boolean): void;
|
|
40
|
+
setAuthenticationRequired(authenticationRequired: boolean): void;
|
|
41
|
+
}
|
|
42
|
+
export declare const ftAppStateManager: FtAppStateManager;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { CacheRegistry, Debouncer, FtStateManager, } from "@fluid-topics/ft-wc-utils";
|
|
2
|
+
import { AuthenticationChangeEvent, ftAppInfoStore, UiLocaleChangedEvent, } from "./FtAppInfoStore";
|
|
3
|
+
import { getOrDefaultIfMissingRequiredAuthentication } from "../services/FtRequiredAuthenticationHelper";
|
|
4
|
+
import { FluidTopicsApiProvider } from "../services";
|
|
5
|
+
import { UserLocaleService } from "../services/user/UserLocaleService";
|
|
6
|
+
export class FtAppStateManager extends FtStateManager {
|
|
7
|
+
static build(apiProvider) {
|
|
8
|
+
return new FtAppStateManager(ftAppInfoStore, apiProvider);
|
|
9
|
+
}
|
|
10
|
+
constructor(store, apiProvider) {
|
|
11
|
+
super();
|
|
12
|
+
this.store = store;
|
|
13
|
+
this.cache = new CacheRegistry();
|
|
14
|
+
this.withManualResources = true;
|
|
15
|
+
this.localesConfiguration = null;
|
|
16
|
+
this.userLocaleService = new UserLocaleService();
|
|
17
|
+
this.cleanSessionDebouncer = new Debouncer();
|
|
18
|
+
this.reloadDebouncer = new Debouncer(500);
|
|
19
|
+
this.apiProvider = apiProvider !== null && apiProvider !== void 0 ? apiProvider : (() => FluidTopicsApiProvider.get());
|
|
20
|
+
}
|
|
21
|
+
setWithManualResources(withManualResources) {
|
|
22
|
+
this.withManualResources = withManualResources;
|
|
23
|
+
this.updateIfNeeded();
|
|
24
|
+
}
|
|
25
|
+
async initService() {
|
|
26
|
+
this.store.addEventListener(AuthenticationChangeEvent.eventName, this.reloadConfiguration);
|
|
27
|
+
}
|
|
28
|
+
async updateIfNeeded() {
|
|
29
|
+
if (this.apiProvider()) {
|
|
30
|
+
if (!this.withManualResources) {
|
|
31
|
+
if (this.store.getState().session == null) {
|
|
32
|
+
this.updateSession();
|
|
33
|
+
}
|
|
34
|
+
if (this.store.getState().metadataConfiguration == null) {
|
|
35
|
+
this.updateMetadataConfiguration();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (this.localesConfiguration == null) {
|
|
39
|
+
this.updateLocalesConfiguration();
|
|
40
|
+
}
|
|
41
|
+
if (this.store.getState().availableContentLocales == null || this.store.getState().availableContentLocales.length == 0) {
|
|
42
|
+
this.updateAvailableContentLocales();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async updateSession() {
|
|
47
|
+
const session = await this.cache.get("session", async () => {
|
|
48
|
+
const currentSession = await this.apiProvider().getCurrentSession();
|
|
49
|
+
if (currentSession.idleTimeoutInMillis > 0) {
|
|
50
|
+
this.cleanSessionDebouncer.run(() => {
|
|
51
|
+
this.cache.clear("session");
|
|
52
|
+
this.setSession(undefined);
|
|
53
|
+
}, currentSession.idleTimeoutInMillis);
|
|
54
|
+
}
|
|
55
|
+
return currentSession;
|
|
56
|
+
});
|
|
57
|
+
this.setSession(session);
|
|
58
|
+
}
|
|
59
|
+
async updateMetadataConfiguration() {
|
|
60
|
+
this.setMetadataConfiguration(await this.cache.get("metadataConfiguration", () => this.apiProvider().getMetadataConfiguration()));
|
|
61
|
+
}
|
|
62
|
+
async updateLocalesConfiguration() {
|
|
63
|
+
this.setLocalesConfiguration(await this.cache.get("localesConfiguration", () => this.apiProvider().getLocalesConfiguration()));
|
|
64
|
+
}
|
|
65
|
+
async updateAvailableContentLocales() {
|
|
66
|
+
var _a;
|
|
67
|
+
const availableContentLocales = await this.cache.get("availableContentLocales", () => getOrDefaultIfMissingRequiredAuthentication(() => this.apiProvider().getAvailableSearchLocales(), { contentLocales: [] }));
|
|
68
|
+
this.setAvailableContentLocales((_a = availableContentLocales.contentLocales) !== null && _a !== void 0 ? _a : []);
|
|
69
|
+
}
|
|
70
|
+
reloadConfiguration() {
|
|
71
|
+
var _a;
|
|
72
|
+
(_a = this.cache) === null || _a === void 0 ? void 0 : _a.clear("availableContentLocales");
|
|
73
|
+
if (typeof this.updateAvailableContentLocales === "function") {
|
|
74
|
+
this.updateAvailableContentLocales();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
setBaseUrl(baseUrl) {
|
|
78
|
+
this.store.actions.baseUrl(baseUrl);
|
|
79
|
+
window.fluidTopicsBaseUrl = baseUrl;
|
|
80
|
+
}
|
|
81
|
+
setApiIntegrationIdentifier(apiIntegrationIdentifier) {
|
|
82
|
+
this.store.actions.apiIntegrationIdentifier(apiIntegrationIdentifier);
|
|
83
|
+
}
|
|
84
|
+
setApiIntegrationAppVersion(apiIntegrationAppVersion) {
|
|
85
|
+
this.store.actions.apiIntegrationAppVersion(apiIntegrationAppVersion);
|
|
86
|
+
}
|
|
87
|
+
setUiLocale(uiLocale) {
|
|
88
|
+
this.store.actions.uiLocale(uiLocale);
|
|
89
|
+
}
|
|
90
|
+
setLocalesConfiguration(localesConfiguration) {
|
|
91
|
+
var _a, _b, _c, _d, _e;
|
|
92
|
+
this.localesConfiguration = localesConfiguration;
|
|
93
|
+
this.store.actions.defaultLocales(this.localesConfiguration.defaultLocales);
|
|
94
|
+
this.store.actions.availableUiLocales((_a = this.localesConfiguration.availableUiLocales) !== null && _a !== void 0 ? _a : []);
|
|
95
|
+
this.store.actions.searchInAllLanguagesAllowed((_b = this.localesConfiguration.allLanguagesAllowed) !== null && _b !== void 0 ? _b : false);
|
|
96
|
+
this.store.actions.searchLanguageSetsUiLanguage((_c = this.localesConfiguration.searchLanguageSetsUiLanguage) !== null && _c !== void 0 ? _c : false);
|
|
97
|
+
this.store.actions.uiLanguageSetsSearchLanguage((_d = this.localesConfiguration.uiLanguageSetsSearchLanguage) !== null && _d !== void 0 ? _d : false);
|
|
98
|
+
this.store.actions.uiLanguageSetsReaderLanguage((_e = this.localesConfiguration.uiLanguageSetsReaderLanguage) !== null && _e !== void 0 ? _e : false);
|
|
99
|
+
setTimeout(() => this.updateIfNeeded());
|
|
100
|
+
}
|
|
101
|
+
setAvailableContentLocales(availableContentLocales) {
|
|
102
|
+
this.store.actions.availableContentLocales(availableContentLocales);
|
|
103
|
+
setTimeout(() => this.updateIfNeeded());
|
|
104
|
+
}
|
|
105
|
+
stopReloadDebouncer() {
|
|
106
|
+
this.reloadDebouncer.cancel();
|
|
107
|
+
}
|
|
108
|
+
requestUiLocaleUpdate(uiLocale) {
|
|
109
|
+
this.userLocaleService.updateUiLocale({ uiLocale })
|
|
110
|
+
.then((response) => {
|
|
111
|
+
if (!response.uiLocaleChanged) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// We trigger a debounced reload, each component who interact with URL before reload (search/reader) stop the debouncer and take care of the reload
|
|
115
|
+
// Known limitation : If multiple component need to mutate the URL before reload,the faster one will achieved it reload before the other.
|
|
116
|
+
this.reloadDebouncer.run(() => window.location.reload());
|
|
117
|
+
this.store.dispatchEvent(new UiLocaleChangedEvent(response));
|
|
118
|
+
})
|
|
119
|
+
.catch(() => {
|
|
120
|
+
// No locale update or error
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
setMetadataConfiguration(metadataConfiguration) {
|
|
124
|
+
this.store.actions.metadataConfiguration(metadataConfiguration);
|
|
125
|
+
setTimeout(() => this.updateIfNeeded());
|
|
126
|
+
}
|
|
127
|
+
setNoCustom(noCustom) {
|
|
128
|
+
this.store.actions.noCustom(noCustom);
|
|
129
|
+
}
|
|
130
|
+
setEditorMode(editorMode) {
|
|
131
|
+
this.store.actions.editorMode(editorMode);
|
|
132
|
+
}
|
|
133
|
+
setNoCustomComponent(noCustomComponent) {
|
|
134
|
+
this.store.actions.noCustomComponent(noCustomComponent);
|
|
135
|
+
}
|
|
136
|
+
setSession(session) {
|
|
137
|
+
this.store.actions.session(session);
|
|
138
|
+
setTimeout(() => this.updateIfNeeded());
|
|
139
|
+
}
|
|
140
|
+
setOpenExternalDocumentInNewTab(openExternalDocumentInNewTab) {
|
|
141
|
+
this.store.actions.openExternalDocumentInNewTab(openExternalDocumentInNewTab);
|
|
142
|
+
}
|
|
143
|
+
setNavigatorOnline(navigatorOnline) {
|
|
144
|
+
this.store.actions.navigatorOnline(navigatorOnline);
|
|
145
|
+
}
|
|
146
|
+
setForcedOffline(forcedOffline) {
|
|
147
|
+
this.store.actions.forcedOffline(forcedOffline);
|
|
148
|
+
}
|
|
149
|
+
setAuthenticationRequired(authenticationRequired) {
|
|
150
|
+
this.store.actions.authenticationRequired(authenticationRequired);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export const ftAppStateManager = FtAppStateManager.build();
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
class HistoryChangeEvent extends CustomEvent {
|
|
1
|
+
export class HistoryChangeEvent extends CustomEvent {
|
|
2
2
|
constructor(currentItem) {
|
|
3
3
|
super(HistoryChangeEvent.eventName, { detail: { currentItem } });
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
6
|
HistoryChangeEvent.eventName = "change";
|
|
7
|
-
export { HistoryChangeEvent };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FtService } from "../FtService";
|
|
2
|
+
import { FtUserLocaleSummary, FtUserUiLocaleUpdateRequest } from "@fluid-topics/public-api";
|
|
3
|
+
export declare class UserLocaleService extends FtService {
|
|
4
|
+
updateUiLocale(uiLocale: FtUserUiLocaleUpdateRequest): Promise<FtUserLocaleSummary>;
|
|
5
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-topics/ft-app-context",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"description": "Global application context for Fluid Topics integrations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lit"
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"url": "ssh://git@scm.mrs.antidot.net:2222/fluidtopics/ft-web-components.git"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@fluid-topics/ft-wc-utils": "2.0.
|
|
22
|
+
"@fluid-topics/ft-wc-utils": "2.0.16",
|
|
23
23
|
"lit": "3.1.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@fluid-topics/public-api": "1.0.
|
|
26
|
+
"@fluid-topics/public-api": "1.0.120"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "a972b95acf70b2bfab648ae99cec9d9cbe77c86f"
|
|
29
29
|
}
|