Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@lexical/plain-text

Package Overview
Dependencies
Maintainers
6
Versions
602
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/plain-text - npm Package Compare versions

Comparing version
0.44.1-nightly.20260519.0
to
0.45.0
+13
dist/index.d.ts
/**
* 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.
*
*/
import type { LexicalEditor } from 'lexical';
export declare function registerPlainText(editor: LexicalEditor): () => void;
/**
* An extension to register \@lexical/plain-text behavior
*/
export declare const PlainTextExtension: import("lexical").LexicalExtension<import("lexical").ExtensionConfigBase, "@lexical/plain-text", unknown, unknown>;
/**
* 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 clipboard = require('@lexical/clipboard');
var dragon = require('@lexical/dragon');
var extension = require('@lexical/extension');
var selection = require('@lexical/selection');
var utils = require('@lexical/utils');
var lexical = require('lexical');
/**
* 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.
*
*/
function onCopyForPlainText(event, editor) {
editor.update(() => {
if (event !== null) {
const clipboardData = utils.objectKlassEquals(event, KeyboardEvent) ? null : event.clipboardData;
const selection = lexical.$getSelection();
if (selection !== null && !selection.isCollapsed() && clipboardData != null) {
event.preventDefault();
const htmlString = clipboard.$getHtmlContent(editor);
if (htmlString !== null) {
clipboardData.setData('text/html', htmlString);
}
clipboardData.setData('text/plain', selection.getTextContent());
}
}
});
}
function onPasteForPlainText(event, editor) {
event.preventDefault();
editor.update(() => {
const selection = lexical.$getSelection();
const clipboardData = utils.objectKlassEquals(event, ClipboardEvent) ? event.clipboardData : null;
if (clipboardData != null && lexical.$isRangeSelection(selection)) {
clipboard.$insertDataTransferForPlainText(clipboardData, selection);
}
}, {
tag: lexical.PASTE_TAG
});
}
function onCutForPlainText(event, editor) {
onCopyForPlainText(event, editor);
editor.update(() => {
const selection = lexical.$getSelection();
if (lexical.$isRangeSelection(selection)) {
selection.removeText();
}
});
}
function registerPlainText(editor) {
const removeListener = utils.mergeRegister(editor.registerCommand(lexical.DELETE_CHARACTER_COMMAND, isBackward => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
selection.deleteCharacter(isBackward);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_WORD_COMMAND, isBackward => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
selection.deleteWord(isBackward);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_LINE_COMMAND, isBackward => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
selection.deleteLine(isBackward);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CONTROLLED_TEXT_INSERTION_COMMAND, eventOrText => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
if (typeof eventOrText === 'string') {
selection.insertText(eventOrText);
} else {
const dataTransfer = eventOrText.dataTransfer;
if (dataTransfer != null) {
clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
} else {
const data = eventOrText.data;
if (data) {
selection.insertText(data);
}
}
}
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.REMOVE_TEXT_COMMAND, () => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
selection.removeText();
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_LINE_BREAK_COMMAND, selectStart => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
selection.insertLineBreak(selectStart);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, () => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
selection.insertLineBreak();
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, payload => {
const selection$1 = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection$1)) {
return false;
}
const event = payload;
const isHoldingShift = event.shiftKey;
if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
event.preventDefault();
selection.$moveCharacter(selection$1, isHoldingShift, true);
return true;
}
return false;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, payload => {
const selection$1 = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection$1)) {
return false;
}
const event = payload;
const isHoldingShift = event.shiftKey;
if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
event.preventDefault();
selection.$moveCharacter(selection$1, isHoldingShift, false);
return true;
}
return false;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
// Exception handling for iOS native behavior instead of Lexical's behavior when using Korean on iOS devices.
// more details - https://github.com/facebook/lexical/issues/5841
if (lexical.IS_IOS && navigator.language === 'ko-KR') {
return false;
}
event.preventDefault();
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
event.preventDefault();
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, false);
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
if (event !== null) {
// If we have beforeinput, then we can avoid blocking
// the default behavior. This ensures that the iOS can
// intercept that we're actually inserting a paragraph,
// and autocomplete, autocapitalize etc work as intended.
// This can also cause a strange performance issue in
// Safari, where there is a noticeable pause due to
// preventing the key down of enter.
if ((lexical.IS_IOS || lexical.IS_SAFARI || lexical.IS_APPLE_WEBKIT) && lexical.CAN_USE_BEFORE_INPUT) {
return false;
}
event.preventDefault();
}
return editor.dispatchCommand(lexical.INSERT_LINE_BREAK_COMMAND, false);
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.SELECT_ALL_COMMAND, () => {
lexical.$selectAll();
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
onCopyForPlainText(event, editor);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CUT_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
onCutForPlainText(event, editor);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.PASTE_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
onPasteForPlainText(event, editor);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DROP_COMMAND, event => clipboard.$handlePlainTextDrop(event, editor), lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DRAGSTART_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
// Mark the drag source so a drop in a different editor can remove
// the source range to produce cut-and-paste semantics.
if (!selection.isCollapsed() && event.dataTransfer !== null) {
clipboard.$writeDragSourceToDataTransfer(event.dataTransfer, editor);
}
return true;
}, lexical.COMMAND_PRIORITY_EDITOR));
return removeListener;
}
/**
* An extension to register \@lexical/plain-text behavior
*/
const PlainTextExtension = lexical.defineExtension({
conflictsWith: ['@lexical/rich-text'],
dependencies: [dragon.DragonExtension, extension.NormalizeInlineElementsExtension, extension.NormalizeTripleClickSelectionExtension],
name: '@lexical/plain-text',
register: registerPlainText
});
exports.PlainTextExtension = PlainTextExtension;
exports.registerPlainText = registerPlainText;
/**
* 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.
*
*/
import { $insertDataTransferForPlainText, $handlePlainTextDrop, $writeDragSourceToDataTransfer, $getHtmlContent } from '@lexical/clipboard';
import { DragonExtension } from '@lexical/dragon';
import { NormalizeInlineElementsExtension, NormalizeTripleClickSelectionExtension } from '@lexical/extension';
import { $shouldOverrideDefaultCharacterSelection, $moveCharacter } from '@lexical/selection';
import { mergeRegister, objectKlassEquals } from '@lexical/utils';
import { defineExtension, DELETE_CHARACTER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, REMOVE_TEXT_COMMAND, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_BACKSPACE_COMMAND, IS_IOS, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, IS_SAFARI, IS_APPLE_WEBKIT, CAN_USE_BEFORE_INPUT, SELECT_ALL_COMMAND, $selectAll, COPY_COMMAND, CUT_COMMAND, PASTE_COMMAND, DROP_COMMAND, DRAGSTART_COMMAND, PASTE_TAG } from 'lexical';
/**
* 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.
*
*/
function onCopyForPlainText(event, editor) {
editor.update(() => {
if (event !== null) {
const clipboardData = objectKlassEquals(event, KeyboardEvent) ? null : event.clipboardData;
const selection = $getSelection();
if (selection !== null && !selection.isCollapsed() && clipboardData != null) {
event.preventDefault();
const htmlString = $getHtmlContent(editor);
if (htmlString !== null) {
clipboardData.setData('text/html', htmlString);
}
clipboardData.setData('text/plain', selection.getTextContent());
}
}
});
}
function onPasteForPlainText(event, editor) {
event.preventDefault();
editor.update(() => {
const selection = $getSelection();
const clipboardData = objectKlassEquals(event, ClipboardEvent) ? event.clipboardData : null;
if (clipboardData != null && $isRangeSelection(selection)) {
$insertDataTransferForPlainText(clipboardData, selection);
}
}, {
tag: PASTE_TAG
});
}
function onCutForPlainText(event, editor) {
onCopyForPlainText(event, editor);
editor.update(() => {
const selection = $getSelection();
if ($isRangeSelection(selection)) {
selection.removeText();
}
});
}
function registerPlainText(editor) {
const removeListener = mergeRegister(editor.registerCommand(DELETE_CHARACTER_COMMAND, isBackward => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.deleteCharacter(isBackward);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DELETE_WORD_COMMAND, isBackward => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.deleteWord(isBackward);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DELETE_LINE_COMMAND, isBackward => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.deleteLine(isBackward);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(CONTROLLED_TEXT_INSERTION_COMMAND, eventOrText => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
if (typeof eventOrText === 'string') {
selection.insertText(eventOrText);
} else {
const dataTransfer = eventOrText.dataTransfer;
if (dataTransfer != null) {
$insertDataTransferForPlainText(dataTransfer, selection);
} else {
const data = eventOrText.data;
if (data) {
selection.insertText(data);
}
}
}
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(REMOVE_TEXT_COMMAND, () => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.removeText();
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INSERT_LINE_BREAK_COMMAND, selectStart => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.insertLineBreak(selectStart);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INSERT_PARAGRAPH_COMMAND, () => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.insertLineBreak();
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_LEFT_COMMAND, payload => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
const event = payload;
const isHoldingShift = event.shiftKey;
if ($shouldOverrideDefaultCharacterSelection(selection, true)) {
event.preventDefault();
$moveCharacter(selection, isHoldingShift, true);
return true;
}
return false;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_RIGHT_COMMAND, payload => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
const event = payload;
const isHoldingShift = event.shiftKey;
if ($shouldOverrideDefaultCharacterSelection(selection, false)) {
event.preventDefault();
$moveCharacter(selection, isHoldingShift, false);
return true;
}
return false;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_BACKSPACE_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
// Exception handling for iOS native behavior instead of Lexical's behavior when using Korean on iOS devices.
// more details - https://github.com/facebook/lexical/issues/5841
if (IS_IOS && navigator.language === 'ko-KR') {
return false;
}
event.preventDefault();
return editor.dispatchCommand(DELETE_CHARACTER_COMMAND, true);
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_DELETE_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
event.preventDefault();
return editor.dispatchCommand(DELETE_CHARACTER_COMMAND, false);
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ENTER_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
if (event !== null) {
// If we have beforeinput, then we can avoid blocking
// the default behavior. This ensures that the iOS can
// intercept that we're actually inserting a paragraph,
// and autocomplete, autocapitalize etc work as intended.
// This can also cause a strange performance issue in
// Safari, where there is a noticeable pause due to
// preventing the key down of enter.
if ((IS_IOS || IS_SAFARI || IS_APPLE_WEBKIT) && CAN_USE_BEFORE_INPUT) {
return false;
}
event.preventDefault();
}
return editor.dispatchCommand(INSERT_LINE_BREAK_COMMAND, false);
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(SELECT_ALL_COMMAND, () => {
$selectAll();
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(COPY_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
onCopyForPlainText(event, editor);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(CUT_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
onCutForPlainText(event, editor);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(PASTE_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
onPasteForPlainText(event, editor);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DROP_COMMAND, event => $handlePlainTextDrop(event, editor), COMMAND_PRIORITY_EDITOR), editor.registerCommand(DRAGSTART_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
// Mark the drag source so a drop in a different editor can remove
// the source range to produce cut-and-paste semantics.
if (!selection.isCollapsed() && event.dataTransfer !== null) {
$writeDragSourceToDataTransfer(event.dataTransfer, editor);
}
return true;
}, COMMAND_PRIORITY_EDITOR));
return removeListener;
}
/**
* An extension to register \@lexical/plain-text behavior
*/
const PlainTextExtension = defineExtension({
conflictsWith: ['@lexical/rich-text'],
dependencies: [DragonExtension, NormalizeInlineElementsExtension, NormalizeTripleClickSelectionExtension],
name: '@lexical/plain-text',
register: registerPlainText
});
export { PlainTextExtension, registerPlainText };
/**
* 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'
const LexicalPlainText = process.env.NODE_ENV !== 'production' ? require('./LexicalPlainText.dev.js') : require('./LexicalPlainText.prod.js');
module.exports = LexicalPlainText;

Sorry, the diff of this file is not supported yet

/**
* 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.
*
*/
import * as modDev from './LexicalPlainText.dev.mjs';
import * as modProd from './LexicalPlainText.prod.mjs';
const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
export const PlainTextExtension = mod.PlainTextExtension;
export const registerPlainText = mod.registerPlainText;
/**
* 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.
*
*/
const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalPlainText.dev.mjs') : import('./LexicalPlainText.prod.mjs'));
export const PlainTextExtension = mod.PlainTextExtension;
export const registerPlainText = mod.registerPlainText;
/**
* 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"),a=require("lexical");function o(t,n){n.update(()=>{if(null!==t){const r=i.objectKlassEquals(t,KeyboardEvent)?null:t.clipboardData,o=a.$getSelection();if(null!==o&&!o.isCollapsed()&&null!=r){t.preventDefault();const i=e.$getHtmlContent(n);null!==i&&r.setData("text/html",i),r.setData("text/plain",o.getTextContent())}}})}function l(t){const n=i.mergeRegister(t.registerCommand(a.DELETE_CHARACTER_COMMAND,e=>{const t=a.$getSelection();return!!a.$isRangeSelection(t)&&(t.deleteCharacter(e),!0)},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.DELETE_WORD_COMMAND,e=>{const t=a.$getSelection();return!!a.$isRangeSelection(t)&&(t.deleteWord(e),!0)},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.DELETE_LINE_COMMAND,e=>{const t=a.$getSelection();return!!a.$isRangeSelection(t)&&(t.deleteLine(e),!0)},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.CONTROLLED_TEXT_INSERTION_COMMAND,t=>{const n=a.$getSelection();if(!a.$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},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.REMOVE_TEXT_COMMAND,()=>{const e=a.$getSelection();return!!a.$isRangeSelection(e)&&(e.removeText(),!0)},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.INSERT_LINE_BREAK_COMMAND,e=>{const t=a.$getSelection();return!!a.$isRangeSelection(t)&&(t.insertLineBreak(e),!0)},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.INSERT_PARAGRAPH_COMMAND,()=>{const e=a.$getSelection();return!!a.$isRangeSelection(e)&&(e.insertLineBreak(),!0)},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.KEY_ARROW_LEFT_COMMAND,e=>{const t=a.$getSelection();if(!a.$isRangeSelection(t))return!1;const n=e,i=n.shiftKey;return!!r.$shouldOverrideDefaultCharacterSelection(t,!0)&&(n.preventDefault(),r.$moveCharacter(t,i,!0),!0)},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.KEY_ARROW_RIGHT_COMMAND,e=>{const t=a.$getSelection();if(!a.$isRangeSelection(t))return!1;const n=e,i=n.shiftKey;return!!r.$shouldOverrideDefaultCharacterSelection(t,!1)&&(n.preventDefault(),r.$moveCharacter(t,i,!1),!0)},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.KEY_BACKSPACE_COMMAND,e=>{const n=a.$getSelection();return!!a.$isRangeSelection(n)&&((!a.IS_IOS||"ko-KR"!==navigator.language)&&(e.preventDefault(),t.dispatchCommand(a.DELETE_CHARACTER_COMMAND,!0)))},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.KEY_DELETE_COMMAND,e=>{const n=a.$getSelection();return!!a.$isRangeSelection(n)&&(e.preventDefault(),t.dispatchCommand(a.DELETE_CHARACTER_COMMAND,!1))},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.KEY_ENTER_COMMAND,e=>{const n=a.$getSelection();if(!a.$isRangeSelection(n))return!1;if(null!==e){if((a.IS_IOS||a.IS_SAFARI||a.IS_APPLE_WEBKIT)&&a.CAN_USE_BEFORE_INPUT)return!1;e.preventDefault()}return t.dispatchCommand(a.INSERT_LINE_BREAK_COMMAND,!1)},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.SELECT_ALL_COMMAND,()=>(a.$selectAll(),!0),a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.COPY_COMMAND,e=>{const n=a.$getSelection();return!!a.$isRangeSelection(n)&&(o(e,t),!0)},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.CUT_COMMAND,e=>{const n=a.$getSelection();return!!a.$isRangeSelection(n)&&(function(e,t){o(e,t),t.update(()=>{const e=a.$getSelection();a.$isRangeSelection(e)&&e.removeText()})}(e,t),!0)},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.PASTE_COMMAND,n=>{const r=a.$getSelection();return!!a.$isRangeSelection(r)&&(function(t,n){t.preventDefault(),n.update(()=>{const n=a.$getSelection(),r=i.objectKlassEquals(t,ClipboardEvent)?t.clipboardData:null;null!=r&&a.$isRangeSelection(n)&&e.$insertDataTransferForPlainText(r,n)},{tag:a.PASTE_TAG})}(n,t),!0)},a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.DROP_COMMAND,n=>e.$handlePlainTextDrop(n,t),a.COMMAND_PRIORITY_EDITOR),t.registerCommand(a.DRAGSTART_COMMAND,n=>{const r=a.$getSelection();return!!a.$isRangeSelection(r)&&(r.isCollapsed()||null===n.dataTransfer||e.$writeDragSourceToDataTransfer(n.dataTransfer,t),!0)},a.COMMAND_PRIORITY_EDITOR));return n}const s=a.defineExtension({conflictsWith:["@lexical/rich-text"],dependencies:[t.DragonExtension,n.NormalizeInlineElementsExtension,n.NormalizeTripleClickSelectionExtension],name:"@lexical/plain-text",register:l});exports.PlainTextExtension=s,exports.registerPlainText=l;
/**
* 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.
*
*/
import{$insertDataTransferForPlainText as e,$handlePlainTextDrop as t,$writeDragSourceToDataTransfer as r,$getHtmlContent as n}from"@lexical/clipboard";import{DragonExtension as a}from"@lexical/dragon";import{NormalizeInlineElementsExtension as o,NormalizeTripleClickSelectionExtension as i}from"@lexical/extension";import{$shouldOverrideDefaultCharacterSelection as s,$moveCharacter as l}from"@lexical/selection";import{mergeRegister as m,objectKlassEquals as c}from"@lexical/utils";import{defineExtension as u,DELETE_CHARACTER_COMMAND as d,$getSelection as f,$isRangeSelection as p,COMMAND_PRIORITY_EDITOR as g,DELETE_WORD_COMMAND as C,DELETE_LINE_COMMAND as x,CONTROLLED_TEXT_INSERTION_COMMAND as v,REMOVE_TEXT_COMMAND as D,INSERT_LINE_BREAK_COMMAND as h,INSERT_PARAGRAPH_COMMAND as T,KEY_ARROW_LEFT_COMMAND as b,KEY_ARROW_RIGHT_COMMAND as y,KEY_BACKSPACE_COMMAND as K,IS_IOS as k,KEY_DELETE_COMMAND as L,KEY_ENTER_COMMAND as B,IS_SAFARI as E,IS_APPLE_WEBKIT as W,CAN_USE_BEFORE_INPUT as R,SELECT_ALL_COMMAND as j,$selectAll as q,COPY_COMMAND as w,CUT_COMMAND as z,PASTE_COMMAND as A,DROP_COMMAND as F,DRAGSTART_COMMAND as G,PASTE_TAG as H}from"lexical";function I(e,t){t.update(()=>{if(null!==e){const r=c(e,KeyboardEvent)?null:e.clipboardData,a=f();if(null!==a&&!a.isCollapsed()&&null!=r){e.preventDefault();const o=n(t);null!==o&&r.setData("text/html",o),r.setData("text/plain",a.getTextContent())}}})}function J(n){return m(n.registerCommand(d,e=>{const t=f();return!!p(t)&&(t.deleteCharacter(e),!0)},g),n.registerCommand(C,e=>{const t=f();return!!p(t)&&(t.deleteWord(e),!0)},g),n.registerCommand(x,e=>{const t=f();return!!p(t)&&(t.deleteLine(e),!0)},g),n.registerCommand(v,t=>{const r=f();if(!p(r))return!1;if("string"==typeof t)r.insertText(t);else{const n=t.dataTransfer;if(null!=n)e(n,r);else{const e=t.data;e&&r.insertText(e)}}return!0},g),n.registerCommand(D,()=>{const e=f();return!!p(e)&&(e.removeText(),!0)},g),n.registerCommand(h,e=>{const t=f();return!!p(t)&&(t.insertLineBreak(e),!0)},g),n.registerCommand(T,()=>{const e=f();return!!p(e)&&(e.insertLineBreak(),!0)},g),n.registerCommand(b,e=>{const t=f();if(!p(t))return!1;const r=e,n=r.shiftKey;return!!s(t,!0)&&(r.preventDefault(),l(t,n,!0),!0)},g),n.registerCommand(y,e=>{const t=f();if(!p(t))return!1;const r=e,n=r.shiftKey;return!!s(t,!1)&&(r.preventDefault(),l(t,n,!1),!0)},g),n.registerCommand(K,e=>{const t=f();return!!p(t)&&((!k||"ko-KR"!==navigator.language)&&(e.preventDefault(),n.dispatchCommand(d,!0)))},g),n.registerCommand(L,e=>{const t=f();return!!p(t)&&(e.preventDefault(),n.dispatchCommand(d,!1))},g),n.registerCommand(B,e=>{const t=f();if(!p(t))return!1;if(null!==e){if((k||E||W)&&R)return!1;e.preventDefault()}return n.dispatchCommand(h,!1)},g),n.registerCommand(j,()=>(q(),!0),g),n.registerCommand(w,e=>{const t=f();return!!p(t)&&(I(e,n),!0)},g),n.registerCommand(z,e=>{const t=f();return!!p(t)&&(function(e,t){I(e,t),t.update(()=>{const e=f();p(e)&&e.removeText()})}(e,n),!0)},g),n.registerCommand(A,t=>{const r=f();return!!p(r)&&(function(t,r){t.preventDefault(),r.update(()=>{const r=f(),n=c(t,ClipboardEvent)?t.clipboardData:null;null!=n&&p(r)&&e(n,r)},{tag:H})}(t,n),!0)},g),n.registerCommand(F,e=>t(e,n),g),n.registerCommand(G,e=>{const t=f();return!!p(t)&&(t.isCollapsed()||null===e.dataTransfer||r(e.dataTransfer,n),!0)},g))}const M=u({conflictsWith:["@lexical/rich-text"],dependencies:[a,o,i],name:"@lexical/plain-text",register:J});export{M as PlainTextExtension,J as registerPlainText};
/**
* 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.
*
*/
import type {CommandPayloadType, LexicalEditor} from 'lexical';
import {
$getHtmlContent,
$handlePlainTextDrop,
$insertDataTransferForPlainText,
$writeDragSourceToDataTransfer,
} from '@lexical/clipboard';
import {DragonExtension} from '@lexical/dragon';
import {
NormalizeInlineElementsExtension,
NormalizeTripleClickSelectionExtension,
} from '@lexical/extension';
import {
$moveCharacter,
$shouldOverrideDefaultCharacterSelection,
} from '@lexical/selection';
import {mergeRegister, objectKlassEquals} from '@lexical/utils';
import {
$getSelection,
$isRangeSelection,
$selectAll,
CAN_USE_BEFORE_INPUT,
COMMAND_PRIORITY_EDITOR,
CONTROLLED_TEXT_INSERTION_COMMAND,
COPY_COMMAND,
CUT_COMMAND,
defineExtension,
DELETE_CHARACTER_COMMAND,
DELETE_LINE_COMMAND,
DELETE_WORD_COMMAND,
DRAGSTART_COMMAND,
DROP_COMMAND,
INSERT_LINE_BREAK_COMMAND,
INSERT_PARAGRAPH_COMMAND,
IS_APPLE_WEBKIT,
IS_IOS,
IS_SAFARI,
KEY_ARROW_LEFT_COMMAND,
KEY_ARROW_RIGHT_COMMAND,
KEY_BACKSPACE_COMMAND,
KEY_DELETE_COMMAND,
KEY_ENTER_COMMAND,
PASTE_COMMAND,
PASTE_TAG,
REMOVE_TEXT_COMMAND,
SELECT_ALL_COMMAND,
} from 'lexical';
function onCopyForPlainText(
event: CommandPayloadType<typeof COPY_COMMAND>,
editor: LexicalEditor,
): void {
editor.update(() => {
if (event !== null) {
const clipboardData = objectKlassEquals(event, KeyboardEvent)
? null
: event.clipboardData;
const selection = $getSelection();
if (
selection !== null &&
!selection.isCollapsed() &&
clipboardData != null
) {
event.preventDefault();
const htmlString = $getHtmlContent(editor);
if (htmlString !== null) {
clipboardData.setData('text/html', htmlString);
}
clipboardData.setData('text/plain', selection.getTextContent());
}
}
});
}
function onPasteForPlainText(
event: CommandPayloadType<typeof PASTE_COMMAND>,
editor: LexicalEditor,
): void {
event.preventDefault();
editor.update(
() => {
const selection = $getSelection();
const clipboardData = objectKlassEquals(event, ClipboardEvent)
? event.clipboardData
: null;
if (clipboardData != null && $isRangeSelection(selection)) {
$insertDataTransferForPlainText(clipboardData, selection);
}
},
{
tag: PASTE_TAG,
},
);
}
function onCutForPlainText(
event: CommandPayloadType<typeof CUT_COMMAND>,
editor: LexicalEditor,
): void {
onCopyForPlainText(event, editor);
editor.update(() => {
const selection = $getSelection();
if ($isRangeSelection(selection)) {
selection.removeText();
}
});
}
export function registerPlainText(editor: LexicalEditor): () => void {
const removeListener = mergeRegister(
editor.registerCommand<boolean>(
DELETE_CHARACTER_COMMAND,
isBackward => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.deleteCharacter(isBackward);
return true;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand<boolean>(
DELETE_WORD_COMMAND,
isBackward => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.deleteWord(isBackward);
return true;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand<boolean>(
DELETE_LINE_COMMAND,
isBackward => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.deleteLine(isBackward);
return true;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand<InputEvent | string>(
CONTROLLED_TEXT_INSERTION_COMMAND,
eventOrText => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
if (typeof eventOrText === 'string') {
selection.insertText(eventOrText);
} else {
const dataTransfer = eventOrText.dataTransfer;
if (dataTransfer != null) {
$insertDataTransferForPlainText(dataTransfer, selection);
} else {
const data = eventOrText.data;
if (data) {
selection.insertText(data);
}
}
}
return true;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand(
REMOVE_TEXT_COMMAND,
() => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.removeText();
return true;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand<boolean>(
INSERT_LINE_BREAK_COMMAND,
selectStart => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.insertLineBreak(selectStart);
return true;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand(
INSERT_PARAGRAPH_COMMAND,
() => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.insertLineBreak();
return true;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand<KeyboardEvent>(
KEY_ARROW_LEFT_COMMAND,
payload => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
const event = payload;
const isHoldingShift = event.shiftKey;
if ($shouldOverrideDefaultCharacterSelection(selection, true)) {
event.preventDefault();
$moveCharacter(selection, isHoldingShift, true);
return true;
}
return false;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand<KeyboardEvent>(
KEY_ARROW_RIGHT_COMMAND,
payload => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
const event = payload;
const isHoldingShift = event.shiftKey;
if ($shouldOverrideDefaultCharacterSelection(selection, false)) {
event.preventDefault();
$moveCharacter(selection, isHoldingShift, false);
return true;
}
return false;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand<KeyboardEvent>(
KEY_BACKSPACE_COMMAND,
event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
// Exception handling for iOS native behavior instead of Lexical's behavior when using Korean on iOS devices.
// more details - https://github.com/facebook/lexical/issues/5841
if (IS_IOS && navigator.language === 'ko-KR') {
return false;
}
event.preventDefault();
return editor.dispatchCommand(DELETE_CHARACTER_COMMAND, true);
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand<KeyboardEvent>(
KEY_DELETE_COMMAND,
event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
event.preventDefault();
return editor.dispatchCommand(DELETE_CHARACTER_COMMAND, false);
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand<KeyboardEvent | null>(
KEY_ENTER_COMMAND,
event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
if (event !== null) {
// If we have beforeinput, then we can avoid blocking
// the default behavior. This ensures that the iOS can
// intercept that we're actually inserting a paragraph,
// and autocomplete, autocapitalize etc work as intended.
// This can also cause a strange performance issue in
// Safari, where there is a noticeable pause due to
// preventing the key down of enter.
if (
(IS_IOS || IS_SAFARI || IS_APPLE_WEBKIT) &&
CAN_USE_BEFORE_INPUT
) {
return false;
}
event.preventDefault();
}
return editor.dispatchCommand(INSERT_LINE_BREAK_COMMAND, false);
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand(
SELECT_ALL_COMMAND,
() => {
$selectAll();
return true;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand(
COPY_COMMAND,
event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
onCopyForPlainText(event, editor);
return true;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand(
CUT_COMMAND,
event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
onCutForPlainText(event, editor);
return true;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand(
PASTE_COMMAND,
event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
onPasteForPlainText(event, editor);
return true;
},
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand<DragEvent>(
DROP_COMMAND,
event => $handlePlainTextDrop(event, editor),
COMMAND_PRIORITY_EDITOR,
),
editor.registerCommand<DragEvent>(
DRAGSTART_COMMAND,
event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
// Mark the drag source so a drop in a different editor can remove
// the source range to produce cut-and-paste semantics.
if (!selection.isCollapsed() && event.dataTransfer !== null) {
$writeDragSourceToDataTransfer(event.dataTransfer, editor);
}
return true;
},
COMMAND_PRIORITY_EDITOR,
),
);
return removeListener;
}
/**
* An extension to register \@lexical/plain-text behavior
*/
export const PlainTextExtension = defineExtension({
conflictsWith: ['@lexical/rich-text'],
dependencies: [
DragonExtension,
NormalizeInlineElementsExtension,
NormalizeTripleClickSelectionExtension,
],
name: '@lexical/plain-text',
register: registerPlainText,
});
+34
-20

@@ -10,5 +10,5 @@ {

"license": "MIT",
"version": "0.44.1-nightly.20260519.0",
"main": "LexicalPlainText.js",
"types": "index.d.ts",
"version": "0.45.0",
"main": "./dist/LexicalPlainText.js",
"types": "./dist/index.d.ts",
"repository": {

@@ -19,18 +19,19 @@ "type": "git",

},
"module": "LexicalPlainText.mjs",
"module": "./dist/LexicalPlainText.mjs",
"sideEffects": false,
"exports": {
".": {
"source": "./src/index.ts",
"import": {
"types": "./index.d.ts",
"development": "./LexicalPlainText.dev.mjs",
"production": "./LexicalPlainText.prod.mjs",
"node": "./LexicalPlainText.node.mjs",
"default": "./LexicalPlainText.mjs"
"types": "./dist/index.d.ts",
"development": "./dist/LexicalPlainText.dev.mjs",
"production": "./dist/LexicalPlainText.prod.mjs",
"node": "./dist/LexicalPlainText.node.mjs",
"default": "./dist/LexicalPlainText.mjs"
},
"require": {
"types": "./index.d.ts",
"development": "./LexicalPlainText.dev.js",
"production": "./LexicalPlainText.prod.js",
"default": "./LexicalPlainText.js"
"types": "./dist/index.d.ts",
"development": "./dist/LexicalPlainText.dev.js",
"production": "./dist/LexicalPlainText.prod.js",
"default": "./dist/LexicalPlainText.js"
}

@@ -40,9 +41,22 @@ }

"dependencies": {
"@lexical/clipboard": "0.44.1-nightly.20260519.0",
"@lexical/dragon": "0.44.1-nightly.20260519.0",
"@lexical/extension": "0.44.1-nightly.20260519.0",
"@lexical/selection": "0.44.1-nightly.20260519.0",
"@lexical/utils": "0.44.1-nightly.20260519.0",
"lexical": "0.44.1-nightly.20260519.0"
}
"@lexical/clipboard": "0.45.0",
"@lexical/utils": "0.45.0",
"@lexical/extension": "0.45.0",
"@lexical/selection": "0.45.0",
"lexical": "0.45.0",
"@lexical/dragon": "0.45.0"
},
"files": [
"dist",
"src",
"!src/__tests__",
"!src/__bench__",
"!src/__mocks__",
"!src/**/*.test.ts",
"!src/**/*.test.tsx",
"!src/**/*.bench.ts",
"!src/**/*.bench.tsx",
"README.md",
"LICENSE"
]
}
/**
* 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.
*
*/
import type { LexicalEditor } from 'lexical';
export declare function registerPlainText(editor: LexicalEditor): () => void;
/**
* An extension to register \@lexical/plain-text behavior
*/
export declare const PlainTextExtension: import("lexical").LexicalExtension<import("lexical").ExtensionConfigBase, "@lexical/plain-text", unknown, unknown>;
/**
* 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 clipboard = require('@lexical/clipboard');
var dragon = require('@lexical/dragon');
var extension = require('@lexical/extension');
var selection = require('@lexical/selection');
var utils = require('@lexical/utils');
var lexical = require('lexical');
/**
* 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.
*
*/
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
/**
* 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.
*
*/
const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
const IS_APPLE = CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
const CAN_USE_BEFORE_INPUT = CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
const IS_ANDROID = CAN_USE_DOM && /Android/.test(navigator.userAgent);
// Exclude Android — Android WebView's UA contains "Version/X.X ... Safari/537.36"
// which falsely matches the Safari regex, activating wrong composition code paths.
const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent) && !IS_ANDROID;
// Keep these in case we need to use them in the future.
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
const IS_CHROME = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
const IS_APPLE_WEBKIT = CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && IS_APPLE && !IS_CHROME;
/**
* 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.
*
*/
function onCopyForPlainText(event, editor) {
editor.update(() => {
if (event !== null) {
const clipboardData = utils.objectKlassEquals(event, KeyboardEvent) ? null : event.clipboardData;
const selection = lexical.$getSelection();
if (selection !== null && !selection.isCollapsed() && clipboardData != null) {
event.preventDefault();
const htmlString = clipboard.$getHtmlContent(editor);
if (htmlString !== null) {
clipboardData.setData('text/html', htmlString);
}
clipboardData.setData('text/plain', selection.getTextContent());
}
}
});
}
function onPasteForPlainText(event, editor) {
event.preventDefault();
editor.update(() => {
const selection = lexical.$getSelection();
const clipboardData = utils.objectKlassEquals(event, ClipboardEvent) ? event.clipboardData : null;
if (clipboardData != null && lexical.$isRangeSelection(selection)) {
clipboard.$insertDataTransferForPlainText(clipboardData, selection);
}
}, {
tag: lexical.PASTE_TAG
});
}
function onCutForPlainText(event, editor) {
onCopyForPlainText(event, editor);
editor.update(() => {
const selection = lexical.$getSelection();
if (lexical.$isRangeSelection(selection)) {
selection.removeText();
}
});
}
function registerPlainText(editor) {
const removeListener = utils.mergeRegister(editor.registerCommand(lexical.DELETE_CHARACTER_COMMAND, isBackward => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
selection.deleteCharacter(isBackward);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_WORD_COMMAND, isBackward => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
selection.deleteWord(isBackward);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_LINE_COMMAND, isBackward => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
selection.deleteLine(isBackward);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CONTROLLED_TEXT_INSERTION_COMMAND, eventOrText => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
if (typeof eventOrText === 'string') {
selection.insertText(eventOrText);
} else {
const dataTransfer = eventOrText.dataTransfer;
if (dataTransfer != null) {
clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
} else {
const data = eventOrText.data;
if (data) {
selection.insertText(data);
}
}
}
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.REMOVE_TEXT_COMMAND, () => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
selection.removeText();
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_LINE_BREAK_COMMAND, selectStart => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
selection.insertLineBreak(selectStart);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, () => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
selection.insertLineBreak();
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, payload => {
const selection$1 = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection$1)) {
return false;
}
const event = payload;
const isHoldingShift = event.shiftKey;
if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
event.preventDefault();
selection.$moveCharacter(selection$1, isHoldingShift, true);
return true;
}
return false;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, payload => {
const selection$1 = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection$1)) {
return false;
}
const event = payload;
const isHoldingShift = event.shiftKey;
if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
event.preventDefault();
selection.$moveCharacter(selection$1, isHoldingShift, false);
return true;
}
return false;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
// Exception handling for iOS native behavior instead of Lexical's behavior when using Korean on iOS devices.
// more details - https://github.com/facebook/lexical/issues/5841
if (IS_IOS && navigator.language === 'ko-KR') {
return false;
}
event.preventDefault();
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
event.preventDefault();
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, false);
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
if (event !== null) {
// If we have beforeinput, then we can avoid blocking
// the default behavior. This ensures that the iOS can
// intercept that we're actually inserting a paragraph,
// and autocomplete, autocapitalize etc work as intended.
// This can also cause a strange performance issue in
// Safari, where there is a noticeable pause due to
// preventing the key down of enter.
if ((IS_IOS || IS_SAFARI || IS_APPLE_WEBKIT) && CAN_USE_BEFORE_INPUT) {
return false;
}
event.preventDefault();
}
return editor.dispatchCommand(lexical.INSERT_LINE_BREAK_COMMAND, false);
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.SELECT_ALL_COMMAND, () => {
lexical.$selectAll();
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
onCopyForPlainText(event, editor);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CUT_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
onCutForPlainText(event, editor);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.PASTE_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
onPasteForPlainText(event, editor);
return true;
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DROP_COMMAND, event => clipboard.$handlePlainTextDrop(event, editor), lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DRAGSTART_COMMAND, event => {
const selection = lexical.$getSelection();
if (!lexical.$isRangeSelection(selection)) {
return false;
}
// Mark the drag source so a drop in a different editor can remove
// the source range to produce cut-and-paste semantics.
if (!selection.isCollapsed() && event.dataTransfer !== null) {
clipboard.$writeDragSourceToDataTransfer(event.dataTransfer, editor);
}
return true;
}, lexical.COMMAND_PRIORITY_EDITOR));
return removeListener;
}
/**
* An extension to register \@lexical/plain-text behavior
*/
const PlainTextExtension = lexical.defineExtension({
conflictsWith: ['@lexical/rich-text'],
dependencies: [dragon.DragonExtension, extension.NormalizeInlineElementsExtension],
name: '@lexical/plain-text',
register: registerPlainText
});
exports.PlainTextExtension = PlainTextExtension;
exports.registerPlainText = registerPlainText;
/**
* 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.
*
*/
import { $insertDataTransferForPlainText, $handlePlainTextDrop, $writeDragSourceToDataTransfer, $getHtmlContent } from '@lexical/clipboard';
import { DragonExtension } from '@lexical/dragon';
import { NormalizeInlineElementsExtension } from '@lexical/extension';
import { $shouldOverrideDefaultCharacterSelection, $moveCharacter } from '@lexical/selection';
import { mergeRegister, objectKlassEquals } from '@lexical/utils';
import { defineExtension, DELETE_CHARACTER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, REMOVE_TEXT_COMMAND, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, SELECT_ALL_COMMAND, $selectAll, COPY_COMMAND, CUT_COMMAND, PASTE_COMMAND, DROP_COMMAND, DRAGSTART_COMMAND, PASTE_TAG } from 'lexical';
/**
* 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.
*
*/
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
/**
* 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.
*
*/
const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
const IS_APPLE = CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
const CAN_USE_BEFORE_INPUT = CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
const IS_ANDROID = CAN_USE_DOM && /Android/.test(navigator.userAgent);
// Exclude Android — Android WebView's UA contains "Version/X.X ... Safari/537.36"
// which falsely matches the Safari regex, activating wrong composition code paths.
const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent) && !IS_ANDROID;
// Keep these in case we need to use them in the future.
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
const IS_CHROME = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
const IS_APPLE_WEBKIT = CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && IS_APPLE && !IS_CHROME;
/**
* 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.
*
*/
function onCopyForPlainText(event, editor) {
editor.update(() => {
if (event !== null) {
const clipboardData = objectKlassEquals(event, KeyboardEvent) ? null : event.clipboardData;
const selection = $getSelection();
if (selection !== null && !selection.isCollapsed() && clipboardData != null) {
event.preventDefault();
const htmlString = $getHtmlContent(editor);
if (htmlString !== null) {
clipboardData.setData('text/html', htmlString);
}
clipboardData.setData('text/plain', selection.getTextContent());
}
}
});
}
function onPasteForPlainText(event, editor) {
event.preventDefault();
editor.update(() => {
const selection = $getSelection();
const clipboardData = objectKlassEquals(event, ClipboardEvent) ? event.clipboardData : null;
if (clipboardData != null && $isRangeSelection(selection)) {
$insertDataTransferForPlainText(clipboardData, selection);
}
}, {
tag: PASTE_TAG
});
}
function onCutForPlainText(event, editor) {
onCopyForPlainText(event, editor);
editor.update(() => {
const selection = $getSelection();
if ($isRangeSelection(selection)) {
selection.removeText();
}
});
}
function registerPlainText(editor) {
const removeListener = mergeRegister(editor.registerCommand(DELETE_CHARACTER_COMMAND, isBackward => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.deleteCharacter(isBackward);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DELETE_WORD_COMMAND, isBackward => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.deleteWord(isBackward);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DELETE_LINE_COMMAND, isBackward => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.deleteLine(isBackward);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(CONTROLLED_TEXT_INSERTION_COMMAND, eventOrText => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
if (typeof eventOrText === 'string') {
selection.insertText(eventOrText);
} else {
const dataTransfer = eventOrText.dataTransfer;
if (dataTransfer != null) {
$insertDataTransferForPlainText(dataTransfer, selection);
} else {
const data = eventOrText.data;
if (data) {
selection.insertText(data);
}
}
}
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(REMOVE_TEXT_COMMAND, () => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.removeText();
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INSERT_LINE_BREAK_COMMAND, selectStart => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.insertLineBreak(selectStart);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INSERT_PARAGRAPH_COMMAND, () => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
selection.insertLineBreak();
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_LEFT_COMMAND, payload => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
const event = payload;
const isHoldingShift = event.shiftKey;
if ($shouldOverrideDefaultCharacterSelection(selection, true)) {
event.preventDefault();
$moveCharacter(selection, isHoldingShift, true);
return true;
}
return false;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_RIGHT_COMMAND, payload => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
const event = payload;
const isHoldingShift = event.shiftKey;
if ($shouldOverrideDefaultCharacterSelection(selection, false)) {
event.preventDefault();
$moveCharacter(selection, isHoldingShift, false);
return true;
}
return false;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_BACKSPACE_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
// Exception handling for iOS native behavior instead of Lexical's behavior when using Korean on iOS devices.
// more details - https://github.com/facebook/lexical/issues/5841
if (IS_IOS && navigator.language === 'ko-KR') {
return false;
}
event.preventDefault();
return editor.dispatchCommand(DELETE_CHARACTER_COMMAND, true);
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_DELETE_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
event.preventDefault();
return editor.dispatchCommand(DELETE_CHARACTER_COMMAND, false);
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ENTER_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
if (event !== null) {
// If we have beforeinput, then we can avoid blocking
// the default behavior. This ensures that the iOS can
// intercept that we're actually inserting a paragraph,
// and autocomplete, autocapitalize etc work as intended.
// This can also cause a strange performance issue in
// Safari, where there is a noticeable pause due to
// preventing the key down of enter.
if ((IS_IOS || IS_SAFARI || IS_APPLE_WEBKIT) && CAN_USE_BEFORE_INPUT) {
return false;
}
event.preventDefault();
}
return editor.dispatchCommand(INSERT_LINE_BREAK_COMMAND, false);
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(SELECT_ALL_COMMAND, () => {
$selectAll();
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(COPY_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
onCopyForPlainText(event, editor);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(CUT_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
onCutForPlainText(event, editor);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(PASTE_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
onPasteForPlainText(event, editor);
return true;
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DROP_COMMAND, event => $handlePlainTextDrop(event, editor), COMMAND_PRIORITY_EDITOR), editor.registerCommand(DRAGSTART_COMMAND, event => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
// Mark the drag source so a drop in a different editor can remove
// the source range to produce cut-and-paste semantics.
if (!selection.isCollapsed() && event.dataTransfer !== null) {
$writeDragSourceToDataTransfer(event.dataTransfer, editor);
}
return true;
}, COMMAND_PRIORITY_EDITOR));
return removeListener;
}
/**
* An extension to register \@lexical/plain-text behavior
*/
const PlainTextExtension = defineExtension({
conflictsWith: ['@lexical/rich-text'],
dependencies: [DragonExtension, NormalizeInlineElementsExtension],
name: '@lexical/plain-text',
register: registerPlainText
});
export { PlainTextExtension, registerPlainText };
/**
* 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'
const LexicalPlainText = process.env.NODE_ENV !== 'production' ? require('./LexicalPlainText.dev.js') : require('./LexicalPlainText.prod.js');
module.exports = LexicalPlainText;

Sorry, the diff of this file is not supported yet

/**
* 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.
*
*/
import * as modDev from './LexicalPlainText.dev.mjs';
import * as modProd from './LexicalPlainText.prod.mjs';
const mod = process.env.NODE_ENV !== 'production' ? modDev : modProd;
export const PlainTextExtension = mod.PlainTextExtension;
export const registerPlainText = mod.registerPlainText;
/**
* 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.
*
*/
const mod = await (process.env.NODE_ENV !== 'production' ? import('./LexicalPlainText.dev.mjs') : import('./LexicalPlainText.prod.mjs'));
export const PlainTextExtension = mod.PlainTextExtension;
export const registerPlainText = mod.registerPlainText;
/**
* 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"),i=require("@lexical/selection"),r=require("@lexical/utils"),o=require("lexical");const a="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,l=a&&"documentMode"in document?document.documentMode:null,s=a&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),c=!(!a||!("InputEvent"in window)||l)&&"getTargetRanges"in new window.InputEvent("input"),R=a&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,D=a&&/Android/.test(navigator.userAgent),O=a&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!D,g=a&&/^(?=.*Chrome).*/i.test(navigator.userAgent),C=a&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&s&&!g;function M(t,n){n.update(()=>{if(null!==t){const i=r.objectKlassEquals(t,KeyboardEvent)?null:t.clipboardData,a=o.$getSelection();if(null!==a&&!a.isCollapsed()&&null!=i){t.preventDefault();const r=e.$getHtmlContent(n);null!==r&&i.setData("text/html",r),i.setData("text/plain",a.getTextContent())}}})}function T(t){const n=r.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 i=t.dataTransfer;if(null!=i)e.$insertDataTransferForPlainText(i,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,r=n.shiftKey;return!!i.$shouldOverrideDefaultCharacterSelection(t,!0)&&(n.preventDefault(),i.$moveCharacter(t,r,!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,r=n.shiftKey;return!!i.$shouldOverrideDefaultCharacterSelection(t,!1)&&(n.preventDefault(),i.$moveCharacter(t,r,!1),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.KEY_BACKSPACE_COMMAND,e=>{const n=o.$getSelection();return!!o.$isRangeSelection(n)&&((!R||"ko-KR"!==navigator.language)&&(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((R||O||C)&&c)return!1;e.preventDefault()}return t.dispatchCommand(o.INSERT_LINE_BREAK_COMMAND,!1)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.SELECT_ALL_COMMAND,()=>(o.$selectAll(),!0),o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.COPY_COMMAND,e=>{const n=o.$getSelection();return!!o.$isRangeSelection(n)&&(M(e,t),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.CUT_COMMAND,e=>{const n=o.$getSelection();return!!o.$isRangeSelection(n)&&(function(e,t){M(e,t),t.update(()=>{const e=o.$getSelection();o.$isRangeSelection(e)&&e.removeText()})}(e,t),!0)},o.COMMAND_PRIORITY_EDITOR),t.registerCommand(o.PASTE_COMMAND,n=>{const i=o.$getSelection();return!!o.$isRangeSelection(i)&&(function(t,n){t.preventDefault(),n.update(()=>{const n=o.$getSelection(),i=r.objectKlassEquals(t,ClipboardEvent)?t.clipboardData:null;null!=i&&o.$isRangeSelection(n)&&e.$insertDataTransferForPlainText(i,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 i=o.$getSelection();return!!o.$isRangeSelection(i)&&(i.isCollapsed()||null===n.dataTransfer||e.$writeDragSourceToDataTransfer(n.dataTransfer,t),!0)},o.COMMAND_PRIORITY_EDITOR));return n}const _=o.defineExtension({conflictsWith:["@lexical/rich-text"],dependencies:[t.DragonExtension,n.NormalizeInlineElementsExtension],name:"@lexical/plain-text",register:T});exports.PlainTextExtension=_,exports.registerPlainText=T;
/**
* 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.
*
*/
import{$insertDataTransferForPlainText as e,$handlePlainTextDrop as t,$writeDragSourceToDataTransfer as n,$getHtmlContent as r}from"@lexical/clipboard";import{DragonExtension as o}from"@lexical/dragon";import{NormalizeInlineElementsExtension as i}from"@lexical/extension";import{$shouldOverrideDefaultCharacterSelection as a,$moveCharacter as s}from"@lexical/selection";import{mergeRegister as d,objectKlassEquals as l}from"@lexical/utils";import{defineExtension as m,DELETE_CHARACTER_COMMAND as u,$getSelection as c,$isRangeSelection as g,COMMAND_PRIORITY_EDITOR as f,DELETE_WORD_COMMAND as p,DELETE_LINE_COMMAND as C,CONTROLLED_TEXT_INSERTION_COMMAND as v,REMOVE_TEXT_COMMAND as x,INSERT_LINE_BREAK_COMMAND as w,INSERT_PARAGRAPH_COMMAND as h,KEY_ARROW_LEFT_COMMAND as D,KEY_ARROW_RIGHT_COMMAND as T,KEY_BACKSPACE_COMMAND as A,KEY_DELETE_COMMAND as b,KEY_ENTER_COMMAND as P,SELECT_ALL_COMMAND as y,$selectAll as E,COPY_COMMAND as K,CUT_COMMAND as M,PASTE_COMMAND as k,DROP_COMMAND as L,DRAGSTART_COMMAND as S,PASTE_TAG as W}from"lexical";const B="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,I=B&&"documentMode"in document?document.documentMode:null,R=B&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),V=!(!B||!("InputEvent"in window)||I)&&"getTargetRanges"in new window.InputEvent("input"),j=B&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,q=B&&/Android/.test(navigator.userAgent),z=B&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!q,F=B&&/^(?=.*Chrome).*/i.test(navigator.userAgent),G=B&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&R&&!F;function H(e,t){t.update(()=>{if(null!==e){const n=l(e,KeyboardEvent)?null:e.clipboardData,o=c();if(null!==o&&!o.isCollapsed()&&null!=n){e.preventDefault();const i=r(t);null!==i&&n.setData("text/html",i),n.setData("text/plain",o.getTextContent())}}})}function J(r){return d(r.registerCommand(u,e=>{const t=c();return!!g(t)&&(t.deleteCharacter(e),!0)},f),r.registerCommand(p,e=>{const t=c();return!!g(t)&&(t.deleteWord(e),!0)},f),r.registerCommand(C,e=>{const t=c();return!!g(t)&&(t.deleteLine(e),!0)},f),r.registerCommand(v,t=>{const n=c();if(!g(n))return!1;if("string"==typeof t)n.insertText(t);else{const r=t.dataTransfer;if(null!=r)e(r,n);else{const e=t.data;e&&n.insertText(e)}}return!0},f),r.registerCommand(x,()=>{const e=c();return!!g(e)&&(e.removeText(),!0)},f),r.registerCommand(w,e=>{const t=c();return!!g(t)&&(t.insertLineBreak(e),!0)},f),r.registerCommand(h,()=>{const e=c();return!!g(e)&&(e.insertLineBreak(),!0)},f),r.registerCommand(D,e=>{const t=c();if(!g(t))return!1;const n=e,r=n.shiftKey;return!!a(t,!0)&&(n.preventDefault(),s(t,r,!0),!0)},f),r.registerCommand(T,e=>{const t=c();if(!g(t))return!1;const n=e,r=n.shiftKey;return!!a(t,!1)&&(n.preventDefault(),s(t,r,!1),!0)},f),r.registerCommand(A,e=>{const t=c();return!!g(t)&&((!j||"ko-KR"!==navigator.language)&&(e.preventDefault(),r.dispatchCommand(u,!0)))},f),r.registerCommand(b,e=>{const t=c();return!!g(t)&&(e.preventDefault(),r.dispatchCommand(u,!1))},f),r.registerCommand(P,e=>{const t=c();if(!g(t))return!1;if(null!==e){if((j||z||G)&&V)return!1;e.preventDefault()}return r.dispatchCommand(w,!1)},f),r.registerCommand(y,()=>(E(),!0),f),r.registerCommand(K,e=>{const t=c();return!!g(t)&&(H(e,r),!0)},f),r.registerCommand(M,e=>{const t=c();return!!g(t)&&(function(e,t){H(e,t),t.update(()=>{const e=c();g(e)&&e.removeText()})}(e,r),!0)},f),r.registerCommand(k,t=>{const n=c();return!!g(n)&&(function(t,n){t.preventDefault(),n.update(()=>{const n=c(),r=l(t,ClipboardEvent)?t.clipboardData:null;null!=r&&g(n)&&e(r,n)},{tag:W})}(t,r),!0)},f),r.registerCommand(L,e=>t(e,r),f),r.registerCommand(S,e=>{const t=c();return!!g(t)&&(t.isCollapsed()||null===e.dataTransfer||n(e.dataTransfer,r),!0)},f))}const N=m({conflictsWith:["@lexical/rich-text"],dependencies:[o,i],name:"@lexical/plain-text",register:J});export{N as PlainTextExtension,J as registerPlainText};