@esportsplus/ui 0.35.8 → 0.35.9

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
@@ -42,7 +42,7 @@
42
42
  "private": false,
43
43
  "sideEffects": false,
44
44
  "type": "module",
45
- "version": "0.35.8",
45
+ "version": "0.35.9",
46
46
  "scripts": {
47
47
  "build": "run-s build:vite build:ts",
48
48
  "build:ts": "tsc && tsc-alias",
@@ -1,15 +1,9 @@
1
1
  import response, { Response } from '@esportsplus/action';
2
- import { html, Attributes, Element } from '@esportsplus/template';
2
+ import { html, Attributes, Element, Renderable } from '@esportsplus/template';
3
3
  import { omit } from '@esportsplus/utilities';
4
- import template from '~/components/template';
5
4
  import input from './input';
6
5
 
7
6
 
8
- type A = {
9
- action: (data: { input: Record<string, any>, response: typeof response }) => (Promise<Errors> | Errors),
10
- state?: { processing: boolean }
11
- } & Attributes;
12
-
13
7
  type Errors = { errors: Response<unknown>['errors'] };
14
8
 
15
9
 
@@ -46,59 +40,63 @@ function parse(input: ReturnType<FormData['entries']>) {
46
40
  };
47
41
 
48
42
 
49
- export default template.factory<A>(
50
- (attributes, content) => {
51
- let { action, state } = attributes;
52
-
53
- return html`
54
- <form
55
- ${omit(attributes, OMIT)}
56
- ${{
57
- onclick: function(event) {
58
- let trigger = event.target as HTMLButtonElement;
59
-
60
- if (trigger?.type !== 'submit') {
61
- return;
62
- }
63
-
64
- // On initial page load both events will be dispatched without preventDefault
65
- event.preventDefault();
43
+ export default <T extends Record<string, any>>(
44
+ attributes: {
45
+ action: (data: { input: T, response: typeof response }) => (Promise<Errors> | Errors),
46
+ state?: { processing: boolean }
47
+ } & Attributes,
48
+ content: Renderable<any>
49
+ ) => {
50
+ let { action, state } = attributes;
51
+
52
+ return html`
53
+ <form
54
+ ${omit(attributes, OMIT)}
55
+ ${{
56
+ onclick: function(event) {
57
+ let trigger = event.target as HTMLButtonElement;
58
+
59
+ if (trigger?.type !== 'submit') {
60
+ return;
61
+ }
66
62
 
67
- this.dispatchEvent(
68
- new SubmitEvent('submit', { cancelable: true, bubbles:true, submitter: trigger })
69
- );
70
- },
71
- onsubmit: async function(event) {
72
- event.preventDefault();
63
+ // On initial page load both events will be dispatched without preventDefault
64
+ event.preventDefault();
73
65
 
74
- if (state) {
75
- state.processing = true;
76
- }
66
+ this.dispatchEvent(
67
+ new SubmitEvent('submit', { cancelable: true, bubbles:true, submitter: trigger })
68
+ );
69
+ },
70
+ onsubmit: async function(event) {
71
+ event.preventDefault();
77
72
 
78
- let { errors } = await action({
79
- input: parse( new FormData( this as any as HTMLFormElement ).entries() ),
80
- response
81
- });
73
+ if (state) {
74
+ state.processing = true;
75
+ }
82
76
 
83
- for (let i = 0, n = errors.length; i < n; i++) {
84
- let { message, path } = errors[i],
85
- reactive = input.get( (this as any as HTMLFormElement)[path!] as Element | undefined );
77
+ let { errors } = await action({
78
+ input: parse( new FormData( this as any as HTMLFormElement ).entries() ) as T,
79
+ response
80
+ });
86
81
 
87
- if (!reactive) {
88
- continue;
89
- }
82
+ for (let i = 0, n = errors.length; i < n; i++) {
83
+ let { message, path } = errors[i],
84
+ reactive = input.get( (this as any as HTMLFormElement)[path!] as Element | undefined );
90
85
 
91
- reactive.error = `${message[0].toUpperCase()}${message.substring(1)}`;
86
+ if (!reactive) {
87
+ continue;
92
88
  }
93
89
 
94
- if (state) {
95
- state.processing = false;
96
- }
90
+ reactive.error = `${message[0].toUpperCase()}${message.substring(1)}`;
97
91
  }
98
- }}
99
- >
100
- ${content}
101
- </form>
102
- `;
103
- }
104
- );
92
+
93
+ if (state) {
94
+ state.processing = false;
95
+ }
96
+ }
97
+ }}
98
+ >
99
+ ${content}
100
+ </form>
101
+ `;
102
+ };