@azure/communication-react 1.18.0-alpha-202407180014 → 1.18.0-alpha-202407200014
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.
- package/dist/communication-react.d.ts +71 -18
- package/dist/dist-cjs/communication-react/{ChatMessageComponentAsRichTextEditBox-Bi4Or6hk.js → ChatMessageComponentAsRichTextEditBox-D4ctXnw1.js} +27 -6
- package/dist/dist-cjs/communication-react/ChatMessageComponentAsRichTextEditBox-D4ctXnw1.js.map +1 -0
- package/dist/dist-cjs/communication-react/{RichTextSendBoxWrapper-CaXswhPn.js → RichTextSendBoxWrapper-F6eqVXer.js} +2 -2
- package/dist/dist-cjs/communication-react/{RichTextSendBoxWrapper-CaXswhPn.js.map → RichTextSendBoxWrapper-F6eqVXer.js.map} +1 -1
- package/dist/dist-cjs/communication-react/{index-B3X0l4SB.js → index-BJO_NOTU.js} +658 -367
- package/dist/dist-cjs/communication-react/index-BJO_NOTU.js.map +1 -0
- package/dist/dist-cjs/communication-react/index.js +1 -1
- package/dist/dist-esm/acs-ui-common/src/telemetryVersion.js +1 -1
- package/dist/dist-esm/acs-ui-common/src/telemetryVersion.js.map +1 -1
- package/dist/dist-esm/calling-stateful-client/src/CallAgentDeclarative.d.ts +3 -3
- package/dist/dist-esm/calling-stateful-client/src/CallAgentDeclarative.js.map +1 -1
- package/dist/dist-esm/calling-stateful-client/src/CallAgentDeclarativeCommon.d.ts +1 -1
- package/dist/dist-esm/calling-stateful-client/src/CallAgentDeclarativeCommon.js +15 -7
- package/dist/dist-esm/calling-stateful-client/src/CallAgentDeclarativeCommon.js.map +1 -1
- package/dist/dist-esm/calling-stateful-client/src/IncomingCallDeclarative.d.ts +2 -8
- package/dist/dist-esm/calling-stateful-client/src/IncomingCallDeclarative.js.map +1 -1
- package/dist/dist-esm/calling-stateful-client/src/TeamsCallAgentDeclarative.d.ts +14 -2
- package/dist/dist-esm/calling-stateful-client/src/TeamsCallAgentDeclarative.js.map +1 -1
- package/dist/dist-esm/calling-stateful-client/src/TeamsIncomingCallDeclarative.d.ts +17 -0
- package/dist/dist-esm/calling-stateful-client/src/TeamsIncomingCallDeclarative.js +49 -0
- package/dist/dist-esm/calling-stateful-client/src/TeamsIncomingCallDeclarative.js.map +1 -0
- package/dist/dist-esm/calling-stateful-client/src/TypeGuards.d.ts +9 -1
- package/dist/dist-esm/calling-stateful-client/src/TypeGuards.js +16 -0
- package/dist/dist-esm/calling-stateful-client/src/TypeGuards.js.map +1 -1
- package/dist/dist-esm/calling-stateful-client/src/index-public.d.ts +1 -1
- package/dist/dist-esm/calling-stateful-client/src/index-public.js.map +1 -1
- package/dist/dist-esm/communication-react/src/index.d.ts +1 -1
- package/dist/dist-esm/communication-react/src/index.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/Attachment/AttachmentCard.js +14 -8
- package/dist/dist-esm/react-components/src/components/Attachment/AttachmentCard.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/ChatMessage/ChatMessageComponentWrapper.d.ts +8 -2
- package/dist/dist-esm/react-components/src/components/ChatMessage/ChatMessageComponentWrapper.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/ChatMessage/MyMessageComponents/ChatMessageComponentAsEditBoxPicker.d.ts +6 -4
- package/dist/dist-esm/react-components/src/components/ChatMessage/MyMessageComponents/ChatMessageComponentAsEditBoxPicker.js +2 -12
- package/dist/dist-esm/react-components/src/components/ChatMessage/MyMessageComponents/ChatMessageComponentAsEditBoxPicker.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/ChatMessage/MyMessageComponents/ChatMessageComponentAsRichTextEditBox.d.ts +2 -2
- package/dist/dist-esm/react-components/src/components/ChatMessage/MyMessageComponents/ChatMessageComponentAsRichTextEditBox.js +25 -4
- package/dist/dist-esm/react-components/src/components/ChatMessage/MyMessageComponents/ChatMessageComponentAsRichTextEditBox.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/ChatMessage/MyMessageComponents/ChatMyMessageComponent.d.ts +8 -6
- package/dist/dist-esm/react-components/src/components/ChatMessage/MyMessageComponents/ChatMyMessageComponent.js +12 -3
- package/dist/dist-esm/react-components/src/components/ChatMessage/MyMessageComponents/ChatMyMessageComponent.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/ChatMessage/MyMessageComponents/FluentChatMyMessageComponent.js +27 -3
- package/dist/dist-esm/react-components/src/components/ChatMessage/MyMessageComponents/FluentChatMyMessageComponent.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/MessageThread.d.ts +9 -15
- package/dist/dist-esm/react-components/src/components/MessageThread.js +10 -1
- package/dist/dist-esm/react-components/src/components/MessageThread.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/RichTextEditor/RichTextEditor.js +28 -22
- package/dist/dist-esm/react-components/src/components/RichTextEditor/RichTextEditor.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/RichTextEditor/RichTextSendBox.d.ts +49 -0
- package/dist/dist-esm/react-components/src/components/RichTextEditor/RichTextSendBox.js +16 -4
- package/dist/dist-esm/react-components/src/components/RichTextEditor/RichTextSendBox.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/RichTextEditor/Toolbar/RichTextToolbar.js +20 -2
- package/dist/dist-esm/react-components/src/components/RichTextEditor/Toolbar/RichTextToolbar.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/index.d.ts +2 -1
- package/dist/dist-esm/react-components/src/components/index.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/styles/AttachmentCard.styles.d.ts +2 -2
- package/dist/dist-esm/react-components/src/components/styles/AttachmentCard.styles.js +15 -17
- package/dist/dist-esm/react-components/src/components/styles/AttachmentCard.styles.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/styles/RichTextEditor.styles.js +3 -0
- package/dist/dist-esm/react-components/src/components/styles/RichTextEditor.styles.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/utils/RichTextEditorUtils.d.ts +1 -5
- package/dist/dist-esm/react-components/src/components/utils/RichTextEditorUtils.js +0 -21
- package/dist/dist-esm/react-components/src/components/utils/RichTextEditorUtils.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/utils/SendBoxUtils.d.ts +9 -1
- package/dist/dist-esm/react-components/src/components/utils/SendBoxUtils.js +10 -2
- package/dist/dist-esm/react-components/src/components/utils/SendBoxUtils.js.map +1 -1
- package/dist/dist-esm/react-components/src/localization/locales/ar-SA/strings.json +101 -63
- package/dist/dist-esm/react-components/src/localization/locales/cs-CZ/strings.json +99 -61
- package/dist/dist-esm/react-components/src/localization/locales/de-DE/strings.json +99 -61
- package/dist/dist-esm/react-components/src/localization/locales/en-GB/strings.json +99 -61
- package/dist/dist-esm/react-components/src/localization/locales/en-US/strings.json +8 -2
- package/dist/dist-esm/react-components/src/localization/locales/es-ES/strings.json +99 -61
- package/dist/dist-esm/react-components/src/localization/locales/fi-FI/strings.json +99 -61
- package/dist/dist-esm/react-components/src/localization/locales/fr-FR/strings.json +102 -64
- package/dist/dist-esm/react-components/src/localization/locales/he-IL/strings.json +99 -61
- package/dist/dist-esm/react-components/src/localization/locales/it-IT/strings.json +99 -61
- package/dist/dist-esm/react-components/src/localization/locales/ja-JP/strings.json +101 -63
- package/dist/dist-esm/react-components/src/localization/locales/ko-KR/strings.json +106 -68
- package/dist/dist-esm/react-components/src/localization/locales/nb-NO/strings.json +99 -61
- package/dist/dist-esm/react-components/src/localization/locales/nl-NL/strings.json +105 -67
- package/dist/dist-esm/react-components/src/localization/locales/pl-PL/strings.json +104 -66
- package/dist/dist-esm/react-components/src/localization/locales/pt-BR/strings.json +102 -64
- package/dist/dist-esm/react-components/src/localization/locales/ru-RU/strings.json +100 -62
- package/dist/dist-esm/react-components/src/localization/locales/sv-SE/strings.json +99 -61
- package/dist/dist-esm/react-components/src/localization/locales/tr-TR/strings.json +100 -62
- package/dist/dist-esm/react-components/src/localization/locales/zh-CN/strings.json +101 -63
- package/dist/dist-esm/react-components/src/localization/locales/zh-TW/strings.json +100 -62
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ChatScreen.js +66 -31
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ChatScreen.js.map +1 -1
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/ImageUploadReducer.d.ts +49 -0
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/ImageUploadReducer.js +48 -0
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/ImageUploadReducer.js.map +1 -0
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/ImageUploadUtils.d.ts +33 -1
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/ImageUploadUtils.js +198 -6
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/ImageUploadUtils.js.map +1 -1
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/file-sharing/AttachmentUpload.d.ts +7 -7
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/file-sharing/AttachmentUpload.js.map +1 -1
- package/dist/dist-esm/react-composites/src/composites/common/SendBoxPicker.d.ts +2 -5
- package/dist/dist-esm/react-composites/src/composites/common/SendBoxPicker.js.map +1 -1
- package/dist/dist-esm/react-composites/src/composites/common/constants.d.ts +4 -0
- package/dist/dist-esm/react-composites/src/composites/common/constants.js +4 -0
- package/dist/dist-esm/react-composites/src/composites/common/constants.js.map +1 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/ar-SA/strings.json +10 -5
- package/dist/dist-esm/react-composites/src/composites/localization/locales/cs-CZ/strings.json +6 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/de-DE/strings.json +6 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/en-GB/strings.json +6 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/es-ES/strings.json +6 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/fi-FI/strings.json +10 -5
- package/dist/dist-esm/react-composites/src/composites/localization/locales/fr-FR/strings.json +10 -5
- package/dist/dist-esm/react-composites/src/composites/localization/locales/he-IL/strings.json +10 -5
- package/dist/dist-esm/react-composites/src/composites/localization/locales/it-IT/strings.json +10 -5
- package/dist/dist-esm/react-composites/src/composites/localization/locales/ja-JP/strings.json +6 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/ko-KR/strings.json +10 -5
- package/dist/dist-esm/react-composites/src/composites/localization/locales/nb-NO/strings.json +6 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/nl-NL/strings.json +6 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/pl-PL/strings.json +6 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/pt-BR/strings.json +10 -5
- package/dist/dist-esm/react-composites/src/composites/localization/locales/ru-RU/strings.json +6 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/sv-SE/strings.json +10 -5
- package/dist/dist-esm/react-composites/src/composites/localization/locales/tr-TR/strings.json +6 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/zh-CN/strings.json +10 -5
- package/dist/dist-esm/react-composites/src/composites/localization/locales/zh-TW/strings.json +10 -5
- package/package.json +14 -14
- package/dist/dist-cjs/communication-react/ChatMessageComponentAsRichTextEditBox-Bi4Or6hk.js.map +0 -1
- package/dist/dist-cjs/communication-react/index-B3X0l4SB.js.map +0 -1
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/useImageUpload.d.ts +0 -12
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/useImageUpload.js +0 -115
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/useImageUpload.js.map +0 -1
package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/useImageUpload.d.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { Dispatch } from 'react';
|
2
|
-
import { AttachmentUpload, Actions } from '../file-sharing/AttachmentUpload';
|
3
|
-
/**
|
4
|
-
* @private
|
5
|
-
*/
|
6
|
-
export declare const useImageUpload: () => [
|
7
|
-
AttachmentUpload[],
|
8
|
-
Dispatch<Actions>,
|
9
|
-
onUploadInlineImage: (image: string, fileName: string) => Promise<void>,
|
10
|
-
onCancelInlineImageUploadHandler: (imageId: string) => void
|
11
|
-
];
|
12
|
-
//# sourceMappingURL=useImageUpload.d.ts.map
|
package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/useImageUpload.js
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
2
|
-
// Licensed under the MIT License.
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
10
|
-
});
|
11
|
-
};
|
12
|
-
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
13
|
-
import { useCallback, useReducer } from 'react';
|
14
|
-
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
15
|
-
import { AttachmentUploadActionType, AttachmentUploadReducer } from '../file-sharing/AttachmentUpload';
|
16
|
-
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
17
|
-
import { useAdapter } from '../adapter/ChatAdapterProvider';
|
18
|
-
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
19
|
-
import { nanoid } from 'nanoid';
|
20
|
-
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
21
|
-
import { getInlineImageData } from './ImageUploadUtils';
|
22
|
-
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
23
|
-
/**
|
24
|
-
* @private
|
25
|
-
*/
|
26
|
-
export const useImageUpload = () => {
|
27
|
-
const MAX_INLINE_IMAGE_UPLOAD_SIZE_MB = 20;
|
28
|
-
const adapter = useAdapter();
|
29
|
-
const [inlineImageUploads, handleInlineImageUploadAction] = useReducer(AttachmentUploadReducer, []);
|
30
|
-
const inlineImageUploadHandler = useCallback((uploadTasks) => __awaiter(void 0, void 0, void 0, function* () {
|
31
|
-
var _a, _b, _c, _d, _e;
|
32
|
-
for (const task of uploadTasks) {
|
33
|
-
const uploadTask = task;
|
34
|
-
const image = uploadTask.image;
|
35
|
-
if (!image) {
|
36
|
-
uploadTask.notifyUploadFailed(`Image data for "${(_a = task.metadata) === null || _a === void 0 ? void 0 : _a.name}" is not provided.`);
|
37
|
-
continue;
|
38
|
-
}
|
39
|
-
if (image && image.size > MAX_INLINE_IMAGE_UPLOAD_SIZE_MB * 1024 * 1024) {
|
40
|
-
uploadTask.notifyUploadFailed(`"${(_b = task.metadata) === null || _b === void 0 ? void 0 : _b.name}" is too big. Select a file under ${MAX_INLINE_IMAGE_UPLOAD_SIZE_MB}MB.`);
|
41
|
-
continue;
|
42
|
-
}
|
43
|
-
const SUPPORTED_FILES = ['jpg', 'jpeg', 'png', 'gif', 'heic', 'webp'];
|
44
|
-
const imageExtension = (_d = (_c = task.metadata) === null || _c === void 0 ? void 0 : _c.name.split('.').pop()) !== null && _d !== void 0 ? _d : '';
|
45
|
-
if (!SUPPORTED_FILES.includes(imageExtension)) {
|
46
|
-
uploadTask.notifyUploadFailed(`Uploading ".${imageExtension}" image is not allowed.`);
|
47
|
-
continue;
|
48
|
-
}
|
49
|
-
try {
|
50
|
-
const response = yield adapter.uploadImage(image, (_e = task.metadata) === null || _e === void 0 ? void 0 : _e.name);
|
51
|
-
uploadTask.notifyUploadCompleted(response.id, task.metadata.url || '');
|
52
|
-
}
|
53
|
-
catch (error) {
|
54
|
-
console.error(error);
|
55
|
-
uploadTask.notifyUploadFailed('Unable to upload inline image. Please try again later.');
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}), [adapter]);
|
59
|
-
const onUploadInlineImage = useCallback((image, fileName) => __awaiter(void 0, void 0, void 0, function* () {
|
60
|
-
if (!image) {
|
61
|
-
return;
|
62
|
-
}
|
63
|
-
const imageData = yield getInlineImageData(image);
|
64
|
-
if (!imageData) {
|
65
|
-
return;
|
66
|
-
}
|
67
|
-
const taskId = nanoid();
|
68
|
-
const uploadTask = {
|
69
|
-
image: imageData,
|
70
|
-
taskId,
|
71
|
-
metadata: {
|
72
|
-
id: taskId,
|
73
|
-
name: fileName,
|
74
|
-
url: image,
|
75
|
-
progress: 0
|
76
|
-
},
|
77
|
-
notifyUploadProgressChanged: (value) => {
|
78
|
-
handleInlineImageUploadAction({ type: AttachmentUploadActionType.Progress, taskId, progress: value });
|
79
|
-
},
|
80
|
-
notifyUploadCompleted: (id, url) => {
|
81
|
-
handleInlineImageUploadAction({ type: AttachmentUploadActionType.Completed, taskId, id, url });
|
82
|
-
},
|
83
|
-
notifyUploadFailed: (message) => {
|
84
|
-
handleInlineImageUploadAction({ type: AttachmentUploadActionType.Failed, taskId, message });
|
85
|
-
// remove the failed upload task when error banner is auto dismissed after 10 seconds
|
86
|
-
// so the banner won't be shown again on UI re-rendering.
|
87
|
-
setTimeout(() => {
|
88
|
-
handleInlineImageUploadAction({ type: AttachmentUploadActionType.Remove, id: taskId });
|
89
|
-
}, 10 * 1000);
|
90
|
-
}
|
91
|
-
};
|
92
|
-
const newUploads = [uploadTask];
|
93
|
-
handleInlineImageUploadAction({ type: AttachmentUploadActionType.Set, newUploads });
|
94
|
-
inlineImageUploadHandler(newUploads);
|
95
|
-
}), [inlineImageUploadHandler]);
|
96
|
-
const onCancelInlineImageUploadHandler = useCallback((imageId) => {
|
97
|
-
const imageUpload = inlineImageUploads.find((upload) => upload.metadata.id === imageId);
|
98
|
-
const uploadId = imageUpload === null || imageUpload === void 0 ? void 0 : imageUpload.metadata.id;
|
99
|
-
if (!uploadId) {
|
100
|
-
return;
|
101
|
-
}
|
102
|
-
handleInlineImageUploadAction({ type: AttachmentUploadActionType.Remove, id: uploadId });
|
103
|
-
// TODO: remove local blob
|
104
|
-
if ((imageUpload === null || imageUpload === void 0 ? void 0 : imageUpload.metadata.progress) === 1) {
|
105
|
-
try {
|
106
|
-
adapter.deleteImage(imageId);
|
107
|
-
}
|
108
|
-
catch (error) {
|
109
|
-
console.error(error);
|
110
|
-
}
|
111
|
-
}
|
112
|
-
}, [adapter, inlineImageUploads]);
|
113
|
-
return [inlineImageUploads, handleInlineImageUploadAction, onUploadInlineImage, onCancelInlineImageUploadHandler];
|
114
|
-
};
|
115
|
-
//# sourceMappingURL=useImageUpload.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"useImageUpload.js","sourceRoot":"","sources":["../../../../../../../../react-composites/src/composites/ChatComposite/ImageUpload/useImageUpload.tsx"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;;;;;;;;;AAElC,gEAAgE;AAChE,OAAO,EAAY,WAAW,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1D,gEAAgE;AAChE,OAAO,EAEL,0BAA0B,EAC1B,uBAAuB,EAGxB,MAAM,kCAAkC,CAAC;AAC1C,gEAAgE;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,gEAAgE;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,gEAAgE;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,gEAAgE;AAChE;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAK5B,EAAE;IACF,MAAM,+BAA+B,GAAG,EAAE,CAAC;IAC3C,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,CAAC,kBAAkB,EAAE,6BAA6B,CAAC,GAAG,UAAU,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;IAEpG,MAAM,wBAAwB,GAAG,WAAW,CAC1C,CAAO,WAA+B,EAAiB,EAAE;;QACvD,KAAK,MAAM,IAAI,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AAC;AACpH,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { Dispatch, useCallback, useReducer } from 'react';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport {\n AttachmentUpload,\n AttachmentUploadActionType,\n AttachmentUploadReducer,\n AttachmentUploadTask,\n Actions\n} from '../file-sharing/AttachmentUpload';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { useAdapter } from '../adapter/ChatAdapterProvider';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { nanoid } from 'nanoid';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { getInlineImageData } from './ImageUploadUtils';\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @private\n */\nexport const useImageUpload = (): [\n AttachmentUpload[],\n Dispatch<Actions>,\n onUploadInlineImage: (image: string, fileName: string) => Promise<void>,\n onCancelInlineImageUploadHandler: (imageId: string) => void\n] => {\n const MAX_INLINE_IMAGE_UPLOAD_SIZE_MB = 20;\n const adapter = useAdapter();\n const [inlineImageUploads, handleInlineImageUploadAction] = useReducer(AttachmentUploadReducer, []);\n\n const inlineImageUploadHandler = useCallback(\n async (uploadTasks: AttachmentUpload[]): Promise<void> => {\n for (const task of uploadTasks) {\n const uploadTask = task as AttachmentUploadTask;\n const image: Blob | undefined = uploadTask.image;\n if (!image) {\n uploadTask.notifyUploadFailed(`Image data for \"${task.metadata?.name}\" is not provided.`);\n continue;\n }\n if (image && image.size > MAX_INLINE_IMAGE_UPLOAD_SIZE_MB * 1024 * 1024) {\n uploadTask.notifyUploadFailed(\n `\"${task.metadata?.name}\" is too big. Select a file under ${MAX_INLINE_IMAGE_UPLOAD_SIZE_MB}MB.`\n );\n continue;\n }\n\n const SUPPORTED_FILES: Array<string> = ['jpg', 'jpeg', 'png', 'gif', 'heic', 'webp'];\n const imageExtension = task.metadata?.name.split('.').pop() ?? '';\n if (!SUPPORTED_FILES.includes(imageExtension)) {\n uploadTask.notifyUploadFailed(`Uploading \".${imageExtension}\" image is not allowed.`);\n continue;\n }\n\n try {\n const response = await adapter.uploadImage(image, task.metadata?.name);\n uploadTask.notifyUploadCompleted(response.id, task.metadata.url || '');\n } catch (error) {\n console.error(error);\n uploadTask.notifyUploadFailed('Unable to upload inline image. Please try again later.');\n }\n }\n },\n [adapter]\n );\n\n const onUploadInlineImage = useCallback(\n async (image: string, fileName: string): Promise<void> => {\n if (!image) {\n return;\n }\n const imageData = await getInlineImageData(image);\n if (!imageData) {\n return;\n }\n const taskId = nanoid();\n const uploadTask: AttachmentUpload = {\n image: imageData,\n taskId,\n metadata: {\n id: taskId,\n name: fileName,\n url: image,\n progress: 0\n },\n notifyUploadProgressChanged: (value: number) => {\n handleInlineImageUploadAction({ type: AttachmentUploadActionType.Progress, taskId, progress: value });\n },\n notifyUploadCompleted: (id: string, url: string) => {\n handleInlineImageUploadAction({ type: AttachmentUploadActionType.Completed, taskId, id, url });\n },\n notifyUploadFailed: (message: string) => {\n handleInlineImageUploadAction({ type: AttachmentUploadActionType.Failed, taskId, message });\n // remove the failed upload task when error banner is auto dismissed after 10 seconds\n // so the banner won't be shown again on UI re-rendering.\n setTimeout(() => {\n handleInlineImageUploadAction({ type: AttachmentUploadActionType.Remove, id: taskId });\n }, 10 * 1000);\n }\n };\n\n const newUploads = [uploadTask];\n handleInlineImageUploadAction({ type: AttachmentUploadActionType.Set, newUploads });\n inlineImageUploadHandler(newUploads);\n },\n [inlineImageUploadHandler]\n );\n\n const onCancelInlineImageUploadHandler = useCallback(\n (imageId: string) => {\n const imageUpload = inlineImageUploads.find((upload) => upload.metadata.id === imageId);\n const uploadId = imageUpload?.metadata.id;\n if (!uploadId) {\n return;\n }\n handleInlineImageUploadAction({ type: AttachmentUploadActionType.Remove, id: uploadId });\n // TODO: remove local blob\n if (imageUpload?.metadata.progress === 1) {\n try {\n adapter.deleteImage(imageId);\n } catch (error) {\n console.error(error);\n }\n }\n },\n [adapter, inlineImageUploads]\n );\n return [inlineImageUploads, handleInlineImageUploadAction, onUploadInlineImage, onCancelInlineImageUploadHandler];\n};\n"]}
|