@fluentui-copilot/react-editor-input 0.4.7 → 0.4.9

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
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@fluentui-copilot/react-editor-input",
3
3
  "entries": [
4
+ {
5
+ "date": "Wed, 30 Apr 2025 01:46:03 GMT",
6
+ "tag": "@fluentui-copilot/react-editor-input_v0.4.9",
7
+ "version": "0.4.9",
8
+ "comments": {
9
+ "none": [
10
+ {
11
+ "author": "tristan.watanabe@gmail.com",
12
+ "package": "@fluentui-copilot/react-editor-input",
13
+ "commit": "1391e0a7243d050db30fcc27547fd3e91df0162c",
14
+ "comment": "chore: update tsconfig to remove allowSyntheticDefaultImports to enforce named imports."
15
+ }
16
+ ],
17
+ "patch": [
18
+ {
19
+ "author": "owcampbe@microsoft.com",
20
+ "package": "@fluentui-copilot/react-editor-input",
21
+ "commit": "5a9efb11481fbe2c9bd25c8825ec4a9b991050ab",
22
+ "comment": "chore: Bump @fluentui/react-components to 9.58.3."
23
+ }
24
+ ]
25
+ }
26
+ },
27
+ {
28
+ "date": "Sat, 19 Apr 2025 00:05:39 GMT",
29
+ "tag": "@fluentui-copilot/react-editor-input_v0.4.8",
30
+ "version": "0.4.8",
31
+ "comments": {
32
+ "patch": [
33
+ {
34
+ "author": "owcampbe@microsoft.com",
35
+ "package": "@fluentui-copilot/react-editor-input",
36
+ "commit": "154067a90ddf5cc157f7cc361b98e44420315c57",
37
+ "comment": "feat: Allow setting defaultValue without calling onChange."
38
+ }
39
+ ]
40
+ }
41
+ },
4
42
  {
5
43
  "date": "Thu, 20 Mar 2025 17:00:42 GMT",
6
44
  "tag": "@fluentui-copilot/react-editor-input_v0.4.4",
package/CHANGELOG.md CHANGED
@@ -1,9 +1,27 @@
1
1
  # Change Log - @fluentui-copilot/react-editor-input
2
2
 
3
- This log was last generated on Thu, 20 Mar 2025 17:00:42 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 30 Apr 2025 01:46:03 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [0.4.9](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/react-editor-input_v0.4.9)
8
+
9
+ Wed, 30 Apr 2025 01:46:03 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/react-editor-input_v0.4.8..@fluentui-copilot/react-editor-input_v0.4.9)
11
+
12
+ ### Patches
13
+
14
+ - chore: Bump @fluentui/react-components to 9.58.3. ([PR #2963](https://github.com/microsoft/fluentai/pull/2963) by owcampbe@microsoft.com)
15
+
16
+ ## [0.4.8](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/react-editor-input_v0.4.8)
17
+
18
+ Sat, 19 Apr 2025 00:05:39 GMT
19
+ [Compare changes](https://github.com/microsoft/fluentai/compare/@fluentui-copilot/react-editor-input_v0.4.4..@fluentui-copilot/react-editor-input_v0.4.8)
20
+
21
+ ### Patches
22
+
23
+ - feat: Allow setting defaultValue without calling onChange. ([PR #2899](https://github.com/microsoft/fluentai/pull/2899) by owcampbe@microsoft.com)
24
+
7
25
  ## [0.4.4](https://github.com/microsoft/fluentai/tree/@fluentui-copilot/react-editor-input_v0.4.4)
8
26
 
9
27
  Thu, 20 Mar 2025 17:00:42 GMT
package/dist/index.d.ts CHANGED
@@ -63,6 +63,11 @@ export declare type EditorInputProps = Omit<ComponentProps<Partial<EditorInputSl
63
63
  * @default true
64
64
  */
65
65
  isSentinelNodeEnabled?: boolean;
66
+ /**
67
+ * By default when the `defaultValue` is inserted into the editor, `onChange` is triggered.
68
+ * When this prop is true, if `defaultValue` is a string, `onChange` will not be triggered with its value.
69
+ */
70
+ preventDefaultValueOnChange?: boolean;
66
71
  };
67
72
 
68
73
  export declare type EditorInputSlots = {
@@ -1 +1 @@
1
- {"version":3,"sources":["EditorInput.types.ts"],"sourcesContent":["import type { InitialConfigType, LexicalEditor, LexicalPlainTextPlugin } from '@fluentui-copilot/react-text-editor';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-components';\n\nexport type EditorInputSlots = {\n root: NonNullable<Slot<'span'>>;\n input: NonNullable<Slot<'span'>>;\n placeholderValue?: Slot<'span'>;\n};\n\n/**\n * EditorInput Props\n */\nexport type EditorInputProps = Omit<\n ComponentProps<Partial<EditorInputSlots>, 'input'>,\n 'onChange' | 'onPaste' | 'defaultValue' | 'onSubmit'\n> & {\n disabled?: boolean;\n /**\n * If defaultValue is a string, it will be added to the input on first render.\n * If defaultValue is a function, it can call lexical $ functions to imperatively set the initial content with more complex nodes.\n */\n defaultValue?: string | (() => void);\n /**\n * Callback for when the user changes the value.\n * TODO: Add proper event type for callback\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange?: (ev: any, data: EditorInputValueData) => void;\n /**\n * Callback for when content is pasted into the Editor.\n */\n onPaste?: (ev: ClipboardEvent) => void;\n /**\n * When true, the input will be cleared when only whitespace is remaining.\n * @default false\n */\n trimWhiteSpace?: boolean;\n /**\n * Used to register any custom nodes used by plugins added. Can also be used to override the default nodes.\n */\n customNodes?: InitialConfigType['nodes'];\n /**\n * The plugin which is in charge of initializing Lexical and is given the `input` and `placeholder` slots\n * @default LexicalPlainTextPlugin\n */\n textPlugin?: typeof LexicalPlainTextPlugin;\n /**\n * Controls whether history is tracked to provide undo and redo functionality\n * @default true\n */\n history?: boolean;\n\n editorRef?: React.RefObject<LexicalEditor>;\n\n /**\n * Customize the default styles of elements inserted by Lexical in the editor.\n */\n customTheme?: InitialConfigType['theme'];\n\n /**\n * Whether or not to enable the sentinel node. The sentinel node is a node that is inserted at the end of the editor\n * The SentinelNode fixes a Safari bug in lexical versions below 0.20.1\n * @default true\n */\n isSentinelNodeEnabled?: boolean;\n};\n\n/**\n * State used in rendering EditorInput\n */\nexport type EditorInputState = ComponentState<EditorInputSlots> &\n Required<\n Pick<\n EditorInputProps,\n 'disabled' | 'textPlugin' | 'history' | 'trimWhiteSpace' | 'editorRef' | 'isSentinelNodeEnabled'\n >\n > &\n Partial<Pick<EditorInputProps, 'onPaste'>> & {\n lexicalInitialConfig: InitialConfigType;\n defaultValue?: string;\n handleOnChange: (value: string) => void;\n };\n\n/**\n * Data passed to the `onChange` callback when the chat input's value changes.\n */\nexport type EditorInputValueData = {\n value: string;\n};\n"],"names":[],"rangeMappings":";;","mappings":"AAmFA;;CAEC,GACD,WAEE"}
1
+ {"version":3,"sources":["EditorInput.types.ts"],"sourcesContent":["import type { InitialConfigType, LexicalEditor, LexicalPlainTextPlugin } from '@fluentui-copilot/react-text-editor';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-components';\n\nexport type EditorInputSlots = {\n root: NonNullable<Slot<'span'>>;\n input: NonNullable<Slot<'span'>>;\n placeholderValue?: Slot<'span'>;\n};\n\n/**\n * EditorInput Props\n */\nexport type EditorInputProps = Omit<\n ComponentProps<Partial<EditorInputSlots>, 'input'>,\n 'onChange' | 'onPaste' | 'defaultValue' | 'onSubmit'\n> & {\n disabled?: boolean;\n /**\n * If defaultValue is a string, it will be added to the input on first render.\n * If defaultValue is a function, it can call lexical $ functions to imperatively set the initial content with more complex nodes.\n */\n defaultValue?: string | (() => void);\n /**\n * Callback for when the user changes the value.\n * TODO: Add proper event type for callback\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange?: (ev: any, data: EditorInputValueData) => void;\n /**\n * Callback for when content is pasted into the Editor.\n */\n onPaste?: (ev: ClipboardEvent) => void;\n /**\n * When true, the input will be cleared when only whitespace is remaining.\n * @default false\n */\n trimWhiteSpace?: boolean;\n /**\n * Used to register any custom nodes used by plugins added. Can also be used to override the default nodes.\n */\n customNodes?: InitialConfigType['nodes'];\n /**\n * The plugin which is in charge of initializing Lexical and is given the `input` and `placeholder` slots\n * @default LexicalPlainTextPlugin\n */\n textPlugin?: typeof LexicalPlainTextPlugin;\n /**\n * Controls whether history is tracked to provide undo and redo functionality\n * @default true\n */\n history?: boolean;\n\n editorRef?: React.RefObject<LexicalEditor>;\n\n /**\n * Customize the default styles of elements inserted by Lexical in the editor.\n */\n customTheme?: InitialConfigType['theme'];\n\n /**\n * Whether or not to enable the sentinel node. The sentinel node is a node that is inserted at the end of the editor\n * The SentinelNode fixes a Safari bug in lexical versions below 0.20.1\n * @default true\n */\n isSentinelNodeEnabled?: boolean;\n /**\n * By default when the `defaultValue` is inserted into the editor, `onChange` is triggered.\n * When this prop is true, if `defaultValue` is a string, `onChange` will not be triggered with its value.\n */\n preventDefaultValueOnChange?: boolean;\n};\n\n/**\n * State used in rendering EditorInput\n */\nexport type EditorInputState = ComponentState<EditorInputSlots> &\n Required<\n Pick<\n EditorInputProps,\n 'disabled' | 'textPlugin' | 'history' | 'trimWhiteSpace' | 'editorRef' | 'isSentinelNodeEnabled'\n >\n > &\n Partial<Pick<EditorInputProps, 'onPaste'>> & {\n lexicalInitialConfig: InitialConfigType;\n defaultValue?: string;\n handleOnChange: (value: string) => void;\n };\n\n/**\n * Data passed to the `onChange` callback when the chat input's value changes.\n */\nexport type EditorInputValueData = {\n value: string;\n};\n"],"names":[],"rangeMappings":";;","mappings":"AAwFA;;CAEC,GACD,WAEE"}
@@ -3,6 +3,9 @@ import { getPartitionedNativeProps, slot, useId, useIsomorphicLayoutEffect, useM
3
3
  import { SentinelNode } from '@fluentui-copilot/chat-input-plugins';
4
4
  import { LexicalPlainTextPlugin, mergeRegister } from '@fluentui-copilot/react-text-editor';
5
5
  import { useControllableState } from '@fluentui/react-utilities';
6
+ export const createInitialEditorState = defaultValue => {
7
+ return `{"root":{"type":"root","children":[{"children":[{"text":${JSON.stringify(defaultValue)},"type":"text"}],"type":"paragraph"}]}}`;
8
+ };
6
9
  /**
7
10
  * Create the state required to render EditorInput.
8
11
  *
@@ -21,7 +24,8 @@ export const useEditorInput_unstable = (props, ref) => {
21
24
  history = true,
22
25
  editorRef: userEditorRef,
23
26
  customTheme,
24
- isSentinelNodeEnabled = true
27
+ isSentinelNodeEnabled = true,
28
+ preventDefaultValueOnChange = false
25
29
  } = props;
26
30
  const {
27
31
  root,
@@ -72,12 +76,19 @@ export const useEditorInput_unstable = (props, ref) => {
72
76
  value: newValue
73
77
  });
74
78
  }, [onChange]);
75
- const [defaultString, defaultValueFunction] = (() => {
79
+ const [defaultString, lexicalEditorStateDefaultValue] = React.useMemo(() => {
76
80
  if (typeof props.defaultValue === 'function') {
77
81
  return [undefined, props.defaultValue];
78
82
  }
83
+ if (preventDefaultValueOnChange && props.defaultValue !== undefined) {
84
+ // Any method of providing a default value to lexical which inserts it after initialization
85
+ // will trigger a text content change.
86
+ // Providing a default value as a stringified editorState will prevent calling onChange
87
+ const editorState = createInitialEditorState(props.defaultValue);
88
+ return [undefined, editorState];
89
+ }
79
90
  return [props.defaultValue, undefined];
80
- })();
91
+ }, [preventDefaultValueOnChange, props.defaultValue]);
81
92
  const placeholderValue = slot.optional(props.placeholderValue, {
82
93
  elementType: 'span'
83
94
  });
@@ -116,7 +127,7 @@ export const useEditorInput_unstable = (props, ref) => {
116
127
  namespace: 'fai-EditorInput',
117
128
  onError: console.error,
118
129
  nodes: customNodes,
119
- editorState: defaultValueFunction,
130
+ editorState: lexicalEditorStateDefaultValue,
120
131
  theme: customTheme
121
132
  },
122
133
  editorRef,
@@ -1 +1 @@
1
- {"version":3,"sources":["useEditorInput.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n getPartitionedNativeProps,\n slot,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n} from '@fluentui/react-components';\nimport type { EditorInputProps, EditorInputState } from './EditorInput.types';\nimport { SentinelNode } from '@fluentui-copilot/chat-input-plugins';\nimport type { LexicalEditor } from '@fluentui-copilot/react-text-editor';\nimport { LexicalPlainTextPlugin, mergeRegister } from '@fluentui-copilot/react-text-editor';\nimport { useControllableState } from '@fluentui/react-utilities';\n\n/**\n * Create the state required to render EditorInput.\n *\n * The returned state can be modified with hooks such as useEditorInputStyles_unstable,\n * before being passed to renderEditorInput_unstable.\n *\n * @param props - props from this instance of EditorInput\n * @param ref - reference to root HTMLElement of EditorInput\n */\nexport const useEditorInput_unstable = (props: EditorInputProps, ref: React.Ref<HTMLSpanElement>): EditorInputState => {\n const {\n onChange,\n onPaste,\n trimWhiteSpace = false,\n textPlugin = LexicalPlainTextPlugin,\n history = true,\n editorRef: userEditorRef,\n customTheme,\n isSentinelNodeEnabled = true,\n } = props;\n const { root, primary } = getPartitionedNativeProps({\n primarySlotTagName: 'span',\n props,\n excludedPropNames: ['onChange', 'onPaste', 'defaultValue'],\n });\n\n const editorRef = useMergedRefs(React.useRef<LexicalEditor>(null), userEditorRef);\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 customNodes = props.customNodes ? [...props.customNodes, SentinelNode] : [SentinelNode];\n\n const spanRef = React.useCallback(\n span => {\n // Register the `input` span with lexical\n editorRef.current?.setRootElement(span);\n },\n [editorRef],\n );\n\n // Update lexical when disabled changes\n useIsomorphicLayoutEffect(() => {\n if (editorRef.current) {\n editorRef.current?.setEditable(!disabled);\n }\n }, [disabled]);\n\n useIsomorphicLayoutEffect(() => {\n if (editorRef.current) {\n return mergeRegister(\n editorRef.current.registerEditableListener(isEditable => {\n setDisabled(!isEditable);\n }),\n editorRef.current?.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 }, [editorRef]);\n\n const handleOnChange = React.useCallback(\n (newValue: string) => {\n onChange?.({}, { value: newValue });\n },\n [onChange],\n );\n\n const [defaultString, defaultValueFunction] = (() => {\n if (typeof props.defaultValue === 'function') {\n return [undefined, props.defaultValue];\n }\n return [props.defaultValue, undefined];\n })();\n\n const placeholderValue = slot.optional(props.placeholderValue, { elementType: 'span' });\n const placeholderId = useId('chat-input-placeholder', placeholderValue?.id);\n if (placeholderValue) {\n placeholderValue.id = placeholderId;\n }\n\n return {\n components: {\n root: 'span',\n input: 'span',\n placeholderValue: 'span',\n },\n root: slot.always(props.root, { defaultProps: { ...root }, elementType: 'span' }),\n input: slot.always(props.input, {\n defaultProps: {\n ref: useMergedRefs(ref, spanRef),\n role: 'textbox',\n contentEditable: !disabled,\n 'aria-readonly': disabled ? true : undefined,\n disabled,\n suppressContentEditableWarning: true,\n tabIndex: disabled ? undefined : 0,\n ...primary,\n 'aria-describedby': primary['aria-describedby']\n ? `${primary['aria-describedby']} ${placeholderId}`\n : placeholderId,\n },\n elementType: 'span',\n }),\n placeholderValue,\n lexicalInitialConfig: {\n namespace: 'fai-EditorInput',\n onError: console.error,\n nodes: customNodes,\n editorState: defaultValueFunction,\n theme: customTheme,\n },\n editorRef,\n disabled,\n textPlugin,\n onPaste,\n handleOnChange,\n defaultValue: defaultString,\n trimWhiteSpace,\n history,\n isSentinelNodeEnabled,\n };\n};\n"],"names":["React","getPartitionedNativeProps","slot","useId","useIsomorphicLayoutEffect","useMergedRefs","SentinelNode","LexicalPlainTextPlugin","mergeRegister","useControllableState","useEditorInput_unstable","props","ref","onChange","onPaste","trimWhiteSpace","textPlugin","history","editorRef","userEditorRef","customTheme","isSentinelNodeEnabled","root","primary","primarySlotTagName","excludedPropNames","useRef","disabled","setDisabled","state","initialState","customNodes","spanRef","useCallback","span","current","setRootElement","setEditable","registerEditableListener","isEditable","registerRootListener","style","whiteSpace","handleOnChange","newValue","value","defaultString","defaultValueFunction","defaultValue","undefined","placeholderValue","optional","elementType","placeholderId","id","components","input","always","defaultProps","role","contentEditable","suppressContentEditableWarning","tabIndex","lexicalInitialConfig","namespace","onError","console","error","nodes","editorState","theme"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EAAE;YAC9BE,cAAc;gBACZ9C,KAAKP,cAAcO,KAAKoB;gBACxB2B,MAAM;gBACNC,iBAAiB,CAACjC;gBAClB,iBAAiBA,WAAW,OAAOsB;gBACnCtB;gBACAkC,gCAAgC;gBAChCC,UAAUnC,WAAWsB,YAAY;gBACjC,GAAG1B,OAAO;gBACV,oBAAoBA,OAAO,CAAC,mBAAmB,GAC3C,CAAC,EAAEA,OAAO,CAAC,mBAAmB,CAAC,CAAC,EAAE8B,cAAc,CAAC,GACjDA;YACN;YACAD,aAAa;QACf;QACAF;QACAa,sBAAsB;YACpBC,WAAW;YACXC,SAASC,QAAQC,KAAK;YACtBC,OAAOrC;YACPsC,aAAatB;YACbuB,OAAOlD;QACT;QACAF;QACAS;QACAX;QACAF;QACA6B;QACAK,cAAcF;QACd/B;QACAE;QACAI;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["useEditorInput.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n getPartitionedNativeProps,\n slot,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n} from '@fluentui/react-components';\nimport type { EditorInputProps, EditorInputState } from './EditorInput.types';\nimport { SentinelNode } from '@fluentui-copilot/chat-input-plugins';\nimport type { LexicalEditor } from '@fluentui-copilot/react-text-editor';\nimport { LexicalPlainTextPlugin, mergeRegister } from '@fluentui-copilot/react-text-editor';\nimport { useControllableState } from '@fluentui/react-utilities';\n\nexport const createInitialEditorState = (defaultValue: string) => {\n return `{\"root\":{\"type\":\"root\",\"children\":[{\"children\":[{\"text\":${JSON.stringify(\n defaultValue,\n )},\"type\":\"text\"}],\"type\":\"paragraph\"}]}}`;\n};\n\n/**\n * Create the state required to render EditorInput.\n *\n * The returned state can be modified with hooks such as useEditorInputStyles_unstable,\n * before being passed to renderEditorInput_unstable.\n *\n * @param props - props from this instance of EditorInput\n * @param ref - reference to root HTMLElement of EditorInput\n */\nexport const useEditorInput_unstable = (props: EditorInputProps, ref: React.Ref<HTMLSpanElement>): EditorInputState => {\n const {\n onChange,\n onPaste,\n trimWhiteSpace = false,\n textPlugin = LexicalPlainTextPlugin,\n history = true,\n editorRef: userEditorRef,\n customTheme,\n isSentinelNodeEnabled = true,\n preventDefaultValueOnChange = false,\n } = props;\n const { root, primary } = getPartitionedNativeProps({\n primarySlotTagName: 'span',\n props,\n excludedPropNames: ['onChange', 'onPaste', 'defaultValue'],\n });\n\n const editorRef = useMergedRefs(React.useRef<LexicalEditor>(null), userEditorRef);\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 customNodes = props.customNodes ? [...props.customNodes, SentinelNode] : [SentinelNode];\n\n const spanRef = React.useCallback(\n span => {\n // Register the `input` span with lexical\n editorRef.current?.setRootElement(span);\n },\n [editorRef],\n );\n\n // Update lexical when disabled changes\n useIsomorphicLayoutEffect(() => {\n if (editorRef.current) {\n editorRef.current?.setEditable(!disabled);\n }\n }, [disabled]);\n\n useIsomorphicLayoutEffect(() => {\n if (editorRef.current) {\n return mergeRegister(\n editorRef.current.registerEditableListener(isEditable => {\n setDisabled(!isEditable);\n }),\n editorRef.current?.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 }, [editorRef]);\n\n const handleOnChange = React.useCallback(\n (newValue: string) => {\n onChange?.({}, { value: newValue });\n },\n [onChange],\n );\n\n const [defaultString, lexicalEditorStateDefaultValue] = React.useMemo(() => {\n if (typeof props.defaultValue === 'function') {\n return [undefined, props.defaultValue];\n }\n\n if (preventDefaultValueOnChange && props.defaultValue !== undefined) {\n // Any method of providing a default value to lexical which inserts it after initialization\n // will trigger a text content change.\n // Providing a default value as a stringified editorState will prevent calling onChange\n const editorState = createInitialEditorState(props.defaultValue);\n return [undefined, editorState];\n }\n\n return [props.defaultValue, undefined];\n }, [preventDefaultValueOnChange, props.defaultValue]);\n\n const placeholderValue = slot.optional(props.placeholderValue, { elementType: 'span' });\n const placeholderId = useId('chat-input-placeholder', placeholderValue?.id);\n if (placeholderValue) {\n placeholderValue.id = placeholderId;\n }\n\n return {\n components: {\n root: 'span',\n input: 'span',\n placeholderValue: 'span',\n },\n root: slot.always(props.root, { defaultProps: { ...root }, elementType: 'span' }),\n input: slot.always(props.input, {\n defaultProps: {\n ref: useMergedRefs(ref, spanRef),\n role: 'textbox',\n contentEditable: !disabled,\n 'aria-readonly': disabled ? true : undefined,\n disabled,\n suppressContentEditableWarning: true,\n tabIndex: disabled ? undefined : 0,\n ...primary,\n 'aria-describedby': primary['aria-describedby']\n ? `${primary['aria-describedby']} ${placeholderId}`\n : placeholderId,\n },\n elementType: 'span',\n }),\n placeholderValue,\n lexicalInitialConfig: {\n namespace: 'fai-EditorInput',\n onError: console.error,\n nodes: customNodes,\n editorState: lexicalEditorStateDefaultValue,\n theme: customTheme,\n },\n editorRef,\n disabled,\n textPlugin,\n onPaste,\n handleOnChange,\n defaultValue: defaultString,\n trimWhiteSpace,\n history,\n isSentinelNodeEnabled,\n };\n};\n"],"names":["React","getPartitionedNativeProps","slot","useId","useIsomorphicLayoutEffect","useMergedRefs","SentinelNode","LexicalPlainTextPlugin","mergeRegister","useControllableState","createInitialEditorState","defaultValue","JSON","stringify","useEditorInput_unstable","props","ref","onChange","onPaste","trimWhiteSpace","textPlugin","history","editorRef","userEditorRef","customTheme","isSentinelNodeEnabled","preventDefaultValueOnChange","root","primary","primarySlotTagName","excludedPropNames","useRef","disabled","setDisabled","state","initialState","customNodes","spanRef","useCallback","span","current","setRootElement","setEditable","registerEditableListener","isEditable","registerRootListener","style","whiteSpace","handleOnChange","newValue","value","defaultString","lexicalEditorStateDefaultValue","useMemo","undefined","editorState","placeholderValue","optional","elementType","placeholderId","id","components","input","always","defaultProps","role","contentEditable","suppressContentEditableWarning","tabIndex","lexicalInitialConfig","namespace","onError","console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ACjC;QAEA,OAAO;YAACxC,MAAMJ,YAAY;YAAE2C;SAAU;IACxC,GAAG;QAAC5B;QAA6BX,MAAMJ,YAAY;KAAC;IAEpD,MAAM6C,mBAAmBtD,KAAKuD,QAAQ,CAAC1C,MAAMyC,gBAAgB,EAAE;QAAEE,aAAa;IAAO;IACrF,MAAMC,gBAAgBxD,MAAM,0BAA0BqD,6BAAAA,uCAAAA,iBAAkBI,EAAE;IAC1E,IAAIJ,kBAAkB;QACpBA,iBAAiBI,EAAE,GAAGD;IACxB;IAEA,OAAO;QACLE,YAAY;YACVlC,MAAM;YACNmC,OAAO;YACPN,kBAAkB;QACpB;QACA7B,MAAMzB,KAAK6D,MAAM,CAAChD,MAAMY,IAAI,EAAE;YAAEqC,cAAc;gBAAE,GAAGrC,IAAI;YAAC;YAAG+B,aAAa;QAAO;QAC/EI,OAAO5D,KAAK6D,MAAM,CAAChD,MAAM+C,KAAK,EAAE;YAC9BE,cAAc;gBACZhD,KAAKX,cAAcW,KAAKqB;gBACxB4B,MAAM;gBACNC,iBAAiB,CAAClC;gBAClB,iBAAiBA,WAAW,OAAOsB;gBACnCtB;gBACAmC,gCAAgC;gBAChCC,UAAUpC,WAAWsB,YAAY;gBACjC,GAAG1B,OAAO;gBACV,oBAAoBA,OAAO,CAAC,mBAAmB,GAC3C,CAAC,EAAEA,OAAO,CAAC,mBAAmB,CAAC,CAAC,EAAE+B,cAAc,CAAC,GACjDA;YACN;YACAD,aAAa;QACf;QACAF;QACAa,sBAAsB;YACpBC,WAAW;YACXC,SAASC,QAAQC,KAAK;YACtBC,OAAOtC;YACPmB,aAAaH;YACbuB,OAAOnD;QACT;QACAF;QACAU;QACAZ;QACAF;QACA8B;QACArC,cAAcwC;QACdhC;QACAE;QACAI;IACF;AACF,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["EditorInput.types.ts"],"sourcesContent":["import type { InitialConfigType, LexicalEditor, LexicalPlainTextPlugin } from '@fluentui-copilot/react-text-editor';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-components';\n\nexport type EditorInputSlots = {\n root: NonNullable<Slot<'span'>>;\n input: NonNullable<Slot<'span'>>;\n placeholderValue?: Slot<'span'>;\n};\n\n/**\n * EditorInput Props\n */\nexport type EditorInputProps = Omit<\n ComponentProps<Partial<EditorInputSlots>, 'input'>,\n 'onChange' | 'onPaste' | 'defaultValue' | 'onSubmit'\n> & {\n disabled?: boolean;\n /**\n * If defaultValue is a string, it will be added to the input on first render.\n * If defaultValue is a function, it can call lexical $ functions to imperatively set the initial content with more complex nodes.\n */\n defaultValue?: string | (() => void);\n /**\n * Callback for when the user changes the value.\n * TODO: Add proper event type for callback\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange?: (ev: any, data: EditorInputValueData) => void;\n /**\n * Callback for when content is pasted into the Editor.\n */\n onPaste?: (ev: ClipboardEvent) => void;\n /**\n * When true, the input will be cleared when only whitespace is remaining.\n * @default false\n */\n trimWhiteSpace?: boolean;\n /**\n * Used to register any custom nodes used by plugins added. Can also be used to override the default nodes.\n */\n customNodes?: InitialConfigType['nodes'];\n /**\n * The plugin which is in charge of initializing Lexical and is given the `input` and `placeholder` slots\n * @default LexicalPlainTextPlugin\n */\n textPlugin?: typeof LexicalPlainTextPlugin;\n /**\n * Controls whether history is tracked to provide undo and redo functionality\n * @default true\n */\n history?: boolean;\n\n editorRef?: React.RefObject<LexicalEditor>;\n\n /**\n * Customize the default styles of elements inserted by Lexical in the editor.\n */\n customTheme?: InitialConfigType['theme'];\n\n /**\n * Whether or not to enable the sentinel node. The sentinel node is a node that is inserted at the end of the editor\n * The SentinelNode fixes a Safari bug in lexical versions below 0.20.1\n * @default true\n */\n isSentinelNodeEnabled?: boolean;\n};\n\n/**\n * State used in rendering EditorInput\n */\nexport type EditorInputState = ComponentState<EditorInputSlots> &\n Required<\n Pick<\n EditorInputProps,\n 'disabled' | 'textPlugin' | 'history' | 'trimWhiteSpace' | 'editorRef' | 'isSentinelNodeEnabled'\n >\n > &\n Partial<Pick<EditorInputProps, 'onPaste'>> & {\n lexicalInitialConfig: InitialConfigType;\n defaultValue?: string;\n handleOnChange: (value: string) => void;\n };\n\n/**\n * Data passed to the `onChange` callback when the chat input's value changes.\n */\nexport type EditorInputValueData = {\n value: string;\n};\n"],"names":[],"rangeMappings":";;","mappings":"AAmFA;;CAEC"}
1
+ {"version":3,"sources":["EditorInput.types.ts"],"sourcesContent":["import type { InitialConfigType, LexicalEditor, LexicalPlainTextPlugin } from '@fluentui-copilot/react-text-editor';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-components';\n\nexport type EditorInputSlots = {\n root: NonNullable<Slot<'span'>>;\n input: NonNullable<Slot<'span'>>;\n placeholderValue?: Slot<'span'>;\n};\n\n/**\n * EditorInput Props\n */\nexport type EditorInputProps = Omit<\n ComponentProps<Partial<EditorInputSlots>, 'input'>,\n 'onChange' | 'onPaste' | 'defaultValue' | 'onSubmit'\n> & {\n disabled?: boolean;\n /**\n * If defaultValue is a string, it will be added to the input on first render.\n * If defaultValue is a function, it can call lexical $ functions to imperatively set the initial content with more complex nodes.\n */\n defaultValue?: string | (() => void);\n /**\n * Callback for when the user changes the value.\n * TODO: Add proper event type for callback\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange?: (ev: any, data: EditorInputValueData) => void;\n /**\n * Callback for when content is pasted into the Editor.\n */\n onPaste?: (ev: ClipboardEvent) => void;\n /**\n * When true, the input will be cleared when only whitespace is remaining.\n * @default false\n */\n trimWhiteSpace?: boolean;\n /**\n * Used to register any custom nodes used by plugins added. Can also be used to override the default nodes.\n */\n customNodes?: InitialConfigType['nodes'];\n /**\n * The plugin which is in charge of initializing Lexical and is given the `input` and `placeholder` slots\n * @default LexicalPlainTextPlugin\n */\n textPlugin?: typeof LexicalPlainTextPlugin;\n /**\n * Controls whether history is tracked to provide undo and redo functionality\n * @default true\n */\n history?: boolean;\n\n editorRef?: React.RefObject<LexicalEditor>;\n\n /**\n * Customize the default styles of elements inserted by Lexical in the editor.\n */\n customTheme?: InitialConfigType['theme'];\n\n /**\n * Whether or not to enable the sentinel node. The sentinel node is a node that is inserted at the end of the editor\n * The SentinelNode fixes a Safari bug in lexical versions below 0.20.1\n * @default true\n */\n isSentinelNodeEnabled?: boolean;\n /**\n * By default when the `defaultValue` is inserted into the editor, `onChange` is triggered.\n * When this prop is true, if `defaultValue` is a string, `onChange` will not be triggered with its value.\n */\n preventDefaultValueOnChange?: boolean;\n};\n\n/**\n * State used in rendering EditorInput\n */\nexport type EditorInputState = ComponentState<EditorInputSlots> &\n Required<\n Pick<\n EditorInputProps,\n 'disabled' | 'textPlugin' | 'history' | 'trimWhiteSpace' | 'editorRef' | 'isSentinelNodeEnabled'\n >\n > &\n Partial<Pick<EditorInputProps, 'onPaste'>> & {\n lexicalInitialConfig: InitialConfigType;\n defaultValue?: string;\n handleOnChange: (value: string) => void;\n };\n\n/**\n * Data passed to the `onChange` callback when the chat input's value changes.\n */\nexport type EditorInputValueData = {\n value: string;\n};\n"],"names":[],"rangeMappings":";;","mappings":"AAwFA;;CAEC"}
@@ -2,9 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "useEditorInput_unstable", {
6
- enumerable: true,
7
- get: function() {
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ createInitialEditorState: function() {
13
+ return createInitialEditorState;
14
+ },
15
+ useEditorInput_unstable: function() {
8
16
  return useEditorInput_unstable;
9
17
  }
10
18
  });
@@ -14,8 +22,11 @@ const _reactcomponents = require("@fluentui/react-components");
14
22
  const _chatinputplugins = require("@fluentui-copilot/chat-input-plugins");
15
23
  const _reacttexteditor = require("@fluentui-copilot/react-text-editor");
16
24
  const _reactutilities = require("@fluentui/react-utilities");
25
+ const createInitialEditorState = (defaultValue)=>{
26
+ return `{"root":{"type":"root","children":[{"children":[{"text":${JSON.stringify(defaultValue)},"type":"text"}],"type":"paragraph"}]}}`;
27
+ };
17
28
  const useEditorInput_unstable = (props, ref)=>{
18
- const { onChange, onPaste, trimWhiteSpace = false, textPlugin = _reacttexteditor.LexicalPlainTextPlugin, history = true, editorRef: userEditorRef, customTheme, isSentinelNodeEnabled = true } = props;
29
+ const { onChange, onPaste, trimWhiteSpace = false, textPlugin = _reacttexteditor.LexicalPlainTextPlugin, history = true, editorRef: userEditorRef, customTheme, isSentinelNodeEnabled = true, preventDefaultValueOnChange = false } = props;
19
30
  const { root, primary } = (0, _reactcomponents.getPartitionedNativeProps)({
20
31
  primarySlotTagName: 'span',
21
32
  props,
@@ -78,18 +89,31 @@ const useEditorInput_unstable = (props, ref)=>{
78
89
  }, [
79
90
  onChange
80
91
  ]);
81
- const [defaultString, defaultValueFunction] = (()=>{
92
+ const [defaultString, lexicalEditorStateDefaultValue] = _react.useMemo(()=>{
82
93
  if (typeof props.defaultValue === 'function') {
83
94
  return [
84
95
  undefined,
85
96
  props.defaultValue
86
97
  ];
87
98
  }
99
+ if (preventDefaultValueOnChange && props.defaultValue !== undefined) {
100
+ // Any method of providing a default value to lexical which inserts it after initialization
101
+ // will trigger a text content change.
102
+ // Providing a default value as a stringified editorState will prevent calling onChange
103
+ const editorState = createInitialEditorState(props.defaultValue);
104
+ return [
105
+ undefined,
106
+ editorState
107
+ ];
108
+ }
88
109
  return [
89
110
  props.defaultValue,
90
111
  undefined
91
112
  ];
92
- })();
113
+ }, [
114
+ preventDefaultValueOnChange,
115
+ props.defaultValue
116
+ ]);
93
117
  const placeholderValue = _reactcomponents.slot.optional(props.placeholderValue, {
94
118
  elementType: 'span'
95
119
  });
@@ -128,7 +152,7 @@ const useEditorInput_unstable = (props, ref)=>{
128
152
  namespace: 'fai-EditorInput',
129
153
  onError: console.error,
130
154
  nodes: customNodes,
131
- editorState: defaultValueFunction,
155
+ editorState: lexicalEditorStateDefaultValue,
132
156
  theme: customTheme
133
157
  },
134
158
  editorRef,
@@ -1 +1 @@
1
- {"version":3,"sources":["useEditorInput.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n getPartitionedNativeProps,\n slot,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n} from '@fluentui/react-components';\nimport type { EditorInputProps, EditorInputState } from './EditorInput.types';\nimport { SentinelNode } from '@fluentui-copilot/chat-input-plugins';\nimport type { LexicalEditor } from '@fluentui-copilot/react-text-editor';\nimport { LexicalPlainTextPlugin, mergeRegister } from '@fluentui-copilot/react-text-editor';\nimport { useControllableState } from '@fluentui/react-utilities';\n\n/**\n * Create the state required to render EditorInput.\n *\n * The returned state can be modified with hooks such as useEditorInputStyles_unstable,\n * before being passed to renderEditorInput_unstable.\n *\n * @param props - props from this instance of EditorInput\n * @param ref - reference to root HTMLElement of EditorInput\n */\nexport const useEditorInput_unstable = (props: EditorInputProps, ref: React.Ref<HTMLSpanElement>): EditorInputState => {\n const {\n onChange,\n onPaste,\n trimWhiteSpace = false,\n textPlugin = LexicalPlainTextPlugin,\n history = true,\n editorRef: userEditorRef,\n customTheme,\n isSentinelNodeEnabled = true,\n } = props;\n const { root, primary } = getPartitionedNativeProps({\n primarySlotTagName: 'span',\n props,\n excludedPropNames: ['onChange', 'onPaste', 'defaultValue'],\n });\n\n const editorRef = useMergedRefs(React.useRef<LexicalEditor>(null), userEditorRef);\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 customNodes = props.customNodes ? [...props.customNodes, SentinelNode] : [SentinelNode];\n\n const spanRef = React.useCallback(\n span => {\n // Register the `input` span with lexical\n editorRef.current?.setRootElement(span);\n },\n [editorRef],\n );\n\n // Update lexical when disabled changes\n useIsomorphicLayoutEffect(() => {\n if (editorRef.current) {\n editorRef.current?.setEditable(!disabled);\n }\n }, [disabled]);\n\n useIsomorphicLayoutEffect(() => {\n if (editorRef.current) {\n return mergeRegister(\n editorRef.current.registerEditableListener(isEditable => {\n setDisabled(!isEditable);\n }),\n editorRef.current?.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 }, [editorRef]);\n\n const handleOnChange = React.useCallback(\n (newValue: string) => {\n onChange?.({}, { value: newValue });\n },\n [onChange],\n );\n\n const [defaultString, defaultValueFunction] = (() => {\n if (typeof props.defaultValue === 'function') {\n return [undefined, props.defaultValue];\n }\n return [props.defaultValue, undefined];\n })();\n\n const placeholderValue = slot.optional(props.placeholderValue, { elementType: 'span' });\n const placeholderId = useId('chat-input-placeholder', placeholderValue?.id);\n if (placeholderValue) {\n placeholderValue.id = placeholderId;\n }\n\n return {\n components: {\n root: 'span',\n input: 'span',\n placeholderValue: 'span',\n },\n root: slot.always(props.root, { defaultProps: { ...root }, elementType: 'span' }),\n input: slot.always(props.input, {\n defaultProps: {\n ref: useMergedRefs(ref, spanRef),\n role: 'textbox',\n contentEditable: !disabled,\n 'aria-readonly': disabled ? true : undefined,\n disabled,\n suppressContentEditableWarning: true,\n tabIndex: disabled ? undefined : 0,\n ...primary,\n 'aria-describedby': primary['aria-describedby']\n ? `${primary['aria-describedby']} ${placeholderId}`\n : placeholderId,\n },\n elementType: 'span',\n }),\n placeholderValue,\n lexicalInitialConfig: {\n namespace: 'fai-EditorInput',\n onError: console.error,\n nodes: customNodes,\n editorState: defaultValueFunction,\n theme: customTheme,\n },\n editorRef,\n disabled,\n textPlugin,\n onPaste,\n handleOnChange,\n defaultValue: defaultString,\n trimWhiteSpace,\n history,\n isSentinelNodeEnabled,\n };\n};\n"],"names":["onChange","trimWhiteSpace","primarySlotTagName","props","excludedPropNames","LexicalPlainTextPlugin","userEditorRef","isSentinelNodeEnabled","root","primary","disabled","customNodes","SentinelNode","setDisabled","useControllableState","state","spanRef","React","editorRef","current","useCallback","span","_editorRef_current","useIsomorphicLayoutEffect","setRootElement","isEditable","registerRootListener","style","whiteSpace","handleOnChange","newValue","defaultString","defaultValueFunction","undefined","defaultValue","placeholderId","useId","placeholderValue","id","components","elementType","input","ref","useMergedRefs","slot","defaultProps","tabIndex","role","suppressContentEditableWarning","customTheme","nodes","textPlugin"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAyBIA;;;eAAAA;;;;iEAzBmB;iCAOhB;kCAEsB;iCAEyB;gCACjB;AAYnC,MACEA,0BAEAC,CAAAA,OAAAA;UAOF,UACEC,SACAC,mBACAC,KAAAA,eAAoBC,uCAAA,YAAY,IAAA,aAAWC,aAAA,aAAe,EAC5DC,wBAAA,IAAA,KAEAJ;UACA,EACAK,IAAA,EACAC,OAAOC,mDACgB,EAAA;4BACP;QAChBP;QAEAC,mBAAMO;YAAcR;YAAMQ;YAAc;SAAA;;UAAuBC,YAAAA,IAAAA,8BAAAA,EAAAA,OAAAA,MAAAA,CAAAA,OAAAA;qFAAgB;kDAACA;UAAa,CAAAF,UAAAG,YAAA,GAAAC,IAAAA,oCAAA,EAAA;QAE7FC,OAAMC,MAAAA,QAAUC;sBAEZ;;wBACAC,MAAAA,WAAAA,GAAUC;WAAAA,MAAOR,WAAjBO;QAAAA,8BAAAA;KAAAA,GAAAA;QAAAA,8BAAAA;KAAAA;UAEFF,UAAAC,OAAAG,WAAA,CAAAC,CAAAA;qDAAW;QAGbC;QACAC,CAAAA,qBAAAA,UAA0BJ,OAAA,MAAA,QAAAG,uBAAA,KAAA,IAAA,KAAA,IAAAA,mBAAAE,cAAA,CAAAH;;;KACpBH;2CACFA;kDAAAA,EAAAA;YACFA,UAAAC,OAAA,EAAA;YACF,IAAGG;kCAACZ,UAAAA,OA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R,MAAMoC;iCAA0BC,CAAcnC;iCAASA,WAAA,OAAAuB;;gDAAiB;gBAAOa,UAAApC,WAAAuB,YAAA;gBAC/EQ,GAAAA,OAAOG;oCACSnC,OAAA,CAAA,mBAAA,GAAA,CAAA,EAAAA,OAAA,CAAA,mBAAA,CAAA,CAAA,EAAA0B,cAAA,CAAA,GAAAA;;yBAEZY;;;8BAGArC;uBACAsC;6BACAF,KAAUpC;;yBAEVsB;mBAGFiB;;;;;;;sBAOAC;;;;;6CAMFC"}
1
+ {"version":3,"sources":["useEditorInput.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n getPartitionedNativeProps,\n slot,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n} from '@fluentui/react-components';\nimport type { EditorInputProps, EditorInputState } from './EditorInput.types';\nimport { SentinelNode } from '@fluentui-copilot/chat-input-plugins';\nimport type { LexicalEditor } from '@fluentui-copilot/react-text-editor';\nimport { LexicalPlainTextPlugin, mergeRegister } from '@fluentui-copilot/react-text-editor';\nimport { useControllableState } from '@fluentui/react-utilities';\n\nexport const createInitialEditorState = (defaultValue: string) => {\n return `{\"root\":{\"type\":\"root\",\"children\":[{\"children\":[{\"text\":${JSON.stringify(\n defaultValue,\n )},\"type\":\"text\"}],\"type\":\"paragraph\"}]}}`;\n};\n\n/**\n * Create the state required to render EditorInput.\n *\n * The returned state can be modified with hooks such as useEditorInputStyles_unstable,\n * before being passed to renderEditorInput_unstable.\n *\n * @param props - props from this instance of EditorInput\n * @param ref - reference to root HTMLElement of EditorInput\n */\nexport const useEditorInput_unstable = (props: EditorInputProps, ref: React.Ref<HTMLSpanElement>): EditorInputState => {\n const {\n onChange,\n onPaste,\n trimWhiteSpace = false,\n textPlugin = LexicalPlainTextPlugin,\n history = true,\n editorRef: userEditorRef,\n customTheme,\n isSentinelNodeEnabled = true,\n preventDefaultValueOnChange = false,\n } = props;\n const { root, primary } = getPartitionedNativeProps({\n primarySlotTagName: 'span',\n props,\n excludedPropNames: ['onChange', 'onPaste', 'defaultValue'],\n });\n\n const editorRef = useMergedRefs(React.useRef<LexicalEditor>(null), userEditorRef);\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 customNodes = props.customNodes ? [...props.customNodes, SentinelNode] : [SentinelNode];\n\n const spanRef = React.useCallback(\n span => {\n // Register the `input` span with lexical\n editorRef.current?.setRootElement(span);\n },\n [editorRef],\n );\n\n // Update lexical when disabled changes\n useIsomorphicLayoutEffect(() => {\n if (editorRef.current) {\n editorRef.current?.setEditable(!disabled);\n }\n }, [disabled]);\n\n useIsomorphicLayoutEffect(() => {\n if (editorRef.current) {\n return mergeRegister(\n editorRef.current.registerEditableListener(isEditable => {\n setDisabled(!isEditable);\n }),\n editorRef.current?.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 }, [editorRef]);\n\n const handleOnChange = React.useCallback(\n (newValue: string) => {\n onChange?.({}, { value: newValue });\n },\n [onChange],\n );\n\n const [defaultString, lexicalEditorStateDefaultValue] = React.useMemo(() => {\n if (typeof props.defaultValue === 'function') {\n return [undefined, props.defaultValue];\n }\n\n if (preventDefaultValueOnChange && props.defaultValue !== undefined) {\n // Any method of providing a default value to lexical which inserts it after initialization\n // will trigger a text content change.\n // Providing a default value as a stringified editorState will prevent calling onChange\n const editorState = createInitialEditorState(props.defaultValue);\n return [undefined, editorState];\n }\n\n return [props.defaultValue, undefined];\n }, [preventDefaultValueOnChange, props.defaultValue]);\n\n const placeholderValue = slot.optional(props.placeholderValue, { elementType: 'span' });\n const placeholderId = useId('chat-input-placeholder', placeholderValue?.id);\n if (placeholderValue) {\n placeholderValue.id = placeholderId;\n }\n\n return {\n components: {\n root: 'span',\n input: 'span',\n placeholderValue: 'span',\n },\n root: slot.always(props.root, { defaultProps: { ...root }, elementType: 'span' }),\n input: slot.always(props.input, {\n defaultProps: {\n ref: useMergedRefs(ref, spanRef),\n role: 'textbox',\n contentEditable: !disabled,\n 'aria-readonly': disabled ? true : undefined,\n disabled,\n suppressContentEditableWarning: true,\n tabIndex: disabled ? undefined : 0,\n ...primary,\n 'aria-describedby': primary['aria-describedby']\n ? `${primary['aria-describedby']} ${placeholderId}`\n : placeholderId,\n },\n elementType: 'span',\n }),\n placeholderValue,\n lexicalInitialConfig: {\n namespace: 'fai-EditorInput',\n onError: console.error,\n nodes: customNodes,\n editorState: lexicalEditorStateDefaultValue,\n theme: customTheme,\n },\n editorRef,\n disabled,\n textPlugin,\n onPaste,\n handleOnChange,\n defaultValue: defaultString,\n trimWhiteSpace,\n history,\n isSentinelNodeEnabled,\n };\n};\n"],"names":["createInitialEditorState","onChange","trimWhiteSpace","defaultValue","JSON","stringify","primarySlotTagName","props","excludedPropNames","LexicalPlainTextPlugin","userEditorRef","isSentinelNodeEnabled","preventDefaultValueOnChange","useMergedRefs","React","root","state","customNodes","editorRef","useRef","SentinelNode","disabled","spanRef","useCallback","span","useIsomorphicLayoutEffect","current","_editorRef_current","setRootElement","setEditable","mergeRegister","registerRootListener","style","whiteSpace","handleOnChange","value","defaultString","lexicalEditorStateDefaultValue","undefined","editorState","id","placeholderId","input","slot","always","defaultProps","placeholderValue","elementType","ref","components","suppressContentEditableWarning","primary","error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAcaA,wBAAAA;eAAAA;;IAiBTC,uBAEAC;eAFAD;;;;iEA/BmB;iCAOhB;kCAEsB;iCAEyB;gCACjB;AAE9B,MAAMD,2BAA2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AAA,CAAA,EAAAV,cAAA,CAAA,GAAAA;;yBAAIM;;;8BAE3C;uBACZC;6BACMI,KAAA;;yBAENf;;;;;;;;sBAUJD;;;;;6CAMeC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui-copilot/react-editor-input",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "a base rich editor input.",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -13,15 +13,15 @@
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
15
  "@fluentui-copilot/chat-input-plugins": "^0.4.2",
16
- "@fluentui-copilot/react-chat-input-plugins": "^0.4.6",
16
+ "@fluentui-copilot/react-chat-input-plugins": "^0.4.8",
17
17
  "@fluentui-copilot/react-text-editor": "^0.4.1",
18
- "@fluentui-copilot/tokens": "^0.3.8",
18
+ "@fluentui-copilot/tokens": "^0.3.10",
19
19
  "@swc/helpers": "^0.5.1"
20
20
  },
21
21
  "peerDependencies": {
22
- "@fluentui/react-components": ">=9.55.1 <10.0.0",
23
- "@fluentui/react-jsx-runtime": ">=9.0.45 <10.0.0",
24
- "@fluentui/react-utilities": ">=9.18.16 <10.0.0",
22
+ "@fluentui/react-components": ">=9.58.3 <10.0.0",
23
+ "@fluentui/react-jsx-runtime": ">=9.0.50 <10.0.0",
24
+ "@fluentui/react-utilities": ">=9.19.0 <10.0.0",
25
25
  "@types/react": ">=16.14.0 <19.0.0",
26
26
  "@types/react-dom": ">=16.9.8 <19.0.0",
27
27
  "react": ">=16.14.0 <19.0.0",