@miso.ai/client-sdk-ui 1.10.0-beta.1 → 1.10.0-beta.10

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 (78) hide show
  1. package/dist/cjs/actor/data.js +1 -1
  2. package/dist/cjs/actor/tracker.js +46 -70
  3. package/dist/cjs/actor/trackers.js +5 -1
  4. package/dist/cjs/actor/utils.js +6 -2
  5. package/dist/cjs/actor/view.js +14 -3
  6. package/dist/cjs/actor/views.js +9 -1
  7. package/dist/cjs/affiliation/index.js +126 -0
  8. package/dist/cjs/combo/ask/options.js +1 -1
  9. package/dist/cjs/combo/base.js +1 -1
  10. package/dist/cjs/constants.js +6 -3
  11. package/dist/cjs/defaults/ask/controls.js +1 -1
  12. package/dist/cjs/defaults/ask/phrases.js +1 -1
  13. package/dist/cjs/defaults/ask/templates.js +14 -4
  14. package/dist/cjs/element/role/index.js +7 -0
  15. package/dist/cjs/element/role/miso-affiliation.js +20 -0
  16. package/dist/cjs/layout/affiliation/affiliation.js +330 -0
  17. package/dist/cjs/layout/banner/banner.js +1 -1
  18. package/dist/cjs/layout/container/container.js +1 -1
  19. package/dist/cjs/layout/error/error.js +1 -1
  20. package/dist/cjs/layout/index.js +7 -0
  21. package/dist/cjs/layout/input/option-list.js +35 -50
  22. package/dist/cjs/layout/input/search-box.js +17 -5
  23. package/dist/cjs/layout/list/cards.js +1 -1
  24. package/dist/cjs/layout/list/carousel.js +5 -3
  25. package/dist/cjs/layout/list/collection.js +38 -48
  26. package/dist/cjs/layout/list/list.js +1 -1
  27. package/dist/cjs/layout/radio/feedback.js +1 -1
  28. package/dist/cjs/layout/radio/radio.js +1 -1
  29. package/dist/cjs/layout/raf.js +1 -1
  30. package/dist/cjs/layout/template.js +1 -1
  31. package/dist/cjs/layout/templates.js +135 -44
  32. package/dist/cjs/layout/text/text.js +1 -1
  33. package/dist/cjs/layout/text/typewriter/index.js +3 -3
  34. package/dist/cjs/layout/trackable.js +124 -0
  35. package/dist/cjs/plugin.js +1 -1
  36. package/dist/cjs/util/bindings.js +58 -110
  37. package/dist/cjs/util/states.js +31 -24
  38. package/dist/cjs/util/trackers.js +75 -0
  39. package/dist/cjs/util/viewables.js +55 -0
  40. package/dist/cjs/version.js +1 -1
  41. package/dist/cjs/workflow/ask.js +14 -5
  42. package/dist/cjs/workflow/asks.js +1 -1
  43. package/dist/cjs/workflow/base.js +5 -5
  44. package/dist/cjs/workflow/explore.js +1 -1
  45. package/dist/cjs/workflow/options.js +6 -1
  46. package/dist/cjs/workflow/recommendation.js +2 -0
  47. package/package.json +2 -2
  48. package/src/actor/tracker.js +39 -62
  49. package/src/actor/trackers.js +3 -1
  50. package/src/actor/utils.js +6 -2
  51. package/src/actor/view.js +12 -1
  52. package/src/actor/views.js +11 -0
  53. package/src/affiliation/index.js +108 -0
  54. package/src/constants.js +10 -1
  55. package/src/defaults/ask/phrases.js +1 -1
  56. package/src/defaults/ask/templates.js +13 -2
  57. package/src/element/role/index.js +1 -0
  58. package/src/element/role/miso-affiliation.js +16 -0
  59. package/src/layout/affiliation/affiliation.js +295 -0
  60. package/src/layout/index.js +1 -0
  61. package/src/layout/input/option-list.js +35 -43
  62. package/src/layout/input/search-box.js +7 -2
  63. package/src/layout/list/carousel.js +4 -2
  64. package/src/layout/list/collection.js +37 -43
  65. package/src/layout/templates.js +101 -26
  66. package/src/layout/text/typewriter/index.js +2 -2
  67. package/src/layout/trackable.js +106 -0
  68. package/src/util/bindings.js +47 -103
  69. package/src/util/states.js +26 -20
  70. package/src/util/trackers.js +69 -0
  71. package/src/util/viewables.js +47 -0
  72. package/src/version.js +1 -1
  73. package/src/workflow/ask.js +7 -3
  74. package/src/workflow/base.js +1 -1
  75. package/src/workflow/options.js +5 -1
  76. package/src/workflow/recommendation.js +1 -0
  77. package/dist/cjs/util/tracker.js +0 -348
  78. package/src/util/tracker.js +0 -318
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _commons = require("@miso.ai/commons");
8
+ var _constants = require("../../constants.js");
9
+ var _collection = _interopRequireDefault(require("../list/collection.js"));
10
+ var _templates = require("../templates.js");
11
+ const _excluded = ["className", "templates", "autoplay"];
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
14
+ const TYPE = 'affiliation';
15
+ const DEFAULT_CLASSNAME = 'miso-affiliation';
16
+ function root(layout, state) {
17
+ const {
18
+ className,
19
+ role,
20
+ templates
21
+ } = layout;
22
+ const {
23
+ status
24
+ } = state;
25
+ const roleAttr = role ? ` data-role="${role}"` : '';
26
+ const data = state.value || {};
27
+ const channelAttr = data.channel ? ` data-channel="${data.channel}"` : '';
28
+ return `<div class="${className} ${status}"${roleAttr}${channelAttr}>${status === _constants.STATUS.READY ? templates[status](layout, state) : ''}</div>`;
29
+ }
30
+ function ready(layout, state) {
31
+ const {
32
+ templates
33
+ } = layout;
34
+ const items = layout._getItems(state);
35
+ if (items && items.length > 0) {
36
+ return templates.control(layout, state, 'previous') + templates.body(layout, state) + templates.control(layout, state, 'next');
37
+ } else {
38
+ return templates.empty(layout, state);
39
+ }
40
+ }
41
+ function control(layout, state, direction) {
42
+ const {
43
+ className
44
+ } = layout;
45
+ return `<div class="${className}__control-${direction}" data-role="${direction}"></div>`;
46
+ }
47
+ function body(layout, state) {
48
+ const {
49
+ className,
50
+ templates
51
+ } = layout;
52
+ const items = layout._getItems(state);
53
+ return `<div class="${className}__body">${templates.list(layout, state, items)}</div>`;
54
+ }
55
+ function header(layout, state) {
56
+ const {
57
+ className,
58
+ templates
59
+ } = layout;
60
+ let {
61
+ headerText
62
+ } = templates;
63
+ if (typeof headerText === 'function') {
64
+ headerText = headerText(layout, state);
65
+ }
66
+ if (!headerText) {
67
+ return '';
68
+ }
69
+ return `<div class="${className}__header"><div class="${className}__header-tab">${headerText}</div></div>`;
70
+ }
71
+ function item(layout, state, value, index) {
72
+ const {
73
+ className,
74
+ templates,
75
+ options
76
+ } = layout;
77
+ const {
78
+ itemType
79
+ } = options;
80
+ const header = templates.itemHeader(layout, state, value, {
81
+ index
82
+ });
83
+ const body = templates[itemType](layout, state, value, {
84
+ index
85
+ });
86
+ return `<li class="${className}__item">${header}${body}</li>`;
87
+ }
88
+ function itemHeader(layout, state, value, meta) {
89
+ const {
90
+ className,
91
+ templates
92
+ } = layout;
93
+ let {
94
+ headerText
95
+ } = templates;
96
+ if (typeof headerText === 'function') {
97
+ headerText = headerText(layout, state, value, meta);
98
+ }
99
+ if (!headerText) {
100
+ return '';
101
+ }
102
+ return `<div class="${className}__item-header"><div class="${className}__item-header-tab">${headerText}</div></div>`;
103
+ }
104
+ const DEFAULT_TEMPLATES = Object.freeze({
105
+ root,
106
+ [_constants.STATUS.READY]: ready,
107
+ control,
108
+ body,
109
+ header,
110
+ item,
111
+ itemHeader,
112
+ affiliation: _templates.affiliation,
113
+ ctaText: 'View',
114
+ headerText: 'Featured'
115
+ });
116
+ const INHERITED_DEFAULT_TEMPLATES = Object.freeze(Object.assign({}, _collection.default.defaultTemplates, DEFAULT_TEMPLATES));
117
+ function normalizeAutoplayOptions(options) {
118
+ if (options === true) {
119
+ options = {
120
+ interval: 5000
121
+ };
122
+ } else if (typeof options === 'number') {
123
+ if (options <= 0) {
124
+ options = false;
125
+ } else {
126
+ options = {
127
+ interval: Math.max(options, 500)
128
+ };
129
+ }
130
+ }
131
+ return options;
132
+ }
133
+ function autoplayOptionsEquals(a, b) {
134
+ if (a === b) {
135
+ return true;
136
+ }
137
+ if (!a || !b) {
138
+ return false;
139
+ }
140
+ return a.interval === b.interval;
141
+ }
142
+ class AffiliationLayout extends _collection.default {
143
+ static get category() {
144
+ return _constants.LAYOUT_CATEGORY.AFFILIATION;
145
+ }
146
+ static get type() {
147
+ return TYPE;
148
+ }
149
+ static get defaultTemplates() {
150
+ return INHERITED_DEFAULT_TEMPLATES;
151
+ }
152
+ static get defaultClassName() {
153
+ return DEFAULT_CLASSNAME;
154
+ }
155
+ constructor() {
156
+ let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
157
+ let {
158
+ className = DEFAULT_CLASSNAME,
159
+ templates,
160
+ autoplay
161
+ } = _ref,
162
+ options = _objectWithoutPropertiesLoose(_ref, _excluded);
163
+ super(Object.assign({
164
+ className,
165
+ itemType: 'affiliation',
166
+ templates: Object.assign({}, DEFAULT_TEMPLATES, templates)
167
+ }, options));
168
+ this._itemCount = undefined;
169
+ this._itemIndex = 0;
170
+ this._displayedCount = undefined;
171
+ this._displayedIndex = undefined;
172
+ this._viewable = undefined;
173
+ this._autoplay = {};
174
+ this.autoplay(autoplay);
175
+ }
176
+ initialize(view) {
177
+ super.initialize(view);
178
+ const {
179
+ viewable: options
180
+ } = this._view.trackerOptions || {};
181
+ this._viewable = new _commons.CarouselItemViewabilityObserver(this._onViewable.bind(this), options);
182
+ }
183
+ autoplay() {
184
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
185
+ options = normalizeAutoplayOptions(options);
186
+ if (autoplayOptionsEquals(options, this._autoplay.options)) {
187
+ return;
188
+ }
189
+ if (this._autoplay.options) {
190
+ clearInterval(this._autoplay.intervalId);
191
+ }
192
+ this._autoplay = {
193
+ options
194
+ };
195
+ // TODO: use slower transition speed for autoplay
196
+ // TODO: pause on hover
197
+ // TODO: cooldown after manual interaction
198
+ if (options) {
199
+ this._autoplay.intervalId = setInterval(() => this.next(), options.interval);
200
+ }
201
+ }
202
+ get itemIndex() {
203
+ return this._itemIndex;
204
+ }
205
+ set itemIndex(index) {
206
+ if (this._itemCount === undefined) {
207
+ return;
208
+ }
209
+ if (index < 0) {
210
+ index = this._itemCount - 1;
211
+ } else if (index >= this._itemCount) {
212
+ index = 0;
213
+ }
214
+ this._itemIndex = index;
215
+ (0, _commons.requestAnimationFrame)(() => this._syncItemIndex());
216
+ }
217
+ next() {
218
+ if (this._itemCount === undefined) {
219
+ return;
220
+ }
221
+ this.itemIndex++;
222
+ }
223
+ previous() {
224
+ if (this._itemCount === undefined) {
225
+ return;
226
+ }
227
+ this.itemIndex--;
228
+ }
229
+ _getItems(state) {
230
+ const {
231
+ products
232
+ } = state.value || {};
233
+ return products;
234
+ }
235
+ _render(element, states, controls) {
236
+ super._render(element, states, controls);
237
+
238
+ // update item count, but raf to display as attribute
239
+ const items = this._getItems(states.state);
240
+ this._itemCount = items ? items.length : undefined;
241
+ (0, _commons.requestAnimationFrame)(() => {
242
+ this._syncItemCount();
243
+ this._syncItemIndex();
244
+ });
245
+ }
246
+ _syncElement(element) {
247
+ const oldElement = this._element;
248
+ super._syncElement(element);
249
+ this._syncViewableElement(oldElement, element);
250
+ }
251
+ _syncViewableElement(oldElement, newElement) {
252
+ if (oldElement === newElement) {
253
+ return;
254
+ }
255
+ oldElement && this._viewable.unobserve(oldElement);
256
+ newElement && this._viewable.observe(newElement);
257
+ }
258
+ _syncItemCount() {
259
+ const itemCount = this._itemCount;
260
+ if (itemCount === this._displayedCount) {
261
+ return;
262
+ }
263
+ let {
264
+ element
265
+ } = this._view;
266
+ element = element.firstElementChild;
267
+ if (!element) {
268
+ return;
269
+ }
270
+ this._displayedCount = itemCount;
271
+ if (itemCount === undefined) {
272
+ element.removeAttribute('data-item-count');
273
+ } else {
274
+ element.setAttribute('data-item-count', itemCount);
275
+ }
276
+ }
277
+ _syncItemIndex() {
278
+ const index = this._itemIndex;
279
+ if (index === this._displayedIndex) {
280
+ return;
281
+ }
282
+ const {
283
+ element
284
+ } = this._view;
285
+ const listElement = element && this._getListElement(element);
286
+ if (!listElement) {
287
+ return;
288
+ }
289
+ this._displayedIndex = index;
290
+ listElement.style.left = `${-index * 100}%`;
291
+ this._viewable.display(index);
292
+ this._view._events.emit('display', {
293
+ index
294
+ });
295
+ }
296
+ _onViewable(index) {
297
+ const item = this._getRenderedItemData(index);
298
+ if (!item) {
299
+ return;
300
+ }
301
+ this._view._track(_constants.EVENT_TYPE.VIEWABLE, [item]);
302
+ }
303
+ _getRenderedItemData(index) {
304
+ const {
305
+ value
306
+ } = this._rendered.get(this._element) || {};
307
+ if (!value) {
308
+ return undefined;
309
+ }
310
+ const {
311
+ products = []
312
+ } = value;
313
+ return products[index];
314
+ }
315
+ _trackViewables() {} // omit default behavior for we want to track by other means
316
+
317
+ _onClick(event) {
318
+ super._onClick(event);
319
+ const element = event.target;
320
+ if (element.closest(`[data-role="previous"]`)) {
321
+ this.previous();
322
+ return;
323
+ }
324
+ if (element.closest(`[data-role="next"]`)) {
325
+ this.next();
326
+ return;
327
+ }
328
+ }
329
+ }
330
+ exports.default = AffiliationLayout;
@@ -9,7 +9,7 @@ var _template = _interopRequireDefault(require("../template.js"));
9
9
  var _svgs = require("../svgs.js");
10
10
  const _excluded = ["className", "templates"];
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
12
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
13
13
  const TYPE = 'banner';
14
14
  const DEFAULT_CLASSNAME = 'miso-banner';
15
15
  function root(layout) {
@@ -9,7 +9,7 @@ var _raf = _interopRequireDefault(require("../raf.js"));
9
9
  var _misoBanner = _interopRequireDefault(require("../../element/miso-banner.js"));
10
10
  const _excluded = ["logo"];
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
12
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
13
13
  const TYPE = 'container';
14
14
  class ContainerLayout extends _raf.default {
15
15
  static get category() {
@@ -8,7 +8,7 @@ var _constants = require("../../constants.js");
8
8
  var _template = _interopRequireDefault(require("../template.js"));
9
9
  const _excluded = ["className", "templates"];
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
11
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
12
12
  const TYPE = 'error';
13
13
  const DEFAULT_CLASSNAME = 'miso-error';
14
14
  function root(layout, state) {
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "AffiliationLayout", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _affiliation.default;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "BannerLayout", {
7
13
  enumerable: true,
8
14
  get: function () {
@@ -94,4 +100,5 @@ var _optionList = _interopRequireDefault(require("./input/option-list.js"));
94
100
  var _feedback = _interopRequireDefault(require("./radio/feedback.js"));
95
101
  var _text = _interopRequireDefault(require("./text/text.js"));
96
102
  var _index = _interopRequireDefault(require("./text/typewriter/index.js"));
103
+ var _affiliation = _interopRequireDefault(require("./affiliation/affiliation.js"));
97
104
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -8,10 +8,10 @@ var _commons = require("@miso.ai/commons");
8
8
  var _constants = require("../../constants.js");
9
9
  var _index = require("../../actor/index.js");
10
10
  var _template = _interopRequireDefault(require("../template.js"));
11
+ var _trackable = require("../trackable.js");
11
12
  const _excluded = ["className", "templates"];
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
14
- const OPTION_VALUE = Symbol.for('miso.option-value');
14
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
15
15
  const TYPE = 'option-list';
16
16
  const DEFAULT_CLASSNAME = 'miso-option-list';
17
17
  function root(layout, state) {
@@ -77,11 +77,7 @@ class OptionListLayout extends _template.default {
77
77
  className,
78
78
  templates: Object.assign({}, DEFAULT_TEMPLATES, templates)
79
79
  }, options));
80
- (0, _commons.defineValues)(this, {
81
- bindings: Object.freeze({
82
- list: this._listBindings.bind(this)
83
- })
84
- });
80
+ this._initTrackable();
85
81
  }
86
82
  initialize(view) {
87
83
  this._view = view;
@@ -98,61 +94,44 @@ class OptionListLayout extends _template.default {
98
94
  }
99
95
  _render(element, data, controls) {
100
96
  super._render(element, data, controls);
101
- this._syncOptionValues(element, data);
102
- }
103
- _syncOptionValues(element, _ref2) {
104
- let {
97
+ const {
105
98
  state
106
- } = _ref2;
107
- if (!element) {
108
- return;
109
- }
110
- const optionsElement = this._getOptionsElement(element);
99
+ } = data;
100
+ this._syncBindings(element, state);
101
+ this._syncOptionValues(element, state);
102
+ }
103
+ _unrender() {
104
+ this._clearBindings();
105
+ }
106
+ _syncOptionValues(element, state) {
107
+ const optionsElement = element && this._getOptionsElement(element);
111
108
  if (!optionsElement) {
112
109
  return;
113
110
  }
114
- const optionValues = state.value || [];
111
+ const optionValues = this._getItems(state) || [];
115
112
  optionsElement.classList[optionValues.length === 0 ? 'add' : 'remove']('empty');
116
- let i = 0;
117
- for (const optionElement of this._listOptionElements(optionsElement)) {
118
- optionElement[OPTION_VALUE] = optionValues[i++];
119
- }
120
113
  }
121
- _listBindings(rootElement) {
122
- if (!rootElement) {
123
- return [];
124
- }
125
- const optionsElement = this._getOptionsElement(rootElement);
126
- const bindings = [];
127
- for (const element of this._listOptionElements(optionsElement)) {
128
- const value = element[OPTION_VALUE];
129
- if (!value) {
130
- continue;
131
- }
132
- const key = value.text || value;
133
- bindings.push({
134
- key,
135
- value,
136
- element
137
- });
138
- }
139
- return bindings;
114
+ _getItems(state) {
115
+ return state.value;
140
116
  }
141
117
  _getOptionsElement(element) {
142
118
  return element.querySelector(`[data-role="options"]`);
143
119
  }
144
- _listOptionElements(optionsElement) {
145
- return optionsElement ? Array.from(optionsElement.querySelectorAll(`[data-role="option"]`)) : [];
120
+ _getItemElements(element) {
121
+ return element ? Array.from(element.querySelectorAll(`[data-role="option"]`)) : [];
146
122
  }
147
- _handleClick(e) {
148
- for (let element = e.target; element && element !== this._view.element; element = element.parentElement) {
149
- const option = element[OPTION_VALUE];
150
- if (!option) {
151
- continue;
152
- }
153
- this._submit(option.text);
123
+ _handleClick(event) {
124
+ const element = event.target.closest(`[data-role="option"]`);
125
+ if (!element) {
126
+ return;
127
+ }
128
+ const binding = this._bindings.get(element);
129
+ const option = binding && binding.value;
130
+ if (!option) {
154
131
  return;
155
132
  }
133
+ this._trackClick(event, binding);
134
+ this._submit(option.text);
156
135
  }
157
136
  async _submit(value) {
158
137
  if (!value) {
@@ -163,5 +142,11 @@ class OptionListLayout extends _template.default {
163
142
  q: value
164
143
  });
165
144
  }
145
+ destroy() {
146
+ this._destroyTrackable();
147
+ this._view = undefined;
148
+ super.destroy();
149
+ }
166
150
  }
167
- exports.default = OptionListLayout;
151
+ exports.default = OptionListLayout;
152
+ (0, _trackable.makeTrackable)(OptionListLayout.prototype);
@@ -12,7 +12,7 @@ var _templates = require("../templates.js");
12
12
  var _svgs = require("../../asset/svgs.js");
13
13
  const _excluded = ["className", "templates", "autocomplete"];
14
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
15
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
16
16
  const TYPE = 'search-box';
17
17
  const DEFAULT_CLASSNAME = 'miso-search-box';
18
18
  const DEFAULT_AUTOCOMPLETE_CLASSNAME = 'miso-autocomplete';
@@ -324,10 +324,10 @@ class SearchBoxLayout extends _template.default {
324
324
  }
325
325
  // TODO: select completion items with arrow keys
326
326
  }
327
- _handleClick(_ref9) {
328
- let {
327
+ _handleClick(event) {
328
+ const {
329
329
  target
330
- } = _ref9;
330
+ } = event;
331
331
  const {
332
332
  inputElement
333
333
  } = this._context();
@@ -347,12 +347,24 @@ class SearchBoxLayout extends _template.default {
347
347
  if (inputElement) {
348
348
  inputElement.value = value;
349
349
  }
350
- this._submit(value);
350
+ this._view._events.emit('select', Object.freeze({
351
+ value: item,
352
+ index,
353
+ domEvent: event
354
+ }));
355
+ if (!event.defaultPrevented) {
356
+ this._submit(value);
357
+ }
351
358
  }
352
359
  this.close();
353
360
  return;
354
361
  }
355
362
  if (element.matches('[data-role="product-item"]')) {
363
+ this._view._events.emit('select', Object.freeze({
364
+ value: item,
365
+ index,
366
+ domEvent: event
367
+ }));
356
368
  return;
357
369
  }
358
370
  }
@@ -7,7 +7,7 @@ exports.default = void 0;
7
7
  var _collection = _interopRequireDefault(require("./collection.js"));
8
8
  const _excluded = ["className"];
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
10
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
11
11
  const TYPE = 'cards';
12
12
  const DEFAULT_CLASSNAME = 'miso-cards';
13
13
  class CardsLayout extends _collection.default {
@@ -7,7 +7,7 @@ exports.default = void 0;
7
7
  var _collection = _interopRequireDefault(require("./collection.js"));
8
8
  const _excluded = ["className", "templates"];
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
10
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
11
11
  const TYPE = 'carousel';
12
12
  const DEFAULT_CLASSNAME = 'miso-carousel';
13
13
  const DEFAULT_TEMPLATES = Object.freeze({
@@ -21,7 +21,8 @@ function ready(layout, state) {
21
21
  const {
22
22
  templates
23
23
  } = layout;
24
- const nonEmpty = state.value && state.value.length > 0;
24
+ const items = layout._getItems(state);
25
+ const nonEmpty = items && items.length > 0;
25
26
  const html = Object.getPrototypeOf(layout.constructor).defaultTemplates.ready(layout, state);
26
27
  return nonEmpty ? templates.carousel(layout, state, html) : html;
27
28
  }
@@ -71,7 +72,8 @@ class CarouselLayout extends _collection.default {
71
72
  const {
72
73
  state
73
74
  } = states;
74
- this._itemCount = state.value ? state.value.length : undefined;
75
+ const items = this._getItems(state);
76
+ this._itemCount = items ? items.length : undefined;
75
77
  this.syncSize();
76
78
  }
77
79
  get page() {