From 4e8b2fcf16e4d0938eb8879ed56c9d33d6b6bf24 Mon Sep 17 00:00:00 2001 From: Waleed Khaled Date: Tue, 27 Aug 2024 21:13:55 +0400 Subject: [PATCH] docs: add debounce demo --- docs/src/plugins/moduleDocTransform.ts | 18 +- docs/tsconfig.json | 6 +- .../utilix/src/function/debounce/demo.vue | 170 ++++++++++++++++++ .../utilix/src/function/debounce/index.md | 8 + 4 files changed, 191 insertions(+), 11 deletions(-) create mode 100644 packages/utilix/src/function/debounce/demo.vue diff --git a/docs/src/plugins/moduleDocTransform.ts b/docs/src/plugins/moduleDocTransform.ts index 2b5f405..4126baf 100644 --- a/docs/src/plugins/moduleDocTransform.ts +++ b/docs/src/plugins/moduleDocTransform.ts @@ -15,21 +15,21 @@ export function moduleDocTransform(): Plugin { let exporter: um.DocExporterPluginAPI; function transform(code: string, module: string, watchModule?: string) { - let mainMd = '', usageMd = '', extMd = ''; + let mainMd = '', subMd = '', extMd = ''; const codeIndex = code.indexOf('## '); if (codeIndex >= 0) { mainMd = code.slice(0, codeIndex); extMd = code.slice(codeIndex); - const usageIdx = extMd.indexOf("## Usage"); - if (usageIdx >= 0) { - const usageLastIdx = extMd.indexOf("\n## ", usageIdx + 1); - if (usageLastIdx >= 0) { - usageMd = extMd.slice(0, usageLastIdx); - extMd = extMd.slice(usageLastIdx); + const subIdx = Math.max(extMd.indexOf("## Usage"), extMd.indexOf("## Demo")); + if (subIdx >= 0) { + const subLastIdx = extMd.indexOf("\n## ", subIdx + 1); + if (subLastIdx >= 0) { + subMd = extMd.slice(0, subLastIdx); + extMd = extMd.slice(subLastIdx); } else { - usageMd = extMd; + subMd = extMd; extMd = ''; } } @@ -38,7 +38,7 @@ export function moduleDocTransform(): Plugin { } const md = mdExports(exporter.getExports(module, watchModule), module.slice(module.indexOf('/') + 1)); - return mainMd + usageMd + md + extMd; + return mainMd + subMd + md + extMd; } return { diff --git a/docs/tsconfig.json b/docs/tsconfig.json index b01ee81..cd8533c 100644 --- a/docs/tsconfig.json +++ b/docs/tsconfig.json @@ -4,6 +4,7 @@ "types": ["node"], "outDir": ".vitepress/dist", + "rootDir": "../", "composite": true, "paths": { @@ -13,8 +14,9 @@ } }, "include": [ - "**/*", - ".vitepress/**/*" + "src", + ".vitepress/**/*", + "../packages/**/*.vue" ], "references": [ { diff --git a/packages/utilix/src/function/debounce/demo.vue b/packages/utilix/src/function/debounce/demo.vue new file mode 100644 index 0000000..bbc54d7 --- /dev/null +++ b/packages/utilix/src/function/debounce/demo.vue @@ -0,0 +1,170 @@ + + + + diff --git a/packages/utilix/src/function/debounce/index.md b/packages/utilix/src/function/debounce/index.md index 49c648c..f176335 100644 --- a/packages/utilix/src/function/debounce/index.md +++ b/packages/utilix/src/function/debounce/index.md @@ -1,3 +1,11 @@ + + # debounce Limit the frequency of a function call by delaying its execution until a certain amount of time has passed since the last invocation. It is commonly used in scenarios where you want to prevent a function from being called too frequently, such as handling user input or event listeners. + +## Demo + +