Merge remote-tracking branch 'origin/dev' into feat/beta-public
Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -61,6 +61,10 @@ jobs:
|
||||
node-version: 22
|
||||
cache: "pnpm"
|
||||
|
||||
- name: Install Python setuptools
|
||||
if: runner.os == 'macOS'
|
||||
run: brew install python-setuptools
|
||||
|
||||
- name: Install appdmg
|
||||
if: runner.os == 'macOS'
|
||||
run: pnpm add -g appdmg
|
||||
|
||||
@@ -51,6 +51,10 @@ jobs:
|
||||
node-version: 22
|
||||
cache: "pnpm"
|
||||
|
||||
- name: Install Python setuptools
|
||||
if: runner.os == 'macOS'
|
||||
run: brew install python-setuptools
|
||||
|
||||
- name: Install appdmg
|
||||
if: runner.os == 'macOS'
|
||||
run: pnpm add -g appdmg
|
||||
|
||||
@@ -28,31 +28,31 @@
|
||||
"@eneris/push-receiver": "4.2.0",
|
||||
"@follow/shared": "workspace:*",
|
||||
"@mozilla/readability": "^0.5.0",
|
||||
"@sentry/electron": "5.4.0",
|
||||
"builder-util-runtime": "9.2.5",
|
||||
"@sentry/electron": "5.6.0",
|
||||
"builder-util-runtime": "9.2.10",
|
||||
"dayjs": "1.11.13",
|
||||
"dotenv": "16.4.5",
|
||||
"electron-context-menu": "4.0.4",
|
||||
"electron-log": "5.2.0",
|
||||
"electron-squirrel-startup": "1.0.1",
|
||||
"electron-updater": "^6.3.4",
|
||||
"electron-updater": "^6.3.9",
|
||||
"font-list": "1.5.1",
|
||||
"i18next": "^23.15.1",
|
||||
"i18next": "^23.16.0",
|
||||
"linkedom": "^0.18.5",
|
||||
"lodash-es": "4.17.21",
|
||||
"lowdb": "7.0.1",
|
||||
"msedge-tts": "1.3.4",
|
||||
"nanoid": "5.0.7",
|
||||
"ofetch": "1.4.0",
|
||||
"posthog-js": "1.165.0",
|
||||
"posthog-node": "4.2.0",
|
||||
"ofetch": "1.4.1",
|
||||
"posthog-js": "1.169.0",
|
||||
"posthog-node": "4.2.1",
|
||||
"semver": "7.6.3",
|
||||
"vscode-languagedetection": "npm:@vscode/vscode-languagedetection@^1.0.22"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash-es": "4.17.12",
|
||||
"@types/node": "^22.7.4",
|
||||
"electron": "32.1.2",
|
||||
"@types/node": "^22.7.5",
|
||||
"electron": "33.0.0",
|
||||
"electron-devtools-installer": "3.2.0",
|
||||
"hono": "4.6.3"
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import { name, version } from "@pkg"
|
||||
import { parseHTML } from "linkedom"
|
||||
import { fetch } from "ofetch"
|
||||
|
||||
import { isDev } from "~/env"
|
||||
|
||||
const userAgents = `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 ${name}/${version}`
|
||||
|
||||
export async function readability(url: string) {
|
||||
@@ -41,7 +43,7 @@ export async function readability(url: string) {
|
||||
})
|
||||
|
||||
const reader = new Readability(document, {
|
||||
// debug: isDev,
|
||||
debug: isDev,
|
||||
})
|
||||
return reader.parse()
|
||||
}
|
||||
|
||||
+47
-45
@@ -13,37 +13,37 @@
|
||||
"@follow/electron-main": "workspace:*",
|
||||
"@follow/shared": "workspace:*",
|
||||
"@fontsource/sn-pro": "5.1.0",
|
||||
"@headlessui/react": "2.1.8",
|
||||
"@hono/auth-js": "1.0.10",
|
||||
"@headlessui/react": "2.1.10",
|
||||
"@hono/auth-js": "1.0.11",
|
||||
"@hookform/resolvers": "3.9.0",
|
||||
"@iconify/tools": "4.0.7",
|
||||
"@lottiefiles/dotlottie-react": "0.9.0",
|
||||
"@lottiefiles/dotlottie-react": "0.9.1",
|
||||
"@microflash/remark-callout-directives": "4.3.1",
|
||||
"@mozilla/readability": "^0.5.0",
|
||||
"@radix-ui/react-avatar": "1.1.0",
|
||||
"@radix-ui/react-checkbox": "1.1.1",
|
||||
"@radix-ui/react-context-menu": "2.2.1",
|
||||
"@radix-ui/react-dialog": "1.1.1",
|
||||
"@radix-ui/react-dropdown-menu": "2.1.1",
|
||||
"@radix-ui/react-hover-card": "1.1.1",
|
||||
"@radix-ui/react-avatar": "1.1.1",
|
||||
"@radix-ui/react-checkbox": "1.1.2",
|
||||
"@radix-ui/react-context-menu": "2.2.2",
|
||||
"@radix-ui/react-dialog": "1.1.2",
|
||||
"@radix-ui/react-dropdown-menu": "2.1.2",
|
||||
"@radix-ui/react-hover-card": "1.1.2",
|
||||
"@radix-ui/react-label": "2.1.0",
|
||||
"@radix-ui/react-popover": "1.1.1",
|
||||
"@radix-ui/react-radio-group": "1.2.0",
|
||||
"@radix-ui/react-scroll-area": "1.1.0",
|
||||
"@radix-ui/react-select": "2.1.1",
|
||||
"@radix-ui/react-slider": "^1.2.0",
|
||||
"@radix-ui/react-popover": "1.1.2",
|
||||
"@radix-ui/react-radio-group": "1.2.1",
|
||||
"@radix-ui/react-scroll-area": "1.2.0",
|
||||
"@radix-ui/react-select": "2.1.2",
|
||||
"@radix-ui/react-slider": "^1.2.1",
|
||||
"@radix-ui/react-slot": "1.1.0",
|
||||
"@radix-ui/react-switch": "1.1.0",
|
||||
"@radix-ui/react-tabs": "1.1.0",
|
||||
"@radix-ui/react-toast": "1.2.1",
|
||||
"@radix-ui/react-tooltip": "1.1.2",
|
||||
"@sentry/react": "8.32.0",
|
||||
"@shikijs/transformers": "1.20.0",
|
||||
"@radix-ui/react-switch": "1.1.1",
|
||||
"@radix-ui/react-tabs": "1.1.1",
|
||||
"@radix-ui/react-toast": "1.2.2",
|
||||
"@radix-ui/react-tooltip": "1.1.3",
|
||||
"@sentry/react": "8.34.0",
|
||||
"@shikijs/transformers": "1.22.0",
|
||||
"@t3-oss/env-core": "^0.11.1",
|
||||
"@tanstack/query-sync-storage-persister": "5.56.2",
|
||||
"@tanstack/react-query": "5.56.2",
|
||||
"@tanstack/react-query-devtools": "5.58.0",
|
||||
"@tanstack/react-query-persist-client": "5.56.2",
|
||||
"@tanstack/query-sync-storage-persister": "5.59.13",
|
||||
"@tanstack/react-query": "5.59.14",
|
||||
"@tanstack/react-query-devtools": "5.59.14",
|
||||
"@tanstack/react-query-persist-client": "5.59.14",
|
||||
"@use-gesture/react": "10.3.1",
|
||||
"@yornaath/batshit": "0.10.1",
|
||||
"camelcase-keys": "9.1.3",
|
||||
@@ -55,37 +55,38 @@
|
||||
"dexie": "4.0.8",
|
||||
"dnum": "^2.14.0",
|
||||
"electron-log": "5.2.0",
|
||||
"foxact": "0.2.38",
|
||||
"framer-motion": "11.9.0",
|
||||
"foxact": "0.2.39",
|
||||
"framer-motion": "11.11.9",
|
||||
"franc-min": "6.2.0",
|
||||
"fuse.js": "7.0.0",
|
||||
"hast-util-to-jsx-runtime": "2.3.0",
|
||||
"hast-util-to-jsx-runtime": "2.3.2",
|
||||
"hast-util-to-text": "4.0.2",
|
||||
"i18next": "^23.15.1",
|
||||
"i18next": "^23.16.0",
|
||||
"i18next-browser-languagedetector": "8.0.0",
|
||||
"idb-keyval": "6.2.1",
|
||||
"immer": "10.1.1",
|
||||
"jotai": "2.10.0",
|
||||
"jotai": "2.10.1",
|
||||
"katex": "0.16.11",
|
||||
"lethargy": "1.0.9",
|
||||
"lodash-es": "4.17.21",
|
||||
"masonic": "4.0.1",
|
||||
"nanoid": "5.0.7",
|
||||
"ofetch": "1.4.0",
|
||||
"ofetch": "1.4.1",
|
||||
"path-to-regexp": "8.2.0",
|
||||
"posthog-js": "1.165.0",
|
||||
"posthog-js": "1.169.0",
|
||||
"re-resizable": "6.10.0",
|
||||
"react-blurhash": "^0.3.0",
|
||||
"react-error-boundary": "4.0.13",
|
||||
"react-fast-marquee": "1.6.5",
|
||||
"react-hook-form": "7.53.0",
|
||||
"react-hotkeys-hook": "4.5.1",
|
||||
"react-i18next": "^15.0.2",
|
||||
"react-i18next": "^15.0.3",
|
||||
"react-intersection-observer": "9.13.1",
|
||||
"react-resizable-layout": "npm:@innei/react-resizable-layout@0.7.3-fork.1",
|
||||
"react-router-dom": "6.26.2",
|
||||
"react-router-dom": "6.27.0",
|
||||
"react-selecto": "1.26.3",
|
||||
"react-shadow": "20.5.0",
|
||||
"react-virtuoso": "4.10.4",
|
||||
"react-virtuoso": "4.12.0",
|
||||
"rehype-infer-description-meta": "2.0.0",
|
||||
"rehype-parse": "9.0.1",
|
||||
"rehype-sanitize": "6.0.0",
|
||||
@@ -95,30 +96,31 @@
|
||||
"remark-gh-alerts": "0.0.3",
|
||||
"remark-parse": "11.0.0",
|
||||
"remark-rehype": "11.1.1",
|
||||
"shiki": "1.20.0",
|
||||
"shiki": "1.22.0",
|
||||
"sonner": "^1.5.0",
|
||||
"swiper": "11.1.14",
|
||||
"tailwind-merge": "2.5.2",
|
||||
"tailwind-merge": "2.5.4",
|
||||
"tailwindcss-motion": "0.3.0-beta",
|
||||
"tldts": "6.1.48",
|
||||
"tldts": "6.1.51",
|
||||
"unified": "11.0.5",
|
||||
"use-context-selector": "2.0.0",
|
||||
"use-sync-external-store": "1.2.2",
|
||||
"usehooks-ts": "3.1.0",
|
||||
"vfile": "6.0.3",
|
||||
"zod": "3.23.8",
|
||||
"zustand": "4.5.5"
|
||||
"zustand": "5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/generator": "7.25.6",
|
||||
"@hono/node-server": "1.13.1",
|
||||
"@babel/generator": "7.25.7",
|
||||
"@hono/node-server": "1.13.2",
|
||||
"@types/katex": "0.16.7",
|
||||
"@types/lodash-es": "4.17.12",
|
||||
"@types/node": "^22.7.4",
|
||||
"@types/react": "^18.3.10",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@types/node": "^22.7.5",
|
||||
"@types/react": "^18.3.11",
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"fake-indexeddb": "6.0.0",
|
||||
"happy-dom": "15.7.4",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"vitest": "2.0"
|
||||
"react-dom": "^18.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,22 @@ import type { IntegrationSettings } from "@follow/shared/interface/settings"
|
||||
import { createSettingAtom } from "./helper"
|
||||
|
||||
export const createDefaultSettings = (): IntegrationSettings => ({
|
||||
// eagle
|
||||
enableEagle: true,
|
||||
|
||||
// readwise
|
||||
enableReadwise: false,
|
||||
readwiseToken: "",
|
||||
|
||||
// instapaper
|
||||
enableInstapaper: false,
|
||||
instapaperUsername: "",
|
||||
instapaperPassword: "",
|
||||
|
||||
// omnivore
|
||||
enableOmnivore: false,
|
||||
omnivoreEndpoint: "",
|
||||
omnivoreToken: "",
|
||||
})
|
||||
|
||||
export const {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { FC } from "react"
|
||||
import { memo, useMemo } from "react"
|
||||
|
||||
export const MemoedDangerousHTMLStyle: FC<
|
||||
{
|
||||
children: string
|
||||
} & React.DetailedHTMLProps<React.StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement> &
|
||||
Record<string, unknown>
|
||||
> = memo(({ children, ...rest }) => (
|
||||
<style
|
||||
{...rest}
|
||||
dangerouslySetInnerHTML={useMemo(
|
||||
() => ({
|
||||
__html: children,
|
||||
}),
|
||||
[children],
|
||||
)}
|
||||
/>
|
||||
))
|
||||
@@ -1,38 +1,15 @@
|
||||
import { nanoid } from "nanoid"
|
||||
import type { FC, PropsWithChildren, ReactNode } from "react"
|
||||
import {
|
||||
createContext,
|
||||
createElement,
|
||||
memo,
|
||||
useContext,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react"
|
||||
import { createContext, createElement, useContext, useLayoutEffect, useMemo, useState } from "react"
|
||||
import root from "react-shadow"
|
||||
|
||||
import { useUISettingKey } from "~/atoms/settings/ui"
|
||||
import { useReduceMotion } from "~/hooks/biz/useReduceMotion"
|
||||
import { useIsDark } from "~/hooks/common"
|
||||
|
||||
const ShadowDOMContext = createContext(false)
|
||||
import { MemoedDangerousHTMLStyle } from "./MemoedDangerousHTMLStyle"
|
||||
|
||||
const MemoedDangerousHTMLStyle: FC<
|
||||
{
|
||||
children: string
|
||||
} & React.DetailedHTMLProps<React.StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement> &
|
||||
Record<string, unknown>
|
||||
> = memo(({ children, ...rest }) => (
|
||||
<style
|
||||
{...rest}
|
||||
dangerouslySetInnerHTML={useMemo(
|
||||
() => ({
|
||||
__html: children,
|
||||
}),
|
||||
[children],
|
||||
)}
|
||||
/>
|
||||
))
|
||||
const ShadowDOMContext = createContext(false)
|
||||
|
||||
const weakMapElementKey = new WeakMap<HTMLStyleElement | HTMLLinkElement, string>()
|
||||
const cloneStylesElement = (_mutationRecord?: MutationRecord) => {
|
||||
|
||||
@@ -14,10 +14,7 @@ import { Button } from "../ui/button"
|
||||
import { useModalStack } from "../ui/modal"
|
||||
import { CustomSafeError, useResetErrorWhenRouteChange } from "./helper"
|
||||
|
||||
export const FeedFoundCanBeFollowErrorFallback: FC<AppErrorFallbackProps> = ({
|
||||
resetError,
|
||||
error,
|
||||
}) => {
|
||||
const FeedFoundCanBeFollowErrorFallback: FC<AppErrorFallbackProps> = ({ resetError, error }) => {
|
||||
if (!(error instanceof FeedFoundCanBeFollowError)) {
|
||||
throw error
|
||||
}
|
||||
@@ -90,6 +87,7 @@ export const FeedFoundCanBeFollowErrorFallback: FC<AppErrorFallbackProps> = ({
|
||||
)
|
||||
}
|
||||
|
||||
export default FeedFoundCanBeFollowErrorFallback
|
||||
export class FeedFoundCanBeFollowError extends CustomSafeError {
|
||||
constructor(public detail: FeedModel) {
|
||||
super("Feed Found Can Be Follow")
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Logo } from "../icons/logo"
|
||||
import { Button } from "../ui/button"
|
||||
import { CustomSafeError, useResetErrorWhenRouteChange } from "./helper"
|
||||
|
||||
export const FeedNotFoundErrorFallback: FC<AppErrorFallbackProps> = ({ resetError, error }) => {
|
||||
const FeedNotFoundErrorFallback: FC<AppErrorFallbackProps> = ({ resetError, error }) => {
|
||||
if (!(error instanceof FeedNotFound)) {
|
||||
throw error
|
||||
}
|
||||
@@ -40,6 +40,7 @@ export const FeedNotFoundErrorFallback: FC<AppErrorFallbackProps> = ({ resetErro
|
||||
</div>
|
||||
)
|
||||
}
|
||||
export default FeedNotFoundErrorFallback
|
||||
|
||||
export class FeedNotFound extends CustomSafeError {
|
||||
constructor() {
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Button } from "../ui/button"
|
||||
import { useCurrentModal } from "../ui/modal"
|
||||
import { parseError } from "./helper"
|
||||
|
||||
export const ModalErrorFallback: FC<AppErrorFallbackProps> = (props) => {
|
||||
const ModalErrorFallback: FC<AppErrorFallbackProps> = (props) => {
|
||||
const { message, stack } = parseError(props.error)
|
||||
const modal = useCurrentModal()
|
||||
return (
|
||||
@@ -50,3 +50,4 @@ export const ModalErrorFallback: FC<AppErrorFallbackProps> = (props) => {
|
||||
</m.div>
|
||||
)
|
||||
}
|
||||
export default ModalErrorFallback
|
||||
|
||||
@@ -7,7 +7,7 @@ import { FeedbackIssue } from "../common/ErrorElement"
|
||||
import { Button } from "../ui/button"
|
||||
import { parseError, useResetErrorWhenRouteChange } from "./helper"
|
||||
|
||||
export const PageErrorFallback: FC<AppErrorFallbackProps> = (props) => {
|
||||
const PageErrorFallback: FC<AppErrorFallbackProps> = (props) => {
|
||||
const { message, stack } = parseError(props.error)
|
||||
useResetErrorWhenRouteChange(props.resetError)
|
||||
return (
|
||||
@@ -43,3 +43,5 @@ export const PageErrorFallback: FC<AppErrorFallbackProps> = (props) => {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default PageErrorFallback
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { lazy } from "react"
|
||||
|
||||
import { ErrorComponentType } from "./enum"
|
||||
import { FeedFoundCanBeFollowErrorFallback } from "./FeedFoundCanBeFollowErrorFallback"
|
||||
import { FeedNotFoundErrorFallback } from "./FeedNotFound"
|
||||
import { ModalErrorFallback } from "./ModalError"
|
||||
import { PageErrorFallback } from "./PageError"
|
||||
|
||||
const ErrorFallbackMap = {
|
||||
[ErrorComponentType.Modal]: ModalErrorFallback,
|
||||
[ErrorComponentType.Page]: PageErrorFallback,
|
||||
[ErrorComponentType.FeedFoundCanBeFollow]: FeedFoundCanBeFollowErrorFallback,
|
||||
[ErrorComponentType.FeedNotFound]: FeedNotFoundErrorFallback,
|
||||
[ErrorComponentType.Modal]: lazy(() => import("./ModalError")),
|
||||
[ErrorComponentType.Page]: lazy(() => import("./PageError")),
|
||||
[ErrorComponentType.FeedFoundCanBeFollow]: lazy(
|
||||
() => import("./FeedFoundCanBeFollowErrorFallback"),
|
||||
),
|
||||
[ErrorComponentType.FeedNotFound]: lazy(() => import("./FeedNotFound")),
|
||||
}
|
||||
|
||||
export const getErrorFallback = (type: ErrorComponentType) => ErrorFallbackMap[type]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { WEB_URL } from "@follow/shared/constants"
|
||||
import { env } from "@follow/shared/env"
|
||||
|
||||
import { FeedIcon } from "~/components/feed-icon"
|
||||
import { UrlBuilder } from "~/lib/url-builder"
|
||||
import { cn } from "~/lib/utils"
|
||||
import type { FeedOrListRespModel } from "~/models"
|
||||
|
||||
@@ -17,21 +17,16 @@ export function FollowSummary({
|
||||
docs?: string
|
||||
className?: string
|
||||
}) {
|
||||
let siteLink
|
||||
let feedLink
|
||||
let siteLink: string | undefined
|
||||
let feedLink: string | undefined
|
||||
let feedTitle = feed.title
|
||||
let feedText
|
||||
let feedText: string | undefined
|
||||
|
||||
switch (feed.type) {
|
||||
case "feed": {
|
||||
siteLink = feed.siteUrl || void 0
|
||||
feedLink = feed.url || docs
|
||||
feedText = feed.url || docs
|
||||
break
|
||||
}
|
||||
case "list": {
|
||||
siteLink = `${WEB_URL}/list/${feed.id}`
|
||||
siteLink = UrlBuilder.shareList(feed.id)
|
||||
feedLink = siteLink
|
||||
feedText = `/list/${feed.id}`
|
||||
feedText = UrlBuilder.shareList(feed.id)
|
||||
break
|
||||
}
|
||||
case "inbox": {
|
||||
@@ -41,6 +36,12 @@ export function FollowSummary({
|
||||
feedTitle = feed.title || `${feed.id}'s Inbox`
|
||||
break
|
||||
}
|
||||
default: {
|
||||
siteLink = feed.siteUrl || void 0
|
||||
feedLink = feed.url || docs
|
||||
feedText = feed.url || docs
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { Combobox, ComboboxInput, ComboboxOption, ComboboxOptions } from "@headlessui/react"
|
||||
import { AnimatePresence, m } from "framer-motion"
|
||||
import Fuse from "fuse.js"
|
||||
import { forwardRef, Fragment, useCallback, useEffect, useState } from "react"
|
||||
import { forwardRef, useCallback, useEffect, useState } from "react"
|
||||
|
||||
import { cn } from "~/lib/utils"
|
||||
|
||||
import { Input } from "../input"
|
||||
import { useCorrectZIndex } from "../modal"
|
||||
|
||||
export type Suggestion = {
|
||||
name: string
|
||||
@@ -17,8 +18,6 @@ export interface AutocompleteProps extends React.InputHTMLAttributes<HTMLInputEl
|
||||
|
||||
onSuggestionSelected: (suggestion: NoInfer<Suggestion> | null) => void
|
||||
|
||||
portal?: boolean
|
||||
|
||||
// classnames
|
||||
|
||||
searchKeys?: string[]
|
||||
@@ -34,7 +33,6 @@ export const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
|
||||
renderSuggestion = defaultRenderSuggestion,
|
||||
onSuggestionSelected,
|
||||
maxHeight,
|
||||
portal,
|
||||
value,
|
||||
searchKeys = defaultSearchKeys,
|
||||
defaultValue,
|
||||
@@ -65,6 +63,7 @@ export const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
|
||||
doFilter()
|
||||
}, [doFilter])
|
||||
|
||||
const zIndex = useCorrectZIndex(9)
|
||||
return (
|
||||
<Combobox
|
||||
immediate
|
||||
@@ -76,7 +75,7 @@ export const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
|
||||
>
|
||||
{({ open }) => {
|
||||
return (
|
||||
<Fragment>
|
||||
<div className="relative">
|
||||
<ComboboxInput
|
||||
ref={forwardedRef}
|
||||
as={Input}
|
||||
@@ -89,17 +88,18 @@ export const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
|
||||
<AnimatePresence>
|
||||
{open && (
|
||||
<ComboboxOptions
|
||||
portal={portal}
|
||||
portal={false}
|
||||
static
|
||||
as={m.div}
|
||||
initial={{ opacity: 0, scale: 0.98 }}
|
||||
animate={{ opacity: 1, scale: 1 }}
|
||||
exit={{ opacity: 0, scale: 0.98 }}
|
||||
anchor="bottom"
|
||||
style={{ zIndex }}
|
||||
className={cn(
|
||||
"pointer-events-auto z-[99] max-h-48 grow",
|
||||
"pointer-events-auto max-h-48 grow",
|
||||
"shadow-perfect overflow-auto rounded-md border border-border bg-popover text-popover-foreground",
|
||||
"w-[var(--input-width)] empty:invisible",
|
||||
"absolute inset-x-0 top-[110%]",
|
||||
)}
|
||||
>
|
||||
<div style={{ maxHeight }}>
|
||||
@@ -119,7 +119,7 @@ export const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
|
||||
</ComboboxOptions>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</Fragment>
|
||||
</div>
|
||||
)
|
||||
}}
|
||||
</Combobox>
|
||||
|
||||
@@ -3,14 +3,14 @@ import * as React from "react"
|
||||
|
||||
import { cn } from "~/lib/utils"
|
||||
|
||||
import { RootPortal } from "../portal"
|
||||
|
||||
const ContextMenu = ContextMenuPrimitive.Root
|
||||
|
||||
const ContextMenuTrigger = ContextMenuPrimitive.Trigger
|
||||
|
||||
const ContextMenuGroup = ContextMenuPrimitive.Group
|
||||
|
||||
const ContextMenuPortal = ContextMenuPrimitive.Portal
|
||||
|
||||
const ContextMenuSub = ContextMenuPrimitive.Sub
|
||||
|
||||
const ContextMenuRadioGroup = ContextMenuPrimitive.RadioGroup
|
||||
@@ -42,7 +42,7 @@ const ContextMenuSubContent = React.forwardRef<
|
||||
React.ElementRef<typeof ContextMenuPrimitive.SubContent>,
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubContent>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ContextMenuPrimitive.Portal>
|
||||
<RootPortal>
|
||||
<ContextMenuPrimitive.SubContent
|
||||
ref={ref}
|
||||
className={cn(
|
||||
@@ -51,7 +51,7 @@ const ContextMenuSubContent = React.forwardRef<
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</ContextMenuPrimitive.Portal>
|
||||
</RootPortal>
|
||||
))
|
||||
ContextMenuSubContent.displayName = ContextMenuPrimitive.SubContent.displayName
|
||||
|
||||
@@ -59,17 +59,17 @@ const ContextMenuContent = React.forwardRef<
|
||||
React.ElementRef<typeof ContextMenuPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Content>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ContextMenuPrimitive.Portal>
|
||||
<RootPortal>
|
||||
<ContextMenuPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"z-[999] min-w-32 overflow-hidden rounded-md border border-border bg-theme-modal-background-opaque p-1 text-theme-foreground/90 shadow-lg dark:shadow-zinc-800/60",
|
||||
"z-[60] min-w-32 overflow-hidden rounded-md border border-border bg-theme-modal-background-opaque p-1 text-theme-foreground/90 shadow-lg dark:shadow-zinc-800/60",
|
||||
"text-xs",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</ContextMenuPrimitive.Portal>
|
||||
</RootPortal>
|
||||
))
|
||||
ContextMenuContent.displayName = ContextMenuPrimitive.Content.displayName
|
||||
|
||||
@@ -149,7 +149,6 @@ export {
|
||||
ContextMenuGroup,
|
||||
ContextMenuItem,
|
||||
ContextMenuLabel,
|
||||
ContextMenuPortal,
|
||||
ContextMenuRadioGroup,
|
||||
ContextMenuSeparator,
|
||||
ContextMenuSub,
|
||||
@@ -157,3 +156,5 @@ export {
|
||||
ContextMenuSubTrigger,
|
||||
ContextMenuTrigger,
|
||||
}
|
||||
|
||||
export { RootPortal as ContextMenuPortal } from "../portal"
|
||||
|
||||
@@ -4,6 +4,8 @@ import * as React from "react"
|
||||
import { useHotkeyScope, useTypeScriptHappyCallback } from "~/hooks/common"
|
||||
import { cn } from "~/lib/utils"
|
||||
|
||||
import { RootPortal } from "../portal"
|
||||
|
||||
const DropdownMenu: typeof DropdownMenuPrimitive.Root = (props) => {
|
||||
const [open, setOpen] = React.useState(!!props.open)
|
||||
useHotkeyScope("DropdownMenu", open)
|
||||
@@ -73,7 +75,7 @@ const DropdownMenuContent = React.forwardRef<
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
|
||||
>(({ className, sideOffset = 4, ...props }, ref) => {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<RootPortal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
ref={ref}
|
||||
sideOffset={sideOffset}
|
||||
@@ -84,7 +86,7 @@ const DropdownMenuContent = React.forwardRef<
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
</RootPortal>
|
||||
)
|
||||
})
|
||||
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import katex from "katex"
|
||||
import type { FC } from "react"
|
||||
import { useMemo } from "react"
|
||||
|
||||
type KateXProps = {
|
||||
children: string
|
||||
mode?: "display" | "inline"
|
||||
}
|
||||
|
||||
export const KateX: FC<KateXProps> = (props) => {
|
||||
const { children, mode } = props
|
||||
|
||||
const displayMode = mode === "display"
|
||||
|
||||
const throwOnError = false // render unsupported commands as text instead of throwing a `ParseError`
|
||||
|
||||
return (
|
||||
<span
|
||||
dangerouslySetInnerHTML={useMemo(
|
||||
() => ({
|
||||
__html: katex.renderToString(children, {
|
||||
displayMode,
|
||||
throwOnError,
|
||||
}),
|
||||
}),
|
||||
[children, displayMode, throwOnError],
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { lazy, Suspense } from "react"
|
||||
|
||||
import type { KateX } from "./index"
|
||||
|
||||
const LazyKateX_ = lazy(() => import("./index").then((mod) => ({ default: mod.KateX })))
|
||||
export const LazyKateX: typeof KateX = (props) => {
|
||||
return (
|
||||
<Suspense>
|
||||
<LazyKateX_ {...props} />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
@@ -128,10 +128,9 @@ export const RotatingRefreshIcon: React.FC<{
|
||||
transition: { duration: 1, repeat: Infinity, ease: "linear" },
|
||||
})
|
||||
} else {
|
||||
controls.stop()
|
||||
controls.start({
|
||||
rotate: 360,
|
||||
transition: { ease: "linear", type: "spring" },
|
||||
transition: { type: "spring" },
|
||||
})
|
||||
}
|
||||
}, [isRefreshing, controls])
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import katexStyle from "katex/dist/katex.min.css?raw"
|
||||
import { createElement, Fragment, memo, useEffect, useMemo, useRef, useState } from "react"
|
||||
|
||||
import { MemoedDangerousHTMLStyle } from "~/components/common/MemoedDangerousHTMLStyle"
|
||||
import { parseHtml } from "~/lib/parse-html"
|
||||
import type { RemarkOptions } from "~/lib/parse-markdown"
|
||||
import { parseMarkdown } from "~/lib/parse-markdown"
|
||||
@@ -108,6 +110,7 @@ const HTMLImpl = <A extends keyof JSX.IntrinsicElements = "div">(
|
||||
<MarkdownRenderContainerRefContext.Provider value={refElement}>
|
||||
<MediaContainerWidthProvider width={containerWidth}>
|
||||
<MediaInfoRecordProvider mediaInfo={mediaInfo}>
|
||||
<MemoedDangerousHTMLStyle>{katexStyle}</MemoedDangerousHTMLStyle>
|
||||
{createElement(as, { ...rest, ref: setRefElement }, markdownElement)}
|
||||
</MediaInfoRecordProvider>
|
||||
</MediaContainerWidthProvider>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { FeedViewType } from "~/lib/enum"
|
||||
import { useEntryContentContextSelector } from "~/modules/entry-content/hooks"
|
||||
|
||||
import { ensureAndRenderTimeStamp } from "../utils"
|
||||
import { IsInParagraphContext } from "./ctx"
|
||||
|
||||
export const MarkdownP: Component<
|
||||
React.DetailedHTMLProps<React.HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>
|
||||
@@ -29,5 +30,9 @@ export const MarkdownP: Component<
|
||||
)
|
||||
}
|
||||
|
||||
return <p {...props}>{children}</p>
|
||||
return (
|
||||
<p {...props}>
|
||||
<IsInParagraphContext.Provider value={true}>{children}</IsInParagraphContext.Provider>
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { createContext, useContext } from "react"
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const IsInParagraphContext = createContext<boolean>(false)
|
||||
|
||||
export const useIsInParagraphContext = () => {
|
||||
return useContext(IsInParagraphContext)
|
||||
}
|
||||
@@ -18,4 +18,5 @@ export const modalMontionConfig = {
|
||||
transition: microReboundPreset,
|
||||
}
|
||||
|
||||
export const MODAL_STACK_Z_INDEX = 40
|
||||
// Radix context menu z-index 999
|
||||
export const MODAL_STACK_Z_INDEX = 1001
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { FC, RefObject } from "react"
|
||||
import { createContext } from "react"
|
||||
import { createContext as reactCreateContext } from "react"
|
||||
import { createContext as createContextSelector } from "use-context-selector"
|
||||
|
||||
export type CurrentModalContentProps = ModalActionsInternal & {
|
||||
ref: RefObject<HTMLElement | null>
|
||||
@@ -16,12 +17,19 @@ const defaultCtxValue: CurrentModalContentProps = {
|
||||
dismiss: warnNoProvider,
|
||||
setClickOutSideToDismiss: warnNoProvider,
|
||||
ref: { current: null },
|
||||
getIndex: () => 0,
|
||||
}
|
||||
|
||||
export const CurrentModalContext = createContext<CurrentModalContentProps>(defaultCtxValue)
|
||||
export const CurrentModalContext = reactCreateContext<CurrentModalContentProps>(defaultCtxValue)
|
||||
export const CurrentModalStateContext = createContextSelector<{
|
||||
isTop: boolean
|
||||
}>({
|
||||
isTop: true,
|
||||
})
|
||||
|
||||
export type ModalContentComponent<T = object> = FC<ModalActionsInternal & T>
|
||||
export type ModalActionsInternal = {
|
||||
dismiss: () => void
|
||||
setClickOutSideToDismiss: (value: boolean) => void
|
||||
getIndex: () => number
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ export const DrawerModalLayout: FC<PropsWithChildren> = ({ children }) => {
|
||||
className={cn(
|
||||
"flex flex-col items-center overflow-hidden rounded-xl border bg-theme-background p-8 pb-0",
|
||||
"shadow-drawer-to-left w-[60ch] max-w-full",
|
||||
"fixed inset-y-2 right-2",
|
||||
"fixed bottom-0 right-2 safe-inset-top-4",
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import type { DragControls } from "framer-motion"
|
||||
import { useAtomValue } from "jotai"
|
||||
import { selectAtom } from "jotai/utils"
|
||||
import type { ResizeCallback, ResizeStartCallback } from "re-resizable"
|
||||
import { useCallback, useContext, useId, useRef, useState } from "react"
|
||||
import { useCallback, useContext, useId, useMemo, useRef, useState } from "react"
|
||||
import { flushSync } from "react-dom"
|
||||
import { useContextSelector } from "use-context-selector"
|
||||
import { useEventCallback } from "usehooks-ts"
|
||||
|
||||
import { getUISettings } from "~/atoms/settings/ui"
|
||||
import { jotaiStore } from "~/lib/jotai"
|
||||
|
||||
import { modalStackAtom } from "./atom"
|
||||
import { CurrentModalContext } from "./context"
|
||||
import { MODAL_STACK_Z_INDEX } from "./constants"
|
||||
import { CurrentModalContext, CurrentModalStateContext } from "./context"
|
||||
import type { ModalProps, ModalStackOptions } from "./types"
|
||||
|
||||
export const modalIdToPropsMap = {} as Record<string, ModalProps>
|
||||
@@ -147,3 +151,19 @@ export const useResizeableModal = (
|
||||
preferDragDir,
|
||||
}
|
||||
}
|
||||
|
||||
export const useIsTopModal = () => useContextSelector(CurrentModalStateContext, (v) => v.isTop)
|
||||
|
||||
export const useCorrectZIndex = (fallbackZIndex = 0) => {
|
||||
const inModal = useCurrentModal()
|
||||
|
||||
return useAtomValue(
|
||||
useMemo(
|
||||
() =>
|
||||
selectAtom(modalStackAtom, (v) =>
|
||||
inModal ? v.length + MODAL_STACK_Z_INDEX + inModal.getIndex() + 1 : fallbackZIndex,
|
||||
),
|
||||
[fallbackZIndex, inModal],
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { useAnimationControls } from "framer-motion"
|
||||
import { useCallback, useEffect } from "react"
|
||||
|
||||
import { nextFrame } from "~/lib/dom"
|
||||
|
||||
import { modalMontionConfig } from "../constants"
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const useModalAnimate = (isTop: boolean) => {
|
||||
const animateController = useAnimationControls()
|
||||
useEffect(() => {
|
||||
nextFrame(() => {
|
||||
animateController.start(modalMontionConfig.animate)
|
||||
})
|
||||
}, [animateController])
|
||||
const noticeModal = useCallback(() => {
|
||||
animateController
|
||||
.start({
|
||||
scale: 1.05,
|
||||
transition: {
|
||||
duration: 0.06,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
animateController.start({
|
||||
scale: 1,
|
||||
})
|
||||
})
|
||||
}, [animateController])
|
||||
|
||||
useEffect(() => {
|
||||
if (isTop) return
|
||||
animateController.start({
|
||||
scale: 0.96,
|
||||
y: 10,
|
||||
})
|
||||
return () => {
|
||||
try {
|
||||
animateController.stop()
|
||||
animateController.start({
|
||||
scale: 1,
|
||||
y: 0,
|
||||
})
|
||||
} catch {
|
||||
/* empty */
|
||||
}
|
||||
}
|
||||
}, [isTop])
|
||||
|
||||
return {
|
||||
noticeModal,
|
||||
animateController,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { useDragControls } from "framer-motion"
|
||||
import type { PointerEventHandler, RefObject } from "react"
|
||||
import { useCallback } from "react"
|
||||
|
||||
import { useResizeableModal } from "../hooks"
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const useModalResizeAndDrag = (
|
||||
modalElementRef: RefObject<HTMLDivElement>,
|
||||
{
|
||||
resizeable,
|
||||
draggable,
|
||||
}: {
|
||||
resizeable: boolean
|
||||
draggable: boolean
|
||||
},
|
||||
) => {
|
||||
const dragController = useDragControls()
|
||||
const {
|
||||
handleResizeStop,
|
||||
handleResizeStart,
|
||||
relocateModal,
|
||||
preferDragDir,
|
||||
isResizeable,
|
||||
resizeableStyle,
|
||||
} = useResizeableModal(modalElementRef, {
|
||||
enableResizeable: resizeable,
|
||||
dragControls: dragController,
|
||||
})
|
||||
|
||||
const handleDrag: PointerEventHandler<HTMLDivElement> = useCallback(
|
||||
(e) => {
|
||||
if (draggable) {
|
||||
dragController.start(e)
|
||||
}
|
||||
},
|
||||
[dragController, draggable],
|
||||
)
|
||||
|
||||
return {
|
||||
handleDrag,
|
||||
handleResizeStart,
|
||||
handleResizeStop,
|
||||
relocateModal,
|
||||
preferDragDir,
|
||||
isResizeable,
|
||||
resizeableStyle,
|
||||
|
||||
dragController,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useCallback, useRef } from "react"
|
||||
|
||||
import { nextFrame } from "~/lib/dom"
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Handle select text in modal
|
||||
*/
|
||||
export const useModalSelect = () => {
|
||||
const isSelectingRef = useRef(false)
|
||||
const handleSelectStart = useCallback(() => {
|
||||
isSelectingRef.current = true
|
||||
}, [])
|
||||
const handleDetectSelectEnd = useCallback(() => {
|
||||
nextFrame(() => {
|
||||
if (isSelectingRef.current) {
|
||||
isSelectingRef.current = false
|
||||
}
|
||||
})
|
||||
}, [])
|
||||
|
||||
return {
|
||||
isSelectingRef,
|
||||
handleSelectStart,
|
||||
handleDetectSelectEnd,
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import * as Dialog from "@radix-ui/react-dialog"
|
||||
import type { BoundingBox } from "framer-motion"
|
||||
import { useAnimationControls, useDragControls } from "framer-motion"
|
||||
import { produce } from "immer"
|
||||
import { useSetAtom } from "jotai"
|
||||
import { Resizable } from "re-resizable"
|
||||
import type { PointerEventHandler, PropsWithChildren, SyntheticEvent } from "react"
|
||||
import type { FC, PropsWithChildren, SyntheticEvent } from "react"
|
||||
import {
|
||||
createElement,
|
||||
forwardRef,
|
||||
@@ -24,9 +23,8 @@ import { AppErrorBoundary } from "~/components/common/AppErrorBoundary"
|
||||
import { SafeFragment } from "~/components/common/Fragment"
|
||||
import { m } from "~/components/common/Motion"
|
||||
import { ErrorComponentType } from "~/components/errors/enum"
|
||||
import { resizableOnly } from "~/components/ui/modal"
|
||||
import { ElECTRON_CUSTOM_TITLEBAR_HEIGHT, isElectronBuild } from "~/constants"
|
||||
import { useSwitchHotKeyScope } from "~/hooks/common"
|
||||
import { useRefValue, useSwitchHotKeyScope } from "~/hooks/common"
|
||||
import { nextFrame, stopPropagation } from "~/lib/dom"
|
||||
import { cn, getOS } from "~/lib/utils"
|
||||
|
||||
@@ -34,10 +32,12 @@ import { Divider } from "../../divider"
|
||||
import { RootPortalProvider } from "../../portal/provider"
|
||||
import { EllipsisHorizontalTextWithTooltip } from "../../typography"
|
||||
import { modalStackAtom } from "./atom"
|
||||
import { modalMontionConfig } from "./constants"
|
||||
import { MODAL_STACK_Z_INDEX, modalMontionConfig } from "./constants"
|
||||
import type { CurrentModalContentProps, ModalActionsInternal } from "./context"
|
||||
import { CurrentModalContext } from "./context"
|
||||
import { useResizeableModal } from "./hooks"
|
||||
import { CurrentModalContext, CurrentModalStateContext } from "./context"
|
||||
import { useModalAnimate } from "./internal/use-animate"
|
||||
import { useModalResizeAndDrag } from "./internal/use-drag"
|
||||
import { useModalSelect } from "./internal/use-select"
|
||||
import { ModalOverlay } from "./overlay"
|
||||
import type { ModalOverlayOptions, ModalProps } from "./types"
|
||||
|
||||
@@ -51,11 +51,15 @@ export const ModalInternal = memo(
|
||||
item: ModalProps & { id: string }
|
||||
index: number
|
||||
|
||||
isTop: boolean
|
||||
isTop?: boolean
|
||||
isBottom?: boolean
|
||||
overlayOptions?: ModalOverlayOptions
|
||||
onClose?: (open: boolean) => void
|
||||
} & PropsWithChildren
|
||||
>(function Modal({ item, overlayOptions, onClose: onPropsClose, children, isTop }, ref) {
|
||||
>(function Modal(
|
||||
{ item, overlayOptions, onClose: onPropsClose, children, isTop, index, isBottom },
|
||||
ref,
|
||||
) {
|
||||
const {
|
||||
CustomModalComponent,
|
||||
modalClassName,
|
||||
@@ -110,72 +114,29 @@ export const ModalInternal = memo(
|
||||
)
|
||||
|
||||
const modalElementRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
const dragController = useDragControls()
|
||||
const {
|
||||
handleResizeStop,
|
||||
handleDrag,
|
||||
handleResizeStart,
|
||||
handleResizeStop,
|
||||
relocateModal,
|
||||
preferDragDir,
|
||||
isResizeable,
|
||||
resizeableStyle,
|
||||
} = useResizeableModal(modalElementRef, {
|
||||
enableResizeable: resizeable,
|
||||
dragControls: dragController,
|
||||
|
||||
dragController,
|
||||
} = useModalResizeAndDrag(modalElementRef, {
|
||||
resizeable,
|
||||
draggable,
|
||||
})
|
||||
const animateController = useAnimationControls()
|
||||
useEffect(() => {
|
||||
nextFrame(() => {
|
||||
animateController.start(modalMontionConfig.animate)
|
||||
})
|
||||
}, [animateController])
|
||||
const noticeModal = useCallback(() => {
|
||||
animateController
|
||||
.start({
|
||||
scale: 1.05,
|
||||
transition: {
|
||||
duration: 0.06,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
animateController.start({
|
||||
scale: 1,
|
||||
})
|
||||
})
|
||||
}, [animateController])
|
||||
|
||||
const handleDrag: PointerEventHandler<HTMLDivElement> = useCallback(
|
||||
(e) => {
|
||||
if (draggable) {
|
||||
dragController.start(e)
|
||||
}
|
||||
},
|
||||
[dragController, draggable],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (isTop) return
|
||||
animateController.start({
|
||||
scale: 0.96,
|
||||
y: 10,
|
||||
})
|
||||
return () => {
|
||||
try {
|
||||
animateController.stop()
|
||||
animateController.start({
|
||||
scale: 1,
|
||||
y: 0,
|
||||
})
|
||||
} catch {
|
||||
/* empty */
|
||||
}
|
||||
}
|
||||
}, [isTop])
|
||||
const { noticeModal, animateController } = useModalAnimate(!!isTop)
|
||||
|
||||
const getIndex = useEventCallback(() => index)
|
||||
const modalContentRef = useRef<HTMLDivElement>(null)
|
||||
const ModalProps: ModalActionsInternal = useMemo(
|
||||
() => ({
|
||||
dismiss: close,
|
||||
getIndex,
|
||||
setClickOutSideToDismiss: (v) => {
|
||||
setStack((state) =>
|
||||
produce(state, (draft) => {
|
||||
@@ -187,7 +148,7 @@ export const ModalInternal = memo(
|
||||
)
|
||||
},
|
||||
}),
|
||||
[close, item.id, setStack],
|
||||
[close, getIndex, item.id, setStack],
|
||||
)
|
||||
|
||||
const ModalContextProps = useMemo<CurrentModalContentProps>(
|
||||
@@ -198,17 +159,17 @@ export const ModalInternal = memo(
|
||||
[ModalProps],
|
||||
)
|
||||
|
||||
const edgeElementRef = useRef<HTMLDivElement>(null)
|
||||
const [edgeElementRef, setEdgeElementRef] = useState<HTMLDivElement | null>(null)
|
||||
|
||||
const finalChildren = useMemo(
|
||||
() => (
|
||||
<AppErrorBoundary errorType={ErrorComponentType.Modal}>
|
||||
<RootPortalProvider value={edgeElementRef.current as HTMLElement}>
|
||||
<RootPortalProvider value={edgeElementRef as HTMLElement}>
|
||||
{children ?? createElement(content, ModalProps)}
|
||||
</RootPortalProvider>
|
||||
</AppErrorBoundary>
|
||||
),
|
||||
[ModalProps, children, content],
|
||||
[ModalProps, children, content, edgeElementRef],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -218,34 +179,17 @@ export const ModalInternal = memo(
|
||||
}
|
||||
}, [currentIsClosing])
|
||||
|
||||
const switchHotkeyScope = useSwitchHotKeyScope()
|
||||
useEffect(() => {
|
||||
switchHotkeyScope("Modal")
|
||||
return () => {
|
||||
switchHotkeyScope("Home")
|
||||
}
|
||||
}, [switchHotkeyScope])
|
||||
useShortcutScope()
|
||||
|
||||
const modalStyle = resizeableStyle
|
||||
const isSelectingRef = useRef(false)
|
||||
const handleSelectStart = useCallback(() => {
|
||||
isSelectingRef.current = true
|
||||
}, [])
|
||||
const handleDetectSelectEnd = useCallback(() => {
|
||||
nextFrame(() => {
|
||||
if (isSelectingRef.current) {
|
||||
isSelectingRef.current = false
|
||||
}
|
||||
})
|
||||
}, [])
|
||||
|
||||
const { handleSelectStart, handleDetectSelectEnd, isSelectingRef } = useModalSelect()
|
||||
const handleClickOutsideToDismiss = useCallback(
|
||||
(e: SyntheticEvent) => {
|
||||
if (isSelectingRef.current) return
|
||||
const fn = modal ? (clickOutsideToDismiss && canClose ? dismiss : noticeModal) : undefined
|
||||
fn?.(e)
|
||||
},
|
||||
[canClose, clickOutsideToDismiss, dismiss, modal, noticeModal],
|
||||
[canClose, clickOutsideToDismiss, dismiss, modal, noticeModal, isSelectingRef],
|
||||
)
|
||||
|
||||
const openAutoFocus = useCallback(
|
||||
@@ -268,15 +212,20 @@ export const ModalInternal = memo(
|
||||
}, [])
|
||||
|
||||
useImperativeHandle(ref, () => modalElementRef.current!)
|
||||
const currentModalZIndex = MODAL_STACK_Z_INDEX + index * 2
|
||||
|
||||
const Overlay = (
|
||||
<ModalOverlay
|
||||
zIndex={currentModalZIndex - 1}
|
||||
blur={overlayOptions?.blur}
|
||||
className={cn(overlayOptions?.className, {
|
||||
hidden: item.overlay ? false : !modalSettingOverlay,
|
||||
})}
|
||||
hidden={
|
||||
item.overlay ? currentIsClosing : !(modalSettingOverlay && isBottom) || currentIsClosing
|
||||
}
|
||||
/>
|
||||
)
|
||||
|
||||
const mutateableEdgeElementRef = useRefValue(edgeElementRef)
|
||||
|
||||
if (CustomModalComponent) {
|
||||
return (
|
||||
<Wrapper>
|
||||
@@ -286,13 +235,16 @@ export const ModalInternal = memo(
|
||||
<Dialog.DialogTitle className="sr-only">{title}</Dialog.DialogTitle>
|
||||
<Dialog.Content asChild aria-describedby={undefined} onOpenAutoFocus={openAutoFocus}>
|
||||
<div
|
||||
ref={edgeElementRef}
|
||||
ref={setEdgeElementRef}
|
||||
className={cn(
|
||||
"no-drag-region fixed",
|
||||
modal ? "inset-0 overflow-auto" : "left-0 top-0",
|
||||
currentIsClosing ? "!pointer-events-none" : "!pointer-events-auto",
|
||||
modalContainerClassName,
|
||||
)}
|
||||
style={{
|
||||
zIndex: currentModalZIndex,
|
||||
}}
|
||||
onPointerUp={handleDetectSelectEnd}
|
||||
onClick={handleClickOutsideToDismiss}
|
||||
onFocus={stopPropagation}
|
||||
@@ -305,9 +257,9 @@ export const ModalInternal = memo(
|
||||
onSelect={handleSelectStart}
|
||||
onKeyUp={handleDetectSelectEnd}
|
||||
>
|
||||
<CurrentModalContext.Provider value={ModalContextProps}>
|
||||
<ModalContext modalContextProps={ModalContextProps} isTop={!!isTop}>
|
||||
<CustomModalComponent>{finalChildren}</CustomModalComponent>
|
||||
</CurrentModalContext.Provider>
|
||||
</ModalContext>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
@@ -326,7 +278,7 @@ export const ModalInternal = memo(
|
||||
{Overlay}
|
||||
<Dialog.Content asChild aria-describedby={undefined} onOpenAutoFocus={openAutoFocus}>
|
||||
<div
|
||||
ref={edgeElementRef}
|
||||
ref={setEdgeElementRef}
|
||||
className={cn(
|
||||
"fixed flex",
|
||||
modal ? "inset-0 overflow-auto" : "left-0 top-0",
|
||||
@@ -337,6 +289,9 @@ export const ModalInternal = memo(
|
||||
onFocus={stopPropagation}
|
||||
onPointerUp={handleDetectSelectEnd}
|
||||
onClick={handleClickOutsideToDismiss}
|
||||
style={{
|
||||
zIndex: currentModalZIndex,
|
||||
}}
|
||||
>
|
||||
{DragBar}
|
||||
|
||||
@@ -364,14 +319,14 @@ export const ModalInternal = memo(
|
||||
dragElastic={0}
|
||||
dragListener={false}
|
||||
dragMomentum={false}
|
||||
dragConstraints={edgeElementRef}
|
||||
dragConstraints={mutateableEdgeElementRef}
|
||||
onMeasureDragConstraints={measureDragConstraints}
|
||||
whileDrag={{
|
||||
cursor: "grabbing",
|
||||
}}
|
||||
>
|
||||
<ResizeSwitch
|
||||
enable={resizableOnly("bottomRight")}
|
||||
// enable={resizableOnly("bottomRight")}
|
||||
onResizeStart={handleResizeStart}
|
||||
onResizeStop={handleResizeStop}
|
||||
defaultSize={resizeDefaultSize}
|
||||
@@ -389,7 +344,11 @@ export const ModalInternal = memo(
|
||||
</EllipsisHorizontalTextWithTooltip>
|
||||
</Dialog.Title>
|
||||
{canClose && (
|
||||
<Dialog.DialogClose className="center p-2" tabIndex={1} onClick={close}>
|
||||
<Dialog.DialogClose
|
||||
className="center z-[1] p-2"
|
||||
tabIndex={1}
|
||||
onClick={close}
|
||||
>
|
||||
<i className="i-mgc-close-cute-re" />
|
||||
</Dialog.DialogClose>
|
||||
)}
|
||||
@@ -397,9 +356,9 @@ export const ModalInternal = memo(
|
||||
<Divider className="my-2 shrink-0 border-slate-200 opacity-80 dark:border-neutral-800" />
|
||||
|
||||
<div className="min-h-0 shrink grow overflow-auto px-4 py-2">
|
||||
<CurrentModalContext.Provider value={ModalContextProps}>
|
||||
<ModalContext modalContextProps={ModalContextProps} isTop={!!isTop}>
|
||||
{finalChildren}
|
||||
</CurrentModalContext.Provider>
|
||||
</ModalContext>
|
||||
</div>
|
||||
</ResizeSwitch>
|
||||
</m.div>
|
||||
@@ -411,3 +370,35 @@ export const ModalInternal = memo(
|
||||
)
|
||||
}),
|
||||
)
|
||||
|
||||
const useShortcutScope = () => {
|
||||
const switchHotkeyScope = useSwitchHotKeyScope()
|
||||
useEffect(() => {
|
||||
switchHotkeyScope("Modal")
|
||||
return () => {
|
||||
switchHotkeyScope("Home")
|
||||
}
|
||||
}, [switchHotkeyScope])
|
||||
}
|
||||
|
||||
const ModalContext: FC<
|
||||
PropsWithChildren & {
|
||||
modalContextProps: CurrentModalContentProps
|
||||
isTop: boolean
|
||||
}
|
||||
> = ({ modalContextProps, isTop, children }) => {
|
||||
return (
|
||||
<CurrentModalContext.Provider value={modalContextProps}>
|
||||
<CurrentModalStateContext.Provider
|
||||
value={useMemo(
|
||||
() => ({
|
||||
isTop: !!isTop,
|
||||
}),
|
||||
[isTop],
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</CurrentModalStateContext.Provider>
|
||||
</CurrentModalContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,41 +1,45 @@
|
||||
import * as Dialog from "@radix-ui/react-dialog"
|
||||
import { AnimatePresence } from "framer-motion"
|
||||
import type { ForwardedRef } from "react"
|
||||
import { forwardRef } from "react"
|
||||
|
||||
import { m } from "~/components/common/Motion"
|
||||
import { cn } from "~/lib/utils"
|
||||
|
||||
import { softSpringPreset } from "../../constants/spring"
|
||||
|
||||
export const ModalOverlay = forwardRef(
|
||||
(
|
||||
{
|
||||
zIndex,
|
||||
blur,
|
||||
className,
|
||||
hidden,
|
||||
}: {
|
||||
zIndex?: number
|
||||
blur?: boolean
|
||||
className?: string
|
||||
hidden?: boolean
|
||||
},
|
||||
ref: ForwardedRef<HTMLDivElement>,
|
||||
) => (
|
||||
<Dialog.Overlay asChild>
|
||||
<m.div
|
||||
ref={ref}
|
||||
id="modal-overlay"
|
||||
className={cn(
|
||||
// NOTE: pointer-events-none is required, if remove this, when modal is closing, you can not click element behind the modal
|
||||
"!pointer-events-none fixed inset-0 rounded-[var(--fo-window-radius)] bg-zinc-50/80 dark:bg-neutral-900/80",
|
||||
blur && "backdrop-blur-sm",
|
||||
className,
|
||||
<AnimatePresence>
|
||||
{!hidden && (
|
||||
<m.div
|
||||
ref={ref}
|
||||
id="modal-overlay"
|
||||
className={cn(
|
||||
// NOTE: pointer-events-none is required, if remove this, when modal is closing, you can not click element behind the modal
|
||||
"!pointer-events-none fixed inset-0 rounded-[var(--fo-window-radius)] bg-zinc-50/80 dark:bg-neutral-900/80",
|
||||
blur && "backdrop-blur-sm",
|
||||
className,
|
||||
)}
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
style={{ zIndex }}
|
||||
/>
|
||||
)}
|
||||
transition={softSpringPreset}
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
style={{ zIndex }}
|
||||
/>
|
||||
</AnimatePresence>
|
||||
</Dialog.Overlay>
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { AnimatePresence } from "framer-motion"
|
||||
import { useAtomValue } from "jotai"
|
||||
import type { FC, PropsWithChildren } from "react"
|
||||
import { useEffect } from "react"
|
||||
|
||||
import { modalStackAtom } from "./atom"
|
||||
import { ModalInternal } from "./modal"
|
||||
@@ -18,14 +19,25 @@ const ModalStack = () => {
|
||||
const topModalIndex = stack.findLastIndex((item) => item.modal)
|
||||
const overlayIndex = stack.findLastIndex((item) => item.overlay || item.modal)
|
||||
const overlayOptions = stack[overlayIndex]?.overlayOptions
|
||||
|
||||
const hasModalStack = stack.length > 0
|
||||
|
||||
useEffect(() => {
|
||||
// NOTE: document.body is being used by radix's dismissable,
|
||||
// and using that will cause radix to get the value of `none` as the store value,
|
||||
// and then revert to `none` instead of `auto` after a modal dismiss.
|
||||
document.documentElement.style.pointerEvents = hasModalStack ? "none" : "auto"
|
||||
document.documentElement.dataset.hasModal = hasModalStack.toString()
|
||||
}, [hasModalStack])
|
||||
return (
|
||||
<AnimatePresence mode="popLayout">
|
||||
{stack.map((item, index) => (
|
||||
<ModalInternal
|
||||
key={item.id}
|
||||
item={item}
|
||||
index={index * 2}
|
||||
isTop={index === topModalIndex * 2}
|
||||
index={index}
|
||||
isTop={index === topModalIndex}
|
||||
isBottom={index === 0}
|
||||
overlayOptions={overlayOptions}
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { SVGProps } from "react"
|
||||
|
||||
export function SimpleIconsOmnivore(props: SVGProps<SVGSVGElement>) {
|
||||
return (
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 16 16" {...props}>
|
||||
<path
|
||||
fill="#3D3D3D"
|
||||
d="M15.9 7.801c0 .507-.123 1.12-.248 1.656v.004l-.001.003a2.87 2.87 0 0 1-2.793 2.186h-.036c-1.625 0-2.649-1.334-2.649-2.828v-2.14l-1.21 1.794-.067.055a1.404 1.404 0 0 1-1.793 0l-.065-.053-1.248-1.82v4.414H4.6V6.268c0-.91 1.078-1.439 1.794-.802l.055.048 1.46 2.13a.21.21 0 0 0 .179 0l1.43-2.119.065-.054c.68-.567 1.78-.138 1.78.815v2.536c0 .971.619 1.638 1.46 1.638h.035c.78 0 1.45-.527 1.636-1.277.125-.534.216-1.026.216-1.378-.017-3.835-3.262-6.762-7.188-6.498-3.311.23-5.986 2.905-6.216 6.216A6.705 6.705 0 0 0 8 14.693v1.19a7.895 7.895 0 0 1-7.882-8.44C.39 3.536 3.536.39 7.44.118 12.017-.19 15.88 3.242 15.9 7.8z"
|
||||
/>
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
export * from "./collections/eagle"
|
||||
export * from "./collections/instapaper"
|
||||
export * from "./collections/omnivore"
|
||||
export * from "./collections/readwise"
|
||||
export * from "./collections/rss3"
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as React from "react"
|
||||
|
||||
import { cn } from "~/lib/utils"
|
||||
|
||||
import { RootPortal } from "../portal"
|
||||
import styles from "./index.module.css"
|
||||
|
||||
const Popover = PopoverPrimitive.Root
|
||||
@@ -15,7 +16,7 @@ const PopoverContent = React.forwardRef<
|
||||
React.ElementRef<typeof PopoverPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
|
||||
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
|
||||
<PopoverPrimitive.Portal>
|
||||
<RootPortal>
|
||||
<PopoverPrimitive.Content
|
||||
ref={ref}
|
||||
align={align}
|
||||
@@ -28,7 +29,7 @@ const PopoverContent = React.forwardRef<
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</PopoverPrimitive.Portal>
|
||||
</RootPortal>
|
||||
))
|
||||
PopoverContent.displayName = PopoverPrimitive.Content.displayName
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ export const RootPortal: FC<
|
||||
} & PropsWithChildren
|
||||
> = (props) => {
|
||||
const to = useRootPortal()
|
||||
|
||||
if (props.to === null) return props.children
|
||||
|
||||
return createPortal(props.children, props.to || to || document.body)
|
||||
|
||||
@@ -3,6 +3,8 @@ import * as React from "react"
|
||||
|
||||
import { cn } from "~/lib/utils"
|
||||
|
||||
import { RootPortal } from "./portal"
|
||||
|
||||
const Select = SelectPrimitive.Root
|
||||
|
||||
const SelectGroup = SelectPrimitive.Group
|
||||
@@ -67,7 +69,7 @@ const SelectContent = React.forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
|
||||
>(({ className, children, position = "popper", ...props }, ref) => (
|
||||
<SelectPrimitive.Portal>
|
||||
<RootPortal>
|
||||
<SelectPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
@@ -93,7 +95,7 @@ const SelectContent = React.forwardRef<
|
||||
</SelectPrimitive.Viewport>
|
||||
<SelectScrollDownButton />
|
||||
</SelectPrimitive.Content>
|
||||
</SelectPrimitive.Portal>
|
||||
</RootPortal>
|
||||
))
|
||||
SelectContent.displayName = SelectPrimitive.Content.displayName
|
||||
|
||||
|
||||
@@ -46,6 +46,6 @@ const TooltipContent = React.forwardRef<
|
||||
))
|
||||
TooltipContent.displayName = TooltipPrimitive.Content.displayName
|
||||
|
||||
const TooltipPortal = TooltipPrimitive.Portal
|
||||
export { Tooltip, TooltipContent, TooltipTrigger }
|
||||
|
||||
export { Tooltip, TooltipContent, TooltipPortal, TooltipTrigger }
|
||||
export { RootPortal as TooltipPortal } from "../portal"
|
||||
|
||||
@@ -15,3 +15,5 @@ export const ROUTE_FEED_IN_INBOX = "inbox-"
|
||||
|
||||
export const DAILY_CLAIM_AMOUNT = "20"
|
||||
export const INVITATION_PRICE = "100"
|
||||
|
||||
export const INBOX_PREFIX_ID = "inbox-"
|
||||
|
||||
@@ -25,6 +25,7 @@ import { mountLottie } from "~/components/ui/lottie-container"
|
||||
import {
|
||||
SimpleIconsEagle,
|
||||
SimpleIconsInstapaper,
|
||||
SimpleIconsOmnivore,
|
||||
SimpleIconsReadwise,
|
||||
} from "~/components/ui/platform-icon/icons"
|
||||
import { shortcuts } from "~/constants/shortcuts"
|
||||
@@ -137,6 +138,7 @@ export const useEntryActions = ({
|
||||
const { t } = useTranslation()
|
||||
|
||||
const feed = useFeedById(entry?.feedId)
|
||||
const isInbox = feed?.type === "inbox"
|
||||
|
||||
const populatedEntry = useMemo(() => {
|
||||
if (!entry) return null
|
||||
@@ -166,6 +168,9 @@ export const useEntryActions = ({
|
||||
const enableInstapaper = useIntegrationSettingKey("enableInstapaper")
|
||||
const instapaperUsername = useIntegrationSettingKey("instapaperUsername")
|
||||
const instapaperPassword = useIntegrationSettingKey("instapaperPassword")
|
||||
const enableOmnivore = useIntegrationSettingKey("enableOmnivore")
|
||||
const omnivoreToken = useIntegrationSettingKey("omnivoreToken")
|
||||
const omnivoreEndpoint = useIntegrationSettingKey("omnivoreEndpoint")
|
||||
|
||||
const checkEagle = useQuery({
|
||||
queryKey: ["check-eagle"],
|
||||
@@ -307,12 +312,70 @@ export const useEntryActions = ({
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: t("entry_actions.save_to_omnivore"),
|
||||
icon: <SimpleIconsOmnivore />,
|
||||
key: "saveToomnivore",
|
||||
hide: !enableOmnivore || !omnivoreToken || !omnivoreEndpoint || !populatedEntry.entries.url,
|
||||
onClick: async () => {
|
||||
const saveUrlQuery = `
|
||||
mutation SaveUrl($input: SaveUrlInput!) {
|
||||
saveUrl(input: $input) {
|
||||
... on SaveSuccess {
|
||||
url
|
||||
clientRequestId
|
||||
}
|
||||
... on SaveError {
|
||||
errorCodes
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
try {
|
||||
const data = await ofetch(omnivoreEndpoint, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: omnivoreToken,
|
||||
},
|
||||
body: {
|
||||
query: saveUrlQuery,
|
||||
variables: {
|
||||
input: {
|
||||
url: populatedEntry.entries.url,
|
||||
source: "Follow",
|
||||
clientRequestId: globalThis.crypto.randomUUID(),
|
||||
publishedAt: new Date(populatedEntry.entries.publishedAt),
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
toast.success(
|
||||
<>
|
||||
{t("entry_actions.saved_to_omnivore")},{" "}
|
||||
<a target="_blank" className="underline" href={data.data.saveUrl.url}>
|
||||
view
|
||||
</a>
|
||||
</>,
|
||||
{
|
||||
duration: 3000,
|
||||
},
|
||||
)
|
||||
} catch {
|
||||
toast.error(t("entry_actions.failed_to_save_to_omnivore"), {
|
||||
duration: 3000,
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "tip",
|
||||
shortcut: shortcuts.entry.tip.key,
|
||||
name: t("entry_actions.tip"),
|
||||
className: "i-mgc-power-outline",
|
||||
hide: feed?.ownerUserId === whoami()?.id,
|
||||
hide: isInbox || feed?.ownerUserId === whoami()?.id,
|
||||
onClick: () => {
|
||||
nextFrame(openTipModal)
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IN_ELECTRON, WEB_URL } from "@follow/shared/constants"
|
||||
import { IN_ELECTRON } from "@follow/shared/constants"
|
||||
import { env } from "@follow/shared/env"
|
||||
import { useMemo } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -7,6 +7,7 @@ import { whoami } from "~/atoms/user"
|
||||
import { useModalStack } from "~/components/ui/modal"
|
||||
import type { FeedViewType } from "~/lib/enum"
|
||||
import type { NativeMenuItem, NullableNativeMenuItem } from "~/lib/native-menu"
|
||||
import { UrlBuilder } from "~/lib/url-builder"
|
||||
import { isBizId } from "~/lib/utils"
|
||||
import { useFeedClaimModal } from "~/modules/claim"
|
||||
import { FeedForm } from "~/modules/discover/feed-form"
|
||||
@@ -38,6 +39,7 @@ export const useFeedActions = ({
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const feed = useFeedById(feedId)
|
||||
const isInbox = feed?.type === "inbox"
|
||||
const subscription = useSubscriptionByFeedId(feedId)
|
||||
const { present } = useModalStack()
|
||||
const deleteSubscription = useDeleteSubscription({})
|
||||
@@ -91,6 +93,7 @@ export const useFeedActions = ({
|
||||
{
|
||||
type: "text" as const,
|
||||
label: t("sidebar.feed_column.context_menu.add_feeds_to_list"),
|
||||
disabled: isInbox,
|
||||
submenu: [
|
||||
...listByView.map((list) => {
|
||||
const isIncluded = list.feedIds.includes(feedId)
|
||||
@@ -113,9 +116,7 @@ export const useFeedActions = ({
|
||||
},
|
||||
}
|
||||
}),
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
listByView.length > 0 && { type: "separator" as const },
|
||||
{
|
||||
label: t("sidebar.feed_actions.create_list"),
|
||||
type: "text" as const,
|
||||
@@ -150,13 +151,14 @@ export const useFeedActions = ({
|
||||
? t("sidebar.feed_actions.unfollow_feed")
|
||||
: t("sidebar.feed_actions.unfollow"),
|
||||
shortcut: "Meta+Backspace",
|
||||
disabled: isInbox,
|
||||
click: () => deleteSubscription.mutate(subscription),
|
||||
},
|
||||
{
|
||||
type: "text" as const,
|
||||
label: t("sidebar.feed_actions.navigate_to_feed"),
|
||||
shortcut: "Meta+G",
|
||||
disabled: !isEntryList || getRouteParams().feedId === feedId,
|
||||
disabled: isInbox || !isEntryList || getRouteParams().feedId === feedId,
|
||||
click: () => {
|
||||
navigateEntry({ feedId })
|
||||
},
|
||||
@@ -172,7 +174,7 @@ export const useFeedActions = ({
|
||||
}),
|
||||
disabled: isEntryList,
|
||||
shortcut: "O",
|
||||
click: () => window.open(`${WEB_URL}/feed/${feedId}?view=${view}`, "_blank"),
|
||||
click: () => window.open(UrlBuilder.shareFeed(feedId, view), "_blank"),
|
||||
},
|
||||
{
|
||||
type: "text" as const,
|
||||
@@ -295,7 +297,7 @@ export const useListActions = ({ listId, view }: { listId: string; view: FeedVie
|
||||
}),
|
||||
disabled: false,
|
||||
shortcut: "O",
|
||||
click: () => window.open(`${WEB_URL}/list/${listId}?view=${view}`, "_blank"),
|
||||
click: () => window.open(UrlBuilder.shareList(listId, view), "_blank"),
|
||||
},
|
||||
|
||||
{
|
||||
@@ -308,8 +310,7 @@ export const useListActions = ({ listId, view }: { listId: string; view: FeedVie
|
||||
disabled: false,
|
||||
shortcut: "Meta+C",
|
||||
click: () => {
|
||||
const url = `${WEB_URL}/list/${listId}?view=${view}`
|
||||
navigator.clipboard.writeText(url)
|
||||
navigator.clipboard.writeText(UrlBuilder.shareList(listId, view))
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,376 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import { extractCodeFromHtml } from "../parse-html"
|
||||
|
||||
describe("extractCodeFromHtml", () => {
|
||||
it("should extract code from div elements", () => {
|
||||
const htmlString = "<div>line 1</div><div>line 2</div>"
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toBe("line 1\nline 2\n")
|
||||
})
|
||||
|
||||
it("should extract code from span elements with line breaks", () => {
|
||||
const htmlString = "<span><span>line 1</span></span><span><span>line 2</span></span>"
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"line 1line 2
|
||||
"
|
||||
`)
|
||||
})
|
||||
|
||||
it("should extract code from span elements without line breaks", () => {
|
||||
const htmlString = "<span><span>line 1</span></span><span><span>line 2</span></span>"
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"line 1line 2
|
||||
"
|
||||
`)
|
||||
})
|
||||
|
||||
it("should return the entire text content if no specific structure is found", () => {
|
||||
const htmlString = "plain text content"
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toBe("plain text content")
|
||||
})
|
||||
|
||||
it("pre > code", () => {
|
||||
const htmlString = `<pre class="language-ts lang-ts"><code class="language-ts lang-ts">import i18next from 'i18next' import { initReactI18next } from 'react-i18next' import en from '@/locales/en.json' import zhCN from '@/locales/zh_CN.json' i18next.use(initReactI18next).init({ lng: 'zh', fallbackLng: 'en', resources: { en: { translation: en, }, zh: { translation: zhCN, }, }, })</code></pre>`
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(
|
||||
`"import i18next from 'i18next' import { initReactI18next } from 'react-i18next' import en from '@/locales/en.json' import zhCN from '@/locales/zh_CN.json' i18next.use(initReactI18next).init({ lng: 'zh', fallbackLng: 'en', resources: { en: { translation: en, }, zh: { translation: zhCN, }, }, })"`,
|
||||
)
|
||||
})
|
||||
|
||||
it("pre > code 2", () => {
|
||||
const htmlString = `<pre><code class="language-ts">import type { Namespace } from '@/types'; export const namespace: Namespace = { // ... }; </code></pre>`
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(
|
||||
`"import type { Namespace } from '@/types'; export const namespace: Namespace = { // ... }; "`,
|
||||
)
|
||||
})
|
||||
|
||||
it("pre", () => {
|
||||
const htmlString = `<pre>@keyframes seed {
|
||||
0%{--seed:0}1%{--seed:1}2%{--seed:2}3%{--seed:3}4%{--seed:4}5%{--seed:5}6%{--seed:6}7%{--seed:7}8%{--seed:8}9%{--seed:9}10%{--seed:10}11%{--seed:11}...95%{--seed:95}96%{--seed:96}97%{--seed:97}98%{--seed:98}99%{--seed:99}100%{--seed:100}
|
||||
}</pre>`
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`"@keyframes seed {
|
||||
0%{--seed:0}1%{--seed:1}2%{--seed:2}3%{--seed:3}4%{--seed:4}5%{--seed:5}6%{--seed:6}7%{--seed:7}8%{--seed:8}9%{--seed:9}10%{--seed:10}11%{--seed:11}...95%{--seed:95}96%{--seed:96}97%{--seed:97}98%{--seed:98}99%{--seed:99}100%{--seed:100}
|
||||
}"`)
|
||||
})
|
||||
|
||||
it("pre 2", () => {
|
||||
const htmlString = `<pre>@property --seed {
|
||||
syntax: "<integer>";
|
||||
inherits: true;
|
||||
initial-value: 0;
|
||||
}
|
||||
|
||||
@keyframes seed {
|
||||
from { --seed: 0; }
|
||||
to { --seed: 100; }
|
||||
}</pre>`
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"@property --seed {
|
||||
syntax: "<integer>";
|
||||
inherits: true;
|
||||
initial-value: 0;
|
||||
}
|
||||
|
||||
@keyframes seed {
|
||||
from { --seed: 0; }
|
||||
to { --seed: 100; }
|
||||
}"
|
||||
`)
|
||||
})
|
||||
|
||||
it("pre > lang-*", () => {
|
||||
const htmlString = `<pre><code class="lang-javascript">module.exports = {
|
||||
output: "standalone",
|
||||
}</code></pre>`
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"module.exports = {
|
||||
output: "standalone",
|
||||
}"
|
||||
`)
|
||||
})
|
||||
|
||||
it("shiki render", () => {
|
||||
const htmlString = `<pre class="shiki shiki-themes github-light github-dark" style="background-color:#fff;--shiki-dark-bg:#24292e;color:#24292e;--shiki-dark:#e1e4e8" tabindex="0"><code><span class="line" style="width: 920px;"><span style="color:#D73A49;--shiki-dark:#F97583">import</span><span style="color:#24292E;--shiki-dark:#E1E4E8"> i18next </span><span style="color:#D73A49;--shiki-dark:#F97583">from</span><span style="color:#032F62;--shiki-dark:#9ECBFF"> 'i18next'</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#D73A49;--shiki-dark:#F97583">import</span><span style="color:#24292E;--shiki-dark:#E1E4E8"> { initReactI18next } </span><span style="color:#D73A49;--shiki-dark:#F97583">from</span><span style="color:#032F62;--shiki-dark:#9ECBFF"> 'react-i18next'</span></span>
|
||||
<span class="line" style="width: 920px;"></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#D73A49;--shiki-dark:#F97583">import</span><span style="color:#24292E;--shiki-dark:#E1E4E8"> en </span><span style="color:#D73A49;--shiki-dark:#F97583">from</span><span style="color:#032F62;--shiki-dark:#9ECBFF"> '@/locales/en.json'</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#D73A49;--shiki-dark:#F97583">import</span><span style="color:#24292E;--shiki-dark:#E1E4E8"> zhCN </span><span style="color:#D73A49;--shiki-dark:#F97583">from</span><span style="color:#032F62;--shiki-dark:#9ECBFF"> '@/locales/zh_CN.json'</span></span>
|
||||
<span class="line" style="width: 920px;"></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#24292E;--shiki-dark:#E1E4E8">i18next.</span><span style="color:#6F42C1;--shiki-dark:#B392F0">use</span><span style="color:#24292E;--shiki-dark:#E1E4E8">(initReactI18next).</span><span style="color:#6F42C1;--shiki-dark:#B392F0">init</span><span style="color:#24292E;--shiki-dark:#E1E4E8">({</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#24292E;--shiki-dark:#E1E4E8"> lng: </span><span style="color:#032F62;--shiki-dark:#9ECBFF">'zh'</span><span style="color:#24292E;--shiki-dark:#E1E4E8">,</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#24292E;--shiki-dark:#E1E4E8"> fallbackLng: </span><span style="color:#032F62;--shiki-dark:#9ECBFF">'en'</span><span style="color:#24292E;--shiki-dark:#E1E4E8">,</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#24292E;--shiki-dark:#E1E4E8"> resources: {</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#24292E;--shiki-dark:#E1E4E8"> en: {</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#24292E;--shiki-dark:#E1E4E8"> translation: en,</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#24292E;--shiki-dark:#E1E4E8"> },</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#24292E;--shiki-dark:#E1E4E8"> zh: {</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#24292E;--shiki-dark:#E1E4E8"> translation: zhCN,</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#24292E;--shiki-dark:#E1E4E8"> },</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#24292E;--shiki-dark:#E1E4E8"> },</span></span>
|
||||
<span class="line" style="width: 920px;"><span style="color:#24292E;--shiki-dark:#E1E4E8">})</span></span></code></pre>`
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"import i18next from 'i18next'
|
||||
import { initReactI18next } from 'react-i18next'
|
||||
|
||||
import en from '@/locales/en.json'
|
||||
import zhCN from '@/locales/zh_CN.json'
|
||||
|
||||
i18next.use(initReactI18next).init({
|
||||
lng: 'zh',
|
||||
fallbackLng: 'en',
|
||||
resources: {
|
||||
en: {
|
||||
translation: en,
|
||||
},
|
||||
zh: {
|
||||
translation: zhCN,
|
||||
},
|
||||
},
|
||||
})
|
||||
"
|
||||
`)
|
||||
})
|
||||
|
||||
it("pre > code, without line wrapper", () => {
|
||||
const htmlString = `<pre class=" language-dockerfile"><code class=" language-dockerfile"><span class="token keyword">FROM</span> node<span class="token punctuation">:</span>20.15<span class="token punctuation">-</span>alpine AS runner
|
||||
|
||||
<span class="token keyword">ENV</span> NODE_ENV production
|
||||
|
||||
<span class="token comment"># Create app directory</span>
|
||||
<span class="token keyword">WORKDIR</span> /app
|
||||
|
||||
<span class="token keyword">RUN</span> addgroup <span class="token punctuation">-</span><span class="token punctuation">-</span>system <span class="token punctuation">-</span><span class="token punctuation">-</span>gid 1001 nodejs
|
||||
<span class="token keyword">RUN</span> adduser <span class="token punctuation">-</span><span class="token punctuation">-</span>system <span class="token punctuation">-</span><span class="token punctuation">-</span>uid 1001 nextjs
|
||||
|
||||
<span class="token keyword">COPY</span> public /app/public
|
||||
|
||||
<span class="token comment"># Set the correct permission for prerender cache</span>
|
||||
<span class="token keyword">RUN</span> mkdir .next
|
||||
<span class="token keyword">RUN</span> chown nextjs<span class="token punctuation">:</span>nodejs .next
|
||||
|
||||
<span class="token comment"># Automatically leverage output traces to reduce image size</span>
|
||||
<span class="token comment"># https://nextjs.org/docs/advanced-features/output-file-tracing</span>
|
||||
<span class="token keyword">COPY</span> <span class="token punctuation">-</span><span class="token punctuation">-</span>chown=nextjs<span class="token punctuation">:</span>nodejs .next/standalone ./
|
||||
<span class="token keyword">COPY</span> <span class="token punctuation">-</span><span class="token punctuation">-</span>chown=nextjs<span class="token punctuation">:</span>nodejs .next/static .next/static
|
||||
|
||||
<span class="token keyword">USER</span> nextjs
|
||||
|
||||
<span class="token keyword">EXPOSE</span> 3000
|
||||
<span class="token keyword">ENV</span> PORT 3000
|
||||
|
||||
<span class="token keyword">CMD</span> <span class="token punctuation">[</span><span class="token string">"ls"</span><span class="token punctuation">,</span> <span class="token string">"-l"</span><span class="token punctuation">]</span>
|
||||
|
||||
<span class="token comment"># server.js is created by next build from the standalone output</span>
|
||||
<span class="token comment"># https://nextjs.org/docs/pages/api-reference/next-config-js/output</span>
|
||||
<span class="token keyword">CMD</span> HOSTNAME=<span class="token string">"0.0.0.0"</span> node server.js</code></pre>`
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"FROM node:20.15-alpine AS runner
|
||||
|
||||
ENV NODE_ENV production
|
||||
|
||||
# Create app directory
|
||||
WORKDIR /app
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
COPY public /app/public
|
||||
|
||||
# Set the correct permission for prerender cache
|
||||
RUN mkdir .next
|
||||
RUN chown nextjs:nodejs .next
|
||||
|
||||
# Automatically leverage output traces to reduce image size
|
||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||
COPY --chown=nextjs:nodejs .next/standalone ./
|
||||
COPY --chown=nextjs:nodejs .next/static .next/static
|
||||
|
||||
USER nextjs
|
||||
|
||||
EXPOSE 3000
|
||||
ENV PORT 3000
|
||||
|
||||
CMD ["ls", "-l"]
|
||||
|
||||
# server.js is created by next build from the standalone output
|
||||
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
|
||||
CMD HOSTNAME="0.0.0.0" node server.js"
|
||||
`)
|
||||
})
|
||||
|
||||
it("hijs", () => {
|
||||
const htmlString = `<pre tabindex="0" class="hljs language-css"><a href="javascript:" class="copy" tabindex="0" title="复制"><svg class="icon-copy"><use xlink:href="#icon-copy"></use></svg></a><a href="javascript:" class="beatuy revert" tabindex="0" title="还原"><svg class="icon-palette"><use xlink:href="#icon-palette"></use></svg></a><span class="hljs-keyword">@keyframes</span> seed {
|
||||
<span class="hljs-number">0%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">0</span>}<span class="hljs-number">1%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">1</span>}<span class="hljs-number">2%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">2</span>}<span class="hljs-number">3%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">3</span>}<span class="hljs-number">4%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">4</span>}<span class="hljs-number">5%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">5</span>}<span class="hljs-number">6%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">6</span>}<span class="hljs-number">7%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">7</span>}<span class="hljs-number">8%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">8</span>}<span class="hljs-number">9%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">9</span>}<span class="hljs-number">10%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">10</span>}<span class="hljs-number">11%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">11</span>}...<span class="hljs-number">95%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">95</span>}<span class="hljs-number">96%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">96</span>}<span class="hljs-number">97%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">97</span>}<span class="hljs-number">98%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">98</span>}<span class="hljs-number">99%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">99</span>}<span class="hljs-number">100%</span>{<span class="hljs-attr">--seed</span>:<span class="hljs-number">100</span>}
|
||||
}</pre>`
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"@keyframes seed {
|
||||
0%{--seed:0}1%{--seed:1}2%{--seed:2}3%{--seed:3}4%{--seed:4}5%{--seed:5}6%{--seed:6}7%{--seed:7}8%{--seed:8}9%{--seed:9}10%{--seed:10}11%{--seed:11}...95%{--seed:95}96%{--seed:96}97%{--seed:97}98%{--seed:98}99%{--seed:99}100%{--seed:100}
|
||||
}"
|
||||
`)
|
||||
})
|
||||
|
||||
it("hijs 2", () => {
|
||||
const htmlString = `<pre translate="no" class="flat-scrollbar-normal not-prose rounded-md bg-[#F6F8FA] p-2 text-sm selection:bg-gray-300 selection:text-inherit dark:bg-[#0d1117] dark:selection:bg-gray-700"><code class="hljs language-typescript"><span class="hljs-keyword">function</span> <span class="hljs-title function_">randInterval</span>(<span class="hljs-params"></span>): <span class="hljs-built_in">number</span> {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">random</span>();
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">function</span> <span class="hljs-title function_">boxMuller</span>(<span class="hljs-params">mu: <span class="hljs-built_in">number</span>, sigma: <span class="hljs-built_in">number</span></span>): [<span class="hljs-built_in">number</span>, <span class="hljs-built_in">number</span>] {
|
||||
<span class="hljs-keyword">const</span> u = <span class="hljs-title function_">randInterval</span>();
|
||||
<span class="hljs-keyword">const</span> v = <span class="hljs-title function_">randInterval</span>();
|
||||
<span class="hljs-keyword">const</span> x = <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">cos</span>(<span class="hljs-number">2</span> * <span class="hljs-title class_">Math</span>.<span class="hljs-property">PI</span> * u) * <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">sqrt</span>(-<span class="hljs-number">2</span> * <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">log</span>(v));
|
||||
<span class="hljs-keyword">const</span> y = <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">sin</span>(<span class="hljs-number">2</span> * <span class="hljs-title class_">Math</span>.<span class="hljs-property">PI</span> * u) * <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">sqrt</span>(-<span class="hljs-number">2</span> * <span class="hljs-title class_">Math</span>.<span class="hljs-title function_">log</span>(v));
|
||||
<span class="hljs-keyword">return</span> [x * sigma + mu, y * sigma + mu];
|
||||
}
|
||||
|
||||
<span class="hljs-comment">// Usage example</span>
|
||||
<span class="hljs-keyword">const</span> [value1, value2] = <span class="hljs-title function_">boxMuller</span>(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>);
|
||||
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(value1, value2);
|
||||
<span class="hljs-comment">// Outputs two normally distributed random numbers</span>
|
||||
</code></pre>`
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"function randInterval(): number {
|
||||
return Math.random();
|
||||
}
|
||||
|
||||
function boxMuller(mu: number, sigma: number): [number, number] {
|
||||
const u = randInterval();
|
||||
const v = randInterval();
|
||||
const x = Math.cos(2 * Math.PI * u) * Math.sqrt(-2 * Math.log(v));
|
||||
const y = Math.sin(2 * Math.PI * u) * Math.sqrt(-2 * Math.log(v));
|
||||
return [x * sigma + mu, y * sigma + mu];
|
||||
}
|
||||
|
||||
// Usage example
|
||||
const [value1, value2] = boxMuller(0, 1);
|
||||
console.log(value1, value2);
|
||||
// Outputs two normally distributed random numbers
|
||||
|
||||
"
|
||||
`)
|
||||
})
|
||||
|
||||
it("hijs without wrapper", () => {
|
||||
const htmlString = `<pre><span>import</span> * <span>as</span> fs <span>from</span> <span>"fs"</span>;
|
||||
<span>import</span> * <span>as</span> plotly <span>from</span> <span>"plotly.js-dist"</span>;
|
||||
|
||||
<span>// Generate random numbers following a normal distribution using Box-Muller</span>
|
||||
<span>function</span> <span>randInterval</span>(<span></span>): <span>number</span> {
|
||||
<span>return</span> <span>Math</span>.<span>random</span>();
|
||||
}
|
||||
|
||||
<span>function</span> <span>boxMuller</span>(<span>mu: <span>number</span>, sigma: <span>number</span></span>): [<span>number</span>, <span>number</span>] {
|
||||
<span>const</span> u = <span>randInterval</span>();
|
||||
<span>const</span> v = <span>randInterval</span>();
|
||||
<span>const</span> x = <span>Math</span>.<span>cos</span>(<span>2</span> * <span>Math</span>.<span>PI</span> * u) * <span>Math</span>.<span>sqrt</span>(-<span>2</span> * <span>Math</span>.<span>log</span>(v));
|
||||
<span>const</span> y = <span>Math</span>.<span>sin</span>(<span>2</span> * <span>Math</span>.<span>PI</span> * u) * <span>Math</span>.<span>sqrt</span>(-<span>2</span> * <span>Math</span>.<span>log</span>(v));
|
||||
<span>return</span> [x * sigma + mu, y * sigma + mu];
|
||||
}
|
||||
|
||||
<span>// Generate n normally distributed random numbers</span>
|
||||
<span>function</span> <span>generateNormalDistribution</span>(<span>
|
||||
mu: <span>number</span>,
|
||||
sigma: <span>number</span>,
|
||||
n: <span>number</span>
|
||||
</span>): <span>number</span>[] {
|
||||
<span>const</span> <span>values</span>: <span>number</span>[] = [];
|
||||
<span>for</span> (<span>let</span> i = <span>0</span>; i < n / <span>2</span>; i++) {
|
||||
<span>const</span> [value1, value2] = <span>boxMuller</span>(mu, sigma);
|
||||
values.<span>push</span>(value1, value2);
|
||||
}
|
||||
<span>return</span> values;
|
||||
}
|
||||
|
||||
<span>// Generate the data</span>
|
||||
<span>const</span> mu = <span>0</span>;
|
||||
<span>const</span> sigma = <span>1</span>;
|
||||
<span>const</span> sampleSize = <span>10000</span>; <span>// Sample size</span>
|
||||
<span>const</span> values = <span>generateNormalDistribution</span>(mu, sigma, sampleSize);
|
||||
|
||||
<span>// Calculate the mean and variance of the generated random numbers</span>
|
||||
<span>const</span> mean = values.<span>reduce</span>(<span>(<span>acc, val</span>) =></span> acc + val, <span>0</span>) / values.<span>length</span>;
|
||||
<span>const</span> variance =
|
||||
values.<span>reduce</span>(<span>(<span>acc, val</span>) =></span> acc + (val - mean) ** <span>2</span>, <span>0</span>) / values.<span>length</span>;
|
||||
</pre>
|
||||
`
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"import * as fs from "fs";
|
||||
import * as plotly from "plotly.js-dist";
|
||||
|
||||
// Generate random numbers following a normal distribution using Box-Muller
|
||||
function randInterval(): number {
|
||||
return Math.random();
|
||||
}
|
||||
|
||||
function boxMuller(mu: number, sigma: number): [number, number] {
|
||||
const u = randInterval();
|
||||
const v = randInterval();
|
||||
const x = Math.cos(2 * Math.PI * u) * Math.sqrt(-2 * Math.log(v));
|
||||
const y = Math.sin(2 * Math.PI * u) * Math.sqrt(-2 * Math.log(v));
|
||||
return [x * sigma + mu, y * sigma + mu];
|
||||
}
|
||||
|
||||
// Generate n normally distributed random numbers
|
||||
function generateNormalDistribution(
|
||||
mu: number,
|
||||
sigma: number,
|
||||
n: number
|
||||
): number[] {
|
||||
const values: number[] = [];
|
||||
for (let i = 0; i < n / 2; i++) {
|
||||
const [value1, value2] = boxMuller(mu, sigma);
|
||||
values.push(value1, value2);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
// Generate the data
|
||||
const mu = 0;
|
||||
const sigma = 1;
|
||||
const sampleSize = 10000; // Sample size
|
||||
const values = generateNormalDistribution(mu, sigma, sampleSize);
|
||||
|
||||
// Calculate the mean and variance of the generated random numbers
|
||||
const mean = values.reduce((acc, val) => acc + val, 0) / values.length;
|
||||
const variance =
|
||||
values.reduce((acc, val) => acc + (val - mean) ** 2, 0) / values.length;
|
||||
|
||||
"
|
||||
`)
|
||||
})
|
||||
|
||||
it("no <code />", () => {
|
||||
const htmlString = `<span class="line"><span class="keyword">if</span> theme.<span class="property">twikoo</span>.<span class="property">enable</span> == <span class="literal">true</span></span><br><span class="line"> #tcomment</span><br><span class="line"> <span class="title function_">script</span>(src=<span class="string">'https://registry.npmmirror.com/twikoo/1.6.39/files/dist/twikoo.all.min.js'</span>)</span><br><span class="line"> script.</span><br><span class="line"> twikoo.<span class="title function_">init</span>({</span><br><span class="line"> <span class="attr">envId</span>: <span class="string">'#{theme.twikoo.envId}'</span>,</span><br><span class="line"> <span class="attr">el</span>: <span class="string">'#tcomment'</span>,</span><br><span class="line"> <span class="attr">region</span>: <span class="string">'#{theme.twikoo.region}'</span>,</span><br><span class="line"> <span class="attr">path</span>: <span class="string">'#{theme.twikoo.path}'</span>,</span><br><span class="line"> <span class="attr">onCommentLoaded</span>: <span class="keyword">function</span> (<span class="params"></span>) {</span><br><span class="line"> <span class="keyword">const</span> commentCountElement = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">'.tk-comments-count'</span>);</span><br><span class="line"> <span class="keyword">const</span> targetElement = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">'.waline-comment-count'</span>);</span><br><span class="line"> <span class="keyword">if</span> (commentCountElement) {</span><br><span class="line"> <span class="keyword">const</span> countSpan = commentCountElement.<span class="title function_">querySelector</span>(<span class="string">'span:first-child'</span>);</span><br><span class="line"> <span class="keyword">const</span> commentCount = <span class="built_in">parseInt</span>(countSpan.<span class="property">textContent</span>);</span><br><span class="line"> targetElement.<span class="property">textContent</span> = commentCount;</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">'未找到评论数量元素'</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> })</span><br><span class="line"></span><br>`
|
||||
const result = extractCodeFromHtml(htmlString)
|
||||
|
||||
expect(result).toMatchInlineSnapshot(
|
||||
`"if theme.twikoo.enable == true #tcomment script(src='https://registry.npmmirror.com/twikoo/1.6.39/files/dist/twikoo.all.min.js') script. twikoo.init({ envId: '#{theme.twikoo.envId}', el: '#tcomment', region: '#{theme.twikoo.region}', path: '#{theme.twikoo.path}', onCommentLoaded: function () { const commentCountElement = document.querySelector('.tk-comments-count'); const targetElement = document.querySelector('.waline-comment-count'); if (commentCountElement) { const countSpan = commentCountElement.querySelector('span:first-child'); const commentCount = parseInt(countSpan.textContent); targetElement.textContent = commentCount; } else { console.log('未找到评论数量元素'); } } })"`,
|
||||
)
|
||||
})
|
||||
})
|
||||
+1
-1
@@ -8,7 +8,7 @@ import {
|
||||
parseRegexpPathParams,
|
||||
regexpPathToPath,
|
||||
transformUriPath,
|
||||
} from "./path-parser"
|
||||
} from "../path-parser"
|
||||
|
||||
describe("test `transformUriPath()`", () => {
|
||||
test("normal path", () => {
|
||||
@@ -22,25 +22,13 @@ export const apiFetch = ofetch.create({
|
||||
}
|
||||
|
||||
const csrfToken = await csrfTokenPromise
|
||||
if (options.method && options.method.toLowerCase() !== "get") {
|
||||
if (typeof options.body === "string") {
|
||||
options.body = JSON.parse(options.body)
|
||||
}
|
||||
if (!options.body) {
|
||||
options.body = {}
|
||||
}
|
||||
if (options.body instanceof FormData) {
|
||||
options.body.append("csrfToken", csrfToken)
|
||||
} else {
|
||||
;(options.body as Record<string, unknown>).csrfToken = csrfToken
|
||||
}
|
||||
|
||||
const header = new Headers(options.headers)
|
||||
const header = new Headers(options.headers)
|
||||
|
||||
header.set("x-app-version", PKG.version)
|
||||
header.set("X-App-Dev", process.env.NODE_ENV === "development" ? "1" : "0")
|
||||
options.headers = header
|
||||
}
|
||||
header.set("x-app-version", PKG.version)
|
||||
header.set("X-App-Dev", process.env.NODE_ENV === "development" ? "1" : "0")
|
||||
header.set("X-Csrf-Token", csrfToken)
|
||||
options.headers = header
|
||||
},
|
||||
onResponse() {
|
||||
setApiStatus(NetworkStatus.ONLINE)
|
||||
@@ -94,10 +82,11 @@ export const apiClient = hc<AppType>(env.VITE_API_URL, {
|
||||
}
|
||||
throw err
|
||||
}),
|
||||
headers() {
|
||||
async headers() {
|
||||
return {
|
||||
"X-App-Version": PKG.version,
|
||||
"X-App-Dev": process.env.NODE_ENV === "development" ? "1" : "0",
|
||||
"X-Csrf-Token": await getCsrfToken(),
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -43,8 +43,10 @@ export const toastFetchError = (
|
||||
const json = JSON.parse(error.response?._data)
|
||||
|
||||
const { reason, code, message: _message } = json
|
||||
const i18nKey = `errors:${code}` as any
|
||||
const i18nMessage = t(i18nKey) === i18nKey ? message : t(i18nKey)
|
||||
message = _message
|
||||
|
||||
const tValue = t(`errors:${code}` as any)
|
||||
const i18nMessage = tValue === code.toString() ? message : tValue
|
||||
|
||||
message = i18nMessage
|
||||
|
||||
|
||||
@@ -4,22 +4,39 @@ import { get } from "lodash-es"
|
||||
import { tipcClient } from "./client"
|
||||
import { getOS } from "./utils"
|
||||
|
||||
export type NativeMenuItem = (
|
||||
| {
|
||||
type: "text"
|
||||
label: string
|
||||
click?: () => void
|
||||
/** only work in web app */
|
||||
icon?: React.ReactNode
|
||||
shortcut?: string
|
||||
disabled?: boolean
|
||||
submenu?: NativeMenuItem[]
|
||||
checked?: boolean
|
||||
}
|
||||
| { type: "separator"; disabled?: boolean }
|
||||
) & { hide?: boolean }
|
||||
type MenuItemWithHide<T> = T & {
|
||||
hide?: boolean
|
||||
}
|
||||
|
||||
export type NullableNativeMenuItem = NativeMenuItem | null | undefined | false | ""
|
||||
type BaseMenuItemText = MenuItemWithHide<{
|
||||
type: "text"
|
||||
label: string
|
||||
click?: () => void
|
||||
/** only work in web app */
|
||||
icon?: React.ReactNode
|
||||
shortcut?: string
|
||||
disabled?: boolean
|
||||
checked?: boolean
|
||||
}>
|
||||
|
||||
type BaseMenuItemSeparator = MenuItemWithHide<{
|
||||
type: "separator"
|
||||
disabled?: boolean
|
||||
}>
|
||||
|
||||
type BaseMenuItem = BaseMenuItemText | BaseMenuItemSeparator
|
||||
|
||||
export type NativeMenuItem = BaseMenuItem & {
|
||||
submenu?: NativeMenuItem[]
|
||||
}
|
||||
|
||||
export type NullableNativeMenuItem =
|
||||
| (BaseMenuItemText & { submenu?: NullableNativeMenuItem[] })
|
||||
| BaseMenuItemSeparator
|
||||
| null
|
||||
| undefined
|
||||
| false
|
||||
| ""
|
||||
|
||||
function sortShortcutsString(shortcut: string) {
|
||||
const order = ["Shift", "Ctrl", "Meta", "Alt"]
|
||||
@@ -37,19 +54,24 @@ function sortShortcutsString(shortcut: string) {
|
||||
|
||||
return [...sortedModifiers, ...otherKeys].join("+")
|
||||
}
|
||||
export const showNativeMenu = async (
|
||||
items: Array<NullableNativeMenuItem>,
|
||||
e?: MouseEvent | React.MouseEvent,
|
||||
) => {
|
||||
const nextItems = (items.filter((item) => item && !item.hide) as NativeMenuItem[]).map((item) => {
|
||||
|
||||
function processMenuItems(items: NullableNativeMenuItem[]): NativeMenuItem[] {
|
||||
return (items.filter((item) => item && !item.hide) as NativeMenuItem[]).map((item) => {
|
||||
if (item.type === "text") {
|
||||
return {
|
||||
...item,
|
||||
shortcut: item.shortcut ? sortShortcutsString(item.shortcut) : undefined,
|
||||
submenu: item.submenu ? processMenuItems(item.submenu) : undefined,
|
||||
}
|
||||
}
|
||||
return item
|
||||
}) as NativeMenuItem[]
|
||||
})
|
||||
}
|
||||
export const showNativeMenu = async (
|
||||
items: Array<NullableNativeMenuItem>,
|
||||
e?: MouseEvent | React.MouseEvent,
|
||||
) => {
|
||||
const nextItems = processMenuItems(items)
|
||||
|
||||
const el = e && e.currentTarget
|
||||
|
||||
|
||||
@@ -18,8 +18,10 @@ import { VFile } from "vfile"
|
||||
import { ShadowDOM } from "~/components/common/ShadowDOM"
|
||||
import { Checkbox } from "~/components/ui/checkbox"
|
||||
import { ShikiHighLighter } from "~/components/ui/code-highlighter"
|
||||
import { LazyKateX } from "~/components/ui/katex/lazy"
|
||||
import { MarkdownBlockImage, MarkdownLink, MarkdownP } from "~/components/ui/markdown/renderers"
|
||||
import { BlockError } from "~/components/ui/markdown/renderers/BlockErrorBoundary"
|
||||
import { useIsInParagraphContext } from "~/components/ui/markdown/renderers/ctx"
|
||||
import { createHeadingRenderer } from "~/components/ui/markdown/renderers/Heading"
|
||||
import { MarkdownInlineImage } from "~/components/ui/markdown/renderers/InlineImage"
|
||||
import { Media } from "~/components/ui/media"
|
||||
@@ -68,6 +70,7 @@ export const parseHtml = (
|
||||
const { renderInlineStyle = false, noMedia = false } = options || {}
|
||||
|
||||
const rehypeSchema: Schema = { ...defaultSchema }
|
||||
rehypeSchema.tagNames = [...rehypeSchema.tagNames!, "math"]
|
||||
|
||||
if (noMedia) {
|
||||
rehypeSchema.tagNames = rehypeSchema.tagNames?.filter(
|
||||
@@ -148,6 +151,8 @@ export const parseHtml = (
|
||||
markInlineImage(node)
|
||||
return createElement("span", props, props.children)
|
||||
},
|
||||
// @ts-expect-error
|
||||
math: Math,
|
||||
hr: ({ node, ...props }) =>
|
||||
createElement("hr", {
|
||||
...props,
|
||||
@@ -181,6 +186,7 @@ export const parseHtml = (
|
||||
? propsChildren.find((i) => i.type === "code")
|
||||
: propsChildren
|
||||
|
||||
// Don't process not code block
|
||||
if (!children) return createElement("pre", props, props.children)
|
||||
|
||||
if (
|
||||
@@ -190,8 +196,8 @@ export const parseHtml = (
|
||||
) {
|
||||
language = children.props.className.replace("language-", "")
|
||||
}
|
||||
const code = "props" in children && children.props.children
|
||||
if (!code) createElement("pre", props, props.children)
|
||||
const code = ("props" in children && children.props.children) || children
|
||||
if (!code) return null
|
||||
|
||||
try {
|
||||
codeString = extractCodeFromHtml(renderToString(code))
|
||||
@@ -241,10 +247,15 @@ const Img: Components["img"] = ({ node, ...props }) => {
|
||||
)
|
||||
}
|
||||
|
||||
function extractCodeFromHtml(htmlString: string) {
|
||||
export function extractCodeFromHtml(htmlString: string) {
|
||||
const tempDiv = document.createElement("div")
|
||||
tempDiv.innerHTML = htmlString
|
||||
|
||||
const hasPre = tempDiv.querySelector("pre")
|
||||
if (!hasPre) {
|
||||
tempDiv.innerHTML = `<pre><code>${htmlString}</code></pre>`
|
||||
}
|
||||
|
||||
// 1. line break via <div />
|
||||
const divElements = tempDiv.querySelectorAll("div")
|
||||
|
||||
@@ -272,6 +283,14 @@ function extractCodeFromHtml(htmlString: string) {
|
||||
if (spanAsLineBreak) break
|
||||
}
|
||||
}
|
||||
|
||||
if (!spanAsLineBreak) {
|
||||
const usingBr = tempDiv.querySelector("br")
|
||||
if (usingBr) {
|
||||
spanAsLineBreak = true
|
||||
}
|
||||
}
|
||||
|
||||
if (spanElements.length > 0) {
|
||||
for (const node of tempDiv.children) {
|
||||
if (spanAsLineBreak) {
|
||||
@@ -345,3 +364,16 @@ function rehypeUrlToAnchor(tree: Node) {
|
||||
;(parent.children as (Text | Element)[]).splice(index, 1, ...newNodes)
|
||||
})
|
||||
}
|
||||
|
||||
const Math = ({ node }) => {
|
||||
const annotation = node.children.at(-1)
|
||||
|
||||
const isInParagraph = useIsInParagraphContext()
|
||||
if (!annotation) return null
|
||||
const latex = annotation.value
|
||||
|
||||
return createElement(LazyKateX, {
|
||||
children: latex,
|
||||
mode: isInParagraph ? "inline" : "display",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,7 +9,10 @@ function nestPaths(paths: string[]): NestedStructure {
|
||||
|
||||
paths.forEach((path) => {
|
||||
// Remove the './pages' prefix and the '.tsx' suffix
|
||||
const trimmedPath = path.replace("./pages/", "").replace(".tsx", "")
|
||||
const prefix = "./pages/"
|
||||
const suffix = ".tsx"
|
||||
const trimmedPath = path.slice(prefix.length, -suffix.length)
|
||||
|
||||
const parts = trimmedPath.split("/")
|
||||
|
||||
let currentLevel = result
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { WEB_URL } from "@follow/shared/constants"
|
||||
|
||||
class UrlBuilderStatic {
|
||||
private join(path: string, query?: Record<string, string>) {
|
||||
const nextUrl = new URL(WEB_URL)
|
||||
nextUrl.pathname = path
|
||||
if (query) {
|
||||
for (const [key, value] of Object.entries(query)) {
|
||||
nextUrl.searchParams.set(key, value)
|
||||
}
|
||||
}
|
||||
return nextUrl.toString()
|
||||
}
|
||||
shareFeed(id: string, view?: number) {
|
||||
return this.join(`share/feeds/${id}`, view ? { view: view.toString() } : undefined)
|
||||
}
|
||||
shareList(id: string, view?: number) {
|
||||
return this.join(`share/lists/${id}`, view ? { view: view.toString() } : undefined)
|
||||
}
|
||||
|
||||
profile(id: string) {
|
||||
return this.join(`profile/${id}`)
|
||||
}
|
||||
}
|
||||
|
||||
export const UrlBuilder = new UrlBuilderStatic()
|
||||
@@ -49,6 +49,10 @@ export type CombinedEntryModel = EntriesResponse[number] & {
|
||||
}
|
||||
}
|
||||
export type EntryModel = CombinedEntryModel["entries"]
|
||||
export type EntryModelSimple = Exclude<
|
||||
ExtractBizResponse<typeof apiClient.feeds.$get>["data"]["entries"],
|
||||
undefined
|
||||
>[number]
|
||||
export type DiscoverResponse = Array<
|
||||
Exclude<ExtractBizResponse<typeof apiClient.discover.$post>["data"], undefined>[number]
|
||||
>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Variant } from "framer-motion"
|
||||
import { m, useAnimationControls } from "framer-motion"
|
||||
import type { Components } from "hast-util-to-jsx-runtime"
|
||||
import { useEffect, useState } from "react"
|
||||
@@ -276,7 +277,7 @@ const createRelatedEntryLink = (variant: "toast" | "modal") => (props: LinkProps
|
||||
const EntryToastPreview = ({ entryId }: { entryId: string }) => {
|
||||
useAuthQuery(Queries.entries.byId(entryId))
|
||||
|
||||
const variants = {
|
||||
const variants: Record<string, Variant> = {
|
||||
enter: {
|
||||
x: 0,
|
||||
opacity: 1,
|
||||
@@ -306,89 +307,88 @@ const EntryToastPreview = ({ entryId }: { entryId: string }) => {
|
||||
if (!isDisplay) return null
|
||||
|
||||
return (
|
||||
<>
|
||||
<m.div
|
||||
tabIndex={-1}
|
||||
initial="initial"
|
||||
animate={controller}
|
||||
onPointerDown={stopPropagation}
|
||||
onPointerDownCapture={stopPropagation}
|
||||
variants={variants}
|
||||
transition={{
|
||||
type: "spring",
|
||||
mass: 0.4,
|
||||
tension: 120,
|
||||
friction: 1.4,
|
||||
}}
|
||||
exit="exit"
|
||||
layout="size"
|
||||
className={cn(
|
||||
"shadow-perfect relative flex flex-col items-center rounded-xl border bg-theme-background p-8",
|
||||
"mr-4 mt-4 max-h-[500px] w-[60ch] max-w-full overflow-auto",
|
||||
)}
|
||||
>
|
||||
<div className="flex w-full gap-3">
|
||||
<FeedIcon
|
||||
fallback
|
||||
className="mask-squircle mask"
|
||||
feed={feed}
|
||||
entry={entry.entries}
|
||||
size={36}
|
||||
/>
|
||||
<div className="flex min-w-0 grow flex-col">
|
||||
<div className="w-[calc(100%-10rem)] space-x-1">
|
||||
<span className="font-semibold">{entry.entries.author}</span>
|
||||
<span className="text-zinc-500">·</span>
|
||||
<span className="text-zinc-500">
|
||||
<RelativeTime date={entry.entries.publishedAt} />
|
||||
</span>
|
||||
</div>
|
||||
<m.div
|
||||
tabIndex={-1}
|
||||
initial="initial"
|
||||
animate={controller}
|
||||
onPointerDown={stopPropagation}
|
||||
onPointerDownCapture={stopPropagation}
|
||||
variants={variants}
|
||||
onWheel={stopPropagation}
|
||||
transition={{
|
||||
type: "spring",
|
||||
mass: 0.4,
|
||||
tension: 120,
|
||||
friction: 1.4,
|
||||
}}
|
||||
exit="exit"
|
||||
layout="size"
|
||||
className={cn(
|
||||
"shadow-perfect relative flex flex-col items-center rounded-xl border bg-theme-background p-8",
|
||||
"mr-4 mt-4 max-h-[500px] w-[60ch] max-w-full overflow-auto",
|
||||
)}
|
||||
>
|
||||
<div className="flex w-full gap-3">
|
||||
<FeedIcon
|
||||
fallback
|
||||
className="mask-squircle mask"
|
||||
feed={feed}
|
||||
entry={entry.entries}
|
||||
size={36}
|
||||
/>
|
||||
<div className="flex min-w-0 grow flex-col">
|
||||
<div className="w-[calc(100%-10rem)] space-x-1">
|
||||
<span className="font-semibold">{entry.entries.author}</span>
|
||||
<span className="text-zinc-500">·</span>
|
||||
<span className="text-zinc-500">
|
||||
<RelativeTime date={entry.entries.publishedAt} />
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
className={cn(
|
||||
"relative mt-0.5 whitespace-pre-line text-base",
|
||||
!!entry.collections && "pr-5",
|
||||
)}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"relative mt-0.5 whitespace-pre-line text-base",
|
||||
!!entry.collections && "pr-5",
|
||||
"rounded-xl p-3 align-middle text-[15px]",
|
||||
"rounded-tl-none bg-zinc-600/5 dark:bg-zinc-500/20",
|
||||
"mt-1 -translate-x-3",
|
||||
)}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"rounded-xl p-3 align-middle text-[15px]",
|
||||
"rounded-tl-none bg-zinc-600/5 dark:bg-zinc-500/20",
|
||||
"mt-1 -translate-x-3",
|
||||
)}
|
||||
>
|
||||
{entry.entries.description}
|
||||
{entry.entries.description}
|
||||
|
||||
{!!entry.entries.media?.length && (
|
||||
<div className="mt-1 flex w-full gap-2 overflow-x-auto">
|
||||
{entry.entries.media.map((media, i, mediaList) => (
|
||||
<Media
|
||||
key={media.url}
|
||||
src={media.url}
|
||||
type={media.type}
|
||||
previewImageUrl={media.preview_image_url}
|
||||
className="size-28 shrink-0 cursor-zoom-in"
|
||||
loading="lazy"
|
||||
proxy={{
|
||||
width: 224,
|
||||
height: 224,
|
||||
}}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
previewMedia(mediaList, i)
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{!!entry.collections && <StarIcon />}
|
||||
{!!entry.entries.media?.length && (
|
||||
<div className="mt-1 flex w-full gap-2 overflow-x-auto">
|
||||
{entry.entries.media.map((media, i, mediaList) => (
|
||||
<Media
|
||||
key={media.url}
|
||||
src={media.url}
|
||||
type={media.type}
|
||||
previewImageUrl={media.preview_image_url}
|
||||
className="size-28 shrink-0 cursor-zoom-in"
|
||||
loading="lazy"
|
||||
proxy={{
|
||||
width: 224,
|
||||
height: 224,
|
||||
}}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
previewMedia(mediaList, i)
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* End right column */}
|
||||
{!!entry.collections && <StarIcon />}
|
||||
</div>
|
||||
|
||||
{/* End right column */}
|
||||
</div>
|
||||
</m.div>
|
||||
</>
|
||||
</div>
|
||||
</m.div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import { CopyButton } from "~/components/ui/code-highlighter"
|
||||
import { Form, FormItem, FormLabel } from "~/components/ui/form"
|
||||
import { Input } from "~/components/ui/input"
|
||||
import { Markdown } from "~/components/ui/markdown"
|
||||
import { useCurrentModal, useModalStack } from "~/components/ui/modal"
|
||||
import { useCurrentModal, useIsTopModal, useModalStack } from "~/components/ui/modal"
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
@@ -226,12 +226,13 @@ export const DiscoverFeedForm = ({
|
||||
)
|
||||
|
||||
const formElRef = useRef<HTMLFormElement>(null)
|
||||
|
||||
const isTop = useIsTopModal()
|
||||
useLayoutEffect(() => {
|
||||
if (!isTop) return
|
||||
const $form = formElRef.current
|
||||
if (!$form) return
|
||||
$form.querySelectorAll("input")[0]?.focus()
|
||||
}, [formElRef])
|
||||
}, [formElRef, isTop])
|
||||
|
||||
const modal = useCurrentModal()
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import { FeedViewType } from "~/lib/enum"
|
||||
import { getFetchErrorMessage, toastFetchError } from "~/lib/error-parser"
|
||||
import { getNewIssueUrl } from "~/lib/issues"
|
||||
import { cn } from "~/lib/utils"
|
||||
import type { FeedModel } from "~/models"
|
||||
import type { EntryModelSimple, FeedModel } from "~/models"
|
||||
import { feed as feedQuery, useFeed } from "~/queries/feed"
|
||||
import { subscription as subscriptionQuery } from "~/queries/subscriptions"
|
||||
import { useFeedByIdOrUrl } from "~/store/feed"
|
||||
@@ -95,6 +95,7 @@ export const FeedForm: Component<{
|
||||
asWidget,
|
||||
onSuccess,
|
||||
subscriptionData: feedQuery.data?.subscription,
|
||||
entries: feedQuery.data?.entries,
|
||||
feed,
|
||||
}}
|
||||
/>
|
||||
@@ -166,6 +167,7 @@ const FeedInnerForm = ({
|
||||
onSuccess,
|
||||
subscriptionData,
|
||||
feed,
|
||||
entries,
|
||||
}: {
|
||||
defaultValues?: z.infer<typeof formSchema>
|
||||
id?: string
|
||||
@@ -178,6 +180,7 @@ const FeedInnerForm = ({
|
||||
title?: string | null
|
||||
}
|
||||
feed: FeedModel
|
||||
entries?: EntryModelSimple[]
|
||||
}) => {
|
||||
const subscription = useSubscriptionByFeedId(id || "") || subscriptionData
|
||||
const isSubscribed = !!subscription
|
||||
@@ -259,10 +262,12 @@ const FeedInnerForm = ({
|
||||
|
||||
const suggestions = useMemo(
|
||||
() =>
|
||||
categories.data?.map((i) => ({
|
||||
name: i,
|
||||
value: i,
|
||||
})) || [],
|
||||
(
|
||||
categories.data?.map((i) => ({
|
||||
name: i,
|
||||
value: i,
|
||||
})) || []
|
||||
).sort((a, b) => a.name.localeCompare(b.name)),
|
||||
[categories.data],
|
||||
)
|
||||
|
||||
@@ -275,18 +280,6 @@ const FeedInnerForm = ({
|
||||
</Card>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="flex flex-1 flex-col gap-y-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="view"
|
||||
render={() => (
|
||||
<FormItem>
|
||||
<FormLabel>{t("feed_form.view")}</FormLabel>
|
||||
|
||||
<ViewSelectorRadioGroup {...form.register("view")} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="title"
|
||||
@@ -316,7 +309,6 @@ const FeedInnerForm = ({
|
||||
<div>
|
||||
<Autocomplete
|
||||
maxHeight={window.innerHeight < 600 ? 120 : 240}
|
||||
portal
|
||||
suggestions={suggestions}
|
||||
{...(field as any)}
|
||||
onSuggestionSelected={(suggestion) => {
|
||||
@@ -352,7 +344,24 @@ const FeedInnerForm = ({
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="flex flex-1 items-end justify-end gap-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="view"
|
||||
render={() => (
|
||||
<FormItem className="mb-16">
|
||||
<FormLabel>{t("feed_form.view")}</FormLabel>
|
||||
|
||||
<ViewSelectorRadioGroup
|
||||
{...form.register("view")}
|
||||
entries={entries}
|
||||
feed={feed}
|
||||
view={Number(form.getValues("view"))}
|
||||
/>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="absolute inset-x-0 bottom-0 flex flex-1 items-end justify-end gap-4 bg-theme-background p-4">
|
||||
{isSubscribed && (
|
||||
<Button
|
||||
type="button"
|
||||
|
||||
@@ -196,7 +196,7 @@ export function DiscoverForm({ type = "search" }: { type?: string }) {
|
||||
<Form {...form}>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(onSubmit)}
|
||||
className="w-[512px] space-y-8"
|
||||
className="w-[540px] space-y-8"
|
||||
data-testid="discover-form"
|
||||
>
|
||||
<FormField
|
||||
|
||||
@@ -100,7 +100,7 @@ export function DiscoverImport() {
|
||||
return (
|
||||
<>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="w-[512px] space-y-8">
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="w-[540px] space-y-8">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="file"
|
||||
|
||||
@@ -195,7 +195,7 @@ const ConfirmDestroyModalContent = ({ id, onSuccess }: { id: string; onSuccess:
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="w-[512px]">
|
||||
<div className="w-[540px]">
|
||||
<div className="mb-4">
|
||||
<i className="i-mingcute-warning-fill -mb-1 mr-1 size-5 text-red-500" />
|
||||
{t("discover.inbox_destroy_warning")}
|
||||
|
||||
@@ -29,7 +29,7 @@ export function DiscoverRSS3() {
|
||||
return (
|
||||
<>
|
||||
{data?.rss3.routes && (
|
||||
<div className="w-[512px]">
|
||||
<div className="w-[540px]">
|
||||
<DiscoverFeedForm
|
||||
routePrefix="rss3"
|
||||
route={data.rss3.routes[Object.keys(data.rss3.routes)[0]]}
|
||||
|
||||
@@ -37,6 +37,11 @@ const transformRouteParams: RouteParams = {
|
||||
description: "The attributes of pubDate element as pubDate",
|
||||
default: "Element html",
|
||||
},
|
||||
itemContent: {
|
||||
description:
|
||||
"The HTML elements as description in item using CSS selector ( in itemLink page for full content )",
|
||||
},
|
||||
encoding: { description: "The encoding of the HTML content", default: "utf-8" },
|
||||
}
|
||||
|
||||
export function DiscoverTransform() {
|
||||
@@ -62,7 +67,7 @@ export function DiscoverTransform() {
|
||||
return (
|
||||
<>
|
||||
{data?.rsshub.routes && (
|
||||
<div className="w-[512px]">
|
||||
<div className="w-[540px]">
|
||||
<DiscoverFeedForm
|
||||
routePrefix="rsshub"
|
||||
route={data?.rsshub.routes["/transform/html/:url/:routeParams"]}
|
||||
|
||||
@@ -27,7 +27,7 @@ export function DiscoverUser() {
|
||||
return (
|
||||
<>
|
||||
{data?.follow.routes && (
|
||||
<div className="w-[512px]">
|
||||
<div className="w-[540px]">
|
||||
<DiscoverFeedForm
|
||||
routePrefix="follow"
|
||||
route={data.follow.routes[Object.keys(data.follow.routes)[0]]}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { FeedIcon } from "~/components/feed-icon"
|
||||
import { RelativeTime } from "~/components/ui/datetime"
|
||||
import { Media } from "~/components/ui/media"
|
||||
import { Skeleton } from "~/components/ui/skeleton"
|
||||
import { ListItem } from "~/modules/entry-column/templates/list-item-template"
|
||||
|
||||
import type { UniversalItemProps } from "../types"
|
||||
import type { EntryItemStatelessProps, UniversalItemProps } from "../types"
|
||||
|
||||
export function ArticleItem({ entryId, entryPreview, translation }: UniversalItemProps) {
|
||||
return (
|
||||
@@ -9,6 +12,49 @@ export function ArticleItem({ entryId, entryPreview, translation }: UniversalIte
|
||||
)
|
||||
}
|
||||
|
||||
export function ArticleItemStateLess({ entry, feed }: EntryItemStatelessProps) {
|
||||
return (
|
||||
<div className="relative rounded-md text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
<div className="group relative flex py-4 pl-3 pr-2">
|
||||
<FeedIcon className="mr-2 size-5 rounded-sm" feed={feed} fallback />
|
||||
<div className="-mt-0.5 line-clamp-4 flex-1 text-sm leading-tight">
|
||||
<div className="flex gap-1 text-[10px] font-bold text-zinc-400 dark:text-neutral-500">
|
||||
<span>{feed.title}</span>
|
||||
<span>·</span>
|
||||
<span>{!!entry.publishedAt && <RelativeTime date={entry.publishedAt} />}</span>
|
||||
</div>
|
||||
<div className="relative my-1 break-words font-medium">{entry.title}</div>
|
||||
<div className="mt-1.5 text-[13px] text-zinc-400 dark:text-neutral-500">
|
||||
{entry.description}
|
||||
</div>
|
||||
</div>
|
||||
{entry.media?.[0] ? (
|
||||
<Media
|
||||
thumbnail
|
||||
src={entry.media[0].url}
|
||||
type={entry.media[0].type}
|
||||
previewImageUrl={entry.media[0].preview_image_url}
|
||||
className="ml-2 size-20 overflow-hidden rounded"
|
||||
mediaContainerClassName={"w-auto h-auto rounded"}
|
||||
loading="lazy"
|
||||
proxy={{
|
||||
width: 160,
|
||||
height: 160,
|
||||
}}
|
||||
height={entry.media[0].height}
|
||||
width={entry.media[0].width}
|
||||
blurhash={entry.media[0].blurhash}
|
||||
/>
|
||||
) : (
|
||||
<Skeleton className="ml-2 size-20 overflow-hidden rounded" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const ArticleItemSkeleton = (
|
||||
<div className="relative h-[120px] rounded-md bg-theme-background text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { RelativeTime } from "~/components/ui/datetime"
|
||||
import { Media } from "~/components/ui/media"
|
||||
import { Skeleton } from "~/components/ui/skeleton"
|
||||
import { ListItem } from "~/modules/entry-column/templates/list-item-template"
|
||||
|
||||
import type { UniversalItemProps } from "../types"
|
||||
import type { EntryItemStatelessProps, UniversalItemProps } from "../types"
|
||||
|
||||
export function AudioItem({ entryId, entryPreview, translation }: UniversalItemProps) {
|
||||
return (
|
||||
@@ -9,6 +11,49 @@ export function AudioItem({ entryId, entryPreview, translation }: UniversalItemP
|
||||
)
|
||||
}
|
||||
|
||||
export function AudioItemStateLess({ entry, feed }: EntryItemStatelessProps) {
|
||||
return (
|
||||
<div className="relative mx-auto w-full max-w-lg rounded-md bg-theme-background text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
<div className="group relative flex py-4 pl-3 pr-2">
|
||||
<div className="-mt-0.5 line-clamp-4 flex-1 text-sm leading-tight">
|
||||
<div className="flex gap-1 text-[10px] font-bold text-zinc-400 dark:text-neutral-500">
|
||||
<span>{feed.title}</span>
|
||||
<span>·</span>
|
||||
<span>{!!entry.publishedAt && <RelativeTime date={entry.publishedAt} />}</span>
|
||||
</div>
|
||||
<div className="relative my-0.5 line-clamp-3 break-words font-medium">
|
||||
{entry.description}
|
||||
</div>
|
||||
</div>
|
||||
<div className="relative ml-2 size-20 shrink-0">
|
||||
{entry.media?.[0] ? (
|
||||
<Media
|
||||
thumbnail
|
||||
src={entry.media[0].url}
|
||||
type={entry.media[0].type}
|
||||
previewImageUrl={entry.media[0].preview_image_url}
|
||||
className="mr-2 size-20 shrink-0 overflow-hidden rounded-sm"
|
||||
mediaContainerClassName={"w-auto h-auto rounded"}
|
||||
loading="lazy"
|
||||
proxy={{
|
||||
width: 160,
|
||||
height: 160,
|
||||
}}
|
||||
height={entry.media[0].height}
|
||||
width={entry.media[0].width}
|
||||
blurhash={entry.media[0].blurhash}
|
||||
/>
|
||||
) : (
|
||||
<Skeleton className="mr-2 size-20 shrink-0 overflow-hidden rounded-sm " />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const AudioItemSkeleton = (
|
||||
<div className="relative mx-auto w-full max-w-lg rounded-md bg-theme-background text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
import { FeedViewType } from "~/lib/enum"
|
||||
|
||||
import { ArticleItem, ArticleItemSkeleton } from "./article-item"
|
||||
import { AudioItem, AudioItemSkeleton } from "./audio-item"
|
||||
import { NotificationItem, NotificationItemSkeleton } from "./notification-item"
|
||||
import { PictureItem, PictureItemSkeleton } from "./picture-item"
|
||||
import { SocialMediaItem, SocialMediaItemSkeleton } from "./social-media-item"
|
||||
import { VideoItem, VideoItemSkeleton } from "./video-item"
|
||||
import { ArticleItem, ArticleItemSkeleton, ArticleItemStateLess } from "./article-item"
|
||||
import { AudioItem, AudioItemSkeleton, AudioItemStateLess } from "./audio-item"
|
||||
import {
|
||||
NotificationItem,
|
||||
NotificationItemSkeleton,
|
||||
NotificationItemStateLess,
|
||||
} from "./notification-item"
|
||||
import { PictureItem, PictureItemSkeleton, PictureItemStateLess } from "./picture-item"
|
||||
import {
|
||||
SocialMediaItem,
|
||||
SocialMediaItemSkeleton,
|
||||
SocialMediaItemStateLess,
|
||||
} from "./social-media-item"
|
||||
import { VideoItem, VideoItemSkeleton, VideoItemStateLess } from "./video-item"
|
||||
|
||||
const ItemMap = {
|
||||
[FeedViewType.Articles]: ArticleItem,
|
||||
@@ -19,6 +27,19 @@ export const getItemComponentByView = (view: FeedViewType) => {
|
||||
return ItemMap[view] || ArticleItem
|
||||
}
|
||||
|
||||
const StatelessItemMap = {
|
||||
[FeedViewType.Articles]: ArticleItemStateLess,
|
||||
[FeedViewType.SocialMedia]: SocialMediaItemStateLess,
|
||||
[FeedViewType.Pictures]: PictureItemStateLess,
|
||||
[FeedViewType.Videos]: VideoItemStateLess,
|
||||
[FeedViewType.Audios]: AudioItemStateLess,
|
||||
[FeedViewType.Notifications]: NotificationItemStateLess,
|
||||
}
|
||||
|
||||
export const getStatelessItemComponentByView = (view: FeedViewType) => {
|
||||
return StatelessItemMap[view] || ArticleItemStateLess
|
||||
}
|
||||
|
||||
const SkeletonItemMap = {
|
||||
[FeedViewType.Articles]: ArticleItemSkeleton,
|
||||
[FeedViewType.SocialMedia]: SocialMediaItemSkeleton,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { FeedIcon } from "~/components/feed-icon"
|
||||
import { RelativeTime } from "~/components/ui/datetime"
|
||||
import { Skeleton } from "~/components/ui/skeleton"
|
||||
import { ListItem } from "~/modules/entry-column/templates/list-item-template"
|
||||
|
||||
import type { UniversalItemProps } from "../types"
|
||||
import type { EntryItemStatelessProps, UniversalItemProps } from "../types"
|
||||
|
||||
export function NotificationItem({ entryId, entryPreview, translation }: UniversalItemProps) {
|
||||
return (
|
||||
@@ -9,6 +11,25 @@ export function NotificationItem({ entryId, entryPreview, translation }: Univers
|
||||
)
|
||||
}
|
||||
|
||||
export function NotificationItemStateLess({ entry, feed }: EntryItemStatelessProps) {
|
||||
return (
|
||||
<div className="relative mx-auto w-full max-w-lg">
|
||||
<div className="group relative flex py-4 pl-3 pr-2">
|
||||
<FeedIcon feed={feed} fallback />
|
||||
|
||||
<div className="-mt-0.5 line-clamp-4 flex-1 text-sm leading-tight">
|
||||
<div className="flex gap-1 text-[10px] font-bold text-zinc-400 dark:text-neutral-500">
|
||||
<span>{feed.title}</span>
|
||||
<span>·</span>
|
||||
<span>{!!entry.publishedAt && <RelativeTime date={entry.publishedAt} />}</span>
|
||||
</div>
|
||||
<div className="relative my-0.5 break-words">{entry.title}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const NotificationItemSkeleton = (
|
||||
<div className="relative mx-auto w-full max-w-lg">
|
||||
<div className="group relative flex py-4 pl-3 pr-2">
|
||||
|
||||
@@ -3,6 +3,9 @@ import type { PropsWithChildren } from "react"
|
||||
import { memo, useContext, useEffect, useMemo, useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { FeedIcon } from "~/components/feed-icon"
|
||||
import { RelativeTime } from "~/components/ui/datetime"
|
||||
import { Media } from "~/components/ui/media"
|
||||
import { SwipeMedia } from "~/components/ui/media/SwipeMedia"
|
||||
import { ReactVirtuosoItemPlaceholder } from "~/components/ui/placeholder"
|
||||
import { Skeleton } from "~/components/ui/skeleton"
|
||||
@@ -15,7 +18,7 @@ import { useImageDimensions } from "~/store/image"
|
||||
import { usePreviewMedia } from "../../../components/ui/media/hooks"
|
||||
import { EntryItemWrapper } from "../layouts/EntryItemWrapper"
|
||||
import { GridItem, GridItemFooter } from "../templates/grid-item-template"
|
||||
import type { UniversalItemProps } from "../types"
|
||||
import type { EntryItemStatelessProps, UniversalItemProps } from "../types"
|
||||
import {
|
||||
MasonryIntersectionContext,
|
||||
useMasonryItemRatio,
|
||||
@@ -195,6 +198,57 @@ const MasonryItemFixedDimensionWrapper = (
|
||||
)
|
||||
}
|
||||
|
||||
export function PictureItemStateLess({ entry, feed }: EntryItemStatelessProps) {
|
||||
return (
|
||||
<div className="relative mx-auto max-w-md rounded-md bg-theme-background text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
<div className="p-1.5">
|
||||
<div className="relative flex gap-2 overflow-x-auto">
|
||||
<div
|
||||
className={cn(
|
||||
"relative flex w-full shrink-0 items-center overflow-hidden rounded-md",
|
||||
!entry.media?.[0].url && "aspect-square",
|
||||
)}
|
||||
>
|
||||
{entry.media?.[0] ? (
|
||||
<Media
|
||||
thumbnail
|
||||
src={entry.media[0].url}
|
||||
type={entry.media[0].type}
|
||||
previewImageUrl={entry.media[0].preview_image_url}
|
||||
className="size-full overflow-hidden"
|
||||
mediaContainerClassName={"w-auto h-auto rounded"}
|
||||
loading="lazy"
|
||||
proxy={{
|
||||
width: 0,
|
||||
height: 0,
|
||||
}}
|
||||
height={entry.media[0].height}
|
||||
width={entry.media[0].width}
|
||||
blurhash={entry.media[0].blurhash}
|
||||
/>
|
||||
) : (
|
||||
<Skeleton className="size-full overflow-hidden" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="relative flex-1 px-2 pb-3 pt-1 text-sm">
|
||||
<div className="relative mb-1 mt-1.5 truncate font-medium leading-none">
|
||||
{entry.title}
|
||||
</div>
|
||||
<div className="mt-1 flex items-center gap-1 truncate text-[13px]">
|
||||
<FeedIcon feed={feed} fallback className="size-4" />
|
||||
<span>{feed.title}</span>
|
||||
<span className="text-zinc-500">·</span>
|
||||
{!!entry.publishedAt && <RelativeTime date={entry.publishedAt} />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const PictureItemSkeleton = (
|
||||
<div className="relative max-w-md rounded-md bg-theme-background text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
|
||||
@@ -21,7 +21,7 @@ import { useFeedById } from "~/store/feed"
|
||||
import { ReactVirtuosoItemPlaceholder } from "../../../components/ui/placeholder"
|
||||
import { StarIcon } from "../star-icon"
|
||||
import { EntryTranslation } from "../translation"
|
||||
import type { EntryListItemFC } from "../types"
|
||||
import type { EntryItemStatelessProps, EntryListItemFC } from "../types"
|
||||
|
||||
const socialMediaContentWidthAtom = atom(0)
|
||||
export const SocialMediaItem: EntryListItemFC = ({ entryId, entryPreview, translation }) => {
|
||||
@@ -200,6 +200,49 @@ const ActionBar = ({ entryId }: { entryId: string }) => {
|
||||
)
|
||||
}
|
||||
|
||||
export function SocialMediaItemStateLess({ entry, feed }: EntryItemStatelessProps) {
|
||||
return (
|
||||
<div className="relative m-auto rounded-md text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
<div className="group relative flex px-8 py-6">
|
||||
<FeedIcon className="mr-2 size-9" feed={feed} fallback />
|
||||
<div className="ml-2 min-w-0 flex-1">
|
||||
<div className="-mt-0.5 line-clamp-5 flex-1 text-sm">
|
||||
<div className="flex space-x-1">
|
||||
<span>{feed.title}</span>
|
||||
<span className="text-zinc-500">·</span>
|
||||
<span>{!!entry.publishedAt && <RelativeTime date={entry.publishedAt} />}</span>
|
||||
</div>
|
||||
<div className="relative mt-0.5 text-sm">{entry.description}</div>
|
||||
</div>
|
||||
<div className="mt-2 flex gap-2 overflow-x-auto">
|
||||
{entry.media?.map((media) => (
|
||||
<Media
|
||||
key={media.url}
|
||||
thumbnail
|
||||
src={media.url}
|
||||
type={media.type}
|
||||
previewImageUrl={media.preview_image_url}
|
||||
className="size-28 overflow-hidden rounded"
|
||||
mediaContainerClassName={"w-auto h-auto rounded"}
|
||||
loading="lazy"
|
||||
proxy={{
|
||||
width: 160,
|
||||
height: 160,
|
||||
}}
|
||||
height={media.height}
|
||||
width={media.width}
|
||||
blurhash={media.blurhash}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const SocialMediaItemSkeleton = (
|
||||
<div className="relative m-auto w-[645px] rounded-md bg-theme-background text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
@@ -212,7 +255,7 @@ export const SocialMediaItemSkeleton = (
|
||||
<span className="text-zinc-500">·</span>
|
||||
<Skeleton className="h-4 w-12 " />
|
||||
</div>
|
||||
<div className="relative mt-0.5 whitespace-pre-line text-base">
|
||||
<div className="relative mt-0.5 text-sm">
|
||||
<Skeleton className="h-4 w-full " />
|
||||
<Skeleton className="mt-1.5 h-4 w-full " />
|
||||
<Skeleton className="mt-1.5 h-4 w-3/4 " />
|
||||
|
||||
@@ -4,6 +4,8 @@ import { useEffect, useMemo, useRef, useState } from "react"
|
||||
|
||||
import { AudioPlayer } from "~/atoms/player"
|
||||
import { m } from "~/components/common/Motion"
|
||||
import { FeedIcon } from "~/components/feed-icon"
|
||||
import { RelativeTime } from "~/components/ui/datetime"
|
||||
import { Media } from "~/components/ui/media"
|
||||
import type { ModalContentComponent } from "~/components/ui/modal"
|
||||
import { useModalStack } from "~/components/ui/modal"
|
||||
@@ -16,7 +18,7 @@ import { useEntry } from "~/store/entry/hooks"
|
||||
|
||||
import { ReactVirtuosoItemPlaceholder } from "../../../components/ui/placeholder"
|
||||
import { GridItem } from "../templates/grid-item-template"
|
||||
import type { UniversalItemProps } from "../types"
|
||||
import type { EntryItemStatelessProps, UniversalItemProps } from "../types"
|
||||
|
||||
const ViewTag = IN_ELECTRON ? "webview" : "iframe"
|
||||
|
||||
@@ -132,6 +134,52 @@ const PreviewVideoModalContent: ModalContentComponent<{
|
||||
)
|
||||
}
|
||||
|
||||
export function VideoItemStateLess({ entry, feed }: EntryItemStatelessProps) {
|
||||
return (
|
||||
<div className="relative mx-auto w-full max-w-lg rounded-md bg-theme-background text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
<div className="p-1.5">
|
||||
<div className="w-full">
|
||||
<div className="overflow-x-auto">
|
||||
{entry.media?.[0] ? (
|
||||
<Media
|
||||
thumbnail
|
||||
src={entry.media[0].url}
|
||||
type={entry.media[0].type}
|
||||
previewImageUrl={entry.media[0].preview_image_url}
|
||||
className="aspect-video w-full shrink-0 overflow-hidden"
|
||||
mediaContainerClassName={"w-auto h-auto rounded"}
|
||||
loading="lazy"
|
||||
proxy={{
|
||||
width: 0,
|
||||
height: 0,
|
||||
}}
|
||||
height={entry.media[0].height}
|
||||
width={entry.media[0].width}
|
||||
blurhash={entry.media[0].blurhash}
|
||||
/>
|
||||
) : (
|
||||
<Skeleton className="aspect-video w-full shrink-0 overflow-hidden" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="relative flex-1 px-2 pb-3 pt-1 text-sm">
|
||||
<div className="relative mb-1 mt-1.5 truncate font-medium leading-none">
|
||||
{entry.title}
|
||||
</div>
|
||||
<div className="mt-1 flex items-center gap-1 truncate text-[13px]">
|
||||
<FeedIcon feed={feed} fallback className="size-4" />
|
||||
<span>{feed.title}</span>
|
||||
<span className="text-zinc-500">·</span>
|
||||
{!!entry.publishedAt && <RelativeTime date={entry.publishedAt} />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const VideoItemSkeleton = (
|
||||
<div className="relative mx-auto w-full max-w-lg rounded-md bg-theme-background text-zinc-700 transition-colors dark:text-neutral-400">
|
||||
<div className="relative">
|
||||
|
||||
@@ -6,10 +6,11 @@ import { Trans, useTranslation } from "react-i18next"
|
||||
import { toast } from "sonner"
|
||||
import { useOnClickOutside } from "usehooks-ts"
|
||||
|
||||
import { useViewport } from "~/atoms/hooks/viewport"
|
||||
import { ActionButton, Button, IconButton } from "~/components/ui/button"
|
||||
import { Kbd, KbdCombined } from "~/components/ui/kbd/Kbd"
|
||||
import { RootPortal } from "~/components/ui/portal"
|
||||
import { ElECTRON_CUSTOM_TITLEBAR_HEIGHT, HotKeyScopeMap, isElectronBuild } from "~/constants"
|
||||
import { HotKeyScopeMap, isElectronBuild } from "~/constants"
|
||||
import { shortcuts } from "~/constants/shortcuts"
|
||||
import { useI18n } from "~/hooks/common"
|
||||
import { cn, getOS } from "~/lib/utils"
|
||||
@@ -21,7 +22,6 @@ interface MarkAllButtonProps {
|
||||
filter?: MarkAllFilter
|
||||
className?: string
|
||||
which?: ReactNode
|
||||
|
||||
shortcut?: boolean
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ export const MarkAllReadWithOverlay = forwardRef<
|
||||
containerRef: React.RefObject<HTMLDivElement>
|
||||
}
|
||||
>(({ filter, className, which = "all", shortcut, containerRef }, ref) => {
|
||||
const { t } = useTranslation()
|
||||
const { t: commonT } = useTranslation("common")
|
||||
|
||||
const [show, setShow] = useState(false)
|
||||
@@ -42,55 +41,7 @@ export const MarkAllReadWithOverlay = forwardRef<
|
||||
useOnClickOutside({ current: popoverRef }, () => {
|
||||
setShow(false)
|
||||
})
|
||||
const renderPopup = () => {
|
||||
const $parent = containerRef.current!
|
||||
const rect = $parent.getBoundingClientRect()
|
||||
const paddingLeft = $parent.offsetLeft
|
||||
return (
|
||||
<RootPortal to={$parent}>
|
||||
<m.div
|
||||
ref={setPopoverRef}
|
||||
initial={{ y: -70 }}
|
||||
animate={{
|
||||
y: isElectronBuild && getOS() === "Windows" ? -ElECTRON_CUSTOM_TITLEBAR_HEIGHT : 0,
|
||||
}}
|
||||
exit={{ y: -70 }}
|
||||
transition={{ type: "spring", damping: 20, stiffness: 300 }}
|
||||
className="shadow-modal absolute z-50 bg-theme-modal-background-opaque shadow"
|
||||
style={{
|
||||
left: -paddingLeft,
|
||||
top: rect.top,
|
||||
width: rect.width,
|
||||
}}
|
||||
>
|
||||
<div className="flex w-full translate-x-[-2px] items-center justify-between gap-3 !py-3 pl-6 pr-3 [&_button]:text-xs">
|
||||
<span className="center gap-[calc(0.5rem+2px)]">
|
||||
<i className="i-mgc-check-circle-cute-re" />
|
||||
<span className="text-sm font-bold">
|
||||
<Trans
|
||||
i18nKey="mark_all_read_button.confirm_mark_all"
|
||||
components={{
|
||||
which: commonT(`words.which.${which}` as any),
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
</span>
|
||||
<div className="space-x-4">
|
||||
<IconButton
|
||||
icon={<i className="i-mgc-check-filled" />}
|
||||
onClick={() => {
|
||||
handleMarkAllAsRead()
|
||||
setShow(false)
|
||||
}}
|
||||
>
|
||||
{t("words.confirm")}
|
||||
</IconButton>
|
||||
</div>
|
||||
</div>
|
||||
</m.div>
|
||||
</RootPortal>
|
||||
)
|
||||
}
|
||||
|
||||
useHotkeys(
|
||||
shortcuts.entries.markAllAsRead.key,
|
||||
() => {
|
||||
@@ -156,11 +107,83 @@ export const MarkAllReadWithOverlay = forwardRef<
|
||||
<i className="i-mgc-check-circle-cute-re" />
|
||||
</ActionButton>
|
||||
|
||||
<AnimatePresence>{show && renderPopup()}</AnimatePresence>
|
||||
<AnimatePresence>
|
||||
{show && (
|
||||
<Popup
|
||||
which={which}
|
||||
containerRef={containerRef}
|
||||
setPopoverRef={setPopoverRef}
|
||||
setShow={setShow}
|
||||
handleMarkAllAsRead={handleMarkAllAsRead}
|
||||
/>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</Fragment>
|
||||
)
|
||||
})
|
||||
|
||||
const Popup = ({ which, containerRef, setPopoverRef, setShow, handleMarkAllAsRead }) => {
|
||||
const { t } = useTranslation()
|
||||
const { t: commonT } = useTranslation("common")
|
||||
const $parent = containerRef.current!
|
||||
const rect = $parent.getBoundingClientRect()
|
||||
const paddingLeft = $parent.offsetLeft
|
||||
|
||||
// change popup's width when viewport changes.
|
||||
useViewport((v) => v.w)
|
||||
|
||||
// electron window has pt-[calc(var(--fo-window-padding-top)_-10px)]
|
||||
const isElectronWindows = isElectronBuild && getOS() === "Windows"
|
||||
return (
|
||||
<RootPortal to={$parent}>
|
||||
<m.div
|
||||
ref={setPopoverRef}
|
||||
initial={{
|
||||
y: isElectronWindows ? -95 : -70,
|
||||
}}
|
||||
animate={{
|
||||
y: isElectronWindows ? -10 : 0,
|
||||
}}
|
||||
exit={{
|
||||
y: isElectronWindows ? -95 : -70,
|
||||
}}
|
||||
transition={{ type: "spring", damping: 20, stiffness: 300 }}
|
||||
className="shadow-modal absolute z-50 bg-theme-modal-background-opaque shadow"
|
||||
style={{
|
||||
left: -paddingLeft,
|
||||
top: rect.top,
|
||||
width: rect.width,
|
||||
}}
|
||||
>
|
||||
<div className="flex w-full translate-x-[-2px] items-center justify-between gap-3 !py-3 pl-6 pr-3 [&_button]:text-xs">
|
||||
<span className="center gap-[calc(0.5rem+2px)]">
|
||||
<i className="i-mgc-check-circle-cute-re" />
|
||||
<span className="text-sm font-bold">
|
||||
<Trans
|
||||
i18nKey="mark_all_read_button.confirm_mark_all"
|
||||
components={{
|
||||
which: commonT(`words.which.${which}` as any),
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
</span>
|
||||
<div className="space-x-4">
|
||||
<IconButton
|
||||
icon={<i className="i-mgc-check-filled" />}
|
||||
onClick={() => {
|
||||
handleMarkAllAsRead()
|
||||
setShow(false)
|
||||
}}
|
||||
>
|
||||
{t("words.confirm")}
|
||||
</IconButton>
|
||||
</div>
|
||||
</div>
|
||||
</m.div>
|
||||
</RootPortal>
|
||||
)
|
||||
}
|
||||
|
||||
const ConfirmMarkAllReadInfo = ({ undo }: { undo: () => any }) => {
|
||||
const { t } = useTranslation()
|
||||
useHotkeys("ctrl+z,meta+z", undo, {
|
||||
|
||||
@@ -11,10 +11,14 @@ import type { FlatEntryModel } from "~/store/entry"
|
||||
import { useEntry } from "~/store/entry/hooks"
|
||||
|
||||
import { ReactVirtuosoItemPlaceholder } from "../../components/ui/placeholder"
|
||||
import { getItemComponentByView, getSkeletonItemComponentByView } from "./Items"
|
||||
import {
|
||||
getItemComponentByView,
|
||||
getSkeletonItemComponentByView,
|
||||
getStatelessItemComponentByView,
|
||||
} from "./Items"
|
||||
import { EntryItemWrapper } from "./layouts/EntryItemWrapper"
|
||||
import { girdClassNames } from "./styles"
|
||||
import type { EntryListItemFC } from "./types"
|
||||
import type { EntryItemStatelessProps, EntryListItemFC } from "./types"
|
||||
|
||||
interface EntryItemProps {
|
||||
entryId: string
|
||||
@@ -52,6 +56,12 @@ export const EntryItem: FC<EntryItemProps> = memo(({ entryId, view }) => {
|
||||
return <EntryItemImpl entry={entry} view={view} />
|
||||
})
|
||||
|
||||
export const EntryItemStateless: FC<EntryItemStatelessProps> = memo((props) => {
|
||||
const Item = getStatelessItemComponentByView(props.view as FeedViewType)
|
||||
|
||||
return <Item {...props} />
|
||||
})
|
||||
|
||||
const LoadingCircleFallback = (
|
||||
<div className="center mt-2">
|
||||
<LoadingCircle size="medium" />
|
||||
|
||||
@@ -46,12 +46,12 @@ export const EntryListHeader: FC<{
|
||||
|
||||
const titleInfo = !!headerTitle && (
|
||||
<div className={!titleAtBottom ? "min-w-0 translate-y-1" : void 0}>
|
||||
<div className="h-6 min-w-0 break-all text-lg font-bold leading-tight">
|
||||
<div className="mt-1 h-6 min-w-0 break-all text-lg font-bold leading-tight">
|
||||
<EllipsisHorizontalTextWithTooltip className="inline-block !w-auto max-w-full">
|
||||
<span className="relative -top-px">{headerTitle}</span>
|
||||
</EllipsisHorizontalTextWithTooltip>
|
||||
</div>
|
||||
<div className="text-xs font-medium leading-none text-zinc-400">
|
||||
<div className="whitespace-nowrap text-xs font-medium leading-none text-zinc-400">
|
||||
{totalCount || 0} {t("quantifier.piece", { ns: "common" })}
|
||||
{unreadOnly && !isInCollectionList ? t("words.unread") : ""}
|
||||
{t("space", { ns: "common" })}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { env } from "@follow/shared/env"
|
||||
import { useDebounceCallback } from "usehooks-ts"
|
||||
|
||||
import { AudioPlayer, useAudioPlayerAtomSelector } from "~/atoms/player"
|
||||
@@ -13,6 +12,7 @@ import { EllipsisHorizontalTextWithTooltip } from "~/components/ui/typography"
|
||||
import { FEED_COLLECTION_LIST } from "~/constants"
|
||||
import { useAsRead } from "~/hooks/biz/useAsRead"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { UrlBuilder } from "~/lib/url-builder"
|
||||
import { cn, isSafari } from "~/lib/utils"
|
||||
import { FeedForm } from "~/modules/discover/feed-form"
|
||||
import { EntryTranslation } from "~/modules/entry-column/translation"
|
||||
@@ -55,9 +55,10 @@ export function ListItem({
|
||||
{ leading: false },
|
||||
)
|
||||
|
||||
const isSubscription = withFollow && entry?.entries.url?.startsWith(`${env.VITE_WEB_URL}/feed/`)
|
||||
const isSubscription =
|
||||
withFollow && entry?.entries.url?.startsWith(UrlBuilder.shareFeed(entry.feedId))
|
||||
const feedId = isSubscription
|
||||
? entry?.entries.url?.replace(`${env.VITE_WEB_URL}/feed/`, "")
|
||||
? entry?.entries.url?.slice(UrlBuilder.shareFeed(entry.feedId).length)
|
||||
: undefined
|
||||
const isFollowed = !!useSubscriptionStore((state) => feedId && state.data[feedId])
|
||||
const { present } = useModalStack()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { FC } from "react"
|
||||
|
||||
import type { CombinedEntryModel, FeedOrListRespModel } from "~/models"
|
||||
import type { CombinedEntryModel, EntryModelSimple, FeedModel, FeedOrListRespModel } from "~/models"
|
||||
|
||||
export type UniversalItemProps = {
|
||||
entryId: string
|
||||
@@ -18,3 +18,9 @@ export type UniversalItemProps = {
|
||||
export type EntryListItemFC<P extends object = object> = FC<P & UniversalItemProps> & {
|
||||
wrapperClassName?: string
|
||||
}
|
||||
|
||||
export type EntryItemStatelessProps = {
|
||||
feed: FeedModel
|
||||
entry: EntryModelSimple
|
||||
view?: number
|
||||
}
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { AnimatePresence, m } from "framer-motion"
|
||||
import type { FC } from "react"
|
||||
import { Fragment, memo, useEffect, useRef, useState } from "react"
|
||||
import { Fragment, memo, useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useOnClickOutside } from "usehooks-ts"
|
||||
|
||||
import { MotionButtonBase } from "~/components/ui/button"
|
||||
import { LoadingCircle } from "~/components/ui/loading"
|
||||
import { useScrollViewElement } from "~/components/ui/scroll-area/hooks"
|
||||
import { ROUTE_FEED_IN_FOLDER, views } from "~/constants"
|
||||
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { getRouteParams, useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { useAnyPointDown, useInputComposition } from "~/hooks/common"
|
||||
import { useAnyPointDown, useInputComposition, useRefValue } from "~/hooks/common"
|
||||
import { stopPropagation } from "~/lib/dom"
|
||||
import type { FeedViewType } from "~/lib/enum"
|
||||
import type { NullableNativeMenuItem } from "~/lib/native-menu"
|
||||
import { showNativeMenu } from "~/lib/native-menu"
|
||||
import { cn, sortByAlphabet } from "~/lib/utils"
|
||||
import { getPreferredTitle, useAddFeedToFeedList, useFeedStore } from "~/store/feed"
|
||||
@@ -51,19 +53,30 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego
|
||||
const subscription = useSubscriptionByFeedId(ids[0])
|
||||
const folderName = subscription?.category || subscription.defaultCategory
|
||||
|
||||
const showCollapse = sortByUnreadFeedList.length > 1 || subscription?.category
|
||||
const showCollapse = sortByUnreadFeedList.length > 1 || !!subscription?.category
|
||||
|
||||
const [open, setOpen] = useState(() => {
|
||||
const open = useMemo(() => {
|
||||
if (!showCollapse) return true
|
||||
if (folderName && typeof categoryOpenStateData[folderName] === "boolean") {
|
||||
return categoryOpenStateData[folderName]
|
||||
}
|
||||
return false
|
||||
})
|
||||
}, [categoryOpenStateData, folderName, showCollapse])
|
||||
|
||||
const setOpen = useCallback(
|
||||
(next: boolean) => {
|
||||
if (view !== undefined && folderName) {
|
||||
subscriptionActions.changeCategoryOpenState(view, folderName, next)
|
||||
}
|
||||
},
|
||||
[folderName, view],
|
||||
)
|
||||
|
||||
const shouldOpen = useRouteParamsSelector(
|
||||
(s) => typeof s.feedId === "string" && ids.includes(s.feedId),
|
||||
)
|
||||
const scroller = useScrollViewElement()
|
||||
const scrollerRef = useRefValue(scroller)
|
||||
useEffect(() => {
|
||||
if (shouldOpen) {
|
||||
setOpen(true)
|
||||
@@ -71,19 +84,21 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego
|
||||
const $items = itemsRef.current
|
||||
|
||||
if (!$items) return
|
||||
$items.querySelector(`[data-feed-id="${getRouteParams().feedId}"]`)?.scrollIntoView({
|
||||
block: "center",
|
||||
const $target = $items.querySelector(
|
||||
`[data-feed-id="${getRouteParams().feedId}"]`,
|
||||
) as HTMLElement
|
||||
if (!$target) return
|
||||
|
||||
const $scroller = scrollerRef.current
|
||||
if (!$scroller) return
|
||||
|
||||
const scrollTop = $target.offsetTop - $scroller.clientHeight / 2
|
||||
$scroller.scrollTo({
|
||||
top: scrollTop,
|
||||
behavior: "smooth",
|
||||
})
|
||||
}
|
||||
}, [shouldOpen])
|
||||
const expansion = folderName ? categoryOpenStateData[folderName] : true
|
||||
|
||||
useEffect(() => {
|
||||
if (showCollapse) {
|
||||
setOpen(expansion)
|
||||
}
|
||||
}, [expansion])
|
||||
}, [scrollerRef, setOpen, shouldOpen])
|
||||
|
||||
const itemsRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
@@ -154,6 +169,7 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego
|
||||
}}
|
||||
onContextMenu={(e) => {
|
||||
setIsContextMenuOpen(true)
|
||||
|
||||
showNativeMenu(
|
||||
[
|
||||
{
|
||||
@@ -169,21 +185,23 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego
|
||||
{
|
||||
type: "text",
|
||||
label: t("sidebar.feed_column.context_menu.add_feeds_to_list"),
|
||||
// @ts-expect-error
|
||||
|
||||
submenu: listList
|
||||
?.map((list) => ({
|
||||
label: list.title || "",
|
||||
type: "text",
|
||||
click() {
|
||||
return addMutation.mutate({
|
||||
feedIds: ids,
|
||||
listId: list.id,
|
||||
})
|
||||
},
|
||||
}))
|
||||
?.map(
|
||||
(list) =>
|
||||
({
|
||||
label: list.title || "",
|
||||
type: "text",
|
||||
click() {
|
||||
return addMutation.mutate({
|
||||
feedIds: ids,
|
||||
listId: list.id,
|
||||
})
|
||||
},
|
||||
}) as NullableNativeMenuItem,
|
||||
)
|
||||
.concat(listList?.length > 0 ? [{ type: "separator" as const }] : [])
|
||||
.concat([
|
||||
// @ts-expect-error
|
||||
{ type: "separator" as const },
|
||||
{
|
||||
label: t("sidebar.feed_actions.create_list"),
|
||||
type: "text" as const,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { WEB_URL } from "@follow/shared/constants"
|
||||
import dayjs from "dayjs"
|
||||
import { memo, useCallback, useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
@@ -17,6 +16,7 @@ import { nextFrame } from "~/lib/dom"
|
||||
import type { FeedViewType } from "~/lib/enum"
|
||||
import { getNewIssueUrl } from "~/lib/issues"
|
||||
import { showNativeMenu } from "~/lib/native-menu"
|
||||
import { UrlBuilder } from "~/lib/url-builder"
|
||||
import { cn } from "~/lib/utils"
|
||||
import { getPreferredTitle, useFeedById } from "~/store/feed"
|
||||
import { useInboxById } from "~/store/inbox"
|
||||
@@ -82,7 +82,7 @@ const FeedItemImpl = ({ view, feedId, className }: FeedItemProps) => {
|
||||
)}
|
||||
onClick={handleNavigate}
|
||||
onDoubleClick={() => {
|
||||
window.open(`${WEB_URL}/feed/${feedId}?view=${view}`, "_blank")
|
||||
window.open(UrlBuilder.shareFeed(feedId, view), "_blank")
|
||||
}}
|
||||
onContextMenu={(e) => {
|
||||
setIsContextMenuOpen(true)
|
||||
@@ -215,7 +215,7 @@ const ListItemImpl: Component<{
|
||||
)}
|
||||
onClick={handleNavigate}
|
||||
onDoubleClick={() => {
|
||||
window.open(`${WEB_URL}/list/${listId}?view=${view}`, "_blank")
|
||||
window.open(UrlBuilder.shareList(listId, view), "_blank")
|
||||
}}
|
||||
onContextMenu={(e) => {
|
||||
setIsContextMenuOpen(true)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Fragment } from "react"
|
||||
|
||||
import { INBOX_PREFIX_ID } from "~/constants"
|
||||
import { sortByAlphabet } from "~/lib/utils"
|
||||
import { getPreferredTitle, useFeedStore } from "~/store/feed"
|
||||
import { getSubscriptionByFeedId } from "~/store/subscription"
|
||||
@@ -75,8 +76,14 @@ export const SortByAlphabeticalListList = ({ view, data }: ListListProps) => {
|
||||
export const SortByAlphabeticalInboxList = ({ view, data }: ListListProps) => {
|
||||
return (
|
||||
<div>
|
||||
{Object.keys(data).map((inboxId) => (
|
||||
<InboxItem key={inboxId} inboxId={inboxId} view={view} />
|
||||
{Object.keys(data).map((feedId) => (
|
||||
<InboxItem
|
||||
key={feedId}
|
||||
inboxId={
|
||||
feedId.startsWith(INBOX_PREFIX_ID) ? feedId.slice(INBOX_PREFIX_ID.length) : feedId
|
||||
}
|
||||
view={view}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -11,6 +11,7 @@ import { LoadMoreIndicator } from "~/components/common/LoadMoreIndicator"
|
||||
import { FeedIcon } from "~/components/feed-icon"
|
||||
import { EmptyIcon } from "~/components/icons/empty"
|
||||
import { Logo } from "~/components/icons/logo"
|
||||
import { useModalStack } from "~/components/ui/modal"
|
||||
import { ScrollArea } from "~/components/ui/scroll-area"
|
||||
import {
|
||||
Select,
|
||||
@@ -58,6 +59,8 @@ export const SearchCmdK: React.FC = () => {
|
||||
const dialogRef = React.useRef<HTMLDivElement>(null)
|
||||
const scrollViewRef = React.useRef<HTMLDivElement>(null)
|
||||
|
||||
const { getTopModalStack } = useModalStack()
|
||||
|
||||
React.useEffect(() => {
|
||||
const $input = inputRef.current
|
||||
if (open && $input) {
|
||||
@@ -71,7 +74,7 @@ export const SearchCmdK: React.FC = () => {
|
||||
(e) => {
|
||||
const $input = inputRef.current
|
||||
|
||||
if (e.key === "Escape" && !isCompositionRef.current) {
|
||||
if (e.key === "Escape" && !isCompositionRef.current && !getTopModalStack()) {
|
||||
setAppSearchOpen(false)
|
||||
return
|
||||
}
|
||||
@@ -82,7 +85,7 @@ export const SearchCmdK: React.FC = () => {
|
||||
$input?.focus()
|
||||
}
|
||||
},
|
||||
[isCompositionRef],
|
||||
[getTopModalStack, isCompositionRef],
|
||||
)
|
||||
const [isPending, startTransition] = React.useTransition()
|
||||
const handleSearch = React.useCallback(
|
||||
@@ -136,7 +139,6 @@ export const SearchCmdK: React.FC = () => {
|
||||
"flex min-h-[50vh] flex-col bg-zinc-50/85 shadow-2xl backdrop-blur-xl dark:bg-neutral-900/90 md:rounded-xl",
|
||||
"border-0 border-zinc-300 dark:border-zinc-700 md:border",
|
||||
"absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2",
|
||||
"z-10",
|
||||
)}
|
||||
>
|
||||
<Command.Input
|
||||
@@ -252,7 +254,7 @@ const SearchItem = memo(function Item({
|
||||
className={clsx(
|
||||
"relative flex w-full justify-between px-1 text-[0.9rem]",
|
||||
`before:absolute before:inset-0 before:rounded-md before:content-[""]`,
|
||||
"before:z-0 hover:before:bg-zinc-200/60 dark:hover:before:bg-zinc-800/80",
|
||||
"hover:before:bg-zinc-200/60 dark:hover:before:bg-zinc-800/80",
|
||||
"data-[selected=true]:before:bg-zinc-200/60 data-[selected=true]:dark:before:bg-zinc-800/80",
|
||||
"min-w-0 max-w-full",
|
||||
styles["content-visually"],
|
||||
@@ -267,7 +269,7 @@ const SearchItem = memo(function Item({
|
||||
})
|
||||
}}
|
||||
>
|
||||
<div className="relative z-10 flex w-full items-center justify-between px-1 py-2">
|
||||
<div className="relative flex w-full items-center justify-between px-1 py-2">
|
||||
{feed && <FeedIcon className="mr-2 size-5 shrink-0 rounded" feed={feed} />}
|
||||
<span className="block min-w-0 flex-1 shrink-0 truncate">{title}</span>
|
||||
<span className="block min-w-0 shrink-0 grow-0 text-xs font-medium text-zinc-800 opacity-60 dark:text-slate-200/80">
|
||||
|
||||
@@ -249,11 +249,12 @@ export const UserProfileModalContent: FC<{
|
||||
asChild
|
||||
src={replaceImgUrlIfNeed(userInfo.avatar || undefined)}
|
||||
>
|
||||
<m.img layout />
|
||||
<m.img layout transition={{ duration: 0.35 }} />
|
||||
</AvatarImage>
|
||||
<AvatarFallback>{userInfo.name?.slice(0, 2)}</AvatarFallback>
|
||||
</m.span>
|
||||
</Avatar>
|
||||
|
||||
<m.div
|
||||
layout
|
||||
transition={{ duration: 0.35 }}
|
||||
|
||||
@@ -12,7 +12,16 @@ function getSettings() {
|
||||
loader: () => SettingPageConfig
|
||||
}[]
|
||||
for (const path in map) {
|
||||
const p = path.split("/").pop()?.replace(".tsx", "").replace("(settings)", "")!
|
||||
const prefix = "(settings)"
|
||||
const postfix = ".tsx"
|
||||
const lastItem = path.split("/").pop()
|
||||
|
||||
if (!lastItem) continue
|
||||
let p = lastItem.slice(0, -postfix.length)
|
||||
|
||||
if (p.includes(prefix)) {
|
||||
p = p.replace(prefix, "")
|
||||
}
|
||||
|
||||
if (p === "index" || p === "layout") continue
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { WEB_URL } from "@follow/shared/constants"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { FeedIcon } from "~/components/feed-icon"
|
||||
@@ -15,6 +14,7 @@ import {
|
||||
} from "~/components/ui/table"
|
||||
import { EllipsisHorizontalTextWithTooltip } from "~/components/ui/typography"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
import { UrlBuilder } from "~/lib/url-builder"
|
||||
import { Balance } from "~/modules/wallet/balance"
|
||||
import { Queries } from "~/queries"
|
||||
|
||||
@@ -54,7 +54,7 @@ export const SettingFeeds = () => {
|
||||
<TableCell size="sm">
|
||||
<a
|
||||
target="_blank"
|
||||
href={`${WEB_URL}/feed/${row.feed.id}`}
|
||||
href={UrlBuilder.shareFeed(row.feed.id)}
|
||||
className="flex items-center"
|
||||
>
|
||||
<FeedIcon fallback feed={row.feed} size={16} />
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "~/components/ui/select"
|
||||
import { useProxyValue, useSetProxy } from "~/hooks/common/useProxySetting"
|
||||
import { useProxyValue, useSetProxy } from "~/hooks/biz/useProxySetting"
|
||||
import { fallbackLanguage } from "~/i18n"
|
||||
import { initPostHog } from "~/initialize/posthog"
|
||||
import { tipcClient } from "~/lib/client"
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Divider } from "~/components/ui/divider"
|
||||
import {
|
||||
SimpleIconsEagle,
|
||||
SimpleIconsInstapaper,
|
||||
SimpleIconsOmnivore,
|
||||
SimpleIconsReadwise,
|
||||
} from "~/components/ui/platform-icon/icons"
|
||||
|
||||
@@ -100,6 +101,56 @@ export const SettingIntegration = () => {
|
||||
labelClassName: "w-[150px]",
|
||||
},
|
||||
}),
|
||||
{
|
||||
type: "title",
|
||||
value: (
|
||||
<span className="flex items-center gap-2 font-bold">
|
||||
<SimpleIconsOmnivore />
|
||||
{t("integration.omnivore.title")}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
defineSettingItem("enableOmnivore", {
|
||||
label: t("integration.omnivore.enable.label"),
|
||||
description: t("integration.omnivore.enable.description"),
|
||||
}),
|
||||
defineSettingItem("omnivoreEndpoint", {
|
||||
label: t("integration.omnivore.endpoint.label"),
|
||||
vertical: true,
|
||||
description: (
|
||||
<>
|
||||
{t("integration.omnivore.endpoint.description")}{" "}
|
||||
<a
|
||||
target="_blank"
|
||||
className="underline"
|
||||
rel="noreferrer noopener"
|
||||
href="https://api-prod.omnivore.app/api/graphql"
|
||||
>
|
||||
https://api-prod.omnivore.app/api/graphql
|
||||
</a>
|
||||
.
|
||||
</>
|
||||
),
|
||||
}),
|
||||
defineSettingItem("omnivoreToken", {
|
||||
label: t("integration.omnivore.token.label"),
|
||||
vertical: true,
|
||||
type: "password",
|
||||
description: (
|
||||
<>
|
||||
{t("integration.omnivore.token.description")}{" "}
|
||||
<a
|
||||
target="_blank"
|
||||
className="underline"
|
||||
rel="noreferrer noopener"
|
||||
href="https://omnivore.app/settings/api"
|
||||
>
|
||||
omnivore.app/settings/api
|
||||
</a>
|
||||
.
|
||||
</>
|
||||
),
|
||||
}),
|
||||
|
||||
BottomTip,
|
||||
]}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { WEB_URL } from "@follow/shared/constants"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { toast } from "sonner"
|
||||
|
||||
@@ -20,6 +19,7 @@ import { Tooltip, TooltipContent, TooltipPortal, TooltipTrigger } from "~/compon
|
||||
import { views } from "~/constants"
|
||||
import { useAuthQuery, useI18n } from "~/hooks/common"
|
||||
import { apiClient } from "~/lib/api-fetch"
|
||||
import { UrlBuilder } from "~/lib/url-builder"
|
||||
import { cn } from "~/lib/utils"
|
||||
import { Balance } from "~/modules/wallet/balance"
|
||||
import { Queries } from "~/queries"
|
||||
@@ -90,7 +90,7 @@ export const SettingLists = () => {
|
||||
<TableCell size="sm">
|
||||
<a
|
||||
target="_blank"
|
||||
href={`${WEB_URL}/list/${row.id}`}
|
||||
href={UrlBuilder.shareList(row.id)}
|
||||
className="inline-flex items-center gap-2 font-semibold"
|
||||
>
|
||||
{row.image && (
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { WEB_URL } from "@follow/shared/constants"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { useMemo, useRef, useState } from "react"
|
||||
@@ -37,6 +36,7 @@ import {
|
||||
import { views } from "~/constants"
|
||||
import { apiClient } from "~/lib/api-fetch"
|
||||
import { createErrorToaster } from "~/lib/error-parser"
|
||||
import { UrlBuilder } from "~/lib/url-builder"
|
||||
import { isBizId } from "~/lib/utils"
|
||||
import type { FeedModel } from "~/models"
|
||||
import { ViewSelectorRadioGroup } from "~/modules/shared/ViewSelectorRadioGroup"
|
||||
@@ -317,7 +317,7 @@ const RowRender = ({ feedId, listId }: { feedId: string; listId: string }) => {
|
||||
<TableCell size="sm">
|
||||
<a
|
||||
target="_blank"
|
||||
href={`${WEB_URL}/list/${feed.id}`}
|
||||
href={UrlBuilder.shareFeed(feed.id)}
|
||||
className="flex items-center gap-2 font-semibold"
|
||||
>
|
||||
{feed.siteUrl && <FeedIcon className="mr-0" siteUrl={feed.siteUrl} />}
|
||||
|
||||
@@ -4,12 +4,17 @@ export interface SettingPageContext {
|
||||
role: Nullable<UserRole>
|
||||
}
|
||||
|
||||
export enum DisableWhy {
|
||||
NotActivation = "not_activation",
|
||||
}
|
||||
|
||||
export interface SettingPageConfig {
|
||||
iconName: string
|
||||
name: I18nKeysForSettings
|
||||
priority: number
|
||||
headerIcon?: string
|
||||
hideIf?: (ctx: SettingPageContext) => boolean
|
||||
disableIf?: (ctx: SettingPageContext) => [boolean, DisableWhy]
|
||||
}
|
||||
export const defineSettingPageData = (config: SettingPageConfig) => () => ({
|
||||
...config,
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
import { forwardRef } from "react"
|
||||
|
||||
import { Card, CardHeader } from "~/components/ui/card"
|
||||
import { Card, CardContent, CardHeader } from "~/components/ui/card"
|
||||
import { views } from "~/constants"
|
||||
import { useI18n } from "~/hooks/common"
|
||||
import { cn } from "~/lib/utils"
|
||||
import type { EntryModelSimple, FeedModel } from "~/models"
|
||||
|
||||
import { EntryItemStateless } from "../entry-column/item"
|
||||
|
||||
export const ViewSelectorRadioGroup = forwardRef<
|
||||
HTMLInputElement,
|
||||
React.InputHTMLAttributes<HTMLInputElement>
|
||||
>(({ className, ...rest }, ref) => {
|
||||
{
|
||||
entries?: EntryModelSimple[]
|
||||
feed?: FeedModel
|
||||
view?: number
|
||||
} & React.InputHTMLAttributes<HTMLInputElement>
|
||||
>(({ entries, feed, view, className, ...rest }, ref) => {
|
||||
const t = useI18n()
|
||||
|
||||
return (
|
||||
@@ -41,6 +48,13 @@ export const ViewSelectorRadioGroup = forwardRef<
|
||||
</div>
|
||||
))}
|
||||
</CardHeader>
|
||||
{!!feed && !!entries && (
|
||||
<CardContent className="space-y-2 p-2">
|
||||
{entries.slice(0, 2).map((entry) => (
|
||||
<EntryItemStateless entry={entry} feed={feed} view={view} key={entry.guid} />
|
||||
))}
|
||||
</CardContent>
|
||||
)}
|
||||
</Card>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -16,6 +16,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "~/components/ui/tooltip
|
||||
import { EllipsisHorizontalTextWithTooltip } from "~/components/ui/typography"
|
||||
import { useFollow } from "~/hooks/biz/useFollow"
|
||||
import { stopPropagation } from "~/lib/dom"
|
||||
import { UrlBuilder } from "~/lib/url-builder"
|
||||
import { cn } from "~/lib/utils"
|
||||
import type { FeedModel, Models } from "~/models"
|
||||
|
||||
@@ -82,7 +83,7 @@ const TrendContent = () => {
|
||||
</ActionButton>
|
||||
<ScrollArea.ScrollArea
|
||||
rootClassName="flex h-0 w-[calc(100%+8px)] grow flex-col overflow-visible"
|
||||
viewportClassName="pb-4"
|
||||
viewportClassName="pb-4 [&>div]:!block"
|
||||
scrollbarClassName="-mr-6"
|
||||
>
|
||||
<TrendingUsers data={data.trendingUsers} />
|
||||
@@ -123,7 +124,7 @@ const TrendingLists: FC<{
|
||||
<UserCount count={item.subscriberCount} />
|
||||
</div>
|
||||
{!!item.description && (
|
||||
<div className={"-mt-0.5 line-clamp-2 text-xs"}>{item.description}</div>
|
||||
<div className={"line-clamp-2 text-xs"}>{item.description}</div>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
@@ -241,14 +242,14 @@ const TrendingFeeds = ({ data }: { data: FeedModel[] }) => {
|
||||
return (
|
||||
<li
|
||||
className={cn(
|
||||
"group flex w-full items-center gap-1 rounded-md pl-2 duration-200 hover:bg-theme-item-hover",
|
||||
"group flex w-full items-center gap-1 rounded-md py-0.5 pl-2 duration-200 hover:bg-theme-item-hover",
|
||||
"relative",
|
||||
)}
|
||||
key={feed.id}
|
||||
>
|
||||
<a
|
||||
target="_blank"
|
||||
href={`/feed/${feed.id}`}
|
||||
href={UrlBuilder.shareFeed(feed.id)}
|
||||
className="flex grow items-center gap-2 py-1"
|
||||
>
|
||||
<div>
|
||||
@@ -283,17 +284,18 @@ const TrendingFeeds = ({ data }: { data: FeedModel[] }) => {
|
||||
}
|
||||
|
||||
const TrendingEntries = ({ data }: { data: Models.TrendingEntry[] }) => {
|
||||
const { t } = useTranslation()
|
||||
const filteredData = data.filter((entry) => !entry.url.startsWith("https://x.com"))
|
||||
return (
|
||||
<section className="mt-8 w-full text-left">
|
||||
<h2 className="my-2 text-xl font-bold">Trending Entries</h2>
|
||||
<h2 className="my-2 text-xl font-bold">{t("trending.entry")}</h2>
|
||||
|
||||
<ul className="mt-2 list-inside list-disc space-y-1">
|
||||
{filteredData.map((entry) => {
|
||||
return (
|
||||
<li
|
||||
key={entry.id}
|
||||
className="relative truncate whitespace-nowrap pr-10 marker:text-accent"
|
||||
className="relative truncate whitespace-nowrap py-0.5 pr-10 marker:text-accent"
|
||||
>
|
||||
<a
|
||||
href={entry.url}
|
||||
|
||||
@@ -54,7 +54,10 @@ export const ProfileButton: FC<LoginProps> = memo((props) => {
|
||||
return (
|
||||
<>
|
||||
<DropdownMenu onOpenChange={setDropdown}>
|
||||
<DropdownMenuTrigger asChild className="!outline-none focus-visible:bg-theme-item-hover">
|
||||
<DropdownMenuTrigger
|
||||
asChild
|
||||
className="!outline-none focus-visible:bg-theme-item-hover data-[state=open]:bg-transparent"
|
||||
>
|
||||
<TransitionAvatar stage={dropdown ? "zoom-in" : ""} />
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
@@ -186,7 +189,7 @@ const TransitionAvatar = forwardRef<
|
||||
className={cn(
|
||||
"pointer-events-none fixed -bottom-6 p-0 duration-200 [&_*]:border-0",
|
||||
"transform-gpu will-change-[left,top,height]",
|
||||
zoomIn ? "z-[999] h-14" : "z-[-1] h-6",
|
||||
zoomIn ? "z-[51] h-14" : "z-[-1] h-6",
|
||||
)}
|
||||
hideName
|
||||
onTransitionEnd={() => {
|
||||
|
||||
@@ -1,140 +1,11 @@
|
||||
import type { FC } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useParams, useSearchParams } from "react-router-dom"
|
||||
import { toast } from "sonner"
|
||||
import { redirect } from "react-router-dom"
|
||||
|
||||
import { PoweredByFooter } from "~/components/common/PoweredByFooter"
|
||||
import { FeedCertification } from "~/components/feed-certification"
|
||||
import { FeedIcon } from "~/components/feed-icon"
|
||||
import { FollowIcon } from "~/components/icons/follow"
|
||||
import { Button } from "~/components/ui/button"
|
||||
import { ListItemHoverOverlay } from "~/components/ui/list-item-hover-overlay"
|
||||
import { LoadingCircle } from "~/components/ui/loading"
|
||||
import { views } from "~/constants"
|
||||
import { usePresentFeedFormModal } from "~/hooks/biz/useFeedFormModal"
|
||||
import { useTitle } from "~/hooks/common"
|
||||
import type { FeedViewType } from "~/lib/enum"
|
||||
import { cn } from "~/lib/utils"
|
||||
import type { FeedModel } from "~/models"
|
||||
import { getItemComponentByView } from "~/modules/entry-column/Items"
|
||||
import type { UniversalItemProps } from "~/modules/entry-column/types"
|
||||
import { useEntriesPreview } from "~/queries/entries"
|
||||
import { useFeed } from "~/queries/feed"
|
||||
|
||||
export function Component() {
|
||||
const { id } = useParams()
|
||||
const [search] = useSearchParams()
|
||||
const view = Number.parseInt(search.get("view") || "0")
|
||||
|
||||
const feed = useFeed({
|
||||
id,
|
||||
})
|
||||
const feedData = feed.data?.feed as FeedModel
|
||||
const isSubscribed = !!feed.data?.subscription
|
||||
const entries = useEntriesPreview({
|
||||
id,
|
||||
})
|
||||
|
||||
const Item: FC<UniversalItemProps> = getItemComponentByView(view as FeedViewType)
|
||||
|
||||
const { t } = useTranslation("external")
|
||||
useTitle(feed.data?.feed.title)
|
||||
const presentFeedFormModal = usePresentFeedFormModal()
|
||||
return (
|
||||
<>
|
||||
{feed.isLoading ? (
|
||||
<LoadingCircle size="large" className="center fixed inset-0" />
|
||||
) : (
|
||||
feed.data?.feed && (
|
||||
<div className="mx-auto mt-12 flex max-w-5xl flex-col items-center justify-center p-4 lg:p-0">
|
||||
<FeedIcon
|
||||
fallback
|
||||
feed={feed.data.feed}
|
||||
className="mask-squircle mask shrink-0"
|
||||
size={64}
|
||||
/>
|
||||
<div className="flex flex-col items-center">
|
||||
<div className="mb-2 mt-4 flex items-center text-2xl font-bold">
|
||||
<h1>{feed.data.feed.title}</h1>
|
||||
<FeedCertification feed={feed.data.feed} />
|
||||
</div>
|
||||
<div className="mb-8 text-sm text-zinc-500">{feed.data.feed.description}</div>
|
||||
</div>
|
||||
<div className="mb-4 text-sm">
|
||||
{t("feed.followsAndReads", {
|
||||
subscriptionCount: feed.data.subscriptionCount,
|
||||
subscriptionNoun: t("feed.follower", { count: feed.data.subscriptionCount }),
|
||||
readCount: feed.data.readCount,
|
||||
readNoun: t("feed.read", { count: feed.data.readCount }),
|
||||
appName: APP_NAME,
|
||||
})}
|
||||
</div>
|
||||
<span className="center mb-8 flex gap-4">
|
||||
{feedData.url.startsWith("https://") ? (
|
||||
<Button
|
||||
variant={"outline"}
|
||||
onClick={() => {
|
||||
window.open(feedData.url, "_blank")
|
||||
}}
|
||||
>
|
||||
{t("feed.view_feed_url")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant={"outline"}
|
||||
onClick={() => {
|
||||
toast.success(t("copied_link"))
|
||||
navigator.clipboard.writeText(feedData.url)
|
||||
}}
|
||||
>
|
||||
{t("feed.copy_feed_url")}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant={isSubscribed ? "outline" : undefined}
|
||||
onClick={() => {
|
||||
presentFeedFormModal({
|
||||
feedId: id!,
|
||||
})
|
||||
}}
|
||||
>
|
||||
<FollowIcon className="mr-1 size-3" />
|
||||
{isSubscribed ? t("feed.actions.followed") : <>{APP_NAME}</>}
|
||||
</Button>
|
||||
</span>
|
||||
<div
|
||||
className={cn(
|
||||
"w-full pb-12 pt-8",
|
||||
views[view].gridMode
|
||||
? "grid grid-cols-2 gap-4 md:grid-cols-3 lg:grid-cols-4"
|
||||
: "flex max-w-3xl flex-col gap-6",
|
||||
)}
|
||||
>
|
||||
{entries.data?.map((entry) => (
|
||||
<a
|
||||
className="relative cursor-pointer"
|
||||
href={entry.url || void 0}
|
||||
target="_blank"
|
||||
key={entry.id}
|
||||
>
|
||||
<ListItemHoverOverlay className="rounded">
|
||||
<Item
|
||||
entryPreview={{
|
||||
entries: entry,
|
||||
feeds: feedData,
|
||||
read: true,
|
||||
feedId: feedData.id!,
|
||||
}}
|
||||
entryId={entry.id}
|
||||
/>
|
||||
</ListItemHoverOverlay>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
<PoweredByFooter className="pb-12" />
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</>
|
||||
)
|
||||
/**
|
||||
* @deprecated remove after split application
|
||||
*/
|
||||
export const loader = async ({ params }: { params: { id: string } }) => {
|
||||
return redirect(`/share/feeds/${params.id}`)
|
||||
}
|
||||
export function Component() {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -1,122 +1,11 @@
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useParams } from "react-router-dom"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { PoweredByFooter } from "~/components/common/PoweredByFooter"
|
||||
import { FeedCertification } from "~/components/feed-certification"
|
||||
import { FeedIcon } from "~/components/feed-icon"
|
||||
import { FollowIcon } from "~/components/icons/follow"
|
||||
import { Button } from "~/components/ui/button"
|
||||
import { LoadingCircle } from "~/components/ui/loading"
|
||||
import { usePresentFeedFormModal } from "~/hooks/biz/useFeedFormModal"
|
||||
import { useTitle } from "~/hooks/common"
|
||||
import type { ListModel } from "~/models"
|
||||
import { useList } from "~/queries/lists"
|
||||
import { useFeedById } from "~/store/feed/hooks"
|
||||
import { redirect } from "react-router-dom"
|
||||
|
||||
export const loader = async ({ params }: { params: { id: string } }) => {
|
||||
return redirect(`/share/lists/${params.id}`)
|
||||
}
|
||||
/**
|
||||
* @deprecated remove after split application
|
||||
*/
|
||||
export function Component() {
|
||||
const { id } = useParams()
|
||||
|
||||
const list = useList({
|
||||
id: id!,
|
||||
})
|
||||
const listData = list.data?.list as ListModel
|
||||
const isSubscribed = !!list.data?.subscription
|
||||
|
||||
const { t } = useTranslation("external")
|
||||
useTitle(list.data?.list.title)
|
||||
const presentFeedFormModal = usePresentFeedFormModal()
|
||||
return (
|
||||
<>
|
||||
{list.isLoading ? (
|
||||
<LoadingCircle size="large" className="center fixed inset-0" />
|
||||
) : (
|
||||
list.data?.list && (
|
||||
<div className="mx-auto mt-12 flex max-w-5xl flex-col items-center justify-center p-4 lg:p-0">
|
||||
<FeedIcon
|
||||
fallback
|
||||
feed={list.data.list}
|
||||
className="mask-squircle mask shrink-0"
|
||||
size={64}
|
||||
/>
|
||||
<div className="flex flex-col items-center">
|
||||
<div className="mb-2 mt-4 flex items-center text-2xl font-bold">
|
||||
<h1>{list.data.list.title}</h1>
|
||||
<FeedCertification feed={list.data.list} />
|
||||
</div>
|
||||
<div className="mb-8 text-sm text-zinc-500">{list.data.list.description}</div>
|
||||
</div>
|
||||
<div className="mb-4 text-sm">
|
||||
{t("feed.followsAndFeeds", {
|
||||
subscriptionCount: list.data?.subscriptionCount,
|
||||
subscriptionNoun: t("feed.follower", { count: list.data?.subscriptionCount }),
|
||||
feedsCount: list.data?.feedCount || 0,
|
||||
feedsNoun: t("feed.feeds", { count: listData?.feedIds?.length }),
|
||||
appName: APP_NAME,
|
||||
})}
|
||||
</div>
|
||||
<span className="center mb-8 flex gap-4">
|
||||
<Button
|
||||
variant={"outline"}
|
||||
onClick={() => {
|
||||
toast.success(t("copied_link"))
|
||||
navigator.clipboard.writeText(id!)
|
||||
}}
|
||||
>
|
||||
Copy List ID
|
||||
</Button>
|
||||
<Button
|
||||
variant={isSubscribed ? "outline" : undefined}
|
||||
onClick={() => {
|
||||
presentFeedFormModal({
|
||||
listId: id!,
|
||||
})
|
||||
}}
|
||||
>
|
||||
<FollowIcon className="mr-2 size-3" />
|
||||
{isSubscribed ? "Followed" : <>{APP_NAME}</>}
|
||||
</Button>
|
||||
</span>
|
||||
<div className="flex w-full max-w-3xl flex-col gap-4 pb-12 pt-8">
|
||||
{listData.feedIds
|
||||
?.slice(0, 5)
|
||||
.map((feedId) => <FeedRow feedId={feedId} key={feedId} />)}
|
||||
{"feedCount" in list.data && (
|
||||
<div
|
||||
onClick={() => {
|
||||
presentFeedFormModal({
|
||||
listId: id!,
|
||||
})
|
||||
}}
|
||||
className="text-sm text-zinc-500"
|
||||
>
|
||||
{t("feed.follow_to_view_all", {
|
||||
count: list.data.feedCount || 0,
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<PoweredByFooter className="mt-20 pb-12" />
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const FeedRow = ({ feedId }: { feedId: string }) => {
|
||||
const feed = useFeedById(feedId)
|
||||
if (!feed) return null
|
||||
return (
|
||||
<a
|
||||
className="relative flex cursor-pointer items-center text-base"
|
||||
href={`/feed/${feed.id}`}
|
||||
target="_blank"
|
||||
key={feed.id}
|
||||
>
|
||||
<FeedIcon fallback feed={feed} className="mask-squircle mask mr-2 shrink-0" size={20} />
|
||||
{feed.title}
|
||||
<FeedCertification feed={feed} />
|
||||
</a>
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { useAuthQuery, useI18n, useTitle } from "~/hooks/common"
|
||||
import { apiClient } from "~/lib/api-fetch"
|
||||
import { defineQuery } from "~/lib/defineQuery"
|
||||
import { replaceImgUrlIfNeed } from "~/lib/img-proxy"
|
||||
import { UrlBuilder } from "~/lib/url-builder"
|
||||
import { cn, isBizId } from "~/lib/utils"
|
||||
import { useUserSubscriptionsQuery } from "~/modules/profile/hooks"
|
||||
|
||||
@@ -80,7 +81,7 @@ export function Component() {
|
||||
<div key={subscription.feedId} className="group relative border-b py-5">
|
||||
<a
|
||||
className="flex flex-1 cursor-button"
|
||||
href={`/feed/${subscription.feedId}`}
|
||||
href={UrlBuilder.shareFeed(subscription.feedId)}
|
||||
target="_blank"
|
||||
>
|
||||
<FeedIcon
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
import type { FC } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useParams, useSearchParams } from "react-router-dom"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { PoweredByFooter } from "~/components/common/PoweredByFooter"
|
||||
import { FeedCertification } from "~/components/feed-certification"
|
||||
import { FeedIcon } from "~/components/feed-icon"
|
||||
import { FollowIcon } from "~/components/icons/follow"
|
||||
import { Button } from "~/components/ui/button"
|
||||
import { LoadingCircle } from "~/components/ui/loading"
|
||||
import { views } from "~/constants"
|
||||
import { usePresentFeedFormModal } from "~/hooks/biz/useFeedFormModal"
|
||||
import { useTitle } from "~/hooks/common"
|
||||
import type { FeedViewType } from "~/lib/enum"
|
||||
import { cn } from "~/lib/utils"
|
||||
import type { FeedModel } from "~/models"
|
||||
import { getItemComponentByView } from "~/modules/entry-column/Items"
|
||||
import type { UniversalItemProps } from "~/modules/entry-column/types"
|
||||
import { useEntriesPreview } from "~/queries/entries"
|
||||
import { useFeed } from "~/queries/feed"
|
||||
|
||||
export function Component() {
|
||||
const { id } = useParams()
|
||||
const [search] = useSearchParams()
|
||||
const view = Number.parseInt(search.get("view") || "0")
|
||||
|
||||
const feed = useFeed({
|
||||
id,
|
||||
})
|
||||
const feedData = feed.data?.feed as FeedModel
|
||||
const isSubscribed = !!feed.data?.subscription
|
||||
const entries = useEntriesPreview({
|
||||
id,
|
||||
})
|
||||
|
||||
const Item: FC<UniversalItemProps> = getItemComponentByView(view as FeedViewType)
|
||||
|
||||
const { t } = useTranslation("external")
|
||||
useTitle(feed.data?.feed.title)
|
||||
const presentFeedFormModal = usePresentFeedFormModal()
|
||||
return (
|
||||
<>
|
||||
{feed.isLoading ? (
|
||||
<LoadingCircle size="large" className="center fixed inset-0" />
|
||||
) : (
|
||||
feed.data?.feed && (
|
||||
<div className="mx-auto mt-12 flex w-full max-w-5xl flex-col items-center justify-center p-4 lg:p-0">
|
||||
<FeedIcon
|
||||
fallback
|
||||
feed={feed.data.feed}
|
||||
className="mask-squircle mask shrink-0"
|
||||
size={64}
|
||||
/>
|
||||
<div className="flex flex-col items-center">
|
||||
<div className="mb-2 mt-4 flex items-center text-2xl font-bold">
|
||||
<h1>{feed.data.feed.title}</h1>
|
||||
<FeedCertification feed={feed.data.feed} />
|
||||
</div>
|
||||
<div className="mb-8 text-sm text-zinc-500">{feed.data.feed.description}</div>
|
||||
</div>
|
||||
<div className="mb-4 text-sm">
|
||||
{t("feed.followsAndReads", {
|
||||
subscriptionCount: feed.data.subscriptionCount,
|
||||
subscriptionNoun: t("feed.follower", { count: feed.data.subscriptionCount }),
|
||||
readCount: feed.data.readCount,
|
||||
readNoun: t("feed.read", { count: feed.data.readCount }),
|
||||
appName: APP_NAME,
|
||||
})}
|
||||
</div>
|
||||
<span className="center mb-8 flex gap-4">
|
||||
{feedData.url.startsWith("https://") ? (
|
||||
<Button
|
||||
variant={"outline"}
|
||||
onClick={() => {
|
||||
window.open(feedData.url, "_blank")
|
||||
}}
|
||||
>
|
||||
{t("feed.view_feed_url")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant={"outline"}
|
||||
onClick={() => {
|
||||
toast.success(t("copied_link"))
|
||||
navigator.clipboard.writeText(feedData.url)
|
||||
}}
|
||||
>
|
||||
{t("feed.copy_feed_url")}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant={isSubscribed ? "outline" : undefined}
|
||||
onClick={() => {
|
||||
presentFeedFormModal({
|
||||
feedId: id!,
|
||||
})
|
||||
}}
|
||||
>
|
||||
<FollowIcon className="mr-1 size-3" />
|
||||
{isSubscribed ? t("feed.actions.followed") : <>{APP_NAME}</>}
|
||||
</Button>
|
||||
</span>
|
||||
<div
|
||||
className={cn(
|
||||
"w-full pb-12 pt-8",
|
||||
views[view].gridMode
|
||||
? "grid grid-cols-2 gap-4 md:grid-cols-3 lg:grid-cols-4"
|
||||
: "flex max-w-3xl flex-col gap-6",
|
||||
)}
|
||||
>
|
||||
{entries.data?.map((entry) => (
|
||||
<a
|
||||
className="relative cursor-pointer"
|
||||
href={entry.url || void 0}
|
||||
target="_blank"
|
||||
key={entry.id}
|
||||
>
|
||||
<div className="rounded-xl pl-3 duration-300 hover:bg-theme-item-active">
|
||||
<Item
|
||||
entryPreview={{
|
||||
entries: entry,
|
||||
feeds: feedData,
|
||||
read: true,
|
||||
feedId: feedData.id!,
|
||||
}}
|
||||
entryId={entry.id}
|
||||
/>
|
||||
</div>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
<PoweredByFooter className="pb-12" />
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { useParams } from "react-router-dom"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { PoweredByFooter } from "~/components/common/PoweredByFooter"
|
||||
import { FeedCertification } from "~/components/feed-certification"
|
||||
import { FeedIcon } from "~/components/feed-icon"
|
||||
import { FollowIcon } from "~/components/icons/follow"
|
||||
import { Button } from "~/components/ui/button"
|
||||
import { LoadingCircle } from "~/components/ui/loading"
|
||||
import { usePresentFeedFormModal } from "~/hooks/biz/useFeedFormModal"
|
||||
import { useTitle } from "~/hooks/common"
|
||||
import type { ListModel } from "~/models"
|
||||
import { useList } from "~/queries/lists"
|
||||
import { useFeedById } from "~/store/feed/hooks"
|
||||
|
||||
export function Component() {
|
||||
const { id } = useParams()
|
||||
|
||||
const list = useList({
|
||||
id: id!,
|
||||
})
|
||||
const listData = list.data?.list as ListModel
|
||||
const isSubscribed = !!list.data?.subscription
|
||||
|
||||
const { t } = useTranslation("external")
|
||||
useTitle(list.data?.list.title)
|
||||
const presentFeedFormModal = usePresentFeedFormModal()
|
||||
return (
|
||||
<>
|
||||
{list.isLoading ? (
|
||||
<LoadingCircle size="large" className="center fixed inset-0" />
|
||||
) : (
|
||||
list.data?.list && (
|
||||
<div className="mx-auto mt-12 flex w-full max-w-5xl flex-col items-center justify-center p-4 lg:p-0">
|
||||
<FeedIcon
|
||||
fallback
|
||||
feed={list.data.list}
|
||||
className="mask-squircle mask shrink-0"
|
||||
size={64}
|
||||
/>
|
||||
<div className="flex flex-col items-center">
|
||||
<div className="mb-2 mt-4 flex items-center text-2xl font-bold">
|
||||
<h1>{list.data.list.title}</h1>
|
||||
<FeedCertification feed={list.data.list} />
|
||||
</div>
|
||||
<div className="mb-8 text-sm text-zinc-500">{list.data.list.description}</div>
|
||||
</div>
|
||||
<div className="mb-4 text-sm">
|
||||
{t("feed.followsAndFeeds", {
|
||||
subscriptionCount: list.data?.subscriptionCount,
|
||||
subscriptionNoun: t("feed.follower", { count: list.data?.subscriptionCount }),
|
||||
feedsCount: list.data?.feedCount || 0,
|
||||
feedsNoun: t("feed.feeds", { count: listData?.feedIds?.length }),
|
||||
appName: APP_NAME,
|
||||
})}
|
||||
</div>
|
||||
<span className="center mb-8 flex gap-4">
|
||||
<Button
|
||||
variant={"outline"}
|
||||
onClick={() => {
|
||||
toast.success(t("copied_link"))
|
||||
navigator.clipboard.writeText(id!)
|
||||
}}
|
||||
>
|
||||
Copy List ID
|
||||
</Button>
|
||||
<Button
|
||||
variant={isSubscribed ? "outline" : undefined}
|
||||
onClick={() => {
|
||||
presentFeedFormModal({
|
||||
listId: id!,
|
||||
})
|
||||
}}
|
||||
>
|
||||
<FollowIcon className="mr-2 size-3" />
|
||||
{isSubscribed ? "Followed" : <>{APP_NAME}</>}
|
||||
</Button>
|
||||
</span>
|
||||
<div className="flex w-full max-w-3xl flex-col gap-4 pb-12 pt-8">
|
||||
{listData.feedIds
|
||||
?.slice(0, 5)
|
||||
.map((feedId) => <FeedRow feedId={feedId} key={feedId} />)}
|
||||
{"feedCount" in list.data && (
|
||||
<div
|
||||
onClick={() => {
|
||||
presentFeedFormModal({
|
||||
listId: id!,
|
||||
})
|
||||
}}
|
||||
className="text-sm text-zinc-500"
|
||||
>
|
||||
{t("feed.follow_to_view_all", {
|
||||
count: list.data.feedCount || 0,
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<PoweredByFooter className="mt-20 pb-12" />
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
const FeedRow = ({ feedId }: { feedId: string }) => {
|
||||
const feed = useFeedById(feedId)
|
||||
if (!feed) return null
|
||||
return (
|
||||
<a
|
||||
className="relative flex cursor-pointer items-center text-base"
|
||||
href={`/share/feeds/${feed.id}`}
|
||||
target="_blank"
|
||||
key={feed.id}
|
||||
>
|
||||
<FeedIcon fallback feed={feed} className="mask-squircle mask mr-2 shrink-0" size={20} />
|
||||
{feed.title}
|
||||
<FeedCertification feed={feed} />
|
||||
</a>
|
||||
)
|
||||
}
|
||||
@@ -128,6 +128,7 @@ export function Component() {
|
||||
id="login"
|
||||
CustomModalComponent={PlainModal}
|
||||
open
|
||||
overlay
|
||||
title="Login"
|
||||
canClose={false}
|
||||
clickOutsideToDismiss={false}
|
||||
|
||||
@@ -15,7 +15,7 @@ export default defineProject({
|
||||
test: {
|
||||
globals: true,
|
||||
setupFiles: [resolve(__dirname, "./setup-file.ts")],
|
||||
environment: "node",
|
||||
environment: "happy-dom",
|
||||
includeSource: [resolve(__dirname, ".")],
|
||||
dom: true,
|
||||
},
|
||||
@@ -35,5 +35,7 @@ export default defineProject({
|
||||
tsconfigPath({
|
||||
projects: ["./tsconfig.json"],
|
||||
}),
|
||||
|
||||
twMacro(),
|
||||
],
|
||||
})
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
import "./tw-css-plugin"
|
||||
|
||||
import path, { resolve } from "node:path"
|
||||
|
||||
import { getIconCollections, iconsPlugin } from "@egoist/tailwindcss-icons"
|
||||
import { cleanupSVG, importDirectorySync, isEmptyColor, parseColors, runSVGO } from "@iconify/tools"
|
||||
import { compareColors, stringToColor } from "@iconify/utils/lib/colors"
|
||||
import type { Config } from "tailwindcss"
|
||||
import plugin from "tailwindcss/plugin"
|
||||
|
||||
export const baseConfig: Config = {
|
||||
darkMode: ["class", '[data-theme="dark"]'],
|
||||
content: [],
|
||||
prefix: "",
|
||||
theme: {
|
||||
container: {
|
||||
center: true,
|
||||
padding: "2rem",
|
||||
screens: {
|
||||
"2xl": "1400px",
|
||||
},
|
||||
},
|
||||
|
||||
extend: {
|
||||
spacing: {
|
||||
"safe-inset-top": "var(--fo-window-padding-top, 0)",
|
||||
},
|
||||
fontFamily: {
|
||||
theme: "var(--fo-font-family)",
|
||||
default: "SN pro, sans-serif, system-ui",
|
||||
},
|
||||
cursor: {
|
||||
button: "var(--cursor-button)",
|
||||
select: "var(--cursor-select)",
|
||||
checkbox: "var(--cursor-checkbox)",
|
||||
link: "var(--cursor-link)",
|
||||
menu: "var(--cursor-menu)",
|
||||
radio: "var(--cursor-radio)",
|
||||
switch: "var(--cursor-switch)",
|
||||
card: "var(--cursor-card)",
|
||||
},
|
||||
width: {
|
||||
"feed-col": "var(--fo-feed-col-w)",
|
||||
},
|
||||
colors: {
|
||||
border: "hsl(var(--border) / <alpha-value>)",
|
||||
background: "hsl(var(--background) / <alpha-value>)",
|
||||
foreground: "hsl(var(--foreground) / <alpha-value>)",
|
||||
|
||||
destructive: {
|
||||
DEFAULT: "hsl(var(--destructive) / <alpha-value>)",
|
||||
foreground: "hsl(var(--destructive-foreground) / <alpha-value>)",
|
||||
},
|
||||
muted: {
|
||||
DEFAULT: "hsl(var(--muted) / <alpha-value>)",
|
||||
foreground: "hsl(var(--muted-foreground) / <alpha-value>)",
|
||||
},
|
||||
accent: "hsl(var(--fo-a) / <alpha-value>)",
|
||||
|
||||
popover: {
|
||||
DEFAULT: "hsl(var(--popover) / <alpha-value>)",
|
||||
foreground: "hsl(var(--popover-foreground) / <alpha-value>)",
|
||||
},
|
||||
card: {
|
||||
DEFAULT: "hsl(var(--card) / <alpha-value>)",
|
||||
foreground: "hsl(var(--card-foreground) / <alpha-value>)",
|
||||
},
|
||||
native: {
|
||||
DEFAULT: "hsl(var(--fo-native) / <alpha-value>)",
|
||||
active: "hsl(var(--fo-native-active) / <alpha-value>)",
|
||||
},
|
||||
|
||||
theme: {
|
||||
// https://uicolors.app/create
|
||||
accent: {
|
||||
DEFAULT: "hsl(var(--fo-a) / <alpha-value>)",
|
||||
50: "#fff7ec",
|
||||
100: "#ffeed3",
|
||||
200: "#ffd9a5",
|
||||
300: "#ffbd6d",
|
||||
400: "#ff9532",
|
||||
500: "#ff760a",
|
||||
600: "#ff5c00",
|
||||
700: "#cc4102",
|
||||
800: "#a1330b",
|
||||
900: "#822c0c",
|
||||
950: "#461304",
|
||||
},
|
||||
|
||||
vibrancyFg: "hsl(var(--fo-vibrancy-foreground) / <alpha-value>)",
|
||||
vibrancyBg: "var(--fo-vibrancy-background)",
|
||||
|
||||
item: {
|
||||
active: "var(--fo-item-active)",
|
||||
hover: "var(--fo-item-hover)",
|
||||
},
|
||||
|
||||
inactive: "hsl(var(--fo-inactive) / <alpha-value>)",
|
||||
disabled: "hsl(var(--fo-disabled) / <alpha-value>)",
|
||||
|
||||
foreground: "hsl(var(--fo-text-primary) / <alpha-value>)",
|
||||
background: "var(--fo-background)",
|
||||
|
||||
"foreground-hover": "hsl(var(--fo-text-primary-hover) / <alpha-value>)",
|
||||
|
||||
modal: {
|
||||
background: "var(--fo-modal-background)",
|
||||
"background-opaque": "var(--fo-modal-background-opaque)",
|
||||
},
|
||||
button: {
|
||||
hover: "var(--fo-button-hover)",
|
||||
},
|
||||
|
||||
placeholder: {
|
||||
text: "var(--fo-text-placeholder)",
|
||||
image: "var(--fo-image-placeholder)",
|
||||
},
|
||||
},
|
||||
},
|
||||
borderRadius: {
|
||||
lg: "var(--radius)",
|
||||
md: "calc(var(--radius) - 2px)",
|
||||
sm: "calc(var(--radius) - 4px)",
|
||||
},
|
||||
|
||||
typography: (theme) => ({
|
||||
zinc: {
|
||||
css: {
|
||||
"--tw-prose-body": theme("colors.zinc.500"),
|
||||
"--tw-prose-quotes": theme("colors.zinc.500"),
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
||||
plugins: [
|
||||
iconsPlugin({
|
||||
collections: {
|
||||
...getIconCollections(["mingcute", "simple-icons", "logos"]),
|
||||
mgc: getCollections(path.resolve(__dirname, "../icons/mgc")),
|
||||
},
|
||||
}),
|
||||
require("tailwindcss-animate"),
|
||||
require("@tailwindcss/container-queries"),
|
||||
require("@tailwindcss/typography"),
|
||||
require("tailwindcss-motion"),
|
||||
|
||||
require(resolve(__dirname, "./tailwind-extend.css")),
|
||||
|
||||
plugin(({ addVariant }) => {
|
||||
addVariant("f-motion-reduce", '[data-motion-reduce="true"] &')
|
||||
addVariant("group-motion-reduce", ':merge(.group)[data-motion-reduce="true"] &')
|
||||
addVariant("peer-motion-reduce", ':merge(.peer)[data-motion-reduce="true"] ~ &')
|
||||
}),
|
||||
plugin(({ addUtilities, matchUtilities, theme }) => {
|
||||
addUtilities({
|
||||
".safe-inset-top": {
|
||||
top: "var(--fo-window-padding-top, 0)",
|
||||
},
|
||||
})
|
||||
|
||||
const safeInsetTopVariants = {}
|
||||
for (let i = 1; i <= 16; i++) {
|
||||
safeInsetTopVariants[`.safe-inset-top-${i}`] = {
|
||||
top: `calc(var(--fo-window-padding-top, 0px) + ${theme(`spacing.${i}`)})`,
|
||||
}
|
||||
}
|
||||
addUtilities(safeInsetTopVariants)
|
||||
|
||||
// Add arbitrary value support
|
||||
matchUtilities(
|
||||
{
|
||||
"safe-inset-top": (value) => ({
|
||||
top: `calc(var(--fo-window-padding-top, 0px) + ${value})`,
|
||||
}),
|
||||
},
|
||||
{ values: theme("spacing") },
|
||||
)
|
||||
}),
|
||||
],
|
||||
}
|
||||
|
||||
function getCollections(dir: string) {
|
||||
// Import icons
|
||||
const iconSet = importDirectorySync(dir, {
|
||||
includeSubDirs: false,
|
||||
})
|
||||
|
||||
// Validate, clean up, fix palette and optimism
|
||||
iconSet.forEachSync((name, type) => {
|
||||
if (type !== "icon") {
|
||||
return
|
||||
}
|
||||
|
||||
const svg = iconSet.toSVG(name)
|
||||
if (!svg) {
|
||||
// Invalid icon
|
||||
iconSet.remove(name)
|
||||
return
|
||||
}
|
||||
|
||||
// Clean up and optimize icons
|
||||
try {
|
||||
// Clean up icon code
|
||||
cleanupSVG(svg)
|
||||
|
||||
// Change color to `currentColor`
|
||||
// Skip this step if icon has hardcoded palette
|
||||
const blackColor = stringToColor("black")!
|
||||
const whiteColor = stringToColor("white")!
|
||||
parseColors(svg, {
|
||||
defaultColor: "currentColor",
|
||||
callback: (attr, colorStr, color) => {
|
||||
if (!color) {
|
||||
// Color cannot be parsed!
|
||||
throw new Error(`Invalid color: "${colorStr}" in attribute ${attr}`)
|
||||
}
|
||||
|
||||
if (isEmptyColor(color)) {
|
||||
// Color is empty: 'none' or 'transparent'. Return as is
|
||||
return color
|
||||
}
|
||||
|
||||
// Change black to 'currentColor'
|
||||
if (compareColors(color, blackColor)) {
|
||||
return "currentColor"
|
||||
}
|
||||
|
||||
// Remove shapes with white color
|
||||
if (compareColors(color, whiteColor)) {
|
||||
return "remove"
|
||||
}
|
||||
|
||||
// NOTE: MGC icons has default color of #10161F
|
||||
if (compareColors(color, stringToColor("#10161F")!)) {
|
||||
return "currentColor"
|
||||
}
|
||||
|
||||
// Icon is not monotone
|
||||
return color
|
||||
},
|
||||
})
|
||||
|
||||
runSVGO(svg)
|
||||
} catch (err) {
|
||||
// Invalid icon
|
||||
console.error(`Error parsing ${name}:`, err)
|
||||
iconSet.remove(name)
|
||||
return
|
||||
}
|
||||
|
||||
// Update icon
|
||||
iconSet.fromSVG(name, svg)
|
||||
})
|
||||
|
||||
// Export
|
||||
return iconSet.export()
|
||||
}
|
||||
@@ -59,6 +59,7 @@
|
||||
"entry_actions.copy_title": "Copy Title",
|
||||
"entry_actions.failed_to_save_to_eagle": "Failed to save to Eagle.",
|
||||
"entry_actions.failed_to_save_to_instapaper": "Failed to save to Instapaper.",
|
||||
"entry_actions.failed_to_save_to_omnivore": "Failed to save to Omnivore.",
|
||||
"entry_actions.failed_to_save_to_readwise": "Failed to save to Readwise.",
|
||||
"entry_actions.mark_as_read": "Mark as Read",
|
||||
"entry_actions.mark_as_unread": "Mark as Unread",
|
||||
@@ -66,9 +67,11 @@
|
||||
"entry_actions.recent_reader": "Recent reader:",
|
||||
"entry_actions.save_media_to_eagle": "Save Media To Eagle",
|
||||
"entry_actions.save_to_instapaper": "Save To Instapaper",
|
||||
"entry_actions.save_to_omnivore": "Save To Omnivore",
|
||||
"entry_actions.save_to_readwise": "Save To Readwise",
|
||||
"entry_actions.saved_to_eagle": "Saved To Eagle.",
|
||||
"entry_actions.saved_to_instapaper": "Saved To Instapaper.",
|
||||
"entry_actions.saved_to_omnivore": "Saved To Omnivore.",
|
||||
"entry_actions.saved_to_readwise": "Saved To Readwise.",
|
||||
"entry_actions.share": "Share",
|
||||
"entry_actions.star": "Star",
|
||||
|
||||
+3
-1
@@ -14,19 +14,21 @@
|
||||
"discover.rss_hub_route": "RSSHub ルート",
|
||||
"discover.rss_url": "RSS URL",
|
||||
"discover.select_placeholder": "選択",
|
||||
"early_access": "アーリーアクセス",
|
||||
"entry_actions.copy_link": "リンクをコピー",
|
||||
"entry_actions.failed_to_save_to_eagle": "Eagle への保存に失敗しました。",
|
||||
"entry_actions.failed_to_save_to_instapaper": "Instapaper への保存に失敗しました。",
|
||||
"entry_actions.failed_to_save_to_omnivore": "Omnivore への保存に失敗しました。",
|
||||
"entry_actions.failed_to_save_to_readwise": "Readwise への保存に失敗しました。",
|
||||
"entry_actions.mark_as_read": "既読にする",
|
||||
"entry_actions.mark_as_unread": "未読にする",
|
||||
"entry_actions.open_in_browser": "ブラウザで開く",
|
||||
"entry_actions.save_media_to_eagle": "メディアを Eagle に保存",
|
||||
"entry_actions.save_to_instapaper": "Instapaper に保存",
|
||||
"entry_actions.save_to_omnivore": "Omnivore に保存",
|
||||
"entry_actions.save_to_readwise": "Readwise に保存",
|
||||
"entry_actions.saved_to_eagle": "Eagle に保存されました。",
|
||||
"entry_actions.saved_to_instapaper": "Instapaper に保存されました。",
|
||||
"entry_actions.saved_to_omnivore": "Omnivore に保存されました。",
|
||||
"entry_actions.saved_to_readwise": "Readwise に保存されました。",
|
||||
"entry_actions.share": "共有",
|
||||
"entry_actions.star": "スター",
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
"entry_actions.copy_title": "复制标题",
|
||||
"entry_actions.failed_to_save_to_eagle": "保存到 Eagle 失败",
|
||||
"entry_actions.failed_to_save_to_instapaper": "保存到 Instapaper 失败",
|
||||
"entry_actions.failed_to_save_to_omnivore": "保存到 Omnivore 失败",
|
||||
"entry_actions.failed_to_save_to_readwise": "保存到 Readwise 失败",
|
||||
"entry_actions.mark_as_read": "标记为已读",
|
||||
"entry_actions.mark_as_unread": "标记为未读",
|
||||
@@ -62,9 +63,11 @@
|
||||
"entry_actions.recent_reader": "最近阅读者:",
|
||||
"entry_actions.save_media_to_eagle": "保存到 Eagle",
|
||||
"entry_actions.save_to_instapaper": "保存到 Instapaper",
|
||||
"entry_actions.save_to_omnivore": "保存到 Omnivore",
|
||||
"entry_actions.save_to_readwise": "保存到 Readwise",
|
||||
"entry_actions.saved_to_eagle": "保存到 Eagle",
|
||||
"entry_actions.saved_to_instapaper": "保存到 Instapaper.",
|
||||
"entry_actions.saved_to_omnivore": "保存到 Omnivore.",
|
||||
"entry_actions.saved_to_readwise": "保存到 Readwise.",
|
||||
"entry_actions.share": "分享",
|
||||
"entry_actions.star": "收藏",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user