Skip to content

Commit 74873f1

Browse files
committed
feat(core): move slides manipulation methods to Manipulation module
1 parent 3b50feb commit 74873f1

14 files changed

+89
-81
lines changed

scripts/build-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ module.exports = {
2121
'thumbs',
2222
'free-mode',
2323
'grid',
24+
'manipulation',
2425
],
2526
};

src/core/core.js

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import transition from './transition/index.js';
1717
import slide from './slide/index.js';
1818
import loop from './loop/index.js';
1919
import grabCursor from './grab-cursor/index.js';
20-
import manipulation from './manipulation/index.js';
2120
import events from './events/index.js';
2221
import breakpoints from './breakpoints/index.js';
2322
import classes from './classes/index.js';
@@ -35,7 +34,6 @@ const prototypes = {
3534
slide,
3635
loop,
3736
grabCursor,
38-
manipulation,
3937
events,
4038
breakpoints,
4139
checkOverflow,

src/core/manipulation/index.js

-13
This file was deleted.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import appendSlide from './methods/appendSlide.js';
2+
import prependSlide from './methods/prependSlide.js';
3+
import addSlide from './methods/addSlide.js';
4+
import removeSlide from './methods/removeSlide.js';
5+
import removeAllSlides from './methods/removeAllSlides.js';
6+
7+
export default function Manipulation({ swiper }) {
8+
Object.assign(swiper, {
9+
appendSlide: appendSlide.bind(swiper),
10+
prependSlide: prependSlide.bind(swiper),
11+
addSlide: addSlide.bind(swiper),
12+
removeSlide: removeSlide.bind(swiper),
13+
removeAllSlides: removeAllSlides.bind(swiper),
14+
});
15+
}

src/modules/manipulation/manipulation.less

Whitespace-only changes.

src/modules/manipulation/manipulation.scss

Whitespace-only changes.

src/types/modules/manipulation.d.ts

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
export interface ManipulationMethods {
2+
/**
3+
* Add new slides to the end. slides could be
4+
* HTMLElement or HTML string with new slide or
5+
* array with such slides, for example:
6+
*
7+
* @example
8+
* ```js
9+
* appendSlide('<div class="swiper-slide">Slide 10"</div>')
10+
*
11+
* appendSlide([
12+
* '<div class="swiper-slide">Slide 10"</div>',
13+
* '<div class="swiper-slide">Slide 11"</div>'
14+
* ]);
15+
* ```
16+
*/
17+
appendSlide(slides: HTMLElement | string | string[] | HTMLElement[]): void;
18+
19+
/**
20+
* Add new slides to the beginning. slides could be
21+
* HTMLElement or HTML string with new slide or array with such slides, for example:
22+
*
23+
* @example
24+
* ```js
25+
* prependSlide('<div class="swiper-slide">Slide 0"</div>')
26+
*
27+
* prependSlide([
28+
* '<div class="swiper-slide">Slide 1"</div>',
29+
* '<div class="swiper-slide">Slide 2"</div>'
30+
* ]);
31+
* ```
32+
*/
33+
prependSlide(slides: HTMLElement | string | string[] | HTMLElement[]): void;
34+
35+
/**
36+
* Add new slides to the required index. slides could be HTMLElement or HTML string with new slide or array with such slides, for example:
37+
*
38+
* @example
39+
* ```js
40+
* addSlide(1, '<div class="swiper-slide">Slide 10"</div>')
41+
*
42+
* addSlide(1, [
43+
* '<div class="swiper-slide">Slide 10"</div>',
44+
* '<div class="swiper-slide">Slide 11"</div>'
45+
* ]);
46+
* ```
47+
*/
48+
addSlide(index: number, slides: HTMLElement | string | string[] | HTMLElement[]): void;
49+
50+
/**
51+
* Remove selected slides. slideIndex could be a number with slide index to remove or array with indexes.
52+
*
53+
* @example
54+
* ```js
55+
* removeSlide(0); // remove first slide
56+
* removeSlide([0, 1]); // remove first and second slides
57+
* removeAllSlides(); // Remove all slides
58+
* ```
59+
*/
60+
removeSlide(slideIndex: number | number[]): void;
61+
62+
/**
63+
* Remove all slides
64+
*/
65+
removeAllSlides(): void;
66+
}
67+
68+
export interface ManipulationEvents {}
69+
70+
export interface ManipulationOptions {}

src/types/modules/public-api.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ export * from './virtual';
1919
export * from './zoom';
2020
export * from './free-mode';
2121
export * from './grid';
22+
export * from './manipulation';

src/types/swiper-class.d.ts

+2-66
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { ThumbsMethods } from './modules/thumbs';
2323
import { VirtualMethods } from './modules/virtual';
2424
import { ZoomMethods } from './modules/zoom';
2525
import { FreeModeMethods } from './modules/free-mode';
26+
import { ManipulationMethods } from './modules/manipulation';
2627

2728
interface SwiperClass<Events> {
2829
/** Add event handler */
@@ -315,71 +316,6 @@ interface Swiper extends SwiperClass<SwiperEvents> {
315316
*/
316317
destroy(deleteInstance?: boolean, cleanStyles?: boolean): void;
317318

318-
/**
319-
* Add new slides to the end. slides could be
320-
* HTMLElement or HTML string with new slide or
321-
* array with such slides, for example:
322-
*
323-
* @example
324-
* ```js
325-
* appendSlide('<div class="swiper-slide">Slide 10"</div>')
326-
*
327-
* appendSlide([
328-
* '<div class="swiper-slide">Slide 10"</div>',
329-
* '<div class="swiper-slide">Slide 11"</div>'
330-
* ]);
331-
* ```
332-
*/
333-
appendSlide(slides: HTMLElement | string | string[] | HTMLElement[]): void;
334-
335-
/**
336-
* Add new slides to the beginning. slides could be
337-
* HTMLElement or HTML string with new slide or array with such slides, for example:
338-
*
339-
* @example
340-
* ```js
341-
* prependSlide('<div class="swiper-slide">Slide 0"</div>')
342-
*
343-
* prependSlide([
344-
* '<div class="swiper-slide">Slide 1"</div>',
345-
* '<div class="swiper-slide">Slide 2"</div>'
346-
* ]);
347-
* ```
348-
*/
349-
prependSlide(slides: HTMLElement | string | string[] | HTMLElement[]): void;
350-
351-
/**
352-
* Add new slides to the required index. slides could be HTMLElement or HTML string with new slide or array with such slides, for example:
353-
*
354-
* @example
355-
* ```js
356-
* addSlide(1, '<div class="swiper-slide">Slide 10"</div>')
357-
*
358-
* addSlide(1, [
359-
* '<div class="swiper-slide">Slide 10"</div>',
360-
* '<div class="swiper-slide">Slide 11"</div>'
361-
* ]);
362-
* ```
363-
*/
364-
addSlide(index: number, slides: HTMLElement | string | string[] | HTMLElement[]): void;
365-
366-
/**
367-
* Remove selected slides. slideIndex could be a number with slide index to remove or array with indexes.
368-
*
369-
* @example
370-
* ```js
371-
* removeSlide(0); // remove first slide
372-
* removeSlide([0, 1]); // remove first and second slides
373-
* removeAllSlides(); // Remove all slides
374-
* ```
375-
*/
376-
removeSlide(slideIndex: number | number[]): void;
377-
378-
/**
379-
* Remove all slides
380-
*/
381-
removeAllSlides(): void;
382-
383319
/**
384320
* Set custom css3 transform's translate value for swiper wrapper
385321
*/
@@ -454,7 +390,7 @@ interface Swiper extends SwiperClass<SwiperEvents> {
454390
/**
455391
* !INTERNAL
456392
*/
457-
modules: Array<any>; //TODO: add typing
393+
modules: Array<SwiperModule>;
458394

459395
a11y: A11yMethods;
460396
autoplay: AutoplayMethods;

0 commit comments

Comments
 (0)