@rokkit/core 1.0.0-next.32 → 1.0.0-next.34
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 +13 -11
- package/src/ListActions.svelte +1 -1
- package/src/NestedPaginator.svelte +3 -4
- package/src/PageNavigator.svelte +2 -2
- package/src/ResponsiveGrid.svelte +1 -2
- package/src/SpinList.svelte +5 -5
- package/src/SplitPane.svelte +1 -1
- package/src/Splitter.svelte +1 -1
- package/src/TabItems.svelte +1 -1
- package/src/index.js +15 -15
- package/src/Accordion.svelte +0 -80
- package/src/Alerts.svelte +0 -39
- package/src/BreadCrumbs.svelte +0 -34
- package/src/DropDown.svelte +0 -82
- package/src/DropSearch.svelte +0 -67
- package/src/Icon.svelte +0 -38
- package/src/List.svelte +0 -66
- package/src/NestedList.svelte +0 -59
- package/src/Slider.svelte +0 -17
- package/src/Switch.svelte +0 -69
- package/src/Tabs.svelte +0 -82
- package/src/Tree.svelte +0 -52
- package/src/actions/dismissable.js +0 -24
- package/src/actions/fillable.js +0 -114
- package/src/actions/hierarchy.js +0 -180
- package/src/actions/index.js +0 -7
- package/src/actions/navigable.js +0 -42
- package/src/actions/navigator.js +0 -179
- package/src/actions/pannable.js +0 -57
- package/src/actions/swipeable.js +0 -55
- package/src/actions/themeable.js +0 -23
- package/src/constants.js +0 -95
- package/src/items/Connector.svelte +0 -28
- package/src/items/Item.svelte +0 -29
- package/src/items/ItemWrapper.svelte +0 -47
- package/src/items/Link.svelte +0 -18
- package/src/items/Node.svelte +0 -47
- package/src/items/Separator.svelte +0 -1
- package/src/items/Summary.svelte +0 -27
- package/src/items/index.js +0 -7
- package/src/lib/connector.js +0 -12
- package/src/lib/index.js +0 -7
- package/src/lib/nested.js +0 -45
- package/src/list.js +0 -14
- package/src/mocks/Custom.svelte +0 -6
- package/src/mocks/index.js +0 -17
- package/src/stores/alerts.js +0 -2
- package/src/stores/index.js +0 -6
- package/src/stores/persist.js +0 -63
- package/src/stores/theme.js +0 -34
package/src/Switch.svelte
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { createEventDispatcher } from 'svelte'
|
|
3
|
-
import { defaultFields } from './constants'
|
|
4
|
-
import { Item } from './items'
|
|
5
|
-
import { navigator } from './actions'
|
|
6
|
-
import { getComponent } from './lib'
|
|
7
|
-
|
|
8
|
-
const dispatch = createEventDispatcher()
|
|
9
|
-
|
|
10
|
-
let className = ''
|
|
11
|
-
export { className as class }
|
|
12
|
-
export let items = [false, true]
|
|
13
|
-
export let fields = defaultFields
|
|
14
|
-
export let using = {}
|
|
15
|
-
export let compact = true
|
|
16
|
-
export let value
|
|
17
|
-
let cursor = []
|
|
18
|
-
|
|
19
|
-
function handleNav(event) {
|
|
20
|
-
value = event.detail.node
|
|
21
|
-
cursor = event.detail.path
|
|
22
|
-
|
|
23
|
-
dispatch('change', { item: value, indices: cursor })
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
$: useComponent = !items.every((item) => [false, true].includes(item))
|
|
27
|
-
$: fields = { ...defaultFields, ...fields }
|
|
28
|
-
$: using = { default: Item, ...using }
|
|
29
|
-
</script>
|
|
30
|
-
|
|
31
|
-
{#if !Array.isArray(items) || items.length < 2}
|
|
32
|
-
<error>Items should be an array with at least two items.</error>
|
|
33
|
-
{:else}
|
|
34
|
-
<toggle-switch
|
|
35
|
-
class="flex items-center {className}"
|
|
36
|
-
class:is-off={items.length == 2 && value === items[0]}
|
|
37
|
-
class:is-on={items.length == 2 && value === items[1]}
|
|
38
|
-
class:compact
|
|
39
|
-
tabindex="0"
|
|
40
|
-
role="listbox"
|
|
41
|
-
use:navigator={{
|
|
42
|
-
items,
|
|
43
|
-
fields,
|
|
44
|
-
vertical: false,
|
|
45
|
-
indices: cursor
|
|
46
|
-
}}
|
|
47
|
-
on:move={handleNav}
|
|
48
|
-
on:select={handleNav}
|
|
49
|
-
>
|
|
50
|
-
{#each items as item, index (item)}
|
|
51
|
-
{@const component = useComponent
|
|
52
|
-
? getComponent(item, fields, using)
|
|
53
|
-
: null}
|
|
54
|
-
<item
|
|
55
|
-
class="relative flex"
|
|
56
|
-
role="option"
|
|
57
|
-
aria-selected={item === value}
|
|
58
|
-
data-path={index}
|
|
59
|
-
>
|
|
60
|
-
{#if item == value}
|
|
61
|
-
<indicator class="absolute bottom-0 left-0 right-0 top-0" />
|
|
62
|
-
{/if}
|
|
63
|
-
{#if component}
|
|
64
|
-
<svelte:component this={component} value={item} {fields} />
|
|
65
|
-
{/if}
|
|
66
|
-
</item>
|
|
67
|
-
{/each}
|
|
68
|
-
</toggle-switch>
|
|
69
|
-
{/if}
|
package/src/Tabs.svelte
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { defaultFields, defaultStateIcons } from './constants'
|
|
3
|
-
import Icon from './Icon.svelte'
|
|
4
|
-
import { ItemWrapper, Item } from './items'
|
|
5
|
-
import { navigator } from './actions'
|
|
6
|
-
import { createEventDispatcher } from 'svelte'
|
|
7
|
-
|
|
8
|
-
const dispatch = createEventDispatcher()
|
|
9
|
-
|
|
10
|
-
let className = ''
|
|
11
|
-
export { className as class }
|
|
12
|
-
export let items = []
|
|
13
|
-
export let fields = {}
|
|
14
|
-
export let using
|
|
15
|
-
export let value = null
|
|
16
|
-
export let below = false
|
|
17
|
-
export let align = 'left'
|
|
18
|
-
export let editable = false
|
|
19
|
-
export let icons = defaultStateIcons.action
|
|
20
|
-
|
|
21
|
-
let cursor = []
|
|
22
|
-
|
|
23
|
-
function handleRemove(item) {
|
|
24
|
-
if (typeof item === Object) {
|
|
25
|
-
item[fields.isDeleted] = true
|
|
26
|
-
} else {
|
|
27
|
-
items = items.filter((i) => i !== item)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
dispatch('remove', { item })
|
|
31
|
-
}
|
|
32
|
-
function handleNav(event) {
|
|
33
|
-
value = event.detail.node
|
|
34
|
-
cursor = event.detail.path
|
|
35
|
-
|
|
36
|
-
dispatch('select', { item: value, indices: cursor })
|
|
37
|
-
}
|
|
38
|
-
$: using = { default: Item, ...using }
|
|
39
|
-
$: icons = { ...defaultStateIcons.action, ...icons }
|
|
40
|
-
$: filtered = items.filter((item) => !item[fields.isDeleted])
|
|
41
|
-
$: fields = { ...defaultFields, ...fields }
|
|
42
|
-
</script>
|
|
43
|
-
|
|
44
|
-
<tabs
|
|
45
|
-
class="flex w-full {className}"
|
|
46
|
-
class:is-below={below}
|
|
47
|
-
class:justify-center={align == 'center'}
|
|
48
|
-
class:justify-end={align == 'right'}
|
|
49
|
-
tabindex="0"
|
|
50
|
-
role="listbox"
|
|
51
|
-
use:navigator={{
|
|
52
|
-
items,
|
|
53
|
-
fields,
|
|
54
|
-
vertical: false,
|
|
55
|
-
indices: cursor
|
|
56
|
-
}}
|
|
57
|
-
on:move={handleNav}
|
|
58
|
-
on:select={handleNav}
|
|
59
|
-
>
|
|
60
|
-
{#each filtered as item, index}
|
|
61
|
-
<ItemWrapper
|
|
62
|
-
value={item}
|
|
63
|
-
{index}
|
|
64
|
-
{fields}
|
|
65
|
-
{using}
|
|
66
|
-
removable={editable}
|
|
67
|
-
selected={item === value}
|
|
68
|
-
{icons}
|
|
69
|
-
class="tab"
|
|
70
|
-
on:remove={handleRemove}
|
|
71
|
-
/>
|
|
72
|
-
{/each}
|
|
73
|
-
{#if editable}
|
|
74
|
-
<Icon
|
|
75
|
-
name="add"
|
|
76
|
-
role="button"
|
|
77
|
-
label="Add Tab"
|
|
78
|
-
size="small"
|
|
79
|
-
on:click={() => dispatch('add')}
|
|
80
|
-
/>
|
|
81
|
-
{/if}
|
|
82
|
-
</tabs>
|
package/src/Tree.svelte
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { createEventDispatcher } from 'svelte'
|
|
3
|
-
import NestedList from './NestedList.svelte'
|
|
4
|
-
import { Item } from './items'
|
|
5
|
-
import { defaultFields } from './constants'
|
|
6
|
-
import { navigator } from './actions/navigator'
|
|
7
|
-
|
|
8
|
-
const dispatch = createEventDispatcher()
|
|
9
|
-
let className = 'list'
|
|
10
|
-
export { className as class }
|
|
11
|
-
export let items = []
|
|
12
|
-
export let fields = {}
|
|
13
|
-
export let using = { default: Item }
|
|
14
|
-
export let root = null
|
|
15
|
-
export let value = null
|
|
16
|
-
|
|
17
|
-
let indices = []
|
|
18
|
-
|
|
19
|
-
function handle(event) {
|
|
20
|
-
value = event.detail.node
|
|
21
|
-
indices = event.detail.path
|
|
22
|
-
if (['collapse', 'expand'].includes(event.type)) {
|
|
23
|
-
items = items
|
|
24
|
-
}
|
|
25
|
-
dispatch(event.type, value)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
$: fields = { ...defaultFields, ...fields }
|
|
29
|
-
$: items =
|
|
30
|
-
items[0][fields.text] == root || root == null
|
|
31
|
-
? items
|
|
32
|
-
: [
|
|
33
|
-
{
|
|
34
|
-
[fields.text]: root,
|
|
35
|
-
[fields.isOpen]: true,
|
|
36
|
-
[fields.children]: items
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
</script>
|
|
40
|
-
|
|
41
|
-
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
42
|
-
<tree
|
|
43
|
-
use:navigator={{ items, fields, indices }}
|
|
44
|
-
on:select={handle}
|
|
45
|
-
on:move={handle}
|
|
46
|
-
on:expand={handle}
|
|
47
|
-
on:collapse={handle}
|
|
48
|
-
tabindex="0"
|
|
49
|
-
class={className}
|
|
50
|
-
>
|
|
51
|
-
<NestedList {items} {fields} {using} bind:value {...$$restProps} />
|
|
52
|
-
</tree>
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const KEYCODE_ESC = 27
|
|
2
|
-
|
|
3
|
-
export function dismissable(node) {
|
|
4
|
-
const handleClick = (event) => {
|
|
5
|
-
if (node && !node.contains(event.target) && !event.defaultPrevented) {
|
|
6
|
-
node.dispatchEvent(new CustomEvent('dismiss', node))
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
const keyup = (event) => {
|
|
10
|
-
if (event.keyCode === KEYCODE_ESC) {
|
|
11
|
-
node.dispatchEvent(new CustomEvent('dismiss', node))
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
document.addEventListener('click', handleClick, true)
|
|
16
|
-
document.addEventListener('keyup', keyup, true)
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
destroy() {
|
|
20
|
-
document.removeEventListener('click', handleClick, true)
|
|
21
|
-
document.removeEventListener('keyup', keyup, true)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/actions/fillable.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef FillOptions
|
|
3
|
-
* @property {Array<string>} options available options to fill
|
|
4
|
-
* @property {integer} current index of option to be filled
|
|
5
|
-
* @property {boolean} check validate filled values
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Action for filling a <del>?</del> element in html block.
|
|
9
|
-
*
|
|
10
|
-
* @param {*} node
|
|
11
|
-
* @param {FillOptions} options
|
|
12
|
-
* @returns
|
|
13
|
-
*/
|
|
14
|
-
export function fillable(node, { options, current, check }) {
|
|
15
|
-
let data = { options, current, check }
|
|
16
|
-
let blanks = node.getElementsByTagName('del')
|
|
17
|
-
|
|
18
|
-
function click(event) {
|
|
19
|
-
if ('?' !== event.target.innerHTML) {
|
|
20
|
-
clear(event, node)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
initialize(blanks, click)
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
update({ options, current }) {
|
|
28
|
-
data.options = options
|
|
29
|
-
data.current = current
|
|
30
|
-
data.check = check
|
|
31
|
-
|
|
32
|
-
fill(blanks, data.options, data.current)
|
|
33
|
-
if (data.check) validate(blanks, data)
|
|
34
|
-
},
|
|
35
|
-
destroy() {
|
|
36
|
-
Object.keys(blanks).map((ref) => {
|
|
37
|
-
blanks[ref].removeEventListener('click', click)
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Initialize empty fillable element style and add listener for click
|
|
45
|
-
*
|
|
46
|
-
* @param {*} blanks
|
|
47
|
-
* @param {*} click
|
|
48
|
-
*/
|
|
49
|
-
function initialize(blanks, click) {
|
|
50
|
-
Object.keys(blanks).map((ref) => {
|
|
51
|
-
blanks[ref].addEventListener('click', click)
|
|
52
|
-
blanks[ref].classList.add('empty')
|
|
53
|
-
blanks[ref].name = 'fill-' + ref
|
|
54
|
-
blanks[ref]['data-index'] = ref
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Fill current blank with provided option
|
|
60
|
-
*
|
|
61
|
-
* @param {*} blanks
|
|
62
|
-
* @param {*} options
|
|
63
|
-
* @param {*} current
|
|
64
|
-
*/
|
|
65
|
-
function fill(blanks, options, current) {
|
|
66
|
-
if (current > -1 && current < Object.keys(blanks).length) {
|
|
67
|
-
let index = options.findIndex(({ actualIndex }) => actualIndex == current)
|
|
68
|
-
if (index > -1) {
|
|
69
|
-
blanks[current].innerHTML = options[index].value
|
|
70
|
-
blanks[current].classList.remove('empty')
|
|
71
|
-
blanks[current].classList.add('filled')
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Clear all fillable elements
|
|
78
|
-
*
|
|
79
|
-
* @param {*} event
|
|
80
|
-
* @param {*} node
|
|
81
|
-
*/
|
|
82
|
-
function clear(event, node) {
|
|
83
|
-
event.target.innerHTML = '?'
|
|
84
|
-
event.target.classList.remove('filled')
|
|
85
|
-
event.target.classList.remove('pass')
|
|
86
|
-
event.target.classList.remove('fail')
|
|
87
|
-
event.target.classList.add('empty')
|
|
88
|
-
node.dispatchEvent(
|
|
89
|
-
new CustomEvent('remove', {
|
|
90
|
-
detail: {
|
|
91
|
-
index: event.target.name.split('-')[1],
|
|
92
|
-
value: event.target['data-index']
|
|
93
|
-
}
|
|
94
|
-
})
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Validate the filled values
|
|
100
|
-
*
|
|
101
|
-
* @param {*} blanks
|
|
102
|
-
* @param {*} data
|
|
103
|
-
*/
|
|
104
|
-
function validate(blanks, data) {
|
|
105
|
-
Object.keys(blanks).map((ref) => {
|
|
106
|
-
let index = data.options.findIndex(({ actualIndex }) => actualIndex == ref)
|
|
107
|
-
if (index > -1)
|
|
108
|
-
blanks[ref].classList.add(
|
|
109
|
-
data.options[index].expectedIndex == data.options[index].actualIndex
|
|
110
|
-
? 'pass'
|
|
111
|
-
: 'fail'
|
|
112
|
-
)
|
|
113
|
-
})
|
|
114
|
-
}
|
package/src/actions/hierarchy.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A part of the path to node in hierarchy
|
|
3
|
-
*
|
|
4
|
-
* @typedef PathFragment
|
|
5
|
-
* @property {integer} index - Index to item in array
|
|
6
|
-
* @property {Array<*>} items - Array of items
|
|
7
|
-
* @property {import('../constants').FieldMapping} fields - Field mapping for the data
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Check if the current item is a parent
|
|
12
|
-
*
|
|
13
|
-
* @param {*} item
|
|
14
|
-
* @param {import('../constants').FieldMapping} fields
|
|
15
|
-
* @returns {boolean}
|
|
16
|
-
*/
|
|
17
|
-
export function hasChildren(item, fields) {
|
|
18
|
-
return (
|
|
19
|
-
typeof item === 'object' &&
|
|
20
|
-
fields.children in item &&
|
|
21
|
-
Array.isArray(item[fields.children])
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Check if the current item is a parent and is expanded
|
|
27
|
-
*
|
|
28
|
-
* @param {*} item
|
|
29
|
-
* @param {import('../constants').FieldMapping} fields
|
|
30
|
-
* @returns {boolean}
|
|
31
|
-
*/
|
|
32
|
-
export function isExpanded(item, fields) {
|
|
33
|
-
if (item == null) return false
|
|
34
|
-
if (!hasChildren(item, fields)) return false
|
|
35
|
-
if (fields.isOpen in item) {
|
|
36
|
-
return item[fields.isOpen]
|
|
37
|
-
}
|
|
38
|
-
return false
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Verify if at least one item has children
|
|
43
|
-
*
|
|
44
|
-
* @param {Array<*>} items
|
|
45
|
-
* @param {import('../constants').FieldMapping} fields
|
|
46
|
-
* @returns {boolean}
|
|
47
|
-
*/
|
|
48
|
-
export function isNested(items, fields) {
|
|
49
|
-
for (let i = 0; i < items.length; i++) {
|
|
50
|
-
if (hasChildren(items[i], fields)) return true
|
|
51
|
-
}
|
|
52
|
-
return false
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Navigate to last visible child in the hirarchy starting with the provided path
|
|
57
|
-
*
|
|
58
|
-
* @param {Array<PathFragment>} path - path to a node in the hierarchy
|
|
59
|
-
* @returns
|
|
60
|
-
*/
|
|
61
|
-
export function navigateToLastVisibleChild(path) {
|
|
62
|
-
let current = path[path.length - 1]
|
|
63
|
-
// console.log(current)
|
|
64
|
-
while (isExpanded(current.items[current.index], current.fields)) {
|
|
65
|
-
const items = current.items[current.index][current.fields.children]
|
|
66
|
-
const level = {
|
|
67
|
-
items,
|
|
68
|
-
index: items.length - 1,
|
|
69
|
-
fields: current.fields.fields ?? current.fields
|
|
70
|
-
}
|
|
71
|
-
path.push(level)
|
|
72
|
-
current = level
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return path
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Navigate to the next item
|
|
80
|
-
*
|
|
81
|
-
* @param {Array<PathFragment>} path - path to a node in the hierarchy
|
|
82
|
-
* @param {Array<*>} items - array of items
|
|
83
|
-
* @param {import('../constants').FieldMapping} fields - field mapping
|
|
84
|
-
* @returns
|
|
85
|
-
*/
|
|
86
|
-
export function moveNext(path, items, fields) {
|
|
87
|
-
if (path.length === 0) {
|
|
88
|
-
return [{ index: 0, items, fields }]
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const current = path[path.length - 1]
|
|
92
|
-
if (isExpanded(current.items[current.index], current.fields)) {
|
|
93
|
-
path.push({
|
|
94
|
-
items: current.items[current.index][current.fields.children],
|
|
95
|
-
index: 0,
|
|
96
|
-
fields: current.fields.fields || current.fields
|
|
97
|
-
})
|
|
98
|
-
} else if (current.index < current.items.length - 1) {
|
|
99
|
-
current.index++
|
|
100
|
-
} else {
|
|
101
|
-
let level = path.length - 2
|
|
102
|
-
while (level >= 0) {
|
|
103
|
-
const parent = path[level]
|
|
104
|
-
if (parent.index < parent.items.length - 1) {
|
|
105
|
-
parent.index++
|
|
106
|
-
path = path.slice(0, level + 1)
|
|
107
|
-
break
|
|
108
|
-
}
|
|
109
|
-
level--
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return path
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Navigate to the previous item
|
|
117
|
-
*
|
|
118
|
-
* @param {Array<PathFragment>} path - path to a node in the hierarchy
|
|
119
|
-
* @returns
|
|
120
|
-
*/
|
|
121
|
-
export function movePrevious(path) {
|
|
122
|
-
if (path.length === 0) return []
|
|
123
|
-
|
|
124
|
-
const current = path[path.length - 1]
|
|
125
|
-
|
|
126
|
-
if (current.index == 0) {
|
|
127
|
-
if (path.length > 1) path.pop()
|
|
128
|
-
return path
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
current.index--
|
|
132
|
-
if (isExpanded(current.items[current.index], current.fields)) {
|
|
133
|
-
return navigateToLastVisibleChild(path)
|
|
134
|
-
}
|
|
135
|
-
return path
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
*
|
|
140
|
-
* @param {Array<integer>} indices
|
|
141
|
-
* @param {Array<*>} items
|
|
142
|
-
* @param {import('../constants').FieldMapping} fields
|
|
143
|
-
* @returns
|
|
144
|
-
*/
|
|
145
|
-
export function pathFromIndices(indices, items, fields) {
|
|
146
|
-
let path = []
|
|
147
|
-
let fragment
|
|
148
|
-
indices.map((index, level) => {
|
|
149
|
-
if (level === 0) {
|
|
150
|
-
fragment = { index, items, fields }
|
|
151
|
-
} else {
|
|
152
|
-
fragment = {
|
|
153
|
-
index,
|
|
154
|
-
items: fragment.items[fragment.index][fragment.fields.children],
|
|
155
|
-
fields: fragment.fields.fields ?? fragment.fields
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
path.push(fragment)
|
|
159
|
-
})
|
|
160
|
-
return path
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function indicesFromPath(path) {
|
|
164
|
-
return path.map(({ index }) => index)
|
|
165
|
-
}
|
|
166
|
-
export function getCurrentNode(path) {
|
|
167
|
-
if (path.length === 0) return null
|
|
168
|
-
const lastIndex = path.length - 1
|
|
169
|
-
return path[lastIndex].items[path[lastIndex].index]
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function findItem(items, indices, fields) {
|
|
173
|
-
let item = items[indices[0]]
|
|
174
|
-
let levelFields = fields
|
|
175
|
-
for (let level = 1; level < indices.length; level++) {
|
|
176
|
-
item = item[levelFields.children][indices[level]]
|
|
177
|
-
levelFields = levelFields.fields ?? levelFields
|
|
178
|
-
}
|
|
179
|
-
return item
|
|
180
|
-
}
|
package/src/actions/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { fillable } from './fillable'
|
|
2
|
-
export { pannable } from './pannable'
|
|
3
|
-
export { navigable } from './navigable'
|
|
4
|
-
export { navigator } from './navigator'
|
|
5
|
-
export { dismissable } from './dismissable'
|
|
6
|
-
export { themable } from './themeable'
|
|
7
|
-
export { swipeable } from './swipeable'
|
package/src/actions/navigable.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export function navigable(
|
|
2
|
-
node,
|
|
3
|
-
{ horizontal = true, nested = false, enabled = true } = {}
|
|
4
|
-
) {
|
|
5
|
-
if (!enabled) return { destroy() {} }
|
|
6
|
-
const previous = () => node.dispatchEvent(new CustomEvent('previous'))
|
|
7
|
-
const next = () => node.dispatchEvent(new CustomEvent('next'))
|
|
8
|
-
const collapse = () => node.dispatchEvent(new CustomEvent('collapse'))
|
|
9
|
-
const expand = () => node.dispatchEvent(new CustomEvent('expand'))
|
|
10
|
-
const select = () => node.dispatchEvent(new CustomEvent('select'))
|
|
11
|
-
|
|
12
|
-
const movement = horizontal
|
|
13
|
-
? { ArrowLeft: previous, ArrowRight: next }
|
|
14
|
-
: { ArrowUp: previous, ArrowDown: next }
|
|
15
|
-
const change = nested
|
|
16
|
-
? horizontal
|
|
17
|
-
? { ArrowUp: collapse, ArrowDown: expand }
|
|
18
|
-
: { ArrowLeft: collapse, ArrowRight: expand }
|
|
19
|
-
: {}
|
|
20
|
-
const actions = {
|
|
21
|
-
Enter: select,
|
|
22
|
-
' ': select,
|
|
23
|
-
...movement,
|
|
24
|
-
...change
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function handleKeydown(event) {
|
|
28
|
-
if (actions[event.key]) {
|
|
29
|
-
event.preventDefault()
|
|
30
|
-
event.stopPropagation()
|
|
31
|
-
actions[event.key]()
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
node.addEventListener('keydown', handleKeydown)
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
destroy() {
|
|
39
|
-
node.removeEventListener('keydown', handleKeydown)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|