Skip to content

Commit b2e30ed

Browse files
committed
chore: fix lint issues
1 parent 016686e commit b2e30ed

File tree

5 files changed

+92
-93
lines changed

5 files changed

+92
-93
lines changed

packages/actions/src/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as R from 'ramda'
2020
* @returns {string|null} - The event name or null if no match is found.
2121
*/
2222
export const getEventForKey = (keyMapping, key) => {
23-
// eslint-disable-next-line no-unused-vars
23+
2424
const matchEvent = ([eventName, keys]) =>
2525
(Array.isArray(keys) && keys.includes(key)) || (keys instanceof RegExp && keys.test(key))
2626

packages/atoms/spec/ListItems.spec.svelte.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { describe, expect, it, beforeEach, vi } from 'vitest'
2-
import { cleanup, render, fireEvent } from '@testing-library/svelte'
3-
import { tick } from 'svelte'
1+
import { describe, expect, it, beforeEach } from 'vitest'
2+
import { cleanup, render } from '@testing-library/svelte'
43
import { MockItem } from '@rokkit/helpers/components'
54
import ListItems from '../src/ListItems.svelte'
65
import Item from '../src/Item.svelte'

packages/core/src/key-event-map.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class KeyEventMap {
2626
* @returns {string|null} - The event name or null if no match is found.
2727
*/
2828
getEventForKey(key) {
29-
// eslint-disable-next-line no-unused-vars
29+
3030
const matchEvent = ([_, keys]) =>
3131
(Array.isArray(keys) && keys.includes(key)) || (keys instanceof RegExp && keys.test(key))
3232

packages/state/src/view.svelte.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@ import { equals } from 'ramda'
22
import { FieldMapper } from '@rokkit/core'
33
import { getTree } from './view/tree'
44
import {
5-
getList,
6-
collapse,
7-
collapseAll,
8-
expand,
9-
expandAll,
10-
moveByOffset,
11-
moveTo,
12-
select,
13-
selectAll,
14-
selectRange,
15-
toggleExpansion,
16-
toggleSelection,
17-
unselect,
18-
unselectAll,
19-
invertSelection
5+
getList
6+
// collapse,
7+
// collapseAll,
8+
// expand,
9+
// expandAll,
10+
// moveByOffset,
11+
// moveTo,
12+
// select,
13+
// selectAll,
14+
// selectRange,
15+
// toggleExpansion,
16+
// toggleSelection,
17+
// unselect,
18+
// unselectAll,
19+
// invertSelection
2020
} from './view/primitives'
2121

22-
/**
23-
* Gets the current item from the view store.
24-
*
25-
* @param {import('svelte/store').Writable} view - the view store.
26-
* @returns {Object} The current item.
27-
*/
28-
function getCurrentItem(view) {
29-
const state = get(view)
30-
const currentItem =
31-
state.data.length > 0 && state.currentIndex >= 0 ? state.data[state.currentIndex] : null
32-
return currentItem
33-
}
22+
// /**
23+
// * Gets the current item from the view store.
24+
// *
25+
// * @param {import('svelte/store').Writable} view - the view store.
26+
// * @returns {Object} The current item.
27+
// */
28+
// function getCurrentItem(view) {
29+
// const state = get(view)
30+
// const currentItem =
31+
// state.data.length > 0 && state.currentIndex >= 0 ? state.data[state.currentIndex] : null
32+
// return currentItem
33+
// }
3434

3535
/**
3636
* Validates the index.

packages/state/src/view/primitives.js

+61-61
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
import { equals, has } from 'ramda'
2+
3+
/**
4+
* Add an event to the event stack
5+
* @param {Object} state
6+
* @param {Object} event
7+
* @param {Number} index
8+
* @returns {Object} The updated state.
9+
*/
10+
export function addEvent(state, event, index = -1) {
11+
// state.events = state.events ?? []
12+
13+
if (event === 'select') {
14+
const detail = state.selectedItems.map((i) => state.data[i].value)
15+
state.events.push({ type: event, detail })
16+
} else if (event === 'move' || index > -1) {
17+
const { value = null, indexPath = null } = index >= 0 ? state.data[index] : {}
18+
state.events.push({ type: event, detail: { value, path: indexPath } })
19+
}
20+
}
21+
222
/**
323
* Creates a list view data store using the given items.
424
*
@@ -191,6 +211,47 @@ export function selectRange(state, offset) {
191211
return state
192212
}
193213

214+
/**
215+
* Recursively update visibility for all children of the given parent
216+
* based on the parent's expanded state. Stops recursion if a child's expanded
217+
* state does not match the parent's state.
218+
*
219+
* @param {Array} children - The children of the parent to update visibility for.
220+
* @param {Boolean} isVisible - Indicates whether children should be visible or hidden.
221+
*/
222+
function updateChildVisibility(children, isVisible) {
223+
children.forEach((child) => {
224+
// Update visibility only if child's expanded state mismatches with the desired visibility
225+
if (child.isExpanded === isVisible) {
226+
child.isHidden = !isVisible // Update based on parent's state
227+
if (child.children) {
228+
updateChildVisibility(child.children, isVisible) // Recursive call for further children
229+
}
230+
}
231+
})
232+
}
233+
234+
/**
235+
* Toggles the expansion of the item at the given index.
236+
*
237+
* @param {Object} state
238+
* @param {Number} index
239+
* @param {Boolean} expand - the state
240+
* @param {Boolean} events - Whether to emit event
241+
* @returns {Object} The updated state.
242+
*/
243+
function toggle(state, index, events = true) {
244+
const item = state.data[index]
245+
item.isExpanded = !item.isExpanded
246+
247+
updateChildVisibility(item.children, item.isExpanded)
248+
if (events) {
249+
const event = item.isExpanded ? 'expand' : 'collapse'
250+
addEvent(state, event, index)
251+
}
252+
return state
253+
}
254+
194255
/**
195256
* Expands the item at the given index.
196257
*
@@ -230,28 +291,6 @@ export function collapse(state, pathIndex, emit = true) {
230291

231292
return state
232293
}
233-
234-
/**
235-
* Toggles the expansion of the item at the given index.
236-
*
237-
* @param {Object} state
238-
* @param {Number} index
239-
* @param {Boolean} expand - the state
240-
* @param {Boolean} events - Whether to emit event
241-
* @returns {Object} The updated state.
242-
*/
243-
function toggle(state, index, events = true) {
244-
const item = state.data[index]
245-
item.isExpanded = !item.isExpanded
246-
247-
updateChildVisibility(item.children, item.isExpanded)
248-
if (events) {
249-
const event = item.isExpanded ? 'expand' : 'collapse'
250-
addEvent(state, event, index)
251-
}
252-
return state
253-
}
254-
255294
/**
256295
* Toggles the expansion of the item at the given index.
257296
*
@@ -294,42 +333,3 @@ export function collapseAll(state) {
294333
addEvent(state, 'collapse')
295334
return state
296335
}
297-
298-
/**
299-
* Recursively update visibility for all children of the given parent
300-
* based on the parent's expanded state. Stops recursion if a child's expanded
301-
* state does not match the parent's state.
302-
*
303-
* @param {Array} children - The children of the parent to update visibility for.
304-
* @param {Boolean} isVisible - Indicates whether children should be visible or hidden.
305-
*/
306-
function updateChildVisibility(children, isVisible) {
307-
children.forEach((child) => {
308-
// Update visibility only if child's expanded state mismatches with the desired visibility
309-
if (child.isExpanded === isVisible) {
310-
child.isHidden = !isVisible // Update based on parent's state
311-
if (child.children) {
312-
updateChildVisibility(child.children, isVisible) // Recursive call for further children
313-
}
314-
}
315-
})
316-
}
317-
318-
/**
319-
* Add an event to the event stack
320-
* @param {Object} state
321-
* @param {Object} event
322-
* @param {Number} index
323-
* @returns {Object} The updated state.
324-
*/
325-
export function addEvent(state, event, index = -1) {
326-
// state.events = state.events ?? []
327-
328-
if (event === 'select') {
329-
const detail = state.selectedItems.map((i) => state.data[i].value)
330-
state.events.push({ type: event, detail })
331-
} else if (event === 'move' || index > -1) {
332-
const { value = null, indexPath = null } = index >= 0 ? state.data[index] : {}
333-
state.events.push({ type: event, detail: { value, path: indexPath } })
334-
}
335-
}

0 commit comments

Comments
 (0)