@esportsplus/ui 0.0.19 → 0.0.21

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,5 +1,5 @@
1
- import { Action, Reactive } from './types';
2
- export default function (action: Action, reactive?: Reactive): {
1
+ import { Action } from './types';
2
+ export default function (action: Action): {
3
3
  content: string;
4
4
  type: string;
5
5
  values: never[];
@@ -1,6 +1,7 @@
1
1
  import { response } from '@esportsplus/action';
2
2
  import { html } from '@esportsplus/template';
3
3
  import alert from '../../components/alert';
4
+ import input from './input';
4
5
  function parse(input) {
5
6
  let data = {};
6
7
  for (let path in input) {
@@ -13,7 +14,7 @@ function parse(input) {
13
14
  return data;
14
15
  }
15
16
  ;
16
- export default function (action, reactive = {}) {
17
+ export default function (action) {
17
18
  return html({
18
19
  onclick: function (event) {
19
20
  let trigger = event.target;
@@ -42,13 +43,12 @@ export default function (action, reactive = {}) {
42
43
  },
43
44
  response
44
45
  });
45
- if (errors && 'errors' in reactive) {
46
- let messages = {};
47
- for (let i = 0, n = errors.length; i < n; i++) {
48
- let { message, path } = errors[i];
49
- messages[path] = `${message[0].toUpperCase()}${message.substring(1)}`;
46
+ for (let i = 0, n = errors.length; i < n; i++) {
47
+ let { message, path } = errors[i], state = input.get(this[path]);
48
+ if (!state) {
49
+ continue;
50
50
  }
51
- reactive.errors = messages;
51
+ state.error = `${message[0].toUpperCase()}${message.substring(1)}`;
52
52
  }
53
53
  }
54
54
  });
@@ -1,6 +1,14 @@
1
1
  import action from './action';
2
2
  declare const _default: {
3
3
  action: typeof action;
4
+ input: {
5
+ attributes: (reactive: {
6
+ error: string;
7
+ }) => (element: HTMLInputElement | HTMLSelectElement) => void;
8
+ get: (element?: HTMLInputElement | HTMLSelectElement | undefined) => {
9
+ error: string;
10
+ } | undefined;
11
+ };
4
12
  layout: (data: {
5
13
  action?: any;
6
14
  button?: {
@@ -1,3 +1,4 @@
1
1
  import action from './action';
2
+ import input from './input';
2
3
  import layout from './layout';
3
- export default { action, layout };
4
+ export default { action, input, layout };
@@ -0,0 +1,9 @@
1
+ declare const _default: {
2
+ attributes: (reactive: {
3
+ error: string;
4
+ }) => (element: HTMLInputElement | HTMLSelectElement) => void;
5
+ get: (element?: HTMLInputElement | HTMLSelectElement | undefined) => {
6
+ error: string;
7
+ } | undefined;
8
+ };
9
+ export default _default;
@@ -0,0 +1,10 @@
1
+ let cache = new WeakMap();
2
+ const attributes = (reactive) => {
3
+ return (element) => {
4
+ cache.set(element, reactive);
5
+ };
6
+ };
7
+ const get = (element) => {
8
+ return element ? cache.get(element) : undefined;
9
+ };
10
+ export default { attributes, get };
@@ -2,7 +2,7 @@ import { response, Response } from '@esportsplus/action';
2
2
  import alert from '../../components/alert';
3
3
  type Action = (data: Payload) => Promise<Errors> | Errors;
4
4
  type Errors = {
5
- errors?: Response<unknown>['errors'];
5
+ errors: Response<unknown>['errors'];
6
6
  };
7
7
  type Payload = {
8
8
  alert: typeof alert;
@@ -13,7 +13,4 @@ type Payload = {
13
13
  start: VoidFunction;
14
14
  };
15
15
  };
16
- type Reactive = {
17
- errors?: Record<string, string>;
18
- };
19
- export { Action, Errors, Payload, Reactive };
16
+ export { Action, Errors, Payload };
@@ -3,5 +3,4 @@ export { default as form } from './form';
3
3
  export { default as page } from './page';
4
4
  export { default as root } from './root';
5
5
  export { default as scrollbar } from './scrollbar';
6
- export { default as state } from './state';
7
6
  export { default as tooltip } from './tooltip';
@@ -3,5 +3,4 @@ export { default as form } from './form';
3
3
  export { default as page } from './page';
4
4
  export { default as root } from './root';
5
5
  export { default as scrollbar } from './scrollbar';
6
- export { default as state } from './state';
7
6
  export { default as tooltip } from './tooltip';
@@ -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.21"
41
41
  }
@@ -1,7 +1,8 @@
1
1
  import { response } from '@esportsplus/action';
2
2
  import { html } from '@esportsplus/template';
3
+ import { Action } from './types';
3
4
  import alert from '~/components/alert';
4
- import { Action, Reactive } from './types';
5
+ import input from './input';
5
6
 
6
7
 
7
8
  function parse(input: Record<string, any>) {
@@ -22,7 +23,7 @@ function parse(input: Record<string, any>) {
22
23
  };
23
24
 
24
25
 
25
- export default function(action: Action, reactive: Reactive = {}) {
26
+ export default function(action: Action) {
26
27
  return html({
27
28
  onclick: function(this: HTMLFormElement, event: Event) {
28
29
  let trigger = event.target as HTMLButtonElement;
@@ -60,16 +61,15 @@ export default function(action: Action, reactive: Reactive = {}) {
60
61
  response
61
62
  });
62
63
 
63
- if (errors && 'errors' in reactive) {
64
- let messages: Record<string, string> = {};
64
+ for (let i = 0, n = errors.length; i < n; i++) {
65
+ let { message, path } = errors[i],
66
+ state = input.get( this[path] );
65
67
 
66
- for (let i = 0, n = errors.length; i < n; i++) {
67
- let { message, path } = errors[i];
68
-
69
- messages[path] = `${message[0].toUpperCase()}${message.substring(1)}`;
68
+ if (!state) {
69
+ continue;
70
70
  }
71
71
 
72
- reactive.errors = messages;
72
+ state.error = `${message[0].toUpperCase()}${message.substring(1)}`;
73
73
  }
74
74
  }
75
75
  });
@@ -1,5 +1,6 @@
1
1
  import action from './action';
2
+ import input from './input';
2
3
  import layout from './layout';
3
4
 
4
5
 
5
- export default { action, layout };
6
+ export default { action, input, layout };
@@ -0,0 +1,15 @@
1
+ let cache = new WeakMap<HTMLInputElement | HTMLSelectElement, { error: string }>();
2
+
3
+
4
+ const attributes = (reactive: { error: string }) => {
5
+ return (element: HTMLInputElement | HTMLSelectElement) => {
6
+ cache.set(element, reactive);
7
+ };
8
+ };
9
+
10
+ const get = (element?: HTMLInputElement | HTMLSelectElement) => {
11
+ return element ? cache.get(element) : undefined;
12
+ };
13
+
14
+
15
+ export default { attributes, get };
@@ -4,7 +4,7 @@ import alert from '~/components/alert';
4
4
 
5
5
  type Action = (data: Payload) => Promise<Errors> | Errors;
6
6
 
7
- type Errors = { errors?: Response<unknown>['errors'] };
7
+ type Errors = { errors: Response<unknown>['errors'] };
8
8
 
9
9
  type Payload = {
10
10
  alert: typeof alert;
@@ -16,9 +16,5 @@ type Payload = {
16
16
  }
17
17
  };
18
18
 
19
- type Reactive = {
20
- errors?: Record<string, string>;
21
- };
22
-
23
19
 
24
- export { Action, Errors, Payload, Reactive };
20
+ export { Action, Errors, Payload };
@@ -3,5 +3,4 @@ export { default as form }from './form';
3
3
  export { default as page }from './page';
4
4
  export { default as root }from './root';
5
5
  export { default as scrollbar }from './scrollbar';
6
- export { default as state }from './state';
7
6
  export { default as tooltip }from './tooltip';
@@ -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
  });
@@ -1,22 +0,0 @@
1
- import { reactive } from '@esportsplus/reactivity';
2
- import { html } from '@esportsplus/template';
3
-
4
-
5
- const onfocus = (active: boolean = false) => {
6
- let state = reactive({ active });
7
-
8
- return html({
9
- class: () => {
10
- return state.active ? '--active' : '';
11
- },
12
- onfocusin: () => {
13
- state.active = true;
14
- },
15
- onfocusout: () => {
16
- state.active = false;
17
- }
18
- });
19
- };
20
-
21
-
22
- export default { onfocus };