srcdev-nuxt-components 2.3.1 → 2.3.2

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,11 +1,11 @@
1
1
  <template>
2
2
  <div class="slider-gallery" :class="[elementClasses]" ref="sliderGalleryWrapper">
3
- <div class="loading-state" :class="[{ loaded: !isLoading }]">
3
+ <div class="loading-state" :class="[{ galleryLoaded: !galleryLoaded }]">
4
4
  <div class="loading-spinner"></div>
5
5
  <p>Loading gallery...</p>
6
6
  </div>
7
7
 
8
- <div v-if="showGallery" class="gallery-content" :class="[{ loaded: isLoading }]">
8
+ <div v-if="showGallery" class="gallery-content" :class="[{ galleryLoaded: !galleryLoaded }]">
9
9
  <div class="list" ref="sliderGalleryImagesList">
10
10
  <div v-for="(item, index) in galleryData" :key="index" class="item">
11
11
  <NuxtImg :src="item.src" :alt="item.alt" @load="handleImageLoad(index)" @error="handleImageError(index)" loading="lazy" />
@@ -83,7 +83,8 @@ const sliderGalleryWrapper = useTemplateRef('sliderGalleryWrapper');
83
83
  const sliderGalleryImagesList = useTemplateRef('sliderGalleryImagesList');
84
84
  const sliderGalleryThumbnailsList = useTemplateRef('sliderGalleryThumbnailsList');
85
85
 
86
- const isLoading = ref(true);
86
+ const transitionRunning = ref(false);
87
+ const galleryLoaded = ref(true);
87
88
  const showGallery = ref(false);
88
89
  const loadedImages = ref<Set<number>>(new Set());
89
90
  const preloadedImages = ref<Array<HTMLImageElement>>([]);
@@ -93,7 +94,7 @@ onMounted(async () => {
93
94
 
94
95
  // If no images or galleryData is empty, stop loading
95
96
  if (!galleryData.value || galleryData.value.length === 0) {
96
- isLoading.value = false;
97
+ galleryLoaded.value = false;
97
98
  return;
98
99
  }
99
100
 
@@ -127,27 +128,28 @@ onMounted(async () => {
127
128
  await Promise.race(imageLoadPromises);
128
129
 
129
130
  setTimeout(() => {
130
- isLoading.value = false;
131
+ galleryLoaded.value = false;
131
132
  }, 500);
133
+
134
+ showGallery.value = true;
135
+ window.addEventListener('keydown', handleKeyDown);
132
136
  });
133
137
 
134
138
  const handleImageLoad = (index: number) => {
135
- console.log('Image loaded:', index);
136
139
  loadedImages.value.add(index);
137
140
  };
138
141
 
139
142
  const handleImageError = (index: number) => {
140
- console.error(`Failed to load image at index ${index}`);
141
143
  loadedImages.value.add(index);
142
144
  };
143
145
 
144
146
  const doNext = () => {
145
- if (isLoading.value) return;
147
+ if (transitionRunning.value) return;
146
148
  showSlider('next');
147
149
  };
148
150
 
149
151
  const doPrevious = () => {
150
- if (isLoading.value) return;
152
+ if (transitionRunning.value) return;
151
153
  showSlider('prev');
152
154
  };
153
155
 
@@ -155,6 +157,8 @@ let runTimeOut: any;
155
157
  let runNextAuto: any = null;
156
158
 
157
159
  function showSlider(type: string) {
160
+ transitionRunning.value = true;
161
+
158
162
  const currentSliderItems = Array.from(sliderGalleryImagesList.value?.children || []);
159
163
  const currentThumbnailItems = Array.from(sliderGalleryThumbnailsList.value?.children || []);
160
164
 
@@ -189,31 +193,45 @@ function showSlider(type: string) {
189
193
 
190
194
  clearTimeout(runTimeOut);
191
195
  runTimeOut = setTimeout(() => {
192
- // Your existing cleanup code
196
+
193
197
  if (sliderGalleryWrapper.value) {
194
198
  sliderGalleryWrapper.value.classList.remove('next');
195
199
  sliderGalleryWrapper.value.classList.remove('prev');
196
200
 
197
- // Remove helper classes
198
201
  const items = sliderGalleryImagesList.value?.querySelectorAll('.prepend-item');
199
202
  items?.forEach((item) => item.classList.remove('prepend-item'));
200
203
 
201
204
  const thumbs = sliderGalleryThumbnailsList.value?.querySelectorAll('.prepend-item');
202
205
  thumbs?.forEach((thumb) => thumb.classList.remove('prepend-item'));
203
206
  }
207
+ transitionRunning.value = false;
204
208
  }, props.animationDuration);
205
209
 
206
210
  // Reset auto-run timer
207
211
  clearTimeout(runNextAuto);
208
212
  runNextAuto = setTimeout(() => {
209
- if (!props.autoRun || isLoading.value) return;
213
+ if (!props.autoRun || galleryLoaded.value) return;
210
214
  doNext();
211
215
  }, props.autoRunInterval);
212
216
  }
213
217
 
218
+ // Add keyboard navigation event handlers
219
+ const handleKeyDown = (event: KeyboardEvent) => {
220
+ // Don't process key events if transition is running or gallery isn't loaded
221
+ if (transitionRunning.value || galleryLoaded.value) {
222
+ return;
223
+ }
224
+
225
+ if (event.key === 'ArrowLeft') {
226
+ doPrevious();
227
+ } else if (event.key === 'ArrowRight') {
228
+ doNext();
229
+ }
230
+ };
231
+
214
232
  // Initialize auto-run only after loading completes
215
- watch(isLoading, (isLoadingNow) => {
216
- if (!isLoadingNow && props.autoRun) {
233
+ watch(galleryLoaded, (previousValue, currentValue) => {
234
+ if (!currentValue && props.autoRun) {
217
235
  clearTimeout(runNextAuto);
218
236
  runNextAuto = setTimeout(() => {
219
237
  doNext();
@@ -231,10 +249,7 @@ watch(
231
249
  onBeforeUnmount(() => {
232
250
  clearTimeout(runTimeOut);
233
251
  clearTimeout(runNextAuto);
234
- });
235
-
236
- onMounted(() => {
237
- showGallery.value = true;
252
+ window.removeEventListener('keydown', handleKeyDown);
238
253
  });
239
254
  </script>
240
255
 
@@ -258,6 +273,8 @@ onMounted(() => {
258
273
  position: absolute;
259
274
  inset: 0 0 0 0;
260
275
 
276
+ z-index: 9999;
277
+
261
278
  .loading-state {
262
279
  position: absolute;
263
280
  inset: 0 0 0 0;
@@ -272,7 +289,7 @@ onMounted(() => {
272
289
  transition: display 0.5s, opacity 0.5s;
273
290
  transition-behavior: allow-discrete;
274
291
 
275
- &.loaded {
292
+ &.galleryLoaded {
276
293
  display: none;
277
294
  opacity: 0;
278
295
  }
@@ -300,7 +317,7 @@ onMounted(() => {
300
317
  /* opacity: 0; */
301
318
  /* transition: opacity 0.5s ease-in-out; */
302
319
 
303
- &.loaded {
320
+ &.galleryLoaded {
304
321
  /* opacity: 1; */
305
322
  }
306
323
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "srcdev-nuxt-components",
3
3
  "type": "module",
4
- "version": "2.3.1",
4
+ "version": "2.3.2",
5
5
  "main": "nuxt.config.ts",
6
6
  "scripts": {
7
7
  "clean": "rm -rf .nuxt && rm -rf .output && rm -rf .playground/.nuxt && rm -rf .playground/.output",