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

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.145",
3
+ "version": "1.0.0-next.146",
4
4
  "description": "Contains generic data manipulation functions that can be used in various components.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,46 @@
1
+ class AlertsStore {
2
+ /** @type {Array<{id: string, type: string, text?: string, dismissible: boolean, timeout: number, actions?: unknown}>} */
3
+ #items = $state([])
4
+ /** @type {Map<string, ReturnType<typeof setTimeout>>} */
5
+ #timers = new Map()
6
+
7
+ get current() {
8
+ return this.#items
9
+ }
10
+
11
+ /**
12
+ * Push a new alert. Returns the alert id.
13
+ * @param {{ type?: string, text?: string, dismissible?: boolean, timeout?: number, actions?: unknown }} alert
14
+ * @returns {string}
15
+ */
16
+ push({ type = 'info', text, dismissible = false, timeout = dismissible ? 0 : 4000, actions } = {}) {
17
+ const id = crypto.randomUUID()
18
+ this.#items = [...this.#items, { id, type, text, dismissible, timeout, actions }]
19
+ if (timeout > 0) {
20
+ const timer = setTimeout(() => this.dismiss(id), timeout)
21
+ this.#timers.set(id, timer)
22
+ }
23
+ return id
24
+ }
25
+
26
+ /**
27
+ * Dismiss an alert by id, cancelling its timer if any.
28
+ * @param {string} id
29
+ */
30
+ dismiss(id) {
31
+ clearTimeout(this.#timers.get(id))
32
+ this.#timers.delete(id)
33
+ this.#items = this.#items.filter((a) => a.id !== id)
34
+ }
35
+
36
+ /**
37
+ * Clear all alerts and cancel all timers.
38
+ */
39
+ clear() {
40
+ for (const timer of this.#timers.values()) clearTimeout(timer)
41
+ this.#timers.clear()
42
+ this.#items = []
43
+ }
44
+ }
45
+
46
+ export const alerts = new AlertsStore()
@@ -25,7 +25,9 @@ function visitNode(data, ctx) {
25
25
  const hasChildren = Array.isArray(item[fields.children]) && item[fields.children].length > 0
26
26
  data.push({ key, value: item, level, hasChildren })
27
27
  if (isExpanded(item, fields, key, expandedKeys)) {
28
- data.push(...flatVisibleNodes(item[fields.children], getNestedFields(fields), itemPath, expandedKeys))
28
+ data.push(
29
+ ...flatVisibleNodes(item[fields.children], getNestedFields(fields), itemPath, expandedKeys)
30
+ )
29
31
  }
30
32
  }
31
33
 
package/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { alerts } from './alerts.svelte.js'
1
2
  export { TableController } from './table-controller.svelte.js'
2
3
  export { vibe } from './vibe.svelte.js'
3
4
  export { ListController } from './list-controller.svelte.js'
@@ -281,7 +281,11 @@ export class ListController {
281
281
  const indices = this.#findRangeIndices(anchorKey, key)
282
282
  if (!indices) return false
283
283
  const { anchorIndex, targetIndex } = indices
284
- this.#selectIndexRange(Math.min(anchorIndex, targetIndex), Math.max(anchorIndex, targetIndex), targetIndex)
284
+ this.#selectIndexRange(
285
+ Math.min(anchorIndex, targetIndex),
286
+ Math.max(anchorIndex, targetIndex),
287
+ targetIndex
288
+ )
285
289
  return true
286
290
  }
287
291
 
@@ -74,7 +74,15 @@ function visitProxy(result, proxy, parentLineTypes, position) {
74
74
  const hasChildren = children.length > 0
75
75
  const isExpandable = hasChildren || proxy.get('children') === true // sentinel: lazy-loadable
76
76
  const lineTypes = computeLineTypes(parentLineTypes, position, isExpandable)
77
- result.push({ key: proxy.key, proxy, level: proxy.level, hasChildren, isExpandable, type: proxy.type, lineTypes })
77
+ result.push({
78
+ key: proxy.key,
79
+ proxy,
80
+ level: proxy.level,
81
+ hasChildren,
82
+ isExpandable,
83
+ type: proxy.type,
84
+ lineTypes
85
+ })
78
86
  if (hasChildren && proxy.expanded) {
79
87
  result.push(...buildReactiveFlatView(children, lineTypes))
80
88
  }