Skip to content

Commit 7aa7e05

Browse files
committed
perf: the security, remove usePreview from version 1.7.2
1 parent 44c845d commit 7aa7e05

File tree

7 files changed

+96
-17
lines changed

7 files changed

+96
-17
lines changed

packages/hooks/docs/.vitepress/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const Router = [
7777
text: 'useAsyncOrder',
7878
link: '/useAsyncOrder/',
7979
},
80-
{ text: 'usePreview', link: '/usePreview/' },
80+
{ text: 'usePreview ⚠️', link: '/usePreview/' },
8181
],
8282
},
8383
{

packages/hooks/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"@types/js-cookie": "^3.0.1",
3737
"js-cookie": "^3.0.1",
3838
"lodash": "^4.17.21",
39-
"marked": "^4.0.17",
4039
"qs": "^6.11.0",
4140
"query-string": "^7.1.1",
4241
"screenfull": "^5.0.0"

packages/hooks/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import useFormatResult from './useFormatResult'
1717
import useFetchs from './useFetchs'
1818
import useFullscreen from './useFullscreen'
1919
import useHover from './useHover'
20-
import usePreview from './usePreview'
20+
// import usePreview from './usePreview'
2121
import usePrevious from './usePrevious'
2222
import useInterval from './useInterval'
2323
import useInfiniteScroll from './useInfiniteScroll'
@@ -79,7 +79,7 @@ export {
7979
useMedia,
8080
useMouse,
8181
useNetwork,
82-
usePreview,
82+
// usePreview,
8383
usePrevious,
8484
useSessionStorageState,
8585
useSet,

packages/hooks/src/usePreview/index.en-US.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,56 @@ map:
66

77
# usePreview
88

9+
:::warning Remark
10+
11+
Due to low usage frequency and reliance on security, `v1.7.2` has been deprecated. The following provides packaging ideas.
12+
13+
:::
14+
915
A hook for previewing the md and vue component views
1016

11-
## Code demonstration
17+
## Source Show
18+
19+
```typescript
20+
import { marked } from 'marked'
21+
import { Ref, computed, unref, ref, watchEffect, createApp, VueElement } from 'vue'
22+
23+
export default function usePreview(
24+
md: Parameters<typeof createApp> | Ref<string> | string | VueElement,
25+
) {
26+
const container = ref<Element>()
27+
const mdCompute = computed(() => unref(md))
28+
29+
watchEffect(onInvalidate => {
30+
if (mdCompute.value && container.value) {
31+
try {
32+
if (typeof mdCompute.value === 'string') {
33+
const html = marked.parse(mdCompute.value)
34+
if (html) container.value.innerHTML = html
35+
} else {
36+
const app = createApp(mdCompute.value)
37+
app.mount(container.value)
38+
}
39+
} catch (error) {
40+
console.log(error)
41+
}
42+
}
43+
44+
onInvalidate(() => {
45+
if (container.value) container.value.innerHTML = ''
46+
})
47+
})
48+
49+
return {
50+
container,
51+
}
52+
}
53+
```
1254

13-
<demo src="./demo/demo.vue"
55+
<!-- <demo src="./demo/demo.vue"
1456
language="vue"
1557
title="Basic usage"
16-
desc="Preview view"> </demo>
58+
desc="Preview view"> </demo> -->
1759

1860
## API
1961

packages/hooks/src/usePreview/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Due to low usage frequency and reliance on security, `v1.7.2` has been deprecated.
3+
*/
14
import { marked } from 'marked'
25
import { Ref, computed, unref, ref, watchEffect, createApp, VueElement } from 'vue'
36

packages/hooks/src/usePreview/index.zh-CN.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,57 @@ map:
66

77
# usePreview
88

9+
:::warning 注意
10+
11+
由于使用频率低和依赖的安全性,`v1.7.2 已弃用`。以下给予封装思路。
12+
13+
:::
14+
915
用于预览 md 和 vue 组件视图的 hook
1016

11-
## 代码演示
17+
## 源码展示
18+
19+
```typescript
20+
import { marked } from 'marked'
21+
import { Ref, computed, unref, ref, watchEffect, createApp, VueElement } from 'vue'
22+
23+
export default function usePreview(
24+
md: Parameters<typeof createApp> | Ref<string> | string | VueElement,
25+
) {
26+
const container = ref<Element>()
27+
const mdCompute = computed(() => unref(md))
28+
29+
watchEffect(onInvalidate => {
30+
if (mdCompute.value && container.value) {
31+
try {
32+
if (typeof mdCompute.value === 'string') {
33+
const html = marked.parse(mdCompute.value)
34+
if (html) container.value.innerHTML = html
35+
} else {
36+
const app = createApp(mdCompute.value)
37+
app.mount(container.value)
38+
}
39+
} catch (error) {
40+
console.log(error)
41+
}
42+
}
43+
44+
onInvalidate(() => {
45+
if (container.value) container.value.innerHTML = ''
46+
})
47+
})
48+
49+
return {
50+
container,
51+
}
52+
}
53+
```
1254

55+
<!--
1356
<demo src="./demo/demo.vue"
1457
language="vue"
1558
title="基本用法"
16-
desc="预览视图"> </demo>
59+
desc="预览视图"> </demo> -->
1760

1861
## API
1962

pnpm-lock.yaml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)