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

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 (91) hide show
  1. package/dist/calendar.d.ts +10 -0
  2. package/dist/colors/index.d.ts +47 -0
  3. package/dist/connector.d.ts +8 -0
  4. package/dist/constants.d.ts +88 -0
  5. package/dist/events.d.ts +12 -0
  6. package/dist/field-mapper.d.ts +60 -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 +14 -0
  11. package/dist/nested.d.ts +9 -0
  12. package/dist/string.d.ts +59 -0
  13. package/dist/theme.d.ts +96 -0
  14. package/dist/ticks.d.ts +10 -0
  15. package/dist/types.d.ts +300 -0
  16. package/dist/utils.d.ts +107 -0
  17. package/dist/vite/icon-collections.d.ts +32 -0
  18. package/dist/vite/index.d.ts +1 -0
  19. package/package.json +24 -39
  20. package/src/calendar.js +44 -0
  21. package/src/colors/extra.json +16 -0
  22. package/src/colors/syntax.json +42 -0
  23. package/src/colors/tailwind.json +275 -0
  24. package/src/connector.js +34 -0
  25. package/src/constants.js +181 -107
  26. package/src/events.js +32 -0
  27. package/src/field-mapper.js +147 -0
  28. package/src/index.js +19 -27
  29. package/src/key-event-map.js +36 -0
  30. package/src/mapped-items.js +22 -0
  31. package/src/mapping.js +21 -0
  32. package/src/nested.js +28 -0
  33. package/src/string.js +97 -0
  34. package/src/ticks.js +26 -0
  35. package/src/types.js +160 -0
  36. package/src/utils.js +250 -0
  37. package/src/vite/icon-collections.js +73 -0
  38. package/src/vite/index.js +1 -0
  39. package/LICENSE +0 -21
  40. package/README.md +0 -1
  41. package/src/Accordion.svelte +0 -80
  42. package/src/Alerts.svelte +0 -39
  43. package/src/DropDown.svelte +0 -82
  44. package/src/DropSearch.svelte +0 -67
  45. package/src/EditableTabs.svelte +0 -31
  46. package/src/Icon.svelte +0 -15
  47. package/src/List-Discard.svelte +0 -48
  48. package/src/List.svelte +0 -65
  49. package/src/ListActions.svelte +0 -35
  50. package/src/NavTabs.svelte +0 -0
  51. package/src/NestedList.svelte +0 -77
  52. package/src/Overlay.svelte +0 -4
  53. package/src/PageNavigator.svelte +0 -94
  54. package/src/ResponsiveGrid.svelte +0 -73
  55. package/src/Scrollable.svelte +0 -8
  56. package/src/Searchable.svelte +0 -19
  57. package/src/Sidebar.svelte +0 -5
  58. package/src/Slider.svelte +0 -17
  59. package/src/SpinList.svelte +0 -48
  60. package/src/SplitPane.svelte +0 -109
  61. package/src/SplitView.svelte +0 -44
  62. package/src/Splitter.svelte +0 -95
  63. package/src/TabItem.svelte +0 -27
  64. package/src/TabItems.svelte +0 -34
  65. package/src/Tabs.svelte +0 -49
  66. package/src/Tree.svelte +0 -45
  67. package/src/actions/dismissable.js +0 -24
  68. package/src/actions/fillable.js +0 -114
  69. package/src/actions/hierarchy.js +0 -189
  70. package/src/actions/index.js +0 -7
  71. package/src/actions/navigable.js +0 -43
  72. package/src/actions/navigator.js +0 -179
  73. package/src/actions/pannable.js +0 -50
  74. package/src/actions/swipeable.js +0 -56
  75. package/src/actions/themeable.js +0 -23
  76. package/src/items/Collapsible.svelte +0 -51
  77. package/src/items/Connector.svelte +0 -26
  78. package/src/items/Link.svelte +0 -18
  79. package/src/items/Node.svelte +0 -52
  80. package/src/items/Pill.svelte +0 -19
  81. package/src/items/Separator.svelte +0 -1
  82. package/src/items/Summary.svelte +0 -27
  83. package/src/items/Text.svelte +0 -21
  84. package/src/items/index.js +0 -8
  85. package/src/list.js +0 -14
  86. package/src/mocks/Custom.svelte +0 -7
  87. package/src/mocks/index.js +0 -10
  88. package/src/stores/alerts.js +0 -3
  89. package/src/stores/index.js +0 -6
  90. package/src/stores/persist.js +0 -63
  91. package/src/stores/theme.js +0 -34
@@ -1,95 +0,0 @@
1
- <script>
2
- // ensure that parent has position: relative.
3
- // on reaching limit remove mouse events.
4
- import { createEventDispatcher } from 'svelte'
5
- import { pannable } from './actions'
6
-
7
- const dispatch = createEventDispatcher()
8
-
9
- export let vertical = false
10
- export let index
11
- export let min = 0
12
- export let max = 100
13
- export let pos = 50
14
- export let offset = 0
15
-
16
- let wall
17
-
18
- function clamp(min, max, value) {
19
- return min > value ? min : max < value ? max : value
20
- }
21
-
22
- function fixLimits() {
23
- if (min > max) [min, max] = [max, min]
24
- max = clamp(0, 100, max)
25
- min = clamp(0, 100, min)
26
- pos = clamp(min, max, pos)
27
- }
28
-
29
- function handlePanMove(event) {
30
- const { top, bottom, left, right } =
31
- wall.parentElement.getBoundingClientRect()
32
- const extents = horizontal ? [left, right] : [top, bottom]
33
- let px = clamp(
34
- extents[0],
35
- extents[1],
36
- horizontal ? event.detail.x : event.detail.y
37
- )
38
-
39
- pos = clamp(min, max, (100 * (px - extents[0])) / (extents[1] - extents[0]))
40
-
41
- dispatch('change', { pos, index, offset })
42
- }
43
- $: fixLimits()
44
- $: horizontal = !vertical
45
- $: side = horizontal ? 'left' : 'top'
46
- </script>
47
-
48
- <span
49
- bind:this={wall}
50
- class="wall"
51
- class:vertical
52
- class:horizontal
53
- use:pannable
54
- on:panmove={handlePanMove}
55
- style="{side}: calc({pos}% - 8px)"
56
- />
57
-
58
- <style>
59
- .wall {
60
- position: absolute;
61
- z-index: 10;
62
- }
63
- .wall::after {
64
- content: '';
65
- position: absolute;
66
- background-color: #000;
67
- }
68
- .wall:hover {
69
- cursor: ew-resize;
70
- }
71
- .horizontal.wall {
72
- padding: 0 8px;
73
- width: 0;
74
- height: 100%;
75
- cursor: ew-resize;
76
- }
77
- .horizontal.wall::after {
78
- left: 8px;
79
- top: 0;
80
- width: 1px;
81
- height: 100%;
82
- }
83
- .vertical.wall {
84
- padding: 8px 0;
85
- width: 100%;
86
- height: 0;
87
- cursor: ns-resize;
88
- }
89
- .vertical.wall::after {
90
- top: 8px;
91
- left: 0;
92
- width: 100%;
93
- height: 1px;
94
- }
95
- </style>
@@ -1,27 +0,0 @@
1
- <script>
2
- import { createEventDispatcher } from 'svelte'
3
-
4
- const dispatch = createEventDispatcher()
5
-
6
- export let icon = null
7
- export let label
8
- export let active = false
9
- export let allowClose = false
10
- </script>
11
-
12
- <!-- svelte-ignore a11y-click-events-have-key-events -->
13
- <tab class="flex flex-row items-center" class:active on:click>
14
- {#if icon}
15
- <icon class={icon} aria-label={icon} />
16
- {/if}
17
- {#if label}
18
- <p class="flex flex-shrink-0 flex-grow justify-center">{label}</p>
19
- {/if}
20
- {#if allowClose}
21
- <icon
22
- class="remove small"
23
- aria-label="remove"
24
- on:click={() => dispatch('remove')}
25
- />
26
- {/if}
27
- </tab>
@@ -1,34 +0,0 @@
1
- <script>
2
- import { createEventDispatcher } from 'svelte'
3
- import { defaultFields } from './constants'
4
- import TabItem from './TabItem.svelte'
5
-
6
- const dispatch = createEventDispatcher()
7
-
8
- export let items = []
9
- export let fields = {}
10
- export let allowClose = false
11
- export let value = items[0]
12
-
13
- function activate(item) {
14
- value = item
15
- dispatch('switch', item)
16
- }
17
- function closeTab(index) {
18
- items[index].isClosed = true
19
- }
20
- $: fields = { ...defaultFields, ...fields }
21
- $: filtered = items.filter((item) => !item.isClosed)
22
- </script>
23
-
24
- {#each filtered as item, index}
25
- {@const label = item[fields.text]}
26
- <TabItem
27
- icon={item[fields.icon]}
28
- {label}
29
- {allowClose}
30
- active={value == item}
31
- on:click={() => activate(item)}
32
- on:close={() => closeTab(index)}
33
- />
34
- {/each}
package/src/Tabs.svelte DELETED
@@ -1,49 +0,0 @@
1
- <script>
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()
8
-
9
- let className = ''
10
- export { className as class }
11
- export let items = []
12
- export let fields = {}
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
20
-
21
- dispatch('select', { item: value, indices: cursor })
22
- }
23
- $: fields = { ...defaultFields, ...fields }
24
- $: using = { default: Text, ...using }
25
- </script>
26
-
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 DELETED
@@ -1,45 +0,0 @@
1
- <script>
2
- import { createEventDispatcher } from 'svelte'
3
- import NestedList from './NestedList.svelte'
4
- import { Text } from './items'
5
- import { defaultFields } from './constants'
6
- import { navigator } from './actions/navigator'
7
-
8
- const dispatch = createEventDispatcher()
9
-
10
- export let items = []
11
- export let fields = {}
12
- export let using = { default: Text }
13
- export let root = null
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
- }
27
-
28
- $: fields = { ...defaultFields, ...fields }
29
- $: items =
30
- items.length == 1 || root == null
31
- ? items
32
- : [{ [fields.text]: root, [fields.children]: items }]
33
- </script>
34
-
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>
@@ -1,24 +0,0 @@
1
- const KEYCODE_ESC = 27
2
-
3
- export function dismissable(node) {
4
- const handleClick = (event) => {
5
- if (node && !node.contains(event.target) && !event.defaultPrevented) {
6
- node.dispatchEvent(new CustomEvent('dismiss', node))
7
- }
8
- }
9
- const keyup = (event) => {
10
- if (event.keyCode === KEYCODE_ESC) {
11
- node.dispatchEvent(new CustomEvent('dismiss', node))
12
- }
13
- }
14
-
15
- document.addEventListener('click', handleClick, true)
16
- document.addEventListener('keyup', keyup, true)
17
-
18
- return {
19
- destroy() {
20
- document.removeEventListener('click', handleClick, true)
21
- document.removeEventListener('keyup', keyup, true)
22
- }
23
- }
24
- }
@@ -1,114 +0,0 @@
1
- /**
2
- * @typedef FillOptions
3
- * @property {Array<string>} options available options to fill
4
- * @property {integer} current index of option to be filled
5
- * @property {boolean} check validate filled values
6
- */
7
- /**
8
- * Action for filling a <del>?</del> element in html block.
9
- *
10
- * @param {*} node
11
- * @param {FillOptions} options
12
- * @returns
13
- */
14
- export function fillable(node, { options, current, check }) {
15
- let data = { options, current, check }
16
- let blanks = node.getElementsByTagName('del')
17
-
18
- function click(event) {
19
- if ('?' !== event.target.innerHTML) {
20
- clear(event, node)
21
- }
22
- }
23
-
24
- initialize(blanks, click)
25
-
26
- return {
27
- update({ options, current }) {
28
- data.options = options
29
- data.current = current
30
- data.check = check
31
-
32
- fill(blanks, data.options, data.current)
33
- if (data.check) validate(blanks, data)
34
- },
35
- destroy() {
36
- Object.keys(blanks).map((ref) => {
37
- blanks[ref].removeEventListener('click', click)
38
- })
39
- }
40
- }
41
- }
42
-
43
- /**
44
- * Initialize empty fillable element style and add listener for click
45
- *
46
- * @param {*} blanks
47
- * @param {*} click
48
- */
49
- function initialize(blanks, click) {
50
- Object.keys(blanks).map((ref) => {
51
- blanks[ref].addEventListener('click', click)
52
- blanks[ref].classList.add('empty')
53
- blanks[ref].name = 'fill-' + ref
54
- blanks[ref]['data-index'] = ref
55
- })
56
- }
57
-
58
- /**
59
- * Fill current blank with provided option
60
- *
61
- * @param {*} blanks
62
- * @param {*} options
63
- * @param {*} current
64
- */
65
- function fill(blanks, options, current) {
66
- if (current > -1 && current < Object.keys(blanks).length) {
67
- let index = options.findIndex(({ actualIndex }) => actualIndex == current)
68
- if (index > -1) {
69
- blanks[current].innerHTML = options[index].value
70
- blanks[current].classList.remove('empty')
71
- blanks[current].classList.add('filled')
72
- }
73
- }
74
- }
75
-
76
- /**
77
- * Clear all fillable elements
78
- *
79
- * @param {*} event
80
- * @param {*} node
81
- */
82
- function clear(event, node) {
83
- event.target.innerHTML = '?'
84
- event.target.classList.remove('filled')
85
- event.target.classList.remove('pass')
86
- event.target.classList.remove('fail')
87
- event.target.classList.add('empty')
88
- node.dispatchEvent(
89
- new CustomEvent('remove', {
90
- detail: {
91
- index: event.target.name.split('-')[1],
92
- value: event.target['data-index']
93
- }
94
- })
95
- )
96
- }
97
-
98
- /**
99
- * Validate the filled values
100
- *
101
- * @param {*} blanks
102
- * @param {*} data
103
- */
104
- function validate(blanks, data) {
105
- Object.keys(blanks).map((ref) => {
106
- let index = data.options.findIndex(({ actualIndex }) => actualIndex == ref)
107
- if (index > -1)
108
- blanks[ref].classList.add(
109
- data.options[index].expectedIndex == data.options[index].actualIndex
110
- ? 'pass'
111
- : 'fail'
112
- )
113
- })
114
- }
@@ -1,189 +0,0 @@
1
- /**
2
- * A part of the path to node in hierarchy
3
- *
4
- * @typedef PathFragment
5
- * @property {integer} index - Index to item in array
6
- * @property {Array<*>} items - Array of items
7
- * @property {import('../constants').FieldMapping} fields - Field mapping for the data
8
- */
9
-
10
- /**
11
- * Check if the current item is a parent
12
- *
13
- * @param {*} item
14
- * @param {import('../constants').FieldMapping} fields
15
- * @returns {boolean}
16
- */
17
- export function hasChildren(item, fields) {
18
- return (
19
- typeof item === 'object' &&
20
- fields.children in item &&
21
- Array.isArray(item[fields.children])
22
- )
23
- }
24
-
25
- /**
26
- * Check if the current item is a parent and is expanded
27
- *
28
- * @param {*} item
29
- * @param {import('../constants').FieldMapping} fields
30
- * @returns {boolean}
31
- */
32
- export function isExpanded(item, fields) {
33
- if (item == null) return false
34
- if (!hasChildren(item, fields)) return false
35
- if (fields.isOpen in item) {
36
- return item[fields.isOpen]
37
- }
38
- return false
39
- }
40
-
41
- /**
42
- * Verify if at least one item has children
43
- *
44
- * @param {Array<*>} items
45
- * @param {import('../constants').FieldMapping} fields
46
- * @returns {boolean}
47
- */
48
- export function isNested(items, fields) {
49
- for (let i = 0; i < items.length; i++) {
50
- if (hasChildren(items[i], fields)) return true
51
- }
52
- return false
53
- }
54
-
55
- /**
56
- * Navigate to last visible child in the hirarchy starting with the provided path
57
- *
58
- * @param {Array<PathFragment>} path - path to a node in the hierarchy
59
- * @returns
60
- */
61
- export function navigateToLastVisibleChild(path) {
62
- let current = path[path.length - 1]
63
- // console.log(current)
64
- while (isExpanded(current.items[current.index], current.fields)) {
65
- const items = current.items[current.index][current.fields.children]
66
- const level = {
67
- items,
68
- index: items.length - 1,
69
- fields: current.fields.fields ?? current.fields
70
- }
71
- path.push(level)
72
- current = level
73
- }
74
-
75
- return path
76
- }
77
-
78
- /**
79
- * Navigate to the next item
80
- *
81
- * @param {Array<PathFragment>} path - path to a node in the hierarchy
82
- * @param {Array<*>} items - array of items
83
- * @param {import('../constants').FieldMapping} fields - field mapping
84
- * @returns
85
- */
86
- export function moveNext(path, items, fields) {
87
- if (path.length === 0) {
88
- return [{ index: 0, items, fields }]
89
- }
90
-
91
- const current = path[path.length - 1]
92
- if (isExpanded(current.items[current.index], current.fields)) {
93
- path.push({
94
- items: current.items[current.index][current.fields.children],
95
- index: 0,
96
- fields: current.fields.fields || current.fields
97
- })
98
- } else if (current.index < current.items.length - 1) {
99
- current.index++
100
- } else {
101
- let level = path.length - 2
102
- while (level >= 0) {
103
- const parent = path[level]
104
- if (parent.index < parent.items.length - 1) {
105
- parent.index++
106
- path = path.slice(0, level + 1)
107
- break
108
- }
109
- level--
110
- }
111
- }
112
- return path
113
- }
114
-
115
- /**
116
- * Navigate to the previous item
117
- *
118
- * @param {Array<PathFragment>} path - path to a node in the hierarchy
119
- * @returns
120
- */
121
- export function movePrevious(path) {
122
- if (path.length === 0) return []
123
-
124
- const current = path[path.length - 1]
125
-
126
- if (current.index == 0) {
127
- if (path.length > 1) path.pop()
128
- return path
129
- }
130
-
131
- current.index--
132
- if (isExpanded(current.items[current.index], current.fields)) {
133
- return navigateToLastVisibleChild(path)
134
- }
135
- return path
136
- }
137
-
138
- export function pathFromIndices(indices, items, fields) {
139
- let path = []
140
- let fragment
141
- indices.map((index, level) => {
142
- if (level === 0) {
143
- fragment = { index, items, fields }
144
- } else {
145
- fragment = {
146
- index,
147
- items: fragment.items[fragment.index][fragment.fields.children],
148
- fields: fragment.fields.fields ?? fragment.fields
149
- }
150
- }
151
- path.push(fragment)
152
- })
153
- return path
154
- }
155
-
156
- export function indicesFromPath(path) {
157
- return path.map(({ index }) => index)
158
- }
159
- export function getCurrentNode(path) {
160
- if (path.length === 0) return null
161
- const lastIndex = path.length - 1
162
- return path[lastIndex].items[path[lastIndex].index]
163
- }
164
-
165
- export function findItem(items, indices, fields) {
166
- let item = items[indices[0]]
167
- let levelFields = fields
168
- for (let level = 1; level < indices.length; level++) {
169
- item = item[levelFields.children][indices[level]]
170
- levelFields = levelFields.fields ?? levelFields
171
- }
172
- return item
173
- }
174
-
175
- // export function getNodeFromIndices(indices, items, fields) {
176
- // let fragment
177
- // indices.map((index, level) => {
178
- // if (level === 0) {
179
- // fragment = { index, items, fields }
180
- // } else {
181
- // fragment = {
182
- // index,
183
- // items: fragment.items[fragment.index][fragment.fields.children],
184
- // fields: fragment.fields.fields ?? fragment.fields
185
- // }
186
- // }
187
- // })
188
- // return indices.length === 0 ? null : fragment.items[fragment.index]
189
- // }
@@ -1,7 +0,0 @@
1
- export { fillable } from './fillable'
2
- export { pannable } from './pannable'
3
- export { navigable } from './navigable'
4
- export { navigator } from './navigator'
5
- export { dismissable } from './dismissable'
6
- export { themable } from './themeable'
7
- export { swipeable } from './swipeable'
@@ -1,43 +0,0 @@
1
- export function navigable(
2
- node,
3
- { horizontal = true, nested = false, enabled = true } = {}
4
- ) {
5
- // console.log(node, enabled)
6
- if (!enabled) return { destroy() {} }
7
- const previous = () => node.dispatchEvent(new CustomEvent('previous'))
8
- const next = () => node.dispatchEvent(new CustomEvent('next'))
9
- const collapse = () => node.dispatchEvent(new CustomEvent('collapse'))
10
- const expand = () => node.dispatchEvent(new CustomEvent('expand'))
11
- const select = () => node.dispatchEvent(new CustomEvent('select'))
12
-
13
- const movement = horizontal
14
- ? { ArrowLeft: previous, ArrowRight: next }
15
- : { ArrowUp: previous, ArrowDown: next }
16
- const change = nested
17
- ? horizontal
18
- ? { ArrowUp: collapse, ArrowDown: expand }
19
- : { ArrowLeft: collapse, ArrowRight: expand }
20
- : {}
21
- const actions = {
22
- Enter: select,
23
- ' ': select,
24
- ...movement,
25
- ...change
26
- }
27
-
28
- function handleKeydown(event) {
29
- if (actions[event.key]) {
30
- event.preventDefault()
31
- event.stopPropagation()
32
- actions[event.key]()
33
- }
34
- }
35
-
36
- node.addEventListener('keydown', handleKeydown)
37
-
38
- return {
39
- destroy() {
40
- node.removeEventListener('keydown', handleKeydown)
41
- }
42
- }
43
- }