@miso.ai/client-sdk-ui 1.9.0 → 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.
- package/dist/cjs/actor/views.js +1 -1
- package/dist/cjs/combo/ask/elements.js +0 -7
- package/dist/cjs/combo/ask/index.js +3 -21
- package/dist/cjs/combo/ask/options.js +3 -7
- package/dist/cjs/defaults/ask/constants.js +7 -0
- package/dist/cjs/defaults/ask/index.js +14 -0
- package/dist/cjs/{combo → defaults}/ask/phrases.js +15 -0
- package/dist/cjs/defaults/ask/templates.js +128 -0
- package/dist/cjs/defaults/index.js +10 -0
- package/dist/cjs/layout/input/search-box.js +49 -0
- package/dist/cjs/plugin.js +13 -8
- package/dist/cjs/styles.js +38 -18
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/ask.js +23 -0
- package/dist/cjs/workflow/base.js +3 -0
- package/dist/cjs/workflow/search.js +23 -0
- package/package.json +2 -2
- package/src/actor/views.js +1 -1
- package/src/combo/ask/elements.js +0 -8
- package/src/combo/ask/index.js +2 -16
- package/src/combo/ask/options.js +2 -4
- package/src/defaults/ask/constants.js +1 -0
- package/src/defaults/ask/index.js +7 -0
- package/src/defaults/ask/phrases.js +19 -0
- package/src/defaults/ask/templates.js +107 -0
- package/src/defaults/index.js +3 -0
- package/src/layout/input/search-box.js +51 -0
- package/src/plugin.js +16 -7
- package/src/styles.js +42 -19
- package/src/version.js +1 -1
- package/src/workflow/ask.js +16 -0
- package/src/workflow/base.js +4 -0
- package/src/workflow/search.js +16 -0
- package/dist/cjs/combo/ask/templates.js +0 -87
- package/src/combo/ask/phrases.js +0 -7
- package/src/combo/ask/templates.js +0 -72
package/dist/cjs/actor/views.js
CHANGED
|
@@ -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"));
|
|
@@ -122,9 +120,9 @@ class AskCombo extends _base.default {
|
|
|
122
120
|
let {
|
|
123
121
|
workflow
|
|
124
122
|
} = _ref;
|
|
125
|
-
elements.followUpsSection.insertAdjacentHTML('beforeend', templates.followUp(options, {
|
|
123
|
+
elements.followUpsSection.insertAdjacentHTML('beforeend', templates.followUp(Object.assign({}, options, {
|
|
126
124
|
parentQuestionId: workflow.questionId
|
|
127
|
-
}));
|
|
125
|
+
})));
|
|
128
126
|
});
|
|
129
127
|
|
|
130
128
|
// when a new query starts, associate the last section container (for related resources) to that workflow
|
|
@@ -145,24 +143,8 @@ class AskCombo extends _base.default {
|
|
|
145
143
|
});
|
|
146
144
|
});
|
|
147
145
|
|
|
148
|
-
// wait for miso-query content to be populated
|
|
149
|
-
const QUERY = _index.fields.view(_constants.ROLE.QUERY);
|
|
150
|
-
if (!rootWorkflow.states[QUERY]) {
|
|
151
|
-
await rootWorkflow._hub.once(QUERY);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
146
|
// start query if specified in URL
|
|
155
|
-
|
|
156
|
-
q
|
|
157
|
-
} = options;
|
|
158
|
-
if (q) {
|
|
159
|
-
elements.rootInput.value = q;
|
|
160
|
-
rootWorkflow.query({
|
|
161
|
-
q
|
|
162
|
-
});
|
|
163
|
-
} else {
|
|
164
|
-
elements.rootInput.focus();
|
|
165
|
-
}
|
|
147
|
+
rootWorkflow.autoQuery();
|
|
166
148
|
}
|
|
167
149
|
}
|
|
168
150
|
exports.default = AskCombo;
|
|
@@ -5,11 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
|
-
var
|
|
9
|
-
var phrases = _interopRequireWildcard(require("./phrases.js"));
|
|
8
|
+
var _index = require("../../defaults/ask/index.js");
|
|
10
9
|
const _excluded = ["api_key", "api_host", "templates", "phrases"];
|
|
11
|
-
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); }
|
|
12
|
-
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; }
|
|
13
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; }
|
|
14
11
|
// TODO: generalize
|
|
15
12
|
|
|
@@ -17,8 +14,7 @@ const {
|
|
|
17
14
|
currentScript
|
|
18
15
|
} = document;
|
|
19
16
|
const DEFAULT_OPTIONS = Object.freeze({
|
|
20
|
-
templates,
|
|
21
|
-
phrases,
|
|
17
|
+
templates: _index.templates,
|
|
22
18
|
autostart: true
|
|
23
19
|
});
|
|
24
20
|
class AskComboOptions {
|
|
@@ -62,7 +58,7 @@ function normalizeOptions() {
|
|
|
62
58
|
apiKey,
|
|
63
59
|
apiHost,
|
|
64
60
|
templates: templateAsFunction(templates),
|
|
65
|
-
phrases
|
|
61
|
+
phrases
|
|
66
62
|
}, options));
|
|
67
63
|
}
|
|
68
64
|
|
|
@@ -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);
|
|
@@ -4,7 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.sources = exports.relatedResources = exports.relatedQuestions = exports.question = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* The phrase displayed right before <miso-question>
|
|
9
|
+
*/
|
|
7
10
|
const question = exports.question = 'You asked...';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The phrase displayed right before <miso-sources>
|
|
14
|
+
*/
|
|
8
15
|
const sources = exports.sources = 'My reply is based on the following';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The phrase displayed right before <miso-query-suggestions>
|
|
19
|
+
*/
|
|
9
20
|
const relatedQuestions = exports.relatedQuestions = 'Related questions you can explore';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The phrase displayed right before <miso-related-resources>
|
|
24
|
+
*/
|
|
10
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
|
}
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -11,6 +11,7 @@ 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"));
|
|
14
15
|
var _styles = require("./styles.js");
|
|
15
16
|
var _misoContainer = _interopRequireDefault(require("./element/container/miso-container.js"));
|
|
16
17
|
var _misoCombo = _interopRequireDefault(require("./element/combo/miso-combo.js"));
|
|
@@ -30,12 +31,15 @@ class UiPlugin extends _commons.Component {
|
|
|
30
31
|
this._recommendations = new WeakMap();
|
|
31
32
|
this._asks = new WeakMap();
|
|
32
33
|
this._extensions = new WeakMap();
|
|
34
|
+
this._ready = new _commons.Resolution();
|
|
33
35
|
}
|
|
34
36
|
async install(MisoClient, context) {
|
|
35
37
|
context.addSubtree(this);
|
|
36
38
|
MisoClient.on('create', this._injectClient.bind(this));
|
|
37
|
-
const ui = {
|
|
38
|
-
|
|
39
|
+
const ui = {
|
|
40
|
+
defaults
|
|
41
|
+
};
|
|
42
|
+
(0, _commons.delegateGetters)(ui, this, ['layouts', 'combo', 'ready']);
|
|
39
43
|
(0, _commons.defineValues)(this, {
|
|
40
44
|
MisoClient
|
|
41
45
|
});
|
|
@@ -78,6 +82,7 @@ class UiPlugin extends _commons.Component {
|
|
|
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;
|
package/dist/cjs/styles.js
CHANGED
|
@@ -18,17 +18,13 @@ async function loadStylesIfNecessary() {
|
|
|
18
18
|
async function loadStyles() {
|
|
19
19
|
try {
|
|
20
20
|
let link = getExistedLinkElement();
|
|
21
|
-
if (link) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
link.rel = 'stylesheet';
|
|
26
|
-
link.href = getCssUrl();
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
link.onload = resolve;
|
|
29
|
-
link.onerror = reject;
|
|
21
|
+
if (!link) {
|
|
22
|
+
link = document.createElement('link');
|
|
23
|
+
link.rel = 'stylesheet';
|
|
24
|
+
link.href = getCssUrl();
|
|
30
25
|
document.head.appendChild(link);
|
|
31
|
-
}
|
|
26
|
+
}
|
|
27
|
+
return waitForStylesApplied(link);
|
|
32
28
|
} catch (e) {
|
|
33
29
|
console.error(e);
|
|
34
30
|
}
|
|
@@ -53,25 +49,49 @@ function resolveCssUrl() {
|
|
|
53
49
|
function getExistedLinkElement() {
|
|
54
50
|
return document.head.querySelector(`link[href="${getCssUrl()}"]`);
|
|
55
51
|
}
|
|
56
|
-
async function
|
|
52
|
+
async function waitForStylesApplied(element) {
|
|
53
|
+
await waitForSheetAvailable(element);
|
|
54
|
+
await waitForSheetIncluded(element);
|
|
55
|
+
}
|
|
56
|
+
async function waitForSheetAvailable(element) {
|
|
57
57
|
if (element.sheet) {
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
return new Promise((resolve, reject) => {
|
|
61
61
|
let intervalId;
|
|
62
|
-
element.onload = () => {
|
|
63
|
-
intervalId && clearInterval(intervalId);
|
|
64
|
-
resolve();
|
|
65
|
-
};
|
|
66
62
|
element.onerror = () => {
|
|
67
63
|
intervalId && clearInterval(intervalId);
|
|
68
64
|
reject();
|
|
69
65
|
};
|
|
70
66
|
intervalId = setInterval(() => {
|
|
71
|
-
if (element.sheet) {
|
|
72
|
-
|
|
73
|
-
resolve();
|
|
67
|
+
if (!element.sheet) {
|
|
68
|
+
return;
|
|
74
69
|
}
|
|
70
|
+
intervalId && clearInterval(intervalId);
|
|
71
|
+
resolve();
|
|
75
72
|
}, 100);
|
|
76
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;
|
|
77
97
|
}
|
package/dist/cjs/version.js
CHANGED
package/dist/cjs/workflow/ask.js
CHANGED
|
@@ -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 {
|
|
@@ -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 {
|
package/package.json
CHANGED
package/src/actor/views.js
CHANGED
|
@@ -9,14 +9,10 @@ export default class AskComboElements {
|
|
|
9
9
|
}
|
|
10
10
|
defineValues(this, {
|
|
11
11
|
root,
|
|
12
|
-
rootQuery: root.querySelector(`#${PREFIX}__question miso-query`),
|
|
13
12
|
followUpsSection: root.querySelector(`#${PREFIX}__follow-ups`),
|
|
14
13
|
relatedResourcesContainer: root.querySelector(`#${PREFIX}__related-resources miso-ask`),
|
|
15
14
|
});
|
|
16
15
|
|
|
17
|
-
if (!this.rootQuery) {
|
|
18
|
-
throw new Error(`Root question query element not found.`);
|
|
19
|
-
}
|
|
20
16
|
if (!this.followUpsSection) {
|
|
21
17
|
throw new Error(`Follow-ups section element not found.`);
|
|
22
18
|
}
|
|
@@ -25,8 +21,4 @@ export default class AskComboElements {
|
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
23
|
|
|
28
|
-
get rootInput() {
|
|
29
|
-
return this.rootQuery.querySelector(`[data-role="input"]`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
24
|
}
|