This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
import InfiniteScroll from './src';
import type { SFCWithInstall } from 'element-plus/es/utils';
declare const _InfiniteScroll: SFCWithInstall<typeof InfiniteScroll>;
export default _InfiniteScroll;
export declare const ElInfiniteScroll: SFCWithInstall<import("vue").ObjectDirective<HTMLElement & {
ElInfiniteScroll: {
container: HTMLElement | Window;
containerEl: HTMLElement;
instance: import("vue").ComponentPublicInstance;
delay: number;
lastScrollTop: number;
cb: () => void;
onScroll: () => void;
observer?: MutationObserver;
};
}, () => void>>;

View File

@@ -0,0 +1,15 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var index = require('./src/index.js');
const _InfiniteScroll = index["default"];
_InfiniteScroll.install = (app) => {
app.directive("InfiniteScroll", _InfiniteScroll);
};
const ElInfiniteScroll = _InfiniteScroll;
exports.ElInfiniteScroll = ElInfiniteScroll;
exports["default"] = _InfiniteScroll;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../../../../packages/components/infinite-scroll/index.ts"],"sourcesContent":["import InfiniteScroll from './src'\n\nimport type { App } from 'vue'\nimport type { SFCWithInstall } from '@element-plus/utils'\n\nconst _InfiniteScroll = InfiniteScroll as SFCWithInstall<typeof InfiniteScroll>\n\n_InfiniteScroll.install = (app: App) => {\n app.directive('InfiniteScroll', _InfiniteScroll)\n}\n\nexport default _InfiniteScroll\nexport const ElInfiniteScroll = _InfiniteScroll\n"],"names":["InfiniteScroll"],"mappings":";;;;;;AACK,MAAC,eAAe,GAAGA,iBAAe;AACvC,eAAe,CAAC,OAAO,GAAG,CAAC,GAAG,KAAK;AACnC,EAAE,GAAG,CAAC,SAAS,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;AACnD,CAAC,CAAC;AAEU,MAAC,gBAAgB,GAAG;;;;;"}

View File

@@ -0,0 +1,20 @@
import type { ComponentPublicInstance, ObjectDirective } from 'vue';
export declare const SCOPE = "ElInfiniteScroll";
export declare const CHECK_INTERVAL = 50;
export declare const DEFAULT_DELAY = 200;
export declare const DEFAULT_DISTANCE = 0;
type InfiniteScrollCallback = () => void;
type InfiniteScrollEl = HTMLElement & {
[SCOPE]: {
container: HTMLElement | Window;
containerEl: HTMLElement;
instance: ComponentPublicInstance;
delay: number;
lastScrollTop: number;
cb: InfiniteScrollCallback;
onScroll: () => void;
observer?: MutationObserver;
};
};
declare const InfiniteScroll: ObjectDirective<InfiniteScrollEl, InfiniteScrollCallback>;
export default InfiniteScroll;

View File

@@ -0,0 +1,138 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var lodashUnified = require('lodash-unified');
var shared = require('@vue/shared');
var error = require('../../../utils/error.js');
var scroll = require('../../../utils/dom/scroll.js');
var position = require('../../../utils/dom/position.js');
const SCOPE = "ElInfiniteScroll";
const CHECK_INTERVAL = 50;
const DEFAULT_DELAY = 200;
const DEFAULT_DISTANCE = 0;
const attributes = {
delay: {
type: Number,
default: DEFAULT_DELAY
},
distance: {
type: Number,
default: DEFAULT_DISTANCE
},
disabled: {
type: Boolean,
default: false
},
immediate: {
type: Boolean,
default: true
}
};
const getScrollOptions = (el, instance) => {
return Object.entries(attributes).reduce((acm, [name, option]) => {
var _a, _b;
const { type, default: defaultValue } = option;
const attrVal = el.getAttribute(`infinite-scroll-${name}`);
let value = (_b = (_a = instance[attrVal]) != null ? _a : attrVal) != null ? _b : defaultValue;
value = value === "false" ? false : value;
value = type(value);
acm[name] = Number.isNaN(value) ? defaultValue : value;
return acm;
}, {});
};
const destroyObserver = (el) => {
const { observer } = el[SCOPE];
if (observer) {
observer.disconnect();
delete el[SCOPE].observer;
}
};
const handleScroll = (el, cb) => {
const { container, containerEl, instance, observer, lastScrollTop } = el[SCOPE];
const { disabled, distance } = getScrollOptions(el, instance);
const { clientHeight, scrollHeight, scrollTop } = containerEl;
const delta = scrollTop - lastScrollTop;
el[SCOPE].lastScrollTop = scrollTop;
if (observer || disabled || delta < 0)
return;
let shouldTrigger = false;
if (container === el) {
shouldTrigger = scrollHeight - (clientHeight + scrollTop) <= distance;
} else {
const { clientTop, scrollHeight: height } = el;
const offsetTop = position.getOffsetTopDistance(el, containerEl);
shouldTrigger = scrollTop + clientHeight >= offsetTop + clientTop + height - distance;
}
if (shouldTrigger) {
cb.call(instance);
}
};
function checkFull(el, cb) {
const { containerEl, instance } = el[SCOPE];
const { disabled } = getScrollOptions(el, instance);
if (disabled || containerEl.clientHeight === 0)
return;
if (containerEl.scrollHeight <= containerEl.clientHeight) {
cb.call(instance);
} else {
destroyObserver(el);
}
}
const InfiniteScroll = {
async mounted(el, binding) {
const { instance, value: cb } = binding;
if (!shared.isFunction(cb)) {
error.throwError(SCOPE, "'v-infinite-scroll' binding value must be a function");
}
await vue.nextTick();
const { delay, immediate } = getScrollOptions(el, instance);
const container = scroll.getScrollContainer(el, true);
const containerEl = container === window ? document.documentElement : container;
const onScroll = lodashUnified.throttle(handleScroll.bind(null, el, cb), delay);
if (!container)
return;
el[SCOPE] = {
instance,
container,
containerEl,
delay,
cb,
onScroll,
lastScrollTop: containerEl.scrollTop
};
if (immediate) {
const observer = new MutationObserver(lodashUnified.throttle(checkFull.bind(null, el, cb), CHECK_INTERVAL));
el[SCOPE].observer = observer;
observer.observe(el, { childList: true, subtree: true });
checkFull(el, cb);
}
container.addEventListener("scroll", onScroll);
},
unmounted(el) {
if (!el[SCOPE])
return;
const { container, onScroll } = el[SCOPE];
container == null ? void 0 : container.removeEventListener("scroll", onScroll);
destroyObserver(el);
},
async updated(el) {
if (!el[SCOPE]) {
await vue.nextTick();
} else {
const { containerEl, cb, observer } = el[SCOPE];
if (containerEl.clientHeight && observer) {
checkFull(el, cb);
}
}
}
};
exports.CHECK_INTERVAL = CHECK_INTERVAL;
exports.DEFAULT_DELAY = DEFAULT_DELAY;
exports.DEFAULT_DISTANCE = DEFAULT_DISTANCE;
exports.SCOPE = SCOPE;
exports["default"] = InfiniteScroll;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
import 'element-plus/es/components/base/style/css';
import 'element-plus/theme-chalk/el-infinite-scroll.css';

View File

@@ -0,0 +1,6 @@
'use strict';
require('../../base/style/css.js');
require('element-plus/theme-chalk/el-infinite-scroll.css');
//# sourceMappingURL=css.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}

View File

@@ -0,0 +1,2 @@
import 'element-plus/es/components/base/style';
import 'element-plus/theme-chalk/src/infinite-scroll.scss';

View File

@@ -0,0 +1,6 @@
'use strict';
require('../../base/style/index.js');
require('element-plus/theme-chalk/src/infinite-scroll.scss');
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}