@sprucelabs/heartwood-view-controllers 119.2.1 → 119.3.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 (34) hide show
  1. package/README.md +1 -1
  2. package/build/esm/schemas/v2021_02_11/autocompleteInput.builder.d.ts +35 -35
  3. package/build/esm/tests/AbstractViewControllerTest.d.ts +2 -1
  4. package/build/esm/tests/AbstractViewControllerTest.js +3 -0
  5. package/build/esm/tests/MockActiveRecordCard.d.ts +1 -1
  6. package/build/esm/tests/utilities/assertSupport.d.ts +3 -2
  7. package/build/esm/tests/utilities/vcAssert.d.ts +11 -11
  8. package/build/esm/tests/utilities/vcAssert.js +2 -7
  9. package/build/esm/tests/utilities/vcAssert.utility.d.ts +9 -9
  10. package/build/esm/viewControllers/Abstract.ac.d.ts +3 -10
  11. package/build/esm/viewControllers/Abstract.ac.js +4 -17
  12. package/build/esm/viewControllers/Abstract.vc.d.ts +7 -28
  13. package/build/esm/viewControllers/Abstract.vc.js +10 -124
  14. package/build/esm/viewControllers/AbstractController.d.ts +25 -0
  15. package/build/esm/viewControllers/AbstractController.js +128 -0
  16. package/build/esm/viewControllers/activeRecord/ActiveRecordCard.vc.d.ts +1 -1
  17. package/build/esm/viewControllers/formBuilder/FieldOptionsMapper.d.ts +3 -3
  18. package/build/schemas/v2021_02_11/autocompleteInput.builder.d.ts +35 -35
  19. package/build/tests/AbstractViewControllerTest.d.ts +2 -1
  20. package/build/tests/AbstractViewControllerTest.js +3 -0
  21. package/build/tests/MockActiveRecordCard.d.ts +1 -1
  22. package/build/tests/utilities/assertSupport.d.ts +3 -2
  23. package/build/tests/utilities/vcAssert.d.ts +11 -11
  24. package/build/tests/utilities/vcAssert.js +2 -7
  25. package/build/tests/utilities/vcAssert.utility.d.ts +9 -9
  26. package/build/viewControllers/Abstract.ac.d.ts +3 -10
  27. package/build/viewControllers/Abstract.ac.js +7 -15
  28. package/build/viewControllers/Abstract.vc.d.ts +7 -28
  29. package/build/viewControllers/Abstract.vc.js +10 -117
  30. package/build/viewControllers/AbstractController.d.ts +25 -0
  31. package/build/viewControllers/AbstractController.js +118 -0
  32. package/build/viewControllers/activeRecord/ActiveRecordCard.vc.d.ts +1 -1
  33. package/build/viewControllers/formBuilder/FieldOptionsMapper.d.ts +3 -3
  34. package/package.json +1 -1
package/README.md CHANGED
@@ -18,4 +18,4 @@ Spruce XP Documentation
18
18
  <a href="https://developer.spruce.ai/#/"><img width="250" src="https://raw.githubusercontent.com/sprucelabsai/heartwood-view-controllers/master/docs/images/read-full-docs.png" /></a>
19
19
  </p>
20
20
  ### Dependencies
21
- [Arkit diagram here](docs/dependencies.md).
21
+ [Arkit diagram here](docs/dependencies.md).
@@ -50,9 +50,12 @@ declare const _default: {
50
50
  type: "text";
51
51
  label: string;
52
52
  };
53
- onChange: {
53
+ value: {
54
+ type: "text";
55
+ };
56
+ renderedValue: {
54
57
  type: "raw";
55
- label: string;
58
+ hint: string;
56
59
  options: {
57
60
  valueType: string;
58
61
  };
@@ -61,8 +64,36 @@ declare const _default: {
61
64
  type: "boolean";
62
65
  label: string;
63
66
  };
64
- value: {
65
- type: "text";
67
+ isInteractive: {
68
+ type: "boolean";
69
+ };
70
+ onChange: {
71
+ type: "raw";
72
+ label: string;
73
+ options: {
74
+ valueType: string;
75
+ };
76
+ };
77
+ onChangeRenderedValue: {
78
+ type: "raw";
79
+ label: string;
80
+ options: {
81
+ valueType: string;
82
+ };
83
+ };
84
+ onFocus: {
85
+ type: "raw";
86
+ label: string;
87
+ options: {
88
+ valueType: string;
89
+ };
90
+ };
91
+ onBlur: {
92
+ type: "raw";
93
+ label: string;
94
+ options: {
95
+ valueType: string;
96
+ };
66
97
  };
67
98
  rightButtons: {
68
99
  type: "schema";
@@ -862,37 +893,6 @@ declare const _default: {
862
893
  };
863
894
  };
864
895
  };
865
- renderedValue: {
866
- type: "raw";
867
- hint: string;
868
- options: {
869
- valueType: string;
870
- };
871
- };
872
- isInteractive: {
873
- type: "boolean";
874
- };
875
- onChangeRenderedValue: {
876
- type: "raw";
877
- label: string;
878
- options: {
879
- valueType: string;
880
- };
881
- };
882
- onFocus: {
883
- type: "raw";
884
- label: string;
885
- options: {
886
- valueType: string;
887
- };
888
- };
889
- onBlur: {
890
- type: "raw";
891
- label: string;
892
- options: {
893
- valueType: string;
894
- };
895
- };
896
896
  };
897
897
  };
898
898
  export default _default;
@@ -1,7 +1,7 @@
1
1
  import { MercuryClient } from '@sprucelabs/mercury-client';
2
2
  import AbstractSpruceTest from '@sprucelabs/test-utils';
3
3
  import EventFaker from '../__tests__/support/EventFaker';
4
- import { ControllerOptions, ViewController, ViewControllerMap } from '../types/heartwood.types';
4
+ import { AppControllerId, ControllerOptions, ViewController, ViewControllerMap } from '../types/heartwood.types';
5
5
  import { RenderOptions } from '../utilities/render.utility';
6
6
  import ViewControllerFactory, { ViewControllerFactoryOptions } from '../viewControllers/ViewControllerFactory';
7
7
  import MercuryFixture from './fixtures/MercuryFixture';
@@ -17,6 +17,7 @@ export default abstract class AbstractViewControllerTest extends AbstractSpruceT
17
17
  protected static Factory(options?: Partial<ViewControllerFactoryOptions>): ViewControllerFactory;
18
18
  protected static getFactory(): ViewControllerFactory;
19
19
  protected static Controller<N extends keyof ViewControllerMap>(name: N, options: ControllerOptions<N>): ViewControllerMap[N];
20
+ protected static App<N extends AppControllerId>(name: N, options?: Partial<ControllerOptions<N>>): import("../types/heartwood.types").AppControllerMap[N];
20
21
  protected static render<Vc extends ViewController<any>>(vc: Vc, options?: RenderOptions): ReturnType<Vc["render"]>;
21
22
  protected static click(button?: {
22
23
  onClick?: (() => void | Promise<void>) | null | undefined;
@@ -81,6 +81,9 @@ class AbstractViewControllerTest extends AbstractSpruceTest {
81
81
  this.render(vc);
82
82
  return vc;
83
83
  }
84
+ static App(name, options) {
85
+ return this.getFactory().App(name, options);
86
+ }
84
87
  static render(vc, options) {
85
88
  return renderUtil.render(vc, options);
86
89
  }
@@ -34,7 +34,7 @@ export default class MockActiveRecordCard extends ActiveRecordCardViewController
34
34
  assertDoesNotRenderFooter(): void;
35
35
  assertRendersFooter(): void;
36
36
  getSwipeVc(): import("..").SwipeCardViewController;
37
- getCardVc(): Pick<import("..").CardViewController, "setHeaderTitle" | "setHeaderSubtitle" | "enableFooter" | "disableFooter" | "setCriticalError" | "getHasCriticalError" | "clearCriticalError" | "setIsBusy" | "isBusy" | "setFooter" | "getHeaderTitle" | "getFooter" | "getHeaderSubtitle" | "render" | "triggerRender" | "setTriggerRenderHandler">;
37
+ getCardVc(): Pick<import("..").CardViewController, "isBusy" | "setHeaderTitle" | "setHeaderSubtitle" | "enableFooter" | "disableFooter" | "setCriticalError" | "getHasCriticalError" | "clearCriticalError" | "setIsBusy" | "setFooter" | "getHeaderTitle" | "getFooter" | "getHeaderSubtitle" | "render" | "triggerRender" | "setTriggerRenderHandler">;
38
38
  getListVcs(): import("..").ListViewController[];
39
39
  rebuildSlidesForPaging(): void;
40
40
  assertRebuildSlideCountEquals(expected: number): void;
@@ -26,9 +26,10 @@ export interface ButtonViewController {
26
26
  triggerRender(): void;
27
27
  setTriggerRenderHandler(handler: TriggerRenderHandler): void;
28
28
  }
29
- export declare function getVcName(vc: ViewController<any> | AbstractAppController | AppController): any;
30
- export declare function getControllerType(vc: ViewController<any> | AbstractAppController | AppController): "App" | "SkillView" | "ViewController";
29
+ export declare function getVcName(vc: Controller): any;
30
+ export declare function getControllerType(vc: Controller): "App" | "SkillView" | "ViewController";
31
31
  export declare function wait(...promises: (Promise<any> | undefined | any)[]): Promise<any>;
32
32
  export declare function assertToolInstanceOf(tool: SpruceSchemas.HeartwoodViewControllers.v2021_02_11.ToolBeltTool, Class: any): ViewController<any>;
33
33
  export declare function isVcInstanceOf<C>(vc: any, Class: new () => C): C | false;
34
34
  export declare function checkForCardSection(vc: ViewController<SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card>, sectionIdOrIdx: string | number): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CardSection;
35
+ export type Controller = ViewController<any> | AbstractAppController | AppController;
@@ -1,4 +1,4 @@
1
- import { LineIcon, SkillViewController, ViewController, CardViewController, ScopedBy, Card, StickyToolPosition, ScopeFlag, Button, List, RowStyle, AlertOptions, AppController } from '../../types/heartwood.types';
1
+ import { LineIcon, SkillViewController, ViewController, CardViewController, ScopedBy, Card, StickyToolPosition, ScopeFlag, Button, List, RowStyle, AlertOptions } from '../../types/heartwood.types';
2
2
  import ButtonBarViewController from '../../viewControllers/ButtonBar.vc';
3
3
  import CalendarViewController from '../../viewControllers/Calendar.vc';
4
4
  import DialogViewController from '../../viewControllers/Dialog.vc';
@@ -12,21 +12,21 @@ import SwipeCardViewController from '../../viewControllers/SwipeCard.vc';
12
12
  import TalkingSprucebotViewController from '../../viewControllers/TalkingSprucebot.vc';
13
13
  import ToolBeltViewController, { OpenToolBeltOptions } from '../../viewControllers/ToolBelt.vc';
14
14
  import ViewControllerFactory from '../../viewControllers/ViewControllerFactory';
15
- import { Vc, AssertConfirmViewController, ButtonViewController, AssertRedirectOptions, SelectViewController } from './assertSupport';
15
+ import { Vc, AssertConfirmViewController, ButtonViewController, AssertRedirectOptions, SelectViewController, Controller } from './assertSupport';
16
16
  declare const vcAssert: {
17
17
  _setVcFactory(factory: ViewControllerFactory): void;
18
18
  attachTriggerRenderCounter(vc: Vc): void;
19
19
  assertTriggerRenderCount(vc: Vc, expected: number): void;
20
- assertRendersConfirm(vc: ViewController<any>, action: () => any | Promise<any>): Promise<AssertConfirmViewController>;
21
- assertDoesNotRenderConfirm(vc: ViewController<any>, action: () => any | Promise<any>): Promise<void>;
22
- assertDoesNotRenderDialog(vc: ViewController<any>, action: () => any | Promise<any>): Promise<void>;
23
- assertRendersSuccessAlert(vc: ViewController<any>, action: () => any | Promise<any>): Promise<AlertViewController>;
24
- assertRendersAlert(vc: ViewController<any>, action: () => any | Promise<any>, style?: AlertOptions["style"]): Promise<AlertViewController>;
25
- assertDoesNotRenderAlert(vc: ViewController<any>, action: () => any | Promise<any>, style?: AlertOptions["style"]): Promise<void>;
26
- assertAsksForAVote(vc: ViewController<any> | AppController, action: () => Promise<any>): Promise<{
20
+ assertRendersConfirm(vc: Controller, action: () => any | Promise<any>): Promise<AssertConfirmViewController>;
21
+ assertDoesNotRenderConfirm(vc: Controller, action: () => any | Promise<any>): Promise<void>;
22
+ assertDoesNotRenderDialog(vc: Controller, action: () => any | Promise<any>): Promise<void>;
23
+ assertRendersSuccessAlert(vc: Controller, action: () => any | Promise<any>): Promise<AlertViewController>;
24
+ assertRendersAlert(vc: Controller, action: () => any | Promise<any>, style?: AlertOptions["style"]): Promise<AlertViewController>;
25
+ assertDoesNotRenderAlert(vc: Controller, action: () => any | Promise<any>, style?: AlertOptions["style"]): Promise<void>;
26
+ assertAsksForAVote(vc: Controller, action: () => Promise<any>): Promise<{
27
27
  castVote: () => Promise<void>;
28
28
  }>;
29
- assertRendersDialog(vc: ViewController<any>, action: () => any | Promise<any>, dialogHandler?: (dialogVc: DialogViewController) => any | Promise<any>): Promise<DialogViewController>;
29
+ assertRendersDialog(vc: Controller, action: () => any | Promise<any>, dialogHandler?: (dialogVc: DialogViewController) => any | Promise<any>): Promise<DialogViewController>;
30
30
  assertCardRendersSection(vc: ViewController<Card>, sectionIdOrIdx: string | number): void;
31
31
  assertCardDoesNotRenderSection(vc: ViewController<Card>, sectionIdOrIdx: string | number): void;
32
32
  /**
@@ -263,7 +263,7 @@ declare const vcAssert: {
263
263
  assertRendersAlertThenRedirects(options: AssertRedirectOptions & {
264
264
  vc: ViewController<any>;
265
265
  }): Promise<void>;
266
- patchAlertToThrow(vc: ViewController<any>): void;
266
+ patchAlertToThrow(vc: Controller): void;
267
267
  assertCardDoesNotRenderProgress(vc: ViewController<Card>, id?: string): void;
268
268
  assertCardRendersProgress(vc: ViewController<Card>, expectedPercentComplete?: number, id?: string): ProgressViewController;
269
269
  assertCardRendersRatings(vc: ViewController<Card>): RatingsViewController;
@@ -203,11 +203,6 @@ const vcAssert = {
203
203
  //@ts-ignore
204
204
  vc._currentlyRenderingInDialog = true;
205
205
  dialogVc = oldRenderInDialog(...args);
206
- // //@ts-ignore
207
- // dialogVc.getParent = () => {
208
- // //@ts-ignore
209
- // return dialogVc?.getCardVc().getParent()
210
- // }
211
206
  resolve(undefined);
212
207
  const oldHide = dialogVc.hide.bind(dialogVc);
213
208
  dialogVc.hide = () => __awaiter(this, void 0, void 0, function* () {
@@ -247,7 +242,7 @@ const vcAssert = {
247
242
  try {
248
243
  actionPromise = action();
249
244
  yield wait(actionPromise, dialogPromise);
250
- assert.isTrue(wasHit, `this.renderInDialog() was not invoked in your view controller within ${WAIT_TIMEOUT} milliseconds.`);
245
+ assert.isTrue(wasHit, `this.renderInDialog() was not invoked in your controller.`);
251
246
  yield dialogHandlerPromise;
252
247
  assert.isTruthy(dialogVc);
253
248
  //@ts-ignore
@@ -1005,7 +1000,7 @@ const vcAssert = {
1005
1000
  //@ts-ignore
1006
1001
  vc.alert = (options) => __awaiter(this, void 0, void 0, function* () {
1007
1002
  if (!options.style || options.style === 'error') {
1008
- assert.fail(`Skill view '${getVcName(vc)}' unexpectedly rendered an error alert. It reads:\n\n${options.message}`);
1003
+ assert.fail(`Controller '${getVcName(vc)}' unexpectedly rendered an error alert. It reads:\n\n${options.message}`);
1009
1004
  }
1010
1005
  });
1011
1006
  },
@@ -6,16 +6,16 @@ declare const vcAssertUtil: {
6
6
  _setVcFactory(factory: import("../..").ViewControllerFactory): void;
7
7
  attachTriggerRenderCounter(vc: import("./assertSupport").Vc): void;
8
8
  assertTriggerRenderCount(vc: import("./assertSupport").Vc, expected: number): void;
9
- assertRendersConfirm(vc: import("../..").ViewController<any>, action: () => any | Promise<any>): Promise<import("./assertSupport").AssertConfirmViewController>;
10
- assertDoesNotRenderConfirm(vc: import("../..").ViewController<any>, action: () => any | Promise<any>): Promise<void>;
11
- assertDoesNotRenderDialog(vc: import("../..").ViewController<any>, action: () => any | Promise<any>): Promise<void>;
12
- assertRendersSuccessAlert(vc: import("../..").ViewController<any>, action: () => any | Promise<any>): Promise<import("./vcAssert").AlertViewController>;
13
- assertRendersAlert(vc: import("../..").ViewController<any>, action: () => any | Promise<any>, style?: import("../..").AlertOptions["style"]): Promise<import("./vcAssert").AlertViewController>;
14
- assertDoesNotRenderAlert(vc: import("../..").ViewController<any>, action: () => any | Promise<any>, style?: import("../..").AlertOptions["style"]): Promise<void>;
15
- assertAsksForAVote(vc: import("../..").ViewController<any> | import("../..").AppController, action: () => Promise<any>): Promise<{
9
+ assertRendersConfirm(vc: import("./assertSupport").Controller, action: () => any | Promise<any>): Promise<import("./assertSupport").AssertConfirmViewController>;
10
+ assertDoesNotRenderConfirm(vc: import("./assertSupport").Controller, action: () => any | Promise<any>): Promise<void>;
11
+ assertDoesNotRenderDialog(vc: import("./assertSupport").Controller, action: () => any | Promise<any>): Promise<void>;
12
+ assertRendersSuccessAlert(vc: import("./assertSupport").Controller, action: () => any | Promise<any>): Promise<import("./vcAssert").AlertViewController>;
13
+ assertRendersAlert(vc: import("./assertSupport").Controller, action: () => any | Promise<any>, style?: import("../..").AlertOptions["style"]): Promise<import("./vcAssert").AlertViewController>;
14
+ assertDoesNotRenderAlert(vc: import("./assertSupport").Controller, action: () => any | Promise<any>, style?: import("../..").AlertOptions["style"]): Promise<void>;
15
+ assertAsksForAVote(vc: import("./assertSupport").Controller, action: () => Promise<any>): Promise<{
16
16
  castVote: () => Promise<void>;
17
17
  }>;
18
- assertRendersDialog(vc: import("../..").ViewController<any>, action: () => any | Promise<any>, dialogHandler?: (dialogVc: import("../..").DialogViewController) => any | Promise<any>): Promise<import("../..").DialogViewController>;
18
+ assertRendersDialog(vc: import("./assertSupport").Controller, action: () => any | Promise<any>, dialogHandler?: (dialogVc: import("../..").DialogViewController) => any | Promise<any>): Promise<import("../..").DialogViewController>;
19
19
  assertCardRendersSection(vc: import("../..").ViewController<import("../..").Card>, sectionIdOrIdx: string | number): void;
20
20
  assertCardDoesNotRenderSection(vc: import("../..").ViewController<import("../..").Card>, sectionIdOrIdx: string | number): void;
21
21
  assertCardSectionRendersButton(vc: import("../..").ViewController<import("../..").Card>, sectionIdOrIdx: string | number, buttonId?: string): void;
@@ -107,7 +107,7 @@ declare const vcAssertUtil: {
107
107
  assertRendersAlertThenRedirects(options: import("./assertSupport").AssertRedirectOptions & {
108
108
  vc: import("../..").ViewController<any>;
109
109
  }): Promise<void>;
110
- patchAlertToThrow(vc: import("../..").ViewController<any>): void;
110
+ patchAlertToThrow(vc: import("./assertSupport").Controller): void;
111
111
  assertCardDoesNotRenderProgress(vc: import("../..").ViewController<import("../..").Card>, id?: string): void;
112
112
  assertCardRendersProgress(vc: import("../..").ViewController<import("../..").Card>, expectedPercentComplete?: number, id?: string): import("../..").ProgressViewController;
113
113
  assertCardRendersRatings(vc: import("../..").ViewController<import("../..").Card>): import("../..").RatingsViewController;
@@ -1,18 +1,11 @@
1
- import { MercuryClient } from '@sprucelabs/mercury-client';
2
1
  import { LockScreenSkillViewControllerOptions } from '../skillViewControllers/LockScreen.svc';
3
- import { AppController, AppControllerLoadOptions, ControllerOptions, ToastOptions, ViewControllerId, ViewControllerMap, ViewControllerOptions, ViewControllerPlugins, VoteOptions } from '../types/heartwood.types';
4
- export default abstract class AbstractAppController implements AppController {
2
+ import { AppController, AppControllerLoadOptions, ViewControllerOptions, ViewControllerPlugins } from '../types/heartwood.types';
3
+ import AbstractController from './AbstractController';
4
+ export default abstract class AbstractAppController extends AbstractController implements AppController {
5
5
  static id: string;
6
6
  protected plugins: ViewControllerPlugins;
7
- private views;
8
7
  private renderLockScreenHandler;
9
- protected connectToApi: () => Promise<MercuryClient>;
10
- private toastHandler;
11
- private voteHandler;
12
8
  constructor(options: ViewControllerOptions);
13
9
  load(options: AppControllerLoadOptions): Promise<void>;
14
10
  protected renderLockScreen(options: LockScreenSkillViewControllerOptions): import("../skillViewControllers/LockScreen.svc").default;
15
- protected toast(options: ToastOptions): void;
16
- protected askForAVote(options: VoteOptions): Promise<void>;
17
- Controller<N extends ViewControllerId, O extends ControllerOptions<N>>(id: N, options: O): ViewControllerMap[N];
18
11
  }
@@ -7,15 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- export default class AbstractAppController {
10
+ import AbstractController from './AbstractController.js';
11
+ export default class AbstractAppController extends AbstractController {
11
12
  constructor(options) {
12
- const { plugins, vcFactory, renderLockScreenHandler, connectToApi, toastHandler, voteHandler, } = options;
13
+ super(options);
14
+ const { plugins, renderLockScreenHandler } = options;
13
15
  this.plugins = plugins;
14
- this.views = vcFactory;
15
- this.toastHandler = toastHandler;
16
- this.voteHandler = voteHandler;
17
16
  this.renderLockScreenHandler = renderLockScreenHandler;
18
- this.connectToApi = connectToApi;
19
17
  }
20
18
  load(options) {
21
19
  return __awaiter(this, void 0, void 0, function* () { });
@@ -26,15 +24,4 @@ export default class AbstractAppController {
26
24
  (_a = this.renderLockScreenHandler) === null || _a === void 0 ? void 0 : _a.call(this, controller.render());
27
25
  return controller;
28
26
  }
29
- toast(options) {
30
- this.toastHandler(options);
31
- }
32
- askForAVote(options) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- yield this.voteHandler(options);
35
- });
36
- }
37
- Controller(id, options) {
38
- return this.views.Controller(id, options);
39
- }
40
27
  }
@@ -1,49 +1,28 @@
1
1
  import { DateUtil } from '@sprucelabs/calendar-utils';
2
- import { MercuryClient } from '@sprucelabs/mercury-client';
3
2
  import { Log } from '@sprucelabs/spruce-skill-utils';
4
- import { ViewController, ViewControllerOptions, ConfirmOptions, ViewControllerId, ViewControllerMap, ControllerOptions, VoteOptions, Device, MapUtil, AlertOptions, ToastOptions, TriggerRenderHandler, ViewControllerPlugins } from '../types/heartwood.types';
5
- import { DialogViewControllerOptions } from './Dialog.vc';
6
- import ViewControllerFactory from './ViewControllerFactory';
7
- export default abstract class AbstractViewController<ViewModel extends Record<string, any>> implements ViewController<ViewModel> {
3
+ import { ViewController, ViewControllerOptions, ConfirmOptions, MapUtil, ViewControllerPlugins, TriggerRenderHandler } from '../types/heartwood.types';
4
+ import AbstractController from './AbstractController';
5
+ export default abstract class AbstractViewController<ViewModel extends Record<string, any>> extends AbstractController implements ViewController<ViewModel> {
8
6
  static id: string;
9
- private vcFactory;
10
- private renderInDialogHandler;
11
- private confirmHandler;
12
- private wasDestroyed;
13
- private activeDialog?;
14
- protected connectToApi: () => Promise<MercuryClient>;
15
7
  protected dates: DateUtil;
16
8
  protected maps: MapUtil;
17
- private voteHandler;
18
- private device;
19
- private children;
20
- private toastHandler;
21
- private activeAlert?;
22
- protected triggerRenderHandler?: TriggerRenderHandler;
9
+ private confirmHandler;
23
10
  private suspendRenderCount;
24
11
  protected plugins: ViewControllerPlugins;
25
12
  protected log: Log;
13
+ protected triggerRenderHandler?: TriggerRenderHandler;
26
14
  constructor(options: ViewControllerOptions);
27
15
  triggerRender(): void;
28
16
  setTriggerRenderHandler(handler: TriggerRenderHandler): void;
29
17
  /**
30
18
  * @deprecated this.getVcFactory() -> this.views()
31
19
  */
32
- protected getVcFactory(): ViewControllerFactory;
33
- protected get views(): ViewControllerFactory;
34
- protected mixinControllers(map: Record<string, any>): void;
35
- Controller<N extends ViewControllerId, O extends ControllerOptions<N>>(name: N, options: O): ViewControllerMap[N];
36
- protected renderInDialog(dialog: DialogViewControllerOptions): import("./Dialog.vc").default;
37
- protected hideDialog(): Promise<void>;
38
- protected askForAVote(options: VoteOptions): Promise<void>;
20
+ protected getVcFactory(): import("./ViewControllerFactory").default;
39
21
  private suspendRendering;
40
22
  private restoreRendering;
41
23
  renderOnce(cb: () => any | Promise<any>): Promise<void>;
42
24
  renderOnceSync(cb: () => any): void;
43
- destroy(): Promise<void>;
44
- protected toast(options: ToastOptions): void;
45
- protected alert(options: AlertOptions): Promise<void>;
46
25
  protected confirm(options: ConfirmOptions): Promise<boolean>;
47
- protected getDevice(): Device;
26
+ protected getDevice(): import("../types/heartwood.types").Device;
48
27
  abstract render(): ViewModel;
49
28
  }
@@ -7,24 +7,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import SpruceError from '../errors/SpruceError.js';
11
- export default class AbstractViewController {
10
+ import AbstractController from './AbstractController.js';
11
+ export default class AbstractViewController extends AbstractController {
12
12
  constructor(options) {
13
- this.wasDestroyed = false;
14
- this.children = [];
13
+ super(options);
15
14
  this.suspendRenderCount = 0;
16
15
  this.plugins = {};
17
- this.vcFactory = options.vcFactory;
18
- this.renderInDialogHandler = options.renderInDialogHandler;
19
- this.confirmHandler = options.confirmHandler;
20
- this.connectToApi = options.connectToApi;
21
- this.voteHandler = options.voteHandler;
22
- this.device = options.device;
23
- this.dates = options.dates;
24
- this.maps = options.maps;
25
- this.toastHandler = options.toastHandler;
26
- this.log = options.log;
27
- this.plugins = options.plugins;
16
+ const { confirmHandler, dates, maps, log, plugins } = options;
17
+ this.confirmHandler = confirmHandler;
18
+ this.dates = dates;
19
+ this.maps = maps;
20
+ this.log = log;
21
+ this.plugins = plugins;
28
22
  }
29
23
  triggerRender() {
30
24
  var _a;
@@ -39,39 +33,7 @@ export default class AbstractViewController {
39
33
  * @deprecated this.getVcFactory() -> this.views()
40
34
  */
41
35
  getVcFactory() {
42
- return this.vcFactory;
43
- }
44
- get views() {
45
- return this.vcFactory;
46
- }
47
- mixinControllers(map) {
48
- this.vcFactory.mixinControllers(map);
49
- }
50
- Controller(name, options) {
51
- const vc = this.vcFactory.Controller(name, options);
52
- if (vc) {
53
- //@ts-ignore
54
- vc.getParent = () => this;
55
- }
56
- this.children.push(vc);
57
- return vc;
58
- }
59
- renderInDialog(dialog) {
60
- const controller = this.Controller('dialog', Object.assign(Object.assign({}, dialog), { isVisible: true }));
61
- this.renderInDialogHandler(controller.render());
62
- this.activeDialog = controller;
63
- return controller;
64
- }
65
- hideDialog() {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- var _a;
68
- yield ((_a = this.activeDialog) === null || _a === void 0 ? void 0 : _a.hide());
69
- });
70
- }
71
- askForAVote(options) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- yield this.voteHandler(options);
74
- });
36
+ return this.views;
75
37
  }
76
38
  suspendRendering() {
77
39
  this.suspendRenderCount++;
@@ -93,71 +55,6 @@ export default class AbstractViewController {
93
55
  this.restoreRendering();
94
56
  this.triggerRender();
95
57
  }
96
- destroy() {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- if (this.wasDestroyed) {
99
- throw new SpruceError({
100
- code: 'VIEW_ALREADY_DESTROYED',
101
- //@ts-ignore
102
- viewId: this.id,
103
- });
104
- }
105
- yield Promise.all(
106
- //@ts-ignore
107
- this.children.map((c) => { var _a; return !c.wasDestroyed && ((_a = c.destroy) === null || _a === void 0 ? void 0 : _a.call(c)); }));
108
- this.wasDestroyed = true;
109
- });
110
- }
111
- toast(options) {
112
- this.toastHandler(options);
113
- }
114
- alert(options) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- var _a, _b, _c;
117
- const { title = 'Alert!', message, style, okButtonLabel } = options;
118
- const header = {
119
- title,
120
- };
121
- if (((_a = this.activeAlert) === null || _a === void 0 ? void 0 : _a.message) === message &&
122
- ((_b = this.activeAlert) === null || _b === void 0 ? void 0 : _b.title) === title &&
123
- ((_c = this.activeAlert) === null || _c === void 0 ? void 0 : _c.style) === style) {
124
- return;
125
- }
126
- this.activeAlert = Object.assign(Object.assign({}, options), { title });
127
- const text = {};
128
- const isHtml = message.includes('</');
129
- if (isHtml) {
130
- text.html = message;
131
- }
132
- else {
133
- text.content = message;
134
- }
135
- const dlg = this.renderInDialog({
136
- header,
137
- body: {
138
- sections: [
139
- {
140
- text,
141
- },
142
- ],
143
- },
144
- footer: {
145
- buttons: [
146
- {
147
- label: okButtonLabel !== null && okButtonLabel !== void 0 ? okButtonLabel : 'Ok',
148
- type: buttonStyleToType(style),
149
- onClick: () => {
150
- void dlg.hide();
151
- },
152
- },
153
- ],
154
- },
155
- });
156
- this.device.vibrate();
157
- yield dlg.wait();
158
- this.activeAlert = undefined;
159
- });
160
- }
161
58
  confirm(options) {
162
59
  return __awaiter(this, void 0, void 0, function* () {
163
60
  return this.confirmHandler(options);
@@ -167,14 +64,3 @@ export default class AbstractViewController {
167
64
  return this.device;
168
65
  }
169
66
  }
170
- function buttonStyleToType(style) {
171
- switch (style) {
172
- case 'error':
173
- case undefined:
174
- return 'destructive';
175
- case 'success':
176
- return 'primary';
177
- default:
178
- return 'primary';
179
- }
180
- }
@@ -0,0 +1,25 @@
1
+ import { MercuryClient } from '@sprucelabs/mercury-client';
2
+ import { AlertOptions, ControllerOptions, Device, ToastOptions, ViewControllerId, ViewControllerMap, ViewControllerOptions, VoteOptions } from '../types/heartwood.types';
3
+ import { DialogViewControllerOptions } from './Dialog.vc';
4
+ import ViewControllerFactory from './ViewControllerFactory';
5
+ export default abstract class AbstractController {
6
+ private renderInDialogHandler;
7
+ private voteHandler;
8
+ private activeDialog?;
9
+ private children;
10
+ private toastHandler;
11
+ private activeAlert?;
12
+ private wasDestroyed;
13
+ protected device: Device;
14
+ protected connectToApi: () => Promise<MercuryClient>;
15
+ protected views: ViewControllerFactory;
16
+ constructor(options: ViewControllerOptions);
17
+ protected askForAVote(options: VoteOptions): Promise<void>;
18
+ protected renderInDialog(dialog: DialogViewControllerOptions): import("./Dialog.vc").default;
19
+ protected hideDialog(): Promise<void>;
20
+ Controller<N extends ViewControllerId, O extends ControllerOptions<N>>(name: N, options: O): ViewControllerMap[N];
21
+ protected mixinControllers(map: Record<string, any>): void;
22
+ protected toast(options: ToastOptions): void;
23
+ protected alert(options: AlertOptions): Promise<void>;
24
+ destroy(): Promise<void>;
25
+ }