@rokkit/states 1.0.0-next.146 → 1.0.0-next.147

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/states",
3
- "version": "1.0.0-next.146",
3
+ "version": "1.0.0-next.147",
4
4
  "description": "Contains generic data manipulation functions that can be used in various components.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,14 +42,17 @@ export class Wrapper {
42
42
  #onchange
43
43
  #selectedValue = $state(undefined)
44
44
 
45
+ #collapsible
46
+
45
47
  /**
46
48
  * @param {import('./proxy-tree.svelte.js').ProxyTree} proxyTree
47
- * @param {{ onselect?: Function, onchange?: Function }} [options]
49
+ * @param {{ onselect?: Function, onchange?: Function, collapsible?: boolean }} [options]
48
50
  */
49
51
  constructor(proxyTree, options = {}) {
50
52
  this.#proxyTree = proxyTree
51
53
  this.#onselect = options.onselect
52
54
  this.#onchange = options.onchange
55
+ this.#collapsible = options.collapsible ?? true
53
56
  }
54
57
 
55
58
  // ─── IWrapper: state read by Navigator ─────────────────────────────────────
@@ -90,7 +93,8 @@ export class Wrapper {
90
93
 
91
94
  /**
92
95
  * Expand focused group, or move focus into it if already open.
93
- * No-op on leaf items.
96
+ * No-op on leaf items. When collapsible=false groups are always open,
97
+ * so this only ever moves focus into the first child.
94
98
  */
95
99
  expand(_path) {
96
100
  if (!this.#focusedKey) return
@@ -119,12 +123,13 @@ export class Wrapper {
119
123
  /**
120
124
  * Collapse focused group, or move focus to parent if already collapsed / leaf.
121
125
  * At root level with no parent: no-op.
126
+ * When collapsible=false, skips closing the group but still moves focus to parent.
122
127
  */
123
128
  collapse(_path) {
124
129
  if (!this.#focusedKey) return
125
130
  const node = this.flatView.find((n) => n.key === this.#focusedKey)
126
131
  if (!node) return
127
- if (node.hasChildren && node.proxy.expanded) {
132
+ if (node.hasChildren && node.proxy.expanded && this.#collapsible) {
128
133
  node.proxy.expanded = false
129
134
  } else {
130
135
  this.#focusParent()
@@ -147,7 +152,7 @@ export class Wrapper {
147
152
 
148
153
  /**
149
154
  * Select item at path (or focusedKey when path is null).
150
- * Groups toggle expanded. Leaves fire onchange (value differs) and onselect callbacks.
155
+ * Groups toggle expanded (only when collapsible=true). Leaves fire onchange and onselect callbacks.
151
156
  */
152
157
  select(path) {
153
158
  const key = path ?? this.#focusedKey
@@ -156,7 +161,7 @@ export class Wrapper {
156
161
  const proxy = this.#proxyTree.lookup.get(key)
157
162
  if (!proxy) return
158
163
  if (proxy.hasChildren) {
159
- proxy.expanded = !proxy.expanded
164
+ if (this.#collapsible) proxy.expanded = !proxy.expanded
160
165
  } else {
161
166
  this.#selectLeaf(proxy)
162
167
  }
@@ -165,8 +170,10 @@ export class Wrapper {
165
170
  /**
166
171
  * Toggle expansion of group at path — called by Navigator for accordion-trigger clicks.
167
172
  * Unlike select(), this only applies to groups and never fires onselect.
173
+ * No-op when collapsible=false.
168
174
  */
169
175
  toggle(path) {
176
+ if (!this.#collapsible) return
170
177
  const key = path ?? this.#focusedKey
171
178
  if (!key) return
172
179
  const proxy = this.#proxyTree.lookup.get(key)