@miso.ai/client-sdk-ui 1.11.0-beta.0 → 1.11.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 (118) hide show
  1. package/dist/cjs/actor/data.js +6 -7
  2. package/dist/cjs/actor/feedback.js +6 -39
  3. package/dist/cjs/actor/fields.js +14 -6
  4. package/dist/cjs/actor/hub.js +1 -2
  5. package/dist/cjs/actor/index.js +0 -7
  6. package/dist/cjs/actor/interactions.js +4 -15
  7. package/dist/cjs/actor/sessions.js +2 -33
  8. package/dist/cjs/actor/tracker.js +25 -26
  9. package/dist/cjs/actor/utils.js +0 -49
  10. package/dist/cjs/actor/view.js +40 -40
  11. package/dist/cjs/actor/views.js +32 -8
  12. package/dist/cjs/asset/svgs.js +18 -8
  13. package/dist/cjs/constants.js +18 -19
  14. package/dist/cjs/defaults/hybrid-search/answer-box.js +19 -3
  15. package/dist/cjs/defaults/hybrid-search/phrases.js +5 -5
  16. package/dist/cjs/defaults/hybrid-search/templates.js +37 -9
  17. package/dist/cjs/element/role/index.js +12 -5
  18. package/dist/cjs/element/role/{miso-hits.js → miso-more.js} +4 -4
  19. package/dist/cjs/element/role/miso-total.js +20 -0
  20. package/dist/cjs/layout/affiliation/affiliation.js +0 -3
  21. package/dist/cjs/layout/banner/banner.js +0 -4
  22. package/dist/cjs/layout/button/more-button.js +73 -0
  23. package/dist/cjs/layout/container/container.js +0 -3
  24. package/dist/cjs/layout/error/error.js +0 -4
  25. package/dist/cjs/layout/index.js +7 -0
  26. package/dist/cjs/layout/input/facets.js +5 -5
  27. package/dist/cjs/layout/input/option-list.js +0 -4
  28. package/dist/cjs/layout/input/search-box.js +33 -12
  29. package/dist/cjs/layout/list/cards.js +0 -3
  30. package/dist/cjs/layout/list/carousel.js +0 -3
  31. package/dist/cjs/layout/list/collection.js +25 -7
  32. package/dist/cjs/layout/list/list.js +0 -3
  33. package/dist/cjs/layout/radio/feedback.js +0 -3
  34. package/dist/cjs/layout/radio/radio.js +0 -4
  35. package/dist/cjs/layout/raf.js +4 -2
  36. package/dist/cjs/layout/text/text.js +0 -4
  37. package/dist/cjs/layout/text/typewriter/index.js +3 -3
  38. package/dist/cjs/layout/triggerable.js +79 -0
  39. package/dist/cjs/util/states.js +0 -15
  40. package/dist/cjs/version.js +1 -1
  41. package/dist/cjs/workflow/answer-based.js +109 -111
  42. package/dist/cjs/workflow/ask.js +35 -27
  43. package/dist/cjs/workflow/asks.js +1 -1
  44. package/dist/cjs/workflow/autocompletable.js +33 -0
  45. package/dist/cjs/workflow/autocomplete.js +122 -0
  46. package/dist/cjs/workflow/base.js +169 -102
  47. package/dist/cjs/workflow/explore.js +26 -19
  48. package/dist/cjs/workflow/hybrid-search-answer.js +99 -0
  49. package/dist/cjs/workflow/hybrid-search-results.js +70 -0
  50. package/dist/cjs/workflow/hybrid-search-views.js +122 -0
  51. package/dist/cjs/workflow/hybrid-search.js +98 -103
  52. package/dist/cjs/workflow/options.js +32 -17
  53. package/dist/cjs/workflow/processors.js +185 -17
  54. package/dist/cjs/workflow/recommendation.js +36 -49
  55. package/dist/cjs/workflow/search-based.js +186 -0
  56. package/dist/cjs/workflow/search.js +21 -68
  57. package/package.json +2 -2
  58. package/src/actor/data.js +2 -4
  59. package/src/actor/feedback.js +6 -23
  60. package/src/actor/fields.js +14 -6
  61. package/src/actor/hub.js +1 -2
  62. package/src/actor/index.js +0 -1
  63. package/src/actor/interactions.js +4 -10
  64. package/src/actor/sessions.js +3 -30
  65. package/src/actor/tracker.js +25 -19
  66. package/src/actor/utils.js +0 -47
  67. package/src/actor/view.js +27 -15
  68. package/src/actor/views.js +36 -8
  69. package/src/asset/svgs.js +19 -7
  70. package/src/constants.js +25 -16
  71. package/src/defaults/hybrid-search/answer-box.js +17 -5
  72. package/src/defaults/hybrid-search/phrases.js +4 -4
  73. package/src/defaults/hybrid-search/templates.js +25 -9
  74. package/src/element/role/index.js +2 -1
  75. package/src/element/role/{miso-hits.js → miso-more.js} +3 -3
  76. package/src/element/role/miso-total.js +16 -0
  77. package/src/layout/affiliation/affiliation.js +1 -5
  78. package/src/layout/banner/banner.js +0 -5
  79. package/src/layout/button/more-button.js +69 -0
  80. package/src/layout/container/container.js +1 -5
  81. package/src/layout/error/error.js +0 -5
  82. package/src/layout/index.js +2 -1
  83. package/src/layout/input/facets.js +5 -6
  84. package/src/layout/input/option-list.js +0 -5
  85. package/src/layout/input/search-box.js +27 -14
  86. package/src/layout/list/cards.js +0 -4
  87. package/src/layout/list/carousel.js +0 -4
  88. package/src/layout/list/collection.js +22 -9
  89. package/src/layout/list/list.js +0 -4
  90. package/src/layout/radio/feedback.js +0 -4
  91. package/src/layout/radio/radio.js +0 -5
  92. package/src/layout/raf.js +2 -2
  93. package/src/layout/text/text.js +0 -5
  94. package/src/layout/text/typewriter/index.js +4 -5
  95. package/src/layout/trackable.js +1 -1
  96. package/src/layout/triggerable.js +76 -0
  97. package/src/util/states.js +0 -14
  98. package/src/version.js +1 -1
  99. package/src/workflow/answer-based.js +101 -77
  100. package/src/workflow/ask.js +33 -25
  101. package/src/workflow/asks.js +1 -1
  102. package/src/workflow/autocompletable.js +29 -0
  103. package/src/workflow/autocomplete.js +113 -0
  104. package/src/workflow/base.js +147 -93
  105. package/src/workflow/explore.js +23 -8
  106. package/src/workflow/hybrid-search-answer.js +92 -0
  107. package/src/workflow/hybrid-search-results.js +63 -0
  108. package/src/workflow/hybrid-search-views.js +124 -0
  109. package/src/workflow/hybrid-search.js +102 -73
  110. package/src/workflow/options.js +26 -11
  111. package/src/workflow/processors.js +165 -14
  112. package/src/workflow/recommendation.js +32 -33
  113. package/src/workflow/search-based.js +183 -0
  114. package/src/workflow/search.js +21 -65
  115. package/dist/cjs/actor/autocomplete.js +0 -160
  116. package/dist/cjs/workflow/utils.js +0 -42
  117. package/src/actor/autocomplete.js +0 -133
  118. package/src/workflow/utils.js +0 -29
@@ -3,8 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TRACKING_STATUS = exports.TRACKING_EVENT_TYPES = exports.STATUS = exports.ROLE = exports.ORGANIC_QUESTION_SOURCE = exports.LAYOUT_CATEGORY = exports.EVENT_TYPE = exports.DEFAULT_UNIT_ID = exports.DATA_ASPECT = exports.ATTR_DATA_MISO_UNIT_ID = exports.ATTR_DATA_MISO_PRODUCT_ID = void 0;
6
+ exports.TRACKING_STATUS = exports.TRACKING_EVENT_TYPES = exports.STATUS = exports.ROLE = exports.PERFORMANCE_EVENT_TYPES = exports.ORGANIC_QUESTION_SOURCE = exports.EVENT_TYPE = exports.DEFAULT_UNIT_ID = exports.ATTR_DATA_MISO_UNIT_ID = exports.ATTR_DATA_MISO_PRODUCT_ID = void 0;
7
7
  exports.isDataRole = isDataRole;
8
+ exports.isPerformanceEventType = isPerformanceEventType;
9
+ exports.isProductRole = isProductRole;
8
10
  exports.validateEventType = validateEventType;
9
11
  exports.validateTrackingStatus = validateTrackingStatus;
10
12
  const ATTR_DATA_MISO_UNIT_ID = exports.ATTR_DATA_MISO_UNIT_ID = `data-miso-unit-id`;
@@ -30,34 +32,31 @@ const ROLE = exports.ROLE = Object.freeze({
30
32
  AFFILIATION: 'affiliation',
31
33
  KEYWORDS: 'keywords',
32
34
  FACETS: 'facets',
33
- HITS: 'hits',
35
+ TOTAL: 'total',
36
+ MORE: 'more',
34
37
  ERROR: 'error'
35
38
  });
36
- const DATA_ROLE_SET = new Set([ROLE.PRODUCTS, ROLE.CATEGORIES, ROLE.ATTRIBUTES, ROLE.RESULTS, ROLE.ITEMS, ROLE.QUESTION, ROLE.ANSWER, ROLE.SOURCES, ROLE.RELATED_RESOURCES, ROLE.QUERY_SUGGESTIONS, ROLE.RELATED_QUESTIONS, ROLE.AFFILIATION, ROLE.FACETS, ROLE.HITS]);
39
+ const DATA_ROLE_SET = new Set([ROLE.PRODUCTS, ROLE.CATEGORIES, ROLE.ATTRIBUTES, ROLE.RESULTS, ROLE.ITEMS, ROLE.QUESTION, ROLE.ANSWER, ROLE.SOURCES, ROLE.RELATED_RESOURCES, ROLE.QUERY_SUGGESTIONS, ROLE.RELATED_QUESTIONS, ROLE.AFFILIATION, ROLE.FACETS, ROLE.TOTAL]);
37
40
  function isDataRole(role) {
38
41
  return DATA_ROLE_SET.has(role);
39
42
  }
40
- const DATA_ASPECT = exports.DATA_ASPECT = Object.freeze({
41
- AUTOCOMPLETE: 'autocomplete'
42
- });
43
- const LAYOUT_CATEGORY = exports.LAYOUT_CATEGORY = Object.freeze({
44
- CONTAINER: 'container',
45
- BANNER: 'banner',
46
- LIST: 'list',
47
- QUERY: 'query',
48
- RADIO: 'radio',
49
- FILTERS: 'filters',
50
- TEXT: 'text',
51
- AFFILIATION: 'affiliation',
52
- ERROR: 'error'
53
- });
43
+ const PRODUCT_ROLE_SET = new Set([ROLE.PRODUCTS, ROLE.SOURCES, ROLE.RELATED_RESOURCES]);
44
+ function isProductRole(role) {
45
+ return PRODUCT_ROLE_SET.has(role);
46
+ }
54
47
  const EVENT_TYPE = exports.EVENT_TYPE = Object.freeze({
55
48
  IMPRESSION: 'impression',
56
49
  VIEWABLE: 'viewable',
57
50
  CLICK: 'click',
58
- SUBMIT: 'submit'
51
+ SUBMIT: 'submit',
52
+ FEEDBACK: 'feedback'
59
53
  });
60
- const TRACKING_EVENT_TYPES = exports.TRACKING_EVENT_TYPES = [EVENT_TYPE.IMPRESSION, EVENT_TYPE.VIEWABLE, EVENT_TYPE.CLICK, EVENT_TYPE.SUBMIT];
54
+ const TRACKING_EVENT_TYPES = exports.TRACKING_EVENT_TYPES = [EVENT_TYPE.IMPRESSION, EVENT_TYPE.VIEWABLE, EVENT_TYPE.CLICK, EVENT_TYPE.SUBMIT, EVENT_TYPE.FEEDBACK];
55
+ const PERFORMANCE_EVENT_TYPES = exports.PERFORMANCE_EVENT_TYPES = [EVENT_TYPE.IMPRESSION, EVENT_TYPE.VIEWABLE, EVENT_TYPE.CLICK];
56
+ const PERFORMANCE_EVENT_TYPE_SET = new Set(PERFORMANCE_EVENT_TYPES);
57
+ function isPerformanceEventType(type) {
58
+ return PERFORMANCE_EVENT_TYPE_SET.has(type);
59
+ }
61
60
  const TRACKING_STATUS = exports.TRACKING_STATUS = Object.freeze({
62
61
  UNTRACKED: 'untracked',
63
62
  TRACKING: 'tracking',
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _constants = require("./constants.js");
8
8
  var _constants2 = require("../../constants.js");
9
+ var _index = require("../../actor/index.js");
9
10
  var _phrases = require("./phrases.js");
10
11
  const CLASS_OPEN = 'answer-box-open';
11
12
  const CLASS_SHOWN = 'answer-box-shown';
@@ -29,7 +30,12 @@ class AnswerBox {
29
30
 
30
31
  // expose widget API
31
32
  workflow.answerBox = this;
32
- workflow._unsubscribes.push(() => this.destroy()); // TODO: review
33
+ workflow._unsubscribes.push(() => {
34
+ if (workflow.answerBox === this) {
35
+ this.destroy();
36
+ workflow.answerBox = undefined;
37
+ }
38
+ });
33
39
 
34
40
  // handle toggle button clicks
35
41
  const callback = event => this._handleClick(event);
@@ -38,7 +44,9 @@ class AnswerBox {
38
44
  // sync state
39
45
  this._syncWofkflowStatus();
40
46
  this._syncButtonText();
41
- this._unsubscribes = [() => element.removeEventListener('click', callback), workflow.on('loading', () => this.hide()), workflow.on('error', () => this.show()), workflow.on('ready', () => this.show())];
47
+ this._unsubscribes = [() => element.removeEventListener('click', callback),
48
+ // cling to data rather than view, as we may miss view event when tab is inactive due to raf
49
+ workflow._answer._hub.on(_index.fields.data(), () => this._syncWofkflowStatus())];
42
50
  }
43
51
  _handleClick(_ref) {
44
52
  let {
@@ -56,7 +64,7 @@ class AnswerBox {
56
64
  _syncWofkflowStatus() {
57
65
  const {
58
66
  status
59
- } = this._workflow;
67
+ } = this._workflow._answer;
60
68
  switch (status) {
61
69
  case _constants2.STATUS.ERRONEOUS:
62
70
  case _constants2.STATUS.READY:
@@ -75,6 +83,13 @@ class AnswerBox {
75
83
  button.textContent = phrase;
76
84
  }
77
85
  }
86
+ _syncScroll() {
87
+ if (!this.isOpen) {
88
+ this._element.scrollIntoView({
89
+ behavior: 'smooth'
90
+ });
91
+ }
92
+ }
78
93
  destroy() {
79
94
  for (const unsubscribe of this._unsubscribes) {
80
95
  unsubscribe();
@@ -110,6 +125,7 @@ for (const [method, [action, className]] of Object.entries(METHODS)) {
110
125
  this._updateBoxStatus(action, className);
111
126
  if (className === CLASS_OPEN) {
112
127
  this._syncButtonText();
128
+ this._syncScroll();
113
129
  }
114
130
  };
115
131
  }
@@ -3,11 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.sources = exports.showMore = exports.showLess = exports.question = exports.keywords = exports.hits = void 0;
6
+ exports.total = exports.sources = exports.showMore = exports.showLess = exports.question = exports.keywords = void 0;
7
7
  /**
8
- * The phrase displayed right before <miso-question>
8
+ * The phrase to display <miso-question>
9
9
  */
10
- const question = exports.question = 'You asked...';
10
+ const question = exports.question = 'You asked “${value}”';
11
11
 
12
12
  /**
13
13
  * The phrase displayed right before <miso-sources>
@@ -20,8 +20,8 @@ const sources = exports.sources = 'Sources';
20
20
  const keywords = exports.keywords = 'You searched for “${value}”';
21
21
 
22
22
  /**
23
- * The phrase to display <miso-hits>
23
+ * The phrase to display <miso-total>
24
24
  */
25
- const hits = exports.hits = '${value} Results';
25
+ const total = exports.total = '${value} Results';
26
26
  const showMore = exports.showMore = 'Show more';
27
27
  const showLess = exports.showLess = 'Show less';
@@ -31,6 +31,15 @@ class Sections extends _templates.Sections {
31
31
  classes: [`${classPrefix}__answer-box-inner`]
32
32
  }, this.answerGroup(options)), this.answerBoxToggle(options)]);
33
33
  }
34
+ question(options) {
35
+ const {
36
+ phrase
37
+ } = this._helpers;
38
+ return phrase(options, {
39
+ name: 'question',
40
+ tag: 'div'
41
+ }).replaceAll('${value}', '<miso-question></miso-question>');
42
+ }
34
43
  answerBoxToggle(options) {
35
44
  const {
36
45
  element
@@ -51,8 +60,8 @@ class Sections extends _templates.Sections {
51
60
  } = this._helpers;
52
61
  return container(options, {
53
62
  name: 'search-results',
54
- visibleWhen: 'ready'
55
- }, [this.searchResultsInfoGroup(options), this.searchResultsFilters(options), '<miso-products></miso-products>']);
63
+ visibleWhen: 'loading ready'
64
+ }, [this.searchResultsInfoGroup(options), this.searchResultsFilters(options), '<miso-products></miso-products>', this.more(options)]);
56
65
  }
57
66
  searchResultsInfoGroup(options) {
58
67
  const {
@@ -63,7 +72,7 @@ class Sections extends _templates.Sections {
63
72
  } = options;
64
73
  return element('div', {
65
74
  classes: [`${classPrefix}__search-results-info`]
66
- }, [this.keywords(options), this.hits(options)]);
75
+ }, [this.keywords(options), this.total(options)]);
67
76
  }
68
77
  searchResultsFilters(options) {
69
78
  const {
@@ -86,15 +95,29 @@ class Sections extends _templates.Sections {
86
95
  inline: true
87
96
  }).replaceAll('${value}', '<miso-keywords></miso-keywords>');
88
97
  }
89
- hits(options) {
98
+ total(options) {
90
99
  const {
91
100
  phrase
92
101
  } = this._helpers;
93
102
  return phrase(options, {
94
- name: 'hits',
103
+ name: 'total',
95
104
  tag: 'div',
96
105
  inline: true
97
- }).replaceAll('${value}', '<miso-hits></miso-hits>');
106
+ }).replaceAll('${value}', '<miso-total></miso-total>');
107
+ }
108
+ more(options) {
109
+ if (!options.moreButton) {
110
+ return '';
111
+ }
112
+ const {
113
+ element
114
+ } = this._helpers;
115
+ const {
116
+ classPrefix
117
+ } = options;
118
+ return element('div', {
119
+ classes: [`${classPrefix}__search-results-more-container`]
120
+ }, ['<miso-more></miso-more>']);
98
121
  }
99
122
  }
100
123
  const helpers = exports.helpers = (0, _commons.externalize)(new _templates.Helpers(Object.assign({}, CONSTANTS, {
@@ -112,16 +135,21 @@ function root() {
112
135
  } = helpers;
113
136
  options = normalizeOptions(options);
114
137
  const {
115
- answerBox
138
+ answerBox,
139
+ answerGroup,
140
+ searchResultsGroup
116
141
  } = sections;
142
+ const {
143
+ answerBox: answerBoxOptions = true
144
+ } = options;
117
145
  return [section(options, {
118
146
  name: 'question'
119
147
  }, [container(options, {
120
148
  name: 'query'
121
149
  }, '<miso-query></miso-query>')]), section(options, {
122
150
  name: 'answer'
123
- }, [answerBox(options)]), section(options, {
151
+ }, answerBoxOptions ? [answerBox(options)] : answerGroup(options)), section(options, {
124
152
  name: 'search-results'
125
- }, sections.searchResultsGroup(options))].join('');
153
+ }, searchResultsGroup(options))].join('');
126
154
  }
127
155
  ;
@@ -33,16 +33,16 @@ Object.defineProperty(exports, "MisoFeedbackElement", {
33
33
  return _misoFeedback.default;
34
34
  }
35
35
  });
36
- Object.defineProperty(exports, "MisoHitsElement", {
36
+ Object.defineProperty(exports, "MisoKeywordsElement", {
37
37
  enumerable: true,
38
38
  get: function () {
39
- return _misoHits.default;
39
+ return _misoKeywords.default;
40
40
  }
41
41
  });
42
- Object.defineProperty(exports, "MisoKeywordsElement", {
42
+ Object.defineProperty(exports, "MisoMoreElement", {
43
43
  enumerable: true,
44
44
  get: function () {
45
- return _misoKeywords.default;
45
+ return _misoMore.default;
46
46
  }
47
47
  });
48
48
  Object.defineProperty(exports, "MisoProductsElement", {
@@ -99,6 +99,12 @@ Object.defineProperty(exports, "MisoSovrnAffiliationElement", {
99
99
  return _misoAffiliation.default;
100
100
  }
101
101
  });
102
+ Object.defineProperty(exports, "MisoTotalElement", {
103
+ enumerable: true,
104
+ get: function () {
105
+ return _misoTotal.default;
106
+ }
107
+ });
102
108
  var _misoComponent = _interopRequireDefault(require("./miso-component.js"));
103
109
  var _misoQuery = _interopRequireDefault(require("./miso-query.js"));
104
110
  var _misoQuerySuggestions = _interopRequireDefault(require("./miso-query-suggestions.js"));
@@ -112,7 +118,8 @@ var _misoRelatedResources = _interopRequireDefault(require("./miso-related-resou
112
118
  var _misoRelatedQuestions = _interopRequireDefault(require("./miso-related-questions.js"));
113
119
  var _misoAffiliation = _interopRequireDefault(require("./miso-affiliation.js"));
114
120
  var _misoKeywords = _interopRequireDefault(require("./miso-keywords.js"));
115
- var _misoHits = _interopRequireDefault(require("./miso-hits.js"));
121
+ var _misoTotal = _interopRequireDefault(require("./miso-total.js"));
116
122
  var _misoFacets = _interopRequireDefault(require("./miso-facets.js"));
123
+ var _misoMore = _interopRequireDefault(require("./miso-more.js"));
117
124
  var _misoError = _interopRequireDefault(require("./miso-error.js"));
118
125
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -7,14 +7,14 @@ exports.default = void 0;
7
7
  var _misoComponent = _interopRequireDefault(require("./miso-component.js"));
8
8
  var _constants = require("../../constants.js");
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- class MisoHitsElement extends _misoComponent.default {
10
+ class MisoMoreElement extends _misoComponent.default {
11
11
  constructor() {
12
12
  super({
13
- role: _constants.ROLE.HITS
13
+ role: _constants.ROLE.MORE
14
14
  });
15
15
  }
16
16
  static get tagName() {
17
- return 'miso-hits';
17
+ return 'miso-more';
18
18
  }
19
19
  }
20
- exports.default = MisoHitsElement;
20
+ exports.default = MisoMoreElement;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _misoComponent = _interopRequireDefault(require("./miso-component.js"));
8
+ var _constants = require("../../constants.js");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ class MisoTotalElement extends _misoComponent.default {
11
+ constructor() {
12
+ super({
13
+ role: _constants.ROLE.TOTAL
14
+ });
15
+ }
16
+ static get tagName() {
17
+ return 'miso-total';
18
+ }
19
+ }
20
+ exports.default = MisoTotalElement;
@@ -166,9 +166,6 @@ function autoplayOptionsEquals(a, b) {
166
166
  */
167
167
 
168
168
  class AffiliationLayout extends _collection.default {
169
- static get category() {
170
- return _constants.LAYOUT_CATEGORY.AFFILIATION;
171
- }
172
169
  static get type() {
173
170
  return TYPE;
174
171
  }
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _constants = require("../../constants.js");
8
7
  var _template = _interopRequireDefault(require("../template.js"));
9
8
  var _svgs = require("../svgs.js");
10
9
  const _excluded = ["className", "templates"];
@@ -27,9 +26,6 @@ const DEFAULT_TEMPLATES = Object.freeze({
27
26
  // TODO: give a role and make this customizable
28
27
 
29
28
  class BannerLayout extends _template.default {
30
- static get category() {
31
- return _constants.LAYOUT_CATEGORY.BANNER;
32
- }
33
29
  static get type() {
34
30
  return TYPE;
35
31
  }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _constants = require("../../constants.js");
8
+ var _index = require("../../actor/index.js");
9
+ var _template = _interopRequireDefault(require("../template.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 (e.includes(n)) continue; t[n] = r[n]; } return t; }
13
+ const TYPE = 'more-button';
14
+ const DEFAULT_CLASSNAME = 'miso-more-button';
15
+ function root(layout, state) {
16
+ const {
17
+ className,
18
+ role,
19
+ templates
20
+ } = layout;
21
+ const roleAttr = role ? ` data-role="${role}"` : '';
22
+ const disabledAttr = state.status !== _constants.STATUS.READY ? ' disabled' : '';
23
+ return `
24
+ <div class="${className}"${roleAttr}${disabledAttr}>
25
+ ${templates.text(layout)}
26
+ </div>
27
+ `;
28
+ }
29
+ const DEFAULT_TEMPLATES = Object.freeze({
30
+ root,
31
+ text
32
+ });
33
+ function text(layout) {
34
+ return 'More';
35
+ }
36
+ class MoreButtonLayout extends _template.default {
37
+ static get type() {
38
+ return TYPE;
39
+ }
40
+ static get defaultTemplates() {
41
+ return DEFAULT_TEMPLATES;
42
+ }
43
+ static get defaultClassName() {
44
+ return DEFAULT_CLASSNAME;
45
+ }
46
+ constructor() {
47
+ let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
48
+ let {
49
+ className = DEFAULT_CLASSNAME,
50
+ templates
51
+ } = _ref,
52
+ options = _objectWithoutPropertiesLoose(_ref, _excluded);
53
+ super(Object.assign({
54
+ className,
55
+ templates: Object.assign({}, DEFAULT_TEMPLATES, templates)
56
+ }, options));
57
+ }
58
+ initialize(view) {
59
+ this._unsubscribes = [...this._unsubscribes, view.proxyElement.on('click', e => this._handleClick(e))];
60
+ }
61
+ _handleClick(event) {
62
+ // only left click
63
+ if (event.button !== 0) {
64
+ return;
65
+ }
66
+ const button = event.target.closest('data-role="more"');
67
+ if (!button || button.disabled) {
68
+ return;
69
+ }
70
+ this._view.hub.trigger(_index.fields.more());
71
+ }
72
+ }
73
+ exports.default = MoreButtonLayout;
@@ -13,9 +13,6 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
13
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
14
  const TYPE = 'container';
15
15
  class ContainerLayout extends _raf.default {
16
- static get category() {
17
- return _constants.LAYOUT_CATEGORY.CONTAINER;
18
- }
19
16
  static get type() {
20
17
  return TYPE;
21
18
  }
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _constants = require("../../constants.js");
8
7
  var _template = _interopRequireDefault(require("../template.js"));
9
8
  const _excluded = ["className", "templates"];
10
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -33,9 +32,6 @@ const DEFAULT_TEMPLATES = Object.freeze({
33
32
  message
34
33
  });
35
34
  class ErrorLayout extends _template.default {
36
- static get category() {
37
- return _constants.LAYOUT_CATEGORY.ERROR;
38
- }
39
35
  static get type() {
40
36
  return TYPE;
41
37
  }
@@ -63,6 +63,12 @@ Object.defineProperty(exports, "ListLayout", {
63
63
  return _list.default;
64
64
  }
65
65
  });
66
+ Object.defineProperty(exports, "MoreButtonLayout", {
67
+ enumerable: true,
68
+ get: function () {
69
+ return _moreButton.default;
70
+ }
71
+ });
66
72
  Object.defineProperty(exports, "OptionListLayout", {
67
73
  enumerable: true,
68
74
  get: function () {
@@ -108,4 +114,5 @@ var _text = _interopRequireDefault(require("./text/text.js"));
108
114
  var _index = _interopRequireDefault(require("./text/typewriter/index.js"));
109
115
  var _affiliation = _interopRequireDefault(require("./affiliation/affiliation.js"));
110
116
  var _facets = _interopRequireDefault(require("./input/facets.js"));
117
+ var _moreButton = _interopRequireDefault(require("./button/more-button.js"));
111
118
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _commons = require("@miso.ai/commons");
8
- var _constants = require("../../constants.js");
9
8
  var _template = _interopRequireDefault(require("../template.js"));
10
9
  var _bindings = _interopRequireDefault(require("../../util/bindings.js"));
11
10
  const _excluded = ["className", "templates"];
@@ -126,9 +125,6 @@ function getSelectedValues(facets) {
126
125
  return selections;
127
126
  }
128
127
  class FacetsLayout extends _template.default {
129
- static get category() {
130
- return _constants.LAYOUT_CATEGORY.FILTERS;
131
- }
132
128
  static get type() {
133
129
  return TYPE;
134
130
  }
@@ -161,10 +157,10 @@ class FacetsLayout extends _template.default {
161
157
  }
162
158
  _render(element, data, controls) {
163
159
  super._render(element, data, controls);
164
- this._syncSelections();
165
160
  }
166
161
  _afterRender(element, state) {
167
162
  this._syncBindings(element, state);
163
+ this._syncSelections();
168
164
  }
169
165
  _unrender() {
170
166
  this._clearBindings();
@@ -270,6 +266,10 @@ class FacetsLayout extends _template.default {
270
266
  return Array.from(element.querySelectorAll(`[data-role="option"]`));
271
267
  }
272
268
  _handleClick(event) {
269
+ // only left click
270
+ if (event.button !== 0) {
271
+ return;
272
+ }
273
273
  const element = event.target.closest(`[data-role="option"]`);
274
274
  if (!element) {
275
275
  return;
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _commons = require("@miso.ai/commons");
8
- var _constants = require("../../constants.js");
9
8
  var _index = require("../../actor/index.js");
10
9
  var _template = _interopRequireDefault(require("../template.js"));
11
10
  var _trackable = require("../trackable.js");
@@ -54,9 +53,6 @@ const DEFAULT_TEMPLATES = Object.freeze({
54
53
  option
55
54
  });
56
55
  class OptionListLayout extends _template.default {
57
- static get category() {
58
- return _constants.LAYOUT_CATEGORY.QUERY;
59
- }
60
56
  static get type() {
61
57
  return TYPE;
62
58
  }
@@ -19,26 +19,40 @@ const DEFAULT_AUTOCOMPLETE_CLASSNAME = 'miso-autocomplete';
19
19
  function root(layout) {
20
20
  const {
21
21
  className,
22
+ templates,
22
23
  role,
23
24
  options,
24
- workflow,
25
25
  autocomplete
26
26
  } = layout;
27
27
  const {
28
- placeholder,
29
- buttonText
28
+ placeholder
30
29
  } = options;
31
30
  const roleAttr = role ? `data-role="${role}"` : '';
32
- const buttonContent = buttonText || workflow === 'search' ? _svgs.SEARCH : _svgs.SEND;
33
31
  return `
34
32
  <div class="${className}" ${roleAttr}>
35
33
  <div class="${className}__input-group">
36
34
  <input class="${className}__input" type="text" data-role="input" ${placeholder ? `placeholder="${placeholder}"` : ''}>
37
- <button class="${className}__button" type="submit" data-role="submit">${buttonContent}</button>
35
+ <button class="${className}__button" type="submit" data-role="submit">${templates.buttonContent(layout)}</button>
38
36
  </div>
39
37
  <div class="${autocomplete.className}" data-role="autocomplete"></div>
40
38
  </div>`.trim();
41
39
  }
40
+ function buttonContent(layout) {
41
+ const {
42
+ templates,
43
+ options
44
+ } = layout;
45
+ if (options.buttonText) {
46
+ return options.buttonText; // legacy
47
+ }
48
+ const {
49
+ buttonText,
50
+ buttonIcon
51
+ } = templates;
52
+ const text = typeof buttonText === 'function' ? buttonText(layout) : `${buttonText}`;
53
+ const icon = typeof buttonIcon === 'function' ? buttonIcon(layout) : (0, _svgs.getIcon)(buttonIcon) || `${buttonIcon}`;
54
+ return text + icon;
55
+ }
42
56
  function completions(layout, items) {
43
57
  const {
44
58
  templates,
@@ -110,6 +124,9 @@ function completionItem(layout, type, item) {
110
124
  }
111
125
  const DEFAULT_TEMPLATES = Object.freeze({
112
126
  root,
127
+ buttonContent,
128
+ buttonText: '',
129
+ buttonIcon: 'search',
113
130
  completions,
114
131
  completionList,
115
132
  completionItem,
@@ -125,9 +142,6 @@ const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
125
142
  debounce: 300
126
143
  });
127
144
  class SearchBoxLayout extends _template.default {
128
- static get category() {
129
- return _constants.LAYOUT_CATEGORY.QUERY;
130
- }
131
145
  static get type() {
132
146
  return TYPE;
133
147
  }
@@ -161,7 +175,7 @@ class SearchBoxLayout extends _template.default {
161
175
  proxyElement,
162
176
  hub
163
177
  } = view;
164
- this._unsubscribes = [...this._unsubscribes, proxyElement.on('input', e => this._syncInput(e)), proxyElement.on('keydown', e => this._handleKeyDown(e)), proxyElement.on('click', e => this._handleClick(e)), proxyElement.on('focusin', e => this._handleFocusIn(e)), proxyElement.on('focusout', e => this._handleFocusOut(e)), hub.on(_index.fields.data(_constants.DATA_ASPECT.AUTOCOMPLETE), () => view.refresh({
178
+ this._unsubscribes = [...this._unsubscribes, proxyElement.on('input', e => this._syncInput(e)), proxyElement.on('keydown', e => this._handleKeyDown(e)), proxyElement.on('click', e => this._handleClick(e)), proxyElement.on('focusin', e => this._handleFocusIn(e)), proxyElement.on('focusout', e => this._handleFocusOut(e)), hub.on(_index.fields.completions(), () => view.refresh({
165
179
  force: true
166
180
  }))];
167
181
  }
@@ -195,7 +209,7 @@ class SearchBoxLayout extends _template.default {
195
209
  state
196
210
  });
197
211
  return Object.assign({}, state, {
198
- completions: this._view.hub.states[_index.fields.data(_constants.DATA_ASPECT.AUTOCOMPLETE)]
212
+ completions: this._view.hub.states[_index.fields.completions()]
199
213
  });
200
214
  }
201
215
  _render(element, data, controls) {
@@ -204,6 +218,8 @@ class SearchBoxLayout extends _template.default {
204
218
  super._render(element, data, controls);
205
219
  }
206
220
  this._updateCompletions(element, data, controls);
221
+ }
222
+ _afterRender(element, state) {
207
223
  this._fullfillFocusRequest(element);
208
224
  this._fullfillValueRequest(element);
209
225
  }
@@ -220,9 +236,12 @@ class SearchBoxLayout extends _template.default {
220
236
  }
221
237
  const {
222
238
  status = _constants.STATUS.INITIAL,
223
- index,
239
+ session,
224
240
  value: completions
225
241
  } = state.completions;
242
+ const {
243
+ index
244
+ } = session;
226
245
  if (rendered && rendered.completions.index === index && rendered.completions.status === status) {
227
246
  return;
228
247
  }
@@ -384,7 +403,9 @@ class SearchBoxLayout extends _template.default {
384
403
  if (!options) {
385
404
  return;
386
405
  }
387
- this._view.tracker.submit(value);
406
+ this._view.tracker.submit({
407
+ value
408
+ }); // not array
388
409
  }
389
410
  }
390
411
  exports.default = SearchBoxLayout;
@@ -11,9 +11,6 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
11
11
  const TYPE = 'cards';
12
12
  const DEFAULT_CLASSNAME = 'miso-cards';
13
13
  class CardsLayout extends _collection.default {
14
- static get category() {
15
- return super.category;
16
- }
17
14
  static get type() {
18
15
  return TYPE;
19
16
  }