@lexical/dragon 0.44.1-nightly.20260519.0 → 0.45.0
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/package.json +30 -16
- package/src/index.ts +148 -0
- /package/{LexicalDragon.dev.js → dist/LexicalDragon.dev.js} +0 -0
- /package/{LexicalDragon.dev.mjs → dist/LexicalDragon.dev.mjs} +0 -0
- /package/{LexicalDragon.js → dist/LexicalDragon.js} +0 -0
- /package/{LexicalDragon.js.flow → dist/LexicalDragon.js.flow} +0 -0
- /package/{LexicalDragon.mjs → dist/LexicalDragon.mjs} +0 -0
- /package/{LexicalDragon.node.mjs → dist/LexicalDragon.node.mjs} +0 -0
- /package/{LexicalDragon.prod.js → dist/LexicalDragon.prod.js} +0 -0
- /package/{LexicalDragon.prod.mjs → dist/LexicalDragon.prod.mjs} +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -9,35 +9,49 @@
|
|
|
9
9
|
"accessibility"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.
|
|
13
|
-
"main": "LexicalDragon.js",
|
|
14
|
-
"types": "index.d.ts",
|
|
12
|
+
"version": "0.45.0",
|
|
13
|
+
"main": "./dist/LexicalDragon.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
17
|
"url": "git+https://github.com/facebook/lexical.git",
|
|
18
18
|
"directory": "packages/lexical-dragon"
|
|
19
19
|
},
|
|
20
|
-
"module": "LexicalDragon.mjs",
|
|
20
|
+
"module": "./dist/LexicalDragon.mjs",
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
+
"source": "./src/index.ts",
|
|
24
25
|
"import": {
|
|
25
|
-
"types": "./index.d.ts",
|
|
26
|
-
"development": "./LexicalDragon.dev.mjs",
|
|
27
|
-
"production": "./LexicalDragon.prod.mjs",
|
|
28
|
-
"node": "./LexicalDragon.node.mjs",
|
|
29
|
-
"default": "./LexicalDragon.mjs"
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"development": "./dist/LexicalDragon.dev.mjs",
|
|
28
|
+
"production": "./dist/LexicalDragon.prod.mjs",
|
|
29
|
+
"node": "./dist/LexicalDragon.node.mjs",
|
|
30
|
+
"default": "./dist/LexicalDragon.mjs"
|
|
30
31
|
},
|
|
31
32
|
"require": {
|
|
32
|
-
"types": "./index.d.ts",
|
|
33
|
-
"development": "./LexicalDragon.dev.js",
|
|
34
|
-
"production": "./LexicalDragon.prod.js",
|
|
35
|
-
"default": "./LexicalDragon.js"
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"development": "./dist/LexicalDragon.dev.js",
|
|
35
|
+
"production": "./dist/LexicalDragon.prod.js",
|
|
36
|
+
"default": "./dist/LexicalDragon.js"
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"@lexical/extension": "0.
|
|
41
|
-
"lexical": "0.
|
|
42
|
-
}
|
|
41
|
+
"@lexical/extension": "0.45.0",
|
|
42
|
+
"lexical": "0.45.0"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"src",
|
|
47
|
+
"!src/__tests__",
|
|
48
|
+
"!src/__bench__",
|
|
49
|
+
"!src/__mocks__",
|
|
50
|
+
"!src/**/*.test.ts",
|
|
51
|
+
"!src/**/*.test.tsx",
|
|
52
|
+
"!src/**/*.bench.ts",
|
|
53
|
+
"!src/**/*.bench.tsx",
|
|
54
|
+
"README.md",
|
|
55
|
+
"LICENSE"
|
|
56
|
+
]
|
|
43
57
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
import {effect, namedSignals} from '@lexical/extension';
|
|
10
|
+
import {
|
|
11
|
+
$getSelection,
|
|
12
|
+
$isRangeSelection,
|
|
13
|
+
$isTextNode,
|
|
14
|
+
defineExtension,
|
|
15
|
+
LexicalEditor,
|
|
16
|
+
safeCast,
|
|
17
|
+
} from 'lexical';
|
|
18
|
+
|
|
19
|
+
export function registerDragonSupport(editor: LexicalEditor): () => void {
|
|
20
|
+
const origin = window.location.origin;
|
|
21
|
+
const handler = (event: MessageEvent) => {
|
|
22
|
+
if (event.origin !== origin) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const rootElement = editor.getRootElement();
|
|
26
|
+
|
|
27
|
+
if (document.activeElement !== rootElement) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const data = event.data;
|
|
32
|
+
|
|
33
|
+
if (typeof data === 'string') {
|
|
34
|
+
let parsedData;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
parsedData = JSON.parse(data);
|
|
38
|
+
} catch (_e) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
parsedData &&
|
|
44
|
+
parsedData.protocol === 'nuanria_messaging' &&
|
|
45
|
+
parsedData.type === 'request'
|
|
46
|
+
) {
|
|
47
|
+
const payload = parsedData.payload;
|
|
48
|
+
|
|
49
|
+
if (payload && payload.functionId === 'makeChanges') {
|
|
50
|
+
const args = payload.args;
|
|
51
|
+
|
|
52
|
+
if (args) {
|
|
53
|
+
const [
|
|
54
|
+
elementStart,
|
|
55
|
+
elementLength,
|
|
56
|
+
text,
|
|
57
|
+
selStart,
|
|
58
|
+
selLength,
|
|
59
|
+
_formatCommand,
|
|
60
|
+
] = args;
|
|
61
|
+
// TODO: we should probably handle formatCommand somehow?
|
|
62
|
+
// formatCommand;
|
|
63
|
+
editor.update(() => {
|
|
64
|
+
const selection = $getSelection();
|
|
65
|
+
|
|
66
|
+
if ($isRangeSelection(selection)) {
|
|
67
|
+
const anchor = selection.anchor;
|
|
68
|
+
let anchorNode = anchor.getNode();
|
|
69
|
+
let setSelStart = 0;
|
|
70
|
+
let setSelEnd = 0;
|
|
71
|
+
|
|
72
|
+
if ($isTextNode(anchorNode)) {
|
|
73
|
+
// set initial selection
|
|
74
|
+
if (elementStart >= 0 && elementLength >= 0) {
|
|
75
|
+
setSelStart = elementStart;
|
|
76
|
+
setSelEnd = elementStart + elementLength;
|
|
77
|
+
// If the offset is more than the end, make it the end
|
|
78
|
+
selection.setTextNodeRange(
|
|
79
|
+
anchorNode,
|
|
80
|
+
setSelStart,
|
|
81
|
+
anchorNode,
|
|
82
|
+
setSelEnd,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (setSelStart !== setSelEnd || text !== '') {
|
|
88
|
+
selection.insertRawText(text);
|
|
89
|
+
anchorNode = anchor.getNode();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if ($isTextNode(anchorNode)) {
|
|
93
|
+
// set final selection
|
|
94
|
+
setSelStart = selStart;
|
|
95
|
+
setSelEnd = selStart + selLength;
|
|
96
|
+
const anchorNodeTextLength = anchorNode.getTextContentSize();
|
|
97
|
+
// If the offset is more than the end, make it the end
|
|
98
|
+
setSelStart =
|
|
99
|
+
setSelStart > anchorNodeTextLength
|
|
100
|
+
? anchorNodeTextLength
|
|
101
|
+
: setSelStart;
|
|
102
|
+
setSelEnd =
|
|
103
|
+
setSelEnd > anchorNodeTextLength
|
|
104
|
+
? anchorNodeTextLength
|
|
105
|
+
: setSelEnd;
|
|
106
|
+
selection.setTextNodeRange(
|
|
107
|
+
anchorNode,
|
|
108
|
+
setSelStart,
|
|
109
|
+
anchorNode,
|
|
110
|
+
setSelEnd,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// block the chrome extension from handling this event
|
|
115
|
+
event.stopImmediatePropagation();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
window.addEventListener('message', handler, true);
|
|
125
|
+
return () => {
|
|
126
|
+
window.removeEventListener('message', handler, true);
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface DragonConfig {
|
|
131
|
+
disabled: boolean;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Add Dragon speech to text input support to the editor, via the
|
|
136
|
+
* \@lexical/dragon module.
|
|
137
|
+
*/
|
|
138
|
+
export const DragonExtension = defineExtension({
|
|
139
|
+
build: (editor, config, state) => namedSignals(config),
|
|
140
|
+
config: safeCast<DragonConfig>({disabled: typeof window === 'undefined'}),
|
|
141
|
+
name: '@lexical/dragon',
|
|
142
|
+
register: (editor, config, state) =>
|
|
143
|
+
effect(() =>
|
|
144
|
+
state.getOutput().disabled.value
|
|
145
|
+
? undefined
|
|
146
|
+
: registerDragonSupport(editor),
|
|
147
|
+
),
|
|
148
|
+
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|