@sprucelabs/spruce-heartwood-utils 29.10.8 → 29.11.1

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.
@@ -36,8 +36,7 @@ class MockRemoteViewControllerFactory {
36
36
  }
37
37
  }
38
38
  assertSkillViewRendersRemoteCard(vc, name, id) {
39
- var _a;
40
- const Class = (_a = MockRemoteViewControllerFactory.controllers) === null || _a === void 0 ? void 0 : _a[name];
39
+ const Class = MockRemoteViewControllerFactory.controllers?.[name];
41
40
  test_utils_1.assert.isTruthy(Class, `You did not drop in a remote card with the name '${name}'! Try MockRemoteViewControllerFactory.dropInRemoteController('${name}', Class) in your beforeEach().`);
42
41
  const cards = heartwood_view_controllers_1.vcAssert.assertSkillViewRendersCards(vc);
43
42
  const cardsWithNoControllers = cards.filter((c) => !c);
@@ -80,7 +79,7 @@ class MockRemoteViewControllerFactory {
80
79
  try {
81
80
  this.assertFetchedRemoteController(id);
82
81
  }
83
- catch (_a) {
82
+ catch {
84
83
  return;
85
84
  }
86
85
  test_utils_1.assert.fail(`You fetched the controller with the id '${id}' but you should not have.`);
@@ -95,14 +94,12 @@ class MockRemoteViewControllerFactory {
95
94
  test_utils_1.assert.isEqualDeep(this.constructorOptionsById[id], expected, `The constructor options for the remote card with id '${id}' do not match the expected options. Make sure the card you are rendering has an id using this.views.Controller('card', { id })`);
96
95
  }
97
96
  hasController(name) {
98
- var _a;
99
- return (_a = this.loadedControllers[name]) !== null && _a !== void 0 ? _a : false;
97
+ return this.loadedControllers[name] ?? false;
100
98
  }
101
99
  async RemoteController(id, options) {
102
- var _a, _b;
103
- test_utils_1.assert.isTruthy((_a = MockRemoteViewControllerFactory.controllers) === null || _a === void 0 ? void 0 : _a[id], `Could not find a remote card with the id '${id}'! Try MockRemoteViewControllerFactory.dropInRemoteController('${id}', Class) in your beforeEach().`);
100
+ test_utils_1.assert.isTruthy(MockRemoteViewControllerFactory.controllers?.[id], `Could not find a remote card with the id '${id}'! Try MockRemoteViewControllerFactory.dropInRemoteController('${id}', Class) in your beforeEach().`);
104
101
  this.loadedControllers[id] = true;
105
- this.constructorOptionsById[(_b = options.id) !== null && _b !== void 0 ? _b : id] = options;
102
+ this.constructorOptionsById[options.id ?? id] = options;
106
103
  this.lastRemoteCostructorOptions = options;
107
104
  return this.views.Controller(id, options);
108
105
  }
@@ -31,7 +31,7 @@ function generateVcSource(options) {
31
31
  return [
32
32
  `class TestEventViewController${count} {
33
33
  alert = function() {}
34
- ${stubMethod !== null && stubMethod !== void 0 ? stubMethod : 'noop'} = function () {
34
+ ${stubMethod ?? 'noop'} = function () {
35
35
  this.wasHit = true
36
36
  this.passedParams = Array.prototype.slice.call(arguments)
37
37
  }
@@ -11,7 +11,6 @@ const test_utils_2 = require("@sprucelabs/test-utils");
11
11
  const heartwoodEventFaker_1 = __importDefault(require("./heartwoodEventFaker"));
12
12
  const remoteVcAssert = {
13
13
  async assertSkillViewRendersRemoteCards(options) {
14
- var _a;
15
14
  const { views, svc: svc, expectedTarget, expectedPayload, fqen, shouldInvoke, loadArgs, } = (0, schema_1.assertOptions)(options, [
16
15
  'svc',
17
16
  'fqen',
@@ -34,7 +33,7 @@ const remoteVcAssert = {
34
33
  vcIds: ['assert.' + vc1Id, 'assert.' + vc2Id],
35
34
  };
36
35
  });
37
- const stubMethodName = shouldInvoke === null || shouldInvoke === void 0 ? void 0 : shouldInvoke.methodName;
36
+ const stubMethodName = shouldInvoke?.methodName;
38
37
  const ids = [vc1Id, vc2Id];
39
38
  await heartwoodEventFaker_1.default.fakeGetViews(ids, stubMethodName);
40
39
  await views.load(svc, loadArgs);
@@ -68,7 +67,7 @@ public render() {
68
67
  }
69
68
  }
70
69
 
71
- The original error is: ${(_a = err.stack) !== null && _a !== void 0 ? _a : err.message}
70
+ The original error is: ${err.stack ?? err.message}
72
71
  `);
73
72
  }
74
73
  if (shouldInvoke) {
@@ -30,9 +30,8 @@ class HeartwoodDevice extends events_1.default {
30
30
  });
31
31
  }
32
32
  static Device(storage) {
33
- var _a;
34
33
  (0, schema_1.assertOptions)({ storage }, ['storage']);
35
- return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(storage);
34
+ return new (this.Class ?? this)(storage);
36
35
  }
37
36
  setCachedValue(key, value) {
38
37
  this.storage.setItem(key, JSON.stringify({ value }));
@@ -64,7 +63,6 @@ class HeartwoodDevice extends events_1.default {
64
63
  this.sendCommand('skillViewLoaded');
65
64
  }
66
65
  sendCommand(command, payload) {
67
- var _a, _b, _c, _d, _e, _f, _g;
68
66
  const options = {
69
67
  command,
70
68
  payload,
@@ -72,12 +70,12 @@ class HeartwoodDevice extends events_1.default {
72
70
  const message = JSON.stringify(options);
73
71
  if (!this.isGettingTheatreSetting) {
74
72
  //@ts-ignore
75
- (_d = (_c = (_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.messages) === null || _c === void 0 ? void 0 : _c.postMessage) === null || _d === void 0 ? void 0 : _d.call(_c, message);
73
+ window.webkit?.messageHandlers?.messages?.postMessage?.(message);
76
74
  // @ts-ignore
77
- (_e = window.AndroidInterface) === null || _e === void 0 ? void 0 : _e.postMessage(message);
75
+ window.AndroidInterface?.postMessage(message);
78
76
  }
79
77
  //@ts-ignore
80
- (_g = (_f = window.api) === null || _f === void 0 ? void 0 : _f.postMessage) === null || _g === void 0 ? void 0 : _g.call(_f, message);
78
+ window.api?.postMessage?.(message);
81
79
  this.emit('command', command, payload);
82
80
  }
83
81
  setTheatreSetting(name, value) {
@@ -99,10 +97,9 @@ class HeartwoodDevice extends events_1.default {
99
97
  return null;
100
98
  }
101
99
  return new Promise((resolve) => {
102
- var _a, _b;
103
100
  let timeout = setTimeout(() => resolve(null), 250);
104
101
  //@ts-ignore
105
- (_b = (_a = window.api) === null || _a === void 0 ? void 0 : _a.onMessage) === null || _b === void 0 ? void 0 : _b.call(_a, (json) => {
102
+ window.api?.onMessage?.((json) => {
106
103
  const { value, name: returnedName } = JSON.parse(json);
107
104
  if (name === returnedName) {
108
105
  clearTimeout(timeout);
@@ -8,7 +8,7 @@ class SpruceError extends error_1.default {
8
8
  friendlyMessage() {
9
9
  const { options } = this;
10
10
  let message;
11
- switch (options === null || options === void 0 ? void 0 : options.code) {
11
+ switch (options?.code) {
12
12
  case 'CONTROLLER_NOT_SET_ON_VIEW':
13
13
  message =
14
14
  'A view controller has not been set as the `controller` of the view returned from render().';
@@ -29,7 +29,7 @@ class CardRegistrar {
29
29
  async fetch(options) {
30
30
  try {
31
31
  //@ts-ignore
32
- const { each, controllerOptionsHandler, target, payload } = options !== null && options !== void 0 ? options : {};
32
+ const { each, controllerOptionsHandler, target, payload } = options ?? {};
33
33
  let targetAndPayload;
34
34
  if (target && payload) {
35
35
  targetAndPayload = { target, payload };
@@ -42,9 +42,8 @@ class CardRegistrar {
42
42
  }
43
43
  const cards = [];
44
44
  await this.client.emit(this.eventName, targetAndPayload, async (targetAndPayload) => {
45
- var _a;
46
- const { payload, errors } = targetAndPayload !== null && targetAndPayload !== void 0 ? targetAndPayload : {};
47
- const err = errors === null || errors === void 0 ? void 0 : errors[0];
45
+ const { payload, errors } = targetAndPayload ?? {};
46
+ const err = errors?.[0];
48
47
  if (err) {
49
48
  console.error('Remote card error', err);
50
49
  cards.push(this.ErrorCardVc(err));
@@ -59,7 +58,7 @@ class CardRegistrar {
59
58
  const responseCards = [];
60
59
  for (const id of vcIds) {
61
60
  try {
62
- const vc = await this.remoteVcFactory.RemoteController(id, (_a = controllerOptionsHandler === null || controllerOptionsHandler === void 0 ? void 0 : controllerOptionsHandler(id)) !== null && _a !== void 0 ? _a : {});
61
+ const vc = await this.remoteVcFactory.RemoteController(id, controllerOptionsHandler?.(id) ?? {});
63
62
  responseCards.push(vc);
64
63
  }
65
64
  catch (err) {
@@ -67,7 +66,7 @@ class CardRegistrar {
67
66
  }
68
67
  }
69
68
  if (responseCards.length > 0) {
70
- await (each === null || each === void 0 ? void 0 : each(responseCards));
69
+ await each?.(responseCards);
71
70
  }
72
71
  cards.push(...responseCards);
73
72
  });
@@ -7,8 +7,7 @@ const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-control
7
7
  const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
8
8
  class RemoteViewControllerFactoryImpl {
9
9
  static Factory(options) {
10
- var _a;
11
- return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(options);
10
+ return new (this.Class ?? this)(options);
12
11
  }
13
12
  static reset() {
14
13
  delete this.Class;
@@ -22,7 +21,7 @@ class RemoteViewControllerFactoryImpl {
22
21
  return this.vcFactory.hasController(name);
23
22
  }
24
23
  getTheme(namespace) {
25
- return this.themesByNamespace[namespace !== null && namespace !== void 0 ? namespace : ''];
24
+ return this.themesByNamespace[namespace ?? ''];
26
25
  }
27
26
  Controller(name, options) {
28
27
  return this.vcFactory.Controller(name, options);
@@ -65,7 +64,11 @@ class RemoteViewControllerFactoryImpl {
65
64
  }
66
65
  this.vcFactory.importControllers(skillViews, plugins);
67
66
  if (theme) {
68
- this.themesByNamespace[namespace] = Object.assign(Object.assign({}, theme), { slug: namespace, name: namespace });
67
+ this.themesByNamespace[namespace] = {
68
+ ...theme,
69
+ slug: namespace,
70
+ name: namespace,
71
+ };
69
72
  }
70
73
  }
71
74
  }
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.heartwoodTheme = exports.ThemeManagerImpl = void 0;
15
4
  class ThemeManagerImpl {
@@ -40,22 +29,22 @@ class ThemeManagerImpl {
40
29
  this.themeCount = 0;
41
30
  }
42
31
  async setTheme(theme, shouldAnimate = true) {
43
- var _a, _b, _c, _d;
44
- if (((_a = this.currentTheme) === null || _a === void 0 ? void 0 : _a.name) === theme.name) {
32
+ if (this.currentTheme?.name === theme.name) {
45
33
  return;
46
34
  }
47
- (_b = this.themeChangeHandler) === null || _b === void 0 ? void 0 : _b.call(this, theme);
35
+ this.themeChangeHandler?.(theme);
48
36
  this.themeCount++;
49
37
  this.currentTheme = theme;
50
- const _e = theme.props, { calendarEvents, borderRadius } = _e, rest = __rest(_e, ["calendarEvents", "borderRadius"]);
38
+ const { calendarEvents, borderRadius, ...rest } = theme.props;
51
39
  this.applyBorderRadius(borderRadius);
52
40
  //@ts-ignore
53
41
  await this.setProps(Object.entries(rest), shouldAnimate);
54
42
  if (calendarEvents) {
55
43
  await this.setProps(Object.entries(calendarEvents), shouldAnimate);
56
44
  }
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');
45
+ document
46
+ .querySelector('meta[name="theme-color"]')
47
+ ?.setAttribute('content', theme.props.color1Inverse ?? 'white');
59
48
  }
60
49
  applyBorderRadius(borderRadius) {
61
50
  if (!borderRadius || borderRadius === 'rounded') {
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.10.8",
4
+ "version": "29.11.1",
5
5
  "skill": {
6
6
  "namespace": "heartwood"
7
7
  },