1
0
mirror of https://github.com/elk-zone/elk synced 2024-11-30 15:58:06 +09:00

Merge branch 'main' into userquin/feat-remember-last-position

This commit is contained in:
userquin 2023-01-09 18:21:41 +01:00
commit 6ce5eadcac
17 changed files with 110 additions and 88 deletions

View File

@ -8,5 +8,11 @@
"jsonc/sort-keys": "error" "jsonc/sort-keys": "error"
} }
} }
] ],
"rules": {
"vue/no-restricted-syntax":["error", {
"selector": "VElement[name='a']",
"message": "Use NuxtLink instead."
}]
}
} }

View File

@ -28,9 +28,9 @@ defineOptions({
<div w-17 h-17 rounded-full border-4 border-bg-base z-2 mt--2 ms--1> <div w-17 h-17 rounded-full border-4 border-bg-base z-2 mt--2 ms--1>
<AccountAvatar :account="account" /> <AccountAvatar :account="account" />
</div> </div>
<a block sm:hidden href="javascript:;" @click.stop> <NuxtLink block sm:hidden href="javascript:;" @click.stop>
<AccountFollowButton :account="account" /> <AccountFollowButton :account="account" />
</a> </NuxtLink>
</div> </div>
<div sm:mt-2> <div sm:mt-2>
<AccountDisplayName :account="account" font-bold text-lg line-clamp-1 ws-pre-wrap break-all /> <AccountDisplayName :account="account" font-bold text-lg line-clamp-1 ws-pre-wrap break-all />
@ -46,9 +46,9 @@ defineOptions({
<!-- Follow info --> <!-- Follow info -->
<div flex justify-between items-center> <div flex justify-between items-center>
<AccountPostsFollowers text-sm :account="account" /> <AccountPostsFollowers text-sm :account="account" />
<a sm:block hidden href="javascript:;" @click.stop> <NuxtLink sm:block hidden href="javascript:;" @click.stop>
<AccountFollowButton :account="account" /> <AccountFollowButton :account="account" />
</a> </NuxtLink>
</div> </div>
</div> </div>
</component> </component>

View File

@ -1,4 +1,4 @@
<script setup lang="ts" generic="T, O"> <script setup lang="ts" generic="T, O, U = T">
// @ts-expect-error missing types // @ts-expect-error missing types
import { DynamicScroller } from 'vue-virtual-scroller' import { DynamicScroller } from 'vue-virtual-scroller'
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css' import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
@ -10,7 +10,6 @@ const {
keyProp = 'id', keyProp = 'id',
virtualScroller = false, virtualScroller = false,
eventType = 'update', eventType = 'update',
buffer = 10,
preprocess, preprocess,
} = defineProps<{ } = defineProps<{
paginator: Paginator<T[], O> paginator: Paginator<T[], O>
@ -18,24 +17,20 @@ const {
virtualScroller?: boolean virtualScroller?: boolean
stream?: Promise<WsEvents> stream?: Promise<WsEvents>
eventType?: 'notification' | 'update' eventType?: 'notification' | 'update'
// When preprocess is used, buffer is the number of items that will be hidden preprocess?: (items: (U | T)[]) => U[]
// until the next pagination to avoid border effect between pages when reordering
// and grouping items
buffer?: number
preprocess?: (items: T[]) => any[]
}>() }>()
defineSlots<{ defineSlots<{
default: { default: {
items: T[] items: U[]
item: T item: U
index: number index: number
active?: boolean active?: boolean
older?: T older?: U
newer?: T // newer is undefined when index === 0 newer?: U // newer is undefined when index === 0
} }
items: { items: {
items: T[] items: U[]
} }
updater: { updater: {
number: number number: number

View File

@ -23,17 +23,17 @@ const emit = defineEmits<{
</p> </p>
<p> <p>
{{ $t('help.desc_para4') }} {{ $t('help.desc_para4') }}
<a font-bold text-primary href="/m.webtoo.ls/@elk" target="_blank"> <NuxtLink font-bold text-primary href="/m.webtoo.ls/@elk" target="_blank">
{{ $t('help.desc_para5') }} {{ $t('help.desc_para5') }}
</a> </NuxtLink>
{{ $t('help.desc_para6') }} {{ $t('help.desc_para6') }}
</p> </p>
{{ $t('help.desc_para3') }} {{ $t('help.desc_para3') }}
<p flex="~ gap-2 wrap" mxa> <p flex="~ gap-2 wrap" mxa>
<template v-for="team of teams" :key="team.github"> <template v-for="team of teams" :key="team.github">
<a :href="`https://github.com/sponsors/${team.github}`" target="_blank" rounded-full transition duration-300 border="~ transparent" hover="scale-105 border-primary"> <NuxtLink :href="`https://github.com/sponsors/${team.github}`" target="_blank" external rounded-full transition duration-300 border="~ transparent" hover="scale-105 border-primary">
<img :src="`/avatars/${team.github}-100x100.png`" :alt="team.display" rounded-full w-15 h-15 height="60" width="60"> <img :src="`/avatars/${team.github}-100x100.png`" :alt="team.display" rounded-full w-15 h-15 height="60" width="60">
</a> </NuxtLink>
</template> </template>
</p> </p>
<p italic flex justify-center w-full> <p italic flex justify-center w-full>

View File

@ -55,11 +55,17 @@ function toggleDark() {
{{ $t('settings.about.label') }} {{ $t('settings.about.label') }}
</NuxtLink> </NuxtLink>
&middot; &middot;
<a href="/m.webtoo.ls/@elk" target="_blank">Mastodon</a> <NuxtLink href="/m.webtoo.ls/@elk" target="_blank">
Mastodon
</NuxtLink>
&middot; &middot;
<a href="https://chat.elk.zone" target="_blank">Discord</a> <NuxtLink href="https://chat.elk.zone" target="_blank" external>
Discord
</NuxtLink>
&middot; &middot;
<a href="https://github.com/elk-zone" target="_blank">GitHub</a> <NuxtLink href="https://github.com/elk-zone" target="_blank" external>
GitHub
</NuxtLink>
</div> </div>
</footer> </footer>
</template> </template>

View File

@ -1,12 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
import { mastodon } from 'masto' import type { Paginator, WsEvents, mastodon } from 'masto'
import type { Paginator, WsEvents } from 'masto' import type { GroupedAccountLike, NotificationSlot } from '~/types'
// type used in <template>
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import type { GroupedAccountLike, GroupedLikeNotifications, GroupedNotifications, NotificationSlot } from '~/types'
const { paginator, stream } = defineProps<{ const { paginator, stream } = defineProps<{
paginator: Paginator<NotificationSlot[], mastodon.v1.ListNotificationsParams> paginator: Paginator<mastodon.v1.Notification[], mastodon.v1.ListNotificationsParams>
stream?: Promise<WsEvents> stream?: Promise<WsEvents>
}>() }>()
@ -43,21 +40,31 @@ function groupItems(items: mastodon.v1.Notification[]): NotificationSlot[] {
// This normally happens when you transfer an account, if not, show // This normally happens when you transfer an account, if not, show
// a big profile card for each follow // a big profile card for each follow
if (group[0].type === 'follow') { if (group[0].type === 'follow') {
const toGroup = [] let groups: mastodon.v1.Notification[] = []
function newGroup() {
if (groups.length > 0) {
results.push({
id: `grouped-${id++}`,
type: 'grouped-follow',
items: groups,
})
groups = []
}
}
for (const item of group) { for (const item of group) {
const hasHeader = !item.account.header.endsWith('/original/missing.png') const hasHeader = !item.account.header.endsWith('/original/missing.png')
if (hasHeader && (item.account.followersCount > 250 || (group.length === 1 && item.account.followersCount > 25))) if (hasHeader && (item.account.followersCount > 250 || (group.length === 1 && item.account.followersCount > 25))) {
newGroup()
results.push(item) results.push(item)
else }
toGroup.push(item) else {
} groups.push(item)
if (toGroup.length > 0) { }
results.push({
id: `grouped-${id++}`,
type: `grouped-${group[0].type}`,
items: toGroup,
})
} }
newGroup()
return return
} }
@ -105,7 +112,7 @@ function preprocess(items: NotificationSlot[]): NotificationSlot[] {
const flattenedNotifications: mastodon.v1.Notification[] = [] const flattenedNotifications: mastodon.v1.Notification[] = []
for (const item of items) { for (const item of items) {
if (item.type === 'grouped-reblogs-and-favourites') { if (item.type === 'grouped-reblogs-and-favourites') {
const group = item as GroupedLikeNotifications const group = item
for (const like of group.likes) { for (const like of group.likes) {
if (like.reblog) if (like.reblog)
flattenedNotifications.push(like.reblog) flattenedNotifications.push(like.reblog)
@ -113,11 +120,11 @@ function preprocess(items: NotificationSlot[]): NotificationSlot[] {
flattenedNotifications.push(like.favourite) flattenedNotifications.push(like.favourite)
} }
} }
else if (item.type.startsWith('grouped-')) { else if (item.type === 'grouped-follow') {
flattenedNotifications.push(...(item as GroupedNotifications).items) flattenedNotifications.push(...item.items)
} }
else { else {
flattenedNotifications.push(item as mastodon.v1.Notification) flattenedNotifications.push(item)
} }
} }
return groupItems(flattenedNotifications) return groupItems(flattenedNotifications)
@ -143,12 +150,12 @@ const { formatNumber } = useHumanReadableNumber()
/> />
<NotificationGroupedLikes <NotificationGroupedLikes
v-else-if="item.type === 'grouped-reblogs-and-favourites'" v-else-if="item.type === 'grouped-reblogs-and-favourites'"
:group="item as GroupedLikeNotifications" :group="item"
border="b base" border="b base"
/> />
<NotificationCard <NotificationCard
v-else v-else
:notification="item as mastodon.v1.Notification" :notification="item"
hover:bg-active hover:bg-active
border="b base" border="b base"
/> />

View File

@ -364,7 +364,9 @@ const isPublishDisabled = computed(() => {
aria-describedby="publish-tooltip" aria-describedby="publish-tooltip"
@click="publish" @click="publish"
> >
{{ !draft.editingStatus ? $t('action.publish') : $t('action.save_changes') }} <span v-if="draft.editingStatus">{{ $t('action.save_changes') }}</span>
<span v-else-if="draft.params.inReplyToId">{{ $t('action.reply') }}</span>
<span v-else>{{ $t('action.publish') }}</span>
</button> </button>
</CommonTooltip> </CommonTooltip>
</div> </div>

View File

@ -170,11 +170,11 @@ const showReplyTo = $computed(() => !replyToMain && !directReply)
<AccountBotIndicator v-if="status.account.bot" me-2 /> <AccountBotIndicator v-if="status.account.bot" me-2 />
<div flex> <div flex>
<CommonTooltip :content="createdAt"> <CommonTooltip :content="createdAt">
<a :title="status.createdAt" :href="statusRoute.href" @click.prevent="go($event)"> <NuxtLink :title="status.createdAt" :href="statusRoute.href" @click.prevent="go($event)">
<time text-sm ws-nowrap hover:underline :datetime="status.createdAt"> <time text-sm ws-nowrap hover:underline :datetime="status.createdAt">
{{ timeago }} {{ timeago }}
</time> </time>
</a> </NuxtLink>
</CommonTooltip> </CommonTooltip>
<StatusEditIndicator :status="status" inline /> <StatusEditIndicator :status="status" inline />
</div> </div>

View File

@ -46,6 +46,7 @@ const cardTypeIconMap: Record<mastodon.v1.PreviewCardType, string> = {
'rounded-lg border border-base': !root, 'rounded-lg border border-base': !root,
}" }"
target="_blank" target="_blank"
external
> >
<div <div
v-if="card.image" v-if="card.image"

View File

@ -99,13 +99,13 @@ const meta = $computed(() => {
<div p4 sm:px-8 flex flex-col justify-between min-h-50 md:min-h-60 h-full> <div p4 sm:px-8 flex flex-col justify-between min-h-50 md:min-h-60 h-full>
<div flex justify-between items-center gap-2 sm:gap-6 h-full mb-2 min-h-35 md:min-h-45> <div flex justify-between items-center gap-2 sm:gap-6 h-full mb-2 min-h-35 md:min-h-45>
<div flex flex-col gap-2> <div flex flex-col gap-2>
<a flex gap-1 text-xl sm:text-3xl flex-wrap leading-none :href="meta.titleUrl" target="_blank"> <NuxtLink flex gap-1 text-xl sm:text-3xl flex-wrap leading-none :href="meta.titleUrl" target="_blank" external>
<template v-if="meta.repo"> <template v-if="meta.repo">
<span>{{ meta.user }}</span><span text-secondary-light>/</span><span text-primary font-bold>{{ meta.repo }}</span> <span>{{ meta.user }}</span><span text-secondary-light>/</span><span text-primary font-bold>{{ meta.repo }}</span>
</template> </template>
<span v-else>{{ meta.user }}</span> <span v-else>{{ meta.user }}</span>
</a> </NuxtLink>
<a sm:text-lg :href="card.url" target="_blank"> <NuxtLink sm:text-lg :href="card.url" target="_blank" external>
<span v-if="meta.type === 'issue'" text-secondary-light me-2> <span v-if="meta.type === 'issue'" text-secondary-light me-2>
#{{ meta.number }} #{{ meta.number }}
</span> </span>
@ -113,12 +113,12 @@ const meta = $computed(() => {
PR #{{ meta.number }} PR #{{ meta.number }}
</span> </span>
<span text-secondary leading-tight>{{ meta.details }}</span> <span text-secondary leading-tight>{{ meta.details }}</span>
</a> </NuxtLink>
</div> </div>
<div> <div>
<a :href="meta.titleUrl" target="_blank"> <NuxtLink :href="meta.titleUrl" target="_blank" external>
<img w-30 aspect-square width="20" height="20" rounded-2 :src="meta.avatar"> <img w-30 aspect-square width="20" height="20" rounded-2 :src="meta.avatar">
</a> </NuxtLink>
</div> </div>
</div> </div>
<div flex justify-between> <div flex justify-between>

View File

@ -41,14 +41,14 @@ const showOriginSite = $computed(() =>
<template v-if="context === 'account' && showOriginSite" #done> <template v-if="context === 'account' && showOriginSite" #done>
<div p5 text-secondary text-center flex flex-col items-center gap1> <div p5 text-secondary text-center flex flex-col items-center gap1>
<span italic>{{ $t('timeline.view_older_posts') }}</span> <span italic>{{ $t('timeline.view_older_posts') }}</span>
<a <NuxtLink
:href="account!.url" target="_blank" :href="account!.url" target="_blank" external
flex="~ gap-1" items-center text-primary flex="~ gap-1" items-center text-primary
hover="underline text-primary-active" hover="underline text-primary-active"
> >
<div i-ri:external-link-fill /> <div i-ri:external-link-fill />
{{ $t('menu.open_in_original_site') }} {{ $t('menu.open_in_original_site') }}
</a> </NuxtLink>
</div> </div>
</template> </template>
</CommonPaginator> </CommonPaginator>

View File

@ -175,7 +175,7 @@ onClickOutside($$(input), () => {
<div i-ri:lightbulb-line me-1 /> <div i-ri:lightbulb-line me-1 />
<span> <span>
<i18n-t keypath="user.tip_no_account"> <i18n-t keypath="user.tip_no_account">
<a href="https://joinmastodon.org/servers" target="_blank" hover="underline text-primary">{{ $t('user.tip_register_account') }}</a> <NuxtLink href="https://joinmastodon.org/servers" target="_blank" external hover="underline text-primary">{{ $t('user.tip_register_account') }}</NuxtLink>
</i18n-t> </i18n-t>
</span> </span>
</div> </div>

View File

@ -322,7 +322,7 @@ const _markdownReplacements: [RegExp, (c: (string | Node)[]) => Node][] = [
[/~~(.*?)~~/g, c => h('del', null, c)], [/~~(.*?)~~/g, c => h('del', null, c)],
[/`([^`]+?)`/g, c => h('code', null, c)], [/`([^`]+?)`/g, c => h('code', null, c)],
// transform @username@twitter.com as links // transform @username@twitter.com as links
[/\B@([a-zA-Z0-9_]+)@twitter\.com\b/gi, c => h('a', { href: `https://twitter.com/${c}`, target: '_blank', class: 'mention external' }, `@${c}@twitter.com`)], [/\B@([a-zA-Z0-9_]+)@twitter\.com\b/gi, c => h('a', { href: `https://twitter.com/${c}`, target: '_blank', rel: 'nofollow noopener noreferrer', class: 'mention external' }, `@${c}@twitter.com`)],
] ]
function _markdownProcess(value: string) { function _markdownProcess(value: string) {

View File

@ -1,17 +1,17 @@
import type { Paginator, WsEvents } from 'masto' import type { Paginator, WsEvents, mastodon } from 'masto'
import type { PaginatorState } from '~/types' import type { PaginatorState } from '~/types'
import { onReactivated } from '~/composables/vue' import { onReactivated } from '~/composables/vue'
export function usePaginator<T, P>( export function usePaginator<T, P, U = T>(
paginator: Paginator<T[], P>, paginator: Paginator<T[], P>,
stream?: Promise<WsEvents>, stream?: Promise<WsEvents>,
eventType: 'notification' | 'update' = 'update', eventType: 'notification' | 'update' = 'update',
preprocess: (items: T[]) => T[] = (items: T[]) => items, preprocess: (items: (T | U)[]) => U[] = items => items as unknown as U[],
buffer = 10, buffer = 10,
) { ) {
const state = ref<PaginatorState>(isMastoInitialised.value ? 'idle' : 'loading') const state = ref<PaginatorState>(isMastoInitialised.value ? 'idle' : 'loading')
const items = ref<T[]>([]) const items = ref<U[]>([])
const nextItems = ref<T[]>([]) const nextItems = ref<U[]>([])
const prevItems = ref<T[]>([]) const prevItems = ref<T[]>([])
const endAnchor = ref<HTMLDivElement>() const endAnchor = ref<HTMLDivElement>()
@ -24,7 +24,7 @@ export function usePaginator<T, P>(
const nuxtApp = useNuxtApp() const nuxtApp = useNuxtApp()
async function update() { async function update() {
items.value.unshift(...preprocess(prevItems.value as any) as any) (items.value as U[]).unshift(...preprocess(prevItems.value as T[]))
prevItems.value = [] prevItems.value = []
} }
@ -44,17 +44,19 @@ export function usePaginator<T, P>(
s.on('status.update', (status) => { s.on('status.update', (status) => {
cacheStatus(status, undefined, true) cacheStatus(status, undefined, true)
const index = items.value.findIndex((s: any) => s.id === status.id) const data = items.value as mastodon.v1.Status[]
const index = data.findIndex(s => s.id === status.id)
if (index >= 0) if (index >= 0)
items.value[index] = status as any data[index] = status
}) })
s.on('delete', (id) => { s.on('delete', (id) => {
removeCachedStatus(id) removeCachedStatus(id)
const index = items.value.findIndex((s: any) => s.id === id) const data = items.value as mastodon.v1.Status[]
const index = data.findIndex(s => s.id === id)
if (index >= 0) if (index >= 0)
items.value.splice(index, 1) data.splice(index, 1)
}) })
}) })
@ -66,11 +68,14 @@ export function usePaginator<T, P>(
try { try {
const result = await paginator.next() const result = await paginator.next()
if (result.value?.length) { if (!result.done && result.value.length) {
const preprocessedItems = preprocess([...nextItems.value, ...result.value]) as any const preprocessedItems = preprocess([...nextItems.value, ...result.value] as (U | T)[])
const itemsToShowCount = preprocessedItems.length - buffer const itemsToShowCount
nextItems.value = preprocessedItems.slice(itemsToShowCount) = preprocessedItems.length < buffer
items.value.push(...preprocessedItems.slice(0, itemsToShowCount)) ? preprocessedItems.length
: preprocessedItems.length - buffer
;(nextItems.value as U[]) = preprocessedItems.slice(itemsToShowCount)
;(items.value as U[]).push(...preprocessedItems.slice(0, itemsToShowCount))
state.value = 'idle' state.value = 'idle'
} }
else { else {

View File

@ -1,13 +1,13 @@
diff --git a/dist/shared/nitro.c8278d90.mjs b/dist/shared/nitro.c8278d90.mjs diff --git a/dist/shared/nitro.c8278d90.mjs b/dist/shared/nitro.c8278d90.mjs
index 9ba312fc248da3731720ee7e3b38ba2a85537657..3cd508f0720adb959d94e40c124382ec0110d92c 100644 index 9ba312fc248da3731720ee7e3b38ba2a85537657..5ec9f06ccf60259820586715d73d41466daa8cff 100644
--- a/dist/shared/nitro.c8278d90.mjs --- a/dist/shared/nitro.c8278d90.mjs
+++ b/dist/shared/nitro.c8278d90.mjs +++ b/dist/shared/nitro.c8278d90.mjs
@@ -1298,7 +1298,7 @@ async function copyPublicAssets(nitro) { @@ -1296,7 +1296,7 @@ async function copyPublicAssets(nitro) {
if (nitro.options.noPublicDir) {
return;
} }
for (const asset of nitro.options.publicAssets) { - for (const asset of nitro.options.publicAssets) {
+ for (const asset of [...nitro.options.publicAssets].reverse()) {
if (await isDirectory(asset.dir)) { if (await isDirectory(asset.dir)) {
- await fse.copy(asset.dir, join(nitro.options.output.publicDir, asset.baseURL)); await fse.copy(asset.dir, join(nitro.options.output.publicDir, asset.baseURL));
+ await fse.copy(asset.dir, join(nitro.options.output.publicDir, asset.baseURL), { override: false }); }
}
}
if (nitro.options.compressPublicAssets) {

View File

@ -5,7 +5,7 @@ patchedDependencies:
hash: afe7v34zn4lohdq7767l3tlrje hash: afe7v34zn4lohdq7767l3tlrje
path: patches/mlly@1.0.0.patch path: patches/mlly@1.0.0.patch
nitropack@1.0.0: nitropack@1.0.0:
hash: 5rbw6wsrpkguwhgdzu2jwggidq hash: k66pyfgyevhmomc3yledfrjhru
path: patches/nitropack@1.0.0.patch path: patches/nitropack@1.0.0.patch
importers: importers:
@ -8581,7 +8581,7 @@ packages:
- utf-8-validate - utf-8-validate
dev: true dev: true
/nitropack/1.0.0_5rbw6wsrpkguwhgdzu2jwggidq: /nitropack/1.0.0_k66pyfgyevhmomc3yledfrjhru:
resolution: {integrity: sha512-788lHgNgC+NKqecwFgMkAQTuTXwuh2hEgOk2sLwV3qPVUogxrl6P3m5eKdt6Mtzx+mlXIw0G/P90B5TNWEqDSQ==} resolution: {integrity: sha512-788lHgNgC+NKqecwFgMkAQTuTXwuh2hEgOk2sLwV3qPVUogxrl6P3m5eKdt6Mtzx+mlXIw0G/P90B5TNWEqDSQ==}
engines: {node: ^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0} engines: {node: ^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0}
hasBin: true hasBin: true
@ -8911,7 +8911,7 @@ packages:
knitwork: 1.0.0 knitwork: 1.0.0
magic-string: 0.26.7 magic-string: 0.26.7
mlly: 1.0.0_afe7v34zn4lohdq7767l3tlrje mlly: 1.0.0_afe7v34zn4lohdq7767l3tlrje
nitropack: 1.0.0_5rbw6wsrpkguwhgdzu2jwggidq nitropack: 1.0.0_k66pyfgyevhmomc3yledfrjhru
nuxi: 3.0.0 nuxi: 3.0.0
ofetch: 1.0.0 ofetch: 1.0.0
ohash: 1.0.0 ohash: 1.0.0

View File

@ -29,7 +29,7 @@ export type PaginatorState = 'idle' | 'loading' | 'done' | 'error'
export interface GroupedNotifications { export interface GroupedNotifications {
id: string id: string
type: Exclude<string, 'grouped-reblogs-and-favourites'> type: 'grouped-follow'
items: mastodon.v1.Notification[] items: mastodon.v1.Notification[]
} }