@azure/communication-react 1.19.0-alpha-202408030014 → 1.19.0-alpha-202408070015
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/dist-cjs/communication-react/{ChatMessageComponentAsRichTextEditBox-BBTJIosO.js → ChatMessageComponentAsRichTextEditBox-BMVUY7HX.js} +2 -2
- package/dist/dist-cjs/communication-react/{ChatMessageComponentAsRichTextEditBox-BBTJIosO.js.map → ChatMessageComponentAsRichTextEditBox-BMVUY7HX.js.map} +1 -1
- package/dist/dist-cjs/communication-react/{RichTextSendBoxWrapper-C1Ev6MKx.js → RichTextSendBoxWrapper-UkjXSVQH.js} +2 -2
- package/dist/dist-cjs/communication-react/{RichTextSendBoxWrapper-C1Ev6MKx.js.map → RichTextSendBoxWrapper-UkjXSVQH.js.map} +1 -1
- package/dist/dist-cjs/communication-react/{index-B74o7NiP.js → index-D46R0M5v.js} +116 -93
- package/dist/dist-cjs/communication-react/index-D46R0M5v.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/react-components/src/components/RichTextEditor/Plugins/CopyPastePlugin.d.ts +2 -5
- package/dist/dist-esm/react-components/src/components/RichTextEditor/Plugins/CopyPastePlugin.js +48 -31
- package/dist/dist-esm/react-components/src/components/RichTextEditor/Plugins/CopyPastePlugin.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/utils/RichTextEditorUtils.d.ts +1 -0
- package/dist/dist-esm/react-components/src/components/utils/RichTextEditorUtils.js +1 -0
- package/dist/dist-esm/react-components/src/components/utils/RichTextEditorUtils.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/utils/SendBoxUtils.js +7 -3
- package/dist/dist-esm/react-components/src/components/utils/SendBoxUtils.js.map +1 -1
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/ImageUploadUtils.js +4 -2
- package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/ImageUploadUtils.js.map +1 -1
- package/package.json +1 -1
- package/dist/dist-cjs/communication-react/index-B74o7NiP.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"telemetryVersion.js","sourceRoot":"","sources":["../../../../../acs-ui-common/src/telemetryVersion.js"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;AAElC,wCAAwC;AAExC,MAAM,CAAC,OAAO,GAAG,2BAA2B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n// GENERATED FILE. DO NOT EDIT MANUALLY.\n\nmodule.exports = '1.19.0-alpha-
|
1
|
+
{"version":3,"file":"telemetryVersion.js","sourceRoot":"","sources":["../../../../../acs-ui-common/src/telemetryVersion.js"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;AAElC,wCAAwC;AAExC,MAAM,CAAC,OAAO,GAAG,2BAA2B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n// GENERATED FILE. DO NOT EDIT MANUALLY.\n\nmodule.exports = '1.19.0-alpha-202408070015';\n"]}
|
package/dist/dist-esm/react-components/src/components/RichTextEditor/Plugins/CopyPastePlugin.d.ts
CHANGED
@@ -8,9 +8,11 @@ export default class CopyPastePlugin implements EditorPlugin {
|
|
8
8
|
content: DocumentFragment;
|
9
9
|
}) => void;
|
10
10
|
onInsertInlineImage?: (imageAttributes: Record<string, string>) => void;
|
11
|
+
private imageBase64DataMap;
|
11
12
|
getName(): string;
|
12
13
|
initialize(editor: IEditor): void;
|
13
14
|
dispose(): void;
|
15
|
+
private handleInlineImage;
|
14
16
|
onPluginEvent(event: PluginEvent): void;
|
15
17
|
}
|
16
18
|
/**
|
@@ -20,11 +22,6 @@ export default class CopyPastePlugin implements EditorPlugin {
|
|
20
22
|
export declare const handleBeforePasteEvent: (event: PluginEvent, onPaste?: (event: {
|
21
23
|
content: DocumentFragment;
|
22
24
|
}) => void) => void;
|
23
|
-
/**
|
24
|
-
* @internal
|
25
|
-
* Exported only for unit testing
|
26
|
-
*/
|
27
|
-
export declare const handleInlineImage: (event: PluginEvent, onInsertInlineImage?: (imageAttributes: Record<string, string>) => void) => void;
|
28
25
|
/**
|
29
26
|
* Update the scroll position of the editor after pasting content to ensure the content is visible.
|
30
27
|
* @param event - The plugin event.
|
package/dist/dist-esm/react-components/src/components/RichTextEditor/Plugins/CopyPastePlugin.js
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
1
10
|
/* @conditional-compile-remove(rich-text-editor) */
|
2
11
|
import { scrollToBottomRichTextEditor } from '../../utils/RichTextEditorUtils';
|
3
12
|
import { ContentChangedEventSource, PluginEventType } from '../../utils/RichTextEditorUtils';
|
@@ -13,6 +22,35 @@ import { v1 as generateGUID } from 'uuid';
|
|
13
22
|
export default class CopyPastePlugin {
|
14
23
|
constructor() {
|
15
24
|
this.editor = null;
|
25
|
+
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
26
|
+
this.imageBase64DataMap = {};
|
27
|
+
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
28
|
+
this.handleInlineImage = (event) => {
|
29
|
+
if (event.eventType === PluginEventType.BeforePaste && event.pasteType === 'normal' && this.onInsertInlineImage) {
|
30
|
+
event.fragment.querySelectorAll('img').forEach((image) => {
|
31
|
+
// Assign a unique id to the image element so Contosos can identify the image element.
|
32
|
+
// We also use it internally such as in getRemovedInlineImages to compare images in the content with previous images
|
33
|
+
image.id = generateGUID();
|
34
|
+
const clipboardImage = event.clipboardData.image;
|
35
|
+
const fileName = (clipboardImage === null || clipboardImage === void 0 ? void 0 : clipboardImage.name) ||
|
36
|
+
(clipboardImage === null || clipboardImage === void 0 ? void 0 : clipboardImage.type.replace('/', '.')) ||
|
37
|
+
image.getAttribute(_IMAGE_ATTRIBUTE_INLINE_IMAGE_FILE_NAME_KEY) ||
|
38
|
+
'';
|
39
|
+
// If the image src is an external url, call the onInsertInlineImage callback with the url.
|
40
|
+
let imageUrl = image.src;
|
41
|
+
if (image.src.startsWith('data:image/')) {
|
42
|
+
this.imageBase64DataMap[image.id] = image.src;
|
43
|
+
const blobImage = _base64ToBlob(image.src);
|
44
|
+
imageUrl = URL.createObjectURL(blobImage);
|
45
|
+
}
|
46
|
+
image.src = imageUrl;
|
47
|
+
image.alt = image.alt || 'image';
|
48
|
+
image.dataset.imageFileName = fileName;
|
49
|
+
const imageAttributes = getInlineImageAttributes(image);
|
50
|
+
this.onInsertInlineImage && this.onInsertInlineImage(imageAttributes);
|
51
|
+
});
|
52
|
+
}
|
53
|
+
};
|
16
54
|
}
|
17
55
|
getName() {
|
18
56
|
return 'CopyPastePlugin';
|
@@ -22,6 +60,15 @@ export default class CopyPastePlugin {
|
|
22
60
|
}
|
23
61
|
dispose() { }
|
24
62
|
onPluginEvent(event) {
|
63
|
+
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
64
|
+
if (event.eventType === PluginEventType.BeforeCutCopy) {
|
65
|
+
event.clonedRoot.querySelectorAll('img').forEach((image) => __awaiter(this, void 0, void 0, function* () {
|
66
|
+
if (image.src.startsWith('blob:')) {
|
67
|
+
const base64Data = this.imageBase64DataMap[image.id];
|
68
|
+
image.src = base64Data || image.src;
|
69
|
+
}
|
70
|
+
}));
|
71
|
+
}
|
25
72
|
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
26
73
|
// If onInsertInlineImage is not provided, we should remove the image tags before calling the onPaste callback
|
27
74
|
if (event.eventType === PluginEventType.BeforePaste && event.pasteType === 'normal' && !this.onInsertInlineImage) {
|
@@ -31,7 +78,7 @@ export default class CopyPastePlugin {
|
|
31
78
|
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
32
79
|
// We should handle the onInsertInlineImage after the onPaste callback in case Contosos want to modify the image tags, especially the src attribute.
|
33
80
|
if (this.onInsertInlineImage) {
|
34
|
-
handleInlineImage(event
|
81
|
+
this.handleInlineImage(event);
|
35
82
|
}
|
36
83
|
if (this.editor !== null && !this.editor.isDisposed()) {
|
37
84
|
// scroll the editor to the correct position after pasting content
|
@@ -52,36 +99,6 @@ export const handleBeforePasteEvent = (event,
|
|
52
99
|
return;
|
53
100
|
}
|
54
101
|
};
|
55
|
-
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
56
|
-
/**
|
57
|
-
* @internal
|
58
|
-
* Exported only for unit testing
|
59
|
-
*/
|
60
|
-
export const handleInlineImage = (event, onInsertInlineImage) => {
|
61
|
-
if (event.eventType === PluginEventType.BeforePaste && event.pasteType === 'normal' && onInsertInlineImage) {
|
62
|
-
event.fragment.querySelectorAll('img').forEach((image) => {
|
63
|
-
const clipboardImage = event.clipboardData.image;
|
64
|
-
const fileName = (clipboardImage === null || clipboardImage === void 0 ? void 0 : clipboardImage.name) ||
|
65
|
-
(clipboardImage === null || clipboardImage === void 0 ? void 0 : clipboardImage.type.replace('/', '.')) ||
|
66
|
-
image.getAttribute(_IMAGE_ATTRIBUTE_INLINE_IMAGE_FILE_NAME_KEY) ||
|
67
|
-
'';
|
68
|
-
// If the image src is an external url, call the onInsertInlineImage callback with the url.
|
69
|
-
let imageUrl = image.src;
|
70
|
-
if (image.src.startsWith('data:image/')) {
|
71
|
-
const blobImage = _base64ToBlob(image.src);
|
72
|
-
imageUrl = URL.createObjectURL(blobImage);
|
73
|
-
}
|
74
|
-
image.src = imageUrl;
|
75
|
-
image.alt = image.alt || 'image';
|
76
|
-
// Assign a unique id to the image element so Contosos can identify the image element.
|
77
|
-
// We also use it internally such as in getRemovedInlineImages to compare images in the content with previous images
|
78
|
-
image.id = generateGUID();
|
79
|
-
image.dataset.imageFileName = fileName;
|
80
|
-
const imageAttributes = getInlineImageAttributes(image);
|
81
|
-
onInsertInlineImage(imageAttributes);
|
82
|
-
});
|
83
|
-
}
|
84
|
-
};
|
85
102
|
/**
|
86
103
|
* Update the scroll position of the editor after pasting content to ensure the content is visible.
|
87
104
|
* @param event - The plugin event.
|
package/dist/dist-esm/react-components/src/components/RichTextEditor/Plugins/CopyPastePlugin.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CopyPastePlugin.js","sourceRoot":"","sources":["../../../../../../../../react-components/src/components/RichTextEditor/Plugins/CopyPastePlugin.tsx"],"names":[],"mappings":"AAGA,mDAAmD;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAC7F,gEAAgE;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,gEAAgE;AAChE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,2CAA2C,EAAE,yCAAgC;AACtH,gEAAgE;AAChE,OAAO,EAAE,EAAE,IAAI,YAAY,EAAE,MAAM,MAAM,CAAC;AAE1C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAApC;QACU,WAAM,GAAmB,IAAI,CAAC;
|
1
|
+
{"version":3,"file":"CopyPastePlugin.js","sourceRoot":"","sources":["../../../../../../../../react-components/src/components/RichTextEditor/Plugins/CopyPastePlugin.tsx"],"names":[],"mappings":";;;;;;;;;AAGA,mDAAmD;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;A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CAAC;QAC3G,mDAAmD;QACnD,4BAA4B,EAAE,CAAC;IACjC,CAAC;AACH,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { PluginEvent, EditorPlugin, IEditor } from 'roosterjs-content-model-types';\n/* @conditional-compile-remove(rich-text-editor) */\nimport { scrollToBottomRichTextEditor } from '../../utils/RichTextEditorUtils';\nimport { ContentChangedEventSource, PluginEventType } from '../../utils/RichTextEditorUtils';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { getInlineImageAttributes } from '../../utils/RichTextEditorUtils';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { _base64ToBlob, removeImageTags, _IMAGE_ATTRIBUTE_INLINE_IMAGE_FILE_NAME_KEY } from '@internal/acs-ui-common';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { v1 as generateGUID } from 'uuid';\n\n/**\n * CopyPastePlugin is a plugin for handling copy and paste events in the editor.\n */\nexport default class CopyPastePlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n // don't set value in constructor to be able to update it without plugin recreation\n /* @conditional-compile-remove(rich-text-editor-image-upload) */\n onPaste?: (event: { content: DocumentFragment }) => void;\n /* @conditional-compile-remove(rich-text-editor-image-upload) */\n onInsertInlineImage?: (imageAttributes: Record<string, string>) => void;\n /* @conditional-compile-remove(rich-text-editor-image-upload) */\n private imageBase64DataMap: Record<string, string> = {};\n\n getName(): string {\n return 'CopyPastePlugin';\n }\n\n initialize(editor: IEditor): void {\n this.editor = editor;\n }\n\n dispose(): void {}\n\n /* @conditional-compile-remove(rich-text-editor-image-upload) */\n private handleInlineImage = (event: PluginEvent): void => {\n if (event.eventType === PluginEventType.BeforePaste && event.pasteType === 'normal' && this.onInsertInlineImage) {\n event.fragment.querySelectorAll('img').forEach((image) => {\n // Assign a unique id to the image element so Contosos can identify the image element.\n // We also use it internally such as in getRemovedInlineImages to compare images in the content with previous images\n image.id = generateGUID();\n\n const clipboardImage = event.clipboardData.image;\n const fileName =\n clipboardImage?.name ||\n clipboardImage?.type.replace('/', '.') ||\n image.getAttribute(_IMAGE_ATTRIBUTE_INLINE_IMAGE_FILE_NAME_KEY) ||\n '';\n // If the image src is an external url, call the onInsertInlineImage callback with the url.\n let imageUrl = image.src;\n if (image.src.startsWith('data:image/')) {\n this.imageBase64DataMap[image.id] = image.src;\n\n const blobImage = _base64ToBlob(image.src);\n imageUrl = URL.createObjectURL(blobImage);\n }\n\n image.src = imageUrl;\n image.alt = image.alt || 'image';\n\n image.dataset.imageFileName = fileName;\n\n const imageAttributes = getInlineImageAttributes(image);\n\n this.onInsertInlineImage && this.onInsertInlineImage(imageAttributes);\n });\n }\n };\n\n onPluginEvent(event: PluginEvent): void {\n /* @conditional-compile-remove(rich-text-editor-image-upload) */\n if (event.eventType === PluginEventType.BeforeCutCopy) {\n event.clonedRoot.querySelectorAll('img').forEach(async (image) => {\n if (image.src.startsWith('blob:')) {\n const base64Data = this.imageBase64DataMap[image.id];\n image.src = base64Data || image.src;\n }\n });\n }\n\n /* @conditional-compile-remove(rich-text-editor-image-upload) */\n // If onInsertInlineImage is not provided, we should remove the image tags before calling the onPaste callback\n if (event.eventType === PluginEventType.BeforePaste && event.pasteType === 'normal' && !this.onInsertInlineImage) {\n removeImageTags({ content: event.fragment });\n }\n\n handleBeforePasteEvent(event, /* @conditional-compile-remove(rich-text-editor-image-upload) */ this.onPaste);\n\n /* @conditional-compile-remove(rich-text-editor-image-upload) */\n // We should handle the onInsertInlineImage after the onPaste callback in case Contosos want to modify the image tags, especially the src attribute.\n if (this.onInsertInlineImage) {\n this.handleInlineImage(event);\n }\n\n if (this.editor !== null && !this.editor.isDisposed()) {\n // scroll the editor to the correct position after pasting content\n scrollToBottomAfterContentPaste(event);\n }\n }\n}\n\n/**\n * @internal\n * Exported only for unit testing\n */\nexport const handleBeforePasteEvent = (\n event: PluginEvent,\n /* @conditional-compile-remove(rich-text-editor-image-upload) */ onPaste?: (event: {\n content: DocumentFragment;\n }) => void\n): void => {\n if (event.eventType === PluginEventType.BeforePaste && event.pasteType === 'normal') {\n /* @conditional-compile-remove(rich-text-editor-image-upload) */\n onPaste?.({ content: event.fragment });\n /* @conditional-compile-remove(rich-text-editor-image-upload) */\n return;\n }\n};\n\n/**\n * Update the scroll position of the editor after pasting content to ensure the content is visible.\n * @param event - The plugin event.\n */\nexport const scrollToBottomAfterContentPaste = (event: PluginEvent): void => {\n if (event.eventType === PluginEventType.ContentChanged && event.source === ContentChangedEventSource.Paste) {\n /* @conditional-compile-remove(rich-text-editor) */\n scrollToBottomRichTextEditor();\n }\n};\n"]}
|
@@ -12,6 +12,7 @@ export var PluginEventType;
|
|
12
12
|
PluginEventType["BeforeSetContent"] = "beforeSetContent";
|
13
13
|
PluginEventType["Input"] = "input";
|
14
14
|
PluginEventType["KeyDown"] = "keyDown";
|
15
|
+
PluginEventType["BeforeCutCopy"] = "beforeCutCopy";
|
15
16
|
PluginEventType["BeforePaste"] = "beforePaste";
|
16
17
|
PluginEventType["ZoomChanged"] = "zoomChanged";
|
17
18
|
PluginEventType["MouseUp"] = "mouseUp";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"RichTextEditorUtils.js","sourceRoot":"","sources":["../../../../../../../react-components/src/components/utils/RichTextEditorUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;;GAGG;AACH,MAAM,CAAN,IAAY,eAUX;AAVD,WAAY,eAAe;IACzB,8CAA2B,CAAA;IAC3B,kDAA+B,CAAA;IAC/B,oDAAiC,CAAA;IACjC,wDAAqC,CAAA;IACrC,kCAAe,CAAA;IACf,sCAAmB,CAAA;IACnB,8CAA2B,CAAA;IAC3B,8CAA2B,CAAA;IAC3B,sCAAmB,CAAA;AACrB,CAAC,EAVW,eAAe,KAAf,eAAe,QAU1B;AAED;;;GAGG;AACH,MAAM,CAAN,IAAY,yBAEX;AAFD,WAAY,yBAAyB;IACnC,4CAAe,CAAA;AACjB,CAAC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OAAO,CAAC,CAAC;QAC7B,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { BorderFormat, DatasetFormat, ModelToDomContext } from 'roosterjs-content-model-types';\n\n/**\n * Plugin event type for RoosterJS plugins\n * @private\n */\nexport enum PluginEventType {\n EditorReady = 'editorReady',\n BeforeDispose = 'beforeDispose',\n ContentChanged = 'contentChanged',\n BeforeSetContent = 'beforeSetContent',\n Input = 'input',\n KeyDown = 'keyDown',\n BeforePaste = 'beforePaste',\n ZoomChanged = 'zoomChanged',\n MouseUp = 'mouseUp'\n}\n\n/**\n * ContentChanged event source for RoosterJS\n * @private\n */\nexport enum ContentChangedEventSource {\n Paste = 'Paste'\n}\n\n/**\n * Applies the border format to the specified element.\n * If the element is an HTMLTableCellElement, it skips setting editing info\n * and to use classes instead of inline styles.\n * For all other cases, the default format applier is used.\n */\nexport const borderApplier = (format: BorderFormat, element: HTMLElement, context: ModelToDomContext): void => {\n if (element instanceof HTMLTableCellElement) {\n // don't set format for table cell\n // as it will set inline styles for them\n // we want to use classes instead\n } else if (context.defaultFormatAppliers.border) {\n // apply default formats for all other cases\n context.defaultFormatAppliers.border(format, element, context);\n }\n};\n\n/**\n * Applies the dataset format to the given HTML element.\n * If the element is an HTMLTableElement, it skips setting editing info\n * and to use classes instead of inline styles.\n * For all other cases, it applies the default formats.\n */\nexport const dataSetApplier = (format: DatasetFormat, element: HTMLElement, context: ModelToDomContext): void => {\n if (element instanceof HTMLTableElement) {\n // don't set editing info for tables\n // as it will set inline styles for them\n // we want to use classes instead\n } else if (context.defaultFormatAppliers.dataset) {\n // apply default formats for all other cases\n context.defaultFormatAppliers.dataset(format, element, context);\n }\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getPreviousInlineImages = (content?: string): Record<string, string>[] => {\n if (!content) {\n return [];\n }\n const previousInlineImages: Record<string, string>[] = [];\n const document = new DOMParser().parseFromString(content ?? '', 'text/html');\n document.querySelectorAll('img').forEach((img) => {\n const imageAttributes = getInlineImageAttributes(img);\n previousInlineImages.push(imageAttributes);\n });\n return previousInlineImages;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getRemovedInlineImages = (\n content: string,\n previousInlineImages: Record<string, string>[]\n): Record<string, string>[] => {\n const document = new DOMParser().parseFromString(content ?? '', 'text/html');\n const currentContentIds = Array.from(document.querySelectorAll('img')).map((img) => img.id);\n previousInlineImages = previousInlineImages?.filter((img) => !currentContentIds?.includes(img.id));\n\n const removedInlineImages = [...previousInlineImages];\n return removedInlineImages;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getInsertedInlineImages = (\n content: string,\n previousInlineImages: NodeListOf<HTMLImageElement>\n): HTMLImageElement[] => {\n const document = new DOMParser().parseFromString(content ?? '', 'text/html');\n const currentContentInlineImages = Array.from(document.querySelectorAll('img'));\n const previousContentIds = Array.from(previousInlineImages).map((img) => img.id);\n // if check is updated, also update getRemovedInlineImages\n const insertedInlineImages = currentContentInlineImages.filter((img) => !previousContentIds.includes(img.id));\n return insertedInlineImages;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getInlineImageAttributes = (image: HTMLImageElement): Record<string, string> => {\n const imageAttributes: Record<string, string> = {};\n image.getAttributeNames().forEach((attrName) => {\n const attrValue = image.getAttribute(attrName);\n if (attrValue) {\n imageAttributes[attrName] = attrValue;\n }\n });\n return imageAttributes;\n};\n\n/* @conditional-compile-remove(rich-text-editor) */\n/**\n * @internal\n */\n/**\n * Update the scroll position of the editor to ensure the content is visible.\n */\nexport const scrollToBottomRichTextEditor = (): void => {\n // Get the current selection in the document\n const selection = document.getSelection();\n\n // Check if a selection exists and it has at least one range\n if (!selection || selection.rangeCount <= 0) {\n // If no selection or range, exit the function\n return;\n }\n\n // Get the first range of the selection\n // A user can normally only select one range at a time, so the rangeCount will usually be 1\n const range = selection.getRangeAt(0);\n\n // If the common ancestor container of the range is the document itself,\n // it might mean that the editable element is getting removed from the DOM\n // In such cases, especially in Safari, trying to modify the range might throw a HierarchyRequest error\n if (range.commonAncestorContainer === document) {\n return;\n }\n\n // Create a temporary span element to use as an anchor for scrolling\n // We can't use the anchor node directly because if it's a Text node, calling scrollIntoView() on it will throw an error\n const tempElement = document.createElement('span');\n // Collapse the range to its end point\n // This means the start and end points of the range will be the same, and it will not contain any content\n range.collapse(false);\n // Insert the temporary element at the cursor's position at the end of the range\n range.insertNode(tempElement);\n // Scroll the temporary element into view\n // the element will be aligned at the center of the scroll container, otherwise, text and images may be positioned incorrectly\n tempElement.scrollIntoView({\n block: 'center'\n });\n tempElement.remove();\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * Revoke the blob urls in the removedInlineImages and remove them from the currentLocalBlobMap\n * @internal\n */\nexport const removeLocalBlobs = (\n currentLocalBlobMap: Record<string, string>,\n removedInlineImages: Record<string, string>[]\n): void => {\n removedInlineImages.forEach((image) => {\n removeSingleLocalBlob(currentLocalBlobMap, image.id);\n });\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * Revoke all the blob urls in the currentLocalBlobMap and clean up the currentLocalBlobMap\n * @internal\n */\nexport const cleanAllLocalBlobs = (currentLocalBlobMap: Record<string, string>): void => {\n Object.keys(currentLocalBlobMap).forEach((imageId) => {\n removeSingleLocalBlob(currentLocalBlobMap, imageId);\n });\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nconst removeSingleLocalBlob = (currentLocalBlobMap: Record<string, string>, imageId: string): void => {\n const blobUrl = currentLocalBlobMap[imageId];\n if (blobUrl) {\n URL.revokeObjectURL(blobUrl);\n delete currentLocalBlobMap[imageId];\n }\n};\n"]}
|
1
|
+
{"version":3,"file":"RichTextEditorUtils.js","sourceRoot":"","sources":["../../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L,CAAC,CAAC;AAEF,gEAAgE;AAChE;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,mBAA2C,EAAQ,EAAE;IACtF,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACnD,qBAAqB,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,gEAAgE;AAChE,MAAM,qBAAqB,GAAG,CAAC,mBAA2C,EAAE,OAAe,EAAQ,EAAE;IACnG,MAAM,OAAO,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAC7C,IAAI,OAAO,EAAE,CAAC;QACZ,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { BorderFormat, DatasetFormat, ModelToDomContext } from 'roosterjs-content-model-types';\n\n/**\n * Plugin event type for RoosterJS plugins\n * @private\n */\nexport enum PluginEventType {\n EditorReady = 'editorReady',\n BeforeDispose = 'beforeDispose',\n ContentChanged = 'contentChanged',\n BeforeSetContent = 'beforeSetContent',\n Input = 'input',\n KeyDown = 'keyDown',\n BeforeCutCopy = 'beforeCutCopy',\n BeforePaste = 'beforePaste',\n ZoomChanged = 'zoomChanged',\n MouseUp = 'mouseUp'\n}\n\n/**\n * ContentChanged event source for RoosterJS\n * @private\n */\nexport enum ContentChangedEventSource {\n Paste = 'Paste'\n}\n\n/**\n * Applies the border format to the specified element.\n * If the element is an HTMLTableCellElement, it skips setting editing info\n * and to use classes instead of inline styles.\n * For all other cases, the default format applier is used.\n */\nexport const borderApplier = (format: BorderFormat, element: HTMLElement, context: ModelToDomContext): void => {\n if (element instanceof HTMLTableCellElement) {\n // don't set format for table cell\n // as it will set inline styles for them\n // we want to use classes instead\n } else if (context.defaultFormatAppliers.border) {\n // apply default formats for all other cases\n context.defaultFormatAppliers.border(format, element, context);\n }\n};\n\n/**\n * Applies the dataset format to the given HTML element.\n * If the element is an HTMLTableElement, it skips setting editing info\n * and to use classes instead of inline styles.\n * For all other cases, it applies the default formats.\n */\nexport const dataSetApplier = (format: DatasetFormat, element: HTMLElement, context: ModelToDomContext): void => {\n if (element instanceof HTMLTableElement) {\n // don't set editing info for tables\n // as it will set inline styles for them\n // we want to use classes instead\n } else if (context.defaultFormatAppliers.dataset) {\n // apply default formats for all other cases\n context.defaultFormatAppliers.dataset(format, element, context);\n }\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getPreviousInlineImages = (content?: string): Record<string, string>[] => {\n if (!content) {\n return [];\n }\n const previousInlineImages: Record<string, string>[] = [];\n const document = new DOMParser().parseFromString(content ?? '', 'text/html');\n document.querySelectorAll('img').forEach((img) => {\n const imageAttributes = getInlineImageAttributes(img);\n previousInlineImages.push(imageAttributes);\n });\n return previousInlineImages;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getRemovedInlineImages = (\n content: string,\n previousInlineImages: Record<string, string>[]\n): Record<string, string>[] => {\n const document = new DOMParser().parseFromString(content ?? '', 'text/html');\n const currentContentIds = Array.from(document.querySelectorAll('img')).map((img) => img.id);\n previousInlineImages = previousInlineImages?.filter((img) => !currentContentIds?.includes(img.id));\n\n const removedInlineImages = [...previousInlineImages];\n return removedInlineImages;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getInsertedInlineImages = (\n content: string,\n previousInlineImages: NodeListOf<HTMLImageElement>\n): HTMLImageElement[] => {\n const document = new DOMParser().parseFromString(content ?? '', 'text/html');\n const currentContentInlineImages = Array.from(document.querySelectorAll('img'));\n const previousContentIds = Array.from(previousInlineImages).map((img) => img.id);\n // if check is updated, also update getRemovedInlineImages\n const insertedInlineImages = currentContentInlineImages.filter((img) => !previousContentIds.includes(img.id));\n return insertedInlineImages;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getInlineImageAttributes = (image: HTMLImageElement): Record<string, string> => {\n const imageAttributes: Record<string, string> = {};\n image.getAttributeNames().forEach((attrName) => {\n const attrValue = image.getAttribute(attrName);\n if (attrValue) {\n imageAttributes[attrName] = attrValue;\n }\n });\n return imageAttributes;\n};\n\n/* @conditional-compile-remove(rich-text-editor) */\n/**\n * @internal\n */\n/**\n * Update the scroll position of the editor to ensure the content is visible.\n */\nexport const scrollToBottomRichTextEditor = (): void => {\n // Get the current selection in the document\n const selection = document.getSelection();\n\n // Check if a selection exists and it has at least one range\n if (!selection || selection.rangeCount <= 0) {\n // If no selection or range, exit the function\n return;\n }\n\n // Get the first range of the selection\n // A user can normally only select one range at a time, so the rangeCount will usually be 1\n const range = selection.getRangeAt(0);\n\n // If the common ancestor container of the range is the document itself,\n // it might mean that the editable element is getting removed from the DOM\n // In such cases, especially in Safari, trying to modify the range might throw a HierarchyRequest error\n if (range.commonAncestorContainer === document) {\n return;\n }\n\n // Create a temporary span element to use as an anchor for scrolling\n // We can't use the anchor node directly because if it's a Text node, calling scrollIntoView() on it will throw an error\n const tempElement = document.createElement('span');\n // Collapse the range to its end point\n // This means the start and end points of the range will be the same, and it will not contain any content\n range.collapse(false);\n // Insert the temporary element at the cursor's position at the end of the range\n range.insertNode(tempElement);\n // Scroll the temporary element into view\n // the element will be aligned at the center of the scroll container, otherwise, text and images may be positioned incorrectly\n tempElement.scrollIntoView({\n block: 'center'\n });\n tempElement.remove();\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * Revoke the blob urls in the removedInlineImages and remove them from the currentLocalBlobMap\n * @internal\n */\nexport const removeLocalBlobs = (\n currentLocalBlobMap: Record<string, string>,\n removedInlineImages: Record<string, string>[]\n): void => {\n removedInlineImages.forEach((image) => {\n removeSingleLocalBlob(currentLocalBlobMap, image.id);\n });\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * Revoke all the blob urls in the currentLocalBlobMap and clean up the currentLocalBlobMap\n * @internal\n */\nexport const cleanAllLocalBlobs = (currentLocalBlobMap: Record<string, string>): void => {\n Object.keys(currentLocalBlobMap).forEach((imageId) => {\n removeSingleLocalBlob(currentLocalBlobMap, imageId);\n });\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nconst removeSingleLocalBlob = (currentLocalBlobMap: Record<string, string>, imageId: string): void => {\n const blobUrl = currentLocalBlobMap[imageId];\n if (blobUrl) {\n URL.revokeObjectURL(blobUrl);\n delete currentLocalBlobMap[imageId];\n }\n};\n"]}
|
@@ -77,8 +77,7 @@ export const updateStylesOfInlineImages = (message, initialInlineImages) => __aw
|
|
77
77
|
resolve();
|
78
78
|
};
|
79
79
|
imageElement.onerror = () => {
|
80
|
-
|
81
|
-
rejects();
|
80
|
+
rejects(`Error loading image ${img.id}`);
|
82
81
|
};
|
83
82
|
});
|
84
83
|
});
|
@@ -145,7 +144,12 @@ export const toAttachmentMetadata = (attachmentsWithProgress) => {
|
|
145
144
|
export const modifyInlineImagesInContentString = (content, initialInlineImages, onCompleted) => __awaiter(void 0, void 0, void 0, function* () {
|
146
145
|
let newContent = content;
|
147
146
|
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
148
|
-
|
147
|
+
try {
|
148
|
+
newContent = yield updateStylesOfInlineImages(content, initialInlineImages);
|
149
|
+
}
|
150
|
+
catch (error) {
|
151
|
+
console.error('Error updating inline images: ', error);
|
152
|
+
}
|
149
153
|
onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(newContent);
|
150
154
|
});
|
151
155
|
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SendBoxUtils.js","sourceRoot":"","sources":["../../../../../../../react-components/src/components/utils/SendBoxUtils.ts"],"names":[],"mapp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AS,CAAC;AACjC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* @conditional-compile-remove(file-sharing-acs) */\nimport { AttachmentMetadataInProgress } from '@internal/acs-ui-common';\n/* @conditional-compile-remove(file-sharing-acs) */\nimport { AttachmentMetadata } from '@internal/acs-ui-common';\n\n/**\n * @private\n */\nexport const MAXIMUM_LENGTH_OF_MESSAGE = 8000;\nconst EMPTY_MESSAGE_REGEX = /^\\s*$/;\n\n/* @conditional-compile-remove(file-sharing-acs) */\n/**\n * @private\n */\nexport const hasIncompleteAttachmentUploads = (\n attachmentsWithProgress: AttachmentMetadataInProgress[] | undefined\n): boolean => {\n return !!(\n attachmentsWithProgress?.length &&\n !attachmentsWithProgress\n .filter((attachmentUpload) => !attachmentUpload.error)\n .every((attachmentUpload) => attachmentUpload.progress === 1 && attachmentUpload.progress !== undefined)\n );\n};\n\n/* @conditional-compile-remove(file-sharing-acs) */\n/**\n * @private\n */\nexport const isAttachmentUploadCompleted = (\n attachmentsWithProgress: AttachmentMetadataInProgress[] | undefined\n): boolean => {\n return !!attachmentsWithProgress?.find((attachment) => !attachment.error);\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * Check if the content has inline image.\n * @internal\n */\nexport const hasInlineImageContent = (content: string): boolean => {\n const document = new DOMParser().parseFromString(content, 'text/html');\n return !!document.querySelector('img');\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n *\n * @param message - The message content to update.\n * @param initialInlineImages - The initial inline images that comes with the message before editing.\n *\n * @returns The updated message content.\n */\nexport const updateStylesOfInlineImages = async (\n message: string,\n initialInlineImages: Record<string, string>[]\n): Promise<string> => {\n if (message === '') {\n return message;\n }\n const initialInlineImagesIds = initialInlineImages.map((initialInlineImage) => initialInlineImage.id);\n const document = new DOMParser().parseFromString(message ?? '', 'text/html');\n const imagesPromise = Array.from(document.querySelectorAll('img')).map((img) => {\n return new Promise<void>((resolve, rejects) => {\n // The message might content images that comes with the message before editing.\n // This function should only modify the message content for images that are newly added.\n if (initialInlineImagesIds.includes(img.id)) {\n resolve();\n return;\n }\n const imageElement = new Image();\n imageElement.src = img.src;\n imageElement.onload = () => {\n // imageElement is a copy of original img element, so changes need to be made to the original img element\n img.width = imageElement.width;\n img.height = imageElement.height;\n img.style.aspectRatio = `${imageElement.width} / ${imageElement.height}`;\n // Clear maxWidth and maxHeight styles that are set by roosterJS.\n // This is so that they can be set in messageThread styles without using the important flag.\n img.style.maxWidth = '';\n img.style.maxHeight = '';\n resolve();\n };\n imageElement.onerror = () => {\n console.log('Error loading image', img.src);\n rejects();\n };\n });\n });\n await Promise.all(imagesPromise);\n const newMessage = document.body.innerHTML;\n return newMessage;\n};\n\n/**\n * @private\n */\nexport const isMessageTooLong = (valueLength: number): boolean => {\n return valueLength > MAXIMUM_LENGTH_OF_MESSAGE;\n};\n\n/**\n * @private\n */\nexport const sanitizeText = (message: string): string => {\n if (EMPTY_MESSAGE_REGEX.test(message)) {\n return '';\n } else {\n return message;\n }\n};\n\n/**\n * Determines whether the send box should be disabled for ARIA accessibility.\n *\n * @param hasContent - Indicates whether the send box has content.\n * @param hasCompletedAttachmentUploads - Indicates whether attachment uploads have completed.\n * @param hasError - Indicates whether there is an error.\n * @param disabled - Indicates whether the send box is disabled.\n * @returns A boolean value indicating whether the send box should be disabled for ARIA accessibility.\n */\nexport const isSendBoxButtonAriaDisabled = ({\n hasContent,\n /* @conditional-compile-remove(file-sharing-acs) */\n hasCompletedAttachmentUploads,\n hasError,\n disabled\n}: {\n hasContent: boolean;\n /* @conditional-compile-remove(file-sharing-acs) */\n hasCompletedAttachmentUploads: boolean;\n hasError: boolean;\n disabled: boolean;\n}): boolean => {\n return (\n // no content\n !(hasContent || /* @conditional-compile-remove(file-sharing-acs) */ hasCompletedAttachmentUploads) ||\n //error message exists\n hasError ||\n disabled\n );\n};\n\n/* @conditional-compile-remove(file-sharing-acs) */\n/**\n * @internal\n */\nexport const toAttachmentMetadata = (\n attachmentsWithProgress: AttachmentMetadataInProgress[] | undefined\n): AttachmentMetadata[] | undefined => {\n return attachmentsWithProgress\n ?.filter((attachment) => {\n return !('error' in attachment) && !attachment.error?.message;\n })\n .map((attachment) => {\n return {\n id: attachment.id,\n name: attachment.name,\n url: attachment.url ?? ''\n };\n });\n};\n\n/**\n * @internal\n */\nexport const modifyInlineImagesInContentString = async (\n content: string,\n initialInlineImages: Record<string, string>[],\n onCompleted?: (content: string) => void\n): Promise<void> => {\n let newContent = content;\n /* @conditional-compile-remove(rich-text-editor-image-upload) */\n newContent = await updateStylesOfInlineImages(content, initialInlineImages);\n onCompleted?.(newContent);\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const removeBrokenImageContentAndClearImageSizeStyles = (content: string): string => {\n const document = new DOMParser().parseFromString(content, 'text/html');\n document.querySelectorAll('img').forEach((img) => {\n // Before submitting/resend the message, we need to trim the unnecessary attributes such as src,\n // which is set to a local svg of a broken image icon at this point.\n // Once message is submitted/resent, it will be fetched again and might not be a broken image anymore,\n // That's why we need to remove the class and data-ui-id attribute of 'broken-image-wrapper'\n if (img.className === 'broken-image-wrapper') {\n img.removeAttribute('class');\n img.removeAttribute('src');\n img.removeAttribute('data-ui-id');\n }\n // Clear maxWidth and maxHeight styles that are set by roosterJS.\n // Clear width and height styles as the width and height is set in attributes\n // This is so that they can be set in messageThread styles without using the important flag.\n img.style.width = '';\n img.style.height = '';\n img.style.maxWidth = '';\n img.style.maxHeight = '';\n });\n return document.body.innerHTML;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getContentWithUpdatedInlineImagesInfo = (\n content: string,\n inlineImageWithProgress: AttachmentMetadataInProgress[]\n): string => {\n if (!inlineImageWithProgress || inlineImageWithProgress.length <= 0) {\n return content;\n }\n const document = new DOMParser().parseFromString(content, 'text/html');\n document.querySelectorAll('img').forEach((img) => {\n const imageId = img.id;\n const inlineImage = inlineImageWithProgress.find(\n (image) => !image.error && image.progress === 1 && image.id === imageId\n );\n if (inlineImage) {\n img.id = inlineImage.id;\n img.src = inlineImage.url || img.src;\n }\n });\n return document.body.innerHTML;\n};\n"]}
|
1
|
+
{"version":3,"file":"SendBoxUtils.js","sourceRoot":"","sources":["../../../../../../../react-components/src/components/utils/SendBoxUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;;;;;;;;;AAOlC;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAC9C,MAAM,mBAAmB,GAAG,OAAO,CAAC;AAEpC,mDAAmD;AACnD;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,uBAAmE,EAC1D,EAAE;IACX,OAAO,CAAC,CAAC,CACP,CAAA,uBAAuB,aAAvB,uBAAuB,uBAAvB,uBAAuB,CAAE,MAAM;QAC/B,CAAC,uBAAuB;aACrB,MAAM,CAAC,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC;aACrD,KAAK,CAAC,CAAC,gBAAgB,EAAE,EAAE,CAAC,gBAAgB,CAAC,QAAQ,KAAK,CAAC,IAAI,gBAAgB,CAAC,QAAQ,KAAK,SAAS,CAAC,CAC3G,CAAC;AACJ,CAAC,CAAC;AAEF,mDAAmD;AACnD;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,uBAAmE,EAC1D,EAAE;IACX,OAAO,CAAC,CAAC,CAAA,uBAAuB,aAAvB,uBAAuB,uBAAvB,uBAAuB,CAAE,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA,CAAC;AAC5E,CAAC,CAAC;AAEF,gEAAgE;AAChE;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAe,EAAW,EAAE;IAChE,MAAM,QAAQ,GAAG,IAAI,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KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,QAAQ,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE,KAAK,OAAO,CACxE,CAAC;QACF,IAAI,WAAW,EAAE,CAAC;YAChB,GAAG,CAAC,EAAE,GAAG,WAAW,CAAC,EAAE,CAAC;YACxB,GAAG,CAAC,GAAG,GAAG,WAAW,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC;QACvC,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;AACjC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* @conditional-compile-remove(file-sharing-acs) */\nimport { AttachmentMetadataInProgress } from '@internal/acs-ui-common';\n/* @conditional-compile-remove(file-sharing-acs) */\nimport { AttachmentMetadata } from '@internal/acs-ui-common';\n\n/**\n * @private\n */\nexport const MAXIMUM_LENGTH_OF_MESSAGE = 8000;\nconst EMPTY_MESSAGE_REGEX = /^\\s*$/;\n\n/* @conditional-compile-remove(file-sharing-acs) */\n/**\n * @private\n */\nexport const hasIncompleteAttachmentUploads = (\n attachmentsWithProgress: AttachmentMetadataInProgress[] | undefined\n): boolean => {\n return !!(\n attachmentsWithProgress?.length &&\n !attachmentsWithProgress\n .filter((attachmentUpload) => !attachmentUpload.error)\n .every((attachmentUpload) => attachmentUpload.progress === 1 && attachmentUpload.progress !== undefined)\n );\n};\n\n/* @conditional-compile-remove(file-sharing-acs) */\n/**\n * @private\n */\nexport const isAttachmentUploadCompleted = (\n attachmentsWithProgress: AttachmentMetadataInProgress[] | undefined\n): boolean => {\n return !!attachmentsWithProgress?.find((attachment) => !attachment.error);\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * Check if the content has inline image.\n * @internal\n */\nexport const hasInlineImageContent = (content: string): boolean => {\n const document = new DOMParser().parseFromString(content, 'text/html');\n return !!document.querySelector('img');\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n *\n * @param message - The message content to update.\n * @param initialInlineImages - The initial inline images that comes with the message before editing.\n *\n * @returns The updated message content.\n */\nexport const updateStylesOfInlineImages = async (\n message: string,\n initialInlineImages: Record<string, string>[]\n): Promise<string> => {\n if (message === '') {\n return message;\n }\n const initialInlineImagesIds = initialInlineImages.map((initialInlineImage) => initialInlineImage.id);\n const document = new DOMParser().parseFromString(message ?? '', 'text/html');\n const imagesPromise = Array.from(document.querySelectorAll('img')).map((img) => {\n return new Promise<void>((resolve, rejects) => {\n // The message might content images that comes with the message before editing.\n // This function should only modify the message content for images that are newly added.\n if (initialInlineImagesIds.includes(img.id)) {\n resolve();\n return;\n }\n const imageElement = new Image();\n imageElement.src = img.src;\n imageElement.onload = () => {\n // imageElement is a copy of original img element, so changes need to be made to the original img element\n img.width = imageElement.width;\n img.height = imageElement.height;\n img.style.aspectRatio = `${imageElement.width} / ${imageElement.height}`;\n // Clear maxWidth and maxHeight styles that are set by roosterJS.\n // This is so that they can be set in messageThread styles without using the important flag.\n img.style.maxWidth = '';\n img.style.maxHeight = '';\n resolve();\n };\n imageElement.onerror = () => {\n rejects(`Error loading image ${img.id}`);\n };\n });\n });\n await Promise.all(imagesPromise);\n const newMessage = document.body.innerHTML;\n return newMessage;\n};\n\n/**\n * @private\n */\nexport const isMessageTooLong = (valueLength: number): boolean => {\n return valueLength > MAXIMUM_LENGTH_OF_MESSAGE;\n};\n\n/**\n * @private\n */\nexport const sanitizeText = (message: string): string => {\n if (EMPTY_MESSAGE_REGEX.test(message)) {\n return '';\n } else {\n return message;\n }\n};\n\n/**\n * Determines whether the send box should be disabled for ARIA accessibility.\n *\n * @param hasContent - Indicates whether the send box has content.\n * @param hasCompletedAttachmentUploads - Indicates whether attachment uploads have completed.\n * @param hasError - Indicates whether there is an error.\n * @param disabled - Indicates whether the send box is disabled.\n * @returns A boolean value indicating whether the send box should be disabled for ARIA accessibility.\n */\nexport const isSendBoxButtonAriaDisabled = ({\n hasContent,\n /* @conditional-compile-remove(file-sharing-acs) */\n hasCompletedAttachmentUploads,\n hasError,\n disabled\n}: {\n hasContent: boolean;\n /* @conditional-compile-remove(file-sharing-acs) */\n hasCompletedAttachmentUploads: boolean;\n hasError: boolean;\n disabled: boolean;\n}): boolean => {\n return (\n // no content\n !(hasContent || /* @conditional-compile-remove(file-sharing-acs) */ hasCompletedAttachmentUploads) ||\n //error message exists\n hasError ||\n disabled\n );\n};\n\n/* @conditional-compile-remove(file-sharing-acs) */\n/**\n * @internal\n */\nexport const toAttachmentMetadata = (\n attachmentsWithProgress: AttachmentMetadataInProgress[] | undefined\n): AttachmentMetadata[] | undefined => {\n return attachmentsWithProgress\n ?.filter((attachment) => {\n return !('error' in attachment) && !attachment.error?.message;\n })\n .map((attachment) => {\n return {\n id: attachment.id,\n name: attachment.name,\n url: attachment.url ?? ''\n };\n });\n};\n\n/**\n * @internal\n */\nexport const modifyInlineImagesInContentString = async (\n content: string,\n initialInlineImages: Record<string, string>[],\n onCompleted?: (content: string) => void\n): Promise<void> => {\n let newContent = content;\n /* @conditional-compile-remove(rich-text-editor-image-upload) */\n try {\n newContent = await updateStylesOfInlineImages(content, initialInlineImages);\n } catch (error) {\n console.error('Error updating inline images: ', error);\n }\n onCompleted?.(newContent);\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const removeBrokenImageContentAndClearImageSizeStyles = (content: string): string => {\n const document = new DOMParser().parseFromString(content, 'text/html');\n document.querySelectorAll('img').forEach((img) => {\n // Before submitting/resend the message, we need to trim the unnecessary attributes such as src,\n // which is set to a local svg of a broken image icon at this point.\n // Once message is submitted/resent, it will be fetched again and might not be a broken image anymore,\n // That's why we need to remove the class and data-ui-id attribute of 'broken-image-wrapper'\n if (img.className === 'broken-image-wrapper') {\n img.removeAttribute('class');\n img.removeAttribute('src');\n img.removeAttribute('data-ui-id');\n }\n // Clear maxWidth and maxHeight styles that are set by roosterJS.\n // Clear width and height styles as the width and height is set in attributes\n // This is so that they can be set in messageThread styles without using the important flag.\n img.style.width = '';\n img.style.height = '';\n img.style.maxWidth = '';\n img.style.maxHeight = '';\n });\n return document.body.innerHTML;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getContentWithUpdatedInlineImagesInfo = (\n content: string,\n inlineImageWithProgress: AttachmentMetadataInProgress[]\n): string => {\n if (!inlineImageWithProgress || inlineImageWithProgress.length <= 0) {\n return content;\n }\n const document = new DOMParser().parseFromString(content, 'text/html');\n document.querySelectorAll('img').forEach((img) => {\n const imageId = img.id;\n const inlineImage = inlineImageWithProgress.find(\n (image) => !image.error && image.progress === 1 && image.id === imageId\n );\n if (inlineImage) {\n img.id = inlineImage.id;\n img.src = inlineImage.url || img.src;\n }\n });\n return document.body.innerHTML;\n};\n"]}
|
package/dist/dist-esm/react-composites/src/composites/ChatComposite/ImageUpload/ImageUploadUtils.js
CHANGED
@@ -205,8 +205,10 @@ export const cancelInlineImageUpload = (imageAttributes, imageUploads, messageId
|
|
205
205
|
id: imageUpload === null || imageUpload === void 0 ? void 0 : imageUpload.metadata.id,
|
206
206
|
messageId
|
207
207
|
});
|
208
|
-
if ((imageUpload === null || imageUpload === void 0 ? void 0 : imageUpload.metadata.progress) === 1) {
|
209
|
-
|
208
|
+
if ((imageUpload === null || imageUpload === void 0 ? void 0 : imageUpload.metadata.progress) === 1 && (imageUpload === null || imageUpload === void 0 ? void 0 : imageUpload.metadata.url)) {
|
209
|
+
// The image id that we got back from the ChatSDK response is stored in the image src attribute,
|
210
|
+
// while the metadata id is the internal image id that we assigned to the image when it was pasted in.
|
211
|
+
deleteInlineImageFromServer(imageUpload === null || imageUpload === void 0 ? void 0 : imageUpload.metadata.url, adapter);
|
210
212
|
}
|
211
213
|
};
|
212
214
|
/* @conditional-compile-remove(rich-text-editor-image-upload) */
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ImageUploadUtils.js","sourceRoot":"","sources":["../../../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IAAI,iBAAiB,EAAE,CAAC;YACtB,+HAA+H;YAC/H,GAAG,CAAC,EAAE,GAAG,MAAA,iBAAiB,CAAC,QAAQ,CAAC,GAAG,mCAAI,GAAG,CAAC,EAAE,CAAC;YAClD,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;IAElC,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,gEAAgE;AAChE;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,eAAuC,EAAU,EAAE;IAChG,MAAM,QAAQ,GAAG,eAAe,CAAC,2CAA2C,CAAC,CAAC;IAC9E,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,EAAE,IAAI,QAAQ,KAAK,WAAW,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;QACpF,OAAO,+BAA+B,CAAC;IACzC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { AttachmentMetadataInProgress, _IMAGE_ATTRIBUTE_INLINE_IMAGE_FILE_NAME_KEY } from '@internal/acs-ui-common';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { AttachmentUpload, AttachmentUploadActionType, AttachmentUploadTask } from '../file-sharing/AttachmentUpload';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { _DEFAULT_INLINE_IMAGE_FILE_NAME, SEND_BOX_UPLOADS_KEY_VALUE } from '../../common/constants';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { ChatAdapter } from '../adapter/ChatAdapter';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { Dispatch } from 'react';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { ImageActions } from './ImageUploadReducer';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { nanoid } from 'nanoid';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { ChatCompositeStrings } from '../Strings';\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nconst MAX_INLINE_IMAGE_UPLOAD_SIZE_MB = 20;\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nconst fetchBlobData = async (\n resource: string | URL | Request,\n options: { timeout?: number; headers?: Headers; abortController: AbortController }\n): Promise<Response> => {\n // default timeout is 30 seconds\n const { timeout = 30000, abortController } = options;\n\n const id = setTimeout(() => {\n abortController.abort();\n }, timeout);\n\n const response = await fetch(resource, {\n ...options,\n signal: abortController.signal\n });\n clearTimeout(id);\n return response;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @private\n */\nexport const getInlineImageData = async (image: string): Promise<Blob | undefined> => {\n if (image.startsWith('blob') || image.startsWith('http')) {\n try {\n const res = await fetchBlobData(image, { abortController: new AbortController() });\n const blobImage = await res.blob();\n return blobImage;\n } catch (error) {\n console.error('Error fetching image data', error);\n return;\n }\n }\n return;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getEditBoxMessagesInlineImages = (\n editBoxInlineImageUploads: Record<string, AttachmentUpload[]> | undefined\n): Record<string, AttachmentMetadataInProgress[]> | undefined => {\n if (!editBoxInlineImageUploads) {\n return;\n }\n const messageIds = Object.keys(editBoxInlineImageUploads || {});\n const messagesInlineImagesWithProgress: Record<string, AttachmentMetadataInProgress[]> = {};\n messageIds.map((messageId) => {\n const messageUploads = editBoxInlineImageUploads[messageId].map((upload) => {\n return upload.metadata;\n });\n messagesInlineImagesWithProgress[messageId] = messageUploads;\n });\n return messagesInlineImagesWithProgress;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getSendBoxInlineImages = (\n sendBoxInlineImageUploads: Record<string, AttachmentUpload[]> | undefined\n): AttachmentMetadataInProgress[] | undefined => {\n if (!sendBoxInlineImageUploads) {\n return;\n }\n return sendBoxInlineImageUploads[SEND_BOX_UPLOADS_KEY_VALUE]?.map((upload) => upload.metadata);\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nconst inlineImageUploadHandler = async (\n uploadTasks: AttachmentUpload[],\n adapter: ChatAdapter,\n strings: ChatCompositeStrings\n): 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(strings.uploadImageDataNotProvided);\n continue;\n }\n if (image && image.size > MAX_INLINE_IMAGE_UPLOAD_SIZE_MB * 1024 * 1024) {\n uploadTask.notifyUploadFailed(\n strings.uploadImageIsTooLarge.replace('{maxImageSize}', `${MAX_INLINE_IMAGE_UPLOAD_SIZE_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(\n strings.uploadImageExtensionIsNotAllowed.replace('{imageExtension}', imageExtension)\n );\n continue;\n }\n\n try {\n const response = await adapter.uploadImage(image, task.metadata?.name);\n // Use response id as the image src because we need to keep the original image id as a reference to find the image.\n // Also the html content we send to ChatSDK does not need image src,\n // it only need the response id to match the uploaded image, url is not needed.\n uploadTask.notifyUploadCompleted(task.metadata.id, response.id);\n } catch (error) {\n console.error(error);\n uploadTask.notifyUploadFailed(strings.uploadImageFailed);\n }\n }\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nconst generateUploadTask = async (\n imageAttributes: Record<string, string>,\n fileName: string,\n messageId: string,\n inlineImageUploadActionHandler: Dispatch<ImageActions>\n): Promise<AttachmentUpload | undefined> => {\n const imageData = await getInlineImageData(imageAttributes.src);\n if (!imageData) {\n return;\n }\n const taskId = nanoid();\n const uploadTask: AttachmentUpload = {\n image: imageData,\n taskId,\n metadata: {\n id: imageAttributes.id,\n name: fileName,\n url: imageAttributes.src,\n progress: 0\n },\n notifyUploadProgressChanged: (value: number) => {\n inlineImageUploadActionHandler({\n type: AttachmentUploadActionType.Progress,\n taskId,\n progress: value,\n messageId\n });\n },\n notifyUploadCompleted: (id: string, url: string) => {\n inlineImageUploadActionHandler({\n type: AttachmentUploadActionType.Completed,\n taskId,\n id,\n url,\n messageId\n });\n },\n notifyUploadFailed: (message: string) => {\n inlineImageUploadActionHandler({ type: AttachmentUploadActionType.Failed, taskId, message, messageId });\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 inlineImageUploadActionHandler({ type: AttachmentUploadActionType.Remove, id: taskId, messageId });\n }, 10 * 1000);\n }\n };\n return uploadTask;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const onInsertInlineImageForEditBox = async (\n imageAttributes: Record<string, string>,\n fileName: string,\n messageId: string,\n adapter: ChatAdapter,\n handleEditBoxInlineImageUploadAction: Dispatch<ImageActions>,\n chatCompositeStrings: ChatCompositeStrings\n): Promise<void> => {\n const uploadTask: AttachmentUpload | undefined = await generateUploadTask(\n imageAttributes,\n fileName,\n messageId,\n handleEditBoxInlineImageUploadAction\n );\n if (!uploadTask) {\n return;\n }\n\n handleEditBoxInlineImageUploadAction({\n type: AttachmentUploadActionType.Set,\n newUploads: [uploadTask],\n messageId\n });\n inlineImageUploadHandler([uploadTask], adapter, chatCompositeStrings);\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const onInsertInlineImageForSendBox = async (\n imageAttributes: Record<string, string>,\n fileName: string,\n adapter: ChatAdapter,\n handleSendBoxInlineImageUploadAction: Dispatch<ImageActions>,\n chatCompositeStrings: ChatCompositeStrings\n): Promise<void> => {\n const uploadTask: AttachmentUpload | undefined = await generateUploadTask(\n imageAttributes,\n fileName,\n SEND_BOX_UPLOADS_KEY_VALUE,\n handleSendBoxInlineImageUploadAction\n );\n\n if (!uploadTask) {\n return;\n }\n\n handleSendBoxInlineImageUploadAction({\n type: AttachmentUploadActionType.Set,\n newUploads: [uploadTask],\n messageId: SEND_BOX_UPLOADS_KEY_VALUE\n });\n inlineImageUploadHandler([uploadTask], adapter, chatCompositeStrings);\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const cancelInlineImageUpload = (\n imageAttributes: Record<string, string>,\n imageUploads: Record<string, AttachmentUpload[]> | undefined,\n messageId: string,\n inlineImageUploadActionHandler: Dispatch<ImageActions>,\n adapter: ChatAdapter\n): void => {\n if (!imageUploads || !imageUploads[messageId]) {\n deleteExistingInlineImageForEditBox(imageAttributes.id, messageId, adapter);\n return;\n }\n const imageUpload = imageUploads[messageId].find((upload) => upload.metadata.id === imageAttributes.id);\n\n if (!imageUpload || !imageUpload?.metadata.id) {\n deleteExistingInlineImageForEditBox(imageAttributes.id, messageId, adapter);\n return;\n }\n\n inlineImageUploadActionHandler({\n type: AttachmentUploadActionType.Remove,\n id: imageUpload?.metadata.id,\n messageId\n });\n\n if (imageUpload?.metadata.progress === 1) {\n deleteInlineImageFromServer(imageUpload?.metadata.id, adapter);\n }\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nconst deleteInlineImageFromServer = (imageId: string, adapter: ChatAdapter): void => {\n try {\n adapter.deleteImage(imageId);\n } catch (error) {\n console.error(error);\n }\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n// This function is used to delete the inline image that existed before editing starts\nconst deleteExistingInlineImageForEditBox = (imageId: string, messageId: string, adapter: ChatAdapter): void => {\n messageId !== SEND_BOX_UPLOADS_KEY_VALUE && deleteInlineImageFromServer(imageId, adapter);\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const updateContentStringWithUploadedInlineImages = (\n content: string,\n imageUploads: Record<string, AttachmentUpload[]> | undefined,\n messageId: string = SEND_BOX_UPLOADS_KEY_VALUE\n): string => {\n if (!imageUploads || !imageUploads[messageId]) {\n return content;\n }\n const messageUploads = imageUploads[messageId];\n const document = new DOMParser().parseFromString(content ?? '', 'text/html');\n document.querySelectorAll('img').forEach((img) => {\n const uploadInlineImage = messageUploads.find(\n (upload) => !upload.metadata.error && upload.metadata.progress === 1 && upload.metadata.id === img.id\n );\n\n if (uploadInlineImage) {\n // ChatSDK uses the respond id provided by the upload response. We store the response id in the image src attribute previously.\n img.id = uploadInlineImage.metadata.url ?? img.id;\n img.src = '';\n }\n });\n content = document.body.innerHTML;\n\n return content;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getImageFileNameFromAttributes = (imageAttributes: Record<string, string>): string => {\n const fileName = imageAttributes[_IMAGE_ATTRIBUTE_INLINE_IMAGE_FILE_NAME_KEY];\n if (!fileName || fileName === '' || fileName === 'undefined' || fileName === 'null') {\n return _DEFAULT_INLINE_IMAGE_FILE_NAME;\n }\n return fileName;\n};\n"]}
|
1
|
+
{"version":3,"file":"ImageUploadUtils.js","sourceRoot":"","sources":["../../../../../../../../react-composites/src/composites/ChatComposite/ImageUpload/ImageUploadUtils.tsx"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;;;;;;;;;AAElC,gEAAgE;AAChE,OAAO,EAAgC,2CAA2C,EAAE,yCAAgC;AACpH,gEAAgE;AAChE,OAAO,EAAoB,0BAA0B,EAAwB,MAAM,kCAAkC,CAAC;AACtH,gEAAgE;AAChE,OAAO,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAOrG,gEAAgE;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,gEAAgE;AAChE,MAAM,+BAA+B,GAAG,EAAE,CAAC;AAE3C,gEAAgE;AAChE,MAAM,aAAa,GAAG,CACpB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CAAC,eAAuC,EAAU,EAAE;IAChG,MAAM,QAAQ,GAAG,eAAe,CAAC,2CAA2C,CAAC,CAAC;IAC9E,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,EAAE,IAAI,QAAQ,KAAK,WAAW,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;QACpF,OAAO,+BAA+B,CAAC;IACzC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { AttachmentMetadataInProgress, _IMAGE_ATTRIBUTE_INLINE_IMAGE_FILE_NAME_KEY } from '@internal/acs-ui-common';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { AttachmentUpload, AttachmentUploadActionType, AttachmentUploadTask } from '../file-sharing/AttachmentUpload';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { _DEFAULT_INLINE_IMAGE_FILE_NAME, SEND_BOX_UPLOADS_KEY_VALUE } from '../../common/constants';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { ChatAdapter } from '../adapter/ChatAdapter';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { Dispatch } from 'react';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { ImageActions } from './ImageUploadReducer';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { nanoid } from 'nanoid';\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nimport { ChatCompositeStrings } from '../Strings';\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nconst MAX_INLINE_IMAGE_UPLOAD_SIZE_MB = 20;\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nconst fetchBlobData = async (\n resource: string | URL | Request,\n options: { timeout?: number; headers?: Headers; abortController: AbortController }\n): Promise<Response> => {\n // default timeout is 30 seconds\n const { timeout = 30000, abortController } = options;\n\n const id = setTimeout(() => {\n abortController.abort();\n }, timeout);\n\n const response = await fetch(resource, {\n ...options,\n signal: abortController.signal\n });\n clearTimeout(id);\n return response;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @private\n */\nexport const getInlineImageData = async (image: string): Promise<Blob | undefined> => {\n if (image.startsWith('blob') || image.startsWith('http')) {\n try {\n const res = await fetchBlobData(image, { abortController: new AbortController() });\n const blobImage = await res.blob();\n return blobImage;\n } catch (error) {\n console.error('Error fetching image data', error);\n return;\n }\n }\n return;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getEditBoxMessagesInlineImages = (\n editBoxInlineImageUploads: Record<string, AttachmentUpload[]> | undefined\n): Record<string, AttachmentMetadataInProgress[]> | undefined => {\n if (!editBoxInlineImageUploads) {\n return;\n }\n const messageIds = Object.keys(editBoxInlineImageUploads || {});\n const messagesInlineImagesWithProgress: Record<string, AttachmentMetadataInProgress[]> = {};\n messageIds.map((messageId) => {\n const messageUploads = editBoxInlineImageUploads[messageId].map((upload) => {\n return upload.metadata;\n });\n messagesInlineImagesWithProgress[messageId] = messageUploads;\n });\n return messagesInlineImagesWithProgress;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getSendBoxInlineImages = (\n sendBoxInlineImageUploads: Record<string, AttachmentUpload[]> | undefined\n): AttachmentMetadataInProgress[] | undefined => {\n if (!sendBoxInlineImageUploads) {\n return;\n }\n return sendBoxInlineImageUploads[SEND_BOX_UPLOADS_KEY_VALUE]?.map((upload) => upload.metadata);\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nconst inlineImageUploadHandler = async (\n uploadTasks: AttachmentUpload[],\n adapter: ChatAdapter,\n strings: ChatCompositeStrings\n): 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(strings.uploadImageDataNotProvided);\n continue;\n }\n if (image && image.size > MAX_INLINE_IMAGE_UPLOAD_SIZE_MB * 1024 * 1024) {\n uploadTask.notifyUploadFailed(\n strings.uploadImageIsTooLarge.replace('{maxImageSize}', `${MAX_INLINE_IMAGE_UPLOAD_SIZE_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(\n strings.uploadImageExtensionIsNotAllowed.replace('{imageExtension}', imageExtension)\n );\n continue;\n }\n\n try {\n const response = await adapter.uploadImage(image, task.metadata?.name);\n // Use response id as the image src because we need to keep the original image id as a reference to find the image.\n // Also the html content we send to ChatSDK does not need image src,\n // it only need the response id to match the uploaded image, url is not needed.\n uploadTask.notifyUploadCompleted(task.metadata.id, response.id);\n } catch (error) {\n console.error(error);\n uploadTask.notifyUploadFailed(strings.uploadImageFailed);\n }\n }\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nconst generateUploadTask = async (\n imageAttributes: Record<string, string>,\n fileName: string,\n messageId: string,\n inlineImageUploadActionHandler: Dispatch<ImageActions>\n): Promise<AttachmentUpload | undefined> => {\n const imageData = await getInlineImageData(imageAttributes.src);\n if (!imageData) {\n return;\n }\n const taskId = nanoid();\n const uploadTask: AttachmentUpload = {\n image: imageData,\n taskId,\n metadata: {\n id: imageAttributes.id,\n name: fileName,\n url: imageAttributes.src,\n progress: 0\n },\n notifyUploadProgressChanged: (value: number) => {\n inlineImageUploadActionHandler({\n type: AttachmentUploadActionType.Progress,\n taskId,\n progress: value,\n messageId\n });\n },\n notifyUploadCompleted: (id: string, url: string) => {\n inlineImageUploadActionHandler({\n type: AttachmentUploadActionType.Completed,\n taskId,\n id,\n url,\n messageId\n });\n },\n notifyUploadFailed: (message: string) => {\n inlineImageUploadActionHandler({ type: AttachmentUploadActionType.Failed, taskId, message, messageId });\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 inlineImageUploadActionHandler({ type: AttachmentUploadActionType.Remove, id: taskId, messageId });\n }, 10 * 1000);\n }\n };\n return uploadTask;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const onInsertInlineImageForEditBox = async (\n imageAttributes: Record<string, string>,\n fileName: string,\n messageId: string,\n adapter: ChatAdapter,\n handleEditBoxInlineImageUploadAction: Dispatch<ImageActions>,\n chatCompositeStrings: ChatCompositeStrings\n): Promise<void> => {\n const uploadTask: AttachmentUpload | undefined = await generateUploadTask(\n imageAttributes,\n fileName,\n messageId,\n handleEditBoxInlineImageUploadAction\n );\n if (!uploadTask) {\n return;\n }\n\n handleEditBoxInlineImageUploadAction({\n type: AttachmentUploadActionType.Set,\n newUploads: [uploadTask],\n messageId\n });\n inlineImageUploadHandler([uploadTask], adapter, chatCompositeStrings);\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const onInsertInlineImageForSendBox = async (\n imageAttributes: Record<string, string>,\n fileName: string,\n adapter: ChatAdapter,\n handleSendBoxInlineImageUploadAction: Dispatch<ImageActions>,\n chatCompositeStrings: ChatCompositeStrings\n): Promise<void> => {\n const uploadTask: AttachmentUpload | undefined = await generateUploadTask(\n imageAttributes,\n fileName,\n SEND_BOX_UPLOADS_KEY_VALUE,\n handleSendBoxInlineImageUploadAction\n );\n\n if (!uploadTask) {\n return;\n }\n\n handleSendBoxInlineImageUploadAction({\n type: AttachmentUploadActionType.Set,\n newUploads: [uploadTask],\n messageId: SEND_BOX_UPLOADS_KEY_VALUE\n });\n inlineImageUploadHandler([uploadTask], adapter, chatCompositeStrings);\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const cancelInlineImageUpload = (\n imageAttributes: Record<string, string>,\n imageUploads: Record<string, AttachmentUpload[]> | undefined,\n messageId: string,\n inlineImageUploadActionHandler: Dispatch<ImageActions>,\n adapter: ChatAdapter\n): void => {\n if (!imageUploads || !imageUploads[messageId]) {\n deleteExistingInlineImageForEditBox(imageAttributes.id, messageId, adapter);\n return;\n }\n const imageUpload = imageUploads[messageId].find((upload) => upload.metadata.id === imageAttributes.id);\n\n if (!imageUpload || !imageUpload?.metadata.id) {\n deleteExistingInlineImageForEditBox(imageAttributes.id, messageId, adapter);\n return;\n }\n\n inlineImageUploadActionHandler({\n type: AttachmentUploadActionType.Remove,\n id: imageUpload?.metadata.id,\n messageId\n });\n\n if (imageUpload?.metadata.progress === 1 && imageUpload?.metadata.url) {\n // The image id that we got back from the ChatSDK response is stored in the image src attribute,\n // while the metadata id is the internal image id that we assigned to the image when it was pasted in.\n deleteInlineImageFromServer(imageUpload?.metadata.url, adapter);\n }\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\nconst deleteInlineImageFromServer = (imageId: string, adapter: ChatAdapter): void => {\n try {\n adapter.deleteImage(imageId);\n } catch (error) {\n console.error(error);\n }\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n// This function is used to delete the inline image that existed before editing starts\nconst deleteExistingInlineImageForEditBox = (imageId: string, messageId: string, adapter: ChatAdapter): void => {\n messageId !== SEND_BOX_UPLOADS_KEY_VALUE && deleteInlineImageFromServer(imageId, adapter);\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const updateContentStringWithUploadedInlineImages = (\n content: string,\n imageUploads: Record<string, AttachmentUpload[]> | undefined,\n messageId: string = SEND_BOX_UPLOADS_KEY_VALUE\n): string => {\n if (!imageUploads || !imageUploads[messageId]) {\n return content;\n }\n const messageUploads = imageUploads[messageId];\n const document = new DOMParser().parseFromString(content ?? '', 'text/html');\n document.querySelectorAll('img').forEach((img) => {\n const uploadInlineImage = messageUploads.find(\n (upload) => !upload.metadata.error && upload.metadata.progress === 1 && upload.metadata.id === img.id\n );\n\n if (uploadInlineImage) {\n // ChatSDK uses the respond id provided by the upload response. We store the response id in the image src attribute previously.\n img.id = uploadInlineImage.metadata.url ?? img.id;\n img.src = '';\n }\n });\n content = document.body.innerHTML;\n\n return content;\n};\n\n/* @conditional-compile-remove(rich-text-editor-image-upload) */\n/**\n * @internal\n */\nexport const getImageFileNameFromAttributes = (imageAttributes: Record<string, string>): string => {\n const fileName = imageAttributes[_IMAGE_ATTRIBUTE_INLINE_IMAGE_FILE_NAME_KEY];\n if (!fileName || fileName === '' || fileName === 'undefined' || fileName === 'null') {\n return _DEFAULT_INLINE_IMAGE_FILE_NAME;\n }\n return fileName;\n};\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@azure/communication-react",
|
3
|
-
"version": "1.19.0-alpha-
|
3
|
+
"version": "1.19.0-alpha-202408070015",
|
4
4
|
"sideEffects": false,
|
5
5
|
"description": "React library for building modern communication user experiences utilizing Azure Communication Services",
|
6
6
|
"keywords": [
|