@inizioevoke/astro-core 1.3.3 → 1.3.4

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": "@inizioevoke/astro-core",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -17,7 +17,7 @@
17
17
  "index.ts"
18
18
  ],
19
19
  "peerDependencies": {
20
- "astro": ">=6.0.0",
20
+ "astro": ">=5.0.0",
21
21
  "typescript": ">=5.0.0"
22
22
  },
23
23
  "devDependencies": {
@@ -5,8 +5,11 @@ interface ModalEventCallbackItem {
5
5
  once?: boolean;
6
6
  callback: ModalEventCallback;
7
7
  }
8
+ interface ModalEventCallbackArgs {
9
+ once?: boolean
10
+ }
8
11
 
9
- type ModalEventType = 'show' | 'hide';
12
+ type ModalEventType = 'show' | 'hide' | 'overlay';
10
13
  type ModalEventTypeCallbacks = Record<ModalEventType, Set<ModalEventCallbackItem>>;
11
14
  const callbacks = new Map<HTMLElement, ModalEventTypeCallbacks>();
12
15
 
@@ -50,7 +53,7 @@ function __showOverlay(animation: ModalAnimation) {
50
53
  overlay.classList.add('evo-modal-visible', `evo-modal-show-${animation}`);
51
54
  }
52
55
  }
53
- export function onShow(selector: string | HTMLElement, callback: ModalEventCallback, { once }: { once?: boolean } = {}) {
56
+ export function onShow(selector: string | HTMLElement, callback: ModalEventCallback, { once }: ModalEventCallbackArgs = {}) {
54
57
  onEvent('show', selector, { once, callback });
55
58
  }
56
59
 
@@ -105,7 +108,7 @@ function __hide(modal: HTMLElement, animation: ModalAnimation) {
105
108
  }, animation !== 'none' ? animationDuration : 0);
106
109
  });
107
110
  }
108
- export function onHide(selector: string | HTMLElement, callback: ModalEventCallback, { once }: { once?: boolean } = {}) {
111
+ export function onHide(selector: string | HTMLElement, callback: ModalEventCallback, { once }: ModalEventCallbackArgs = {}) {
109
112
  onEvent('hide', selector, { once, callback });
110
113
  }
111
114
 
@@ -120,6 +123,10 @@ export function appendOverlay(selector: string | HTMLElement) {
120
123
  }
121
124
  }
122
125
 
126
+ export function onOverlayClick(callback: ModalEventCallback, { once }: ModalEventCallbackArgs = {}) {
127
+ onEvent('overlay', overlay, { once, callback });
128
+ }
129
+
123
130
  function onEvent(type: ModalEventType, selector: string | HTMLElement, callbackItem: ModalEventCallbackItem) {
124
131
  let modal = typeof selector == 'string' ? document.querySelector<HTMLElement>(/^[\.#]/.test(selector) ? selector : `#${selector}`) : selector;
125
132
  if (modal) {
@@ -132,15 +139,15 @@ function onEvent(type: ModalEventType, selector: string | HTMLElement, callbackI
132
139
  }
133
140
  }
134
141
 
135
- function triggerEventCallbacks(modal: HTMLElement, eventType: 'show' | 'hide') {
136
- if (modal) {
137
- const modalCallbacks = callbacks.get(modal);
138
- if (modalCallbacks && modalCallbacks[eventType]) {
139
- const items = [...modalCallbacks[eventType]];
142
+ function triggerEventCallbacks(element: HTMLElement, eventType: ModalEventType) {
143
+ if (element) {
144
+ const eventCallbacks = callbacks.get(element);
145
+ if (eventCallbacks && eventCallbacks[eventType]) {
146
+ const items = [...eventCallbacks[eventType]];
140
147
  const keep: ModalEventCallbackItem[] = [];
141
148
  for (const item of items) {
142
149
  try {
143
- item.callback(modal);
150
+ item.callback(element);
144
151
  } catch (err) {
145
152
  console.log(err);
146
153
  } finally {
@@ -149,7 +156,7 @@ function triggerEventCallbacks(modal: HTMLElement, eventType: 'show' | 'hide') {
149
156
  }
150
157
  }
151
158
  }
152
- callbacks.set(modal, {...modalCallbacks, [eventType]: new Set(keep)});
159
+ callbacks.set(element, {...eventCallbacks, [eventType]: new Set(keep)});
153
160
  }
154
161
  }
155
162
  }
@@ -163,6 +170,7 @@ const overlay: HTMLElement = document.querySelector<HTMLElement>('.evo-modal-ove
163
170
  })();
164
171
  overlay.addEventListener('click', () => {
165
172
  hide();
173
+ triggerEventCallbacks(overlay, 'overlay');
166
174
  });
167
175
 
168
176
  const animationDuration = (() => {
@@ -1 +1,14 @@
1
- <div class="evo-modal-overlay"></div>
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ interface Props extends HTMLAttributes<'div'> {
5
+ class?: string;
6
+ }
7
+
8
+ const {
9
+ class: cssClass,
10
+ ...rest
11
+ } = Astro.props;
12
+
13
+ ---
14
+ <div class:list={['evo-modal-overlay', cssClass]} {...rest}><slot /></div>