@miso.ai/client-sdk-ui 1.11.0-beta.1 → 1.11.0-beta.11

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 (118) hide show
  1. package/dist/cjs/actor/data.js +6 -7
  2. package/dist/cjs/actor/feedback.js +6 -39
  3. package/dist/cjs/actor/fields.js +14 -6
  4. package/dist/cjs/actor/hub.js +1 -2
  5. package/dist/cjs/actor/index.js +0 -7
  6. package/dist/cjs/actor/interactions.js +4 -15
  7. package/dist/cjs/actor/sessions.js +2 -33
  8. package/dist/cjs/actor/tracker.js +25 -26
  9. package/dist/cjs/actor/utils.js +0 -49
  10. package/dist/cjs/actor/view.js +40 -40
  11. package/dist/cjs/actor/views.js +32 -8
  12. package/dist/cjs/asset/svgs.js +18 -8
  13. package/dist/cjs/constants.js +18 -19
  14. package/dist/cjs/defaults/hybrid-search/answer-box.js +19 -3
  15. package/dist/cjs/defaults/hybrid-search/phrases.js +5 -5
  16. package/dist/cjs/defaults/hybrid-search/templates.js +37 -9
  17. package/dist/cjs/element/role/index.js +12 -5
  18. package/dist/cjs/element/role/{miso-hits.js → miso-more.js} +4 -4
  19. package/dist/cjs/element/role/miso-total.js +20 -0
  20. package/dist/cjs/layout/affiliation/affiliation.js +0 -3
  21. package/dist/cjs/layout/banner/banner.js +0 -4
  22. package/dist/cjs/layout/button/more-button.js +73 -0
  23. package/dist/cjs/layout/container/container.js +0 -3
  24. package/dist/cjs/layout/error/error.js +0 -4
  25. package/dist/cjs/layout/index.js +7 -0
  26. package/dist/cjs/layout/input/facets.js +5 -5
  27. package/dist/cjs/layout/input/option-list.js +0 -4
  28. package/dist/cjs/layout/input/search-box.js +35 -17
  29. package/dist/cjs/layout/list/cards.js +0 -3
  30. package/dist/cjs/layout/list/carousel.js +0 -3
  31. package/dist/cjs/layout/list/collection.js +22 -7
  32. package/dist/cjs/layout/list/list.js +0 -3
  33. package/dist/cjs/layout/radio/feedback.js +0 -3
  34. package/dist/cjs/layout/radio/radio.js +0 -4
  35. package/dist/cjs/layout/raf.js +4 -2
  36. package/dist/cjs/layout/text/text.js +0 -4
  37. package/dist/cjs/layout/text/typewriter/index.js +0 -3
  38. package/dist/cjs/layout/triggerable.js +79 -0
  39. package/dist/cjs/util/states.js +0 -15
  40. package/dist/cjs/version.js +1 -1
  41. package/dist/cjs/workflow/answer-based.js +109 -111
  42. package/dist/cjs/workflow/ask.js +35 -27
  43. package/dist/cjs/workflow/asks.js +1 -1
  44. package/dist/cjs/workflow/autocompletable.js +33 -0
  45. package/dist/cjs/workflow/autocomplete.js +122 -0
  46. package/dist/cjs/workflow/base.js +169 -102
  47. package/dist/cjs/workflow/explore.js +26 -19
  48. package/dist/cjs/workflow/hybrid-search-answer.js +99 -0
  49. package/dist/cjs/workflow/hybrid-search-results.js +66 -0
  50. package/dist/cjs/workflow/hybrid-search-views.js +122 -0
  51. package/dist/cjs/workflow/hybrid-search.js +98 -103
  52. package/dist/cjs/workflow/options.js +32 -17
  53. package/dist/cjs/workflow/processors.js +191 -17
  54. package/dist/cjs/workflow/recommendation.js +36 -49
  55. package/dist/cjs/workflow/search-based.js +228 -0
  56. package/dist/cjs/workflow/search.js +21 -68
  57. package/package.json +2 -2
  58. package/src/actor/data.js +2 -4
  59. package/src/actor/feedback.js +6 -23
  60. package/src/actor/fields.js +14 -6
  61. package/src/actor/hub.js +1 -2
  62. package/src/actor/index.js +0 -1
  63. package/src/actor/interactions.js +4 -10
  64. package/src/actor/sessions.js +3 -30
  65. package/src/actor/tracker.js +25 -19
  66. package/src/actor/utils.js +0 -47
  67. package/src/actor/view.js +27 -15
  68. package/src/actor/views.js +36 -8
  69. package/src/asset/svgs.js +19 -7
  70. package/src/constants.js +25 -16
  71. package/src/defaults/hybrid-search/answer-box.js +17 -5
  72. package/src/defaults/hybrid-search/phrases.js +4 -4
  73. package/src/defaults/hybrid-search/templates.js +25 -9
  74. package/src/element/role/index.js +2 -1
  75. package/src/element/role/{miso-hits.js → miso-more.js} +3 -3
  76. package/src/element/role/miso-total.js +16 -0
  77. package/src/layout/affiliation/affiliation.js +1 -5
  78. package/src/layout/banner/banner.js +0 -5
  79. package/src/layout/button/more-button.js +69 -0
  80. package/src/layout/container/container.js +1 -5
  81. package/src/layout/error/error.js +0 -5
  82. package/src/layout/index.js +2 -1
  83. package/src/layout/input/facets.js +5 -6
  84. package/src/layout/input/option-list.js +0 -5
  85. package/src/layout/input/search-box.js +29 -19
  86. package/src/layout/list/cards.js +0 -4
  87. package/src/layout/list/carousel.js +0 -4
  88. package/src/layout/list/collection.js +21 -9
  89. package/src/layout/list/list.js +0 -4
  90. package/src/layout/radio/feedback.js +0 -4
  91. package/src/layout/radio/radio.js +0 -5
  92. package/src/layout/raf.js +2 -2
  93. package/src/layout/text/text.js +0 -5
  94. package/src/layout/text/typewriter/index.js +1 -5
  95. package/src/layout/trackable.js +1 -1
  96. package/src/layout/triggerable.js +76 -0
  97. package/src/util/states.js +0 -14
  98. package/src/version.js +1 -1
  99. package/src/workflow/answer-based.js +101 -77
  100. package/src/workflow/ask.js +33 -25
  101. package/src/workflow/asks.js +1 -1
  102. package/src/workflow/autocompletable.js +29 -0
  103. package/src/workflow/autocomplete.js +113 -0
  104. package/src/workflow/base.js +147 -93
  105. package/src/workflow/explore.js +23 -8
  106. package/src/workflow/hybrid-search-answer.js +92 -0
  107. package/src/workflow/hybrid-search-results.js +62 -0
  108. package/src/workflow/hybrid-search-views.js +124 -0
  109. package/src/workflow/hybrid-search.js +102 -73
  110. package/src/workflow/options.js +26 -11
  111. package/src/workflow/processors.js +169 -14
  112. package/src/workflow/recommendation.js +32 -33
  113. package/src/workflow/search-based.js +222 -0
  114. package/src/workflow/search.js +21 -65
  115. package/dist/cjs/actor/autocomplete.js +0 -160
  116. package/dist/cjs/workflow/utils.js +0 -42
  117. package/src/actor/autocomplete.js +0 -133
  118. package/src/workflow/utils.js +0 -29
@@ -58,13 +58,12 @@ class DataActor {
58
58
  session
59
59
  } = this._hub.states;
60
60
  const request = _objectWithoutPropertiesLoose(event, _excluded);
61
- if (!event._skipLoading) {
62
- // emit response to update request
63
- this._emitResponse({
64
- session,
65
- request
66
- });
67
- }
61
+
62
+ // emit response to update request
63
+ this._emitResponse({
64
+ session,
65
+ request
66
+ });
68
67
  try {
69
68
  const {
70
69
  signal
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var fields = _interopRequireWildcard(require("./fields.js"));
8
+ var _constants = require("../constants.js");
8
9
  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); }
9
10
  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; }
10
11
  class FeedbackActor {
@@ -13,45 +14,11 @@ class FeedbackActor {
13
14
  this._unsubscribes = [hub.on(fields.feedback(), state => this._trigger(state))];
14
15
  }
15
16
  _trigger(state) {
16
- const {
17
- [fields.data()]: data
18
- } = this._hub.states;
19
- const {
20
- question_id
21
- } = data && data.value || {};
22
- if (!question_id) {
23
- return;
24
- }
25
- // TODO: ad-hoc
26
- const {
27
- request
28
- } = data || {};
29
- const {
30
- payload
31
- } = request || {};
32
- const question_source = payload && payload._meta && payload._meta.question_source;
33
- this._hub.trigger(fields.interaction(), this._buildInteraction(state, {
34
- question_source
35
- }));
36
- }
37
- _buildInteraction(_ref, _ref2) {
38
- let {
39
- value,
40
- unselected
41
- } = _ref;
42
- let {
43
- question_source
44
- } = _ref2;
45
- return {
46
- type: 'feedback',
47
- context: {
48
- custom_context: {
49
- result_type: 'answer',
50
- question_source,
51
- value: unselected ? 'unselected' : value
52
- }
53
- }
54
- };
17
+ this._hub.trigger(fields.tracker(), {
18
+ type: _constants.EVENT_TYPE.FEEDBACK,
19
+ result_type: 'answer',
20
+ value: state.unselected ? 'unselected' : state.value
21
+ });
55
22
  }
56
23
  _destroy() {
57
24
  for (const unsubscribe of this._unsubscribes) {
@@ -3,12 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.completions = completions;
6
7
  exports.data = data;
7
8
  exports.event = event;
8
9
  exports.feedback = feedback;
9
10
  exports.filters = filters;
10
11
  exports.input = input;
11
12
  exports.interaction = interaction;
13
+ exports.more = more;
12
14
  exports.query = query;
13
15
  exports.request = request;
14
16
  exports.response = response;
@@ -22,20 +24,23 @@ function session() {
22
24
  function suggestions() {
23
25
  return 'suggestions';
24
26
  }
27
+ function completions() {
28
+ return 'completions';
29
+ }
25
30
  function filters() {
26
31
  return 'filters';
27
32
  }
28
33
  function query() {
29
34
  return 'query';
30
35
  }
31
- function request(aspect) {
32
- return aspect ? `request:${aspect}` : 'request';
36
+ function request() {
37
+ return 'request';
33
38
  }
34
- function response(aspect) {
35
- return aspect ? `response:${aspect}` : 'response';
39
+ function response() {
40
+ return 'response';
36
41
  }
37
- function data(aspect) {
38
- return aspect ? `data:${aspect}` : 'data';
42
+ function data() {
43
+ return 'data';
39
44
  }
40
45
  function view(role) {
41
46
  return role ? `view:${role}` : 'view';
@@ -54,4 +59,7 @@ function feedback() {
54
59
  }
55
60
  function input() {
56
61
  return 'input';
62
+ }
63
+ function more() {
64
+ return 'more';
57
65
  }
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _commons = require("@miso.ai/commons");
8
- var _processors = require("../workflow/processors.js");
9
8
  class Hub {
10
9
  constructor() {
11
10
  (this._events = new _commons.EventEmitter())._injectSubscribeInterface(this);
@@ -20,7 +19,7 @@ class Hub {
20
19
  let {
21
20
  silent = false
22
21
  } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
23
- this._states[name] = Object.freeze((0, _processors.removeDataInstructions)(state));
22
+ this._states[name] = Object.freeze(state);
24
23
  if (!silent) {
25
24
  this._events.emit(name, state);
26
25
  }
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "AutocompleteActor", {
7
- enumerable: true,
8
- get: function () {
9
- return _autocomplete.default;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "DataActor", {
13
7
  enumerable: true,
14
8
  get: function () {
@@ -53,7 +47,6 @@ var _sessions = _interopRequireDefault(require("./sessions.js"));
53
47
  var _data = _interopRequireDefault(require("./data.js"));
54
48
  var _views = _interopRequireDefault(require("./views.js"));
55
49
  var _feedback = _interopRequireDefault(require("./feedback.js"));
56
- var _autocomplete = _interopRequireDefault(require("./autocomplete.js"));
57
50
  var _interactions = _interopRequireDefault(require("./interactions.js"));
58
51
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
59
52
  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); }
@@ -19,25 +19,14 @@ class InteractionsActor {
19
19
  this._unsubscribes = [hub.on(fields.interaction(), payload => this._handle(payload))];
20
20
  }
21
21
  _handle(payload) {
22
+ // TODO: omit when option == false
22
23
  payload = (0, _commons.asArray)(payload);
23
- const {
24
- preprocess = [],
25
- handle
26
- } = this._options.resolved.interactions;
27
- for (const p of preprocess) {
28
- payload = payload.map(p);
29
- }
30
- // TODO: support filter?
31
24
  if (payload.length === 0) {
32
25
  return;
33
26
  }
34
- if (handle) {
35
- handle(payload);
36
- } else {
37
- this._client.api.interactions.upload(payload, {
38
- merge: true
39
- });
40
- }
27
+ this._client.api.interactions.upload(payload, {
28
+ merge: true
29
+ });
41
30
  }
42
31
  destroy() {
43
32
  for (const unsubscribe of this._unsubscribes) {
@@ -12,45 +12,14 @@ class SessionMaker {
12
12
  constructor(hub) {
13
13
  this._hub = hub;
14
14
  this._sessionIndex = 0;
15
- (0, _commons.delegateGetters)(hub, this, ['active']);
16
- }
17
- get active() {
18
- const {
19
- session
20
- } = this._hub.states;
21
- return !!(session && session.active);
22
- }
23
- new() {
24
- let {
25
- force = false
26
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
27
- const currentSession = this._hub.states.session;
28
- if (currentSession && !currentSession.active && !force) {
29
- return;
30
- }
31
- const session = this._create();
32
- this._hub.update(fields.session(), session);
33
- }
34
- start() {
35
- const session = this._hub.states.session || this._create();
36
- if (session.active) {
37
- return;
38
- }
39
- this._hub.update(fields.session(), Object.assign({}, session, {
40
- active: true
41
- }));
42
15
  }
43
16
  restart() {
44
- this._hub.update(fields.session(), this._create(true));
45
- }
46
- _create() {
47
- let active = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
48
- return Object.freeze({
49
- active,
17
+ const session = Object.freeze({
50
18
  uuid: (0, _commons.uuidv4)(),
51
19
  index: this._sessionIndex++,
52
20
  meta: {}
53
21
  });
22
+ this._hub.update(fields.session(), session);
54
23
  }
55
24
  }
56
25
  exports.default = SessionMaker;
@@ -8,7 +8,6 @@ var _commons = require("@miso.ai/commons");
8
8
  var _constants = require("../constants.js");
9
9
  var fields = _interopRequireWildcard(require("./fields.js"));
10
10
  var _states = _interopRequireDefault(require("../util/states.js"));
11
- var _utils = require("./utils.js");
12
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
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); }
14
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 && {}.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; }
@@ -36,35 +35,35 @@ class Tracker {
36
35
  return this._states.getFullState(item);
37
36
  }
38
37
  _trigger(type, items) {
39
- let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
38
+ (0, _constants.validateEventType)(type);
40
39
  if (this._valueless) {
41
- meta = items;
42
40
  items = VALUELESS_ITEMS;
43
41
  }
44
- (0, _constants.validateEventType)(type);
45
42
  this._syncSession();
46
- if (type !== _constants.EVENT_TYPE.SUBMIT) {
47
- items = this._states.untriggered((0, _commons.asArray)(items), type);
48
- if (items.length === 0) {
49
- return;
50
- }
51
- this._states.set(items, type, _constants.TRACKING_STATUS.TRIGGERED);
43
+ items = this._states.untriggered((0, _commons.asArray)(items), type);
44
+ if (items.length === 0) {
45
+ return;
52
46
  }
53
- const property = this._role === 'results' ? 'products' : this._role; // TODO: ad-hoc, see #83
54
- const misoId = this._getMisoId();
55
- const request = this._getRequestPayload();
56
- const values = this._valueless ? undefined : items;
57
-
58
- // TODO: should trigger 'tracker' and let workflow translate to interactions
59
- this._hub.trigger(fields.interaction(), (0, _utils.toInteraction)({
60
- property,
61
- misoId,
62
- request
63
- }, {
64
- event: type,
65
- values,
66
- meta
67
- }));
47
+ this._states.set(items, type, _constants.TRACKING_STATUS.TRIGGERED);
48
+ this._sendToHub({
49
+ type,
50
+ items: this._valueless ? undefined : items
51
+ });
52
+ }
53
+ submit(_ref2) {
54
+ let {
55
+ value
56
+ } = _ref2;
57
+ this._syncSession();
58
+ this._sendToHub({
59
+ type: _constants.EVENT_TYPE.SUBMIT,
60
+ value
61
+ });
62
+ }
63
+ _sendToHub(args) {
64
+ this._hub.trigger(fields.tracker(), Object.freeze((0, _commons.trimObj)(Object.assign({
65
+ role: this._role
66
+ }, args))));
68
67
  }
69
68
  _syncSession() {
70
69
  const sessionId = this._getSessionId();
@@ -96,7 +95,7 @@ class Tracker {
96
95
  }
97
96
  }
98
97
  exports.default = Tracker;
99
- for (const type of _constants.TRACKING_EVENT_TYPES) {
98
+ for (const type of _constants.PERFORMANCE_EVENT_TYPES) {
100
99
  Tracker.prototype[type] = function (items, meta) {
101
100
  this._trigger(type, items, meta);
102
101
  };
@@ -4,55 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isCurrentSession = isCurrentSession;
7
- exports.isProduct = isProduct;
8
- exports.toInteraction = toInteraction;
9
- var _commons = require("@miso.ai/commons");
10
- var _constants = require("../constants.js");
11
- const PRODUCT_TYPED_PROPERTIES = new Set([_constants.ROLE.PRODUCTS, _constants.ROLE.SOURCES, _constants.ROLE.RELATED_RESOURCES]);
12
-
13
- // TODO: move away
14
- function isProduct(property) {
15
- return PRODUCT_TYPED_PROPERTIES.has(property);
16
- }
17
- function toInteraction(_ref, _ref2) {
18
- let {
19
- property,
20
- misoId,
21
- request
22
- } = _ref;
23
- let {
24
- event,
25
- values,
26
- manual
27
- } = _ref2;
28
- // TODO: ad-hoc
29
- const question_source = request && request._meta && request._meta.question_source;
30
- const isProductType = isProduct(property);
31
- const isSubmit = event === _constants.EVENT_TYPE.SUBMIT;
32
- const isAffiliation = property === _constants.ROLE.AFFILIATION;
33
- const product_ids = isProductType && values ? values.map(v => typeof v === 'string' ? v : v.product_id).filter(v => v) : !isSubmit ? [] : undefined;
34
- const items = !isProductType && !isSubmit && values ? values.map(v => v.text || v.id || v) : undefined;
35
- const value = isSubmit ? values : undefined;
36
- const channel = isAffiliation ? values[0] && values[0].channel : undefined;
37
- const positions = isAffiliation ? values.map(v => v.position) : undefined;
38
- const payload = (0, _commons.trimObj)({
39
- type: event === 'viewable' ? 'viewable_impression' : event,
40
- product_ids,
41
- miso_id: misoId,
42
- context: {
43
- custom_context: (0, _commons.trimObj)({
44
- property,
45
- channel,
46
- items,
47
- value,
48
- positions,
49
- trigger: manual ? 'manual' : 'auto',
50
- question_source
51
- })
52
- }
53
- });
54
- return payload;
55
- }
56
7
  function isCurrentSession(hub, session) {
57
8
  if (!session) {
58
9
  return false;
@@ -28,7 +28,7 @@ class ViewActor {
28
28
  target: this
29
29
  });
30
30
  this._views = views;
31
- this._config = views._rolesConfig[role] || {};
31
+ this._mapping = asMappingFunction((views._roles.mappings || {})[role] || role);
32
32
  (0, _commons.defineValues)(this, {
33
33
  role,
34
34
  interface: new View(this)
@@ -112,6 +112,9 @@ class ViewActor {
112
112
  }
113
113
  return this._tracker;
114
114
  }
115
+ get workflowOptions() {
116
+ return this._views._getWorkflowOptions();
117
+ }
115
118
  get filters() {
116
119
  return this._views.filters;
117
120
  }
@@ -138,35 +141,32 @@ class ViewActor {
138
141
  const previousData = this._data;
139
142
  this._data = data = this._sliceData(data || this._views._getData());
140
143
 
141
- // protocol: no reaction until session starts
144
+ // if data is unchanged, skip unless forced
145
+ if (!force && statesEqual(data, previousData)) {
146
+ return;
147
+ }
142
148
  const {
143
149
  session,
144
150
  status,
145
151
  ongoing,
146
152
  request,
147
- meta
153
+ meta,
154
+ value
148
155
  } = data;
149
- const active = session && session.active;
150
- if (!force && !active) {
151
- return;
152
- }
153
-
154
- // if data is unchanged, skip unless forced
155
- if (!force && statesEqual(data, previousData)) {
156
- return;
157
- }
156
+ const baseState = Object.assign({
157
+ session,
158
+ status,
159
+ ongoing,
160
+ request,
161
+ meta,
162
+ data: value
163
+ }, getDataEmptyness(data));
158
164
 
159
165
  // render
160
166
  const notifyUpdate = function () {
161
167
  let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
162
168
  let options = arguments.length > 1 ? arguments[1] : undefined;
163
- state !== false && _this.updateState(Object.assign({
164
- session,
165
- status,
166
- ongoing,
167
- request,
168
- meta
169
- }, state), options);
169
+ state !== false && _this.updateState(Object.assign({}, baseState, state), options);
170
170
  };
171
171
  try {
172
172
  await this._layout.render(element, data, {
@@ -179,29 +179,15 @@ class ViewActor {
179
179
  });
180
180
  }
181
181
  }
182
- updateState(_ref) {
183
- let {
184
- session,
185
- status,
186
- ongoing,
187
- request,
188
- meta,
189
- error
190
- } = _ref;
182
+ updateState(state) {
191
183
  let {
192
184
  silent = false
193
185
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
194
- if (error) {
195
- status = _constants.STATUS.ERRONEOUS;
196
- }
197
- const state = this._state = Object.freeze((0, _commons.trimObj)({
198
- session,
199
- status,
200
- ongoing,
201
- request,
202
- meta,
203
- error
204
- }));
186
+ // there might be error from notifyUpdate() call
187
+ const status = state.error ? _constants.STATUS.ERRONEOUS : state.status;
188
+ state = this._state = Object.freeze((0, _commons.trimObj)(Object.assign({}, state, {
189
+ status
190
+ })));
205
191
  const {
206
192
  role
207
193
  } = this;
@@ -221,7 +207,7 @@ class ViewActor {
221
207
  } = data,
222
208
  rest = _objectWithoutPropertiesLoose(data, _excluded);
223
209
  const sliced = Object.assign({
224
- value: asMappingFunction(this._config.mapping || this.role)(data),
210
+ value: this._mapping(data),
225
211
  status,
226
212
  data: value,
227
213
  meta
@@ -300,4 +286,18 @@ function asMappingFunction(fn) {
300
286
  default:
301
287
  throw new Error(`Invalid mapping function: ${fn}`);
302
288
  }
289
+ }
290
+ function getDataEmptyness(data) {
291
+ return isDataStatusRelevantToEmptyness(data) ? {
292
+ empty: !!isDateValueEmpty(data)
293
+ } : {};
294
+ }
295
+ function isDataStatusRelevantToEmptyness(data) {
296
+ return data.status === _constants.STATUS.READY && !data.ongoing;
297
+ }
298
+ function isDateValueEmpty(data) {
299
+ const {
300
+ value
301
+ } = data;
302
+ return value === undefined || (Array.isArray(value) || typeof value === 'string') && !value.length;
303
303
  }
@@ -20,8 +20,7 @@ class ViewsActor {
20
20
  workflow,
21
21
  extensions,
22
22
  layouts,
23
- roles = [],
24
- rolesConfig = {},
23
+ roles,
25
24
  options
26
25
  } = _ref;
27
26
  this._hub = hub;
@@ -29,13 +28,16 @@ class ViewsActor {
29
28
  this._extensions = extensions;
30
29
  this._layoutFactory = layouts;
31
30
  this._options = options;
32
- this._rolesConfig = rolesConfig;
31
+ this._roles = roles;
33
32
  this._containers = new Map();
34
33
  this._containerTracker = undefined;
35
34
  this._views = {};
36
- this._trackers = new Trackers(this, roles);
35
+ this._trackers = new Trackers(this, roles.members);
37
36
  this._filters = new _filters.default(this);
38
- for (const role of roles) {
37
+ for (const role of roles.members) {
38
+ if (role === _constants.ROLE.CONTAINER) {
39
+ continue;
40
+ }
39
41
  this._views[role] = new _view.default(this, role);
40
42
  }
41
43
  (0, _commons.defineValues)(this, {
@@ -45,7 +47,9 @@ class ViewsActor {
45
47
  window.addEventListener('resize', syncSize);
46
48
  this._unsubscribes = [() => window.removeEventListener('resize', syncSize), hub.on(fields.data(), data => this.refresh({
47
49
  data
48
- })), options.on('trackers', () => this._syncTrackers()), options.on('layouts', () => this._syncLayouts())];
50
+ })), options.on('autocomplete', () => this._syncAutocompleteOptions()), options.on('pagination', () => this._syncPaginationOptions()), options.on('trackers', () => this._syncTrackers()), options.on('layouts', () => this._syncLayouts())];
51
+ this._syncAutocompleteOptions();
52
+ this._syncPaginationOptions();
49
53
  this._syncTrackers();
50
54
  this._syncLayouts();
51
55
  }
@@ -95,6 +99,9 @@ class ViewsActor {
95
99
  updateComponentRole(element, oldRole, newRole) {
96
100
  // TODO
97
101
  }
102
+ containsElement(element) {
103
+ return this._containers.has(element) || this._views[element.role];
104
+ }
98
105
  refreshElement(element) {
99
106
  const view = element.isContainer ? this._containers.get(element) : this._getViewByElement(element);
100
107
  view && view.refresh({
@@ -143,7 +150,8 @@ class ViewsActor {
143
150
  // TODO: try to omit if unchanged
144
151
  const fn = () => this._layoutFactory.create(name, Object.assign({}, options, {
145
152
  role,
146
- workflow: this._workflowName
153
+ workflow: this._workflowName,
154
+ workflowOptions: this._getWorkflowOptions()
147
155
  }));
148
156
  if (role === _constants.ROLE.CONTAINER) {
149
157
  for (const view of this._containers.values()) {
@@ -163,7 +171,8 @@ class ViewsActor {
163
171
  const [name, options] = args;
164
172
  return this._layoutFactory.create(name, Object.assign({}, options, {
165
173
  role,
166
- workflow: this._workflowName
174
+ workflow: this._workflowName,
175
+ workflowOptions: this._getWorkflowOptions()
167
176
  }));
168
177
  }
169
178
  get(role) {
@@ -229,6 +238,18 @@ class ViewsActor {
229
238
  }
230
239
  return this._containerTracker;
231
240
  }
241
+ _syncAutocompleteOptions() {
242
+ this._autocompleteOptions = this._options.resolved.autocomplete;
243
+ }
244
+ _syncPaginationOptions() {
245
+ this._paginationOptions = this._options.resolved.pagination;
246
+ }
247
+ _getWorkflowOptions() {
248
+ return (0, _commons.trimObj)({
249
+ autocomplete: this._autocompleteOptions,
250
+ pagination: this._paginationOptions
251
+ });
252
+ }
232
253
  _error(e) {
233
254
  // TODO: hub trigger error event
234
255
  console.error(e);
@@ -266,6 +287,9 @@ class Trackers {
266
287
  constructor(views, roles) {
267
288
  this._views = views;
268
289
  for (const role of roles) {
290
+ if (role === _constants.ROLE.CONTAINER) {
291
+ continue;
292
+ }
269
293
  Object.defineProperty(this, role, {
270
294
  get: () => views.get(role).tracker
271
295
  });
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TRIANGLE = exports.SEND = exports.SEARCH = void 0;
6
+ exports.TRIANGLE = exports.SEND = exports.SEARCH = exports.ICON_NAMES = void 0;
7
+ exports.getIcon = getIcon;
7
8
  var _version = _interopRequireDefault(require("../version.js"));
8
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
10
  function trianglePath(r) {
@@ -14,13 +15,18 @@ function trianglePath(r) {
14
15
  }
15
16
  const PREFIX = 'miso-ui-icon';
16
17
  const ID = `${PREFIX}-svg-${_version.default.replaceAll('.', '_')}`;
18
+ const ICON_NAME = {
19
+ SEND: 'send',
20
+ SEARCH: 'search',
21
+ TRIANGLE: 'triangle'
22
+ };
17
23
 
18
24
  // CC0 SVGs
19
- const ICON_SEND = `<symbol id="${PREFIX}-send" viewBox="0 0 32 32"><path fill="currentColor" d="M11.499,19.173l5.801,-5.849c0.389,-0.392 1.022,-0.394 1.414,-0.006c0.392,0.389 0.395,1.022 0.006,1.414l-5.798,5.847l5.306,8.002c0.207,0.313 0.572,0.483 0.945,0.441c0.373,-0.042 0.691,-0.289 0.824,-0.64l9.024,-23.904c0.138,-0.366 0.05,-0.78 -0.226,-1.058c-0.276,-0.278 -0.689,-0.369 -1.057,-0.233l-24.004,8.892c-0.353,0.13 -0.602,0.448 -0.646,0.821c-0.044,0.373 0.125,0.74 0.438,0.948l7.973,5.325Z"/></symbol>`;
20
- const ICON_SEARCH = `<symbol id="${PREFIX}-search" viewBox="0 0 24 24"><path fill="currentColor" d="M4 11C4 7.13401 7.13401 4 11 4C14.866 4 18 7.13401 18 11C18 14.866 14.866 18 11 18C7.13401 18 4 14.866 4 11ZM11 2C6.02944 2 2 6.02944 2 11C2 15.9706 6.02944 20 11 20C13.125 20 15.078 19.2635 16.6177 18.0319L20.2929 21.7071C20.6834 22.0976 21.3166 22.0976 21.7071 21.7071C22.0976 21.3166 22.0976 20.6834 21.7071 20.2929L18.0319 16.6177C19.2635 15.078 20 13.125 20 11C20 6.02944 15.9706 2 11 2Z"/></symbol>`;
25
+ const ICON_SEND = `<symbol id="${PREFIX}-${ICON_NAME.SEND}" viewBox="0 0 32 32"><path fill="currentColor" d="M11.499,19.173l5.801,-5.849c0.389,-0.392 1.022,-0.394 1.414,-0.006c0.392,0.389 0.395,1.022 0.006,1.414l-5.798,5.847l5.306,8.002c0.207,0.313 0.572,0.483 0.945,0.441c0.373,-0.042 0.691,-0.289 0.824,-0.64l9.024,-23.904c0.138,-0.366 0.05,-0.78 -0.226,-1.058c-0.276,-0.278 -0.689,-0.369 -1.057,-0.233l-24.004,8.892c-0.353,0.13 -0.602,0.448 -0.646,0.821c-0.044,0.373 0.125,0.74 0.438,0.948l7.973,5.325Z"/></symbol>`;
26
+ const ICON_SEARCH = `<symbol id="${PREFIX}-${ICON_NAME.SEARCH}" viewBox="0 0 24 24"><path fill="currentColor" d="M4 11C4 7.13401 7.13401 4 11 4C14.866 4 18 7.13401 18 11C18 14.866 14.866 18 11 18C7.13401 18 4 14.866 4 11ZM11 2C6.02944 2 2 6.02944 2 11C2 15.9706 6.02944 20 11 20C13.125 20 15.078 19.2635 16.6177 18.0319L20.2929 21.7071C20.6834 22.0976 21.3166 22.0976 21.7071 21.7071C22.0976 21.3166 22.0976 20.6834 21.7071 20.2929L18.0319 16.6177C19.2635 15.078 20 13.125 20 11C20 6.02944 15.9706 2 11 2Z"/></symbol>`;
21
27
 
22
28
  // Custom SVGs
23
- const ICON_TRIANGLE = `<symbol id="${PREFIX}-triangle" viewBox="-5 -5 105 105"><path d="${trianglePath(5)}"/></symbol>`;
29
+ const ICON_TRIANGLE = `<symbol id="${PREFIX}-${ICON_NAME.TRIANGLE}" viewBox="-5 -5 105 105"><path d="${trianglePath(5)}"/></symbol>`;
24
30
  const ICONS = [ICON_SEND, ICON_SEARCH, ICON_TRIANGLE];
25
31
  const SPRITES_SVG = `<svg id="${ID}" style="display:none;">${ICONS.join('')}</svg>`;
26
32
  let loaded = false;
@@ -32,9 +38,13 @@ function loadSvgSprites() {
32
38
  document.head.insertAdjacentHTML('beforeend', SPRITES_SVG);
33
39
  }
34
40
  loadSvgSprites();
35
- function getSvg(name) {
41
+ function _icon(name) {
36
42
  return `<svg class="miso-ui-icon miso-ui-icon-${name}"><use href="#${PREFIX}-${name}"></use></svg>`;
37
43
  }
38
- const SEND = exports.SEND = getSvg('send');
39
- const SEARCH = exports.SEARCH = getSvg('search');
40
- const TRIANGLE = exports.TRIANGLE = getSvg('triangle');
44
+ const ICON_NAMES = exports.ICON_NAMES = new Set(Object.values(ICON_NAME));
45
+ function getIcon(name) {
46
+ return ICON_NAMES.has(name) ? _icon(name) : '';
47
+ }
48
+ const SEND = exports.SEND = _icon(ICON_NAME.SEND);
49
+ const SEARCH = exports.SEARCH = _icon(ICON_NAME.SEARCH);
50
+ const TRIANGLE = exports.TRIANGLE = _icon(ICON_NAME.TRIANGLE);