UNPKG

matrix-react-sdk

Version:
837 lines (823 loc) 138 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.REGEX_EMOTICON = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _classnames = _interopRequireDefault(require("classnames")); var _react = _interopRequireWildcard(require("react")); var _emoticon = _interopRequireDefault(require("emojibase-regex/emoticon")); var _logger = require("matrix-js-sdk/src/logger"); var _emojibaseBindings = require("@matrix-org/emojibase-bindings"); var _history = _interopRequireDefault(require("../../../editor/history")); var _caret = require("../../../editor/caret"); var _operations = require("../../../editor/operations"); var _dom = require("../../../editor/dom"); var _Autocomplete = _interopRequireWildcard(require("../rooms/Autocomplete")); var _parts = require("../../../editor/parts"); var _deserialize = require("../../../editor/deserialize"); var _render = require("../../../editor/render"); var _SettingsStore = _interopRequireDefault(require("../../../settings/SettingsStore")); var _Keyboard = require("../../../Keyboard"); var _SlashCommands = require("../../../SlashCommands"); var _range = _interopRequireDefault(require("../../../editor/range")); var _MessageComposerFormatBar = _interopRequireWildcard(require("./MessageComposerFormatBar")); var _KeyBindingsManager = require("../../../KeyBindingsManager"); var _KeyboardShortcuts = require("../../../accessibility/KeyboardShortcuts"); var _languageHandler = require("../../../languageHandler"); var _linkifyMatrix = require("../../../linkify-matrix"); var _SDKContext = require("../../../contexts/SDKContext"); var _MatrixClientPeg = require("../../../MatrixClientPeg"); var _LandmarkNavigation = require("../../../accessibility/LandmarkNavigation"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /* Copyright 2024 New Vector Ltd. Copyright 2019-2021 The Matrix.org Foundation C.I.C. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ // matches emoticons which follow the start of a line or whitespace const REGEX_EMOTICON_WHITESPACE = new RegExp("(?:^|\\s)(" + _emoticon.default.source + ")\\s|:^$"); const REGEX_EMOTICON = exports.REGEX_EMOTICON = new RegExp("(?:^|\\s)(" + _emoticon.default.source + ")$"); const SURROUND_WITH_CHARACTERS = ['"', "_", "`", "'", "*", "~", "$"]; const SURROUND_WITH_DOUBLE_CHARACTERS = new Map([["(", ")"], ["[", "]"], ["{", "}"], ["<", ">"]]); function ctrlShortcutLabel(key, needsShift = false, needsAlt = false) { return (_Keyboard.IS_MAC ? "⌘" : (0, _languageHandler._t)(_KeyboardShortcuts.ALTERNATE_KEY_NAME[_Keyboard.Key.CONTROL])) + (needsShift ? "+" + (0, _languageHandler._t)(_KeyboardShortcuts.ALTERNATE_KEY_NAME[_Keyboard.Key.SHIFT]) : "") + (needsAlt ? "+" + (0, _languageHandler._t)(_KeyboardShortcuts.ALTERNATE_KEY_NAME[_Keyboard.Key.ALT]) : "") + "+" + key; } function cloneSelection(selection) { return { anchorNode: selection.anchorNode, anchorOffset: selection.anchorOffset, focusNode: selection.focusNode, focusOffset: selection.focusOffset, isCollapsed: selection.isCollapsed, rangeCount: selection.rangeCount, type: selection.type }; } function selectionEquals(a, b) { return a.anchorNode === b.anchorNode && a.anchorOffset === b.anchorOffset && a.focusNode === b.focusNode && a.focusOffset === b.focusOffset && a.isCollapsed === b.isCollapsed && a.rangeCount === b.rangeCount && a.type === b.type; } class BasicMessageEditor extends _react.default.Component { constructor(props) { super(props); (0, _defineProperty2.default)(this, "editorRef", /*#__PURE__*/(0, _react.createRef)()); (0, _defineProperty2.default)(this, "autocompleteRef", /*#__PURE__*/(0, _react.createRef)()); (0, _defineProperty2.default)(this, "formatBarRef", /*#__PURE__*/(0, _react.createRef)()); (0, _defineProperty2.default)(this, "modifiedFlag", false); (0, _defineProperty2.default)(this, "isIMEComposing", false); (0, _defineProperty2.default)(this, "hasTextSelected", false); (0, _defineProperty2.default)(this, "isSafari", void 0); (0, _defineProperty2.default)(this, "_isCaretAtEnd", false); (0, _defineProperty2.default)(this, "lastCaret", void 0); (0, _defineProperty2.default)(this, "lastSelection", null); (0, _defineProperty2.default)(this, "useMarkdownHandle", void 0); (0, _defineProperty2.default)(this, "emoticonSettingHandle", void 0); (0, _defineProperty2.default)(this, "shouldShowPillAvatarSettingHandle", void 0); (0, _defineProperty2.default)(this, "surroundWithHandle", void 0); (0, _defineProperty2.default)(this, "historyManager", new _history.default()); (0, _defineProperty2.default)(this, "updateEditorState", (selection, inputType, diff) => { if (!this.editorRef.current) return; (0, _render.renderModel)(this.editorRef.current, this.props.model); if (selection) { // set the caret/selection try { (0, _caret.setSelection)(this.editorRef.current, this.props.model, selection); } catch (err) { _logger.logger.error(err); } // if caret selection is a range, take the end position const position = selection instanceof _range.default ? selection.end : selection; this.setLastCaretFromPosition(position); } const { isEmpty } = this.props.model; if (this.props.placeholder) { if (isEmpty) { this.showPlaceholder(); } else { this.hidePlaceholder(); } } if (isEmpty) { this.formatBarRef.current?.hide(); } this.setState({ autoComplete: this.props.model.autoComplete ?? undefined, // if a change is happening then clear the showVisualBell showVisualBell: diff ? false : this.state.showVisualBell }); this.historyManager.tryPush(this.props.model, selection, inputType, diff); // inputType is falsy during initial mount, don't consider re-loading the draft as typing let isTyping = !this.props.model.isEmpty && !!inputType; // If the user is entering a command, only consider them typing if it is one which sends a message into the room if (isTyping && this.props.model.parts[0].type === "command") { const { cmd } = (0, _SlashCommands.parseCommandString)(this.props.model.parts[0].text); const command = _SlashCommands.CommandMap.get(cmd); if (!command?.isEnabled(_MatrixClientPeg.MatrixClientPeg.get()) || command.category !== _SlashCommands.CommandCategories.messages) { isTyping = false; } } _SDKContext.SdkContextClass.instance.typingStore.setSelfTyping(this.props.room.roomId, this.props.threadId ?? null, isTyping); this.props.onChange?.(selection, inputType, diff); }); (0, _defineProperty2.default)(this, "onCompositionStart", () => { this.isIMEComposing = true; // even if the model is empty, the composition text shouldn't be mixed with the placeholder this.hidePlaceholder(); }); (0, _defineProperty2.default)(this, "onCompositionEnd", () => { this.isIMEComposing = false; // some browsers (Chrome) don't fire an input event after ending a composition, // so trigger a model update after the composition is done by calling the input handler. // however, modifying the DOM (caused by the editor model update) from the compositionend handler seems // to confuse the IME in Chrome, likely causing https://github.com/vector-im/element-web/issues/10913 , // so we do it async // however, doing this async seems to break things in Safari for some reason, so browser sniff. if (this.isSafari) { this.onInput({ inputType: "insertCompositionText" }); } else { Promise.resolve().then(() => { this.onInput({ inputType: "insertCompositionText" }); }); } }); (0, _defineProperty2.default)(this, "onCutCopy", (event, type) => { const selection = document.getSelection(); const text = selection.toString(); if (text && this.editorRef.current) { const { model } = this.props; const range = (0, _dom.getRangeForSelection)(this.editorRef.current, model, selection); const selectedParts = range.parts.map(p => p.serialize()); event.clipboardData.setData("application/x-element-composer", JSON.stringify(selectedParts)); event.clipboardData.setData("text/plain", text); // so plain copy/paste works if (type === "cut") { // Remove the text, updating the model as appropriate this.modifiedFlag = true; (0, _operations.replaceRangeAndMoveCaret)(range, []); } event.preventDefault(); } }); (0, _defineProperty2.default)(this, "onCopy", event => { this.onCutCopy(event, "copy"); }); (0, _defineProperty2.default)(this, "onCut", event => { this.onCutCopy(event, "cut"); }); (0, _defineProperty2.default)(this, "onPasteHandler", (event, data) => { event.preventDefault(); // we always handle the paste ourselves if (!this.editorRef.current) return; if (this.props.onPaste?.(event, data, this.props.model)) { // to prevent double handling, allow props.onPaste to skip internal onPaste return true; } const { model } = this.props; const { partCreator } = model; const plainText = data.getData("text/plain"); const partsText = data.getData("application/x-element-composer"); let parts; if (partsText) { const serializedTextParts = JSON.parse(partsText); parts = serializedTextParts.map(p => partCreator.deserializePart(p)); } else { parts = (0, _deserialize.parsePlainTextMessage)(plainText, partCreator, { shouldEscape: false }); } this.modifiedFlag = true; const range = (0, _dom.getRangeForSelection)(this.editorRef.current, model, document.getSelection()); // If the user is pasting a link, and has a range selected which is not a link, wrap the range with the link if (plainText && range.length > 0 && _linkifyMatrix.linkify.test(plainText) && !_linkifyMatrix.linkify.test(range.text)) { (0, _operations.formatRangeAsLink)(range, plainText); } else { (0, _operations.replaceRangeAndMoveCaret)(range, parts); } }); (0, _defineProperty2.default)(this, "onPaste", event => { return this.onPasteHandler(event, event.clipboardData); }); (0, _defineProperty2.default)(this, "onBeforeInput", event => { // ignore any input while doing IME compositions if (this.isIMEComposing) { return; } if (event.inputType === "insertFromPaste" && event.dataTransfer) { this.onPasteHandler(event, event.dataTransfer); } }); (0, _defineProperty2.default)(this, "onInput", event => { if (!this.editorRef.current) return; // ignore any input while doing IME compositions if (this.isIMEComposing) { return; } this.modifiedFlag = true; const sel = document.getSelection(); const { caret, text } = (0, _dom.getCaretOffsetAndText)(this.editorRef.current, sel); this.props.model.update(text, event.inputType, caret); }); (0, _defineProperty2.default)(this, "onBlur", () => { document.removeEventListener("selectionchange", this.onSelectionChange); }); (0, _defineProperty2.default)(this, "onFocus", () => { document.addEventListener("selectionchange", this.onSelectionChange); // force to recalculate this.lastSelection = null; this.refreshLastCaretIfNeeded(); }); (0, _defineProperty2.default)(this, "onSelectionChange", () => { if (!this.editorRef.current) return; const { isEmpty } = this.props.model; this.refreshLastCaretIfNeeded(); const selection = document.getSelection(); if (this.hasTextSelected && selection.isCollapsed) { this.hasTextSelected = false; this.formatBarRef.current?.hide(); } else if (!selection.isCollapsed && !isEmpty) { this.hasTextSelected = true; const range = (0, _dom.getRangeForSelection)(this.editorRef.current, this.props.model, selection); if (this.formatBarRef.current && this.state.useMarkdown && !!range.text.trim()) { const selectionRect = selection.getRangeAt(0).getBoundingClientRect(); this.formatBarRef.current.showAt(selectionRect); } } }); (0, _defineProperty2.default)(this, "onKeyDown", event => { if (!this.editorRef.current) return; if (this.isSafari && event.which == 229) { // Swallow the extra keyDown by Safari event.stopPropagation(); return; } const model = this.props.model; let handled = false; if (this.state.surroundWith && document.getSelection().type !== "Caret") { // This surrounds the selected text with a character. This is // intentionally left out of the keybinding manager as the keybinds // here shouldn't be changeable const selectionRange = (0, _dom.getRangeForSelection)(this.editorRef.current, this.props.model, document.getSelection()); // trim the range as we want it to exclude leading/trailing spaces selectionRange.trim(); if ([...SURROUND_WITH_DOUBLE_CHARACTERS.keys(), ...SURROUND_WITH_CHARACTERS].includes(event.key)) { this.historyManager.ensureLastChangesPushed(this.props.model); this.modifiedFlag = true; (0, _operations.toggleInlineFormat)(selectionRange, event.key, SURROUND_WITH_DOUBLE_CHARACTERS.get(event.key)); handled = true; } } const navAction = (0, _KeyBindingsManager.getKeyBindingsManager)().getNavigationAction(event); if (navAction === _KeyboardShortcuts.KeyBindingAction.NextLandmark || navAction === _KeyboardShortcuts.KeyBindingAction.PreviousLandmark) { _LandmarkNavigation.LandmarkNavigation.findAndFocusNextLandmark(_LandmarkNavigation.Landmark.MESSAGE_COMPOSER_OR_HOME, navAction === _KeyboardShortcuts.KeyBindingAction.PreviousLandmark); handled = true; } const autocompleteAction = (0, _KeyBindingsManager.getKeyBindingsManager)().getAutocompleteAction(event); const accessibilityAction = (0, _KeyBindingsManager.getKeyBindingsManager)().getAccessibilityAction(event); if (model.autoComplete?.hasCompletions()) { const autoComplete = model.autoComplete; switch (autocompleteAction) { case _KeyboardShortcuts.KeyBindingAction.ForceCompleteAutocomplete: case _KeyboardShortcuts.KeyBindingAction.CompleteAutocomplete: this.historyManager.ensureLastChangesPushed(this.props.model); this.modifiedFlag = true; autoComplete.confirmCompletion(); handled = true; break; case _KeyboardShortcuts.KeyBindingAction.PrevSelectionInAutocomplete: autoComplete.selectPreviousSelection(); handled = true; break; case _KeyboardShortcuts.KeyBindingAction.NextSelectionInAutocomplete: autoComplete.selectNextSelection(); handled = true; break; case _KeyboardShortcuts.KeyBindingAction.CancelAutocomplete: autoComplete.onEscape(event); handled = true; break; } } else if (autocompleteAction === _KeyboardShortcuts.KeyBindingAction.ForceCompleteAutocomplete && !this.state.showVisualBell) { // there is no current autocomplete window, try to open it this.tabCompleteName(); handled = true; } else if ([_KeyboardShortcuts.KeyBindingAction.Delete, _KeyboardShortcuts.KeyBindingAction.Backspace].includes(accessibilityAction)) { this.formatBarRef.current?.hide(); } if (handled) { event.preventDefault(); event.stopPropagation(); return; } const action = (0, _KeyBindingsManager.getKeyBindingsManager)().getMessageComposerAction(event); switch (action) { case _KeyboardShortcuts.KeyBindingAction.FormatBold: this.onFormatAction(_MessageComposerFormatBar.Formatting.Bold); handled = true; break; case _KeyboardShortcuts.KeyBindingAction.FormatItalics: this.onFormatAction(_MessageComposerFormatBar.Formatting.Italics); handled = true; break; case _KeyboardShortcuts.KeyBindingAction.FormatCode: this.onFormatAction(_MessageComposerFormatBar.Formatting.Code); handled = true; break; case _KeyboardShortcuts.KeyBindingAction.FormatQuote: this.onFormatAction(_MessageComposerFormatBar.Formatting.Quote); handled = true; break; case _KeyboardShortcuts.KeyBindingAction.FormatLink: this.onFormatAction(_MessageComposerFormatBar.Formatting.InsertLink); handled = true; break; case _KeyboardShortcuts.KeyBindingAction.EditRedo: { const history = this.historyManager.redo(); if (history) { const { parts, caret } = history; // pass matching inputType so historyManager doesn't push echo // when invoked from rerender callback. model.reset(parts, caret, "historyRedo"); } handled = true; break; } case _KeyboardShortcuts.KeyBindingAction.EditUndo: { const history = this.historyManager.undo(this.props.model); if (history) { const { parts, caret } = history; // pass matching inputType so historyManager doesn't push echo // when invoked from rerender callback. model.reset(parts, caret, "historyUndo"); } handled = true; break; } case _KeyboardShortcuts.KeyBindingAction.NewLine: this.insertText("\n"); handled = true; break; case _KeyboardShortcuts.KeyBindingAction.MoveCursorToStart: (0, _caret.setSelection)(this.editorRef.current, model, { index: 0, offset: 0 }); handled = true; break; case _KeyboardShortcuts.KeyBindingAction.MoveCursorToEnd: (0, _caret.setSelection)(this.editorRef.current, model, { index: model.parts.length - 1, offset: model.parts[model.parts.length - 1].text.length }); handled = true; break; } if (handled) { event.preventDefault(); event.stopPropagation(); } }); (0, _defineProperty2.default)(this, "onAutoCompleteConfirm", completion => { this.modifiedFlag = true; this.props.model.autoComplete?.onComponentConfirm(completion); }); (0, _defineProperty2.default)(this, "onAutoCompleteSelectionChange", completionIndex => { this.modifiedFlag = true; this.setState({ completionIndex }); }); (0, _defineProperty2.default)(this, "configureUseMarkdown", () => { const useMarkdown = _SettingsStore.default.getValue("MessageComposerInput.useMarkdown"); this.setState({ useMarkdown }); if (!useMarkdown && this.formatBarRef.current) { this.formatBarRef.current.hide(); } }); (0, _defineProperty2.default)(this, "configureEmoticonAutoReplace", () => { this.props.model.setTransformCallback(this.transform); }); (0, _defineProperty2.default)(this, "configureShouldShowPillAvatar", () => { const showPillAvatar = _SettingsStore.default.getValue("Pill.shouldShowPillAvatar"); this.setState({ showPillAvatar }); }); (0, _defineProperty2.default)(this, "surroundWithSettingChanged", () => { const surroundWith = _SettingsStore.default.getValue("MessageComposerInput.surroundWith"); this.setState({ surroundWith }); }); (0, _defineProperty2.default)(this, "transform", documentPosition => { const shouldReplace = _SettingsStore.default.getValue("MessageComposerInput.autoReplaceEmoji"); if (shouldReplace) this.replaceEmoticon(documentPosition, REGEX_EMOTICON_WHITESPACE); }); (0, _defineProperty2.default)(this, "onFormatAction", action => { if (!this.state.useMarkdown || !this.editorRef.current) { return; } const range = (0, _dom.getRangeForSelection)(this.editorRef.current, this.props.model, document.getSelection()); this.historyManager.ensureLastChangesPushed(this.props.model); this.modifiedFlag = true; (0, _operations.formatRange)(range, action); }); this.state = { showPillAvatar: _SettingsStore.default.getValue("Pill.shouldShowPillAvatar"), useMarkdown: _SettingsStore.default.getValue("MessageComposerInput.useMarkdown"), surroundWith: _SettingsStore.default.getValue("MessageComposerInput.surroundWith"), showVisualBell: false }; const ua = navigator.userAgent.toLowerCase(); this.isSafari = ua.includes("safari/") && !ua.includes("chrome/"); this.useMarkdownHandle = _SettingsStore.default.watchSetting("MessageComposerInput.useMarkdown", null, this.configureUseMarkdown); this.emoticonSettingHandle = _SettingsStore.default.watchSetting("MessageComposerInput.autoReplaceEmoji", null, this.configureEmoticonAutoReplace); this.configureEmoticonAutoReplace(); this.shouldShowPillAvatarSettingHandle = _SettingsStore.default.watchSetting("Pill.shouldShowPillAvatar", null, this.configureShouldShowPillAvatar); this.surroundWithHandle = _SettingsStore.default.watchSetting("MessageComposerInput.surroundWith", null, this.surroundWithSettingChanged); } componentDidUpdate(prevProps) { // We need to re-check the placeholder when the enabled state changes because it causes the // placeholder element to remount, which gets rid of the `::before` class. Re-evaluating the // placeholder means we get a proper `::before` with the placeholder. const enabledChange = this.props.disabled !== prevProps.disabled; const placeholderChanged = this.props.placeholder !== prevProps.placeholder; if (this.props.placeholder && (placeholderChanged || enabledChange)) { const { isEmpty } = this.props.model; if (isEmpty) { this.showPlaceholder(); } else { this.hidePlaceholder(); } } } replaceEmoticon(caretPosition, regex) { const { model } = this.props; const range = model.startRange(caretPosition); // expand range max 9 characters backwards from caretPosition, // as a space to look for an emoticon let n = 9; range.expandBackwardsWhile((index, offset) => { const part = model.parts[index]; n -= 1; return n >= 0 && [_parts.Type.Plain, _parts.Type.PillCandidate, _parts.Type.Newline].includes(part.type); }); const emoticonMatch = regex.exec(range.text); // ignore matches at start of proper substrings // so xd will not match if the string was "mixd 123456" // and we are lookinh at xd 123456 part of the string if (emoticonMatch && (n >= 0 || emoticonMatch.index !== 0)) { const query = emoticonMatch[1]; // variations of plaintext emoitcons(E.g. :P vs :p vs :-P) are handled upstream by the emojibase-bindings library const data = _emojibaseBindings.EMOTICON_TO_EMOJI.get(query); if (data) { const { partCreator } = model; const firstMatch = emoticonMatch[0]; const moveStart = firstMatch[0] === " " ? 1 : 0; // we need the range to only comprise of the emoticon // because we'll replace the whole range with an emoji, // so move the start forward to the start of the emoticon. // Take + 1 because index is reported without the possible preceding space. range.moveStartForwards(emoticonMatch.index + moveStart); // If the end is a trailing space/newline move end backwards, so that we don't replace it if (["\n", " "].includes(firstMatch[firstMatch.length - 1])) { range.moveEndBackwards(1); } // this returns the amount of added/removed characters during the replace // so the caret position can be adjusted. return range.replace([partCreator.emoji(data.unicode)]); } } } showPlaceholder() { this.editorRef.current?.style.setProperty("--placeholder", `'${CSS.escape(this.props.placeholder ?? "")}'`); this.editorRef.current?.classList.add("mx_BasicMessageComposer_inputEmpty"); } hidePlaceholder() { this.editorRef.current?.classList.remove("mx_BasicMessageComposer_inputEmpty"); this.editorRef.current?.style.removeProperty("--placeholder"); } isComposing(event) { // checking the event.isComposing flag just in case any browser out there // emits events related to the composition after compositionend // has been fired // From https://www.stum.de/2016/06/24/handling-ime-events-in-javascript/ // Safari emits an additional keyDown after compositionend return !!(this.isIMEComposing || event.nativeEvent && event.nativeEvent.isComposing); } insertText(textToInsert, inputType = "insertText") { if (!this.editorRef.current) return; const sel = document.getSelection(); const { caret, text } = (0, _dom.getCaretOffsetAndText)(this.editorRef.current, sel); const newText = text.slice(0, caret.offset) + textToInsert + text.slice(caret.offset); caret.offset += textToInsert.length; this.modifiedFlag = true; this.props.model.update(newText, inputType, caret); } // this is used later to see if we need to recalculate the caret // on selectionchange. If it is just a consequence of typing // we don't need to. But if the user is navigating the caret without input // we need to recalculate it, to be able to know where to insert content after // losing focus setLastCaretFromPosition(position) { const { model } = this.props; this._isCaretAtEnd = position.isAtEnd(model); this.lastCaret = position.asOffset(model); this.lastSelection = cloneSelection(document.getSelection()); } refreshLastCaretIfNeeded() { // XXX: needed when going up and down in editing messages ... not sure why yet // because the editors should stop doing this when when blurred ... // maybe it's on focus and the _editorRef isn't available yet or something. if (!this.editorRef.current) { return; } const selection = document.getSelection(); if (!this.lastSelection || !selectionEquals(this.lastSelection, selection)) { this.lastSelection = cloneSelection(selection); const { caret, text } = (0, _dom.getCaretOffsetAndText)(this.editorRef.current, selection); this.lastCaret = caret; this._isCaretAtEnd = caret.offset === text.length; } return this.lastCaret; } clearUndoHistory() { this.historyManager.clear(); } getCaret() { return this.lastCaret; } isSelectionCollapsed() { return !this.lastSelection || !!this.lastSelection.isCollapsed; } isCaretAtStart() { return this.getCaret().offset === 0; } isCaretAtEnd() { return this._isCaretAtEnd; } async tabCompleteName() { try { await new Promise(resolve => this.setState({ showVisualBell: false }, resolve)); const { model } = this.props; const caret = this.getCaret(); const position = model.positionForOffset(caret.offset, caret.atNodeEnd); const range = model.startRange(position); range.expandBackwardsWhile((index, offset, part) => { return part.text[offset] !== " " && part.text[offset] !== "+" && (part.type === _parts.Type.Plain || part.type === _parts.Type.PillCandidate || part.type === _parts.Type.Command); }); const { partCreator } = model; // await for auto-complete to be open await model.transform(() => { const addedLen = range.replace([partCreator.pillCandidate(range.text)]); return model.positionForOffset(caret.offset + addedLen, true); }); // Don't try to do things with the autocomplete if there is none shown if (model.autoComplete) { await model.autoComplete.startSelection(); if (!model.autoComplete.hasSelection()) { this.setState({ showVisualBell: true }); model.autoComplete.close(); } } else { this.setState({ showVisualBell: true }); } } catch (err) { _logger.logger.error(err); } } isModified() { return this.modifiedFlag; } componentWillUnmount() { document.removeEventListener("selectionchange", this.onSelectionChange); this.editorRef.current?.removeEventListener("beforeinput", this.onBeforeInput, true); this.editorRef.current?.removeEventListener("input", this.onInput, true); this.editorRef.current?.removeEventListener("compositionstart", this.onCompositionStart, true); this.editorRef.current?.removeEventListener("compositionend", this.onCompositionEnd, true); _SettingsStore.default.unwatchSetting(this.useMarkdownHandle); _SettingsStore.default.unwatchSetting(this.emoticonSettingHandle); _SettingsStore.default.unwatchSetting(this.shouldShowPillAvatarSettingHandle); _SettingsStore.default.unwatchSetting(this.surroundWithHandle); } componentDidMount() { const model = this.props.model; model.setUpdateCallback(this.updateEditorState); const partCreator = model.partCreator; // TODO: does this allow us to get rid of EditorStateTransfer? // not really, but we could not serialize the parts, and just change the autoCompleter partCreator.setAutoCompleteCreator((0, _parts.getAutoCompleteCreator)(() => this.autocompleteRef.current, query => new Promise(resolve => this.setState({ query }, resolve)))); // initial render of model this.updateEditorState(this.getInitialCaretPosition()); // attach input listener by hand so React doesn't proxy the events, // as the proxied event doesn't support inputType, which we need. this.editorRef.current?.addEventListener("beforeinput", this.onBeforeInput, true); this.editorRef.current?.addEventListener("input", this.onInput, true); this.editorRef.current?.addEventListener("compositionstart", this.onCompositionStart, true); this.editorRef.current?.addEventListener("compositionend", this.onCompositionEnd, true); this.editorRef.current?.focus(); } getInitialCaretPosition() { let caretPosition; if (this.props.initialCaret) { // if restoring state from a previous editor, // restore caret position from the state const caret = this.props.initialCaret; caretPosition = this.props.model.positionForOffset(caret.offset, caret.atNodeEnd); } else { // otherwise, set it at the end caretPosition = this.props.model.getPositionAtEnd(); } return caretPosition; } render() { let autoComplete; if (this.state.autoComplete && this.state.query) { const query = this.state.query; const queryLen = query.length; autoComplete = /*#__PURE__*/_react.default.createElement("div", { className: "mx_BasicMessageComposer_AutoCompleteWrapper" }, /*#__PURE__*/_react.default.createElement(_Autocomplete.default, { ref: this.autocompleteRef, query: query, onConfirm: this.onAutoCompleteConfirm, onSelectionChange: this.onAutoCompleteSelectionChange, selection: { beginning: true, end: queryLen, start: queryLen }, room: this.props.room })); } const wrapperClasses = (0, _classnames.default)("mx_BasicMessageComposer", { mx_BasicMessageComposer_input_error: this.state.showVisualBell }); const classes = (0, _classnames.default)("mx_BasicMessageComposer_input", { mx_BasicMessageComposer_input_shouldShowPillAvatar: this.state.showPillAvatar, mx_BasicMessageComposer_input_disabled: this.props.disabled }); const shortcuts = { [_MessageComposerFormatBar.Formatting.Bold]: ctrlShortcutLabel("B"), [_MessageComposerFormatBar.Formatting.Italics]: ctrlShortcutLabel("I"), [_MessageComposerFormatBar.Formatting.Code]: ctrlShortcutLabel("E"), [_MessageComposerFormatBar.Formatting.Quote]: ctrlShortcutLabel(">", true), [_MessageComposerFormatBar.Formatting.InsertLink]: ctrlShortcutLabel("L", true) }; const { completionIndex } = this.state; const hasAutocomplete = !!this.state.autoComplete; let activeDescendant; if (hasAutocomplete && completionIndex >= 0) { activeDescendant = (0, _Autocomplete.generateCompletionDomId)(completionIndex); } return /*#__PURE__*/_react.default.createElement("div", { className: wrapperClasses }, autoComplete, /*#__PURE__*/_react.default.createElement(_MessageComposerFormatBar.default, { ref: this.formatBarRef, onAction: this.onFormatAction, shortcuts: shortcuts }), /*#__PURE__*/_react.default.createElement("div", { className: classes, contentEditable: this.props.disabled ? undefined : true, tabIndex: 0, onBlur: this.onBlur, onFocus: this.onFocus, onCopy: this.onCopy, onCut: this.onCut, onPaste: this.onPaste, onKeyDown: this.onKeyDown, ref: this.editorRef, "aria-label": this.props.label, role: "textbox", "aria-multiline": "true", "aria-autocomplete": "list", "aria-haspopup": "listbox", "aria-expanded": hasAutocomplete ? !this.autocompleteRef.current?.state.hide : undefined, "aria-owns": hasAutocomplete ? "mx_Autocomplete" : undefined, "aria-activedescendant": activeDescendant, dir: "auto", "aria-disabled": this.props.disabled, "data-testid": "basicmessagecomposer", translate: "no" })); } focus() { this.editorRef.current?.focus(); } insertMention(userId) { this.modifiedFlag = true; const { model } = this.props; const { partCreator } = model; const member = this.props.room.getMember(userId); const displayName = member ? member.rawDisplayName : userId; const caret = this.getCaret(); const position = model.positionForOffset(caret.offset, caret.atNodeEnd); // Insert suffix only if the caret is at the start of the composer const parts = partCreator.createMentionParts(caret.offset === 0, displayName, userId); model.transform(() => { const addedLen = model.insert(parts, position); return model.positionForOffset(caret.offset + addedLen, true); }); // refocus on composer, as we just clicked "Mention" this.focus(); } insertQuotedMessage(event) { this.modifiedFlag = true; const { model } = this.props; const { partCreator } = model; const quoteParts = (0, _deserialize.parseEvent)(event, partCreator, { isQuotedMessage: true }); // add two newlines quoteParts.push(partCreator.newline()); quoteParts.push(partCreator.newline()); model.transform(() => { const addedLen = model.insert(quoteParts, model.positionForOffset(0)); return model.positionForOffset(addedLen, true); }); // refocus on composer, as we just clicked "Quote" this.focus(); } insertPlaintext(text) { this.modifiedFlag = true; const { model } = this.props; const { partCreator } = model; const caret = this.getCaret(); const position = model.positionForOffset(caret.offset, caret.atNodeEnd); model.transform(() => { const addedLen = model.insert(partCreator.plainWithEmoji(text), position); return model.positionForOffset(caret.offset + addedLen, true); }); } } exports.default = BasicMessageEditor; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfY2xhc3NuYW1lcyIsIl9pbnRlcm9wUmVxdWlyZURlZmF1bHQiLCJyZXF1aXJlIiwiX3JlYWN0IiwiX2ludGVyb3BSZXF1aXJlV2lsZGNhcmQiLCJfZW1vdGljb24iLCJfbG9nZ2VyIiwiX2Vtb2ppYmFzZUJpbmRpbmdzIiwiX2hpc3RvcnkiLCJfY2FyZXQiLCJfb3BlcmF0aW9ucyIsIl9kb20iLCJfQXV0b2NvbXBsZXRlIiwiX3BhcnRzIiwiX2Rlc2VyaWFsaXplIiwiX3JlbmRlciIsIl9TZXR0aW5nc1N0b3JlIiwiX0tleWJvYXJkIiwiX1NsYXNoQ29tbWFuZHMiLCJfcmFuZ2UiLCJfTWVzc2FnZUNvbXBvc2VyRm9ybWF0QmFyIiwiX0tleUJpbmRpbmdzTWFuYWdlciIsIl9LZXlib2FyZFNob3J0Y3V0cyIsIl9sYW5ndWFnZUhhbmRsZXIiLCJfbGlua2lmeU1hdHJpeCIsIl9TREtDb250ZXh0IiwiX01hdHJpeENsaWVudFBlZyIsIl9MYW5kbWFya05hdmlnYXRpb24iLCJfZ2V0UmVxdWlyZVdpbGRjYXJkQ2FjaGUiLCJlIiwiV2Vha01hcCIsInIiLCJ0IiwiX19lc01vZHVsZSIsImRlZmF1bHQiLCJoYXMiLCJnZXQiLCJuIiwiX19wcm90b19fIiwiYSIsIk9iamVjdCIsImRlZmluZVByb3BlcnR5IiwiZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yIiwidSIsImhhc093blByb3Bl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