"use client"; import { Popover } from "components/Popover"; import { Color } from "react-aria-components"; import { LeafletBackgroundPicker, PageThemePickers, } from "./Pickers/PageThemePickers"; import { PageWidthSetter } from "./Pickers/PageWidthSetter"; import { useMemo, useState } from "react"; import { ReplicacheMutators, useEntity, useReplicache } from "src/replicache"; import { Replicache } from "replicache"; import { FilterAttributes } from "src/replicache/attributes"; import { colorToString } from "components/ThemeManager/useColorAttribute"; import { useEntitySetContext } from "components/EntitySetProvider"; import { ActionButton } from "components/ActionBar/ActionButton"; import { CheckboxChecked } from "components/Icons/CheckboxChecked"; import { CheckboxEmpty } from "components/Icons/CheckboxEmpty"; import { PaintSmall } from "components/Icons/PaintSmall"; import { AccentPickers } from "./Pickers/AccentPickers"; import { useLeafletPublicationData } from "components/PageSWRDataProvider"; import { useIsMobile } from "src/hooks/isMobile"; import { Toggle } from "components/Toggle"; import { getFontConfig, getFontFamilyValue } from "src/fonts"; export type pickers = | "null" | "leaflet" | "page" | "accent-1" | "accent-2" | "text" | "highlight-1" | "highlight-2" | "highlight-3" | "page-background-image" | "page-width"; export function setColorAttribute( rep: Replicache | null, entity: string, ) { return (attribute: keyof FilterAttributes<{ type: "color" }>) => (color: Color) => rep?.mutate.assertFact({ entity, attribute, data: { type: "color", value: colorToString(color, "hsba") }, }); } export const ThemePopover = (props: { entityID: string; home?: boolean }) => { let { rep } = useReplicache(); let { data: pub } = useLeafletPublicationData(); let isMobile = useIsMobile(); // I need to get these variables from replicache and then write them to the DB. I also need to parse them into a state that can be used here. let permission = useEntitySetContext().permissions.write; let leafletBGImage = useEntity(props.entityID, "theme/background-image"); let leafletBGRepeat = useEntity( props.entityID, "theme/background-image-repeat", ); let [openPicker, setOpenPicker] = useState( props.home === true ? "leaflet" : "null", ); let set = useMemo(() => { return setColorAttribute(rep, props.entityID); }, [rep, props.entityID]); if (!permission) return null; if (pub?.publications) return null; return ( <> } label="Theme" />} > ); }; export const ThemeSetterContent = (props: { entityID: string; home?: boolean; }) => { let { rep } = useReplicache(); let { data: pub } = useLeafletPublicationData(); // I need to get these variables from replicache and then write them to the DB. I also need to parse them into a state that can be used here. let permission = useEntitySetContext().permissions.write; let leafletBGImage = useEntity(props.entityID, "theme/background-image"); let leafletBGRepeat = useEntity( props.entityID, "theme/background-image-repeat", ); let [openPicker, setOpenPicker] = useState( props.home === true ? "leaflet" : "null", ); let set = useMemo(() => { return setColorAttribute(rep, props.entityID); }, [rep, props.entityID]); if (!permission) return null; if (pub?.publications) return null; return (
{!props.home && ( setOpenPicker("null")} /> )}
{ e.currentTarget === e.target && setOpenPicker("leaflet"); }} style={{ backgroundImage: leafletBGImage ? `url(${leafletBGImage.data.src})` : undefined, backgroundRepeat: leafletBGRepeat ? "repeat" : "no-repeat", backgroundPosition: "center", backgroundSize: !leafletBGRepeat ? "cover" : `calc(${leafletBGRepeat.data.value}px / 2 )`, }} className={`bg-bg-leaflet px-3 pt-4 pb-0 mb-2 flex flex-col gap-4 rounded-md border border-border`} > setOpenPicker(pickers)} home={props.home} />
setOpenPicker(pickers)} />
{!props.home && }
); }; function WatermarkSetter(props: { entityID: string }) { let { rep } = useReplicache(); let checked = useEntity(props.entityID, "theme/page-leaflet-watermark"); function handleToggle() { rep?.mutate.assertFact({ entity: props.entityID, attribute: "theme/page-leaflet-watermark", data: { type: "boolean", value: !checked?.data.value }, }); } return (
{ handleToggle(); }} disabledColor1="#8C8C8C" disabledColor2="#DBDBDB" >
Show Leaflet Watermark
Help us spread the word!
); } const SampleButton = (props: { entityID: string; setOpenPicker: (thisPicker: pickers) => void; }) => { return (
{ e.target === e.currentTarget && props.setOpenPicker("accent-1"); }} className="pointer-cursor font-bold relative text-center text-lg py-2 rounded-md bg-accent-1 text-accent-2 shadow-md flex items-center justify-center" >
{ props.setOpenPicker("accent-2"); }} > Example Button
); }; const SamplePage = (props: { entityID: string; home: boolean | undefined; setOpenPicker: (picker: "page" | "text") => void; }) => { let pageBGImage = useEntity(props.entityID, "theme/card-background-image"); let pageBGRepeat = useEntity( props.entityID, "theme/card-background-image-repeat", ); let pageBGOpacity = useEntity( props.entityID, "theme/card-background-image-opacity", ); let pageBorderHidden = useEntity(props.entityID, "theme/card-border-hidden") ?.data.value; // Read font values directly since the popover is portalled outside .leafletWrapper let headingFontId = useEntity(props.entityID, "theme/heading-font")?.data.value; let bodyFontId = useEntity(props.entityID, "theme/body-font")?.data.value; let bodyFontFamily = getFontFamilyValue(getFontConfig(bodyFontId)); let headingFontFamily = getFontFamilyValue(getFontConfig(headingFontId)); return (
{ e.currentTarget === e.target && props.setOpenPicker("page"); }} className={` text-primary relative ${ pageBorderHidden ? "py-2 px-0 border border-transparent" : `cursor-pointer p-2 border border-border border-b-transparent shadow-md ${props.home ? "rounded-md " : "rounded-t-lg "}` }`} style={ pageBorderHidden ? undefined : { backgroundColor: "rgba(var(--bg-page), var(--bg-page-alpha))", } } >

{ props.setOpenPicker("text"); }} className="cursor-pointer font-bold w-fit" style={{ fontFamily: headingFontFamily }} > Hello!

props.setOpenPicker("text")}> Welcome to{" "} Leaflet — a fun and easy way to make, share, and collab on little bits of paper ✨
); }; export const SectionArrow = (props: { fill: string; stroke: string; className: string; }) => { return ( ); };