/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 */

"use strict";var e=require("@lexical/clipboard"),t=require("@lexical/dragon"),n=require("@lexical/extension"),r=require("@lexical/selection"),i=require("@lexical/utils"),o=require("lexical");function a(t,n){n.update(()=>{if(null!==t){const r=i.objectKlassEquals(t,KeyboardEvent)?null:t.clipboardData,a=o.$getSelection();if(null!==a&&!a.isCollapsed()&&null!=r){t.preventDefault();const i=e.$getHtmlContent(n);null!==i&&r.setData("text/html",i),r.setData("text/plain",a.getTextContent())}}})}function l(t){const n=o.mergeRegister(t.registerCommand(o.DELETE_CHARACTER_COMMAND,e=>{const t=o.$getSelection();return!!o.$isRangeSelection(t)&&(t.deleteCharacter(e),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.DELETE_WORD_COMMAND,e=>{const t=o.$getSelection();return!!o.$isRangeSelection(t)&&(t.deleteWord(e),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.DELETE_LINE_COMMAND,e=>{const t=o.$getSelection();return!!o.$isRangeSelection(t)&&(t.deleteLine(e),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.CONTROLLED_TEXT_INSERTION_COMMAND,t=>{const n=o.$getSelection();if(!o.$isRangeSelection(n))return!1;if("string"==typeof t)n.insertText(t);else{const r=t.dataTransfer;if(null!=r)e.$insertDataTransferForPlainText(r,n);else{const e=t.data;e&&n.insertText(e)}}return!0},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.REMOVE_TEXT_COMMAND,()=>{const e=o.$getSelection();return!!o.$isRangeSelection(e)&&(e.removeText(),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.INSERT_LINE_BREAK_COMMAND,e=>{const t=o.$getSelection();return!!o.$isRangeSelection(t)&&(t.insertLineBreak(e),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.INSERT_PARAGRAPH_COMMAND,()=>{const e=o.$getSelection();return!!o.$isRangeSelection(e)&&(e.insertLineBreak(),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.KEY_ARROW_LEFT_COMMAND,e=>{const t=o.$getSelection();if(!o.$isRangeSelection(t))return!1;const n=e,i=n.shiftKey;return!!r.$shouldOverrideDefaultCharacterSelection(t,!0)&&(n.preventDefault(),r.$moveCharacter(t,i,!0),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.KEY_ARROW_RIGHT_COMMAND,e=>{const t=o.$getSelection();if(!o.$isRangeSelection(t))return!1;const n=e,i=n.shiftKey;return!!r.$shouldOverrideDefaultCharacterSelection(t,!1)&&(n.preventDefault(),r.$moveCharacter(t,i,!1),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.KEY_BACKSPACE_COMMAND,e=>{const n=o.$getSelection();return!!o.$isRangeSelection(n)&&((!o.IS_IOS||!o.CAN_USE_BEFORE_INPUT)&&(e.preventDefault(),t.dispatchCommand(o.DELETE_CHARACTER_COMMAND,!0)))},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.KEY_DELETE_COMMAND,e=>{const n=o.$getSelection();return!!o.$isRangeSelection(n)&&(e.preventDefault(),t.dispatchCommand(o.DELETE_CHARACTER_COMMAND,!1))},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.KEY_ENTER_COMMAND,e=>{const n=o.$getSelection();if(!o.$isRangeSelection(n))return!1;if(null!==e){if((o.IS_IOS||o.IS_SAFARI||o.IS_APPLE_WEBKIT)&&o.CAN_USE_BEFORE_INPUT)return!1;e.preventDefault()}return t.dispatchCommand(o.INSERT_LINE_BREAK_COMMAND,!1)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.SELECT_ALL_COMMAND,()=>{const e=o.$getSelection();return o.$selectAll(o.$isRangeSelection(e)&&null!==o.$getSlotFrame(e.anchor.getNode())?e:null),!0},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.COPY_COMMAND,e=>{const n=o.$getSelection();return!!o.$isRangeSelection(n)&&(a(e,t),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.CUT_COMMAND,e=>{const n=o.$getSelection();return!!o.$isRangeSelection(n)&&(function(e,t){a(e,t),t.update(()=>{const e=o.$getSelection();o.$isRangeSelection(e)&&e.removeText()},{tag:o.CUT_TAG})}(e,t),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.PASTE_COMMAND,n=>{const r=o.$getSelection();return!!o.$isRangeSelection(r)&&(function(t,n){t.preventDefault(),n.update(()=>{const n=o.$getSelection(),r=i.objectKlassEquals(t,ClipboardEvent)?t.clipboardData:null;null!=r&&o.$isRangeSelection(n)&&e.$insertDataTransferForPlainText(r,n)},{tag:o.PASTE_TAG})}(n,t),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.DROP_COMMAND,n=>e.$handlePlainTextDrop(n,t),o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.DRAGSTART_COMMAND,n=>{const r=o.$getSelection();return!!o.$isRangeSelection(r)&&(r.isCollapsed()||null===n.dataTransfer||e.$writeDragSourceToDataTransfer(n.dataTransfer,t),!0)},o.COMMAND_PRIORITY_EDITOR));return n}const s=/* @__PURE__ */o.defineExtension({conflictsWith:["@lexical/rich-text"],dependencies:[t.DragonExtension,n.NormalizeInlineElementsExtension,n.NormalizeTripleClickSelectionExtension],name:"@lexical/plain-text",register:l});exports.PlainTextExtension=s,exports.registerPlainText=l;
