@progressive-development/pd-spa-helper 0.1.172 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/src/PdSpaHelper.d.ts +8 -6
  2. package/dist/src/PdSpaHelper.js +30 -1
  3. package/dist/src/PdSpaHelper.js.map +1 -1
  4. package/dist/src/index.d.ts +3 -0
  5. package/dist/src/index.js +3 -0
  6. package/dist/src/index.js.map +1 -1
  7. package/dist/src/model/spa-model.d.ts +7 -0
  8. package/dist/src/model/spa-model.js +2 -0
  9. package/dist/src/model/spa-model.js.map +1 -0
  10. package/dist/src/store/indexDB.d.ts +1 -1
  11. package/dist/src/store/indexDB.js +4 -2
  12. package/dist/src/store/indexDB.js.map +1 -1
  13. package/dist/src/store/mini-rx.store.js +11 -2
  14. package/dist/src/store/mini-rx.store.js.map +1 -1
  15. package/dist/src/store/spa-app-actions.d.ts +32 -0
  16. package/dist/src/store/spa-app-actions.js +7 -0
  17. package/dist/src/store/spa-app-actions.js.map +1 -0
  18. package/dist/src/store/spa-app-effects.d.ts +6 -0
  19. package/dist/src/store/spa-app-effects.js +23 -0
  20. package/dist/src/store/spa-app-effects.js.map +1 -0
  21. package/dist/src/store/spa-app-reducer.d.ts +9 -0
  22. package/dist/src/store/spa-app-reducer.js +28 -0
  23. package/dist/src/store/spa-app-reducer.js.map +1 -0
  24. package/dist/src/store/spa-app-selector.d.ts +6 -0
  25. package/dist/src/store/spa-app-selector.js +9 -0
  26. package/dist/src/store/spa-app-selector.js.map +1 -0
  27. package/dist/src/tmpown/pd-loading-state.d.ts +2 -6
  28. package/dist/src/tmpown/pd-loading-state.js.map +1 -1
  29. package/dist/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +1 -1
  31. package/src/PdSpaHelper.ts +43 -9
  32. package/src/index.ts +5 -1
  33. package/src/model/spa-model.ts +8 -0
  34. package/src/store/indexDB.ts +5 -4
  35. package/src/store/mini-rx.store.ts +13 -2
  36. package/src/store/spa-app-actions.ts +11 -0
  37. package/src/store/spa-app-effects.ts +33 -0
  38. package/src/store/spa-app-reducer.ts +64 -0
  39. package/src/store/spa-app-selector.ts +23 -0
  40. package/src/tmpown/pd-loading-state.ts +3 -6
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent pd-spa-helper following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "pd-spa-helper",
6
- "version": "0.1.172",
6
+ "version": "0.2.0",
7
7
  "main": "dist/src/index.js",
8
8
  "module": "dist/src/index.js",
9
9
  "exports": {
@@ -2,17 +2,24 @@ import { html, LitElement, css, CSSResultGroup, TemplateResult, unsafeCSS } from
2
2
  import { router, navigator } from 'lit-element-router';
3
3
  import { property } from 'lit/decorators.js';
4
4
 
5
+ import { Subscription } from 'rxjs';
6
+
5
7
  import { FirebaseApp } from 'firebase/app';
6
8
 
7
9
  import '@progressive-development/pd-page/pd-menu.js';
8
10
  import '@progressive-development/pd-page/pd-footer.js';
9
11
 
10
12
  import { ServiceCallController } from './service-call-controller2.js';
11
- import { initializeStore } from './store/mini-rx.store.js';
13
+ import { initializeStore, pdStore } from './store/mini-rx.store.js';
12
14
 
13
15
  import { authStateChangedImpl, initAppImpl, isAuthenticatedImpl, setServiceProvider } from './service-provider/service-provider-impl.js';
14
16
  import { AppConfiguration, Footer, FunctionResult, MenuElement, NavigationConfig, NavigationPage } from './service-provider/service-provider-model.js';
15
17
 
18
+ import { getLoadingSelector } from './store/spa-app-selector.js';
19
+ import { setRouteElement } from './store/spa-app-effects.js';
20
+ import { APP_CONF_EVENT, LoadingState } from './model/spa-model.js';
21
+ import { loginSucess } from './store/spa-app-actions.js';
22
+
16
23
  import './router/AppMain.js';
17
24
  import './defaultpage/default-login.js';
18
25
  import './tmpown/pd-panel-viewer.js';
@@ -134,6 +141,8 @@ export abstract class PdSpaHelper extends router(navigator(LitElement)) {
134
141
 
135
142
  protected functionsController = new ServiceCallController(this);
136
143
 
144
+ protected abstract _appConfiguration: any;
145
+
137
146
  // not used at the moment
138
147
  @property({ type: String })
139
148
  title = 'Hey there';
@@ -148,12 +157,7 @@ export abstract class PdSpaHelper extends router(navigator(LitElement)) {
148
157
  _profile: any | undefined;
149
158
 
150
159
  @property({ type: Object, state: true })
151
- _loadingState?: {
152
- isLoading: boolean,
153
- smallBackground?: boolean,
154
- modal?: boolean,
155
- loadingTxt?: string
156
- };
160
+ _loadingState?: LoadingState;
157
161
 
158
162
  /**
159
163
  * Properties needed for the router.
@@ -180,7 +184,9 @@ export abstract class PdSpaHelper extends router(navigator(LitElement)) {
180
184
  abstract _availableLocales: string[];
181
185
 
182
186
  protected _singleLocaleMenu: boolean = false;
183
-
187
+
188
+ // subscription for loading-state selector
189
+ _subscription?: Subscription;
184
190
 
185
191
  static styles =
186
192
  // Ref: Additional use classmap to add custom classes in concrete impl
@@ -264,6 +270,8 @@ export abstract class PdSpaHelper extends router(navigator(LitElement)) {
264
270
 
265
271
  super();
266
272
 
273
+ setRouteElement(this);
274
+
267
275
  const doSomething = (scrollPos:number) => {
268
276
  if (scrollPos <= 50) {
269
277
  this._teaserClosed = false;
@@ -295,7 +303,32 @@ export abstract class PdSpaHelper extends router(navigator(LitElement)) {
295
303
 
296
304
  // For common toast messages (not for callfunction toasts => handelt by own controller)
297
305
  this.addEventListener("toast-event", this._createTemporaryToast);
298
- this.addEventListener("route-event", this._handleMenuRouteEvent);
306
+ this.addEventListener("route-event", this._handleMenuRouteEvent);
307
+ }
308
+
309
+ connectedCallback(): void {
310
+ super.connectedCallback();
311
+ this.addEventListener(APP_CONF_EVENT, this._setConfInDetail);
312
+ this._subscription = pdStore().select(getLoadingSelector)
313
+ .subscribe((loadingState) => {
314
+ console.log("Loading State: ", loadingState);
315
+ this._loadingState = loadingState;
316
+ });
317
+ }
318
+
319
+ disconnectedCallback(): void {
320
+ this.removeEventListener(APP_CONF_EVENT, this._setConfInDetail);
321
+ this._subscription?.unsubscribe();
322
+ super.disconnectedCallback();
323
+ }
324
+
325
+ _setConfInDetail(event: Event) {
326
+ const {detail} = event as CustomEvent;
327
+ if (detail) {
328
+ detail.appConf = {
329
+ ...this._appConfiguration
330
+ };
331
+ }
299
332
  }
300
333
 
301
334
  /**
@@ -332,6 +365,7 @@ export abstract class PdSpaHelper extends router(navigator(LitElement)) {
332
365
  console.log("My callback user:", user);
333
366
  this._user = user;
334
367
  if (this._user) {
368
+ pdStore().dispatch(loginSucess());
335
369
  this._loginSuccess(new CustomEvent("login-success"));
336
370
  }
337
371
  };
package/src/index.ts CHANGED
@@ -3,7 +3,8 @@ export {
3
3
  startInit,
4
4
  } from './PdSpaHelper.js';
5
5
 
6
- export * as pdSpaModel from './service-provider/service-provider-model.js'
6
+ export * as pdSpaModel from './service-provider/service-provider-model.js';
7
+ export * as pdSpaModel2 from './model/spa-model.js';
7
8
 
8
9
  export {isBlank, isEmpty} from './helper/helper-utils.js';
9
10
 
@@ -37,6 +38,9 @@ export {
37
38
  } from './service-provider/service-provider-impl.js'
38
39
 
39
40
  export { pdStore } from './store/mini-rx.store.js';
41
+ export * as pdAction from './store/spa-app-actions.js';
42
+ export * as pdSelector from './store/spa-app-selector.js';
43
+
40
44
  export * as pdDB from './store/indexDB.js'
41
45
 
42
46
  export { templates as beTemplaes} from './generated/locale-wrapper/be-wrapper.js'
@@ -0,0 +1,8 @@
1
+ export const APP_CONF_EVENT = "get-app-conf";
2
+
3
+ export interface LoadingState {
4
+ isLoading: boolean,
5
+ modal?: boolean,
6
+ smallBackground?: boolean,
7
+ loadingTxt?: string
8
+ }
@@ -1,5 +1,8 @@
1
1
  // use version import to initialize modul
2
2
 
3
+ import { pdStore } from "./mini-rx.store";
4
+ import { initIndexDBSucess } from "./spa-app-actions.js";
5
+
3
6
  const {indexedDB} = window;
4
7
  let db:any;
5
8
 
@@ -188,9 +191,7 @@ export const initDB = (
188
191
  keyPath?: string
189
192
  }
190
193
  }[]
191
- },
192
- successCallback: Function
193
- ) => {
194
+ }) => {
194
195
  if (!indexedDB) {
195
196
  window.alert("Your browser doesn't support a stable version of IndexedDB.");
196
197
  } else {
@@ -203,7 +204,7 @@ export const initDB = (
203
204
  request.onsuccess = () => {
204
205
  db = request.result;
205
206
  console.log(`db init success: ${db}`);
206
- successCallback();
207
+ pdStore().dispatch(initIndexDBSucess());
207
208
  };
208
209
 
209
210
  request.onupgradeneeded = (event: any) => {
@@ -2,6 +2,9 @@ import { configureStore, Store, LoggerExtension, ReduxDevtoolsExtension, Immutab
2
2
 
3
3
  import { StoreConfig } from '../service-provider/service-provider-model.js';
4
4
 
5
+ import { spaAppReducer } from '../store/spa-app-reducer.js';
6
+ import { appRouteEffect } from '../store/spa-app-effects.js';
7
+
5
8
 
6
9
  let store: Store;
7
10
 
@@ -12,7 +15,12 @@ export const initializeStore = (param: StoreConfig) => {
12
15
  // create store
13
16
  if (!store) {
14
17
  store = configureStore({
15
- reducers: param.reducer,
18
+ reducers: param.reducer ? {
19
+ spaApp: spaAppReducer,
20
+ ...param.reducer
21
+ } : {
22
+ spaApp: spaAppReducer
23
+ },
16
24
  extensions: [
17
25
  new LoggerExtension(),
18
26
  new ReduxDevtoolsExtension({
@@ -22,7 +30,10 @@ export const initializeStore = (param: StoreConfig) => {
22
30
  ],
23
31
  });
24
32
 
25
- // register effects
33
+ // register default effects
34
+ store.effect(appRouteEffect);
35
+
36
+ // register configured effects
26
37
  param.effects.forEach(effect => store.effect(effect));
27
38
  }
28
39
  }
@@ -0,0 +1,11 @@
1
+ import { action, payload } from 'ts-action';
2
+ import { LoadingState } from '../model/spa-model.js';
3
+
4
+ export const initIndexDBSucess = action('SPA_INIT_INDEX_DB_SUCCESS');
5
+ export const loginSucess = action('SPA_LOGIN_SUCCESS');
6
+
7
+ export const routeAction = action('SPA_APP_ROUTE', payload<string>());
8
+
9
+ export const updateInternetOffline = action('SPA_APP_UPDATE_INTERNET_OFFLINE', payload<boolean>());
10
+
11
+ export const loadingStateChange = action('SPA_APP_LOADING_STATE_CHANGE', payload<LoadingState>());
@@ -0,0 +1,33 @@
1
+ import { actions$, createEffect } from 'mini-rx-store';
2
+
3
+ import { tap } from 'rxjs/operators';
4
+
5
+ import { ofType } from 'ts-action-operators';
6
+
7
+ import { routeAction } from './spa-app-actions.js';
8
+
9
+
10
+ let routeElement: HTMLElement;
11
+
12
+ export const setRouteElement = (param: HTMLElement) => {
13
+ routeElement = param;
14
+ }
15
+
16
+ export const appRouteEffect = createEffect(
17
+ actions$.pipe(
18
+ ofType(routeAction),
19
+ tap((action) => {
20
+ if (!routeElement) {
21
+ console.error("No route element set for appRouteEffect");
22
+ } else {
23
+ routeElement.dispatchEvent(new CustomEvent('route-event', {
24
+ detail: {route: action.payload},
25
+ bubbles: true,
26
+ composed: true
27
+ }));
28
+ }
29
+ })
30
+ ), {
31
+ dispatch: false
32
+ }
33
+ );
@@ -0,0 +1,64 @@
1
+ import { on, reducer } from 'ts-action';
2
+
3
+ import { initIndexDBSucess, loadingStateChange, loginSucess, routeAction, updateInternetOffline } from './spa-app-actions.js';
4
+ import { LoadingState } from '../model/spa-model.js';
5
+
6
+ export interface SpaAppState {
7
+ offline?: boolean,
8
+ loadingState?: LoadingState;
9
+ lastRoutes?: any[];
10
+ initIndexDB?: boolean;
11
+ userLogin?: boolean;
12
+ }
13
+
14
+ const initialState: SpaAppState = {
15
+
16
+ };
17
+
18
+ export const spaAppReducer = reducer(
19
+ initialState,
20
+
21
+ on (updateInternetOffline, (state, {payload}) => (
22
+ {
23
+ ...state,
24
+ offline: payload
25
+ }
26
+ )),
27
+
28
+ on(loadingStateChange, (state, {payload}) => (
29
+ {
30
+ ...state,
31
+ loadingState: payload ? {
32
+ isLoading: payload.isLoading,
33
+ smallBackground: payload.smallBackground,
34
+ modal: payload.modal,
35
+ txt: payload.loadingTxt,
36
+ } : undefined
37
+ }
38
+ )),
39
+
40
+ on(routeAction, (state, {payload}) => (
41
+ {
42
+ ...state,
43
+ lastRoutes: [
44
+ ...(state.lastRoutes || []),
45
+ payload
46
+ ]
47
+ }
48
+ )),
49
+
50
+ on(initIndexDBSucess, (state) => (
51
+ {
52
+ ...state,
53
+ initIndexDB: true,
54
+ }
55
+ )),
56
+
57
+ on(loginSucess, (state) => (
58
+ {
59
+ ...state,
60
+ userLogin: true,
61
+ }
62
+ )),
63
+
64
+ );
@@ -0,0 +1,23 @@
1
+ import { createFeatureStateSelector, createSelector } from "mini-rx-store";
2
+
3
+ import { SpaAppState } from "./spa-app-reducer.js";
4
+
5
+ const getSpaAppFeatureState = createFeatureStateSelector<SpaAppState>('spaApp');
6
+
7
+ export const getLoadingSelector = createSelector(
8
+ getSpaAppFeatureState,
9
+ state => state.loadingState
10
+ );
11
+
12
+ export const getOfflineSelector = createSelector(
13
+ getSpaAppFeatureState,
14
+ state => state.offline === true
15
+ );
16
+
17
+ export const getInitStatusSelector = createSelector(
18
+ getSpaAppFeatureState,
19
+ state => ({
20
+ login: state.userLogin,
21
+ indexedDB: state.initIndexDB
22
+ })
23
+ );
@@ -3,17 +3,14 @@ import { customElement, property } from 'lit/decorators.js';
3
3
  import { msg } from '@lit/localize';
4
4
  import { classMap } from 'lit/directives/class-map.js';
5
5
 
6
+ import {LoadingState} from '../model/spa-model.js';
7
+
6
8
 
7
9
  @customElement('pd-loading-state')
8
10
  export class PdLoadingState extends LitElement {
9
11
 
10
12
  @property({ type: Object})
11
- loadingState: {
12
- isLoading: boolean,
13
- modal?: boolean,
14
- smallBackground?: boolean,
15
- loadingTxt?: string
16
- } = {
13
+ loadingState: LoadingState = {
17
14
  isLoading: false
18
15
  };
19
16