Skip to content

Commit 8d9f523

Browse files
authored
Revert "feat(feedback) Allowing annotation via highlighting & masking (#15484)" (#15609)
Screenshots without annotations were not showing up properly (they are being capture as completely transparent). This reverts commit 9c1f79b.
1 parent 44a3507 commit 8d9f523

File tree

13 files changed

+703
-366
lines changed

13 files changed

+703
-366
lines changed

packages/core/src/types-hoist/feedback/config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ export interface FeedbackGeneralConfiguration {
5757
name: string;
5858
};
5959

60+
/**
61+
* _experiments allows users to enable experimental or internal features.
62+
* We don't consider such features as part of the public API and hence we don't guarantee semver for them.
63+
* Experimental features can be added, changed or removed at any time.
64+
*
65+
* Default: undefined
66+
*/
67+
_experiments: Partial<{ annotations: boolean }>;
68+
6069
/**
6170
* Set an object that will be merged sent as tags data with the event.
6271
*/

packages/feedback/src/constants/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export const NAME_PLACEHOLDER = 'Your Name';
2020
export const NAME_LABEL = 'Name';
2121
export const SUCCESS_MESSAGE_TEXT = 'Thank you for your report!';
2222
export const IS_REQUIRED_LABEL = '(required)';
23-
export const ADD_SCREENSHOT_LABEL = 'Capture Screenshot';
24-
export const REMOVE_SCREENSHOT_LABEL = 'Remove Screenshot';
23+
export const ADD_SCREENSHOT_LABEL = 'Add a screenshot';
24+
export const REMOVE_SCREENSHOT_LABEL = 'Remove screenshot';
2525

2626
export const FEEDBACK_WIDGET_SOURCE = 'widget';
2727
export const FEEDBACK_API_SOURCE = 'api';

packages/feedback/src/core/integration.ts

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const buildFeedbackIntegration = ({
8484
email: 'email',
8585
name: 'username',
8686
},
87+
_experiments = {},
8788
tags,
8889
styleNonce,
8990
scriptNonce,
@@ -158,6 +159,8 @@ export const buildFeedbackIntegration = ({
158159
onSubmitError,
159160
onSubmitSuccess,
160161
onFormSubmitted,
162+
163+
_experiments,
161164
};
162165

163166
let _shadow: ShadowRoot | null = null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import type { VNode, h as hType } from 'preact';
2+
import type * as Hooks from 'preact/hooks';
3+
import { DOCUMENT } from '../../constants';
4+
5+
interface FactoryParams {
6+
h: typeof hType;
7+
}
8+
9+
export default function AnnotationsFactory({
10+
h, // eslint-disable-line @typescript-eslint/no-unused-vars
11+
}: FactoryParams) {
12+
return function Annotations({
13+
action,
14+
imageBuffer,
15+
annotatingRef,
16+
}: {
17+
action: 'crop' | 'annotate' | '';
18+
imageBuffer: HTMLCanvasElement;
19+
annotatingRef: Hooks.Ref<HTMLCanvasElement>;
20+
}): VNode {
21+
const onAnnotateStart = (): void => {
22+
if (action !== 'annotate') {
23+
return;
24+
}
25+
26+
const handleMouseMove = (moveEvent: MouseEvent): void => {
27+
const annotateCanvas = annotatingRef.current;
28+
if (annotateCanvas) {
29+
const rect = annotateCanvas.getBoundingClientRect();
30+
const x = moveEvent.clientX - rect.x;
31+
const y = moveEvent.clientY - rect.y;
32+
33+
const ctx = annotateCanvas.getContext('2d');
34+
if (ctx) {
35+
ctx.lineTo(x, y);
36+
ctx.stroke();
37+
ctx.beginPath();
38+
ctx.moveTo(x, y);
39+
}
40+
}
41+
};
42+
43+
const handleMouseUp = (): void => {
44+
const ctx = annotatingRef.current?.getContext('2d');
45+
if (ctx) {
46+
ctx.beginPath();
47+
}
48+
49+
// Add your apply annotation logic here
50+
applyAnnotation();
51+
52+
DOCUMENT.removeEventListener('mousemove', handleMouseMove);
53+
DOCUMENT.removeEventListener('mouseup', handleMouseUp);
54+
};
55+
56+
DOCUMENT.addEventListener('mousemove', handleMouseMove);
57+
DOCUMENT.addEventListener('mouseup', handleMouseUp);
58+
};
59+
60+
const applyAnnotation = (): void => {
61+
// Logic to apply the annotation
62+
const imageCtx = imageBuffer.getContext('2d');
63+
const annotateCanvas = annotatingRef.current;
64+
if (imageCtx && annotateCanvas) {
65+
imageCtx.drawImage(
66+
annotateCanvas,
67+
0,
68+
0,
69+
annotateCanvas.width,
70+
annotateCanvas.height,
71+
0,
72+
0,
73+
imageBuffer.width,
74+
imageBuffer.height,
75+
);
76+
77+
const annotateCtx = annotateCanvas.getContext('2d');
78+
if (annotateCtx) {
79+
annotateCtx.clearRect(0, 0, annotateCanvas.width, annotateCanvas.height);
80+
}
81+
}
82+
};
83+
return (
84+
<canvas
85+
class={`editor__annotation ${action === 'annotate' ? 'editor__annotation--active' : ''}`}
86+
onMouseDown={onAnnotateStart}
87+
ref={annotatingRef}
88+
></canvas>
89+
);
90+
};
91+
}

0 commit comments

Comments
 (0)