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