@miso.ai/client-sdk-ui 1.10.0-beta.1 → 1.10.0-beta.11
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/data.js +1 -1
- package/dist/cjs/actor/tracker.js +46 -70
- package/dist/cjs/actor/trackers.js +5 -1
- package/dist/cjs/actor/utils.js +6 -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 +14 -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 +17 -5
- 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 +38 -48
- 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 +135 -44
- 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/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 +14 -5
- package/dist/cjs/workflow/asks.js +1 -1
- package/dist/cjs/workflow/base.js +5 -5
- package/dist/cjs/workflow/explore.js +1 -1
- package/dist/cjs/workflow/options.js +6 -1
- package/dist/cjs/workflow/recommendation.js +2 -0
- package/package.json +2 -2
- package/src/actor/tracker.js +39 -62
- package/src/actor/trackers.js +3 -1
- package/src/actor/utils.js +6 -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 +13 -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 +7 -2
- package/src/layout/list/carousel.js +4 -2
- package/src/layout/list/collection.js +37 -43
- package/src/layout/templates.js +101 -26
- package/src/layout/text/typewriter/index.js +2 -2
- package/src/layout/trackable.js +106 -0
- 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 +7 -3
- package/src/workflow/base.js +1 -1
- package/src/workflow/options.js +5 -1
- package/src/workflow/recommendation.js +1 -0
- package/dist/cjs/util/tracker.js +0 -348
- package/src/util/tracker.js +0 -318
|
@@ -4,14 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _commons = require("@miso.ai/commons");
|
|
8
7
|
var _constants = require("../../constants.js");
|
|
9
8
|
var _template = _interopRequireDefault(require("../template.js"));
|
|
9
|
+
var _trackable = require("../trackable.js");
|
|
10
10
|
var _templates = require("../templates.js");
|
|
11
11
|
const _excluded = ["templates", "itemType"];
|
|
12
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.
|
|
14
|
-
const VALUE = Symbol.for('miso.value');
|
|
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; }
|
|
15
14
|
function root(layout, state) {
|
|
16
15
|
const {
|
|
17
16
|
className,
|
|
@@ -28,7 +27,7 @@ function ready(layout, state) {
|
|
|
28
27
|
const {
|
|
29
28
|
templates
|
|
30
29
|
} = layout;
|
|
31
|
-
const values = state
|
|
30
|
+
const values = layout._getItems(state);
|
|
32
31
|
|
|
33
32
|
// TODO: handle categories, attributes, etc. by introducing sublayout
|
|
34
33
|
if (values && values.length > 0 || state.ongoing) {
|
|
@@ -45,7 +44,7 @@ function list(layout, state, values) {
|
|
|
45
44
|
} = layout;
|
|
46
45
|
const listTag = templates.ordered ? 'ol' : 'ul';
|
|
47
46
|
// TODO: support separator?
|
|
48
|
-
return `<${listTag} class="${className}__list" data-item-type="${options.itemType}">${templates.items(layout, state, values)}</${listTag}>`;
|
|
47
|
+
return `<${listTag} class="${className}__list" data-role="list" data-item-type="${options.itemType}">${templates.items(layout, state, values)}</${listTag}>`;
|
|
49
48
|
}
|
|
50
49
|
function items(layout, state, values) {
|
|
51
50
|
let {
|
|
@@ -87,6 +86,14 @@ const DEFAULT_TEMPLATES = Object.freeze({
|
|
|
87
86
|
item,
|
|
88
87
|
productInfoBlock: _templates.productInfoBlock,
|
|
89
88
|
articleInfoBlock: _templates.articleInfoBlock,
|
|
89
|
+
brandBlock: _templates.brandBlock,
|
|
90
|
+
titleBlock: _templates.titleBlock,
|
|
91
|
+
descriptionBlock: _templates.descriptionBlock,
|
|
92
|
+
dateBlock: _templates.dateBlock,
|
|
93
|
+
priceBlock: _templates.priceBlock,
|
|
94
|
+
discountRateText: _templates.discountRateText,
|
|
95
|
+
ctaBlock: _templates.ctaBlock,
|
|
96
|
+
cta: _templates.cta,
|
|
90
97
|
imageBlock: _templates.imageBlock,
|
|
91
98
|
indexBlock: _templates.indexBlock,
|
|
92
99
|
helpers: _templates.helpers
|
|
@@ -108,19 +115,12 @@ class CollectionLayout extends _template.default {
|
|
|
108
115
|
templates: Object.assign({}, DEFAULT_TEMPLATES, templates),
|
|
109
116
|
itemType
|
|
110
117
|
}, options));
|
|
111
|
-
(0, _commons.defineValues)(this, {
|
|
112
|
-
bindings: Object.freeze({
|
|
113
|
-
list: this._listBindings.bind(this)
|
|
114
|
-
})
|
|
115
|
-
});
|
|
116
118
|
this._view = undefined;
|
|
119
|
+
this._initTrackable();
|
|
117
120
|
}
|
|
118
121
|
initialize(view) {
|
|
119
122
|
this._view = view;
|
|
120
|
-
|
|
121
|
-
proxyElement
|
|
122
|
-
} = this._view = view;
|
|
123
|
-
this._unsubscribes.push(proxyElement.on('click', this._onClick.bind(this)));
|
|
123
|
+
this._unsubscribes.push(view.proxyElement.on('click', this._onClick.bind(this)));
|
|
124
124
|
}
|
|
125
125
|
_preprocess(_ref2) {
|
|
126
126
|
let {
|
|
@@ -141,7 +141,7 @@ class CollectionLayout extends _template.default {
|
|
|
141
141
|
_html(state, rendered, incremental) {
|
|
142
142
|
if (incremental) {
|
|
143
143
|
const offset = rendered.value.length;
|
|
144
|
-
const values = state.
|
|
144
|
+
const values = (this._getItems(state) || []).slice(offset);
|
|
145
145
|
return values.length > 0 ? this.templates.items(this, state, values, {
|
|
146
146
|
offset
|
|
147
147
|
}) : '';
|
|
@@ -170,52 +170,40 @@ class CollectionLayout extends _template.default {
|
|
|
170
170
|
} else {
|
|
171
171
|
element.innerHTML = html;
|
|
172
172
|
}
|
|
173
|
-
this.
|
|
173
|
+
this._syncBindings(element, state);
|
|
174
174
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
let i = 0;
|
|
181
|
-
for (const itemElement of this._listItemElements(element)) {
|
|
182
|
-
itemElement[VALUE] = values[i++];
|
|
183
|
-
}
|
|
175
|
+
_unrender() {
|
|
176
|
+
this._clearBindings();
|
|
177
|
+
}
|
|
178
|
+
_getItems(state) {
|
|
179
|
+
return state.value;
|
|
184
180
|
}
|
|
185
181
|
_getListElement(element) {
|
|
186
|
-
return element.querySelector(
|
|
182
|
+
return element.querySelector('[data-role="list"]');
|
|
187
183
|
}
|
|
188
|
-
|
|
184
|
+
_getItemElements(element) {
|
|
189
185
|
return element ? Array.from(element.querySelectorAll(`[data-role="item"]`)) : [];
|
|
190
186
|
}
|
|
191
|
-
_listBindings(rootElement) {
|
|
192
|
-
if (!rootElement) {
|
|
193
|
-
return [];
|
|
194
|
-
}
|
|
195
|
-
const bindings = [];
|
|
196
|
-
for (const element of this._listItemElements(rootElement)) {
|
|
197
|
-
const value = element[VALUE];
|
|
198
|
-
if (!value) {
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
const key = this.options.itemType === 'product' ? value.product_id : value;
|
|
202
|
-
bindings.push({
|
|
203
|
-
element,
|
|
204
|
-
key,
|
|
205
|
-
value
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
return bindings;
|
|
209
|
-
}
|
|
210
187
|
_onClick(event) {
|
|
211
188
|
const element = event.target.closest(`[data-role="item"]`);
|
|
212
189
|
if (!element) {
|
|
213
190
|
return;
|
|
214
191
|
}
|
|
215
|
-
const
|
|
192
|
+
const binding = this._bindings.get(element);
|
|
193
|
+
if (!binding) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this._trackClick(event, binding);
|
|
197
|
+
this._emitClickEvent(event, binding);
|
|
198
|
+
}
|
|
199
|
+
_emitClickEvent(event, binding) {
|
|
216
200
|
const {
|
|
217
201
|
session
|
|
218
202
|
} = this._view._state;
|
|
203
|
+
const {
|
|
204
|
+
value,
|
|
205
|
+
element
|
|
206
|
+
} = binding;
|
|
219
207
|
this._view._events.emit('click', {
|
|
220
208
|
session,
|
|
221
209
|
value,
|
|
@@ -224,8 +212,10 @@ class CollectionLayout extends _template.default {
|
|
|
224
212
|
});
|
|
225
213
|
}
|
|
226
214
|
destroy() {
|
|
215
|
+
this._destroyTrackable();
|
|
227
216
|
this._view = undefined;
|
|
228
217
|
super.destroy();
|
|
229
218
|
}
|
|
230
219
|
}
|
|
231
|
-
exports.default = CollectionLayout;
|
|
220
|
+
exports.default = CollectionLayout;
|
|
221
|
+
(0, _trackable.makeTrackable)(CollectionLayout.prototype);
|
|
@@ -7,7 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _collection = _interopRequireDefault(require("./collection.js"));
|
|
8
8
|
const _excluded = ["className"];
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
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
|
const TYPE = 'list';
|
|
12
12
|
const DEFAULT_CLASSNAME = 'miso-list';
|
|
13
13
|
class ListLayout extends _collection.default {
|
|
@@ -9,7 +9,7 @@ var _radio = _interopRequireDefault(require("./radio.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 = 'feedback';
|
|
14
14
|
const DEFAULT_CLASSNAME = 'miso-feedback';
|
|
15
15
|
const OPTIONS = ['helpful', 'unhelpful'];
|
|
@@ -10,7 +10,7 @@ var _template = _interopRequireDefault(require("../template.js"));
|
|
|
10
10
|
var _templates = require("../templates.js");
|
|
11
11
|
const _excluded = ["className", "templates", "field", "defaultValue"];
|
|
12
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.
|
|
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
14
|
function root(layout) {
|
|
15
15
|
const {
|
|
16
16
|
className,
|
package/dist/cjs/layout/raf.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 = ["role", "workflow"];
|
|
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 RafLayout {
|
|
11
11
|
constructor() {
|
|
12
12
|
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -9,7 +9,7 @@ var _raf = _interopRequireDefault(require("./raf.js"));
|
|
|
9
9
|
var _templates = require("./templates.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
|
class TemplateBasedLayout extends _raf.default {
|
|
14
14
|
constructor() {
|
|
15
15
|
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -3,15 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.affiliation = affiliation;
|
|
7
|
+
exports.affiliationInfoBlock = affiliationInfoBlock;
|
|
6
8
|
exports.article = article;
|
|
7
9
|
exports.articleInfoBlock = articleInfoBlock;
|
|
10
|
+
exports.brandBlock = brandBlock;
|
|
11
|
+
exports.cta = cta;
|
|
12
|
+
exports.ctaBlock = ctaBlock;
|
|
13
|
+
exports.dateBlock = dateBlock;
|
|
14
|
+
exports.descriptionBlock = descriptionBlock;
|
|
15
|
+
exports.discountRateText = discountRateText;
|
|
8
16
|
exports.helpers = void 0;
|
|
9
17
|
exports.imageBlock = imageBlock;
|
|
10
18
|
exports.indexBlock = indexBlock;
|
|
19
|
+
exports.priceBlock = priceBlock;
|
|
11
20
|
exports.product = product;
|
|
12
21
|
exports.productInfoBlock = productInfoBlock;
|
|
13
22
|
exports.question = question;
|
|
14
23
|
exports.requiresImplementation = requiresImplementation;
|
|
24
|
+
exports.titleBlock = titleBlock;
|
|
15
25
|
exports.unimplemented = unimplemented;
|
|
16
26
|
var _commons = require("@miso.ai/commons");
|
|
17
27
|
var _constants = require("../constants.js");
|
|
@@ -47,92 +57,173 @@ function article(layout, state, data, meta) {
|
|
|
47
57
|
const [openTag, closeTag] = tagPair(layout, data);
|
|
48
58
|
return [openTag, (templates.imageBlock || imageBlock)(layout, data, meta), (templates.infoBlock || templates.articleInfoBlock || articleInfoBlock)(layout, data, meta), (templates.indexBlock || indexBlock)(layout, data, meta), closeTag].join('');
|
|
49
59
|
}
|
|
50
|
-
function
|
|
60
|
+
function affiliation(layout, state, data, meta) {
|
|
61
|
+
const {
|
|
62
|
+
templates
|
|
63
|
+
} = layout;
|
|
64
|
+
const [openTag, closeTag] = tagPair(layout, data);
|
|
65
|
+
return [openTag, (templates.infoBlock || templates.affiliationInfoBlock || affiliationInfoBlock)(layout, data, meta), (templates.imageBlock || imageBlock)(layout, data, meta), (templates.brandBlock || brandBlock)(layout, data, meta), closeTag].join('');
|
|
66
|
+
}
|
|
67
|
+
function affiliationInfoBlock(layout, data, meta) {
|
|
68
|
+
const {
|
|
69
|
+
className,
|
|
70
|
+
templates
|
|
71
|
+
} = layout;
|
|
72
|
+
return `<div class="${className}__item-info-container">${[(templates.titleBlock || titleBlock)(layout, data, meta), (templates.descriptionBlock || descriptionBlock)(layout, data, meta), (templates.priceBlock || priceBlock)(layout, data, meta), (templates.ctaBlock || ctaBlock)(layout, data, meta)].join('')}</div>`;
|
|
73
|
+
}
|
|
74
|
+
function productInfoBlock(layout, data, meta) {
|
|
75
|
+
const {
|
|
76
|
+
className,
|
|
77
|
+
templates
|
|
78
|
+
} = layout;
|
|
79
|
+
return `<div class="${className}__item-info-container">${[(templates.titleBlock || titleBlock)(layout, data, meta), (templates.descriptionBlock || descriptionBlock)(layout, data, meta), (templates.priceBlock || priceBlock)(layout, data, meta)].join('')}</div>`;
|
|
80
|
+
}
|
|
81
|
+
function articleInfoBlock(layout, data, meta) {
|
|
82
|
+
const {
|
|
83
|
+
className,
|
|
84
|
+
templates
|
|
85
|
+
} = layout;
|
|
86
|
+
return `<div class="${className}__item-info-container">${[(templates.titleBlock || titleBlock)(layout, data, meta), (templates.dateBlock || dateBlock)(layout, data, meta), (templates.descriptionBlock || descriptionBlock)(layout, data, meta), (templates.ctaBlock || ctaBlock)(layout, data, meta)].join('')}</div>`;
|
|
87
|
+
}
|
|
88
|
+
function titleBlock(_ref, _ref2) {
|
|
51
89
|
let {
|
|
52
90
|
className
|
|
53
91
|
} = _ref;
|
|
54
92
|
let {
|
|
55
|
-
title
|
|
56
|
-
description,
|
|
57
|
-
sale_price,
|
|
58
|
-
original_price
|
|
93
|
+
title
|
|
59
94
|
} = _ref2;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
95
|
+
return title ? `<div class="${className}__item-title">${(0, _commons.escapeHtml)(title)}</div>` : '';
|
|
96
|
+
}
|
|
97
|
+
function brandBlock(_ref3, _ref4) {
|
|
98
|
+
let {
|
|
99
|
+
className
|
|
100
|
+
} = _ref3;
|
|
101
|
+
let {
|
|
102
|
+
brand,
|
|
103
|
+
brand_logo
|
|
104
|
+
} = _ref4;
|
|
105
|
+
if (!brand && !brand_logo) {
|
|
106
|
+
return '';
|
|
71
107
|
}
|
|
72
|
-
|
|
108
|
+
const content = brand_logo ? `<img class="${className}__item-brand-logo" src="${brand_logo}"${brand ? ` alt="${brand}"` : ''}>` : `<div class="${className}__item-brand">${brand}</div>`;
|
|
109
|
+
return `<div class="${className}__item-brand-container">${content}</div>`;
|
|
110
|
+
}
|
|
111
|
+
function descriptionBlock(_ref5, _ref6) {
|
|
112
|
+
let {
|
|
113
|
+
className
|
|
114
|
+
} = _ref5;
|
|
115
|
+
let {
|
|
116
|
+
snippet,
|
|
117
|
+
description
|
|
118
|
+
} = _ref6;
|
|
119
|
+
return snippet ? `<div class="${className}__item-snippet">${snippet}</div>` : description ? `<div class="${className}__item-desc">${(0, _commons.escapeHtml)(description)}</div>` : '';
|
|
73
120
|
}
|
|
74
|
-
function
|
|
121
|
+
function dateBlock(_ref7, _ref8) {
|
|
75
122
|
let {
|
|
76
123
|
className,
|
|
77
124
|
templates
|
|
78
|
-
} =
|
|
125
|
+
} = _ref7;
|
|
79
126
|
let {
|
|
80
|
-
title,
|
|
81
|
-
snippet,
|
|
82
|
-
description,
|
|
83
127
|
created_at,
|
|
84
128
|
updated_at,
|
|
85
129
|
published_at
|
|
86
|
-
} =
|
|
130
|
+
} = _ref8;
|
|
87
131
|
const date = published_at || created_at || updated_at;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
132
|
+
return date ? `<div class="${className}__item-date">${formatDate(date, templates.date)}</div>` : '';
|
|
133
|
+
}
|
|
134
|
+
function priceBlock(layout, data) {
|
|
135
|
+
const {
|
|
136
|
+
className,
|
|
137
|
+
templates
|
|
138
|
+
} = layout;
|
|
139
|
+
const {
|
|
140
|
+
sale_price,
|
|
141
|
+
original_price,
|
|
142
|
+
currency = 'USD'
|
|
143
|
+
} = data;
|
|
144
|
+
const price = sale_price || original_price;
|
|
145
|
+
if (!price) {
|
|
146
|
+
return '';
|
|
91
147
|
}
|
|
92
|
-
|
|
93
|
-
|
|
148
|
+
const has_price_difference = original_price !== undefined && sale_price !== undefined && sale_price < original_price;
|
|
149
|
+
const discount_rate_percent = data.discount_rate_percent || (has_price_difference ? Math.floor((1 - sale_price / original_price) * 100) : undefined);
|
|
150
|
+
let content = '';
|
|
151
|
+
// original price
|
|
152
|
+
if (has_price_difference) {
|
|
153
|
+
content += `<span class="${className}__item-original-price miso-price" data-currency="${currency}">${original_price}</span><br>`;
|
|
94
154
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
155
|
+
// current price
|
|
156
|
+
content += `<span class="${className}__item-price miso-price" data-currency="${currency}">${price}</span>`;
|
|
157
|
+
// discount rate
|
|
158
|
+
if (discount_rate_percent) {
|
|
159
|
+
const text = (templates.discountRateText || discountRateText)(layout, Object.assign({}, data, {
|
|
160
|
+
discount_rate_percent
|
|
161
|
+
}));
|
|
162
|
+
content += ` <span class="${className}__item-discount-rate">${text}</span>`;
|
|
99
163
|
}
|
|
100
|
-
return `<div class="${className}__item-
|
|
164
|
+
return `<div class="${className}__item-price-container">${content}</div>`;
|
|
165
|
+
}
|
|
166
|
+
function discountRateText(layout, _ref9) {
|
|
167
|
+
let {
|
|
168
|
+
discount_rate_percent
|
|
169
|
+
} = _ref9;
|
|
170
|
+
return `(${discount_rate_percent}% off)`;
|
|
101
171
|
}
|
|
102
|
-
function imageBlock(
|
|
172
|
+
function imageBlock(_ref10, _ref11) {
|
|
103
173
|
let {
|
|
104
174
|
className
|
|
105
|
-
} =
|
|
175
|
+
} = _ref10;
|
|
106
176
|
let {
|
|
107
177
|
cover_image
|
|
108
|
-
} =
|
|
178
|
+
} = _ref11;
|
|
109
179
|
if (!cover_image) {
|
|
110
180
|
return '';
|
|
111
181
|
}
|
|
112
182
|
const img = `<img class="${className}__item-cover-image" src="${cover_image}">`;
|
|
113
183
|
return `<div class="${className}__item-cover-image-container">${img}</div>`;
|
|
114
184
|
}
|
|
115
|
-
function indexBlock(
|
|
185
|
+
function indexBlock(_ref12, data, _ref13) {
|
|
116
186
|
let {
|
|
117
187
|
className
|
|
118
|
-
} =
|
|
188
|
+
} = _ref12;
|
|
119
189
|
let {
|
|
120
190
|
index
|
|
121
|
-
} =
|
|
122
|
-
|
|
123
|
-
|
|
191
|
+
} = _ref13;
|
|
192
|
+
return `<div class="${className}__item-index-container"><span class="${className}__item-index miso-citation-index" data-index="${index + 1}"></span></div>`;
|
|
193
|
+
}
|
|
194
|
+
function ctaBlock(layout, data, meta) {
|
|
195
|
+
const {
|
|
196
|
+
className,
|
|
197
|
+
templates
|
|
198
|
+
} = layout;
|
|
199
|
+
let _cta = templates.cta || cta;
|
|
200
|
+
if (typeof _cta === 'function') {
|
|
201
|
+
_cta = _cta(layout, data, meta);
|
|
202
|
+
}
|
|
203
|
+
return _cta ? `<div class="${className}__item-cta-container">${_cta}</div>` : '';
|
|
204
|
+
}
|
|
205
|
+
function cta(layout, data, meta) {
|
|
206
|
+
const {
|
|
207
|
+
className,
|
|
208
|
+
templates
|
|
209
|
+
} = layout;
|
|
210
|
+
let text = templates.ctaText;
|
|
211
|
+
if (typeof text === 'function') {
|
|
212
|
+
text = text(layout, data, meta);
|
|
213
|
+
}
|
|
214
|
+
return text ? `<div class="${className}__item-cta">${text}</div>` : '';
|
|
124
215
|
}
|
|
125
216
|
|
|
126
217
|
// helpers //
|
|
127
|
-
function tagPair(
|
|
218
|
+
function tagPair(_ref14, _ref15) {
|
|
128
219
|
let {
|
|
129
220
|
className,
|
|
130
221
|
options = {}
|
|
131
|
-
} =
|
|
222
|
+
} = _ref14;
|
|
132
223
|
let {
|
|
133
224
|
product_id,
|
|
134
225
|
url
|
|
135
|
-
} =
|
|
226
|
+
} = _ref15;
|
|
136
227
|
let {
|
|
137
228
|
classSuffix = 'item-body',
|
|
138
229
|
role = 'item'
|
|
@@ -9,7 +9,7 @@ var _constants = require("../../constants.js");
|
|
|
9
9
|
var _template = _interopRequireDefault(require("../template.js"));
|
|
10
10
|
const _excluded = ["className", "templates", "tag"];
|
|
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 = 'text';
|
|
14
14
|
const DEFAULT_CLASSNAME = 'miso-text';
|
|
15
15
|
function root(layout, state) {
|
|
@@ -12,7 +12,7 @@ var _plaintext = _interopRequireDefault(require("./plaintext.js"));
|
|
|
12
12
|
var _utils = require("./utils.js");
|
|
13
13
|
const _excluded = ["className", "tag", "format", "tooltip"];
|
|
14
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
15
|
+
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
16
|
const TYPE = 'typewriter';
|
|
17
17
|
const DEFAULT_CLASSNAME = 'miso-typewriter';
|
|
18
18
|
class TypewriterLayout extends _progressive.default {
|
|
@@ -86,7 +86,7 @@ class TypewriterLayout extends _progressive.default {
|
|
|
86
86
|
onDebug
|
|
87
87
|
});
|
|
88
88
|
// capture citation link click if necessary
|
|
89
|
-
this._unsubscribes.push(this._view.proxyElement.on('click', e => this.
|
|
89
|
+
this._unsubscribes.push(this._view.proxyElement.on('click', e => this._onClick(e)));
|
|
90
90
|
}
|
|
91
91
|
_getSource(index) {
|
|
92
92
|
const {
|
|
@@ -172,7 +172,7 @@ class TypewriterLayout extends _progressive.default {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
// event //
|
|
175
|
-
|
|
175
|
+
_onClick(_ref5) {
|
|
176
176
|
let {
|
|
177
177
|
target
|
|
178
178
|
} = _ref5;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TrackableMixin = void 0;
|
|
7
|
+
exports.makeTrackable = makeTrackable;
|
|
8
|
+
var _constants = require("../constants.js");
|
|
9
|
+
var _bindings = _interopRequireDefault(require("../util/bindings.js"));
|
|
10
|
+
var _viewables = _interopRequireDefault(require("../util/viewables.js"));
|
|
11
|
+
var _trackers = require("../util/trackers.js");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
function makeTrackable(prototype) {
|
|
14
|
+
_mixin(prototype, TrackableMixin.prototype);
|
|
15
|
+
}
|
|
16
|
+
function _mixin(target, source) {
|
|
17
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
18
|
+
for (const key in descriptors) {
|
|
19
|
+
if (key === 'constructor') {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const {
|
|
23
|
+
value
|
|
24
|
+
} = descriptors[key];
|
|
25
|
+
if (target[key] === undefined && typeof value === 'function') {
|
|
26
|
+
target[key] = value;
|
|
27
|
+
}
|
|
28
|
+
// TODO: getter, setter
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class TrackableMixin {
|
|
32
|
+
_initTrackable() {
|
|
33
|
+
this._bindings = new _bindings.default();
|
|
34
|
+
this._viewables = new _viewables.default();
|
|
35
|
+
}
|
|
36
|
+
_syncBindings(element, state) {
|
|
37
|
+
const values = this._getItems(state) || [];
|
|
38
|
+
const keys = values.map(value => this._getItemKey(value));
|
|
39
|
+
const elements = this._getItemElements(element);
|
|
40
|
+
const {
|
|
41
|
+
bounds,
|
|
42
|
+
unbounds
|
|
43
|
+
} = this._bindings.update(keys, values, elements);
|
|
44
|
+
this._onBindingsUpdate(bounds, unbounds);
|
|
45
|
+
}
|
|
46
|
+
_clearBindings() {
|
|
47
|
+
const {
|
|
48
|
+
bounds,
|
|
49
|
+
unbounds
|
|
50
|
+
} = this._bindings.clear();
|
|
51
|
+
this._onBindingsUpdate(bounds, unbounds);
|
|
52
|
+
}
|
|
53
|
+
_getItemKey(value) {
|
|
54
|
+
// TODO: ad-hoc!
|
|
55
|
+
return value.product_id || value.text || value.id || value;
|
|
56
|
+
}
|
|
57
|
+
_getItems(state) {
|
|
58
|
+
throw new Error(`Not implemented.`);
|
|
59
|
+
}
|
|
60
|
+
_getItemElements(element) {
|
|
61
|
+
throw new Error(`Not implemented.`);
|
|
62
|
+
}
|
|
63
|
+
_onBindingsUpdate(bounds, unbounds) {
|
|
64
|
+
this._trackImpressions(bounds);
|
|
65
|
+
this._untrackViewables(unbounds);
|
|
66
|
+
this._trackViewables(bounds);
|
|
67
|
+
}
|
|
68
|
+
_trackImpressions(entries) {
|
|
69
|
+
if (entries.length === 0) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const {
|
|
73
|
+
impression: options
|
|
74
|
+
} = this._view.trackerOptions || {};
|
|
75
|
+
if (!options) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
setTimeout(() => this._view._track(_constants.EVENT_TYPE.IMPRESSION, entries.map(_ref => {
|
|
79
|
+
let {
|
|
80
|
+
value
|
|
81
|
+
} = _ref;
|
|
82
|
+
return value;
|
|
83
|
+
})), 0);
|
|
84
|
+
}
|
|
85
|
+
_untrackViewables(entries) {
|
|
86
|
+
for (const {
|
|
87
|
+
element
|
|
88
|
+
} of entries) {
|
|
89
|
+
this._viewables.untrack(element);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
_trackViewables(entries) {
|
|
93
|
+
if (entries.length === 0) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const {
|
|
97
|
+
viewable: options
|
|
98
|
+
} = this._view.trackerOptions || {};
|
|
99
|
+
if (!options) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
for (const {
|
|
103
|
+
value,
|
|
104
|
+
element
|
|
105
|
+
} of entries) {
|
|
106
|
+
(async () => (await this._viewables.track(element, options)) && this._view._track(_constants.EVENT_TYPE.VIEWABLE, [value]))();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
_trackClick(event, binding) {
|
|
110
|
+
const {
|
|
111
|
+
click: options
|
|
112
|
+
} = this._view.trackerOptions || {};
|
|
113
|
+
if ((0, _trackers.validateClick)(options, event, binding)) {
|
|
114
|
+
this._view._track(_constants.EVENT_TYPE.CLICK, [binding.value]);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
_destroyTrackable() {
|
|
118
|
+
const {
|
|
119
|
+
unbounds
|
|
120
|
+
} = this._bindings.clear();
|
|
121
|
+
this._untrackViewables(unbounds);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.TrackableMixin = TrackableMixin;
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -19,7 +19,7 @@ const _excluded = ["containers", "roles", "combos"];
|
|
|
19
19
|
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); }
|
|
20
20
|
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; }
|
|
21
21
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
22
|
+
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; }
|
|
23
23
|
const PLUGIN_ID = 'std:ui';
|
|
24
24
|
class UiPlugin extends _commons.Component {
|
|
25
25
|
static get id() {
|