diff --git a/app/web/src/nova/ed/panel/side/style/panel/advanced.tsx b/app/web/src/nova/ed/panel/side/style/panel/advanced.tsx index 98b9c8d9..45452432 100644 --- a/app/web/src/nova/ed/panel/side/style/panel/advanced.tsx +++ b/app/web/src/nova/ed/panel/side/style/panel/advanced.tsx @@ -1,26 +1,20 @@ import { FC } from "react"; -import { useGlobal } from "web-utils"; +import { useGlobal, useLocal } from "web-utils"; import { IItem } from "../../../../../../utils/types/item"; -import { FNAdv } from "../../../../../../utils/types/meta-fn"; import { ISection } from "../../../../../../utils/types/section"; import { IText } from "../../../../../../utils/types/text"; +import { Popover } from "../../../../../../utils/ui/popover"; import { EDGlobal } from "../../../../logic/ed-global"; +import { SimpleMonaco } from "../../simple-monaco"; import { Button } from "../ui/Button"; -import { getActiveMeta } from "../../../../logic/active/get-meta"; - -type AdvUpdate = { - adv?: FNAdv; -}; export const PanelAdv: FC<{ value: ISection | IItem | IText; mode: "desktop" | "mobile"; - update: (key: T, val: AdvUpdate[T]) => void; + update: (key: T, val: string) => void; }> = ({ value, update }) => { const p = useGlobal(EDGlobal, "EDITOR"); - const meta = getActiveMeta(p); - const adv = meta?.mitem?.get("adv")?.toJSON() || ({} as any); - + const local = useLocal({ openTypings: false, typings: "" }); return ( <>
-
+ { + local.typings = value; + local.render(); + }} + value={local.typings} + lang="typescript" + /> +
+ } + open={local.openTypings} + onOpenChange={(open) => { + try { + if (open) { + local.typings = + value.typings || + `\ +const typings = { + _raw: { + } +}`; + } else { + update("typings", local.typings); + } + } catch (e) { + console.log(e); + } + local.openTypings = open; + local.render(); + }} className={cx( "bg-white p-[2px] border flex flex-1 border-gray-300", css` > * { flex: 1; } - `, - !!adv.css && - css` - button { - background: #e8ffe8; - border-bottom: solid green !important; - } - ` + ` )} > -
-
* { - flex: 1; - } - `, - !!adv.html && [ - css` - button { - background: #e8f5ff; - border-bottom: 2px solid blue !important; - } - `, - ] - )} - > - -
-
* { - flex: 1; - } - `, - !!adv.js && [ - css` - button { - background: #fff4e8; - border-bottom: 2px solid orange !important; - } - `, - ] - )} - > - -
+ ); diff --git a/app/web/src/nova/ed/panel/side/style/panel/link.tsx b/app/web/src/nova/ed/panel/side/style/panel/link.tsx deleted file mode 100644 index 9a098447..00000000 --- a/app/web/src/nova/ed/panel/side/style/panel/link.tsx +++ /dev/null @@ -1,111 +0,0 @@ -import { - FC, - TextareaHTMLAttributes, - useCallback, - useEffect, - useRef, -} from "react"; -import { useLocal } from "web-utils"; -import { IItem } from "../../../../../../utils/types/item"; -import { FNLinkTag } from "../../../../../../utils/types/meta-fn"; -import { ISection } from "../../../../../../utils/types/section"; -import { IText } from "../../../../../../utils/types/text"; -import { responsiveVal } from "../tools/responsive-val"; - -type LinkTagUpdate = { - linktag: FNLinkTag; -}; - -export const PanelLink: FC<{ - value: ISection | IItem | IText; - mode: "desktop" | "mobile"; - update: ( - key: T, - val: LinkTagUpdate[T] - ) => void; -}> = ({ value, update, mode }) => { - const linktag = responsiveVal(value, "linktag", mode, {}); - const local = useLocal({ link: linktag.link }); - - useEffect(() => { - local.link = linktag.link; - local.render(); - }, [linktag.link]); - - return ( - <> - { - local.link = e.currentTarget.value; - local.render(); - }} - onBlur={() => { - update("linktag", { ...linktag, link: local.link }); - }} - /> - - ); -}; - -export function AutoHeightTextarea({ - minRows = 1, - ...props -}: TextareaHTMLAttributes & { minRows?: number }) { - const ref = useRef(null); - - const calculateAndSetHeight = useCallback(() => { - if (!ref.current) { - return; - } - const { - borderBottomWidth, - borderTopWidth, - boxSizing, - lineHeight, - paddingBottom, - paddingTop, - } = window.getComputedStyle(ref.current); - ref.current.style.height = lineHeight; // set height temporarily to a single row to obtain scrollHeight, disregarding empty space after text (otherwise, scrollHeight would be equal to the height of the element) - this solves auto-shrinking of the textarea (it's not needed for auto-growing it) - const { scrollHeight } = ref.current; // scrollHeight = content height + padding top + padding bottom - - if (boxSizing === "border-box") { - const minHeight = - parseFloat(lineHeight) * minRows + - parseFloat(paddingTop) + - parseFloat(paddingBottom) + - parseFloat(borderTopWidth) + - parseFloat(borderBottomWidth); - const allTextHeight = - scrollHeight + - parseFloat(borderTopWidth) + - parseFloat(borderBottomWidth); - ref.current.style.height = `${Math.max(minHeight, allTextHeight)}px`; - } else if (boxSizing === "content-box") { - const minHeight = parseFloat(lineHeight) * minRows; - const allTextHeight = - scrollHeight - parseFloat(paddingTop) - parseFloat(paddingBottom); - ref.current.style.height = `${Math.max(minHeight, allTextHeight)}px`; - } else { - console.error("Unknown box-sizing value."); - } - }, [minRows]); - - useEffect(() => { - calculateAndSetHeight(); - }, [calculateAndSetHeight]); - - const handleChange: React.ChangeEventHandler = (e) => { - calculateAndSetHeight(); - if (props.onChange) { - props.onChange(e); - } - }; - calculateAndSetHeight(); - - return