Skip to content

Commit

Permalink
fix: update modules and fix context
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Jun 4, 2023
1 parent 87b9a96 commit 5dfea55
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
6 changes: 3 additions & 3 deletions packages/infinite-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"dist/*"
],
"dependencies": {
"@daybrush/utils": "^1.9.1",
"@daybrush/utils": "^1.13.0",
"@egjs/agent": "^2.2.1",
"@scena/event-emitter": "^1.0.5",
"css-styled": "^1.0.7",
"css-styled": "^1.0.8",
"framework-utils": "^1.1.0",
"gesto": "^1.18.0"
"gesto": "^1.19.1"
},
"devDependencies": {
"@daybrush/builder": "^0.1.2",
Expand Down
24 changes: 14 additions & 10 deletions packages/infinite-viewer/src/InfiniteViewerManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import EventEmitter from "@scena/event-emitter";
import Gesto from "gesto";
import { InjectResult } from "css-styled";
import { Properties } from "framework-utils";
import { camelize, IObject, addEvent, removeEvent, addClass, convertUnitSize, between, isObject, isArray, isString } from "@daybrush/utils";
import { camelize, IObject, addEvent, removeEvent, addClass, convertUnitSize, between, isObject, isArray, isString, isNode, getDocument, getWindow } from "@daybrush/utils";
import { InfiniteViewerOptions, InfiniteViewerProperties, InfiniteViewerEvents, OnPinch, AnimationOptions, ScrollOptions, ZoomOptions, GetScollPosOptions, InnerScrollOptions, ScrollCenterOptions, SetOptions } from "./types";
import {
PROPERTIES, injector, CLASS_NAME, TINY_NUM,
Expand Down Expand Up @@ -78,7 +78,7 @@ class InfiniteViewer extends EventEmitter<InfiniteViewerEvents> {
super();


if (viewportElement instanceof Element) {
if (isNode(viewportElement)) {
this._viewportElement = viewportElement;
this.options = {
...DEFAULT_OPTIONS,
Expand Down Expand Up @@ -453,6 +453,8 @@ class InfiniteViewer extends EventEmitter<InfiniteViewerEvents> {
// children
const containerElement = this._containerElement;
const options = this.options;
const doc = getDocument(containerElement);
const win = getWindow(containerElement);

// vanilla
let wrapperElement = options.wrapperElement
Expand All @@ -465,14 +467,14 @@ class InfiniteViewer extends EventEmitter<InfiniteViewerEvents> {
|| containerElement.querySelector(`.${VERTICAL_SCROLL_BAR_CLASS_NAME}`);

if (!wrapperElement) {
wrapperElement = document.createElement("div");
wrapperElement = doc.createElement("div");
wrapperElement.insertBefore(this._viewportElement, null);
containerElement.insertBefore(wrapperElement, null);
}
this.wrapperElement = wrapperElement;

if (!scrollAreaElement) {
scrollAreaElement = document.createElement("div");
scrollAreaElement = doc.createElement("div");

wrapperElement.insertBefore(scrollAreaElement, wrapperElement.firstChild);
}
Expand All @@ -484,10 +486,12 @@ class InfiniteViewer extends EventEmitter<InfiniteViewerEvents> {
addClass(scrollAreaElement, SCROLL_AREA_CLASS_NAME);

const horizontalBar = new ScrollBar(
containerElement,
"horizontal",
horizontalScrollElement,
);
const verticalBar = new ScrollBar(
containerElement,
"vertical",
verticalScrollElement,
);
Expand Down Expand Up @@ -517,8 +521,8 @@ class InfiniteViewer extends EventEmitter<InfiniteViewerEvents> {

if (wheelContainerOption) {
if (isString(wheelContainerOption)) {
wheelContainerElement = document.querySelector(wheelContainerOption);
} else if (wheelContainerOption instanceof Node) {
wheelContainerElement = doc.querySelector(wheelContainerOption);
} else if (isNode(wheelContainerOption)) {
wheelContainerElement = wheelContainerOption;
} else if ("value" in wheelContainerOption || "current" in wheelContainerOption) {
wheelContainerElement = wheelContainerOption.current || wheelContainerOption.value;
Expand Down Expand Up @@ -610,7 +614,7 @@ class InfiniteViewer extends EventEmitter<InfiniteViewerEvents> {
* });
*/
this.gesto = new Gesto(containerElement, {
container: window,
container: getWindow(containerElement),
events: ["touch", "mouse"],
preventWheelClick: this.options.preventWheelClick ?? true,
}).on("dragStart", e => {
Expand Down Expand Up @@ -692,7 +696,7 @@ class InfiniteViewer extends EventEmitter<InfiniteViewerEvents> {
addEvent(wrapperElement, "scroll", this._onScroll);

if (options.useResizeObserver) {
const observer = new ResizeObserver(() => {
const observer = new win.ResizeObserver(() => {
this.resize();
});

Expand All @@ -704,10 +708,10 @@ class InfiniteViewer extends EventEmitter<InfiniteViewerEvents> {
observer.disconnect();
});
} else {
addEvent(window, "resize", this.resize);
addEvent(win, "resize", this.resize);

this._onDestroys.push(() => {
removeEvent(window, "resize", this.resize);
removeEvent(win, "resize", this.resize);
})
}

Expand Down
11 changes: 7 additions & 4 deletions packages/infinite-viewer/src/ScrollBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
SCROLL_BAR_CLASS_NAME, SCROLL_THUMB_CLASS_NAME,
HORIZONTAL_SCROLL_BAR_CLASS_NAME, VERTICAL_SCROLL_BAR_CLASS_NAME
} from "./consts";
import { addClass, removeEvent, addEvent, throttle } from "@daybrush/utils";
import { addClass, removeEvent, addEvent, throttle, getDocument, getWindow } from "@daybrush/utils";
import EventEmitter from "@scena/event-emitter";
import { abs } from "./utils";

Expand All @@ -17,17 +17,20 @@ export default class ScrollBar extends EventEmitter {
protected isHorizontal = false;

constructor(
containerElement: HTMLElement,
public type: "horizontal" | "vertical",
container?: HTMLElement,
) {
super();
const isHorizontal = type === "horizontal";
const doc = getDocument(containerElement);

let thumbElement: HTMLElement;
let barElement: HTMLElement = container;

if (!container) {
barElement = document.createElement("div");
thumbElement = document.createElement("div");
barElement = doc.createElement("div");
thumbElement = doc.createElement("div");

barElement.insertBefore(thumbElement, null);
this.isAppend = true;
Expand All @@ -46,7 +49,7 @@ export default class ScrollBar extends EventEmitter {
this.barElement = barElement;
this.isHorizontal = isHorizontal;
this.gesto = new Gesto(barElement, {
container: window,
container: getWindow(doc),
}).on(
"dragStart",
e => this._onDragStart(e),
Expand Down
28 changes: 14 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1814,10 +1814,10 @@
dependencies:
prototype-minify "^1.0.0"

"@daybrush/utils@^0.10.0", "@daybrush/utils@^0.10.1", "@daybrush/utils@^0.10.3", "@daybrush/utils@^0.11.0", "@daybrush/utils@^1.1.1", "@daybrush/utils@^1.11.0", "@daybrush/utils@^1.3.1", "@daybrush/utils@^1.4.0", "@daybrush/utils@^1.6.0", "@daybrush/utils@^1.7.1", "@daybrush/utils@^1.9.1":
version "1.10.0"
resolved "https://registry.npmjs.org/@daybrush/utils/-/utils-1.10.0.tgz#2a2235269b960b7ffaf05ca2e75379ea1fb58204"
integrity sha512-IDT0DWAGcjxb2+WMr8pHrVTkHVKdilBumX1SubXJUlowN4rMSLphwDxvMNfv+vQOrdCPXSoPVZ3mhfrHsQ9Xow==
"@daybrush/utils@^0.10.0", "@daybrush/utils@^0.10.1", "@daybrush/utils@^0.10.3", "@daybrush/utils@^0.11.0", "@daybrush/utils@^1.1.1", "@daybrush/utils@^1.13.0", "@daybrush/utils@^1.3.1", "@daybrush/utils@^1.4.0", "@daybrush/utils@^1.6.0", "@daybrush/utils@^1.7.1":
version "1.13.0"
resolved "https://registry.npmjs.org/@daybrush/utils/-/utils-1.13.0.tgz#ea70a60864130da476406fdd1d465e3068aea0ff"
integrity sha512-ALK12C6SQNNHw1enXK+UO8bdyQ+jaWNQ1Af7Z3FNxeAwjYhQT7do+TRE4RASAJ3ObaS2+TJ7TXR3oz2Gzbw0PQ==

"@discoveryjs/json-ext@0.5.6":
version "0.5.6"
Expand Down Expand Up @@ -7013,12 +7013,12 @@ css-selector-tokenizer@^0.7.0:
cssesc "^3.0.0"
fastparse "^1.1.2"

css-styled@^0.1.7, css-styled@^1.0.7:
version "1.0.7"
resolved "https://registry.npmjs.org/css-styled/-/css-styled-1.0.7.tgz#08bb17676b27e62b3978d1072c3dbbebb96edb51"
integrity sha512-ud6VclnjgwWxkxz3vrLTv7oEKP3xP/VeydTj5VAqa8zp5LFqKnHb7oSMgW+Z1R70Oz7sfBNEkv/H+yE9FhM4HQ==
css-styled@^0.1.7, css-styled@^1.0.7, css-styled@^1.0.8:
version "1.0.8"
resolved "https://registry.npmjs.org/css-styled/-/css-styled-1.0.8.tgz#c9c05dc4abdef5571033090bfb8cfc5e19429974"
integrity sha512-tCpP7kLRI8dI95rCh3Syl7I+v7PP+2JYOzWkl0bUEoSbJM+u8ITbutjlQVf0NC2/g4ULROJPi16sfwDIO8/84g==
dependencies:
"@daybrush/utils" "^1.11.0"
"@daybrush/utils" "^1.13.0"

css-to-mat@^1.0.3:
version "1.0.3"
Expand Down Expand Up @@ -9386,12 +9386,12 @@ gensync@^1.0.0-beta.1, gensync@^1.0.0-beta.2:
resolved "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0"
integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==

gesto@^1.12.2, gesto@^1.18.0:
version "1.18.0"
resolved "https://registry.npmjs.org/gesto/-/gesto-1.18.0.tgz#d1de6cb8086d9f8b919b1f75c8fc78ed40ad2b07"
integrity sha512-XjGedc2Ix1Z8Py5IlFqupp0dg/2Iwq0/KiJITZ8zX1WfBSkD+G2j4J0ohWCEtmTdWWvJSi1Ql6iDq+NdIHYzVg==
gesto@^1.12.2, gesto@^1.19.1:
version "1.19.1"
resolved "https://registry.npmjs.org/gesto/-/gesto-1.19.1.tgz#b2a29730663eecf77b248982bbff929e79d4a461"
integrity sha512-ofWVEdqmnpFm3AFf7aoclhoayseb3OkwSiXbXusKYu/99iN5HgeWP+SWqdghQ5TFlOgP5Zlz+6SY8mP2V0kFaQ==
dependencies:
"@daybrush/utils" "^1.7.1"
"@daybrush/utils" "^1.13.0"
"@scena/event-emitter" "^1.0.2"

get-caller-file@^2.0.1, get-caller-file@^2.0.5:
Expand Down

0 comments on commit 5dfea55

Please sign in to comment.