@v-c/util 1.3.0 → 1.3.2-rc.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/Dom/dynamicCSS.js +8 -2
- package/dist/pickDefined.d.ts +15 -0
- package/dist/pickDefined.js +27 -0
- package/dist/utils/set.js +8 -2
- package/package.json +1 -1
package/dist/Dom/dynamicCSS.js
CHANGED
|
@@ -21,6 +21,7 @@ function getOrder(prepend) {
|
|
|
21
21
|
* Find style which inject by rc-util
|
|
22
22
|
*/
|
|
23
23
|
function findStyles(container) {
|
|
24
|
+
if (!container) return [];
|
|
24
25
|
return Array.from((containerCache.get(container) || container).children).filter((node) => node.tagName === "STYLE");
|
|
25
26
|
}
|
|
26
27
|
function injectCSS(css, option = {}) {
|
|
@@ -34,6 +35,7 @@ function injectCSS(css, option = {}) {
|
|
|
34
35
|
if (csp?.nonce) styleNode.nonce = csp?.nonce;
|
|
35
36
|
styleNode.innerHTML = css;
|
|
36
37
|
const container = getContainer(option);
|
|
38
|
+
if (!container) return null;
|
|
37
39
|
const { firstChild } = container;
|
|
38
40
|
if (prepend) {
|
|
39
41
|
if (isPrependQueue) {
|
|
@@ -57,7 +59,7 @@ function findExistNode(key, option = {}) {
|
|
|
57
59
|
function removeCSS(key, option = {}) {
|
|
58
60
|
if (!canUseDom()) return null;
|
|
59
61
|
const existNode = findExistNode(key, option);
|
|
60
|
-
if (existNode) getContainer(option)
|
|
62
|
+
if (existNode) getContainer(option)?.removeChild(existNode);
|
|
61
63
|
}
|
|
62
64
|
/**
|
|
63
65
|
* qiankun will inject `appendChild` to insert into other
|
|
@@ -66,6 +68,7 @@ function syncRealContainer(container, option) {
|
|
|
66
68
|
const cachedRealContainer = containerCache.get(container);
|
|
67
69
|
if (!cachedRealContainer || !contains(document, cachedRealContainer)) {
|
|
68
70
|
const placeholderStyle = injectCSS("", option);
|
|
71
|
+
if (!placeholderStyle) return;
|
|
69
72
|
const { parentNode } = placeholderStyle;
|
|
70
73
|
containerCache.set(container, parentNode);
|
|
71
74
|
container.removeChild(placeholderStyle);
|
|
@@ -79,7 +82,9 @@ function clearContainerCache() {
|
|
|
79
82
|
}
|
|
80
83
|
function updateCSS(css, key, option = {}) {
|
|
81
84
|
if (!canUseDom()) return null;
|
|
82
|
-
|
|
85
|
+
const container = getContainer(option);
|
|
86
|
+
if (!container) return null;
|
|
87
|
+
syncRealContainer(container, option);
|
|
83
88
|
const existNode = findExistNode(key, option);
|
|
84
89
|
if (existNode) {
|
|
85
90
|
if (option.csp?.nonce && existNode.nonce !== option.csp?.nonce) existNode.nonce = option.csp?.nonce;
|
|
@@ -87,6 +92,7 @@ function updateCSS(css, key, option = {}) {
|
|
|
87
92
|
return existNode;
|
|
88
93
|
}
|
|
89
94
|
const newNode = injectCSS(css, option);
|
|
95
|
+
if (!newNode) return null;
|
|
90
96
|
newNode.setAttribute(getMark(option), key);
|
|
91
97
|
return newNode;
|
|
92
98
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy `obj` keeping only the keys whose value is not `undefined`, optionally
|
|
3
|
+
* dropping `omitKeys` as well.
|
|
4
|
+
*
|
|
5
|
+
* Vue materialises every declared prop on `props` (unset ones as `undefined`),
|
|
6
|
+
* so spreading `props` into a child forwards dozens of empty keys that the
|
|
7
|
+
* child has to normalise in `initProps` / `setFullProps` on every mount, and
|
|
8
|
+
* that every further spread / omit copies again. Boolean props in @v-c default
|
|
9
|
+
* to `undefined` rather than `false`, so leaving an unset key out behaves the
|
|
10
|
+
* same as forwarding it as `undefined`.
|
|
11
|
+
*
|
|
12
|
+
* Reads each key exactly once: `obj` is usually a reactive proxy and every read
|
|
13
|
+
* goes through the `get` trap and dependency tracking.
|
|
14
|
+
*/
|
|
15
|
+
export default function pickDefined<T extends object, K extends keyof T = never>(obj: T, omitKeys?: readonly K[]): Omit<T, K>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { toRaw } from "vue";
|
|
2
|
+
//#region src/pickDefined.ts
|
|
3
|
+
/**
|
|
4
|
+
* Copy `obj` keeping only the keys whose value is not `undefined`, optionally
|
|
5
|
+
* dropping `omitKeys` as well.
|
|
6
|
+
*
|
|
7
|
+
* Vue materialises every declared prop on `props` (unset ones as `undefined`),
|
|
8
|
+
* so spreading `props` into a child forwards dozens of empty keys that the
|
|
9
|
+
* child has to normalise in `initProps` / `setFullProps` on every mount, and
|
|
10
|
+
* that every further spread / omit copies again. Boolean props in @v-c default
|
|
11
|
+
* to `undefined` rather than `false`, so leaving an unset key out behaves the
|
|
12
|
+
* same as forwarding it as `undefined`.
|
|
13
|
+
*
|
|
14
|
+
* Reads each key exactly once: `obj` is usually a reactive proxy and every read
|
|
15
|
+
* goes through the `get` trap and dependency tracking.
|
|
16
|
+
*/
|
|
17
|
+
function pickDefined(obj, omitKeys) {
|
|
18
|
+
const result = {};
|
|
19
|
+
const raw = toRaw(obj);
|
|
20
|
+
for (const key in raw) {
|
|
21
|
+
const value = obj[key];
|
|
22
|
+
if (value !== void 0 && (!omitKeys || !omitKeys.includes(key))) result[key] = value;
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { pickDefined as default };
|
package/dist/utils/set.js
CHANGED
|
@@ -7,8 +7,14 @@ function internalSet(entity, paths, value, removeIfUndefined) {
|
|
|
7
7
|
if (!entity && typeof path === "number") clone = [];
|
|
8
8
|
else if (Array.isArray(entity)) clone = [...entity];
|
|
9
9
|
else clone = { ...entity };
|
|
10
|
-
if (removeIfUndefined && value === void 0 && restPath.length === 1)
|
|
11
|
-
|
|
10
|
+
if (removeIfUndefined && value === void 0 && restPath.length === 1) {
|
|
11
|
+
const origin = clone[path];
|
|
12
|
+
if (origin && typeof origin === "object") {
|
|
13
|
+
const child = Array.isArray(origin) ? [...origin] : { ...origin };
|
|
14
|
+
delete child[restPath[0]];
|
|
15
|
+
clone[path] = child;
|
|
16
|
+
}
|
|
17
|
+
} else clone[path] = internalSet(clone[path], restPath, value, removeIfUndefined);
|
|
12
18
|
return clone;
|
|
13
19
|
}
|
|
14
20
|
function set(entity, paths, value, removeIfUndefined = false) {
|