@webitel/ui-sdk 3.0.6 → 3.0.7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/ui-sdk",
3
- "version": "3.0.6",
3
+ "version": "3.0.7",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve-lib": "vue-cli-service serve",
@@ -18,6 +18,7 @@
18
18
  "src/locale/*",
19
19
  "src/css/*",
20
20
  "src/components/*",
21
+ "src/directives/*",
21
22
  "src/enums/*",
22
23
  "src/mixins/*",
23
24
  "src/scripts/*",
@@ -0,0 +1,52 @@
1
+ /* eslint-disable */
2
+
3
+ const HANDLER = '_vue_clickaway_handler';
4
+
5
+ function bind(el, binding, vnode) {
6
+ unbind(el);
7
+
8
+ const vm = vnode.context;
9
+ const callback = binding.value;
10
+
11
+ // @NOTE: Vue binds directives in microtasks, while UI events are dispatched
12
+ // in macrotasks. This causes the listener to be set up before
13
+ // the "origin" click event (the event that lead to the binding of
14
+ // the directive) arrives at the document root. To work around that,
15
+ // we ignore events until the end of the "initial" macrotask.
16
+ // @REFERENCE: https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/
17
+ // @REFERENCE: https://github.com/simplesmiler/vue-clickaway/issues/8
18
+ let initialMacrotaskEnded = false;
19
+ setTimeout(function() {
20
+ initialMacrotaskEnded = true;
21
+ }, 0);
22
+
23
+ el[HANDLER] = function(ev) {
24
+ // @NOTE: this test used to be just `el.contains`, but working with path is better,
25
+ // because it tests whether the element was there at the time of
26
+ // the click, not whether it is there now, that the event has arrived
27
+ // to the top.
28
+ // @NOTE: `.path` is non-standard, the standard way is `.composedPath()`
29
+ const path = ev.path || (ev.composedPath ? ev.composedPath() : undefined);
30
+ if (initialMacrotaskEnded && (path ? path.indexOf(el) < 0 : !el.contains(ev.target))) {
31
+ return callback.call(vm, ev);
32
+ }
33
+ };
34
+
35
+ document.documentElement.addEventListener('click', el[HANDLER], false);
36
+ }
37
+
38
+ function unbind(el) {
39
+ document.documentElement.removeEventListener('click', el[HANDLER], false);
40
+ delete el[HANDLER];
41
+ }
42
+
43
+ const clickaway = {
44
+ bind,
45
+ update (el, binding) {
46
+ if (binding.value === binding.oldValue) return;
47
+ bind(el, binding);
48
+ },
49
+ unbind,
50
+ };
51
+
52
+ export default clickaway;
@@ -0,0 +1,8 @@
1
+ import Vue from 'vue';
2
+ import clickaway from './clickaway/clickaway';
3
+
4
+ const Directives = {
5
+ clickaway,
6
+ };
7
+
8
+ export default Directives;