-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zuofenghua
committed
Aug 21, 2020
1 parent
5e7d30b
commit b692303
Showing
7 changed files
with
111 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { reactive, toRefs } from 'vue' | ||
|
||
export function useCopyCode(code: string) { | ||
const state = reactive({ | ||
showTip: false | ||
}) | ||
|
||
function copyCode() { | ||
navigator.clipboard.writeText(code) | ||
state.showTip = true | ||
setTimeout(() => { | ||
state.showTip = false | ||
}, 5 * 1000) | ||
} | ||
|
||
return { | ||
...toRefs(state), | ||
copyCode | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { reactive, computed, toRefs } from 'vue' | ||
|
||
import { JS_RE, CSS_RE, HTML_RE } from './OnlineEdit/constants' | ||
import { getMatchedResult, parseAndDecode } from './OnlineEdit/utils' | ||
|
||
export function useParseCode( | ||
decodedCodeStr: string, | ||
jsLibsStr: string, | ||
cssLibsStr: string | ||
) { | ||
const state = reactive({ | ||
expand: false | ||
}) | ||
|
||
const toggleExpand = () => (state.expand = !state.expand) | ||
|
||
const parsedCode = computed(() => { | ||
const js = getMatchedResult(JS_RE)(decodedCodeStr) || '' | ||
const css = getMatchedResult(CSS_RE)(decodedCodeStr) || '' | ||
const html = | ||
getMatchedResult(HTML_RE)(decodedCodeStr) || | ||
decodedCodeStr | ||
.replace(JS_RE, '') | ||
.replace(CSS_RE, '') | ||
.replace(HTML_RE, '') | ||
.trim() | ||
|
||
const jsLibs = parseAndDecode(jsLibsStr) | ||
const cssLibs = parseAndDecode(cssLibsStr) | ||
|
||
return { js, css, html, jsLibs, cssLibs } | ||
}) | ||
|
||
return { | ||
...toRefs(state), | ||
toggleExpand, | ||
parsedCode | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters