@foundationui/smart-input
Advanced tools
Comparing version 1.0.87 to 1.0.88
import React, { HTMLAttributes, MutableRefObject } from 'react'; | ||
import { useSmartInput } from './useSmartInput'; | ||
/** | ||
@@ -6,2 +7,3 @@ * Properties for the `SmartInput` component. | ||
interface SmartInputProps<P> extends Omit<HTMLAttributes<HTMLElement>, 'onChange'> { | ||
smartInputHooks?: ReturnType<typeof useSmartInput>; | ||
/** | ||
@@ -48,2 +50,6 @@ * The path of the model to use for completions, e.g. "my-org/my-input". | ||
/** | ||
* External hook to | ||
*/ | ||
requestCompletion?: () => void; | ||
/** | ||
* A ref to the underlying contenteditable wrapper element. This can be used to focus the editor, select text, etc. | ||
@@ -50,0 +56,0 @@ */ |
@@ -8,3 +8,3 @@ import { useFoundationModel } from '@foundationui/react-hooks'; | ||
export declare class SmartInputFetcher { | ||
addCompletion: (text: string, completion: ICompletionResponse) => void; | ||
addCompletion: (text: string, completion: ICompletionResponse, force?: boolean) => void; | ||
foundationModel: ReturnType<typeof useFoundationModel>; | ||
@@ -43,3 +43,3 @@ model: string; | ||
}>; | ||
constructor(addCompletion: (text: string, completion: ICompletionResponse) => void, foundationModel: ReturnType<typeof useFoundationModel>, model: string); | ||
constructor(addCompletion: (text: string, completion: ICompletionResponse, force?: boolean) => void, foundationModel: ReturnType<typeof useFoundationModel>, model: string); | ||
fetchCompletion: { | ||
@@ -46,0 +46,0 @@ (...args: any[]): any; |
import React, { HTMLAttributes, MutableRefObject } from 'react'; | ||
import { useSmartInput } from './useSmartInput'; | ||
/** | ||
@@ -6,2 +7,3 @@ * Properties for the `SmartInput` component. | ||
interface SmartInputProps<P> extends Omit<HTMLAttributes<HTMLElement>, 'onChange'> { | ||
smartInputHooks?: ReturnType<typeof useSmartInput>; | ||
/** | ||
@@ -48,2 +50,6 @@ * The path of the model to use for completions, e.g. "my-org/my-input". | ||
/** | ||
* External hook to | ||
*/ | ||
requestCompletion?: () => void; | ||
/** | ||
* A ref to the underlying contenteditable wrapper element. This can be used to focus the editor, select text, etc. | ||
@@ -50,0 +56,0 @@ */ |
@@ -8,3 +8,3 @@ import { useFoundationModel } from '@foundationui/react-hooks'; | ||
export declare class SmartInputFetcher { | ||
addCompletion: (text: string, completion: ICompletionResponse) => void; | ||
addCompletion: (text: string, completion: ICompletionResponse, force?: boolean) => void; | ||
foundationModel: ReturnType<typeof useFoundationModel>; | ||
@@ -43,3 +43,3 @@ model: string; | ||
}>; | ||
constructor(addCompletion: (text: string, completion: ICompletionResponse) => void, foundationModel: ReturnType<typeof useFoundationModel>, model: string); | ||
constructor(addCompletion: (text: string, completion: ICompletionResponse, force?: boolean) => void, foundationModel: ReturnType<typeof useFoundationModel>, model: string); | ||
fetchCompletion: { | ||
@@ -46,0 +46,0 @@ (...args: any[]): any; |
import React, { HTMLAttributes, MutableRefObject } from 'react'; | ||
import * as slate from 'slate'; | ||
import { BaseEditor, Operation, Range, Descendant } from 'slate'; | ||
import * as slate_react from 'slate-react'; | ||
import { ReactEditor } from 'slate-react'; | ||
import { useFoundationModel } from '@foundationui/react-hooks'; | ||
/** | ||
* The shape of the completion response from the API. | ||
*/ | ||
interface ICompletionResponse { | ||
sid: string; | ||
input: string; | ||
completion?: string | null; | ||
} | ||
type CustomElement = { | ||
type: 'text' | 'completion' | undefined; | ||
children: CustomText[]; | ||
}; | ||
type CustomText = { | ||
text: string; | ||
type: undefined; | ||
}; | ||
type CustomDescendant = CustomElement | CustomText; | ||
type CEditor = Omit<BaseEditor, 'children'> & ReactEditor & { | ||
children: CustomDescendant[]; | ||
}; | ||
declare module 'slate' { | ||
interface CustomTypes { | ||
Editor: CEditor; | ||
Element: CustomElement; | ||
Text: CustomText; | ||
} | ||
} | ||
interface Batch { | ||
operations: Operation[]; | ||
selectionBefore: Range | null; | ||
} | ||
/** | ||
* `History` objects hold all of the operations that are applied to a value, so | ||
* they can be undone or redone as necessary. | ||
*/ | ||
interface History { | ||
redos: Batch[]; | ||
undos: Batch[]; | ||
} | ||
declare const History: { | ||
/** | ||
* Check if a value is a `History` object. | ||
*/ | ||
isHistory(value: any): value is History; | ||
}; | ||
/** | ||
* `HistoryEditor` contains helpers for history-enabled editors. | ||
*/ | ||
interface HistoryEditor extends CEditor { | ||
history: History; | ||
undo: () => void; | ||
redo: () => void; | ||
} | ||
declare const HistoryEditor: { | ||
/** | ||
* Check if a value is a `HistoryEditor` object. | ||
*/ | ||
isHistoryEditor(value: any): value is HistoryEditor; | ||
/** | ||
* Get the merge flag's current value. | ||
*/ | ||
isMerging(editor: HistoryEditor): boolean | undefined; | ||
/** | ||
* Get the saving flag's current value. | ||
*/ | ||
isSaving(editor: HistoryEditor): boolean | undefined; | ||
/** | ||
* Redo to the previous saved state. | ||
*/ | ||
redo(editor: HistoryEditor): void; | ||
/** | ||
* Undo to the previous saved state. | ||
*/ | ||
undo(editor: HistoryEditor): void; | ||
/** | ||
* Apply a series of changes inside a synchronous `fn`, without merging any of | ||
* the new operations into previous save point in the history. | ||
*/ | ||
withoutMerging(editor: HistoryEditor, fn: () => void): void; | ||
/** | ||
* Apply a series of changes inside a synchronous `fn`, without saving any of | ||
* their operations into the history. | ||
*/ | ||
withoutSaving(editor: HistoryEditor, fn: () => void): void; | ||
}; | ||
/** | ||
* Responsible for fetching completions from a model and adding them to the input. | ||
* Each `<SmartInput />` component rendered to the DOM will have its own instance of this class as state. | ||
*/ | ||
declare class SmartInputFetcher { | ||
addCompletion: (text: string, completion: ICompletionResponse, force?: boolean) => void; | ||
foundationModel: ReturnType<typeof useFoundationModel>; | ||
model: string; | ||
/** | ||
* sequenceId is used to ensure that we don't add completions from a previous fetch, | ||
* we increment it each time we request to fetch a new completion because the user input has changed | ||
*/ | ||
sequenceId: number; | ||
/** | ||
* sessionId is used to track this particular instantiation of the `<SmartInput />` component | ||
*/ | ||
sessionId: string; | ||
/** | ||
* completionCache is used to cache the completions that we've already fetched from the model | ||
*/ | ||
completionCache: Record<string, ICompletionResponse | null>; | ||
/** | ||
* currentCompletion tracks the latest text that was sent to the model for fetching completions, and the | ||
* completion that was returned (if any ~ we may still be waiting for it) | ||
*/ | ||
currentCompletion: { | ||
sequenceId: number; | ||
text: string; | ||
completion?: string | null; | ||
} | null; | ||
blurred: boolean; | ||
ignoreNextFetch: boolean; | ||
eventsByModel: Record<string, { | ||
model: string; | ||
session: string; | ||
input: string; | ||
user?: string; | ||
context?: string; | ||
}>; | ||
constructor(addCompletion: (text: string, completion: ICompletionResponse, force?: boolean) => void, foundationModel: ReturnType<typeof useFoundationModel>, model: string); | ||
fetchCompletion: { | ||
(...args: any[]): any; | ||
cancel: () => void; | ||
flush: () => any; | ||
}; | ||
updateCompletion(completionSid: string, arg: { | ||
seen?: boolean; | ||
accepted?: boolean; | ||
}): void; | ||
addEvent: { | ||
(...args: any[]): any; | ||
cancel: () => void; | ||
flush: () => any; | ||
}; | ||
} | ||
declare function useSmartInput(arg: { | ||
model: string; | ||
value: string; | ||
onAcceptCompletion?: (completion: string) => void; | ||
onShowCompletion?: (completion: string) => void; | ||
context?: string; | ||
user?: string; | ||
dev?: boolean; | ||
safeMode?: boolean; | ||
}): { | ||
editor: Omit<slate.BaseEditor, "children"> & slate_react.ReactEditor & { | ||
children: CustomDescendant[]; | ||
} & HistoryEditor; | ||
foundationModel: any; | ||
completion: ICompletionResponse | null; | ||
setCompletion: React.Dispatch<React.SetStateAction<ICompletionResponse | null>>; | ||
fetcher: SmartInputFetcher; | ||
onChange: (value: Descendant[]) => string; | ||
triggerCompletion: () => void; | ||
addCompletion: (completion: ICompletionResponse, force?: boolean) => void; | ||
acceptCompletion: () => void; | ||
clearCompletion: () => void; | ||
}; | ||
/** | ||
* Properties for the `SmartInput` component. | ||
*/ | ||
interface SmartInputProps<P> extends Omit<HTMLAttributes<HTMLElement>, 'onChange'> { | ||
smartInputHooks?: ReturnType<typeof useSmartInput>; | ||
/** | ||
@@ -48,2 +222,6 @@ * The path of the model to use for completions, e.g. "my-org/my-input". | ||
/** | ||
* External hook to | ||
*/ | ||
requestCompletion?: () => void; | ||
/** | ||
* A ref to the underlying contenteditable wrapper element. This can be used to focus the editor, select text, etc. | ||
@@ -50,0 +228,0 @@ */ |
import React, { HTMLAttributes, MutableRefObject } from 'react'; | ||
import { useSmartInput } from './useSmartInput'; | ||
/** | ||
@@ -6,2 +7,3 @@ * Properties for the `SmartInput` component. | ||
interface SmartInputProps<P> extends Omit<HTMLAttributes<HTMLElement>, 'onChange'> { | ||
smartInputHooks?: ReturnType<typeof useSmartInput>; | ||
/** | ||
@@ -48,2 +50,6 @@ * The path of the model to use for completions, e.g. "my-org/my-input". | ||
/** | ||
* External hook to | ||
*/ | ||
requestCompletion?: () => void; | ||
/** | ||
* A ref to the underlying contenteditable wrapper element. This can be used to focus the editor, select text, etc. | ||
@@ -50,0 +56,0 @@ */ |
@@ -8,3 +8,3 @@ import { useFoundationModel } from '@foundationui/react-hooks'; | ||
export declare class SmartInputFetcher { | ||
addCompletion: (text: string, completion: ICompletionResponse) => void; | ||
addCompletion: (text: string, completion: ICompletionResponse, force?: boolean) => void; | ||
foundationModel: ReturnType<typeof useFoundationModel>; | ||
@@ -43,3 +43,3 @@ model: string; | ||
}>; | ||
constructor(addCompletion: (text: string, completion: ICompletionResponse) => void, foundationModel: ReturnType<typeof useFoundationModel>, model: string); | ||
constructor(addCompletion: (text: string, completion: ICompletionResponse, force?: boolean) => void, foundationModel: ReturnType<typeof useFoundationModel>, model: string); | ||
fetchCompletion: { | ||
@@ -46,0 +46,0 @@ (...args: any[]): any; |
{ | ||
"name": "@foundationui/smart-input", | ||
"version": "1.0.87", | ||
"version": "1.0.88", | ||
"description": "Smart input/textarea component for React. Learns to provide inline, tab-completeable suggestions.", | ||
@@ -38,3 +38,3 @@ "type": "module", | ||
"dependencies": { | ||
"@foundationui/react-hooks": "^0.0.1", | ||
"@foundationui/react-hooks": "^0.0.2", | ||
"slate": "^0.87.0", | ||
@@ -41,0 +41,0 @@ "slate-react": "^0.88.0" |
@@ -61,4 +61,2 @@ # `<SmartInput>` | ||
![admin console playground](https://raw.githubusercontent.com/foundation-ui/assets/main/img/admin-playground.png) | ||
<br> | ||
@@ -81,3 +79,8 @@ | ||
```jsx | ||
<SmartInput context="Subject: 'This is too easy to integrate'\nTo: 'support@foundation-ui.com'" /> | ||
<SmartInput | ||
context={JSON.stringify({ | ||
subject: 'This is too easy to integrate', | ||
recipient: 'jane@doe.com', | ||
})} | ||
/> | ||
``` | ||
@@ -93,4 +96,2 @@ | ||
![admin UI accepts a bulk upload of data](https://raw.githubusercontent.com/foundation-ui/assets/main/img/admin-upload-data.gif) | ||
You can also send your data to our data ingestion endpoint, which accepts inputs your users have already written. | ||
@@ -158,6 +159,2 @@ | ||
<br> | ||
![branch](https://raw.githubusercontent.com/foundation-ui/assets/main/img/branch.gif) | ||
## :scroll: Props | ||
@@ -164,0 +161,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
583818
44
3216
3
263
+ Added@foundationui/react-hooks@0.0.2(transitive)
- Removed@foundationui/react-hooks@0.0.1(transitive)