impr: switch menus to attachment based vs cursed div wrapper
This commit is contained in:
20 files changed
+93
-93
No files matched your search
@@ -66,8 +66,9 @@
|
||||
<CommentModerationMenu bind:item={comment} />
|
||||
{/if}
|
||||
<Menu placement="bottom">
|
||||
{#snippet target()}
|
||||
{#snippet target(attachment)}
|
||||
<Button
|
||||
{@attach attachment}
|
||||
title={$t('comment.actions.label')}
|
||||
color="tertiary"
|
||||
rounding="pill"
|
||||
|
||||
@@ -270,8 +270,8 @@
|
||||
</Button>
|
||||
{/if}
|
||||
<Menu placement="top-end">
|
||||
{#snippet target()}
|
||||
<Button size="square-md" rounding="pill">
|
||||
{#snippet target(attachment)}
|
||||
<Button {@attach attachment} size="square-md" rounding="pill">
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} size="16" mini />
|
||||
{/snippet}
|
||||
|
||||
@@ -193,8 +193,8 @@
|
||||
{#if site.data}
|
||||
<div class="flex gap-2 flex-wrap flex-row">
|
||||
<Menu class="gap-px">
|
||||
{#snippet target()}
|
||||
<button type="button">
|
||||
{#snippet target(attachment)}
|
||||
<button {@attach attachment} type="button">
|
||||
<Badge color="blue-subtle">
|
||||
<Icon src={Plus} micro size="14" />
|
||||
{$t('common.add')}
|
||||
|
||||
@@ -170,8 +170,8 @@
|
||||
</Button>
|
||||
{/if}
|
||||
<Menu placement="top-end">
|
||||
{#snippet target()}
|
||||
<Button size="custom" rounding="pill" class="h-8.5 aspect-square">
|
||||
{#snippet target(attachment)}
|
||||
<Button {@attach attachment} size="custom" rounding="pill" class="h-8.5 aspect-square">
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} size="16" mini />
|
||||
{/snippet}
|
||||
|
||||
@@ -24,8 +24,9 @@
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom" class="top-0 h-[26px] w-[26px] ">
|
||||
{#snippet target()}
|
||||
{#snippet target(attachment)}
|
||||
<Button
|
||||
{@attach attachment}
|
||||
class="w-[26px] h-[26px] hover:text-green-500! dark:text-zinc-400 text-slate-600"
|
||||
size="square-md"
|
||||
color="tertiary"
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import { amMod, ban, isAdmin, remove, viewVotes } from './moderation'
|
||||
import type { Attachment } from 'svelte/attachments'
|
||||
|
||||
interface Props {
|
||||
item: PostView | CommentView
|
||||
target: Snippet<[boolean]>
|
||||
target: Snippet<[Attachment, boolean]>
|
||||
}
|
||||
|
||||
let { item = $bindable(), target: passedTarget }: Props = $props()
|
||||
@@ -75,8 +76,8 @@
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom-end">
|
||||
{#snippet target()}
|
||||
{@render passedTarget(acting)}
|
||||
{#snippet target(attachment)}
|
||||
{@render passedTarget(attachment, acting)}
|
||||
{/snippet}
|
||||
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
||||
<MenuDivider showLabel>
|
||||
|
||||
@@ -134,8 +134,9 @@
|
||||
{#if profile.current?.user && (amMod(profile.current.user, post.community) || isAdmin(profile.current.user))}
|
||||
{#await import('$lib/components/lemmy/moderation/ModerationMenu.svelte') then { default: ModerationMenu }}
|
||||
<ModerationMenu bind:item={post}>
|
||||
{#snippet target(acting)}
|
||||
{#snippet target(attachment, acting)}
|
||||
<Button
|
||||
{@attach attachment}
|
||||
size="custom"
|
||||
color="secondary"
|
||||
rounding="pill"
|
||||
@@ -172,8 +173,9 @@
|
||||
{/if}
|
||||
|
||||
<Menu placement="bottom-end">
|
||||
{#snippet target()}
|
||||
{#snippet target(popover)}
|
||||
<Button
|
||||
{@attach popover}
|
||||
title={$t('post.actions.more.label')}
|
||||
color="secondary"
|
||||
rounding="pill"
|
||||
|
||||
@@ -105,8 +105,9 @@
|
||||
href="/create"
|
||||
/>
|
||||
<Menu placement="bottom">
|
||||
{#snippet target()}
|
||||
{#snippet target(attachment)}
|
||||
<button
|
||||
{@attach attachment}
|
||||
class="w-10 h-10 rounded-full border-slate-200 dark:border-zinc-700
|
||||
transition-all bg-slate-50 dark:bg-zinc-900 relative
|
||||
hover:bg-slate-200 dark:hover:bg-zinc-700 group cursor-pointer"
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
MenuButton,
|
||||
MenuDivider,
|
||||
modal,
|
||||
Modal,
|
||||
Option,
|
||||
Select,
|
||||
Spinner,
|
||||
@@ -41,8 +40,6 @@
|
||||
UserCircle,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
let showInstance = $state(false)
|
||||
</script>
|
||||
|
||||
{#snippet siteSnippet()}
|
||||
@@ -140,8 +137,9 @@
|
||||
<!--svelte-ignore a11y_no_static_element_interactions-->
|
||||
<div onclick={e => e.stopPropagation()}>
|
||||
<Select bind:value={theme.colorScheme} size="sm">
|
||||
{#snippet target()}
|
||||
{#snippet target(attachment)}
|
||||
<MenuButton
|
||||
{@attach attachment}
|
||||
icon={theme.colorScheme == 'system'
|
||||
? ComputerDesktop
|
||||
: theme.colorScheme == 'light'
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom">
|
||||
{#snippet target()}
|
||||
{#snippet target(attachment)}
|
||||
<Button
|
||||
{@attach attachment}
|
||||
color="tertiary"
|
||||
alignment="left"
|
||||
size="md"
|
||||
|
||||
@@ -83,8 +83,9 @@
|
||||
icon={Cog6Tooth}
|
||||
/>
|
||||
<Select bind:value={theme.colorScheme} size="sm">
|
||||
{#snippet target()}
|
||||
{#snippet target(attachment)}
|
||||
<SidebarButton
|
||||
{@attach attachment}
|
||||
label={$t('nav.menu.colorscheme.label')}
|
||||
icon={theme.colorScheme == 'system'
|
||||
? ComputerDesktop
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
},
|
||||
]
|
||||
>
|
||||
target?: Snippet
|
||||
target?: Snippet<[Attachment]>
|
||||
oncontextmenu?: HTMLSelectAttributes['oncontextmenu']
|
||||
onchange?: HTMLSelectAttributes['onchange']
|
||||
placement?: Placement
|
||||
@@ -54,6 +54,7 @@
|
||||
import Label from '../Label.svelte'
|
||||
import { generateID } from '../helper.js'
|
||||
import type { Placement } from 'svelte-floating-ui/core'
|
||||
import type { Attachment } from 'svelte/attachments'
|
||||
|
||||
let open = $state(false)
|
||||
let element: HTMLSelectElement | undefined = $state()
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
type Strategy,
|
||||
} from '@floating-ui/core'
|
||||
import Popover from '../popover/Popover.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import type { Attachment } from 'svelte/attachments'
|
||||
|
||||
interface Props {
|
||||
openOnHover?: boolean
|
||||
@@ -17,7 +19,7 @@
|
||||
middleware?: Middleware[]
|
||||
strategy?: Strategy
|
||||
class?: string
|
||||
target?: import('svelte').Snippet
|
||||
target?: Snippet<[Attachment]>
|
||||
children?: import('svelte').Snippet<[boolean]>
|
||||
}
|
||||
|
||||
@@ -41,11 +43,11 @@
|
||||
{middleware}
|
||||
{strategy}
|
||||
{manual}
|
||||
{target}
|
||||
{...rest}
|
||||
bind:open
|
||||
popoverClass="rounded-xl w-full backdrop-blur-md max-w-72"
|
||||
class={clazz}
|
||||
{target}
|
||||
>
|
||||
{#snippet popover()}
|
||||
<div
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
} from '@floating-ui/core'
|
||||
import { createFloatingActions } from 'svelte-floating-ui'
|
||||
import { focusTrap } from 'svelte-focus-trap'
|
||||
import type { Attachment } from 'svelte/attachments'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { scale } from 'svelte/transition'
|
||||
import { Material } from '../index'
|
||||
@@ -24,7 +25,7 @@
|
||||
manual?: boolean
|
||||
popoverClass?: string
|
||||
class?: string
|
||||
target?: import('svelte').Snippet
|
||||
target?: import('svelte').Snippet<[Attachment]>
|
||||
popover?: import('svelte').Snippet<[boolean]>
|
||||
children?: import('svelte').Snippet<[boolean]>
|
||||
}
|
||||
@@ -36,17 +37,12 @@
|
||||
placement = 'bottom-start',
|
||||
middleware = [offset(6), shift(), flip()],
|
||||
strategy = 'fixed',
|
||||
manual = false,
|
||||
popoverClass = '',
|
||||
class: clazz = '',
|
||||
target,
|
||||
popover,
|
||||
children,
|
||||
}: Props = $props()
|
||||
|
||||
let canUseContents = $state(true)
|
||||
|
||||
let el = $state<HTMLElement>()
|
||||
let popoverEl = $state<HTMLElement>()
|
||||
|
||||
let origins: Record<Placement, string> = {
|
||||
@@ -75,66 +71,58 @@
|
||||
},
|
||||
})
|
||||
|
||||
const customFloatingContent = (node: HTMLDivElement) => {
|
||||
floatingContent(node)
|
||||
}
|
||||
const menuAttach: Attachment = element => {
|
||||
console.log(element)
|
||||
const e = element as HTMLButtonElement
|
||||
|
||||
const customFloatingRef = (node: HTMLDivElement) => {
|
||||
const n = node.children.item(0)
|
||||
const mouseLeave = () => (openOnHover ? (open = false) : false)
|
||||
const focus = () => (openOnHover ? (open = true) : false)
|
||||
const focusout = () => (openOnHover ? (open = false) : false)
|
||||
const click = () => {
|
||||
open = !open
|
||||
|
||||
// @ts-expect-error svelte hell
|
||||
if (n) floatingRef(n)
|
||||
else {
|
||||
canUseContents = false
|
||||
floatingRef(node)
|
||||
if (autoClose) {
|
||||
const clickHandler = (event: Event) => {
|
||||
if (!e) return
|
||||
|
||||
if (!e?.contains(event.target as Node | null)) {
|
||||
if (!autoClose) {
|
||||
// @ts-expect-error svelte hell
|
||||
if (popoverEl && !popoverEl.contains(event.target)) {
|
||||
open = false
|
||||
}
|
||||
} else {
|
||||
open = false
|
||||
}
|
||||
document.removeEventListener('click', clickHandler)
|
||||
}
|
||||
}
|
||||
document.addEventListener('click', clickHandler)
|
||||
}
|
||||
}
|
||||
const keydown = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') open = false
|
||||
}
|
||||
|
||||
e.addEventListener('mouseleave', mouseLeave)
|
||||
e.addEventListener('focus', focus)
|
||||
e.addEventListener('focusout', focusout)
|
||||
e.addEventListener('click', click)
|
||||
e.addEventListener('keydown', keydown)
|
||||
|
||||
floatingRef(e)
|
||||
|
||||
return () => {
|
||||
e.removeEventListener('mouseleave', mouseLeave)
|
||||
e.removeEventListener('focus', focus)
|
||||
e.removeEventListener('focusout', focusout)
|
||||
e.removeEventListener('click', click)
|
||||
e.removeEventListener('keydown', keydown)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:body
|
||||
onclick={e => {
|
||||
if (openOnHover) return
|
||||
|
||||
// @ts-expect-error svelte hell
|
||||
if (!el?.contains(e.target) && open) {
|
||||
if (!autoClose) {
|
||||
// @ts-expect-error svelte hell
|
||||
if (popoverEl && !popoverEl.contains(e.target)) {
|
||||
open = false
|
||||
}
|
||||
} else {
|
||||
open = false
|
||||
}
|
||||
}
|
||||
}}
|
||||
onkeydown={async e => {
|
||||
if (open && e.key == 'Escape') {
|
||||
open = false
|
||||
// @ts-expect-error svelte hell
|
||||
el?.firstChild.focus()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
{#if target}
|
||||
<div
|
||||
onmouseover={() => (openOnHover ? (open = true) : false)}
|
||||
onmouseleave={() => (openOnHover ? (open = false) : false)}
|
||||
onfocus={() => (openOnHover ? (open = true) : false)}
|
||||
onfocusout={() => (openOnHover ? (open = false) : false)}
|
||||
onclick={() => (!openOnHover && !manual ? (open = !open) : false)}
|
||||
onkeydown={e => {
|
||||
if (e.key == 'Escape') open = false
|
||||
}}
|
||||
tabindex="0"
|
||||
role="button"
|
||||
class="{canUseContents ? 'contents text-left' : 'w-max h-max'} {clazz}"
|
||||
bind:this={el}
|
||||
use:customFloatingRef
|
||||
>
|
||||
{@render target?.()}
|
||||
</div>
|
||||
{/if}
|
||||
{@render target?.(menuAttach)}
|
||||
|
||||
{#if open}
|
||||
<Portal class="z-150">
|
||||
@@ -146,7 +134,7 @@
|
||||
easing: expoOut,
|
||||
}}
|
||||
class="z-150 {popoverClass}"
|
||||
use:customFloatingContent
|
||||
use:floatingContent
|
||||
use:focusTrap
|
||||
bind:this={popoverEl}
|
||||
>
|
||||
|
||||
@@ -65,9 +65,10 @@
|
||||
|
||||
<div class="relative">
|
||||
<Menu bind:open={openMenu}>
|
||||
{#snippet target()}
|
||||
{#snippet target(attachment)}
|
||||
{#if input}{@render input()}{:else}
|
||||
<TextInput
|
||||
{@attach attachment}
|
||||
bind:value={query}
|
||||
oninput={e => {
|
||||
searching = true
|
||||
|
||||
@@ -171,8 +171,9 @@
|
||||
</span>
|
||||
</div>
|
||||
<Menu placement="bottom-end">
|
||||
{#snippet target()}
|
||||
{#snippet target(attachment)}
|
||||
<Button
|
||||
{@attach attachment}
|
||||
size="square-md"
|
||||
color="tertiary"
|
||||
class="justify-self-end ml-auto z-50"
|
||||
|
||||
@@ -188,8 +188,8 @@
|
||||
{#if site.data}
|
||||
<div class="flex gap-2 flex-wrap flex-row">
|
||||
<Menu class="gap-px">
|
||||
{#snippet target()}
|
||||
<button type="button">
|
||||
{#snippet target(attachment)}
|
||||
<button {@attach attachment} type="button">
|
||||
<Badge color="blue-subtle">
|
||||
<Icon src={Plus} micro size="14" />
|
||||
{$t('common.add')}
|
||||
|
||||
@@ -120,8 +120,8 @@
|
||||
{#if site.data && formData.discussion_languages}
|
||||
<div class="flex gap-2 flex-wrap flex-row">
|
||||
<Menu class="gap-px">
|
||||
{#snippet target()}
|
||||
<button type="button">
|
||||
{#snippet target(attachment)}
|
||||
<button {@attach attachment} type="button">
|
||||
<Badge color="blue-subtle">
|
||||
<Icon src={Plus} micro size="14" />
|
||||
{$t('common.add')}
|
||||
|
||||
@@ -48,8 +48,9 @@
|
||||
]}
|
||||
>
|
||||
<Menu class="flex-1" placement="bottom-end">
|
||||
{#snippet target()}
|
||||
{#snippet target(attachment)}
|
||||
<Button
|
||||
{@attach attachment}
|
||||
aria-label={$t('post.actions.more.label')}
|
||||
size="square-sm"
|
||||
color="none"
|
||||
|
||||
@@ -240,8 +240,8 @@
|
||||
{/if}
|
||||
{#if isAdmin(profile.current?.user)}
|
||||
<Menu class="ml-auto" placement="bottom-end">
|
||||
{#snippet target()}
|
||||
<Button size="sm" rounding="pill">
|
||||
{#snippet target(attachment)}
|
||||
<Button {@attach attachment} size="sm" rounding="pill">
|
||||
<ShieldIcon width={16} filled />
|
||||
{$t('moderation.label')}
|
||||
</Button>
|
||||
|
||||
Reference in new issue
Block a user