@rokkit/core 1.0.0-next.20 → 1.0.0-next.22
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 +2 -2
- package/src/NestedList.svelte +2 -12
- package/src/NestedPaginator.svelte +1 -0
- package/src/Switch.svelte +54 -0
- package/src/Tree.svelte +1 -1
- package/src/constants.js +2 -31
- package/src/index.js +1 -1
- package/src/items/Connector.svelte +1 -1
- package/src/items/Node.svelte +3 -22
- package/src/items/Text.svelte +16 -9
- package/src/lib/nested.js +0 -5
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.22",
|
|
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.
|
|
28
|
+
"vite": "^4.3.4",
|
|
29
29
|
"vitest": "~0.19.1",
|
|
30
30
|
"shared-config": "1.0.0"
|
|
31
31
|
},
|
package/src/NestedList.svelte
CHANGED
|
@@ -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
|
|
@@ -0,0 +1,54 @@
|
|
|
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-switch
|
|
33
|
+
class="flex items-center {className}"
|
|
34
|
+
class:compact
|
|
35
|
+
tabindex="0"
|
|
36
|
+
>
|
|
37
|
+
{#each items as item, index (item)}
|
|
38
|
+
{@const component = useComponent ? getComponent(item, fields) : null}
|
|
39
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
40
|
+
<item
|
|
41
|
+
class="flex relative"
|
|
42
|
+
class:is-selected={item === value}
|
|
43
|
+
on:click={() => onItemClick(item)}
|
|
44
|
+
>
|
|
45
|
+
{#if item == value}
|
|
46
|
+
<indicator class="absolute top-0 left-0 right-0 bottom-0" />
|
|
47
|
+
{/if}
|
|
48
|
+
{#if component}
|
|
49
|
+
<svelte:component this={component} content={item} {fields} />
|
|
50
|
+
{/if}
|
|
51
|
+
</item>
|
|
52
|
+
{/each}
|
|
53
|
+
</toggle-switch>
|
|
54
|
+
{/if}
|
package/src/Tree.svelte
CHANGED
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: '
|
|
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
|
-
|
|
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" />
|
package/src/items/Node.svelte
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
</
|
|
47
|
+
</item>
|
|
67
48
|
</node>
|
package/src/items/Text.svelte
CHANGED
|
@@ -8,14 +8,21 @@
|
|
|
8
8
|
$: text = isObject ? content[fields.text] : content
|
|
9
9
|
</script>
|
|
10
10
|
|
|
11
|
-
{#if isObject
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
19
|
-
<
|
|
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 }
|