@code-coaching/vuetiful 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -135
- package/dist/style.css +10 -1
- package/dist/styles/all.css +259 -15
- package/dist/types/directives/clipboard.d.ts +3 -0
- package/dist/types/directives/index.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/code-block/code-block.vue.d.ts +110 -0
- package/dist/types/utils/code-block/highlight.d.ts +4 -0
- package/dist/types/utils/index.d.ts +2 -2
- package/dist/vuetiful.es.mjs +46479 -24
- package/dist/vuetiful.umd.js +25 -17
- package/package.json +4 -1
- package/src/directives/clipboard.ts +9 -0
- package/src/directives/index.ts +5 -0
- package/src/index.ts +1 -0
- package/src/utils/code-block/code-block.vue +106 -0
- package/src/utils/code-block/highlight.ts +19 -0
- package/src/utils/index.ts +3 -2
- package/dist/types/utils/MyUtil.d.ts +0 -5
- package/src/utils/MyUtil.ts +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-coaching/vuetiful",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "onchange 'src/**/*.vue' 'src/**/*.ts' 'src/**/*.css' -- npm run build",
|
|
6
6
|
"prebuild": "node 'scripts/intellisense.js'",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"vue": "^3.2.25"
|
|
15
15
|
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"highlight.js": "^11.7.0"
|
|
18
|
+
},
|
|
16
19
|
"devDependencies": {
|
|
17
20
|
"@types/node": "^17.0.14",
|
|
18
21
|
"@vitejs/plugin-vue": "^2.0.0",
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ export default { install };
|
|
|
15
15
|
export * from "./components";
|
|
16
16
|
export * from "./constants";
|
|
17
17
|
export * from "./utils";
|
|
18
|
+
export * from "./directives";
|
|
18
19
|
|
|
19
20
|
// This type alias is to identify CSS classes within component props, which enables Tailwind IntelliSense
|
|
20
21
|
export type CssClasses = string;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { CssClasses, vClipboard } from "@/index";
|
|
3
|
+
import "highlight.js/styles/github-dark.css";
|
|
4
|
+
import { computed, ref, useAttrs } from "vue";
|
|
5
|
+
import { useHighlight } from "./highlight";
|
|
6
|
+
|
|
7
|
+
const { highlight } = useHighlight();
|
|
8
|
+
|
|
9
|
+
const props = defineProps({
|
|
10
|
+
language: {
|
|
11
|
+
type: String,
|
|
12
|
+
default: "plaintext",
|
|
13
|
+
},
|
|
14
|
+
code: {
|
|
15
|
+
type: String,
|
|
16
|
+
default: "",
|
|
17
|
+
},
|
|
18
|
+
background: {
|
|
19
|
+
type: String as () => CssClasses,
|
|
20
|
+
default: "bg-neutral-900/90",
|
|
21
|
+
},
|
|
22
|
+
blur: {
|
|
23
|
+
type: String as () => CssClasses,
|
|
24
|
+
default: "",
|
|
25
|
+
},
|
|
26
|
+
text: {
|
|
27
|
+
type: String as () => CssClasses,
|
|
28
|
+
default: "text-sm",
|
|
29
|
+
},
|
|
30
|
+
color: {
|
|
31
|
+
type: String as () => CssClasses,
|
|
32
|
+
default: "text-white",
|
|
33
|
+
},
|
|
34
|
+
rounded: {
|
|
35
|
+
type: String as () => CssClasses,
|
|
36
|
+
default: "rounded-container-token",
|
|
37
|
+
},
|
|
38
|
+
shadow: {
|
|
39
|
+
type: String as () => CssClasses,
|
|
40
|
+
default: "shadow",
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
button: {
|
|
44
|
+
type: String as () => CssClasses,
|
|
45
|
+
default: "btn btn-sm variant-soft",
|
|
46
|
+
},
|
|
47
|
+
buttonLabel: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: "Copy",
|
|
50
|
+
},
|
|
51
|
+
buttonCopied: {
|
|
52
|
+
type: String,
|
|
53
|
+
default: "👍",
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const attrs = useAttrs();
|
|
58
|
+
const emit = defineEmits<{
|
|
59
|
+
(event: "copy"): void;
|
|
60
|
+
}>();
|
|
61
|
+
|
|
62
|
+
const cBase = "overflow-hidden shadow";
|
|
63
|
+
const cHeader = "text-xs text-white/50 uppercase flex justify-between items-center p-2 pl-4 pb-0";
|
|
64
|
+
const cPre = "whitespace-pre-wrap break-all p-4 pt-1";
|
|
65
|
+
|
|
66
|
+
const copyState = ref(false);
|
|
67
|
+
|
|
68
|
+
// Allow shorthand alias, but show full text in UI
|
|
69
|
+
function languageFormatter(lang: string): string {
|
|
70
|
+
if (lang === "js") return "javascript";
|
|
71
|
+
if (lang === "ts") return "typescript";
|
|
72
|
+
if (["sh", "bash", "zsh", "shell"].includes(lang)) return "console";
|
|
73
|
+
return lang;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function onCopyClick() {
|
|
77
|
+
copyState.value = true;
|
|
78
|
+
setTimeout(() => {
|
|
79
|
+
copyState.value = false;
|
|
80
|
+
}, 2000);
|
|
81
|
+
emit("copy");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Reactive
|
|
85
|
+
const classesBase = computed(
|
|
86
|
+
() =>
|
|
87
|
+
`${cBase} ${props.background} ${props.blur} ${props.text} ${props.color} ${props.rounded} ${
|
|
88
|
+
props.shadow
|
|
89
|
+
} ${attrs.class ?? ""}`
|
|
90
|
+
);
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
<!-- prettier-ignore -->
|
|
94
|
+
<template>
|
|
95
|
+
<div v-if="language && code">
|
|
96
|
+
<div :class="`code-block ${classesBase}`" data-testid="code-block">
|
|
97
|
+
<header :class="`code-block-header ${cHeader}`">
|
|
98
|
+
<span :class="`code-block-language`">{{languageFormatter(language)}}</span>
|
|
99
|
+
<button :class="`code-block-btn ${button}`" @click="onCopyClick()" v-clipboard="props.code">
|
|
100
|
+
{{!copyState ? buttonLabel : buttonCopied}}
|
|
101
|
+
</button>
|
|
102
|
+
</header>
|
|
103
|
+
<pre :class="`code-block-pre ${cPre}`"><code :class="`code-block-code language-${language}`" v-html="highlight(props.code, props.language)"></code></pre>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</template>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import hljs from "highlight.js";
|
|
2
|
+
|
|
3
|
+
const highlighter = hljs;
|
|
4
|
+
|
|
5
|
+
const useHighlight = () => {
|
|
6
|
+
const highlight = (code: string, lang: string) => {
|
|
7
|
+
if (lang && highlighter.getLanguage(lang)) {
|
|
8
|
+
return highlighter.highlight(lang, code).value;
|
|
9
|
+
} else {
|
|
10
|
+
return highlighter.highlightAuto(code).value;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
highlight,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { useHighlight };
|
package/src/utils/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useDarkMode } from "./dark-mode/dark-mode";
|
|
2
2
|
import DarkModeSwitch from "./dark-mode/dark-mode.vue";
|
|
3
|
-
import MyUtil from "./MyUtil";
|
|
4
3
|
import { useTheme } from "./theme/theme";
|
|
5
4
|
import ThemeSwitcher from "./theme/theme-switcher.vue";
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
import CodeBlock from "./code-block/code-block.vue";
|
|
7
|
+
|
|
8
|
+
export { DarkModeSwitch, ThemeSwitcher, useDarkMode, useTheme, CodeBlock };
|