@miso.ai/client-sdk-ui 1.13.0-beta.3 → 1.13.0-beta.5

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.
@@ -22,6 +22,6 @@ const keywords = exports.keywords = 'You searched for “${value}”';
22
22
  /**
23
23
  * The phrase to display <miso-total>
24
24
  */
25
- const total = exports.total = '${value} Results';
25
+ const total = exports.total = '${value}';
26
26
  const showMore = exports.showMore = 'Show more';
27
27
  const showLess = exports.showLess = 'Show less';
@@ -11,9 +11,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
11
11
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
12
12
  const TYPE = 'text';
13
13
  const DEFAULT_CLASSNAME = 'miso-text';
14
- function root(layout, {
15
- value
16
- }) {
14
+ function root(layout, state) {
17
15
  const {
18
16
  className,
19
17
  role,
@@ -23,8 +21,13 @@ function root(layout, {
23
21
  }
24
22
  } = layout;
25
23
  const roleAttr = role ? `data-role="${role}"` : '';
26
- const content = value !== undefined ? (0, _commons.escapeHtml)(getFormatFunction(layout)(value)) : '';
27
- return raw ? content : `<${tag} class="${className}" ${roleAttr}>${content}</${tag}>`;
24
+ const text = layout.templates.content(layout, state);
25
+ return raw ? text : `<${tag} class="${className}" ${roleAttr}>${text}</${tag}>`;
26
+ }
27
+ function content(layout, {
28
+ value
29
+ }) {
30
+ return value !== undefined ? (0, _commons.escapeHtml)(getFormatFunction(layout)(value)) : '';
28
31
  }
29
32
  function getFormatFunction(layout) {
30
33
  let {
@@ -55,7 +58,8 @@ function getFormatFunction(layout) {
55
58
  }
56
59
  }
57
60
  const DEFAULT_TEMPLATES = Object.freeze({
58
- root
61
+ root,
62
+ content
59
63
  });
60
64
  class TextLayout extends _template.default {
61
65
  static get type() {
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '1.13.0-beta.3';
7
+ var _default = exports.default = '1.13.0-beta.5';
@@ -141,15 +141,14 @@ class Explore extends _unit.default {
141
141
  if (!value || !value.related_questions) {
142
142
  return data;
143
143
  }
144
- const linkFn = this._linkFn && this._linkFn[0];
145
- const related_questions = value.related_questions.map(linkFn ? text => ({
144
+ const [linkFn, linkOptions = {}] = this._linkFn || [];
145
+ const getDisplayedUrl = text => linkFn && linkOptions.showUrl ? this._getSubmitUrl({
146
+ q: text,
147
+ generated: true
148
+ }) : '#';
149
+ const related_questions = value.related_questions.map(text => ({
146
150
  text,
147
- url: this._getSubmitUrl({
148
- q: text,
149
- generated: true
150
- })
151
- }) : text => ({
152
- text
151
+ url: getDisplayedUrl(text)
153
152
  }));
154
153
  return Object.assign({}, data, {
155
154
  value: Object.assign({}, value, {
@@ -165,6 +164,16 @@ class Explore extends _unit.default {
165
164
  this._events.emit('select', Object.freeze(Object.assign({}, event, {
166
165
  question
167
166
  })));
167
+ const [linkFn, linkOptions = {}] = this._linkFn || [];
168
+ if (!linkFn || !linkOptions.showUrl) {
169
+ event.domEvent && event.domEvent.preventDefault();
170
+ }
171
+ if (linkFn && !linkOptions.showUrl) {
172
+ this._submitToPage({
173
+ q: question.text,
174
+ generated: true
175
+ });
176
+ }
168
177
  }
169
178
  query(args) {
170
179
  if (!args.q) {
@@ -178,6 +187,7 @@ class Explore extends _unit.default {
178
187
  }));
179
188
  }
180
189
  _getSubmitUrl(args) {
190
+ // TODO: if trending_questions -> qs = '_trending'
181
191
  let url = _useLink.UseLinkMixin.prototype._getSubmitUrl.call(this, args);
182
192
  if (!args.generated || !this._productId) {
183
193
  return url;
@@ -22,6 +22,19 @@ const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAUL
22
22
  rows: DEFAULT_ROWS
23
23
  })
24
24
  }));
25
+ function totalContent(layout, {
26
+ value
27
+ }) {
28
+ if (value === undefined) {
29
+ return '';
30
+ }
31
+ const {
32
+ formatNumber
33
+ } = layout.templates.helpers;
34
+ const formatted = formatNumber(value);
35
+ const label = value === 1 ? 'result' : 'results';
36
+ return `${formatted} ${label}`;
37
+ }
25
38
  const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LAYOUTS, {
26
39
  [_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type],
27
40
  [_constants.ROLE.PRODUCTS]: [_index2.ListLayout.type, {
@@ -33,7 +46,9 @@ const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LA
33
46
  }],
34
47
  [_constants.ROLE.TOTAL]: [_index2.TextLayout.type, {
35
48
  raw: true,
36
- format: 'number'
49
+ templates: {
50
+ content: totalContent
51
+ }
37
52
  }],
38
53
  [_constants.ROLE.FACETS]: [_index2.FacetsLayout.type],
39
54
  [_constants.ROLE.SORT]: [_index2.SelectLayout.type],
@@ -23,7 +23,6 @@ class UseLinkMixin {
23
23
  if (!this._linkFn) {
24
24
  return;
25
25
  }
26
- // TODO: we want a submit event
27
26
  const url = this._getSubmitUrl(args);
28
27
  const [_, options = {}] = this._linkFn;
29
28
  if (options.open === false) {
package/package.json CHANGED
@@ -16,7 +16,11 @@
16
16
  "build:cjs": "BABEL_ENV=cjs npx babel src --root-mode upward --out-dir dist/cjs",
17
17
  "build": "npm run build:clean && npm run build:cjs"
18
18
  },
19
- "repository": "MisoAI/miso-client-js-sdk",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/MisoAI/miso-client-js-sdk.git",
22
+ "directory": "packages/client-sdk-ui"
23
+ },
20
24
  "homepage": "https://misoai.github.io/miso-client-js-sdk/sdk",
21
25
  "license": "MIT",
22
26
  "contributors": [
@@ -26,7 +30,7 @@
26
30
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
27
31
  },
28
32
  "dependencies": {
29
- "@miso.ai/commons": "1.13.0-beta.3"
33
+ "@miso.ai/commons": "1.13.0-beta.5"
30
34
  },
31
- "version": "1.13.0-beta.3"
35
+ "version": "1.13.0-beta.5"
32
36
  }
@@ -16,7 +16,7 @@ export const keywords = 'You searched for “${value}”';
16
16
  /**
17
17
  * The phrase to display <miso-total>
18
18
  */
19
- export const total = '${value} Results';
19
+ export const total = '${value}';
20
20
 
21
21
  export const showMore = 'Show more';
22
22
  export const showLess = 'Show less';
@@ -4,11 +4,15 @@ import TemplateBasedLayout from '../template.js';
4
4
  const TYPE = 'text';
5
5
  const DEFAULT_CLASSNAME = 'miso-text';
6
6
 
7
- function root(layout, { value }) {
7
+ function root(layout, state) {
8
8
  const { className, role, options: { raw = false, tag } } = layout;
9
9
  const roleAttr = role ? `data-role="${role}"` : '';
10
- const content = value !== undefined ? escapeHtml(getFormatFunction(layout)(value)) : '';
11
- return raw ? content : `<${tag} class="${className}" ${roleAttr}>${content}</${tag}>`;
10
+ const text = layout.templates.content(layout, state);
11
+ return raw ? text : `<${tag} class="${className}" ${roleAttr}>${text}</${tag}>`;
12
+ }
13
+
14
+ function content(layout, { value }) {
15
+ return value !== undefined ? escapeHtml(getFormatFunction(layout)(value)) : '';
12
16
  }
13
17
 
14
18
  function getFormatFunction(layout) {
@@ -37,6 +41,7 @@ function getFormatFunction(layout) {
37
41
 
38
42
  const DEFAULT_TEMPLATES = Object.freeze({
39
43
  root,
44
+ content,
40
45
  });
41
46
 
42
47
  export default class TextLayout extends TemplateBasedLayout {
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.13.0-beta.3';
1
+ export default '1.13.0-beta.5';
@@ -132,8 +132,12 @@ export default class Explore extends UnitWorkflow {
132
132
  if (!value || !value.related_questions) {
133
133
  return data;
134
134
  }
135
- const linkFn = this._linkFn && this._linkFn[0];
136
- const related_questions = value.related_questions.map(linkFn ? (text => ({ text, url: this._getSubmitUrl({ q: text, generated: true }) })) : (text => ({ text })));
135
+ const [linkFn, linkOptions = {}] = this._linkFn || [];
136
+ const getDisplayedUrl = text => linkFn && linkOptions.showUrl ? this._getSubmitUrl({ q: text, generated: true }) : '#';
137
+ const related_questions = value.related_questions.map(text => ({
138
+ text,
139
+ url: getDisplayedUrl(text),
140
+ }));
137
141
  return {
138
142
  ...data,
139
143
  value: {
@@ -145,6 +149,13 @@ export default class Explore extends UnitWorkflow {
145
149
 
146
150
  _handleRelatedQuestionClick({ value: question, ...event }) {
147
151
  this._events.emit('select', Object.freeze({ ...event, question }));
152
+ const [linkFn, linkOptions = {}] = this._linkFn || [];
153
+ if (!linkFn || !linkOptions.showUrl) {
154
+ event.domEvent && event.domEvent.preventDefault();
155
+ }
156
+ if (linkFn && !linkOptions.showUrl) {
157
+ this._submitToPage({ q: question.text, generated: true });
158
+ }
148
159
  }
149
160
 
150
161
  query(args) {
@@ -159,6 +170,7 @@ export default class Explore extends UnitWorkflow {
159
170
  }
160
171
 
161
172
  _getSubmitUrl(args) {
173
+ // TODO: if trending_questions -> qs = '_trending'
162
174
  let url = UseLinkMixin.prototype._getSubmitUrl.call(this, args);
163
175
  if (!args.generated || !this._productId) {
164
176
  return url;
@@ -20,12 +20,22 @@ const DEFAULT_API_OPTIONS = Object.freeze({
20
20
  },
21
21
  });
22
22
 
23
+ function totalContent(layout, { value }) {
24
+ if (value === undefined) {
25
+ return '';
26
+ }
27
+ const { formatNumber } = layout.templates.helpers;
28
+ const formatted = formatNumber(value);
29
+ const label = value === 1 ? 'result' : 'results';
30
+ return `${formatted} ${label}`;
31
+ }
32
+
23
33
  const DEFAULT_LAYOUTS = Object.freeze({
24
34
  ...Workflow.DEFAULT_LAYOUTS,
25
35
  [ROLE.QUERY]: [SearchBoxLayout.type],
26
36
  [ROLE.PRODUCTS]: [ListLayout.type, { incremental: true, infiniteScroll: true }],
27
37
  [ROLE.KEYWORDS]: [TextLayout.type, { raw: true }],
28
- [ROLE.TOTAL]: [TextLayout.type, { raw: true, format: 'number' }],
38
+ [ROLE.TOTAL]: [TextLayout.type, { raw: true, templates: { content: totalContent } }],
29
39
  [ROLE.FACETS]: [FacetsLayout.type],
30
40
  [ROLE.SORT]: [SelectLayout.type],
31
41
  [ROLE.MORE]: [MoreButtonLayout.type],
@@ -18,7 +18,6 @@ export class UseLinkMixin {
18
18
  if (!this._linkFn) {
19
19
  return;
20
20
  }
21
- // TODO: we want a submit event
22
21
  const url = this._getSubmitUrl(args);
23
22
  const [_, options = {}] = this._linkFn;
24
23
  if (options.open === false) {