@lets-events/react 11.8.0 → 12.0.0

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 (87) hide show
  1. package/.eslintrc.json +2 -2
  2. package/.turbo/turbo-build.log +21 -18
  3. package/CHANGELOG.md +12 -0
  4. package/dist/index.d.mts +124 -6
  5. package/dist/index.d.ts +124 -6
  6. package/dist/index.js +1033 -276
  7. package/dist/index.mjs +1027 -276
  8. package/package.json +7 -2
  9. package/src/components/Alert.tsx +303 -303
  10. package/src/components/Avatar.tsx +55 -55
  11. package/src/components/Badge.tsx +125 -125
  12. package/src/components/Box.tsx +3 -3
  13. package/src/components/Button/index.tsx +16 -16
  14. package/src/components/Button/styledComponents.ts +287 -287
  15. package/src/components/ButtonGroup.tsx +484 -484
  16. package/src/components/Calendar/index.tsx +139 -136
  17. package/src/components/Calendar/styledComponents.ts +209 -209
  18. package/src/components/Card.tsx +48 -48
  19. package/src/components/CheckboxGroup.tsx +176 -176
  20. package/src/components/Container.tsx +39 -39
  21. package/src/components/Drawer/index.tsx +55 -55
  22. package/src/components/Drawer/styledComponents.ts +46 -46
  23. package/src/components/Dropdown.tsx +302 -302
  24. package/src/components/Filter.tsx +164 -164
  25. package/src/components/Flex.tsx +118 -118
  26. package/src/components/FormFields/AddressFormFields/CityFormField.tsx +111 -111
  27. package/src/components/FormFields/AddressFormFields/CountryFormField.tsx +33 -33
  28. package/src/components/FormFields/AddressFormFields/PostalCodeFormField.tsx +39 -39
  29. package/src/components/FormFields/AddressFormFields/StateFormField.tsx +32 -32
  30. package/src/components/FormFields/AddressFormFields/index.tsx +141 -141
  31. package/src/components/FormFields/BirthDateFormField.tsx +84 -84
  32. package/src/components/FormFields/CNPJFormField.tsx +87 -87
  33. package/src/components/FormFields/CPFFormField.tsx +78 -78
  34. package/src/components/FormFields/CalendarFormField.tsx +89 -0
  35. package/src/components/FormFields/CheckboxGroupFormField.tsx +91 -91
  36. package/src/components/FormFields/EmailFormField.tsx +27 -27
  37. package/src/components/FormFields/Form.tsx +39 -39
  38. package/src/components/FormFields/IdentityDocumentNumberFormField.tsx +40 -40
  39. package/src/components/FormFields/MultiSelectFormField.tsx +61 -55
  40. package/src/components/FormFields/PhoneFormField.tsx +40 -40
  41. package/src/components/FormFields/RadioGroupFormField.tsx +84 -84
  42. package/src/components/FormFields/RichEditorFormField.tsx +69 -0
  43. package/src/components/FormFields/SelectFormField.tsx +93 -93
  44. package/src/components/FormFields/TextAreaFormField.tsx +57 -48
  45. package/src/components/FormFields/TextFormField.tsx +112 -112
  46. package/src/components/FormFields/TimePickerFormField.tsx +88 -0
  47. package/src/components/FormFields/subComponents/ErrorFormMessage.tsx +36 -36
  48. package/src/components/FormFields/subComponents/FormLabel.tsx +29 -29
  49. package/src/components/FormFields/utils/validation.ts +23 -23
  50. package/src/components/Grid.tsx +137 -137
  51. package/src/components/Icon.tsx +47 -47
  52. package/src/components/MenuDropdown/index.tsx +38 -38
  53. package/src/components/MenuDropdown/styledComponents.ts +31 -31
  54. package/src/components/Modal.tsx +90 -90
  55. package/src/components/MultiSelect.tsx +266 -252
  56. package/src/components/RadioGroup.tsx +210 -210
  57. package/src/components/RichEditor/QuillComponent.tsx +415 -0
  58. package/src/components/RichEditor/RichEditor.tsx +38 -0
  59. package/src/components/RichEditor/index.ts +2 -0
  60. package/src/components/RichEditor/styledComponents.ts +62 -0
  61. package/src/components/Section.tsx +33 -33
  62. package/src/components/Step.tsx +164 -164
  63. package/src/components/Switch.tsx +108 -108
  64. package/src/components/Text.tsx +38 -38
  65. package/src/components/TextField.tsx +372 -365
  66. package/src/components/TextareaField.tsx +128 -128
  67. package/src/components/TimePicker.tsx +301 -298
  68. package/src/components/Toast/components/ToastItem.tsx +41 -41
  69. package/src/components/Toast/components/ToastProvider.tsx +63 -63
  70. package/src/components/Toast/hooks/useToast.ts +12 -12
  71. package/src/components/Toast/index.tsx +5 -5
  72. package/src/components/Toast/styles/index.ts +135 -135
  73. package/src/components/Toast/types/index.ts +46 -46
  74. package/src/components/Tooltip/index.tsx +66 -66
  75. package/src/components/Tooltip/styles.ts +77 -77
  76. package/src/hooks/useCountries.ts +41 -41
  77. package/src/hooks/useImageUpload.ts +139 -0
  78. package/src/hooks/useOnClickOutside.tsx +20 -20
  79. package/src/index.tsx +67 -55
  80. package/src/styles/index.ts +38 -38
  81. package/src/types/typographyValues.ts +178 -178
  82. package/src/utils/getNestedValue.ts +3 -3
  83. package/src/utils/states.ts +29 -29
  84. package/src/utils/uploadService.ts +180 -0
  85. package/tsconfig.json +3 -3
  86. package/tsup.config.ts +38 -0
  87. package/dist/index.css +0 -171
@@ -1,38 +1,38 @@
1
- import {
2
- colors,
3
- fontSizes,
4
- fontWeights,
5
- fonts,
6
- lineHeights,
7
- radii,
8
- space,
9
- } from '@lets-events/tokens'
10
-
11
- import { createStitches, defaultThemeMap } from '@stitches/react'
12
-
13
- export const {
14
- styled,
15
- css,
16
- globalCss,
17
- keyframes,
18
- getCssText,
19
- theme,
20
- createTheme,
21
- config,
22
- } = createStitches({
23
- themeMap: {
24
- ...defaultThemeMap,
25
- height: 'space',
26
- width: 'space',
27
- gap: 'space'
28
- },
29
- theme: {
30
- colors,
31
- fontSizes,
32
- fonts,
33
- fontWeights,
34
- lineHeights,
35
- radii,
36
- space,
37
- },
38
- })
1
+ import {
2
+ colors,
3
+ fontSizes,
4
+ fontWeights,
5
+ fonts,
6
+ lineHeights,
7
+ radii,
8
+ space,
9
+ } from '@lets-events/tokens'
10
+
11
+ import { createStitches, defaultThemeMap } from '@stitches/react'
12
+
13
+ export const {
14
+ styled,
15
+ css,
16
+ globalCss,
17
+ keyframes,
18
+ getCssText,
19
+ theme,
20
+ createTheme,
21
+ config,
22
+ } = createStitches({
23
+ themeMap: {
24
+ ...defaultThemeMap,
25
+ height: 'space',
26
+ width: 'space',
27
+ gap: 'space'
28
+ },
29
+ theme: {
30
+ colors,
31
+ fontSizes,
32
+ fonts,
33
+ fontWeights,
34
+ lineHeights,
35
+ radii,
36
+ space,
37
+ },
38
+ })
@@ -1,179 +1,179 @@
1
- export const typographyValues = {
2
- displayLarge: {
3
- fontSize: '$displayLarge',
4
- lineHeight: '$displayLarge',
5
- letterSpacing: '$displayLarge',
6
-
7
- },
8
- displayMedium: {
9
- fontSize: '$displayMedium',
10
- lineHeight: '$displayMedium',
11
- letterSpacing: '$displayMedium',
12
- },
13
- displaySmall: {
14
- fontSize: '$displaySmall',
15
- lineHeight: '$displaySmall',
16
- letterSpacing: '$displaySmall',
17
- },
18
- headline1: {
19
- fontSize: '$headline1',
20
- lineHeight: '$headline1',
21
- },
22
- headline2: {
23
- fontSize: '$headline2',
24
- lineHeight: '$headline2',
25
- },
26
- headline3: {
27
- fontSize: '$headline3',
28
- lineHeight: '$headline3',
29
- },
30
- headline4: {
31
- fontSize: '$headline4',
32
- lineHeight: '$headline4',
33
- },
34
- headline5: {
35
- fontSize: '$headline5',
36
- lineHeight: '$headline5',
37
- },
38
- headline6: {
39
- fontSize: '$headline6',
40
- lineHeight: '$headline6',
41
- },
42
- headline7: {
43
- fontSize: '$headline7',
44
- lineHeight: '$headline7',
45
- },
46
- headline8: {
47
- fontSize: '$headline8',
48
- lineHeight: '$headline8',
49
- },
50
- bodyXL: {
51
- fontSize: '$bodyXL',
52
- lineHeight: '$bodyXL',
53
- },
54
- bodyL: {
55
- fontSize: '$bodyL',
56
- lineHeight: '$bodyL',
57
- },
58
- bodyM: {
59
- fontSize: '$bodyM',
60
- lineHeight: '$bodyM',
61
- },
62
- bodyS: {
63
- fontSize: '$bodyS',
64
- lineHeight: '$bodyS',
65
- },
66
- bodyXS: {
67
- fontSize: '$bodyXS',
68
- lineHeight: '$bodyXS',
69
- },
70
- bodyXXS: {
71
- fontSize: '$bodyXXS',
72
- lineHeight: '$bodyXXS',
73
- },
74
- badgeLarge: {
75
- fontSize: '$badgeLarge',
76
- lineHeight: '$badgeLarge',
77
- },
78
- badgeMedium: {
79
- fontSize: '$badgeMedium',
80
- lineHeight: '$badgeMedium',
81
- },
82
- badgeSmall: {
83
- fontSize: '$badgeSmall',
84
- lineHeight: '$badgeSmall',
85
- },
86
- badgeExtraSmall: {
87
- fontSize: '$badgeExtraSmall',
88
- lineHeight: '$badgeExtraSmall',
89
- },
90
- tooltip: {
91
- fontSize: '$tooltip',
92
- lineHeight: '$tooltip',
93
- },
94
- popoversRegular: {
95
- fontSize: '$popoversRegular',
96
- lineHeight: '$popoversRegular',
97
- },
98
- captionLarge: {
99
- fontSize: '$captionLarge',
100
- lineHeight: '$captionLarge',
101
- },
102
- captionMedium: {
103
- fontSize: '$captionMedium',
104
- lineHeight: '$captionMedium',
105
- },
106
- captionSmall: {
107
- fontSize: '$captionSmall',
108
- lineHeight: '$captionSmall',
109
- },
110
- buttonLarge: {
111
- fontSize: '$buttonLarge',
112
- lineHeight: '$buttonLarge',
113
- },
114
- buttonMedium: {
115
- fontSize: '$buttonMedium',
116
- lineHeight: '$buttonMedium',
117
- },
118
- buttonSmall: {
119
- fontSize: '$buttonSmall',
120
- lineHeight: '$buttonSmall',
121
- },
122
- buttonExtraSmall: {
123
- fontSize: '$buttonExtraSmall',
124
- lineHeight: '$buttonExtraSmall',
125
- },
126
- labelLarge: {
127
- fontSize: '$labelLarge',
128
- lineHeight: '$labelLarge',
129
- },
130
- labelMedium: {
131
- fontSize: '$labelMedium',
132
- lineHeight: '$labelMedium',
133
- },
134
- labelSmall: {
135
- fontSize: '$labelSmall',
136
- lineHeight: '$labelSmall',
137
- },
138
- labelExtraSmall: {
139
- fontSize: '$labelExtraSmall',
140
- lineHeight: '$labelExtraSmall',
141
- },
142
-
143
- }
144
- export const typographyButtonValues = {
145
- buttonLarge: {
146
- fontSize: '$buttonLarge',
147
- lineHeight: '$buttonLarge',
148
- },
149
- buttonMedium: {
150
- fontSize: '$buttonMedium',
151
- lineHeight: '$buttonMedium',
152
- },
153
- buttonSmall: {
154
- fontSize: '$buttonSmall',
155
- lineHeight: '$buttonSmall',
156
- },
157
- buttonExtraSmall: {
158
- fontSize: '$buttonExtraSmall',
159
- lineHeight: '$buttonExtraSmall',
160
- },
161
- }
162
- export const typographyLabelValues = {
163
- labelLarge: {
164
- fontSize: '$labelLarge',
165
- lineHeight: '$labelLarge',
166
- },
167
- labelMedium: {
168
- fontSize: '$labelMedium',
169
- lineHeight: '$labelMedium',
170
- },
171
- labelSmall: {
172
- fontSize: '$labelSmall',
173
- lineHeight: '$labelSmall',
174
- },
175
- labelExtraSmall: {
176
- fontSize: '$labelExtraSmall',
177
- lineHeight: '$labelExtraSmall',
178
- },
1
+ export const typographyValues = {
2
+ displayLarge: {
3
+ fontSize: '$displayLarge',
4
+ lineHeight: '$displayLarge',
5
+ letterSpacing: '$displayLarge',
6
+
7
+ },
8
+ displayMedium: {
9
+ fontSize: '$displayMedium',
10
+ lineHeight: '$displayMedium',
11
+ letterSpacing: '$displayMedium',
12
+ },
13
+ displaySmall: {
14
+ fontSize: '$displaySmall',
15
+ lineHeight: '$displaySmall',
16
+ letterSpacing: '$displaySmall',
17
+ },
18
+ headline1: {
19
+ fontSize: '$headline1',
20
+ lineHeight: '$headline1',
21
+ },
22
+ headline2: {
23
+ fontSize: '$headline2',
24
+ lineHeight: '$headline2',
25
+ },
26
+ headline3: {
27
+ fontSize: '$headline3',
28
+ lineHeight: '$headline3',
29
+ },
30
+ headline4: {
31
+ fontSize: '$headline4',
32
+ lineHeight: '$headline4',
33
+ },
34
+ headline5: {
35
+ fontSize: '$headline5',
36
+ lineHeight: '$headline5',
37
+ },
38
+ headline6: {
39
+ fontSize: '$headline6',
40
+ lineHeight: '$headline6',
41
+ },
42
+ headline7: {
43
+ fontSize: '$headline7',
44
+ lineHeight: '$headline7',
45
+ },
46
+ headline8: {
47
+ fontSize: '$headline8',
48
+ lineHeight: '$headline8',
49
+ },
50
+ bodyXL: {
51
+ fontSize: '$bodyXL',
52
+ lineHeight: '$bodyXL',
53
+ },
54
+ bodyL: {
55
+ fontSize: '$bodyL',
56
+ lineHeight: '$bodyL',
57
+ },
58
+ bodyM: {
59
+ fontSize: '$bodyM',
60
+ lineHeight: '$bodyM',
61
+ },
62
+ bodyS: {
63
+ fontSize: '$bodyS',
64
+ lineHeight: '$bodyS',
65
+ },
66
+ bodyXS: {
67
+ fontSize: '$bodyXS',
68
+ lineHeight: '$bodyXS',
69
+ },
70
+ bodyXXS: {
71
+ fontSize: '$bodyXXS',
72
+ lineHeight: '$bodyXXS',
73
+ },
74
+ badgeLarge: {
75
+ fontSize: '$badgeLarge',
76
+ lineHeight: '$badgeLarge',
77
+ },
78
+ badgeMedium: {
79
+ fontSize: '$badgeMedium',
80
+ lineHeight: '$badgeMedium',
81
+ },
82
+ badgeSmall: {
83
+ fontSize: '$badgeSmall',
84
+ lineHeight: '$badgeSmall',
85
+ },
86
+ badgeExtraSmall: {
87
+ fontSize: '$badgeExtraSmall',
88
+ lineHeight: '$badgeExtraSmall',
89
+ },
90
+ tooltip: {
91
+ fontSize: '$tooltip',
92
+ lineHeight: '$tooltip',
93
+ },
94
+ popoversRegular: {
95
+ fontSize: '$popoversRegular',
96
+ lineHeight: '$popoversRegular',
97
+ },
98
+ captionLarge: {
99
+ fontSize: '$captionLarge',
100
+ lineHeight: '$captionLarge',
101
+ },
102
+ captionMedium: {
103
+ fontSize: '$captionMedium',
104
+ lineHeight: '$captionMedium',
105
+ },
106
+ captionSmall: {
107
+ fontSize: '$captionSmall',
108
+ lineHeight: '$captionSmall',
109
+ },
110
+ buttonLarge: {
111
+ fontSize: '$buttonLarge',
112
+ lineHeight: '$buttonLarge',
113
+ },
114
+ buttonMedium: {
115
+ fontSize: '$buttonMedium',
116
+ lineHeight: '$buttonMedium',
117
+ },
118
+ buttonSmall: {
119
+ fontSize: '$buttonSmall',
120
+ lineHeight: '$buttonSmall',
121
+ },
122
+ buttonExtraSmall: {
123
+ fontSize: '$buttonExtraSmall',
124
+ lineHeight: '$buttonExtraSmall',
125
+ },
126
+ labelLarge: {
127
+ fontSize: '$labelLarge',
128
+ lineHeight: '$labelLarge',
129
+ },
130
+ labelMedium: {
131
+ fontSize: '$labelMedium',
132
+ lineHeight: '$labelMedium',
133
+ },
134
+ labelSmall: {
135
+ fontSize: '$labelSmall',
136
+ lineHeight: '$labelSmall',
137
+ },
138
+ labelExtraSmall: {
139
+ fontSize: '$labelExtraSmall',
140
+ lineHeight: '$labelExtraSmall',
141
+ },
142
+
143
+ }
144
+ export const typographyButtonValues = {
145
+ buttonLarge: {
146
+ fontSize: '$buttonLarge',
147
+ lineHeight: '$buttonLarge',
148
+ },
149
+ buttonMedium: {
150
+ fontSize: '$buttonMedium',
151
+ lineHeight: '$buttonMedium',
152
+ },
153
+ buttonSmall: {
154
+ fontSize: '$buttonSmall',
155
+ lineHeight: '$buttonSmall',
156
+ },
157
+ buttonExtraSmall: {
158
+ fontSize: '$buttonExtraSmall',
159
+ lineHeight: '$buttonExtraSmall',
160
+ },
161
+ }
162
+ export const typographyLabelValues = {
163
+ labelLarge: {
164
+ fontSize: '$labelLarge',
165
+ lineHeight: '$labelLarge',
166
+ },
167
+ labelMedium: {
168
+ fontSize: '$labelMedium',
169
+ lineHeight: '$labelMedium',
170
+ },
171
+ labelSmall: {
172
+ fontSize: '$labelSmall',
173
+ lineHeight: '$labelSmall',
174
+ },
175
+ labelExtraSmall: {
176
+ fontSize: '$labelExtraSmall',
177
+ lineHeight: '$labelExtraSmall',
178
+ },
179
179
  }
@@ -1,3 +1,3 @@
1
- export function getNestedValue(obj: any, path: string): any {
2
- return path.split(".").reduce((acc, key) => acc?.[key], obj);
3
- }
1
+ export function getNestedValue(obj: any, path: string): any {
2
+ return path.split(".").reduce((acc, key) => acc?.[key], obj);
3
+ }
@@ -1,29 +1,29 @@
1
- export const brazilianStates = [
2
- { value: "AC", label: "Acre" },
3
- { value: "AL", label: "Alagoas" },
4
- { value: "AP", label: "Amapá" },
5
- { value: "AM", label: "Amazonas" },
6
- { value: "BA", label: "Bahia" },
7
- { value: "CE", label: "Ceará" },
8
- { value: "DF", label: "Distrito Federal" },
9
- { value: "ES", label: "Espírito Santo" },
10
- { value: "GO", label: "Goiás" },
11
- { value: "MA", label: "Maranhão" },
12
- { value: "MT", label: "Mato Grosso" },
13
- { value: "MS", label: "Mato Grosso do Sul" },
14
- { value: "MG", label: "Minas Gerais" },
15
- { value: "PA", label: "Pará" },
16
- { value: "PB", label: "Paraíba" },
17
- { value: "PR", label: "Paraná" },
18
- { value: "PE", label: "Pernambuco" },
19
- { value: "PI", label: "Piauí" },
20
- { value: "RJ", label: "Rio de Janeiro" },
21
- { value: "RN", label: "Rio Grande do Norte" },
22
- { value: "RS", label: "Rio Grande do Sul" },
23
- { value: "RO", label: "Rondônia" },
24
- { value: "RR", label: "Roraima" },
25
- { value: "SC", label: "Santa Catarina" },
26
- { value: "SP", label: "São Paulo" },
27
- { value: "SE", label: "Sergipe" },
28
- { value: "TO", label: "Tocantins" },
29
- ];
1
+ export const brazilianStates = [
2
+ { value: "AC", label: "Acre" },
3
+ { value: "AL", label: "Alagoas" },
4
+ { value: "AP", label: "Amapá" },
5
+ { value: "AM", label: "Amazonas" },
6
+ { value: "BA", label: "Bahia" },
7
+ { value: "CE", label: "Ceará" },
8
+ { value: "DF", label: "Distrito Federal" },
9
+ { value: "ES", label: "Espírito Santo" },
10
+ { value: "GO", label: "Goiás" },
11
+ { value: "MA", label: "Maranhão" },
12
+ { value: "MT", label: "Mato Grosso" },
13
+ { value: "MS", label: "Mato Grosso do Sul" },
14
+ { value: "MG", label: "Minas Gerais" },
15
+ { value: "PA", label: "Pará" },
16
+ { value: "PB", label: "Paraíba" },
17
+ { value: "PR", label: "Paraná" },
18
+ { value: "PE", label: "Pernambuco" },
19
+ { value: "PI", label: "Piauí" },
20
+ { value: "RJ", label: "Rio de Janeiro" },
21
+ { value: "RN", label: "Rio Grande do Norte" },
22
+ { value: "RS", label: "Rio Grande do Sul" },
23
+ { value: "RO", label: "Rondônia" },
24
+ { value: "RR", label: "Roraima" },
25
+ { value: "SC", label: "Santa Catarina" },
26
+ { value: "SP", label: "São Paulo" },
27
+ { value: "SE", label: "Sergipe" },
28
+ { value: "TO", label: "Tocantins" },
29
+ ];
@@ -0,0 +1,180 @@
1
+ export interface UploadConfig {
2
+ apiUrl: string;
3
+ s3Bucket: string;
4
+ s3Region: string;
5
+ s3Url: string;
6
+ timeout?: number;
7
+ maxFileSize?: number;
8
+ endpoints?: {
9
+ presignedUrl: string;
10
+ upload: string;
11
+ };
12
+ }
13
+
14
+ interface UploadResponse {
15
+ url: string;
16
+ filename: string;
17
+ size: number;
18
+ type: string;
19
+ }
20
+
21
+ interface UploadProgress {
22
+ amount: number;
23
+ message: string;
24
+ }
25
+ const generateUniqueFilename = (originalName: string): string => {
26
+ const timestamp = Date.now().toString(36);
27
+ const random = Math.random().toString(36).substring(2, 8);
28
+ const extension = originalName.split(".").pop();
29
+
30
+ return `${timestamp}_${random}.${extension}`;
31
+ };
32
+
33
+ export class UploadService {
34
+ static async getPresignedUrl(
35
+ filename: string,
36
+ contentType: string,
37
+ config: UploadConfig
38
+ ): Promise<string> {
39
+ const apiUrl = config.apiUrl;
40
+ const presignedUrlEndpoint = config.endpoints?.presignedUrl;
41
+ const bucket = config.s3Bucket;
42
+
43
+ try {
44
+ const response = await fetch(`${apiUrl}${presignedUrlEndpoint}`, {
45
+ method: "POST",
46
+ headers: {
47
+ "Content-Type": "application/json",
48
+ },
49
+ body: JSON.stringify({
50
+ filename,
51
+ contentType,
52
+ bucket,
53
+ }),
54
+ });
55
+
56
+ if (!response.ok) {
57
+ throw new Error("Falha ao gerar URL de upload");
58
+ }
59
+
60
+ const data = await response.json();
61
+ return data.presignedUrl;
62
+ } catch (error) {
63
+ console.error("Erro ao gerar URL pré-assinada:", error);
64
+ throw new Error("Falha ao gerar URL de upload");
65
+ }
66
+ }
67
+
68
+ static async uploadToS3(
69
+ file: File,
70
+ config: UploadConfig,
71
+ onProgress?: (progress: UploadProgress) => void
72
+ ): Promise<UploadResponse> {
73
+ try {
74
+ const uniqueFilename = generateUniqueFilename(file.name);
75
+ const blob = new Blob([file], { type: file.type });
76
+
77
+ const s3Url = `${config.s3Url}/${uniqueFilename}`;
78
+
79
+ return new Promise((resolve, reject) => {
80
+ const xhr = new XMLHttpRequest();
81
+
82
+ xhr.upload.addEventListener("progress", (event) => {
83
+ if (event.lengthComputable) {
84
+ const percentComplete = Math.round(
85
+ (event.loaded / event.total) * 100
86
+ );
87
+ onProgress?.({
88
+ amount: percentComplete,
89
+ message: `Fazendo upload... ${percentComplete}%`,
90
+ });
91
+ }
92
+ });
93
+
94
+ xhr.addEventListener("load", () => {
95
+ if (xhr.status === 200) {
96
+ resolve({
97
+ url: s3Url,
98
+ filename: uniqueFilename,
99
+ size: file.size,
100
+ type: file.type,
101
+ });
102
+ } else {
103
+ reject(new Error(`Upload falhou com status: ${xhr.status}`));
104
+ }
105
+ });
106
+
107
+ xhr.addEventListener("error", () => {
108
+ reject(new Error("Erro de rede durante upload"));
109
+ });
110
+
111
+ xhr.open("PUT", s3Url);
112
+ xhr.setRequestHeader("Content-Type", file.type);
113
+ xhr.send(blob);
114
+ });
115
+ } catch (error) {
116
+ console.error("Erro no upload:", error);
117
+ throw error;
118
+ }
119
+ }
120
+
121
+ static async uploadViaAPI(
122
+ file: File,
123
+ config: UploadConfig,
124
+ onProgress?: (progress: UploadProgress) => void
125
+ ): Promise<UploadResponse> {
126
+ try {
127
+ const formData = new FormData();
128
+ formData.append("file", file);
129
+ const bucket = config.s3Bucket;
130
+ formData.append("bucket", bucket);
131
+
132
+ const xhr = new XMLHttpRequest();
133
+
134
+ return new Promise((resolve, reject) => {
135
+ xhr.upload.addEventListener("progress", (event) => {
136
+ if (event.lengthComputable) {
137
+ const percentComplete = Math.round(
138
+ (event.loaded / event.total) * 100
139
+ );
140
+ onProgress?.({
141
+ amount: percentComplete,
142
+ message: `Fazendo upload... ${percentComplete}%`,
143
+ });
144
+ }
145
+ });
146
+
147
+ xhr.addEventListener("load", () => {
148
+ if (xhr.status === 200) {
149
+ try {
150
+ const response = JSON.parse(xhr.responseText);
151
+ resolve({
152
+ url: response.url,
153
+ filename: response.filename,
154
+ size: file.size,
155
+ type: file.type,
156
+ });
157
+ } catch (error) {
158
+ reject(new Error("Resposta inválida do servidor"));
159
+ }
160
+ } else {
161
+ reject(new Error(`Upload falhou com status: ${xhr.status}`));
162
+ }
163
+ });
164
+
165
+ xhr.addEventListener("error", () => {
166
+ reject(new Error("Erro de rede durante upload"));
167
+ });
168
+
169
+ const apiUrl = config.apiUrl;
170
+ const uploadEndpoint = config.endpoints?.upload;
171
+
172
+ xhr.open("POST", `${apiUrl}${uploadEndpoint}`);
173
+ xhr.send(formData);
174
+ });
175
+ } catch (error) {
176
+ console.error("Erro no upload via API:", error);
177
+ throw error;
178
+ }
179
+ }
180
+ }
package/tsconfig.json CHANGED
@@ -1,4 +1,4 @@
1
- {
2
- "extends": "@lets-events/ts-config/react.json",
3
- "include": ["src"]
1
+ {
2
+ "extends": "@lets-events/ts-config/react.json",
3
+ "include": ["src"]
4
4
  }