Skip to content

Commit 04ffe64

Browse files
authored
fix: fix chromium agent (#864)
* test: fix e2e config * demo: add agent * fix: fix chromium agent * fix: fix chromium agent * fix: fix custom element offset
1 parent 6f6e585 commit 04ffe64

File tree

7 files changed

+18
-13
lines changed

7 files changed

+18
-13
lines changed

.github/workflows/run-e2e.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
run: npm run test:fail-ci
3535
working-directory: ./packages/react-moveable
3636
- name: Archive Failed Artifact
37+
if: ${{ failure() }}
3738
uses: actions/upload-artifact@v2
3839
with:
3940
name: failed snapshot

packages/react-moveable/.storybook/test-runner.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
// .storybook/test-runner.js
2-
const { toMatchImageSnapshot } = require('jest-image-snapshot');
3-
41
const customSnapshotsDir = `${process.cwd()}/__snapshots__`;
52

63
module.exports = {
7-
setup() {
8-
expect.extend({ toMatchImageSnapshot });
9-
},
104
async postRender(page, context) {
115
if (!process.env.SKIP_TEST) {
126
return;

packages/react-moveable/src/consts.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ export const IS_WEBKIT605 = IS_WEBKIT && (() => {
3939

4040
const browserName = agent.browser.name;
4141
const browserVersion = parseInt(agent.browser.version, 10);
42+
const IS_CHROME = browserName === "chrome";
4243
const IS_CHROMIUM = agent.browser.chromium;
4344
const chromiumVersion = parseInt(agent.browser.chromiumVersion, 10) || 0;
4445

45-
export const IS_CHROME109 = IS_CHROMIUM && chromiumVersion >= 109;
46+
export const IS_CHROMIUM109 = (IS_CHROME && browserVersion >= 109)
47+
|| (IS_CHROMIUM && chromiumVersion >= 109);
4648
export const IS_FIREFOX = browserName === "firefox";
4749
export const IS_SAFARI_ABOVE15
4850
= parseInt(agent.browser.webkitVersion, 10) >= 612

packages/react-moveable/src/utils.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,11 @@ export function getOffsetInfo(
196196
}
197197
const parentNode = slotParentNode || targetParentNode;
198198

199-
200199
if (parentNode && parentNode.nodeType === 11) {
201200
// Shadow Root
202201
target = (parentNode as ShadowRoot).host as HTMLElement;
203202
isCustomElement = true;
204-
203+
position = getComputedStyle(target).position;
205204
break;
206205
}
207206
target = parentNode as HTMLElement | SVGElement;

packages/react-moveable/src/utils/getMatrixStackInfo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
convertCSStoMatrix, convertDimension,
33
createIdentityMatrix, createOriginMatrix, createScaleMatrix,
44
} from "@scena/matrix";
5-
import { IS_WEBKIT, IS_SAFARI_ABOVE15, IS_FIREFOX, IS_CHROME109 } from "../consts";
5+
import { IS_WEBKIT, IS_SAFARI_ABOVE15, IS_FIREFOX, IS_CHROMIUM109 } from "../consts";
66
import { MatrixInfo } from "../types";
77
import {
88
getOffsetInfo, getElementTransform,
@@ -124,10 +124,10 @@ export function getMatrixStackInfo(
124124
isStatic = offsetInfo.isStatic;
125125
zoom *= offsetZoom;
126126

127-
if (offsetZoom !== 1 && isStatic) {
127+
if ((offsetInfo.isCustomElement || offsetZoom !== 1) && isStatic) {
128128
offsetLeft -= offsetParent.offsetLeft;
129129
offsetTop -= offsetParent.offsetTop;
130-
} else if (IS_FIREFOX || IS_CHROME109) {
130+
} else if (IS_FIREFOX || IS_CHROMIUM109) {
131131
const parentSlotElement = offsetInfo.parentSlotElement;
132132

133133
if (parentSlotElement) {

packages/react-moveable/stories/99-Tests/Deafult.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const TestsCustomElement = add("Test Custom Element Offset", {
3030
await wait();
3131
const moveableElement = findMoveable(canvasElement);
3232

33-
expect(moveableElement.style.transform).toBe("translate3d(60px, 140px, 0px)");
33+
expect(moveableElement.style.transform).toBe("translate3d(60px, 192px, 0px)");
3434
},
3535
});
3636
export const TestsCustomElementBounds = add("Test Custom Element with Bounds", {

packages/react-moveable/stories/99-Tests/ReactCustomElementApp.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,18 @@ declare global {
7373
}
7474

7575
export default function App() {
76+
const [agent, setAgent] = React.useState("");
77+
78+
React.useEffect(() => {
79+
setAgent(navigator.userAgent);
80+
}, []);
7681
return <div className="container" style={{
7782
border: "1px solid black",
7883
}}>
84+
<p style={{
85+
display: "block",
86+
height: "20px",
87+
}}>{agent}</p>
7988
<custom-element style={{
8089
display: "block",
8190
padding: "10px",

0 commit comments

Comments
 (0)