@nextclaw/agent-chat-ui 0.4.7 → 0.4.9-beta.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/dist/index.js +46 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1621,83 +1621,83 @@ function handleLexicalComposerKeyboardCommand(params) {
|
|
|
1621
1621
|
}
|
|
1622
1622
|
//#endregion
|
|
1623
1623
|
//#region src/components/chat/ui/chat-input-bar/lexical/chat-composer-plugins.tsx
|
|
1624
|
-
function ChatComposerBindingsPlugin(
|
|
1624
|
+
function ChatComposerBindingsPlugin({ disabled, editorRef, editorSignatureRef, isApplyingExternalUpdateRef, isComposingRef, lastPublishedSignatureRef, nodes, onBlur, onKeyDown, onNodesChange, pendingSelectionRef, selectionRef, shouldFocusAfterSyncRef, syncSlashState }) {
|
|
1625
1625
|
const [editor] = useLexicalComposerContext();
|
|
1626
1626
|
useLayoutEffect(() => {
|
|
1627
|
-
|
|
1627
|
+
editorRef.current = editor;
|
|
1628
1628
|
return () => {
|
|
1629
|
-
if (
|
|
1629
|
+
if (editorRef.current === editor) editorRef.current = null;
|
|
1630
1630
|
};
|
|
1631
|
-
}, [editor,
|
|
1631
|
+
}, [editor, editorRef]);
|
|
1632
1632
|
useLayoutEffect(() => {
|
|
1633
|
-
editor.setEditable(!
|
|
1634
|
-
}, [
|
|
1633
|
+
editor.setEditable(!disabled);
|
|
1634
|
+
}, [disabled, editor]);
|
|
1635
1635
|
useLayoutEffect(() => {
|
|
1636
|
-
const nextSignature = getChatComposerNodesSignature(
|
|
1637
|
-
const pendingSelection =
|
|
1638
|
-
const shouldSyncDocument = nextSignature !==
|
|
1636
|
+
const nextSignature = getChatComposerNodesSignature(nodes);
|
|
1637
|
+
const pendingSelection = pendingSelectionRef.current;
|
|
1638
|
+
const shouldSyncDocument = nextSignature !== editorSignatureRef.current;
|
|
1639
1639
|
if (!shouldSyncDocument && !pendingSelection) return;
|
|
1640
|
-
|
|
1640
|
+
isApplyingExternalUpdateRef.current = true;
|
|
1641
1641
|
if (shouldSyncDocument) {
|
|
1642
|
-
syncLexicalEditorFromChatComposerState(editor,
|
|
1643
|
-
|
|
1644
|
-
|
|
1642
|
+
syncLexicalEditorFromChatComposerState(editor, nodes, pendingSelection);
|
|
1643
|
+
editorSignatureRef.current = nextSignature;
|
|
1644
|
+
lastPublishedSignatureRef.current = nextSignature;
|
|
1645
1645
|
} else if (pendingSelection) syncLexicalSelectionFromChatComposerSelection(editor, pendingSelection);
|
|
1646
1646
|
if (pendingSelection) {
|
|
1647
|
-
|
|
1648
|
-
|
|
1647
|
+
selectionRef.current = pendingSelection;
|
|
1648
|
+
pendingSelectionRef.current = null;
|
|
1649
1649
|
}
|
|
1650
|
-
if (
|
|
1651
|
-
|
|
1652
|
-
const targetSelection =
|
|
1650
|
+
if (shouldFocusAfterSyncRef.current) {
|
|
1651
|
+
shouldFocusAfterSyncRef.current = false;
|
|
1652
|
+
const targetSelection = selectionRef.current;
|
|
1653
1653
|
editor.focus(() => {
|
|
1654
1654
|
if (targetSelection) syncLexicalSelectionFromChatComposerSelection(editor, targetSelection);
|
|
1655
1655
|
});
|
|
1656
1656
|
}
|
|
1657
1657
|
requestAnimationFrame(() => {
|
|
1658
|
-
|
|
1658
|
+
isApplyingExternalUpdateRef.current = false;
|
|
1659
1659
|
});
|
|
1660
1660
|
}, [
|
|
1661
1661
|
editor,
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1662
|
+
editorSignatureRef,
|
|
1663
|
+
isApplyingExternalUpdateRef,
|
|
1664
|
+
lastPublishedSignatureRef,
|
|
1665
|
+
nodes,
|
|
1666
|
+
pendingSelectionRef,
|
|
1667
|
+
selectionRef,
|
|
1668
|
+
shouldFocusAfterSyncRef
|
|
1669
1669
|
]);
|
|
1670
1670
|
useEffect(() => {
|
|
1671
1671
|
return mergeRegister(editor.registerUpdateListener(({ editorState }) => {
|
|
1672
1672
|
const snapshot = readChatComposerSnapshotFromEditorState(editorState);
|
|
1673
1673
|
const signature = getChatComposerNodesSignature(snapshot.nodes);
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
if (
|
|
1678
|
-
if (signature ===
|
|
1679
|
-
|
|
1680
|
-
|
|
1674
|
+
selectionRef.current = snapshot.selection;
|
|
1675
|
+
editorSignatureRef.current = signature;
|
|
1676
|
+
syncSlashState(snapshot.nodes, snapshot.selection);
|
|
1677
|
+
if (isApplyingExternalUpdateRef.current || isComposingRef.current) return;
|
|
1678
|
+
if (signature === lastPublishedSignatureRef.current) return;
|
|
1679
|
+
lastPublishedSignatureRef.current = signature;
|
|
1680
|
+
onNodesChange(snapshot.nodes);
|
|
1681
1681
|
}), editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
|
|
1682
1682
|
const snapshot = readChatComposerSnapshotFromEditorState(editor.getEditorState());
|
|
1683
|
-
|
|
1684
|
-
if (!
|
|
1683
|
+
selectionRef.current = snapshot.selection;
|
|
1684
|
+
if (!isComposingRef.current) syncSlashState(snapshot.nodes, snapshot.selection);
|
|
1685
1685
|
return false;
|
|
1686
1686
|
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(BLUR_COMMAND, () => {
|
|
1687
|
-
|
|
1687
|
+
onBlur();
|
|
1688
1688
|
return false;
|
|
1689
|
-
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_DOWN_COMMAND, (event) =>
|
|
1689
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_DOWN_COMMAND, (event) => onKeyDown(event), COMMAND_PRIORITY_HIGH));
|
|
1690
1690
|
}, [
|
|
1691
1691
|
editor,
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1692
|
+
editorSignatureRef,
|
|
1693
|
+
isApplyingExternalUpdateRef,
|
|
1694
|
+
isComposingRef,
|
|
1695
|
+
lastPublishedSignatureRef,
|
|
1696
|
+
onBlur,
|
|
1697
|
+
onKeyDown,
|
|
1698
|
+
onNodesChange,
|
|
1699
|
+
selectionRef,
|
|
1700
|
+
syncSlashState
|
|
1701
1701
|
]);
|
|
1702
1702
|
return null;
|
|
1703
1703
|
}
|