@miso.ai/client-sdk-ui 1.10.0-beta.0 → 1.10.0-beta.10

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 (90) hide show
  1. package/dist/cjs/actor/autocomplete.js +157 -0
  2. package/dist/cjs/actor/data.js +4 -12
  3. package/dist/cjs/actor/fields.js +8 -0
  4. package/dist/cjs/actor/index.js +7 -0
  5. package/dist/cjs/actor/tracker.js +46 -70
  6. package/dist/cjs/actor/trackers.js +5 -1
  7. package/dist/cjs/actor/utils.js +16 -2
  8. package/dist/cjs/actor/view.js +14 -3
  9. package/dist/cjs/actor/views.js +9 -1
  10. package/dist/cjs/affiliation/index.js +126 -0
  11. package/dist/cjs/combo/ask/options.js +1 -1
  12. package/dist/cjs/combo/base.js +1 -1
  13. package/dist/cjs/constants.js +6 -3
  14. package/dist/cjs/defaults/ask/controls.js +1 -1
  15. package/dist/cjs/defaults/ask/phrases.js +1 -1
  16. package/dist/cjs/defaults/ask/templates.js +35 -4
  17. package/dist/cjs/element/role/index.js +7 -0
  18. package/dist/cjs/element/role/miso-affiliation.js +20 -0
  19. package/dist/cjs/layout/affiliation/affiliation.js +330 -0
  20. package/dist/cjs/layout/banner/banner.js +1 -1
  21. package/dist/cjs/layout/container/container.js +1 -1
  22. package/dist/cjs/layout/error/error.js +1 -1
  23. package/dist/cjs/layout/index.js +7 -0
  24. package/dist/cjs/layout/input/option-list.js +35 -50
  25. package/dist/cjs/layout/input/search-box.js +227 -129
  26. package/dist/cjs/layout/list/cards.js +1 -1
  27. package/dist/cjs/layout/list/carousel.js +5 -3
  28. package/dist/cjs/layout/list/collection.js +44 -49
  29. package/dist/cjs/layout/list/list.js +1 -1
  30. package/dist/cjs/layout/radio/feedback.js +1 -1
  31. package/dist/cjs/layout/radio/radio.js +1 -1
  32. package/dist/cjs/layout/raf.js +1 -1
  33. package/dist/cjs/layout/template.js +1 -1
  34. package/dist/cjs/layout/templates.js +172 -66
  35. package/dist/cjs/layout/text/text.js +1 -1
  36. package/dist/cjs/layout/text/typewriter/index.js +3 -3
  37. package/dist/cjs/layout/trackable.js +124 -0
  38. package/dist/cjs/plugin.js +1 -1
  39. package/dist/cjs/source/index.js +20 -8
  40. package/dist/cjs/util/bindings.js +58 -110
  41. package/dist/cjs/util/states.js +31 -24
  42. package/dist/cjs/util/trackers.js +75 -0
  43. package/dist/cjs/util/viewables.js +55 -0
  44. package/dist/cjs/version.js +1 -1
  45. package/dist/cjs/workflow/ask.js +60 -19
  46. package/dist/cjs/workflow/asks.js +1 -1
  47. package/dist/cjs/workflow/base.js +6 -7
  48. package/dist/cjs/workflow/explore.js +5 -2
  49. package/dist/cjs/workflow/options.js +60 -14
  50. package/dist/cjs/workflow/recommendation.js +2 -0
  51. package/dist/cjs/workflow/search.js +35 -7
  52. package/package.json +2 -2
  53. package/src/actor/autocomplete.js +131 -0
  54. package/src/actor/data.js +3 -10
  55. package/src/actor/fields.js +8 -0
  56. package/src/actor/index.js +1 -0
  57. package/src/actor/tracker.js +39 -62
  58. package/src/actor/trackers.js +3 -1
  59. package/src/actor/utils.js +14 -2
  60. package/src/actor/view.js +12 -1
  61. package/src/actor/views.js +11 -0
  62. package/src/affiliation/index.js +108 -0
  63. package/src/constants.js +10 -1
  64. package/src/defaults/ask/phrases.js +1 -1
  65. package/src/defaults/ask/templates.js +34 -2
  66. package/src/element/role/index.js +1 -0
  67. package/src/element/role/miso-affiliation.js +16 -0
  68. package/src/layout/affiliation/affiliation.js +295 -0
  69. package/src/layout/index.js +1 -0
  70. package/src/layout/input/option-list.js +35 -43
  71. package/src/layout/input/search-box.js +192 -95
  72. package/src/layout/list/carousel.js +4 -2
  73. package/src/layout/list/collection.js +42 -43
  74. package/src/layout/templates.js +127 -46
  75. package/src/layout/text/typewriter/index.js +2 -2
  76. package/src/layout/trackable.js +106 -0
  77. package/src/source/index.js +14 -1
  78. package/src/util/bindings.js +47 -103
  79. package/src/util/states.js +26 -20
  80. package/src/util/trackers.js +69 -0
  81. package/src/util/viewables.js +47 -0
  82. package/src/version.js +1 -1
  83. package/src/workflow/ask.js +37 -3
  84. package/src/workflow/base.js +2 -3
  85. package/src/workflow/explore.js +1 -1
  86. package/src/workflow/options.js +54 -13
  87. package/src/workflow/recommendation.js +1 -0
  88. package/src/workflow/search.js +33 -1
  89. package/dist/cjs/util/tracker.js +0 -348
  90. package/src/util/tracker.js +0 -318
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TrackableMixin = void 0;
7
+ exports.makeTrackable = makeTrackable;
8
+ var _constants = require("../constants.js");
9
+ var _bindings = _interopRequireDefault(require("../util/bindings.js"));
10
+ var _viewables = _interopRequireDefault(require("../util/viewables.js"));
11
+ var _trackers = require("../util/trackers.js");
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ function makeTrackable(prototype) {
14
+ _mixin(prototype, TrackableMixin.prototype);
15
+ }
16
+ function _mixin(target, source) {
17
+ const descriptors = Object.getOwnPropertyDescriptors(source);
18
+ for (const key in descriptors) {
19
+ if (key === 'constructor') {
20
+ continue;
21
+ }
22
+ const {
23
+ value
24
+ } = descriptors[key];
25
+ if (target[key] === undefined && typeof value === 'function') {
26
+ target[key] = value;
27
+ }
28
+ // TODO: getter, setter
29
+ }
30
+ }
31
+ class TrackableMixin {
32
+ _initTrackable() {
33
+ this._bindings = new _bindings.default();
34
+ this._viewables = new _viewables.default();
35
+ }
36
+ _syncBindings(element, state) {
37
+ const values = this._getItems(state) || [];
38
+ const keys = values.map(value => this._getItemKey(value));
39
+ const elements = this._getItemElements(element);
40
+ const {
41
+ bounds,
42
+ unbounds
43
+ } = this._bindings.update(keys, values, elements);
44
+ this._onBindingsUpdate(bounds, unbounds);
45
+ }
46
+ _clearBindings() {
47
+ const {
48
+ bounds,
49
+ unbounds
50
+ } = this._bindings.clear();
51
+ this._onBindingsUpdate(bounds, unbounds);
52
+ }
53
+ _getItemKey(value) {
54
+ // TODO: ad-hoc!
55
+ return value.product_id || value.text || value.id || value;
56
+ }
57
+ _getItems(state) {
58
+ throw new Error(`Not implemented.`);
59
+ }
60
+ _getItemElements(element) {
61
+ throw new Error(`Not implemented.`);
62
+ }
63
+ _onBindingsUpdate(bounds, unbounds) {
64
+ this._trackImpressions(bounds);
65
+ this._untrackViewables(unbounds);
66
+ this._trackViewables(bounds);
67
+ }
68
+ _trackImpressions(entries) {
69
+ if (entries.length === 0) {
70
+ return;
71
+ }
72
+ const {
73
+ impression: options
74
+ } = this._view.trackerOptions || {};
75
+ if (!options) {
76
+ return;
77
+ }
78
+ setTimeout(() => this._view._track(_constants.EVENT_TYPE.IMPRESSION, entries.map(_ref => {
79
+ let {
80
+ value
81
+ } = _ref;
82
+ return value;
83
+ })), 0);
84
+ }
85
+ _untrackViewables(entries) {
86
+ for (const {
87
+ element
88
+ } of entries) {
89
+ this._viewables.untrack(element);
90
+ }
91
+ }
92
+ _trackViewables(entries) {
93
+ if (entries.length === 0) {
94
+ return;
95
+ }
96
+ const {
97
+ viewable: options
98
+ } = this._view.trackerOptions || {};
99
+ if (!options) {
100
+ return;
101
+ }
102
+ for (const {
103
+ value,
104
+ element
105
+ } of entries) {
106
+ (async () => (await this._viewables.track(element, options)) && this._view._track(_constants.EVENT_TYPE.VIEWABLE, [value]))();
107
+ }
108
+ }
109
+ _trackClick(event, binding) {
110
+ const {
111
+ click: options
112
+ } = this._view.trackerOptions || {};
113
+ if ((0, _trackers.validateClick)(options, event, binding)) {
114
+ this._view._track(_constants.EVENT_TYPE.CLICK, [binding.value]);
115
+ }
116
+ }
117
+ _destroyTrackable() {
118
+ const {
119
+ unbounds
120
+ } = this._bindings.clear();
121
+ this._untrackViewables(unbounds);
122
+ }
123
+ }
124
+ exports.TrackableMixin = TrackableMixin;
@@ -19,7 +19,7 @@ const _excluded = ["containers", "roles", "combos"];
19
19
  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); }
20
20
  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; }
21
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
22
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
23
23
  const PLUGIN_ID = 'std:ui';
24
24
  class UiPlugin extends _commons.Component {
25
25
  static get id() {
@@ -3,11 +3,23 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "api", {
7
- enumerable: true,
8
- get: function () {
9
- return _api.default;
10
- }
11
- });
12
- var _api = _interopRequireDefault(require("./api.js"));
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
6
+ exports.api = api;
7
+ var _commons = require("@miso.ai/commons");
8
+ //export { default as api } from './api.js';
9
+
10
+ function api(client) {
11
+ // TODO: send uuid & unit id
12
+ return async _ref => {
13
+ let {
14
+ group,
15
+ name,
16
+ payload,
17
+ options
18
+ } = _ref;
19
+ if (group === _commons.API.GROUP.ASK && name === _commons.API.NAME.QUESTIONS) {
20
+ return client.api.ask.questions(payload, options);
21
+ }
22
+ // because name is in snake case
23
+ return client.api[group]._run(name, payload, options);
24
+ };
25
+ }
@@ -3,131 +3,79 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Bindings = void 0;
7
- exports.fallbackListFunction = fallbackListFunction;
8
- var _commons = require("@miso.ai/commons");
9
- function fallbackListFunction(keyAttrName) {
10
- return element => Array.from(element.querySelectorAll(`[${keyAttrName}]`)).map(element => ({
11
- element,
12
- value: {
13
- product_id: element.getAttribute(keyAttrName) // TODO: product_id is ad-hoc
6
+ exports.default = void 0;
7
+ function tuple(keys, values, elements) {
8
+ const k2b = new Map();
9
+ const e2b = new Map();
10
+ const entries = [];
11
+ for (let index = 0; index < keys.length; index++) {
12
+ const key = keys[index];
13
+ const element = elements[index];
14
+ const value = values[index];
15
+ const entry = Object.freeze({
16
+ index,
17
+ key,
18
+ value,
19
+ element
20
+ });
21
+ k2b.set(key, entry);
22
+ e2b.set(element, entry);
23
+ entries.push(entry);
24
+ }
25
+ return {
26
+ k2b,
27
+ e2b,
28
+ entries
29
+ };
30
+ }
31
+ function diff(from, to) {
32
+ const entries = [];
33
+ for (const entry of to.entries) {
34
+ const f = from.e2b.get(entry.element);
35
+ if (!f || f.key !== entry.key) {
36
+ entries.push(entry);
14
37
  }
15
- }));
38
+ }
39
+ return entries;
16
40
  }
17
41
  class Bindings {
18
42
  constructor() {
19
- let {
20
- keyAttrName = 'data-key',
21
- list
22
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
23
- this._list = list || fallbackListFunction(keyAttrName);
24
- this._bindings = new Map();
25
- this._e2b = new WeakMap();
43
+ this._k2b = new Map();
44
+ this._e2b = new Map();
45
+ this._entries = [];
26
46
  }
27
- list() {
28
- return [...this._bindings.values()];
47
+ get entries() {
48
+ return [...this._entries];
29
49
  }
30
- get(ref) {
31
- if (!ref) {
32
- throw new Error(`Value or element is required.`);
33
- }
34
- if (!this._root) {
35
- return undefined;
36
- }
37
- if (!(0, _commons.isElement)(ref)) {
38
- return this._bindings.get(ref);
39
- }
40
- return (0, _commons.findInAncestors)(ref, element => this._e2b.get(element) || undefined, {
41
- root: this._root
42
- });
50
+ get(element) {
51
+ return this._e2b.get(element) || undefined;
43
52
  }
44
- refresh(rootElement) {
45
- if (!rootElement) {
46
- return this.unbindAll();
47
- }
48
- this._root = rootElement;
49
- const unbounds = this._purge();
50
- const bounds = [];
51
- // warn for conflict productIds
52
- // TODO
53
- for (const pair of this._list(rootElement)) {
54
- const [binding, ...ubs] = this._bind(pair);
55
- if (binding) {
56
- bounds.push(binding);
57
- }
58
- for (const u of ubs) {
59
- unbounds.push(u);
60
- }
61
- }
53
+ update(keys, values, elements) {
54
+ const newTuple = tuple(keys, values, elements);
55
+ const oldTuple = {
56
+ k2b: this._k2b,
57
+ e2b: this._e2b,
58
+ entries: this._entries
59
+ };
60
+ const bounds = diff(oldTuple, newTuple);
61
+ const unbounds = diff(newTuple, oldTuple);
62
+ this._k2b = newTuple.k2b;
63
+ this._e2b = newTuple.e2b;
64
+ this._entries = newTuple.entries;
62
65
  return {
63
66
  bounds,
64
67
  unbounds
65
68
  };
66
69
  }
67
- unbindAll() {
68
- const unbounds = this.list();
69
- this._bindings.clear();
70
- this._root = undefined;
70
+ clear() {
71
+ const unbounds = this._entries;
72
+ this._k2b = new Map();
73
+ this._e2b = new Map();
74
+ this._entries = [];
71
75
  return {
72
76
  bounds: [],
73
77
  unbounds
74
78
  };
75
79
  }
76
- _bind(_ref) {
77
- let {
78
- element,
79
- key,
80
- value
81
- } = _ref;
82
- key = key || value;
83
- if (!key) {
84
- throw new Error(`Key or value is required.`);
85
- }
86
- if (!element) {
87
- throw new Error(`Element is required.`);
88
- }
89
-
90
- // check if binding already exist
91
- const oldBinding = this._bindings.get(key);
92
- if (oldBinding && oldBinding.element === element) {
93
- return [];
94
- }
95
- const unbound0 = this._unbind(this.get(key));
96
- const unbound1 = this._unbind(this.get(element));
97
- const binding = Object.freeze({
98
- key,
99
- value,
100
- element
101
- });
102
- this._bindings.set(key, binding);
103
- this._e2b.set(element, binding);
104
- const results = [binding];
105
- unbound0 && results.push(unbound0);
106
- unbound1 && results.push(unbound1);
107
- return results;
108
- }
109
- _purge() {
110
- const purged = [];
111
- for (const binding of this._bindings.values()) {
112
- const {
113
- element
114
- } = binding;
115
- if ((0, _commons.isInDocument)(element)) {
116
- continue;
117
- }
118
- purged.push(this._unbind(binding));
119
- }
120
- return purged;
121
- }
122
- _unbind(binding) {
123
- if (binding) {
124
- this._bindings.delete(binding.key);
125
- this._e2b.delete(binding.element);
126
- }
127
- return binding;
128
- }
129
- _destroy() {
130
- this.unbindAll();
131
- }
132
80
  }
133
- exports.Bindings = Bindings;
81
+ exports.default = Bindings;
@@ -15,55 +15,62 @@ const {
15
15
  UNTRACKED,
16
16
  TRIGGERED
17
17
  } = _constants.TRACKING_STATUS;
18
+
19
+ /*
18
20
  const STATES = {
19
21
  NEW: Object.freeze({
20
22
  [IMPRESSION]: UNTRACKED,
21
- [VIEWABLE]: UNTRACKED
23
+ [VIEWABLE]: UNTRACKED,
22
24
  }),
23
25
  UNTRACKED: Object.freeze({
24
26
  [IMPRESSION]: UNTRACKED,
25
27
  [VIEWABLE]: UNTRACKED,
26
- [CLICK]: UNTRACKED
27
- })
28
+ [CLICK]: UNTRACKED,
29
+ }),
28
30
  };
31
+ */
32
+
33
+ const UNTRACKED_STATES = Object.freeze({
34
+ [IMPRESSION]: UNTRACKED,
35
+ [VIEWABLE]: UNTRACKED,
36
+ [CLICK]: UNTRACKED
37
+ });
29
38
 
30
39
  /**
31
40
  * Tracking states for a session to keep track of the tracking status of each product.
32
- * For each entry there are status of impression, viewable, and click events.
33
- * The actual click tracking status depends on the presence of root element, which is not respected in this object.
41
+ * For each entry there are status of impression, viewable, and click events.
34
42
  */
35
43
  class States {
36
44
  constructor(sessionId) {
37
45
  this.sessionId = sessionId;
38
- this._states = new Map(); // productId -> {impression, viewable, click}
46
+ this._states = new Map(); // item key -> {impression, viewable, click}
39
47
  }
40
- getFullState(productId) {
48
+ getFullState(item) {
41
49
  // when we receive a bind event, impression is trigger, making an entry here
42
50
  // so if the state is not found, the product is not present yet => all untracked
43
- const state = this._states.get(getKey(productId));
44
- return state ? Object.assign({}, state) : STATES.UNTRACKED;
51
+ const state = this._states.get(this._getKey(item));
52
+ return state ? Object.assign({}, state) : UNTRACKED_STATES;
45
53
  }
46
- get(productId, type) {
47
- const state = this._states.get(getKey(productId));
54
+ get(item, type) {
55
+ const state = this._states.get(this._getKey(item));
48
56
  return state && state[type] || UNTRACKED;
49
57
  }
50
- set(productIds, type, status) {
58
+ set(items, type, status) {
51
59
  (0, _constants.validateEventType)(type);
52
60
  (0, _constants.validateTrackingStatus)(status);
53
- for (const productId of (0, _commons.asArray)(productIds)) {
54
- this._setOne(getKey(productId), type, status);
61
+ for (const item of (0, _commons.asArray)(items)) {
62
+ this._setOne(item, type, status);
55
63
  }
56
64
  }
57
- _setOne(productId, type, status) {
58
- // leave click untracked/tracking judged by its global state
59
- (0, _commons.computeIfAbsent)(this._states, productId, () => Object.assign({}, STATES.NEW))[type] = status;
65
+ untriggered(items, type) {
66
+ return items.filter(item => this.get(item, type) !== TRIGGERED);
67
+ }
68
+ _getKey(item) {
69
+ // TODO: ad-hoc! should move away to higher level
70
+ return item.product_id || item.text || item.id || item;
60
71
  }
61
- untriggered(productIds, type) {
62
- return productIds.filter(productId => this.get(productId, type) !== TRIGGERED);
72
+ _setOne(item, type, status) {
73
+ (0, _commons.computeIfAbsent)(this._states, this._getKey(item), () => Object.assign({}, UNTRACKED_STATES))[type] = status;
63
74
  }
64
75
  }
65
- exports.default = States;
66
- function getKey(value) {
67
- // TODO: ad-hoc!
68
- return value.product_id || value.text || value;
69
- }
76
+ exports.default = States;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.normalizeTrackerOptions = normalizeTrackerOptions;
7
+ exports.validateClick = validateClick;
8
+ var _commons = require("@miso.ai/commons");
9
+ const _excluded = ["impression", "viewable", "click"];
10
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
11
+ const DEFAULT_TRACKER_OPTIONS = Object.freeze({
12
+ impression: Object.freeze({}),
13
+ viewable: Object.freeze({
14
+ area: 0.5,
15
+ duration: 1000
16
+ }),
17
+ click: Object.freeze({
18
+ lenient: false
19
+ }),
20
+ watch: false
21
+ });
22
+ function mergeOptions(def, opt) {
23
+ // if opt is falsy then return false, merge otherwise
24
+ return !!opt && Object.assign({}, def, opt);
25
+ }
26
+ function normalizeTrackerOptions(options) {
27
+ if (options === false) {
28
+ return false; // turn off all tracking
29
+ }
30
+ if (options === true) {
31
+ options = {};
32
+ }
33
+ if (typeof options !== 'object') {
34
+ throw new Error(`Invalid options: ${options}`);
35
+ }
36
+ const {
37
+ impression = {},
38
+ viewable = {},
39
+ click = {}
40
+ } = options,
41
+ rest = _objectWithoutPropertiesLoose(options, _excluded);
42
+ return (0, _commons.trimObj)(Object.assign({}, DEFAULT_TRACKER_OPTIONS, rest, {
43
+ impression: mergeOptions(DEFAULT_TRACKER_OPTIONS.impression, impression),
44
+ viewable: mergeOptions(DEFAULT_TRACKER_OPTIONS.viewable, viewable),
45
+ click: mergeOptions(DEFAULT_TRACKER_OPTIONS.click, click)
46
+ }));
47
+ }
48
+ function validateClick() {
49
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
50
+ let event = arguments.length > 1 ? arguments[1] : undefined;
51
+ if (!options) {
52
+ return false;
53
+ }
54
+ if (typeof options.validate === 'function') {
55
+ return options.validate(event);
56
+ }
57
+ if (options.lenient) {
58
+ return true;
59
+ }
60
+
61
+ // standard criteria
62
+ // 1. it must be a left click
63
+ if (event.button !== 0) {
64
+ return false;
65
+ }
66
+ // 2. event default must not be prevented
67
+ if (event.defaultPrevented) {
68
+ return false;
69
+ }
70
+ // 3. must go through a real link
71
+ if (!(0, _commons.findInAncestors)(event.target, element => element.tagName === 'A' && element.href || undefined)) {
72
+ return false;
73
+ }
74
+ return true;
75
+ }
@@ -0,0 +1,55 @@
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
+ class Viewables {
9
+ constructor() {
10
+ this._entries = new WeakMap();
11
+ }
12
+ isTracked(element) {
13
+ return this._entries.has(element);
14
+ }
15
+ async track(element) {
16
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17
+ if (!options) {
18
+ return false;
19
+ }
20
+ const entry = this._entries.get(element);
21
+ if (entry) {
22
+ return false;
23
+ }
24
+ const ac = new AbortController();
25
+ const {
26
+ signal
27
+ } = ac;
28
+ this._entries.set(element, {
29
+ ac
30
+ });
31
+ let result = false;
32
+ try {
33
+ await (0, _commons.viewable)(element, Object.assign({}, options, {
34
+ signal
35
+ }));
36
+ result = true;
37
+ } catch (e) {
38
+ if (e.name !== 'AbortError') {
39
+ throw e;
40
+ }
41
+ } finally {
42
+ this._entries.delete(element);
43
+ }
44
+ return result;
45
+ }
46
+ untrack(element) {
47
+ const entry = this._entries.get(element);
48
+ if (!entry) {
49
+ return;
50
+ }
51
+ entry.ac.abort();
52
+ this._entries.delete(element);
53
+ }
54
+ }
55
+ exports.default = Viewables;
@@ -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.10.0-beta.0';
7
+ var _default = exports.default = '1.10.0-beta.10';