@v-c/util 1.2.1 → 1.3.1
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/getScrollBarSize.js +4 -2
- package/dist/hooks/useDelayState.js +2 -1
- package/dist/hooks/useMemo.js +3 -2
- package/dist/hooks/useState.js +2 -1
- package/dist/props-util/index.js +4 -3
- package/dist/type.d.ts +11 -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
|
}
|
package/dist/getScrollBarSize.js
CHANGED
|
@@ -22,10 +22,12 @@ function measureScrollbarSize(ele) {
|
|
|
22
22
|
const width = parseInt(webkitScrollbarStyle.width, 10);
|
|
23
23
|
const height = parseInt(webkitScrollbarStyle.height, 10);
|
|
24
24
|
try {
|
|
25
|
+
const widthStyle = width ? `width: ${webkitScrollbarStyle.width};` : "";
|
|
26
|
+
const heightStyle = height ? `height: ${webkitScrollbarStyle.height};` : "";
|
|
25
27
|
updateCSS(`
|
|
26
28
|
#${randomId}::-webkit-scrollbar {
|
|
27
|
-
${
|
|
28
|
-
${
|
|
29
|
+
${widthStyle}
|
|
30
|
+
${heightStyle}
|
|
29
31
|
}`, randomId);
|
|
30
32
|
} catch (e) {
|
|
31
33
|
console.error(e);
|
|
@@ -6,7 +6,8 @@ import { onBeforeUnmount, ref } from "vue";
|
|
|
6
6
|
* Pending updates are always replaced by the latest one.
|
|
7
7
|
*/
|
|
8
8
|
function useDelayState(defaultValue) {
|
|
9
|
-
const
|
|
9
|
+
const initValue = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
10
|
+
const value = ref(initValue);
|
|
10
11
|
let delayInfo = null;
|
|
11
12
|
const cancelPending = () => {
|
|
12
13
|
if (delayInfo) {
|
package/dist/hooks/useMemo.js
CHANGED
|
@@ -2,10 +2,11 @@ import { isReactive, isRef, ref, watch } from "vue";
|
|
|
2
2
|
//#region src/hooks/useMemo.ts
|
|
3
3
|
function useMemo(getValue, condition, shouldUpdate) {
|
|
4
4
|
const cacheRef = ref(getValue());
|
|
5
|
-
|
|
5
|
+
const sources = condition.map((item) => {
|
|
6
6
|
if (typeof item === "function" || isRef(item) || isReactive(item)) return item;
|
|
7
7
|
return () => item;
|
|
8
|
-
})
|
|
8
|
+
});
|
|
9
|
+
watch(sources, (next, pre) => {
|
|
9
10
|
if (shouldUpdate) {
|
|
10
11
|
if (shouldUpdate(next, pre)) cacheRef.value = getValue();
|
|
11
12
|
} else cacheRef.value = getValue();
|
package/dist/hooks/useState.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ref } from "vue";
|
|
2
2
|
//#region src/hooks/useState.ts
|
|
3
3
|
function useState(defaultStateValue) {
|
|
4
|
-
const
|
|
4
|
+
const initValue = typeof defaultStateValue === "function" ? defaultStateValue() : defaultStateValue;
|
|
5
|
+
const innerValue = ref(initValue);
|
|
5
6
|
function triggerChange(newValue) {
|
|
6
7
|
innerValue.value = newValue;
|
|
7
8
|
}
|
package/dist/props-util/index.js
CHANGED
|
@@ -22,9 +22,10 @@ function flattenChildren(children, isFilterEmpty = true) {
|
|
|
22
22
|
temp.forEach((child) => {
|
|
23
23
|
if (Array.isArray(child)) res.push(...flattenChildren(child, isFilterEmpty));
|
|
24
24
|
else if (isValid(child)) res.push(child);
|
|
25
|
-
else if (child && typeof child === "object" && child.type === Fragment)
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
else if (child && typeof child === "object" && child.type === Fragment) {
|
|
26
|
+
if (child.key === skipFlattenKey) res.push(child);
|
|
27
|
+
else res.push(...flattenChildren(child.children, isFilterEmpty));
|
|
28
|
+
} else if (child && isVNode(child)) {
|
|
28
29
|
if (isFilterEmpty && !isEmptyElement(child)) res.push(child);
|
|
29
30
|
else if (!isFilterEmpty) res.push(child);
|
|
30
31
|
}
|
package/dist/type.d.ts
CHANGED
|
@@ -59,4 +59,15 @@ export declare function someType<T>(types?: any[], defaultVal?: T): {
|
|
|
59
59
|
};
|
|
60
60
|
export type CustomSlotsType<T extends Record<string, any>> = SlotsType<T>;
|
|
61
61
|
export type AnyObject = Record<PropertyKey, any>;
|
|
62
|
+
/**
|
|
63
|
+
* Identity wrapper understood by `vite-plugin-tsx-resolve-types`: the wrapped
|
|
64
|
+
* type is excluded from runtime prop inference, the way `/* @vue-ignore *\/`
|
|
65
|
+
* is, but the marker survives declaration emit so it also works for types
|
|
66
|
+
* consumed from a published `.d.ts`.
|
|
67
|
+
*
|
|
68
|
+
* `interface Props extends Base, VueIgnore<Emits> {}` keeps the `Emits`
|
|
69
|
+
* members as fallthrough attrs; `x?: VueIgnore<Heavy>` declares `x` with no
|
|
70
|
+
* runtime type check.
|
|
71
|
+
*/
|
|
72
|
+
export type VueIgnore<T> = T;
|
|
62
73
|
export {};
|
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) {
|