@rokkit/ui 1.0.0-next.125 → 1.0.0-next.128

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 (154) hide show
  1. package/README.md +198 -101
  2. package/package.json +42 -34
  3. package/src/components/BreadCrumbs.svelte +90 -0
  4. package/src/components/Button.svelte +93 -0
  5. package/src/components/ButtonGroup.svelte +18 -0
  6. package/src/components/Card.svelte +61 -0
  7. package/src/components/Carousel.svelte +174 -0
  8. package/src/components/Code.svelte +189 -0
  9. package/src/components/Connector.svelte +46 -0
  10. package/src/components/FloatingAction.svelte +334 -0
  11. package/src/components/FloatingNavigation.svelte +235 -0
  12. package/src/components/Grid.svelte +128 -0
  13. package/src/components/ItemContent.svelte +25 -0
  14. package/src/components/LazyTree.svelte +165 -0
  15. package/src/components/List.svelte +188 -0
  16. package/src/components/Menu.svelte +270 -0
  17. package/src/components/MultiSelect.svelte +369 -0
  18. package/src/components/PaletteManager.svelte +364 -0
  19. package/src/components/Pill.svelte +83 -0
  20. package/src/components/ProgressBar.svelte +31 -0
  21. package/src/components/Range.svelte +330 -0
  22. package/src/components/Rating.svelte +101 -0
  23. package/src/components/Reveal.svelte +58 -0
  24. package/src/components/SearchFilter.svelte +88 -0
  25. package/src/components/Select.svelte +396 -0
  26. package/src/{Shine.svelte → components/Shine.svelte} +29 -21
  27. package/src/components/Stepper.svelte +172 -0
  28. package/src/components/Switch.svelte +75 -0
  29. package/src/components/Table.svelte +242 -0
  30. package/src/components/Tabs.svelte +192 -0
  31. package/src/components/Tilt.svelte +68 -0
  32. package/src/components/Timeline.svelte +61 -0
  33. package/src/components/Toggle.svelte +93 -0
  34. package/src/components/Toolbar.svelte +308 -0
  35. package/src/components/ToolbarGroup.svelte +17 -0
  36. package/src/components/Tree.svelte +144 -0
  37. package/src/components/UploadFileStatus.svelte +83 -0
  38. package/src/components/UploadProgress.svelte +131 -0
  39. package/src/components/UploadTarget.svelte +124 -0
  40. package/src/components/index.ts +38 -0
  41. package/src/index.ts +46 -0
  42. package/src/types/button.ts +86 -0
  43. package/src/types/code.ts +46 -0
  44. package/src/types/floating-action.ts +123 -0
  45. package/src/types/floating-navigation.ts +80 -0
  46. package/src/types/index.ts +55 -0
  47. package/src/types/list.ts +200 -0
  48. package/src/types/menu.ts +95 -0
  49. package/src/types/palette.ts +160 -0
  50. package/src/types/range.ts +51 -0
  51. package/src/types/search-filter.ts +67 -0
  52. package/src/types/select.ts +176 -0
  53. package/src/types/switch.ts +68 -0
  54. package/src/types/table.ts +210 -0
  55. package/src/types/tabs.ts +103 -0
  56. package/src/types/timeline.ts +53 -0
  57. package/src/types/toggle.ts +68 -0
  58. package/src/types/toolbar.ts +164 -0
  59. package/src/types/tree.ts +250 -0
  60. package/src/types/upload-file-status.ts +45 -0
  61. package/src/types/upload-progress.ts +111 -0
  62. package/src/types/upload-target.ts +68 -0
  63. package/src/utils/palette.ts +582 -0
  64. package/src/utils/shiki.ts +122 -0
  65. package/src/utils/upload.js +128 -0
  66. package/dist/constants.d.ts +0 -2
  67. package/dist/index.d.ts +0 -41
  68. package/dist/lib/fields.d.ts +0 -16
  69. package/dist/lib/form.d.ts +0 -95
  70. package/dist/lib/index.d.ts +0 -6
  71. package/dist/lib/layout.d.ts +0 -7
  72. package/dist/lib/nested.d.ts +0 -48
  73. package/dist/lib/schema.d.ts +0 -7
  74. package/dist/lib/select.d.ts +0 -8
  75. package/dist/lib/tree.d.ts +0 -9
  76. package/dist/tree/List.spec.svelte.d.ts +0 -1
  77. package/dist/tree/Node.spec.svelte.d.ts +0 -1
  78. package/dist/tree/Root.spec.svelte.d.ts +0 -1
  79. package/dist/types.d.ts +0 -5
  80. package/dist/wrappers/index.d.ts +0 -3
  81. package/src/Accordion.svelte +0 -118
  82. package/src/BreadCrumbs.svelte +0 -32
  83. package/src/Button.svelte +0 -57
  84. package/src/Calendar.svelte +0 -93
  85. package/src/Card.svelte +0 -45
  86. package/src/Carousel.svelte +0 -49
  87. package/src/CheckBox.svelte +0 -56
  88. package/src/Connector.svelte +0 -40
  89. package/src/DropDown.svelte +0 -68
  90. package/src/DropSearch.svelte +0 -37
  91. package/src/Fillable.svelte +0 -19
  92. package/src/GraphPaper.svelte +0 -43
  93. package/src/Icon.svelte +0 -81
  94. package/src/Item.svelte +0 -25
  95. package/src/Link.svelte +0 -21
  96. package/src/List.svelte +0 -89
  97. package/src/ListBody.svelte +0 -43
  98. package/src/Message.svelte +0 -11
  99. package/src/MultiSelect.svelte +0 -48
  100. package/src/NestedList.svelte +0 -78
  101. package/src/NestedPaginator.svelte +0 -63
  102. package/src/Node.svelte +0 -76
  103. package/src/Overlay.svelte +0 -21
  104. package/src/PageNavigator.svelte +0 -94
  105. package/src/PickOne.svelte +0 -60
  106. package/src/Pill.svelte +0 -41
  107. package/src/ProgressBar.svelte +0 -21
  108. package/src/ProgressDots.svelte +0 -53
  109. package/src/RadioGroup.svelte +0 -52
  110. package/src/Range.svelte +0 -45
  111. package/src/RangeMinMax.svelte +0 -124
  112. package/src/RangeSlider.svelte +0 -79
  113. package/src/RangeTick.svelte +0 -28
  114. package/src/Rating.svelte +0 -95
  115. package/src/ResponsiveGrid.svelte +0 -88
  116. package/src/Scrollable.svelte +0 -7
  117. package/src/Select.svelte +0 -114
  118. package/src/Separator.svelte +0 -1
  119. package/src/Slider.svelte +0 -14
  120. package/src/SlidingColumns.svelte +0 -50
  121. package/src/Stage.svelte +0 -41
  122. package/src/Stepper.svelte +0 -66
  123. package/src/Summary.svelte +0 -22
  124. package/src/Switch.svelte +0 -106
  125. package/src/TableCell.svelte +0 -51
  126. package/src/TableHeaderCell.svelte +0 -54
  127. package/src/Tabs.svelte +0 -176
  128. package/src/Tilt.svelte +0 -66
  129. package/src/Toggle.svelte +0 -58
  130. package/src/ToggleThemeMode.svelte +0 -23
  131. package/src/Tree.svelte +0 -80
  132. package/src/TreeTable.svelte +0 -171
  133. package/src/ValidationReport.svelte +0 -23
  134. package/src/constants.js +0 -4
  135. package/src/index.js +0 -48
  136. package/src/lib/fields.js +0 -118
  137. package/src/lib/form.js +0 -72
  138. package/src/lib/index.js +0 -13
  139. package/src/lib/layout.js +0 -63
  140. package/src/lib/nested.js +0 -192
  141. package/src/lib/schema.js +0 -32
  142. package/src/lib/select.js +0 -38
  143. package/src/lib/tree.js +0 -22
  144. package/src/tree/List.spec.svelte.js +0 -84
  145. package/src/tree/List.svelte +0 -78
  146. package/src/tree/Node.spec.svelte.js +0 -104
  147. package/src/tree/Node.svelte +0 -80
  148. package/src/tree/Root.spec.svelte.js +0 -63
  149. package/src/tree/Root.svelte +0 -81
  150. package/src/types.js +0 -9
  151. package/src/wrappers/Category.svelte +0 -27
  152. package/src/wrappers/Section.svelte +0 -16
  153. package/src/wrappers/Wrapper.svelte +0 -12
  154. package/src/wrappers/index.js +0 -3
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Upload utility functions — shared helpers for UploadTarget and UploadProgress.
3
+ * Pure functions with no Svelte dependency.
4
+ */
5
+
6
+ const ARCHIVE_TYPES = new Set(['application/zip', 'application/gzip', 'application/x-tar'])
7
+
8
+ /**
9
+ * Check if a file matches an accept string (comma-separated MIME types and extensions).
10
+ * @param {{ type: string, name: string }} file
11
+ * @param {string | null | undefined} accept - e.g. 'image/*,.pdf,application/json'
12
+ * @returns {boolean}
13
+ */
14
+ export function matchesAccept(file, accept) {
15
+ if (!accept) return true
16
+
17
+ const tokens = accept.split(',').map((t) => t.trim()).filter(Boolean)
18
+ if (tokens.length === 0) return true
19
+
20
+ return tokens.some((token) => {
21
+ if (token.startsWith('.')) {
22
+ // Extension match (case-insensitive)
23
+ return file.name.toLowerCase().endsWith(token.toLowerCase())
24
+ }
25
+ if (token.endsWith('/*')) {
26
+ // Wildcard MIME type match (e.g. image/*)
27
+ const prefix = token.slice(0, -1) // 'image/'
28
+ return file.type.startsWith(prefix)
29
+ }
30
+ // Exact MIME type match
31
+ return file.type === token
32
+ })
33
+ }
34
+
35
+ /**
36
+ * Validate a file against accept and maxSize constraints.
37
+ * @param {{ type: string, name: string, size: number }} file
38
+ * @param {{ accept?: string, maxSize?: number }} constraints
39
+ * @returns {true | { reason: 'type' | 'size' }}
40
+ */
41
+ export function validateFile(file, { accept, maxSize } = {}) {
42
+ if (accept && !matchesAccept(file, accept)) {
43
+ return { reason: 'type' }
44
+ }
45
+ if (maxSize !== undefined && file.size > maxSize) {
46
+ return { reason: 'size' }
47
+ }
48
+ return true
49
+ }
50
+
51
+ /**
52
+ * Map a MIME type to an icon class string.
53
+ * @param {string | null | undefined} mimeType
54
+ * @returns {string}
55
+ */
56
+ export function inferIcon(mimeType) {
57
+ if (!mimeType) return 'i-lucide:file'
58
+
59
+ if (mimeType.startsWith('image/')) return 'i-lucide:image'
60
+ if (mimeType.startsWith('video/')) return 'i-lucide:video'
61
+ if (mimeType.startsWith('audio/')) return 'i-lucide:music'
62
+ if (mimeType === 'application/pdf') return 'i-lucide:file-text'
63
+ if (mimeType.startsWith('text/')) return 'i-lucide:file-text'
64
+ if (ARCHIVE_TYPES.has(mimeType)) return 'i-lucide:archive'
65
+
66
+ return 'i-lucide:file'
67
+ }
68
+
69
+ /**
70
+ * Format a byte count as a human-readable size string.
71
+ * @param {number} bytes
72
+ * @returns {string}
73
+ */
74
+ export function formatSize(bytes) {
75
+ if (bytes < 1024) return `${bytes} B`
76
+ if (bytes < 1024 ** 2) return `${(bytes / 1024).toFixed(1)} KB`
77
+ if (bytes < 1024 ** 3) return `${(bytes / 1024 ** 2).toFixed(1)} MB`
78
+ return `${(bytes / 1024 ** 3).toFixed(1)} GB`
79
+ }
80
+
81
+ /**
82
+ * Group a flat file array by path field into a nested tree structure.
83
+ * Root-level items (empty path) stay ungrouped.
84
+ * Group nodes use `text` as the label field (ProxyItem compatibility).
85
+ *
86
+ * @param {Array<Record<string, any>>} items
87
+ * @param {string} pathField - field name containing the path (e.g. 'path')
88
+ * @param {string} childrenField - field name for children arrays (e.g. 'children')
89
+ * @returns {Array<Record<string, any>>}
90
+ */
91
+ export function groupByPath(items, pathField, childrenField) {
92
+ if (!items || items.length === 0) return []
93
+
94
+ const root = []
95
+ /** @type {Map<string, Record<string, any>>} */
96
+ const folderMap = new Map()
97
+
98
+ for (const item of items) {
99
+ const rawPath = item[pathField] || ''
100
+ if (!rawPath) {
101
+ root.push(item)
102
+ continue
103
+ }
104
+
105
+ // Split path into segments, filtering empty strings from trailing slashes
106
+ const segments = rawPath.split('/').filter(Boolean)
107
+ let parent = root
108
+ let fullPath = ''
109
+
110
+ for (let i = 0; i < segments.length; i++) {
111
+ const segment = segments[i]
112
+ fullPath = fullPath ? `${fullPath}/${segment}` : segment
113
+
114
+ let folder = folderMap.get(fullPath)
115
+ if (!folder) {
116
+ folder = { text: segment, [childrenField]: [] }
117
+ folderMap.set(fullPath, folder)
118
+ parent.push(folder)
119
+ }
120
+
121
+ parent = folder[childrenField]
122
+ }
123
+
124
+ parent.push(item)
125
+ }
126
+
127
+ return root
128
+ }
@@ -1,2 +0,0 @@
1
- export const defaultMapping: FieldMapper;
2
- import { FieldMapper } from '@rokkit/core';
package/dist/index.d.ts DELETED
@@ -1,41 +0,0 @@
1
- export * from "./types.js";
2
- export { default as Button } from "./Button.svelte";
3
- export { default as Icon } from "./Icon.svelte";
4
- export { default as Item } from "./Item.svelte";
5
- export { default as Pill } from "./Pill.svelte";
6
- export { default as ProgressBar } from "./ProgressBar.svelte";
7
- export { default as Separator } from "./Separator.svelte";
8
- export { default as Connector } from "./Connector.svelte";
9
- export { default as RangeTick } from "./RangeTick.svelte";
10
- export { default as RangeSlider } from "./RangeSlider.svelte";
11
- export { default as Node } from "./Node.svelte";
12
- export { default as Summary } from "./Summary.svelte";
13
- export { default as BreadCrumbs } from "./BreadCrumbs.svelte";
14
- export { default as Rating } from "./Rating.svelte";
15
- export { default as RangeMinMax } from "./RangeMinMax.svelte";
16
- export { default as Range } from "./Range.svelte";
17
- export { default as RadioGroup } from "./RadioGroup.svelte";
18
- export { default as CheckBox } from "./CheckBox.svelte";
19
- export { default as Calendar } from "./Calendar.svelte";
20
- export { default as ValidationReport } from "./ValidationReport.svelte";
21
- export { default as ResponsiveGrid } from "./ResponsiveGrid.svelte";
22
- export { default as Toggle } from "./Toggle.svelte";
23
- export { default as Switch } from "./Switch.svelte";
24
- export { default as List } from "./List.svelte";
25
- export { default as Accordion } from "./Accordion.svelte";
26
- export { default as Tree } from "./Tree.svelte";
27
- export { default as Tabs } from "./Tabs.svelte";
28
- export { default as Select } from "./Select.svelte";
29
- export { default as MultiSelect } from "./MultiSelect.svelte";
30
- export { default as DropDown } from "./DropDown.svelte";
31
- export { default as Table } from "./TreeTable.svelte";
32
- export { default as ToggleThemeMode } from "./ToggleThemeMode.svelte";
33
- export { default as Overlay } from "./Overlay.svelte";
34
- export { default as Message } from "./Message.svelte";
35
- export { default as SlidingColumns } from "./SlidingColumns.svelte";
36
- export { default as Stepper } from "./Stepper.svelte";
37
- export { default as ProgressDots } from "./ProgressDots.svelte";
38
- export { default as Card } from "./Card.svelte";
39
- export { default as Shine } from "./Shine.svelte";
40
- export { default as Tilt } from "./Tilt.svelte";
41
- export { default as GraphPaper } from "./GraphPaper.svelte";
@@ -1,16 +0,0 @@
1
- /**
2
- * Find an attribute in a schema by path
3
- * @param {string} scope
4
- * @param {import('../types').DataSchema} schema
5
- * @returns {import('../types').LayoutSchema}
6
- * @throws {Error} Invalid path
7
- */
8
- export function findAttributeByPath(scope: string, schema: import("../types").DataSchema): import("../types").LayoutSchema;
9
- /**
10
- * Get combined schema and layout
11
- * @param {*} data
12
- * @param {import('../types').DataSchema} schema
13
- * @param {import('../types').LayoutSchema} layout
14
- * @returns {import('../types').LayoutSchema}
15
- */
16
- export function getSchemaWithLayout(schema: import("../types").DataSchema, layout: import("../types").LayoutSchema): import("../types").LayoutSchema;
@@ -1,95 +0,0 @@
1
- export namespace messages {
2
- let required: string;
3
- let email: string;
4
- let url: string;
5
- let color: string;
6
- let number: string;
7
- let min: string;
8
- let max: string;
9
- let pattern: string;
10
- let exclusiveMin: string;
11
- let exclusiveMax: string;
12
- let minLength: string;
13
- let maxLength: string;
14
- let minItems: string;
15
- let maxItems: string;
16
- let uniqueItems: string;
17
- let contains: string;
18
- let exclude: string;
19
- let integer: string;
20
- }
21
- export namespace dataTypes {
22
- export namespace integer_1 {
23
- let editor: string;
24
- namespace props {
25
- let type: string;
26
- let step: number;
27
- }
28
- let availableProps: string[];
29
- }
30
- export { integer_1 as integer };
31
- export namespace number_1 {
32
- let editor_1: string;
33
- export { editor_1 as editor };
34
- export namespace props_1 {
35
- let type_1: string;
36
- export { type_1 as type };
37
- let step_1: number;
38
- export { step_1 as step };
39
- }
40
- export { props_1 as props };
41
- let availableProps_1: string[];
42
- export { availableProps_1 as availableProps };
43
- }
44
- export { number_1 as number };
45
- export namespace range {
46
- let editor_2: string;
47
- export { editor_2 as editor };
48
- export namespace props_2 {
49
- let type_2: string;
50
- export { type_2 as type };
51
- }
52
- export { props_2 as props };
53
- }
54
- export let string: {
55
- default: string;
56
- text: string;
57
- password: string;
58
- email: string;
59
- url: string;
60
- tel: string;
61
- date: string;
62
- 'datetime-local': string;
63
- time: string;
64
- week: string;
65
- month: string;
66
- file: string;
67
- hidden: string;
68
- color: string;
69
- colorpicker: string;
70
- };
71
- export namespace _enum {
72
- let _default: string;
73
- export { _default as default };
74
- export let select: string;
75
- export let radio: string;
76
- }
77
- export { _enum as enum };
78
- export namespace boolean {
79
- let _default_1: string;
80
- export { _default_1 as default };
81
- export let checkbox: string;
82
- let _switch: string;
83
- export { _switch as switch };
84
- let radio_1: string;
85
- export { radio_1 as radio };
86
- }
87
- export namespace array {
88
- let _default_2: string;
89
- export { _default_2 as default };
90
- }
91
- export namespace object {
92
- let _default_3: string;
93
- export { _default_3 as default };
94
- }
95
- }
@@ -1,6 +0,0 @@
1
- export { addRootNode } from "./tree";
2
- export { deriveSchemaFromValue } from "./schema";
3
- export { deriveLayoutFromValue } from "./layout";
4
- export { messages, dataTypes } from "./form";
5
- export { getSchemaWithLayout, findAttributeByPath } from "./fields";
6
- export { deriveNestedSchema, flattenAttributes, flattenObject, flattenElement, generateIndex, generateTreeTable } from "./nested";
@@ -1,7 +0,0 @@
1
- /**
2
- * Derives a layout from a given value.
3
- * @param {any} value
4
- * @param {string} scope
5
- * @returns {import('../types').DataLayout}
6
- */
7
- export function deriveLayoutFromValue(value: any, scope?: string): import("../types").DataLayout;
@@ -1,48 +0,0 @@
1
- /**
2
- * Flattens an object into a flat object
3
- *
4
- * @param {Object} input - The object to flatten
5
- * @param {String} scope - The scope of the object
6
- */
7
- export function flattenObject(input: Object, scope?: string): any;
8
- /**
9
- * Flattens an object into an array of key-value pairs
10
- *
11
- * @param {Object} input - The object to flatten
12
- * @param {String} scope - The scope of the object
13
- */
14
- export function flattenAttributes(input: Object, scope?: string): {
15
- key: string;
16
- value: any;
17
- type: string;
18
- scope: string;
19
- }[];
20
- /**
21
- * Derives a nested schema from an object
22
- *
23
- * @param {Object} input - The object to derive the schema from
24
- * @param {String} scope - The scope of the object
25
- * @returns {Object} The derived schema
26
- */
27
- export function deriveNestedSchema(input: Object, scope?: string): Object;
28
- /**
29
- * Flattens an element into a flat object
30
- *
31
- * @param {Object} element - The element to flatten
32
- */
33
- export function flattenElement(element: Object): any;
34
- /**
35
- * Generates an index array referencing the input data
36
- *
37
- * @param {Object} data - The flat object to index
38
- * @param {String} key - The key to use as index
39
- */
40
- export function generateIndex(data: Object, key?: string): any;
41
- /**
42
- * Generates a tree table from the input data
43
- *
44
- * @param {Object} data - The data to generate the tree table from
45
- * @param {String} key - The key to use as index
46
- * @param {Boolean} ellipsis - Whether to truncate the value
47
- */
48
- export function generateTreeTable(data: Object, key?: string, ellipsis?: boolean): any;
@@ -1,7 +0,0 @@
1
- /**
2
- * Derives a schema from a given value.
3
- *
4
- * @param {any} data
5
- * @returns {import('../types').DataSchema}
6
- */
7
- export function deriveSchemaFromValue(data: any): import("../types").DataSchema;
@@ -1,8 +0,0 @@
1
- /**
2
- * Get the optimal position for the list based on anchor and viewport dimensions.
3
- *
4
- * @param {HTMLElement} anchor - The anchor element to position the list relative to.
5
- * @param {HTMLElement} viewport - The viewport element that determines the position.
6
- * @returns {string} - A string with CSS position properties and values.
7
- */
8
- export function getListPosition(anchor: HTMLElement, viewport: HTMLElement): string;
@@ -1,9 +0,0 @@
1
- /**
2
- * Adds a root node to the items array converting it into a nested tree with one root node
3
- *
4
- * @param {Array<Object>} items
5
- * @param {string} root
6
- * @param {import('@rokkit/core').FieldMapping} fields
7
- * @returns
8
- */
9
- export function addRootNode(items: Array<Object>, root?: string, mapping?: import("@rokkit/core").FieldMapper): Object[];
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
package/dist/types.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export type NodeStateIcons = {
2
- opened: string;
3
- closed: string;
4
- };
5
- export type ConnectionType = "empty" | "last" | "child" | "sibling";
@@ -1,3 +0,0 @@
1
- export { default as Wrapper } from "./Wrapper.svelte";
2
- export { default as Section } from "./Section.svelte";
3
- export { default as Category } from "./Category.svelte";
@@ -1,118 +0,0 @@
1
- <script>
2
- import { equals } from 'ramda'
3
- import {
4
- createEmitter,
5
- noop,
6
- getKeyFromPath,
7
- getSnippet,
8
- defaultFields,
9
- hasChildren
10
- } from '@rokkit/core'
11
- import { NestedController } from '@rokkit/states'
12
- import { navigator } from '@rokkit/actions'
13
- import Summary from './Summary.svelte'
14
- import Item from './Item.svelte'
15
- import ListBody from './ListBody.svelte'
16
-
17
- const eventNames = ['collapse', 'change', 'expand', 'click', 'select', 'move']
18
- /**
19
- * @typedef {Object} Props
20
- * @property {string} [class]
21
- * @property {any} [items]
22
- * @property {import('@rokkit/core').FieldMapper} [mapping]
23
- * @property {boolean} [autoCloseSiblings]
24
- * @property {boolean} [multiselect]
25
- * @property {any} [value]
26
- */
27
-
28
- /** @type {Props} */
29
- let {
30
- class: classes = '',
31
- items = $bindable([]),
32
- value = $bindable(null),
33
- fields,
34
- autoCloseSiblings = false,
35
- multiselect = false,
36
- header = null,
37
- footer = null,
38
- empty = null,
39
- oncollapse,
40
- onexpand,
41
- onchange,
42
- onselect,
43
- onmove,
44
- ...snippets
45
- } = $props()
46
-
47
- let emitter = $derived(
48
- createEmitter({ oncollapse, onexpand, onchange, onselect, onmove }, eventNames)
49
- )
50
- function handleAction(event) {
51
- const { name, data } = event.detail
52
-
53
- if (has(name, emitter)) {
54
- value = data.value
55
- selected = data.selected
56
- emitter[name](data)
57
- }
58
- }
59
-
60
- let wrapper = new NestedController(items, value, fields, {
61
- multiselect,
62
- autoCloseSiblings
63
- })
64
- let derivedFields = $derived({ ...defaultFields, ...fields })
65
- </script>
66
-
67
- <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
68
- <rk-accordion
69
- class={classes}
70
- tabindex="0"
71
- use:navigator={{ wrapper, nested: true }}
72
- onactivate={() => (value = wrapper.value)}
73
- >
74
- {#if header}
75
- <rk-header>{@render header()}</rk-header>
76
- {/if}
77
- {#if items.length === 0}
78
- <rk-list-item role="presentation">
79
- {#if empty}
80
- {@render empty()}
81
- {:else}
82
- No items found.
83
- {/if}
84
- </rk-list-item>
85
- {/if}
86
- {#each items as item, index (index)}
87
- {@const key = `${index}`}
88
- {@const expanded = item[derivedFields.expanded]}
89
- <div
90
- class="flex flex-col"
91
- class:is-expanded={expanded}
92
- class:is-selected={wrapper.selectedKeys.has(key)}
93
- data-path={index}
94
- >
95
- <Summary
96
- bind:value={items[index]}
97
- {fields}
98
- {expanded}
99
- hasChildren={hasChildren(item, derivedFields)}
100
- />
101
- {#if expanded}
102
- <rk-list role="listbox" tabindex="-1">
103
- <ListBody
104
- bind:items={items[fields.children]}
105
- bind:value
106
- fields={fields.fields ?? fields}
107
- {selected}
108
- onchange={emitter.change}
109
- {snippets}
110
- />
111
- </rk-list>
112
- {/if}
113
- </div>
114
- {/each}
115
- {#if footer}
116
- <rk-footer>{@render footer()}</rk-footer>
117
- {/if}
118
- </rk-accordion>
@@ -1,32 +0,0 @@
1
- <script>
2
- import Item from './Item.svelte'
3
- import Icon from './Icon.svelte'
4
- import { Proxy } from '@rokkit/states'
5
- /**
6
- * @typedef {Object} Props
7
- * @property {string} [class]
8
- * @property {any} [items]
9
- * @property {string} [separator]
10
- * @property {any} [fields]
11
- * @property {any} [crumb]
12
- */
13
-
14
- /** @type {Props} */
15
- let { class: classes = '', items = [], separator = '/', fields, child } = $props()
16
- let childSnippet = $derived(child ? child : defaultChild)
17
- </script>
18
-
19
- {#snippet defaultChild(proxy)}
20
- <Item {proxy} />
21
- {/snippet}
22
- <div data-crumb-root class={classes}>
23
- {#each items as item, index (index)}
24
- {@const proxy = new Proxy(item, fields)}
25
- {#if index > 0}
26
- <Icon name={separator} data-crumb-separator></Icon>
27
- {/if}
28
- <div data-crumb-item class:is-selected={index === items.length - 1}>
29
- {@render childSnippet?.(proxy)}
30
- </div>
31
- {/each}
32
- </div>
package/src/Button.svelte DELETED
@@ -1,57 +0,0 @@
1
- <script>
2
- import Icon from './Icon.svelte'
3
- /**
4
- * @typedef {Object} ButtonProps
5
- * @property {'default' | 'primary' | 'secondary' | 'tertiary'} variant - The variant of the button.
6
- * @property {'button' | 'submit' | 'reset'} type - The type of the button.
7
- * @property {string} [label] - The label of the button.
8
- * @property {string|import('svelte').Snippet} [leftIcon] - The left icon of the button.
9
- * @property {string|import('svelte').Snippet} [rightIcon] - The right icon of the button.
10
- * @property {import('svelte').Snippet} [children]
11
- * @property {Function} onclick - The onclick event of the button.
12
- * @property {Function} onsubmit - The onsubmit event of the button.
13
- * @property {Function} onreset - The onreset event of the button.
14
- */
15
- /** @type {ButtonProps} */
16
- let {
17
- class: classes = '',
18
- variant = 'default',
19
- type = 'button',
20
- leftIcon = null,
21
- rightIcon = null,
22
- label = null,
23
- children = null,
24
- description = null,
25
- disabled = false,
26
- onclick
27
- } = $props()
28
- </script>
29
-
30
- <button
31
- data-button-root
32
- data-variant={variant}
33
- data-disabled={disabled}
34
- class={classes}
35
- {disabled}
36
- {type}
37
- {onclick}
38
- aria-label={description ?? label}
39
- >
40
- {#if typeof leftIcon === 'string'}
41
- <Icon name={leftIcon} />
42
- {:else}
43
- {@render leftIcon?.()}
44
- {/if}
45
-
46
- {#if children}
47
- {@render children()}
48
- {:else if label}
49
- {label}
50
- {/if}
51
-
52
- {#if typeof rightIcon === 'string'}
53
- <Icon name={rightIcon} />
54
- {:else}
55
- {@render rightIcon?.()}
56
- {/if}
57
- </button>