@miso.ai/client-sdk-ui 1.9.10 → 1.10.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/cjs/actor/autocomplete.js +157 -0
  2. package/dist/cjs/actor/data.js +3 -11
  3. package/dist/cjs/actor/fields.js +8 -0
  4. package/dist/cjs/actor/index.js +7 -0
  5. package/dist/cjs/actor/utils.js +10 -0
  6. package/dist/cjs/defaults/ask/templates.js +21 -0
  7. package/dist/cjs/layout/input/search-box.js +213 -127
  8. package/dist/cjs/layout/list/collection.js +6 -1
  9. package/dist/cjs/layout/templates.js +50 -35
  10. package/dist/cjs/layout/text/typewriter/index.js +8 -53
  11. package/dist/cjs/source/index.js +20 -8
  12. package/dist/cjs/styles.js +4 -83
  13. package/dist/cjs/version.js +1 -1
  14. package/dist/cjs/workflow/ask.js +48 -16
  15. package/dist/cjs/workflow/base.js +1 -2
  16. package/dist/cjs/workflow/explore.js +4 -1
  17. package/dist/cjs/workflow/options.js +54 -13
  18. package/dist/cjs/workflow/search.js +35 -7
  19. package/package.json +2 -2
  20. package/src/actor/autocomplete.js +131 -0
  21. package/src/actor/data.js +3 -10
  22. package/src/actor/fields.js +8 -0
  23. package/src/actor/index.js +1 -0
  24. package/src/actor/utils.js +8 -0
  25. package/src/defaults/ask/templates.js +21 -0
  26. package/src/layout/input/search-box.js +186 -94
  27. package/src/layout/list/collection.js +6 -1
  28. package/src/layout/templates.js +31 -25
  29. package/src/layout/text/typewriter/index.js +6 -46
  30. package/src/source/index.js +14 -1
  31. package/src/styles.js +4 -86
  32. package/src/version.js +1 -1
  33. package/src/workflow/ask.js +31 -1
  34. package/src/workflow/base.js +1 -2
  35. package/src/workflow/explore.js +1 -1
  36. package/src/workflow/options.js +49 -12
  37. package/src/workflow/search.js +33 -1
@@ -75,73 +75,28 @@ class TypewriterLayout extends _progressive.default {
75
75
  const context = await this._view._views._extensions.require('markdown');
76
76
  const cursorClass = (0, _utils.cursorClassName)(this.className);
77
77
  const {
78
- onDebug
78
+ onDebug,
79
+ onCitationLink
79
80
  } = this.options;
80
81
  // TODO: options
81
82
  this._renderer = context.createRenderer({
82
- onRefChange: (oldRef, newRef) => {
83
- oldRef && oldRef.classList.remove(cursorClass);
84
- newRef && newRef.classList.add(cursorClass);
85
- },
86
- onDone: element => {
87
- element.classList.add('done');
88
- },
89
- onDebug,
90
- onCitationLink: this._handleCitationLink.bind(this)
83
+ cursorClass,
84
+ getSource: index => this._getSource(index),
85
+ onCitationLink,
86
+ onDebug
91
87
  });
92
88
  // capture citation link click if necessary
93
89
  this._unsubscribes.push(this._view.proxyElement.on('click', e => this._handleClick(e)));
94
90
  }
95
- _handleCitationLink(methods, index) {
96
- const {
97
- onCitationLink
98
- } = this.options;
99
- if (typeof onCitationLink !== 'function') {
100
- return;
101
- }
91
+ _getSource(index) {
102
92
  const {
103
93
  data = {}
104
94
  } = this._view._data;
105
95
  const {
106
96
  sources = []
107
97
  } = data;
108
- const source = sources[index];
109
- try {
110
- onCitationLink(methods, {
111
- source,
112
- index
113
- });
114
- } catch (e) {
115
- console.error(e);
116
- }
98
+ return sources[index];
117
99
  }
118
-
119
- /*
120
- _handleCitationTooltip({ node, tooltip, index }) {
121
- const { tooltip: tooltipOptions } = this.options;
122
- if (!tooltipOptions || !tooltip || tooltip.properties['data-value']) {
123
- return;
124
- }
125
- const { data = {} } = this._view._data;
126
- const { sources = [] } = data;
127
- const source = sources[index];
128
- if (!source) {
129
- return;
130
- }
131
- // TODO: allow HTML
132
- let value;
133
- try {
134
- value = typeof tooltipOptions === 'function' ? tooltipOptions(source) : source.title;
135
- } catch (e) {
136
- console.error(e);
137
- }
138
- if (!value) {
139
- return;
140
- }
141
- tooltip.properties['data-value'] = escapeHtml(value);
142
- }
143
- */
144
-
145
100
  async _setupForPlaintext() {
146
101
  this._renderer = new _plaintext.default();
147
102
  }
@@ -3,11 +3,23 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "api", {
7
- enumerable: true,
8
- get: function () {
9
- return _api.default;
10
- }
11
- });
12
- var _api = _interopRequireDefault(require("./api.js"));
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
6
+ exports.api = api;
7
+ var _commons = require("@miso.ai/commons");
8
+ //export { default as api } from './api.js';
9
+
10
+ function api(client) {
11
+ // TODO: send uuid & unit id
12
+ return async _ref => {
13
+ let {
14
+ group,
15
+ name,
16
+ payload,
17
+ options
18
+ } = _ref;
19
+ if (group === _commons.API.GROUP.ASK && name === _commons.API.NAME.QUESTIONS) {
20
+ return client.api.ask.questions(payload, options);
21
+ }
22
+ // because name is in snake case
23
+ return client.api[group]._run(name, payload, options);
24
+ };
25
+ }
@@ -3,95 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.loadStyles = loadStyles;
7
6
  exports.loadStylesIfNecessary = loadStylesIfNecessary;
8
- var _version = _interopRequireDefault(require("./version.js"));
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
- const {
11
- currentScript
12
- } = document;
7
+ var _commons = require("@miso.ai/commons");
8
+ const NAME = 'ui';
13
9
  let cssUrl;
14
10
  let stylesLoaded;
15
11
  async function loadStylesIfNecessary() {
16
- return stylesLoaded || (stylesLoaded = loadStyles());
17
- }
18
- async function loadStyles() {
19
- try {
20
- let link = getExistedLinkElement();
21
- if (!link) {
22
- link = document.createElement('link');
23
- link.rel = 'stylesheet';
24
- link.href = getCssUrl();
25
- document.head.appendChild(link);
26
- }
27
- return waitForStylesApplied(link);
28
- } catch (e) {
29
- console.error(e);
30
- }
12
+ return stylesLoaded || (stylesLoaded = (0, _commons.loadStyles)(getCssUrl()));
31
13
  }
32
14
 
33
15
  // helpers //
34
16
  function getCssUrl() {
35
- return cssUrl || (cssUrl = resolveCssUrl());
36
- }
37
- function resolveCssUrl() {
38
- // TODO: refactor with getPluginScriptUrl() in core
39
- if (_version.default === 'dev') {
40
- const src = currentScript.src;
41
- const searchIndex = src.indexOf('?');
42
- const k = searchIndex < 0 ? src.length : searchIndex;
43
- const i = src.lastIndexOf('/', k); // .../dist/umd/*.min.js
44
- return `${src.slice(0, i - 4)}/css/ui.css`;
45
- } else {
46
- return `https://cdn.jsdelivr.net/npm/@miso.ai/client-sdk@${_version.default}/dist/css/ui.css`;
47
- }
48
- }
49
- function getExistedLinkElement() {
50
- return document.head.querySelector(`link[href="${getCssUrl()}"]`);
51
- }
52
- async function waitForStylesApplied(element) {
53
- await waitForSheetAvailable(element);
54
- await waitForSheetIncluded(element);
55
- }
56
- async function waitForSheetAvailable(element) {
57
- if (element.sheet) {
58
- return;
59
- }
60
- return new Promise((resolve, reject) => {
61
- let intervalId;
62
- element.onerror = () => {
63
- intervalId && clearInterval(intervalId);
64
- reject();
65
- };
66
- intervalId = setInterval(() => {
67
- if (!element.sheet) {
68
- return;
69
- }
70
- intervalId && clearInterval(intervalId);
71
- resolve();
72
- }, 100);
73
- });
74
- }
75
- async function waitForSheetIncluded(element) {
76
- if (isSheetIncluded(element)) {
77
- return;
78
- }
79
- return new Promise(resolve => {
80
- let intervalId;
81
- intervalId = setInterval(() => {
82
- if (!isSheetIncluded(element)) {
83
- return;
84
- }
85
- intervalId && clearInterval(intervalId);
86
- resolve();
87
- }, 100);
88
- });
89
- }
90
- function isSheetIncluded(element) {
91
- for (const sheet of document.styleSheets) {
92
- if (sheet.ownerNode === element) {
93
- return true;
94
- }
95
- }
96
- return false;
17
+ return cssUrl || (cssUrl = (0, _commons.resolveCssUrl)(NAME));
97
18
  }
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '1.9.10';
7
+ var _default = exports.default = '1.10.0-beta.1';
@@ -7,10 +7,13 @@ exports.default = void 0;
7
7
  var _commons = require("@miso.ai/commons");
8
8
  var _base = _interopRequireDefault(require("./base.js"));
9
9
  var _options = require("./options.js");
10
- var _index = require("../actor/index.js");
10
+ var sources = _interopRequireWildcard(require("../source/index.js"));
11
+ var _index2 = require("../actor/index.js");
11
12
  var _constants = require("../constants.js");
12
- var _index2 = require("../layout/index.js");
13
+ var _index3 = require("../layout/index.js");
13
14
  const _excluded = ["q", "qs"];
15
+ 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); }
16
+ 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; }
14
17
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
18
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
16
19
  const DEFAULT_API_OPTIONS = Object.freeze({
@@ -24,27 +27,34 @@ const DEFAULT_API_OPTIONS = Object.freeze({
24
27
  cite_end: ']'
25
28
  }
26
29
  });
30
+ const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
31
+ actor: false,
32
+ api: {
33
+ group: _commons.API.GROUP.ASK,
34
+ name: _commons.API.NAME.AUTOCOMPLETE
35
+ }
36
+ });
27
37
  const DEFAULT_LAYOUTS = Object.freeze({
28
- [_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type, {
38
+ [_constants.ROLE.QUERY]: [_index3.SearchBoxLayout.type, {
29
39
  placeholder: 'Ask a question'
30
40
  }],
31
- [_constants.ROLE.QUESTION]: [_index2.TextLayout.type, {
41
+ [_constants.ROLE.QUESTION]: [_index3.TextLayout.type, {
32
42
  tag: 'h2'
33
43
  }],
34
- [_constants.ROLE.ANSWER]: _index2.TypewriterLayout.type,
35
- [_constants.ROLE.FEEDBACK]: _index2.FeedbackLayout.type,
36
- [_constants.ROLE.SOURCES]: [_index2.ListLayout.type, {
44
+ [_constants.ROLE.ANSWER]: _index3.TypewriterLayout.type,
45
+ [_constants.ROLE.FEEDBACK]: _index3.FeedbackLayout.type,
46
+ [_constants.ROLE.SOURCES]: [_index3.ListLayout.type, {
37
47
  incremental: true,
38
48
  itemType: 'article',
39
49
  templates: {
40
50
  ordered: true
41
51
  }
42
52
  }],
43
- [_constants.ROLE.RELATED_RESOURCES]: [_index2.ListLayout.type, {
53
+ [_constants.ROLE.RELATED_RESOURCES]: [_index3.ListLayout.type, {
44
54
  incremental: true,
45
55
  itemType: 'article'
46
56
  }],
47
- [_constants.ROLE.QUERY_SUGGESTIONS]: _index2.OptionListLayout.type
57
+ [_constants.ROLE.QUERY_SUGGESTIONS]: _index3.OptionListLayout.type
48
58
  });
49
59
  const DEFAULT_TRACKERS = Object.freeze({
50
60
  [_constants.ROLE.SOURCES]: {},
@@ -59,6 +69,7 @@ const DEFAULT_TRACKERS = Object.freeze({
59
69
  });
60
70
  const DEFAULT_OPTIONS = Object.freeze({
61
71
  api: DEFAULT_API_OPTIONS,
72
+ autocomplete: DEFAULT_AUTOCOMPLETE_OPTIONS,
62
73
  layouts: DEFAULT_LAYOUTS,
63
74
  trackers: DEFAULT_TRACKERS
64
75
  });
@@ -75,9 +86,17 @@ class Ask extends _base.default {
75
86
  (0, _commons.defineValues)(this, {
76
87
  parentQuestionId
77
88
  });
78
- this._feedback = new _index.FeedbackActor(this._hub);
89
+ this._feedback = new _index2.FeedbackActor(this._hub);
79
90
  this._setSuggestedQuestions();
80
- this._unsubscribes = [...this._unsubscribes, this._hub.on(_index.fields.query(), payload => this.query(payload)), this._hub.on(_index.fields.view(_constants.ROLE.ANSWER), data => this._onAnswerViewUpdate(data)), this._views.get(_constants.ROLE.ANSWER).on('citation-click', event => this._onCitationClick(event))];
91
+
92
+ /*
93
+ this._autocomplete = new AutocompleteActor(this._hub, {
94
+ source: sources.api(this._client),
95
+ options: this._options,
96
+ });
97
+ */
98
+
99
+ this._unsubscribes = [...this._unsubscribes, this._hub.on(_index2.fields.query(), payload => this.query(payload)), this._hub.on(_index2.fields.view(_constants.ROLE.ANSWER), data => this._onAnswerViewUpdate(data)), this._views.get(_constants.ROLE.ANSWER).on('citation-click', event => this._onCitationClick(event))];
81
100
  parentQuestionId && context._byPqid.set(parentQuestionId, this);
82
101
  context._events.emit('create', this);
83
102
  this.reset(); // create a session so query suggestions can be tracked
@@ -163,7 +182,7 @@ class Ask extends _base.default {
163
182
  session
164
183
  } = this;
165
184
  session.meta.question_source = questionSource;
166
- this._hub.update(_index.fields.request(), (0, _options.mergeApiOptions)(this._options.resolved.api, {
185
+ this._hub.update(_index2.fields.request(), (0, _options.mergeApiOptions)(this._options.resolved.api, {
167
186
  payload,
168
187
  session
169
188
  }));
@@ -175,7 +194,7 @@ class Ask extends _base.default {
175
194
  session,
176
195
  status,
177
196
  ongoing
178
- } = this._hub.states[_index.fields.view(_constants.ROLE.ANSWER)] || {};
197
+ } = this._hub.states[_index2.fields.view(_constants.ROLE.ANSWER)] || {};
179
198
  if (session && status !== _constants.STATUS.INITIAL && (status !== _constants.STATUS.READY || ongoing)) {
180
199
  // it's interrupted by a new question
181
200
  const state = Object.freeze({
@@ -188,6 +207,18 @@ class Ask extends _base.default {
188
207
  }
189
208
  super.restart();
190
209
  }
210
+
211
+ /*
212
+ updateCompletions(event) {
213
+ // TODO: verify
214
+ this._hub.update(fields.completions(), {
215
+ ...event,
216
+ source: 'manual',
217
+ });
218
+ return this;
219
+ }
220
+ */
221
+
191
222
  _defaultProcessData(data) {
192
223
  data = super._defaultProcessData(data);
193
224
  const {
@@ -258,9 +289,9 @@ class Ask extends _base.default {
258
289
  if (!previous) {
259
290
  return;
260
291
  }
261
- const values = previous.states[_index.fields.data()].value;
292
+ const values = previous.states[_index2.fields.data()].value;
262
293
  const value = values.suggested_followup_questions || values.followup_questions || [];
263
- this._hub.update(_index.fields.suggestions(), {
294
+ this._hub.update(_index2.fields.suggestions(), {
264
295
  value: value.map(text => ({
265
296
  text
266
297
  }))
@@ -272,7 +303,7 @@ class Ask extends _base.default {
272
303
  } = _ref3;
273
304
  const {
274
305
  value
275
- } = this.states[_index.fields.data()] || {};
306
+ } = this.states[_index2.fields.data()] || {};
276
307
  const {
277
308
  sources
278
309
  } = value || {};
@@ -327,6 +358,7 @@ class Ask extends _base.default {
327
358
  this._context._byQid.delete(questionId);
328
359
  }
329
360
  this._feedback._destroy();
361
+ this._autocomplete._destroy();
330
362
  super._destroy(options);
331
363
  }
332
364
  }
@@ -59,11 +59,10 @@ class Workflow extends _commons.Component {
59
59
  const hub = this._hub = (0, _utils.injectLogger)(new _index.Hub(), function () {
60
60
  return _this._log(...arguments);
61
61
  });
62
- const source = this._source = sources.api(client);
63
62
  const layouts = plugin.layouts;
64
63
  this._sessions = new _index.SessionMaker(hub);
65
64
  this._data = new _index.DataActor(hub, {
66
- source,
65
+ source: sources.api(client),
67
66
  options
68
67
  });
69
68
  const views = this._views = new _index.ViewsActor(hub, {
@@ -19,7 +19,10 @@ const DEFAULT_API_OPTIONS = Object.freeze({
19
19
  });
20
20
  const DEFAULT_LAYOUTS = Object.freeze({
21
21
  [_constants.ROLE.RELATED_QUESTIONS]: [_index2.ListLayout.type, {
22
- itemType: 'question'
22
+ itemType: 'question',
23
+ link: {
24
+ rel: 'noopener nofollow'
25
+ }
23
26
  }],
24
27
  [_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type, {
25
28
  placeholder: 'Ask a question'
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.WorkflowOptions = exports.WorkflowContextOptions = void 0;
7
7
  exports.makeConfigurable = makeConfigurable;
8
8
  exports.mergeApiOptions = mergeApiOptions;
9
+ exports.mergeAutocompleteOptions = mergeAutocompleteOptions;
9
10
  exports.mergeDataProcessorOptions = mergeDataProcessorOptions;
10
11
  exports.mergeInteractionsOptions = mergeInteractionsOptions;
11
12
  exports.mergeLayoutsOptions = mergeLayoutsOptions;
12
13
  exports.mergeTrackersOptions = mergeTrackersOptions;
13
14
  exports.normalizeApiOptions = normalizeApiOptions;
15
+ exports.normalizeAutocompleteOptions = normalizeAutocompleteOptions;
14
16
  exports.normalizeDataProcessorOptions = normalizeDataProcessorOptions;
15
17
  exports.normalizeInteractionsOptions = normalizeInteractionsOptions;
16
18
  exports.normalizeLayoutsOptions = normalizeLayoutsOptions;
@@ -23,6 +25,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
23
25
  // normalize //
24
26
  function normalizeApiOptions() {
25
27
  let [name, payload] = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
28
+ // TODO: take object form as well
26
29
  if (name === false) {
27
30
  return {
28
31
  actor: false
@@ -131,6 +134,20 @@ function normalizeInteractionsOptions(options) {
131
134
  preprocess
132
135
  });
133
136
  }
137
+ function normalizeAutocompleteOptions(options) {
138
+ if (options === undefined) {
139
+ throw new Error(`Expect autocomplete options to be an object or a boolean value: ${options}`);
140
+ }
141
+ if (typeof options === 'boolean') {
142
+ options = {
143
+ actor: options
144
+ };
145
+ }
146
+ const processData = normalizeDataProcessorOptions(options.processData);
147
+ return Object.assign({}, options, {
148
+ processData
149
+ });
150
+ }
134
151
 
135
152
  // merge //
136
153
  function mergeApiOptions() {
@@ -217,6 +234,18 @@ function mergeInteractionsOptions() {
217
234
  preprocess: concatArrays(merged.preprocess, options.preprocess)
218
235
  })));
219
236
  }
237
+ function mergeAutocompleteOptions() {
238
+ for (var _len6 = arguments.length, optionsList = new Array(_len6), _key7 = 0; _key7 < _len6; _key7++) {
239
+ optionsList[_key7] = arguments[_key7];
240
+ }
241
+ if (optionsList[optionsList.length - 1] === false) {
242
+ return false;
243
+ }
244
+ return mergeOptions(optionsList, (merged, options) => Object.assign(merged, Object.assign({}, options, {
245
+ api: mergeApiOptions(merged.api, options.api),
246
+ processData: mergeDataProcessorOptions(merged.processData, options.processData)
247
+ })));
248
+ }
220
249
 
221
250
  // manifest //
222
251
  const FEATURES = [{
@@ -239,6 +268,10 @@ const FEATURES = [{
239
268
  key: 'interactions',
240
269
  normalize: normalizeInteractionsOptions,
241
270
  merge: mergeInteractionsOptions
271
+ }, {
272
+ key: 'autocomplete',
273
+ normalize: normalizeAutocompleteOptions,
274
+ merge: mergeAutocompleteOptions
242
275
  }];
243
276
  class WorkflowContextOptions {
244
277
  constructor() {
@@ -339,21 +372,29 @@ for (const {
339
372
  }
340
373
  });
341
374
  }
375
+ const DEFAULT_FEATURES = ['api', 'layouts', 'dataProcessor', 'trackers', 'interactions'];
342
376
  function makeConfigurable(prototype) {
343
- Object.assign(prototype, {
344
- useApi() {
345
- for (var _len6 = arguments.length, args = new Array(_len6), _key7 = 0; _key7 < _len6; _key7++) {
346
- args[_key7] = arguments[_key7];
377
+ let features = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_FEATURES;
378
+ for (const feature of features) {
379
+ injectConfigurableFeature(prototype, feature);
380
+ }
381
+ }
382
+ function injectConfigurableFeature(prototype, feature) {
383
+ if (feature === 'api') {
384
+ Object.assign(prototype, {
385
+ useApi() {
386
+ for (var _len7 = arguments.length, args = new Array(_len7), _key8 = 0; _key8 < _len7; _key8++) {
387
+ args[_key8] = arguments[_key8];
388
+ }
389
+ this._options.api.merge(args);
390
+ return this;
391
+ },
392
+ clearApi() {
393
+ this._options.api.set();
394
+ return this;
347
395
  }
348
- this._options.api.merge(args);
349
- return this;
350
- },
351
- clearApi() {
352
- this._options.api.set();
353
- return this;
354
- }
355
- });
356
- for (const feature of ['layouts', 'dataProcessor', 'trackers', 'interactions']) {
396
+ });
397
+ } else {
357
398
  const upperCased = upperCase(feature);
358
399
  Object.assign(prototype, {
359
400
  [`use${upperCased}`](value) {
@@ -7,9 +7,12 @@ exports.default = void 0;
7
7
  var _commons = require("@miso.ai/commons");
8
8
  var _base = _interopRequireDefault(require("./base.js"));
9
9
  var _options = require("./options.js");
10
- var _index = require("../actor/index.js");
10
+ var sources = _interopRequireWildcard(require("../source/index.js"));
11
+ var _index2 = require("../actor/index.js");
11
12
  var _constants = require("../constants.js");
12
- var _index2 = require("../layout/index.js");
13
+ var _index3 = require("../layout/index.js");
14
+ 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); }
15
+ 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; }
13
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
17
  const DEFAULT_API_OPTIONS = Object.freeze({
15
18
  group: _commons.API.GROUP.SEARCH,
@@ -18,15 +21,28 @@ const DEFAULT_API_OPTIONS = Object.freeze({
18
21
  fl: ['*']
19
22
  }
20
23
  });
24
+ const DEFAULT_AUTOCOMPLETE_OPTIONS = Object.freeze({
25
+ actor: false,
26
+ api: {
27
+ group: _commons.API.GROUP.SEARCH,
28
+ name: _commons.API.NAME.AUTOCOMPLETE,
29
+ payload: {
30
+ completion_fields: ['suggested_queries', 'title'],
31
+ fl: ['title', 'url', 'cover_image']
32
+ }
33
+ },
34
+ throttle: 300
35
+ });
21
36
  const DEFAULT_LAYOUTS = Object.freeze({
22
- [_constants.ROLE.QUERY]: _index2.SearchBoxLayout.type,
23
- [_constants.ROLE.PRODUCTS]: _index2.ListLayout.type
37
+ [_constants.ROLE.QUERY]: _index3.SearchBoxLayout.type,
38
+ [_constants.ROLE.PRODUCTS]: _index3.ListLayout.type
24
39
  });
25
40
  const DEFAULT_TRACKERS = Object.freeze({
26
41
  [_constants.ROLE.PRODUCTS]: {}
27
42
  });
28
43
  const DEFAULT_OPTIONS = Object.freeze({
29
44
  api: DEFAULT_API_OPTIONS,
45
+ autocomplete: DEFAULT_AUTOCOMPLETE_OPTIONS,
30
46
  layouts: DEFAULT_LAYOUTS,
31
47
  trackers: DEFAULT_TRACKERS
32
48
  });
@@ -39,7 +55,11 @@ class Search extends _base.default {
39
55
  roles: Object.keys(DEFAULT_LAYOUTS),
40
56
  defaults: DEFAULT_OPTIONS
41
57
  });
42
- this._unsubscribes.push(this._hub.on(_index.fields.query(), payload => this.query(payload)));
58
+ this._autocomplete = new _index2.AutocompleteActor(this._hub, {
59
+ source: sources.api(this._client),
60
+ options: this._options
61
+ });
62
+ this._unsubscribes.push(this._hub.on(_index2.fields.query(), payload => this.query(payload)));
43
63
  }
44
64
 
45
65
  // lifecycle //
@@ -71,12 +91,19 @@ class Search extends _base.default {
71
91
  const {
72
92
  session
73
93
  } = this;
74
- this._hub.update(_index.fields.request(), (0, _options.mergeApiOptions)(this._options.resolved.api, {
94
+ this._hub.update(_index2.fields.request(), (0, _options.mergeApiOptions)(this._options.resolved.api, {
75
95
  payload,
76
96
  session
77
97
  }));
78
98
  return this;
79
99
  }
100
+ updateCompletions(event) {
101
+ // TODO: verify
102
+ this._hub.update(_index2.fields.completions(), Object.assign({}, event, {
103
+ source: 'manual'
104
+ }));
105
+ return this;
106
+ }
80
107
  notifyViewUpdate() {
81
108
  let role = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.ROLE.PRODUCTS;
82
109
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
@@ -86,4 +113,5 @@ class Search extends _base.default {
86
113
  return this;
87
114
  }
88
115
  }
89
- exports.default = Search;
116
+ exports.default = Search;
117
+ (0, _options.makeConfigurable)(Search.prototype, ['autocomplete']);
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@miso.ai/commons": "1.9.10"
29
+ "@miso.ai/commons": "1.10.0-beta.1"
30
30
  },
31
- "version": "1.9.10"
31
+ "version": "1.10.0-beta.1"
32
32
  }