@miso.ai/client-sdk-ui 1.9.0 → 1.9.1-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.
- package/dist/cjs/actor/views.js +1 -1
- package/dist/cjs/combo/ask/elements.js +6 -16
- package/dist/cjs/combo/ask/index.js +34 -49
- package/dist/cjs/combo/ask/options.js +3 -7
- package/dist/cjs/combo/base.js +5 -0
- 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 +205 -0
- package/dist/cjs/defaults/index.js +10 -0
- package/dist/cjs/element/role/miso-component.js +0 -1
- package/dist/cjs/layout/input/search-box.js +49 -1
- package/dist/cjs/layout/list/carousel.js +0 -1
- package/dist/cjs/layout/radio/radio.js +0 -1
- package/dist/cjs/layout/raf.js +0 -2
- package/dist/cjs/layout/templates.js +0 -1
- package/dist/cjs/plugin.js +13 -10
- package/dist/cjs/styles.js +38 -18
- package/dist/cjs/util/bindings.js +0 -1
- package/dist/cjs/util/proxy.js +0 -1
- package/dist/cjs/util/states.js +0 -1
- package/dist/cjs/util/tracker.js +0 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/ask.js +23 -2
- package/dist/cjs/workflow/asks.js +0 -2
- package/dist/cjs/workflow/base.js +3 -1
- 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 +4 -19
- package/src/combo/ask/index.js +24 -35
- package/src/combo/ask/options.js +2 -4
- package/src/combo/base.js +7 -1
- 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 +154 -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/constants.js +0 -7
- package/dist/cjs/combo/ask/templates.js +0 -87
- package/src/combo/ask/constants.js +0 -1
- package/src/combo/ask/phrases.js +0 -7
- package/src/combo/ask/templates.js +0 -72
package/dist/cjs/actor/views.js
CHANGED
|
@@ -5,30 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
|
-
var
|
|
8
|
+
var _index = require("../../defaults/ask/index.js");
|
|
9
9
|
class AskComboElements {
|
|
10
10
|
constructor(root) {
|
|
11
|
+
let {
|
|
12
|
+
classPrefix = _index.constants.CLASS_PREFIX
|
|
13
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
11
14
|
if (!root) {
|
|
12
15
|
throw new Error('Root element is required');
|
|
13
16
|
}
|
|
14
17
|
(0, _commons.defineValues)(this, {
|
|
15
18
|
root,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
relatedResourcesContainer: root.querySelector(`#${_constants.PREFIX}__related-resources miso-ask`)
|
|
19
|
+
followUpsSection: root.querySelector(`.${classPrefix}__follow-ups`),
|
|
20
|
+
relatedResourcesContainer: root.querySelector(`.${classPrefix}__related-resources miso-ask`)
|
|
19
21
|
});
|
|
20
|
-
if (!this.rootQuery) {
|
|
21
|
-
throw new Error(`Root question query element not found.`);
|
|
22
|
-
}
|
|
23
|
-
if (!this.followUpsSection) {
|
|
24
|
-
throw new Error(`Follow-ups section element not found.`);
|
|
25
|
-
}
|
|
26
|
-
if (!this.relatedResourcesContainer) {
|
|
27
|
-
throw new Error(`Related resources container element not found.`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
get rootInput() {
|
|
31
|
-
return this.rootQuery.querySelector(`[data-role="input"]`);
|
|
32
22
|
}
|
|
33
23
|
}
|
|
34
24
|
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"));
|
|
@@ -47,7 +45,7 @@ class AskCombo extends _base.default {
|
|
|
47
45
|
}
|
|
48
46
|
async _start() {
|
|
49
47
|
await (0, _commons.waitForDomContentLoaded)();
|
|
50
|
-
await this.
|
|
48
|
+
await this.waitForElement();
|
|
51
49
|
|
|
52
50
|
// setup MisoClient
|
|
53
51
|
await this._setupMisoClient();
|
|
@@ -98,7 +96,7 @@ class AskCombo extends _base.default {
|
|
|
98
96
|
templates = {}
|
|
99
97
|
} = options;
|
|
100
98
|
element.innerHTML = templates.root(options);
|
|
101
|
-
this._elements = new _elements.default(element);
|
|
99
|
+
this._elements = new _elements.default(element, options);
|
|
102
100
|
}
|
|
103
101
|
async _createClientInstance() {
|
|
104
102
|
this._client = new MisoClient(this.resolvedOptions);
|
|
@@ -110,59 +108,46 @@ class AskCombo extends _base.default {
|
|
|
110
108
|
resolvedOptions: options
|
|
111
109
|
} = this;
|
|
112
110
|
const {
|
|
113
|
-
templates = {}
|
|
111
|
+
templates = {},
|
|
112
|
+
features = {}
|
|
114
113
|
} = options;
|
|
115
114
|
const context = client.ui.asks;
|
|
116
115
|
const rootWorkflow = client.ui.ask;
|
|
117
116
|
|
|
118
|
-
// TODO: set placeholder
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// if user starts over, clean up current follow-up questions
|
|
139
|
-
rootWorkflow.on('loading', () => {
|
|
140
|
-
// clean up the entire follow-ups section
|
|
141
|
-
elements.followUpsSection.innerHTML = '';
|
|
142
|
-
// destroy all follow-up workflows
|
|
143
|
-
context.reset({
|
|
144
|
-
root: false
|
|
117
|
+
// TODO: set placeholder if present in options
|
|
118
|
+
|
|
119
|
+
if (elements.followUpsSection && features.followUpQuestions !== false) {
|
|
120
|
+
// when a answer is fully populated, insert a new section for the follow-up question
|
|
121
|
+
context.on('done', _ref => {
|
|
122
|
+
let {
|
|
123
|
+
workflow
|
|
124
|
+
} = _ref;
|
|
125
|
+
elements.followUpsSection.insertAdjacentHTML('beforeend', templates.followUp(Object.assign({}, options, {
|
|
126
|
+
parentQuestionId: workflow.questionId
|
|
127
|
+
})));
|
|
128
|
+
});
|
|
129
|
+
// if user starts over, clean up current follow-up questions
|
|
130
|
+
rootWorkflow.on('loading', () => {
|
|
131
|
+
// clean up the entire follow-ups section
|
|
132
|
+
elements.followUpsSection.innerHTML = '';
|
|
133
|
+
// destroy all follow-up workflows
|
|
134
|
+
context.reset({
|
|
135
|
+
root: false
|
|
136
|
+
});
|
|
145
137
|
});
|
|
146
|
-
});
|
|
147
|
-
|
|
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
138
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
rootWorkflow.query({
|
|
161
|
-
q
|
|
139
|
+
if (elements.relatedResourcesContainer && features.relatedResources !== false && features.followUpQuestions !== false) {
|
|
140
|
+
// when a new query starts, associate the last section container (for related resources) to that workflow
|
|
141
|
+
context.on('loading', _ref2 => {
|
|
142
|
+
let {
|
|
143
|
+
workflow
|
|
144
|
+
} = _ref2;
|
|
145
|
+
elements.relatedResourcesContainer.workflow = workflow;
|
|
162
146
|
});
|
|
163
|
-
} else {
|
|
164
|
-
elements.rootInput.focus();
|
|
165
147
|
}
|
|
148
|
+
|
|
149
|
+
// start query if specified in URL
|
|
150
|
+
rootWorkflow.autoQuery();
|
|
166
151
|
}
|
|
167
152
|
}
|
|
168
153
|
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
|
|
package/dist/cjs/combo/base.js
CHANGED
|
@@ -27,8 +27,13 @@ class Combo extends _commons.Component {
|
|
|
27
27
|
get element() {
|
|
28
28
|
return this._element;
|
|
29
29
|
}
|
|
30
|
+
async waitForElement() {
|
|
31
|
+
return this._element || (this._elementRes || (this._elementRes = new _commons.Resolution())).promise;
|
|
32
|
+
}
|
|
30
33
|
set element(element) {
|
|
34
|
+
// TODO: guard against multiple element assignment
|
|
31
35
|
this._element = element;
|
|
36
|
+
this._elementRes && this._elementRes.resolve(element);
|
|
32
37
|
}
|
|
33
38
|
start(options) {
|
|
34
39
|
if (this._started) {
|
|
@@ -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,205 @@
|
|
|
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
|
+
const _excluded = ["classPrefix", "circledCitationIndex"],
|
|
11
|
+
_excluded2 = ["classes"];
|
|
12
|
+
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); }
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
// TODO: placeholder
|
|
16
|
+
|
|
17
|
+
function root() {
|
|
18
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
19
|
+
options = normalizeOptions(options);
|
|
20
|
+
return [section(options, {
|
|
21
|
+
name: 'question'
|
|
22
|
+
}, [container(options, {
|
|
23
|
+
name: 'query'
|
|
24
|
+
}, '<miso-query></miso-query>')]), section(options, {
|
|
25
|
+
name: 'answer'
|
|
26
|
+
}, answerGroup(options)), followUps(options), relatedResources(options)].join('');
|
|
27
|
+
}
|
|
28
|
+
;
|
|
29
|
+
function followUp() {
|
|
30
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
31
|
+
options = normalizeOptions(options);
|
|
32
|
+
return section(options, {
|
|
33
|
+
name: 'follow-up'
|
|
34
|
+
}, [querySuggestions(options), container(options, {
|
|
35
|
+
name: 'query',
|
|
36
|
+
visibleWhen: 'initial loading'
|
|
37
|
+
}, '<miso-query></miso-query>'), ...answerGroup(options)]);
|
|
38
|
+
}
|
|
39
|
+
;
|
|
40
|
+
|
|
41
|
+
// options //
|
|
42
|
+
function normalizeOptions() {
|
|
43
|
+
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
44
|
+
let {
|
|
45
|
+
classPrefix = _constants.CLASS_PREFIX,
|
|
46
|
+
circledCitationIndex = true
|
|
47
|
+
} = _ref,
|
|
48
|
+
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
49
|
+
return Object.assign({
|
|
50
|
+
classPrefix,
|
|
51
|
+
circledCitationIndex
|
|
52
|
+
}, options);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// sections & containers //
|
|
56
|
+
function followUps(options) {
|
|
57
|
+
const {
|
|
58
|
+
classPrefix,
|
|
59
|
+
features = {}
|
|
60
|
+
} = options;
|
|
61
|
+
return features.followUpQuestions === false ? '' : `<div id="${classPrefix}__follow-ups" class="${classPrefix}__follow-ups"></div>`;
|
|
62
|
+
}
|
|
63
|
+
function relatedResources(options) {
|
|
64
|
+
const {
|
|
65
|
+
features = {},
|
|
66
|
+
logo = true
|
|
67
|
+
} = options;
|
|
68
|
+
const body = features.relatedResources === false ? '' : container(options, {
|
|
69
|
+
name: 'related-resources',
|
|
70
|
+
visibleWhen: 'nonempty',
|
|
71
|
+
logo
|
|
72
|
+
}, [phrase(options, {
|
|
73
|
+
name: 'related-resources',
|
|
74
|
+
tag: 'h2'
|
|
75
|
+
}), '<miso-related-resources></miso-related-resources>']);
|
|
76
|
+
return section(options, {
|
|
77
|
+
name: 'related-resources'
|
|
78
|
+
}, body);
|
|
79
|
+
}
|
|
80
|
+
function querySuggestions(options) {
|
|
81
|
+
const {
|
|
82
|
+
features = {}
|
|
83
|
+
} = options;
|
|
84
|
+
return features.querySuggestions === false ? '' : container(options, {
|
|
85
|
+
name: 'query-suggestions',
|
|
86
|
+
visibleWhen: 'initial+nonempty'
|
|
87
|
+
}, [phrase(options, {
|
|
88
|
+
name: 'related-questions',
|
|
89
|
+
tag: 'h3'
|
|
90
|
+
}), '<miso-query-suggestions></miso-query-suggestions>']);
|
|
91
|
+
}
|
|
92
|
+
function answerGroup(options) {
|
|
93
|
+
return [answer(options), sources(options), container(options, {
|
|
94
|
+
name: 'bottom-spacing',
|
|
95
|
+
visibleWhen: 'ongoing'
|
|
96
|
+
})];
|
|
97
|
+
}
|
|
98
|
+
function answer(options) {
|
|
99
|
+
return container(options, {
|
|
100
|
+
name: 'answer',
|
|
101
|
+
visibleWhen: 'ready'
|
|
102
|
+
}, [options.parentQuestionId ? '<hr>' : '', phrase(options, {
|
|
103
|
+
name: 'question',
|
|
104
|
+
tag: 'div'
|
|
105
|
+
}), '<miso-question></miso-question>', '<miso-answer></miso-answer>', '<miso-feedback></miso-feedback>']);
|
|
106
|
+
}
|
|
107
|
+
;
|
|
108
|
+
function sources(options) {
|
|
109
|
+
return container(options, {
|
|
110
|
+
name: 'sources',
|
|
111
|
+
visibleWhen: 'nonempty'
|
|
112
|
+
}, ['<hr>', phrase(options, {
|
|
113
|
+
name: 'sources',
|
|
114
|
+
tag: 'h3'
|
|
115
|
+
}), '<miso-sources></miso-sources>']);
|
|
116
|
+
}
|
|
117
|
+
;
|
|
118
|
+
function phrase(options, _ref2) {
|
|
119
|
+
let {
|
|
120
|
+
name,
|
|
121
|
+
tag = 'div'
|
|
122
|
+
} = _ref2;
|
|
123
|
+
const {
|
|
124
|
+
classPrefix
|
|
125
|
+
} = options;
|
|
126
|
+
return `<${tag} class="${classPrefix}__phrase ${classPrefix}__${name}-phrase">${phraseText(options, kebabToLowerCamel(name))}</${tag}>`;
|
|
127
|
+
}
|
|
128
|
+
function phraseText(options, key) {
|
|
129
|
+
const {
|
|
130
|
+
phrases = {}
|
|
131
|
+
} = options;
|
|
132
|
+
const fn = phrases[key] || DEFAULT_PHRASES[key];
|
|
133
|
+
switch (typeof fn) {
|
|
134
|
+
case 'function':
|
|
135
|
+
return fn(options);
|
|
136
|
+
case 'string':
|
|
137
|
+
return fn;
|
|
138
|
+
default:
|
|
139
|
+
return '';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function section(_ref3, _ref4, body) {
|
|
143
|
+
let {
|
|
144
|
+
classPrefix
|
|
145
|
+
} = _ref3;
|
|
146
|
+
let {
|
|
147
|
+
name
|
|
148
|
+
} = _ref4;
|
|
149
|
+
return element('section', {
|
|
150
|
+
classes: [`${classPrefix}__section`, `${classPrefix}__${name}`]
|
|
151
|
+
}, body);
|
|
152
|
+
}
|
|
153
|
+
function container(_ref5, _ref6, body) {
|
|
154
|
+
let {
|
|
155
|
+
classPrefix,
|
|
156
|
+
circledCitationIndex,
|
|
157
|
+
parentQuestionId
|
|
158
|
+
} = _ref5;
|
|
159
|
+
let {
|
|
160
|
+
name,
|
|
161
|
+
visibleWhen,
|
|
162
|
+
logo = false
|
|
163
|
+
} = _ref6;
|
|
164
|
+
const classes = [`${classPrefix}__${name}-container`];
|
|
165
|
+
circledCitationIndex && classes.push('miso-circled-citation-index');
|
|
166
|
+
return element('miso-ask', {
|
|
167
|
+
classes,
|
|
168
|
+
visibleWhen,
|
|
169
|
+
logo,
|
|
170
|
+
parentQuestionId
|
|
171
|
+
}, body);
|
|
172
|
+
}
|
|
173
|
+
function element(tag) {
|
|
174
|
+
let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
175
|
+
let body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
176
|
+
if (typeof attributes === 'string' || Array.isArray(attributes)) {
|
|
177
|
+
body = attributes;
|
|
178
|
+
attributes = {};
|
|
179
|
+
}
|
|
180
|
+
return `<${tag}${attrs(attributes)}>${Array.isArray(body) ? body.join('') : body}</${tag}>`;
|
|
181
|
+
}
|
|
182
|
+
function attrs() {
|
|
183
|
+
let _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
184
|
+
let {
|
|
185
|
+
classes = []
|
|
186
|
+
} = _ref7,
|
|
187
|
+
attributes = _objectWithoutPropertiesLoose(_ref7, _excluded2);
|
|
188
|
+
let str = ``;
|
|
189
|
+
if (classes.length) {
|
|
190
|
+
str += ` class="${classes.join(' ')}"`;
|
|
191
|
+
}
|
|
192
|
+
for (const name in attributes) {
|
|
193
|
+
const value = attributes[name];
|
|
194
|
+
if (value !== undefined) {
|
|
195
|
+
str += ` ${lowerCamelToKebab(name)}="${value}"`;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return str;
|
|
199
|
+
}
|
|
200
|
+
function kebabToLowerCamel(str) {
|
|
201
|
+
return str.replace(/-([a-z])/g, g => g[1].toUpperCase());
|
|
202
|
+
}
|
|
203
|
+
function lowerCamelToKebab(str) {
|
|
204
|
+
return str.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
205
|
+
}
|
|
@@ -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);
|
|
@@ -95,7 +95,6 @@ class SearchBoxLayout extends _template.default {
|
|
|
95
95
|
this._contexts = new WeakMap();
|
|
96
96
|
this._suggestionItems = new WeakMap(); // TODO: put them on elements as layout can be potentially replaced
|
|
97
97
|
}
|
|
98
|
-
|
|
99
98
|
initialize(view) {
|
|
100
99
|
const {
|
|
101
100
|
autocomplete
|
|
@@ -110,6 +109,21 @@ class SearchBoxLayout extends _template.default {
|
|
|
110
109
|
this._unsubscribes.push(hub.on(_index.fields.suggestions(), () => this._handleInput()));
|
|
111
110
|
}
|
|
112
111
|
}
|
|
112
|
+
focus() {
|
|
113
|
+
if (this._element) {
|
|
114
|
+
this._context().focus();
|
|
115
|
+
} else {
|
|
116
|
+
// take a rain check, wait for render
|
|
117
|
+
this._focusRequested = true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
set value(value) {
|
|
121
|
+
if (this._element) {
|
|
122
|
+
this._context().value = value;
|
|
123
|
+
} else {
|
|
124
|
+
this._valueRequested = value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
113
127
|
_preprocess(_ref2) {
|
|
114
128
|
let {
|
|
115
129
|
state
|
|
@@ -135,6 +149,8 @@ class SearchBoxLayout extends _template.default {
|
|
|
135
149
|
}
|
|
136
150
|
this._setupAutocomplete(element);
|
|
137
151
|
this._renderSuggestions(element, data, controls);
|
|
152
|
+
this._fullfillFocusRequest(element);
|
|
153
|
+
this._fullfillValueRequest(element);
|
|
138
154
|
}
|
|
139
155
|
_setupAutocomplete(element) {
|
|
140
156
|
const {
|
|
@@ -184,6 +200,20 @@ class SearchBoxLayout extends _template.default {
|
|
|
184
200
|
this._suggestionItems.set(itemElement, suggestionItems[i++]);
|
|
185
201
|
}
|
|
186
202
|
}
|
|
203
|
+
_fullfillFocusRequest(element) {
|
|
204
|
+
if (!element || !this._focusRequested) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
this._focusRequested = false;
|
|
208
|
+
this._context(element).focus();
|
|
209
|
+
}
|
|
210
|
+
_fullfillValueRequest(element) {
|
|
211
|
+
if (!element || !this._valueRequested) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
this._context(element).value = this._valueRequested;
|
|
215
|
+
this._valueRequested = undefined;
|
|
216
|
+
}
|
|
187
217
|
_context(element) {
|
|
188
218
|
element = element || this._view.element;
|
|
189
219
|
if (!element) {
|
|
@@ -288,6 +318,24 @@ class Context {
|
|
|
288
318
|
});
|
|
289
319
|
}
|
|
290
320
|
}
|
|
321
|
+
focus() {
|
|
322
|
+
if (!this._element) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const {
|
|
326
|
+
inputElement
|
|
327
|
+
} = this;
|
|
328
|
+
inputElement && inputElement.focus();
|
|
329
|
+
}
|
|
330
|
+
set value(value) {
|
|
331
|
+
if (!this._element) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const {
|
|
335
|
+
inputElement
|
|
336
|
+
} = this;
|
|
337
|
+
inputElement && (inputElement.value = value);
|
|
338
|
+
}
|
|
291
339
|
_get(role) {
|
|
292
340
|
return !this._element ? undefined : this._cache[role] || (this._cache[role] = this._element.querySelector(`[data-role="${role}"]`));
|
|
293
341
|
}
|
package/dist/cjs/layout/raf.js
CHANGED
|
@@ -85,7 +85,6 @@ class RafLayout {
|
|
|
85
85
|
if (!this._requested) {
|
|
86
86
|
return; // just in case
|
|
87
87
|
}
|
|
88
|
-
|
|
89
88
|
this._requested = false;
|
|
90
89
|
this._applyRender();
|
|
91
90
|
}
|
|
@@ -94,7 +93,6 @@ class RafLayout {
|
|
|
94
93
|
if (!this._pending) {
|
|
95
94
|
return; // just in case
|
|
96
95
|
}
|
|
97
|
-
|
|
98
96
|
const timestamp = Date.now();
|
|
99
97
|
let [state, {
|
|
100
98
|
notifyUpdate
|
|
@@ -64,7 +64,6 @@ function productInfoBlock(_ref, _ref2) {
|
|
|
64
64
|
content += `<hr><div class="${className}__item-price">${price}</div>`;
|
|
65
65
|
// TODO: enhance this
|
|
66
66
|
}
|
|
67
|
-
|
|
68
67
|
return `<div class="${className}__item-info-container">${content}</div>`;
|
|
69
68
|
}
|
|
70
69
|
function articleInfoBlock(_ref3, _ref4) {
|