@rokkit/core 1.0.0-next.35 → 1.0.0-next.36

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.35",
3
+ "version": "1.0.0-next.36",
4
4
  "description": "Core components, actions and stores for svelte apps.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -15,16 +15,17 @@
15
15
  "devDependencies": {
16
16
  "@sveltejs/vite-plugin-svelte": "^2.4.2",
17
17
  "@testing-library/svelte": "^4.0.3",
18
- "@vitest/coverage-c8": "^0.32.3",
19
- "@vitest/coverage-istanbul": "^0.32.3",
20
- "@vitest/ui": "~0.32.3",
18
+ "@vitest/coverage-c8": "^0.33.0",
19
+ "@vitest/coverage-istanbul": "^0.33.0",
20
+ "@vitest/coverage-v8": "^0.33.0",
21
+ "@vitest/ui": "~0.33.0",
21
22
  "jsdom": "^22.1.0",
22
- "svelte": "^4.0.1",
23
+ "svelte": "^4.0.5",
23
24
  "typescript": "^5.1.6",
24
25
  "validators": "latest",
25
- "vite": "^4.3.9",
26
- "vitest": "~0.32.3",
27
- "shared-config": "1.0.0-next.35"
26
+ "vite": "^4.4.4",
27
+ "vitest": "~0.33.0",
28
+ "shared-config": "1.0.0-next.36"
28
29
  },
29
30
  "files": [
30
31
  "src/**/*.js",
package/src/constants.js CHANGED
@@ -1,3 +1,25 @@
1
+ /**
2
+ * @type {import('./types).FieldMapping} Fields
3
+ */
4
+ export const defaultFields = {
5
+ id: 'id',
6
+ url: 'url',
7
+ text: 'text',
8
+ children: 'children',
9
+ icon: 'icon',
10
+ image: 'image',
11
+ component: 'component',
12
+ summary: 'summary',
13
+ notes: 'notes',
14
+ props: 'props',
15
+ target: 'target',
16
+ state: 'state',
17
+ isOpen: '_open',
18
+ isDeleted: '_deleted',
19
+ level: 'level',
20
+ parent: 'parent'
21
+ }
22
+
1
23
  export const defaultIcons = [
2
24
  'accordion-opened',
3
25
  'accordion-closed',
@@ -23,7 +45,16 @@ export const defaultIcons = [
23
45
  'navigate-left',
24
46
  'navigate-right',
25
47
  'navigate-up',
26
- 'navigate-down'
48
+ 'navigate-down',
49
+ 'state-error',
50
+ 'state-warning',
51
+ 'state-success',
52
+ 'state-info',
53
+ 'state-unknown',
54
+ 'validity-failed',
55
+ 'validity-warning',
56
+ 'validity-passed',
57
+ 'validity-unknown'
27
58
  ]
28
59
 
29
60
  export const defaultOptions = {
@@ -33,44 +64,6 @@ export const defaultOptions = {
33
64
  checked: 'checked'
34
65
  }
35
66
 
36
- /**
37
- * Structure to map custom fields for rendering
38
- *
39
- * @typedef FieldMapping
40
- * @property {string} [id='id'] - Unique id for the item
41
- * @property {string} [text='text'] - Attribute to identify the text to render
42
- * @property {string} [url='url'] - Attribute to identify a URL
43
- * @property {string} [icon='icon'] - Attribute to identify an icon class to render
44
- * @property {string} [image='image'] - Attribute to identify an image to render
45
- * @property {string} [children='children'] - Attribute to identify children of the current item
46
- * @property {string} [summary='summary']
47
- * @property {string} [notes='notes']
48
- * @property {string} [props='props']
49
- * @property {string} [isOpen='_open'] - Attribute to identify if the current item is open
50
- * @property {string} [level='level'] - Attribute to identify level of current item
51
- * @property {string} [parent='parent'] - Attribute to identify if the current item is a parent
52
- * @property {string} [isDeleted='_deleted'] - Attribute to identify if the current item is deleted
53
- * @property {FieldMapping} [fields?] - Field mapping to be used on children in the next level
54
- */
55
- export const defaultFields = {
56
- id: 'id',
57
- url: 'url',
58
- text: 'text',
59
- children: 'children',
60
- icon: 'icon',
61
- image: 'image',
62
- component: 'component',
63
- summary: 'summary',
64
- notes: 'notes',
65
- props: 'props',
66
- target: 'target',
67
- state: 'state',
68
- isOpen: '_open',
69
- isDeleted: '_deleted',
70
- level: 'level',
71
- parent: 'parent'
72
- }
73
-
74
67
  export const defaultKeyMap = {
75
68
  ArrowRight: 'open',
76
69
  ArrowLeft: 'close',
package/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import './types'
1
2
  export * from './constants'
2
3
  export * from './nested'
3
4
  export * from './mapping'
package/src/mapping.js CHANGED
@@ -1,11 +1,25 @@
1
1
  import { defaultFields } from './constants'
2
2
 
3
+ /**
4
+ * Get the component to be used to render the item.
5
+ * If the component is null or undefined, it will return the default component.
6
+ *
7
+ * @param {object|string} value
8
+ * @param {import('./types.js').FieldMapping} fields
9
+ * @param {import('./types.js').ComponentMap} using
10
+ */
3
11
  export function getComponent(value, fields, using) {
4
12
  return fields.component && typeof value == 'object'
5
13
  ? using[value[fields.component]] ?? using.default
6
14
  : using.default
7
15
  }
8
16
 
17
+ /**
18
+ * Get the icon for the item. If the icon is an object, it will use the state to determine which icon to use.
19
+ *
20
+ * @param {object|string} value
21
+ * @param {import('./types.js').FieldMapping} fields
22
+ */
9
23
  export function getIcon(value, fields = defaultFields) {
10
24
  if (fields.icon === undefined || typeof (value ?? '') !== 'object')
11
25
  return null
@@ -14,3 +28,9 @@ export function getIcon(value, fields = defaultFields) {
14
28
  ? value[fields.icon][value[fields.state]]
15
29
  : value[fields.icon]
16
30
  }
31
+
32
+ export function getId(node, fields = defaultFields) {
33
+ return typeof node === 'object' && node !== null
34
+ ? node[fields.id] ?? node[fields.text]
35
+ : node
36
+ }
package/src/types.js ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Structure to map custom fields for rendering. This is used to identofy the attributes for various purposes.
3
+ *
4
+ * @typedef FieldMapping
5
+ * @property {string} [id='id'] Unique id for the item
6
+ * @property {string} [text='text'] the text to render
7
+ * @property {string} [url='url'] a URL
8
+ * @property {string} [icon='icon'] icon to render
9
+ * @property {string} [image='image'] the image to render
10
+ * @property {string} [children='children'] children of the item
11
+ * @property {string} [summary='summary']
12
+ * @property {string} [notes='notes']
13
+ * @property {string} [props='props']
14
+ * @property {string} [isOpen='_open'] item is open or closed
15
+ * @property {string} [level='level'] level of item
16
+ * @property {string} [parent='parent'] item is a parent
17
+ * @property {string} [isDeleted='_deleted'] item is deleted
18
+ * @property {FieldMapping} [fields] Field mapping to be used on children in the next level
19
+ */
20
+
21
+ /**
22
+ * Component map to be used to render the item.
23
+ * @typedef {Object<string, import('svelte').SvelteComponent>} ComponentMap
24
+ */