@miso.ai/client-sdk-ui 1.9.1-beta.2 → 1.9.1-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.
@@ -12,6 +12,7 @@ const _excluded = ["classPrefix", "circledCitationIndex"],
12
12
  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); }
13
13
  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 && Object.prototype.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; }
14
14
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
15
+ // TODO: rename classPrefix -> rootClass?
15
16
  // TODO: placeholder
16
17
 
17
18
  function root() {
@@ -79,7 +79,7 @@ function articleInfoBlock(_ref3, _ref4) {
79
79
  updated_at,
80
80
  published_at
81
81
  } = _ref4;
82
- const date = updated_at || published_at || created_at;
82
+ const date = published_at || created_at || updated_at;
83
83
  let content = '';
84
84
  if (title) {
85
85
  content += `<div class="${className}__item-title">${title}</div>`;
@@ -98,14 +98,22 @@ function articleInfoBlock(_ref3, _ref4) {
98
98
  // helpers //
99
99
  function renderTagPair(_ref5, _ref6) {
100
100
  let {
101
- className
101
+ className,
102
+ options = {}
102
103
  } = _ref5;
103
104
  let {
104
105
  product_id,
105
106
  url
106
107
  } = _ref6;
108
+ const {
109
+ link = {}
110
+ } = options;
111
+ const {
112
+ target = '_blank',
113
+ rel = 'noopener'
114
+ } = link; // TODO: other properties
107
115
  const tag = url ? 'a' : 'div';
108
- const urlAttrs = url ? `href="${url}" target="_blank" rel="noopener"` : '';
116
+ const urlAttrs = url ? `href="${url}" target="${target}" rel="${rel}"` : '';
109
117
  const productAttrs = product_id ? `${_constants.ATTR_DATA_MISO_PRODUCT_ID}="${product_id}"` : '';
110
118
  return [`<${tag} class="${className}__item-body" data-role="item" ${productAttrs} ${urlAttrs}>`, `</${tag}>`];
111
119
  }
@@ -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.9.1-beta.2';
7
+ var _default = exports.default = '1.9.1-beta.4';
@@ -10,8 +10,7 @@ var _options = require("./options.js");
10
10
  var _index = require("../actor/index.js");
11
11
  var _constants = require("../constants.js");
12
12
  var _index2 = require("../layout/index.js");
13
- const _excluded = ["layouts"],
14
- _excluded2 = ["q"];
13
+ const _excluded = ["q"];
15
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
15
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
17
16
  const DEFAULT_API_OPTIONS = Object.freeze({
@@ -26,7 +25,9 @@ const DEFAULT_API_OPTIONS = Object.freeze({
26
25
  }
27
26
  });
28
27
  const DEFAULT_LAYOUTS = Object.freeze({
29
- [_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type],
28
+ [_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type, {
29
+ placeholder: 'Ask a question'
30
+ }],
30
31
  [_constants.ROLE.QUESTION]: [_index2.TextLayout.type, {
31
32
  tag: 'h2'
32
33
  }],
@@ -61,26 +62,13 @@ const DEFAULT_OPTIONS = Object.freeze({
61
62
  layouts: DEFAULT_LAYOUTS,
62
63
  trackers: DEFAULT_TRACKERS
63
64
  });
64
- function mergeDefaults(_ref, parentQuestionId) {
65
- let {
66
- layouts
67
- } = _ref,
68
- defaults = _objectWithoutPropertiesLoose(_ref, _excluded);
69
- return Object.assign({}, defaults, {
70
- layouts: (0, _options.mergeLayoutsOptions)(layouts, {
71
- [_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type, {
72
- placeholder: parentQuestionId ? 'Ask a follow-up question' : 'Ask anything'
73
- }]
74
- })
75
- });
76
- }
77
65
  class Ask extends _base.default {
78
66
  constructor(context, parentQuestionId) {
79
67
  super({
80
68
  name: 'ask',
81
69
  context,
82
70
  roles: Object.keys(DEFAULT_LAYOUTS),
83
- defaults: mergeDefaults(DEFAULT_OPTIONS, parentQuestionId)
71
+ defaults: DEFAULT_OPTIONS
84
72
  });
85
73
  this._context = context;
86
74
  (0, _commons.defineValues)(this, {
@@ -145,11 +133,11 @@ class Ask extends _base.default {
145
133
  }
146
134
  }
147
135
  query() {
148
- let _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
136
+ let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
149
137
  let {
150
138
  q: question
151
- } = _ref2,
152
- payload = _objectWithoutPropertiesLoose(_ref2, _excluded2);
139
+ } = _ref,
140
+ payload = _objectWithoutPropertiesLoose(_ref, _excluded);
153
141
  payload = Object.assign({}, payload, {
154
142
  question
155
143
  });
@@ -220,12 +208,12 @@ class Ask extends _base.default {
220
208
  this._context._byQid.set(questionId, this);
221
209
  }
222
210
  }
223
- _onAnswerViewUpdate(_ref3) {
211
+ _onAnswerViewUpdate(_ref2) {
224
212
  let {
225
213
  session,
226
214
  status,
227
215
  ongoing
228
- } = _ref3;
216
+ } = _ref2;
229
217
  if (status === _constants.STATUS.INITIAL) {
230
218
  return;
231
219
  }
@@ -257,10 +245,10 @@ class Ask extends _base.default {
257
245
  }))
258
246
  });
259
247
  }
260
- _onCitationClick(_ref4) {
248
+ _onCitationClick(_ref3) {
261
249
  let {
262
250
  index
263
- } = _ref4;
251
+ } = _ref3;
264
252
  const {
265
253
  value
266
254
  } = this.states[_index.fields.data()] || {};
@@ -21,7 +21,9 @@ const DEFAULT_LAYOUTS = Object.freeze({
21
21
  [_constants.ROLE.RELATED_QUESTIONS]: [_index2.ListLayout.type, {
22
22
  itemType: 'question'
23
23
  }],
24
- [_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type]
24
+ [_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type, {
25
+ placeholder: 'Ask a question'
26
+ }]
25
27
  });
26
28
  const DEFAULT_TRACKERS = Object.freeze({
27
29
  [_constants.ROLE.RELATED_QUESTIONS]: {}
@@ -17,8 +17,8 @@ exports.normalizeTrackers = normalizeTrackers;
17
17
  var _commons = require("@miso.ai/commons");
18
18
  var _constants = require("../constants.js");
19
19
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
20
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
21
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
20
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
21
+ 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); }
22
22
  // normalize //
23
23
  function normalizeApiOptions() {
24
24
  let [name, payload] = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
@@ -157,7 +157,13 @@ function mergeLayoutOptions(base, overrides) {
157
157
  if (overrides[0] === false) {
158
158
  return overrides;
159
159
  }
160
- return base && overrides ? [overrides[0] || base[0], Object.assign({}, base[1], overrides[1])] : overrides || base;
160
+ return base && overrides ? [overrides[0] || base[0], mergeLayoutParameters(base[1], overrides[1])] : overrides || base;
161
+ }
162
+ function mergeLayoutParameters(base, overrides) {
163
+ return Object.assign({}, base, overrides, {
164
+ link: Object.assign({}, base && base.link, overrides && overrides.link),
165
+ templates: Object.assign({}, base && base.templates, overrides && overrides.templates)
166
+ });
161
167
  }
162
168
  function mergeDataProcessorOptions() {
163
169
  for (var _len3 = arguments.length, optionsList = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@miso.ai/commons": "1.9.1-beta.2"
29
+ "@miso.ai/commons": "1.9.1-beta.4"
30
30
  },
31
- "version": "1.9.1-beta.2"
31
+ "version": "1.9.1-beta.4"
32
32
  }
@@ -1,6 +1,7 @@
1
1
  import { CLASS_PREFIX } from './constants.js';
2
2
  import * as DEFAULT_PHRASES from './phrases.js';
3
3
 
4
+ // TODO: rename classPrefix -> rootClass?
4
5
  // TODO: placeholder
5
6
 
6
7
  export function root(options = {}) {
@@ -59,7 +59,7 @@ function productInfoBlock({ className }, { title, snippet, description, sale_pri
59
59
  }
60
60
 
61
61
  function articleInfoBlock({ className, templates }, { title, snippet, description, created_at, updated_at, published_at }) {
62
- const date = updated_at || published_at || created_at;
62
+ const date = published_at || created_at || updated_at;
63
63
  let content = '';
64
64
  if (title) {
65
65
  content += `<div class="${className}__item-title">${title}</div>`;
@@ -76,9 +76,11 @@ function articleInfoBlock({ className, templates }, { title, snippet, descriptio
76
76
  }
77
77
 
78
78
  // helpers //
79
- function renderTagPair({ className }, { product_id, url }) {
79
+ function renderTagPair({ className, options = {} }, { product_id, url }) {
80
+ const { link = {} } = options;
81
+ const { target = '_blank', rel = 'noopener' } = link; // TODO: other properties
80
82
  const tag = url ? 'a' : 'div';
81
- const urlAttrs = url ? `href="${url}" target="_blank" rel="noopener"` : '';
83
+ const urlAttrs = url ? `href="${url}" target="${target}" rel="${rel}"` : '';
82
84
  const productAttrs = product_id ? `${ATTR_DATA_MISO_PRODUCT_ID}="${product_id}"` : '';
83
85
  return [`<${tag} class="${className}__item-body" data-role="item" ${productAttrs} ${urlAttrs}>`, `</${tag}>`];
84
86
  }
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.9.1-beta.2';
1
+ export default '1.9.1-beta.4';
@@ -1,6 +1,6 @@
1
1
  import { defineValues, trimObj, API } from '@miso.ai/commons';
2
2
  import Workflow from './base.js';
3
- import { mergeApiOptions, mergeLayoutsOptions } from './options.js';
3
+ import { mergeApiOptions } from './options.js';
4
4
  import { fields, FeedbackActor } from '../actor/index.js';
5
5
  import { ROLE, STATUS } from '../constants.js';
6
6
  import { SearchBoxLayout, OptionListLayout, ListLayout, TextLayout, TypewriterLayout, FeedbackLayout } from '../layout/index.js';
@@ -18,7 +18,7 @@ const DEFAULT_API_OPTIONS = Object.freeze({
18
18
  });
19
19
 
20
20
  const DEFAULT_LAYOUTS = Object.freeze({
21
- [ROLE.QUERY]: [SearchBoxLayout.type],
21
+ [ROLE.QUERY]: [SearchBoxLayout.type, { placeholder: 'Ask a question' }],
22
22
  [ROLE.QUESTION]: [TextLayout.type, { tag: 'h2' }],
23
23
  [ROLE.ANSWER]: TypewriterLayout.type,
24
24
  [ROLE.FEEDBACK]: FeedbackLayout.type,
@@ -44,17 +44,6 @@ const DEFAULT_OPTIONS = Object.freeze({
44
44
  trackers: DEFAULT_TRACKERS,
45
45
  });
46
46
 
47
- function mergeDefaults({ layouts, ...defaults }, parentQuestionId) {
48
- return {
49
- ...defaults,
50
- layouts: mergeLayoutsOptions(layouts, {
51
- [ROLE.QUERY]: [SearchBoxLayout.type, {
52
- placeholder: parentQuestionId ? 'Ask a follow-up question' : 'Ask anything',
53
- }],
54
- }),
55
- };
56
- }
57
-
58
47
  export default class Ask extends Workflow {
59
48
 
60
49
  constructor(context, parentQuestionId) {
@@ -62,7 +51,7 @@ export default class Ask extends Workflow {
62
51
  name: 'ask',
63
52
  context,
64
53
  roles: Object.keys(DEFAULT_LAYOUTS),
65
- defaults: mergeDefaults(DEFAULT_OPTIONS, parentQuestionId),
54
+ defaults: DEFAULT_OPTIONS,
66
55
  });
67
56
  this._context = context;
68
57
  defineValues(this, { parentQuestionId });
@@ -12,7 +12,7 @@ const DEFAULT_API_OPTIONS = Object.freeze({
12
12
 
13
13
  const DEFAULT_LAYOUTS = Object.freeze({
14
14
  [ROLE.RELATED_QUESTIONS]: [ListLayout.type, { itemType: 'question' }],
15
- [ROLE.QUERY]: [SearchBoxLayout.type],
15
+ [ROLE.QUERY]: [SearchBoxLayout.type, { placeholder: 'Ask a question' }],
16
16
  });
17
17
 
18
18
  const DEFAULT_TRACKERS = Object.freeze({
@@ -130,7 +130,16 @@ function mergeLayoutOptions(base, overrides) {
130
130
  if (overrides[0] === false) {
131
131
  return overrides;
132
132
  }
133
- return base && overrides ? [overrides[0] || base[0], { ...base[1], ...overrides[1] }] : (overrides || base);
133
+ return base && overrides ? [overrides[0] || base[0], mergeLayoutParameters(base[1], overrides[1])] : (overrides || base);
134
+ }
135
+
136
+ function mergeLayoutParameters(base, overrides) {
137
+ return {
138
+ ...base,
139
+ ...overrides,
140
+ link: { ...(base && base.link), ...(overrides && overrides.link) },
141
+ templates: { ...(base && base.templates), ...(overrides && overrides.templates) },
142
+ };
134
143
  }
135
144
 
136
145
  export function mergeDataProcessorOptions(...optionsList) {