@spectral_labs/ui 1.6.0 → 1.7.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.
- package/dist/components/command/__tests__/CommandInlineDirectTest.svelte +29 -0
- package/dist/components/command/__tests__/CommandInlineTest.svelte +89 -0
- package/dist/components/command/__tests__/command-inline.test.svelte.js +392 -0
- package/dist/components/command/command.svelte.d.ts +30 -0
- package/dist/components/command/command.svelte.d.ts.map +1 -1
- package/dist/components/command/command.svelte.js +85 -4
- package/dist/components/command/components/command-group.svelte +25 -15
- package/dist/components/command/components/command-group.svelte.d.ts.map +1 -1
- package/dist/components/command/components/command-input.svelte +54 -5
- package/dist/components/command/components/command-input.svelte.d.ts +1 -1
- package/dist/components/command/components/command-input.svelte.d.ts.map +1 -1
- package/dist/components/command/components/command-list.svelte +22 -3
- package/dist/components/command/components/command-list.svelte.d.ts.map +1 -1
- package/dist/components/command/components/command-root.svelte +43 -4
- package/dist/components/command/components/command-root.svelte.d.ts.map +1 -1
- package/dist/components/command/index.d.ts +1 -0
- package/dist/components/command/index.d.ts.map +1 -1
- package/dist/components/command/types.d.ts +59 -4
- package/dist/components/command/types.d.ts.map +1 -1
- package/dist/internal/drag-drop/__tests__/drag-session.test.svelte.js +256 -0
- package/dist/internal/drag-drop/drag-session.svelte.d.ts.map +1 -1
- package/dist/internal/drag-drop/drag-session.svelte.js +114 -14
- package/dist/internal/drag-drop/keyboard-dnd.svelte.d.ts +8 -0
- package/dist/internal/drag-drop/keyboard-dnd.svelte.d.ts.map +1 -1
- package/dist/internal/drag-drop/keyboard-dnd.svelte.js +14 -3
- package/dist/internal/escape-layer/escape-layer.svelte.d.ts +12 -0
- package/dist/internal/escape-layer/escape-layer.svelte.d.ts.map +1 -1
- package/dist/internal/escape-layer/escape-layer.svelte.js +20 -1
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Manages search filtering, item scoring, keyboard navigation,
|
|
5
5
|
* and selection for a command palette interface.
|
|
6
6
|
*/
|
|
7
|
-
import { getContext, setContext } from 'svelte';
|
|
7
|
+
import { getContext, setContext, untrack } from 'svelte';
|
|
8
8
|
import { useId } from '../../internal/helpers/index.js';
|
|
9
9
|
const KEY = Symbol('sp-command');
|
|
10
10
|
/**
|
|
@@ -76,7 +76,45 @@ export function createCommandState(options) {
|
|
|
76
76
|
// eslint-disable-next-line svelte/prefer-svelte-reactivity -- internal non-reactive scoring cache
|
|
77
77
|
const scores = new Map();
|
|
78
78
|
let selectedValue = $state('');
|
|
79
|
+
let listMounted = $state(false);
|
|
80
|
+
/**
|
|
81
|
+
* `items` and `scores` are deliberately PLAIN (a hot scoring cache). Anything
|
|
82
|
+
* derived from the COLLECTION therefore needs an explicit reactive beat, or
|
|
83
|
+
* removing an option would leave `aria-activedescendant` naming a node that
|
|
84
|
+
* no longer exists — silently, because no signal changed.
|
|
85
|
+
*/
|
|
86
|
+
let collectionVersion = $state(0);
|
|
87
|
+
/**
|
|
88
|
+
* `registerItem` / `unregisterItem` run from an item's `$effect`. A plain
|
|
89
|
+
* `collectionVersion += 1` there is a read-modify-WRITE of reactive state, so
|
|
90
|
+
* the effect would take a dependency on the very signal it bumps and loop
|
|
91
|
+
* forever. The read is untracked; only the write is observable.
|
|
92
|
+
*/
|
|
93
|
+
function bumpCollection() {
|
|
94
|
+
collectionVersion = untrack(() => collectionVersion) + 1;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The selection as the user actually sees it.
|
|
98
|
+
*
|
|
99
|
+
* The stored `selectedValue` survives unregistration (an option removed by
|
|
100
|
+
* the consumer, or the whole list unmounted while an inline field stays put).
|
|
101
|
+
* Reading it raw would hand out a selection that no rendered option carries —
|
|
102
|
+
* a stale highlight, a dead ARIA reference, and a first arrow press spent
|
|
103
|
+
* recovering instead of moving. Resolving against the live enabled+visible
|
|
104
|
+
* set makes all three impossible by construction, whatever order mounts and
|
|
105
|
+
* unmounts happen to interleave in during a remount.
|
|
106
|
+
*/
|
|
107
|
+
function resolveSelected() {
|
|
108
|
+
void collectionVersion;
|
|
109
|
+
const enabled = getEnabledVisibleItems();
|
|
110
|
+
if (enabled.length === 0)
|
|
111
|
+
return '';
|
|
112
|
+
if (enabled.some((item) => item.value === selectedValue))
|
|
113
|
+
return selectedValue;
|
|
114
|
+
return enabled[0].value;
|
|
115
|
+
}
|
|
79
116
|
function updateScores(search) {
|
|
117
|
+
bumpCollection();
|
|
80
118
|
scores.clear();
|
|
81
119
|
if (!options.shouldFilter || search === '') {
|
|
82
120
|
for (const item of items)
|
|
@@ -89,6 +127,7 @@ export function createCommandState(options) {
|
|
|
89
127
|
}
|
|
90
128
|
}
|
|
91
129
|
function getVisibleItems() {
|
|
130
|
+
void collectionVersion;
|
|
92
131
|
return items.filter((item) => (scores.get(item.value) ?? 0) > 0);
|
|
93
132
|
}
|
|
94
133
|
function getEnabledVisibleItems() {
|
|
@@ -106,7 +145,11 @@ export function createCommandState(options) {
|
|
|
106
145
|
selectedValue = enabled[enabled.length - 1].value;
|
|
107
146
|
return;
|
|
108
147
|
}
|
|
109
|
-
|
|
148
|
+
// Résolue, pas brute : après un remontage la valeur stockée peut ne
|
|
149
|
+
// correspondre à aucune option rendue, et la navigation repartirait alors
|
|
150
|
+
// du début au lieu de continuer depuis ce qui est mis en évidence.
|
|
151
|
+
const current = resolveSelected();
|
|
152
|
+
const currentIndex = enabled.findIndex((item) => item.value === current);
|
|
110
153
|
if (direction === 'next') {
|
|
111
154
|
if (currentIndex === -1 || currentIndex >= enabled.length - 1) {
|
|
112
155
|
selectedValue = options.loop ? enabled[0].value : enabled[enabled.length - 1].value;
|
|
@@ -131,10 +174,39 @@ export function createCommandState(options) {
|
|
|
131
174
|
return options.search;
|
|
132
175
|
},
|
|
133
176
|
get selectedValue() {
|
|
134
|
-
return
|
|
177
|
+
return resolveSelected();
|
|
135
178
|
},
|
|
136
179
|
inputId,
|
|
137
180
|
listId,
|
|
181
|
+
get mode() {
|
|
182
|
+
return options.mode;
|
|
183
|
+
},
|
|
184
|
+
get open() {
|
|
185
|
+
return options.open;
|
|
186
|
+
},
|
|
187
|
+
get listMounted() {
|
|
188
|
+
return listMounted;
|
|
189
|
+
},
|
|
190
|
+
setListMounted(mounted) {
|
|
191
|
+
listMounted = mounted;
|
|
192
|
+
},
|
|
193
|
+
getActiveOptionId() {
|
|
194
|
+
void collectionVersion;
|
|
195
|
+
// No list rendered ⇒ no option rendered ⇒ nothing to point at.
|
|
196
|
+
if (!listMounted)
|
|
197
|
+
return null;
|
|
198
|
+
const active = resolveSelected();
|
|
199
|
+
if (active === '')
|
|
200
|
+
return null;
|
|
201
|
+
const item = getEnabledVisibleItems().find((candidate) => candidate.value === active);
|
|
202
|
+
// The DOM id of the rendered option, never its business `value`.
|
|
203
|
+
return item ? item.id : null;
|
|
204
|
+
},
|
|
205
|
+
requestOpen() {
|
|
206
|
+
if (options.open)
|
|
207
|
+
return;
|
|
208
|
+
options.onRequestOpen?.();
|
|
209
|
+
},
|
|
138
210
|
get shouldFilter() {
|
|
139
211
|
return options.shouldFilter;
|
|
140
212
|
},
|
|
@@ -151,11 +223,19 @@ export function createCommandState(options) {
|
|
|
151
223
|
}
|
|
152
224
|
},
|
|
153
225
|
getScore(value) {
|
|
226
|
+
// `scores` is a plain Map, so a reader that did not touch the collection
|
|
227
|
+
// beat would never see a score written AFTER it first ran. That is the
|
|
228
|
+
// case on every mount: an item's `isVisible` derived evaluates during
|
|
229
|
+
// render, while `registerItem` runs in its `$effect`, i.e. later. With a
|
|
230
|
+
// retained query the item scored 0 at render, matched at registration,
|
|
231
|
+
// and stayed hidden forever — no signal had changed.
|
|
232
|
+
void collectionVersion;
|
|
154
233
|
return scores.get(value) ?? 0;
|
|
155
234
|
},
|
|
156
235
|
filter: options.filter,
|
|
157
236
|
registerItem(item) {
|
|
158
237
|
items.push(item);
|
|
238
|
+
bumpCollection();
|
|
159
239
|
const score = options.shouldFilter && options.search
|
|
160
240
|
? options.filter(item.value, options.search, item.keywords)
|
|
161
241
|
: 1;
|
|
@@ -171,13 +251,14 @@ export function createCommandState(options) {
|
|
|
171
251
|
const item = items[index];
|
|
172
252
|
scores.delete(item.value);
|
|
173
253
|
items.splice(index, 1);
|
|
254
|
+
bumpCollection();
|
|
174
255
|
}
|
|
175
256
|
},
|
|
176
257
|
select(value) {
|
|
177
258
|
selectedValue = value;
|
|
178
259
|
},
|
|
179
260
|
getSelectedValue() {
|
|
180
|
-
return
|
|
261
|
+
return resolveSelected();
|
|
181
262
|
},
|
|
182
263
|
navigateItems,
|
|
183
264
|
selectCurrent() {
|
|
@@ -7,26 +7,36 @@
|
|
|
7
7
|
const ctx = getCommandContext()
|
|
8
8
|
const headingId = useId('sp-command-group')
|
|
9
9
|
|
|
10
|
-
// In filtered mode,
|
|
11
|
-
//
|
|
10
|
+
// In filtered mode, a group with no visible item is hidden — its heading
|
|
11
|
+
// alone would be a promise of results that are not there.
|
|
12
12
|
const isHidden = $derived(
|
|
13
13
|
!forceMount && ctx.shouldFilter && ctx.search !== '' && !ctx.hasVisibleItems(),
|
|
14
14
|
)
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
{
|
|
17
|
+
<!--
|
|
18
|
+
The group is HIDDEN, never unmounted. Items register from their own
|
|
19
|
+
`$effect`, so they must exist for the registry to learn about them: gating
|
|
20
|
+
the children on `hasVisibleItems()` — a predicate over that same registry —
|
|
21
|
+
deadlocked whenever the registry was empty while a query was retained. On
|
|
22
|
+
remount (an inline field whose list reopens, a list rebuilt after its options
|
|
23
|
+
changed) nothing ever registered again and the palette showed zero options,
|
|
24
|
+
permanently. Items already gate their OWN rendering on their score, so a
|
|
25
|
+
hidden group is an empty box: `hidden` takes it out of layout and out of the
|
|
26
|
+
accessibility tree, which is all the rule was ever asking for.
|
|
27
|
+
-->
|
|
28
|
+
<div
|
|
29
|
+
class="sp-command-group {className ?? ''}"
|
|
30
|
+
role="group"
|
|
31
|
+
aria-labelledby={heading ? headingId : undefined}
|
|
32
|
+
data-command-group
|
|
33
|
+
hidden={isHidden}
|
|
34
|
+
>
|
|
35
|
+
{#if heading}
|
|
36
|
+
<div class="sp-command-group-heading" id={headingId}>{heading}</div>
|
|
37
|
+
{/if}
|
|
38
|
+
{#if children}{@render children()}{/if}
|
|
39
|
+
</div>
|
|
30
40
|
|
|
31
41
|
<style>
|
|
32
42
|
.sp-command-group {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-group.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/command/components/command-group.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"command-group.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/command/components/command-group.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAgCpD,QAAA,MAAM,YAAY,uDAAwC,CAAC;AAC3D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,eAAe,YAAY,CAAC"}
|
|
@@ -3,12 +3,55 @@
|
|
|
3
3
|
import { kbd } from '../../../internal/helpers/index.js'
|
|
4
4
|
import { getCommandContext } from '../command.svelte.js'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
let {
|
|
7
|
+
placeholder = 'Search...',
|
|
8
|
+
class: className,
|
|
9
|
+
wrapperClass,
|
|
10
|
+
element = $bindable(null),
|
|
11
|
+
// Pulled out of `rest` so the built-in behaviour can COMPOSE with it
|
|
12
|
+
// instead of being clobbered by the spread.
|
|
13
|
+
onkeydown: consumerKeydown,
|
|
14
|
+
...rest
|
|
15
|
+
}: CommandInputProps = $props()
|
|
7
16
|
const ctx = getCommandContext()
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Every keyboard behaviour below is gated on the list being REALLY rendered,
|
|
20
|
+
* never on finding a node in the document. In `modal` the list is always
|
|
21
|
+
* rendered alongside the input, so this is constantly true and nothing about
|
|
22
|
+
* the shipped behaviour moves. In `inline` the field outlives the results,
|
|
23
|
+
* and that is where the distinction earns its keep.
|
|
24
|
+
*/
|
|
25
|
+
const open = $derived(ctx.listMounted)
|
|
26
|
+
|
|
27
|
+
/** The rendered option's DOM id, or nothing at all. Resolved through the live
|
|
28
|
+
* registry, so it cannot name an option that filtering, removal or a closed
|
|
29
|
+
* list has taken away. */
|
|
30
|
+
const activeOptionId = $derived(ctx.getActiveOptionId() ?? undefined)
|
|
31
|
+
|
|
32
|
+
function onkeydown(e: KeyboardEvent & { currentTarget: EventTarget & HTMLInputElement }) {
|
|
10
33
|
if (e.isComposing) return
|
|
11
34
|
|
|
35
|
+
// The consumer runs first and may cancel Spectral's local handling for this
|
|
36
|
+
// key. It cannot retract a close the Escape layer has already performed:
|
|
37
|
+
// that one runs earlier, on `document`, in the capture phase —
|
|
38
|
+
// `onEscapeKeydown` on `Command.Root` is the hook for it.
|
|
39
|
+
consumerKeydown?.(e)
|
|
40
|
+
if (e.defaultPrevented) return
|
|
41
|
+
|
|
42
|
+
if (!open) {
|
|
43
|
+
// Results closed. The field is an ordinary text input: Enter belongs to
|
|
44
|
+
// the surrounding form, Escape to whatever surface is actually listening,
|
|
45
|
+
// Home/End to the caret. Claiming them here would make a closed palette
|
|
46
|
+
// interfere with the page — and Enter, in particular, could activate an
|
|
47
|
+
// option nobody can see.
|
|
48
|
+
if (e.key === kbd.ARROW_DOWN || e.key === kbd.ARROW_UP) {
|
|
49
|
+
e.preventDefault()
|
|
50
|
+
ctx.requestOpen()
|
|
51
|
+
}
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
|
|
12
55
|
switch (e.key) {
|
|
13
56
|
case kbd.ARROW_DOWN: {
|
|
14
57
|
e.preventDefault()
|
|
@@ -54,7 +97,7 @@
|
|
|
54
97
|
}
|
|
55
98
|
</script>
|
|
56
99
|
|
|
57
|
-
<div class="sp-command-input-wrapper">
|
|
100
|
+
<div class="sp-command-input-wrapper {wrapperClass ?? ''}">
|
|
58
101
|
<svg
|
|
59
102
|
class="sp-command-input-icon"
|
|
60
103
|
xmlns="http://www.w3.org/2000/svg"
|
|
@@ -71,13 +114,19 @@
|
|
|
71
114
|
<circle cx="11" cy="11" r="8" />
|
|
72
115
|
<path d="m21 21-4.3-4.3" />
|
|
73
116
|
</svg>
|
|
117
|
+
<!-- `{...rest}` FIRST: a consumer may add attributes, never override the
|
|
118
|
+
field's identity (role, id, type) or the three relations computed from
|
|
119
|
+
the palette's own state — those come after and win. -->
|
|
74
120
|
<input
|
|
121
|
+
{...rest}
|
|
122
|
+
bind:this={element}
|
|
75
123
|
class="sp-command-input {className ?? ''}"
|
|
76
124
|
id={ctx.inputId}
|
|
77
125
|
type="text"
|
|
78
126
|
role="combobox"
|
|
79
|
-
aria-expanded=
|
|
80
|
-
aria-controls={ctx.listId}
|
|
127
|
+
aria-expanded={ctx.open}
|
|
128
|
+
aria-controls={open ? ctx.listId : undefined}
|
|
129
|
+
aria-activedescendant={activeOptionId}
|
|
81
130
|
aria-autocomplete="list"
|
|
82
131
|
autocomplete="off"
|
|
83
132
|
{placeholder}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CommandInputProps } from '../types.js';
|
|
2
|
-
declare const CommandInput: import("svelte").Component<CommandInputProps, {}, "">;
|
|
2
|
+
declare const CommandInput: import("svelte").Component<CommandInputProps, {}, "element">;
|
|
3
3
|
type CommandInput = ReturnType<typeof CommandInput>;
|
|
4
4
|
export default CommandInput;
|
|
5
5
|
//# sourceMappingURL=command-input.svelte.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-input.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/command/components/command-input.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"command-input.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/command/components/command-input.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAoHpD,QAAA,MAAM,YAAY,8DAAwC,CAAC;AAC3D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,eAAe,YAAY,CAAC"}
|
|
@@ -4,11 +4,30 @@
|
|
|
4
4
|
|
|
5
5
|
const { label = 'Suggestions', class: className, children }: CommandListProps = $props()
|
|
6
6
|
const ctx = getCommandContext()
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* In `modal` the Root only exists while open, so this is always true and
|
|
10
|
+
* nothing changes. In `inline` the field outlives the results: the list must
|
|
11
|
+
* be ABSENT when closed, not merely hidden. Hiding it in CSS would leave
|
|
12
|
+
* every option in the document, where the Enter path could still reach one —
|
|
13
|
+
* an invisible command, executed.
|
|
14
|
+
*/
|
|
15
|
+
const rendered = $derived(ctx.mode !== 'inline' || ctx.open)
|
|
16
|
+
|
|
17
|
+
// The Root gates behaviour on the list being REALLY rendered, so the list is
|
|
18
|
+
// what reports it rather than anyone inferring it.
|
|
19
|
+
$effect(() => {
|
|
20
|
+
if (!rendered) return
|
|
21
|
+
ctx.setListMounted(true)
|
|
22
|
+
return () => ctx.setListMounted(false)
|
|
23
|
+
})
|
|
7
24
|
</script>
|
|
8
25
|
|
|
9
|
-
|
|
10
|
-
{
|
|
11
|
-
|
|
26
|
+
{#if rendered}
|
|
27
|
+
<div class="sp-command-list {className ?? ''}" id={ctx.listId} role="listbox" aria-label={label}>
|
|
28
|
+
{#if children}{@render children()}{/if}
|
|
29
|
+
</div>
|
|
30
|
+
{/if}
|
|
12
31
|
|
|
13
32
|
<style>
|
|
14
33
|
.sp-command-list {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-list.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/command/components/command-list.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"command-list.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/command/components/command-list.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAsCnD,QAAA,MAAM,WAAW,sDAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
shouldFilter = true,
|
|
16
16
|
loop = true,
|
|
17
17
|
portalTo,
|
|
18
|
-
|
|
18
|
+
mode = 'modal',
|
|
19
|
+
trapFocus,
|
|
19
20
|
closeOnEscape = true,
|
|
20
21
|
closeOnOutsideClick = true,
|
|
21
22
|
onEscapeKeydown,
|
|
@@ -26,10 +27,27 @@
|
|
|
26
27
|
children,
|
|
27
28
|
}: CommandProps = $props()
|
|
28
29
|
|
|
30
|
+
/** A field living in an app bar must stay in the page's natural tab order,
|
|
31
|
+
* so `inline` flips the default — an explicit value still wins. */
|
|
32
|
+
const trapsFocus = $derived(trapFocus ?? mode !== 'inline')
|
|
33
|
+
/** Inline renders IN PLACE unless a target is given: the consumer's scoped
|
|
34
|
+
* CSS then applies, and the results can be anchored to the field. */
|
|
35
|
+
const portalDisabled = $derived(mode === 'inline' && portalTo === undefined)
|
|
36
|
+
|
|
29
37
|
const commandState = createCommandState({
|
|
30
38
|
get search() {
|
|
31
39
|
return value
|
|
32
40
|
},
|
|
41
|
+
get mode() {
|
|
42
|
+
return mode
|
|
43
|
+
},
|
|
44
|
+
get open() {
|
|
45
|
+
return open
|
|
46
|
+
},
|
|
47
|
+
onRequestOpen() {
|
|
48
|
+
open = true
|
|
49
|
+
onOpenChange?.(true)
|
|
50
|
+
},
|
|
33
51
|
get filter() {
|
|
34
52
|
return filter
|
|
35
53
|
},
|
|
@@ -83,11 +101,15 @@
|
|
|
83
101
|
},
|
|
84
102
|
})
|
|
85
103
|
|
|
104
|
+
// The two layers follow `open` in BOTH modes — which is exactly what makes a
|
|
105
|
+
// closed inline palette inert: no `document` listener, and no slot held in
|
|
106
|
+
// the global Escape / dismiss stacks that a surface below would have to
|
|
107
|
+
// yield to.
|
|
86
108
|
$effect(() => {
|
|
87
109
|
if (open && isBrowser) {
|
|
88
110
|
escapeLayer.mount()
|
|
89
111
|
dismissLayer.mount()
|
|
90
|
-
if (
|
|
112
|
+
if (trapsFocus && contentEl) {
|
|
91
113
|
focusScope.setElement(contentEl)
|
|
92
114
|
focusScope.mount()
|
|
93
115
|
}
|
|
@@ -109,12 +131,14 @@
|
|
|
109
131
|
})
|
|
110
132
|
</script>
|
|
111
133
|
|
|
112
|
-
|
|
113
|
-
|
|
134
|
+
<!-- Inline keeps the Root mounted whatever `open` is: the field is the point. -->
|
|
135
|
+
{#if mode === 'inline' || presence.isPresent}
|
|
136
|
+
<Portal to={portalTo} disabled={portalDisabled}>
|
|
114
137
|
<div
|
|
115
138
|
bind:this={contentEl}
|
|
116
139
|
class="sp-command {className ?? ''}"
|
|
117
140
|
data-command-root
|
|
141
|
+
data-mode={mode}
|
|
118
142
|
data-state={open ? 'open' : 'closed'}
|
|
119
143
|
>
|
|
120
144
|
{#if children}{@render children()}{/if}
|
|
@@ -132,4 +156,19 @@
|
|
|
132
156
|
background-color: var(--sp-sys-color-surface-container);
|
|
133
157
|
box-shadow: var(--sp-sys-elevation-3);
|
|
134
158
|
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Inline is not a panel: it is a field with results hanging off it. The
|
|
162
|
+
* panel chrome is dropped so the consumer can dress the field, and
|
|
163
|
+
* `overflow` is released so results positioned below are not clipped by the
|
|
164
|
+
* very element that owns them. `position: relative` makes the Root the
|
|
165
|
+
* containing block, which is what an anchored list needs.
|
|
166
|
+
*/
|
|
167
|
+
.sp-command[data-mode='inline'] {
|
|
168
|
+
position: relative;
|
|
169
|
+
overflow: visible;
|
|
170
|
+
border-radius: 0;
|
|
171
|
+
background-color: transparent;
|
|
172
|
+
box-shadow: none;
|
|
173
|
+
}
|
|
135
174
|
</style>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-root.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/command/components/command-root.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"command-root.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/command/components/command-root.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AA2J/C,QAAA,MAAM,WAAW,gEAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { defaultFilter } from './command.svelte.js';
|
|
2
|
+
export type { CommandMode } from './command.svelte.js';
|
|
2
3
|
export { default as Empty } from './components/command-empty.svelte';
|
|
3
4
|
export { default as Group } from './components/command-group.svelte';
|
|
4
5
|
export { default as Input } from './components/command-input.svelte';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/components/command/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,mCAAmC,CAAA;AACpE,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,mCAAmC,CAAA;A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|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
|
+
import type { HTMLAttributes, HTMLInputAttributes } from 'svelte/elements';
|
|
3
|
+
import type { CommandMode } from './command.svelte.js';
|
|
3
4
|
export interface CommandProps {
|
|
4
5
|
/** Current search query (bindable). */
|
|
5
6
|
value?: string;
|
|
@@ -9,13 +10,39 @@ export interface CommandProps {
|
|
|
9
10
|
shouldFilter?: boolean;
|
|
10
11
|
/** Whether keyboard navigation loops at edges. @default true */
|
|
11
12
|
loop?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Composition mode.
|
|
15
|
+
*
|
|
16
|
+
* - `'modal'` (default, unchanged behaviour): `open` controls whether the
|
|
17
|
+
* palette is MOUNTED — closing unmounts the content, the field included,
|
|
18
|
+
* together with the Escape and outside-pointer layers.
|
|
19
|
+
* - `'inline'`: the Root and its `Command.Input` stay mounted whatever `open`
|
|
20
|
+
* is, so a search field can live permanently in a bar; `open` then governs
|
|
21
|
+
* only whether `Command.List` is RENDERED, and the two layers follow the
|
|
22
|
+
* results. A closed inline palette listens to nothing: no document
|
|
23
|
+
* listener, no slot held in the global layer stacks.
|
|
24
|
+
*
|
|
25
|
+
* @default 'modal'
|
|
26
|
+
*/
|
|
27
|
+
mode?: CommandMode;
|
|
12
28
|
/**
|
|
13
29
|
* Controls whether the palette is mounted. When true, render content. Default: true.
|
|
30
|
+
* In `'inline'` mode this controls the RESULTS only — see `mode`.
|
|
14
31
|
*/
|
|
15
32
|
open?: boolean;
|
|
16
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Portal target. Default `document.body` in `'modal'` mode; in `'inline'`
|
|
35
|
+
* mode the content is rendered IN PLACE by default, so the consumer's scoped
|
|
36
|
+
* CSS applies and the results can be anchored to the field. Passing a target
|
|
37
|
+
* portals in either mode.
|
|
38
|
+
*/
|
|
17
39
|
portalTo?: HTMLElement | string;
|
|
18
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Trap focus within the palette.
|
|
42
|
+
* @default `true` in `'modal'` mode, `false` in `'inline'` mode — a field
|
|
43
|
+
* sitting in a bar must stay part of the page's natural tab order. An
|
|
44
|
+
* explicit value is honoured in both modes.
|
|
45
|
+
*/
|
|
19
46
|
trapFocus?: boolean;
|
|
20
47
|
/** Close on Escape keydown. Default: true. */
|
|
21
48
|
closeOnEscape?: boolean;
|
|
@@ -35,10 +62,38 @@ export interface CommandProps {
|
|
|
35
62
|
class?: string;
|
|
36
63
|
children?: Snippet;
|
|
37
64
|
}
|
|
38
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Extends the native `input` attributes. A consumer's `title`, `name`,
|
|
67
|
+
* `aria-label` / `aria-labelledby` / `aria-describedby`, `data-testid`,
|
|
68
|
+
* `style` and native event handlers reach the real `role="combobox"` node.
|
|
69
|
+
*
|
|
70
|
+
* The field's IDENTITY stays with the component: `role`, `id`, `type` and the
|
|
71
|
+
* three computed relations (`aria-expanded`, `aria-controls`,
|
|
72
|
+
* `aria-activedescendant`) are rejected by the type — they are derived from
|
|
73
|
+
* the palette's own state and a consumer value could only contradict it.
|
|
74
|
+
*
|
|
75
|
+
* Consumer handlers COMPOSE with the built-in ones: yours runs first, and
|
|
76
|
+
* calling `preventDefault()` cancels Spectral's local keyboard handling for
|
|
77
|
+
* that key. It does NOT retract a close already performed by the Escape layer,
|
|
78
|
+
* which runs earlier, on `document`, in the capture phase — `onEscapeKeydown`
|
|
79
|
+
* on `Command.Root` is the public hook for that.
|
|
80
|
+
*/
|
|
81
|
+
export interface CommandInputProps extends Omit<HTMLInputAttributes, 'class' | 'children' | 'value' | 'type' | 'role' | 'id' | 'autocomplete' | 'oninput' | 'aria-expanded' | 'aria-controls' | 'aria-activedescendant' | 'aria-autocomplete'> {
|
|
39
82
|
/** Placeholder text for the search input. */
|
|
40
83
|
placeholder?: string;
|
|
84
|
+
/** Class placed on the `<input>` itself. */
|
|
41
85
|
class?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Class placed on the wrapper that holds the icon and the input — the box
|
|
88
|
+
* that carries the padding and the bottom border. This is the hook for
|
|
89
|
+
* restyling the field as, say, a pill inside an app bar.
|
|
90
|
+
*/
|
|
91
|
+
wrapperClass?: string;
|
|
92
|
+
/**
|
|
93
|
+
* The real input element, bindable. Lets the consumer focus the field
|
|
94
|
+
* (a `Cmd/Ctrl+K` shortcut, say) without reaching for an internal selector.
|
|
95
|
+
*/
|
|
96
|
+
element?: HTMLInputElement | null;
|
|
42
97
|
}
|
|
43
98
|
export interface CommandListProps {
|
|
44
99
|
/** Accessible label for the listbox. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/components/command/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/components/command/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEtD,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,gGAAgG;IAChG,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,CAAA;IACvE,0EAA0E;IAC1E,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,gEAAgE;IAChE,IAAI,CAAC,EAAE,OAAO,CAAA;IACd;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAC,EAAE,WA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