@fluentui-copilot/chat-input-plugins 0.4.1 → 0.4.2-hotfix.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 +45 -0
- package/CHANGELOG.md +19 -1
- package/dist/index.d.ts +1 -1
- package/lib/BasicFunctionality/BasicFunctionality.base.js +94 -91
- 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 +7 -5
- 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 +3 -7
|
@@ -2,87 +2,86 @@ import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
|
2
2
|
import { $createParagraphNode, $createRangeSelection, $createTextNode, $getLeafNodes, $getRoot, $getSelection, $isTextNode, $normalizeSelection__EXPERIMENTAL, $setSelection } from '@fluentui-copilot/text-editor';
|
|
3
3
|
import { SENTINEL_VALUE, $isSentinelNode } from '../BasicFunctionality';
|
|
4
4
|
export class ImperativeControlBase {
|
|
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
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
5
|
+
moveCursor(location) {
|
|
6
|
+
this.__editor.update(()=>{
|
|
7
|
+
const children = $getLeafNodes($getRoot());
|
|
8
|
+
let baseOffset = 0;
|
|
9
|
+
let currentNode = children.shift();
|
|
10
|
+
while(baseOffset < location && currentNode){
|
|
11
|
+
const nodeLength = $isTextNode(currentNode) && !currentNode.isToken() ? currentNode.getTextContent().length : 1;
|
|
12
|
+
if (baseOffset + nodeLength >= location) {
|
|
13
|
+
const elementType = $isTextNode(currentNode) ? 'text' : 'element';
|
|
14
|
+
const localOffset = location - baseOffset;
|
|
15
|
+
const nodeKey = currentNode.getKey();
|
|
16
|
+
const selection = $createRangeSelection();
|
|
17
|
+
selection.anchor.set(nodeKey, localOffset, elementType);
|
|
18
|
+
selection.focus.set(nodeKey, localOffset, elementType);
|
|
19
|
+
$setSelection($normalizeSelection__EXPERIMENTAL(selection));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
baseOffset += nodeLength;
|
|
23
|
+
currentNode = children.shift();
|
|
24
|
+
}
|
|
25
|
+
if (location > baseOffset) {
|
|
26
|
+
$getRoot().selectEnd();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
setInputText(inputText) {
|
|
31
|
+
this.__editor.update(()=>{
|
|
32
|
+
const root = $getRoot();
|
|
33
|
+
root.clear();
|
|
34
|
+
if (inputText !== '') {
|
|
35
|
+
const newParagraph = $createParagraphNode();
|
|
36
|
+
const newText = $createTextNode(inputText);
|
|
37
|
+
newParagraph.append(newText);
|
|
38
|
+
root.append(newParagraph);
|
|
39
|
+
root.selectEnd();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
appendText(text) {
|
|
44
|
+
this.__editor.update(()=>{
|
|
45
|
+
$getRoot().selectEnd().insertText(text);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
prependText(text) {
|
|
49
|
+
this.__editor.update(()=>{
|
|
50
|
+
$getRoot().selectStart().insertText(text);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
insertTextAtCursor(text) {
|
|
54
|
+
this.__editor.update(()=>{
|
|
55
|
+
var _$getSelection;
|
|
56
|
+
const selection = (_$getSelection = $getSelection()) !== null && _$getSelection !== void 0 ? _$getSelection : $getRoot().selectEnd();
|
|
57
|
+
selection.insertText(text);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
getInputText(transform) {
|
|
61
|
+
return this.__editor.getEditorState().read(()=>{
|
|
62
|
+
if (!transform) {
|
|
63
|
+
return $getRoot().getTextContent().replace(SENTINEL_VALUE, '');
|
|
64
|
+
}
|
|
65
|
+
const children = $getLeafNodes($getRoot());
|
|
66
|
+
const transformedNodeTexts = [];
|
|
67
|
+
for (const currentNode of children){
|
|
68
|
+
if (!$isSentinelNode(currentNode)) {
|
|
69
|
+
transformedNodeTexts.push(transform(currentNode));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return transformedNodeTexts.join('');
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
scrollToBottom() {
|
|
76
|
+
var _this___editor_getRootElement;
|
|
77
|
+
(_this___editor_getRootElement = this.__editor.getRootElement()) === null || _this___editor_getRootElement === void 0 ? void 0 : _this___editor_getRootElement.scrollIntoView({
|
|
78
|
+
behavior: 'smooth',
|
|
79
|
+
block: 'end'
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
constructor(editor){
|
|
84
|
+
_define_property(this, "__editor", void 0);
|
|
85
|
+
this.__editor = editor;
|
|
86
|
+
}
|
|
87
87
|
}
|
|
88
|
-
//# sourceMappingURL=ImperativeControl.base.js.map
|
|
@@ -1,77 +1,78 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import { $createTextNode, $getNodeByKey, $insertNodes } from '@fluentui-copilot/text-editor';
|
|
3
3
|
export class ManualGhostTextBase {
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
4
|
+
getGhostText() {
|
|
5
|
+
return this.__editor.getEditorState().read(()=>{
|
|
6
|
+
if (this.__nodeKey) {
|
|
7
|
+
const node = $getNodeByKey(this.__nodeKey);
|
|
8
|
+
if (this.__$isNodeType(node)) {
|
|
9
|
+
return node.__content;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
setGhostText(text, exposeText, componentProps, discrete) {
|
|
15
|
+
this.__editor.update(()=>{
|
|
16
|
+
if (this.__nodeKey) {
|
|
17
|
+
const node = $getNodeByKey(this.__nodeKey);
|
|
18
|
+
if (this.__$isNodeType(node)) {
|
|
19
|
+
node.getWritable().__content = text;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const node = this.__$createNode(this.__id, text, exposeText, componentProps);
|
|
24
|
+
this.__nodeKey = node.getKey();
|
|
25
|
+
$insertNodes([
|
|
26
|
+
node
|
|
27
|
+
]);
|
|
28
|
+
node.selectStart();
|
|
29
|
+
}, {
|
|
30
|
+
tag: 'historic',
|
|
31
|
+
discrete: discrete ? true : undefined
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
commitGhostText(finalText, discrete) {
|
|
35
35
|
if (this.__nodeKey) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
this.__editor.update(()=>{
|
|
37
|
+
if (this.__nodeKey) {
|
|
38
|
+
const node = $getNodeByKey(this.__nodeKey);
|
|
39
|
+
if (this.__$isNodeType(node)) {
|
|
40
|
+
const textNode = $createTextNode(finalText);
|
|
41
|
+
node.replace(textNode);
|
|
42
|
+
textNode.selectEnd();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}, {
|
|
46
|
+
discrete: discrete ? true : undefined
|
|
47
|
+
});
|
|
48
|
+
this.__nodeKey = undefined;
|
|
42
49
|
}
|
|
43
|
-
}, {
|
|
44
|
-
discrete: discrete ? true : undefined
|
|
45
|
-
});
|
|
46
|
-
this.__nodeKey = undefined;
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
cancelGhostText(discrete) {
|
|
50
|
-
if (this.__nodeKey) {
|
|
51
|
-
this.__editor.update(() => {
|
|
51
|
+
cancelGhostText(discrete) {
|
|
52
52
|
if (this.__nodeKey) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
this.__editor.update(()=>{
|
|
54
|
+
if (this.__nodeKey) {
|
|
55
|
+
const node = $getNodeByKey(this.__nodeKey);
|
|
56
|
+
if (this.__$isNodeType(node)) {
|
|
57
|
+
node.remove();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
tag: 'historic',
|
|
62
|
+
discrete: discrete ? true : undefined
|
|
63
|
+
});
|
|
64
|
+
this.__nodeKey = undefined;
|
|
57
65
|
}
|
|
58
|
-
}, {
|
|
59
|
-
tag: 'historic',
|
|
60
|
-
discrete: discrete ? true : undefined
|
|
61
|
-
});
|
|
62
|
-
this.__nodeKey = undefined;
|
|
63
66
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
67
|
+
constructor(editor, id, $isNodeType, $createNode){
|
|
68
|
+
_define_property(this, "__editor", void 0);
|
|
69
|
+
_define_property(this, "__nodeKey", void 0);
|
|
70
|
+
_define_property(this, "__id", void 0);
|
|
71
|
+
_define_property(this, "__$isNodeType", void 0);
|
|
72
|
+
_define_property(this, "__$createNode", void 0);
|
|
73
|
+
this.__editor = editor;
|
|
74
|
+
this.__id = id;
|
|
75
|
+
this.__$isNodeType = $isNodeType;
|
|
76
|
+
this.__$createNode = $createNode;
|
|
77
|
+
}
|
|
76
78
|
}
|
|
77
|
-
//# sourceMappingURL=ManualGhostText.base.js.map
|
|
@@ -1,65 +1,60 @@
|
|
|
1
1
|
import { COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_LOW, PASTE_COMMAND, $insertNodes, $createTextNode } from '@fluentui-copilot/text-editor';
|
|
2
2
|
function unhandledPart(part) {
|
|
3
|
-
|
|
3
|
+
throw new Error(`Unhandled part: ${part}`);
|
|
4
4
|
}
|
|
5
5
|
export function registerPasteUnfurlingPlugin(editor, props) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return unhandledPart(part);
|
|
21
|
-
});
|
|
22
|
-
$insertNodes(nodes);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function handlePaste(event) {
|
|
26
|
-
const transformPromises = [];
|
|
27
|
-
for (const transform of transforms) {
|
|
28
|
-
transformPromises.push(Promise.resolve(transform(event, editor)));
|
|
6
|
+
const { entityPluginId, transforms, $createEntityNode } = props;
|
|
7
|
+
function insertParts(parts) {
|
|
8
|
+
editor.update(()=>{
|
|
9
|
+
const nodes = parts.map((part)=>{
|
|
10
|
+
switch(part.type){
|
|
11
|
+
case 'entity':
|
|
12
|
+
return $createEntityNode(entityPluginId, part.value.text, part.value.data, part.value.entityProps);
|
|
13
|
+
case 'text':
|
|
14
|
+
return $createTextNode(part.value);
|
|
15
|
+
}
|
|
16
|
+
return unhandledPart(part);
|
|
17
|
+
});
|
|
18
|
+
$insertNodes(nodes);
|
|
19
|
+
});
|
|
29
20
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const transformResult = result.value;
|
|
35
|
-
if (transformResult.transformedParts) {
|
|
36
|
-
insertParts(transformResult.transformedParts);
|
|
37
|
-
}
|
|
38
|
-
if (transformResult.handled) {
|
|
39
|
-
handledPaste = true;
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
21
|
+
function handlePaste(event) {
|
|
22
|
+
const transformPromises = [];
|
|
23
|
+
for (const transform of transforms){
|
|
24
|
+
transformPromises.push(Promise.resolve(transform(event, editor)));
|
|
42
25
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
26
|
+
Promise.allSettled(transformPromises).then((results)=>{
|
|
27
|
+
let handledPaste = false;
|
|
28
|
+
for (const result of results){
|
|
29
|
+
if (result.status === 'fulfilled') {
|
|
30
|
+
const transformResult = result.value;
|
|
31
|
+
if (transformResult.transformedParts) {
|
|
32
|
+
insertParts(transformResult.transformedParts);
|
|
33
|
+
}
|
|
34
|
+
if (transformResult.handled) {
|
|
35
|
+
handledPaste = true;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
56
39
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
40
|
+
if (!handledPaste) {
|
|
41
|
+
var _commandsMap_get;
|
|
42
|
+
const commandsMap = editor._commands;
|
|
43
|
+
const defaultEditorListeners = (_commandsMap_get = commandsMap.get(PASTE_COMMAND)) === null || _commandsMap_get === void 0 ? void 0 : _commandsMap_get[COMMAND_PRIORITY_EDITOR];
|
|
44
|
+
if (defaultEditorListeners) {
|
|
45
|
+
// After the promises have resolved, we're not guaranteed to be in the same update state as the original command
|
|
46
|
+
editor.update(()=>{
|
|
47
|
+
for (const listener of defaultEditorListeners){
|
|
48
|
+
const defaultHandled = listener(event, editor);
|
|
49
|
+
if (defaultHandled) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return editor.registerCommand(PASTE_COMMAND, handlePaste, COMMAND_PRIORITY_LOW);
|
|
64
60
|
}
|
|
65
|
-
//# sourceMappingURL=PasteUnfurling.base.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=PasteUnfurling.types.js.map
|
|
1
|
+
export { };
|