import type { mastodon } from "masto"; import { splitProps, type Component, type JSX, Show, createRenderEffect, createSignal, type Setter, } from "solid-js"; import tootStyle from "./toot.module.css"; import { formatRelative } from "date-fns"; import Img from "../material/Img.js"; import { Body2 } from "../material/typography.js"; import { css } from "solid-styled"; import { BookmarkAddOutlined, Repeat, ReplyAll, Star, StarOutline, Bookmark, Share, SmartToySharp, Lock, } from "@suid/icons-material"; import { useTimeSource } from "../platform/timesrc.js"; import { resolveCustomEmoji } from "../masto/toot.js"; import { Divider } from "@suid/material"; import cardStyle from "../material/cards.module.css"; import Button from "../material/Button.js"; import MediaAttachmentGrid from "./toots/MediaAttachmentGrid.jsx"; import { useDateFnLocale } from "../platform/i18n"; import { canShare, share } from "../platform/share"; import { makeAcctText, useDefaultSession } from "../masto/clients"; import TootContent from "./toots/TootContent"; import BoostIcon from "./toots/BoostIcon"; import PreviewCard from "./toots/PreviewCard"; type TootActionGroupProps = { onRetoot?: (value: T) => void; onFavourite?: (value: T) => void; onBookmark?: (value: T) => void; onReply?: ( value: T, event: MouseEvent & { currentTarget: HTMLButtonElement }, ) => void; }; type RegularTootProps = { status: mastodon.v1.Status; actionable?: boolean; evaluated?: boolean; thread?: "top" | "bottom" | "middle"; } & TootActionGroupProps & JSX.HTMLElementTags["article"]; function isolatedCallback(e: MouseEvent) { e.stopPropagation(); } export function findRootToot(element: HTMLElement) { let current: HTMLElement | null = element; while (current && !current.classList.contains(tootStyle.toot)) { current = current.parentElement; } if (!current) { throw Error( `the element must be placed under a element with ${tootStyle.toot}`, ); } return current; } function TootActionGroup( props: TootActionGroupProps & { value: T }, ) { let actGrpElement: HTMLDivElement; const toot = () => props.value; return (
); } function TootAuthorGroup( props: { status: mastodon.v1.Status; now: Date; } & JSX.HTMLElementTags["div"], ) { const [managed, rest] = splitProps(props, ["status", "now"]); const toot = () => managed.status; const dateFnLocale = useDateFnLocale(); return (
{ createRenderEffect(() => { e.innerHTML = resolveCustomEmoji( toot().account.displayName, toot().account.emojis, ); }); }} />
@{toot().account.username}@{new URL(toot().account.url).hostname}
); } /** * find bottom-to-top the element with `data-action`. */ export function findElementActionable( element: HTMLElement, top: HTMLElement, ): HTMLElement | undefined { let current = element; while (!current.dataset.action) { if (!current.parentElement || current.parentElement === top) { return undefined; } current = current.parentElement; } return current; } function onToggleReveal(setValue: Setter, event: Event) { event.stopPropagation(); setValue((x) => !x); } /** * Component for a toot. * * If the session involved is not the first session, you must wrap * this component under a `` with correct * session. * * **Handling Clicks** * There are multiple actions supported in the component. Some handlers * are passed in, some should be handled as the click event. * * For those handler directly passed in, see the props starts with "on". * We are moving to the new method below. * * The following actions are handled by the click event: * - `[data-action="acct"]`: open the profile page of a account * - `[data-acct-id]` is the account id for the client * - `[data-client]` is the client perferred * - `[href]` is the url of the account * * Handling the click event for this component, you should use * {@link findElementActionable} to find out if the click event has * additional intent. If the event's target is any from * the subtree of any "actionable" element, the function returns the element. * * You can extract the intent from the attributes of the "actionable" element. * The action type is the dataset's `action`. */ const RegularToot: Component = (props) => { let rootRef: HTMLElement; const [managed, managedActionGroup, rest] = splitProps( props, ["status", "lang", "class", "actionable", "evaluated", "thread"], ["onRetoot", "onFavourite", "onBookmark", "onReply"], ); const now = useTimeSource(); const status = () => managed.status; const toot = () => status().reblog ?? status(); const session = useDefaultSession(); const [reveal, setReveal] = createSignal(false); css` .reply-sep { margin-left: calc(var(--toot-avatar-size) + var(--card-pad) + 8px); margin-block: 8px; } .thread-top, .thread-mid, .thread-btm { position: relative; &::before { content: ""; position: absolute; left: 36px; background-color: var(--tutu-color-secondary); width: 2px; display: block; } } .thread-mid { &::before { top: 0; bottom: 0; } } .thread-top { &::before { top: 16px; bottom: 0; } } .thread-btm { &::before { top: 0; height: 16px; } } `; return ( <>
{ createRenderEffect(() => { e.innerHTML = resolveCustomEmoji( status().account.displayName, toot().emojis, ); }); }} > boosts
0}>
); }; export default RegularToot;