@fluentui-copilot/chat-input-plugins 0.0.5 → 0.0.7
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 +31 -1
- package/CHANGELOG.md +20 -2
- package/dist/index.d.ts +7 -2
- package/lib/BasicFunctionality/SentinelNode.js +5 -0
- package/lib/BasicFunctionality/SentinelNode.js.map +1 -1
- package/lib/ImperativeControl/ImperativeControl.base.js +13 -3
- package/lib/ImperativeControl/ImperativeControl.base.js.map +1 -1
- package/lib-commonjs/BasicFunctionality/SentinelNode.js +5 -0
- package/lib-commonjs/BasicFunctionality/SentinelNode.js.map +1 -1
- package/lib-commonjs/ImperativeControl/ImperativeControl.base.js +12 -2
- package/lib-commonjs/ImperativeControl/ImperativeControl.base.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,37 @@
|
|
|
2
2
|
"name": "@fluentui-copilot/chat-input-plugins",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Fri, 17 May 2024 23:06:15 GMT",
|
|
6
|
+
"tag": "@fluentui-copilot/chat-input-plugins_v0.0.7",
|
|
7
|
+
"version": "0.0.7",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "owcampbe@microsoft.com",
|
|
12
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
13
|
+
"commit": "03d610bd40dea99f4fc8f1c0986e77bb619137aa",
|
|
14
|
+
"comment": "fix: Make SentinelNode aria hidden."
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Wed, 15 May 2024 23:57:34 GMT",
|
|
21
|
+
"tag": "@fluentui-copilot/chat-input-plugins_v0.0.6",
|
|
22
|
+
"version": "0.0.6",
|
|
23
|
+
"comments": {
|
|
24
|
+
"patch": [
|
|
25
|
+
{
|
|
26
|
+
"author": "tristan.watanabe@gmail.com",
|
|
27
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
28
|
+
"commit": "64698dbd45e8203c4db973e866db42f4e74ebeef",
|
|
29
|
+
"comment": "feat: add transform callback to getInputText to enable custom string representation for each node."
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"date": "Wed, 08 May 2024 22:10:20 GMT",
|
|
6
36
|
"tag": "@fluentui-copilot/chat-input-plugins_v0.0.5",
|
|
7
37
|
"version": "0.0.5",
|
|
8
38
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
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 Fri, 17 May 2024 23:06:15 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [0.0.7](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.0.7)
|
|
8
|
+
|
|
9
|
+
Fri, 17 May 2024 23:06:15 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.0.6..@fluentui-copilot/chat-input-plugins_v0.0.7)
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- fix: Make SentinelNode aria hidden. ([PR #1633](https://github.com/microsoft/fluentai/pull/1633) by owcampbe@microsoft.com)
|
|
15
|
+
|
|
16
|
+
## [0.0.6](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.0.6)
|
|
17
|
+
|
|
18
|
+
Wed, 15 May 2024 23:57:34 GMT
|
|
19
|
+
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.0.5..@fluentui-copilot/chat-input-plugins_v0.0.6)
|
|
20
|
+
|
|
21
|
+
### Patches
|
|
22
|
+
|
|
23
|
+
- 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)
|
|
24
|
+
|
|
7
25
|
## [0.0.5](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.0.5)
|
|
8
26
|
|
|
9
|
-
Wed, 08 May 2024 22:
|
|
27
|
+
Wed, 08 May 2024 22:10:20 GMT
|
|
10
28
|
[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
29
|
|
|
12
30
|
### Patches
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EditorConfig } from 'lexical';
|
|
1
2
|
import { EditorState } from 'lexical';
|
|
2
3
|
import { Klass } from 'lexical';
|
|
3
4
|
import { LexicalEditor } from 'lexical';
|
|
@@ -113,7 +114,10 @@ export declare interface IImperativeControlBase {
|
|
|
113
114
|
appendText: (text: string) => void;
|
|
114
115
|
prependText: (text: string) => void;
|
|
115
116
|
insertTextAtCursor: (text: string) => void;
|
|
116
|
-
|
|
117
|
+
/**
|
|
118
|
+
* @param transform will be called for each Lexical node in the input. This enables custom string representation for each node.
|
|
119
|
+
*/
|
|
120
|
+
getInputText: (transform?: (node: LexicalNode) => string) => string;
|
|
117
121
|
scrollToBottom: () => void;
|
|
118
122
|
moveCursor: (location: number) => void;
|
|
119
123
|
}
|
|
@@ -133,7 +137,7 @@ export declare class ImperativeControlBase implements IImperativeControlBase {
|
|
|
133
137
|
appendText(text: string): void;
|
|
134
138
|
prependText(text: string): void;
|
|
135
139
|
insertTextAtCursor(text: string): void;
|
|
136
|
-
getInputText(): string;
|
|
140
|
+
getInputText(transform?: (node: LexicalNode) => string): string;
|
|
137
141
|
scrollToBottom(): void;
|
|
138
142
|
}
|
|
139
143
|
|
|
@@ -156,6 +160,7 @@ export declare class SentinelNode extends TextNode {
|
|
|
156
160
|
constructor(key?: NodeKey);
|
|
157
161
|
static getType(): string;
|
|
158
162
|
static clone(node: SentinelNode): SentinelNode;
|
|
163
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
159
164
|
isToken(): boolean;
|
|
160
165
|
}
|
|
161
166
|
|
|
@@ -7,6 +7,11 @@ export class SentinelNode extends TextNode {
|
|
|
7
7
|
static clone(node) {
|
|
8
8
|
return new SentinelNode(node.__key);
|
|
9
9
|
}
|
|
10
|
+
createDOM(config) {
|
|
11
|
+
const element = super.createDOM(config);
|
|
12
|
+
element.ariaHidden = 'true';
|
|
13
|
+
return element;
|
|
14
|
+
}
|
|
10
15
|
isToken() {
|
|
11
16
|
return true;
|
|
12
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["SentinelNode.ts"],"sourcesContent":["import type { LexicalNode, NodeKey } from '@fluentui-copilot/text-editor';\nimport { TextNode } from '@fluentui-copilot/text-editor';\n\nexport const SENTINEL_VALUE = '\\u200b\\u200c';\n\nexport class SentinelNode extends TextNode {\n constructor(key?: NodeKey) {\n // 2 zero width characters will not be visible in the editor.\n // These also happen to be markers for CIQ to ignore the following content.\n super(SENTINEL_VALUE, key);\n }\n\n static getType() {\n return 'sentinel';\n }\n static clone(node: SentinelNode) {\n return new SentinelNode(node.__key);\n }\n\n isToken() {\n return true;\n }\n}\n\nexport function $createSentinelNode(key?: NodeKey) {\n return new SentinelNode(key);\n}\n\nexport function $isSentinelNode(node: LexicalNode | null): node is SentinelNode {\n return node instanceof SentinelNode;\n}\n"],"names":["TextNode","SENTINEL_VALUE","SentinelNode","getType","clone","node","__key","isToken","constructor","key","$createSentinelNode","$isSentinelNode"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["SentinelNode.ts"],"sourcesContent":["import type { EditorConfig, LexicalNode, NodeKey } from '@fluentui-copilot/text-editor';\nimport { TextNode } from '@fluentui-copilot/text-editor';\n\nexport const SENTINEL_VALUE = '\\u200b\\u200c';\n\nexport class SentinelNode extends TextNode {\n constructor(key?: NodeKey) {\n // 2 zero width characters will not be visible in the editor.\n // These also happen to be markers for CIQ to ignore the following content.\n super(SENTINEL_VALUE, key);\n }\n\n static getType() {\n return 'sentinel';\n }\n static clone(node: SentinelNode) {\n return new SentinelNode(node.__key);\n }\n\n createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n element.ariaHidden = 'true';\n return element;\n }\n\n isToken() {\n return true;\n }\n}\n\nexport function $createSentinelNode(key?: NodeKey) {\n return new SentinelNode(key);\n}\n\nexport function $isSentinelNode(node: LexicalNode | null): node is SentinelNode {\n return node instanceof SentinelNode;\n}\n"],"names":["TextNode","SENTINEL_VALUE","SentinelNode","getType","clone","node","__key","createDOM","config","element","ariaHidden","isToken","constructor","key","$createSentinelNode","$isSentinelNode"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,QAAQ,QAAQ,gCAAgC;AAEzD,OAAO,MAAMC,iBAAiB,eAAe;AAE7C,OAAO,MAAMC,qBAAqBF;IAOhC,OAAOG,UAAU;QACf,OAAO;IACT;IACA,OAAOC,MAAMC,IAAkB,EAAE;QAC/B,OAAO,IAAIH,aAAaG,KAAKC,KAAK;IACpC;IAEAC,UAAUC,MAAoB,EAAe;QAC3C,MAAMC,UAAU,KAAK,CAACF,UAAUC;QAChCC,QAAQC,UAAU,GAAG;QACrB,OAAOD;IACT;IAEAE,UAAU;QACR,OAAO;IACT;IArBAC,YAAYC,GAAa,CAAE;QACzB,6DAA6D;QAC7D,2EAA2E;QAC3E,KAAK,CAACZ,gBAAgBY;IACxB;AAkBF;AAEA,OAAO,SAASC,oBAAoBD,GAAa;IAC/C,OAAO,IAAIX,aAAaW;AAC1B;AAEA,OAAO,SAASE,gBAAgBV,IAAwB;IACtD,OAAOA,gBAAgBH;AACzB"}
|
|
@@ -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
|
-
|
|
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":"
|
|
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,UAAUC,MAAM,CAACC,GAAG,CAACJ,SAASD,aAAaD;oBAC3CI,UAAUG,KAAK,CAACD,GAAG,CAACJ,SAASD,aAAaD;oBAE1ChB,cAAcD,kCAAkCqB;oBAChD;gBACF;gBAEAX,cAAcG;gBACdF,cAAcF,SAASG,KAAK;YAC9B;YAEA,IAAIN,WAAWI,YAAY;gBACzBb,WAAW4B,SAAS;YACtB;QACF;IACF;IACAC,aAAaC,SAAiB,E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C,UAAU;YAAUC,OAAO;QAAM;QAClF;IACF;IAzFAC,YAAYC,MAAqB,CAAE;QAFnC,uBAAQ9C,YAAR,KAAA;QAGE,IAAI,CAACA,QAAQ,GAAG8C;IAClB;AAwFF"}
|
|
@@ -31,6 +31,11 @@ class SentinelNode extends _texteditor.TextNode {
|
|
|
31
31
|
static clone(node) {
|
|
32
32
|
return new SentinelNode(node.__key);
|
|
33
33
|
}
|
|
34
|
+
createDOM(config) {
|
|
35
|
+
const element = super.createDOM(config);
|
|
36
|
+
element.ariaHidden = 'true';
|
|
37
|
+
return element;
|
|
38
|
+
}
|
|
34
39
|
isToken() {
|
|
35
40
|
return true;
|
|
36
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["SentinelNode.ts"],"sourcesContent":["import type { LexicalNode, NodeKey } from '@fluentui-copilot/text-editor';\nimport { TextNode } from '@fluentui-copilot/text-editor';\n\nexport const SENTINEL_VALUE = '\\u200b\\u200c';\n\nexport class SentinelNode extends TextNode {\n constructor(key?: NodeKey) {\n // 2 zero width characters will not be visible in the editor.\n // These also happen to be markers for CIQ to ignore the following content.\n super(SENTINEL_VALUE, key);\n }\n\n static getType() {\n return 'sentinel';\n }\n static clone(node: SentinelNode) {\n return new SentinelNode(node.__key);\n }\n\n isToken() {\n return true;\n }\n}\n\nexport function $createSentinelNode(key?: NodeKey) {\n return new SentinelNode(key);\n}\n\nexport function $isSentinelNode(node: LexicalNode | null): node is SentinelNode {\n return node instanceof SentinelNode;\n}\n"],"names":["$createSentinelNode","$isSentinelNode","SENTINEL_VALUE","SentinelNode","TextNode","getType","clone","node","__key","isToken","constructor","key"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["SentinelNode.ts"],"sourcesContent":["import type { EditorConfig, LexicalNode, NodeKey } from '@fluentui-copilot/text-editor';\nimport { TextNode } from '@fluentui-copilot/text-editor';\n\nexport const SENTINEL_VALUE = '\\u200b\\u200c';\n\nexport class SentinelNode extends TextNode {\n constructor(key?: NodeKey) {\n // 2 zero width characters will not be visible in the editor.\n // These also happen to be markers for CIQ to ignore the following content.\n super(SENTINEL_VALUE, key);\n }\n\n static getType() {\n return 'sentinel';\n }\n static clone(node: SentinelNode) {\n return new SentinelNode(node.__key);\n }\n\n createDOM(config: EditorConfig): HTMLElement {\n const element = super.createDOM(config);\n element.ariaHidden = 'true';\n return element;\n }\n\n isToken() {\n return true;\n }\n}\n\nexport function $createSentinelNode(key?: NodeKey) {\n return new SentinelNode(key);\n}\n\nexport function $isSentinelNode(node: LexicalNode | null): node is SentinelNode {\n return node instanceof SentinelNode;\n}\n"],"names":["$createSentinelNode","$isSentinelNode","SENTINEL_VALUE","SentinelNode","TextNode","getType","clone","node","__key","createDOM","config","element","ariaHidden","isToken","constructor","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IA8BgBA,mBAAAA;eAAAA;;IAIAC,eAAAA;eAAAA;;IA/BHC,cAAAA;eAAAA;;IAEAC,YAAAA;eAAAA;;;4BAJY;AAElB,MAAMD,iBAAiB;AAEvB,MAAMC,qBAAqBC,oBAAAA;WAOhCC,UAAOA;eACL;;WAEFC,MAAOA,IAAMC,EAAkB;eAC7B,IAAOJ,aAAIA,KAAaI,KAAKC;;cAG/BC,MAAUC,EAAoB;cAC5BC,UAAMA,KAAU,CAAAF,UAAMA;gBACtBE,UAAQC,GAAAA;eACRD;;cAGFE;eACE;;gBApBFC,GAAYC,CAAa;qEACvB;mFACA;aACA,CAAAb,gBAAMA;;AAmBV;AAEO,SAASF,oBAAoBe,GAAa;WAC/C,IAAOZ,aAAIA;AACb;AAEO,SAASF,gBAAgBM,IAAwB;WACtDA,gBAAOA;AACT"}
|
|
@@ -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
|
-
|
|
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":"
|
|
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,IAA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