-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: init Signed-off-by: Innei <i@innei.in> * feat: reduce motion Signed-off-by: Innei <i@innei.in> * fix: image preview Signed-off-by: Innei <i@innei.in> * fix: guard ui setting storage Signed-off-by: Innei <i@innei.in> --------- Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
28 changed files
with
219 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export * from "./dom" | ||
export * from "./route" | ||
export * from "./sidebar" | ||
export * from "./ui" | ||
export * from "./user" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { useRefValue } from "@renderer/hooks" | ||
import { createAtomHooks } from "@renderer/lib/jotai" | ||
import { getStorageNS } from "@renderer/lib/ns" | ||
import { useAtomValue } from "jotai" | ||
import { atomWithStorage, selectAtom } from "jotai/utils" | ||
import { useMemo } from "react" | ||
|
||
const createDefaultSettings = () => ({ | ||
// Sidebar | ||
entryColWidth: 340, | ||
opaqueSidebar: false, | ||
sidebarShowUnreadCount: true, | ||
|
||
// Global UI | ||
uiTextSize: 16, | ||
// System | ||
showDockBadge: true, | ||
// Misc | ||
modalOverlay: true, | ||
modalDraggable: true, | ||
modalOpaque: true, | ||
reduceMotion: false, | ||
|
||
// Content | ||
readerFontFamily: "SN Pro", | ||
readerRenderInlineStyle: false, | ||
codeHighlightTheme: "github-dark", | ||
}) | ||
const atom = atomWithStorage(getStorageNS("ui"), createDefaultSettings()) | ||
const [, , useUISettingValue, , getUISettings, setUISettings] = | ||
createAtomHooks(atom) | ||
|
||
export const initializeDefaultUISettings = () => { | ||
const currentSettings = getUISettings() | ||
const defaultSettings = createDefaultSettings() | ||
if (typeof currentSettings !== "object") setUISettings(defaultSettings) | ||
const newSettings = { ...defaultSettings, ...currentSettings } | ||
setUISettings(newSettings) | ||
} | ||
|
||
export { getUISettings, useUISettingValue } | ||
export const useUISettingKey = < | ||
T extends keyof ReturnType<typeof getUISettings>, | ||
>( | ||
key: T, | ||
) => useAtomValue(useMemo(() => selectAtom(atom, (s) => s[key]), [key])) | ||
|
||
export const useUISettingSelector = < | ||
T extends keyof ReturnType<typeof getUISettings>, | ||
S extends ReturnType<typeof getUISettings>, | ||
R = S[T], | ||
>( | ||
selector: (s: S) => R, | ||
): R => { | ||
const stableSelector = useRefValue(selector) | ||
|
||
return useAtomValue( | ||
// @ts-expect-error | ||
Check warning on line 58 in src/renderer/src/atoms/ui.ts GitHub Actions / Lint and Typecheck (18.x)
|
||
useMemo(() => selectAtom(atom, stableSelector.current), [stableSelector]), | ||
) | ||
} | ||
|
||
export const setUISetting = <K extends keyof ReturnType<typeof getUISettings>>( | ||
key: K, | ||
value: ReturnType<typeof getUISettings>[K], | ||
) => { | ||
setUISettings({ | ||
...getUISettings(), | ||
[key]: value, | ||
}) | ||
} | ||
|
||
export const clearUISettings = () => { | ||
setUISettings(createDefaultSettings()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useReduceMotion } from "@renderer/hooks/biz/useReduceMotion" | ||
import type { MotionProps } from "framer-motion" | ||
import { m as M } from "framer-motion" | ||
import { createElement, forwardRef } from "react" | ||
|
||
const cacheMap = new Map<string, any>() | ||
export const m: typeof M = new Proxy(M, { | ||
get(target, p: string) { | ||
const Component = target[p] | ||
|
||
if (cacheMap.has(p)) { | ||
return cacheMap.get(p) | ||
} | ||
const MotionComponent = forwardRef((props: MotionProps, ref) => { | ||
const shouldReduceMotion = useReduceMotion() | ||
const nextProps = { ...props } | ||
if (shouldReduceMotion) { | ||
if (props.exit) { | ||
delete nextProps.exit | ||
} | ||
|
||
if (props.initial) { | ||
nextProps.initial = true | ||
} | ||
} | ||
|
||
return createElement(Component, { ...nextProps, ref }) | ||
}) | ||
|
||
cacheMap.set(p, MotionComponent) | ||
|
||
return MotionComponent | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/renderer/src/components/ui/code-highlighter/copy-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useUISettingKey } from "@renderer/atoms/ui" | ||
import { useReducedMotion } from "framer-motion" | ||
|
||
export const useReduceMotion = () => { | ||
const appReduceMotion = useUISettingKey("reduceMotion") | ||
const reduceMotion = useReducedMotion() | ||
return appReduceMotion || reduceMotion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
const ns = "follow" | ||
export const buildStorageNS = (key: string) => `${ns}:${key}` | ||
export const getStorageNS = (key: string) => `${ns}:${key}` | ||
/** | ||
* @deprecated Use `getStorageNS` instead. | ||
*/ | ||
export const buildStorageKey = getStorageNS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.