From 7c7107346e9a9ed8c152202f5d046db253ea104f Mon Sep 17 00:00:00 2001 From: volchok Date: Mon, 29 Jan 2024 14:15:26 +0300 Subject: [PATCH 1/2] feat: pc x tanker mvp --- src/containers/PageConstructor/PageConstructor.tsx | 14 +++++++------- src/editor/containers/Editor/Editor.tsx | 2 ++ src/editor/types/index.ts | 3 ++- src/models/constructor.ts | 4 ++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/containers/PageConstructor/PageConstructor.tsx b/src/containers/PageConstructor/PageConstructor.tsx index 316c69cb6..50fd027ce 100644 --- a/src/containers/PageConstructor/PageConstructor.tsx +++ b/src/containers/PageConstructor/PageConstructor.tsx @@ -14,6 +14,7 @@ import { BlockTypes, CustomConfig, CustomItems, + FinalizeContent, HeaderBlockTypes, NavigationData, NavigationItemTypes, @@ -49,16 +50,15 @@ export interface PageConstructorProps { custom?: CustomConfig; renderMenu?: () => React.ReactNode; navigation?: NavigationData; + finalizeContent?: FinalizeContent; } export const Constructor = (props: PageConstructorProps) => { - const { - content: {blocks = [], background} = {}, - renderMenu, - shouldRenderBlock, - navigation, - custom, - } = props; + const {renderMenu, shouldRenderBlock, navigation, custom, finalizeContent} = props; + + const content = + props.content && finalizeContent ? finalizeContent(props.content) : props.content; + const {blocks = [], background} = content ?? {}; const {context} = useMemo( () => ({ diff --git a/src/editor/containers/Editor/Editor.tsx b/src/editor/containers/Editor/Editor.tsx index 7ba73d190..e2f8c268b 100644 --- a/src/editor/containers/Editor/Editor.tsx +++ b/src/editor/containers/Editor/Editor.tsx @@ -22,6 +22,7 @@ export const Editor = ({ onChange, providerProps, transformContent, + finalizeContent, deviceEmulationSettings, theme: editorTheme, ...rest @@ -81,6 +82,7 @@ export const Editor = ({ content: transformedContent, custom, viewMode, + finalizeContent, }; }, [ injectEditBlockProps, diff --git a/src/editor/types/index.ts b/src/editor/types/index.ts index 302b2b18c..31064d4de 100644 --- a/src/editor/types/index.ts +++ b/src/editor/types/index.ts @@ -1,5 +1,5 @@ import {PageConstructorProps, PageConstructorProviderProps} from '../../containers/PageConstructor'; -import {BlockDecorationProps, PageContent} from '../../models'; +import {BlockDecorationProps, FinalizeContent, PageContent} from '../../models'; import {Theme} from '../../models/common'; import {SchemaCustomConfig} from '../../schema'; import {EditBlockActions} from '../components/EditBlock/EditBlock'; @@ -26,6 +26,7 @@ export interface EditorProps providerProps?: PageConstructorProviderProps; onChange?: (data: PageContent) => void; transformContent?: ContentTransformer; + finalizeContent?: FinalizeContent; customSchema?: SchemaCustomConfig; deviceEmulationSettings?: DeviceEmulationSettings; theme?: Theme; diff --git a/src/models/constructor.ts b/src/models/constructor.ts index b38649f4a..44065cd82 100644 --- a/src/models/constructor.ts +++ b/src/models/constructor.ts @@ -16,12 +16,15 @@ export interface Menu { title: string; } +export type PageMetadata = Record; + export type ConstructorBlock = ConstructorItem | CustomBlock; export interface PageContent extends Animatable { blocks: ConstructorBlock[]; menu?: Menu; background?: ThemedMediaProps; + meta?: PageMetadata; } export interface InitConstrucorState { @@ -44,6 +47,7 @@ export type FetchLoadableData = ( params: FetchLoadableDataParams, ) => Promise; export type ShouldRenderBlock = (block: ConstructorBlock, blockKey: string) => Boolean; +export type FinalizeContent = (content: PageContent) => PageContent; export type OnInit = (data: InitConstrucorState) => void; // eslint-disable-next-line @typescript-eslint/no-explicit-any type ComponentProps = React.ComponentProps>; From 4c34a1aeae9eeb408e556e07a4396edb566a6a0f Mon Sep 17 00:00:00 2001 From: volchok Date: Tue, 30 Jan 2024 11:55:46 +0300 Subject: [PATCH 2/2] chore: lint --- src/editor/containers/Editor/Editor.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/editor/containers/Editor/Editor.tsx b/src/editor/containers/Editor/Editor.tsx index e2f8c268b..b8d4fd027 100644 --- a/src/editor/containers/Editor/Editor.tsx +++ b/src/editor/containers/Editor/Editor.tsx @@ -91,6 +91,7 @@ export const Editor = ({ viewMode, transformedContent, rest.custom, + finalizeContent, ]); const context = useMemo(