free-astro-components 1.2.1 → 1.3.0

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.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/utils/modal.ts +25 -15
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A collection of free Astro components",
4
4
  "author": "Denis Ventura",
5
5
  "type": "module",
6
- "version": "1.2.1",
6
+ "version": "1.3.0",
7
7
  "exports": {
8
8
  ".": {
9
9
  "import": {
@@ -22,11 +22,11 @@
22
22
  "astro": "astro"
23
23
  },
24
24
  "dependencies": {
25
- "@astrojs/check": "^0.9.4",
26
- "astro": "^5.11.0",
25
+ "@astrojs/check": "^0.9.7",
26
+ "astro": "^6.0.3",
27
27
  "typescript": "^5.5.3"
28
28
  },
29
29
  "devDependencies": {
30
30
  "prettier": "^3.3.3"
31
31
  }
32
- }
32
+ }
@@ -1,5 +1,19 @@
1
1
  import { isTouchDevice } from '../utils/utils'
2
2
 
3
+ const runCloseCleanup = (modal: HTMLDialogElement) => {
4
+ const body = document.body
5
+ if (isTouchDevice()) {
6
+ disableTouchControls(modal)
7
+ }
8
+ setTimeout(() => {
9
+ modal.classList.add('ac-modal--close')
10
+ modal.style.removeProperty('transform')
11
+ modal.style.removeProperty('opacity')
12
+ modal.style.removeProperty('transition')
13
+ body.style.overflow = 'auto'
14
+ }, 200)
15
+ }
16
+
3
17
  export const openModal = (modal: HTMLDialogElement) => {
4
18
  const body = document.body
5
19
 
@@ -11,6 +25,14 @@ export const openModal = (modal: HTMLDialogElement) => {
11
25
  enableTouchControls(modal)
12
26
  }
13
27
 
28
+ modal.addEventListener(
29
+ 'close',
30
+ () => {
31
+ runCloseCleanup(modal)
32
+ },
33
+ { once: true },
34
+ )
35
+
14
36
  modal.addEventListener(
15
37
  'click',
16
38
  (event) => {
@@ -23,20 +45,8 @@ export const openModal = (modal: HTMLDialogElement) => {
23
45
  }
24
46
 
25
47
  export const closeModal = (modal: HTMLDialogElement) => {
26
- const body = document.body
27
48
  modal.classList.add('ac-modal--animated')
28
-
29
49
  modal.close()
30
- if (isTouchDevice()) {
31
- disableTouchControls(modal)
32
- }
33
- setTimeout(() => {
34
- modal.classList.add('ac-modal--close')
35
- modal.style.removeProperty('transform')
36
- modal.style.removeProperty('opacity')
37
- modal.style.removeProperty('transition')
38
- body.style.overflow = 'auto'
39
- }, 200)
40
50
  }
41
51
 
42
52
  const enableTouchControls = (modal: HTMLDialogElement) => {
@@ -98,9 +108,9 @@ const enableTouchControls = (modal: HTMLDialogElement) => {
98
108
  modal.addEventListener('touchstart', handleTouchStart, { passive: true })
99
109
  modal.addEventListener('touchmove', handleTouchMove, { passive: true })
100
110
  modal.addEventListener('touchend', handleTouchEnd, { passive: true })
101
- ;(modal as any).handleTouchStart = handleTouchStart
102
- ;(modal as any).handleTouchMove = handleTouchMove
103
- ;(modal as any).handleTouchEnd = handleTouchEnd
111
+ ; (modal as any).handleTouchStart = handleTouchStart
112
+ ; (modal as any).handleTouchMove = handleTouchMove
113
+ ; (modal as any).handleTouchEnd = handleTouchEnd
104
114
  }
105
115
 
106
116
  const disableTouchControls = (modal: HTMLDialogElement) => {