Skip to content

Commit 8fc74e5

Browse files
authored
Merge pull request #276 from InhiblabCore/alpha
Alpha for 2.4.0 🏎️
2 parents 112fd55 + 65711fe commit 8fc74e5

File tree

51 files changed

+1804
-466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1804
-466
lines changed

docs/.vitepress/config/en.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function sidebarGuide(): DefaultTheme.SidebarItem[] {
114114
{
115115
text: 'Guide',
116116
items: [
117-
{ text: 'Introduction', link: "/guide" },
117+
{ text: 'Introduction', link: "/guide/introduction" },
118118
{ text: 'Getting Started', link: '/guide/getting-started' },
119119
{ text: '🫶 Migrate to v2 version', link: '/guide/migrate' }
120120
],
@@ -137,6 +137,7 @@ export const en = defineConfig({
137137
...sidebarHooks(),
138138
]
139139
},
140+
'/components/': sidebarComponents(),
140141
},
141142

142143
editLink: {
@@ -155,9 +156,9 @@ function nav(): DefaultTheme.NavItem[] {
155156
return [
156157
{
157158
text: 'Guide',
158-
activeMatch: '/guide/',
159+
activeMatch: '^/guide/',
159160
items: [
160-
{ text: 'Introduction', link: '/guide' },
161+
{ text: 'Introduction', link: '/guide/introduction' },
161162
{ text: 'Getting Started', link: '/guide/getting-started' },
162163
{ text: '🫶 Migrate to v2 version', link: '/guide/migrate' }
163164
]
@@ -167,6 +168,11 @@ function nav(): DefaultTheme.NavItem[] {
167168
link: '/hooks/useRequest/quick-start',
168169
activeMatch: '/hooks'
169170
},
171+
{
172+
text: "Components",
173+
link: '/components/guide',
174+
activeMatch: '/components/'
175+
},
170176
{
171177
text: '🤺 Playground',
172178
link: 'https://inhiblabcore.github.io/vue-hooks-plus-playground/play',
@@ -265,7 +271,7 @@ export function sidebarHooks(): DefaultTheme.SidebarItem[] {
265271
{
266272
text: 'Advanced',
267273
items: [
268-
{ text: 'useEventEmitter', link: '/useEventEmitter/' },
274+
{ text: 'useEventEmitter', link: 'useEventEmitter' },
269275
{
270276
text: 'useAsyncOrder',
271277
link: 'useAsyncOrder',
@@ -286,3 +292,19 @@ export function sidebarHooks(): DefaultTheme.SidebarItem[] {
286292
})
287293
}
288294

295+
296+
297+
export function sidebarComponents(): DefaultTheme.SidebarItem[] {
298+
return [
299+
{
300+
text: 'Components',
301+
items: [
302+
{
303+
text: 'Guide',
304+
link: '/components/guide',
305+
},
306+
{ text: 'useRequest', link: '/components/useRequest' },
307+
],
308+
}
309+
]
310+
}

docs/.vitepress/config/factory.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fsExtra from 'fs-extra';
1+
import * as fs from 'node:fs';
22
import { dirname, join, sep } from 'path';
33
import { MarkdownRenderer } from 'vitepress';
44

@@ -48,13 +48,13 @@ export function genDemoByCode(
4848
while (true) {
4949
demoName = `demo-${fenceIndex++}.vue`;
5050
demoPath = join(dirname(path), 'dist', demoName);
51-
if (!fsExtra.existsSync(demoPath)) {
51+
if (!fs.existsSync(demoPath)) {
5252
break;
5353
}
5454
}
5555

56-
fsExtra.createFileSync(demoPath);
57-
fsExtra.writeFileSync(demoPath, code);
56+
fs.writeFileSync(demoPath, '');
57+
fs.writeFileSync(demoPath, code);
5858

5959
codeFileMap[code] = {
6060
demoName,

docs/.vitepress/config/zh.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ function sidebarGuide(): DefaultTheme.SidebarItem[] {
123123
}
124124
]
125125
}
126+
127+
function sidebarComponents(): DefaultTheme.SidebarItem[] {
128+
return [
129+
{
130+
text: 'Components',
131+
items: [
132+
{ text: 'Guide', link: '/zh/components/guide' },
133+
{ text: 'useRequest', link: '/zh/components/useRequest' },
134+
],
135+
}
136+
]
137+
}
138+
126139
export const zh = defineConfig({
127140
lang: 'zh-Hans',
128141
description: '高性能的 Vue 组合式函数库',
@@ -138,7 +151,8 @@ export const zh = defineConfig({
138151
...siderbarUseRequestPlugin(),
139152
...sidebarHooks()
140153
]
141-
}
154+
},
155+
'/zh/components/': sidebarComponents(),
142156
},
143157

144158
editLink: {
@@ -182,18 +196,23 @@ function nav(): DefaultTheme.NavItem[] {
182196
return [
183197
{
184198
text: '指南',
185-
activeMatch: '/zh/guide/',
199+
activeMatch: '^/zh/guide/',
186200
items: [
187-
{ text: '介绍', link: '/zh/guide' },
201+
{ text: '介绍', link: '/zh/guide/introduction' },
188202
{ text: '开始使用', link: '/zh/guide/getting-started' },
189203
{ text: '🫶 迁移到 v2 版本', link: '/zh/guide/migrate' }
190204
]
191205
},
192206
{
193-
text: 'Hooks',
207+
text: 'Hooks 函数',
194208
link: '/zh/hooks/useRequest/quick-start',
195209
activeMatch: '/zh/hooks'
196210
},
211+
{
212+
text: '函数组件',
213+
link: '/zh/components/guide',
214+
activeMatch: '/zh/components/'
215+
},
197216
{
198217
text: '🤺 演武场',
199218
link: 'https://inhiblabcore.github.io/vue-hooks-plus-playground/play',

docs/.vitepress/plugins/applyMdPlugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { parseProps } from "../config/utils";
22
import { resolve } from 'path'
3-
import fsExtra from 'fs-extra'
3+
import * as fs from 'node:fs'
44
import { getDemoComponent } from "../config/factory";
55
export const applyMdPlugin = (md: any) => {
66
const htmlBlock = md.renderer.rules.html_block!
7-
md.renderer.rules.html_block = function (tokens, idx, options, env, self) {
7+
md.renderer.rules.html_block = function (tokens: any, idx: any, options: any, env: any, self: any) {
88
const token = tokens[idx];
99
const content = token.content.trim();
1010
const { path } = env;
@@ -17,7 +17,7 @@ export const applyMdPlugin = (md: any) => {
1717
}
1818

1919
const srcPath = resolve(process.cwd(), "docs", "demo", props.src);
20-
const code = fsExtra.readFileSync(srcPath, 'utf8');
20+
const code = fs.readFileSync(srcPath, 'utf8');
2121
const demoScripts = getDemoComponent(md, env, {
2222
title: props?.title,
2323
desc: props?.desc,

docs/demo/useEventEmitter/App.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<div>
3+
<vhp-button @click="refRouter = !refRouter" style="margin-bottom: 16px;">
4+
toggle router</vhp-button
5+
>
6+
<demo v-if="refRouter" />
7+
<div v-else>
8+
SHOW TEXT
9+
</div>
10+
</div>
11+
</template>
12+
13+
<script lang="ts" setup>
14+
import { ref } from 'vue'
15+
import Demo from './demo.vue'
16+
17+
const refRouter = ref(true)
18+
</script>

docs/demo/useEventEmitter/DemoA.vue

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,30 @@
66
</template>
77

88
<script lang="ts" setup>
9-
import { ref } from 'vue'
9+
import { onMounted, onUnmounted, ref } from 'vue'
1010
1111
import { useEventEmitter } from 'vue-hooks-plus'
12+
import { EventEmitter } from 'vue-hooks-plus/src/useEventEmitter/event'
1213
13-
const event = useEventEmitter({ global: true })
14+
const event_ = useEventEmitter({ global: true })
1415
const props = defineProps<{
15-
event: any
16+
event: EventEmitter<any>
1617
}>()
1718
const count = ref(0)
1819
19-
props.event.useSubscription('change', () => {
20-
count.value += 1
20+
let unsubscribe: (() => void) | null = null
21+
22+
onMounted(() => {
23+
unsubscribe = props.event.subscribe('change', () => {
24+
console.log('props', props.event)
25+
count.value += 1
26+
})
27+
})
28+
onUnmounted(() => {
29+
if (unsubscribe) unsubscribe()
2130
})
2231
2332
const changeGlobal = () => {
24-
event.emit('change')
33+
event_.emit('change')
2534
}
2635
</script>

docs/demo/useEventEmitter/GlobalDemo.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
const event = useEventEmitter({ global: true })
1111
const globalCount = ref(0)
1212
13-
event.useSubscription('change', () => {
13+
event.subscribe('change', () => {
14+
console.log('global', event)
1415
globalCount.value += 1
1516
})
1617
</script>

docs/demo/useEventEmitter/demo.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
}
2828
2929
const changeA = () => {
30-
// globalCount.value += 1
3130
eventA.emit('change')
3231
}
3332
</script>

docs/demo/useMouse/demo.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
<p>Client - x: {{ mouse.clientX }}, y: {{ mouse.clientY }}</p>
44
<p>Page - x: {{ mouse.pageX }}, y: {{ mouse.pageY }}</p>
55
<p>Screen - x: {{ mouse.screenX }}, y: {{ mouse.screenY }}</p>
6+
<UseMouse v-slot="{ clientX, clientY }">
7+
<p>component use: {{ clientX }}, y: {{ clientY }}</p>
8+
</UseMouse>
69
</div>
710
</template>
811

912
<script lang="ts" setup>
10-
import { useMouse } from 'vue-hooks-plus'
13+
import { useMouse, UseMouse } from 'vue-hooks-plus'
1114
const mouse = useMouse()
1215
</script>

docs/demo/useMouse/demo1.vue

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,39 @@
2121
{{ mouse.elementH }}
2222
</p>
2323
</div>
24+
25+
<h3>UseMouse Component</h3>
26+
<UseMouse>
27+
<template #default="{ elementX, elementY,elementPosX,elementPosY,elementW,elementH }">
28+
<p>Mouse In Element - x: {{ elementX }}, y: {{ elementY }}</p>
29+
<p> Element Position - x: {{ elementPosX }}, y: {{ elementPosY }} </p>
30+
<p>
31+
Element Dimensions - width: {{ elementW }}, height:
32+
{{ elementH }}
33+
</p>
34+
</template>
35+
<template #target>
36+
<div
37+
ref="domRef"
38+
:style="{
39+
width: '200px',
40+
height: '200px',
41+
backgroundColor: 'gray',
42+
opacity: 0.85,
43+
color: 'white',
44+
lineHeight: '200px',
45+
textAlign: 'center',
46+
}"
47+
>
48+
element
49+
</div>
50+
</template>
51+
</UseMouse>
2452
</template>
2553

2654
<script lang="ts" setup>
2755
import { ref } from 'vue'
28-
import { useMouse } from 'vue-hooks-plus'
56+
import { useMouse, UseMouse } from 'vue-hooks-plus'
2957
const domRef = ref(null)
3058
const mouse = useMouse(domRef)
3159
</script>

0 commit comments

Comments
 (0)