import { useEditorStates } from "src/state/useEditorState"; import { useUIState } from "src/useUIState"; import { schema } from "components/Blocks/TextBlock/schema"; import { TextSelection } from "prosemirror-state"; import { TextDecorationButton, toggleMarkInFocusedBlock, } from "./TextDecorationButton"; import * as Popover from "@radix-ui/react-popover"; import * as Tooltip from "@radix-ui/react-tooltip"; import { theme } from "../../tailwind.config"; import { pickers, SectionArrow, setColorAttribute, } from "components/ThemeManager/ThemeSetter"; import { ColorPicker } from "components/ThemeManager/Pickers/ColorPicker"; import { useEntity, useReplicache } from "src/replicache"; import { useEffect, useMemo, useState } from "react"; import { useColorAttribute } from "components/ThemeManager/useColorAttribute"; import { rangeHasMark } from "src/utils/prosemirror/rangeHasMark"; import { Separator, ShortcutKey } from "components/Layout"; import { ToolbarButton } from "."; import { NestedCardThemeProvider } from "components/ThemeManager/ThemeProvider"; import { Props } from "components/Icons/Props"; import { PopoverArrow } from "components/Icons/PopoverArrow"; import { ArrowRightTiny } from "components/Icons/ArrowRightTiny"; import { PaintSmall } from "components/Icons/PaintSmall"; import { isMac } from "src/utils/isDevice"; export const HighlightButton = (props: { lastUsedHighlight: string; setToolbarState: (s: "highlight") => void; }) => { return (
Highlight
{isMac() ? ( <> +{" "} Ctrl +{" "} H ) : ( <> Ctrl +{" "} Meta +{" "} H )}
} attrs={{ color: props.lastUsedHighlight }} mark={schema.marks.highlight} icon={ } /> { props.setToolbarState("highlight"); }} className="-ml-1" > ); }; export const HighlightToolbar = (props: { onClose: () => void; lastUsedHighlight: "1" | "2" | "3"; setLastUsedHighlight: (color: "1" | "2" | "3") => void; pageID: string; }) => { let focusedBlock = useUIState((s) => s.focusedEntity); let focusedEditor = useEditorStates((s) => focusedBlock ? s.editorStates[focusedBlock.entityID] : null, ); let [initialRender, setInitialRender] = useState(true); useEffect(() => { setInitialRender(false); }, []); useEffect(() => { // we're not returning initialRender in the dependancy array on purpose! although admittedly, can't remember why not... if (initialRender) return; if (focusedEditor) props.onClose(); }, [focusedEditor, props]); return (
); }; export const HighlightColorButton = (props: { color: "1" | "2" | "3"; lastUsedHighlight: "1" | "2" | "3"; setLastUsedHightlight: (color: "1" | "2" | "3") => void; }) => { let focusedBlock = useUIState((s) => s.focusedEntity); let focusedEditor = useEditorStates((s) => focusedBlock ? s.editorStates[focusedBlock.entityID] : null, ); let hasMark: boolean = false; if (focusedEditor) { let { to, from, $cursor } = focusedEditor.editor.selection as TextSelection; let mark = rangeHasMark( focusedEditor.editor, schema.marks.highlight, from, to, ); if ($cursor) hasMark = !!schema.marks.highlight.isInSet( focusedEditor.editor.storedMarks || $cursor.marks(), ); else { hasMark = !!mark; } } return ( ); }; export const HighlightColorSettings = (props: { pageID: string }) => { let { rep, rootEntity } = useReplicache(); let set = useMemo(() => { return setColorAttribute(rep, rootEntity); }, [rep, rootEntity]); let [openPicker, setOpenPicker] = useState("null"); let backgroundImage = useEntity(rootEntity, "theme/background-image"); let backgroundRepeat = useEntity(rootEntity, "theme/background-image-repeat"); let pageBGImage = useEntity(props.pageID, "theme/card-background-image"); let pageBGRepeat = useEntity( props.pageID, "theme/card-background-image-repeat", ); let pageBGOpacity = useEntity( props.pageID, "theme/card-background-image-opacity", ); let highlight1Value = useColorAttribute(rootEntity, "theme/highlight-1"); let highlight2Value = useColorAttribute(rootEntity, "theme/highlight-2"); let highlight3Value = useColorAttribute(rootEntity, "theme/highlight-3"); return ( { e.preventDefault(); }} > Change Highlight Colors
{ set("theme/highlight-1")( color.withChannelValue("alpha", 1), ); }} thisPicker={"highlight-1"} openPicker={openPicker} setOpenPicker={setOpenPicker} closePicker={() => setOpenPicker("null")} /> setOpenPicker("null")} /> setOpenPicker("null")} />

Pick your highlights!

This is what{" "} Highlights look like
Make them{" "} whatever you want!
Happy theming!
); }; const HighlightSmall = (props: { highlightColor: string } & Props) => { let { highlightColor, ...svgProps } = props; return ( ); };