@miso.ai/client-sdk-ui 1.13.2-beta.0 → 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.
- package/dist/cjs/asset/svgs.js +15 -4
- package/dist/cjs/combo/ask/index.js +2 -2
- package/dist/cjs/constants.js +118 -98
- package/dist/cjs/defaults/ask/controls.js +1 -1
- package/dist/cjs/defaults/hybrid-search/answer-box.js +4 -4
- package/dist/cjs/defaults.js +169 -0
- package/dist/cjs/element/container/index.js +14 -0
- package/dist/cjs/element/container/miso-ask.js +3 -3
- package/dist/cjs/element/container/miso-conversation.js +21 -0
- package/dist/cjs/element/container/miso-explore.js +1 -1
- package/dist/cjs/element/container/miso-history.js +21 -0
- package/dist/cjs/element/container/miso-hybrid-search.js +1 -1
- package/dist/cjs/element/container/miso-recommendation.js +1 -1
- package/dist/cjs/element/container/miso-search.js +1 -1
- package/dist/cjs/element/context/miso-follow-ups.js +1 -1
- package/dist/cjs/element/role/index.js +42 -0
- package/dist/cjs/element/role/miso-messages.js +20 -0
- package/dist/cjs/element/role/miso-new-thread.js +20 -0
- package/dist/cjs/element/role/miso-rename.js +20 -0
- package/dist/cjs/element/role/miso-subscription.js +20 -0
- package/dist/cjs/element/role/miso-threads.js +20 -0
- package/dist/cjs/element/role/miso-title.js +20 -0
- package/dist/cjs/layout/affiliation/affiliation.js +1 -1
- package/dist/cjs/layout/banner/banner.js +2 -1
- package/dist/cjs/layout/button/button.js +130 -0
- package/dist/cjs/layout/button/checkbox.js +115 -0
- package/dist/cjs/layout/button/more-button.js +3 -3
- package/dist/cjs/layout/container/container.js +1 -1
- package/dist/cjs/layout/error/error.js +2 -1
- package/dist/cjs/layout/index.js +28 -0
- package/dist/cjs/layout/input/facets.js +4 -3
- package/dist/cjs/layout/input/option-list.js +3 -2
- package/dist/cjs/layout/input/search-box.js +42 -9
- package/dist/cjs/layout/input/select.js +2 -1
- package/dist/cjs/layout/list/cards.js +2 -1
- package/dist/cjs/layout/list/carousel.js +2 -1
- package/dist/cjs/layout/list/collection.js +5 -0
- package/dist/cjs/layout/list/gallery.js +2 -1
- package/dist/cjs/layout/list/horizontal.js +2 -1
- package/dist/cjs/layout/list/list.js +2 -1
- package/dist/cjs/layout/list/messages.js +346 -0
- package/dist/cjs/layout/list/threads.js +257 -0
- package/dist/cjs/layout/mixin/trackable.js +4 -5
- package/dist/cjs/layout/mixin/triggerable.js +2 -2
- package/dist/cjs/layout/radio/feedback.js +4 -3
- package/dist/cjs/layout/templates.js +70 -0
- package/dist/cjs/layout/text/text.js +2 -1
- package/dist/cjs/layout/text/typewriter/index.js +4 -2
- package/dist/cjs/plugin.js +43 -104
- package/dist/cjs/util/confirm.js +33 -0
- package/dist/cjs/util/modal.js +48 -0
- package/dist/cjs/util/prompt.js +47 -0
- package/dist/cjs/version.js +1 -1
- package/package.json +5 -4
- package/src/CLAUDE.md +48 -105
- package/src/asset/svgs.js +14 -3
- package/src/combo/ask/index.js +2 -2
- package/src/constants.js +37 -147
- package/src/defaults/ask/controls.js +1 -1
- package/src/defaults/hybrid-search/answer-box.js +2 -2
- package/src/defaults.js +107 -0
- package/src/element/container/index.js +2 -0
- package/src/element/container/miso-ask.js +3 -3
- package/src/element/container/miso-conversation.js +19 -0
- package/src/element/container/miso-explore.js +1 -1
- package/src/element/container/miso-history.js +19 -0
- package/src/element/container/miso-hybrid-search.js +1 -1
- package/src/element/container/miso-recommendation.js +1 -1
- package/src/element/container/miso-search.js +1 -1
- package/src/element/context/miso-follow-ups.js +1 -1
- package/src/element/role/index.js +6 -0
- package/src/element/role/miso-messages.js +16 -0
- package/src/element/role/miso-new-thread.js +16 -0
- package/src/element/role/miso-rename.js +16 -0
- package/src/element/role/miso-subscription.js +16 -0
- package/src/element/role/miso-threads.js +16 -0
- package/src/element/role/miso-title.js +16 -0
- package/src/layout/affiliation/affiliation.js +2 -2
- package/src/layout/banner/banner.js +2 -1
- package/src/layout/button/button.js +116 -0
- package/src/layout/button/checkbox.js +91 -0
- package/src/layout/button/more-button.js +3 -3
- package/src/layout/container/container.js +2 -2
- package/src/layout/error/error.js +2 -1
- package/src/layout/index.js +4 -0
- package/src/layout/input/facets.js +3 -2
- package/src/layout/input/option-list.js +3 -2
- package/src/layout/input/search-box.js +41 -6
- package/src/layout/input/select.js +2 -1
- package/src/layout/list/cards.js +2 -1
- package/src/layout/list/carousel.js +2 -1
- package/src/layout/list/collection.js +6 -1
- package/src/layout/list/gallery.js +2 -1
- package/src/layout/list/horizontal.js +2 -1
- package/src/layout/list/list.js +2 -1
- package/src/layout/list/messages.js +318 -0
- package/src/layout/list/threads.js +206 -0
- package/src/layout/mixin/trackable.js +2 -3
- package/src/layout/mixin/triggerable.js +1 -1
- package/src/layout/radio/feedback.js +3 -2
- package/src/layout/templates.js +62 -0
- package/src/layout/text/text.js +2 -1
- package/src/layout/text/typewriter/index.js +5 -3
- package/src/plugin.js +31 -117
- package/src/util/confirm.js +28 -0
- package/src/util/modal.js +49 -0
- package/src/util/prompt.js +42 -0
- package/src/version.js +1 -1
- package/dist/cjs/actor/data.js +0 -132
- package/dist/cjs/actor/feedback.js +0 -29
- package/dist/cjs/actor/fields.js +0 -57
- package/dist/cjs/actor/filters.js +0 -161
- package/dist/cjs/actor/hub.js +0 -57
- package/dist/cjs/actor/index.js +0 -73
- package/dist/cjs/actor/interactions.js +0 -36
- package/dist/cjs/actor/sessions.js +0 -25
- package/dist/cjs/actor/tracker-states.js +0 -61
- package/dist/cjs/actor/tracker.js +0 -109
- package/dist/cjs/actor/trackers.js +0 -52
- package/dist/cjs/actor/utils.js +0 -15
- package/dist/cjs/actor/view.js +0 -294
- package/dist/cjs/actor/views.js +0 -209
- package/dist/cjs/source.js +0 -27
- package/dist/cjs/util/proxy.js +0 -88
- package/dist/cjs/util/trackers.js +0 -88
- package/dist/cjs/workflow/affiliations.js +0 -140
- package/dist/cjs/workflow/answer-based.js +0 -337
- package/dist/cjs/workflow/ask.js +0 -319
- package/dist/cjs/workflow/asks.js +0 -150
- package/dist/cjs/workflow/autocompletable.js +0 -63
- package/dist/cjs/workflow/autocomplete.js +0 -120
- package/dist/cjs/workflow/base.js +0 -418
- package/dist/cjs/workflow/context.js +0 -19
- package/dist/cjs/workflow/explore.js +0 -210
- package/dist/cjs/workflow/explores.js +0 -21
- package/dist/cjs/workflow/hybrid-search-answer.js +0 -88
- package/dist/cjs/workflow/hybrid-search-views.js +0 -109
- package/dist/cjs/workflow/hybrid-search.js +0 -213
- package/dist/cjs/workflow/index.js +0 -41
- package/dist/cjs/workflow/options/api.js +0 -41
- package/dist/cjs/workflow/options/auto-query.js +0 -97
- package/dist/cjs/workflow/options/configurable.js +0 -45
- package/dist/cjs/workflow/options/data-processor.js +0 -20
- package/dist/cjs/workflow/options/filters.js +0 -15
- package/dist/cjs/workflow/options/index.js +0 -126
- package/dist/cjs/workflow/options/interactions.js +0 -41
- package/dist/cjs/workflow/options/layouts.js +0 -79
- package/dist/cjs/workflow/options/options.js +0 -156
- package/dist/cjs/workflow/options/pagination.js +0 -25
- package/dist/cjs/workflow/options/roles.js +0 -15
- package/dist/cjs/workflow/options/templates.js +0 -30
- package/dist/cjs/workflow/options/trackers.js +0 -83
- package/dist/cjs/workflow/options/utils.js +0 -33
- package/dist/cjs/workflow/processors.js +0 -607
- package/dist/cjs/workflow/recommendation.js +0 -57
- package/dist/cjs/workflow/recommendations.js +0 -18
- package/dist/cjs/workflow/search-based.js +0 -337
- package/dist/cjs/workflow/search.js +0 -64
- package/dist/cjs/workflow/unit.js +0 -57
- package/dist/cjs/workflow/units.js +0 -42
- package/dist/cjs/workflow/use-link.js +0 -49
- package/src/actor/data.js +0 -106
- package/src/actor/feedback.js +0 -28
- package/src/actor/fields.js +0 -51
- package/src/actor/filters.js +0 -149
- package/src/actor/hub.js +0 -47
- package/src/actor/index.js +0 -10
- package/src/actor/interactions.js +0 -32
- package/src/actor/sessions.js +0 -21
- package/src/actor/tracker-states.js +0 -57
- package/src/actor/tracker.js +0 -104
- package/src/actor/trackers.js +0 -45
- package/src/actor/utils.js +0 -7
- package/src/actor/view.js +0 -272
- package/src/actor/views.js +0 -224
- package/src/source.js +0 -17
- package/src/util/proxy.js +0 -81
- package/src/util/trackers.js +0 -84
- package/src/workflow/affiliations.js +0 -121
- package/src/workflow/answer-based.js +0 -312
- package/src/workflow/ask.js +0 -284
- package/src/workflow/asks.js +0 -143
- package/src/workflow/autocompletable.js +0 -67
- package/src/workflow/autocomplete.js +0 -114
- package/src/workflow/base.js +0 -396
- package/src/workflow/context.js +0 -16
- package/src/workflow/explore.js +0 -194
- package/src/workflow/explores.js +0 -18
- package/src/workflow/hybrid-search-answer.js +0 -73
- package/src/workflow/hybrid-search-views.js +0 -116
- package/src/workflow/hybrid-search.js +0 -230
- package/src/workflow/index.js +0 -5
- package/src/workflow/options/api.js +0 -31
- package/src/workflow/options/auto-query.js +0 -70
- package/src/workflow/options/configurable.js +0 -48
- package/src/workflow/options/data-processor.js +0 -15
- package/src/workflow/options/filters.js +0 -10
- package/src/workflow/options/index.js +0 -11
- package/src/workflow/options/interactions.js +0 -36
- package/src/workflow/options/layouts.js +0 -73
- package/src/workflow/options/options.js +0 -175
- package/src/workflow/options/pagination.js +0 -18
- package/src/workflow/options/roles.js +0 -12
- package/src/workflow/options/templates.js +0 -27
- package/src/workflow/options/trackers.js +0 -80
- package/src/workflow/options/utils.js +0 -26
- package/src/workflow/processors.js +0 -490
- package/src/workflow/recommendation.js +0 -63
- package/src/workflow/recommendations.js +0 -14
- package/src/workflow/search-based.js +0 -329
- package/src/workflow/search.js +0 -73
- package/src/workflow/unit.js +0 -51
- package/src/workflow/units.js +0 -43
- package/src/workflow/use-link.js +0 -41
|
@@ -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 _processors = require("./processors.js");
|
|
13
|
-
var _index3 = require("./options/index.js");
|
|
14
|
-
var _useLink = require("./use-link.js");
|
|
15
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
const DEFAULT_ROWS = 10;
|
|
17
|
-
const DEFAULT_PAGE_LIMIT = 10;
|
|
18
|
-
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_API_OPTIONS, {
|
|
19
|
-
group: _commons.API.GROUP.SEARCH,
|
|
20
|
-
payload: Object.assign({}, _base.default.DEFAULT_API_OPTIONS.payload, {
|
|
21
|
-
fl: ['cover_image', 'url', 'created_at', 'updated_at', 'published_at', 'title'],
|
|
22
|
-
rows: DEFAULT_ROWS
|
|
23
|
-
})
|
|
24
|
-
}));
|
|
25
|
-
function totalContent(layout, {
|
|
26
|
-
value
|
|
27
|
-
}) {
|
|
28
|
-
if (value === undefined) {
|
|
29
|
-
return '';
|
|
30
|
-
}
|
|
31
|
-
const {
|
|
32
|
-
formatNumber
|
|
33
|
-
} = layout.templates.helpers;
|
|
34
|
-
const formatted = formatNumber(value);
|
|
35
|
-
const label = value === 1 ? 'result' : 'results';
|
|
36
|
-
return `${formatted} ${label}`;
|
|
37
|
-
}
|
|
38
|
-
const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LAYOUTS, {
|
|
39
|
-
[_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type],
|
|
40
|
-
[_constants.ROLE.PRODUCTS]: [_index2.ListLayout.type, {
|
|
41
|
-
incremental: true,
|
|
42
|
-
infiniteScroll: true
|
|
43
|
-
}],
|
|
44
|
-
[_constants.ROLE.KEYWORDS]: [_index2.TextLayout.type, {
|
|
45
|
-
raw: true
|
|
46
|
-
}],
|
|
47
|
-
[_constants.ROLE.TOTAL]: [_index2.TextLayout.type, {
|
|
48
|
-
raw: true,
|
|
49
|
-
templates: {
|
|
50
|
-
content: totalContent
|
|
51
|
-
}
|
|
52
|
-
}],
|
|
53
|
-
[_constants.ROLE.FACETS]: [_index2.FacetsLayout.type],
|
|
54
|
-
[_constants.ROLE.SORT]: [_index2.SelectLayout.type],
|
|
55
|
-
[_constants.ROLE.MORE]: [_index2.MoreButtonLayout.type]
|
|
56
|
-
}));
|
|
57
|
-
const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _base.default.DEFAULT_TRACKERS, {
|
|
58
|
-
[_constants.ROLE.PRODUCTS]: _index3.DEFAULT_TRACKER_OPTIONS
|
|
59
|
-
}));
|
|
60
|
-
const DEFAULT_PAGINATION = Object.freeze({
|
|
61
|
-
active: false,
|
|
62
|
-
mode: 'infiniteScroll',
|
|
63
|
-
pageLimit: 10
|
|
64
|
-
});
|
|
65
|
-
const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_OPTIONS, {
|
|
66
|
-
api: DEFAULT_API_OPTIONS,
|
|
67
|
-
layouts: DEFAULT_LAYOUTS,
|
|
68
|
-
trackers: DEFAULT_TRACKERS,
|
|
69
|
-
pagination: DEFAULT_PAGINATION
|
|
70
|
-
}));
|
|
71
|
-
const ROLES_OPTIONS = (0, _index3.mergeRolesOptions)(_base.default.ROLES_OPTIONS, {
|
|
72
|
-
main: _constants.ROLE.PRODUCTS,
|
|
73
|
-
members: Object.keys(DEFAULT_LAYOUTS),
|
|
74
|
-
mappings: {
|
|
75
|
-
[_constants.ROLE.FACETS]: 'facet_counts',
|
|
76
|
-
[_constants.ROLE.SORT]: _processors.mappingSortData
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
class SearchBasedWorkflow extends _base.default {
|
|
80
|
-
_initSubscriptions(args) {
|
|
81
|
-
super._initSubscriptions(args);
|
|
82
|
-
this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.query(), args => this._query(args)), this._hub.on(_index.fields.filters(), () => this._refine()), this._hub.on(_index.fields.more(), () => this._more()), this._views.on(_constants.ROLE.SORT, 'select', event => this._handleSortSelect(event))];
|
|
83
|
-
}
|
|
84
|
-
restart() {
|
|
85
|
-
super.restart();
|
|
86
|
-
this._page = 0;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// properties //
|
|
90
|
-
get exhausted() {
|
|
91
|
-
const data = this._hub.states[_index.fields.data()];
|
|
92
|
-
return !!(data && data.meta && data.meta.exhausted);
|
|
93
|
-
}
|
|
94
|
-
get page() {
|
|
95
|
-
return this._page;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// query //
|
|
99
|
-
autoQuery(options = {}) {
|
|
100
|
-
_index3.autoQuery.call(this, options);
|
|
101
|
-
}
|
|
102
|
-
query(args) {
|
|
103
|
-
if (!args.q) {
|
|
104
|
-
throw new Error(`q is required in query() call`);
|
|
105
|
-
}
|
|
106
|
-
this._hub.update(_index.fields.query(), args);
|
|
107
|
-
}
|
|
108
|
-
_query(args) {
|
|
109
|
-
if (this._linkFn) {
|
|
110
|
-
this._submitToPage(args);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const type = _constants.REQUEST_TYPE.QUERY;
|
|
114
|
-
|
|
115
|
-
// reset filters view
|
|
116
|
-
this._views.filters.reset({
|
|
117
|
-
silent: true
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// start a new session
|
|
121
|
-
this.restart({
|
|
122
|
-
type
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// payload
|
|
126
|
-
const payload = this._buildPayload(args, type);
|
|
127
|
-
this._request({
|
|
128
|
-
payload,
|
|
129
|
-
type
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
_refine() {
|
|
133
|
-
const type = _constants.REQUEST_TYPE.REFINE;
|
|
134
|
-
|
|
135
|
-
// remember current facet_counts
|
|
136
|
-
const {
|
|
137
|
-
facet_counts
|
|
138
|
-
} = this._hub.states[_index.fields.data()].value || {};
|
|
139
|
-
this._currentFacetCounts = facet_counts;
|
|
140
|
-
|
|
141
|
-
// start a new session
|
|
142
|
-
this.restart({
|
|
143
|
-
type
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// payload
|
|
147
|
-
const query = this._getQuery();
|
|
148
|
-
const payload = this._buildPayload(query, type);
|
|
149
|
-
this._request({
|
|
150
|
-
payload,
|
|
151
|
-
type
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// TODO: expose API
|
|
156
|
-
_more() {
|
|
157
|
-
// if still loading, complain
|
|
158
|
-
if (this.status !== _constants.STATUS.READY) {
|
|
159
|
-
throw new Error(`Can not call more() while loading.`);
|
|
160
|
-
}
|
|
161
|
-
// no more pages, ignore
|
|
162
|
-
if (this.exhausted || this._page >= DEFAULT_PAGE_LIMIT - 1) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
// don't create a new session!
|
|
166
|
-
|
|
167
|
-
this._page++;
|
|
168
|
-
|
|
169
|
-
// payload
|
|
170
|
-
const type = _constants.REQUEST_TYPE.MORE;
|
|
171
|
-
const query = this._getQuery();
|
|
172
|
-
const payload = this._buildPayload(query, type);
|
|
173
|
-
this._request({
|
|
174
|
-
payload,
|
|
175
|
-
type
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
_getQuery() {
|
|
179
|
-
return this._hub.states[_index.fields.query()];
|
|
180
|
-
}
|
|
181
|
-
_getPageSize() {
|
|
182
|
-
return this._options.resolved.api.payload.rows;
|
|
183
|
-
}
|
|
184
|
-
_buildPayload(payload, type) {
|
|
185
|
-
payload = this._writeFiltersToPayload(payload);
|
|
186
|
-
payload = this._writePageInfoToPayload(payload);
|
|
187
|
-
if (type === _constants.REQUEST_TYPE.MORE) {
|
|
188
|
-
payload = this._processPayloadForMoreRequest(payload);
|
|
189
|
-
}
|
|
190
|
-
return payload;
|
|
191
|
-
}
|
|
192
|
-
_writeFiltersToPayload(payload) {
|
|
193
|
-
const filters = this._hub.states[_index.fields.filters()];
|
|
194
|
-
const {
|
|
195
|
-
facets,
|
|
196
|
-
sort
|
|
197
|
-
} = filters || {};
|
|
198
|
-
return (0, _commons.trimObj)(Object.assign({}, payload, {
|
|
199
|
-
facet_filters: this._buildFacetFilters(facets),
|
|
200
|
-
order_by: this._buildOrderBy(sort)
|
|
201
|
-
}));
|
|
202
|
-
}
|
|
203
|
-
_buildFacetFilters(facets) {
|
|
204
|
-
if (!facets) {
|
|
205
|
-
return undefined;
|
|
206
|
-
}
|
|
207
|
-
const filters = {};
|
|
208
|
-
for (const field in facets) {
|
|
209
|
-
const values = facets[field];
|
|
210
|
-
if (!values || !values.length) {
|
|
211
|
-
continue; // just in case
|
|
212
|
-
}
|
|
213
|
-
filters[field] = {
|
|
214
|
-
terms: values
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
return Object.keys(filters).length ? filters : undefined;
|
|
218
|
-
}
|
|
219
|
-
_buildOrderBy(sort) {
|
|
220
|
-
if (!sort) {
|
|
221
|
-
return undefined;
|
|
222
|
-
}
|
|
223
|
-
return (0, _commons.asArray)(sort);
|
|
224
|
-
}
|
|
225
|
-
_writePageInfoToPayload(payload) {
|
|
226
|
-
return Object.assign({}, payload, {
|
|
227
|
-
metadata: Object.assign({}, payload.metadata, {
|
|
228
|
-
page: this._page
|
|
229
|
-
})
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
_processPayloadForMoreRequest(payload = {}) {
|
|
233
|
-
const data = this._hub.states[_index.fields.data()];
|
|
234
|
-
const {
|
|
235
|
-
[this._roles.main]: items = []
|
|
236
|
-
} = data && data.value || {};
|
|
237
|
-
const productIds = items.map(item => item.product_id).filter(v => v);
|
|
238
|
-
const exclude = [...(payload.exclude || []), ...productIds];
|
|
239
|
-
if (exclude.length === 0) {
|
|
240
|
-
return payload;
|
|
241
|
-
}
|
|
242
|
-
return Object.assign({}, payload, {
|
|
243
|
-
exclude
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
_writeRequestTimeToSession(timestamp, options = {}) {
|
|
247
|
-
if (options.type !== _constants.REQUEST_TYPE.QUERY) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
super._writeRequestTimeToSession(timestamp, options);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// data //
|
|
254
|
-
_defaultProcessData(data, oldData) {
|
|
255
|
-
data = super._defaultProcessData(data, oldData);
|
|
256
|
-
data = (0, _processors.writeKeywordsToData)(data);
|
|
257
|
-
data = (0, _processors.retainFacetCountsInData)(data, this._currentFacetCounts);
|
|
258
|
-
data = (0, _processors.writeExhaustionToData)(data, {
|
|
259
|
-
role: this._roles.main
|
|
260
|
-
});
|
|
261
|
-
return data;
|
|
262
|
-
}
|
|
263
|
-
_updateData(data) {
|
|
264
|
-
super._updateData(data);
|
|
265
|
-
_index3.updateQueryParametersInUrl.call(this, data);
|
|
266
|
-
}
|
|
267
|
-
_updateDataInHub(data, oldData) {
|
|
268
|
-
data = this._appendResultsFromMoreRequest(data);
|
|
269
|
-
super._updateDataInHub(data, oldData);
|
|
270
|
-
}
|
|
271
|
-
_appendResultsFromMoreRequest(data) {
|
|
272
|
-
const {
|
|
273
|
-
request
|
|
274
|
-
} = data;
|
|
275
|
-
if (!request) {
|
|
276
|
-
return data; // the initial state
|
|
277
|
-
}
|
|
278
|
-
const {
|
|
279
|
-
metadata
|
|
280
|
-
} = request.payload;
|
|
281
|
-
if (!metadata || !metadata.page) {
|
|
282
|
-
return (0, _processors.writeMisoIdAsRootMisoId)(data); // not from "more" request
|
|
283
|
-
}
|
|
284
|
-
// concat records if it's from "more" request
|
|
285
|
-
const currentData = this._hub.states[_index.fields.data()];
|
|
286
|
-
return (0, _processors.concatItemsFromMoreResponse)(currentData, data, {
|
|
287
|
-
role: this._roles.main
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// view actions //
|
|
292
|
-
_handleSortSelect({
|
|
293
|
-
value
|
|
294
|
-
} = {}) {
|
|
295
|
-
if (!value) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
this._views.filters.update({
|
|
299
|
-
sort: value
|
|
300
|
-
});
|
|
301
|
-
this._views.filters.apply();
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// interactions //
|
|
305
|
-
_defaultProcessInteraction(payload, args) {
|
|
306
|
-
payload = super._defaultProcessInteraction(payload, args);
|
|
307
|
-
payload = this._writeRootMisoIdToInteraction(payload);
|
|
308
|
-
return payload;
|
|
309
|
-
}
|
|
310
|
-
_writeRootMisoIdToInteraction(payload) {
|
|
311
|
-
const data = this._hub.states[_index.fields.data()];
|
|
312
|
-
const {
|
|
313
|
-
root_miso_id
|
|
314
|
-
} = data && data.value || {};
|
|
315
|
-
if (!root_miso_id) {
|
|
316
|
-
return payload;
|
|
317
|
-
}
|
|
318
|
-
return (0, _commons.mergeInteractions)(payload, {
|
|
319
|
-
context: {
|
|
320
|
-
custom_context: {
|
|
321
|
-
root_miso_id
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
exports.default = SearchBasedWorkflow;
|
|
328
|
-
(0, _index3.makeConfigurable)(SearchBasedWorkflow.prototype, [_constants.WORKFLOW_CONFIGURABLE.PAGINATION, _constants.WORKFLOW_CONFIGURABLE.FILTERS]);
|
|
329
|
-
(0, _useLink.enableUseLink)(SearchBasedWorkflow.prototype);
|
|
330
|
-
Object.assign(SearchBasedWorkflow, {
|
|
331
|
-
DEFAULT_API_OPTIONS,
|
|
332
|
-
DEFAULT_LAYOUTS,
|
|
333
|
-
DEFAULT_TRACKERS,
|
|
334
|
-
DEFAULT_PAGINATION,
|
|
335
|
-
DEFAULT_OPTIONS,
|
|
336
|
-
ROLES_OPTIONS
|
|
337
|
-
});
|
|
@@ -1,64 +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 _constants = require("../constants.js");
|
|
9
|
-
var _searchBased = _interopRequireDefault(require("./search-based.js"));
|
|
10
|
-
var _autocompletable = require("./autocompletable.js");
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
const DEFAULT_API_OPTIONS = Object.freeze({
|
|
13
|
-
group: _commons.API.GROUP.SEARCH,
|
|
14
|
-
name: _commons.API.NAME.SEARCH,
|
|
15
|
-
payload: {
|
|
16
|
-
fl: ['*']
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
|
|
20
|
-
api: {
|
|
21
|
-
group: _commons.API.GROUP.SEARCH,
|
|
22
|
-
name: _commons.API.NAME.AUTOCOMPLETE,
|
|
23
|
-
payload: {
|
|
24
|
-
completion_fields: ['suggested_queries', 'title'],
|
|
25
|
-
fl: ['title', 'url', 'cover_image']
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _searchBased.default.DEFAULT_LAYOUTS));
|
|
30
|
-
const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _searchBased.default.DEFAULT_TRACKERS));
|
|
31
|
-
const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _searchBased.default.DEFAULT_OPTIONS, {
|
|
32
|
-
api: DEFAULT_API_OPTIONS,
|
|
33
|
-
autocomplete: DEFAULT_AUTOCOMPLETE_OPTIONS,
|
|
34
|
-
layouts: DEFAULT_LAYOUTS,
|
|
35
|
-
trackers: DEFAULT_TRACKERS
|
|
36
|
-
}));
|
|
37
|
-
const ROLES_OPTIONS = _searchBased.default.ROLES_OPTIONS;
|
|
38
|
-
class Search extends _searchBased.default {
|
|
39
|
-
constructor(plugin, client) {
|
|
40
|
-
super({
|
|
41
|
-
name: 'search',
|
|
42
|
-
plugin,
|
|
43
|
-
client,
|
|
44
|
-
roles: ROLES_OPTIONS,
|
|
45
|
-
defaults: DEFAULT_OPTIONS
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
_initProperties(args) {
|
|
49
|
-
super._initProperties(args);
|
|
50
|
-
this._initAutocomplete(args);
|
|
51
|
-
}
|
|
52
|
-
notifyViewUpdate(role = _constants.ROLE.PRODUCTS, ...args) {
|
|
53
|
-
super.notifyViewUpdate(role, ...args);
|
|
54
|
-
return this;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// destroy //
|
|
58
|
-
_destroy(options) {
|
|
59
|
-
this._destroyAutocomplete();
|
|
60
|
-
super._destroy(options);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.default = Search;
|
|
64
|
-
(0, _autocompletable.makeAutocompletable)(Search.prototype);
|
|
@@ -1,57 +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
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
class UnitWorkflow extends _base.default {
|
|
11
|
-
_initProperties(args) {
|
|
12
|
-
super._initProperties(args);
|
|
13
|
-
const {
|
|
14
|
-
id
|
|
15
|
-
} = args;
|
|
16
|
-
(0, _commons.defineValues)(this, {
|
|
17
|
-
id
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
_initSession(args) {
|
|
21
|
-
this._context._members.set(args.id, this);
|
|
22
|
-
super._initSession(args);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// interactions //
|
|
26
|
-
_defaultProcessInteraction(payload, args) {
|
|
27
|
-
payload = super._defaultProcessInteraction(payload, args);
|
|
28
|
-
payload = this._writeUnitIdToInteraction(payload, args);
|
|
29
|
-
return payload;
|
|
30
|
-
}
|
|
31
|
-
_writeUnitIdToInteraction(payload) {
|
|
32
|
-
const unit_id = this.id;
|
|
33
|
-
const unit_instance_uuid = this.uuid;
|
|
34
|
-
return (0, _commons.mergeInteractions)(payload, {
|
|
35
|
-
context: {
|
|
36
|
-
custom_context: {
|
|
37
|
-
unit_id,
|
|
38
|
-
unit_instance_uuid
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// destroy //
|
|
45
|
-
_destroy(options) {
|
|
46
|
-
this._context._members.delete(this.id);
|
|
47
|
-
super._destroy(options);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.default = UnitWorkflow;
|
|
51
|
-
Object.assign(UnitWorkflow, {
|
|
52
|
-
DEFAULT_API_OPTIONS: _base.default.DEFAULT_API_OPTIONS,
|
|
53
|
-
DEFAULT_LAYOUTS: _base.default.DEFAULT_LAYOUTS,
|
|
54
|
-
DEFAULT_TRACKERS: _base.default.DEFAULT_TRACKERS,
|
|
55
|
-
DEFAULT_OPTIONS: _base.default.DEFAULT_OPTIONS,
|
|
56
|
-
ROLES_OPTIONS: _base.default.ROLES_OPTIONS
|
|
57
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
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 _context = _interopRequireDefault(require("./context.js"));
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
class UnitWorkflowContext extends _context.default {
|
|
11
|
-
constructor(name, plugin, client) {
|
|
12
|
-
super(name, plugin, client);
|
|
13
|
-
this._members = new Map();
|
|
14
|
-
}
|
|
15
|
-
workflows() {
|
|
16
|
-
return [...this._members.values()];
|
|
17
|
-
}
|
|
18
|
-
create(unitId = _constants.DEFAULT_UNIT_ID) {
|
|
19
|
-
if (this._members.has(unitId)) {
|
|
20
|
-
throw new Error(`Unit already exists: ${unitId}`);
|
|
21
|
-
}
|
|
22
|
-
return this._createAndEmit(unitId);
|
|
23
|
-
}
|
|
24
|
-
has(unitId = _constants.DEFAULT_UNIT_ID) {
|
|
25
|
-
return this._members.has(unitId);
|
|
26
|
-
}
|
|
27
|
-
get(unitId = _constants.DEFAULT_UNIT_ID) {
|
|
28
|
-
if (typeof unitId !== 'string') {
|
|
29
|
-
throw new Error(`Required unit ID to be a string: ${unitId}`);
|
|
30
|
-
}
|
|
31
|
-
return this._members.get(unitId) || this._createAndEmit(unitId);
|
|
32
|
-
}
|
|
33
|
-
_createAndEmit(unitId) {
|
|
34
|
-
const workflow = this._create(unitId);
|
|
35
|
-
this._client._events.emit('postworkflow', workflow);
|
|
36
|
-
return workflow;
|
|
37
|
-
}
|
|
38
|
-
_create(unitId) {
|
|
39
|
-
throw new Error('Not implemented');
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.default = UnitWorkflowContext;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.UseLinkMixin = void 0;
|
|
7
|
-
exports.enableUseLink = enableUseLink;
|
|
8
|
-
var _commons = require("@miso.ai/commons");
|
|
9
|
-
const _excluded = ["q"];
|
|
10
|
-
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; }
|
|
11
|
-
// TODO: eliminate browser dependency
|
|
12
|
-
|
|
13
|
-
function enableUseLink(prototype) {
|
|
14
|
-
(0, _commons.mixin)(prototype, UseLinkMixin.prototype);
|
|
15
|
-
}
|
|
16
|
-
class UseLinkMixin {
|
|
17
|
-
useLink(fn, options = {}) {
|
|
18
|
-
if (typeof fn !== 'function' && fn !== false) {
|
|
19
|
-
throw new Error('useLink(fn) expects fn to be a function or false');
|
|
20
|
-
}
|
|
21
|
-
this._linkFn = fn ? [fn, options] : false;
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
_submitToPage(args = {}) {
|
|
25
|
-
if (!this._linkFn) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const url = this._getSubmitUrl(args);
|
|
29
|
-
const [_, options = {}] = this._linkFn;
|
|
30
|
-
if (options.open === false) {
|
|
31
|
-
window.location.href = url;
|
|
32
|
-
} else {
|
|
33
|
-
const target = options.target || '_blank';
|
|
34
|
-
const windowFeatures = options.windowFeatures || 'noopener';
|
|
35
|
-
window.open(url, target, windowFeatures);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
_getSubmitUrl(_ref = {}) {
|
|
39
|
-
let {
|
|
40
|
-
q
|
|
41
|
-
} = _ref,
|
|
42
|
-
args = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
43
|
-
if (!this._linkFn) {
|
|
44
|
-
throw new Error('useLink(fn) must be called before _getSubmitUrl()');
|
|
45
|
-
}
|
|
46
|
-
return this._linkFn[0](q, args);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.UseLinkMixin = UseLinkMixin;
|
package/src/actor/data.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import * as fields from './fields.js';
|
|
2
|
-
import { isCurrentSession } from './utils.js';
|
|
3
|
-
|
|
4
|
-
export default class DataActor {
|
|
5
|
-
|
|
6
|
-
constructor(hub, { source, options, polling = true }) {
|
|
7
|
-
this._hub = hub;
|
|
8
|
-
this._source = source;
|
|
9
|
-
this._options = options;
|
|
10
|
-
this._polling = polling;
|
|
11
|
-
this._unsubscribes = [
|
|
12
|
-
hub.on(fields.session(), session => this._handleSession(session)),
|
|
13
|
-
hub.on(fields.request(), event => this._handleRequest(event)),
|
|
14
|
-
];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get active() {
|
|
18
|
-
return this._options.resolved.api.actor !== false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get source() {
|
|
22
|
-
return this._source;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
_handleSession(session) {
|
|
26
|
-
// this is mandatory in any case
|
|
27
|
-
/*
|
|
28
|
-
if (!this.active) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
*/
|
|
32
|
-
// abort ongoing data fetch if any
|
|
33
|
-
if (!this._session || (session.index !== this._session.index)) {
|
|
34
|
-
// new session, abort preview data fetch if necessary
|
|
35
|
-
this._ac && this._ac.abort({
|
|
36
|
-
type: 'new-session',
|
|
37
|
-
message: 'A new session is created, discarding the old one.',
|
|
38
|
-
});
|
|
39
|
-
this._ac = new AbortController();
|
|
40
|
-
}
|
|
41
|
-
this._session = session;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async _handleRequest(event) {
|
|
45
|
-
// protocol: inactive -> no reaction
|
|
46
|
-
if (!this.active) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const { session, ...request } = event;
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const { signal } = this._ac || {};
|
|
53
|
-
const options = { ...event.options, signal };
|
|
54
|
-
const response = await this._source({ session, ...request, options });
|
|
55
|
-
// takes an iterable, either sync or async
|
|
56
|
-
if (response && response[Symbol.asyncIterator]) {
|
|
57
|
-
// also emit reponse of the head request, if available
|
|
58
|
-
if (response._response) {
|
|
59
|
-
this._emitResponseWithSessionCheck({ session, request, value: response._response });
|
|
60
|
-
}
|
|
61
|
-
if (this._polling) {
|
|
62
|
-
let value;
|
|
63
|
-
for await (value of response) {
|
|
64
|
-
// A new session invalidates ongoing data fetch for the old session, terminating the loop
|
|
65
|
-
if (!isCurrentSession(this._hub, session)) {
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
this._emitResponse({ session, request, value });
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
this._emitResponseWithSessionCheck({ session, request, value: response });
|
|
73
|
-
}
|
|
74
|
-
} catch(error) {
|
|
75
|
-
this._error(error);
|
|
76
|
-
this._emitResponseWithSessionCheck({ session, request, error });
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
_emitResponseWithSessionCheck(response) {
|
|
81
|
-
// A new session invalidates ongoing data fetch
|
|
82
|
-
isCurrentSession(this._hub, response.session) && this._emitResponse(response);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
_emitResponse(response) {
|
|
86
|
-
this._hub.update(fields.response(), response);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
_error(error) {
|
|
90
|
-
// TODO
|
|
91
|
-
console.error(error);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
_destroy() {
|
|
95
|
-
// abort ongoing data fetch if any
|
|
96
|
-
this._ac && this._ac.abort({
|
|
97
|
-
type: 'data-actor-destroy',
|
|
98
|
-
message: 'Data actor is destroyed.',
|
|
99
|
-
});
|
|
100
|
-
for (const unsubscribe of this._unsubscribes) {
|
|
101
|
-
unsubscribe();
|
|
102
|
-
}
|
|
103
|
-
this._unsubscribes = [];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
}
|
package/src/actor/feedback.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as fields from './fields.js';
|
|
2
|
-
import { EVENT_TYPE } from '../constants.js';
|
|
3
|
-
|
|
4
|
-
export default class FeedbackActor {
|
|
5
|
-
|
|
6
|
-
constructor(hub) {
|
|
7
|
-
this._hub = hub;
|
|
8
|
-
this._unsubscribes = [
|
|
9
|
-
hub.on(fields.feedback(), state => this._trigger(state)),
|
|
10
|
-
];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
_trigger(state) {
|
|
14
|
-
this._hub.trigger(fields.tracker(), {
|
|
15
|
-
type: EVENT_TYPE.FEEDBACK,
|
|
16
|
-
result_type: 'answer',
|
|
17
|
-
value: state.unselected ? 'unselected' : state.value,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
_destroy() {
|
|
22
|
-
for (const unsubscribe of this._unsubscribes) {
|
|
23
|
-
unsubscribe();
|
|
24
|
-
}
|
|
25
|
-
this._unsubscribes = [];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
}
|