@fluentui-copilot/chat-input-plugins 0.5.0 → 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 +16 -1
- package/CHANGELOG.md +11 -2
- package/lib/BasicFunctionality/BasicFunctionality.base.js +90 -96
- 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 +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,22 @@
|
|
|
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",
|
|
6
21
|
"tag": "@fluentui-copilot/chat-input-plugins_v0.5.0",
|
|
7
22
|
"version": "0.5.0",
|
|
8
23
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
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
|
+
|
|
7
16
|
## [0.5.0](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.5.0)
|
|
8
17
|
|
|
9
|
-
Wed, 28 May 2025 23:41:
|
|
18
|
+
Wed, 28 May 2025 23:41:43 GMT
|
|
10
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)
|
|
11
20
|
|
|
12
21
|
### 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
|
|
@@ -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
|