@miso.ai/client-sdk-ui 1.10.3-beta.0 → 1.10.4-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/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/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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.wireAnswerBox = wireAnswerBox;
|
|
7
|
+
var _answerBox = _interopRequireDefault(require("./answer-box.js"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
function wireAnswerBox(client, element) {
|
|
10
|
+
if (!client) {
|
|
11
|
+
throw new Error('client is required');
|
|
12
|
+
}
|
|
13
|
+
if (!element) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
new _answerBox.default(client, element);
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
constants: true,
|
|
8
|
+
phrases: true,
|
|
9
|
+
templates: true
|
|
10
|
+
};
|
|
11
|
+
exports.templates = exports.phrases = exports.constants = void 0;
|
|
12
|
+
var _constants = _interopRequireWildcard(require("./constants.js"));
|
|
13
|
+
var _phrases = _interopRequireWildcard(require("./phrases.js"));
|
|
14
|
+
var _templates = _interopRequireWildcard(require("./templates.js"));
|
|
15
|
+
var _controls = require("./controls.js");
|
|
16
|
+
Object.keys(_controls).forEach(function (key) {
|
|
17
|
+
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
19
|
+
if (key in exports && exports[key] === _controls[key]) return;
|
|
20
|
+
Object.defineProperty(exports, key, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () {
|
|
23
|
+
return _controls[key];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
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); }
|
|
28
|
+
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; }
|
|
29
|
+
const constants = exports.constants = Object.freeze(_constants);
|
|
30
|
+
const phrases = exports.phrases = Object.freeze(_phrases);
|
|
31
|
+
const templates = exports.templates = Object.freeze(_templates);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sources = exports.showMore = exports.showLess = exports.question = exports.keywords = exports.hits = 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 = 'Sources';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The phrase to display <miso-keywords>
|
|
19
|
+
*/
|
|
20
|
+
const keywords = exports.keywords = 'You searched for “${value}”';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The phrase to display <miso-hits>
|
|
24
|
+
*/
|
|
25
|
+
const hits = exports.hits = '${value} Results';
|
|
26
|
+
const showMore = exports.showMore = 'Show more';
|
|
27
|
+
const showLess = exports.showLess = 'Show less';
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.helpers = void 0;
|
|
7
|
+
exports.root = root;
|
|
8
|
+
exports.sections = void 0;
|
|
9
|
+
var _commons = require("@miso.ai/commons");
|
|
10
|
+
var CONSTANTS = _interopRequireWildcard(require("./constants.js"));
|
|
11
|
+
var DEFAULT_PHRASES = _interopRequireWildcard(require("./phrases.js"));
|
|
12
|
+
var _templates = require("../common/templates.js");
|
|
13
|
+
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); }
|
|
14
|
+
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; }
|
|
15
|
+
class Sections extends _templates.Sections {
|
|
16
|
+
constructor() {
|
|
17
|
+
super({
|
|
18
|
+
helpers
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
answerBox(options) {
|
|
22
|
+
const {
|
|
23
|
+
element
|
|
24
|
+
} = this._helpers;
|
|
25
|
+
const {
|
|
26
|
+
classPrefix
|
|
27
|
+
} = options;
|
|
28
|
+
return element('div', {
|
|
29
|
+
classes: [`${classPrefix}__answer-box`]
|
|
30
|
+
}, [element('div', {
|
|
31
|
+
classes: [`${classPrefix}__answer-box-inner`]
|
|
32
|
+
}, this.answerGroup(options)), this.answerBoxToggle(options)]);
|
|
33
|
+
}
|
|
34
|
+
answerBoxToggle(options) {
|
|
35
|
+
const {
|
|
36
|
+
element
|
|
37
|
+
} = this._helpers;
|
|
38
|
+
const {
|
|
39
|
+
classPrefix
|
|
40
|
+
} = options;
|
|
41
|
+
return element('div', {
|
|
42
|
+
classes: [`${classPrefix}__answer-box-toggle-container`]
|
|
43
|
+
}, [element('div', {
|
|
44
|
+
classes: [`${classPrefix}__answer-box-toggle`],
|
|
45
|
+
'data-role': 'answer-box-toggle'
|
|
46
|
+
})]);
|
|
47
|
+
}
|
|
48
|
+
searchResultsGroup(options) {
|
|
49
|
+
const {
|
|
50
|
+
container
|
|
51
|
+
} = this._helpers;
|
|
52
|
+
return container(options, {
|
|
53
|
+
name: 'search-results',
|
|
54
|
+
visibleWhen: 'ready'
|
|
55
|
+
}, [this.searchResultsInfoGroup(options), this.searchResultsFilters(options), '<miso-products></miso-products>']);
|
|
56
|
+
}
|
|
57
|
+
searchResultsInfoGroup(options) {
|
|
58
|
+
const {
|
|
59
|
+
element
|
|
60
|
+
} = this._helpers;
|
|
61
|
+
const {
|
|
62
|
+
classPrefix
|
|
63
|
+
} = options;
|
|
64
|
+
return element('div', {
|
|
65
|
+
classes: [`${classPrefix}__search-results-info`]
|
|
66
|
+
}, [this.keywords(options), this.hits(options)]);
|
|
67
|
+
}
|
|
68
|
+
searchResultsFilters(options) {
|
|
69
|
+
const {
|
|
70
|
+
element
|
|
71
|
+
} = this._helpers;
|
|
72
|
+
const {
|
|
73
|
+
classPrefix
|
|
74
|
+
} = options;
|
|
75
|
+
return element('div', {
|
|
76
|
+
classes: [`${classPrefix}__search-results-filters`]
|
|
77
|
+
}, ['<miso-facets></miso-facets>']);
|
|
78
|
+
}
|
|
79
|
+
keywords(options) {
|
|
80
|
+
const {
|
|
81
|
+
phrase
|
|
82
|
+
} = this._helpers;
|
|
83
|
+
return phrase(options, {
|
|
84
|
+
name: 'keywords',
|
|
85
|
+
tag: 'div',
|
|
86
|
+
inline: true
|
|
87
|
+
}).replaceAll('${value}', '<miso-keywords></miso-keywords>');
|
|
88
|
+
}
|
|
89
|
+
hits(options) {
|
|
90
|
+
const {
|
|
91
|
+
phrase
|
|
92
|
+
} = this._helpers;
|
|
93
|
+
return phrase(options, {
|
|
94
|
+
name: 'hits',
|
|
95
|
+
tag: 'div',
|
|
96
|
+
inline: true
|
|
97
|
+
}).replaceAll('${value}', '<miso-hits></miso-hits>');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const helpers = exports.helpers = (0, _commons.externalize)(new _templates.Helpers(Object.assign({}, CONSTANTS, {
|
|
101
|
+
DEFAULT_PHRASES
|
|
102
|
+
})));
|
|
103
|
+
const sections = exports.sections = (0, _commons.externalize)(new Sections({
|
|
104
|
+
helpers
|
|
105
|
+
}));
|
|
106
|
+
function root() {
|
|
107
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
108
|
+
const {
|
|
109
|
+
normalizeOptions,
|
|
110
|
+
section,
|
|
111
|
+
container
|
|
112
|
+
} = helpers;
|
|
113
|
+
options = normalizeOptions(options);
|
|
114
|
+
const {
|
|
115
|
+
answerBox
|
|
116
|
+
} = sections;
|
|
117
|
+
return [section(options, {
|
|
118
|
+
name: 'question'
|
|
119
|
+
}, [container(options, {
|
|
120
|
+
name: 'query'
|
|
121
|
+
}, '<miso-query></miso-query>')]), section(options, {
|
|
122
|
+
name: 'answer'
|
|
123
|
+
}, [answerBox(options)]), section(options, {
|
|
124
|
+
name: 'search-results'
|
|
125
|
+
}, sections.searchResultsGroup(options))].join('');
|
|
126
|
+
}
|
|
127
|
+
;
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.ask = void 0;
|
|
6
|
+
exports.hybridSearch = exports.ask = void 0;
|
|
7
7
|
var _ask = _interopRequireWildcard(require("./ask/index.js"));
|
|
8
|
+
var _hybridSearch = _interopRequireWildcard(require("./hybrid-search/index.js"));
|
|
8
9
|
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
10
|
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; }
|
|
10
|
-
const ask = exports.ask = Object.freeze(_ask);
|
|
11
|
+
const ask = exports.ask = Object.freeze(_ask);
|
|
12
|
+
const hybridSearch = exports.hybridSearch = Object.freeze(_hybridSearch);
|
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "MisoExploreElement", {
|
|
|
15
15
|
return _misoExplore.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "MisoHybridSearchElement", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _misoHybridSearch.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "MisoRecommendationElement", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function () {
|
|
@@ -29,6 +35,7 @@ Object.defineProperty(exports, "MisoSearchElement", {
|
|
|
29
35
|
});
|
|
30
36
|
var _misoAsk = _interopRequireDefault(require("./miso-ask.js"));
|
|
31
37
|
var _misoExplore = _interopRequireDefault(require("./miso-explore.js"));
|
|
38
|
+
var _misoHybridSearch = _interopRequireDefault(require("./miso-hybrid-search.js"));
|
|
32
39
|
var _misoSearch = _interopRequireDefault(require("./miso-search.js"));
|
|
33
40
|
var _misoRecommendation = _interopRequireDefault(require("./miso-recommendation.js"));
|
|
34
41
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _misoContainer = _interopRequireDefault(require("./miso-container.js"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
const TAG_NAME = 'miso-hybrid-search';
|
|
10
|
+
class MisoHybridSearchElement extends _misoContainer.default {
|
|
11
|
+
static get observedAttributes() {
|
|
12
|
+
return _misoContainer.default.observedAttributes;
|
|
13
|
+
}
|
|
14
|
+
static get tagName() {
|
|
15
|
+
return TAG_NAME;
|
|
16
|
+
}
|
|
17
|
+
_getWorkflow(client) {
|
|
18
|
+
return client.ui.hybridSearch;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = MisoHybridSearchElement;
|
|
@@ -21,12 +21,30 @@ Object.defineProperty(exports, "MisoErrorElement", {
|
|
|
21
21
|
return _misoError.default;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "MisoFacetsElement", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _misoFacets.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
24
30
|
Object.defineProperty(exports, "MisoFeedbackElement", {
|
|
25
31
|
enumerable: true,
|
|
26
32
|
get: function () {
|
|
27
33
|
return _misoFeedback.default;
|
|
28
34
|
}
|
|
29
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "MisoHitsElement", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _misoHits.default;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "MisoKeywordsElement", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _misoKeywords.default;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
30
48
|
Object.defineProperty(exports, "MisoProductsElement", {
|
|
31
49
|
enumerable: true,
|
|
32
50
|
get: function () {
|
|
@@ -93,5 +111,8 @@ var _misoSources = _interopRequireDefault(require("./miso-sources.js"));
|
|
|
93
111
|
var _misoRelatedResources = _interopRequireDefault(require("./miso-related-resources.js"));
|
|
94
112
|
var _misoRelatedQuestions = _interopRequireDefault(require("./miso-related-questions.js"));
|
|
95
113
|
var _misoAffiliation = _interopRequireDefault(require("./miso-affiliation.js"));
|
|
114
|
+
var _misoKeywords = _interopRequireDefault(require("./miso-keywords.js"));
|
|
115
|
+
var _misoHits = _interopRequireDefault(require("./miso-hits.js"));
|
|
116
|
+
var _misoFacets = _interopRequireDefault(require("./miso-facets.js"));
|
|
96
117
|
var _misoError = _interopRequireDefault(require("./miso-error.js"));
|
|
97
118
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _misoComponent = _interopRequireDefault(require("./miso-component.js"));
|
|
8
|
+
var _constants = require("../../constants.js");
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
class MisoFacetsElement extends _misoComponent.default {
|
|
11
|
+
constructor() {
|
|
12
|
+
super({
|
|
13
|
+
role: _constants.ROLE.FACETS
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
static get tagName() {
|
|
17
|
+
return 'miso-facets';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = MisoFacetsElement;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _misoComponent = _interopRequireDefault(require("./miso-component.js"));
|
|
8
|
+
var _constants = require("../../constants.js");
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
class MisoHitsElement extends _misoComponent.default {
|
|
11
|
+
constructor() {
|
|
12
|
+
super({
|
|
13
|
+
role: _constants.ROLE.HITS
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
static get tagName() {
|
|
17
|
+
return 'miso-hits';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = MisoHitsElement;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _misoComponent = _interopRequireDefault(require("./miso-component.js"));
|
|
8
|
+
var _constants = require("../../constants.js");
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
class MisoKeywordsElement extends _misoComponent.default {
|
|
11
|
+
constructor() {
|
|
12
|
+
super({
|
|
13
|
+
role: _constants.ROLE.KEYWORDS
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
static get tagName() {
|
|
17
|
+
return 'miso-keywords';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = MisoKeywordsElement;
|
package/dist/cjs/layout/index.js
CHANGED
|
@@ -45,6 +45,12 @@ Object.defineProperty(exports, "ErrorLayout", {
|
|
|
45
45
|
return _error.default;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
+
Object.defineProperty(exports, "FacetsLayout", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _facets.default;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
48
54
|
Object.defineProperty(exports, "FeedbackLayout", {
|
|
49
55
|
enumerable: true,
|
|
50
56
|
get: function () {
|
|
@@ -101,4 +107,5 @@ var _feedback = _interopRequireDefault(require("./radio/feedback.js"));
|
|
|
101
107
|
var _text = _interopRequireDefault(require("./text/text.js"));
|
|
102
108
|
var _index = _interopRequireDefault(require("./text/typewriter/index.js"));
|
|
103
109
|
var _affiliation = _interopRequireDefault(require("./affiliation/affiliation.js"));
|
|
110
|
+
var _facets = _interopRequireDefault(require("./input/facets.js"));
|
|
104
111
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _commons = require("@miso.ai/commons");
|
|
8
|
+
var _constants = require("../../constants.js");
|
|
9
|
+
var _template = _interopRequireDefault(require("../template.js"));
|
|
10
|
+
var _bindings = _interopRequireDefault(require("../../util/bindings.js"));
|
|
11
|
+
const _excluded = ["className", "templates"];
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
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; }
|
|
14
|
+
const TYPE = 'facets';
|
|
15
|
+
const DEFAULT_CLASSNAME = 'miso-facets';
|
|
16
|
+
const DEDAULT_FACET_CLASSNAME = 'miso-facet';
|
|
17
|
+
const CUSTOM_ATTRIBUTES_PREFIX = 'custom_attributes.';
|
|
18
|
+
function root(layout, state) {
|
|
19
|
+
const {
|
|
20
|
+
className,
|
|
21
|
+
role,
|
|
22
|
+
templates
|
|
23
|
+
} = layout;
|
|
24
|
+
const roleAttr = role ? `data-role="${role}"` : '';
|
|
25
|
+
return `<div class="${className}" ${roleAttr}>${templates.facets(layout, state)}</div>`;
|
|
26
|
+
}
|
|
27
|
+
function facets(layout, state) {
|
|
28
|
+
const {
|
|
29
|
+
templates
|
|
30
|
+
} = layout;
|
|
31
|
+
const {
|
|
32
|
+
facet_fields = {}
|
|
33
|
+
} = state.value || {};
|
|
34
|
+
return Object.keys(facet_fields).map(field => templates.facet(layout, {
|
|
35
|
+
field,
|
|
36
|
+
entries: facet_fields[field]
|
|
37
|
+
}, state));
|
|
38
|
+
}
|
|
39
|
+
function facet(layout, facet, state) {
|
|
40
|
+
const {
|
|
41
|
+
facetClassName = DEDAULT_FACET_CLASSNAME,
|
|
42
|
+
templates
|
|
43
|
+
} = layout;
|
|
44
|
+
const {
|
|
45
|
+
field
|
|
46
|
+
} = facet;
|
|
47
|
+
return `<div class="${facetClassName}" data-role="facet" data-field="${(0, _commons.escapeHtml)(field)}">${templates.header(layout, facet, state)}${templates.options(layout, facet, state)}</div>`;
|
|
48
|
+
}
|
|
49
|
+
function header(layout, facet, state) {
|
|
50
|
+
const {
|
|
51
|
+
facetClassName = DEDAULT_FACET_CLASSNAME,
|
|
52
|
+
templates
|
|
53
|
+
} = layout;
|
|
54
|
+
return `<div class="${facetClassName}__header">${templates.title(layout, facet, state)}</div>`;
|
|
55
|
+
}
|
|
56
|
+
function title(layout, _ref) {
|
|
57
|
+
let {
|
|
58
|
+
field
|
|
59
|
+
} = _ref;
|
|
60
|
+
if (field.startsWith(CUSTOM_ATTRIBUTES_PREFIX)) {
|
|
61
|
+
field = field.substring(CUSTOM_ATTRIBUTES_PREFIX.length);
|
|
62
|
+
}
|
|
63
|
+
// TODO: to words
|
|
64
|
+
return (0, _commons.escapeHtml)(field);
|
|
65
|
+
}
|
|
66
|
+
function options(layout, _ref2, state) {
|
|
67
|
+
let {
|
|
68
|
+
field,
|
|
69
|
+
entries
|
|
70
|
+
} = _ref2;
|
|
71
|
+
const {
|
|
72
|
+
facetClassName = DEDAULT_FACET_CLASSNAME,
|
|
73
|
+
templates
|
|
74
|
+
} = layout;
|
|
75
|
+
return `<ul class="${facetClassName}__options" data-role="options">${entries.map(_ref3 => {
|
|
76
|
+
let [value, count] = _ref3;
|
|
77
|
+
return templates.option(layout, {
|
|
78
|
+
field,
|
|
79
|
+
value,
|
|
80
|
+
count
|
|
81
|
+
}, state);
|
|
82
|
+
}).join('')}</ul>`;
|
|
83
|
+
}
|
|
84
|
+
function option(layout, entry, state) {
|
|
85
|
+
const {
|
|
86
|
+
facetClassName = DEDAULT_FACET_CLASSNAME,
|
|
87
|
+
templates
|
|
88
|
+
} = layout;
|
|
89
|
+
return `
|
|
90
|
+
<li class="${facetClassName}__option" data-role="option" tabindex="0">
|
|
91
|
+
<span class="${facetClassName}__value">${templates.value(layout, entry, state)}</span>
|
|
92
|
+
<span class="${facetClassName}__count">${templates.count(layout, entry, state)}</span>
|
|
93
|
+
</li>`;
|
|
94
|
+
}
|
|
95
|
+
function value(layout, _ref4, state) {
|
|
96
|
+
let {
|
|
97
|
+
value
|
|
98
|
+
} = _ref4;
|
|
99
|
+
return (0, _commons.escapeHtml)(value);
|
|
100
|
+
}
|
|
101
|
+
function count(layout, _ref5, state) {
|
|
102
|
+
let {
|
|
103
|
+
count
|
|
104
|
+
} = _ref5;
|
|
105
|
+
return layout.templates.helpers.formatNumber(count);
|
|
106
|
+
}
|
|
107
|
+
const DEFAULT_TEMPLATES = Object.freeze({
|
|
108
|
+
root,
|
|
109
|
+
facets,
|
|
110
|
+
facet,
|
|
111
|
+
header,
|
|
112
|
+
title,
|
|
113
|
+
options,
|
|
114
|
+
option,
|
|
115
|
+
value,
|
|
116
|
+
count
|
|
117
|
+
});
|
|
118
|
+
function getItemKey(field, value) {
|
|
119
|
+
return `${field}:::${value}`;
|
|
120
|
+
}
|
|
121
|
+
function getSelectedValues(facets) {
|
|
122
|
+
const selections = {};
|
|
123
|
+
for (const field in facets) {
|
|
124
|
+
selections[field] = new Set(facets[field]);
|
|
125
|
+
}
|
|
126
|
+
return selections;
|
|
127
|
+
}
|
|
128
|
+
class FacetsLayout extends _template.default {
|
|
129
|
+
static get category() {
|
|
130
|
+
return _constants.LAYOUT_CATEGORY.FILTERS;
|
|
131
|
+
}
|
|
132
|
+
static get type() {
|
|
133
|
+
return TYPE;
|
|
134
|
+
}
|
|
135
|
+
static get defaultTemplates() {
|
|
136
|
+
return DEFAULT_TEMPLATES;
|
|
137
|
+
}
|
|
138
|
+
static get defaultClassName() {
|
|
139
|
+
return DEFAULT_CLASSNAME;
|
|
140
|
+
}
|
|
141
|
+
constructor() {
|
|
142
|
+
let _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
143
|
+
let {
|
|
144
|
+
className = DEFAULT_CLASSNAME,
|
|
145
|
+
templates
|
|
146
|
+
} = _ref6,
|
|
147
|
+
options = _objectWithoutPropertiesLoose(_ref6, _excluded);
|
|
148
|
+
super(Object.assign({
|
|
149
|
+
className,
|
|
150
|
+
templates: Object.assign({}, DEFAULT_TEMPLATES, templates)
|
|
151
|
+
}, options));
|
|
152
|
+
this._bindings = new _bindings.default();
|
|
153
|
+
}
|
|
154
|
+
initialize(view) {
|
|
155
|
+
const {
|
|
156
|
+
proxyElement,
|
|
157
|
+
hub,
|
|
158
|
+
filters
|
|
159
|
+
} = view;
|
|
160
|
+
this._unsubscribes = [...this._unsubscribes, proxyElement.on('click', e => this._handleClick(e)), filters.on('update', e => this._updateSelections(e)), filters.on('reset', () => this._syncSelections())];
|
|
161
|
+
}
|
|
162
|
+
_render(element, data, controls) {
|
|
163
|
+
super._render(element, data, controls);
|
|
164
|
+
this._syncSelections();
|
|
165
|
+
}
|
|
166
|
+
_afterRender(element, state) {
|
|
167
|
+
this._syncBindings(element, state);
|
|
168
|
+
}
|
|
169
|
+
_unrender() {
|
|
170
|
+
this._clearBindings();
|
|
171
|
+
}
|
|
172
|
+
_syncSelections() {
|
|
173
|
+
const selectedValues = getSelectedValues(this._view.filters.states.facets);
|
|
174
|
+
for (const {
|
|
175
|
+
value: {
|
|
176
|
+
field,
|
|
177
|
+
value
|
|
178
|
+
},
|
|
179
|
+
element
|
|
180
|
+
} of this._bindings.entries) {
|
|
181
|
+
this._setSelected(element, selectedValues[field] && selectedValues[field].has(value));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
_updateSelections(_ref7) {
|
|
185
|
+
let {
|
|
186
|
+
updates
|
|
187
|
+
} = _ref7;
|
|
188
|
+
const selectedValues = getSelectedValues(updates.facets);
|
|
189
|
+
for (const {
|
|
190
|
+
value: {
|
|
191
|
+
field,
|
|
192
|
+
value
|
|
193
|
+
},
|
|
194
|
+
element
|
|
195
|
+
} of this._bindings.entries) {
|
|
196
|
+
if (!selectedValues[field]) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
this._setSelected(element, selectedValues[field].has(value));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
_setSelected(element, selected) {
|
|
203
|
+
if (!element) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (selected) {
|
|
207
|
+
element.classList.add('selected');
|
|
208
|
+
} else {
|
|
209
|
+
element.classList.remove('selected');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
_syncBindings(element, state) {
|
|
213
|
+
if (!element || !state.value) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const items = this._getItems(state);
|
|
217
|
+
const keys = [];
|
|
218
|
+
const values = [];
|
|
219
|
+
const elements = [];
|
|
220
|
+
for (const facetElement of this._getFacetElements(element)) {
|
|
221
|
+
const field = facetElement.getAttribute('data-field');
|
|
222
|
+
const _values = items[field];
|
|
223
|
+
if (!_values) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const itemElements = this._getItemElements(facetElement);
|
|
227
|
+
for (let i = 0; i < itemElements.length; i++) {
|
|
228
|
+
const itemElement = itemElements[i];
|
|
229
|
+
const value = _values[i];
|
|
230
|
+
if (!value) {
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
keys.push(getItemKey(field, value));
|
|
234
|
+
values.push({
|
|
235
|
+
field,
|
|
236
|
+
value
|
|
237
|
+
});
|
|
238
|
+
elements.push(itemElement);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
this._bindings.update(keys, values, elements);
|
|
242
|
+
}
|
|
243
|
+
_clearBindings() {
|
|
244
|
+
this._bindings.clear();
|
|
245
|
+
}
|
|
246
|
+
_getItems() {
|
|
247
|
+
let {
|
|
248
|
+
value
|
|
249
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
250
|
+
const {
|
|
251
|
+
facet_fields = {}
|
|
252
|
+
} = value || {};
|
|
253
|
+
const items = {};
|
|
254
|
+
for (const field in facet_fields) {
|
|
255
|
+
// the key needs to be matched against data-field attribute
|
|
256
|
+
items[(0, _commons.escapeHtml)(field)] = facet_fields[field].map(_ref8 => {
|
|
257
|
+
let [value] = _ref8;
|
|
258
|
+
return value;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
return items;
|
|
262
|
+
}
|
|
263
|
+
_getFacetElements(element) {
|
|
264
|
+
return Array.from(element.querySelectorAll(`[data-role="facet"]`));
|
|
265
|
+
}
|
|
266
|
+
_getFacetElement(element, field) {
|
|
267
|
+
return element.querySelector(`[data-role="facet"][data-field="${field}"]`);
|
|
268
|
+
}
|
|
269
|
+
_getItemElements(element) {
|
|
270
|
+
return Array.from(element.querySelectorAll(`[data-role="option"]`));
|
|
271
|
+
}
|
|
272
|
+
_handleClick(event) {
|
|
273
|
+
const element = event.target.closest(`[data-role="option"]`);
|
|
274
|
+
if (!element) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const binding = this._bindings.get(element);
|
|
278
|
+
const option = binding && binding.value;
|
|
279
|
+
if (!option) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const {
|
|
283
|
+
field,
|
|
284
|
+
value
|
|
285
|
+
} = option;
|
|
286
|
+
this._view.filters.facets.toggle(field, value);
|
|
287
|
+
this._view.filters.apply(); // TODO: support autoApply = false
|
|
288
|
+
}
|
|
289
|
+
destroy() {
|
|
290
|
+
this._bindings.clear();
|
|
291
|
+
super.destroy();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
exports.default = FacetsLayout;
|