@miso.ai/client-sdk-ui 1.11.5-beta.0 → 1.11.5-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.
- package/dist/cjs/actor/data.js +4 -2
- package/dist/cjs/actor/view.js +3 -2
- package/dist/cjs/asset/svgs.js +5 -2
- package/dist/cjs/constants.js +2 -1
- package/dist/cjs/defaults/hybrid-search/answer-box.js +13 -2
- package/dist/cjs/defaults/hybrid-search/controls.js +2 -1
- package/dist/cjs/defaults/hybrid-search/templates.js +9 -0
- package/dist/cjs/layout/affiliation/affiliation.js +6 -7
- package/dist/cjs/layout/container/container.js +5 -1
- package/dist/cjs/layout/index.js +7 -0
- package/dist/cjs/layout/input/option-list.js +2 -1
- package/dist/cjs/layout/input/search-box.js +2 -1
- package/dist/cjs/layout/list/carousel.js +2 -2
- package/dist/cjs/layout/list/collection.js +7 -4
- package/dist/cjs/layout/list/gallery.js +270 -0
- package/dist/cjs/layout/mixin/swipeable.js +14 -15
- package/dist/cjs/layout/raf.js +2 -0
- package/dist/cjs/layout/templates.js +19 -8
- package/dist/cjs/util/dom.js +101 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/answer-based.js +49 -77
- package/dist/cjs/workflow/ask.js +5 -3
- package/dist/cjs/workflow/base.js +4 -2
- package/dist/cjs/workflow/explore.js +17 -7
- package/dist/cjs/workflow/hybrid-search-answer.js +13 -0
- package/dist/cjs/workflow/hybrid-search-results.js +16 -0
- package/dist/cjs/workflow/hybrid-search.js +3 -8
- package/dist/cjs/workflow/options/auto-query.js +62 -0
- package/dist/cjs/workflow/options/index.js +11 -0
- package/dist/cjs/workflow/processors.js +73 -0
- package/dist/cjs/workflow/search-based.js +4 -0
- package/dist/cjs/workflow/search.js +0 -25
- package/dist/cjs/workflow/use-link.js +9 -2
- package/package.json +2 -2
- package/src/actor/data.js +4 -2
- package/src/actor/view.js +3 -2
- package/src/asset/svgs.js +5 -1
- package/src/constants.js +1 -0
- package/src/defaults/hybrid-search/answer-box.js +9 -2
- package/src/defaults/hybrid-search/controls.js +2 -2
- package/src/defaults/hybrid-search/templates.js +9 -0
- package/src/layout/affiliation/affiliation.js +5 -7
- package/src/layout/container/container.js +4 -1
- package/src/layout/index.js +1 -0
- package/src/layout/input/option-list.js +2 -1
- package/src/layout/input/search-box.js +2 -1
- package/src/layout/list/carousel.js +3 -3
- package/src/layout/list/collection.js +6 -4
- package/src/layout/list/gallery.js +229 -0
- package/src/layout/mixin/swipeable.js +12 -16
- package/src/layout/raf.js +1 -0
- package/src/layout/templates.js +15 -3
- package/src/util/dom.js +103 -0
- package/src/version.js +1 -1
- package/src/workflow/answer-based.js +42 -42
- package/src/workflow/ask.js +6 -4
- package/src/workflow/base.js +4 -2
- package/src/workflow/explore.js +15 -4
- package/src/workflow/hybrid-search-answer.js +15 -1
- package/src/workflow/hybrid-search-results.js +17 -0
- package/src/workflow/hybrid-search.js +3 -6
- package/src/workflow/options/auto-query.js +29 -0
- package/src/workflow/options/index.js +1 -0
- package/src/workflow/processors.js +60 -0
- package/src/workflow/search-based.js +5 -1
- package/src/workflow/search.js +0 -17
- package/src/workflow/use-link.js +2 -2
|
@@ -263,19 +263,30 @@ function tagPair(_ref13, _ref14) {
|
|
|
263
263
|
role = 'item'
|
|
264
264
|
} = _ref12,
|
|
265
265
|
meta = _objectWithoutPropertiesLoose(_ref12, _excluded);
|
|
266
|
-
const {
|
|
267
|
-
link = {}
|
|
268
|
-
} = options;
|
|
269
|
-
const {
|
|
270
|
-
target = '_blank',
|
|
271
|
-
rel = 'noopener'
|
|
272
|
-
} = link; // TODO: other properties
|
|
273
266
|
const tag = meta.link !== false && url ? 'a' : 'div';
|
|
274
|
-
const urlAttrs = meta.link !== false && url ? `href="${url}"
|
|
267
|
+
const urlAttrs = meta.link !== false && url ? `href="${url}" ${linkAttrs(options.link)}` : '';
|
|
275
268
|
const productAttrs = product_id ? `${_constants.ATTR_DATA_MISO_PRODUCT_ID}="${product_id}"` : '';
|
|
276
269
|
const roleAttrs = role ? `data-role="${role}"` : '';
|
|
277
270
|
return [`<${tag} class="${className}__${classSuffix}" ${roleAttrs} ${productAttrs} ${urlAttrs}>`, `</${tag}>`];
|
|
278
271
|
}
|
|
272
|
+
function linkAttrs() {
|
|
273
|
+
let link = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
274
|
+
const {
|
|
275
|
+
target = '_blank',
|
|
276
|
+
rel = 'noopener',
|
|
277
|
+
open = true
|
|
278
|
+
} = link; // TODO: other properties
|
|
279
|
+
let attrs = '';
|
|
280
|
+
if (open) {
|
|
281
|
+
if (target) {
|
|
282
|
+
attrs += ` target="${target}"`;
|
|
283
|
+
}
|
|
284
|
+
if (rel) {
|
|
285
|
+
attrs += ` rel="${rel}"`;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return attrs;
|
|
289
|
+
}
|
|
279
290
|
const DEFAULT_DATE_OPTIONS = Object.freeze({
|
|
280
291
|
locale: 'en-US',
|
|
281
292
|
year: 'numeric',
|
|
@@ -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
|
+
}
|
package/dist/cjs/version.js
CHANGED
|
@@ -14,8 +14,7 @@ var _index4 = require("./options/index.js");
|
|
|
14
14
|
var _processors = require("./processors.js");
|
|
15
15
|
var _useLink = require("./use-link.js");
|
|
16
16
|
var _trackers = require("../util/trackers.js");
|
|
17
|
-
const _excluded = ["
|
|
18
|
-
_excluded2 = ["event"];
|
|
17
|
+
const _excluded = ["event"];
|
|
19
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
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; }
|
|
21
20
|
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_API_OPTIONS, {
|
|
@@ -43,7 +42,7 @@ const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LA
|
|
|
43
42
|
}],
|
|
44
43
|
[_constants.ROLE.ANSWER]: _index2.TypewriterLayout.type,
|
|
45
44
|
[_constants.ROLE.FEEDBACK]: _index2.FeedbackLayout.type,
|
|
46
|
-
[_constants.ROLE.IMAGES]: [_index2.
|
|
45
|
+
[_constants.ROLE.IMAGES]: [_index2.GalleryLayout.type, {
|
|
47
46
|
incremental: true,
|
|
48
47
|
itemType: 'image'
|
|
49
48
|
}],
|
|
@@ -84,22 +83,6 @@ const ROLES_OPTIONS = (0, _index4.mergeRolesOptions)(_base.default.ROLES_OPTIONS
|
|
|
84
83
|
main: _constants.ROLE.ANSWER,
|
|
85
84
|
members: Object.keys(DEFAULT_LAYOUTS)
|
|
86
85
|
});
|
|
87
|
-
function normalizeAutoQueryOptions() {
|
|
88
|
-
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
89
|
-
let {
|
|
90
|
-
setValue = true,
|
|
91
|
-
focus = true,
|
|
92
|
-
param = 'q',
|
|
93
|
-
sourceParam = 'qs'
|
|
94
|
-
} = _ref,
|
|
95
|
-
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
96
|
-
return Object.assign({
|
|
97
|
-
setValue,
|
|
98
|
-
focus,
|
|
99
|
-
param,
|
|
100
|
-
sourceParam
|
|
101
|
-
}, options);
|
|
102
|
-
}
|
|
103
86
|
class AnswerBasedWorkflow extends _base.default {
|
|
104
87
|
// constructor //
|
|
105
88
|
_initProperties(args) {
|
|
@@ -170,32 +153,7 @@ class AnswerBasedWorkflow extends _base.default {
|
|
|
170
153
|
// query //
|
|
171
154
|
autoQuery() {
|
|
172
155
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
173
|
-
|
|
174
|
-
setValue,
|
|
175
|
-
focus,
|
|
176
|
-
param,
|
|
177
|
-
sourceParam
|
|
178
|
-
} = this._autoQuery = normalizeAutoQueryOptions(options);
|
|
179
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
180
|
-
const q = searchParams.get(param);
|
|
181
|
-
const qs = searchParams.get(sourceParam);
|
|
182
|
-
const {
|
|
183
|
-
layout
|
|
184
|
-
} = this._views.get(_constants.ROLE.QUERY);
|
|
185
|
-
if (layout) {
|
|
186
|
-
if (q && setValue) {
|
|
187
|
-
layout.value = q;
|
|
188
|
-
}
|
|
189
|
-
if (!q && focus) {
|
|
190
|
-
layout.focus();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
if (q) {
|
|
194
|
-
this.query({
|
|
195
|
-
q,
|
|
196
|
-
qs
|
|
197
|
-
});
|
|
198
|
-
}
|
|
156
|
+
_index4.autoQuery.call(this, options);
|
|
199
157
|
}
|
|
200
158
|
query(args) {
|
|
201
159
|
// TODO: also accept "question", "questionSource"?
|
|
@@ -228,9 +186,20 @@ class AnswerBasedWorkflow extends _base.default {
|
|
|
228
186
|
_buildPayload() {
|
|
229
187
|
throw new Error(`Not implemented`);
|
|
230
188
|
}
|
|
189
|
+
_writeWikiLinkTemplateToPayload(payload) {
|
|
190
|
+
if (!this._autoQuery || !this._autoQuery.param || this._autoQuery.param === _index4.DEFAULT_AUTO_QUERY_PARAM) {
|
|
191
|
+
return payload;
|
|
192
|
+
}
|
|
193
|
+
return Object.assign({}, payload, {
|
|
194
|
+
wiki_link_template: `?${this._autoQuery.param}=%s`
|
|
195
|
+
});
|
|
196
|
+
}
|
|
231
197
|
|
|
232
198
|
// data //
|
|
233
199
|
_updateData(data) {
|
|
200
|
+
// capture question ID and register at context
|
|
201
|
+
this._writeQuestionIdFromData(data);
|
|
202
|
+
|
|
234
203
|
// if it's the head response, write question id and return
|
|
235
204
|
if (data.value && !data.value.answer_stage) {
|
|
236
205
|
this._handleHeadResponse(data);
|
|
@@ -241,51 +210,49 @@ class AnswerBasedWorkflow extends _base.default {
|
|
|
241
210
|
// update URL if autoQuery.updateUrl is not false
|
|
242
211
|
this._updateUrlIfNecessary(data);
|
|
243
212
|
}
|
|
244
|
-
_handleHeadResponse(data) {
|
|
245
|
-
// capture question ID and register at context
|
|
246
|
-
this._writeQuestionIdFromData(data);
|
|
247
|
-
}
|
|
213
|
+
_handleHeadResponse(data) {}
|
|
248
214
|
_defaultProcessData(data) {
|
|
249
215
|
data = super._defaultProcessData(data);
|
|
250
216
|
data = (0, _index3.processData)(data);
|
|
251
217
|
data = (0, _processors.writeAnswerStageToMeta)(data);
|
|
252
218
|
return data;
|
|
253
219
|
}
|
|
254
|
-
_writeQuestionIdFromData(
|
|
220
|
+
_writeQuestionIdFromData(_ref) {
|
|
255
221
|
let {
|
|
256
222
|
value
|
|
257
|
-
} =
|
|
258
|
-
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
const {
|
|
262
|
-
question_id: questionId
|
|
263
|
-
} = value;
|
|
264
|
-
this._writeQuestionId(questionId);
|
|
223
|
+
} = _ref;
|
|
224
|
+
value && this._writeQuestionId(value.question_id);
|
|
265
225
|
}
|
|
266
|
-
_updateUrlIfNecessary(
|
|
226
|
+
_updateUrlIfNecessary(_ref2) {
|
|
267
227
|
let {
|
|
268
228
|
value,
|
|
269
229
|
request
|
|
270
|
-
} =
|
|
271
|
-
if (!
|
|
272
|
-
// explicitly false
|
|
230
|
+
} = _ref2;
|
|
231
|
+
if (!this._autoQuery || !this._autoQuery.updateUrl) {
|
|
273
232
|
return;
|
|
274
233
|
}
|
|
275
234
|
const {
|
|
276
|
-
param
|
|
235
|
+
param,
|
|
236
|
+
sourceParam
|
|
277
237
|
} = this._autoQuery;
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
238
|
+
const question = value && value.question || request && request.payload && request.payload.question;
|
|
239
|
+
const questionSource = request && request.payload && request.payload._meta && request.payload._meta.question_source;
|
|
240
|
+
if (!question) {
|
|
241
|
+
return; // at initial phase
|
|
242
|
+
}
|
|
282
243
|
const url = new URL(window.location);
|
|
283
244
|
const currentQuestion = url.searchParams.get(param);
|
|
284
|
-
|
|
285
|
-
if (question
|
|
286
|
-
|
|
287
|
-
|
|
245
|
+
const currentQuestionSource = url.searchParams.get(sourceParam) || _constants.ORGANIC_QUESTION_SOURCE;
|
|
246
|
+
if (question === currentQuestion && questionSource === currentQuestionSource) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
url.searchParams.set(param, question);
|
|
250
|
+
if (questionSource === _constants.ORGANIC_QUESTION_SOURCE) {
|
|
251
|
+
url.searchParams.delete(sourceParam);
|
|
252
|
+
} else {
|
|
253
|
+
url.searchParams.set(sourceParam, questionSource);
|
|
288
254
|
}
|
|
255
|
+
window.history.replaceState({}, '', url);
|
|
289
256
|
}
|
|
290
257
|
|
|
291
258
|
// interactions //
|
|
@@ -293,6 +260,7 @@ class AnswerBasedWorkflow extends _base.default {
|
|
|
293
260
|
payload = super._defaultProcessInteraction(payload, args);
|
|
294
261
|
payload = this._writeAskPropertiesToInteraction(payload, args);
|
|
295
262
|
payload = this._writeAnswerClickInteraction(payload, args);
|
|
263
|
+
payload = (0, _processors.writeEventTargetToInteraction)(payload, args);
|
|
296
264
|
return payload;
|
|
297
265
|
}
|
|
298
266
|
_writeAskPropertiesToInteraction() {
|
|
@@ -338,11 +306,11 @@ class AnswerBasedWorkflow extends _base.default {
|
|
|
338
306
|
}
|
|
339
307
|
|
|
340
308
|
// handlers //
|
|
341
|
-
_onCitationClick(
|
|
309
|
+
_onCitationClick(_ref3) {
|
|
342
310
|
let {
|
|
343
311
|
index,
|
|
344
312
|
event
|
|
345
|
-
} =
|
|
313
|
+
} = _ref3;
|
|
346
314
|
if ((0, _trackers.isTracked)(event)) {
|
|
347
315
|
return;
|
|
348
316
|
}
|
|
@@ -359,13 +327,17 @@ class AnswerBasedWorkflow extends _base.default {
|
|
|
359
327
|
}
|
|
360
328
|
// TODO: should we track impression as well?
|
|
361
329
|
(0, _trackers.markAsTracked)(event);
|
|
362
|
-
|
|
330
|
+
// distinguish from regular sources element click
|
|
331
|
+
// TODO
|
|
332
|
+
this._views.trackers.sources.click([source.product_id], {
|
|
333
|
+
event_target: 'citation-link'
|
|
334
|
+
});
|
|
363
335
|
}
|
|
364
|
-
_onAnswerLinkClick(
|
|
336
|
+
_onAnswerLinkClick(_ref4) {
|
|
365
337
|
let {
|
|
366
338
|
event
|
|
367
|
-
} =
|
|
368
|
-
item = _objectWithoutPropertiesLoose(
|
|
339
|
+
} = _ref4,
|
|
340
|
+
item = _objectWithoutPropertiesLoose(_ref4, _excluded);
|
|
369
341
|
if ((0, _trackers.isTracked)(event)) {
|
|
370
342
|
return;
|
|
371
343
|
}
|
package/dist/cjs/workflow/ask.js
CHANGED
|
@@ -134,18 +134,20 @@ class Ask extends _answerBased.default {
|
|
|
134
134
|
q,
|
|
135
135
|
qs
|
|
136
136
|
} = _ref,
|
|
137
|
-
|
|
137
|
+
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
138
138
|
const {
|
|
139
139
|
parentQuestionId
|
|
140
140
|
} = this;
|
|
141
|
-
|
|
141
|
+
let payload = (0, _commons.trimObj)(Object.assign({}, options, {
|
|
142
142
|
question: q,
|
|
143
143
|
// question, not q
|
|
144
144
|
parent_question_id: parentQuestionId,
|
|
145
|
-
_meta: Object.assign({},
|
|
145
|
+
_meta: Object.assign({}, options._meta, {
|
|
146
146
|
question_source: qs || _constants.ORGANIC_QUESTION_SOURCE // might be null, not undefined
|
|
147
147
|
})
|
|
148
148
|
}));
|
|
149
|
+
payload = this._writeWikiLinkTemplateToPayload(payload);
|
|
150
|
+
return payload;
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
// interactions //
|
|
@@ -20,17 +20,19 @@ function injectLogger(hub, callback) {
|
|
|
20
20
|
trigger
|
|
21
21
|
} = hub;
|
|
22
22
|
hub.update = (name, state, options) => {
|
|
23
|
+
const result = update.call(hub, name, state, options);
|
|
23
24
|
if (!options || !options.silent) {
|
|
24
25
|
callback('update', name, state, options);
|
|
25
26
|
}
|
|
26
|
-
return
|
|
27
|
+
return result;
|
|
27
28
|
};
|
|
28
29
|
hub.trigger = function () {
|
|
29
30
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
30
31
|
args[_key] = arguments[_key];
|
|
31
32
|
}
|
|
33
|
+
const result = trigger.apply(hub, args);
|
|
32
34
|
callback('trigger', ...args);
|
|
33
|
-
return
|
|
35
|
+
return result;
|
|
34
36
|
};
|
|
35
37
|
return hub;
|
|
36
38
|
}
|
|
@@ -85,6 +85,18 @@ class Explore extends _base.default {
|
|
|
85
85
|
}
|
|
86
86
|
return super.useApi(options);
|
|
87
87
|
}
|
|
88
|
+
useLink(fn, options) {
|
|
89
|
+
_useLink.UseLinkMixin.prototype.useLink.call(this, fn, options);
|
|
90
|
+
// also put options to layouts
|
|
91
|
+
if (options) {
|
|
92
|
+
this.useLayouts({
|
|
93
|
+
[_constants.ROLE.RELATED_QUESTIONS]: {
|
|
94
|
+
link: options
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
88
100
|
|
|
89
101
|
// lifecycle //
|
|
90
102
|
start() {
|
|
@@ -137,8 +149,7 @@ class Explore extends _base.default {
|
|
|
137
149
|
const related_questions = value.related_questions.map(linkFn ? text => ({
|
|
138
150
|
text,
|
|
139
151
|
url: this._getSubmitUrl({
|
|
140
|
-
q: text
|
|
141
|
-
}, {
|
|
152
|
+
q: text,
|
|
142
153
|
generated: true
|
|
143
154
|
})
|
|
144
155
|
}) : text => ({
|
|
@@ -166,14 +177,13 @@ class Explore extends _base.default {
|
|
|
166
177
|
this._hub.update(_index.fields.query(), args);
|
|
167
178
|
}
|
|
168
179
|
_query(args) {
|
|
169
|
-
this._submitToPage(args
|
|
180
|
+
this._submitToPage(Object.assign({}, args, {
|
|
181
|
+
generated: false
|
|
182
|
+
}));
|
|
170
183
|
}
|
|
171
184
|
_getSubmitUrl(args) {
|
|
172
|
-
let {
|
|
173
|
-
generated = false
|
|
174
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
175
185
|
let url = _useLink.UseLinkMixin.prototype._getSubmitUrl.call(this, args);
|
|
176
|
-
if (!generated || !this._productId) {
|
|
186
|
+
if (!args.generated || !this._productId) {
|
|
177
187
|
return url;
|
|
178
188
|
}
|
|
179
189
|
return `${url}&qs=${encodeURIComponent(this._productId)}`;
|
|
@@ -48,6 +48,7 @@ class HybridSearchAnswer extends _answerBased.default {
|
|
|
48
48
|
// query //
|
|
49
49
|
_buildPayload(payload) {
|
|
50
50
|
payload = this._writeQuestionSourceToPayload(payload);
|
|
51
|
+
payload = this._writeWikiLinkTemplateToPayload(payload);
|
|
51
52
|
payload = this._superworkflow._results._writeFiltersToPayload(payload);
|
|
52
53
|
return payload;
|
|
53
54
|
}
|
|
@@ -68,6 +69,8 @@ class HybridSearchAnswer extends _answerBased.default {
|
|
|
68
69
|
_defaultProcessData(data) {
|
|
69
70
|
data = super._defaultProcessData(data);
|
|
70
71
|
data = (0, _processors.writeKeywordsToData)(data);
|
|
72
|
+
data = (0, _processors.writeMisoIdFromSession)(data);
|
|
73
|
+
data = (0, _processors.writeUnanswerableToMeta)(data);
|
|
71
74
|
return data;
|
|
72
75
|
}
|
|
73
76
|
_updateDataInHub(data) {
|
|
@@ -82,6 +85,8 @@ class HybridSearchAnswer extends _answerBased.default {
|
|
|
82
85
|
}
|
|
83
86
|
_handleHeadResponse(data) {
|
|
84
87
|
super._handleHeadResponse(data);
|
|
88
|
+
// keep track of miso_id in session
|
|
89
|
+
(0, _processors.writeMisoIdToSession)(data);
|
|
85
90
|
// share the search results with its sibling
|
|
86
91
|
this._dispatchDataToSibling(data);
|
|
87
92
|
}
|
|
@@ -91,6 +96,14 @@ class HybridSearchAnswer extends _answerBased.default {
|
|
|
91
96
|
}));
|
|
92
97
|
}
|
|
93
98
|
|
|
99
|
+
// interactions //
|
|
100
|
+
_defaultProcessInteraction(payload, args) {
|
|
101
|
+
return this._superworkflow._defaultProcessInteraction(payload, args);
|
|
102
|
+
}
|
|
103
|
+
_defaultProcessInteraction0(payload, args) {
|
|
104
|
+
return super._defaultProcessInteraction(payload, args);
|
|
105
|
+
}
|
|
106
|
+
|
|
94
107
|
// destroy //
|
|
95
108
|
_destroy(options) {
|
|
96
109
|
this._destroyAutocomplete();
|
|
@@ -8,6 +8,7 @@ var _commons = require("@miso.ai/commons");
|
|
|
8
8
|
var _searchBased = _interopRequireDefault(require("./search-based.js"));
|
|
9
9
|
var _index = require("../actor/index.js");
|
|
10
10
|
var _constants = require("../constants.js");
|
|
11
|
+
var _processors = require("./processors.js");
|
|
11
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
13
|
// we want to override members, not adding to it
|
|
13
14
|
const ROLES_OPTIONS = Object.assign({}, _searchBased.default.ROLES_OPTIONS, {
|
|
@@ -66,6 +67,21 @@ class HybridSearchResults extends _searchBased.default {
|
|
|
66
67
|
}))
|
|
67
68
|
});
|
|
68
69
|
}
|
|
70
|
+
|
|
71
|
+
// data //
|
|
72
|
+
_defaultProcessData(data) {
|
|
73
|
+
data = super._defaultProcessData(data);
|
|
74
|
+
(0, _processors.writeMisoIdToSession)(data);
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// interactions //
|
|
79
|
+
_defaultProcessInteraction(payload, args) {
|
|
80
|
+
return this._superworkflow._defaultProcessInteraction(payload, args);
|
|
81
|
+
}
|
|
82
|
+
_defaultProcessInteraction0(payload, args) {
|
|
83
|
+
return super._defaultProcessInteraction(payload, args);
|
|
84
|
+
}
|
|
69
85
|
}
|
|
70
86
|
exports.default = HybridSearchResults;
|
|
71
87
|
Object.assign(HybridSearchResults, {
|
|
@@ -81,14 +81,7 @@ class HybridSearch extends _base.default {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
_initActors() {
|
|
84
|
-
const hub = this._hub;
|
|
85
|
-
const client = this._client;
|
|
86
|
-
const options = this._options;
|
|
87
84
|
this._views = new _hybridSearchViews.default(this);
|
|
88
|
-
this._interactions = new _index.InteractionsActor(hub, {
|
|
89
|
-
client,
|
|
90
|
-
options
|
|
91
|
-
});
|
|
92
85
|
}
|
|
93
86
|
_initSession() {
|
|
94
87
|
this._results._sessions.restart();
|
|
@@ -128,7 +121,9 @@ class HybridSearch extends _base.default {
|
|
|
128
121
|
|
|
129
122
|
// interactions //
|
|
130
123
|
_defaultProcessInteraction(payload, args) {
|
|
131
|
-
|
|
124
|
+
payload = this._answer._defaultProcessInteraction0(payload, args);
|
|
125
|
+
payload = this._results._defaultProcessInteraction0(payload, args);
|
|
126
|
+
return payload;
|
|
132
127
|
}
|
|
133
128
|
|
|
134
129
|
// destroy //
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DEFAULT_AUTO_QUERY_SOURCE_PARAM = exports.DEFAULT_AUTO_QUERY_PARAM = void 0;
|
|
7
|
+
exports.autoQuery = autoQuery;
|
|
8
|
+
exports.normalizeAutoQueryOptions = normalizeAutoQueryOptions;
|
|
9
|
+
var _commons = require("@miso.ai/commons");
|
|
10
|
+
var _constants = require("../../constants.js");
|
|
11
|
+
const _excluded = ["setValue", "focus", "updateUrl", "param", "sourceParam"];
|
|
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 DEFAULT_AUTO_QUERY_PARAM = exports.DEFAULT_AUTO_QUERY_PARAM = 'q';
|
|
14
|
+
const DEFAULT_AUTO_QUERY_SOURCE_PARAM = exports.DEFAULT_AUTO_QUERY_SOURCE_PARAM = 'qs';
|
|
15
|
+
function normalizeAutoQueryOptions() {
|
|
16
|
+
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
17
|
+
let {
|
|
18
|
+
setValue = true,
|
|
19
|
+
focus = true,
|
|
20
|
+
updateUrl = true,
|
|
21
|
+
param = DEFAULT_AUTO_QUERY_PARAM,
|
|
22
|
+
sourceParam = DEFAULT_AUTO_QUERY_SOURCE_PARAM
|
|
23
|
+
} = _ref,
|
|
24
|
+
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
25
|
+
return Object.assign({
|
|
26
|
+
setValue,
|
|
27
|
+
focus,
|
|
28
|
+
updateUrl,
|
|
29
|
+
param,
|
|
30
|
+
sourceParam
|
|
31
|
+
}, options);
|
|
32
|
+
}
|
|
33
|
+
function autoQuery() {
|
|
34
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
35
|
+
// TODO: support getting value from URL path
|
|
36
|
+
const {
|
|
37
|
+
setValue,
|
|
38
|
+
focus,
|
|
39
|
+
param,
|
|
40
|
+
sourceParam
|
|
41
|
+
} = this._autoQuery = normalizeAutoQueryOptions(options);
|
|
42
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
43
|
+
const q = searchParams.get(param);
|
|
44
|
+
const qs = searchParams.get(sourceParam) || undefined;
|
|
45
|
+
const {
|
|
46
|
+
layout
|
|
47
|
+
} = this._views.get(_constants.ROLE.QUERY);
|
|
48
|
+
if (layout) {
|
|
49
|
+
if (q && setValue) {
|
|
50
|
+
layout.value = q;
|
|
51
|
+
}
|
|
52
|
+
if (!q && focus) {
|
|
53
|
+
layout.focus();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (q) {
|
|
57
|
+
this.query((0, _commons.trimObj)({
|
|
58
|
+
q,
|
|
59
|
+
qs
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -112,4 +112,15 @@ Object.keys(_configurable).forEach(function (key) {
|
|
|
112
112
|
return _configurable[key];
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
|
+
});
|
|
116
|
+
var _autoQuery = require("./auto-query.js");
|
|
117
|
+
Object.keys(_autoQuery).forEach(function (key) {
|
|
118
|
+
if (key === "default" || key === "__esModule") return;
|
|
119
|
+
if (key in exports && exports[key] === _autoQuery[key]) return;
|
|
120
|
+
Object.defineProperty(exports, key, {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function () {
|
|
123
|
+
return _autoQuery[key];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
115
126
|
});
|