hocmai-feedback-widget 0.1.14 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +42 -32
  2. package/dist/components/FeedbackWidget.d.ts +2 -1
  3. package/dist/context/FeedbackContext.d.ts +1 -1
  4. package/dist/index.d.ts +2 -0
  5. package/dist/support-feedback-lib.es.js +2155 -1247
  6. package/dist/support-feedback-lib.umd.js +23 -3
  7. package/dist/test-mobile-screenshot.html +211 -0
  8. package/dist/test-simple-capture.html +107 -0
  9. package/dist/utils/screenshot/background-renderer.d.ts +3 -0
  10. package/dist/utils/screenshot/canvas-renderer.d.ts +9 -0
  11. package/dist/utils/screenshot/cleanup.d.ts +3 -0
  12. package/dist/utils/screenshot/device-detection.d.ts +16 -0
  13. package/dist/utils/screenshot/element-collector.d.ts +10 -0
  14. package/dist/utils/screenshot/image-renderer.d.ts +21 -0
  15. package/dist/utils/screenshot/performance.d.ts +3 -0
  16. package/dist/utils/screenshot/svg-renderer.d.ts +24 -0
  17. package/dist/utils/screenshot/text-renderer.d.ts +23 -0
  18. package/dist/utils/screenshot/types.d.ts +35 -0
  19. package/dist/utils/screenshot.d.ts +9 -7
  20. package/package.json +6 -3
  21. package/src/App.css +42 -0
  22. package/src/App.tsx +75 -0
  23. package/src/assets/react.svg +1 -0
  24. package/src/components/CropOverlay.tsx +174 -0
  25. package/src/components/FeedbackWidget.tsx +854 -0
  26. package/src/context/FeedbackContext.tsx +66 -0
  27. package/src/index.css +68 -0
  28. package/src/index.ts +7 -0
  29. package/src/main.tsx +10 -0
  30. package/src/utils/device.ts +22 -0
  31. package/src/utils/screenshot/background-renderer.ts +54 -0
  32. package/src/utils/screenshot/canvas-renderer.ts +343 -0
  33. package/src/utils/screenshot/cleanup.ts +32 -0
  34. package/src/utils/screenshot/device-detection.ts +90 -0
  35. package/src/utils/screenshot/element-collector.ts +134 -0
  36. package/src/utils/screenshot/image-renderer.ts +148 -0
  37. package/src/utils/screenshot/performance.ts +57 -0
  38. package/src/utils/screenshot/svg-renderer.ts +149 -0
  39. package/src/utils/screenshot/text-renderer.ts +212 -0
  40. package/src/utils/screenshot/types.ts +40 -0
  41. package/src/utils/screenshot.ts +83 -0
package/README.md CHANGED
@@ -5,6 +5,7 @@ A React library for collecting user feedback with screenshot capabilities, conte
5
5
  ## Features
6
6
  - **Context-Aware**: Support for multiple questions/items on a single page.
7
7
  - **Screenshot Capture**: Automatic viewport capture with cropping/highlighting.
8
+ - **Auto-Upload**: Screenshots are automatically uploaded to S3 and returned as URLs.
8
9
  - **Image Protection**: Prevents right-click/download on sensitive screenshots.
9
10
  - **Responsive**: Mobile-friendly "bottom sheet" style on small screens.
10
11
  - **Customizable**: Theme colors, context data, and error types.
@@ -37,13 +38,13 @@ Wrap your root component (or the section of the app that needs feedback) with `F
37
38
  ```tsx
38
39
  import { FeedbackProvider, type FeedbackData } from 'hocmai-feedback-widget';
39
40
  // If styles are not automatically injected by your bundler, you might need:
40
- // import '@antigravity/feedback-widget/dist/style.css';
41
+ // import 'hocmai-feedback-widget/dist/style.css';
41
42
 
42
43
  function App() {
43
44
  const handleSubmit = async (data: FeedbackData) => {
44
45
  // Send data to your API
45
46
  console.log('Feedback submitted:', data);
46
- // data.screenshots contains base64 images
47
+ // data.listImage contains URLs of uploaded images
47
48
  // data.deviceInfo contains browser/OS info
48
49
  // data.errorType contains the selected category
49
50
  };
@@ -69,7 +70,7 @@ const QuestionItem = ({ id, content }) => {
69
70
  <div className="card">
70
71
  <p>{content}</p>
71
72
  <button
72
- onClick={() => openFeedback(id, { source: 'QuestionItem', extra: 'details' })}
73
+ onClick={() => openFeedback(id, { questionIdChild: 'optional-child-id', ...otherContext })}
73
74
  >
74
75
  Report Error
75
76
  </button>
@@ -78,8 +79,8 @@ const QuestionItem = ({ id, content }) => {
78
79
  };
79
80
  ```
80
81
 
81
- ### 3. Standalone Component (Legacy)
82
- If you only need a single widget instance and manage state manually:
82
+ ### 3. Standalone Component
83
+ If you need a single widget instance and manage state manually (legacy mode):
83
84
 
84
85
  ```tsx
85
86
  import { FeedbackWidget } from 'hocmai-feedback-widget';
@@ -89,6 +90,8 @@ import { FeedbackWidget } from 'hocmai-feedback-widget';
89
90
  isOpen={isOpen}
90
91
  onClose={() => setIsOpen(false)}
91
92
  onSubmit={handleSubmit}
93
+ isEnableCaptureFull={true}
94
+ isEnableCaptureElement={true}
92
95
  />
93
96
  ```
94
97
 
@@ -101,34 +104,41 @@ import { FeedbackWidget } from 'hocmai-feedback-widget';
101
104
  | `themeColor` | `string` | No | Primary color for buttons/highlights. Default: `#3b82f6`. |
102
105
  | `children` | `ReactNode` | Yes | Your application content. |
103
106
 
104
- ### useFeedback Hook
105
- Returns an object with:
106
- - `openFeedback(questionId: string | number, questionIdChild?: string | number, contextData?: any)`: Opens the form with the specified ID.
107
-
108
- ### Close Feedback Hook
109
- Returns an object with:
110
- - `closeFeedback()`: Closes the form.
111
-
112
- ### 4. Using with JavaScript (No TypeScript)
113
- This library is fully compatible with standard JavaScript projects. The usage is identical, just without type annotations.
114
-
115
- ```jsx
116
- import { FeedbackProvider, useFeedback } from 'hocmai-feedback-widget';
117
-
118
- function App() {
119
- const handleSubmit = async (data) => {
120
- console.log('Feedback submitted:', data);
121
- };
122
-
123
- return (
124
- <FeedbackProvider onSubmit={handleSubmit}>
125
- <YourAppContent />
126
- </FeedbackProvider>
127
- );
107
+ ### FeedbackData Interface
108
+ ```ts
109
+ interface FeedbackData {
110
+ idQuestion: string | number;
111
+ idChildQuestion?: string | number;
112
+ errorDescription: string;
113
+ errorType: string;
114
+ listImage: string[]; // Array of image URLs
115
+ deviceInfo: {
116
+ device: string;
117
+ os: string;
118
+ browser: string;
119
+ screen: string;
120
+ userAgent: string;
121
+ };
122
+ contextData?: any;
128
123
  }
129
124
  ```
130
125
 
131
- **Note**: You won't get autocomplete for props, but the functionality remains the same.
126
+ ### useFeedback Hook
127
+ Returns an object with:
128
+ - `openFeedback(questionId: string | number, contextData?: any)`: Opens the form. `contextData` can include `questionIdChild` which will pre-fill the child question ID field.
129
+ - `closeFeedback()`: Closes the form.
132
130
 
133
- **Note**: You need to refer to and combine the documentation link below to prepare the question report.
134
- url: https://gist.github.com/haiduy/fe2b016af8f0c9d268d791b130dc64d2
131
+ ### FeedbackWidget Props
132
+ | Prop | Type | Default | Description |
133
+ |------|------|---------|-------------|
134
+ | `questionId` | `string \| number` | Required | Main ID of the item being reported. |
135
+ | `onSubmit` | `function` | Required | Async callback receiving `FeedbackData`. |
136
+ | `contextData` | `object` | - | Additional data passed to `FeedbackData`. |
137
+ | `themeColor` | `string` | `#3b82f6` | Theme color. |
138
+ | `isOpen` | `boolean` | - | Control visibility manually. |
139
+ | `onClose` | `function` | - | Callback when closed. |
140
+ | `isEnableCaptureFull` | `boolean` | `true` | Enable full screen capture button. |
141
+ | `isEnableCaptureElement` | `boolean` | `true` | Enable crop/element capture button. |
142
+
143
+ ## License
144
+ MIT
@@ -11,7 +11,6 @@ export interface FeedbackData {
11
11
  }
12
12
  export interface FeedbackProps {
13
13
  questionId: string | number;
14
- questionIdChild?: string | number;
15
14
  contextData?: Record<string, any>;
16
15
  onSubmit: (data: FeedbackData) => Promise<void>;
17
16
  themeColor?: string;
@@ -19,6 +18,8 @@ export interface FeedbackProps {
19
18
  isOpen?: boolean;
20
19
  onOpen?: () => void;
21
20
  onClose?: () => void;
21
+ isEnableCaptureFull?: boolean;
22
+ isEnableCaptureElement?: boolean;
22
23
  }
23
24
  declare const FeedbackWidget: React.FC<FeedbackProps>;
24
25
  export default FeedbackWidget;
@@ -1,7 +1,7 @@
1
1
  import { default as React, ReactNode } from 'react';
2
2
  import { FeedbackData } from '../components/FeedbackWidget';
3
3
  interface FeedbackContextType {
4
- openFeedback: (questionId: string | number, questionIdChild?: string | number | undefined, contextData?: any) => void;
4
+ openFeedback: (questionId: string | number, contextData?: any) => void;
5
5
  closeFeedback: () => void;
6
6
  isOpen: boolean;
7
7
  activeQuestionId: string | number | null;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export { default as FeedbackWidget } from './components/FeedbackWidget';
2
2
  export type { FeedbackData, FeedbackProps } from './components/FeedbackWidget';
3
3
  export { FeedbackProvider, useFeedback } from './context/FeedbackContext';
4
+ export { captureScreenshot } from './utils/screenshot';
5
+ export type { Rect, CaptureProgress } from './utils/screenshot/types';