@fluentui-copilot/chat-input-plugins 0.4.2 → 0.5.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/CHANGELOG.json +61 -1
- package/CHANGELOG.md +20 -2
- package/dist/index.d.ts +0 -2
- package/lib/BasicFunctionality/BasicFunctionality.base.js +92 -93
- package/lib/BasicFunctionality/BasicFunctionality.base.js.map +1 -1
- package/lib/BasicFunctionality/SentinelNode.js +29 -30
- package/lib/BasicFunctionality/SentinelNodeHandlers.js +73 -78
- package/lib/BasicFunctionality/index.js +0 -1
- package/lib/ChatInputEntity/ChatInputEntityPlugin.base.js +109 -114
- 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/index.js +0 -1
- package/lib/ImperativeControl/ImperativeControl.base.js +82 -83
- 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/index.js +0 -1
- package/lib/index.js +0 -1
- package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js +15 -17
- 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,67 @@
|
|
|
2
2
|
"name": "@fluentui-copilot/chat-input-plugins",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Thu, 17 Jul 2025 17:47:35 GMT",
|
|
6
|
+
"tag": "@fluentui-copilot/chat-input-plugins_v0.5.1",
|
|
7
|
+
"version": "0.5.1",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "hochelmartin@gmail.com",
|
|
12
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
13
|
+
"commit": "fef5160c07333e8d9996952a305b34e357604919",
|
|
14
|
+
"comment": "feat: enable griffel raw styles"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Wed, 28 May 2025 23:41:43 GMT",
|
|
21
|
+
"tag": "@fluentui-copilot/chat-input-plugins_v0.5.0",
|
|
22
|
+
"version": "0.5.0",
|
|
23
|
+
"comments": {
|
|
24
|
+
"minor": [
|
|
25
|
+
{
|
|
26
|
+
"author": "owcampbe@microsoft.com",
|
|
27
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
28
|
+
"commit": "914b30d1dd5b9e19a2a156578894a7b8163f9caf",
|
|
29
|
+
"comment": "feat: Filter out SentinelNode and defaultValue changes from onChange."
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"date": "Mon, 19 May 2025 18:04:26 GMT",
|
|
36
|
+
"tag": "@fluentui-copilot/chat-input-plugins_v0.4.2",
|
|
37
|
+
"version": "0.4.2",
|
|
38
|
+
"comments": {
|
|
39
|
+
"none": [
|
|
40
|
+
{
|
|
41
|
+
"author": "hochelmartin@gmail.com",
|
|
42
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
43
|
+
"commit": "442954951d0eca92de20ecb0ff0fa9492431b62d",
|
|
44
|
+
"comment": "fix: exclude story files from production build"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"date": "Wed, 30 Apr 2025 01:47:47 GMT",
|
|
51
|
+
"tag": "@fluentui-copilot/chat-input-plugins_v0.4.2",
|
|
52
|
+
"version": "0.4.2",
|
|
53
|
+
"comments": {
|
|
54
|
+
"none": [
|
|
55
|
+
{
|
|
56
|
+
"author": "tristan.watanabe@gmail.com",
|
|
57
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
58
|
+
"commit": "1391e0a7243d050db30fcc27547fd3e91df0162c",
|
|
59
|
+
"comment": "chore: update tsconfig to remove allowSyntheticDefaultImports to enforce named imports."
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"date": "Fri, 07 Feb 2025 02:02:08 GMT",
|
|
6
66
|
"tag": "@fluentui-copilot/chat-input-plugins_v0.4.2",
|
|
7
67
|
"version": "0.4.2",
|
|
8
68
|
"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 Thu, 17 Jul 2025 17:47:35 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [0.5.1](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.5.1)
|
|
8
|
+
|
|
9
|
+
Thu, 17 Jul 2025 17:47:35 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.5.0..@fluentui-copilot/chat-input-plugins_v0.5.1)
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- feat: enable griffel raw styles ([PR #3227](https://github.com/microsoft/fluentai/pull/3227) by hochelmartin@gmail.com)
|
|
15
|
+
|
|
16
|
+
## [0.5.0](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.5.0)
|
|
17
|
+
|
|
18
|
+
Wed, 28 May 2025 23:41:43 GMT
|
|
19
|
+
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.4.2..@fluentui-copilot/chat-input-plugins_v0.5.0)
|
|
20
|
+
|
|
21
|
+
### Minor changes
|
|
22
|
+
|
|
23
|
+
- feat: Filter out SentinelNode and defaultValue changes from onChange. ([PR #3032](https://github.com/microsoft/fluentai/pull/3032) by owcampbe@microsoft.com)
|
|
24
|
+
|
|
7
25
|
## [0.4.2](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.4.2)
|
|
8
26
|
|
|
9
|
-
Fri, 07 Feb 2025 02:
|
|
27
|
+
Fri, 07 Feb 2025 02:02:08 GMT
|
|
10
28
|
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.3.4..@fluentui-copilot/chat-input-plugins_v0.4.2)
|
|
11
29
|
|
|
12
30
|
### Patches
|
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,6 @@ export declare class BasicFunctionalityBase implements IBasicFunctionalityBase {
|
|
|
19
19
|
private __pasteHandlerCleanup?;
|
|
20
20
|
private __enterHandler;
|
|
21
21
|
constructor(editor: LexicalEditor, isSentinelNodeEnabled?: boolean);
|
|
22
|
-
insertDefaultValue(defaultValue: string): void;
|
|
23
22
|
activateContentCallbacks(onContentChange?: ((value: string) => void) | undefined, onCountChanged?: ((count: number) => void) | undefined): void;
|
|
24
23
|
deactivateContentCallbacks(): void;
|
|
25
24
|
activatePasteCallback(onPaste: (event: ClipboardEvent) => void): void;
|
|
@@ -76,7 +75,6 @@ export declare class GhostTextPluginBase<ComponentPropsType> {
|
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
export declare interface IBasicFunctionalityBase {
|
|
79
|
-
insertDefaultValue: (defaultValue: string) => void;
|
|
80
78
|
setIsDisabled: (isDisabled: boolean) => void;
|
|
81
79
|
activateContentCallbacks(onContentChange?: (value: string) => void, onCountChanged?: (count: number) => void): void;
|
|
82
80
|
deactivateContentCallbacks(): void;
|
|
@@ -1,108 +1,107 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import { COMMAND_PRIORITY_HIGH } from '@fluentui-copilot/text-editor';
|
|
3
|
-
import { $
|
|
3
|
+
import { $getRoot, $getSelection, $isRangeSelection, INSERT_PARAGRAPH_COMMAND, KEY_ENTER_COMMAND, PASTE_COMMAND, mergeRegister } from '@fluentui-copilot/text-editor';
|
|
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
|
+
}
|
|
9
|
+
function getTextFromEditorState(state) {
|
|
10
|
+
// Remove the sentinel node whenever getting the text
|
|
11
|
+
return state.read(()=>$getRoot().getTextContent()).replace(SENTINEL_VALUE, '');
|
|
8
12
|
}
|
|
9
13
|
export class BasicFunctionalityBase {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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;
|
|
14
28
|
}
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
});
|
|
17
41
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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;
|
|
21
46
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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);
|
|
30
58
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
onPaste(event);
|
|
52
|
-
if (event.defaultPrevented) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
}, COMMAND_PRIORITY_HIGH);
|
|
57
|
-
}
|
|
58
|
-
deactivatePasteCallback() {
|
|
59
|
-
var _this___pasteHandlerCleanup, _this;
|
|
60
|
-
(_this___pasteHandlerCleanup = (_this = this).__pasteHandlerCleanup) === null || _this___pasteHandlerCleanup === void 0 ? void 0 : _this___pasteHandlerCleanup.call(_this);
|
|
61
|
-
this.__pasteHandlerCleanup = undefined;
|
|
62
|
-
}
|
|
63
|
-
activateTrimWhitespace() {
|
|
64
|
-
this.deactivateTrimWhitespace();
|
|
65
|
-
this.__trimWhitespaceCleanup = this.__editor.registerTextContentListener(text => {
|
|
66
|
-
if (text.trim() === '') {
|
|
67
|
-
this.__editor.update(() => {
|
|
68
|
-
$getRoot().getAllTextNodes().forEach(node => {
|
|
69
|
-
node.remove();
|
|
70
|
-
});
|
|
71
|
-
},
|
|
72
|
-
// Don't allow undoing this action
|
|
73
|
-
{
|
|
74
|
-
tag: 'historic'
|
|
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
|
+
}
|
|
75
77
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this.__baseHandlersCleanup = mergeRegister(this.__editor.registerCommand(KEY_ENTER_COMMAND, this.__enterHandler.bind(this), COMMAND_PRIORITY_HIGH), isSentinelNodeEnabled ? registerSentinelNodeHandlers(editor) : noop);
|
|
103
|
-
}
|
|
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
|
+
}
|
|
104
104
|
}
|
|
105
105
|
function noop() {
|
|
106
|
-
|
|
106
|
+
return;
|
|
107
107
|
}
|
|
108
|
-
//# sourceMappingURL=BasicFunctionality.base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["BasicFunctionality.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport { COMMAND_PRIORITY_HIGH } from '@fluentui-copilot/text-editor';\nimport {\n $
|
|
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,E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jE,uBAAQxC,YAAR,KAAA;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,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
|