@stacksjs/components 0.2.863 → 0.2.865

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.
@@ -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
  }