Skip to content

Commit 6992e85

Browse files
committed
feat: force copy experimental features
1 parent 1381747 commit 6992e85

File tree

16 files changed

+140
-23
lines changed

16 files changed

+140
-23
lines changed

packages/copy/src/constant/event.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export const SELECT_START = "selectstart";
1313
export const CONTEXT_MENU = "contextmenu";
1414
export const KEY_DOWN = "keydown";
1515
export const TOUCH_START = "touchstart";
16+
export const TOUCH_MOVE = "touchmove";
17+
export const TOUCH_END = "touchend";
1618
export const FOCUS = "focus";
1719
export const BLUR = "blur";
1820
export const FOCUS_IN = "focusin";

packages/force-copy/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"dev:rollup": "cross-env NODE_ENV=development rollup -wc",
1111
"dev:gecko": "cross-env NODE_ENV=development PLATFORM=gecko rspack build --watch",
1212
"build:gecko": "rm -rf build-gecko && cross-env PLATFORM=gecko rspack build",
13+
"build:zip": "mkdir -p .zip && cd build && zip -r ../.zip/chromium.zip .",
14+
"build:zip:gecko": "mkdir -p .zip && cd build-gecko && zip -r ../.zip/gecko.zip .",
1315
"lint:ts": "../../node_modules/typescript/bin/tsc --noEmit"
1416
},
1517
"repository": {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { decodeJSON, encodeJSON } from "laser-utils";
1+
import { decodeJSON, encodeJSON, isUndefined } from "laser-utils";
22
import type { CIRequestType } from "./request";
33
import { CONTENT_TO_INJECT_REQUEST } from "./request";
44
import { EVENT_TYPE, MARK } from "./constant";
@@ -13,7 +13,7 @@ export class CIBridge {
1313
static onContentMessage(cb: (data: CIRequestType) => void) {
1414
const handler = (event: CustomEvent<string>) => {
1515
const data = decodeJSON<CIRequestType>(event.detail);
16-
if (data && data.type && data.payload) {
16+
if (data && data.type && !isUndefined(data.payload)) {
1717
cb(data);
1818
}
1919
};

packages/force-copy/src/bridge/content-inject/request.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import type { Reflex, Object } from "@/utils/types";
22
import { MARK } from "./constant";
33

4-
const CI_REQUEST_ENUM = ["COPY_TYPE", "KEYBOARD_TYPE", "CONTEXT_MENU_TYPE"] as const;
4+
const CI_REQUEST_ENUM = [
5+
"COPY_TYPE",
6+
"KEYBOARD_TYPE",
7+
"CONTEXT_MENU_TYPE",
8+
"DEBUG_MOUSE_EVENT",
9+
"DEBUG_FOCUS_EVENT",
10+
"DEBUG_EDITABLE",
11+
] as const;
512
export const CONTENT_TO_INJECT_REQUEST = CI_REQUEST_ENUM.reduce(
613
(acc, cur) => ({ ...acc, [cur]: `__${cur}__${MARK}__` }),
714
{} as { [K in typeof CI_REQUEST_ENUM[number]]: `__${K}__${typeof MARK}__` }
@@ -18,6 +25,9 @@ export type EventMap = {
1825
[CONTENT_TO_INJECT_REQUEST.COPY_TYPE]: CIExecutionType;
1926
[CONTENT_TO_INJECT_REQUEST.KEYBOARD_TYPE]: CIExecutionType;
2027
[CONTENT_TO_INJECT_REQUEST.CONTEXT_MENU_TYPE]: CIExecutionType;
28+
[CONTENT_TO_INJECT_REQUEST.DEBUG_MOUSE_EVENT]: null;
29+
[CONTENT_TO_INJECT_REQUEST.DEBUG_FOCUS_EVENT]: null;
30+
[CONTENT_TO_INJECT_REQUEST.DEBUG_EDITABLE]: null;
2131
};
2232

2333
export type CIRequestType = Reflex.Tuple<EventMap>;

packages/force-copy/src/bridge/popup-content/request.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import type { Reflex } from "@/utils/types";
22
import { MARK } from "./constant";
33

4-
const PC_REQUEST_TYPE = ["COPY_TYPE", "KEYBOARD_TYPE", "CONTEXT_MENU_TYPE", "QUERY_STATE"] as const;
4+
const PC_REQUEST_TYPE = [
5+
"COPY_TYPE",
6+
"KEYBOARD_TYPE",
7+
"CONTEXT_MENU_TYPE",
8+
"QUERY_STATE",
9+
"DEBUG_MOUSE_EVENT",
10+
"DEBUG_FOCUS_EVENT",
11+
"DEBUG_EDITABLE",
12+
] as const;
513
export const POPUP_TO_CONTENT_REQUEST = PC_REQUEST_TYPE.reduce(
614
(acc, cur) => ({ ...acc, [cur]: `__${cur}__${MARK}__` }),
715
{} as { [K in typeof PC_REQUEST_TYPE[number]]: `__${K}__${typeof MARK}__` }
@@ -12,6 +20,9 @@ type EventMap = {
1220
[POPUP_TO_CONTENT_REQUEST.KEYBOARD_TYPE]: { checked: boolean; once: boolean };
1321
[POPUP_TO_CONTENT_REQUEST.CONTEXT_MENU_TYPE]: { checked: boolean; once: boolean };
1422
[POPUP_TO_CONTENT_REQUEST.QUERY_STATE]: null;
23+
[POPUP_TO_CONTENT_REQUEST.DEBUG_MOUSE_EVENT]: null;
24+
[POPUP_TO_CONTENT_REQUEST.DEBUG_FOCUS_EVENT]: null;
25+
[POPUP_TO_CONTENT_REQUEST.DEBUG_EDITABLE]: null;
1526
};
1627

1728
export type PCRequestType = Reflex.Tuple<EventMap>;

packages/force-copy/src/content/channel/popup.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { POPUP_TO_CONTENT_REQUEST } from "@/bridge/popup-content/request";
88
import { CIBridge } from "@/bridge/content-inject";
99
import { CONTENT_TO_INJECT_REQUEST } from "@/bridge/content-inject/request";
1010
import { PC_QUERY_STATE_ENUM } from "@/bridge/popup-content/response";
11+
import { PCBridge } from "@/bridge/popup-content";
1112

1213
export const onPopupMessage = (data: PCRequestType) => {
1314
logger.info("Content Receive Popup Message", location.host, data);
@@ -62,5 +63,26 @@ export const onPopupMessage = (data: PCRequestType) => {
6263
},
6364
};
6465
}
66+
case PCBridge.REQUEST.DEBUG_MOUSE_EVENT: {
67+
CIBridge.postToInject({
68+
type: CIBridge.REQUEST.DEBUG_MOUSE_EVENT,
69+
payload: null,
70+
});
71+
break;
72+
}
73+
case PCBridge.REQUEST.DEBUG_FOCUS_EVENT: {
74+
CIBridge.postToInject({
75+
type: CIBridge.REQUEST.DEBUG_FOCUS_EVENT,
76+
payload: null,
77+
});
78+
break;
79+
}
80+
case PCBridge.REQUEST.DEBUG_EDITABLE: {
81+
CIBridge.postToInject({
82+
type: CIBridge.REQUEST.DEBUG_EDITABLE,
83+
payload: null,
84+
});
85+
break;
86+
}
6587
}
6688
};

packages/force-copy/src/inject/channel/content.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { logger } from "@/utils/logger";
44
import { DOM_STAGE } from "copy/src/constant/event";
55
import type { CIRequestType } from "@/bridge/content-inject/request";
66
import { CI_EXECUTION_ENUM, CONTENT_TO_INJECT_REQUEST } from "@/bridge/content-inject/request";
7+
import { CIBridge } from "@/bridge/content-inject";
8+
import { EventBus, EVENTS_ENUM } from "../utils/bus";
9+
import { stopNativePropagation } from "../utils/events";
710

811
export const onContentMessage = (handler: WebSite) => {
912
return (data: CIRequestType) => {
@@ -27,6 +30,24 @@ export const onContentMessage = (handler: WebSite) => {
2730
: handler.close(CONTEXT_MENU_TYPE);
2831
break;
2932
}
33+
case CIBridge.REQUEST.DEBUG_MOUSE_EVENT: {
34+
EventBus.on(EVENTS_ENUM.MOUSE_DOWN_CAPTURE, stopNativePropagation);
35+
EventBus.on(EVENTS_ENUM.MOUSE_UP_CAPTURE, stopNativePropagation);
36+
EventBus.on(EVENTS_ENUM.MOUSE_MOVE_CAPTURE, stopNativePropagation);
37+
EventBus.on(EVENTS_ENUM.TOUCH_START_CAPTURE, stopNativePropagation);
38+
EventBus.on(EVENTS_ENUM.TOUCH_MOVE_CAPTURE, stopNativePropagation);
39+
EventBus.on(EVENTS_ENUM.TOUCH_END_CAPTURE, stopNativePropagation);
40+
break;
41+
}
42+
case CIBridge.REQUEST.DEBUG_FOCUS_EVENT: {
43+
EventBus.on(EVENTS_ENUM.FOCUS_CAPTURE, stopNativePropagation);
44+
EventBus.on(EVENTS_ENUM.BLUR_CAPTURE, stopNativePropagation);
45+
break;
46+
}
47+
case CIBridge.REQUEST.DEBUG_EDITABLE: {
48+
document.body.contentEditable = "true";
49+
break;
50+
}
3051
}
3152
};
3253
};

packages/force-copy/src/inject/modules/qq-ppt.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export const QQPpt: WebSite = {
4848
start(type) {
4949
if (type === COPY_TYPE) {
5050
win.__CAN_COPY = true;
51-
console.dir(win, win.__CAN_COPY);
5251
styles.insertCSS(STYLE_ID, AUTO_USER_SELECT + ALLOW_PAINT);
5352
} else if (type === KEYBOARD_TYPE) {
5453
EventBus.on(EVENTS_ENUM.KEY_BOARD_CAPTURE, stopNativePropagation);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const EVENTS_TYPE = [
1818
"TOUCH_START_CAPTURE",
1919
"FOCUS_CAPTURE",
2020
"BLUR_CAPTURE",
21+
"MOUSE_MOVE_CAPTURE",
22+
"TOUCH_MOVE_CAPTURE",
23+
"TOUCH_END_CAPTURE",
2124
] as const;
2225

2326
export const EVENTS_ENUM = EVENTS_TYPE.reduce(
@@ -30,6 +33,7 @@ interface EventBusParams {
3033
[EVENTS_ENUM.MOUSE_DOWN_CAPTURE]: MouseEvent;
3134
[EVENTS_ENUM.MOUSE_UP_BUBBLE]: MouseEvent;
3235
[EVENTS_ENUM.MOUSE_DOWN_BUBBLE]: MouseEvent;
36+
[EVENTS_ENUM.MOUSE_MOVE_CAPTURE]: MouseEvent;
3337
[EVENTS_ENUM.DOM_LOADED]: Event;
3438
[EVENTS_ENUM.PAGE_LOADED]: Event;
3539
[EVENTS_ENUM.OPEN_ACTION]: ALL_ACTION_TYPE;
@@ -42,6 +46,8 @@ interface EventBusParams {
4246
[EVENTS_ENUM.TOUCH_START_CAPTURE]: TouchEvent;
4347
[EVENTS_ENUM.FOCUS_CAPTURE]: FocusEvent;
4448
[EVENTS_ENUM.BLUR_CAPTURE]: FocusEvent;
49+
[EVENTS_ENUM.TOUCH_MOVE_CAPTURE]: TouchEvent;
50+
[EVENTS_ENUM.TOUCH_END_CAPTURE]: TouchEvent;
4551
}
4652

4753
declare module "laser-utils/dist/es/event-bus" {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import {
88
FOCUS_OUT,
99
KEY_DOWN,
1010
MOUSE_DOWN,
11+
MOUSE_MOVE,
1112
MOUSE_UP,
1213
PAGE_LOADED,
1314
SELECT_START,
15+
TOUCH_END,
16+
TOUCH_MOVE,
1417
TOUCH_START,
1518
} from "copy/src/constant/event";
1619
import { EVENTS_ENUM, EventBus } from "./bus";
@@ -43,6 +46,9 @@ export const initBaseEvents = () => {
4346
window.addEventListener(FOCUS_IN, e => EventBus.emit(EVENTS_ENUM.FOCUS_CAPTURE, e), true);
4447
window.addEventListener(BLUR, e => EventBus.emit(EVENTS_ENUM.BLUR_CAPTURE, e), true);
4548
window.addEventListener(FOCUS_OUT, e => EventBus.emit(EVENTS_ENUM.FOCUS_CAPTURE, e), true);
49+
window.addEventListener(MOUSE_MOVE, e => EventBus.emit(EVENTS_ENUM.MOUSE_MOVE_CAPTURE, e), true);
50+
window.addEventListener(TOUCH_MOVE, e => EventBus.emit(EVENTS_ENUM.TOUCH_MOVE_CAPTURE, e), true);
51+
window.addEventListener(TOUCH_END, e => EventBus.emit(EVENTS_ENUM.TOUCH_END_CAPTURE, e), true);
4652
};
4753

4854
export const stopNativePropagation = (event: Event) => event.stopImmediatePropagation();

0 commit comments

Comments
 (0)