@miso.ai/client-sdk-ui 1.10.0-beta.0 → 1.10.0-beta.10
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 +157 -0
- package/dist/cjs/actor/data.js +4 -12
- package/dist/cjs/actor/fields.js +8 -0
- package/dist/cjs/actor/index.js +7 -0
- package/dist/cjs/actor/tracker.js +46 -70
- package/dist/cjs/actor/trackers.js +5 -1
- package/dist/cjs/actor/utils.js +16 -2
- package/dist/cjs/actor/view.js +14 -3
- package/dist/cjs/actor/views.js +9 -1
- package/dist/cjs/affiliation/index.js +126 -0
- package/dist/cjs/combo/ask/options.js +1 -1
- package/dist/cjs/combo/base.js +1 -1
- package/dist/cjs/constants.js +6 -3
- package/dist/cjs/defaults/ask/controls.js +1 -1
- package/dist/cjs/defaults/ask/phrases.js +1 -1
- package/dist/cjs/defaults/ask/templates.js +35 -4
- package/dist/cjs/element/role/index.js +7 -0
- package/dist/cjs/element/role/miso-affiliation.js +20 -0
- package/dist/cjs/layout/affiliation/affiliation.js +330 -0
- package/dist/cjs/layout/banner/banner.js +1 -1
- package/dist/cjs/layout/container/container.js +1 -1
- package/dist/cjs/layout/error/error.js +1 -1
- package/dist/cjs/layout/index.js +7 -0
- package/dist/cjs/layout/input/option-list.js +35 -50
- package/dist/cjs/layout/input/search-box.js +227 -129
- package/dist/cjs/layout/list/cards.js +1 -1
- package/dist/cjs/layout/list/carousel.js +5 -3
- package/dist/cjs/layout/list/collection.js +44 -49
- package/dist/cjs/layout/list/list.js +1 -1
- package/dist/cjs/layout/radio/feedback.js +1 -1
- package/dist/cjs/layout/radio/radio.js +1 -1
- package/dist/cjs/layout/raf.js +1 -1
- package/dist/cjs/layout/template.js +1 -1
- package/dist/cjs/layout/templates.js +172 -66
- package/dist/cjs/layout/text/text.js +1 -1
- package/dist/cjs/layout/text/typewriter/index.js +3 -3
- package/dist/cjs/layout/trackable.js +124 -0
- package/dist/cjs/plugin.js +1 -1
- package/dist/cjs/source/index.js +20 -8
- package/dist/cjs/util/bindings.js +58 -110
- package/dist/cjs/util/states.js +31 -24
- package/dist/cjs/util/trackers.js +75 -0
- package/dist/cjs/util/viewables.js +55 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/ask.js +60 -19
- package/dist/cjs/workflow/asks.js +1 -1
- package/dist/cjs/workflow/base.js +6 -7
- package/dist/cjs/workflow/explore.js +5 -2
- package/dist/cjs/workflow/options.js +60 -14
- package/dist/cjs/workflow/recommendation.js +2 -0
- package/dist/cjs/workflow/search.js +35 -7
- package/package.json +2 -2
- package/src/actor/autocomplete.js +131 -0
- package/src/actor/data.js +3 -10
- package/src/actor/fields.js +8 -0
- package/src/actor/index.js +1 -0
- package/src/actor/tracker.js +39 -62
- package/src/actor/trackers.js +3 -1
- package/src/actor/utils.js +14 -2
- package/src/actor/view.js +12 -1
- package/src/actor/views.js +11 -0
- package/src/affiliation/index.js +108 -0
- package/src/constants.js +10 -1
- package/src/defaults/ask/phrases.js +1 -1
- package/src/defaults/ask/templates.js +34 -2
- package/src/element/role/index.js +1 -0
- package/src/element/role/miso-affiliation.js +16 -0
- package/src/layout/affiliation/affiliation.js +295 -0
- package/src/layout/index.js +1 -0
- package/src/layout/input/option-list.js +35 -43
- package/src/layout/input/search-box.js +192 -95
- package/src/layout/list/carousel.js +4 -2
- package/src/layout/list/collection.js +42 -43
- package/src/layout/templates.js +127 -46
- package/src/layout/text/typewriter/index.js +2 -2
- package/src/layout/trackable.js +106 -0
- package/src/source/index.js +14 -1
- package/src/util/bindings.js +47 -103
- package/src/util/states.js +26 -20
- package/src/util/trackers.js +69 -0
- package/src/util/viewables.js +47 -0
- package/src/version.js +1 -1
- package/src/workflow/ask.js +37 -3
- package/src/workflow/base.js +2 -3
- package/src/workflow/explore.js +1 -1
- package/src/workflow/options.js +54 -13
- package/src/workflow/recommendation.js +1 -0
- package/src/workflow/search.js +33 -1
- package/dist/cjs/util/tracker.js +0 -348
- package/src/util/tracker.js +0 -318
package/dist/cjs/combo/base.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
8
|
const _excluded = ["name", "plugin", "MisoClient"];
|
|
9
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
9
|
+
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; }
|
|
10
10
|
class Combo extends _commons.Component {
|
|
11
11
|
constructor(_ref) {
|
|
12
12
|
let {
|
package/dist/cjs/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.TRACKING_STATUS = exports.STATUS = exports.ROLE = exports.ORGANIC_QUESTION_SOURCE = exports.LAYOUT_CATEGORY = exports.EVENT_TYPE = exports.DEFAULT_UNIT_ID = exports.ATTR_DATA_MISO_UNIT_ID = exports.ATTR_DATA_MISO_PRODUCT_ID = void 0;
|
|
6
|
+
exports.TRACKING_STATUS = exports.TRACKING_EVENT_TYPES = exports.STATUS = exports.ROLE = exports.ORGANIC_QUESTION_SOURCE = exports.LAYOUT_CATEGORY = exports.EVENT_TYPE = exports.DEFAULT_UNIT_ID = exports.ATTR_DATA_MISO_UNIT_ID = exports.ATTR_DATA_MISO_PRODUCT_ID = void 0;
|
|
7
7
|
exports.isDataRole = isDataRole;
|
|
8
8
|
exports.validateEventType = validateEventType;
|
|
9
9
|
exports.validateTrackingStatus = validateTrackingStatus;
|
|
@@ -27,9 +27,10 @@ const ROLE = exports.ROLE = Object.freeze({
|
|
|
27
27
|
RELATED_RESOURCES: 'related_resources',
|
|
28
28
|
QUERY_SUGGESTIONS: 'query_suggestions',
|
|
29
29
|
RELATED_QUESTIONS: 'related_questions',
|
|
30
|
+
AFFILIATION: 'affiliation',
|
|
30
31
|
ERROR: 'error'
|
|
31
32
|
});
|
|
32
|
-
const DATA_ROLE_SET = new Set([ROLE.PRODUCTS, ROLE.CATEGORIES, ROLE.ATTRIBUTES, ROLE.RESULTS, ROLE.ITEMS, ROLE.QUESTION, ROLE.ANSWER, ROLE.SOURCES, ROLE.RELATED_RESOURCES, ROLE.QUERY_SUGGESTIONS, ROLE.RELATED_QUESTIONS]);
|
|
33
|
+
const DATA_ROLE_SET = new Set([ROLE.PRODUCTS, ROLE.CATEGORIES, ROLE.ATTRIBUTES, ROLE.RESULTS, ROLE.ITEMS, ROLE.QUESTION, ROLE.ANSWER, ROLE.SOURCES, ROLE.RELATED_RESOURCES, ROLE.QUERY_SUGGESTIONS, ROLE.RELATED_QUESTIONS, ROLE.AFFILIATION]);
|
|
33
34
|
function isDataRole(role) {
|
|
34
35
|
return DATA_ROLE_SET.has(role);
|
|
35
36
|
}
|
|
@@ -40,6 +41,7 @@ const LAYOUT_CATEGORY = exports.LAYOUT_CATEGORY = Object.freeze({
|
|
|
40
41
|
QUERY: 'query',
|
|
41
42
|
RADIO: 'radio',
|
|
42
43
|
TEXT: 'text',
|
|
44
|
+
AFFILIATION: 'affiliation',
|
|
43
45
|
ERROR: 'error'
|
|
44
46
|
});
|
|
45
47
|
const EVENT_TYPE = exports.EVENT_TYPE = Object.freeze({
|
|
@@ -47,6 +49,7 @@ const EVENT_TYPE = exports.EVENT_TYPE = Object.freeze({
|
|
|
47
49
|
VIEWABLE: 'viewable',
|
|
48
50
|
CLICK: 'click'
|
|
49
51
|
});
|
|
52
|
+
const TRACKING_EVENT_TYPES = exports.TRACKING_EVENT_TYPES = [EVENT_TYPE.IMPRESSION, EVENT_TYPE.VIEWABLE, EVENT_TYPE.CLICK];
|
|
50
53
|
const TRACKING_STATUS = exports.TRACKING_STATUS = Object.freeze({
|
|
51
54
|
UNTRACKED: 'untracked',
|
|
52
55
|
TRACKING: 'tracking',
|
|
@@ -63,7 +66,7 @@ const STATUS = exports.STATUS = Object.freeze({
|
|
|
63
66
|
NONEMPTY: 'nonempty'
|
|
64
67
|
});
|
|
65
68
|
function validateEventType(value) {
|
|
66
|
-
if (
|
|
69
|
+
if (TRACKING_EVENT_TYPES.indexOf(value) < 0) {
|
|
67
70
|
throw new Error(`Unrecognized event type: ${value}`);
|
|
68
71
|
}
|
|
69
72
|
}
|
|
@@ -7,7 +7,7 @@ exports.wireFollowUps = wireFollowUps;
|
|
|
7
7
|
exports.wireRelatedResources = wireRelatedResources;
|
|
8
8
|
var _templates = require("./templates.js");
|
|
9
9
|
const _excluded = ["template"];
|
|
10
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
10
|
+
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; }
|
|
11
11
|
function wireFollowUps(client, element) {
|
|
12
12
|
let _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
13
13
|
let {
|
|
@@ -12,7 +12,7 @@ const question = exports.question = 'You asked...';
|
|
|
12
12
|
/**
|
|
13
13
|
* The phrase displayed right before <miso-sources>
|
|
14
14
|
*/
|
|
15
|
-
const sources = exports.sources = '
|
|
15
|
+
const sources = exports.sources = 'This reply is based on the following articles';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* The phrase displayed right before <miso-query-suggestions>
|
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.followUp = followUp;
|
|
7
|
+
exports.helpers = void 0;
|
|
7
8
|
exports.root = root;
|
|
9
|
+
exports.sections = void 0;
|
|
8
10
|
var _commons = require("@miso.ai/commons");
|
|
9
11
|
var _constants = require("./constants.js");
|
|
10
12
|
var DEFAULT_PHRASES = _interopRequireWildcard(require("./phrases.js"));
|
|
@@ -12,7 +14,7 @@ const _excluded = ["classPrefix", "circledCitationIndex", "phrases"],
|
|
|
12
14
|
_excluded2 = ["classes"];
|
|
13
15
|
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
16
|
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
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
17
|
+
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; }
|
|
16
18
|
// TODO: rename classPrefix -> rootClass?
|
|
17
19
|
// TODO: placeholder
|
|
18
20
|
|
|
@@ -39,6 +41,25 @@ function followUp() {
|
|
|
39
41
|
}, '<miso-query></miso-query>'), ...answerGroup(options)]);
|
|
40
42
|
}
|
|
41
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
|
+
});
|
|
42
63
|
|
|
43
64
|
// options //
|
|
44
65
|
function normalizeOptions() {
|
|
@@ -113,7 +134,7 @@ function querySuggestions(options) {
|
|
|
113
134
|
}), '<miso-query-suggestions></miso-query-suggestions>']);
|
|
114
135
|
}
|
|
115
136
|
function answerGroup(options) {
|
|
116
|
-
return [answer(options), sources(options), container(options, {
|
|
137
|
+
return [answer(options), affiliation(options), sources(options), container(options, {
|
|
117
138
|
name: 'bottom-spacing',
|
|
118
139
|
visibleWhen: 'ongoing'
|
|
119
140
|
})];
|
|
@@ -127,7 +148,6 @@ function answer(options) {
|
|
|
127
148
|
tag: 'div'
|
|
128
149
|
}), '<miso-question></miso-question>', '<miso-answer></miso-answer>', '<miso-feedback></miso-feedback>']);
|
|
129
150
|
}
|
|
130
|
-
;
|
|
131
151
|
function sources(options) {
|
|
132
152
|
return container(options, {
|
|
133
153
|
name: 'sources',
|
|
@@ -137,7 +157,18 @@ function sources(options) {
|
|
|
137
157
|
tag: 'h3'
|
|
138
158
|
}), '<miso-sources></miso-sources>']);
|
|
139
159
|
}
|
|
140
|
-
|
|
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
|
+
}
|
|
141
172
|
function phrase(options, _ref2) {
|
|
142
173
|
let {
|
|
143
174
|
name,
|
|
@@ -75,6 +75,12 @@ Object.defineProperty(exports, "MisoSourcesElement", {
|
|
|
75
75
|
return _misoSources.default;
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
|
+
Object.defineProperty(exports, "MisoSovrnAffiliationElement", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _misoAffiliation.default;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
78
84
|
var _misoComponent = _interopRequireDefault(require("./miso-component.js"));
|
|
79
85
|
var _misoQuery = _interopRequireDefault(require("./miso-query.js"));
|
|
80
86
|
var _misoQuerySuggestions = _interopRequireDefault(require("./miso-query-suggestions.js"));
|
|
@@ -86,5 +92,6 @@ var _misoAnswer = _interopRequireDefault(require("./miso-answer.js"));
|
|
|
86
92
|
var _misoSources = _interopRequireDefault(require("./miso-sources.js"));
|
|
87
93
|
var _misoRelatedResources = _interopRequireDefault(require("./miso-related-resources.js"));
|
|
88
94
|
var _misoRelatedQuestions = _interopRequireDefault(require("./miso-related-questions.js"));
|
|
95
|
+
var _misoAffiliation = _interopRequireDefault(require("./miso-affiliation.js"));
|
|
89
96
|
var _misoError = _interopRequireDefault(require("./miso-error.js"));
|
|
90
97
|
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 MisoAffiliationElement extends _misoComponent.default {
|
|
11
|
+
constructor() {
|
|
12
|
+
super({
|
|
13
|
+
role: _constants.ROLE.AFFILIATION
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
static get tagName() {
|
|
17
|
+
return 'miso-affiliation';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = MisoAffiliationElement;
|
|
@@ -0,0 +1,330 @@
|
|
|
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 _collection = _interopRequireDefault(require("../list/collection.js"));
|
|
10
|
+
var _templates = require("../templates.js");
|
|
11
|
+
const _excluded = ["className", "templates", "autoplay"];
|
|
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 = 'affiliation';
|
|
15
|
+
const DEFAULT_CLASSNAME = 'miso-affiliation';
|
|
16
|
+
function root(layout, state) {
|
|
17
|
+
const {
|
|
18
|
+
className,
|
|
19
|
+
role,
|
|
20
|
+
templates
|
|
21
|
+
} = layout;
|
|
22
|
+
const {
|
|
23
|
+
status
|
|
24
|
+
} = state;
|
|
25
|
+
const roleAttr = role ? ` data-role="${role}"` : '';
|
|
26
|
+
const data = state.value || {};
|
|
27
|
+
const channelAttr = data.channel ? ` data-channel="${data.channel}"` : '';
|
|
28
|
+
return `<div class="${className} ${status}"${roleAttr}${channelAttr}>${status === _constants.STATUS.READY ? templates[status](layout, state) : ''}</div>`;
|
|
29
|
+
}
|
|
30
|
+
function ready(layout, state) {
|
|
31
|
+
const {
|
|
32
|
+
templates
|
|
33
|
+
} = layout;
|
|
34
|
+
const items = layout._getItems(state);
|
|
35
|
+
if (items && items.length > 0) {
|
|
36
|
+
return templates.control(layout, state, 'previous') + templates.body(layout, state) + templates.control(layout, state, 'next');
|
|
37
|
+
} else {
|
|
38
|
+
return templates.empty(layout, state);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function control(layout, state, direction) {
|
|
42
|
+
const {
|
|
43
|
+
className
|
|
44
|
+
} = layout;
|
|
45
|
+
return `<div class="${className}__control-${direction}" data-role="${direction}"></div>`;
|
|
46
|
+
}
|
|
47
|
+
function body(layout, state) {
|
|
48
|
+
const {
|
|
49
|
+
className,
|
|
50
|
+
templates
|
|
51
|
+
} = layout;
|
|
52
|
+
const items = layout._getItems(state);
|
|
53
|
+
return `<div class="${className}__body">${templates.list(layout, state, items)}</div>`;
|
|
54
|
+
}
|
|
55
|
+
function header(layout, state) {
|
|
56
|
+
const {
|
|
57
|
+
className,
|
|
58
|
+
templates
|
|
59
|
+
} = layout;
|
|
60
|
+
let {
|
|
61
|
+
headerText
|
|
62
|
+
} = templates;
|
|
63
|
+
if (typeof headerText === 'function') {
|
|
64
|
+
headerText = headerText(layout, state);
|
|
65
|
+
}
|
|
66
|
+
if (!headerText) {
|
|
67
|
+
return '';
|
|
68
|
+
}
|
|
69
|
+
return `<div class="${className}__header"><div class="${className}__header-tab">${headerText}</div></div>`;
|
|
70
|
+
}
|
|
71
|
+
function item(layout, state, value, index) {
|
|
72
|
+
const {
|
|
73
|
+
className,
|
|
74
|
+
templates,
|
|
75
|
+
options
|
|
76
|
+
} = layout;
|
|
77
|
+
const {
|
|
78
|
+
itemType
|
|
79
|
+
} = options;
|
|
80
|
+
const header = templates.itemHeader(layout, state, value, {
|
|
81
|
+
index
|
|
82
|
+
});
|
|
83
|
+
const body = templates[itemType](layout, state, value, {
|
|
84
|
+
index
|
|
85
|
+
});
|
|
86
|
+
return `<li class="${className}__item">${header}${body}</li>`;
|
|
87
|
+
}
|
|
88
|
+
function itemHeader(layout, state, value, meta) {
|
|
89
|
+
const {
|
|
90
|
+
className,
|
|
91
|
+
templates
|
|
92
|
+
} = layout;
|
|
93
|
+
let {
|
|
94
|
+
headerText
|
|
95
|
+
} = templates;
|
|
96
|
+
if (typeof headerText === 'function') {
|
|
97
|
+
headerText = headerText(layout, state, value, meta);
|
|
98
|
+
}
|
|
99
|
+
if (!headerText) {
|
|
100
|
+
return '';
|
|
101
|
+
}
|
|
102
|
+
return `<div class="${className}__item-header"><div class="${className}__item-header-tab">${headerText}</div></div>`;
|
|
103
|
+
}
|
|
104
|
+
const DEFAULT_TEMPLATES = Object.freeze({
|
|
105
|
+
root,
|
|
106
|
+
[_constants.STATUS.READY]: ready,
|
|
107
|
+
control,
|
|
108
|
+
body,
|
|
109
|
+
header,
|
|
110
|
+
item,
|
|
111
|
+
itemHeader,
|
|
112
|
+
affiliation: _templates.affiliation,
|
|
113
|
+
ctaText: 'View',
|
|
114
|
+
headerText: 'Featured'
|
|
115
|
+
});
|
|
116
|
+
const INHERITED_DEFAULT_TEMPLATES = Object.freeze(Object.assign({}, _collection.default.defaultTemplates, DEFAULT_TEMPLATES));
|
|
117
|
+
function normalizeAutoplayOptions(options) {
|
|
118
|
+
if (options === true) {
|
|
119
|
+
options = {
|
|
120
|
+
interval: 5000
|
|
121
|
+
};
|
|
122
|
+
} else if (typeof options === 'number') {
|
|
123
|
+
if (options <= 0) {
|
|
124
|
+
options = false;
|
|
125
|
+
} else {
|
|
126
|
+
options = {
|
|
127
|
+
interval: Math.max(options, 500)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return options;
|
|
132
|
+
}
|
|
133
|
+
function autoplayOptionsEquals(a, b) {
|
|
134
|
+
if (a === b) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
if (!a || !b) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
return a.interval === b.interval;
|
|
141
|
+
}
|
|
142
|
+
class AffiliationLayout extends _collection.default {
|
|
143
|
+
static get category() {
|
|
144
|
+
return _constants.LAYOUT_CATEGORY.AFFILIATION;
|
|
145
|
+
}
|
|
146
|
+
static get type() {
|
|
147
|
+
return TYPE;
|
|
148
|
+
}
|
|
149
|
+
static get defaultTemplates() {
|
|
150
|
+
return INHERITED_DEFAULT_TEMPLATES;
|
|
151
|
+
}
|
|
152
|
+
static get defaultClassName() {
|
|
153
|
+
return DEFAULT_CLASSNAME;
|
|
154
|
+
}
|
|
155
|
+
constructor() {
|
|
156
|
+
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
157
|
+
let {
|
|
158
|
+
className = DEFAULT_CLASSNAME,
|
|
159
|
+
templates,
|
|
160
|
+
autoplay
|
|
161
|
+
} = _ref,
|
|
162
|
+
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
163
|
+
super(Object.assign({
|
|
164
|
+
className,
|
|
165
|
+
itemType: 'affiliation',
|
|
166
|
+
templates: Object.assign({}, DEFAULT_TEMPLATES, templates)
|
|
167
|
+
}, options));
|
|
168
|
+
this._itemCount = undefined;
|
|
169
|
+
this._itemIndex = 0;
|
|
170
|
+
this._displayedCount = undefined;
|
|
171
|
+
this._displayedIndex = undefined;
|
|
172
|
+
this._viewable = undefined;
|
|
173
|
+
this._autoplay = {};
|
|
174
|
+
this.autoplay(autoplay);
|
|
175
|
+
}
|
|
176
|
+
initialize(view) {
|
|
177
|
+
super.initialize(view);
|
|
178
|
+
const {
|
|
179
|
+
viewable: options
|
|
180
|
+
} = this._view.trackerOptions || {};
|
|
181
|
+
this._viewable = new _commons.CarouselItemViewabilityObserver(this._onViewable.bind(this), options);
|
|
182
|
+
}
|
|
183
|
+
autoplay() {
|
|
184
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
185
|
+
options = normalizeAutoplayOptions(options);
|
|
186
|
+
if (autoplayOptionsEquals(options, this._autoplay.options)) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (this._autoplay.options) {
|
|
190
|
+
clearInterval(this._autoplay.intervalId);
|
|
191
|
+
}
|
|
192
|
+
this._autoplay = {
|
|
193
|
+
options
|
|
194
|
+
};
|
|
195
|
+
// TODO: use slower transition speed for autoplay
|
|
196
|
+
// TODO: pause on hover
|
|
197
|
+
// TODO: cooldown after manual interaction
|
|
198
|
+
if (options) {
|
|
199
|
+
this._autoplay.intervalId = setInterval(() => this.next(), options.interval);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
get itemIndex() {
|
|
203
|
+
return this._itemIndex;
|
|
204
|
+
}
|
|
205
|
+
set itemIndex(index) {
|
|
206
|
+
if (this._itemCount === undefined) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (index < 0) {
|
|
210
|
+
index = this._itemCount - 1;
|
|
211
|
+
} else if (index >= this._itemCount) {
|
|
212
|
+
index = 0;
|
|
213
|
+
}
|
|
214
|
+
this._itemIndex = index;
|
|
215
|
+
(0, _commons.requestAnimationFrame)(() => this._syncItemIndex());
|
|
216
|
+
}
|
|
217
|
+
next() {
|
|
218
|
+
if (this._itemCount === undefined) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
this.itemIndex++;
|
|
222
|
+
}
|
|
223
|
+
previous() {
|
|
224
|
+
if (this._itemCount === undefined) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
this.itemIndex--;
|
|
228
|
+
}
|
|
229
|
+
_getItems(state) {
|
|
230
|
+
const {
|
|
231
|
+
products
|
|
232
|
+
} = state.value || {};
|
|
233
|
+
return products;
|
|
234
|
+
}
|
|
235
|
+
_render(element, states, controls) {
|
|
236
|
+
super._render(element, states, controls);
|
|
237
|
+
|
|
238
|
+
// update item count, but raf to display as attribute
|
|
239
|
+
const items = this._getItems(states.state);
|
|
240
|
+
this._itemCount = items ? items.length : undefined;
|
|
241
|
+
(0, _commons.requestAnimationFrame)(() => {
|
|
242
|
+
this._syncItemCount();
|
|
243
|
+
this._syncItemIndex();
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
_syncElement(element) {
|
|
247
|
+
const oldElement = this._element;
|
|
248
|
+
super._syncElement(element);
|
|
249
|
+
this._syncViewableElement(oldElement, element);
|
|
250
|
+
}
|
|
251
|
+
_syncViewableElement(oldElement, newElement) {
|
|
252
|
+
if (oldElement === newElement) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
oldElement && this._viewable.unobserve(oldElement);
|
|
256
|
+
newElement && this._viewable.observe(newElement);
|
|
257
|
+
}
|
|
258
|
+
_syncItemCount() {
|
|
259
|
+
const itemCount = this._itemCount;
|
|
260
|
+
if (itemCount === this._displayedCount) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
let {
|
|
264
|
+
element
|
|
265
|
+
} = this._view;
|
|
266
|
+
element = element.firstElementChild;
|
|
267
|
+
if (!element) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
this._displayedCount = itemCount;
|
|
271
|
+
if (itemCount === undefined) {
|
|
272
|
+
element.removeAttribute('data-item-count');
|
|
273
|
+
} else {
|
|
274
|
+
element.setAttribute('data-item-count', itemCount);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
_syncItemIndex() {
|
|
278
|
+
const index = this._itemIndex;
|
|
279
|
+
if (index === this._displayedIndex) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const {
|
|
283
|
+
element
|
|
284
|
+
} = this._view;
|
|
285
|
+
const listElement = element && this._getListElement(element);
|
|
286
|
+
if (!listElement) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
this._displayedIndex = index;
|
|
290
|
+
listElement.style.left = `${-index * 100}%`;
|
|
291
|
+
this._viewable.display(index);
|
|
292
|
+
this._view._events.emit('display', {
|
|
293
|
+
index
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
_onViewable(index) {
|
|
297
|
+
const item = this._getRenderedItemData(index);
|
|
298
|
+
if (!item) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
this._view._track(_constants.EVENT_TYPE.VIEWABLE, [item]);
|
|
302
|
+
}
|
|
303
|
+
_getRenderedItemData(index) {
|
|
304
|
+
const {
|
|
305
|
+
value
|
|
306
|
+
} = this._rendered.get(this._element) || {};
|
|
307
|
+
if (!value) {
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
const {
|
|
311
|
+
products = []
|
|
312
|
+
} = value;
|
|
313
|
+
return products[index];
|
|
314
|
+
}
|
|
315
|
+
_trackViewables() {} // omit default behavior for we want to track by other means
|
|
316
|
+
|
|
317
|
+
_onClick(event) {
|
|
318
|
+
super._onClick(event);
|
|
319
|
+
const element = event.target;
|
|
320
|
+
if (element.closest(`[data-role="previous"]`)) {
|
|
321
|
+
this.previous();
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (element.closest(`[data-role="next"]`)) {
|
|
325
|
+
this.next();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
exports.default = AffiliationLayout;
|
|
@@ -9,7 +9,7 @@ var _template = _interopRequireDefault(require("../template.js"));
|
|
|
9
9
|
var _svgs = require("../svgs.js");
|
|
10
10
|
const _excluded = ["className", "templates"];
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
12
|
+
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; }
|
|
13
13
|
const TYPE = 'banner';
|
|
14
14
|
const DEFAULT_CLASSNAME = 'miso-banner';
|
|
15
15
|
function root(layout) {
|
|
@@ -9,7 +9,7 @@ var _raf = _interopRequireDefault(require("../raf.js"));
|
|
|
9
9
|
var _misoBanner = _interopRequireDefault(require("../../element/miso-banner.js"));
|
|
10
10
|
const _excluded = ["logo"];
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
12
|
+
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; }
|
|
13
13
|
const TYPE = 'container';
|
|
14
14
|
class ContainerLayout extends _raf.default {
|
|
15
15
|
static get category() {
|
|
@@ -8,7 +8,7 @@ var _constants = require("../../constants.js");
|
|
|
8
8
|
var _template = _interopRequireDefault(require("../template.js"));
|
|
9
9
|
const _excluded = ["className", "templates"];
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
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
12
|
const TYPE = 'error';
|
|
13
13
|
const DEFAULT_CLASSNAME = 'miso-error';
|
|
14
14
|
function root(layout, state) {
|
package/dist/cjs/layout/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "AffiliationLayout", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _affiliation.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "BannerLayout", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
@@ -94,4 +100,5 @@ var _optionList = _interopRequireDefault(require("./input/option-list.js"));
|
|
|
94
100
|
var _feedback = _interopRequireDefault(require("./radio/feedback.js"));
|
|
95
101
|
var _text = _interopRequireDefault(require("./text/text.js"));
|
|
96
102
|
var _index = _interopRequireDefault(require("./text/typewriter/index.js"));
|
|
103
|
+
var _affiliation = _interopRequireDefault(require("./affiliation/affiliation.js"));
|
|
97
104
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|