@sprucelabs/heartwood-view-controllers 111.1.33 → 111.1.35

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,4 +1,4 @@
1
- import { Button, Card, FormViewController, Navigation, ViewController } from '../../types/heartwood.types';
1
+ import { Button, Card, FormViewController, Navigation, SkillViewController, ViewController } from '../../types/heartwood.types';
2
2
  import BigFormViewController from '../../viewControllers/BigForm.vc';
3
3
  import ButtonBarViewController from '../../viewControllers/ButtonBar.vc';
4
4
  import ButtonGroupViewController from '../../viewControllers/ButtonGroup.vc';
@@ -20,7 +20,7 @@ declare const buttonAssert: {
20
20
  buttonIsSelected(vc: ViewController<Card>, id: string): void;
21
21
  };
22
22
  export default buttonAssert;
23
- export declare function pluckButtons(vc: ViewController<Card> | ViewController<Navigation> | FormViewController<any> | BigFormViewController<any>, ids: string[]): {
23
+ export declare function pluckButtons(vc: ViewController<Card> | ViewController<Navigation> | FormViewController<any> | BigFormViewController<any> | SkillViewController, ids: string[]): {
24
24
  found: string[];
25
25
  missing: string[];
26
26
  foundButtons: Button[];
@@ -114,9 +114,26 @@ const buttonAssert = {
114
114
  };
115
115
  export default buttonAssert;
116
116
  export function pluckButtons(vc, ids) {
117
- var _a, _b, _c, _d;
117
+ var _a;
118
118
  assertOptions({ vc, ids }, ['vc', 'ids']);
119
119
  const model = renderUtil.render(vc);
120
+ //@ts-ignore
121
+ if (model.layouts) {
122
+ const sv = model;
123
+ for (const layout of (_a = sv.layouts) !== null && _a !== void 0 ? _a : []) {
124
+ const cards = layout === null || layout === void 0 ? void 0 : layout.cards;
125
+ for (const card of cards !== null && cards !== void 0 ? cards : []) {
126
+ const results = pluckButtonsFromViewModel(card, ids);
127
+ if (results.found.length > 0) {
128
+ return results;
129
+ }
130
+ }
131
+ }
132
+ }
133
+ return pluckButtonsFromViewModel(model, ids);
134
+ }
135
+ function pluckButtonsFromViewModel(model, ids) {
136
+ var _a, _b, _c, _d;
120
137
  const buttons = [
121
138
  //@ts-ignore
122
139
  ...((_d = (_b = (_a = model.criticalError) === null || _a === void 0 ? void 0 : _a.buttons) !== null && _b !== void 0 ? _b : (_c = model.footer) === null || _c === void 0 ? void 0 : _c.buttons) !== null && _d !== void 0 ? _d : []),
@@ -66,7 +66,7 @@ const interactor = {
66
66
  },
67
67
  clickButton(vc, buttonId) {
68
68
  return __awaiter(this, void 0, void 0, function* () {
69
- const match = pluckButtonFromCard(vc, buttonId);
69
+ const match = pluckButtonFromView(vc, buttonId);
70
70
  yield this.click(match);
71
71
  });
72
72
  },
@@ -86,7 +86,7 @@ const interactor = {
86
86
  return __awaiter(this, void 0, void 0, function* () {
87
87
  var _a, _b;
88
88
  assertOptions({ vc, buttonId }, ['vc', 'buttonId']);
89
- const button = pluckButtonFromCard(vc, buttonId);
89
+ const button = pluckButtonFromView(vc, buttonId);
90
90
  assert.isTrue(button.shouldShowHintIcon, `Make sure have 'shouldShowHintIcon' set to true in your button: '${buttonId}'`);
91
91
  assert.isFunction(button.onClickHintIcon, `You gotta set 'onClickHintIcon' on your button with the id: '${(_a = button.id) !== null && _a !== void 0 ? _a : '***missing***'}'`);
92
92
  return (_b = button.onClickHintIcon) === null || _b === void 0 ? void 0 : _b.call(button);
@@ -412,7 +412,7 @@ const interactor = {
412
412
  },
413
413
  };
414
414
  export default interactor;
415
- function pluckButtonFromCard(vc, buttonId) {
415
+ function pluckButtonFromView(vc, buttonId) {
416
416
  const { foundButtons } = pluckButtons(vc, [buttonId]);
417
417
  const match = foundButtons[0];
418
418
  assert.isTruthy(match, `Could not find a button in '${getVcName(vc)}' with the id '${buttonId}'`);
@@ -1,5 +1,5 @@
1
1
  import { PermissionContractId } from '@sprucelabs/mercury-types';
2
- import { Navigation, SkillViewController, SkillViewControllerId, ViewController } from '../../types/heartwood.types';
2
+ import { AppController, Navigation, SkillViewController, SkillViewControllerId, ViewController } from '../../types/heartwood.types';
3
3
  declare const navigationAssert: {
4
4
  rendersButton(vc: ViewController<Navigation>, id: string): void;
5
5
  buttonRedirectsTo(options: {
@@ -12,7 +12,9 @@ declare const navigationAssert: {
12
12
  }): void;
13
13
  rendersButtons(vc: ViewController<Navigation>, ids: string[]): void;
14
14
  rendersButtonLabels(vc: ViewController<Navigation>): void;
15
- skillViewRendersNavigation(vc: Pick<SkillViewController, "renderNavigation">): ViewController<import("@sprucelabs/mercury-types").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Navigation>;
15
+ skillViewRendersNavigation(vc: Pick<SkillViewController, "renderNavigation">, msg?: string): ViewController<import("@sprucelabs/mercury-types").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Navigation>;
16
+ appRendersNavigation(vc: Pick<AppController, "renderNavigation">): ViewController<import("@sprucelabs/mercury-types").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Navigation>;
17
+ appDoesNotRenderNavigation(vc: Pick<AppController, "renderNavigation">): void;
16
18
  skillViewDoesNotRenderNavigation(vc: Pick<SkillViewController, "renderNavigation">): void;
17
19
  buttonRequiresViewPermissions(vc: ViewController<Navigation>, button: string, permissionContractId: PermissionContractId): void;
18
20
  };
@@ -22,12 +22,20 @@ const navigationAssert = {
22
22
  const model = renderUtil.render(vc);
23
23
  assert.isTrue(model.shouldRenderButtonLabels, `Your navigation should render button labels but it is not! Try shouldRenderButtonLabels: true`);
24
24
  },
25
- skillViewRendersNavigation(vc) {
25
+ skillViewRendersNavigation(vc, msg) {
26
26
  var _a;
27
27
  const nav = (_a = vc.renderNavigation) === null || _a === void 0 ? void 0 : _a.call(vc);
28
- assert.isTruthy(nav, `Your skill view did not render a navigation! Implement renderNavigation() and use this.Controller('navigation', {}) to render one.`);
28
+ assert.isTruthy(nav, msg !== null && msg !== void 0 ? msg : `Your skill view did not render a navigation! Implement renderNavigation() and use this.Controller('navigation', {}) to render one.`);
29
29
  return nav.controller;
30
30
  },
31
+ appRendersNavigation(vc) {
32
+ return this.skillViewRendersNavigation(vc, `Your AppController did not render a navigation! Implement renderNavigation() and use this.Controller('navigation', {}) to render one.`);
33
+ },
34
+ appDoesNotRenderNavigation(vc) {
35
+ var _a;
36
+ const nav = (_a = vc.renderNavigation) === null || _a === void 0 ? void 0 : _a.call(vc);
37
+ assert.isNull(nav, `Your AppController should not render a navigation! Implement renderNavigation() and return null.`);
38
+ },
31
39
  skillViewDoesNotRenderNavigation(vc) {
32
40
  var _a;
33
41
  const nav = (_a = vc.renderNavigation) === null || _a === void 0 ? void 0 : _a.call(vc);
@@ -517,7 +517,7 @@ export interface ActiveRecordSearchOptions {
517
517
  export interface AppController {
518
518
  renderNavigation?(): Navigation | null | undefined;
519
519
  renderToolBelt?(): ToolBelt | null | undefined;
520
- load?(options: AppControllerLoadOptions): Promise<void>;
520
+ load(options: AppControllerLoadOptions): Promise<void>;
521
521
  }
522
522
  export type BuiltAppController = AppController & {
523
523
  id: string;
@@ -1,5 +1,9 @@
1
- import { AppController, ViewControllerOptions } from '../types/heartwood.types';
1
+ import { AppController, AppControllerLoadOptions, ControllerOptions, ViewControllerId, ViewControllerMap, ViewControllerOptions, ViewControllerPlugins } from '../types/heartwood.types';
2
2
  export default abstract class AbstractAppController implements AppController {
3
3
  static id: string;
4
- constructor(_options: ViewControllerOptions);
4
+ protected plugins: ViewControllerPlugins;
5
+ private views;
6
+ constructor(options: ViewControllerOptions);
7
+ load(options: AppControllerLoadOptions): Promise<void>;
8
+ Controller<N extends ViewControllerId, O extends ControllerOptions<N>>(id: N, options: O): ViewControllerMap[N];
5
9
  }
@@ -1,3 +1,22 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  export default class AbstractAppController {
2
- constructor(_options) { }
11
+ constructor(options) {
12
+ const { plugins, vcFactory } = options;
13
+ this.plugins = plugins;
14
+ this.views = vcFactory;
15
+ }
16
+ load(options) {
17
+ return __awaiter(this, void 0, void 0, function* () { });
18
+ }
19
+ Controller(id, options) {
20
+ return this.views.Controller(id, options);
21
+ }
3
22
  }
@@ -1,4 +1,4 @@
1
- import { Button, Card, FormViewController, Navigation, ViewController } from '../../types/heartwood.types';
1
+ import { Button, Card, FormViewController, Navigation, SkillViewController, ViewController } from '../../types/heartwood.types';
2
2
  import BigFormViewController from '../../viewControllers/BigForm.vc';
3
3
  import ButtonBarViewController from '../../viewControllers/ButtonBar.vc';
4
4
  import ButtonGroupViewController from '../../viewControllers/ButtonGroup.vc';
@@ -20,7 +20,7 @@ declare const buttonAssert: {
20
20
  buttonIsSelected(vc: ViewController<Card>, id: string): void;
21
21
  };
22
22
  export default buttonAssert;
23
- export declare function pluckButtons(vc: ViewController<Card> | ViewController<Navigation> | FormViewController<any> | BigFormViewController<any>, ids: string[]): {
23
+ export declare function pluckButtons(vc: ViewController<Card> | ViewController<Navigation> | FormViewController<any> | BigFormViewController<any> | SkillViewController, ids: string[]): {
24
24
  found: string[];
25
25
  missing: string[];
26
26
  foundButtons: Button[];
@@ -116,6 +116,22 @@ exports.default = buttonAssert;
116
116
  function pluckButtons(vc, ids) {
117
117
  (0, schema_1.assertOptions)({ vc, ids }, ['vc', 'ids']);
118
118
  const model = render_utility_1.default.render(vc);
119
+ //@ts-ignore
120
+ if (model.layouts) {
121
+ const sv = model;
122
+ for (const layout of sv.layouts ?? []) {
123
+ const cards = layout?.cards;
124
+ for (const card of cards ?? []) {
125
+ const results = pluckButtonsFromViewModel(card, ids);
126
+ if (results.found.length > 0) {
127
+ return results;
128
+ }
129
+ }
130
+ }
131
+ }
132
+ return pluckButtonsFromViewModel(model, ids);
133
+ }
134
+ function pluckButtonsFromViewModel(model, ids) {
119
135
  const buttons = [
120
136
  //@ts-ignore
121
137
  ...(model.criticalError?.buttons ?? model.footer?.buttons ?? []),
@@ -59,7 +59,7 @@ const interactor = {
59
59
  });
60
60
  },
61
61
  async clickButton(vc, buttonId) {
62
- const match = pluckButtonFromCard(vc, buttonId);
62
+ const match = pluckButtonFromView(vc, buttonId);
63
63
  await this.click(match);
64
64
  },
65
65
  async clickButtonInGroup(buttonGroupVc, buttonIdOrIdx) {
@@ -74,7 +74,7 @@ const interactor = {
74
74
  },
75
75
  async clickButtonHint(vc, buttonId) {
76
76
  (0, schema_1.assertOptions)({ vc, buttonId }, ['vc', 'buttonId']);
77
- const button = pluckButtonFromCard(vc, buttonId);
77
+ const button = pluckButtonFromView(vc, buttonId);
78
78
  test_utils_1.assert.isTrue(button.shouldShowHintIcon, `Make sure have 'shouldShowHintIcon' set to true in your button: '${buttonId}'`);
79
79
  test_utils_1.assert.isFunction(button.onClickHintIcon, `You gotta set 'onClickHintIcon' on your button with the id: '${button.id ?? '***missing***'}'`);
80
80
  return button.onClickHintIcon?.();
@@ -330,7 +330,7 @@ const interactor = {
330
330
  },
331
331
  };
332
332
  exports.default = interactor;
333
- function pluckButtonFromCard(vc, buttonId) {
333
+ function pluckButtonFromView(vc, buttonId) {
334
334
  const { foundButtons } = (0, buttonAssert_1.pluckButtons)(vc, [buttonId]);
335
335
  const match = foundButtons[0];
336
336
  test_utils_1.assert.isTruthy(match, `Could not find a button in '${(0, assertSupport_1.getVcName)(vc)}' with the id '${buttonId}'`);
@@ -1,5 +1,5 @@
1
1
  import { PermissionContractId } from '@sprucelabs/mercury-types';
2
- import { Navigation, SkillViewController, SkillViewControllerId, ViewController } from '../../types/heartwood.types';
2
+ import { AppController, Navigation, SkillViewController, SkillViewControllerId, ViewController } from '../../types/heartwood.types';
3
3
  declare const navigationAssert: {
4
4
  rendersButton(vc: ViewController<Navigation>, id: string): void;
5
5
  buttonRedirectsTo(options: {
@@ -12,7 +12,9 @@ declare const navigationAssert: {
12
12
  }): void;
13
13
  rendersButtons(vc: ViewController<Navigation>, ids: string[]): void;
14
14
  rendersButtonLabels(vc: ViewController<Navigation>): void;
15
- skillViewRendersNavigation(vc: Pick<SkillViewController, "renderNavigation">): ViewController<import("@sprucelabs/mercury-types").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Navigation>;
15
+ skillViewRendersNavigation(vc: Pick<SkillViewController, "renderNavigation">, msg?: string): ViewController<import("@sprucelabs/mercury-types").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Navigation>;
16
+ appRendersNavigation(vc: Pick<AppController, "renderNavigation">): ViewController<import("@sprucelabs/mercury-types").SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Navigation>;
17
+ appDoesNotRenderNavigation(vc: Pick<AppController, "renderNavigation">): void;
16
18
  skillViewDoesNotRenderNavigation(vc: Pick<SkillViewController, "renderNavigation">): void;
17
19
  buttonRequiresViewPermissions(vc: ViewController<Navigation>, button: string, permissionContractId: PermissionContractId): void;
18
20
  };
@@ -26,11 +26,19 @@ const navigationAssert = {
26
26
  const model = render_utility_1.default.render(vc);
27
27
  test_utils_1.assert.isTrue(model.shouldRenderButtonLabels, `Your navigation should render button labels but it is not! Try shouldRenderButtonLabels: true`);
28
28
  },
29
- skillViewRendersNavigation(vc) {
29
+ skillViewRendersNavigation(vc, msg) {
30
30
  const nav = vc.renderNavigation?.();
31
- test_utils_1.assert.isTruthy(nav, `Your skill view did not render a navigation! Implement renderNavigation() and use this.Controller('navigation', {}) to render one.`);
31
+ test_utils_1.assert.isTruthy(nav, msg ??
32
+ `Your skill view did not render a navigation! Implement renderNavigation() and use this.Controller('navigation', {}) to render one.`);
32
33
  return nav.controller;
33
34
  },
35
+ appRendersNavigation(vc) {
36
+ return this.skillViewRendersNavigation(vc, `Your AppController did not render a navigation! Implement renderNavigation() and use this.Controller('navigation', {}) to render one.`);
37
+ },
38
+ appDoesNotRenderNavigation(vc) {
39
+ const nav = vc.renderNavigation?.();
40
+ test_utils_1.assert.isNull(nav, `Your AppController should not render a navigation! Implement renderNavigation() and return null.`);
41
+ },
34
42
  skillViewDoesNotRenderNavigation(vc) {
35
43
  const nav = vc.renderNavigation?.();
36
44
  test_utils_1.assert.isNull(nav, `Your skill view should not render a navigation! Implement renderNavigation() and return null.`);
@@ -517,7 +517,7 @@ export interface ActiveRecordSearchOptions {
517
517
  export interface AppController {
518
518
  renderNavigation?(): Navigation | null | undefined;
519
519
  renderToolBelt?(): ToolBelt | null | undefined;
520
- load?(options: AppControllerLoadOptions): Promise<void>;
520
+ load(options: AppControllerLoadOptions): Promise<void>;
521
521
  }
522
522
  export type BuiltAppController = AppController & {
523
523
  id: string;
@@ -1,5 +1,9 @@
1
- import { AppController, ViewControllerOptions } from '../types/heartwood.types';
1
+ import { AppController, AppControllerLoadOptions, ControllerOptions, ViewControllerId, ViewControllerMap, ViewControllerOptions, ViewControllerPlugins } from '../types/heartwood.types';
2
2
  export default abstract class AbstractAppController implements AppController {
3
3
  static id: string;
4
- constructor(_options: ViewControllerOptions);
4
+ protected plugins: ViewControllerPlugins;
5
+ private views;
6
+ constructor(options: ViewControllerOptions);
7
+ load(options: AppControllerLoadOptions): Promise<void>;
8
+ Controller<N extends ViewControllerId, O extends ControllerOptions<N>>(id: N, options: O): ViewControllerMap[N];
5
9
  }
@@ -1,6 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class AbstractAppController {
4
- constructor(_options) { }
4
+ constructor(options) {
5
+ const { plugins, vcFactory } = options;
6
+ this.plugins = plugins;
7
+ this.views = vcFactory;
8
+ }
9
+ async load(options) { }
10
+ Controller(id, options) {
11
+ return this.views.Controller(id, options);
12
+ }
5
13
  }
6
14
  exports.default = AbstractAppController;
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "sideEffects": false,
14
14
  "license": "MIT",
15
15
  "description": "All the power of Heartwood in one, convenient package.",
16
- "version": "111.1.33",
16
+ "version": "111.1.35",
17
17
  "skill": {
18
18
  "namespace": "HeartwoodViewControllers",
19
19
  "commandOverrides": {