@fluentui-copilot/chat-input-plugins 0.3.0 → 0.3.2
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 +43 -1
- package/CHANGELOG.md +22 -2
- package/dist/index.d.ts +8 -8
- package/lib/ManualGhostText/ManualGhostText.base.js +9 -5
- package/lib/ManualGhostText/ManualGhostText.base.js.map +1 -1
- package/lib/PasteUnfurling/PasteUnfurling.base.js +35 -9
- package/lib/PasteUnfurling/PasteUnfurling.base.js.map +1 -1
- package/lib/PasteUnfurling/PasteUnfurling.types.js.map +1 -1
- package/lib-commonjs/ManualGhostText/ManualGhostText.base.js +9 -5
- package/lib-commonjs/ManualGhostText/ManualGhostText.base.js.map +1 -1
- package/lib-commonjs/PasteUnfurling/PasteUnfurling.base.js +34 -8
- package/lib-commonjs/PasteUnfurling/PasteUnfurling.base.js.map +1 -1
- package/lib-commonjs/PasteUnfurling/PasteUnfurling.types.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,49 @@
|
|
|
2
2
|
"name": "@fluentui-copilot/chat-input-plugins",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "Wed,
|
|
5
|
+
"date": "Wed, 20 Nov 2024 23:38:32 GMT",
|
|
6
|
+
"tag": "@fluentui-copilot/chat-input-plugins_v0.3.2",
|
|
7
|
+
"version": "0.3.2",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "owcampbe@microsoft.com",
|
|
12
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
13
|
+
"commit": "0b973dffa7a48e7ea5f2ebca45c1992f83c20b12",
|
|
14
|
+
"comment": "chore: Fix Paste Unfurling default handlers."
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Thu, 31 Oct 2024 17:41:08 GMT",
|
|
21
|
+
"tag": "@fluentui-copilot/chat-input-plugins_v0.3.1",
|
|
22
|
+
"version": "0.3.1",
|
|
23
|
+
"comments": {
|
|
24
|
+
"patch": [
|
|
25
|
+
{
|
|
26
|
+
"author": "Humberto.Morimoto@microsoft.com",
|
|
27
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
28
|
+
"commit": "49fcd13f2ab4e6635394196e53ef1de79638e6d6",
|
|
29
|
+
"comment": "feat: Enabling async transforms in the PasteUnfurlingPlugin of ChatInput."
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"author": "Humberto.Morimoto@microsoft.com",
|
|
33
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
34
|
+
"commit": "db6349629aa22001ea83df218e61e6d938e04198",
|
|
35
|
+
"comment": "chore: Chaining getters into single line in paste unfurling plugin."
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"author": "owcampbe@microsoft.com",
|
|
39
|
+
"package": "@fluentui-copilot/chat-input-plugins",
|
|
40
|
+
"commit": "2bdb166cd12430b68d776c012dbb574b88e47fc8",
|
|
41
|
+
"comment": "feat: Add discrete update options to ghost text functions."
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"date": "Wed, 25 Sep 2024 19:50:22 GMT",
|
|
6
48
|
"tag": "@fluentui-copilot/chat-input-plugins_v0.3.0",
|
|
7
49
|
"version": "0.3.0",
|
|
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 Wed,
|
|
3
|
+
This log was last generated on Wed, 20 Nov 2024 23:38:32 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [0.3.2](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.3.2)
|
|
8
|
+
|
|
9
|
+
Wed, 20 Nov 2024 23:38:32 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.3.1..@fluentui-copilot/chat-input-plugins_v0.3.2)
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- chore: Fix Paste Unfurling default handlers. ([PR #2408](https://github.com/microsoft/fluentai/pull/2408) by owcampbe@microsoft.com)
|
|
15
|
+
|
|
16
|
+
## [0.3.1](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.3.1)
|
|
17
|
+
|
|
18
|
+
Thu, 31 Oct 2024 17:41:08 GMT
|
|
19
|
+
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.3.0..@fluentui-copilot/chat-input-plugins_v0.3.1)
|
|
20
|
+
|
|
21
|
+
### Patches
|
|
22
|
+
|
|
23
|
+
- feat: Enabling async transforms in the PasteUnfurlingPlugin of ChatInput. ([PR #2326](https://github.com/microsoft/fluentai/pull/2326) by Humberto.Morimoto@microsoft.com)
|
|
24
|
+
- chore: Chaining getters into single line in paste unfurling plugin. ([PR #2328](https://github.com/microsoft/fluentai/pull/2328) by Humberto.Morimoto@microsoft.com)
|
|
25
|
+
- feat: Add discrete update options to ghost text functions. ([PR #2251](https://github.com/microsoft/fluentai/pull/2251) by owcampbe@microsoft.com)
|
|
26
|
+
|
|
7
27
|
## [0.3.0](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/chat-input-plugins_v0.3.0)
|
|
8
28
|
|
|
9
|
-
Wed, 25 Sep 2024 19:
|
|
29
|
+
Wed, 25 Sep 2024 19:50:22 GMT
|
|
10
30
|
[Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/chat-input-plugins_v0.2.2..@fluentui-copilot/chat-input-plugins_v0.3.0)
|
|
11
31
|
|
|
12
32
|
### Minor changes
|
package/dist/index.d.ts
CHANGED
|
@@ -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;
|
|
@@ -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
|
|
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,EAAEC,cAAmC,EAAEC,QAAkB,EAAQ;QAC9G,IAAI,CAACX,QAAQ,CAACY,MAAM,CAClB;YACE,IAAI,IAAI,CAACT,SAAS,EAAE;gBAClB,MAAMC,OAAOR,cAAc,IAAI,CAACO,SAAS;gBACzC,IAAI,IAAI,CAACE,aAAa,CAACD,OAAO;oBAC5BA,KAAKS,WAAW,GAAGP,SAAS,GAAGE;oBAC/B;gBACF;YACF;YAEA,MAAMJ,OAAO,IAAI,CAACU,aAAa,CAAC,IAAI,CAACC,IAAI,EAAEP,MAAMC,YAAYC;YAC7D,IAAI,CAACP,SAAS,GAAGC,KAAKY,MAAM;YAC5BnB,aAAa;gBAACO;aAAK;YACnBA,KAAKa,WAAW;QAClB,GACA;YAAEC,KAAK;YAAYP,UAAUA,WAAW,OAAOQ;QAAU;IAE7D;IAEAC,gBAAgBC,SAAiB,EAAEV,QAAkB,EAAQ;QAC3D,IAAI,IAAI,CAACR,SAAS,EAAE;YAClB,IAAI,CAACH,QAAQ,CAACY,MAAM,CAClB;gBACE,IAAI,IAAI,CAACT,SAAS,EAAE;oBAClB,MAAMC,OAAOR,cAAc,IAAI,CAACO,SAAS;oBACzC,IAAI,IAAI,CAACE,aAAa,CAACD,OAAO;wBAC5B,MAAMkB,WAAW3B,gBAAgB0B;wBACjCjB,KAAKmB,OAAO,CAACD;wBACbA,SAASE,SAAS;oBACpB;gBACF;YACF,GACA;gBAAEb,UAAUA,WAAW,OAAOQ;YAAU;YAE1C,IAAI,CAAChB,SAAS,GAAGgB;QACnB;IACF;IAEAM,gBAAgBd,QAAkB,EAAQ;QACxC,IAAI,IAAI,CAACR,SAAS,EAAE;YAClB,IAAI,CAACH,QAAQ,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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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,43 @@ 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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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 (
|
|
32
|
-
|
|
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
|
+
// After the promises have resolved, we're not guaranteed to be in the same update state as the original command
|
|
50
|
+
editor.update(() => {
|
|
51
|
+
for (const listener of defaultEditorListeners) {
|
|
52
|
+
const defaultHandled = listener(event, editor);
|
|
53
|
+
if (defaultHandled) {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
33
59
|
}
|
|
34
|
-
}
|
|
35
|
-
return
|
|
60
|
+
});
|
|
61
|
+
return true;
|
|
36
62
|
}
|
|
37
|
-
return editor.registerCommand(PASTE_COMMAND, handlePaste,
|
|
63
|
+
return editor.registerCommand(PASTE_COMMAND, handlePaste, COMMAND_PRIORITY_LOW);
|
|
38
64
|
}
|
|
39
65
|
//# sourceMappingURL=PasteUnfurling.base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["PasteUnfurling.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport {
|
|
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 +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)
|
|
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"}
|
|
@@ -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
|
|
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;gCACpBC,SAAOC;;;;;iBAMfC,IAAaC,EAAYC,UAAEA,EAAoBC,cAAEA,EAAmCC,QAAEA,EAAkB;YACtG,CAAAZ,QAAKA,CAAAA,MAASa,CAAAA;oBAEV,CAAAV,SAASA,EAAAA;6BACPC,IAAAA,yBAAaA,EAAAA,IAAAA,CAAAA,SAAmBD;wBAChC,CAAAE,aAASA,CAAAA,OAAa;oCACfS,GAAAA,SAAW,GAAGR;;;;kBAKvBC,OAAMA,IAAAA,CAAAA,aAAYQ,CAAAA,IAAAA,CAAaC,IAAC,EAAKA,MAAMP,YAAMC;0BAC5CP,GAAAA,KAASc,MAAQA;wCACtBC,EAAAA;gBAAAA;aAAa;4BAACX;;;sBAGhBK,WAAA,OAAAO;;;oBAAyDC,SAAA,EAAAR,QAAA,EAAA;QAE7D,IAAA,IAAA,CAAAT,SAAA,EAAA;YAEAkB,IAAAA,CAAAA,QAAAA,CAAgBD,MAAAA,CAAAA;gBACd,IAAI,IAAI,CAACjB,SAAS,EAAE;0BACdI,OAACP,IAAAA,yBACH,EAAA,IAAA,CAAAG,SAAA;4BACE,CAAAE,aAASF,CAAAA,OAAW;yCACZI,IAAAA,2BAAOH,EAAAA;oCACT,CAAAkB;0CACIA;;;;0BAIVV,WAAA,OAAAO;;0BAEAP,GAAAA;;;oBAGNA,QAAA,EAAA;QACF,IAAA,IAAA,CAAAT,SAAA,EAAA;YAEAoB,IAAAA,CAAAA,QAAAA,CAAgBX,MAAAA,CAAAA;gBACd,IAAI,IAAI,CAACT,SAAS,EAAE;0BACdI,OAACP,IAAAA,yBACH,EAAA,IAAA,CAAAG,SAAA;4BACE,CAAAE,aAASF,CAAAA,OAAW;mCAClB;;;;;0BAMJS,WAAA,OAAAO;;0BAAmBP,GAAAA;;;gBAGvBY,MAAA,EAAAC,EAAA,EAAAC,WAAA,EAAAC,WAAA,CAAA;QACFC,IAAAA,kBAAA,EAAA,IAAA,EAAA,YAAA,KAAA;QAlFAC,IAAAA,kBACEL,EAAAA,IACAC,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,42 @@ function registerPasteUnfurlingPlugin(editor, props) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
function handlePaste(event) {
|
|
32
|
+
const transformPromises = [];
|
|
32
33
|
for (const transform of transforms){
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 (
|
|
38
|
-
|
|
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
|
+
// After the promises have resolved, we're not guaranteed to be in the same update state as the original command
|
|
56
|
+
editor.update(()=>{
|
|
57
|
+
for (const listener of defaultEditorListeners){
|
|
58
|
+
const defaultHandled = listener(event, editor);
|
|
59
|
+
if (defaultHandled) {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
39
65
|
}
|
|
40
|
-
}
|
|
41
|
-
return
|
|
66
|
+
});
|
|
67
|
+
return true;
|
|
42
68
|
}
|
|
43
|
-
return editor.registerCommand(_texteditor.PASTE_COMMAND, handlePaste, _texteditor.
|
|
69
|
+
return editor.registerCommand(_texteditor.PASTE_COMMAND, handlePaste, _texteditor.COMMAND_PRIORITY_LOW);
|
|
44
70
|
} //# sourceMappingURL=PasteUnfurling.base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["PasteUnfurling.base.ts"],"sourcesContent":["import type { LexicalEditor } from '@fluentui-copilot/text-editor';\nimport {
|
|
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":["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","update","_commands","listener","get","PASTE_COMMAND","_commandsMap_get","COMMAND_PRIORITY_EDITOR","defaultHandled"],"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;;oCAEKC,OAAOC,SAAA;+CACDC,CAAAA,mBAAYH,YAAwBI,GAAA,CAAAC,yBAAA,CAAA,MAAA,QAAAC,qBAAA,KAAA,IAAA,KAAA,IAAAA,gBAAA,CAAAC,mCAAA,CAAA;4CACvCC;oIACc;;+CAEpBR,uBAAA;mDACFG,SAAAZ,OAAAX;gDACF;gCACF;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)
|
|
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