Skip to content

Commit

Permalink
feat(theme)!: migrate plugin-md-enhance to official plugins (#206)
Browse files Browse the repository at this point in the history
* feat(theme)!: migrate `plugin-markdown-hint`

* chore: tweak

* chore: tweak

* chore: tweak

* chore: tweak

* chore: tweak

* chore: tweak

* chore: tweak

* chore: tweak

* chore: tweak

* chore: tweak

* fix(theme): improve `home-blog` styles in mobile, close #210

* chore: tweak

* chore: tweak
  • Loading branch information
pengzhanbo authored Sep 25, 2024
1 parent 6a3c643 commit 4967272
Show file tree
Hide file tree
Showing 42 changed files with 3,199 additions and 2,631 deletions.
3 changes: 3 additions & 0 deletions cli/src/packageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export async function createPackageJson(
if (bundler === 'webpack' && !pkg.dependencies?.['sass-loader'] && !pkg.devDependencies['sass-loader'])
deps.push('sass-loader')

if (!pkg.dependencies?.['sass-embedded'] && !pkg.devDependencies['sass-embedded'])
deps.push('sass-embedded')

const dv = await getDependenciesVersion(deps)

for (const [d, v] of Object.entries(dv))
Expand Down
8 changes: 8 additions & 0 deletions docs/2.preview/主题效果预览.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ function foo() {
}
```

::: tip 仅标题
:::

::: note 注释
注释内容 [link](https://github.com/pengzhanbo) `inline code`

Expand Down Expand Up @@ -318,6 +321,11 @@ const c = a + b

:::

::: details 详细标题

这里是内容。
:::

**GFM alert:**

> [!note]
Expand Down
5 changes: 3 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
"vuepress": "2.0.0-rc.15"
},
"dependencies": {
"@iconify/json": "^2.2.251",
"@iconify/json": "^2.2.252",
"@simonwep/pickr": "^1.9.1",
"@vuepress/bundler-vite": "2.0.0-rc.15",
"chart.js": "^4.4.4",
"echarts": "^5.5.1",
"flowchart.ts": "^3.0.1",
"http-server": "^14.1.1",
"mermaid": "^11.2.1",
"sass-embedded": "^1.79.3",
"swiper": "^11.1.14",
"vue": "^3.5.7",
"vue": "^3.5.8",
"vuepress-theme-plume": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-content-update/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"vuepress": "2.0.0-rc.15"
},
"dependencies": {
"vue": "^3.5.7"
"vue": "^3.5.8"
},
"publishConfig": {
"access": "public"
Expand Down
13 changes: 10 additions & 3 deletions plugins/plugin-md-power/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,22 @@
"vuepress": "2.0.0-rc.15"
},
"dependencies": {
"@vuepress/helper": "2.0.0-rc.46",
"@mdit/plugin-attrs": "^0.13.1",
"@mdit/plugin-footnote": "^0.13.1",
"@mdit/plugin-mark": "^0.13.1",
"@mdit/plugin-sub": "^0.13.1",
"@mdit/plugin-sup": "^0.13.1",
"@mdit/plugin-tab": "^0.13.1",
"@mdit/plugin-tasklist": "^0.13.1",
"@vuepress/helper": "2.0.0-rc.47",
"@vueuse/core": "^11.1.0",
"image-size": "^1.1.1",
"markdown-it-container": "^4.0.0",
"nanoid": "^5.0.7",
"shiki": "^1.18.0",
"tm-grammars": "^1.17.24",
"tm-themes": "^1.8.3",
"vue": "^3.5.7"
"tm-themes": "^1.8.4",
"vue": "^3.5.8"
},
"devDependencies": {
"@types/markdown-it": "^14.1.2"
Expand Down
8 changes: 4 additions & 4 deletions plugins/plugin-md-power/src/client/components/CodeRepl.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import { defineAsyncComponent, shallowRef } from 'vue'
import { useCodeRepl } from '../composables/codeRepl.js'
import IconClose from './IconClose.vue'
import IconConsole from './IconConsole.vue'
import IconRun from './IconRun.vue'
import Loading from './Loading.vue'
import IconClose from './icons/IconClose.vue'
import IconConsole from './icons/IconConsole.vue'
import IconRun from './icons/IconRun.vue'
import Loading from './icons/Loading.vue'
defineProps<{
editable?: boolean
Expand Down
241 changes: 241 additions & 0 deletions plugins/plugin-md-power/src/client/components/CodeTabs.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
<script setup lang="ts">
import { useStorage } from '@vueuse/core'
import { onMounted, ref, shallowRef, watch } from 'vue'
interface TabProps extends Record<string, unknown> {
id: string
}
const props = withDefaults(defineProps<{
id: string
tabId?: string
active?: number
data: TabProps[]
}>(), { active: 0, tabId: '' })
const CODE_TAB_STORE_NAME = 'VUEPRESS_CODE_TAB_STORE'
const codeTabStore = useStorage<Record<string, string>>(CODE_TAB_STORE_NAME, {})
// Index of current active item
const activeIndex = ref(props.active)
// Refs of the tab buttons
const tabRefs = shallowRef<HTMLUListElement[]>([])
// Update store
function updateStore(): void {
if (props.tabId)
codeTabStore.value[props.tabId] = props.data[activeIndex.value].id
}
// Activate next tab
function activateNext(index = activeIndex.value): void {
activeIndex.value = index < tabRefs.value.length - 1 ? index + 1 : 0
tabRefs.value[activeIndex.value].focus()
}
// Activate previous tab
function activatePrev(index = activeIndex.value): void {
activeIndex.value = index > 0 ? index - 1 : tabRefs.value.length - 1
tabRefs.value[activeIndex.value].focus()
}
// Handle keyboard event
function keyboardHandler(event: KeyboardEvent, index: number): void {
if (event.key === ' ' || event.key === 'Enter') {
event.preventDefault()
activeIndex.value = index
}
else if (event.key === 'ArrowRight') {
event.preventDefault()
activateNext()
}
else if (event.key === 'ArrowLeft') {
event.preventDefault()
activatePrev()
}
if (props.tabId)
codeTabStore.value[props.tabId] = props.data[activeIndex.value].id
}
function getInitialIndex(): number {
if (props.tabId) {
const valueIndex = props.data.findIndex(
({ id }) => codeTabStore.value[props.tabId] === id,
)
if (valueIndex !== -1)
return valueIndex
}
return props.active
}
onMounted(() => {
activeIndex.value = getInitialIndex()
watch(
() => codeTabStore.value[props.tabId],
(newValue, oldValue) => {
if (props.tabId && newValue !== oldValue) {
const index = props.data.findIndex(({ id }) => id === newValue)
if (index !== -1)
activeIndex.value = index
}
},
)
})
function onTabNavClick(index: number): void {
activeIndex.value = index
updateStore()
}
</script>

<template>
<div v-if="data.length" class="vp-code-tabs">
<div class="vp-code-tabs-nav" role="tablist">
<button
v-for="(item, index) in data"
:key="index"
:ref="(el) => el && (tabRefs[index] = el as HTMLUListElement)"
class="vp-code-tab-nav" :class="{ active: index === activeIndex }"
type="button" role="tab"
:aria-controls="`codetab-${id}-${index}`"
:aria-selected="index === activeIndex"
@click="() => onTabNavClick(index)"
@keydown="(e) => keyboardHandler(e, index)"
>
<slot :name="`title${index}`" :value="item.id" :is-active="index === activeIndex" />
</button>
</div>
<div
v-for="(item, index) in data"
:id="`codetab-${id}-${index}`" :key="index"
class="vp-code-tab" :class="{ active: index === activeIndex }"
role="tabpanel" :aria-expanded="index === activeIndex"
>
<div class="vp-code-tab-title">
<slot :name="`title${index}`" :value="item.id" :is-active="index === activeIndex" />
</div>
<slot :name="`tab${index}`" :value="item.id" :is-active="index === activeIndex" />
</div>
</div>
</template>

<style>
.vp-code-tabs-nav {
padding: 0 12px;
margin: 16px 0 0;
overflow: auto hidden;
white-space: nowrap;
list-style: none;
background-color: var(--vp-code-tab-bg);
border-radius: 6px 6px 0 0;
box-shadow: inset 0 -1px var(--vp-code-tab-divider);
transition: background-color var(--vp-t-color), box-shadow var(--vp-t-color);
}
@media print {
.vp-code-tabs-nav {
display: none;
}
}
@media (max-width: 639px) {
.vp-code-tabs-nav {
margin: 16px -24px 0;
border-radius: 0;
}
.vp-doc li .vp-code-tabs-nav {
border-top-left-radius: 6px;
}
}
.vp-code-tab-nav {
position: relative;
padding: 0 12px;
font-size: 14px;
font-weight: 500;
line-height: 48px;
color: var(--vp-code-tab-text-color);
white-space: nowrap;
border-bottom: 1px solid transparent;
transition: color var(--vp-t-color);
}
.vp-code-tab-nav:hover {
color: var(--vp-code-tab-hover-text-color);
}
.vp-code-tab-nav::after {
position: absolute;
right: 8px;
bottom: -1px;
left: 8px;
z-index: 1;
display: block;
width: auto;
height: 2px;
content: "";
background: transparent;
border-radius: 2px;
transition: background var(--vp-t-color);
}
.vp-code-tab-nav.active {
color: var(--vp-code-tab-active-text-color);
background: transparent;
}
.vp-code-tab-nav.active::after {
background: var(--vp-code-tab-active-bar-color);
}
.vp-code-tab-nav .vp-icon {
width: 18px;
height: 18px;
margin-left: 0;
}
.vp-code-tab-nav span {
vertical-align: middle;
}
@media (max-width: 419px) {
.hint-container .vp-code-tabs-nav {
margin: 0.85rem -0.75rem 0 -1rem;
}
}
.vp-code-tab {
display: none;
}
@media print {
.vp-code-tab {
display: block;
}
}
.vp-code-tab.active {
display: block;
}
.vp-doc .vp-code-tab div[class*="language-"] {
margin-top: 0;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
.vp-code-tab-title {
display: none;
}
@media print {
.vp-code-tab-title {
display: block;
}
}
</style>
2 changes: 1 addition & 1 deletion plugins/plugin-md-power/src/client/components/Replit.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { ReplitTokenMeta } from '../../shared/index.js'
import { computed, getCurrentInstance, ref } from 'vue'
import Loading from './Loading.vue'
import Loading from './icons/Loading.vue'
const props = defineProps<ReplitTokenMeta>()
Expand Down
Loading

0 comments on commit 4967272

Please sign in to comment.