@lexical/dragon 0.13.0 → 0.14.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.
- package/LexicalDragon.dev.esm.js +80 -0
- package/LexicalDragon.esm.js +10 -0
- package/LexicalDragon.js +1 -1
- package/LexicalDragon.prod.esm.js +7 -0
- package/README.md +2 -0
- package/package.json +5 -3
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { $getSelection, $isRangeSelection, $isTextNode } from 'lexical';
|
|
8
|
+
|
|
9
|
+
/** @module @lexical/dragon */
|
|
10
|
+
function registerDragonSupport(editor) {
|
|
11
|
+
const origin = window.location.origin;
|
|
12
|
+
const handler = event => {
|
|
13
|
+
if (event.origin !== origin) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const rootElement = editor.getRootElement();
|
|
17
|
+
if (document.activeElement !== rootElement) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const data = event.data;
|
|
21
|
+
if (typeof data === 'string') {
|
|
22
|
+
let parsedData;
|
|
23
|
+
try {
|
|
24
|
+
parsedData = JSON.parse(data);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (parsedData && parsedData.protocol === 'nuanria_messaging' && parsedData.type === 'request') {
|
|
29
|
+
const payload = parsedData.payload;
|
|
30
|
+
if (payload && payload.functionId === 'makeChanges') {
|
|
31
|
+
const args = payload.args;
|
|
32
|
+
if (args) {
|
|
33
|
+
const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args;
|
|
34
|
+
editor.update(() => {
|
|
35
|
+
const selection = $getSelection();
|
|
36
|
+
if ($isRangeSelection(selection)) {
|
|
37
|
+
const anchor = selection.anchor;
|
|
38
|
+
let anchorNode = anchor.getNode();
|
|
39
|
+
let setSelStart = 0;
|
|
40
|
+
let setSelEnd = 0;
|
|
41
|
+
if ($isTextNode(anchorNode)) {
|
|
42
|
+
// set initial selection
|
|
43
|
+
if (elementStart >= 0 && elementLength >= 0) {
|
|
44
|
+
setSelStart = elementStart;
|
|
45
|
+
setSelEnd = elementStart + elementLength;
|
|
46
|
+
// If the offset is more than the end, make it the end
|
|
47
|
+
selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (setSelStart !== setSelEnd || text !== '') {
|
|
51
|
+
selection.insertRawText(text);
|
|
52
|
+
anchorNode = anchor.getNode();
|
|
53
|
+
}
|
|
54
|
+
if ($isTextNode(anchorNode)) {
|
|
55
|
+
// set final selection
|
|
56
|
+
setSelStart = selStart;
|
|
57
|
+
setSelEnd = selStart + selLength;
|
|
58
|
+
const anchorNodeTextLength = anchorNode.getTextContentSize();
|
|
59
|
+
// If the offset is more than the end, make it the end
|
|
60
|
+
setSelStart = setSelStart > anchorNodeTextLength ? anchorNodeTextLength : setSelStart;
|
|
61
|
+
setSelEnd = setSelEnd > anchorNodeTextLength ? anchorNodeTextLength : setSelEnd;
|
|
62
|
+
selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// block the chrome extension from handling this event
|
|
66
|
+
event.stopImmediatePropagation();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
window.addEventListener('message', handler, true);
|
|
75
|
+
return () => {
|
|
76
|
+
window.removeEventListener('message', handler, true);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { registerDragonSupport };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import * as modDev from './LexicalDragon.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalDragon.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const registerDragonSupport = mod.registerDragonSupport;
|
package/LexicalDragon.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalDragon = process.env.NODE_ENV === 'development' ? require('./LexicalDragon.dev.js') : require('./LexicalDragon.prod.js')
|
|
8
|
+
const LexicalDragon = process.env.NODE_ENV === 'development' ? require('./LexicalDragon.dev.js') : require('./LexicalDragon.prod.js');
|
|
9
9
|
module.exports = LexicalDragon;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import{$getSelection as e,$isRangeSelection as t,$isTextNode as n}from"lexical";function o(o){const i=window.location.origin,a=a=>{if(a.origin!==i)return;const r=o.getRootElement();if(document.activeElement!==r)return;const s=a.data;if("string"==typeof s){let i;try{i=JSON.parse(s)}catch(e){return}if(i&&"nuanria_messaging"===i.protocol&&"request"===i.type){const r=i.payload;if(r&&"makeChanges"===r.functionId){const i=r.args;if(i){const[r,s,c,g,d,f]=i;o.update((()=>{const o=e();if(t(o)){const e=o.anchor;let t=e.getNode(),i=0,f=0;if(n(t)&&r>=0&&s>=0&&(i=r,f=r+s,o.setTextNodeRange(t,i,t,f)),i===f&&""===c||(o.insertRawText(c),t=e.getNode()),n(t)){i=g,f=g+d;const e=t.getTextContentSize();i=i>e?e:i,f=f>e?e:f,o.setTextNodeRange(t,i,t,f)}a.stopImmediatePropagation()}}))}}}}};return window.addEventListener("message",a,!0),()=>{window.removeEventListener("message",a,!0)}}export{o as registerDragonSupport};
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `@lexical/dragon`
|
|
2
2
|
|
|
3
|
+
[](https://lexical.dev/docs/api/modules/lexical_dragon)
|
|
4
|
+
|
|
3
5
|
This package contains compatibility with Dragon NaturallySpeaking accessibility tools.
|
|
4
6
|
|
|
5
7
|
More documentation coming soon.
|
package/package.json
CHANGED
|
@@ -9,14 +9,16 @@
|
|
|
9
9
|
"accessibility"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.14.1",
|
|
13
13
|
"main": "LexicalDragon.js",
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"lexical": "0.
|
|
15
|
+
"lexical": "0.14.1"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
19
|
"url": "https://github.com/facebook/lexical",
|
|
20
20
|
"directory": "packages/lexical-dragon"
|
|
21
|
-
}
|
|
21
|
+
},
|
|
22
|
+
"module": "LexicalDragon.esm.js",
|
|
23
|
+
"sideEffects": false
|
|
22
24
|
}
|