2
This commit is contained in:
14
normal-admin/node_modules/element-plus/es/hooks/use-ordered-children/index.d.ts
generated
vendored
Normal file
14
normal-admin/node_modules/element-plus/es/hooks/use-ordered-children/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { ComponentInternalInstance, VNode } from 'vue';
|
||||
type ChildEssential = {
|
||||
uid: number;
|
||||
getVnode: () => VNode;
|
||||
};
|
||||
export declare const useOrderedChildren: <T extends ChildEssential>(vm: ComponentInternalInstance, childComponentName: string) => {
|
||||
children: import("vue").ShallowRef<T[]>;
|
||||
addChild: (child: T) => void;
|
||||
removeChild: (child: T) => void;
|
||||
ChildrenSorter: import("vue").DefineComponent<{}, () => VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
||||
[key: string]: any;
|
||||
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}>;
|
||||
};
|
||||
export {};
|
||||
69
normal-admin/node_modules/element-plus/es/hooks/use-ordered-children/index.mjs
generated
vendored
Normal file
69
normal-admin/node_modules/element-plus/es/hooks/use-ordered-children/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
import { shallowRef, triggerRef, onMounted, defineComponent, h, isVNode } from 'vue';
|
||||
import { flattedChildren } from '../../utils/vue/vnode.mjs';
|
||||
|
||||
const getOrderedChildren = (vm, childComponentName, children) => {
|
||||
const nodes = flattedChildren(vm.subTree).filter((n) => {
|
||||
var _a;
|
||||
return isVNode(n) && ((_a = n.type) == null ? void 0 : _a.name) === childComponentName && !!n.component;
|
||||
});
|
||||
const uids = nodes.map((n) => n.component.uid);
|
||||
return uids.map((uid) => children[uid]).filter((p) => !!p);
|
||||
};
|
||||
const useOrderedChildren = (vm, childComponentName) => {
|
||||
const children = shallowRef({});
|
||||
const orderedChildren = shallowRef([]);
|
||||
const nodesMap = /* @__PURE__ */ new WeakMap();
|
||||
const addChild = (child) => {
|
||||
children.value[child.uid] = child;
|
||||
triggerRef(children);
|
||||
onMounted(() => {
|
||||
const childNode = child.getVnode().el;
|
||||
const parentNode = childNode.parentNode;
|
||||
if (!nodesMap.has(parentNode)) {
|
||||
nodesMap.set(parentNode, []);
|
||||
const originalFn = parentNode.insertBefore.bind(parentNode);
|
||||
parentNode.insertBefore = (node, anchor) => {
|
||||
const shouldSortChildren = nodesMap.get(parentNode).some((el) => node === el || anchor === el);
|
||||
if (shouldSortChildren)
|
||||
triggerRef(children);
|
||||
return originalFn(node, anchor);
|
||||
};
|
||||
}
|
||||
nodesMap.get(parentNode).push(childNode);
|
||||
});
|
||||
};
|
||||
const removeChild = (child) => {
|
||||
delete children.value[child.uid];
|
||||
triggerRef(children);
|
||||
const childNode = child.getVnode().el;
|
||||
const parentNode = childNode.parentNode;
|
||||
const childNodes = nodesMap.get(parentNode);
|
||||
const index = childNodes.indexOf(childNode);
|
||||
childNodes.splice(index, 1);
|
||||
};
|
||||
const sortChildren = () => {
|
||||
orderedChildren.value = getOrderedChildren(vm, childComponentName, children.value);
|
||||
};
|
||||
const IsolatedRenderer = (props) => {
|
||||
return props.render();
|
||||
};
|
||||
const ChildrenSorter = defineComponent({
|
||||
setup(_, { slots }) {
|
||||
return () => {
|
||||
sortChildren();
|
||||
return slots.default ? h(IsolatedRenderer, {
|
||||
render: slots.default
|
||||
}) : null;
|
||||
};
|
||||
}
|
||||
});
|
||||
return {
|
||||
children: orderedChildren,
|
||||
addChild,
|
||||
removeChild,
|
||||
ChildrenSorter
|
||||
};
|
||||
};
|
||||
|
||||
export { useOrderedChildren };
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
1
normal-admin/node_modules/element-plus/es/hooks/use-ordered-children/index.mjs.map
generated
vendored
Normal file
1
normal-admin/node_modules/element-plus/es/hooks/use-ordered-children/index.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user