Skip to content

Commit

Permalink
fix: prevent event overlay compatibility with once option
Browse files Browse the repository at this point in the history
  • Loading branch information
zjxxxxxxxxx committed Nov 28, 2024
1 parent 59d33af commit baba659
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-cats-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@open-editor/client': patch
---

Fix prevent event overlay compatibility with once option
2 changes: 1 addition & 1 deletion .codesandbox/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"name": "Create tasks",
"command": "pnpm create-codesandbox-tasks"
"command": "pnpm tasks"
}
],
"tasks": {}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"play": "pnpm start --script=dev",
"lint": "pnpm eslint . --ext .ts,.tsx --ignore-pattern='/playground/*'",
"format": "prettier --write '**/*.{vue,ts,tsx,json,md}'",
"create-codesandbox-tasks": "esno scripts/create-codesandbox-tasks.ts",
"tasks": "esno scripts/create-codesandbox-tasks.ts",
"postinstall": "simple-git-hooks",
"release": "run-s build publish:ci",
"test": "turbo run test",
Expand Down
26 changes: 17 additions & 9 deletions packages/client/src/bridge/treeOpenBridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { crossIframeBridge } from '../utils/crossIframeBridge';
import { isTopWindow, whenTopWindow } from '../utils/topWindow';
import { appendChild } from '../utils/dom';
import { onMessage, postMessage } from '../utils/message';
import { getOptions } from '../options';
import { resolveSource, type CodeSource } from '../resolve';
import { TREE_OPEN_CROSS_IFRAME } from '../constants';
import { on } from '../event';
import { off } from 'process';
import { on, off } from '../event';

export const treeOpenBridge = crossIframeBridge<[CodeSource]>({
setup() {
Expand All @@ -15,15 +15,23 @@ export const treeOpenBridge = crossIframeBridge<[CodeSource]>({
},
emitMiddlewares: [
(_, next) => {
const preventEventOverlay = <div className="oe-prevent-event-overlay" />;
const { once } = getOptions();

const overlay = <div className="oe-prevent-event-overlay" />;
const eventOpts = {
target: once ? overlay : window,
capture: true,
};

const remove = () => {
off('pointerup', remove);
off('pointerout', remove);
preventEventOverlay.remove();
off('pointerup', remove, eventOpts);
off('pointerout', remove, eventOpts);
overlay.remove();
};
on('pointerup', remove, { capture: true });
on('pointerout', remove, { capture: true });
appendChild(document.body, preventEventOverlay);
on('pointerup', remove, eventOpts);
on('pointerout', remove, eventOpts);

appendChild(document.body, overlay);

next();
},
Expand Down

0 comments on commit baba659

Please sign in to comment.