@rokkit/core 1.0.0-next.20 → 1.0.0-next.21

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.20",
3
+ "version": "1.0.0-next.21",
4
4
  "description": "Core components, actions and stores for svelte apps.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "svelte": "^3.58.0",
26
26
  "typescript": "^4.9.5",
27
27
  "validators": "latest",
28
- "vite": "^4.3.3",
28
+ "vite": "^4.3.4",
29
29
  "vitest": "~0.19.1",
30
30
  "shared-config": "1.0.0"
31
31
  },
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { Node, Text } from './items'
3
- import { defaultFields } from './constants'
3
+ import { defaultFields, defaultStateIcons } from './constants'
4
4
  import { getLineTypes } from './lib/connector'
5
5
 
6
6
  let className = 'list'
@@ -10,26 +10,16 @@
10
10
  export let using = {}
11
11
  export let types = []
12
12
  export let value = null
13
- // export let linesVisible = true
14
13
  export let rtl = false
15
14
  export let hierarchy = []
16
15
  export let icons
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
16
 
28
17
  $: using = { default: Text, ...using }
29
18
  $: fields = { ...defaultFields, ...fields }
30
19
  $: nodeTypes = items.map((_, index) =>
31
20
  index === items.length - 1 ? 'last' : 'child'
32
21
  )
22
+ $: icons = { ...defaultStateIcons.node, ...icons }
33
23
  </script>
34
24
 
35
25
  <nested-list
@@ -1,5 +1,6 @@
1
1
  <script>
2
2
  import BreadCrumbs from './BreadCrumbs.svelte'
3
+ import { defaultFields } from './constants'
3
4
  import { Text } from './items'
4
5
  import { flattenNestedList } from './lib/nested'
5
6
  import { createEventDispatcher } from 'svelte'
@@ -0,0 +1,50 @@
1
+ <script>
2
+ import { defaultFields } from './constants'
3
+ import { Text } from './items'
4
+
5
+ let className = ''
6
+ export { className as class }
7
+ export let items = [false, true]
8
+ export let fields = defaultFields
9
+ export let using = { default: Text }
10
+ export let compact = true
11
+ export let value
12
+
13
+ const getComponent = (item, fields) => {
14
+ return fields.component
15
+ ? item[fields.component] ?? using.default
16
+ : using.default
17
+ }
18
+
19
+ const onItemClick = (item) => {
20
+ value = item
21
+ }
22
+
23
+ $: useComponent = !items.every((item) => [false, true].includes(item))
24
+ $: fields = { ...defaultFields, ...fields }
25
+ $: using = { default: Text, ...using }
26
+ </script>
27
+
28
+ {#if !Array.isArray(items) || items.length < 2}
29
+ <error>Items should be an array with at least two items.</error>
30
+ {:else}
31
+ <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
32
+ <toggle class="flex items-center {className}" class:compact tabindex="0">
33
+ {#each items as item, index (item)}
34
+ {@const component = useComponent ? getComponent(item, fields) : null}
35
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
36
+ <item
37
+ class="flex relative"
38
+ class:is-selected={item === value}
39
+ on:click={() => onItemClick(item)}
40
+ >
41
+ {#if item == value}
42
+ <indicator class="absolute top-0 left-0 right-0 bottom-0" />
43
+ {/if}
44
+ {#if component}
45
+ <svelte:component this={component} content={item} {fields} />
46
+ {/if}
47
+ </item>
48
+ {/each}
49
+ </toggle>
50
+ {/if}
package/src/Tree.svelte CHANGED
@@ -48,5 +48,5 @@
48
48
  tabindex="0"
49
49
  class={className}
50
50
  >
51
- <NestedList {items} {fields} {using} {value} {...$$restProps} />
51
+ <NestedList {items} {fields} {using} bind:value {...$$restProps} />
52
52
  </tree>
package/src/constants.js CHANGED
@@ -26,36 +26,6 @@ export const defaultIcons = [
26
26
  'navigate-down'
27
27
  ]
28
28
 
29
- // export const defaultIcons = [
30
- // 'accordion-opened',
31
- // 'accordion-closed',
32
- // 'action-remove',
33
- // 'action-add',
34
- // 'action-clear',
35
- // 'action-search',
36
- // 'action-close',
37
- // 'node-opened',
38
- // 'node-closed',
39
- // 'checkbox-checked',
40
- // 'checkbox-unchecked',
41
- // 'checkbox-unknown',
42
- // 'rating-filled',
43
- // 'rating-empty',
44
- // 'rating-half',
45
- // 'radio-off',
46
- // 'radio-on',
47
- // 'folder-closed',
48
- // 'folder-opened',
49
- // 'navigate-up',
50
- // 'navigate-down',
51
- // 'navigate-left',
52
- // 'navigate-right',
53
- // 'selector-closed',
54
- // 'selector-opened',
55
- // 'mode-dark',
56
- // 'mode-light'
57
- // ]
58
-
59
29
  export const defaultOptions = {
60
30
  id: 'id',
61
31
  label: 'label',
@@ -86,7 +56,7 @@ export const defaultFields = {
86
56
  id: 'id',
87
57
  url: 'url',
88
58
  text: 'text',
89
- children: 'data',
59
+ children: 'children',
90
60
  icon: 'icon',
91
61
  image: 'image',
92
62
  component: 'component',
@@ -94,6 +64,7 @@ export const defaultFields = {
94
64
  notes: 'notes',
95
65
  props: 'props',
96
66
  target: 'target',
67
+ state: 'state',
97
68
  isOpen: '_open',
98
69
  isDeleted: '_deleted',
99
70
  level: 'level',
package/src/index.js CHANGED
@@ -3,7 +3,7 @@ export * from './items'
3
3
  export * from './lib'
4
4
 
5
5
  export { default as Icon } from './Icon.svelte'
6
- // export { default as List } from './List-Discard.svelte'
6
+ export { default as Switch } from './Switch.svelte'
7
7
  export { default as Tree } from './Tree.svelte'
8
8
  export { default as Accordion } from './Accordion.svelte'
9
9
  export { default as List } from './List.svelte'
@@ -5,7 +5,7 @@
5
5
  $: type = ['last', 'child', 'sibling'].includes(type) ? type : 'empty'
6
6
  </script>
7
7
 
8
- <span class="grid grid-rows-2 grid-cols-2 h-full w-4 line-{type}">
8
+ <span class="grid grid-rows-2 grid-cols-2 h-full min-w-4 w-4 line-{type}">
9
9
  {#if type === 'last'}
10
10
  {#if rtl}
11
11
  <i class="border-b border-r" />
@@ -1,16 +1,12 @@
1
1
  <script>
2
2
  import Connector from './Connector.svelte'
3
3
  import { defaultFields, defaultStateIcons } from '../constants'
4
- // import { getLineTypes } from '../lib/connector'
5
- // import { has } from 'ramda'
6
- // import { createEventDispatcher } from 'svelte'
7
4
 
8
- // const dispatch = createEventDispatcher()
9
5
  export let content
10
6
  export let fields = defaultFields
11
7
  export let types = []
12
8
  export let stateIcons = defaultStateIcons.node
13
- // export let linesVisible = true
9
+
14
10
  export let selected = false
15
11
  export let using = {}
16
12
  export let rtl = false
@@ -25,12 +21,6 @@
25
21
  $: component = content[fields.component]
26
22
  ? using[content[fields.component]] || using.default
27
23
  : using.default
28
- // $: types = [...types, ...(hasChildren ? [] : ['empty'])]
29
- // $: types = getLineTypes(hasChildren, types)
30
- // function toggle() {
31
- // if (hasChildren) content[fields.isOpen] = !content[fields.isOpen]
32
- // dispatch('select', content)
33
- // }
34
24
  </script>
35
25
 
36
26
  <!-- svelte-ignore a11y-click-events-have-key-events -->
@@ -52,16 +42,7 @@
52
42
  <Connector {type} />
53
43
  {/if}
54
44
  {/each}
55
- <!-- {#each types.slice(1) as type}
56
- <Connector {type} />
57
- {/each} -->
58
-
59
- <!-- {#if hasChildren}
60
- <span class="flex flex-col w-4 h-full items-center justify-center">
61
- <icon class={state.icon} aria-label={state.label} tabindex="-1" />
62
- </span>
63
- {/if} -->
64
- <fragment>
45
+ <item>
65
46
  <svelte:component this={component} bind:content {fields} />
66
- </fragment>
47
+ </item>
67
48
  </node>
@@ -8,14 +8,21 @@
8
8
  $: text = isObject ? content[fields.text] : content
9
9
  </script>
10
10
 
11
- {#if isObject && content[fields.image]}
12
- <img
13
- class="h-4 w-4 object-cover"
14
- alt={content[fields.text]}
15
- src={content[fields.image]}
16
- />
11
+ {#if isObject}
12
+ {#if content[fields.icon]}
13
+ {@const iconName =
14
+ typeof content[fields.icon] == 'object'
15
+ ? content[fields.icon][content[fields.state]]
16
+ : content[fields.icon]}
17
+ <icon class={iconName} />
18
+ {:else if content[fields.image]}
19
+ <img
20
+ class="h-4 w-4 object-cover"
21
+ alt={content[fields.text]}
22
+ src={content[fields.image]}
23
+ />
24
+ {/if}
17
25
  {/if}
18
- {#if isObject && content[fields.icon]}
19
- <icon class={content[fields.icon]} />
26
+ {#if text}
27
+ <p class="flex w-full">{text}</p>
20
28
  {/if}
21
- <p class="flex flex-grow">{text}</p>
package/src/lib/nested.js CHANGED
@@ -1,10 +1,5 @@
1
1
  import { omit } from 'ramda'
2
2
  import { defaultFields } from '../constants'
3
- // const defaultFields = {
4
- // children: 'children',
5
- // level: 'level',
6
- // parent: 'parent'
7
- // }
8
3
 
9
4
  export function flattenNestedList(items, fields = defaultFields, level = 0) {
10
5
  fields = { ...defaultFields, ...fields }