zova-module-a-style 5.0.7 → 5.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zova-module-a-style",
3
- "version": "5.0.7",
3
+ "version": "5.0.9",
4
4
  "title": "a-style",
5
5
  "zovaModule": {
6
6
  "capabilities": {
@@ -34,5 +34,5 @@
34
34
  "tsc:publish": "npm run clean && tsc -b",
35
35
  "prepublishOnly": "npm run tsc:publish"
36
36
  },
37
- "gitHead": "f72c4e9f7fbc562a409406abbc57808610fa0b25"
37
+ "gitHead": "1c586ea11b3ca5eba665522e25adcb26b4eecd12"
38
38
  }
@@ -1,6 +1,6 @@
1
1
  import { BeanBase, Cast, IBeanRecord, Store } from 'zova';
2
2
  import { ScopeModule } from '../resource/this.js';
3
- import { ThemeBase } from '../types.js';
3
+ import { ThemeBase, ThemeHandler } from '../types.js';
4
4
 
5
5
  export type ThemeDarkMode = 'auto' | boolean;
6
6
 
@@ -11,11 +11,19 @@ export class StoreTheme extends BeanBase<ScopeModule> {
11
11
  return this._name;
12
12
  }
13
13
  public set name(value: string) {
14
- this._name = value;
15
- this.applyTheme();
14
+ this.setTheme(value as any);
15
+ }
16
+ private _dark: boolean;
17
+ public get dark(): boolean {
18
+ return this._dark;
19
+ }
20
+ private _darkMode: ThemeDarkMode; // auto/true/false
21
+ public get darkMode(): ThemeDarkMode {
22
+ return this._darkMode;
23
+ }
24
+ public set darkMode(value: ThemeDarkMode) {
25
+ this.setDark(value);
16
26
  }
17
- dark: boolean;
18
- darkMode: ThemeDarkMode; // auto/true/false
19
27
  token: unknown;
20
28
  private _mediaDark?: MediaQueryList;
21
29
  private _onMediaDarkChange?;
@@ -31,9 +39,13 @@ export class StoreTheme extends BeanBase<ScopeModule> {
31
39
  }
32
40
 
33
41
  async applyTheme() {
34
- const theme = (await this.bean._getBean(this.name, true)) as ThemeBase;
42
+ const theme = (await this.bean._getBean(this.name as any, true)) as ThemeBase;
35
43
  const res = await theme.apply({ name: this.name, dark: this.dark });
36
44
  this.token = Cast(res).token;
45
+ if (res.handler) {
46
+ const themeHandler = (await this.bean._getBean(res.handler, true)) as unknown as ThemeHandler;
47
+ await themeHandler.apply(res);
48
+ }
37
49
  }
38
50
 
39
51
  async setTheme(name?: keyof IBeanRecord) {
@@ -42,7 +54,7 @@ export class StoreTheme extends BeanBase<ScopeModule> {
42
54
  }
43
55
 
44
56
  async _setTheme(name?: keyof IBeanRecord) {
45
- this.name = name || this.scope.config.defaultTheme;
57
+ this._name = name || this.scope.config.defaultTheme;
46
58
  }
47
59
 
48
60
  async setDark(mode: ThemeDarkMode) {
@@ -51,13 +63,13 @@ export class StoreTheme extends BeanBase<ScopeModule> {
51
63
  }
52
64
 
53
65
  async _setDark(mode: ThemeDarkMode) {
54
- this.darkMode = mode;
66
+ this._darkMode = mode;
55
67
  if (mode === 'auto') {
56
68
  this._listenMediaDarkChange(true);
57
- this.dark = !!this._mediaDark?.matches;
69
+ this._dark = !!this._mediaDark?.matches;
58
70
  } else {
59
71
  this._listenMediaDarkChange(false);
60
- this.dark = mode;
72
+ this._dark = mode;
61
73
  }
62
74
  }
63
75
 
package/src/types.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { style } from 'typestyle';
2
2
  import 'zova';
3
3
  import { StoreTheme } from './bean/store.theme.js';
4
+ import { IBeanRecord } from 'zova';
4
5
  declare module 'zova' {
5
6
  export interface BeanBase {
6
7
  $style: typeof style;
@@ -13,8 +14,14 @@ export interface ThemeApplyParams {
13
14
  dark: boolean;
14
15
  }
15
16
 
16
- export interface ThemeApplyResult {}
17
+ export interface ThemeApplyResult {
18
+ handler?: keyof IBeanRecord;
19
+ }
17
20
 
18
21
  export interface ThemeBase {
19
22
  apply({ name, dark }: ThemeApplyParams): Promise<ThemeApplyResult>;
20
23
  }
24
+
25
+ export interface ThemeHandler {
26
+ apply(result: ThemeApplyResult): Promise<void>;
27
+ }