@miso.ai/client-sdk-ui 1.10.3 → 1.11.0-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/autocomplete.js +4 -1
- package/dist/cjs/actor/data.js +15 -6
- package/dist/cjs/actor/fields.js +10 -10
- package/dist/cjs/actor/filters.js +114 -0
- package/dist/cjs/actor/hub.js +2 -1
- package/dist/cjs/actor/sessions.js +3 -5
- package/dist/cjs/actor/view.js +19 -6
- package/dist/cjs/actor/views.js +32 -19
- package/dist/cjs/constants.js +9 -2
- package/dist/cjs/defaults/ask/constants.js +3 -2
- package/dist/cjs/defaults/ask/templates.js +112 -219
- package/dist/cjs/defaults/common/templates.js +234 -0
- package/dist/cjs/defaults/hybrid-search/answer-box.js +115 -0
- package/dist/cjs/defaults/hybrid-search/constants.js +8 -0
- package/dist/cjs/defaults/hybrid-search/controls.js +17 -0
- package/dist/cjs/defaults/hybrid-search/index.js +31 -0
- package/dist/cjs/defaults/hybrid-search/phrases.js +27 -0
- package/dist/cjs/defaults/hybrid-search/templates.js +127 -0
- package/dist/cjs/defaults/index.js +4 -2
- package/dist/cjs/element/container/index.js +7 -0
- package/dist/cjs/element/container/miso-hybrid-search.js +21 -0
- package/dist/cjs/element/role/index.js +21 -0
- package/dist/cjs/element/role/miso-facets.js +20 -0
- package/dist/cjs/element/role/miso-hits.js +20 -0
- package/dist/cjs/element/role/miso-keywords.js +20 -0
- package/dist/cjs/layout/index.js +7 -0
- package/dist/cjs/layout/input/facets.js +294 -0
- package/dist/cjs/layout/input/option-list.js +4 -4
- package/dist/cjs/layout/input/search-box.js +6 -8
- package/dist/cjs/layout/list/collection.js +1 -2
- package/dist/cjs/layout/radio/radio.js +1 -1
- package/dist/cjs/layout/raf.js +1 -0
- package/dist/cjs/layout/template.js +3 -1
- package/dist/cjs/layout/templates.js +15 -0
- package/dist/cjs/layout/text/text.js +38 -5
- package/dist/cjs/layout/trackable.js +2 -16
- package/dist/cjs/plugin.js +4 -1
- package/dist/cjs/{source/index.js → source.js} +7 -4
- package/dist/cjs/util/bindings.js +3 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/answer-based.js +335 -0
- package/dist/cjs/workflow/ask.js +98 -271
- package/dist/cjs/workflow/base.js +69 -35
- package/dist/cjs/workflow/explore.js +10 -0
- package/dist/cjs/workflow/hybrid-search.js +140 -0
- package/dist/cjs/workflow/index.js +7 -0
- package/dist/cjs/workflow/processors.js +113 -0
- package/dist/cjs/workflow/recommendation.js +12 -3
- package/dist/cjs/workflow/search.js +34 -12
- package/package.json +2 -2
- package/src/actor/autocomplete.js +4 -2
- package/src/actor/data.js +8 -2
- package/src/actor/fields.js +10 -10
- package/src/actor/filters.js +103 -0
- package/src/actor/hub.js +2 -1
- package/src/actor/sessions.js +3 -4
- package/src/actor/view.js +19 -2
- package/src/actor/views.js +30 -16
- package/src/constants.js +10 -0
- package/src/defaults/ask/constants.js +1 -0
- package/src/defaults/ask/templates.js +70 -179
- package/src/defaults/common/templates.js +173 -0
- package/src/defaults/hybrid-search/answer-box.js +118 -0
- package/src/defaults/hybrid-search/constants.js +2 -0
- package/src/defaults/hybrid-search/controls.js +11 -0
- package/src/defaults/hybrid-search/index.js +9 -0
- package/src/defaults/hybrid-search/phrases.js +22 -0
- package/src/defaults/hybrid-search/templates.js +83 -0
- package/src/defaults/index.js +2 -0
- package/src/element/container/index.js +1 -0
- package/src/element/container/miso-hybrid-search.js +19 -0
- package/src/element/role/index.js +3 -0
- package/src/element/role/miso-facets.js +16 -0
- package/src/element/role/miso-hits.js +16 -0
- package/src/element/role/miso-keywords.js +16 -0
- package/src/layout/index.js +1 -0
- package/src/layout/input/facets.js +242 -0
- package/src/layout/input/option-list.js +3 -4
- package/src/layout/input/search-box.js +6 -7
- package/src/layout/list/collection.js +1 -2
- package/src/layout/radio/radio.js +1 -1
- package/src/layout/raf.js +1 -0
- package/src/layout/template.js +2 -1
- package/src/layout/templates.js +15 -0
- package/src/layout/text/text.js +28 -3
- package/src/layout/trackable.js +2 -15
- package/src/plugin.js +6 -2
- package/src/{source/index.js → source.js} +7 -4
- package/src/util/bindings.js +4 -0
- package/src/version.js +1 -1
- package/src/workflow/answer-based.js +280 -0
- package/src/workflow/ask.js +82 -204
- package/src/workflow/base.js +64 -27
- package/src/workflow/explore.js +10 -1
- package/src/workflow/hybrid-search.js +125 -0
- package/src/workflow/index.js +1 -0
- package/src/workflow/processors.js +95 -0
- package/src/workflow/recommendation.js +9 -2
- package/src/workflow/search.js +35 -7
- package/dist/cjs/source/api.js +0 -23
- package/src/source/api.js +0 -12
|
@@ -8,18 +8,112 @@ exports.helpers = void 0;
|
|
|
8
8
|
exports.root = root;
|
|
9
9
|
exports.sections = void 0;
|
|
10
10
|
var _commons = require("@miso.ai/commons");
|
|
11
|
-
var
|
|
11
|
+
var CONSTANTS = _interopRequireWildcard(require("./constants.js"));
|
|
12
12
|
var DEFAULT_PHRASES = _interopRequireWildcard(require("./phrases.js"));
|
|
13
|
-
|
|
14
|
-
_excluded2 = ["classes"];
|
|
13
|
+
var _templates = require("../common/templates.js");
|
|
15
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); }
|
|
16
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; }
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
class Sections extends _templates.Sections {
|
|
17
|
+
constructor() {
|
|
18
|
+
super({
|
|
19
|
+
helpers
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
answerGroup(options) {
|
|
23
|
+
const {
|
|
24
|
+
container
|
|
25
|
+
} = this._helpers;
|
|
26
|
+
return [...super.answerGroup(options), container(options, {
|
|
27
|
+
name: 'bottom-spacing',
|
|
28
|
+
visibleWhen: 'ongoing'
|
|
29
|
+
})];
|
|
30
|
+
}
|
|
31
|
+
answer(options) {
|
|
32
|
+
const {
|
|
33
|
+
container
|
|
34
|
+
} = this._helpers;
|
|
35
|
+
return container(options, {
|
|
36
|
+
name: 'answer',
|
|
37
|
+
visibleWhen: 'ready'
|
|
38
|
+
}, [options.parentQuestionId ? '<hr>' : '', ...this.question(options), '<miso-answer></miso-answer>', '<miso-feedback></miso-feedback>']);
|
|
39
|
+
}
|
|
40
|
+
sources(options) {
|
|
41
|
+
const {
|
|
42
|
+
container,
|
|
43
|
+
phrase
|
|
44
|
+
} = this._helpers;
|
|
45
|
+
return container(options, {
|
|
46
|
+
name: 'sources',
|
|
47
|
+
visibleWhen: 'nonempty'
|
|
48
|
+
}, ['<hr>', phrase(options, {
|
|
49
|
+
name: 'sources',
|
|
50
|
+
tag: 'h3'
|
|
51
|
+
}), '<miso-sources></miso-sources>']);
|
|
52
|
+
}
|
|
53
|
+
followUps(options) {
|
|
54
|
+
const {
|
|
55
|
+
classPrefix,
|
|
56
|
+
features = {}
|
|
57
|
+
} = options;
|
|
58
|
+
return features.followUpQuestions === false ? '' : `<div id="${classPrefix}__follow-ups" class="${classPrefix}__follow-ups"></div>`;
|
|
59
|
+
}
|
|
60
|
+
relatedResourcesSection(options) {
|
|
61
|
+
const {
|
|
62
|
+
container,
|
|
63
|
+
phrase,
|
|
64
|
+
section
|
|
65
|
+
} = this._helpers;
|
|
66
|
+
const {
|
|
67
|
+
features = {},
|
|
68
|
+
logo = true
|
|
69
|
+
} = options;
|
|
70
|
+
const body = features.relatedResources === false ? '' : container(options, {
|
|
71
|
+
name: 'related-resources',
|
|
72
|
+
visibleWhen: 'nonempty',
|
|
73
|
+
logo
|
|
74
|
+
}, [phrase(options, {
|
|
75
|
+
name: 'related-resources',
|
|
76
|
+
tag: 'h2'
|
|
77
|
+
}), '<miso-related-resources></miso-related-resources>']);
|
|
78
|
+
return section(options, {
|
|
79
|
+
name: 'related-resources'
|
|
80
|
+
}, body);
|
|
81
|
+
}
|
|
82
|
+
querySuggestions(options) {
|
|
83
|
+
const {
|
|
84
|
+
container,
|
|
85
|
+
phrase
|
|
86
|
+
} = this._helpers;
|
|
87
|
+
const {
|
|
88
|
+
features = {}
|
|
89
|
+
} = options;
|
|
90
|
+
return features.querySuggestions === false ? '' : container(options, {
|
|
91
|
+
name: 'query-suggestions',
|
|
92
|
+
visibleWhen: 'initial+nonempty'
|
|
93
|
+
}, [phrase(options, {
|
|
94
|
+
name: 'query-suggestions',
|
|
95
|
+
tag: 'h3'
|
|
96
|
+
}), '<miso-query-suggestions></miso-query-suggestions>']);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const helpers = exports.helpers = (0, _commons.externalize)(new _templates.Helpers(Object.assign({}, CONSTANTS, {
|
|
100
|
+
DEFAULT_PHRASES
|
|
101
|
+
})));
|
|
102
|
+
const sections = exports.sections = (0, _commons.externalize)(new Sections({
|
|
103
|
+
helpers
|
|
104
|
+
}));
|
|
21
105
|
function root() {
|
|
22
106
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
107
|
+
const {
|
|
108
|
+
normalizeOptions,
|
|
109
|
+
section,
|
|
110
|
+
container
|
|
111
|
+
} = helpers;
|
|
112
|
+
const {
|
|
113
|
+
followUps,
|
|
114
|
+
relatedResourcesSection,
|
|
115
|
+
answerGroup
|
|
116
|
+
} = sections;
|
|
23
117
|
options = normalizeOptions(options);
|
|
24
118
|
return [section(options, {
|
|
25
119
|
name: 'question'
|
|
@@ -27,11 +121,20 @@ function root() {
|
|
|
27
121
|
name: 'query'
|
|
28
122
|
}, '<miso-query></miso-query>')]), section(options, {
|
|
29
123
|
name: 'answer'
|
|
30
|
-
}, answerGroup(options)), followUps(options),
|
|
124
|
+
}, answerGroup(options)), followUps(options), relatedResourcesSection(options)].join('');
|
|
31
125
|
}
|
|
32
126
|
;
|
|
33
127
|
function followUp() {
|
|
34
128
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
129
|
+
const {
|
|
130
|
+
normalizeOptions,
|
|
131
|
+
section,
|
|
132
|
+
container
|
|
133
|
+
} = helpers;
|
|
134
|
+
const {
|
|
135
|
+
querySuggestions,
|
|
136
|
+
answerGroup
|
|
137
|
+
} = sections;
|
|
35
138
|
options = normalizeOptions(options);
|
|
36
139
|
return section(options, {
|
|
37
140
|
name: 'follow-up'
|
|
@@ -40,214 +143,4 @@ function followUp() {
|
|
|
40
143
|
visibleWhen: 'initial loading'
|
|
41
144
|
}, '<miso-query></miso-query>'), ...answerGroup(options)]);
|
|
42
145
|
}
|
|
43
|
-
;
|
|
44
|
-
const sections = exports.sections = Object.freeze({
|
|
45
|
-
followUps,
|
|
46
|
-
relatedResources,
|
|
47
|
-
querySuggestions,
|
|
48
|
-
answerGroup,
|
|
49
|
-
answer,
|
|
50
|
-
sources
|
|
51
|
-
});
|
|
52
|
-
const helpers = exports.helpers = Object.freeze({
|
|
53
|
-
normalizeOptions,
|
|
54
|
-
normalizePhraseOptions,
|
|
55
|
-
normalizePhraseOptionKey,
|
|
56
|
-
phrase,
|
|
57
|
-
phraseText,
|
|
58
|
-
section,
|
|
59
|
-
container,
|
|
60
|
-
element,
|
|
61
|
-
attrs
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// options //
|
|
65
|
-
function normalizeOptions() {
|
|
66
|
-
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
67
|
-
let {
|
|
68
|
-
classPrefix = _constants.CLASS_PREFIX,
|
|
69
|
-
circledCitationIndex = true,
|
|
70
|
-
phrases
|
|
71
|
-
} = _ref,
|
|
72
|
-
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
73
|
-
phrases = normalizePhraseOptions(phrases);
|
|
74
|
-
return Object.assign({
|
|
75
|
-
classPrefix,
|
|
76
|
-
circledCitationIndex,
|
|
77
|
-
phrases
|
|
78
|
-
}, options);
|
|
79
|
-
}
|
|
80
|
-
function normalizePhraseOptions() {
|
|
81
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
82
|
-
if (!options) {
|
|
83
|
-
return {};
|
|
84
|
-
}
|
|
85
|
-
const normalized = {};
|
|
86
|
-
for (const key in options) {
|
|
87
|
-
normalized[normalizePhraseOptionKey(key)] = options[key];
|
|
88
|
-
}
|
|
89
|
-
return normalized;
|
|
90
|
-
}
|
|
91
|
-
function normalizePhraseOptionKey(key) {
|
|
92
|
-
key = (0, _commons.kebabOrSnakeToLowerCamel)(key);
|
|
93
|
-
if (key === 'relatedQuestions') {
|
|
94
|
-
return 'querySuggestions'; // legacy key
|
|
95
|
-
}
|
|
96
|
-
return key;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// sections & containers //
|
|
100
|
-
function followUps(options) {
|
|
101
|
-
const {
|
|
102
|
-
classPrefix,
|
|
103
|
-
features = {}
|
|
104
|
-
} = options;
|
|
105
|
-
return features.followUpQuestions === false ? '' : `<div id="${classPrefix}__follow-ups" class="${classPrefix}__follow-ups"></div>`;
|
|
106
|
-
}
|
|
107
|
-
function relatedResources(options) {
|
|
108
|
-
const {
|
|
109
|
-
features = {},
|
|
110
|
-
logo = true
|
|
111
|
-
} = options;
|
|
112
|
-
const body = features.relatedResources === false ? '' : container(options, {
|
|
113
|
-
name: 'related-resources',
|
|
114
|
-
visibleWhen: 'nonempty',
|
|
115
|
-
logo
|
|
116
|
-
}, [phrase(options, {
|
|
117
|
-
name: 'related-resources',
|
|
118
|
-
tag: 'h2'
|
|
119
|
-
}), '<miso-related-resources></miso-related-resources>']);
|
|
120
|
-
return section(options, {
|
|
121
|
-
name: 'related-resources'
|
|
122
|
-
}, body);
|
|
123
|
-
}
|
|
124
|
-
function querySuggestions(options) {
|
|
125
|
-
const {
|
|
126
|
-
features = {}
|
|
127
|
-
} = options;
|
|
128
|
-
return features.querySuggestions === false ? '' : container(options, {
|
|
129
|
-
name: 'query-suggestions',
|
|
130
|
-
visibleWhen: 'initial+nonempty'
|
|
131
|
-
}, [phrase(options, {
|
|
132
|
-
name: 'query-suggestions',
|
|
133
|
-
tag: 'h3'
|
|
134
|
-
}), '<miso-query-suggestions></miso-query-suggestions>']);
|
|
135
|
-
}
|
|
136
|
-
function answerGroup(options) {
|
|
137
|
-
return [answer(options), affiliation(options), sources(options), container(options, {
|
|
138
|
-
name: 'bottom-spacing',
|
|
139
|
-
visibleWhen: 'ongoing'
|
|
140
|
-
})];
|
|
141
|
-
}
|
|
142
|
-
function answer(options) {
|
|
143
|
-
return container(options, {
|
|
144
|
-
name: 'answer',
|
|
145
|
-
visibleWhen: 'ready'
|
|
146
|
-
}, [options.parentQuestionId ? '<hr>' : '', phrase(options, {
|
|
147
|
-
name: 'question',
|
|
148
|
-
tag: 'div'
|
|
149
|
-
}), '<miso-question></miso-question>', '<miso-answer></miso-answer>', '<miso-feedback></miso-feedback>']);
|
|
150
|
-
}
|
|
151
|
-
function sources(options) {
|
|
152
|
-
return container(options, {
|
|
153
|
-
name: 'sources',
|
|
154
|
-
visibleWhen: 'nonempty'
|
|
155
|
-
}, ['<hr>', phrase(options, {
|
|
156
|
-
name: 'sources',
|
|
157
|
-
tag: 'h3'
|
|
158
|
-
}), '<miso-sources></miso-sources>']);
|
|
159
|
-
}
|
|
160
|
-
function affiliation(options) {
|
|
161
|
-
const {
|
|
162
|
-
affiliation = true
|
|
163
|
-
} = options || {};
|
|
164
|
-
if (!affiliation) {
|
|
165
|
-
return '';
|
|
166
|
-
}
|
|
167
|
-
return container(options, {
|
|
168
|
-
name: 'affiliation',
|
|
169
|
-
visibleWhen: 'nonempty'
|
|
170
|
-
}, ['<miso-affiliation></miso-affiliation>']);
|
|
171
|
-
}
|
|
172
|
-
function phrase(options, _ref2) {
|
|
173
|
-
let {
|
|
174
|
-
name,
|
|
175
|
-
tag = 'div'
|
|
176
|
-
} = _ref2;
|
|
177
|
-
const {
|
|
178
|
-
classPrefix
|
|
179
|
-
} = options;
|
|
180
|
-
return `<${tag} class="${classPrefix}__phrase ${classPrefix}__${name}-phrase">${phraseText(options, (0, _commons.kebabToLowerCamel)(name))}</${tag}>`;
|
|
181
|
-
}
|
|
182
|
-
function phraseText(options, key) {
|
|
183
|
-
const {
|
|
184
|
-
phrases = {}
|
|
185
|
-
} = options;
|
|
186
|
-
const fn = phrases[key] || DEFAULT_PHRASES[key];
|
|
187
|
-
switch (typeof fn) {
|
|
188
|
-
case 'function':
|
|
189
|
-
return fn(options);
|
|
190
|
-
case 'string':
|
|
191
|
-
return fn;
|
|
192
|
-
default:
|
|
193
|
-
return '';
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function section(_ref3, _ref4, body) {
|
|
197
|
-
let {
|
|
198
|
-
classPrefix
|
|
199
|
-
} = _ref3;
|
|
200
|
-
let {
|
|
201
|
-
name
|
|
202
|
-
} = _ref4;
|
|
203
|
-
return element('section', {
|
|
204
|
-
classes: [`${classPrefix}__section`, `${classPrefix}__${name}`]
|
|
205
|
-
}, body);
|
|
206
|
-
}
|
|
207
|
-
function container(_ref5, _ref6, body) {
|
|
208
|
-
let {
|
|
209
|
-
classPrefix,
|
|
210
|
-
circledCitationIndex,
|
|
211
|
-
parentQuestionId
|
|
212
|
-
} = _ref5;
|
|
213
|
-
let {
|
|
214
|
-
name,
|
|
215
|
-
visibleWhen,
|
|
216
|
-
logo = false
|
|
217
|
-
} = _ref6;
|
|
218
|
-
const classes = [`${classPrefix}__${name}-container`];
|
|
219
|
-
circledCitationIndex && classes.push('miso-circled-citation-index');
|
|
220
|
-
return element('miso-ask', {
|
|
221
|
-
classes,
|
|
222
|
-
visibleWhen,
|
|
223
|
-
logo,
|
|
224
|
-
parentQuestionId
|
|
225
|
-
}, body);
|
|
226
|
-
}
|
|
227
|
-
function element(tag) {
|
|
228
|
-
let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
229
|
-
let body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
230
|
-
if (typeof attributes === 'string' || Array.isArray(attributes)) {
|
|
231
|
-
body = attributes;
|
|
232
|
-
attributes = {};
|
|
233
|
-
}
|
|
234
|
-
return `<${tag}${attrs(attributes)}>${Array.isArray(body) ? body.join('') : body}</${tag}>`;
|
|
235
|
-
}
|
|
236
|
-
function attrs() {
|
|
237
|
-
let _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
238
|
-
let {
|
|
239
|
-
classes = []
|
|
240
|
-
} = _ref7,
|
|
241
|
-
attributes = _objectWithoutPropertiesLoose(_ref7, _excluded2);
|
|
242
|
-
let str = ``;
|
|
243
|
-
if (classes.length) {
|
|
244
|
-
str += ` class="${classes.join(' ')}"`;
|
|
245
|
-
}
|
|
246
|
-
for (const name in attributes) {
|
|
247
|
-
const value = attributes[name];
|
|
248
|
-
if (value !== undefined) {
|
|
249
|
-
str += ` ${(0, _commons.lowerCamelToKebab)(name)}="${value}"`;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return str;
|
|
253
|
-
}
|
|
146
|
+
;
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Sections = exports.Helpers = void 0;
|
|
7
|
+
exports.externalize = externalize;
|
|
8
|
+
var _commons = require("@miso.ai/commons");
|
|
9
|
+
const _excluded = ["classPrefix", "circledCitationIndex", "phrases"],
|
|
10
|
+
_excluded2 = ["classes"];
|
|
11
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
12
|
+
// TODO: rename classPrefix -> rootClass?
|
|
13
|
+
// TODO: placeholder
|
|
14
|
+
|
|
15
|
+
class Sections {
|
|
16
|
+
constructor(_ref) {
|
|
17
|
+
let {
|
|
18
|
+
helpers
|
|
19
|
+
} = _ref;
|
|
20
|
+
this._helpers = helpers;
|
|
21
|
+
}
|
|
22
|
+
errorSection(options) {
|
|
23
|
+
const {
|
|
24
|
+
section,
|
|
25
|
+
container
|
|
26
|
+
} = this._helpers;
|
|
27
|
+
return section(options, {
|
|
28
|
+
name: 'error'
|
|
29
|
+
}, [container(options, {
|
|
30
|
+
name: 'error',
|
|
31
|
+
visibleWhen: 'erroneous'
|
|
32
|
+
}, '<miso-error></miso-error>')]);
|
|
33
|
+
}
|
|
34
|
+
answerGroup(options) {
|
|
35
|
+
return [this.answer(options), this.affiliation(options), this.sources(options)];
|
|
36
|
+
}
|
|
37
|
+
answer(options) {
|
|
38
|
+
const {
|
|
39
|
+
container
|
|
40
|
+
} = this._helpers;
|
|
41
|
+
return container(options, {
|
|
42
|
+
name: 'answer',
|
|
43
|
+
visibleWhen: 'ready'
|
|
44
|
+
}, [...this.question(options), '<miso-answer></miso-answer>', '<miso-feedback></miso-feedback>']);
|
|
45
|
+
}
|
|
46
|
+
question(options) {
|
|
47
|
+
const {
|
|
48
|
+
phrase
|
|
49
|
+
} = this._helpers;
|
|
50
|
+
return [phrase(options, {
|
|
51
|
+
name: 'question',
|
|
52
|
+
tag: 'div'
|
|
53
|
+
}), '<miso-question></miso-question>'];
|
|
54
|
+
}
|
|
55
|
+
sources(options) {
|
|
56
|
+
const {
|
|
57
|
+
container,
|
|
58
|
+
phrase
|
|
59
|
+
} = this._helpers;
|
|
60
|
+
return container(options, {
|
|
61
|
+
name: 'sources',
|
|
62
|
+
visibleWhen: 'nonempty'
|
|
63
|
+
}, [phrase(options, {
|
|
64
|
+
name: 'sources',
|
|
65
|
+
tag: 'h3'
|
|
66
|
+
}), '<miso-sources></miso-sources>']);
|
|
67
|
+
}
|
|
68
|
+
affiliation(options) {
|
|
69
|
+
const {
|
|
70
|
+
container
|
|
71
|
+
} = this._helpers;
|
|
72
|
+
const {
|
|
73
|
+
affiliation = true
|
|
74
|
+
} = options || {};
|
|
75
|
+
if (!affiliation) {
|
|
76
|
+
return '';
|
|
77
|
+
}
|
|
78
|
+
return container(options, {
|
|
79
|
+
name: 'affiliation',
|
|
80
|
+
visibleWhen: 'nonempty'
|
|
81
|
+
}, ['<miso-affiliation></miso-affiliation>']);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.Sections = Sections;
|
|
85
|
+
class Helpers {
|
|
86
|
+
constructor(context) {
|
|
87
|
+
this._context = context;
|
|
88
|
+
(0, _commons.defineValues)(this, {
|
|
89
|
+
lowerCamelToKebab: _commons.lowerCamelToKebab,
|
|
90
|
+
kebabToLowerCamel: _commons.kebabToLowerCamel,
|
|
91
|
+
kebabOrSnakeToLowerCamel: _commons.kebabOrSnakeToLowerCamel
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// options //
|
|
96
|
+
normalizeOptions() {
|
|
97
|
+
let _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
98
|
+
let {
|
|
99
|
+
classPrefix,
|
|
100
|
+
circledCitationIndex = true,
|
|
101
|
+
phrases
|
|
102
|
+
} = _ref2,
|
|
103
|
+
options = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
104
|
+
classPrefix = classPrefix || this._context.CLASS_PREFIX;
|
|
105
|
+
phrases = this.normalizePhraseOptions(phrases);
|
|
106
|
+
return Object.assign({
|
|
107
|
+
classPrefix,
|
|
108
|
+
circledCitationIndex,
|
|
109
|
+
phrases
|
|
110
|
+
}, options);
|
|
111
|
+
}
|
|
112
|
+
normalizePhraseOptions() {
|
|
113
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
114
|
+
if (!options) {
|
|
115
|
+
return {};
|
|
116
|
+
}
|
|
117
|
+
const normalized = {};
|
|
118
|
+
for (const key in options) {
|
|
119
|
+
normalized[this.normalizePhraseOptionKey(key)] = options[key];
|
|
120
|
+
}
|
|
121
|
+
return normalized;
|
|
122
|
+
}
|
|
123
|
+
normalizePhraseOptionKey(key) {
|
|
124
|
+
key = (0, _commons.kebabOrSnakeToLowerCamel)(key);
|
|
125
|
+
if (key === 'relatedQuestions') {
|
|
126
|
+
return 'querySuggestions'; // legacy key
|
|
127
|
+
}
|
|
128
|
+
return key;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// html //
|
|
132
|
+
phrase(options, _ref3) {
|
|
133
|
+
let {
|
|
134
|
+
name,
|
|
135
|
+
tag = 'div',
|
|
136
|
+
inline = false
|
|
137
|
+
} = _ref3;
|
|
138
|
+
const {
|
|
139
|
+
classPrefix
|
|
140
|
+
} = options;
|
|
141
|
+
const mainClass = inline ? `${classPrefix}__phrase-inline` : `${classPrefix}__phrase`;
|
|
142
|
+
return `<${tag} class="${mainClass} ${classPrefix}__${name}-phrase">${this.phraseText(options, (0, _commons.kebabToLowerCamel)(name))}</${tag}>`;
|
|
143
|
+
}
|
|
144
|
+
phraseText(options, key) {
|
|
145
|
+
const {
|
|
146
|
+
phrases = {}
|
|
147
|
+
} = options;
|
|
148
|
+
const fn = phrases[key] || this._context.DEFAULT_PHRASES[key];
|
|
149
|
+
switch (typeof fn) {
|
|
150
|
+
case 'function':
|
|
151
|
+
return fn(options);
|
|
152
|
+
case 'string':
|
|
153
|
+
return fn;
|
|
154
|
+
default:
|
|
155
|
+
return '';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
section(_ref4, _ref5, body) {
|
|
159
|
+
let {
|
|
160
|
+
classPrefix
|
|
161
|
+
} = _ref4;
|
|
162
|
+
let {
|
|
163
|
+
name
|
|
164
|
+
} = _ref5;
|
|
165
|
+
return this.element('section', {
|
|
166
|
+
classes: [`${classPrefix}__section`, `${classPrefix}__${name}`]
|
|
167
|
+
}, body);
|
|
168
|
+
}
|
|
169
|
+
container(_ref6, _ref7, body) {
|
|
170
|
+
let {
|
|
171
|
+
classPrefix,
|
|
172
|
+
circledCitationIndex,
|
|
173
|
+
parentQuestionId
|
|
174
|
+
} = _ref6;
|
|
175
|
+
let {
|
|
176
|
+
name,
|
|
177
|
+
visibleWhen,
|
|
178
|
+
logo = false
|
|
179
|
+
} = _ref7;
|
|
180
|
+
const classes = [`${classPrefix}__${name}-container`];
|
|
181
|
+
circledCitationIndex && classes.push('miso-circled-citation-index');
|
|
182
|
+
return this.element(this._context.CONAINER_TAG, {
|
|
183
|
+
classes,
|
|
184
|
+
visibleWhen,
|
|
185
|
+
logo,
|
|
186
|
+
parentQuestionId
|
|
187
|
+
}, body);
|
|
188
|
+
}
|
|
189
|
+
element(tag) {
|
|
190
|
+
let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
191
|
+
let body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
192
|
+
return `<${tag}${this.attrs(attributes)}>${Array.isArray(body) ? body.join('') : body}</${tag}>`;
|
|
193
|
+
}
|
|
194
|
+
attrs() {
|
|
195
|
+
let _ref8 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
196
|
+
let {
|
|
197
|
+
classes = []
|
|
198
|
+
} = _ref8,
|
|
199
|
+
attributes = _objectWithoutPropertiesLoose(_ref8, _excluded2);
|
|
200
|
+
let str = ``;
|
|
201
|
+
if (classes.length) {
|
|
202
|
+
str += ` class="${classes.join(' ')}"`;
|
|
203
|
+
}
|
|
204
|
+
for (const name in attributes) {
|
|
205
|
+
const value = attributes[name];
|
|
206
|
+
if (value !== undefined) {
|
|
207
|
+
str += ` ${(0, _commons.lowerCamelToKebab)(name)}="${value}"`;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return str;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.Helpers = Helpers;
|
|
214
|
+
function externalize(object) {
|
|
215
|
+
const externalized = {};
|
|
216
|
+
const props = new Set();
|
|
217
|
+
for (let o = object; o !== Object.prototype; o = Object.getPrototypeOf(o)) {
|
|
218
|
+
const descriptors = Object.getOwnPropertyDescriptors(o);
|
|
219
|
+
for (const key in descriptors) {
|
|
220
|
+
if (key === 'constructor' || key.startsWith('_') || props.has(key)) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
props.add(key);
|
|
224
|
+
// TODO: getter, setter
|
|
225
|
+
const {
|
|
226
|
+
value
|
|
227
|
+
} = descriptors[key];
|
|
228
|
+
if (value) {
|
|
229
|
+
externalized[key] = typeof value === 'function' ? value.bind(object) : value;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return Object.freeze(externalized);
|
|
234
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _constants = require("./constants.js");
|
|
8
|
+
var _constants2 = require("../../constants.js");
|
|
9
|
+
var _phrases = require("./phrases.js");
|
|
10
|
+
const CLASS_OPEN = 'answer-box-open';
|
|
11
|
+
const CLASS_SHOWN = 'answer-box-shown';
|
|
12
|
+
const TOGGLE_BUTTON_SELECTOR = '[data-role="answer-box-toggle"]';
|
|
13
|
+
class AnswerBox {
|
|
14
|
+
constructor(client, element) {
|
|
15
|
+
let {
|
|
16
|
+
classPrefix = _constants.CLASS_PREFIX,
|
|
17
|
+
phrases = {}
|
|
18
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
19
|
+
this._client = client;
|
|
20
|
+
this._workflow = client.ui.hybridSearch;
|
|
21
|
+
this._element = element;
|
|
22
|
+
this._classPrefix = classPrefix;
|
|
23
|
+
this._phrases = phrases;
|
|
24
|
+
this._init();
|
|
25
|
+
}
|
|
26
|
+
_init() {
|
|
27
|
+
const element = this._element;
|
|
28
|
+
const workflow = this._workflow;
|
|
29
|
+
|
|
30
|
+
// expose widget API
|
|
31
|
+
workflow.answerBox = this;
|
|
32
|
+
workflow._unsubscribes.push(() => this.destroy()); // TODO: review
|
|
33
|
+
|
|
34
|
+
// handle toggle button clicks
|
|
35
|
+
const callback = event => this._handleClick(event);
|
|
36
|
+
element.addEventListener('click', callback);
|
|
37
|
+
|
|
38
|
+
// sync state
|
|
39
|
+
this._syncWofkflowStatus();
|
|
40
|
+
this._syncButtonText();
|
|
41
|
+
this._unsubscribes = [() => element.removeEventListener('click', callback), workflow.on('loading', () => this.hide()), workflow.on('error', () => this.show()), workflow.on('ready', () => this.show())];
|
|
42
|
+
}
|
|
43
|
+
_handleClick(_ref) {
|
|
44
|
+
let {
|
|
45
|
+
target,
|
|
46
|
+
button
|
|
47
|
+
} = _ref;
|
|
48
|
+
// only left click
|
|
49
|
+
if (button !== 0) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (target.closest(TOGGLE_BUTTON_SELECTOR)) {
|
|
53
|
+
this.toggleOpen();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
_syncWofkflowStatus() {
|
|
57
|
+
const {
|
|
58
|
+
status
|
|
59
|
+
} = this._workflow;
|
|
60
|
+
switch (status) {
|
|
61
|
+
case _constants2.STATUS.ERRONEOUS:
|
|
62
|
+
case _constants2.STATUS.READY:
|
|
63
|
+
this.show();
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
this.hide();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
_updateBoxStatus(method, className) {
|
|
70
|
+
this._element.classList[method](`${this._classPrefix}__${className}`);
|
|
71
|
+
}
|
|
72
|
+
_syncButtonText() {
|
|
73
|
+
const phrase = this.isOpen ? this._phrases.showLess || _phrases.showLess : this._phrases.showMore || _phrases.showMore;
|
|
74
|
+
for (const button of this._element.querySelectorAll(TOGGLE_BUTTON_SELECTOR)) {
|
|
75
|
+
button.textContent = phrase;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
destroy() {
|
|
79
|
+
for (const unsubscribe of this._unsubscribes) {
|
|
80
|
+
unsubscribe();
|
|
81
|
+
}
|
|
82
|
+
const workflow = this._workflow;
|
|
83
|
+
if (workflow && workflow.answerBox === this) {
|
|
84
|
+
delete workflow.answerBox;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.default = AnswerBox;
|
|
89
|
+
const GETTERS = {
|
|
90
|
+
isOpen: CLASS_OPEN,
|
|
91
|
+
shown: CLASS_SHOWN
|
|
92
|
+
};
|
|
93
|
+
const METHODS = {
|
|
94
|
+
toggleOpen: ['toggle', CLASS_OPEN],
|
|
95
|
+
open: ['open', CLASS_OPEN],
|
|
96
|
+
close: ['remove', CLASS_OPEN],
|
|
97
|
+
toggleHidden: ['toggle', CLASS_SHOWN],
|
|
98
|
+
show: ['add', CLASS_SHOWN],
|
|
99
|
+
hide: ['remove', CLASS_SHOWN]
|
|
100
|
+
};
|
|
101
|
+
for (const [prop, className] of Object.entries(GETTERS)) {
|
|
102
|
+
Object.defineProperty(AnswerBox.prototype, prop, {
|
|
103
|
+
get() {
|
|
104
|
+
return this._element.classList.contains(`${this._classPrefix}__${className}`);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
for (const [method, [action, className]] of Object.entries(METHODS)) {
|
|
109
|
+
AnswerBox.prototype[method] = function () {
|
|
110
|
+
this._updateBoxStatus(action, className);
|
|
111
|
+
if (className === CLASS_OPEN) {
|
|
112
|
+
this._syncButtonText();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CONAINER_TAG = exports.CLASS_PREFIX = void 0;
|
|
7
|
+
const CLASS_PREFIX = exports.CLASS_PREFIX = 'miso-hybrid-search-combo';
|
|
8
|
+
const CONAINER_TAG = exports.CONAINER_TAG = 'miso-hybrid-search';
|