@lexical/plain-text 0.3.10 → 0.4.1

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.
@@ -29,13 +29,7 @@ const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !w
29
29
  // export const IS_CHROME: boolean = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
30
30
  // export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
31
31
 
32
- /**
33
- * Copyright (c) Meta Platforms, Inc. and affiliates.
34
- *
35
- * This source code is licensed under the MIT license found in the
36
- * LICENSE file in the root directory of this source tree.
37
- *
38
- */
32
+ /** @module @lexical/plain-text */
39
33
  // Convoluted logic to make this work with Flow. Order matters.
40
34
  const options = {
41
35
  tag: 'history-merge'
@@ -44,21 +38,19 @@ const setEditorOptions = options;
44
38
  const updateOptions = options;
45
39
 
46
40
  function onCopyForPlainText(event, editor) {
47
- event.preventDefault();
48
41
  editor.update(() => {
49
42
  const clipboardData = event instanceof KeyboardEvent ? null : event.clipboardData;
50
43
  const selection = lexical.$getSelection();
51
44
 
52
- if (selection !== null) {
53
- if (clipboardData != null) {
54
- const htmlString = clipboard.$getHtmlContent(editor);
55
-
56
- if (htmlString !== null) {
57
- clipboardData.setData('text/html', htmlString);
58
- }
45
+ if (selection !== null && clipboardData != null) {
46
+ event.preventDefault();
47
+ const htmlString = clipboard.$getHtmlContent(editor);
59
48
 
60
- clipboardData.setData('text/plain', selection.getTextContent());
49
+ if (htmlString !== null) {
50
+ clipboardData.setData('text/html', htmlString);
61
51
  }
52
+
53
+ clipboardData.setData('text/plain', selection.getTextContent());
62
54
  }
63
55
  });
64
56
  }
@@ -5,7 +5,7 @@
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,f){d.preventDefault();f.update(()=>{let e=d instanceof KeyboardEvent?null: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())}})}
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){f.update(()=>{let e=d instanceof KeyboardEvent?null:d.clipboardData,b=l.$getSelection();if(null!==b&&null!=e){d.preventDefault();let c=a.$getHtmlContent(f);null!==c&&e.setData("text/html",c);e.setData("text/plain",b.getTextContent())}})}
9
9
  function v(d,f){d.preventDefault();f.update(()=>{let e=l.$getSelection(),b=d instanceof InputEvent?null:d.clipboardData;null!=b&&l.$isRangeSelection(e)&&a.$insertDataTransferForPlainText(b,e)},{tag:"paste"})}function w(d,f){u(d,f);f.update(()=>{let e=l.$getSelection();l.$isRangeSelection(e)&&e.removeText()})}
10
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
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);
package/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /** @module @lexical/plain-text */
1
2
  /**
2
3
  * Copyright (c) Meta Platforms, Inc. and affiliates.
3
4
  *
package/package.json CHANGED
@@ -7,13 +7,13 @@
7
7
  "plain-text"
8
8
  ],
9
9
  "license": "MIT",
10
- "version": "0.3.10",
10
+ "version": "0.4.1",
11
11
  "main": "LexicalPlainText.js",
12
12
  "peerDependencies": {
13
- "lexical": "0.3.10",
14
- "@lexical/utils": "0.3.10",
15
- "@lexical/selection": "0.3.10",
16
- "@lexical/clipboard": "0.3.10"
13
+ "lexical": "0.4.1",
14
+ "@lexical/utils": "0.4.1",
15
+ "@lexical/selection": "0.4.1",
16
+ "@lexical/clipboard": "0.4.1"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",