@miso.ai/client-sdk-ui 1.10.0-beta.2 → 1.10.0-beta.4
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 +1 -1
- package/dist/cjs/actor/view.js +1 -1
- package/dist/cjs/affiliation/index.js +98 -0
- package/dist/cjs/combo/ask/options.js +1 -1
- package/dist/cjs/combo/base.js +1 -1
- package/dist/cjs/constants.js +3 -1
- 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 +109 -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 +1 -1
- package/dist/cjs/layout/input/search-box.js +1 -1
- package/dist/cjs/layout/list/cards.js +1 -1
- package/dist/cjs/layout/list/carousel.js +1 -1
- package/dist/cjs/layout/list/collection.js +9 -1
- 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 +133 -44
- package/dist/cjs/layout/text/text.js +1 -1
- package/dist/cjs/layout/text/typewriter/index.js +1 -1
- package/dist/cjs/plugin.js +1 -1
- package/dist/cjs/util/tracker.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/ask.js +12 -2
- package/dist/cjs/workflow/asks.js +1 -1
- package/dist/cjs/workflow/base.js +1 -1
- package/dist/cjs/workflow/explore.js +1 -1
- package/dist/cjs/workflow/options.js +1 -1
- package/package.json +2 -2
- package/src/affiliation/index.js +82 -0
- package/src/constants.js +3 -0
- package/src/defaults/ask/phrases.js +1 -1
- package/src/defaults/ask/templates.js +14 -2
- package/src/element/role/index.js +1 -0
- package/src/element/role/miso-affiliation.js +16 -0
- package/src/layout/affiliation/affiliation.js +84 -0
- package/src/layout/index.js +1 -0
- package/src/layout/list/collection.js +9 -1
- package/src/layout/templates.js +101 -26
- package/src/version.js +1 -1
- package/src/workflow/ask.js +6 -1
|
@@ -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,171 @@ 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, data);
|
|
160
|
+
content += ` <span class="${className}__item-discount-rate">${text}</span>`;
|
|
99
161
|
}
|
|
100
|
-
return `<div class="${className}__item-
|
|
162
|
+
return `<div class="${className}__item-price-container">${content}</div>`;
|
|
163
|
+
}
|
|
164
|
+
function discountRateText(layout, _ref9) {
|
|
165
|
+
let {
|
|
166
|
+
discount_rate_percent
|
|
167
|
+
} = _ref9;
|
|
168
|
+
return `(${discount_rate_percent}% off)`;
|
|
101
169
|
}
|
|
102
|
-
function imageBlock(
|
|
170
|
+
function imageBlock(_ref10, _ref11) {
|
|
103
171
|
let {
|
|
104
172
|
className
|
|
105
|
-
} =
|
|
173
|
+
} = _ref10;
|
|
106
174
|
let {
|
|
107
175
|
cover_image
|
|
108
|
-
} =
|
|
176
|
+
} = _ref11;
|
|
109
177
|
if (!cover_image) {
|
|
110
178
|
return '';
|
|
111
179
|
}
|
|
112
180
|
const img = `<img class="${className}__item-cover-image" src="${cover_image}">`;
|
|
113
181
|
return `<div class="${className}__item-cover-image-container">${img}</div>`;
|
|
114
182
|
}
|
|
115
|
-
function indexBlock(
|
|
183
|
+
function indexBlock(_ref12, data, _ref13) {
|
|
116
184
|
let {
|
|
117
185
|
className
|
|
118
|
-
} =
|
|
186
|
+
} = _ref12;
|
|
119
187
|
let {
|
|
120
188
|
index
|
|
121
|
-
} =
|
|
122
|
-
|
|
123
|
-
|
|
189
|
+
} = _ref13;
|
|
190
|
+
return `<div class="${className}__item-index-container"><span class="${className}__item-index miso-citation-index" data-index="${index + 1}"></span></div>`;
|
|
191
|
+
}
|
|
192
|
+
function ctaBlock(layout, data, meta) {
|
|
193
|
+
const {
|
|
194
|
+
className,
|
|
195
|
+
templates
|
|
196
|
+
} = layout;
|
|
197
|
+
let _cta = templates.cta || cta;
|
|
198
|
+
if (typeof _cta === 'function') {
|
|
199
|
+
_cta = _cta(layout, data, meta);
|
|
200
|
+
}
|
|
201
|
+
return _cta ? `<div class="${className}__item-cta-container">${_cta}</div>` : '';
|
|
202
|
+
}
|
|
203
|
+
function cta(layout, data, meta) {
|
|
204
|
+
const {
|
|
205
|
+
className,
|
|
206
|
+
templates
|
|
207
|
+
} = layout;
|
|
208
|
+
let text = templates.ctaText;
|
|
209
|
+
if (typeof text === 'function') {
|
|
210
|
+
text = text(layout, data, meta);
|
|
211
|
+
}
|
|
212
|
+
return text ? `<div class="${className}__item-cta">${text}</div>` : '';
|
|
124
213
|
}
|
|
125
214
|
|
|
126
215
|
// helpers //
|
|
127
|
-
function tagPair(
|
|
216
|
+
function tagPair(_ref14, _ref15) {
|
|
128
217
|
let {
|
|
129
218
|
className,
|
|
130
219
|
options = {}
|
|
131
|
-
} =
|
|
220
|
+
} = _ref14;
|
|
132
221
|
let {
|
|
133
222
|
product_id,
|
|
134
223
|
url
|
|
135
|
-
} =
|
|
224
|
+
} = _ref15;
|
|
136
225
|
let {
|
|
137
226
|
classSuffix = 'item-body',
|
|
138
227
|
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 {
|
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() {
|
package/dist/cjs/util/tracker.js
CHANGED
|
@@ -12,7 +12,7 @@ var _proxy = _interopRequireDefault(require("./proxy.js"));
|
|
|
12
12
|
const _excluded = ["impression", "viewable", "click"],
|
|
13
13
|
_excluded2 = ["proxyElement", "element", "sessionId", "active", "bindings"];
|
|
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 {
|
|
17
17
|
IMPRESSION,
|
|
18
18
|
VIEWABLE,
|
package/dist/cjs/version.js
CHANGED
package/dist/cjs/workflow/ask.js
CHANGED
|
@@ -11,11 +11,12 @@ var sources = _interopRequireWildcard(require("../source/index.js"));
|
|
|
11
11
|
var _index2 = require("../actor/index.js");
|
|
12
12
|
var _constants = require("../constants.js");
|
|
13
13
|
var _index3 = require("../layout/index.js");
|
|
14
|
+
var _index4 = require("../affiliation/index.js");
|
|
14
15
|
const _excluded = ["q", "qs"];
|
|
15
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
19
|
+
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; }
|
|
19
20
|
const DEFAULT_API_OPTIONS = Object.freeze({
|
|
20
21
|
group: _commons.API.GROUP.ASK,
|
|
21
22
|
name: _commons.API.NAME.QUESTIONS,
|
|
@@ -54,7 +55,13 @@ const DEFAULT_LAYOUTS = Object.freeze({
|
|
|
54
55
|
incremental: true,
|
|
55
56
|
itemType: 'article'
|
|
56
57
|
}],
|
|
57
|
-
[_constants.ROLE.QUERY_SUGGESTIONS]: _index3.OptionListLayout.type
|
|
58
|
+
[_constants.ROLE.QUERY_SUGGESTIONS]: _index3.OptionListLayout.type,
|
|
59
|
+
[_constants.ROLE.AFFILIATION]: [_index3.AffiliationLayout.type, {
|
|
60
|
+
itemType: 'affiliation',
|
|
61
|
+
link: {
|
|
62
|
+
rel: 'noopener nofollow'
|
|
63
|
+
}
|
|
64
|
+
}]
|
|
58
65
|
});
|
|
59
66
|
const DEFAULT_TRACKERS = Object.freeze({
|
|
60
67
|
[_constants.ROLE.SOURCES]: {},
|
|
@@ -251,6 +258,9 @@ class Ask extends _base.default {
|
|
|
251
258
|
}
|
|
252
259
|
}
|
|
253
260
|
|
|
261
|
+
// affiliation
|
|
262
|
+
data = (0, _index4.processData)(data);
|
|
263
|
+
|
|
254
264
|
// 1. put answer_stage to meta
|
|
255
265
|
// 2. mark ongoing flag
|
|
256
266
|
return Object.assign({}, data, {
|
|
@@ -8,7 +8,7 @@ var _context = _interopRequireDefault(require("./context.js"));
|
|
|
8
8
|
var _ask = _interopRequireDefault(require("./ask.js"));
|
|
9
9
|
const _excluded = ["root", "events"];
|
|
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
|
class Asks extends _context.default {
|
|
13
13
|
constructor(plugin, client) {
|
|
14
14
|
super('asks', plugin, client);
|
|
@@ -16,7 +16,7 @@ const _excluded = ["layouts", "interactions"],
|
|
|
16
16
|
_excluded3 = ["context"];
|
|
17
17
|
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); }
|
|
18
18
|
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; }
|
|
19
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
19
|
+
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; }
|
|
20
20
|
const DEFAULT_LAYOUTS = Object.freeze({
|
|
21
21
|
[_constants.ROLE.CONTAINER]: _index3.ContainerLayout.type,
|
|
22
22
|
[_constants.ROLE.ERROR]: _index3.ErrorLayout.type
|
|
@@ -12,7 +12,7 @@ var _constants = require("../constants.js");
|
|
|
12
12
|
var _index2 = require("../layout/index.js");
|
|
13
13
|
const _excluded = ["value"];
|
|
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 DEFAULT_API_OPTIONS = Object.freeze({
|
|
17
17
|
group: _commons.API.GROUP.ASK,
|
|
18
18
|
name: _commons.API.NAME.RELATED_QUESTIONS
|
|
@@ -19,7 +19,7 @@ exports.normalizeLayoutsOptions = normalizeLayoutsOptions;
|
|
|
19
19
|
exports.normalizeTrackers = normalizeTrackers;
|
|
20
20
|
var _commons = require("@miso.ai/commons");
|
|
21
21
|
var _constants = require("../constants.js");
|
|
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
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
24
24
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
25
25
|
// normalize //
|
package/package.json
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { trimObj } from '@miso.ai/commons';
|
|
2
|
+
|
|
3
|
+
export function processData(data) {
|
|
4
|
+
if (!data || !data.value) {
|
|
5
|
+
return data;
|
|
6
|
+
}
|
|
7
|
+
const { value } = data;
|
|
8
|
+
return {
|
|
9
|
+
...data,
|
|
10
|
+
value: processValue(value)
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function processValue(value) {
|
|
15
|
+
if (value.sovrn_aff) {
|
|
16
|
+
const { sovrn_aff, ...rest } = value;
|
|
17
|
+
return {
|
|
18
|
+
...rest,
|
|
19
|
+
affiliation: processSovrnData(sovrn_aff),
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function processSovrnData({ products, ...sovrn_aff }) {
|
|
26
|
+
products = products.slice(0, 1);
|
|
27
|
+
return {
|
|
28
|
+
channel: 'sovrn',
|
|
29
|
+
...sovrn_aff,
|
|
30
|
+
products: products.map(processSovrnProduct),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function processSovrnProduct({
|
|
35
|
+
id,
|
|
36
|
+
deeplink: url,
|
|
37
|
+
headline: title,
|
|
38
|
+
currency,
|
|
39
|
+
retailPrice: original_price,
|
|
40
|
+
salePrice: sale_price,
|
|
41
|
+
discountRate: discount_rate_percent,
|
|
42
|
+
image: cover_image,
|
|
43
|
+
thumbnail,
|
|
44
|
+
merchant,
|
|
45
|
+
...product
|
|
46
|
+
}) {
|
|
47
|
+
const brand = merchant && merchant.name;
|
|
48
|
+
const brand_logo = merchant && merchant.logo;
|
|
49
|
+
return trimObj({
|
|
50
|
+
id: `sovrn-${id}`,
|
|
51
|
+
channel: 'sovrn',
|
|
52
|
+
title,
|
|
53
|
+
cover_image,
|
|
54
|
+
url,
|
|
55
|
+
currency,
|
|
56
|
+
original_price,
|
|
57
|
+
sale_price,
|
|
58
|
+
discount_rate_percent,
|
|
59
|
+
brand,
|
|
60
|
+
brand_logo,
|
|
61
|
+
custom_attributes: flatten({
|
|
62
|
+
sovrn_id: id,
|
|
63
|
+
thumbnail,
|
|
64
|
+
merchant,
|
|
65
|
+
...product,
|
|
66
|
+
}),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function flatten(obj, prefix = '') {
|
|
71
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
72
|
+
const value = obj[key];
|
|
73
|
+
if (value === undefined) {
|
|
74
|
+
return acc;
|
|
75
|
+
}
|
|
76
|
+
const prefixedKey = prefix ? `${prefix}_${key}` : key;
|
|
77
|
+
if (typeof value === 'object') {
|
|
78
|
+
return { ...acc, ...flatten(value, prefixedKey) };
|
|
79
|
+
}
|
|
80
|
+
return { ...acc, [prefixedKey]: value };
|
|
81
|
+
}, {});
|
|
82
|
+
}
|
package/src/constants.js
CHANGED
|
@@ -19,6 +19,7 @@ export const ROLE = Object.freeze({
|
|
|
19
19
|
RELATED_RESOURCES: 'related_resources',
|
|
20
20
|
QUERY_SUGGESTIONS: 'query_suggestions',
|
|
21
21
|
RELATED_QUESTIONS: 'related_questions',
|
|
22
|
+
AFFILIATION: 'affiliation',
|
|
22
23
|
ERROR: 'error',
|
|
23
24
|
});
|
|
24
25
|
|
|
@@ -34,6 +35,7 @@ const DATA_ROLE_SET = new Set([
|
|
|
34
35
|
ROLE.RELATED_RESOURCES,
|
|
35
36
|
ROLE.QUERY_SUGGESTIONS,
|
|
36
37
|
ROLE.RELATED_QUESTIONS,
|
|
38
|
+
ROLE.AFFILIATION,
|
|
37
39
|
]);
|
|
38
40
|
|
|
39
41
|
export function isDataRole(role) {
|
|
@@ -47,6 +49,7 @@ export const LAYOUT_CATEGORY = Object.freeze({
|
|
|
47
49
|
QUERY: 'query',
|
|
48
50
|
RADIO: 'radio',
|
|
49
51
|
TEXT: 'text',
|
|
52
|
+
AFFILIATION: 'affiliation',
|
|
50
53
|
ERROR: 'error',
|
|
51
54
|
});
|
|
52
55
|
|
|
@@ -6,7 +6,7 @@ export const question = 'You asked...';
|
|
|
6
6
|
/**
|
|
7
7
|
* The phrase displayed right before <miso-sources>
|
|
8
8
|
*/
|
|
9
|
-
export const sources = '
|
|
9
|
+
export const sources = 'This reply is based on the following articles';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The phrase displayed right before <miso-query-suggestions>
|
|
@@ -106,6 +106,7 @@ function querySuggestions(options) {
|
|
|
106
106
|
function answerGroup(options) {
|
|
107
107
|
return [
|
|
108
108
|
answer(options),
|
|
109
|
+
affiliation(options),
|
|
109
110
|
sources(options),
|
|
110
111
|
container(options, { name: 'bottom-spacing', visibleWhen: 'ongoing' }),
|
|
111
112
|
];
|
|
@@ -119,7 +120,7 @@ function answer(options) {
|
|
|
119
120
|
'<miso-answer></miso-answer>',
|
|
120
121
|
'<miso-feedback></miso-feedback>',
|
|
121
122
|
]);
|
|
122
|
-
}
|
|
123
|
+
}
|
|
123
124
|
|
|
124
125
|
function sources(options) {
|
|
125
126
|
return container(options, { name: 'sources', visibleWhen: 'nonempty' }, [
|
|
@@ -127,7 +128,18 @@ function sources(options) {
|
|
|
127
128
|
phrase(options, { name: 'sources', tag: 'h3' }),
|
|
128
129
|
'<miso-sources></miso-sources>',
|
|
129
130
|
]);
|
|
130
|
-
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function affiliation(options) {
|
|
134
|
+
const { affiliation = true } = options || {};
|
|
135
|
+
if (!affiliation) {
|
|
136
|
+
return '';
|
|
137
|
+
}
|
|
138
|
+
return container(options, { name: 'affiliation', visibleWhen: 'nonempty' }, [
|
|
139
|
+
'<hr>',
|
|
140
|
+
'<miso-affiliation></miso-affiliation>',
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
131
143
|
|
|
132
144
|
function phrase(options, { name, tag = 'div' }) {
|
|
133
145
|
const { classPrefix } = options;
|
|
@@ -9,4 +9,5 @@ export { default as MisoAnswerElement } from './miso-answer.js';
|
|
|
9
9
|
export { default as MisoSourcesElement } from './miso-sources.js';
|
|
10
10
|
export { default as MisoRelatedResourcesElement } from './miso-related-resources.js';
|
|
11
11
|
export { default as MisoRelatedQuestionsElement } from './miso-related-questions.js';
|
|
12
|
+
export { default as MisoSovrnAffiliationElement } from './miso-affiliation.js';
|
|
12
13
|
export { default as MisoErrorElement } from './miso-error.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import MisoComponentElement from './miso-component.js';
|
|
2
|
+
import { ROLE } from '../../constants.js';
|
|
3
|
+
|
|
4
|
+
export default class MisoAffiliationElement extends MisoComponentElement {
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
super({
|
|
8
|
+
role: ROLE.AFFILIATION,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static get tagName() {
|
|
13
|
+
return 'miso-affiliation';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { STATUS, LAYOUT_CATEGORY } from '../../constants.js';
|
|
2
|
+
import CollectionLayout from '../list/collection.js';
|
|
3
|
+
import { affiliation } from '../templates.js';
|
|
4
|
+
|
|
5
|
+
const TYPE = 'affiliation';
|
|
6
|
+
const DEFAULT_CLASSNAME = 'miso-affiliation';
|
|
7
|
+
|
|
8
|
+
function root(layout, state) {
|
|
9
|
+
const { className, role, templates } = layout;
|
|
10
|
+
const { status } = state;
|
|
11
|
+
const roleAttr = role ? ` data-role="${role}"` : '';
|
|
12
|
+
const data = state.value || {};
|
|
13
|
+
const channelAttr = data.channel ? ` data-channel="${data.channel}"` : '';
|
|
14
|
+
return `<div class="${className} ${status}"${roleAttr}${channelAttr}>${status === STATUS.READY ? templates[status](layout, state) : ''}</div>`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function ready(layout, state) {
|
|
18
|
+
const { templates } = layout;
|
|
19
|
+
const { products } = state.value || {};
|
|
20
|
+
|
|
21
|
+
if (products && products.length > 0) {
|
|
22
|
+
return templates.body(layout, state);
|
|
23
|
+
} else {
|
|
24
|
+
return templates.empty(layout, state);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function body(layout, state) {
|
|
29
|
+
const { className, templates } = layout;
|
|
30
|
+
let { channel, products } = state.value;
|
|
31
|
+
products = products.map(product => ({ channel, ...product }));
|
|
32
|
+
return `<div class="${className}__body">${templates.header(layout, state)}${templates.list(layout, state, products)}</div>`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function header(layout, state) {
|
|
36
|
+
const { className, templates } = layout;
|
|
37
|
+
let { headerText } = templates;
|
|
38
|
+
if (typeof headerText === 'function') {
|
|
39
|
+
headerText = headerText(layout, state);
|
|
40
|
+
}
|
|
41
|
+
if (!headerText) {
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
return `<div class="${className}__header"><div class="${className}__header-tab">${headerText}</div></div>`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const DEFAULT_TEMPLATES = Object.freeze({
|
|
48
|
+
root,
|
|
49
|
+
[STATUS.READY]: ready,
|
|
50
|
+
body,
|
|
51
|
+
header,
|
|
52
|
+
affiliation,
|
|
53
|
+
ctaText: 'View',
|
|
54
|
+
headerText: 'Featured',
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const INHERITED_DEFAULT_TEMPLATES = Object.freeze({
|
|
58
|
+
...CollectionLayout.defaultTemplates,
|
|
59
|
+
...DEFAULT_TEMPLATES,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export default class AffiliationLayout extends CollectionLayout {
|
|
63
|
+
|
|
64
|
+
static get category() {
|
|
65
|
+
return LAYOUT_CATEGORY.AFFILIATION;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static get type() {
|
|
69
|
+
return TYPE;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static get defaultTemplates() {
|
|
73
|
+
return INHERITED_DEFAULT_TEMPLATES;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static get defaultClassName() {
|
|
77
|
+
return DEFAULT_CLASSNAME;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
constructor({ className = DEFAULT_CLASSNAME, templates, ...options } = {}) {
|
|
81
|
+
super({ className, itemType: 'affiliation', templates: { ...DEFAULT_TEMPLATES, ...templates }, ...options });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
package/src/layout/index.js
CHANGED
|
@@ -11,3 +11,4 @@ export { default as OptionListLayout } from './input/option-list.js';
|
|
|
11
11
|
export { default as FeedbackLayout } from './radio/feedback.js';
|
|
12
12
|
export { default as TextLayout } from './text/text.js';
|
|
13
13
|
export { default as TypewriterLayout } from './text/typewriter/index.js';
|
|
14
|
+
export { default as AffiliationLayout } from './affiliation/affiliation.js';
|