@fluentui-copilot/chat-input-plugins 0.0.1 → 0.0.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.
- package/CHANGELOG.json +37 -1
- package/CHANGELOG.md +21 -2
- package/dist/index.d.ts +2 -0
- package/lib/BasicFunctionality/BasicFunctionality.base.js +1 -1
- package/lib/BasicFunctionality/BasicFunctionality.base.js.map +1 -1
- package/lib/GhostText/GhostText.base.js +7 -0
- package/lib/GhostText/GhostText.base.js.map +1 -1
- package/lib/ImperativeControl/ImperativeControl.base.js +26 -1
- package/lib/ImperativeControl/ImperativeControl.base.js.map +1 -1
- package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js +1 -1
- package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js.map +1 -1
- package/lib-commonjs/GhostText/GhostText.base.js +7 -0
- package/lib-commonjs/GhostText/GhostText.base.js.map +1 -1
- package/lib-commonjs/ImperativeControl/ImperativeControl.base.js +25 -0
- package/lib-commonjs/ImperativeControl/ImperativeControl.base.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,43 @@
|
|
|
2
2
|
"name": "@fluentui-copilot/chat-input-plugins",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Thu, 18 Apr 2024 00:27:52 GMT",
|
|
6
|
+
"tag": "@fluentui-copilot/chat-input-plugins_v0.0.3",
|
|
7
|
+
"version": "0.0.3",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "owcampbe@microsoft.com",
|
|
12
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
13
|
+
"commit": "50adfb80f8441f2f9fa58fa60d751707ceef5367",
|
|
14
|
+
"comment": "fix: Allow navigating past GhostText."
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"author": "owcampbe@microsoft.com",
|
|
18
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
19
|
+
"commit": "f2dda4b0a5319dde7830506e15c49e9f3505ca23",
|
|
20
|
+
"comment": "fix: Bind this to callback."
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"date": "Tue, 16 Apr 2024 17:55:27 GMT",
|
|
27
|
+
"tag": "@fluentui-copilot/chat-input-plugins_v0.0.2",
|
|
28
|
+
"version": "0.0.2",
|
|
29
|
+
"comments": {
|
|
30
|
+
"patch": [
|
|
31
|
+
{
|
|
32
|
+
"author": "owcampbe@microsoft.com",
|
|
33
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
34
|
+
"commit": "67fe97fe19c40d2a0e93f4c48b2e727af2440c45",
|
|
35
|
+
"comment": "feat: Add `moveCursor` function to ImperativeControlPlugin."
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"date": "Wed, 10 Apr 2024 23:07:49 GMT",
|
|
6
42
|
"tag": "@fluentui-copilot/chat-input-plugins_v0.0.1",
|
|
7
43
|
"version": "0.0.1",
|
|
8
44
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
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, 18 Apr 2024 00:27:52 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [0.0.3](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.0.3)
|
|
8
|
+
|
|
9
|
+
Thu, 18 Apr 2024 00:27:52 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.0.2..@fluentui-copilot/chat-input-plugins_v0.0.3)
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- fix: Allow navigating past GhostText. ([PR #1563](https://github.com/microsoft/fluentai/pull/1563) by owcampbe@microsoft.com)
|
|
15
|
+
- fix: Bind this to callback. ([PR #1565](https://github.com/microsoft/fluentai/pull/1565) by owcampbe@microsoft.com)
|
|
16
|
+
|
|
17
|
+
## [0.0.2](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.0.2)
|
|
18
|
+
|
|
19
|
+
Tue, 16 Apr 2024 17:55:27 GMT
|
|
20
|
+
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.0.1..@fluentui-copilot/chat-input-plugins_v0.0.2)
|
|
21
|
+
|
|
22
|
+
### Patches
|
|
23
|
+
|
|
24
|
+
- feat: Add `moveCursor` function to ImperativeControlPlugin. ([PR #1539](https://github.com/microsoft/fluentai/pull/1539) by owcampbe@microsoft.com)
|
|
25
|
+
|
|
7
26
|
## [0.0.1](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.0.1)
|
|
8
27
|
|
|
9
|
-
Wed, 10 Apr 2024 23:
|
|
28
|
+
Wed, 10 Apr 2024 23:07:49 GMT
|
|
10
29
|
|
|
11
30
|
### Patches
|
|
12
31
|
|
package/dist/index.d.ts
CHANGED
|
@@ -105,6 +105,7 @@ export declare interface IImperativeControlBase {
|
|
|
105
105
|
insertTextAtCursor: (text: string) => void;
|
|
106
106
|
getInputText: () => string;
|
|
107
107
|
scrollToBottom: () => void;
|
|
108
|
+
moveCursor: (location: number) => void;
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
export declare interface IManualGhostTextBase<ComponentPropsType> {
|
|
@@ -117,6 +118,7 @@ export declare interface IManualGhostTextBase<ComponentPropsType> {
|
|
|
117
118
|
export declare class ImperativeControlBase implements IImperativeControlBase {
|
|
118
119
|
private __editor;
|
|
119
120
|
constructor(editor: LexicalEditor);
|
|
121
|
+
moveCursor(location: number): void;
|
|
120
122
|
setInputText(inputText: string): void;
|
|
121
123
|
appendText(text: string): void;
|
|
122
124
|
prependText(text: string): void;
|
|
@@ -72,7 +72,7 @@ export class BasicFunctionalityBase {
|
|
|
72
72
|
_define_property(this, "__trimWhitespaceCleanup", void 0);
|
|
73
73
|
_define_property(this, "__enterHandlerCleanup", void 0);
|
|
74
74
|
this.__editor = editor;
|
|
75
|
-
this.__enterHandlerCleanup = this.__editor.registerCommand(KEY_ENTER_COMMAND, this.__enterHandler, COMMAND_PRIORITY_CRITICAL);
|
|
75
|
+
this.__enterHandlerCleanup = this.__editor.registerCommand(KEY_ENTER_COMMAND, this.__enterHandler.bind(this), COMMAND_PRIORITY_CRITICAL);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
//# sourceMappingURL=BasicFunctionality.base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["BasicFunctionality.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport {\n $createTextNode,\n $getRoot,\n $getSelection,\n $insertNodes,\n $isRangeSelection,\n COMMAND_PRIORITY_CRITICAL,\n INSERT_PARAGRAPH_COMMAND,\n KEY_ENTER_COMMAND,\n} from '@fluentui-copilot/text-editor';\n\nexport interface IBasicFunctionalityBase {\n insertDefaultValue: (defaultValue: string) => void;\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 cleanup(): void;\n}\n\nexport class BasicFunctionalityBase implements IBasicFunctionalityBase {\n private __editor: LexicalEditor;\n private __contentChangeCleanup?: () => void;\n private __trimWhitespaceCleanup?: () => void;\n private __enterHandlerCleanup?: () => 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) {\n this.__editor = editor;\n\n this.__enterHandlerCleanup = this.__editor.registerCommand(\n KEY_ENTER_COMMAND,\n this.__enterHandler,\n COMMAND_PRIORITY_CRITICAL,\n );\n }\n\n insertDefaultValue(defaultValue: string) {\n if (defaultValue) {\n this.__editor.update(() => {\n $insertNodes([$createTextNode(defaultValue)]);\n });\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.registerTextContentListener(text => {\n onContentChange?.(text);\n onCountChanged?.(text.length);\n });\n }\n\n deactivateContentCallbacks() {\n this.__contentChangeCleanup?.();\n this.__contentChangeCleanup = 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.__enterHandlerCleanup?.();\n this.__enterHandlerCleanup = undefined;\n }\n}\n"],"names":["$createTextNode","$getRoot","$getSelection","$insertNodes","$isRangeSelection","COMMAND_PRIORITY_CRITICAL","INSERT_PARAGRAPH_COMMAND","KEY_ENTER_COMMAND","BasicFunctionalityBase","__enterHandler","event","selection","preventDefault","shiftKey","__editor","dispatchCommand","undefined","insertDefaultValue","defaultValue","update","activateContentCallbacks","onContentChange","onCountChanged","deactivateContentCallbacks","__contentChangeCleanup","registerTextContentListener","text","length","activateTrimWhitespace","deactivateTrimWhitespace","__trimWhitespaceCleanup","trim","getAllTextNodes","forEach","node","remove","tag","setIsDisabled","isDisabled","setEditable","cleanup","__enterHandlerCleanup","constructor","editor","registerCommand"],"mappings":";AACA,SACEA,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,YAAY,EACZC,iBAAiB,EACjBC,yBAAyB,EACzBC,wBAAwB,EACxBC,iBAAiB,QACZ,gCAAgC;AAYvC,OAAO,MAAMC;IAMHC,eAAeC,KAAoB,EAAE;QAC3C,MAAMC,YAAYT;QAClB,IAAI,CAACE,kBAAkBO,YAAY;YACjC,OAAO;QACT;QAEA,IAAID,UAAU,MAAM;YAClB,OAAO;QACT;QAEAA,MAAME,cAAc;QAEpB,IAAIF,MAAMG,QAAQ,EAAE;YAClB,OAAO,IAAI,CAACC,QAAQ,CAACC,eAAe,CAACT,0BAA0BU;QACjE;QAEA,kDAAkD;QAClD,OAAO;IACT;IAYAC,mBAAmBC,YAAoB,EAAE;QACvC,IAAIA,cAAc;YAChB,IAAI,CAACJ,QAAQ,CAACK,MAAM,CAAC;gBACnBhB,aAAa;oBAACH,gBAAgBkB;iBAAc;YAC9C;QACF;IACF;IAEAE,yBACEC,eAAuD,EACvDC,cAAsD,EACtD;QACA,IAAI,CAACC,0BAA0B;QAC/B,IAAI,CAACC,sBAAsB,GAAG,IAAI,CAACV,QAAQ,CAACW,2BAA2B,CAACC,CAAAA;YACtEL,4BAAAA,sCAAAA,gBAAkBK;YAClBJ,2BAAAA,qCAAAA,eAAiBI,KAAKC,MAAM;QAC9B;IACF;IAEAJ,6BAA6B;YAC3B,8BAAA;SAAA,+BAAA,CAAA,QAAA,IAAI,EAACC,sBAAsB,cAA3B,mDAAA,kCAAA;QACA,IAAI,CAACA,sBAAsB,GAAGR;IAChC;IAEAY,yBAAyB;QACvB,IAAI,CAACC,wBAAwB;QAC7B,IAAI,CAACC,uBAAuB,GAAG,IAAI,CAAChB,QAAQ,CAACW,2BAA2B,CAACC,CAAAA;YACvE,IAAIA,KAAKK,IAAI,OAAO,IAAI;gBACtB,IAAI,CAACjB,QAAQ,CAACK,MAAM,CAClB;oBACElB,WACG+B,eAAe,GACfC,OAAO,CAACC,CAAAA;wBACPA,KAAKC,MAAM;oBACb;gBACJ,GACA,kCAAkC;gBAClC;oBAAEC,KAAK;gBAAW;YAEtB;QACF;IACF;IAEAP,2BAA2B;YACzB,+BAAA;SAAA,gCAAA,CAAA,QAAA,IAAI,EAACC,uBAAuB,cAA5B,oDAAA,mCAAA;QACA,IAAI,CAACA,uBAAuB,GAAGd;IACjC;IAEAqB,cAAcC,UAAmB,EAAE;QACjC,IAAI,CAACxB,QAAQ,CAACyB,WAAW,CAAC,CAACD;IAC7B;IAEAE,UAAU;YAGR,6BAAA;QAFA,IAAI,CAACjB,0BAA0B;QAC/B,IAAI,CAACM,wBAAwB;SAC7B,8BAAA,CAAA,QAAA,IAAI,EAACY,qBAAqB,cAA1B,kDAAA,iCAAA;QACA,IAAI,CAACA,qBAAqB,GAAGzB;IAC/B;IAnEA0B,YAAYC,MAAqB,CAAE;QAzBnC,uBAAQ7B,YAAR,KAAA;QACA,uBAAQU,0BAAR,KAAA;QACA,uBAAQM,2BAAR,KAAA;QACA,uBAAQW,yBAAR,KAAA;QAuBE,IAAI,CAAC3B,QAAQ,GAAG6B;QAEhB,IAAI,CAACF,qBAAqB,GAAG,IAAI,CAAC3B,QAAQ,CAAC8B,eAAe,CACxDrC,mBACA,IAAI,CAACE,cAAc,
|
|
1
|
+
{"version":3,"sources":["BasicFunctionality.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport {\n $createTextNode,\n $getRoot,\n $getSelection,\n $insertNodes,\n $isRangeSelection,\n COMMAND_PRIORITY_CRITICAL,\n INSERT_PARAGRAPH_COMMAND,\n KEY_ENTER_COMMAND,\n} from '@fluentui-copilot/text-editor';\n\nexport interface IBasicFunctionalityBase {\n insertDefaultValue: (defaultValue: string) => void;\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 cleanup(): void;\n}\n\nexport class BasicFunctionalityBase implements IBasicFunctionalityBase {\n private __editor: LexicalEditor;\n private __contentChangeCleanup?: () => void;\n private __trimWhitespaceCleanup?: () => void;\n private __enterHandlerCleanup?: () => 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) {\n this.__editor = editor;\n\n this.__enterHandlerCleanup = this.__editor.registerCommand(\n KEY_ENTER_COMMAND,\n this.__enterHandler.bind(this),\n COMMAND_PRIORITY_CRITICAL,\n );\n }\n\n insertDefaultValue(defaultValue: string) {\n if (defaultValue) {\n this.__editor.update(() => {\n $insertNodes([$createTextNode(defaultValue)]);\n });\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.registerTextContentListener(text => {\n onContentChange?.(text);\n onCountChanged?.(text.length);\n });\n }\n\n deactivateContentCallbacks() {\n this.__contentChangeCleanup?.();\n this.__contentChangeCleanup = 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.__enterHandlerCleanup?.();\n this.__enterHandlerCleanup = undefined;\n }\n}\n"],"names":["$createTextNode","$getRoot","$getSelection","$insertNodes","$isRangeSelection","COMMAND_PRIORITY_CRITICAL","INSERT_PARAGRAPH_COMMAND","KEY_ENTER_COMMAND","BasicFunctionalityBase","__enterHandler","event","selection","preventDefault","shiftKey","__editor","dispatchCommand","undefined","insertDefaultValue","defaultValue","update","activateContentCallbacks","onContentChange","onCountChanged","deactivateContentCallbacks","__contentChangeCleanup","registerTextContentListener","text","length","activateTrimWhitespace","deactivateTrimWhitespace","__trimWhitespaceCleanup","trim","getAllTextNodes","forEach","node","remove","tag","setIsDisabled","isDisabled","setEditable","cleanup","__enterHandlerCleanup","constructor","editor","registerCommand","bind"],"mappings":";AACA,SACEA,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,YAAY,EACZC,iBAAiB,EACjBC,yBAAyB,EACzBC,wBAAwB,EACxBC,iBAAiB,QACZ,gCAAgC;AAYvC,OAAO,MAAMC;IAMHC,eAAeC,KAAoB,EAAE;QAC3C,MAAMC,YAAYT;QAClB,IAAI,CAACE,kBAAkBO,YAAY;YACjC,OAAO;QACT;QAEA,IAAID,UAAU,MAAM;YAClB,OAAO;QACT;QAEAA,MAAME,cAAc;QAEpB,IAAIF,MAAMG,QAAQ,EAAE;YAClB,OAAO,IAAI,CAACC,QAAQ,CAACC,eAAe,CAACT,0BAA0BU;QACjE;QAEA,kDAAkD;QAClD,OAAO;IACT;IAYAC,mBAAmBC,YAAoB,EAAE;QACvC,IAAIA,cAAc;YAChB,IAAI,CAACJ,QAAQ,CAACK,MAAM,CAA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BnC,uBAAQ7B,YAAR,KAAA;QACA,uBAAQU,0BAAR,KAAA;QACA,uBAAQM,2BAAR,KAAA;QACA,uBAAQW,yBAAR,KAAA;QAuBE,IAAI,CAAC3B,QAAQ,GAAG6B;QAEhB,IAAI,CAACF,qBAAqB,GAAG,IAAI,CAAC3B,QAAQ,CAAC8B,eAAe,CACxDrC,mBACA,IAAI,CAACE,cAAc,CAACoC,IAAI,CAAC,IAAI,GAC7BxC;IAEJ;AA4DF"}
|
|
@@ -33,6 +33,7 @@ export class GhostTextPluginBase {
|
|
|
33
33
|
this.__allowCompletion = allowCompletion;
|
|
34
34
|
let ghostTextNodeKey = null;
|
|
35
35
|
let lastText = undefined;
|
|
36
|
+
let justRemovedGhostText = false;
|
|
36
37
|
function $clearGhostText() {
|
|
37
38
|
const ghostTextNode = ghostTextNodeKey !== null ? $getNodeByKey(ghostTextNodeKey) : null;
|
|
38
39
|
ghostTextNodeKey = null;
|
|
@@ -57,6 +58,7 @@ export class GhostTextPluginBase {
|
|
|
57
58
|
$clearGhostText();
|
|
58
59
|
const selection = $getSelection();
|
|
59
60
|
if (!text || !selection) {
|
|
61
|
+
justRemovedGhostText = true;
|
|
60
62
|
return;
|
|
61
63
|
}
|
|
62
64
|
const selectionCopy = selection.clone();
|
|
@@ -74,6 +76,11 @@ export class GhostTextPluginBase {
|
|
|
74
76
|
editorState,
|
|
75
77
|
prevEditorState
|
|
76
78
|
} = props;
|
|
79
|
+
// If this update was caused by deleting the previous ghost text, don't create a new one until a subsequent update
|
|
80
|
+
if (justRemovedGhostText) {
|
|
81
|
+
justRemovedGhostText = false;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
77
84
|
editorState.read(() => {
|
|
78
85
|
const promise = this.__$getGhostText(editor, editorState, prevEditorState);
|
|
79
86
|
promise.then(handleGhostTextResponse).catch(e => console.error(e));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["GhostText.base.ts"],"sourcesContent":["import type { EditorState, Klass, LexicalEditor, LexicalNode, UpdateListener } from '@fluentui-copilot/text-editor';\nimport {\n $createTextNode,\n $getNodeByKey,\n $getSelection,\n $setSelection,\n COMMAND_PRIORITY_LOW,\n KEY_TAB_COMMAND,\n mergeRegister,\n} from '@fluentui-copilot/text-editor';\n\nexport type GetGhostTextFunction = (\n editor: LexicalEditor,\n editorState: EditorState,\n prevEditorState: EditorState,\n) => Promise<string | undefined>;\n\nexport interface IGhostTextNode<ComponentPropsType> extends LexicalNode {\n __content: string;\n __id: string;\n __allowCommitting?: boolean;\n __componentProps?: ComponentPropsType;\n __exposeText?: boolean;\n}\n\nexport class GhostTextPluginBase<ComponentPropsType> {\n private __id: string;\n private __$getGhostText: GetGhostTextFunction;\n private __componentProps?: ComponentPropsType;\n private __exposeText?: boolean;\n private __allowCompletion?: boolean;\n\n private __cleanup?: () => void;\n\n cleanup() {\n this.__cleanup?.();\n }\n\n constructor(\n editor: LexicalEditor,\n id: string,\n $getGhostText: GetGhostTextFunction,\n nodeClass: Klass<IGhostTextNode<ComponentPropsType>>,\n createNode: (\n id: string,\n content: string,\n exposeText?: boolean,\n componentProps?: ComponentPropsType,\n ) => IGhostTextNode<ComponentPropsType>,\n componentProps?: ComponentPropsType,\n // Whether or not the ghost text should count as text inside the input for submitting and character count\n exposeText?: boolean,\n allowCompletion?: boolean,\n ) {\n this.__id = id;\n this.__$getGhostText = $getGhostText;\n this.__componentProps = componentProps;\n this.__exposeText = exposeText;\n this.__allowCompletion = allowCompletion;\n\n let ghostTextNodeKey: string | null = null;\n let lastText: string | undefined = undefined;\n\n function $clearGhostText() {\n const ghostTextNode = ghostTextNodeKey !== null ? $getNodeByKey(ghostTextNodeKey) : null;\n ghostTextNodeKey = null;\n lastText = undefined;\n if (ghostTextNode && ghostTextNode.isAttached()) {\n ghostTextNode.remove();\n }\n }\n function handleGhostTextNodeTransform(node: IGhostTextNode<ComponentPropsType>) {\n const key = node.getKey();\n\n if (node.__id === id && key !== ghostTextNodeKey) {\n // Only one ghost text\n node.remove();\n $clearGhostText();\n }\n }\n\n const handleGhostTextResponse = (text?: string) => {\n if (text === lastText) {\n return;\n }\n\n editor.update(\n () => {\n $clearGhostText();\n\n const selection = $getSelection();\n if (!text || !selection) {\n return;\n }\n\n const selectionCopy = selection.clone();\n\n const node = createNode(this.__id, text, this.__exposeText, this.__componentProps);\n ghostTextNodeKey = node.getKey();\n lastText = text;\n\n selection.insertNodes([node]);\n $setSelection(selectionCopy);\n },\n { tag: 'historic' },\n );\n };\n\n const handleUpdate: UpdateListener = props => {\n const { editorState, prevEditorState } = props;\n editorState.read(() => {\n const promise = this.__$getGhostText(editor, editorState, prevEditorState);\n promise.then(handleGhostTextResponse).catch(e => console.error(e));\n });\n };\n\n function unmountGhostText() {\n if (ghostTextNodeKey) {\n editor.update(\n () => {\n $clearGhostText();\n },\n { tag: 'historic' },\n );\n }\n }\n\n function $handleTabCommand(e: KeyboardEvent) {\n if (ghostTextNodeKey === null || lastText === null) {\n return false;\n }\n\n const ghostTextNode = $getNodeByKey(ghostTextNodeKey);\n if (!ghostTextNode) {\n return false;\n }\n\n e.preventDefault();\n\n const textNode = $createTextNode(lastText);\n ghostTextNode.replace(textNode);\n textNode.selectEnd();\n $clearGhostText();\n return true;\n }\n\n this.__cleanup = mergeRegister(\n editor.registerNodeTransform(nodeClass, handleGhostTextNodeTransform),\n editor.registerUpdateListener(handleUpdate),\n this.__allowCompletion ? editor.registerCommand(KEY_TAB_COMMAND, $handleTabCommand, COMMAND_PRIORITY_LOW) : noop,\n unmountGhostText,\n );\n }\n\n setExposeText(exposeText?: boolean) {\n this.__exposeText = exposeText;\n }\n\n setComponentProps(componentProps?: ComponentPropsType) {\n this.__componentProps = componentProps;\n }\n\n setGetGhostText($getGhostText: GetGhostTextFunction) {\n this.__$getGhostText = $getGhostText;\n }\n\n setAllowCompletion(allowCompletion?: boolean) {\n this.__allowCompletion = allowCompletion;\n }\n}\nfunction noop(): void {\n return;\n}\n"],"names":["$createTextNode","$getNodeByKey","$getSelection","$setSelection","COMMAND_PRIORITY_LOW","KEY_TAB_COMMAND","mergeRegister","GhostTextPluginBase","cleanup","__cleanup","setExposeText","exposeText","__exposeText","setComponentProps","componentProps","__componentProps","setGetGhostText","$getGhostText","__$getGhostText","setAllowCompletion","allowCompletion","__allowCompletion","constructor","editor","id","nodeClass","createNode","__id","ghostTextNodeKey","lastText","undefined","$clearGhostText","ghostTextNode","isAttached","remove","handleGhostTextNodeTransform","node","key","getKey","handleGhostTextResponse","text","update","selection","selectionCopy","clone","insertNodes","tag","handleUpdate","props","editorState","prevEditorState","read","promise","then","catch","e","console","error","unmountGhostText","$handleTabCommand","preventDefault","textNode","replace","selectEnd","registerNodeTransform","registerUpdateListener","registerCommand","noop"],"mappings":";AACA,SACEA,eAAe,EACfC,aAAa,EACbC,aAAa,EACbC,aAAa,EACbC,oBAAoB,EACpBC,eAAe,EACfC,aAAa,QACR,gCAAgC;AAgBvC,OAAO,MAAMC;IASXC,UAAU;YACR,iBAAA;SAAA,kBAAA,CAAA,QAAA,IAAI,EAACC,SAAS,cAAd,sCAAA,qBAAA;IACF;
|
|
1
|
+
{"version":3,"sources":["GhostText.base.ts"],"sourcesContent":["import type { EditorState, Klass, LexicalEditor, LexicalNode, UpdateListener } from '@fluentui-copilot/text-editor';\nimport {\n $createTextNode,\n $getNodeByKey,\n $getSelection,\n $setSelection,\n COMMAND_PRIORITY_LOW,\n KEY_TAB_COMMAND,\n mergeRegister,\n} from '@fluentui-copilot/text-editor';\n\nexport type GetGhostTextFunction = (\n editor: LexicalEditor,\n editorState: EditorState,\n prevEditorState: EditorState,\n) => Promise<string | undefined>;\n\nexport interface IGhostTextNode<ComponentPropsType> extends LexicalNode {\n __content: string;\n __id: string;\n __allowCommitting?: boolean;\n __componentProps?: ComponentPropsType;\n __exposeText?: boolean;\n}\n\nexport class GhostTextPluginBase<ComponentPropsType> {\n private __id: string;\n private __$getGhostText: GetGhostTextFunction;\n private __componentProps?: ComponentPropsType;\n private __exposeText?: boolean;\n private __allowCompletion?: boolean;\n\n private __cleanup?: () => void;\n\n cleanup() {\n this.__cleanup?.();\n }\n\n constructor(\n editor: LexicalEditor,\n id: string,\n $getGhostText: GetGhostTextFunction,\n nodeClass: Klass<IGhostTextNode<ComponentPropsType>>,\n createNode: (\n id: string,\n content: string,\n exposeText?: boolean,\n componentProps?: ComponentPropsType,\n ) => IGhostTextNode<ComponentPropsType>,\n componentProps?: ComponentPropsType,\n // Whether or not the ghost text should count as text inside the input for submitting and character count\n exposeText?: boolean,\n allowCompletion?: boolean,\n ) {\n this.__id = id;\n this.__$getGhostText = $getGhostText;\n this.__componentProps = componentProps;\n this.__exposeText = exposeText;\n this.__allowCompletion = allowCompletion;\n\n let ghostTextNodeKey: string | null = null;\n let lastText: string | undefined = undefined;\n let justRemovedGhostText = false;\n\n function $clearGhostText() {\n const ghostTextNode = ghostTextNodeKey !== null ? $getNodeByKey(ghostTextNodeKey) : null;\n ghostTextNodeKey = null;\n lastText = undefined;\n if (ghostTextNode && ghostTextNode.isAttached()) {\n ghostTextNode.remove();\n }\n }\n function handleGhostTextNodeTransform(node: IGhostTextNode<ComponentPropsType>) {\n const key = node.getKey();\n\n if (node.__id === id && key !== ghostTextNodeKey) {\n // Only one ghost text\n node.remove();\n $clearGhostText();\n }\n }\n\n const handleGhostTextResponse = (text?: string) => {\n if (text === lastText) {\n return;\n }\n\n editor.update(\n () => {\n $clearGhostText();\n\n const selection = $getSelection();\n if (!text || !selection) {\n justRemovedGhostText = true;\n return;\n }\n\n const selectionCopy = selection.clone();\n\n const node = createNode(this.__id, text, this.__exposeText, this.__componentProps);\n ghostTextNodeKey = node.getKey();\n lastText = text;\n\n selection.insertNodes([node]);\n $setSelection(selectionCopy);\n },\n { tag: 'historic' },\n );\n };\n\n const handleUpdate: UpdateListener = props => {\n const { editorState, prevEditorState } = props;\n // If this update was caused by deleting the previous ghost text, don't create a new one until a subsequent update\n if (justRemovedGhostText) {\n justRemovedGhostText = false;\n return;\n }\n editorState.read(() => {\n const promise = this.__$getGhostText(editor, editorState, prevEditorState);\n promise.then(handleGhostTextResponse).catch(e => console.error(e));\n });\n };\n\n function unmountGhostText() {\n if (ghostTextNodeKey) {\n editor.update(\n () => {\n $clearGhostText();\n },\n { tag: 'historic' },\n );\n }\n }\n\n function $handleTabCommand(e: KeyboardEvent) {\n if (ghostTextNodeKey === null || lastText === null) {\n return false;\n }\n\n const ghostTextNode = $getNodeByKey(ghostTextNodeKey);\n if (!ghostTextNode) {\n return false;\n }\n\n e.preventDefault();\n\n const textNode = $createTextNode(lastText);\n ghostTextNode.replace(textNode);\n textNode.selectEnd();\n $clearGhostText();\n return true;\n }\n\n this.__cleanup = mergeRegister(\n editor.registerNodeTransform(nodeClass, handleGhostTextNodeTransform),\n editor.registerUpdateListener(handleUpdate),\n this.__allowCompletion ? editor.registerCommand(KEY_TAB_COMMAND, $handleTabCommand, COMMAND_PRIORITY_LOW) : noop,\n unmountGhostText,\n );\n }\n\n setExposeText(exposeText?: boolean) {\n this.__exposeText = exposeText;\n }\n\n setComponentProps(componentProps?: ComponentPropsType) {\n this.__componentProps = componentProps;\n }\n\n setGetGhostText($getGhostText: GetGhostTextFunction) {\n this.__$getGhostText = $getGhostText;\n }\n\n setAllowCompletion(allowCompletion?: boolean) {\n this.__allowCompletion = allowCompletion;\n }\n}\nfunction noop(): void {\n return;\n}\n"],"names":["$createTextNode","$getNodeByKey","$getSelection","$setSelection","COMMAND_PRIORITY_LOW","KEY_TAB_COMMAND","mergeRegister","GhostTextPluginBase","cleanup","__cleanup","setExposeText","exposeText","__exposeText","setComponentProps","componentProps","__componentProps","setGetGhostText","$getGhostText","__$getGhostText","setAllowCompletion","allowCompletion","__allowCompletion","constructor","editor","id","nodeClass","createNode","__id","ghostTextNodeKey","lastText","undefined","justRemovedGhostText","$clearGhostText","ghostTextNode","isAttached","remove","handleGhostTextNodeTransform","node","key","getKey","handleGhostTextResponse","text","update","selection","selectionCopy","clone","insertNodes","tag","handleUpdate","props","editorState","prevEditorState","read","promise","then","catch","e","console","error","unmountGhostText","$handleTabCommand","preventDefault","textNode","replace","selectEnd","registerNodeTransform","registerUpdateListener","registerCommand","noop"],"mappings":";AACA,SACEA,eAAe,EACfC,aAAa,EACbC,aAAa,EACbC,aAAa,EACbC,oBAAoB,EACpBC,eAAe,EACfC,aAAa,QACR,gCAAgC;AAgBvC,OAAO,MAAMC;IASXC,UAAU;YACR,iBAAA;SAAA,kBAAA,CAAA,QAAA,IAAI,EAACC,SAAS,cAAd,sCAAA,qBAAA;IACF;IA6HAC,cAAcC,UAAoB,EAAE;QAClC,IAAI,CAACC,YAAY,GAAGD;IACtB;IAEAE,kBAAkBC,cAAmC,EAAE;QACrD,IAAI,CAACC,gBAAgB,GAAGD;IAC1B;IAEAE,gBAAgBC,aAAmC,EAAE;QACnD,IAAI,CAACC,eAAe,GAAGD;IACzB;IAEAE,mBAAmBC,eAAyB,EAAE;QAC5C,IAAI,CAACC,iBAAiB,GAAGD;IAC3B;IAzIAE,YACEC,MAAqB,EACrBC,EAAU,EACVP,aAAmC,EACnCQ,SAAoD,EACpDC,UAKuC,EACvCZ,cAAmC,EACnC,yGAAyG;IACzGH,UAAoB,EACpBS,eAAyB,CACzB;QA3BF,uBAAQO,QAAR,KAAA;QACA,uBAAQT,mBAAR,KAAA;QACA,uBAAQH,oBAAR,KAAA;QACA,uBAAQH,gBAAR,KAAA;QACA,uBAAQS,qBAAR,KAAA;QAEA,uBAAQZ,aAAR,KAAA;QAsBE,IAAI,CAACkB,IAAI,GAAGH;QACZ,IAAI,CAACN,eAAe,GAAGD;QACvB,IAAI,CAACF,gBAAgB,GAAGD;QACxB,IAAI,CAACF,YAAY,GAAGD;QACpB,IAAI,CAACU,iBAAiB,GAAGD;QAEzB,IAAIQ,mBAAkC;QACtC,IAAIC,WAA+BC;QACnC,IAAIC,uBAAuB;QAE3B,SAASC;YACP,MAAMC,gBAAgBL,qBAAqB,OAAO3B,cAAc2B,oBAAoB;YACpFA,mBAAmB;YACnBC,WA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AqB,QAAQC,aAAa,MAAM;gBAClD,OAAO;YACT;YAEA,MAAMI,gBAAgBhC,cAAc2B;YACpC,IAAI,CAACK,eAAe;gBAClB,OAAO;YACT;YAEAuB,EAAEK,cAAc;YAEhB,MAAMC,WAAW9D,gBAAgB6B;YACjCI,cAAc8B,OAAO,CAACD;YACtBA,SAASE,SAAS;YAClBhC;YACA,OAAO;QACT;QAEA,IAAI,CAACvB,SAAS,GAAGH,cACfiB,OAAO0C,qBAAqB,CAACxC,WAAWW,+BACxCb,OAAO2C,sBAAsB,CAAClB,eAC9B,IAAI,CAAC3B,iBAAiB,GAAGE,OAAO4C,eAAe,CAAC9D,iBAAiBuD,mBAAmBxD,wBAAwBgE,MAC5GT;IAEJ;AAiBF;AACA,SAASS;IACP;AACF"}
|
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
import { $createParagraphNode, $createTextNode, $getRoot, $getSelection } from '@fluentui-copilot/text-editor';
|
|
2
|
+
import { $createParagraphNode, $createRangeSelection, $createTextNode, $getLeafNodes, $getRoot, $getSelection, $isTextNode, $normalizeSelection__EXPERIMENTAL, $setSelection } from '@fluentui-copilot/text-editor';
|
|
3
3
|
export class ImperativeControlBase {
|
|
4
|
+
moveCursor(location) {
|
|
5
|
+
this.__editor.update(() => {
|
|
6
|
+
const children = $getLeafNodes($getRoot());
|
|
7
|
+
let baseOffset = 0;
|
|
8
|
+
let currentNode = children.shift();
|
|
9
|
+
while (baseOffset < location && currentNode) {
|
|
10
|
+
const nodeLength = $isTextNode(currentNode) && !currentNode.isToken() ? currentNode.getTextContent().length : 1;
|
|
11
|
+
if (baseOffset + nodeLength >= location) {
|
|
12
|
+
const elementType = $isTextNode(currentNode) ? 'text' : 'element';
|
|
13
|
+
const localOffset = location - baseOffset;
|
|
14
|
+
const nodeKey = currentNode.getKey();
|
|
15
|
+
const selection = $createRangeSelection();
|
|
16
|
+
selection.anchor.set(nodeKey, localOffset, elementType);
|
|
17
|
+
selection.focus.set(nodeKey, localOffset, elementType);
|
|
18
|
+
$setSelection($normalizeSelection__EXPERIMENTAL(selection));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
baseOffset += nodeLength;
|
|
22
|
+
currentNode = children.shift();
|
|
23
|
+
}
|
|
24
|
+
if (location > baseOffset) {
|
|
25
|
+
$getRoot().selectEnd();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
4
29
|
setInputText(inputText) {
|
|
5
30
|
this.__editor.update(() => {
|
|
6
31
|
const root = $getRoot();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ImperativeControl.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport {
|
|
1
|
+
{"version":3,"sources":["ImperativeControl.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport {\n $createParagraphNode,\n $createRangeSelection,\n $createTextNode,\n $getLeafNodes,\n $getRoot,\n $getSelection,\n $isTextNode,\n $normalizeSelection__EXPERIMENTAL,\n $setSelection,\n} from '@fluentui-copilot/text-editor';\n\nexport interface IImperativeControlBase {\n setInputText: (inputText: string) => void;\n appendText: (text: string) => void;\n prependText: (text: string) => void;\n insertTextAtCursor: (text: string) => void;\n getInputText: () => string;\n scrollToBottom: () => void;\n moveCursor: (location: number) => void;\n}\n\nexport class ImperativeControlBase implements IImperativeControlBase {\n private __editor: LexicalEditor;\n\n constructor(editor: LexicalEditor) {\n this.__editor = editor;\n }\n\n moveCursor(location: number): void {\n this.__editor.update(() => {\n const children = $getLeafNodes($getRoot());\n\n let baseOffset = 0;\n let currentNode = children.shift();\n while (baseOffset < location && currentNode) {\n const nodeLength =\n $isTextNode(currentNode) && !currentNode.isToken()\n ? currentNode.getTextContent().length\n : // Token text nodes and non-text nodes are considered to be a single entry in the input\n 1;\n\n if (baseOffset + nodeLength >= location) {\n const elementType = $isTextNode(currentNode) ? 'text' : 'element';\n const localOffset = location - baseOffset;\n const nodeKey = currentNode.getKey();\n\n const selection = $createRangeSelection();\n selection.anchor.set(nodeKey, localOffset, elementType);\n selection.focus.set(nodeKey, localOffset, elementType);\n\n $setSelection($normalizeSelection__EXPERIMENTAL(selection));\n return;\n }\n\n baseOffset += nodeLength;\n currentNode = children.shift();\n }\n\n if (location > baseOffset) {\n $getRoot().selectEnd();\n }\n });\n }\n setInputText(inputText: string) {\n this.__editor.update(() => {\n const root = $getRoot();\n root.clear();\n if (inputText !== '') {\n const newParagraph = $createParagraphNode();\n const newText = $createTextNode(inputText);\n\n newParagraph.append(newText);\n root.append(newParagraph);\n root.selectEnd();\n }\n });\n }\n appendText(text: string) {\n this.__editor.update(() => {\n $getRoot().selectEnd().insertText(text);\n });\n }\n prependText(text: string) {\n this.__editor.update(() => {\n $getRoot().selectStart().insertText(text);\n });\n }\n insertTextAtCursor(text: string) {\n this.__editor.update(() => {\n $getSelection()?.insertText(text);\n });\n }\n getInputText() {\n return this.__editor.getEditorState().read(() => {\n return $getRoot().getTextContent();\n });\n }\n scrollToBottom() {\n this.__editor.getRootElement()?.scrollIntoView({ behavior: 'smooth', block: 'end' });\n return;\n }\n}\n"],"names":["$createParagraphNode","$createRangeSelection","$createTextNode","$getLeafNodes","$getRoot","$getSelection","$isTextNode","$normalizeSelection__EXPERIMENTAL","$setSelection","ImperativeControlBase","moveCursor","location","__editor","update","children","baseOffset","currentNode","shift","nodeLength","isToken","getTextContent","length","elementType","localOffset","nodeKey","getKey","selection","anchor","set","focus","selectEnd","setInputText","inputText","root","clear","newParagraph","newText","append","appendText","text","insertText","prependText","selectStart","insertTextAtCursor","getInputText","getEditorState","read","scrollToBottom","getRootElement","scrollIntoView","behavior","block","constructor","editor"],"mappings":";AACA,SACEA,oBAAoB,EACpBC,qBAAqB,EACrBC,eAAe,EACfC,aAAa,EACbC,QAAQ,EACRC,aAAa,EACbC,WAAW,EACXC,iCAAiC,EACjCC,aAAa,QACR,gCAAgC;AAY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,WAAW,GAAGF,UAAU,CAACD;QACtC;IACF;IACAI,mBAAmBJ,IAAY,EAAE;QAC/B,IAAI,CAAC3B,QAAQ,CAACC,MAAM,CAAC;gBACnBR;aAAAA,iBAAAA,6BAAAA,qCAAAA,eAAiBmC,UAAU,CAACD;QAC9B;IACF;IACAK,eAAe;QACb,OAAO,IAAI,CAAChC,QAAQ,CAACiC,cAAc,GAAGC,IAAI,CAAC;YACzC,OAAO1C,WAAWgB,cAAc;QAClC;IACF;IACA2B,iBAAiB;YACf;SAAA,gCAAA,IAAI,CAACnC,QAAQ,CAACoC,cAAc,gBAA5B,oDAAA,8BAAgCC,cAAc,CAAC;YAAEC,UAAU;YAAUC,OAAO;QAAM;QAClF;IACF;IA5EAC,YAAYC,MAAqB,CAAE;QAFnC,uBAAQzC,YAAR,KAAA;QAGE,IAAI,CAACA,QAAQ,GAAGyC;IAClB;AA2EF"}
|
|
@@ -83,6 +83,6 @@ class BasicFunctionalityBase {
|
|
|
83
83
|
(0, _define_property._)(this, "__trimWhitespaceCleanup", void 0);
|
|
84
84
|
(0, _define_property._)(this, "__enterHandlerCleanup", void 0);
|
|
85
85
|
this.__editor = editor;
|
|
86
|
-
this.__enterHandlerCleanup = this.__editor.registerCommand(_texteditor.KEY_ENTER_COMMAND, this.__enterHandler, _texteditor.COMMAND_PRIORITY_CRITICAL);
|
|
86
|
+
this.__enterHandlerCleanup = this.__editor.registerCommand(_texteditor.KEY_ENTER_COMMAND, this.__enterHandler.bind(this), _texteditor.COMMAND_PRIORITY_CRITICAL);
|
|
87
87
|
}
|
|
88
88
|
} //# sourceMappingURL=BasicFunctionality.base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["BasicFunctionality.base.js"],"sourcesContent":["import { _ as _define_property } from \"@swc/helpers/_/_define_property\";\nimport { $createTextNode, $getRoot, $getSelection, $insertNodes, $isRangeSelection, COMMAND_PRIORITY_CRITICAL, INSERT_PARAGRAPH_COMMAND, KEY_ENTER_COMMAND } from '@fluentui-copilot/text-editor';\nexport class BasicFunctionalityBase {\n __enterHandler(event) {\n const selection = $getSelection();\n if (!$isRangeSelection(selection)) {\n return false;\n }\n if (event === null) {\n return false;\n }\n event.preventDefault();\n if (event.shiftKey) {\n return this.__editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);\n }\n // Mark event handled to override default behavior\n return true;\n }\n insertDefaultValue(defaultValue) {\n if (defaultValue) {\n this.__editor.update(() => {\n $insertNodes([$createTextNode(defaultValue)]);\n });\n }\n }\n activateContentCallbacks(onContentChange, onCountChanged) {\n this.deactivateContentCallbacks();\n this.__contentChangeCleanup = this.__editor.registerTextContentListener(text => {\n onContentChange === null || onContentChange === void 0 ? void 0 : onContentChange(text);\n onCountChanged === null || onCountChanged === void 0 ? void 0 : onCountChanged(text.length);\n });\n }\n deactivateContentCallbacks() {\n var _this___contentChangeCleanup, _this;\n (_this___contentChangeCleanup = (_this = this).__contentChangeCleanup) === null || _this___contentChangeCleanup === void 0 ? void 0 : _this___contentChangeCleanup.call(_this);\n this.__contentChangeCleanup = undefined;\n }\n activateTrimWhitespace() {\n this.deactivateTrimWhitespace();\n this.__trimWhitespaceCleanup = this.__editor.registerTextContentListener(text => {\n if (text.trim() === '') {\n this.__editor.update(() => {\n $getRoot().getAllTextNodes().forEach(node => {\n node.remove();\n });\n },\n // Don't allow undoing this action\n {\n tag: 'historic'\n });\n }\n });\n }\n deactivateTrimWhitespace() {\n var _this___trimWhitespaceCleanup, _this;\n (_this___trimWhitespaceCleanup = (_this = this).__trimWhitespaceCleanup) === null || _this___trimWhitespaceCleanup === void 0 ? void 0 : _this___trimWhitespaceCleanup.call(_this);\n this.__trimWhitespaceCleanup = undefined;\n }\n setIsDisabled(isDisabled) {\n this.__editor.setEditable(!isDisabled);\n }\n cleanup() {\n var _this___enterHandlerCleanup, _this;\n this.deactivateContentCallbacks();\n this.deactivateTrimWhitespace();\n (_this___enterHandlerCleanup = (_this = this).__enterHandlerCleanup) === null || _this___enterHandlerCleanup === void 0 ? void 0 : _this___enterHandlerCleanup.call(_this);\n this.__enterHandlerCleanup = undefined;\n }\n constructor(editor) {\n _define_property(this, \"__editor\", void 0);\n _define_property(this, \"__contentChangeCleanup\", void 0);\n _define_property(this, \"__trimWhitespaceCleanup\", void 0);\n _define_property(this, \"__enterHandlerCleanup\", void 0);\n this.__editor = editor;\n this.__enterHandlerCleanup = this.__editor.registerCommand(KEY_ENTER_COMMAND, this.__enterHandler, COMMAND_PRIORITY_CRITICAL);\n }\n}\n//# sourceMappingURL=BasicFunctionality.base.js.map"],"names":["BasicFunctionalityBase","__enterHandler","event","selection","$getSelection","$isRangeSelection","preventDefault","shiftKey","__editor","dispatchCommand","INSERT_PARAGRAPH_COMMAND","undefined","insertDefaultValue","defaultValue","update","$insertNodes","$createTextNode","activateContentCallbacks","onContentChange","onCountChanged","deactivateContentCallbacks","__contentChangeCleanup","registerTextContentListener","text","length","_this___contentChangeCleanup","_this","call","activateTrimWhitespace","deactivateTrimWhitespace","__trimWhitespaceCleanup","trim","$getRoot","getAllTextNodes","forEach","node","remove","tag","_this___trimWhitespaceCleanup","setIsDisabled","isDisabled","setEditable","cleanup","_this___enterHandlerCleanup","__enterHandlerCleanup","constructor","editor","_define_property","registerCommand","KEY_ENTER_COMMAND","COMMAND_PRIORITY_CRITICAL"],"mappings":";;;;+BAEaA;;;eAAAA;;;iCAFyB;4BAC4H;AAC3J,MAAMA;IACXC,eAAeC,KAAK,EAAE;QACpB,MAAMC,YAAYC,IAAAA,yBAAa;QAC/B,IAAI,CAACC,IAAAA,6BAAiB,EAACF,YAAY;YACjC,OAAO;QACT;QACA,IAAID,UAAU,MAAM;YAClB,OAAO;QACT;QACAA,MAAMI,cAAc;QACpB,IAAIJ,MAAMK,QAAQ,EAAE;YAClB,OAAO,IAAI,CAACC,QAAQ,CAACC,eAAe,CAACC,oCAAwB,EAAEC;QACjE;QACA,kDAAkD;QAClD,OAAO;IACT;IACAC,mBAAmBC,YAAY,EAAE;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AI,CAACI,uBAAuB,GAAGnB;IACjC;IACA4B,cAAcC,UAAU,EAAE;QACxB,IAAI,CAAChC,QAAQ,CAACiC,WAAW,CAAC,CAACD;IAC7B;IACAE,UAAU;QACR,IAAIC,6BAA6BjB;QACjC,IAAI,CAACN,0BAA0B;QAC/B,IAAI,CAACS,wBAAwB;QAC5Bc,CAAAA,8BAA8B,AAACjB,CAAAA,QAAQ,IAAI,AAAD,EAAGkB,qBAAqB,AAAD,MAAO,QAAQD,gCAAgC,KAAK,IAAI,KAAK,IAAIA,4BAA4BhB,IAAI,CAACD;QACpK,IAAI,CAACkB,qBAAqB,GAAGjC;IAC/B;IACAkC,YAAYC,MAAM,CAAE;QAClBC,IAAAA,kBAAgB,EAAC,IAAI,EAAE,YAAY,KAAK;QACxCA,IAAAA,kBAAgB,EAAC,IAAI,EAAE,0BAA0B,KAAK;QACtDA,IAAAA,kBAAgB,EAAC,IAAI,EAAE,2BAA2B,KAAK;QACvDA,IAAAA,kBAAgB,EAAC,IAAI,EAAE,yBAAyB,KAAK;QACrD,IAAI,CAACvC,QAAQ,GAAGsC;QAChB,IAAI,CAACF,qBAAqB,GAAG,IAAI,CAACpC,QAAQ,CAACwC,eAAe,CAACC,6BAAiB,EAAE,IAAI,CAAChD,cAAc,
|
|
1
|
+
{"version":3,"sources":["BasicFunctionality.base.js"],"sourcesContent":["import { _ as _define_property } from \"@swc/helpers/_/_define_property\";\nimport { $createTextNode, $getRoot, $getSelection, $insertNodes, $isRangeSelection, COMMAND_PRIORITY_CRITICAL, INSERT_PARAGRAPH_COMMAND, KEY_ENTER_COMMAND } from '@fluentui-copilot/text-editor';\nexport class BasicFunctionalityBase {\n __enterHandler(event) {\n const selection = $getSelection();\n if (!$isRangeSelection(selection)) {\n return false;\n }\n if (event === null) {\n return false;\n }\n event.preventDefault();\n if (event.shiftKey) {\n return this.__editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);\n }\n // Mark event handled to override default behavior\n return true;\n }\n insertDefaultValue(defaultValue) {\n if (defaultValue) {\n this.__editor.update(() => {\n $insertNodes([$createTextNode(defaultValue)]);\n });\n }\n }\n activateContentCallbacks(onContentChange, onCountChanged) {\n this.deactivateContentCallbacks();\n this.__contentChangeCleanup = this.__editor.registerTextContentListener(text => {\n onContentChange === null || onContentChange === void 0 ? void 0 : onContentChange(text);\n onCountChanged === null || onCountChanged === void 0 ? void 0 : onCountChanged(text.length);\n });\n }\n deactivateContentCallbacks() {\n var _this___contentChangeCleanup, _this;\n (_this___contentChangeCleanup = (_this = this).__contentChangeCleanup) === null || _this___contentChangeCleanup === void 0 ? void 0 : _this___contentChangeCleanup.call(_this);\n this.__contentChangeCleanup = undefined;\n }\n activateTrimWhitespace() {\n this.deactivateTrimWhitespace();\n this.__trimWhitespaceCleanup = this.__editor.registerTextContentListener(text => {\n if (text.trim() === '') {\n this.__editor.update(() => {\n $getRoot().getAllTextNodes().forEach(node => {\n node.remove();\n });\n },\n // Don't allow undoing this action\n {\n tag: 'historic'\n });\n }\n });\n }\n deactivateTrimWhitespace() {\n var _this___trimWhitespaceCleanup, _this;\n (_this___trimWhitespaceCleanup = (_this = this).__trimWhitespaceCleanup) === null || _this___trimWhitespaceCleanup === void 0 ? void 0 : _this___trimWhitespaceCleanup.call(_this);\n this.__trimWhitespaceCleanup = undefined;\n }\n setIsDisabled(isDisabled) {\n this.__editor.setEditable(!isDisabled);\n }\n cleanup() {\n var _this___enterHandlerCleanup, _this;\n this.deactivateContentCallbacks();\n this.deactivateTrimWhitespace();\n (_this___enterHandlerCleanup = (_this = this).__enterHandlerCleanup) === null || _this___enterHandlerCleanup === void 0 ? void 0 : _this___enterHandlerCleanup.call(_this);\n this.__enterHandlerCleanup = undefined;\n }\n constructor(editor) {\n _define_property(this, \"__editor\", void 0);\n _define_property(this, \"__contentChangeCleanup\", void 0);\n _define_property(this, \"__trimWhitespaceCleanup\", void 0);\n _define_property(this, \"__enterHandlerCleanup\", void 0);\n this.__editor = editor;\n this.__enterHandlerCleanup = this.__editor.registerCommand(KEY_ENTER_COMMAND, this.__enterHandler.bind(this), COMMAND_PRIORITY_CRITICAL);\n }\n}\n//# sourceMappingURL=BasicFunctionality.base.js.map"],"names":["BasicFunctionalityBase","__enterHandler","event","selection","$getSelection","$isRangeSelection","preventDefault","shiftKey","__editor","dispatchCommand","INSERT_PARAGRAPH_COMMAND","undefined","insertDefaultValue","defaultValue","update","$insertNodes","$createTextNode","activateContentCallbacks","onContentChange","onCountChanged","deactivateContentCallbacks","__contentChangeCleanup","registerTextContentListener","text","length","_this___contentChangeCleanup","_this","call","activateTrimWhitespace","deactivateTrimWhitespace","__trimWhitespaceCleanup","trim","$getRoot","getAllTextNodes","forEach","node","remove","tag","_this___trimWhitespaceCleanup","setIsDisabled","isDisabled","setEditable","cleanup","_this___enterHandlerCleanup","__enterHandlerCleanup","constructor","editor","_define_property","registerCommand","KEY_ENTER_COMMAND","bind","COMMAND_PRIORITY_CRITICAL"],"mappings":";;;;+BAEaA;;;eAAAA;;;iCAFyB;4BAC4H;AAC3J,MAAMA;IACXC,eAAeC,KAAK,EAAE;QACpB,MAAMC,YAAYC,IAAAA,yBAAa;QAC/B,IAAI,CAACC,IAAAA,6BAAiB,EAACF,YAAY;YACjC,OAAO;QACT;QACA,IAAID,UAAU,MAAM;YAClB,OAAO;QACT;QACAA,MAAMI,cAAc;QACpB,IAAIJ,MAAMK,QAAQ,EAAE;YAClB,OAAO,IAAI,CAACC,QAAQ,CAACC,eAAe,CAACC,oCAAwB,EAAEC;QACjE;QACA,kDAAkD;QAClD,OAAO;IACT;IACAC,mBAAmBC,YAAY,EAAE;QAC/B,IAAIA,cAAc;YAChB,IAAI,CAACL,QAAQ,CAACM,MAAM,CAAC;gBACnBC,IAAAA,wBAAY,EAAC;oBAACC,IAAAA,2BAAe,EAACH;iBAAc;YAC9C;QACF;IACF;IACAI,yBAAyBC,eAAe,EAAEC,cAAc,EAAE;QACxD,IAAI,CAACC,0BAA0B;QAC/B,IAAI,CAACC,sBAA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jB,CAAAA,QAAQ,IAAI,AAAD,EAAGkB,qBAAqB,AAAD,MAAO,QAAQD,gCAAgC,KAAK,IAAI,KAAK,IAAIA,4BAA4BhB,IAAI,CAACD;QACpK,IAAI,CAACkB,qBAAqB,GAAGjC;IAC/B;IACAkC,YAAYC,MAAM,CAAE;QAClBC,IAAAA,kBAAgB,EAAC,IAAI,EAAE,YAAY,KAAK;QACxCA,IAAAA,kBAAgB,EAAC,IAAI,EAAE,0BAA0B,KAAK;QACtDA,IAAAA,kBAAgB,EAAC,IAAI,EAAE,2BAA2B,KAAK;QACvDA,IAAAA,kBAAgB,EAAC,IAAI,EAAE,yBAAyB,KAAK;QACrD,IAAI,CAACvC,QAAQ,GAAGsC;QAChB,IAAI,CAACF,qBAAqB,GAAG,IAAI,CAACpC,QAAQ,CAACwC,eAAe,CAACC,6BAAiB,EAAE,IAAI,CAAChD,cAAc,CAACiD,IAAI,CAAC,IAAI,GAAGC,qCAAyB;IACzI;AACF,EACA,mDAAmD"}
|
|
@@ -42,6 +42,7 @@ class GhostTextPluginBase {
|
|
|
42
42
|
this.__allowCompletion = allowCompletion;
|
|
43
43
|
let ghostTextNodeKey = null;
|
|
44
44
|
let lastText = undefined;
|
|
45
|
+
let justRemovedGhostText = false;
|
|
45
46
|
function $clearGhostText() {
|
|
46
47
|
const ghostTextNode = ghostTextNodeKey !== null ? (0, _texteditor.$getNodeByKey)(ghostTextNodeKey) : null;
|
|
47
48
|
ghostTextNodeKey = null;
|
|
@@ -66,6 +67,7 @@ class GhostTextPluginBase {
|
|
|
66
67
|
$clearGhostText();
|
|
67
68
|
const selection = (0, _texteditor.$getSelection)();
|
|
68
69
|
if (!text || !selection) {
|
|
70
|
+
justRemovedGhostText = true;
|
|
69
71
|
return;
|
|
70
72
|
}
|
|
71
73
|
const selectionCopy = selection.clone();
|
|
@@ -82,6 +84,11 @@ class GhostTextPluginBase {
|
|
|
82
84
|
};
|
|
83
85
|
const handleUpdate = (props)=>{
|
|
84
86
|
const { editorState, prevEditorState } = props;
|
|
87
|
+
// If this update was caused by deleting the previous ghost text, don't create a new one until a subsequent update
|
|
88
|
+
if (justRemovedGhostText) {
|
|
89
|
+
justRemovedGhostText = false;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
85
92
|
editorState.read(()=>{
|
|
86
93
|
const promise = this.__$getGhostText(editor, editorState, prevEditorState);
|
|
87
94
|
promise.then(handleGhostTextResponse).catch((e)=>console.error(e));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["GhostText.base.js"],"sourcesContent":["import { _ as _define_property } from \"@swc/helpers/_/_define_property\";\nimport { $createTextNode, $getNodeByKey, $getSelection, $setSelection, COMMAND_PRIORITY_LOW, KEY_TAB_COMMAND, mergeRegister } from '@fluentui-copilot/text-editor';\nexport class GhostTextPluginBase {\n cleanup() {\n var _this___cleanup, _this;\n (_this___cleanup = (_this = this).__cleanup) === null || _this___cleanup === void 0 ? void 0 : _this___cleanup.call(_this);\n }\n setExposeText(exposeText) {\n this.__exposeText = exposeText;\n }\n setComponentProps(componentProps) {\n this.__componentProps = componentProps;\n }\n setGetGhostText($getGhostText) {\n this.__$getGhostText = $getGhostText;\n }\n setAllowCompletion(allowCompletion) {\n this.__allowCompletion = allowCompletion;\n }\n constructor(editor, id, $getGhostText, nodeClass, createNode, componentProps,\n // Whether or not the ghost text should count as text inside the input for submitting and character count\n exposeText, allowCompletion) {\n _define_property(this, \"__id\", void 0);\n _define_property(this, \"__$getGhostText\", void 0);\n _define_property(this, \"__componentProps\", void 0);\n _define_property(this, \"__exposeText\", void 0);\n _define_property(this, \"__allowCompletion\", void 0);\n _define_property(this, \"__cleanup\", void 0);\n this.__id = id;\n this.__$getGhostText = $getGhostText;\n this.__componentProps = componentProps;\n this.__exposeText = exposeText;\n this.__allowCompletion = allowCompletion;\n let ghostTextNodeKey = null;\n let lastText = undefined;\n function $clearGhostText() {\n const ghostTextNode = ghostTextNodeKey !== null ? $getNodeByKey(ghostTextNodeKey) : null;\n ghostTextNodeKey = null;\n lastText = undefined;\n if (ghostTextNode && ghostTextNode.isAttached()) {\n ghostTextNode.remove();\n }\n }\n function handleGhostTextNodeTransform(node) {\n const key = node.getKey();\n if (node.__id === id && key !== ghostTextNodeKey) {\n // Only one ghost text\n node.remove();\n $clearGhostText();\n }\n }\n const handleGhostTextResponse = text => {\n if (text === lastText) {\n return;\n }\n editor.update(() => {\n $clearGhostText();\n const selection = $getSelection();\n if (!text || !selection) {\n return;\n }\n const selectionCopy = selection.clone();\n const node = createNode(this.__id, text, this.__exposeText, this.__componentProps);\n ghostTextNodeKey = node.getKey();\n lastText = text;\n selection.insertNodes([node]);\n $setSelection(selectionCopy);\n }, {\n tag: 'historic'\n });\n };\n const handleUpdate = props => {\n const {\n editorState,\n prevEditorState\n } = props;\n editorState.read(() => {\n const promise = this.__$getGhostText(editor, editorState, prevEditorState);\n promise.then(handleGhostTextResponse).catch(e => console.error(e));\n });\n };\n function unmountGhostText() {\n if (ghostTextNodeKey) {\n editor.update(() => {\n $clearGhostText();\n }, {\n tag: 'historic'\n });\n }\n }\n function $handleTabCommand(e) {\n if (ghostTextNodeKey === null || lastText === null) {\n return false;\n }\n const ghostTextNode = $getNodeByKey(ghostTextNodeKey);\n if (!ghostTextNode) {\n return false;\n }\n e.preventDefault();\n const textNode = $createTextNode(lastText);\n ghostTextNode.replace(textNode);\n textNode.selectEnd();\n $clearGhostText();\n return true;\n }\n this.__cleanup = mergeRegister(editor.registerNodeTransform(nodeClass, handleGhostTextNodeTransform), editor.registerUpdateListener(handleUpdate), this.__allowCompletion ? editor.registerCommand(KEY_TAB_COMMAND, $handleTabCommand, COMMAND_PRIORITY_LOW) : noop, unmountGhostText);\n }\n}\nfunction noop() {\n return;\n}\n//# sourceMappingURL=GhostText.base.js.map"],"names":["GhostTextPluginBase","cleanup","_this___cleanup","_this","__cleanup","call","setExposeText","exposeText","__exposeText","setComponentProps","componentProps","__componentProps","setGetGhostText","$getGhostText","__$getGhostText","setAllowCompletion","allowCompletion","__allowCompletion","constructor","editor","id","nodeClass","createNode","_define_property","__id","ghostTextNodeKey","lastText","undefined","$clearGhostText","ghostTextNode","$getNodeByKey","isAttached","remove","handleGhostTextNodeTransform","node","key","getKey","handleGhostTextResponse","text","update","selection","$getSelection","selectionCopy","clone","insertNodes","$setSelection","tag","handleUpdate","props","editorState","prevEditorState","read","promise","then","catch","e","console","error","unmountGhostText","$handleTabCommand","preventDefault","textNode","$createTextNode","replace","selectEnd","mergeRegister","registerNodeTransform","registerUpdateListener","registerCommand","KEY_TAB_COMMAND","COMMAND_PRIORITY_LOW","noop"],"mappings":";;;;+BAEaA;;;eAAAA;;;iCAFyB;4BAC6F;AAC5H,MAAMA;IACXC,UAAU;QACR,IAAIC,iBAAiBC;QACpBD,CAAAA,kBAAkB,AAACC,CAAAA,QAAQ,IAAI,AAAD,EAAGC,SAAS,AAAD,MAAO,QAAQF,oBAAoB,KAAK,IAAI,KAAK,IAAIA,gBAAgBG,IAAI,CAACF;IACtH;IACAG,cAAcC,UAAU,EAAE;QACxB,IAAI,CAACC,YAAY,GAAGD;IACtB;IACAE,kBAAkBC,cAAc,EAAE;QAChC,IAAI,CAACC,gBAAgB,GAAGD;IAC1B;IACAE,gBAAgBC,aAAa,EAAE;QAC7B,IAAI,CAACC,eAAe,GAAGD;IACzB;IACAE,mBAAmBC,eAAe,EAAE;QAClC,IAAI,CAACC,iBAAiB,GAAGD;IAC3B;IACAE,YAAYC,MAAM,EAAEC,EAAE,EAAEP,aAAa,EAAEQ,SAAS,EAAEC,UAAU,EAAEZ,cAAc,EAC5E,yGAAyG;IACzGH,UAAU,EAAES,eAAe,CAAE;QAC3BO,IAAAA,kBAAgB,EAAC,IAAI,EAAE,QAAQ,KAAK;QACpCA,IAAAA,kBAAgB,EAAC,IAAI,EAAE,mBAAmB,KAAK;QAC/CA,IAAAA,kBAAgB,EAAC,IAAI,EAAE,oBAAoB,KAAK;QAChDA,IAAAA,kBAAgB,EAAC,IAAI,EAAE,gBAAgB,KAAK;QAC5CA,IAAAA,kBAAgB,EAAC,IAAI,EAAE,qBAAqB,KAAK;QACjDA,IAAAA,kBAAgB,EAAC,IAAI,EAAE,aAAa,KAAK;QACzC,IAAI,CAACC,IAAI,GAAGJ;QACZ,IAAI,CAACN,eAAe,GAAGD;QACvB,IAAI,CAACF,gBAAgB,GAAGD;QACxB,IAAI,CAACF,YAAY,GAAGD;QACpB,IAAI,CAACU,iBAAiB,GAAGD;QACzB,IAAIS,mBAAmB;QACvB,IAAIC,WAAWC;QACf,SAASC;YACP,MAAMC,
|
|
1
|
+
{"version":3,"sources":["GhostText.base.js"],"sourcesContent":["import { _ as _define_property } from \"@swc/helpers/_/_define_property\";\nimport { $createTextNode, $getNodeByKey, $getSelection, $setSelection, COMMAND_PRIORITY_LOW, KEY_TAB_COMMAND, mergeRegister } from '@fluentui-copilot/text-editor';\nexport class GhostTextPluginBase {\n cleanup() {\n var _this___cleanup, _this;\n (_this___cleanup = (_this = this).__cleanup) === null || _this___cleanup === void 0 ? void 0 : _this___cleanup.call(_this);\n }\n setExposeText(exposeText) {\n this.__exposeText = exposeText;\n }\n setComponentProps(componentProps) {\n this.__componentProps = componentProps;\n }\n setGetGhostText($getGhostText) {\n this.__$getGhostText = $getGhostText;\n }\n setAllowCompletion(allowCompletion) {\n this.__allowCompletion = allowCompletion;\n }\n constructor(editor, id, $getGhostText, nodeClass, createNode, componentProps,\n // Whether or not the ghost text should count as text inside the input for submitting and character count\n exposeText, allowCompletion) {\n _define_property(this, \"__id\", void 0);\n _define_property(this, \"__$getGhostText\", void 0);\n _define_property(this, \"__componentProps\", void 0);\n _define_property(this, \"__exposeText\", void 0);\n _define_property(this, \"__allowCompletion\", void 0);\n _define_property(this, \"__cleanup\", void 0);\n this.__id = id;\n this.__$getGhostText = $getGhostText;\n this.__componentProps = componentProps;\n this.__exposeText = exposeText;\n this.__allowCompletion = allowCompletion;\n let ghostTextNodeKey = null;\n let lastText = undefined;\n let justRemovedGhostText = false;\n function $clearGhostText() {\n const ghostTextNode = ghostTextNodeKey !== null ? $getNodeByKey(ghostTextNodeKey) : null;\n ghostTextNodeKey = null;\n lastText = undefined;\n if (ghostTextNode && ghostTextNode.isAttached()) {\n ghostTextNode.remove();\n }\n }\n function handleGhostTextNodeTransform(node) {\n const key = node.getKey();\n if (node.__id === id && key !== ghostTextNodeKey) {\n // Only one ghost text\n node.remove();\n $clearGhostText();\n }\n }\n const handleGhostTextResponse = text => {\n if (text === lastText) {\n return;\n }\n editor.update(() => {\n $clearGhostText();\n const selection = $getSelection();\n if (!text || !selection) {\n justRemovedGhostText = true;\n return;\n }\n const selectionCopy = selection.clone();\n const node = createNode(this.__id, text, this.__exposeText, this.__componentProps);\n ghostTextNodeKey = node.getKey();\n lastText = text;\n selection.insertNodes([node]);\n $setSelection(selectionCopy);\n }, {\n tag: 'historic'\n });\n };\n const handleUpdate = props => {\n const {\n editorState,\n prevEditorState\n } = props;\n // If this update was caused by deleting the previous ghost text, don't create a new one until a subsequent update\n if (justRemovedGhostText) {\n justRemovedGhostText = false;\n return;\n }\n editorState.read(() => {\n const promise = this.__$getGhostText(editor, editorState, prevEditorState);\n promise.then(handleGhostTextResponse).catch(e => console.error(e));\n });\n };\n function unmountGhostText() {\n if (ghostTextNodeKey) {\n editor.update(() => {\n $clearGhostText();\n }, {\n tag: 'historic'\n });\n }\n }\n function $handleTabCommand(e) {\n if (ghostTextNodeKey === null || lastText === null) {\n return false;\n }\n const ghostTextNode = $getNodeByKey(ghostTextNodeKey);\n if (!ghostTextNode) {\n return false;\n }\n e.preventDefault();\n const textNode = $createTextNode(lastText);\n ghostTextNode.replace(textNode);\n textNode.selectEnd();\n $clearGhostText();\n return true;\n }\n this.__cleanup = mergeRegister(editor.registerNodeTransform(nodeClass, handleGhostTextNodeTransform), editor.registerUpdateListener(handleUpdate), this.__allowCompletion ? editor.registerCommand(KEY_TAB_COMMAND, $handleTabCommand, COMMAND_PRIORITY_LOW) : noop, unmountGhostText);\n }\n}\nfunction noop() {\n return;\n}\n//# sourceMappingURL=GhostText.base.js.map"],"names":["GhostTextPluginBase","cleanup","_this___cleanup","_this","__cleanup","call","setExposeText","exposeText","__exposeText","setComponentProps","componentProps","__componentProps","setGetGhostText","$getGhostText","__$getGhostText","setAllowCompletion","allowCompletion","__allowCompletion","constructor","editor","id","nodeClass","createNode","_define_property","__id","ghostTextNodeKey","lastText","undefined","justRemovedGhostText","$clearGhostText","ghostTextNode","$getNodeByKey","isAttached","remove","handleGhostTextNodeTransform","node","key","getKey","handleGhostTextResponse","text","update","selection","$getSelection","selectionCopy","clone","insertNodes","$setSelection","tag","handleUpdate","props","editorState","prevEditorState","read","promise","then","catch","e","console","error","unmountGhostText","$handleTabCommand","preventDefault","textNode","$createTextNode","replace","selectEnd","mergeRegister","registerNodeTransform","registerUpdateListener","registerCommand","KEY_TAB_COMMAND","COMMAND_PRIORITY_LOW","noop"],"mappings":";;;;+BAEaA;;;eAAAA;;;iCAFyB;4BAC6F;AAC5H,MAAMA;IACXC,UAAU;QACR,IAAIC,iBAAiBC;QACpBD,CAAAA,kBAAkB,AAACC,CAAAA,QAAQ,IAAI,AAAD,EAAGC,SAAS,AAAD,MAAO,QAAQF,oBAAoB,KAAK,IAAI,KAAK,IAAIA,gBAAgBG,IAAI,CAACF;IACtH;IACAG,cAAcC,UAAU,EAAE;QACxB,IAAI,CAACC,YAAY,GAAGD;IACtB;IACAE,kBAAkBC,cAAc,EAAE;QAChC,IAAI,CAACC,gBAAgB,GAAGD;IAC1B;IACAE,gBAAgBC,aAAa,EAAE;QAC7B,IAAI,CAACC,eAAe,GAAGD;IACzB;IACAE,mBAAmBC,eAAe,EAAE;QAClC,IAAI,CAACC,iBAAiB,GAAGD;IAC3B;IACAE,YAAYC,MAAM,EAAEC,EAAE,EAAEP,aAAa,EAAEQ,SAAS,EAAEC,UAAU,EAAEZ,cAAc,EAC5E,yGAAyG;IACzGH,UAAU,EAAES,eAAe,CAAE;QAC3BO,IAAAA,kBAAgB,EAAC,IAA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
11
|
const _define_property = require("@swc/helpers/_/_define_property");
|
|
12
12
|
const _texteditor = require("@fluentui-copilot/text-editor");
|
|
13
13
|
class ImperativeControlBase {
|
|
14
|
+
moveCursor(location) {
|
|
15
|
+
this.__editor.update(()=>{
|
|
16
|
+
const children = (0, _texteditor.$getLeafNodes)((0, _texteditor.$getRoot)());
|
|
17
|
+
let baseOffset = 0;
|
|
18
|
+
let currentNode = children.shift();
|
|
19
|
+
while(baseOffset < location && currentNode){
|
|
20
|
+
const nodeLength = (0, _texteditor.$isTextNode)(currentNode) && !currentNode.isToken() ? currentNode.getTextContent().length : 1;
|
|
21
|
+
if (baseOffset + nodeLength >= location) {
|
|
22
|
+
const elementType = (0, _texteditor.$isTextNode)(currentNode) ? 'text' : 'element';
|
|
23
|
+
const localOffset = location - baseOffset;
|
|
24
|
+
const nodeKey = currentNode.getKey();
|
|
25
|
+
const selection = (0, _texteditor.$createRangeSelection)();
|
|
26
|
+
selection.anchor.set(nodeKey, localOffset, elementType);
|
|
27
|
+
selection.focus.set(nodeKey, localOffset, elementType);
|
|
28
|
+
(0, _texteditor.$setSelection)((0, _texteditor.$normalizeSelection__EXPERIMENTAL)(selection));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
baseOffset += nodeLength;
|
|
32
|
+
currentNode = children.shift();
|
|
33
|
+
}
|
|
34
|
+
if (location > baseOffset) {
|
|
35
|
+
(0, _texteditor.$getRoot)().selectEnd();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
14
39
|
setInputText(inputText) {
|
|
15
40
|
this.__editor.update(()=>{
|
|
16
41
|
const root = (0, _texteditor.$getRoot)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ImperativeControl.base.js"],"sourcesContent":["import { _ as _define_property } from \"@swc/helpers/_/_define_property\";\nimport { $createParagraphNode, $createTextNode, $getRoot, $getSelection } from '@fluentui-copilot/text-editor';\nexport class ImperativeControlBase {\n setInputText(inputText) {\n this.__editor.update(() => {\n const root = $getRoot();\n root.clear();\n if (inputText !== '') {\n const newParagraph = $createParagraphNode();\n const newText = $createTextNode(inputText);\n newParagraph.append(newText);\n root.append(newParagraph);\n root.selectEnd();\n }\n });\n }\n appendText(text) {\n this.__editor.update(() => {\n $getRoot().selectEnd().insertText(text);\n });\n }\n prependText(text) {\n this.__editor.update(() => {\n $getRoot().selectStart().insertText(text);\n });\n }\n insertTextAtCursor(text) {\n this.__editor.update(() => {\n var _$getSelection;\n (_$getSelection = $getSelection()) === null || _$getSelection === void 0 ? void 0 : _$getSelection.insertText(text);\n });\n }\n getInputText() {\n return this.__editor.getEditorState().read(() => {\n return $getRoot().getTextContent();\n });\n }\n scrollToBottom() {\n var _this___editor_getRootElement;\n (_this___editor_getRootElement = this.__editor.getRootElement()) === null || _this___editor_getRootElement === void 0 ? void 0 : _this___editor_getRootElement.scrollIntoView({\n behavior: 'smooth',\n block: 'end'\n });\n return;\n }\n constructor(editor) {\n _define_property(this, \"__editor\", void 0);\n this.__editor = editor;\n }\n}\n//# sourceMappingURL=ImperativeControl.base.js.map"],"names":["ImperativeControlBase","
|
|
1
|
+
{"version":3,"sources":["ImperativeControl.base.js"],"sourcesContent":["import { _ as _define_property } from \"@swc/helpers/_/_define_property\";\nimport { $createParagraphNode, $createRangeSelection, $createTextNode, $getLeafNodes, $getRoot, $getSelection, $isTextNode, $normalizeSelection__EXPERIMENTAL, $setSelection } from '@fluentui-copilot/text-editor';\nexport class ImperativeControlBase {\n moveCursor(location) {\n this.__editor.update(() => {\n const children = $getLeafNodes($getRoot());\n let baseOffset = 0;\n let currentNode = children.shift();\n while (baseOffset < location && currentNode) {\n const nodeLength = $isTextNode(currentNode) && !currentNode.isToken() ? currentNode.getTextContent().length : 1;\n if (baseOffset + nodeLength >= location) {\n const elementType = $isTextNode(currentNode) ? 'text' : 'element';\n const localOffset = location - baseOffset;\n const nodeKey = currentNode.getKey();\n const selection = $createRangeSelection();\n selection.anchor.set(nodeKey, localOffset, elementType);\n selection.focus.set(nodeKey, localOffset, elementType);\n $setSelection($normalizeSelection__EXPERIMENTAL(selection));\n return;\n }\n baseOffset += nodeLength;\n currentNode = children.shift();\n }\n if (location > baseOffset) {\n $getRoot().selectEnd();\n }\n });\n }\n setInputText(inputText) {\n this.__editor.update(() => {\n const root = $getRoot();\n root.clear();\n if (inputText !== '') {\n const newParagraph = $createParagraphNode();\n const newText = $createTextNode(inputText);\n newParagraph.append(newText);\n root.append(newParagraph);\n root.selectEnd();\n }\n });\n }\n appendText(text) {\n this.__editor.update(() => {\n $getRoot().selectEnd().insertText(text);\n });\n }\n prependText(text) {\n this.__editor.update(() => {\n $getRoot().selectStart().insertText(text);\n });\n }\n insertTextAtCursor(text) {\n this.__editor.update(() => {\n var _$getSelection;\n (_$getSelection = $getSelection()) === null || _$getSelection === void 0 ? void 0 : _$getSelection.insertText(text);\n });\n }\n getInputText() {\n return this.__editor.getEditorState().read(() => {\n return $getRoot().getTextContent();\n });\n }\n scrollToBottom() {\n var _this___editor_getRootElement;\n (_this___editor_getRootElement = this.__editor.getRootElement()) === null || _this___editor_getRootElement === void 0 ? void 0 : _this___editor_getRootElement.scrollIntoView({\n behavior: 'smooth',\n block: 'end'\n });\n return;\n }\n constructor(editor) {\n _define_property(this, \"__editor\", void 0);\n this.__editor = editor;\n }\n}\n//# sourceMappingURL=ImperativeControl.base.js.map"],"names":["ImperativeControlBase","moveCursor","location","__editor","update","children","$getLeafNodes","$getRoot","baseOffset","currentNode","shift","nodeLength","$isTextNode","isToken","getTextContent","length","elementType","localOffset","nodeKey","getKey","selection","$createRangeSelection","anchor","set","focus","$setSelection","$normalizeSelection__EXPERIMENTAL","selectEnd","setInputText","inputText","root","clear","newParagraph","$createParagraphNode","newText","$createTextNode","append","appendText","text","insertText","prependText","selectStart","insertTextAtCursor","_$getSelection","$getSelection","getInputText","getEditorState","read","scrollToBottom","_this___editor_getRootElement","getRootElement","scrollIntoView","behavior","block","constructor","editor","_define_property"],"mappings":";;;;+BA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,CAACnC,QAAQ,CAACC,MAAM,CAAC;YACnBG,IAAAA,oBAAQ,IAAGoB,SAAS,GAAGY,UAAU,CAACD;QACpC;IACF;IACAE,YAAYF,IAAI,EAAE;QAChB,IAAI,CAACnC,QAAQ,CAACC,MAAM,CAAC;YACnBG,IAAAA,oBAAQ,IAAGkC,WAAW,GAAGF,UAAU,CAACD;QACtC;IACF;IACAI,mBAAmBJ,IAAI,EAAE;QACvB,IAAI,CAACnC,QAAQ,CAACC,MAAM,CAAC;YACnB,IAAIuC;YACHA,CAAAA,iBAAiBC,IAAAA,yBAAa,GAAC,MAAO,QAAQD,mBAAmB,KAAK,IAAI,KAAK,IAAIA,eAAeJ,UAAU,CAACD;QAChH;IACF;IACAO,eAAe;QACb,OAAO,IAAI,CAAC1C,QAAQ,CAAC2C,cAAc,GAAGC,IAAI,CAAC;YACzC,OAAOxC,IAAAA,oBAAQ,IAAGO,cAAc;QAClC;IACF;IACAkC,iBAAiB;QACf,IAAIC;QACHA,CAAAA,gCAAgC,IAAI,CAAC9C,QAAQ,CAAC+C,cAAc,EAAC,MAAO,QAAQD,kCAAkC,KAAK,IAAI,KAAK,IAAIA,8BAA8BE,cAAc,CAAC;YAC5KC,UAAU;YACVC,OAAO;QACT;QACA;IACF;IACAC,YAAYC,MAAM,CAAE;QAClBC,IAAAA,kBAAgB,EAAC,IAAI,EAAE,YAAY,KAAK;QACxC,IAAI,CAACrD,QAAQ,GAAGoD;IAClB;AACF,EACA,kDAAkD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui-copilot/chat-input-plugins",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "A Fluent AI package for non-react specific chat input plugins.",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@fluentui-copilot/text-editor": "^0.0.
|
|
15
|
+
"@fluentui-copilot/text-editor": "^0.0.2",
|
|
16
16
|
"@swc/helpers": "^0.5.1"
|
|
17
17
|
},
|
|
18
18
|
"beachball": {
|