winduum 3.0.0-next.5 → 3.0.0-next.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": "winduum",
3
- "version": "3.0.0-next.5",
3
+ "version": "3.0.0-next.7",
4
4
  "type": "module",
5
5
  "types": "types/index.d.ts",
6
6
  "main": "plugin/index.cjs",
@@ -23,27 +23,27 @@
23
23
  "@floating-ui/dom": "^1.7.6",
24
24
  "@stylistic/eslint-plugin": "^5.10.0",
25
25
  "@stylistic/stylelint-config": "^5.0.0",
26
- "@tailwindcss/vite": "^4.3.0",
26
+ "@tailwindcss/vite": "^4.3.2",
27
27
  "@vitejs/plugin-vue": "^6.0.7",
28
28
  "@webreflection/custom-elements-builtin": "^0.4.1",
29
- "autoprefixer": "^10.5.0",
30
- "dts-buddy": "^0.8.0",
31
- "eslint": "^10.4.1",
29
+ "autoprefixer": "^10.5.2",
30
+ "dts-buddy": "^0.8.2",
31
+ "eslint": "^10.6.0",
32
32
  "fast-glob": "^3.3.3",
33
- "globals": "^17.6.0",
33
+ "globals": "^17.7.0",
34
34
  "invokers-polyfill": "^1.0.3",
35
- "postcss": "^8.5.15",
35
+ "postcss": "^8.5.16",
36
36
  "postcss-custom-media": "^12.0.1",
37
37
  "postcss-import": "^16.1.1",
38
38
  "postcss-nesting": "^14.0.0",
39
39
  "slide-element": "^2.3.1",
40
- "stylelint": "^17.12.0",
40
+ "stylelint": "^17.14.0",
41
41
  "stylelint-config-standard": "^40.0.0",
42
- "tailwindcss": "^4.3.0",
42
+ "tailwindcss": "^4.3.2",
43
43
  "typescript": "^6",
44
- "vite": "^8.0.16",
45
- "vue": "^3.5.35",
46
- "webuum": "^0.1.0"
44
+ "vite": "^8.1.3",
45
+ "vue": "^3.5.39",
46
+ "webuum": "^0.2.1"
47
47
  },
48
48
  "files": [
49
49
  "index.js",
@@ -1,5 +1,5 @@
1
1
  export interface ValidateFormOptions {
2
- validateSelectors?: string
2
+ validateSelector?: string
3
3
  validateOptions?: ValidateFieldOptions
4
4
  validateField?: typeof validateField
5
5
  scrollOptions?: ScrollIntoViewOptions
@@ -7,23 +7,16 @@ export interface ValidateFormOptions {
7
7
  }
8
8
 
9
9
  export interface ValidateFieldOptions {
10
- validate?: boolean
11
10
  validationMessage?: string
12
11
  selector?: string
13
- ignoreMatch?: RegExp
14
12
  validitySelector?: string
15
- infoParentSelector?: string
16
- infoSelector?: string
17
13
  infoContent?: string
18
- endParentSelector?: string
19
- endSelector?: string
20
- endContent?: string
21
- validAttribute?: string
14
+ iconParentSelector?: string
15
+ iconSelector?: string
16
+ iconContent?: string
22
17
  validIcon?: string | null
23
- invalidAttribute?: string
24
18
  invalidIcon?: string
25
- activeAttribute?: string
26
19
  }
27
20
 
28
21
  export function validateForm(event: Event | SubmitEvent, options?: ValidateFormOptions): void
29
- export function validateField(element: HTMLElement | SubmitEvent, options?: ValidateFieldOptions): void
22
+ export function validateField(element: HTMLElement, options?: ValidateFieldOptions): void
@@ -5,30 +5,26 @@
5
5
  */
6
6
  export const validateForm = (event, options = {}) => {
7
7
  options = {
8
- validateSelectors: '.x-control, .x-check, .x-switch, .x-rating, .x-color',
9
- validateOptions: {
10
- validate: true,
11
- },
8
+ validateSelector: '.x-field',
9
+ validateOptions: {},
12
10
  validateField,
13
11
  submitterLoadingAttribute: 'data-loading',
14
12
  scrollOptions: { behavior: 'smooth', block: 'center' },
15
13
  ...options,
16
14
  }
17
15
 
18
- if (options.validateOptions.validate) {
19
- if (!event.target.checkValidity()) {
20
- event.preventDefault()
21
- event.stopImmediatePropagation()
16
+ if (!event.target.checkValidity()) {
17
+ event.preventDefault()
18
+ event.stopImmediatePropagation()
22
19
 
23
- event.target.querySelector(':invalid').scrollIntoView(options.scrollOptions)
24
- event.target.querySelector(':invalid').focus()
25
- }
26
- else if (options.submitterLoadingAttribute) {
27
- event?.submitter?.setAttribute(options.submitterLoadingAttribute, '')
28
- }
20
+ event.target.querySelector(':invalid').scrollIntoView(options.scrollOptions)
21
+ event.target.querySelector(':invalid').focus()
22
+ }
23
+ else if (options.submitterLoadingAttribute) {
24
+ event?.submitter?.setAttribute(options.submitterLoadingAttribute, '')
29
25
  }
30
26
 
31
- event.target.querySelectorAll(options.validateSelectors).forEach((element) => {
27
+ event.target.querySelectorAll(options.validateSelector).forEach((element) => {
32
28
  options.validateField(element, options.validateOptions)
33
29
  })
34
30
  }
@@ -40,74 +36,42 @@ export const validateForm = (event, options = {}) => {
40
36
  */
41
37
  export const validateField = (element, options = {}) => {
42
38
  options = {
43
- validate: true,
44
- selector: 'input:not([type="hidden"]), textarea, select',
45
- ignoreMatch: /(data-novalidate|readonly)/,
46
- validitySelector: '.validity',
47
- infoParentSelector: '.x-field',
48
- infoSelector: '.x-info',
49
- infoContent: '<div class="x-info text-error validity"></div>',
50
- endParentSelector: '.x-control',
51
- endSelector: '.ms-auto',
52
- endContent: '<div class="ms-auto"></div>',
53
- validAttribute: 'data-valid',
39
+ selector: ':is(input:not([type="hidden"]), textarea, select):not([readonly], [data-novalidate])',
40
+ validitySelector: '[data-validity]',
41
+ infoContent: '<div class="x-info text-error" data-validity></div>',
42
+ iconParentSelector: '.x-control',
43
+ iconSelector: '.ms-auto',
44
+ iconContent: '<div class="ms-auto"></div>',
54
45
  validIcon: null,
55
- invalidAttribute: 'data-invalid',
56
- invalidIcon: '<svg class="text-error validity" aria-hidden="true"><use href="#icon-exclamation-circle"></use></svg>',
57
- activeAttribute: 'data-active',
46
+ invalidIcon: '<svg class="text-error" data-validity aria-hidden="true"><use href="#heroicons-outline/exclamation-circle"></use></svg>',
58
47
  ...options,
59
48
  }
60
49
 
61
- const validationElement = /** @type {HTMLInputElement} */ (element.querySelector(options.selector))
62
-
63
- if (!validationElement) return
50
+ const validationElements = [...element.querySelectorAll(options.selector)]
64
51
 
65
- const validationMessage = options.validationMessage ?? validationElement.dataset.validationMessage ?? validationElement.validationMessage
66
- const infoParentElement = validationElement?.closest(options.infoParentSelector)
67
- const endParentElement = validationElement.closest(options.endParentSelector)
68
- const infoSelector = options.infoSelector + options.validitySelector
69
- const endSelector = `${options.endSelector} ${options.validitySelector}`
52
+ if (!validationElements.length) return
70
53
 
71
- const insertIcon = (icon) => {
72
- if (!endParentElement || !icon) return
54
+ element.querySelectorAll(options.validitySelector).forEach(el => el.remove())
73
55
 
74
- if (!element?.querySelector(options.endSelector)) {
75
- element?.insertAdjacentHTML('beforeend', options.endContent)
76
- }
56
+ const invalidElements = validationElements.filter(validationElement => !validationElement.checkValidity())
77
57
 
78
- element.querySelector(options.endSelector).insertAdjacentHTML('afterbegin', icon)
79
- }
58
+ validationElements.forEach((validationElement) => {
59
+ const icon = invalidElements.includes(validationElement) ? options.invalidIcon : options.validIcon
60
+ const iconParentElement = validationElement.closest(options.iconParentSelector)
80
61
 
81
- if (validationElement.value !== '') {
82
- element.setAttribute(options.activeAttribute, '')
83
- }
84
- else {
85
- element.removeAttribute(options.activeAttribute)
86
- }
62
+ if (!iconParentElement || !icon) return
87
63
 
88
- if (!validationElement.outerHTML.match(options.ignoreMatch) && options.validate) {
89
- element?.removeAttribute(options.validAttribute)
90
- element?.removeAttribute(options.invalidAttribute)
91
-
92
- infoParentElement?.querySelector(infoSelector)?.remove()
93
- endParentElement?.querySelector(endSelector)?.remove()
94
-
95
- if (validationElement.checkValidity()) {
96
- element.setAttribute(options.validAttribute, '')
97
-
98
- insertIcon(options.validIcon)
64
+ if (!iconParentElement.querySelector(options.iconSelector)) {
65
+ iconParentElement.insertAdjacentHTML('beforeend', options.iconContent)
99
66
  }
100
- else {
101
- element.setAttribute(options.invalidAttribute, '')
102
67
 
103
- insertIcon(options.invalidIcon)
68
+ iconParentElement.querySelector(options.iconSelector).insertAdjacentHTML('afterbegin', icon)
69
+ })
104
70
 
105
- if (infoParentElement) {
106
- infoParentElement.insertAdjacentHTML('beforeend', options.infoContent)
107
- infoParentElement.querySelector(infoSelector).textContent = validationMessage
108
- }
109
- }
110
- }
71
+ if (!invalidElements.length) return
72
+
73
+ element.insertAdjacentHTML('beforeend', options.infoContent)
74
+ element.lastElementChild.textContent = options.validationMessage ?? invalidElements[0].dataset.validationMessage ?? invalidElements[0].validationMessage
111
75
  }
112
76
 
113
77
  export default {
package/types/index.d.ts CHANGED
@@ -121,7 +121,7 @@ declare module 'winduum/src/components/drawer' {
121
121
 
122
122
  declare module 'winduum/src/components/form' {
123
123
  export interface ValidateFormOptions {
124
- validateSelectors?: string
124
+ validateSelector?: string
125
125
  validateOptions?: ValidateFieldOptions
126
126
  validateField?: typeof validateField
127
127
  scrollOptions?: ScrollIntoViewOptions
@@ -129,26 +129,19 @@ declare module 'winduum/src/components/form' {
129
129
  }
130
130
 
131
131
  export interface ValidateFieldOptions {
132
- validate?: boolean
133
132
  validationMessage?: string
134
133
  selector?: string
135
- ignoreMatch?: RegExp
136
134
  validitySelector?: string
137
- infoParentSelector?: string
138
- infoSelector?: string
139
135
  infoContent?: string
140
- endParentSelector?: string
141
- endSelector?: string
142
- endContent?: string
143
- validAttribute?: string
136
+ iconParentSelector?: string
137
+ iconSelector?: string
138
+ iconContent?: string
144
139
  validIcon?: string | null
145
- invalidAttribute?: string
146
140
  invalidIcon?: string
147
- activeAttribute?: string
148
141
  }
149
142
 
150
143
  export function validateForm(event: Event | SubmitEvent, options?: ValidateFormOptions): void
151
- export function validateField(element: HTMLElement | SubmitEvent, options?: ValidateFieldOptions): void
144
+ export function validateField(element: HTMLElement, options?: ValidateFieldOptions): void
152
145
 
153
146
  export {};
154
147
  }