@lexical/dragon 0.1.17

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Meta Platforms, Inc. and affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,11 @@
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
+ */
8
+
9
+ export default function LexicalAutoScrollPlugin(props: {
10
+ scrollRef: {current: HTMLElement | null};
11
+ }): null;
@@ -0,0 +1,97 @@
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
+ 'use strict';
8
+
9
+ var lexical = require('lexical');
10
+
11
+ /**
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ *
18
+ */
19
+ function registerDragonSupport(editor) {
20
+ const handler = event => {
21
+ const rootElement = editor.getRootElement();
22
+
23
+ if (document.activeElement !== rootElement) {
24
+ return;
25
+ }
26
+
27
+ const data = event.data;
28
+
29
+ if (typeof data === 'string') {
30
+ let parsedData;
31
+
32
+ try {
33
+ parsedData = JSON.parse(data);
34
+ } catch (e) {
35
+ return;
36
+ }
37
+
38
+ if (parsedData && parsedData.protocol === 'nuanria_messaging' && parsedData.type === 'request') {
39
+ const payload = parsedData.payload;
40
+
41
+ if (payload && payload.functionId === 'makeChanges') {
42
+ const args = payload.args;
43
+
44
+ if (args) {
45
+ const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
46
+ editor.update(() => {
47
+ const selection = lexical.$getSelection();
48
+
49
+ if (lexical.$isRangeSelection(selection)) {
50
+ const anchor = selection.anchor;
51
+ let anchorNode = anchor.getNode();
52
+ let setSelStart = 0;
53
+ let setSelEnd = 0;
54
+
55
+ if (lexical.$isTextNode(anchorNode)) {
56
+ // set initial selection
57
+ if (elementStart >= 0 && elementLength >= 0) {
58
+ setSelStart = elementStart;
59
+ setSelEnd = elementStart + elementLength; // If the offset is more than the end, make it the end
60
+
61
+ selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
62
+ }
63
+ }
64
+
65
+ if (setSelStart !== setSelEnd || text !== '') {
66
+ selection.insertRawText(text);
67
+ anchorNode = anchor.getNode();
68
+ }
69
+
70
+ if (lexical.$isTextNode(anchorNode)) {
71
+ // set final selection
72
+ setSelStart = selStart;
73
+ setSelEnd = selStart + selLength;
74
+ const anchorNodeTextLength = anchorNode.getTextContentSize(); // If the offset is more than the end, make it the end
75
+
76
+ setSelStart = setSelStart > anchorNodeTextLength ? anchorNodeTextLength : setSelStart;
77
+ setSelEnd = setSelEnd > anchorNodeTextLength ? anchorNodeTextLength : setSelEnd;
78
+ selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
79
+ } // block the chrome extension from handling this event
80
+
81
+
82
+ event.stopImmediatePropagation();
83
+ }
84
+ });
85
+ }
86
+ }
87
+ }
88
+ }
89
+ };
90
+
91
+ window.addEventListener('message', handler, true);
92
+ return () => {
93
+ window.removeEventListener('message', handler, true);
94
+ };
95
+ }
96
+
97
+ exports.registerDragonSupport = registerDragonSupport;
@@ -0,0 +1,9 @@
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
+ 'use strict'
8
+ const LexicalDragon = process.env.NODE_ENV === 'development' ? require('./LexicalDragon.dev.js') : require('./LexicalDragon.prod.js')
9
+ module.exports = LexicalDragon;
@@ -0,0 +1,13 @@
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
+ * @flow strict
8
+ */
9
+ import type {LexicalEditor} from 'lexical';
10
+ import {$getSelection, $isRangeSelection, $isTextNode} from 'lexical';
11
+ declare export function registerDragonSupport(
12
+ editor: LexicalEditor,
13
+ ): () => void;
@@ -0,0 +1,9 @@
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
+ var g=require("lexical");
8
+ exports.registerDragonSupport=function(l){const r=m=>{var h=l.getRootElement();if(document.activeElement===h&&(h=m.data,"string"===typeof h)){try{var a=JSON.parse(h)}catch(k){return}if(a&&"nuanria_messaging"===a.protocol&&"request"===a.type&&(a=a.payload)&&"makeChanges"===a.functionId&&(a=a.args)){const [k,n,p,q,t]=a;l.update(()=>{const f=g.$getSelection();if(g.$isRangeSelection(f)){var e=f.anchor;let b=e.getNode(),c=0,d=0;g.$isTextNode(b)&&0<=k&&0<=n&&(c=k,d=k+n,f.setTextNodeRange(b,c,b,d));if(c!==
9
+ d||""!==p)f.insertRawText(p),b=e.getNode();g.$isTextNode(b)&&(c=q,d=q+t,e=b.getTextContentSize(),c=c>e?e:c,d=d>e?e:d,f.setTextNodeRange(b,c,b,d));m.stopImmediatePropagation()}})}}};window.addEventListener("message",r,!0);return()=>{window.removeEventListener("message",r,!0)}};
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # `@lexical/dragon`
2
+
3
+ This package contains compatability with Dragon NaturallySpeaking accessibility tools.
4
+
5
+ More documentation coming soon.
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@lexical/dragon",
3
+ "description": "This package contains compatability with Dragon NaturallySpeaking accessibility tools.",
4
+ "keywords": [
5
+ "lexical",
6
+ "editor",
7
+ "rich-text",
8
+ "dragon",
9
+ "accessibility"
10
+ ],
11
+ "license": "MIT",
12
+ "version": "0.1.17",
13
+ "main": "LexicalDragon.js",
14
+ "peerDependencies": {
15
+ "lexical": "0.1.17"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/facebook/lexical",
20
+ "directory": "packages/lexical-dragon"
21
+ }
22
+ }