zova-module-a-style 5.0.15 → 5.0.17

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,10 +1,13 @@
1
1
  {
2
2
  "name": "zova-module-a-style",
3
- "version": "5.0.15",
3
+ "version": "5.0.17",
4
4
  "title": "a-style",
5
5
  "zovaModule": {
6
6
  "capabilities": {
7
7
  "monkey": true
8
+ },
9
+ "dependencies": {
10
+ "a-model": "5.0.0"
8
11
  }
9
12
  },
10
13
  "type": "module",
@@ -34,5 +37,5 @@
34
37
  "tsc:publish": "npm run clean && tsc -b",
35
38
  "prepublishOnly": "npm run tsc:publish"
36
39
  },
37
- "gitHead": "4694913185e21d7ff9f241cb7fc949dde41cf6fd"
40
+ "gitHead": "6b24f8fbc3857e405882791f096d19d146675077"
38
41
  }
@@ -1,16 +1,17 @@
1
- import { Bean, BeanBase, Cast, IBeanRecord } from 'zova';
1
+ import { Bean, Cast, IBeanRecord } from 'zova';
2
2
  import { ScopeModule } from '../resource/this.js';
3
3
  import { ThemeBase, ThemeHandler } from '../types.js';
4
+ import { BeanModelBase } from 'zova-module-a-model';
4
5
 
5
6
  export type ThemeDarkMode = 'auto' | boolean;
6
7
 
7
8
  @Bean({ containerScope: 'app' })
8
- export class BeanTheme extends BeanBase<ScopeModule> {
9
- private _name: string;
10
- public get name(): string {
9
+ export class BeanTheme extends BeanModelBase<ScopeModule> {
10
+ private _name: keyof IBeanRecord;
11
+ public get name(): keyof IBeanRecord {
11
12
  return this._name;
12
13
  }
13
- public set name(value: string) {
14
+ public set name(value: keyof IBeanRecord) {
14
15
  this.setTheme(value as any);
15
16
  }
16
17
  private _dark: boolean;
@@ -29,8 +30,25 @@ export class BeanTheme extends BeanBase<ScopeModule> {
29
30
  private _onMediaDarkChange?;
30
31
 
31
32
  protected async __init__() {
32
- await this._setDark('auto');
33
- await this._setTheme();
33
+ this._name = this.$useQueryCookie({
34
+ queryKey: ['themename'],
35
+ });
36
+ this._dark = this.$useQueryCookie({
37
+ queryKey: ['themedark'],
38
+ });
39
+ this._darkMode = this.$useQueryCookie({
40
+ queryKey: ['themedarkmode'],
41
+ meta: {
42
+ persister: {
43
+ deserialize: value => {
44
+ value = value === 'true' ? true : value === 'false' ? false : !value ? undefined : value;
45
+ return this.$deserializeCookie(value);
46
+ },
47
+ },
48
+ },
49
+ });
50
+ await this._setDark(this._darkMode);
51
+ await this._setTheme(this._name);
34
52
  await this.applyTheme();
35
53
  }
36
54
 
@@ -42,8 +60,9 @@ export class BeanTheme extends BeanBase<ScopeModule> {
42
60
  const theme = (await this.bean._getBean(this.name as any, true)) as ThemeBase;
43
61
  const res = await theme.apply({ name: this.name, dark: this.dark });
44
62
  this.token = Cast(res).token;
45
- if (res.handler) {
46
- const themeHandler = (await this.bean._getBean(res.handler, true)) as unknown as ThemeHandler;
63
+ const handler = res.handler ?? this.scope.config.defaultThemeHandler;
64
+ if (handler) {
65
+ const themeHandler = (await this.bean._getBean(handler, true)) as unknown as ThemeHandler;
47
66
  await themeHandler.apply({ name: this.name, dark: this.dark, token: this.token } as any);
48
67
  }
49
68
  }
@@ -62,7 +81,8 @@ export class BeanTheme extends BeanBase<ScopeModule> {
62
81
  await this.applyTheme();
63
82
  }
64
83
 
65
- async _setDark(mode: ThemeDarkMode) {
84
+ async _setDark(mode?: ThemeDarkMode) {
85
+ if (mode === undefined) mode = 'auto';
66
86
  this._darkMode = mode;
67
87
  if (mode === 'auto') {
68
88
  this._listenMediaDarkChange(true);
@@ -4,5 +4,6 @@ export const config = (_app: ZovaApplication) => {
4
4
  return {
5
5
  defaultStyle: 'home-style.style.default' as keyof IBeanRecord,
6
6
  defaultTheme: 'home-theme.theme.default' as keyof IBeanRecord,
7
+ defaultThemeHandler: '' as keyof IBeanRecord,
7
8
  };
8
9
  };
package/src/monkey.ts CHANGED
@@ -7,14 +7,14 @@ export class Monkey extends BeanSimple implements IMonkeySystem {
7
7
  private _beanTheme: BeanTheme;
8
8
  private _beanStyleDefault: any;
9
9
 
10
- async appInitialize(bean: BeanContainer) {
10
+ async appInitialize(_bean: BeanContainer) {}
11
+ async appInitialized(bean: BeanContainer) {
11
12
  // theme
12
13
  this._beanTheme = await bean._getBean(BeanTheme, true);
13
14
  // style default
14
15
  const scope: ScopeModule = await bean.getScope(__ThisModule__);
15
16
  this._beanStyleDefault = await bean._getBean(scope.config.defaultStyle, true);
16
17
  }
17
- async appInitialized(_bean: BeanContainer) {}
18
18
  async beanInit(bean: BeanContainer, beanInstance: BeanBase) {
19
19
  const self = this;
20
20
  bean.defineProperty(beanInstance, '$style', {