@fluentui-copilot/chat-input-plugins 0.5.0 → 0.5.2
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/CHANGELOG.json +31 -1
- package/CHANGELOG.md +20 -2
- package/lib/BasicFunctionality/BasicFunctionality.base.js +90 -96
- package/lib/BasicFunctionality/BasicFunctionality.base.js.map +1 -1
- package/lib/BasicFunctionality/SentinelNode.js +29 -30
- package/lib/BasicFunctionality/SentinelNode.js.map +1 -1
- package/lib/BasicFunctionality/SentinelNodeHandlers.js +73 -78
- package/lib/BasicFunctionality/SentinelNodeHandlers.js.map +1 -1
- package/lib/BasicFunctionality/index.js +0 -1
- package/lib/ChatInputEntity/ChatInputEntityPlugin.base.js +109 -114
- package/lib/ChatInputEntity/ChatInputEntityPlugin.base.js.map +1 -1
- package/lib/ChatInputEntity/ChatInputEntityPlugin.types.js +1 -2
- package/lib/ChatInputEntity/index.js +0 -1
- package/lib/GhostText/GhostText.base.js +142 -145
- package/lib/GhostText/GhostText.base.js.map +1 -1
- package/lib/GhostText/index.js +0 -1
- package/lib/ImperativeControl/ImperativeControl.base.js +82 -83
- package/lib/ImperativeControl/ImperativeControl.base.js.map +1 -1
- package/lib/ImperativeControl/index.js +0 -1
- package/lib/ManualGhostText/ManualGhostText.base.js +68 -67
- package/lib/ManualGhostText/index.js +0 -1
- package/lib/PasteUnfurling/PasteUnfurling.base.js +52 -57
- package/lib/PasteUnfurling/PasteUnfurling.types.js +1 -2
- package/lib/PasteUnfurling/PasteUnfurlingTestUtils.js +138 -139
- package/lib/PasteUnfurling/PasteUnfurlingTestUtils.js.map +1 -1
- package/lib/PasteUnfurling/index.js +0 -1
- package/lib/index.js +0 -1
- package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js +2 -3
- package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js.map +1 -1
- package/lib-commonjs/BasicFunctionality/SentinelNode.js +1 -1
- package/lib-commonjs/BasicFunctionality/SentinelNode.js.map +1 -1
- package/lib-commonjs/BasicFunctionality/SentinelNodeHandlers.js +3 -5
- package/lib-commonjs/BasicFunctionality/SentinelNodeHandlers.js.map +1 -1
- package/lib-commonjs/BasicFunctionality/index.js +0 -1
- package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.base.js +3 -5
- package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.base.js.map +1 -1
- package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.types.js +0 -1
- package/lib-commonjs/ChatInputEntity/index.js +0 -1
- package/lib-commonjs/GhostText/GhostText.base.js +2 -3
- package/lib-commonjs/GhostText/GhostText.base.js.map +1 -1
- package/lib-commonjs/GhostText/index.js +0 -1
- package/lib-commonjs/ImperativeControl/ImperativeControl.base.js +1 -1
- package/lib-commonjs/ImperativeControl/ImperativeControl.base.js.map +1 -1
- package/lib-commonjs/ImperativeControl/index.js +0 -1
- package/lib-commonjs/ManualGhostText/ManualGhostText.base.js +1 -1
- package/lib-commonjs/ManualGhostText/ManualGhostText.base.js.map +1 -1
- package/lib-commonjs/ManualGhostText/index.js +0 -1
- package/lib-commonjs/PasteUnfurling/PasteUnfurling.base.js +1 -1
- package/lib-commonjs/PasteUnfurling/PasteUnfurling.base.js.map +1 -1
- package/lib-commonjs/PasteUnfurling/PasteUnfurling.types.js +0 -1
- package/lib-commonjs/PasteUnfurling/PasteUnfurlingTestUtils.js +1 -1
- package/lib-commonjs/PasteUnfurling/PasteUnfurlingTestUtils.js.map +1 -1
- package/lib-commonjs/PasteUnfurling/index.js +0 -1
- package/lib-commonjs/index.js +0 -1
- package/package.json +2 -2
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,37 @@
|
|
|
2
2
|
"name": "@fluentui-copilot/chat-input-plugins",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Tue, 14 Oct 2025 00:02:53 GMT",
|
|
6
|
+
"tag": "@fluentui-copilot/chat-input-plugins_v0.5.2",
|
|
7
|
+
"version": "0.5.2",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "tristan.watanabe@gmail.com",
|
|
12
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
13
|
+
"commit": "9a3bf49a3c6302529b2c9b6bc3fc63f549aaf88f",
|
|
14
|
+
"comment": "chore: enforce explicit return types."
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Thu, 17 Jul 2025 17:49:26 GMT",
|
|
21
|
+
"tag": "@fluentui-copilot/chat-input-plugins_v0.5.1",
|
|
22
|
+
"version": "0.5.1",
|
|
23
|
+
"comments": {
|
|
24
|
+
"patch": [
|
|
25
|
+
{
|
|
26
|
+
"author": "hochelmartin@gmail.com",
|
|
27
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
28
|
+
"commit": "fef5160c07333e8d9996952a305b34e357604919",
|
|
29
|
+
"comment": "feat: enable griffel raw styles"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"date": "Wed, 28 May 2025 23:41:43 GMT",
|
|
6
36
|
"tag": "@fluentui-copilot/chat-input-plugins_v0.5.0",
|
|
7
37
|
"version": "0.5.0",
|
|
8
38
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
# Change Log - @fluentui-copilot/chat-input-plugins
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 14 Oct 2025 00:02:53 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [0.5.2](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.5.2)
|
|
8
|
+
|
|
9
|
+
Tue, 14 Oct 2025 00:02:53 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.5.1..@fluentui-copilot/chat-input-plugins_v0.5.2)
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- chore: enforce explicit return types. ([PR #3360](https://github.com/microsoft/fluentai/pull/3360) by tristan.watanabe@gmail.com)
|
|
15
|
+
|
|
16
|
+
## [0.5.1](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.5.1)
|
|
17
|
+
|
|
18
|
+
Thu, 17 Jul 2025 17:49:26 GMT
|
|
19
|
+
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.5.0..@fluentui-copilot/chat-input-plugins_v0.5.1)
|
|
20
|
+
|
|
21
|
+
### Patches
|
|
22
|
+
|
|
23
|
+
- feat: enable griffel raw styles ([PR #3227](https://github.com/microsoft/fluentai/pull/3227) by hochelmartin@gmail.com)
|
|
24
|
+
|
|
7
25
|
## [0.5.0](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.5.0)
|
|
8
26
|
|
|
9
|
-
Wed, 28 May 2025 23:41:
|
|
27
|
+
Wed, 28 May 2025 23:41:43 GMT
|
|
10
28
|
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.4.2..@fluentui-copilot/chat-input-plugins_v0.5.0)
|
|
11
29
|
|
|
12
30
|
### Minor changes
|
|
@@ -4,110 +4,104 @@ import { $getRoot, $getSelection, $isRangeSelection, INSERT_PARAGRAPH_COMMAND, K
|
|
|
4
4
|
import { SENTINEL_VALUE } from './SentinelNode';
|
|
5
5
|
import { registerSentinelNodeHandlers } from './SentinelNodeHandlers';
|
|
6
6
|
function isClipboardEvent(event) {
|
|
7
|
-
|
|
7
|
+
return event.type === 'paste';
|
|
8
8
|
}
|
|
9
9
|
function getTextFromEditorState(state) {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// Remove the sentinel node whenever getting the text
|
|
11
|
+
return state.read(()=>$getRoot().getTextContent()).replace(SENTINEL_VALUE, '');
|
|
12
12
|
}
|
|
13
13
|
export class BasicFunctionalityBase {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
__enterHandler(event) {
|
|
15
|
+
const selection = $getSelection();
|
|
16
|
+
if (!$isRangeSelection(selection)) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (event === null) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
if (event.shiftKey) {
|
|
24
|
+
return this.__editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);
|
|
25
|
+
}
|
|
26
|
+
// Mark event handled to override default behavior
|
|
27
|
+
return true;
|
|
18
28
|
}
|
|
19
|
-
|
|
20
|
-
|
|
29
|
+
activateContentCallbacks(onContentChange, onCountChanged) {
|
|
30
|
+
this.deactivateContentCallbacks();
|
|
31
|
+
this.__contentChangeCleanup = this.__editor.registerUpdateListener(({ editorState, prevEditorState, tags })=>{
|
|
32
|
+
const prevText = getTextFromEditorState(prevEditorState);
|
|
33
|
+
const newText = getTextFromEditorState(editorState);
|
|
34
|
+
// If the text has not changed, don't trigger callbacks
|
|
35
|
+
if (prevText === newText) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
onContentChange === null || onContentChange === void 0 ? void 0 : onContentChange(newText);
|
|
39
|
+
onCountChanged === null || onCountChanged === void 0 ? void 0 : onCountChanged(newText.length);
|
|
40
|
+
});
|
|
21
41
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
42
|
+
deactivateContentCallbacks() {
|
|
43
|
+
var _this___contentChangeCleanup, _this;
|
|
44
|
+
(_this___contentChangeCleanup = (_this = this).__contentChangeCleanup) === null || _this___contentChangeCleanup === void 0 ? void 0 : _this___contentChangeCleanup.call(_this);
|
|
45
|
+
this.__contentChangeCleanup = undefined;
|
|
25
46
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
onPaste(event);
|
|
57
|
-
if (event.defaultPrevented) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
return false;
|
|
61
|
-
}, COMMAND_PRIORITY_HIGH);
|
|
62
|
-
}
|
|
63
|
-
deactivatePasteCallback() {
|
|
64
|
-
var _this___pasteHandlerCleanup, _this;
|
|
65
|
-
(_this___pasteHandlerCleanup = (_this = this).__pasteHandlerCleanup) === null || _this___pasteHandlerCleanup === void 0 ? void 0 : _this___pasteHandlerCleanup.call(_this);
|
|
66
|
-
this.__pasteHandlerCleanup = undefined;
|
|
67
|
-
}
|
|
68
|
-
activateTrimWhitespace() {
|
|
69
|
-
this.deactivateTrimWhitespace();
|
|
70
|
-
this.__trimWhitespaceCleanup = this.__editor.registerTextContentListener(text => {
|
|
71
|
-
if (text.trim() === '') {
|
|
72
|
-
this.__editor.update(() => {
|
|
73
|
-
$getRoot().getAllTextNodes().forEach(node => {
|
|
74
|
-
node.remove();
|
|
75
|
-
});
|
|
76
|
-
},
|
|
77
|
-
// Don't allow undoing this action
|
|
78
|
-
{
|
|
79
|
-
tag: 'historic'
|
|
47
|
+
activatePasteCallback(onPaste) {
|
|
48
|
+
this.__pasteHandlerCleanup = this.__editor.registerCommand(PASTE_COMMAND, (event)=>{
|
|
49
|
+
if (!isClipboardEvent(event)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
onPaste(event);
|
|
53
|
+
if (event.defaultPrevented) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}, COMMAND_PRIORITY_HIGH);
|
|
58
|
+
}
|
|
59
|
+
deactivatePasteCallback() {
|
|
60
|
+
var _this___pasteHandlerCleanup, _this;
|
|
61
|
+
(_this___pasteHandlerCleanup = (_this = this).__pasteHandlerCleanup) === null || _this___pasteHandlerCleanup === void 0 ? void 0 : _this___pasteHandlerCleanup.call(_this);
|
|
62
|
+
this.__pasteHandlerCleanup = undefined;
|
|
63
|
+
}
|
|
64
|
+
activateTrimWhitespace() {
|
|
65
|
+
this.deactivateTrimWhitespace();
|
|
66
|
+
this.__trimWhitespaceCleanup = this.__editor.registerTextContentListener((text)=>{
|
|
67
|
+
if (text.trim() === '') {
|
|
68
|
+
this.__editor.update(()=>{
|
|
69
|
+
$getRoot().getAllTextNodes().forEach((node)=>{
|
|
70
|
+
node.remove();
|
|
71
|
+
});
|
|
72
|
+
}, // Don't allow undoing this action
|
|
73
|
+
{
|
|
74
|
+
tag: 'historic'
|
|
75
|
+
});
|
|
76
|
+
}
|
|
80
77
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.__baseHandlersCleanup = mergeRegister(this.__editor.registerCommand(KEY_ENTER_COMMAND, this.__enterHandler.bind(this), COMMAND_PRIORITY_HIGH), isSentinelNodeEnabled ? registerSentinelNodeHandlers(editor) : noop);
|
|
108
|
-
}
|
|
78
|
+
}
|
|
79
|
+
deactivateTrimWhitespace() {
|
|
80
|
+
var _this___trimWhitespaceCleanup, _this;
|
|
81
|
+
(_this___trimWhitespaceCleanup = (_this = this).__trimWhitespaceCleanup) === null || _this___trimWhitespaceCleanup === void 0 ? void 0 : _this___trimWhitespaceCleanup.call(_this);
|
|
82
|
+
this.__trimWhitespaceCleanup = undefined;
|
|
83
|
+
}
|
|
84
|
+
setIsDisabled(isDisabled) {
|
|
85
|
+
this.__editor.setEditable(!isDisabled);
|
|
86
|
+
}
|
|
87
|
+
cleanup() {
|
|
88
|
+
var _this___baseHandlersCleanup, _this;
|
|
89
|
+
this.deactivateContentCallbacks();
|
|
90
|
+
this.deactivateTrimWhitespace();
|
|
91
|
+
this.deactivatePasteCallback();
|
|
92
|
+
(_this___baseHandlersCleanup = (_this = this).__baseHandlersCleanup) === null || _this___baseHandlersCleanup === void 0 ? void 0 : _this___baseHandlersCleanup.call(_this);
|
|
93
|
+
this.__baseHandlersCleanup = undefined;
|
|
94
|
+
}
|
|
95
|
+
constructor(editor, isSentinelNodeEnabled = true){
|
|
96
|
+
_define_property(this, "__editor", void 0);
|
|
97
|
+
_define_property(this, "__contentChangeCleanup", void 0);
|
|
98
|
+
_define_property(this, "__trimWhitespaceCleanup", void 0);
|
|
99
|
+
_define_property(this, "__baseHandlersCleanup", void 0);
|
|
100
|
+
_define_property(this, "__pasteHandlerCleanup", void 0);
|
|
101
|
+
this.__editor = editor;
|
|
102
|
+
this.__baseHandlersCleanup = mergeRegister(this.__editor.registerCommand(KEY_ENTER_COMMAND, this.__enterHandler.bind(this), COMMAND_PRIORITY_HIGH), isSentinelNodeEnabled ? registerSentinelNodeHandlers(editor) : noop);
|
|
103
|
+
}
|
|
109
104
|
}
|
|
110
105
|
function noop() {
|
|
111
|
-
|
|
106
|
+
return;
|
|
112
107
|
}
|
|
113
|
-
//# sourceMappingURL=BasicFunctionality.base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["BasicFunctionality.base.ts"],"sourcesContent":["import type { EditorState, LexicalEditor } from '@fluentui-copilot/text-editor';\nimport { COMMAND_PRIORITY_HIGH } from '@fluentui-copilot/text-editor';\nimport {\n $getRoot,\n $getSelection,\n $isRangeSelection,\n INSERT_PARAGRAPH_COMMAND,\n KEY_ENTER_COMMAND,\n PASTE_COMMAND,\n mergeRegister,\n} from '@fluentui-copilot/text-editor';\nimport { SENTINEL_VALUE } from './SentinelNode';\nimport { registerSentinelNodeHandlers } from './SentinelNodeHandlers';\n\nfunction isClipboardEvent(event: ClipboardEvent | KeyboardEvent | InputEvent): event is ClipboardEvent {\n return event.type === 'paste';\n}\n\nexport interface IBasicFunctionalityBase {\n setIsDisabled: (isDisabled: boolean) => void;\n activateContentCallbacks(onContentChange?: (value: string) => void, onCountChanged?: (count: number) => void): void;\n deactivateContentCallbacks(): void;\n activateTrimWhitespace(): void;\n deactivateTrimWhitespace(): void;\n activatePasteCallback(onPaste: (event: ClipboardEvent) => void): void;\n deactivatePasteCallback(): void;\n cleanup(): void;\n}\n\nfunction getTextFromEditorState(state: EditorState): string {\n // Remove the sentinel node whenever getting the text\n return state.read(() => $getRoot().getTextContent()).replace(SENTINEL_VALUE, '');\n}\n\nexport class BasicFunctionalityBase implements IBasicFunctionalityBase {\n private __editor: LexicalEditor;\n private __contentChangeCleanup?: () => void;\n private __trimWhitespaceCleanup?: () => void;\n private __baseHandlersCleanup?: () => void;\n private __pasteHandlerCleanup?: () => void;\n\n private __enterHandler(event: KeyboardEvent) {\n const selection = $getSelection();\n if (!$isRangeSelection(selection)) {\n return false;\n }\n\n if (event === null) {\n return false;\n }\n\n event.preventDefault();\n\n if (event.shiftKey) {\n return this.__editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);\n }\n\n // Mark event handled to override default behavior\n return true;\n }\n\n constructor(editor: LexicalEditor, isSentinelNodeEnabled = true) {\n this.__editor = editor;\n\n this.__baseHandlersCleanup = mergeRegister(\n this.__editor.registerCommand(KEY_ENTER_COMMAND, this.__enterHandler.bind(this), COMMAND_PRIORITY_HIGH),\n isSentinelNodeEnabled ? registerSentinelNodeHandlers(editor) : noop,\n );\n }\n\n activateContentCallbacks(\n onContentChange?: ((value: string) => void) | undefined,\n onCountChanged?: ((count: number) => void) | undefined,\n ) {\n this.deactivateContentCallbacks();\n this.__contentChangeCleanup = this.__editor.registerUpdateListener(({ editorState, prevEditorState, tags }) => {\n const prevText = getTextFromEditorState(prevEditorState);\n const newText = getTextFromEditorState(editorState);\n\n // If the text has not changed, don't trigger callbacks\n if (prevText === newText) {\n return;\n }\n\n onContentChange?.(newText);\n onCountChanged?.(newText.length);\n });\n }\n\n deactivateContentCallbacks() {\n this.__contentChangeCleanup?.();\n this.__contentChangeCleanup = undefined;\n }\n\n activatePasteCallback(onPaste: (event: ClipboardEvent) => void) {\n this.__pasteHandlerCleanup = this.__editor.registerCommand(\n PASTE_COMMAND,\n (event: ClipboardEvent | KeyboardEvent | InputEvent) => {\n if (!isClipboardEvent(event)) {\n return false;\n }\n\n onPaste(event);\n\n if (event.defaultPrevented) {\n return true;\n }\n\n return false;\n },\n COMMAND_PRIORITY_HIGH,\n );\n }\n\n deactivatePasteCallback() {\n this.__pasteHandlerCleanup?.();\n this.__pasteHandlerCleanup = undefined;\n }\n\n activateTrimWhitespace() {\n this.deactivateTrimWhitespace();\n this.__trimWhitespaceCleanup = this.__editor.registerTextContentListener(text => {\n if (text.trim() === '') {\n this.__editor.update(\n () => {\n $getRoot()\n .getAllTextNodes()\n .forEach(node => {\n node.remove();\n });\n },\n // Don't allow undoing this action\n { tag: 'historic' },\n );\n }\n });\n }\n\n deactivateTrimWhitespace() {\n this.__trimWhitespaceCleanup?.();\n this.__trimWhitespaceCleanup = undefined;\n }\n\n setIsDisabled(isDisabled: boolean) {\n this.__editor.setEditable(!isDisabled);\n }\n\n cleanup() {\n this.deactivateContentCallbacks();\n this.deactivateTrimWhitespace();\n this.deactivatePasteCallback();\n this.__baseHandlersCleanup?.();\n this.__baseHandlersCleanup = undefined;\n }\n}\n\nfunction noop() {\n return;\n}\n"],"names":["COMMAND_PRIORITY_HIGH","$getRoot","$getSelection","$isRangeSelection","INSERT_PARAGRAPH_COMMAND","KEY_ENTER_COMMAND","PASTE_COMMAND","mergeRegister","SENTINEL_VALUE","registerSentinelNodeHandlers","isClipboardEvent","event","type","getTextFromEditorState","state","read","getTextContent","replace","BasicFunctionalityBase","__enterHandler","selection","preventDefault","shiftKey","__editor","dispatchCommand","undefined","activateContentCallbacks","onContentChange","onCountChanged","deactivateContentCallbacks","__contentChangeCleanup","registerUpdateListener","editorState","prevEditorState","tags","prevText","newText","length","activatePasteCallback","onPaste","__pasteHandlerCleanup","registerCommand","defaultPrevented","deactivatePasteCallback","activateTrimWhitespace","deactivateTrimWhitespace","__trimWhitespaceCleanup","registerTextContentListener","text","trim","update","getAllTextNodes","forEach","node","remove","tag","setIsDisabled","isDisabled","setEditable","cleanup","__baseHandlersCleanup","constructor","editor","isSentinelNodeEnabled","bind","noop"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AACA,SAASA,qBAAqB,QAAQ,gCAAgC;AACtE,SACEC,QAAQ,EACRC,aAAa,EACbC,iBAAiB,EACjBC,wBAAwB,EACxBC,iBAAiB,EACjBC,aAAa,EACbC,aAAa,QACR,gCAAgC;AACvC,SAASC,cAAc,QAAQ,iBAAiB;AAChD,SAASC,4BAA4B,QAAQ,yBAAyB;AAEtE,SAASC,iBAAiBC,KAAkD;IAC1E,OAAOA,MAAMC,IAAI,KAAK;AACxB;AAaA,SAASC,uBAAuBC,KAAkB;IAChD,qDAAqD;IACrD,OAAOA,MAAMC,IAAI,CAAC,IAAMd,WAAWe,cAAc,IAAIC,OAAO,CAACT,gBAAgB;AAC/E;AAEA,OAAO,MAAMU;IAOHC,eAAeR,KAAoB,EAAE;QAC3C,MAAMS,YAAYlB;QAClB,IAAI,CAACC,kBAAkBiB,YAAY;YACjC,OAAO;QACT;QAEA,IAAIT,UAAU,MAAM;YAClB,OAAO;QACT;QAEAA,MAAMU,cAAc;QAEpB,IAAIV,MAAMW,QAAQ,EAAE;YAClB,OAAO,IAAI,CAACC,QAAQ,CAACC,eAAe,CAACpB,0BAA0BqB;QACjE;QAEA,kDAAkD;QAClD,OAAO;IACT;IAWAC,yBACEC,eAAuD,EACvDC,cAAsD,
|
|
1
|
+
{"version":3,"sources":["BasicFunctionality.base.ts"],"sourcesContent":["import type { EditorState, LexicalEditor } from '@fluentui-copilot/text-editor';\nimport { COMMAND_PRIORITY_HIGH } from '@fluentui-copilot/text-editor';\nimport {\n $getRoot,\n $getSelection,\n $isRangeSelection,\n INSERT_PARAGRAPH_COMMAND,\n KEY_ENTER_COMMAND,\n PASTE_COMMAND,\n mergeRegister,\n} from '@fluentui-copilot/text-editor';\nimport { SENTINEL_VALUE } from './SentinelNode';\nimport { registerSentinelNodeHandlers } from './SentinelNodeHandlers';\n\nfunction isClipboardEvent(event: ClipboardEvent | KeyboardEvent | InputEvent): event is ClipboardEvent {\n return event.type === 'paste';\n}\n\nexport interface IBasicFunctionalityBase {\n setIsDisabled: (isDisabled: boolean) => void;\n activateContentCallbacks(onContentChange?: (value: string) => void, onCountChanged?: (count: number) => void): void;\n deactivateContentCallbacks(): void;\n activateTrimWhitespace(): void;\n deactivateTrimWhitespace(): void;\n activatePasteCallback(onPaste: (event: ClipboardEvent) => void): void;\n deactivatePasteCallback(): void;\n cleanup(): void;\n}\n\nfunction getTextFromEditorState(state: EditorState): string {\n // Remove the sentinel node whenever getting the text\n return state.read(() => $getRoot().getTextContent()).replace(SENTINEL_VALUE, '');\n}\n\nexport class BasicFunctionalityBase implements IBasicFunctionalityBase {\n private __editor: LexicalEditor;\n private __contentChangeCleanup?: () => void;\n private __trimWhitespaceCleanup?: () => void;\n private __baseHandlersCleanup?: () => void;\n private __pasteHandlerCleanup?: () => void;\n\n private __enterHandler(event: KeyboardEvent) {\n const selection = $getSelection();\n if (!$isRangeSelection(selection)) {\n return false;\n }\n\n if (event === null) {\n return false;\n }\n\n event.preventDefault();\n\n if (event.shiftKey) {\n return this.__editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);\n }\n\n // Mark event handled to override default behavior\n return true;\n }\n\n constructor(editor: LexicalEditor, isSentinelNodeEnabled = true) {\n this.__editor = editor;\n\n this.__baseHandlersCleanup = mergeRegister(\n this.__editor.registerCommand(KEY_ENTER_COMMAND, this.__enterHandler.bind(this), COMMAND_PRIORITY_HIGH),\n isSentinelNodeEnabled ? registerSentinelNodeHandlers(editor) : noop,\n );\n }\n\n activateContentCallbacks(\n onContentChange?: ((value: string) => void) | undefined,\n onCountChanged?: ((count: number) => void) | undefined,\n ): void {\n this.deactivateContentCallbacks();\n this.__contentChangeCleanup = this.__editor.registerUpdateListener(({ editorState, prevEditorState, tags }) => {\n const prevText = getTextFromEditorState(prevEditorState);\n const newText = getTextFromEditorState(editorState);\n\n // If the text has not changed, don't trigger callbacks\n if (prevText === newText) {\n return;\n }\n\n onContentChange?.(newText);\n onCountChanged?.(newText.length);\n });\n }\n\n deactivateContentCallbacks(): void {\n this.__contentChangeCleanup?.();\n this.__contentChangeCleanup = undefined;\n }\n\n activatePasteCallback(onPaste: (event: ClipboardEvent) => void): void {\n this.__pasteHandlerCleanup = this.__editor.registerCommand(\n PASTE_COMMAND,\n (event: ClipboardEvent | KeyboardEvent | InputEvent) => {\n if (!isClipboardEvent(event)) {\n return false;\n }\n\n onPaste(event);\n\n if (event.defaultPrevented) {\n return true;\n }\n\n return false;\n },\n COMMAND_PRIORITY_HIGH,\n );\n }\n\n deactivatePasteCallback(): void {\n this.__pasteHandlerCleanup?.();\n this.__pasteHandlerCleanup = undefined;\n }\n\n activateTrimWhitespace(): void {\n this.deactivateTrimWhitespace();\n this.__trimWhitespaceCleanup = this.__editor.registerTextContentListener(text => {\n if (text.trim() === '') {\n this.__editor.update(\n () => {\n $getRoot()\n .getAllTextNodes()\n .forEach(node => {\n node.remove();\n });\n },\n // Don't allow undoing this action\n { tag: 'historic' },\n );\n }\n });\n }\n\n deactivateTrimWhitespace(): void {\n this.__trimWhitespaceCleanup?.();\n this.__trimWhitespaceCleanup = undefined;\n }\n\n setIsDisabled(isDisabled: boolean): void {\n this.__editor.setEditable(!isDisabled);\n }\n\n cleanup(): void {\n this.deactivateContentCallbacks();\n this.deactivateTrimWhitespace();\n this.deactivatePasteCallback();\n this.__baseHandlersCleanup?.();\n this.__baseHandlersCleanup = undefined;\n }\n}\n\nfunction noop() {\n return;\n}\n"],"names":["COMMAND_PRIORITY_HIGH","$getRoot","$getSelection","$isRangeSelection","INSERT_PARAGRAPH_COMMAND","KEY_ENTER_COMMAND","PASTE_COMMAND","mergeRegister","SENTINEL_VALUE","registerSentinelNodeHandlers","isClipboardEvent","event","type","getTextFromEditorState","state","read","getTextContent","replace","BasicFunctionalityBase","__enterHandler","selection","preventDefault","shiftKey","__editor","dispatchCommand","undefined","activateContentCallbacks","onContentChange","onCountChanged","deactivateContentCallbacks","__contentChangeCleanup","registerUpdateListener","editorState","prevEditorState","tags","prevText","newText","length","activatePasteCallback","onPaste","__pasteHandlerCleanup","registerCommand","defaultPrevented","deactivatePasteCallback","activateTrimWhitespace","deactivateTrimWhitespace","__trimWhitespaceCleanup","registerTextContentListener","text","trim","update","getAllTextNodes","forEach","node","remove","tag","setIsDisabled","isDisabled","setEditable","cleanup","__baseHandlersCleanup","constructor","editor","isSentinelNodeEnabled","bind","noop"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AACA,SAASA,qBAAqB,QAAQ,gCAAgC;AACtE,SACEC,QAAQ,EACRC,aAAa,EACbC,iBAAiB,EACjBC,wBAAwB,EACxBC,iBAAi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;QACA,uBAAQO,0BAAR,KAAA;QACA,uBAAQgB,2BAAR,KAAA;QACA,uBAAQc,yBAAR,KAAA;QACA,uBAAQpB,yBAAR,KAAA;QAuBE,IAAI,CAACjB,QAAQ,GAAGuC;QAEhB,IAAI,CAACF,qBAAqB,GAAGrD,cAC3B,IAAI,CAACgB,QAAQ,CAACkB,eAAe,CAACpC,mBAAmB,IAAI,CAACc,cAAc,CAAC6C,IAAI,CAAC,IAAI,GAAGhE,wBACjF+D,wBAAwBtD,6BAA6BqD,UAAUG;IAEnE;AAsFF;AAEA,SAASA;IACP;AACF"}
|
|
@@ -5,38 +5,37 @@ import { TextNode } from '@fluentui-copilot/text-editor';
|
|
|
5
5
|
// These two characters together are a no-op and should not be present together in any legitimate user input.
|
|
6
6
|
export const SENTINEL_VALUE = '\u200b\u200c';
|
|
7
7
|
export class SentinelNode extends TextNode {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
8
|
+
static getType() {
|
|
9
|
+
return 'sentinel';
|
|
10
|
+
}
|
|
11
|
+
static clone(node) {
|
|
12
|
+
return new SentinelNode(node.__key);
|
|
13
|
+
}
|
|
14
|
+
createDOM(config) {
|
|
15
|
+
const element = super.createDOM(config);
|
|
16
|
+
element.ariaHidden = 'true';
|
|
17
|
+
return element;
|
|
18
|
+
}
|
|
19
|
+
isToken() {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
exportJSON() {
|
|
23
|
+
return {
|
|
24
|
+
...super.exportJSON(),
|
|
25
|
+
type: 'sentinel',
|
|
26
|
+
version: 1
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
static importJSON(serializedNode) {
|
|
30
|
+
return $createSentinelNode();
|
|
31
|
+
}
|
|
32
|
+
constructor(key){
|
|
33
|
+
super(SENTINEL_VALUE, key);
|
|
34
|
+
}
|
|
35
35
|
}
|
|
36
36
|
export function $createSentinelNode(key) {
|
|
37
|
-
|
|
37
|
+
return new SentinelNode(key);
|
|
38
38
|
}
|
|
39
39
|
export function $isSentinelNode(node) {
|
|
40
|
-
|
|
40
|
+
return node instanceof SentinelNode;
|
|
41
41
|
}
|
|
42
|
-
//# sourceMappingURL=SentinelNode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["SentinelNode.ts"],"sourcesContent":["import type { EditorConfig, LexicalNode, NodeKey, SerializedTextNode } from '@fluentui-copilot/text-editor';\nimport { TextNode } from '@fluentui-copilot/text-editor';\n\n// 2 zero width characters will not be visible in the editor.\n// \\u200b is the zero width space character which can allow line wrapping in a word\n// \\u200c is the zero width non-joiner character which prevents ligatures from connecting the two surrounding characters\n// These two characters together are a no-op and should not be present together in any legitimate user input.\nexport const SENTINEL_VALUE = '\\u200b\\u200c';\n\nexport class SentinelNode extends TextNode {\n constructor(key?: NodeKey) {\n super(SENTINEL_VALUE, key);\n }\n\n static getType() {\n return 'sentinel';\n }\n static clone(node: SentinelNode) {\n return new SentinelNode(node.__key);\n }\n\n createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n element.ariaHidden = 'true';\n return element;\n }\n\n isToken() {\n return true;\n }\n\n exportJSON(): SerializedTextNode {\n return {\n ...super.exportJSON(),\n type: 'sentinel',\n version: 1,\n };\n }\n\n static importJSON(serializedNode: SerializedTextNode): SentinelNode {\n return $createSentinelNode();\n }\n}\n\nexport function $createSentinelNode(key?: NodeKey) {\n return new SentinelNode(key);\n}\n\nexport function $isSentinelNode(node: LexicalNode | null): node is SentinelNode {\n return node instanceof SentinelNode;\n}\n"],"names":["TextNode","SENTINEL_VALUE","SentinelNode","getType","clone","node","__key","createDOM","config","element","ariaHidden","isToken","exportJSON","type","version","importJSON","serializedNode","$createSentinelNode","constructor","key","$isSentinelNode"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,QAAQ,QAAQ,gCAAgC;AAEzD,6DAA6D;AAC7D,mFAAmF;AACnF,wHAAwH;AACxH,6GAA6G;AAC7G,OAAO,MAAMC,iBAAiB,eAAe;AAE7C,OAAO,MAAMC,qBAAqBF;IAKhC,OAAOG,
|
|
1
|
+
{"version":3,"sources":["SentinelNode.ts"],"sourcesContent":["import type { EditorConfig, LexicalNode, NodeKey, SerializedTextNode } from '@fluentui-copilot/text-editor';\nimport { TextNode } from '@fluentui-copilot/text-editor';\n\n// 2 zero width characters will not be visible in the editor.\n// \\u200b is the zero width space character which can allow line wrapping in a word\n// \\u200c is the zero width non-joiner character which prevents ligatures from connecting the two surrounding characters\n// These two characters together are a no-op and should not be present together in any legitimate user input.\nexport const SENTINEL_VALUE = '\\u200b\\u200c';\n\nexport class SentinelNode extends TextNode {\n constructor(key?: NodeKey) {\n super(SENTINEL_VALUE, key);\n }\n\n static getType(): string {\n return 'sentinel';\n }\n static clone(node: SentinelNode): SentinelNode {\n return new SentinelNode(node.__key);\n }\n\n createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n element.ariaHidden = 'true';\n return element;\n }\n\n isToken(): boolean {\n return true;\n }\n\n exportJSON(): SerializedTextNode {\n return {\n ...super.exportJSON(),\n type: 'sentinel',\n version: 1,\n };\n }\n\n static importJSON(serializedNode: SerializedTextNode): SentinelNode {\n return $createSentinelNode();\n }\n}\n\nexport function $createSentinelNode(key?: NodeKey): SentinelNode {\n return new SentinelNode(key);\n}\n\nexport function $isSentinelNode(node: LexicalNode | null): node is SentinelNode {\n return node instanceof SentinelNode;\n}\n"],"names":["TextNode","SENTINEL_VALUE","SentinelNode","getType","clone","node","__key","createDOM","config","element","ariaHidden","isToken","exportJSON","type","version","importJSON","serializedNode","$createSentinelNode","constructor","key","$isSentinelNode"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,QAAQ,QAAQ,gCAAgC;AAEzD,6DAA6D;AAC7D,mFAAmF;AACnF,wHAAwH;AACxH,6GAA6G;AAC7G,OAAO,MAAMC,iBAAiB,eAAe;AAE7C,OAAO,MAAMC,qBAAqBF;IAKhC,OAAOG,UAAkB;QACvB,OAAO;IACT;IACA,OAAOC,MAAMC,IAAkB,EAAgB;QAC7C,OAAO,IAAIH,aAAaG,KAAKC,KAAK;IACpC;IAEAC,UAAUC,MAAoB,EAAe;QAC3C,MAAMC,UAAU,KAAK,CAACF,UAAUC;QAChCC,QAAQC,UAAU,GAAG;QACrB,OAAOD;IACT;IAEAE,UAAmB;QACjB,OAAO;IACT;IAEAC,aAAiC;QAC/B,OAAO;YACL,GAAG,KAAK,CAACA,YAAY;YACrBC,MAAM;YACNC,SAAS;QACX;IACF;IAEA,OAAOC,WAAWC,cAAkC,EAAgB;QAClE,OAAOC;IACT;IA/BAC,YAAYC,GAAa,CAAE;QACzB,KAAK,CAAClB,gBAAgBkB;IACxB;AA8BF;AAEA,OAAO,SAASF,oBAAoBE,GAAa;IAC/C,OAAO,IAAIjB,aAAaiB;AAC1B;AAEA,OAAO,SAASC,gBAAgBf,IAAwB;IACtD,OAAOA,gBAAgBH;AACzB"}
|
|
@@ -1,84 +1,79 @@
|
|
|
1
1
|
import { $getLeafNodes, $getNodeByKey, $getRoot, $getSelection, $isRangeSelection, $normalizeSelection__EXPERIMENTAL, $setSelection, mergeRegister } from '@fluentui-copilot/text-editor';
|
|
2
2
|
import { $isSentinelNode, $createSentinelNode, SentinelNode } from './SentinelNode';
|
|
3
3
|
export function registerSentinelNodeHandlers(editor) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
discrete: true,
|
|
32
|
-
tag: 'historic'
|
|
33
|
-
});
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
// If the sentinel node is not selected, we're done
|
|
37
|
-
const previous = lastNode.getPreviousSibling();
|
|
38
|
-
if (!previous || !lastNode.isSelected()) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const selection = $getSelection();
|
|
42
|
-
if (!$isRangeSelection(selection)) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
// If the cursor is inside the sentinel node, move it out (next to the beginning)
|
|
46
|
-
// We allow selection on the boundary of the sentinel in case the adjacent node is a decorator node
|
|
47
|
-
// where selection is ill-defined.
|
|
48
|
-
if (selection.isCollapsed() && selection.anchor.offset > 0) {
|
|
49
|
-
editor.update(() => {
|
|
50
|
-
var _$getNodeByKey;
|
|
51
|
-
(_$getNodeByKey = $getNodeByKey(lastNodeKey)) === null || _$getNodeByKey === void 0 ? void 0 : _$getNodeByKey.selectStart();
|
|
52
|
-
});
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
// If the selection is a range which includes the sentinel, modify the range to exclude it
|
|
56
|
-
if (!selection.isCollapsed()) {
|
|
57
|
-
let selectionChanged = false;
|
|
58
|
-
const newSelection = selection.clone();
|
|
59
|
-
if (newSelection.anchor.getNode() === lastNode && newSelection.anchor.offset > 0) {
|
|
60
|
-
newSelection.anchor.set(lastNodeKey, 0, 'text');
|
|
61
|
-
selectionChanged = true;
|
|
62
|
-
}
|
|
63
|
-
if (newSelection.focus.getNode() === lastNode && newSelection.focus.offset > 0) {
|
|
64
|
-
newSelection.focus.set(lastNodeKey, 0, 'text');
|
|
65
|
-
selectionChanged = true;
|
|
66
|
-
}
|
|
67
|
-
if (selectionChanged) {
|
|
68
|
-
editor.update(() => {
|
|
69
|
-
if ($getNodeByKey(lastNodeKey) !== null) {
|
|
70
|
-
$setSelection($normalizeSelection__EXPERIMENTAL(newSelection));
|
|
4
|
+
// Add a sentinel node at the end of the input when there is content.
|
|
5
|
+
// This sentinel node fixes a number of issues.
|
|
6
|
+
// In Safari, Lexical's behaviour of adding <br /> tags to the end of the input when it ends
|
|
7
|
+
// in a decorator node causes cursor location issues: https://github.com/facebook/lexical/issues/4487
|
|
8
|
+
// Otherwise, when a decorator node is the last node in the input, the cursor can't move past it.
|
|
9
|
+
// Adding an invisible text node that doesn't contribute to the content and can't be selected to the end of the input
|
|
10
|
+
// mitigates these issues.
|
|
11
|
+
const sentinelNodeUpdateHandler = ({ editorState })=>{
|
|
12
|
+
editorState.read(()=>{
|
|
13
|
+
const leaves = $getLeafNodes($getRoot());
|
|
14
|
+
if (leaves.length === 0) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const lastNode = leaves[leaves.length - 1];
|
|
18
|
+
const lastNodeKey = lastNode.getKey();
|
|
19
|
+
// If the last node isn't a sentinel, add one
|
|
20
|
+
if (!$isSentinelNode(lastNode)) {
|
|
21
|
+
editor.update(()=>{
|
|
22
|
+
var // We find the node by its key again in case the node was removed before this update runs
|
|
23
|
+
_$getNodeByKey;
|
|
24
|
+
(_$getNodeByKey = $getNodeByKey(lastNodeKey)) === null || _$getNodeByKey === void 0 ? void 0 : _$getNodeByKey.insertAfter($createSentinelNode());
|
|
25
|
+
}, // historic tag prevents every sentinel node addition from being added to LexicalHistoryPlugin undo stack
|
|
26
|
+
{
|
|
27
|
+
discrete: true,
|
|
28
|
+
tag: 'historic'
|
|
29
|
+
});
|
|
30
|
+
return;
|
|
71
31
|
}
|
|
72
|
-
|
|
32
|
+
// If the sentinel node is not selected, we're done
|
|
33
|
+
const previous = lastNode.getPreviousSibling();
|
|
34
|
+
if (!previous || !lastNode.isSelected()) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const selection = $getSelection();
|
|
38
|
+
if (!$isRangeSelection(selection)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// If the cursor is inside the sentinel node, move it out (next to the beginning)
|
|
42
|
+
// We allow selection on the boundary of the sentinel in case the adjacent node is a decorator node
|
|
43
|
+
// where selection is ill-defined.
|
|
44
|
+
if (selection.isCollapsed() && selection.anchor.offset > 0) {
|
|
45
|
+
editor.update(()=>{
|
|
46
|
+
var _$getNodeByKey;
|
|
47
|
+
(_$getNodeByKey = $getNodeByKey(lastNodeKey)) === null || _$getNodeByKey === void 0 ? void 0 : _$getNodeByKey.selectStart();
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// If the selection is a range which includes the sentinel, modify the range to exclude it
|
|
52
|
+
if (!selection.isCollapsed()) {
|
|
53
|
+
let selectionChanged = false;
|
|
54
|
+
const newSelection = selection.clone();
|
|
55
|
+
if (newSelection.anchor.getNode() === lastNode && newSelection.anchor.offset > 0) {
|
|
56
|
+
newSelection.anchor.set(lastNodeKey, 0, 'text');
|
|
57
|
+
selectionChanged = true;
|
|
58
|
+
}
|
|
59
|
+
if (newSelection.focus.getNode() === lastNode && newSelection.focus.offset > 0) {
|
|
60
|
+
newSelection.focus.set(lastNodeKey, 0, 'text');
|
|
61
|
+
selectionChanged = true;
|
|
62
|
+
}
|
|
63
|
+
if (selectionChanged) {
|
|
64
|
+
editor.update(()=>{
|
|
65
|
+
if ($getNodeByKey(lastNodeKey) !== null) {
|
|
66
|
+
$setSelection($normalizeSelection__EXPERIMENTAL(newSelection));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
return mergeRegister(editor.registerUpdateListener(sentinelNodeUpdateHandler), editor.registerNodeTransform(SentinelNode, (node)=>{
|
|
74
|
+
if (!node.getPreviousSibling() || node.getNextSibling()) {
|
|
75
|
+
node.remove();
|
|
76
|
+
return;
|
|
73
77
|
}
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
return mergeRegister(editor.registerUpdateListener(sentinelNodeUpdateHandler), editor.registerNodeTransform(SentinelNode, node => {
|
|
78
|
-
if (!node.getPreviousSibling() || node.getNextSibling()) {
|
|
79
|
-
node.remove();
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
}));
|
|
78
|
+
}));
|
|
83
79
|
}
|
|
84
|
-
//# sourceMappingURL=SentinelNodeHandlers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["SentinelNodeHandlers.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["SentinelNodeHandlers.ts"],"sourcesContent":["import type { LexicalEditor, UpdateListener } from '@fluentui-copilot/text-editor';\nimport {\n $getLeafNodes,\n $getNodeByKey,\n $getRoot,\n $getSelection,\n $isRangeSelection,\n $normalizeSelection__EXPERIMENTAL,\n $setSelection,\n mergeRegister,\n} from '@fluentui-copilot/text-editor';\nimport { $isSentinelNode, $createSentinelNode, SentinelNode } from './SentinelNode';\n\nexport function registerSentinelNodeHandlers(editor: LexicalEditor): () => void {\n // Add a sentinel node at the end of the input when there is content.\n // This sentinel node fixes a number of issues.\n // In Safari, Lexical's behaviour of adding <br /> tags to the end of the input when it ends\n // in a decorator node causes cursor location issues: https://github.com/facebook/lexical/issues/4487\n // Otherwise, when a decorator node is the last node in the input, the cursor can't move past it.\n // Adding an invisible text node that doesn't contribute to the content and can't be selected to the end of the input\n // mitigates these issues.\n const sentinelNodeUpdateHandler: UpdateListener = ({ editorState }) => {\n editorState.read(() => {\n const leaves = $getLeafNodes($getRoot());\n if (leaves.length === 0) {\n return;\n }\n\n const lastNode = leaves[leaves.length - 1];\n const lastNodeKey = lastNode.getKey();\n\n // If the last node isn't a sentinel, add one\n if (!$isSentinelNode(lastNode)) {\n editor.update(\n () => {\n // We find the node by its key again in case the node was removed before this update runs\n $getNodeByKey(lastNodeKey)?.insertAfter($createSentinelNode());\n },\n // historic tag prevents every sentinel node addition from being added to LexicalHistoryPlugin undo stack\n { discrete: true, tag: 'historic' },\n );\n return;\n }\n\n // If the sentinel node is not selected, we're done\n const previous = lastNode.getPreviousSibling();\n if (!previous || !lastNode.isSelected()) {\n return;\n }\n\n const selection = $getSelection();\n if (!$isRangeSelection(selection)) {\n return;\n }\n\n // If the cursor is inside the sentinel node, move it out (next to the beginning)\n // We allow selection on the boundary of the sentinel in case the adjacent node is a decorator node\n // where selection is ill-defined.\n if (selection.isCollapsed() && selection.anchor.offset > 0) {\n editor.update(() => {\n $getNodeByKey(lastNodeKey)?.selectStart();\n });\n return;\n }\n\n // If the selection is a range which includes the sentinel, modify the range to exclude it\n if (!selection.isCollapsed()) {\n let selectionChanged = false;\n const newSelection = selection.clone();\n\n if (newSelection.anchor.getNode() === lastNode && newSelection.anchor.offset > 0) {\n newSelection.anchor.set(lastNodeKey, 0, 'text');\n selectionChanged = true;\n }\n if (newSelection.focus.getNode() === lastNode && newSelection.focus.offset > 0) {\n newSelection.focus.set(lastNodeKey, 0, 'text');\n selectionChanged = true;\n }\n\n if (selectionChanged) {\n editor.update(() => {\n if ($getNodeByKey(lastNodeKey) !== null) {\n $setSelection($normalizeSelection__EXPERIMENTAL(newSelection));\n }\n });\n }\n }\n });\n };\n\n return mergeRegister(\n editor.registerUpdateListener(sentinelNodeUpdateHandler),\n editor.registerNodeTransform(SentinelNode, node => {\n if (!node.getPreviousSibling() || node.getNextSibling()) {\n node.remove();\n return;\n }\n }),\n );\n}\n"],"names":["$getLeafNodes","$getNodeByKey","$getRoot","$getSelection","$isRangeSelection","$normalizeSelection__EXPERIMENTAL","$setSelection","mergeRegister","$isSentinelNode","$createSentinelNode","SentinelNode","registerSentinelNodeHandlers","editor","sentinelNodeUpdateHandler","editorState","read","leaves","length","lastNode","lastNodeKey","getKey","update","insertAfter","discrete","tag","previous","getPreviousSibling","isSelected","selection","isCollapsed","anchor","offset","selectStart","selectionChanged","newSelection","clone","getNode","set","focus","registerUpdateListener","registerNodeTransform","node","getNextSibling","remove"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SACEA,aAAa,EACbC,aAAa,EACbC,QAAQ,EACRC,aAAa,EACbC,iBAAiB,EACjBC,iCAAiC,EACjCC,aAAa,EACbC,aAAa,QACR,gCAAgC;AACvC,SAASC,eAAe,EAAEC,mBAAmB,EAAEC,YAAY,QAAQ,iBAAiB;AAEpF,OAAO,SAASC,6BAA6BC,MAAqB;IAChE,qEAAqE;IACrE,+CAA+C;IAC/C,4FAA4F;IAC5F,qGAAqG;IACrG,iGAAiG;IACjG,qHAAqH;IACrH,0BAA0B;IAC1B,MAAMC,4BAA4C,CAAC,EAAEC,WAAW,EAAE;QAChEA,YAAYC,IAAI,CAAC;YACf,MAAMC,SAAShB,cAAcE;YAC7B,IAAIc,OAAOC,MAAM,KAAK,GAAG;gBACvB;YACF;YAEA,MAAMC,WAAWF,MAAM,CAACA,OAAOC,MAAM,GAAG,EAAE;YAC1C,MAAME,cAAcD,SAASE,MAAM;YAEnC,6CAA6C;YAC7C,IAAI,CAACZ,gBAAgBU,WAAW;gBAC9BN,OAAOS,MAAM,CACX;wBACE,yFAAyF;oBACzFpB;qBAAAA,iBAAAA,cAAckB,0BAAdlB,qCAAAA,eAA4BqB,WAAW,CAACb;gBAC1C,GACA,yGAAyG;gBACzG;oBAAEc,UAAU;oBAAMC,KAAK;gBAAW;gBAEpC;YACF;YAEA,mDAAmD;YACnD,MAAMC,WAAWP,SAASQ,kBAAkB;YAC5C,IAAI,CAACD,YAAY,CAACP,SAASS,UAAU,IAAI;gBACvC;YACF;YAEA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