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

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.94",
3
+ "version": "1.0.0-next.95",
4
4
  "description": "Core components, actions and stores for svelte apps.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -22,8 +22,8 @@
22
22
  "typescript": "^5.4.4",
23
23
  "vite": "^5.2.8",
24
24
  "vitest": "~1.4.0",
25
- "shared-config": "1.0.0-next.94",
26
- "validators": "1.0.0-next.94"
25
+ "shared-config": "1.0.0-next.95",
26
+ "validators": "1.0.0-next.95"
27
27
  },
28
28
  "files": [
29
29
  "src/**/*.js",
@@ -35,7 +35,7 @@
35
35
  "./package.json": "./package.json",
36
36
  "./constants": "./src/constants.js",
37
37
  ".": {
38
- "types": "./dist/types.d.ts",
38
+ "types": "./dist/index.d.ts",
39
39
  "import": "./src/index.js",
40
40
  "svelte": "./src/index.js"
41
41
  }
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import './types'
1
+ export * from './types'
2
2
  export * from './constants'
3
3
  export * from './nested'
4
4
  export * from './mapping'
@@ -2,11 +2,25 @@ import { defaultFields } from './constants'
2
2
  import { isExpanded, hasChildren, getAttribute } from './mapping'
3
3
  import { equals } from 'ramda'
4
4
 
5
+ /**
6
+ * Checks if a specifc attribute of an item matches a value.
7
+ *
8
+ * @param {Object} item - The item.
9
+ * @param {string} attr - The attribute to check.
10
+ */
5
11
  function isMatch(item, attr, value) {
6
12
  const itemValue = attr ? getAttribute(item, attr) : item
7
13
  return equals(itemValue, value)
8
14
  }
9
15
 
16
+ /**
17
+ * Traverses the tree to find an item by value.
18
+ * @param {Array} items - The items array.
19
+ * @param {Object} fields - The fields mapping.
20
+ * @param {any} value - The value to find.
21
+ * @param {Array} position - The current position in the tree.
22
+ * @returns {Object} The found item, or null if not found.
23
+ */
10
24
  function findInChildren(item, index, fields, value, attr, position) {
11
25
  if (hasChildren(item, fields)) {
12
26
  return findItemByValue(value, item[fields.children], fields.fields ?? fields, attr, [
@@ -69,7 +83,7 @@ export function findNearestItemBefore(position, items, fields) {
69
83
  if (position.length === 0) return { item: items[0], position: [0], fields }
70
84
 
71
85
  let index = position[position.length - 1]
72
- let result
86
+ let result = null
73
87
  if (index > 0) {
74
88
  index -= 1
75
89
  if (position.length === 1) {
@@ -85,6 +99,7 @@ export function findNearestItemBefore(position, items, fields) {
85
99
  }
86
100
 
87
101
  /**
102
+ * Returns the next sibling of the current item.
88
103
  *
89
104
  * @param {*} parent
90
105
  * @param {Array<integer>} position
@@ -114,8 +129,8 @@ export function findNearestItemAfter(position, items, fields) {
114
129
  if (items.length === 0) return null
115
130
  if (position.length === 0) return { item: items[0], position: [0], fields }
116
131
 
117
- let current = findItemByIndexArray(position, items, fields)
118
- let result
132
+ const current = findItemByIndexArray(position, items, fields)
133
+ let result = null
119
134
  if (isExpanded(current.item, current.fields)) {
120
135
  result = getFirstChild(current, position)
121
136
  } else if (position.length === 1) {
package/src/nested.js CHANGED
@@ -4,7 +4,7 @@ import { defaultFields } from './constants'
4
4
  export function flattenNestedList(items, fields = defaultFields, level = 0) {
5
5
  fields = { ...defaultFields, ...fields }
6
6
  let data = []
7
- items.map((item) => {
7
+ items.forEach((item) => {
8
8
  const children = item[fields.children] ?? []
9
9
  data = [
10
10
  ...data,
@@ -31,7 +31,7 @@ export function findValueFromPath(slug, data, fields) {
31
31
  let items = data
32
32
  let value = null
33
33
 
34
- keys.map((key, index) => {
34
+ keys.forEach((key, index) => {
35
35
  const match = items.find((item) => item[fields.key] === key)
36
36
  if (match) {
37
37
  if (index < keys.length - 1) {
package/src/parser.js CHANGED
@@ -19,11 +19,11 @@
19
19
  * @returns {RegExp} - The regular expression pattern to identify search filter elements.
20
20
  */
21
21
  export function getRegex() {
22
- let column = '[\\w]+'
23
- let operator = ':|>|<|>=|<=|=<|=>|=|!=|~|~\\*|!~|!~\\*'
24
- let value = '("[^"]+"|[^\\s=:<>!~*]+)'
22
+ const column = '[\\w]+'
23
+ const operator = ':|>|<|>=|<=|=<|=>|=|!=|~|~\\*|!~|!~\\*'
24
+ const value = '("[^"]+"|[^\\s=:<>!~*]+)'
25
25
 
26
- let pattern = `(?<group>((?<column>${column})\\s?(?<operator>${operator})\\s?)(?<value>${value}))`
26
+ const pattern = `(?<group>((?<column>${column})\\s?(?<operator>${operator})\\s?)(?<value>${value}))`
27
27
 
28
28
  return new RegExp(pattern, 'gm')
29
29
  }
package/src/string.js CHANGED
@@ -70,7 +70,7 @@ export function compareStrings(a, b) {
70
70
  * @returns {String} timestamp based unique id
71
71
  */
72
72
  export function uniqueId(prefix = '', separator = '-') {
73
- let pair = prefix && prefix.length > 0 ? [prefix] : []
73
+ const pair = prefix && prefix.length > 0 ? [prefix] : []
74
74
  pair.push(Date.now().toString(36))
75
75
  return pair.join(separator)
76
76
  }
package/src/theme.js CHANGED
@@ -47,8 +47,8 @@ export function stateColors(name, modifier = 'none') {
47
47
  export function themeColors(modifier = 'none') {
48
48
  const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
49
49
 
50
- let states = ['info', 'danger', 'warning', 'success', 'error']
51
- let variants = ['neutral', 'primary', 'secondary', 'accent']
50
+ const states = ['info', 'danger', 'warning', 'success', 'error']
51
+ const variants = ['neutral', 'primary', 'secondary', 'accent']
52
52
  let colors = states.reduce(
53
53
  (acc, state) => ({ ...acc, [state]: stateColors(state, modifier) }),
54
54
  {}
@@ -82,7 +82,7 @@ function createShadeMappings(variant, mode, valueCondition) {
82
82
  return shades.map((shade) => ({
83
83
  key: `--on-${variant}-${shade}`,
84
84
  value: valueCondition(shade),
85
- mode: mode
85
+ mode
86
86
  }))
87
87
  }
88
88
 
package/src/types.js CHANGED
@@ -85,3 +85,5 @@
85
85
  * @typedef {Object} RowStateMap
86
86
  * @property {RowState[]} rows - Flat list of hierarchy nodes.
87
87
  */
88
+
89
+ export default {}
package/src/utils.js CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * A function that performs no operations.
3
+ */
4
+ export function noop() {
5
+ // intentionally empty to support default actions
6
+ }
7
+
1
8
  /**
2
9
  * Generates a random id
3
10
  *
@@ -60,6 +67,6 @@ export function iconShortcuts(icons, collection, variants) {
60
67
  * @returns {string|number}
61
68
  */
62
69
  export function scaledPath(size, x) {
63
- if (Array.isArray(x)) return x.map((x) => scaledPath(size, x)).join(' ')
70
+ if (Array.isArray(x)) return x.map((v) => scaledPath(size, v)).join(' ')
64
71
  return typeof x === 'number' ? x * size : x
65
72
  }