feat: initial commit - Phase 1 & 2 core features

This commit is contained in:
hiderfong
2026-04-22 17:07:33 +08:00
commit 1773bda06b
25005 changed files with 6252106 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
import { OnlyChild, OnlyChildExpose } from "./src/only-child.js";
export { OnlyChild as ElOnlyChild, OnlyChild, OnlyChildExpose };
+5
View File
@@ -0,0 +1,5 @@
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_only_child = require('./src/only-child.js');
exports.ElOnlyChild = require_only_child.OnlyChild;
exports.OnlyChild = require_only_child.OnlyChild;
@@ -0,0 +1,12 @@
import * as vue from "vue";
import { Ref, VNode } from "vue";
//#region ../../packages/components/slot/src/only-child.d.ts
declare const OnlyChild: vue.DefineComponent<{}, () => VNode<vue.RendererNode, vue.RendererElement, {
[key: string]: any;
}> | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
type OnlyChildExpose = {
forwardRef: Ref<HTMLElement>;
};
//#endregion
export { OnlyChild, OnlyChildExpose };
@@ -0,0 +1,55 @@
const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
const require_error = require('../../../utils/error.js');
const require_index = require('../../../hooks/use-namespace/index.js');
const require_index$1 = require('../../../hooks/use-forward-ref/index.js');
let vue = require("vue");
let _vue_shared = require("@vue/shared");
//#region ../../packages/components/slot/src/only-child.tsx
const NAME = "ElOnlyChild";
const OnlyChild = /* @__PURE__ */ (0, vue.defineComponent)({
name: NAME,
setup(_, { slots, attrs }) {
const forwardRefDirective = require_index$1.useForwardRefDirective((0, vue.inject)(require_index$1.FORWARD_REF_INJECTION_KEY)?.setForwardRef ?? _vue_shared.NOOP);
return () => {
const defaultSlot = slots.default?.(attrs);
if (!defaultSlot) return null;
const [firstLegitNode, length] = findFirstLegitChild(defaultSlot);
if (!firstLegitNode) {
require_error.debugWarn(NAME, "no valid child node found");
return null;
}
if (length > 1) require_error.debugWarn(NAME, "requires exact only one valid child.");
return (0, vue.withDirectives)((0, vue.cloneVNode)(firstLegitNode, attrs), [[forwardRefDirective]]);
};
}
});
function findFirstLegitChild(node) {
if (!node) return [null, 0];
const children = node;
const len = children.filter((c) => c.type !== vue.Comment).length;
for (const child of children) {
/**
* when user uses h(Fragment, [text]) to render plain string,
* this switch case just cannot handle, when the value is primitives
* we should just return the wrapped string
*/
if ((0, _vue_shared.isObject)(child)) switch (child.type) {
case vue.Comment: continue;
case vue.Text:
case "svg": return [wrapTextContent(child), len];
case vue.Fragment: return findFirstLegitChild(child.children);
default: return [child, len];
}
return [wrapTextContent(child), len];
}
return [null, 0];
}
function wrapTextContent(s) {
const ns = require_index.useNamespace("only-child");
return (0, vue.createVNode)("span", { "class": ns.e("content") }, [s]);
}
//#endregion
exports.OnlyChild = OnlyChild;
//# sourceMappingURL=only-child.js.map
@@ -0,0 +1 @@
{"version":3,"file":"only-child.js","names":["Comment","Fragment","Text","cloneVNode","defineComponent","inject","withDirectives","createVNode","_createVNode","NOOP","debugWarn","isObject","FORWARD_REF_INJECTION_KEY","useForwardRefDirective","useNamespace","NAME","OnlyChild","name","setup","_","slots","attrs","forwardRefInjection","forwardRefDirective","setForwardRef","defaultSlot","default","firstLegitNode","length","findFirstLegitChild","node","children","len","filter","c","type","child","wrapTextContent","s","ns","e"],"sources":["../../../../../../packages/components/slot/src/only-child.tsx"],"sourcesContent":["import {\n Comment,\n Fragment,\n Text,\n cloneVNode,\n defineComponent,\n inject,\n withDirectives,\n} from 'vue'\nimport { NOOP, debugWarn, isObject } from '@element-plus/utils'\nimport {\n FORWARD_REF_INJECTION_KEY,\n useForwardRefDirective,\n useNamespace,\n} from '@element-plus/hooks'\n\nimport type { Ref, VNode } from 'vue'\n\nconst NAME = 'ElOnlyChild'\n\nexport const OnlyChild = defineComponent({\n name: NAME,\n setup(_, { slots, attrs }) {\n const forwardRefInjection = inject(FORWARD_REF_INJECTION_KEY)\n const forwardRefDirective = useForwardRefDirective(\n forwardRefInjection?.setForwardRef ?? NOOP\n )\n return () => {\n const defaultSlot = slots.default?.(attrs)\n if (!defaultSlot) return null\n const [firstLegitNode, length] = findFirstLegitChild(defaultSlot)\n\n if (!firstLegitNode) {\n debugWarn(NAME, 'no valid child node found')\n return null\n }\n if (length > 1) {\n debugWarn(NAME, 'requires exact only one valid child.')\n }\n\n return withDirectives(cloneVNode(firstLegitNode!, attrs), [\n [forwardRefDirective],\n ])\n }\n },\n})\n\nfunction findFirstLegitChild(\n node: VNode[] | undefined\n): [VNode | null, number] {\n if (!node) return [null, 0]\n const children = node as VNode[]\n const len = children.filter((c) => c.type !== Comment).length\n\n for (const child of children) {\n /**\n * when user uses h(Fragment, [text]) to render plain string,\n * this switch case just cannot handle, when the value is primitives\n * we should just return the wrapped string\n */\n if (isObject(child)) {\n switch (child.type) {\n case Comment:\n continue\n case Text:\n case 'svg':\n return [wrapTextContent(child), len]\n case Fragment:\n return findFirstLegitChild(child.children as VNode[])\n default:\n return [child, len]\n }\n }\n return [wrapTextContent(child), len]\n }\n return [null, 0]\n}\n\nfunction wrapTextContent(s: string | VNode) {\n const ns = useNamespace('only-child')\n return <span class={ns.e('content')}>{s}</span>\n}\n\nexport type OnlyChildExpose = {\n forwardRef: Ref<HTMLElement>\n}\n"],"mappings":";;;;;;;;AAkBA,MAAMe,OAAO;AAEb,MAAaC,YAAYZ,yCAAgB;CACvCa,MAAMF;CACNG,MAAMC,GAAG,EAAEC,OAAOC,SAAS;EAEzB,MAAME,sBAAsBV,uDADOD,0CAA0B,EAEtCY,iBAAiBf,iBACvC;AACD,eAAa;GACX,MAAMgB,cAAcL,MAAMM,UAAUL,MAAM;AAC1C,OAAI,CAACI,YAAa,QAAO;GACzB,MAAM,CAACE,gBAAgBC,UAAUC,oBAAoBJ,YAAY;AAEjE,OAAI,CAACE,gBAAgB;AACnBjB,4BAAUK,MAAM,4BAA4B;AAC5C,WAAO;;AAET,OAAIa,SA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