@v-c/util 1.4.2 → 1.4.3
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/hooks/useScopeId.d.ts +1 -0
- package/dist/hooks/useScopeId.js +37 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useScopeIdAttrs(): Record<string, ''>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Comment, getCurrentInstance, isVNode } from "vue";
|
|
2
|
+
//#region src/hooks/useScopeId.ts
|
|
3
|
+
var DEV_ROOT_FRAGMENT = 2048;
|
|
4
|
+
function filterSingleRoot(children) {
|
|
5
|
+
if (!Array.isArray(children)) return;
|
|
6
|
+
let singleRoot;
|
|
7
|
+
for (const child of children) {
|
|
8
|
+
if (!isVNode(child)) return;
|
|
9
|
+
if (child.type !== Comment || child.children === "v-if") {
|
|
10
|
+
if (singleRoot) return;
|
|
11
|
+
singleRoot = child;
|
|
12
|
+
if (singleRoot.patchFlag > 0 && singleRoot.patchFlag & DEV_ROOT_FRAGMENT) return filterSingleRoot(singleRoot.children);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return singleRoot;
|
|
16
|
+
}
|
|
17
|
+
function isParentRoot(parent, vnode) {
|
|
18
|
+
let subTree = parent.subTree;
|
|
19
|
+
if (!subTree) return false;
|
|
20
|
+
if (process.env.NODE_ENV !== "production" && subTree.patchFlag > 0 && subTree.patchFlag & DEV_ROOT_FRAGMENT) subTree = filterSingleRoot(subTree.children) || subTree;
|
|
21
|
+
return vnode === subTree || subTree.type.__isSuspense && (subTree.ssContent === vnode || subTree.ssFallback === vnode);
|
|
22
|
+
}
|
|
23
|
+
function useScopeIdAttrs() {
|
|
24
|
+
const scopeIds = /* @__PURE__ */ new Set();
|
|
25
|
+
let instance = getCurrentInstance();
|
|
26
|
+
while (instance) {
|
|
27
|
+
const vnode = instance.vnode;
|
|
28
|
+
if (vnode.scopeId) scopeIds.add(vnode.scopeId);
|
|
29
|
+
vnode.slotScopeIds?.forEach((scopeId) => scopeIds.add(scopeId));
|
|
30
|
+
const parent = instance.parent;
|
|
31
|
+
if (!parent || !isParentRoot(parent, vnode)) break;
|
|
32
|
+
instance = parent;
|
|
33
|
+
}
|
|
34
|
+
return Object.fromEntries([...scopeIds].map((scopeId) => [scopeId, ""]));
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { useScopeIdAttrs };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { useControlledState } from './hooks/useControlledState.js';
|
|
|
5
5
|
export { default as useId } from './hooks/useId.js';
|
|
6
6
|
export { default as useMergedState } from './hooks/useMergedState.js';
|
|
7
7
|
export { default as useMobile } from './hooks/useMobile.js';
|
|
8
|
+
export { useScopeIdAttrs } from './hooks/useScopeId.js';
|
|
8
9
|
export { isNonNullable, isVueRenderable } from './is.js';
|
|
9
10
|
export { default as KeyCode } from './KeyCode.js';
|
|
10
11
|
export { default as omit } from './omit.js';
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,9 @@ import { useControlledState } from "./hooks/useControlledState.js";
|
|
|
8
8
|
import useId_default from "./hooks/useId.js";
|
|
9
9
|
import useMergedState from "./hooks/useMergedState.js";
|
|
10
10
|
import useMobile from "./hooks/useMobile.js";
|
|
11
|
+
import { useScopeIdAttrs } from "./hooks/useScopeId.js";
|
|
11
12
|
import { isNonNullable, isVueRenderable } from "./is.js";
|
|
12
13
|
import get from "./utils/get.js";
|
|
13
14
|
import set, { merge, mergeWith } from "./utils/set.js";
|
|
14
15
|
import warningOnce from "./warning.js";
|
|
15
|
-
export { KeyCode, RenderComponent_default as RenderComponent, classNames, clsx, get, isNonNullable, isVueRenderable, merge, mergeWith, normalizeAllowClear, omit, wrapperRaf as raf, set, useAllowClear, useControlledState, useId_default as useId, useMergedState, useMobile, warningOnce as warning };
|
|
16
|
+
export { KeyCode, RenderComponent_default as RenderComponent, classNames, clsx, get, isNonNullable, isVueRenderable, merge, mergeWith, normalizeAllowClear, omit, wrapperRaf as raf, set, useAllowClear, useControlledState, useId_default as useId, useMergedState, useMobile, useScopeIdAttrs, warningOnce as warning };
|