@miso.ai/client-sdk-ui 1.11.5 → 1.11.6-beta.1

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 (117) hide show
  1. package/dist/cjs/actor/data.js +5 -7
  2. package/dist/cjs/actor/feedback.js +1 -2
  3. package/dist/cjs/actor/filters.js +20 -21
  4. package/dist/cjs/actor/hub.js +34 -8
  5. package/dist/cjs/actor/index.js +1 -2
  6. package/dist/cjs/actor/interactions.js +5 -7
  7. package/dist/cjs/actor/sessions.js +1 -2
  8. package/dist/cjs/actor/tracker.js +9 -12
  9. package/dist/cjs/actor/view.js +11 -20
  10. package/dist/cjs/actor/views.js +16 -21
  11. package/dist/cjs/affiliation/index.js +1 -2
  12. package/dist/cjs/combo/ask/elements.js +3 -4
  13. package/dist/cjs/combo/ask/index.js +1 -2
  14. package/dist/cjs/combo/ask/options.js +2 -6
  15. package/dist/cjs/defaults/ask/controls.js +1 -2
  16. package/dist/cjs/defaults/ask/index.js +1 -2
  17. package/dist/cjs/defaults/ask/templates.js +3 -6
  18. package/dist/cjs/defaults/common/templates.js +30 -41
  19. package/dist/cjs/defaults/hybrid-search/answer-box.js +9 -11
  20. package/dist/cjs/defaults/hybrid-search/controls.js +1 -2
  21. package/dist/cjs/defaults/hybrid-search/index.js +1 -2
  22. package/dist/cjs/defaults/hybrid-search/templates.js +2 -4
  23. package/dist/cjs/defaults/index.js +1 -2
  24. package/dist/cjs/element/container/miso-explore.js +7 -7
  25. package/dist/cjs/element/container/miso-hybrid-search.js +3 -3
  26. package/dist/cjs/element/container/miso-recommendation.js +3 -38
  27. package/dist/cjs/element/container/miso-search.js +3 -3
  28. package/dist/cjs/element/container/miso-unit.js +52 -0
  29. package/dist/cjs/element/index.js +1 -2
  30. package/dist/cjs/element/role/miso-component.js +3 -4
  31. package/dist/cjs/element/utils.js +6 -9
  32. package/dist/cjs/layout/affiliation/affiliation.js +4 -6
  33. package/dist/cjs/layout/banner/banner.js +1 -2
  34. package/dist/cjs/layout/button/more-button.js +1 -2
  35. package/dist/cjs/layout/container/container.js +7 -12
  36. package/dist/cjs/layout/error/error.js +1 -2
  37. package/dist/cjs/layout/input/facets.js +28 -41
  38. package/dist/cjs/layout/input/option-list.js +1 -2
  39. package/dist/cjs/layout/input/search-box.js +31 -40
  40. package/dist/cjs/layout/input/select.js +1 -2
  41. package/dist/cjs/layout/list/cards.js +1 -2
  42. package/dist/cjs/layout/list/carousel.js +1 -2
  43. package/dist/cjs/layout/list/collection.js +12 -16
  44. package/dist/cjs/layout/list/gallery.js +18 -26
  45. package/dist/cjs/layout/list/list.js +1 -2
  46. package/dist/cjs/layout/mixin/swipeable.js +3 -4
  47. package/dist/cjs/layout/mixin/trackable.js +3 -6
  48. package/dist/cjs/layout/progressive.js +1 -2
  49. package/dist/cjs/layout/radio/feedback.js +6 -8
  50. package/dist/cjs/layout/radio/radio.js +5 -6
  51. package/dist/cjs/layout/raf.js +6 -10
  52. package/dist/cjs/layout/template.js +7 -10
  53. package/dist/cjs/layout/templates.js +51 -71
  54. package/dist/cjs/layout/text/text.js +6 -8
  55. package/dist/cjs/layout/text/typewriter/index.js +14 -18
  56. package/dist/cjs/layout/text/typewriter/plaintext.js +8 -10
  57. package/dist/cjs/layout/text/typewriter/utils.js +12 -15
  58. package/dist/cjs/plugin.js +13 -3
  59. package/dist/cjs/source.js +6 -7
  60. package/dist/cjs/util/dom.js +1 -2
  61. package/dist/cjs/util/proxy.js +3 -4
  62. package/dist/cjs/util/trackers.js +1 -3
  63. package/dist/cjs/util/viewables.js +1 -2
  64. package/dist/cjs/version.js +1 -1
  65. package/dist/cjs/workflow/answer-based.js +17 -24
  66. package/dist/cjs/workflow/ask.js +1 -2
  67. package/dist/cjs/workflow/asks.js +4 -6
  68. package/dist/cjs/workflow/autocomplete.js +3 -4
  69. package/dist/cjs/workflow/base.js +56 -54
  70. package/dist/cjs/workflow/explore.js +18 -22
  71. package/dist/cjs/workflow/explores.js +18 -0
  72. package/dist/cjs/workflow/hybrid-search-answer.js +4 -3
  73. package/dist/cjs/workflow/index.js +3 -3
  74. package/dist/cjs/workflow/options/api.js +2 -6
  75. package/dist/cjs/workflow/options/auto-query.js +2 -4
  76. package/dist/cjs/workflow/options/configurable.js +2 -6
  77. package/dist/cjs/workflow/options/data-processor.js +1 -4
  78. package/dist/cjs/workflow/options/filters.js +1 -4
  79. package/dist/cjs/workflow/options/interactions.js +1 -4
  80. package/dist/cjs/workflow/options/layouts.js +2 -6
  81. package/dist/cjs/workflow/options/options.js +5 -8
  82. package/dist/cjs/workflow/options/pagination.js +1 -4
  83. package/dist/cjs/workflow/options/roles.js +1 -3
  84. package/dist/cjs/workflow/options/trackers.js +6 -16
  85. package/dist/cjs/workflow/processors.js +16 -22
  86. package/dist/cjs/workflow/recommendation.js +9 -52
  87. package/dist/cjs/workflow/recommendations.js +3 -23
  88. package/dist/cjs/workflow/search-based.js +12 -8
  89. package/dist/cjs/workflow/search.js +1 -5
  90. package/dist/cjs/workflow/unit.js +58 -0
  91. package/dist/cjs/workflow/units.js +37 -0
  92. package/dist/cjs/workflow/use-link.js +3 -6
  93. package/package.json +2 -2
  94. package/src/actor/filters.js +4 -2
  95. package/src/actor/hub.js +26 -5
  96. package/src/element/container/miso-explore.js +8 -8
  97. package/src/element/container/miso-hybrid-search.js +4 -4
  98. package/src/element/container/miso-recommendation.js +3 -45
  99. package/src/element/container/miso-search.js +4 -4
  100. package/src/element/container/miso-unit.js +55 -0
  101. package/src/layout/input/search-box.js +1 -1
  102. package/src/layout/radio/radio.js +1 -0
  103. package/src/layout/templates.js +3 -2
  104. package/src/plugin.js +15 -2
  105. package/src/version.js +1 -1
  106. package/src/workflow/autocomplete.js +1 -0
  107. package/src/workflow/base.js +33 -23
  108. package/src/workflow/explore.js +13 -12
  109. package/src/workflow/explores.js +14 -0
  110. package/src/workflow/hybrid-search-answer.js +1 -1
  111. package/src/workflow/index.js +1 -1
  112. package/src/workflow/processors.js +2 -2
  113. package/src/workflow/recommendation.js +9 -47
  114. package/src/workflow/recommendations.js +3 -23
  115. package/src/workflow/search-based.js +4 -0
  116. package/src/workflow/unit.js +52 -0
  117. package/src/workflow/units.js +37 -0
@@ -5,35 +5,34 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _commons = require("@miso.ai/commons");
8
- var _base = _interopRequireDefault(require("./base.js"));
8
+ var _unit = _interopRequireDefault(require("./unit.js"));
9
9
  var _index = require("../layout/index.js");
10
10
  var _constants = require("../constants.js");
11
11
  var _index2 = require("./options/index.js");
12
- var _processors = require("./processors.js");
13
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_API_OPTIONS, {
13
+ const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _unit.default.DEFAULT_API_OPTIONS, {
15
14
  group: _commons.API.GROUP.RECOMMENDATION,
16
15
  name: _commons.API.NAME.USER_TO_PRODUCTS,
17
- payload: Object.assign({}, _base.default.DEFAULT_API_OPTIONS.payload, {
16
+ payload: Object.assign({}, _unit.default.DEFAULT_API_OPTIONS.payload, {
18
17
  fl: ['*']
19
18
  })
20
19
  }));
21
- const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LAYOUTS, {
20
+ const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _unit.default.DEFAULT_LAYOUTS, {
22
21
  [_constants.ROLE.PRODUCTS]: _index.ListLayout.type
23
22
  }));
24
- const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _base.default.DEFAULT_TRACKERS, {
23
+ const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _unit.default.DEFAULT_TRACKERS, {
25
24
  [_constants.ROLE.PRODUCTS]: _index2.DEFAULT_TRACKER_OPTIONS
26
25
  }));
27
- const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_OPTIONS, {
26
+ const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _unit.default.DEFAULT_OPTIONS, {
28
27
  api: DEFAULT_API_OPTIONS,
29
28
  layouts: DEFAULT_LAYOUTS,
30
29
  trackers: DEFAULT_TRACKERS
31
30
  }));
32
- const ROLES_OPTIONS = (0, _index2.mergeRolesOptions)(_base.default.ROLES_OPTIONS, {
31
+ const ROLES_OPTIONS = (0, _index2.mergeRolesOptions)(_unit.default.ROLES_OPTIONS, {
33
32
  main: _constants.ROLE.PRODUCTS,
34
33
  members: Object.keys(DEFAULT_LAYOUTS)
35
34
  });
36
- class Recommendation extends _base.default {
35
+ class Recommendation extends _unit.default {
37
36
  constructor(context, id) {
38
37
  super({
39
38
  name: 'recommendation',
@@ -43,19 +42,6 @@ class Recommendation extends _base.default {
43
42
  id
44
43
  });
45
44
  }
46
- _initProperties(args) {
47
- super._initProperties(args);
48
- const {
49
- id
50
- } = args;
51
- (0, _commons.defineValues)(this, {
52
- id
53
- });
54
- }
55
- _initSession(args) {
56
- this._context._members.set(args.id, this);
57
- super._initSession(args);
58
- }
59
45
 
60
46
  // lifecycle //
61
47
  start() {
@@ -63,38 +49,9 @@ class Recommendation extends _base.default {
63
49
  this._request();
64
50
  return this;
65
51
  }
66
- notifyViewUpdate() {
67
- let role = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.ROLE.PRODUCTS;
68
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
69
- args[_key - 1] = arguments[_key];
70
- }
52
+ notifyViewUpdate(role = _constants.ROLE.PRODUCTS, ...args) {
71
53
  super.notifyViewUpdate(role, ...args);
72
54
  return this;
73
55
  }
74
-
75
- // interactions //
76
- _defaultProcessInteraction(payload, args) {
77
- payload = super._defaultProcessInteraction(payload, args);
78
- payload = this._writeUnitIdToInteraction(payload, args);
79
- return payload;
80
- }
81
- _writeUnitIdToInteraction(payload) {
82
- const unit_id = this.id;
83
- const unit_instance_uuid = this.uuid;
84
- return (0, _processors.mergeInteraction)(payload, {
85
- context: {
86
- custom_context: {
87
- unit_id,
88
- unit_instance_uuid
89
- }
90
- }
91
- });
92
- }
93
-
94
- // destroy //
95
- _destroy(options) {
96
- this._context._members.delete(this.id);
97
- super._destroy(options);
98
- }
99
56
  }
100
57
  exports.default = Recommendation;
@@ -4,35 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _constants = require("../constants.js");
8
- var _context = _interopRequireDefault(require("./context.js"));
7
+ var _units = _interopRequireDefault(require("./units.js"));
9
8
  var _recommendation = _interopRequireDefault(require("./recommendation.js"));
10
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- class Recommendations extends _context.default {
10
+ class Recommendations extends _units.default {
12
11
  constructor(plugin, client) {
13
12
  super('recommendations', plugin, client);
14
- this._members = new Map();
15
13
  }
16
- workflows() {
17
- return [...this._members.values()];
18
- }
19
- create() {
20
- let unitId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.DEFAULT_UNIT_ID;
21
- if (this._members.has(unitId)) {
22
- throw new Error(`Unit already exists: ${unitId}`);
23
- }
14
+ _create(unitId) {
24
15
  return new _recommendation.default(this, unitId);
25
16
  }
26
- has() {
27
- let unitId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.DEFAULT_UNIT_ID;
28
- return this._members.has(unitId);
29
- }
30
- get() {
31
- let unitId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.DEFAULT_UNIT_ID;
32
- if (typeof unitId !== 'string') {
33
- throw new Error(`Required unit ID to be a string: ${unitId}`);
34
- }
35
- return this._members.get(unitId) || new _recommendation.default(this, unitId);
36
- }
37
17
  }
38
18
  exports.default = Recommendations;
@@ -80,8 +80,7 @@ class SearchBasedWorkflow extends _base.default {
80
80
  }
81
81
 
82
82
  // query //
83
- autoQuery() {
84
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
83
+ autoQuery(options = {}) {
85
84
  _index3.autoQuery.call(this, options);
86
85
  }
87
86
  query(args) {
@@ -94,6 +93,11 @@ class SearchBasedWorkflow extends _base.default {
94
93
  // keep track of the query args for refine and more calls
95
94
  this._queryArgs = args;
96
95
 
96
+ // reset filters view
97
+ this._views.filters.reset({
98
+ silent: true
99
+ });
100
+
97
101
  // start a new session
98
102
  this.restart();
99
103
 
@@ -120,6 +124,8 @@ class SearchBasedWorkflow extends _base.default {
120
124
  payload
121
125
  });
122
126
  }
127
+
128
+ // TODO: expose API
123
129
  _more() {
124
130
  // if still loading, complain
125
131
  if (this.status !== _constants.STATUS.READY) {
@@ -193,8 +199,7 @@ class SearchBasedWorkflow extends _base.default {
193
199
  })
194
200
  });
195
201
  }
196
- _processPayloadForMoreRequest() {
197
- let payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
202
+ _processPayloadForMoreRequest(payload = {}) {
198
203
  const data = this._hub.states[_index.fields.data()];
199
204
  const {
200
205
  [this._roles.main]: items = []
@@ -244,10 +249,9 @@ class SearchBasedWorkflow extends _base.default {
244
249
  }
245
250
 
246
251
  // view actions //
247
- _handleSortSelect() {
248
- let {
249
- value
250
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
252
+ _handleSortSelect({
253
+ value
254
+ } = {}) {
251
255
  if (!value) {
252
256
  return;
253
257
  }
@@ -49,11 +49,7 @@ class Search extends _searchBased.default {
49
49
  super._initProperties(args);
50
50
  this._initAutocomplete(args);
51
51
  }
52
- notifyViewUpdate() {
53
- let role = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.ROLE.PRODUCTS;
54
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
55
- args[_key - 1] = arguments[_key];
56
- }
52
+ notifyViewUpdate(role = _constants.ROLE.PRODUCTS, ...args) {
57
53
  super.notifyViewUpdate(role, ...args);
58
54
  return this;
59
55
  }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _commons = require("@miso.ai/commons");
8
+ var _base = _interopRequireDefault(require("./base.js"));
9
+ var _processors = require("./processors.js");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ class UnitWorkflow extends _base.default {
12
+ _initProperties(args) {
13
+ super._initProperties(args);
14
+ const {
15
+ id
16
+ } = args;
17
+ (0, _commons.defineValues)(this, {
18
+ id
19
+ });
20
+ }
21
+ _initSession(args) {
22
+ this._context._members.set(args.id, this);
23
+ super._initSession(args);
24
+ }
25
+
26
+ // interactions //
27
+ _defaultProcessInteraction(payload, args) {
28
+ payload = super._defaultProcessInteraction(payload, args);
29
+ payload = this._writeUnitIdToInteraction(payload, args);
30
+ return payload;
31
+ }
32
+ _writeUnitIdToInteraction(payload) {
33
+ const unit_id = this.id;
34
+ const unit_instance_uuid = this.uuid;
35
+ return (0, _processors.mergeInteraction)(payload, {
36
+ context: {
37
+ custom_context: {
38
+ unit_id,
39
+ unit_instance_uuid
40
+ }
41
+ }
42
+ });
43
+ }
44
+
45
+ // destroy //
46
+ _destroy(options) {
47
+ this._context._members.delete(this.id);
48
+ super._destroy(options);
49
+ }
50
+ }
51
+ exports.default = UnitWorkflow;
52
+ Object.assign(UnitWorkflow, {
53
+ DEFAULT_API_OPTIONS: _base.default.DEFAULT_API_OPTIONS,
54
+ DEFAULT_LAYOUTS: _base.default.DEFAULT_LAYOUTS,
55
+ DEFAULT_TRACKERS: _base.default.DEFAULT_TRACKERS,
56
+ DEFAULT_OPTIONS: _base.default.DEFAULT_OPTIONS,
57
+ ROLES_OPTIONS: _base.default.ROLES_OPTIONS
58
+ });
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _constants = require("../constants.js");
8
+ var _context = _interopRequireDefault(require("./context.js"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ class UnitWorkflowContext extends _context.default {
11
+ constructor(name, plugin, client) {
12
+ super(name, plugin, client);
13
+ this._members = new Map();
14
+ }
15
+ workflows() {
16
+ return [...this._members.values()];
17
+ }
18
+ create(unitId = _constants.DEFAULT_UNIT_ID) {
19
+ if (this._members.has(unitId)) {
20
+ throw new Error(`Unit already exists: ${unitId}`);
21
+ }
22
+ return this._create(unitId);
23
+ }
24
+ has(unitId = _constants.DEFAULT_UNIT_ID) {
25
+ return this._members.has(unitId);
26
+ }
27
+ get(unitId = _constants.DEFAULT_UNIT_ID) {
28
+ if (typeof unitId !== 'string') {
29
+ throw new Error(`Required unit ID to be a string: ${unitId}`);
30
+ }
31
+ return this._members.get(unitId) || this._create(unitId);
32
+ }
33
+ _create(unitId) {
34
+ throw new Error('Not implemented');
35
+ }
36
+ }
37
+ exports.default = UnitWorkflowContext;
@@ -12,16 +12,14 @@ function enableUseLink(prototype) {
12
12
  (0, _commons.mixin)(prototype, UseLinkMixin.prototype);
13
13
  }
14
14
  class UseLinkMixin {
15
- useLink(fn) {
16
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
15
+ useLink(fn, options = {}) {
17
16
  if (typeof fn !== 'function' && fn !== false) {
18
17
  throw new Error('useLink(fn) expects fn to be a function or false');
19
18
  }
20
19
  this._linkFn = fn ? [fn, options] : false;
21
20
  return this;
22
21
  }
23
- _submitToPage() {
24
- let args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
22
+ _submitToPage(args = {}) {
25
23
  if (!this._linkFn) {
26
24
  return;
27
25
  }
@@ -36,8 +34,7 @@ class UseLinkMixin {
36
34
  window.open(url, target, windowFeatures);
37
35
  }
38
36
  }
39
- _getSubmitUrl() {
40
- let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
37
+ _getSubmitUrl(_ref = {}) {
41
38
  let {
42
39
  q
43
40
  } = _ref,
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.11.5"
29
+ "@miso.ai/commons": "1.11.6-beta.1"
30
30
  },
31
- "version": "1.11.5"
31
+ "version": "1.11.6-beta.1"
32
32
  }
@@ -67,10 +67,12 @@ export default class Filters {
67
67
  this._events.emit('update', { updates, states, oldStates });
68
68
  }
69
69
 
70
- reset() {
71
- const oldStates = this.states;
70
+ reset({ silent = false } = {}) {
71
+ // TODO: review this
72
+ const oldStates = this._states;
72
73
  this._states = undefined;
73
74
  const states = this._getStates();
75
+ this._hub.update(fields.filters(), states, { silent });
74
76
  this._events.emit('reset', { states, oldStates });
75
77
  }
76
78
 
package/src/actor/hub.js CHANGED
@@ -2,8 +2,9 @@ import { defineValues, EventEmitter } from '@miso.ai/commons';
2
2
 
3
3
  export default class Hub {
4
4
 
5
- constructor() {
5
+ constructor(options = {}) {
6
6
  (this._events = new EventEmitter())._injectSubscribeInterface(this);
7
+ this._options = options;
7
8
  this._states = {};
8
9
  defineValues(this, {
9
10
  states: new Proxy(this._states, {
@@ -12,15 +13,35 @@ export default class Hub {
12
13
  });
13
14
  }
14
15
 
15
- update(name, state, { silent = false } = {}) {
16
+ update(name, state, options = {}) {
16
17
  this._states[name] = Object.freeze(state);
17
- if (!silent) {
18
+ const event = Object.freeze({ action: 'update', name, state, ...options });
19
+ // callback after update, before emit
20
+ if (typeof this._options.onUpdate === 'function') {
21
+ this._options.onUpdate(event);
22
+ }
23
+ // emit
24
+ if (!options.silent) {
18
25
  this._events.emit(name, state);
19
26
  }
27
+ // callback after emit
28
+ if (typeof this._options.onEmit === 'function') {
29
+ this._options.onEmit(event);
30
+ }
20
31
  }
21
32
 
22
- trigger(name, event) {
23
- this._events.emit(name, event);
33
+ trigger(name, state) {
34
+ const event = Object.freeze({ action: 'trigger', name, state });
35
+ // callback before emit
36
+ if (typeof this._options.onUpdate === 'function') {
37
+ this._options.onUpdate(event);
38
+ }
39
+ // emit
40
+ this._events.emit(name, state);
41
+ // callback after emit
42
+ if (typeof this._options.onEmit === 'function') {
43
+ this._options.onEmit(event);
44
+ }
24
45
  }
25
46
 
26
47
  }
@@ -1,19 +1,19 @@
1
- import MisoContainerElement from './miso-container.js';
1
+ import MisoUnitElement from './miso-unit.js';
2
2
 
3
3
  const TAG_NAME = 'miso-explore';
4
4
 
5
- export default class MisoExploreElement extends MisoContainerElement {
6
-
7
- static get observedAttributes() {
8
- return MisoContainerElement.observedAttributes;
9
- }
5
+ export default class MisoExploreElement extends MisoUnitElement {
10
6
 
11
7
  static get tagName() {
12
8
  return TAG_NAME;
13
9
  }
14
10
 
15
- _getWorkflow(client) {
16
- return client.ui.explore;
11
+ static get observedAttributes() {
12
+ return MisoUnitElement.observedAttributes;
13
+ }
14
+
15
+ _getWorkflowByUnitId(client, unitId) {
16
+ return client.ui.explores.get(unitId);
17
17
  }
18
18
 
19
19
  }
@@ -4,14 +4,14 @@ const TAG_NAME = 'miso-hybrid-search';
4
4
 
5
5
  export default class MisoHybridSearchElement extends MisoContainerElement {
6
6
 
7
- static get observedAttributes() {
8
- return MisoContainerElement.observedAttributes;
9
- }
10
-
11
7
  static get tagName() {
12
8
  return TAG_NAME;
13
9
  }
14
10
 
11
+ static get observedAttributes() {
12
+ return MisoContainerElement.observedAttributes;
13
+ }
14
+
15
15
  _getWorkflow(client) {
16
16
  return client.ui.hybridSearch;
17
17
  }
@@ -1,61 +1,19 @@
1
- import MisoContainerElement from './miso-container.js';
1
+ import MisoUnitElement from './miso-unit.js';
2
2
 
3
3
  const TAG_NAME = 'miso-recommendation';
4
4
 
5
- const ATTR_UNIT_ID = 'unit-id';
6
- const OBSERVED_ATTRIBUTES = Object.freeze([
7
- ...MisoContainerElement.observedAttributes,
8
- ATTR_UNIT_ID,
9
- ]);
10
-
11
- export default class MisoRecommendationElement extends MisoContainerElement {
5
+ export default class MisoRecommendationElement extends MisoUnitElement {
12
6
 
13
7
  static get tagName() {
14
8
  return TAG_NAME;
15
9
  }
16
10
 
17
11
  static get observedAttributes() {
18
- return OBSERVED_ATTRIBUTES;
19
- }
20
-
21
- _getWorkflow(client) {
22
- return this._getWorkflowByUnitId(client, this.unitId);
12
+ return MisoUnitElement.observedAttributes;
23
13
  }
24
14
 
25
15
  _getWorkflowByUnitId(client, unitId) {
26
16
  return client.ui.recommendations.get(unitId);
27
17
  }
28
18
 
29
- // properties //
30
- get unitId() {
31
- return this.getAttribute(ATTR_UNIT_ID) || undefined;
32
- }
33
-
34
- set unitId(value) {
35
- value = value && `${value}`;
36
- if (value) {
37
- this.setAttribute(ATTR_UNIT_ID, value);
38
- } else {
39
- this.removeAttribute(ATTR_UNIT_ID);
40
- }
41
- }
42
-
43
- // lifecycle //
44
- attributeChangedCallback(attr, oldValue, newValue) {
45
- switch (attr) {
46
- case ATTR_UNIT_ID:
47
- this._handleUnitIdUpdate(oldValue, newValue);
48
- break;
49
- default:
50
- super.attributeChangedCallback(attr, oldValue, newValue);
51
- }
52
- }
53
-
54
- _handleUnitIdUpdate(oldUnitId, newUnitId) {
55
- if (oldUnitId === newUnitId || !this._client) {
56
- return;
57
- }
58
- this._setWorkflow(this._getWorkflowByUnitId(this._client, newUnitId));
59
- }
60
-
61
19
  }
@@ -4,14 +4,14 @@ const TAG_NAME = 'miso-search';
4
4
 
5
5
  export default class MisoSearchElement extends MisoContainerElement {
6
6
 
7
- static get observedAttributes() {
8
- return MisoContainerElement.observedAttributes;
9
- }
10
-
11
7
  static get tagName() {
12
8
  return TAG_NAME;
13
9
  }
14
10
 
11
+ static get observedAttributes() {
12
+ return MisoContainerElement.observedAttributes;
13
+ }
14
+
15
15
  _getWorkflow(client) {
16
16
  return client.ui.search;
17
17
  }
@@ -0,0 +1,55 @@
1
+ import MisoContainerElement from './miso-container.js';
2
+
3
+ const ATTR_UNIT_ID = 'unit-id';
4
+ const OBSERVED_ATTRIBUTES = Object.freeze([
5
+ ...MisoContainerElement.observedAttributes,
6
+ ATTR_UNIT_ID,
7
+ ]);
8
+
9
+ export default class MisoUnitElement extends MisoContainerElement {
10
+
11
+ static get observedAttributes() {
12
+ return OBSERVED_ATTRIBUTES;
13
+ }
14
+
15
+ _getWorkflow(client) {
16
+ return this._getWorkflowByUnitId(client, this.unitId);
17
+ }
18
+
19
+ _getWorkflowByUnitId(client, unitId) {
20
+ throw new Error('Not implemented');
21
+ }
22
+
23
+ // properties //
24
+ get unitId() {
25
+ return this.getAttribute(ATTR_UNIT_ID) || undefined;
26
+ }
27
+
28
+ set unitId(value) {
29
+ value = value && `${value}`;
30
+ if (value) {
31
+ this.setAttribute(ATTR_UNIT_ID, value);
32
+ } else {
33
+ this.removeAttribute(ATTR_UNIT_ID);
34
+ }
35
+ }
36
+
37
+ // lifecycle //
38
+ attributeChangedCallback(attr, oldValue, newValue) {
39
+ switch (attr) {
40
+ case ATTR_UNIT_ID:
41
+ this._handleUnitIdUpdate(oldValue, newValue);
42
+ break;
43
+ default:
44
+ super.attributeChangedCallback(attr, oldValue, newValue);
45
+ }
46
+ }
47
+
48
+ _handleUnitIdUpdate(oldUnitId, newUnitId) {
49
+ if (oldUnitId === newUnitId || !this._client) {
50
+ return;
51
+ }
52
+ this._setWorkflow(this._getWorkflowByUnitId(this._client, newUnitId));
53
+ }
54
+
55
+ }
@@ -329,7 +329,7 @@ export default class SearchBoxLayout extends TemplateBasedLayout {
329
329
  }
330
330
 
331
331
  async _submit(value) {
332
- if (!value) {
332
+ if (!value || !value.trim()) {
333
333
  return;
334
334
  }
335
335
  this.close();
@@ -50,6 +50,7 @@ export default class RadioLayout extends TemplateBasedLayout {
50
50
  view.hub.on(this._field, () => this._refresh()),
51
51
  proxyElement.on('click', (e) => this._handleClick(e)),
52
52
  ];
53
+ // TODO: it shall not carry the responsibility of setting default value
53
54
  this._defaultValue ? this._select(this._defaultValue, { silent: true }) : this._clear({ silent: true });
54
55
  }
55
56
 
@@ -100,8 +100,9 @@ export function imageInfoBlock(layout, data, meta) {
100
100
  ].join('')}</div>`;
101
101
  }
102
102
 
103
- export function titleBlock({ className }, { title }) {
104
- return title ? `<div class="${className}__item-title">${escapeHtml(title)}</div>` : '';
103
+ export function titleBlock({ className }, { title, _title_with_markups }) {
104
+ const text = _title_with_markups || escapeHtml(title);
105
+ return text ? `<div class="${className}__item-title">${text}</div>` : '';
105
106
  }
106
107
 
107
108
  export function brandBlock({ className }, { brand, brand_logo }) {
package/src/plugin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Component, Resolution, defineAndUpgrade, delegateGetters, defineValues } from '@miso.ai/commons';
2
- import { Asks, HybridSearch, Explore, Search, Recommendations } from './workflow/index.js';
2
+ import { Asks, HybridSearch, Explores, Search, Recommendations } from './workflow/index.js';
3
3
  import { AskCombo } from './combo/index.js';
4
4
  import Layouts from './layouts.js';
5
5
  import * as elements from './element/index.js';
@@ -23,6 +23,7 @@ export default class UiPlugin extends Component {
23
23
  super('ui');
24
24
  this.layouts = new Layouts(this);
25
25
  this._recommendations = new WeakMap();
26
+ this._explores = new WeakMap();
26
27
  this._asks = new WeakMap();
27
28
  this._extensions = new WeakMap();
28
29
  this._ready = new Resolution();
@@ -114,6 +115,14 @@ export default class UiPlugin extends Component {
114
115
  return recommendations;
115
116
  }
116
117
 
118
+ _getExplores(client) {
119
+ let explores = this._explores.get(client);
120
+ if (!explores) {
121
+ this._explores.set(client, explores = new Explores(this, client));
122
+ }
123
+ return explores;
124
+ }
125
+
117
126
  _getAsks(client) {
118
127
  let asks = this._asks.get(client);
119
128
  if (!asks) {
@@ -180,8 +189,12 @@ class Ui {
180
189
  return this._hybridSearch || (this._hybridSearch = new HybridSearch(this._plugin, this._client));
181
190
  }
182
191
 
192
+ get explores() {
193
+ return this._explores || (this._explores = this._plugin._getExplores(this._client));
194
+ }
195
+
183
196
  get explore() {
184
- return this._explore || (this._explore = new Explore(this._plugin, this._client));
197
+ return this.explores.get(); // get default explore unit
185
198
  }
186
199
 
187
200
  get ready() {
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.11.5';
1
+ export default '1.11.6-beta.1';