@miso.ai/client-sdk-ui 1.11.0-beta.9 → 1.11.1-beta.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 (111) hide show
  1. package/dist/cjs/actor/feedback.js +6 -39
  2. package/dist/cjs/actor/fields.js +14 -6
  3. package/dist/cjs/actor/index.js +0 -7
  4. package/dist/cjs/actor/interactions.js +4 -15
  5. package/dist/cjs/actor/sessions.js +2 -32
  6. package/dist/cjs/actor/tracker.js +25 -26
  7. package/dist/cjs/actor/utils.js +0 -49
  8. package/dist/cjs/actor/view.js +40 -40
  9. package/dist/cjs/actor/views.js +29 -8
  10. package/dist/cjs/constants.js +18 -19
  11. package/dist/cjs/defaults/hybrid-search/phrases.js +3 -3
  12. package/dist/cjs/defaults/hybrid-search/templates.js +22 -7
  13. package/dist/cjs/element/role/index.js +12 -5
  14. package/dist/cjs/element/role/{miso-hits.js → miso-more.js} +4 -4
  15. package/dist/cjs/element/role/miso-total.js +20 -0
  16. package/dist/cjs/layout/affiliation/affiliation.js +0 -3
  17. package/dist/cjs/layout/banner/banner.js +0 -4
  18. package/dist/cjs/layout/button/more-button.js +73 -0
  19. package/dist/cjs/layout/container/container.js +0 -3
  20. package/dist/cjs/layout/error/error.js +0 -4
  21. package/dist/cjs/layout/index.js +7 -0
  22. package/dist/cjs/layout/input/facets.js +0 -4
  23. package/dist/cjs/layout/input/option-list.js +0 -4
  24. package/dist/cjs/layout/input/search-box.js +13 -12
  25. package/dist/cjs/layout/list/cards.js +0 -3
  26. package/dist/cjs/layout/list/carousel.js +0 -3
  27. package/dist/cjs/layout/list/collection.js +22 -7
  28. package/dist/cjs/layout/list/list.js +0 -3
  29. package/dist/cjs/layout/radio/feedback.js +0 -3
  30. package/dist/cjs/layout/radio/radio.js +0 -4
  31. package/dist/cjs/layout/raf.js +4 -2
  32. package/dist/cjs/layout/text/text.js +0 -4
  33. package/dist/cjs/layout/text/typewriter/index.js +0 -3
  34. package/dist/cjs/layout/triggerable.js +79 -0
  35. package/dist/cjs/util/states.js +0 -15
  36. package/dist/cjs/version.js +1 -1
  37. package/dist/cjs/workflow/answer-based.js +70 -105
  38. package/dist/cjs/workflow/ask.js +29 -27
  39. package/dist/cjs/workflow/asks.js +1 -1
  40. package/dist/cjs/workflow/autocompletable.js +33 -0
  41. package/dist/cjs/workflow/autocomplete.js +122 -0
  42. package/dist/cjs/workflow/base.js +156 -98
  43. package/dist/cjs/workflow/explore.js +48 -46
  44. package/dist/cjs/workflow/hybrid-search-answer.js +17 -7
  45. package/dist/cjs/workflow/hybrid-search-results.js +17 -87
  46. package/dist/cjs/workflow/hybrid-search-views.js +122 -0
  47. package/dist/cjs/workflow/hybrid-search.js +47 -168
  48. package/dist/cjs/workflow/options.js +32 -17
  49. package/dist/cjs/workflow/processors.js +166 -2
  50. package/dist/cjs/workflow/recommendation.js +36 -49
  51. package/dist/cjs/workflow/search-based.js +228 -0
  52. package/dist/cjs/workflow/search.js +21 -68
  53. package/dist/cjs/workflow/use-link.js +44 -0
  54. package/package.json +2 -2
  55. package/src/actor/feedback.js +6 -23
  56. package/src/actor/fields.js +14 -6
  57. package/src/actor/index.js +0 -1
  58. package/src/actor/interactions.js +4 -10
  59. package/src/actor/sessions.js +3 -31
  60. package/src/actor/tracker.js +25 -19
  61. package/src/actor/utils.js +0 -47
  62. package/src/actor/view.js +27 -15
  63. package/src/actor/views.js +32 -8
  64. package/src/constants.js +25 -16
  65. package/src/defaults/hybrid-search/phrases.js +2 -2
  66. package/src/defaults/hybrid-search/templates.js +17 -5
  67. package/src/element/role/index.js +2 -1
  68. package/src/element/role/{miso-hits.js → miso-more.js} +3 -3
  69. package/src/element/role/miso-total.js +16 -0
  70. package/src/layout/affiliation/affiliation.js +1 -5
  71. package/src/layout/banner/banner.js +0 -5
  72. package/src/layout/button/more-button.js +69 -0
  73. package/src/layout/container/container.js +1 -5
  74. package/src/layout/error/error.js +0 -5
  75. package/src/layout/index.js +2 -1
  76. package/src/layout/input/facets.js +0 -5
  77. package/src/layout/input/option-list.js +0 -5
  78. package/src/layout/input/search-box.js +11 -14
  79. package/src/layout/list/cards.js +0 -4
  80. package/src/layout/list/carousel.js +0 -4
  81. package/src/layout/list/collection.js +21 -9
  82. package/src/layout/list/list.js +0 -4
  83. package/src/layout/radio/feedback.js +0 -4
  84. package/src/layout/radio/radio.js +0 -5
  85. package/src/layout/raf.js +2 -2
  86. package/src/layout/text/text.js +0 -5
  87. package/src/layout/text/typewriter/index.js +1 -5
  88. package/src/layout/triggerable.js +76 -0
  89. package/src/util/states.js +0 -14
  90. package/src/version.js +1 -1
  91. package/src/workflow/answer-based.js +61 -72
  92. package/src/workflow/ask.js +30 -24
  93. package/src/workflow/asks.js +1 -1
  94. package/src/workflow/autocompletable.js +29 -0
  95. package/src/workflow/autocomplete.js +113 -0
  96. package/src/workflow/base.js +133 -87
  97. package/src/workflow/explore.js +38 -30
  98. package/src/workflow/hybrid-search-answer.js +17 -6
  99. package/src/workflow/hybrid-search-results.js +17 -77
  100. package/src/workflow/hybrid-search-views.js +124 -0
  101. package/src/workflow/hybrid-search.js +47 -157
  102. package/src/workflow/options.js +26 -11
  103. package/src/workflow/processors.js +151 -3
  104. package/src/workflow/recommendation.js +32 -33
  105. package/src/workflow/search-based.js +222 -0
  106. package/src/workflow/search.js +21 -65
  107. package/src/workflow/use-link.js +40 -0
  108. package/dist/cjs/actor/autocomplete.js +0 -160
  109. package/dist/cjs/workflow/utils.js +0 -42
  110. package/src/actor/autocomplete.js +0 -133
  111. package/src/workflow/utils.js +0 -29
@@ -11,6 +11,7 @@ export { default as MisoRelatedResourcesElement } from './miso-related-resources
11
11
  export { default as MisoRelatedQuestionsElement } from './miso-related-questions.js';
12
12
  export { default as MisoSovrnAffiliationElement } from './miso-affiliation.js';
13
13
  export { default as MisoKeywordsElement } from './miso-keywords.js';
14
- export { default as MisoHitsElement } from './miso-hits.js';
14
+ export { default as MisoTotalElement } from './miso-total.js';
15
15
  export { default as MisoFacetsElement } from './miso-facets.js';
16
+ export { default as MisoMoreElement } from './miso-more.js';
16
17
  export { default as MisoErrorElement } from './miso-error.js';
@@ -1,16 +1,16 @@
1
1
  import MisoComponentElement from './miso-component.js';
2
2
  import { ROLE } from '../../constants.js';
3
3
 
4
- export default class MisoHitsElement extends MisoComponentElement {
4
+ export default class MisoMoreElement extends MisoComponentElement {
5
5
 
6
6
  constructor() {
7
7
  super({
8
- role: ROLE.HITS,
8
+ role: ROLE.MORE,
9
9
  });
10
10
  }
11
11
 
12
12
  static get tagName() {
13
- return 'miso-hits';
13
+ return 'miso-more';
14
14
  }
15
15
 
16
16
  }
@@ -0,0 +1,16 @@
1
+ import MisoComponentElement from './miso-component.js';
2
+ import { ROLE } from '../../constants.js';
3
+
4
+ export default class MisoTotalElement extends MisoComponentElement {
5
+
6
+ constructor() {
7
+ super({
8
+ role: ROLE.TOTAL,
9
+ });
10
+ }
11
+
12
+ static get tagName() {
13
+ return 'miso-total';
14
+ }
15
+
16
+ }
@@ -1,5 +1,5 @@
1
1
  import { CarouselItemViewabilityObserver, requestAnimationFrame as raf } from '@miso.ai/commons';
2
- import { STATUS, LAYOUT_CATEGORY } from '../../constants.js';
2
+ import { STATUS } from '../../constants.js';
3
3
  import CollectionLayout from '../list/collection.js';
4
4
  import { affiliation, helpers } from '../templates.js';
5
5
  import { TRIANGLE } from '../../asset/svgs.js';
@@ -136,10 +136,6 @@ function autoplayOptionsEquals(a, b) {
136
136
 
137
137
  export default class AffiliationLayout extends CollectionLayout {
138
138
 
139
- static get category() {
140
- return LAYOUT_CATEGORY.AFFILIATION;
141
- }
142
-
143
139
  static get type() {
144
140
  return TYPE;
145
141
  }
@@ -1,4 +1,3 @@
1
- import { LAYOUT_CATEGORY } from '../../constants.js';
2
1
  import TemplateBasedLayout from '../template.js';
3
2
  import { LOGO } from '../svgs.js';
4
3
 
@@ -19,10 +18,6 @@ const DEFAULT_TEMPLATES = Object.freeze({
19
18
 
20
19
  export default class BannerLayout extends TemplateBasedLayout {
21
20
 
22
- static get category() {
23
- return LAYOUT_CATEGORY.BANNER;
24
- }
25
-
26
21
  static get type() {
27
22
  return TYPE;
28
23
  }
@@ -0,0 +1,69 @@
1
+ import { STATUS } from '../../constants.js';
2
+ import { fields } from '../../actor/index.js';
3
+ import TemplateBasedLayout from '../template.js';
4
+
5
+ const TYPE = 'more-button';
6
+ const DEFAULT_CLASSNAME = 'miso-more-button';
7
+
8
+ function root(layout, state) {
9
+ const { className, role, templates } = layout;
10
+ const roleAttr = role ? ` data-role="${role}"` : '';
11
+ const disabledAttr = state.status !== STATUS.READY ? ' disabled' : '';
12
+ return `
13
+ <div class="${className}"${roleAttr}${disabledAttr}>
14
+ ${templates.text(layout)}
15
+ </div>
16
+ `;
17
+ }
18
+
19
+ const DEFAULT_TEMPLATES = Object.freeze({
20
+ root,
21
+ text,
22
+ });
23
+
24
+ function text(layout) {
25
+ return 'More';
26
+ }
27
+
28
+ export default class MoreButtonLayout extends TemplateBasedLayout {
29
+
30
+ static get type() {
31
+ return TYPE;
32
+ }
33
+
34
+ static get defaultTemplates() {
35
+ return DEFAULT_TEMPLATES;
36
+ }
37
+
38
+ static get defaultClassName() {
39
+ return DEFAULT_CLASSNAME;
40
+ }
41
+
42
+ constructor({ className = DEFAULT_CLASSNAME, templates, ...options } = {}) {
43
+ super({
44
+ className,
45
+ templates: { ...DEFAULT_TEMPLATES, ...templates },
46
+ ...options,
47
+ });
48
+ }
49
+
50
+ initialize(view) {
51
+ this._unsubscribes = [
52
+ ...this._unsubscribes,
53
+ view.proxyElement.on('click', (e) => this._handleClick(e)),
54
+ ];
55
+ }
56
+
57
+ _handleClick(event) {
58
+ // only left click
59
+ if (event.button !== 0) {
60
+ return;
61
+ }
62
+ const button = event.target.closest('data-role="more"');
63
+ if (!button || button.disabled) {
64
+ return;
65
+ }
66
+ this._view.hub.trigger(fields.more());
67
+ }
68
+
69
+ }
@@ -1,4 +1,4 @@
1
- import { ROLE, STATUS, LAYOUT_CATEGORY } from '../../constants.js';
1
+ import { ROLE, STATUS } from '../../constants.js';
2
2
  import RafLayout from '../raf.js';
3
3
  import MisoBannerElement from '../../element/miso-banner.js';
4
4
  import Viewables from '../../util/viewables.js';
@@ -7,10 +7,6 @@ const TYPE = 'container';
7
7
 
8
8
  export default class ContainerLayout extends RafLayout {
9
9
 
10
- static get category() {
11
- return LAYOUT_CATEGORY.CONTAINER;
12
- }
13
-
14
10
  static get type() {
15
11
  return TYPE;
16
12
  }
@@ -1,4 +1,3 @@
1
- import { LAYOUT_CATEGORY } from '../../constants.js';
2
1
  import TemplateBasedLayout from '../template.js';
3
2
 
4
3
  const TYPE = 'error';
@@ -24,10 +23,6 @@ const DEFAULT_TEMPLATES = Object.freeze({
24
23
 
25
24
  export default class ErrorLayout extends TemplateBasedLayout {
26
25
 
27
- static get category() {
28
- return LAYOUT_CATEGORY.ERROR;
29
- }
30
-
31
26
  static get type() {
32
27
  return TYPE;
33
28
  }
@@ -12,4 +12,5 @@ export { default as FeedbackLayout } from './radio/feedback.js';
12
12
  export { default as TextLayout } from './text/text.js';
13
13
  export { default as TypewriterLayout } from './text/typewriter/index.js';
14
14
  export { default as AffiliationLayout } from './affiliation/affiliation.js';
15
- export { default as FacetsLayout } from './input/facets.js';
15
+ export { default as FacetsLayout } from './input/facets.js';
16
+ export { default as MoreButtonLayout } from './button/more-button.js';
@@ -1,5 +1,4 @@
1
1
  import { escapeHtml } from '@miso.ai/commons';
2
- import { LAYOUT_CATEGORY } from '../../constants.js';
3
2
  import TemplateBasedLayout from '../template.js';
4
3
  import Bindings from '../../util/bindings.js';
5
4
 
@@ -88,10 +87,6 @@ function getSelectedValues(facets) {
88
87
 
89
88
  export default class FacetsLayout extends TemplateBasedLayout {
90
89
 
91
- static get category() {
92
- return LAYOUT_CATEGORY.FILTERS;
93
- }
94
-
95
90
  static get type() {
96
91
  return TYPE;
97
92
  }
@@ -1,5 +1,4 @@
1
1
  import { escapeHtml } from '@miso.ai/commons';
2
- import { LAYOUT_CATEGORY } from '../../constants.js';
3
2
  import { fields } from '../../actor/index.js';
4
3
  import TemplateBasedLayout from '../template.js';
5
4
  import { makeTrackable } from '../trackable.js';
@@ -41,10 +40,6 @@ const DEFAULT_TEMPLATES = Object.freeze({
41
40
 
42
41
  export default class OptionListLayout extends TemplateBasedLayout {
43
42
 
44
- static get category() {
45
- return LAYOUT_CATEGORY.QUERY;
46
- }
47
-
48
43
  static get type() {
49
44
  return TYPE;
50
45
  }
@@ -1,5 +1,5 @@
1
1
  import { defineValues, escapeHtml, findInAncestors, debounce } from '@miso.ai/commons';
2
- import { LAYOUT_CATEGORY, STATUS, EVENT_TYPE, DATA_ASPECT } from '../../constants.js';
2
+ import { STATUS, EVENT_TYPE } from '../../constants.js';
3
3
  import { fields } from '../../actor/index.js';
4
4
  import TemplateBasedLayout from '../template.js';
5
5
  import { imageBlock, productInfoBlock } from '../templates.js';
@@ -78,10 +78,7 @@ function product(layout, { product }) {
78
78
 
79
79
  function completionList(layout, type, items) {
80
80
  const { className, templates } = layout;
81
- return `
82
- <ul class="${className}__${type}-list" data-role="${type}-list">
83
- ${items.map(item => templates.completionItem(layout, type, item)).join('')}
84
- </ul>`.trim();
81
+ return `<ul class="${className}__${type}-list" data-role="${type}-list">${items.map(item => templates.completionItem(layout, type, item)).join('')}</ul>`;
85
82
  }
86
83
 
87
84
  function completionItem(layout, type, item) {
@@ -115,10 +112,6 @@ const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
115
112
 
116
113
  export default class SearchBoxLayout extends TemplateBasedLayout {
117
114
 
118
- static get category() {
119
- return LAYOUT_CATEGORY.QUERY;
120
- }
121
-
122
115
  static get type() {
123
116
  return TYPE;
124
117
  }
@@ -154,7 +147,7 @@ export default class SearchBoxLayout extends TemplateBasedLayout {
154
147
  proxyElement.on('click', (e) => this._handleClick(e)),
155
148
  proxyElement.on('focusin', (e) => this._handleFocusIn(e)),
156
149
  proxyElement.on('focusout', (e) => this._handleFocusOut(e)),
157
- hub.on(fields.data(DATA_ASPECT.AUTOCOMPLETE), () => view.refresh({ force: true })),
150
+ hub.on(fields.completions(), () => view.refresh({ force: true })),
158
151
  ];
159
152
  }
160
153
 
@@ -188,7 +181,7 @@ export default class SearchBoxLayout extends TemplateBasedLayout {
188
181
  state = super._preprocess({ state });
189
182
  return {
190
183
  ...state,
191
- completions: this._view.hub.states[fields.data(DATA_ASPECT.AUTOCOMPLETE)],
184
+ completions: this._view.hub.states[fields.completions()],
192
185
  };
193
186
  }
194
187
 
@@ -198,6 +191,9 @@ export default class SearchBoxLayout extends TemplateBasedLayout {
198
191
  super._render(element, data, controls);
199
192
  }
200
193
  this._updateCompletions(element, data, controls);
194
+ }
195
+
196
+ _afterRender(element, state) {
201
197
  this._fullfillFocusRequest(element);
202
198
  this._fullfillValueRequest(element);
203
199
  }
@@ -206,7 +202,8 @@ export default class SearchBoxLayout extends TemplateBasedLayout {
206
202
  if (!state.completions) {
207
203
  return;
208
204
  }
209
- const { status = STATUS.INITIAL, index, value: completions } = state.completions;
205
+ const { status = STATUS.INITIAL, session, value: completions } = state.completions;
206
+ const { index } = session;
210
207
  if (rendered && rendered.completions.index === index && rendered.completions.status === status) {
211
208
  return;
212
209
  }
@@ -289,7 +286,7 @@ export default class SearchBoxLayout extends TemplateBasedLayout {
289
286
  }
290
287
 
291
288
  _handleKeyDown({ key, target, isComposing }) {
292
- if (!isComposing && key === 'Enter' && target.matches('input')) {
289
+ if (!isComposing && key === 'Enter' && target.matches('[data-role="input"]')) {
293
290
  this._submit(target.value);
294
291
  target.blur();
295
292
  }
@@ -345,7 +342,7 @@ export default class SearchBoxLayout extends TemplateBasedLayout {
345
342
  if (!options) {
346
343
  return;
347
344
  }
348
- this._view.tracker.submit(value);
345
+ this._view.tracker.submit({ value }); // not array
349
346
  }
350
347
 
351
348
  }
@@ -5,10 +5,6 @@ const DEFAULT_CLASSNAME = 'miso-cards';
5
5
 
6
6
  export default class CardsLayout extends CollectionLayout {
7
7
 
8
- static get category() {
9
- return super.category;
10
- }
11
-
12
8
  static get type() {
13
9
  return TYPE;
14
10
  }
@@ -35,10 +35,6 @@ function chevron(layout) {
35
35
 
36
36
  export default class CarouselLayout extends CollectionLayout {
37
37
 
38
- static get category() {
39
- return super.category;
40
- }
41
-
42
38
  static get type() {
43
39
  return TYPE;
44
40
  }
@@ -1,13 +1,14 @@
1
- import { STATUS, LAYOUT_CATEGORY } from '../../constants.js';
1
+ import { STATUS } from '../../constants.js';
2
2
  import TemplateBasedLayout from '../template.js';
3
3
  import { makeTrackable } from '../trackable.js';
4
+ import { makeTriggerable } from '../triggerable.js';
4
5
  import { product, article, question, productInfoBlock, articleInfoBlock, titleBlock, brandBlock, descriptionBlock, dateBlock, priceBlock, discountRateText, ctaBlock, cta, imageBlock, indexBlock } from '../templates.js';
5
6
 
6
7
  function root(layout, state) {
7
8
  const { className, role, templates } = layout;
8
9
  const { status } = state;
9
10
  const roleAttr = role ? `data-role="${role}"` : '';
10
- return `<div class="${className} ${status}" ${roleAttr}>${status === STATUS.READY ? templates[status](layout, state) : ''}</div>`;
11
+ return `<div class="${className} ${status}" ${roleAttr}>${status === STATUS.READY ? templates[status](layout, state) : ''}${templates.trigger(layout, state)}${templates.loading(layout, state)}</div>`;
11
12
  }
12
13
 
13
14
  function ready(layout, state) {
@@ -15,7 +16,7 @@ function ready(layout, state) {
15
16
  const values = layout._getItems(state);
16
17
 
17
18
  // TODO: handle categories, attributes, etc. by introducing sublayout
18
- if ((values && values.length > 0) || state.ongoing) {
19
+ if ((values && values.length > 0) || state.ongoing) { // TODO: ad-hoc ongoing?
19
20
  return templates.list(layout, state, values);
20
21
  } else {
21
22
  return templates.empty(layout, state);
@@ -42,6 +43,15 @@ function item(layout, state, value, index) {
42
43
  return `<li class="${className}__item">${body}</li>`;
43
44
  }
44
45
 
46
+ function trigger(layout, state) {
47
+ const { className } = layout;
48
+ return `<div class="${className}__trigger" data-role="trigger"></div>`;
49
+ }
50
+
51
+ function loading() {
52
+ return `<div class="miso-loading" aria-label="Loading" data-role="loading"></div>`;
53
+ }
54
+
45
55
  // TODO: let templates.js control what to be included here
46
56
 
47
57
  const DEFAULT_TEMPLATES = Object.freeze({
@@ -67,14 +77,12 @@ const DEFAULT_TEMPLATES = Object.freeze({
67
77
  cta,
68
78
  imageBlock,
69
79
  indexBlock,
80
+ trigger,
81
+ loading,
70
82
  });
71
83
 
72
84
  export default class CollectionLayout extends TemplateBasedLayout {
73
85
 
74
- static get category() {
75
- return LAYOUT_CATEGORY.LIST;
76
- }
77
-
78
86
  static get defaultTemplates() {
79
87
  return DEFAULT_TEMPLATES;
80
88
  }
@@ -86,6 +94,7 @@ export default class CollectionLayout extends TemplateBasedLayout {
86
94
  ...options,
87
95
  });
88
96
  this._initTrackable();
97
+ this._initTriggerable();
89
98
  }
90
99
 
91
100
  initialize(view) {
@@ -106,8 +115,7 @@ export default class CollectionLayout extends TemplateBasedLayout {
106
115
  // TODO: compare item ids as well
107
116
  return this.options.incremental &&
108
117
  rendered && rendered.value && rendered.value.length > 0 &&
109
- state.status === STATUS.READY &&
110
- rendered.status === STATUS.READY &&
118
+ state.value && state.value.length >= rendered.value.length &&
111
119
  state.session && rendered.session &&
112
120
  state.session.id === rendered.session.id;
113
121
  }
@@ -138,10 +146,12 @@ export default class CollectionLayout extends TemplateBasedLayout {
138
146
 
139
147
  _afterRender(element, state) {
140
148
  this._syncBindings(element, state);
149
+ this._syncTrigger(element, state);
141
150
  }
142
151
 
143
152
  _unrender() {
144
153
  this._clearBindings();
154
+ this._untrackTrigger();
145
155
  }
146
156
 
147
157
  _getItems(state) {
@@ -177,6 +187,7 @@ export default class CollectionLayout extends TemplateBasedLayout {
177
187
 
178
188
  destroy() {
179
189
  this._destroyTrackable();
190
+ this._destroyTriggerable();
180
191
  this._view = undefined;
181
192
  super.destroy();
182
193
  }
@@ -184,3 +195,4 @@ export default class CollectionLayout extends TemplateBasedLayout {
184
195
  }
185
196
 
186
197
  makeTrackable(CollectionLayout.prototype);
198
+ makeTriggerable(CollectionLayout.prototype);
@@ -5,10 +5,6 @@ const DEFAULT_CLASSNAME = 'miso-list';
5
5
 
6
6
  export default class ListLayout extends CollectionLayout {
7
7
 
8
- static get category() {
9
- return super.category;
10
- }
11
-
12
8
  static get type() {
13
9
  return TYPE;
14
10
  }
@@ -50,10 +50,6 @@ const DEFAULT_TEMPLATES = Object.freeze({
50
50
 
51
51
  export default class FeedbackLayout extends RadioLayout {
52
52
 
53
- static get category() {
54
- return super.category;
55
- }
56
-
57
53
  static get type() {
58
54
  return TYPE;
59
55
  }
@@ -1,5 +1,4 @@
1
1
  import { findInAncestors, requestAnimationFrame as raf } from '@miso.ai/commons';
2
- import { LAYOUT_CATEGORY } from '../../constants.js';
3
2
  import TemplateBasedLayout from '../template.js';
4
3
  import { requiresImplementation } from '../templates.js';
5
4
 
@@ -30,10 +29,6 @@ const DEFAULT_TEMPLATES = Object.freeze({
30
29
 
31
30
  export default class RadioLayout extends TemplateBasedLayout {
32
31
 
33
- static get category() {
34
- return LAYOUT_CATEGORY.RADIO;
35
- }
36
-
37
32
  static get defaultTemplates() {
38
33
  return DEFAULT_TEMPLATES;
39
34
  }
package/src/layout/raf.js CHANGED
@@ -2,8 +2,8 @@ import { defineValues, requestAnimationFrame as raf, capture } from '@miso.ai/co
2
2
 
3
3
  export default class RafLayout {
4
4
 
5
- constructor({ role, workflow, ...options } = {}) {
6
- defineValues(this, { role, workflow, options });
5
+ constructor({ role, workflow, workflowOptions, ...options } = {}) {
6
+ defineValues(this, { role, workflow, workflowOptions, options });
7
7
  this._unsubscribes = [];
8
8
  this._rendered = new WeakMap();
9
9
  this._element = undefined;
@@ -1,5 +1,4 @@
1
1
  import { escapeHtml } from '@miso.ai/commons';
2
- import { LAYOUT_CATEGORY } from '../../constants.js';
3
2
  import TemplateBasedLayout from '../template.js';
4
3
 
5
4
  const TYPE = 'text';
@@ -42,10 +41,6 @@ const DEFAULT_TEMPLATES = Object.freeze({
42
41
 
43
42
  export default class TextLayout extends TemplateBasedLayout {
44
43
 
45
- static get category() {
46
- return LAYOUT_CATEGORY.TEXT;
47
- }
48
-
49
44
  static get type() {
50
45
  return TYPE;
51
46
  }
@@ -1,5 +1,5 @@
1
1
  import { trimObj, defineValues, Resolution, pacer } from '@miso.ai/commons';
2
- import { LAYOUT_CATEGORY, STATUS } from '../../../constants.js';
2
+ import { STATUS } from '../../../constants.js';
3
3
  import ProgressiveLayout from '../../progressive.js';
4
4
  import PlaintextRenderer from './plaintext.js';
5
5
  import { containerElement, cursorClassName, fromSameSession, normalizeOnDebug } from './utils.js';
@@ -9,10 +9,6 @@ const DEFAULT_CLASSNAME = 'miso-typewriter';
9
9
 
10
10
  export default class TypewriterLayout extends ProgressiveLayout {
11
11
 
12
- static get category() {
13
- return LAYOUT_CATEGORY.TEXT;
14
- }
15
-
16
12
  static get type() {
17
13
  return TYPE;
18
14
  }
@@ -0,0 +1,76 @@
1
+ import { mixin, viewable as whenViewable } from '@miso.ai/commons';
2
+ import { STATUS } from '../constants.js';
3
+ import { fields } from '../actor/index.js';
4
+
5
+ export function makeTriggerable(prototype) {
6
+ mixin(prototype, TriggerableMixin.prototype);
7
+ }
8
+
9
+ export class TriggerableMixin {
10
+
11
+ _initTriggerable() {
12
+ this._trigger = undefined;
13
+ }
14
+
15
+ _syncTrigger(element, state) {
16
+ if (!this.options.infiniteScroll) {
17
+ return;
18
+ }
19
+ const workflowPaginationOptions = this.workflowOptions.pagination;
20
+ if (!workflowPaginationOptions.active || workflowPaginationOptions.mode !== 'infiniteScroll') {
21
+ return;
22
+ }
23
+ // only track trigger when ready
24
+ if (state.status === STATUS.READY) {
25
+ this._trackTrigger(element);
26
+ } else {
27
+ this._untrackTrigger();
28
+ }
29
+ }
30
+
31
+ async _trackTrigger(element) {
32
+ if (this._trigger) {
33
+ return;
34
+ }
35
+ const triggerElement = element.querySelector('[data-role="trigger"]');
36
+ if (!triggerElement) {
37
+ return;
38
+ }
39
+ const ac = new AbortController();
40
+ this._trigger = Object.freeze({
41
+ element: triggerElement,
42
+ ac,
43
+ });
44
+ let result = false;
45
+ try {
46
+ await whenViewable(triggerElement, { area: 1, duration: 0, signal: ac.signal });
47
+ result = true;
48
+ } catch (e) {
49
+ if (e.name !== 'AbortError') {
50
+ throw e;
51
+ }
52
+ } finally {
53
+ this._trigger = undefined;
54
+ }
55
+ if (result) {
56
+ this._onTrigger();
57
+ }
58
+ }
59
+
60
+ _onTrigger() {
61
+ this._view.hub.trigger(fields.more());
62
+ }
63
+
64
+ _untrackTrigger() {
65
+ if (!this._trigger) {
66
+ return;
67
+ }
68
+ this._trigger.ac && this._trigger.ac.abort();
69
+ this._trigger = undefined;
70
+ }
71
+
72
+ _destroyTriggerable() {
73
+ this._untrackTrigger();
74
+ }
75
+
76
+ }
@@ -4,20 +4,6 @@ import { EVENT_TYPE, TRACKING_STATUS, validateEventType, validateTrackingStatus
4
4
  const { IMPRESSION, VIEWABLE, CLICK } = EVENT_TYPE;
5
5
  const { UNTRACKED, TRIGGERED } = TRACKING_STATUS;
6
6
 
7
- /*
8
- const STATES = {
9
- NEW: Object.freeze({
10
- [IMPRESSION]: UNTRACKED,
11
- [VIEWABLE]: UNTRACKED,
12
- }),
13
- UNTRACKED: Object.freeze({
14
- [IMPRESSION]: UNTRACKED,
15
- [VIEWABLE]: UNTRACKED,
16
- [CLICK]: UNTRACKED,
17
- }),
18
- };
19
- */
20
-
21
7
  const UNTRACKED_STATES = Object.freeze({
22
8
  [IMPRESSION]: UNTRACKED,
23
9
  [VIEWABLE]: UNTRACKED,
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.11.0-beta.9';
1
+ export default '1.11.1-beta.0';