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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.json +55 -1
  2. package/CHANGELOG.md +24 -2
  3. package/dist/index.d.ts +20 -1
  4. package/lib/BasicFunctionality/BasicFunctionality.base.js +106 -8
  5. package/lib/BasicFunctionality/BasicFunctionality.base.js.map +1 -1
  6. package/lib/BasicFunctionality/SentinelNode.js +25 -0
  7. package/lib/BasicFunctionality/SentinelNode.js.map +1 -0
  8. package/lib/BasicFunctionality/index.js +1 -0
  9. package/lib/BasicFunctionality/index.js.map +1 -1
  10. package/lib/ChatInputEntity/ChatInputEntityPlugin.base.js.map +1 -1
  11. package/lib/ChatInputEntity/ChatInputEntityPlugin.types.js.map +1 -1
  12. package/lib/ChatInputEntity/index.js.map +1 -1
  13. package/lib/GhostText/GhostText.base.js +46 -4
  14. package/lib/GhostText/GhostText.base.js.map +1 -1
  15. package/lib/GhostText/index.js.map +1 -1
  16. package/lib/ImperativeControl/ImperativeControl.base.js +4 -2
  17. package/lib/ImperativeControl/ImperativeControl.base.js.map +1 -1
  18. package/lib/ImperativeControl/index.js.map +1 -1
  19. package/lib/ManualGhostText/ManualGhostText.base.js.map +1 -1
  20. package/lib/ManualGhostText/index.js.map +1 -1
  21. package/lib/index.js +1 -1
  22. package/lib/index.js.map +1 -1
  23. package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js +101 -7
  24. package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js.map +1 -1
  25. package/lib-commonjs/BasicFunctionality/SentinelNode.js +48 -0
  26. package/lib-commonjs/BasicFunctionality/SentinelNode.js.map +1 -0
  27. package/lib-commonjs/BasicFunctionality/index.js +1 -0
  28. package/lib-commonjs/BasicFunctionality/index.js.map +1 -1
  29. package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.base.js.map +1 -1
  30. package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.types.js.map +1 -1
  31. package/lib-commonjs/ChatInputEntity/index.js.map +1 -1
  32. package/lib-commonjs/GhostText/GhostText.base.js +45 -3
  33. package/lib-commonjs/GhostText/GhostText.base.js.map +1 -1
  34. package/lib-commonjs/GhostText/index.js.map +1 -1
  35. package/lib-commonjs/ImperativeControl/ImperativeControl.base.js +4 -2
  36. package/lib-commonjs/ImperativeControl/ImperativeControl.base.js.map +1 -1
  37. package/lib-commonjs/ImperativeControl/index.js.map +1 -1
  38. package/lib-commonjs/ManualGhostText/ManualGhostText.base.js.map +1 -1
  39. package/lib-commonjs/ManualGhostText/index.js.map +1 -1
  40. package/lib-commonjs/index.js +12 -0
  41. package/lib-commonjs/index.js.map +1 -1
  42. package/package.json +2 -2
@@ -1,5 +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
4
  export class ImperativeControlBase {
4
5
  moveCursor(location) {
5
6
  this.__editor.update(() => {
@@ -52,12 +53,13 @@ export class ImperativeControlBase {
52
53
  insertTextAtCursor(text) {
53
54
  this.__editor.update(() => {
54
55
  var _$getSelection;
55
- (_$getSelection = $getSelection()) === null || _$getSelection === void 0 ? void 0 : _$getSelection.insertText(text);
56
+ const selection = (_$getSelection = $getSelection()) !== null && _$getSelection !== void 0 ? _$getSelection : $getRoot().selectEnd();
57
+ selection.insertText(text);
56
58
  });
57
59
  }
58
60
  getInputText() {
59
61
  return this.__editor.getEditorState().read(() => {
60
- return $getRoot().getTextContent();
62
+ return $getRoot().getTextContent().replace(SENTINEL_VALUE, '');
61
63
  });
62
64
  }
63
65
  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';\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;AAYvC,OAAO,MAAMC;IAOXC,WAAWC,QAAgB,EAAQ;QACjC,IAAI,CAACC,QAAQ,CAACC,MAAM,CAAC;YACnB,MAAMC,WAAWX,cAAcC;YAE/B,IAAIW,aAAa;YACjB,IAAIC,cAAcF,SAASG,KAAK;YAChC,MAAOF,aAAaJ,YAAYK,YAAa;gBAC3C,MAAME,aACJZ,YAAYU,gBAAgB,CAACA,YAAYG,OAAO,KAC5CH,YAAYI,cAAc,GAAGC,MAAM,GAEnC;gBAEN,IAAIN,aAAaG,cAAcP,UAAU;oBACvC,MAAMW,cAAchB,YAAYU,eAAe,SAAS;oBACxD,MAAMO,cAAcZ,WAAWI;oBAC/B,MAAMS,UAAUR,YAAYS,MAAM;oBAElC,MAAMC,YAAYzB;oBAClByB,UAAUC,MAAM,CAACC,GAAG,CAACJ,SAASD,aAAaD;oBAC3CI,UA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GAAGyC;IAClB;AA2EF"}
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,gCAAgC;AACvC,SAASC,cAAc,QAAQ,wBAAwB;AAYvD,OAAO,MAAMC;IAOXC,WAAWC,QAAgB,EAAQ;QACjC,IAAI,CAACC,QAAQ,CAACC,MAAM,CAAC;YACnB,MAAMC,WAAWZ,cAAcC;YAE/B,IAAIY,aAAa;YACjB,IAAIC,cAAcF,SAASG,KAAK;YAChC,MAAOF,aAAaJ,YAAYK,YAAa;gBAC3C,MAAME,aACJb,YAAY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;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 +1 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":["export * from './ImperativeControl.base';\n"],"names":[],"mappings":"AAAA,cAAc,2BAA2B"}
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export * from './ImperativeControl.base';\n"],"names":[],"rangeMappings":"","mappings":"AAAA,cAAc,2BAA2B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["ManualGhostText.base.ts"],"sourcesContent":["import {\n $createTextNode,\n $getNodeByKey,\n $insertNodes,\n type LexicalEditor,\n type LexicalNode,\n} from '@fluentui-copilot/text-editor';\nimport type { IGhostTextNode } from '../GhostText';\n\nexport interface IManualGhostTextBase<ComponentPropsType> {\n getGhostText: () => string | undefined;\n setGhostText: (text: string, componentProps?: ComponentPropsType) => void;\n commitGhostText: (finalText: string) => void;\n cancelGhostText: () => void;\n}\n\nexport class ManualGhostTextBase<ComponentPropsType> {\n private __editor: LexicalEditor;\n private __nodeKey?: string;\n\n private __id: string;\n private __$isNodeType: (node: LexicalNode | null) => node is IGhostTextNode<ComponentPropsType>;\n private __$createNode: (\n id: string,\n content: string,\n exposeText?: boolean,\n componentProps?: ComponentPropsType,\n ) => IGhostTextNode<ComponentPropsType>;\n\n constructor(\n editor: LexicalEditor,\n id: string,\n $isNodeType: (node: LexicalNode | null) => node is IGhostTextNode<ComponentPropsType>,\n $createNode: (\n id: string,\n content: string,\n exposeText?: boolean,\n componentProps?: ComponentPropsType,\n ) => IGhostTextNode<ComponentPropsType>,\n ) {\n this.__editor = editor;\n this.__id = id;\n this.__$isNodeType = $isNodeType;\n this.__$createNode = $createNode;\n }\n\n getGhostText(): string | undefined {\n return this.__editor.getEditorState().read(() => {\n if (this.__nodeKey) {\n const node = $getNodeByKey(this.__nodeKey);\n if (this.__$isNodeType(node)) {\n return node.__content;\n }\n }\n });\n }\n\n setGhostText(text: string, exposeText?: boolean, componentProps?: ComponentPropsType): void {\n this.__editor.update(\n () => {\n if (this.__nodeKey) {\n const node = $getNodeByKey(this.__nodeKey);\n if (this.__$isNodeType(node)) {\n node.getWritable().__content = text;\n return;\n }\n }\n\n const node = this.__$createNode(this.__id, text, exposeText, componentProps);\n this.__nodeKey = node.getKey();\n $insertNodes([node]);\n node.selectStart();\n },\n { tag: 'historic' },\n );\n }\n\n commitGhostText(finalText: string): void {\n if (this.__nodeKey) {\n this.__editor.update(() => {\n if (this.__nodeKey) {\n const node = $getNodeByKey(this.__nodeKey);\n if (this.__$isNodeType(node)) {\n const textNode = $createTextNode(finalText);\n node.replace(textNode);\n textNode.selectEnd();\n }\n }\n });\n this.__nodeKey = undefined;\n }\n }\n\n cancelGhostText(): void {\n if (this.__nodeKey) {\n this.__editor.update(\n () => {\n if (this.__nodeKey) {\n const node = $getNodeByKey(this.__nodeKey);\n if (this.__$isNodeType(node)) {\n node.remove();\n }\n }\n },\n { tag: 'historic' },\n );\n this.__nodeKey = undefined;\n }\n }\n}\n"],"names":["$createTextNode","$getNodeByKey","$insertNodes","ManualGhostTextBase","getGhostText","__editor","getEditorState","read","__nodeKey","node","__$isNodeType","__content","setGhostText","text","exposeText","componentProps","update","getWritable","__$createNode","__id","getKey","selectStart","tag","commitGhostText","finalText","textNode","replace","selectEnd","undefined","cancelGhostText","remove","constructor","editor","id","$isNodeType","$createNode"],"mappings":";AAAA,SACEA,eAAe,EACfC,aAA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,SAAS,EAAE;YAClB,IAAI,CAACH,QAAQ,CAACW,MAAM,CAClB;gBACE,IAAI,IAAI,CAACR,SAAS,EAAE;oBAClB,MAAMC,OAAOR,cAAc,IAAI,CAACO,SAAS;oBACzC,IAAI,IAAI,CAACE,aAAa,CAACD,OAAO;wBAC5BA,KAAKqB,MAAM;oBACb;gBACF;YACF,GACA;gBAAER,KAAK;YAAW;YAEpB,IAAI,CAACd,SAAS,GAAGoB;QACnB;IACF;IA/EAG,YACEC,MAAqB,EACrBC,EAAU,EACVC,WAAqF,EACrFC,WAKuC,CACvC;QAtBF,uBAAQ9B,YAAR,KAAA;QACA,uBAAQG,aAAR,KAAA;QAEA,uBAAQW,QAAR,KAAA;QACA,uBAAQT,iBAAR,KAAA;QACA,uBAAQQ,iBAAR,KAAA;QAkBE,IAAI,CAACb,QAAQ,GAAG2B;QAChB,IAAI,CAACb,IAAI,GAAGc;QACZ,IAAI,CAACvB,aAAa,GAAGwB;QACrB,IAAI,CAAChB,aAAa,GAAGiB;IACvB;AAiEF"}
1
+ {"version":3,"sources":["ManualGhostText.base.ts"],"sourcesContent":["import {\n $createTextNode,\n $getNodeByKey,\n $insertNodes,\n type LexicalEditor,\n type LexicalNode,\n} from '@fluentui-copilot/text-editor';\nimport type { IGhostTextNode } from '../GhostText';\n\nexport interface IManualGhostTextBase<ComponentPropsType> {\n getGhostText: () => string | undefined;\n setGhostText: (text: string, componentProps?: ComponentPropsType) => void;\n commitGhostText: (finalText: string) => void;\n cancelGhostText: () => void;\n}\n\nexport class ManualGhostTextBase<ComponentPropsType> {\n private __editor: LexicalEditor;\n private __nodeKey?: string;\n\n private __id: string;\n private __$isNodeType: (node: LexicalNode | null) => node is IGhostTextNode<ComponentPropsType>;\n private __$createNode: (\n id: string,\n content: string,\n exposeText?: boolean,\n componentProps?: ComponentPropsType,\n ) => IGhostTextNode<ComponentPropsType>;\n\n constructor(\n editor: LexicalEditor,\n id: string,\n $isNodeType: (node: LexicalNode | null) => node is IGhostTextNode<ComponentPropsType>,\n $createNode: (\n id: string,\n content: string,\n exposeText?: boolean,\n componentProps?: ComponentPropsType,\n ) => IGhostTextNode<ComponentPropsType>,\n ) {\n this.__editor = editor;\n this.__id = id;\n this.__$isNodeType = $isNodeType;\n this.__$createNode = $createNode;\n }\n\n getGhostText(): string | undefined {\n return this.__editor.getEditorState().read(() => {\n if (this.__nodeKey) {\n const node = $getNodeByKey(this.__nodeKey);\n if (this.__$isNodeType(node)) {\n return node.__content;\n }\n }\n });\n }\n\n setGhostText(text: string, exposeText?: boolean, componentProps?: ComponentPropsType): void {\n this.__editor.update(\n () => {\n if (this.__nodeKey) {\n const node = $getNodeByKey(this.__nodeKey);\n if (this.__$isNodeType(node)) {\n node.getWritable().__content = text;\n return;\n }\n }\n\n const node = this.__$createNode(this.__id, text, exposeText, componentProps);\n this.__nodeKey = node.getKey();\n $insertNodes([node]);\n node.selectStart();\n },\n { tag: 'historic' },\n );\n }\n\n commitGhostText(finalText: string): void {\n if (this.__nodeKey) {\n this.__editor.update(() => {\n if (this.__nodeKey) {\n const node = $getNodeByKey(this.__nodeKey);\n if (this.__$isNodeType(node)) {\n const textNode = $createTextNode(finalText);\n node.replace(textNode);\n textNode.selectEnd();\n }\n }\n });\n this.__nodeKey = undefined;\n }\n }\n\n cancelGhostText(): void {\n if (this.__nodeKey) {\n this.__editor.update(\n () => {\n if (this.__nodeKey) {\n const node = $getNodeByKey(this.__nodeKey);\n if (this.__$isNodeType(node)) {\n node.remove();\n }\n }\n },\n { tag: 'historic' },\n );\n this.__nodeKey = undefined;\n }\n }\n}\n"],"names":["$createTextNode","$getNodeByKey","$insertNodes","ManualGhostTextBase","getGhostText","__editor","getEditorState","read","__nodeKey","node","__$isNodeType","__content","setGhostText","text","exposeText","componentProps","update","getWritable","__$createNode","__id","getKey","selectStart","tag","commitGhostText","finalText","textNode","replace","selectEnd","undefined","cancelGhostText","remove","constructor","editor","id","$isNodeType","$createNode"],"rangeMappings":";;;;;;;;;;;;;;;;;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;oBACpB;gBACF;YACF;YACA,IAAI,CAACnB,SAAS,GAAGoB;QACnB;IACF;IAEAC,kBAAwB;QACtB,IAAI,IAAI,CAACrB,SAAS,EAAE;YAClB,IAAI,CAACH,QAAQ,CAACW,MAAM,CAClB;gBACE,IAAI,IAAI,CAACR,SAAS,EAAE;oBAClB,MAAMC,OAAOR,cAAc,IAAI,CAACO,SAAS;oBACzC,IAAI,IAAI,CAACE,aAAa,CAACD,OAAO;wBAC5BA,KAAKqB,MAAM;oBACb;gBACF;YACF,GACA;gBAAER,KAAK;YAAW;YAEpB,IAAI,CAACd,SAAS,GAAGoB;QACnB;IACF;IA/EAG,YACEC,MAAqB,EACrBC,EAAU,EACVC,WAAqF,EACrFC,WAKuC,CACvC;QAtBF,uBAAQ9B,YAAR,KAAA;QACA,uBAAQG,aAAR,KAAA;QAEA,uBAAQW,QAAR,KAAA;QACA,uBAAQT,iBAAR,KAAA;QACA,uBAAQQ,iBAAR,KAAA;QAkBE,IAAI,CAACb,QAAQ,GAAG2B;QAChB,IAAI,CAACb,IAAI,GAAGc;QACZ,IAAI,CAACvB,aAAa,GAAGwB;QACrB,IAAI,CAAChB,aAAa,GAAGiB;IACvB;AAiEF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":["export * from './ManualGhostText.base';\n"],"names":[],"mappings":"AAAA,cAAc,yBAAyB"}
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export * from './ManualGhostText.base';\n"],"names":[],"rangeMappings":"","mappings":"AAAA,cAAc,yBAAyB"}
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { BasicFunctionalityBase } from './BasicFunctionality';
1
+ export { BasicFunctionalityBase, SentinelNode, $createSentinelNode, $isSentinelNode, SENTINEL_VALUE } from './BasicFunctionality';
2
2
  export { ChatInputEntityPluginBase } from './ChatInputEntity';
3
3
  export { GhostTextPluginBase } from './GhostText';
4
4
  export { ImperativeControlBase } from './ImperativeControl';
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":["export { BasicFunctionalityBase } from './BasicFunctionality';\nexport type { IBasicFunctionalityBase } from './BasicFunctionality';\n\nexport { ChatInputEntityPluginBase } from './ChatInputEntity';\nexport type {\n ChatInputEntityData,\n ChatInputEntityPluginProps,\n IChatInputEntityPluginBase,\n IEntityNode,\n} from './ChatInputEntity';\n\nexport { GhostTextPluginBase } from './GhostText';\nexport type { GetGhostTextFunction, IGhostTextNode } from './GhostText';\n\nexport { ImperativeControlBase } from './ImperativeControl';\nexport type { IImperativeControlBase } from './ImperativeControl';\n\nexport { ManualGhostTextBase } from './ManualGhostText';\nexport type { IManualGhostTextBase } from './ManualGhostText';\n"],"names":["BasicFunctionalityBase","ChatInputEntityPluginBase","GhostTextPluginBase","ImperativeControlBase","ManualGhostTextBase"],"mappings":"AAAA,SAASA,sBAAsB,QAAQ,uBAAuB;AAG9D,SAASC,yBAAyB,QAAQ,oBAAoB;AAQ9D,SAASC,mBAAmB,QAAQ,cAAc;AAGlD,SAASC,qBAAqB,QAAQ,sBAAsB;AAG5D,SAASC,mBAAmB,QAAQ,oBAAoB"}
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export {\n BasicFunctionalityBase,\n SentinelNode,\n $createSentinelNode,\n $isSentinelNode,\n SENTINEL_VALUE,\n} from './BasicFunctionality';\nexport type { IBasicFunctionalityBase } from './BasicFunctionality';\n\nexport { ChatInputEntityPluginBase } from './ChatInputEntity';\nexport type {\n ChatInputEntityData,\n ChatInputEntityPluginProps,\n IChatInputEntityPluginBase,\n IEntityNode,\n} from './ChatInputEntity';\n\nexport { GhostTextPluginBase } from './GhostText';\nexport type { GetGhostTextFunction, IGhostTextNode } from './GhostText';\n\nexport { ImperativeControlBase } from './ImperativeControl';\nexport type { IImperativeControlBase } from './ImperativeControl';\n\nexport { ManualGhostTextBase } from './ManualGhostText';\nexport type { IManualGhostTextBase } from './ManualGhostText';\n"],"names":["BasicFunctionalityBase","SentinelNode","$createSentinelNode","$isSentinelNode","SENTINEL_VALUE","ChatInputEntityPluginBase","GhostTextPluginBase","ImperativeControlBase","ManualGhostTextBase"],"rangeMappings":";;;;","mappings":"AAAA,SACEA,sBAAsB,EACtBC,YAAY,EACZC,mBAAmB,EACnBC,eAAe,EACfC,cAAc,QACT,uBAAuB;AAG9B,SAASC,yBAAyB,QAAQ,oBAAoB;AAQ9D,SAASC,mBAAmB,QAAQ,cAAc;AAGlD,SAASC,qBAAqB,QAAQ,sBAAsB;AAG5D,SAASC,mBAAmB,QAAQ,oBAAoB"}
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "BasicFunctionalityBase", {
10
10
  });
11
11
  const _define_property = require("@swc/helpers/_/_define_property");
12
12
  const _texteditor = require("@fluentui-copilot/text-editor");
13
+ const _SentinelNode = require("./SentinelNode");
13
14
  class BasicFunctionalityBase {
14
15
  __enterHandler(event) {
15
16
  const selection = (0, _texteditor.$getSelection)();
@@ -38,8 +39,10 @@ class BasicFunctionalityBase {
38
39
  activateContentCallbacks(onContentChange, onCountChanged) {
39
40
  this.deactivateContentCallbacks();
40
41
  this.__contentChangeCleanup = this.__editor.registerTextContentListener((text)=>{
41
- onContentChange === null || onContentChange === void 0 ? void 0 : onContentChange(text);
42
- onCountChanged === null || onCountChanged === void 0 ? void 0 : onCountChanged(text.length);
42
+ // Remove the sentinel node
43
+ const processed = text.replace(_SentinelNode.SENTINEL_VALUE, '');
44
+ onContentChange === null || onContentChange === void 0 ? void 0 : onContentChange(processed);
45
+ onCountChanged === null || onCountChanged === void 0 ? void 0 : onCountChanged(processed.length);
43
46
  });
44
47
  }
45
48
  deactivateContentCallbacks() {
@@ -47,6 +50,20 @@ class BasicFunctionalityBase {
47
50
  (_this___contentChangeCleanup = (_this = this).__contentChangeCleanup) === null || _this___contentChangeCleanup === void 0 ? void 0 : _this___contentChangeCleanup.call(_this);
48
51
  this.__contentChangeCleanup = undefined;
49
52
  }
53
+ activatePasteCallback(onPaste) {
54
+ this.__pasteHandlerCleanup = this.__editor.registerCommand(_texteditor.PASTE_COMMAND, (event)=>{
55
+ onPaste(event);
56
+ if (event.defaultPrevented) {
57
+ return true;
58
+ }
59
+ return false;
60
+ }, _texteditor.COMMAND_PRIORITY_CRITICAL);
61
+ }
62
+ deactivatePasteCallback() {
63
+ var _this___pasteHandlerCleanup, _this;
64
+ (_this___pasteHandlerCleanup = (_this = this).__pasteHandlerCleanup) === null || _this___pasteHandlerCleanup === void 0 ? void 0 : _this___pasteHandlerCleanup.call(_this);
65
+ this.__pasteHandlerCleanup = undefined;
66
+ }
50
67
  activateTrimWhitespace() {
51
68
  this.deactivateTrimWhitespace();
52
69
  this.__trimWhitespaceCleanup = this.__editor.registerTextContentListener((text)=>{
@@ -71,18 +88,95 @@ class BasicFunctionalityBase {
71
88
  this.__editor.setEditable(!isDisabled);
72
89
  }
73
90
  cleanup() {
74
- var _this___enterHandlerCleanup, _this;
91
+ var _this___baseHandlersCleanup, _this;
75
92
  this.deactivateContentCallbacks();
76
93
  this.deactivateTrimWhitespace();
77
- (_this___enterHandlerCleanup = (_this = this).__enterHandlerCleanup) === null || _this___enterHandlerCleanup === void 0 ? void 0 : _this___enterHandlerCleanup.call(_this);
78
- this.__enterHandlerCleanup = undefined;
94
+ this.deactivatePasteCallback();
95
+ (_this___baseHandlersCleanup = (_this = this).__baseHandlersCleanup) === null || _this___baseHandlersCleanup === void 0 ? void 0 : _this___baseHandlersCleanup.call(_this);
96
+ this.__baseHandlersCleanup = undefined;
79
97
  }
80
98
  constructor(editor){
81
99
  (0, _define_property._)(this, "__editor", void 0);
82
100
  (0, _define_property._)(this, "__contentChangeCleanup", void 0);
83
101
  (0, _define_property._)(this, "__trimWhitespaceCleanup", void 0);
84
- (0, _define_property._)(this, "__enterHandlerCleanup", void 0);
102
+ (0, _define_property._)(this, "__baseHandlersCleanup", void 0);
103
+ (0, _define_property._)(this, "__pasteHandlerCleanup", void 0);
85
104
  this.__editor = editor;
86
- this.__enterHandlerCleanup = this.__editor.registerCommand(_texteditor.KEY_ENTER_COMMAND, this.__enterHandler.bind(this), _texteditor.COMMAND_PRIORITY_CRITICAL);
105
+ this.__baseHandlersCleanup = (0, _texteditor.mergeRegister)(this.__editor.registerCommand(_texteditor.KEY_ENTER_COMMAND, this.__enterHandler.bind(this), _texteditor.COMMAND_PRIORITY_CRITICAL), // Add a sentinel node at the end of the input when there is content.
106
+ // This sentinel node fixes a number of issues.
107
+ // In Safari, Lexical's behaviour of adding <br /> tags to the end of the input when it ends
108
+ // in a decorator node causes cursor location issues: https://github.com/facebook/lexical/issues/4487
109
+ // Otherwise, when a decorator node is the last node in the input, the cursor can't move past it.
110
+ // Adding an invisible text node that doesn't contribute to the content and can't be selected to the end of the input
111
+ // mitigates these issues.
112
+ this.__editor.registerUpdateListener(({ editorState })=>{
113
+ editorState.read(()=>{
114
+ const leaves = (0, _texteditor.$getLeafNodes)((0, _texteditor.$getRoot)());
115
+ if (leaves.length === 0) {
116
+ return;
117
+ }
118
+ const lastNode = leaves[leaves.length - 1];
119
+ const lastNodeKey = lastNode.getKey();
120
+ // If the last node isn't a sentinel, add one
121
+ if (!(0, _SentinelNode.$isSentinelNode)(lastNode)) {
122
+ this.__editor.update(()=>{
123
+ var // We find the node by its key again in case the node was removed before this update runs
124
+ _$getNodeByKey;
125
+ (_$getNodeByKey = (0, _texteditor.$getNodeByKey)(lastNodeKey)) === null || _$getNodeByKey === void 0 ? void 0 : _$getNodeByKey.insertAfter((0, _SentinelNode.$createSentinelNode)());
126
+ }, {
127
+ discrete: true
128
+ });
129
+ return;
130
+ }
131
+ // If the sentinel node is not selected, we're done
132
+ const previous = lastNode.getPreviousSibling();
133
+ if (!previous || !lastNode.isSelected()) {
134
+ return;
135
+ }
136
+ const selection = (0, _texteditor.$getSelection)();
137
+ if (!(0, _texteditor.$isRangeSelection)(selection)) {
138
+ return;
139
+ }
140
+ // If the cursor is inside the sentinel node, move it out (next to the beginning)
141
+ // We allow selection on the boundary of the sentinel in case the adjacent node is a decorator node
142
+ // where selection is ill-defined.
143
+ if (selection.isCollapsed() && selection.anchor.offset > 0) {
144
+ this.__editor.update(()=>{
145
+ var _$getNodeByKey;
146
+ (_$getNodeByKey = (0, _texteditor.$getNodeByKey)(lastNodeKey)) === null || _$getNodeByKey === void 0 ? void 0 : _$getNodeByKey.selectStart();
147
+ }, {
148
+ discrete: true
149
+ });
150
+ return;
151
+ }
152
+ // If the selection is a range which includes the sentinel, modify the range to exclude it
153
+ if (!selection.isCollapsed()) {
154
+ let selectionChanged = false;
155
+ const newSelection = selection.clone();
156
+ if (newSelection.anchor.getNode() === lastNode && newSelection.anchor.offset > 0) {
157
+ newSelection.anchor.set(lastNodeKey, 0, 'text');
158
+ selectionChanged = true;
159
+ }
160
+ if (newSelection.focus.getNode() === lastNode && newSelection.focus.offset > 0) {
161
+ newSelection.focus.set(lastNodeKey, 0, 'text');
162
+ selectionChanged = true;
163
+ }
164
+ if (selectionChanged) {
165
+ this.__editor.update(()=>{
166
+ if ((0, _texteditor.$getNodeByKey)(lastNodeKey) !== null) {
167
+ (0, _texteditor.$setSelection)((0, _texteditor.$normalizeSelection__EXPERIMENTAL)(newSelection));
168
+ }
169
+ }, {
170
+ discrete: true
171
+ });
172
+ }
173
+ }
174
+ });
175
+ }), this.__editor.registerNodeTransform(_SentinelNode.SentinelNode, (node)=>{
176
+ if (!node.getPreviousSibling() || node.getNextSibling()) {
177
+ node.remove();
178
+ return;
179
+ }
180
+ }));
87
181
  }
88
182
  } //# 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.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;g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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,CAACiD,IAAI,CAAC,IAAI,GAAGC,qCAAyB;IACzI;AACF,EACA,mDAAmD"}
1
+ {"version":3,"sources":["BasicFunctionality.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport {\n $createTextNode,\n $getLeafNodes,\n $getNodeByKey,\n $getRoot,\n $getSelection,\n $insertNodes,\n $isRangeSelection,\n $normalizeSelection__EXPERIMENTAL,\n $setSelection,\n COMMAND_PRIORITY_CRITICAL,\n INSERT_PARAGRAPH_COMMAND,\n KEY_ENTER_COMMAND,\n PASTE_COMMAND,\n mergeRegister,\n} from '@fluentui-copilot/text-editor';\nimport { $createSentinelNode, $isSentinelNode, SENTINEL_VALUE, SentinelNode } from './SentinelNode';\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 activatePasteCallback(onPaste: (event: ClipboardEvent) => void): void;\n deactivatePasteCallback(): 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 __baseHandlersCleanup?: () => void;\n private __pasteHandlerCleanup?: () => 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.__baseHandlersCleanup = mergeRegister(\n this.__editor.registerCommand(KEY_ENTER_COMMAND, this.__enterHandler.bind(this), COMMAND_PRIORITY_CRITICAL),\n\n // Add a sentinel node at the end of the input when there is content.\n // This sentinel node fixes a number of issues.\n // In Safari, Lexical's behaviour of adding <br /> tags to the end of the input when it ends\n // in a decorator node causes cursor location issues: https://github.com/facebook/lexical/issues/4487\n // Otherwise, when a decorator node is the last node in the input, the cursor can't move past it.\n // Adding an invisible text node that doesn't contribute to the content and can't be selected to the end of the input\n // mitigates these issues.\n this.__editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n const leaves = $getLeafNodes($getRoot());\n if (leaves.length === 0) {\n return;\n }\n\n const lastNode = leaves[leaves.length - 1];\n const lastNodeKey = lastNode.getKey();\n\n // If the last node isn't a sentinel, add one\n if (!$isSentinelNode(lastNode)) {\n this.__editor.update(\n () => {\n // We find the node by its key again in case the node was removed before this update runs\n $getNodeByKey(lastNodeKey)?.insertAfter($createSentinelNode());\n },\n { discrete: true },\n );\n return;\n }\n\n // If the sentinel node is not selected, we're done\n const previous = lastNode.getPreviousSibling();\n if (!previous || !lastNode.isSelected()) {\n return;\n }\n\n const selection = $getSelection();\n if (!$isRangeSelection(selection)) {\n return;\n }\n\n // If the cursor is inside the sentinel node, move it out (next to the beginning)\n // We allow selection on the boundary of the sentinel in case the adjacent node is a decorator node\n // where selection is ill-defined.\n if (selection.isCollapsed() && selection.anchor.offset > 0) {\n this.__editor.update(\n () => {\n $getNodeByKey(lastNodeKey)?.selectStart();\n },\n { discrete: true },\n );\n return;\n }\n\n // If the selection is a range which includes the sentinel, modify the range to exclude it\n if (!selection.isCollapsed()) {\n let selectionChanged = false;\n const newSelection = selection.clone();\n\n if (newSelection.anchor.getNode() === lastNode && newSelection.anchor.offset > 0) {\n newSelection.anchor.set(lastNodeKey, 0, 'text');\n selectionChanged = true;\n }\n if (newSelection.focus.getNode() === lastNode && newSelection.focus.offset > 0) {\n newSelection.focus.set(lastNodeKey, 0, 'text');\n selectionChanged = true;\n }\n\n if (selectionChanged) {\n this.__editor.update(\n () => {\n if ($getNodeByKey(lastNodeKey) !== null) {\n $setSelection($normalizeSelection__EXPERIMENTAL(newSelection));\n }\n },\n { discrete: true },\n );\n }\n }\n });\n }),\n this.__editor.registerNodeTransform(SentinelNode, node => {\n if (!node.getPreviousSibling() || node.getNextSibling()) {\n node.remove();\n return;\n }\n }),\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 // Remove the sentinel node\n const processed = text.replace(SENTINEL_VALUE, '');\n onContentChange?.(processed);\n onCountChanged?.(processed.length);\n });\n }\n\n deactivateContentCallbacks() {\n this.__contentChangeCleanup?.();\n this.__contentChangeCleanup = undefined;\n }\n\n activatePasteCallback(onPaste: (event: ClipboardEvent) => void) {\n this.__pasteHandlerCleanup = this.__editor.registerCommand(\n PASTE_COMMAND,\n (event: ClipboardEvent) => {\n onPaste(event);\n\n if (event.defaultPrevented) {\n return true;\n }\n\n return false;\n },\n COMMAND_PRIORITY_CRITICAL,\n );\n }\n\n deactivatePasteCallback() {\n this.__pasteHandlerCleanup?.();\n this.__pasteHandlerCleanup = 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.deactivatePasteCallback();\n this.__baseHandlersCleanup?.();\n this.__baseHandlersCleanup = undefined;\n }\n}\n"],"names":["BasicFunctionalityBase","__enterHandler","event","selection","$getSelection","$isRangeSelection","preventDefault","shiftKey","__editor","dispatchCommand","INSERT_PARAGRAPH_COMMAND","insertDefaultValue","defaultValue","update","$insertNodes","onContentChange","onCountChanged","deactivateContentCallbacks","activateContentCallbacks","text","processed","__contentChangeCleanup","SENTINEL_VALUE","registerTextContentListener","length","_this___contentChangeCleanup","_this","call","undefined","__pasteHandlerCleanup","registerCommand","PASTE_COMMAND","activatePasteCallback","onPaste","COMMAND_PRIORITY_CRITICAL","_this___pasteHandlerCleanup","deactivatePasteCallback","deactivateTrimWhitespace","activateTrimWhitespace","__trimWhitespaceCleanup","trim","forEach","node","remove","_this___trimWhitespaceCleanup","isDisabled","setIsDisabled","cleanup","__baseHandlersCleanup","_this___baseHandlersCleanup","editor","constructor","registerUpdateListener","editorState","read","leaves","$getLeafNodes","$getRoot","$isSentinelNode","lastNode","$getNodeByKey","lastNodeKey","_$getNodeByKey","insertAfter","$createSentinelNode","getPreviousSibling","selectStart","isCollapsed","newSelection","anchor","selectionChanged","getNode","offset","focus","$setSelection","discrete","registerNodeTransform","SentinelNode","getNextSibling"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BA+BaA;;;eAAAA;;;;4BAfN;8BAC4E;AAc5E,MAAMA;mBAOHC,KAAeC,EAAoB;cACzCC,YAAMA,IAAAA,yBAAYC;YAClB,CAAAC,IAAAA,6BAAKA,EAAAA,YAAkBF;mBACrB;;YAGFD,UAAIA,MAAU;mBACZ;;cAGFA,cAAMI;YAENJ,MAAIA,QAAMK,EAAAA;mBACR,IAAA,CAAAC,QAAYA,CAAAA,eAASC,CAAAA,oCAAgBC,EAAAA;;0DAGvC;eACA;;uBAkGFC,YAAmBC,EAAoB;YACrCA,cAAIA;yBACGJ,CAAAA,MAASK,CAAAA;4CACZC,EAAAA;oBAAAA,IAAAA,2BAAa,EAAAF;iBAAA;;;;6BAEjBG,eAAA,EAAAC,cAAA,EAAA;QACF,IAAA,CAAAC,0BAAA;QAEAC,IAAAA,CAAAA,sBACEH,GAAAA,IAAAA,CAAAA,QACAC,CAAAA,2BACA,CAAAG,CAAAA;uCACKF;kBACDG,YAACC,KAAAA,OAAsB,CAAAC,4BAAgB,EAACC;gCAC1C,QAAAR,oBAA2B,KAAA,IAAA,KAAA,IAAAA,gBAAAK;+BACrBA,QAAYD,mBAAaG,KAAAA,IAAgB,K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AhD,MAAA,CAAA;;0CAAiB+C,IAAAA,yBAAA,EAAAC,YAAA,MAAA,QAAAC,mBAAA,KAAA,IAAA,KAAA,IAAAA,eAAAI,WAAA;;kCAGrB;;;;0GAKsC;+BAEpCC,WAAIC,IAAaC;2CACfD;yCACAE,UAAAA,KAAmB;qCACrBD,MAAA,CAAAE,OAAA,OAAAZ,YAAAS,aAAAC,MAAA,CAAAG,MAAA,GAAA,GAAA;qCACIJ,MAAAA,CAAAA,GAAAA,CAAAA,aAAmBG,GAAO;2CAC5BH;;qCAEFK,KAAA,CAAAF,OAAA,OAAAZ,YAAAS,aAAAK,KAAA,CAAAD,MAAA,GAAA,GAAA;qCAEIF,KAAAA,CAAAA,GAAAA,CAAAA,aAAkB,GAAA;2CACf9D;;0CAGCkE;4CACF,CAAA;6DAEF,EAAAb,iBAAA,MAAA;6DAAEc,EAAAA,IAAAA,6CAAU,EAAAP;;;sCAGlB;wBACF;oBACF;;;yBAII,CAAAQ,qBAAA,CAAAC,0BAAA,EAAAnC,CAAAA;sBACFuB,kBAAA,MAAAvB,KAAAoC,cAAA,IAAA;gBACFpC,KAAAC,MAAA;gBAEJ;YAoFF"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ $createSentinelNode: function() {
13
+ return $createSentinelNode;
14
+ },
15
+ $isSentinelNode: function() {
16
+ return $isSentinelNode;
17
+ },
18
+ SENTINEL_VALUE: function() {
19
+ return SENTINEL_VALUE;
20
+ },
21
+ SentinelNode: function() {
22
+ return SentinelNode;
23
+ }
24
+ });
25
+ const _texteditor = require("@fluentui-copilot/text-editor");
26
+ const SENTINEL_VALUE = '\u200b\u200c';
27
+ class SentinelNode extends _texteditor.TextNode {
28
+ static getType() {
29
+ return 'sentinel';
30
+ }
31
+ static clone(node) {
32
+ return new SentinelNode(node.__key);
33
+ }
34
+ isToken() {
35
+ return true;
36
+ }
37
+ constructor(key){
38
+ // 2 zero width characters will not be visible in the editor.
39
+ // These also happen to be markers for CIQ to ignore the following content.
40
+ super(SENTINEL_VALUE, key);
41
+ }
42
+ }
43
+ function $createSentinelNode(key) {
44
+ return new SentinelNode(key);
45
+ }
46
+ function $isSentinelNode(node) {
47
+ return node instanceof SentinelNode;
48
+ } //# sourceMappingURL=SentinelNode.js.map
@@ -0,0 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAwBgBA,mBAAAA;eAAAA;;IAIAC,eAAAA;eAAAA;;IAzBHC,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;eACE;;gBAdFC,GAAYC,CAAa;qEACvB;mFACA;aACA,CAAAT,gBAAMA;;AAaV;AAEO,SAASF,oBAAoBW,GAAa;WAC/C,IAAOR,aAAIA;AACb;AAEO,SAASF,gBAAgBM,IAAwB;WACtDA,gBAAOA;AACT"}
@@ -4,4 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  const _export_star = require("@swc/helpers/_/_export_star");
6
6
  _export_star._(require("./BasicFunctionality.base"), exports);
7
+ _export_star._(require("./SentinelNode"), exports);
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.js"],"sourcesContent":["export * from './BasicFunctionality.base';\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;;uBAAc;CACd,iCAAiC"}
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export * from './BasicFunctionality.base';\nexport * from './SentinelNode';\n"],"names":[],"rangeMappings":";;;;;;","mappings":";;;;;uBAAc;uBACA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["ChatInputEntityPlugin.base.js"],"sourcesContent":["import { _ as _define_property } from \"@swc/helpers/_/_define_property\";\nimport { $createParagraphNode, $createTextNode, $getNodeByKey, $getSelection, $insertNodes, $isDecoratorNode, $isRangeSelection, $isRootOrShadowRoot, $nodesOfType, $wrapNodeInElement, COMMAND_PRIORITY_CRITICAL, DELETE_CHARACTER_COMMAND, mergeRegister } from '@fluentui-copilot/text-editor';\nexport class ChatInputEntityPluginBase {\n cleanup() {\n this._cleanup();\n }\n insertChatInputEntity(props) {\n let key = undefined;\n this.__editor.update(() => {\n const {\n text,\n data,\n entityProps\n } = props;\n const entityNode = this.__$createNode(this.__id, text, data, entityProps);\n $insertNodes([entityNode]);\n entityNode.selectEnd();\n if ($isRootOrShadowRoot(entityNode.getParentOrThrow())) {\n $wrapNodeInElement(entityNode, $createParagraphNode).selectEnd();\n }\n key = entityNode.getKey();\n });\n return key;\n }\n removeChatInputEntity(keyOrPredicate) {\n this.__editor.update(() => {\n if (typeof keyOrPredicate === 'function') {\n $nodesOfType(this.__nodeClass).filter((node, i) => node.__pluginId === this.__id && keyOrPredicate(node.getEntityData(), i)).forEach(node => node.remove());\n } else {\n var _$getNodeByKey;\n (_$getNodeByKey = $getNodeByKey(keyOrPredicate)) === null || _$getNodeByKey === void 0 ? void 0 : _$getNodeByKey.remove();\n }\n });\n }\n updateChatInputEntityProps(keyOrPredicate, props) {\n const updateNode = node => {\n const newProps = typeof props === 'function' ? props(node.getEntityData()) : props;\n node.updateEntityData(newProps);\n };\n this.__editor.update(() => {\n if (typeof keyOrPredicate === 'function') {\n $nodesOfType(this.__nodeClass).filter((node, i) => node.__pluginId === this.__id && keyOrPredicate(node.getEntityData(), i)).forEach(updateNode);\n } else {\n const node = $getNodeByKey(keyOrPredicate);\n if (node) {\n updateNode(node);\n }\n }\n }, {\n tag: 'historic'\n });\n }\n getActiveEntities() {\n return this.__editor.getEditorState().read(() => $nodesOfType(this.__nodeClass).filter(node => node.__pluginId === this.__id).map(node => node.getEntityData()));\n }\n constructor(editor, id, nodeClass, $createNode, $isChatInputEntityNode, onChatInputEntityAdded, onChatInputEntityDeleted) {\n _define_property(this, \"__nodeClass\", void 0);\n _define_property(this, \"__editor\", void 0);\n _define_property(this, \"__id\", void 0);\n _define_property(this, \"__deleteDirection\", null);\n _define_property(this, \"__$createNode\", void 0);\n _define_property(this, \"_cleanup\", void 0);\n this.__$createNode = $createNode;\n this.__editor = editor;\n this.__id = id;\n this.__nodeClass = nodeClass;\n this._cleanup = mergeRegister(\n // Keep track of delete direction so we know where to put the selection after adding back a space\n editor.registerCommand(DELETE_CHARACTER_COMMAND, isBackward => {\n this.__deleteDirection = isBackward ? 'backward' : 'forward';\n return false;\n }, COMMAND_PRIORITY_CRITICAL),\n // Always maintain a space before, after, and between entities in order for selection to work properly\n editor.registerNodeTransform(this.__nodeClass, node => {\n const nextSibling = node.getNextSibling();\n if (!nextSibling || $isDecoratorNode(nextSibling)) {\n const selection = $getSelection();\n // If selection is between the two nodes, that means the user is trying to delete the space\n // If they deleted to the left, we should move the cursor to the end of the entity\n // If they delete to the right, we should move the cursor to the end of the newly added space\n // This mimics changing the delete into a cursor move action\n const shouldMoveSelection = selection && $isRangeSelection(selection) && selection.isCollapsed() && selection.anchor.offset === node.getIndexWithinParent() + 1;\n const text = $createTextNode(' ');\n node.insertAfter(text);\n if (shouldMoveSelection) {\n if (this.__deleteDirection === 'forward') {\n text.selectEnd();\n } else {\n node.selectEnd();\n }\n }\n }\n // In the case the entity is the first node, we need a space before it.\n if (!node.getPreviousSibling()) {\n const text = $createTextNode(' ');\n node.insertBefore(text);\n }\n }), onChatInputEntityAdded || onChatInputEntityDeleted ? editor.registerMutationListener(this.__nodeClass, (nodes, payload) => {\n for (const [nodeKey, mutation] of nodes) {\n if (onChatInputEntityDeleted && mutation === 'destroyed') {\n payload.prevEditorState.read(() => {\n const node = $getNodeByKey(nodeKey);\n if ($isChatInputEntityNode(node) && node.__pluginId === id) {\n onChatInputEntityDeleted(node.getEntityData());\n }\n });\n } else if (onChatInputEntityAdded && mutation === 'created') {\n editor.getEditorState().read(() => {\n const node = $getNodeByKey(nodeKey);\n if ($isChatInputEntityNode(node) && node.__pluginId === id) {\n onChatInputEntityAdded(node.getEntityData());\n }\n });\n }\n }\n }) : noop);\n }\n}\nfunction noop() {\n return;\n}\n//# sourceMappingURL=ChatInputEntityPlugin.base.js.map"],"names":["ChatInputEntityPluginBase","cleanup","_cleanup","insertChatInputEntity","props","key","undefined","__editor","update","text","data","entityProps","entityNode","__$createNode","__id","$insertNodes","selectEnd","$isRootOrShadowRoot","getParentOrThrow","$wrapNodeInElement","$createParagraphNode","getKey","removeChatInputEntity","keyOrPredicate","$nodesOfType","__nodeClass","filter","node","i","__pluginId","getEntityData","forEach","remove","_$getNodeByKey","$getNodeByKey","updateChatInputEntityProps","updateNode","newProps","updateEntityData","tag","getActiveEntities","getEditorState","read","map","constructor","editor","id","nodeClass","$createNode","$isChatInputEntityNode","onChatInputEntityAdded","onChatInputEntityDeleted","_define_property","mergeRegister","registerCommand","DELETE_CHARACTER_COMMAND","isBackward","__deleteDirection","COMMAND_PRIORITY_CRITICAL","registerNodeTransform","nextSibling","getNextSibling","$isDecoratorNode","selection","$getSelection","shouldMoveSelection","$isRangeSelection","isCollapsed","anchor","offset","getIndexWithinParent","$createTextNode","insertAfter","getPreviousSibling","insertBefore","registerMutationListener","nodes","payload","nodeKey","mutation","prevEditorState","noop"],"mappings":";;;;+BAEaA;;;eAAAA;;;iCAFyB;4BAC4N;AAC3P,MAAMA;IACXC,UAAU;QACR,IAAI,CAACC,QAAQ;IACf;IACAC,sBAAsBC,KAAK,EAAE;QAC3B,IAAIC,MAAMC;QACV,IAAI,CAACC,QAAQ,CAACC,MAAM,CAAC;YACnB,MAAM,EACJC,IAAI,EACJC,IAAI,EACJC,WAAW,EACZ,GAAGP;YACJ,MAAMQ,aAAa,IAAI,CAACC,aAAa,CAAC,IAAI,CAACC,IAAI,EAAEL,MAAMC,MAAMC;YAC7DI,IAAAA,wBAAY,EAAC;gBAACH;aAAW;YACzBA,WAAWI,SAAS;YACpB,IAAIC,IAAAA,+BAAmB,EAACL,WAAWM,gBAAgB,KAAK;gBACtDC,IAAAA,8BAAkB,EAACP,YAAYQ,gCAAoB,EAAEJ,SAAS;YAChE;YACAX,MAAMO,WAAWS,MAAM;QACzB;QACA,OAAOhB;IACT;IACAiB,sBAAsBC,cAAc,EAAE;QACpC,IAAI,CAAChB,QAAQ,CAACC,MAAM,CAAC;YACnB,IAAI,OAAOe,mBAAmB,YAAY;gBACxCC,IAAAA,wBAAY,EAAC,IAAI,CAACC,WAAW,EAAEC,MAAM,CAAC,CAACC,MAAMC,IAAMD,KAAKE,UAAU,KAAK,IAAI,CAACf,IAAI,IAAIS,eAAeI,KAAKG,aAAa,IAAIF,IAAIG,OAAO,CAACJ,CAAAA,OAAQA,KAAKK,MAAM;YAC1J,OAAO;gBACL,IAAIC;gBACHA,CAAAA,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;YACpB;QACF,IAAIyC,0BAA0BC,2BAA2BN,OAAO8B,wBAAwB,CAAC,IAAI,CAAClD,WAAW,EAAE,CAACmD,OAAOC;YACjH,KAAK,MAAM,CAACC,SAASC,SAAS,IAAIH,MAAO;gBACvC,IAAIzB,4BAA4B4B,aAAa,aAAa;oBACxDF,QAAQG,eAAe,CAACtC,IAAI,CAAC;wBAC3B,MAAMf,OAAOO,IAAAA,yBAAa,EAAC4C;wBAC3B,IAAI7B,uBAAuBtB,SAASA,KAAKE,UAAU,KAAKiB,IAAI;4BAC1DK,yBAAyBxB,KAAKG,aAAa;wBAC7C;oBACF;gBACF,OAAO,IAAIoB,0BAA0B6B,aAAa,WAAW;oBAC3DlC,OAAOJ,cAAc,GAAGC,IAAI,CAAC;wBAC3B,MAAMf,OAAOO,IAAAA,yBAAa,EAAC4C;wBAC3B,IAAI7B,uBAAuBtB,SAASA,KAAKE,UAAU,KAAKiB,IAAI;4BAC1DI,uBAAuBvB,KAAKG,aAAa;wBAC3C;oBACF;gBACF;YACF;QACF,KAAKmD;IACP;AACF;AACA,SAASA;IACP;AACF,EACA,sDAAsD"}
1
+ {"version":3,"sources":["ChatInputEntityPlugin.base.ts"],"sourcesContent":["import type { LexicalEditor, LexicalNode, NodeKey, Klass } from '@fluentui-copilot/text-editor';\nimport {\n $createParagraphNode,\n $createTextNode,\n $getNodeByKey,\n $getSelection,\n $insertNodes,\n $isDecoratorNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n $nodesOfType,\n $wrapNodeInElement,\n COMMAND_PRIORITY_CRITICAL,\n DELETE_CHARACTER_COMMAND,\n mergeRegister,\n} from '@fluentui-copilot/text-editor';\nimport type { ChatInputEntityData, IChatInputEntityPluginBase, IEntityNode } from './ChatInputEntityPlugin.types';\n\nexport class ChatInputEntityPluginBase<\n ExtraDataType,\n NodePropsType,\n NodeType extends IEntityNode<ExtraDataType, NodePropsType>,\n> implements IChatInputEntityPluginBase<ExtraDataType, NodePropsType>\n{\n private __nodeClass: Klass<NodeType>;\n private __editor: LexicalEditor;\n private __id: string;\n\n private __deleteDirection: 'forward' | 'backward' | null = null;\n private __$createNode: (\n pluginId: string,\n text: string,\n data?: ExtraDataType,\n entityProps?: NodePropsType,\n key?: NodeKey,\n ) => NodeType;\n\n private _cleanup: () => void;\n\n cleanup() {\n this._cleanup();\n }\n\n constructor(\n editor: LexicalEditor,\n id: string,\n nodeClass: Klass<NodeType>,\n $createNode: (\n pluginId: string,\n text: string,\n data?: ExtraDataType,\n entityProps?: NodePropsType,\n key?: NodeKey,\n ) => NodeType,\n $isChatInputEntityNode: (node: LexicalNode | null) => node is NodeType,\n onChatInputEntityAdded?: (entity: ChatInputEntityData<ExtraDataType, NodePropsType>) => void,\n onChatInputEntityDeleted?: (entity: ChatInputEntityData<ExtraDataType, NodePropsType>) => void,\n ) {\n this.__$createNode = $createNode;\n this.__editor = editor;\n this.__id = id;\n this.__nodeClass = nodeClass;\n\n this._cleanup = mergeRegister(\n // Keep track of delete direction so we know where to put the selection after adding back a space\n editor.registerCommand(\n DELETE_CHARACTER_COMMAND,\n isBackward => {\n this.__deleteDirection = isBackward ? 'backward' : 'forward';\n return false;\n },\n COMMAND_PRIORITY_CRITICAL,\n ),\n // Always maintain a space before, after, and between entities in order for selection to work properly\n editor.registerNodeTransform(this.__nodeClass, node => {\n const nextSibling = node.getNextSibling();\n if (!nextSibling || $isDecoratorNode(nextSibling)) {\n const selection = $getSelection();\n\n // If selection is between the two nodes, that means the user is trying to delete the space\n // If they deleted to the left, we should move the cursor to the end of the entity\n // If they delete to the right, we should move the cursor to the end of the newly added space\n // This mimics changing the delete into a cursor move action\n const shouldMoveSelection =\n selection &&\n $isRangeSelection(selection) &&\n selection.isCollapsed() &&\n selection.anchor.offset === node.getIndexWithinParent() + 1;\n const text = $createTextNode(' ');\n node.insertAfter(text);\n if (shouldMoveSelection) {\n if (this.__deleteDirection === 'forward') {\n text.selectEnd();\n } else {\n node.selectEnd();\n }\n }\n }\n\n // In the case the entity is the first node, we need a space before it.\n if (!node.getPreviousSibling()) {\n const text = $createTextNode(' ');\n node.insertBefore(text);\n }\n }),\n onChatInputEntityAdded || onChatInputEntityDeleted\n ? editor.registerMutationListener(this.__nodeClass, (nodes, payload) => {\n for (const [nodeKey, mutation] of nodes) {\n if (onChatInputEntityDeleted && mutation === 'destroyed') {\n payload.prevEditorState.read(() => {\n const node = $getNodeByKey(nodeKey);\n if ($isChatInputEntityNode(node) && node.__pluginId === id) {\n onChatInputEntityDeleted(node.getEntityData());\n }\n });\n } else if (onChatInputEntityAdded && mutation === 'created') {\n editor.getEditorState().read(() => {\n const node = $getNodeByKey(nodeKey);\n if ($isChatInputEntityNode(node) && node.__pluginId === id) {\n onChatInputEntityAdded(node.getEntityData());\n }\n });\n }\n }\n })\n : noop,\n );\n }\n insertChatInputEntity(props: ChatInputEntityData<ExtraDataType, NodePropsType>): string | undefined {\n let key: string | undefined = undefined;\n this.__editor.update(() => {\n const { text, data, entityProps } = props;\n\n const entityNode = this.__$createNode(this.__id, text, data, entityProps);\n\n $insertNodes([entityNode]);\n entityNode.selectEnd();\n if ($isRootOrShadowRoot(entityNode.getParentOrThrow())) {\n $wrapNodeInElement(entityNode, $createParagraphNode).selectEnd();\n }\n\n key = entityNode.getKey();\n });\n\n return key;\n }\n removeChatInputEntity(\n keyOrPredicate: string | ((entity: ChatInputEntityData<ExtraDataType, NodePropsType>, i: number) => boolean),\n ) {\n this.__editor.update(() => {\n if (typeof keyOrPredicate === 'function') {\n $nodesOfType(this.__nodeClass)\n .filter((node, i) => node.__pluginId === this.__id && keyOrPredicate(node.getEntityData(), i))\n .forEach(node => node.remove());\n } else {\n $getNodeByKey(keyOrPredicate)?.remove();\n }\n });\n }\n updateChatInputEntityProps(\n keyOrPredicate: string | ((entity: ChatInputEntityData<ExtraDataType, NodePropsType>, i: number) => boolean),\n props:\n | ChatInputEntityData<ExtraDataType, NodePropsType>\n | ((\n oldProps: ChatInputEntityData<ExtraDataType, NodePropsType>,\n ) => ChatInputEntityData<ExtraDataType, NodePropsType>),\n ) {\n const updateNode = (node: NodeType) => {\n const newProps = typeof props === 'function' ? props(node.getEntityData()) : props;\n node.updateEntityData(newProps);\n };\n\n this.__editor.update(\n () => {\n if (typeof keyOrPredicate === 'function') {\n $nodesOfType(this.__nodeClass)\n .filter((node, i) => node.__pluginId === this.__id && keyOrPredicate(node.getEntityData(), i))\n .forEach(updateNode);\n } else {\n const node = $getNodeByKey<NodeType>(keyOrPredicate);\n if (node) {\n updateNode(node);\n }\n }\n },\n { tag: 'historic' },\n );\n }\n\n getActiveEntities(): ChatInputEntityData<ExtraDataType, NodePropsType>[] {\n return this.__editor.getEditorState().read(() =>\n $nodesOfType(this.__nodeClass)\n .filter(node => node.__pluginId === this.__id)\n .map(node => node.getEntityData()),\n );\n }\n}\n\nfunction noop() {\n return;\n}\n"],"names":["ChatInputEntityPluginBase","cleanup","_cleanup","insertChatInputEntity","props","key","__editor","update","$insertNodes","entityNode","selectEnd","__id","text","data","entityProps","$isRootOrShadowRoot","$wrapNodeInElement","getParentOrThrow","$createParagraphNode","removeChatInputEntity","keyOrPredicate","$nodesOfType","$getNodeByKey","_$getNodeByKey","remove","updateChatInputEntityProps","updateEntityData","newProps","node","getEntityData","updateNode","tag","getActiveEntities","constructor","editor","id","$createNode","$isChatInputEntityNode","onChatInputEntityAdded","onChatInputEntityDeleted","map","nodeClass","__deleteDirection","__$createNode","__nodeClass","registerCommand","COMMAND_PRIORITY_CRITICAL","isBackward","registerNodeTransform","$isDecoratorNode","$getSelection","getNextSibling","nextSibling","isCollapsed","$isRangeSelection","selection","anchor","offset","getIndexWithinParent","$createTextNode","mutation","nodeKey","read","getEditorState","__pluginId","noop"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAkBaA;;;eA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AA;gCACP,CAAAE;yCACOF;8CACP,KAAA,WAAA;6BACFA,SAAA;2BACF;wBAEAkB,KAAAlB,SAAA;;;;mFAIA;gBACF,CAAAkB,KACAU,kBAAAA,IAA0BC;sBAEpB3B,OAAK+C,IAAAA,2BAAgBC,EAAAA;iCACfrB,CAAAA;;sCAEMX,2BAAqBiC,OAAAA,wBAAAA,CAAAA,IAAAA,CAAAA,WAAAA,EAAAA,CAAAA,OAAAA;iCAC3BD,SAAIvB,IAAAA,MAAAA;gDACFE,aAAyBX,aAAKC;2CAChC,CAAAiC,IAAA,CAAA;qCACFxC,IAAAA,yBAAA,EAAAuC;4BACFxB,uBAAWC,SAAAA,KAA0BsB,UAAAA,KAAazB,IAAA;qDACzC4B,KAAiBD,aAAK;;;qDAGzBxB,aAA4BT,WAAa;yCAC3C,GAAAiC,IAAA,CAAA;qCACFxC,IAAAA,yBAAA,EAAAuC;4BACFxB,uBAAAT,SAAAA,KAAAoC,UAAA,KAAA7B,IAAA;4BACFG,uBAAAV,KAAAC,aAAA;wBACF;oBAGR;gBAqEF;YAEA;QACE,KAAAoC;IACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["ChatInputEntityPlugin.types.js"],"sourcesContent":["export {};\n//# sourceMappingURL=ChatInputEntityPlugin.types.js.map"],"names":[],"mappings":";;;;CACA,uDAAuD"}
1
+ {"version":3,"sources":["ChatInputEntityPlugin.types.ts"],"sourcesContent":["import type { LexicalNode } from '@fluentui-copilot/text-editor';\n\nexport type ChatInputEntityData<ExtraDataType, NodePropsType> = {\n // Represents the string content of the entity that will returned inside the ChatInput's text content\n text: string;\n // Props to pass to the component rendered by the node\n // By default, `text` will be used as the entity's text content.\n // If entityProps contains information for rendering children, that will take priority\n entityProps?: NodePropsType;\n // Optional extra data that can be associated with the entity\n data?: ExtraDataType;\n};\n\nexport type ChatInputEntityPluginProps<ExtraDataType, NodePropsType> = {\n // An identifier for an instance of the ChatInputEntityPlugin\n // Only entities created by this instance of the plugin will be handled by it\n id: string;\n onChatInputEntityAdded?: (entity: ChatInputEntityData<ExtraDataType, NodePropsType>) => void;\n onChatInputEntityDeleted?: (entity: ChatInputEntityData<ExtraDataType, NodePropsType>) => void;\n};\n\n/**\n * A lexical node representing an entity should conform to this interface\n */\nexport interface IEntityNode<ExtraDataType, NodePropsType> extends LexicalNode {\n getEntityData: () => ChatInputEntityData<ExtraDataType, NodePropsType>;\n updateEntityData: (data: ChatInputEntityData<ExtraDataType, NodePropsType>) => void;\n __pluginId: string;\n}\n\nexport interface IChatInputEntityPluginBase<ExtraDataType, NodePropsType> {\n // Inserts a new entity and returns its key, to be used by removeChatInputEntity or updateChatInputEntityProps\n insertChatInputEntity: (props: ChatInputEntityData<ExtraDataType, NodePropsType>) => string | undefined;\n // Removes an entity by its key, or removes all entities that match a predicate function\n removeChatInputEntity: (\n keyOrPredicate: string | ((entity: ChatInputEntityData<ExtraDataType, NodePropsType>, i: number) => boolean),\n ) => void;\n // Updates an entity by its key, or removes all entities that match a predicate function\n updateChatInputEntityProps: (\n keyOrPredicate: string | ((entity: ChatInputEntityData<ExtraDataType, NodePropsType>, i: number) => boolean),\n props:\n | ChatInputEntityData<ExtraDataType, NodePropsType>\n | ((\n oldProps: ChatInputEntityData<ExtraDataType, NodePropsType>,\n ) => ChatInputEntityData<ExtraDataType, NodePropsType>),\n ) => void;\n getActiveEntities: () => ChatInputEntityData<ExtraDataType, NodePropsType>[];\n}\n"],"names":[],"rangeMappings":"","mappings":""}
@@ -1 +1 @@
1
- {"version":3,"sources":["index.js"],"sourcesContent":["export * from './ChatInputEntityPlugin.types';\nexport * from './ChatInputEntityPlugin.base';\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;;uBAAc;uBACA;CACd,iCAAiC"}
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export * from './ChatInputEntityPlugin.types';\nexport * from './ChatInputEntityPlugin.base';\n"],"names":[],"rangeMappings":";;;;;;","mappings":";;;;;uBAAc;uBACA"}
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "GhostTextPluginBase", {
10
10
  });
11
11
  const _define_property = require("@swc/helpers/_/_define_property");
12
12
  const _texteditor = require("@fluentui-copilot/text-editor");
13
+ const _BasicFunctionality = require("../BasicFunctionality");
13
14
  class GhostTextPluginBase {
14
15
  cleanup() {
15
16
  var _this___cleanup, _this;
@@ -43,12 +44,14 @@ class GhostTextPluginBase {
43
44
  let ghostTextNodeKey = null;
44
45
  let lastText = undefined;
45
46
  let justRemovedGhostText = false;
47
+ let justAddedGhostText = false;
46
48
  function $clearGhostText() {
47
49
  const ghostTextNode = ghostTextNodeKey !== null ? (0, _texteditor.$getNodeByKey)(ghostTextNodeKey) : null;
48
50
  ghostTextNodeKey = null;
49
51
  lastText = undefined;
50
52
  if (ghostTextNode && ghostTextNode.isAttached()) {
51
53
  ghostTextNode.remove();
54
+ justRemovedGhostText = true;
52
55
  }
53
56
  }
54
57
  function handleGhostTextNodeTransform(node) {
@@ -67,7 +70,6 @@ class GhostTextPluginBase {
67
70
  $clearGhostText();
68
71
  const selection = (0, _texteditor.$getSelection)();
69
72
  if (!text || !selection) {
70
- justRemovedGhostText = true;
71
73
  return;
72
74
  }
73
75
  const selectionCopy = selection.clone();
@@ -78,18 +80,58 @@ class GhostTextPluginBase {
78
80
  node
79
81
  ]);
80
82
  (0, _texteditor.$setSelection)(selectionCopy);
83
+ justAddedGhostText = true;
84
+ justRemovedGhostText = false;
81
85
  }, {
82
86
  tag: 'historic'
83
87
  });
84
88
  };
85
89
  const handleUpdate = (props)=>{
86
90
  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) {
91
+ // If this update was caused by adding or deleting ghost text, don't recheck the ghost text function until a subsequent update
92
+ if (justRemovedGhostText || justAddedGhostText) {
89
93
  justRemovedGhostText = false;
94
+ justAddedGhostText = false;
90
95
  return;
91
96
  }
92
97
  editorState.read(()=>{
98
+ // We only update the ghost text if the user selection is inside the input
99
+ const selection = (0, _texteditor.$getSelection)();
100
+ if (!(0, _texteditor.$getSelection)()) {
101
+ return;
102
+ }
103
+ if ((0, _texteditor.$isRangeSelection)(selection) && selection.isCollapsed()) {
104
+ var _selectedNode_getPreviousSibling;
105
+ var _selection_getNodes_at;
106
+ // All the `$isXNode` functions prefer `null` over `undefined`
107
+ const selectedNode = (_selection_getNodes_at = selection.getNodes().at(0)) !== null && _selection_getNodes_at !== void 0 ? _selection_getNodes_at : null;
108
+ const previousNodeKey = selectedNode === null || selectedNode === void 0 ? void 0 : (_selectedNode_getPreviousSibling = selectedNode.getPreviousSibling()) === null || _selectedNode_getPreviousSibling === void 0 ? void 0 : _selectedNode_getPreviousSibling.getKey();
109
+ const previousNodeIsGhostText = previousNodeKey === ghostTextNodeKey;
110
+ // If the ghost text is active and we're navigating past it, act as if the ghost text is not there and move 1 extra character
111
+ if (previousNodeIsGhostText && !(0, _BasicFunctionality.$isSentinelNode)(selectedNode) && (0, _texteditor.$isTextNode)(selectedNode) && selection.anchor.offset === 0) {
112
+ editor.update(()=>{
113
+ const selection = (0, _texteditor.$getSelection)();
114
+ if ((0, _texteditor.$isRangeSelection)(selection)) {
115
+ selection.modify('move', false, 'character');
116
+ }
117
+ $clearGhostText();
118
+ }, {
119
+ tag: 'historic'
120
+ });
121
+ // Defer checking the ghost text until after this update has finished
122
+ return;
123
+ }
124
+ // If the ghost text is the last node before the sentinel, we shouldn't let selection get past it
125
+ if (previousNodeIsGhostText && (0, _BasicFunctionality.$isSentinelNode)(selectedNode)) {
126
+ editor.update(()=>{
127
+ var _$getNodeByKey_getPreviousSibling, _$getNodeByKey;
128
+ (_$getNodeByKey = (0, _texteditor.$getNodeByKey)(previousNodeKey)) === null || _$getNodeByKey === void 0 ? void 0 : (_$getNodeByKey_getPreviousSibling = _$getNodeByKey.getPreviousSibling()) === null || _$getNodeByKey_getPreviousSibling === void 0 ? void 0 : _$getNodeByKey_getPreviousSibling.selectEnd();
129
+ }, {
130
+ tag: 'historic'
131
+ });
132
+ return;
133
+ }
134
+ }
93
135
  const promise = this.__$getGhostText(editor, editorState, prevEditorState);
94
136
  promise.then(handleGhostTextResponse).catch((e)=>console.error(e));
95
137
  });
@@ -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 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,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,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,GAAGF;YACJ,kHAAkH;YAClH,IAAIrB,sBAAsB;gBACxBA,uBAAuB;gBACvB;YACF;YACAsB,YAAYE,IAAI,CAAC;gBACf,MAAMC,UAAU,IAAI,CAACvC,eAAe,CAACK,QAAQ+B,aAAaC;gBAC1DE,QAAQC,IAAI,CAAChB,yBAAyBiB,KAAK,CAACC,CAAAA,IAAKC,QAAQC,KAAK,CAACF;YACjE;QACF;QACA,SAASG;YACP,IAAIlC,kBAAkB;gBACpBN,OAAOqB,MAAM,CAAC;oBACZX;gBACF,GAAG;oBACDkB,KAAK;gBACP;YACF;QACF;QACA,SAASa,kBAAkBJ,CAAC;YAC1B,IAAI/B,qBAAqB,QAAQC,aAAa,MAAM;gBAClD,OAAO;YACT;YACA,MAAMI,gBAAgBC,IAAAA,yBAAa,EAACN;YACpC,IAAI,CAACK,eAAe;gBAClB,OAAO;YACT;YACA0B,EAAEK,cAAc;YAChB,MAAMC,WAAWC,IAAAA,2BAAe,EAACrC;YACjCI,cAAckC,OAAO,CAACF;YACtBA,SAASG,SAAS;YAClBpC;YACA,OAAO;QACT;QACA,IAAI,CAACzB,SAAS,GAAG8D,IAAAA,yBAAa,EAAC/C,OAAOgD,qBAAqB,CAAC9C,WAAWa,+BAA+Bf,OAAOiD,sBAAsB,CAACpB,eAAe,IAAI,CAAC/B,iBAAiB,GAAGE,OAAOkD,eAAe,CAACC,2BAAe,EAAEV,mBAAmBW,gCAAoB,IAAIC,MAAMb;IACvQ;AACF;AACA,SAASa;IACP;AACF,EACA,0CAA0C"}
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 $isRangeSelection,\n $isTextNode,\n $setSelection,\n COMMAND_PRIORITY_LOW,\n KEY_TAB_COMMAND,\n mergeRegister,\n} from '@fluentui-copilot/text-editor';\nimport { $isSentinelNode } from '../BasicFunctionality';\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 let justAddedGhostText = 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 justRemovedGhostText = true;\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 justAddedGhostText = true;\n justRemovedGhostText = false;\n },\n { tag: 'historic' },\n );\n };\n\n const handleUpdate: UpdateListener = props => {\n const { editorState, prevEditorState } = props;\n\n // If this update was caused by adding or deleting ghost text, don't recheck the ghost text function until a subsequent update\n if (justRemovedGhostText || justAddedGhostText) {\n justRemovedGhostText = false;\n justAddedGhostText = false;\n return;\n }\n\n editorState.read(() => {\n // We only update the ghost text if the user selection is inside the input\n const selection = $getSelection();\n if (!$getSelection()) {\n return;\n }\n\n if ($isRangeSelection(selection) && selection.isCollapsed()) {\n // All the `$isXNode` functions prefer `null` over `undefined`\n const selectedNode = selection.getNodes().at(0) ?? null;\n const previousNodeKey = selectedNode?.getPreviousSibling()?.getKey();\n const previousNodeIsGhostText = previousNodeKey === ghostTextNodeKey;\n // If the ghost text is active and we're navigating past it, act as if the ghost text is not there and move 1 extra character\n if (\n previousNodeIsGhostText &&\n !$isSentinelNode(selectedNode) &&\n $isTextNode(selectedNode) &&\n selection.anchor.offset === 0\n ) {\n editor.update(\n () => {\n const selection = $getSelection();\n if ($isRangeSelection(selection)) {\n selection.modify('move', false, 'character');\n }\n $clearGhostText();\n },\n { tag: 'historic' },\n );\n // Defer checking the ghost text until after this update has finished\n return;\n }\n\n // If the ghost text is the last node before the sentinel, we shouldn't let selection get past it\n if (previousNodeIsGhostText && $isSentinelNode(selectedNode)) {\n editor.update(\n () => {\n $getNodeByKey(previousNodeKey)?.getPreviousSibling()?.selectEnd();\n },\n { tag: 'historic' },\n );\n return;\n }\n }\n\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":["GhostTextPluginBase","cleanup","_this","__cleanup","_this___cleanup","call","setExposeText","exposeText","__exposeText","setComponentProps","componentProps","__componentProps","setGetGhostText","$getGhostText","__$getGhostText","setAllowCompletion","allowCompletion","__allowCompletion","constructor","editor","id","nodeClass","createNode","__id","ghostTextNodeKey","undefined","lastText","justRemovedGhostText","justAddedGhostText","$clearGhostText","$getNodeByKey","ghostTextNode","isAttached","handleGhostTextNodeTransform","node","key","text","selection","clone","getKey","selectionCopy","$setSelection","handleUpdate","props","read","$getSelection","selectedNode","previousNodeIsGhostText","previousNodeKey","_selectedNode_getPreviousSibling","getPreviousSibling","$isSentinelNode","modify","_$getNodeByKey","tag","_$getNodeByKey_getPreviousSibling","selectEnd","promise","editorState","prevEditorState","then","handleGhostTextResponse","catch","e","console","error","preventDefault","textNode","mergeRegister","registerNodeTransform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8CAEhBR,IAAAA,yBAAUe;iEACZ,EAAAf,YAAA;gDACAR,CAAAA,QAAAA,OAAAA;;;;;;6FAMN;;;qHAKI;mDACEC,IAAAA,mCAAAA,EAAAA,eAAAA;;mEAEFuB;8CAAEC,IAAAA,yBAAK,EAAAN,gBAAA,MAAA,QAAAK,mBAAA,KAAA,IAAA,KAAA,IAAA,AAAAE,CAAAA,oCAAAF,eAAAH,kBAAA,EAAA,MAAA,QAAAK,sCAAA,KAAA,IAAA,KAAA,IAAAA,kCAAAC,SAAA;;;;;;;sBAQfC,UAAA,IAAA,CAAA3C,eAAA,CAAAK,QAAAuC,aAAAC;gBACFF,QAAAG,IAAA,CAAAC,yBAAAC,KAAA,CAAAC,CAAAA,IAAAC,QAAAC,KAAA,CAAAF;;;;kCAMQlC;6BAEF,CAAA;;;yBAEJ;gBACF;;;mCAIWkC,CAAA;qCACT,QAAArC,aAAA,MAAA;uBAEA;;kCAESI,IAAAA,yBAAA,EAAAN;gCACT;uBAEE0C;;4BAGFnC;kBACAoC,WAASX,IAAAA,2BAAS,EAAA9B;0BAClBG,OAAAA,CAAAA;qBACA2B,SAAO;;mBAGJrD;QAMP;QAiBF,IAAA,CAAAA,SAAA,GAAAiE,IAAAA,yBAAA,EAAAjD,OAAAkD,qBAAA,CAAAhD,WAAAY,+BAAAd,OAAAmD,sBAAA,CAAA5B,eAAA,IAAA,CAAAzB,iBAAA,GAAAE,OAAAoD,eAAA,CAAAC,2BAAA,EAAAC,mBAAAC,gCAAA,IAAAC,MAAAC;IACA;;AAEA,SAAAD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["index.js"],"sourcesContent":["export * from './GhostText.base';\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;;uBAAc;CACd,iCAAiC"}
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export * from './GhostText.base';\n"],"names":[],"rangeMappings":";;;;;","mappings":";;;;;uBAAc"}