@ewjdev/anyclick-react 2.0.0 → 3.0.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.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as React$1 from 'react';
3
- import React__default, { ReactNode, CSSProperties } from 'react';
3
+ import React__default, { CSSProperties, ReactNode } from 'react';
4
4
  import { AnyclickAdapter, AnyclickType, AnyclickPayload, ScreenshotConfig, AnyclickTriggerEvent, ScreenshotData, AnyclickMenuEvent } from '@ewjdev/anyclick-core';
5
5
  export { ALL_CURATED_PROPERTIES, AccessibilityInfo, AnyclickAdapter, AnyclickPayload, AnyclickType, BoxModelInfo, CURATED_STYLE_PROPERTIES, ComputedStylesInfo, DEFAULT_SCREENSHOT_CONFIG, DEFAULT_SENSITIVE_SELECTORS, ElementContext, ElementInspectInfo, PageContext, ScreenshotCapture, ScreenshotCaptureMode, ScreenshotConfig, ScreenshotData, captureAllScreenshots, captureScreenshot, estimateTotalSize, formatBoxModel, formatBytes, formatStylesAsCSS, getAccessibilityInfo, getAttributes, getBoxModelInfo, getComputedStyles, getElementInspectInfo, isScreenshotSupported } from '@ewjdev/anyclick-core';
6
6
  import * as zustand from 'zustand';
@@ -139,6 +139,160 @@ interface InspectSimpleProps {
139
139
  }
140
140
  declare function InspectSimple({ visible, targetElement, onClose, ideConfig, style, className, highlightColors, }: InspectSimpleProps): react_jsx_runtime.JSX.Element | null;
141
141
 
142
+ /**
143
+ * Type definitions for QuickChat component.
144
+ *
145
+ * @module QuickChat/types
146
+ * @since 2.0.0
147
+ */
148
+
149
+ /**
150
+ * Context payload chunk that can be included or excluded by the user.
151
+ */
152
+ interface ContextChunk {
153
+ /** Unique identifier for the chunk */
154
+ id: string;
155
+ /** Human-readable label for the chunk */
156
+ label: string;
157
+ /** The actual content/data */
158
+ content: string;
159
+ /** Type of context (element, text, error, etc.) */
160
+ type: "element" | "text" | "error" | "navigation" | "custom";
161
+ /** Whether this chunk is included in the payload (default: true) */
162
+ included: boolean;
163
+ /** Size in characters */
164
+ size: number;
165
+ }
166
+ /**
167
+ * A suggested prompt from the AI pre-pass.
168
+ */
169
+ interface SuggestedPrompt {
170
+ /** Unique identifier */
171
+ id: string;
172
+ /** The prompt text */
173
+ text: string;
174
+ /** Optional category */
175
+ category?: string;
176
+ }
177
+ /**
178
+ * Quick action available for AI responses.
179
+ */
180
+ interface QuickAction {
181
+ /** Unique identifier */
182
+ id: string;
183
+ /** Label to display */
184
+ label: string;
185
+ /** Icon to display */
186
+ icon?: ReactNode;
187
+ /** Action handler */
188
+ onClick: () => void;
189
+ }
190
+ /**
191
+ * A single chat message.
192
+ */
193
+ interface ChatMessage {
194
+ /** Unique identifier */
195
+ id: string;
196
+ /** Role of the sender */
197
+ role: "user" | "assistant" | "system";
198
+ /** Message content */
199
+ content: string;
200
+ /** Timestamp */
201
+ timestamp: number;
202
+ /** Whether the message is currently streaming */
203
+ isStreaming?: boolean;
204
+ /** Quick actions available for this message */
205
+ actions?: QuickAction[];
206
+ }
207
+ /**
208
+ * Configuration for t3.chat integration.
209
+ */
210
+ interface T3ChatIntegrationConfig {
211
+ /** Whether to show the "Send to t3.chat" button */
212
+ enabled?: boolean;
213
+ /** Base URL for t3.chat (default: https://t3.chat) */
214
+ baseUrl?: string;
215
+ /** Label for the button (default: "Ask t3.chat") */
216
+ label?: string;
217
+ }
218
+ /**
219
+ * Configuration for the QuickChat component.
220
+ */
221
+ interface QuickChatConfig {
222
+ /** API endpoint for chat requests */
223
+ endpoint?: string;
224
+ /** Model to use for the main chat (default: auto) */
225
+ model?: string;
226
+ /** Model to use for pre-pass suggestions (default: gpt-5-nano) */
227
+ prePassModel?: string;
228
+ /** Maximum response length in characters */
229
+ maxResponseLength?: number;
230
+ /** Whether to show context redaction UI */
231
+ showRedactionUI?: boolean;
232
+ /** Whether to show suggested prompts */
233
+ showSuggestions?: boolean;
234
+ /** Custom system prompt */
235
+ systemPrompt?: string;
236
+ /** Placeholder text for input */
237
+ placeholder?: string;
238
+ /** Header title */
239
+ title?: string;
240
+ /** t3.chat integration settings */
241
+ t3chat?: T3ChatIntegrationConfig;
242
+ }
243
+ /**
244
+ * Props for the QuickChat component.
245
+ */
246
+ interface QuickChatProps {
247
+ /** Whether the chat is visible */
248
+ visible: boolean;
249
+ /** Target element that was right-clicked */
250
+ targetElement: Element | null;
251
+ /** Container element */
252
+ containerElement: Element | null;
253
+ /** Callback when chat is closed */
254
+ onClose: () => void;
255
+ /** Callback when user wants to pin the chat */
256
+ onPin?: (pinned: boolean) => void;
257
+ /** Whether the chat is pinned */
258
+ isPinned?: boolean;
259
+ /** Configuration options */
260
+ config?: QuickChatConfig;
261
+ /** Custom styles */
262
+ style?: CSSProperties;
263
+ /** Custom class name */
264
+ className?: string;
265
+ /** Initial input value (for type-to-chat feature) */
266
+ initialInput?: string;
267
+ /** Callback when initial input has been consumed */
268
+ onInitialInputConsumed?: () => void;
269
+ }
270
+ /**
271
+ * State for the QuickChat hook.
272
+ */
273
+ interface QuickChatState {
274
+ /** Current input value */
275
+ input: string;
276
+ /** Chat messages */
277
+ messages: ChatMessage[];
278
+ /** Whether we're loading suggestions */
279
+ isLoadingSuggestions: boolean;
280
+ /** Whether we're sending a message */
281
+ isSending: boolean;
282
+ /** Whether we're streaming a response */
283
+ isStreaming: boolean;
284
+ /** Suggested prompts from pre-pass */
285
+ suggestedPrompts: SuggestedPrompt[];
286
+ /** Context chunks with redaction state */
287
+ contextChunks: ContextChunk[];
288
+ /** Error message if any */
289
+ error: string | null;
290
+ }
291
+ /**
292
+ * Default configuration values.
293
+ */
294
+ declare const DEFAULT_QUICK_CHAT_CONFIG: Required<QuickChatConfig>;
295
+
142
296
  /**
143
297
  * Type definitions for @ewjdev/anyclick-react.
144
298
  *
@@ -439,6 +593,11 @@ interface AnyclickProviderProps {
439
593
  onSubmitError?: (error: Error, payload: AnyclickPayload) => void;
440
594
  /** Callback after successful submission */
441
595
  onSubmitSuccess?: (payload: AnyclickPayload) => void;
596
+ /**
597
+ * Configuration for QuickChat AI assistant.
598
+ * Set to enable the lightweight AI chat in the context menu.
599
+ */
600
+ quickChatConfig?: QuickChatConfig;
442
601
  /**
443
602
  * Whether to scope this provider to its children only.
444
603
  * When true, events will only be captured for elements within this provider's subtree.
@@ -541,6 +700,11 @@ interface ContextMenuProps {
541
700
  };
542
701
  /** Menu positioning mode (default: 'inView') */
543
702
  positionMode?: MenuPositionMode;
703
+ /**
704
+ * Configuration for QuickChat AI assistant.
705
+ * When provided, shows the QuickChat interface in the context menu.
706
+ */
707
+ quickChatConfig?: QuickChatConfig;
544
708
  /** Configuration for screenshot capture */
545
709
  screenshotConfig?: ScreenshotConfig;
546
710
  /** Custom styles */
@@ -591,7 +755,7 @@ interface ScreenshotPreviewProps {
591
755
  *
592
756
  * @since 1.0.0
593
757
  */
594
- declare function AnyclickProvider({ adapter, children, cooldownMs, disabled, header, highlightConfig, maxAncestors, maxInnerTextLength, maxOuterHTMLLength, menuClassName, menuItems, menuStyle, metadata, onSubmitError, onSubmitSuccess, scoped, screenshotConfig, stripAttributes, targetFilter, theme, touchHoldDurationMs, touchMoveThreshold, }: AnyclickProviderProps): react_jsx_runtime.JSX.Element;
758
+ declare function AnyclickProvider({ adapter, children, cooldownMs, disabled, header, highlightConfig, maxAncestors, maxInnerTextLength, maxOuterHTMLLength, menuClassName, menuItems, menuStyle, metadata, onSubmitError, onSubmitSuccess, quickChatConfig, scoped, screenshotConfig, stripAttributes, targetFilter, theme, touchHoldDurationMs, touchMoveThreshold, }: AnyclickProviderProps): react_jsx_runtime.JSX.Element;
595
759
  /**
596
760
  * @deprecated Use {@link AnyclickProvider} instead. Will be removed in v2.0.0.
597
761
  */
@@ -617,7 +781,7 @@ declare function FunModeBridge(): null;
617
781
  *
618
782
  * @since 1.0.0
619
783
  */
620
- declare function ContextMenu({ className, containerElement, footer, header, highlightConfig, isSubmitting, items, onClose, onSelect, position, positionMode, screenshotConfig, style, targetElement, visible, }: ContextMenuProps): react_jsx_runtime.JSX.Element | null;
784
+ declare function ContextMenu({ className, containerElement, footer, header, highlightConfig, isSubmitting, items, onClose, onSelect, position, positionMode, quickChatConfig, screenshotConfig, style, targetElement, visible, }: ContextMenuProps): react_jsx_runtime.JSX.Element;
621
785
 
622
786
  /**
623
787
  * Screenshot preview component - shows captured screenshots before sending.
@@ -987,6 +1151,160 @@ declare function createPresetMenu(role: PresetRole, options?: CreatePresetMenuOp
987
1151
  */
988
1152
  declare function listPresets(): PresetConfig[];
989
1153
 
1154
+ /**
1155
+ * Creates a menu item for sending selected text or a query to t3.chat.
1156
+ *
1157
+ * Can be added to any custom menu configuration. Uses the current text
1158
+ * selection if available, otherwise opens t3.chat without a pre-filled query.
1159
+ *
1160
+ * @param options - Optional customization for the menu item
1161
+ * @returns A ContextMenuItem configured for t3.chat
1162
+ *
1163
+ * @example
1164
+ * ```tsx
1165
+ * import { createT3ChatMenuItem } from "@ewjdev/anyclick-react";
1166
+ *
1167
+ * const menuItems = [
1168
+ * { label: "Bug", type: "bug", showComment: true },
1169
+ * createT3ChatMenuItem(),
1170
+ * ];
1171
+ * ```
1172
+ *
1173
+ * @since 1.5.0
1174
+ */
1175
+ declare function createT3ChatMenuItem(options?: {
1176
+ /** Custom label for the menu item */
1177
+ label?: string;
1178
+ /** Base URL for t3.chat */
1179
+ baseUrl?: string;
1180
+ }): ContextMenuItem;
1181
+ /**
1182
+ * Gets the currently selected text on the page.
1183
+ *
1184
+ * Useful for checking if text is selected before showing certain menu items.
1185
+ *
1186
+ * @returns The selected text, or empty string if nothing is selected
1187
+ *
1188
+ * @example
1189
+ * ```tsx
1190
+ * const selection = getSelectedText();
1191
+ * if (selection) {
1192
+ * console.log("Selected:", selection);
1193
+ * }
1194
+ * ```
1195
+ *
1196
+ * @since 1.5.0
1197
+ */
1198
+ declare function getSelectedText(): string;
1199
+ /**
1200
+ * Checks if there is currently any text selected on the page.
1201
+ *
1202
+ * @returns true if text is selected
1203
+ *
1204
+ * @since 1.5.0
1205
+ */
1206
+ declare function hasTextSelection(): boolean;
1207
+ /**
1208
+ * Detects if an element is or contains an image that can be uploaded.
1209
+ *
1210
+ * Checks for:
1211
+ * - `<img>` elements
1212
+ * - `<picture>` elements
1213
+ * - `<canvas>` elements
1214
+ * - `<svg>` elements
1215
+ * - CSS background images
1216
+ *
1217
+ * @param element - The element to check
1218
+ * @returns Object with isImage flag and optional image source
1219
+ *
1220
+ * @since 1.5.0
1221
+ */
1222
+ declare function detectImageElement(element: Element | null): {
1223
+ isImage: boolean;
1224
+ src?: string;
1225
+ type?: "img" | "picture" | "svg" | "canvas" | "background";
1226
+ };
1227
+ /**
1228
+ * Creates a menu item for uploading images to UploadThing.
1229
+ *
1230
+ * The menu item will upload the target element if it's an image,
1231
+ * or a screenshot of the element otherwise.
1232
+ *
1233
+ * Requires an UploadThing adapter to be configured. The onClick handler
1234
+ * receives the target element and can use detectImageElement to determine
1235
+ * if it's an image.
1236
+ *
1237
+ * @param options - Configuration options
1238
+ * @returns A ContextMenuItem configured for UploadThing
1239
+ *
1240
+ * @example
1241
+ * ```tsx
1242
+ * import { createUploadThingMenuItem } from "@ewjdev/anyclick-react";
1243
+ *
1244
+ * const menuItems = [
1245
+ * createUploadThingMenuItem({
1246
+ * endpoint: "/api/uploadthing",
1247
+ * onUploadComplete: (result) => {
1248
+ * console.log("Uploaded:", result.url);
1249
+ * },
1250
+ * }),
1251
+ * ];
1252
+ * ```
1253
+ *
1254
+ * @since 1.5.0
1255
+ */
1256
+ declare function createUploadThingMenuItem(options?: {
1257
+ /** Custom label for the menu item */
1258
+ label?: string;
1259
+ /** API endpoint for uploading */
1260
+ endpoint?: string;
1261
+ /** Callback when upload completes */
1262
+ onUploadComplete?: (result: {
1263
+ url?: string;
1264
+ error?: string;
1265
+ }) => void;
1266
+ /** Callback when upload fails */
1267
+ onUploadError?: (error: Error) => void;
1268
+ }): ContextMenuItem;
1269
+ /**
1270
+ * Creates a menu item for uploading screenshots to UploadThing.
1271
+ *
1272
+ * This captures a screenshot of the target element and uploads it.
1273
+ * Requires the screenshot preview to be enabled for best results.
1274
+ *
1275
+ * @param options - Configuration options
1276
+ * @returns A ContextMenuItem configured for screenshot uploads
1277
+ *
1278
+ * @example
1279
+ * ```tsx
1280
+ * import { createUploadScreenshotMenuItem } from "@ewjdev/anyclick-react";
1281
+ *
1282
+ * const menuItems = [
1283
+ * createUploadScreenshotMenuItem({
1284
+ * endpoint: "/api/uploadthing",
1285
+ * onUploadComplete: (result) => {
1286
+ * navigator.clipboard.writeText(result.url);
1287
+ * },
1288
+ * }),
1289
+ * ];
1290
+ * ```
1291
+ *
1292
+ * @since 1.5.0
1293
+ */
1294
+ declare function createUploadScreenshotMenuItem(options?: {
1295
+ /** Custom label for the menu item */
1296
+ label?: string;
1297
+ /** API endpoint for uploading */
1298
+ endpoint?: string;
1299
+ /** Callback when upload completes */
1300
+ onUploadComplete?: (result: {
1301
+ url?: string;
1302
+ error?: string;
1303
+ }) => void;
1304
+ /** Callback when upload fails */
1305
+ onUploadError?: (error: Error) => void;
1306
+ }): ContextMenuItem;
1307
+
990
1308
  /**
991
1309
  * Style definitions for anyclick-react components.
992
1310
  *
@@ -1277,4 +1595,57 @@ interface AnyclickLogoProps {
1277
1595
  */
1278
1596
  declare function AnyclickLogo({ size, borderWidth, primaryColor, backgroundColor, className, style, onClick, }: AnyclickLogoProps): react_jsx_runtime.JSX.Element;
1279
1597
 
1280
- export { AnyclickContext, type AnyclickContextValue, AnyclickLogo, type AnyclickLogoProps, AnyclickProvider, type AnyclickProviderProps, type AnyclickTheme, type AnyclickUserContext, type CompactModeConfig, ContextMenu, type ContextMenuItem, type ContextMenuProps, type CreatePresetMenuOptions, DEFAULT_COMPACT_CONFIG, FeedbackContext, type FeedbackMenuBadge, type FeedbackMenuStatus, FeedbackProvider, FunModeBridge, type FunModeThemeConfig, type HighlightColors, type HighlightConfig, type IDEConfig, type IDEProtocol, INSPECT_DIALOG_EVENT, type InspectDialogEventDetail, InspectDialogManager, type InspectDialogManagerProps, InspectSimple, type InspectSimpleProps, type MenuPositionMode, type PinnedPosition, type PresetConfig, type PresetRole, type ProviderInstance, ScreenshotPreview, type ScreenshotPreviewProps, type SourceLocation, applyHighlights, buildIDEUrl, clearHighlights, createIDEOpener, createPresetMenu, darkMenuStyles, defaultContainerSelectors, defaultHighlightColors, detectPreferredIDE, dispatchContextMenuEvent, filterMenuItemsByRole, findContainerParent, findSourceLocationInAncestors, formatSourceLocation, generateProviderId, getBadgeStyle, getSourceLocationFromElement, highlightContainer, highlightTarget, isIDEProtocolSupported, listPresets, menuCSSVariables, menuStyles, openInIDE, openInspectDialog, presetDefaults, useAnyclick, useFeedback, useProviderStore };
1598
+ /**
1599
+ * QuickChat component.
1600
+ */
1601
+ declare function QuickChat({ visible, targetElement, containerElement, onClose, onPin, isPinned: isPinnedProp, config, style, className, initialInput, onInitialInputConsumed, }: QuickChatProps): react_jsx_runtime.JSX.Element | null;
1602
+
1603
+ /**
1604
+ * Hook for managing QuickChat state and interactions.
1605
+ */
1606
+ declare function useQuickChat(targetElement: Element | null, containerElement: Element | null, config?: QuickChatConfig): {
1607
+ config: {
1608
+ endpoint: string;
1609
+ model: string;
1610
+ prePassModel: string;
1611
+ maxResponseLength: number;
1612
+ showRedactionUI: boolean;
1613
+ showSuggestions: boolean;
1614
+ systemPrompt: string;
1615
+ placeholder: string;
1616
+ title: string;
1617
+ t3chat: T3ChatIntegrationConfig;
1618
+ };
1619
+ setInput: (value: string) => void;
1620
+ toggleChunk: (chunkId: string) => void;
1621
+ toggleAllChunks: (included: boolean) => void;
1622
+ selectSuggestion: (prompt: SuggestedPrompt) => void;
1623
+ sendMessage: (messageText?: string) => Promise<void>;
1624
+ clearMessages: () => void;
1625
+ input: string;
1626
+ messages: ChatMessage[];
1627
+ isLoadingSuggestions: boolean;
1628
+ isSending: boolean;
1629
+ isStreaming: boolean;
1630
+ suggestedPrompts: SuggestedPrompt[];
1631
+ contextChunks: ContextChunk[];
1632
+ error: string | null;
1633
+ };
1634
+
1635
+ /**
1636
+ * Style definitions for QuickChat component.
1637
+ *
1638
+ * @module QuickChat/styles
1639
+ * @since 2.0.0
1640
+ */
1641
+
1642
+ /**
1643
+ * QuickChat component styles.
1644
+ */
1645
+ declare const quickChatStyles: Record<string, CSSProperties>;
1646
+ /**
1647
+ * CSS keyframes for animations (to be injected).
1648
+ */
1649
+ declare const quickChatKeyframes = "\n@keyframes blink {\n 0%, 50% { opacity: 1; }\n 51%, 100% { opacity: 0; }\n}\n\n@keyframes bounce {\n 0%, 80%, 100% { transform: scale(0); }\n 40% { transform: scale(1); }\n}\n\n@keyframes slideIn {\n from {\n opacity: 0;\n transform: translateY(-8px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n@keyframes slideInFromRight {\n from {\n transform: translateX(100%);\n }\n to {\n transform: translateX(0);\n }\n}\n\n@keyframes slideOutToRight {\n from {\n transform: translateX(0);\n }\n to {\n transform: translateX(100%);\n }\n}\n\n@keyframes fadeIn {\n from { opacity: 0; }\n to { opacity: 1; }\n}\n\n@keyframes spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n}\n\n@keyframes pulse {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.5; }\n}\n";
1650
+
1651
+ export { AnyclickContext, type AnyclickContextValue, AnyclickLogo, type AnyclickLogoProps, AnyclickProvider, type AnyclickProviderProps, type AnyclickTheme, type AnyclickUserContext, type ChatMessage, type CompactModeConfig, type ContextChunk, ContextMenu, type ContextMenuItem, type ContextMenuProps, type CreatePresetMenuOptions, DEFAULT_COMPACT_CONFIG, DEFAULT_QUICK_CHAT_CONFIG, FeedbackContext, type FeedbackMenuBadge, type FeedbackMenuStatus, FeedbackProvider, FunModeBridge, type FunModeThemeConfig, type HighlightColors, type HighlightConfig, type IDEConfig, type IDEProtocol, INSPECT_DIALOG_EVENT, type InspectDialogEventDetail, InspectDialogManager, type InspectDialogManagerProps, InspectSimple, type InspectSimpleProps, type MenuPositionMode, type PinnedPosition, type PresetConfig, type PresetRole, type ProviderInstance, type QuickAction, QuickChat, type QuickChatConfig, type QuickChatProps, type QuickChatState, ScreenshotPreview, type ScreenshotPreviewProps, type SourceLocation, type SuggestedPrompt, type T3ChatIntegrationConfig, applyHighlights, buildIDEUrl, clearHighlights, createIDEOpener, createPresetMenu, createT3ChatMenuItem, createUploadScreenshotMenuItem, createUploadThingMenuItem, darkMenuStyles, defaultContainerSelectors, defaultHighlightColors, detectImageElement, detectPreferredIDE, dispatchContextMenuEvent, filterMenuItemsByRole, findContainerParent, findSourceLocationInAncestors, formatSourceLocation, generateProviderId, getBadgeStyle, getSelectedText, getSourceLocationFromElement, hasTextSelection, highlightContainer, highlightTarget, isIDEProtocolSupported, listPresets, menuCSSVariables, menuStyles, openInIDE, openInspectDialog, presetDefaults, quickChatKeyframes, quickChatStyles, useAnyclick, useFeedback, useProviderStore, useQuickChat };