nuxt-unified-ui 0.2.25 → 0.2.27
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/app/app.config.js +1 -1
- package/app/components/un-form.vue +1 -1
- package/app/utils/unified-set.ts +53 -0
- package/package.json +1 -1
package/app/app.config.js
CHANGED
|
@@ -63,7 +63,7 @@ const filteredFields = computed(() => {
|
|
|
63
63
|
:is="elementsMap[field.identifier]"
|
|
64
64
|
:field="field"
|
|
65
65
|
:model-value="radGet(props.target, field.key)"
|
|
66
|
-
@update:model-value="
|
|
66
|
+
@update:model-value="unSet(props.target, field.key, $event)"
|
|
67
67
|
/>
|
|
68
68
|
</div>
|
|
69
69
|
</div>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Dynamically set a nested value into an object using a key path.
|
|
5
|
+
* Modifies the given initial object.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* unSet({}, 'name', 'ra')
|
|
9
|
+
* // => { name: 'ra' }
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* unSet({}, 'cards[0].value', 2)
|
|
13
|
+
* // => { cards: [{ value: 2 }] }
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export function unSet(target: any, key: string, value: any) {
|
|
17
|
+
|
|
18
|
+
const segments = (
|
|
19
|
+
key
|
|
20
|
+
.replace(/\[(\d+)\]/g, '.$1')
|
|
21
|
+
.split('.')
|
|
22
|
+
.filter(Boolean)
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (segments.length === 0) {
|
|
26
|
+
return target;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
let current = target;
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
34
|
+
|
|
35
|
+
const segment = segments[i]!;
|
|
36
|
+
const nextSegment = segments[i + 1]!;
|
|
37
|
+
const isNextArray = /^\d+$/.test(nextSegment);
|
|
38
|
+
|
|
39
|
+
if (current[segment] === undefined || current[segment] === null) {
|
|
40
|
+
current[segment] = isNextArray ? [] : {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
current = current[segment];
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
const lastSegment = segments[segments.length - 1]!;
|
|
49
|
+
current[lastSegment] = value;
|
|
50
|
+
|
|
51
|
+
return target;
|
|
52
|
+
|
|
53
|
+
}
|