@copilotkit/react-textarea 1.53.0 → 1.53.1-next.1

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/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "version": "1.53.0",
13
+ "version": "1.53.1-next.1",
14
14
  "sideEffects": [
15
15
  "**/*.css"
16
16
  ],
@@ -70,9 +70,9 @@
70
70
  "slate-history": "^0.93.0",
71
71
  "slate-react": "^0.98.1",
72
72
  "tailwind-merge": "^1.13.2",
73
- "@copilotkit/react-core": "1.53.0",
74
- "@copilotkit/runtime-client-gql": "1.53.0",
75
- "@copilotkit/shared": "1.53.0"
73
+ "@copilotkit/react-core": "1.53.1-next.1",
74
+ "@copilotkit/runtime-client-gql": "1.53.1-next.1",
75
+ "@copilotkit/shared": "1.53.1-next.1"
76
76
  },
77
77
  "keywords": [
78
78
  "copilotkit",
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useLayoutEffect, useRef, useState } from "react";
2
2
  import { Editor, Location, Transforms } from "slate";
3
- import { useSlate, useSlateSelection } from "slate-react";
3
+ import { ReactEditor, useSlate, useSlateSelection } from "slate-react";
4
4
  import {
5
5
  getFullEditorTextWithNewlines,
6
6
  getTextAroundSelection,
@@ -123,6 +123,36 @@ export const HoveringToolbar = (props: HoveringToolbarProps) => {
123
123
  };
124
124
  }, [ref, setIsDisplayed]);
125
125
 
126
+ // Close the hovering editor on Escape and restore focus to the textarea.
127
+ // This complements the Escape handler in HoveringInsertionPromptBoxCore's
128
+ // onKeyDown. That handler covers Escape when the prompt input has focus;
129
+ // this document-level listener covers Escape from anywhere else in the popup.
130
+ // Both may fire when the input is focused (double setIsDisplayed(false) is
131
+ // harmless). If nested dismissible UI is ever added inside this toolbar,
132
+ // this listener will need stopPropagation guards to avoid stealing Escape.
133
+ useEffect(() => {
134
+ const handleEscapeKey = (event: KeyboardEvent) => {
135
+ if (event.key === "Escape") {
136
+ event.preventDefault();
137
+ setIsDisplayed(false);
138
+ // Re-focus the Slate editor after closing
139
+ try {
140
+ ReactEditor.focus(editor);
141
+ } catch {
142
+ // Editor may not be mounted, ignore
143
+ }
144
+ }
145
+ };
146
+
147
+ if (isDisplayed) {
148
+ document.addEventListener("keydown", handleEscapeKey);
149
+ }
150
+
151
+ return () => {
152
+ document.removeEventListener("keydown", handleEscapeKey);
153
+ };
154
+ }, [isDisplayed, setIsDisplayed, editor]);
155
+
126
156
  if (!isShown) {
127
157
  return null;
128
158
  }
@@ -178,6 +178,9 @@ export const HoveringInsertionPromptBoxCore = ({
178
178
  } else if (e.key === "Enter") {
179
179
  e.preventDefault();
180
180
  beginGeneratingAdjustment();
181
+ } else if (e.key === "Escape") {
182
+ e.preventDefault();
183
+ setIsDisplayed(false);
181
184
  }
182
185
  }}
183
186
  placeholder={placeholder}