@v-c/util 1.3.0 → 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.
@@ -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).removeChild(existNode);
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
- syncRealContainer(getContainer(option), option);
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/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) delete clone[path][restPath[0]];
11
- else clone[path] = internalSet(clone[path], restPath, value, removeIfUndefined);
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) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/util",
3
3
  "type": "module",
4
- "version": "1.3.0",
4
+ "version": "1.3.1",
5
5
  "description": "Vue3 components utils",
6
6
  "author": {
7
7
  "name": "aibayanyu20",