@esportsplus/ui 0.0.19 → 0.0.20

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.
@@ -1,4 +1,5 @@
1
1
  import layout from './layout';
2
+ import queue from './queue';
2
3
  declare const _default: {
3
4
  layout: (data?: {
4
5
  overlay?: {
@@ -17,6 +18,9 @@ declare const _default: {
17
18
  type: string;
18
19
  values: never[];
19
20
  };
21
+ queue: {
22
+ onclick: (fn: VoidFunction) => void;
23
+ };
20
24
  };
21
25
  export default _default;
22
- export { layout };
26
+ export { layout, queue };
@@ -1,3 +1,4 @@
1
1
  import layout from './layout';
2
- export default { layout };
3
- export { layout };
2
+ import queue from './queue';
3
+ export default { layout, queue };
4
+ export { layout, queue };
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ onclick: (fn: VoidFunction) => void;
3
+ };
4
+ export default _default;
@@ -0,0 +1,18 @@
1
+ import events from '@esportsplus/delegated-events';
2
+ let initialized = false, queue = [];
3
+ const onclick = (fn) => {
4
+ if (!initialized) {
5
+ events.register(document.body, 'click', async () => {
6
+ if (!queue.length) {
7
+ return;
8
+ }
9
+ let items = queue.splice(0);
10
+ for (let i = 0, n = items.length; i < n; i++) {
11
+ await items[i]();
12
+ }
13
+ });
14
+ initialized = true;
15
+ }
16
+ queue.push(fn);
17
+ };
18
+ export default { onclick };
@@ -1,21 +1,8 @@
1
1
  import { reactive } from '@esportsplus/reactivity';
2
2
  import { html } from '@esportsplus/template';
3
- import events from '@esportsplus/delegated-events';
3
+ import { root } from '../../components';
4
4
  import menu from './menu';
5
- let initialized = false, root = [];
6
5
  const onclick = ({ active, toggle }) => {
7
- if (!initialized) {
8
- events.register(document.body, 'click', () => {
9
- if (!root.length) {
10
- return;
11
- }
12
- let deactivate = root.splice(0);
13
- for (let i = 0, n = deactivate.length; i < n; i++) {
14
- deactivate[i].active = false;
15
- }
16
- });
17
- initialized = true;
18
- }
19
6
  let state = reactive({
20
7
  active: active || false
21
8
  });
@@ -30,7 +17,7 @@ const onclick = ({ active, toggle }) => {
30
17
  }
31
18
  state.active = active;
32
19
  if (active) {
33
- root.push(state);
20
+ root.queue.onclick(() => state.active = false);
34
21
  }
35
22
  }
36
23
  });
package/package.json CHANGED
@@ -37,5 +37,5 @@
37
37
  "prepublishOnly": "npm run build"
38
38
  },
39
39
  "types": "./build/index.d.ts",
40
- "version": "0.0.19"
40
+ "version": "0.0.20"
41
41
  }
@@ -1,5 +1,6 @@
1
1
  import layout from './layout';
2
+ import queue from './queue';
2
3
 
3
4
 
4
- export default { layout };
5
- export { layout };
5
+ export default { layout, queue };
6
+ export { layout, queue };
@@ -0,0 +1,28 @@
1
+ import events from '@esportsplus/delegated-events';
2
+
3
+
4
+ let initialized = false,
5
+ queue: VoidFunction[] = [];
6
+
7
+
8
+ const onclick = (fn: VoidFunction) => {
9
+ if (!initialized) {
10
+ events.register(document.body, 'click', async () => {
11
+ if (!queue.length) {
12
+ return;
13
+ }
14
+
15
+ let items = queue.splice(0);
16
+
17
+ for (let i = 0, n = items.length; i < n; i++) {
18
+ await items[i]();
19
+ }
20
+ });
21
+ initialized = true;
22
+ }
23
+
24
+ queue.push(fn);
25
+ };
26
+
27
+
28
+ export default { onclick };
@@ -1,29 +1,10 @@
1
1
  import { reactive } from '@esportsplus/reactivity';
2
2
  import { html } from '@esportsplus/template';
3
- import events from '@esportsplus/delegated-events';
3
+ import { root } from '~/components';
4
4
  import menu from './menu';
5
5
 
6
6
 
7
- let initialized = false,
8
- root: { active: boolean }[] = [];
9
-
10
-
11
7
  const onclick = ({ active, toggle }: { active?: boolean, toggle?: boolean }) => {
12
- if (!initialized) {
13
- events.register(document.body, 'click', () => {
14
- if (!root.length) {
15
- return;
16
- }
17
-
18
- let deactivate = root.splice(0);
19
-
20
- for (let i = 0, n = deactivate.length; i < n; i++) {
21
- deactivate[i].active = false;
22
- }
23
- });
24
- initialized = true;
25
- }
26
-
27
8
  let state = reactive({
28
9
  active: active || false
29
10
  });
@@ -42,7 +23,7 @@ const onclick = ({ active, toggle }: { active?: boolean, toggle?: boolean }) =>
42
23
  state.active = active;
43
24
 
44
25
  if (active) {
45
- root.push(state);
26
+ root.queue.onclick(() => state.active = false);
46
27
  }
47
28
  }
48
29
  });