well-waterfall 1.2.9 → 1.2.11

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/dist/util.d.ts CHANGED
@@ -8,5 +8,6 @@ export declare function parseAny(el: HTMLElement, attrName: string, defaultValue
8
8
  export declare function parseNumber(el: HTMLElement, attrName: string, defaultValue?: number): number | undefined;
9
9
  export declare function parseBoolean(el: HTMLElement, attrName: string, defaultValue?: boolean): boolean | undefined;
10
10
  export declare function removeNullOrUndefinedKeys<T extends Record<string, any>>(obj: T): T;
11
- export declare function getSwipersByName(waterfalls: Waterfall[], selector: string, debug: boolean): Swiper[];
11
+ export declare function getWaterfallByName(waterfalls: Waterfall[], name: string): Waterfall | undefined;
12
+ export declare function getWaterfallsByName(waterfalls: Waterfall[], selector: string, debug: boolean): Swiper[];
12
13
  export declare function fixWebflowCMSListARIARole(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "well-waterfall",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "description": "Create Swipers in Webflow with attributes",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -25,7 +25,7 @@
25
25
  "license": "ISC",
26
26
  "dependencies": {
27
27
  "fs": "^0.0.1-security",
28
- "swiper": "^11.2.10"
28
+ "swiper": "^14.0.7"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/jquery": "^3.5.32",
@@ -40,5 +40,9 @@
40
40
  "vite": "^7.1.2",
41
41
  "vite-plugin-css-injected-by-js": "^3.5.2",
42
42
  "vite-plugin-dts": "^4.5.4"
43
+ },
44
+ "allowScripts": {
45
+ "esbuild@0.28.1": true,
46
+ "fsevents@2.3.3": true
43
47
  }
44
48
  }
package/src/index.ts CHANGED
@@ -60,9 +60,6 @@ document.addEventListener("DOMContentLoaded", () => {
60
60
  indexCounter = initAll(`[${ATTR_WATERFALL}][${ATTR_THUMBS}]`, indexCounter);
61
61
  indexCounter = initAll(`[${ATTR_WATERFALL}][${ATTR_CONTROLLER}]`, indexCounter);
62
62
 
63
- // MANIPULATION
64
- manipulateSlides();
65
-
66
63
  // SLIDE COUNT
67
64
  initSlideCount();
68
65
 
@@ -105,6 +102,9 @@ function initConfig(el: HTMLElement, index: number) {
105
102
  parallaxConfig(swiperConfig, el);
106
103
  advancedConfig(swiperConfig, el);
107
104
 
105
+ // MANIPULATION - Add or remove slides
106
+ manipulateSlides();
107
+
108
108
  // Clean up the config and debug
109
109
  if (debug) console.warn(swiperConfig);
110
110
  const config: SwiperOptions = removeNullOrUndefinedKeys(swiperConfig);
@@ -6,7 +6,7 @@ export const ATTR_WATERFALL_CONTENT = "waterfall-content";
6
6
  // Debug
7
7
  export const ATTR_DEBUG_MODE = "waterfall-debug-mode";
8
8
  export const ATTR_ADVANCED_DEBUG_MODE = "waterfall-advanced-debug-mode";
9
- // A11Y
9
+ // A11Y`
10
10
  export const ATTR_A11Y = "waterfall-a11y";
11
11
  export const ATTR_A11Y_CONTAINER_MESSAGE = "waterfall-a11y-container-message";
12
12
  export const ATTR_A11Y_CONTAINER_ROLE = "waterfall-a11y-container-role";
@@ -1,5 +1,5 @@
1
1
  import { Waterfall } from "types/waterfall";
2
- import { getSwipersByName, parseAny, parseBoolean, parseString } from "../util";
2
+ import { getWaterfallsByName, parseAny, parseBoolean, parseString } from "../util";
3
3
  import Swiper from "swiper";
4
4
  import { ATTR_CONTROLLER, ATTR_CONTROLLER_BY, ATTR_CONTROLLER_INVERSE } from "../lib/attributes";
5
5
  import { SwiperOptions } from "swiper/types";
@@ -7,7 +7,7 @@ import { SwiperOptions } from "swiper/types";
7
7
  export function controllerConfig(config: SwiperOptions, el: HTMLElement, waterfalls: Waterfall[], debug: boolean) {
8
8
  const controllerSelector = parseString(el, ATTR_CONTROLLER, "");
9
9
  if (!controllerSelector) return;
10
- const swipers: Swiper[] = getSwipersByName(waterfalls, controllerSelector, debug);
10
+ const swipers: Swiper[] = getWaterfallsByName(waterfalls, controllerSelector, debug);
11
11
 
12
12
  if (debug) {
13
13
  if (!swipers.length) console.error(`No controller swipers found for selector "${controllerSelector}"`);
@@ -6,6 +6,7 @@ import {
6
6
  ATTR_MANIPULATION_REMOVE_INDEX,
7
7
  ATTR_MANIPULATION_REMOVE_SLIDE,
8
8
  } from "../lib/attributes";
9
+ import { getWaterfallByName } from "../util";
9
10
 
10
11
  function handleSlideManipulation(attr: string, action: "append" | "prepend" | "remove" | "add") {
11
12
  if (!Array.isArray(window.waterfalls)) {
@@ -17,7 +18,8 @@ function handleSlideManipulation(attr: string, action: "append" | "prepend" | "r
17
18
 
18
19
  document.querySelectorAll(`[${attr}]`).forEach((el) => {
19
20
  const targetName = el.getAttribute(attr);
20
- const matchedWaterfall = window.waterfalls.find((wf) => wf.name === targetName);
21
+ if (!targetName) return;
22
+ const matchedWaterfall = getWaterfallByName(window.waterfalls, targetName);
21
23
 
22
24
  if (!matchedWaterfall) {
23
25
  console.warn(`[MANIPULATION] No Waterfall found with name: "${targetName}"`);
@@ -30,14 +32,33 @@ function handleSlideManipulation(attr: string, action: "append" | "prepend" | "r
30
32
  return;
31
33
  }
32
34
 
35
+ const clone = el.cloneNode(true) as Element;
36
+ clone.removeAttribute(attr);
37
+ if (action === "add") {
38
+ clone.removeAttribute(ATTR_MANIPULATION_ADD_INDEX);
39
+ } else if (action === "remove") {
40
+ clone.removeAttribute(ATTR_MANIPULATION_REMOVE_INDEX);
41
+ }
42
+
43
+ // Ensure the element has the swiper-slide class
44
+ if (!clone.classList.contains("swiper-slide")) {
45
+ clone.classList.add("swiper-slide");
46
+ }
47
+
33
48
  if (action === "append") {
34
- swiper.appendSlide(el.outerHTML);
49
+ swiper.appendSlide(clone.outerHTML);
35
50
  } else if (action === "prepend") {
36
- swiper.prependSlide(el.outerHTML);
51
+ swiper.prependSlide(clone.outerHTML);
37
52
  } else if (action === "add") {
38
53
  let index = Number(el.getAttribute(ATTR_MANIPULATION_ADD_INDEX));
39
54
  if (!index) index = 1;
40
- swiper.addSlide(index, [el.outerHTML]);
55
+ // Parse HTML string into DOM element (addSlide doesn't handle strings properly)
56
+ const tempDOM = document.createElement("div");
57
+ tempDOM.innerHTML = clone.outerHTML;
58
+ const slideElement = tempDOM.children[0] as HTMLElement;
59
+ if (slideElement) {
60
+ swiper.addSlide(index, slideElement);
61
+ }
41
62
  } else if (action === "remove") {
42
63
  const slideIndex = Number(el.getAttribute(ATTR_MANIPULATION_REMOVE_INDEX));
43
64
  if (slideIndex !== -1) {
@@ -1,5 +1,5 @@
1
1
  import { SwiperOptions } from "swiper/types";
2
- import { parseBoolean, parseNumber, parseString } from "../util";
2
+ import { getWaterfallByName, parseBoolean, parseNumber, parseString } from "../util";
3
3
  import { Waterfall } from "types/waterfall";
4
4
  import {
5
5
  ATTR_THUMBS,
@@ -15,7 +15,7 @@ export function thumbsConfig(config: SwiperOptions, el: HTMLElement, swipers: Wa
15
15
  return;
16
16
  }
17
17
 
18
- const waterfall = swipers.find((slider: Waterfall) => slider.name === thumbsName);
18
+ const waterfall = getWaterfallByName(swipers, thumbsName);
19
19
 
20
20
  if (!waterfall) {
21
21
  if (debug) console.warn("A matching thumbs waterfall was not found for ", thumbsName);
package/src/util.ts CHANGED
@@ -88,17 +88,21 @@ export function removeNullOrUndefinedKeys<T extends Record<string, any>>(obj: T)
88
88
  return obj;
89
89
  }
90
90
 
91
- export function getSwipersByName(waterfalls: Waterfall[], selector: string, debug: boolean): Swiper[] {
92
- const matchedSwipers = waterfalls
91
+ export function getWaterfallByName(waterfalls: Waterfall[], name: string): Waterfall | undefined {
92
+ return waterfalls.find((w) => w.name?.toLowerCase() === name?.toLowerCase());
93
+ }
94
+
95
+ export function getWaterfallsByName(waterfalls: Waterfall[], selector: string, debug: boolean): Swiper[] {
96
+ const matchedWaterfalls = waterfalls
93
97
  .filter((w) => {
94
- const match = w.name === selector;
98
+ const match = w.name?.toLowerCase() === selector?.toLowerCase();
95
99
  return match;
96
100
  })
97
101
  .map((w) => w.swiper);
98
102
 
99
- debug && console.log(`📊 Found ${matchedSwipers.length} matching swiper(s) for "${selector}"`);
103
+ debug && console.log(`📊 Found ${matchedWaterfalls.length} matching waterfall(s) for "${selector}"`);
100
104
 
101
- return matchedSwipers;
105
+ return matchedWaterfalls;
102
106
  }
103
107
 
104
108
  export function fixWebflowCMSListARIARole() {