@lexical/plain-text 0.7.8 → 0.7.9

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.
@@ -18,6 +18,7 @@ var lexical = require('lexical');
18
18
  * LICENSE file in the root directory of this source tree.
19
19
  *
20
20
  */
21
+
21
22
  const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
22
23
 
23
24
  /**
@@ -32,37 +33,33 @@ CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
32
33
  CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
33
34
  const CAN_USE_BEFORE_INPUT = CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
34
35
  const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
35
- const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; // Keep these in case we need to use them in the future.
36
- // export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
36
+ const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
37
37
 
38
- CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent); // export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
38
+ // Keep these in case we need to use them in the future.
39
+ // export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
40
+ CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
41
+ // export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
39
42
 
40
43
  /** @module @lexical/plain-text */
41
-
42
44
  function onCopyForPlainText(event, editor) {
43
45
  editor.update(() => {
44
46
  const clipboardData = event instanceof KeyboardEvent ? null : event.clipboardData;
45
47
  const selection = lexical.$getSelection();
46
-
47
48
  if (selection !== null && clipboardData != null) {
48
49
  event.preventDefault();
49
50
  const htmlString = clipboard.$getHtmlContent(editor);
50
-
51
51
  if (htmlString !== null) {
52
52
  clipboardData.setData('text/html', htmlString);
53
53
  }
54
-
55
54
  clipboardData.setData('text/plain', selection.getTextContent());
56
55
  }
57
56
  });
58
57
  }
59
-
60
58
  function onPasteForPlainText(event, editor) {
61
59
  event.preventDefault();
62
60
  editor.update(() => {
63
61
  const selection = lexical.$getSelection();
64
62
  const clipboardData = event instanceof InputEvent || event instanceof KeyboardEvent ? null : event.clipboardData;
65
-
66
63
  if (clipboardData != null && lexical.$isRangeSelection(selection)) {
67
64
  clipboard.$insertDataTransferForPlainText(clipboardData, selection);
68
65
  }
@@ -70,156 +67,122 @@ function onPasteForPlainText(event, editor) {
70
67
  tag: 'paste'
71
68
  });
72
69
  }
73
-
74
70
  function onCutForPlainText(event, editor) {
75
71
  onCopyForPlainText(event, editor);
76
72
  editor.update(() => {
77
73
  const selection = lexical.$getSelection();
78
-
79
74
  if (lexical.$isRangeSelection(selection)) {
80
75
  selection.removeText();
81
76
  }
82
77
  });
83
78
  }
84
-
85
79
  function registerPlainText(editor) {
86
80
  const removeListener = utils.mergeRegister(editor.registerCommand(lexical.DELETE_CHARACTER_COMMAND, isBackward => {
87
81
  const selection = lexical.$getSelection();
88
-
89
82
  if (!lexical.$isRangeSelection(selection)) {
90
83
  return false;
91
84
  }
92
-
93
85
  selection.deleteCharacter(isBackward);
94
86
  return true;
95
87
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_WORD_COMMAND, isBackward => {
96
88
  const selection = lexical.$getSelection();
97
-
98
89
  if (!lexical.$isRangeSelection(selection)) {
99
90
  return false;
100
91
  }
101
-
102
92
  selection.deleteWord(isBackward);
103
93
  return true;
104
94
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_LINE_COMMAND, isBackward => {
105
95
  const selection = lexical.$getSelection();
106
-
107
96
  if (!lexical.$isRangeSelection(selection)) {
108
97
  return false;
109
98
  }
110
-
111
99
  selection.deleteLine(isBackward);
112
100
  return true;
113
101
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CONTROLLED_TEXT_INSERTION_COMMAND, eventOrText => {
114
102
  const selection = lexical.$getSelection();
115
-
116
103
  if (!lexical.$isRangeSelection(selection)) {
117
104
  return false;
118
105
  }
119
-
120
106
  if (typeof eventOrText === 'string') {
121
107
  selection.insertText(eventOrText);
122
108
  } else {
123
109
  const dataTransfer = eventOrText.dataTransfer;
124
-
125
110
  if (dataTransfer != null) {
126
111
  clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
127
112
  } else {
128
113
  const data = eventOrText.data;
129
-
130
114
  if (data) {
131
115
  selection.insertText(data);
132
116
  }
133
117
  }
134
118
  }
135
-
136
119
  return true;
137
120
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.REMOVE_TEXT_COMMAND, () => {
138
121
  const selection = lexical.$getSelection();
139
-
140
122
  if (!lexical.$isRangeSelection(selection)) {
141
123
  return false;
142
124
  }
143
-
144
125
  selection.removeText();
145
126
  return true;
146
127
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_LINE_BREAK_COMMAND, selectStart => {
147
128
  const selection = lexical.$getSelection();
148
-
149
129
  if (!lexical.$isRangeSelection(selection)) {
150
130
  return false;
151
131
  }
152
-
153
132
  selection.insertLineBreak(selectStart);
154
133
  return true;
155
134
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, () => {
156
135
  const selection = lexical.$getSelection();
157
-
158
136
  if (!lexical.$isRangeSelection(selection)) {
159
137
  return false;
160
138
  }
161
-
162
139
  selection.insertLineBreak();
163
140
  return true;
164
141
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, payload => {
165
142
  const selection$1 = lexical.$getSelection();
166
-
167
143
  if (!lexical.$isRangeSelection(selection$1)) {
168
144
  return false;
169
145
  }
170
-
171
146
  const event = payload;
172
147
  const isHoldingShift = event.shiftKey;
173
-
174
148
  if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
175
149
  event.preventDefault();
176
150
  selection.$moveCharacter(selection$1, isHoldingShift, true);
177
151
  return true;
178
152
  }
179
-
180
153
  return false;
181
154
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, payload => {
182
155
  const selection$1 = lexical.$getSelection();
183
-
184
156
  if (!lexical.$isRangeSelection(selection$1)) {
185
157
  return false;
186
158
  }
187
-
188
159
  const event = payload;
189
160
  const isHoldingShift = event.shiftKey;
190
-
191
161
  if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
192
162
  event.preventDefault();
193
163
  selection.$moveCharacter(selection$1, isHoldingShift, false);
194
164
  return true;
195
165
  }
196
-
197
166
  return false;
198
167
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, event => {
199
168
  const selection = lexical.$getSelection();
200
-
201
169
  if (!lexical.$isRangeSelection(selection)) {
202
170
  return false;
203
171
  }
204
-
205
172
  event.preventDefault();
206
173
  return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
207
174
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND, event => {
208
175
  const selection = lexical.$getSelection();
209
-
210
176
  if (!lexical.$isRangeSelection(selection)) {
211
177
  return false;
212
178
  }
213
-
214
179
  event.preventDefault();
215
180
  return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, false);
216
181
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
217
182
  const selection = lexical.$getSelection();
218
-
219
183
  if (!lexical.$isRangeSelection(selection)) {
220
184
  return false;
221
185
  }
222
-
223
186
  if (event !== null) {
224
187
  // If we have beforeinput, then we can avoid blocking
225
188
  // the default behavior. This ensures that the iOS can
@@ -231,56 +194,46 @@ function registerPlainText(editor) {
231
194
  if ((IS_IOS || IS_SAFARI) && CAN_USE_BEFORE_INPUT) {
232
195
  return false;
233
196
  }
234
-
235
197
  event.preventDefault();
236
198
  }
237
-
238
199
  return editor.dispatchCommand(lexical.INSERT_LINE_BREAK_COMMAND, false);
239
200
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND, event => {
240
201
  const selection = lexical.$getSelection();
241
-
242
202
  if (!lexical.$isRangeSelection(selection)) {
243
203
  return false;
244
204
  }
245
-
246
205
  onCopyForPlainText(event, editor);
247
206
  return true;
248
207
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CUT_COMMAND, event => {
249
208
  const selection = lexical.$getSelection();
250
-
251
209
  if (!lexical.$isRangeSelection(selection)) {
252
210
  return false;
253
211
  }
254
-
255
212
  onCutForPlainText(event, editor);
256
213
  return true;
257
214
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.PASTE_COMMAND, event => {
258
215
  const selection = lexical.$getSelection();
259
-
260
216
  if (!lexical.$isRangeSelection(selection)) {
261
217
  return false;
262
218
  }
263
-
264
219
  onPasteForPlainText(event, editor);
265
220
  return true;
266
221
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DROP_COMMAND, event => {
267
222
  const selection = lexical.$getSelection();
268
-
269
223
  if (!lexical.$isRangeSelection(selection)) {
270
224
  return false;
271
- } // TODO: Make drag and drop work at some point.
272
-
225
+ }
273
226
 
227
+ // TODO: Make drag and drop work at some point.
274
228
  event.preventDefault();
275
229
  return true;
276
230
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DRAGSTART_COMMAND, event => {
277
231
  const selection = lexical.$getSelection();
278
-
279
232
  if (!lexical.$isRangeSelection(selection)) {
280
233
  return false;
281
- } // TODO: Make drag and drop work at some point.
282
-
234
+ }
283
235
 
236
+ // TODO: Make drag and drop work at some point.
284
237
  event.preventDefault();
285
238
  return true;
286
239
  }, lexical.COMMAND_PRIORITY_EDITOR));
package/package.json CHANGED
@@ -7,13 +7,13 @@
7
7
  "plain-text"
8
8
  ],
9
9
  "license": "MIT",
10
- "version": "0.7.8",
10
+ "version": "0.7.9",
11
11
  "main": "LexicalPlainText.js",
12
12
  "peerDependencies": {
13
- "lexical": "0.7.8",
14
- "@lexical/utils": "0.7.8",
15
- "@lexical/selection": "0.7.8",
16
- "@lexical/clipboard": "0.7.8"
13
+ "lexical": "0.7.9",
14
+ "@lexical/utils": "0.7.9",
15
+ "@lexical/selection": "0.7.9",
16
+ "@lexical/clipboard": "0.7.9"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",