This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+109
View File
@@ -0,0 +1,109 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _directives = require("../../directives");
var _console = require("../../util/console");
var _vue = _interopRequireDefault(require("vue"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Directives
// Utilities
// Types
/**
* Scrollable
*
* Used for monitoring scrolling and
* invoking functions based upon
* scrolling thresholds being
* met.
*/
/* @vue/component */
var _default = _vue.default.extend({
name: 'scrollable',
directives: {
Scroll: _directives.Scroll
},
props: {
scrollTarget: String,
scrollThreshold: [String, Number]
},
data: function data() {
return {
currentScroll: 0,
currentThreshold: 0,
isActive: false,
isScrollingUp: false,
previousScroll: 0,
savedScroll: 0,
target: null
};
},
computed: {
/**
* A computed property that returns
* whether scrolling features are
* enabled or disabled
*/
canScroll: function canScroll() {
return typeof window !== 'undefined';
},
/**
* The threshold that must be met before
* thresholdMet function is invoked
*/
computedScrollThreshold: function computedScrollThreshold() {
return this.scrollThreshold ? Number(this.scrollThreshold) : 300;
}
},
watch: {
isScrollingUp: function isScrollingUp() {
this.savedScroll = this.savedScroll || this.currentScroll;
},
isActive: function isActive() {
this.savedScroll = 0;
}
},
mounted: function mounted() {
if (this.scrollTarget) {
this.target = document.querySelector(this.scrollTarget);
if (!this.target) {
(0, _console.consoleWarn)("Unable to locate element with identifier ".concat(this.scrollTarget), this);
}
}
},
methods: {
onScroll: function onScroll() {
var _this = this;
if (!this.canScroll) return;
this.previousScroll = this.currentScroll;
this.currentScroll = this.target ? this.target.scrollTop : window.pageYOffset;
this.isScrollingUp = this.currentScroll < this.previousScroll;
this.currentThreshold = Math.abs(this.currentScroll - this.computedScrollThreshold);
this.$nextTick(function () {
if (Math.abs(_this.currentScroll - _this.savedScroll) > _this.computedScrollThreshold) _this.thresholdMet();
});
},
/**
* The method invoked when
* scrolling in any direction
* has exceeded the threshold
*/
thresholdMet: function thresholdMet() {}
}
});
exports.default = _default;
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/mixins/scrollable/index.ts"],"names":[],"mappings":";;;;;;;AACA;;AAGA;;AAGA;;;;AAPA;AAGA;AAGA;;AAGA;;;;;;;;;AAQA;eACe,aAAI,MAAJ,CAAW;AACxB,EAAA,IAAI,EAAE,YADkB;AAGxB,EAAA,UAAU,EAAE;AAAE,IAAA,MAAM,EAAN;AAAF,GAHY;AAKxB,EAAA,KAAK,EAAE;AACL,IAAA,YAAY,EAAE,MADT;AAEL,IAAA,eAAe,EAAE,CAAC,MAAD,EAAS,MAAT;AAFZ,GALiB;AAUxB,EAAA,IAAI,EAAE;AAAA,WAAO;AACX,MAAA,aAAa,EAAE,CADJ;AAEX,MAAA,gBAAgB,EAAE,CAFP;AAGX,MAAA,QAAQ,EAAE,KAHC;AAIX,MAAA,aAAa,EAAE,KAJJ;AAKX,MAAA,cAAc,EAAE,CALL;AAMX,MAAA,WAAW,EAAE,CANF;AAOX,MAAA,MAAM,EAAE;AAPG,KAAP;AAAA,GAVkB;AAoBxB,EAAA,QAAQ,EAAE;AACR;;;;;AAKA,IAAA,SANQ,uBAMC;AACP,aAAO,OAAO,MAAP,KAAkB,WAAzB;AACD,KARO;;AASR;;;;AAIA,IAAA,uBAbQ,qCAae;AACrB,aAAO,KAAK,eAAL,GACH,MAAM,CAAC,KAAK,eAAN,CADH,GAEH,GAFJ;AAGD;AAjBO,GApBc;AAwCxB,EAAA,KAAK,EAAE;AACL,IAAA,aADK,2BACQ;AACX,WAAK,WAAL,GAAmB,KAAK,WAAL,IAAoB,KAAK,aAA5C;AACD,KAHI;AAIL,IAAA,QAJK,sBAIG;AACN,WAAK,WAAL,GAAmB,CAAnB;AACD;AANI,GAxCiB;AAiDxB,EAAA,OAjDwB,qBAiDjB;AACL,QAAI,KAAK,YAAT,EAAuB;AACrB,WAAK,MAAL,GAAc,QAAQ,CAAC,aAAT,CAAuB,KAAK,YAA5B,CAAd;;AAEA,UAAI,CAAC,KAAK,MAAV,EAAkB;AAChB,qFAAwD,KAAK,YAA7D,GAA6E,IAA7E;AACD;AACF;AACF,GAzDuB;AA2DxB,EAAA,OAAO,EAAE;AACP,IAAA,QADO,sBACC;AAAA;;AACN,UAAI,CAAC,KAAK,SAAV,EAAqB;AAErB,WAAK,cAAL,GAAsB,KAAK,aAA3B;AACA,WAAK,aAAL,GAAqB,KAAK,MAAL,GACjB,KAAK,MAAL,CAAY,SADK,GAEjB,MAAM,CAAC,WAFX;AAIA,WAAK,aAAL,GAAqB,KAAK,aAAL,GAAqB,KAAK,cAA/C;AACA,WAAK,gBAAL,GAAwB,IAAI,CAAC,GAAL,CAAS,KAAK,aAAL,GAAqB,KAAK,uBAAnC,CAAxB;AAEA,WAAK,SAAL,CAAe,YAAK;AAClB,YACE,IAAI,CAAC,GAAL,CAAS,KAAI,CAAC,aAAL,GAAqB,KAAI,CAAC,WAAnC,IACA,KAAI,CAAC,uBAFP,EAGE,KAAI,CAAC,YAAL;AACH,OALD;AAMD,KAlBM;;AAmBP;;;;;AAKA,IAAA,YAxBO,0BAwBK,CAAkB;AAxBvB;AA3De,CAAX,C","sourcesContent":["// Directives\nimport { Scroll } from '../../directives'\n\n// Utilities\nimport { consoleWarn } from '../../util/console'\n\n// Types\nimport Vue from 'vue'\n\n/**\n * Scrollable\n *\n * Used for monitoring scrolling and\n * invoking functions based upon\n * scrolling thresholds being\n * met.\n */\n/* @vue/component */\nexport default Vue.extend({\n name: 'scrollable',\n\n directives: { Scroll },\n\n props: {\n scrollTarget: String,\n scrollThreshold: [String, Number],\n },\n\n data: () => ({\n currentScroll: 0,\n currentThreshold: 0,\n isActive: false,\n isScrollingUp: false,\n previousScroll: 0,\n savedScroll: 0,\n target: null as Element | null,\n }),\n\n computed: {\n /**\n * A computed property that returns\n * whether scrolling features are\n * enabled or disabled\n */\n canScroll (): boolean {\n return typeof window !== 'undefined'\n },\n /**\n * The threshold that must be met before\n * thresholdMet function is invoked\n */\n computedScrollThreshold (): number {\n return this.scrollThreshold\n ? Number(this.scrollThreshold)\n : 300\n },\n },\n\n watch: {\n isScrollingUp () {\n this.savedScroll = this.savedScroll || this.currentScroll\n },\n isActive () {\n this.savedScroll = 0\n },\n },\n\n mounted () {\n if (this.scrollTarget) {\n this.target = document.querySelector(this.scrollTarget)\n\n if (!this.target) {\n consoleWarn(`Unable to locate element with identifier ${this.scrollTarget}`, this)\n }\n }\n },\n\n methods: {\n onScroll () {\n if (!this.canScroll) return\n\n this.previousScroll = this.currentScroll\n this.currentScroll = this.target\n ? this.target.scrollTop\n : window.pageYOffset\n\n this.isScrollingUp = this.currentScroll < this.previousScroll\n this.currentThreshold = Math.abs(this.currentScroll - this.computedScrollThreshold)\n\n this.$nextTick(() => {\n if (\n Math.abs(this.currentScroll - this.savedScroll) >\n this.computedScrollThreshold\n ) this.thresholdMet()\n })\n },\n /**\n * The method invoked when\n * scrolling in any direction\n * has exceeded the threshold\n */\n thresholdMet () { /* noop */ },\n },\n})\n"],"sourceRoot":"","file":"index.js"}