@rokkit/core 1.0.0-next.92 → 1.0.0-next.94

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.92",
3
+ "version": "1.0.0-next.94",
4
4
  "description": "Core components, actions and stores for svelte apps.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -14,16 +14,16 @@
14
14
  "devDependencies": {
15
15
  "@sveltejs/vite-plugin-svelte": "^3.0.2",
16
16
  "@testing-library/svelte": "^4.1.0",
17
- "@types/ramda": "^0.29.10",
18
- "@vitest/coverage-v8": "^1.3.1",
19
- "@vitest/ui": "~1.3.1",
17
+ "@types/ramda": "^0.29.12",
18
+ "@vitest/coverage-v8": "^1.4.0",
19
+ "@vitest/ui": "~1.4.0",
20
20
  "jsdom": "^24.0.0",
21
- "svelte": "^4.2.11",
22
- "typescript": "^5.3.3",
23
- "vite": "^5.1.4",
24
- "vitest": "~1.3.1",
25
- "shared-config": "1.0.0-next.92",
26
- "validators": "1.0.0-next.92"
21
+ "svelte": "^4.2.12",
22
+ "typescript": "^5.4.4",
23
+ "vite": "^5.2.8",
24
+ "vitest": "~1.4.0",
25
+ "shared-config": "1.0.0-next.94",
26
+ "validators": "1.0.0-next.94"
27
27
  },
28
28
  "files": [
29
29
  "src/**/*.js",
@@ -35,13 +35,13 @@
35
35
  "./package.json": "./package.json",
36
36
  "./constants": "./src/constants.js",
37
37
  ".": {
38
- "types": "./dist/index.d.ts",
38
+ "types": "./dist/types.d.ts",
39
39
  "import": "./src/index.js",
40
40
  "svelte": "./src/index.js"
41
41
  }
42
42
  },
43
43
  "dependencies": {
44
- "date-fns": "^3.3.1",
44
+ "date-fns": "^3.6.0",
45
45
  "ramda": "^0.29.1"
46
46
  },
47
47
  "scripts": {
package/src/calendar.js CHANGED
@@ -18,7 +18,7 @@ export function getCalendarDays(value, holidays = [], fixed = false) {
18
18
  holidays = holidays.map((x) => format(new Date(x), 'yyyy-MMM-dd'))
19
19
  let days = Array.from({ length: getDaysInMonth(value) }, (_, i) => ({
20
20
  day: i + 1,
21
- offset: i == 0 ? offset : 0,
21
+ offset: i === 0 ? offset : 0,
22
22
  date: new Date(year, month, i + 1)
23
23
  })).map((x) => ({
24
24
  ...x,
@@ -1,4 +1,6 @@
1
- import { defaultTailwindColors } from './tailwind'
1
+ import defaultTailwindColors from './tailwind.json'
2
+ import syntaxColorPalette from './syntax.json'
3
+
2
4
  export const shades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
3
5
  export const defaultPalette = [
4
6
  'neutral',
@@ -10,8 +12,8 @@ export const defaultPalette = [
10
12
  'danger',
11
13
  'info'
12
14
  ]
13
- export * from './syntax'
14
15
 
16
+ export const syntaxColors = syntaxColorPalette
15
17
  export const defaultColors = {
16
18
  ...defaultTailwindColors
17
19
  }
package/src/connector.js CHANGED
@@ -1,8 +1,29 @@
1
+ const nextType = {
2
+ child: 'sibling',
3
+ last: 'empty',
4
+ sibling: 'sibling',
5
+ empty: 'empty'
6
+ }
7
+
8
+ /**
9
+ * Constructs an array of line types based on the provided parameters.
10
+ *
11
+ * @param {boolean} hasChildren - Indicates whether the current item has children, affecting the line type for the item itself.
12
+ * @param {Array<string>} parentTypes - An array of types from the parent indicating the line type context.
13
+ * @param {string} position - The line type to use for the current position (usually 'child' or 'last').
14
+ * @returns {Array<string>} An array of line types.
15
+ */
1
16
  export function getLineTypes(hasChildren = false, parentTypes = [], position = 'child') {
2
- let types = parentTypes.slice(0, -1).map((type) => {
3
- return type === 'child' ? 'sibling' : type === 'last' ? 'empty' : type
4
- })
5
- if (parentTypes.length > 0) types.push(position)
17
+ // Map each parent type to a line type, except for the last element.
18
+ const types = parentTypes.slice(0, -1).map((type) => nextType[type])
19
+
20
+ // Append the position type for the last parent, if any.
21
+ if (parentTypes.length > 0) {
22
+ types.push(position)
23
+ }
24
+
25
+ // Append the line type based on whether the current item has children.
6
26
  types.push(hasChildren ? 'icon' : 'empty')
27
+
7
28
  return types
8
29
  }
@@ -1,6 +1,20 @@
1
1
  import { defaultFields } from './constants'
2
2
  import { isExpanded, hasChildren, getAttribute } from './mapping'
3
3
  import { equals } from 'ramda'
4
+
5
+ function isMatch(item, attr, value) {
6
+ const itemValue = attr ? getAttribute(item, attr) : item
7
+ return equals(itemValue, value)
8
+ }
9
+
10
+ function findInChildren(item, index, fields, value, attr, position) {
11
+ if (hasChildren(item, fields)) {
12
+ return findItemByValue(value, item[fields.children], fields.fields ?? fields, attr, [
13
+ ...position,
14
+ index
15
+ ])
16
+ }
17
+ }
4
18
  /**
5
19
  * Traverses the tree to find an item by value.
6
20
  * @param {Array} items - The items array.
@@ -11,30 +25,14 @@ import { equals } from 'ramda'
11
25
  */
12
26
  export function findItemByValue(value, items, fields = defaultFields, attr = null, position = []) {
13
27
  for (let i = 0; i < items.length; i++) {
14
- const item = items[i]
15
-
16
- if (attr) {
17
- if (getAttribute(item, attr) === value) {
18
- return { item, position: position.concat(i), fields }
19
- }
20
- } else if (equals(item, value)) {
21
- return { item, position: position.concat(i), fields }
28
+ if (isMatch(items[i], attr, value)) {
29
+ return { item: items[i], position: [...position, i], fields }
22
30
  }
23
31
 
24
- // If the item has children, recurse into them.
25
- if (hasChildren(item, fields)) {
26
- const found = findItemByValue(
27
- value,
28
- item[fields.children],
29
- fields.fields ?? fields,
30
- attr,
31
- position.concat(i)
32
- )
33
- if (found) return found
34
- }
32
+ const foundInChildren = findInChildren(items[i], i, fields, value, attr, position)
33
+ if (foundInChildren) return foundInChildren
35
34
  }
36
35
 
37
- // If the item was not found, return null.
38
36
  return null
39
37
  }
40
38
 
@@ -63,7 +61,7 @@ export function findItemByIndexArray(indices, items, fields) {
63
61
  *
64
62
  * @param {Array<integer>} position
65
63
  * @param {Array<*>} items
66
- * @param {import('@rokkit/core').FieldMapping} fields
64
+ * @param {import('./types').FieldMapping} fields
67
65
  * @returns
68
66
  */
69
67
  export function findNearestItemBefore(position, items, fields) {
@@ -74,7 +72,7 @@ export function findNearestItemBefore(position, items, fields) {
74
72
  let result
75
73
  if (index > 0) {
76
74
  index -= 1
77
- if (position.length == 1) {
75
+ if (position.length === 1) {
78
76
  return findLastVisibleChild(items[index], [index], fields)
79
77
  }
80
78
 
@@ -90,7 +88,7 @@ export function findNearestItemBefore(position, items, fields) {
90
88
  *
91
89
  * @param {*} parent
92
90
  * @param {Array<integer>} position
93
- * @param {import('@rokkit/core').FieldMapping} fields
91
+ * @param {import('./types').FieldMapping} fields
94
92
  * @returns
95
93
  */
96
94
  export function findLastVisibleChild(parent, position, fields) {
@@ -197,7 +195,7 @@ function getNextSiblingOrAncestor(position, items, fields) {
197
195
  /**
198
196
  * Creates a mapped list from an items array and a fields mapping.
199
197
  * @param {Array<Object>} items - The items array.
200
- * @param {import('@rokkit/core').FieldMapping} fields - The fields mapping.
198
+ * @param {import('./types').FieldMapping} fields - The fields mapping.
201
199
  * @returns {Object} The mapped list.
202
200
  */
203
201
  export function mappedList(items, fields) {
package/src/mapping.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defaultFields } from './constants'
2
- import { isObject } from '.'
2
+ import { toString, isObject } from './utils'
3
3
 
4
4
  /**
5
5
  * Get the component to be used to render the item.
@@ -10,7 +10,7 @@ import { isObject } from '.'
10
10
  * @param {import('./types.js').ComponentMap} using
11
11
  */
12
12
  export function getComponent(value, fields, using) {
13
- return fields.component && typeof value == 'object'
13
+ return fields.component && isObject(value)
14
14
  ? using[value[fields.component]] ?? using.default
15
15
  : using.default
16
16
  }
@@ -25,7 +25,7 @@ export function getIcon(value, fields = defaultFields) {
25
25
  if (fields.icon === undefined || typeof (value ?? '') !== 'object') return null
26
26
  // console.log(fields.icon, fields.state, value[fields.icon][value[fields.state]])
27
27
  const name =
28
- typeof value[fields.icon] == 'object'
28
+ typeof value[fields.icon] === 'object'
29
29
  ? value[fields.icon][value[fields.state]]
30
30
  : value[fields.icon]
31
31
  return fields.iconPrefix ? [fields.iconPrefix, name].join('-') : name
@@ -47,20 +47,36 @@ export function getValue(node, fields = defaultFields) {
47
47
  * Get the text for the item. If the text is an object,
48
48
  * it will use the field mapping to determine which attribute to get.
49
49
  *
50
- * @param {*} node
50
+ * @param {*} node
51
51
  * @param {import('./types').FieldMapping} fields
52
- * @returns {*}
52
+ * @returns {string}
53
53
  */
54
54
  export function getText(node, fields = defaultFields) {
55
- let value = typeof node === 'object' && node !== null ? node[fields.text] : node
56
-
57
- return value != null
58
- ? isObject(value)
59
- ? JSON.stringify(value, null, 2)
60
- : value.toString()
61
- : value
55
+ const value = isObject(node) ? node[fields.text] : node
56
+ return value
57
+ // return value != null
58
+ // ? isObject(value)
59
+ // ? JSON.stringify(value, null, 2)
60
+ // : value.toString()
61
+ // : value
62
62
  }
63
63
 
64
+ /**
65
+ * Get the formatted text for the item. If the text is an object, use the field mapping to determine
66
+ * which attribute to get currency. Use the formatter or identity function to format the text.
67
+ *
68
+ * @param {*} node
69
+ * @param {import('./types').FieldMapping} fields
70
+ * @param {function} formatter
71
+ * @returns {*}
72
+ */
73
+ export function getFormattedText(node, fields = defaultFields, formatter = toString) {
74
+ const value = isObject(node) ? node[fields.text] : node
75
+ const currency = getAttribute(node, fields.currency)
76
+ const formatValue = typeof formatter === 'function' ? formatter : toString
77
+
78
+ return currency ? formatValue(value, currency) : formatValue(value)
79
+ }
64
80
  /**
65
81
  * Gets the attribute from the node
66
82
  * @param {*} node
@@ -68,7 +84,7 @@ export function getText(node, fields = defaultFields) {
68
84
  * @returns {*}
69
85
  */
70
86
  export function getAttribute(node, attr) {
71
- return typeof node === 'object' && node !== null && attr != null ? node[attr] : null
87
+ return typeof node === 'object' && node !== null && attr !== null ? node[attr] : null
72
88
  }
73
89
  /**
74
90
  * Check if the current item is a parent
@@ -79,7 +95,7 @@ export function getAttribute(node, attr) {
79
95
  */
80
96
  export function hasChildren(item, fields) {
81
97
  return (
82
- item != null &&
98
+ item !== null &&
83
99
  typeof item === 'object' &&
84
100
  fields.children in item &&
85
101
  Array.isArray(item[fields.children])
@@ -94,7 +110,7 @@ export function hasChildren(item, fields) {
94
110
  * @returns {boolean}
95
111
  */
96
112
  export function isExpanded(item, fields) {
97
- if (item == null) return false
113
+ if (item === null) return false
98
114
  if (!hasChildren(item, fields)) return false
99
115
  if (fields.isOpen in item) {
100
116
  return item[fields.isOpen]
package/src/string.js CHANGED
@@ -25,8 +25,8 @@ export function toPascalCase(text) {
25
25
  /**
26
26
  * Convert a PascalCase string to snake case with separator as hyphen
27
27
  *
28
- * @param {Strin} text
29
- * @returns
28
+ * @param {string} text
29
+ * @returns {string}
30
30
  */
31
31
  export function toHyphenCase(text) {
32
32
  return text
@@ -40,15 +40,16 @@ export function toHyphenCase(text) {
40
40
  *
41
41
  * @param {String} a hyphen separates string
42
42
  * @param {String} b hyphen separates string
43
- * @returns
43
+ * @param {string} separator - separator to split the string
44
+ * @returns {Number} -1, 0, 1 based on comparison
44
45
  */
45
- export function sortByParts(a, b) {
46
- const partsOfA = a.split('-')
47
- const partsOfB = b.split('-')
46
+ export function sortByParts(a, b, separator = '-') {
47
+ const partsOfA = a.split(separator)
48
+ const partsOfB = b.split(separator)
48
49
 
49
50
  let result = compareStrings(partsOfA[0], partsOfB[0])
50
- if (result == 0) result = partsOfA.length - partsOfB.length
51
- if (result == 0) result = compareStrings(a, b)
51
+ if (result === 0) result = partsOfA.length - partsOfB.length
52
+ if (result === 0) result = compareStrings(a, b)
52
53
  return result
53
54
  }
54
55
 
package/src/theme.js CHANGED
@@ -60,71 +60,130 @@ export function themeColors(modifier = 'none') {
60
60
  colors.neutral = {
61
61
  ...colors.neutral,
62
62
  // contrast: fn(`var(--neutral-800)`),
63
- zebra: fn(`var(--neutral-zebra)`)
63
+ zebra: fn('var(--neutral-zebra)')
64
64
  }
65
65
 
66
66
  return colors
67
67
  }
68
68
 
69
+ /**
70
+ * Creates an array of shade mapping objects for a given theme variant and mode.
71
+ * Each object represents a CSS custom property (variable) with its value set based on a provided condition.
72
+ *
73
+ * @param {string} variant - The name of the theme variant (e.g., 'primary', 'secondary').
74
+ * @param {'light' | 'dark'} mode - The theme mode for which the mappings are being created.
75
+ * @param {function(number): string} valueCondition - A function that takes a shade value and returns the color value
76
+ * based on the condition appropriate for light or dark mode.
77
+ * @returns {Array<{key: string, value: string, mode: string}>} An array of objects, where each object contains
78
+ * key, value, and mode properties corresponding to
79
+ * a CSS custom property definition.
80
+ */
81
+ function createShadeMappings(variant, mode, valueCondition) {
82
+ return shades.map((shade) => ({
83
+ key: `--on-${variant}-${shade}`,
84
+ value: valueCondition(shade),
85
+ mode: mode
86
+ }))
87
+ }
88
+
89
+ /**
90
+ * Generates contrast colors for light and dark modes based on a given palette. Each color variant in the
91
+ * palette is mapped to either a light or dark contrast color depending on the shade's value.
92
+ *
93
+ * @param {string} [light='#ffffff'] - The default light color used when the shade is >= 500 in light mode or <= 500 in dark mode.
94
+ * @param {string} [dark='#000000'] - The default dark color used when the shade is < 500 in light mode or > 500 in dark mode.
95
+ * @param {Array<string>} [palette=defaultPalette] - An array of color variant names to generate contrast colors for.
96
+ * @returns {Array<Object>} An array containing contrast color rules organized by light and dark modes for each variant in the palette.
97
+ */
69
98
  export function contrastColors(light = '#ffffff', dark = '#000000', palette = defaultPalette) {
70
99
  const colors = palette
71
100
  .flatMap((variant) => [
72
- shades.map((shade) => ({
73
- key: `--on-${variant}-${shade}`,
74
- value: shade < 500 ? dark : light,
75
- mode: 'light'
76
- })),
77
- shades.map((shade) => ({
78
- key: `--on-${variant}-${shade}`,
79
- value: shade > 500 ? dark : light,
80
- mode: 'dark'
81
- }))
101
+ createShadeMappings(variant, 'light', (shade) => (shade < 500 ? dark : light)),
102
+ createShadeMappings(variant, 'dark', (shade) => (shade > 500 ? dark : light))
82
103
  ])
83
104
  .reduce((acc, item) => [...acc, ...item], [])
84
105
  return colors
85
106
  }
107
+ /**
108
+ * Generates color rules for a specific theme variant, for both light and dark modes.
109
+ *
110
+ * @param {string} variant - The name of the variant to generate rules for.
111
+ * @param {Object} colors - The object containing color definitions.
112
+ * @param {Object} mapping - An object that maps variant names to color property names.
113
+ * @returns {Array<Object>} An array containing the color rules for both light and dark modes.
114
+ */
115
+ function generateColorRules(variant, colors, mapping) {
116
+ return shades.flatMap((shade, index) => [
117
+ {
118
+ key: `--${variant}-${shade}`,
119
+ value: colors[mapping[variant]][shade],
120
+ mode: 'light'
121
+ },
122
+ {
123
+ key: `--${variant}-${shade}`,
124
+ value: colors[mapping[variant]][shades[shades.length - index - 1]],
125
+ mode: 'dark'
126
+ }
127
+ ])
128
+ }
129
+
130
+ /**
131
+ * Filters the rules for a specific mode and transforms them into an object mapping
132
+ * CSS variable names to their values.
133
+ *
134
+ * @param {Array<Object>} rules - The array of rules to filter and transform.
135
+ * @param {'light' | 'dark'} mode - The mode to filter by.
136
+ * @returns {Object} An object containing the rules specific to the provided mode.
137
+ */
138
+ function filterRulesByMode(rules, mode) {
139
+ return rules
140
+ .filter((rule) => rule.mode === mode)
141
+ .reduce((acc, { key, value }) => ({ ...acc, [key]: value }), {})
142
+ }
86
143
 
144
+ /**
145
+ * Creates a theme variant object with a given mode, a collection of color rules, and additional colors.
146
+ *
147
+ * @param {string} name - The base name for the theme variant.
148
+ * @param {'light' | 'dark'} mode - The mode of the theme variant.
149
+ * @param {Object} colors - The object containing color rules for the theme.
150
+ * @param {Object} extraColors - Any additional color properties for the theme.
151
+ * @returns {Array} An array where the first element is the theme's name and the second element
152
+ * is an object containing all color rules and extra properties for the theme variant.
153
+ */
154
+ function createThemeVariant(name, mode, colors, extraColors) {
155
+ return [
156
+ `${name}-mode-${mode}`,
157
+ {
158
+ ...colors,
159
+ ...extraColors,
160
+ '--plot-background': 'var(--neutral-200)'
161
+ }
162
+ ]
163
+ }
164
+
165
+ /**
166
+ * Constructs and returns the light and dark theme variants based on provided color mapping and color definitions.
167
+ *
168
+ * @param {string} name - The base name for the theme, defaults to 'rokkit' if not provided.
169
+ * @param {Object} [mapping=defaultThemeMapping] - An object mapping variant names to color property names.
170
+ * @param {Object} [colors=defaultColors] - The object containing default color definitions.
171
+ * @returns {Array<Array>} An array containing two arrays, one for the light theme variant and another for the dark theme.
172
+ */
87
173
  export function themeRules(name = 'rokkit', mapping = defaultThemeMapping, colors = defaultColors) {
88
174
  mapping = { ...defaultThemeMapping, ...mapping }
89
175
  const variants = Object.keys(mapping)
90
- const rules = variants
91
- .flatMap((variant) => [
92
- shades.map((shade) => ({
93
- key: `--${variant}-${shade}`,
94
- value: colors[mapping[variant]][shade],
95
- mode: 'light'
96
- })),
97
- shades.map((shade, i) => ({
98
- key: `--${variant}-${shade}`,
99
- value: colors[mapping[variant]][shades[shades.length - i - 1]],
100
- mode: 'dark'
101
- }))
102
- ])
103
- .reduce((acc, item) => [...acc, ...item], [])
104
176
 
105
- const light = rules
106
- .filter((rule) => rule.mode === 'light')
107
- .reduce((acc, item) => ({ ...acc, [item.key]: item.value }), {})
108
- const dark = rules
109
- .filter((rule) => rule.mode === 'dark')
110
- .reduce((acc, item) => ({ ...acc, [item.key]: item.value }), {})
177
+ const rules = variants.reduce(
178
+ (acc, variant) => [...acc, ...generateColorRules(variant, colors, mapping)],
179
+ []
180
+ )
111
181
 
112
- return [
113
- [
114
- `${name}-mode-light`,
115
- {
116
- ...light,
117
- ...syntaxColors['one-dark'].light,
118
- '--plot-background': 'var(--neutral-200)'
119
- }
120
- ],
121
- [
122
- `${name}-mode-dark`,
123
- {
124
- ...dark,
125
- ...syntaxColors['one-dark'].dark,
126
- '--plot-background': 'var(--neutral-200)'
127
- }
128
- ]
129
- ]
182
+ const lightRules = filterRulesByMode(rules, 'light')
183
+ const darkRules = filterRulesByMode(rules, 'dark')
184
+
185
+ const lightTheme = createThemeVariant(name, 'light', lightRules, syntaxColors['one-dark'].light)
186
+ const darkTheme = createThemeVariant(name, 'dark', darkRules, syntaxColors['one-dark'].dark)
187
+
188
+ return [lightTheme, darkTheme]
130
189
  }
package/src/ticks.js CHANGED
@@ -19,8 +19,8 @@ export function generateTicks(
19
19
  // majorTickStep = +majorTickStep
20
20
  const length = 1 + Math.ceil((upperBound - lowerBound) / minorTickStep)
21
21
  return Array.from({ length }, (_, i) => {
22
- const value = i == length - 1 ? upperBound : lowerBound + minorTickStep * i
23
- const major = i == 0 || i == length - 1 || i % majorTickStep == 0
22
+ const value = i === length - 1 ? upperBound : lowerBound + minorTickStep * i
23
+ const major = i === 0 || i === length - 1 || i % majorTickStep === 0
24
24
  return {
25
25
  value,
26
26
  label: major ? value : '',
package/src/types.js CHANGED
@@ -1,9 +1,18 @@
1
+ /**
2
+ * Component map to be used to render the item.
3
+ * @typedef {Object<string, import('svelte').SvelteComponent>} ComponentMap
4
+ */
5
+
1
6
  /**
2
7
  * Options for the sort order of the column.
3
8
  *
4
9
  * @typedef {'ascending'|'descending'|'none'} SortOptions
5
10
  */
6
11
 
12
+ /**
13
+ * @typedef {'checked'|'unchecked'|'indeterminate'} SelectionState
14
+ */
15
+
7
16
  /**
8
17
  * Options for the horizontal alignment of the column content.
9
18
  *
@@ -38,11 +47,6 @@
38
47
  * @property {FieldMapping} [fields] Field mapping to be used on children in the next level
39
48
  */
40
49
 
41
- /**
42
- * Component map to be used to render the item.
43
- * @typedef {Object<string, import('svelte').SvelteComponent>} ComponentMap
44
- */
45
-
46
50
  /**
47
51
  * Column metadata for the table.
48
52
  *
@@ -64,11 +68,15 @@
64
68
  * Track the state of a row in the table.
65
69
  *
66
70
  * @typedef {Object} RowState
67
- * @property {boolean} visible - Indicates whether the node is visible (true/false).
68
- * @property {string} [label] - The label of the hierarchy node.
69
- * @property {boolean} is_parent - Indicates if this node is a parent (true/false).
70
- * @property {boolean} is_collapsed - Indicates whether the node is collapsed (true/false).
71
- * @property {number[]} levels - Array of hierarchy indices, including parent indices.
71
+ * @property {number} index - The index of the node in the flat list.
72
+ * @property {number} depth - The depth of the node in the hierarchy.
73
+ * @property {string} [value] - The value of the hierarchy node.
74
+ * @property {boolean} [isHidden] - Indicates whether the node is visible (true/false).
75
+ * @property {boolean} [isParent] - Indicates if this node is a parent (true/false).
76
+ * @property {boolean} [isExpanded] - Indicates whether the node is expanded (true/false).
77
+ * @property {number} [parentIndex] - The index of the parent node in the flat list.
78
+ * @property {SelectionState} [selected] - Indicates whether the node is selected (true/false/indeterminate).
79
+ * @property {Array<number>} childred - The indices of the children in the flat list.
72
80
  */
73
81
 
74
82
  /**
package/src/utils.js CHANGED
@@ -17,6 +17,26 @@ export function isObject(val) {
17
17
  return typeof val === 'object' && val !== null && !(val instanceof Date)
18
18
  }
19
19
 
20
+ /**
21
+ * Converts the value to a string. If the value is an object, it will convert it to a JSON string.
22
+ *
23
+ * @param {*} value
24
+ * @returns {string}
25
+ */
26
+ export function toString(value) {
27
+ if (value === null || value === undefined) return value
28
+ if (isObject(value)) return JSON.stringify(value, null, 2)
29
+ return value.toString()
30
+ }
31
+
32
+ /**
33
+ * Generates icon shortcuts for a collection of icons
34
+ *
35
+ * @param {string[]} icons
36
+ * @param {string} collection
37
+ * @param {string} variants
38
+ * @returns {Object}
39
+ */
20
40
  export function iconShortcuts(icons, collection, variants) {
21
41
  const suffix = variants ? `-${variants}` : ''
22
42
  const shortcuts = !collection
@@ -32,6 +52,13 @@ export function iconShortcuts(icons, collection, variants) {
32
52
  return shortcuts
33
53
  }
34
54
 
55
+ /**
56
+ * Scales the path by the size
57
+ *
58
+ * @param {number} size
59
+ * @param {string|number} x
60
+ * @returns {string|number}
61
+ */
35
62
  export function scaledPath(size, x) {
36
63
  if (Array.isArray(x)) return x.map((x) => scaledPath(size, x)).join(' ')
37
64
  return typeof x === 'number' ? x * size : x
@@ -1,44 +0,0 @@
1
- export const syntaxColors = {
2
- 'one-dark': {
3
- dark: {
4
- '--tab-size': '2',
5
- // '--code-bg': 'var(--neutral-100)',
6
- '--code-fill': 'var(--neutral-100)',
7
- '--code-normal': '#e06c75',
8
- '--code-string': '#98c379',
9
- '--code-number': '#d19a66',
10
- '--code-atrule': 'var(--code-string)',
11
- '--code-keyword': '#c678dd',
12
- '--code-comment': '#5c6370',
13
- '--code-property': '#d19a66',
14
- '--code-selector': 'var(--code-keyword)',
15
- '--code-operator': '#56b6c2',
16
- '--code-function': '#61afef',
17
- '--code-gutter-marker': 'black',
18
- '--code-gutter-subtle': '#999',
19
- '--code-cursor': '#24292e',
20
- '--code-cursor-block': 'rgba(20, 255, 20, 0.5)',
21
- '--code-linenumbers': 'rgba(27, 31, 35, 0.3)'
22
- },
23
- light: {
24
- '--tab-size': '2',
25
- // '--code-bg': 'var(--neutral-100)',
26
- '--code-fill': 'var(--neutral-100)',
27
- '--code-normal': '#333333',
28
- '--code-string': '#9D8248',
29
- '--code-number': '#71A15D',
30
- '--code-atrule': 'var(--code-string)',
31
- '--code-keyword': '#3080B5',
32
- '--code-comment': '#969896',
33
- '--code-property': '#63a35c',
34
- '--code-selector': 'var(--code-keyword)',
35
- '--code-operator': '#bf5625',
36
- '--code-function': '#a71d5d',
37
- '--code-gutter-marker': 'black',
38
- '--code-gutter-subtle': '#999',
39
- '--code-cursor': '#24292e',
40
- '--code-cursor-block': 'rgba(20, 255, 20, 0.5)',
41
- '--code-linenumbers': 'rgba(27, 31, 35, 0.3)'
42
- }
43
- }
44
- }
@@ -1,275 +0,0 @@
1
- export const defaultTailwindColors = {
2
- amber: {
3
- 50: '#fffbeb',
4
- 100: '#fef3c7',
5
- 200: '#fde68a',
6
- 300: '#fcd34d',
7
- 400: '#fbbf24',
8
- 500: '#f59e0b',
9
- 600: '#d97706',
10
- 700: '#b45309',
11
- 800: '#92400e',
12
- 900: '#78350f',
13
- 950: '#451a03'
14
- },
15
- blue: {
16
- 50: '#eff6ff',
17
- 100: '#dbeafe',
18
- 200: '#bfdbfe',
19
- 300: '#93c5fd',
20
- 400: '#60a5fa',
21
- 500: '#3b82f6',
22
- 600: '#2563eb',
23
- 700: '#1d4ed8',
24
- 800: '#1e40af',
25
- 900: '#1e3a8a',
26
- 950: '#172554'
27
- },
28
- cyan: {
29
- 50: '#ecfeff',
30
- 100: '#cffafe',
31
- 200: '#a5f3fc',
32
- 300: '#67e8f9',
33
- 400: '#22d3ee',
34
- 500: '#06b6d4',
35
- 600: '#0891b2',
36
- 700: '#0e7490',
37
- 800: '#155e75',
38
- 900: '#164e63',
39
- 950: '#083344'
40
- },
41
- emerald: {
42
- 50: '#ecfdf5',
43
- 100: '#d1fae5',
44
- 200: '#a7f3d0',
45
- 300: '#6ee7b7',
46
- 400: '#34d399',
47
- 500: '#10b981',
48
- 600: '#059669',
49
- 700: '#047857',
50
- 800: '#065f46',
51
- 900: '#064e3b',
52
- 950: '#022c22'
53
- },
54
- fuscia: {
55
- 50: '#fdf4ff',
56
- 100: '#fae8ff',
57
- 200: '#f5d0fe',
58
- 300: '#f0abfc',
59
- 400: '#e879f9',
60
- 500: '#d946ef',
61
- 600: '#c026d3',
62
- 700: '#a21caf',
63
- 800: '#86198f',
64
- 900: '#701a75',
65
- 950: '#4a044e'
66
- },
67
- gray: {
68
- 50: '#f9fafb',
69
- 100: '#f3f4f6',
70
- 200: '#e5e7eb',
71
- 300: '#d1d5db',
72
- 400: '#9ca3af',
73
- 500: '#6b7280',
74
- 600: '#4b5563',
75
- 700: '#374151',
76
- 800: '#1f2937',
77
- 900: '#111827',
78
- 950: '#00060c'
79
- },
80
- green: {
81
- 50: '#f0fdf4',
82
- 100: '#dcfce7',
83
- 200: '#bbf7d0',
84
- 300: '#86efac',
85
- 400: '#4ade80',
86
- 500: '#22c55e',
87
- 600: '#16a34a',
88
- 700: '#15803d',
89
- 800: '#166534',
90
- 900: '#14532d',
91
- 950: '#052e16'
92
- },
93
- indigo: {
94
- 50: '#eef2ff',
95
- 100: '#e0e7ff',
96
- 200: '#c7d2fe',
97
- 300: '#a5b4fc',
98
- 400: '#818cf8',
99
- 500: '#6366f1',
100
- 600: '#4f46e5',
101
- 700: '#4338ca',
102
- 800: '#3730a3',
103
- 900: '#312e81',
104
- 950: '#1e1b4b'
105
- },
106
- lime: {
107
- 50: '#f7fee7',
108
- 100: '#ecfccb',
109
- 200: '#d9f99d',
110
- 300: '#bef264',
111
- 400: '#a3e635',
112
- 500: '#84cc16',
113
- 600: '#65a30d',
114
- 700: '#4d7c0f',
115
- 800: '#3f6212',
116
- 900: '#365314',
117
- 950: '#1a2e05'
118
- },
119
- orange: {
120
- 50: '#fff7ed',
121
- 100: '#ffedd5',
122
- 200: '#fed7aa',
123
- 300: '#fdba74',
124
- 400: '#fb923c',
125
- 500: '#f97316',
126
- 600: '#ea580c',
127
- 700: '#c2410c',
128
- 800: '#9a3412',
129
- 900: '#7c2d12',
130
- 950: '#431407'
131
- },
132
- pink: {
133
- 50: '#fdf2f8',
134
- 100: '#fce7f3',
135
- 200: '#fbcfe8',
136
- 300: '#f9a8d4',
137
- 400: '#f472b6',
138
- 500: '#ec4899',
139
- 600: '#db2777',
140
- 700: '#be185d',
141
- 800: '#9d174d',
142
- 900: '#831843',
143
- 950: '#500724'
144
- },
145
- purple: {
146
- 50: '#faf5ff',
147
- 100: '#f3e8ff',
148
- 200: '#e9d5ff',
149
- 300: '#d8b4fe',
150
- 400: '#c084fc',
151
- 500: '#a855f7',
152
- 600: '#9333ea',
153
- 700: '#7e22ce',
154
- 800: '#6b21a8',
155
- 900: '#581c87',
156
- 950: '#3b0764'
157
- },
158
- red: {
159
- 50: '#fef2f2',
160
- 100: '#fee2e2',
161
- 200: '#fecaca',
162
- 300: '#fca5a5',
163
- 400: '#f87171',
164
- 500: '#ef4444',
165
- 600: '#dc2626',
166
- 700: '#b91c1c',
167
- 800: '#991b1b',
168
- 900: '#7f1d1d',
169
- 950: '#450a0a'
170
- },
171
- rose: {
172
- 50: '#fff1f2',
173
- 100: '#ffe4e6',
174
- 200: '#fecdd3',
175
- 300: '#fda4af',
176
- 400: '#fb7185',
177
- 500: '#f43f5e',
178
- 600: '#e11d48',
179
- 700: '#be123c',
180
- 800: '#9f1239',
181
- 900: '#881337',
182
- 950: '#4c0519'
183
- },
184
- sky: {
185
- 50: '#f0f9ff',
186
- 100: '#e0f2fe',
187
- 200: '#bae6fd',
188
- 300: '#7dd3fc',
189
- 400: '#38bdf8',
190
- 500: '#0ea5e9',
191
- 600: '#0284c7',
192
- 700: '#0369a1',
193
- 800: '#075985',
194
- 900: '#0c4a6e',
195
- 950: '#082f49'
196
- },
197
- slate: {
198
- 50: '#f8fafc',
199
- 100: '#f1f5f9',
200
- 200: '#e2e8f0',
201
- 300: '#cbd5e0',
202
- 400: '#94a3b8',
203
- 500: '#64748b',
204
- 600: '#475569',
205
- 700: '#334155',
206
- 800: '#1e293b',
207
- 900: '#0f172a',
208
- 950: '#020617'
209
- },
210
- stone: {
211
- 50: '#fafaf9',
212
- 100: '#f5f5f4',
213
- 200: '#e7e5e4',
214
- 300: '#d6d3d1',
215
- 400: '#a8a29e',
216
- 500: '#78716c',
217
- 600: '#57534e',
218
- 700: '#44403c',
219
- 800: '#292524',
220
- 900: '#1c1917',
221
- 950: '#0c0a09'
222
- },
223
- teal: {
224
- 50: '#f0fdfa',
225
- 100: '#ccfbf1',
226
- 200: '#99f6e4',
227
- 300: '#5eead4',
228
- 400: '#2dd4bf',
229
- 500: '#14b8a6',
230
- 600: '#0d9488',
231
- 700: '#0f766e',
232
- 800: '#115e59',
233
- 900: '#134e4a',
234
- 950: '#042f2e'
235
- },
236
- violet: {
237
- 50: '#f5f3ff',
238
- 100: '#ede9fe',
239
- 200: '#ddd6fe',
240
- 300: '#c4b5fd',
241
- 400: '#a78bfa',
242
- 500: '#8b5cf6',
243
- 600: '#7c3aed',
244
- 700: '#6d28d9',
245
- 800: '#5b21b6',
246
- 900: '#4c1d95',
247
- 950: '#2e1065'
248
- },
249
- yellow: {
250
- 50: '#fefce8',
251
- 100: '#fef9c3',
252
- 200: '#fef08a',
253
- 300: '#fde047',
254
- 400: '#facc15',
255
- 500: '#eab308',
256
- 600: '#ca8a04',
257
- 700: '#a16207',
258
- 800: '#854d0e',
259
- 900: '#713f12',
260
- 950: '#422006'
261
- },
262
- zinc: {
263
- 50: '#fafafa',
264
- 100: '#f4f4f5',
265
- 200: '#e4e4e7',
266
- 300: '#d4d4d8',
267
- 400: '#a1a1aa',
268
- 500: '#71717a',
269
- 600: '#52525b',
270
- 700: '#3f3f46',
271
- 800: '#27272a',
272
- 900: '#18181b',
273
- 950: '#000000'
274
- }
275
- }
package/src/formatter.js DELETED
@@ -1,47 +0,0 @@
1
- import { identity } from 'ramda'
2
-
3
- /**
4
- * Creates a formatter function that formats a value according to the specified type and optional locale settings.
5
- * Supported types include 'default' (no formatting), 'integer', 'number', 'date', 'time', and 'currency'.
6
- *
7
- * The function is curried, which means it can be partially applied with some arguments and reused
8
- * to format different values with the same settings.
9
- *
10
- * @param {string} type - The type of the formatter to use (e.g., 'integer', 'number', 'date', 'time', 'currency').
11
- * @param {string} [language='en-US'] - Optional IETF language tag used for locale-specific formatting.
12
- * @param {string} [currency='USD'] - Optional currency code which is relevant when the type is 'currency'.
13
- * @param {number} [decimalPlaces=2] - Optional number of decimal places to show with number and currency formatting.
14
- * @param {number|Date} value - The value to format, it should be of a type corresponding to the formatter type.
15
- * @returns {*} - The formatted value as a string or the original value if formatting is not applicable.
16
- */
17
- export function createFormatter(type, language = 'en-US', decimalPlaces = 2, currency) {
18
- const formatWithLocaleOptions = (options, val) => val.toLocaleString(language, options)
19
- const formatCurrency = (val, currency = 'USD') =>
20
- val.toLocaleString(language, {
21
- style: 'currency',
22
- currency,
23
- minimumFractionDigits: decimalPlaces,
24
- maximumFractionDigits: decimalPlaces
25
- })
26
-
27
- const formatters = {
28
- integer: (val) => formatWithLocaleOptions({ maximumFractionDigits: 0 }, val), // Integer without decimals
29
- number: (val) =>
30
- formatWithLocaleOptions(
31
- {
32
- minimumFractionDigits: decimalPlaces,
33
- maximumFractionDigits: decimalPlaces
34
- },
35
- val
36
- ), // Number with fixed decimal places
37
- date: (val) => val.toLocaleDateString(language), // Locale-specific date format
38
- time: (val) => val.toLocaleTimeString(language), // Locale-specific time format
39
- currency: currency ? (val) => formatCurrency(val, currency) : formatCurrency
40
- // Currency with fixed decimal places and currency symbol
41
- }
42
- if (type in formatters) return formatters[type]
43
- return identity
44
- // return propOr(identity, type, formatters)(value) // Apply the formatter based on the type
45
- }
46
-
47
- // export
package/src/tabular.js DELETED
@@ -1,64 +0,0 @@
1
- import { createFormatter } from './formatter'
2
-
3
- export function tabular(data, columns, options) {
4
- const { path, separator = '/', actions } = options ?? {}
5
-
6
- let metadata = columns
7
- if (!Array.isArray(columns) || columns.length === 0) metadata = deriveColumnMetadata(data)
8
-
9
- return {
10
- data,
11
- columns: metadata,
12
- filter: () => {},
13
- sort: () => {}
14
- }
15
- }
16
-
17
- /**
18
- * Derives column metadata from the data to be used in a tabular component.
19
- *
20
- * @param {Array} data - The data to derive column metadata from.
21
- * @returns {Array<import('./types').ColumnMetadata>} - The derived column metadata.
22
- */
23
- export function deriveColumnMetadata(dataArray) {
24
- if (dataArray.length === 0) {
25
- return []
26
- }
27
-
28
- const firstRow = dataArray[0]
29
- const language = navigator.language || 'en-US' // Get the browser's language or default to 'en-US'
30
-
31
- const columns = []
32
-
33
- for (const key in firstRow) {
34
- // if (Object.prototype.hasOwnProperty.call(firstRow, key)) {
35
- const dataType = typeof firstRow[key]
36
- const formatter = createFormatter(dataType, language)
37
- const fields = { text: key }
38
-
39
- if (key.endsWith('_currency')) {
40
- const currencyColumn = key
41
- const baseColumn = key.replace(/_currency$/, '')
42
-
43
- // Find the existing column and update its currency attribute
44
- const existingColumn = columns.find((column) => column.name === baseColumn)
45
- existingColumn.dataType = 'currency'
46
- existingColumn.formatter = createFormatter('currency', language, 2)
47
- if (existingColumn) {
48
- existingColumn.fields = {
49
- ...existingColumn.fields,
50
- currency: currencyColumn
51
- }
52
- }
53
- } else {
54
- columns.push({
55
- name: key,
56
- dataType: dataType,
57
- fields,
58
- formatter
59
- })
60
- }
61
- }
62
-
63
- return columns
64
- }