@sprucelabs/spruce-heartwood-utils 29.3.3 → 29.5.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.
@@ -1,6 +1,6 @@
1
1
  import { ControllerOptions, ViewController, ViewControllerFactory, ViewControllerId, ViewControllerMap } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { MercuryClient } from '@sprucelabs/mercury-client';
3
- import { SkillTheme } from '../theming/ThemeManager';
3
+ import { SkillTheme } from '../types/heartwood.types';
4
4
  export default class RemoteViewControllerFactoryImpl implements RemoteViewControllerFactory {
5
5
  static Class?: new (options: RemoteFactoryOptions) => RemoteViewControllerFactory;
6
6
  static Request: any;
@@ -22,7 +22,6 @@ export default class RemoteViewControllerFactoryImpl implements RemoteViewContro
22
22
  protected optionallyLoadController(name: string): Promise<void>;
23
23
  private fetchFromUrl;
24
24
  }
25
- type Theme = SkillTheme;
26
25
  type ConnectToApi = () => Promise<MercuryClient>;
27
26
  export type VcFactoryForRemoteFactory = Pick<ViewControllerFactory, 'setController' | 'hasController' | 'getController' | 'Controller' | 'importControllers' | 'setAppController'>;
28
27
  export interface RemoteFactoryOptions {
@@ -32,7 +31,7 @@ export interface RemoteFactoryOptions {
32
31
  type Factory = Pick<ViewControllerFactory, 'hasController' | 'Controller'>;
33
32
  export interface RemoteViewControllerFactory extends Factory {
34
33
  RemoteController: (name: string, options: Record<string, any>) => Promise<ViewController<Record<string, any>>>;
35
- getTheme: (namespace?: string) => Theme | undefined;
34
+ getTheme: (namespace?: string) => SkillTheme | undefined;
36
35
  fetchRemoteController: (name: string) => Promise<(new () => ViewController<any>) & {
37
36
  id: string;
38
37
  }>;
@@ -1,9 +1,10 @@
1
1
  import { ThemeManager } from '@sprucelabs/heartwood-view-controllers';
2
- import { SpruceSchemas } from '@sprucelabs/spruce-core-schemas';
2
+ import { SkillTheme, ThemeChangeHandler } from '../types/heartwood.types';
3
3
  export declare class ThemeManagerImpl implements ThemeManager {
4
4
  private static instance?;
5
5
  private currentTheme;
6
6
  private themeCount;
7
+ private themeChangeHandler?;
7
8
  private constructor();
8
9
  static getInstance(): ThemeManagerImpl;
9
10
  static reset(): void;
@@ -16,12 +17,7 @@ export declare class ThemeManagerImpl implements ThemeManager {
16
17
  private deleteProp;
17
18
  private setProps;
18
19
  private setProp;
20
+ onChangeTheme(callback: ThemeChangeHandler): void;
19
21
  reset(): Promise<void>;
20
22
  }
21
- type Theme = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Theme;
22
- export type SkillTheme = Theme & {
23
- name: string;
24
- slug: string;
25
- };
26
23
  export declare const heartwoodTheme: SkillTheme;
27
- export {};
@@ -47,21 +47,22 @@ export class ThemeManagerImpl {
47
47
  }
48
48
  setTheme(theme_1) {
49
49
  return __awaiter(this, arguments, void 0, function* (theme, shouldAnimate = true) {
50
- var _a, _b, _c;
50
+ var _a, _b, _c, _d;
51
51
  if (((_a = this.currentTheme) === null || _a === void 0 ? void 0 : _a.name) === theme.name) {
52
52
  return;
53
53
  }
54
+ (_b = this.themeChangeHandler) === null || _b === void 0 ? void 0 : _b.call(this, theme);
54
55
  this.themeCount++;
55
56
  this.currentTheme = theme;
56
- const _d = theme.props, { calendarEvents, borderRadius } = _d, rest = __rest(_d, ["calendarEvents", "borderRadius"]);
57
+ const _e = theme.props, { calendarEvents, borderRadius } = _e, rest = __rest(_e, ["calendarEvents", "borderRadius"]);
57
58
  this.applyBorderRadius(borderRadius);
58
59
  //@ts-ignore
59
60
  yield this.setProps(Object.entries(rest), shouldAnimate);
60
61
  if (calendarEvents) {
61
62
  yield this.setProps(Object.entries(calendarEvents), shouldAnimate);
62
63
  }
63
- (_b = document
64
- .querySelector('meta[name="theme-color"]')) === null || _b === void 0 ? void 0 : _b.setAttribute('content', (_c = theme.props.color1Inverse) !== null && _c !== void 0 ? _c : 'white');
64
+ (_c = document
65
+ .querySelector('meta[name="theme-color"]')) === null || _c === void 0 ? void 0 : _c.setAttribute('content', (_d = theme.props.color1Inverse) !== null && _d !== void 0 ? _d : 'white');
65
66
  });
66
67
  }
67
68
  applyBorderRadius(borderRadius) {
@@ -92,6 +93,9 @@ export class ThemeManagerImpl {
92
93
  setProp(name, value) {
93
94
  document.documentElement.style.setProperty(`--${name}`, value);
94
95
  }
96
+ onChangeTheme(callback) {
97
+ this.themeChangeHandler = callback;
98
+ }
95
99
  reset() {
96
100
  return __awaiter(this, void 0, void 0, function* () {
97
101
  if (this.currentTheme.slug !== 'heartwood') {
@@ -1,6 +1,6 @@
1
1
  import { ControllerOptions, ViewController, ViewControllerFactory, ViewControllerId, ViewControllerMap } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { MercuryClient } from '@sprucelabs/mercury-client';
3
- import { SkillTheme } from '../theming/ThemeManager';
3
+ import { SkillTheme } from '../types/heartwood.types';
4
4
  export default class RemoteViewControllerFactoryImpl implements RemoteViewControllerFactory {
5
5
  static Class?: new (options: RemoteFactoryOptions) => RemoteViewControllerFactory;
6
6
  static Request: any;
@@ -22,7 +22,6 @@ export default class RemoteViewControllerFactoryImpl implements RemoteViewContro
22
22
  protected optionallyLoadController(name: string): Promise<void>;
23
23
  private fetchFromUrl;
24
24
  }
25
- type Theme = SkillTheme;
26
25
  type ConnectToApi = () => Promise<MercuryClient>;
27
26
  export type VcFactoryForRemoteFactory = Pick<ViewControllerFactory, 'setController' | 'hasController' | 'getController' | 'Controller' | 'importControllers' | 'setAppController'>;
28
27
  export interface RemoteFactoryOptions {
@@ -32,7 +31,7 @@ export interface RemoteFactoryOptions {
32
31
  type Factory = Pick<ViewControllerFactory, 'hasController' | 'Controller'>;
33
32
  export interface RemoteViewControllerFactory extends Factory {
34
33
  RemoteController: (name: string, options: Record<string, any>) => Promise<ViewController<Record<string, any>>>;
35
- getTheme: (namespace?: string) => Theme | undefined;
34
+ getTheme: (namespace?: string) => SkillTheme | undefined;
36
35
  fetchRemoteController: (name: string) => Promise<(new () => ViewController<any>) & {
37
36
  id: string;
38
37
  }>;
@@ -1,9 +1,10 @@
1
1
  import { ThemeManager } from '@sprucelabs/heartwood-view-controllers';
2
- import { SpruceSchemas } from '@sprucelabs/spruce-core-schemas';
2
+ import { SkillTheme, ThemeChangeHandler } from '../types/heartwood.types';
3
3
  export declare class ThemeManagerImpl implements ThemeManager {
4
4
  private static instance?;
5
5
  private currentTheme;
6
6
  private themeCount;
7
+ private themeChangeHandler?;
7
8
  private constructor();
8
9
  static getInstance(): ThemeManagerImpl;
9
10
  static reset(): void;
@@ -16,12 +17,7 @@ export declare class ThemeManagerImpl implements ThemeManager {
16
17
  private deleteProp;
17
18
  private setProps;
18
19
  private setProp;
20
+ onChangeTheme(callback: ThemeChangeHandler): void;
19
21
  reset(): Promise<void>;
20
22
  }
21
- type Theme = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Theme;
22
- export type SkillTheme = Theme & {
23
- name: string;
24
- slug: string;
25
- };
26
23
  export declare const heartwoodTheme: SkillTheme;
27
- export {};
@@ -40,21 +40,22 @@ class ThemeManagerImpl {
40
40
  this.themeCount = 0;
41
41
  }
42
42
  async setTheme(theme, shouldAnimate = true) {
43
- var _a, _b, _c;
43
+ var _a, _b, _c, _d;
44
44
  if (((_a = this.currentTheme) === null || _a === void 0 ? void 0 : _a.name) === theme.name) {
45
45
  return;
46
46
  }
47
+ (_b = this.themeChangeHandler) === null || _b === void 0 ? void 0 : _b.call(this, theme);
47
48
  this.themeCount++;
48
49
  this.currentTheme = theme;
49
- const _d = theme.props, { calendarEvents, borderRadius } = _d, rest = __rest(_d, ["calendarEvents", "borderRadius"]);
50
+ const _e = theme.props, { calendarEvents, borderRadius } = _e, rest = __rest(_e, ["calendarEvents", "borderRadius"]);
50
51
  this.applyBorderRadius(borderRadius);
51
52
  //@ts-ignore
52
53
  await this.setProps(Object.entries(rest), shouldAnimate);
53
54
  if (calendarEvents) {
54
55
  await this.setProps(Object.entries(calendarEvents), shouldAnimate);
55
56
  }
56
- (_b = document
57
- .querySelector('meta[name="theme-color"]')) === null || _b === void 0 ? void 0 : _b.setAttribute('content', (_c = theme.props.color1Inverse) !== null && _c !== void 0 ? _c : 'white');
57
+ (_c = document
58
+ .querySelector('meta[name="theme-color"]')) === null || _c === void 0 ? void 0 : _c.setAttribute('content', (_d = theme.props.color1Inverse) !== null && _d !== void 0 ? _d : 'white');
58
59
  }
59
60
  applyBorderRadius(borderRadius) {
60
61
  if (!borderRadius || borderRadius === 'rounded') {
@@ -82,6 +83,9 @@ class ThemeManagerImpl {
82
83
  setProp(name, value) {
83
84
  document.documentElement.style.setProperty(`--${name}`, value);
84
85
  }
86
+ onChangeTheme(callback) {
87
+ this.themeChangeHandler = callback;
88
+ }
85
89
  async reset() {
86
90
  if (this.currentTheme.slug !== 'heartwood') {
87
91
  await this.setTheme(exports.heartwoodTheme);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-heartwood-utils",
3
3
  "description": "Heartwood Utilities",
4
- "version": "29.3.3",
4
+ "version": "29.5.0",
5
5
  "skill": {
6
6
  "namespace": "heartwood"
7
7
  },