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

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.13",
4
4
  "description": "Core components, actions and stores for svelte apps.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -6,6 +6,7 @@
6
6
  import Icon from './Icon.svelte'
7
7
  import Text from './items/Text.svelte'
8
8
  import List from './List.svelte'
9
+ import Slider from './Slider.svelte'
9
10
 
10
11
  const dispatch = createEventDispatcher()
11
12
 
@@ -62,10 +63,11 @@
62
63
  {/if}
63
64
  </button>
64
65
  {#if open}
65
- <div
66
+ <!-- <div
66
67
  class="flex flex-col absolute z-10 h-fit w-full menu"
67
68
  style:top="{offsetTop}px"
68
- >
69
+ > -->
70
+ <Slider top={offsetTop}>
69
71
  <List
70
72
  {items}
71
73
  {fields}
@@ -74,6 +76,7 @@
74
76
  on:select={handleSelect}
75
77
  tabindex="-1"
76
78
  />
77
- </div>
79
+ </Slider>
80
+ <!-- </div> -->
78
81
  {/if}
79
82
  </drop-down>
@@ -0,0 +1,31 @@
1
+ <script>
2
+ import TabItems from './TabItems.svelte'
3
+ import TabItem from './TabItem.svelte'
4
+
5
+ let className = ''
6
+ export { className as class }
7
+ export let items = []
8
+ export let fields = {}
9
+ export let title = null
10
+ export let allowAdd = false
11
+ export let allowClose = false
12
+ export let value = items[0]
13
+
14
+ function addTab() {
15
+ items = [...items, {}]
16
+ value = items[items.length - 1]
17
+ }
18
+ </script>
19
+
20
+ <tab-view class="flex flex-col w-full flex-grow {className}">
21
+ <tabs class="flex flex-row flex-shrink-0 w-full select-none cursor-pointer">
22
+ {#if title}
23
+ <p>{title}</p>
24
+ {/if}
25
+ <TabItems {items} {fields} {allowClose} bind:value on:close />
26
+ {#if allowAdd}
27
+ <TabItem label="+" on:click={addTab} />
28
+ {/if}
29
+ </tabs>
30
+ <content class="flex flex-col flex-grow"><slot /></content>
31
+ </tab-view>
@@ -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/Tabs.svelte CHANGED
@@ -1,31 +1,49 @@
1
1
  <script>
2
- import TabItems from './TabItems.svelte'
3
- import TabItem from './TabItem.svelte'
2
+ import { defaultFields } from './constants'
3
+ import { Text } from './items'
4
+ import { navigator } from './actions'
5
+ import { createEventDispatcher } from 'svelte'
6
+
7
+ const dispatch = createEventDispatcher()
4
8
 
5
9
  let className = ''
6
10
  export { className as class }
7
11
  export let items = []
8
12
  export let fields = {}
9
- export let title = null
10
- export let allowAdd = false
11
- export let allowClose = false
12
- export let value = items[0]
13
+ export let using = {}
14
+ export let value = null
15
+ let cursor = []
16
+
17
+ function handleNav(event) {
18
+ value = event.detail.node
19
+ cursor = event.detail.path
13
20
 
14
- function addTab() {
15
- items = [...items, {}]
16
- value = items[items.length - 1]
21
+ dispatch('select', { item: value, indices: cursor })
17
22
  }
23
+ $: fields = { ...defaultFields, ...fields }
24
+ $: using = { default: Text, ...using }
18
25
  </script>
19
26
 
20
- <tab-view class="flex flex-col w-full flex-grow {className}">
21
- <tabs class="flex flex-row flex-shrink-0 w-full select-none cursor-pointer">
22
- {#if title}
23
- <p>{title}</p>
24
- {/if}
25
- <TabItems {items} {fields} {allowClose} bind:value on:close />
26
- {#if allowAdd}
27
- <TabItem label="+" on:click={addTab} />
28
- {/if}
29
- </tabs>
30
- <content class="flex flex-col flex-grow"><slot /></content>
31
- </tab-view>
27
+ <tabs
28
+ class="flex w-full {className}"
29
+ tabindex="0"
30
+ role="listbox"
31
+ use:navigator={{
32
+ items,
33
+ fields,
34
+ vertical: false,
35
+ indices: cursor
36
+ }}
37
+ on:move={handleNav}
38
+ on:select={handleNav}
39
+ >
40
+ {#each items as item, index}
41
+ {@const component = item[fields.component]
42
+ ? using[item[fields.component]] || using.default
43
+ : using.default}
44
+
45
+ <item class="flex" class:is-selected={item === value} data-path={index}>
46
+ <svelte:component this={component} content={item} {fields} />
47
+ </item>
48
+ {/each}
49
+ </tabs>
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>
@@ -2,6 +2,7 @@ export function navigable(
2
2
  node,
3
3
  { horizontal = true, nested = false, enabled = true } = {}
4
4
  ) {
5
+ // console.log(node, enabled)
5
6
  if (!enabled) return { destroy() {} }
6
7
  const previous = () => node.dispatchEvent(new CustomEvent('previous'))
7
8
  const next = () => node.dispatchEvent(new CustomEvent('next'))
@@ -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', {
@@ -12,6 +12,7 @@
12
12
  class="flex flex-row flex-grow gap-2 items-center content"
13
13
  href={content[fields.url]}
14
14
  {target}
15
+ tabindex="-1"
15
16
  >
16
17
  <Text {content} {fields} />
17
18
  </a>