@rokkit/forms 1.3.14 → 1.4.0
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/dist/FieldLayout.svelte
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { getContext, type Component } from 'svelte'
|
|
3
|
-
import { omit } from 'ramda'
|
|
4
3
|
import InputField from './InputField.svelte'
|
|
5
4
|
import FieldLayout from './FieldLayout.svelte'
|
|
6
5
|
|
|
@@ -32,8 +31,8 @@
|
|
|
32
31
|
|
|
33
32
|
let { value = $bindable({}), schema = {}, path = [], onchange }: Props = $props()
|
|
34
33
|
|
|
35
|
-
let Wrapper = registry.wrappers[schema.wrapper ?? ''] ?? registry.wrappers.default
|
|
36
|
-
|
|
34
|
+
let Wrapper = $derived(registry.wrappers[schema.wrapper ?? ''] ?? registry.wrappers.default)
|
|
35
|
+
const { wrapper: _w, elements: _e, key: _k, ...wrapperProps } = $derived(schema)
|
|
37
36
|
</script>
|
|
38
37
|
|
|
39
38
|
{#if !Array.isArray(schema.elements)}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { HTMLInputAttributes } from 'svelte/elements'
|
|
3
3
|
import { DEFAULT_STATE_ICONS } from '@rokkit/core'
|
|
4
|
-
import { isNil } from 'ramda'
|
|
5
4
|
|
|
6
5
|
type StateIcons = {
|
|
7
6
|
checked?: string
|
|
@@ -42,7 +41,7 @@
|
|
|
42
41
|
|
|
43
42
|
let checked = $derived(Boolean(value))
|
|
44
43
|
let stateIcons = $derived({ ...DEFAULT_STATE_ICONS.checkbox, ...icons })
|
|
45
|
-
let icon = $derived(stateIcons[
|
|
44
|
+
let icon = $derived(stateIcons[value === null || value === undefined ? 'unknown' : value ? 'checked' : 'unchecked'])
|
|
46
45
|
</script>
|
|
47
46
|
|
|
48
47
|
<div data-checkbox-root data-variant={variant}>
|
package/dist/lib/fields.js
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Pick only the listed keys from an object (native replacement for ramda.pick).
|
|
3
|
+
* @param {string[]} keys
|
|
4
|
+
* @param {Object} obj
|
|
5
|
+
* @returns {Object}
|
|
6
|
+
*/
|
|
7
|
+
function pick(keys, obj) {
|
|
8
|
+
const result = {}
|
|
9
|
+
for (const key of keys) {
|
|
10
|
+
if (key in obj) result[key] = obj[key]
|
|
11
|
+
}
|
|
12
|
+
return result
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Return a shallow copy with the listed keys removed (native replacement for ramda.omit).
|
|
17
|
+
* @param {string[]} keys
|
|
18
|
+
* @param {Object} obj
|
|
19
|
+
* @returns {Object}
|
|
20
|
+
*/
|
|
21
|
+
function omit(keys, obj) {
|
|
22
|
+
const keySet = new Set(keys)
|
|
23
|
+
const result = {}
|
|
24
|
+
for (const key of Object.keys(obj)) {
|
|
25
|
+
if (!keySet.has(key)) result[key] = obj[key]
|
|
26
|
+
}
|
|
27
|
+
return result
|
|
28
|
+
}
|
|
2
29
|
|
|
3
30
|
/**
|
|
4
31
|
* Combines array elements with schema
|
|
@@ -109,6 +136,7 @@ function combineNestedElementsWithSchema(element, attribute, schema) {
|
|
|
109
136
|
* @returns {import('../types').LayoutSchema}
|
|
110
137
|
*/
|
|
111
138
|
export function getSchemaWithLayout(schema, layout) {
|
|
139
|
+
if (!layout) return { elements: [] }
|
|
112
140
|
const combined = omit(['elements'], layout)
|
|
113
141
|
combined.elements =
|
|
114
142
|
layout.elements?.map((element) => combineElementWithSchema(element, schema)) ?? []
|