Skip to content

Commit

Permalink
fix: fix iframe css
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed May 30, 2023
1 parent 58f2e89 commit 0d217f1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@
"framework-utils": "^1.1.0",
"gesto": "^1.15.1",
"overlap-area": "^1.1.0",
"react-compat-css-styled": "^1.0.8",
"react-css-styled": "^1.0.3",
"tslib": "^2.3.0"
},
"overrides": {
Expand All @@ -109,8 +107,6 @@
"framework-utils": "^1.1.0",
"gesto": "^1.15.1",
"overlap-area": "^1.1.0",
"react-compat-css-styled": "^1.0.8",
"react-css-styled": "^1.0.3",
"tslib": "^2.3.0"
}
}
2 changes: 1 addition & 1 deletion packages/selecto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@egjs/children-differ": "^1.0.1",
"@scena/dragscroll": "^1.4.0",
"@scena/event-emitter": "^1.0.5",
"css-styled": "^1.0.0",
"css-styled": "^1.0.7",
"css-to-mat": "^1.0.3",
"framework-utils": "^1.1.0",
"gesto": "^1.15.1",
Expand Down
26 changes: 18 additions & 8 deletions packages/selecto/src/SelectoManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
elementFromPoint,
filterDuplicated,
getLineSize,
getDocument,
} from "./utils";
import {
SelectoOptions,
Expand Down Expand Up @@ -288,6 +289,7 @@ class Selecto extends EventEmitter<SelectoEvents> {
* Get all elements set in `selectableTargets`.
*/
public getSelectableElements() {
const container = this.container;
const selectableElements: Array<HTMLElement | SVGElement> = [];

this.options.selectableTargets.forEach((target) => {
Expand All @@ -303,7 +305,7 @@ class Selecto extends EventEmitter<SelectoEvents> {
selectableElements.push(target.value || target.current);
} else {
const elements = [].slice.call(
document.querySelectorAll(target)
(getDocument(container)).querySelectorAll(target)
);

selectableElements.push(...elements);
Expand Down Expand Up @@ -347,6 +349,7 @@ class Selecto extends EventEmitter<SelectoEvents> {

const options = this.options;
const hasIndexesMap = options.checkOverflow || options.innerScrollOptions;
const doc = getDocument(this.container);

if (hasIndexesMap) {
const parentMap = new Map<Element, InnerParentInfo>();
Expand All @@ -358,7 +361,7 @@ class Selecto extends EventEmitter<SelectoEvents> {
let parents: Element[] = [];
const paths: Element[] = [];

while (parentElement && parentElement !== document.body) {
while (parentElement && parentElement !== doc.body) {
let info: InnerParentInfo = parentMap.get(parentElement);

if (!info) {
Expand Down Expand Up @@ -515,12 +518,15 @@ class Selecto extends EventEmitter<SelectoEvents> {
this.gesto.options.checkInput = value;
}
private initElement() {
const container = this.container;

this.target = createElement(
(<div className={CLASS_NAME}></div>) as any,
this.target,
this.container
container,
);


const target = this.target;

const {
Expand All @@ -534,7 +540,7 @@ class Selecto extends EventEmitter<SelectoEvents> {
} = this.options;
this.dragContainer =
typeof dragContainer === "string"
? [].slice.call(document.querySelectorAll(dragContainer))
? [].slice.call(getDocument(container).querySelectorAll(dragContainer))
: dragContainer || (this.target.parentNode as any);
this.gesto = new Gesto(this.dragContainer, {
checkWindowBlur: true,
Expand Down Expand Up @@ -914,6 +920,7 @@ class Selecto extends EventEmitter<SelectoEvents> {
data.containerY = 0;


const container = this.container;
let boundArea = {
left: -Infinity,
top: -Infinity,
Expand Down Expand Up @@ -950,7 +957,7 @@ class Selecto extends EventEmitter<SelectoEvents> {

if (boundElement) {
if (isString(boundElement)) {
rectElement = document.querySelector(boundElement);
rectElement = getDocument(container).querySelector(boundElement);
} else if (boundElement === true) {
rectElement = this.container;
} else {
Expand Down Expand Up @@ -1102,7 +1109,7 @@ class Selecto extends EventEmitter<SelectoEvents> {
let innerScrollElement: HTMLElement | null = null;
let parentElement = target;

while (parentElement && parentElement !== document.body) {
while (parentElement && parentElement !== getDocument(container).body) {

const overflow = getComputedStyle(parentElement).overflow !== "visible";

Expand Down Expand Up @@ -1228,6 +1235,7 @@ class Selecto extends EventEmitter<SelectoEvents> {
const { data, inputEvent } = e;
const rect = getRect(e, this.options.ratio);
const selectFlag = data.selectFlag;
const container = this.container;

/**
* When the drag ends (triggers on mouseup or touchend after drag), the dragEnd event is called.
Expand All @@ -1254,7 +1262,7 @@ class Selecto extends EventEmitter<SelectoEvents> {
} else if (this.selectByClick && this.clickBySelectEnd) {
// only clickBySelectEnd
const pointTarget = this._findElement(
inputEvent?.target || elementFromPoint(e.clientX, e.clientY),
inputEvent?.target || elementFromPoint(container, e.clientX, e.clientY),
data.selectableTargets,
);
this._select(pointTarget ? [pointTarget] : [], rect, e);
Expand Down Expand Up @@ -1399,13 +1407,15 @@ class Selecto extends EventEmitter<SelectoEvents> {
}
};
private _onDocumentSelectStart = (e: any) => {
const doc = getDocument(this.container);

if (!this.gesto.isFlag()) {
return;
}
let dragContainer = this.dragContainer;

if (dragContainer === window) {
dragContainer = document.documentElement;
dragContainer = doc.documentElement;
}
const containers =
dragContainer instanceof Element
Expand Down
12 changes: 10 additions & 2 deletions packages/selecto/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ export function filterDuplicated<T>(arr: T[]): T[] {
return true;
});
}
export function elementFromPoint(clientX: number, clientY: number): HTMLElement | SVGElement | null {
return (document.elementFromPoint && document.elementFromPoint(clientX, clientY)) as any || null;

export function elementFromPoint(baseNode: Node, clientX: number, clientY: number): HTMLElement | SVGElement | null {
const doc = getDocument(baseNode);

return (doc.elementFromPoint && doc.elementFromPoint(clientX, clientY)) as any || null;
}

export function createElement(
jsx: Hypertext,
prevTarget?: HTMLElement | SVGElement,
Expand Down Expand Up @@ -210,3 +214,7 @@ export function getLineSize(points: number[][]) {

return size;
}

export function getDocument(el: Node) {
return el.ownerDocument || document;
}
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@
dependencies:
prototype-minify "^1.0.0"

"@daybrush/utils@^0.10.0", "@daybrush/utils@^0.10.1", "@daybrush/utils@^0.11.0", "@daybrush/utils@^1.0.0", "@daybrush/utils@^1.1.1", "@daybrush/utils@^1.3.1", "@daybrush/utils@^1.4.0", "@daybrush/utils@^1.6.0", "@daybrush/utils@^1.7.1":
"@daybrush/utils@^0.10.0", "@daybrush/utils@^0.10.1", "@daybrush/utils@^0.11.0", "@daybrush/utils@^1.0.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":
version "1.7.1"
resolved "https://registry.npmjs.org/@daybrush/utils/-/utils-1.7.1.tgz"
integrity sha512-ruVDIfXeVAF4s0RxJoNx5hTjxlIRMnKoJ7N5e2m9eDyluIXB12EvhMPQdoq4a/ohJ+cPgj2MiWS5Lvmpsrx8Gg==
Expand Down Expand Up @@ -8678,6 +8678,13 @@ css-styled@^1.0.0:
"@daybrush/utils" "^1.0.0"
string-hash "^1.1.3"

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==
dependencies:
"@daybrush/utils" "^1.11.0"

css-to-mat@^1.0.3:
version "1.0.3"
resolved "https://registry.npmjs.org/css-to-mat/-/css-to-mat-1.0.3.tgz"
Expand Down

0 comments on commit 0d217f1

Please sign in to comment.