@miso.ai/client-sdk-ui 1.13.2-beta.1 → 1.14.0-beta.2

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 (214) hide show
  1. package/dist/cjs/asset/svgs.js +15 -4
  2. package/dist/cjs/combo/ask/index.js +2 -2
  3. package/dist/cjs/constants.js +118 -98
  4. package/dist/cjs/defaults/ask/controls.js +1 -1
  5. package/dist/cjs/defaults/hybrid-search/answer-box.js +4 -4
  6. package/dist/cjs/defaults.js +169 -0
  7. package/dist/cjs/element/container/index.js +14 -0
  8. package/dist/cjs/element/container/miso-ask.js +3 -3
  9. package/dist/cjs/element/container/miso-conversation.js +21 -0
  10. package/dist/cjs/element/container/miso-explore.js +1 -1
  11. package/dist/cjs/element/container/miso-history.js +21 -0
  12. package/dist/cjs/element/container/miso-hybrid-search.js +1 -1
  13. package/dist/cjs/element/container/miso-recommendation.js +1 -1
  14. package/dist/cjs/element/container/miso-search.js +1 -1
  15. package/dist/cjs/element/context/miso-follow-ups.js +1 -1
  16. package/dist/cjs/element/role/index.js +42 -0
  17. package/dist/cjs/element/role/miso-messages.js +20 -0
  18. package/dist/cjs/element/role/miso-new-thread.js +20 -0
  19. package/dist/cjs/element/role/miso-rename.js +20 -0
  20. package/dist/cjs/element/role/miso-subscription.js +20 -0
  21. package/dist/cjs/element/role/miso-threads.js +20 -0
  22. package/dist/cjs/element/role/miso-title.js +20 -0
  23. package/dist/cjs/layout/affiliation/affiliation.js +1 -1
  24. package/dist/cjs/layout/banner/banner.js +2 -1
  25. package/dist/cjs/layout/button/button.js +130 -0
  26. package/dist/cjs/layout/button/checkbox.js +115 -0
  27. package/dist/cjs/layout/button/more-button.js +3 -3
  28. package/dist/cjs/layout/container/container.js +1 -1
  29. package/dist/cjs/layout/error/error.js +2 -1
  30. package/dist/cjs/layout/index.js +28 -0
  31. package/dist/cjs/layout/input/facets.js +4 -3
  32. package/dist/cjs/layout/input/option-list.js +3 -2
  33. package/dist/cjs/layout/input/search-box.js +42 -9
  34. package/dist/cjs/layout/input/select.js +2 -1
  35. package/dist/cjs/layout/list/cards.js +2 -1
  36. package/dist/cjs/layout/list/carousel.js +2 -1
  37. package/dist/cjs/layout/list/collection.js +5 -0
  38. package/dist/cjs/layout/list/gallery.js +2 -1
  39. package/dist/cjs/layout/list/horizontal.js +2 -1
  40. package/dist/cjs/layout/list/list.js +2 -1
  41. package/dist/cjs/layout/list/messages.js +346 -0
  42. package/dist/cjs/layout/list/threads.js +257 -0
  43. package/dist/cjs/layout/mixin/trackable.js +4 -5
  44. package/dist/cjs/layout/mixin/triggerable.js +2 -2
  45. package/dist/cjs/layout/radio/feedback.js +4 -3
  46. package/dist/cjs/layout/templates.js +70 -0
  47. package/dist/cjs/layout/text/text.js +2 -1
  48. package/dist/cjs/layout/text/typewriter/index.js +4 -2
  49. package/dist/cjs/plugin.js +43 -104
  50. package/dist/cjs/util/confirm.js +33 -0
  51. package/dist/cjs/util/modal.js +48 -0
  52. package/dist/cjs/util/prompt.js +47 -0
  53. package/dist/cjs/version.js +1 -1
  54. package/package.json +5 -4
  55. package/src/CLAUDE.md +48 -105
  56. package/src/asset/svgs.js +14 -3
  57. package/src/combo/ask/index.js +2 -2
  58. package/src/constants.js +37 -147
  59. package/src/defaults/ask/controls.js +1 -1
  60. package/src/defaults/hybrid-search/answer-box.js +2 -2
  61. package/src/defaults.js +107 -0
  62. package/src/element/container/index.js +2 -0
  63. package/src/element/container/miso-ask.js +3 -3
  64. package/src/element/container/miso-conversation.js +19 -0
  65. package/src/element/container/miso-explore.js +1 -1
  66. package/src/element/container/miso-history.js +19 -0
  67. package/src/element/container/miso-hybrid-search.js +1 -1
  68. package/src/element/container/miso-recommendation.js +1 -1
  69. package/src/element/container/miso-search.js +1 -1
  70. package/src/element/context/miso-follow-ups.js +1 -1
  71. package/src/element/role/index.js +6 -0
  72. package/src/element/role/miso-messages.js +16 -0
  73. package/src/element/role/miso-new-thread.js +16 -0
  74. package/src/element/role/miso-rename.js +16 -0
  75. package/src/element/role/miso-subscription.js +16 -0
  76. package/src/element/role/miso-threads.js +16 -0
  77. package/src/element/role/miso-title.js +16 -0
  78. package/src/layout/affiliation/affiliation.js +2 -2
  79. package/src/layout/banner/banner.js +2 -1
  80. package/src/layout/button/button.js +116 -0
  81. package/src/layout/button/checkbox.js +91 -0
  82. package/src/layout/button/more-button.js +3 -3
  83. package/src/layout/container/container.js +2 -2
  84. package/src/layout/error/error.js +2 -1
  85. package/src/layout/index.js +4 -0
  86. package/src/layout/input/facets.js +3 -2
  87. package/src/layout/input/option-list.js +3 -2
  88. package/src/layout/input/search-box.js +41 -6
  89. package/src/layout/input/select.js +2 -1
  90. package/src/layout/list/cards.js +2 -1
  91. package/src/layout/list/carousel.js +2 -1
  92. package/src/layout/list/collection.js +6 -1
  93. package/src/layout/list/gallery.js +2 -1
  94. package/src/layout/list/horizontal.js +2 -1
  95. package/src/layout/list/list.js +2 -1
  96. package/src/layout/list/messages.js +318 -0
  97. package/src/layout/list/threads.js +206 -0
  98. package/src/layout/mixin/trackable.js +2 -3
  99. package/src/layout/mixin/triggerable.js +1 -1
  100. package/src/layout/radio/feedback.js +3 -2
  101. package/src/layout/templates.js +62 -0
  102. package/src/layout/text/text.js +2 -1
  103. package/src/layout/text/typewriter/index.js +5 -3
  104. package/src/plugin.js +31 -117
  105. package/src/util/confirm.js +28 -0
  106. package/src/util/modal.js +49 -0
  107. package/src/util/prompt.js +42 -0
  108. package/src/version.js +1 -1
  109. package/dist/cjs/actor/data.js +0 -132
  110. package/dist/cjs/actor/feedback.js +0 -29
  111. package/dist/cjs/actor/fields.js +0 -57
  112. package/dist/cjs/actor/filters.js +0 -161
  113. package/dist/cjs/actor/hub.js +0 -57
  114. package/dist/cjs/actor/index.js +0 -73
  115. package/dist/cjs/actor/interactions.js +0 -36
  116. package/dist/cjs/actor/sessions.js +0 -25
  117. package/dist/cjs/actor/tracker-states.js +0 -61
  118. package/dist/cjs/actor/tracker.js +0 -109
  119. package/dist/cjs/actor/trackers.js +0 -52
  120. package/dist/cjs/actor/utils.js +0 -15
  121. package/dist/cjs/actor/view.js +0 -294
  122. package/dist/cjs/actor/views.js +0 -209
  123. package/dist/cjs/source.js +0 -27
  124. package/dist/cjs/util/proxy.js +0 -88
  125. package/dist/cjs/util/trackers.js +0 -88
  126. package/dist/cjs/workflow/affiliations.js +0 -140
  127. package/dist/cjs/workflow/answer-based.js +0 -337
  128. package/dist/cjs/workflow/ask.js +0 -319
  129. package/dist/cjs/workflow/asks.js +0 -150
  130. package/dist/cjs/workflow/autocompletable.js +0 -63
  131. package/dist/cjs/workflow/autocomplete.js +0 -120
  132. package/dist/cjs/workflow/base.js +0 -418
  133. package/dist/cjs/workflow/context.js +0 -19
  134. package/dist/cjs/workflow/explore.js +0 -210
  135. package/dist/cjs/workflow/explores.js +0 -21
  136. package/dist/cjs/workflow/hybrid-search-answer.js +0 -88
  137. package/dist/cjs/workflow/hybrid-search-views.js +0 -109
  138. package/dist/cjs/workflow/hybrid-search.js +0 -213
  139. package/dist/cjs/workflow/index.js +0 -41
  140. package/dist/cjs/workflow/options/api.js +0 -41
  141. package/dist/cjs/workflow/options/auto-query.js +0 -97
  142. package/dist/cjs/workflow/options/configurable.js +0 -45
  143. package/dist/cjs/workflow/options/data-processor.js +0 -20
  144. package/dist/cjs/workflow/options/filters.js +0 -15
  145. package/dist/cjs/workflow/options/index.js +0 -126
  146. package/dist/cjs/workflow/options/interactions.js +0 -41
  147. package/dist/cjs/workflow/options/layouts.js +0 -79
  148. package/dist/cjs/workflow/options/options.js +0 -156
  149. package/dist/cjs/workflow/options/pagination.js +0 -25
  150. package/dist/cjs/workflow/options/roles.js +0 -15
  151. package/dist/cjs/workflow/options/templates.js +0 -30
  152. package/dist/cjs/workflow/options/trackers.js +0 -83
  153. package/dist/cjs/workflow/options/utils.js +0 -33
  154. package/dist/cjs/workflow/processors.js +0 -607
  155. package/dist/cjs/workflow/recommendation.js +0 -57
  156. package/dist/cjs/workflow/recommendations.js +0 -18
  157. package/dist/cjs/workflow/search-based.js +0 -337
  158. package/dist/cjs/workflow/search.js +0 -64
  159. package/dist/cjs/workflow/unit.js +0 -57
  160. package/dist/cjs/workflow/units.js +0 -42
  161. package/dist/cjs/workflow/use-link.js +0 -49
  162. package/src/actor/data.js +0 -106
  163. package/src/actor/feedback.js +0 -28
  164. package/src/actor/fields.js +0 -51
  165. package/src/actor/filters.js +0 -149
  166. package/src/actor/hub.js +0 -47
  167. package/src/actor/index.js +0 -10
  168. package/src/actor/interactions.js +0 -32
  169. package/src/actor/sessions.js +0 -21
  170. package/src/actor/tracker-states.js +0 -57
  171. package/src/actor/tracker.js +0 -104
  172. package/src/actor/trackers.js +0 -45
  173. package/src/actor/utils.js +0 -7
  174. package/src/actor/view.js +0 -272
  175. package/src/actor/views.js +0 -224
  176. package/src/source.js +0 -17
  177. package/src/util/proxy.js +0 -81
  178. package/src/util/trackers.js +0 -84
  179. package/src/workflow/affiliations.js +0 -121
  180. package/src/workflow/answer-based.js +0 -312
  181. package/src/workflow/ask.js +0 -284
  182. package/src/workflow/asks.js +0 -143
  183. package/src/workflow/autocompletable.js +0 -67
  184. package/src/workflow/autocomplete.js +0 -114
  185. package/src/workflow/base.js +0 -396
  186. package/src/workflow/context.js +0 -16
  187. package/src/workflow/explore.js +0 -194
  188. package/src/workflow/explores.js +0 -18
  189. package/src/workflow/hybrid-search-answer.js +0 -73
  190. package/src/workflow/hybrid-search-views.js +0 -116
  191. package/src/workflow/hybrid-search.js +0 -230
  192. package/src/workflow/index.js +0 -5
  193. package/src/workflow/options/api.js +0 -31
  194. package/src/workflow/options/auto-query.js +0 -70
  195. package/src/workflow/options/configurable.js +0 -48
  196. package/src/workflow/options/data-processor.js +0 -15
  197. package/src/workflow/options/filters.js +0 -10
  198. package/src/workflow/options/index.js +0 -11
  199. package/src/workflow/options/interactions.js +0 -36
  200. package/src/workflow/options/layouts.js +0 -73
  201. package/src/workflow/options/options.js +0 -175
  202. package/src/workflow/options/pagination.js +0 -18
  203. package/src/workflow/options/roles.js +0 -12
  204. package/src/workflow/options/templates.js +0 -27
  205. package/src/workflow/options/trackers.js +0 -80
  206. package/src/workflow/options/utils.js +0 -26
  207. package/src/workflow/processors.js +0 -490
  208. package/src/workflow/recommendation.js +0 -63
  209. package/src/workflow/recommendations.js +0 -14
  210. package/src/workflow/search-based.js +0 -329
  211. package/src/workflow/search.js +0 -73
  212. package/src/workflow/unit.js +0 -51
  213. package/src/workflow/units.js +0 -43
  214. package/src/workflow/use-link.js +0 -41
@@ -1,88 +0,0 @@
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
- class ProxyElement {
9
- constructor(element) {
10
- this._get = typeof element === 'function' ? element : () => element;
11
- this._handlers = [];
12
- this._elementUpdatedHandlers = [];
13
- this.sync();
14
- }
15
- get current() {
16
- return this._element;
17
- }
18
- on(event, handler) {
19
- if (event === 'element') {
20
- return this._onElementUpdated(handler);
21
- }
22
- const element = this._get();
23
- if (element) {
24
- element.addEventListener(event, handler);
25
- }
26
- this._handlers.push({
27
- event,
28
- handler
29
- });
30
- return () => this._off(event, handler);
31
- }
32
- _off(event, handler) {
33
- const element = this._get();
34
- if (element) {
35
- element.removeEventListener(event, handler);
36
- }
37
- (0, _commons.findAndRemoveItem)(this._handlers, en => en.handler === handler);
38
- }
39
- _onElementUpdated(handler) {
40
- this._elementUpdatedHandlers.push(handler);
41
- return () => {
42
- (0, _commons.removeItem)(this._elementUpdatedHandlers, handler);
43
- };
44
- }
45
- sync({
46
- silent = false
47
- } = {}) {
48
- const element = this._get();
49
- if (this._element === element) {
50
- return;
51
- }
52
- this._offAllFromCurrentElement();
53
- if (element) {
54
- for (const {
55
- event,
56
- handler
57
- } of this._handlers) {
58
- element.addEventListener(event, handler);
59
- }
60
- }
61
- const oldElement = this._element;
62
- this._element = element;
63
- if (silent) {
64
- return;
65
- }
66
- for (const handler of this._elementUpdatedHandlers) {
67
- try {
68
- handler(element, oldElement);
69
- } catch (e) {
70
- console.error(e); // TODO
71
- }
72
- }
73
- }
74
- _offAllFromCurrentElement() {
75
- if (this._element) {
76
- for (const {
77
- event,
78
- handler
79
- } of this._handlers) {
80
- this._element.removeEventListener(event, handler);
81
- }
82
- }
83
- }
84
- destroy() {
85
- this._offAllFromCurrentElement();
86
- }
87
- }
88
- exports.default = ProxyElement;
@@ -1,88 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isTracked = isTracked;
7
- exports.markAsTracked = markAsTracked;
8
- exports.normalizeTrackerOptions = normalizeTrackerOptions;
9
- exports.validateClick = validateClick;
10
- var _commons = require("@miso.ai/commons");
11
- const _excluded = ["impression", "viewable", "click"];
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
- const TRACKED = Symbol.for('miso:tracked');
14
- function isTracked(event) {
15
- return !!event[TRACKED];
16
- }
17
- function markAsTracked(event) {
18
- event[TRACKED] = true;
19
- }
20
- const DEFAULT_TRACKER_OPTIONS = Object.freeze({
21
- impression: Object.freeze({}),
22
- viewable: Object.freeze({
23
- area: 0.5,
24
- duration: 1000
25
- }),
26
- click: Object.freeze({
27
- lenient: false
28
- })
29
- });
30
- function mergeOptions(def, opt) {
31
- // if opt is falsy then return false, merge otherwise
32
- return !!opt && Object.assign({}, def, opt);
33
- }
34
-
35
- // TODO: don't need this anymore
36
- function normalizeTrackerOptions(options) {
37
- // TODO: make this { active: false } to keep it an object
38
- if (options === false) {
39
- return false; // turn off all tracking
40
- }
41
- if (options === true) {
42
- options = {};
43
- }
44
- if (typeof options !== 'object') {
45
- throw new Error(`Invalid options: ${options}`);
46
- }
47
- const {
48
- impression = {},
49
- viewable = {},
50
- click = {}
51
- } = options,
52
- rest = _objectWithoutPropertiesLoose(options, _excluded);
53
- return (0, _commons.trimObj)(Object.assign({}, DEFAULT_TRACKER_OPTIONS, rest, {
54
- impression: mergeOptions(DEFAULT_TRACKER_OPTIONS.impression, impression),
55
- viewable: mergeOptions(DEFAULT_TRACKER_OPTIONS.viewable, viewable),
56
- click: mergeOptions(DEFAULT_TRACKER_OPTIONS.click, click)
57
- }));
58
- }
59
- function validateClick(options = {}, event) {
60
- if (!options) {
61
- return false;
62
- }
63
- if (typeof options.validate === 'function') {
64
- return options.validate(event);
65
- }
66
- if (options.lenient) {
67
- return true;
68
- }
69
-
70
- // standard criteria
71
- // 1. each event can only be tracked once
72
- if (isTracked(event)) {
73
- return false;
74
- }
75
- // 2. it must be a left click
76
- if (event.button !== 0) {
77
- return false;
78
- }
79
- // 3. event default must not be prevented
80
- if (event.defaultPrevented) {
81
- return false;
82
- }
83
- // 4. must go through a real link
84
- if (!(0, _commons.findInAncestors)(event.target, element => element.tagName === 'A' && element.href || undefined)) {
85
- return false;
86
- }
87
- return true;
88
- }
@@ -1,140 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.processAffiliationData = processAffiliationData;
7
- exports.processSovrnProduct = processSovrnProduct;
8
- var _commons = require("@miso.ai/commons");
9
- const _excluded = ["affiliation_products"],
10
- _excluded2 = ["sovrn_aff"],
11
- _excluded3 = ["products"],
12
- _excluded4 = ["id", "deeplink", "headline", "description", "currency", "retailPrice", "salePrice", "discountRate", "image", "thumbnail", "merchant"];
13
- 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; }
14
- function processAffiliationData(data) {
15
- if (!data || !data.value) {
16
- return data;
17
- }
18
- const {
19
- value
20
- } = data;
21
- return Object.assign({}, data, {
22
- value: processValue(value)
23
- });
24
- }
25
- function processValue(value) {
26
- if (value.affiliation_products) {
27
- const {
28
- affiliation_products
29
- } = value,
30
- rest = _objectWithoutPropertiesLoose(value, _excluded);
31
- value = Object.assign({}, rest, {
32
- affiliation: processMisoData(affiliation_products)
33
- });
34
- } else if (value.sovrn_aff) {
35
- const {
36
- sovrn_aff
37
- } = value,
38
- rest = _objectWithoutPropertiesLoose(value, _excluded2);
39
- value = Object.assign({}, rest, {
40
- affiliation: processSovrnData(sovrn_aff)
41
- });
42
- }
43
- return postProcessValue(value);
44
- }
45
- function postProcessValue(value) {
46
- const {
47
- affiliation
48
- } = value;
49
- if (!affiliation) {
50
- return value;
51
- }
52
- let {
53
- channel,
54
- products
55
- } = affiliation;
56
- if (!products) {
57
- return value;
58
- }
59
- products = products.map(product => Object.assign({}, product));
60
- let i = 0;
61
- for (const product of products) {
62
- if (channel) {
63
- product.channel = channel;
64
- }
65
- product.position = i++;
66
- }
67
- return Object.assign({}, value, {
68
- affiliation: Object.assign({}, affiliation, {
69
- products
70
- })
71
- });
72
- }
73
- function processMisoData(products) {
74
- return {
75
- channel: 'miso',
76
- products
77
- };
78
- }
79
- function processSovrnData(_ref) {
80
- let {
81
- products
82
- } = _ref,
83
- data = _objectWithoutPropertiesLoose(_ref, _excluded3);
84
- return Object.assign({
85
- channel: 'sovrn'
86
- }, data, {
87
- products: products.map(processSovrnProduct)
88
- });
89
- }
90
- function processSovrnProduct(_ref2) {
91
- let {
92
- id,
93
- deeplink: url,
94
- headline: title,
95
- description,
96
- currency,
97
- retailPrice: original_price,
98
- salePrice: sale_price,
99
- discountRate: discount_rate_percent,
100
- image: cover_image,
101
- thumbnail,
102
- merchant
103
- } = _ref2,
104
- product = _objectWithoutPropertiesLoose(_ref2, _excluded4);
105
- const brand = merchant && merchant.name;
106
- const brand_logo = merchant && merchant.logo;
107
- return (0, _commons.trimObj)({
108
- id: `sovrn-${id}`,
109
- title,
110
- description,
111
- cover_image,
112
- url,
113
- currency,
114
- original_price,
115
- sale_price,
116
- discount_rate_percent,
117
- brand,
118
- brand_logo,
119
- custom_attributes: flatten(Object.assign({
120
- sovrn_id: id,
121
- thumbnail,
122
- merchant
123
- }, product))
124
- });
125
- }
126
- function flatten(obj, prefix = '') {
127
- return Object.keys(obj).reduce((acc, key) => {
128
- const value = obj[key];
129
- if (value === undefined) {
130
- return acc;
131
- }
132
- const prefixedKey = prefix ? `${prefix}_${key}` : key;
133
- if (typeof value === 'object') {
134
- return Object.assign({}, acc, flatten(value, prefixedKey));
135
- }
136
- return Object.assign({}, acc, {
137
- [prefixedKey]: value
138
- });
139
- }, {});
140
- }
@@ -1,337 +0,0 @@
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 _base = _interopRequireDefault(require("./base.js"));
9
- var _index = require("../actor/index.js");
10
- var _constants = require("../constants.js");
11
- var _index2 = require("../layout/index.js");
12
- var _affiliations = require("./affiliations.js");
13
- var _index3 = require("./options/index.js");
14
- var _processors = require("./processors.js");
15
- var _useLink = require("./use-link.js");
16
- var _trackers = require("../util/trackers.js");
17
- const _excluded = ["event"];
18
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
- 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; }
20
- const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_API_OPTIONS, {
21
- group: _commons.API.GROUP.ASK,
22
- payload: Object.assign({}, _base.default.DEFAULT_API_OPTIONS.payload, {
23
- source_fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at'],
24
- cite_link: 1,
25
- cite_start: '[',
26
- cite_end: ']'
27
- })
28
- }));
29
- const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
30
- actor: false,
31
- api: {
32
- group: _commons.API.GROUP.ASK,
33
- name: _commons.API.NAME.AUTOCOMPLETE
34
- }
35
- });
36
- const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LAYOUTS, {
37
- [_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type, {
38
- placeholder: 'Ask a question'
39
- }],
40
- [_constants.ROLE.QUESTION]: [_index2.TextLayout.type, {
41
- tag: 'h2'
42
- }],
43
- [_constants.ROLE.ANSWER]: _index2.TypewriterLayout.type,
44
- [_constants.ROLE.FEEDBACK]: _index2.FeedbackLayout.type,
45
- [_constants.ROLE.IMAGES]: [_index2.GalleryLayout.type, {
46
- incremental: true,
47
- itemType: 'image'
48
- }],
49
- [_constants.ROLE.SOURCES]: [_index2.ListLayout.type, {
50
- incremental: true,
51
- itemType: 'article',
52
- templates: {
53
- ordered: true
54
- }
55
- }],
56
- [_constants.ROLE.AFFILIATION]: [_index2.AffiliationLayout.type, {
57
- incremental: true,
58
- itemType: 'affiliation',
59
- link: {
60
- rel: 'noopener nofollow'
61
- }
62
- }]
63
- }));
64
- const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _base.default.DEFAULT_TRACKERS, {
65
- [_constants.ROLE.ANSWER]: {
66
- active: true,
67
- itemless: true,
68
- deduplicated: false,
69
- click: _index3.DEFAULT_TRACKER_OPTIONS.click // click only
70
- },
71
- [_constants.ROLE.IMAGES]: _index3.DEFAULT_TRACKER_OPTIONS,
72
- [_constants.ROLE.SOURCES]: _index3.DEFAULT_TRACKER_OPTIONS,
73
- [_constants.ROLE.AFFILIATION]: _index3.DEFAULT_TRACKER_OPTIONS,
74
- [_constants.ROLE.PRODUCTS]: _index3.DEFAULT_TRACKER_OPTIONS
75
- }));
76
- const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_OPTIONS, {
77
- api: DEFAULT_API_OPTIONS,
78
- autocomplete: DEFAULT_AUTOCOMPLETE_OPTIONS,
79
- layouts: DEFAULT_LAYOUTS,
80
- trackers: DEFAULT_TRACKERS
81
- }));
82
- const ROLES_OPTIONS = (0, _index3.mergeRolesOptions)(_base.default.ROLES_OPTIONS, {
83
- main: _constants.ROLE.ANSWER,
84
- members: Object.keys(DEFAULT_LAYOUTS),
85
- mappings: {
86
- [_constants.ROLE.ANSWER]: _processors.mappingAnswerData,
87
- [_constants.ROLE.REASONING]: _processors.mappingReasoningData
88
- }
89
- });
90
- class AnswerBasedWorkflow extends _base.default {
91
- // constructor //
92
- _initProperties(args) {
93
- super._initProperties(args);
94
- this._questionId = undefined;
95
- this._autoQuery = false;
96
- }
97
- _initActors(args) {
98
- super._initActors(args);
99
- this._feedback = new _index.FeedbackActor(this._hub);
100
- }
101
- _initSubscriptions(args) {
102
- super._initSubscriptions(args);
103
- this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.query(), args => this._query(args)), this._views.on(_constants.ROLE.ANSWER, 'citation-click', event => this._onCitationClick(event)), this._views.on(_constants.ROLE.ANSWER, 'link-click', event => this._onAnswerLinkClick(event))];
104
- }
105
-
106
- // lifecycle //
107
- restart() {
108
- // clear question id from previous session
109
- if (this._questionId) {
110
- this._questionId = undefined;
111
- }
112
- // restart
113
- super.restart();
114
- }
115
- _shallEmitLifecycleEvent(name, event) {
116
- return name === 'answer-stage' || super._shallEmitLifecycleEvent(name, event);
117
- }
118
- _emitInterruptEventIfNecessary() {
119
- const state = this._hub.states[_index.fields.view(this._roles.main)] || {};
120
- if (state.session && state.status !== _constants.STATUS.INITIAL && (state.status !== _constants.STATUS.READY || state.ongoing)) {
121
- // it's interrupted by a new question
122
- this._emitLifecycleEvent('interrupt', state);
123
- this._emitLifecycleEvent('finally', state);
124
- }
125
- }
126
- _onMainViewUpdate(state) {
127
- const {
128
- status,
129
- session
130
- } = state;
131
- const done = status === _constants.STATUS.READY && !state.ongoing;
132
- const erroneous = status === _constants.STATUS.ERRONEOUS;
133
- const eventName = done ? 'done' : erroneous ? 'error' : status;
134
-
135
- // answer-stage
136
- const context = this._getSessionContext(session);
137
- const oldAnswerStage = context.answerStage;
138
- const newAnswerStage = state.meta && state.meta.answer_stage;
139
- if (newAnswerStage && newAnswerStage !== oldAnswerStage) {
140
- this._emitLifecycleEvent('answer-stage', Object.freeze(Object.assign({}, state, {
141
- answer_stage: newAnswerStage
142
- })));
143
- context.answerStage = newAnswerStage;
144
- }
145
-
146
- // blocked reason
147
- const data = this._hub.states[_index.fields.data()] || {};
148
- const {
149
- value
150
- } = data;
151
- if (value) {
152
- const {
153
- blocked_reason
154
- } = value;
155
- if (blocked_reason) {
156
- this._emitLifecycleEvent('blocked', Object.assign({}, state, {
157
- blockedReason: blocked_reason
158
- }));
159
- }
160
- }
161
-
162
- // ready, done, or error
163
- this._emitLifecycleEvent(eventName, state);
164
- if (done || erroneous) {
165
- // finally
166
- this._emitLifecycleEvent('finally', state);
167
- }
168
- }
169
-
170
- // properties //
171
- get questionId() {
172
- return this._questionId;
173
- }
174
-
175
- // query //
176
- autoQuery(options = {}) {
177
- _index3.autoQuery.call(this, options);
178
- }
179
- query(args) {
180
- // TODO: also accept "question", "questionSource"?
181
- if (!args.q && !args.questionId) {
182
- throw new Error(`q is required in query() call`);
183
- }
184
- this._hub.update(_index.fields.query(), args);
185
- }
186
- _query(args = {}) {
187
- if (this._linkFn) {
188
- this._submitToPage(args);
189
- return;
190
- }
191
- // start a new session
192
- this.restart();
193
-
194
- // keep track of question source on this session, for suggested questions interactions
195
- this._writeQuestionSourceToSession(args);
196
-
197
- // build payload and trigger request
198
- const payload = this._buildPayload(args);
199
- this._request({
200
- payload
201
- });
202
- }
203
- _writeQuestionSourceToSession(args) {
204
- this.session.meta.question_source = args.qs || _constants.QUESTION_SOURCE.ORGANIC; // might be null, not undefined
205
- }
206
- _buildPayload() {
207
- throw new Error(`Not implemented`);
208
- }
209
- _writeWikiLinkTemplateToPayload(payload) {
210
- if (!this._autoQuery || !this._autoQuery.param || this._autoQuery.param === _index3.DEFAULT_AUTO_QUERY_PARAM) {
211
- return payload;
212
- }
213
- return Object.assign({}, payload, {
214
- wiki_link_template: `?${this._autoQuery.param}=%s`
215
- });
216
- }
217
-
218
- // data //
219
- _updateData(data) {
220
- // capture question ID and register at context
221
- this._writeQuestionIdFromData(data);
222
-
223
- // if it's the head response, write question id and return
224
- if (data.value && !data.value.answer_stage) {
225
- this._handleHeadResponse(data);
226
- return;
227
- }
228
- super._updateData(data);
229
-
230
- // update URL if autoQuery.updateUrl is not false
231
- _index3.updateQueryParametersInUrl.call(this, data);
232
- }
233
- _handleHeadResponse(data) {}
234
- _defaultProcessData(data, oldData) {
235
- data = super._defaultProcessData(data, oldData);
236
- data = (0, _affiliations.processAffiliationData)(data);
237
- data = (0, _processors.writeAnswerStageToMeta)(data);
238
- return data;
239
- }
240
- _writeQuestionIdFromData({
241
- value
242
- }) {
243
- value && this._writeQuestionId(value.question_id);
244
- }
245
-
246
- // interactions //
247
- _defaultProcessInteraction(payload, args) {
248
- payload = super._defaultProcessInteraction(payload, args);
249
- payload = (0, _processors.writeAnswerInfoToInteraction)(payload, args);
250
- return payload;
251
- }
252
- _getQuestionSourceFromViewState(args) {
253
- const {
254
- request
255
- } = this._hub.states[_index.fields.view(args.role)] || {};
256
- const {
257
- payload
258
- } = request || {};
259
- return payload && payload.metadata && payload.metadata.question_source || undefined;
260
- }
261
-
262
- // handlers //
263
- _onCitationClick({
264
- index,
265
- event
266
- }) {
267
- if (event.button !== 0) {
268
- return; // only left click
269
- }
270
- if ((0, _trackers.isTracked)(event)) {
271
- return;
272
- }
273
- const {
274
- value
275
- } = this._hub.states[_index.fields.data()] || {};
276
- const {
277
- sources
278
- } = value || {};
279
- // index is 1-based
280
- const source = sources && sources[index - 1];
281
- if (!source || !source.product_id) {
282
- return;
283
- }
284
- // TODO: should we track impression as well?
285
- (0, _trackers.markAsTracked)(event);
286
- // distinguish from regular sources element click
287
- this._views.trackers.sources.click([source.product_id], {
288
- event_target: 'citation-link'
289
- });
290
- }
291
- _onAnswerLinkClick(_ref) {
292
- let {
293
- event
294
- } = _ref,
295
- item = _objectWithoutPropertiesLoose(_ref, _excluded);
296
- if (event.button !== 0) {
297
- return; // only left click
298
- }
299
- if ((0, _trackers.isTracked)(event)) {
300
- return;
301
- }
302
- (0, _trackers.markAsTracked)(event);
303
- // put everything into args and let _defaultProcessInteraction() handles it
304
- // for it's hard to make it a standard item
305
- this._views.trackers.answer.click([], {
306
- items: [item]
307
- });
308
- }
309
-
310
- // helpers //
311
- _writeQuestionId(questionId) {
312
- if (!this._questionId && questionId) {
313
- this._questionId = questionId;
314
- }
315
- }
316
- _clearQuestionId() {
317
- // clear question id from previous session
318
- this._questionId = undefined;
319
- }
320
-
321
- // destroy //
322
- _destroy(options) {
323
- this._feedback._destroy();
324
- // this._autocomplete._destroy();
325
- super._destroy(options);
326
- }
327
- }
328
- exports.default = AnswerBasedWorkflow;
329
- (0, _useLink.enableUseLink)(AnswerBasedWorkflow.prototype);
330
- Object.assign(AnswerBasedWorkflow, {
331
- DEFAULT_API_OPTIONS,
332
- DEFAULT_AUTOCOMPLETE_OPTIONS,
333
- DEFAULT_LAYOUTS,
334
- DEFAULT_TRACKERS,
335
- DEFAULT_OPTIONS,
336
- ROLES_OPTIONS
337
- });