Skip to content

Commit 51f493d

Browse files
committed
feat: force copy onpaste event
1 parent 9ab59bf commit 51f493d

File tree

9 files changed

+43
-18
lines changed

9 files changed

+43
-18
lines changed

packages/copy/src/constant/event.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ export const FOCUS = "focus";
1919
export const BLUR = "blur";
2020
export const FOCUS_IN = "focusin";
2121
export const FOCUS_OUT = "focusout";
22+
export const PASTE = "paste";

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const CI_REQUEST_ENUM = [
88
"DEBUG_MOUSE_EVENT",
99
"DEBUG_FOCUS_EVENT",
1010
"DEBUG_EDITABLE",
11+
"DEBUG_PASTE",
1112
] as const;
13+
1214
export const CONTENT_TO_INJECT_REQUEST = CI_REQUEST_ENUM.reduce(
1315
(acc, cur) => ({ ...acc, [cur]: `__${cur}__${MARK}__` }),
1416
{} as { [K in typeof CI_REQUEST_ENUM[number]]: `__${K}__${typeof MARK}__` }
@@ -28,6 +30,7 @@ export type EventMap = {
2830
[CONTENT_TO_INJECT_REQUEST.DEBUG_MOUSE_EVENT]: null;
2931
[CONTENT_TO_INJECT_REQUEST.DEBUG_FOCUS_EVENT]: null;
3032
[CONTENT_TO_INJECT_REQUEST.DEBUG_EDITABLE]: null;
33+
[CONTENT_TO_INJECT_REQUEST.DEBUG_PASTE]: null;
3134
};
3235

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const PC_REQUEST_TYPE = [
99
"DEBUG_MOUSE_EVENT",
1010
"DEBUG_FOCUS_EVENT",
1111
"DEBUG_EDITABLE",
12+
"DEBUG_PASTE_EVENT",
1213
] as const;
14+
1315
export const POPUP_TO_CONTENT_REQUEST = PC_REQUEST_TYPE.reduce(
1416
(acc, cur) => ({ ...acc, [cur]: `__${cur}__${MARK}__` }),
1517
{} as { [K in typeof PC_REQUEST_TYPE[number]]: `__${K}__${typeof MARK}__` }
@@ -23,6 +25,7 @@ type EventMap = {
2325
[POPUP_TO_CONTENT_REQUEST.DEBUG_MOUSE_EVENT]: null;
2426
[POPUP_TO_CONTENT_REQUEST.DEBUG_FOCUS_EVENT]: null;
2527
[POPUP_TO_CONTENT_REQUEST.DEBUG_EDITABLE]: null;
28+
[POPUP_TO_CONTENT_REQUEST.DEBUG_PASTE_EVENT]: null;
2629
};
2730

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

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,12 @@ export const onPopupMessage = (data: PCRequestType) => {
8484
});
8585
break;
8686
}
87+
case PCBridge.REQUEST.DEBUG_PASTE_EVENT: {
88+
CIBridge.postToInject({
89+
type: CIBridge.REQUEST.DEBUG_PASTE,
90+
payload: null,
91+
});
92+
break;
93+
}
8794
}
8895
};

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export const onContentMessage = (handler: WebSite) => {
4848
document.body.contentEditable = "true";
4949
break;
5050
}
51+
case CIBridge.REQUEST.DEBUG_PASTE: {
52+
EventBus.on(EVENTS_ENUM.PASTE_CAPTURE, stopNativePropagation);
53+
break;
54+
}
5155
}
5256
};
5357
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const EVENTS_TYPE = [
2121
"MOUSE_MOVE_CAPTURE",
2222
"TOUCH_MOVE_CAPTURE",
2323
"TOUCH_END_CAPTURE",
24+
"PASTE_CAPTURE",
2425
] as const;
2526

2627
export const EVENTS_ENUM = EVENTS_TYPE.reduce(
@@ -48,6 +49,7 @@ interface EventBusParams {
4849
[EVENTS_ENUM.BLUR_CAPTURE]: FocusEvent;
4950
[EVENTS_ENUM.TOUCH_MOVE_CAPTURE]: TouchEvent;
5051
[EVENTS_ENUM.TOUCH_END_CAPTURE]: TouchEvent;
52+
[EVENTS_ENUM.PASTE_CAPTURE]: ClipboardEvent;
5153
}
5254

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

packages/force-copy/src/popup/components/tools/index.module.scss

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,4 @@ $box-shadow: 0 0 4px var(--color-border-2);
88
border-radius: 4px;
99
box-shadow: $box-shadow;
1010

11-
.row {
12-
margin-bottom: 5px;
13-
&:last-child {
14-
margin-bottom: auto;
15-
}
16-
}
1711
}

packages/force-copy/src/popup/components/tools/index.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ import type { FC } from "react";
44
import type { I18n } from "@/popup/i18n";
55
import { PCBridge } from "@/bridge/popup-content";
66

7-
const Row = Grid.Row;
8-
const Col = Grid.Col;
7+
const GridItem = Grid.GridItem;
98

109
export const Tools: FC<{
1110
i18n: I18n;
1211
visible?: boolean;
1312
}> = ({ i18n }) => {
1413
return (
1514
<div className={styles.container}>
16-
<Row className={styles.row} gutter={10}>
17-
<Col span={12}>
15+
<Grid cols={2} colGap={10} rowGap={5}>
16+
<GridItem>
1817
<Button
1918
size="mini"
2019
onClick={() =>
@@ -26,8 +25,8 @@ export const Tools: FC<{
2625
>
2726
{i18n.t("Tools.MouseEvent")}
2827
</Button>
29-
</Col>
30-
<Col span={12}>
28+
</GridItem>
29+
<GridItem>
3130
<Button
3231
onClick={() =>
3332
PCBridge.postToContent({
@@ -39,10 +38,8 @@ export const Tools: FC<{
3938
>
4039
{i18n.t("Tools.FocusEvent")}
4140
</Button>
42-
</Col>
43-
</Row>
44-
<Row className={styles.row}>
45-
<Col span={12}>
41+
</GridItem>
42+
<GridItem>
4643
<Button
4744
onClick={() =>
4845
PCBridge.postToContent({
@@ -54,8 +51,21 @@ export const Tools: FC<{
5451
>
5552
{i18n.t("Tools.Editable")}
5653
</Button>
57-
</Col>
58-
</Row>
54+
</GridItem>
55+
<GridItem>
56+
<Button
57+
onClick={() =>
58+
PCBridge.postToContent({
59+
type: PCBridge.REQUEST.DEBUG_PASTE_EVENT,
60+
payload: null,
61+
})
62+
}
63+
size="mini"
64+
>
65+
{i18n.t("Tools.PasteEvent")}
66+
</Button>
67+
</GridItem>
68+
</Grid>
5969
</div>
6070
);
6171
};

packages/force-copy/src/popup/i18n/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ export const en = {
2020
MouseEvent: "MouseEvent",
2121
FocusEvent: "FocusEvent",
2222
Editable: "Editable",
23+
PasteEvent: "PasteEvent",
2324
},
2425
};

0 commit comments

Comments
 (0)