well-waterfall 1.0.15 → 1.0.16
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 +1 -1
- package/src/index.ts +6 -6
- package/src/lib/attributes.ts +6 -2
- package/src/modules/manipulation.ts +47 -40
- package/src/util.ts +0 -3
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
ATTR_DEBUG_MODE,
|
|
28
28
|
ATTR_PLAYBACK_MODE,
|
|
29
29
|
ATTR_THUMBS,
|
|
30
|
+
ATTR_CONTROLLER,
|
|
30
31
|
} from "./lib/attributes";
|
|
31
32
|
import { debugConfig, debugConfigUncleaned, debugInit } from "lib/debug";
|
|
32
33
|
|
|
@@ -45,18 +46,18 @@ function initAll(selector: string) {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
// Initialize Thumb Sliders first
|
|
48
|
-
initAll(`[${ATTR_WATERFALL}][${
|
|
49
|
+
initAll(`[${ATTR_WATERFALL}][${ATTR_THUMBS}]`);
|
|
49
50
|
|
|
50
51
|
// Initialize all other sliders
|
|
51
52
|
document.querySelectorAll(`[${ATTR_WATERFALL}]`).forEach((el, index) => {
|
|
52
|
-
if (el.getAttribute(
|
|
53
|
-
|
|
53
|
+
if (el.getAttribute(ATTR_THUMBS) === "true" || el.getAttribute(ATTR_CONTROLLER)) return;
|
|
54
54
|
initConfig(el as HTMLElement, index);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
// Initialize
|
|
58
|
-
initAll(`[${ATTR_WATERFALL}][${
|
|
57
|
+
// Initialize Controller Sliders last
|
|
58
|
+
initAll(`[${ATTR_WATERFALL}][${ATTR_CONTROLLER}]`);
|
|
59
59
|
|
|
60
|
+
// Config
|
|
60
61
|
function initConfig(el: HTMLElement, index: number) {
|
|
61
62
|
{
|
|
62
63
|
const name = parseString(el, ATTR_WATERFALL, `Swiper ${index}`);
|
|
@@ -143,7 +144,6 @@ function initConfig(el: HTMLElement, index: number) {
|
|
|
143
144
|
console.warn(`Skipping "${name}": no .swiper-slide elements found.`);
|
|
144
145
|
return;
|
|
145
146
|
}
|
|
146
|
-
// INIT SWIPER
|
|
147
147
|
const swiper = new Swiper(swiperEl as HTMLElement, config);
|
|
148
148
|
waterfalls.push({ name, swiper });
|
|
149
149
|
}
|
package/src/lib/attributes.ts
CHANGED
|
@@ -182,8 +182,6 @@ export const ATTR_MOUSE_THRESHOLD_TIME = "waterfall-mouse-threshold-time";
|
|
|
182
182
|
// Grid
|
|
183
183
|
export const ATTR_GRID_ROWS = "waterfall-grid-rows";
|
|
184
184
|
export const ATTR_GRID_FILL = "waterfall-grid-fill";
|
|
185
|
-
// Manipulation
|
|
186
|
-
export const ATTR_MANIPULATION_ADD_SLIDE = "waterfall-wtf-add-slide";
|
|
187
185
|
// Navigation
|
|
188
186
|
export const ATTR_NAVIGATION_DISABLED_CLASS = "waterfall-navigation-disabled-class";
|
|
189
187
|
export const ATTR_NAVIGATION_ENABLED = "waterfall-navigation-enabled";
|
|
@@ -246,6 +244,12 @@ export const ATTR_THUMBS_AUTO_SCROLL_OFFSET = "waterfall-thumbs-auto-scroll-offs
|
|
|
246
244
|
export const ATTR_THUMBS_MULTIPLE_ACTIVE_THUMBS = "waterfall-thumbs-multiple-active-thumbs";
|
|
247
245
|
export const ATTR_THUMBS_SLIDE_THUMB_ACTIVE_CLASS = "waterfall-slide-thumb-active-class";
|
|
248
246
|
export const ATTR_THUMBS_CONTAINER_CLASS = "waterfall-thumbs-container-class";
|
|
247
|
+
// Manipulation
|
|
248
|
+
export const ATTR_MANIPULATION_ADD_SLIDE = "waterfall-add-slide";
|
|
249
|
+
export const ATTR_MANIPULATION_APPEND_SLIDE = "waterfall-append-slide";
|
|
250
|
+
export const ATTR_MANIPULATION_PREPEND_SLIDE = "waterfall-prepend-slide";
|
|
251
|
+
export const ATTR_MANIPULATION_REMOVE_SLIDE = "waterfall-remove-slide";
|
|
252
|
+
export const ATTR_MANIPULATION_REMOVE_ALL_SLIDES = "waterfall-remove-all-slides";
|
|
249
253
|
// Zoom
|
|
250
254
|
export const ATTR_ZOOM = "waterfall-zoom";
|
|
251
255
|
export const ATTR_ZOOM_ENABLED = "waterfall-zoom-enabled";
|
|
@@ -1,59 +1,66 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ATTR_MANIPULATION_ADD_SLIDE,
|
|
3
|
+
ATTR_MANIPULATION_APPEND_SLIDE,
|
|
4
|
+
ATTR_MANIPULATION_PREPEND_SLIDE,
|
|
5
|
+
ATTR_MANIPULATION_REMOVE_SLIDE,
|
|
6
|
+
} from "../lib/attributes";
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
8
|
+
// Generic handler
|
|
9
|
+
function handleSlideManipulation(attr: string, action: "append" | "prepend" | "remove") {
|
|
5
10
|
if (!Array.isArray(window.waterfalls)) {
|
|
6
|
-
console.error(
|
|
7
|
-
"[SlideAdder] window.waterfalls is not an array or not defined.",
|
|
8
|
-
);
|
|
11
|
+
console.error("window.waterfalls is not an array or not defined.");
|
|
9
12
|
return;
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
addSlideElements.forEach((el) => {
|
|
21
|
-
// Get the target Waterfall name from the attribute
|
|
22
|
-
const targetName = el.getAttribute(ATTR_MANIPULATION_ADD_SLIDE);
|
|
23
|
-
// Find the matchhing Waterfall by name
|
|
24
|
-
const matchedWaterfall = window.waterfalls.find(
|
|
25
|
-
(wf) => wf.name === targetName,
|
|
26
|
-
);
|
|
15
|
+
const dynListsToRemove = new Set<Element>();
|
|
16
|
+
|
|
17
|
+
document.querySelectorAll(`[${attr}]`).forEach((el) => {
|
|
18
|
+
const targetName = el.getAttribute(attr);
|
|
19
|
+
const matchedWaterfall = window.waterfalls.find((wf) => wf.name === targetName);
|
|
20
|
+
|
|
27
21
|
if (!matchedWaterfall) {
|
|
28
|
-
console.warn(
|
|
29
|
-
`[SlideAdder] No Waterfall found with name: "${targetName}"`,
|
|
30
|
-
);
|
|
22
|
+
console.warn(`[MANIPULATION] No Waterfall found with name: "${targetName}"`);
|
|
31
23
|
return;
|
|
32
24
|
}
|
|
33
25
|
|
|
34
26
|
const swiper = matchedWaterfall.swiper;
|
|
35
|
-
if (!swiper
|
|
36
|
-
console.error(
|
|
37
|
-
`[SlideAdder] Invalid Swiper instance in Waterfall "${targetName}"`,
|
|
38
|
-
);
|
|
27
|
+
if (!swiper) {
|
|
28
|
+
console.error(`[MANIPULATION] Invalid Swiper instance in Waterfall "${targetName}"`);
|
|
39
29
|
return;
|
|
40
30
|
}
|
|
41
31
|
|
|
42
|
-
|
|
43
|
-
el.removeAttribute(ATTR_MANIPULATION_ADD_SLIDE);
|
|
32
|
+
el.removeAttribute(attr);
|
|
44
33
|
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
if (action === "append" && typeof swiper.appendSlide === "function") {
|
|
35
|
+
swiper.appendSlide(el.outerHTML);
|
|
36
|
+
} else if (action === "prepend" && typeof swiper.prependSlide === "function") {
|
|
37
|
+
swiper.prependSlide(el.outerHTML);
|
|
38
|
+
} else if (action === "remove" && typeof swiper.removeSlide === "function") {
|
|
39
|
+
// Find the index of the slide in the swiper
|
|
40
|
+
const slideIndex = Array.from(swiper.slides).findIndex((slide) => slide.outerHTML === el.outerHTML);
|
|
41
|
+
if (slideIndex !== -1) {
|
|
42
|
+
swiper.removeSlide(slideIndex);
|
|
43
|
+
} else {
|
|
44
|
+
console.warn(`[MANIPULATION] Slide not found in Swiper for removal: ${targetName}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
47
|
|
|
48
|
-
// Track parent .w-dyn-list
|
|
49
48
|
const dynList = el.closest(".w-dyn-list");
|
|
50
|
-
if (dynList)
|
|
51
|
-
dynListsToRemove.add(dynList);
|
|
52
|
-
}
|
|
49
|
+
if (dynList) dynListsToRemove.add(dynList);
|
|
53
50
|
});
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
dynListsToRemove.forEach((list) => list.remove());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function addSlides() {
|
|
56
|
+
handleSlideManipulation(ATTR_MANIPULATION_ADD_SLIDE, "append");
|
|
57
|
+
}
|
|
58
|
+
export function appendSlides() {
|
|
59
|
+
handleSlideManipulation(ATTR_MANIPULATION_APPEND_SLIDE, "append");
|
|
60
|
+
}
|
|
61
|
+
export function prependSlides() {
|
|
62
|
+
handleSlideManipulation(ATTR_MANIPULATION_PREPEND_SLIDE, "prepend");
|
|
63
|
+
}
|
|
64
|
+
export function removeSlides() {
|
|
65
|
+
handleSlideManipulation(ATTR_MANIPULATION_REMOVE_SLIDE, "remove");
|
|
59
66
|
}
|
package/src/util.ts
CHANGED
|
@@ -92,12 +92,9 @@ export function removeNullOrUndefinedKeys<T extends Record<string, any>>(obj: T)
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
export function getSwipersByName(waterfalls: Waterfall[], selector: string, debug: boolean): Swiper[] {
|
|
95
|
-
debug && console.log("🔍 getSwipersByName called with selector:", selector);
|
|
96
|
-
|
|
97
95
|
const matchedSwipers = waterfalls
|
|
98
96
|
.filter((w) => {
|
|
99
97
|
const match = w.name === selector;
|
|
100
|
-
debug && console.log(` 🔎 Checking "${w.name}" → ${match ? "✅ match" : "❌ no match"}`);
|
|
101
98
|
return match;
|
|
102
99
|
})
|
|
103
100
|
.map((w) => w.swiper);
|