@ui-sdk/svelte 0.1.0-beta.6 → 0.1.0-beta.7

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.
@@ -9,7 +9,7 @@ Without text content, it shows the suggestion's label.
9
9
  autocomplete as autocompletePrimitive,
10
10
  type AutocompleteItemTextState,
11
11
  } from "@ui-sdk/core/autocomplete"
12
- import { getContext } from "svelte"
12
+ import { getContext, untrack } from "svelte"
13
13
  import { createAttachmentKey, type Attachment } from "svelte/attachments"
14
14
  import Part from "../part.svelte"
15
15
  import { useHandle } from "../instance.js"
@@ -30,20 +30,43 @@ Without text content, it shows the suggestion's label.
30
30
  // can't be read before it renders, as a Vue slot can. Until then, and on
31
31
  // the server, the content renders as it is. Content that holds elements
32
32
  // stays as it is, and the suggestion's label is what's marked.
33
- let text = $state<string>()
33
+ const key = $derived(item().key)
34
+ // A reused item takes a new key, maybe while a search shows the marked text
35
+ // in place of its content, so its text is read again.
36
+ let text = $derived.by<string | undefined>(() => {
37
+ void key
38
+ return undefined
39
+ })
34
40
  const part = useHandlePart(autocomplete, "item-text", () => ({
35
41
  id: item().key,
36
42
  text: text ?? item().label,
37
43
  }))
44
+ // A reused item or a count in its label changes the content without a new
45
+ // snippet, so only the page can tell.
46
+ const searching = $derived(
47
+ text !== undefined && part.state.segments.some((segment) => segment.match)
48
+ )
38
49
  const learn: Attachment<HTMLElement> = (el) => {
39
- if (!children || text !== undefined) {
50
+ if (!children) {
40
51
  return
41
52
  }
42
- const nodes = [...el.childNodes]
43
- if (nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)) {
44
- return
53
+ const read = () => {
54
+ if (searching) {
55
+ return
56
+ }
57
+ const nodes = [...el.childNodes]
58
+ text = nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)
59
+ ? undefined
60
+ : (el.textContent ?? "").replace(/\s+/g, " ").trim()
45
61
  }
46
- text = (el.textContent ?? "").replace(/\s+/g, " ").trim()
62
+ untrack(read)
63
+ const observer = new MutationObserver(read)
64
+ observer.observe(el, {
65
+ childList: true,
66
+ characterData: true,
67
+ subtree: true,
68
+ })
69
+ return () => observer.disconnect()
47
70
  }
48
71
  const learnKey = createAttachmentKey()
49
72
  </script>
@@ -59,7 +82,7 @@ Without text content, it shows the suggestion's label.
59
82
  {part}
60
83
  props={{
61
84
  ...rest,
62
- children: text === undefined && children ? children : marked,
85
+ children: children && !searching ? children : marked,
63
86
  [learnKey]: learn,
64
87
  }}
65
88
  />
@@ -9,7 +9,7 @@ Without text content, it shows the item's label.
9
9
  combobox as comboboxPrimitive,
10
10
  type ComboboxItemTextState,
11
11
  } from "@ui-sdk/core/combobox"
12
- import { getContext } from "svelte"
12
+ import { getContext, untrack } from "svelte"
13
13
  import { createAttachmentKey, type Attachment } from "svelte/attachments"
14
14
  import Part from "../part.svelte"
15
15
  import { useHandle } from "../instance.js"
@@ -27,20 +27,43 @@ Without text content, it shows the item's label.
27
27
  // can't be read before it renders, as a Vue slot can. Until then, and on
28
28
  // the server, the content renders as it is. Content that holds elements
29
29
  // stays as it is, and the item's label is what's marked.
30
- let text = $state<string>()
30
+ const key = $derived(item().key)
31
+ // A reused item takes a new key, maybe while a search shows the marked text
32
+ // in place of its content, so its text is read again.
33
+ let text = $derived.by<string | undefined>(() => {
34
+ void key
35
+ return undefined
36
+ })
31
37
  const part = useHandlePart(combobox, "item-text", () => ({
32
38
  id: item().key,
33
39
  text: text ?? item().label ?? "",
34
40
  }))
41
+ // A reused item or a count in its label changes the content without a new
42
+ // snippet, so only the page can tell.
43
+ const searching = $derived(
44
+ text !== undefined && part.state.segments.some((segment) => segment.match)
45
+ )
35
46
  const learn: Attachment<HTMLElement> = (el) => {
36
- if (!children || text !== undefined) {
47
+ if (!children) {
37
48
  return
38
49
  }
39
- const nodes = [...el.childNodes]
40
- if (nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)) {
41
- return
50
+ const read = () => {
51
+ if (searching) {
52
+ return
53
+ }
54
+ const nodes = [...el.childNodes]
55
+ text = nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)
56
+ ? undefined
57
+ : (el.textContent ?? "").replace(/\s+/g, " ").trim()
42
58
  }
43
- text = (el.textContent ?? "").replace(/\s+/g, " ").trim()
59
+ untrack(read)
60
+ const observer = new MutationObserver(read)
61
+ observer.observe(el, {
62
+ childList: true,
63
+ characterData: true,
64
+ subtree: true,
65
+ })
66
+ return () => observer.disconnect()
44
67
  }
45
68
  const learnKey = createAttachmentKey()
46
69
  </script>
@@ -56,7 +79,7 @@ Without text content, it shows the item's label.
56
79
  {part}
57
80
  props={{
58
81
  ...rest,
59
- children: text === undefined && children ? children : marked,
82
+ children: children && !searching ? children : marked,
60
83
  [learnKey]: learn,
61
84
  }}
62
85
  />
@@ -9,7 +9,7 @@ Without text content, it shows the command's label.
9
9
  command as commandPrimitive,
10
10
  type CommandItemTextState,
11
11
  } from "@ui-sdk/core/command"
12
- import { getContext } from "svelte"
12
+ import { getContext, untrack } from "svelte"
13
13
  import { createAttachmentKey, type Attachment } from "svelte/attachments"
14
14
  import Part from "../part.svelte"
15
15
  import { useHandle } from "../instance.js"
@@ -27,20 +27,43 @@ Without text content, it shows the command's label.
27
27
  // can't be read before it renders, as a Vue slot can. Until then, and on
28
28
  // the server, the content renders as it is. Content that holds elements
29
29
  // stays as it is, and the command's label is what's marked.
30
- let text = $state<string>()
30
+ const key = $derived(item().key)
31
+ // A reused item takes a new key, maybe while a search shows the marked text
32
+ // in place of its content, so its text is read again.
33
+ let text = $derived.by<string | undefined>(() => {
34
+ void key
35
+ return undefined
36
+ })
31
37
  const part = useHandlePart(command, "item-text", () => ({
32
38
  id: item().key,
33
39
  text: text ?? item().label ?? "",
34
40
  }))
41
+ // A reused item or a count in its label changes the content without a new
42
+ // snippet, so only the page can tell.
43
+ const searching = $derived(
44
+ text !== undefined && part.state.segments.some((segment) => segment.match)
45
+ )
35
46
  const learn: Attachment<HTMLElement> = (el) => {
36
- if (!children || text !== undefined) {
47
+ if (!children) {
37
48
  return
38
49
  }
39
- const nodes = [...el.childNodes]
40
- if (nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)) {
41
- return
50
+ const read = () => {
51
+ if (searching) {
52
+ return
53
+ }
54
+ const nodes = [...el.childNodes]
55
+ text = nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)
56
+ ? undefined
57
+ : (el.textContent ?? "").replace(/\s+/g, " ").trim()
42
58
  }
43
- text = (el.textContent ?? "").replace(/\s+/g, " ").trim()
59
+ untrack(read)
60
+ const observer = new MutationObserver(read)
61
+ observer.observe(el, {
62
+ childList: true,
63
+ characterData: true,
64
+ subtree: true,
65
+ })
66
+ return () => observer.disconnect()
44
67
  }
45
68
  const learnKey = createAttachmentKey()
46
69
  </script>
@@ -56,7 +79,7 @@ Without text content, it shows the command's label.
56
79
  {part}
57
80
  props={{
58
81
  ...rest,
59
- children: text === undefined && children ? children : marked,
82
+ children: children && !searching ? children : marked,
60
83
  [learnKey]: learn,
61
84
  }}
62
85
  />
@@ -19,13 +19,10 @@ browser's message for the current problem.
19
19
 
20
20
  const field = useField()
21
21
  const uid = $props.id()
22
- // Only an error with `match` needs an id of its own. One without takes the
23
- // field's, which the control points at before the field binds.
22
+ // Each error is its own part, keyed by a made value. Core gives the first one
23
+ // that shows the id the control points at before the field binds.
24
24
  const error = field
25
- ? useHandlePart(field, "error", () => ({
26
- id: rest.id ?? (match === undefined ? undefined : `ui-sdk-${uid}`),
27
- match,
28
- }))
25
+ ? useHandlePart(field, "error", () => ({ id: rest.id, value: uid, match }))
29
26
  : undefined
30
27
  const shown = $derived(
31
28
  error ? error.present : fieldOutsideErrorShown({ match })
@@ -9,7 +9,7 @@ text content, it shows the item's label.
9
9
  select as selectPrimitive,
10
10
  type SelectItemTextState,
11
11
  } from "@ui-sdk/core/select"
12
- import { getContext } from "svelte"
12
+ import { getContext, untrack } from "svelte"
13
13
  import { createAttachmentKey, type Attachment } from "svelte/attachments"
14
14
  import Part from "../part.svelte"
15
15
  import { useHandle } from "../instance.js"
@@ -27,20 +27,43 @@ text content, it shows the item's label.
27
27
  // can't be read before it renders, as a Vue slot can. Until then, and on
28
28
  // the server, the content renders as it is. Content that holds elements
29
29
  // stays as it is, and the item's label is what's marked.
30
- let text = $state<string>()
30
+ const key = $derived(item().key)
31
+ // A reused item takes a new key, maybe while a search shows the marked text
32
+ // in place of its content, so its text is read again.
33
+ let text = $derived.by<string | undefined>(() => {
34
+ void key
35
+ return undefined
36
+ })
31
37
  const part = useHandlePart(select, "item-text", () => ({
32
38
  id: item().key,
33
39
  text: text ?? item().label ?? "",
34
40
  }))
41
+ // A reused item or a count in its label changes the content without a new
42
+ // snippet, so only the page can tell.
43
+ const searching = $derived(
44
+ text !== undefined && part.state.segments.some((segment) => segment.match)
45
+ )
35
46
  const learn: Attachment<HTMLElement> = (el) => {
36
- if (!children || text !== undefined) {
47
+ if (!children) {
37
48
  return
38
49
  }
39
- const nodes = [...el.childNodes]
40
- if (nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)) {
41
- return
50
+ const read = () => {
51
+ if (searching) {
52
+ return
53
+ }
54
+ const nodes = [...el.childNodes]
55
+ text = nodes.some((node) => node.nodeType === Node.ELEMENT_NODE)
56
+ ? undefined
57
+ : (el.textContent ?? "").replace(/\s+/g, " ").trim()
42
58
  }
43
- text = (el.textContent ?? "").replace(/\s+/g, " ").trim()
59
+ untrack(read)
60
+ const observer = new MutationObserver(read)
61
+ observer.observe(el, {
62
+ childList: true,
63
+ characterData: true,
64
+ subtree: true,
65
+ })
66
+ return () => observer.disconnect()
44
67
  }
45
68
  const learnKey = createAttachmentKey()
46
69
  </script>
@@ -56,7 +79,7 @@ text content, it shows the item's label.
56
79
  {part}
57
80
  props={{
58
81
  ...rest,
59
- children: text === undefined && children ? children : marked,
82
+ children: children && !searching ? children : marked,
60
83
  [learnKey]: learn,
61
84
  }}
62
85
  />
package/docs/agents.md CHANGED
@@ -1029,6 +1029,8 @@ An `allow` that returns `true` without reading `step.confirm` answers yes for th
1029
1029
 
1030
1030
  The mark covers its element and everything inside it, for any action. Put it on a form or section to cover every control in it, or on a dialog's content to cover the buttons inside, wherever the dialog renders.
1031
1031
 
1032
+ A mark on one option of a Select or Combobox counts even while the list is closed, since the agent opens it for a moment to look. A list that renders only some of its options, like a virtualized one, or one filtered by text in its field, shows the agent only those. Mark something that stays on the page instead, like its trigger or a wrapper around it, and every choice in it waits for the person.
1033
+
1032
1034
  ## Keep Parts of the Page from the Agent
1033
1035
 
1034
1036
  Two more marks change what the agent sees:
@@ -3308,6 +3308,7 @@ Also tested:
3308
3308
  **Enhancements**
3309
3309
 
3310
3310
  - The list is named by the combobox's label.
3311
+ - A click on the label focuses the input and leaves the list closed.
3311
3312
  - Filtering matches an item's keywords as well as its label.
3312
3313
  - A create option offers the text, and hides when an item's label matches it exactly.
3313
3314
  - Enter on the create option calls onCreate with the text.
@@ -1409,6 +1409,7 @@ Every line below is an automated test.
1409
1409
  - Tab past the panel's last link moves on to the next trigger.
1410
1410
  - Shift+Tab from the panel's first link returns to its trigger.
1411
1411
  - Shift+Tab from the item after an open panel goes back into the panel.
1412
+ - Tab from the last item past an open panel leaves the navigation and closes it.
1412
1413
  - Escape inside a panel closes it and returns focus to its trigger.
1413
1414
  - Escape on an open trigger closes its panel.
1414
1415
  - Focus leaving the navigation closes the panel.
@@ -882,4 +882,8 @@ Every line below is an automated test.
882
882
  - At a limit, the cursor points the only way a handle can go.
883
883
  - A saved layout is there on the first paint.
884
884
 
885
+ **Touch**
886
+
887
+ - A touch drag that starts beside the handle, in its touch hit area, resizes without scrolling.
888
+
885
889
  Runs in React, Vue and web components.
@@ -29,7 +29,7 @@ Tabs
29
29
  └── TabsPanel
30
30
  ```
31
31
 
32
- Give each tab and its panel the same unique `value`. Give the list an accessible name. Set `defaultValue` to choose the initial tab; otherwise, the first enabled tab is selected.
32
+ Give each tab and its panel the same unique `value`. Give the list an accessible name. Set `defaultValue` to choose the initial tab; otherwise, the first enabled tab is selected. On the server, panels that render before the list don't know that tab yet, so a layout with the panels first, like a bottom tab bar, needs `defaultValue` or `bind:value` to render its panel before hydration.
33
33
 
34
34
  ## Usage
35
35
 
@@ -1123,6 +1123,7 @@ Every line below is an automated test.
1123
1123
 
1124
1124
  - Typing a trigger opens the list with every item.
1125
1125
  - Typing after the trigger filters the list.
1126
+ - Text an input method commits filters the list.
1126
1127
  - Queries match Unicode letters and ignore accents.
1127
1128
  - A trigger mid-word doesn't open.
1128
1129
  - A trigger followed by a space doesn't open.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui-sdk/svelte",
3
- "version": "0.1.0-beta.6",
3
+ "version": "0.1.0-beta.7",
4
4
  "description": "UI SDK for Svelte.",
5
5
  "keywords": [
6
6
  "svelte",
@@ -381,7 +381,7 @@
381
381
  ],
382
382
  "peerDependencies": {
383
383
  "svelte": ">=5.33",
384
- "@ui-sdk/core": "^0.1.0-beta.6"
384
+ "@ui-sdk/core": "^0.1.0-beta.7"
385
385
  },
386
386
  "devDependencies": {
387
387
  "@sveltejs/package": "^2.5.8",
@@ -393,7 +393,7 @@
393
393
  "typescript": "~5.9.3",
394
394
  "vite": "^8.3.3",
395
395
  "vitest": "^5.0.3",
396
- "@ui-sdk/core": "0.1.0-beta.6"
396
+ "@ui-sdk/core": "0.1.0-beta.7"
397
397
  },
398
398
  "scripts": {
399
399
  "build": "node ../../scripts/build/build-svelte-package.mjs",