@salmonui/chat 0.0.0-stage → 0.2.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.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -2
  3. package/dist/conversation/Conversation.d.ts +4 -0
  4. package/dist/conversation/Conversation.d.ts.map +1 -0
  5. package/dist/conversation/Conversation.js +588 -0
  6. package/dist/conversation/Conversation.js.map +1 -0
  7. package/dist/conversation/Item.d.ts +67 -0
  8. package/dist/conversation/Item.d.ts.map +1 -0
  9. package/dist/conversation/Item.js +149 -0
  10. package/dist/conversation/Item.js.map +1 -0
  11. package/dist/conversation/assistant-lazy.d.ts +6 -0
  12. package/dist/conversation/assistant-lazy.d.ts.map +1 -0
  13. package/dist/conversation/assistant-lazy.js +16 -0
  14. package/dist/conversation/assistant-lazy.js.map +1 -0
  15. package/dist/conversation/assistant-static.d.ts +4 -0
  16. package/dist/conversation/assistant-static.d.ts.map +1 -0
  17. package/dist/conversation/assistant-static.js +9 -0
  18. package/dist/conversation/assistant-static.js.map +1 -0
  19. package/dist/conversation/assistant-types.d.ts +2 -0
  20. package/dist/conversation/assistant-types.d.ts.map +1 -0
  21. package/dist/conversation/assistant-types.js +3 -0
  22. package/dist/conversation/assistant-types.js.map +1 -0
  23. package/dist/conversation/assistant.d.ts +54 -0
  24. package/dist/conversation/assistant.d.ts.map +1 -0
  25. package/dist/conversation/assistant.js +348 -0
  26. package/dist/conversation/assistant.js.map +1 -0
  27. package/dist/conversation/context.d.ts +80 -0
  28. package/dist/conversation/context.d.ts.map +1 -0
  29. package/dist/conversation/context.js +40 -0
  30. package/dist/conversation/context.js.map +1 -0
  31. package/dist/conversation/format.d.ts +33 -0
  32. package/dist/conversation/format.d.ts.map +1 -0
  33. package/dist/conversation/format.js +150 -0
  34. package/dist/conversation/format.js.map +1 -0
  35. package/dist/conversation/parts.d.ts +16 -0
  36. package/dist/conversation/parts.d.ts.map +1 -0
  37. package/dist/conversation/parts.js +326 -0
  38. package/dist/conversation/parts.js.map +1 -0
  39. package/dist/conversation/runner.d.ts +15 -0
  40. package/dist/conversation/runner.d.ts.map +1 -0
  41. package/dist/conversation/runner.js +52 -0
  42. package/dist/conversation/runner.js.map +1 -0
  43. package/dist/conversation/store.d.ts +63 -0
  44. package/dist/conversation/store.d.ts.map +1 -0
  45. package/dist/conversation/store.js +142 -0
  46. package/dist/conversation/store.js.map +1 -0
  47. package/dist/conversation/types.d.ts +473 -0
  48. package/dist/conversation/types.d.ts.map +1 -0
  49. package/dist/conversation/types.js +5 -0
  50. package/dist/conversation/types.js.map +1 -0
  51. package/dist/conversation.css +788 -0
  52. package/dist/conversation.d.ts +18 -0
  53. package/dist/conversation.d.ts.map +1 -0
  54. package/dist/conversation.js +26 -0
  55. package/dist/conversation.js.map +1 -0
  56. package/dist/inline-assist/InlineAssist.d.ts +16 -0
  57. package/dist/inline-assist/InlineAssist.d.ts.map +1 -0
  58. package/dist/inline-assist/InlineAssist.js +384 -0
  59. package/dist/inline-assist/InlineAssist.js.map +1 -0
  60. package/dist/inline-assist/model.d.ts +40 -0
  61. package/dist/inline-assist/model.d.ts.map +1 -0
  62. package/dist/inline-assist/model.js +87 -0
  63. package/dist/inline-assist/model.js.map +1 -0
  64. package/dist/inline-assist/types.d.ts +216 -0
  65. package/dist/inline-assist/types.d.ts.map +1 -0
  66. package/dist/inline-assist/types.js +5 -0
  67. package/dist/inline-assist/types.js.map +1 -0
  68. package/dist/inline-assist.css +890 -0
  69. package/dist/inline-assist.d.ts +5 -0
  70. package/dist/inline-assist.d.ts.map +1 -0
  71. package/dist/inline-assist.js +12 -0
  72. package/dist/inline-assist.js.map +1 -0
  73. package/dist/internal/stream-run.d.ts +71 -0
  74. package/dist/internal/stream-run.d.ts.map +1 -0
  75. package/dist/internal/stream-run.js +161 -0
  76. package/dist/internal/stream-run.js.map +1 -0
  77. package/dist/internal/suggest.d.ts +90 -0
  78. package/dist/internal/suggest.d.ts.map +1 -0
  79. package/dist/internal/suggest.js +332 -0
  80. package/dist/internal/suggest.js.map +1 -0
  81. package/dist/smart-paste/fields.d.ts +31 -0
  82. package/dist/smart-paste/fields.d.ts.map +1 -0
  83. package/dist/smart-paste/fields.js +162 -0
  84. package/dist/smart-paste/fields.js.map +1 -0
  85. package/dist/smart-paste/useSmartPaste.d.ts +38 -0
  86. package/dist/smart-paste/useSmartPaste.d.ts.map +1 -0
  87. package/dist/smart-paste/useSmartPaste.js +56 -0
  88. package/dist/smart-paste/useSmartPaste.js.map +1 -0
  89. package/dist/smart-paste.d.ts +3 -0
  90. package/dist/smart-paste.d.ts.map +1 -0
  91. package/dist/smart-paste.js +6 -0
  92. package/dist/smart-paste.js.map +1 -0
  93. package/dist/styles.css +1754 -0
  94. package/dist/text-suggest/useTextSuggest.d.ts +13 -0
  95. package/dist/text-suggest/useTextSuggest.d.ts.map +1 -0
  96. package/dist/text-suggest/useTextSuggest.js +55 -0
  97. package/dist/text-suggest/useTextSuggest.js.map +1 -0
  98. package/dist/text-suggest.css +78 -0
  99. package/dist/text-suggest.d.ts +4 -0
  100. package/dist/text-suggest.d.ts.map +1 -0
  101. package/dist/text-suggest.js +9 -0
  102. package/dist/text-suggest.js.map +1 -0
  103. package/package.json +68 -4
@@ -0,0 +1,5 @@
1
+ export { InlineAssist, InlineAssistDictation } from './inline-assist/InlineAssist.js';
2
+ export type { InlineAssistDictationProps } from './inline-assist/InlineAssist.js';
3
+ export { INLINE_ASSIST_DEFAULT_LOCALE_TEXT } from './inline-assist/model.js';
4
+ export type { InlineAssistAcceptEvent, InlineAssistAdapter, InlineAssistAnchor, InlineAssistApi, InlineAssistBeforeSendEvent, InlineAssistBuiltInAction, InlineAssistCommand, InlineAssistCommandSelectEvent, InlineAssistComposerRenderProps, InlineAssistContentOptions, InlineAssistCustomAction, InlineAssistDiscardEvent, InlineAssistInputProps, InlineAssistLocaleText, InlineAssistMessage, InlineAssistMessagesChangeEvent, InlineAssistMode, InlineAssistOpenChangeEvent, InlineAssistOpenChangeReason, InlineAssistPoint, InlineAssistProps, InlineAssistRequest, InlineAssistResponseAction, InlineAssistResponseActionEvent, InlineAssistResponsePart, InlineAssistSendEvent, } from './inline-assist/types.js';
5
+ //# sourceMappingURL=inline-assist.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-assist.d.ts","sourceRoot":"","sources":["../src/inline-assist.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACtF,YAAY,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAClF,OAAO,EAAE,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAC7E,YAAY,EACV,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,2BAA2B,EAC3B,yBAAyB,EACzB,mBAAmB,EACnB,8BAA8B,EAC9B,+BAA+B,EAC/B,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,+BAA+B,EAC/B,gBAAgB,EAChB,2BAA2B,EAC3B,4BAA4B,EAC5B,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,0BAA0B,EAC1B,+BAA+B,EAC/B,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,12 @@
1
+ 'use client';
2
+ import { expectStylesheet } from '@salmonui/core/internal/dev';
3
+ // `@salmonui/chat/inline-assist`: InlineAssist, its
4
+ // Dictation part and types. Render-safe: the assist renders nothing on the
5
+ // server (it opens on the client); browser APIs only in effects and event
6
+ // handlers. CSS: `@salmonui/chat/inline-assist/styles.css` (carries the
7
+ // Button, Menu and SpeechToText rules it composes).
8
+ export { InlineAssist, InlineAssistDictation } from './inline-assist/InlineAssist.js';
9
+ export { INLINE_ASSIST_DEFAULT_LOCALE_TEXT } from './inline-assist/model.js';
10
+ if (process.env.NODE_ENV !== 'production')
11
+ expectStylesheet('@salmonui/chat/inline-assist', 'salmon-inline-assist');
12
+ //# sourceMappingURL=inline-assist.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-assist.js","sourceRoot":"","sources":["../src/inline-assist.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,oDAAoD;AACpD,2EAA2E;AAC3E,0EAA0E;AAC1E,wEAAwE;AACxE,oDAAoD;AACpD,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAEtF,OAAO,EAAE,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAiC7E,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;IAAE,gBAAgB,CAAC,8BAA8B,EAAE,sBAAsB,CAAC,CAAC"}
@@ -0,0 +1,71 @@
1
+ /** A typed response part. */
2
+ export type StreamPart = {
3
+ readonly type: 'text';
4
+ readonly delta: string;
5
+ } | {
6
+ readonly type: 'reasoning';
7
+ readonly delta: string;
8
+ } | {
9
+ readonly type: 'tool';
10
+ readonly id: string;
11
+ readonly name: string;
12
+ readonly input: unknown;
13
+ readonly output?: unknown;
14
+ readonly status?: 'running' | 'done' | 'error';
15
+ };
16
+ /** What an adapter yields: a text delta or a typed part. */
17
+ export type StreamChunk = string | StreamPart;
18
+ /** What an adapter returns: one final response or a stream. */
19
+ export type StreamResult = PromiseLike<string> | AsyncIterable<StreamChunk>;
20
+ export interface StreamSink {
21
+ /** A text delta (never empty). */
22
+ text(delta: string): void;
23
+ /** A non-text part (`reasoning`, `tool`); ignored when absent. */
24
+ part?(part: StreamPart): void;
25
+ }
26
+ export type StreamOutcome = {
27
+ readonly status: 'done';
28
+ readonly text: string;
29
+ } | {
30
+ readonly status: 'aborted';
31
+ readonly text: string;
32
+ } | {
33
+ readonly status: 'error';
34
+ readonly error: unknown;
35
+ readonly text: string;
36
+ };
37
+ export declare const isPromiseLike: <T>(value: unknown) => value is PromiseLike<T>;
38
+ export declare const isAsyncIterable: (value: unknown) => value is AsyncIterable<unknown>;
39
+ /**
40
+ * Runs `start()` (the adapter call) and feeds its result into `sink` until it
41
+ * ends or `signal` aborts. Returns the accumulated text with the outcome.
42
+ * Never throws.
43
+ */
44
+ export declare function runStream(start: () => unknown, signal: AbortSignal, sink: StreamSink): Promise<StreamOutcome>;
45
+ /** Schedules `callback` once; returns a cancel function. */
46
+ export type FrameScheduler = (callback: () => void) => () => void;
47
+ /** `requestAnimationFrame` when present, else a 16 ms timer (Node, tests). */
48
+ export declare const frameScheduler: FrameScheduler;
49
+ export interface StreamSnapshot {
50
+ /** Text published by the last flush. */
51
+ readonly text: string;
52
+ /** A stream is open (between `start` and `end`). */
53
+ readonly streaming: boolean;
54
+ }
55
+ /**
56
+ * Text buffer of one streamed response: `push` appends to a pending list,
57
+ * and one flush per frame publishes the joined text (one snapshot, one
58
+ * listener round). `end` publishes synchronously.
59
+ */
60
+ export interface StreamBuffer {
61
+ start(): void;
62
+ push(delta: string): void;
63
+ /** Publishes the pending text, closes the stream and returns the full text. */
64
+ end(): string;
65
+ getSnapshot(): StreamSnapshot;
66
+ subscribe(listener: () => void): () => void;
67
+ /** Cancels a scheduled flush (unmount). */
68
+ dispose(): void;
69
+ }
70
+ export declare function createStreamBuffer(schedule?: FrameScheduler): StreamBuffer;
71
+ //# sourceMappingURL=stream-run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-run.d.ts","sourceRoot":"","sources":["../../src/internal/stream-run.ts"],"names":[],"mappings":"AAYA,6BAA6B;AAC7B,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,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GAIG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAsDnH;AAED,4DAA4D;AAC5D,MAAM,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;AAElE,8EAA8E;AAC9E,eAAO,MAAM,cAAc,EAAE,cAU5B,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,+EAA+E;IAC/E,GAAG,IAAI,MAAM,CAAC;IACd,WAAW,IAAI,cAAc,CAAC;IAC9B,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,2CAA2C;IAC3C,OAAO,IAAI,IAAI,CAAC;CACjB;AAID,wBAAgB,kBAAkB,CAAC,QAAQ,GAAE,cAA+B,GAAG,YAAY,CAgD1F"}
@@ -0,0 +1,161 @@
1
+ // Generic adapter stream runner and frame-batched text buffer. Shared by the AI
2
+ // families (InlineAssist today; the Conversation runner can adopt it). No
3
+ // React, no DOM globals: the frame scheduler reads `requestAnimationFrame`
4
+ // from `globalThis` only when a flush is scheduled.
5
+ //
6
+ // - A `PromiseLike` result is one final response; an `AsyncIterable`
7
+ // streams. There is no streaming flag.
8
+ // - A plain string chunk is a text delta (`{ type: 'text', delta }`).
9
+ // - Aborting the signal resolves the run at once (it does not wait for the
10
+ // adapter's next chunk); a chunk or a value that arrives later is dropped.
11
+ // - The runner never throws: errors become `{ status: 'error' }`.
12
+ export const isPromiseLike = (value) => value != null && typeof value.then === 'function';
13
+ export const isAsyncIterable = (value) => value != null && typeof value[Symbol.asyncIterator] === 'function';
14
+ const ABORTED = Symbol('aborted');
15
+ const noop = () => undefined;
16
+ /** Resolves with `ABORTED` when the signal aborts (immediately when it already has). */
17
+ function whenAborted(signal) {
18
+ return new Promise((resolve) => {
19
+ if (signal.aborted)
20
+ resolve(ABORTED);
21
+ else
22
+ signal.addEventListener('abort', () => resolve(ABORTED), { once: true });
23
+ });
24
+ }
25
+ /**
26
+ * Runs `start()` (the adapter call) and feeds its result into `sink` until it
27
+ * ends or `signal` aborts. Returns the accumulated text with the outcome.
28
+ * Never throws.
29
+ */
30
+ export async function runStream(start, signal, sink) {
31
+ let text = '';
32
+ const push = (chunk) => {
33
+ if (signal.aborted)
34
+ return;
35
+ if (typeof chunk === 'string') {
36
+ if (chunk === '')
37
+ return;
38
+ text += chunk;
39
+ sink.text(chunk);
40
+ return;
41
+ }
42
+ if (chunk == null || typeof chunk !== 'object')
43
+ return;
44
+ const part = chunk;
45
+ if (part.type === 'text') {
46
+ if (typeof part.delta !== 'string' || part.delta === '')
47
+ return;
48
+ text += part.delta;
49
+ sink.text(part.delta);
50
+ }
51
+ else
52
+ sink.part?.(part);
53
+ };
54
+ const aborted = whenAborted(signal);
55
+ try {
56
+ const result = start();
57
+ if (isPromiseLike(result)) {
58
+ const pending = Promise.resolve(result);
59
+ pending.then(noop, noop);
60
+ const value = await Promise.race([pending, aborted]);
61
+ if (value === ABORTED || signal.aborted)
62
+ return { status: 'aborted', text };
63
+ push(value);
64
+ return { status: 'done', text };
65
+ }
66
+ if (isAsyncIterable(result)) {
67
+ const iterator = result[Symbol.asyncIterator]();
68
+ for (;;) {
69
+ const next = iterator.next();
70
+ // A step that settles after an abort is dropped, never unhandled.
71
+ Promise.resolve(next).then(noop, noop);
72
+ const step = await Promise.race([next, aborted]);
73
+ if (step === ABORTED || signal.aborted) {
74
+ // Let the adapter clean up (its `finally` blocks); its result is ignored.
75
+ try {
76
+ Promise.resolve(iterator.return?.()).then(noop, noop);
77
+ }
78
+ catch {
79
+ // A throwing `return` changes nothing for the caller.
80
+ }
81
+ return { status: 'aborted', text };
82
+ }
83
+ if (step.done)
84
+ return { status: 'done', text };
85
+ push(step.value);
86
+ }
87
+ }
88
+ return { status: 'done', text };
89
+ }
90
+ catch (error) {
91
+ if (signal.aborted)
92
+ return { status: 'aborted', text };
93
+ return { status: 'error', error, text };
94
+ }
95
+ }
96
+ /** `requestAnimationFrame` when present, else a 16 ms timer (Node, tests). */
97
+ export const frameScheduler = (callback) => {
98
+ const g = globalThis;
99
+ const raf = g.requestAnimationFrame;
100
+ const caf = g.cancelAnimationFrame;
101
+ if (raf && caf) {
102
+ const handle = raf(callback);
103
+ return () => caf(handle);
104
+ }
105
+ const handle = setTimeout(callback, 16);
106
+ return () => clearTimeout(handle);
107
+ };
108
+ const IDLE = Object.freeze({ text: '', streaming: false });
109
+ export function createStreamBuffer(schedule = frameScheduler) {
110
+ let snapshot = IDLE;
111
+ let pending = [];
112
+ let cancel = null;
113
+ const listeners = new Set();
114
+ const emit = () => {
115
+ for (const l of listeners)
116
+ l();
117
+ };
118
+ const flush = () => {
119
+ cancel = null;
120
+ if (pending.length === 0)
121
+ return;
122
+ snapshot = { text: snapshot.text + pending.join(''), streaming: snapshot.streaming };
123
+ pending = [];
124
+ emit();
125
+ };
126
+ const stopFlush = () => {
127
+ cancel?.();
128
+ cancel = null;
129
+ };
130
+ return {
131
+ start() {
132
+ stopFlush();
133
+ pending = [];
134
+ snapshot = { text: '', streaming: true };
135
+ emit();
136
+ },
137
+ push(delta) {
138
+ if (!snapshot.streaming || delta === '')
139
+ return;
140
+ pending.push(delta);
141
+ cancel ??= schedule(flush);
142
+ },
143
+ end() {
144
+ stopFlush();
145
+ const text = snapshot.text + pending.join('');
146
+ pending = [];
147
+ if (snapshot.streaming || text !== snapshot.text) {
148
+ snapshot = { text, streaming: false };
149
+ emit();
150
+ }
151
+ return text;
152
+ },
153
+ getSnapshot: () => snapshot,
154
+ subscribe(listener) {
155
+ listeners.add(listener);
156
+ return () => void listeners.delete(listener);
157
+ },
158
+ dispose: stopFlush,
159
+ };
160
+ }
161
+ //# sourceMappingURL=stream-run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-run.js","sourceRoot":"","sources":["../../src/internal/stream-run.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,0EAA0E;AAC1E,2EAA2E;AAC3E,oDAAoD;AACpD,EAAE;AACF,qEAAqE;AACrE,yCAAyC;AACzC,sEAAsE;AACtE,2EAA2E;AAC3E,6EAA6E;AAC7E,kEAAkE;AA0BlE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAI,KAAc,EAA2B,EAAE,CAAC,KAAK,IAAI,IAAI,IAAI,OAAQ,KAA4B,CAAC,IAAI,KAAK,UAAU,CAAC;AACvJ,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAc,EAAmC,EAAE,CAAC,KAAK,IAAI,IAAI,IAAI,OAAQ,KAA8C,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,UAAU,CAAC;AAEjM,MAAM,OAAO,GAAkB,MAAM,CAAC,SAAS,CAAC,CAAC;AACjD,MAAM,IAAI,GAAG,GAAS,EAAE,CAAC,SAAS,CAAC;AAEnC,wFAAwF;AACxF,SAAS,WAAW,CAAC,MAAmB;IACtC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,CAAC,OAAO,CAAC,CAAC;;YAChC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAChF,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAoB,EAAE,MAAmB,EAAE,IAAgB;I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,KAAK,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,EAAE,SAAS;KACnB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,90 @@
1
+ /** What the application's `suggest` function receives. */
2
+ export interface SuggestContext {
3
+ readonly value: string;
4
+ readonly textBeforeCaret: string;
5
+ readonly textAfterCaret: string;
6
+ }
7
+ export type SuggestFunction = (context: SuggestContext, init: {
8
+ readonly signal: AbortSignal;
9
+ }) => Promise<string | null>;
10
+ /** `'auto'`: inline ghost text on fine pointers, a popover on coarse pointers, chosen by CSS. */
11
+ export type SuggestionDisplay = 'inline' | 'popover' | 'auto';
12
+ /** Cancellable event fired before a suggestion shows. */
13
+ export interface BeforeSuggestionShowEvent {
14
+ readonly text: string;
15
+ readonly defaultPrevented: boolean;
16
+ preventDefault(): void;
17
+ }
18
+ export interface SuggestionEvent {
19
+ readonly text: string;
20
+ }
21
+ export interface SuggestLocaleText {
22
+ /** Hint linked through `aria-describedby` while a suggestion is visible. Default "Tab to accept". */
23
+ readonly acceptHint?: string | undefined;
24
+ }
25
+ export interface SuggestOptions {
26
+ readonly suggest: SuggestFunction;
27
+ readonly suggestionDisplay?: SuggestionDisplay | undefined;
28
+ /** Idle time after the last keystroke before a request, in ms. Default 300. */
29
+ readonly suggestDelay?: number | undefined;
30
+ readonly onBeforeSuggestionShow?: ((event: BeforeSuggestionShowEvent) => void) | undefined;
31
+ readonly onSuggestionShow?: ((event: SuggestionEvent) => void) | undefined;
32
+ readonly onSuggestionAccept?: ((event: SuggestionEvent) => void) | undefined;
33
+ readonly localeText?: SuggestLocaleText | undefined;
34
+ /**
35
+ * Element that receives the overlay, hint and live region; it should be the
36
+ * textarea's positioned wrapper (`position: relative`). Default: the
37
+ * textarea's parent element.
38
+ */
39
+ readonly container?: HTMLElement | undefined;
40
+ }
41
+ export interface SuggestController {
42
+ update(options: SuggestOptions): void;
43
+ dispose(): void;
44
+ }
45
+ export declare const DEFAULT_SUGGEST_DELAY = 300;
46
+ export declare const DEFAULT_ACCEPT_HINT = "Tab to accept";
47
+ /** Letters, digits (any script) and `_`. */
48
+ export declare function isWordChar(ch: string | undefined): boolean;
49
+ /**
50
+ * Whether a request may start: a collapsed selection, no IME
51
+ * composition, some non-blank text before the caret, and the caret at a word
52
+ * boundary, which here means the character after the caret is not a word
53
+ * character (end of text, whitespace or punctuation). The text before the
54
+ * caret may end in a word (completing it) or in whitespace (next word).
55
+ */
56
+ export declare function isSuggestPosition(value: string, selectionStart: number, selectionEnd: number, composing: boolean): boolean;
57
+ export declare function suggestContext(value: string, caret: number): SuggestContext;
58
+ /**
59
+ * Text inserted at `anchor` between two snapshots when the edit was a plain
60
+ * insertion at the caret, otherwise null (deletions, edits elsewhere).
61
+ */
62
+ export declare function typedSince(prevValue: string, anchor: number, value: string, caret: number): string | null;
63
+ /** Remainder of `suggestion` after the user typed its first characters, or null when it no longer matches or is used up. */
64
+ export declare function keepRemainder(suggestion: string, typed: string): string | null;
65
+ export declare function createBeforeShowEvent(text: string): BeforeSuggestionShowEvent;
66
+ /** Runs `onBeforeSuggestionShow`; false when the handler called `preventDefault()`. */
67
+ export declare function allowSuggestion(handler: SuggestOptions['onBeforeSuggestionShow'], text: string): boolean;
68
+ export interface SchedulerTimers {
69
+ setTimeout(callback: () => void, ms: number): unknown;
70
+ clearTimeout(handle: unknown): void;
71
+ }
72
+ export interface SuggestScheduler {
73
+ /** Restarts the idle timer; aborts the request in flight and drops its result. */
74
+ schedule(context: SuggestContext): void;
75
+ /** Aborts the timer and any request in flight. */
76
+ cancel(): void;
77
+ }
78
+ /**
79
+ * Debounced, abortable request runner. Each `schedule` or `cancel`
80
+ * aborts the previous AbortController and bumps a token, so a late response
81
+ * of an earlier request is never delivered. Rejections are swallowed: a
82
+ * failed suggestion shows nothing.
83
+ */
84
+ export declare function createSuggestScheduler(getSuggest: () => SuggestFunction, getDelay: () => number, onResult: (text: string, context: SuggestContext) => void, timers?: SchedulerTimers): SuggestScheduler;
85
+ /**
86
+ * Attaches suggestions to a native textarea. Call from an effect after
87
+ * hydration; `dispose()` in the effect cleanup.
88
+ */
89
+ export declare function attachSuggest(textarea: HTMLTextAreaElement, options: SuggestOptions): SuggestController;
90
+ //# sourceMappingURL=suggest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggest.d.ts","sourceRoot":"","sources":["../../src/internal/suggest.ts"],"names":[],"mappings":"AAOA,0DAA0D;AAC1D,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAAE,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AAE1H,iGAAiG;AACjG,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAE9D,yDAAyD;AACzD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,cAAc,IAAI,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,qGAAqG;IACrG,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC3D,+EAA+E;IAC/E,QAAQ,CAAC,YAAY,CAAC,EAAE,M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