@fluentui-copilot/chat-input-plugins 0.2.2 → 0.3.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.
package/CHANGELOG.json CHANGED
@@ -2,7 +2,49 @@
2
2
  "name": "@fluentui-copilot/chat-input-plugins",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 19 Sep 2024 19:49:24 GMT",
5
+ "date": "Thu, 31 Oct 2024 17:39:46 GMT",
6
+ "tag": "@fluentui-copilot/chat-input-plugins_v0.3.1",
7
+ "version": "0.3.1",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "Humberto.Morimoto@microsoft.com",
12
+ "package": "@fluentui-copilot/chat-input-plugins",
13
+ "commit": "49fcd13f2ab4e6635394196e53ef1de79638e6d6",
14
+ "comment": "feat: Enabling async transforms in the PasteUnfurlingPlugin of ChatInput."
15
+ },
16
+ {
17
+ "author": "Humberto.Morimoto@microsoft.com",
18
+ "package": "@fluentui-copilot/chat-input-plugins",
19
+ "commit": "db6349629aa22001ea83df218e61e6d938e04198",
20
+ "comment": "chore: Chaining getters into single line in paste unfurling plugin."
21
+ },
22
+ {
23
+ "author": "owcampbe@microsoft.com",
24
+ "package": "@fluentui-copilot/chat-input-plugins",
25
+ "commit": "2bdb166cd12430b68d776c012dbb574b88e47fc8",
26
+ "comment": "feat: Add discrete update options to ghost text functions."
27
+ }
28
+ ]
29
+ }
30
+ },
31
+ {
32
+ "date": "Wed, 25 Sep 2024 19:50:22 GMT",
33
+ "tag": "@fluentui-copilot/chat-input-plugins_v0.3.0",
34
+ "version": "0.3.0",
35
+ "comments": {
36
+ "minor": [
37
+ {
38
+ "author": "estebanmu@microsoft.com",
39
+ "package": "@fluentui-copilot/chat-input-plugins",
40
+ "commit": "cf2200a2e3e936a797f057fd58ef492f97c07a8e",
41
+ "comment": "Revert \"feat(react-editor-input): Update Lexical versions and refactor Lexical initialization (#2052)\""
42
+ }
43
+ ]
44
+ }
45
+ },
46
+ {
47
+ "date": "Thu, 19 Sep 2024 19:49:44 GMT",
6
48
  "tag": "@fluentui-copilot/chat-input-plugins_v0.2.2",
7
49
  "version": "0.2.2",
8
50
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,32 @@
1
1
  # Change Log - @fluentui-copilot/chat-input-plugins
2
2
 
3
- This log was last generated on Thu, 19 Sep 2024 19:49:24 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 31 Oct 2024 17:39:46 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [0.3.1](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.3.1)
8
+
9
+ Thu, 31 Oct 2024 17:39:46 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.3.0..@fluentui-copilot/chat-input-plugins_v0.3.1)
11
+
12
+ ### Patches
13
+
14
+ - feat: Enabling async transforms in the PasteUnfurlingPlugin of ChatInput. ([PR #2326](https://github.com/microsoft/fluentai/pull/2326) by Humberto.Morimoto@microsoft.com)
15
+ - chore: Chaining getters into single line in paste unfurling plugin. ([PR #2328](https://github.com/microsoft/fluentai/pull/2328) by Humberto.Morimoto@microsoft.com)
16
+ - feat: Add discrete update options to ghost text functions. ([PR #2251](https://github.com/microsoft/fluentai/pull/2251) by owcampbe@microsoft.com)
17
+
18
+ ## [0.3.0](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.3.0)
19
+
20
+ Wed, 25 Sep 2024 19:50:22 GMT
21
+ [Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.2.2..@fluentui-copilot/chat-input-plugins_v0.3.0)
22
+
23
+ ### Minor changes
24
+
25
+ - Revert "feat(react-editor-input): Update Lexical versions and refactor Lexical initialization (#2052)" ([PR #2202](https://github.com/microsoft/fluentai/pull/2202) by estebanmu@microsoft.com)
26
+
7
27
  ## [0.2.2](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.2.2)
8
28
 
9
- Thu, 19 Sep 2024 19:49:24 GMT
29
+ Thu, 19 Sep 2024 19:49:44 GMT
10
30
  [Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.2.1..@fluentui-copilot/chat-input-plugins_v0.2.2)
11
31
 
12
32
  ### Patches
package/dist/index.d.ts CHANGED
@@ -44,7 +44,7 @@ export declare class ChatInputEntityPluginBase<ExtraDataType, NodePropsType, Nod
44
44
  private __$createNode;
45
45
  private _cleanup;
46
46
  cleanup(): void;
47
- constructor(editor: LexicalEditor, id: string, nodeClass: Klass<NodeType>, $createNode: (pluginId: string, text: string, data?: ExtraDataType, entityProps?: NodePropsType, key?: NodeKey) => NodeType, $isChatInputEntityNode: (node: LexicalNode | null) => node is NodeType, onChatInputEntityAdded?: ChatInputEntityPluginProps<ExtraDataType, NodePropsType>['onChatInputEntityAdded'], onChatInputEntityDeleted?: ChatInputEntityPluginProps<ExtraDataType, NodePropsType>['onChatInputEntityDeleted'], skipInitialization?: boolean);
47
+ constructor(editor: LexicalEditor, id: string, nodeClass: Klass<NodeType>, $createNode: (pluginId: string, text: string, data?: ExtraDataType, entityProps?: NodePropsType, key?: NodeKey) => NodeType, $isChatInputEntityNode: (node: LexicalNode | null) => node is NodeType, onChatInputEntityAdded?: ChatInputEntityPluginProps<ExtraDataType, NodePropsType>['onChatInputEntityAdded'], onChatInputEntityDeleted?: ChatInputEntityPluginProps<ExtraDataType, NodePropsType>['onChatInputEntityDeleted']);
48
48
  insertChatInputEntity(props: ChatInputEntityData<ExtraDataType, NodePropsType>): string | undefined;
49
49
  removeChatInputEntity(keyOrPredicate: string | ((entity: ChatInputEntityData<ExtraDataType, NodePropsType>, i: number) => boolean)): void;
50
50
  updateChatInputEntityProps(keyOrPredicate: string | ((entity: ChatInputEntityData<ExtraDataType, NodePropsType>, i: number) => boolean), props: ChatInputEntityData<ExtraDataType, NodePropsType> | ((oldProps: ChatInputEntityData<ExtraDataType, NodePropsType>) => ChatInputEntityData<ExtraDataType, NodePropsType>)): void;
@@ -126,9 +126,9 @@ export declare interface IImperativeControlBase {
126
126
 
127
127
  export declare interface IManualGhostTextBase<ComponentPropsType> {
128
128
  getGhostText: () => string | undefined;
129
- setGhostText: (text: string, componentProps?: ComponentPropsType) => void;
130
- commitGhostText: (finalText: string) => void;
131
- cancelGhostText: () => void;
129
+ setGhostText: (text: string, exposeText?: boolean, componentProps?: ComponentPropsType, discrete?: boolean) => void;
130
+ commitGhostText: (finalText: string, discrete?: boolean) => void;
131
+ cancelGhostText: (discrete?: boolean) => void;
132
132
  }
133
133
 
134
134
  export declare class ImperativeControlBase implements IImperativeControlBase {
@@ -143,7 +143,7 @@ export declare class ImperativeControlBase implements IImperativeControlBase {
143
143
  scrollToBottom(): void;
144
144
  }
145
145
 
146
- export declare class ManualGhostTextBase<ComponentPropsType> {
146
+ export declare class ManualGhostTextBase<ComponentPropsType> implements IManualGhostTextBase<ComponentPropsType> {
147
147
  private __editor;
148
148
  private __nodeKey?;
149
149
  private __id;
@@ -151,9 +151,9 @@ export declare class ManualGhostTextBase<ComponentPropsType> {
151
151
  private __$createNode;
152
152
  constructor(editor: LexicalEditor, id: string, $isNodeType: (node: LexicalNode | null) => node is IGhostTextNode<ComponentPropsType>, $createNode: (id: string, content: string, exposeText?: boolean, componentProps?: ComponentPropsType) => IGhostTextNode<ComponentPropsType>);
153
153
  getGhostText(): string | undefined;
154
- setGhostText(text: string, exposeText?: boolean, componentProps?: ComponentPropsType): void;
155
- commitGhostText(finalText: string): void;
156
- cancelGhostText(): void;
154
+ setGhostText(text: string, exposeText?: boolean, componentProps?: ComponentPropsType, discrete?: boolean): void;
155
+ commitGhostText(finalText: string, discrete?: boolean): void;
156
+ cancelGhostText(discrete?: boolean): void;
157
157
  }
158
158
 
159
159
  export declare type PasteUnfurlingPluginBaseProps<ExtraDataType, NodePropsType> = {
@@ -170,7 +170,7 @@ export declare type PasteUnfurlingTransformedPart<ExtraDataType, NodePropsType>
170
170
  value: ChatInputEntityData<ExtraDataType, NodePropsType>;
171
171
  };
172
172
 
173
- export declare type PasteUnfurlingTransformFunction<ExtraDataType, NodePropsType> = (event: ClipboardEvent, editor: LexicalEditor) => PasteUnfurlingTransformResult<ExtraDataType, NodePropsType>;
173
+ export declare type PasteUnfurlingTransformFunction<ExtraDataType, NodePropsType> = (event: ClipboardEvent, editor: LexicalEditor) => PasteUnfurlingTransformResult<ExtraDataType, NodePropsType> | Promise<PasteUnfurlingTransformResult<ExtraDataType, NodePropsType>>;
174
174
 
175
175
  export declare type PasteUnfurlingTransformResult<ExtraDataType, NodePropsType> = {
176
176
  handled: boolean;
@@ -53,7 +53,7 @@ export class ChatInputEntityPluginBase {
53
53
  getActiveEntities() {
54
54
  return this.__editor.getEditorState().read(() => $nodesOfType(this.__nodeClass).filter(node => node.__pluginId === this.__id).map(node => node.getEntityData()));
55
55
  }
56
- constructor(editor, id, nodeClass, $createNode, $isChatInputEntityNode, onChatInputEntityAdded, onChatInputEntityDeleted, skipInitialization = true) {
56
+ constructor(editor, id, nodeClass, $createNode, $isChatInputEntityNode, onChatInputEntityAdded, onChatInputEntityDeleted) {
57
57
  _define_property(this, "__nodeClass", void 0);
58
58
  _define_property(this, "__editor", void 0);
59
59
  _define_property(this, "__id", void 0);
@@ -113,8 +113,6 @@ export class ChatInputEntityPluginBase {
113
113
  });
114
114
  }
115
115
  }
116
- }, {
117
- skipInitialization
118
116
  }) : noop);
119
117
  }
120
118
  }
@@ -1 +1 @@
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 skipInitialization = true,\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(\n this.__nodeClass,\n (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 { skipInitialization },\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","skipInitialization","__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;IA4FAC,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,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ACtBN,OAAOuB,wBAAwB,CAC7B,IAAI,CAACzC,WAAW,EAChB,CAAC0C,OAAOC;YACN,KAAK,MAAM,CAACC,SAASC,SAAS,IAAIH,MAAO;gBACvC,IAAIlB,4BAA4BqB,aAAa,aAAa;oBACxDF,QAAQG,eAAe,CAAC/B,IAAI,CAAC;wBAC3B,MAAMb,OAAOjC,cAAc2E;wBAC3B,IAAItB,uBAAuBpB,SAASA,KAAKE,UAAU,KAAKe,IAAI;4BAC1DK,yBAAyBtB,KAAKG,aAAa,IAAIuC;wBACjD;oBACF;gBACF,OAAO,IAAIrB,0BAA0BsB,aAAa,WAAW;oBAC3D3B,OAAOJ,cAAc,GAAGC,IAAI,CAAC;wBAC3B,MAAMb,OAAOjC,cAAc2E;wBAC3B,IAAItB,uBAAuBpB,SAASA,KAAKE,UAAU,KAAKe,IAAI;4BAC1DI,uBAAuBrB,KAAKG,aAAa,IAAIuC;wBAC/C;oBACF;gBACF;YACF;QACF,GACA;YAAEnB;QAAmB,KAEvBsB;IAER;AAqEF;AAEA,SAASA;IACP;AACF"}
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;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,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"}
@@ -11,7 +11,7 @@ export class ManualGhostTextBase {
11
11
  }
12
12
  });
13
13
  }
14
- setGhostText(text, exposeText, componentProps) {
14
+ setGhostText(text, exposeText, componentProps, discrete) {
15
15
  this.__editor.update(() => {
16
16
  if (this.__nodeKey) {
17
17
  const node = $getNodeByKey(this.__nodeKey);
@@ -25,10 +25,11 @@ export class ManualGhostTextBase {
25
25
  $insertNodes([node]);
26
26
  node.selectStart();
27
27
  }, {
28
- tag: 'historic'
28
+ tag: 'historic',
29
+ discrete: discrete ? true : undefined
29
30
  });
30
31
  }
31
- commitGhostText(finalText) {
32
+ commitGhostText(finalText, discrete) {
32
33
  if (this.__nodeKey) {
33
34
  this.__editor.update(() => {
34
35
  if (this.__nodeKey) {
@@ -39,11 +40,13 @@ export class ManualGhostTextBase {
39
40
  textNode.selectEnd();
40
41
  }
41
42
  }
43
+ }, {
44
+ discrete: discrete ? true : undefined
42
45
  });
43
46
  this.__nodeKey = undefined;
44
47
  }
45
48
  }
46
- cancelGhostText() {
49
+ cancelGhostText(discrete) {
47
50
  if (this.__nodeKey) {
48
51
  this.__editor.update(() => {
49
52
  if (this.__nodeKey) {
@@ -53,7 +56,8 @@ export class ManualGhostTextBase {
53
56
  }
54
57
  }
55
58
  }, {
56
- tag: 'historic'
59
+ tag: 'historic',
60
+ discrete: discrete ? true : undefined
57
61
  });
58
62
  this.__nodeKey = undefined;
59
63
  }
@@ -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"],"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,SAAS,EAAE;gBAClB,MAAMC,OAAOR,cAAc,IAAI,CAACO,SAAS;gBACzC,IAAI,IAAI,CAACE,aAAa,CAACD,OAAO;oBAC5B,OAAOA,KAAKE,SAAS;gBACvB;YACF;QACF;IACF;IAEAC,aAAaC,IAAY,EAAEC,UAAoB,EAAEC,cAAmC,EAAQ;QAC1F,IAAI,CAACV,QAAQ,CAACW,MAAM,CAClB;YACE,IAAI,IAAI,CAACR,SAAS,EAAE;gBAClB,MAAMC,OAAOR,cAAc,IAAI,CAACO,SAAS;gBACzC,IAAI,IAAI,CAACE,aAAa,CAACD,OAAO;oBAC5BA,KAAKQ,WAAW,GAAGN,SAAS,GAAGE;oBAC/B;gBACF;YACF;YAEA,MAAMJ,OAAO,IAAI,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a,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, 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,SAAS,EAAE;gBAClB,MAAMC,OAAOR,cAAc,IAAI,CAACO,SAAS;gBACzC,IAAI,IAAI,CAACE,aAAa,CAACD,OAAO;oBAC5B,OAAOA,KAAKE,SAAS;gBACvB;YACF;QACF;IACF;IAEAC,aAAaC,IAAY,EAAEC,UAAoB,EAAE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BAAER,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,4 +1,4 @@
1
- import { PASTE_COMMAND, COMMAND_PRIORITY_HIGH, $insertNodes, $createTextNode } from '@fluentui-copilot/text-editor';
1
+ import { COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_LOW, PASTE_COMMAND, $insertNodes, $createTextNode } from '@fluentui-copilot/text-editor';
2
2
  function unhandledPart(part) {
3
3
  throw new Error(`Unhandled part: ${part}`);
4
4
  }
@@ -23,17 +23,40 @@ export function registerPasteUnfurlingPlugin(editor, props) {
23
23
  });
24
24
  }
25
25
  function handlePaste(event) {
26
+ const transformPromises = [];
26
27
  for (const transform of transforms) {
27
- const result = transform(event, editor);
28
- if (result.transformedParts) {
29
- insertParts(result.transformedParts);
28
+ transformPromises.push(Promise.resolve(transform(event, editor)));
29
+ }
30
+ Promise.allSettled(transformPromises).then(results => {
31
+ let handledPaste = false;
32
+ for (const result of results) {
33
+ if (result.status === 'fulfilled') {
34
+ const transformResult = result.value;
35
+ if (transformResult.transformedParts) {
36
+ insertParts(transformResult.transformedParts);
37
+ }
38
+ if (transformResult.handled) {
39
+ handledPaste = true;
40
+ break;
41
+ }
42
+ }
30
43
  }
31
- if (result.handled) {
32
- return true;
44
+ if (!handledPaste) {
45
+ var _commandsMap_get;
46
+ const commandsMap = editor._commands;
47
+ const defaultEditorListeners = (_commandsMap_get = commandsMap.get(PASTE_COMMAND)) === null || _commandsMap_get === void 0 ? void 0 : _commandsMap_get[COMMAND_PRIORITY_EDITOR];
48
+ if (defaultEditorListeners) {
49
+ for (const listener of defaultEditorListeners) {
50
+ const defaultHandled = listener(event, editor);
51
+ if (defaultHandled) {
52
+ break;
53
+ }
54
+ }
55
+ }
33
56
  }
34
- }
35
- return false;
57
+ });
58
+ return true;
36
59
  }
37
- return editor.registerCommand(PASTE_COMMAND, handlePaste, COMMAND_PRIORITY_HIGH);
60
+ return editor.registerCommand(PASTE_COMMAND, handlePaste, COMMAND_PRIORITY_LOW);
38
61
  }
39
62
  //# sourceMappingURL=PasteUnfurling.base.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["PasteUnfurling.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport { PASTE_COMMAND, COMMAND_PRIORITY_HIGH, $insertNodes, $createTextNode } from '@fluentui-copilot/text-editor';\nimport type { PasteUnfurlingPluginBaseProps, PasteUnfurlingTransformedPart } 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 for (const transform of transforms) {\n const result = transform(event, editor);\n\n if (result.transformedParts) {\n insertParts(result.transformedParts);\n }\n\n if (result.handled) {\n return true;\n }\n }\n\n return false;\n }\n\n return editor.registerCommand(PASTE_COMMAND, handlePaste, COMMAND_PRIORITY_HIGH);\n}\n"],"names":["PASTE_COMMAND","COMMAND_PRIORITY_HIGH","$insertNodes","$createTextNode","unhandledPart","part","Error","registerPasteUnfurlingPlugin","editor","props","entityPluginId","transforms","$createEntityNode","insertParts","parts","update","nodes","map","type","value","text","data","entityProps","handlePaste","event","transform","result","transformedParts","handled","registerCommand"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,aAAa,EAAEC,qBAAqB,EAAEC,YAAY,EAAEC,eAAe,QAAQ,gCAAgC;AAGpH,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,KAAK,MAAMC,aAAad,WAAY;YAClC,MAAMe,SAASD,UAAUD,OAAOhB;YAEhC,IAAIkB,OAAOC,gBAAgB,EAAE;gBAC3Bd,YAAYa,OAAOC,gBAAgB;YACrC;YAEA,IAAID,OAAOE,OAAO,EAAE;gBAClB,OAAO;YACT;QACF;QAEA,OAAO;IACT;IAEA,OAAOpB,OAAOqB,eAAe,CAAC7B,eAAeuB,aAAatB;AAC5D"}
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 for (const listener of defaultEditorListeners) {\n const defaultHandled = listener(event, editor);\n if (defaultHandled) {\n break;\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,KAAK,MAAME,YAAYF,uBAAwB;wBAC7C,MAAMG,iBAAiBD,SAASnB,OAAOhB;wBACvC,IAAIoC,gBAAgB;4BAClB;wBACF;oBACF;gBACF;YACF;QACF;QAEA,OAAO;IACT;IAEA,OAAOpC,OAAOqC,eAAe,CAAC5C,eAAesB,aAAavB;AAC5D"}
@@ -1 +1 @@
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) => 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":"AAiBA,WAUE"}
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"}
@@ -61,7 +61,7 @@ class ChatInputEntityPluginBase {
61
61
  getActiveEntities() {
62
62
  return this.__editor.getEditorState().read(()=>(0, _texteditor.$nodesOfType)(this.__nodeClass).filter((node)=>node.__pluginId === this.__id).map((node)=>node.getEntityData()));
63
63
  }
64
- constructor(editor, id, nodeClass, $createNode, $isChatInputEntityNode, onChatInputEntityAdded, onChatInputEntityDeleted, skipInitialization = true){
64
+ constructor(editor, id, nodeClass, $createNode, $isChatInputEntityNode, onChatInputEntityAdded, onChatInputEntityDeleted){
65
65
  (0, _define_property._)(this, "__nodeClass", void 0);
66
66
  (0, _define_property._)(this, "__editor", void 0);
67
67
  (0, _define_property._)(this, "__id", void 0);
@@ -119,8 +119,6 @@ class ChatInputEntityPluginBase {
119
119
  });
120
120
  }
121
121
  }
122
- }, {
123
- skipInitialization
124
122
  }) : noop);
125
123
  }
126
124
  }
@@ -1 +1 @@
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 skipInitialization = true,\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(\n this.__nodeClass,\n (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 { skipInitialization },\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","skipInitialization","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":";;;;+BAuBaA;;;eAAAA;;;;4BARN;AAQA,MAAMA;cAqBXC;YACE,CAAAC,QAAKA;;0BA6FPC,KAAsBC,EAAwD;YAC5EC,MAAIA;YACJ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SAAA;;;;mFAIA;gBACF,CAAAkB,KACAU,kBAAAA,IAA0BC;sBAIlB3B,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,IAAAD;;;qDAGzBvB,aAA4BT,WAAa;yCAC3C,GAAAiC,IAAA,CAAA;qCACFxC,IAAAA,yBAAA,EAAAuC;4BACFxB,uBAAAT,SAAAA,KAAAoC,UAAA,KAAA7B,IAAA;4BACFG,uBAAAV,KAAAC,aAAA,IAAAgC;wBAEF;;gBAAqB;YAI/B;QAqEF,GAAA;YAEArB;QACE,KAAAyB;IACF"}
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":["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":";;;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A;4DACnChD,EAAAA;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,IAAAD;;;qDAGzBvB,aAA4BT,WAAa;yCAC3C,GAAAiC,IAAA,CAAA;qCACFxC,IAAAA,yBAAA,EAAAuC;4BACFxB,uBAAAT,SAAAA,KAAAoC,UAAA,KAAA7B,IAAA;4BACFG,uBAAAV,KAAAC,aAAA,IAAAgC;wBACF;oBAGR;gBAqEF;YAEA;QACE,KAAAI;IACF"}
@@ -21,7 +21,7 @@ class ManualGhostTextBase {
21
21
  }
22
22
  });
23
23
  }
24
- setGhostText(text, exposeText, componentProps) {
24
+ setGhostText(text, exposeText, componentProps, discrete) {
25
25
  this.__editor.update(()=>{
26
26
  if (this.__nodeKey) {
27
27
  const node = (0, _texteditor.$getNodeByKey)(this.__nodeKey);
@@ -37,10 +37,11 @@ class ManualGhostTextBase {
37
37
  ]);
38
38
  node.selectStart();
39
39
  }, {
40
- tag: 'historic'
40
+ tag: 'historic',
41
+ discrete: discrete ? true : undefined
41
42
  });
42
43
  }
43
- commitGhostText(finalText) {
44
+ commitGhostText(finalText, discrete) {
44
45
  if (this.__nodeKey) {
45
46
  this.__editor.update(()=>{
46
47
  if (this.__nodeKey) {
@@ -51,11 +52,13 @@ class ManualGhostTextBase {
51
52
  textNode.selectEnd();
52
53
  }
53
54
  }
55
+ }, {
56
+ discrete: discrete ? true : undefined
54
57
  });
55
58
  this.__nodeKey = undefined;
56
59
  }
57
60
  }
58
- cancelGhostText() {
61
+ cancelGhostText(discrete) {
59
62
  if (this.__nodeKey) {
60
63
  this.__editor.update(()=>{
61
64
  if (this.__nodeKey) {
@@ -65,7 +68,8 @@ class ManualGhostTextBase {
65
68
  }
66
69
  }
67
70
  }, {
68
- tag: 'historic'
71
+ tag: 'historic',
72
+ discrete: discrete ? true : undefined
69
73
  });
70
74
  this.__nodeKey = undefined;
71
75
  }
@@ -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":["ManualGhostTextBase","getGhostText","__editor","getEditorState","read","__nodeKey","$getNodeByKey","__$isNodeType","__content","node","setGhostText","text","exposeText","componentProps","update","getWritable","__$createNode","__id","getKey","$insertNodes","finalText","commitGhostText","textNode","undefined","cancelGhostText","tag","editor","id","$isNodeType","$createNode","_define_property","constructor"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAgBaA;;;eAAAA;;;;4BAVN;AAUA,MAAMA;mBA8BXC;eACE,IAAO,CAAAC,QAAKA,CAAAA,cAASC,GAAAA,IAAiBC,CAAAA;oBACpC,CAAAC,SAASA,EAAAA;6BACPC,IAAAA,yBAAaA,EAAAA,IAAAA,CAAAA,SAAmBD;wBAChC,CAAAE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AA,iBAAA,KAAA;8BAEA,EAAA,IAAA,EAAA,iBAAA,KAAA;YACA,CAAAA,QAAA,GAAAwB;YACA,CAAAT,IAAA,GAAAU;YAkBE,CAAApB,aAAa,GAAGmB;YAChB,CAAAV,aAAYW,GAAAA;;kDAGd"}
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":["ManualGhostTextBase","getGhostText","__editor","getEditorState","read","__nodeKey","$getNodeByKey","__$isNodeType","__content","node","setGhostText","text","exposeText","componentProps","discrete","update","getWritable","__$createNode","__id","getKey","$insertNodes","undefined","finalText","commitGhostText","textNode","cancelGhostText","editor","id","$isNodeType","$createNode","_define_property","constructor"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAgBaA;;;eAAAA;;;;4BAVN;AAUA,MAAMA;mBA8BXC;eACE,IAAO,CAAAC,QAAKA,CAAAA,cAASC,GAAAA,IAAiBC,CAAAA;oBACpC,CAAAC,SAASA,EAAAA;6BACPC,IAAAA,yBAAaA,EAAAA,IAAAA,CAAAA,SAAmBD;wBAChC,CAAAE,aAASA,CAAAA,OAAa;gCACp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EAAU,aAC2E,KACrFE;8BAhBF,EAAA,IAAA,EAAA,QAAQ3B,KAAAA;8BACR,EAAA,IAAA,EAAA,iBAAA,KAAA;8BAEA,EAAA,IAAA,EAAA,iBAAA,KAAA;YACA,CAAAA,QAAA,GAAAwB;YACA,CAAAR,IAAA,GAAAS;YAkBE,CAAApB,aAAa,GAAGmB;YAChB,CAAAT,aAAYU,GAAAA;;kDAGd"}
@@ -29,16 +29,39 @@ function registerPasteUnfurlingPlugin(editor, props) {
29
29
  });
30
30
  }
31
31
  function handlePaste(event) {
32
+ const transformPromises = [];
32
33
  for (const transform of transforms){
33
- const result = transform(event, editor);
34
- if (result.transformedParts) {
35
- insertParts(result.transformedParts);
34
+ transformPromises.push(Promise.resolve(transform(event, editor)));
35
+ }
36
+ Promise.allSettled(transformPromises).then((results)=>{
37
+ let handledPaste = false;
38
+ for (const result of results){
39
+ if (result.status === 'fulfilled') {
40
+ const transformResult = result.value;
41
+ if (transformResult.transformedParts) {
42
+ insertParts(transformResult.transformedParts);
43
+ }
44
+ if (transformResult.handled) {
45
+ handledPaste = true;
46
+ break;
47
+ }
48
+ }
36
49
  }
37
- if (result.handled) {
38
- return true;
50
+ if (!handledPaste) {
51
+ var _commandsMap_get;
52
+ const commandsMap = editor._commands;
53
+ const defaultEditorListeners = (_commandsMap_get = commandsMap.get(_texteditor.PASTE_COMMAND)) === null || _commandsMap_get === void 0 ? void 0 : _commandsMap_get[_texteditor.COMMAND_PRIORITY_EDITOR];
54
+ if (defaultEditorListeners) {
55
+ for (const listener of defaultEditorListeners){
56
+ const defaultHandled = listener(event, editor);
57
+ if (defaultHandled) {
58
+ break;
59
+ }
60
+ }
61
+ }
39
62
  }
40
- }
41
- return false;
63
+ });
64
+ return true;
42
65
  }
43
- return editor.registerCommand(_texteditor.PASTE_COMMAND, handlePaste, _texteditor.COMMAND_PRIORITY_HIGH);
66
+ return editor.registerCommand(_texteditor.PASTE_COMMAND, handlePaste, _texteditor.COMMAND_PRIORITY_LOW);
44
67
  } //# sourceMappingURL=PasteUnfurling.base.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["PasteUnfurling.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport { PASTE_COMMAND, COMMAND_PRIORITY_HIGH, $insertNodes, $createTextNode } from '@fluentui-copilot/text-editor';\nimport type { PasteUnfurlingPluginBaseProps, PasteUnfurlingTransformedPart } 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 for (const transform of transforms) {\n const result = transform(event, editor);\n\n if (result.transformedParts) {\n insertParts(result.transformedParts);\n }\n\n if (result.handled) {\n return true;\n }\n }\n\n return false;\n }\n\n return editor.registerCommand(PASTE_COMMAND, handlePaste, COMMAND_PRIORITY_HIGH);\n}\n"],"names":["registerPasteUnfurlingPlugin","unhandledPart","part","Error","editor","props","entityPluginId","insertParts","nodes","parts","map","$createEntityNode","$insertNodes","transform","result","transforms","event","transformedParts","handled"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAQgBA;;;eAAAA;;;4BAPoE;AAGpF,SAASC,cAAcC,IAAW;UAChC,IAAMC,MAAIA,CAAAA,gBAAO,EAAgBD,KAAEA,CAAAA;AACrC;AAEO,SAASF,6BACdI,MAAqB,EACrBC,KAAkE;UAElE,EAEAC,cAASC,YACPH,mBACQI;yBAEFC,KAAK;;0BAELA,MAAKC,GAAA,CAAAR,CAAAA;gCACH;;+BAEJS,kBAAqBT,gBAAAA,KAAAA,KAAAA,CAAAA,IAAAA,EAAAA,KAAAA,KAAAA,CAAAA,IAAAA,EAAAA,KAAAA,KAAAA,CAAAA,WAAAA;yBACvB;wBACAU,OAAAA,IAAAA,2BAAaJ,EAAAA,KAAAA,KAAAA;gBACf;gBACF,OAAAP,cAAAC;YAEA;wCACO,EAAMW;;;yBAIPN,KAAYO;mBACdD,aAAAE,WAAA;kBAEAD,SAAIA,UAAcE,OAAEZ;uBAClBa,gBAAO,EAAA;4BACTH,OAAAG,gBAAA;;gBAGFH,OAAOI,OAAA,EAAA;gBACT,OAAA;YAEA;QACF"}
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 for (const listener of defaultEditorListeners) {\n const defaultHandled = listener(event, editor);\n if (defaultHandled) {\n break;\n }\n }\n }\n }\n });\n\n return true;\n }\n\n return editor.registerCommand(PASTE_COMMAND, handlePaste, COMMAND_PRIORITY_LOW);\n}\n"],"names":["registerPasteUnfurlingPlugin","unhandledPart","part","Error","editor","props","entityPluginId","insertParts","nodes","parts","map","$createEntityNode","$insertNodes","transformPromises","handlePaste","event","Promise","transform","handledPaste","result","results","transformResult","handled","transformedParts","defaultEditorListeners","defaultHandled","commandsMap","get","PASTE_COMMAND","_commandsMap_get","COMMAND_PRIORITY_EDITOR","listener"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAkBgBA;;;eAAAA;;;4BAXT;AAOP,SAASC,cAAcC,IAAW;UAChC,IAAMC,MAAIA,CAAAA,gBAAO,EAAgBD,KAAEA,CAAAA;AACrC;AAEO,SAASF,6BACdI,MAAqB,EACrBC,KAAkE;UAElE,EAEAC,cAASC,YACPH,mBACQI;yBAEFC,KAAK;;0BAELA,MAAKC,GAAA,CAAAR,CAAAA;gCACH;;+BAEJS,kBAAqBT,gBAAAA,KAAAA,KAAAA,CAAAA,IAAAA,EAAAA,KAAAA,KAAAA,CAAAA,IAAAA,EAAAA,KAAAA,KAAAA,CAAAA,WAAAA;yBACvB;wBACAU,OAAAA,IAAAA,2BAAaJ,EAAAA,KAAAA,KAAAA;gBACf;gBACF,OAAAP,cAAAC;YAEA;wCACQW,EAAAA;;;aAINC,YAAAC,KAAA;cAEAC,oBAAmBH,EAAAA;mBACjBI,aAAIC,WAAe;8BAERC,IAAAA,CAAAA,QAAUC,OAAS,CAAAH,UAAAF,OAAAX;;0BAE1B,CAAAS,mBAAMQ,IAAkBF,CAAAA,CAAAA;+BACpBE;iCACFd,QAAYc;iCACd,KAAA,aAAA;4CAEIA,OAAgBC,KAAAA;wCAClBJ,gBAAe,EAAA;oCACfG,gBAAAE,gBAAA;;wCAEJD,OAAA,EAAA;wBACFJ,eAAA;wBAEA;;;;+BAGMM;;oCAEApB,OAAMqB,SAAAA;+CACFA,CAAAA,mBAAgBC,YAAAC,GAAA,CAAAC,yBAAA,CAAA,MAAA,QAAAC,qBAAA,KAAA,IAAA,KAAA,IAAAA,gBAAA,CAAAC,mCAAA,CAAA;4CAClB;2CACFN,uBAAA;+CACFO,SAAAhB,OAAAX;4BACFqB,gBAAA;4BACF;wBACF;oBAEA;gBACF;YAEA;QACF"}
@@ -1 +1 @@
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) => 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":""}
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":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui-copilot/chat-input-plugins",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "A Fluent AI package for non-react specific chat input plugins.",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@fluentui-copilot/text-editor": "^0.1.0",
15
+ "@fluentui-copilot/text-editor": "^0.2.0",
16
16
  "@swc/helpers": "^0.5.1"
17
17
  },
18
18
  "beachball": {