@rokkit/core 1.0.0-next.11 → 1.0.0-next.12

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/core",
3
- "version": "1.0.0-next.11",
3
+ "version": "1.0.0-next.12",
4
4
  "description": "Core components, actions and stores for svelte apps.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -2,9 +2,9 @@
2
2
  import { Node, Text } from './items'
3
3
  import { defaultFields } from './constants'
4
4
  import { createEventDispatcher } from 'svelte'
5
- import { navigator } from './actions/navigator'
5
+ // import { navigator } from './actions/navigator'
6
6
 
7
- const dispatch = createEventDispatcher()
7
+ // const dispatch = createEventDispatcher()
8
8
 
9
9
  export let items = []
10
10
  export let fields = defaultFields
@@ -15,29 +15,17 @@
15
15
  export let rtl = false
16
16
  export let hierarchy = []
17
17
 
18
- let indices = []
18
+ // let indices = []
19
19
 
20
- function handle(event) {
21
- value = event.detail.node
22
- indices = event.detail.path
23
- if (['collapse', 'expand'].includes(event.type)) {
24
- items = items
25
- }
26
- dispatch(event.type, value)
27
- }
28
- // function handleExpand(event) {
20
+ // function handle(event) {
29
21
  // value = event.detail.node
30
22
  // indices = event.detail.path
31
- // items = items // tell svelte data has changed
32
- // dispatch('expand', value)
33
- // }
34
- // function handleCollapse(event) {
35
- // // console.log(event)
36
- // value = event.detail.node
37
- // indices = event.detail.path
38
- // items = items // tell svelte data has changed
39
- // dispatch('collapse', value)
23
+ // if (['collapse', 'expand'].includes(event.type)) {
24
+ // items = items
25
+ // }
26
+ // dispatch(event.type, value)
40
27
  // }
28
+
41
29
  $: using = { default: Text, ...using }
42
30
  $: fields = { ...defaultFields, ...fields }
43
31
  $: nodeTypes = items.map((_, index) =>
@@ -49,13 +37,15 @@
49
37
  class="flex flex-col w-full"
50
38
  role="listbox"
51
39
  class:rtl
52
- tabindex={hierarchy.length == 0 ? 0 : -1}
40
+ tabindex="-1"
41
+ >
42
+ <!-- tabindex={hierarchy.length == 0 ? 0 : -1}
53
43
  use:navigator={{ items, fields, indices, enabled: hierarchy.length == 0 }}
54
44
  on:select={handle}
55
45
  on:move={handle}
56
46
  on:expand={handle}
57
47
  on:collapse={handle}
58
- >
48
+ > -->
59
49
  {#each items as content, index}
60
50
  {@const type = nodeTypes[index] === 'middle' ? 'line' : 'empty'}
61
51
  {@const hasChildren = fields.children in content}
package/src/Tree.svelte CHANGED
@@ -1,19 +1,45 @@
1
1
  <script>
2
+ import { createEventDispatcher } from 'svelte'
2
3
  import NestedList from './NestedList.svelte'
3
4
  import { Text } from './items'
4
5
  import { defaultFields } from './constants'
6
+ import { navigator } from './actions/navigator'
7
+
8
+ const dispatch = createEventDispatcher()
5
9
 
6
10
  export let items = []
7
11
  export let fields = {}
8
12
  export let using = { default: Text }
9
- export let root = 'root'
13
+ export let root = null
10
14
  export let rtl = false
15
+ export let value
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
+ }
11
27
 
12
28
  $: fields = { ...defaultFields, ...fields }
13
29
  $: items =
14
- items.length == 1
30
+ items.length == 1 || root == null
15
31
  ? items
16
32
  : [{ [fields.text]: root, [fields.children]: items }]
17
33
  </script>
18
34
 
19
- <NestedList {items} {fields} {using} {rtl} />
35
+ <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
36
+ <tree
37
+ use:navigator={{ items, fields, indices }}
38
+ on:select={handle}
39
+ on:move={handle}
40
+ on:expand={handle}
41
+ on:collapse={handle}
42
+ tabindex="0"
43
+ >
44
+ <NestedList {items} {fields} {using} {rtl} {value} />
45
+ </tree>
@@ -119,7 +119,7 @@ export function navigator(node, options) {
119
119
  .filter((item) => item !== '')
120
120
  .map((item) => +item)
121
121
 
122
- if (indices.length > 0) {
122
+ if (indices.length > 0 && event.target.tagName != 'DETAIL') {
123
123
  path = pathFromIndices(indices, items, fields)
124
124
  currentNode = getCurrentNode(path)
125
125
  if (hasChildren(currentNode, path[path.length - 1].fields)) {
@@ -158,7 +158,7 @@ export function moveTo(node, path, currentNode, idPrefix) {
158
158
  const indices = indicesFromPath(path)
159
159
 
160
160
  let current = node.querySelector('#' + idPrefix + indices.join('-'))
161
- if (current) current.scrollIntoView({ behavior: 'auto' })
161
+ if (current) current.scrollIntoView({ behavior: 'smooth', block: 'nearest' })
162
162
 
163
163
  node.dispatchEvent(
164
164
  new CustomEvent('move', {