@rokkit/core 1.0.0-next.44 → 1.0.0-next.47
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 +10 -9
- package/src/mapped-list.js +17 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokkit/core",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.47",
|
|
4
4
|
"description": "Core components, actions and stores for svelte apps.",
|
|
5
5
|
"author": "Jerry Thomas <me@jerrythomas.name>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,17 +13,18 @@
|
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@sveltejs/vite-plugin-svelte": "^2.4.
|
|
16
|
+
"@sveltejs/vite-plugin-svelte": "^2.4.5",
|
|
17
17
|
"@testing-library/svelte": "^4.0.3",
|
|
18
|
-
"@
|
|
19
|
-
"@vitest/
|
|
18
|
+
"@types/ramda": "^0.29.3",
|
|
19
|
+
"@vitest/coverage-v8": "^0.34.4",
|
|
20
|
+
"@vitest/ui": "~0.34.4",
|
|
20
21
|
"jsdom": "^22.1.0",
|
|
21
|
-
"svelte": "^4.
|
|
22
|
-
"typescript": "^5.
|
|
22
|
+
"svelte": "^4.2.0",
|
|
23
|
+
"typescript": "^5.2.2",
|
|
23
24
|
"validators": "latest",
|
|
24
|
-
"vite": "^4.4.
|
|
25
|
-
"vitest": "~0.
|
|
26
|
-
"shared-config": "1.0.0-next.
|
|
25
|
+
"vite": "^4.4.9",
|
|
26
|
+
"vitest": "~0.34.4",
|
|
27
|
+
"shared-config": "1.0.0-next.47"
|
|
27
28
|
},
|
|
28
29
|
"files": [
|
|
29
30
|
"src/**/*.js",
|
package/src/mapped-list.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { defaultFields } from './constants'
|
|
1
2
|
import { isExpanded, hasChildren, getAttribute } from './mapping'
|
|
2
3
|
import { equals } from 'ramda'
|
|
3
4
|
/**
|
|
@@ -11,7 +12,7 @@ import { equals } from 'ramda'
|
|
|
11
12
|
export function findItemByValue(
|
|
12
13
|
value,
|
|
13
14
|
items,
|
|
14
|
-
fields,
|
|
15
|
+
fields = defaultFields,
|
|
15
16
|
attr = null,
|
|
16
17
|
position = []
|
|
17
18
|
) {
|
|
@@ -72,12 +73,11 @@ export function findItemByIndexArray(indices, items, fields) {
|
|
|
72
73
|
* @returns
|
|
73
74
|
*/
|
|
74
75
|
export function findNearestItemBefore(position, items, fields) {
|
|
75
|
-
if (position.length == 0) return null
|
|
76
76
|
if (items.length === 0) return null
|
|
77
|
-
if (
|
|
78
|
-
return { item: items[0], position: [0], fields }
|
|
77
|
+
if (position.length === 0) return { item: items[0], position: [0], fields }
|
|
79
78
|
|
|
80
79
|
let index = position[position.length - 1]
|
|
80
|
+
let result
|
|
81
81
|
if (index > 0) {
|
|
82
82
|
index -= 1
|
|
83
83
|
if (position.length == 1) {
|
|
@@ -89,10 +89,15 @@ export function findNearestItemBefore(position, items, fields) {
|
|
|
89
89
|
items,
|
|
90
90
|
fields
|
|
91
91
|
)
|
|
92
|
-
|
|
92
|
+
result = findLastVisibleChild(
|
|
93
|
+
sibling.item,
|
|
94
|
+
sibling.position,
|
|
95
|
+
sibling.fields
|
|
96
|
+
)
|
|
93
97
|
} else {
|
|
94
|
-
|
|
98
|
+
result = findItemByIndexArray(position.slice(0, -1), items, fields)
|
|
95
99
|
}
|
|
100
|
+
return result
|
|
96
101
|
}
|
|
97
102
|
|
|
98
103
|
/**
|
|
@@ -123,18 +128,18 @@ export function findLastVisibleChild(parent, position, fields) {
|
|
|
123
128
|
*/
|
|
124
129
|
export function findNearestItemAfter(position, items, fields) {
|
|
125
130
|
if (items.length === 0) return null
|
|
126
|
-
if (
|
|
127
|
-
return { item: items[0], position: [0], fields }
|
|
131
|
+
if (position.length === 0) return { item: items[0], position: [0], fields }
|
|
128
132
|
|
|
129
133
|
let current = findItemByIndexArray(position, items, fields)
|
|
130
|
-
|
|
134
|
+
let result
|
|
131
135
|
if (isExpanded(current.item, current.fields)) {
|
|
132
|
-
|
|
136
|
+
result = getFirstChild(current, position)
|
|
133
137
|
} else if (position.length === 1) {
|
|
134
|
-
|
|
138
|
+
result = getNextSiblingAtRoot(position, items, fields)
|
|
135
139
|
} else {
|
|
136
|
-
|
|
140
|
+
result = getNextSiblingOrAncestor(position, items, fields)
|
|
137
141
|
}
|
|
142
|
+
return result
|
|
138
143
|
}
|
|
139
144
|
|
|
140
145
|
/**
|
|
@@ -179,7 +184,6 @@ function getNextSiblingAtRoot(position, items, fields) {
|
|
|
179
184
|
function getNextSiblingOrAncestor(position, items, fields) {
|
|
180
185
|
let index = position[position.length - 1]
|
|
181
186
|
let parent = findItemByIndexArray(position.slice(0, -1), items, fields)
|
|
182
|
-
|
|
183
187
|
let children = parent.item[parent.fields.children]
|
|
184
188
|
if (index < children.length - 1) {
|
|
185
189
|
index += 1
|