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

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.
Files changed (87) hide show
  1. package/dist/calendar.d.ts +10 -0
  2. package/dist/colors/index.d.ts +333 -0
  3. package/dist/connector.d.ts +8 -0
  4. package/dist/constants.d.ts +39 -0
  5. package/dist/events.d.ts +12 -0
  6. package/dist/field-mapper.d.ts +63 -0
  7. package/dist/index.d.ts +13 -0
  8. package/dist/key-event-map.d.ts +18 -0
  9. package/dist/mapped-items.d.ts +14 -0
  10. package/dist/mapping.d.ts +75 -0
  11. package/dist/nested.d.ts +18 -0
  12. package/dist/string.d.ts +59 -0
  13. package/dist/theme.d.ts +52 -0
  14. package/dist/ticks.d.ts +10 -0
  15. package/dist/types.d.ts +245 -0
  16. package/dist/utils.d.ts +70 -0
  17. package/package.json +13 -38
  18. package/src/calendar.js +44 -0
  19. package/src/colors/index.js +19 -0
  20. package/src/colors/syntax.json +42 -0
  21. package/src/colors/tailwind.json +289 -0
  22. package/src/connector.js +34 -0
  23. package/src/constants.js +67 -94
  24. package/src/events.js +32 -0
  25. package/src/field-mapper.js +148 -0
  26. package/src/index.js +19 -27
  27. package/src/key-event-map.js +36 -0
  28. package/src/mapped-items.js +22 -0
  29. package/src/mapping.js +134 -0
  30. package/src/nested.js +56 -0
  31. package/src/string.js +97 -0
  32. package/src/theme.js +205 -0
  33. package/src/ticks.js +26 -0
  34. package/src/types.js +124 -0
  35. package/src/utils.js +134 -0
  36. package/LICENSE +0 -21
  37. package/README.md +0 -1
  38. package/src/Accordion.svelte +0 -80
  39. package/src/Alerts.svelte +0 -39
  40. package/src/DropDown.svelte +0 -79
  41. package/src/DropSearch.svelte +0 -67
  42. package/src/Icon.svelte +0 -15
  43. package/src/List-Discard.svelte +0 -48
  44. package/src/List.svelte +0 -65
  45. package/src/ListActions.svelte +0 -35
  46. package/src/NavTabs.svelte +0 -0
  47. package/src/NestedList.svelte +0 -87
  48. package/src/Overlay.svelte +0 -4
  49. package/src/PageNavigator.svelte +0 -94
  50. package/src/ResponsiveGrid.svelte +0 -73
  51. package/src/Scrollable.svelte +0 -8
  52. package/src/Searchable.svelte +0 -19
  53. package/src/Sidebar.svelte +0 -5
  54. package/src/Slider.svelte +0 -17
  55. package/src/SpinList.svelte +0 -48
  56. package/src/SplitPane.svelte +0 -109
  57. package/src/SplitView.svelte +0 -44
  58. package/src/Splitter.svelte +0 -95
  59. package/src/TabItem.svelte +0 -27
  60. package/src/TabItems.svelte +0 -34
  61. package/src/Tabs.svelte +0 -31
  62. package/src/Tree.svelte +0 -19
  63. package/src/actions/dismissable.js +0 -24
  64. package/src/actions/fillable.js +0 -114
  65. package/src/actions/hierarchy.js +0 -189
  66. package/src/actions/index.js +0 -7
  67. package/src/actions/navigable.js +0 -42
  68. package/src/actions/navigator.js +0 -179
  69. package/src/actions/pannable.js +0 -50
  70. package/src/actions/swipeable.js +0 -56
  71. package/src/actions/themeable.js +0 -23
  72. package/src/items/Collapsible.svelte +0 -51
  73. package/src/items/Connector.svelte +0 -26
  74. package/src/items/Link.svelte +0 -17
  75. package/src/items/Node.svelte +0 -52
  76. package/src/items/Pill.svelte +0 -19
  77. package/src/items/Separator.svelte +0 -1
  78. package/src/items/Summary.svelte +0 -27
  79. package/src/items/Text.svelte +0 -21
  80. package/src/items/index.js +0 -8
  81. package/src/list.js +0 -14
  82. package/src/mocks/Custom.svelte +0 -7
  83. package/src/mocks/index.js +0 -10
  84. package/src/stores/alerts.js +0 -3
  85. package/src/stores/index.js +0 -6
  86. package/src/stores/persist.js +0 -63
  87. package/src/stores/theme.js +0 -34
package/src/types.js ADDED
@@ -0,0 +1,124 @@
1
+ /**
2
+ * @typedef {'child' | 'last' | 'sibling' | 'empty' | 'icon'} LineType
3
+ */
4
+
5
+ /**
6
+ * @typedef {Object.<string, Function>} EventHandlers
7
+ * An object where keys are event names and values are event handler functions.
8
+ */
9
+
10
+ /**
11
+ * Component map to be used to render the item.
12
+ * @typedef {Object<string, import('svelte').SvelteComponent>} ComponentMap
13
+ */
14
+
15
+ /**
16
+ * Options for the sort order of the column.
17
+ *
18
+ * @typedef {'ascending'|'descending'|'none'} SortOptions
19
+ */
20
+
21
+ /**
22
+ * @typedef {'checked'|'unchecked'|'indeterminate'} SelectionState
23
+ */
24
+
25
+ /**
26
+ * Options for the horizontal alignment of the column content.
27
+ *
28
+ * @typedef {'left'|'middle'|'right'} HorizontalAlignOptions
29
+ */
30
+
31
+ /**
32
+ * Options for the action type of the column.
33
+ *
34
+ * @typedef {'select'|'edit'|'delete'} ActionTypes
35
+ */
36
+
37
+ /**
38
+ * Structure to map custom fields for rendering. This is used to identofy the attributes for various purposes.
39
+ *
40
+ * @typedef FieldMapping
41
+ * @property {string} [id='id'] Unique id for the item
42
+ * @property {string} [text='text'] the text to render
43
+ * @property {string} [value='value'] the value associated with the item
44
+ * @property {string} [url='url'] a URL
45
+ * @property {string} [icon='icon'] icon to render
46
+ * @property {string} [image='image'] the image to render
47
+ * @property {string} [children='children'] children of the item
48
+ * @property {string} [summary='summary'] summary of the item
49
+ * @property {string} [notes='notes'] notes for the item
50
+ * @property {string} [props='props'] additional properties
51
+ * @property {string} [isOpen='_open'] item is open or closed
52
+ * @property {string} [level='level'] level of item
53
+ * @property {string} [parent='parent'] item is a parent
54
+ * @property {string} [currency='currency] column specifying currency to be used for the current value
55
+ * @property {string} [isDeleted='_deleted'] item is deleted
56
+ * @property {FieldMapping} [fields] Field mapping to be used on children in the next level
57
+ */
58
+
59
+ /**
60
+ * Column metadata for the table.
61
+ *
62
+ * @typedef {Object} ColumnMetadata
63
+ *
64
+ * @property {string} name - The name of the column.
65
+ * @property {string} dataType - The data type of the column (e.g., "string", "number", "date").
66
+ * @property {FieldMapping} [fields] - Additional attributes for the column.
67
+ * @property {number} [digits=0] - The number of digits for numeric values (defaults to 0).
68
+ * @property {Function} formatter - A function to format the column value.
69
+ * @property {boolean} [virtual] - Indicates if the column is virtual (true/false).
70
+ * @property {boolean} [sortable] - Indicates if the column is sortable (true/false).
71
+ * @property {SortOptions} [sortOrder] - The sort order of the column.
72
+ * @property {HorizontalAlignOptions} [align] - The alignment of the column content.
73
+ * @property {ActionTypes} [action] - Action attribute for action columns.
74
+ */
75
+
76
+ /**
77
+ * Track the state of a row in the table.
78
+ *
79
+ * @typedef {Object} RowState
80
+ * @property {number} index - The index of the node in the flat list.
81
+ * @property {number} depth - The depth of the node in the hierarchy.
82
+ * @property {string} [value] - The value of the hierarchy node.
83
+ * @property {boolean} [isHidden] - Indicates whether the node is visible (true/false).
84
+ * @property {boolean} [isParent] - Indicates if this node is a parent (true/false).
85
+ * @property {boolean} [isExpanded] - Indicates whether the node is expanded (true/false).
86
+ * @property {number} [parentIndex] - The index of the parent node in the flat list.
87
+ * @property {SelectionState} [selected] - Indicates whether the node is selected (true/false/indeterminate).
88
+ * @property {Array<number>} childred - The indices of the children in the flat list.
89
+ */
90
+
91
+ /**
92
+ * Track the state of all rows in the table.
93
+ *
94
+ * @typedef {Object} RowStateMap
95
+ * @property {RowState[]} rows - Flat list of hierarchy nodes.
96
+ */
97
+
98
+ /**
99
+ * Shade mapping for color variables
100
+ *
101
+ * @typedef {Object} ShadeMapping
102
+ * @property {string} key - the variable name to be used
103
+ * @property {string} value - the value to be used
104
+ * @property {string} mode - light or dark mode
105
+ */
106
+
107
+ /**
108
+ * @typedef {Object} TickMark
109
+ * @property {number} value - The value of the tick mark.
110
+ * @property {string} label - The label for the tick mark.
111
+ * @property {boolean} major - Indicates if the tick mark is a major tick.
112
+ */
113
+
114
+ /**
115
+ * @typedef {Object} CalendarDay
116
+ * @property {number} day - The day of the month.
117
+ * @property {number} offset - indicates the offset for positioning
118
+ * @property {date} date - Datevalue for the day.
119
+ * @property {string} text - formatted text for the day.
120
+ * @property {boolean} holiday - Indicates if the day is a holiday.
121
+ * @property {boolean} weekend - Indicates if the day is on the weekend.
122
+ */
123
+
124
+ export default {}
package/src/utils.js ADDED
@@ -0,0 +1,134 @@
1
+ import { has, isNil } from 'ramda'
2
+
3
+ /**
4
+ * Finds the closest ancestor of the given element that has the given attribute.
5
+ *
6
+ * @param {HTMLElement} element
7
+ * @param {string} attribute
8
+ * @returns {HTMLElement|null}
9
+ */
10
+ export function getClosestAncestorWithAttribute(element, attribute) {
11
+ if (!element) return null
12
+ if (element.getAttribute(attribute)) return element
13
+ return getClosestAncestorWithAttribute(element.parentElement, attribute)
14
+ }
15
+
16
+ /**
17
+ * A function that performs no operations.
18
+ */
19
+ export function noop() {
20
+ // intentionally empty to support default actions
21
+ }
22
+
23
+ /**
24
+ * Generates a random id
25
+ *
26
+ * @returns {string} A random id
27
+ */
28
+ export function id() {
29
+ return Math.random().toString(36).substring(2, 9)
30
+ }
31
+
32
+ /**
33
+ * Check if a value is a json object
34
+ *
35
+ * @param {*} val
36
+ * @returns {boolean}
37
+ */
38
+ export function isObject(val) {
39
+ return typeof val === 'object' && !isNil(val) && !(val instanceof Date)
40
+ }
41
+
42
+ /**
43
+ * Converts the value to a string. If the value is an object, it will convert it to a JSON string.
44
+ *
45
+ * @param {*} value
46
+ * @returns {string}
47
+ */
48
+ export function toString(value) {
49
+ if (value === null || value === undefined) return value
50
+ if (isObject(value)) return JSON.stringify(value, null, 2)
51
+ return value.toString()
52
+ }
53
+
54
+ /**
55
+ * Generates icon shortcuts for a collection of icons
56
+ *
57
+ * @param {string[]} icons
58
+ * @param {string} collection
59
+ * @param {string} variants
60
+ * @returns {Object}
61
+ */
62
+ export function iconShortcuts(icons, collection, variants) {
63
+ const suffix = variants ? `-${variants}` : ''
64
+ const shortcuts = !collection
65
+ ? {}
66
+ : icons.reduce(
67
+ (acc, name) => ({
68
+ ...acc,
69
+ [name]: [collection, name].join(':') + suffix
70
+ }),
71
+ {}
72
+ )
73
+
74
+ return shortcuts
75
+ }
76
+
77
+ /**
78
+ * Scales the path by the size
79
+ *
80
+ * @param {number} size
81
+ * @param {string|number} x
82
+ * @returns {string|number}
83
+ */
84
+ export function scaledPath(size, x) {
85
+ if (Array.isArray(x)) return x.map((v) => scaledPath(size, v)).join(' ')
86
+ return typeof x === 'number' ? x * size : x
87
+ }
88
+
89
+ /**
90
+ * Gets a key string from path
91
+ * @param {string[]} path
92
+ * @returns {string}
93
+ */
94
+ export function getKeyFromPath(path) {
95
+ return Array.isArray(path) ? path.join('-') : [path].join('-')
96
+ }
97
+
98
+ /**
99
+ * Gets a path array from key string
100
+ * @param {string} key
101
+ * @returns {string[]}
102
+ */
103
+ export function getPathFromKey(key) {
104
+ return key.split('-').map(Number)
105
+ }
106
+
107
+ /**
108
+ * Get snippet function from an object
109
+ * @param {Object} obj
110
+ * @param {string} key
111
+ * @param {null|Function} defaultSnippet
112
+ * @returns {Function|undefined}
113
+ */
114
+ export function getSnippet(obj, key, defaultSnippet = null) {
115
+ if (has(key, obj) && typeof obj[key] === 'function') {
116
+ return obj[key]
117
+ }
118
+ return defaultSnippet
119
+ }
120
+
121
+ /**
122
+ * Creates a collection of icon import functions based on an icons dictionary
123
+ *
124
+ * @param {Object} icons - Dictionary mapping collection names to file paths
125
+ * @returns {Object} Collections object with functions that dynamically import icon files
126
+ */
127
+ export const importIcons = (icons) => {
128
+ if (!icons) return {}
129
+
130
+ return Object.entries(icons).reduce((acc, [key, value]) => {
131
+ acc[key] = () => import(value, { with: { type: 'json' } }).then((i) => i.default)
132
+ return acc
133
+ }, {})
134
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Jerry Thomas
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
@@ -1 +0,0 @@
1
- # Core Components
@@ -1,80 +0,0 @@
1
- <script>
2
- import { createEventDispatcher } from 'svelte'
3
- import { defaultFields } from './constants'
4
- import { Text, Summary } from './items'
5
- import List from './List.svelte'
6
- import { navigator } from './actions/navigator'
7
-
8
- const dispatch = createEventDispatcher()
9
- let className = ''
10
- export { className as class }
11
- export let items = []
12
- export let fields = {}
13
- export let using = {}
14
- export let autoClose = false
15
- export let value = null
16
- let cursor = []
17
-
18
- $: fields = { ...defaultFields, ...fields }
19
- $: using = { default: Text, ...using }
20
-
21
- function handle(event) {
22
- // console.log(event.type, event.detail)
23
- value = event.detail.node
24
- cursor = event.detail.path
25
- if (['collapse', 'expand'].includes(event.type)) {
26
- if (autoClose) {
27
- items.map((x) => {
28
- if (x !== value && x[fields.isOpen]) {
29
- x[fields.isOpen] = false
30
- }
31
- })
32
- }
33
- items = items
34
- }
35
- dispatch(event.type, event.detail)
36
- }
37
- </script>
38
-
39
- <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
40
- <accordion
41
- class="flex flex-col w-full select-none {className}"
42
- tabindex="0"
43
- use:navigator={{
44
- items,
45
- fields,
46
- enabled: true,
47
- indices: cursor
48
- }}
49
- on:select={handle}
50
- on:move={handle}
51
- on:expand={handle}
52
- on:collapse={handle}
53
- >
54
- {#each items as item, index}
55
- {@const hasItems =
56
- item[fields.children] && item[fields.children].length > 0}
57
- {@const itemFields = { ...fields, ...(fields.fields ?? fields) }}
58
-
59
- <div
60
- id={'id-' + index}
61
- class="flex flex-col"
62
- class:is-expanded={item[fields.isOpen]}
63
- class:is-selected={item === value}
64
- data-path={index}
65
- >
66
- <Summary {fields} {using} bind:content={item} />
67
- {#if hasItems && item[fields.isOpen]}
68
- <List
69
- bind:items={item[fields.children]}
70
- bind:value
71
- fields={itemFields}
72
- {using}
73
- on:select
74
- hierarchy={[index]}
75
- tabindex="-1"
76
- />
77
- {/if}
78
- </div>
79
- {/each}
80
- </accordion>
package/src/Alerts.svelte DELETED
@@ -1,39 +0,0 @@
1
- <script>
2
- import { fade } from 'svelte/transition'
3
- import { flip } from 'svelte/animate'
4
- import { alerts } from './stores'
5
- import { dismissable } from './actions'
6
-
7
- function dismissAll() {
8
- unreadAlerts.map((alert) => (alert.dismissed = true))
9
- alerts.set([...$alerts])
10
- }
11
-
12
- function dismiss(alert) {
13
- alert.dismissed = true
14
- alerts.set([...$alerts])
15
- }
16
-
17
- $: unreadAlerts = $alerts.filter((x) => x.dismissed)
18
- </script>
19
-
20
- {#if unreadAlerts.length > 0}
21
- <alert-list
22
- class="flex flex-col gap-2 absolute z-10"
23
- use:dismissable
24
- on:dismiss={dismissAll}
25
- >
26
- {#each unreadAlerts as alert (alert.id)}
27
- <!-- svelte-ignore a11y-click-events-have-key-events -->
28
- <alert
29
- class={alert.type}
30
- on:click|stopPropagation={dismiss(alert)}
31
- animate:flip
32
- in:fade
33
- out:fade
34
- >
35
- {alert.message}
36
- </alert>
37
- {/each}
38
- </alert-list>
39
- {/if}
@@ -1,79 +0,0 @@
1
- <script>
2
- import { createEventDispatcher } from 'svelte'
3
- import { dismissable } from './actions'
4
- import { defaultFields, defaultStateIcons } from './constants.js'
5
-
6
- import Icon from './Icon.svelte'
7
- import Text from './items/Text.svelte'
8
- import List from './List.svelte'
9
-
10
- const dispatch = createEventDispatcher()
11
-
12
- let className = ''
13
- export { className as class }
14
- export let items = []
15
- export let fields = defaultFields
16
- export let using = { default: Text }
17
- export let value = null
18
- export let title
19
- export let icon
20
- export let small = false
21
-
22
- $: using = { default: Text, ...using }
23
- $: fields = { ...defaultFields, ...fields }
24
-
25
- let offsetTop = 0
26
- let open = false
27
- let icons = defaultStateIcons.selector
28
-
29
- function handleSelect(event) {
30
- open = false
31
- dispatch('change', event.detail)
32
- }
33
- </script>
34
-
35
- <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
36
- <drop-down
37
- class="flex w-full relative cursor-pointer select-none dropdown {className}"
38
- class:open
39
- tabindex="0"
40
- aria-haspopup="true"
41
- aria-controls="menu"
42
- use:dismissable
43
- on:blur={() => (open = false)}
44
- on:dismiss={() => (open = false)}
45
- >
46
- <button
47
- on:click|stopPropagation={() => (open = !open)}
48
- class="flex"
49
- bind:clientHeight={offsetTop}
50
- tabindex="-1"
51
- >
52
- {#if icon}
53
- <Icon name={icon} />
54
- {/if}
55
- {#if !small && title}
56
- <p>{title}</p>
57
- {/if}
58
- {#if open}
59
- <icon class={icons.opened} />
60
- {:else}
61
- <icon class={icons.closed} />
62
- {/if}
63
- </button>
64
- {#if open}
65
- <div
66
- class="flex flex-col absolute z-10 h-fit w-full menu"
67
- style:top="{offsetTop}px"
68
- >
69
- <List
70
- {items}
71
- {fields}
72
- {using}
73
- bind:value
74
- on:select={handleSelect}
75
- tabindex="-1"
76
- />
77
- </div>
78
- {/if}
79
- </drop-down>
@@ -1,67 +0,0 @@
1
- <script>
2
- import { defaultFields } from './constants.js'
3
- import List from './List.svelte'
4
- import Slider from './Slider.svelte'
5
- import { Text } from './items'
6
-
7
- export let data
8
- export let value = null
9
- export let fields = defaultFields
10
- export let using = { default: Text }
11
-
12
- $: using = { default: Text, ...using }
13
- $: fields = { ...defaultFields, ...fields }
14
-
15
- let opened = false
16
- let search
17
- let searchBox
18
-
19
- // on search change filter list
20
- function handleSelect(event) {
21
- console.log('selected', event)
22
- value = event.detail
23
- search = event.detail[fields.text]
24
- }
25
- </script>
26
-
27
- <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
28
- <div
29
- class="flex flex-col outline-none w-full h-12 relative dropdown"
30
- tabindex={0}
31
- >
32
- <div class="flex flex-shrink-0 h-12 items-center pl-4 selected-item">
33
- <span class="flex flex-grow">
34
- <input
35
- type="text"
36
- class="p-0 border-none bg-transparent w-full"
37
- bind:value={search}
38
- bind:this={searchBox}
39
- on:focus={() => {
40
- opened = true
41
- searchBox.select()
42
- }}
43
- on:blur={() => {
44
- opened = false
45
- }}
46
- />
47
- </span>
48
- {#if opened}
49
- <icon class="selector-opened" />
50
- {:else}
51
- <icon class="selector-closed" />
52
- {/if}
53
- </div>
54
-
55
- {#if opened}
56
- <Slider>
57
- <List
58
- bind:items={data}
59
- bind:value
60
- {fields}
61
- {using}
62
- on:select={handleSelect}
63
- on:change
64
- />
65
- </Slider>
66
- {/if}
67
- </div>
package/src/Icon.svelte DELETED
@@ -1,15 +0,0 @@
1
- <script>
2
- let className = ''
3
- export { className as class }
4
-
5
- export let name = ''
6
- let h
7
- </script>
8
-
9
- <square-icon
10
- class="flex flex-col flex-shrink-0 h-full items-center justify-center {className}"
11
- bind:clientHeight={h}
12
- style:width="{h}px"
13
- >
14
- <icon class={name} aria-hidden="true" />
15
- </square-icon>
@@ -1,48 +0,0 @@
1
- <script>
2
- import ListActions from './ListActions.svelte'
3
- import ListItems from './List.svelte'
4
-
5
- let className = 'list'
6
- export { className as class }
7
- export let items = []
8
- export let fields = {}
9
- export let using = {}
10
- export let value = null
11
- export let searchable = false
12
- export let editable = false
13
-
14
- let search
15
- let filtered
16
-
17
- function addItem() {
18
- items = [...items, {}]
19
- value = items[items.length - 1]
20
- }
21
- function deleteSelection() {
22
- if (value) value.isDeleted = true
23
- }
24
- function clearSelection() {
25
- value = null
26
- }
27
-
28
- $: filtered =
29
- searchable && search && search.length
30
- ? items.filter((item) => item[fields.text].includes(search))
31
- : items
32
- </script>
33
-
34
- <list class="flex flex-col w-full {className}">
35
- {#if searchable || editable}
36
- <ListActions
37
- bind:search
38
- {searchable}
39
- {editable}
40
- on:delete={deleteSelection}
41
- on:clear={clearSelection}
42
- on:add={addItem}
43
- />
44
- {/if}
45
- <scroll class="flex flex-col h-full overflow-scroll">
46
- <ListItems bind:items={filtered} {fields} {using} bind:value on:select />
47
- </scroll>
48
- </list>
package/src/List.svelte DELETED
@@ -1,65 +0,0 @@
1
- <script>
2
- import { navigator } from './actions'
3
- import { createEventDispatcher } from 'svelte'
4
- import { defaultFields } from './constants'
5
- import { Text } from './items'
6
-
7
- const dispatch = createEventDispatcher()
8
-
9
- let className = 'list'
10
- export { className as class }
11
- export let items = []
12
- export let fields = {}
13
- export let using = {}
14
- export let value = null
15
- export let tabindex = 0
16
- export let hierarchy = []
17
- let cursor = []
18
-
19
- function handleNav(event) {
20
- value = event.detail.node
21
- cursor = event.detail.path
22
-
23
- dispatch('select', { item: value, indices: cursor })
24
- }
25
-
26
- $: fields = { ...defaultFields, ...fields }
27
- $: using = { default: Text, ...using }
28
- $: filtered = items.filter((item) => !item[fields.isDeleted])
29
- </script>
30
-
31
- <list
32
- class="flex flex-col w-full flex-shrink-0 select-none {className}"
33
- role="listbox"
34
- use:navigator={{
35
- items,
36
- fields,
37
- enabled: hierarchy.length == 0,
38
- indices: cursor
39
- }}
40
- on:move={handleNav}
41
- on:select={handleNav}
42
- {tabindex}
43
- >
44
- <slot />
45
- {#each filtered as item, index}
46
- {@const component = item[fields.component]
47
- ? using[item[fields.component]] || using.default
48
- : using.default}
49
- {@const path = [...hierarchy, index].join(',')}
50
- <item
51
- class="flex flex-shrink-0 flex-grow-0 items-center cursor-pointer w-full gap-2 select-none item"
52
- role="option"
53
- aria-selected={value === item}
54
- class:is-selected={value === item}
55
- data-path={path}
56
- >
57
- <svelte:component
58
- this={component}
59
- bind:content={item}
60
- {fields}
61
- on:change
62
- />
63
- </item>
64
- {/each}
65
- </list>