Skip to content

Commit b29ff67

Browse files
committed
feat: force-copy mobile support
1 parent 189ba35 commit b29ff67

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

packages/copy/src/constant/event.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export const COPY = "copy";
1212
export const SELECT_START = "selectstart";
1313
export const CONTEXT_MENU = "contextmenu";
1414
export const KEY_DOWN = "keydown";
15+
export const TOUCH_START = "touchstart";

packages/force-copy/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "force-copy",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"author": "Czy",
55
"license": "MIT",
66
"sideEffects": false,
@@ -20,7 +20,7 @@
2020
"@arco-design/web-react": "^2.50.0",
2121
"copy": "workspace: *",
2222
"copy-currency": "workspace: *",
23-
"laser-utils": "0.0.2-alpha.6",
23+
"laser-utils": "0.0.2-alpha.10",
2424
"react": "^17.0.1",
2525
"react-dom": "^17.0.1"
2626
},

packages/force-copy/src/inject/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import { DOM_STAGE } from "copy/src/constant/event";
2222
// @ts-ignore
2323
window[process.env.EVENT_TYPE] = true;
2424
logger.info("Inject Script Loaded");
25+
// 初始化事件
2526
initBaseEvents();
27+
// 初始化状态
2628
const state: State = {
2729
COPY: !!storage.local.get<boolean>(COPY_TYPE) || !!storage.session.get<boolean>(COPY_TYPE),
2830
KEYBOARD:

packages/force-copy/src/inject/modules/basic.ts

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const Basic: WebSite = {
1313
EventBus.on(EVENTS_ENUM.COPY_CAPTURE, stopNativePropagation);
1414
EventBus.on(EVENTS_ENUM.KEY_BOARD_CAPTURE, copyKeyboardHandler);
1515
EventBus.on(EVENTS_ENUM.SELECT_START_CAPTURE, stopNativePropagation);
16+
EventBus.on(EVENTS_ENUM.TOUCH_START_CAPTURE, stopNativePropagation);
1617
} else if (type === KEYBOARD_TYPE) {
1718
EventBus.on(EVENTS_ENUM.KEY_BOARD_CAPTURE, stopNativePropagation);
1819
} else if (type === CONTEXT_MENU_TYPE) {
@@ -25,6 +26,7 @@ export const Basic: WebSite = {
2526
EventBus.off(EVENTS_ENUM.COPY_CAPTURE, stopNativePropagation);
2627
EventBus.off(EVENTS_ENUM.KEY_BOARD_CAPTURE, copyKeyboardHandler);
2728
EventBus.off(EVENTS_ENUM.SELECT_START_CAPTURE, stopNativePropagation);
29+
EventBus.off(EVENTS_ENUM.TOUCH_START_CAPTURE, stopNativePropagation);
2830
} else if (type === KEYBOARD_TYPE) {
2931
EventBus.off(EVENTS_ENUM.KEY_BOARD_CAPTURE, stopNativePropagation);
3032
} else if (type === CONTEXT_MENU_TYPE) {

packages/force-copy/src/inject/utils/events.ts

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
MOUSE_UP,
88
PAGE_LOADED,
99
SELECT_START,
10+
TOUCH_START,
1011
} from "copy/src/constant/event";
1112
import { EVENTS_ENUM, EventBus } from "./bus";
1213

@@ -27,6 +28,11 @@ export const initBaseEvents = () => {
2728
e => EventBus.emit(EVENTS_ENUM.SELECT_START_CAPTURE, e),
2829
true
2930
);
31+
window.addEventListener(
32+
TOUCH_START,
33+
e => EventBus.emit(EVENTS_ENUM.TOUCH_START_CAPTURE, e),
34+
true
35+
);
3036
window.addEventListener(DOM_READY, e => EventBus.emit(EVENTS_ENUM.DOM_LOADED, e), true);
3137
window.addEventListener(PAGE_LOADED, e => EventBus.emit(EVENTS_ENUM.PAGE_LOADED, e), true);
3238
};

pnpm-lock.yaml

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)