@miso.ai/client-sdk-ui 1.11.5-beta.1 → 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import AnswerBasedWorkflow from './answer-based.js';
|
|
2
2
|
import { ROLE, STATUS, ORGANIC_QUESTION_SOURCE } from '../constants.js';
|
|
3
3
|
import { mergeRolesOptions } from './options/index.js';
|
|
4
|
-
import { writeKeywordsToData } from './processors.js';
|
|
4
|
+
import { writeKeywordsToData, writeMisoIdToSession, writeMisoIdFromSession, writeUnanswerableToMeta } from './processors.js';
|
|
5
5
|
import { makeAutocompletable } from './autocompletable.js';
|
|
6
6
|
|
|
7
7
|
const ROLES_OPTIONS = mergeRolesOptions(AnswerBasedWorkflow.ROLES_OPTIONS, {
|
|
@@ -44,6 +44,7 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
|
|
|
44
44
|
// query //
|
|
45
45
|
_buildPayload(payload) {
|
|
46
46
|
payload = this._writeQuestionSourceToPayload(payload);
|
|
47
|
+
payload = this._writeWikiLinkTemplateToPayload(payload);
|
|
47
48
|
payload = this._superworkflow._results._writeFiltersToPayload(payload);
|
|
48
49
|
return payload;
|
|
49
50
|
}
|
|
@@ -62,6 +63,8 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
|
|
|
62
63
|
_defaultProcessData(data) {
|
|
63
64
|
data = super._defaultProcessData(data);
|
|
64
65
|
data = writeKeywordsToData(data);
|
|
66
|
+
data = writeMisoIdFromSession(data);
|
|
67
|
+
data = writeUnanswerableToMeta(data);
|
|
65
68
|
return data;
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -78,6 +81,8 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
|
|
|
78
81
|
|
|
79
82
|
_handleHeadResponse(data) {
|
|
80
83
|
super._handleHeadResponse(data);
|
|
84
|
+
// keep track of miso_id in session
|
|
85
|
+
writeMisoIdToSession(data);
|
|
81
86
|
// share the search results with its sibling
|
|
82
87
|
this._dispatchDataToSibling(data);
|
|
83
88
|
}
|
|
@@ -86,6 +91,15 @@ export default class HybridSearchAnswer extends AnswerBasedWorkflow {
|
|
|
86
91
|
this._resultsSession && this._superworkflow._results.updateData({ ...data, session: this._resultsSession });
|
|
87
92
|
}
|
|
88
93
|
|
|
94
|
+
// interactions //
|
|
95
|
+
_defaultProcessInteraction(payload, args) {
|
|
96
|
+
return this._superworkflow._defaultProcessInteraction(payload, args);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
_defaultProcessInteraction0(payload, args) {
|
|
100
|
+
return super._defaultProcessInteraction(payload, args);
|
|
101
|
+
}
|
|
102
|
+
|
|
89
103
|
// destroy //
|
|
90
104
|
_destroy(options) {
|
|
91
105
|
this._destroyAutocomplete();
|
|
@@ -2,6 +2,7 @@ import { trimObj } from '@miso.ai/commons';
|
|
|
2
2
|
import SearchBasedWorkflow from './search-based.js';
|
|
3
3
|
import { fields } from '../actor/index.js';
|
|
4
4
|
import { ROLE } from '../constants.js';
|
|
5
|
+
import { writeMisoIdToSession } from './processors.js';
|
|
5
6
|
|
|
6
7
|
// we want to override members, not adding to it
|
|
7
8
|
const ROLES_OPTIONS = {
|
|
@@ -69,6 +70,22 @@ export default class HybridSearchResults extends SearchBasedWorkflow {
|
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
// data //
|
|
74
|
+
_defaultProcessData(data) {
|
|
75
|
+
data = super._defaultProcessData(data);
|
|
76
|
+
writeMisoIdToSession(data);
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// interactions //
|
|
81
|
+
_defaultProcessInteraction(payload, args) {
|
|
82
|
+
return this._superworkflow._defaultProcessInteraction(payload, args);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_defaultProcessInteraction0(payload, args) {
|
|
86
|
+
return super._defaultProcessInteraction(payload, args);
|
|
87
|
+
}
|
|
88
|
+
|
|
72
89
|
}
|
|
73
90
|
|
|
74
91
|
Object.assign(HybridSearchResults, {
|
|
@@ -98,12 +98,7 @@ export default class HybridSearch extends Workflow {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
_initActors() {
|
|
101
|
-
const hub = this._hub;
|
|
102
|
-
const client = this._client;
|
|
103
|
-
const options = this._options;
|
|
104
|
-
|
|
105
101
|
this._views = new HybridSearchViewsActor(this);
|
|
106
|
-
this._interactions = new InteractionsActor(hub, { client, options });
|
|
107
102
|
}
|
|
108
103
|
|
|
109
104
|
_initSession() {
|
|
@@ -149,7 +144,9 @@ export default class HybridSearch extends Workflow {
|
|
|
149
144
|
|
|
150
145
|
// interactions //
|
|
151
146
|
_defaultProcessInteraction(payload, args) {
|
|
152
|
-
|
|
147
|
+
payload = this._answer._defaultProcessInteraction0(payload, args);
|
|
148
|
+
payload = this._results._defaultProcessInteraction0(payload, args);
|
|
149
|
+
return payload;
|
|
153
150
|
}
|
|
154
151
|
|
|
155
152
|
// destroy //
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { trimObj } from '@miso.ai/commons';
|
|
2
|
+
import { ROLE } from '../../constants.js';
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_AUTO_QUERY_PARAM = 'q';
|
|
5
|
+
export const DEFAULT_AUTO_QUERY_SOURCE_PARAM = 'qs';
|
|
6
|
+
|
|
7
|
+
export function normalizeAutoQueryOptions({ setValue = true, focus = true, updateUrl = true, param = DEFAULT_AUTO_QUERY_PARAM, sourceParam = DEFAULT_AUTO_QUERY_SOURCE_PARAM, ...options } = {}) {
|
|
8
|
+
return { setValue, focus, updateUrl, param, sourceParam, ...options };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function autoQuery(options = {}) {
|
|
12
|
+
// TODO: support getting value from URL path
|
|
13
|
+
const { setValue, focus, param, sourceParam } = this._autoQuery = normalizeAutoQueryOptions(options);
|
|
14
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
15
|
+
const q = searchParams.get(param);
|
|
16
|
+
const qs = searchParams.get(sourceParam) || undefined;
|
|
17
|
+
const { layout } = this._views.get(ROLE.QUERY);
|
|
18
|
+
if (layout) {
|
|
19
|
+
if (q && setValue) {
|
|
20
|
+
layout.value = q;
|
|
21
|
+
}
|
|
22
|
+
if (!q && focus) {
|
|
23
|
+
layout.focus();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (q) {
|
|
27
|
+
this.query(trimObj({ q, qs }));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -68,6 +68,36 @@ export function writeMisoIdToMeta(data) {
|
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
export function writeMisoIdToSession(data) {
|
|
72
|
+
const { session, value } = data;
|
|
73
|
+
if (!session || !value) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const { miso_id } = value;
|
|
77
|
+
if (!miso_id) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
session.meta.miso_id = miso_id;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function writeMisoIdFromSession(data) {
|
|
84
|
+
const { session, value } = data;
|
|
85
|
+
if (!session || !value) {
|
|
86
|
+
return data;
|
|
87
|
+
}
|
|
88
|
+
const { meta: { miso_id } = {} } = session;
|
|
89
|
+
if (!miso_id) {
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
...data,
|
|
94
|
+
meta: {
|
|
95
|
+
...data.meta,
|
|
96
|
+
miso_id,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
71
101
|
export function writeKeywordsToData(data) {
|
|
72
102
|
const { request, value } = data;
|
|
73
103
|
// we still want the value in loading status
|
|
@@ -230,6 +260,19 @@ export function writeAffiliationInfoToInteraction(payload, args) {
|
|
|
230
260
|
});
|
|
231
261
|
}
|
|
232
262
|
|
|
263
|
+
export function writeEventTargetToInteraction(payload, { event_target } = {}) {
|
|
264
|
+
if (!event_target) {
|
|
265
|
+
return payload;
|
|
266
|
+
}
|
|
267
|
+
return mergeInteraction(payload, {
|
|
268
|
+
context: {
|
|
269
|
+
custom_context: {
|
|
270
|
+
event_target,
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
233
276
|
export function mergeInteraction(base = {}, patch = {}) {
|
|
234
277
|
return trimObj({
|
|
235
278
|
...base,
|
|
@@ -244,3 +287,20 @@ export function mergeInteraction(base = {}, patch = {}) {
|
|
|
244
287
|
}),
|
|
245
288
|
});
|
|
246
289
|
}
|
|
290
|
+
|
|
291
|
+
export function writeUnanswerableToMeta(data) {
|
|
292
|
+
const { value } = data;
|
|
293
|
+
if (!value) {
|
|
294
|
+
return data;
|
|
295
|
+
}
|
|
296
|
+
if (!value.finished || value.finish_reason !== 'success' || (value.sources && value.sources.length > 0)) {
|
|
297
|
+
return data;
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
...data,
|
|
301
|
+
meta: {
|
|
302
|
+
...data.meta,
|
|
303
|
+
unanswerable: true,
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
}
|
|
@@ -4,7 +4,7 @@ import { fields } from '../actor/index.js';
|
|
|
4
4
|
import { STATUS, ROLE, WORKFLOW_CONFIGURABLE } from '../constants.js';
|
|
5
5
|
import { SearchBoxLayout, ListLayout, TextLayout, FacetsLayout, SelectLayout, MoreButtonLayout } from '../layout/index.js';
|
|
6
6
|
import { mappingSortData, writeKeywordsToData, retainFacetCountsInData, writeExhaustionToData, concatItemsFromMoreResponse } from './processors.js';
|
|
7
|
-
import { mergeRolesOptions, makeConfigurable, DEFAULT_TRACKER_OPTIONS } from './options/index.js';
|
|
7
|
+
import { mergeRolesOptions, autoQuery as autoQueryFn, makeConfigurable, DEFAULT_TRACKER_OPTIONS } from './options/index.js';
|
|
8
8
|
|
|
9
9
|
const DEFAULT_ROWS = 10;
|
|
10
10
|
const DEFAULT_PAGE_LIMIT = 10;
|
|
@@ -87,6 +87,10 @@ export default class SearchBasedWorkflow extends Workflow {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
// query //
|
|
90
|
+
autoQuery(options = {}) {
|
|
91
|
+
autoQueryFn.call(this, options);
|
|
92
|
+
}
|
|
93
|
+
|
|
90
94
|
query(args) {
|
|
91
95
|
if (!args.q) {
|
|
92
96
|
throw new Error(`q is required in query() call`);
|
package/src/workflow/search.js
CHANGED
|
@@ -57,23 +57,6 @@ export default class Search extends SearchBasedWorkflow {
|
|
|
57
57
|
this._initAutocomplete(args);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
autoQuery({ setValue = true, focus = true, param = 'q' } = {}) {
|
|
61
|
-
// TODO: align implementation with AnswerBasedWorkflow
|
|
62
|
-
const q = new URLSearchParams(window.location.search).get(param);
|
|
63
|
-
const { layout } = this._views.get(ROLE.QUERY);
|
|
64
|
-
if (layout) {
|
|
65
|
-
if (q && setValue) {
|
|
66
|
-
layout.value = q;
|
|
67
|
-
}
|
|
68
|
-
if (!q && focus) {
|
|
69
|
-
layout.focus();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (q) {
|
|
73
|
-
this.query({ q });
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
60
|
notifyViewUpdate(role = ROLE.PRODUCTS, ...args) {
|
|
78
61
|
super.notifyViewUpdate(role, ...args);
|
|
79
62
|
return this;
|
package/src/workflow/use-link.js
CHANGED
|
@@ -30,11 +30,11 @@ export class UseLinkMixin {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
_getSubmitUrl(args) {
|
|
33
|
+
_getSubmitUrl({ q, ...args } = {}) {
|
|
34
34
|
if (!this._linkFn) {
|
|
35
35
|
throw new Error('useLink(fn) must be called before _getSubmitUrl()');
|
|
36
36
|
}
|
|
37
|
-
return this._linkFn[0](args
|
|
37
|
+
return this._linkFn[0](q, args);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
}
|