|
| 1 | +import { useToggle } from '@vueuse/core' |
| 2 | +import type { FunctionalComponent } from 'vue' |
| 3 | +import { defineComponent, h } from 'vue' |
| 4 | +import type { GitChangelogItem } from '../composables/index.js' |
| 5 | +import { |
| 6 | + useChangelog, |
| 7 | + useGitLocaleConfig, |
| 8 | + useLastUpdated, |
| 9 | +} from '../composables/index.js' |
| 10 | +import { VPHeader } from './VPHeader.js' |
| 11 | + |
| 12 | +import '../styles/vars.css' |
| 13 | +import '../styles/changelog.css' |
| 14 | + |
| 15 | +export const GitChangelog = defineComponent({ |
| 16 | + name: 'GitChangelog', |
| 17 | + |
| 18 | + props: { |
| 19 | + /** Title of changelog */ |
| 20 | + title: String, |
| 21 | + |
| 22 | + /** header level of changelog */ |
| 23 | + headerLevel: { |
| 24 | + type: Number, |
| 25 | + default: 2, |
| 26 | + }, |
| 27 | + }, |
| 28 | + |
| 29 | + setup(props) { |
| 30 | + const changelog = useChangelog() |
| 31 | + const locale = useGitLocaleConfig() |
| 32 | + const latestUpdated = useLastUpdated() |
| 33 | + |
| 34 | + const [active, toggleActive] = useToggle() |
| 35 | + |
| 36 | + const ChangelogHeader: FunctionalComponent = () => |
| 37 | + h( |
| 38 | + 'div', |
| 39 | + { class: 'vp-changelog-header', onClick: () => toggleActive() }, |
| 40 | + [ |
| 41 | + h('div', { class: 'vp-latest-updated' }, [ |
| 42 | + h('span', { class: 'vp-changelog-icon' }), |
| 43 | + h('span', { 'data-allow-mismatch': '' }, latestUpdated.value!.text), |
| 44 | + ]), |
| 45 | + h('div', [ |
| 46 | + h('span', { class: 'vp-changelog-menu-icon' }), |
| 47 | + h('span', locale.value.viewChangelog), |
| 48 | + ]), |
| 49 | + ], |
| 50 | + ) |
| 51 | + |
| 52 | + const ReleaseTag: FunctionalComponent<{ item: GitChangelogItem }> = ({ |
| 53 | + item, |
| 54 | + }) => |
| 55 | + h( |
| 56 | + 'li', |
| 57 | + { class: 'vp-changelog-item-tag' }, |
| 58 | + h('div', [ |
| 59 | + h('a', { class: 'vp-changelog-tag' }, h('code', item.tag)), |
| 60 | + h( |
| 61 | + 'span', |
| 62 | + { 'class': 'vp-changelog-date', 'data-allow-mismatch': '' }, |
| 63 | + [locale.value.timeOn, ' ', item.date], |
| 64 | + ), |
| 65 | + ]), |
| 66 | + ) |
| 67 | + |
| 68 | + const Commit: FunctionalComponent<{ item: GitChangelogItem }> = ({ |
| 69 | + item, |
| 70 | + }) => |
| 71 | + h('li', { class: 'vp-changelog-item-commit' }, [ |
| 72 | + h( |
| 73 | + item.commitUrl ? 'a' : 'span', |
| 74 | + { |
| 75 | + class: 'link hash', |
| 76 | + href: item.commitUrl, |
| 77 | + target: '_blank', |
| 78 | + rel: 'noreferrer', |
| 79 | + }, |
| 80 | + [h('code', item.hash.slice(0, 5))], |
| 81 | + ), |
| 82 | + h('span', { class: 'divider' }, '-'), |
| 83 | + h('span', { class: 'message', innerHTML: item.message }), |
| 84 | + h('span', { 'class': 'vp-changelog-date', 'data-allow-mismatch': '' }, [ |
| 85 | + locale.value.timeOn || 'on', |
| 86 | + ' ', |
| 87 | + item.date, |
| 88 | + ]), |
| 89 | + ]) |
| 90 | + |
| 91 | + return () => |
| 92 | + changelog.value.length |
| 93 | + ? [ |
| 94 | + h(VPHeader, { |
| 95 | + level: props.headerLevel, |
| 96 | + anchor: 'doc-changelog', |
| 97 | + text: props.title || locale.value.changelog, |
| 98 | + }), |
| 99 | + |
| 100 | + h( |
| 101 | + 'div', |
| 102 | + { class: ['vp-changelog-wrapper', { active: active.value }] }, |
| 103 | + [ |
| 104 | + h(ChangelogHeader), |
| 105 | + |
| 106 | + h('ul', { class: 'vp-changelog-list' }, [ |
| 107 | + changelog.value.map((item) => |
| 108 | + item.tag |
| 109 | + ? h(ReleaseTag, { item, key: item.tag }) |
| 110 | + : h(Commit, { item, key: item.hash }), |
| 111 | + ), |
| 112 | + ]), |
| 113 | + ], |
| 114 | + ), |
| 115 | + ] |
| 116 | + : null |
| 117 | + }, |
| 118 | +}) |
0 commit comments