Skip to content

Commit

Permalink
feat(core): move slides manipulation methods to Manipulation module
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Aug 6, 2021
1 parent 3b50feb commit 74873f1
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 81 deletions.
1 change: 1 addition & 0 deletions scripts/build-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ module.exports = {
'thumbs',
'free-mode',
'grid',
'manipulation',
],
};
2 changes: 0 additions & 2 deletions src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import transition from './transition/index.js';
import slide from './slide/index.js';
import loop from './loop/index.js';
import grabCursor from './grab-cursor/index.js';
import manipulation from './manipulation/index.js';
import events from './events/index.js';
import breakpoints from './breakpoints/index.js';
import classes from './classes/index.js';
Expand All @@ -35,7 +34,6 @@ const prototypes = {
slide,
loop,
grabCursor,
manipulation,
events,
breakpoints,
checkOverflow,
Expand Down
13 changes: 0 additions & 13 deletions src/core/manipulation/index.js

This file was deleted.

15 changes: 15 additions & 0 deletions src/modules/manipulation/manipulation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import appendSlide from './methods/appendSlide.js';
import prependSlide from './methods/prependSlide.js';
import addSlide from './methods/addSlide.js';
import removeSlide from './methods/removeSlide.js';
import removeAllSlides from './methods/removeAllSlides.js';

export default function Manipulation({ swiper }) {
Object.assign(swiper, {
appendSlide: appendSlide.bind(swiper),
prependSlide: prependSlide.bind(swiper),
addSlide: addSlide.bind(swiper),
removeSlide: removeSlide.bind(swiper),
removeAllSlides: removeAllSlides.bind(swiper),
});
}
Empty file.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
70 changes: 70 additions & 0 deletions src/types/modules/manipulation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
export interface ManipulationMethods {
/**
* Add new slides to the end. slides could be
* HTMLElement or HTML string with new slide or
* array with such slides, for example:
*
* @example
* ```js
* appendSlide('<div class="swiper-slide">Slide 10"</div>')
*
* appendSlide([
* '<div class="swiper-slide">Slide 10"</div>',
* '<div class="swiper-slide">Slide 11"</div>'
* ]);
* ```
*/
appendSlide(slides: HTMLElement | string | string[] | HTMLElement[]): void;

/**
* Add new slides to the beginning. slides could be
* HTMLElement or HTML string with new slide or array with such slides, for example:
*
* @example
* ```js
* prependSlide('<div class="swiper-slide">Slide 0"</div>')
*
* prependSlide([
* '<div class="swiper-slide">Slide 1"</div>',
* '<div class="swiper-slide">Slide 2"</div>'
* ]);
* ```
*/
prependSlide(slides: HTMLElement | string | string[] | HTMLElement[]): void;

/**
* Add new slides to the required index. slides could be HTMLElement or HTML string with new slide or array with such slides, for example:
*
* @example
* ```js
* addSlide(1, '<div class="swiper-slide">Slide 10"</div>')
*
* addSlide(1, [
* '<div class="swiper-slide">Slide 10"</div>',
* '<div class="swiper-slide">Slide 11"</div>'
* ]);
* ```
*/
addSlide(index: number, slides: HTMLElement | string | string[] | HTMLElement[]): void;

/**
* Remove selected slides. slideIndex could be a number with slide index to remove or array with indexes.
*
* @example
* ```js
* removeSlide(0); // remove first slide
* removeSlide([0, 1]); // remove first and second slides
* removeAllSlides(); // Remove all slides
* ```
*/
removeSlide(slideIndex: number | number[]): void;

/**
* Remove all slides
*/
removeAllSlides(): void;
}

export interface ManipulationEvents {}

export interface ManipulationOptions {}
1 change: 1 addition & 0 deletions src/types/modules/public-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './virtual';
export * from './zoom';
export * from './free-mode';
export * from './grid';
export * from './manipulation';
68 changes: 2 additions & 66 deletions src/types/swiper-class.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ThumbsMethods } from './modules/thumbs';
import { VirtualMethods } from './modules/virtual';
import { ZoomMethods } from './modules/zoom';
import { FreeModeMethods } from './modules/free-mode';
import { ManipulationMethods } from './modules/manipulation';

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

/**
* Add new slides to the end. slides could be
* HTMLElement or HTML string with new slide or
* array with such slides, for example:
*
* @example
* ```js
* appendSlide('<div class="swiper-slide">Slide 10"</div>')
*
* appendSlide([
* '<div class="swiper-slide">Slide 10"</div>',
* '<div class="swiper-slide">Slide 11"</div>'
* ]);
* ```
*/
appendSlide(slides: HTMLElement | string | string[] | HTMLElement[]): void;

/**
* Add new slides to the beginning. slides could be
* HTMLElement or HTML string with new slide or array with such slides, for example:
*
* @example
* ```js
* prependSlide('<div class="swiper-slide">Slide 0"</div>')
*
* prependSlide([
* '<div class="swiper-slide">Slide 1"</div>',
* '<div class="swiper-slide">Slide 2"</div>'
* ]);
* ```
*/
prependSlide(slides: HTMLElement | string | string[] | HTMLElement[]): void;

/**
* Add new slides to the required index. slides could be HTMLElement or HTML string with new slide or array with such slides, for example:
*
* @example
* ```js
* addSlide(1, '<div class="swiper-slide">Slide 10"</div>')
*
* addSlide(1, [
* '<div class="swiper-slide">Slide 10"</div>',
* '<div class="swiper-slide">Slide 11"</div>'
* ]);
* ```
*/
addSlide(index: number, slides: HTMLElement | string | string[] | HTMLElement[]): void;

/**
* Remove selected slides. slideIndex could be a number with slide index to remove or array with indexes.
*
* @example
* ```js
* removeSlide(0); // remove first slide
* removeSlide([0, 1]); // remove first and second slides
* removeAllSlides(); // Remove all slides
* ```
*/
removeSlide(slideIndex: number | number[]): void;

/**
* Remove all slides
*/
removeAllSlides(): void;

/**
* Set custom css3 transform's translate value for swiper wrapper
*/
Expand Down Expand Up @@ -454,7 +390,7 @@ interface Swiper extends SwiperClass<SwiperEvents> {
/**
* !INTERNAL
*/
modules: Array<any>; //TODO: add typing
modules: Array<SwiperModule>;

a11y: A11yMethods;
autoplay: AutoplayMethods;
Expand Down

0 comments on commit 74873f1

Please sign in to comment.