@fluentui-copilot/react-editor-input 0.2.1 → 0.3.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.
- package/CHANGELOG.json +15 -0
- package/CHANGELOG.md +10 -1
- package/dist/index.d.ts +3 -10
- package/lib/components/EditorInput/EditorInput.js +2 -3
- package/lib/components/EditorInput/EditorInput.js.map +1 -1
- package/lib/components/EditorInput/EditorInput.types.js +3 -1
- package/lib/components/EditorInput/EditorInput.types.js.map +1 -1
- package/lib/components/EditorInput/index.js +0 -1
- package/lib/components/EditorInput/index.js.map +1 -1
- package/lib/components/EditorInput/renderEditorInput.js +12 -10
- package/lib/components/EditorInput/renderEditorInput.js.map +1 -1
- package/lib/components/EditorInput/useEditorInput.js +58 -18
- package/lib/components/EditorInput/useEditorInput.js.map +1 -1
- package/lib/components/EditorInput/useEditorInputStyles.styles.js +7 -0
- package/lib/components/EditorInput/useEditorInputStyles.styles.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/components/EditorInput/EditorInput.js +1 -3
- package/lib-commonjs/components/EditorInput/EditorInput.js.map +1 -1
- package/lib-commonjs/components/EditorInput/EditorInput.types.js +3 -1
- package/lib-commonjs/components/EditorInput/EditorInput.types.js.map +1 -1
- package/lib-commonjs/components/EditorInput/index.js +0 -1
- package/lib-commonjs/components/EditorInput/index.js.map +1 -1
- package/lib-commonjs/components/EditorInput/renderEditorInput.js +11 -10
- package/lib-commonjs/components/EditorInput/renderEditorInput.js.map +1 -1
- package/lib-commonjs/components/EditorInput/useEditorInput.js +72 -10
- package/lib-commonjs/components/EditorInput/useEditorInput.js.map +1 -1
- package/lib-commonjs/components/EditorInput/useEditorInputStyles.styles.js +7 -0
- package/lib-commonjs/components/EditorInput/useEditorInputStyles.styles.js.map +1 -1
- package/lib-commonjs/index.js +0 -3
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +4 -4
- package/lib/components/EditorInput/useEditorInputContextValues.js +0 -16
- package/lib/components/EditorInput/useEditorInputContextValues.js.map +0 -1
- package/lib/utilities/useLexicalContentEditable.js +0 -68
- package/lib/utilities/useLexicalContentEditable.js.map +0 -1
- package/lib/utilities/useLexicalEditor.js +0 -75
- package/lib/utilities/useLexicalEditor.js.map +0 -1
- package/lib-commonjs/components/EditorInput/useEditorInputContextValues.js +0 -27
- package/lib-commonjs/components/EditorInput/useEditorInputContextValues.js.map +0 -1
- package/lib-commonjs/utilities/useLexicalContentEditable.js +0 -87
- package/lib-commonjs/utilities/useLexicalContentEditable.js.map +0 -1
- package/lib-commonjs/utilities/useLexicalEditor.js +0 -74
- package/lib-commonjs/utilities/useLexicalEditor.js.map +0 -1
|
@@ -11,10 +11,11 @@ Object.defineProperty(exports, "useEditorInput_unstable", {
|
|
|
11
11
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
13
|
const _reactcomponents = require("@fluentui/react-components");
|
|
14
|
+
const _chatinputplugins = require("@fluentui-copilot/chat-input-plugins");
|
|
14
15
|
const _reacttexteditor = require("@fluentui-copilot/react-text-editor");
|
|
15
|
-
const
|
|
16
|
+
const _reactutilities = require("@fluentui/react-utilities");
|
|
16
17
|
const useEditorInput_unstable = (props, ref)=>{
|
|
17
|
-
const { onChange, onPaste, trimWhiteSpace = false, textPlugin = _reacttexteditor.LexicalPlainTextPlugin, history = true, editorRef } = props;
|
|
18
|
+
const { onChange, onPaste, trimWhiteSpace = false, textPlugin = _reacttexteditor.LexicalPlainTextPlugin, history = true, editorRef: userEditorRef } = props;
|
|
18
19
|
const { root, primary } = (0, _reactcomponents.getPartitionedNativeProps)({
|
|
19
20
|
primarySlotTagName: 'span',
|
|
20
21
|
props,
|
|
@@ -24,7 +25,52 @@ const useEditorInput_unstable = (props, ref)=>{
|
|
|
24
25
|
'defaultValue'
|
|
25
26
|
]
|
|
26
27
|
});
|
|
27
|
-
const
|
|
28
|
+
const editorRef = (0, _reactcomponents.useMergedRefs)(_react.useRef(null), userEditorRef);
|
|
29
|
+
// The disabled state can also be changed by lexical (e.g. by a custom plugin) so
|
|
30
|
+
// we use `useControllableState` to coordinate
|
|
31
|
+
const [disabled, setDisabled] = (0, _reactutilities.useControllableState)({
|
|
32
|
+
state: props.disabled,
|
|
33
|
+
initialState: false
|
|
34
|
+
});
|
|
35
|
+
const customNodes = props.customNodes ? [
|
|
36
|
+
...props.customNodes,
|
|
37
|
+
_chatinputplugins.SentinelNode
|
|
38
|
+
] : [
|
|
39
|
+
_chatinputplugins.SentinelNode
|
|
40
|
+
];
|
|
41
|
+
const spanRef = _react.useCallback((span)=>{
|
|
42
|
+
var // Register the `input` span with lexical
|
|
43
|
+
_editorRef_current;
|
|
44
|
+
(_editorRef_current = editorRef.current) === null || _editorRef_current === void 0 ? void 0 : _editorRef_current.setRootElement(span);
|
|
45
|
+
}, [
|
|
46
|
+
editorRef
|
|
47
|
+
]);
|
|
48
|
+
// Update lexical when disabled changes
|
|
49
|
+
(0, _reactcomponents.useIsomorphicLayoutEffect)(()=>{
|
|
50
|
+
if (editorRef.current) {
|
|
51
|
+
var _editorRef_current;
|
|
52
|
+
(_editorRef_current = editorRef.current) === null || _editorRef_current === void 0 ? void 0 : _editorRef_current.setEditable(!disabled);
|
|
53
|
+
}
|
|
54
|
+
}, [
|
|
55
|
+
disabled
|
|
56
|
+
]);
|
|
57
|
+
(0, _reactcomponents.useIsomorphicLayoutEffect)(()=>{
|
|
58
|
+
if (editorRef.current) {
|
|
59
|
+
var _editorRef_current;
|
|
60
|
+
return (0, _reacttexteditor.mergeRegister)(editorRef.current.registerEditableListener((isEditable)=>{
|
|
61
|
+
setDisabled(!isEditable);
|
|
62
|
+
}), (_editorRef_current = editorRef.current) === null || _editorRef_current === void 0 ? void 0 : _editorRef_current.registerRootListener((root)=>{
|
|
63
|
+
if (!root) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// Remove lexical's inline style so we can apply our own
|
|
67
|
+
// Lexical needs the whitespace style to be either `pre` or `pre-wrap` to work correctly
|
|
68
|
+
root.style.whiteSpace = '';
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
}, [
|
|
72
|
+
editorRef
|
|
73
|
+
]);
|
|
28
74
|
const handleOnChange = _react.useCallback((newValue)=>{
|
|
29
75
|
onChange === null || onChange === void 0 ? void 0 : onChange({}, {
|
|
30
76
|
value: newValue
|
|
@@ -32,14 +78,25 @@ const useEditorInput_unstable = (props, ref)=>{
|
|
|
32
78
|
}, [
|
|
33
79
|
onChange
|
|
34
80
|
]);
|
|
35
|
-
const
|
|
81
|
+
const [defaultString, defaultValueFunction] = (()=>{
|
|
82
|
+
if (typeof props.defaultValue === 'function') {
|
|
83
|
+
return [
|
|
84
|
+
undefined,
|
|
85
|
+
props.defaultValue
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
return [
|
|
89
|
+
props.defaultValue,
|
|
90
|
+
undefined
|
|
91
|
+
];
|
|
92
|
+
})();
|
|
93
|
+
const placeholderValue = _reactcomponents.slot.optional(props.placeholderValue, {
|
|
36
94
|
elementType: 'span'
|
|
37
|
-
})
|
|
95
|
+
});
|
|
38
96
|
const placeholderId = (0, _reactcomponents.useId)('chat-input-placeholder', placeholderValue === null || placeholderValue === void 0 ? void 0 : placeholderValue.id);
|
|
39
97
|
if (placeholderValue) {
|
|
40
98
|
placeholderValue.id = placeholderId;
|
|
41
99
|
}
|
|
42
|
-
const describedBy = primary['aria-describedby'] ? `${primary['aria-describedby']} ${placeholderId}` : placeholderId;
|
|
43
100
|
return {
|
|
44
101
|
components: {
|
|
45
102
|
root: 'span',
|
|
@@ -62,19 +119,24 @@ const useEditorInput_unstable = (props, ref)=>{
|
|
|
62
119
|
disabled,
|
|
63
120
|
suppressContentEditableWarning: true,
|
|
64
121
|
...primary,
|
|
65
|
-
'aria-describedby':
|
|
122
|
+
'aria-describedby': primary['aria-describedby'] ? `${primary['aria-describedby']} ${placeholderId}` : placeholderId
|
|
66
123
|
},
|
|
67
124
|
elementType: 'span'
|
|
68
125
|
}),
|
|
69
126
|
placeholderValue,
|
|
70
|
-
lexicalInitialConfig
|
|
127
|
+
lexicalInitialConfig: {
|
|
128
|
+
namespace: 'fai-EditorInput',
|
|
129
|
+
onError: console.error,
|
|
130
|
+
nodes: customNodes,
|
|
131
|
+
editorState: defaultValueFunction
|
|
132
|
+
},
|
|
71
133
|
editorRef,
|
|
72
134
|
disabled,
|
|
73
135
|
textPlugin,
|
|
74
136
|
onPaste,
|
|
75
137
|
handleOnChange,
|
|
138
|
+
defaultValue: defaultString,
|
|
76
139
|
trimWhiteSpace,
|
|
77
|
-
history
|
|
78
|
-
lexicalEditor
|
|
140
|
+
history
|
|
79
141
|
};
|
|
80
142
|
}; //# sourceMappingURL=useEditorInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useEditorInput.tsx"],"sourcesContent":["import * as React from 'react';\nimport {
|
|
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 } = 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 tabIndex: disabled ? -1 : 0,\n disabled,\n suppressContentEditableWarning: true,\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 },\n editorRef,\n disabled,\n textPlugin,\n onPaste,\n handleOnChange,\n defaultValue: defaultString,\n trimWhiteSpace,\n history,\n };\n};\n"],"names":["onChange","trimWhiteSpace","primarySlotTagName","props","excludedPropNames","LexicalPlainTextPlugin","userEditorRef","root","primary","getPartitionedNativeProps","setDisabled","editorRef","customNodes","SentinelNode","disabled","useControllableState","_editorRef_current","current","setRootElement","span","setEditable","useIsomorphicLayoutEffect","mergeRegister","isEditable","whiteSpace","handleOnChange","React","useCallback","newValue","value","defaultValue","undefined","placeholderValue","id","placeholderId","input","slot","always","defaultProps","elementType","components","ref","spanRef","contentEditable","tabIndex","suppressContentEditableWarning","lexicalInitialConfig"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAyBIA;;;eAAAA;;;;iEAzBmB;iCAOhB;kCAEsB;iCAEyB;gCACjB;AAYnC,MACEA,0BAEAC,CAAAA,OAAAA;UAKF,UACEC,SACAC,mBACAC,KAAAA,eAAoBC,uCAAA,YAAY,IAAA,aAAWC,aAAA;UAC7C,EAEAC,IAAA,EACAC,OAAA,KACAC,IAAAA,0CAAA,EAAA;QACAP,oBAAiBQ;;2BAED;YAAA;YAAA;YAAA;SAAA;;UAGhBC,YAAMC,IAAAA,8BAAoBA,EAAAA,OAAAA,MAAc,CAAA,OAAAN;qFAAqB;kDAAEO;UAAgB,CAAAC,UAAAJ,YAAA,GAAAK,IAAAA,oCAAA,EAAA;eAACF,MAAAA,QAAAA;sBAAa;;wBAIzFV,MAAAS,WAAA,GAAA;WAAAT,MAAAS,WAAyC;QAAAC,8BAAA;KAAA,GAAA;QAAAA,8BAAA;KAAA;UACzCF,UAAAA,OAAAA,WAAAA,CAAAA,CAAAA;YACF,yCACA;;QAAWK,CAAAA,qBAAAL,UAAAM,OAAA,MAAA,QAAAD,uBAAA,KAAA,IAAA,KAAA,IAAAA,mBAAAE,cAAA,CAAAC;OAGb;QAAAR;KAAA;2CAC0B;kDACVM,EAAAA;sBACZN,OAAAA,EAAAA;;kCACFA,UAAAM,OAAA,MAAA,QAAAD,uBAAA,KAAA,IAAA,KAAA,IAAAA,mBAAAI,WAAA,CAAA,CAAAN;QACF;;;KAAIA;kDAAS,EAAA;QAEbO,IAAAA,UAAAA,OAAAA,EAAAA;gBACEL;qDAKIL,EAAAA,UAAAA,OAAAA,CAAAA,wBAAAA,CAAAA,CAAAA;4BAJKW,CAAAA;sCAEUC,UAAAA,OAAAA,MAAAA,QAAAA,uBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,mBAAAA,oBAAAA,CAAAA,CAAAA;oBACf,CAAAhB,MACAI;;;wEAGE;wGAEwD;0BACxD,CAAAa,UAAA,GAAA;;;;;KAIN;UACCC,iBAAAC,OAAAC,WAAA,CAAAC,CAAAA;qBAACjB,QAAAA,aAAAA,KAAAA,IAAAA,KAAAA,IAAAA,SAAAA,CAAAA,GAAAA;YAAUkB,OAAAD;QAEd;;;KAEI5B;0BAAwB4B,qBAAAA,GAAAA,CAAAA;YAAS,OAAAzB,MAAA2B,YAAA,KAAA,YAAA;YACnC,OACA;gBAAAC;gBAAA5B,MAAA2B,YAAA;aAAA;;eAAU;YAAA3B,MAAA2B,YAAA;YAAAC;SAAA;;UAIVC,mBAAiBF,qBAAAA,CAAAA,QAAY,CAAA3B,MAAK6B,gBAAY,EAAA;qBAC5C;;0BAAyBF,IAAAA,sBAAAA,EAAAA,0BAAYE,qBAAA,QAAAA,qBAAA,KAAA,IAAA,KAAA,IAAAA,iBAAAC,EAAA;0BAAC;yBACxCA,EAAA,GAAAC;;;oBAC4BH;kBAAU;YACxCI,OAAA;YAEAH,kBAAMA;;QAA+EzB,MAAA6B,qBAAA,CAAAC,MAAA,CAAAlC,MAAAI,IAAA,EAAA;YACrF+B,cAAMJ;gBACFF,GAAAA,IAAAA;;YAEJO,aAAA;QAEA;eACEC,qBAAAA,CAAAA,MAAY,CAAArC,MAAAgC,KAAA,EAAA;0BACJ;qBACNA,IAAAA,8BAAO,EAAAM,KAAAC;sBACPV;gBACFW,iBAAA,CAAA7B;gBACAP,iBAAiBO,WAAW,OAAEiB;0BAAEO,WAAc,CAAA,IAAA;;gDAAU;0BAAGC;gBAAoB,oBAAA/B,OAAA,CAAA,mBAAA,GAAA,CAAA,EAAAA,OAAA,CAAA,mBAAA,CAAA,CAAA,EAAA0B,cAAA,CAAA,GAAAA;;yBAE7EI;;;8BAGEK;uBACA;6BACAC,KAAU9B;;yBAEV+B;;;;;;;sBASJC;;;;6CAKA"}
|
|
@@ -83,6 +83,13 @@ const useEditorInputStyles_unstable = (state)=>{
|
|
|
83
83
|
const styles = useStyles();
|
|
84
84
|
state.root.className = (0, _reactcomponents.mergeClasses)(editorInputClassNames.root, rootClassName, state.root.className);
|
|
85
85
|
state.input.className = (0, _reactcomponents.mergeClasses)(editorInputClassNames.input, inputClassName, state.input.className);
|
|
86
|
+
state.lexicalInitialConfig = {
|
|
87
|
+
...state.lexicalInitialConfig,
|
|
88
|
+
theme: {
|
|
89
|
+
...useLexicalStyles(),
|
|
90
|
+
...state.lexicalInitialConfig.theme
|
|
91
|
+
}
|
|
92
|
+
};
|
|
86
93
|
if (state.placeholderValue) {
|
|
87
94
|
state.placeholderValue.className = (0, _reactcomponents.mergeClasses)(editorInputClassNames.placeholderValue, placeholderClassName, disabled && styles.placeholderDisabled, state.placeholderValue.className);
|
|
88
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useEditorInputStyles.styles.ts"],"sourcesContent":["import { makeResetStyles, makeStyles, mergeClasses, tokens, typographyStyles } from '@fluentui/react-components';\nimport type { SlotClassNames } from '@fluentui/react-components';\nimport type { EditorInputSlots, EditorInputState } from './EditorInput.types';\n\nexport const editorInputClassNames: SlotClassNames<EditorInputSlots> = {\n root: 'fai-EditorInput',\n input: 'fai-EditorInput__input',\n placeholderValue: 'fai-EditorInput__placeholderValue',\n};\n\n/**\n * Styles for the root slot\n */\nconst useRootClassName = makeResetStyles({\n display: 'inline-grid',\n whiteSpace: 'pre-wrap',\n});\n\nexport const useLexicalStyles = makeStyles({\n paragraph: {\n margin: 0,\n },\n});\n\nexport const usePlaceholderClassName = makeResetStyles({\n zIndex: 0,\n gridArea: '1 / 1 / 1 / 1',\n\n color: tokens.colorNeutralForeground3,\n ...typographyStyles.body1,\n\n '@media (forced-colors: active)': {\n color: 'GrayText',\n },\n});\n\nexport const useInputClassName = makeResetStyles({\n gridArea: '1 / 1 / 1 / 1',\n zIndex: 1,\n width: '100%',\n});\n\nconst useStyles = makeStyles({\n placeholderDisabled: {\n color: tokens.colorNeutralForegroundDisabled,\n },\n});\n/**\n * Apply styling to the EditorInput slots based on the state\n */\nexport const useEditorInputStyles_unstable = (state: EditorInputState): EditorInputState => {\n 'use no memo';\n\n const { disabled } = state;\n const placeholderClassName = usePlaceholderClassName();\n const rootClassName = useRootClassName();\n const inputClassName = useInputClassName();\n const styles = useStyles();\n\n state.root.className = mergeClasses(editorInputClassNames.root, rootClassName, state.root.className);\n\n state.input.className = mergeClasses(editorInputClassNames.input, inputClassName, state.input.className);\n\n if (state.placeholderValue) {\n state.placeholderValue.className = mergeClasses(\n editorInputClassNames.placeholderValue,\n placeholderClassName,\n disabled && styles.placeholderDisabled,\n state.placeholderValue.className,\n );\n }\n\n return state;\n};\n"],"names":["editorInputClassNames","useEditorInputStyles_unstable","gridArea","whiteSpace","color","root","input","placeholderValue","display","__resetStyles","__styles","paragraph","jrapky","margin","B6of3ja","B74szlk","s","zIndex","sj55zd","disabled","rootClassName","state","placeholderClassName","useStyles","useRootClassName","useInputClassName","className","mergeClasses","inputClassName","styles","placeholderDisabled"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["useEditorInputStyles.styles.ts"],"sourcesContent":["import { makeResetStyles, makeStyles, mergeClasses, tokens, typographyStyles } from '@fluentui/react-components';\nimport type { SlotClassNames } from '@fluentui/react-components';\nimport type { EditorInputSlots, EditorInputState } from './EditorInput.types';\n\nexport const editorInputClassNames: SlotClassNames<EditorInputSlots> = {\n root: 'fai-EditorInput',\n input: 'fai-EditorInput__input',\n placeholderValue: 'fai-EditorInput__placeholderValue',\n};\n\n/**\n * Styles for the root slot\n */\nconst useRootClassName = makeResetStyles({\n display: 'inline-grid',\n whiteSpace: 'pre-wrap',\n});\n\nexport const useLexicalStyles = makeStyles({\n paragraph: {\n margin: 0,\n },\n});\n\nexport const usePlaceholderClassName = makeResetStyles({\n zIndex: 0,\n gridArea: '1 / 1 / 1 / 1',\n\n color: tokens.colorNeutralForeground3,\n ...typographyStyles.body1,\n\n '@media (forced-colors: active)': {\n color: 'GrayText',\n },\n});\n\nexport const useInputClassName = makeResetStyles({\n gridArea: '1 / 1 / 1 / 1',\n zIndex: 1,\n width: '100%',\n});\n\nconst useStyles = makeStyles({\n placeholderDisabled: {\n color: tokens.colorNeutralForegroundDisabled,\n },\n});\n/**\n * Apply styling to the EditorInput slots based on the state\n */\nexport const useEditorInputStyles_unstable = (state: EditorInputState): EditorInputState => {\n 'use no memo';\n\n const { disabled } = state;\n const placeholderClassName = usePlaceholderClassName();\n const rootClassName = useRootClassName();\n const inputClassName = useInputClassName();\n const styles = useStyles();\n\n state.root.className = mergeClasses(editorInputClassNames.root, rootClassName, state.root.className);\n\n state.input.className = mergeClasses(editorInputClassNames.input, inputClassName, state.input.className);\n\n state.lexicalInitialConfig = {\n ...state.lexicalInitialConfig,\n theme: { ...useLexicalStyles(), ...state.lexicalInitialConfig.theme },\n };\n\n if (state.placeholderValue) {\n state.placeholderValue.className = mergeClasses(\n editorInputClassNames.placeholderValue,\n placeholderClassName,\n disabled && styles.placeholderDisabled,\n state.placeholderValue.className,\n );\n }\n\n return state;\n};\n"],"names":["editorInputClassNames","useEditorInputStyles_unstable","gridArea","whiteSpace","color","root","input","placeholderValue","display","__resetStyles","__styles","paragraph","jrapky","margin","B6of3ja","B74szlk","s","zIndex","sj55zd","disabled","rootClassName","state","placeholderClassName","useStyles","useRootClassName","useInputClassName","lexicalInitialConfig","className","theme","mergeClasses","inputClassName","useLexicalStyles","styles","placeholderDisabled"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAIaA,qBAAAA;eAAAA;;IA8CNC,6BAAMA;eAANA;;IAbLC,iBAAU;eAAVA;;IAtBAC,gBAAY;eAAZA;;IAiBEC,uBAAO;eAAPA;;;iCAhCwE;AAIrE,MAAMJ,wBAA0D;UACrEK;WACAC;sBACAC;AACF;AAEA;;CAEC,SAECC,mBAASC,IAAAA,8BAAA,EAAA,YAAA,MAAA;IAAA;CAAA;AACTN,MAAAA,mBAAYO,IAAAA,yBAAA,EAAA;IACdC,WAAA;QAEAC,QAAO;QACLD,QAAAA;gBACEE;QACFC,SAAA;QACCC,SAAA;IAEH;;OAEEb;QAAAA;YAAAA;YAAU;gBAEVE,GAAAA,CAAAA;;SACA;KAAA;;MAGEA,0BAAOK,IAAAA,8BAAA,EAAA,YAAA,MAAA;OACT;QAAA;KAAA;IACFO,GAAG;QAAA;KAAA;AAEH;AACEd,MAAAA,oBAAUO,IAAAA,8BAAA,EAAA,YAAA,MAAA;IAAA;CAAA;MACVQ,YAAQP,IAAAA,yBAAA,EAAA;yBACD;QACNQ,QAAA;IAEH;;;;KAEgD;;AAMhD,MAAOjB,gCAAMA,CAAAA;;UAIX,EACAkB,QAAMC,KACNC;UACAC,uBAAeC;UAEfF,gBAAoBG;UAEpBH,iBAAqBI;UAErBJ,SAAMK;UACJrB,IAAGgB,CAAAA,SAAMK,GAAAA,IAAAA,6BAAoB,EAAA1B,sBAAAK,IAAA,EAAAe,eAAAC,MAAAhB,IAAA,CAAAsB,SAAA;UAC7BC,KAAAA,CAAAA,SAAO,GAAAC,IAAAA,6BAAA,EAAA7B,sBAAAM,KAAA,EAAAwB,gBAAAT,MAAAf,KAAA,CAAAqB,SAAA;8BAAKI,GAAAA;iBAAoBL,oBAASA;eAA2B;YACtE,GAAAK,kBAAA;YAEA,GAAIV,MAAMd,oBAAkB,CAAAqB,KAAA;;;QAS5BP,MAAOA,gBAAAA,EAAAA;QACPA,MAAAd,gBAAA,CAAAoB,SAAA,GAAAE,IAAAA,6BAAA,EAAA7B,sBAAAO,gBAAA,EAAAe,sBAAAH,YAAAa,OAAAC,mBAAA,EAAAZ,MAAAd,gBAAA,CAAAoB,SAAA"}
|
package/lib-commonjs/index.js
CHANGED
|
@@ -18,9 +18,6 @@ _export(exports, {
|
|
|
18
18
|
renderEditorInput_unstable: function() {
|
|
19
19
|
return _EditorInput.renderEditorInput_unstable;
|
|
20
20
|
},
|
|
21
|
-
useEditorInputContextValues: function() {
|
|
22
|
-
return _EditorInput.useEditorInputContextValues;
|
|
23
|
-
},
|
|
24
21
|
useEditorInputStyles_unstable: function() {
|
|
25
22
|
return _EditorInput.useEditorInputStyles_unstable;
|
|
26
23
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export type {
|
|
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"],"names":["EditorInput","editorInputClassNames","renderEditorInput_unstable","useEditorInputStyles_unstable","useEditorInput_unstable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAEEA,WAAW;eAAXA,wBAAW;;IACXC,qBAAqB;eAArBA,kCAAqB;;IACrBC,0BAA0B;eAA1BA,uCAA0B;;IAC1BC,6BAA6B;eAA7BA,0CAA6B;;IAC7BC,uBAAuB;eAAvBA,oCAAuB;;;6BAClB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui-copilot/react-editor-input",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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.
|
|
16
|
-
"@fluentui-copilot/react-chat-input-plugins": "^0.
|
|
17
|
-
"@fluentui-copilot/react-text-editor": "^0.
|
|
15
|
+
"@fluentui-copilot/chat-input-plugins": "^0.3.0",
|
|
16
|
+
"@fluentui-copilot/react-chat-input-plugins": "^0.3.0",
|
|
17
|
+
"@fluentui-copilot/react-text-editor": "^0.3.0",
|
|
18
18
|
"@swc/helpers": "^0.5.1"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { createLexicalComposerContext } from '@fluentui-copilot/react-text-editor';
|
|
3
|
-
export function useEditorInputContextValues(state) {
|
|
4
|
-
const {
|
|
5
|
-
lexicalInitialConfig,
|
|
6
|
-
lexicalEditor
|
|
7
|
-
} = state;
|
|
8
|
-
const {
|
|
9
|
-
theme
|
|
10
|
-
} = lexicalInitialConfig;
|
|
11
|
-
const context = React.useMemo(() => [lexicalEditor, createLexicalComposerContext(null, theme)], [lexicalEditor, theme]);
|
|
12
|
-
return {
|
|
13
|
-
lexicalComposer: context
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=useEditorInputContextValues.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["useEditorInputContextValues.ts"],"sourcesContent":["import * as React from 'react';\nimport type { LexicalComposerContextWithEditor } from '@fluentui-copilot/react-text-editor';\nimport { createLexicalComposerContext } from '@fluentui-copilot/react-text-editor';\nimport type { EditorInputContextValues, EditorInputState } from './EditorInput.types';\n\nexport function useEditorInputContextValues(state: EditorInputState): EditorInputContextValues {\n const { lexicalInitialConfig, lexicalEditor } = state;\n const { theme } = lexicalInitialConfig;\n\n const context: LexicalComposerContextWithEditor = React.useMemo(\n () => [lexicalEditor, createLexicalComposerContext(null, theme)],\n [lexicalEditor, theme],\n );\n\n return { lexicalComposer: context };\n}\n"],"names":["React","createLexicalComposerContext","useEditorInputContextValues","state","lexicalInitialConfig","lexicalEditor","theme","context","useMemo","lexicalComposer"],"rangeMappings":";;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,4BAA4B,QAAQ,sCAAsC;AAGnF,OAAO,SAASC,4BAA4BC,KAAuB;IACjE,MAAM,EAAEC,oBAAoB,EAAEC,aAAa,EAAE,GAAGF;IAChD,MAAM,EAAEG,KAAK,EAAE,GAAGF;IAElB,MAAMG,UAA4CP,MAAMQ,OAAO,CAC7D,IAAM;YAACH;YAAeJ,6BAA6B,MAAMK;SAAO,EAChE;QAACD;QAAeC;KAAM;IAGxB,OAAO;QAAEG,iBAAiBF;IAAQ;AACpC"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { SentinelNode } from '@fluentui-copilot/chat-input-plugins';
|
|
3
|
-
import { useCanShowPlaceholder, mergeRegister, $insertNodes, $createParagraphNode, $createTextNode } from '@fluentui-copilot/react-text-editor';
|
|
4
|
-
import { useControllableState, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
|
|
5
|
-
import { useLexicalStyles } from '../EditorInput';
|
|
6
|
-
import { useLexicalEditor } from './useLexicalEditor';
|
|
7
|
-
function $insertString(text) {
|
|
8
|
-
const paragraphNode = $createParagraphNode();
|
|
9
|
-
const textNode = $createTextNode(text);
|
|
10
|
-
paragraphNode.append(textNode);
|
|
11
|
-
$insertNodes([paragraphNode]);
|
|
12
|
-
}
|
|
13
|
-
export function useLexicalContentEditable(props) {
|
|
14
|
-
const {
|
|
15
|
-
defaultValue
|
|
16
|
-
} = props;
|
|
17
|
-
const customNodes = props.customNodes ? [...props.customNodes, SentinelNode] : [SentinelNode];
|
|
18
|
-
// The disabled state can also be changed by lexical (e.g. by a custom plugin) so
|
|
19
|
-
// we use `useControllableState` to coordinate
|
|
20
|
-
const [disabled, setDisabled] = useControllableState({
|
|
21
|
-
state: props.disabled,
|
|
22
|
-
initialState: false
|
|
23
|
-
});
|
|
24
|
-
const editorState = typeof defaultValue === 'string' ? () => {
|
|
25
|
-
$insertString(defaultValue);
|
|
26
|
-
} : defaultValue;
|
|
27
|
-
const lexicalStyles = useLexicalStyles();
|
|
28
|
-
const lexicalInitialConfig = {
|
|
29
|
-
namespace: 'fai-EditorInput',
|
|
30
|
-
onError: console.error,
|
|
31
|
-
nodes: customNodes,
|
|
32
|
-
editorState,
|
|
33
|
-
editable: !disabled,
|
|
34
|
-
theme: {
|
|
35
|
-
paragraph: lexicalStyles.paragraph
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
const lexicalEditor = useLexicalEditor(lexicalInitialConfig);
|
|
39
|
-
const canShowPlaceholder = useCanShowPlaceholder(lexicalEditor);
|
|
40
|
-
const spanRef = React.useCallback(span => {
|
|
41
|
-
// Register the `input` span with lexical
|
|
42
|
-
lexicalEditor.setRootElement(span);
|
|
43
|
-
}, [lexicalEditor]);
|
|
44
|
-
// Update lexical when disabled changes
|
|
45
|
-
useIsomorphicLayoutEffect(() => {
|
|
46
|
-
lexicalEditor.setEditable(!disabled);
|
|
47
|
-
}, [lexicalEditor]);
|
|
48
|
-
useIsomorphicLayoutEffect(() => {
|
|
49
|
-
return mergeRegister(lexicalEditor.registerEditableListener(isEditable => {
|
|
50
|
-
setDisabled(!isEditable);
|
|
51
|
-
}), lexicalEditor.registerRootListener(root => {
|
|
52
|
-
if (!root) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
// Remove lexical's inline style so we can apply our own
|
|
56
|
-
// Lexical needs the whitespace style to be either `pre` or `pre-wrap` to work correctly
|
|
57
|
-
root.style.whiteSpace = '';
|
|
58
|
-
}));
|
|
59
|
-
}, []);
|
|
60
|
-
return {
|
|
61
|
-
canShowPlaceholder,
|
|
62
|
-
disabled,
|
|
63
|
-
spanRef,
|
|
64
|
-
lexicalEditor,
|
|
65
|
-
lexicalInitialConfig
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
//# sourceMappingURL=useLexicalContentEditable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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 {\n useCanShowPlaceholder,\n mergeRegister,\n $insertNodes,\n $createParagraphNode,\n $createTextNode,\n} from '@fluentui-copilot/react-text-editor';\nimport { useControllableState, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport { useLexicalStyles } from '../EditorInput';\nimport { useLexicalEditor } from './useLexicalEditor';\n\nexport type UseLexicalContentEditableProps = {\n customNodes?: InitialConfigType['nodes'];\n defaultValue?: string | (() => void);\n disabled?: boolean;\n};\nexport type UseLexicalContentEditableResult = {\n canShowPlaceholder: boolean;\n disabled: boolean;\n spanRef: React.RefCallback<HTMLSpanElement>;\n lexicalEditor: LexicalEditor;\n lexicalInitialConfig: InitialConfigType;\n};\n\nfunction $insertString(text: string) {\n const paragraphNode = $createParagraphNode();\n const textNode = $createTextNode(text);\n paragraphNode.append(textNode);\n $insertNodes([paragraphNode]);\n}\n\nexport function useLexicalContentEditable(props: UseLexicalContentEditableProps): UseLexicalContentEditableResult {\n const { defaultValue } = 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 editorState =\n typeof defaultValue === 'string'\n ? () => {\n $insertString(defaultValue);\n }\n : defaultValue;\n\n const lexicalStyles = useLexicalStyles();\n const lexicalInitialConfig = {\n namespace: 'fai-EditorInput',\n onError: console.error,\n nodes: customNodes,\n editorState,\n editable: !disabled,\n theme: { paragraph: lexicalStyles.paragraph },\n };\n const lexicalEditor = useLexicalEditor(lexicalInitialConfig);\n\n const canShowPlaceholder = useCanShowPlaceholder(lexicalEditor);\n\n const spanRef = React.useCallback(\n span => {\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":["React","SentinelNode","useCanShowPlaceholder","mergeRegister","$insertNodes","$createParagraphNode","$createTextNode","useControllableState","useIsomorphicLayoutEffect","useLexicalStyles","useLexicalEditor","$insertString","text","paragraphNode","textNode","append","useLexicalContentEditable","props","defaultValue","customNodes","disabled","setDisabled","state","initialState","editorState","lexicalStyles","lexicalInitialConfig","namespace","onError","console","error","nodes","editable","theme","paragraph","lexicalEditor","canShowPlaceholder","spanRef","useCallback","span","setRootElement","setEditable","registerEditableListener","isEditable","registerRootListener","root","style","whiteSpace"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,YAAY,QAAQ,uCAAuC;AAEpE,SACEC,qBAAqB,EACrBC,aAAa,EACbC,YAAY,EACZC,oBAAoB,EACpBC,eAAe,QACV,sCAAsC;AAC7C,SAASC,oBAAoB,EAAEC,yBAAyB,QAAQ,4BAA4B;AAC5F,SAASC,gBAAgB,QAAQ,iBAAiB;AAClD,SAASC,gBAAgB,QAAQ,qBAAqB;AAetD,SAASC,cAAcC,IAAY;IACjC,MAAMC,gBAAgBR;IACtB,MAAMS,WAAWR,gBAAgBM;IACjCC,cAAcE,MAAM,CAACD;IACrBV,aAAa;QAACS;KAAc;AAC9B;AAEA,OAAO,SAASG,0BAA0BC,KAAqC;IAC7E,MAAM,EAAEC,YAAY,EAAE,GAAGD;IAEzB,MAAME,cAAcF,MAAME,WAAW,GAAG;WAAIF,MAAME,WAAW;QAAElB;KAAa,GAAG;QAACA;KAAa;IAE7F,iFAAiF;IACjF,8CAA8C;IAC9C,MAAM,CAACmB,UAAUC,YAAY,GAAGd,qBAAqB;QACnDe,OAAOL,MAAMG,QAAQ;QACrBG,cAAc;IAChB;IAEA,MAAMC,cACJ,OAAON,iBAAiB,WACpB;QACEP,cAAcO;IAChB,IACAA;IAEN,MAAMO,gBAAgBhB;IACtB,MAAMiB,uBAAuB;QAC3BC,WAAW;QACXC,SAASC,QAAQC,KAAK;QACtBC,OAAOZ;QACPK;QACAQ,UAAU,CAACZ;QACXa,OAAO;YAAEC,WAAWT,cAAcS,SAAS;QAAC;IAC9C;IACA,MAAMC,gBAAgBzB,iBAAiBgB;IAEvC,MAAMU,qBAAqBlC,sBAAsBiC;IAEjD,MAAME,UAAUrC,MAAMsC,WAAW,CAC/BC,CAAAA;QACE,yCAAyC;QACzCJ,cAAcK,cAAc,CAACD;IAC/B,GACA;QAACJ;KAAc;IAGjB,uCAAuC;IACvC3B,0BAA0B;QACxB2B,cAAcM,WAAW,CAAC,CAACrB;IAC7B,GAAG;QAACe;KAAc;IAElB3B,0BAA0B;QACxB,OAAOL,cACLgC,cAAcO,wBAAwB,CAACC,CAAAA;YACrCtB,YAAY,CAACsB;QACf,IACAR,cAAcS,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;QAAEX;QAAoBhB;QAAUiB;QAASF;QAAeT;IAAqB;AACtF"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { $createParagraphNode } from '@fluentui-copilot/react-text-editor';
|
|
2
|
-
import { $getRoot } from '@fluentui-copilot/react-text-editor';
|
|
3
|
-
import { createEditor } from '@fluentui-copilot/react-text-editor';
|
|
4
|
-
import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
|
|
5
|
-
import * as React from 'react';
|
|
6
|
-
// Merge initial state with history
|
|
7
|
-
const UPDATE_OPTIONS = {
|
|
8
|
-
tag: 'history-merge'
|
|
9
|
-
};
|
|
10
|
-
function setInitialState(editor, initialState) {
|
|
11
|
-
if (initialState === null) {
|
|
12
|
-
return;
|
|
13
|
-
} else if (initialState === undefined) {
|
|
14
|
-
editor.update(() => {
|
|
15
|
-
const root = $getRoot();
|
|
16
|
-
if (root.isEmpty()) {
|
|
17
|
-
root.append($createParagraphNode());
|
|
18
|
-
}
|
|
19
|
-
}, UPDATE_OPTIONS);
|
|
20
|
-
} else {
|
|
21
|
-
switch (typeof initialState) {
|
|
22
|
-
case 'string':
|
|
23
|
-
{
|
|
24
|
-
const parsedState = editor.parseEditorState(initialState);
|
|
25
|
-
editor.setEditorState(parsedState, UPDATE_OPTIONS);
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
case 'object':
|
|
29
|
-
{
|
|
30
|
-
editor.setEditorState(initialState, UPDATE_OPTIONS);
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
case 'function':
|
|
34
|
-
{
|
|
35
|
-
editor.update(() => {
|
|
36
|
-
if ($getRoot().isEmpty()) {
|
|
37
|
-
initialState(editor);
|
|
38
|
-
}
|
|
39
|
-
}, UPDATE_OPTIONS);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export function useLexicalEditor(initialConfig) {
|
|
45
|
-
const {
|
|
46
|
-
theme,
|
|
47
|
-
namespace,
|
|
48
|
-
nodes,
|
|
49
|
-
onError,
|
|
50
|
-
editorState: initialEditorState,
|
|
51
|
-
html,
|
|
52
|
-
editable = true
|
|
53
|
-
} = initialConfig;
|
|
54
|
-
const lexicalEditor = React.useMemo(() => {
|
|
55
|
-
const lexicalEditor = createEditor({
|
|
56
|
-
editable,
|
|
57
|
-
html,
|
|
58
|
-
namespace,
|
|
59
|
-
nodes,
|
|
60
|
-
onError: error => onError(error, lexicalEditor),
|
|
61
|
-
theme
|
|
62
|
-
});
|
|
63
|
-
setInitialState(lexicalEditor, initialEditorState);
|
|
64
|
-
return lexicalEditor;
|
|
65
|
-
},
|
|
66
|
-
// eslint-disable-next-line react-compiler/react-compiler -- This is a valid breakage of the rules of hooks
|
|
67
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- We only want to create this context once
|
|
68
|
-
[]);
|
|
69
|
-
useIsomorphicLayoutEffect(() => {
|
|
70
|
-
const isEditable = initialConfig.editable;
|
|
71
|
-
lexicalEditor.setEditable(isEditable !== undefined ? isEditable : true);
|
|
72
|
-
}, []);
|
|
73
|
-
return lexicalEditor;
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=useLexicalEditor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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) {\n const { theme, namespace, nodes, onError, editorState: initialEditorState, html, editable = true } = initialConfig;\n\n const lexicalEditor = React.useMemo(\n () => {\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 // eslint-disable-next-line react-compiler/react-compiler -- This is a valid breakage of the rules of hooks\n // eslint-disable-next-line react-hooks/exhaustive-deps -- We only want to create this context once\n [],\n );\n\n useIsomorphicLayoutEffect(() => {\n const isEditable = initialConfig.editable;\n lexicalEditor.setEditable(isEditable !== undefined ? isEditable : true);\n }, []);\n\n return lexicalEditor;\n}\n"],"names":["$createParagraphNode","$getRoot","createEditor","useIsomorphicLayoutEffect","React","UPDATE_OPTIONS","tag","setInitialState","editor","initialState","undefined","update","root","isEmpty","append","parsedState","parseEditorState","setEditorState","useLexicalEditor","initialConfig","theme","namespace","nodes","onError","editorState","initialEditorState","html","editable","lexicalEditor","useMemo","error","isEditable","setEditable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,oBAAoB,QAAQ,sCAAsC;AAC3E,SAASC,QAAQ,QAAQ,sCAAsC;AAC/D,SAASC,YAAY,QAAQ,sCAAsC;AACnE,SAASC,yBAAyB,QAAQ,4BAA4B;AACtE,YAAYC,WAAW,QAAQ;AAE/B,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,OAAOX;YACb,IAAIW,KAAKC,OAAO,IAAI;gBAClBD,KAAKE,MAAM,CAACd;YACd;QACF,GAAGK;IACL,OAAO;QACL,OAAQ,OAAOI;YACb,KAAK;gBAAU;oBACb,MAAMM,cAAcP,OAAOQ,gBAAgB,CAACP;oBAC5CD,OAAOS,cAAc,CAACF,aAAaV;oBACnC;gBACF;YACA,KAAK;gBAAU;oBACbG,OAAOS,cAAc,CAACR,cAAcJ;oBACpC;gBACF;YACA,KAAK;gBAAY;oBACfG,OAAOG,MAAM,CAAC;wBACZ,IAAIV,WAAWY,OAAO,IAAI;4BACxBJ,aAAaD;wBACf;oBACF,GAAGH;gBACL;QACF;IACF;AACF;AAEA,OAAO,SAASa,iBAAiBC,aAAgC;IAC/D,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAEC,KAAK,EAAEC,OAAO,EAAEC,aAAaC,kBAAkB,EAAEC,IAAI,EAAEC,WAAW,IAAI,EAAE,GAAGR;IAErG,MAAMS,gBAAgBxB,MAAMyB,OAAO,CACjC;QACE,MAAMD,gBAAgB1B,aAAa;YACjCyB;YACAD;YACAL;YACAC;YACAC,SAASO,CAAAA,QAASP,QAAQO,OAAOF;YACjCR;QACF;QAEAb,gBAAgBqB,eAAeH;QAE/B,OAAOG;IACT,GACA,2GAA2G;IAC3G,mGAAmG;IACnG,EAAE;IAGJzB,0BAA0B;QACxB,MAAM4B,aAAaZ,cAAcQ,QAAQ;QACzCC,cAAcI,WAAW,CAACD,eAAerB,YAAYqB,aAAa;IACpE,GAAG,EAAE;IAEL,OAAOH;AACT"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "useEditorInputContextValues", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return useEditorInputContextValues;
|
|
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
|
-
function useEditorInputContextValues(state) {
|
|
15
|
-
const { lexicalInitialConfig, lexicalEditor } = state;
|
|
16
|
-
const { theme } = lexicalInitialConfig;
|
|
17
|
-
const context = _react.useMemo(()=>[
|
|
18
|
-
lexicalEditor,
|
|
19
|
-
(0, _reacttexteditor.createLexicalComposerContext)(null, theme)
|
|
20
|
-
], [
|
|
21
|
-
lexicalEditor,
|
|
22
|
-
theme
|
|
23
|
-
]);
|
|
24
|
-
return {
|
|
25
|
-
lexicalComposer: context
|
|
26
|
-
};
|
|
27
|
-
} //# sourceMappingURL=useEditorInputContextValues.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["useEditorInputContextValues.ts"],"sourcesContent":["import * as React from 'react';\nimport type { LexicalComposerContextWithEditor } from '@fluentui-copilot/react-text-editor';\nimport { createLexicalComposerContext } from '@fluentui-copilot/react-text-editor';\nimport type { EditorInputContextValues, EditorInputState } from './EditorInput.types';\n\nexport function useEditorInputContextValues(state: EditorInputState): EditorInputContextValues {\n const { lexicalInitialConfig, lexicalEditor } = state;\n const { theme } = lexicalInitialConfig;\n\n const context: LexicalComposerContextWithEditor = React.useMemo(\n () => [lexicalEditor, createLexicalComposerContext(null, theme)],\n [lexicalEditor, theme],\n );\n\n return { lexicalComposer: context };\n}\n"],"names":["useEditorInputContextValues","state","lexicalInitialConfig","lexicalEditor","context","theme","lexicalComposer"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAKgBA;;;eAAAA;;;;iEALO;iCAEsB;AAGtC,SAASA,4BAA4BC,KAAuB;UACjE,EACAC,oBAAkBA,EAElBC,aAAMC;iBAC4D;UAChDC,UAAAA,OAAAA,OAAAA,CAAAA,IAAAA;YAAAA;YAAAA,IAAAA,6CAAAA,EAAAA,MAAAA;SAAAA,EAAAA;QAAAA;QAAAA;KAAAA;WAAM;QAGxBC,iBAAOF;;EACT,uDAAA"}
|
|
@@ -1,87 +0,0 @@
|
|
|
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
|
-
function $insertString(text) {
|
|
19
|
-
const paragraphNode = (0, _reacttexteditor.$createParagraphNode)();
|
|
20
|
-
const textNode = (0, _reacttexteditor.$createTextNode)(text);
|
|
21
|
-
paragraphNode.append(textNode);
|
|
22
|
-
(0, _reacttexteditor.$insertNodes)([
|
|
23
|
-
paragraphNode
|
|
24
|
-
]);
|
|
25
|
-
}
|
|
26
|
-
function useLexicalContentEditable(props) {
|
|
27
|
-
const { defaultValue } = props;
|
|
28
|
-
const customNodes = props.customNodes ? [
|
|
29
|
-
...props.customNodes,
|
|
30
|
-
_chatinputplugins.SentinelNode
|
|
31
|
-
] : [
|
|
32
|
-
_chatinputplugins.SentinelNode
|
|
33
|
-
];
|
|
34
|
-
// The disabled state can also be changed by lexical (e.g. by a custom plugin) so
|
|
35
|
-
// we use `useControllableState` to coordinate
|
|
36
|
-
const [disabled, setDisabled] = (0, _reactutilities.useControllableState)({
|
|
37
|
-
state: props.disabled,
|
|
38
|
-
initialState: false
|
|
39
|
-
});
|
|
40
|
-
const editorState = typeof defaultValue === 'string' ? ()=>{
|
|
41
|
-
$insertString(defaultValue);
|
|
42
|
-
} : defaultValue;
|
|
43
|
-
const lexicalStyles = (0, _EditorInput.useLexicalStyles)();
|
|
44
|
-
const lexicalInitialConfig = {
|
|
45
|
-
namespace: 'fai-EditorInput',
|
|
46
|
-
onError: console.error,
|
|
47
|
-
nodes: customNodes,
|
|
48
|
-
editorState,
|
|
49
|
-
editable: !disabled,
|
|
50
|
-
theme: {
|
|
51
|
-
paragraph: lexicalStyles.paragraph
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const lexicalEditor = (0, _useLexicalEditor.useLexicalEditor)(lexicalInitialConfig);
|
|
55
|
-
const canShowPlaceholder = (0, _reacttexteditor.useCanShowPlaceholder)(lexicalEditor);
|
|
56
|
-
const spanRef = _react.useCallback((span)=>{
|
|
57
|
-
// Register the `input` span with lexical
|
|
58
|
-
lexicalEditor.setRootElement(span);
|
|
59
|
-
}, [
|
|
60
|
-
lexicalEditor
|
|
61
|
-
]);
|
|
62
|
-
// Update lexical when disabled changes
|
|
63
|
-
(0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
|
|
64
|
-
lexicalEditor.setEditable(!disabled);
|
|
65
|
-
}, [
|
|
66
|
-
lexicalEditor
|
|
67
|
-
]);
|
|
68
|
-
(0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
|
|
69
|
-
return (0, _reacttexteditor.mergeRegister)(lexicalEditor.registerEditableListener((isEditable)=>{
|
|
70
|
-
setDisabled(!isEditable);
|
|
71
|
-
}), lexicalEditor.registerRootListener((root)=>{
|
|
72
|
-
if (!root) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// Remove lexical's inline style so we can apply our own
|
|
76
|
-
// Lexical needs the whitespace style to be either `pre` or `pre-wrap` to work correctly
|
|
77
|
-
root.style.whiteSpace = '';
|
|
78
|
-
}));
|
|
79
|
-
}, []);
|
|
80
|
-
return {
|
|
81
|
-
canShowPlaceholder,
|
|
82
|
-
disabled,
|
|
83
|
-
spanRef,
|
|
84
|
-
lexicalEditor,
|
|
85
|
-
lexicalInitialConfig
|
|
86
|
-
};
|
|
87
|
-
} //# sourceMappingURL=useLexicalContentEditable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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 {\n useCanShowPlaceholder,\n mergeRegister,\n $insertNodes,\n $createParagraphNode,\n $createTextNode,\n} from '@fluentui-copilot/react-text-editor';\nimport { useControllableState, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport { useLexicalStyles } from '../EditorInput';\nimport { useLexicalEditor } from './useLexicalEditor';\n\nexport type UseLexicalContentEditableProps = {\n customNodes?: InitialConfigType['nodes'];\n defaultValue?: string | (() => void);\n disabled?: boolean;\n};\nexport type UseLexicalContentEditableResult = {\n canShowPlaceholder: boolean;\n disabled: boolean;\n spanRef: React.RefCallback<HTMLSpanElement>;\n lexicalEditor: LexicalEditor;\n lexicalInitialConfig: InitialConfigType;\n};\n\nfunction $insertString(text: string) {\n const paragraphNode = $createParagraphNode();\n const textNode = $createTextNode(text);\n paragraphNode.append(textNode);\n $insertNodes([paragraphNode]);\n}\n\nexport function useLexicalContentEditable(props: UseLexicalContentEditableProps): UseLexicalContentEditableResult {\n const { defaultValue } = 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 editorState =\n typeof defaultValue === 'string'\n ? () => {\n $insertString(defaultValue);\n }\n : defaultValue;\n\n const lexicalStyles = useLexicalStyles();\n const lexicalInitialConfig = {\n namespace: 'fai-EditorInput',\n onError: console.error,\n nodes: customNodes,\n editorState,\n editable: !disabled,\n theme: { paragraph: lexicalStyles.paragraph },\n };\n const lexicalEditor = useLexicalEditor(lexicalInitialConfig);\n\n const canShowPlaceholder = useCanShowPlaceholder(lexicalEditor);\n\n const spanRef = React.useCallback(\n span => {\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","$insertString","text","paragraphNode","$createParagraphNode","textNode","$createTextNode","append","$insertNodes","props","defaultValue","customNodes","SentinelNode","disabled","setDisabled","useControllableState","editorState","initialState","useLexicalStyles","lexicalInitialConfig","namespace","nodes","editable","console","paragraph","theme","useCanShowPlaceholder","lexicalEditor","lexicalStyles","setRootElement","span","useCallback","setEditable","isEditable","registerRootListener","root","useIsomorphicLayoutEffect"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BA+B8BA;;;eAAAA;;;;iEA/BP;kCACM;iCAQtB;gCACyD;6BAC/B;kCACA;AAejC,SAASC,cAAcC,IAAY;UACjCC,gBAAMA,IAAAA,qCAAgBC;UACtBC,WAAMA,IAAAA,gCAAWC,EAAAA;kBACjBH,MAAcI,CAAAA;qCACdC,EAAAA;QAAAA;KAAa;;AAAe,SAAAR,0BAAAS,KAAA;IAC9B,MAAA,EAEAC,YAAgBV,KACdS;UAEAE,cAAMA,MAAcF,WAAME,GAAW;WAAGF,MAAAE,WAAA;QAAAC,8BAAA;KAAA,GAAA;QAAAA,8BAAA;KAAA;qFAAqB;kDAAEA;UAAgB,CAAAC,UAAAC,YAAA,GAAAC,IAAAA,oCAAA,EAAA;eAACH,MAAAA,QAAAA;sBAAa;;UAG7FI,cAAA,OAAAN,iBAAA,WAA8C;QAC9CT,cAAOY;;UAELI,gBAAcC,IAAAA,6BAAA;UAChBC,uBAAA;QAEAC,WAAMJ;iBAGEf,QAAAA,KAAcS;QAChBW,OACAX;QAENM;QACAM,UAAMH,CAAAA;eACJC;uBACSG,cAAaC,SAAA;;;UAGtBF,gBAAWT,IAAAA,kCAAAA,EAAAA;UACXY,qBAAOC,IAAAA,sCAAA,EAAAC;oBAAEH,OAAWI,WAAAA,CAAAA,CAAAA;iDAAwB;QAC9CD,cAAAE,cAAA,CAAAC;OACA;QAAAH;KAAMA;2CAEqBD;iDAELK,EAAAA;sBAElBC,WAAA,CAAA,CAAAnB;;;KACAc;iDAEF,EAAA;eAACA,IAAAA,8BAAAA,EAAAA,cAAAA,wBAAAA,CAAAA,CAAAA;YAAcb,YAAA,CAAAmB;QAGjB,IAAAN,cAAAO,oBAAA,CAAuCC,CAAAA;YACvCC,IAAAA,CAAAA,MAAAA;gBACET;YACF;oEAAIA;YAAc,wFAAA;YAElBS,KAAAA,KAAAA,CAAAA,UAAAA,GAA0B;;;WAItB;;;;;;;uDAWC"}
|