@lexical/plain-text 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,11 @@
6
6
  *
7
7
  */
8
8
  import type {EditorState, LexicalEditor} from 'lexical';
9
- export type InitialEditorStateType = null | string | EditorState | (() => void);
9
+ export type InitialEditorStateType =
10
+ | null
11
+ | string
12
+ | EditorState
13
+ | ((editor: LexicalEditor) => void);
10
14
 
11
15
  declare function registerPlainText(
12
16
  editor: LexicalEditor,
@@ -94,9 +94,8 @@ function initializeEditor(editor, initialEditorState) {
94
94
  } else if (initialEditorState === undefined) {
95
95
  editor.update(() => {
96
96
  const root = lexical.$getRoot();
97
- const firstChild = root.getFirstChild();
98
97
 
99
- if (firstChild === null) {
98
+ if (root.isEmpty()) {
100
99
  const paragraph = lexical.$createParagraphNode();
101
100
  root.append(paragraph);
102
101
  const activeElement = document.activeElement;
@@ -123,7 +122,13 @@ function initializeEditor(editor, initialEditorState) {
123
122
 
124
123
  case 'function':
125
124
  {
126
- editor.update(initialEditorState, updateOptions);
125
+ editor.update(() => {
126
+ const root = lexical.$getRoot();
127
+
128
+ if (root.isEmpty()) {
129
+ initialEditorState(editor);
130
+ }
131
+ }, updateOptions);
127
132
  break;
128
133
  }
129
134
  }
@@ -7,7 +7,11 @@
7
7
  * @flow strict
8
8
  */
9
9
  import type {EditorState, LexicalEditor} from 'lexical';
10
- export type InitialEditorStateType = null | string | EditorState | (() => void);
10
+ export type InitialEditorStateType =
11
+ | null
12
+ | string
13
+ | EditorState
14
+ | ((editor: LexicalEditor) => void);
11
15
 
12
16
  declare export function registerPlainText(
13
17
  editor: LexicalEditor,
@@ -5,13 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict';var a=require("@lexical/clipboard"),g=require("@lexical/selection"),k=require("@lexical/utils"),l=require("lexical");let m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,n=m&&"documentMode"in document?document.documentMode:null;m&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);m&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
8
- let p=m&&"InputEvent"in window&&!n?"getTargetRanges"in new window.InputEvent("input"):!1,q=m&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),r=m&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,t={tag:"history-merge"};function u(d,e){d.preventDefault();e.update(()=>{let f=d.clipboardData,b=l.$getSelection();if(null!==b&&null!=f){let c=a.$getHtmlContent(e);null!==c&&f.setData("text/html",c);f.setData("text/plain",b.getTextContent())}})}
9
- function v(d,e){d.preventDefault();e.update(()=>{let f=l.$getSelection(),b=d.clipboardData;null!=b&&l.$isRangeSelection(f)&&a.$insertDataTransferForPlainText(b,f)})}function w(d,e){u(d,e);e.update(()=>{let f=l.$getSelection();l.$isRangeSelection(f)&&f.removeText()})}
10
- function x(d,e){if(null!==e)if(void 0===e)d.update(()=>{var f=l.$getRoot();if(null===f.getFirstChild()){let b=l.$createParagraphNode();f.append(b);f=document.activeElement;(null!==l.$getSelection()||null!==f&&f===d.getRootElement())&&b.select()}},t);else if(null!==e)switch(typeof e){case "string":e=d.parseEditorState(e);d.setEditorState(e,t);break;case "object":d.setEditorState(e,t);break;case "function":d.update(e,t)}}
11
- exports.registerPlainText=function(d,e){let f=k.mergeRegister(d.registerCommand(l.DELETE_CHARACTER_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.deleteCharacter(b);return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.DELETE_WORD_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.deleteWord(b);return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.DELETE_LINE_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.deleteLine(b);
8
+ let p=m&&"InputEvent"in window&&!n?"getTargetRanges"in new window.InputEvent("input"):!1,q=m&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),r=m&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,t={tag:"history-merge"};function u(d,f){d.preventDefault();f.update(()=>{let e=d.clipboardData,b=l.$getSelection();if(null!==b&&null!=e){let c=a.$getHtmlContent(f);null!==c&&e.setData("text/html",c);e.setData("text/plain",b.getTextContent())}})}
9
+ function v(d,f){d.preventDefault();f.update(()=>{let e=l.$getSelection(),b=d.clipboardData;null!=b&&l.$isRangeSelection(e)&&a.$insertDataTransferForPlainText(b,e)})}function w(d,f){u(d,f);f.update(()=>{let e=l.$getSelection();l.$isRangeSelection(e)&&e.removeText()})}
10
+ function x(d,f){if(null!==f)if(void 0===f)d.update(()=>{var e=l.$getRoot();if(e.isEmpty()){let b=l.$createParagraphNode();e.append(b);e=document.activeElement;(null!==l.$getSelection()||null!==e&&e===d.getRootElement())&&b.select()}},t);else if(null!==f)switch(typeof f){case "string":let e=d.parseEditorState(f);d.setEditorState(e,t);break;case "object":d.setEditorState(f,t);break;case "function":d.update(()=>{l.$getRoot().isEmpty()&&f(d)},t)}}
11
+ exports.registerPlainText=function(d,f){let e=k.mergeRegister(d.registerCommand(l.DELETE_CHARACTER_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.deleteCharacter(b);return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.DELETE_WORD_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.deleteWord(b);return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.DELETE_LINE_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.deleteLine(b);
12
12
  return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;if("string"===typeof b)c.insertText(b);else{const h=b.dataTransfer;null!=h?a.$insertDataTransferForPlainText(h,c):(b=b.data)&&c.insertText(b)}return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.REMOVE_TEXT_COMMAND,()=>{const b=l.$getSelection();if(!l.$isRangeSelection(b))return!1;b.removeText();return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.INSERT_LINE_BREAK_COMMAND,
13
13
  b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.insertLineBreak(b);return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.INSERT_PARAGRAPH_COMMAND,()=>{const b=l.$getSelection();if(!l.$isRangeSelection(b))return!1;b.insertLineBreak();return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.KEY_ARROW_LEFT_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;const h=b.shiftKey;return g.$shouldOverrideDefaultCharacterSelection(c,!0)?(b.preventDefault(),g.$moveCharacter(c,
14
14
  h,!0),!0):!1},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.KEY_ARROW_RIGHT_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;const h=b.shiftKey;return g.$shouldOverrideDefaultCharacterSelection(c,!1)?(b.preventDefault(),g.$moveCharacter(c,h,!1),!0):!1},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.KEY_BACKSPACE_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;b.preventDefault();return d.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0)},l.COMMAND_PRIORITY_EDITOR),
15
15
  d.registerCommand(l.KEY_DELETE_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;b.preventDefault();return d.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!1)},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.KEY_ENTER_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;if(null!==b){if((r||q)&&p)return!1;b.preventDefault()}return d.dispatchCommand(l.INSERT_LINE_BREAK_COMMAND,!1)},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.COPY_COMMAND,b=>{const c=l.$getSelection();
16
16
  if(!l.$isRangeSelection(c))return!1;u(b,d);return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.CUT_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;w(b,d);return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.PASTE_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;v(b,d);return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.DROP_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;b.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),
17
- d.registerCommand(l.DRAGSTART_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;b.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR));x(d,e);return f}
17
+ d.registerCommand(l.DRAGSTART_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;b.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR));x(d,f);return e}
package/package.json CHANGED
@@ -7,13 +7,13 @@
7
7
  "plain-text"
8
8
  ],
9
9
  "license": "MIT",
10
- "version": "0.3.2",
10
+ "version": "0.3.3",
11
11
  "main": "LexicalPlainText.js",
12
12
  "peerDependencies": {
13
- "lexical": "0.3.2",
14
- "@lexical/utils": "0.3.2",
15
- "@lexical/selection": "0.3.2",
16
- "@lexical/clipboard": "0.3.2"
13
+ "lexical": "0.3.3",
14
+ "@lexical/utils": "0.3.3",
15
+ "@lexical/selection": "0.3.3",
16
+ "@lexical/clipboard": "0.3.3"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",