From d82711a569c8599f761ca1953c7da0166e1df541 Mon Sep 17 00:00:00 2001 From: Pavel Denisjuk Date: Thu, 28 Mar 2024 13:54:48 +0100 Subject: [PATCH] feat(app-page-builder): export useful editor hooks --- .../src/blockEditor/hooks/index.ts | 2 + .../app-page-builder/src/blockEditor/index.ts | 2 + .../editor/components/Editor/EditorBar.tsx | 69 ------------------- .../src/editor/hooks/index.ts | 17 +++++ .../app-page-builder/src/editor/index.tsx | 3 +- .../src/pageEditor/hooks/index.ts | 4 ++ .../app-page-builder/src/pageEditor/index.ts | 3 +- .../src/templateEditor/hooks/index.ts | 1 + .../src/templateEditor/index.ts | 3 +- 9 files changed, 31 insertions(+), 73 deletions(-) create mode 100644 packages/app-page-builder/src/blockEditor/hooks/index.ts create mode 100644 packages/app-page-builder/src/blockEditor/index.ts delete mode 100644 packages/app-page-builder/src/editor/components/Editor/EditorBar.tsx create mode 100644 packages/app-page-builder/src/editor/hooks/index.ts create mode 100644 packages/app-page-builder/src/pageEditor/hooks/index.ts create mode 100644 packages/app-page-builder/src/templateEditor/hooks/index.ts diff --git a/packages/app-page-builder/src/blockEditor/hooks/index.ts b/packages/app-page-builder/src/blockEditor/hooks/index.ts new file mode 100644 index 00000000000..7b70e05de83 --- /dev/null +++ b/packages/app-page-builder/src/blockEditor/hooks/index.ts @@ -0,0 +1,2 @@ +export { useBlock } from "./useBlock"; +export { useBlockCategories } from "./useBlockCategories"; diff --git a/packages/app-page-builder/src/blockEditor/index.ts b/packages/app-page-builder/src/blockEditor/index.ts new file mode 100644 index 00000000000..438e3effd72 --- /dev/null +++ b/packages/app-page-builder/src/blockEditor/index.ts @@ -0,0 +1,2 @@ +export * from "./hooks"; +export * from "./editorConfig/BlockEditorConfig"; diff --git a/packages/app-page-builder/src/editor/components/Editor/EditorBar.tsx b/packages/app-page-builder/src/editor/components/Editor/EditorBar.tsx deleted file mode 100644 index 1dcb4dccfb4..00000000000 --- a/packages/app-page-builder/src/editor/components/Editor/EditorBar.tsx +++ /dev/null @@ -1,69 +0,0 @@ -import React from "react"; -import { css } from "emotion"; -import styled from "@emotion/styled"; -import { TopAppBarSection } from "@webiny/ui/TopAppBar"; -import { createVoidComponent, makeDecoratable } from "@webiny/app-admin"; - -const centerTopBar = css({ - "&.mdc-top-app-bar__section": { - paddingTop: 0, - paddingBottom: 0 - } -}); - -const StyledDivider = styled("div")({ - width: 1, - margin: "0 5px", - height: "100%", - backgroundColor: "var(--mdc-theme-on-background)" -}); - -const LeftSection = makeDecoratable("LeftSection", ({ children }) => { - return ( - - - - {children} - - ); -}); - -const CenterSection = makeDecoratable("CenterSection", ({ children }) => { - return {children}; -}); - -const RightSection = makeDecoratable("RightSection", ({ children }) => { - return ( - - {children} - - ); -}); - -/** - * This component serves as a placeholder for other editors to implement how they see fit. - * A Page editor will redirect back to the pages list; a Block editor will redirect back to blocks list, etc. - */ -const BackButton = makeDecoratable("BackButton", createVoidComponent()); - -/** - * A generic divider for UI elements in the EditorBar. - */ -const Divider = makeDecoratable("Divider", () => { - return ; -}); - -const DividerRenderer = makeDecoratable("DividerRenderer", () => { - return ; -}); - -export const EditorBar = Object.assign( - {}, - { - LeftSection, - CenterSection, - RightSection, - BackButton, - Divider - } -); diff --git a/packages/app-page-builder/src/editor/hooks/index.ts b/packages/app-page-builder/src/editor/hooks/index.ts new file mode 100644 index 00000000000..964746886d1 --- /dev/null +++ b/packages/app-page-builder/src/editor/hooks/index.ts @@ -0,0 +1,17 @@ +export { useActiveElement } from "./useActiveElement"; +export { useActiveElementId } from "./useActiveElementId"; +export { useCurrentBlockElement } from "./useCurrentBlockElement"; +export { useCurrentElement } from "./useCurrentElement"; +export { useDisplayMode } from "./useDisplayMode"; +export { useElementById } from "./useElementById"; +export { useElementSidebar } from "./useElementSidebar"; +export { useElementVariables, useElementVariableValue } from "./useElementVariableValue"; +export { useEventActionHandler } from "./useEventActionHandler"; +export { useHighlightElement } from "./useHighlightElement"; +export { useKeyHandler } from "./useKeyHandler"; +export { useParentBlock } from "./useParentBlock"; +export { useRefreshBlock } from "./useRefreshBlock"; +export { useRootElement } from "./useRootElement"; +export { useUI } from "./useUI"; +export { useUpdateElement } from "./useUpdateElement"; +export { useUpdateHandlers } from "./useUpdateHandlers"; diff --git a/packages/app-page-builder/src/editor/index.tsx b/packages/app-page-builder/src/editor/index.tsx index 3b036d32400..5a6cfd536b3 100644 --- a/packages/app-page-builder/src/editor/index.tsx +++ b/packages/app-page-builder/src/editor/index.tsx @@ -1,5 +1,4 @@ export { DefaultEditorConfig } from "./defaultConfig/DefaultEditorConfig"; export * from "./config"; -export * from "./components/Editor/EditorBar"; -export { EditorProvider } from "./contexts/EditorProvider"; +export * from "./hooks"; export { default as DropZone } from "../editor/components/DropZone"; diff --git a/packages/app-page-builder/src/pageEditor/hooks/index.ts b/packages/app-page-builder/src/pageEditor/hooks/index.ts new file mode 100644 index 00000000000..c1b25b117d8 --- /dev/null +++ b/packages/app-page-builder/src/pageEditor/hooks/index.ts @@ -0,0 +1,4 @@ +export { usePage } from "./usePage"; +export { usePageSettings } from "./usePageSettings"; +export { useRevisions } from "./useRevisions"; +export { useTemplateMode } from "./useTemplateMode"; diff --git a/packages/app-page-builder/src/pageEditor/index.ts b/packages/app-page-builder/src/pageEditor/index.ts index 17c7b1a1522..1286b13af3c 100644 --- a/packages/app-page-builder/src/pageEditor/index.ts +++ b/packages/app-page-builder/src/pageEditor/index.ts @@ -1,2 +1,3 @@ export { PublishPageButton } from "./config/TopBar/PublishPageButton/PublishPageButton"; -export { usePage } from "./hooks/usePage"; +export * from "./hooks"; +export * from "./editorConfig/PageEditorConfig"; diff --git a/packages/app-page-builder/src/templateEditor/hooks/index.ts b/packages/app-page-builder/src/templateEditor/hooks/index.ts new file mode 100644 index 00000000000..4e1010ee078 --- /dev/null +++ b/packages/app-page-builder/src/templateEditor/hooks/index.ts @@ -0,0 +1 @@ +export { useTemplate } from "./useTemplate"; diff --git a/packages/app-page-builder/src/templateEditor/index.ts b/packages/app-page-builder/src/templateEditor/index.ts index c51b20e8002..71870cc69b1 100644 --- a/packages/app-page-builder/src/templateEditor/index.ts +++ b/packages/app-page-builder/src/templateEditor/index.ts @@ -1 +1,2 @@ -export { useTemplate } from "./hooks/useTemplate"; +export * from "./hooks"; +export * from "./editorConfig/TemplateEditorConfig";