@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 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(props) {
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
- props.editorRef.current = editor;
1627
+ editorRef.current = editor;
1628
1628
  return () => {
1629
- if (props.editorRef.current === editor) props.editorRef.current = null;
1629
+ if (editorRef.current === editor) editorRef.current = null;
1630
1630
  };
1631
- }, [editor, props.editorRef]);
1631
+ }, [editor, editorRef]);
1632
1632
  useLayoutEffect(() => {
1633
- editor.setEditable(!props.disabled);
1634
- }, [editor, props.disabled]);
1633
+ editor.setEditable(!disabled);
1634
+ }, [disabled, editor]);
1635
1635
  useLayoutEffect(() => {
1636
- const nextSignature = getChatComposerNodesSignature(props.nodes);
1637
- const pendingSelection = props.pendingSelectionRef.current;
1638
- const shouldSyncDocument = nextSignature !== props.editorSignatureRef.current;
1636
+ const nextSignature = getChatComposerNodesSignature(nodes);
1637
+ const pendingSelection = pendingSelectionRef.current;
1638
+ const shouldSyncDocument = nextSignature !== editorSignatureRef.current;
1639
1639
  if (!shouldSyncDocument && !pendingSelection) return;
1640
- props.isApplyingExternalUpdateRef.current = true;
1640
+ isApplyingExternalUpdateRef.current = true;
1641
1641
  if (shouldSyncDocument) {
1642
- syncLexicalEditorFromChatComposerState(editor, props.nodes, pendingSelection);
1643
- props.editorSignatureRef.current = nextSignature;
1644
- props.lastPublishedSignatureRef.current = nextSignature;
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
- props.selectionRef.current = pendingSelection;
1648
- props.pendingSelectionRef.current = null;
1647
+ selectionRef.current = pendingSelection;
1648
+ pendingSelectionRef.current = null;
1649
1649
  }
1650
- if (props.shouldFocusAfterSyncRef.current) {
1651
- props.shouldFocusAfterSyncRef.current = false;
1652
- const targetSelection = props.selectionRef.current;
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
- props.isApplyingExternalUpdateRef.current = false;
1658
+ isApplyingExternalUpdateRef.current = false;
1659
1659
  });
1660
1660
  }, [
1661
1661
  editor,
1662
- props.editorSignatureRef,
1663
- props.isApplyingExternalUpdateRef,
1664
- props.lastPublishedSignatureRef,
1665
- props.nodes,
1666
- props.pendingSelectionRef,
1667
- props.selectionRef,
1668
- props.shouldFocusAfterSyncRef
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
- props.selectionRef.current = snapshot.selection;
1675
- props.editorSignatureRef.current = signature;
1676
- props.syncSlashState(snapshot.nodes, snapshot.selection);
1677
- if (props.isApplyingExternalUpdateRef.current || props.isComposingRef.current) return;
1678
- if (signature === props.lastPublishedSignatureRef.current) return;
1679
- props.lastPublishedSignatureRef.current = signature;
1680
- props.onNodesChange(snapshot.nodes);
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
- props.selectionRef.current = snapshot.selection;
1684
- if (!props.isComposingRef.current) props.syncSlashState(snapshot.nodes, snapshot.selection);
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
- props.onBlur();
1687
+ onBlur();
1688
1688
  return false;
1689
- }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_DOWN_COMMAND, (event) => props.onKeyDown(event), COMMAND_PRIORITY_HIGH));
1689
+ }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_DOWN_COMMAND, (event) => onKeyDown(event), COMMAND_PRIORITY_HIGH));
1690
1690
  }, [
1691
1691
  editor,
1692
- props.editorSignatureRef,
1693
- props.isApplyingExternalUpdateRef,
1694
- props.isComposingRef,
1695
- props.lastPublishedSignatureRef,
1696
- props.onBlur,
1697
- props.onKeyDown,
1698
- props.onNodesChange,
1699
- props.selectionRef,
1700
- props.syncSlashState
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
  }