feat: Add comprehensive documentation suite and reorganize project structure
- Created complete documentation in docs/ directory - Added PROJECT_OVERVIEW.md with feature highlights and getting started guide - Added ARCHITECTURE.md with system design and technical details - Added SECURITY.md with comprehensive security implementation guide - Added DEVELOPMENT.md with development workflows and best practices - Added DEPLOYMENT.md with production deployment instructions - Added API.md with complete REST API documentation - Added CONTRIBUTING.md with contribution guidelines - Added CHANGELOG.md with version history and migration notes - Reorganized all documentation files into docs/ directory for better organization - Updated README.md with proper documentation links and quick navigation - Enhanced project structure with professional documentation standards
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { paramsList } from './params-list.js';
|
||||
import { isObject } from './utils.js';
|
||||
function getChangedParams(swiperParams, oldParams, children, oldChildren, getKey) {
|
||||
const keys = [];
|
||||
if (!oldParams) return keys;
|
||||
const addKey = key => {
|
||||
if (keys.indexOf(key) < 0) keys.push(key);
|
||||
};
|
||||
if (children && oldChildren) {
|
||||
const oldChildrenKeys = oldChildren.map(getKey);
|
||||
const childrenKeys = children.map(getKey);
|
||||
if (oldChildrenKeys.join('') !== childrenKeys.join('')) addKey('children');
|
||||
if (oldChildren.length !== children.length) addKey('children');
|
||||
}
|
||||
const watchParams = paramsList.filter(key => key[0] === '_').map(key => key.replace(/_/, ''));
|
||||
watchParams.forEach(key => {
|
||||
if (key in swiperParams && key in oldParams) {
|
||||
if (isObject(swiperParams[key]) && isObject(oldParams[key])) {
|
||||
const newKeys = Object.keys(swiperParams[key]);
|
||||
const oldKeys = Object.keys(oldParams[key]);
|
||||
if (newKeys.length !== oldKeys.length) {
|
||||
addKey(key);
|
||||
} else {
|
||||
newKeys.forEach(newKey => {
|
||||
if (swiperParams[key][newKey] !== oldParams[key][newKey]) {
|
||||
addKey(key);
|
||||
}
|
||||
});
|
||||
oldKeys.forEach(oldKey => {
|
||||
if (swiperParams[key][oldKey] !== oldParams[key][oldKey]) addKey(key);
|
||||
});
|
||||
}
|
||||
} else if (swiperParams[key] !== oldParams[key]) {
|
||||
addKey(key);
|
||||
}
|
||||
}
|
||||
});
|
||||
return keys;
|
||||
}
|
||||
export { getChangedParams };
|
||||
@@ -0,0 +1,50 @@
|
||||
import Swiper from 'swiper';
|
||||
import { isObject, extend } from './utils.js';
|
||||
import { paramsList } from './params-list.js';
|
||||
function getParams(obj = {}, splitEvents = true) {
|
||||
const params = {
|
||||
on: {}
|
||||
};
|
||||
const events = {};
|
||||
const passedParams = {};
|
||||
extend(params, Swiper.defaults);
|
||||
extend(params, Swiper.extendedDefaults);
|
||||
params._emitClasses = true;
|
||||
params.init = false;
|
||||
const rest = {};
|
||||
const allowedParams = paramsList.map(key => key.replace(/_/, ''));
|
||||
const plainObj = Object.assign({}, obj);
|
||||
Object.keys(plainObj).forEach(key => {
|
||||
if (typeof obj[key] === 'undefined') return;
|
||||
if (allowedParams.indexOf(key) >= 0) {
|
||||
if (isObject(obj[key])) {
|
||||
params[key] = {};
|
||||
passedParams[key] = {};
|
||||
extend(params[key], obj[key]);
|
||||
extend(passedParams[key], obj[key]);
|
||||
} else {
|
||||
params[key] = obj[key];
|
||||
passedParams[key] = obj[key];
|
||||
}
|
||||
} else if (key.search(/on[A-Z]/) === 0 && typeof obj[key] === 'function') {
|
||||
if (splitEvents) {
|
||||
events[`${key[2].toLowerCase()}${key.substr(3)}`] = obj[key];
|
||||
} else {
|
||||
params.on[`${key[2].toLowerCase()}${key.substr(3)}`] = obj[key];
|
||||
}
|
||||
} else {
|
||||
rest[key] = obj[key];
|
||||
}
|
||||
});
|
||||
['navigation', 'pagination', 'scrollbar'].forEach(key => {
|
||||
if (params[key] === true) params[key] = {};
|
||||
if (params[key] === false) delete params[key];
|
||||
});
|
||||
return {
|
||||
params,
|
||||
passedParams,
|
||||
rest,
|
||||
events
|
||||
};
|
||||
}
|
||||
export { getParams };
|
||||
@@ -0,0 +1,26 @@
|
||||
import { needsNavigation, needsPagination, needsScrollbar } from './utils.js';
|
||||
function mountSwiper({
|
||||
el,
|
||||
nextEl,
|
||||
prevEl,
|
||||
paginationEl,
|
||||
scrollbarEl,
|
||||
swiper
|
||||
}, swiperParams) {
|
||||
if (needsNavigation(swiperParams) && nextEl && prevEl) {
|
||||
swiper.params.navigation.nextEl = nextEl;
|
||||
swiper.originalParams.navigation.nextEl = nextEl;
|
||||
swiper.params.navigation.prevEl = prevEl;
|
||||
swiper.originalParams.navigation.prevEl = prevEl;
|
||||
}
|
||||
if (needsPagination(swiperParams) && paginationEl) {
|
||||
swiper.params.pagination.el = paginationEl;
|
||||
swiper.originalParams.pagination.el = paginationEl;
|
||||
}
|
||||
if (needsScrollbar(swiperParams) && scrollbarEl) {
|
||||
swiper.params.scrollbar.el = scrollbarEl;
|
||||
swiper.originalParams.scrollbar.el = scrollbarEl;
|
||||
}
|
||||
swiper.init(el);
|
||||
}
|
||||
export { mountSwiper };
|
||||
@@ -0,0 +1,5 @@
|
||||
/* underscore in name -> watch for changes */
|
||||
const paramsList = ['modules', 'init', '_direction', 'oneWayMovement', 'touchEventsTarget', 'initialSlide', '_speed', 'cssMode', 'updateOnWindowResize', 'resizeObserver', 'nested', 'focusableElements', '_enabled', '_width', '_height', 'preventInteractionOnTransition', 'userAgent', 'url', '_edgeSwipeDetection', '_edgeSwipeThreshold', '_freeMode', '_autoHeight', 'setWrapperSize', 'virtualTranslate', '_effect', 'breakpoints', '_spaceBetween', '_slidesPerView', 'maxBackfaceHiddenSlides', '_grid', '_slidesPerGroup', '_slidesPerGroupSkip', '_slidesPerGroupAuto', '_centeredSlides', '_centeredSlidesBounds', '_slidesOffsetBefore', '_slidesOffsetAfter', 'normalizeSlideIndex', '_centerInsufficientSlides', '_watchOverflow', 'roundLengths', 'touchRatio', 'touchAngle', 'simulateTouch', '_shortSwipes', '_longSwipes', 'longSwipesRatio', 'longSwipesMs', '_followFinger', 'allowTouchMove', '_threshold', 'touchMoveStopPropagation', 'touchStartPreventDefault', 'touchStartForcePreventDefault', 'touchReleaseOnEdges', 'uniqueNavElements', '_resistance', '_resistanceRatio', '_watchSlidesProgress', '_grabCursor', 'preventClicks', 'preventClicksPropagation', '_slideToClickedSlide', '_loop', 'loopedSlides', 'loopPreventsSliding', '_rewind', '_allowSlidePrev', '_allowSlideNext', '_swipeHandler', '_noSwiping', 'noSwipingClass', 'noSwipingSelector', 'passiveListeners', 'containerModifierClass', 'slideClass', 'slideActiveClass', 'slideVisibleClass', 'slideNextClass', 'slidePrevClass', 'wrapperClass', 'lazyPreloaderClass', 'runCallbacksOnInit', 'observer', 'observeParents', 'observeSlideChildren',
|
||||
// modules
|
||||
'a11y', '_autoplay', '_controller', 'coverflowEffect', 'cubeEffect', 'fadeEffect', 'flipEffect', 'creativeEffect', 'cardsEffect', 'hashNavigation', 'history', 'keyboard', 'mousewheel', '_navigation', '_pagination', 'parallax', '_scrollbar', '_thumbs', 'virtual', 'zoom', 'control', 'injectStyles', 'injectStylesUrls'];
|
||||
export { paramsList };
|
||||
@@ -0,0 +1,9 @@
|
||||
export const updateOnVirtualData = swiper => {
|
||||
if (!swiper || swiper.destroyed || !swiper.params.virtual || swiper.params.virtual && !swiper.params.virtual.enabled) return;
|
||||
swiper.updateSlides();
|
||||
swiper.updateProgress();
|
||||
swiper.updateSlidesClasses();
|
||||
if (swiper.parallax && swiper.params.parallax && swiper.params.parallax.enabled) {
|
||||
swiper.parallax.setTranslate();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,161 @@
|
||||
import { isObject, extend } from './utils.js';
|
||||
function updateSwiper({
|
||||
swiper,
|
||||
slides,
|
||||
passedParams,
|
||||
changedParams,
|
||||
nextEl,
|
||||
prevEl,
|
||||
scrollbarEl,
|
||||
paginationEl
|
||||
}) {
|
||||
const updateParams = changedParams.filter(key => key !== 'children' && key !== 'direction' && key !== 'wrapperClass');
|
||||
const {
|
||||
params: currentParams,
|
||||
pagination,
|
||||
navigation,
|
||||
scrollbar,
|
||||
virtual,
|
||||
thumbs
|
||||
} = swiper;
|
||||
let needThumbsInit;
|
||||
let needControllerInit;
|
||||
let needPaginationInit;
|
||||
let needScrollbarInit;
|
||||
let needNavigationInit;
|
||||
let loopNeedDestroy;
|
||||
let loopNeedEnable;
|
||||
let loopNeedReloop;
|
||||
if (changedParams.includes('thumbs') && passedParams.thumbs && passedParams.thumbs.swiper && currentParams.thumbs && !currentParams.thumbs.swiper) {
|
||||
needThumbsInit = true;
|
||||
}
|
||||
if (changedParams.includes('controller') && passedParams.controller && passedParams.controller.control && currentParams.controller && !currentParams.controller.control) {
|
||||
needControllerInit = true;
|
||||
}
|
||||
if (changedParams.includes('pagination') && passedParams.pagination && (passedParams.pagination.el || paginationEl) && (currentParams.pagination || currentParams.pagination === false) && pagination && !pagination.el) {
|
||||
needPaginationInit = true;
|
||||
}
|
||||
if (changedParams.includes('scrollbar') && passedParams.scrollbar && (passedParams.scrollbar.el || scrollbarEl) && (currentParams.scrollbar || currentParams.scrollbar === false) && scrollbar && !scrollbar.el) {
|
||||
needScrollbarInit = true;
|
||||
}
|
||||
if (changedParams.includes('navigation') && passedParams.navigation && (passedParams.navigation.prevEl || prevEl) && (passedParams.navigation.nextEl || nextEl) && (currentParams.navigation || currentParams.navigation === false) && navigation && !navigation.prevEl && !navigation.nextEl) {
|
||||
needNavigationInit = true;
|
||||
}
|
||||
const destroyModule = mod => {
|
||||
if (!swiper[mod]) return;
|
||||
swiper[mod].destroy();
|
||||
if (mod === 'navigation') {
|
||||
if (swiper.isElement) {
|
||||
swiper[mod].prevEl.remove();
|
||||
swiper[mod].nextEl.remove();
|
||||
}
|
||||
currentParams[mod].prevEl = undefined;
|
||||
currentParams[mod].nextEl = undefined;
|
||||
swiper[mod].prevEl = undefined;
|
||||
swiper[mod].nextEl = undefined;
|
||||
} else {
|
||||
if (swiper.isElement) {
|
||||
swiper[mod].el.remove();
|
||||
}
|
||||
currentParams[mod].el = undefined;
|
||||
swiper[mod].el = undefined;
|
||||
}
|
||||
};
|
||||
if (changedParams.includes('loop') && swiper.isElement) {
|
||||
if (currentParams.loop && !passedParams.loop) {
|
||||
loopNeedDestroy = true;
|
||||
} else if (!currentParams.loop && passedParams.loop) {
|
||||
loopNeedEnable = true;
|
||||
} else {
|
||||
loopNeedReloop = true;
|
||||
}
|
||||
}
|
||||
updateParams.forEach(key => {
|
||||
if (isObject(currentParams[key]) && isObject(passedParams[key])) {
|
||||
extend(currentParams[key], passedParams[key]);
|
||||
} else {
|
||||
const newValue = passedParams[key];
|
||||
if ((newValue === true || newValue === false) && (key === 'navigation' || key === 'pagination' || key === 'scrollbar')) {
|
||||
if (newValue === false) {
|
||||
destroyModule(key);
|
||||
}
|
||||
} else {
|
||||
currentParams[key] = passedParams[key];
|
||||
}
|
||||
}
|
||||
});
|
||||
if (updateParams.includes('controller') && !needControllerInit && swiper.controller && swiper.controller.control && currentParams.controller && currentParams.controller.control) {
|
||||
swiper.controller.control = currentParams.controller.control;
|
||||
}
|
||||
if (changedParams.includes('children') && slides && virtual && currentParams.virtual.enabled) {
|
||||
virtual.slides = slides;
|
||||
virtual.update(true);
|
||||
}
|
||||
if (changedParams.includes('children') && slides && currentParams.loop) {
|
||||
loopNeedReloop = true;
|
||||
}
|
||||
if (needThumbsInit) {
|
||||
const initialized = thumbs.init();
|
||||
if (initialized) thumbs.update(true);
|
||||
}
|
||||
if (needControllerInit) {
|
||||
swiper.controller.control = currentParams.controller.control;
|
||||
}
|
||||
if (needPaginationInit) {
|
||||
if (swiper.isElement && (!paginationEl || typeof paginationEl === 'string')) {
|
||||
paginationEl = document.createElement('div');
|
||||
paginationEl.classList.add('swiper-pagination');
|
||||
swiper.el.shadowEl.appendChild(paginationEl);
|
||||
}
|
||||
if (paginationEl) currentParams.pagination.el = paginationEl;
|
||||
pagination.init();
|
||||
pagination.render();
|
||||
pagination.update();
|
||||
}
|
||||
if (needScrollbarInit) {
|
||||
if (swiper.isElement && (!scrollbarEl || typeof scrollbarEl === 'string')) {
|
||||
scrollbarEl = document.createElement('div');
|
||||
scrollbarEl.classList.add('swiper-scrollbar');
|
||||
swiper.el.shadowEl.appendChild(scrollbarEl);
|
||||
}
|
||||
if (scrollbarEl) currentParams.scrollbar.el = scrollbarEl;
|
||||
scrollbar.init();
|
||||
scrollbar.updateSize();
|
||||
scrollbar.setTranslate();
|
||||
}
|
||||
if (needNavigationInit) {
|
||||
if (swiper.isElement) {
|
||||
if (!nextEl || typeof nextEl === 'string') {
|
||||
nextEl = document.createElement('div');
|
||||
nextEl.classList.add('swiper-button-next');
|
||||
swiper.el.shadowEl.appendChild(nextEl);
|
||||
}
|
||||
if (!prevEl || typeof prevEl === 'string') {
|
||||
prevEl = document.createElement('div');
|
||||
prevEl.classList.add('swiper-button-prev');
|
||||
swiper.el.shadowEl.appendChild(prevEl);
|
||||
}
|
||||
}
|
||||
if (nextEl) currentParams.navigation.nextEl = nextEl;
|
||||
if (prevEl) currentParams.navigation.prevEl = prevEl;
|
||||
navigation.init();
|
||||
navigation.update();
|
||||
}
|
||||
if (changedParams.includes('allowSlideNext')) {
|
||||
swiper.allowSlideNext = passedParams.allowSlideNext;
|
||||
}
|
||||
if (changedParams.includes('allowSlidePrev')) {
|
||||
swiper.allowSlidePrev = passedParams.allowSlidePrev;
|
||||
}
|
||||
if (changedParams.includes('direction')) {
|
||||
swiper.changeDirection(passedParams.direction, false);
|
||||
}
|
||||
if (loopNeedDestroy || loopNeedReloop) {
|
||||
swiper.loopDestroy();
|
||||
}
|
||||
if (loopNeedEnable || loopNeedReloop) {
|
||||
swiper.loopCreate();
|
||||
}
|
||||
swiper.update();
|
||||
}
|
||||
export { updateSwiper };
|
||||
@@ -0,0 +1,39 @@
|
||||
function isObject(o) {
|
||||
return typeof o === 'object' && o !== null && o.constructor && Object.prototype.toString.call(o).slice(8, -1) === 'Object';
|
||||
}
|
||||
function extend(target, src) {
|
||||
const noExtend = ['__proto__', 'constructor', 'prototype'];
|
||||
Object.keys(src).filter(key => noExtend.indexOf(key) < 0).forEach(key => {
|
||||
if (typeof target[key] === 'undefined') target[key] = src[key];else if (isObject(src[key]) && isObject(target[key]) && Object.keys(src[key]).length > 0) {
|
||||
if (src[key].__swiper__) target[key] = src[key];else extend(target[key], src[key]);
|
||||
} else {
|
||||
target[key] = src[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
function needsNavigation(params = {}) {
|
||||
return params.navigation && typeof params.navigation.nextEl === 'undefined' && typeof params.navigation.prevEl === 'undefined';
|
||||
}
|
||||
function needsPagination(params = {}) {
|
||||
return params.pagination && typeof params.pagination.el === 'undefined';
|
||||
}
|
||||
function needsScrollbar(params = {}) {
|
||||
return params.scrollbar && typeof params.scrollbar.el === 'undefined';
|
||||
}
|
||||
function uniqueClasses(classNames = '') {
|
||||
const classes = classNames.split(' ').map(c => c.trim()).filter(c => !!c);
|
||||
const unique = [];
|
||||
classes.forEach(c => {
|
||||
if (unique.indexOf(c) < 0) unique.push(c);
|
||||
});
|
||||
return unique.join(' ');
|
||||
}
|
||||
function attrToProp(attrName = '') {
|
||||
return attrName.replace(/-[a-z]/g, l => l.toUpperCase().replace('-', ''));
|
||||
}
|
||||
function wrapperClass(className = '') {
|
||||
if (!className) return 'swiper-wrapper';
|
||||
if (!className.includes('swiper-wrapper')) return `swiper-wrapper ${className}`;
|
||||
return className;
|
||||
}
|
||||
export { isObject, extend, needsNavigation, needsPagination, needsScrollbar, uniqueClasses, attrToProp, wrapperClass };
|
||||
Reference in New Issue
Block a user