@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.
Files changed (51) hide show
  1. package/dist/cjs/actor/data.js +1 -1
  2. package/dist/cjs/actor/tracker.js +1 -1
  3. package/dist/cjs/actor/view.js +1 -1
  4. package/dist/cjs/affiliation/index.js +98 -0
  5. package/dist/cjs/combo/ask/options.js +1 -1
  6. package/dist/cjs/combo/base.js +1 -1
  7. package/dist/cjs/constants.js +3 -1
  8. package/dist/cjs/defaults/ask/controls.js +1 -1
  9. package/dist/cjs/defaults/ask/phrases.js +1 -1
  10. package/dist/cjs/defaults/ask/templates.js +14 -4
  11. package/dist/cjs/element/role/index.js +7 -0
  12. package/dist/cjs/element/role/miso-affiliation.js +20 -0
  13. package/dist/cjs/layout/affiliation/affiliation.js +109 -0
  14. package/dist/cjs/layout/banner/banner.js +1 -1
  15. package/dist/cjs/layout/container/container.js +1 -1
  16. package/dist/cjs/layout/error/error.js +1 -1
  17. package/dist/cjs/layout/index.js +7 -0
  18. package/dist/cjs/layout/input/option-list.js +1 -1
  19. package/dist/cjs/layout/input/search-box.js +1 -1
  20. package/dist/cjs/layout/list/cards.js +1 -1
  21. package/dist/cjs/layout/list/carousel.js +1 -1
  22. package/dist/cjs/layout/list/collection.js +9 -1
  23. package/dist/cjs/layout/list/list.js +1 -1
  24. package/dist/cjs/layout/radio/feedback.js +1 -1
  25. package/dist/cjs/layout/radio/radio.js +1 -1
  26. package/dist/cjs/layout/raf.js +1 -1
  27. package/dist/cjs/layout/template.js +1 -1
  28. package/dist/cjs/layout/templates.js +133 -44
  29. package/dist/cjs/layout/text/text.js +1 -1
  30. package/dist/cjs/layout/text/typewriter/index.js +1 -1
  31. package/dist/cjs/plugin.js +1 -1
  32. package/dist/cjs/util/tracker.js +1 -1
  33. package/dist/cjs/version.js +1 -1
  34. package/dist/cjs/workflow/ask.js +12 -2
  35. package/dist/cjs/workflow/asks.js +1 -1
  36. package/dist/cjs/workflow/base.js +1 -1
  37. package/dist/cjs/workflow/explore.js +1 -1
  38. package/dist/cjs/workflow/options.js +1 -1
  39. package/package.json +2 -2
  40. package/src/affiliation/index.js +82 -0
  41. package/src/constants.js +3 -0
  42. package/src/defaults/ask/phrases.js +1 -1
  43. package/src/defaults/ask/templates.js +14 -2
  44. package/src/element/role/index.js +1 -0
  45. package/src/element/role/miso-affiliation.js +16 -0
  46. package/src/layout/affiliation/affiliation.js +84 -0
  47. package/src/layout/index.js +1 -0
  48. package/src/layout/list/collection.js +9 -1
  49. package/src/layout/templates.js +101 -26
  50. package/src/version.js +1 -1
  51. package/src/workflow/ask.js +6 -1
@@ -1,7 +1,7 @@
1
1
  import { defineValues } from '@miso.ai/commons';
2
2
  import { STATUS, LAYOUT_CATEGORY } from '../../constants.js';
3
3
  import TemplateBasedLayout from '../template.js';
4
- import { product, article, question, productInfoBlock, articleInfoBlock, imageBlock, indexBlock, helpers } from '../templates.js';
4
+ import { product, article, question, productInfoBlock, articleInfoBlock, titleBlock, brandBlock, descriptionBlock, dateBlock, priceBlock, discountRateText, ctaBlock, cta, imageBlock, indexBlock, helpers } from '../templates.js';
5
5
 
6
6
  const VALUE = Symbol.for('miso.value');
7
7
 
@@ -59,6 +59,14 @@ const DEFAULT_TEMPLATES = Object.freeze({
59
59
  item,
60
60
  productInfoBlock,
61
61
  articleInfoBlock,
62
+ brandBlock,
63
+ titleBlock,
64
+ descriptionBlock,
65
+ dateBlock,
66
+ priceBlock,
67
+ discountRateText,
68
+ ctaBlock,
69
+ cta,
62
70
  imageBlock,
63
71
  indexBlock,
64
72
  helpers,
@@ -42,37 +42,95 @@ export function article(layout, state, data, meta) {
42
42
  ].join('');
43
43
  }
44
44
 
45
- export function productInfoBlock({ className }, { title, description, sale_price, original_price }) {
46
- let content = '';
47
- if (title) {
48
- content += `<div class="${className}__item-title">${escapeHtml(title)}</div>`;
49
- }
50
- if (description) {
51
- content += `<div class="${className}__item-desc">${escapeHtml(description)}</div>`;
52
- }
53
- const price = sale_price || original_price;
54
- if (price) {
55
- content += `<hr><div class="${className}__item-price">${price}</div>`;
56
- // TODO: enhance this
45
+ export function affiliation(layout, state, data, meta) {
46
+ const { templates } = layout;
47
+ const [openTag, closeTag] = tagPair(layout, data);
48
+ return [
49
+ openTag,
50
+ (templates.infoBlock || templates.affiliationInfoBlock || affiliationInfoBlock)(layout, data, meta),
51
+ (templates.imageBlock || imageBlock)(layout, data, meta),
52
+ (templates.brandBlock || brandBlock)(layout, data, meta),
53
+ closeTag,
54
+ ].join('');
55
+ }
56
+
57
+ export function affiliationInfoBlock(layout, data, meta) {
58
+ const { className, templates } = layout;
59
+ return `<div class="${className}__item-info-container">${[
60
+ (templates.titleBlock || titleBlock)(layout, data, meta),
61
+ (templates.descriptionBlock || descriptionBlock)(layout, data, meta),
62
+ (templates.priceBlock || priceBlock)(layout, data, meta),
63
+ (templates.ctaBlock || ctaBlock)(layout, data, meta),
64
+ ].join('')}</div>`;
65
+ }
66
+
67
+ export function productInfoBlock(layout, data, meta) {
68
+ const { className, templates } = layout;
69
+ return `<div class="${className}__item-info-container">${[
70
+ (templates.titleBlock || titleBlock)(layout, data, meta),
71
+ (templates.descriptionBlock || descriptionBlock)(layout, data, meta),
72
+ (templates.priceBlock || priceBlock)(layout, data, meta),
73
+ ].join('')}</div>`;
74
+ }
75
+
76
+ export function articleInfoBlock(layout, data, meta) {
77
+ const { className, templates } = layout;
78
+ return `<div class="${className}__item-info-container">${[
79
+ (templates.titleBlock || titleBlock)(layout, data, meta),
80
+ (templates.dateBlock || dateBlock)(layout, data, meta),
81
+ (templates.descriptionBlock || descriptionBlock)(layout, data, meta),
82
+ (templates.ctaBlock || ctaBlock)(layout, data, meta),
83
+ ].join('')}</div>`;
84
+ }
85
+
86
+ export function titleBlock({ className }, { title }) {
87
+ return title ? `<div class="${className}__item-title">${escapeHtml(title)}</div>` : '';
88
+ }
89
+
90
+ export function brandBlock({ className }, { brand, brand_logo }) {
91
+ if (!brand && !brand_logo) {
92
+ return '';
57
93
  }
58
- return `<div class="${className}__item-info-container">${content}</div>`;
94
+ const content = brand_logo ? `<img class="${className}__item-brand-logo" src="${brand_logo}"${brand ? ` alt="${brand}"` : ''}>` : `<div class="${className}__item-brand">${brand}</div>`;
95
+ return `<div class="${className}__item-brand-container">${content}</div>`;
59
96
  }
60
97
 
61
- export function articleInfoBlock({ className, templates }, { title, snippet, description, created_at, updated_at, published_at }) {
98
+ export function descriptionBlock({ className }, { snippet, description }) {
99
+ return snippet ? `<div class="${className}__item-snippet">${snippet}</div>` : description ? `<div class="${className}__item-desc">${escapeHtml(description)}</div>` : '';
100
+ }
101
+
102
+ export function dateBlock({ className, templates }, { created_at, updated_at, published_at }) {
62
103
  const date = published_at || created_at || updated_at;
63
- let content = '';
64
- if (title) {
65
- content += `<div class="${className}__item-title">${escapeHtml(title)}</div>`;
104
+ return date ? `<div class="${className}__item-date">${formatDate(date, templates.date)}</div>` : '';
105
+ }
106
+
107
+ export function priceBlock(layout, data) {
108
+ const { className, templates } = layout;
109
+ const { sale_price, original_price, currency = 'USD' } = data;
110
+ const price = sale_price || original_price;
111
+ if (!price) {
112
+ return '';
66
113
  }
67
- if (date) {
68
- content += `<div class="${className}__item-date">${formatDate(date, templates.date)}</div>`;
114
+ const has_price_difference = original_price !== undefined && sale_price !== undefined && sale_price < original_price;
115
+ const discount_rate_percent = data.discount_rate_percent || (has_price_difference ? Math.floor((1 - sale_price / original_price) * 100) : undefined);
116
+
117
+ let content = '';
118
+ // original price
119
+ if (has_price_difference) {
120
+ content += `<span class="${className}__item-original-price miso-price" data-currency="${currency}">${original_price}</span><br>`;
69
121
  }
70
- if (snippet) {
71
- content += `<div class="${className}__item-snippet">${snippet}</div>`;
72
- } else if (description) {
73
- content += `<div class="${className}__item-desc">${escapeHtml(description)}</div>`;
122
+ // current price
123
+ content += `<span class="${className}__item-price miso-price" data-currency="${currency}">${price}</span>`;
124
+ // discount rate
125
+ if (discount_rate_percent) {
126
+ const text = (templates.discountRateText || discountRateText)(layout, data);
127
+ content += ` <span class="${className}__item-discount-rate">${text}</span>`;
74
128
  }
75
- return `<div class="${className}__item-info-container">${content}</div>`;
129
+ return `<div class="${className}__item-price-container">${content}</div>`;
130
+ }
131
+
132
+ export function discountRateText(layout, { discount_rate_percent }) {
133
+ return `(${discount_rate_percent}% off)`;
76
134
  }
77
135
 
78
136
  export function imageBlock({ className }, { cover_image }) {
@@ -84,8 +142,25 @@ export function imageBlock({ className }, { cover_image }) {
84
142
  }
85
143
 
86
144
  export function indexBlock({ className }, data, { index }) {
87
- const i = index + 1;
88
- return `<div class="${className}__item-index-container"><span class="${className}__item-index miso-citation-index" data-index="${i}"></span></div>`;
145
+ return `<div class="${className}__item-index-container"><span class="${className}__item-index miso-citation-index" data-index="${index + 1}"></span></div>`;
146
+ }
147
+
148
+ export function ctaBlock(layout, data, meta) {
149
+ const { className, templates } = layout;
150
+ let _cta = templates.cta || cta;
151
+ if (typeof _cta === 'function') {
152
+ _cta = _cta(layout, data, meta);
153
+ }
154
+ return _cta ? `<div class="${className}__item-cta-container">${_cta}</div>` : '';
155
+ }
156
+
157
+ export function cta(layout, data, meta) {
158
+ const { className, templates } = layout;
159
+ let text = templates.ctaText;
160
+ if (typeof text === 'function') {
161
+ text = text(layout, data, meta);
162
+ }
163
+ return text ? `<div class="${className}__item-cta">${text}</div>` : '';
89
164
  }
90
165
 
91
166
  // helpers //
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.10.0-beta.2';
1
+ export default '1.10.0-beta.4';
@@ -4,8 +4,9 @@ import { mergeApiOptions } from './options.js';
4
4
  import * as sources from '../source/index.js';
5
5
  import { fields, FeedbackActor, AutocompleteActor } from '../actor/index.js';
6
6
  import { ROLE, STATUS, ORGANIC_QUESTION_SOURCE } from '../constants.js';
7
- import { SearchBoxLayout, OptionListLayout, ListLayout, TextLayout, TypewriterLayout, FeedbackLayout } from '../layout/index.js';
7
+ import { SearchBoxLayout, OptionListLayout, ListLayout, TextLayout, TypewriterLayout, FeedbackLayout, AffiliationLayout } from '../layout/index.js';
8
8
  import { makeConfigurable } from './options.js';
9
+ import { processData as processAffiliationData } from '../affiliation/index.js';
9
10
 
10
11
  const DEFAULT_API_OPTIONS = Object.freeze({
11
12
  group: API.GROUP.ASK,
@@ -35,6 +36,7 @@ const DEFAULT_LAYOUTS = Object.freeze({
35
36
  [ROLE.SOURCES]: [ListLayout.type, { incremental: true, itemType: 'article', templates: { ordered: true } }],
36
37
  [ROLE.RELATED_RESOURCES]: [ListLayout.type, { incremental: true, itemType: 'article' }],
37
38
  [ROLE.QUERY_SUGGESTIONS]: OptionListLayout.type,
39
+ [ROLE.AFFILIATION]: [AffiliationLayout.type, { itemType: 'affiliation', link: { rel: 'noopener nofollow' } }],
38
40
  });
39
41
 
40
42
  const DEFAULT_TRACKERS = Object.freeze({
@@ -207,6 +209,9 @@ export default class Ask extends Workflow {
207
209
  }
208
210
  }
209
211
 
212
+ // affiliation
213
+ data = processAffiliationData(data);
214
+
210
215
  // 1. put answer_stage to meta
211
216
  // 2. mark ongoing flag
212
217
  return {