@fluentui-copilot/chat-input-plugins 0.0.5 → 0.0.6

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 CHANGED
@@ -2,7 +2,22 @@
2
2
  "name": "@fluentui-copilot/chat-input-plugins",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 08 May 2024 22:09:00 GMT",
5
+ "date": "Wed, 15 May 2024 23:57:19 GMT",
6
+ "tag": "@fluentui-copilot/chat-input-plugins_v0.0.6",
7
+ "version": "0.0.6",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "tristan.watanabe@gmail.com",
12
+ "package": "@fluentui-copilot/chat-input-plugins",
13
+ "commit": "64698dbd45e8203c4db973e866db42f4e74ebeef",
14
+ "comment": "feat: add transform callback to getInputText to enable custom string representation for each node."
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Wed, 08 May 2024 22:10:20 GMT",
6
21
  "tag": "@fluentui-copilot/chat-input-plugins_v0.0.5",
7
22
  "version": "0.0.5",
8
23
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,21 @@
1
1
  # Change Log - @fluentui-copilot/chat-input-plugins
2
2
 
3
- This log was last generated on Wed, 08 May 2024 22:09:00 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 15 May 2024 23:57:19 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [0.0.6](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.0.6)
8
+
9
+ Wed, 15 May 2024 23:57:19 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.0.5..@fluentui-copilot/chat-input-plugins_v0.0.6)
11
+
12
+ ### Patches
13
+
14
+ - feat: add transform callback to getInputText to enable custom string representation for each node. ([PR #1626](https://github.com/microsoft/fluentai/pull/1626) by tristan.watanabe@gmail.com)
15
+
7
16
  ## [0.0.5](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.0.5)
8
17
 
9
- Wed, 08 May 2024 22:09:00 GMT
18
+ Wed, 08 May 2024 22:10:20 GMT
10
19
  [Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.0.4..@fluentui-copilot/chat-input-plugins_v0.0.5)
11
20
 
12
21
  ### Patches
package/dist/index.d.ts CHANGED
@@ -113,7 +113,10 @@ export declare interface IImperativeControlBase {
113
113
  appendText: (text: string) => void;
114
114
  prependText: (text: string) => void;
115
115
  insertTextAtCursor: (text: string) => void;
116
- getInputText: () => string;
116
+ /**
117
+ * @param transform will be called for each Lexical node in the input. This enables custom string representation for each node.
118
+ */
119
+ getInputText: (transform?: (node: LexicalNode) => string) => string;
117
120
  scrollToBottom: () => void;
118
121
  moveCursor: (location: number) => void;
119
122
  }
@@ -133,7 +136,7 @@ export declare class ImperativeControlBase implements IImperativeControlBase {
133
136
  appendText(text: string): void;
134
137
  prependText(text: string): void;
135
138
  insertTextAtCursor(text: string): void;
136
- getInputText(): string;
139
+ getInputText(transform?: (node: LexicalNode) => string): string;
137
140
  scrollToBottom(): void;
138
141
  }
139
142
 
@@ -1,6 +1,6 @@
1
1
  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
- import { SENTINEL_VALUE } from '../BasicFunctionality';
3
+ import { SENTINEL_VALUE, $isSentinelNode } from '../BasicFunctionality';
4
4
  export class ImperativeControlBase {
5
5
  moveCursor(location) {
6
6
  this.__editor.update(() => {
@@ -57,9 +57,19 @@ export class ImperativeControlBase {
57
57
  selection.insertText(text);
58
58
  });
59
59
  }
60
- getInputText() {
60
+ getInputText(transform) {
61
61
  return this.__editor.getEditorState().read(() => {
62
- return $getRoot().getTextContent().replace(SENTINEL_VALUE, '');
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('');
63
73
  });
64
74
  }
65
75
  scrollToBottom() {
@@ -1 +1 @@
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';\nimport { SENTINEL_VALUE } from '../BasicFunctionality';\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 const selection = $getSelection() ?? $getRoot().selectEnd();\n selection.insertText(text);\n });\n }\n getInputText() {\n return this.__editor.getEditorState().read(() => {\n return $getRoot().getTextContent().replace(SENTINEL_VALUE, '');\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","SENTINEL_VALUE","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","replace","scrollToBottom","getRootElement","scrollIntoView","behavior","block","constructor","editor"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AACA,SACEA,oBAAoB,EACpBC,qBAAqB,EACrBC,eAAe,EACfC,aAAa,EACbC,QAAQ,EACRC,aAAa,EACbC,WAAW,EACXC,iCAAiC,EACjCC,aAAa,QACR,gCAAg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3B,QAAQ,CAACC,MAAM,CAAC;YACnBV,WAAWuC,WAAW,GAAGF,UAAU,CAACD;QACtC;IACF;IACAI,mBAAmBJ,IAAY,EAAE;QAC/B,IAAI,CAAC3B,QAAQ,CAACC,MAAM,CAAC;gBACDT;YAAlB,MAAMsB,YAAYtB,CAAAA,iBAAAA,6BAAAA,4BAAAA,iBAAmBD,WAAW2B,SAAS;YACzDJ,UAAUc,UAAU,CAACD;QACvB;IACF;IACAK,eAAe;QACb,OAAO,IAAI,CAAChC,QAAQ,CAACiC,cAAc,GAAGC,IAAI,CAAC;YACzC,OAAO3C,WAAWiB,cAAc,GAAG2B,OAAO,CAACvC,gBAAgB;QAC7D;IACF;IACAwC,iBAAiB;YACf;SAAA,gCAAA,IAAI,CAACpC,QAAQ,CAACqC,cAAc,gBAA5B,oDAAA,8BAAgCC,cAAc,CAAC;YAAEC,UAAU;YAAUC,OAAO;QAAM;QAClF;IACF;IA7EAC,YAAYC,MAAqB,CAAE;QAFnC,uBAAQ1C,YAAR,KAAA;QAGE,IAAI,CAACA,QAAQ,GAAG0C;IAClB;AA4EF"}
1
+ {"version":3,"sources":["ImperativeControl.base.ts"],"sourcesContent":["import type { LexicalEditor, LexicalNode } 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';\nimport { SENTINEL_VALUE, $isSentinelNode } from '../BasicFunctionality';\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 /**\n * @param transform will be called for each Lexical node in the input. This enables custom string representation for each node.\n */\n getInputText: (transform?: (node: LexicalNode) => string) => 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 const selection = $getSelection() ?? $getRoot().selectEnd();\n selection.insertText(text);\n });\n }\n getInputText(transform?: (node: LexicalNode) => string) {\n return this.__editor.getEditorState().read(() => {\n if (!transform) {\n return $getRoot().getTextContent().replace(SENTINEL_VALUE, '');\n }\n const children = $getLeafNodes($getRoot());\n const transformedNodeTexts: string[] = [];\n\n for (const currentNode of children) {\n if (!$isSentinelNode(currentNode)) {\n transformedNodeTexts.push(transform(currentNode));\n }\n }\n\n return transformedNodeTexts.join('');\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","SENTINEL_VALUE","$isSentinelNode","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","transform","getEditorState","read","replace","transformedNodeTexts","push","join","scrollToBottom","getRootElement","scrollIntoView","behavior","block","constructor","editor"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AACA,SACEA,oBAAoB,EACpBC,qBAAqB,EACrBC,eAAe,EACfC,aAAa,EACbC,QAAQ,EACRC,aAAa,EACbC,WAAW,EACXC,iCAAiC,EACjCC,aAAa,QACR,gCAAgC;AACvC,SAASC,cAAc,EAAEC,eAAe,QAAQ,wBAAwB;AAexE,OAAO,MAAMC;IAOXC,WAAWC,QAAgB,EAAQ;QACjC,IAAI,CAACC,QAAQ,CAACC,MAAM,CAAC;YACnB,MAAMC,WAAWb,cAAcC;YAE/B,IAAIa,aAAa;YACjB,IAAIC,cAAcF,SAASG,KAAK;YAChC,MAAOF,aAAaJ,YAAYK,YAAa;gBAC3C,MAAME,aACJd,YAAYY,gBAAgB,CAACA,YAAYG,OAAO,KAC5CH,YAAYI,cAAc,GAAGC,MAAM,GAEnC;gBAEN,IAAIN,aAAaG,cAAcP,UAAU;oBACvC,MAAMW,cAAclB,YAAYY,eAAe,SAAS;oBACxD,MAAMO,cAAcZ,WAAWI;oBAC/B,MAAMS,UAAUR,YAAYS,MAAM;oBAElC,MAAMC,YAAY3B;oBAClB2B,UA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AEzC,KAAK,MAAMjC,eAAeF,SAAU;gBAClC,IAAI,CAACN,gBAAgBQ,cAAc;oBACjCiC,qBAAqBC,IAAI,CAACL,UAAU7B;gBACtC;YACF;YAEA,OAAOiC,qBAAqBE,IAAI,CAAC;QACnC;IACF;IACAC,iBAAiB;YACf;SAAA,gCAAA,IAAI,CAACxC,QAAQ,CAACyC,cAAc,gBAA5B,oDAAA,8BAAgCC,cAAc,CAAC;YAAEC,UAAU;YAAUC,OAAO;QAAM;QAClF;IACF;IAzFAC,YAAYC,MAAqB,CAAE;QAFnC,uBAAQ9C,YAAR,KAAA;QAGE,IAAI,CAACA,QAAQ,GAAG8C;IAClB;AAwFF"}
@@ -67,9 +67,19 @@ class ImperativeControlBase {
67
67
  selection.insertText(text);
68
68
  });
69
69
  }
70
- getInputText() {
70
+ getInputText(transform) {
71
71
  return this.__editor.getEditorState().read(()=>{
72
- return (0, _texteditor.$getRoot)().getTextContent().replace(_BasicFunctionality.SENTINEL_VALUE, '');
72
+ if (!transform) {
73
+ return (0, _texteditor.$getRoot)().getTextContent().replace(_BasicFunctionality.SENTINEL_VALUE, '');
74
+ }
75
+ const children = (0, _texteditor.$getLeafNodes)((0, _texteditor.$getRoot)());
76
+ const transformedNodeTexts = [];
77
+ for (const currentNode of children){
78
+ if (!(0, _BasicFunctionality.$isSentinelNode)(currentNode)) {
79
+ transformedNodeTexts.push(transform(currentNode));
80
+ }
81
+ }
82
+ return transformedNodeTexts.join('');
73
83
  });
74
84
  }
75
85
  scrollToBottom() {
@@ -1 +1 @@
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';\nimport { SENTINEL_VALUE } from '../BasicFunctionality';\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 const selection = $getSelection() ?? $getRoot().selectEnd();\n selection.insertText(text);\n });\n }\n getInputText() {\n return this.__editor.getEditorState().read(() => {\n return $getRoot().getTextContent().replace(SENTINEL_VALUE, '');\n });\n }\n scrollToBottom() {\n this.__editor.getRootElement()?.scrollIntoView({ behavior: 'smooth', block: 'end' });\n return;\n }\n}\n"],"names":["ImperativeControlBase","moveCursor","location","__editor","update","children","$getLeafNodes","$getRoot","baseOffset","currentNode","nodeLength","$isTextNode","isToken","getTextContent","length","elementType","localOffset","nodeKey","selection","$createRangeSelection","anchor","focus","$setSelection","$normalizeSelection__EXPERIMENTAL","selectEnd","setInputText","inputText","root","newParagraph","$createParagraphNode","newText","$createTextNode","appendText","text","insertText","prependText","selectStart","insertTextAtCursor","$getSelection","getInputText","getEditorState","read","replace","SENTINEL_VALUE","scrollToBottom","getRootElement","_this___editor_getRootElement","scrollIntoView","behavior","block","constructor","editor"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAwBaA;;;eAAAA;;;;4BAbN;oCACwB;AAYxB,MAAMA;eAOXC,QAAWC,EAAgB;YACzB,CAAAC,QAAKA,CAAAA,MAASC,CAAAA;kBACZC,WAAMA,IAAAA,yBAAWC,EAAAA,IAAAA,oBAAcC;6BAE3BC;8BACAC,SAAcJ,KAAAA;kBAClBG,aAAOA,YAAaN,YAAYO;mCACxBC,IAAAA,uBACJC,EAAAA,gBAAYF,CAAAA,YAAiBA,OAAAA,KAAYG,YACrCH,cAAYI,GAAAA,MAAc,GAAGC;iCAI/BN,cAAaE,UAAcR;wCACvBa,IAAAA,uBAAcJ,EAAAA,eAAYF,SAAAA;wCAC1BO,WAAcd;oCACde,YAAUR,MAAAA;sCAEVS,IAAAA,iCAAYC;8BAClBD,MAAAA,CAAAA,GAAUE,CAAAA,SAAUJ,aAAUA;8BAC9BE,KAAAA,CAAAA,GAAAA,CAAUG,SAASL,aAAUA;iDAE7BM,EAAAA,IAAAA,6CAAcC,EAAAA;;;8BAIhBf;8BACAC,SAAcJ,KAAAA;;2BAGZH,YAAWM;wCACbD,IAAAA,SAAWiB;;;;iBAIjBC,SAAaC,EAAiB;YAC5B,CAAAvB,QAAKA,CAAAA,MAASC,CAAAA;kBACZuB,OAAMA,IAAAA,oBAAOpB;sBACboB;8BACID,IAAAA;qCACIE,IAAAA,gCAAeC;gCACfC,IAAAA,2BAAUC,EAAAA;6BAEhBH,MAAAA,CAAAA;2BACAD,CAAAA;8BACKH;;;;eAIXQ,IAAWC,EAAY;YACrB,CAAA9B,QAAKA,CAAAA,MAASC,CAAAA;oCACZG,IAAAA,SAAWiB,GAAAA,UAAYU,CAAAA;;;gBAG3BC,IAAYF,EAAY;YACtB,CAAA9B,QAAKA,CAAAA,MAASC,CAAAA;oCACZG,IAAAA,WAAW6B,GAAAA,UAAcF,CAAAA;;;uBAG7BG,IAAmBJ,EAAY;YAC7B,CAAA9B,QAAKA,CAAAA,MAASC,CAAAA;;kBACZc,YAAMA,CAAAA,iBAAYoB,IAAAA,yBAAAA,GAAAA,MAAAA,QAAAA,mBAAAA,KAAAA,IAAAA,iBAAAA,IAAAA,oBAAmB/B,IAAAA,SAAWiB;sBAChDN,UAAUgB,CAAAA;;;mBAGdK;eACE,IAAO,CAAApC,QAAKA,CAAAA,cAASqC,GAAAA,IAAiBC,CAAAA;mBACpClC,IAAAA,oBAAOA,IAAAA,cAAWM,GAAAA,OAAiB6B,CAAAA,kCAAQC,EAAAA;;;qBAG/CC;;yCACE,IAAA,CAAAzC,QAAKA,CAAAA,cAAS0C,EAAAA,MAAc,QAAAC,kCAA5B,KAAA,IAAA,KAAA,IAAAA,8BAAAC,cAAgCA,CAAAA;sBAAiBC;mBAAoBC;;;;gBA3EvEC,MAAYC,CAAqB;8BAFjC,EAAA,IAAA,EAAA,YAAQhD,KAAR;YAGE,CAAAA,QAAKA,GAAAA;;AA6ET"}
1
+ {"version":3,"sources":["ImperativeControl.base.ts"],"sourcesContent":["import type { LexicalEditor, LexicalNode } 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';\nimport { SENTINEL_VALUE, $isSentinelNode } from '../BasicFunctionality';\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 /**\n * @param transform will be called for each Lexical node in the input. This enables custom string representation for each node.\n */\n getInputText: (transform?: (node: LexicalNode) => string) => 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 const selection = $getSelection() ?? $getRoot().selectEnd();\n selection.insertText(text);\n });\n }\n getInputText(transform?: (node: LexicalNode) => string) {\n return this.__editor.getEditorState().read(() => {\n if (!transform) {\n return $getRoot().getTextContent().replace(SENTINEL_VALUE, '');\n }\n const children = $getLeafNodes($getRoot());\n const transformedNodeTexts: string[] = [];\n\n for (const currentNode of children) {\n if (!$isSentinelNode(currentNode)) {\n transformedNodeTexts.push(transform(currentNode));\n }\n }\n\n return transformedNodeTexts.join('');\n });\n }\n scrollToBottom() {\n this.__editor.getRootElement()?.scrollIntoView({ behavior: 'smooth', block: 'end' });\n return;\n }\n}\n"],"names":["ImperativeControlBase","moveCursor","location","__editor","update","children","$getLeafNodes","$getRoot","baseOffset","currentNode","nodeLength","$isTextNode","isToken","getTextContent","length","elementType","localOffset","nodeKey","selection","$createRangeSelection","anchor","focus","$setSelection","$normalizeSelection__EXPERIMENTAL","selectEnd","setInputText","inputText","root","newParagraph","$createParagraphNode","newText","$createTextNode","appendText","text","insertText","prependText","selectStart","insertTextAtCursor","$getSelection","getInputText","transform","getEditorState","read","replace","SENTINEL_VALUE","transformedNodeTexts","$isSentinelNode","scrollToBottom","getRootElement","_this___editor_getRootElement","scrollIntoView","behavior","block","constructor","editor"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BA2BaA;;;eAAAA;;;;4BAhBN;oCACyC;AAezC,MAAMA;eAOXC,QAAWC,EAAgB;YACzB,CAAAC,QAAKA,CAAAA,MAASC,CAAAA;kBACZC,WAAMA,IAAAA,yBAAWC,EAAAA,IAAAA,oBAAcC;6BAE3BC;8BACAC,SAAcJ,KAAAA;kBAClBG,aAAOA,YAAaN,YAAYO;mCACxBC,IAAAA,uBACJC,EAAAA,gBA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CAAG8B,kCAAQC,EAAAA;;kBAE7CvC,WAAMA,IAAAA,yBAAWC,EAAAA,IAAAA,oBAAcC;kBAC/BsC,uBAAMA,EAAAA;uBAEDpC,eAAMA,SAAeJ;4DACnByC,EAAAA,cAAgBrC;yCACnBoC,IAAAA,CAAAA,UAA0BL;;;mBAI9BK,qBAAOA,IAAAA,CAAAA;;;qBAGXE;;yCACE,IAAA,CAAA5C,QAAKA,CAAAA,cAAS6C,EAAAA,MAAc,QAAAC,kCAA5B,KAAA,IAAA,KAAA,IAAAA,8BAAAC,cAAgCA,CAAAA;sBAAiBC;mBAAoBC;;;;gBAvFvEC,MAAYC,CAAqB;8BAFjC,EAAA,IAAA,EAAA,YAAQnD,KAAR;YAGE,CAAAA,QAAKA,GAAAA;;AAyFT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui-copilot/chat-input-plugins",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
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",