@fluentui-copilot/chat-input-plugins 0.4.2-hotfix.2 → 0.4.2-hotfix.3

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.
Files changed (48) hide show
  1. package/CHANGELOG.json +4 -4
  2. package/CHANGELOG.md +5 -5
  3. package/lib/BasicFunctionality/BasicFunctionality.base.js +92 -92
  4. package/lib/BasicFunctionality/SentinelNode.js +30 -29
  5. package/lib/BasicFunctionality/SentinelNodeHandlers.js +78 -73
  6. package/lib/BasicFunctionality/index.js +1 -0
  7. package/lib/ChatInputEntity/ChatInputEntityPlugin.base.js +114 -109
  8. package/lib/ChatInputEntity/ChatInputEntityPlugin.types.js +2 -1
  9. package/lib/ChatInputEntity/index.js +1 -0
  10. package/lib/GhostText/GhostText.base.js +145 -142
  11. package/lib/GhostText/index.js +1 -0
  12. package/lib/ImperativeControl/ImperativeControl.base.js +83 -82
  13. package/lib/ImperativeControl/index.js +1 -0
  14. package/lib/ManualGhostText/ManualGhostText.base.js +67 -68
  15. package/lib/ManualGhostText/index.js +1 -0
  16. package/lib/PasteUnfurling/PasteUnfurling.base.js +57 -52
  17. package/lib/PasteUnfurling/PasteUnfurling.types.js +2 -1
  18. package/lib/PasteUnfurling/PasteUnfurlingTestUtils.js +139 -138
  19. package/lib/PasteUnfurling/index.js +1 -0
  20. package/lib/index.js +1 -0
  21. package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js +3 -2
  22. package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js.map +1 -1
  23. package/lib-commonjs/BasicFunctionality/SentinelNode.js +1 -1
  24. package/lib-commonjs/BasicFunctionality/SentinelNode.js.map +1 -1
  25. package/lib-commonjs/BasicFunctionality/SentinelNodeHandlers.js +5 -3
  26. package/lib-commonjs/BasicFunctionality/SentinelNodeHandlers.js.map +1 -1
  27. package/lib-commonjs/BasicFunctionality/index.js +1 -0
  28. package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.base.js +5 -3
  29. package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.base.js.map +1 -1
  30. package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.types.js +1 -0
  31. package/lib-commonjs/ChatInputEntity/index.js +1 -0
  32. package/lib-commonjs/GhostText/GhostText.base.js +3 -2
  33. package/lib-commonjs/GhostText/GhostText.base.js.map +1 -1
  34. package/lib-commonjs/GhostText/index.js +1 -0
  35. package/lib-commonjs/ImperativeControl/ImperativeControl.base.js +1 -1
  36. package/lib-commonjs/ImperativeControl/ImperativeControl.base.js.map +1 -1
  37. package/lib-commonjs/ImperativeControl/index.js +1 -0
  38. package/lib-commonjs/ManualGhostText/ManualGhostText.base.js +1 -1
  39. package/lib-commonjs/ManualGhostText/ManualGhostText.base.js.map +1 -1
  40. package/lib-commonjs/ManualGhostText/index.js +1 -0
  41. package/lib-commonjs/PasteUnfurling/PasteUnfurling.base.js +1 -1
  42. package/lib-commonjs/PasteUnfurling/PasteUnfurling.base.js.map +1 -1
  43. package/lib-commonjs/PasteUnfurling/PasteUnfurling.types.js +1 -0
  44. package/lib-commonjs/PasteUnfurling/PasteUnfurlingTestUtils.js +1 -1
  45. package/lib-commonjs/PasteUnfurling/PasteUnfurlingTestUtils.js.map +1 -1
  46. package/lib-commonjs/PasteUnfurling/index.js +1 -0
  47. package/lib-commonjs/index.js +1 -0
  48. package/package.json +2 -2
@@ -2,86 +2,87 @@ 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
- 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
- }
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 +1,2 @@
1
1
  export { ImperativeControlBase } from './ImperativeControl.base';
2
+ //# sourceMappingURL=index.js.map
@@ -1,78 +1,77 @@
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
- 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) {
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([node]);
26
+ node.selectStart();
27
+ }, {
28
+ tag: 'historic',
29
+ discrete: discrete ? true : undefined
30
+ });
31
+ }
32
+ commitGhostText(finalText, discrete) {
33
+ if (this.__nodeKey) {
34
+ this.__editor.update(() => {
35
35
  if (this.__nodeKey) {
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;
36
+ const node = $getNodeByKey(this.__nodeKey);
37
+ if (this.__$isNodeType(node)) {
38
+ const textNode = $createTextNode(finalText);
39
+ node.replace(textNode);
40
+ textNode.selectEnd();
41
+ }
49
42
  }
43
+ }, {
44
+ discrete: discrete ? true : undefined
45
+ });
46
+ this.__nodeKey = undefined;
50
47
  }
51
- cancelGhostText(discrete) {
48
+ }
49
+ cancelGhostText(discrete) {
50
+ if (this.__nodeKey) {
51
+ this.__editor.update(() => {
52
52
  if (this.__nodeKey) {
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;
53
+ const node = $getNodeByKey(this.__nodeKey);
54
+ if (this.__$isNodeType(node)) {
55
+ node.remove();
56
+ }
65
57
  }
58
+ }, {
59
+ tag: 'historic',
60
+ discrete: discrete ? true : undefined
61
+ });
62
+ this.__nodeKey = undefined;
66
63
  }
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
- }
64
+ }
65
+ constructor(editor, id, $isNodeType, $createNode) {
66
+ _define_property(this, "__editor", void 0);
67
+ _define_property(this, "__nodeKey", void 0);
68
+ _define_property(this, "__id", void 0);
69
+ _define_property(this, "__$isNodeType", void 0);
70
+ _define_property(this, "__$createNode", void 0);
71
+ this.__editor = editor;
72
+ this.__id = id;
73
+ this.__$isNodeType = $isNodeType;
74
+ this.__$createNode = $createNode;
75
+ }
78
76
  }
77
+ //# sourceMappingURL=ManualGhostText.base.js.map
@@ -1 +1,2 @@
1
1
  export { ManualGhostTextBase } from './ManualGhostText.base';
2
+ //# sourceMappingURL=index.js.map
@@ -1,60 +1,65 @@
1
1
  import { COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_LOW, PASTE_COMMAND, $insertNodes, $createTextNode } from '@fluentui-copilot/text-editor';
2
2
  function unhandledPart(part) {
3
- throw new Error(`Unhandled part: ${part}`);
3
+ throw new Error(`Unhandled part: ${part}`);
4
4
  }
5
5
  export function registerPasteUnfurlingPlugin(editor, props) {
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
- });
6
+ const {
7
+ entityPluginId,
8
+ transforms,
9
+ $createEntityNode
10
+ } = props;
11
+ function insertParts(parts) {
12
+ editor.update(() => {
13
+ const nodes = parts.map(part => {
14
+ switch (part.type) {
15
+ case 'entity':
16
+ return $createEntityNode(entityPluginId, part.value.text, part.value.data, part.value.entityProps);
17
+ case 'text':
18
+ return $createTextNode(part.value);
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)));
20
29
  }
21
- function handlePaste(event) {
22
- const transformPromises = [];
23
- for (const transform of transforms){
24
- transformPromises.push(Promise.resolve(transform(event, editor)));
30
+ Promise.allSettled(transformPromises).then(results => {
31
+ let handledPaste = false;
32
+ for (const result of results) {
33
+ if (result.status === 'fulfilled') {
34
+ const transformResult = result.value;
35
+ if (transformResult.transformedParts) {
36
+ insertParts(transformResult.transformedParts);
37
+ }
38
+ if (transformResult.handled) {
39
+ handledPaste = true;
40
+ break;
41
+ }
25
42
  }
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
- }
39
- }
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
- }
43
+ }
44
+ if (!handledPaste) {
45
+ var _commandsMap_get;
46
+ const commandsMap = editor._commands;
47
+ const defaultEditorListeners = (_commandsMap_get = commandsMap.get(PASTE_COMMAND)) === null || _commandsMap_get === void 0 ? void 0 : _commandsMap_get[COMMAND_PRIORITY_EDITOR];
48
+ if (defaultEditorListeners) {
49
+ // After the promises have resolved, we're not guaranteed to be in the same update state as the original command
50
+ editor.update(() => {
51
+ for (const listener of defaultEditorListeners) {
52
+ const defaultHandled = listener(event, editor);
53
+ if (defaultHandled) {
54
+ break;
55
+ }
55
56
  }
56
- });
57
- return true;
58
- }
59
- return editor.registerCommand(PASTE_COMMAND, handlePaste, COMMAND_PRIORITY_LOW);
57
+ });
58
+ }
59
+ }
60
+ });
61
+ return true;
62
+ }
63
+ return editor.registerCommand(PASTE_COMMAND, handlePaste, COMMAND_PRIORITY_LOW);
60
64
  }
65
+ //# sourceMappingURL=PasteUnfurling.base.js.map
@@ -1 +1,2 @@
1
- export { };
1
+ export {};
2
+ //# sourceMappingURL=PasteUnfurling.types.js.map