@rokkit/states 1.0.0-next.149 → 1.0.0-next.151
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 +1 -1
- package/src/alerts.svelte.js +8 -4
- package/src/proxy-item.svelte.js +5 -1
- package/src/proxy-tree.svelte.js +5 -1
- package/src/wrapper.svelte.js +17 -10
package/package.json
CHANGED
package/src/alerts.svelte.js
CHANGED
|
@@ -13,13 +13,17 @@ class AlertsStore {
|
|
|
13
13
|
* @param {{ type?: string, text?: string, dismissible?: boolean, timeout?: number, actions?: unknown }} alert
|
|
14
14
|
* @returns {string}
|
|
15
15
|
*/
|
|
16
|
+
#scheduleTimer(id, timeout) {
|
|
17
|
+
if (timeout > 0) {
|
|
18
|
+
this.#timers.set(id, setTimeout(() => this.dismiss(id), timeout))
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line complexity
|
|
16
23
|
push({ type = 'info', text, dismissible = false, timeout = dismissible ? 0 : 4000, actions } = {}) {
|
|
17
24
|
const id = crypto.randomUUID()
|
|
18
25
|
this.#items = [...this.#items, { id, type, text, dismissible, timeout, actions }]
|
|
19
|
-
|
|
20
|
-
const timer = setTimeout(() => this.dismiss(id), timeout)
|
|
21
|
-
this.#timers.set(id, timer)
|
|
22
|
-
}
|
|
26
|
+
this.#scheduleTimer(id, timeout)
|
|
23
27
|
return id
|
|
24
28
|
}
|
|
25
29
|
|
package/src/proxy-item.svelte.js
CHANGED
|
@@ -92,8 +92,12 @@ export class ProxyItem {
|
|
|
92
92
|
* @param {string} [key] Path-based key assigned by ProxyTree
|
|
93
93
|
* @param {number} [level] Nesting depth (1 = root)
|
|
94
94
|
*/
|
|
95
|
+
#mergeFields(fields) {
|
|
96
|
+
return { ...BASE_FIELDS, ...(fields && typeof fields === 'object' ? fields : {}) }
|
|
97
|
+
}
|
|
98
|
+
|
|
95
99
|
constructor(raw, fields = {}, key = '', level = 0) {
|
|
96
|
-
this.#fields =
|
|
100
|
+
this.#fields = this.#mergeFields(fields)
|
|
97
101
|
this.#raw = raw
|
|
98
102
|
this.#key = key
|
|
99
103
|
this.#level = level
|
package/src/proxy-tree.svelte.js
CHANGED
|
@@ -136,8 +136,12 @@ export class ProxyTree {
|
|
|
136
136
|
* @param {Partial<typeof BASE_FIELDS>} [fields]
|
|
137
137
|
* @param {{ createProxy?: (raw: *, fields: object, key: string, level: number) => ProxyItem }} [options]
|
|
138
138
|
*/
|
|
139
|
+
#mergeFields(fields) {
|
|
140
|
+
return { ...BASE_FIELDS, ...(fields && typeof fields === 'object' ? fields : {}) }
|
|
141
|
+
}
|
|
142
|
+
|
|
139
143
|
constructor(items = [], fields = {}, options = {}) {
|
|
140
|
-
this.#fields =
|
|
144
|
+
this.#fields = this.#mergeFields(fields)
|
|
141
145
|
this.#factory = this.#resolveFactory(options.createProxy)
|
|
142
146
|
this.#rootProxies = (items ?? []).map((raw, i) =>
|
|
143
147
|
this.#factory(raw, this.#fields, String(i), 1)
|
package/src/wrapper.svelte.js
CHANGED
|
@@ -125,11 +125,13 @@ export class Wrapper {
|
|
|
125
125
|
* At root level with no parent: no-op.
|
|
126
126
|
* When collapsible=false, skips closing the group but still moves focus to parent.
|
|
127
127
|
*/
|
|
128
|
+
// eslint-disable-next-line complexity
|
|
128
129
|
collapse(_path) {
|
|
129
130
|
if (!this.#focusedKey) return
|
|
130
131
|
const node = this.flatView.find((n) => n.key === this.#focusedKey)
|
|
131
132
|
if (!node) return
|
|
132
|
-
|
|
133
|
+
const canCollapse = node.hasChildren && node.proxy.expanded && this.#collapsible
|
|
134
|
+
if (canCollapse) {
|
|
133
135
|
node.proxy.expanded = false
|
|
134
136
|
} else {
|
|
135
137
|
this.#focusParent()
|
|
@@ -154,12 +156,7 @@ export class Wrapper {
|
|
|
154
156
|
* Select item at path (or focusedKey when path is null).
|
|
155
157
|
* Groups toggle expanded (only when collapsible=true). Leaves fire onchange and onselect callbacks.
|
|
156
158
|
*/
|
|
157
|
-
|
|
158
|
-
const key = path ?? this.#focusedKey
|
|
159
|
-
if (!key) return
|
|
160
|
-
this.#focusedKey = key
|
|
161
|
-
const proxy = this.#proxyTree.lookup.get(key)
|
|
162
|
-
if (!proxy) return
|
|
159
|
+
#selectProxy(proxy) {
|
|
163
160
|
if (proxy.hasChildren) {
|
|
164
161
|
if (this.#collapsible) proxy.expanded = !proxy.expanded
|
|
165
162
|
} else {
|
|
@@ -167,17 +164,27 @@ export class Wrapper {
|
|
|
167
164
|
}
|
|
168
165
|
}
|
|
169
166
|
|
|
167
|
+
select(path) {
|
|
168
|
+
const key = path ?? this.#focusedKey
|
|
169
|
+
if (!key) return
|
|
170
|
+
this.#focusedKey = key
|
|
171
|
+
const proxy = this.#proxyTree.lookup.get(key)
|
|
172
|
+
if (proxy) this.#selectProxy(proxy)
|
|
173
|
+
}
|
|
174
|
+
|
|
170
175
|
/**
|
|
171
176
|
* Toggle expansion of group at path — called by Navigator for accordion-trigger clicks.
|
|
172
177
|
* Unlike select(), this only applies to groups and never fires onselect.
|
|
173
178
|
* No-op when collapsible=false.
|
|
174
179
|
*/
|
|
180
|
+
// eslint-disable-next-line complexity
|
|
175
181
|
toggle(path) {
|
|
176
182
|
if (!this.#collapsible) return
|
|
177
183
|
const key = path ?? this.#focusedKey
|
|
178
|
-
if (
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
if (key) {
|
|
185
|
+
const proxy = this.#proxyTree.lookup.get(key)
|
|
186
|
+
if (proxy?.hasChildren) proxy.expanded = !proxy.expanded
|
|
187
|
+
}
|
|
181
188
|
}
|
|
182
189
|
|
|
183
190
|
/**
|