A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
chore: publish
thecodrr11d587579928
diff --git a/packages/editor/dist/cjs/components/button.js b/packages/editor/dist/cjs/components/button.jsindex 1a56f98c3..4c40a0a92 100644--- a/packages/editor/dist/cjs/components/button.js+++ b/packages/editor/dist/cjs/components/button.js@@ -20,6 +20,7 @@ exports.Button = (0, react_1.forwardRef)((props, forwardedRef) => {var _a;const { sx } = props, buttonProps = __rest(props, ["sx"]);const hoverBg = ((_a = sx === null || sx === void 0 ? void 0 : sx[":hover"]) === null || _a === void 0 ? void 0 : _a["bg"]) || "hover";+ const bg = (sx === null || sx === void 0 ? void 0 : sx["bg"]) || "unset";const buttonRef = (0, react_1.useRef)();(0, react_2.useEffect)(() => {if (!buttonRef.current)@@ -38,11 +39,11 @@ exports.Button = (0, react_1.forwardRef)((props, forwardedRef) => {const onMouseDown = (0, react_1.useCallback)((e) => {e.preventDefault();}, []);- return ((0, jsx_runtime_1.jsx)(rebass_1.Button, Object.assign({}, buttonProps, { sx: Object.assign(Object.assign({}, sx), { ":hover": { bg: ["transparent", hoverBg] }, ":active": { bg: hoverBg } }), ref: (ref) => {+ return ((0, jsx_runtime_1.jsx)(rebass_1.Button, Object.assign({}, buttonProps, { sx: Object.assign(Object.assign({}, sx), { ":hover": { bg: [bg, hoverBg] }, ":active": { bg: hoverBg } }), ref: (ref) => {buttonRef.current = ref;if (typeof forwardedRef === "function")forwardedRef(ref);else if (forwardedRef)forwardedRef.current = ref;- }, onClick: props.onClick, onMouseDown: () => { } })));+ }, onClick: props.onClick })));});diff --git a/packages/editor/dist/cjs/components/menu/index.d.ts b/packages/editor/dist/cjs/components/menu/index.d.tsindex 6af5e4dea..70086f947 100644--- a/packages/editor/dist/cjs/components/menu/index.d.ts+++ b/packages/editor/dist/cjs/components/menu/index.d.ts@@ -1,7 +1,7 @@import { PropsWithChildren } from "react";import { FlexProps } from "rebass";import { MenuItem as MenuItemType } from "./types";-import { PopupPresenterProps as _PopupPresenterProps } from "../popup-presenter";+import { PopupPresenterProps } from "../popup-presenter";declare type MenuProps = MenuContainerProps & {items?: MenuItemType[];onClose: () => void;@@ -10,6 +10,6 @@ export declare function Menu(props: MenuProps): JSX.Element;declare type MenuContainerProps = FlexProps & {title?: string;};-export declare type MenuPresenterProps = _PopupPresenterProps & MenuProps;+export declare type MenuPresenterProps = PopupPresenterProps & MenuProps;export declare function MenuPresenter(props: PropsWithChildren<MenuPresenterProps>): JSX.Element;export {};diff --git a/packages/editor/dist/cjs/components/popuppresenter/index.d.ts b/packages/editor/dist/cjs/components/popuppresenter/index.d.tsindex 14ae76e5d..677f9164c 100644--- a/packages/editor/dist/cjs/components/popuppresenter/index.d.ts+++ b/packages/editor/dist/cjs/components/popuppresenter/index.d.ts@@ -12,16 +12,23 @@ export declare type PopupPresenterProps = {movable?: boolean;};export declare function PopupPresenter(props: PropsWithChildren<PopupPresenterProps>): JSX.Element | null;-export declare type PopupWrapperProps = {- id: string;- group: string;+export declare type PopupWrapperProps = UsePopupHandlerOptions & {position: PositionOptions;- isOpen: boolean;- onClosed?: () => void;renderPopup: (closePopup: () => void) => React.ReactNode;- autoCloseOnUnmount?: boolean;} & Partial<Omit<PopupPresenterProps, "onClose">>;export declare function PopupWrapper(props: PopupWrapperProps): null;+declare type UsePopupHandlerOptions = {+ id: string;+ group: string;+ isOpen: boolean;+ autoCloseOnUnmount?: boolean;+ onClosed?: () => void;+ onClosePopup?: () => void;+};+export declare function usePopupHandler(options: UsePopupHandlerOptions): {+ isPopupOpen: boolean;+ closePopup: (popupId: string) => void;+};declare type ShowPopupOptions = {theme: Theme;popup: (closePopup: () => void) => React.ReactNode;diff --git a/packages/editor/dist/cjs/components/popuppresenter/index.js b/packages/editor/dist/cjs/components/popuppresenter/index.jsindex c0900f1f7..a0ea52ace 100644--- a/packages/editor/dist/cjs/components/popuppresenter/index.js+++ b/packages/editor/dist/cjs/components/popuppresenter/index.js@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {return (mod && mod.__esModule) ? mod : { "default": mod };};Object.defineProperty(exports, "__esModule", { value: true });-exports.showPopup = exports.PopupWrapper = exports.PopupPresenter = void 0;+exports.showPopup = exports.usePopupHandler = exports.PopupWrapper = exports.PopupPresenter = void 0;const jsx_runtime_1 = require("react/jsx-runtime");const react_1 = require("react");const rebass_1 = require("rebass");@@ -154,6 +154,32 @@ exports.PopupPresenter = PopupPresenter;function PopupWrapper(props) {let { id, group, position, renderPopup, isOpen, onClosed, autoCloseOnUnmount } = props, presenterProps = __rest(props, ["id", "group", "position", "renderPopup", "isOpen", "onClosed", "autoCloseOnUnmount"]);const PopupRenderer = (0, popuprenderer_1.usePopupRenderer)();+ const { closePopup, isPopupOpen } = usePopupHandler(props);+ (0, react_1.useEffect)(() => {+ if (PopupRenderer && isPopupOpen) {+ PopupRenderer.openPopup(id, function Popup({ id }) {+ const isPopupOpen = (0, toolbarstore_1.useToolbarStore)((store) => !!store.openedPopups[id]);+ (0, react_1.useEffect)(() => {+ if (!isPopupOpen) {+ PopupRenderer.closePopup(id);+ }+ }, [isPopupOpen]);+ return ((0, jsx_runtime_1.jsx)(PopupPresenter, Object.assign({ isOpen: isPopupOpen, onClose: () => closePopup(id), position: position, blocking: true, focusOnRender: true }, presenterProps, { children: (0, jsx_runtime_1.jsx)(rebass_1.Box, Object.assign({ sx: {+ boxShadow: "menu",+ borderRadius: "default",+ overflow: "hidden",+ // width,+ } }, { children: (0, jsx_runtime_1.jsx)(popuprenderer_1.EditorContext.Consumer, { children: () => {+ return renderPopup(() => PopupRenderer.closePopup(id));+ } }) })) }), id));+ });+ }+ }, [PopupRenderer, isPopupOpen]);+ return null;+}+exports.PopupWrapper = PopupWrapper;+function usePopupHandler(options) {+ let { autoCloseOnUnmount, group, isOpen, id, onClosed, onClosePopup } = options;const isPopupOpen = (0, toolbarstore_1.useToolbarStore)((store) => !!store.openedPopups[id]);const openPopup = (0, toolbarstore_1.useToolbarStore)((store) => store.openPopup);const closePopup = (0, toolbarstore_1.useToolbarStore)((store) => store.closePopup);@@ -171,9 +197,9 @@ function PopupWrapper(props) {if (!autoCloseOnUnmount)return;return () => {- PopupRenderer === null || PopupRenderer === void 0 ? void 0 : PopupRenderer.closePopup(id);+ onClosePopup === null || onClosePopup === void 0 ? void 0 : onClosePopup();};- }, [autoCloseOnUnmount, id]);+ }, [autoCloseOnUnmount, onClosePopup]);(0, react_1.useEffect)(() => {if (!isPopupOpen)onClosed === null || onClosed === void 0 ? void 0 : onClosed();@@ -187,29 +213,9 @@ function PopupWrapper(props) {if (!isOpen)closePopup(id);}, [isOpen, id, group, closePopup]);- (0, react_1.useEffect)(() => {- if (PopupRenderer && isPopupOpen) {- PopupRenderer.openPopup(id, function Popup({ id }) {- const isPopupOpen = (0, toolbarstore_1.useToolbarStore)((store) => !!store.openedPopups[id]);- (0, react_1.useEffect)(() => {- if (!isPopupOpen) {- PopupRenderer.closePopup(id);- }- }, [isPopupOpen]);- return ((0, jsx_runtime_1.jsx)(PopupPresenter, Object.assign({ isOpen: isPopupOpen, onClose: () => closePopup(id), position: position, blocking: true, focusOnRender: true }, presenterProps, { children: (0, jsx_runtime_1.jsx)(rebass_1.Box, Object.assign({ sx: {- boxShadow: "menu",- borderRadius: "default",- overflow: "hidden",- // width,- } }, { children: (0, jsx_runtime_1.jsx)(popuprenderer_1.EditorContext.Consumer, { children: () => {- return renderPopup(() => PopupRenderer.closePopup(id));- } }) })) }), id));- });- }- }, [PopupRenderer, isPopupOpen]);- return null;+ return { isPopupOpen, closePopup };}-exports.PopupWrapper = PopupWrapper;+exports.usePopupHandler = usePopupHandler;function showPopup(options) {const { theme, popup } = options, props = __rest(options, ["theme", "popup"]);function hide() {diff --git a/packages/editor/dist/cjs/toolbar/components/dropdown.d.ts b/packages/editor/dist/cjs/toolbar/components/dropdown.d.tsindex f1011513b..d383ea4a0 100644--- a/packages/editor/dist/cjs/toolbar/components/dropdown.d.ts+++ b/packages/editor/dist/cjs/toolbar/components/dropdown.d.ts@@ -1,6 +1,8 @@/// <reference types="react" />import { MenuItem } from "../../components/menu/types";declare type DropdownProps = {+ id: string;+ group: string;selectedItem: string | JSX.Element;items: MenuItem[];buttonRef?: React.MutableRefObject<HTMLButtonElement | undefined>;diff --git a/packages/editor/dist/cjs/toolbar/components/dropdown.js b/packages/editor/dist/cjs/toolbar/components/dropdown.jsindex 6e4c15cf9..54b6344cb 100644--- a/packages/editor/dist/cjs/toolbar/components/dropdown.js+++ b/packages/editor/dist/cjs/toolbar/components/dropdown.js@@ -10,13 +10,21 @@ const toolbarstore_1 = require("../stores/toolbarstore");const menu_1 = require("../../components/menu");const dom_1 = require("../utils/dom");const button_1 = require("../../components/button");+const popuppresenter_1 = require("../../components/popuppresenter");function Dropdown(props) {- const { items, selectedItem, buttonRef, menuWidth } = props;+ let { id, group, items, selectedItem, buttonRef, menuWidth } = props;const internalRef = (0, react_1.useRef)();const [isOpen, setIsOpen] = (0, react_1.useState)(false);const toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();const isMobile = (0, toolbarstore_1.useIsMobile)();const isBottom = toolbarLocation === "bottom";+ const { closePopup, isPopupOpen } = (0, popuppresenter_1.usePopupHandler)({+ group,+ id,+ isOpen,+ onClosed: () => setIsOpen(false),+ onClosePopup: () => closePopup(id),+ });return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(button_1.Button, Object.assign({ ref: (ref) => {internalRef.current = ref;if (buttonRef)@@ -24,7 +32,7 @@ function Dropdown(props) {}, sx: {p: 1,m: 0,- bg: isOpen ? "hover" : "transparent",+ bg: isPopupOpen ? "hover" : "transparent",mr: 1,display: "flex",alignItems: "center",@@ -32,7 +40,7 @@ function Dropdown(props) {":last-of-type": {mr: 0,},- }, onClick: () => setIsOpen((s) => !s), onMouseDown: (e) => e.preventDefault() }, { children: [typeof selectedItem === "string" ? ((0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ sx: { fontSize: "subBody", mr: 1, color: "text" } }, { children: selectedItem }))) : (selectedItem), (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: isBottom ? icons_1.Icons.chevronUp : icons_1.Icons.chevronDown, size: "small", color: "text" })] })), (0, jsx_runtime_1.jsx)(menu_1.MenuPresenter, { isOpen: isOpen, items: items, onClose: () => setIsOpen(false), position: {+ }, onClick: () => setIsOpen((s) => !s), onMouseDown: (e) => e.preventDefault() }, { children: [typeof selectedItem === "string" ? ((0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ sx: { fontSize: "subBody", mr: 1, color: "text" } }, { children: selectedItem }))) : (selectedItem), (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: isBottom ? icons_1.Icons.chevronUp : icons_1.Icons.chevronDown, size: "small", color: "text" })] })), (0, jsx_runtime_1.jsx)(menu_1.MenuPresenter, { isOpen: isPopupOpen, items: items, onClose: () => closePopup(id), position: {target: isBottom? (0, dom_1.getToolbarElement)(): internalRef.current || "mouse",diff --git a/packages/editor/dist/cjs/toolbar/components/splitbutton.js b/packages/editor/dist/cjs/toolbar/components/splitbutton.jsindex ff04d1eb7..c780d5236 100644--- a/packages/editor/dist/cjs/toolbar/components/splitbutton.js+++ b/packages/editor/dist/cjs/toolbar/components/splitbutton.js@@ -30,18 +30,17 @@ function _SplitButton(props) {const toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ ref: ref, sx: {borderRadius: "default",- bg: toggled ? "hover" : "transparent",- ":hover": { bg: [toggled ? "hover" : "transparent", "hover"] },- ":active": { bg: toggled ? "hover" : "transparent" },- } }, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, toolButtonProps, { toggled: false })), (0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ sx: {+ } }, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, toolButtonProps, { sx: { mr: 0, ":hover": { bg: "hover" } }, toggled: false })), (0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ sx: {+ flexShrink: 0,p: 0,m: 0,- bg: "transparent",+ px: "3px",+ bg: "bgSecondary",":hover": { bg: "hover" },":last-of-type": {mr: 0,},- }, onClick: onOpen }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: toolbarLocation === "bottom" ? icons_1.Icons.chevronUp : icons_1.Icons.chevronDown, color: "text", size: "small" }) }))] })), children] }));+ }, onClick: onOpen }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: toolbarLocation === "bottom" ? icons_1.Icons.chevronUp : icons_1.Icons.chevronDown, color: "text", size: "small", sx: { flexShrink: 0 } }) }))] })), children] }));}exports.SplitButton = react_2.default.memo(_SplitButton, (prev, next) => {return (prev.toggled === next.toggled &&diff --git a/packages/editor/dist/cjs/toolbar/tools/font.js b/packages/editor/dist/cjs/toolbar/tools/font.jsindex 01e0fe9eb..b230a86a5 100644--- a/packages/editor/dist/cjs/toolbar/tools/font.js+++ b/packages/editor/dist/cjs/toolbar/tools/font.js@@ -37,7 +37,7 @@ function FontFamily(props) {const currentFontFamily = ((_b = (_a = Object.entries(fontFamilies).find(([key, value]) => editor.isActive("textStyle", { fontFamily: value }))) === null || _a === void 0 ? void 0 : _a.map((a) => a)) === null || _b === void 0 ? void 0 : _b.at(0)) || "Sans-serif";const items = (0, react_1.useMemo)(() => toMenuItems(editor, currentFontFamily), [currentFontFamily]);- return ((0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { selectedItem: currentFontFamily, items: items, menuWidth: 130 }));+ return ((0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { id: "fontFamily", group: "font", selectedItem: currentFontFamily, items: items, menuWidth: 130 }));}exports.FontFamily = FontFamily;function toMenuItems(editor, currentFontFamily) {diff --git a/packages/editor/dist/cjs/toolbar/tools/headings.js b/packages/editor/dist/cjs/toolbar/tools/headings.jsindex 9c7b79797..b43f7b60b 100644--- a/packages/editor/dist/cjs/toolbar/tools/headings.js+++ b/packages/editor/dist/cjs/toolbar/tools/headings.js@@ -11,7 +11,7 @@ function Headings(props) {const toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();const currentHeadingLevel = defaultLevels.find((level) => editor.isActive("heading", { level }));const items = (0, react_1.useMemo)(() => toMenuItems(editor, toolbarLocation, currentHeadingLevel), [currentHeadingLevel]);- return ((0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { selectedItem: currentHeadingLevel ? `Heading ${currentHeadingLevel}` : "Paragraph", items: items, menuWidth: 130 }));+ return ((0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { id: "headings", group: "headings", selectedItem: currentHeadingLevel ? `Heading ${currentHeadingLevel}` : "Paragraph", items: items, menuWidth: 130 }));}exports.Headings = Headings;function toMenuItems(editor, toolbarLocation, currentHeadingLevel) {diff --git a/packages/editor/dist/es/components/button.js b/packages/editor/dist/es/components/button.jsindex fead075e4..48c152c58 100644--- a/packages/editor/dist/es/components/button.js+++ b/packages/editor/dist/es/components/button.js@@ -17,6 +17,7 @@ export const Button = forwardRef((props, forwardedRef) => {var _a;const { sx } = props, buttonProps = __rest(props, ["sx"]);const hoverBg = ((_a = sx === null || sx === void 0 ? void 0 : sx[":hover"]) === null || _a === void 0 ? void 0 : _a["bg"]) || "hover";+ const bg = (sx === null || sx === void 0 ? void 0 : sx["bg"]) || "unset";const buttonRef = useRef();useEffect(() => {if (!buttonRef.current)@@ -35,11 +36,11 @@ export const Button = forwardRef((props, forwardedRef) => {const onMouseDown = useCallback((e) => {e.preventDefault();}, []);- return (_jsx(RebassButton, Object.assign({}, buttonProps, { sx: Object.assign(Object.assign({}, sx), { ":hover": { bg: ["transparent", hoverBg] }, ":active": { bg: hoverBg } }), ref: (ref) => {+ return (_jsx(RebassButton, Object.assign({}, buttonProps, { sx: Object.assign(Object.assign({}, sx), { ":hover": { bg: [bg, hoverBg] }, ":active": { bg: hoverBg } }), ref: (ref) => {buttonRef.current = ref;if (typeof forwardedRef === "function")forwardedRef(ref);else if (forwardedRef)forwardedRef.current = ref;- }, onClick: props.onClick, onMouseDown: () => { } })));+ }, onClick: props.onClick })));});diff --git a/packages/editor/dist/es/components/menu/index.d.ts b/packages/editor/dist/es/components/menu/index.d.tsindex 6af5e4dea..70086f947 100644--- a/packages/editor/dist/es/components/menu/index.d.ts+++ b/packages/editor/dist/es/components/menu/index.d.ts@@ -1,7 +1,7 @@import { PropsWithChildren } from "react";import { FlexProps } from "rebass";import { MenuItem as MenuItemType } from "./types";-import { PopupPresenterProps as _PopupPresenterProps } from "../popup-presenter";+import { PopupPresenterProps } from "../popup-presenter";declare type MenuProps = MenuContainerProps & {items?: MenuItemType[];onClose: () => void;@@ -10,6 +10,6 @@ export declare function Menu(props: MenuProps): JSX.Element;declare type MenuContainerProps = FlexProps & {title?: string;};-export declare type MenuPresenterProps = _PopupPresenterProps & MenuProps;+export declare type MenuPresenterProps = PopupPresenterProps & MenuProps;export declare function MenuPresenter(props: PropsWithChildren<MenuPresenterProps>): JSX.Element;export {};diff --git a/packages/editor/dist/es/components/menu/index.js b/packages/editor/dist/es/components/menu/index.jsindex 18050aa40..ad1ca07fc 100644--- a/packages/editor/dist/es/components/menu/index.js+++ b/packages/editor/dist/es/components/menu/index.js@@ -16,7 +16,7 @@ import { getPosition } from "../../utils/position";import { useFocus } from "./use-focus";import { MenuSeparator } from "./menu-separator";import { MenuButton } from "./menu-button";-import { PopupPresenter as _PopupPresenter, } from "../popup-presenter";+import { PopupPresenter } from "../popup-presenter";export function Menu(props) {const { items = [], title, onClose } = props, containerProps = __rest(props, ["items", "title", "onClose"]);const hoverTimeout = useRef();@@ -109,5 +109,5 @@ function MenuContainer(props) {}export function MenuPresenter(props) {const { items = [] } = props, restProps = __rest(props, ["items"]);- return (_jsx(_PopupPresenter, Object.assign({}, restProps, { children: props.children ? props.children : _jsx(Menu, Object.assign({ items: items }, restProps)) })));+ return (_jsx(PopupPresenter, Object.assign({}, restProps, { children: props.children ? props.children : _jsx(Menu, Object.assign({ items: items }, restProps)) })));}diff --git a/packages/editor/dist/es/components/popuppresenter/index.d.ts b/packages/editor/dist/es/components/popuppresenter/index.d.tsindex 14ae76e5d..677f9164c 100644--- a/packages/editor/dist/es/components/popuppresenter/index.d.ts+++ b/packages/editor/dist/es/components/popuppresenter/index.d.ts@@ -12,16 +12,23 @@ export declare type PopupPresenterProps = {movable?: boolean;};export declare function PopupPresenter(props: PropsWithChildren<PopupPresenterProps>): JSX.Element | null;-export declare type PopupWrapperProps = {- id: string;- group: string;+export declare type PopupWrapperProps = UsePopupHandlerOptions & {position: PositionOptions;- isOpen: boolean;- onClosed?: () => void;renderPopup: (closePopup: () => void) => React.ReactNode;- autoCloseOnUnmount?: boolean;} & Partial<Omit<PopupPresenterProps, "onClose">>;export declare function PopupWrapper(props: PopupWrapperProps): null;+declare type UsePopupHandlerOptions = {+ id: string;+ group: string;+ isOpen: boolean;+ autoCloseOnUnmount?: boolean;+ onClosed?: () => void;+ onClosePopup?: () => void;+};+export declare function usePopupHandler(options: UsePopupHandlerOptions): {+ isPopupOpen: boolean;+ closePopup: (popupId: string) => void;+};declare type ShowPopupOptions = {theme: Theme;popup: (closePopup: () => void) => React.ReactNode;diff --git a/packages/editor/dist/es/components/popuppresenter/index.js b/packages/editor/dist/es/components/popuppresenter/index.jsindex ac8b78304..dfd5015ed 100644--- a/packages/editor/dist/es/components/popuppresenter/index.js+++ b/packages/editor/dist/es/components/popuppresenter/index.js@@ -147,6 +147,31 @@ export function PopupPresenter(props) {export function PopupWrapper(props) {let { id, group, position, renderPopup, isOpen, onClosed, autoCloseOnUnmount } = props, presenterProps = __rest(props, ["id", "group", "position", "renderPopup", "isOpen", "onClosed", "autoCloseOnUnmount"]);const PopupRenderer = usePopupRenderer();+ const { closePopup, isPopupOpen } = usePopupHandler(props);+ useEffect(() => {+ if (PopupRenderer && isPopupOpen) {+ PopupRenderer.openPopup(id, function Popup({ id }) {+ const isPopupOpen = useToolbarStore((store) => !!store.openedPopups[id]);+ useEffect(() => {+ if (!isPopupOpen) {+ PopupRenderer.closePopup(id);+ }+ }, [isPopupOpen]);+ return (_jsx(PopupPresenter, Object.assign({ isOpen: isPopupOpen, onClose: () => closePopup(id), position: position, blocking: true, focusOnRender: true }, presenterProps, { children: _jsx(Box, Object.assign({ sx: {+ boxShadow: "menu",+ borderRadius: "default",+ overflow: "hidden",+ // width,+ } }, { children: _jsx(EditorContext.Consumer, { children: () => {+ return renderPopup(() => PopupRenderer.closePopup(id));+ } }) })) }), id));+ });+ }+ }, [PopupRenderer, isPopupOpen]);+ return null;+}+export function usePopupHandler(options) {+ let { autoCloseOnUnmount, group, isOpen, id, onClosed, onClosePopup } = options;const isPopupOpen = useToolbarStore((store) => !!store.openedPopups[id]);const openPopup = useToolbarStore((store) => store.openPopup);const closePopup = useToolbarStore((store) => store.closePopup);@@ -164,9 +189,9 @@ export function PopupWrapper(props) {if (!autoCloseOnUnmount)return;return () => {- PopupRenderer === null || PopupRenderer === void 0 ? void 0 : PopupRenderer.closePopup(id);+ onClosePopup === null || onClosePopup === void 0 ? void 0 : onClosePopup();};- }, [autoCloseOnUnmount, id]);+ }, [autoCloseOnUnmount, onClosePopup]);useEffect(() => {if (!isPopupOpen)onClosed === null || onClosed === void 0 ? void 0 : onClosed();@@ -180,27 +205,7 @@ export function PopupWrapper(props) {if (!isOpen)closePopup(id);}, [isOpen, id, group, closePopup]);- useEffect(() => {- if (PopupRenderer && isPopupOpen) {- PopupRenderer.openPopup(id, function Popup({ id }) {- const isPopupOpen = useToolbarStore((store) => !!store.openedPopups[id]);- useEffect(() => {- if (!isPopupOpen) {- PopupRenderer.closePopup(id);- }- }, [isPopupOpen]);- return (_jsx(PopupPresenter, Object.assign({ isOpen: isPopupOpen, onClose: () => closePopup(id), position: position, blocking: true, focusOnRender: true }, presenterProps, { children: _jsx(Box, Object.assign({ sx: {- boxShadow: "menu",- borderRadius: "default",- overflow: "hidden",- // width,- } }, { children: _jsx(EditorContext.Consumer, { children: () => {- return renderPopup(() => PopupRenderer.closePopup(id));- } }) })) }), id));- });- }- }, [PopupRenderer, isPopupOpen]);- return null;+ return { isPopupOpen, closePopup };}export function showPopup(options) {const { theme, popup } = options, props = __rest(options, ["theme", "popup"]);diff --git a/packages/editor/dist/es/toolbar/components/dropdown.d.ts b/packages/editor/dist/es/toolbar/components/dropdown.d.tsindex f1011513b..d383ea4a0 100644--- a/packages/editor/dist/es/toolbar/components/dropdown.d.ts+++ b/packages/editor/dist/es/toolbar/components/dropdown.d.ts@@ -1,6 +1,8 @@/// <reference types="react" />import { MenuItem } from "../../components/menu/types";declare type DropdownProps = {+ id: string;+ group: string;selectedItem: string | JSX.Element;items: MenuItem[];buttonRef?: React.MutableRefObject<HTMLButtonElement | undefined>;diff --git a/packages/editor/dist/es/toolbar/components/dropdown.js b/packages/editor/dist/es/toolbar/components/dropdown.jsindex 8e842475c..651cefe2e 100644--- a/packages/editor/dist/es/toolbar/components/dropdown.js+++ b/packages/editor/dist/es/toolbar/components/dropdown.js@@ -3,17 +3,25 @@ import { useRef, useState } from "react";import { Text } from "rebass";import { Icon } from "./icon";import { Icons } from "../icons";-import { useIsMobile, useToolbarLocation } from "../stores/toolbar-store";+import { useIsMobile, useToolbarLocation, } from "../stores/toolbar-store";import { MenuPresenter } from "../../components/menu";import { getToolbarElement } from "../utils/dom";import { Button } from "../../components/button";+import { usePopupHandler } from "../../components/popup-presenter";export function Dropdown(props) {- const { items, selectedItem, buttonRef, menuWidth } = props;+ let { id, group, items, selectedItem, buttonRef, menuWidth } = props;const internalRef = useRef();const [isOpen, setIsOpen] = useState(false);const toolbarLocation = useToolbarLocation();const isMobile = useIsMobile();const isBottom = toolbarLocation === "bottom";+ const { closePopup, isPopupOpen } = usePopupHandler({+ group,+ id,+ isOpen,+ onClosed: () => setIsOpen(false),+ onClosePopup: () => closePopup(id),+ });return (_jsxs(_Fragment, { children: [_jsxs(Button, Object.assign({ ref: (ref) => {internalRef.current = ref;if (buttonRef)@@ -21,7 +29,7 @@ export function Dropdown(props) {}, sx: {p: 1,m: 0,- bg: isOpen ? "hover" : "transparent",+ bg: isPopupOpen ? "hover" : "transparent",mr: 1,display: "flex",alignItems: "center",@@ -29,7 +37,7 @@ export function Dropdown(props) {":last-of-type": {mr: 0,},- }, onClick: () => setIsOpen((s) => !s), onMouseDown: (e) => e.preventDefault() }, { children: [typeof selectedItem === "string" ? (_jsx(Text, Object.assign({ sx: { fontSize: "subBody", mr: 1, color: "text" } }, { children: selectedItem }))) : (selectedItem), _jsx(Icon, { path: isBottom ? Icons.chevronUp : Icons.chevronDown, size: "small", color: "text" })] })), _jsx(MenuPresenter, { isOpen: isOpen, items: items, onClose: () => setIsOpen(false), position: {+ }, onClick: () => setIsOpen((s) => !s), onMouseDown: (e) => e.preventDefault() }, { children: [typeof selectedItem === "string" ? (_jsx(Text, Object.assign({ sx: { fontSize: "subBody", mr: 1, color: "text" } }, { children: selectedItem }))) : (selectedItem), _jsx(Icon, { path: isBottom ? Icons.chevronUp : Icons.chevronDown, size: "small", color: "text" })] })), _jsx(MenuPresenter, { isOpen: isPopupOpen, items: items, onClose: () => closePopup(id), position: {target: isBottom? getToolbarElement(): internalRef.current || "mouse",diff --git a/packages/editor/dist/es/toolbar/components/splitbutton.js b/packages/editor/dist/es/toolbar/components/splitbutton.jsindex 354729334..733bee369 100644--- a/packages/editor/dist/es/toolbar/components/splitbutton.js+++ b/packages/editor/dist/es/toolbar/components/splitbutton.js@@ -24,18 +24,17 @@ function _SplitButton(props) {const toolbarLocation = useToolbarLocation();return (_jsxs(_Fragment, { children: [_jsxs(Flex, Object.assign({ ref: ref, sx: {borderRadius: "default",- bg: toggled ? "hover" : "transparent",- ":hover": { bg: [toggled ? "hover" : "transparent", "hover"] },- ":active": { bg: toggled ? "hover" : "transparent" },- } }, { children: [_jsx(ToolButton, Object.assign({}, toolButtonProps, { toggled: false })), _jsx(Button, Object.assign({ sx: {+ } }, { children: [_jsx(ToolButton, Object.assign({}, toolButtonProps, { sx: { mr: 0, ":hover": { bg: "hover" } }, toggled: false })), _jsx(Button, Object.assign({ sx: {+ flexShrink: 0,p: 0,m: 0,- bg: "transparent",+ px: "3px",+ bg: "bgSecondary",":hover": { bg: "hover" },":last-of-type": {mr: 0,},- }, onClick: onOpen }, { children: _jsx(Icon, { path: toolbarLocation === "bottom" ? Icons.chevronUp : Icons.chevronDown, color: "text", size: "small" }) }))] })), children] }));+ }, onClick: onOpen }, { children: _jsx(Icon, { path: toolbarLocation === "bottom" ? Icons.chevronUp : Icons.chevronDown, color: "text", size: "small", sx: { flexShrink: 0 } }) }))] })), children] }));}export const SplitButton = React.memo(_SplitButton, (prev, next) => {return (prev.toggled === next.toggled &&diff --git a/packages/editor/dist/es/toolbar/tools/font.js b/packages/editor/dist/es/toolbar/tools/font.jsindex 08f0d5c74..3ba3fa872 100644--- a/packages/editor/dist/es/toolbar/tools/font.js+++ b/packages/editor/dist/es/toolbar/tools/font.js@@ -33,7 +33,7 @@ export function FontFamily(props) {const currentFontFamily = ((_b = (_a = Object.entries(fontFamilies).find(([key, value]) => editor.isActive("textStyle", { fontFamily: value }))) === null || _a === void 0 ? void 0 : _a.map((a) => a)) === null || _b === void 0 ? void 0 : _b.at(0)) || "Sans-serif";const items = useMemo(() => toMenuItems(editor, currentFontFamily), [currentFontFamily]);- return (_jsx(Dropdown, { selectedItem: currentFontFamily, items: items, menuWidth: 130 }));+ return (_jsx(Dropdown, { id: "fontFamily", group: "font", selectedItem: currentFontFamily, items: items, menuWidth: 130 }));}function toMenuItems(editor, currentFontFamily) {const menuItems = [];diff --git a/packages/editor/dist/es/toolbar/tools/headings.js b/packages/editor/dist/es/toolbar/tools/headings.jsindex 4fcde7e4b..24048a264 100644--- a/packages/editor/dist/es/toolbar/tools/headings.js+++ b/packages/editor/dist/es/toolbar/tools/headings.js@@ -8,7 +8,7 @@ export function Headings(props) {const toolbarLocation = useToolbarLocation();const currentHeadingLevel = defaultLevels.find((level) => editor.isActive("heading", { level }));const items = useMemo(() => toMenuItems(editor, toolbarLocation, currentHeadingLevel), [currentHeadingLevel]);- return (_jsx(Dropdown, { selectedItem: currentHeadingLevel ? `Heading ${currentHeadingLevel}` : "Paragraph", items: items, menuWidth: 130 }));+ return (_jsx(Dropdown, { id: "headings", group: "headings", selectedItem: currentHeadingLevel ? `Heading ${currentHeadingLevel}` : "Paragraph", items: items, menuWidth: 130 }));}function toMenuItems(editor, toolbarLocation, currentHeadingLevel) {const menuItems = defaultLevels.map((level) => ({