@fluentui-copilot/react-chat-input-plugins 0.3.4 → 0.4.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,22 @@
2
2
  "name": "@fluentui-copilot/react-chat-input-plugins",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 18 Dec 2024 08:54:34 GMT",
5
+ "date": "Thu, 09 Jan 2025 01:15:37 GMT",
6
+ "tag": "@fluentui-copilot/react-chat-input-plugins_v0.4.0",
7
+ "version": "0.4.0",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "owcampbe@microsoft.com",
12
+ "package": "@fluentui-copilot/react-chat-input-plugins",
13
+ "commit": "856c6874454d673a64987b547e98359b4537927b",
14
+ "comment": "fix: Use State instead of Ref to properly reregister plugins."
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Wed, 18 Dec 2024 08:55:41 GMT",
6
21
  "tag": "@fluentui-copilot/react-chat-input-plugins_v0.3.4",
7
22
  "version": "0.3.4",
8
23
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,21 @@
1
1
  # Change Log - @fluentui-copilot/react-chat-input-plugins
2
2
 
3
- This log was last generated on Wed, 18 Dec 2024 08:54:34 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 09 Jan 2025 01:15:37 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [0.4.0](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/react-chat-input-plugins_v0.4.0)
8
+
9
+ Thu, 09 Jan 2025 01:15:37 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/react-chat-input-plugins_v0.3.4..@fluentui-copilot/react-chat-input-plugins_v0.4.0)
11
+
12
+ ### Patches
13
+
14
+ - fix: Use State instead of Ref to properly reregister plugins. ([PR #2513](https://github.com/microsoft/fluentai/pull/2513) by owcampbe@microsoft.com)
15
+
7
16
  ## [0.3.4](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/react-chat-input-plugins_v0.3.4)
8
17
 
9
- Wed, 18 Dec 2024 08:54:34 GMT
18
+ Wed, 18 Dec 2024 08:55:41 GMT
10
19
  [Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/react-chat-input-plugins_v0.3.3..@fluentui-copilot/react-chat-input-plugins_v0.3.4)
11
20
 
12
21
  ### Patches
@@ -11,55 +11,44 @@ export const BasicFunctionalityPlugin = React.forwardRef((props, ref) => {
11
11
  onPaste
12
12
  } = props;
13
13
  const [editor] = useLexicalComposerContext();
14
- const basicFunctionalityImpl = React.useRef(null);
14
+ const [basicFunctionalityImpl, setBasicFunctionalityImpl] = React.useState(null);
15
15
  useIsomorphicLayoutEffect(() => {
16
- basicFunctionalityImpl.current = new BasicFunctionalityBase(editor);
16
+ setBasicFunctionalityImpl(new BasicFunctionalityBase(editor));
17
17
  return () => {
18
- var _basicFunctionalityImpl_current;
19
- return (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.cleanup();
18
+ setBasicFunctionalityImpl(prev => {
19
+ prev === null || prev === void 0 ? void 0 : prev.cleanup();
20
+ return null;
21
+ });
20
22
  };
21
23
  }, [editor]);
22
24
  React.useImperativeHandle(ref, () => ({
23
25
  setIsDisabled(isDisabled) {
24
- var _basicFunctionalityImpl_current;
25
- (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.setIsDisabled(isDisabled);
26
+ basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.setIsDisabled(isDisabled);
26
27
  }
27
- }));
28
- // useIsomporphicLayoutEffect is used to avoid flickering on first render
28
+ }), [basicFunctionalityImpl]);
29
+ // useIsomorphicLayoutEffect is used to avoid flickering on first render
29
30
  useIsomorphicLayoutEffect(() => {
30
31
  if (defaultValue) {
31
- var _basicFunctionalityImpl_current;
32
- (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.insertDefaultValue(defaultValue);
32
+ basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.insertDefaultValue(defaultValue);
33
33
  }
34
+ // We only want to insert the defaultValue if the `editor` object is recreated, not the `basicFunctionalityImpl`
34
35
  }, [editor]);
35
36
  React.useEffect(() => {
36
- var _basicFunctionalityImpl_current;
37
- (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.activateContentCallbacks(onContentChange, onCountChanged);
38
- return () => {
39
- var _basicFunctionalityImpl_current;
40
- return (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.deactivateContentCallbacks();
41
- };
42
- }, [editor, onContentChange, onCountChanged]);
37
+ basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.activateContentCallbacks(onContentChange, onCountChanged);
38
+ return () => basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.deactivateContentCallbacks();
39
+ }, [basicFunctionalityImpl, editor, onContentChange, onCountChanged]);
43
40
  React.useEffect(() => {
44
41
  if (onPaste) {
45
- var _basicFunctionalityImpl_current;
46
- (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.activatePasteCallback(onPaste);
42
+ basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.activatePasteCallback(onPaste);
47
43
  }
48
- return () => {
49
- var _basicFunctionalityImpl_current;
50
- return (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.deactivatePasteCallback();
51
- };
52
- }, [editor, onPaste]);
44
+ return () => basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.deactivatePasteCallback();
45
+ }, [basicFunctionalityImpl, editor, onPaste]);
53
46
  React.useEffect(() => {
54
47
  if (trimWhitespace) {
55
- var _basicFunctionalityImpl_current;
56
- (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.activateTrimWhitespace();
48
+ basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.activateTrimWhitespace();
57
49
  }
58
- return () => {
59
- var _basicFunctionalityImpl_current;
60
- return (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.deactivateTrimWhitespace();
61
- };
62
- }, [editor, trimWhitespace]);
50
+ return () => basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.deactivateTrimWhitespace();
51
+ }, [basicFunctionalityImpl, editor, trimWhitespace]);
63
52
  return null;
64
53
  });
65
54
  //# sourceMappingURL=BasicFunctionality.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["BasicFunctionality.ts"],"sourcesContent":["import * as React from 'react';\nimport { useLexicalComposerContext } from '@fluentui-copilot/react-text-editor';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-components';\nimport type { IBasicFunctionalityBase } from '@fluentui-copilot/chat-input-plugins';\nimport { BasicFunctionalityBase } from '@fluentui-copilot/chat-input-plugins';\n\nexport type BasicFunctionalityPluginProps = {\n defaultValue?: string;\n // Whether or not to clear the input when only whitespace is remaining\n trimWhitespace?: boolean;\n onCountChanged?: (count: number) => void;\n onContentChange?: (value: string) => void;\n onPaste?: (event: ClipboardEvent) => void;\n};\n\nexport type BasicFunctionalityPluginRef = {\n setIsDisabled: (isDisabled: boolean) => void;\n};\n\nexport const BasicFunctionalityPlugin = React.forwardRef<BasicFunctionalityPluginRef, BasicFunctionalityPluginProps>(\n (props, ref) => {\n const { defaultValue, trimWhitespace, onCountChanged, onContentChange, onPaste } = props;\n\n const [editor] = useLexicalComposerContext();\n\n const basicFunctionalityImpl = React.useRef<IBasicFunctionalityBase | null>(null);\n\n useIsomorphicLayoutEffect(() => {\n basicFunctionalityImpl.current = new BasicFunctionalityBase(editor);\n\n return () => basicFunctionalityImpl.current?.cleanup();\n }, [editor]);\n\n React.useImperativeHandle<BasicFunctionalityPluginRef, BasicFunctionalityPluginRef>(ref, () => ({\n setIsDisabled(isDisabled: boolean) {\n basicFunctionalityImpl.current?.setIsDisabled(isDisabled);\n },\n }));\n\n // useIsomporphicLayoutEffect is used to avoid flickering on first render\n useIsomorphicLayoutEffect(() => {\n if (defaultValue) {\n basicFunctionalityImpl.current?.insertDefaultValue(defaultValue);\n }\n }, [editor]);\n\n React.useEffect(() => {\n basicFunctionalityImpl.current?.activateContentCallbacks(onContentChange, onCountChanged);\n return () => basicFunctionalityImpl.current?.deactivateContentCallbacks();\n }, [editor, onContentChange, onCountChanged]);\n\n React.useEffect(() => {\n if (onPaste) {\n basicFunctionalityImpl.current?.activatePasteCallback(onPaste);\n }\n return () => basicFunctionalityImpl.current?.deactivatePasteCallback();\n }, [editor, onPaste]);\n\n React.useEffect(() => {\n if (trimWhitespace) {\n basicFunctionalityImpl.current?.activateTrimWhitespace();\n }\n return () => basicFunctionalityImpl.current?.deactivateTrimWhitespace();\n }, [editor, trimWhitespace]);\n\n return null;\n },\n);\n"],"names":["React","useLexicalComposerContext","useIsomorphicLayoutEffect","BasicFunctionalityBase","BasicFunctionalityPlugin","forwardRef","props","ref","defaultValue","trimWhitespace","onCountChanged","onContentChange","onPaste","editor","basicFunctionalityImpl","useRef","current","cleanup","useImperativeHandle","setIsDisabled","isDisabled","insertDefaultValue","useEffect","activateContentCallbacks","deactivateContentCallbacks","activatePasteCallback","deactivatePasteCallback","activateTrimWhitespace","deactivateTrimWhitespace"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,yBAAyB,QAAQ,sCAAsC;AAChF,SAASC,yBAAyB,QAAQ,6BAA6B;AAEvE,SAASC,sBAAsB,QAAQ,uCAAuC;AAe9E,OAAO,MAAMC,2BAA2BJ,MAAMK,UAAU,CACtD,CAACC,OAAOC;IACN,MAAM,EAAEC,YAAY,EAAEC,cAAc,EAAEC,cAAc,EAAEC,eAAe,EAAEC,OAAO,EAAE,GAAGN;IAEnF,MAAM,CAACO,OAAO,GAAGZ;IAEjB,MAAMa,yBAAyBd,MAAMe,MAAM,CAAiC;IAE5Eb,0BAA0B;QACxBY,uBAAuBE,OAAO,GAAG,IAAIb,uBAAuBU;QAE5D,OAAO;gBAAMC;oBAAAA,kCAAAA,uBAAuBE,OAAO,cAA9BF,sDAAAA,gCAAgCG,OAAO;;IACtD,GAAG;QAACJ;KAAO;IAEXb,MAAMkB,mBAAmB,CAA2DX,KAAK,IAAO,CAAA;YAC9FY,eAAcC,UAAmB;oBAC/BN;iBAAAA,kCAAAA,uBAAuBE,OAAO,cAA9BF,sDAAAA,gCAAgCK,aAAa,CAACC;YAChD;QACF,CAAA;IAEA,yEAAyE;IACzElB,0BAA0B;QACxB,IAAIM,cAAc;gBAChBM;aAAAA,kCAAAA,uBAAuBE,OAAO,cAA9BF,sDAAAA,gCAAgCO,kBAAkB,CAACb;QACrD;IACF,GAAG;QAACK;KAAO;IAEXb,MAAMsB,SAAS,CAAC;YACdR;SAAAA,kCAAAA,uBAAuBE,OAAO,cAA9BF,sDAAAA,gCAAgCS,wBAAwB,CAACZ,iBAAiBD;QAC1E,OAAO;gBAAMI;oBAAAA,kCAAAA,uBAAuBE,OAAO,cAA9BF,sDAAAA,gCAAgCU,0BAA0B;;IACzE,GAAG;QAACX;QAAQF;QAAiBD;KAAe;IAE5CV,MAAMsB,SAAS,CAAC;QACd,IAAIV,SAAS;gBACXE;aAAAA,kCAAAA,uBAAuBE,OAAO,cAA9BF,sDAAAA,gCAAgCW,qBAAqB,CAACb;QACxD;QACA,OAAO;gBAAME;oBAAAA,kCAAAA,uBAAuBE,OAAO,cAA9BF,sDAAAA,gCAAgCY,uBAAuB;;IACtE,GAAG;QAACb;QAAQD;KAAQ;IAEpBZ,MAAMsB,SAAS,CAAC;QACd,IAAIb,gBAAgB;gBAClBK;aAAAA,kCAAAA,uBAAuBE,OAAO,cAA9BF,sDAAAA,gCAAgCa,sBAAsB;QACxD;QACA,OAAO;gBAAMb;oBAAAA,kCAAAA,uBAAuBE,OAAO,cAA9BF,sDAAAA,gCAAgCc,wBAAwB;;IACvE,GAAG;QAACf;QAAQJ;KAAe;IAE3B,OAAO;AACT,GACA"}
1
+ {"version":3,"sources":["BasicFunctionality.ts"],"sourcesContent":["import * as React from 'react';\nimport { useLexicalComposerContext } from '@fluentui-copilot/react-text-editor';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-components';\nimport type { IBasicFunctionalityBase } from '@fluentui-copilot/chat-input-plugins';\nimport { BasicFunctionalityBase } from '@fluentui-copilot/chat-input-plugins';\n\nexport type BasicFunctionalityPluginProps = {\n defaultValue?: string;\n // Whether or not to clear the input when only whitespace is remaining\n trimWhitespace?: boolean;\n onCountChanged?: (count: number) => void;\n onContentChange?: (value: string) => void;\n onPaste?: (event: ClipboardEvent) => void;\n};\n\nexport type BasicFunctionalityPluginRef = {\n setIsDisabled: (isDisabled: boolean) => void;\n};\n\nexport const BasicFunctionalityPlugin = React.forwardRef<BasicFunctionalityPluginRef, BasicFunctionalityPluginProps>(\n (props, ref) => {\n const { defaultValue, trimWhitespace, onCountChanged, onContentChange, onPaste } = props;\n\n const [editor] = useLexicalComposerContext();\n\n const [basicFunctionalityImpl, setBasicFunctionalityImpl] = React.useState<IBasicFunctionalityBase | null>(null);\n\n useIsomorphicLayoutEffect(() => {\n setBasicFunctionalityImpl(new BasicFunctionalityBase(editor));\n\n return () => {\n setBasicFunctionalityImpl(prev => {\n prev?.cleanup();\n return null;\n });\n };\n }, [editor]);\n\n React.useImperativeHandle<BasicFunctionalityPluginRef, BasicFunctionalityPluginRef>(\n ref,\n () => ({\n setIsDisabled(isDisabled: boolean) {\n basicFunctionalityImpl?.setIsDisabled(isDisabled);\n },\n }),\n [basicFunctionalityImpl],\n );\n\n // useIsomorphicLayoutEffect is used to avoid flickering on first render\n useIsomorphicLayoutEffect(() => {\n if (defaultValue) {\n basicFunctionalityImpl?.insertDefaultValue(defaultValue);\n }\n // We only want to insert the defaultValue if the `editor` object is recreated, not the `basicFunctionalityImpl`\n }, [editor]);\n\n React.useEffect(() => {\n basicFunctionalityImpl?.activateContentCallbacks(onContentChange, onCountChanged);\n return () => basicFunctionalityImpl?.deactivateContentCallbacks();\n }, [basicFunctionalityImpl, editor, onContentChange, onCountChanged]);\n\n React.useEffect(() => {\n if (onPaste) {\n basicFunctionalityImpl?.activatePasteCallback(onPaste);\n }\n return () => basicFunctionalityImpl?.deactivatePasteCallback();\n }, [basicFunctionalityImpl, editor, onPaste]);\n\n React.useEffect(() => {\n if (trimWhitespace) {\n basicFunctionalityImpl?.activateTrimWhitespace();\n }\n return () => basicFunctionalityImpl?.deactivateTrimWhitespace();\n }, [basicFunctionalityImpl, editor, trimWhitespace]);\n\n return null;\n },\n);\n"],"names":["React","useLexicalComposerContext","useIsomorphicLayoutEffect","BasicFunctionalityBase","BasicFunctionalityPlugin","forwardRef","props","ref","defaultValue","trimWhitespace","onCountChanged","onContentChange","onPaste","editor","basicFunctionalityImpl","setBasicFunctionalityImpl","useState","prev","cleanup","useImperativeHandle","setIsDisabled","isDisabled","insertDefaultValue","useEffect","activateContentCallbacks","deactivateContentCallbacks","activatePasteCallback","deactivatePasteCallback","activateTrimWhitespace","deactivateTrimWhitespace"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,yBAAyB,QAAQ,sCAAsC;AAChF,SAASC,yBAAyB,QAAQ,6BAA6B;AAEvE,SAASC,sBAAsB,QAAQ,uCAAuC;AAe9E,OAAO,MAAMC,2BAA2BJ,MAAMK,UAAU,CACtD,CAACC,OAAOC;IACN,MAAM,EAAEC,YAAY,EAAEC,cAAc,EAAEC,cAAc,EAAEC,eAAe,EAAEC,OAAO,EAAE,GAAGN;IAEnF,MAAM,CAACO,OAAO,GAAGZ;IAEjB,MAAM,CAACa,wBAAwBC,0BAA0B,GAAGf,MAAMgB,QAAQ,CAAiC;IAE3Gd,0BAA0B;QACxBa,0BAA0B,IAAIZ,uBAAuBU;QAErD,OAAO;YACLE,0BAA0BE,CAAAA;gBACxBA,iBAAAA,2BAAAA,KAAMC,OAAO;gBACb,OAAO;YACT;QACF;IACF,GAAG;QAACL;KAAO;IAEXb,MAAMmB,mBAAmB,CACvBZ,KACA,IAAO,CAAA;YACLa,eAAcC,UAAmB;gBAC/BP,mCAAAA,6CAAAA,uBAAwBM,aAAa,CAACC;YACxC;QACF,CAAA,GACA;QAACP;KAAuB;IAG1B,wEAAwE;IACxEZ,0BAA0B;QACxB,IAAIM,cAAc;YAChBM,mCAAAA,6CAAAA,uBAAwBQ,kBAAkB,CAACd;QAC7C;IACA,gHAAgH;IAClH,GAAG;QAACK;KAAO;IAEXb,MAAMuB,SAAS,CAAC;QACdT,mCAAAA,6CAAAA,uBAAwBU,wBAAwB,CAACb,iBAAiBD;QAClE,OAAO,IAAMI,mCAAAA,6CAAAA,uBAAwBW,0BAA0B;IACjE,GAAG;QAACX;QAAwBD;QAAQF;QAAiBD;KAAe;IAEpEV,MAAMuB,SAAS,CAAC;QACd,IAAIX,SAAS;YACXE,mCAAAA,6CAAAA,uBAAwBY,qBAAqB,CAACd;QAChD;QACA,OAAO,IAAME,mCAAAA,6CAAAA,uBAAwBa,uBAAuB;IAC9D,GAAG;QAACb;QAAwBD;QAAQD;KAAQ;IAE5CZ,MAAMuB,SAAS,CAAC;QACd,IAAId,gBAAgB;YAClBK,mCAAAA,6CAAAA,uBAAwBc,sBAAsB;QAChD;QACA,OAAO,IAAMd,mCAAAA,6CAAAA,uBAAwBe,wBAAwB;IAC/D,GAAG;QAACf;QAAwBD;QAAQJ;KAAe;IAEnD,OAAO;AACT,GACA"}
@@ -14,33 +14,31 @@ export function GhostTextPlugin(props) {
14
14
  allowCompletion
15
15
  } = props;
16
16
  const [editor] = useLexicalComposerContext();
17
- const ghostTextBase = React.useRef(null);
17
+ const [ghostTextBase, setGhostTextBase] = React.useState(null);
18
18
  React.useEffect(() => {
19
- ghostTextBase.current = new GhostTextPluginBase(editor, id, $getGhostText, GhostTextNode, $createGhostTextNode, ghostTextProps, exposeText, allowCompletion);
19
+ setGhostTextBase(new GhostTextPluginBase(editor, id, $getGhostText, GhostTextNode, $createGhostTextNode, ghostTextProps, exposeText, allowCompletion));
20
20
  return () => {
21
- var _ghostTextBase_current;
22
- (_ghostTextBase_current = ghostTextBase.current) === null || _ghostTextBase_current === void 0 ? void 0 : _ghostTextBase_current.cleanup();
21
+ setGhostTextBase(prev => {
22
+ prev === null || prev === void 0 ? void 0 : prev.cleanup();
23
+ return null;
24
+ });
23
25
  };
24
26
  },
25
27
  // We can update $getGhostText, $createGhostTextNode, ghostTextProps, exposeText, and allowCompletion without remounting
26
28
  // eslint-disable-next-line react-hooks/exhaustive-deps
27
29
  [editor, id]);
28
30
  React.useEffect(() => {
29
- var _ghostTextBase_current;
30
- (_ghostTextBase_current = ghostTextBase.current) === null || _ghostTextBase_current === void 0 ? void 0 : _ghostTextBase_current.setAllowCompletion(allowCompletion);
31
- }, [allowCompletion]);
31
+ ghostTextBase === null || ghostTextBase === void 0 ? void 0 : ghostTextBase.setAllowCompletion(allowCompletion);
32
+ }, [allowCompletion, ghostTextBase]);
32
33
  React.useEffect(() => {
33
- var _ghostTextBase_current;
34
- (_ghostTextBase_current = ghostTextBase.current) === null || _ghostTextBase_current === void 0 ? void 0 : _ghostTextBase_current.setComponentProps(ghostTextProps);
35
- }, [ghostTextProps]);
34
+ ghostTextBase === null || ghostTextBase === void 0 ? void 0 : ghostTextBase.setComponentProps(ghostTextProps);
35
+ }, [ghostTextBase, ghostTextProps]);
36
36
  React.useEffect(() => {
37
- var _ghostTextBase_current;
38
- (_ghostTextBase_current = ghostTextBase.current) === null || _ghostTextBase_current === void 0 ? void 0 : _ghostTextBase_current.setExposeText(exposeText);
39
- }, [exposeText]);
37
+ ghostTextBase === null || ghostTextBase === void 0 ? void 0 : ghostTextBase.setExposeText(exposeText);
38
+ }, [exposeText, ghostTextBase]);
40
39
  React.useEffect(() => {
41
- var _ghostTextBase_current;
42
- (_ghostTextBase_current = ghostTextBase.current) === null || _ghostTextBase_current === void 0 ? void 0 : _ghostTextBase_current.setGetGhostText($getGhostText);
43
- }, [$getGhostText]);
40
+ ghostTextBase === null || ghostTextBase === void 0 ? void 0 : ghostTextBase.setGetGhostText($getGhostText);
41
+ }, [$getGhostText, ghostTextBase]);
44
42
  return null;
45
43
  }
46
44
  //# sourceMappingURL=GhostText.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["GhostText.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useLexicalComposerContext } from '@fluentui-copilot/react-text-editor';\nimport type { LexicalEditor, EditorState } from '@fluentui-copilot/text-editor';\nimport type { GhostTextProps } from '../../GhostText';\nimport { $createGhostTextNode } from '../../GhostText';\nimport { GhostTextNode } from './GhostText.node';\nimport { GhostTextPluginBase } from '@fluentui-copilot/chat-input-plugins';\n\nexport type GhostTextPluginProps = {\n id: string;\n $getGhostText: (\n editor: LexicalEditor,\n editorState: EditorState,\n prevEditorState: EditorState,\n ) => Promise<string | undefined>;\n ghostTextProps?: GhostTextProps;\n // Whether or not the ghost text should count as text inside the input for submitting and character count\n exposeText?: boolean;\n allowCompletion?: boolean;\n};\n\nexport function GhostTextPlugin(props: GhostTextPluginProps): JSX.Element | null {\n 'use no memo';\n\n const { $getGhostText, id, ghostTextProps, exposeText, allowCompletion } = props;\n const [editor] = useLexicalComposerContext();\n\n const ghostTextBase = React.useRef<GhostTextPluginBase<GhostTextProps> | null>(null);\n\n React.useEffect(\n () => {\n ghostTextBase.current = new GhostTextPluginBase(\n editor,\n id,\n $getGhostText,\n GhostTextNode,\n $createGhostTextNode,\n ghostTextProps,\n exposeText,\n allowCompletion,\n );\n\n return () => {\n ghostTextBase.current?.cleanup();\n };\n },\n // We can update $getGhostText, $createGhostTextNode, ghostTextProps, exposeText, and allowCompletion without remounting\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [editor, id],\n );\n\n React.useEffect(() => {\n ghostTextBase.current?.setAllowCompletion(allowCompletion);\n }, [allowCompletion]);\n\n React.useEffect(() => {\n ghostTextBase.current?.setComponentProps(ghostTextProps);\n }, [ghostTextProps]);\n\n React.useEffect(() => {\n ghostTextBase.current?.setExposeText(exposeText);\n }, [exposeText]);\n\n React.useEffect(() => {\n ghostTextBase.current?.setGetGhostText($getGhostText);\n }, [$getGhostText]);\n\n return null;\n}\n"],"names":["React","useLexicalComposerContext","$createGhostTextNode","GhostTextNode","GhostTextPluginBase","GhostTextPlugin","props","$getGhostText","id","ghostTextProps","exposeText","allowCompletion","editor","ghostTextBase","useRef","useEffect","current","cleanup","setAllowCompletion","setComponentProps","setExposeText","setGetGhostText"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,yBAAyB,QAAQ,sCAAsC;AAGhF,SAASC,oBAAoB,QAAQ,kBAAkB;AACvD,SAASC,aAAa,QAAQ,mBAAmB;AACjD,SAASC,mBAAmB,QAAQ,uCAAuC;AAe3E,OAAO,SAASC,gBAAgBC,KAA2B;IACzD;IAEA,MAAM,EAAEC,aAAa,EAAEC,EAAE,EAAEC,cAAc,EAAEC,UAAU,EAAEC,eAAe,EAAE,GAAGL;IAC3E,MAAM,CAACM,OAAO,GAAGX;IAEjB,MAAMY,gBAAgBb,MAAMc,MAAM,CAA6C;IAE/Ed,MAAMe,SAAS,CACb;QACEF,cAAcG,OAAO,GAAG,IAAIZ,oBAC1BQ,QACAJ,IACAD,eACAJ,eACAD,sBACAO,gBACAC,YACAC;QAGF,OAAO;gBACLE;aAAAA,yBAAAA,cAAcG,OAAO,cAArBH,6CAAAA,uBAAuBI,OAAO;QAChC;IACF,GACA,wHAAwH;IACxH,uDAAuD;IACvD;QAACL;QAAQJ;KAAG;IAGdR,MAAMe,SAAS,CAAC;YACdF;SAAAA,yBAAAA,cAAcG,OAAO,cAArBH,6CAAAA,uBAAuBK,kBAAkB,CAACP;IAC5C,GAAG;QAACA;KAAgB;IAEpBX,MAAMe,SAAS,CAAC;YACdF;SAAAA,yBAAAA,cAAcG,OAAO,cAArBH,6CAAAA,uBAAuBM,iBAAiB,CAACV;IAC3C,GAAG;QAACA;KAAe;IAEnBT,MAAMe,SAAS,CAAC;YACdF;SAAAA,yBAAAA,cAAcG,OAAO,cAArBH,6CAAAA,uBAAuBO,aAAa,CAACV;IACvC,GAAG;QAACA;KAAW;IAEfV,MAAMe,SAAS,CAAC;YACdF;SAAAA,yBAAAA,cAAcG,OAAO,cAArBH,6CAAAA,uBAAuBQ,eAAe,CAACd;IACzC,GAAG;QAACA;KAAc;IAElB,OAAO;AACT"}
1
+ {"version":3,"sources":["GhostText.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useLexicalComposerContext } from '@fluentui-copilot/react-text-editor';\nimport type { LexicalEditor, EditorState } from '@fluentui-copilot/text-editor';\nimport type { GhostTextProps } from '../../GhostText';\nimport { $createGhostTextNode } from '../../GhostText';\nimport { GhostTextNode } from './GhostText.node';\nimport { GhostTextPluginBase } from '@fluentui-copilot/chat-input-plugins';\n\nexport type GhostTextPluginProps = {\n id: string;\n $getGhostText: (\n editor: LexicalEditor,\n editorState: EditorState,\n prevEditorState: EditorState,\n ) => Promise<string | undefined>;\n ghostTextProps?: GhostTextProps;\n // Whether or not the ghost text should count as text inside the input for submitting and character count\n exposeText?: boolean;\n allowCompletion?: boolean;\n};\n\nexport function GhostTextPlugin(props: GhostTextPluginProps): JSX.Element | null {\n 'use no memo';\n\n const { $getGhostText, id, ghostTextProps, exposeText, allowCompletion } = props;\n const [editor] = useLexicalComposerContext();\n\n const [ghostTextBase, setGhostTextBase] = React.useState<GhostTextPluginBase<GhostTextProps> | null>(null);\n\n React.useEffect(\n () => {\n setGhostTextBase(\n new GhostTextPluginBase(\n editor,\n id,\n $getGhostText,\n GhostTextNode,\n $createGhostTextNode,\n ghostTextProps,\n exposeText,\n allowCompletion,\n ),\n );\n\n return () => {\n setGhostTextBase(prev => {\n prev?.cleanup();\n return null;\n });\n };\n },\n // We can update $getGhostText, $createGhostTextNode, ghostTextProps, exposeText, and allowCompletion without remounting\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [editor, id],\n );\n\n React.useEffect(() => {\n ghostTextBase?.setAllowCompletion(allowCompletion);\n }, [allowCompletion, ghostTextBase]);\n\n React.useEffect(() => {\n ghostTextBase?.setComponentProps(ghostTextProps);\n }, [ghostTextBase, ghostTextProps]);\n\n React.useEffect(() => {\n ghostTextBase?.setExposeText(exposeText);\n }, [exposeText, ghostTextBase]);\n\n React.useEffect(() => {\n ghostTextBase?.setGetGhostText($getGhostText);\n }, [$getGhostText, ghostTextBase]);\n\n return null;\n}\n"],"names":["React","useLexicalComposerContext","$createGhostTextNode","GhostTextNode","GhostTextPluginBase","GhostTextPlugin","props","$getGhostText","id","ghostTextProps","exposeText","allowCompletion","editor","ghostTextBase","setGhostTextBase","useState","useEffect","prev","cleanup","setAllowCompletion","setComponentProps","setExposeText","setGetGhostText"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,yBAAyB,QAAQ,sCAAsC;AAGhF,SAASC,oBAAoB,QAAQ,kBAAkB;AACvD,SAASC,aAAa,QAAQ,mBAAmB;AACjD,SAASC,mBAAmB,QAAQ,uCAAuC;AAe3E,OAAO,SAASC,gBAAgBC,KAA2B;IACzD;IAEA,MAAM,EAAEC,aAAa,EAAEC,EAAE,EAAEC,cAAc,EAAEC,UAAU,EAAEC,eAAe,EAAE,GAAGL;IAC3E,MAAM,CAACM,OAAO,GAAGX;IAEjB,MAAM,CAACY,eAAeC,iBAAiB,GAAGd,MAAMe,QAAQ,CAA6C;IAErGf,MAAMgB,SAAS,CACb;QACEF,iBACE,IAAIV,oBACFQ,QACAJ,IACAD,eACAJ,eACAD,sBACAO,gBACAC,YACAC;QAIJ,OAAO;YACLG,iBAAiBG,CAAAA;gBACfA,iBAAAA,2BAAAA,KAAMC,OAAO;gBACb,OAAO;YACT;QACF;IACF,GACA,wHAAwH;IACxH,uDAAuD;IACvD;QAACN;QAAQJ;KAAG;IAGdR,MAAMgB,SAAS,CAAC;QACdH,0BAAAA,oCAAAA,cAAeM,kBAAkB,CAACR;IACpC,GAAG;QAACA;QAAiBE;KAAc;IAEnCb,MAAMgB,SAAS,CAAC;QACdH,0BAAAA,oCAAAA,cAAeO,iBAAiB,CAACX;IACnC,GAAG;QAACI;QAAeJ;KAAe;IAElCT,MAAMgB,SAAS,CAAC;QACdH,0BAAAA,oCAAAA,cAAeQ,aAAa,CAACX;IAC/B,GAAG;QAACA;QAAYG;KAAc;IAE9Bb,MAAMgB,SAAS,CAAC;QACdH,0BAAAA,oCAAAA,cAAeS,eAAe,CAACf;IACjC,GAAG;QAACA;QAAeM;KAAc;IAEjC,OAAO;AACT"}
@@ -16,66 +16,60 @@ const _chatinputplugins = require("@fluentui-copilot/chat-input-plugins");
16
16
  const BasicFunctionalityPlugin = /*#__PURE__*/ _react.forwardRef((props, ref)=>{
17
17
  const { defaultValue, trimWhitespace, onCountChanged, onContentChange, onPaste } = props;
18
18
  const [editor] = (0, _reacttexteditor.useLexicalComposerContext)();
19
- const basicFunctionalityImpl = _react.useRef(null);
19
+ const [basicFunctionalityImpl, setBasicFunctionalityImpl] = _react.useState(null);
20
20
  (0, _reactcomponents.useIsomorphicLayoutEffect)(()=>{
21
- basicFunctionalityImpl.current = new _chatinputplugins.BasicFunctionalityBase(editor);
21
+ setBasicFunctionalityImpl(new _chatinputplugins.BasicFunctionalityBase(editor));
22
22
  return ()=>{
23
- var _basicFunctionalityImpl_current;
24
- return (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.cleanup();
23
+ setBasicFunctionalityImpl((prev)=>{
24
+ prev === null || prev === void 0 ? void 0 : prev.cleanup();
25
+ return null;
26
+ });
25
27
  };
26
28
  }, [
27
29
  editor
28
30
  ]);
29
31
  _react.useImperativeHandle(ref, ()=>({
30
32
  setIsDisabled (isDisabled) {
31
- var _basicFunctionalityImpl_current;
32
- (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.setIsDisabled(isDisabled);
33
+ basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.setIsDisabled(isDisabled);
33
34
  }
34
- }));
35
- // useIsomporphicLayoutEffect is used to avoid flickering on first render
35
+ }), [
36
+ basicFunctionalityImpl
37
+ ]);
38
+ // useIsomorphicLayoutEffect is used to avoid flickering on first render
36
39
  (0, _reactcomponents.useIsomorphicLayoutEffect)(()=>{
37
40
  if (defaultValue) {
38
- var _basicFunctionalityImpl_current;
39
- (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.insertDefaultValue(defaultValue);
41
+ basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.insertDefaultValue(defaultValue);
40
42
  }
43
+ // We only want to insert the defaultValue if the `editor` object is recreated, not the `basicFunctionalityImpl`
41
44
  }, [
42
45
  editor
43
46
  ]);
44
47
  _react.useEffect(()=>{
45
- var _basicFunctionalityImpl_current;
46
- (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.activateContentCallbacks(onContentChange, onCountChanged);
47
- return ()=>{
48
- var _basicFunctionalityImpl_current;
49
- return (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.deactivateContentCallbacks();
50
- };
48
+ basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.activateContentCallbacks(onContentChange, onCountChanged);
49
+ return ()=>basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.deactivateContentCallbacks();
51
50
  }, [
51
+ basicFunctionalityImpl,
52
52
  editor,
53
53
  onContentChange,
54
54
  onCountChanged
55
55
  ]);
56
56
  _react.useEffect(()=>{
57
57
  if (onPaste) {
58
- var _basicFunctionalityImpl_current;
59
- (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.activatePasteCallback(onPaste);
58
+ basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.activatePasteCallback(onPaste);
60
59
  }
61
- return ()=>{
62
- var _basicFunctionalityImpl_current;
63
- return (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.deactivatePasteCallback();
64
- };
60
+ return ()=>basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.deactivatePasteCallback();
65
61
  }, [
62
+ basicFunctionalityImpl,
66
63
  editor,
67
64
  onPaste
68
65
  ]);
69
66
  _react.useEffect(()=>{
70
67
  if (trimWhitespace) {
71
- var _basicFunctionalityImpl_current;
72
- (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.activateTrimWhitespace();
68
+ basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.activateTrimWhitespace();
73
69
  }
74
- return ()=>{
75
- var _basicFunctionalityImpl_current;
76
- return (_basicFunctionalityImpl_current = basicFunctionalityImpl.current) === null || _basicFunctionalityImpl_current === void 0 ? void 0 : _basicFunctionalityImpl_current.deactivateTrimWhitespace();
77
- };
70
+ return ()=>basicFunctionalityImpl === null || basicFunctionalityImpl === void 0 ? void 0 : basicFunctionalityImpl.deactivateTrimWhitespace();
78
71
  }, [
72
+ basicFunctionalityImpl,
79
73
  editor,
80
74
  trimWhitespace
81
75
  ]);
@@ -1 +1 @@
1
- {"version":3,"sources":["BasicFunctionality.ts"],"sourcesContent":["import * as React from 'react';\nimport { useLexicalComposerContext } from '@fluentui-copilot/react-text-editor';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-components';\nimport type { IBasicFunctionalityBase } from '@fluentui-copilot/chat-input-plugins';\nimport { BasicFunctionalityBase } from '@fluentui-copilot/chat-input-plugins';\n\nexport type BasicFunctionalityPluginProps = {\n defaultValue?: string;\n // Whether or not to clear the input when only whitespace is remaining\n trimWhitespace?: boolean;\n onCountChanged?: (count: number) => void;\n onContentChange?: (value: string) => void;\n onPaste?: (event: ClipboardEvent) => void;\n};\n\nexport type BasicFunctionalityPluginRef = {\n setIsDisabled: (isDisabled: boolean) => void;\n};\n\nexport const BasicFunctionalityPlugin = React.forwardRef<BasicFunctionalityPluginRef, BasicFunctionalityPluginProps>(\n (props, ref) => {\n const { defaultValue, trimWhitespace, onCountChanged, onContentChange, onPaste } = props;\n\n const [editor] = useLexicalComposerContext();\n\n const basicFunctionalityImpl = React.useRef<IBasicFunctionalityBase | null>(null);\n\n useIsomorphicLayoutEffect(() => {\n basicFunctionalityImpl.current = new BasicFunctionalityBase(editor);\n\n return () => basicFunctionalityImpl.current?.cleanup();\n }, [editor]);\n\n React.useImperativeHandle<BasicFunctionalityPluginRef, BasicFunctionalityPluginRef>(ref, () => ({\n setIsDisabled(isDisabled: boolean) {\n basicFunctionalityImpl.current?.setIsDisabled(isDisabled);\n },\n }));\n\n // useIsomporphicLayoutEffect is used to avoid flickering on first render\n useIsomorphicLayoutEffect(() => {\n if (defaultValue) {\n basicFunctionalityImpl.current?.insertDefaultValue(defaultValue);\n }\n }, [editor]);\n\n React.useEffect(() => {\n basicFunctionalityImpl.current?.activateContentCallbacks(onContentChange, onCountChanged);\n return () => basicFunctionalityImpl.current?.deactivateContentCallbacks();\n }, [editor, onContentChange, onCountChanged]);\n\n React.useEffect(() => {\n if (onPaste) {\n basicFunctionalityImpl.current?.activatePasteCallback(onPaste);\n }\n return () => basicFunctionalityImpl.current?.deactivatePasteCallback();\n }, [editor, onPaste]);\n\n React.useEffect(() => {\n if (trimWhitespace) {\n basicFunctionalityImpl.current?.activateTrimWhitespace();\n }\n return () => basicFunctionalityImpl.current?.deactivateTrimWhitespace();\n }, [editor, trimWhitespace]);\n\n return null;\n },\n);\n"],"names":["BasicFunctionalityPlugin","React","forwardRef","props","ref","defaultValue","editor","trimWhitespace","basicFunctionalityImpl","useIsomorphicLayoutEffect","useImperativeHandle","setIsDisabled","current","_basicFunctionalityImpl_current","cleanup","isDisabled","insertDefaultValue","deactivateContentCallbacks","onContentChange","onCountChanged","onPaste","useEffect","activatePasteCallback","deactivatePasteCallback"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAmBaA;;;eAAAA;;;;iEAnBU;iCACmB;iCACA;kCAEH;AAehC,MAAMA,yCAA2BC,OAAMC,UAAU,CACtD,CAACC,OAAOC;UACN,EAEAC,YAAOC,EAEPC,cAAMC,EAENC,cAAAA,iBACED,SAEA;mEAAaA;;kDACZ,EAAA;+BAACF,OAAAA,GAAAA,IAAAA,wCAAAA,CAAAA;eAAO;YAEXL,IAAMS;mBACJC,CAAAA,kCAAiCH,uBAAAI,OAAA,MAAA,QAAAC,oCAAA,KAAA,IAAA,KAAA,IAAAA,gCAAAC,OAAA;;;;;8BAEjC,CAAAV,KAAA,IAAA,CAAA;2BACFW,UAAA;gBAEA,IAAAF;gBACAJ,CAAAA,kCAA0BD,uBAAAI,OAAA,MAAA,QAAAC,oCAAA,KAAA,IAAA,KAAA,IAAAA,gCAAAF,aAAA,CAAAI;;;6EAECH;kDACzB,EAAA;QACF,IAAGP,cAAA;gBAACC;YAAOO,CAAAA,kCAAAL,uBAAAI,OAAA,MAAA,QAAAC,oCAAA,KAAA,IAAA,KAAA,IAAAA,gCAAAG,kBAAA,CAAAX;QAEXJ;;;KACEO;oBAAAA,CAAAA;YACAK;2CAAaL,uBAAAA,OAAAA,MAAAA,QAAAA,oCAAAA,KAAAA,IAAAA,KAAAA,IAAAA,gCAAAA,wBAAAA,CAAAA,iBAAAA;;;YACf,OAAG,AAAAK,CAAAA,kCAAAL,uBAAAI,OAAA,MAAA,QAAAC,oCAAA,KAAA,IAAA,KAAA,IAAAA,gCAAAI,0BAAA;;;;QAASC;QAAAA;KAAAA;WAAiBC,SAAAA,CAAAA;YAAeC,SAAA;YAE5CnB,IAAMoB;+CACSb,uBAAAI,OAAA,MAAA,QAAAC,oCAAA,KAAA,IAAA,KAAA,IAAAA,gCAAAS,qBAAA,CAAAF;;;gBAEbP;mBACA,AAAAA,CAAAA,kCAAOL,uBAAAI,OAAA,MAAA,QAAAC,oCAAA,KAAA,IAAA,KAAA,IAAAA,gCAAAU,uBAAA;;;;;KAAMf;;QACf,IAAGD,gBAAA;gBAACD;+CAAQc,uBAAAA,OAAAA,MAAAA,QAAAA,oCAAAA,KAAAA,IAAAA,KAAAA,IAAAA,gCAAAA,sBAAAA;;QAEZnB,OAAMoB;gBACJR;sDACEL,uBAAAA,OAAAA,MAAAA,QAAAA,oCAAAA,KAAAA,IAAAA,KAAAA,IAAAA,gCAAAA,wBAAAA;;;;QACFD;KAAA;WACA;kDAAaC"}
1
+ {"version":3,"sources":["BasicFunctionality.ts"],"sourcesContent":["import * as React from 'react';\nimport { useLexicalComposerContext } from '@fluentui-copilot/react-text-editor';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-components';\nimport type { IBasicFunctionalityBase } from '@fluentui-copilot/chat-input-plugins';\nimport { BasicFunctionalityBase } from '@fluentui-copilot/chat-input-plugins';\n\nexport type BasicFunctionalityPluginProps = {\n defaultValue?: string;\n // Whether or not to clear the input when only whitespace is remaining\n trimWhitespace?: boolean;\n onCountChanged?: (count: number) => void;\n onContentChange?: (value: string) => void;\n onPaste?: (event: ClipboardEvent) => void;\n};\n\nexport type BasicFunctionalityPluginRef = {\n setIsDisabled: (isDisabled: boolean) => void;\n};\n\nexport const BasicFunctionalityPlugin = React.forwardRef<BasicFunctionalityPluginRef, BasicFunctionalityPluginProps>(\n (props, ref) => {\n const { defaultValue, trimWhitespace, onCountChanged, onContentChange, onPaste } = props;\n\n const [editor] = useLexicalComposerContext();\n\n const [basicFunctionalityImpl, setBasicFunctionalityImpl] = React.useState<IBasicFunctionalityBase | null>(null);\n\n useIsomorphicLayoutEffect(() => {\n setBasicFunctionalityImpl(new BasicFunctionalityBase(editor));\n\n return () => {\n setBasicFunctionalityImpl(prev => {\n prev?.cleanup();\n return null;\n });\n };\n }, [editor]);\n\n React.useImperativeHandle<BasicFunctionalityPluginRef, BasicFunctionalityPluginRef>(\n ref,\n () => ({\n setIsDisabled(isDisabled: boolean) {\n basicFunctionalityImpl?.setIsDisabled(isDisabled);\n },\n }),\n [basicFunctionalityImpl],\n );\n\n // useIsomorphicLayoutEffect is used to avoid flickering on first render\n useIsomorphicLayoutEffect(() => {\n if (defaultValue) {\n basicFunctionalityImpl?.insertDefaultValue(defaultValue);\n }\n // We only want to insert the defaultValue if the `editor` object is recreated, not the `basicFunctionalityImpl`\n }, [editor]);\n\n React.useEffect(() => {\n basicFunctionalityImpl?.activateContentCallbacks(onContentChange, onCountChanged);\n return () => basicFunctionalityImpl?.deactivateContentCallbacks();\n }, [basicFunctionalityImpl, editor, onContentChange, onCountChanged]);\n\n React.useEffect(() => {\n if (onPaste) {\n basicFunctionalityImpl?.activatePasteCallback(onPaste);\n }\n return () => basicFunctionalityImpl?.deactivatePasteCallback();\n }, [basicFunctionalityImpl, editor, onPaste]);\n\n React.useEffect(() => {\n if (trimWhitespace) {\n basicFunctionalityImpl?.activateTrimWhitespace();\n }\n return () => basicFunctionalityImpl?.deactivateTrimWhitespace();\n }, [basicFunctionalityImpl, editor, trimWhitespace]);\n\n return null;\n },\n);\n"],"names":["BasicFunctionalityPlugin","React","forwardRef","props","ref","defaultValue","editor","trimWhitespace","basicFunctionalityImpl","useIsomorphicLayoutEffect","setBasicFunctionalityImpl","prev","useState","BasicFunctionalityBase","cleanup","useImperativeHandle","setIsDisabled","isDisabled","insertDefaultValue","useEffect","activateContentCallbacks","onContentChange","deactivateContentCallbacks","onCountChanged","deactivatePasteCallback","onPaste","activateTrimWhitespace","deactivateTrimWhitespace"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAmBaA;;;eAAAA;;;;iEAnBU;iCACmB;iCACA;kCAEH;AAehC,MAAMA,yCAA2BC,OAAMC,UAAU,CACtD,CAACC,OAAOC;UACN,EAEAC,YAAOC,EAEPC,cAAOC,EAEPC,cAAAA,iBACEC,SAEA;kBAEIC,GAAAA,IAAAA,0CAAAA;mCACOD,0BAAA,GAAAT,OAAAW,QAAA,CAAA;kDACT,EAAA;kCACF,IAAAC,wCAAA,CAAAP;QACF,OAAG;sCAACA,CAAAA;gBAAOK,SAAA,QAAAA,SAAA,KAAA,IAAA,KAAA,IAAAA,KAAAG,OAAA;gBAEXb,OAAMc;;;;;KAKF;WACFA,mBACA,CAAAX,KAAA,IAAA,CAAA;2BAACI,UAAAA;gBAAuBA,2BAAA,QAAAA,2BAAA,KAAA,IAAA,KAAA,IAAAA,uBAAAQ,aAAA,CAAAC;YAG1B;YACAR;QAAAA;KAA0B;4EACN;kDAChBD,EAAAA;YACFH,cAAA;YACAG,2BAAA,QAAAA,2BAAA,KAAA,IAAA,KAAA,IAAAA,uBAAAU,kBAAgH,CAAAb;QAClH;oHAAIC;OAAO;QAAAA;KAAA;WAEXL,SAAMkB,CAAAA;mCACJX,QAAAA,2BAAAA,KAAAA,IAAAA,KAAAA,IAAAA,uBAAAA,wBAAwBY,CAAAA,iBAAyBC;eACjD,IAAOb,2BAAMA,QAAAA,2BAAAA,KAAAA,IAAAA,KAAAA,IAAAA,uBAAAA,0BAAwBc;OACvC;QAAAd;QAAGF;QAAAe;QAAAE;KAAA;WAACf,SAAAA,CAAAA;YAAwBF,SAAAA;uCAAQe,QAAAA,2BAAAA,KAAAA,IAAAA,KAAAA,IAAAA,uBAAAA,qBAAAA,CAAAA;;eAAgC,IAAAb,2BAAA,QAAAA,2BAAA,KAAA,IAAA,KAAA,IAAAA,uBAAAgB,uBAAA;OAEpEvB;QAAAA;QAAgBK;QAAAmB;KAAA;WACdN,SAAIM,CAAAA;4BACFjB;uCACF,QAAAA,2BAAA,KAAA,IAAA,KAAA,IAAAA,uBAAAkB,sBAAA;;QAEF,OAAG,IAAAlB,2BAAA,QAAAA,2BAAA,KAAA,IAAA,KAAA,IAAAA,uBAAAmB,wBAAA;;;QAACnB;QAAAA;KAAAA;WAAwBF;kDAAgB"}
@@ -18,12 +18,14 @@ function GhostTextPlugin(props) {
18
18
  'use no memo';
19
19
  const { $getGhostText, id, ghostTextProps, exposeText, allowCompletion } = props;
20
20
  const [editor] = (0, _reacttexteditor.useLexicalComposerContext)();
21
- const ghostTextBase = _react.useRef(null);
21
+ const [ghostTextBase, setGhostTextBase] = _react.useState(null);
22
22
  _react.useEffect(()=>{
23
- ghostTextBase.current = new _chatinputplugins.GhostTextPluginBase(editor, id, $getGhostText, _GhostTextnode.GhostTextNode, _GhostText.$createGhostTextNode, ghostTextProps, exposeText, allowCompletion);
23
+ setGhostTextBase(new _chatinputplugins.GhostTextPluginBase(editor, id, $getGhostText, _GhostTextnode.GhostTextNode, _GhostText.$createGhostTextNode, ghostTextProps, exposeText, allowCompletion));
24
24
  return ()=>{
25
- var _ghostTextBase_current;
26
- (_ghostTextBase_current = ghostTextBase.current) === null || _ghostTextBase_current === void 0 ? void 0 : _ghostTextBase_current.cleanup();
25
+ setGhostTextBase((prev)=>{
26
+ prev === null || prev === void 0 ? void 0 : prev.cleanup();
27
+ return null;
28
+ });
27
29
  };
28
30
  }, // We can update $getGhostText, $createGhostTextNode, ghostTextProps, exposeText, and allowCompletion without remounting
29
31
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -32,28 +34,28 @@ function GhostTextPlugin(props) {
32
34
  id
33
35
  ]);
34
36
  _react.useEffect(()=>{
35
- var _ghostTextBase_current;
36
- (_ghostTextBase_current = ghostTextBase.current) === null || _ghostTextBase_current === void 0 ? void 0 : _ghostTextBase_current.setAllowCompletion(allowCompletion);
37
+ ghostTextBase === null || ghostTextBase === void 0 ? void 0 : ghostTextBase.setAllowCompletion(allowCompletion);
37
38
  }, [
38
- allowCompletion
39
+ allowCompletion,
40
+ ghostTextBase
39
41
  ]);
40
42
  _react.useEffect(()=>{
41
- var _ghostTextBase_current;
42
- (_ghostTextBase_current = ghostTextBase.current) === null || _ghostTextBase_current === void 0 ? void 0 : _ghostTextBase_current.setComponentProps(ghostTextProps);
43
+ ghostTextBase === null || ghostTextBase === void 0 ? void 0 : ghostTextBase.setComponentProps(ghostTextProps);
43
44
  }, [
45
+ ghostTextBase,
44
46
  ghostTextProps
45
47
  ]);
46
48
  _react.useEffect(()=>{
47
- var _ghostTextBase_current;
48
- (_ghostTextBase_current = ghostTextBase.current) === null || _ghostTextBase_current === void 0 ? void 0 : _ghostTextBase_current.setExposeText(exposeText);
49
+ ghostTextBase === null || ghostTextBase === void 0 ? void 0 : ghostTextBase.setExposeText(exposeText);
49
50
  }, [
50
- exposeText
51
+ exposeText,
52
+ ghostTextBase
51
53
  ]);
52
54
  _react.useEffect(()=>{
53
- var _ghostTextBase_current;
54
- (_ghostTextBase_current = ghostTextBase.current) === null || _ghostTextBase_current === void 0 ? void 0 : _ghostTextBase_current.setGetGhostText($getGhostText);
55
+ ghostTextBase === null || ghostTextBase === void 0 ? void 0 : ghostTextBase.setGetGhostText($getGhostText);
55
56
  }, [
56
- $getGhostText
57
+ $getGhostText,
58
+ ghostTextBase
57
59
  ]);
58
60
  return null;
59
61
  } //# sourceMappingURL=GhostText.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["GhostText.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useLexicalComposerContext } from '@fluentui-copilot/react-text-editor';\nimport type { LexicalEditor, EditorState } from '@fluentui-copilot/text-editor';\nimport type { GhostTextProps } from '../../GhostText';\nimport { $createGhostTextNode } from '../../GhostText';\nimport { GhostTextNode } from './GhostText.node';\nimport { GhostTextPluginBase } from '@fluentui-copilot/chat-input-plugins';\n\nexport type GhostTextPluginProps = {\n id: string;\n $getGhostText: (\n editor: LexicalEditor,\n editorState: EditorState,\n prevEditorState: EditorState,\n ) => Promise<string | undefined>;\n ghostTextProps?: GhostTextProps;\n // Whether or not the ghost text should count as text inside the input for submitting and character count\n exposeText?: boolean;\n allowCompletion?: boolean;\n};\n\nexport function GhostTextPlugin(props: GhostTextPluginProps): JSX.Element | null {\n 'use no memo';\n\n const { $getGhostText, id, ghostTextProps, exposeText, allowCompletion } = props;\n const [editor] = useLexicalComposerContext();\n\n const ghostTextBase = React.useRef<GhostTextPluginBase<GhostTextProps> | null>(null);\n\n React.useEffect(\n () => {\n ghostTextBase.current = new GhostTextPluginBase(\n editor,\n id,\n $getGhostText,\n GhostTextNode,\n $createGhostTextNode,\n ghostTextProps,\n exposeText,\n allowCompletion,\n );\n\n return () => {\n ghostTextBase.current?.cleanup();\n };\n },\n // We can update $getGhostText, $createGhostTextNode, ghostTextProps, exposeText, and allowCompletion without remounting\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [editor, id],\n );\n\n React.useEffect(() => {\n ghostTextBase.current?.setAllowCompletion(allowCompletion);\n }, [allowCompletion]);\n\n React.useEffect(() => {\n ghostTextBase.current?.setComponentProps(ghostTextProps);\n }, [ghostTextProps]);\n\n React.useEffect(() => {\n ghostTextBase.current?.setExposeText(exposeText);\n }, [exposeText]);\n\n React.useEffect(() => {\n ghostTextBase.current?.setGetGhostText($getGhostText);\n }, [$getGhostText]);\n\n return null;\n}\n"],"names":["GhostTextPlugin","props","$getGhostText","ghostTextBase","React","editor","useLexicalComposerContext","useRef","useEffect","current","GhostTextPluginBase","id","GhostTextNode","$createGhostTextNode","ghostTextProps","exposeText","allowCompletion","_ghostTextBase_current","cleanup","setComponentProps","setExposeText"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAqBgBA;;;eAAAA;;;;iEArBO;iCACmB;2BAGL;+BACP;kCACM;AAe7B,SAASA,gBAAgBC,KAA2B;;UAIzD,EAEAC,aAAMC,EAENC,EAAAA,gBAEID,YAWA,iBACEA;UACF,CAAAE,OAAA,GAAAC,IAAAA,0CAAA;UAEFH,gBAAAC,OAAAG,MAAA,CAAA;WACAC,SAAA,CAAA;QACAL,cAAAM,OAAA,GAAA,IAAAC,qCAAA,CAAAL,QAAAM,IAAAT,eAAAU,4BAAA,EAAAC,+BAAA,EAAAC,gBAAAC,YAAAC;eAACX;gBAAQM;YAAGM,CAAAA,yBAAAd,cAAAM,OAAA,MAAA,QAAAQ,2BAAA,KAAA,IAAA,KAAA,IAAAA,uBAAAC,OAAA;QAGdd;+HACED;2DACC;;;QAACa;KAAAA;WAAgBR,SAAA,CAAA;QAEpBJ,IAAAA;kCACED,cAAAA,OAAAA,MAAAA,QAAAA,2BAAAA,KAAAA,IAAAA,KAAAA,IAAAA,uBAAAA,kBAAAA,CAAAA;;;KAAAA;WACCK,SAAA,CAAA;YAACM;QAAeG,CAAAA,yBAAAd,cAAAM,OAAA,MAAA,QAAAQ,2BAAA,KAAA,IAAA,KAAA,IAAAA,uBAAAE,iBAAA,CAAAL;OAEnBV;QAAAA;KAAgB;oBACdD,CAAAA;;QACFc,CAAAA,yBAAGd,cAAAM,OAAA,MAAA,QAAAQ,2BAAA,KAAA,IAAA,KAAA,IAAAA,uBAAAG,aAAA,CAAAL;;;KAACA;WAAWP,SAAA,CAAA;QAEfJ,IAAAA;kCACED,cAAAA,OAAAA,MAAAA,QAAAA,2BAAAA,KAAAA,IAAAA,KAAAA,IAAAA,uBAAAA,eAAAA,CAAAA;;;KAAAA;WACC;uCAAe"}
1
+ {"version":3,"sources":["GhostText.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useLexicalComposerContext } from '@fluentui-copilot/react-text-editor';\nimport type { LexicalEditor, EditorState } from '@fluentui-copilot/text-editor';\nimport type { GhostTextProps } from '../../GhostText';\nimport { $createGhostTextNode } from '../../GhostText';\nimport { GhostTextNode } from './GhostText.node';\nimport { GhostTextPluginBase } from '@fluentui-copilot/chat-input-plugins';\n\nexport type GhostTextPluginProps = {\n id: string;\n $getGhostText: (\n editor: LexicalEditor,\n editorState: EditorState,\n prevEditorState: EditorState,\n ) => Promise<string | undefined>;\n ghostTextProps?: GhostTextProps;\n // Whether or not the ghost text should count as text inside the input for submitting and character count\n exposeText?: boolean;\n allowCompletion?: boolean;\n};\n\nexport function GhostTextPlugin(props: GhostTextPluginProps): JSX.Element | null {\n 'use no memo';\n\n const { $getGhostText, id, ghostTextProps, exposeText, allowCompletion } = props;\n const [editor] = useLexicalComposerContext();\n\n const [ghostTextBase, setGhostTextBase] = React.useState<GhostTextPluginBase<GhostTextProps> | null>(null);\n\n React.useEffect(\n () => {\n setGhostTextBase(\n new GhostTextPluginBase(\n editor,\n id,\n $getGhostText,\n GhostTextNode,\n $createGhostTextNode,\n ghostTextProps,\n exposeText,\n allowCompletion,\n ),\n );\n\n return () => {\n setGhostTextBase(prev => {\n prev?.cleanup();\n return null;\n });\n };\n },\n // We can update $getGhostText, $createGhostTextNode, ghostTextProps, exposeText, and allowCompletion without remounting\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [editor, id],\n );\n\n React.useEffect(() => {\n ghostTextBase?.setAllowCompletion(allowCompletion);\n }, [allowCompletion, ghostTextBase]);\n\n React.useEffect(() => {\n ghostTextBase?.setComponentProps(ghostTextProps);\n }, [ghostTextBase, ghostTextProps]);\n\n React.useEffect(() => {\n ghostTextBase?.setExposeText(exposeText);\n }, [exposeText, ghostTextBase]);\n\n React.useEffect(() => {\n ghostTextBase?.setGetGhostText($getGhostText);\n }, [$getGhostText, ghostTextBase]);\n\n return null;\n}\n"],"names":["GhostTextPlugin","props","$getGhostText","ghostTextBase","React","setGhostTextBase","useLexicalComposerContext","useState","useEffect","GhostTextPluginBase","editor","id","GhostTextNode","$createGhostTextNode","ghostTextProps","exposeText","allowCompletion","prev","setAllowCompletion","setExposeText"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAqBgBA;;;eAAAA;;;;iEArBO;iCACmB;2BAGL;+BACP;kCACM;AAe7B,SAASA,gBAAgBC,KAA2B;;UAIzD,EAEAC,aAAOC,EAEPC,EAAAA,gBAEIC,YAaA,iBACEA;kBAEE,GAAAC,IAAAA,0CAAO;0BACTD,iBAAA,GAAAD,OAAAG,QAAA,CAAA;WACFC,SAAA,CAAA;QACFH,iBACA,IAAAI,qCAAA,CAAAC,QAAAC,IAAAT,eAAAU,4BAAA,EAAAC,+BAAA,EAAAC,gBAAAC,YAAwHC;QACxH,OAAA;YACAX,iBAAAY,CAAAA;gBAACP,SAAAA,QAAAA,SAAAA,KAAAA,IAAAA,KAAAA,IAAAA,KAAAA,OAAAA;gBAAQC,OAAAA;YAAG;QAGdP;+HAEG;2DAACY;;;QAAiBb;KAAAA;WAAcK,SAAA,CAAA;QAEnCJ,kBAAgB,QAAAD,kBAAA,KAAA,IAAA,KAAA,IAAAA,cAAAe,kBAAA,CAAAF;;;QACdb;KAAAA;WACCK,SAAA,CAAA;0BAACL,QAAAA,kBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,cAAAA,iBAAAA,CAAAA;;;QAAeW;KAAAA;WAAeN,SAAA,CAAA;QAElCJ,kBAAgB,QAAAD,kBAAA,KAAA,IAAA,KAAA,IAAAA,cAAAgB,aAAA,CAAAJ;;;QACdZ;KAAAA;WACCK,SAAA,CAAA;0BAACO,QAAAA,kBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,cAAAA,eAAAA,CAAAA;;;QAAYZ;KAAAA;WAAc;uCAG5BA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui-copilot/react-chat-input-plugins",
3
- "version": "0.3.4",
3
+ "version": "0.4.1",
4
4
  "description": "A Fluent AI package for React-based ChatInput plugins.",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -12,9 +12,9 @@
12
12
  },
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@fluentui-copilot/chat-input-plugins": "^0.3.4",
16
- "@fluentui-copilot/react-text-editor": "^0.3.2",
17
- "@fluentui-copilot/text-editor": "^0.2.1",
15
+ "@fluentui-copilot/chat-input-plugins": "^0.4.1",
16
+ "@fluentui-copilot/react-text-editor": "^0.4.1",
17
+ "@fluentui-copilot/text-editor": "^0.3.1",
18
18
  "@swc/helpers": "^0.5.1"
19
19
  },
20
20
  "peerDependencies": {