first commit
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
import { InjectionKey, Ref } from "vue";
|
||||
import { MaybeRef } from "@vueuse/core";
|
||||
|
||||
//#region ../../packages/hooks/use-id/index.d.ts
|
||||
type ElIdInjectionContext = {
|
||||
prefix: number;
|
||||
current: number;
|
||||
};
|
||||
declare const ID_INJECTION_KEY: InjectionKey<ElIdInjectionContext>;
|
||||
declare const useIdInjection: () => ElIdInjectionContext;
|
||||
declare const useId: (deterministicId?: MaybeRef<string>) => Ref<string>;
|
||||
//#endregion
|
||||
export { ElIdInjectionContext, ID_INJECTION_KEY, useId, useIdInjection };
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
||||
const require_error = require('../../utils/error.js');
|
||||
const require_index = require('../use-namespace/index.js');
|
||||
let _vueuse_core = require("@vueuse/core");
|
||||
let vue = require("vue");
|
||||
|
||||
//#region ../../packages/hooks/use-id/index.ts
|
||||
const defaultIdInjection = {
|
||||
prefix: Math.floor(Math.random() * 1e4),
|
||||
current: 0
|
||||
};
|
||||
const ID_INJECTION_KEY = Symbol("elIdInjection");
|
||||
const useIdInjection = () => {
|
||||
return (0, vue.getCurrentInstance)() ? (0, vue.inject)(ID_INJECTION_KEY, defaultIdInjection) : defaultIdInjection;
|
||||
};
|
||||
const useId = (deterministicId) => {
|
||||
const idInjection = useIdInjection();
|
||||
if (!_vueuse_core.isClient && idInjection === defaultIdInjection) require_error.debugWarn("IdInjection", `Looks like you are using server rendering, you must provide a id provider to ensure the hydration process to be succeed
|
||||
usage: app.provide(ID_INJECTION_KEY, {
|
||||
prefix: number,
|
||||
current: number,
|
||||
})`);
|
||||
const namespace = require_index.useGetDerivedNamespace();
|
||||
return (0, _vueuse_core.computedEager)(() => (0, vue.unref)(deterministicId) || `${namespace.value}-id-${idInjection.prefix}-${idInjection.current++}`);
|
||||
};
|
||||
|
||||
//#endregion
|
||||
exports.ID_INJECTION_KEY = ID_INJECTION_KEY;
|
||||
exports.useId = useId;
|
||||
exports.useIdInjection = useIdInjection;
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","names":["isClient","useGetDerivedNamespace"],"sources":["../../../../../packages/hooks/use-id/index.ts"],"sourcesContent":["import { getCurrentInstance, inject, unref } from 'vue'\nimport { computedEager } from '@vueuse/core'\nimport { debugWarn, isClient } from '@element-plus/utils'\nimport { useGetDerivedNamespace } from '../use-namespace'\n\nimport type { MaybeRef } from '@vueuse/core'\nimport type { InjectionKey, Ref } from 'vue'\n\nexport type ElIdInjectionContext = {\n prefix: number\n current: number\n}\n\nconst defaultIdInjection = {\n prefix: Math.floor(Math.random() * 10000),\n current: 0,\n}\n\nexport const ID_INJECTION_KEY: InjectionKey<ElIdInjectionContext> =\n Symbol('elIdInjection')\n\nexport const useIdInjection = (): ElIdInjectionContext => {\n return getCurrentInstance()\n ? inject(ID_INJECTION_KEY, defaultIdInjection)\n : defaultIdInjection\n}\n\nexport const useId = (deterministicId?: MaybeRef<string>): Ref<string> => {\n const idInjection = useIdInjection()\n if (!isClient && idInjection === defaultIdInjection) {\n debugWarn(\n 'IdInjection',\n `Looks like you are using server rendering, you must provide a id provider to ensure the hydration process to be succeed\nusage: app.provide(ID_INJECTION_KEY, {\n prefix: number,\n current: number,\n})`\n )\n }\n\n const namespace = useGetDerivedNamespace()\n\n // NOTE: Here we use `computedEager` to calculate the id value immediately, avoiding inconsistent id generation due to the lazy feature of `computed` when server rendering.\n const idRef = computedEager(\n () =>\n unref(deterministicId) ||\n `${namespace.value}-id-${idInjection.prefix}-${idInjection.current++}`\n )\n\n return idRef\n}\n"],"mappings":";;;;;;;;AAaA,MAAM,qBAAqB;CACzB,QAAQ,KAAK,MAAM,KAAK,QAAQ,GAAG,IAAM;CACzC,SAAS;CACV;AAED,MAAa,mBACX,OAAO,gBAAgB;AAEzB,MAAa,uBAA6C;AACxD,qCAA2B,mBAChB,kBAAkB,mBAAmB,GAC5C;;AAGN,MAAa,SAAS,oBAAoD;CACxE,MAAM,cAAc,gBAAgB;AACpC,KAAI,CAACA,yBAAY,gBAAgB,mBAC/B,yBACE,eACA;;;;IAKD;CAGH,MAAM,YAAYC,sCAAwB;AAS1C,6DAJU,gBAAgB,IACtB,GAAG,UAAU,MAAM,MAAM,YAAY,OAAO,GAAG,YAAY,YAC9D"}
|
||||
Reference in New Issue
Block a user