@miso.ai/client-sdk-ui 1.9.0-beta.9 → 1.9.1-beta.0

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.
@@ -218,7 +218,7 @@ class Views {
218
218
  get(role) {
219
219
  return this._actor.get(role).interface;
220
220
  }
221
- get views() {
221
+ get all() {
222
222
  return this._actor.views.map(view => view.interface);
223
223
  }
224
224
  }
@@ -13,13 +13,9 @@ class AskComboElements {
13
13
  }
14
14
  (0, _commons.defineValues)(this, {
15
15
  root,
16
- rootQuery: root.querySelector(`#${_constants.PREFIX}__question miso-query`),
17
16
  followUpsSection: root.querySelector(`#${_constants.PREFIX}__follow-ups`),
18
17
  relatedResourcesContainer: root.querySelector(`#${_constants.PREFIX}__related-resources miso-ask`)
19
18
  });
20
- if (!this.rootQuery) {
21
- throw new Error(`Root question query element not found.`);
22
- }
23
19
  if (!this.followUpsSection) {
24
20
  throw new Error(`Follow-ups section element not found.`);
25
21
  }
@@ -27,8 +23,5 @@ class AskComboElements {
27
23
  throw new Error(`Related resources container element not found.`);
28
24
  }
29
25
  }
30
- get rootInput() {
31
- return this.rootQuery.querySelector(`[data-role="input"]`);
32
- }
33
26
  }
34
27
  exports.default = AskComboElements;
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _commons = require("@miso.ai/commons");
8
- var _index = require("../../actor/index.js");
9
- var _constants = require("../../constants.js");
10
8
  var _base = _interopRequireDefault(require("../base.js"));
11
9
  var _options = _interopRequireDefault(require("./options.js"));
12
10
  var _elements = _interopRequireDefault(require("./elements.js"));
@@ -115,14 +113,16 @@ class AskCombo extends _base.default {
115
113
  const context = client.ui.asks;
116
114
  const rootWorkflow = client.ui.ask;
117
115
 
116
+ // TODO: set placeholder is present in options
117
+
118
118
  // when a answer is fully populated, insert a new section for the follow-up question
119
119
  context.on('done', _ref => {
120
120
  let {
121
121
  workflow
122
122
  } = _ref;
123
- elements.followUpsSection.insertAdjacentHTML('beforeend', templates.followUp(options, {
123
+ elements.followUpsSection.insertAdjacentHTML('beforeend', templates.followUp(Object.assign({}, options, {
124
124
  parentQuestionId: workflow.questionId
125
- }));
125
+ })));
126
126
  });
127
127
 
128
128
  // when a new query starts, associate the last section container (for related resources) to that workflow
@@ -143,24 +143,8 @@ class AskCombo extends _base.default {
143
143
  });
144
144
  });
145
145
 
146
- // wait for miso-query content to be populated
147
- const QUERY = _index.fields.view(_constants.ROLE.QUERY);
148
- if (!rootWorkflow.states[QUERY]) {
149
- await rootWorkflow._hub.once(QUERY);
150
- }
151
-
152
146
  // start query if specified in URL
153
- const {
154
- q
155
- } = options;
156
- if (q) {
157
- elements.rootInput.value = q;
158
- rootWorkflow.query({
159
- q
160
- });
161
- } else {
162
- elements.rootInput.focus();
163
- }
147
+ rootWorkflow.autoQuery();
164
148
  }
165
149
  }
166
150
  exports.default = AskCombo;
@@ -5,10 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _commons = require("@miso.ai/commons");
8
- var templates = _interopRequireWildcard(require("./templates.js"));
9
- const _excluded = ["api_key", "api_host"];
10
- 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); }
11
- 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 && Object.prototype.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; }
8
+ var _index = require("../../defaults/ask/index.js");
9
+ const _excluded = ["api_key", "api_host", "templates", "phrases"];
12
10
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
13
11
  // TODO: generalize
14
12
 
@@ -16,7 +14,7 @@ const {
16
14
  currentScript
17
15
  } = document;
18
16
  const DEFAULT_OPTIONS = Object.freeze({
19
- templates,
17
+ templates: _index.templates,
20
18
  autostart: true
21
19
  });
22
20
  class AskComboOptions {
@@ -51,12 +49,16 @@ function normalizeOptions() {
51
49
  let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
52
50
  let {
53
51
  api_key: apiKey,
54
- api_host: apiHost
52
+ api_host: apiHost,
53
+ templates,
54
+ phrases
55
55
  } = _ref,
56
56
  options = _objectWithoutPropertiesLoose(_ref, _excluded);
57
57
  return (0, _commons.trimObj)(Object.assign({
58
58
  apiKey,
59
- apiHost
59
+ apiHost,
60
+ templates: templateAsFunction(templates),
61
+ phrases
60
62
  }, options));
61
63
  }
62
64
 
@@ -98,4 +100,27 @@ function readFromPageUrl() {
98
100
  }
99
101
  function coerceValue(value) {
100
102
  return value === '' ? true : value === 'false' ? false : value;
103
+ }
104
+ function templateAsFunction(value) {
105
+ if (value === undefined || value === null) {
106
+ return value;
107
+ }
108
+ switch (typeof value) {
109
+ case 'function':
110
+ return value;
111
+ case 'string':
112
+ case 'number':
113
+ return () => value;
114
+ case 'object':
115
+ return Array.isArray(value) ? value.map(templateAsFunction) : mappingObjectValues(value, templateAsFunction);
116
+ default:
117
+ throw new Error(`Unsupported template type: ${value}`);
118
+ }
119
+ }
120
+ function mappingObjectValues(obj, fn) {
121
+ const mapped = {};
122
+ for (const [key, value] of Object.entries(obj)) {
123
+ mapped[key] = fn(value);
124
+ }
125
+ return mapped;
101
126
  }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CLASS_PREFIX = void 0;
7
+ const CLASS_PREFIX = exports.CLASS_PREFIX = 'miso-ask-combo';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.templates = exports.phrases = exports.constants = void 0;
7
+ var _constants = _interopRequireWildcard(require("./constants.js"));
8
+ var _phrases = _interopRequireWildcard(require("./phrases.js"));
9
+ var _templates = _interopRequireWildcard(require("./templates.js"));
10
+ 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); }
11
+ 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 && Object.prototype.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; }
12
+ const constants = exports.constants = Object.freeze(_constants);
13
+ const phrases = exports.phrases = Object.freeze(_phrases);
14
+ const templates = exports.templates = Object.freeze(_templates);
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sources = exports.relatedResources = exports.relatedQuestions = exports.question = void 0;
7
+ /**
8
+ * The phrase displayed right before <miso-question>
9
+ */
10
+ const question = exports.question = 'You asked...';
11
+
12
+ /**
13
+ * The phrase displayed right before <miso-sources>
14
+ */
15
+ const sources = exports.sources = 'My reply is based on the following';
16
+
17
+ /**
18
+ * The phrase displayed right before <miso-query-suggestions>
19
+ */
20
+ const relatedQuestions = exports.relatedQuestions = 'Related questions you can explore';
21
+
22
+ /**
23
+ * The phrase displayed right before <miso-related-resources>
24
+ */
25
+ const relatedResources = exports.relatedResources = 'Go beyond, and learn more about this topic';
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.followUp = followUp;
7
+ exports.root = root;
8
+ var _constants = require("./constants.js");
9
+ var DEFAULT_PHRASES = _interopRequireWildcard(require("./phrases.js"));
10
+ 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); }
11
+ 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 && Object.prototype.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; }
12
+ // TODO: refactor
13
+ // TODO: make ids constants
14
+ // TODO: placeholder
15
+
16
+ function root() {
17
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
18
+ const {
19
+ classPrefix = _constants.CLASS_PREFIX
20
+ } = options;
21
+ return `
22
+ <section id="${classPrefix}__question" class="${classPrefix}__section ${classPrefix}__question">
23
+ <miso-ask class="${classPrefix}__query-container">
24
+ <miso-query></miso-query>
25
+ </miso-ask>
26
+ </section>
27
+ <section class="${classPrefix}__section ${classPrefix}__answer">
28
+ ${answer(options)}
29
+ ${sources(options)}
30
+ <miso-ask class="${classPrefix}__bottom-spacing-container" visible-when="ongoing"></miso-ask>
31
+ </section>
32
+ <div id="${classPrefix}__follow-ups" class="${classPrefix}__follow-ups"></div>
33
+ <section id="${classPrefix}__related-resources" class="${classPrefix}__section ${classPrefix}__related-resources">
34
+ <miso-ask visible-when="nonempty" logo="true">
35
+ <h2 class="${classPrefix}__phrase ${classPrefix}__related-resources-phrase">${phraseText(options, 'relatedResources')}</h2>
36
+ <miso-related-resources></miso-related-resources>
37
+ </miso-ask>
38
+ </section>`.trim();
39
+ }
40
+ ;
41
+ function followUp() {
42
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
43
+ const {
44
+ classPrefix = _constants.CLASS_PREFIX,
45
+ parentQuestionId
46
+ } = options;
47
+ return `
48
+ <section class="${classPrefix}__section ${classPrefix}__follow-up">
49
+ <miso-ask class="${classPrefix}__query-suggestions-container" visible-when="initial+nonempty" parent-question-id="${parentQuestionId}">
50
+ <h3 class="${classPrefix}__phrase ${classPrefix}__related-questions-phrase">${phraseText(options, 'relatedQuestions')}</h3>
51
+ <miso-query-suggestions></miso-query-suggestions>
52
+ </miso-ask>
53
+ <miso-ask class="${classPrefix}__query-container" visible-when="initial loading" parent-question-id="${parentQuestionId}">
54
+ <miso-query></miso-query>
55
+ </miso-ask>
56
+ ${answer(options)}
57
+ ${sources(options)}
58
+ <miso-ask class="${classPrefix}__bottom-spacing-container" visible-when="ongoing" parent-question-id="${parentQuestionId}"></miso-ask>
59
+ </section>`.trim();
60
+ }
61
+ ;
62
+
63
+ // helpers //
64
+ function answer(options) {
65
+ const {
66
+ classPrefix = _constants.CLASS_PREFIX
67
+ } = options;
68
+ return `
69
+ ${containerOpenTag('answer', Object.assign({}, options, {
70
+ visibleWhen: 'ready'
71
+ }))}
72
+ ${options.parentQuestionId ? '<hr>' : ''}
73
+ <div class="${classPrefix}__phrase ${classPrefix}__question-phrase">${phraseText(options, 'question')}</div>
74
+ <miso-question></miso-question>
75
+ <miso-answer></miso-answer>
76
+ <miso-feedback></miso-feedback>
77
+ </miso-ask>`.trim();
78
+ }
79
+ ;
80
+ function sources(options) {
81
+ const {
82
+ classPrefix = _constants.CLASS_PREFIX
83
+ } = options;
84
+ return `
85
+ ${containerOpenTag('sources', Object.assign({}, options, {
86
+ visibleWhen: 'nonempty'
87
+ }))}
88
+ <hr>
89
+ <h3 class="${classPrefix}__phrase ${classPrefix}__sources-phrase">${phraseText(options, 'sources')}</h3>
90
+ <miso-sources></miso-sources>
91
+ </miso-ask>`.trim();
92
+ }
93
+ ;
94
+ function phraseText(options, key) {
95
+ const {
96
+ phrases = {}
97
+ } = options;
98
+ const fn = phrases[key] || DEFAULT_PHRASES[key];
99
+ switch (typeof fn) {
100
+ case 'function':
101
+ return fn(options);
102
+ case 'string':
103
+ return fn;
104
+ default:
105
+ return '';
106
+ }
107
+ }
108
+ function containerOpenTag(name, _ref) {
109
+ let {
110
+ visibleWhen,
111
+ classPrefix = _constants.CLASS_PREFIX,
112
+ logo = false,
113
+ circledCitationIndex = true,
114
+ parentQuestionId
115
+ } = _ref;
116
+ let className = `${classPrefix}__${name}-container`;
117
+ if (circledCitationIndex) {
118
+ className += ` miso-circled-citation-index`;
119
+ }
120
+ const attributes = [` class="${className}"`, ` logo="${logo ? 'true' : 'false'}"`];
121
+ if (visibleWhen) {
122
+ attributes.push(` visible-when="${visibleWhen}"`);
123
+ }
124
+ if (parentQuestionId) {
125
+ attributes.push(` parent-question-id="${parentQuestionId}"`);
126
+ }
127
+ return `<miso-ask${attributes.join('')}>`;
128
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ask = void 0;
7
+ var _ask = _interopRequireWildcard(require("./ask/index.js"));
8
+ 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); }
9
+ 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 && Object.prototype.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; }
10
+ const ask = exports.ask = Object.freeze(_ask);
@@ -110,6 +110,21 @@ class SearchBoxLayout extends _template.default {
110
110
  this._unsubscribes.push(hub.on(_index.fields.suggestions(), () => this._handleInput()));
111
111
  }
112
112
  }
113
+ focus() {
114
+ if (this._element) {
115
+ this._context().focus();
116
+ } else {
117
+ // take a rain check, wait for render
118
+ this._focusRequested = true;
119
+ }
120
+ }
121
+ set value(value) {
122
+ if (this._element) {
123
+ this._context().value = value;
124
+ } else {
125
+ this._valueRequested = value;
126
+ }
127
+ }
113
128
  _preprocess(_ref2) {
114
129
  let {
115
130
  state
@@ -135,6 +150,8 @@ class SearchBoxLayout extends _template.default {
135
150
  }
136
151
  this._setupAutocomplete(element);
137
152
  this._renderSuggestions(element, data, controls);
153
+ this._fullfillFocusRequest(element);
154
+ this._fullfillValueRequest(element);
138
155
  }
139
156
  _setupAutocomplete(element) {
140
157
  const {
@@ -184,6 +201,20 @@ class SearchBoxLayout extends _template.default {
184
201
  this._suggestionItems.set(itemElement, suggestionItems[i++]);
185
202
  }
186
203
  }
204
+ _fullfillFocusRequest(element) {
205
+ if (!element || !this._focusRequested) {
206
+ return;
207
+ }
208
+ this._focusRequested = false;
209
+ this._context(element).focus();
210
+ }
211
+ _fullfillValueRequest(element) {
212
+ if (!element || !this._valueRequested) {
213
+ return;
214
+ }
215
+ this._context(element).value = this._valueRequested;
216
+ this._valueRequested = undefined;
217
+ }
187
218
  _context(element) {
188
219
  element = element || this._view.element;
189
220
  if (!element) {
@@ -288,6 +319,24 @@ class Context {
288
319
  });
289
320
  }
290
321
  }
322
+ focus() {
323
+ if (!this._element) {
324
+ return;
325
+ }
326
+ const {
327
+ inputElement
328
+ } = this;
329
+ inputElement && inputElement.focus();
330
+ }
331
+ set value(value) {
332
+ if (!this._element) {
333
+ return;
334
+ }
335
+ const {
336
+ inputElement
337
+ } = this;
338
+ inputElement && (inputElement.value = value);
339
+ }
291
340
  _get(role) {
292
341
  return !this._element ? undefined : this._cache[role] || (this._cache[role] = this._element.querySelector(`[data-role="${role}"]`));
293
342
  }
@@ -11,6 +11,8 @@ var _layouts = _interopRequireDefault(require("./layouts.js"));
11
11
  var elements = _interopRequireWildcard(require("./element/index.js"));
12
12
  var layouts = _interopRequireWildcard(require("./layout/index.js"));
13
13
  var sources = _interopRequireWildcard(require("./source/index.js"));
14
+ var defaults = _interopRequireWildcard(require("./defaults/index.js"));
15
+ var _styles = require("./styles.js");
14
16
  var _misoContainer = _interopRequireDefault(require("./element/container/miso-container.js"));
15
17
  var _misoCombo = _interopRequireDefault(require("./element/combo/miso-combo.js"));
16
18
  const _excluded = ["containers", "roles", "combos"];
@@ -24,22 +26,20 @@ class UiPlugin extends _commons.Component {
24
26
  return PLUGIN_ID;
25
27
  }
26
28
  constructor() {
27
- let {
28
- loadStyles = true
29
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
30
29
  super('ui');
31
30
  this.layouts = new _layouts.default(this);
32
31
  this._recommendations = new WeakMap();
33
32
  this._asks = new WeakMap();
34
33
  this._extensions = new WeakMap();
35
- // TODO: load CSS
34
+ this._ready = new _commons.Resolution();
36
35
  }
37
-
38
- install(MisoClient, context) {
36
+ async install(MisoClient, context) {
39
37
  context.addSubtree(this);
40
38
  MisoClient.on('create', this._injectClient.bind(this));
41
- const ui = {};
42
- (0, _commons.delegateGetters)(ui, this, ['layouts', 'combo']);
39
+ const ui = {
40
+ defaults
41
+ };
42
+ (0, _commons.delegateGetters)(ui, this, ['layouts', 'combo', 'ready']);
43
43
  (0, _commons.defineValues)(this, {
44
44
  MisoClient
45
45
  });
@@ -75,9 +75,14 @@ class UiPlugin extends _commons.Component {
75
75
  ElementClass.MisoClient = MisoClient; // TODO: find better way
76
76
  }
77
77
 
78
+ // load styles
79
+ await (0, _styles.loadStylesIfNecessary)();
80
+
81
+ // define custom elements
78
82
  for (const ElementClass of ElementClasses) {
79
83
  (0, _commons.defineAndUpgrade)(ElementClass);
80
84
  }
85
+ this._ready.resolve();
81
86
  }
82
87
  async requireExtension(name) {
83
88
  switch (name) {
@@ -87,6 +92,10 @@ class UiPlugin extends _commons.Component {
87
92
  throw new Error(`Unknown extension: ${name}`);
88
93
  }
89
94
  }
95
+ get ready() {
96
+ return Promise.all([this._ready.promise, MisoClient.any() // TODO: we need to wait for element connection
97
+ ]).then(() => {});
98
+ }
90
99
  _injectClient(client) {
91
100
  (0, _commons.defineValues)(client, {
92
101
  ui: new Ui(this, client)
@@ -160,14 +169,10 @@ class Ui {
160
169
  get explore() {
161
170
  return this._explore || (this._explore = new _index.Explore(this._plugin, this._client));
162
171
  }
163
-
164
- /*
165
- async whenStylesLoaded() {
166
- // TODO
172
+ get ready() {
173
+ return this._plugin._ready.promise;
167
174
  }
168
- */
169
175
  }
170
-
171
176
  class Combo {
172
177
  constructor(plugin, MisoClient) {
173
178
  this._plugin = plugin;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadStyles = loadStyles;
7
+ exports.loadStylesIfNecessary = loadStylesIfNecessary;
8
+ var _version = _interopRequireDefault(require("./version.js"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ const {
11
+ currentScript
12
+ } = document;
13
+ let cssUrl;
14
+ let stylesLoaded;
15
+ 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
+ }
31
+ }
32
+
33
+ // helpers //
34
+ 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;
97
+ }
@@ -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.0-beta.9';
7
+ var _default = exports.default = '1.9.1-beta.0';
@@ -123,6 +123,29 @@ class Ask extends _base.default {
123
123
  }
124
124
 
125
125
  // lifecycle //
126
+ autoQuery() {
127
+ let {
128
+ setValue = true,
129
+ focus = true
130
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
131
+ const q = new URLSearchParams(window.location.search).get('q');
132
+ const {
133
+ layout
134
+ } = this._views.get(_constants.ROLE.QUERY);
135
+ if (layout) {
136
+ if (q && setValue) {
137
+ layout.value = q;
138
+ }
139
+ if (!q && focus) {
140
+ layout.focus();
141
+ }
142
+ }
143
+ if (q) {
144
+ this.query({
145
+ q
146
+ });
147
+ }
148
+ }
126
149
  query() {
127
150
  let _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
128
151
  let {
@@ -98,6 +98,9 @@ class Workflow extends _commons.Component {
98
98
  get states() {
99
99
  return this._hub.states;
100
100
  }
101
+ get views() {
102
+ return this._views.interface;
103
+ }
101
104
 
102
105
  // lifecycle //
103
106
  reset() {
@@ -43,6 +43,29 @@ class Search extends _base.default {
43
43
  }
44
44
 
45
45
  // lifecycle //
46
+ autoQuery() {
47
+ let {
48
+ setValue = true,
49
+ focus = true
50
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
51
+ const q = new URLSearchParams(window.location.search).get('q');
52
+ const {
53
+ layout
54
+ } = this._views.get(_constants.ROLE.QUERY);
55
+ if (layout) {
56
+ if (q && setValue) {
57
+ layout.value = q;
58
+ }
59
+ if (!q && focus) {
60
+ layout.focus();
61
+ }
62
+ }
63
+ if (q) {
64
+ this.query({
65
+ q
66
+ });
67
+ }
68
+ }
46
69
  query(payload) {
47
70
  this.restart();
48
71
  const {