@fluentui-copilot/chat-input-plugins 0.0.0-nightly-20251002-0405-17b34fb7.1 → 0.0.0-nightly-20251010-0406-7df7c6d1.1

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 (76) hide show
  1. package/CHANGELOG.json +3 -3
  2. package/CHANGELOG.md +4 -4
  3. package/package.json +2 -2
  4. package/dist/index.d.ts +0 -192
  5. package/lib/BasicFunctionality/BasicFunctionality.base.js +0 -107
  6. package/lib/BasicFunctionality/BasicFunctionality.base.js.map +0 -1
  7. package/lib/BasicFunctionality/SentinelNode.js +0 -41
  8. package/lib/BasicFunctionality/SentinelNode.js.map +0 -1
  9. package/lib/BasicFunctionality/SentinelNodeHandlers.js +0 -79
  10. package/lib/BasicFunctionality/SentinelNodeHandlers.js.map +0 -1
  11. package/lib/BasicFunctionality/index.js +0 -2
  12. package/lib/BasicFunctionality/index.js.map +0 -1
  13. package/lib/ChatInputEntity/ChatInputEntityPlugin.base.js +0 -117
  14. package/lib/ChatInputEntity/ChatInputEntityPlugin.base.js.map +0 -1
  15. package/lib/ChatInputEntity/ChatInputEntityPlugin.types.js +0 -1
  16. package/lib/ChatInputEntity/ChatInputEntityPlugin.types.js.map +0 -1
  17. package/lib/ChatInputEntity/index.js +0 -1
  18. package/lib/ChatInputEntity/index.js.map +0 -1
  19. package/lib/GhostText/GhostText.base.js +0 -158
  20. package/lib/GhostText/GhostText.base.js.map +0 -1
  21. package/lib/GhostText/index.js +0 -1
  22. package/lib/GhostText/index.js.map +0 -1
  23. package/lib/ImperativeControl/ImperativeControl.base.js +0 -87
  24. package/lib/ImperativeControl/ImperativeControl.base.js.map +0 -1
  25. package/lib/ImperativeControl/index.js +0 -1
  26. package/lib/ImperativeControl/index.js.map +0 -1
  27. package/lib/ManualGhostText/ManualGhostText.base.js +0 -78
  28. package/lib/ManualGhostText/ManualGhostText.base.js.map +0 -1
  29. package/lib/ManualGhostText/index.js +0 -1
  30. package/lib/ManualGhostText/index.js.map +0 -1
  31. package/lib/PasteUnfurling/PasteUnfurling.base.js +0 -60
  32. package/lib/PasteUnfurling/PasteUnfurling.base.js.map +0 -1
  33. package/lib/PasteUnfurling/PasteUnfurling.types.js +0 -1
  34. package/lib/PasteUnfurling/PasteUnfurling.types.js.map +0 -1
  35. package/lib/PasteUnfurling/PasteUnfurlingTestUtils.js +0 -162
  36. package/lib/PasteUnfurling/PasteUnfurlingTestUtils.js.map +0 -1
  37. package/lib/PasteUnfurling/index.js +0 -1
  38. package/lib/PasteUnfurling/index.js.map +0 -1
  39. package/lib/index.js +0 -6
  40. package/lib/index.js.map +0 -1
  41. package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js +0 -115
  42. package/lib-commonjs/BasicFunctionality/BasicFunctionality.base.js.map +0 -1
  43. package/lib-commonjs/BasicFunctionality/SentinelNode.js +0 -61
  44. package/lib-commonjs/BasicFunctionality/SentinelNode.js.map +0 -1
  45. package/lib-commonjs/BasicFunctionality/SentinelNodeHandlers.js +0 -87
  46. package/lib-commonjs/BasicFunctionality/SentinelNodeHandlers.js.map +0 -1
  47. package/lib-commonjs/BasicFunctionality/index.js +0 -29
  48. package/lib-commonjs/BasicFunctionality/index.js.map +0 -1
  49. package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.base.js +0 -125
  50. package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.base.js.map +0 -1
  51. package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.types.js +0 -4
  52. package/lib-commonjs/ChatInputEntity/ChatInputEntityPlugin.types.js.map +0 -1
  53. package/lib-commonjs/ChatInputEntity/index.js +0 -11
  54. package/lib-commonjs/ChatInputEntity/index.js.map +0 -1
  55. package/lib-commonjs/GhostText/GhostText.base.js +0 -167
  56. package/lib-commonjs/GhostText/GhostText.base.js.map +0 -1
  57. package/lib-commonjs/GhostText/index.js +0 -11
  58. package/lib-commonjs/GhostText/index.js.map +0 -1
  59. package/lib-commonjs/ImperativeControl/ImperativeControl.base.js +0 -97
  60. package/lib-commonjs/ImperativeControl/ImperativeControl.base.js.map +0 -1
  61. package/lib-commonjs/ImperativeControl/index.js +0 -11
  62. package/lib-commonjs/ImperativeControl/index.js.map +0 -1
  63. package/lib-commonjs/ManualGhostText/ManualGhostText.base.js +0 -88
  64. package/lib-commonjs/ManualGhostText/ManualGhostText.base.js.map +0 -1
  65. package/lib-commonjs/ManualGhostText/index.js +0 -11
  66. package/lib-commonjs/ManualGhostText/index.js.map +0 -1
  67. package/lib-commonjs/PasteUnfurling/PasteUnfurling.base.js +0 -70
  68. package/lib-commonjs/PasteUnfurling/PasteUnfurling.base.js.map +0 -1
  69. package/lib-commonjs/PasteUnfurling/PasteUnfurling.types.js +0 -4
  70. package/lib-commonjs/PasteUnfurling/PasteUnfurling.types.js.map +0 -1
  71. package/lib-commonjs/PasteUnfurling/PasteUnfurlingTestUtils.js +0 -197
  72. package/lib-commonjs/PasteUnfurling/PasteUnfurlingTestUtils.js.map +0 -1
  73. package/lib-commonjs/PasteUnfurling/index.js +0 -11
  74. package/lib-commonjs/PasteUnfurling/index.js.map +0 -1
  75. package/lib-commonjs/index.js +0 -48
  76. package/lib-commonjs/index.js.map +0 -1
@@ -1 +0,0 @@
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 {\n ChatInputEntityData,\n ChatInputEntityPluginProps,\n IChatInputEntityPluginBase,\n IEntityNode,\n} 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?: ChatInputEntityPluginProps<ExtraDataType, NodePropsType>['onChatInputEntityAdded'],\n onChatInputEntityDeleted?: ChatInputEntityPluginProps<ExtraDataType, NodePropsType>['onChatInputEntityDeleted'],\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(), nodeKey);\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(), nodeKey);\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":["$createParagraphNode","$createTextNode","$getNodeByKey","$getSelection","$insertNodes","$isDecoratorNode","$isRangeSelection","$isRootOrShadowRoot","$nodesOfType","$wrapNodeInElement","COMMAND_PRIORITY_CRITICAL","DELETE_CHARACTER_COMMAND","mergeRegister","ChatInputEntityPluginBase","cleanup","_cleanup","insertChatInputEntity","props","key","undefined","__editor","update","text","data","entityProps","entityNode","__$createNode","__id","selectEnd","getParentOrThrow","getKey","removeChatInputEntity","keyOrPredicate","__nodeClass","filter","node","i","__pluginId","getEntityData","forEach","remove","updateChatInputEntityProps","updateNode","newProps","updateEntityData","tag","getActiveEntities","getEditorState","read","map","constructor","editor","id","nodeClass","$createNode","$isChatInputEntityNode","onChatInputEntityAdded","onChatInputEntityDeleted","__deleteDirection","registerCommand","isBackward","registerNodeTransform","nextSibling","getNextSibling","selection","shouldMoveSelection","isCollapsed","anchor","offset","getIndexWithinParent","insertAfter","getPreviousSibling","insertBefore","registerMutationListener","nodes","payload","nodeKey","mutation","prevEditorState","noop"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AACA,SACEA,oBAAoB,EACpBC,eAAe,EACfC,aAAa,EACbC,aAAa,EACbC,YAAY,EACZC,gBAAgB,EAChBC,iBAAiB,EACjBC,mBAAmB,EACnBC,YAAY,EACZC,kBAAkB,EAClBC,yBAAyB,EACzBC,wBAAwB,EACxBC,aAAa,QACR,gCAAgC;AAQvC,OAAO,MAAMC;IAqBXC,UAAU;QACR,IAAI,CAACC,QAAQ;IACf;IAuFAC,sBAAsBC,KAAwD,EAAsB;QAClG,IAAIC,MAA0BC;QAC9B,IAAI,CAACC,QAAQ,CAACC,MAAM,CAAC;YACnB,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAEC,WAAW,EAAE,GAAGP;YAEpC,MAAMQ,aAAa,IAAI,CAACC,aAAa,CAAC,IAAI,CAACC,IAAI,EAAEL,MAAMC,MAAMC;YAE7DpB,aAAa;gBAACqB;aAAW;YACzBA,WAAWG,SAAS;YACpB,IAAIrB,oBAAoBkB,WAAWI,gBAAgB,KAAK;gBACtDpB,mBAAmBgB,YAAYzB,sBAAsB4B,SAAS;YAChE;YAEAV,MAAMO,WAAWK,MAAM;QACzB;QAEA,OAAOZ;IACT;IACAa,sBACEC,cAA4G,EAC5G;QACA,IAAI,CAACZ,QAAQ,CAACC,MAAM,CAAC;YACnB,IAAI,OAAOW,mBAAmB,YAAY;gBACxCxB,aAAa,IAAI,CAACyB,WAAW,EAC1BC,MAAM,CAAC,CAACC,MAAMC,IAAMD,KAAKE,UAAU,KAAK,IAAI,CAACV,IAAI,IAAIK,eAAeG,KAAKG,aAAa,IAAIF,IAC1FG,OAAO,CAACJ,CAAAA,OAAQA,KAAKK,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SAASA,KAAKE,UAAU,KAAKe,IAAI;4BAC1DK,yBAAyBtB,KAAKG,aAAa,IAAIsC;wBACjD;oBACF;gBACF,OAAO,IAAIpB,0BAA0BqB,aAAa,WAAW;oBAC3D1B,OAAOJ,cAAc,GAAGC,IAAI,CAAC;wBAC3B,MAAMb,OAAOjC,cAAc0E;wBAC3B,IAAIrB,uBAAuBpB,SAASA,KAAKE,UAAU,KAAKe,IAAI;4BAC1DI,uBAAuBrB,KAAKG,aAAa,IAAIsC;wBAC/C;oBACF;gBACF;YACF;QACF,KACAG;IAER;AAqEF;AAEA,SAASA;IACP;AACF"}
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["ChatInputEntityPlugin.types.ts"],"sourcesContent":["import type { LexicalNode, NodeKey } 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>, nodeKey: NodeKey) => void;\n onChatInputEntityDeleted?: (entity: ChatInputEntityData<ExtraDataType, NodePropsType>, nodeKey: NodeKey) => void;\n // If true, the plugin will call `onChatInputEntityAdded` for all existing entities when it is initialized\n skipInitialization?: boolean;\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":"AAgCA,WAiBC"}
@@ -1 +0,0 @@
1
- export { ChatInputEntityPluginBase } from './ChatInputEntityPlugin.base';
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":["export type { ChatInputEntityData, ChatInputEntityPluginProps, IChatInputEntityPluginBase, IEntityNode } from './ChatInputEntityPlugin.types';\nexport { ChatInputEntityPluginBase } from './ChatInputEntityPlugin.base';\n"],"names":["ChatInputEntityPluginBase"],"rangeMappings":"","mappings":"AACA,SAASA,yBAAyB,QAAQ,+BAA+B"}
@@ -1,158 +0,0 @@
1
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
- import { $createTextNode, $getNodeByKey, $getSelection, $isRangeSelection, $isTextNode, $setSelection, COMMAND_PRIORITY_LOW, KEY_TAB_COMMAND, mergeRegister } from '@fluentui-copilot/text-editor';
3
- import { $isSentinelNode } from '../BasicFunctionality';
4
- export class GhostTextPluginBase {
5
- cleanup() {
6
- var _this___cleanup, _this;
7
- (_this___cleanup = (_this = this).__cleanup) === null || _this___cleanup === void 0 ? void 0 : _this___cleanup.call(_this);
8
- }
9
- setExposeText(exposeText) {
10
- this.__exposeText = exposeText;
11
- }
12
- setComponentProps(componentProps) {
13
- this.__componentProps = componentProps;
14
- }
15
- setGetGhostText($getGhostText) {
16
- this.__$getGhostText = $getGhostText;
17
- }
18
- setAllowCompletion(allowCompletion) {
19
- this.__allowCompletion = allowCompletion;
20
- }
21
- constructor(editor, id, $getGhostText, nodeClass, createNode, componentProps, // Whether or not the ghost text should count as text inside the input for submitting and character count
22
- exposeText, allowCompletion){
23
- _define_property(this, "__id", void 0);
24
- _define_property(this, "__$getGhostText", void 0);
25
- _define_property(this, "__componentProps", void 0);
26
- _define_property(this, "__exposeText", void 0);
27
- _define_property(this, "__allowCompletion", void 0);
28
- _define_property(this, "__cleanup", void 0);
29
- this.__id = id;
30
- this.__$getGhostText = $getGhostText;
31
- this.__componentProps = componentProps;
32
- this.__exposeText = exposeText;
33
- this.__allowCompletion = allowCompletion;
34
- let ghostTextNodeKey = null;
35
- let lastText = undefined;
36
- let justRemovedGhostText = false;
37
- let justAddedGhostText = false;
38
- function $clearGhostText() {
39
- const ghostTextNode = ghostTextNodeKey !== null ? $getNodeByKey(ghostTextNodeKey) : null;
40
- ghostTextNodeKey = null;
41
- lastText = undefined;
42
- if (ghostTextNode && ghostTextNode.isAttached()) {
43
- ghostTextNode.remove();
44
- justRemovedGhostText = true;
45
- }
46
- }
47
- function handleGhostTextNodeTransform(node) {
48
- const key = node.getKey();
49
- if (node.__id === id && key !== ghostTextNodeKey) {
50
- // Only one ghost text
51
- node.remove();
52
- $clearGhostText();
53
- }
54
- }
55
- const handleGhostTextResponse = (text)=>{
56
- if (text === lastText) {
57
- return;
58
- }
59
- editor.update(()=>{
60
- $clearGhostText();
61
- const selection = $getSelection();
62
- if (!text || !selection) {
63
- return;
64
- }
65
- const selectionCopy = selection.clone();
66
- const node = createNode(this.__id, text, this.__exposeText, this.__componentProps);
67
- ghostTextNodeKey = node.getKey();
68
- lastText = text;
69
- selection.insertNodes([
70
- node
71
- ]);
72
- $setSelection(selectionCopy);
73
- justAddedGhostText = true;
74
- justRemovedGhostText = false;
75
- }, {
76
- tag: 'historic'
77
- });
78
- };
79
- const handleUpdate = (props)=>{
80
- const { editorState, prevEditorState } = props;
81
- // If this update was caused by adding or deleting ghost text, don't recheck the ghost text function until a subsequent update
82
- if (justRemovedGhostText || justAddedGhostText) {
83
- justRemovedGhostText = false;
84
- justAddedGhostText = false;
85
- return;
86
- }
87
- editorState.read(()=>{
88
- // We only update the ghost text if the user selection is inside the input
89
- const selection = $getSelection();
90
- if (!$getSelection()) {
91
- return;
92
- }
93
- if ($isRangeSelection(selection) && selection.isCollapsed()) {
94
- var _selectedNode_getPreviousSibling;
95
- var _selection_getNodes_at;
96
- // All the `$isXNode` functions prefer `null` over `undefined`
97
- const selectedNode = (_selection_getNodes_at = selection.getNodes().at(0)) !== null && _selection_getNodes_at !== void 0 ? _selection_getNodes_at : null;
98
- const previousNodeKey = selectedNode === null || selectedNode === void 0 ? void 0 : (_selectedNode_getPreviousSibling = selectedNode.getPreviousSibling()) === null || _selectedNode_getPreviousSibling === void 0 ? void 0 : _selectedNode_getPreviousSibling.getKey();
99
- const previousNodeIsGhostText = previousNodeKey === ghostTextNodeKey;
100
- // 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
101
- if (previousNodeIsGhostText && !$isSentinelNode(selectedNode) && $isTextNode(selectedNode) && selection.anchor.offset === 0) {
102
- editor.update(()=>{
103
- const selection = $getSelection();
104
- if ($isRangeSelection(selection)) {
105
- selection.modify('move', false, 'character');
106
- }
107
- $clearGhostText();
108
- }, {
109
- tag: 'historic'
110
- });
111
- // Defer checking the ghost text until after this update has finished
112
- return;
113
- }
114
- // If the ghost text is the last node before the sentinel, we shouldn't let selection get past it
115
- if (previousNodeIsGhostText && $isSentinelNode(selectedNode)) {
116
- editor.update(()=>{
117
- var _$getNodeByKey_getPreviousSibling, _$getNodeByKey;
118
- (_$getNodeByKey = $getNodeByKey(previousNodeKey)) === null || _$getNodeByKey === void 0 ? void 0 : (_$getNodeByKey_getPreviousSibling = _$getNodeByKey.getPreviousSibling()) === null || _$getNodeByKey_getPreviousSibling === void 0 ? void 0 : _$getNodeByKey_getPreviousSibling.selectEnd();
119
- }, {
120
- tag: 'historic'
121
- });
122
- return;
123
- }
124
- }
125
- const promise = this.__$getGhostText(editor, editorState, prevEditorState);
126
- promise.then(handleGhostTextResponse).catch((e)=>console.error(e));
127
- });
128
- };
129
- function unmountGhostText() {
130
- if (ghostTextNodeKey) {
131
- editor.update(()=>{
132
- $clearGhostText();
133
- }, {
134
- tag: 'historic'
135
- });
136
- }
137
- }
138
- function $handleTabCommand(e) {
139
- if (ghostTextNodeKey === null || lastText === null) {
140
- return false;
141
- }
142
- const ghostTextNode = $getNodeByKey(ghostTextNodeKey);
143
- if (!ghostTextNode) {
144
- return false;
145
- }
146
- e.preventDefault();
147
- const textNode = $createTextNode(lastText);
148
- ghostTextNode.replace(textNode);
149
- textNode.selectEnd();
150
- $clearGhostText();
151
- return true;
152
- }
153
- this.__cleanup = mergeRegister(editor.registerNodeTransform(nodeClass, handleGhostTextNodeTransform), editor.registerUpdateListener(handleUpdate), this.__allowCompletion ? editor.registerCommand(KEY_TAB_COMMAND, $handleTabCommand, COMMAND_PRIORITY_LOW) : noop, unmountGhostText);
154
- }
155
- }
156
- function noop() {
157
- return;
158
- }
@@ -1 +0,0 @@
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":["$createTextNode","$getNodeByKey","$getSelection","$isRangeSelection","$isTextNode","$setSelection","COMMAND_PRIORITY_LOW","KEY_TAB_COMMAND","mergeRegister","$isSentinelNode","GhostTextPluginBase","cleanup","__cleanup","setExposeText","exposeText","__exposeText","setComponentProps","componentProps","__componentProps","setGetGhostText","$getGhostText","__$getGhostText","setAllowCompletion","allowCompletion","__allowCompletion","constructor","editor","id","nodeClass","createNode","__id","ghostTextNodeKey","lastText","undefined","justRemovedGhostText","justAddedGhostText","$clearGhostText","ghostTextNode","isAttached","remove","handleGhostTextNodeTransform","node","key","getKey","handleGhostTextResponse","text","update","selection","selectionCopy","clone","insertNodes","tag","handleUpdate","props","editorState","prevEditorState","read","isCollapsed","selectedNode","getNodes","at","previousNodeKey","getPreviousSibling","previousNodeIsGhostText","anchor","offset","modify","selectEnd","promise","then","catch","e","console","error","unmountGhostText","$handleTabCommand","preventDefault","textNode","replace","registerNodeT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AAkBJ,CAAgB;YACzC,IAAIxC,qBAAqB,QAAQC,aAAa,MAAM;gBAClD,OAAO;YACT;YAEA,MAAMK,gBAAgBpC,cAAc8B;YACpC,IAAI,CAACM,eAAe;gBAClB,OAAO;YACT;YAEAkC,EAAEK,cAAc;YAEhB,MAAMC,WAAW7E,gBAAgBgC;YACjCK,cAAcyC,OAAO,CAACD;YACtBA,SAASV,SAAS;YAClB/B;YACA,OAAO;QACT;QAEA,IAAI,CAACxB,SAAS,GAAGJ,cACfkB,OAAOqD,qBAAqB,CAACnD,WAAWY,+BACxCd,OAAOsD,sBAAsB,CAAC5B,eAC9B,IAAI,CAAC5B,iBAAiB,GAAGE,OAAOuD,eAAe,CAAC1E,iBAAiBoE,mBAAmBrE,wBAAwB4E,MAC5GR;IAEJ;AAiBF;AACA,SAASQ;IACP;AACF"}
@@ -1 +0,0 @@
1
- export { GhostTextPluginBase } from './GhostText.base';
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":["export type { GetGhostTextFunction, IGhostTextNode } from './GhostText.base';\nexport { GhostTextPluginBase } from './GhostText.base';\n"],"names":["GhostTextPluginBase"],"rangeMappings":"","mappings":"AACA,SAASA,mBAAmB,QAAQ,mBAAmB"}
@@ -1,87 +0,0 @@
1
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
- import { $createParagraphNode, $createRangeSelection, $createTextNode, $getLeafNodes, $getRoot, $getSelection, $isTextNode, $normalizeSelection__EXPERIMENTAL, $setSelection } from '@fluentui-copilot/text-editor';
3
- import { SENTINEL_VALUE, $isSentinelNode } from '../BasicFunctionality';
4
- export class ImperativeControlBase {
5
- moveCursor(location) {
6
- this.__editor.update(()=>{
7
- const children = $getLeafNodes($getRoot());
8
- let baseOffset = 0;
9
- let currentNode = children.shift();
10
- while(baseOffset < location && currentNode){
11
- const nodeLength = $isTextNode(currentNode) && !currentNode.isToken() ? currentNode.getTextContent().length : 1;
12
- if (baseOffset + nodeLength >= location) {
13
- const elementType = $isTextNode(currentNode) ? 'text' : 'element';
14
- const localOffset = location - baseOffset;
15
- const nodeKey = currentNode.getKey();
16
- const selection = $createRangeSelection();
17
- selection.anchor.set(nodeKey, localOffset, elementType);
18
- selection.focus.set(nodeKey, localOffset, elementType);
19
- $setSelection($normalizeSelection__EXPERIMENTAL(selection));
20
- return;
21
- }
22
- baseOffset += nodeLength;
23
- currentNode = children.shift();
24
- }
25
- if (location > baseOffset) {
26
- $getRoot().selectEnd();
27
- }
28
- });
29
- }
30
- setInputText(inputText) {
31
- this.__editor.update(()=>{
32
- const root = $getRoot();
33
- root.clear();
34
- if (inputText !== '') {
35
- const newParagraph = $createParagraphNode();
36
- const newText = $createTextNode(inputText);
37
- newParagraph.append(newText);
38
- root.append(newParagraph);
39
- root.selectEnd();
40
- }
41
- });
42
- }
43
- appendText(text) {
44
- this.__editor.update(()=>{
45
- $getRoot().selectEnd().insertText(text);
46
- });
47
- }
48
- prependText(text) {
49
- this.__editor.update(()=>{
50
- $getRoot().selectStart().insertText(text);
51
- });
52
- }
53
- insertTextAtCursor(text) {
54
- this.__editor.update(()=>{
55
- var _$getSelection;
56
- const selection = (_$getSelection = $getSelection()) !== null && _$getSelection !== void 0 ? _$getSelection : $getRoot().selectEnd();
57
- selection.insertText(text);
58
- });
59
- }
60
- getInputText(transform) {
61
- return this.__editor.getEditorState().read(()=>{
62
- if (!transform) {
63
- return $getRoot().getTextContent().replace(SENTINEL_VALUE, '');
64
- }
65
- const children = $getLeafNodes($getRoot());
66
- const transformedNodeTexts = [];
67
- for (const currentNode of children){
68
- if (!$isSentinelNode(currentNode)) {
69
- transformedNodeTexts.push(transform(currentNode));
70
- }
71
- }
72
- return transformedNodeTexts.join('');
73
- });
74
- }
75
- scrollToBottom() {
76
- var _this___editor_getRootElement;
77
- (_this___editor_getRootElement = this.__editor.getRootElement()) === null || _this___editor_getRootElement === void 0 ? void 0 : _this___editor_getRootElement.scrollIntoView({
78
- behavior: 'smooth',
79
- block: 'end'
80
- });
81
- return;
82
- }
83
- constructor(editor){
84
- _define_property(this, "__editor", void 0);
85
- this.__editor = editor;
86
- }
87
- }
@@ -1 +0,0 @@
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,qB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Q,CAACC,MAAM,CAAC;YACnBX,WAAW4B,SAAS,GAAGU,UAAU,CAACD;QACpC;IACF;IACAE,YAAYF,IAAY,EAAE;QACxB,IAAI,CAAC3B,QAAQ,CAACC,MAAM,CAAC;YACnBX,WAAWwC,WAAW,GAAGF,UAAU,CAACD;QACtC;IACF;IACAI,mBAAmBJ,IAAY,EAAE;QAC/B,IAAI,CAAC3B,QAAQ,CAACC,MAAM,CAAC;gBACDV;YAAlB,MAAMuB,YAAYvB,CAAAA,iBAAAA,6BAAAA,4BAAAA,iBAAmBD,WAAW4B,SAAS;YACzDJ,UAAUc,UAAU,CAACD;QACvB;IACF;IACAK,aAAaC,SAAyC,EAAE;QACtD,OAAO,IAAI,CAACjC,QAAQ,CAACkC,cAAc,GAAGC,IAAI,CAAC;YACzC,IAAI,CAACF,WAAW;gBACd,OAAO3C,WAAWkB,cAAc,GAAG4B,OAAO,CAACzC,gBAAgB;YAC7D;YACA,MAAMO,WAAWb,cAAcC;YAC/B,MAAM+C,uBAAiC,EAAE;YAEzC,KAAK,MAAMjC,eAAeF,SAAU;gBAClC,IAAI,CAACN,gBAAgBQ,cAAc;oBACjCiC,qBAAqBC,IAAI,CAACL,UAAU7B;gBACtC;YACF;YAEA,OAAOiC,qBAAqBE,IAAI,CAAC;QACnC;IACF;IACAC,iBAAiB;YACf;SAAA,gCAAA,IAAI,CAACxC,QAAQ,CAACyC,cAAc,gBAA5B,oDAAA,8BAAgCC,cAAc,CAAC;YAAEC,UAAU;YAAUC,OAAO;QAAM;QAClF;IACF;IAzFAC,YAAYC,MAAqB,CAAE;QAFnC,uBAAQ9C,YAAR,KAAA;QAGE,IAAI,CAACA,QAAQ,GAAG8C;IAClB;AAwFF"}
@@ -1 +0,0 @@
1
- export { ImperativeControlBase } from './ImperativeControl.base';
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":["export type { IImperativeControlBase } from './ImperativeControl.base';\nexport { ImperativeControlBase } from './ImperativeControl.base';\n"],"names":["ImperativeControlBase"],"rangeMappings":"","mappings":"AACA,SAASA,qBAAqB,QAAQ,2BAA2B"}
@@ -1,78 +0,0 @@
1
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
- import { $createTextNode, $getNodeByKey, $insertNodes } from '@fluentui-copilot/text-editor';
3
- export class ManualGhostTextBase {
4
- getGhostText() {
5
- return this.__editor.getEditorState().read(()=>{
6
- if (this.__nodeKey) {
7
- const node = $getNodeByKey(this.__nodeKey);
8
- if (this.__$isNodeType(node)) {
9
- return node.__content;
10
- }
11
- }
12
- });
13
- }
14
- setGhostText(text, exposeText, componentProps, discrete) {
15
- this.__editor.update(()=>{
16
- if (this.__nodeKey) {
17
- const node = $getNodeByKey(this.__nodeKey);
18
- if (this.__$isNodeType(node)) {
19
- node.getWritable().__content = text;
20
- return;
21
- }
22
- }
23
- const node = this.__$createNode(this.__id, text, exposeText, componentProps);
24
- this.__nodeKey = node.getKey();
25
- $insertNodes([
26
- node
27
- ]);
28
- node.selectStart();
29
- }, {
30
- tag: 'historic',
31
- discrete: discrete ? true : undefined
32
- });
33
- }
34
- commitGhostText(finalText, discrete) {
35
- if (this.__nodeKey) {
36
- this.__editor.update(()=>{
37
- if (this.__nodeKey) {
38
- const node = $getNodeByKey(this.__nodeKey);
39
- if (this.__$isNodeType(node)) {
40
- const textNode = $createTextNode(finalText);
41
- node.replace(textNode);
42
- textNode.selectEnd();
43
- }
44
- }
45
- }, {
46
- discrete: discrete ? true : undefined
47
- });
48
- this.__nodeKey = undefined;
49
- }
50
- }
51
- cancelGhostText(discrete) {
52
- if (this.__nodeKey) {
53
- this.__editor.update(()=>{
54
- if (this.__nodeKey) {
55
- const node = $getNodeByKey(this.__nodeKey);
56
- if (this.__$isNodeType(node)) {
57
- node.remove();
58
- }
59
- }
60
- }, {
61
- tag: 'historic',
62
- discrete: discrete ? true : undefined
63
- });
64
- this.__nodeKey = undefined;
65
- }
66
- }
67
- constructor(editor, id, $isNodeType, $createNode){
68
- _define_property(this, "__editor", void 0);
69
- _define_property(this, "__nodeKey", void 0);
70
- _define_property(this, "__id", void 0);
71
- _define_property(this, "__$isNodeType", void 0);
72
- _define_property(this, "__$createNode", void 0);
73
- this.__editor = editor;
74
- this.__id = id;
75
- this.__$isNodeType = $isNodeType;
76
- this.__$createNode = $createNode;
77
- }
78
- }
@@ -1 +0,0 @@
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, exposeText?: boolean, componentProps?: ComponentPropsType, discrete?: boolean) => void;\n commitGhostText: (finalText: string, discrete?: boolean) => void;\n cancelGhostText: (discrete?: boolean) => void;\n}\n\nexport class ManualGhostTextBase<ComponentPropsType> implements IManualGhostTextBase<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, discrete?: boolean): 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', discrete: discrete ? true : undefined },\n );\n }\n\n commitGhostText(finalText: string, discrete?: boolean): 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 const textNode = $createTextNode(finalText);\n node.replace(textNode);\n textNode.selectEnd();\n }\n }\n },\n { discrete: discrete ? true : undefined },\n );\n this.__nodeKey = undefined;\n }\n }\n\n cancelGhostText(discrete?: boolean): 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', discrete: discrete ? true : undefined },\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","discrete","update","getWritable","__$createNode","__id","getKey","selectStart","tag","undefined","commitGhostText","finalText","textNode","replace","selectEnd","cancelGhostText","remove","constructor","editor","id","$isNodeType","$createNode"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";AAAA,SACEA,eAAe,EACfC,aAAa,EACbC,YAAY,QAGP,gCAAgC;AAUvC,OAAO,MAAMC;IA8BXC,eAAmC;QACjC,OAAO,IAAI,CAACC,QAAQ,CAACC,cAAc,GAAGC,IAAI,CAAC;YACzC,IAAI,IAAI,CAACC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,CAACY,MAAM,CAClB;gBACE,IAAI,IAAI,CAACT,SAAS,EAAE;oBAClB,MAAMC,OAAOR,cAAc,IAAI,CAACO,SAAS;oBACzC,IAAI,IAAI,CAACE,aAAa,CAACD,OAAO;wBAC5BA,KAAKsB,MAAM;oBACb;gBACF;YACF,GACA;gBAAER,KAAK;gBAAYP,UAAUA,WAAW,OAAOQ;YAAU;YAE3D,IAAI,CAAChB,SAAS,GAAGgB;QACnB;IACF;IAlFAQ,YACEC,MAAqB,EACrBC,EAAU,EACVC,WAAqF,EACrFC,WAKuC,CACvC;QAtBF,uBAAQ/B,YAAR,KAAA;QACA,uBAAQG,aAAR,KAAA;QAEA,uBAAQY,QAAR,KAAA;QACA,uBAAQV,iBAAR,KAAA;QACA,uBAAQS,iBAAR,KAAA;QAkBE,IAAI,CAACd,QAAQ,GAAG4B;QAChB,IAAI,CAACb,IAAI,GAAGc;QACZ,IAAI,CAACxB,aAAa,GAAGyB;QACrB,IAAI,CAAChB,aAAa,GAAGiB;IACvB;AAoEF"}
@@ -1 +0,0 @@
1
- export { ManualGhostTextBase } from './ManualGhostText.base';
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":["export type { IManualGhostTextBase } from './ManualGhostText.base';\nexport { ManualGhostTextBase } from './ManualGhostText.base';\n"],"names":["ManualGhostTextBase"],"rangeMappings":"","mappings":"AACA,SAASA,mBAAmB,QAAQ,yBAAyB"}
@@ -1,60 +0,0 @@
1
- import { COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_LOW, PASTE_COMMAND, $insertNodes, $createTextNode } from '@fluentui-copilot/text-editor';
2
- function unhandledPart(part) {
3
- throw new Error(`Unhandled part: ${part}`);
4
- }
5
- export function registerPasteUnfurlingPlugin(editor, props) {
6
- const { entityPluginId, transforms, $createEntityNode } = props;
7
- function insertParts(parts) {
8
- editor.update(()=>{
9
- const nodes = parts.map((part)=>{
10
- switch(part.type){
11
- case 'entity':
12
- return $createEntityNode(entityPluginId, part.value.text, part.value.data, part.value.entityProps);
13
- case 'text':
14
- return $createTextNode(part.value);
15
- }
16
- return unhandledPart(part);
17
- });
18
- $insertNodes(nodes);
19
- });
20
- }
21
- function handlePaste(event) {
22
- const transformPromises = [];
23
- for (const transform of transforms){
24
- transformPromises.push(Promise.resolve(transform(event, editor)));
25
- }
26
- Promise.allSettled(transformPromises).then((results)=>{
27
- let handledPaste = false;
28
- for (const result of results){
29
- if (result.status === 'fulfilled') {
30
- const transformResult = result.value;
31
- if (transformResult.transformedParts) {
32
- insertParts(transformResult.transformedParts);
33
- }
34
- if (transformResult.handled) {
35
- handledPaste = true;
36
- break;
37
- }
38
- }
39
- }
40
- if (!handledPaste) {
41
- var _commandsMap_get;
42
- const commandsMap = editor._commands;
43
- const defaultEditorListeners = (_commandsMap_get = commandsMap.get(PASTE_COMMAND)) === null || _commandsMap_get === void 0 ? void 0 : _commandsMap_get[COMMAND_PRIORITY_EDITOR];
44
- if (defaultEditorListeners) {
45
- // After the promises have resolved, we're not guaranteed to be in the same update state as the original command
46
- editor.update(()=>{
47
- for (const listener of defaultEditorListeners){
48
- const defaultHandled = listener(event, editor);
49
- if (defaultHandled) {
50
- break;
51
- }
52
- }
53
- });
54
- }
55
- }
56
- });
57
- return true;
58
- }
59
- return editor.registerCommand(PASTE_COMMAND, handlePaste, COMMAND_PRIORITY_LOW);
60
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["PasteUnfurling.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport {\n COMMAND_PRIORITY_EDITOR,\n COMMAND_PRIORITY_LOW,\n PASTE_COMMAND,\n $insertNodes,\n $createTextNode,\n} from '@fluentui-copilot/text-editor';\nimport type {\n PasteUnfurlingPluginBaseProps,\n PasteUnfurlingTransformedPart,\n PasteUnfurlingTransformResult,\n} from './PasteUnfurling.types';\n\nfunction unhandledPart(part: never): never {\n throw new Error(`Unhandled part: ${part}`);\n}\n\nexport function registerPasteUnfurlingPlugin<ExtraDataType, NodePropsType>(\n editor: LexicalEditor,\n props: PasteUnfurlingPluginBaseProps<ExtraDataType, NodePropsType>,\n): () => void {\n const { entityPluginId, transforms, $createEntityNode } = props;\n\n function insertParts(parts: PasteUnfurlingTransformedPart<ExtraDataType, NodePropsType>[]) {\n editor.update(() => {\n const nodes = parts.map(part => {\n switch (part.type) {\n case 'entity':\n return $createEntityNode(entityPluginId, part.value.text, part.value.data, part.value.entityProps);\n case 'text':\n return $createTextNode(part.value);\n }\n return unhandledPart(part);\n });\n $insertNodes(nodes);\n });\n }\n\n function handlePaste(event: ClipboardEvent): boolean {\n const transformPromises: Promise<PasteUnfurlingTransformResult<ExtraDataType, NodePropsType>>[] = [];\n\n for (const transform of transforms) {\n transformPromises.push(Promise.resolve(transform(event, editor)));\n }\n\n Promise.allSettled(transformPromises).then(results => {\n let handledPaste = false;\n\n for (const result of results) {\n if (result.status === 'fulfilled') {\n const transformResult = result.value;\n if (transformResult.transformedParts) {\n insertParts(transformResult.transformedParts);\n }\n\n if (transformResult.handled) {\n handledPaste = true;\n break;\n }\n }\n }\n\n if (!handledPaste) {\n const commandsMap = editor._commands;\n const defaultEditorListeners = commandsMap.get(PASTE_COMMAND)?.[COMMAND_PRIORITY_EDITOR];\n if (defaultEditorListeners) {\n // After the promises have resolved, we're not guaranteed to be in the same update state as the original command\n editor.update(() => {\n for (const listener of defaultEditorListeners) {\n const defaultHandled = listener(event, editor);\n if (defaultHandled) {\n break;\n }\n }\n });\n }\n }\n });\n\n return true;\n }\n\n return editor.registerCommand(PASTE_COMMAND, handlePaste, COMMAND_PRIORITY_LOW);\n}\n"],"names":["COMMAND_PRIORITY_EDITOR","COMMAND_PRIORITY_LOW","PASTE_COMMAND","$insertNodes","$createTextNode","unhandledPart","part","Error","registerPasteUnfurlingPlugin","editor","props","entityPluginId","transforms","$createEntityNode","insertParts","parts","update","nodes","map","type","value","text","data","entityProps","handlePaste","event","transformPromises","transform","push","Promise","resolve","allSettled","then","results","handledPaste","result","status","transformResult","transformedParts","handled","commandsMap","_commands","defaultEditorListeners","get","listener","defaultHandled","registerCommand"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SACEA,uBAAuB,EACvBC,oBAAoB,EACpBC,aAAa,EACbC,YAAY,EACZC,eAAe,QACV,gCAAgC;AAOvC,SAASC,cAAcC,IAAW;IAChC,MAAM,IAAIC,MAAM,CAAC,gBAAgB,EAAED,KAAK,CAAC;AAC3C;AAEA,OAAO,SAASE,6BACdC,MAAqB,EACrBC,KAAkE;IAElE,MAAM,EAAEC,cAAc,EAAEC,UAAU,EAAEC,iBAAiB,EAAE,GAAGH;IAE1D,SAASI,YAAYC,KAAoE;QACvFN,OAAOO,MAAM,CAAC;YACZ,MAAMC,QAAQF,MAAMG,GAAG,CAACZ,CAAAA;gBACtB,OAAQA,KAAKa,IAAI;oBACf,KAAK;wBACH,OAAON,kBAAkBF,gBAAgBL,KAAKc,KAAK,CAACC,IAAI,EAAEf,KAAKc,KAAK,CAACE,IAAI,EAAEhB,KAAKc,KAAK,CAACG,WAAW;oBACnG,KAAK;wBACH,OAAOnB,gBAAgBE,KAAKc,KAAK;gBACrC;gBACA,OAAOf,cAAcC;YACvB;YACAH,aAAac;QACf;IACF;IAEA,SAASO,YAAYC,KAAqB;QACxC,MAAMC,oBAA4F,EAAE;QAEpG,KAAK,MAAMC,aAAaf,WAAY;YAClCc,kBAAkBE,IAAI,CAACC,QAAQC,OAAO,CAACH,UAAUF,OAAOhB;QAC1D;QAEAoB,QAAQE,UAAU,CAACL,mBAAmBM,IAAI,CAACC,CAAAA;YACzC,IAAIC,eAAe;YAEnB,KAAK,MAAMC,UAAUF,QAAS;gBAC5B,IAAIE,OAAOC,MAAM,KAAK,aAAa;oBACjC,MAAMC,kBAAkBF,OAAOf,KAAK;oBACpC,IAAIiB,gBAAgBC,gBAAgB,EAAE;wBACpCxB,YAAYuB,gBAAgBC,gBAAgB;oBAC9C;oBAEA,IAAID,gBAAgBE,OAAO,EAAE;wBAC3BL,eAAe;wBACf;oBACF;gBACF;YACF;YAEA,IAAI,CAACA,cAAc;oBAEcM;gBAD/B,MAAMA,cAAc/B,OAAOgC,SAAS;gBACpC,MAAMC,0BAAyBF,mBAAAA,YAAYG,GAAG,CAACzC,4BAAhBsC,uCAAAA,gBAAgC,CAACxC,wBAAwB;gBACxF,IAAI0C,wBAAwB;oBAC1B,gHAAgH;oBAChHjC,OAAOO,MAAM,CAAC;wBACZ,KAAK,MAAM4B,YAAYF,uBAAwB;4BAC7C,MAAMG,iBAAiBD,SAASnB,OAAOhB;4BACvC,IAAIoC,gBAAgB;gCAClB;4BACF;wBACF;oBACF;gBACF;YACF;QACF;QAEA,OAAO;IACT;IAEA,OAAOpC,OAAOqC,eAAe,CAAC5C,eAAesB,aAAavB;AAC5D"}
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["PasteUnfurling.types.ts"],"sourcesContent":["import type { LexicalEditor, LexicalNode, NodeKey } from '@fluentui-copilot/text-editor';\nimport type { ChatInputEntityData } from '../ChatInputEntity';\n\nexport type PasteUnfurlingTransformedPart<ExtraDataType, NodePropsType> =\n | { type: 'text'; value: string }\n | { type: 'entity'; value: ChatInputEntityData<ExtraDataType, NodePropsType> };\n\nexport type PasteUnfurlingTransformResult<ExtraDataType, NodePropsType> = {\n handled: boolean;\n transformedParts?: PasteUnfurlingTransformedPart<ExtraDataType, NodePropsType>[];\n};\n\nexport type PasteUnfurlingTransformFunction<ExtraDataType, NodePropsType> = (\n event: ClipboardEvent,\n editor: LexicalEditor,\n) =>\n | PasteUnfurlingTransformResult<ExtraDataType, NodePropsType>\n | Promise<PasteUnfurlingTransformResult<ExtraDataType, NodePropsType>>;\n\nexport type PasteUnfurlingPluginBaseProps<ExtraDataType, NodePropsType> = {\n entityPluginId: string;\n transforms: PasteUnfurlingTransformFunction<ExtraDataType, NodePropsType>[];\n $createEntityNode: (\n pluginId: string,\n text: string,\n data?: ExtraDataType,\n entityProps?: NodePropsType,\n key?: NodeKey,\n ) => LexicalNode;\n};\n"],"names":[],"rangeMappings":"","mappings":"AAmBA,WAUE"}