@miso.ai/client-sdk-ui 1.11.0-beta.0 → 1.11.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/actor/data.js +6 -7
- package/dist/cjs/actor/feedback.js +6 -39
- package/dist/cjs/actor/fields.js +14 -6
- package/dist/cjs/actor/hub.js +1 -2
- package/dist/cjs/actor/index.js +0 -7
- package/dist/cjs/actor/interactions.js +4 -15
- package/dist/cjs/actor/sessions.js +2 -33
- package/dist/cjs/actor/tracker.js +25 -26
- package/dist/cjs/actor/utils.js +0 -49
- package/dist/cjs/actor/view.js +40 -40
- package/dist/cjs/actor/views.js +32 -8
- package/dist/cjs/asset/svgs.js +18 -8
- package/dist/cjs/constants.js +18 -19
- package/dist/cjs/defaults/hybrid-search/answer-box.js +19 -3
- package/dist/cjs/defaults/hybrid-search/phrases.js +5 -5
- package/dist/cjs/defaults/hybrid-search/templates.js +37 -9
- package/dist/cjs/element/role/index.js +12 -5
- package/dist/cjs/element/role/{miso-hits.js → miso-more.js} +4 -4
- package/dist/cjs/element/role/miso-total.js +20 -0
- package/dist/cjs/layout/affiliation/affiliation.js +0 -3
- package/dist/cjs/layout/banner/banner.js +0 -4
- package/dist/cjs/layout/button/more-button.js +73 -0
- package/dist/cjs/layout/container/container.js +0 -3
- package/dist/cjs/layout/error/error.js +0 -4
- package/dist/cjs/layout/index.js +7 -0
- package/dist/cjs/layout/input/facets.js +5 -5
- package/dist/cjs/layout/input/option-list.js +0 -4
- package/dist/cjs/layout/input/search-box.js +33 -12
- package/dist/cjs/layout/list/cards.js +0 -3
- package/dist/cjs/layout/list/carousel.js +0 -3
- package/dist/cjs/layout/list/collection.js +25 -7
- package/dist/cjs/layout/list/list.js +0 -3
- package/dist/cjs/layout/radio/feedback.js +0 -3
- package/dist/cjs/layout/radio/radio.js +0 -4
- package/dist/cjs/layout/raf.js +4 -2
- package/dist/cjs/layout/text/text.js +0 -4
- package/dist/cjs/layout/text/typewriter/index.js +3 -3
- package/dist/cjs/layout/triggerable.js +79 -0
- package/dist/cjs/util/states.js +0 -15
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/answer-based.js +109 -111
- package/dist/cjs/workflow/ask.js +35 -27
- package/dist/cjs/workflow/asks.js +1 -1
- package/dist/cjs/workflow/autocompletable.js +33 -0
- package/dist/cjs/workflow/autocomplete.js +122 -0
- package/dist/cjs/workflow/base.js +169 -102
- package/dist/cjs/workflow/explore.js +26 -19
- package/dist/cjs/workflow/hybrid-search-answer.js +99 -0
- package/dist/cjs/workflow/hybrid-search-results.js +70 -0
- package/dist/cjs/workflow/hybrid-search-views.js +122 -0
- package/dist/cjs/workflow/hybrid-search.js +98 -103
- package/dist/cjs/workflow/options.js +32 -17
- package/dist/cjs/workflow/processors.js +185 -17
- package/dist/cjs/workflow/recommendation.js +36 -49
- package/dist/cjs/workflow/search-based.js +186 -0
- package/dist/cjs/workflow/search.js +21 -68
- package/package.json +2 -2
- package/src/actor/data.js +2 -4
- package/src/actor/feedback.js +6 -23
- package/src/actor/fields.js +14 -6
- package/src/actor/hub.js +1 -2
- package/src/actor/index.js +0 -1
- package/src/actor/interactions.js +4 -10
- package/src/actor/sessions.js +3 -30
- package/src/actor/tracker.js +25 -19
- package/src/actor/utils.js +0 -47
- package/src/actor/view.js +27 -15
- package/src/actor/views.js +36 -8
- package/src/asset/svgs.js +19 -7
- package/src/constants.js +25 -16
- package/src/defaults/hybrid-search/answer-box.js +17 -5
- package/src/defaults/hybrid-search/phrases.js +4 -4
- package/src/defaults/hybrid-search/templates.js +25 -9
- package/src/element/role/index.js +2 -1
- package/src/element/role/{miso-hits.js → miso-more.js} +3 -3
- package/src/element/role/miso-total.js +16 -0
- package/src/layout/affiliation/affiliation.js +1 -5
- package/src/layout/banner/banner.js +0 -5
- package/src/layout/button/more-button.js +69 -0
- package/src/layout/container/container.js +1 -5
- package/src/layout/error/error.js +0 -5
- package/src/layout/index.js +2 -1
- package/src/layout/input/facets.js +5 -6
- package/src/layout/input/option-list.js +0 -5
- package/src/layout/input/search-box.js +27 -14
- package/src/layout/list/cards.js +0 -4
- package/src/layout/list/carousel.js +0 -4
- package/src/layout/list/collection.js +22 -9
- package/src/layout/list/list.js +0 -4
- package/src/layout/radio/feedback.js +0 -4
- package/src/layout/radio/radio.js +0 -5
- package/src/layout/raf.js +2 -2
- package/src/layout/text/text.js +0 -5
- package/src/layout/text/typewriter/index.js +4 -5
- package/src/layout/trackable.js +1 -1
- package/src/layout/triggerable.js +76 -0
- package/src/util/states.js +0 -14
- package/src/version.js +1 -1
- package/src/workflow/answer-based.js +101 -77
- package/src/workflow/ask.js +33 -25
- package/src/workflow/asks.js +1 -1
- package/src/workflow/autocompletable.js +29 -0
- package/src/workflow/autocomplete.js +113 -0
- package/src/workflow/base.js +147 -93
- package/src/workflow/explore.js +23 -8
- package/src/workflow/hybrid-search-answer.js +92 -0
- package/src/workflow/hybrid-search-results.js +63 -0
- package/src/workflow/hybrid-search-views.js +124 -0
- package/src/workflow/hybrid-search.js +102 -73
- package/src/workflow/options.js +26 -11
- package/src/workflow/processors.js +165 -14
- package/src/workflow/recommendation.js +32 -33
- package/src/workflow/search-based.js +183 -0
- package/src/workflow/search.js +21 -65
- package/dist/cjs/actor/autocomplete.js +0 -160
- package/dist/cjs/workflow/utils.js +0 -42
- package/src/actor/autocomplete.js +0 -133
- package/src/workflow/utils.js +0 -29
|
@@ -1,160 +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 fields = _interopRequireWildcard(require("./fields.js"));
|
|
9
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
-
class AutocompleteActor {
|
|
12
|
-
constructor(hub, _ref) {
|
|
13
|
-
let {
|
|
14
|
-
source,
|
|
15
|
-
options
|
|
16
|
-
} = _ref;
|
|
17
|
-
this._hub = hub;
|
|
18
|
-
this._source = source;
|
|
19
|
-
this._options = options;
|
|
20
|
-
this._index = -1;
|
|
21
|
-
|
|
22
|
-
// TODO: listen to request:input instead
|
|
23
|
-
this._unsubscribes = [hub.on(fields.input(), () => this._sync()), options.on('autocomplete', () => this._syncOptions())];
|
|
24
|
-
|
|
25
|
-
// sync right away
|
|
26
|
-
this._sync(true);
|
|
27
|
-
}
|
|
28
|
-
get active() {
|
|
29
|
-
return this._options.resolved.autocomplete.actor !== false;
|
|
30
|
-
}
|
|
31
|
-
get source() {
|
|
32
|
-
return this._source;
|
|
33
|
-
}
|
|
34
|
-
_syncOptions() {
|
|
35
|
-
// TODO: explore scenarios where options.actor true -> false
|
|
36
|
-
this._sync(true);
|
|
37
|
-
}
|
|
38
|
-
async _sync() {
|
|
39
|
-
let force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
40
|
-
// protocol: inactive -> no reaction
|
|
41
|
-
if (!this.active) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const {
|
|
45
|
-
input
|
|
46
|
-
} = this._hub.states;
|
|
47
|
-
const value = input && input.value && input.value.trim() || undefined;
|
|
48
|
-
if (sameInput(this._input, input) && !force) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
this._input = input;
|
|
52
|
-
const index = ++this._index;
|
|
53
|
-
|
|
54
|
-
// new input, abort previous data fetch if any
|
|
55
|
-
this._clearTimeout();
|
|
56
|
-
this._abortPendingRequest({
|
|
57
|
-
type: 'new-input',
|
|
58
|
-
message: 'A new input renders previous autocomplete request obsolete.'
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// emit loading/initial state
|
|
62
|
-
this._emitCompletions({
|
|
63
|
-
index,
|
|
64
|
-
input,
|
|
65
|
-
status: value ? _constants.STATUS.LOADING : _constants.STATUS.INITIAL
|
|
66
|
-
});
|
|
67
|
-
if (!value) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
try {
|
|
71
|
-
const response = await this._fetchCompletions(input);
|
|
72
|
-
if (this._index !== index) {
|
|
73
|
-
return; // new results loading, discard this one
|
|
74
|
-
}
|
|
75
|
-
this._emitCompletions({
|
|
76
|
-
index,
|
|
77
|
-
input,
|
|
78
|
-
status: _constants.STATUS.READY,
|
|
79
|
-
value: response.completions
|
|
80
|
-
});
|
|
81
|
-
} catch (error) {
|
|
82
|
-
this._error(error);
|
|
83
|
-
if (this._index !== index) {
|
|
84
|
-
return; // ignore
|
|
85
|
-
}
|
|
86
|
-
this._emitCompletions({
|
|
87
|
-
index,
|
|
88
|
-
input,
|
|
89
|
-
status: _constants.STATUS.ERRONEOUS,
|
|
90
|
-
error
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async _getCompletions(input) {
|
|
95
|
-
// TODO: cache
|
|
96
|
-
return await this._fetchCompletions(input);
|
|
97
|
-
}
|
|
98
|
-
async _fetchCompletions(_ref2) {
|
|
99
|
-
let {
|
|
100
|
-
value
|
|
101
|
-
} = _ref2;
|
|
102
|
-
// TODO: other options?
|
|
103
|
-
const {
|
|
104
|
-
api
|
|
105
|
-
} = this._options.resolved.autocomplete;
|
|
106
|
-
const {
|
|
107
|
-
group,
|
|
108
|
-
name
|
|
109
|
-
} = api;
|
|
110
|
-
const {
|
|
111
|
-
signal
|
|
112
|
-
} = this._ac || {};
|
|
113
|
-
const options = Object.assign({}, api.options, {
|
|
114
|
-
signal
|
|
115
|
-
});
|
|
116
|
-
const payload = Object.assign({}, api.payload, {
|
|
117
|
-
q: value
|
|
118
|
-
});
|
|
119
|
-
return await this._source({
|
|
120
|
-
group,
|
|
121
|
-
name,
|
|
122
|
-
payload,
|
|
123
|
-
options
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
_clearTimeout() {
|
|
127
|
-
if (this._timeoutId) {
|
|
128
|
-
clearTimeout(this._timeoutId);
|
|
129
|
-
this._timeoutId = undefined;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
_abortPendingRequest(info) {
|
|
133
|
-
this._ac && this._ac.abort(info);
|
|
134
|
-
this._ac = new AbortController();
|
|
135
|
-
}
|
|
136
|
-
_emitCompletions(event) {
|
|
137
|
-
event.source = 'actor';
|
|
138
|
-
// TDOO: update response:autocomplete instead
|
|
139
|
-
this._hub.update(fields.data(_constants.DATA_ASPECT.AUTOCOMPLETE), event);
|
|
140
|
-
}
|
|
141
|
-
_error(error) {
|
|
142
|
-
// TODO
|
|
143
|
-
console.error(error);
|
|
144
|
-
}
|
|
145
|
-
_destroy() {
|
|
146
|
-
// abort ongoing data fetch if any
|
|
147
|
-
this._ac && this._ac.abort({
|
|
148
|
-
type: 'autocomplete-actor-destroy',
|
|
149
|
-
message: 'Autocomplete actor is destroyed.'
|
|
150
|
-
});
|
|
151
|
-
for (const unsubscribe of this._unsubscribes) {
|
|
152
|
-
unsubscribe();
|
|
153
|
-
}
|
|
154
|
-
this._unsubscribes = [];
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.default = AutocompleteActor;
|
|
158
|
-
function sameInput(a, b) {
|
|
159
|
-
return !a && !b || a && b && a.value === b.value;
|
|
160
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.injectLogger = injectLogger;
|
|
7
|
-
exports.mergeInteractionsOptions = mergeInteractionsOptions;
|
|
8
|
-
function mergeInteractionsOptions() {
|
|
9
|
-
let base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
10
|
-
let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
11
|
-
if (overrides === false) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
return Object.freeze(Object.assign({}, base, overrides, {
|
|
15
|
-
preprocess: concatFunctions(base.preprocess, overrides.preprocess)
|
|
16
|
-
}));
|
|
17
|
-
}
|
|
18
|
-
function injectLogger(hub, callback) {
|
|
19
|
-
const {
|
|
20
|
-
update,
|
|
21
|
-
trigger
|
|
22
|
-
} = hub;
|
|
23
|
-
hub.update = (name, state, options) => {
|
|
24
|
-
if (!options || !options.silent) {
|
|
25
|
-
callback('update', name, state, options);
|
|
26
|
-
}
|
|
27
|
-
return update.call(hub, name, state, options);
|
|
28
|
-
};
|
|
29
|
-
hub.trigger = function () {
|
|
30
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
31
|
-
args[_key] = arguments[_key];
|
|
32
|
-
}
|
|
33
|
-
callback('trigger', ...args);
|
|
34
|
-
return trigger.apply(hub, args);
|
|
35
|
-
};
|
|
36
|
-
return hub;
|
|
37
|
-
}
|
|
38
|
-
function concatFunctions(fn0, fn1) {
|
|
39
|
-
return fn0 ? fn1 ? function () {
|
|
40
|
-
return fn1(fn0(...arguments));
|
|
41
|
-
} : fn0 : fn1;
|
|
42
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { STATUS, DATA_ASPECT } from '../constants.js';
|
|
2
|
-
import * as fields from './fields.js';
|
|
3
|
-
|
|
4
|
-
export default class AutocompleteActor {
|
|
5
|
-
|
|
6
|
-
constructor(hub, { source, options }) {
|
|
7
|
-
this._hub = hub;
|
|
8
|
-
this._source = source;
|
|
9
|
-
this._options = options;
|
|
10
|
-
this._index = -1;
|
|
11
|
-
|
|
12
|
-
// TODO: listen to request:input instead
|
|
13
|
-
this._unsubscribes = [
|
|
14
|
-
hub.on(fields.input(), () => this._sync()),
|
|
15
|
-
options.on('autocomplete', () => this._syncOptions()),
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
// sync right away
|
|
19
|
-
this._sync(true);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get active() {
|
|
23
|
-
return this._options.resolved.autocomplete.actor !== false;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get source() {
|
|
27
|
-
return this._source;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
_syncOptions() {
|
|
31
|
-
// TODO: explore scenarios where options.actor true -> false
|
|
32
|
-
this._sync(true);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async _sync(force = false) {
|
|
36
|
-
// protocol: inactive -> no reaction
|
|
37
|
-
if (!this.active) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const { input } = this._hub.states;
|
|
42
|
-
const value = input && input.value && input.value.trim() || undefined;
|
|
43
|
-
|
|
44
|
-
if (sameInput(this._input, input) && !force) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
this._input = input;
|
|
48
|
-
const index = ++this._index;
|
|
49
|
-
|
|
50
|
-
// new input, abort previous data fetch if any
|
|
51
|
-
this._clearTimeout();
|
|
52
|
-
this._abortPendingRequest({
|
|
53
|
-
type: 'new-input',
|
|
54
|
-
message: 'A new input renders previous autocomplete request obsolete.',
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// emit loading/initial state
|
|
58
|
-
this._emitCompletions({ index, input, status: value ? STATUS.LOADING : STATUS.INITIAL });
|
|
59
|
-
|
|
60
|
-
if (!value) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
const response = await this._fetchCompletions(input);
|
|
66
|
-
if (this._index !== index) {
|
|
67
|
-
return; // new results loading, discard this one
|
|
68
|
-
}
|
|
69
|
-
this._emitCompletions({ index, input, status: STATUS.READY, value: response.completions });
|
|
70
|
-
} catch (error) {
|
|
71
|
-
this._error(error);
|
|
72
|
-
if (this._index !== index) {
|
|
73
|
-
return; // ignore
|
|
74
|
-
}
|
|
75
|
-
this._emitCompletions({ index, input, status: STATUS.ERRONEOUS, error });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async _getCompletions(input) {
|
|
80
|
-
// TODO: cache
|
|
81
|
-
return await this._fetchCompletions(input);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async _fetchCompletions({ value }) {
|
|
85
|
-
// TODO: other options?
|
|
86
|
-
const { api } = this._options.resolved.autocomplete;
|
|
87
|
-
const { group, name } = api;
|
|
88
|
-
const { signal } = this._ac || {};
|
|
89
|
-
const options = { ...api.options, signal };
|
|
90
|
-
const payload = { ...api.payload, q: value };
|
|
91
|
-
return await this._source({ group, name, payload, options });
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
_clearTimeout() {
|
|
95
|
-
if (this._timeoutId) {
|
|
96
|
-
clearTimeout(this._timeoutId);
|
|
97
|
-
this._timeoutId = undefined;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
_abortPendingRequest(info) {
|
|
102
|
-
this._ac && this._ac.abort(info);
|
|
103
|
-
this._ac = new AbortController();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
_emitCompletions(event) {
|
|
107
|
-
event.source = 'actor';
|
|
108
|
-
// TDOO: update response:autocomplete instead
|
|
109
|
-
this._hub.update(fields.data(DATA_ASPECT.AUTOCOMPLETE), event);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
_error(error) {
|
|
113
|
-
// TODO
|
|
114
|
-
console.error(error);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
_destroy() {
|
|
118
|
-
// abort ongoing data fetch if any
|
|
119
|
-
this._ac && this._ac.abort({
|
|
120
|
-
type: 'autocomplete-actor-destroy',
|
|
121
|
-
message: 'Autocomplete actor is destroyed.',
|
|
122
|
-
});
|
|
123
|
-
for (const unsubscribe of this._unsubscribes) {
|
|
124
|
-
unsubscribe();
|
|
125
|
-
}
|
|
126
|
-
this._unsubscribes = [];
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function sameInput(a, b) {
|
|
132
|
-
return (!a && !b) || (a && b && a.value === b.value);
|
|
133
|
-
}
|
package/src/workflow/utils.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export function mergeInteractionsOptions(base = {}, overrides = {}) {
|
|
2
|
-
if (overrides === false) {
|
|
3
|
-
return false;
|
|
4
|
-
}
|
|
5
|
-
return Object.freeze({
|
|
6
|
-
...base,
|
|
7
|
-
...overrides,
|
|
8
|
-
preprocess: concatFunctions(base.preprocess, overrides.preprocess),
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function injectLogger(hub, callback) {
|
|
13
|
-
const { update, trigger } = hub;
|
|
14
|
-
hub.update = (name, state, options) => {
|
|
15
|
-
if (!options || !options.silent) {
|
|
16
|
-
callback('update', name, state, options);
|
|
17
|
-
}
|
|
18
|
-
return update.call(hub, name, state, options);
|
|
19
|
-
}
|
|
20
|
-
hub.trigger = (...args) => {
|
|
21
|
-
callback('trigger', ...args);
|
|
22
|
-
return trigger.apply(hub, args);
|
|
23
|
-
}
|
|
24
|
-
return hub;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function concatFunctions(fn0, fn1) {
|
|
28
|
-
return fn0 ? fn1 ? (...args) => fn1(fn0(...args)) : fn0 : fn1;
|
|
29
|
-
}
|