@refraction-ui/react 0.16.2 → 0.17.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.
@@ -0,0 +1,131 @@
1
+ import * as React from 'react';
2
+ import { ComposerTrigger, ComposerCandidate, ComposerAttachmentDraft, ComposerDraftStore, ComposerValidator, ComposerSubmission, ComposerAttachment, ComposerEvent, ComposerAPI, ComposerState, ComposerConfig } from '../composer/index.js';
3
+ export { ComposerAPI, ComposerAttachment, ComposerAttachmentDraft, ComposerAttachmentKind, ComposerAttachmentStatus, ComposerCandidate, ComposerConfig, ComposerDraft, ComposerDraftStore, ComposerEvent, ComposerMode, ComposerOutput, ComposerSelection, ComposerState, ComposerSubmission, ComposerToken, ComposerTrigger, ComposerTriggerResolver, ComposerTriggerScope, ComposerValidationResult, ComposerValidator, CounterState, EnterResult, PlacedToken, ResolvedToken, SuggestionState, composerAttachmentChipVariants, composerCounterVariants, composerFieldClass, composerMenuClass, composerMenuItemVariants, composerPrimaryActionVariants, composerSurfaceVariants, composerTokenPillClass, composerTrayClass, createComposer, toMessageAttachment } from '../composer/index.js';
4
+
5
+ /** All user-facing text; every entry is overridable via the `strings` prop. */
6
+ interface RefractionComposerStrings {
7
+ /** Accessible name of the whole composer landmark. */
8
+ composerLabel: string;
9
+ /** Accessible name of the message textarea (independent of the placeholder). */
10
+ messageLabel: string;
11
+ sendLabel: string;
12
+ stopLabel: string;
13
+ attachLabel: string;
14
+ removeAttachmentLabel: (name: string) => string;
15
+ /** Accessible name of the suggestion listbox. */
16
+ suggestionsLabel: string;
17
+ noMatchesLabel: (query: string) => string;
18
+ loadingLabel: string;
19
+ retryLabel: string;
20
+ trimmedNotice: string;
21
+ counterLabel: (remaining: number) => string;
22
+ editingLabel: string;
23
+ cancelEditLabel: string;
24
+ /** Live-region announcement while the suggestion menu shows results. */
25
+ resultsAnnouncement: (count: number) => string;
26
+ }
27
+ declare const DEFAULT_COMPOSER_STRINGS: RefractionComposerStrings;
28
+ interface PrimaryActionContext {
29
+ hasText: boolean;
30
+ canSend: boolean;
31
+ busy: boolean;
32
+ }
33
+ interface SuggestionRenderContext {
34
+ active: boolean;
35
+ index: number;
36
+ }
37
+ interface RefractionComposerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue' | 'onSubmit' | 'onError' | 'content' | 'placeholder' | 'dir'> {
38
+ /** Controlled value. When set, the prop wins over internal edits. */
39
+ value?: string;
40
+ /** Initial value for uncontrolled usage. */
41
+ defaultValue?: string;
42
+ /** Fired with the new text after every user-driven change (incl. submit clearing). */
43
+ onChange?: (value: string) => void;
44
+ placeholder?: string;
45
+ /** Distinct placeholder shown while disabled. Falls back to `placeholder`. */
46
+ disabledPlaceholder?: string;
47
+ /** Rows shown when empty. Default 1. */
48
+ minLines?: number;
49
+ /** Auto-grow ceiling; the field scrolls internally beyond it. Default 6. */
50
+ maxLines?: number;
51
+ /** Grapheme-cluster budget (not UTF-16 units). Fixed at mount. */
52
+ maxLength?: number;
53
+ maxAttachments?: number;
54
+ disabled?: boolean;
55
+ readOnly?: boolean;
56
+ /** Busy/streaming: swaps the default send button for a stop button. */
57
+ busy?: boolean;
58
+ onStop?: () => void;
59
+ autoFocus?: boolean;
60
+ dir?: 'ltr' | 'rtl' | 'auto';
61
+ /** Trigger configs (mention '@', slash '/', emoji ':', …). Fixed at mount. */
62
+ triggers?: ComposerTrigger[];
63
+ /**
64
+ * Whether a plain Enter submits. Defaults to true (SSR-deterministic);
65
+ * after mount a coarse pointer (`(pointer: coarse)`) flips the default to
66
+ * false. An explicit prop always wins.
67
+ */
68
+ submitOnEnter?: boolean;
69
+ strings?: Partial<RefractionComposerStrings>;
70
+ /** Rendered at the start of the action row (e.g. an attach button). */
71
+ leading?: React.ReactNode;
72
+ /** Rendered at the end of the action row, before the primary action. */
73
+ trailing?: React.ReactNode;
74
+ /** Replaces the built-in send/stop primary action. */
75
+ primaryAction?: (context: PrimaryActionContext) => React.ReactNode;
76
+ /** Custom row content for suggestion menu items. */
77
+ renderSuggestion?: (candidate: ComposerCandidate, context: SuggestionRenderContext) => React.ReactNode;
78
+ /** Attachments staged at creation (SSR-deterministic, e.g. restored drafts). */
79
+ initialAttachments?: ComposerAttachmentDraft[];
80
+ draftStore?: ComposerDraftStore;
81
+ draftKey?: string;
82
+ validator?: ComposerValidator;
83
+ replyToMessageId?: string;
84
+ onSubmit?: (submission: ComposerSubmission) => void;
85
+ /** ArrowUp on an empty field (desktop edit-last affordance). */
86
+ onEditLastRequested?: () => void;
87
+ /** Escape pressed while in edit mode (after the core restores the draft). */
88
+ onEditCancel?: () => void;
89
+ /** Throttled typing signal (core-owned leading-edge throttle). */
90
+ onTypingActivity?: () => void;
91
+ onAttachmentAdd?: (attachment: ComposerAttachment) => void;
92
+ onAttachmentRejected?: (event: Extract<ComposerEvent, {
93
+ type: 'attachment-rejected';
94
+ }>) => void;
95
+ /** Raw core notice channel ('paste-trimmed', 'insert-rejected', …). */
96
+ onEvent?: (event: ComposerEvent) => void;
97
+ /** Receives the composer core for imperative use (beginEdit, addAttachment, …). */
98
+ apiRef?: React.Ref<ComposerAPI>;
99
+ id?: string;
100
+ }
101
+ /**
102
+ * RefractionComposer — the chat message composer.
103
+ *
104
+ * Wraps the headless `@refraction-ui/composer` core: flat value + selection,
105
+ * atomic inline tokens (mention/slash/emoji triggers), attachments, drafts,
106
+ * busy/stop, edit-in-place, and one optimistic submit. `ref` targets the
107
+ * textarea; the core is reachable through `apiRef`.
108
+ */
109
+ declare const RefractionComposer: React.ForwardRefExoticComponent<RefractionComposerProps & React.RefAttributes<HTMLTextAreaElement>>;
110
+
111
+ interface UseComposerResult {
112
+ /** Live core snapshot (re-renders on change). */
113
+ state: ComposerState;
114
+ /** The underlying composer core, for imperative use (beginEdit, addAttachment, …). */
115
+ api: ComposerAPI;
116
+ }
117
+ /**
118
+ * useComposer — binds the headless `createComposer` core to React via
119
+ * `useSyncExternalStore`. The core is created once with the config of the
120
+ * first render (the core reads `maxLength`/`maxAttachments`/`validator`/
121
+ * `replyToMessageId`/draft fields lazily, so callers may mutate a stable
122
+ * config object to keep those live). The core is destroyed on unmount and
123
+ * lazily recreated if React StrictMode re-subscribes after that dev-only
124
+ * unmount/remount cycle.
125
+ *
126
+ * @param init Optional one-time initializer invoked right after creation and
127
+ * before the first snapshot (e.g. to seed attachments SSR-deterministically).
128
+ */
129
+ declare function useComposer(config?: ComposerConfig, init?: (api: ComposerAPI) => void): UseComposerResult;
130
+
131
+ export { DEFAULT_COMPOSER_STRINGS, type PrimaryActionContext, RefractionComposer, type RefractionComposerProps, type RefractionComposerStrings, type SuggestionRenderContext, type UseComposerResult, useComposer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@refraction-ui/react",
3
- "version": "0.16.2",
3
+ "version": "0.17.1",
4
4
  "description": "All Refraction UI React components in one package — headless, accessible, zero-dependency",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -80,6 +80,7 @@
80
80
  "@refraction-ui/react-combobox": "workspace:*",
81
81
  "@refraction-ui/react-command": "workspace:*",
82
82
  "@refraction-ui/react-command-input": "workspace:*",
83
+ "@refraction-ui/react-composer": "workspace:*",
83
84
  "@refraction-ui/react-content-protection": "workspace:*",
84
85
  "@refraction-ui/react-conversation": "workspace:*",
85
86
  "@refraction-ui/react-cookie-consent": "workspace:*",