Skip to content

feat: content finalization #788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/containers/PageConstructor/PageConstructor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
BlockTypes,
CustomConfig,
CustomItems,
FinalizeContent,
HeaderBlockTypes,
NavigationData,
NavigationItemTypes,
Expand Down Expand Up @@ -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(
() => ({
Expand Down
3 changes: 3 additions & 0 deletions src/editor/containers/Editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const Editor = ({
onChange,
providerProps,
transformContent,
finalizeContent,
deviceEmulationSettings,
theme: editorTheme,
...rest
Expand Down Expand Up @@ -81,6 +82,7 @@ export const Editor = ({
content: transformedContent,
custom,
viewMode,
finalizeContent,
};
}, [
injectEditBlockProps,
Expand All @@ -89,6 +91,7 @@ export const Editor = ({
viewMode,
transformedContent,
rest.custom,
finalizeContent,
]);

const context = useMemo(
Expand Down
3 changes: 2 additions & 1 deletion src/editor/types/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -26,6 +26,7 @@ export interface EditorProps
providerProps?: PageConstructorProviderProps;
onChange?: (data: PageContent) => void;
transformContent?: ContentTransformer;
finalizeContent?: FinalizeContent;
customSchema?: SchemaCustomConfig;
deviceEmulationSettings?: DeviceEmulationSettings;
theme?: Theme;
Expand Down
4 changes: 4 additions & 0 deletions src/models/constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ export interface Menu {
title: string;
}

export type PageMetadata = Record<string, object>;

export type ConstructorBlock = ConstructorItem | CustomBlock;

export interface PageContent extends Animatable {
blocks: ConstructorBlock[];
menu?: Menu;
background?: ThemedMediaProps;
meta?: PageMetadata;
}

export interface InitConstrucorState {
Expand All @@ -44,6 +47,7 @@ export type FetchLoadableData<TData = LoadableData> = (
params: FetchLoadableDataParams,
) => Promise<TData>;
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<React.ComponentClass<any>>;
Expand Down