@stacksjs/components 0.2.863 → 0.2.864

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.
@@ -10,6 +10,9 @@ export declare const autoComplete: unknown;
10
10
  export declare const inlineDiagnostics: unknown;
11
11
  export declare const insertSpaces: unknown;
12
12
  export declare const autofocus: ReturnType<typeof $bool>;
13
+ export declare const hover: unknown;
14
+ export declare const signatureHelp: unknown;
15
+ export declare const hoverDelay: unknown;
13
16
  export declare const tabSize: unknown;
14
17
  export declare const placeholder: unknown;
15
18
  export declare const label: unknown;
@@ -33,6 +36,8 @@ export declare const theme: unknown;
33
36
  export declare const inputId: unknown;
34
37
  export declare const popupId: string;
35
38
  export declare const statusId: string;
39
+ export declare const hoverId: string;
40
+ export declare const signatureId: string;
36
41
  export declare const editorClasses: unknown;
37
42
  /*
38
43
  * Arrays that arrive as plain props. A bound one (`:completions="names()"`)
@@ -42,5 +47,5 @@ export declare const completions: unknown;
42
47
  export declare const widgets: unknown;
43
48
  export declare const diagnostics: unknown;
44
49
  export declare const ghostText: boolean;
45
- declare type __DtsxStxComponentType = DefineComponent<{ value?: string, language?: string, readonly?: unknown, disabled?: unknown, lineNumbers?: unknown, highlight?: unknown, autoComplete?: unknown, inlineDiagnostics?: unknown, insertSpaces?: unknown, autofocus?: unknown, tabSize?: unknown, placeholder?: string, label?: string, name?: string, className?: string, height?: string, theme?: unknown, id?: string, completions?: unknown, widgets?: unknown, diagnostics?: unknown, ghostText?: unknown }> & { readonly __stxEmits?: ["input", "change", "selection", "run", "run-selection", "complete", "completion-accept", "ghost", "focus", "blur"] }
50
+ declare type __DtsxStxComponentType = DefineComponent<{ value?: string, language?: string, readonly?: unknown, disabled?: unknown, lineNumbers?: unknown, highlight?: unknown, autoComplete?: unknown, inlineDiagnostics?: unknown, insertSpaces?: unknown, autofocus?: unknown, hover?: unknown, signatureHelp?: unknown, hoverDelay?: unknown, tabSize?: unknown, placeholder?: string, label?: string, name?: string, className?: string, height?: string, theme?: unknown, id?: string, completions?: unknown, widgets?: unknown, diagnostics?: unknown, ghostText?: unknown }> & { readonly __stxEmits?: ["input", "change", "selection", "run", "run-selection", "complete", "completion-accept", "hover", "signature", "ghost", "focus", "blur"] }
46
51
  export default __dtsx_component__;
@@ -1,6 +1,6 @@
1
1
  import { EditorCore } from './core/index';
2
2
  import { EditorView } from './view';
3
- import type { CompletionItem, Keymap, Transaction } from './core/index';
3
+ import type { CompletionItem, Keymap, Position, SignatureHelp, Transaction } from './core/index';
4
4
  import type { EditorDiagnostic, EditorWidget } from './view';
5
5
  export declare interface CodeEditorConfig {
6
6
  value?: string
@@ -14,6 +14,9 @@ export declare interface CodeEditorConfig {
14
14
  completions?: readonly CompletionItem[]
15
15
  keymap?: Keymap
16
16
  inlineDiagnostics?: boolean
17
+ hover?: boolean
18
+ hoverDelay?: number
19
+ signatureHelp?: boolean
17
20
  }
18
21
  export declare interface SelectionDetail {
19
22
  anchor: number
@@ -46,6 +49,23 @@ export declare interface CompletionRequest {
46
49
  explicit: boolean
47
50
  trigger: string
48
51
  }
52
+ export declare interface HoverRequest {
53
+ line: number
54
+ column: number
55
+ from: number
56
+ to: number
57
+ word: string
58
+ explicit: boolean
59
+ }
60
+ export declare interface SignatureRequest {
61
+ line: number
62
+ column: number
63
+ offset: number
64
+ start: number
65
+ active: number
66
+ trigger: string
67
+ explicit: boolean
68
+ }
49
69
  export declare interface PopupItem {
50
70
  id: string
51
71
  index: number
@@ -61,6 +81,8 @@ export declare interface PopupState {
61
81
  left: number
62
82
  top: number
63
83
  placement: 'below' | 'above'
84
+ detail: string
85
+ documentation: string
64
86
  }
65
87
  export declare interface CodeEditorHooks {
66
88
  onChange?: (value: string, transaction: Transaction) => void
@@ -70,6 +92,8 @@ export declare interface CodeEditorHooks {
70
92
  onCompleteRequest?: (request: CompletionRequest) => void
71
93
  onCompletionAccept?: (item: CompletionItem) => void
72
94
  onPopup?: (state: PopupState) => void
95
+ onHoverRequest?: (request: HoverRequest) => void
96
+ onSignatureRequest?: (request: SignatureRequest) => void
73
97
  onGhost?: (outcome: 'accept' | 'dismiss', text: string) => void
74
98
  onFocus?: () => void
75
99
  onBlur?: () => void
@@ -99,5 +123,11 @@ export declare class CodeEditorController {
99
123
  closeCompletions(): void;
100
124
  acceptCompletion(index?: number): boolean;
101
125
  selectCompletion(index: number): void;
126
+ setHover(enabled: boolean): void;
127
+ showHover(content: string | null | undefined, position?: Position): void;
128
+ closeHover(): void;
129
+ setSignatureHelp(enabled: boolean): void;
130
+ showSignature(help: SignatureHelp | null | undefined): void;
131
+ closeSignature(): void;
102
132
  destroy(): void;
103
133
  }
@@ -16,6 +16,7 @@ export declare interface CompletionItem {
16
16
  label: string
17
17
  insert?: string
18
18
  detail?: string
19
+ documentation?: string
19
20
  kind?: string
20
21
  filterText?: string
21
22
  boost?: number
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The word at a column, or null when the column is not on one.
3
+ *
4
+ * A column is on a word when the character at it is part of one. The position
5
+ * just past a word's last character counts too when `inclusiveEnd` is set,
6
+ * which is where a caret rests after typing the word.
7
+ */
8
+ export declare function wordAt(text: string, column: number, inclusiveEnd?: boolean): WordRange | null;
9
+ /**
10
+ * Hover content as the pieces it is drawn in.
11
+ *
12
+ * A language server answers in Markdown, and the part worth keeping exactly is
13
+ * the fenced block: that is the signature. Each fence becomes a code segment,
14
+ * and what lies between fences becomes text, left as written. Nothing here
15
+ * interprets Markdown beyond the fence, on purpose: the text is shown as text.
16
+ */
17
+ export declare function parseHoverContent(content: string): HoverSegment[];
18
+ /** Hover content as one line of plain text, for a screen reader. */
19
+ export declare function hoverPlainText(content: string): string;
20
+ /**
21
+ * The call the end of `text` is inside, or null when it is inside none.
22
+ *
23
+ * Reads forward, keeping a stack of open brackets and stepping over strings
24
+ * and comments, so a parenthesis or a comma in a string does not count. The
25
+ * call is the nearest unclosed parenthesis; commas directly inside it, and not
26
+ * inside a nested bracket, say which argument.
27
+ *
28
+ * It is an estimate from text alone. A language server knows better, and its
29
+ * answer is what gets shown; this decides when to ask, and keeps the active
30
+ * argument moving between answers.
31
+ */
32
+ export declare function callContext(text: string): CallContext | null;
33
+ /**
34
+ * A signature cut around its active parameter.
35
+ *
36
+ * Parameters are found in the label in order, each search starting where the
37
+ * last one ended, so two parameters with the same text are told apart. A
38
+ * parameter given as a pair of offsets is taken as is.
39
+ */
40
+ export declare function signatureParts(help: SignatureHelp): SignatureParts;
41
+ export declare interface WordRange {
42
+ from: number
43
+ to: number
44
+ word: string
45
+ }
46
+ export declare interface HoverSegment {
47
+ kind: 'code' | 'text'
48
+ text: string
49
+ language: string
50
+ }
51
+ export declare interface CallContext {
52
+ open: number
53
+ active: number
54
+ }
55
+ export declare interface SignatureHelp {
56
+ label: string
57
+ parameters?: readonly SignatureParameter[]
58
+ active?: number
59
+ documentation?: string
60
+ }
61
+ export declare interface SignatureParts {
62
+ before: string
63
+ active: string
64
+ after: string
65
+ parameterDocumentation: string
66
+ }
67
+ /** One parameter of a signature: its text in the label, or where it sits in it. */
68
+ export type SignatureParameter = string | [number, number] | { label: string | [number, number], documentation?: string }
@@ -7,6 +7,7 @@ export * from './commands';
7
7
  export * from './completion';
8
8
  export * from './editor';
9
9
  export * from './highlight';
10
+ export * from './hints';
10
11
  export * from './history';
11
12
  export * from './keymap';
12
13
  export * from './selection';
@@ -1,6 +1,6 @@
1
- export type { CodeEditorConfig, CodeEditorHooks, CompletionRequest, PopupItem, PopupState, RunDetail, RunSelectionDetail, SelectionDetail } from './controller';
2
- export type { CompletionItem, Keymap, Position } from './core/index';
3
- export type { CaretAnchor, DiagnosticSeverity, EditorDiagnostic, EditorViewOptions, EditorWidget } from './view';
1
+ export type { CodeEditorConfig, CodeEditorHooks, CompletionRequest, HoverRequest, PopupItem, PopupState, RunDetail, RunSelectionDetail, SelectionDetail, SignatureRequest } from './controller';
2
+ export type { CompletionItem, Keymap, Position, SignatureHelp, SignatureParameter } from './core/index';
3
+ export type { CaretAnchor, DiagnosticSeverity, EditorDiagnostic, EditorViewOptions, EditorWidget, HintBlock, SignatureDisplay } from './view';
4
4
  export declare interface CodeEditorProps {
5
5
  value?: string
6
6
  language?: string
@@ -16,6 +16,9 @@ export declare interface CodeEditorProps {
16
16
  diagnostics?: import('./view').EditorDiagnostic[]
17
17
  inlineDiagnostics?: boolean
18
18
  ghostText?: string
19
+ hover?: boolean
20
+ hoverDelay?: number
21
+ signatureHelp?: boolean
19
22
  keymap?: import('./core/index').Keymap
20
23
  theme?: 'light' | 'dark'
21
24
  height?: string
@@ -1,6 +1,10 @@
1
- import type { EditorCore, HighlightedLine, LineTokenizer, Position, ResolvedKeymap, Transaction } from './core/index';
1
+ import type { EditorCore, HighlightedLine, HighlightToken, LineTokenizer, Position, ResolvedKeymap, Transaction } from './core/index';
2
+ /** Coloured runs as HTML: a span per run, plain text left unwrapped. */
3
+ export declare function renderTokensHtml(tokens: readonly HighlightToken[]): string;
2
4
  /** One line as HTML: a span per coloured run, plain text left unwrapped. */
3
5
  export declare function renderLineHtml(line: HighlightedLine | null, text: string): string;
6
+ /** A piece of code as HTML, coloured by a line tokenizer from its first line. */
7
+ export declare function renderCodeHtml<State>(tokenizer: LineTokenizer<State>, code: string): string;
4
8
  /** Something shown beside or after a line: a result, a note, an error. */
5
9
  export declare interface EditorWidget {
6
10
  line: number
@@ -34,8 +38,25 @@ export declare interface EditorViewOptions {
34
38
  onFocus?: () => void
35
39
  onBlur?: () => void
36
40
  onGhost?: (outcome: 'accept' | 'dismiss', text: string) => void
41
+ onPointerRest?: (offset: number | null) => void
42
+ onPointerLeave?: () => void
43
+ onScroll?: () => void
44
+ hoverDelay?: number
37
45
  inlineDiagnostics?: boolean
38
46
  }
47
+ /** One piece of a hint: a block of code, already coloured, or a paragraph. */
48
+ export declare interface HintBlock {
49
+ kind: 'code' | 'text'
50
+ html?: string
51
+ text: string
52
+ }
53
+ /** A signature, cut around the parameter being written. */
54
+ export declare interface SignatureDisplay {
55
+ before: string
56
+ active: string
57
+ after: string
58
+ documentation?: string
59
+ }
39
60
  export type DiagnosticSeverity = 'error' | 'warning' | 'info' | 'hint';
40
61
  export declare class EditorView {
41
62
  readonly core: EditorCore;
@@ -46,6 +67,13 @@ export declare class EditorView {
46
67
  setTokenizer<State>(tokenizer: LineTokenizer<State> | null): void;
47
68
  layout(): void;
48
69
  render(): void;
70
+ offsetAtPoint(clientX: number, clientY: number): number | null;
71
+ showHover(blocks: readonly HintBlock[], offset: number): void;
72
+ hideHover(): void;
73
+ get hoverOpen(): boolean;
74
+ showSignature(display: SignatureDisplay, offset: number, side?: 'above' | 'below'): void;
75
+ hideSignature(): void;
76
+ get signatureOpen(): boolean;
49
77
  caretAnchor(offset?: number): CaretAnchor;
50
78
  revealCaret(): void;
51
79
  focus(): void;
@@ -55,5 +83,6 @@ export declare class EditorView {
55
83
  setGhostText(text: string | null, outcome?: 'accept' | 'dismiss' | null): void;
56
84
  get ghostText(): string;
57
85
  acceptGhost(): boolean;
86
+ announce(message: string): void;
58
87
  destroy(): void;
59
88
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/components",
3
3
  "type": "module",
4
- "version": "0.2.863",
4
+ "version": "0.2.864",
5
5
  "description": "A modern component library built with STX, featuring headwind utility classes and TypeScript syntax highlighting.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -124,8 +124,8 @@
124
124
  "dependencies": {
125
125
  "@iconify-json/f7": "^1.2.2",
126
126
  "@stacksjs/ts-css": "^0.3.11",
127
- "@stacksjs/stx": "0.2.863",
128
- "bun-plugin-stx": "0.2.863",
127
+ "@stacksjs/stx": "0.2.864",
128
+ "bun-plugin-stx": "0.2.864",
129
129
  "ts-syntax-highlighter": "^0.2.20",
130
130
  "ts-video-player": "^0.1.11"
131
131
  },
@@ -186,6 +186,10 @@ const labelProp = useReactiveProp('label', {{ label }}, { parse: value => value
186
186
  const textProp = useReactiveProp('text', '', { parse: value => value == null ? '' : String(value) })
187
187
  const labelText = derived(() => labelProp() || textProp())
188
188
  const isLoading = useReactiveProp('loading', {{ loading }})
189
+ // The accessible name is live too. Read once on the server, a bound one
190
+ // (:ariaLabel="action.label" in a row of icon buttons) stayed on the boxless
191
+ // scope wrapper and never reached the button, which then had no name at all.
192
+ const ariaLabelProp = useReactiveProp('ariaLabel', {{ ariaLabel }}, { parse: value => value == null ? '' : String(value) })
189
193
  const disabledProp = useReactiveProp('disabled', {{ disabled }})
190
194
 
191
195
  // Loading implies disabled, the same combination the server computes for the
@@ -215,6 +219,7 @@ function onClick(event) {
215
219
  aria-busy="{{ loading ? 'true' : 'false' }}"
216
220
  :aria-busy="isLoading() ? 'true' : 'false'"
217
221
  @if(ariaLabel)aria-label="{{ ariaLabel }}"@endif
222
+ :aria-label="String(ariaLabelProp() ?? '') || null"
218
223
  @click="onClick($event)"
219
224
  >
220
225
  <div data-native="ActivityIndicator" :show="isLoading()" class="{{ nativeTintClass }}" :color="platformControls ? null : legacyNativeTint" role="status"></div>
@@ -236,6 +241,7 @@ function onClick(event) {
236
241
  aria-busy="{{ loading ? 'true' : 'false' }}"
237
242
  :aria-busy="isLoading() ? 'true' : 'false'"
238
243
  @if(ariaLabel)aria-label="{{ ariaLabel }}"@endif
244
+ :aria-label="String(ariaLabelProp() ?? '') || null"
239
245
  @click="onClick($event)"
240
246
  >
241
247
  {{-- The spinner is always in the DOM so `loading` can turn it on after render;
@@ -9,6 +9,9 @@ export const autoComplete = $bool($props.autoComplete, true)
9
9
  export const inlineDiagnostics = $bool($props.inlineDiagnostics, true)
10
10
  export const insertSpaces = $bool($props.insertSpaces, true)
11
11
  export const autofocus = $bool($props.autofocus)
12
+ export const hover = $bool($props.hover, true)
13
+ export const signatureHelp = $bool($props.signatureHelp, true)
14
+ export const hoverDelay = $num($props.hoverDelay) || 300
12
15
  export const tabSize = $num($props.tabSize) || 2
13
16
  export const placeholder = $props.placeholder || ''
14
17
  export const label = $props.label || 'Code editor'
@@ -32,6 +35,8 @@ export const theme = ['light', 'dark'].includes($props.theme) ? $props.theme : '
32
35
  export const inputId = $props.id || `code-editor-${$uid}`
33
36
  export const popupId = `${inputId}-completions`
34
37
  export const statusId = `${inputId}-status`
38
+ export const hoverId = `${inputId}-hover`
39
+ export const signatureId = `${inputId}-signature`
35
40
  export const editorClasses = `relative flex flex-col overflow-hidden rounded-panel border border-line ${className}`.trim()
36
41
  /*
37
42
  * Arrays that arrive as plain props. A bound one (`:completions="names()"`)
@@ -54,7 +59,7 @@ export const ghostText = typeof $props.ghostText === 'string' ? $props.ghostText
54
59
  */
55
60
  import { CodeEditorController } from './controller'
56
61
 
57
- const emit = defineEmits(['input', 'change', 'selection', 'run', 'run-selection', 'complete', 'completion-accept', 'ghost', 'focus', 'blur'])
62
+ const emit = defineEmits(['input', 'change', 'selection', 'run', 'run-selection', 'complete', 'completion-accept', 'hover', 'signature', 'ghost', 'focus', 'blur'])
58
63
 
59
64
  function asBoolean(value) {
60
65
  if (value == null) return false
@@ -86,7 +91,9 @@ const liveKeymap = useReactiveProp('keymap', null, { parse: v => v })
86
91
 
87
92
  const locked = derived(() => asBoolean(liveReadonly()) || asBoolean(liveDisabled()))
88
93
  const isEmpty = state({{ value }} === '')
89
- const popup = state({ open: false, items: [], activeId: '', left: 0, top: 0, placement: 'below' })
94
+ const liveHover = useReactiveProp('hover', {{ hover }}, { parse: asBoolean })
95
+ const liveSignatureHelp = useReactiveProp('signatureHelp', {{ signatureHelp }}, { parse: asBoolean })
96
+ const popup = state({ open: false, items: [], activeId: '', left: 0, top: 0, placement: 'below', detail: '', documentation: '' })
90
97
  const popupStyle = derived(() => {
91
98
  const current = popup()
92
99
  const lift = current.placement === 'above' ? ' translateY(-100%)' : ''
@@ -112,6 +119,9 @@ onMount(() => {
112
119
  inlineDiagnostics: {{ inlineDiagnostics }},
113
120
  completions: asList(liveCompletions()),
114
121
  keymap: liveKeymap() || {},
122
+ hover: asBoolean(liveHover()),
123
+ hoverDelay: {{ hoverDelay }},
124
+ signatureHelp: asBoolean(liveSignatureHelp()),
115
125
  }, {
116
126
  onChange(value) {
117
127
  isEmpty.set(value === '')
@@ -124,6 +134,8 @@ onMount(() => {
124
134
  onRunSelection(detail) { emit('run-selection', detail) },
125
135
  onCompleteRequest(request) { emit('complete', request) },
126
136
  onCompletionAccept(item) { emit('completion-accept', item) },
137
+ onHoverRequest(request) { emit('hover', request) },
138
+ onSignatureRequest(request) { emit('signature', request) },
127
139
  onGhost(outcome, text) { emit('ghost', { outcome, text }) },
128
140
  onPopup(next) { popup.set(next) },
129
141
  onFocus() { emit('focus') },
@@ -146,6 +158,8 @@ onMount(() => {
146
158
  effect(() => editor.setDiagnostics(asList(liveDiagnostics())))
147
159
  effect(() => editor.setGhostText(liveGhostText() || null))
148
160
  effect(() => editor.setKeymap(liveKeymap() || {}))
161
+ effect(() => editor.setHover(asBoolean(liveHover())))
162
+ effect(() => editor.setSignatureHelp(asBoolean(liveSignatureHelp())))
149
163
 
150
164
  if ({{ autofocus }}) editor.focus()
151
165
  })
@@ -174,6 +188,10 @@ defineExpose({
174
188
  setGhostText: (text) => { if (editor) editor.setGhostText(text || null) },
175
189
  showCompletions: (items, options) => { if (editor) editor.showCompletions(asList(items), options || {}) },
176
190
  closeCompletions: () => { if (editor) editor.closeCompletions() },
191
+ showHover: (content, position) => { if (editor) editor.showHover(content, position) },
192
+ closeHover: () => { if (editor) editor.closeHover() },
193
+ showSignature: (help) => { if (editor) editor.showSignature(help) },
194
+ closeSignature: () => { if (editor) editor.closeSignature() },
177
195
  editor: () => editor,
178
196
  })
179
197
  </script>
@@ -234,29 +252,60 @@ defineExpose({
234
252
 
235
253
  {{-- The completion list. It stays in the document while closed so the
236
254
  field's aria-controls always has something to point at. --}}
237
- <ul
238
- id="{{ popupId }}"
239
- role="listbox"
240
- aria-label="Completions"
241
- class="stx-ce-popup absolute top-0 left-0 z-40 m-0 p-1 list-none overflow-y-auto rounded-control border border-line bg-panel shadow-lg"
255
+ <div
256
+ class="stx-ce-popup absolute top-0 left-0 z-40 flex flex-col overflow-hidden rounded-control border border-line bg-panel shadow-lg"
242
257
  :show="popup().open"
243
258
  :style="popupStyle()"
244
259
  >
245
- <li
246
- :for="entry in popup().items"
247
- :key="entry.id"
248
- :id="entry.id"
249
- role="option"
250
- :aria-selected="entry.selected ? 'true' : 'false'"
251
- :data-selected="entry.selected ? '' : null"
252
- :data-kind="entry.kind || null"
253
- class="stx-ce-option flex items-baseline gap-3 px-2 py-0.5 rounded-control cursor-default whitespace-nowrap"
254
- @mousedown.prevent="acceptCompletion(entry.index)"
260
+ <ul
261
+ id="{{ popupId }}"
262
+ role="listbox"
263
+ aria-label="Completions"
264
+ class="stx-ce-popup-list m-0 p-1 list-none overflow-y-auto"
255
265
  >
256
- <span class="stx-ce-option-label" x-text="entry.label"></span>
257
- <span class="stx-ce-option-detail ml-auto text-fg-soft" x-text="entry.detail"></span>
258
- </li>
259
- </ul>
266
+ <li
267
+ :for="entry in popup().items"
268
+ :key="entry.id"
269
+ :id="entry.id"
270
+ role="option"
271
+ :aria-selected="entry.selected ? 'true' : 'false'"
272
+ :data-selected="entry.selected ? '' : null"
273
+ :data-kind="entry.kind || null"
274
+ class="stx-ce-option flex items-baseline gap-3 px-2 py-0.5 rounded-control cursor-default whitespace-nowrap"
275
+ @mousedown.prevent="acceptCompletion(entry.index)"
276
+ >
277
+ <span class="stx-ce-option-label" x-text="entry.label"></span>
278
+ <span class="stx-ce-option-detail ml-auto text-fg-soft" x-text="entry.detail"></span>
279
+ </li>
280
+ </ul>
281
+ {{-- What the selected row has to say in full. The row shows one
282
+ line of it and cuts the rest; a type rarely fits. --}}
283
+ <div
284
+ class="stx-ce-popup-detail shrink-0 overflow-y-auto border-t border-line px-2 py-1"
285
+ :show="popup().detail !== '' || popup().documentation !== ''"
286
+ >
287
+ <div class="stx-ce-popup-detail-type" :show="popup().detail !== ''" x-text="popup().detail"></div>
288
+ <div class="stx-ce-popup-detail-doc text-fg-soft" :show="popup().documentation !== ''" x-text="popup().documentation"></div>
289
+ </div>
290
+ </div>
291
+
292
+ {{-- Type hints. Filled and placed by the view; neither takes focus,
293
+ so neither can trap it. What a hover says is also sent to the
294
+ status line when it was asked for from the keyboard. --}}
295
+ <div
296
+ data-ce="hover"
297
+ id="{{ hoverId }}"
298
+ role="tooltip"
299
+ class="stx-ce-hint stx-ce-hover absolute top-0 left-0 z-50 overflow-auto rounded-control border border-line bg-panel shadow-lg"
300
+ style="display: none"
301
+ ></div>
302
+ <div
303
+ data-ce="signature"
304
+ id="{{ signatureId }}"
305
+ role="tooltip"
306
+ class="stx-ce-hint stx-ce-signature absolute top-0 left-0 z-40 overflow-auto rounded-control border border-line bg-panel shadow-lg pointer-events-none"
307
+ style="display: none"
308
+ ></div>
260
309
  </div>
261
310
  </div>
262
311
  </div>
@@ -296,7 +345,7 @@ defineExpose({
296
345
  color: var(--stx-code-fg);
297
346
  }
298
347
 
299
- [data-stx-code-editor] :is(.stx-ce-rows, .stx-ce-input, .stx-ce-gutter, .stx-ce-layer, .stx-ce-measure, .stx-ce-placeholder, .stx-ce-popup) {
348
+ [data-stx-code-editor] :is(.stx-ce-rows, .stx-ce-input, .stx-ce-gutter, .stx-ce-layer, .stx-ce-measure, .stx-ce-placeholder, .stx-ce-popup, .stx-ce-hint) {
300
349
  font-family: var(--stx-code-font);
301
350
  font-size: var(--stx-code-font-size);
302
351
  line-height: var(--stx-code-line-height);
@@ -388,11 +437,50 @@ defineExpose({
388
437
  [data-stx-code-editor] :is(.stx-ce-ghost--block) { background: var(--stx-code-bg); }
389
438
 
390
439
  [data-stx-code-editor] :is(.stx-ce-popup) {
391
- max-height: 14rem;
392
440
  min-width: 12rem;
393
441
  max-width: 32rem;
394
442
  color: var(--stx-code-fg);
395
443
  }
444
+ [data-stx-code-editor] :is(.stx-ce-popup-list) { max-height: 14rem; }
445
+ [data-stx-code-editor] :is(.stx-ce-popup-detail) { max-height: 7rem; }
446
+ [data-stx-code-editor] :is(.stx-ce-popup-detail-type, .stx-ce-popup-detail-doc) {
447
+ white-space: pre-wrap;
448
+ overflow-wrap: anywhere;
449
+ }
450
+ [data-stx-code-editor] :is(.stx-ce-popup-detail-doc) { font-family: inherit; }
451
+
452
+ /* Type hints: a hover on a word, a signature above the caret. The same
453
+ surface as the completion list, so all three read as one family. */
454
+ [data-stx-code-editor] :is(.stx-ce-hint) {
455
+ box-sizing: border-box;
456
+ max-width: min(36rem, 90%);
457
+ max-height: 16rem;
458
+ padding: 4px 8px;
459
+ color: var(--stx-code-fg);
460
+ }
461
+ [data-stx-code-editor] :is(.stx-ce-hint-code, .stx-ce-signature-label) {
462
+ margin: 0;
463
+ font: inherit;
464
+ white-space: pre-wrap;
465
+ overflow-wrap: anywhere;
466
+ }
467
+ [data-stx-code-editor] :is(.stx-ce-hint-text) {
468
+ margin: 0;
469
+ color: var(--stx-code-result);
470
+ white-space: pre-wrap;
471
+ overflow-wrap: anywhere;
472
+ }
473
+ [data-stx-code-editor] :is(.stx-ce-hint) > * + * {
474
+ margin-top: 4px;
475
+ padding-top: 4px;
476
+ border-top: 1px solid color-mix(in srgb, var(--stx-code-fg) 12%, transparent);
477
+ }
478
+ [data-stx-code-editor] :is(.stx-ce-signature-active) {
479
+ font-weight: 700;
480
+ color: var(--stx-code-caret);
481
+ text-decoration: underline;
482
+ text-underline-offset: 3px;
483
+ }
396
484
  [data-stx-code-editor] :is(.stx-ce-option[data-selected]) {
397
485
  background: color-mix(in srgb, var(--stx-accent, #2563eb) 18%, transparent);
398
486
  }
@@ -56,7 +56,10 @@ mounts an editor itself.
56
56
  | `tabSize` | `2` | |
57
57
  | `insertSpaces` | `true` | Indent with spaces rather than tab characters. |
58
58
  | `autoComplete` | `true` | Offer completions while typing, not only on Ctrl+Space. |
59
- | `completions` | `[]` | Names always on offer: `{ label, insert?, detail?, kind?, filterText?, boost? }`. |
59
+ | `completions` | `[]` | Names always on offer: `{ label, insert?, detail?, documentation?, kind?, filterText?, boost? }`. The selected row's `detail` and `documentation` are shown in full under the list. |
60
+ | `hover` | `true` | Ask for a hover (`@hover`) when the pointer rests on a word. |
61
+ | `hoverDelay` | `300` | Milliseconds the pointer has to be still first. |
62
+ | `signatureHelp` | `true` | Ask for signature help (`@signature`) after `(` and `,` inside a call. |
60
63
  | `widgets` | `[]` | Shown beside lines: `{ line, column?, text, kind?, className? }`. `column` defaults to the end of the line. |
61
64
  | `diagnostics` | `[]` | `{ from: { line, column }, to: { line, column }, message, severity? }`. Drawn as a squiggle, marked in the gutter, and said after the line. |
62
65
  | `inlineDiagnostics` | `true` | Show each diagnostic's message after its line. |
@@ -78,6 +81,8 @@ Lines and columns are zero-based everywhere, as a language server counts them.
78
81
  | `@run-selection` | `{ text, from, to, line, selected }`. With Shift. The caret's line when nothing is selected. |
79
82
  | `@complete` | `{ query, from, to, line, column, textBefore, explicit, trigger }`. Answer by calling `showCompletions(items, { from })`. |
80
83
  | `@completion-accept` | The item taken. |
84
+ | `@hover` | `{ line, column, from, to, word, explicit }`. The pointer rested on a word, or Cmd/Ctrl+I was pressed (`explicit`). `line` and `column` are where it points; `from` and `to` are the word's offsets. Answer by calling `showHover(content, { line, column })`. |
85
+ | `@signature` | `{ line, column, offset, start, active, trigger, explicit }`. A `(` or a `,` was typed inside a call, or Shift+Cmd/Ctrl+Space was pressed. `start` is the offset just inside the call's parenthesis and `active` the argument index counted from the text. Answer by calling `showSignature(help)`. |
81
86
  | `@ghost` | `{ outcome: 'accept' \| 'dismiss', text }` |
82
87
  | `@focus`, `@blur` | |
83
88
 
@@ -87,7 +92,54 @@ From `componentApi(target)` (`@stacksjs/components/component-api`), where
87
92
  `target` is the component's element, its id or a selector: `getValue`, `setValue`, `getSelection`,
88
93
  `setSelection(anchor, head)`, `focus`, `undo`, `redo`, `exec(command)`,
89
94
  `setWidgets`, `setDiagnostics`, `setGhostText`, `showCompletions(items, { from })`,
90
- `closeCompletions`, and `editor()` for the controller itself.
95
+ `closeCompletions`, `showHover(content, { line, column })`, `closeHover`,
96
+ `showSignature(help)`, `closeSignature`, and `editor()` for the controller itself.
97
+
98
+ ## Type hints
99
+
100
+ The editor asks; the host answers. It knows nothing about a language server,
101
+ only when a question is worth asking and how to draw the answer.
102
+
103
+ ```html
104
+ <CodeEditor @ref="editor" @hover="onHover($event)" @signature="onSignature($event)" />
105
+ ```
106
+
107
+ ```ts
108
+ async function onHover(request) {
109
+ const hover = await language.hover(code(), request.line, request.column)
110
+ // Pass the position back. An answer for a word the pointer has since left
111
+ // is dropped, so a slow answer never lands on the wrong word.
112
+ api().showHover(hover, { line: request.line, column: request.column })
113
+ }
114
+
115
+ async function onSignature(request) {
116
+ const help = await language.signature(code(), request.line, request.column)
117
+ api().showSignature(help) // { label, parameters, active, documentation } or null
118
+ }
119
+ ```
120
+
121
+ **Hover.** `content` is Markdown or plain text, as a language server gives it. A
122
+ fenced block is drawn as code, coloured in the fence's language (the editor's
123
+ when it names none); everything else is drawn as text, as written. The hint
124
+ sits above its word, or below when there is no room. It closes on typing, on
125
+ scrolling, on Escape, and when the pointer rests somewhere else or leaves the
126
+ editor; the pointer can move onto the hint to scroll it. Empty content shows
127
+ nothing. Moving the mouse costs nothing: a position is only worked out once the
128
+ pointer has been still for `hoverDelay`.
129
+
130
+ **Signature help.** `help` is `{ label, parameters?, active?, documentation? }`.
131
+ A parameter is its text in the label (`'id: string'`), a pair of offsets into
132
+ the label, or `{ label, documentation? }`, which is the shape a language server
133
+ uses. The active one is emphasised. Leave `active` out and it is counted from
134
+ the commas typed so far; give it and it still moves on at the next comma,
135
+ before the next answer arrives. It closes when the caret leaves the call, on
136
+ Escape, or on `showSignature(null)`.
137
+
138
+ **Keyboard.** Cmd/Ctrl+I asks for the hover at the caret, and the answer is
139
+ also sent to the editor's status line, so a screen reader reads it. Neither
140
+ hint takes focus, so neither can trap it. Escape closes one thing at a time:
141
+ the completion list, then the hover, then the signature, and only then does it
142
+ free Tab.
91
143
 
92
144
  ## Keys
93
145
 
@@ -100,6 +152,8 @@ From `componentApi(target)` (`@stacksjs/components/component-api`), where
100
152
  | Cmd/Ctrl+Enter | Run. |
101
153
  | Shift+Cmd/Ctrl+Enter | Run the selection. |
102
154
  | Ctrl+Space | Completions. |
155
+ | Cmd/Ctrl+I | Describe the word at the caret (`showHover`). |
156
+ | Shift+Cmd/Ctrl+Space | Signature help for the call the caret is in (`triggerSignature`). |
103
157
  | Escape, then Tab | Leave the editor. Tab indents, so this is the way out by keyboard. |
104
158
 
105
159
  In a binding, `Mod` is Command on a Mac and Control elsewhere: