@fluentui-copilot/react-editor-input 0.5.7 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.json +24 -1
  2. package/CHANGELOG.md +11 -2
  3. package/dist/index.d.ts +17 -3
  4. package/lib/EditorInput.js +1 -1
  5. package/lib/EditorInput.js.map +1 -1
  6. package/lib/components/EditorInput/EditorInput.js +3 -1
  7. package/lib/components/EditorInput/EditorInput.js.map +1 -1
  8. package/lib/components/EditorInput/EditorInput.types.js +1 -3
  9. package/lib/components/EditorInput/EditorInput.types.js.map +1 -1
  10. package/lib/components/EditorInput/index.js +1 -0
  11. package/lib/components/EditorInput/index.js.map +1 -1
  12. package/lib/components/EditorInput/renderEditorInput.js +10 -9
  13. package/lib/components/EditorInput/renderEditorInput.js.map +1 -1
  14. package/lib/components/EditorInput/useEditorInput.js +18 -63
  15. package/lib/components/EditorInput/useEditorInput.js.map +1 -1
  16. package/lib/components/EditorInput/useEditorInputContextValues.js +16 -0
  17. package/lib/components/EditorInput/useEditorInputContextValues.js.map +1 -0
  18. package/lib/components/EditorInput/useEditorInputStyles.styles.js +0 -7
  19. package/lib/components/EditorInput/useEditorInputStyles.styles.js.map +1 -1
  20. package/lib/components/EditorInput/useEditorInputStyles.styles.raw.js +0 -7
  21. package/lib/components/EditorInput/useEditorInputStyles.styles.raw.js.map +1 -1
  22. package/lib/index.js +1 -1
  23. package/lib/index.js.map +1 -1
  24. package/lib/utilities/useCanShowPlaceholder.js +18 -0
  25. package/lib/utilities/useCanShowPlaceholder.js.map +1 -0
  26. package/lib/utilities/useLexicalContentEditable.js +69 -0
  27. package/lib/utilities/useLexicalContentEditable.js.map +1 -0
  28. package/lib/utilities/useLexicalEditor.js +63 -0
  29. package/lib/utilities/useLexicalEditor.js.map +1 -0
  30. package/lib-commonjs/EditorInput.js +3 -0
  31. package/lib-commonjs/EditorInput.js.map +1 -1
  32. package/lib-commonjs/components/EditorInput/EditorInput.js +3 -1
  33. package/lib-commonjs/components/EditorInput/EditorInput.js.map +1 -1
  34. package/lib-commonjs/components/EditorInput/EditorInput.types.js +1 -3
  35. package/lib-commonjs/components/EditorInput/EditorInput.types.js.map +1 -1
  36. package/lib-commonjs/components/EditorInput/index.js +4 -0
  37. package/lib-commonjs/components/EditorInput/index.js.map +1 -1
  38. package/lib-commonjs/components/EditorInput/renderEditorInput.js +9 -8
  39. package/lib-commonjs/components/EditorInput/renderEditorInput.js.map +1 -1
  40. package/lib-commonjs/components/EditorInput/useEditorInput.js +14 -58
  41. package/lib-commonjs/components/EditorInput/useEditorInput.js.map +1 -1
  42. package/lib-commonjs/components/EditorInput/useEditorInputContextValues.js +27 -0
  43. package/lib-commonjs/components/EditorInput/useEditorInputContextValues.js.map +1 -0
  44. package/lib-commonjs/components/EditorInput/useEditorInputStyles.styles.js +0 -7
  45. package/lib-commonjs/components/EditorInput/useEditorInputStyles.styles.js.map +1 -1
  46. package/lib-commonjs/components/EditorInput/useEditorInputStyles.styles.raw.js +0 -7
  47. package/lib-commonjs/components/EditorInput/useEditorInputStyles.styles.raw.js.map +1 -1
  48. package/lib-commonjs/index.js +12 -0
  49. package/lib-commonjs/index.js.map +1 -1
  50. package/lib-commonjs/utilities/useCanShowPlaceholder.js +29 -0
  51. package/lib-commonjs/utilities/useCanShowPlaceholder.js.map +1 -0
  52. package/lib-commonjs/utilities/useLexicalContentEditable.js +80 -0
  53. package/lib-commonjs/utilities/useLexicalContentEditable.js.map +1 -0
  54. package/lib-commonjs/utilities/useLexicalEditor.js +72 -0
  55. package/lib-commonjs/utilities/useLexicalEditor.js.map +1 -0
  56. package/package.json +4 -4
@@ -33,11 +33,23 @@ _export(exports, {
33
33
  useAnimatedPlaceholder_unstable: function() {
34
34
  return _AnimatedPlaceholder.useAnimatedPlaceholder_unstable;
35
35
  },
36
+ useEditorInputContextValues: function() {
37
+ return _EditorInput.useEditorInputContextValues;
38
+ },
36
39
  useEditorInputStyles_unstable: function() {
37
40
  return _EditorInput.useEditorInputStyles_unstable;
38
41
  },
39
42
  useEditorInput_unstable: function() {
40
43
  return _EditorInput.useEditorInput_unstable;
44
+ },
45
+ useInputClassName: function() {
46
+ return _EditorInput.useInputClassName;
47
+ },
48
+ useLexicalStyles: function() {
49
+ return _EditorInput.useLexicalStyles;
50
+ },
51
+ usePlaceholderClassName: function() {
52
+ return _EditorInput.usePlaceholderClassName;
41
53
  }
42
54
  });
43
55
  const _EditorInput = require("./EditorInput");
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":["export type { EditorInputProps, EditorInputSlots, EditorInputState, EditorInputValueData } from './EditorInput';\nexport {\n EditorInput,\n editorInputClassNames,\n renderEditorInput_unstable,\n useEditorInputStyles_unstable,\n useEditorInput_unstable,\n} from './EditorInput';\n\nexport {\n AnimatedPlaceholder,\n renderAnimatedPlaceholder_unstable,\n useAnimatedPlaceholder_unstable,\n animatedPlaceholderClassNames,\n useAnimatedPlaceholderStyles_unstable,\n} from './AnimatedPlaceholder';\nexport type {\n AnimatedPlaceholderProps,\n AnimatedPlaceholderSlots,\n AnimatedPlaceholderState,\n} from './AnimatedPlaceholder';\n"],"names":["AnimatedPlaceholder","EditorInput","animatedPlaceholderClassNames","editorInputClassNames","renderAnimatedPlaceholder_unstable","renderEditorInput_unstable","useAnimatedPlaceholderStyles_unstable","useAnimatedPlaceholder_unstable","useEditorInputStyles_unstable","useEditorInput_unstable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAUEA,mBAAmB;eAAnBA,wCAAmB;;IARnBC,WAAW;eAAXA,wBAAW;;IAWXC,6BAA6B;eAA7BA,kDAA6B;;IAV7BC,qBAAqB;eAArBA,kCAAqB;;IAQrBC,kCAAkC;eAAlCA,uDAAkC;;IAPlCC,0BAA0B;eAA1BA,uCAA0B;;IAU1BC,qCAAqC;eAArCA,0DAAqC;;IAFrCC,+BAA+B;eAA/BA,oDAA+B;;IAP/BC,6BAA6B;eAA7BA,0CAA6B;;IAC7BC,uBAAuB;eAAvBA,oCAAuB;;;6BAClB;qCAQA"}
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export type {\n EditorInputContextValues,\n EditorInputProps,\n EditorInputSlots,\n EditorInputState,\n EditorInputValueData,\n} from './EditorInput';\nexport {\n EditorInput,\n editorInputClassNames,\n renderEditorInput_unstable,\n useEditorInputContextValues,\n useEditorInputStyles_unstable,\n useEditorInput_unstable,\n useInputClassName,\n useLexicalStyles,\n usePlaceholderClassName,\n} from './EditorInput';\n\nexport {\n AnimatedPlaceholder,\n renderAnimatedPlaceholder_unstable,\n useAnimatedPlaceholder_unstable,\n animatedPlaceholderClassNames,\n useAnimatedPlaceholderStyles_unstable,\n} from './AnimatedPlaceholder';\nexport type {\n AnimatedPlaceholderProps,\n AnimatedPlaceholderSlots,\n AnimatedPlaceholderState,\n} from './AnimatedPlaceholder';\n"],"names":["AnimatedPlaceholder","EditorInput","animatedPlaceholderClassNames","editorInputClassNames","renderAnimatedPlaceholder_unstable","renderEditorInput_unstable","useAnimatedPlaceholderStyles_unstable","useAnimatedPlaceholder_unstable","useEditorInputContextValues","useEditorInputStyles_unstable","useEditorInput_unstable","useInputClassName","useLexicalStyles","usePlaceholderClassName"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAoBEA,mBAAmB;eAAnBA,wCAAmB;;IAZnBC,WAAW;eAAXA,wBAAW;;IAeXC,6BAA6B;eAA7BA,kDAA6B;;IAd7BC,qBAAqB;eAArBA,kCAAqB;;IAYrBC,kCAAkC;eAAlCA,uDAAkC;;IAXlCC,0BAA0B;eAA1BA,uCAA0B;;IAc1BC,qCAAqC;eAArCA,0DAAqC;;IAFrCC,+BAA+B;eAA/BA,oDAA+B;;IAX/BC,2BAA2B;eAA3BA,wCAA2B;;IAC3BC,6BAA6B;eAA7BA,0CAA6B;;IAC7BC,uBAAuB;eAAvBA,oCAAuB;;IACvBC,iBAAiB;eAAjBA,8BAAiB;;IACjBC,gBAAgB;eAAhBA,6BAAgB;;IAChBC,uBAAuB;eAAvBA,oCAAuB;;;6BAClB;qCAQA"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useCanShowPlaceholder", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useCanShowPlaceholder;
9
+ }
10
+ });
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
+ const _reacttexteditor = require("@fluentui-copilot/react-text-editor");
14
+ const _reactcomponents = require("@fluentui/react-components");
15
+ function getCanShowPlaceholder(editor) {
16
+ return editor.getEditorState().read(()=>(0, _reacttexteditor.$canShowPlaceholder)(editor.isComposing()));
17
+ }
18
+ function useCanShowPlaceholder(editor) {
19
+ const [canShowPlaceholder, setCanShowPlaceholder] = _react.useState(()=>getCanShowPlaceholder(editor));
20
+ (0, _reactcomponents.useIsomorphicLayoutEffect)(()=>{
21
+ function updateCanShowPlaceholder() {
22
+ setCanShowPlaceholder(getCanShowPlaceholder(editor));
23
+ }
24
+ return (0, _reacttexteditor.mergeRegister)(editor.registerUpdateListener(updateCanShowPlaceholder), editor.registerEditableListener(updateCanShowPlaceholder));
25
+ }, [
26
+ editor
27
+ ]);
28
+ return canShowPlaceholder;
29
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useCanShowPlaceholder.ts"],"sourcesContent":["import * as React from 'react';\nimport type { LexicalEditor } from '@fluentui-copilot/react-text-editor';\nimport { $canShowPlaceholder, mergeRegister } from '@fluentui-copilot/react-text-editor';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-components';\n\nfunction getCanShowPlaceholder(editor: LexicalEditor): boolean {\n return editor.getEditorState().read(() => $canShowPlaceholder(editor.isComposing()));\n}\n\nexport function useCanShowPlaceholder(editor: LexicalEditor): boolean {\n const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(() => getCanShowPlaceholder(editor));\n\n useIsomorphicLayoutEffect(() => {\n function updateCanShowPlaceholder() {\n setCanShowPlaceholder(getCanShowPlaceholder(editor));\n }\n\n return mergeRegister(\n editor.registerUpdateListener(updateCanShowPlaceholder),\n editor.registerEditableListener(updateCanShowPlaceholder),\n );\n }, [editor]);\n\n return canShowPlaceholder;\n}\n"],"names":["useCanShowPlaceholder","getCanShowPlaceholder","editor","getEditorState","read","$canShowPlaceholder","isComposing","canShowPlaceholder","setCanShowPlaceholder","React","useState","useIsomorphicLayoutEffect","updateCanShowPlaceholder","mergeRegister","registerUpdateListener","registerEditableListener"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BASgBA;;;eAAAA;;;;iEATO;iCAE4B;iCACT;AAE1C,SAASC,sBAAsBC,MAAqB;IAClD,OAAOA,OAAOC,cAAc,GAAGC,IAAI,CAAC,IAAMC,IAAAA,oCAAAA,EAAoBH,OAAOI,WAAW;AAClF;AAEO,SAASN,sBAAsBE,MAAqB;IACzD,MAAM,CAACK,oBAAoBC,sBAAsB,GAAGC,OAAMC,QAAQ,CAAC,IAAMT,sBAAsBC;IAE/FS,IAAAA,0CAAAA,EAA0B;QACxB,SAASC;YACPJ,sBAAsBP,sBAAsBC;QAC9C;QAEA,OAAOW,IAAAA,8BAAAA,EACLX,OAAOY,sBAAsB,CAACF,2BAC9BV,OAAOa,wBAAwB,CAACH;IAEpC,GAAG;QAACV;KAAO;IAEX,OAAOK;AACT"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useLexicalContentEditable", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useLexicalContentEditable;
9
+ }
10
+ });
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
+ const _chatinputplugins = require("@fluentui-copilot/chat-input-plugins");
14
+ const _reacttexteditor = require("@fluentui-copilot/react-text-editor");
15
+ const _reactutilities = require("@fluentui/react-utilities");
16
+ const _EditorInput = require("../EditorInput");
17
+ const _useLexicalEditor = require("./useLexicalEditor");
18
+ const _useCanShowPlaceholder = require("./useCanShowPlaceholder");
19
+ const _reactcomponents = require("@fluentui/react-components");
20
+ function useLexicalContentEditable(props) {
21
+ const { defaultValue, customTheme } = props;
22
+ const customNodes = props.customNodes ? [
23
+ ...props.customNodes,
24
+ _chatinputplugins.SentinelNode
25
+ ] : [
26
+ _chatinputplugins.SentinelNode
27
+ ];
28
+ // The disabled state can also be changed by lexical (e.g. by a custom plugin) so
29
+ // we use `useControllableState` to coordinate
30
+ const [disabled, setDisabled] = (0, _reactutilities.useControllableState)({
31
+ state: props.disabled,
32
+ initialState: false
33
+ });
34
+ const lexicalStyles = (0, _EditorInput.useLexicalStyles)();
35
+ const paragraphClassName = (0, _reactcomponents.mergeClasses)(lexicalStyles.paragraph, customTheme === null || customTheme === void 0 ? void 0 : customTheme.paragraph);
36
+ const lexicalInitialConfig = {
37
+ namespace: 'fai-EditorInput',
38
+ onError: console.log,
39
+ nodes: customNodes,
40
+ editorState: defaultValue,
41
+ editable: !disabled,
42
+ theme: {
43
+ ...customTheme,
44
+ paragraph: paragraphClassName.trim() === '' ? undefined : paragraphClassName
45
+ }
46
+ };
47
+ const lexicalEditor = (0, _useLexicalEditor.useLexicalEditor)(lexicalInitialConfig);
48
+ const canShowPlaceholder = (0, _useCanShowPlaceholder.useCanShowPlaceholder)(lexicalEditor);
49
+ const spanRef = _react.useCallback((span)=>{
50
+ // Register the `input` span with lexical
51
+ lexicalEditor.setRootElement(span);
52
+ }, [
53
+ lexicalEditor
54
+ ]);
55
+ // Update lexical when disabled changes
56
+ (0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
57
+ lexicalEditor.setEditable(!disabled);
58
+ }, [
59
+ lexicalEditor
60
+ ]);
61
+ (0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
62
+ return (0, _reacttexteditor.mergeRegister)(lexicalEditor.registerEditableListener((isEditable)=>{
63
+ setDisabled(!isEditable);
64
+ }), lexicalEditor.registerRootListener((root)=>{
65
+ if (!root) {
66
+ return;
67
+ }
68
+ // Remove lexical's inline style so we can apply our own
69
+ // Lexical needs the whitespace style to be either `pre` or `pre-wrap` to work correctly
70
+ root.style.whiteSpace = '';
71
+ }));
72
+ }, []);
73
+ return {
74
+ canShowPlaceholder,
75
+ disabled,
76
+ spanRef,
77
+ lexicalEditor,
78
+ lexicalInitialConfig
79
+ };
80
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useLexicalContentEditable.ts"],"sourcesContent":["import * as React from 'react';\nimport { SentinelNode } from '@fluentui-copilot/chat-input-plugins';\nimport type { InitialConfigType, LexicalEditor } from '@fluentui-copilot/react-text-editor';\nimport { mergeRegister } from '@fluentui-copilot/react-text-editor';\nimport { useControllableState, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport type { EditorInputProps } from '../EditorInput';\nimport { useLexicalStyles } from '../EditorInput';\nimport { useLexicalEditor } from './useLexicalEditor';\nimport { useCanShowPlaceholder } from './useCanShowPlaceholder';\nimport { mergeClasses } from '@fluentui/react-components';\n\nexport type UseLexicalContentEditableProps = Pick<EditorInputProps, 'customNodes' | 'disabled' | 'customTheme'> & {\n defaultValue?: () => void;\n};\nexport type UseLexicalContentEditableResult = {\n canShowPlaceholder: boolean;\n disabled: boolean;\n spanRef: React.Ref<HTMLSpanElement>;\n lexicalEditor: LexicalEditor;\n lexicalInitialConfig: InitialConfigType;\n};\n\nexport function useLexicalContentEditable(props: UseLexicalContentEditableProps): UseLexicalContentEditableResult {\n const { defaultValue, customTheme } = props;\n\n const customNodes = props.customNodes ? [...props.customNodes, SentinelNode] : [SentinelNode];\n\n // The disabled state can also be changed by lexical (e.g. by a custom plugin) so\n // we use `useControllableState` to coordinate\n const [disabled, setDisabled] = useControllableState({\n state: props.disabled,\n initialState: false,\n });\n\n const lexicalStyles = useLexicalStyles();\n const paragraphClassName = mergeClasses(lexicalStyles.paragraph, customTheme?.paragraph);\n\n const lexicalInitialConfig = {\n namespace: 'fai-EditorInput',\n onError: console.log,\n nodes: customNodes,\n editorState: defaultValue,\n editable: !disabled,\n theme: { ...customTheme, paragraph: paragraphClassName.trim() === '' ? undefined : paragraphClassName },\n };\n const lexicalEditor = useLexicalEditor(lexicalInitialConfig);\n\n const canShowPlaceholder = useCanShowPlaceholder(lexicalEditor);\n\n const spanRef = React.useCallback(\n (span: HTMLSpanElement | null) => {\n // Register the `input` span with lexical\n lexicalEditor.setRootElement(span);\n },\n [lexicalEditor],\n );\n\n // Update lexical when disabled changes\n useIsomorphicLayoutEffect(() => {\n lexicalEditor.setEditable(!disabled);\n }, [lexicalEditor]);\n\n useIsomorphicLayoutEffect(() => {\n return mergeRegister(\n lexicalEditor.registerEditableListener(isEditable => {\n setDisabled(!isEditable);\n }),\n lexicalEditor.registerRootListener(root => {\n if (!root) {\n return;\n }\n\n // Remove lexical's inline style so we can apply our own\n // Lexical needs the whitespace style to be either `pre` or `pre-wrap` to work correctly\n root.style.whiteSpace = '';\n }),\n );\n }, []);\n\n return { canShowPlaceholder, disabled, spanRef, lexicalEditor, lexicalInitialConfig };\n}\n"],"names":["useLexicalContentEditable","props","defaultValue","customTheme","customNodes","SentinelNode","disabled","setDisabled","useControllableState","state","initialState","lexicalStyles","useLexicalStyles","paragraphClassName","mergeClasses","paragraph","lexicalInitialConfig","namespace","onError","console","log","nodes","editorState","editable","theme","trim","undefined","lexicalEditor","useLexicalEditor","canShowPlaceholder","useCanShowPlaceholder","spanRef","React","useCallback","span","setRootElement","useIsomorphicLayoutEffect","setEditable","mergeRegister","registerEditableListener","isEditable","registerRootListener","root","style","whiteSpace"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAsBgBA;;;eAAAA;;;;iEAtBO;kCACM;iCAEC;gCACkC;6BAE/B;kCACA;uCACK;iCACT;AAatB,SAASA,0BAA0BC,KAAqC;IAC7E,MAAM,EAAEC,YAAY,EAAEC,WAAW,EAAE,GAAGF;IAEtC,MAAMG,cAAcH,MAAMG,WAAW,GAAG;WAAIH,MAAMG,WAAW;QAAEC,8BAAAA;KAAa,GAAG;QAACA,8BAAAA;KAAa;IAE7F,iFAAiF;IACjF,8CAA8C;IAC9C,MAAM,CAACC,UAAUC,YAAY,GAAGC,IAAAA,oCAAAA,EAAqB;QACnDC,OAAOR,MAAMK,QAAQ;QACrBI,cAAc;IAChB;IAEA,MAAMC,gBAAgBC,IAAAA,6BAAAA;IACtB,MAAMC,qBAAqBC,IAAAA,6BAAAA,EAAaH,cAAcI,SAAS,EAAEZ,gBAAAA,QAAAA,gBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,YAAaY,SAAS;IAEvF,MAAMC,uBAAuB;QAC3BC,WAAW;QACXC,SAASC,QAAQC,GAAG;QACpBC,OAAOjB;QACPkB,aAAapB;QACbqB,UAAU,CAACjB;QACXkB,OAAO;YAAE,GAAGrB,WAAW;YAAEY,WAAWF,mBAAmBY,IAAI,OAAO,KAAKC,YAAYb;QAAmB;IACxG;IACA,MAAMc,gBAAgBC,IAAAA,kCAAAA,EAAiBZ;IAEvC,MAAMa,qBAAqBC,IAAAA,4CAAAA,EAAsBH;IAEjD,MAAMI,UAAUC,OAAMC,WAAW,CAC/B,CAACC;QACC,yCAAyC;QACzCP,cAAcQ,cAAc,CAACD;IAC/B,GACA;QAACP;KAAc;IAGjB,uCAAuC;IACvCS,IAAAA,yCAAAA,EAA0B;QACxBT,cAAcU,WAAW,CAAC,CAAC/B;IAC7B,GAAG;QAACqB;KAAc;IAElBS,IAAAA,yCAAAA,EAA0B;QACxB,OAAOE,IAAAA,8BAAAA,EACLX,cAAcY,wBAAwB,CAACC,CAAAA;YACrCjC,YAAY,CAACiC;QACf,IACAb,cAAcc,oBAAoB,CAACC,CAAAA;YACjC,IAAI,CAACA,MAAM;gBACT;YACF;YAEA,wDAAwD;YACxD,wFAAwF;YACxFA,KAAKC,KAAK,CAACC,UAAU,GAAG;QAC1B;IAEJ,GAAG,EAAE;IAEL,OAAO;QAAEf;QAAoBvB;QAAUyB;QAASJ;QAAeX;IAAqB;AACtF"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useLexicalEditor", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useLexicalEditor;
9
+ }
10
+ });
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _reacttexteditor = require("@fluentui-copilot/react-text-editor");
13
+ const _reactutilities = require("@fluentui/react-utilities");
14
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
15
+ // Merge initial state with history
16
+ const UPDATE_OPTIONS = {
17
+ tag: 'history-merge'
18
+ };
19
+ function setInitialState(editor, initialState) {
20
+ if (initialState === null) {
21
+ return;
22
+ } else if (initialState === undefined) {
23
+ editor.update(()=>{
24
+ const root = (0, _reacttexteditor.$getRoot)();
25
+ if (root.isEmpty()) {
26
+ root.append((0, _reacttexteditor.$createParagraphNode)());
27
+ }
28
+ }, UPDATE_OPTIONS);
29
+ } else {
30
+ switch(typeof initialState){
31
+ case 'string':
32
+ {
33
+ const parsedState = editor.parseEditorState(initialState);
34
+ editor.setEditorState(parsedState, UPDATE_OPTIONS);
35
+ break;
36
+ }
37
+ case 'object':
38
+ {
39
+ editor.setEditorState(initialState, UPDATE_OPTIONS);
40
+ break;
41
+ }
42
+ case 'function':
43
+ {
44
+ editor.update(()=>{
45
+ if ((0, _reacttexteditor.$getRoot)().isEmpty()) {
46
+ initialState(editor);
47
+ }
48
+ }, UPDATE_OPTIONS);
49
+ }
50
+ }
51
+ }
52
+ }
53
+ function useLexicalEditor(initialConfig) {
54
+ const { theme, namespace, nodes, onError, editorState: initialEditorState, html, editable = true } = initialConfig;
55
+ const [lexicalEditor] = _react.useState(()=>{
56
+ const lexicalEditor = (0, _reacttexteditor.createEditor)({
57
+ editable,
58
+ html,
59
+ namespace,
60
+ nodes,
61
+ onError: (error)=>onError(error, lexicalEditor),
62
+ theme
63
+ });
64
+ setInitialState(lexicalEditor, initialEditorState);
65
+ return lexicalEditor;
66
+ });
67
+ (0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
68
+ const isEditable = initialConfig.editable;
69
+ lexicalEditor.setEditable(isEditable !== undefined ? isEditable : true);
70
+ }, []);
71
+ return lexicalEditor;
72
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useLexicalEditor.ts"],"sourcesContent":["import type { InitialConfigType, LexicalEditor } from '@fluentui-copilot/react-text-editor';\nimport { $createParagraphNode } from '@fluentui-copilot/react-text-editor';\nimport { $getRoot } from '@fluentui-copilot/react-text-editor';\nimport { createEditor } from '@fluentui-copilot/react-text-editor';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\n// Merge initial state with history\nconst UPDATE_OPTIONS = { tag: 'history-merge' };\n\nfunction setInitialState(editor: LexicalEditor, initialState: InitialConfigType['editorState']) {\n if (initialState === null) {\n return;\n } else if (initialState === undefined) {\n editor.update(() => {\n const root = $getRoot();\n if (root.isEmpty()) {\n root.append($createParagraphNode());\n }\n }, UPDATE_OPTIONS);\n } else {\n switch (typeof initialState) {\n case 'string': {\n const parsedState = editor.parseEditorState(initialState);\n editor.setEditorState(parsedState, UPDATE_OPTIONS);\n break;\n }\n case 'object': {\n editor.setEditorState(initialState, UPDATE_OPTIONS);\n break;\n }\n case 'function': {\n editor.update(() => {\n if ($getRoot().isEmpty()) {\n initialState(editor);\n }\n }, UPDATE_OPTIONS);\n }\n }\n }\n}\n\nexport function useLexicalEditor(initialConfig: InitialConfigType): LexicalEditor {\n const { theme, namespace, nodes, onError, editorState: initialEditorState, html, editable = true } = initialConfig;\n\n const [lexicalEditor] = React.useState(() => {\n const lexicalEditor = createEditor({\n editable,\n html,\n namespace,\n nodes,\n onError: error => onError(error, lexicalEditor),\n theme,\n });\n\n setInitialState(lexicalEditor, initialEditorState);\n\n return lexicalEditor;\n });\n\n useIsomorphicLayoutEffect(() => {\n const isEditable = initialConfig.editable;\n lexicalEditor.setEditable(isEditable !== undefined ? isEditable : true);\n }, []);\n\n return lexicalEditor;\n}\n"],"names":["useLexicalEditor","UPDATE_OPTIONS","tag","setInitialState","editor","initialState","undefined","update","root","$getRoot","isEmpty","append","$createParagraphNode","parsedState","parseEditorState","setEditorState","initialConfig","theme","namespace","nodes","onError","editorState","initialEditorState","html","editable","lexicalEditor","React","useState","createEditor","error","useIsomorphicLayoutEffect","isEditable","setEditable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BA0CgBA;;;eAAAA;;;;iCAzCqB;gCAGK;iEACnB;AAEvB,mCAAmC;AACnC,MAAMC,iBAAiB;IAAEC,KAAK;AAAgB;AAE9C,SAASC,gBAAgBC,MAAqB,EAAEC,YAA8C;IAC5F,IAAIA,iBAAiB,MAAM;QACzB;IACF,OAAO,IAAIA,iBAAiBC,WAAW;QACrCF,OAAOG,MAAM,CAAC;YACZ,MAAMC,OAAOC,IAAAA,yBAAAA;YACb,IAAID,KAAKE,OAAO,IAAI;gBAClBF,KAAKG,MAAM,CAACC,IAAAA,qCAAAA;YACd;QACF,GAAGX;IACL,OAAO;QACL,OAAQ,OAAOI;YACb,KAAK;gBAAU;oBACb,MAAMQ,cAAcT,OAAOU,gBAAgB,CAACT;oBAC5CD,OAAOW,cAAc,CAACF,aAAaZ;oBACnC;gBACF;YACA,KAAK;gBAAU;oBACbG,OAAOW,cAAc,CAACV,cAAcJ;oBACpC;gBACF;YACA,KAAK;gBAAY;oBACfG,OAAOG,MAAM,CAAC;wBACZ,IAAIE,IAAAA,yBAAAA,IAAWC,OAAO,IAAI;4BACxBL,aAAaD;wBACf;oBACF,GAAGH;gBACL;QACF;IACF;AACF;AAEO,SAASD,iBAAiBgB,aAAgC;IAC/D,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAEC,KAAK,EAAEC,OAAO,EAAEC,aAAaC,kBAAkB,EAAEC,IAAI,EAAEC,WAAW,IAAI,EAAE,GAAGR;IAErG,MAAM,CAACS,cAAc,GAAGC,OAAMC,QAAQ,CAAC;QACrC,MAAMF,gBAAgBG,IAAAA,6BAAAA,EAAa;YACjCJ;YACAD;YACAL;YACAC;YACAC,SAASS,CAAAA,QAAST,QAAQS,OAAOJ;YACjCR;QACF;QAEAd,gBAAgBsB,eAAeH;QAE/B,OAAOG;IACT;IAEAK,IAAAA,yCAAAA,EAA0B;QACxB,MAAMC,aAAaf,cAAcQ,QAAQ;QACzCC,cAAcO,WAAW,CAACD,eAAezB,YAAYyB,aAAa;IACpE,GAAG,EAAE;IAEL,OAAON;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui-copilot/react-editor-input",
3
- "version": "0.5.7",
3
+ "version": "0.6.0",
4
4
  "description": "a base rich editor input.",
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.5.2",
16
- "@fluentui-copilot/react-chat-input-plugins": "^0.5.6",
17
- "@fluentui-copilot/react-text-editor": "^0.4.2",
15
+ "@fluentui-copilot/chat-input-plugins": "^0.5.3",
16
+ "@fluentui-copilot/react-chat-input-plugins": "^0.5.7",
17
+ "@fluentui-copilot/react-text-editor": "^0.4.3",
18
18
  "@fluentui-copilot/tokens": "^0.3.15",
19
19
  "@swc/helpers": "^0.5.1"
20
20
  },