@azure/communication-react 1.5.1-alpha-202306030013 → 1.5.1-alpha-202306060014
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 +2 -0
- package/dist/dist-cjs/communication-react/index.js +164 -122
- package/dist/dist-cjs/communication-react/index.js.map +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/ChatMessage/ChatMessageComponentAsMessageBubble.js +5 -10
- package/dist/dist-esm/react-components/src/components/ChatMessage/ChatMessageComponentAsMessageBubble.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/FileCard.js +5 -5
- package/dist/dist-esm/react-components/src/components/FileCard.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/FileCardGroup.d.ts +1 -0
- package/dist/dist-esm/react-components/src/components/FileCardGroup.js +2 -2
- package/dist/dist-esm/react-components/src/components/FileCardGroup.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/FileDownloadCards.d.ts +1 -0
- package/dist/dist-esm/react-components/src/components/FileDownloadCards.js +17 -7
- package/dist/dist-esm/react-components/src/components/FileDownloadCards.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/FileUploadCards.js +1 -3
- package/dist/dist-esm/react-components/src/components/FileUploadCards.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/InputBoxComponent.js +94 -74
- package/dist/dist-esm/react-components/src/components/InputBoxComponent.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/MessageThread.d.ts +2 -0
- package/dist/dist-esm/react-components/src/components/MessageThread.js.map +1 -1
- package/dist/dist-esm/react-components/src/components/utils.d.ts +14 -0
- package/dist/dist-esm/react-components/src/components/utils.js +22 -0
- package/dist/dist-esm/react-components/src/components/utils.js.map +1 -1
- package/dist/dist-esm/react-components/src/localization/locales/de-DE/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/en-GB/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/en-US/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/es-ES/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/fr-FR/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/it-IT/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/ja-JP/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/ko-KR/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/nl-NL/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/pt-BR/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/ru-RU/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/tr-TR/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/zh-CN/strings.json +2 -1
- package/dist/dist-esm/react-components/src/localization/locales/zh-TW/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/de-DE/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/en-GB/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/es-ES/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/fr-FR/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/it-IT/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/ja-JP/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/ko-KR/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/nl-NL/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/pt-BR/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/ru-RU/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/tr-TR/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/zh-CN/strings.json +2 -1
- package/dist/dist-esm/react-composites/src/composites/localization/locales/zh-TW/strings.json +2 -1
- package/package.json +8 -8
@@ -17,6 +17,9 @@ import { useLocale } from '../localization';
|
|
17
17
|
/* @conditional-compile-remove(mention) */
|
18
18
|
import { Announcer } from './Announcer';
|
19
19
|
import { Stack, TextField, mergeStyles, concatStyleSets, IconButton, TooltipHost } from '@fluentui/react';
|
20
|
+
import { isEnterKeyEventFromCompositionSession } from './utils';
|
21
|
+
/* @conditional-compile-remove(mention) */
|
22
|
+
import { nullToUndefined, undefinedToNull } from './utils';
|
20
23
|
import { inputBoxStyle, inputBoxWrapperStyle, inputButtonStyle, textFieldStyle, textContainerStyle, newLineButtonsContainerStyle, inputBoxNewLineSpaceAffordance, inputButtonTooltipStyle, iconWrapperStyle } from './styles/InputBoxComponent.style';
|
21
24
|
/* @conditional-compile-remove(mention) */
|
22
25
|
import { Caret } from 'textarea-caret-ts';
|
@@ -53,10 +56,10 @@ export const InputBoxComponent = (props) => {
|
|
53
56
|
const [tagsValue, setTagsValue] = useState([]);
|
54
57
|
/* @conditional-compile-remove(mention) */
|
55
58
|
// Index of the previous selection start in the text field
|
56
|
-
const [selectionStartValue, setSelectionStartValue] = useState(
|
59
|
+
const [selectionStartValue, setSelectionStartValue] = useState();
|
57
60
|
/* @conditional-compile-remove(mention) */
|
58
61
|
// Index of the previous selection end in the text field
|
59
|
-
const [selectionEndValue, setSelectionEndValue] = useState(
|
62
|
+
const [selectionEndValue, setSelectionEndValue] = useState();
|
60
63
|
/* @conditional-compile-remove(mention) */
|
61
64
|
// Boolean value to check if onMouseDown event should be handled during select as selection range
|
62
65
|
// for onMouseDown event is not updated yet and the selection range for mouse click/taps will be
|
@@ -182,33 +185,26 @@ export const InputBoxComponent = (props) => {
|
|
182
185
|
// because its order depends on mouse events not selection.
|
183
186
|
/* @conditional-compile-remove(mention) */
|
184
187
|
setShouldHandleOnMouseDownDuringSelect(false);
|
185
|
-
|
186
|
-
if (ev.nativeEvent.isComposing || ev.nativeEvent.keyCode === 229 || ev.nativeEvent.which === 229) {
|
188
|
+
if (isEnterKeyEventFromCompositionSession(ev)) {
|
187
189
|
return;
|
188
190
|
}
|
189
|
-
|
190
|
-
|
191
|
-
if (
|
191
|
+
/* @conditional-compile-remove(mention) */
|
192
|
+
if (mentionSuggestions.length > 0) {
|
193
|
+
if (ev.key === 'ArrowUp') {
|
192
194
|
ev.preventDefault();
|
193
195
|
const newActiveIndex = activeSuggestionIndex === undefined
|
194
196
|
? mentionSuggestions.length - 1
|
195
197
|
: Math.max(activeSuggestionIndex - 1, 0);
|
196
198
|
setActiveSuggestionIndex(newActiveIndex);
|
197
199
|
}
|
198
|
-
|
199
|
-
else if (ev.key === 'ArrowDown') {
|
200
|
-
/* @conditional-compile-remove(mention) */
|
201
|
-
if (mentionSuggestions.length > 0) {
|
200
|
+
else if (ev.key === 'ArrowDown') {
|
202
201
|
ev.preventDefault();
|
203
202
|
const newActiveIndex = activeSuggestionIndex === undefined
|
204
203
|
? 0
|
205
204
|
: Math.min(activeSuggestionIndex + 1, mentionSuggestions.length - 1);
|
206
205
|
setActiveSuggestionIndex(newActiveIndex);
|
207
206
|
}
|
208
|
-
|
209
|
-
else if (ev.key === 'Escape') {
|
210
|
-
/* @conditional-compile-remove(mention) */
|
211
|
-
if (mentionSuggestions.length > 0) {
|
207
|
+
else if (ev.key === 'Escape') {
|
212
208
|
updateMentionSuggestions([]);
|
213
209
|
}
|
214
210
|
}
|
@@ -257,7 +253,7 @@ export const InputBoxComponent = (props) => {
|
|
257
253
|
}), 500);
|
258
254
|
/* @conditional-compile-remove(mention) */
|
259
255
|
// Update selections index in mention to navigate by words
|
260
|
-
const updateSelectionIndexesWithMentionIfNeeded = useCallback((event, inputTextValue,
|
256
|
+
const updateSelectionIndexesWithMentionIfNeeded = useCallback(({ event, inputTextValue, selectionEndValue, selectionStartValue, tagsValue }) => {
|
261
257
|
var _a, _b, _c;
|
262
258
|
let updatedStartIndex = event.currentTarget.selectionStart;
|
263
259
|
let updatedEndIndex = event.currentTarget.selectionEnd;
|
@@ -324,16 +320,16 @@ export const InputBoxComponent = (props) => {
|
|
324
320
|
else {
|
325
321
|
event.currentTarget.setSelectionRange(updatedStartIndex, updatedEndIndex, event.currentTarget.selectionDirection);
|
326
322
|
}
|
327
|
-
setSelectionStartValue(updatedStartIndex);
|
328
|
-
setSelectionEndValue(updatedEndIndex);
|
323
|
+
setSelectionStartValue(nullToUndefined(updatedStartIndex));
|
324
|
+
setSelectionEndValue(nullToUndefined(updatedEndIndex));
|
329
325
|
}, [setSelectionStartValue, setSelectionEndValue]);
|
330
326
|
/* @conditional-compile-remove(mention) */
|
331
|
-
const handleOnSelect = useCallback((event, inputTextValue, tags, shouldHandleOnMouseDownDuringSelect, selectionStartValue, selectionEndValue) => {
|
327
|
+
const handleOnSelect = useCallback(({ event, inputTextValue, tags, shouldHandleOnMouseDownDuringSelect, selectionStartValue, selectionEndValue }) => {
|
332
328
|
if (shouldHandleOnMouseDownDuringSelect) {
|
333
329
|
if (targetSelection !== undefined) {
|
334
330
|
setSelectionStartValue(targetSelection.start);
|
335
331
|
setSelectionEndValue(targetSelection.end);
|
336
|
-
event.currentTarget.setSelectionRange(targetSelection.start, targetSelection.end);
|
332
|
+
event.currentTarget.setSelectionRange(targetSelection.start, undefinedToNull(targetSelection.end));
|
337
333
|
setTargetSelection(undefined);
|
338
334
|
}
|
339
335
|
else if (event.currentTarget.selectionStart !== null) {
|
@@ -345,7 +341,7 @@ export const InputBoxComponent = (props) => {
|
|
345
341
|
const selectionRange = rangeOfWordInSelection({
|
346
342
|
textInput: inputTextValue,
|
347
343
|
selectionStart: event.currentTarget.selectionStart,
|
348
|
-
selectionEnd: event.currentTarget.selectionEnd,
|
344
|
+
selectionEnd: nullToUndefined(event.currentTarget.selectionEnd),
|
349
345
|
tag: mentionTag
|
350
346
|
});
|
351
347
|
if (event.currentTarget.selectionDirection === null) {
|
@@ -359,13 +355,19 @@ export const InputBoxComponent = (props) => {
|
|
359
355
|
}
|
360
356
|
else {
|
361
357
|
setSelectionStartValue(event.currentTarget.selectionStart);
|
362
|
-
setSelectionEndValue(event.currentTarget.selectionEnd);
|
358
|
+
setSelectionEndValue(nullToUndefined(event.currentTarget.selectionEnd));
|
363
359
|
}
|
364
360
|
}
|
365
361
|
}
|
366
362
|
else {
|
367
363
|
// selection was changed by keyboard
|
368
|
-
updateSelectionIndexesWithMentionIfNeeded(
|
364
|
+
updateSelectionIndexesWithMentionIfNeeded({
|
365
|
+
event,
|
366
|
+
inputTextValue,
|
367
|
+
selectionStartValue,
|
368
|
+
selectionEndValue,
|
369
|
+
tagsValue: tags
|
370
|
+
});
|
369
371
|
}
|
370
372
|
// don't set setShouldHandleOnMouseDownDuringSelect(false) here as setSelectionRange
|
371
373
|
// could trigger additional calls of onSelect event and they may not be handled correctly
|
@@ -378,7 +380,7 @@ export const InputBoxComponent = (props) => {
|
|
378
380
|
setSelectionEndValue
|
379
381
|
]);
|
380
382
|
/* @conditional-compile-remove(mention) */
|
381
|
-
const handleOnChange = useCallback((
|
383
|
+
const handleOnChange = useCallback(({ currentSelectionEnd, currentSelectionStart, currentTriggerStartIndex, event, htmlTextValue, inputTextValue, previousSelectionEnd, previousSelectionStart, tagsValue, updatedValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
382
384
|
var _b;
|
383
385
|
debouncedQueryUpdate.cancel();
|
384
386
|
if (event.currentTarget === null) {
|
@@ -479,7 +481,7 @@ export const InputBoxComponent = (props) => {
|
|
479
481
|
});
|
480
482
|
result = updatedContent.updatedHTML;
|
481
483
|
// update caret index if needed
|
482
|
-
if (updatedContent.updatedSelectionIndex !==
|
484
|
+
if (updatedContent.updatedSelectionIndex !== undefined) {
|
483
485
|
setCaretIndex(updatedContent.updatedSelectionIndex);
|
484
486
|
setSelectionEndValue(updatedContent.updatedSelectionIndex);
|
485
487
|
setSelectionStartValue(updatedContent.updatedSelectionIndex);
|
@@ -548,7 +550,18 @@ export const InputBoxComponent = (props) => {
|
|
548
550
|
/* @conditional-compile-remove(mention) */
|
549
551
|
setInputTextValue(newValue !== null && newValue !== void 0 ? newValue : '');
|
550
552
|
/* @conditional-compile-remove(mention) */
|
551
|
-
handleOnChange(
|
553
|
+
handleOnChange({
|
554
|
+
event: e,
|
555
|
+
tagsValue,
|
556
|
+
htmlTextValue: textValue,
|
557
|
+
inputTextValue,
|
558
|
+
currentTriggerStartIndex,
|
559
|
+
previousSelectionStart: nullToUndefined(selectionStartValue),
|
560
|
+
previousSelectionEnd: nullToUndefined(selectionEndValue),
|
561
|
+
currentSelectionStart: nullToUndefined(e.currentTarget.selectionStart),
|
562
|
+
currentSelectionEnd: nullToUndefined(e.currentTarget.selectionEnd),
|
563
|
+
updatedValue: newValue
|
564
|
+
});
|
552
565
|
/* @conditional-compile-remove(mention) */
|
553
566
|
return;
|
554
567
|
onChange(e, newValue);
|
@@ -564,7 +577,14 @@ export const InputBoxComponent = (props) => {
|
|
564
577
|
}
|
565
578
|
return;
|
566
579
|
}
|
567
|
-
handleOnSelect(
|
580
|
+
handleOnSelect({
|
581
|
+
event: e,
|
582
|
+
inputTextValue,
|
583
|
+
shouldHandleOnMouseDownDuringSelect,
|
584
|
+
selectionEndValue,
|
585
|
+
selectionStartValue,
|
586
|
+
tags: tagsValue
|
587
|
+
});
|
568
588
|
},
|
569
589
|
/* @conditional-compile-remove(mention) */
|
570
590
|
onMouseDown: (e) => {
|
@@ -602,8 +622,8 @@ export const InputBoxComponent = (props) => {
|
|
602
622
|
// setup all flags to default values when text field loses focus
|
603
623
|
setShouldHandleOnMouseDownDuringSelect(false);
|
604
624
|
setCaretIndex(undefined);
|
605
|
-
setSelectionStartValue(
|
606
|
-
setSelectionEndValue(
|
625
|
+
setSelectionStartValue(undefined);
|
626
|
+
setSelectionEndValue(undefined);
|
607
627
|
// Dismiss the suggestions on blur, after enough time to select by mouse if needed
|
608
628
|
setTimeout(() => {
|
609
629
|
setMentionSuggestions([]);
|
@@ -660,12 +680,11 @@ const getValidatedIndexInRange = (props) => {
|
|
660
680
|
*/
|
661
681
|
const findMentionTagForSelection = (tags, selection) => {
|
662
682
|
let mentionTag = undefined;
|
663
|
-
|
664
|
-
const tag = tags[i];
|
683
|
+
tags.every((tag) => {
|
665
684
|
const closingTagInfo = getTagClosingTagInfo(tag);
|
666
685
|
if (tag.plainTextBeginIndex !== undefined && tag.plainTextBeginIndex > selection) {
|
667
686
|
// no need to check further as the selection is before the tag
|
668
|
-
|
687
|
+
return false;
|
669
688
|
}
|
670
689
|
else if (tag.plainTextBeginIndex !== undefined &&
|
671
690
|
tag.plainTextBeginIndex <= selection &&
|
@@ -675,27 +694,28 @@ const findMentionTagForSelection = (tags, selection) => {
|
|
675
694
|
const selectedTag = findMentionTagForSelection(tag.subTags, selection);
|
676
695
|
if (selectedTag !== undefined) {
|
677
696
|
mentionTag = selectedTag;
|
678
|
-
|
697
|
+
return false;
|
679
698
|
}
|
680
699
|
}
|
681
700
|
else if (tag.tagType === MSFT_MENTION_TAG) {
|
682
701
|
mentionTag = tag;
|
683
|
-
|
702
|
+
return false;
|
684
703
|
}
|
685
704
|
}
|
686
|
-
|
705
|
+
return true;
|
706
|
+
});
|
687
707
|
return mentionTag;
|
688
708
|
};
|
689
709
|
/* @conditional-compile-remove(mention) */
|
690
710
|
const rangeOfWordInSelection = ({ textInput, selectionStart, selectionEnd, tag }) => {
|
691
711
|
var _a;
|
692
712
|
if (tag.plainTextBeginIndex === undefined) {
|
693
|
-
return { start: selectionStart, end: selectionEnd ===
|
713
|
+
return { start: selectionStart, end: selectionEnd === undefined ? selectionStart : selectionEnd };
|
694
714
|
}
|
695
715
|
// Look at start word index and optionally end word index.
|
696
716
|
// Select combination of the two and return the range.
|
697
717
|
let start = selectionStart;
|
698
|
-
let end = selectionEnd ===
|
718
|
+
let end = selectionEnd === undefined ? selectionStart : selectionEnd;
|
699
719
|
const firstWordStartIndex = textInput.lastIndexOf(' ', selectionStart);
|
700
720
|
if (firstWordStartIndex === tag.plainTextBeginIndex) {
|
701
721
|
start = firstWordStartIndex;
|
@@ -705,7 +725,7 @@ const rangeOfWordInSelection = ({ textInput, selectionStart, selectionEnd, tag }
|
|
705
725
|
}
|
706
726
|
const firstWordEndIndex = textInput.indexOf(' ', selectionStart);
|
707
727
|
end = Math.max(firstWordEndIndex + 1, (_a = tag.plainTextEndIndex) !== null && _a !== void 0 ? _a : firstWordEndIndex + 1);
|
708
|
-
if (selectionEnd !==
|
728
|
+
if (selectionEnd !== undefined && tag.plainTextEndIndex !== undefined) {
|
709
729
|
const lastWordEndIndex = textInput.indexOf(' ', selectionEnd);
|
710
730
|
end = Math.max(lastWordEndIndex > -1 ? lastWordEndIndex : tag.plainTextEndIndex, selectionEnd);
|
711
731
|
}
|
@@ -768,11 +788,11 @@ const handleMentionTagUpdate = (props) => {
|
|
768
788
|
result: '',
|
769
789
|
updatedChange: processedChange,
|
770
790
|
htmlIndex: lastProcessedHTMLIndex,
|
771
|
-
plainTextSelectionEndIndex:
|
791
|
+
plainTextSelectionEndIndex: undefined
|
772
792
|
};
|
773
793
|
}
|
774
794
|
let result = '';
|
775
|
-
let plainTextSelectionEndIndex
|
795
|
+
let plainTextSelectionEndIndex;
|
776
796
|
let rangeStart;
|
777
797
|
let rangeEnd;
|
778
798
|
// check if space symbol is handled in case if string looks like '<1 2 3>'
|
@@ -801,7 +821,7 @@ const handleMentionTagUpdate = (props) => {
|
|
801
821
|
}
|
802
822
|
if (rangeStart === tag.plainTextBeginIndex && rangeEnd === plainTextEndIndex) {
|
803
823
|
// the whole tag should be removed
|
804
|
-
result += htmlText.substring(lastProcessedHTMLIndex, tag.
|
824
|
+
result += htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex) + processedChange;
|
805
825
|
plainTextSelectionEndIndex = tag.plainTextBeginIndex + processedChange.length;
|
806
826
|
processedChange = '';
|
807
827
|
lastProcessedHTMLIndex = closeTagIdx + closeTagLength;
|
@@ -815,7 +835,7 @@ const handleMentionTagUpdate = (props) => {
|
|
815
835
|
startChangeDiff = rangeStart - tag.plainTextBeginIndex - mentionTagLength;
|
816
836
|
}
|
817
837
|
endChangeDiff = rangeEnd - tag.plainTextBeginIndex - mentionTagLength;
|
818
|
-
result += htmlText.substring(lastProcessedHTMLIndex, tag.
|
838
|
+
result += htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex + tag.openTagBody.length + startChangeDiff);
|
819
839
|
if (startIndex < tag.plainTextBeginIndex) {
|
820
840
|
// if the change is before the tag, the selection should start from startIndex (rangeStart will be equal to tag.plainTextBeginIndex)
|
821
841
|
plainTextSelectionEndIndex = startIndex + change.length;
|
@@ -824,7 +844,7 @@ const handleMentionTagUpdate = (props) => {
|
|
824
844
|
// if the change is inside the tag, the selection should start with rangeStart
|
825
845
|
plainTextSelectionEndIndex = rangeStart + processedChange.length;
|
826
846
|
}
|
827
|
-
lastProcessedHTMLIndex = tag.
|
847
|
+
lastProcessedHTMLIndex = tag.openTagIndex + tag.openTagBody.length + endChangeDiff;
|
828
848
|
// processed change should not be changed as it should be added after the tag
|
829
849
|
}
|
830
850
|
return { result, updatedChange: processedChange, htmlIndex: lastProcessedHTMLIndex, plainTextSelectionEndIndex };
|
@@ -841,17 +861,17 @@ const getTagClosingTagInfo = (tag) => {
|
|
841
861
|
let plainTextEndIndex = 0;
|
842
862
|
let closeTagIdx = 0;
|
843
863
|
let closeTagLength = 0;
|
844
|
-
if (tag.plainTextEndIndex !== undefined && tag.
|
864
|
+
if (tag.plainTextEndIndex !== undefined && tag.closingTagIndex !== undefined) {
|
845
865
|
// close tag exists
|
846
866
|
plainTextEndIndex = tag.plainTextEndIndex;
|
847
|
-
closeTagIdx = tag.
|
867
|
+
closeTagIdx = tag.closingTagIndex;
|
848
868
|
// tag.tagType.length + </>
|
849
869
|
closeTagLength = tag.tagType.length + 3;
|
850
870
|
}
|
851
871
|
else if (tag.plainTextBeginIndex !== undefined) {
|
852
872
|
// no close tag
|
853
873
|
plainTextEndIndex = tag.plainTextBeginIndex;
|
854
|
-
closeTagIdx = tag.
|
874
|
+
closeTagIdx = tag.openTagIndex + tag.openTagBody.length;
|
855
875
|
closeTagLength = 0;
|
856
876
|
}
|
857
877
|
return { plainTextEndIndex, closeTagIdx, closeTagLength };
|
@@ -868,7 +888,7 @@ const updateHTML = (props) => {
|
|
868
888
|
const { htmlText, oldPlainText, newPlainText, tags, startIndex, oldPlainTextEndIndex, change, mentionTrigger } = props;
|
869
889
|
if (tags.length === 0 || (startIndex === 0 && oldPlainTextEndIndex === oldPlainText.length - 1)) {
|
870
890
|
// no tags added yet or the whole text is changed
|
871
|
-
return { updatedHTML: newPlainText, updatedSelectionIndex:
|
891
|
+
return { updatedHTML: newPlainText, updatedSelectionIndex: undefined };
|
872
892
|
}
|
873
893
|
let result = '';
|
874
894
|
let lastProcessedHTMLIndex = 0;
|
@@ -882,7 +902,7 @@ const updateHTML = (props) => {
|
|
882
902
|
// end tag plain text index of the last processed tag
|
883
903
|
let lastProcessedPlainTextTagEndIndex = 0;
|
884
904
|
// as some tags/text can be removed fully, selection should be updated correctly
|
885
|
-
let changeNewEndIndex
|
905
|
+
let changeNewEndIndex;
|
886
906
|
for (let i = 0; i < tags.length; i++) {
|
887
907
|
const tag = tags[i];
|
888
908
|
if (tag.plainTextBeginIndex === undefined) {
|
@@ -901,19 +921,19 @@ const updateHTML = (props) => {
|
|
901
921
|
// change start is before the open tag
|
902
922
|
// Math.max(lastProcessedPlainTextTagEndIndex, startIndex) is used as startIndex may not be in [[previous tag].plainTextEndIndex - tag.plainTextBeginIndex] range
|
903
923
|
const startChangeDiff = tag.plainTextBeginIndex - Math.max(lastProcessedPlainTextTagEndIndex, startIndex);
|
904
|
-
result += htmlText.substring(lastProcessedHTMLIndex, tag.
|
924
|
+
result += htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex - startChangeDiff) + processedChange;
|
905
925
|
processedChange = '';
|
906
926
|
if (oldPlainTextEndIndex <= tag.plainTextBeginIndex) {
|
907
927
|
// the whole change is before tag start
|
908
928
|
// mentionTag length can be ignored here as the change is before the tag
|
909
929
|
const endChangeDiff = tag.plainTextBeginIndex - oldPlainTextEndIndex;
|
910
|
-
lastProcessedHTMLIndex = tag.
|
930
|
+
lastProcessedHTMLIndex = tag.openTagIndex - endChangeDiff;
|
911
931
|
// the change is handled; exit
|
912
932
|
break;
|
913
933
|
}
|
914
934
|
else {
|
915
935
|
// change continues in the tag
|
916
|
-
lastProcessedHTMLIndex = tag.
|
936
|
+
lastProcessedHTMLIndex = tag.openTagIndex;
|
917
937
|
// proceed to the next check
|
918
938
|
}
|
919
939
|
}
|
@@ -922,8 +942,8 @@ const updateHTML = (props) => {
|
|
922
942
|
// change started before the end tag
|
923
943
|
if (startIndex <= tag.plainTextBeginIndex && oldPlainTextEndIndex === closingTagInfo.plainTextEndIndex) {
|
924
944
|
// the change is a tag or starts before the tag
|
925
|
-
// tag should be removed, no matter if there are
|
926
|
-
result += htmlText.substring(lastProcessedHTMLIndex, tag.
|
945
|
+
// tag should be removed, no matter if there are sub-tags
|
946
|
+
result += htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex) + processedChange;
|
927
947
|
processedChange = '';
|
928
948
|
lastProcessedHTMLIndex = closingTagInfo.closeTagIdx + closingTagInfo.closeTagLength;
|
929
949
|
// the change is handled; exit
|
@@ -935,15 +955,15 @@ const updateHTML = (props) => {
|
|
935
955
|
if (change !== '') {
|
936
956
|
if (startIndex !== tag.plainTextBeginIndex && startIndex !== closingTagInfo.plainTextEndIndex) {
|
937
957
|
// mention tag should be deleted when user tries to edit it in the middle
|
938
|
-
result += htmlText.substring(lastProcessedHTMLIndex, tag.
|
958
|
+
result += htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex) + processedChange;
|
939
959
|
changeNewEndIndex = tag.plainTextBeginIndex + processedChange.length;
|
940
960
|
lastProcessedHTMLIndex = closingTagInfo.closeTagIdx + closingTagInfo.closeTagLength;
|
941
961
|
}
|
942
962
|
else if (startIndex === tag.plainTextBeginIndex) {
|
943
963
|
// non empty change at the beginning of the mention tag to be added before the mention tag
|
944
|
-
result += htmlText.substring(lastProcessedHTMLIndex, tag.
|
964
|
+
result += htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex) + processedChange;
|
945
965
|
changeNewEndIndex = tag.plainTextBeginIndex + processedChange.length;
|
946
|
-
lastProcessedHTMLIndex = tag.
|
966
|
+
lastProcessedHTMLIndex = tag.openTagIndex;
|
947
967
|
}
|
948
968
|
else if (startIndex === closingTagInfo.plainTextEndIndex) {
|
949
969
|
// non empty change at the end of the mention tag to be added after the mention tag
|
@@ -978,7 +998,7 @@ const updateHTML = (props) => {
|
|
978
998
|
}
|
979
999
|
else if (tag.subTags !== undefined && tag.subTags.length !== 0 && tag.content !== undefined) {
|
980
1000
|
// with subtags
|
981
|
-
const stringBefore = htmlText.substring(lastProcessedHTMLIndex, tag.
|
1001
|
+
const stringBefore = htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex + tag.openTagBody.length);
|
982
1002
|
lastProcessedHTMLIndex = closingTagInfo.closeTagIdx;
|
983
1003
|
const updatedContent = updateHTML({
|
984
1004
|
htmlText: tag.content,
|
@@ -997,12 +1017,12 @@ const updateHTML = (props) => {
|
|
997
1017
|
// no subtags
|
998
1018
|
const startChangeDiff = startIndex - tag.plainTextBeginIndex;
|
999
1019
|
result +=
|
1000
|
-
htmlText.substring(lastProcessedHTMLIndex, tag.
|
1020
|
+
htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex + tag.openTagBody.length + startChangeDiff) +
|
1001
1021
|
processedChange;
|
1002
1022
|
processedChange = '';
|
1003
1023
|
if (oldPlainTextEndIndex < closingTagInfo.plainTextEndIndex) {
|
1004
1024
|
const endChangeDiff = oldPlainTextEndIndex - tag.plainTextBeginIndex;
|
1005
|
-
lastProcessedHTMLIndex = tag.
|
1025
|
+
lastProcessedHTMLIndex = tag.openTagIndex + tag.openTagBody.length + endChangeDiff;
|
1006
1026
|
}
|
1007
1027
|
else if (oldPlainTextEndIndex === closingTagInfo.plainTextEndIndex) {
|
1008
1028
|
lastProcessedHTMLIndex = closingTagInfo.closeTagIdx;
|
@@ -1035,7 +1055,7 @@ const updateHTML = (props) => {
|
|
1035
1055
|
}
|
1036
1056
|
else if (tag.subTags !== undefined && tag.subTags.length !== 0 && tag.content !== undefined) {
|
1037
1057
|
// with subtags
|
1038
|
-
const stringBefore = htmlText.substring(lastProcessedHTMLIndex, tag.
|
1058
|
+
const stringBefore = htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex + tag.openTagBody.length);
|
1039
1059
|
lastProcessedHTMLIndex = closingTagInfo.closeTagIdx;
|
1040
1060
|
const updatedContent = updateHTML({
|
1041
1061
|
htmlText: tag.content,
|
@@ -1051,7 +1071,7 @@ const updateHTML = (props) => {
|
|
1051
1071
|
}
|
1052
1072
|
else {
|
1053
1073
|
// no subtags
|
1054
|
-
result += htmlText.substring(lastProcessedHTMLIndex, tag.
|
1074
|
+
result += htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex + tag.openTagBody.length + startChangeDiff);
|
1055
1075
|
lastProcessedHTMLIndex = closingTagInfo.closeTagIdx;
|
1056
1076
|
}
|
1057
1077
|
// proceed with the next calculations
|
@@ -1066,7 +1086,7 @@ const updateHTML = (props) => {
|
|
1066
1086
|
else if (startIndex === tag.plainTextBeginIndex && oldPlainTextEndIndex > closingTagInfo.plainTextEndIndex) {
|
1067
1087
|
// the change starts in the tag and finishes after it
|
1068
1088
|
// tag should be removed, no matter if there are subtags
|
1069
|
-
result += htmlText.substring(lastProcessedHTMLIndex, tag.
|
1089
|
+
result += htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex);
|
1070
1090
|
// processedChange shouldn't be updated as it will be added after the tag
|
1071
1091
|
lastProcessedHTMLIndex = closingTagInfo.closeTagIdx + closingTagInfo.closeTagLength;
|
1072
1092
|
// proceed with the next calculations
|
@@ -1095,7 +1115,7 @@ const updateHTML = (props) => {
|
|
1095
1115
|
}
|
1096
1116
|
else if (tag.subTags !== undefined && tag.subTags.length !== 0 && tag.content !== undefined) {
|
1097
1117
|
// with subtags
|
1098
|
-
const stringBefore = htmlText.substring(lastProcessedHTMLIndex, tag.
|
1118
|
+
const stringBefore = htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex + tag.openTagBody.length);
|
1099
1119
|
lastProcessedHTMLIndex = closingTagInfo.closeTagIdx;
|
1100
1120
|
const updatedContent = updateHTML({
|
1101
1121
|
htmlText: tag.content,
|
@@ -1113,7 +1133,7 @@ const updateHTML = (props) => {
|
|
1113
1133
|
else {
|
1114
1134
|
// no subtags
|
1115
1135
|
result +=
|
1116
|
-
htmlText.substring(lastProcessedHTMLIndex, tag.
|
1136
|
+
htmlText.substring(lastProcessedHTMLIndex, tag.openTagIndex + tag.openTagBody.length) + processedChange;
|
1117
1137
|
processedChange = '';
|
1118
1138
|
// oldPlainTextEndIndex already includes mentionTag length
|
1119
1139
|
const endChangeDiff = closingTagInfo.plainTextEndIndex - oldPlainTextEndIndex;
|
@@ -1312,7 +1332,7 @@ const textToTagParser = (text, trigger) => {
|
|
1312
1332
|
const closeTagType = foundHtmlTag.content.substring(2, foundHtmlTag.content.length - 1).toLowerCase();
|
1313
1333
|
if (currentOpenTag && currentOpenTag.tagType === closeTagType) {
|
1314
1334
|
// Tag startIdx is absolute to the text. This is updated later to be relative to the parent tag
|
1315
|
-
currentOpenTag.content = text.substring(currentOpenTag.
|
1335
|
+
currentOpenTag.content = text.substring(currentOpenTag.openTagIndex + currentOpenTag.openTagBody.length, foundHtmlTag.startIdx);
|
1316
1336
|
// Insert the plain text pieces for the sub tags
|
1317
1337
|
if (currentOpenTag.tagType === MSFT_MENTION_TAG) {
|
1318
1338
|
plainTextRepresentation =
|
@@ -1326,7 +1346,7 @@ const textToTagParser = (text, trigger) => {
|
|
1326
1346
|
else if (currentOpenTag.subTags.length > 0) {
|
1327
1347
|
// Add text after the last tag
|
1328
1348
|
const lastSubTag = currentOpenTag.subTags[currentOpenTag.subTags.length - 1];
|
1329
|
-
const startOfRemainingText = ((_a = lastSubTag.
|
1349
|
+
const startOfRemainingText = ((_a = lastSubTag.closingTagIndex) !== null && _a !== void 0 ? _a : lastSubTag.openTagIndex) + lastSubTag.tagType.length + 3;
|
1330
1350
|
const trailingText = currentOpenTag.content.substring(startOfRemainingText);
|
1331
1351
|
plainTextRepresentation += trailingText;
|
1332
1352
|
}
|
@@ -1334,7 +1354,7 @@ const textToTagParser = (text, trigger) => {
|
|
1334
1354
|
addTag(currentOpenTag, tagParseStack, tags);
|
1335
1355
|
}
|
1336
1356
|
else {
|
1337
|
-
|
1357
|
+
throw new Error('Unexpected close tag found. Got "' +
|
1338
1358
|
closeTagType +
|
1339
1359
|
'" but expected "' +
|
1340
1360
|
((_b = tagParseStack[tagParseStack.length - 1]) === null || _b === void 0 ? void 0 : _b.tagType) +
|
@@ -1355,7 +1375,7 @@ const parseOpenTag = (tag, startIdx) => {
|
|
1355
1375
|
.replace('/', '');
|
1356
1376
|
return {
|
1357
1377
|
tagType,
|
1358
|
-
|
1378
|
+
openTagIndex: startIdx,
|
1359
1379
|
openTagBody: tag
|
1360
1380
|
};
|
1361
1381
|
};
|
@@ -1392,18 +1412,18 @@ const addTag = (tag, parseStack, tags) => {
|
|
1392
1412
|
const parentTag = parseStack[parseStack.length - 1];
|
1393
1413
|
if (parentTag) {
|
1394
1414
|
// Adjust the open tag index to be relative to the parent tag
|
1395
|
-
const parentContentStartIdx = parentTag.
|
1396
|
-
const relativeIdx = tag.
|
1397
|
-
tag.
|
1415
|
+
const parentContentStartIdx = parentTag.openTagIndex + parentTag.openTagBody.length;
|
1416
|
+
const relativeIdx = tag.openTagIndex - parentContentStartIdx;
|
1417
|
+
tag.openTagIndex = relativeIdx;
|
1398
1418
|
}
|
1399
|
-
if (!tag.
|
1419
|
+
if (!tag.closingTagIndex) {
|
1400
1420
|
// If the tag is self-closing, the close tag is the same as the open tag
|
1401
1421
|
if (tag.openTagBody[tag.openTagBody.length - 2] === '/') {
|
1402
|
-
tag.
|
1422
|
+
tag.closingTagIndex = tag.openTagIndex;
|
1403
1423
|
}
|
1404
1424
|
else {
|
1405
1425
|
// Otherwise, the close tag index is the open tag index + the open tag body + the content length
|
1406
|
-
tag.
|
1426
|
+
tag.closingTagIndex = tag.openTagIndex + tag.openTagBody.length + ((_a = tag.content) !== null && _a !== void 0 ? _a : []).length;
|
1407
1427
|
}
|
1408
1428
|
}
|
1409
1429
|
// Put the tag where it belongs
|