@miso.ai/client-sdk-ui 1.11.5-beta.1 → 1.11.5-beta.3

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TRIANGLE_EQ = exports.TRIANGLE = exports.SEND = exports.SEARCH = exports.ICON_NAMES = exports.CHEVRON_NEGATIVE = void 0;
6
+ exports.TRIANGLE_EQ = exports.TRIANGLE = exports.SEND = exports.SEARCH = exports.ICON_NAMES = exports.CHEVRON_NEGATIVE = exports.CHEVRON = void 0;
7
7
  exports.getIcon = getIcon;
8
8
  var _version = _interopRequireDefault(require("../version.js"));
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -20,6 +20,7 @@ const ICON_NAME = {
20
20
  SEARCH: 'search',
21
21
  TRIANGLE: 'triangle',
22
22
  TRIANGLE_EQ: 'triangle-eq',
23
+ CHEVRON: 'chevron',
23
24
  CHEVRON_NEGATIVE: 'chevron-negative'
24
25
  };
25
26
 
@@ -30,8 +31,9 @@ const ICON_SEARCH = `<symbol id="${PREFIX}-${ICON_NAME.SEARCH}" viewBox="0 0 24
30
31
  // Custom SVGs
31
32
  const ICON_TRIANGLE = `<symbol id="${PREFIX}-${ICON_NAME.TRIANGLE}" viewBox="-5 -5 105 105"><path d="${trianglePath(5)}"/></symbol>`;
32
33
  const ICON_TRIANGLE_EQ = `<symbol id="${PREFIX}-${ICON_NAME.TRIANGLE_EQ}" viewBox="-100 -100 200 200"><path d="M12.99 -77.5A15 15,0,0,0,-12.99 -77.5L-73.61 27.5A15 15,0,0,0,-60.62 50L60.62 50A15 15,0,0,0,73.61 27.5L12.99 -77.5Z"/></symbol>`;
34
+ const ICON_CHEVRON = `<symbol id="${PREFIX}-${ICON_NAME.CHEVRON}" viewBox="-100 -100 200 200"><path d="M10.61 -43.94A15 15,0,0,0,-10.61 -43.94L-60.61 6.06A15 15,0,0,0,-39.39 27.27L0 -12.12L39.39 27.27A15 15,0,0,0,60.61 6.06L10.61 -43.94Z"/></symbol>`;
33
35
  const ICON_CHEVRON_NEGATIVE = `<symbol id="${PREFIX}-${ICON_NAME.CHEVRON_NEGATIVE}" viewBox="-100 -100 200 200"><path d="M100 100V-200H-200V200H200ZM-10.61 -43.94A15 15,0,0,1,10.61 -43.94L60.61 6.06A15 15,0,0,1,39.39 27.27L0 -12.12L-39.39 27.27A15 15,0,0,1,-60.61 6.06L-10.61 -43.94Z"/></symbol>`;
34
- const ICONS = [ICON_SEND, ICON_SEARCH, ICON_TRIANGLE, ICON_TRIANGLE_EQ, ICON_CHEVRON_NEGATIVE];
36
+ const ICONS = [ICON_SEND, ICON_SEARCH, ICON_TRIANGLE, ICON_TRIANGLE_EQ, ICON_CHEVRON, ICON_CHEVRON_NEGATIVE];
35
37
  const SPRITES_SVG = `<svg id="${ID}" style="display:none;">${ICONS.join('')}</svg>`;
36
38
  let loaded = false;
37
39
  function loadSvgSprites() {
@@ -53,4 +55,5 @@ const SEND = exports.SEND = _icon(ICON_NAME.SEND);
53
55
  const SEARCH = exports.SEARCH = _icon(ICON_NAME.SEARCH);
54
56
  const TRIANGLE = exports.TRIANGLE = _icon(ICON_NAME.TRIANGLE);
55
57
  const TRIANGLE_EQ = exports.TRIANGLE_EQ = _icon(ICON_NAME.TRIANGLE_EQ);
58
+ const CHEVRON = exports.CHEVRON = _icon(ICON_NAME.CHEVRON);
56
59
  const CHEVRON_NEGATIVE = exports.CHEVRON_NEGATIVE = _icon(ICON_NAME.CHEVRON_NEGATIVE);
@@ -9,6 +9,7 @@ var _constants = require("../../constants.js");
9
9
  var _collection = _interopRequireDefault(require("../list/collection.js"));
10
10
  var _templates = require("../templates.js");
11
11
  var _svgs = require("../../asset/svgs.js");
12
+ var _dom = require("../../util/dom.js");
12
13
  const _excluded = ["className", "templates", "autoplay"];
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
15
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
@@ -18,7 +19,8 @@ function root(layout, state) {
18
19
  const {
19
20
  className,
20
21
  role,
21
- templates
22
+ templates,
23
+ options
22
24
  } = layout;
23
25
  const {
24
26
  status
@@ -29,7 +31,8 @@ function root(layout, state) {
29
31
  const items = layout._getItems(state);
30
32
  const itemCount = items ? items.length : undefined;
31
33
  const itemCountAttr = itemCount !== undefined ? ` data-item-count="${itemCount}"` : '';
32
- return `<div class="${className} ${status}"${roleAttr}${channelAttr}${itemCountAttr}>${status === _constants.STATUS.READY ? templates[status](layout, state) : ''}</div>`;
34
+ const itemTypeAttr = options.itemType ? ` data-item-type="${options.itemType}"` : '';
35
+ return `<div class="${className} ${status}"${roleAttr}${channelAttr}${itemTypeAttr}${itemCountAttr}>${status === _constants.STATUS.READY ? templates[status](layout, state) : ''}</div>`;
33
36
  }
34
37
  function ready(layout, state) {
35
38
  const {
@@ -293,12 +296,8 @@ class AffiliationLayout extends _collection.default {
293
296
  if (!element) {
294
297
  return;
295
298
  }
299
+ (0, _dom.setOrRemoveAttribute)(element, 'data-item-count', itemCount);
296
300
  this._displayedCount = itemCount;
297
- if (itemCount === undefined) {
298
- element.removeAttribute('data-item-count');
299
- } else {
300
- element.setAttribute('data-item-count', itemCount);
301
- }
302
301
  }
303
302
  _syncItemIndex() {
304
303
  const index = this._itemIndex;
@@ -57,6 +57,12 @@ Object.defineProperty(exports, "FeedbackLayout", {
57
57
  return _feedback.default;
58
58
  }
59
59
  });
60
+ Object.defineProperty(exports, "GalleryLayout", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _gallery.default;
64
+ }
65
+ });
60
66
  Object.defineProperty(exports, "ListLayout", {
61
67
  enumerable: true,
62
68
  get: function () {
@@ -113,6 +119,7 @@ var _collection = _interopRequireDefault(require("./list/collection.js"));
113
119
  var _list = _interopRequireDefault(require("./list/list.js"));
114
120
  var _cards = _interopRequireDefault(require("./list/cards.js"));
115
121
  var _carousel = _interopRequireDefault(require("./list/carousel.js"));
122
+ var _gallery = _interopRequireDefault(require("./list/gallery.js"));
116
123
  var _searchBox = _interopRequireDefault(require("./input/search-box.js"));
117
124
  var _optionList = _interopRequireDefault(require("./input/option-list.js"));
118
125
  var _feedback = _interopRequireDefault(require("./radio/feedback.js"));
@@ -8,6 +8,7 @@ var _commons = require("@miso.ai/commons");
8
8
  var _index = require("../../actor/index.js");
9
9
  var _template = _interopRequireDefault(require("../template.js"));
10
10
  var _trackable = require("../mixin/trackable.js");
11
+ var _dom = require("../../util/dom.js");
11
12
  const _excluded = ["className", "templates"];
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
@@ -107,7 +108,7 @@ class OptionListLayout extends _template.default {
107
108
  return;
108
109
  }
109
110
  const optionValues = this._getItems(state) || [];
110
- optionsElement.classList[optionValues.length === 0 ? 'add' : 'remove']('empty');
111
+ (0, _dom.addOrRemoveClass)(optionsElement, 'empty', optionValues.length === 0);
111
112
  }
112
113
  _getItems(state) {
113
114
  return state.value;
@@ -10,6 +10,7 @@ var _index = require("../../actor/index.js");
10
10
  var _template = _interopRequireDefault(require("../template.js"));
11
11
  var _templates = require("../templates.js");
12
12
  var _svgs = require("../../asset/svgs.js");
13
+ var _dom = require("../../util/dom.js");
13
14
  const _excluded = ["className", "templates", "autocomplete"];
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
16
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
@@ -250,7 +251,7 @@ class SearchBoxLayout extends _template.default {
250
251
  return;
251
252
  }
252
253
  const items = context.trackItems(completions);
253
- element.classList[items.length > 0 ? 'add' : 'remove']('nonempty');
254
+ (0, _dom.addOrRemoveClass)(element, 'nonempty', items.length > 0);
254
255
  autocompleteElement.setAttribute('data-status', status);
255
256
  autocompleteElement.innerHTML = this.templates.completions(this, items);
256
257
  writeToState({
@@ -50,8 +50,8 @@ function control(layout, state, direction) {
50
50
  } = layout;
51
51
  return `<div class="${className}__control-${direction}" data-role="${direction}">${templates.controlIcon(layout, state, direction)}</div>`;
52
52
  }
53
- function controlIcon(layout, state, direction) {
54
- return _svgs.CHEVRON_NEGATIVE;
53
+ function controlIcon(layout) {
54
+ return layout.options.itemType === 'image' ? _svgs.CHEVRON_NEGATIVE : _svgs.CHEVRON;
55
55
  }
56
56
  function indexIndicator(layout, state, values) {
57
57
  const {
@@ -16,13 +16,15 @@ function root(layout, state) {
16
16
  const {
17
17
  className,
18
18
  role,
19
- templates
19
+ templates,
20
+ options
20
21
  } = layout;
21
22
  const {
22
23
  status
23
24
  } = state;
24
- const roleAttr = role ? `data-role="${role}"` : '';
25
- return `<div class="${className} ${status}" ${roleAttr}>${status === _constants.STATUS.READY ? templates[status](layout, state) : ''}${templates.trigger(layout, state)}${templates.loading(layout, state)}</div>`;
25
+ const roleAttr = role ? ` data-role="${role}"` : '';
26
+ const itemTypeAttr = options.itemType ? ` data-item-type="${options.itemType}"` : '';
27
+ return `<div class="${className} ${status}"${roleAttr}${itemTypeAttr}>${status === _constants.STATUS.READY ? templates[status](layout, state) : ''}${templates.trigger(layout, state)}${templates.loading(layout, state)}</div>`;
26
28
  }
27
29
  function ready(layout, state) {
28
30
  const {
@@ -48,8 +50,9 @@ function list(layout, state, values) {
48
50
  options
49
51
  } = layout;
50
52
  const listTag = templates.ordered ? 'ol' : 'ul';
53
+ const itemTypeAttr = options.itemType ? ` data-item-type="${options.itemType}"` : ''; // backward compatible
51
54
  // TODO: support separator?
52
- return `<${listTag} class="${className}__list" data-role="list" data-item-type="${options.itemType}">${templates.items(layout, state, values)}</${listTag}>`;
55
+ return `<${listTag} class="${className}__list" data-role="list"${itemTypeAttr}>${templates.items(layout, state, values)}</${listTag}>`;
53
56
  }
54
57
  function items(layout, state, values) {
55
58
  let {
@@ -0,0 +1,273 @@
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 _collection = _interopRequireDefault(require("./collection.js"));
9
+ var _dom = require("../../util/dom.js");
10
+ const _excluded = ["className", "templates"];
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 (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
13
+ function calculateItemSizes(itemCount, columnCount) {
14
+ const totalSpaces = columnCount * 2;
15
+ let remainingSpaces = Math.max(totalSpaces - itemCount, 0);
16
+ let small = itemCount;
17
+ // turning a small block into a large block takes 3 extra spaces
18
+ const large = Math.min(Math.floor(remainingSpaces / 3), small);
19
+ small -= large;
20
+ remainingSpaces -= large * 3;
21
+ // turning a small block into a medium block takes 1 extra space
22
+ const medium = Math.min(remainingSpaces, small);
23
+ small -= medium;
24
+ remainingSpaces -= medium;
25
+ return [large, medium, small];
26
+ }
27
+ function item(layout, state, value, index) {
28
+ const {
29
+ className,
30
+ templates,
31
+ options
32
+ } = layout;
33
+ const {
34
+ itemType
35
+ } = options;
36
+ const body = templates[itemType](layout, state, value, {
37
+ index
38
+ });
39
+ const sizeClass = value._size ? ` ${className}__item-${value._size}` : '';
40
+ return `<li class="${className}__item${sizeClass}">${body}</li>`;
41
+ }
42
+ const DEFAULT_HEIGHT = '16rem';
43
+ const DEFAULT_TEMPLATES = Object.freeze(Object.assign({}, _collection.default.defaultTemplates, {
44
+ item
45
+ }));
46
+ const TYPE = 'gallery';
47
+ const DEFAULT_CLASSNAME = 'miso-gallery';
48
+ class GalleryLayout extends _collection.default {
49
+ static get type() {
50
+ return TYPE;
51
+ }
52
+ static get defaultTemplates() {
53
+ return DEFAULT_TEMPLATES;
54
+ }
55
+ static get defaultClassName() {
56
+ return DEFAULT_CLASSNAME;
57
+ }
58
+ constructor() {
59
+ let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
60
+ let {
61
+ className = DEFAULT_CLASSNAME,
62
+ templates
63
+ } = _ref,
64
+ options = _objectWithoutPropertiesLoose(_ref, _excluded);
65
+ super(Object.assign({
66
+ className,
67
+ templates: Object.assign({}, DEFAULT_TEMPLATES, templates)
68
+ }, options));
69
+ this._galleryContext = {
70
+ itemAspectRatio: undefined,
71
+ itemCount: undefined,
72
+ columnCount: undefined
73
+ };
74
+ }
75
+ syncSize() {
76
+ const {
77
+ element
78
+ } = this._view;
79
+ const listElement = element && this._getListElement(element);
80
+ if (!listElement) {
81
+ return;
82
+ }
83
+ this._syncListAspectRatio(listElement);
84
+ this._syncItemSizes(listElement);
85
+ }
86
+ _preprocess(_ref2) {
87
+ let {
88
+ state,
89
+ rendered
90
+ } = _ref2;
91
+ const incremental = this._shallRenderIncrementally(state, rendered);
92
+ const bodyHtml = incremental ? undefined : this._bodyHtml(state);
93
+ const itemsHtml = this._itemsHtml(state, rendered);
94
+ return Object.assign({}, state, (0, _commons.trimObj)({
95
+ incremental,
96
+ bodyHtml,
97
+ itemsHtml
98
+ }));
99
+ }
100
+ _bodyHtml(state) {
101
+ return this.templates.root(this, Object.assign({}, state, {
102
+ value: []
103
+ }));
104
+ }
105
+ _itemsHtml(state, rendered) {
106
+ const offset = rendered && rendered.value && rendered.value.length || 0;
107
+ const values = (this._getItems(state) || []).slice(offset);
108
+ return values.length > 0 ? this.templates.items(this, state, values, {
109
+ offset
110
+ }) : '';
111
+ }
112
+ _render(element, states, controls) {
113
+ this._syncItemCount(states);
114
+ this._syncCssVariables();
115
+ const listElement = this._renderListElement(element, states, controls);
116
+ if (!listElement) {
117
+ return;
118
+ }
119
+ this._syncListAspectRatio(listElement);
120
+ this._renderItems(listElement, states, controls);
121
+ }
122
+ _renderListElement(element, _ref3) {
123
+ let {
124
+ state
125
+ } = _ref3;
126
+ const {
127
+ incremental,
128
+ bodyHtml
129
+ } = state;
130
+ if (!incremental) {
131
+ element.innerHTML = bodyHtml;
132
+ }
133
+ return this._getListElement(element);
134
+ }
135
+ _renderItems(listElement, states) {
136
+ if (states.state.incremental) {
137
+ this._appendItems(listElement, states);
138
+ } else {
139
+ this._updateItems(listElement, states);
140
+ }
141
+ }
142
+ _updateItems(listElement, _ref4) {
143
+ let {
144
+ state
145
+ } = _ref4;
146
+ const {
147
+ itemSizes
148
+ } = this._galleryContext;
149
+ const values = this._writeItemSizes(this._getItems(state), itemSizes);
150
+ listElement.innerHTML = this.templates.items(this, state, values);
151
+ }
152
+ _appendItems(listElement, _ref5) {
153
+ let {
154
+ state
155
+ } = _ref5;
156
+ const {
157
+ itemSizes
158
+ } = this._galleryContext;
159
+ // update existing items
160
+ this._syncItemSizes(listElement);
161
+ // append new items
162
+ const offset = listElement.children.length;
163
+ const values = this._writeItemSizes(this._getItems(state).slice(offset), itemSizes, offset);
164
+ listElement.insertAdjacentHTML('beforeend', this.templates.items(this, state, values, {
165
+ offset
166
+ }));
167
+ }
168
+ _writeItemSizes() {
169
+ let values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
170
+ let [large = 0, medium = 0] = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
171
+ let offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
172
+ let omitted = 0;
173
+ if (offset > 0) {
174
+ omitted = Math.min(offset, large);
175
+ offset -= omitted;
176
+ large -= omitted;
177
+ }
178
+ if (offset > 0) {
179
+ omitted = Math.min(offset, medium);
180
+ offset -= omitted;
181
+ medium -= omitted;
182
+ }
183
+ const results = [];
184
+ for (const value of values) {
185
+ let _size = 'small';
186
+ if (large > 0) {
187
+ _size = 'large';
188
+ large--;
189
+ } else if (medium > 0) {
190
+ _size = 'medium';
191
+ medium--;
192
+ }
193
+ results.push(Object.assign({}, value, {
194
+ _size
195
+ }));
196
+ }
197
+ return results;
198
+ }
199
+ _syncCssVariables() {
200
+ const context = this._galleryContext;
201
+ let {
202
+ itemAspectRatio = 1,
203
+ height = DEFAULT_HEIGHT
204
+ } = this.options;
205
+ itemAspectRatio = context.itemAspectRatio = (0, _dom.cssAspectRatio)(itemAspectRatio);
206
+ const {
207
+ element
208
+ } = this._view;
209
+ if (!element) {
210
+ return;
211
+ }
212
+ // TODO: skip if equal to default values
213
+ element.style.setProperty('--miso-gallery-height', `${height}`);
214
+ element.style.setProperty('--miso-gallery-item-1x1-aspect-ratio', `${itemAspectRatio}`);
215
+ element.style.setProperty('--miso-gallery-item-1x2-aspect-ratio', `${itemAspectRatio.scaleBy([1, 2])}`);
216
+ }
217
+ _syncListAspectRatio(listElement) {
218
+ const context = this._galleryContext;
219
+ const {
220
+ itemCount,
221
+ itemAspectRatio
222
+ } = context;
223
+ const {
224
+ height = DEFAULT_HEIGHT
225
+ } = this.options;
226
+ const resolvedHeight = (0, _dom.resolveCssLength)(height);
227
+ const width = listElement.clientWidth;
228
+ if (width === 0) {
229
+ context.columnCount = undefined;
230
+ context.itemSizes = undefined;
231
+ return; // probably not visible yet
232
+ }
233
+ const columnCount = context.columnCount = Math.round(width * itemAspectRatio.width * 2 / (resolvedHeight * itemAspectRatio.height));
234
+ context.itemSizes = calculateItemSizes(itemCount, columnCount);
235
+
236
+ // update DOM
237
+ listElement.style.aspectRatio = `${columnCount} / 2`;
238
+ listElement.style.height = 'auto';
239
+ }
240
+ _syncItemCount() {
241
+ let {
242
+ state
243
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
244
+ const items = this._getItems(state);
245
+ this._galleryContext.itemCount = items ? items.length : undefined;
246
+ }
247
+ _syncItemSizes(listElement) {
248
+ const {
249
+ itemSizes = []
250
+ } = this._galleryContext;
251
+ let [large = 0, medium = 0] = itemSizes;
252
+ const {
253
+ className
254
+ } = this;
255
+
256
+ // update DOM
257
+ for (const itemElement of listElement.children) {
258
+ let lg = false,
259
+ md = false;
260
+ if (large > 0) {
261
+ lg = true;
262
+ large--;
263
+ } else if (medium > 0) {
264
+ md = true;
265
+ medium--;
266
+ }
267
+ (0, _dom.addOrRemoveClass)(itemElement, `${className}__item-large`, lg);
268
+ (0, _dom.addOrRemoveClass)(itemElement, `${className}__item-medium`, md);
269
+ (0, _dom.addOrRemoveClass)(itemElement, `${className}__item-small`, !lg && !md);
270
+ }
271
+ }
272
+ }
273
+ exports.default = GalleryLayout;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.SwipeableMixin = void 0;
7
7
  exports.makeSwipeable = makeSwipeable;
8
8
  var _commons = require("@miso.ai/commons");
9
+ var _dom = require("../../util/dom.js");
9
10
  function makeSwipeable(prototype) {
10
11
  (0, _commons.mixin)(prototype, SwipeableMixin.prototype);
11
12
  }
@@ -36,7 +37,7 @@ class SwipeableMixin {
36
37
  index = 0;
37
38
  }
38
39
  context.itemIndex = index;
39
- (0, _commons.requestAnimationFrame)(() => this._syncSwipeableItemIndex());
40
+ (0, _commons.requestAnimationFrame)(() => this._syncDisplayedSwipeableItemIndex());
40
41
  }
41
42
  next() {
42
43
  if (this._swipeableContext.itemCount === undefined) {
@@ -52,7 +53,8 @@ class SwipeableMixin {
52
53
  }
53
54
  _renderSwipeable(element, states, controls) {
54
55
  this._syncSwipeableItemCount(states);
55
- this._syncSwipeableItemIndex();
56
+ this._syncDisplayedSwipeableItemCount();
57
+ this._syncDisplayedSwipeableItemIndex();
56
58
  }
57
59
  _afterRenderSwipeable() {
58
60
  this._emitSwipeableDisplayEvent();
@@ -74,7 +76,6 @@ class SwipeableMixin {
74
76
  } else if (oldItemCount === undefined) {
75
77
  context.itemIndex = 0;
76
78
  }
77
- this._syncDisplayedSwipeableItemCount();
78
79
  }
79
80
  _syncDisplayedSwipeableItemCount() {
80
81
  const context = this._swipeableContext;
@@ -91,22 +92,20 @@ class SwipeableMixin {
91
92
  if (!element) {
92
93
  return;
93
94
  }
95
+ (0, _dom.setOrRemoveAttribute)(element, 'data-item-count', itemCount);
94
96
  context.displayedCount = itemCount;
95
- if (itemCount === undefined) {
96
- element.removeAttribute('data-item-count');
97
- } else {
98
- element.setAttribute('data-item-count', itemCount);
99
- }
100
97
  }
101
- _syncSwipeableItemIndex() {
98
+ _syncDisplayedSwipeableItemIndex() {
102
99
  const context = this._swipeableContext;
103
- const index = context.itemIndex;
104
- if (index === context.displayedIndex) {
100
+ const {
101
+ itemIndex
102
+ } = context;
103
+ if (itemIndex === context.displayedIndex) {
105
104
  return;
106
105
  }
107
- context.displayedIndex = index;
108
- this._syncSwipeableListIndex(index);
109
- this._syncSwipeableIndicatorIndex(index);
106
+ context.displayedIndex = itemIndex;
107
+ this._syncSwipeableListIndex(itemIndex);
108
+ this._syncSwipeableIndicatorIndex(itemIndex);
110
109
  }
111
110
  _syncSwipeableListIndex(index) {
112
111
  const {
@@ -128,7 +127,7 @@ class SwipeableMixin {
128
127
  }
129
128
  let i = 0;
130
129
  for (const item of indicatorElement.children) {
131
- item.classList[i === index ? 'add' : 'remove']('active');
130
+ (0, _dom.addOrRemoveClass)(item, 'active', i === index);
132
131
  i++;
133
132
  }
134
133
  }
@@ -115,6 +115,8 @@ class RafLayout {
115
115
  state = Object.freeze(Object.assign({}, state, stateExtra.value));
116
116
  this._rendered.set(this._element, state);
117
117
  notifyUpdate && notifyUpdate(...argsForNotifyUpdate.value);
118
+
119
+ // TODO: should the signature be aligned with _render?
118
120
  this._afterRender(this._element, state);
119
121
  }
120
122
  _render() {
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addOrRemoveClass = addOrRemoveClass;
7
+ exports.cssAspectRatio = cssAspectRatio;
8
+ exports.resolveCssLength = resolveCssLength;
9
+ exports.setOrRemoveAttribute = setOrRemoveAttribute;
10
+ function setOrRemoveAttribute(element, name, value) {
11
+ if (value === undefined) {
12
+ element.removeAttribute(name);
13
+ } else {
14
+ element.setAttribute(name, value);
15
+ }
16
+ }
17
+ function addOrRemoveClass(element, name, add) {
18
+ if (add) {
19
+ element.classList.add(name);
20
+ } else {
21
+ element.classList.remove(name);
22
+ }
23
+ }
24
+ function resolveCssLength(str) {
25
+ if (typeof str === 'number') {
26
+ return str;
27
+ }
28
+ const [value, unit] = parseLength(str);
29
+ switch (unit) {
30
+ case '':
31
+ case 'px':
32
+ return value;
33
+ case 'rem':
34
+ return remToPx(value);
35
+ default:
36
+ throw new Error(`Unsupported unit: ${unit}`);
37
+ }
38
+ }
39
+ function parseLength(str) {
40
+ const match = str.match(/^([+-]?(?:\d+|\d*\.\d+))([a-z]*)$/);
41
+ if (!match) {
42
+ throw new Error(`Invalid length: ${str}`);
43
+ }
44
+ const value = parseFloat(match[1]);
45
+ const unit = match[2] || '';
46
+ return [value, unit];
47
+ }
48
+ function remToPx() {
49
+ let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
50
+ return value * parseFloat(getComputedStyle(document.documentElement).fontSize);
51
+ }
52
+ function cssAspectRatio(value) {
53
+ return value === undefined || value instanceof CssAspectRatio ? value : new CssAspectRatio(value);
54
+ }
55
+ class CssAspectRatio {
56
+ constructor(value) {
57
+ this._width = NaN;
58
+ this._height = NaN;
59
+ switch (typeof value) {
60
+ case 'number':
61
+ this._width = value;
62
+ this._height = 1;
63
+ break;
64
+ case 'object':
65
+ if (Array.isArray(value)) {
66
+ this._width = parseFloat(value[0]);
67
+ this._height = parseFloat(value[1]);
68
+ }
69
+ break;
70
+ case 'string':
71
+ const i = value.indexOf('/');
72
+ if (i < 0) {
73
+ this._width = parseFloat(value);
74
+ this._height = 1;
75
+ } else {
76
+ this._width = parseFloat(value.slice(0, i).trim());
77
+ this._height = parseFloat(value.slice(i + 1).trim());
78
+ }
79
+ break;
80
+ }
81
+ if (this._width === NaN || this._height === NaN) {
82
+ throw new Error(`Invalid aspect ratio value: ${value}`);
83
+ }
84
+ }
85
+ get width() {
86
+ return this._width;
87
+ }
88
+ get height() {
89
+ return this._height;
90
+ }
91
+ get floatValue() {
92
+ return this._width / this._height;
93
+ }
94
+ scaleBy(factor) {
95
+ factor = cssAspectRatio(factor);
96
+ return cssAspectRatio([factor._width * this._width, factor._height * this._height]);
97
+ }
98
+ toString() {
99
+ return this._height === 1 ? `${this._width}` : `${this._width} / ${this._height}`;
100
+ }
101
+ }
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '1.11.5-beta.1';
7
+ var _default = exports.default = '1.11.5-beta.3';
@@ -43,7 +43,7 @@ const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LA
43
43
  }],
44
44
  [_constants.ROLE.ANSWER]: _index2.TypewriterLayout.type,
45
45
  [_constants.ROLE.FEEDBACK]: _index2.FeedbackLayout.type,
46
- [_constants.ROLE.IMAGES]: [_index2.CarouselLayout.type, {
46
+ [_constants.ROLE.IMAGES]: [_index2.GalleryLayout.type, {
47
47
  incremental: true,
48
48
  itemType: 'image'
49
49
  }],
@@ -137,8 +137,7 @@ class Explore extends _base.default {
137
137
  const related_questions = value.related_questions.map(linkFn ? text => ({
138
138
  text,
139
139
  url: this._getSubmitUrl({
140
- q: text
141
- }, {
140
+ q: text,
142
141
  generated: true
143
142
  })
144
143
  }) : text => ({
@@ -166,14 +165,13 @@ class Explore extends _base.default {
166
165
  this._hub.update(_index.fields.query(), args);
167
166
  }
168
167
  _query(args) {
169
- this._submitToPage(args);
168
+ this._submitToPage(Object.assign({}, args, {
169
+ generated: false
170
+ }));
170
171
  }
171
172
  _getSubmitUrl(args) {
172
- let {
173
- generated = false
174
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
175
173
  let url = _useLink.UseLinkMixin.prototype._getSubmitUrl.call(this, args);
176
- if (!generated || !this._productId) {
174
+ if (!args.generated || !this._productId) {
177
175
  return url;
178
176
  }
179
177
  return `${url}&qs=${encodeURIComponent(this._productId)}`;