/**
 * 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/selection"),i=require("@lexical/utils"),r=require("lexical");const o="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,a=o&&"documentMode"in document?document.documentMode:null,s=o&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),l=!(!o||!("InputEvent"in window)||a)&&"getTargetRanges"in new window.InputEvent("input"),c=o&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,R=o&&/Android/.test(navigator.userAgent),O=o&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!R,D=o&&/^(?=.*Chrome).*/i.test(navigator.userAgent),g=o&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&s&&!D;function M(t,n){n.update(()=>{if(null!==t){const o=i.objectKlassEquals(t,KeyboardEvent)?null:t.clipboardData,a=r.$getSelection();if(null!==a&&!a.isCollapsed()&&null!=o){t.preventDefault();const i=e.$getHtmlContent(n);null!==i&&o.setData("text/html",i),o.setData("text/plain",a.getTextContent())}}})}function C(t){const o=i.mergeRegister(t.registerCommand(r.DELETE_CHARACTER_COMMAND,e=>{const t=r.$getSelection();return!!r.$isRangeSelection(t)&&(t.deleteCharacter(e),!0)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.DELETE_WORD_COMMAND,e=>{const t=r.$getSelection();return!!r.$isRangeSelection(t)&&(t.deleteWord(e),!0)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.DELETE_LINE_COMMAND,e=>{const t=r.$getSelection();return!!r.$isRangeSelection(t)&&(t.deleteLine(e),!0)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.CONTROLLED_TEXT_INSERTION_COMMAND,t=>{const n=r.$getSelection();if(!r.$isRangeSelection(n))return!1;if("string"==typeof t)n.insertText(t);else{const i=t.dataTransfer;if(null!=i)e.$insertDataTransferForPlainText(i,n);else{const e=t.data;e&&n.insertText(e)}}return!0},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.REMOVE_TEXT_COMMAND,()=>{const e=r.$getSelection();return!!r.$isRangeSelection(e)&&(e.removeText(),!0)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.INSERT_LINE_BREAK_COMMAND,e=>{const t=r.$getSelection();return!!r.$isRangeSelection(t)&&(t.insertLineBreak(e),!0)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.INSERT_PARAGRAPH_COMMAND,()=>{const e=r.$getSelection();return!!r.$isRangeSelection(e)&&(e.insertLineBreak(),!0)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.KEY_ARROW_LEFT_COMMAND,e=>{const t=r.$getSelection();if(!r.$isRangeSelection(t))return!1;const i=e,o=i.shiftKey;return!!n.$shouldOverrideDefaultCharacterSelection(t,!0)&&(i.preventDefault(),n.$moveCharacter(t,o,!0),!0)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.KEY_ARROW_RIGHT_COMMAND,e=>{const t=r.$getSelection();if(!r.$isRangeSelection(t))return!1;const i=e,o=i.shiftKey;return!!n.$shouldOverrideDefaultCharacterSelection(t,!1)&&(i.preventDefault(),n.$moveCharacter(t,o,!1),!0)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.KEY_BACKSPACE_COMMAND,e=>{const n=r.$getSelection();return!!r.$isRangeSelection(n)&&((!c||"ko-KR"!==navigator.language)&&(e.preventDefault(),t.dispatchCommand(r.DELETE_CHARACTER_COMMAND,!0)))},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.KEY_DELETE_COMMAND,e=>{const n=r.$getSelection();return!!r.$isRangeSelection(n)&&(e.preventDefault(),t.dispatchCommand(r.DELETE_CHARACTER_COMMAND,!1))},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.KEY_ENTER_COMMAND,e=>{const n=r.$getSelection();if(!r.$isRangeSelection(n))return!1;if(null!==e){if((c||O||g)&&l)return!1;e.preventDefault()}return t.dispatchCommand(r.INSERT_LINE_BREAK_COMMAND,!1)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.SELECT_ALL_COMMAND,()=>(r.$selectAll(),!0),r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.COPY_COMMAND,e=>{const n=r.$getSelection();return!!r.$isRangeSelection(n)&&(M(e,t),!0)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.CUT_COMMAND,e=>{const n=r.$getSelection();return!!r.$isRangeSelection(n)&&(function(e,t){M(e,t),t.update(()=>{const e=r.$getSelection();r.$isRangeSelection(e)&&e.removeText()})}(e,t),!0)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.PASTE_COMMAND,n=>{const o=r.$getSelection();return!!r.$isRangeSelection(o)&&(function(t,n){t.preventDefault(),n.update(()=>{const n=r.$getSelection(),o=i.objectKlassEquals(t,ClipboardEvent)?t.clipboardData:null;null!=o&&r.$isRangeSelection(n)&&e.$insertDataTransferForPlainText(o,n)},{tag:r.PASTE_TAG})}(n,t),!0)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.DROP_COMMAND,e=>{const t=r.$getSelection();return!!r.$isRangeSelection(t)&&(e.preventDefault(),!0)},r.COMMAND_PRIORITY_EDITOR),t.registerCommand(r.DRAGSTART_COMMAND,e=>{const t=r.$getSelection();return!!r.$isRangeSelection(t)&&(e.preventDefault(),!0)},r.COMMAND_PRIORITY_EDITOR));return o}const _=r.defineExtension({conflictsWith:["@lexical/rich-text"],dependencies:[t.DragonExtension],name:"@lexical/plain-text",register:C});exports.PlainTextExtension=_,exports.registerPlainText=C;
