@lexical/plain-text 0.2.1 → 0.2.4
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.
- package/LexicalPlainText.dev.js +53 -17
- package/LexicalPlainText.prod.js +11 -9
- package/package.json +5 -5
package/LexicalPlainText.dev.js
CHANGED
|
@@ -11,6 +11,34 @@ var selection = require('@lexical/selection');
|
|
|
11
11
|
var utils = require('@lexical/utils');
|
|
12
12
|
var lexical = require('lexical');
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the MIT license found in the
|
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
26
|
+
*
|
|
27
|
+
* This source code is licensed under the MIT license found in the
|
|
28
|
+
* LICENSE file in the root directory of this source tree.
|
|
29
|
+
*
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
|
|
33
|
+
CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
34
|
+
CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
35
|
+
CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
|
|
36
|
+
CAN_USE_DOM && /Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
|
|
37
|
+
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.
|
|
38
|
+
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
|
|
39
|
+
// export const IS_CHROME: boolean = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
40
|
+
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
41
|
+
|
|
14
42
|
/**
|
|
15
43
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
44
|
*
|
|
@@ -121,7 +149,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
121
149
|
|
|
122
150
|
selection.deleteCharacter(isBackward);
|
|
123
151
|
return true;
|
|
124
|
-
},
|
|
152
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_WORD_COMMAND, isBackward => {
|
|
125
153
|
const selection = lexical.$getSelection();
|
|
126
154
|
|
|
127
155
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -130,7 +158,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
130
158
|
|
|
131
159
|
selection.deleteWord(isBackward);
|
|
132
160
|
return true;
|
|
133
|
-
},
|
|
161
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_LINE_COMMAND, isBackward => {
|
|
134
162
|
const selection = lexical.$getSelection();
|
|
135
163
|
|
|
136
164
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -139,7 +167,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
139
167
|
|
|
140
168
|
selection.deleteLine(isBackward);
|
|
141
169
|
return true;
|
|
142
|
-
},
|
|
170
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_TEXT_COMMAND, eventOrText => {
|
|
143
171
|
const selection = lexical.$getSelection();
|
|
144
172
|
|
|
145
173
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -163,7 +191,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
163
191
|
}
|
|
164
192
|
|
|
165
193
|
return true;
|
|
166
|
-
},
|
|
194
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.REMOVE_TEXT_COMMAND, payload => {
|
|
167
195
|
const selection = lexical.$getSelection();
|
|
168
196
|
|
|
169
197
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -172,7 +200,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
172
200
|
|
|
173
201
|
selection.removeText();
|
|
174
202
|
return true;
|
|
175
|
-
},
|
|
203
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_LINE_BREAK_COMMAND, selectStart => {
|
|
176
204
|
const selection = lexical.$getSelection();
|
|
177
205
|
|
|
178
206
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -181,7 +209,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
181
209
|
|
|
182
210
|
selection.insertLineBreak(selectStart);
|
|
183
211
|
return true;
|
|
184
|
-
},
|
|
212
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, payload => {
|
|
185
213
|
const selection = lexical.$getSelection();
|
|
186
214
|
|
|
187
215
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -190,7 +218,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
190
218
|
|
|
191
219
|
selection.insertLineBreak();
|
|
192
220
|
return true;
|
|
193
|
-
},
|
|
221
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, payload => {
|
|
194
222
|
const selection$1 = lexical.$getSelection();
|
|
195
223
|
|
|
196
224
|
if (!lexical.$isRangeSelection(selection$1)) {
|
|
@@ -207,7 +235,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
207
235
|
}
|
|
208
236
|
|
|
209
237
|
return false;
|
|
210
|
-
},
|
|
238
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, payload => {
|
|
211
239
|
const selection$1 = lexical.$getSelection();
|
|
212
240
|
|
|
213
241
|
if (!lexical.$isRangeSelection(selection$1)) {
|
|
@@ -224,7 +252,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
224
252
|
}
|
|
225
253
|
|
|
226
254
|
return false;
|
|
227
|
-
},
|
|
255
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, event => {
|
|
228
256
|
const selection = lexical.$getSelection();
|
|
229
257
|
|
|
230
258
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -233,7 +261,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
233
261
|
|
|
234
262
|
event.preventDefault();
|
|
235
263
|
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
|
|
236
|
-
},
|
|
264
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND, event => {
|
|
237
265
|
const selection = lexical.$getSelection();
|
|
238
266
|
|
|
239
267
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -242,7 +270,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
242
270
|
|
|
243
271
|
event.preventDefault();
|
|
244
272
|
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, false);
|
|
245
|
-
},
|
|
273
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
|
|
246
274
|
const selection = lexical.$getSelection();
|
|
247
275
|
|
|
248
276
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -250,11 +278,19 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
250
278
|
}
|
|
251
279
|
|
|
252
280
|
if (event !== null) {
|
|
281
|
+
// If we have beforeinput, then we can avoid blocking
|
|
282
|
+
// the default behavior. This ensures that the iOS can
|
|
283
|
+
// intercept that we're actually inserting a paragraph,
|
|
284
|
+
// and autocomplete, autocapitialize etc work as intended.
|
|
285
|
+
if (IS_IOS) {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
|
|
253
289
|
event.preventDefault();
|
|
254
290
|
}
|
|
255
291
|
|
|
256
292
|
return editor.dispatchCommand(lexical.INSERT_LINE_BREAK_COMMAND);
|
|
257
|
-
},
|
|
293
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND, event => {
|
|
258
294
|
const selection = lexical.$getSelection();
|
|
259
295
|
|
|
260
296
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -263,7 +299,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
263
299
|
|
|
264
300
|
onCopyForPlainText(event, editor);
|
|
265
301
|
return true;
|
|
266
|
-
},
|
|
302
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CUT_COMMAND, event => {
|
|
267
303
|
const selection = lexical.$getSelection();
|
|
268
304
|
|
|
269
305
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -272,7 +308,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
272
308
|
|
|
273
309
|
onCutForPlainText(event, editor);
|
|
274
310
|
return true;
|
|
275
|
-
},
|
|
311
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.PASTE_COMMAND, event => {
|
|
276
312
|
const selection = lexical.$getSelection();
|
|
277
313
|
|
|
278
314
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -281,7 +317,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
281
317
|
|
|
282
318
|
onPasteForPlainText(event, editor);
|
|
283
319
|
return true;
|
|
284
|
-
},
|
|
320
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DROP_COMMAND, event => {
|
|
285
321
|
const selection = lexical.$getSelection();
|
|
286
322
|
|
|
287
323
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -291,7 +327,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
291
327
|
|
|
292
328
|
event.preventDefault();
|
|
293
329
|
return true;
|
|
294
|
-
},
|
|
330
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DRAGSTART_COMMAND, event => {
|
|
295
331
|
const selection = lexical.$getSelection();
|
|
296
332
|
|
|
297
333
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -301,7 +337,7 @@ function registerPlainText(editor, initialEditorState) {
|
|
|
301
337
|
|
|
302
338
|
event.preventDefault();
|
|
303
339
|
return true;
|
|
304
|
-
},
|
|
340
|
+
}, lexical.COMMAND_PRIORITY_EDITOR));
|
|
305
341
|
initializeEditor(editor, initialEditorState);
|
|
306
342
|
return removeListener;
|
|
307
343
|
}
|
package/LexicalPlainText.prod.js
CHANGED
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var a=require("@lexical/clipboard"),
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;
|
|
12
|
-
|
|
13
|
-
b
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
var a=require("@lexical/clipboard"),g=require("@lexical/selection"),k=require("@lexical/utils"),l=require("lexical");const 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);m&&"InputEvent"in window&&!n?"getTargetRanges"in new window.InputEvent("input"):!1;
|
|
8
|
+
m&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);const p=m&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,q={tag:"history-merge"};function r(d,e){d.preventDefault();e.update(()=>{const f=d.clipboardData,b=l.$getSelection();if(null!==b&&null!=f){const c=a.getHtmlContent(e);null!==c&&f.setData("text/html",c);f.setData("text/plain",b.getTextContent())}})}
|
|
9
|
+
function t(d,e){d.preventDefault();e.update(()=>{const f=l.$getSelection(),b=d.clipboardData;null!=b&&l.$isRangeSelection(f)&&a.$insertDataTransferForPlainText(b,f)})}function u(d,e){r(d,e);e.update(()=>{const f=l.$getSelection();l.$isRangeSelection(f)&&f.removeText()})}
|
|
10
|
+
function v(d,e){if(null!==e)if(void 0===e)d.update(()=>{var f=l.$getRoot();if(null===f.getFirstChild()){const b=l.$createParagraphNode();f.append(b);f=document.activeElement;(null!==l.$getSelection()||null!==f&&f===d.getRootElement())&&b.select()}},q);else if(null!==e)switch(typeof e){case "string":e=d.parseEditorState(e);d.setEditorState(e,q);break;case "object":d.setEditorState(e,q);break;case "function":d.update(e,q)}}
|
|
11
|
+
exports.registerPlainText=function(d,e){const 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);
|
|
12
|
+
return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.INSERT_TEXT_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
|
+
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
|
+
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
|
+
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(p)return!1;b.preventDefault()}return d.dispatchCommand(l.INSERT_LINE_BREAK_COMMAND)},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.COPY_COMMAND,b=>{const c=l.$getSelection();
|
|
16
|
+
if(!l.$isRangeSelection(c))return!1;r(b,d);return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.CUT_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;u(b,d);return!0},l.COMMAND_PRIORITY_EDITOR),d.registerCommand(l.PASTE_COMMAND,b=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;t(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));v(d,e);return f};
|
package/package.json
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
"plain-text"
|
|
8
8
|
],
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"version": "0.2.
|
|
10
|
+
"version": "0.2.4",
|
|
11
11
|
"main": "LexicalPlainText.js",
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"lexical": "0.2.
|
|
14
|
-
"@lexical/utils": "0.2.
|
|
15
|
-
"@lexical/selection": "0.2.
|
|
16
|
-
"@lexical/clipboard": "0.2.
|
|
13
|
+
"lexical": "0.2.4",
|
|
14
|
+
"@lexical/utils": "0.2.4",
|
|
15
|
+
"@lexical/selection": "0.2.4",
|
|
16
|
+
"@lexical/clipboard": "0.2.4"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|